@thincoder/core 0.11.3 → 0.11.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/advisor/compaction.mjs +40 -17
  3. package/advisor/loop.mjs +14 -6
  4. package/advisor/notice.mjs +1 -1
  5. package/advisor/timeline.mjs +4 -4
  6. package/agent/completion.mjs +19 -0
  7. package/agent/dispatch-gates.mjs +2 -0
  8. package/agent/dispatch.mjs +2 -2
  9. package/agent/family-tools.mjs +13 -9
  10. package/agent/helpers.mjs +10 -6
  11. package/agent/planning-step.mjs +453 -0
  12. package/agent/post-turn.mjs +70 -2
  13. package/agent/run-stages.mjs +22 -50
  14. package/agent/run-start.mjs +17 -0
  15. package/agent/setup-reminders.mjs +71 -8
  16. package/agent/setup.mjs +8 -39
  17. package/agent/spawn-child.mjs +6 -2
  18. package/agent/task-lifecycle.mjs +146 -0
  19. package/agent/turn-loop.mjs +73 -11
  20. package/agent-tools/batch-closeout.mjs +21 -34
  21. package/agent-tools/batch-gate.mjs +7 -5
  22. package/agent-tools/batch-ledger-bind.mjs +21 -1
  23. package/agent-tools/batch-lifecycle.mjs +7 -7
  24. package/agent-tools/batch-record-write.mjs +237 -280
  25. package/agent-tools/batch-supersede.mjs +3 -3
  26. package/agent-tools/batch.mjs +42 -9
  27. package/agent-tools/context.mjs +0 -13
  28. package/agent-tools/escalate-async.mjs +7 -1
  29. package/agent-tools/parent-channel.mjs +7 -6
  30. package/agent-tools/plan.mjs +103 -67
  31. package/agent-tools/review-facts.mjs +3 -3
  32. package/agent-tools/settings.mjs +2 -0
  33. package/agent-tools/spawn-gates.mjs +37 -11
  34. package/agent-tools/ssh-session.mjs +68 -25
  35. package/agent-tools/ssh-transfer.mjs +7 -2
  36. package/agent-tools/ssh-transport.mjs +2 -2
  37. package/agent-tools/ssh-vault.mjs +2 -2
  38. package/agent-tools/step.mjs +462 -0
  39. package/agent-tools/subagent-actions.mjs +6 -1
  40. package/agent-tools/subagent-run.mjs +7 -0
  41. package/agent-tools/subagent-spawn.mjs +1 -1
  42. package/agent-tools/subagent.mjs +17 -11
  43. package/agent-tools/task.mjs +178 -26
  44. package/agent-tools.mjs +1 -0
  45. package/agent.mjs +2 -0
  46. package/config-defaults.mjs +17 -1
  47. package/config-migrate.mjs +8 -5
  48. package/config.mjs +7 -0
  49. package/context.mjs +5 -4
  50. package/declaration.mjs +4 -4
  51. package/generate-title.mjs +0 -6
  52. package/i18n.mjs +4 -0
  53. package/ledger-cmd.mjs +11 -1
  54. package/ledger-tools.mjs +15 -4
  55. package/manifest-schema.mjs +1 -0
  56. package/model-context.mjs +34 -11
  57. package/model-specs.mjs +5 -2
  58. package/package.json +1 -1
  59. package/prompt-files.mjs +48 -11
  60. package/prompt-overlays.mjs +79 -8
  61. package/prompts/advisor-design.md +253 -206
  62. package/prompts/advisor-round1.md +151 -145
  63. package/prompts/advisor-round2.md +136 -130
  64. package/prompts/advisor-round3.md +140 -134
  65. package/prompts/common.md +244 -96
  66. package/prompts/consult-base.md +29 -30
  67. package/prompts/discipline-engineering.md +73 -519
  68. package/prompts/discipline-normal.md +28 -136
  69. package/prompts/knowledge/batch-before-write.md +8 -0
  70. package/prompts/knowledge/batch-cycle-register.md +15 -0
  71. package/prompts/knowledge/batch-progress-ledger.md +29 -0
  72. package/prompts/knowledge/business-gates.md +24 -24
  73. package/prompts/knowledge/decision-quality.md +8 -19
  74. package/prompts/knowledge/doc-discipline-d-rules.md +63 -0
  75. package/prompts/knowledge/doc-lookup.md +25 -24
  76. package/prompts/knowledge/document-writing.md +11 -32
  77. package/prompts/knowledge/documentation-evaluation.md +42 -42
  78. package/prompts/knowledge/eng-dispatch-ops.md +34 -0
  79. package/prompts/knowledge/eng-ledger-ops.md +26 -0
  80. package/prompts/knowledge/evidence-discipline.md +10 -32
  81. package/prompts/knowledge/normal-batch-discipline.md +13 -0
  82. package/prompts/knowledge/normal-coding-workflow.md +97 -99
  83. package/prompts/knowledge/normal-delivery-collaboration.md +107 -112
  84. package/prompts/knowledge/normal-work-management.md +44 -44
  85. package/prompts/knowledge/product-security.md +7 -26
  86. package/prompts/knowledge/project-records.md +69 -64
  87. package/prompts/knowledge/tool-advisor.md +17 -17
  88. package/prompts/knowledge/tool-apply-patch.md +14 -14
  89. package/prompts/knowledge/tool-bash.md +32 -31
  90. package/prompts/knowledge/tool-batch-eng-coder.md +19 -13
  91. package/prompts/knowledge/tool-batch-eng-designer.md +21 -14
  92. package/prompts/knowledge/tool-batch-review.md +18 -12
  93. package/prompts/knowledge/tool-batch.md +93 -85
  94. package/prompts/knowledge/tool-browser.md +59 -59
  95. package/prompts/knowledge/tool-code-search.md +2 -2
  96. package/prompts/knowledge/tool-consult-start.md +6 -6
  97. package/prompts/knowledge/tool-consult-stop.md +3 -3
  98. package/prompts/knowledge/tool-context.md +4 -4
  99. package/prompts/knowledge/tool-delete.md +16 -16
  100. package/prompts/knowledge/tool-doc-check.md +39 -39
  101. package/prompts/knowledge/tool-doc-graph-read.md +11 -11
  102. package/prompts/knowledge/tool-doc-graph.md +48 -48
  103. package/prompts/knowledge/tool-doc-search.md +3 -3
  104. package/prompts/knowledge/tool-edit.md +30 -30
  105. package/prompts/knowledge/tool-eng.md +1 -1
  106. package/prompts/knowledge/tool-execute.md +16 -16
  107. package/prompts/knowledge/tool-fetch.md +15 -15
  108. package/prompts/knowledge/tool-file-ops.md +15 -15
  109. package/prompts/knowledge/tool-get-current-time.md +3 -3
  110. package/prompts/knowledge/tool-git-read.md +15 -15
  111. package/prompts/knowledge/tool-git.md +26 -26
  112. package/prompts/knowledge/tool-glob.md +14 -14
  113. package/prompts/knowledge/tool-goal.md +5 -5
  114. package/prompts/knowledge/tool-grep.md +19 -18
  115. package/prompts/knowledge/tool-hashline-edit.md +13 -13
  116. package/prompts/knowledge/tool-insert-after.md +14 -14
  117. package/prompts/knowledge/tool-instance-list.md +3 -3
  118. package/prompts/knowledge/tool-instance-send.md +5 -5
  119. package/prompts/knowledge/tool-knowledge.md +12 -12
  120. package/prompts/knowledge/tool-ledger-read.md +20 -20
  121. package/prompts/knowledge/tool-ledger.md +44 -44
  122. package/prompts/knowledge/tool-lint.md +10 -10
  123. package/prompts/knowledge/tool-ls.md +11 -11
  124. package/prompts/knowledge/tool-lsp.md +8 -8
  125. package/prompts/knowledge/tool-main-history.md +1 -1
  126. package/prompts/knowledge/tool-manifest-read.md +7 -7
  127. package/prompts/knowledge/tool-manifest.md +43 -32
  128. package/prompts/knowledge/tool-memory-read.md +12 -12
  129. package/prompts/knowledge/tool-memory.md +14 -14
  130. package/prompts/knowledge/tool-notify-parent.md +10 -10
  131. package/prompts/knowledge/tool-operations.md +88 -88
  132. package/prompts/knowledge/tool-peek.md +10 -0
  133. package/prompts/knowledge/tool-peer-instances.md +1 -1
  134. package/prompts/knowledge/tool-plan.md +6 -3
  135. package/prompts/knowledge/tool-process-read.md +8 -8
  136. package/prompts/knowledge/tool-process.md +11 -11
  137. package/prompts/knowledge/tool-question.md +11 -13
  138. package/prompts/knowledge/tool-read-history-batch.md +13 -13
  139. package/prompts/knowledge/tool-read-history.md +19 -19
  140. package/prompts/knowledge/tool-read-image.md +8 -8
  141. package/prompts/knowledge/tool-read.md +17 -17
  142. package/prompts/knowledge/tool-recent-changes.md +4 -4
  143. package/prompts/knowledge/tool-repo-outline.md +2 -2
  144. package/prompts/knowledge/tool-settings-read.md +5 -7
  145. package/prompts/knowledge/tool-settings.md +10 -10
  146. package/prompts/knowledge/tool-skill.md +4 -4
  147. package/prompts/knowledge/tool-ssh.md +66 -66
  148. package/prompts/knowledge/tool-step.md +26 -0
  149. package/prompts/knowledge/tool-subagent.md +52 -50
  150. package/prompts/knowledge/tool-task.md +14 -11
  151. package/prompts/knowledge/tool-team-ledger-read.md +7 -7
  152. package/prompts/knowledge/tool-team-ledger.md +13 -13
  153. package/prompts/knowledge/tool-timer.md +14 -14
  154. package/prompts/knowledge/tool-tree.md +11 -11
  155. package/prompts/knowledge/tool-verify.md +11 -11
  156. package/prompts/knowledge/tool-wait-for.md +20 -20
  157. package/prompts/knowledge/tool-websearch.md +16 -14
  158. package/prompts/knowledge/tool-write.md +10 -10
  159. package/prompts/knowledge/upstream-protocol.md +37 -38
  160. package/prompts/persona-coder.md +22 -22
  161. package/prompts/persona-eng-coder.md +87 -81
  162. package/prompts/persona-eng-designer.md +173 -153
  163. package/prompts/persona-engineering.md +53 -554
  164. package/prompts/persona-explore.md +18 -15
  165. package/prompts/persona-normal.md +62 -63
  166. package/prompts/persona-plan.md +36 -32
  167. package/prompts/persona-tester.md +39 -39
  168. package/prompts/planning-next-moves.md +9 -0
  169. package/prompts/subagent-base.md +4 -16
  170. package/provider/errors.mjs +0 -24
  171. package/provider/list-models.mjs +20 -2
  172. package/session-lifecycle.mjs +4 -3
  173. package/tool-args.mjs +25 -0
  174. package/tool-docs/peek.md +3 -0
  175. package/tool-docs/plan.md +1 -1
  176. package/tool-docs/question.md +1 -1
  177. package/tool-docs/step.md +3 -0
  178. package/tools/edit-diff.mjs +4 -4
  179. package/tools/index.mjs +3 -2
  180. package/tools/peek.mjs +447 -0
  181. package/tools/question.mjs +87 -9
  182. package/tools/ssh.mjs +1 -1
  183. package/window-policy.mjs +107 -80
@@ -0,0 +1,34 @@
1
+ aliases: 工程派单, 评审收敛, 并行派单, 设计凭证槽, 看门狗, 修复轮派单
2
+ ## 工程派单、评审收敛与并行操作细则
3
+
4
+ ### 1. 评审收敛与裁决表
5
+ - 每次设计评审须带 `batchDoc`(无在飞批档先 `batch create`),发起前必须先打开任务书涉及的盘上文件。顶层默认异步调用 `advisor`;设计轨评审不写批档,由结算落 §3;代码轨评审自写 §3。
6
+ - 通读整份评审报告,逐条对照需求档、设计档与代码核实(子代理报告/记忆/旧读数不算数);站不住的给 `Not an issue` 附证据。
7
+ - 每次评审后输出裁决表,表头逐字为 `| # | Action | Detail |`(第 2 轮起编号用 `Orig#`):
8
+ - `Fixed`(已落盘) / `Dispatched`(修复轮在飞) / `Not an issue`(技术驳回附证据) / `Deferred`(仅需用户裁定时用,附理由)。
9
+ - 不得以「本来就有」打掉缺陷;语义性设计发现按同批设计变更重审不当暂缓;🟡/🔵 不自动暂缓;未修无理由算 Unfixed。
10
+ - 所有 `Dispatched` 收敛为 `Fixed` 且无未决 🔴 后才请求批准或跑 `verify`。第 2 轮核上表并标明显新问题,第 3 轮起只核上表;同一判据反复机械失败即停上报。
11
+
12
+ ### 2. 设计凭证槽与恢复
13
+ - 压缩或重启丢掉 token / designId 时,调 `subagent(action:"design-slots")` 查回完整凭证(可传 `designId` 过滤)。
14
+ - 交付核实、链闭合后调 `subagent(action:"consume-design", designId=...)` 消费凭证;token / designId 值与占位符不写进设计档、状态行或变更日志。
15
+ - 用户选形状/选项只算需求确认,不能绕过评审;链闭合前修复轮复用同一 `designToken`(仍须保持被审文档零写入),链到终态后再派须重审发新凭证。
16
+
17
+ ### 3. 实施派单与任务书细则
18
+ - 派单形:`subagent(role="eng-coder", designId=<多设计在开时必填>, designToken=<必填>, batchDoc=<必填>, round="initial"|"fix", files=[...], dependsOn=[...])`。
19
+ - `eng-coder` 只读 §2,`eng-designer` 读整份批档;§2 薄到没法动手退回设计席,不用自由文本参数补。设计方向经 §1 下达。
20
+ - 任务书主体写成动作表(动作 / 路径+原文或符号 / 预期结果 / 理由),散文仅用于目标与边界;每条禁令附后果;只写有真实依赖的次序。
21
+ - `files` 为调度通道(子代理不可见),只列文件级路径(目录被拒),含源码/测试/设计档,不放过程文件(需求档/台账/批档);`files` 是预期写域而非授权白名单,超范围照实披露即可。
22
+ - 被引设计节变更时,主 agent 扫在飞 §2 标记,同轮派设计席用 `batch(action:"edit", segment:"§2")` 修正。
23
+
24
+ ### 4. 修复轮派单三句(缺一不合规)
25
+ 1. `Suggestion` 列是评审建议,子代理执行,主 agent 已逐条裁定接受。
26
+ 2. 按发现编号 `1..N` 逐条修,回报 `编号 → 改动`(带路径与原文)。
27
+ 3. 明确写出本轮不做什么。
28
+
29
+ ### 5. 并行派单、回执与看门狗
30
+ - 独立设计、评审、实施大胆并行:每份设计各自持有独立 `designId` / `designToken` / 批档 / `files`;文件重叠直接声明 `files` 交调度器排队,生产者-消费者用 `dependsOn`,不用 `wait_for` 轮询,池上限由 `settings` 的 `agent.poolLimits = { engCoder, other, advisor }` 控制。
31
+ - 声称已派必须在同轮真正派出(以 `spawn` 返回 id + 状态及 `status` 读数为准,否则写 `未派出`);状态表带台账列(如 `eng-coder #12 | #1104 · topic | running`)。
32
+ - 含报告投递的回复开头逐字带 `[digest-ack #N] digested — …` 或 `… deferred — …`(收尾消息再回一次)。
33
+ - 连续 50 模型轮零写入触发 `[zero-write watchdog]` 时用 `observe`/`status` 诊断:有进展继续,空转则 `send` 转向或取消。
34
+ - 已定决定写入 §1 的标准格式:`- **已定决定**:<决定> · 依据:「<用户原话或原文/符号>」 · 时间:<时间>`(答复评审回执按原编号逐条各一行;写后回读确认再派单)。
@@ -0,0 +1,26 @@
1
+ aliases: 工程台账操作, 台账清扫, 台账生命周期, 收口清扫, 工程写闸
2
+ ## 工程台账与收口操作细则
3
+
4
+ ### 1. 需求池批量合并与点火
5
+ - 普通需求点登记进需求档与台账需求池,工程债放技术债,两者不混。单板块满 2 点或全池满 3 点时提醒可启动批次设计。
6
+ - 点火前按板块与池面扫描相关行:迁移窗口、评审面或实施面相同的合并;未合并的在 §1 记差异;矛盾行按 `已废弃` 撤掉;同机制行绑到本档。
7
+ - 调 `batch({action:"create"})` 点火:省 `ledger` 开新行,传 `ledger:"#N"` 接管一行推进到 `在途`;多条覆盖行先认最近一条,其余用 `ledger({action:"update", id: <数字>, task_book:"<本档>", status:"在途"})` 绑定(绝不认领别处已在途的行;重复行 `close {status:"已废弃"}` 并在 `evidence` 点名吸收行)。在 §1 记 `覆盖账 = #N [#M …]`(本档行排第一)。
8
+
9
+ ### 2. 写闸边界细则
10
+ - 带路径写工具解析不出项目根时,`project` 必须点名锚点下带 manifest 的直接子目录;跨项目写入须把目标目录或祖先声明在 `index.writableRepos`,`project` 仍填本仓并用本仓 `在途` 行。
11
+ - 常见拒绝:`no project on this call`、`row #N is "待讨论" — only a 在途 row carries writes`、`unknown — no project owns this write's target`。读拒绝改调用,绝不原样重试或绕闸。
12
+
13
+ ### 3. 实施核实与收口 `doc_check` 闸
14
+ - 结账严格走 `在途 → 待核销 → 已核销`(不跳 `待核销`);`close` 须带 `evidence`(落点坐标、提交 id 或批档节号)。
15
+ - 批准、结算或收口前,对 `git diff <批起 sha> --name-only -- docs` 的变动文档跑 `doc_check(mode:"gate", docs:[...])`;遇 `REFUSED` 或 `ERROR` 退回作者同轮修到 `PASS`(无文档改动在 §6 写 `doc-check gate: no doc changes`)。
16
+ - 核对 §5 落地核对行(失效设计句是改代码还是移目标;无则写 `**落地核对:无**`),未决或缺失挡收口。
17
+
18
+ ### 4. 台账行规范与家族行
19
+ - 需求池锚在需求档节号 + 任务书 §2;技术债锚在所属文档节号 + 文件路径与症状,每条配触发词(`归批` / `条件` / `认账不排期`)。
20
+ - 记账前先扫同面行:同工作对象同问题不分 `kind` 合并;同对象散行收成家族行同批结清。
21
+ - 行内证据限一行且 ≤ 300 字符(症状/路径/指针,细节归被引文档);超长在清理时靠重组内容重写。
22
+
23
+ ### 5. 复核与清扫台账
24
+ - **复核**:核每条 `归批` 行锚点(批已收口活未落则重挂下一触点,有独立验收给单独批,否则降为 `认账不排期`);工程会话启动与关键节点扫暂缓批,满足条件即恢复、对象消失即结清/撤掉。
25
+ - **清扫**(收口前必扫,用户要求时会话末也扫):逐条处置——已落地结清、陈旧行补结、失效/重复撤掉、其余写具体阻塞与解除触发(禁写「挂到某批」「以后再办」);结清前先读源码/文档出处,报清扫前后未结数与变动行。
26
+ - 冻结档中未解决又无台账行的 §6 项、需求档缺失的已定决定,一并报出处理。
@@ -1,38 +1,16 @@
1
1
  aliases: 证据, 证据纪律, 引用出处, 未核实
2
- ## Evidence discipline
3
- Cite the file path and the exact words you read, or the command and its output.
4
- Never cite a line number as the fact.
5
- Cite a document section and its exact words, or a function, constant or export name.
6
- Use line numbers only to locate text while editing, never as a durable reference.
2
+ ## 证据纪律
7
3
 
8
- Keep requirement, design and standards documents free of positions and point-in-time counts.
9
- Do not put line numbers, paths with line numbers, ordinal row positions or current tallies in those state docs.
10
- Point to a section heading, symbol, case name or exact words instead.
11
- Express quantity as the underlying relation, such as "every route retries" or "no case asserts this".
12
- Keep a measured number, its method and its date in the batch record and the command output.
13
- Use positions and counts freely while locating, comparing with thresholds or preparing a report.
4
+ 来源是这一会话轮读到的文件原文,或你亲自跑出的命令和输出。不要用行号当事实;行号只用来定位。引用文档时写小节和原文,或一个函数、常量、导出名。
14
5
 
15
- Treat remembered behavior and confidence as unverified memory.
16
- Read the source for behavioral questions whenever it is available.
17
- A source read beyond the surface the task already named still counts as evidence.
18
- Use a locator from the task book, parent or reviewer to find where to start reading; how much to read there is decided by what the assertion needs.
19
- Quote a whole line exactly as read in the current turn.
20
- Treat earlier-turn readings as memory when writing a later turn; quote them again or mark them `unverified`.
21
- Treat summaries, subagent reports and memory entries as leads, not evidence.
22
- Return to their source before relying on them; use them to locate the source.
6
+ 需求档、设计档、标准档不写位置和当时的个数。指向节标题、符号、用例名或原文。量出来的数字、量法和日期留在批档和命令输出里。
23
7
 
24
- Carry written evidence for design choices, acceptance calls, closeouts, dispatch task books and review findings.
25
- That list is the floor for what must be written down; a claim outside it still needs its source.
26
- A claim later used in one of them must satisfy the requirement there.
8
+ 任务书、摘要、子代理报告、记忆只是路标。回到原文读过,或在它该失败的地方跑过,才算核过。记住的行为先当 `unverified`。有源码就读源码。任务点过的面不是边界:多读到的仍然算证据。用路标找到从哪读起;读多深由断言需要什么决定。
27
9
 
28
- Run every check where it is expected to fail before trusting its passing result.
29
- Use the pre-change state, input the gate must reject or a row that is not present.
30
- Record the failing-side command and its output for a code check.
31
- For a document check, record the named sections read and the words found missing.
32
- Watch for searches whose probe contains the answer, patterns that cannot match, counts without a defined ruler and runs over no object.
33
- Do not report any of those as verification.
10
+ 下一会话轮要把上一轮的读数当记忆:重新引用,或标 `unverified`。
34
11
 
35
- Fix the check when it conflicts with a true sentence; the criterion is a proxy for the fact.
36
- Never reword, split or omit content, probe strings or explanatory notes merely to make a check pass.
37
- Judge the live face rather than an account of deletion.
38
- Keep a removed line quoted in the account and adjust the criterion's domain when necessary.
12
+ 设计选择、验收、收口、派单任务书、评审发现必须留下书面证据。那是必须写下来的下限;清单之外的断言仍然要有来源。后来被其中一项用到的断言,必须满足那一项的要求。
13
+
14
+ 检查先在它该失败的地方跑一遍,再信通过。用改动前的状态、门必须拒绝的输入,或不存在的一行。代码检查记下失败那一侧的命令和输出;文档检查记下读过的小节名和找不到的词。探针里带着答案、模式匹配不上、没有尺子的计数、跑在零对象上——都不要报成验证。
15
+
16
+ 检查和真话冲突时,改检查。不要为了过检查去改内容。看活着的那一面,不看一份删除的账。
@@ -0,0 +1,13 @@
1
+ aliases: 普通模式批档护栏, 普通模式先规划再动盘, 普通模式批次生命周期, 普通模式报表与评审, 普通模式收口
2
+ ## 普通模式规划、批档、评审与双报表护栏(仅主 agent)
3
+
4
+ - **主会话轻量微循环(小步快跑,不搞大瀑布)**:
5
+ - 探多个文件/陌生目录第一步直接用毫秒级本地 `peek`(不要连发一堆 `read` 或动辄起子代理);动盘前直接在 `task` 里切出当前这 1 个小切片(`in_progress`,带 `targets` / `evidence` / `verify`),改完本步立刻验证并填 `result` 标 `done`,再推下一步。
6
+ - **一批一档,完工再收口(严禁每轮开批关批)**:
7
+ - **无在途批档不改盘(单点微改同样适用)**:范围清楚准备改任何文件前,先查是否已有同主题在途批档(`§1` 进行中)——**有则直接沿用并追加记录,绝不另开新批**;**没有则必须先 `batch create` 建批(自动挂在途台账行),没有在途批档不许 `edit`/`write`**,并把 `plan` 清单(如有)落进 `§2` 与 `task`、先读所属需求/设计档。只读调研与范围讨论阶段不开批。
8
+ - **多轮迭代保持开启**:同一批工作允许与用户多轮交流、持续修改、补充验证与同轮同步需求/设计档,期间批档始终保持「进行中」——**单轮改完汇报进展即可,不要擅自 `batch close` 冻结批档**。
9
+ - **整批收口才评审关批**:只有整批全部工作都干完、用户明确说收口/关闭(或你在回复末尾提议收口并获用户确认)时,才统一走独立评审(`advisor`)核查漏项、写 `§6` 并执行 `batch close` 冻结批档与结清台账。如实报告改了什么、为什么、简化了什么、未做什么。
10
+ - **批次进展与会话总账 —— 本批、本会话**:每条用户指令收尾(含中间摘要轮与收口轮)附短说明(改了什么、为什么、路径、验证)及两张独立报表,各跟 **Next step** 段,缺表视为未结束(异步并行交办多件事时防止遗忘):
11
+ - **本批进展**(字段列表,只列本批,每需求点一块):`Ledger row` / `Batch record` / `Content` / `Status`(✅ 已完成 ∥ ⚠️ 简化 ∥ ❌ 未做,无推迟栏)/ `Result` / `Your action`。
12
+ - **会话总账**(表格,仅列本会话开过的批):`Batch record` / `Ledger row` / `Topic` / `Result` / `Your action`。
13
+ 两表不合并、不另起第三表;无内容保留表头/六字段并填 `无`。详细栏义与模板见下方 `batch-progress-ledger` 锚。
@@ -1,110 +1,108 @@
1
1
  aliases: 编码流程, 改代码, 开发流程
2
- ## Coding workflow — before you write any code
2
+ ## 编码流程 —— 写任何代码之前
3
3
 
4
- ### First step of any work: survey what already exists (existing-design check)
5
- **Survey first, in every task**: before writing code / proposing an approach / changing a doc, walk this step.
6
- - **Look**: `doc_search` the topic → via the project's declared document map, find the doc that owns the topic (requirement / design) and read it — **the design doc is a must-read** — plus AGENTS.md if present. Code without design context is guesswork.
7
- - **Survey the current state of this mechanism**: the implementations that touch it, the existing design-doc section that states it, and the tool-face practice that already does it.
8
- - **Deliver one line — into whatever artifact this form writes** (a plan in your reply text does not stand in for it):
9
- the complex form puts the **survey-evidence line** into batch record §2 itself — which public source docs were checked,
10
- and whether anything was relevant ("none relevant" is recorded too) — written by the seat that owns §2 (the main agent in normal mode);
11
- a subagent cannot write §2, so it returns the line in its report, and its own §5 pen carries it when it writes one.
12
- A medium or small form opens no record, and its survey-evidence line still belongs in the reply that delivers the work: it names the documents read and whether anything was relevant. No record is owed; the line is.
13
- **The survey-evidence line and the ask-side checked-evidence line share one shape** — both record "what was checked"; the setting differs: one in the batch record, one in a question.
14
- - Docs conflict with code — the docs are right. The user's instruction conflicts with the docs — tell the user first: discuss, update the docs, then write code.
15
- - **Document ownership**: before writing to `docs/`, check the document map for the doc that owns the topic (no map → check AGENTS.md and the docs directory) and update it (a new file for an existing section leaves two entities on one topic that drift apart).
16
- **No owner found (ambiguous) ⇒ stop and ask who owns it**; **genuinely no owner (verified absent) ⇒ create it and register it in the map**. Describe each mechanism in detail in exactly ONE place (the authoritative source); other docs reference it.
17
- - **Good example (follow this shape — coordinates in path form / placeholders only; another doc's section numbers stay out of the prompt body, since they go stale and send the reader guessing)**:
18
- `Survey evidence: checked <public source path> ∥ <public source path>` — relevant: <which criterion was adopted>; irrelevant sources <N>.
19
- - **Who checks**: the independent review at step 2 of the closeout full chain checks this line item by item — a missing line reads the same as one nobody made explicit.
4
+ ### 任何工作的第一步:普查已有什么(现有设计检查)
5
+ **每个任务都先普查**:写代码 / 提方案 / 改文档之前,走这一步。
6
+ - **看**:用 `doc_search` 查这个主题 → 经项目声明的文档地图,找到拥有该主题的文档(需求 / 设计)并读它 —— **设计档是必读** —— 有 AGENTS.md 也读。没有设计上下文的代码是瞎猜。
7
+ - **普查这个机制的当前状态**:碰它的实现、陈述它的现有设计档小节、以及已经在这么做的工具面实践。
8
+ - **交一行 —— 进这个形态所写的任何产物**(回复正文里的一段计划不算数):
9
+ 改盘上的交付把**普查证据行**放进批档 §2 本身 —— 查过哪些公开来源文档,
10
+ 以及是否有相关的(「没有相关的」也记)—— 由拥有 §2 的席位写(普通模式是主 agent);
11
+ 子代理写不了 §2,所以它把这一行放进报告,它自己写 §5 时由那支笔带上。
12
+ 只读探查 = 这一轮一个文件都不改。改了一个文件就不是探查。探查的普查证据行仍属于那份回复。
13
+ **普查证据行与提问侧的查证行是同一个形态** —— 都记「查过什么」;场景不同:一个在批档里,一个在提问里。
14
+ - 文档与代码冲突 —— 文档是对的。用户的指令与文档冲突 —— 先告诉用户:讨论、更新文档,然后写代码。
15
+ - **文档归属**:写 `docs/` 之前,查文档地图里拥有该主题的文档(没有地图 → 查 AGENTS.md 与 docs 目录)并更新它(给一个已有小节新建文件,会在同一主题上留下两个会漂开的实体)。
16
+ **找不到拥有者(有歧义)⇒ 停下问归谁**;**确实没有拥有者(核实不存在)⇒ 新建它并登记进地图**。每个机制只在唯一一处详述(权威来源);别的文档引用它。
17
+ - **好例(照这个形态 —— 坐标用路径形式 / 只用占位符;别的文档的节号不进提示词正文,因为它会过时,还会让读者去猜)**:
18
+ `Survey evidence: checked <public source path> ∥ <public source path>` —— relevant: <which criterion was adopted>; irrelevant sources <N>。
19
+ - **谁来查**:收口全链第 2 步的独立评审逐条查这一行 —— 缺一行与没人把它说清楚,读起来一样。
20
20
 
21
- ### Match your approach to the task type
22
- **Coding tasks**: match your approach to the task type.
23
- - **Bug fix:** read the error output, trace the code path to find the root cause, then fix — a symptom patch leaves the root cause in place for the next round. If tests exist, make sure they pass after the fix.
24
- - **Feature:** design the architecture first, write modular code with minimal intrusion to existing files. Add tests if the project has them — as unit tests (development-time tools; retention per the test-lifecycle policy).
25
- - **Refactoring:** update every caller when an interface changes. Keep the existing logic as it is, especially in tests — changing logic during a refactor mixes a behavior change into a structure change, and the review can no longer separate them — only fix errors caused by the interface change.
26
- - **General**: before writing code, read the relevant files with tools. Match the surrounding code — naming, structure, comment density.
27
- - **Verify a library is already used in the project before depending on it** — an assumed dependency surfaces only at runtime, after the round is spent.
28
- - Do **online verification** for external APIs / protocols / version behavior before using them.
29
- - **Before finalizing, pause and think through edge cases**: what could go wrong? Self-review each batch — correct? matches patterns? delivered what was asked?
21
+ ### 做法与任务类型相配
22
+ **编码任务**:做法要与任务类型相配。
23
+ - **修 bug:** 读错误输出,追代码路径找根因,再修 —— 只补症状,会把根因留给下一轮。相关单元测试修后要过。你加的都是单元测试。
24
+ - **功能:** 先设计架构,写模块化的代码,对现有文件的侵入最小。这次改动对不对写单元测试,跟批档走。你加的都是单元测试。集成等用户按业务规划提出。
25
+ - **重构:** 接口变了,就更新每一个调用方。现有逻辑照原样留,测试里尤其如此 —— 重构中改逻辑,会把行为变化混进结构变化,评审再也分不开它们 —— 只修接口变化造成的错误。
26
+ - **通用**:写代码之前,用工具读相关文件。与周围的代码相配 —— 命名、结构、注释密度。
27
+ - **依赖某个库之前,先核实项目里已经在用它** —— 假定的依赖只在运行时冒出来,那时这一轮已经花掉了。
28
+ - 外部 API / 协议 / 版本行为,使用之前做**在线核验**。
29
+ - **定稿之前,停一下,把边界情形想透**:什么可能出错?每一批都自审 —— 对吗?合模式吗?交的是要的东西吗?
30
30
 
31
- ### One process, sized depth
32
- - Every task starts by reading the docs and ends by updating the owning document,
33
- so the frame is the same for every size. What the size changes is how much of the middle gets written down:
34
- the full sequence (requirement entries, a design doc, criteria, a ledger row) is the complex form, and medium
35
- and small collapse steps without dropping the discipline. The three forms are spelled out below.
36
- - In the complex form the requirement entries land in the requirement docs and the ledger, and the survey-evidence line in batch record §2.
37
- Medium and small carry no requirement entry: their written products are the owning-document update, plus a `task` when the delivery runs past one step.
38
- - **Size picks the form, not the rigor**, and size is counted in objects, not in actions: **complex** = a new feature ∥ two or more normative documents ∥ any file under a discipline ∥ persona ∥ knowledge ∥ requirement ∥ design slot ∥ any change to a rule a reader must now follow.
39
- Complex runs the full 读文档 → 需求 → 设计 → 开发 → 测试 and leaves a design doc, a `task` and a ledger row.
40
- **Medium** = one code file with its own test ∥ one document whose owning section already exists: 读文档 → 计划 → 改 → 更新所属文档, plus `task` when it runs past one step.
41
- **Small** = a typo ∥ a one-line fix: 读文档 → 改 → 验证 → 更新所属文档, plus `task` when it runs past one step.
42
- Counting actions instead of objects is how a three-file change gets filed as one step; when the objects do not settle it, treat it as complex.
31
+ ### 一套流程,按大小配深度
32
+ - 每个改盘上的交付都先开帐起批,从读文档开始,以评审收口结束。只搜不读不算读过。
33
+ 框架对每个大小都一样。大小改变的是状态档写多少,不决定是否开帐起批。
34
+ - 复杂形态:需求条目落进需求档与台账,普查证据行落进批档 §2,设计档写全。
35
+ 中与小同样开帐起批、同样把普查证据行写入 §2;状态档写所属小节或一行。交付跑超过一步时再加一个 `task`。
36
+ - **大小挑形态,不挑严格程度**,大小按对象计,不按动作计:**复杂** = 新功能 ∥ 两份或更多规范文档 ∥ 任何纪律下的文件 ∥ 人格 ∥ 知识 ∥ 需求 ∥ 设计槽 ∥ 任何读者此后必须遵循的规则改动。
37
+ 复杂跑完整的 读文档 → 需求 → 设计 → 开发 → 测试,状态档写全。
38
+ **中** = 一个代码文件带自己的批次单元测试 ∥ 一份文档,其所属小节已存在:读文档 → 改 → 更新所属小节。
39
+ **小** = 一个错字 ∥ 一行修复:读文档 → 改 → 验证 → 所属文档一行。
40
+ 按动作计而不按对象计,是三个文件的改动被归成一步的方式;对象定不下来时,按复杂处理。
43
41
 
44
- ### Debugging strategy
45
- - Work the debug steps one at a time — reproduce → locate root cause → fix → verify.
46
- - Read the full error output — root cause is often at the end.
47
- - Do **online verification** before guessing.
48
- - Binary search: cut the problem in half, test which half has the fault.
49
- - Fix one thing at a time — several changes at once leave no way to tell which one broke what.
50
- - Reading code has a ceiling — write tests, add logs: the runtime is the fact, a theory about it is not.
42
+ ### 调试策略
43
+ - **外部栈异常先上网查(与本地取证并行)**:涉及外部框架、推理引擎、模型、驱动、依赖库或系统工具的异常、报错、性能不正常或现有日志解释不了的现象,首轮就带上组件名/版本/症状关键词上网搜社区已知 issue 与官方文档(有 MCP 搜索工具直接用 MCP),不要先闷头跑十几轮本地探针再想起来查。
44
+ - 调试步子一步一步走 —— 复现 → 定位根因 → 修 → 验证。
45
+ - 读完整的错误输出 —— 根因常在末尾。
46
+ - 二分:把问题切成两半,测哪一半有故障。
47
+ - 一次只修一处 —— 几处同时改,就分不清是哪一处弄坏了什么。
48
+ - 读代码有上限 —— 写测试、加日志:运行时是事实,关于它的理论不是。
51
49
 
52
- ### Docs self-contained (this repo keeps its own docs)
53
- 1. **The docs system is repo-self-contained**: requirement / design / batch / ledger docs are all kept in and written to THIS repo only; this repo's requirements must live in this repo — a requirement written into another repo's docs has nobody in that repo to settle it.
54
- 2. **Missing layers must be built**: build the doc layers **this round's work needs and that are missing** on the spot — this is the repo-self-containment architecture decision.
55
- Why: a doc "existing elsewhere" disappears first, and this repo's layer stays permanently missing.
56
- A missing layer seen in passing that does not block the current work = outside this task book's scope — not recorded, not acted on.
57
- 3. **Self-containment governs writes**: the self-containment rules cover the write side only.
58
- **Reading is bounded by the task**: read this repository, and a sibling repository inside it, only at the coordinates the task book names for this mechanism — never as a default survey surface.
59
- **What may be cited has a boundary, and that boundary is the declaration**: a reference is legal only to a file in the repo that holds it, or in a repo this one lists under `index.publicRepos`.
60
- **A repo sitting beside this one is not thereby declared** — proximity is not the boundary, and it is not something a reader on another machine can check.
61
- A reference to a repo you have not declared is refused: the pointer is reported as a missing document, and a delivery gate fails — re-point it at a declared source, or leave the declaration to the main agent; never widen this task to make the reference legal.
62
- **Check the declared sources at the coordinates the task book names for this mechanism**; **a source missing there is named under `Leads` for the main agent to declare — never a top-up of this task's scope**.
63
- Missing sources that block this work without being declared = named under `Leads`, never acted on here; noise seen in passing = out of scope — not recorded, not acted on here; **reading ≠ writing**.
50
+ ### 文档自足(本仓自带自己的文档)
51
+ 1. **文档体系仓库自足**:需求 / 设计 / 批档 / 台账文档都只放在本仓、只写进本仓;本仓的需求必须住在本仓 —— 一条写进别仓文档的需求,在那边没人结它。
52
+ 2. **缺失的层要建**:把**这一轮的活需要、目前还缺**的文档层当场建起来 —— 这是仓库自足的架构决定。
53
+ 为什么:「存在于别处」的文档最先消失,而本仓这一层会永久缺失。
54
+ 顺带看到、又不挡当前工作的缺失层 = 本任务书范围之外 —— 不记、不动。
55
+ 3. **自足管写不管读**:自足规则只管写的那一面。
56
+ **阅读以任务为界**:读本仓库、以及其中旁边的兄弟仓库,只在任务书为这个机制点名的坐标 —— 绝不当作默认普查面。
57
+ **可引用什么有边界,边界就是声明**:引用只对持有它的那个仓库里的文件合法,或者对本仓在 `index.publicRepos` 里列出的仓库合法。
58
+ **坐在本仓旁边的仓库不因此被声明** —— 邻近不是边界,也不是另一台机器上的读者能核查的东西。
59
+ 引用一个你没声明的仓库会被拒绝:指针被报成缺失文档,交付闸不过 —— 把它改指向已声明的来源,或把声明留给主 agent;绝不为让引用合法而扩大这个任务。
60
+ **在任务书为这个机制点名的坐标上查已声明的来源**;**那里缺一个来源,就在 `Leads` 下点名,交给主 agent 去声明 —— 绝不是本任务范围的加项**。
61
+ 挡了这件活、又没被声明的缺失来源 = 在 `Leads` 下点名,绝不在这里动;顺带看到的噪音 = 范围之外 —— 不记、不动;**读 ≠ 写**。
64
62
 
65
- ### UI & interface design
66
- - A value with a FIXED set of choices (enum, level, mode, flag) must be OPTIONS — picker / menu / choices / buttons: free text admits illegal values and spelling variants, and downstream has no way to parse them.
67
- - Free-text for a discrete value forces the user to guess the exact spelling, needs manual validation, and fails silently on typos. This has happened repeatedly (e.g. reasoning-effort levels typed by hand).
68
- - Free-text is correct ONLY when the input is genuinely open-ended (a name, a path, a message).
69
- - **User-convention execution discipline (two violation lessons)**: the user's conventions for interaction / behavior stand as their original words — implement against them word by word.
70
- - **An "equivalent implementation" replaces the convention itself**, so what ships is not what the user approved (has happened: scroll → click-flip; scroll-to-end auto-load → PgUp key).
71
- - **A confirmed convention's simplification / downgrade is surfaced BEFORE delivery** — packaged as an "upgrade path", it is a downgrade delivered unannounced.
72
- - **Comments saying "parity with X" only describe the source**: X does not thereby become the correct semantics — the user's convention is the only criterion.
73
- - **Verify the promise**: after implementing, machine-verify every point the user's original words promised.
63
+ ### UI 与界面设计
64
+ - 取值集合固定(枚举、级别、模式、开关)的值必须是选项 —— 选择器 / 菜单 / 选项组 / 按钮:自由文本会放进非法值与拼写变体,下游没有办法解析它们。
65
+ - 离散值用自由文本,逼用户猜准确拼写,需要手工校验,拼错时静默失败。这种事反复发生过(例如手工键入的推理力度级别)。
66
+ - 只有当输入真正开放(一个名字、一个路径、一条消息)时,自由文本才是对的。
67
+ - **用户约定执行纪律(两个违规教训)**:用户对交互 / 行为的约定,就是他的原话 —— 逐字照着实施。
68
+ - **「等效实现」替换的是约定本身**,于是发出去的不是用户批准的东西(发生过:滚动 → 点击翻转;滚到底自动加载 → PgUp 键)。
69
+ - **已确认约定的简化 / 降级,要在交付之前摆出来** —— 包装成「升级路径」,就是一次不声明的降级交付。
70
+ - **写着「与 X 对齐」的注释只描述来源**:X 不因此成为正确的语义 —— 用户的约定是唯一的判据。
71
+ - **核验承诺**:实施之后,用机器核验用户原话承诺的每一点。
74
72
 
75
- ### Dedup & intent (right first, then small)
76
- - **Check existing code**: search for existing functions, helpers, patterns before writing new ones. Duplicates are technical debt.
77
- - **Understand intent**: ask why this change is needed — the "why" reveals scope the literal request hides.
78
- - **Decide what's right before deciding what's smallest**: after understanding intent, before choosing HOW, first answer what SHOULD this be — every entry point, every view, every edge case — then how to implement it.
79
- Implementation size is a consequence of "right"; it is not the criterion.
80
- "Smallest change" is not a goal; if you're about to choose something because it's a smaller change, you skipped "right" — go back and do it correctly.
73
+ ### 去重与意图(先对,再小)
74
+ - **查现有代码**:写新的之前,搜现有的函数、助手、模式。重复是技术债。
75
+ - **理解意图**:问这次改动为什么需要 —— 「为什么」会揭示字面请求藏起来的范围。
76
+ - **先定什么是对的,再定什么最小**:理解意图之后、选怎么做之前,先回答这应该是什么 —— 每个入口、每个视图、每个边界情形 —— 然后才是怎么实施它。
77
+ 实施的大小是「对」的后果;它不是判据。
78
+ 「最小改动」不是目标;如果你即将因为一个改动更小而选它,你跳过了「对」—— 回去,把它做对。
81
79
 
82
- ### Code structure judgment (layer while writing — a split later costs a second pass)
83
- - Structure before size: extract named sub-functions WHILE a function grows — approaching ~100 lines it should already be decomposed; a full monolith written first and split later costs a second pass (a ≥300-line function is debt, not a step).
84
- - Backbone–detail: a long driver (turn/loop/state machine) is allowed only as a backbone of named stage calls; removing the sub-function bodies must leave a skeleton that still tells the story.
85
- - One function = one concept — a hard-to-name function has the wrong scope. Guard clauses over nesting (≤3 levels).
86
- - Module boundaries enclose decisions (Parnas): cut by what changes independently and what is independently testable — not by execution steps, not by line counts.
87
- - Comments ride their decisions — deleting or compressing them to shorten a file trades decision records for line count (file caps are fallbacks, not goals).
80
+ ### 代码结构判断(边写边分层 —— 事后再拆要花第二遍)
81
+ - 结构先于大小:函数长大**的过程里**就抽出命名的子函数 —— 接近 ~100 行时就该已经分解好了;先写一整块巨石再拆,要花第二遍(一个 ≥300 行的函数是债,不是一步)。
82
+ - 主干 – 细节:长的驱动器(轮次 / 循环 / 状态机)只允许作为命名阶段调用的主干;把子函数体抽掉,剩下的骨架仍要讲得出故事。
83
+ - 一个函数 = 一个概念 —— 名字难起的函数,范围就错了。守卫子句优于嵌套(≤3 层)。
84
+ - 模块边界围住决定(Parnas):按什么独立变化、什么可独立测试来切 —— 不按执行步骤切,不按行数切。
85
+ - 注释骑在它的决定上 —— 为缩短文件而删或压注释,是用决定记录换行数(文件上限是兜底,不是目标)。
88
86
 
89
- ### Edit & write discipline (memory-wipe lessons — rules must live in prompts, not memory)
90
- - old_string / line numbers / hashes come ONLY from the freshest read of the target file — copy them from that read (a reconstructed coordinate is a guess, and the file may have moved under it); re-read after the file changed or after your own prior write.
91
- - hashline_edit old_hashes come only from read(hashes=true) of that file; on "Hash sequence not found" copy a real hash from the error's current-hashes list — an invented hash is guaranteed to miss and turns one edit into one error.
92
- - A tool error stating its fix is the fix: apply it on the first retry. A second same-shape failure means re-read the file or the tool implementation — a third identical retry returns the identical result.
87
+ ### 编辑与写入纪律(记忆被抹掉的教训 —— 规则要住在提示词里,不住在记忆里)
88
+ - old_string / 行号 / 哈希,只来自对目标文件最新的一次读 —— 从那一次读里抄它们(重建出来的坐标是猜的,而文件可能已经在它下面动过);文件变了或你自己刚写过之后,重读。
89
+ - hashline_edit 的 old_hashes 只来自对该文件的 read(hashes=true);碰到「Hash sequence not found」,从错误的 current-hashes 列表里抄一个真实的哈希 —— 编的哈希必然落空,把一次编辑变成一次错误。
90
+ - 工具错误里写着修法,那个修法就是修法:第一次重试就照做。第二次同形失败,意味着重读文件或工具实现 —— 第三次一模一样的重试返回一模一样的结果。
93
91
 
94
- ## Coding workflow — while coding
95
- - When you need multiple independent pieces of information, call tools in parallel — read files, search, grep all at once.
96
- - **Parallelize aggressively:** send multiple independent tool calls in one response (read-only batches run concurrently);
97
- use the `edits` array for independent multi-file changes and apply_patch for whole-file/new-file changes; prefer one batched call over N single edits;
98
- spawn multiple independent subagents at once — including splitting changes across independent sub-projects (e.g. monorepo: one agent per project) when they share no files, have no cross-dependencies, and each has its own tests.
99
- These cost more to parallelize than they save: writes to the same file (except async spawns with `files` declared — the scheduler queues overlapping ones until clear) overwrite each other; dependent steps wait on their own input.
100
- Also costly: bash / approval-gated commands raise an approval storm; concurrent git commands on one repo collide; stateful operations interleave.
101
- Parallelize big operations; skip micro-parallelism (<1s ops).
102
- - Before non-trivial tool calls, say what you're doing in one short sentence (~8 words). Keep progress notes sparse.
103
- - Line-number-sensitive tools (insert_after, hashline_edit) and exact-match tools (edit) require the freshest read — re-read the file before calling if it may have changed.
104
- - **Module Split Policy**: to split a large file —
105
- ① **write-first** — write the moved segment verbatim into the target file, then delete it from the source (code always has a copy; deleting first is irrecoverable on failure);
106
- ② logic body unchanged — only imports adjust (relative paths + new imports for referenced source symbols);
107
- ③ wiring — the source's remaining references to the moved symbol import it; the moved segment's references to source symbols move along or export/import back;
108
- ④ verify — node --check + related tests + the integration tests go green, AND the test/assertion count before and after the split must match (broken references and orphan bodies surface explicitly; a silent drop of assertions is a split defect);
109
- complete the split inside ONE task (no two-batch intermediate states).
110
- Assertion-count parity binds splits only — inventory cleanup rounds delete per an explicit itemized list (count delta = list).
92
+ ## 编码流程 —— 编码期间
93
+ - 需要几份互不相关的信息时,并行调工具 —— 读文件、搜索、grep 一次发出去。
94
+ - **大力并行**:在一个回复里发多个独立的工具调用(只读批次并发跑);
95
+ 多文件的独立改动用 `edits` 数组,整文件 / 新文件用 apply_patch;宁要一次批量调用,不要 N 次单改;
96
+ 一次 spawn 多个独立子代理 —— 包括把改动拆到互不相关的子项目(例如 monorepo:一个项目一个 agent),只要它们不共享文件、没有互相依赖、各有各的测试。
97
+ 这些并行起来花得比省得多:写同一个文件(带 `files` 声明的异步 spawn 除外 —— 调度器把重叠的排队到清空)互相覆盖;有依赖的步骤等各自的输入。
98
+ 同样费钱:bash / 需要批准的调用引起批准风暴;同一个仓库上并发的 git 命令互相撞;有状态操作交错。
99
+ 大的操作并行;微并行(<1s 的操作)略过。
100
+ - 非平凡工具调用之前,用一句短话说你在做什么(约 8 个词)。进度说明保持稀疏。
101
+ - 对行号敏感的工具(insert_after、hashline_edit)与精确匹配的工具(edit)需要最新的读 —— 文件可能变过,就在调用前重读。
102
+ - **模块拆分政策**:拆分一个大文件时 ——
103
+ ① **先写** —— 把要搬的段落逐字写进目标文件,再从来源删掉它(代码始终有一份副本;先删,失败就不可恢复);
104
+ ② 逻辑体不动 —— 只调导入(相对路径 + 为被引用的来源符号加新导入);
105
+ ③ 接线 —— 来源里剩下的、对搬走符号的引用改为导入它;搬走段落对来源符号的引用跟着搬,或导出 / 导入回来;
106
+ ④ 验证 —— node --check + 相关单元测试全绿,且拆分前后的测试 / 断言数必须相等(断掉的引用与孤儿体会明确浮出来;悄悄丢掉断言是拆分缺陷);
107
+ 在一次任务内完成拆分(不留两个批次之间的中间状态)。
108
+ 断言数相等只约束拆分 —— 清点式清理轮按明确的逐项清单删(计数差 = 清单)。