dsh-continual-evolve 0.15.8 → 0.15.10
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 +3 -3
- package/README.zh.md +3 -3
- package/lib/extraction.js +21 -4
- package/lib/review-prompt.d.ts +10 -2
- package/lib/review-prompt.js +19 -16
- package/lib/review.js +26 -6
- package/lib/store-apply.d.ts +2 -0
- package/lib/store-apply.js +4 -3
- package/lib/store.d.ts +14 -0
- package/lib/store.js +35 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ English | [中文](README.zh.md)
|
|
|
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
|
[]()
|
|
13
13
|
[]()
|
|
@@ -22,8 +22,8 @@ Reusable experience gathered in one session (user preferences, pitfalls, project
|
|
|
22
22
|
|
|
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
|
-
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. 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/
|
|
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/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. 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
|
|
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
|
[]()
|
|
13
13
|
[]()
|
|
@@ -22,8 +22,8 @@ Agent 每个会话积累的可复用经验(用户偏好、踩坑教训、项
|
|
|
22
22
|
|
|
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
|
-
3. **提案制提取** —— 轨迹到记忆的自动化,全程 `extraction_log` 可对账:每个 `agent/turn-stopping` 调度**该会话自己**的边界,状态按会话隔离(运行中只保留最新边界——合并而非排队;`compaction/start` 与会话收尾触发 drain),**没有空闲计时器**。一次运行读取该会话游标之后的轨迹增量,用 FTS 取相似既有记忆喂给一次 LLM 调用,模型的结构化提案过同一套门禁落盘;失败与被拒不推游标,下次触发重试。贵调用之前先过一道便宜预检门(增量前 4KB + 归属三测,小 verdict):拒了直接按 model-skip 消费游标,不烧全量 prompt;门不清不楚就透传给贵调用——最差退化成老单调用,永不 stall。贵用量与门用量分 `usage` / `cheap_usage`
|
|
26
|
-
4. **内容质量自进化环** —— 第二条后台自动化,与提取在结构上独立(自有提示词、自有日预算、自有 `review_log` 账本、无游标;只共享库的写门):便宜门模型先判某条记忆/技能值不值得细看,批了才跑贵改写,按内容质量打分(记忆:归属 + 准确/可用/可复用/不重复/不过时五维;技能:归属 +
|
|
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 不落盘,且未落盘的拟改稿全文随行进 `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
|
|
package/lib/extraction.js
CHANGED
|
@@ -7,12 +7,18 @@ const FAILURE_RAW_MAX = 2048;
|
|
|
7
7
|
const UNEXPECTED_ERROR_RAW_MAX = 2048;
|
|
8
8
|
/** Head length of an error message embedded in a ledger `skip_reason`. */
|
|
9
9
|
const ERROR_REASON_MAX = 300;
|
|
10
|
+
/** Head length of a failed pre-gate call's error kept in the ledger `cheap_error` column. */
|
|
11
|
+
const GATE_ERROR_MAX = 200;
|
|
10
12
|
/** Split an unexpected throw into a ledger-sized reason head and file body. */
|
|
11
13
|
function errorText(error) {
|
|
12
14
|
const message = error instanceof Error && error.message.length > 0 ? error.message : String(error);
|
|
13
15
|
const stack = error instanceof Error && typeof error.stack === "string" ? error.stack : message;
|
|
14
16
|
return { message, detail: `${message}\n${stack}`.slice(0, UNEXPECTED_ERROR_RAW_MAX) };
|
|
15
17
|
}
|
|
18
|
+
/** One-line head of a thrown pre-gate error (flat, so the column stays greppable). */
|
|
19
|
+
function errorHead(error) {
|
|
20
|
+
return errorText(error).message.replace(/\s+/g, " ").trim().slice(0, GATE_ERROR_MAX);
|
|
21
|
+
}
|
|
16
22
|
/**
|
|
17
23
|
* Run one extraction pass for a target. Never throws unless the ledger
|
|
18
24
|
* itself is unwritable: every terminal path is either a landed application,
|
|
@@ -111,8 +117,13 @@ async function runExtractionInner(deps, target, opts) {
|
|
|
111
117
|
// (manifest + full-body candidates + full increment). A "not worth it"
|
|
112
118
|
// consumes the increment exactly like a model skip; an unclear gate
|
|
113
119
|
// (unparseable/failed) fails OPEN to the full call — worst case degrades
|
|
114
|
-
// to the old single-call behavior, never to a stall.
|
|
120
|
+
// to the old single-call behavior, never to a stall. A gate that dies
|
|
121
|
+
// still rides the run's own ledger row as `cheap_error`: without it a
|
|
122
|
+
// failed gate is indistinguishable from a gate that never existed, which
|
|
123
|
+
// is how a 512-token budget truncating every call on a reasoning model
|
|
124
|
+
// stayed invisible.
|
|
115
125
|
let cheapUsage;
|
|
126
|
+
let cheapError;
|
|
116
127
|
{
|
|
117
128
|
const gateStarted = Date.now();
|
|
118
129
|
try {
|
|
@@ -132,8 +143,11 @@ async function runExtractionInner(deps, target, opts) {
|
|
|
132
143
|
return { status: "skipped", skipReason: verdict.reason, cursor: boundarySeq };
|
|
133
144
|
}
|
|
134
145
|
}
|
|
135
|
-
catch {
|
|
136
|
-
// Fail open: the full call below is the old behavior.
|
|
146
|
+
catch (error) {
|
|
147
|
+
// Fail open: the full call below is the old behavior. The error
|
|
148
|
+
// head is kept for the run's own row (never a row of its own, so
|
|
149
|
+
// one run stays one ledger row).
|
|
150
|
+
cheapError = errorHead(error);
|
|
137
151
|
}
|
|
138
152
|
}
|
|
139
153
|
const manifest = store.list(target.workspaceId).slice(0, 50).map(manifestLineOf);
|
|
@@ -155,7 +169,7 @@ async function runExtractionInner(deps, target, opts) {
|
|
|
155
169
|
catch (error) {
|
|
156
170
|
const { message, detail } = errorText(error);
|
|
157
171
|
try {
|
|
158
|
-
store.logSkipped({ ...ledgerBase, skipReason: "llm-failed", status: "failed", durationMs: Date.now() - started, cheapUsage, files: detail });
|
|
172
|
+
store.logSkipped({ ...ledgerBase, skipReason: "llm-failed", status: "failed", durationMs: Date.now() - started, cheapUsage, cheapError, files: detail });
|
|
159
173
|
}
|
|
160
174
|
catch (ledgerError) {
|
|
161
175
|
throw new Error(`llm call failed (${message}); failure ledger write also failed (${errorText(ledgerError).message})`);
|
|
@@ -175,6 +189,7 @@ async function runExtractionInner(deps, target, opts) {
|
|
|
175
189
|
model: target.model,
|
|
176
190
|
usage,
|
|
177
191
|
cheapUsage,
|
|
192
|
+
cheapError,
|
|
178
193
|
durationMs: Date.now() - started,
|
|
179
194
|
files: text.slice(0, FAILURE_RAW_MAX),
|
|
180
195
|
});
|
|
@@ -191,6 +206,7 @@ async function runExtractionInner(deps, target, opts) {
|
|
|
191
206
|
model: target.model,
|
|
192
207
|
usage,
|
|
193
208
|
cheapUsage,
|
|
209
|
+
cheapError,
|
|
194
210
|
durationMs: Date.now() - started,
|
|
195
211
|
});
|
|
196
212
|
return { status: "skipped", skipReason: parsed.reason, cursor: boundarySeq };
|
|
@@ -203,6 +219,7 @@ async function runExtractionInner(deps, target, opts) {
|
|
|
203
219
|
model: target.model,
|
|
204
220
|
usage,
|
|
205
221
|
cheapUsage,
|
|
222
|
+
cheapError,
|
|
206
223
|
decision: parsed.reason,
|
|
207
224
|
}, parsed.proposals);
|
|
208
225
|
if (!outcomes.every((outcome) => outcome.ok)) {
|
package/lib/review-prompt.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
18
|
-
|
|
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;
|
package/lib/review-prompt.js
CHANGED
|
@@ -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
|
-
/**
|
|
18
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
`
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
33
|
-
`
|
|
34
|
-
|
|
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.js
CHANGED
|
@@ -228,7 +228,7 @@ async function reviewOne(deps, runId, candidate, opts, summary, skipReasons) {
|
|
|
228
228
|
let evolveRaw;
|
|
229
229
|
try {
|
|
230
230
|
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);
|
|
231
|
+
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
232
|
evolveRaw = answer.usage;
|
|
233
233
|
summary.evolveToken += totalOf(evolveRaw);
|
|
234
234
|
const evolved = parseEvolveAnswer(answer.text);
|
|
@@ -242,17 +242,17 @@ async function reviewOne(deps, runId, candidate, opts, summary, skipReasons) {
|
|
|
242
242
|
return;
|
|
243
243
|
}
|
|
244
244
|
if (evolved.verdict === "quarantine") {
|
|
245
|
-
landQuarantine(deps, base, candidate, opts, evolved.reason, gateUsage, evolveRaw, summary);
|
|
245
|
+
landQuarantine(deps, base, candidate, opts, evolved.reason, gateUsage, evolveRaw, proposedOf(evolved), summary);
|
|
246
246
|
return;
|
|
247
247
|
}
|
|
248
248
|
// ── Rewrite: magnitude cap first, dry-run second, gates last ──
|
|
249
249
|
const nextBody = evolved.body ?? candidate.body;
|
|
250
250
|
if (rewriteMagnitude(candidate.body, nextBody) > REWRITE_MAGNITUDE_CAP) {
|
|
251
|
-
landQuarantine(deps, base, candidate, opts, `幅度超限转隔离:${evolved.reason}`, gateUsage, evolveRaw, summary);
|
|
251
|
+
landQuarantine(deps, base, candidate, opts, `幅度超限转隔离:${evolved.reason}`, gateUsage, evolveRaw, proposedOf(evolved), summary);
|
|
252
252
|
return;
|
|
253
253
|
}
|
|
254
254
|
if (opts.dryRun) {
|
|
255
|
-
deps.store.logReview({ ...base, verdict: "rewrite", reason: `试运行未落盘:${evolved.reason}`, cheapUsage: gateUsage, evolveUsage: evolveRaw, applied: 0 });
|
|
255
|
+
deps.store.logReview({ ...base, verdict: "rewrite", reason: `试运行未落盘:${evolved.reason}`, proposed: proposedOf(evolved), cheapUsage: gateUsage, evolveUsage: evolveRaw, applied: 0 });
|
|
256
256
|
return;
|
|
257
257
|
}
|
|
258
258
|
landRewrite(deps, base, candidate, opts, evolved, gateUsage, evolveRaw, summary);
|
|
@@ -262,6 +262,26 @@ async function reviewOne(deps, runId, candidate, opts, summary, skipReasons) {
|
|
|
262
262
|
skipReasons.push("evolve-llm-failed");
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* The rewrite payload a non-landing row keeps: exactly the fields the model
|
|
267
|
+
* supplied, or `undefined` when it proposed no text at all.
|
|
268
|
+
*/
|
|
269
|
+
function proposedOf(evolved) {
|
|
270
|
+
const payload = {};
|
|
271
|
+
if (evolved.title !== undefined) {
|
|
272
|
+
payload.title = evolved.title;
|
|
273
|
+
}
|
|
274
|
+
if (evolved.description !== undefined) {
|
|
275
|
+
payload.description = evolved.description;
|
|
276
|
+
}
|
|
277
|
+
if (evolved.body !== undefined) {
|
|
278
|
+
payload.body = evolved.body;
|
|
279
|
+
}
|
|
280
|
+
if (evolved.corrects !== undefined) {
|
|
281
|
+
payload.corrects = evolved.corrects;
|
|
282
|
+
}
|
|
283
|
+
return Object.keys(payload).length === 0 ? undefined : payload;
|
|
284
|
+
}
|
|
265
285
|
function neighborHooks(store, candidate) {
|
|
266
286
|
try {
|
|
267
287
|
if (candidate.kind === "memory") {
|
|
@@ -276,10 +296,10 @@ function neighborHooks(store, candidate) {
|
|
|
276
296
|
return [];
|
|
277
297
|
}
|
|
278
298
|
}
|
|
279
|
-
function landQuarantine(deps, base, candidate, opts, reason, gateUsage, evolveRaw, summary) {
|
|
299
|
+
function landQuarantine(deps, base, candidate, opts, reason, gateUsage, evolveRaw, proposed, summary) {
|
|
280
300
|
const prior = deps.store.reviewStateOf(candidate.workspaceId, candidate.kind, candidate.id)?.evolveCount ?? 0;
|
|
281
301
|
if (opts.dryRun) {
|
|
282
|
-
deps.store.logReview({ ...base, verdict: "quarantine", reason: `试运行未隔离:${reason}`, cheapUsage: gateUsage, evolveUsage: evolveRaw, applied: 0, evolveCount: prior });
|
|
302
|
+
deps.store.logReview({ ...base, verdict: "quarantine", reason: `试运行未隔离:${reason}`, proposed, cheapUsage: gateUsage, evolveUsage: evolveRaw, applied: 0, evolveCount: prior });
|
|
283
303
|
return;
|
|
284
304
|
}
|
|
285
305
|
const ok = deps.store.quarantine(candidate.workspaceId, candidate.kind, candidate.id);
|
package/lib/store-apply.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export interface ProposalContext {
|
|
|
28
28
|
usage?: unknown;
|
|
29
29
|
/** Pre-gate call payload (extraction cheap gate); carried into the ledger row. */
|
|
30
30
|
cheapUsage?: unknown;
|
|
31
|
+
/** Error head when the pre-gate call threw (fail open); carried into the ledger row. */
|
|
32
|
+
cheapError?: string | undefined;
|
|
31
33
|
/** One-line model decision summary for the ledger. */
|
|
32
34
|
decision?: string | undefined;
|
|
33
35
|
}
|
package/lib/store-apply.js
CHANGED
|
@@ -63,6 +63,7 @@ export function applyProposals(db, ctx, proposals) {
|
|
|
63
63
|
model: ctx.model,
|
|
64
64
|
usage: ctx.usage,
|
|
65
65
|
cheapUsage: ctx.cheapUsage,
|
|
66
|
+
cheapError: ctx.cheapError,
|
|
66
67
|
files: applied ? files : [],
|
|
67
68
|
};
|
|
68
69
|
if (!applied) {
|
|
@@ -71,10 +72,10 @@ export function applyProposals(db, ctx, proposals) {
|
|
|
71
72
|
writeLedger(db.database.prepare(LEDGER_SQL), ledger);
|
|
72
73
|
return { outcomes, applied };
|
|
73
74
|
}
|
|
74
|
-
const LEDGER_SQL = "INSERT INTO extraction_log (run_id, ts, session_id, workspace_id, trigger, decision, skip_reason, status, duration_ms, model, usage, cheap_usage, files) " +
|
|
75
|
-
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
|
75
|
+
const LEDGER_SQL = "INSERT INTO extraction_log (run_id, ts, session_id, workspace_id, trigger, decision, skip_reason, status, duration_ms, model, usage, cheap_usage, cheap_error, files) " +
|
|
76
|
+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
|
76
77
|
function writeLedger(stmt, entry) {
|
|
77
|
-
stmt.run(entry.runId ?? null, new Date().toISOString(), entry.sessionId ?? null, entry.workspaceId ?? null, entry.trigger, entry.decision ?? null, entry.skipReason ?? null, entry.status ?? null, entry.durationMs ?? null, entry.model ?? null, entry.usage === undefined ? null : JSON.stringify(entry.usage), entry.cheapUsage === undefined ? null : JSON.stringify(entry.cheapUsage), entry.files === undefined ? null : JSON.stringify(entry.files));
|
|
78
|
+
stmt.run(entry.runId ?? null, new Date().toISOString(), entry.sessionId ?? null, entry.workspaceId ?? null, entry.trigger, entry.decision ?? null, entry.skipReason ?? null, entry.status ?? null, entry.durationMs ?? null, entry.model ?? null, entry.usage === undefined ? null : JSON.stringify(entry.usage), entry.cheapUsage === undefined ? null : JSON.stringify(entry.cheapUsage), entry.cheapError ?? null, entry.files === undefined ? null : JSON.stringify(entry.files));
|
|
78
79
|
}
|
|
79
80
|
/** Validate one proposal and land it; appends the audit payload on success. */
|
|
80
81
|
function applyOne(db, ctx, proposal, stmts, files) {
|
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 {
|
|
@@ -134,6 +141,13 @@ export interface LedgerEntry {
|
|
|
134
141
|
usage?: unknown;
|
|
135
142
|
/** Pre-gate call payload (extraction cheap gate); `undefined` when the run never reached it. */
|
|
136
143
|
cheapUsage?: unknown;
|
|
144
|
+
/**
|
|
145
|
+
* Why the pre-gate call left no payload: the error head when the gate
|
|
146
|
+
* threw (fail open). `undefined` when the gate never ran, never resolved
|
|
147
|
+
* to an answer, or was not reached — the column exists so that a failed
|
|
148
|
+
* gate is tellable from a gate that never existed.
|
|
149
|
+
*/
|
|
150
|
+
cheapError?: string | undefined;
|
|
137
151
|
/** Applied/attempted mutations: `{id, action, before?, after?, sourceSeqs}`; a parse-failed run instead carries the raw answer's head. */
|
|
138
152
|
files?: unknown;
|
|
139
153
|
}
|
package/lib/store.js
CHANGED
|
@@ -70,7 +70,7 @@ CREATE TABLE IF NOT EXISTS extraction_log (
|
|
|
70
70
|
trigger TEXT CHECK (trigger IN ('turn-debounce','compaction','close-drain','explicit','import','item-review')),
|
|
71
71
|
decision TEXT, skip_reason TEXT,
|
|
72
72
|
status TEXT, duration_ms INTEGER, model TEXT, usage TEXT,
|
|
73
|
-
cheap_usage TEXT,
|
|
73
|
+
cheap_usage TEXT, cheap_error TEXT,
|
|
74
74
|
files TEXT, occurrences INTEGER NOT NULL DEFAULT 1
|
|
75
75
|
);
|
|
76
76
|
CREATE TABLE IF NOT EXISTS state (
|
|
@@ -130,6 +130,7 @@ CREATE TABLE IF NOT EXISTS review_log (
|
|
|
130
130
|
item_id TEXT NOT NULL,
|
|
131
131
|
verdict TEXT NOT NULL CHECK (verdict IN ('keep','rewrite','quarantine','skip')),
|
|
132
132
|
reason TEXT,
|
|
133
|
+
proposed TEXT,
|
|
133
134
|
cheap_usage TEXT, evolve_usage TEXT,
|
|
134
135
|
applied INTEGER NOT NULL DEFAULT 0,
|
|
135
136
|
evolve_count INTEGER NOT NULL DEFAULT 0
|
|
@@ -302,6 +303,8 @@ export async function openMemoryStore(explicitPath) {
|
|
|
302
303
|
ensureLedgerOccurrences(database);
|
|
303
304
|
ensureMemoriesCorrects(database);
|
|
304
305
|
ensureExtractionCheapUsage(database);
|
|
306
|
+
ensureExtractionCheapError(database);
|
|
307
|
+
ensureReviewProposed(database);
|
|
305
308
|
const stmts = {
|
|
306
309
|
get: database.prepare("SELECT * FROM memories WHERE workspace_id = ? AND id = ?"),
|
|
307
310
|
list: database.prepare(`SELECT * FROM memories WHERE workspace_id = ? AND status = 'active' ${LIST_ORDER}`),
|
|
@@ -320,8 +323,8 @@ export async function openMemoryStore(explicitPath) {
|
|
|
320
323
|
"WHERE status = 'active' AND workspace_id <> '' GROUP BY workspace_id ORDER BY ts DESC LIMIT 1"),
|
|
321
324
|
recentSkill: database.prepare("SELECT workspace_id, MAX(ts) AS ts FROM skill_log " +
|
|
322
325
|
"WHERE workspace_id IS NOT NULL AND workspace_id <> '' GROUP BY workspace_id ORDER BY ts DESC LIMIT 1"),
|
|
323
|
-
ledger: database.prepare("INSERT INTO extraction_log (run_id, ts, session_id, workspace_id, trigger, decision, skip_reason, status, duration_ms, model, usage, cheap_usage, files) " +
|
|
324
|
-
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"),
|
|
326
|
+
ledger: database.prepare("INSERT INTO extraction_log (run_id, ts, session_id, workspace_id, trigger, decision, skip_reason, status, duration_ms, model, usage, cheap_usage, cheap_error, files) " +
|
|
327
|
+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"),
|
|
325
328
|
latestSkip: database.prepare("SELECT rowid AS rid, skip_reason AS reason, status FROM extraction_log " +
|
|
326
329
|
"WHERE workspace_id IS ? AND session_id IS ? ORDER BY ts DESC, rowid DESC LIMIT 1"),
|
|
327
330
|
bumpSkip: database.prepare(`UPDATE extraction_log SET ts = ?, ${LEDGER_OCCURRENCES} = ${LEDGER_OCCURRENCES} + 1 WHERE rowid = ?`),
|
|
@@ -356,8 +359,8 @@ export async function openMemoryStore(explicitPath) {
|
|
|
356
359
|
memUseGet: database.prepare("SELECT use_count, last_used_at FROM memory_usage WHERE workspace_id = ? AND memory_id = ?"),
|
|
357
360
|
memUseUpsert: database.prepare("INSERT INTO memory_usage (workspace_id, memory_id, use_count, last_used_at) VALUES (?, ?, 1, ?) " +
|
|
358
361
|
"ON CONFLICT (workspace_id, memory_id) DO UPDATE SET use_count = use_count + 1, last_used_at = excluded.last_used_at"),
|
|
359
|
-
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) " +
|
|
360
|
-
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"),
|
|
362
|
+
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) " +
|
|
363
|
+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"),
|
|
361
364
|
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"),
|
|
362
365
|
reviewEvolved: database.prepare("SELECT COUNT(*) AS n FROM review_log WHERE workspace_id IS ? AND item_kind = ? AND item_id = ? AND applied = 1"),
|
|
363
366
|
reviewPrune: database.prepare("DELETE FROM review_log WHERE ts < ?"),
|
|
@@ -902,7 +905,7 @@ export async function openMemoryStore(explicitPath) {
|
|
|
902
905
|
}
|
|
903
906
|
},
|
|
904
907
|
logReview(entry) {
|
|
905
|
-
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);
|
|
908
|
+
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);
|
|
906
909
|
},
|
|
907
910
|
consumeReviewBudget(day, budget) {
|
|
908
911
|
stmts.dailyUpsert.run(day, budget);
|
|
@@ -1002,6 +1005,31 @@ function ensureExtractionCheapUsage(database) {
|
|
|
1002
1005
|
}
|
|
1003
1006
|
database.exec("ALTER TABLE extraction_log ADD COLUMN cheap_usage TEXT");
|
|
1004
1007
|
}
|
|
1008
|
+
/**
|
|
1009
|
+
* Add the extraction ledger `cheap_error` column to a store created before
|
|
1010
|
+
* the failed-gate head was ledgered. Separate from the `cheap_usage`
|
|
1011
|
+
* migration above so a store that already carries that column still gains
|
|
1012
|
+
* this one. Same single-migration discipline as the columns above.
|
|
1013
|
+
*/
|
|
1014
|
+
function ensureExtractionCheapError(database) {
|
|
1015
|
+
const columns = database.prepare("SELECT name FROM pragma_table_info('extraction_log')").all();
|
|
1016
|
+
if (columns.some((column) => column.name === "cheap_error")) {
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
database.exec("ALTER TABLE extraction_log ADD COLUMN cheap_error TEXT");
|
|
1020
|
+
}
|
|
1021
|
+
/**
|
|
1022
|
+
* Add the review ledger `proposed` column to a store created before trial
|
|
1023
|
+
* mode started keeping the rewrite it declined to land. Same single-migration
|
|
1024
|
+
* discipline as the columns above.
|
|
1025
|
+
*/
|
|
1026
|
+
function ensureReviewProposed(database) {
|
|
1027
|
+
const columns = database.prepare("SELECT name FROM pragma_table_info('review_log')").all();
|
|
1028
|
+
if (columns.some((column) => column.name === "proposed")) {
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
database.exec("ALTER TABLE review_log ADD COLUMN proposed TEXT");
|
|
1032
|
+
}
|
|
1005
1033
|
/** Parse the daily skip-counts map; corrupt payloads degrade to empty. */
|
|
1006
1034
|
function parseCounts(raw) {
|
|
1007
1035
|
if (raw === null) {
|
|
@@ -1026,6 +1054,6 @@ function parseCounts(raw) {
|
|
|
1026
1054
|
}
|
|
1027
1055
|
/** JSON-encode the optional ledger fields and insert the row (never throws past a warn). */
|
|
1028
1056
|
function writeLedger(stmt, entry) {
|
|
1029
|
-
stmt.run(entry.runId ?? null, new Date().toISOString(), entry.sessionId ?? null, entry.workspaceId ?? null, entry.trigger, entry.decision ?? null, entry.skipReason ?? null, entry.status ?? null, entry.durationMs ?? null, entry.model ?? null, entry.usage === undefined ? null : JSON.stringify(entry.usage), entry.cheapUsage === undefined ? null : JSON.stringify(entry.cheapUsage), entry.files === undefined ? null : JSON.stringify(entry.files));
|
|
1057
|
+
stmt.run(entry.runId ?? null, new Date().toISOString(), entry.sessionId ?? null, entry.workspaceId ?? null, entry.trigger, entry.decision ?? null, entry.skipReason ?? null, entry.status ?? null, entry.durationMs ?? null, entry.model ?? null, entry.usage === undefined ? null : JSON.stringify(entry.usage), entry.cheapUsage === undefined ? null : JSON.stringify(entry.cheapUsage), entry.cheapError ?? null, entry.files === undefined ? null : JSON.stringify(entry.files));
|
|
1030
1058
|
}
|
|
1031
1059
|
//# sourceMappingURL=store.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-continual-evolve",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.10",
|
|
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": {
|