dsh-continual-evolve 0.7.5 → 0.8.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.
- package/README.md +32 -21
- package/README.zh.md +16 -11
- package/lib/auto.d.ts +31 -2
- package/lib/auto.js +124 -6
- package/lib/command.d.ts +4 -3
- package/lib/command.js +100 -16
- package/lib/index.d.ts +12 -4
- package/lib/index.js +38 -40
- package/lib/memory-agent.d.ts +1 -1
- package/lib/memory-agent.js +1 -0
- package/lib/memory-benchmark.d.ts +76 -0
- package/lib/memory-benchmark.js +170 -0
- package/lib/notify.d.ts +27 -0
- package/lib/notify.js +53 -0
- package/lib/projection.d.ts +22 -0
- package/lib/projection.js +112 -0
- package/lib/recall.d.ts +85 -0
- package/lib/recall.js +142 -0
- package/lib/service.js +14 -0
- package/lib/tool.js +40 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://github.com/ZK-Andy/dsh-continual-evolve/actions/workflows/ci.yml)
|
|
8
8
|
[](LICENSE)
|
|
9
9
|
[](package.json)
|
|
10
|
-
[]()
|
|
11
11
|
|
|
12
12
|
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.
|
|
13
13
|
|
|
@@ -19,14 +19,15 @@ Agents accumulate reusable experience (repeated failures, durable facts, reusabl
|
|
|
19
19
|
|
|
20
20
|
- **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
|
|
21
21
|
- **Typed one-fact memories**: every memory entry carries a recall type (`user | feedback | project | reference`); pitfalls (`feedback`) must include Why + How to apply
|
|
22
|
-
- **Dedicated background memory agent**:
|
|
22
|
+
- **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
|
|
23
|
+
- **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
|
|
23
24
|
- **Deterministic rollback**: inverse edits generated from applied results — no LLM re-guessing
|
|
24
25
|
- **Benchmark loop**: candidate refinements are evaluated against frozen cases by a separate scorer before acceptance (rubric encrypted at rest)
|
|
25
26
|
- **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
|
|
26
27
|
|
|
27
28
|
## How it works
|
|
28
29
|
|
|
29
|
-
1. **Sediment** — the model creates entries via `evolve_add`, or
|
|
30
|
+
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.
|
|
30
31
|
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.
|
|
31
32
|
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.
|
|
32
33
|
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.
|
|
@@ -56,6 +57,9 @@ Commands (in-session):
|
|
|
56
57
|
| `/evolve plan [msg]` | run the LLM planner against the store |
|
|
57
58
|
| `/evolve wrapup` | assess this session's local entries: promote / archive / keep |
|
|
58
59
|
| `/evolve archive · unarchive · demote <id>` | hide from injection (data kept, restorable) — `demote` targets global noise |
|
|
60
|
+
| `/evolve recall [scope] <query…>` | targeted memory recall: full content with version, source, and staleness |
|
|
61
|
+
| `/evolve remember <type> [scope] <text…>` | immediately persist one typed memory (`user|feedback|project|reference`) |
|
|
62
|
+
| `/evolve forget [scope] <query…>` | locate one memory and archive it (restorable); ambiguous queries only list |
|
|
59
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 |
|
|
60
64
|
| `/evolve failures` | aggregated failure classes (gate + benchmark) |
|
|
61
65
|
| `/evolve log [tail N] [session <id>]` | plugin log |
|
|
@@ -66,27 +70,28 @@ Commands (in-session):
|
|
|
66
70
|
| `/evolve pause · resume · status` | pause/resume the auto-review gate (manual tools keep working), gate state |
|
|
67
71
|
| `/evolve usage` | per-entry injection counts + exact provider-reported tokens for direct memory/review/planner/wrapup/fate calls (benchmark host subagents excluded) |
|
|
68
72
|
|
|
69
|
-
Model tools: `evolve_list / add / update / delete / rollback` (`evolve_delete` takes `id` or a batch `ids` array — one refinement, one approval).
|
|
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).
|
|
70
74
|
|
|
71
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.
|
|
72
76
|
|
|
73
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.
|
|
74
78
|
|
|
75
|
-
Injection shape: prompt notes and delegation specs inject with content (≤6/kind × 180 chars, relevance-ranked). Memories and skills appear as a relevance-ordered directory index (`[memory:type:id] title` hooks, capped at 15 lines with a fold counter) — full text via `evolve_list`. Empty store = zero injected tokens.
|
|
79
|
+
Injection shape: prompt notes and delegation specs inject with content (≤6/kind × 180 chars, relevance-ranked). Memories and skills appear as a relevance-ordered directory index (`[memory:type:id] title` hooks, capped at 15 lines with a fold counter) — full text via `evolve_recall` (targeted) or `evolve_list`. Every memory apply also refreshes a readable `MEMORY.md` index plus one fact file per entry in the store directory. Empty store = zero injected tokens.
|
|
76
80
|
|
|
77
81
|
## Configuration
|
|
78
82
|
|
|
79
83
|
| Key | Default | Meaning |
|
|
80
84
|
|---|---|---|
|
|
81
85
|
| `baseDir` | resolved DSH home | root for the `evolve/` stores |
|
|
82
|
-
| `autoReview` | `false` |
|
|
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 |
|
|
83
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) |
|
|
84
89
|
| `reviewIntervalTurns` | `6` | legacy local-fate cadence fallback; successful-turn review no longer waits for this interval |
|
|
85
90
|
| `maxReviewInputChars` | `40000` | trajectory slice handed to the gate |
|
|
86
91
|
| `reviewBudgetTokens` | `4096` | output budget for the gate call |
|
|
87
92
|
| `notifyOnAutoReview` | `true` | visible follow-up notice after an applied gate run |
|
|
88
93
|
| `requireGlobalApproval` | `true` | global and project edits ask for explicit approval |
|
|
89
|
-
| `localFate` | `false` | optional local-entry promote/archive fate assessment;
|
|
94
|
+
| `localFate` | `false` | optional local-entry promote/archive fate assessment; unreachable while the listener runs memory-only, so it only affects direct/full callers |
|
|
90
95
|
| `fateIntervalTurns` | follows `reviewIntervalTurns` | minimum turns between fate assessments |
|
|
91
96
|
| `goalBlockedWrapupTurns` | `3` | consecutive blocked-goal gate runs trigger one fate assessment (`0` disables) |
|
|
92
97
|
| `promotionBlockPatterns` | POSIX paths, session ids, `~/.dsh` | content matching these is project-scoped and never promoted to global |
|
|
@@ -112,23 +117,29 @@ Example profile patch:
|
|
|
112
117
|
reviewIntervalTurns: 6
|
|
113
118
|
```
|
|
114
119
|
|
|
115
|
-
|
|
116
|
-
`autoReview
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
120
|
+
The Memory Agent listener is registered even when `autoReview` is `false` —
|
|
121
|
+
`autoReview` only supplies the initial default, so an install works without
|
|
122
|
+
editing the profile. Use `/evolve resume` to enable successful-turn snapshots
|
|
123
|
+
immediately, `/evolve pause` to suppress new snapshots and model work, and
|
|
124
|
+
`/evolve status` to inspect the configured default plus the current runtime
|
|
125
|
+
state. The runtime switch is stored in `evolve/runtime.json`; manual `evolve_*`
|
|
126
|
+
tools and `/evolve` commands are not paused. Only the Memory Agent runs
|
|
127
|
+
automatically: the generic review/planner, prompt/skill writes, and local-fate
|
|
128
|
+
phases are not reachable from this listener. The memory trigger follows ZCode's
|
|
129
|
+
lightweight eligibility: direct user text must contain at least
|
|
130
|
+
`memoryMinUserWords` lexical words (CJK-aware segmentation), while
|
|
131
|
+
empty/internal/direct-memory-write snapshots are skipped; compaction does not
|
|
132
|
+
add a separate memory-only trigger. Every extraction writes a unified audit
|
|
133
|
+
receipt (`noop`/`applied`/`declined` with duration and turn/search stats) to
|
|
134
|
+
`reviews.jsonl`; only applied outcomes queue a visible follow-up, and a
|
|
135
|
+
closing session lets in-flight extraction settle up to `sessionCloseDrainMs`
|
|
136
|
+
before aborting.
|
|
126
137
|
|
|
127
138
|
## Development
|
|
128
139
|
|
|
129
140
|
```bash
|
|
130
141
|
pnpm install && pnpm build # deps + tsc -> lib/
|
|
131
|
-
pnpm test # vitest (
|
|
142
|
+
pnpm test # vitest (783 tests)
|
|
132
143
|
pnpm test:coverage # v8 coverage, thresholds enforced in CI
|
|
133
144
|
pnpm lint # oxlint src test
|
|
134
145
|
```
|
|
@@ -136,8 +147,8 @@ pnpm lint # oxlint src test
|
|
|
136
147
|
Project layout:
|
|
137
148
|
|
|
138
149
|
```
|
|
139
|
-
├── src/ # engine, tools, commands, memory agent, gate, fate, benchmark, injection + token usage…
|
|
140
|
-
├── test/ # vitest suites (
|
|
150
|
+
├── src/ # engine, tools, commands, memory agent, recall, projection, gate, fate, benchmark, injection + token usage…
|
|
151
|
+
├── test/ # vitest suites (47 files)
|
|
141
152
|
├── lib/ # build output (tsc)
|
|
142
153
|
├── docs/
|
|
143
154
|
│ ├── design.md # full design doc (hardening matrix)
|
package/README.zh.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://github.com/ZK-Andy/dsh-continual-evolve/actions/workflows/ci.yml)
|
|
8
8
|
[](LICENSE)
|
|
9
9
|
[](package.json)
|
|
10
|
-
[]()
|
|
11
11
|
|
|
12
12
|
[DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(`dsh`)的持续自进化插件:一套**版本化、可审计、可回滚**的 harness 状态层——提示词补充、记忆、技能、子代理规格——从会话轨迹中沉淀而来。
|
|
13
13
|
|
|
@@ -19,14 +19,15 @@ Agent 在每个会话里积累可复用经验(重复失败、持久事实、
|
|
|
19
19
|
|
|
20
20
|
- **三作用域**与合并语义(global < project < local):**local** 本会话暂存、**project** 本项目跨会话库、**global** 跨项目——配合机械化晋升守卫,只有可携带、有分量、非重复的知识才能进全局
|
|
21
21
|
- **类型化单条记忆**:每条 memory 带召回类型(`user | feedback | project | reference`);踩坑(`feedback`)必须含 Why + How to apply
|
|
22
|
-
- **专用后台记忆 Agent
|
|
22
|
+
- **专用后台记忆 Agent**:成功回合通过机械 eligibility 后,有界 ZCode 式 loop 检索冻结的 memory manifest,并经闭集工具提出纯 memory 编辑;不能调用 Agent、MCP、网络,也不能写源码。该 listener 不运行通用 review/planner/fate
|
|
23
|
+
- **记忆召回、投影与回执**:`evolve_recall` 按 query/kind/scope/type 精确读回记忆全文;每次 memory 落盘同时生成可读的 `MEMORY.md` 索引 + 单事实文件;每次提取留统一审计回执(no-op/applied/declined + 耗时与轮次统计),只有实际沉淀才通知会话
|
|
23
24
|
- **确定性回滚**:逆操作编辑由已应用结果生成——不靠 LLM 重新猜测
|
|
24
25
|
- **benchmark 闭环**:候选沉淀先经冻结用例 + 独立评分者评估再接受(rubric 加密落盘)
|
|
25
26
|
- **store 卫生**:`/evolve consolidate` 把写入时冲突提示与零使用陈旧条目变成一次批准、完全可逆的批量归档——加 `merge` 可将近重复内容并入幸存原条目
|
|
26
27
|
|
|
27
28
|
## 工作原理
|
|
28
29
|
|
|
29
|
-
1. **沉淀**——模型经 `evolve_add`
|
|
30
|
+
1. **沉淀**——模型经 `evolve_add` 创建条目,或由专用 Memory Agent 消费成功回合后的增量 snapshot。通用 review/planner 保持手动,除非另行显式调用。
|
|
30
31
|
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 默认行为。
|
|
31
32
|
3. **守卫**——代码强制校验:编辑 schema、blast-radius 与作用域一致性、晋升政策(项目专属标记 / 过薄内容 / 近似重复检测 / 凭据筛查保持全局库干净——密钥类内容在所有写入出口被拒,含 mount 物化)。全局 create 与既有条目高度相似(≥0.8)时写入即拒;中等重叠带 `conflictHint` 供后续合并。
|
|
32
33
|
4. **审批**——全局与项目写入需明确人工批准;弹窗展示有界结构化编辑 diff 与冲突提示,弹窗丢失/响应畸形会重试,不会被误记为拒绝。
|
|
@@ -56,6 +57,9 @@ dsh plugin add ZK-Andy/dsh-continual-evolve
|
|
|
56
57
|
| `/evolve plan [msg]` | 对 store 运行 LLM 规划器 |
|
|
57
58
|
| `/evolve wrapup` | 收尾本会话 local 条目:晋升 / 归档 / 保留 |
|
|
58
59
|
| `/evolve archive · unarchive · demote <id>` | 从注入中隐藏(数据保留可恢复)——`demote` 针对全局噪声 |
|
|
60
|
+
| `/evolve recall [scope] <query…>` | 定向记忆召回:全文 + 版本 + 来源 + 过时信号 |
|
|
61
|
+
| `/evolve remember <type> [scope] <text…>` | 立即持久化一条类型化记忆(`user|feedback|project|reference`) |
|
|
62
|
+
| `/evolve forget [scope] <query…>` | 按 query 定位一条记忆并归档(可恢复);多义只列候选不写 |
|
|
59
63
|
| `/evolve consolidate [apply] [merge]` | 报告(或应用)冲突提示 + 零使用陈旧全局条目的批量归档;`merge` 将近重复内容并入幸存原条目 |
|
|
60
64
|
| `/evolve failures` | 失败类聚合(门禁 + benchmark) |
|
|
61
65
|
| `/evolve log [tail N] [session <id>]` | 插件日志 |
|
|
@@ -66,27 +70,28 @@ dsh plugin add ZK-Andy/dsh-continual-evolve
|
|
|
66
70
|
| `/evolve pause · resume · status` | 暂停/恢复自动门禁(手动工具不受影响)、门禁状态 |
|
|
67
71
|
| `/evolve usage` | 每条目注入次数 + memory/review/planner/wrapup/fate 直属调用的 provider 精确 token(不含 benchmark 宿主子代理) |
|
|
68
72
|
|
|
69
|
-
模型工具:`evolve_list / add / update / delete / rollback`(`evolve_delete` 支持 `id` 或批量 `ids` 数组——一次 refinement
|
|
73
|
+
模型工具:`evolve_list / add / update / delete / rollback / recall`(`evolve_delete` 支持 `id` 或批量 `ids` 数组——一次 refinement、一次审批;`evolve_recall` 按 query/kind/scope/memoryType/limit 过滤,返回全文 + 版本 + 来源 + 过时信号)。
|
|
70
74
|
|
|
71
75
|
第三方消费:每次进化落地(门禁或手动)都会向 `reviews.jsonl` 追加结构化 `evolve_complete` 事件(shape 见 `src/evolve-event.ts`),与人类可读的审计记录并存。
|
|
72
76
|
|
|
73
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 注入归因。
|
|
74
78
|
|
|
75
|
-
注入形态:prompt 补充与委派规格带内容注入(每 kind ≤6 条 × 180 字符,按相关性排序)。memory/skill 以按相关性排序的目录索引出现(`[memory:type:id] 标题`钩子,15 行封顶 + 折叠计数行)——全文经 `evolve_list`
|
|
79
|
+
注入形态:prompt 补充与委派规格带内容注入(每 kind ≤6 条 × 180 字符,按相关性排序)。memory/skill 以按相关性排序的目录索引出现(`[memory:type:id] 标题`钩子,15 行封顶 + 折叠计数行)——全文经 `evolve_recall`(精确)或 `evolve_list` 获取。每次 memory 落盘同时刷新 store 目录下的可读 `MEMORY.md` 索引 + 单事实文件。空 store = 零注入 token。
|
|
76
80
|
|
|
77
81
|
## 配置
|
|
78
82
|
|
|
79
83
|
| 键 | 默认 | 含义 |
|
|
80
84
|
|---|---|---|
|
|
81
85
|
| `baseDir` | 解析后的 DSH home | `evolve/` 存储根目录 |
|
|
82
|
-
| `autoReview` | `false` |
|
|
86
|
+
| `autoReview` | `false` | 没有 `evolve/runtime.json` 时 Memory Agent 的初始默认;监听器始终注册,因此它不是注册门 |
|
|
83
87
|
| `memoryMinUserWords` | `3` | ZCode 风格:单个直接用户文本至少包含的词数;使用 CJK 分词 |
|
|
88
|
+
| `sessionCloseDrainMs` | `15000` | 会话关闭时在途提取的有界 drain(毫秒,`0` 立即 abort) |
|
|
84
89
|
| `reviewIntervalTurns` | `6` | local-fate 的兼容节奏;成功回合 review 不再等待这个间隔 |
|
|
85
90
|
| `maxReviewInputChars` | `40000` | 交给门禁的轨迹切片 |
|
|
86
91
|
| `reviewBudgetTokens` | `4096` | 门禁调用输出预算 |
|
|
87
92
|
| `notifyOnAutoReview` | `true` | 门禁应用后发可见跟进通知 |
|
|
88
93
|
| `requireGlobalApproval` | `true` | 全局与项目写入需明确批准 |
|
|
89
|
-
| `localFate` | `false` | 可选的本地条目晋升/归档 fate
|
|
94
|
+
| `localFate` | `false` | 可选的本地条目晋升/归档 fate 评估;listener 以 memory-only 运行时不可达,只对直接/完整调用者生效 |
|
|
90
95
|
| `fateIntervalTurns` | 跟随 `reviewIntervalTurns` | 归宿评估的最小回合间隔 |
|
|
91
96
|
| `goalBlockedWrapupTurns` | `3` | 连续阻塞目标的门禁轮数触发一次归宿评估(`0` 关闭) |
|
|
92
97
|
| `promotionBlockPatterns` | POSIX 路径、session id、`~/.dsh` | 内容命中即判定项目专属,永不晋升全局 |
|
|
@@ -112,13 +117,13 @@ profile patch 示例:
|
|
|
112
117
|
reviewIntervalTurns: 6
|
|
113
118
|
```
|
|
114
119
|
|
|
115
|
-
|
|
120
|
+
即使 `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。
|
|
116
121
|
|
|
117
122
|
## 开发
|
|
118
123
|
|
|
119
124
|
```bash
|
|
120
125
|
pnpm install && pnpm build # 依赖 + tsc -> lib/
|
|
121
|
-
pnpm test # vitest(
|
|
126
|
+
pnpm test # vitest(783 例)
|
|
122
127
|
pnpm test:coverage # v8 覆盖率,CI 强制阈值
|
|
123
128
|
pnpm lint # oxlint src test
|
|
124
129
|
```
|
|
@@ -126,8 +131,8 @@ pnpm lint # oxlint src test
|
|
|
126
131
|
目录结构:
|
|
127
132
|
|
|
128
133
|
```
|
|
129
|
-
├── src/ # 引擎、工具、命令、memory Agent
|
|
130
|
-
├── test/ # vitest 测试套件(
|
|
134
|
+
├── src/ # 引擎、工具、命令、memory Agent、召回、投影、门禁、fate、benchmark、注入 + token 用量…
|
|
135
|
+
├── test/ # vitest 测试套件(47 个文件)
|
|
131
136
|
├── lib/ # 构建产物(tsc)
|
|
132
137
|
├── docs/
|
|
133
138
|
│ ├── design.md # 完整设计文档(硬化矩阵)
|
package/lib/auto.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
|
4
4
|
import type { HarnessState, RefinementEdit, RefinementProposal } from "./types.js";
|
|
5
5
|
import type { EvolutionEngine } from "./service.js";
|
|
6
6
|
import { type AutoRefineReason } from "./review.js";
|
|
7
|
+
import { type ReviewScheduler } from "./review-scheduler.js";
|
|
7
8
|
import { type TurnSnapshot } from "./turn-snapshot.js";
|
|
8
9
|
import type { PromotionPolicy } from "./promotion.js";
|
|
9
10
|
import type { PlannerPrefixCacheMode } from "./prefix-cache.js";
|
|
@@ -78,6 +79,12 @@ export interface AutoReviewConfig {
|
|
|
78
79
|
* window, not the full past).
|
|
79
80
|
*/
|
|
80
81
|
reviewsRetain?: number;
|
|
82
|
+
/**
|
|
83
|
+
* Session-close bounded drain (P1): how long a disposed session's
|
|
84
|
+
* in-flight extraction may settle before its owner signal aborts.
|
|
85
|
+
* Absent → 15s; 0 restores the legacy immediate abort.
|
|
86
|
+
*/
|
|
87
|
+
sessionCloseDrainMs?: number;
|
|
81
88
|
}
|
|
82
89
|
export interface GateState {
|
|
83
90
|
turns: number;
|
|
@@ -114,14 +121,36 @@ export interface GateState {
|
|
|
114
121
|
}
|
|
115
122
|
/** Turns a rejected skill candidate stays silent before being offered again. */
|
|
116
123
|
export declare const SKILL_CONSULT_COOLDOWN_TURNS = 10;
|
|
124
|
+
/** Default session-close drain budget: an in-flight extraction gets 15s to settle. */
|
|
125
|
+
export declare const SESSION_CLOSE_DRAIN_MS_DEFAULT = 15000;
|
|
126
|
+
/**
|
|
127
|
+
* Resolve the session-close drain budget: absent/invalid → default, 0 →
|
|
128
|
+
* immediate abort (legacy). Negative or non-finite values fail back to the
|
|
129
|
+
* default rather than silently disabling the drain.
|
|
130
|
+
*/
|
|
131
|
+
export declare function resolveSessionCloseDrainMs(raw?: number): number;
|
|
132
|
+
/**
|
|
133
|
+
* Bounded session-close drain for one scheduler: wait for in-flight work up
|
|
134
|
+
* to drainMs, then abort the owner signal and drop pending captures. Never
|
|
135
|
+
* rejects — disposal must not hang the host on a stuck model call, and the
|
|
136
|
+
* abort below is idempotent when the drain already settled.
|
|
137
|
+
*/
|
|
138
|
+
export declare function drainSchedulerOnDispose(scheduler: Pick<ReviewScheduler<TurnSnapshot>, "drain" | "shutdown">, drainMs: number): Promise<void>;
|
|
117
139
|
export interface ReviewRecord {
|
|
118
140
|
timestamp: string;
|
|
119
141
|
sessionId: string;
|
|
120
142
|
reason: AutoRefineReason;
|
|
121
143
|
turnsSinceLastReview: number;
|
|
122
|
-
outcome: "approved" | "declined" | "failed" | "assessed" | "deferred" | "skipped" | "armed";
|
|
144
|
+
outcome: "approved" | "declined" | "failed" | "assessed" | "deferred" | "skipped" | "armed" | "applied" | "noop";
|
|
123
145
|
rationale?: string;
|
|
124
146
|
refinementId?: string;
|
|
147
|
+
/** P1 extraction stats (§6.7): wall time of the memory phase. */
|
|
148
|
+
durationMs?: number;
|
|
149
|
+
/** Extractor loop turns / manifest searches behind this row. */
|
|
150
|
+
memoryTurns?: number;
|
|
151
|
+
memorySearches?: number;
|
|
152
|
+
/** Applied edit count carried by an applied row. */
|
|
153
|
+
appliedEdits?: number;
|
|
125
154
|
}
|
|
126
155
|
export declare function registerAutoReview(ctx: Context, engine: EvolutionEngine, config: AutoReviewConfig): void;
|
|
127
156
|
/**
|
|
@@ -167,7 +196,7 @@ export declare function runGoalBlockedFate(ctx: Context, engine: EvolutionEngine
|
|
|
167
196
|
* successful/no-op memory outcome; later review/fate failures do not replay
|
|
168
197
|
* old memory decisions, while memory failures leave the boundary retryable.
|
|
169
198
|
*/
|
|
170
|
-
export declare function runMemoryExtractionPhase(ctx: Context, engine: EvolutionEngine, agent: Agent, config: AutoReviewConfig, state: GateState, snapshot: TurnSnapshot, signal?: AbortSignal): Promise<void>;
|
|
199
|
+
export declare function runMemoryExtractionPhase(ctx: Context, engine: EvolutionEngine, agent: Agent, config: AutoReviewConfig, state: GateState, snapshot: TurnSnapshot, record: (entry: Omit<ReviewRecord, "timestamp">) => void, signal?: AbortSignal): Promise<void>;
|
|
171
200
|
/** True when the general planner returned only edits owned by the memory phase. */
|
|
172
201
|
export declare function isDedicatedMemoryOnlyProposal(proposal: RefinementProposal): boolean;
|
|
173
202
|
/**
|
package/lib/auto.js
CHANGED
|
@@ -23,7 +23,7 @@ import { slug } from "./types.js";
|
|
|
23
23
|
import { planWithLlm } from "./planner.js";
|
|
24
24
|
import { reviewAutoRefine } from "./review.js";
|
|
25
25
|
import { goalServiceOf } from "./goal.js";
|
|
26
|
-
import { notifyAutoReview } from "./notify.js";
|
|
26
|
+
import { notifyAutoReview, notifyMemoryExtraction } from "./notify.js";
|
|
27
27
|
import { runLocalFatePhase } from "./fate.js";
|
|
28
28
|
import { mergeHarnessStates } from "./state.js";
|
|
29
29
|
import { projectKeyOf } from "./project.js";
|
|
@@ -38,6 +38,52 @@ import { applyMemoryExtractionProposal, buildMemoryManifest, runMemoryAgent, } f
|
|
|
38
38
|
import { asLlmSessionId } from "./llm-text.js";
|
|
39
39
|
/** Turns a rejected skill candidate stays silent before being offered again. */
|
|
40
40
|
export const SKILL_CONSULT_COOLDOWN_TURNS = 10;
|
|
41
|
+
/** Default session-close drain budget: an in-flight extraction gets 15s to settle. */
|
|
42
|
+
export const SESSION_CLOSE_DRAIN_MS_DEFAULT = 15000;
|
|
43
|
+
/**
|
|
44
|
+
* Resolve the session-close drain budget: absent/invalid → default, 0 →
|
|
45
|
+
* immediate abort (legacy). Negative or non-finite values fail back to the
|
|
46
|
+
* default rather than silently disabling the drain.
|
|
47
|
+
*/
|
|
48
|
+
export function resolveSessionCloseDrainMs(raw) {
|
|
49
|
+
if (raw === undefined)
|
|
50
|
+
return SESSION_CLOSE_DRAIN_MS_DEFAULT;
|
|
51
|
+
if (typeof raw !== "number" || !Number.isFinite(raw) || raw < 0)
|
|
52
|
+
return SESSION_CLOSE_DRAIN_MS_DEFAULT;
|
|
53
|
+
return Math.floor(raw);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Bounded session-close drain for one scheduler: wait for in-flight work up
|
|
57
|
+
* to drainMs, then abort the owner signal and drop pending captures. Never
|
|
58
|
+
* rejects — disposal must not hang the host on a stuck model call, and the
|
|
59
|
+
* abort below is idempotent when the drain already settled.
|
|
60
|
+
*/
|
|
61
|
+
export function drainSchedulerOnDispose(scheduler, drainMs) {
|
|
62
|
+
if (drainMs <= 0) {
|
|
63
|
+
try {
|
|
64
|
+
scheduler.shutdown();
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// shutdown is flag-setting plus abort: nothing observable to do
|
|
68
|
+
}
|
|
69
|
+
return Promise.resolve();
|
|
70
|
+
}
|
|
71
|
+
let timer;
|
|
72
|
+
const timeout = new Promise((resolve) => {
|
|
73
|
+
timer = setTimeout(resolve, drainMs);
|
|
74
|
+
});
|
|
75
|
+
const settle = () => {
|
|
76
|
+
if (timer !== undefined)
|
|
77
|
+
clearTimeout(timer);
|
|
78
|
+
try {
|
|
79
|
+
scheduler.shutdown();
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// same as above — the abort is best-effort by design
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
return Promise.race([scheduler.drain(), timeout]).then(settle, settle);
|
|
86
|
+
}
|
|
41
87
|
export function registerAutoReview(ctx, engine, config) {
|
|
42
88
|
const perSession = new Map();
|
|
43
89
|
const schedulers = new Map();
|
|
@@ -82,7 +128,7 @@ export function registerAutoReview(ctx, engine, config) {
|
|
|
82
128
|
}
|
|
83
129
|
try {
|
|
84
130
|
if (config.memoryOnly) {
|
|
85
|
-
await runMemoryExtractionPhase(ctx, engine, agent, config, state, snapshot, signal);
|
|
131
|
+
await runMemoryExtractionPhase(ctx, engine, agent, config, state, snapshot, record, signal);
|
|
86
132
|
}
|
|
87
133
|
else {
|
|
88
134
|
await runGate(ctx, engine, agent, config, state, snapshot, record, signal);
|
|
@@ -193,10 +239,17 @@ export function registerAutoReview(ctx, engine, config) {
|
|
|
193
239
|
if (!agent)
|
|
194
240
|
return;
|
|
195
241
|
disposedSessions.add(agent.id);
|
|
196
|
-
schedulers.get(agent.id)
|
|
242
|
+
const scheduler = schedulers.get(agent.id);
|
|
197
243
|
schedulers.delete(agent.id);
|
|
198
244
|
captureTails.delete(agent.id);
|
|
199
245
|
perSession.delete(agent.id);
|
|
246
|
+
if (scheduler) {
|
|
247
|
+
// Bounded drain (P1): an in-flight extraction gets drainMs to
|
|
248
|
+
// settle so its result is not lost on session close; afterwards
|
|
249
|
+
// the owner signal aborts. Fire-and-forget — disposal must never
|
|
250
|
+
// hang the host, and the helper never rejects.
|
|
251
|
+
void drainSchedulerOnDispose(scheduler, resolveSessionCloseDrainMs(config.sessionCloseDrainMs));
|
|
252
|
+
}
|
|
200
253
|
});
|
|
201
254
|
ctx.on("session/event", (session, event) => {
|
|
202
255
|
// ZCode schedules extraction from successful turns, not from compaction.
|
|
@@ -295,7 +348,7 @@ async function runGate(ctx, engine, agent, config, state, snapshot, record, sign
|
|
|
295
348
|
}
|
|
296
349
|
state.running = true;
|
|
297
350
|
try {
|
|
298
|
-
await runMemoryExtractionPhase(ctx, engine, agent, config, state, snapshot, signal);
|
|
351
|
+
await runMemoryExtractionPhase(ctx, engine, agent, config, state, snapshot, record, signal);
|
|
299
352
|
await runReviewPhase(ctx, engine, agent, config, state, snapshot, record, signal);
|
|
300
353
|
// D3: a goal stuck in "blocked" for consecutive gate runs gets one
|
|
301
354
|
// local-fate assessment (the pipeline below), so whatever led the
|
|
@@ -343,14 +396,27 @@ export async function runGoalBlockedFate(ctx, engine, agent, config, state, _rea
|
|
|
343
396
|
* successful/no-op memory outcome; later review/fate failures do not replay
|
|
344
397
|
* old memory decisions, while memory failures leave the boundary retryable.
|
|
345
398
|
*/
|
|
346
|
-
export async function runMemoryExtractionPhase(ctx, engine, agent, config, state, snapshot, signal) {
|
|
399
|
+
export async function runMemoryExtractionPhase(ctx, engine, agent, config, state, snapshot, record, signal) {
|
|
400
|
+
const sessionId = agent.id;
|
|
401
|
+
const turnsSinceLastReview = state.turns - state.lastReviewAt;
|
|
402
|
+
const startedAt = Date.now();
|
|
347
403
|
const memorySnapshot = state.memoryCheckpoint ? sliceTurnSnapshot(snapshot, state.memoryCheckpoint) : snapshot;
|
|
348
404
|
if (!memorySnapshot.eligible || !memorySnapshot.trajectory) {
|
|
349
405
|
advanceMemoryCheckpoint(state, snapshot.cursor);
|
|
350
406
|
ctx.logger("continual-evolve").info(`memory agent no-op (${snapshot.reason}) [${agent.id}]: no new eligible evidence after checkpoint`);
|
|
407
|
+
record({
|
|
408
|
+
sessionId,
|
|
409
|
+
reason: snapshot.reason,
|
|
410
|
+
turnsSinceLastReview,
|
|
411
|
+
outcome: "noop",
|
|
412
|
+
rationale: `memory no-op (${snapshot.reason}): no new eligible evidence after checkpoint`,
|
|
413
|
+
durationMs: Date.now() - startedAt,
|
|
414
|
+
memoryTurns: 0,
|
|
415
|
+
memorySearches: 0,
|
|
416
|
+
appliedEdits: 0,
|
|
417
|
+
});
|
|
351
418
|
return;
|
|
352
419
|
}
|
|
353
|
-
const sessionId = agent.id;
|
|
354
420
|
const projectKey = snapshot.projectKey ?? projectKeyOf(agent);
|
|
355
421
|
const baselines = {
|
|
356
422
|
local: engine.load("local", sessionId),
|
|
@@ -393,6 +459,17 @@ export async function runMemoryExtractionPhase(ctx, engine, agent, config, state
|
|
|
393
459
|
if (run.proposal.edits.length === 0) {
|
|
394
460
|
advanceMemoryCheckpoint(state, memorySnapshot.cursor);
|
|
395
461
|
ctx.logger("continual-evolve").info(`memory agent no-op (${snapshot.reason}) [${sessionId}] after ${run.turns} turn(s): ${run.proposal.rationale}`);
|
|
462
|
+
record({
|
|
463
|
+
sessionId,
|
|
464
|
+
reason: snapshot.reason,
|
|
465
|
+
turnsSinceLastReview,
|
|
466
|
+
outcome: "noop",
|
|
467
|
+
rationale: `memory no-op (${snapshot.reason}) after ${run.turns} turn(s): ${run.proposal.rationale}`,
|
|
468
|
+
durationMs: Date.now() - startedAt,
|
|
469
|
+
memoryTurns: run.turns,
|
|
470
|
+
memorySearches: run.searches,
|
|
471
|
+
appliedEdits: 0,
|
|
472
|
+
});
|
|
396
473
|
return;
|
|
397
474
|
}
|
|
398
475
|
const source = { sessionId, ...(memorySnapshot.sourceSeqs.length > 0 ? { seqs: [...memorySnapshot.sourceSeqs] } : {}) };
|
|
@@ -413,7 +490,48 @@ export async function runMemoryExtractionPhase(ctx, engine, agent, config, state
|
|
|
413
490
|
state.memoryCheckpoint = memorySnapshot.cursor;
|
|
414
491
|
const applied = application.results.reduce((count, result) => count + result.appliedEdits.filter((edit) => edit.applied).length, 0);
|
|
415
492
|
const declined = application.declinedScopes.length > 0 ? `; declined scopes=${application.declinedScopes.join(",")}` : "";
|
|
493
|
+
const durationMs = Date.now() - startedAt;
|
|
494
|
+
for (const result of application.results) {
|
|
495
|
+
record({
|
|
496
|
+
sessionId,
|
|
497
|
+
reason: snapshot.reason,
|
|
498
|
+
turnsSinceLastReview,
|
|
499
|
+
outcome: "applied",
|
|
500
|
+
rationale: `memory applied (${snapshot.reason}) after ${run.turns} turn(s): ${run.proposal.rationale}${declined}`,
|
|
501
|
+
refinementId: result.id,
|
|
502
|
+
durationMs,
|
|
503
|
+
memoryTurns: run.turns,
|
|
504
|
+
memorySearches: run.searches,
|
|
505
|
+
appliedEdits: result.appliedEdits.filter((edit) => edit.applied).length,
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
if (application.declinedScopes.length > 0) {
|
|
509
|
+
record({
|
|
510
|
+
sessionId,
|
|
511
|
+
reason: snapshot.reason,
|
|
512
|
+
turnsSinceLastReview,
|
|
513
|
+
outcome: "declined",
|
|
514
|
+
rationale: `memory scopes declined (${snapshot.reason}): ${application.declinedScopes.join(",")}`,
|
|
515
|
+
durationMs,
|
|
516
|
+
memoryTurns: run.turns,
|
|
517
|
+
memorySearches: run.searches,
|
|
518
|
+
appliedEdits: 0,
|
|
519
|
+
});
|
|
520
|
+
}
|
|
416
521
|
ctx.logger("continual-evolve").info(`memory agent applied ${applied} edit(s) across ${application.results.length} scope batch(es) [${sessionId}] after ${run.turns} turn(s)${declined}: ${run.proposal.rationale}`);
|
|
522
|
+
// Visibility (P1 unified receipt): only applied outcomes wake the agent
|
|
523
|
+
// with a follow-up — and only on the turn path, never mid-compaction.
|
|
524
|
+
// No-op and declined-only runs stay audit-only (reviews.jsonl).
|
|
525
|
+
if (config.notifyOnAutoReview && snapshot.reason === "turn_snapshot" && applied > 0) {
|
|
526
|
+
notifyMemoryExtraction(ctx, agent, {
|
|
527
|
+
outcome: "applied",
|
|
528
|
+
results: application.results,
|
|
529
|
+
...(application.declinedScopes.length > 0 ? { declinedScopes: [...application.declinedScopes] } : {}),
|
|
530
|
+
turns: run.turns,
|
|
531
|
+
searches: run.searches,
|
|
532
|
+
durationMs,
|
|
533
|
+
});
|
|
534
|
+
}
|
|
417
535
|
}
|
|
418
536
|
async function runReviewPhase(ctx, engine, agent, config, state, snapshot, record, signal) {
|
|
419
537
|
const sessionId = agent.id;
|
package/lib/command.d.ts
CHANGED
|
@@ -17,10 +17,11 @@ export interface CommandRuntimeOptions {
|
|
|
17
17
|
autoCase: boolean;
|
|
18
18
|
/** Mechanical promotion guards for wrapup/fate (2026-08-22 policy). */
|
|
19
19
|
promotionPolicy: PromotionPolicy;
|
|
20
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Initial Memory Agent default from plugin config. The listener is always
|
|
22
|
+
* registered; this is not a registration gate.
|
|
23
|
+
*/
|
|
21
24
|
autoReview?: boolean;
|
|
22
|
-
/** The automatic listener runs only the dedicated Memory Agent. */
|
|
23
|
-
memoryOnly?: boolean;
|
|
24
25
|
}
|
|
25
26
|
export declare function registerEvolveCommand(ctx: Context, engine: EvolutionEngine, opts: CommandGateOptions, runtime: CommandRuntimeOptions): void;
|
|
26
27
|
/**
|