@thincoder/core 0.11.1 → 0.11.2

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 (333) hide show
  1. package/CHANGELOG.md +46 -2
  2. package/advisor/convergence.mjs +34 -3
  3. package/advisor/loop.mjs +42 -10
  4. package/advisor/messages.mjs +42 -25
  5. package/advisor/project-context.mjs +171 -42
  6. package/advisor/run.mjs +7 -4
  7. package/advisor.mjs +29 -43
  8. package/agent/batch-attribution.mjs +87 -0
  9. package/agent/batch-changed-surface.mjs +129 -0
  10. package/agent/completion.mjs +44 -3
  11. package/agent/dispatch-gates.mjs +6 -0
  12. package/agent/dispatch.mjs +8 -3
  13. package/agent/family-tools.mjs +27 -12
  14. package/agent/helpers.mjs +122 -1
  15. package/agent/offload.mjs +25 -29
  16. package/agent/post-turn.mjs +24 -10
  17. package/agent/record-results.mjs +18 -1
  18. package/agent/run-stages.mjs +77 -32
  19. package/agent/run-start.mjs +37 -0
  20. package/agent/setup-reminders.mjs +9 -2
  21. package/agent/setup.mjs +24 -11
  22. package/agent/spawn-child.mjs +38 -1
  23. package/agent/timers.mjs +5 -3
  24. package/agent/turn-loop.mjs +30 -5
  25. package/agent/turn-projection.mjs +386 -0
  26. package/agent/turn-task-state.mjs +274 -0
  27. package/agent/turn-tool-process.mjs +168 -0
  28. package/agent/write-gate-ledger.mjs +569 -0
  29. package/agent/write-gate.mjs +29 -352
  30. package/agent-tools/advisor-async.mjs +29 -169
  31. package/agent-tools/advisor-launch.mjs +178 -0
  32. package/agent-tools/advisor-settle.mjs +28 -1
  33. package/agent-tools/advisor.mjs +36 -47
  34. package/agent-tools/audit-block.mjs +6 -6
  35. package/agent-tools/batch-closeout.mjs +273 -35
  36. package/agent-tools/batch-gate.mjs +142 -342
  37. package/agent-tools/batch-ledger-bind.mjs +226 -17
  38. package/agent-tools/batch-ledger-view.mjs +109 -0
  39. package/agent-tools/batch-lifecycle.mjs +169 -46
  40. package/agent-tools/batch-paths.mjs +29 -8
  41. package/agent-tools/batch-record-write.mjs +417 -0
  42. package/agent-tools/batch-regions.mjs +215 -0
  43. package/agent-tools/batch-reopen.mjs +23 -11
  44. package/agent-tools/batch-segment-vocab.mjs +379 -0
  45. package/agent-tools/batch-skeleton.mjs +192 -239
  46. package/agent-tools/batch-supersede.mjs +232 -0
  47. package/agent-tools/batch-tier-gate.mjs +297 -0
  48. package/agent-tools/batch.mjs +182 -439
  49. package/agent-tools/consult.mjs +7 -4
  50. package/agent-tools/context.mjs +44 -17
  51. package/agent-tools/design-review-record.mjs +225 -0
  52. package/agent-tools/design-slots.mjs +1 -1
  53. package/agent-tools/design-token.mjs +279 -81
  54. package/agent-tools/doc-check.mjs +43 -33
  55. package/agent-tools/doc-graph.mjs +140 -0
  56. package/agent-tools/eng.mjs +9 -8
  57. package/agent-tools/escalate-async.mjs +2 -2
  58. package/agent-tools/manifest.mjs +34 -18
  59. package/agent-tools/read-history.mjs +112 -11
  60. package/agent-tools/review-facts.mjs +10 -3
  61. package/agent-tools/settings.mjs +23 -2
  62. package/agent-tools/spawn-gates.mjs +9 -8
  63. package/agent-tools/ssh-session.mjs +2 -2
  64. package/agent-tools/ssh-text.mjs +155 -0
  65. package/agent-tools/ssh-transport.mjs +19 -148
  66. package/agent-tools/subagent-actions-query.mjs +10 -6
  67. package/agent-tools/subagent-async.mjs +8 -9
  68. package/agent-tools/subagent-brief.mjs +76 -0
  69. package/agent-tools/subagent-design-token.mjs +168 -0
  70. package/agent-tools/subagent-run.mjs +1 -1
  71. package/agent-tools/subagent-scheduler.mjs +4 -4
  72. package/agent-tools/subagent-spawn.mjs +90 -110
  73. package/agent-tools/subagent.mjs +11 -10
  74. package/agent-tools/taskbook-block.mjs +94 -0
  75. package/agent-tools/timer.mjs +12 -8
  76. package/agent-tools/verify.mjs +13 -4
  77. package/agent-tools.mjs +7 -3
  78. package/agent.mjs +20 -1
  79. package/attachments.mjs +3 -3
  80. package/browser/actions.mjs +9 -3
  81. package/browser/cdp.mjs +45 -17
  82. package/browser/launch.mjs +25 -43
  83. package/browser/pool.mjs +299 -0
  84. package/browser/queue.mjs +2 -0
  85. package/browser/session-state.mjs +450 -0
  86. package/browser/session.mjs +127 -151
  87. package/browser/snapshot.mjs +89 -0
  88. package/client-identity.mjs +1 -1
  89. package/config-defaults.mjs +2 -1
  90. package/config-migrate.mjs +40 -0
  91. package/config-normalize.mjs +28 -2
  92. package/config-reload.mjs +59 -0
  93. package/config.mjs +62 -98
  94. package/context-degrade.mjs +38 -10
  95. package/context-echo.mjs +11 -0
  96. package/context.mjs +149 -83
  97. package/conventions.mjs +11 -9
  98. package/declaration.mjs +31 -5
  99. package/declared-repos.mjs +94 -0
  100. package/doc-check/doc-names.mjs +73 -0
  101. package/doc-check/doc-tokens.mjs +110 -0
  102. package/doc-check/existence.mjs +160 -0
  103. package/doc-check/index.mjs +309 -213
  104. package/doc-check/line-refs.mjs +27 -101
  105. package/doc-check/paragraph.mjs +218 -102
  106. package/doc-graph/anchors.mjs +474 -0
  107. package/doc-graph/doc-batch-face.mjs +59 -0
  108. package/doc-graph/doc-suffix.mjs +27 -0
  109. package/doc-graph/graph-tokens.mjs +160 -0
  110. package/doc-graph.mjs +778 -0
  111. package/explore-distill.mjs +11 -5
  112. package/i18n.mjs +1 -1
  113. package/instance-inbox-watch.mjs +272 -0
  114. package/instance-inbox.mjs +218 -0
  115. package/instance-registry.mjs +179 -0
  116. package/knowledge/README.md +3 -0
  117. package/knowledge/prompt-resources.md +6 -0
  118. package/ledger-close-proof.mjs +100 -49
  119. package/ledger-close.mjs +188 -0
  120. package/ledger-cmd.mjs +47 -91
  121. package/ledger-consistency.mjs +113 -0
  122. package/ledger-db.mjs +47 -15
  123. package/ledger-executors.mjs +1 -1
  124. package/ledger-tools.mjs +78 -19
  125. package/ledger-write-ops.mjs +130 -41
  126. package/ledger.mjs +1 -1
  127. package/manifest-discovery.mjs +3 -1
  128. package/manifest-schema.mjs +27 -5
  129. package/memory/schema.mjs +2 -2
  130. package/package.json +3 -1
  131. package/path-resolve.mjs +338 -57
  132. package/prompt-files.mjs +91 -1
  133. package/prompt-overlays.mjs +9 -6
  134. package/prompts/advisor-design.md +62 -21
  135. package/prompts/advisor-round1.md +34 -1
  136. package/prompts/advisor-round2.md +40 -7
  137. package/prompts/advisor-round3.md +39 -6
  138. package/prompts/common.md +14 -387
  139. package/prompts/consult-base.md +5 -1
  140. package/prompts/discipline-engineering.md +226 -51
  141. package/prompts/discipline-normal.md +4 -255
  142. package/prompts/knowledge/business-gates.md +22 -0
  143. package/prompts/knowledge/decision-quality.md +23 -0
  144. package/prompts/knowledge/doc-lookup.md +35 -0
  145. package/prompts/knowledge/document-writing.md +51 -0
  146. package/prompts/knowledge/documentation-evaluation.md +56 -0
  147. package/prompts/knowledge/evidence-discipline.md +57 -0
  148. package/prompts/knowledge/normal-coding-workflow.md +104 -0
  149. package/prompts/knowledge/normal-delivery-collaboration.md +108 -0
  150. package/prompts/knowledge/normal-work-management.md +57 -0
  151. package/prompts/knowledge/product-security.md +23 -0
  152. package/prompts/knowledge/project-records.md +62 -0
  153. package/prompts/knowledge/tool-advisor.md +29 -0
  154. package/prompts/knowledge/tool-apply-patch.md +18 -0
  155. package/prompts/knowledge/tool-bash.md +39 -0
  156. package/prompts/knowledge/tool-batch-eng-coder.md +12 -0
  157. package/prompts/knowledge/tool-batch-eng-designer.md +12 -0
  158. package/prompts/knowledge/tool-batch-review.md +12 -0
  159. package/prompts/knowledge/tool-batch.md +80 -0
  160. package/prompts/knowledge/tool-browser.md +57 -0
  161. package/prompts/knowledge/tool-code-search.md +4 -0
  162. package/prompts/knowledge/tool-consult-start.md +12 -0
  163. package/prompts/knowledge/tool-consult-stop.md +6 -0
  164. package/prompts/knowledge/tool-context.md +6 -0
  165. package/prompts/knowledge/tool-delete.md +17 -0
  166. package/prompts/knowledge/tool-doc-check.md +70 -0
  167. package/prompts/knowledge/tool-doc-graph-read.md +20 -0
  168. package/prompts/knowledge/tool-doc-graph.md +49 -0
  169. package/prompts/knowledge/tool-doc-search.md +6 -0
  170. package/prompts/knowledge/tool-edit.md +38 -0
  171. package/prompts/knowledge/tool-eng.md +2 -0
  172. package/prompts/knowledge/tool-execute.md +16 -0
  173. package/prompts/knowledge/tool-fetch.md +12 -0
  174. package/prompts/knowledge/tool-file-ops.md +16 -0
  175. package/prompts/knowledge/tool-get-current-time.md +7 -0
  176. package/prompts/knowledge/tool-git-read.md +19 -0
  177. package/prompts/knowledge/tool-git.md +29 -0
  178. package/prompts/knowledge/tool-glob.md +15 -0
  179. package/prompts/knowledge/tool-goal.md +8 -0
  180. package/prompts/knowledge/tool-grep.md +18 -0
  181. package/prompts/knowledge/tool-hashline-edit.md +14 -0
  182. package/prompts/knowledge/tool-insert-after.md +15 -0
  183. package/prompts/knowledge/tool-instance-list.md +6 -0
  184. package/prompts/knowledge/tool-instance-send.md +10 -0
  185. package/prompts/knowledge/tool-knowledge.md +18 -0
  186. package/prompts/knowledge/tool-ledger-read.md +35 -0
  187. package/prompts/knowledge/tool-ledger.md +42 -0
  188. package/prompts/knowledge/tool-lint.md +16 -0
  189. package/prompts/knowledge/tool-ls.md +13 -0
  190. package/prompts/knowledge/tool-lsp.md +11 -0
  191. package/prompts/knowledge/tool-main-history.md +2 -0
  192. package/prompts/knowledge/tool-manifest-read.md +14 -0
  193. package/prompts/knowledge/tool-manifest.md +31 -0
  194. package/prompts/knowledge/tool-memory-read.md +20 -0
  195. package/prompts/knowledge/tool-memory.md +15 -0
  196. package/prompts/knowledge/tool-notify-parent.md +12 -0
  197. package/prompts/knowledge/tool-operations.md +114 -0
  198. package/prompts/knowledge/tool-peer-instances.md +2 -0
  199. package/prompts/knowledge/tool-plan.md +6 -0
  200. package/prompts/knowledge/tool-process-read.md +13 -0
  201. package/prompts/knowledge/tool-process.md +15 -0
  202. package/prompts/knowledge/tool-question.md +16 -0
  203. package/prompts/knowledge/tool-read-history-batch.md +22 -0
  204. package/prompts/knowledge/tool-read-history.md +36 -0
  205. package/prompts/knowledge/tool-read-image.md +11 -0
  206. package/prompts/knowledge/tool-read.md +21 -0
  207. package/prompts/knowledge/tool-recent-changes.md +6 -0
  208. package/prompts/knowledge/tool-repo-outline.md +4 -0
  209. package/prompts/knowledge/tool-settings-read.md +12 -0
  210. package/prompts/knowledge/tool-settings.md +18 -0
  211. package/prompts/knowledge/tool-skill.md +6 -0
  212. package/prompts/knowledge/tool-ssh.md +52 -0
  213. package/prompts/knowledge/tool-subagent.md +59 -0
  214. package/prompts/knowledge/tool-task.md +12 -0
  215. package/prompts/knowledge/tool-team-ledger-read.md +11 -0
  216. package/prompts/knowledge/tool-team-ledger.md +11 -0
  217. package/prompts/knowledge/tool-timer.md +23 -0
  218. package/prompts/knowledge/tool-tree.md +14 -0
  219. package/prompts/knowledge/tool-verify.md +19 -0
  220. package/prompts/knowledge/tool-wait-for.md +25 -0
  221. package/prompts/knowledge/tool-websearch.md +19 -0
  222. package/prompts/knowledge/tool-write.md +9 -0
  223. package/prompts/knowledge/upstream-protocol.md +43 -0
  224. package/prompts/persona-eng-coder.md +21 -3
  225. package/prompts/persona-eng-designer.md +131 -169
  226. package/prompts/persona-engineering.md +142 -84
  227. package/prompts/persona-explore.md +1 -1
  228. package/prompts/persona-plan.md +5 -1
  229. package/prompts/subagent-base.md +2 -0
  230. package/provider/anthropic.mjs +6 -4
  231. package/provider/core.mjs +3 -2
  232. package/provider/errors.mjs +29 -4
  233. package/provider/google.mjs +24 -7
  234. package/provider/responses.mjs +3 -1
  235. package/provider-flows.mjs +2 -2
  236. package/session-index-build.mjs +1 -1
  237. package/session-index-pass.mjs +1 -1
  238. package/session-index-query.mjs +1 -1
  239. package/session-index.mjs +1 -1
  240. package/session-lifecycle.mjs +72 -17
  241. package/session-slot-write.mjs +37 -5
  242. package/session.mjs +24 -8
  243. package/skip-dirs.mjs +2 -2
  244. package/team-ledger.mjs +13 -9
  245. package/token-ttl.mjs +73 -4
  246. package/token-window.mjs +167 -33
  247. package/tool-docs/advisor.md +2 -27
  248. package/tool-docs/apply_patch.md +1 -15
  249. package/tool-docs/bash.md +2 -41
  250. package/tool-docs/batch-eng-coder.md +3 -0
  251. package/tool-docs/batch-eng-designer.md +3 -0
  252. package/tool-docs/batch-review.md +3 -0
  253. package/tool-docs/batch.md +2 -84
  254. package/tool-docs/browser.md +2 -49
  255. package/tool-docs/code_search.md +2 -2
  256. package/tool-docs/consult_start.md +2 -8
  257. package/tool-docs/consult_stop.md +2 -4
  258. package/tool-docs/context.md +1 -5
  259. package/tool-docs/delete.md +2 -17
  260. package/tool-docs/doc_check.md +2 -107
  261. package/tool-docs/doc_graph-read.md +3 -0
  262. package/tool-docs/doc_graph.md +3 -0
  263. package/tool-docs/doc_search.md +2 -4
  264. package/tool-docs/edit.md +1 -38
  265. package/tool-docs/eng.md +3 -1
  266. package/tool-docs/execute.md +2 -18
  267. package/tool-docs/fetch.md +2 -14
  268. package/tool-docs/file_ops.md +2 -18
  269. package/tool-docs/get_current_time.md +1 -6
  270. package/tool-docs/git-read.md +3 -0
  271. package/tool-docs/git.md +2 -35
  272. package/tool-docs/glob.md +2 -10
  273. package/tool-docs/goal.md +1 -6
  274. package/tool-docs/grep.md +2 -18
  275. package/tool-docs/hashline_edit.md +2 -15
  276. package/tool-docs/insert_after.md +2 -16
  277. package/tool-docs/instance_list.md +3 -0
  278. package/tool-docs/instance_send.md +3 -0
  279. package/tool-docs/knowledge.md +3 -0
  280. package/tool-docs/ledger-read.md +3 -0
  281. package/tool-docs/ledger.md +3 -8
  282. package/tool-docs/lint.md +2 -10
  283. package/tool-docs/ls.md +2 -11
  284. package/tool-docs/lsp.md +2 -9
  285. package/tool-docs/main_history.md +3 -1
  286. package/tool-docs/manifest-read.md +2 -8
  287. package/tool-docs/manifest.md +2 -35
  288. package/tool-docs/memory-read.md +3 -0
  289. package/tool-docs/memory.md +2 -20
  290. package/tool-docs/notify_parent.md +2 -13
  291. package/tool-docs/peer_instances.md +3 -1
  292. package/tool-docs/plan.md +1 -5
  293. package/tool-docs/process-read.md +3 -0
  294. package/tool-docs/process.md +2 -13
  295. package/tool-docs/question.md +3 -17
  296. package/tool-docs/read.md +2 -19
  297. package/tool-docs/read_history-batch.md +3 -0
  298. package/tool-docs/read_history.md +2 -18
  299. package/tool-docs/read_image.md +2 -9
  300. package/tool-docs/recent_changes.md +2 -2
  301. package/tool-docs/repo_outline.md +2 -2
  302. package/tool-docs/settings-read.md +3 -0
  303. package/tool-docs/settings.md +1 -12
  304. package/tool-docs/skill.md +2 -6
  305. package/tool-docs/ssh.md +1 -62
  306. package/tool-docs/subagent.md +2 -100
  307. package/tool-docs/task.md +1 -7
  308. package/tool-docs/team_ledger-read.md +3 -0
  309. package/tool-docs/team_ledger.md +3 -9
  310. package/tool-docs/timer.md +2 -19
  311. package/tool-docs/tree.md +2 -13
  312. package/tool-docs/verify.md +2 -12
  313. package/tool-docs/wait_for.md +2 -32
  314. package/tool-docs/websearch.md +2 -19
  315. package/tool-docs/write.md +2 -12
  316. package/tools/browser.mjs +52 -7
  317. package/tools/doc-write-gate.mjs +73 -0
  318. package/tools/edit-batch.mjs +170 -92
  319. package/tools/edit-diff.mjs +78 -62
  320. package/tools/edit-receipt.mjs +39 -0
  321. package/tools/execute.mjs +1 -1
  322. package/tools/file.mjs +16 -8
  323. package/tools/git.mjs +24 -9
  324. package/tools/index.mjs +6 -0
  325. package/tools/knowledge.mjs +143 -0
  326. package/tools/linter.mjs +3 -3
  327. package/tools/ops.mjs +3 -1
  328. package/tools/patch.mjs +123 -43
  329. package/tools/shared.mjs +28 -27
  330. package/tools/write-gate-params.mjs +31 -0
  331. package/tools/write-path.mjs +16 -4
  332. package/window-policy.mjs +203 -0
  333. package/doc-check/anchors.mjs +0 -235
@@ -0,0 +1,168 @@
1
+ /**
2
+ * subagent-design-token.mjs — **设计令牌门**族:design-token 槽解析、七态拒句、eng-coder spawn 的令牌判定。
3
+ *
4
+ * 机制单源 = `docs/core/design/TOOLS.md` §6.25(③ 七态拒句 ∥ ④ 令牌门)与 `docs/core/design/ENGINEERING-MODE.md`
5
+ * 的设计令牌结算段;本档只实现,不重述口径。
6
+ * **为什么单独立档**:这一族是 spawn 门里唯一「判授权」的部分(其余门判参数与路径),消费者只有
7
+ * `subagent-spawn.mjs` 的 child 装配点——整族搬走不动装配面一字(`docs/core/design/PATH-RESOLUTION.md` §3 末条)。
8
+ *
9
+ * 导出面两处消费:装配点(`gateDesignToken`)与再导出面(`subagent-spawn.mjs` 原样再导出 `resolveDesignSlot`
10
+ * ∥ `designTokenRefusal` ⇒ `subagent.mjs` 的再导出行与用例的 import 行零改)。
11
+ */
12
+ import { readEngTokenBatchesFromSlot, readEngTokenSealsFromSlot, removeDesignTokenSlot, reconcileEngTokensFromSlot, tokenExpired } from "../token-ttl.mjs"
13
+ import { validateDesignToken } from "./advisor.mjs"
14
+ // 评审封印的字节口径单源(settle 与闸面同调一个函数——两处各写一份字节法,必漂)。
15
+ import { designDocHash, designSealHash } from "./design-token.mjs"
16
+ // 批档比较的归一单源(§9 的匹配规则:`resolve` + 分隔符归一 + win32 折小写)——本门不自写第二份。
17
+ import { batchPathKey } from "./design-slots.mjs"
18
+
19
+ /**
20
+ * Resolve the design-token slot for an eng-coder spawn (2026-09-01 multi-design, FR3):
21
+ * - designId given → exact slot lookup (no match = explicit error, never a fuzzy guess)
22
+ * - designId omitted → exactly ONE slot must exist (single-design compatibility); with
23
+ * multiple slots we refuse rather than pick one (T16: never silently aim the wrong design)
24
+ * Returns { token, designId } on success (designId = the slot actually resolved — the spawn may omit
25
+ * it while a single slot exists, and the batch/seal steps still need its key); throws with a
26
+ * parent-actionable message otherwise.
27
+ * R16 (2026-09-06): the slot Map is the authority; the format/TTL check itself stays in
28
+ * validateDesignToken (2026-09-06: HMAC 防伪层已删——token 为无签名流程凭证——见
29
+ * ENGINEERING-MODE.md 2026-09-06 段)。
30
+ * DESIGN-TOKEN-SETTLEMENT D2(2026-09-08):内存 Map miss(指定 designId 不在 / 空 Map)
31
+ * 时回读槽文件权威台账 reconcile + 判定(reconcileEngTokensFromSlot——与 dispatch 写门
32
+ * D3 同源)——覆盖"进程重启后槽有但 Map 未及回填/缓存与槽不一致"(槽文件 = 权威台账)。
33
+ * TTL 过滤保留(reconcile 只并入未过期项)。单值镜像 `_engDesignToken` 已随 D3 退役——
34
+ * 本门禁不再读镜像(AC3 零命中)。
35
+ */
36
+ export function resolveDesignSlot(parent, designIdArg) {
37
+ let slots = parent._engDesignTokens
38
+ const hasSlots = slots instanceof Map && slots.size > 0
39
+ // D2:内存 miss(指定 designId 不在 或 空 Map)→ 权威槽回读 reconcile + 判定
40
+ if (designIdArg ? !(hasSlots && slots.has(designIdArg)) : !hasSlots) {
41
+ const rec = reconcileEngTokensFromSlot(parent)
42
+ if (rec && rec !== slots) slots = rec
43
+ }
44
+ // F2d: both refusal branches carry the HELD id list — after a
45
+ // persistence restore the parent has no digest to look the id up in; the error
46
+ // list is the only discovery path (ids are not credentials — the token is).
47
+ const size = slots instanceof Map ? slots.size : 0
48
+ const heldIds = size > 0 ? [...slots.keys()].join(", ") : "(none)"
49
+ if (designIdArg) {
50
+ if (!(slots instanceof Map) || !slots.has(designIdArg)) {
51
+ throw new Error(`designId not found — no approved design review holds this id. Run advisor with type='design' again and pass the designId echoed with the token. (session holds ${size} approved design slot(s); held design ids: ${heldIds})`)
52
+ }
53
+ return { token: slots.get(designIdArg), designId: designIdArg }
54
+ }
55
+ if (size > 1) {
56
+ throw new Error(`Multiple approved designs in this session (${size}) — pass the designId parameter (echoed with each token) to choose which design this eng-coder spawn belongs to. Held design ids: ${heldIds}`)
57
+ }
58
+ if (size === 1) return { token: [...slots.values()][0], designId: [...slots.keys()][0] }
59
+ throw designTokenRefusal("missing", null, {})
60
+ }
61
+
62
+ /** 七态拒句(逐字 = TOOLS.md §6.25 ③):missing / mismatch / expired / invalid /
63
+ * batch-mismatch / seal-mismatch / seal-unreadable。
64
+ * 第三参 `scope` **必传、不设默认值**(三参形单源 = DESIGN-TOKEN-SETTLEMENT §10.2):无名字可点的态传
65
+ * `{}`,缺参在构造器入口拒——缺省值会默默代调用方决定「没有名字」,而错位的判决三条层下去才看得出来。
66
+ * 四个带名字的态各自入参:mismatch ⇒ designId 走第二参 · batch-mismatch ⇒ `{boundBatch, givenBatch}` 两个绝对路径 ·
67
+ * seal-mismatch ⇒ `{changed: [<可变路径…>]}`(按 `docs` 原序;空数组 ⇒ 无路径形)· seal-unreadable ⇒ `{path}`。
68
+ * designId 与路径都不是凭证,七句均零令牌值回显。 */
69
+ export function designTokenRefusal(kind, designId, scope) {
70
+ if (scope === undefined || scope === null || typeof scope !== "object" || Array.isArray(scope)) {
71
+ const got = scope === null ? "null" : Array.isArray(scope) ? "an array" : typeof scope
72
+ throw new Error(`designTokenRefusal: the third parameter \`scope\` is required and must be an object — got ${got} for kind="${kind}"; pass {} when the refusal names nothing (DESIGN-TOKEN-SETTLEMENT §10.2「三参形」).`)
73
+ }
74
+ if (kind === "missing") return new Error("designToken missing — the eng-coder spawn is refused: no usable token for an approved design slot came with this spawn. Pass the designToken parameter with the exact value from the subagent action:'design-slots' row (the text after designToken=), copied verbatim; if that list is empty, no design review has been approved in this session yet — run advisor with type='design' first. No token value is echoed here.")
75
+ if (kind === "mismatch") return new Error("designToken mismatch — the eng-coder spawn is refused: the value passed does not equal the token held for this design slot. Re-read the subagent action:'design-slots' row and pass the value after designToken= verbatim, unchanged. No token value is echoed here." + (designId ? ` (designId: ${designId})` : ""))
76
+ if (kind === "expired") return new Error("designToken expired — the eng-coder spawn is refused: the token matches this design slot but is past its TTL. The expired slot has been removed; run advisor with type='design' again on the current design and pass the newly issued token — an expired authorization cannot be retried. No token value is echoed here.")
77
+ if (kind === "batch") return new Error(`designToken batch mismatch — the eng-coder spawn is refused: this token was issued for ${scope?.boundBatch ?? "(unknown)"}, but this spawn implements ${scope?.givenBatch ?? "(unknown)"}. Use the token from this batch's design review.`)
78
+ if (kind === "seal") {
79
+ // 点名判定(§10.2「拒文点名变了的那几份档」):有可比路径 ⇒ 列路径形;一条都点不出来(旧封印行
80
+ // 没有 `docHashes`)⇒ 保留无路径形。两形业务结果相同(照旧拒),差的只是报面上的名字。
81
+ const changed = Array.isArray(scope.changed) ? scope.changed.filter((p) => typeof p === "string" && p) : []
82
+ if (changed.length > 0) return new Error(`designToken seal mismatch — the reviewed documents changed after the review passed: ${changed.join(", ")} — re-run the review, or revert those files to the version the review approved.`)
83
+ return new Error("designToken seal mismatch — the reviewed documents changed after the review passed (this seal records no per-document hashes, so no path can be named) — re-run the review, or revert the change.")
84
+ }
85
+ if (kind === "seal-unreadable") return new Error(`designToken seal unreadable — the eng-coder spawn is refused: the reviewed document ${scope?.path ?? "(unknown)"} cannot be read, so the seal cannot be checked. Restore that file, or re-run the review, and spawn again.`)
86
+ return new Error("designToken invalid — the eng-coder spawn is refused: the value passed equals this design slot's stored token, but that stored value is not a well-formed token, so no expiry can be judged and the slot was left in place. Run advisor with type='design' to issue a fresh token for this design; a malformed record never passes the gate. No token value is echoed here.")
87
+ }
88
+
89
+ /** 拒文点名(DESIGN-TOKEN-SETTLEMENT §10.2「拒文点名变了的那几份档」):按封印行的 `docs` 原序逐档
90
+ * 重算,与 `docHashes` 里同一路径的记值比对,返回不等的那些路径。**只服务报面**——判定值仍是组合
91
+ * `hash`,本函数不参与放行与否。旧封印行没有 `docHashes`(本改动之前写下的)⇒ 空数组 ⇒ 拒文走无路径形。
92
+ * 逐档读不到由调用方的 `try` 收成 `seal-unreadable`(fail-closed:判不了就不放行)。
93
+ * @param {{docs: string[], docHashes?: {path: string, hash: string}[]}} seal 槽里那一行封印
94
+ * @returns {string[]} 变了的档路径(按 `docs` 原序) */
95
+ function changedDocsOf(seal) {
96
+ if (!Array.isArray(seal.docHashes)) return []
97
+ const recorded = new Map()
98
+ for (const d of seal.docHashes) {
99
+ if (d && typeof d === "object" && typeof d.path === "string" && typeof d.hash === "string" && !recorded.has(d.path)) recorded.set(d.path, d.hash)
100
+ }
101
+ const changed = []
102
+ for (const p of seal.docs) {
103
+ const want = recorded.get(p)
104
+ if (want === undefined) continue
105
+ if (designDocHash(p) !== want) changed.push(p)
106
+ }
107
+ return changed
108
+ }
109
+
110
+ /** eng-coder spawn 的令牌门(TOOLS.md §6.25 ④⑤⑥):resolveDesignSlot 的既有两条 designId
111
+ * 诊断零改 → 参数在场 → 值相等 → 值有效 → 批归属 → 评审封印。槽删除只在 tokenExpired(given)
112
+ * 成立时发生(D-R16c ③);mismatch / invalid / batch / seal 不删槽(T-R16d)。返回槽内令牌
113
+ * (调用方回写 designId 依赖它);sync / async 两路共经装配点——一处判定双路生效。
114
+ *
115
+ * ⑤ 批归属(DESIGN-TOKEN-SETTLEMENT §10.1):比较对象 = `buildSpawnChild` 的 batchDoc 门已解析
116
+ * 好的绝对路径(第三参;本步不自己解析 `args.batchDoc`——解析单源在那一处)。旁列**严格读**:
117
+ * 槽文件读不到 ⇒ 抛,不落进「旁列无值 ⇒ 不拦」。旁列无值(旧槽 ∥ 该次评审不带批档)⇒ 跳过。
118
+ * ⑥ 评审封印(§10.2):只读槽里记下的 `docs` 复算,不自己推清单(自己推 = 两处各自定义「被审档」)。
119
+ * 无封印值(旧槽)⇒ 跳过;被审档读不到 ⇒ 拒(fail-closed——判不了就不放行)。
120
+ * @param {string} opts.batchDocAbs 第三参恒由装配点给(eng-coder 缺 batchDoc 时更早的门已拒);旁列有值
121
+ * 而它不是串 = 接线故障 ⇒ throw(不是一条给用户看的拒因)。 */
122
+ export function gateDesignToken(parent, args, { batchDocAbs }) {
123
+ const slot = resolveDesignSlot(parent, args?.designId)
124
+ const issuedToken = slot.token
125
+ // 非字符串 ⇒ 空串 ⇒ missing(本意——T9 锁定)
126
+ const given = typeof args?.designToken === "string" ? args.designToken : ""
127
+ if (!issuedToken || !given.trim()) throw designTokenRefusal("missing", null, {})
128
+ if (given !== issuedToken) throw designTokenRefusal("mismatch", args?.designId, {})
129
+ if (!validateDesignToken(given)) {
130
+ const expired = tokenExpired(given)
131
+ if (expired) removeDesignTokenSlot(parent, args?.designId, given)
132
+ throw designTokenRefusal(expired ? "expired" : "invalid", null, {})
133
+ }
134
+ // ⑤ 批归属:旁列有值 ∧ 归一后 ≠ 本次 spawn 的 batchDoc 绝对路径 ⇒ 拒。排在封印之前 = 先判便宜的那条
135
+ // (归属不符时不必逐档读盘算 hash;判据顺序单源 = TOOLS.md §6.25 ③ 的顺序行)。
136
+ const batches = readEngTokenBatchesFromSlot(parent, { strict: true })
137
+ // 「读到、没有这个 designId 的行」与「行在、值不成形」同判为**无归属**(与 `restoreEngTokens` 同一取舍:
138
+ // 成形与否由写者保证;结构损坏在整档层已由严格读的 `JSON.parse` 兜住)。这不是一条宽容读。
139
+ const bound = batches && typeof batches[slot.designId] === "string" ? batches[slot.designId] : null
140
+ if (bound) {
141
+ if (typeof batchDocAbs !== "string" || !batchDocAbs.trim()) {
142
+ throw new Error(`gateDesignToken: design slot ${slot.designId} carries a batch attribution (${bound}) but the spawn passed no resolved batchDoc — the batchDoc gate runs before the token gate, so this is a wiring fault, not an input to judge.`)
143
+ }
144
+ if (batchPathKey(bound) !== batchPathKey(batchDocAbs)) {
145
+ throw designTokenRefusal("batch", null, { boundBatch: bound, givenBatch: batchDocAbs })
146
+ }
147
+ }
148
+ // ⑥ 评审封印:有封印值 ∧ 重算的 sha256 ≠ 记下的值 ⇒ 拒;清单里一份档读不到 ⇒ 拒(fail-closed)。
149
+ const seals = readEngTokenSealsFromSlot(parent, { strict: true })
150
+ const seal = seals && seals[slot.designId]
151
+ // 成形不全的行也按「无封印值」跳过(与 `restoreEngTokens` 同一取舍)——它与「旧槽无值」不是同一种事实,
152
+ // 是写明的一笔降级:成形由写者保证,整档结构损坏已由严格读的解析失败兜住;设计 §10.2 只裁到「旧槽无值 ⇒ 不拦」。
153
+ const hasSeal = seal && typeof seal === "object" && typeof seal.hash === "string"
154
+ && Array.isArray(seal.docs) && seal.docs.every((p) => typeof p === "string")
155
+ if (hasSeal) {
156
+ let actual
157
+ let changed = []
158
+ try {
159
+ actual = designSealHash(seal.docs)
160
+ // 只有组合值不等才逐档比(多数派单走不到这里);逐档读不到由同一条 catch 收成 seal-unreadable。
161
+ if (actual !== seal.hash) changed = changedDocsOf(seal)
162
+ } catch (e) {
163
+ throw designTokenRefusal("seal-unreadable", null, { path: e?.sealPath ?? "(unknown)" })
164
+ }
165
+ if (actual !== seal.hash) throw designTokenRefusal("seal", null, { changed })
166
+ }
167
+ return issuedToken
168
+ }
@@ -40,7 +40,7 @@ export function drainInjectedQueue(entry, agent) {
40
40
  }
41
41
 
42
42
  /**
43
- * Async branch (AGENT-LOOP-SUBAGENT.md §6.7.3 D-A1/D-A6): spawn without waiting.
43
+ * Async branch (AGENT-LOOP-SUBAGENT.md §6.7.3): spawn without waiting.
44
44
  * The child runs the EXACT blocking pipeline (runChildPipeline — relay /
45
45
  * turn-cap / permission / MIN_REPORT_CHARS / mergeChildMutations all unchanged),
46
46
  * but the parent does not await it: the promise is parked in _asyncSubagents and
@@ -17,7 +17,7 @@ import { logEvent } from "../log.mjs"
17
17
  // M5 F6(ENGINEERING-MODE-V2-MODULE-DELEGATION §2.3):files 声明面拦截谓词本体落
18
18
  // spawn-gates.mjs(纯谓词零依赖——本处只加 import 调用,无环)。
19
19
  import { rejectProcessDocPaths } from "./spawn-gates.mjs"
20
- // `files` 落点单源 = 统一解析层(`docs/core/design/PATH-RESOLUTION.md` §2.5 第 4 行:`kind:"none"` /
20
+ // `files` 落点单源 = 统一解析层(`docs/core/design/PATH-RESOLUTION.md` §2.5 的「子代理 `files`(spawn 门)」行:`kind:"none"` /
21
21
  // `order:"near-first"` ⇒ 恒解析出、只做调度、不校验存在性)。门判(目录声明 / 过程档)
22
22
  // 仍吃**原始声明形状**——判据在转绝对之前跑,顺序零改。
23
23
  import { resolvePathTarget } from "../path-resolve.mjs"
@@ -191,7 +191,7 @@ export function describeBlockers(parent, entry) {
191
191
  * 三条判据各防一个具体的错:① 池**经访问器读**(`getAsyncPool`,读法同 `depInfo`)——
192
192
  * 裸读 `parent._asyncSubagents` 在只携 `history` 的合成 parent 上读到空池 ⇒ 护栏不报错、
193
193
  * 不生效、没人知道;② **按 status 过滤**(`done` / `cancelled` 皆假)——正常 settle 的条目
194
- * 留在池里(`async-settle.mjs:295`)⇒ 只看「池里有同档条目」会把单席顺序交接全部误拒;
194
+ * 留在池里(`async-settle.mjs` 的「留池 done-in-pool」段)⇒ 只看「池里有同档条目」会把单席顺序交接全部误拒;
195
195
  * ③ **占用判据只认 `_batchDoc`、不分角色**(普通面 coder 携档也算),而被检面只有工程角色的
196
196
  * spawn、sync spawn 不入池也不是占用者(同档 §6.58.7 第 7 条)——**这个不对称勿「顺手统一」**。
197
197
  * 入参 = 已解析的绝对路径(唯一消费方 `buildSpawnChild` 的工程分支,路径由 `resolveBatchReadPath`
@@ -374,7 +374,7 @@ export function dependentLabels(parent, depId) {
374
374
  /** §6.9 D-SD3b 排队态面板刷新(⟦ev⟧queued 事件族——TUI routeSubToken 消费):对全部
375
375
  * queued 条目重算等待态并发射变化(去重 sig——kind/position/detail 全变才发)——
376
376
  * 调用点 = 一切队列突变与等待态变迁(spawn 入队 / settle 后补位与依赖转移 / cancel
377
- * 出队 / 自动通道消费)。position = 队列序(D-A1 既有——cancel 前移同源)。
377
+ * 出队 / 自动通道消费)。position = 队列序(§6.7.3 既有——cancel 前移同源)。
378
378
  * P1 禁静默(zero-block 批 §6.8.3.2②):relay 异常不再静默——留痕一条
379
379
  * `ev:queued-paint-failed`(**池状态不被破坏**语义不变——catch 不重抛)。 */
380
380
  export function refreshQueuedTokens(parent, onToken) {
@@ -396,7 +396,7 @@ export function refreshQueuedTokens(parent, onToken) {
396
396
  }
397
397
 
398
398
  /**
399
- * Slot-queue refill (AGENT-LOOP-SUBAGENT.md §6.7.3 D-A1/D-A6 + §6.9 D-SD4 + AGENT-LOOP-ASYNC-POOL.md §6.10 D-24a/R14 分域):
399
+ * Slot-queue refill (AGENT-LOOP-SUBAGENT.md §6.7.3 + §6.9 D-SD4 + AGENT-LOOP-ASYNC-POOL.md §6.10 D-24a/R14 分域):
400
400
  * start queue heads while a running slot is free — called from every settle
401
401
  * (completion frees a slot) and from the turn-end collection's refill loop. 队列现可混合 waiting-deps 与 slot-queued——扫描选"依赖全满足 + 域无冲突"的最早
402
402
  * 条目启动(waiting 越行不阻塞槽位;多任务同时解除按 queued 序逐个启动)。
@@ -1,26 +1,38 @@
1
1
  /**
2
2
  * subagent-spawn.mjs — spawn 路径装配(2026-09-05 module-split:subagent.mjs 726
3
- * > 500 硬限——spawn 前置 helpers(effectiveSubagentModel/resolveDesignSlot——审计块
4
- * 构造器 2026-09-22 起另立 ./audit-block.mjs)+ AGENT-LOOP-SUBAGENT.md §6.9 调度参数准入(prepareScheduling)+ child 装配
3
+ * > 500 硬限——spawn 前置 helpers(effectiveSubagentModel)+ AGENT-LOOP-SUBAGENT.md §6.9 调度参数准入(prepareScheduling)+ child 装配
5
4
  * (buildSpawnChild)verbatim 迁入(仅闭包变量参数化),语义零变;executeAsyncSpawn
6
5
  * 另在 subagent-run.mjs。subagent.mjs execute 经本文件 import 调用。
6
+ * **本轮(档位 500 设计器硬线)再切两族**:任务书与 system 固块拼装 → `./subagent-brief.mjs`、
7
+ * 设计令牌门 → `./subagent-design-token.mjs`(落点 = `docs/core/design/PATH-RESOLUTION.md` §3 末条)。
8
+ * **两族的对外面各不相同、各自守住**:设计令牌族**原样再导出**(`subagent.mjs` 的再导出行与用例的 import 行零改);
9
+ * 任务书族由本档直接 import 消费,不对外导出(今天没有任何调用点从本档取它)。
7
10
  * 2026-09-07:executeConsumeDesignAction 消费执行器(token 链终消费制——与 spawn 侧
8
11
  * slot 族同域——ENGINEERING-MODE.md §2.6 F1——removeDesignTokenSlot 自 token-ttl.mjs)。
9
12
  * 2026-09-22(台账 #23 · AGENT-LOOP-SUBAGENT.md §6.26):审计块构造器外提 `./audit-block.mjs`;
10
13
  * spawn 级固定机制性指令改走 system 固块(`child._spawnSystemBlock` 单点绑定——消费点 = 核
11
14
  * `prepareRun`),`input` 只留任务书。2026-10-24(§6.22):工程角色 `input` = 一行机械任务书行
12
- * (批档绝对路径 + §2 指向句),任务书本体由子代理自读 §2。
15
+ * (批档绝对路径 + 按角色的指向句),任务书本体由子代理从批档读(§8.1 切片)。
13
16
  */
14
17
 
18
+ // 2026-11-15(AGENT-LOOP-SUBAGENT.md §8.1):工程角色的任务书正文随 system 固块下发——spawn 当刻读一次
19
+ // 批档并冻结(`readFileSync` 在本档,切段与拼块的本体住 `./taskbook-block.mjs`)。
20
+ import { readFileSync } from "node:fs"
15
21
  import {
16
22
  createAgent,
17
23
  readonlyToolNames, escapeXml, excludeSubagentTools,
18
24
  } from "../agent.mjs"
19
- import { allocRelay, wrapChildCallbacks, relayPrefixOf } from "../agent/spawn-child.mjs"
25
+ import { allocRelay, wrapChildCallbacks, relayPrefixOf, chargeDesignerSurveySpawn, rootAgentOf } from "../agent/spawn-child.mjs"
26
+ // B8(TOOLS.md §6.29 ④):eng 两角色的受限父历史(同名 `read_history`,只在 extraTools 注入)
27
+ import { makeBatchHistoryTool, recordBatchHistoryStart } from "./read-history.mjs"
28
+ // B4(TOOLS.md §6.29 ①):只读角色的 action 级变体派生(构造器单源 = `agent/helpers.mjs`,
29
+ // 判据单源 = `agent/dispatch-gates.mjs` 的 `readonlyActionOf`)。
30
+ import { deriveReadonlyTools } from "../agent/helpers.mjs"
31
+ import { readonlyActionTest } from "../agent/dispatch-gates.mjs"
20
32
  // TUI-OOM-ROOTCAUSE(AGENT-LOOP.md §6.15):子代理人读线窗口常量单源(store 零依赖)。
21
33
  import { RECORD_WINDOW_MESSAGES } from "../session-store.mjs"
22
- import { validateDesignToken } from "./advisor.mjs"
23
- import { tokenExpired, removeDesignTokenSlot, reconcileEngTokensFromSlot } from "../token-ttl.mjs"
34
+ // 设计令牌门(七态拒句 ∥ 槽解析 ∥ 令牌判定)本体落 `./subagent-design-token.mjs`;本档只吃判定。
35
+ import { gateDesignToken } from "./subagent-design-token.mjs"
24
36
  import { resolveChildProvider, buildChildRunOpts, enqueueAsk } from "./subagent-async.mjs"
25
37
  import { nextSubagentId } from "./subagent-scheduler.mjs"
26
38
  import {
@@ -29,12 +41,16 @@ import {
29
41
  // M5 F2(ENGINEERING-MODE-V2-MODULE-DELEGATION §2.3):任务书 round 枚举 + 五项结构化参数校验/拼装本体落
30
42
  // spawn-gates.mjs(纯谓词零依赖)——本处只加 import 调用。
31
43
  import {
32
- validateRoundParam, validateTaskBookParams, composeTaskBookBrief,
44
+ validateRoundParam, validateTaskBookParams,
33
45
  isEngineeringRole, rejectEngFreeTextParams,
34
46
  } from "./spawn-gates.mjs"
47
+ // 任务书与 system 固块拼装(任务书播报 ∥ 写域行 S4 ∥ 文档坐标行 S5)落 `./subagent-brief.mjs`。
48
+ import { docsCoordinatesBlockOf, filesBlockOf, taskBriefOf } from "./subagent-brief.mjs"
35
49
  // 台账 #23(AGENT-LOOP-SUBAGENT.md §6.26 · D23-3):审计块构造器外提(`buildAuditBlock` 纯函数)
36
50
  // ——spawn 档只做「收集 + 绑定」;块文本逐字搬移(D23-4)。
37
51
  import { buildAuditBlock } from "./audit-block.mjs"
52
+ // 任务书正文块(`AGENT-LOOP-SUBAGENT.md` §8.1 载体 ∥ 切片 ∥ 快照 ∥ 失效即拒)——纯函数外提,同审计块先例。
53
+ import { buildTaskBookBlock, taskBookPointerLine } from "./taskbook-block.mjs"
38
54
  // 批次档路径解析单源(BATCH-RECORD.md §4.15 · 台账 #287):门内解析改经叶档(读面非抛形),
39
55
  // 与 append / create 同源——门判据仍「参数在 + 路径可读」,错误文案逐字零变。
40
56
  import { resolveBatchReadPath, resolveBatchReadResult } from "./batch-paths.mjs"
@@ -53,14 +69,6 @@ function unreadableHint(cwd, given) {
53
69
  return ""
54
70
  }
55
71
 
56
- /** 任务书播报文本:该角色名集拼装 + 可选 task 自由文本(拼装空 ⇒ 原 task 逐字——旧形零变)。 */
57
- function taskBriefOf(args, role) {
58
- const composed = composeTaskBookBrief(args, role)
59
- if (!composed) return args.task
60
- const extra = typeof args.task === "string" ? args.task.trim() : ""
61
- return extra ? `${composed}\n\n${extra}` : composed
62
- }
63
-
64
72
  /** 原 #309 任务书 token 观测(`child:batchdoc-ref`)已废止——2026-10-24 用户裁定
65
73
  * 「不允许跨批引用」后,工程角色 input 只剩一行机械文本,扫描对象失效;无场景分支不留
66
74
  * (AGENT-LOOP-SUBAGENT.md §6.29.3)。 */
@@ -83,47 +91,6 @@ export function effectiveSubagentModel(parent, role, modelArg) {
83
91
  return cfg.subagentModels?.[role] ?? cfg.subagentModel ?? null
84
92
  }
85
93
 
86
- /**
87
- * Resolve the design-token slot for an eng-coder spawn (2026-09-01 multi-design, FR3):
88
- * - designId given → exact slot lookup (no match = explicit error, never a fuzzy guess)
89
- * - designId omitted → exactly ONE slot must exist (single-design compatibility); with
90
- * multiple slots we refuse rather than pick one (T16: never silently aim the wrong design)
91
- * Returns { token } on success; throws with a parent-actionable message otherwise.
92
- * R16 (2026-09-06): the slot Map is the authority; the format/TTL check itself stays in
93
- * validateDesignToken (2026-09-06: HMAC 防伪层已删——token 为无签名流程凭证——见
94
- * ENGINEERING-MODE.md 2026-09-06 段)。
95
- * DESIGN-TOKEN-SETTLEMENT D2(2026-09-08):内存 Map miss(指定 designId 不在 / 空 Map)
96
- * 时回读槽文件权威台账 reconcile + 判定(reconcileEngTokensFromSlot——与 dispatch 写门
97
- * D3 同源)——覆盖"进程重启后槽有但 Map 未及回填/缓存与槽不一致"(槽文件 = 权威台账)。
98
- * TTL 过滤保留(reconcile 只并入未过期项)。单值镜像 `_engDesignToken` 已随 D3 退役——
99
- * 本门禁不再读镜像(AC3 零命中)。
100
- */
101
- export function resolveDesignSlot(parent, designIdArg) {
102
- let slots = parent._engDesignTokens
103
- const hasSlots = slots instanceof Map && slots.size > 0
104
- // D2:内存 miss(指定 designId 不在 或 空 Map)→ 权威槽回读 reconcile + 判定
105
- if (designIdArg ? !(hasSlots && slots.has(designIdArg)) : !hasSlots) {
106
- const rec = reconcileEngTokensFromSlot(parent)
107
- if (rec && rec !== slots) slots = rec
108
- }
109
- // F2d: both refusal branches carry the HELD id list — after a
110
- // persistence restore the parent has no digest to look the id up in; the error
111
- // list is the only discovery path (ids are not credentials — the token is).
112
- const size = slots instanceof Map ? slots.size : 0
113
- const heldIds = size > 0 ? [...slots.keys()].join(", ") : "(none)"
114
- if (designIdArg) {
115
- if (!(slots instanceof Map) || !slots.has(designIdArg)) {
116
- throw new Error(`designId not found — no approved design review holds this id. Run advisor with type='design' again and pass the designId echoed with the token. (session holds ${size} approved design slot(s); held design ids: ${heldIds})`)
117
- }
118
- return { token: slots.get(designIdArg) }
119
- }
120
- if (size > 1) {
121
- throw new Error(`Multiple approved designs in this session (${size}) — pass the designId parameter (echoed with each token) to choose which design this eng-coder spawn belongs to. Held design ids: ${heldIds}`)
122
- }
123
- if (size === 1) return { token: [...slots.values()][0] }
124
- throw designTokenRefusal("missing")
125
- }
126
-
127
94
  /**
128
95
  * consume-design 动作执行器(2026-09-07 token 链终消费制——ENGINEERING-MODE.md §2.6 F1):
129
96
  * 父侧验收核销时显式调用——读槽值 → removeDesignTokenSlot(移除该 designId 槽)→ 消费后同
@@ -181,16 +148,6 @@ export function prepareScheduling(parent, filesRaw, dependsRaw, wantAsync) {
181
148
  return { files, dependsOn, errorJson: null }
182
149
  }
183
150
 
184
- /** S4 写域行(AGENT-LOOP-SUBAGENT.md §6.26「写域行(S4)」):表头 + 逐条绝对路径 + 两句语义——
185
- * 本档局部纯函数(D23-9:不外提模块)。两句不可省:缺① 子代理读成「我只能写这些」⇒ 该写的漏掉;
186
- * 缺② 仍把任务书 §2 全文当成自己的改动面(本块的病因)。清单不截断——截断正是本块要消除的
187
- * 「看不见」。返回块文本(块间分隔由装配侧 `join("\n\n")` 施加)。 */
188
- function filesBlockOf(files) {
189
- return `Files declared for this spawn (the write domain this task declares, for scheduling):\n` +
190
- files.map((f) => `- ${f}`).join("\n") +
191
- `\n\nThis list is not an authorization boundary: touching a file outside it is allowed — report every out-of-list file you changed, with its reason. It is also not the whole change surface: other spawns on this task declare their own files, and what is listed here is your share only.`
192
- }
193
-
194
151
  /**
195
152
  * AGENT-LOOP-SUBAGENT.md §6.9 准入通过后的 child 装配(2026-09-05 module-split——自 execute 参数化提取,
196
153
  * 原 318-488 段 verbatim——语义零变)。副作用保留:relay 取号(sync 支 allocRelay——
@@ -201,7 +158,7 @@ function filesBlockOf(files) {
201
158
  export function buildSpawnChild(parent, ctx, args, role, wantAsync, files, dependsOn, engAuditAttempt) {
202
159
  // Provider/model override: tool `model` arg > subagentModels[role] > subagentModel > parent provider
203
160
  const childProvider = resolveChildProvider(parent, effectiveSubagentModel(parent, role, args.model))
204
- // 工程角色(任务书 = 批次档 §2,零任务书文本参数)——AGENT-LOOP-SUBAGENT.md §6.22.1。
161
+ // 工程角色(任务书 = 绑定批档,按角色切片(§8.1);零任务书文本参数)——AGENT-LOOP-SUBAGENT.md §6.22.1。
205
162
  const engineeringRole = isEngineeringRole(role)
206
163
 
207
164
  // ── batchDoc gate(ENGINEERING-MODE.md §2.12 + §2.15 D1——FR20 #9 机械面)────────
@@ -264,17 +221,54 @@ export function buildSpawnChild(parent, ctx, args, role, wantAsync, files, depen
264
221
  validateTaskBookParams(args, role)
265
222
  }
266
223
 
267
- // eng-coder token gate(TOOLS.md §6.25 ④):判定本体 = gateDesignToken(本档模块尾)——
268
- // missing / mismatch / expired / invalid 四态各出互异拒句;拒绝集合与旧三条件合取全等。
224
+ // AGENT-LOOP-SUBAGENT.md §8.1:任务书**正文**进 system 固块(§8.2 收集序首块)——spawn 当刻读一次批档
225
+ // 并冻结,此后改动不回流(快照语义);切片与块文本住 `./taskbook-block.mjs`,本处只做「读 + 收集」。
226
+ // 失效即拒:段切不出来(无对应段头)⇒ 拒发并点名路径与缺失段(拒文由构造器给出)——
227
+ // 退回只发指向句会让 §8.1 的承诺落空而无人知道。读不到走同一条拒因:batchDoc 门已判过可读,
228
+ // 这里只剩「读的那一刻文件不在了」,那不是可降级情形。
229
+ // 落点 = 任务书参数门之后、token 门之前(门序 §3.3:既有门的先后不变)。
230
+ let taskBookBlock = null
231
+ if (engineeringRole) {
232
+ let recordText
233
+ try {
234
+ recordText = readFileSync(batchDocAbs, "utf8")
235
+ } catch (e) {
236
+ throw new Error(`Task book unavailable — spawn refused: the batch record at ${batchDocAbs} could not be read at spawn time (${e?.message ?? e}); the ${role} task book is cut from it, so this spawn would have no authorized text. Restore the file and spawn again.`)
237
+ }
238
+ taskBookBlock = buildTaskBookBlock({ role, record: { path: batchDocAbs, text: recordText } })
239
+ }
240
+
241
+ // eng-coder token gate(TOOLS.md §6.25 ④⑤⑥):判定本体 = `./subagent-design-token.mjs` 的 `gateDesignToken`——
242
+ // missing / mismatch / expired / invalid / batch-mismatch / seal-mismatch / seal-unreadable 七态各出互异拒句;
243
+ // 前四态的拒绝集合与旧三条件合取全等。第三参 = 本函数上方 batchDoc 门已解析好的绝对路径
244
+ // (§10.1 的比较对象;本门不二次解析 `args.batchDoc`)。
269
245
  // 返回值 = 槽内令牌,必须落回 issuedToken:下方 `child._engDesignId` 回写依赖它。
270
246
  let issuedToken
271
- if (role === "eng-coder") issuedToken = gateDesignToken(parent, args)
247
+ if (role === "eng-coder") issuedToken = gateDesignToken(parent, args, { batchDocAbs })
248
+
249
+ // ── B7(TOOLS.md §6.29 B7):eng-designer 的勘察预算计数 ──────────────────────────
250
+ // 计的是**设计席发起的勘察**(`parent._role === "eng-designer"` 且本 spawn 的 role = explore),
251
+ // 不是设计师自己的被派次数——模型面承诺的是「≤6 explore spawns per batch」。
252
+ // 判据序(设计档原话「先完成角色、同步方式与 batchDoc 准入再计数」):角色/同步两道门在
253
+ // `gateEngCoderSpawn`(调用方,本函数之前已过);本角色的 batchDoc 绑定在设计师自己那一次 spawn
254
+ // 就过完了门(`parent._batchDoc`);任务书门在本函数上方 ⇒ 到此处仍未拒的 spawn 才占额度。
255
+ // 载体 = depth-0 根 agent 的独立 Map(K5:挂一次性 designer child 上会在 fix respawn 归零)。
256
+ if (role === "explore" && parent?._role === "eng-designer" && parent._batchDoc) {
257
+ chargeDesignerSurveySpawn(rootAgentOf(parent), parent._batchDoc)
258
+ }
259
+
260
+ // ── B8(TOOLS.md §6.29 ④):eng 两角色的限量父历史 ────────────────────────────────
261
+ // 绑定的是**父会话**(depth-0 根 agent)与**本批起点**;未绑定角色(explore/plan/coder/tester/consult)
262
+ // 一个新历史工具都拿不到(K7:新工具解决不了「没有 _batchDoc 时范围怎么定」)。
263
+ if (engineeringRole) recordBatchHistoryStart(rootAgentOf(parent), batchDocAbs, Date.now())
272
264
 
273
265
  // Filter tool set by role: explore/plan are read-only (plan is a planning agent, its deliverable is the plan itself)
274
266
  let tools
275
267
  if (role === "explore" || role === "plan") {
276
- const allowed = readonlyToolNames(parent.tools)
277
- tools = parent.tools.filter((t) => allowed.has(t.name))
268
+ // B4(TOOLS.md §6.29):整把只读集 ∪ action 级只读变体——旧形只认 `t.readonly`,`git` / `memory` /
269
+ // `settings` / `process` 整把不是只读,于是它们的只读动作在只读角色里一起消失(需求 B4 的直接病因)。
270
+ // 判据单源 = 运行期 `readonlyActionOf`(经 `readonlyActionTest` 适配)——不另写一份只读动作名单。
271
+ tools = deriveReadonlyTools(parent.tools, readonlyActionTest)
278
272
  } else if (role === "tester") {
279
273
  // tester = the THIRD tool face (AGENT-LOOP-SUBAGENT.md §6.59.2 ④): read-only set ∪ {execute, bash},
280
274
  // minus {verify, advisor}.
@@ -330,7 +324,7 @@ export function buildSpawnChild(parent, ctx, args, role, wantAsync, files, depen
330
324
  // 场景映射落到 assemblePrompt("eng-coder"/"eng-designer")(persona-{role} + common +
331
325
  // discipline-engineering);designer 也必须 engineering=true 才能装配工程纪律槽。
332
326
  const childConfig = engineeringRole
333
- ? { ...parent.config, agent: { ...parent.config.agent, engineering: true } }
327
+ ? { ...parent.config, agent: { ...parent.config.agent, mode: "engineering", engineering: true } }
334
328
  : parent.config
335
329
 
336
330
  const child = createAgent({
@@ -377,21 +371,24 @@ export function buildSpawnChild(parent, ctx, args, role, wantAsync, files, depen
377
371
  // 审计/探索("status 里这个文件算不算超清单?")。注入分支整体删除(B 方案
378
372
  // git 只读变体亦随裁定废弃——D-AG5)。顶层主 agent 注入保留(§3 prepareRun——
379
373
  // setup.mjs depth===0——D-AG7 范围边界)。
380
- // §6.22.2 子代理任务输入:工程角色 `input` = 一行机械任务书行(批档绝对路径 + §2 指向句)——
381
- // 任务书本体由子代理自读 §2(KD-SC5:运行时不抽取正文注入,避免过期副本 / 脆标题解析);
374
+ // §6.22.2 子代理任务输入:工程角色 `input` = 一行机械任务书行(批档绝对路径 + 按角色的指向句);
375
+ // 任务书**正文**在 system 固块(§8.1),本行只指路(指向句文本住 `./taskbook-block.mjs`);
382
376
  // 非工程角色 = 既有拼装(context 前缀 + 任务书参数 + 可选 task——零变)。
383
377
  const input = engineeringRole
384
- ? `Task book: §2 of the batch record at ${batchDocAbs} — read it before acting; it is the only task channel for this spawn.`
378
+ ? taskBookPointerLine(role, batchDocAbs)
385
379
  : (args.context ? `Context:\n${args.context}\n\nTask:\n${taskBriefOf(args, role)}` : taskBriefOf(args, role))
386
380
  // 台账 #23(AGENT-LOOP-SUBAGENT.md §6.26 · D23-1):**spawn 级固定机制性指令改走 system 固块**——
387
381
  // 两处(批次档路径行 + 审计模板块)原随 user 首条下发,压缩把首条并入摘要即丢(长任务中后期
388
382
  // 既看不到批次档路径、也看不到审计模板 ⇒ 过度勘察的真病根);固块值在 child 生命周期内恒定
389
383
  // ⇒ run 内 system 前缀逐字节稳定(前缀缓存不破),且不在 `agent.history` 内 ⇒ 压缩结构上吞不掉。
390
- // 收集序 = 批次档行 → 审计块 → 写域行(S4,见下);空数组 ⇒ 不绑定(depth-0 / explore / plan /
391
- // consult 的 system 逐字节同改前——§6.26 缓存契约兼容证明)。
384
+ // 收集序 = 任务书正文(§8.2)→ 批次档行 → 审计块 → 写域行(S4,见下)→ 文档坐标行(S5,见下);
385
+ // 空数组 ⇒ 不绑定(depth-0 不进本函数、system 逐字节同改前——§6.26 缓存契约兼容证明)。
386
+ // S5 与角色无关 ⇒ explore ∥ plan 的子代理也会带上它;它随本项目 manifest 声明而定、与 spawn 参数无关,同一 child 终身不变。
392
387
  const spawnBlocks = []
388
+ // §8.1 任务书正文(§8.2 收集序首块):仅工程角色携带,已按角色切片(eng-coder = §2、eng-designer = §1 + §2)。
389
+ if (taskBookBlock) spawnBlocks.push(taskBookBlock)
393
390
  // §2.11 第 1 点(FR16 载体 + FR17 铁律 #5 的机械面):批次档**绝对路径**下发给工程角色
394
- // (eng-coder 实现 / eng-designer 写稿)——任务书本体 = 本档 §2;本行让子代理"拿到本档路径"。
391
+ // (eng-coder 实现 / eng-designer 写稿)——任务书正文就在上方那块;本行让子代理“拿到本档路径”(改写前回读磁盘用)。
395
392
  // 工程角色恒注入;携绑定 coder(§4.16)随绑定注入(绑定 coder 要能读到本档)。
396
393
  if (batchBound) spawnBlocks.push(`Batch record (batchDoc): ${batchDocAbs}`)
397
394
  // AGENT-LOOP-SUBAGENT.md §6.7.6 D-E2 ③ + §6.22 KD-SC6:审计 spawn 的范围证据 = 机械跟踪的
@@ -401,8 +398,13 @@ export function buildSpawnChild(parent, ctx, args, role, wantAsync, files, depen
401
398
  // §6.26「写域行(S4)」:`files`(本 spawn 的预期写域,`prepareScheduling` 已归一化)非空 ⇒ 追加
402
399
  // 一格——写域此前只有调度器知道,子代理只能猜自己的改动面;空 / 未传 ⇒ 不推块,system 逐字节同改前。
403
400
  if (files.length > 0) spawnBlocks.push(filesBlockOf(files))
401
+ // §6.61「子代理文档坐标行(S5)」:本项目声明的三层文档坐标一行随 system 面下发。子代理此前也读得到
402
+ // `docRoot`(`manifestReadTool` 按需主动读),但那得先想到坐标记在 manifest 里、再知道键名——本行把
403
+ // 答案在 spawn 时就放进 system 面,省掉的只是那一趟(出口零新解析)。读不出 ⇒ 不推块。
404
+ const docsBlock = docsCoordinatesBlockOf(parent.cwd)
405
+ if (docsBlock) spawnBlocks.push(docsBlock)
404
406
  // The child's own task input rides the child object: D23-6 —— `_engTaskInput` 语义 = **一行机械
405
- // 任务书行**(批档绝对路径 + §2 指向句;不含固块)。
407
+ // 任务书行**(批档绝对路径 + 按角色的指向句;不含固块——正文在 system 面)。
406
408
  if (engineeringRole) child._engTaskInput = input
407
409
  // spawn 固块单点绑定(sync / async 同点——buildSpawnChild 唯一调用点):此后只读 ⇒ 同一
408
410
  // child 的任意 run(resume 续跑 / 报告追问重跑)逐字节恒定;消费点 = 核 `prepareRun`。
@@ -412,7 +414,7 @@ export function buildSpawnChild(parent, ctx, args, role, wantAsync, files, depen
412
414
  // pipeline (AGENT-LOOP-SUBAGENT.md §6.7.2 D3). Prefix includes a unique id: parallel child agents
413
415
  // with the same role stay independent and don't overwrite each other.
414
416
  // Format: role#id/ → onToken("coder#2/writing..."), onToolCall("coder#2/read", args)
415
- // Async id allocation (AGENT-LOOP-SUBAGENT.md §6.7.3 D-A1): reserve the relay counter at
417
+ // Async id allocation (AGENT-LOOP-SUBAGENT.md §6.7.3): reserve the relay counter at
416
418
  // spawn time — the returned id must be stable while the item sits in the queue.
417
419
  // The [model] token (TUI block creation) is DEFERRED to actual start so queued
418
420
  // children don't paint an empty panel block ("queued 态不显示").
@@ -441,34 +443,12 @@ export function buildSpawnChild(parent, ctx, args, role, wantAsync, files, depen
441
443
  ...wrapChildCallbacks(relayPrefix, ctx.callbacks),
442
444
  }
443
445
  const childRunOpts = buildChildRunOpts(ctx)
446
+ // B8(TOOLS.md §6.29 ④):eng 两角色各挂一枚**本批窗口**的受限 `read_history`(同名工具、
447
+ // 经 extraTools 注入——装配面在 `agent/setup.mjs` 的 `extraTools` 段)。未绑定角色不挂(K7)。
448
+ if (engineeringRole) childRunOpts.extraTools = [makeBatchHistoryTool(rootAgentOf(parent), batchDocAbs)]
444
449
  return { child, input, childOpts, childRunOpts, relayPrefix, childProvider }
445
450
  }
446
-
447
- // ── design-token 门(TOOLS.md §6.25 ③④——四态互异拒句;拒绝集合与旧三条件合取全等) ──
448
-
449
- /** 四态拒句(逐字 = TOOLS.md §6.25 ③):missing / mismatch / expired / invalid。
450
- * mismatch 可携 designId(非凭证);四句均零令牌值回显。 */
451
- export function designTokenRefusal(kind, designId) {
452
- if (kind === "missing") return new Error("designToken missing — the eng-coder spawn is refused: no usable token for an approved design slot came with this spawn. Pass the designToken parameter with the exact value from the subagent action:'design-slots' row (the text after designToken=), copied verbatim; if that list is empty, no design review has been approved in this session yet — run advisor with type='design' first. No token value is echoed here.")
453
- if (kind === "mismatch") return new Error("designToken mismatch — the eng-coder spawn is refused: the value passed does not equal the token held for this design slot. Re-read the subagent action:'design-slots' row and pass the value after designToken= verbatim, unchanged. No token value is echoed here." + (designId ? ` (designId: ${designId})` : ""))
454
- if (kind === "expired") return new Error("designToken expired — the eng-coder spawn is refused: the token matches this design slot but is past its TTL. The expired slot has been removed; run advisor with type='design' again on the current design and pass the newly issued token — an expired authorization cannot be retried. No token value is echoed here.")
455
- return new Error("designToken invalid — the eng-coder spawn is refused: the value passed equals this design slot's stored token, but that stored value is not a well-formed token, so no expiry can be judged and the slot was left in place. Run advisor with type='design' to issue a fresh token for this design; a malformed record never passes the gate. No token value is echoed here.")
456
- }
457
-
458
- /** eng-coder spawn 的令牌门(TOOLS.md §6.25 ④):resolveDesignSlot 的既有两条 designId
459
- * 诊断零改 → 参数在场 → 值相等 → 值有效。槽删除只在 tokenExpired(given) 成立时发生
460
- * (D-R16c ③);mismatch / invalid 不删槽(T-R16d)。返回槽内令牌(调用方回写 designId
461
- * 依赖它);sync / async 两路共经 buildSpawnChild——一处判定双路生效。 */
462
- export function gateDesignToken(parent, args) {
463
- const issuedToken = resolveDesignSlot(parent, args?.designId).token
464
- // 非字符串 ⇒ 空串 ⇒ missing(本意——T9 锁定)
465
- const given = typeof args?.designToken === "string" ? args.designToken : ""
466
- if (!issuedToken || !given.trim()) throw designTokenRefusal("missing")
467
- if (given !== issuedToken) throw designTokenRefusal("mismatch", args?.designId)
468
- if (!validateDesignToken(given)) {
469
- const expired = tokenExpired(given)
470
- if (expired) removeDesignTokenSlot(parent, args?.designId, given)
471
- throw designTokenRefusal(expired ? "expired" : "invalid")
472
- }
473
- return issuedToken
474
- }
451
+ // 设计令牌门(七态拒句 ∥ eng-coder spawn 的令牌判定)已搬 `./subagent-design-token.mjs`(分拆落点 =
452
+ // `docs/core/design/PATH-RESOLUTION.md` §3 末条);本档**原样再导出**其导出面 ⇒ `subagent.mjs` 的再导出行与
453
+ // 用例的 import 行零改。
454
+ export { designTokenRefusal, gateDesignToken, resolveDesignSlot } from "./subagent-design-token.mjs"
@@ -157,12 +157,12 @@ export const subagentTool = {
157
157
  scope: { type: "string", description: "REQUIRED for role='explore'/'plan'/'coder'/'tester' (non-engineering task book, the fifth parameter): scope & forbidden scope — what to read / search and what not to touch." },
158
158
  acceptance: { type: "string", description: "REQUIRED for role='explore'/'plan'/'coder'/'tester' (non-engineering task book): acceptance criteria — machine-verifiable (commands / thresholds / assertion counts)." },
159
159
  reportFormat: { type: "string", description: "REQUIRED for role='explore'/'plan'/'coder'/'tester' (non-engineering task book): the delivery-report format the child must produce." },
160
- async: { type: "boolean", description: "action:'spawn'/'escalate': default at depth 0 = true (async; the report arrives automatically); depth>0 always sync. async:false forces the blocking flight." },
160
+ async: { type: "boolean", description: "Required: `true` = async spawn (report via the auto channel); `false` = blocking; omitting it is refused. At depth>0 every spawn is synchronous — an explicit `async: true` there is refused. action:'escalate' keeps its own form: omission there still means the async flight, and `false` asks for the blocking one." },
161
161
  files: { type: "array", items: { type: "string" }, description: "action:'spawn' only: the file write-domain this task declares — file-level paths only (cwd-relative or absolute; directories rejected — they bypass the conflict detector). Overlapping-file tasks serialize automatically. Omit = no conflict detection." },
162
162
  dependsOn: { type: "array", items: { type: "string" }, description: "action:'spawn' only: ids from prior async returns whose outcome this task needs — queues until every dependency settles, then starts. Consumed ids count as satisfied; a cancelled/failed dependency stays queued marked 'dependency cancelled' until you decide (AUTO sessions auto-start). Unknown ids error." },
163
163
  id: { type: "string", description: "action:'status'/'observe'/'send'/'cancel': the subagent id from the spawn return. status: omit = pool overview; observe/send/cancel: REQUIRED." },
164
164
  message: { type: "string", description: "action:'send' only (REQUIRED there): the direction to inject — consumed by the running child at its next turn boundary as an ordinary instruction (non-interrupting)." },
165
- recent: { type: "integer", description: "action:'observe' only (optional, default 5): how many recent-turn summaries (1..20)." },
165
+ recent: { type: "integer", description: "Required for action:'observe': how many recent-turn summaries (1..20)" },
166
166
  },
167
167
  required: [],
168
168
  },
@@ -224,17 +224,18 @@ export const subagentTool = {
224
224
  // schema), so the mechanical check lives here: an absent task would otherwise
225
225
  // flow downstream as `content: undefined` and surface as an obscure error.
226
226
  // 载体判据:**非工程角色** = 结构化参数(拼装后非空)——task 只作补充;两者皆缺 ⇒ 此处先拒。
227
- // 工程角色 = 无任务书文本参数(任务书 = 批次档 §2):此处不判——自由文本键由
227
+ // 工程角色 = 无任务书文本参数(任务书 = 绑定批档,按角色切片(§8.1)):此处不判——自由文本键由
228
228
  // buildSpawnChild 的任务书门键在场即拒并点名(空集拼装不得误报「缺任务书」)。
229
229
  if (!isEngineeringRole(args.role) && !composeTaskBookBrief(args, args.role) && (typeof args.task !== "string" || !args.task.trim())) {
230
- throw new Error("subagent action:'spawn' requires the structured task-book parameters for non-engineering roles (explore / plan / coder / tester) (four core: goal / knownFacts / acceptance / reportFormat + scope) — a free-text task alone is not the brief. Engineering roles take no task-book text parameters: their task book is batch record §2.")
230
+ throw new Error("subagent action:'spawn' requires the structured task-book parameters for non-engineering roles (explore / plan / coder / tester) (four core: goal / knownFacts / acceptance / reportFormat + scope) — a free-text task alone is not the brief. Engineering roles take no task-book text parameters: their task book is the bound batch record (batchDoc), sliced per role into the spawn system block.")
231
231
  }
232
- // §18 D-E1a depth-gated async default (2026-09-06 需求池 R12): depth-0 spawns
233
- // default to async for EVERY role (the old role-level default — eng-coder only —
234
- // is superseded); depth>0 spawns default to sync (子代理内部强制同步现状保留).
235
- // async:false remains the explicit escape hatch; async:true at depth>0 is
236
- // refused downstream (executeAsyncSpawn top-level gate).
237
- const wantAsync = args.async ?? ((ctx.depth ?? 0) === 0)
232
+ // §18 D-E1a(必填化——2026-11-07 批 tool-param-zero-defaults):`recent` ∥ `async` 皆必填;
233
+ // depth 不再替调用方选(旧形 `args.async ?? depth === 0` 已撤)。depth>0 无异步——显式
234
+ // `async:true` 下游拒(`async spawn only available at the top level`);`async:false` 仍是阻塞飞行的显式形。
235
+ if (args.async !== true && args.async !== false) {
236
+ throw new Error("subagent: async is required — pass true for an async spawn or false for a blocking flight")
237
+ }
238
+ const wantAsync = args.async
238
239
 
239
240
  // Role normalization + whitelist (2026-08-25, coder-leak fix): exact-string gates let
240
241
  // variant roles ("Coder", " coder") bypass BOTH mode gates and fall through to