dsh-continual-evolve 0.15.9 → 0.15.11

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 CHANGED
@@ -7,7 +7,7 @@ English | [中文](README.zh.md)
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-330%20passing-brightgreen)]()
10
+ [![Tests](https://img.shields.io/badge/tests-337%20passing-brightgreen)]()
11
11
  [![Coverage · statements](https://img.shields.io/badge/coverage_statements-96%25-brightgreen)]()
12
12
  [![Coverage · branches](https://img.shields.io/badge/coverage_branches-90%25-green)]()
13
13
  [![Coverage · functions](https://img.shields.io/badge/coverage_functions-100%25-brightgreen)]()
@@ -23,7 +23,7 @@ Reusable experience gathered in one session (user preferences, pitfalls, project
23
23
  1. **Session-start injection** — the plugin registers a single system-prompt section: the workspace's memory index as a store query (hooks only, whole-line truncated over budget, ordered feedback > user > reference), the central-library path, and a three-line 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
24
  2. **Four tools, one writer** — `memory_write` (create/update/delete) is the explicit path for "remember …" / "forget …": every proposal passes the code gates (id shape, type enum, the feedback Why/How contract, secret screening carried over from v1, 64KB body cap, optional `corrects` links to the same-workspace active memory being superseded) inside one transaction. `memory_read` fetches bodies by id and searches by keyword — whitespace-separated terms are AND-combined, with literal substring matching for short terms and whenever the trigram index misses; the injected index carries hooks only. Each memory body served by id increments that memory's view counter (views + last viewed, the same presence heartbeat as skills). `skill_write` (create/update/delete in the project, plus an explicit move-to-global) sediments reusable procedures through the same discipline (kebab ids, secret screening, 64KB cap, no duplicate ids or bodies across scopes); every applied skill is materialized by the plugin as `<workspace>/.agents/skills/<id>/SKILL.md` — the database is the source of truth, the files are a read-only projection patrol restores on drift. `skill_read` fetches skill bodies by id and searches project plus global skills (the project shadows a same-named global); each body served by id increments that skill's view counter (views + last viewed), which the card shows as a presence heartbeat — viewed, not applied, so long-unviewed rows are removal candidates while pruning itself stays human. On hosts without the tools service the plugin degrades to "tell the user" phrasing and stays functional.
25
25
  3. **Proposal-based extraction** — the trajectory-to-memory automation, audited in the `extraction_log`: every `agent/turn-stopping` schedules that session's boundary, with state kept **per session** (a run in flight keeps only its newest boundary — coalescing, not queueing; `compaction/start` and session close drain it) and **no idle timer**. A run reads the session increment since its cursor, feeds FTS-similar existing memories to one LLM call, and the model's structured proposal lands through the same gates; failures and rejections never advance the cursor. A cheap pre-gate (increment head + ownership triple-test, tiny verdict) runs first: refusals consume the increment as a model skip without the full call, and an unclear gate fails open to the full call — worst case degrades to the old single-call behavior, never to a stall. Full and gate usages ledger in separate `usage` / `cheap_usage` columns, and a gate that dies keeps its error head in the same row's `cheap_error` — a dead gate stays tellable from a gate that never existed. Internal agents, empty increments, turns without real user prose, and turns that already carried an explicit `memory_write` are mechanically skipped — and every skip is ledgered, consecutive quiet turns of one session as a single row carrying how many wake-ups it stands for.
26
- 4. **Autonomous content-quality loop** — the second background automation, independent from extraction by construction (own prompts, own daily budget, own `review_log` ledger, no cursor; only the store's write gates are shared): a cheap gate model call decides whether a memory/skill entry deserves a close look, and only approvals run the evolve pass that judges content quality (memories on home-ownership plus accuracy/usability/reusability/duplication/freshness, skills on home-ownership plus trigger precision/executability/reusability/duplication) and proposes the rewrite. The same three home tests (user/environment vs repo-version subject, name-stripped sentence, repo facts live in ADR/docs) guard the extraction prompt, so repo-version specifics never enter as memories in the first place. Gate/leg failures ledger the error text instead of a bare code. New writes are reviewed as they land, the existing stock drains through a bounded backlog queue, and untouched entries requeue after 30 days. Two hard guarantees bound the autonomy: delete never lands automatically (rewrite or quarantine only — quarantine hides, never deletes) and oversized rewrites degrade to quarantine. A daily cap (default 100 items, new > corrects-linked > stale > spot-check priority, the tail drops instead of rolling over) bounds the token spend, and every terminal path lands one `item-review` verdict row plus one daily rollup row (budget vs reviewed vs backlog vs dropped, tokens split by cheap/evolve purpose) for later replay. Ships in trial mode (`review.dryRun`, default on): verdicts ledgered, nothing applied.
26
+ 4. **Autonomous content-quality loop** — the second background automation, independent from extraction by construction (own prompts, own daily budget, own `review_log` ledger, no cursor; only the store's write gates are shared): a cheap gate model call decides whether a memory/skill entry deserves a close look, and only approvals run the evolve pass that judges content quality (memories on home-ownership plus accuracy/usability/reusability/duplication/freshness, skills on home-ownership plus trigger precision/executability/duplication, where reuse is scope-aware: a project-partition skill is judged inside its project (in-project reuse) and the cross-project test applies to global-scope skills only — a repo-bound row in the global partition is the mis-homed case) and proposes the rewrite. The same three home tests (user/environment vs repo-version subject, name-stripped sentence, repo facts live in ADR/docs) guard the extraction prompt, so repo-version specifics never enter as memories in the first place. Gate/leg failures ledger the error text instead of a bare code, and the gate's own budget (1024 tokens) leaves room for a thinking model's reasoning: a verdict that completed before a cut still counts, while a call that produced no verdict at all (route fault, budget cut) leaves the item queued instead of marking it reviewed. New writes are reviewed as they land, the existing stock drains through a bounded backlog queue, and untouched entries requeue after 30 days. Two hard guarantees bound the autonomy: delete never lands automatically (rewrite or quarantine only — quarantine hides, never deletes) and oversized rewrites degrade to quarantine. A daily cap (default 100 items, new > corrects-linked > stale > spot-check priority, the tail drops instead of rolling over) bounds the token spend, and every terminal path lands one `item-review` verdict row plus one daily rollup row (budget vs reviewed vs backlog vs dropped, tokens split by cheap/evolve purpose) for later replay. Ships in trial mode (`review.dryRun`, default on): verdicts ledgered, nothing applied — and a declined rewrite now rides the row's `proposed` column, because a trial has to show what it would write, not just why.
27
27
  5. **Rollback is a ledger, not a mechanism** — every mutation lands an `extraction_log` row with full before/after snapshots; undo means rewriting the `before` values. Skill mutations land the same way in `skill_log`, review verdicts in `review_log`. A hygiene pass rides on every applied run: orphan FTS rows are dropped and secret-bearing rows are quarantined (hidden, never deleted; a quarantined skill's materialized file is removed so it stops loading). The read-only card surfaces quarantine anomalies.
28
28
  6. **Read-only card** — mounted on the plugin's page in the official plugin manager (the `plugins.bundle.config` slot; hosts without it silently degrade to no card), shaped like the market's own settings card and aligned with ZCode's Settings → Memory viewer: a dropdown scope selector over the store's workspace partitions (opening on the host's current workspace), a search box, per-entry relative updated times, click-to-preview bodies (5 MiB cap), patrol warnings, and a skills section listing the workspace's project skills plus visible global skills (global rows badged, project shadowing global) with the same preview, each row showing its view count. Localized through the host's `locale/*.json` metadata channel; host theme tokens, the `Button` primitive, and zh/en copy that tracks the DSH language. The card is a request-time projection of the database and has no edit path.
29
29
 
@@ -60,8 +60,11 @@ No commands. On the first session after restart the index is injected automatica
60
60
  | `review.dryRun` | `true` | Ledger verdicts without landing them (flip off after the trial distribution reads clean) |
61
61
  | `review.dailyBudget` | `100` | Reviewed items per UTC day (new > corrects-linked > stale > spot-check, tail drops) |
62
62
  | `review.batchSize` | `10` | Max items per drain run |
63
+ | `review.staleDays` | `30` | Days a reviewed item stays out of the queue before it requeues (a review that produced no verdict never counts) |
63
64
  | `memoryCard.enabled` | `true` | Read-only memory card in the official plugin manager (degrades to no card when the host lacks `webServer`/`plugins.bundle.config`) |
64
65
 
66
+ Every `review.*` field is volatile: a settings surface edits it without a remount, and the scheduler re-reads the values on every drain.
67
+
65
68
  Profile patch example:
66
69
 
67
70
  ```yaml
@@ -78,7 +81,7 @@ Profile patch example:
78
81
 
79
82
  ```bash
80
83
  pnpm install && pnpm build # deps + clean build -> lib/
81
- pnpm test # vitest (328 tests)
84
+ pnpm test # vitest (337 tests)
82
85
  pnpm test:coverage # v8 coverage, CI-enforced thresholds
83
86
  pnpm lint # oxlint src test client
84
87
  pnpm check:pack # published-artifact consistency (also runs on prepack)
package/README.zh.md CHANGED
@@ -7,7 +7,7 @@
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-330%20passing-brightgreen)]()
10
+ [![Tests](https://img.shields.io/badge/tests-337%20passing-brightgreen)]()
11
11
  [![Coverage · statements](https://img.shields.io/badge/coverage_statements-96%25-brightgreen)]()
12
12
  [![Coverage · branches](https://img.shields.io/badge/coverage_branches-90%25-green)]()
13
13
  [![Coverage · functions](https://img.shields.io/badge/coverage_functions-100%25-brightgreen)]()
@@ -23,7 +23,7 @@ Agent 每个会话积累的可复用经验(用户偏好、踩坑教训、项
23
23
  1. **开局注入** —— 插件只注册一个 system-prompt section:注入本工作区的记忆索引(查库结果,只含钩子,超预算按整行截断,feedback > user > reference 排序)、中央库路径、三行指南。该 section 每会话只算一次并逐字节复用,system prompt 稳定、prompt cache 持续命中;空 store 零 token。
24
24
  2. **四个工具,一个写者** —— `memory_write`(create/update/delete)承接显式的记住/忘掉:每条提案过代码门禁(id 规范、type 枚举、feedback 的 Why/How 契约、v1 移植的 secret 筛查、64KB 正文上限、可选 `corrects` 指向被替代的同工作区 active 记忆)后在一个事务内落盘。`memory_read` 按 id 取正文、按关键词检索——空格分隔的关键词取 AND,短词与 trigram 未命中时回退字面子串匹配;注入索引只有钩子。按 id 取到的每份记忆正文计一次查阅(与技能同纪律的存在心跳)。`skill_write`(项目内 create/update/delete + 显式搬到全局)沉淀可复用的操作规程,走同一套纪律(短横线 id、secret 筛查、64KB 上限、跨范围禁重名重文);每条落地的技能由插件代码物化为 `<workspace>/.agents/skills/<id>/SKILL.md`——库是唯一真相,文件是只读投影,漂移由巡检按库还原。`skill_read` 按 id 取技能正文、检索项目与全局技能(同名时项目遮蔽全局);按 id 取到的每份正文计一次查阅(查阅次数 + 上次查阅,卡片展示)。这是存在心跳——只证明被翻过,不证明有用:长期零查阅是删除候选,剪枝拍板仍需人工。宿主没有工具服务时降级为告诉用户措辞,注入不受影响。
25
25
  3. **提案制提取** —— 轨迹到记忆的自动化,全程 `extraction_log` 可对账:每个 `agent/turn-stopping` 调度**该会话自己**的边界,状态按会话隔离(运行中只保留最新边界——合并而非排队;`compaction/start` 与会话收尾触发 drain),**没有空闲计时器**。一次运行读取该会话游标之后的轨迹增量,用 FTS 取相似既有记忆喂给一次 LLM 调用,模型的结构化提案过同一套门禁落盘;失败与被拒不推游标,下次触发重试。贵调用之前先过一道便宜预检门(增量前 4KB + 归属三测,小 verdict):拒了直接按 model-skip 消费游标,不烧全量 prompt;门不清不楚就透传给贵调用——最差退化成老单调用,永不 stall。贵用量与门用量分 `usage` / `cheap_usage` 两列记账;门自己挂了按 fail-open 透传,错误原文留在同一行的 `cheap_error`——门死了与门不存在可区分。内部 agent、空增量、无真实用户文本的轮次、当轮已有显式 `memory_write` 的轮次机械跳过——每次跳过都记账,同一会话连续的空转轮次合成一行并累计唤醒次数。
26
- 4. **内容质量自进化环** —— 第二条后台自动化,与提取在结构上独立(自有提示词、自有日预算、自有 `review_log` 账本、无游标;只共享库的写门):便宜门模型先判某条记忆/技能值不值得细看,批了才跑贵改写,按内容质量打分(记忆:归属 + 准确/可用/可复用/不重复/不过时五维;技能:归属 + 触发精度/可执行完备/可复用/不重复四维)并给出改写提案。同一套归属三测(主语是用户/环境还是某仓库的某版机制、去名后还成立吗、仓库事实住 ADR/docs)也守在提取 prompt 门口,版本细节从源头就不进记忆;评审调用失败记错误原文,不记秃码。新写即审、存量走有界积压队列排空、长期未动 30 天回炉。两条硬保证框住自动化:删除永不自动落盘(只有改写与隔离——隔离隐藏不删),超幅改写自动转隔离。日上限默认 100 条(新写 > 被纠正牵连 > 陈旧 > 抽查,尾部丢弃不滚雪球)框住 token 开销;每条终态落一行 `item-review` verdict 行、每天合一行日 rollup(预算 vs 实审 vs 积压 vs 丢弃,token 按便宜/贵分账),方便以后复盘。默认试运行(`review.dryRun` 开):只记 verdict,不落盘。
26
+ 4. **内容质量自进化环** —— 第二条后台自动化,与提取在结构上独立(自有提示词、自有日预算、自有 `review_log` 账本、无游标;只共享库的写门):便宜门模型先判某条记忆/技能值不值得细看,批了才跑贵改写,按内容质量打分(记忆:归属 + 准确/可用/可复用/不重复/不过时五维;技能:归属 + 触发精度/可执行完备/不重复三维,其中「可复用」按分区判——项目分区技能只按该项目内跨任务可用判,跨项目可用只对全局分区技能判,绑定本仓库路径/门禁的项目技能不算缺陷)并给出改写提案。同一套归属三测(主语是用户/环境还是某仓库的某版机制、去名后还成立吗、仓库事实住 ADR/docs)也守在提取 prompt 门口,版本细节从源头就不进记忆;评审调用失败记错误原文,不记秃码;门自身预算 1024 token,给推理模型的思考留出余量——截断前已完成解析的 verdict 仍算数,而一条 verdict 都没产出的调用(路由故障、预算截断)不让条目记为已评审,而是留队重试。新写即审、存量走有界积压队列排空、长期未动 30 天回炉。两条硬保证框住自动化:删除永不自动落盘(只有改写与隔离——隔离隐藏不删),超幅改写自动转隔离。日上限默认 100 条(新写 > 被纠正牵连 > 陈旧 > 抽查,尾部丢弃不滚雪球)框住 token 开销;每条终态落一行 `item-review` verdict 行、每天合一行日 rollup(预算 vs 实审 vs 积压 vs 丢弃,token 按便宜/贵分账),方便以后复盘。默认试运行(`review.dryRun` 开):只记 verdict 不落盘,且未落盘的拟改稿全文随行进 `proposed` 列——试运行要看的是「改成什么样」,不只是「为什么改」。
27
27
  5. **回滚靠账本,不靠机制** —— 每次变更落一条带 before/after 全文快照的 `extraction_log` 行;undo 就是取 before 重写。技能变更同样落 `skill_log`,评审 verdict 落 `review_log`。每次应用后随跑一次巡检:孤儿 FTS 行清除、含密钥条目隔离(隐藏,不物理删除;被隔离技能的物化文件一并撤下,使其不再被加载)。只读卡片显形巡检异常。
28
28
  6. **只读卡片** —— 挂在官方插件管理的本 bundle 页面(`plugins.bundle.config` slot,老宿主自动降级为无卡片):形态对齐市场自家设置卡,内容对齐 ZCode 设置的记忆选项卡——下拉作用域选择器列出库里的工作区分区(默认选中宿主当前工作区)、搜索框、每条记忆的相对更新时间、点击行内展开正文预览(5 MiB 上限)、巡检异常警告,以及技能区(本工作区技能 + 可见的全局技能,全局行打标记,同名时项目遮蔽全局),预览同记忆,每行显示查阅次数。显示名与描述走宿主 `locale/*.json` 通道双语;宿主主题 token、`Button` 原语、中英文案跟随 DSH 语言。卡片是数据库的请求时投影,没有编辑路径。
29
29
 
@@ -60,8 +60,11 @@ dsh plugin add ZK-Andy/dsh-continual-evolve
60
60
  | `review.dryRun` | `true` | 只记 verdict 不落盘(试运行分布看顺后再关) |
61
61
  | `review.dailyBudget` | `100` | 每天评审上限(新写 > 被纠正牵连 > 陈旧 > 抽查,尾部丢弃) |
62
62
  | `review.batchSize` | `10` | 每次 drain 最多审几条 |
63
+ | `review.staleDays` | `30` | 已评审条目重回队列前要等几天(没产出 verdict 的评审从不算数) |
63
64
  | `memoryCard.enabled` | `true` | 官方插件管理内的只读记忆卡片(宿主缺 `webServer`/`plugins.bundle.config` 时自动降级为无卡片) |
64
65
 
66
+ `review.*` 全部是 volatile 字段:设置界面可在不重挂载的情况下修改,调度器每次 drain 重新读取取值。
67
+
65
68
  profile patch 示例:
66
69
 
67
70
  ```yaml
@@ -78,7 +81,7 @@ profile patch 示例:
78
81
 
79
82
  ```bash
80
83
  pnpm install && pnpm build # 依赖 + 干净构建 -> lib/
81
- pnpm test # vitest(328 例)
84
+ pnpm test # vitest(337 例)
82
85
  pnpm test:coverage # v8 覆盖率,CI 强制阈值
83
86
  pnpm lint # oxlint src test client
84
87
  pnpm check:pack # 发布产物一致性(prepack 也会跑)
package/lib/extraction.js CHANGED
@@ -9,6 +9,8 @@ const UNEXPECTED_ERROR_RAW_MAX = 2048;
9
9
  const ERROR_REASON_MAX = 300;
10
10
  /** Head length of a failed pre-gate call's error kept in the ledger `cheap_error` column. */
11
11
  const GATE_ERROR_MAX = 200;
12
+ /** Output budget for one cheap-gate call (see review.ts's `GATE_MAX_TOKENS`). */
13
+ const GATE_MAX_TOKENS = 1024;
12
14
  /** Split an unexpected throw into a ledger-sized reason head and file body. */
13
15
  function errorText(error) {
14
16
  const message = error instanceof Error && error.message.length > 0 ? error.message : String(error);
@@ -127,9 +129,15 @@ async function runExtractionInner(deps, target, opts) {
127
129
  {
128
130
  const gateStarted = Date.now();
129
131
  try {
130
- const gate = await streamOnce(deps.llm, target, cheapPrompt({ incrementHead: increment.slice(0, CHEAP_INCREMENT_MAX), userSeqs: slice.userSeqs }), EXTRACTION_CHEAP_SYSTEM_PROMPT, 512);
132
+ const gate = await streamOnce(deps.llm, target, cheapPrompt({ incrementHead: increment.slice(0, CHEAP_INCREMENT_MAX), userSeqs: slice.userSeqs }), EXTRACTION_CHEAP_SYSTEM_PROMPT, GATE_MAX_TOKENS);
131
133
  cheapUsage = gate.usage;
132
134
  const verdict = parseCheapAnswer(gate.text);
135
+ // A gate cut at its budget that still answered is a usable verdict;
136
+ // only a cut with nothing parseable rides the run's row as a gate
137
+ // error. Parse before blaming the finish reason.
138
+ if (verdict === null && gate.finish !== undefined && gate.finish !== "stop") {
139
+ throw new Error(`stream finished with ${gate.finish}`);
140
+ }
133
141
  if (verdict !== null && !verdict.worth) {
134
142
  advanceCursor();
135
143
  store.logSkipped({
@@ -163,6 +171,10 @@ async function runExtractionInner(deps, target, opts) {
163
171
  let usage;
164
172
  try {
165
173
  const answer = await streamOnce(deps.llm, target, prompt);
174
+ // The full call carries the proposal payload: a cut stream is a failure.
175
+ if (answer.finish !== undefined && answer.finish !== "stop") {
176
+ throw new Error(`stream finished with ${answer.finish}`);
177
+ }
166
178
  text = answer.text;
167
179
  usage = answer.usage;
168
180
  }
@@ -267,13 +279,14 @@ async function streamOnce(llm, target, prompt, system = EXTRACTION_SYSTEM_PROMPT
267
279
  finish = piece.reason;
268
280
  }
269
281
  }
270
- if (finish !== undefined && finish.kind !== "stop") {
271
- throw new Error(`stream finished with ${finish.kind ?? "unknown"}`);
272
- }
282
+ const finishKind = finish?.kind;
273
283
  if (text.trim().length === 0) {
274
- throw new Error("empty model output");
284
+ // Nothing usable arrived: the finish reason is the only diagnosis.
285
+ throw new Error(finishKind !== undefined && finishKind !== "stop" ? `stream finished with ${finishKind}` : "empty model output");
275
286
  }
276
- return { text, usage };
287
+ // The caller owns the truncation verdict: a gate answer often completes
288
+ // before its budget does, a proposal body never does.
289
+ return { text, usage, finish: finishKind };
277
290
  }
278
291
  /**
279
292
  * Wire the extraction triggers onto the host context. Returns a disposer
package/lib/index.d.ts CHANGED
@@ -82,19 +82,25 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
82
82
  /**
83
83
  * The autonomous content-quality loop (own prompts, own daily budget,
84
84
  * own ledger — shares only the store's write gates with extraction).
85
- * `dryRun` ledgers verdicts without landing them (trial mode, default
86
- * on); `dailyBudget` caps reviewed items per UTC day (default 100).
85
+ * Every field is volatile: a settings surface edits them without a
86
+ * remount, so the scheduler re-reads them per drain instead of capturing
87
+ * them at mount. `dryRun` ledgers verdicts without landing them (trial
88
+ * mode, default on); `dailyBudget` caps reviewed items per UTC day
89
+ * (default 100); `staleDays` is how long a reviewed item stays out of the
90
+ * queue before it comes back (default 30).
87
91
  */
88
92
  review: z<Schemastery.ObjectS<NoInfer<{
89
- enabled: z<boolean, boolean, "plain">;
90
- dryRun: z<boolean, boolean, "plain">;
91
- dailyBudget: z<number, number, "plain">;
92
- batchSize: z<number, number, "plain">;
93
+ enabled: z<boolean, boolean, "volatile">;
94
+ dryRun: z<boolean, boolean, "volatile">;
95
+ dailyBudget: z<number, number, "volatile">;
96
+ batchSize: z<number, number, "volatile">;
97
+ staleDays: z<number, number, "volatile">;
93
98
  }>>, Schemastery.ObjectT<NoInfer<{
94
- enabled: z<boolean, boolean, "plain">;
95
- dryRun: z<boolean, boolean, "plain">;
96
- dailyBudget: z<number, number, "plain">;
97
- batchSize: z<number, number, "plain">;
99
+ enabled: z<boolean, boolean, "volatile">;
100
+ dryRun: z<boolean, boolean, "volatile">;
101
+ dailyBudget: z<number, number, "volatile">;
102
+ batchSize: z<number, number, "volatile">;
103
+ staleDays: z<number, number, "volatile">;
98
104
  }>>, "plain">;
99
105
  /**
100
106
  * The read-only memory card in the official plugin manager
@@ -141,19 +147,25 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
141
147
  /**
142
148
  * The autonomous content-quality loop (own prompts, own daily budget,
143
149
  * own ledger — shares only the store's write gates with extraction).
144
- * `dryRun` ledgers verdicts without landing them (trial mode, default
145
- * on); `dailyBudget` caps reviewed items per UTC day (default 100).
150
+ * Every field is volatile: a settings surface edits them without a
151
+ * remount, so the scheduler re-reads them per drain instead of capturing
152
+ * them at mount. `dryRun` ledgers verdicts without landing them (trial
153
+ * mode, default on); `dailyBudget` caps reviewed items per UTC day
154
+ * (default 100); `staleDays` is how long a reviewed item stays out of the
155
+ * queue before it comes back (default 30).
146
156
  */
147
157
  review: z<Schemastery.ObjectS<NoInfer<{
148
- enabled: z<boolean, boolean, "plain">;
149
- dryRun: z<boolean, boolean, "plain">;
150
- dailyBudget: z<number, number, "plain">;
151
- batchSize: z<number, number, "plain">;
158
+ enabled: z<boolean, boolean, "volatile">;
159
+ dryRun: z<boolean, boolean, "volatile">;
160
+ dailyBudget: z<number, number, "volatile">;
161
+ batchSize: z<number, number, "volatile">;
162
+ staleDays: z<number, number, "volatile">;
152
163
  }>>, Schemastery.ObjectT<NoInfer<{
153
- enabled: z<boolean, boolean, "plain">;
154
- dryRun: z<boolean, boolean, "plain">;
155
- dailyBudget: z<number, number, "plain">;
156
- batchSize: z<number, number, "plain">;
164
+ enabled: z<boolean, boolean, "volatile">;
165
+ dryRun: z<boolean, boolean, "volatile">;
166
+ dailyBudget: z<number, number, "volatile">;
167
+ batchSize: z<number, number, "volatile">;
168
+ staleDays: z<number, number, "volatile">;
157
169
  }>>, "plain">;
158
170
  /**
159
171
  * The read-only memory card in the official plugin manager
package/lib/index.js CHANGED
@@ -31,7 +31,7 @@
31
31
  import z from "@deepseek-ai/schemastery";
32
32
  import { mountCardRoutes } from "./card-routes.js";
33
33
  import { createExtractionScheduler } from "./extraction.js";
34
- import { createReviewScheduler } from "./review.js";
34
+ import { createReviewScheduler, REVIEW_DEFAULT_BATCH_SIZE, REVIEW_DEFAULT_DAILY_BUDGET, REVIEW_DEFAULT_DRY_RUN, REVIEW_DEFAULT_STALE_DAYS, } from "./review.js";
35
35
  import { createFrozenMemorySection, cwdOf, DEFAULT_MAX_CHARS, DEFAULT_MEMORY_SECTION_ORDER, MEMORY_SECTION_NAME, memorySectionText, } from "./memory-section.js";
36
36
  import { registerMemoryTools } from "./memory-tools.js";
37
37
  import { registerSkillTools } from "./skill-tools.js";
@@ -63,14 +63,19 @@ export const Config = z.object({
63
63
  /**
64
64
  * The autonomous content-quality loop (own prompts, own daily budget,
65
65
  * own ledger — shares only the store's write gates with extraction).
66
- * `dryRun` ledgers verdicts without landing them (trial mode, default
67
- * on); `dailyBudget` caps reviewed items per UTC day (default 100).
66
+ * Every field is volatile: a settings surface edits them without a
67
+ * remount, so the scheduler re-reads them per drain instead of capturing
68
+ * them at mount. `dryRun` ledgers verdicts without landing them (trial
69
+ * mode, default on); `dailyBudget` caps reviewed items per UTC day
70
+ * (default 100); `staleDays` is how long a reviewed item stays out of the
71
+ * queue before it comes back (default 30).
68
72
  */
69
73
  review: z.object({
70
- enabled: z.boolean(),
71
- dryRun: z.boolean(),
72
- dailyBudget: z.natural(),
73
- batchSize: z.natural(),
74
+ enabled: z.boolean().volatile(),
75
+ dryRun: z.boolean().volatile(),
76
+ dailyBudget: z.natural().volatile(),
77
+ batchSize: z.natural().volatile(),
78
+ staleDays: z.natural().volatile(),
74
79
  }),
75
80
  /**
76
81
  * The read-only memory card in the official plugin manager
@@ -140,7 +145,7 @@ function mountExtractionWhenAvailable(host, store, config) {
140
145
  */
141
146
  function mountReviewWhenAvailable(host, store, config) {
142
147
  const log = host.logger("continual-evolve");
143
- if (config.review?.enabled === false) {
148
+ if (config.review?.enabled?.get() === false) {
144
149
  log.info("review disabled by config — extraction and tools unaffected");
145
150
  return;
146
151
  }
@@ -155,10 +160,12 @@ function mountReviewWhenAvailable(host, store, config) {
155
160
  const llm = (context.llm ?? context.get?.("llm"));
156
161
  createReviewScheduler(events, { store, llm }, {
157
162
  enabled: true,
158
- dryRun: config.review?.dryRun ?? true,
159
- dailyBudget: config.review?.dailyBudget ?? 100,
160
- batchSize: config.review?.batchSize ?? 10,
161
- staleDays: 30,
163
+ read: () => ({
164
+ dryRun: config.review?.dryRun?.get() ?? REVIEW_DEFAULT_DRY_RUN,
165
+ dailyBudget: config.review?.dailyBudget?.get() ?? REVIEW_DEFAULT_DAILY_BUDGET,
166
+ batchSize: config.review?.batchSize?.get() ?? REVIEW_DEFAULT_BATCH_SIZE,
167
+ staleDays: config.review?.staleDays?.get() ?? REVIEW_DEFAULT_STALE_DAYS,
168
+ }),
162
169
  minIntervalMs: 5 * 60 * 1000,
163
170
  });
164
171
  });
@@ -14,8 +14,14 @@
14
14
  export declare const REVIEW_CHEAP_SYSTEM_PROMPT = "\u4F60\u662F\u8BB0\u5FC6\u5E93\u7684\u5185\u5BB9\u8BC4\u5BA1\u95E8\u3002\u5148\u8FC7\u5F52\u5C5E\u4E09\u6D4B\uFF1A\u2460\u4E3B\u8BED\u662F\u7528\u6237/\u73AF\u5883\u8FD8\u662F\u67D0\u4ED3\u5E93\u7684\u67D0\u7248\u673A\u5236\uFF08\u7248\u672C\u53F7\u3001\u9608\u503C\u3001\u5F00\u5173\u540D\u51FA\u73B0\u5373\u540E\u8005\uFF09\uFF1B\u2461\u62B9\u6389\u4ED3\u5E93\u540D\u7248\u672C\u53F7\u673A\u5236\u540D\u540E\u53E5\u5B50\u8FD8\u6210\u7ACB\u5417\uFF1B\u2462\u4ED3\u5E93\u4E8B\u5B9E\u4F4F ADR/docs\uFF0C\u8BB0\u5FC6\u53EA\u6536\u8DDF\u4EBA\u8D70\u7684\u3002\u5F52\u5C5E\u4E0D\u8FC7\u76F4\u63A5\u5224 false \u5E76\u6CE8\u660E\u653E\u9519\u5BB6\u3002\u518D\u5224\u503C\u4E0D\u503C\u5F97\u7EC6\u770B\uFF1A\u6709\u660E\u786E\u4E8B\u5B9E\u3001\u505A\u6CD5\u3001\u504F\u597D\u6216\u53EF\u590D\u7528\u89C4\u7A0B\u5C31\u6279\uFF1B\u7A7A\u8BDD\u3001\u7EAF\u8FC7\u7A0B\u8BB0\u5F55\u3001\u4E00\u6B21\u6027\u7684\u77AC\u65F6\u8F93\u51FA\u3001\u5F53\u8F6E\u5DF2\u53EF\u63A8\u5BFC\u7684\u4E00\u5F8B\u62D2\u3002\u53EA\u8F93\u51FA JSON\uFF1A{\"worthReview\": true|false, \"reason\": \"\u4E00\u53E5\u8BDD\"}\u3002";
15
15
  /** Memory rubric: accurate, usable, reusable, non-duplicate, fresh, right-home. */
16
16
  export declare const REVIEW_MEMORY_SYSTEM_PROMPT = "\u4F60\u662F\u8BB0\u5FC6\u5E93\u7684\u5185\u5BB9\u8BC4\u5BA1\u3002\u5148\u8FC7\u5F52\u5C5E\u4E09\u6D4B\uFF08\u4E3B\u8BED\u662F\u7528\u6237/\u73AF\u5883\u8FD8\u662F\u67D0\u4ED3\u5E93\u7684\u67D0\u7248\u673A\u5236\uFF1B\u62B9\u6389\u4ED3\u5E93\u540D\u7248\u672C\u53F7\u673A\u5236\u540D\u540E\u8FD8\u6210\u7ACB\u5417\uFF1B\u4ED3\u5E93\u4E8B\u5B9E\u4F4F ADR/docs\uFF09\uFF1A\u5F52\u5C5E\u4E0D\u8FC7\u76F4\u63A5 quarantine \u5E76\u6CE8\u660E\u653E\u9519\u5BB6\u3002\u518D\u6309\u4E94\u7EF4\u5224\uFF1A\u2460\u51C6\u786E\uFF08\u4E8B\u5B9E\u53EF\u4FE1\u3001\u65E0\u5E7B\u89C9\uFF09\uFF1B\u2461\u53EF\u7528\uFF08Why/How \u5177\u4F53\u3001\u53EF\u6267\u884C\uFF0C\u53CD\u9988\u7C7B\u5FC5\u987B\u5E26 Why \u4E0E How to apply\uFF09\uFF1B\u2462\u53EF\u590D\u7528\uFF08\u672A\u6765\u4F1A\u8BDD\u7528\u5F97\u4E0A\uFF09\uFF1B\u2463\u4E0D\u91CD\u590D\uFF08\u4E0E\u5019\u9009\u65E7\u6761\u6BD4\uFF0C\u6709\u91CD\u590D\u5C31\u6307\u51FA\u6765\uFF09\uFF1B\u2464\u4E0D\u8FC7\u65F6\uFF08\u672A\u88AB\u7EA0\u6B63\u94FE\u53D6\u4EE3\uFF09\u3002\u53EA\u8F93\u51FA JSON\uFF1A{\"verdict\": \"keep|rewrite|quarantine\", \"reason\": \"\u4E00\u53E5\u8BDD\", \"title\"?: \"\u6539\u5199\u540E\u6807\u9898\", \"description\"?: \"\u6539\u5199\u540E\u94A9\u5B50\", \"body\"?: \"\u6539\u5199\u540E\u6B63\u6587\u5168\u6587\", \"corrects\"?: \"\u88AB\u53D6\u4EE3\u7684\u540C\u533A\u6761\u76EEid\"}\u3002verdict \u8BF4\u660E\uFF1Akeep=\u4E0D\u52A8\uFF1Brewrite=\u7ED9\u51FA\u6539\u5199\u540E\u5168\u6587\u4E09\u4EF6\uFF1Bquarantine=\u6D89\u5BC6/\u6709\u5BB3/\u5B8C\u5168\u8FC7\u65F6/\u653E\u9519\u5BB6\u3002\u7981\u5220\u9664\uFF0C\u7981\u7F16\u9020\u5F15\u7528\u3002";
17
- /** Skill rubric: trigger precision, executability, reusability, non-duplicate, right-home. */
18
- export declare const REVIEW_SKILL_SYSTEM_PROMPT = "\u4F60\u662F\u6280\u80FD\u5E93\u7684\u5185\u5BB9\u8BC4\u5BA1\u3002\u5148\u8FC7\u5F52\u5C5E\u4E09\u6D4B\uFF08\u6280\u80FD\u662F\u5426\u7ED1\u5B9A\u5355\u4E00\u4ED3\u5E93\u7684\u8DEF\u5F84\u4E0E\u673A\u5236\uFF1B\u62B9\u6389\u4ED3\u5E93\u540D\u540E\u8FD8\u6210\u7ACB\u5417\uFF09\uFF1A\u653E\u9519\u5BB6\u76F4\u63A5 quarantine\u3002\u518D\u6309\u56DB\u7EF4\u5224\uFF1A\u2460\u89E6\u53D1\u7CBE\u5EA6\uFF08description \u662F\u5426\u8BA9\u4EBA/\u6A21\u578B\u5728\u8BE5\u7528\u65F6\u60F3\u8D77\u3001\u4E0D\u8BE5\u7528\u65F6\u4E0D\u6253\u6270\uFF09\uFF1B\u2461\u6B63\u6587\u53EF\u6267\u884C\u5B8C\u5907\uFF08\u6B65\u9AA4\u5B8C\u6574\u3001\u8F93\u5165\u8F93\u51FA\u660E\u786E\uFF09\uFF1B\u2462\u53EF\u590D\u7528\uFF08\u8DE8\u4EFB\u52A1\u53EF\u7528\uFF09\uFF1B\u2463\u4E0D\u91CD\u590D\uFF08\u4E0E\u5019\u9009\u65E2\u6709\u6280\u80FD\u6BD4\uFF09\u3002\u53EA\u8F93\u51FA JSON\uFF1A{\"verdict\": \"keep|rewrite|quarantine\", \"reason\": \"\u4E00\u53E5\u8BDD\", \"title\"?: \"\u6539\u5199\u540E\u6807\u9898\", \"description\"?: \"\u6539\u5199\u540E\u94A9\u5B50\", \"body\"?: \"\u6539\u5199\u540E\u6B63\u6587\u5168\u6587\"}\u3002verdict \u8BF4\u660E\uFF1Akeep=\u4E0D\u52A8\uFF1Brewrite=\u7ED9\u51FA\u6539\u5199\u540E\u5168\u6587\u4E09\u4EF6\uFF1Bquarantine=\u6D89\u5BC6/\u6709\u5BB3/\u5B8C\u5168\u8FC7\u65F6/\u653E\u9519\u5BB6\u3002\u7981\u5220\u9664\u3002";
17
+ /**
18
+ * Skill rubric: trigger precision, executability, reuse, non-duplicate — with
19
+ * the cross-project reuse test reserved for `scope=global`. A skill bound to
20
+ * one repo's paths, gates and workflow cards is not defective when it lives in
21
+ * that project's partition (that is what a project skill is for); only a
22
+ * repo-bound skill sitting in the global partition is mis-homed.
23
+ */
24
+ export declare const REVIEW_SKILL_SYSTEM_PROMPT = "\u4F60\u662F\u6280\u80FD\u5E93\u7684\u5185\u5BB9\u8BC4\u5BA1\u3002\u5148\u770B\u5F52\u5C5E\uFF08prompt \u91CC\u6807\u4E86 scope\uFF09\uFF1A\u7ED1\u5B9A\u67D0\u4ED3\u5E93\u7684\u8DEF\u5F84/\u95E8\u7981/\u6D41\u7A0B**\u4E0D\u662F**\u7F3A\u9677\u2014\u2014\u4F4F\u9879\u76EE\u5206\u533A\uFF08scope=project\uFF09\u7684\u6280\u80FD\u672C\u6765\u5C31\u53EA\u5728\u8BE5\u9879\u76EE\u5185\u751F\u6548\uFF0C\u7981\u7528\u300C\u8DE8\u9879\u76EE\u4E0D\u53EF\u590D\u7528\u300D\u300C\u62B9\u6389\u4ED3\u5E93\u540D\u4E0D\u6210\u7ACB\u300D\u5F53\u7406\u7531\u53BB\u6539\u5199\u6216\u9694\u79BB\u5B83\uFF1B\u53EA\u6709\u300Cscope=global \u5374\u7ED1\u5B9A\u67D0\u4ED3\u5E93\u300D\u624D\u7B97\u653E\u9519\u5BB6\uFF0C\u76F4\u63A5 quarantine\u3002\u518D\u5224\uFF1A\u2460\u89E6\u53D1\u7CBE\u5EA6\uFF08description \u662F\u5426\u8BA9\u4EBA/\u6A21\u578B\u5728\u8BE5\u7528\u65F6\u60F3\u8D77\u3001\u4E0D\u8BE5\u7528\u65F6\u4E0D\u6253\u6270\uFF09\uFF1B\u2461\u6B63\u6587\u53EF\u6267\u884C\u5B8C\u5907\uFF08\u6B65\u9AA4\u5B8C\u6574\u3001\u8F93\u5165\u8F93\u51FA\u660E\u786E\uFF09\uFF1B\u2462\u53EF\u590D\u7528\uFF08scope=project \u6309\u8BE5\u9879\u76EE\u5185\u8DE8\u4EFB\u52A1\u53EF\u7528\u5224\uFF0Cscope=global \u624D\u6309\u8DE8\u9879\u76EE\u53EF\u7528\u5224\uFF09\uFF1B\u2463\u4E0D\u91CD\u590D\uFF08\u4E0E\u5019\u9009\u65E2\u6709\u6280\u80FD\u6BD4\uFF09\u3002\u53EA\u8F93\u51FA JSON\uFF1A{\"verdict\": \"keep|rewrite|quarantine\", \"reason\": \"\u4E00\u53E5\u8BDD\", \"title\"?: \"\u6539\u5199\u540E\u6807\u9898\", \"description\"?: \"\u6539\u5199\u540E\u94A9\u5B50\", \"body\"?: \"\u6539\u5199\u540E\u6B63\u6587\u5168\u6587\"}\u3002verdict \u8BF4\u660E\uFF1Akeep=\u4E0D\u52A8\uFF1Brewrite=\u7ED9\u51FA\u6539\u5199\u540E\u5168\u6587\u4E09\u4EF6\uFF1Bquarantine=\u6D89\u5BC6/\u6709\u5BB3/\u5B8C\u5168\u8FC7\u65F6/\u653E\u9519\u5BB6\u3002\u7981\u5220\u9664\u3002";
19
25
  export interface GateVerdict {
20
26
  worthReview: boolean;
21
27
  reason: string;
@@ -35,6 +41,7 @@ export declare function gatePrompt(entry: {
35
41
  title: string;
36
42
  description: string;
37
43
  body: string;
44
+ scope?: "project" | "global" | undefined;
38
45
  }): string;
39
46
  /** The evolve prompt for one item plus its similar neighbors for dup-checking. */
40
47
  export declare function evolvePrompt(entry: {
@@ -43,6 +50,7 @@ export declare function evolvePrompt(entry: {
43
50
  description: string;
44
51
  body: string;
45
52
  extra?: string | undefined;
53
+ scope?: "project" | "global" | undefined;
46
54
  }, neighbors: readonly {
47
55
  id: string;
48
56
  title: string;
@@ -14,27 +14,30 @@
14
14
  export const REVIEW_CHEAP_SYSTEM_PROMPT = "你是记忆库的内容评审门。先过归属三测:①主语是用户/环境还是某仓库的某版机制(版本号、阈值、开关名出现即后者);②抹掉仓库名版本号机制名后句子还成立吗;③仓库事实住 ADR/docs,记忆只收跟人走的。归属不过直接判 false 并注明放错家。再判值不值得细看:有明确事实、做法、偏好或可复用规程就批;空话、纯过程记录、一次性的瞬时输出、当轮已可推导的一律拒。只输出 JSON:{\"worthReview\": true|false, \"reason\": \"一句话\"}。";
15
15
  /** Memory rubric: accurate, usable, reusable, non-duplicate, fresh, right-home. */
16
16
  export const REVIEW_MEMORY_SYSTEM_PROMPT = "你是记忆库的内容评审。先过归属三测(主语是用户/环境还是某仓库的某版机制;抹掉仓库名版本号机制名后还成立吗;仓库事实住 ADR/docs):归属不过直接 quarantine 并注明放错家。再按五维判:①准确(事实可信、无幻觉);②可用(Why/How 具体、可执行,反馈类必须带 Why 与 How to apply);③可复用(未来会话用得上);④不重复(与候选旧条比,有重复就指出来);⑤不过时(未被纠正链取代)。只输出 JSON:{\"verdict\": \"keep|rewrite|quarantine\", \"reason\": \"一句话\", \"title\"?: \"改写后标题\", \"description\"?: \"改写后钩子\", \"body\"?: \"改写后正文全文\", \"corrects\"?: \"被取代的同区条目id\"}。verdict 说明:keep=不动;rewrite=给出改写后全文三件;quarantine=涉密/有害/完全过时/放错家。禁删除,禁编造引用。";
17
- /** Skill rubric: trigger precision, executability, reusability, non-duplicate, right-home. */
18
- export const REVIEW_SKILL_SYSTEM_PROMPT = "你是技能库的内容评审。先过归属三测(技能是否绑定单一仓库的路径与机制;抹掉仓库名后还成立吗):放错家直接 quarantine。再按四维判:①触发精度(description 是否让人/模型在该用时想起、不该用时不打扰);②正文可执行完备(步骤完整、输入输出明确);③可复用(跨任务可用);④不重复(与候选既有技能比)。只输出 JSON:{\"verdict\": \"keep|rewrite|quarantine\", \"reason\": \"一句话\", \"title\"?: \"改写后标题\", \"description\"?: \"改写后钩子\", \"body\"?: \"改写后正文全文\"}。verdict 说明:keep=不动;rewrite=给出改写后全文三件;quarantine=涉密/有害/完全过时/放错家。禁删除。";
17
+ /**
18
+ * Skill rubric: trigger precision, executability, reuse, non-duplicate — with
19
+ * the cross-project reuse test reserved for `scope=global`. A skill bound to
20
+ * one repo's paths, gates and workflow cards is not defective when it lives in
21
+ * that project's partition (that is what a project skill is for); only a
22
+ * repo-bound skill sitting in the global partition is mis-homed.
23
+ */
24
+ export const REVIEW_SKILL_SYSTEM_PROMPT = "你是技能库的内容评审。先看归属(prompt 里标了 scope):绑定某仓库的路径/门禁/流程**不是**缺陷——住项目分区(scope=project)的技能本来就只在该项目内生效,禁用「跨项目不可复用」「抹掉仓库名不成立」当理由去改写或隔离它;只有「scope=global 却绑定某仓库」才算放错家,直接 quarantine。再判:①触发精度(description 是否让人/模型在该用时想起、不该用时不打扰);②正文可执行完备(步骤完整、输入输出明确);③可复用(scope=project 按该项目内跨任务可用判,scope=global 才按跨项目可用判);④不重复(与候选既有技能比)。只输出 JSON:{\"verdict\": \"keep|rewrite|quarantine\", \"reason\": \"一句话\", \"title\"?: \"改写后标题\", \"description\"?: \"改写后钩子\", \"body\"?: \"改写后正文全文\"}。verdict 说明:keep=不动;rewrite=给出改写后全文三件;quarantine=涉密/有害/完全过时/放错家。禁删除。";
19
25
  /** The cheap-gate prompt for one item (id + hook + body, truncated by caller). */
20
26
  export function gatePrompt(entry) {
21
- return [
22
- `kind=${entry.kind} id=${entry.id}`,
23
- `title=${entry.title}`,
24
- `钩子=${entry.description}`,
25
- "全文:",
26
- entry.body,
27
- ].join("\n");
27
+ const lines = [`kind=${entry.kind} id=${entry.id}`];
28
+ if (entry.scope !== undefined) {
29
+ lines.push(`scope=${entry.scope}`);
30
+ }
31
+ lines.push(`title=${entry.title}`, `钩子=${entry.description}`, "全文:", entry.body);
32
+ return lines.join("\n");
28
33
  }
29
34
  /** The evolve prompt for one item plus its similar neighbors for dup-checking. */
30
35
  export function evolvePrompt(entry, neighbors) {
31
- const lines = [
32
- `id=${entry.id}`,
33
- `title=${entry.title}`,
34
- `钩子=${entry.description}`,
35
- "全文:",
36
- entry.body,
37
- ];
36
+ const lines = [`id=${entry.id}`];
37
+ if (entry.scope !== undefined) {
38
+ lines.push(`scope=${entry.scope}`);
39
+ }
40
+ lines.push(`title=${entry.title}`, `钩子=${entry.description}`, "全文:", entry.body);
38
41
  if (entry.extra !== undefined && entry.extra.length > 0) {
39
42
  lines.push("", entry.extra);
40
43
  }
package/lib/review.d.ts CHANGED
@@ -48,6 +48,18 @@ export interface ReviewRunSummary {
48
48
  }
49
49
  /** A rewrite lands only when the body-length ratio stays within this bound. */
50
50
  export declare const REWRITE_MAGNITUDE_CAP = 0.3;
51
+ /**
52
+ * Output budget for one cheap-gate call: a verdict JSON **plus** the reasoning
53
+ * a thinking model spends before emitting it. A 512-token budget cut the gate
54
+ * off on reasoning-model calls (2026-10-13) and the cut was ledgered as a
55
+ * route failure, so the per-item failure rate read as a network problem.
56
+ */
57
+ export declare const GATE_MAX_TOKENS = 1024;
58
+ /** Defaults for the review settings the host may override — and edit live. */
59
+ export declare const REVIEW_DEFAULT_DRY_RUN = true;
60
+ export declare const REVIEW_DEFAULT_DAILY_BUDGET = 100;
61
+ export declare const REVIEW_DEFAULT_BATCH_SIZE = 10;
62
+ export declare const REVIEW_DEFAULT_STALE_DAYS = 30;
51
63
  /** Relative body change: |new-old| / max(old, 1). Above the cap → quarantine. */
52
64
  export declare function rewriteMagnitude(oldBody: string, newBody: string): number;
53
65
  /**
@@ -80,12 +92,21 @@ export interface ReviewSchedulerHost {
80
92
  warn(message: string): void;
81
93
  };
82
94
  }
83
- export interface ReviewSchedulerConfig {
84
- enabled: boolean;
95
+ /** The editable review settings, re-read on every drain. */
96
+ export interface ReviewSettings {
85
97
  dryRun: boolean;
86
98
  dailyBudget: number;
87
99
  batchSize: number;
88
100
  staleDays: number;
101
+ }
102
+ export interface ReviewSchedulerConfig {
103
+ enabled: boolean;
104
+ /**
105
+ * Read the current settings for each drain: the host's configuration is
106
+ * volatile, so values edited live take effect without a remount and are
107
+ * never captured once at mount time.
108
+ */
109
+ read: () => ReviewSettings;
89
110
  /** Minimum ms between two drains (default 5 minutes). */
90
111
  minIntervalMs: number;
91
112
  }
package/lib/review.js CHANGED
@@ -16,6 +16,18 @@ import { evolvePrompt, gatePrompt, parseEvolveAnswer, parseGateAnswer, REVIEW_CH
16
16
  import { cwdOf } from "./memory-section.js";
17
17
  /** A rewrite lands only when the body-length ratio stays within this bound. */
18
18
  export const REWRITE_MAGNITUDE_CAP = 0.3;
19
+ /**
20
+ * Output budget for one cheap-gate call: a verdict JSON **plus** the reasoning
21
+ * a thinking model spends before emitting it. A 512-token budget cut the gate
22
+ * off on reasoning-model calls (2026-10-13) and the cut was ledgered as a
23
+ * route failure, so the per-item failure rate read as a network problem.
24
+ */
25
+ export const GATE_MAX_TOKENS = 1024;
26
+ /** Defaults for the review settings the host may override — and edit live. */
27
+ export const REVIEW_DEFAULT_DRY_RUN = true;
28
+ export const REVIEW_DEFAULT_DAILY_BUDGET = 100;
29
+ export const REVIEW_DEFAULT_BATCH_SIZE = 10;
30
+ export const REVIEW_DEFAULT_STALE_DAYS = 30;
19
31
  /** Relative body change: |new-old| / max(old, 1). Above the cap → quarantine. */
20
32
  export function rewriteMagnitude(oldBody, newBody) {
21
33
  return Math.abs(newBody.length - oldBody.length) / Math.max(oldBody.length, 1);
@@ -194,10 +206,16 @@ async function reviewOne(deps, runId, candidate, opts, summary, skipReasons) {
194
206
  let gateUsage = zeroUsage();
195
207
  let gateRaw;
196
208
  try {
197
- const answer = await streamOnce(deps.llm, opts, REVIEW_CHEAP_SYSTEM_PROMPT, gatePrompt(candidate), 512);
209
+ const answer = await streamOnce(deps.llm, opts, REVIEW_CHEAP_SYSTEM_PROMPT, gatePrompt(candidate), GATE_MAX_TOKENS);
198
210
  gateRaw = answer.usage;
199
211
  const gate = parseGateAnswer(answer.text);
200
212
  if (gate === null) {
213
+ // A cut gate is a failure only when no complete verdict came
214
+ // through: the JSON usually lands before the budget runs out, so
215
+ // parse first and blame the finish reason only if it did not.
216
+ if (answer.finish !== undefined && answer.finish !== "stop") {
217
+ throw new Error(`stream finished with ${answer.finish}`);
218
+ }
201
219
  deps.store.logReview({ ...base, verdict: "skip", reason: "gate-parse-failed", cheapUsage: gateRaw, applied: 0 });
202
220
  skipReasons.push("gate-parse-failed");
203
221
  return;
@@ -228,9 +246,14 @@ async function reviewOne(deps, runId, candidate, opts, summary, skipReasons) {
228
246
  let evolveRaw;
229
247
  try {
230
248
  const system = candidate.kind === "memory" ? REVIEW_MEMORY_SYSTEM_PROMPT : REVIEW_SKILL_SYSTEM_PROMPT;
231
- const answer = await streamOnce(deps.llm, opts, system, evolvePrompt({ id: candidate.id, title: candidate.title, description: candidate.description, body: candidate.body, extra }, neighbors), 4096);
249
+ const answer = await streamOnce(deps.llm, opts, system, evolvePrompt({ id: candidate.id, title: candidate.title, description: candidate.description, body: candidate.body, extra, scope: candidate.scope }, neighbors), 4096);
232
250
  evolveRaw = answer.usage;
233
251
  summary.evolveToken += totalOf(evolveRaw);
252
+ // The evolve pass carries full replacement text: a cut stream may hold
253
+ // half a body, so it never becomes a verdict.
254
+ if (answer.finish !== undefined && answer.finish !== "stop") {
255
+ throw new Error(`stream finished with ${answer.finish}`);
256
+ }
234
257
  const evolved = parseEvolveAnswer(answer.text);
235
258
  if (evolved === null) {
236
259
  deps.store.logReview({ ...base, verdict: "skip", reason: "evolve-parse-failed", cheapUsage: gateUsage, evolveUsage: evolveRaw, applied: 0 });
@@ -242,17 +265,17 @@ async function reviewOne(deps, runId, candidate, opts, summary, skipReasons) {
242
265
  return;
243
266
  }
244
267
  if (evolved.verdict === "quarantine") {
245
- landQuarantine(deps, base, candidate, opts, evolved.reason, gateUsage, evolveRaw, summary);
268
+ landQuarantine(deps, base, candidate, opts, evolved.reason, gateUsage, evolveRaw, proposedOf(evolved), summary);
246
269
  return;
247
270
  }
248
271
  // ── Rewrite: magnitude cap first, dry-run second, gates last ──
249
272
  const nextBody = evolved.body ?? candidate.body;
250
273
  if (rewriteMagnitude(candidate.body, nextBody) > REWRITE_MAGNITUDE_CAP) {
251
- landQuarantine(deps, base, candidate, opts, `幅度超限转隔离:${evolved.reason}`, gateUsage, evolveRaw, summary);
274
+ landQuarantine(deps, base, candidate, opts, `幅度超限转隔离:${evolved.reason}`, gateUsage, evolveRaw, proposedOf(evolved), summary);
252
275
  return;
253
276
  }
254
277
  if (opts.dryRun) {
255
- deps.store.logReview({ ...base, verdict: "rewrite", reason: `试运行未落盘:${evolved.reason}`, cheapUsage: gateUsage, evolveUsage: evolveRaw, applied: 0 });
278
+ deps.store.logReview({ ...base, verdict: "rewrite", reason: `试运行未落盘:${evolved.reason}`, proposed: proposedOf(evolved), cheapUsage: gateUsage, evolveUsage: evolveRaw, applied: 0 });
256
279
  return;
257
280
  }
258
281
  landRewrite(deps, base, candidate, opts, evolved, gateUsage, evolveRaw, summary);
@@ -262,6 +285,26 @@ async function reviewOne(deps, runId, candidate, opts, summary, skipReasons) {
262
285
  skipReasons.push("evolve-llm-failed");
263
286
  }
264
287
  }
288
+ /**
289
+ * The rewrite payload a non-landing row keeps: exactly the fields the model
290
+ * supplied, or `undefined` when it proposed no text at all.
291
+ */
292
+ function proposedOf(evolved) {
293
+ const payload = {};
294
+ if (evolved.title !== undefined) {
295
+ payload.title = evolved.title;
296
+ }
297
+ if (evolved.description !== undefined) {
298
+ payload.description = evolved.description;
299
+ }
300
+ if (evolved.body !== undefined) {
301
+ payload.body = evolved.body;
302
+ }
303
+ if (evolved.corrects !== undefined) {
304
+ payload.corrects = evolved.corrects;
305
+ }
306
+ return Object.keys(payload).length === 0 ? undefined : payload;
307
+ }
265
308
  function neighborHooks(store, candidate) {
266
309
  try {
267
310
  if (candidate.kind === "memory") {
@@ -276,10 +319,10 @@ function neighborHooks(store, candidate) {
276
319
  return [];
277
320
  }
278
321
  }
279
- function landQuarantine(deps, base, candidate, opts, reason, gateUsage, evolveRaw, summary) {
322
+ function landQuarantine(deps, base, candidate, opts, reason, gateUsage, evolveRaw, proposed, summary) {
280
323
  const prior = deps.store.reviewStateOf(candidate.workspaceId, candidate.kind, candidate.id)?.evolveCount ?? 0;
281
324
  if (opts.dryRun) {
282
- deps.store.logReview({ ...base, verdict: "quarantine", reason: `试运行未隔离:${reason}`, cheapUsage: gateUsage, evolveUsage: evolveRaw, applied: 0, evolveCount: prior });
325
+ deps.store.logReview({ ...base, verdict: "quarantine", reason: `试运行未隔离:${reason}`, proposed, cheapUsage: gateUsage, evolveUsage: evolveRaw, applied: 0, evolveCount: prior });
283
326
  return;
284
327
  }
285
328
  const ok = deps.store.quarantine(candidate.workspaceId, candidate.kind, candidate.id);
@@ -363,13 +406,14 @@ async function streamOnce(llm, opts, system, prompt, maxTokens) {
363
406
  finish = piece.reason;
364
407
  }
365
408
  }
366
- if (finish !== undefined && finish.kind !== "stop") {
367
- throw new Error(`stream finished with ${finish.kind ?? "unknown"}`);
368
- }
409
+ const finishKind = finish?.kind;
369
410
  if (text.trim().length === 0) {
370
- throw new Error("empty model output");
411
+ // Nothing usable arrived: the finish reason is the only diagnosis.
412
+ throw new Error(finishKind !== undefined && finishKind !== "stop" ? `stream finished with ${finishKind}` : "empty model output");
371
413
  }
372
- return { text, usage };
414
+ // The caller owns the truncation verdict: a gate answer often completes
415
+ // before its budget does, a replacement body never does.
416
+ return { text, usage, finish: finishKind };
373
417
  }
374
418
  /** Current UTC day `YYYY-MM-DD` for the hard-cap account. */
375
419
  export function todayUtc() {
@@ -409,19 +453,20 @@ export function createReviewScheduler(host, deps, config) {
409
453
  pendingWorkspace = undefined;
410
454
  void (async () => {
411
455
  try {
456
+ const settings = config.read();
412
457
  const day = todayUtc();
413
458
  const daily = deps.store.getDaily(day);
414
- const remaining = config.dailyBudget - (daily?.reviewed ?? 0);
459
+ const remaining = settings.dailyBudget - (daily?.reviewed ?? 0);
415
460
  if (remaining <= 0) {
416
461
  return;
417
462
  }
418
- const candidates = collectCandidates(deps.store, { staleDays: config.staleDays, limit: config.batchSize * 2 });
463
+ const candidates = collectCandidates(deps.store, { staleDays: settings.staleDays, limit: settings.batchSize * 2 });
419
464
  const ordered = workspace === undefined
420
465
  ? candidates
421
466
  : [...candidates.filter((c) => c.workspaceId === workspace), ...candidates.filter((c) => c.workspaceId !== workspace)];
422
- await runReviewBatch(deps, ordered.slice(0, config.batchSize), {
423
- day, budget: config.dailyBudget, dryRun: config.dryRun,
424
- batchSize: config.batchSize, staleDays: config.staleDays,
467
+ await runReviewBatch(deps, ordered.slice(0, settings.batchSize), {
468
+ day, budget: settings.dailyBudget, dryRun: settings.dryRun,
469
+ batchSize: settings.batchSize, staleDays: settings.staleDays,
425
470
  provider: lastRoute?.provider, model: lastRoute?.model, sessionId: lastRoute?.sessionId,
426
471
  });
427
472
  }
@@ -454,7 +499,8 @@ export function createReviewScheduler(host, deps, config) {
454
499
  drain(pendingWorkspace);
455
500
  pendingWorkspace = undefined;
456
501
  }));
457
- host.logger("continual-evolve").info(`review scheduler armed (daily cap ${config.dailyBudget}, dry-run ${config.dryRun ? "on" : "off"})`);
502
+ const armed = config.read();
503
+ host.logger("continual-evolve").info(`review scheduler armed (daily cap ${armed.dailyBudget}, dry-run ${armed.dryRun ? "on" : "off"})`);
458
504
  return () => {
459
505
  pendingWorkspace = undefined;
460
506
  for (const listener of listeners) {
package/lib/store.d.ts CHANGED
@@ -65,6 +65,13 @@ export interface ReviewLogEntry {
65
65
  applied?: number | undefined;
66
66
  /** How many times this item has evolved including this run. */
67
67
  evolveCount?: number | undefined;
68
+ /**
69
+ * The rewrite the model proposed when the row did NOT land it (trial mode),
70
+ * as `{title, description, body, corrects}`. Without it a dry run ledgers
71
+ * only why it would change an item, never into what — and the "into what"
72
+ * is the part a human has to judge before turning the trial off.
73
+ */
74
+ proposed?: unknown;
68
75
  }
69
76
  /** One day of the hard-cap account (UTC `YYYY-MM-DD`, budget = 100). */
70
77
  export interface DailyStats {
package/lib/store.js CHANGED
@@ -37,6 +37,14 @@ const LEDGER_OCCURRENCES = "occurrences";
37
37
  * row per occurrence — a persistent fault deserves a timeline, not a counter.
38
38
  */
39
39
  const COALESCED_SKIP_REASONS = new Set(["no-user-prose", "no-new-events"]);
40
+ /**
41
+ * Verdict rows that leave an item queued: a call that never produced a verdict
42
+ * must not read as "reviewed". Without this a single gate fault (a route blip,
43
+ * a budget cut) locked the item out for `staleDays`, because the failure row
44
+ * counted as a finished review (2026-10-13).
45
+ */
46
+ const INCOMPLETE_REVIEW_SQL = "(coalesce(reason, '') LIKE 'gate-llm-failed%' OR coalesce(reason, '') LIKE 'evolve-llm-failed%' " +
47
+ "OR coalesce(reason, '') IN ('no-route', 'budget-exhausted', 'gate-parse-failed', 'evolve-parse-failed'))";
40
48
  const DDL = `
41
49
  PRAGMA journal_mode=WAL;
42
50
  PRAGMA busy_timeout=5000;CREATE TABLE IF NOT EXISTS memories (
@@ -130,6 +138,7 @@ CREATE TABLE IF NOT EXISTS review_log (
130
138
  item_id TEXT NOT NULL,
131
139
  verdict TEXT NOT NULL CHECK (verdict IN ('keep','rewrite','quarantine','skip')),
132
140
  reason TEXT,
141
+ proposed TEXT,
133
142
  cheap_usage TEXT, evolve_usage TEXT,
134
143
  applied INTEGER NOT NULL DEFAULT 0,
135
144
  evolve_count INTEGER NOT NULL DEFAULT 0
@@ -303,6 +312,7 @@ export async function openMemoryStore(explicitPath) {
303
312
  ensureMemoriesCorrects(database);
304
313
  ensureExtractionCheapUsage(database);
305
314
  ensureExtractionCheapError(database);
315
+ ensureReviewProposed(database);
306
316
  const stmts = {
307
317
  get: database.prepare("SELECT * FROM memories WHERE workspace_id = ? AND id = ?"),
308
318
  list: database.prepare(`SELECT * FROM memories WHERE workspace_id = ? AND status = 'active' ${LIST_ORDER}`),
@@ -357,9 +367,9 @@ export async function openMemoryStore(explicitPath) {
357
367
  memUseGet: database.prepare("SELECT use_count, last_used_at FROM memory_usage WHERE workspace_id = ? AND memory_id = ?"),
358
368
  memUseUpsert: database.prepare("INSERT INTO memory_usage (workspace_id, memory_id, use_count, last_used_at) VALUES (?, ?, 1, ?) " +
359
369
  "ON CONFLICT (workspace_id, memory_id) DO UPDATE SET use_count = use_count + 1, last_used_at = excluded.last_used_at"),
360
- reviewLog: database.prepare("INSERT INTO review_log (run_id, ts, workspace_id, item_kind, item_id, verdict, reason, cheap_usage, evolve_usage, applied, evolve_count) " +
361
- "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"),
362
- reviewLast: database.prepare("SELECT ts, applied FROM review_log WHERE workspace_id IS ? AND item_kind = ? AND item_id = ? ORDER BY rowid DESC LIMIT 1"),
370
+ reviewLog: database.prepare("INSERT INTO review_log (run_id, ts, workspace_id, item_kind, item_id, verdict, reason, proposed, cheap_usage, evolve_usage, applied, evolve_count) " +
371
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"),
372
+ reviewLast: database.prepare(`SELECT ts, applied FROM review_log WHERE workspace_id IS ? AND item_kind = ? AND item_id = ? AND NOT ${INCOMPLETE_REVIEW_SQL} ORDER BY rowid DESC LIMIT 1`),
363
373
  reviewEvolved: database.prepare("SELECT COUNT(*) AS n FROM review_log WHERE workspace_id IS ? AND item_kind = ? AND item_id = ? AND applied = 1"),
364
374
  reviewPrune: database.prepare("DELETE FROM review_log WHERE ts < ?"),
365
375
  dailyGet: database.prepare("SELECT * FROM review_daily WHERE day = ?"),
@@ -903,7 +913,7 @@ export async function openMemoryStore(explicitPath) {
903
913
  }
904
914
  },
905
915
  logReview(entry) {
906
- stmts.reviewLog.run(entry.runId ?? null, new Date().toISOString(), entry.workspaceId ?? null, entry.itemKind, entry.itemId, entry.verdict, entry.reason ?? null, entry.cheapUsage === undefined ? null : JSON.stringify(entry.cheapUsage), entry.evolveUsage === undefined ? null : JSON.stringify(entry.evolveUsage), entry.applied ?? 0, entry.evolveCount ?? 0);
916
+ stmts.reviewLog.run(entry.runId ?? null, new Date().toISOString(), entry.workspaceId ?? null, entry.itemKind, entry.itemId, entry.verdict, entry.reason ?? null, entry.proposed === undefined ? null : JSON.stringify(entry.proposed), entry.cheapUsage === undefined ? null : JSON.stringify(entry.cheapUsage), entry.evolveUsage === undefined ? null : JSON.stringify(entry.evolveUsage), entry.applied ?? 0, entry.evolveCount ?? 0);
907
917
  },
908
918
  consumeReviewBudget(day, budget) {
909
919
  stmts.dailyUpsert.run(day, budget);
@@ -1016,6 +1026,18 @@ function ensureExtractionCheapError(database) {
1016
1026
  }
1017
1027
  database.exec("ALTER TABLE extraction_log ADD COLUMN cheap_error TEXT");
1018
1028
  }
1029
+ /**
1030
+ * Add the review ledger `proposed` column to a store created before trial
1031
+ * mode started keeping the rewrite it declined to land. Same single-migration
1032
+ * discipline as the columns above.
1033
+ */
1034
+ function ensureReviewProposed(database) {
1035
+ const columns = database.prepare("SELECT name FROM pragma_table_info('review_log')").all();
1036
+ if (columns.some((column) => column.name === "proposed")) {
1037
+ return;
1038
+ }
1039
+ database.exec("ALTER TABLE review_log ADD COLUMN proposed TEXT");
1040
+ }
1019
1041
  /** Parse the daily skip-counts map; corrupt payloads degrade to empty. */
1020
1042
  function parseCounts(raw) {
1021
1043
  if (raw === null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-continual-evolve",
3
- "version": "0.15.9",
3
+ "version": "0.15.11",
4
4
  "description": "ZCode-style workspace memory for DeepSeek Harness: one central SQLite store partitioned by workspace, index injection, and sole-writer gated writes.",
5
5
  "license": "MIT",
6
6
  "repository": {