@morning-start/dsh-code-toolkit 0.28.1 → 0.30.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,125 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.30.1 — 2026-12-04
4
+
5
+ `0.30.0` was cut but never tagged; the caption goal fix below rides with it, so the line ships as
6
+ a patch.
7
+
8
+ - **An injected run's decision rules now live in a system section, not only in the message.** The
9
+ persona was delivered to the current session as one steered user message (`src/command.js`),
10
+ while an isolated child gets a system-prompt section (`src/runtime.js`) — the same protocol at
11
+ two very different strengths. In a long session the message competes with everything else, and
12
+ a compaction can summarize it away; the second run of a command injects only a one-line "the
13
+ protocol is already installed", so the rules survive on nothing. `inject()` now also installs a
14
+ `CODE_TOOLKIT_PROTOCOL` section carrying the two decisions a run makes about itself — when the
15
+ plan warrants a goal, and when the ready items warrant a wave — replacing its own section on a
16
+ later run instead of stacking copies, and falling back silently on a host without the service.
17
+ The receipt ends with a suffix when the section was installed, so the person can see which
18
+ carrier their session actually got. This is the likely reason a live run dispatched two
19
+ children while a real session never opened a goal.
20
+ - **The two autonomy triggers are shape predicates now, and a live run confirmed the dispatch
21
+ one.** "Open a goal when the person asked the work to run to completion" waited for a phrase a
22
+ plain task never contains; "dispatch when the briefs cost less than the work" was an estimate
23
+ that always came out negative. Both now read the plan: **three or more items, or criteria no
24
+ single iteration can prove**, opens a goal; **two or more ready items with disjoint paths, a
25
+ gate each and more than a one-line edit** is a wave. In run 4 — same fixture shape, nothing in
26
+ the prompt about agents or goals — caption dispatched two children in one message, wrote both
27
+ rows and owners before the first call, collected with `wait_agent`, and re-ran the merged gate
28
+ itself (10/10). `list_agents` still lists both grandchildren, so the split is verified by the
29
+ tree rather than by the report. It also decided on its own that a goal was warranted and called
30
+ `create_goal` — refused, because a delegated child cannot hold one. Both children then corrected
31
+ the parent's brief (a guessed test count, and a git ban it applied to itself but never passed
32
+ down), which are now two brief rules in `references/dispatch.md`.
33
+ - **The caption protocol was run for real, three times, on fixtures that genuinely fail.** A
34
+ delegated child with an empty context, given only the persona and a task, produced ledgers with
35
+ plans, dependencies, dispatch tables and entries carrying exit codes; it proved its guards by
36
+ breaking them; it wrote probe scripts to check documentation claims and deleted them after. Two
37
+ runs correctly *declined* to dispatch (both slices behind one gate), and the third dispatched two
38
+ children in one message, recorded both rows and owners **before** the first `subagent` call,
39
+ collected with `wait_agent`, and re-ran the merged gate itself. `list_agents` afterwards still
40
+ showed both grandchildren, so the dispatch is verified by the tree rather than by the report.
41
+ **`create_goal` is structurally unavailable to a delegated child** — three attempts, one error:
42
+ `this goal operation requires a direct human turn on a top-level agent` — which means the goal
43
+ tier only exists in-session, and that half of the protocol remains unmeasured. See
44
+ `evals/results/iteration-13.md`.
45
+ - **`docs/tooling-map.md`: every module against the host's own services and tools.** The scan
46
+ found one class of mistake repeated across personas — a mechanism described in our words when
47
+ the host has a tool — and one class of mistake waiting to happen: telling a persona to spawn a
48
+ child the plugin already spawned. `design` now asks its three questions with
49
+ `ask_user_question` instead of prose, `simplify` and `scrub` mirror their item lists into
50
+ `todo_write`, and the caption approval gate is named as a three-option question. Five
51
+ candidates were considered and refused with reasons (`ctx.approval` is a permission policy, not
52
+ a design decision; `ctx.workspaceChanges` records turn diffs, not branch scopes;
53
+ `ctx.actionCards` is a UI projection; `ctx.agentTeams` is a board for the Lead session;
54
+ `ctx.workflowEngine` is the engine under `workflow`, not a protocol). A test now fails if any
55
+ of `review` / `simplify` / `scrub` starts naming `subagent`.
56
+ - **The caption reference pages are 18% smaller and one of them was broken.** `dispatch.md`
57
+ merged its two overlapping "when not to parallelize" lists into one and moved the child-failure
58
+ rules next to the wave they belong to; `loop.md` dropped the section that restated the plan
59
+ format; `experts.md` merged sizing into its rules. Two real defects fell out of the pass:
60
+ `flows.md` had a paragraph inserted **inside** Flow A's table, splitting it into two, and
61
+ `experts.md` had lost its lifecycle heading to an earlier merge. 37 520 → 30 693 characters.
62
+ - **Every mechanism that the host already provides now uses the host's tool.** The sweep
63
+ found three of ours standing in for one of theirs: the clarification questions now go
64
+ through `ask_user_question`, `workflow` is documented as the official orchestrator with its
65
+ bar (explicit request, or a wave big enough that hand-dispatch stops paying), and the
66
+ unattended case is no longer a rule of ours — `schedule_create` is the official mechanism,
67
+ and it is bounded by what the installed `docs/user/guide/schedule.md` promises: a delivery
68
+ proves the message reached the inbox, **not that the model did the work**; exactly-once is
69
+ not guaranteed; closing the Host discards a message still waiting; a child is refused by
70
+ the schedule tools. So a run is scheduled only when the person asks, and carries a stop
71
+ condition. The ledger stays ours because the host has no cross-session plan store —
72
+ `todo_write` dies with the session and a resumed goal comes back disarmed.
73
+ - **The caption plan is a dependency graph, not a flat list.** Items take `| deps: 2,3` and
74
+ `| owner: <child>`; `src/caption.js` parses both and derives `ready` (deps all done, no
75
+ owner) and `inFlight` (open with an owner), so "what is next" is computed instead of felt.
76
+ `list` and `/code-status` show it: `计划 2/5 · 1 项在飞`.
77
+ - **Dispatch is recorded, and runs in waves.** The ledger gains a `## Dispatch` table
78
+ (child / lane / paths / gate / state / entry) that only the root writes. A wave is the
79
+ ready items with disjoint write sets, capped at three children, each required to answer in
80
+ at most twenty lines. Dispatch, do your own item, collect with `wait_agent`, then run the
81
+ whole gate on the merged tree yourself — a child's green is not the merged tree's green.
82
+ Children still cannot fan out (the plugin already denies delegation tools); a slice that
83
+ needs sub-slices is two waves.
84
+ - **A long run continues in two states, not three.** Same session: the goal keeps running.
85
+ Resumed session: the goal comes back disarmed, so `update_goal resume` and then read the
86
+ ledger before touching an item. Unattended: **not part of this protocol** — the loop never
87
+ schedules its own continuation, because a scheduled prompt arrives as a message from a
88
+ person who is not watching. The ledger is what survives the session; the clock is theirs.
89
+ - 134 → 136 deterministic checks.
90
+
91
+ ## 0.29.0 — 2026-11-29
92
+
93
+ - **"Propose, then act" is now the shared spine of every command that changes files.**
94
+ Review writes a finding before fixing it, simplify writes the plan (what it is now, what
95
+ it becomes, why behaviour is unchanged) before the first edit, scrub writes the dry-run
96
+ JSON and the redaction list before touching a file, caption writes the proposal before
97
+ opening a goal. The two steps may share one run, but the order cannot swap and the plan
98
+ must be on disk, not in the model's head. Read-only commands stop at the proposal. The
99
+ rule is a project constraint (`AGENTS.md` #11) with a test behind it, and a table in the
100
+ README saying which artifact is each command's plan.
101
+ - **The caption loop is now six stages, each with a refusal.** 方案 → goal → small tasks →
102
+ one item at a time → incremental task updates → until the goal is met. The first stage is
103
+ the new part: when the intent is too vague to propose an approach, caption stops and
104
+ either asks the two or three questions that would settle it or names the command that
105
+ answers it first (`/code-design` when the need is still a need, `/code-audit` when the
106
+ question is what exists today) — and says which approach it would take. **A ledger is
107
+ never opened for a task that cannot be stated**: a ledger for a wish produces entries
108
+ that record activity instead of progress. This closes the loop with `/code-design`, whose
109
+ last line already hands approved plans to `/code-caption`.
110
+ - **`/code-caption` now opens a DSH goal, and mirrors its plan into the task list.** The
111
+ intent-to-plan work was already in the ledger, but nothing ever told it to use the
112
+ host's continuation mechanism: `git log -S'create_goal'` returns nothing for the
113
+ repository's whole history, and the plugin's only tool restriction (`src/runtime.js`, a
114
+ deny list of delegation tools) never touched it. A run for "finish this" now opens a goal
115
+ once the plan is approved, closes it with `update_goal complete` when the plan is empty
116
+ and the criteria hold, and reports `blocked` with a concrete reason instead of quietly
117
+ stopping. `todo_write` mirrors the ledger's `## Plan` for the person watching; the ledger
118
+ stays authoritative, because the todo list dies with the session and the ledger does not.
119
+ `update_goal` needs `goal_id` and `revision`, so the loop reads `get_goal` first — the
120
+ detail lives in `agents/caption/references/loop.md`. Persona text, **not measured**
121
+ (see `evals/results/iteration-10.md`); the persona moved 7 652 → 8 433 characters.
122
+
3
123
  ## 0.28.1 — 2026-11-29
4
124
 
5
125
  - **Menu labels and hints were cut to a scan length.** Every `description` had grown
package/README.md CHANGED
@@ -43,7 +43,7 @@ DeepSeek Harness 的代码工具箱:**审查**、**精炼**、**隐私清理**
43
43
  | `/code-simplify` | 一次改造:功能不变的前提下简化 | 一次性 | `report` 出方案 → 人看过 → 再跑一次执行 | 是,默认写 |
44
44
  | `/code-scrub` | 一次清理:找出并移除隐私信息 | 一次性 | 同上,报告默认脱敏 | 是,默认写 |
45
45
  | `/code-audit` | 一次判断:现有能力是「通」还是「看起来有」 | 一次性,只读 | 单段:五态表 + `file:line`,没有 apply 路径 | **否** |
46
- | `/code-caption` | 复杂任务:跨轮、要验证、要台账 | **持续**,多轮多步 | 完整契约:需求 → 调查 → 方案 → **人审** → 执行 → 测试 → 人确认 → 改文档 | 是,按方案 |
46
+ | `/code-caption` | 复杂任务:跨轮、要验证、要台账 | **持续**,多轮多步 | 完整契约:方案 → **人批** → goal → 拆小任务 → 逐项推进 → 渐进更新 → 到完成 | 是,按方案 |
47
47
  | `/code-design` | 一次设计:把「缺什么」压成带证据的场景与批次 | **持续**,多轮,随人回答推进 | 四张底图 → 场景 → 排序 → 批次表 → **人批**;止于方案 | 只写 `docs/design/`,不写代码 |
48
48
  | `/pua` | 一次注入:给当前会话装纪律 | 一次性,注入即结束 | 无审核环节——它不做事,只改做事的方式 | 否 |
49
49
  | `/code-status` | 查询:干到哪了 | 只读 | 无 | 否 |
@@ -51,6 +51,21 @@ DeepSeek Harness 的代码工具箱:**审查**、**精炼**、**隐私清理**
51
51
 
52
52
  **只有 caption 需要完整契约**,因为它是唯一要连续跑门禁、唯一有「方案被推翻要回头改」的命令。design 也跨轮,但它跨轮是为了跟人把方案谈清楚:**它止于方案**,批准之后交给 caption 执行——所以设计命令没有台账,也没有门禁。其余命令是一次单独的行动——它们的「审核」要么压缩成一个开关(`report`),要么根本不存在。
53
53
 
54
+ ### 共同骨架:方案 → 动手
55
+
56
+ **所有会改文件的命令都是同一个形状,只是粒度不同**:先把要改的写成方案(改什么、改哪、为什么、怎么证明),再动手。顺序不能颠倒,方案必须落盘。
57
+
58
+ | 命令 | 它的「方案」是 | 什么时候动手 |
59
+ | --- | --- | --- |
60
+ | `/code-review` | findings:每条带 `path:line` 和证据 | 同一轮接着修;`report` 就停在方案 |
61
+ | `/code-simplify` | plan:每处 `now → change to` + 行为不变的论证 | 方案写完、门禁定好之后;`report` 停在方案 |
62
+ | `/code-scrub` | 脱敏清单 + 干跑 JSON,值已打码 | 同上 |
63
+ | `/code-caption` | 方案 → goal → 任务清单 | 你批了之后,逐项推进 |
64
+
65
+ 只读的两条止于方案:`/code-audit` 的产物就是报告,`/code-design` 的产物就是方案(执行交出去)。`status` / `cancel` 没有方案。
66
+
67
+ 这条规则在 `AGENTS.md` 的硬约束里,也有测试守着——「方案先落盘、再动手」不是建议。
68
+
54
69
  ## 一个外壳,所有命令
55
70
 
56
71
  命令的行为不是各写一遍:九条命令全部由同一个 `SessionCommand` 类实现([src/command.js](src/command.js))。每条命令只提供一份声明:
@@ -68,6 +83,17 @@ DeepSeek Harness 的代码工具箱:**审查**、**精炼**、**隐私清理**
68
83
 
69
84
  统一的好处是行为一致:都立刻返回、都先定范围、失败都发一条说明、都写 journal;差异只留在声明里,不再散落在每个 handler 中。测试会检查 `index.js` 里没有直接 `ctx.commands.register`——绕开外壳就等于又写了一遍。
70
85
 
86
+ ## 和宿主的分工
87
+
88
+ 这个插件不重造宿主已经有的东西。两类替代,不能混:
89
+
90
+ - **(S)服务**:插件代码做的事,宿主有服务 → 直接调。命令注册 `ctx.commands`、隔离运行 `ctx.subagents`、persona 注入 `ctx.systemPrompt`、子 agent 工具限制 `ctx.tools.restrict`、语言 `settings`。
91
+ - **(T)工具**:模型做的事,宿主有工具 → persona 里只写工具名,不写怎么做。续跑用 `create_goal`、进度用 `todo_write`、派工用 `subagent` / `wait_agent`、提问用 `ask_user_question`、大规模编排用 `workflow`、无人值守用 `schedule_create`。
92
+
93
+ 一条容易搞反的推论:**插件已经派出去的孩子,不能再被告知去派**。`review sub` / `simplify sub` / `scrub sub` 是 `src/runtime.js` 派的,它们的 persona 里不能出现 `subagent`,否则孩子会在刚建好的隔离里再扇出。只有跑在你自己会话里的 `/code-caption` 才派工。
94
+
95
+ 每个功能模块对着哪个宿主机制、哪些候选被否掉(以及为什么),在 [docs/tooling-map.md](docs/tooling-map.md)。
96
+
71
97
  ## 提示词不是两个文件
72
98
 
73
99
  `agents/` 按 skill 的三层结构组织,而不是把全部规则塞进一个 prompt:
@@ -151,7 +177,16 @@ agents/pua/
151
177
 
152
178
  `/code-caption <任务>` 是这套东西里唯一不 spawn 的命令,因为它的对象不是一次检查,而是**一次长任务的进行方式**。
153
179
 
154
- 它注入的不是一张清单,而是一个循环:读台账 → 取计划里下一项 → 看真实状态 → 动手(锚点唯一、改完读回)→ 跑门禁 → 给新守卫做反证 → 记一条 caption 并提交 → 改计划。循环的产物是 `docs/caption/<slug>.md`:头部写目标、判据、门禁和**计划清单**,清单在头部原地改;每条写看到什么、判断什么、做了什么、命令与结果、结论(done / dead end / unverified)。
180
+ 它注入的不是一张清单,而是六个阶段,**每个阶段都带一个「不该硬推」时的出口**:
181
+
182
+ 1. **方案** — 改什么、改哪、为什么这样改、不做什么。方案说不清就停:问两三个能定的问题,或者指出该先用哪条命令——需求本身还没定 → `/code-design`;问「现在到底有什么」→ `/code-audit`——并说明你会怎么走。**说不清的任务不写台账。**
183
+ 2. **设 goal** — 一句目标 + 判据;你要求「跑到完成」时用 `create_goal` 开目标。
184
+ 3. **拆小任务** — 按结果切、每项自带检查;写进台账 `## Plan`,`todo_write` 同步给人看。
185
+ 4. **逐步推进** — 一次一项:读台账 → 看真实状态 → 动手(锚点唯一、改完读回)→ 跑门禁 → 给新守卫做反证 → 记一条并提交。
186
+ 5. **渐进更新** — 勾掉、重写 todo、证据推翻计划时原地改计划并写明是第几条改的。
187
+ 6. **直到完成** — 计划无未完成项且判据成立才收口,`update_goal complete`;卡住就 `blocked`,写清阻因。
188
+
189
+ 循环的产物是 `docs/caption/<slug>.md`:头部写目标、判据、门禁和**计划清单**,清单在头部原地改;每条写看到什么、判断什么、做了什么、命令与结果、结论(done / dead end / unverified)。
155
190
 
156
191
  三条规则是它的全部价值:**没有证据就不许声称**、**死路要留痕**、**判据满足才收口,清单空了不算**。另外两条补在同一节:**门禁绿不等于功能在**(碰了入口的改动,必须有一次走到真实入口、真数据、看结果);**关于宿主和第三方的判断先写探针**,「文档说支持」不算证据,探针没跑就进未验证清单。细节在 `agents/caption/references/`,一次健康的运行与一次"忙碌但什么都没证明"的运行在 `examples/` 里对照。
157
192
 
@@ -178,8 +213,64 @@ caption 不是「你给任务,它照着做」。你给的是一句**意图**
178
213
 
179
214
  `[ ]` 未做、`[x]` 完成、`[~]` 受阻、`[-]` 放弃。**原地改**,绝不追加第二份计划——计划是当前状态,条目是历史。勾掉时把条目号写在旁边,后来的人不用翻。没有 gate 的那一行不是计划项,是备注。
180
215
 
216
+ ### 三层:goal / 台账 / todo
217
+
218
+ 这三样分工不同,混起来就是三份互相打架的计划:
219
+
220
+ | 谁 | 活多久 | 回答什么 |
221
+ |---|---|---|
222
+ | `create_goal` | 本次会话的自动续轮 | 要不要不用人催,一直干到完成 |
223
+ | 台账 `## Plan` | 仓库里,跨会话 | 还剩哪几项,每项由什么证明 |
224
+ | `todo_write` | 本次会话,只给人看 | 现在在干哪一项 |
225
+
226
+ 你说了「做到完成为止」,它在方案批准后建 goal;收口时 `update_goal complete`,卡住时 `blocked` 并写出具体阻因。没说「跑到底」就不建——goal 会真的让会话自动续轮,不该替你做主。`todo_write` 每轮从 Plan 重写一遍,**台账永远是对的**:todo 随会话消失,台账不会。
227
+
181
228
  改计划是常态而不是失败:调查出结果后加、拆、删、重排都行,但每次都要写清是哪一条、为什么。一条**永远没被改过**的计划,说明调查没发现任何东西。
182
229
 
230
+ ### 编排:依赖图 + 派工表
231
+
232
+ 计划不是平铺清单,是**依赖图**。每项可以带两个字段,于是「下一项」是算出来的,不是感觉出来的:
233
+
234
+ ```markdown
235
+ ## Plan
236
+ - [x] 1. 复现失败 — gate: `node --test` 点名 `sum([])`(见条目 1)
237
+ - [ ] 2. 钉住契约 — gate: 新测试在旧代码上通过 | deps: 1
238
+ - [ ] 3. 修空输入 — gate: `sum([])` 为 0 | deps: 2
239
+ - [ ] 4. 修导出入口 — gate: 真实导出一次 | deps: 2 | owner: agent-import
240
+ ```
241
+
242
+ `deps` 全绿且没有 `owner` 的项=**可做**;同一波里互不冲突的可做项并行。`owner` 在派出去的那一刻写上,结果记完清除——续跑的人看到它就知道该**收**,不是该**再派**。
243
+
244
+ 派工本身也进台账,只有根 agent 写:
245
+
246
+ ```markdown
247
+ ## Dispatch
248
+ | child | lane | paths | gate | state | entry |
249
+ | --- | --- | --- | --- | --- | --- |
250
+ | agent-import | build | src/import/** | `node --test test/import` | running | — |
251
+ | agent-copy | analysis | src/, docs/ | — | returned | 4 |
252
+ ```
253
+
254
+ 四条规矩:**分析线只读可以扇出;实现线每个孩子独占一组路径**(含台账在内的共享文件只属于根);**派工→自己干一项→`wait_agent` 收齐→根在合并后的树上跑全量门禁**,孩子的绿不等于合并后的绿;**孩子不许再派**(插件已禁委派类工具)。每波最多三个孩子,每份报告不超过 20 行——上下文才是真的预算。
255
+
256
+ 用的是 DSH 官方工具:`subagent` / `subagent_fork` 派,`wait_agent` 收,`list_agents` 看谁还在跑,`send_message` 纠偏。
257
+
258
+ ### 官方机制优先,缺的自己补
259
+
260
+ caption 里凡是能交给宿主的,都交给宿主;只有宿主没有的才自己造:
261
+
262
+ | 能力 | 用谁的 | 说明 |
263
+ |---|---|---|
264
+ | 续跑 / 收口 / 卡住 | **官方** `create_goal` / `update_goal` | 迭代引擎是宿主的,六阶段只是每一轮的内容 |
265
+ | 实时进度 | **官方** `todo_write` | 台账的投影,不是第二份计划 |
266
+ | 派 / 收 / 看 / 纠偏 | **官方** `subagent`、`wait_agent`、`list_agents`、`send_message` | 孩子不能再派,也不能碰定时任务 |
267
+ | 大规模编排 | **官方** `workflow` | 只在明确要求「workflow」或波次很大时用 |
268
+ | 提问 | **官方** `ask_user_question` | 方案说不清时问那两三个问题 |
269
+ | 无人值守 | **官方** `schedule_create` | 保证弱:不保证执行、可能重复、关掉 Host 会丢,所以由人创建并带停止条件 |
270
+ | 计划 / 依赖 / 派工记录 | **自己的台账** | 宿主没有跨会话的计划存储,这是唯一必须自造的 |
271
+
272
+ 最后一行是被动选择,不是偷懒:`todo_write` 随会话消失,goal 重开就被 disarm,只有仓库里的台账能跨会话、跨机器、进 git。
273
+
183
274
  ### 台账是入口
184
275
 
185
276
  一个项目攒几份台账之后,「继续当前任务」就指不清了。所以:
@@ -1,78 +1,88 @@
1
1
  # Caption loop
2
2
 
3
- You are running one long task until it is actually done. You are not handed a plan: the
4
- person gives you an **intent** — "make the export work" — and you derive the goal, the
5
- acceptance criteria and the task list from it. Then you work the list one item per
6
- iteration, and you change the list when the repository contradicts it.
3
+ You are running one long task until it is done. You are not handed a plan: the person gives
4
+ you an **intent** — "make the export work" — and you derive the goal, criteria and task list
5
+ from it, then work the list one item per iteration, changing it when the code contradicts it.
7
6
 
8
- That is a loop over a list you own. What goes wrong is not the design — it is losing the
9
- thread: working without a proof, repeating a dead end, ticking an item that was never
10
- true, or reporting done while items remain open.
11
-
12
- ## From intent to a plan
13
-
14
- Before the first working iteration, write three things into the ledger head:
15
-
16
- - **Goal** — one sentence you can say back to the person without adding anything.
17
- - **Criteria** — how someone else tells it is done: a command, an observable state, or a
18
- file that must say something. "Works better" is not a criterion.
19
- - **Plan** — ordered **outcomes, not activities**. Each item is one result provable on
20
- its own, and each names the check that proves it. Ordering and sizing:
21
- `references/loop.md`.
22
-
23
- **The approval gate is not optional.** The person approves goal, criteria and plan
24
- together — a plan nobody read is not an approval, and a plan you keep in your head is not
25
- a plan. If the intent admits two materially different readings, ask before writing the
26
- plan; that one question is worth interrupting for.
7
+ What goes wrong is not the design — it is losing the thread: working without a proof,
8
+ repeating a dead end, or reporting done with items still open.
27
9
 
28
10
  ## The loop
29
11
 
30
- Every iteration takes **one item off the plan**.
31
-
32
- Before the first iteration, decide the flow — **changing code** or **changing
33
- documentation** — and write it in the ledger head. Both share one spine: requirement →
34
- investigate → propose → **the person approves** → execute → summarize;
35
- `references/flows.md` has each step.
36
-
37
- 1. **Read the ledger first.** Head, plan, last entry — before anything else. It is the
38
- only memory that survives compaction; never re-derive what it settled.
39
- 2. **Take the next open item** — the first unblocked one, not the most interesting, and
40
- not a new one you just thought of. Too big to prove in one step? Split it now.
41
- 3. **Observe the real state** — run the check that would prove the item, or read the file
42
- you are about to change. Work from the repository, not from memory.
43
- 4. **Act.** Read before you edit; make the anchor unique; read the changed region back.
44
- 5. **Verify.** Run the item's gate. Exit status decides, not your opinion. A red gate is
45
- data: diagnose, adjust, run the next iteration.
46
- 6. **Prove a new guard.** Break what it protects, watch it go red, restore, watch it go
47
- green. A guard you never saw fail is decoration.
48
- 7. **Record one caption entry, then commit.** Saw, decided, did, evidence, outcome — and
49
- tick the plan item with that entry's number.
50
- 8. **Re-plan.** When the evidence contradicted the plan, edit the plan: add, split, drop,
51
- reorder, naming the entry that caused it. A plan edited without a reason is drift.
52
-
53
- The loop ends when the plan has no open items **and** every criterion holds — not when
54
- the first plan is exhausted.
12
+ Six stages, in this order. Each has a refusal: what to do instead of pushing through.
13
+
14
+ 1. **方案 — the approach.** What changes, where, why this way, what you will not do. Not a
15
+ task list yet. Write it so someone else could execute it without you: it goes into the
16
+ ledger head, and a proposal only you can read is not one. If the intent is not clear
17
+ enough to propose, stop: ask the two or three questions that would settle it with
18
+ `ask_user_question`, or name the command that answers it first — `/code-design` when the
19
+ need is still a need, `/code-audit` when the question is what exists today — and say
20
+ which approach you would take and why you cannot start. **Never write a ledger for a task you cannot state.**
21
+
22
+ **The approval gate is not optional.** The person approves the approach, the criteria
23
+ and the tasks together — a plan nobody read is not an approval, and a plan you keep in
24
+ your head is not a plan. If it admits two materially different readings, ask before
25
+ writing it; that one question is worth interrupting for.
26
+
27
+ 2. **The goal.** One objective sentence, plus the criteria that prove it. **Open it from the
28
+ shape of the work, not from the person's wording**: three or more plan items, or criteria
29
+ no single iteration can prove, is a run that needs more than one turn — `create_goal` with
30
+ the objective, the criteria and which ledger carries the work. A one-turn task gets no
31
+ goal. On resume it comes back disarmed: `update_goal resume`, then read the ledger first.
32
+
33
+ 3. **Split it into small tasks.** Ordered outcomes, not activities — each provable on its
34
+ own, each naming its check. An item that needs two gates is two items. This is the
35
+ ledger's `## Plan`; `todo_write` mirrors it for the person watching.
36
+
37
+ 4. **Advance one item at a time.** Take the first unblocked item, not the most interesting
38
+ one. **Read the ledger first** — head, plan, last entry; it is the only memory that
39
+ survives compaction. Observe the real state, act (unique anchor, read the region back),
40
+ then **Verify**: run the item's gate, exit status decides. Prove a new guard by breaking
41
+ what it protects. **Record one caption entry** with saw, decided, did, evidence and
42
+ outcome, tick the item with that entry number, and commit while the gate is green.
43
+
44
+ 5. **Update the tasks as you learn.** Tick, rewrite `todo_write` from the plan, and edit
45
+ the plan when the evidence contradicted it — add, split, drop, reorder, naming the entry
46
+ that caused it. A plan edited without a reason is drift; a plan never edited means the
47
+ investigation found nothing.
48
+
49
+ 6. **Until the goal is met.** The run ends when the plan has no open items **and** every
50
+ criterion holds — not when the first plan is exhausted. Then `update_goal complete`,
51
+ reading it with `get_goal` first because the update needs its id and revision. When it
52
+ stalls, `blocked` with the concrete condition; being unsure is not blocked.
53
+
54
+ Before stage 1, decide the flow — **changing code** or **changing documentation** — and
55
+ write it in the ledger head. Both share the spine requirement → investigate → propose →
56
+ **the person approves** → execute → summarize; `references/flows.md` has each step.
55
57
 
56
58
  ## Dispatch
57
59
 
58
- Dispatch only when the work splits into slices that cannot collide.
60
+ The plan decides the wave — the items whose `deps` are green and whose `owner` is empty — and
61
+ **you decide whether a wave exists at all**. That is a shape question, so answer it from the
62
+ plan rather than from cost: **two or more ready items, touching disjoint paths, each with its
63
+ own gate and more than a one-line edit, are a wave.** One ready item, shared files, or one gate
64
+ for all of them is not. Write every child into the ledger's `## Dispatch` table before it
65
+ starts, and keep four rules:
59
66
 
60
67
  - **Analysis is read-only**, so it may fan out: one agent per area, findings with
61
- `file:line` and the command that produced them. No writes, no conflicts.
62
- - **Build writes**, so each agent owns a **disjoint** set of paths. Shared files —
63
- barrels, indexes, configs, lockfiles, shared tests — belong to **exactly one owner**,
64
- normally you. **Never run two writers on the same path**, and never split one coupled
65
- change across two agents.
66
-
67
- Two mechanisms only: `subagent` / `subagent_fork` for an analysis slice or a build slice
68
- nobody else touches; `/code-review sub`, `/code-simplify sub`, `/code-scrub sub` when the
69
- slice is exactly that check. The child does not see this conversation — everything it
70
- needs goes in the brief. Details: `references/dispatch.md`.
68
+ `file:line`. No writes, no conflicts.
69
+ - **Build writes**, so each child owns a **disjoint** set of paths. Shared files — barrels,
70
+ configs, lockfiles, shared tests, **and this ledger** — belong to **exactly one owner**,
71
+ which is you. **Never run two writers on the same path.**
72
+ - **You collect, you prove.** Dispatch, do your own item, collect with `wait_agent`, then
73
+ run the whole gate on the merged tree yourself. A child's green is not the merged tree's
74
+ green.
75
+ - **Children do not fan out.** They have no delegation tools; a slice needing sub-slices is
76
+ two waves from here.
77
+
78
+ First-party tools only: `subagent` / `subagent_fork`, and `/code-review sub`,
79
+ `/code-simplify sub`, `/code-scrub sub` when the slice is exactly that check.
80
+ The child does not see this conversation — the brief carries everything. Brief, table shape,
81
+ per-wave cap and failure handling: `references/dispatch.md`.
71
82
 
72
83
  ## Creating experts mid-run
73
84
 
74
- An expert is a paragraph, not a file: identity and bar, what it looks at, what counts as
75
- a finding, what is not, output shape. Five steps:
85
+ An expert is a paragraph, not a file. Five steps:
76
86
 
77
87
  1. **Write the brief first, in the ledger** — the question, the bar, what "done" is.
78
88
  2. **Decide the lane** — analysis (read-only, may fan out) or build (exclusive paths).
@@ -90,18 +100,17 @@ code. Method and worked briefs: `references/experts.md`.
90
100
  unrecorded one costs the next iteration the same discovery.
91
101
  - **Stop on outcomes, not on activity.** The plan has no open items **and** the criteria
92
102
  hold. A ticked item is not proof; the gate is.
93
- - **One gate per iteration.** Do not batch five changes and then test.
94
- - **A green gate is not a working feature.** When the change touches an entry point, one
95
- iteration must take the real entry point the way a person does, with real data. Record
96
- the click, the input, and the state afterwards.
103
+ - **A green gate is not a working feature, and one gate per iteration is the rule.** When
104
+ the change touches an entry point, one iteration must take the real entry point the way a
105
+ person does, with real data — record the click, the input, and the state afterwards.
97
106
  - **Assume nothing about the host.** Read the installed version, or write the smallest
98
107
  probe that prints the answer. "The docs say" is a lead, not evidence.
99
108
  - **A rejection is information.** Go back to investigation with the objection; a second
100
109
  rejection means the requirement is wrong — stop and ask.
101
110
  - **Stop when the loop stops paying.** Two iterations with no new fact mean stop and hand
102
111
  back what is blocked. A recorded "stuck here" beats a third attempt.
103
- - **Ask only at real forks** — scope change, irreversible action, unauthorized cost.
104
- Everything else: continue. Whatever is not verified stays in the unverified list.
112
+ - **Ask only at real forks** — scope change, irreversible action, unauthorized cost; anything
113
+ else goes in the unverified list and the run continues.
105
114
 
106
115
  ## The ledger
107
116
 
@@ -111,19 +120,21 @@ Write it to `docs/caption/<slug>.md`, creating the directory if needed. Three pa
111
120
  `- Approved`. First values win; a closing entry may repeat `- Gate:`.
112
121
 
113
122
  **Plan** — the open work, one line per item with the check that proves it: `[ ]` open,
114
- `[x]` done, `[~]` blocked, `[-]` dropped. **Edit it in place**; never append a second
115
- plan — the plan is current state, the entries are history. Tick with the entry number.
123
+ `[x]` done, `[~]` blocked, `[-]` dropped. Add `| deps: 2,3` when an item waits on another
124
+ and `| owner: <child>` once dispatched; that is what makes "next" derived instead of felt.
125
+ **Edit it in place**; never append a second plan — the plan is current state, the entries
126
+ are history.
127
+
128
+ `todo_write` mirrors that plan for the person watching; rewrite it from the plan each
129
+ iteration. **The ledger wins** every disagreement — the list dies with the session.
116
130
 
117
131
  **Entries** — appended, one per iteration: `## 3. <title>`, then `- Saw`, `- Decided`,
118
132
  `- Did`, `- Evidence`, `- Outcome: done | dead end | unverified`.
119
133
 
120
- Shape and ordering rules: `references/loop.md`.
121
-
122
134
  ## When the task ends
123
135
 
124
- Report what changed, the gate output, each criterion, the dead ends, the unverified list,
125
- and how the plan ended. Do not summarize the loop away. `references/loop.md` has the
126
- closing shape.
136
+ Report the gate output, each criterion, the dead ends, the unverified list and how the plan
137
+ ended — `references/loop.md` has the closing shape.
127
138
 
128
139
  ## Reference files
129
140
 
@@ -138,5 +149,4 @@ closing shape.
138
149
  | `examples/dispatch.md` | the shape of a safe split |
139
150
  | `examples/theater.md` | the run feels busy but nothing is being proven |
140
151
 
141
- If a reference path is unreadable, continue from this file — the core instructions are
142
- self-sufficient.
152
+ If a reference path is unreadable, continue from this file.