mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 18:55:22 +00:00
从官方 Git 仓库导入 chandra447/pi-hermes-memory 在 tag v0.9.10 (df624056a2e8c68bc89ba0a81e1c120856ec9665,2026-10-02)的源码快照。 本次仅导入源码,尚未接入组合包:package.json、加载顺序、依赖与权限策略 均未改动。 - 原样导入 src/、tests/、docs/、scripts/、README、CHANGELOG、PLAN、 AGENTS 与 LICENSE;该快照共 156 个上游文件。 - 剔除嵌套 .git、上游 .github 工作流、.ralph/、.claude/、node_modules、 覆盖率与构建产物。 - 新增中文 UPSTREAM.md,记录来源,以及启用前必须完成的待决事项: 在 pi-compaction 之前注册加载顺序、better-sqlite3 版本与根 allowScripts 对齐、strip-ansi 解析确认。 - 说明选择 tag 而非 main 的原因:导入时上游 main 已领先至 24fcd8ad26fc27badb8d7dbaf8034645de07b893(2026-10-11),选 tag 是为 对应一个已发布、可复现的版本。 尚未接线。启用前还需反转 tests/extension-load.test.ts 中"不得加载 Hermes"的断言,并同步 pi-tool-search 分组、权限策略与文档。 验证:快照 156 个上游文件全部导入,目录内仅多出 UPSTREAM.md 一份; 已确认与上游 main 内容存在差异,证明取的是 tag 而非 main。
5.3 KiB
5.3 KiB
v0.7 Tasks: Token-Aware Graph-Based Memory Retrieval
Status Legend
[ ]Not started[~]In progress[x]Done
Epic 1: Stop Prompt Bloat
Done when full Markdown memory is no longer injected by default.
src/types.ts— addmemoryMode: "policy-only" | "legacy-inject"src/config.ts— parsememoryModewithpolicy-onlydefaultsrc/constants.ts— add expandedMEMORY_POLICY_PROMPTwith accepted targets/categoriessrc/index.ts— replace full memory block injection with memory policy by default- Legacy compatibility — support
memoryMode: "legacy-inject"for old behavior /memory-preview-context— show policy-only prompt in default mode and full blocks in legacy mode- Tests — system prompt contains policy only in retrieval mode
- Tests — legacy mode still injects current blocks
Epic 2: Memory Router
Future phase. Do not start until policy-only mode is shipped and measured.
src/handlers/memory-router.ts— inspect user message, recent context, project, repo/tool/error signals- Router rules — retrieve for prior-context phrases, repo tasks, failures, preferences, conventions
- Router rules — skip generic explanation and one-off examples
- Query builder — produce compact search query from message + signals
- Debug record — persist last router decision in memory for
/memory-debug-last - Tests — retrieve/skip decisions for representative coding and generic prompts
Epic 3: Memory Ranking + Packing
Future phase. Depends on a working runtime injection hook and router.
src/store/memory-ranker.ts— score candidates by FTS relevance, project match, category, recency, confidencesrc/store/memory-eligibility.ts— exclude wrong-scope, stale, superseded, low-confidence, and irrelevant memoriessrc/store/memory-pack.ts— build<retrieved-memory security="untrusted-context">block- Read-time scanner — run
scanContent()or equivalent before injection - Token estimate helper — approximate budget with chars/4 and hard cap
- Tests — ranking favors project corrections/failures/conventions
- Tests — packer respects
maxRetrievedTokens
Epic 4: Runtime Injection
Future phase. Do not start until the policy-only default proves insufficient.
- Identify Pi hook/API for per-turn context injection or closest supported equivalent
src/index.ts— wire router/search/ranker/packer into the selected hook- No-memory path — inject nothing when router skips retrieval
- Retrieved-memory path — inject small block when router finds eligible memories
- Tests — no retrieved block for generic prompt
- Tests — retrieved block appears for project/debugging prompt
Epic 5: SQLite Graph Tables
Done when graph relationships exist in SQLite and can boost retrieval.
src/store/schema.ts— addmemory_nodes,memory_edges,memory_node_linkssrc/store/memory-graph-store.ts— CRUD for nodes, edges, memory linkssrc/store/memory-graph-extractor.ts— extract project/file/tool/error/decision/failure entities from memory text- Sync path — link new/updated memories to graph nodes
- Graph lookup — retrieve 1-2 hop related memory IDs for current turn signals
- Ranking integration — add
graph_distance_score - Tests — graph tables migrate cleanly
- Tests — graph-linked memory outranks unrelated FTS match
Epic 6: Conflict + Staleness
Done when stale or conflicting memory is not blindly injected.
- Schema migration — add
confidence,status,supersedes_id,valid_from,valid_to,last_accessed_at,access_count src/store/memory-conflict-detector.ts— mark superseded/conflicting memories where deterministic- Update write path — support status/confidence updates
- Update search path — exclude
supersededand expired rows by default - Tests — superseded memory is not injected
- Tests — current project evidence wins over memory conflict
Epic 7: Debug Commands
Done when users can see what memory did and why.
/memory-status— mode, config, DB counts, prompt injection mode/memory-debug-last— router decision, query, candidates, injected count, skipped reasons, token estimate/memory-graph-status— graph backend, nodes, edges, links, traversal depth/memory-doctor— stale schema, FTS consistency, orphan graph links, oversized prompt warnings- Tests — commands render useful output with empty and populated DBs
Epic 8: Documentation + Release
- README — document policy-only mode and legacy mode
- README — add memory policy and retrieved-memory examples
- ROADMAP — mark frozen full injection as legacy, not the future default
- Migration notes — explain how Markdown remains readable/syncable
npm run checknpm test- Version bump
- Tag release
Implementation Order
- Epic 1 — remove token tax first.
- Epic 2 — route retrieval cheaply.
- Epic 3 — rank/filter/pack safely.
- Epic 4 — wire runtime injection.
- Epic 7 — expose behavior for debugging.
- Epic 5 — add graph booster after baseline retrieval works.
- Epic 6 — harden conflict/staleness.
- Epic 8 — docs and release.