feat(pi-hermes-memory): 导入上游 v0.9.10 源码快照

从官方 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。
This commit is contained in:
云服务部-叶林立
2026-10-13 23:19:35 -07:00
parent 879fc5d37f
commit 312bb2ba5a
157 changed files with 52287 additions and 0 deletions
+134
View File
@@ -0,0 +1,134 @@
# Tasks — v0.2.0: Skills + Smart Curation
> **Workflow**: When you start a task, change `[ ]` to `[~]`. When done, change to `[x]` and note the commit hash.
>
> **Implementation order**: Epic 2 → Epic 3 → Epic 4 → Epic 1 → Epic 5 (quick wins first, then the largest piece)
>
> **Plan**: See `docs/0.2/PLAN.md` for full implementation details and architectural decisions.
---
## Epic 2: Auto-Consolidation
_Done when: memory full no longer returns an error — it triggers automatic consolidation and retries the add._
### Shared Config (Epics 2-4 touch these files — do once, extend per epic)
- [x] `src/types.ts` — add `autoConsolidate: boolean` to `MemoryConfig`; add `ConsolidationResult` interface (`c6317dd`)
- [x] `src/config.ts` — add `autoConsolidate: true` default + parsing (`c6317dd`)
- [x] `src/constants.ts` — add `CONSOLIDATION_PROMPT` (`c6317dd`)
### Implementation
- [x] `src/store/memory-store.ts` — make `add()` async, add `setConsolidator()` injection method; after consolidation: `await this.loadFromDisk()` before retry (`c6317dd`)
- [x] `src/tools/memory-tool.ts` — `await store.add(target, content)` (`c6317dd`)
- [x] `src/handlers/auto-consolidate.ts` — `triggerConsolidation()` using `pi.exec()` pattern (`c6317dd`)
- [x] `src/handlers/consolidate-command.ts` — `/memory-consolidate` command (`c6317dd` — combined into `auto-consolidate.ts`)
- [x] `src/index.ts` — wire consolidator via `store.setConsolidator()` + register command (`c6317dd`)
### Tests
- [x] `tests/handlers/auto-consolidate.test.ts` — consolidation trigger, pi.exec call, success/failure paths (`83e7c46`)
- [x] `tests/store/memory-store.test.ts` — migrate all `store.add()` calls to `await store.add()`; consolidator tests (`83e7c46`)
---
## Epic 3: Correction Detection + Immediate Save
_Done when: user corrections are detected in real-time and trigger an immediate memory save._
### Config
- [x] `src/types.ts` — add `correctionDetection: boolean` to `MemoryConfig` (`c6317dd`)
- [x] `src/config.ts` — add `correctionDetection: true` default + parsing (`c6317dd`)
- [x] `src/constants.ts` — add `CORRECTION_SAVE_PROMPT`, strong/weak/negative pattern arrays (`c6317dd`)
### Implementation
- [x] `src/handlers/correction-detector.ts` — two-pass filter: strong/weak/negative patterns (`c6317dd`)
- [x] Rate limiting — `turnsSinceLastCorrection >= 3` and `!correctionInProgress` guard (`c6317dd`)
- [x] `src/index.ts` — wire `setupCorrectionDetector()` (`c6317dd`)
### Tests
- [x] `tests/handlers/correction-detector.test.ts` — 35 tests: strong/weak/negative patterns, rate limiting, false positives (`83e7c46`)
---
## Epic 4: Tool-Call-Aware Nudge
_Done when: background review triggers based on EITHER turn count OR tool call count._
### Config
- [x] `src/types.ts` — add `nudgeToolCalls: number` to `MemoryConfig` (`c6317dd`)
- [x] `src/config.ts` — add `nudgeToolCalls: 15` default + parsing (`c6317dd`)
### Implementation
- [x] `src/handlers/background-review.ts` — count toolCall entries from branch; OR trigger logic; reset both counters (`c6317dd`)
### Tests
- [x] `tests/handlers/background-review.test.ts` — 6 new tests: tool-call trigger, combined trigger, counter reset, text-only, crash recovery (`83e7c46`)
---
## Epic 1: Skill Tool + Procedural Memory
_Done when: the agent can create/update/delete skill documents, skills appear in a progressive index in the system prompt, and skills are auto-created after complex tasks._
### Research & Design
- [x] Read Pi's skill discovery API — Pi uses `~/.pi/agent/skills/` with SKILL.md frontmatter format (`c6317dd`)
- [x] Decide: write to `~/.pi/agent/memory/skills/` — isolated from user skills (`c6317dd`)
- [x] Read Hermes `skill_manage` tool source for reference patterns (`c6317dd`)
### Store
- [x] `src/store/skill-store.ts` — `SkillStore` class with full CRUD + `formatIndexForSystemPrompt()` (`c6317dd`)
- [x] SKILL.md format — frontmatter (name, description, version, created, updated) + markdown body (`c6317dd`)
- [x] File naming — `slugify(name) + ".md"` (`c6317dd`)
- [x] Frontmatter parsing — regex-based, no yaml dependency (`c6317dd`)
- [x] Content scanning — all writes go through `scanContent()` (`c6317dd`)
- [x] Atomic writes — temp+rename pattern (`c6317dd`)
### Tool
- [x] `src/tools/skill-tool.ts` — `registerSkillTool()` with actions: `create`, `view`, `patch`, `edit`, `delete` (`c6317dd`)
- [x] `src/constants.ts` — add `SKILL_TOOL_DESCRIPTION` and `DEFAULT_SKILL_TRIGGER_TOOL_CALLS` (= 8) (`c6317dd`)
- [x] Rewrite `COMBINED_REVIEW_PROMPT` — references skill tool with create/patch actions (`c6317dd`)
### Progressive Disclosure
- [x] Skill index (name + description only) injected into system prompt at `before_agent_start` (`c6317dd`)
- [x] `view` action loads full skill content on demand (`c6317dd`)
- [x] Frozen snapshot — index captured at `session_start`, consistent throughout session (`c6317dd`)
### Auto-Trigger
- [x] `src/handlers/skill-auto-trigger.ts` — 8+ tool calls with 2+ distinct tool types (`c6317dd`)
- [x] Rate limit — max 1 auto-trigger per session (`c6317dd`)
### Command
- [x] `src/handlers/skills-command.ts` — `/memory-skills` command (`c6317dd`)
### Wiring
- [x] `src/index.ts` — wire SkillStore, registerSkillTool, setupSkillAutoTrigger, registerSkillsCommand (`c6317dd`)
### Tests
- [x] `tests/store/skill-store.test.ts` — 27 tests: CRUD, frontmatter, progressive disclosure, atomic writes (`83e7c46`)
- [x] `tests/tools/skill-tool.test.ts` — 10 tests: registration, action dispatch, validation (`83e7c46`)
- [x] `tests/handlers/skill-auto-trigger.test.ts` — 6 tests: threshold, distinct types, session limit (`83e7c46`)
---
## Epic 5: Documentation & Release
_Done when: v0.2.0 is tagged and released with updated docs._
- [x] Update `README.md` — skill tool, auto-consolidation, correction detection, new config, new commands (`4658529`)
- [x] Update `src/constants.ts` — verify all new prompts are finalized (`c6317dd`)
- [x] Update `docs/ROADMAP.md` — v0.2 roadmap documented (`d5b7518`)
- [x] `npm run check` passes with zero errors (`c6317dd`)
- [x] `npm test` — all 218 tests pass (`83e7c46`)
- [x] Bump `package.json` version to `0.2.0`
- [x] Tag v0.2.0 release
---
## Summary
| Epic | Priority | Est. Complexity | New Files | Modified Files |
|---|---|---|---|---|
| 2: Auto-Consolidation | HIGH | Low | 3 (src + test) | 5 (types, config, constants, memory-store, memory-tool, index) |
| 3: Correction Detection | HIGH | Low | 2 (src + test) | 3 (types, config, constants, index) |
| 4: Tool-Call Nudge | MEDIUM | Low | 0 | 3 (types, config, background-review, test) |
| 1: Skill Tool | CRITICAL | High | 8 (4 src + 4 test) | 3 (constants, index, memory-store) |
| 5: Documentation | NORMAL | Low | 0 | 4 (README, constants, ROADMAP, package.json) |