@thincoder/core 0.11.1 → 0.11.3

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 (382) hide show
  1. package/CHANGELOG.md +64 -2
  2. package/advisor/compaction.mjs +7 -5
  3. package/advisor/convergence.mjs +34 -3
  4. package/advisor/history.mjs +24 -11
  5. package/advisor/loop.mjs +49 -12
  6. package/advisor/messages.mjs +114 -33
  7. package/advisor/project-context.mjs +171 -42
  8. package/advisor/run.mjs +24 -10
  9. package/advisor.mjs +36 -46
  10. package/agent/batch-attribution.mjs +87 -0
  11. package/agent/batch-changed-surface.mjs +129 -0
  12. package/agent/chat-call.mjs +14 -9
  13. package/agent/completion.mjs +70 -41
  14. package/agent/continue-decision.mjs +14 -8
  15. package/agent/digest-account.mjs +133 -59
  16. package/agent/dispatch-gates.mjs +6 -0
  17. package/agent/dispatch-run.mjs +1 -1
  18. package/agent/dispatch.mjs +10 -4
  19. package/agent/family-tools.mjs +37 -23
  20. package/agent/helpers.mjs +139 -73
  21. package/agent/image-heal.mjs +18 -4
  22. package/agent/offload.mjs +25 -29
  23. package/agent/post-turn.mjs +36 -35
  24. package/agent/record-results.mjs +39 -7
  25. package/agent/run-stages.mjs +132 -52
  26. package/agent/run-start.mjs +150 -78
  27. package/agent/setup-reminders.mjs +194 -91
  28. package/agent/setup.mjs +219 -140
  29. package/agent/spawn-child.mjs +40 -3
  30. package/agent/suspension.mjs +43 -15
  31. package/agent/timers.mjs +9 -4
  32. package/agent/turn-domain-text.mjs +105 -0
  33. package/agent/turn-loop.mjs +84 -27
  34. package/agent/turn-projection.mjs +286 -0
  35. package/agent/turn-task-state.mjs +274 -0
  36. package/agent/turn-tool-process.mjs +163 -0
  37. package/agent/write-gate-ledger.mjs +569 -0
  38. package/agent/write-gate.mjs +29 -352
  39. package/agent-tools/advisor-async.mjs +35 -172
  40. package/agent-tools/advisor-launch.mjs +178 -0
  41. package/agent-tools/advisor-settle.mjs +28 -1
  42. package/agent-tools/advisor.mjs +37 -48
  43. package/agent-tools/async-discard.mjs +7 -2
  44. package/agent-tools/async-settle.mjs +18 -12
  45. package/agent-tools/audit-block.mjs +6 -6
  46. package/agent-tools/bash-async.mjs +5 -2
  47. package/agent-tools/batch-closeout.mjs +223 -35
  48. package/agent-tools/batch-gate.mjs +142 -342
  49. package/agent-tools/batch-ledger-bind.mjs +240 -20
  50. package/agent-tools/batch-ledger-view.mjs +109 -0
  51. package/agent-tools/batch-lifecycle.mjs +197 -48
  52. package/agent-tools/batch-paths.mjs +29 -8
  53. package/agent-tools/batch-read.mjs +151 -4
  54. package/agent-tools/batch-record-write.mjs +417 -0
  55. package/agent-tools/batch-regions.mjs +215 -0
  56. package/agent-tools/batch-reopen.mjs +23 -11
  57. package/agent-tools/batch-segment-vocab.mjs +459 -0
  58. package/agent-tools/batch-skeleton.mjs +196 -239
  59. package/agent-tools/batch-supersede.mjs +232 -0
  60. package/agent-tools/batch-tier-gate.mjs +214 -0
  61. package/agent-tools/batch.mjs +192 -439
  62. package/agent-tools/browser-async.mjs +5 -2
  63. package/agent-tools/consult.mjs +17 -11
  64. package/agent-tools/context.mjs +76 -33
  65. package/agent-tools/design-review-record.mjs +225 -0
  66. package/agent-tools/design-slots.mjs +1 -1
  67. package/agent-tools/design-token.mjs +279 -81
  68. package/agent-tools/digest-budget.mjs +10 -9
  69. package/agent-tools/doc-check.mjs +43 -33
  70. package/agent-tools/doc-graph.mjs +140 -0
  71. package/agent-tools/eng.mjs +12 -12
  72. package/agent-tools/escalate-async.mjs +5 -5
  73. package/agent-tools/goal.mjs +5 -2
  74. package/agent-tools/judge-domain.mjs +347 -0
  75. package/agent-tools/manifest.mjs +34 -18
  76. package/agent-tools/parent-channel.mjs +6 -3
  77. package/agent-tools/plan.mjs +11 -10
  78. package/agent-tools/read-history.mjs +112 -11
  79. package/agent-tools/review-facts.mjs +19 -6
  80. package/agent-tools/settings.mjs +23 -2
  81. package/agent-tools/skill.mjs +7 -8
  82. package/agent-tools/spawn-gates.mjs +14 -24
  83. package/agent-tools/ssh-session.mjs +8 -5
  84. package/agent-tools/ssh-text.mjs +155 -0
  85. package/agent-tools/ssh-transfer.mjs +1 -1
  86. package/agent-tools/ssh-transport.mjs +19 -148
  87. package/agent-tools/subagent-actions-query.mjs +10 -6
  88. package/agent-tools/subagent-actions.mjs +2 -2
  89. package/agent-tools/subagent-async.mjs +19 -17
  90. package/agent-tools/subagent-brief.mjs +76 -0
  91. package/agent-tools/subagent-design-token.mjs +168 -0
  92. package/agent-tools/subagent-run.mjs +1 -1
  93. package/agent-tools/subagent-scheduler.mjs +13 -13
  94. package/agent-tools/subagent-spawn.mjs +92 -112
  95. package/agent-tools/subagent.mjs +16 -28
  96. package/agent-tools/task.mjs +0 -8
  97. package/agent-tools/taskbook-block.mjs +94 -0
  98. package/agent-tools/timer.mjs +12 -8
  99. package/agent-tools/verify.mjs +13 -4
  100. package/agent-tools.mjs +7 -3
  101. package/agent.mjs +26 -7
  102. package/attachments.mjs +3 -3
  103. package/auto-think.mjs +5 -2
  104. package/browser/actions.mjs +9 -3
  105. package/browser/cdp.mjs +45 -17
  106. package/browser/launch.mjs +25 -43
  107. package/browser/pool.mjs +299 -0
  108. package/browser/queue.mjs +2 -0
  109. package/browser/session-state.mjs +450 -0
  110. package/browser/session.mjs +127 -151
  111. package/browser/snapshot.mjs +89 -0
  112. package/client-identity.mjs +1 -1
  113. package/compaction-work-state.mjs +230 -0
  114. package/compress-form.mjs +41 -6
  115. package/config-defaults.mjs +7 -3
  116. package/config-migrate.mjs +40 -0
  117. package/config-normalize.mjs +28 -2
  118. package/config-reload.mjs +59 -0
  119. package/config.mjs +110 -110
  120. package/context-degrade.mjs +93 -34
  121. package/context-echo.mjs +6 -15
  122. package/context-push.mjs +328 -31
  123. package/context.mjs +298 -170
  124. package/conventions.mjs +11 -9
  125. package/declaration.mjs +126 -22
  126. package/declared-repos.mjs +94 -0
  127. package/doc-check/doc-names.mjs +73 -0
  128. package/doc-check/doc-tokens.mjs +110 -0
  129. package/doc-check/existence.mjs +160 -0
  130. package/doc-check/index.mjs +309 -213
  131. package/doc-check/line-refs.mjs +27 -101
  132. package/doc-check/paragraph.mjs +218 -102
  133. package/doc-graph/anchors.mjs +474 -0
  134. package/doc-graph/doc-batch-face.mjs +59 -0
  135. package/doc-graph/doc-suffix.mjs +27 -0
  136. package/doc-graph/graph-tokens.mjs +160 -0
  137. package/doc-graph.mjs +778 -0
  138. package/escape.mjs +6 -5
  139. package/explore-distill.mjs +41 -8
  140. package/generate-title.mjs +10 -1
  141. package/i18n.mjs +1 -1
  142. package/instance-inbox-watch.mjs +272 -0
  143. package/instance-inbox.mjs +218 -0
  144. package/instance-registry.mjs +179 -0
  145. package/knowledge/README.md +3 -0
  146. package/knowledge/prompt-resources.md +10 -0
  147. package/ledger-close-proof.mjs +100 -49
  148. package/ledger-close.mjs +188 -0
  149. package/ledger-cmd.mjs +47 -91
  150. package/ledger-consistency.mjs +113 -0
  151. package/ledger-db.mjs +47 -15
  152. package/ledger-executors.mjs +1 -1
  153. package/ledger-tools.mjs +121 -62
  154. package/ledger-write-ops.mjs +162 -46
  155. package/ledger.mjs +1 -1
  156. package/manifest-discovery.mjs +3 -1
  157. package/manifest-schema.mjs +27 -5
  158. package/memory/docs.mjs +51 -15
  159. package/memory/file-list.mjs +6 -0
  160. package/memory/schema.mjs +2 -2
  161. package/model-specs.mjs +87 -21
  162. package/origin-guard.mjs +190 -0
  163. package/package.json +3 -1
  164. package/path-resolve.mjs +338 -57
  165. package/prompt-files.mjs +114 -2
  166. package/prompt-overlays.mjs +21 -11
  167. package/prompts/advisor-design.md +96 -36
  168. package/prompts/advisor-round1.md +48 -4
  169. package/prompts/advisor-round2.md +54 -10
  170. package/prompts/advisor-round3.md +53 -9
  171. package/prompts/common.md +99 -434
  172. package/prompts/consult-base.md +7 -4
  173. package/prompts/discipline-engineering.md +504 -295
  174. package/prompts/discipline-normal.md +106 -281
  175. package/prompts/knowledge/business-gates.md +30 -0
  176. package/prompts/knowledge/decision-quality.md +21 -0
  177. package/prompts/knowledge/doc-lookup.md +30 -0
  178. package/prompts/knowledge/document-writing.md +33 -0
  179. package/prompts/knowledge/documentation-evaluation.md +48 -0
  180. package/prompts/knowledge/evidence-discipline.md +38 -0
  181. package/prompts/knowledge/normal-coding-workflow.md +110 -0
  182. package/prompts/knowledge/normal-delivery-collaboration.md +124 -0
  183. package/prompts/knowledge/normal-work-management.md +60 -0
  184. package/prompts/knowledge/product-security.md +28 -0
  185. package/prompts/knowledge/project-records.md +73 -0
  186. package/prompts/knowledge/tool-advisor.md +29 -0
  187. package/prompts/knowledge/tool-apply-patch.md +17 -0
  188. package/prompts/knowledge/tool-bash.md +48 -0
  189. package/prompts/knowledge/tool-batch-eng-coder.md +19 -0
  190. package/prompts/knowledge/tool-batch-eng-designer.md +20 -0
  191. package/prompts/knowledge/tool-batch-review.md +18 -0
  192. package/prompts/knowledge/tool-batch.md +94 -0
  193. package/prompts/knowledge/tool-browser.md +68 -0
  194. package/prompts/knowledge/tool-code-search.md +4 -0
  195. package/prompts/knowledge/tool-consult-start.md +12 -0
  196. package/prompts/knowledge/tool-consult-stop.md +6 -0
  197. package/prompts/knowledge/tool-context.md +6 -0
  198. package/prompts/knowledge/tool-delete.md +21 -0
  199. package/prompts/knowledge/tool-doc-check.md +71 -0
  200. package/prompts/knowledge/tool-doc-graph-read.md +20 -0
  201. package/prompts/knowledge/tool-doc-graph.md +49 -0
  202. package/prompts/knowledge/tool-doc-search.md +6 -0
  203. package/prompts/knowledge/tool-edit.md +41 -0
  204. package/prompts/knowledge/tool-eng.md +2 -0
  205. package/prompts/knowledge/tool-execute.md +21 -0
  206. package/prompts/knowledge/tool-fetch.md +18 -0
  207. package/prompts/knowledge/tool-file-ops.md +21 -0
  208. package/prompts/knowledge/tool-get-current-time.md +7 -0
  209. package/prompts/knowledge/tool-git-read.md +21 -0
  210. package/prompts/knowledge/tool-git.md +29 -0
  211. package/prompts/knowledge/tool-glob.md +17 -0
  212. package/prompts/knowledge/tool-goal.md +8 -0
  213. package/prompts/knowledge/tool-grep.md +21 -0
  214. package/prompts/knowledge/tool-hashline-edit.md +16 -0
  215. package/prompts/knowledge/tool-insert-after.md +17 -0
  216. package/prompts/knowledge/tool-instance-list.md +6 -0
  217. package/prompts/knowledge/tool-instance-send.md +10 -0
  218. package/prompts/knowledge/tool-knowledge.md +18 -0
  219. package/prompts/knowledge/tool-ledger-read.md +28 -0
  220. package/prompts/knowledge/tool-ledger.md +46 -0
  221. package/prompts/knowledge/tool-lint.md +16 -0
  222. package/prompts/knowledge/tool-ls.md +15 -0
  223. package/prompts/knowledge/tool-lsp.md +11 -0
  224. package/prompts/knowledge/tool-main-history.md +2 -0
  225. package/prompts/knowledge/tool-manifest-read.md +14 -0
  226. package/prompts/knowledge/tool-manifest.md +34 -0
  227. package/prompts/knowledge/tool-memory-read.md +20 -0
  228. package/prompts/knowledge/tool-memory.md +19 -0
  229. package/prompts/knowledge/tool-notify-parent.md +12 -0
  230. package/prompts/knowledge/tool-operations.md +102 -0
  231. package/prompts/knowledge/tool-peer-instances.md +2 -0
  232. package/prompts/knowledge/tool-plan.md +5 -0
  233. package/prompts/knowledge/tool-process-read.md +13 -0
  234. package/prompts/knowledge/tool-process.md +15 -0
  235. package/prompts/knowledge/tool-question.md +16 -0
  236. package/prompts/knowledge/tool-read-history-batch.md +22 -0
  237. package/prompts/knowledge/tool-read-history.md +35 -0
  238. package/prompts/knowledge/tool-read-image.md +11 -0
  239. package/prompts/knowledge/tool-read.md +22 -0
  240. package/prompts/knowledge/tool-recent-changes.md +6 -0
  241. package/prompts/knowledge/tool-repo-outline.md +4 -0
  242. package/prompts/knowledge/tool-settings-read.md +12 -0
  243. package/prompts/knowledge/tool-settings.md +17 -0
  244. package/prompts/knowledge/tool-skill.md +6 -0
  245. package/prompts/knowledge/tool-ssh.md +74 -0
  246. package/prompts/knowledge/tool-subagent.md +57 -0
  247. package/prompts/knowledge/tool-task.md +14 -0
  248. package/prompts/knowledge/tool-team-ledger-read.md +11 -0
  249. package/prompts/knowledge/tool-team-ledger.md +15 -0
  250. package/prompts/knowledge/tool-timer.md +23 -0
  251. package/prompts/knowledge/tool-tree.md +16 -0
  252. package/prompts/knowledge/tool-verify.md +19 -0
  253. package/prompts/knowledge/tool-wait-for.md +25 -0
  254. package/prompts/knowledge/tool-websearch.md +19 -0
  255. package/prompts/knowledge/tool-write.md +12 -0
  256. package/prompts/knowledge/upstream-protocol.md +45 -0
  257. package/prompts/persona-coder.md +1 -3
  258. package/prompts/persona-eng-coder.md +24 -6
  259. package/prompts/persona-eng-designer.md +150 -171
  260. package/prompts/persona-engineering.md +531 -442
  261. package/prompts/persona-explore.md +1 -3
  262. package/prompts/persona-normal.md +17 -9
  263. package/prompts/persona-plan.md +5 -3
  264. package/prompts/persona-tester.md +0 -2
  265. package/prompts/subagent-base.md +2 -2
  266. package/provider/anthropic.mjs +10 -6
  267. package/provider/core.mjs +8 -5
  268. package/provider/errors.mjs +63 -4
  269. package/provider/google.mjs +29 -10
  270. package/provider/reasoning-echo.mjs +16 -0
  271. package/provider/responses.mjs +7 -3
  272. package/provider/sse.mjs +11 -6
  273. package/provider-flows.mjs +2 -2
  274. package/rules.mjs +11 -10
  275. package/session-index-build.mjs +1 -1
  276. package/session-index-pass.mjs +1 -1
  277. package/session-index-query.mjs +1 -1
  278. package/session-index.mjs +1 -1
  279. package/session-lifecycle.mjs +131 -42
  280. package/session-slot-write.mjs +38 -6
  281. package/session.mjs +30 -11
  282. package/shell-identity.mjs +129 -22
  283. package/skip-dirs.mjs +26 -2
  284. package/team-ledger.mjs +34 -30
  285. package/text-budget.mjs +1 -1
  286. package/think-off.mjs +27 -0
  287. package/token-ttl.mjs +74 -5
  288. package/token-window.mjs +371 -47
  289. package/tool-docs/advisor.md +2 -27
  290. package/tool-docs/apply_patch.md +1 -15
  291. package/tool-docs/bash.md +2 -43
  292. package/tool-docs/batch-eng-coder.md +3 -0
  293. package/tool-docs/batch-eng-designer.md +3 -0
  294. package/tool-docs/batch-review.md +3 -0
  295. package/tool-docs/batch.md +2 -84
  296. package/tool-docs/browser.md +2 -49
  297. package/tool-docs/code_search.md +2 -2
  298. package/tool-docs/consult_start.md +2 -8
  299. package/tool-docs/consult_stop.md +2 -4
  300. package/tool-docs/context.md +1 -5
  301. package/tool-docs/delete.md +2 -17
  302. package/tool-docs/doc_check.md +2 -107
  303. package/tool-docs/doc_graph-read.md +3 -0
  304. package/tool-docs/doc_graph.md +3 -0
  305. package/tool-docs/doc_search.md +2 -4
  306. package/tool-docs/edit.md +1 -38
  307. package/tool-docs/eng.md +3 -1
  308. package/tool-docs/execute.md +2 -18
  309. package/tool-docs/fetch.md +2 -14
  310. package/tool-docs/file_ops.md +2 -18
  311. package/tool-docs/get_current_time.md +1 -6
  312. package/tool-docs/git-read.md +3 -0
  313. package/tool-docs/git.md +2 -35
  314. package/tool-docs/glob.md +2 -10
  315. package/tool-docs/goal.md +1 -6
  316. package/tool-docs/grep.md +2 -18
  317. package/tool-docs/hashline_edit.md +2 -15
  318. package/tool-docs/insert_after.md +2 -16
  319. package/tool-docs/instance_list.md +3 -0
  320. package/tool-docs/instance_send.md +3 -0
  321. package/tool-docs/knowledge.md +3 -0
  322. package/tool-docs/ledger-read.md +3 -0
  323. package/tool-docs/ledger.md +3 -8
  324. package/tool-docs/lint.md +2 -10
  325. package/tool-docs/ls.md +2 -11
  326. package/tool-docs/lsp.md +2 -9
  327. package/tool-docs/main_history.md +3 -1
  328. package/tool-docs/manifest-read.md +2 -8
  329. package/tool-docs/manifest.md +2 -35
  330. package/tool-docs/memory-read.md +3 -0
  331. package/tool-docs/memory.md +2 -20
  332. package/tool-docs/notify_parent.md +2 -13
  333. package/tool-docs/peer_instances.md +3 -1
  334. package/tool-docs/plan.md +1 -5
  335. package/tool-docs/process-read.md +3 -0
  336. package/tool-docs/process.md +2 -13
  337. package/tool-docs/question.md +3 -17
  338. package/tool-docs/read.md +2 -19
  339. package/tool-docs/read_history-batch.md +3 -0
  340. package/tool-docs/read_history.md +2 -18
  341. package/tool-docs/read_image.md +2 -9
  342. package/tool-docs/recent_changes.md +2 -2
  343. package/tool-docs/repo_outline.md +2 -2
  344. package/tool-docs/settings-read.md +3 -0
  345. package/tool-docs/settings.md +1 -12
  346. package/tool-docs/skill.md +2 -6
  347. package/tool-docs/ssh.md +1 -62
  348. package/tool-docs/subagent.md +2 -100
  349. package/tool-docs/task.md +1 -7
  350. package/tool-docs/team_ledger-read.md +3 -0
  351. package/tool-docs/team_ledger.md +3 -9
  352. package/tool-docs/timer.md +2 -19
  353. package/tool-docs/tree.md +2 -13
  354. package/tool-docs/verify.md +2 -12
  355. package/tool-docs/wait_for.md +2 -32
  356. package/tool-docs/websearch.md +2 -19
  357. package/tool-docs/write.md +2 -12
  358. package/tools/browser.mjs +54 -9
  359. package/tools/doc-write-gate.mjs +73 -0
  360. package/tools/edit-batch.mjs +170 -92
  361. package/tools/edit-diff.mjs +78 -62
  362. package/tools/edit-receipt.mjs +39 -0
  363. package/tools/execute.mjs +3 -3
  364. package/tools/file.mjs +28 -14
  365. package/tools/git.mjs +36 -21
  366. package/tools/index.mjs +6 -0
  367. package/tools/knowledge.mjs +143 -0
  368. package/tools/linter.mjs +3 -3
  369. package/tools/ops.mjs +5 -3
  370. package/tools/patch.mjs +124 -44
  371. package/tools/process-doc-mark.mjs +33 -4
  372. package/tools/repomap.mjs +25 -3
  373. package/tools/search.mjs +74 -26
  374. package/tools/shared.mjs +29 -27
  375. package/tools/ssh.mjs +5 -5
  376. package/tools/tree.mjs +32 -10
  377. package/tools/web-deepseek.mjs +1 -1
  378. package/tools/web.mjs +2 -2
  379. package/tools/write-gate-params.mjs +31 -0
  380. package/tools/write-path.mjs +16 -4
  381. package/window-policy.mjs +243 -0
  382. package/doc-check/anchors.mjs +0 -235
@@ -1,22 +1,26 @@
1
1
  /**
2
- * ssh-transport.mjs — SSH 传输面单点(askpass 链 ∥ 子进程 ∥ 沉降 ∥ 遮蔽 ∥ 输出帽)。
2
+ * ssh-transport.mjs — SSH 传输面单点(askpass 链 ∥ 子进程 ∥ 沉降 ∥ 输出帽)。
3
3
  * 设计 = `docs/core/design/TOOLS.md` §6.22(D-TO17/D-TO18 · 台账 #1436)。
4
4
  *
5
- * 拆档由 = 机制档触 500 顾问线(§6.22 落点表「触 500 顾问线 ⇒ 实施轮先审拆分」)——本档收**运行面**
5
+ * 拆档由 = 设计轮判定机制档改前读数过 500(`docs/core/design/DOC-GRAPH.md` §3「行数档位口径」)——本档收**运行面**
6
6
  * (与会话语义无关的传输原语),`ssh-session.mjs` 收**会话面**(池 / 生命周期 / 动作)。条目形
7
7
  * (entry)由 `ssh-session.mjs` 定义并持有;本档只经其字段工作(`buf` / `mask` / `_waiters` /
8
8
  * `promptRe` / `state` / `child` / `logStream` / `_notify` / `lastDataAt` / `bytes`)。
9
9
  *
10
+ * 2026-11-05 拆档族再切一刀:**可见文本面**(剥离 ∥ 归一 ∥ 遮蔽 ∥ 收场注记)搬进同目录叶档
11
+ * `ssh-text.mjs`——本档只留进程、计时、四门与输出面。
12
+ *
10
13
  * - askpass 链:包装档(Win `.cmd` ∥ POSIX `.sh` 0700)→ `tools/ssh-askpass.mjs` → stdout;秘密只经
11
14
  * ssh 子进程环境 `TC_SSH_SECRET`(零入参 / 零落盘 / 零回显;环境经 `nodeChildEnv` 单点补 Electron 旗标)。
12
15
  * - 终端噪声:有状态剥离(CSI ∥ OSC ∥ 单字符控制三类 + CRLF 归一;状态跨 chunk 携带)——落点 = 传输入口,
13
- * **先剥离后遮蔽**;日志面 = 模型面同源(D-TO23)。
16
+ * **先剥离后遮蔽**;日志面 = 模型面同源(D-TO23)。剥离器与遮蔽器本体住 `ssh-text.mjs`,本档 import 消费。
14
17
  * - 就绪判据:四门(待答标记 ∥ 提示符 ∥ 仍在吐 ∥ 硬超时 60 s);静默窗只作去抖(D-TO21)。
15
- * - 遮蔽:写入的秘密对**捕获面与日志面**做字面移除(比较面 = 同一归一 + 按不可见处切段 ≥ 4)。
18
+ * - 遮蔽:写入的秘密对**捕获面与日志面**做字面移除(比较面 = 同一归一 + 按不可见处切段 ≥ 4)——
19
+ * 实现住 `ssh-text.mjs` 的 `createMask`。
16
20
  * - 失败分类族(auth ∥ unreachable ∥ hostkey)照服务端 `src/sandbox/ssh.mjs` 同源判据。
17
21
  * 模块图:→ config.mjs(configDir 缺省)· tools/shared.mjs(解码)· text-budget.mjs(截断本体)·
18
- * tools/node-child.mjs(nodeChildEnv)· expand-home.mjs(`~` 展开单源——`identityFile` 用)——叶子向、无环
19
- * (本档不 import `ssh-session.mjs`)。
22
+ * tools/node-child.mjs(nodeChildEnv)· expand-home.mjs(`~` 展开单源——`identityFile` 用)·
23
+ * ssh-text.mjs(可见文本面)——叶子向、无环(本档不 import `ssh-session.mjs`)。
20
24
  */
21
25
  import { chmodSync, mkdirSync, unlinkSync, writeFileSync } from "node:fs"
22
26
  import { spawn } from "node:child_process"
@@ -26,6 +30,10 @@ import { expandHome } from "../expand-home.mjs"
26
30
  import { makeDecoder } from "../tools/shared.mjs"
27
31
  import { nodeChildEnv } from "../tools/node-child.mjs"
28
32
  import { capText as capBudgetText, fillMarker } from "../text-budget.mjs"
33
+ // 可见文本面(剥离 ∥ 归一 ∥ 遮蔽 ∥ 收场注记)2026-11-05 外移同目录叶档 `ssh-text.mjs`:体逐字搬家、
34
+ // 导出名零改——`ssh-session.mjs` / `ssh-transfer.mjs` / `ssh-vault.mjs` 的 import 行零改。
35
+ import { createStripper, createMask, escapeNote, normalizeText } from "./ssh-text.mjs"
36
+ export { createStripper, createMask, escapeNote, normalizeText }
29
37
 
30
38
  /** 静默窗(§6.22 ③):**只作去抖**——判尾部这半条标记到没到齐;不再单独构成「已就绪」。 */
31
39
  export const SSH_SETTLE_MS = 800
@@ -37,8 +45,6 @@ export const SSH_CONNECT_SETTLE_MS = 10_000
37
45
  export const SSH_RETURN_CAP = 8000
38
46
  /** 帽窗头尾比例(§6.22 ⑥:头 60% ∥ 尾 40%——头段装接口 / ACL,尾段装结束证据)。 */
39
47
  const CAP_HEAD_RATIO = 0.6
40
- /** 遮蔽分段下限(§6.22 ③「`≥ 4` 为选定策略值」:3 字符以下与正常输出撞面过高)。 */
41
- const MASK_SEG_MIN = 4
42
48
  /** 保活缺省(§6.22 ④:`ServerAliveInterval=30`;测试态时间缝按 ms 传入后换算)。 */
43
49
  export const SSH_KEEPALIVE_MS = 30_000
44
50
  /** 秘密环境变量名(§6.22 ②「秘密传递」行)。 */
@@ -113,138 +119,11 @@ export function buildSshArgs({ host, user, port, probe, identityFile = null, kee
113
119
  ]
114
120
  }
115
121
 
116
- // ─── 终端噪声(§6.22 ③「终端噪声」· D-TO23)────────────────────────────────
117
-
118
- /** 不可见处(遮蔽比较面的切段器——与剥离同一类目:CSI ∥ ESC+1 ∥ 任一控制字符)。 */
119
- const INVISIBLE_SPLIT = /\x1b\[[\x20-\x3f]*[\x40-\x7e]|\x1b[^\x1b]?|[\x00-\x1f\x7f]/
120
-
121
- /** 有状态剥离器(§6.22 ③):三类序列 CSI ∥ OSC ∥ 单字符控制 + `\r\n`∥裸 `\r` 归 `\n`。
122
- * 状态跨 chunk 携带(序列被 chunk 边界切开不残留成字面);三类之外的序列(DCS / APC 等)按
123
- * 单字符控制处理——头字节剥掉,体内字节当可见文本如实交出(设计「表外序列的出口」)。
124
- * `push` = 返回边界(状态保留);`end` = 收场(硬超时 ∥ close ∥ 会话终结:尾部半条序列丢弃并计一次)。 */
125
- export function createStripper() {
126
- let state = "ground" // ground ∥ esc ∥ csi ∥ osc ∥ oscEsc ∥ charset
127
- let pendingCr = false // chunk 尾的 `\r`(下一片首字为 `\n` ⇒ 仍归一条——跨 chunk 的 CRLF)
128
- const scan = (text) => {
129
- const s = String(text ?? "")
130
- let out = ""
131
- let i = 0
132
- while (i < s.length) {
133
- const ch = s[i]
134
- if (pendingCr) {
135
- pendingCr = false
136
- out += "\n"
137
- if (ch === "\n") { i += 1; continue }
138
- }
139
- if (state === "esc") {
140
- state = "ground"
141
- if (ch === "[") state = "csi"
142
- else if (ch === "]") state = "osc"
143
- else if (ch === "(" || ch === ")" || ch === "*" || ch === "+") state = "charset"
144
- else if (ch === "\x1b") state = "esc"
145
- i += 1
146
- continue
147
- }
148
- if (state === "charset") { state = "ground"; i += 1; continue } // `ESC ( 0` 字符集指定(既有覆盖不回归)
149
- if (state === "csi") {
150
- const c = ch.charCodeAt(0)
151
- if (c >= 0x20 && c <= 0x3f) { i += 1; continue } // 参数 ∥ 中间字节
152
- if (c >= 0x40 && c <= 0x7e) { state = "ground"; i += 1; continue } // 终字节
153
- state = "ground" // 类外字 ⇒ 序列作废,本字按常规面重判(不吞可见字节)
154
- continue
155
- }
156
- if (state === "osc") {
157
- if (ch === "\x07") { state = "ground"; i += 1; continue }
158
- if (ch === "\x1b") { state = "oscEsc"; i += 1; continue }
159
- i += 1
160
- continue
161
- }
162
- if (state === "oscEsc") {
163
- state = "ground"
164
- if (ch === "\\") { i += 1; continue } // `ESC \` = ST
165
- state = "osc" // 非 ST ⇒ 本字仍在 OSC 体内(ESC 已丢弃,体内字节本就要丢)
166
- continue
167
- }
168
- if (ch === "\x1b") { state = "esc"; i += 1; continue }
169
- if (ch === "\r") {
170
- if (i + 1 >= s.length) { pendingCr = true; i += 1; continue }
171
- out += "\n"
172
- i += s[i + 1] === "\n" ? 2 : 1
173
- continue
174
- }
175
- if (ch === "\n" || ch === "\t") { out += ch; i += 1; continue }
176
- const code = ch.charCodeAt(0)
177
- if (code < 0x20 || code === 0x7f) { i += 1; continue } // BEL ∥ 退格 ∥ 其余 C0(保留 `\n` / `\t`)
178
- out += ch
179
- i += 1
180
- }
181
- return out
182
- }
183
- return {
184
- /** 喂一片(返回可交出文本;半条序列留给下一片)。 */
185
- feed(text) { return scan(text) },
186
- /** 收场:尾部半条序列丢弃并计一次;其前后的可见字节照常交出。 */
187
- end(text = "") {
188
- let out = scan(text)
189
- if (pendingCr) { out += "\n"; pendingCr = false }
190
- const dropped = state === "ground" ? 0 : 1
191
- state = "ground"
192
- return { text: out, dropped }
193
- },
194
- }
195
- }
196
-
197
- /** 同一归一(无状态旁路——遮蔽比较面用:秘密值先过控制字节剥离 + CRLF 归一)。 */
198
- export function normalizeText(text) {
199
- return createStripper().end(String(text ?? "")).text
200
- }
201
-
202
- // ─── 遮蔽(§6.22 ⑦)────────────────────────────────────────────────────────
203
-
204
- /** 秘密遮蔽过滤器:字面移除 + `len-1` 尾缓冲(跨 chunk 切分不泄;尾至沉降冲涮)。
205
- * 比较面 = 与剥离同一归一(§6.22 ③):秘密值先归一、再按不可见处切段(段长 ≥ 4)——
206
- * 裸字面匹配会漏掉夹控制字节 ∥ 被 chunk 切开的回显。 */
207
- export function createMask() {
208
- const secrets = []
209
- let tail = ""
210
- let keep = 0
211
- return {
212
- add(secret) {
213
- const raw = String(secret ?? "")
214
- if (!raw) return
215
- const table = [normalizeText(raw), ...raw.split(INVISIBLE_SPLIT).filter((seg) => seg.length >= MASK_SEG_MIN)]
216
- for (const s of table) {
217
- if (!s || secrets.includes(s)) continue
218
- secrets.push(s)
219
- keep = Math.max(keep, s.length - 1)
220
- }
221
- },
222
- push(text) {
223
- let out = tail + String(text ?? "")
224
- for (const s of secrets) out = out.split(s).join("")
225
- if (out.length <= keep) { tail = out; return "" }
226
- const emit = out.slice(0, out.length - keep)
227
- tail = out.slice(out.length - keep)
228
- return emit
229
- },
230
- /** 尾缓冲现行内容(**判据面用**:门①② 要看到已达字节——尾在 drain 时释放,判据不得被它推迟)。 */
231
- peek() { return tail },
232
- /** 沉降时冲涮尾缓冲:**只放行非秘密前缀段**(尾内最长可疑后缀一律扣下——整尾 ∥ 移位前缀
233
- * 都不出返回面;扣下的至多 `秘密长-1` 字符,代价 < 前缀外泄)。 */
234
- flush() {
235
- const t = tail
236
- tail = ""
237
- if (!t) return ""
238
- let cut = 0
239
- for (const s of secrets) {
240
- const max = Math.min(t.length, s.length - 1)
241
- for (let L = 1; L <= max; L++) if (t.endsWith(s.slice(0, L))) cut = Math.max(cut, L)
242
- }
243
- return cut ? t.slice(0, t.length - cut) : t
244
- },
245
- }
246
- }
247
-
122
+ // ─── 终端噪声 / 遮蔽(2026-11-05 拆档族已外移 `ssh-text.mjs`)──────────────────
123
+ // 剥离器(`createStripper`)、同一归一(`normalizeText`)与遮蔽过滤器(`createMask`)的体全住兄弟档
124
+ // `ssh-text.mjs`(纯「字节 → 可见文本」链,零子进程 / 零计时);本档 import 回来原样再出口。
125
+ // 收场面作两半:**半条序列的冲涮**(`flushEscapes`)留本档——它把交出的字节经 `handleChunk` 汇入
126
+ // log / 缓冲 / 等待者(运行时汇聚点住这里,搬过去就得反向 import);**注记**(`escapeNote`)随文本面走。
248
127
  // ─── 子进程(起跑 ∥ 双流汇入 ∥ 退出)────────────────────────────────────────
249
128
 
250
129
  /** 悬挂 chunk 双流汇入(已剥离已遮蔽 → log ∥ 缓冲 ∥ 面板 → 唤醒沉降等待者)。 */
@@ -506,14 +385,6 @@ export function flushEscapes(entry) {
506
385
  return dropped
507
386
  }
508
387
 
509
- /** 半条序列收场注记(§6.22 ③ flush②)——报告一次即清零。 */
510
- export function escapeNote(entry) {
511
- const n = entry.escDropped ?? 0
512
- if (!n) return ""
513
- entry.escDropped = 0
514
- return `\n— ${n} incomplete escape sequence dropped`
515
- }
516
-
517
388
  /** 状态行冠形(§6.22 动作表末行):每返回首行。 */
518
389
  export function statusLine(entry) {
519
390
  const idle = Math.max(0, Math.round((Date.now() - entry.lastActivityAt) / 1000))
@@ -217,11 +217,10 @@ function queuedPositionOf(agent, key) {
217
217
  return i >= 0 ? i + 1 : undefined
218
218
  }
219
219
 
220
- /** recent 参数钳制(默认 ~5 条摘要——可参数;钳到 1..20 防超长 N2 失控)。 */
220
+ /** recent 参数钳制(必填,1..20;不再造默认值)。值已在 `executeObserveAction` 入口判过缺 ∥ 非法,
221
+ * 本函数只钳区间;钳制到 1..20 防超长 N2 失控。 */
221
222
  function clampRecent(n) {
222
- const v = Number.parseInt(n, 10)
223
- if (!Number.isFinite(v)) return 5
224
- return Math.max(1, Math.min(20, v))
223
+ return Math.max(1, Math.min(20, n))
225
224
  }
226
225
 
227
226
  /**
@@ -242,6 +241,11 @@ export function executeObserveAction(args, ctx) {
242
241
  return JSON.stringify({ status: "error", error: "observe requires the id of the async subagent to inspect (from the async spawn return) — pass the id; omitting it observes nothing" })
243
242
  }
244
243
  const key = String(id)
244
+ // `recent` 必填(KD-4):钳制函数里的 `return 5` 是代码造的值——缺了就拒,不替调用方选条数。
245
+ const recentNum = Number.parseInt(args?.recent, 10)
246
+ if (!Number.isFinite(recentNum)) {
247
+ return JSON.stringify({ status: "error", error: `observe: recent is required — pass how many recent-turn summaries to return (1..20); got ${JSON.stringify(args?.recent ?? null)}` })
248
+ }
245
249
  const entry = getAsyncPool(agent, "subagent")?.get(key)
246
250
  if (!entry) {
247
251
  if (getAsyncPool(agent, "advisor")?.has(key)) {
@@ -259,7 +263,7 @@ export function executeObserveAction(args, ctx) {
259
263
  // 执行前后维护——LLM 生成/工具间空隙为空;子代理 await 长工具调用时父回合可见它。
260
264
  const inflight = child?._inflightTools
261
265
  if (inflight instanceof Set && inflight.size > 0) out.currentTool = [...inflight]
262
- const n = clampRecent(args?.recent)
266
+ const n = clampRecent(recentNum)
263
267
  out.recentTurns = recentTurnLines(child, n)
264
268
  out.note = `observing running ${entry.role}#${key} — recentTurns newest-first (cap ${n}); currentTool shown only while a tool is executing (stuck detection); sent directions consume at the next turn boundary`
265
269
  } else if (entry.status === "queued") {
@@ -270,7 +274,7 @@ export function executeObserveAction(args, ctx) {
270
274
  out.done = true
271
275
  out.turn = entry.turn ?? 0
272
276
  out.maxTurns = entry.maxTurns ?? 0
273
- out.recentTurns = child ? recentTurnLines(child, clampRecent(args?.recent)) : []
277
+ out.recentTurns = child ? recentTurnLines(child, clampRecent(recentNum)) : []
274
278
  out.note = "settled — the final report is delivered by the auto channel (turn-end collection or the suspension digest); observe returns the activity summary, not the full report (N2)"
275
279
  }
276
280
  return JSON.stringify(out)
@@ -22,7 +22,7 @@ import {
22
22
  import { logEvent, errText } from "../log.mjs"
23
23
  import { resolveChildProvider, mergeChildMutations } from "./subagent-async.mjs"
24
24
  import { launchEscalateAsync } from "./escalate-async.mjs"
25
- // TUI-OOM-ROOTCAUSE·AGENT-LOOP.md §6.15:子代理人读线窗口常量(单源——store 零依赖)。
25
+ // TUI-OOM-ROOTCAUSE·AGENT-LOOP.md §9.2:子代理人读线窗口常量(单源——store 零依赖)。
26
26
  import { RECORD_WINDOW_MESSAGES } from "../session-store.mjs"
27
27
  // ASYNC-RESULT-CONTAINER.md D1:池 accessor(absorb 双池——advisor 独立池无队列)
28
28
  import { getAsyncPool } from "./async-settle.mjs"
@@ -170,7 +170,7 @@ export async function executeEscalateAction(args, ctx) {
170
170
  memory: parent.memory,
171
171
  role: "coder",
172
172
  })
173
- child._historyWindow = RECORD_WINDOW_MESSAGES // TUI-OOM-ROOTCAUSE·AGENT-LOOP.md §6.15:子代理人读线窗口(四处创建点同置)
173
+ child._historyWindow = RECORD_WINDOW_MESSAGES // TUI-OOM-ROOTCAUSE·AGENT-LOOP.md §9.2:子代理人读线窗口(四处创建点同置)
174
174
  child._logId = escId // LOGGING:子内事件归属(escalate#N)
175
175
  // SUBAGENT-UPSTREAM-CHANNEL(§6.27.4 W2——escalate **sync**:单向;工具返回注走同步形)。
176
176
  child._upstream = { parent, label: escId, sync: true }
@@ -18,11 +18,11 @@ import {
18
18
  MIN_REPORT_CHARS, REPORT_CONTINUATION, DEFAULT_SUBAGENT_TURNS,
19
19
  } from "../agent.mjs"
20
20
  import { runWithContinue, TURN_CAP_MARK } from "../agent/spawn-child.mjs"
21
- import { pushReal } from "../context.mjs"
21
+ import { pushInject, pushRecord } from "../context.mjs"
22
22
  import { offloadToolResult } from "../agent/helpers.mjs"
23
23
  import { logEvent } from "../log.mjs"
24
24
  import { digestBudgetOver, persistOverflowReport, _digestOffloadDirForTest } from "./digest-budget.mjs"
25
- // 群 B 批 B5(AGENT-LOOP.md §6.14 D-DG4):预算单源迁出(digest-budget.mjs)——原处 re-export 保测试
25
+ // 群 B 批 B5(AGENT-LOOP.md §9 D-DG4):预算单源迁出(digest-budget.mjs)——原处 re-export 保测试
26
26
  // 导入面零改(DIGEST_INJECT_BUDGET / _setDigestOffloadDirForTest)。
27
27
  export { DIGEST_INJECT_BUDGET, _setDigestOffloadDirForTest } from "./digest-budget.mjs"
28
28
  import {
@@ -40,6 +40,7 @@ import { noteReviewDelivered } from "./review-facts.mjs"
40
40
  import { injectBgResult } from "./bash-async.mjs"
41
41
  // 批 browser-async-fix:后台浏览器动作注入器(同族——role="browser" 分发到 browser-async.mjs)。
42
42
  import { injectBrowserResult } from "./browser-async.mjs"
43
+ import { mergeAttribution } from "../agent/batch-attribution.mjs" // 归属表合入(收口取材的判据一;子代理记在自己的 agent 上,并回父侧)
43
44
 
44
45
  // agent-tools 共享:并行子代理的审批/继续弹窗经 owner 上命名 promise 链串行——
45
46
  // 永不叠弹窗(返回链供调用方 .then 续接)。
@@ -50,7 +51,7 @@ export function enqueueAsk(owner, key, ask) {
50
51
  }
51
52
 
52
53
  // Async pool limits per role domain (AGENT-LOOP-ASYNC-POOL.md §6.10 — R14, 2026-09-06):
53
- // the old single cap (ASYNC_SUBAGENT_LIMIT = 4, AGENT-LOOP-SUBAGENT.md §6.7.3 D-A4) evolved into two
54
+ // the old single cap (ASYNC_SUBAGENT_LIMIT = 4, AGENT-LOOP-SUBAGENT.md §6.7.3) evolved into two
54
55
  // independent pools — eng-coder 4 / other roles 4 (user ruling "eng-coder 四路,
55
56
  // 其他 4 路") — a full engCoder pool never blocks an explore spawn and vice versa
56
57
  // (same-domain cap still 4, cross-domain total up to 8). The per-turn check
@@ -123,7 +124,7 @@ function warnPoolFallback(what, sig) {
123
124
  console.warn(`[config] agent.poolLimits: ${what} — must be a positive integer ≥1 — falling back to default ${JSON.stringify(ASYNC_POOL_LIMITS)}`)
124
125
  }
125
126
 
126
- /** Running count within ONE pool domain (口径同 AGENT-LOOP-SUBAGENT.md §6.7.3 D-A1/T6: queued 与已完成不计入;
127
+ /** Running count within ONE pool domain (口径同 AGENT-LOOP-SUBAGENT.md §6.7.3 T6: queued 与已完成不计入;
127
128
  * 条目带 _pool 域字段——spawn 时 poolDomainOf(role) 落位;缺字段(手工/旧条目)按
128
129
  * other——既有 coder 域测试语义不变)。 */
129
130
  export function runningPoolCount(parent, pool) {
@@ -314,10 +315,10 @@ export function executeCancelAction(args, ctx) {
314
315
  }
315
316
 
316
317
  /**
317
- * 共享 post-spawn 管线(阻塞与 async 同一条——AGENT-LOOP-SUBAGENT.md §6.7.3 D-A1 "全不变"):turn-cap continue
318
+ * 共享 post-spawn 管线(阻塞与 async 同一条——AGENT-LOOP-SUBAGENT.md §6.7.3 "全不变"):turn-cap continue
318
319
  * 循环 → 拒绝降级 partial 返回 → MIN_REPORT_CHARS 扩写 → eng-coder mutation merge →
319
320
  * designId 后缀。onDeclined 在此(两路同一形态)——只有 askContinue 不同:阻塞经权限
320
- * 面板询问;async 永不弹面板(自动拒绝;engineering && AUTO 自动 resume——§6.7.3 D-A3)。
321
+ * 面板询问;async 永不弹面板(自动拒绝;撞帽即注册父侧检查点、挂起等父 `send` / `cancel`,AUTO 档亦不自动续跑——§6.7.3)。
321
322
  */
322
323
  export async function runChildPipeline(child, input, childOpts, childRunOpts, { parent, role, args, askContinue }) {
323
324
  const declined = { partial: null }
@@ -361,7 +362,7 @@ export async function runChildPipeline(child, input, childOpts, childRunOpts, {
361
362
  }
362
363
 
363
364
  // ─── BATCH-3-STRUCTURE F-2:digest 注入批量预算(2026-09-09)───
364
- // AGENT-LOOP.md §6.14 D-DG1(群 B 批 B5):常量 / 判超 / 记账 / 落盘四处合一入 digest-budget.mjs 叶子模块
365
+ // AGENT-LOOP.md §9 D-DG1(群 B 批 B5):常量 / 判超 / 记账 / 落盘四处合一入 digest-budget.mjs 叶子模块
365
366
  // (四族共享单源——D2);本文件保留 re-export(顶部)与经本入口的三族注入器接线。
366
367
 
367
368
  /**
@@ -379,12 +380,12 @@ export async function injectAsyncResult(agent, entry) {
379
380
  // 批 browser-async-fix:后台浏览器动作族(role="browser")同式单列(摘要文法 = ack 族同源)。
380
381
  if (entry.role === "browser") return injectBrowserResult(agent, entry)
381
382
  const body = entry.error ?? entry.report ?? "(no report)"
382
- // F-2(BATCH-3-STRUCTURE)+ AGENT-LOOP.md §6.14 D-DG2(群 B 批 B5):注入前查轮累计(单源)——超限条目不
383
+ // F-2(BATCH-3-STRUCTURE)+ AGENT-LOOP.md §9 D-DG2(群 B 批 B5):注入前查轮累计(单源)——超限条目不
383
384
  // inline 全文,改清单行(全文经 persistOverflowReport 落盘——path 随行)。首条豁免
384
385
  // (used===0 不判超)。
385
386
  const raw = String(body)
386
387
  const over = digestBudgetOver(agent, raw.length)
387
- // TIMEOUT-DIGEST.md §2.2:轮累计超预算 ⇒ 清单行(正文不进请求体);否则无条件落盘——`force` 跳过
388
+ // TIMEOUT-DIGEST.md §2:轮累计超预算 ⇒ 清单行(正文不进请求体);否则无条件落盘——`force` 跳过
388
389
  // 长度门(≤64K 的报告也上盘,父回合丢了还能按路径回读);渲染二分全在 offloadToolResult。
389
390
  const preview = (over && await persistOverflowReport(raw, { tag: `async-subagent-${entry.id}` }))
390
391
  || await offloadToolResult(raw, `async-subagent-${entry.id}`, _digestOffloadDirForTest(), { force: true })
@@ -405,11 +406,14 @@ export async function injectAsyncResult(agent, entry) {
405
406
  } else {
406
407
  label = `[System reminder: async subagent #${entry.id} (${entry.role}) finished]\n${escapeXml(preview)}`
407
408
  }
408
- pushReal(agent, {
409
+ const msg = {
409
410
  role: "user",
410
411
  content: label,
411
- })
412
- // #949:评审族投递水印落点(响应表取件下界 = 投递刻下标;非评审族零写)。
412
+ }
413
+ // B 段:一次性投递走待发队,持久写入只落人读线(机读线零触)。
414
+ pushInject(agent, msg)
415
+ pushRecord(agent, msg)
416
+ // #949:评审族投递水印落点(响应表取件下界 = 投递刻线尾位置;非评审族零写)。
413
417
  if (entry.role === "advisor") noteReviewDelivered(agent, entry.run)
414
418
  // §6.9 D-SD5 终态墓碑:本函数是全部自动注入路径的共享形态(回合尾 collect + 挂起
415
419
  // digest 首行注入)——注入即消费(墓碑落注入时点——依赖满足判据不随销账后移)——容器侧:
@@ -463,11 +467,9 @@ export function mergeChildMutations(parent, child) {
463
467
  // to the parent's guard state.
464
468
  if (!child._mutatedThisRun || !(child._touchedFiles?.length)) return false
465
469
  parent._mutatedThisRun = true
466
- const merged = []
467
- for (const abs of child._touchedFiles ?? []) {
468
- if (!parent._touchedFiles.includes(abs)) parent._touchedFiles.push(abs)
469
- merged.push(abs)
470
- }
470
+ const merged = [...(child._touchedFiles ?? [])]
471
+ for (const abs of merged) if (!parent._touchedFiles.includes(abs)) parent._touchedFiles.push(abs)
472
+ mergeAttribution(parent, child) // 归属表并集(判据一的取材面随 `_touchedFiles` 同笔并回)
471
473
  // §6.10: merged code mutates the parent's state — log it for the stale
472
474
  // scan of in-flight reviews (a review whose code changed under it is stale).
473
475
  noteMutations(parent, merged)
@@ -0,0 +1,76 @@
1
+ /**
2
+ * subagent-brief.mjs — **任务书与 system 固块拼装**族:任务书播报文本、写域行(S4)、文档坐标行(S5)。
3
+ *
4
+ * 机制单源 = `docs/core/design/AGENT-LOOP-SUBAGENT.md` §6.22(任务书)∥ §6.26(写域行 S4)∥ §6.61(文档坐标行 S5);
5
+ * 本档只拼文本,不判准入——三条门的判据住 `./spawn-gates.mjs` 与 `./subagent-spawn.mjs`。
6
+ * **为什么单独立档**:这三个函数是纯拼装(入参 → 一段文本),消费者只有 `subagent-spawn.mjs` 的 child 装配点;
7
+ * 把它整族搬走是分拆落点(`docs/core/design/PATH-RESOLUTION.md` §3 末条),装配面一句调用都没动。
8
+ */
9
+ import { relative } from "node:path"
10
+
11
+ import { docRootBase, docRootPaths, readManifest } from "../manifest.mjs"
12
+ import { composeTaskBookBrief } from "./spawn-gates.mjs"
13
+
14
+ /** 任务书播报文本:该角色名集拼装 + 可选 task 自由文本(拼装空 ⇒ 原 task 逐字——旧形零变)。 */
15
+ export function taskBriefOf(args, role) {
16
+ const composed = composeTaskBookBrief(args, role)
17
+ if (!composed) return args.task
18
+ const extra = typeof args.task === "string" ? args.task.trim() : ""
19
+ return extra ? `${composed}\n\n${extra}` : composed
20
+ }
21
+
22
+ /** S4 写域行(AGENT-LOOP-SUBAGENT.md §6.26「写域行(S4)」):表头 + 逐条绝对路径 + 两句语义——
23
+ * 本档局部纯函数(D23-9:不外提模块)。两句不可省:缺① 子代理读成「我只能写这些」⇒ 该写的漏掉;
24
+ * 缺② 仍把任务书 §2 全文当成自己的改动面(本块的病因)。清单不截断——截断正是本块要消除的
25
+ * 「看不见」。返回块文本(块间分隔由装配侧 `join("\n\n")` 施加)。 */
26
+ export function filesBlockOf(files) {
27
+ return `Files declared for this spawn (the write domain this task declares, for scheduling):\n` +
28
+ files.map((f) => `- ${f}`).join("\n") +
29
+ `\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.`
30
+ }
31
+
32
+ /** §6.61 契约 ② 的两件常量:层键固定 = 这三层(`specs` ∥ `modules` ∥ `standards` 不读——多的层每发再付
33
+ * 一次 token,KD-DC3);前缀逐字(英文——与兄弟块同语体),层串接在其后。 */
34
+ const DOCS_COORDINATE_KEYS = ["requirements", "design", "batches"]
35
+ const DOCS_COORDINATE_PREFIX = "Docs (project-root relative, declared by this project's PROJECT-MANIFEST.json docRoot):"
36
+
37
+ /** S5 文档坐标行(AGENT-LOOP-SUBAGENT.md §6.61「子代理文档坐标行」):本项目 manifest 声明的三层
38
+ * 文档坐标(`requirements` ∥ `design` ∥ `batches`),项目根相对形,一行随 system 固块下发;
39
+ * 未声明的层呈现 `(undeclared)`。
40
+ *
41
+ * **「未声明」的判别单源 = `readManifest` 同次返回的 `missingKeys`**——它在**原始档**上算得,与补默认
42
+ * 后的值分属两个事实。不能看返回的 `manifest.docRoot[键]` 判:`readManifest` 的返回值已 `fillDefaults`,
43
+ * `docs/design` 这类默认路径与一条真声明同形,打出去就是把项目从未声明的坐标当声明发给子代理
44
+ * (KD-DC2——比不发更坏,它看起来像声明)。
45
+ *
46
+ * **读不出(缺档 ∥ 坏档 ∥ 校验不过 ∥ 读抛 ∥ 项目根解析链 I/O 异常)⇒ 返回 null,调用点不推块**:不加本行
47
+ * 的结果 = 本批之前的行为,业务结果零变(KD-DC4;这不是兜底式静默——坐标取不到不该赔掉一次 spawn)。
48
+ *
49
+ * **护栏宽度 = 整段坐标计算**(读档 + 基数解析 + 路径映射 + 串拼装),不是只包读档那一句(§6.61.2 ④ ·
50
+ * AC-DC-8):基数取法 `docRootBase(cwd)` 走项目发现链,而树根那一环 `owningProject` 的 `statSync` 无护栏
51
+ * ⇒ 该链的 I/O 异常照原样上抛;只包读档那一句,「读不出不赔掉一次 spawn」就只兑现一半。
52
+ *
53
+ * 返回块文本 ∥ null。 */
54
+ export function docsCoordinatesBlockOf(cwd) {
55
+ try {
56
+ const read = readManifest(cwd)
57
+ if (!read.ok || !read.manifest) return null // 缺档 ∥ 坏 JSON ∥ 校验不过(契约 ③ 读档格)
58
+ const missing = new Set(read.missingKeys ?? [])
59
+ // 整键缺 ∥ 非对象 ⇒ 三层皆按未声明。**不另设「三层全未声明」分支**:它就是下面这条逐层判据连用三次。
60
+ const wholeUndeclared = missing.has("docRoot")
61
+ const base = docRootBase(cwd)
62
+ const layers = DOCS_COORDINATE_KEYS.map((key) => {
63
+ if (wholeUndeclared || missing.has(`docRoot.${key}`)) return `${key} = (undeclared)`
64
+ const value = read.manifest.docRoot?.[key]
65
+ // 显式「本面无」(`null`)与缺键同呈现:`docRootPaths(null) = []` 已定那一读(MANIFEST.md §2.7)。
66
+ if (value === null || value === undefined) return `${key} = (undeclared)`
67
+ // 路径一律项目根相对、`/` 分隔;解析为空(声明 = 项目根自身)呈现为 `.`。
68
+ const roots = docRootPaths(value, cwd).map((abs) => relative(base, abs).replaceAll("\\", "/") || ".")
69
+ return `${key} = ${roots.join(", ")}`
70
+ })
71
+ return `${DOCS_COORDINATE_PREFIX} ${layers.join(" · ")}`
72
+ } catch {
73
+ // 读档非 ENOENT 读错(权限 ∥ 目录等)· 项目根解析链的 I/O 异常:一律收成「读不出」(契约 ④)
74
+ return null
75
+ }
76
+ }
@@ -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
+ }