dsh-continual-evolve 0.10.6 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/README.md +35 -122
  2. package/README.zh.md +26 -97
  3. package/cordis.patch.yml +2 -2
  4. package/lib/index.d.ts +44 -241
  5. package/lib/index.js +30 -253
  6. package/lib/memory-guide.d.ts +13 -14
  7. package/lib/memory-guide.js +32 -21
  8. package/lib/memory-section.d.ts +77 -0
  9. package/lib/memory-section.js +189 -0
  10. package/package.json +2 -17
  11. package/lib/apply.d.ts +0 -22
  12. package/lib/apply.js +0 -157
  13. package/lib/approval.d.ts +0 -72
  14. package/lib/approval.js +0 -127
  15. package/lib/auto.d.ts +0 -236
  16. package/lib/auto.js +0 -773
  17. package/lib/autocase.d.ts +0 -38
  18. package/lib/autocase.js +0 -76
  19. package/lib/benchmark-command.d.ts +0 -9
  20. package/lib/benchmark-command.js +0 -357
  21. package/lib/benchmark.d.ts +0 -151
  22. package/lib/benchmark.js +0 -250
  23. package/lib/command.d.ts +0 -49
  24. package/lib/command.js +0 -568
  25. package/lib/consolidate.d.ts +0 -90
  26. package/lib/consolidate.js +0 -180
  27. package/lib/copy.d.ts +0 -74
  28. package/lib/copy.js +0 -160
  29. package/lib/declines.d.ts +0 -101
  30. package/lib/declines.js +0 -175
  31. package/lib/evaluate.d.ts +0 -74
  32. package/lib/evaluate.js +0 -271
  33. package/lib/evolve-event.d.ts +0 -40
  34. package/lib/evolve-event.js +0 -59
  35. package/lib/failures.d.ts +0 -42
  36. package/lib/failures.js +0 -171
  37. package/lib/fate.d.ts +0 -130
  38. package/lib/fate.js +0 -350
  39. package/lib/goal-command.d.ts +0 -7
  40. package/lib/goal-command.js +0 -37
  41. package/lib/goal.d.ts +0 -72
  42. package/lib/goal.js +0 -72
  43. package/lib/inject.d.ts +0 -196
  44. package/lib/inject.js +0 -412
  45. package/lib/llm-text.d.ts +0 -104
  46. package/lib/llm-text.js +0 -140
  47. package/lib/logfile.d.ts +0 -71
  48. package/lib/logfile.js +0 -159
  49. package/lib/memory-agent.d.ts +0 -129
  50. package/lib/memory-agent.js +0 -568
  51. package/lib/memory-benchmark.d.ts +0 -76
  52. package/lib/memory-benchmark.js +0 -170
  53. package/lib/memory-index.d.ts +0 -114
  54. package/lib/memory-index.js +0 -197
  55. package/lib/message-source.d.ts +0 -23
  56. package/lib/message-source.js +0 -12
  57. package/lib/mount-command.d.ts +0 -10
  58. package/lib/mount-command.js +0 -48
  59. package/lib/mount.d.ts +0 -42
  60. package/lib/mount.js +0 -212
  61. package/lib/notify.d.ts +0 -59
  62. package/lib/notify.js +0 -97
  63. package/lib/plan.d.ts +0 -16
  64. package/lib/plan.js +0 -126
  65. package/lib/planner.d.ts +0 -61
  66. package/lib/planner.js +0 -144
  67. package/lib/pool.d.ts +0 -7
  68. package/lib/pool.js +0 -25
  69. package/lib/prefix-cache.d.ts +0 -78
  70. package/lib/prefix-cache.js +0 -168
  71. package/lib/project.d.ts +0 -28
  72. package/lib/project.js +0 -66
  73. package/lib/projection.d.ts +0 -22
  74. package/lib/projection.js +0 -112
  75. package/lib/promotion.d.ts +0 -94
  76. package/lib/promotion.js +0 -171
  77. package/lib/recall.d.ts +0 -85
  78. package/lib/recall.js +0 -142
  79. package/lib/record-language.d.ts +0 -85
  80. package/lib/record-language.js +0 -152
  81. package/lib/render.d.ts +0 -13
  82. package/lib/render.js +0 -80
  83. package/lib/review-scheduler.d.ts +0 -38
  84. package/lib/review-scheduler.js +0 -191
  85. package/lib/review.d.ts +0 -60
  86. package/lib/review.js +0 -145
  87. package/lib/rollback.d.ts +0 -9
  88. package/lib/rollback.js +0 -68
  89. package/lib/rubric.d.ts +0 -29
  90. package/lib/rubric.js +0 -119
  91. package/lib/runtime.d.ts +0 -24
  92. package/lib/runtime.js +0 -87
  93. package/lib/score.d.ts +0 -64
  94. package/lib/score.js +0 -191
  95. package/lib/search.d.ts +0 -83
  96. package/lib/search.js +0 -136
  97. package/lib/service.d.ts +0 -49
  98. package/lib/service.js +0 -180
  99. package/lib/skill-render.d.ts +0 -23
  100. package/lib/skill-render.js +0 -69
  101. package/lib/skill.d.ts +0 -15
  102. package/lib/skill.js +0 -80
  103. package/lib/skillquality.d.ts +0 -85
  104. package/lib/skillquality.js +0 -320
  105. package/lib/source.d.ts +0 -30
  106. package/lib/source.js +0 -43
  107. package/lib/state.d.ts +0 -26
  108. package/lib/state.js +0 -151
  109. package/lib/store.d.ts +0 -62
  110. package/lib/store.js +0 -164
  111. package/lib/token-usage.d.ts +0 -68
  112. package/lib/token-usage.js +0 -211
  113. package/lib/tool.d.ts +0 -34
  114. package/lib/tool.js +0 -320
  115. package/lib/turn-snapshot.d.ts +0 -72
  116. package/lib/turn-snapshot.js +0 -238
  117. package/lib/types.d.ts +0 -208
  118. package/lib/types.js +0 -127
  119. package/lib/usage.d.ts +0 -36
  120. package/lib/usage.js +0 -98
  121. package/lib/validate.d.ts +0 -28
  122. package/lib/validate.js +0 -181
  123. package/lib/wrapup-command.d.ts +0 -10
  124. package/lib/wrapup-command.js +0 -243
  125. package/lib/wrapup.d.ts +0 -260
  126. package/lib/wrapup.js +0 -539
package/README.md CHANGED
@@ -1,178 +1,91 @@
1
1
  # dsh-continual-evolve
2
2
 
3
- [中文](README.zh.md) | English
3
+ English | [中文](README.zh.md)
4
4
 
5
5
  [![awesome · DSH plugin](https://awesome-dsh-plugin.com/badge.svg)](https://awesome-dsh-plugin.com)
6
6
  [![npm](https://img.shields.io/npm/v/dsh-continual-evolve)](https://www.npmjs.com/package/dsh-continual-evolve)
7
7
  [![CI](https://github.com/ZK-Andy/dsh-continual-evolve/actions/workflows/ci.yml/badge.svg)](https://github.com/ZK-Andy/dsh-continual-evolve/actions/workflows/ci.yml)
8
8
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
9
9
  [![Node](https://img.shields.io/badge/node-%5E22.19%20%7C%7C%20%3E%3D24-339933)](package.json)
10
- [![Tests](https://img.shields.io/badge/tests-1097%20passing-brightgreen)]()
10
+ [![Tests](https://img.shields.io/badge/tests-32%20passing-brightgreen)]()
11
11
  [![Coverage · statements](https://img.shields.io/badge/coverage_statements-98%25-brightgreen)]()
12
- [![Coverage · branches](https://img.shields.io/badge/coverage_branches-92%25-green)]()
13
- [![Coverage · functions](https://img.shields.io/badge/coverage_functions-99%25-brightgreen)]()
12
+ [![Coverage · branches](https://img.shields.io/badge/coverage_branches-98%25-green)]()
13
+ [![Coverage · functions](https://img.shields.io/badge/coverage_functions-100%25-brightgreen)]()
14
14
 
15
- Continual self-evolution for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness): a versioned, auditable, rollback-safe harness state layer — prompt notes, memories, skills, subagent specs — refined from session trajectories.
16
-
17
- **The model proposes, the code guarantees.** Every mechanical safety property — schema validation, atomic writes, snapshots, versioning, audit trail, acceptance decisions — is enforced in code, never by prompt discipline.
15
+ A workspace-memory plugin for the [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (`dsh`): one plain-markdown memory store per workspace (`<workspace>/.evolve/memory/`), the index injected at session start, used by the model with its **native file tools** — and nothing else.
18
16
 
19
17
  ## Why
20
18
 
21
- Agents accumulate reusable experience (repeated failures, durable facts, reusable procedures) and forget it next session. This plugin turns that experience into first-class state:
22
-
23
- - **Three scopes** with merge semantics (global < project < local): **local** per-session staging, **project** per-workspace cross-session store, **global** cross-project — plus mechanical promotion guards so only portable, substantial, non-duplicate knowledge reaches global
24
- - **Typed one-fact memories**: every memory entry carries a recall type (`user | feedback | project | reference`); pitfalls (`feedback`) must include Why + How to apply
25
- - **Dedicated background memory agent**: eligible successful turns feed a bounded ZCode-style loop that searches the frozen memory manifest and proposes memory-only edits through a closed tool set; it cannot call agents, MCP, the network, or write source files. The generic review/planner/fate path is not run by this listener
26
- - **Memory recall, projection, and receipts**: `evolve_recall` reads back full memory content by query/kind/scope/type; every memory apply also materializes a readable `MEMORY.md` index plus one fact file per entry; each extraction lands a unified audit receipt (no-op/applied/declined with duration and turn stats) and only applied outcomes notify the session
27
- - **Deterministic rollback**: inverse edits generated from applied results — no LLM re-guessing
28
- - **Benchmark loop**: candidate refinements are evaluated against frozen cases by a separate scorer before acceptance (rubric encrypted at rest)
29
- - **Store hygiene**: `/evolve consolidate` turns write-time conflict hints and zero-use staleness into one approved, fully reversible batch of archives — with `merge`, near-duplicate content folds into the surviving original
19
+ Reusable experience gathered in one session (user preferences, pitfalls, project context) is forgotten by the next. ZCode solves this with a folder: one fact per markdown file plus a `MEMORY.md` index, injected at session start, read and written natively by the model, with no dedicated machinery. This plugin brings that exact shape to DSH.
30
20
 
31
21
  ## How it works
32
22
 
33
- 1. **Sediment** — the model creates entries via `evolve_add`, or the automatic Memory Agent consumes incremental snapshots after successful turns. Generic review/planner remains manual unless separately invoked.
34
- 2. **Capability-aware auxiliary calls** — the memory loop, review, planner, wrapup, and fate resolve exact provider/model metadata through [`src/llm-text.ts`](src/llm-text.ts), use the lowest advertised enabled reasoning effort (falling back to a closing effort only when no enabled level exists), and forward the host session id for provider routing; models without reasoning metadata use their provider default.
35
- 3. **Guard** — code-enforced validation: edit schema, blast-radius/scope coherence, and the promotion policy (project-scoped markers, thin content, near-duplicate detection, credential screening keep the global store clean — secrets are rejected at every write sink, including mount materialization). Global creates that near-duplicate an existing entry are rejected at write time (≥0.8 similarity); moderate overlaps carry a `conflictHint` for later consolidation.
36
- 4. **Approve** — global and project writes require explicit human approval; the dialog shows the bounded structured edit diff and conflict warnings, while malformed/lost responses remain retryable rather than counting as rejection.
37
- 5. **Apply & inject** — memory batches preflight every persistent approval, recheck abort before writes, and compensate earlier scope writes if a later batch fails; every successful scope still passes through snapshot + audit. Prompt notes and delegation specs inject into the system prompt (capped, relevance-ranked, contradicted entries demoted, zero tokens when empty); memory CONTENT injects at session start under a hard character budget, frozen per session, with the when_to_save guide riding along; skills still appear as a relevance-ordered capped directory index.
38
- 6. **Validate & roll back** — benchmarks score candidates against frozen cases; rejected candidates roll back deterministically and are captured as draft regression cases (`auto_regression` benchmark).
23
+ 1. **Session-start injection** — the plugin registers a single system-prompt section: the `MEMORY.md` index content (whole-line truncated over budget, with a read-the-directory hint), the absolute store path, and the when_to_save guide. The section is computed once per session and reused byte-for-byte, keeping the system prompt stable and the prompt cache warm; an empty store costs zero tokens.
24
+ 2. **Native read/write** — DSH fully permits file access inside the workspace (reads are never fenced; the write fence only covers paths outside the workspace, see [`docs/FAQ.md`](docs/FAQ.md) #6). The model reads, writes, and edits memory files and maintains the index directly; the store is bootstrapped on first use.
25
+ 3. **Governance is the file** — no versions, no snapshots, no approvals, no background extraction: a bad memory is a visible file in the workspace, and deleting it is the retirement path. Memories are personal context — on bootstrap in a git workspace the store appends `.evolve/` to the workspace `.gitignore` (non-git workspaces are left untouched).
26
+
27
+ Memory file format (same as ZCode): frontmatter with `name` / `description` (the hook that decides whether a future session recalls it) / `metadata.type` (`user | feedback | project | reference`); `feedback` bodies must carry **Why:** and **How to apply:** lines.
39
28
 
40
29
  ## Install
41
30
 
42
31
  ```bash
43
- # from npm (installs and activates — ships its own bundle patch)
32
+ # From npm (activates on install — ships its own bundle patch)
44
33
  dsh plugin add dsh-continual-evolve
45
34
 
46
- # or from source (first GitHub installs require approving the allowBuilds step)
35
+ # Or from source (approve the allowBuilds build step on first GitHub install)
47
36
  dsh plugin add ZK-Andy/dsh-continual-evolve
48
37
  ```
49
38
 
50
- Restart the DSH profile you use (`dsh web` or the desktop host) after installing or updating.
39
+ After installing or updating, restart the DSH profile you actually use (`dsh web` or the desktop host).
51
40
 
52
41
  ## Usage
53
42
 
54
- Commands (in-session):
55
-
56
- | Command | Effect |
57
- |---|---|
58
- | `/evolve` | short help + current local store (`/evolve help all` lists every subcommand) |
59
- | `/evolve list · history · rollback <id>` | inspect and revert (add `project` for this project's store, `global` for the cross-project store) |
60
- | `/evolve plan [msg]` | run the LLM planner against the store |
61
- | `/evolve wrapup` | assess this session's local entries: promote / archive / keep |
62
- | `/evolve archive · unarchive <id>` | hide from injection (data kept, restorable) |
63
- | `/evolve consolidate [apply] [merge]` | report (or apply) one batch archive of conflict-hinted + stale zero-use global entries; `merge` folds near-duplicate content into the survivors |
64
- | `/evolve failures` | aggregated failure classes (gate + benchmark) |
65
- | `/evolve log [tail N] [session <id>]` | plugin log |
66
- | `/evolve export · import <path>` | backup / restore a store |
67
- | `/evolve mount · unmount <skillId>` | hot-mount an executable skill as a live plugin |
68
- | `/evolve goal [objective · done · block]` | round-driven auto-review goal |
69
- | `/evolve benchmark …` | case lifecycle, runs, acceptance |
70
- | `/evolve pause · resume · status` | pause/resume the auto-review gate (manual tools keep working), gate state |
71
- | `/evolve usage` | per-entry injection counts + exact provider-reported tokens for direct memory/review/planner/wrapup/fate calls (benchmark host subagents excluded) |
72
-
73
- Model tools: `evolve_list / add / update / delete / rollback / recall` (`evolve_delete` takes `id` or a batch `ids` array — one refinement, one approval; `evolve_recall` filters by query, kinds, scopes, memory types, and limit, and returns full content with version, source, and staleness). Memory reads and writes live in the conversation — the model carries the injected memory index plus `evolve_recall`/`evolve_add` — so there are no `/evolve remember · forget · recall` counterparts: ask in chat.
74
-
75
- For third-party consumers: every applied evolution (gate or manual) appends a structured `evolve_complete` event to `reviews.jsonl` (`src/evolve-event.ts` defines the shape) alongside the human-readable audit records.
76
-
77
- `/evolve usage` also reads `evolve/token-usage.jsonl`: exact provider-reported input/cache/output/total tokens for the plugin's direct memory-agent, review, planner, manual-wrapup, and automatic-fate calls. The report covers a retained tail rather than lifetime usage, distinguishes missing provider samples, and explicitly excludes host benchmark subagents, their agent-loop calls, and per-entry injection attribution.
78
-
79
- Injection shape: prompt notes and delegation specs inject with content (≤6/kind × 180 chars, relevance-ranked). Memories inject as CONTENT at session start: the `evolve:memory-index` section (order 400) carries the when_to_save guide plus every memory body the budget allows, ranked `project > feedback > user > reference`, with overflow degraded to `[memory:type:id] title` hooks and the remainder counted (hard cap `memoryIndex.maxChars`, default 6000 chars; `evolve_recall` reads anything not shown). The section is computed once per session and reused byte-for-byte, so the system prompt stays stable and prompt-cache reads keep hitting — a memory written mid-session appears in the next session. Skills still appear as a relevance-ordered directory index (capped at 15 lines with a fold counter); memories no longer do. Every memory apply also refreshes a readable `MEMORY.md` index plus one fact file per entry in the store directory. With `memoryIndex.guide` off and an empty store, injection is zero tokens.
43
+ No commands, no tools. On the first session after restart, `.evolve/memory/` is created and the index is injected automatically. Just tell the model "remember …" / "forget …" — the memory files plus their index lines are the entire persistent state. Memories written mid-session become visible in the next session (the section is frozen to protect the prompt cache); for an immediate look the model simply reads the directory.
80
44
 
81
45
  ## Configuration
82
46
 
83
47
  | Key | Default | Meaning |
84
48
  |---|---|---|
85
- | `baseDir` | resolved DSH home | root for the `evolve/` stores |
86
- | `autoReview` | `false` | initial Memory Agent default when no `evolve/runtime.json` exists yet; the listener is always registered, so this is not a registration gate |
87
- | `memoryMinUserWords` | `3` | ZCode-style minimum lexical words in one direct user text part; uses CJK-aware segmentation |
88
- | `sessionCloseDrainMs` | `15000` | session-close bounded drain for in-flight extraction in ms (`0` aborts immediately) |
89
- | `reviewIntervalTurns` | `6` | legacy local-fate cadence fallback; successful-turn review no longer waits for this interval |
90
- | `maxReviewInputChars` | `40000` | trajectory slice handed to the gate |
91
- | `reviewBudgetTokens` | `4096` | output budget for the gate call |
92
- | `notifyOnAutoReview` | `true` | visible follow-up notice after an applied gate run |
93
- | `requireGlobalApproval` | `true` | global and project edits ask for explicit approval |
94
- | `recordLanguage` | `auto` | authoring **and dialog** language: `auto` follows the DSH client preference, then the session's own user text, then `en`; `zh`/`en` pin it |
95
- | `localFate` | `false` | optional local-entry promote/archive fate assessment; unreachable while the listener runs memory-only, so it only affects direct/full callers |
96
- | `fateIntervalTurns` | follows `reviewIntervalTurns` | minimum turns between fate assessments |
97
- | `goalBlockedWrapupTurns` | `3` | consecutive blocked-goal gate runs trigger one fate assessment (`0` disables) |
98
- | `promotionBlockPatterns` | POSIX paths, session ids, `~/.dsh` | content matching these is project-scoped and never promoted to global |
99
- | `promotionMinChars` | `100` | whole promotions below this length stay local |
100
- | `injectionDirectoryLines` | `15` | entry-directory lines per build before folding into a counter |
101
- | `sectionOrder` | `118` | system-prompt section order for the guidance + entries sections |
102
- | `memoryIndex.enabled` | `true` | register the `evolve:memory-index` content section |
103
- | `memoryIndex.guide` | `true` | include the when_to_save guide (with the store empty and this off, the section renders nothing) |
104
- | `memoryIndex.order` | `400` | section order (upstream named slots start at `PLAN_POLICY=500`; the plugin's other sections sit at 118/119) |
105
- | `memoryIndex.maxChars` | `6000` | hard character budget for the injected memories block |
106
- | `skillsDir` | `<dshHome>/skills` | where skill entries materialize as SKILL.md bundles |
107
- | `rubricKey` | auto-generated key file | AES-256-GCM passphrase for benchmark rubrics (`DSH_EVOLVE_RUBRIC_KEY` overrides) |
108
- | `logToFile` / `logLevel` / `logMaxBytes` | `true` / `1` / 5 MiB | plugin-owned JSONL file log with rotation |
109
- | `autoRollbackOnReject` | `true` | deterministic rollback after a benchmark rejection |
110
- | `autoCase` | `true` | failed evolution attempts are captured as draft regression cases (`auto_regression` benchmark) |
111
- | `reviewModel` | agent's own | optional cheaper model for the dedicated memory agent and review gate (`"provider/model"`) |
112
- | `plannerPrefixCache` | `auto` | Route A session-prefix input when cache evidence exists (`session` always, `off` legacy flat text) |
113
- | `plannerPrefixMaxChars` | `12000` | session-prefix budget for Route A planning inputs (chars) |
114
- | `historyRetain` | `{snapshots: 20, refinements: 500, reviews: 500, tokenUsage: 500}` | storage hygiene: snapshots per store, tail lines per store history, shared `reviews.jsonl` tail, and direct-call `token-usage.jsonl` tail |
115
-
116
- Example profile patch:
49
+ | `memoryIndex.enabled` | `true` | Register the memory section |
50
+ | `memoryIndex.guide` | `true` | Inject the when_to_save guide (zero tokens when off and the index is empty) |
51
+ | `memoryIndex.order` | `400` | Section order (upstream named slots start at `PLAN_POLICY=500`) |
52
+ | `memoryIndex.maxChars` | `6000` | Hard character budget for the injected index |
53
+
54
+ Profile patch example:
117
55
 
118
56
  ```yaml
119
57
  - id: continual-evolve
120
58
  config:
121
- autoReview: true
122
- reviewIntervalTurns: 6
59
+ memoryIndex:
60
+ maxChars: 8000
123
61
  ```
124
62
 
125
- The Memory Agent listener is registered even when `autoReview` is `false` —
126
- `autoReview` only supplies the initial default, so an install works without
127
- editing the profile. Use `/evolve resume` to enable successful-turn snapshots
128
- immediately, `/evolve pause` to suppress new snapshots and model work, and
129
- `/evolve status` to inspect the configured default plus the current runtime
130
- state. The runtime switch is stored in `evolve/runtime.json`; manual `evolve_*`
131
- tools and `/evolve` commands are not paused. Only the Memory Agent runs
132
- automatically: the generic review/planner, prompt/skill writes, and local-fate
133
- phases are not reachable from this listener. The memory trigger follows ZCode's
134
- lightweight eligibility: direct user text must contain at least
135
- `memoryMinUserWords` lexical words (CJK-aware segmentation), while
136
- empty/internal/direct-memory-write snapshots are skipped; compaction does not
137
- add a separate memory-only trigger. Every extraction writes a unified audit
138
- receipt (`noop`/`applied`/`declined` with duration and turn/search stats) to
139
- `reviews.jsonl`; only applied outcomes queue a visible follow-up, and a
140
- closing session lets in-flight extraction settle up to `sessionCloseDrainMs`
141
- before aborting.
142
-
143
63
  ## Development
144
64
 
145
65
  ```bash
146
66
  pnpm install && pnpm build # deps + tsc -> lib/
147
- pnpm test # vitest (1097 tests)
148
- pnpm test:coverage # v8 coverage, thresholds enforced in CI
149
- pnpm coverage:gaps # locate uncovered lines per file (read-only)
67
+ pnpm test # vitest (32 tests)
68
+ pnpm test:coverage # v8 coverage, CI-enforced thresholds
150
69
  pnpm lint # oxlint src test
151
70
  ```
152
71
 
153
- Project layout:
72
+ Layout:
154
73
 
155
74
  ```
156
- ├── src/ # engine, tools, commands, memory agent, recall, projection, gate, fate, benchmark, injection + token usage…
157
- ├── test/ # vitest suites (59 files)
75
+ ├── src/
76
+ │ ├── index.ts # registration: the one section + config
77
+ │ ├── memory-section.ts # injection: read index / bootstrap / truncate / session freeze
78
+ │ └── memory-guide.ts # guide: when_to_save and upkeep (adapted from ZCode)
79
+ ├── test/ # vitest suite (3 files)
158
80
  ├── lib/ # build output (tsc)
159
- ├── docs/
160
- │ ├── design.md # full design doc (hardening matrix)
161
- │ ├── FAQ.md # real failure/fix records
162
- │ ├── gap-analysis.md # vs prime-agent /refine + penguin-harness
163
- │ ├── research/pi-dsh-competitor-gap-analysis.md # pi/dsh ecosystem competitors
164
- │ ├── experiment-bootstrap.md
165
- │ ├── archive/ # closed point-in-time reports
166
- │ └── research/ # penguin report + prime-agent annotated source
167
- ├── examples/README.md # seed benchmark cases
81
+ ├── docs/ # design.md (design) · FAQ.md (real-world pitfalls)
168
82
  └── .agents/ # AI collaboration layer (AGENTS.md, skills, ADR notes)
169
83
  ```
170
84
 
171
- ## Docs & provenance
85
+ ## Docs
172
86
 
173
- - Design: [`docs/design.md`](docs/design.md) · Pitfalls: [`docs/FAQ.md`](docs/FAQ.md) · Gap analysis: [`docs/gap-analysis.md`](docs/gap-analysis.md) · D2 experiment: [`docs/experiment-bootstrap.md`](docs/experiment-bootstrap.md)
174
- - Lineage: **penguin-harness** (concept; Apache-2.0) — report in [`docs/research/penguin-harness-self-evolution.md`](docs/research/penguin-harness-self-evolution.md); **prime-agent `/refine`** (engineering shape; MIT) — annotated reference source in [`docs/research/prime-agent-refinement.ts`](docs/research/prime-agent-refinement.ts). This package is an original implementation on the DSH plugin surface.
87
+ - Design: [`docs/design.md`](docs/design.md) · Pitfalls: [`docs/FAQ.md`](docs/FAQ.md) · Teardown decision: [`.agents/notes/implemented/architecture/2026-10-04-zcode-alignment-teardown.md`](.agents/notes/implemented/architecture/2026-10-04-zcode-alignment-teardown.md)
175
88
 
176
89
  ## License
177
90
 
178
- [MIT](LICENSE)
91
+ MIT. Independent project — not affiliated with DeepSeek.
package/README.zh.md CHANGED
@@ -7,35 +7,24 @@
7
7
  [![CI](https://github.com/ZK-Andy/dsh-continual-evolve/actions/workflows/ci.yml/badge.svg)](https://github.com/ZK-Andy/dsh-continual-evolve/actions/workflows/ci.yml)
8
8
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
9
9
  [![Node](https://img.shields.io/badge/node-%5E22.19%20%7C%7C%20%3E%3D24-339933)](package.json)
10
- [![Tests](https://img.shields.io/badge/tests-1097%20passing-brightgreen)]()
10
+ [![Tests](https://img.shields.io/badge/tests-32%20passing-brightgreen)]()
11
11
  [![Coverage · statements](https://img.shields.io/badge/coverage_statements-98%25-brightgreen)]()
12
- [![Coverage · branches](https://img.shields.io/badge/coverage_branches-92%25-green)]()
13
- [![Coverage · functions](https://img.shields.io/badge/coverage_functions-99%25-brightgreen)]()
12
+ [![Coverage · branches](https://img.shields.io/badge/coverage_branches-98%25-green)]()
13
+ [![Coverage · functions](https://img.shields.io/badge/coverage_functions-100%25-brightgreen)]()
14
14
 
15
- [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(`dsh`)的持续自进化插件:一套**版本化、可审计、可回滚**的 harness 状态层——提示词补充、记忆、技能、子代理规格——从会话轨迹中沉淀而来。
16
-
17
- **模型提议,代码保证。** 每一项机械化安全属性——schema 校验、原子写入、快照、版本、审计、接受决策——都由代码强制,从不依赖提示词自觉。
15
+ [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(`dsh`)的工作区记忆插件:每个工作区一个纯 markdown 记忆库(`<workspace>/.evolve/memory/`),会话开局注入索引,模型用**原生文件读写工具**直接使用——仅此而已。
18
16
 
19
17
  ## 为什么
20
18
 
21
- Agent 在每个会话里积累可复用经验(重复失败、持久事实、可复用流程),下个会话就忘掉。本插件把这些经验变成一等公民的持久状态:
22
-
23
- - **三作用域**与合并语义(global < project < local):**local** 本会话暂存、**project** 本项目跨会话库、**global** 跨项目——配合机械化晋升守卫,只有可携带、有分量、非重复的知识才能进全局
24
- - **类型化单条记忆**:每条 memory 带召回类型(`user | feedback | project | reference`);踩坑(`feedback`)必须含 Why + How to apply
25
- - **专用后台记忆 Agent**:成功回合通过机械 eligibility 后,有界 ZCode 式 loop 检索冻结的 memory manifest,并经闭集工具提出纯 memory 编辑;不能调用 Agent、MCP、网络,也不能写源码。该 listener 不运行通用 review/planner/fate
26
- - **记忆召回、投影与回执**:`evolve_recall` 按 query/kind/scope/type 精确读回记忆全文;每次 memory 落盘同时生成可读的 `MEMORY.md` 索引 + 单事实文件;每次提取留统一审计回执(no-op/applied/declined + 耗时与轮次统计),只有实际沉淀才通知会话
27
- - **确定性回滚**:逆操作编辑由已应用结果生成——不靠 LLM 重新猜测
28
- - **benchmark 闭环**:候选沉淀先经冻结用例 + 独立评分者评估再接受(rubric 加密落盘)
29
- - **store 卫生**:`/evolve consolidate` 把写入时冲突提示与零使用陈旧条目变成一次批准、完全可逆的批量归档——加 `merge` 可将近重复内容并入幸存原条目
19
+ Agent 每个会话积累的可复用经验(用户偏好、踩坑教训、项目背景)下个会话就忘。ZCode 用一个文件夹解决了这件事:一事一文的 md 记忆 + `MEMORY.md` 索引、开局注入、模型原生读写、没有任何专用机器。本插件把同一形态带给 DSH。
30
20
 
31
21
  ## 工作原理
32
22
 
33
- 1. **沉淀**——模型经 `evolve_add` 创建条目,或由专用 Memory Agent 消费成功回合后的增量 snapshot。通用 review/planner 保持手动,除非另行显式调用。
34
- 2. **能力感知的辅助调用**——memory loop、review、planner、wrapup、fate 通过 [`src/llm-text.ts`](src/llm-text.ts) 解析精确 provider/model 能力并使用模型公布的最低开启 reasoning effort,同时转发 host session id 供 provider 路由;只有没有开启档时才回退关闭档,没有 reasoning 元数据时使用 provider 默认行为。
35
- 3. **守卫**——代码强制校验:编辑 schema、blast-radius 与作用域一致性、晋升政策(项目专属标记 / 过薄内容 / 近似重复检测 / 凭据筛查保持全局库干净——密钥类内容在所有写入出口被拒,含 mount 物化)。全局 create 与既有条目高度相似(≥0.8)时写入即拒;中等重叠带 `conflictHint` 供后续合并。
36
- 4. **审批**——全局与项目写入需明确人工批准;弹窗展示有界结构化编辑 diff 与冲突提示,弹窗丢失/响应畸形会重试,不会被误记为拒绝。
37
- 5. **应用与注入**——memory 批次先完成所有持久化审批,写前重查 abort;后续 scope 失败时补偿回滚先前写入,成功 scope 仍保留快照与审计。prompt 补充与委派规格注入系统提示词(封顶、按相关性排序、被证伪条目降权、空 store 零 token);**memory 正文**在会话开场按硬预算注入(会话内冻结,when_to_save 指南随行);skill 仍以按相关性排序的目录索引出现。
38
- 6. **验证与回滚**——benchmark 用冻结用例为候选打分;被拒候选确定性回滚,并自动沉淀为 draft 回归用例(`auto_regression` 基准)。
23
+ 1. **开局注入** —— 插件只注册一个 system-prompt section:注入 `MEMORY.md` 索引正文(超预算按整行截断并提示读目录)、记忆目录绝对路径、when_to_save 指南。该 section 每会话只算一次并逐字节复用,system prompt 稳定、prompt cache 持续命中;空 store 零 token。
24
+ 2. **原生读写** —— DSH 对工作区内文件读写全放行(读路径从不设防,写围栏只围工作区外,见 [`docs/FAQ.md`](docs/FAQ.md) #6)。模型直接 Read/Write/Edit 记忆文件并维护索引;store 不存在时自动 bootstrap。
25
+ 3. **治理即文件** —— 无版本、无快照、无审批、无后台提取:一条坏记忆就是工作区里一个可见的文件,删掉它就是退役。记忆是个人上下文——bootstrap 时若工作区是 git 仓库会自动把 `.evolve/` 追加进 `.gitignore`(非 git 工作区不碰任何文件)。
26
+
27
+ 记忆文件格式(与 ZCode 一致):frontmatter 带 `name` / `description`(决定未来会话会不会想起它)/ `metadata.type`(`user | feedback | project | reference`);`feedback` 正文必带 **Why:** 与 **How to apply:**。
39
28
 
40
29
  ## 安装
41
30
 
@@ -51,111 +40,51 @@ dsh plugin add ZK-Andy/dsh-continual-evolve
51
40
 
52
41
  ## 使用
53
42
 
54
- 会话内命令:
55
-
56
- | 命令 | 效果 |
57
- |---|---|
58
- | `/evolve` | 简短帮助 + 当前 local store(`/evolve help all` 列全部子命令) |
59
- | `/evolve list · history · rollback <id>` | 查看与回滚(加 `project` 操作本项目库,`global` 操作跨项目库) |
60
- | `/evolve plan [msg]` | 对 store 运行 LLM 规划器 |
61
- | `/evolve wrapup` | 收尾本会话 local 条目:晋升 / 归档 / 保留 |
62
- | `/evolve archive · unarchive <id>` | 从注入中隐藏(数据保留可恢复) |
63
- | `/evolve consolidate [apply] [merge]` | 报告(或应用)冲突提示 + 零使用陈旧全局条目的批量归档;`merge` 将近重复内容并入幸存原条目 |
64
- | `/evolve failures` | 失败类聚合(门禁 + benchmark) |
65
- | `/evolve log [tail N] [session <id>]` | 插件日志 |
66
- | `/evolve export · import <path>` | 备份 / 恢复 store |
67
- | `/evolve mount · unmount <skillId>` | 把可执行技能热挂载为 live 插件 |
68
- | `/evolve goal [objective · done · block]` | 回合驱动的自进化目标 |
69
- | `/evolve benchmark …` | 用例生命周期、运行、接受决策 |
70
- | `/evolve pause · resume · status` | 暂停/恢复自动门禁(手动工具不受影响)、门禁状态 |
71
- | `/evolve usage` | 每条目注入次数 + memory/review/planner/wrapup/fate 直属调用的 provider 精确 token(不含 benchmark 宿主子代理) |
72
-
73
- 模型工具:`evolve_list / add / update / delete / rollback / recall`(`evolve_delete` 支持 `id` 或批量 `ids` 数组——一次 refinement、一次审批;`evolve_recall` 按 query/kind/scope/memoryType/limit 过滤,返回全文 + 版本 + 来源 + 过时信号)。记忆的读写都在对话里完成——模型手里有注入的记忆索引 + `evolve_recall`/`evolve_add`——因此不再有 `/evolve remember · forget · recall` 对应命令:直接在对话里说。
74
-
75
- 第三方消费:每次进化落地(门禁或手动)都会向 `reviews.jsonl` 追加结构化 `evolve_complete` 事件(shape 见 `src/evolve-event.ts`),与人类可读的审计记录并存。
76
-
77
- `/evolve usage` 还会读取 `evolve/token-usage.jsonl`:插件直属 memory Agent、review、planner、手动 wrapup 与自动 fate 调用的 provider 精确 input/cache/output/total token。报告只覆盖保留尾部而非终身累计,单独显示 provider 未返回 usage 的调用,并明确排除宿主 benchmark 子代理、其 agent-loop 调用与逐条 memory 注入归因。
78
-
79
- 注入形态:prompt 补充与委派规格带内容注入(每 kind ≤6 条 × 180 字符,按相关性排序)。memory 以**正文**在会话开场注入:`evolve:memory-index` section(order 400)承载 when_to_save 指南 + 预算内的全部记忆正文,排序 `project > feedback > user > reference`,放不下的降级为 `[memory:type:id] 标题`钩子、其余折叠计数(硬上限 `memoryIndex.maxChars`,默认 6000 字符;未展示的用 `evolve_recall` 读)。该 section 每会话只算一次并逐字节复用,system prompt 因此稳定、prompt cache 持续命中——会话中途写入的记忆下个会话生效。skill 仍以按相关性排序的目录索引出现(15 行封顶 + 折叠计数行),memory 不再列入。每次 memory 落盘同时刷新 store 目录下的可读 `MEMORY.md` 索引 + 单事实文件。`memoryIndex.guide` 关闭且 store 为空时 = 零注入 token。
43
+ 无需命令、无需工具。重启后第一场会话,`.evolve/memory/` 会自动生成,索引自动注入开场;对模型直接说"记住……"/"忘掉……"即可,写入的记忆文件 + 索引行就是全部持久状态。会话中途写入的记忆下个会话生效(会话内冻结守 prompt cache);需要立即查看时,模型直接读目录。
80
44
 
81
45
  ## 配置
82
46
 
83
47
  | 键 | 默认 | 含义 |
84
48
  |---|---|---|
85
- | `baseDir` | 解析后的 DSH home | `evolve/` 存储根目录 |
86
- | `autoReview` | `false` | 没有 `evolve/runtime.json` 时 Memory Agent 的初始默认;监听器始终注册,因此它不是注册门 |
87
- | `memoryMinUserWords` | `3` | ZCode 风格:单个直接用户文本至少包含的词数;使用 CJK 分词 |
88
- | `sessionCloseDrainMs` | `15000` | 会话关闭时在途提取的有界 drain(毫秒,`0` 立即 abort) |
89
- | `reviewIntervalTurns` | `6` | local-fate 的兼容节奏;成功回合 review 不再等待这个间隔 |
90
- | `maxReviewInputChars` | `40000` | 交给门禁的轨迹切片 |
91
- | `reviewBudgetTokens` | `4096` | 门禁调用输出预算 |
92
- | `notifyOnAutoReview` | `true` | 门禁应用后发可见跟进通知 |
93
- | `requireGlobalApproval` | `true` | 全局与项目写入需明确批准 |
94
- | `recordLanguage` | `auto` | 记录**与弹窗**语言:`auto` 依次跟随 DSH 客户端偏好 → 会话自身用户文本 → `en`;`zh`/`en` 固定 |
95
- | `localFate` | `false` | 可选的本地条目晋升/归档 fate 评估;listener 以 memory-only 运行时不可达,只对直接/完整调用者生效 |
96
- | `fateIntervalTurns` | 跟随 `reviewIntervalTurns` | 归宿评估的最小回合间隔 |
97
- | `goalBlockedWrapupTurns` | `3` | 连续阻塞目标的门禁轮数触发一次归宿评估(`0` 关闭) |
98
- | `promotionBlockPatterns` | POSIX 路径、session id、`~/.dsh` | 内容命中即判定项目专属,永不晋升全局 |
99
- | `promotionMinChars` | `100` | 低于此长度的整体晋升留在本地 |
100
- | `injectionDirectoryLines` | `15` | 每次构建的目录行数上限,超出折叠为计数行 |
101
- | `sectionOrder` | `118` | 指南与条目两个 section 的系统提示词顺序 |
102
- | `memoryIndex.enabled` | `true` | 是否注册 `evolve:memory-index` 内容 section |
103
- | `memoryIndex.guide` | `true` | 是否注入 when_to_save 指南(关闭且 store 为空时该 section 不渲染) |
104
- | `memoryIndex.order` | `400` | section 顺序(上游命名槽位自 `PLAN_POLICY=500` 起;本插件另两段在 118/119) |
105
- | `memoryIndex.maxChars` | `6000` | 注入记忆块的硬字符预算 |
106
- | `skillsDir` | `<dshHome>/skills` | 技能条目物化为 SKILL.md 的根目录 |
107
- | `rubricKey` | 自动生成本地密钥文件 | benchmark rubric 的 AES-256-GCM 口令(`DSH_EVOLVE_RUBRIC_KEY` 可覆盖) |
108
- | `logToFile` / `logLevel` / `logMaxBytes` | `true` / `1` / 5 MiB | 插件自带 JSONL 文件日志带轮转 |
109
- | `autoRollbackOnReject` | `true` | benchmark 拒绝后自动确定性回滚 |
110
- | `autoCase` | `true` | 失败的进化尝试自动沉淀为 draft 回归用例(`auto_regression` 基准) |
111
- | `reviewModel` | agent 自身 | 专用 memory Agent 与 review 门禁可选更便宜的模型(`"provider/model"`) |
112
- | `plannerPrefixCache` | `auto` | 有缓存证据时用会话前缀输入(`session` 总是前缀,`off` 保持旧扁平文本) |
113
- | `plannerPrefixMaxChars` | `12000` | Route A 会话前缀预算(字符) |
114
- | `historyRetain` | `{snapshots: 20, refinements: 500, reviews: 500, tokenUsage: 500}` | 存储卫生:每 store 快照数、每 store 历史尾行、共享 `reviews.jsonl` 尾行、直属调用 `token-usage.jsonl` 尾行 |
49
+ | `memoryIndex.enabled` | `true` | 是否注册记忆 section |
50
+ | `memoryIndex.guide` | `true` | 是否注入 when_to_save 指南(关闭且索引为空时该 section 零 token) |
51
+ | `memoryIndex.order` | `400` | section 顺序(上游命名槽位自 `PLAN_POLICY=500` 起) |
52
+ | `memoryIndex.maxChars` | `6000` | 注入索引的硬字符预算 |
115
53
 
116
54
  profile patch 示例:
117
55
 
118
56
  ```yaml
119
57
  - id: continual-evolve
120
58
  config:
121
- autoReview: true
122
- reviewIntervalTurns: 6
59
+ memoryIndex:
60
+ maxChars: 8000
123
61
  ```
124
62
 
125
- 即使 `autoReview` 为 `false`,Memory Agent 监听器也会注册——`autoReview` 只提供初始默认值,装完即用,无需改 profile。使用 `/evolve resume` 立即开启成功回合 snapshot,使用 `/evolve pause` 抑制新 snapshot 与模型调用,使用 `/evolve status` 查看配置默认值与运行时状态。开关保存在 `evolve/runtime.json`;手动 `evolve_*` 工具和 `/evolve` 命令不受暂停影响。自动运行只有 Memory Agent:通用 review/planner、prompt/skill 写入与 local fate 都不由该 listener 触达。Memory 触发采用 ZCode 的轻量 eligibility:单个直接用户文本至少包含 `memoryMinUserWords` 个词(使用 CJK 分词);空增量、内部 Agent、直接 memory 写入会跳过,压缩不会额外触发 memory-only 管线。每次提取都在 `reviews.jsonl` 留统一审计回执(`noop`/`applied`/`declined` + 耗时与轮次/检索统计);只有实际沉淀才排队前台通知,关闭的会话让在途提取在 `sessionCloseDrainMs` 内收尾再 abort。
126
-
127
63
  ## 开发
128
64
 
129
65
  ```bash
130
66
  pnpm install && pnpm build # 依赖 + tsc -> lib/
131
- pnpm test # vitest(1097 例)
67
+ pnpm test # vitest(32 例)
132
68
  pnpm test:coverage # v8 覆盖率,CI 强制阈值
133
- pnpm coverage:gaps # 定位各文件未覆盖行(只读)
134
69
  pnpm lint # oxlint src test
135
70
  ```
136
71
 
137
72
  目录结构:
138
73
 
139
74
  ```
140
- ├── src/ # 引擎、工具、命令、memory Agent、召回、投影、门禁、fate、benchmark、注入 + token 用量…
141
- ├── test/ # vitest 测试套件(59 个文件)
75
+ ├── src/
76
+ │ ├── index.ts # 注册:唯一 section + 配置
77
+ │ ├── memory-section.ts # 注入:读索引 / bootstrap / 截断 / 会话冻结
78
+ │ └── memory-guide.ts # 指南:when_to_save 与维护纪律(改编自 ZCode)
79
+ ├── test/ # vitest 测试(3 个文件)
142
80
  ├── lib/ # 构建产物(tsc)
143
- ├── docs/
144
- │ ├── design.md # 完整设计文档(硬化矩阵)
145
- │ ├── FAQ.md # 真实踩坑记录
146
- │ ├── gap-analysis.md # 对照 prime-agent /refine + penguin-harness
147
- │ ├── research/pi-dsh-competitor-gap-analysis.md # pi/dsh 生态竞品差距分析
148
- │ ├── experiment-bootstrap.md
149
- │ ├── archive/ # 已完结的一次性报告
150
- │ └── research/ # penguin 报告 + prime-agent 注释源码
151
- ├── examples/README.md # 种子 benchmark 用例
81
+ ├── docs/ # design.md(设计)· FAQ.md(踩坑)
152
82
  └── .agents/ # AI 协作层(AGENTS.md、技能、ADR 笔记)
153
83
  ```
154
84
 
155
- ## 文档与出处
85
+ ## 文档
156
86
 
157
- - 设计:[`docs/design.md`](docs/design.md) · 踩坑:[`docs/FAQ.md`](docs/FAQ.md) · 差距分析:[`docs/gap-analysis.md`](docs/gap-analysis.md) · D2 实验:[`docs/experiment-bootstrap.md`](docs/experiment-bootstrap.md)
158
- - 血统:**penguin-harness**(概念;Apache-2.0)——报告见 [`docs/research/penguin-harness-self-evolution.md`](docs/research/penguin-harness-self-evolution.md);**prime-agent `/refine`**(工程形态;MIT)——注释参考源码见 [`docs/research/prime-agent-refinement.ts`](docs/research/prime-agent-refinement.ts)。本包是面向 DSH 插件表面的原创实现。
87
+ - 设计:[`docs/design.md`](docs/design.md) · 踩坑:[`docs/FAQ.md`](docs/FAQ.md) · 拆解决策:[`.agents/notes/implemented/architecture/2026-10-04-zcode-alignment-teardown.md`](.agents/notes/implemented/architecture/2026-10-04-zcode-alignment-teardown.md)
159
88
 
160
89
  ## License
161
90
 
package/cordis.patch.yml CHANGED
@@ -2,8 +2,8 @@
2
2
  #
3
3
  # Installed via `dsh plugin --profile <name> add dsh-continual-evolve`, this
4
4
  # patch inserts the plugin row so it activates without manual profile editing.
5
- # Conservative defaults: the auto-review gate is OFF (opt in via your profile
6
- # cordis.patch.yml config) and cross-session edits require human approval.
5
+ # The plugin only registers a session-start memory section (workspace
6
+ # .evolve/memory, native file read/write); no gate is ever ON by default.
7
7
  - insert:
8
8
  - id: continual-evolve
9
9
  name: 'dsh-continual-evolve'