@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,27 @@
1
1
  /**
2
- * agent-tools/doc-check.mjs — `doc_check` 工具:文档纪律机检(产品内建 · 两种问法)。
2
+ * agent-tools/doc-check.mjs — `doc_check` 工具:文档机检(只判三件事)。
3
3
  *
4
- * 设计 = `docs/core/design/DOC-DISCIPLINE.md` §3.20 条目 S(判据 = 锚 ∥ 段判据 · 参数内置常量)。
5
- * 工具形:**无动作枚举**——`mode` = 同一条判据的两种问法(`report` = 报告态 ∥ `gate` = 交付时点的裁定);
6
- * **只读**(零副作用 · 免审批 · 可并行);参数 `target` / `mode` / `docs`
7
- * (`target` 指向多项目工作区 ⇒ 报明候选并要求指名,同 `manifest` 工具面)。
8
- * 判据参数 = 引擎内置常量 `DOC_CHECK_BUILTINS`——不读 manifest、不硬编码本仓路径、不扫目录。
4
+ * 判据句单源 = `docs/core/design/DOC-CHECK.md`:① 一段太长 ∥ ② 拿行号做锚 ∥ ③ 悬空指针。
5
+ * 工具形:**无动作枚举**——`mode` 只是这一笔的意图,而两个 mode 的**判域不同**(单源 = 同档 §6):
6
+ * `report` = 诊断面,判整份;`gate` = 交付判定,只判**本批变更区**。同一句话不许两面各说一套。
7
+ * **时点 = 收口**(§9):它读的是已经在盘的档,与收口同处境——批档面整份不进判域(两个 mode 同此一判)。
8
+ * `gate` 的基线取**绑定给本席的批档**(`ctx.agent._batchDoc`)§1 的记入行:没有绑定 ⇒ 没有「本批」可指
9
+ * ⇒ 没有要判的行,一个档也不判(不猜一份在途批档来当基线)。
10
+ * **`report` 面只读(零副作用 · 免审批 · 可并行)**;**`gate` 面写索引**:判之前对它此行判的那几份档逐个
11
+ * `git add -- <该档>`(按路径限定,不 `git add -A`)——索引外的新档 `git diff` 看不见,那不是「没改」(§6)。
12
+ * 两面都不写档字节、都不问审批。参数 `target` / `mode` / `docs`。
13
+ * `target` = 基根(相对 `docs` 条目按它解析);每份档的项目根沿它自己往上找(单源 = 引擎)。
9
14
  * 判定范围 = 调用方传入的档:`report` 面 `docs` 必填(不给 ⇒ 明确报错,零遍历);
10
15
  * `gate` 面缺省 = 本会话触达记账里的 `.md`(交付面按轮次收窄的唯一来源)。
11
- * `report` 非门禁(硬):输出不得被读作拒执行的理由(用户令 > 机检——§2 总则族);
12
- * `gate` 的强制面住交付协议 + 批次档 §6 前置,工具本体同样不阻断任何动作。
13
16
  * 描述外置:模型可见文本单点 = `tool-docs/doc_check.md`(`DESC` 单一解析面)。
14
17
  * 装配段 = `agent/family-tools.mjs` 三处(depth-0 / eng-coder / eng-designer)——写文档 / 设计档的角色面。
15
18
  */
16
- import { resolve } from "node:path"
19
+ import { isAbsolute, resolve } from "node:path"
17
20
  import { projectRootView } from "../manifest.mjs"
18
21
  import { resolvePathTarget } from "../path-resolve.mjs"
19
- import { runDocCheck } from "../doc-check/index.mjs"
22
+ import { runDocCheck, MOMENT } from "../doc-check/index.mjs"
23
+ import { baseShaOf } from "./batch-gate.mjs"
24
+ import { changedRegionsOf, stageDocs } from "./batch-regions.mjs"
20
25
  import { DESC } from "../tools/shared.mjs"
21
26
 
22
27
  export const docCheckTool = {
@@ -25,20 +30,25 @@ export const docCheckTool = {
25
30
  parameters: {
26
31
  type: "object",
27
32
  properties: {
28
- target: { type: "string", description: "Explicit project root to check — defaults to the session anchor; relative paths resolve against it. A workspace target (several projects below it) is reported with the full candidate list — pass the project root you mean." },
29
- mode: { type: "string", enum: ["report", "gate"], description: "How to ask the same two-criteria check. \"report\" (default): a non-gating report over the documents you list in docs. \"gate\": the delivery gate — the documents this round touched (docs, or this session's written documents when docs is omitted), whole-file judged, first line a machine-readable verdict (DOC-CHECK GATE: PASS / REFUSED / ERROR)." },
30
- docs: { type: "array", items: { type: "string" }, description: "The documents to judge, as paths relative to the project root or absolute — each is judged whole; nothing else is read except the targets those documents point at. Required in \"report\" mode (there is no default range: omitting it is refused, not widened). Omitted in \"gate\" mode ⇒ the Markdown documents this session wrote. A path that is not on disk or is not a Markdown document is an error (no document judged) in report mode and a visible skipped line in gate mode." },
33
+ target: { type: "string", description: "The base root for this call: relative `docs` entries resolve against it, and a document that belongs to no project falls back to it. Required — there is no default; the session anchor is the base for relative paths, never a substitute for `target`." },
34
+ mode: { type: "string", enum: ["report", "gate"], description: "What this call is for. \"report\" (default): the diagnostic face — every named document is judged whole. \"gate\": the delivery-time verdict — only this batch's changed region inside each named document is judged (docs, or this session's written documents when docs is omitted). Both judge the same three things and print the same sentences; the first line is DOC-CHECK GATE: PASS or REFUSED." },
35
+ docs: { type: "array", items: { type: "string" }, description: "The documents to judge, as paths relative to `target` or absolute. In \"report\" mode each is judged whole (the diagnostic face); in \"gate\" mode only this batch's changed region inside it is judged, so a pre-existing dangling pointer outside the region is not reported. Required in \"report\" mode (there is no default range: omitting it is refused, not widened). Omitted in \"gate\" mode ⇒ the Markdown documents this session wrote." },
31
36
  },
37
+ required: ["target"],
32
38
  },
33
39
  readonly: true,
34
40
  execute(args, ctx) {
35
41
  const anchor = ctx?.agent?.cwd ?? ctx?.cwd
36
42
  const mode = args?.mode === undefined ? "report" : String(args.mode)
37
- if (mode !== "report" && mode !== "gate") return `doc_check: unknown mode "${mode}" — use "report" (a report over the documents you list) or "gate" (this round's documents).`
38
- // `target` 的路径判定经统一解析层(`kind:"dir"` / `order:"root-first"`):判不出唯一根 ⇒ 报明候选(KD-5
39
- // 的形),解析出 ⇒ 用。`dangling` 不阻断本面——本面判据 = 内置常量、不读声明面,任可判目录都能跑
40
- // (受判档由 `docs` 给定),故无项目根时按显式目标 ∥ 会话锚照跑(受理判据归本面)。
41
- const picked = resolvePathTarget(anchor, args?.target, { kind: "dir", order: "root-first" })
43
+ if (mode !== "report" && mode !== "gate") return `doc_check: unknown mode "${mode}" — use "report" (look at the documents you list) or "gate" (this round's documents).`
44
+ const givenTarget = typeof args?.target === "string" && args.target.trim() !== "" ? args.target : undefined
45
+ if (givenTarget === undefined) {
46
+ return "doc_check: `target` is required — pass the base root you mean (an absolute path, or a path relative to the session anchor). There is no default: the session anchor is the base for relative paths, never a substitute for `target`."
47
+ }
48
+ if (!anchor && !isAbsolute(givenTarget)) {
49
+ return "doc_check: no session anchor is available (`ctx.agent.cwd` / `ctx.cwd` both empty) — pass `target` as an absolute path; a relative `target` has no base to resolve against, and this tool will not fall back to `process.cwd()`."
50
+ }
51
+ const picked = resolvePathTarget(anchor, givenTarget, { kind: "dir", order: "root-first" })
42
52
  if (picked.state === "ambiguous") {
43
53
  if (mode === "gate") {
44
54
  return [
@@ -50,7 +60,7 @@ export const docCheckTool = {
50
60
  return `doc_check: ${anchor} is a workspace holding ${picked.candidates.length} projects — pass the project root explicitly via target:\n` +
51
61
  picked.candidates.map((c) => `- ${c}`).join("\n")
52
62
  }
53
- const target = picked.state === "resolved" ? picked.abs : resolve(anchor, args?.target ? String(args.target) : "")
63
+ const target = picked.state === "resolved" ? picked.abs : resolve(anchor, givenTarget)
54
64
  const explicit = Array.isArray(args?.docs) ? args.docs : null
55
65
  if (args?.docs !== undefined && !Array.isArray(args.docs)) {
56
66
  return `doc_check: \`docs\` must be an array of paths (got ${typeof args.docs}) — a bare string is refused rather than read as a whole-domain request; pass ["<path>"].`
@@ -59,27 +69,27 @@ export const docCheckTool = {
59
69
  return "doc_check: every `docs` entry must be a path string — a non-string entry is refused rather than coerced (no document was judged)."
60
70
  }
61
71
  const view = projectRootView(target)
62
- if (view.state === "workspace") {
63
- if (mode === "gate") {
64
- return [
65
- "DOC-CHECK GATE: ERROR(多项目工作区:请指名 target)",
66
- `候选:${view.candidates.join(" ∥ ")}`,
67
- "处置:指名项目根(`target`)后复跑",
68
- ].join("\n")
69
- }
70
- return `doc_check: ${target} is a workspace holding ${view.candidates.length} projects — pass the project root explicitly via target:\n` +
71
- view.candidates.map((c) => `- ${c}`).join("\n")
72
- }
73
72
  const root = view.state === "ok" ? view.root : target
74
73
  if (mode === "gate") {
75
74
  const docs = explicit ?? (Array.isArray(ctx?.agent?._touchedFiles) ? ctx.agent._touchedFiles : [])
76
75
  .filter((p) => typeof p === "string" && p.toLowerCase().endsWith(".md"))
77
- return runDocCheck(root, { mode: "gate", docs, docsSource: explicit ? "explicit" : "session" }).report
76
+ if (docs.length === 0) return "DOC-CHECK GATE: ERROR(0 档受检——本轮没有碰过 .md)"
77
+ // 判域只是一部分:先按**收口时点**裁掉批档面(§9),再只判**本批变更区**(§6)——区内照判三件、区外一个字都不出。
78
+ // 基线 = 绑定给本席的批档(谁在判,谁已经知道自己是哪一批):不猜一份在途批档,不去扫发现面。
79
+ // 没有绑定 ⇒ 没有「本批」可指 ⇒ 没有要判的行 ⇒ 一档也不判(空表 = 每一档都没有条目)。
80
+ const bound = typeof ctx?.agent?._batchDoc === "string" && ctx.agent._batchDoc.trim() !== "" ? ctx.agent._batchDoc : null
81
+ const sha = bound ? baseShaOf(bound) : null
82
+ const absDocs = docs.map((d) => resolve(root, d))
83
+ // `gate` 面在判之前会 `git add` 它此行判的那几份档(§6):索引外的新档 `git diff` 看不见,那不是「没改」。
84
+ // 按路径限定、不 `git add -A`。没有绑定的批档 ⇒ 没有基线 ⇒ 没有要取的区,索引也不动。
85
+ if (sha) stageDocs(root, absDocs)
86
+ const regions = sha ? changedRegionsOf(root, sha, absDocs).regions : new Map()
87
+ return runDocCheck(root, { docs, moment: MOMENT.close, regions }).report
78
88
  }
79
- // 报告态:清单是唯一范围来源——不给就是拒绝(不是「全域」)。
80
89
  if (explicit === null) {
81
90
  return "doc_check: `docs` is required in report mode — pass the explicit list of documents to judge (e.g. docs: [\"docs/design/X.md\"]). There is no default range: nothing is scanned unless you name it."
82
91
  }
83
- return runDocCheck(root, { docs: explicit, docsSource: "explicit" }).report
92
+ // `report` = 诊断面:判整份(`regions: null`)。时点不按 mode 分,按**谁在调**分(§9)——批档面两个 mode 都不进判域。
93
+ return runDocCheck(root, { docs: explicit, moment: MOMENT.close, regions: null }).report
84
94
  },
85
95
  }
@@ -0,0 +1,140 @@
1
+ /**
2
+ * agent-tools/doc-graph.mjs — `doc_graph` 工具面:入参校验 ∥ 动作分派 ∥ 文本回执。
3
+ *
4
+ * 设计单源 = `docs/core/design/DOC-GRAPH.md` §2.5(工具面)∥ §2.5.5(两变体契约)∥ §3(登记面);机制单源 =
5
+ * `../doc-graph.mjs`。工具形与同族(`ledger` ∥ `team_ledger` ∥ `doc_check`)同构:**一个工具 + `action` 枚举**
6
+ * 四种问法(`scan` 扫 ∥ `forward` 正向 ∥ `reverse` 反向 ∥ `chain` 链路)——`doc_check` 那边是「判决」的两种问法,
7
+ * 两者判的东西不同,故不并成一个工具(KD-2)。
8
+ *
9
+ * **两变体同体、动作集一处字面**(构造单源 = `docs/core/design/AGENT-LOOP-SUBAGENT.md` §6.60.2 ②):参数化工厂
10
+ * `makeDocGraphTool(actions, { readonly, docName, unscanned })` 产出两形——全量 `docGraphTool`(四动作,depth-0 主 agent 段)
11
+ * ∥ 只读 `docGraphReadTool`(三动作、无 `scan`,全部 depth>0 角色段与 advisor 面)。动作集一处字面 `ALL_ACTIONS`、
12
+ * 只读集由它派生 ⇒ schema 的 `enum` ∥ execute 的护栏 ∥ 拒文里的取值集三处取同一个 `actions` 参数,变体不写第二份
13
+ * 字面对象(先例 = `../ledger-tools.mjs` 的 `makeLedgerTool`)。描述从同一 `actions` 生成(`ACTION_CLAUSES`)、
14
+ * 各自一份描述档;未建图策略(`unscanned`)由只读变体传 `readonly-empty`(TOOLS.md §6.29 ③)。
15
+ *
16
+ * **子代理段为什么不给 `scan`**:`scan` 把边落进台账库(`doc_edges` 表)——一次显式动作,没有常驻进程、没有 watch
17
+ * (需求 §3);而 depth>0 段拿到的台账是**只读**变体 ⇒ 同一段里没有可依的写面,多个子代理并发扫还会重写同一张共享
18
+ * 边表(D-DT1)。父侧扫一次、子代理查同一份库。只读性按 action 判(`isReadonlyAction`,与 `ledger` 同形):三个
19
+ * 查询走只读句柄、免审批;`scan` 走写面。
20
+ *
21
+ * **参数零默认**(设计 §2.5):`target` 恒必填;`forward` ∥ `reverse` ∥ `chain` 的 `node`、`chain` 的 `depth` 缺一即拒
22
+ * 并**点名**那一个——给默认值就是替调用方做决定。两个可选参数(`scan` 的 `scope` ∥ 三个读动作的 `kind`)缺席的含义
23
+ * 都由回执首行印出来(`全仓` / `范围 K 档` ∥ 本次生效的 kind 集合),不靠调用方记。
24
+ * `kind` 的**闭集校验住在核里**(`doc-graph.mjs` 的 `kindFilterOf`,闭集单源 = `ledger-db.mjs` 的 `DOC_EDGE_KINDS`):
25
+ * 本档只判形(必为字符串),闭集外拒并点名那个值由核做——一处校验,两个入口(工具 ∥ 直调核)。
26
+ *
27
+ * W8 契约②:本档只**动态** import `../doc-graph.mjs`(它自己再动态 import 台账库)——端壳静态闭包零 `node:sqlite`。
28
+ * 描述外置:模型可见文本单点 = `tool-docs/{doc_graph,doc_graph-read}.md`(`DESC` 单一解析面)——
29
+ * 两变体各一份描述档(TOOLS.md §6.29「描述面也分两份」:只读变体的字面里没有它执行不到的 `scan` 段)。
30
+ */
31
+ import { isAbsolute, resolve } from "node:path"
32
+ import { DESC } from "../tools/shared.mjs"
33
+
34
+ /** `target` 归一:相对路径按会话锚解析(锚缺位 + 相对形 ⇒ 拒、点名锚——不落 `process.cwd()`)。 */
35
+ function targetOf(args, ctx) {
36
+ const anchor = ctx?.agent?.cwd ?? ctx?.cwd
37
+ const given = args?.target
38
+ if (typeof given !== "string" || given.trim() === "") {
39
+ throw new Error("doc_graph:target 缺失(必填)——请给项目根(带 PROJECT-MANIFEST.json 的那个目录)")
40
+ }
41
+ if (!isAbsolute(given) && !anchor) {
42
+ throw new Error("doc_graph:会话锚不可用(`ctx.agent.cwd` / `ctx.cwd` 都空)——请把 target 写成绝对路径;相对 target 没有基根,本工具不落 `process.cwd()`")
43
+ }
44
+ return resolve(anchor ?? ".", given)
45
+ }
46
+
47
+ /** 全量动作集——本档唯一字面。 */
48
+ const ALL_ACTIONS = ["scan", "forward", "reverse", "chain"]
49
+ /** 只读动作集——由上一行派生,不写第二份字面(`scan` 归主 agent,见文件头)。 */
50
+ const READ_ACTIONS = ALL_ACTIONS.filter((a) => a !== "scan")
51
+
52
+ /** 逐动作的一句话(`action` 参数描述的唯一措辞来源:描述从**本变体的动作集**生成——只读变体的字面
53
+ * 因此不含 `scan`,而两变体的措辞只有这一份,漂移由「同一张表同时派生动作与描述」挡住)。 */
54
+ const ACTION_CLAUSES = {
55
+ scan: "collects the edges into the ledger database (one explicit pass, no background index)",
56
+ forward: "lists the edges leaving a node",
57
+ reverse: "lists the edges pointing at a node",
58
+ chain: "walks outward from a node layer by layer, one layer per edge count",
59
+ }
60
+ /** `action` 参数描述(按本变体动作集生成;全量四个动作时与旧字面逐字相同)。 */
61
+ const actionDescOf = (actions) => `The question to ask: ${actions.map((a) => `\`${a}\` ${ACTION_CLAUSES[a]}`).join(" · ")}.`
62
+
63
+ /**
64
+ * 工具工厂:两个装配面同体,只有 `actions` ∥ `readonly` ∥ `docName` ∥ `unscanned` 四个参数不同。
65
+ * @param {string[]} actions — 本变体的 action 闭集(schema `enum` ∥ execute 护栏 ∥ 拒文取值集三处同取本参数)。
66
+ * @param {{readonly?: boolean, docName?: string, unscanned?: 'throw'|'readonly-empty'}} [opts] — `readonly` 缺省 false
67
+ * (全量);`docName` = 该变体的描述档名(`tool-docs/<docName>.md`);`unscanned` = 未建图策略(B5:
68
+ * 只读变体传 `readonly-empty`,全量保持抛既有指引)。
69
+ */
70
+ function makeDocGraphTool(actions, { readonly = false, docName = "doc_graph", unscanned = "throw" } = {}) {
71
+ const readOnlyVariant = readonly
72
+ return {
73
+ name: "doc_graph",
74
+ description: DESC(docName),
75
+ parameters: {
76
+ type: "object",
77
+ required: ["action"],
78
+ properties: {
79
+ action: { type: "string", enum: actions, description: actionDescOf(actions) },
80
+ target: {
81
+ type: "string",
82
+ description: "The project root this call is about (the directory carrying PROJECT-MANIFEST.json; a relative path resolves against the session anchor). Required for every action — there is no default: the session anchor is the base for a relative path, never a substitute for `target`.",
83
+ },
84
+ node: {
85
+ type: "string",
86
+ description: "The node to start from, written in the identity form: `req:F16` · `doc:<path>` · `doc:<path>#<section>` · `case:CLI 41-1` · `symbol:editTool` · `ledger:#2236`. Required for forward / reverse / chain — a missing node is refused by name, never answered with an empty result.",
87
+ },
88
+ depth: {
89
+ type: "number",
90
+ description: "How many edge steps to walk (`chain` only, required there): depth 1 = the immediate neighbours, depth 2 = their neighbours, and so on. Hops are counted in edges, not nodes. There is no default — a missing depth is refused by name.",
91
+ },
92
+ // `scope` 只服务 `scan` ⇒ 只存在全量 schema(B6:只读角色面不出现它执行不了的参数)
93
+ ...(readOnlyVariant ? {} : {
94
+ scope: {
95
+ type: "array",
96
+ items: { type: "string" },
97
+ description: "`scan` only, optional: re-scan just these documents (project-root-relative or absolute). Their edges are deleted and rebuilt; every other document's edges stay untouched. Omit it to scan the whole repository — the receipt's first field always says which of the two it did (`全仓` / `范围 K 档`).",
98
+ },
99
+ }),
100
+ kind: {
101
+ type: "string",
102
+ description: "`forward` / `reverse` / `chain` only, optional: a comma-separated subset of edge kinds to read — `cites`, `cites-req`, `mentions-case`, `case-file`, `cites-symbol`, `imports`. The edges are filtered before sorting and layering, so a narrowed run is a complete run, not a few lines pulled out of a big receipt. Omit it to read every kind (ledger projections included); the receipt's first line always prints the set in force. A value outside that closed set is refused by name — it is never treated as an empty set.",
103
+ },
104
+ },
105
+ additionalProperties: false,
106
+ },
107
+ readonly,
108
+ /** 只读性按 action(先例 = `ledger` 的 `isReadonlyAction`):三查询免审批,`scan` 走侧效门。
109
+ * 只读变体的动作集不含 `scan` ⇒ 它恒为真,与 `readonly: true` 同向,不需要第二份实现。 */
110
+ isReadonlyAction(args) { return args?.action !== "scan" },
111
+ async execute(args, ctx) {
112
+ const action = args?.action
113
+ // schema 的 enum 是建议性的(provider 不强制)——枚举外的值必须由入口拒,且只印本变体的取值集。
114
+ if (!actions.includes(action)) {
115
+ throw new Error(`doc_graph:action 非法(${JSON.stringify(action ?? null)})——取值 ∈ {${actions.join(", ")}}`)
116
+ }
117
+ const target = targetOf(args, ctx)
118
+ const boundary = ctx?.agent?.cwd ?? ctx?.cwd
119
+ const kindArg = args?.kind
120
+ if (kindArg !== undefined && typeof kindArg !== "string") {
121
+ throw new Error(`doc_graph:kind 须为逗号分隔的字符串(收到 ${typeof kindArg})——如 "cites,imports";闭集外拒并点名那一个值(由核校验)`)
122
+ }
123
+ const mod = await import("../doc-graph.mjs")
124
+ if (action === "scan") {
125
+ const scope = args?.scope
126
+ if (scope !== undefined && !Array.isArray(scope)) {
127
+ throw new Error(`doc_graph:scope 须为路径数组(收到 ${typeof scope})——只重扫几档就给 ["<path>"];给空数组等号于全仓`)
128
+ }
129
+ return mod.scanDocGraph({ target, scope, boundary })
130
+ }
131
+ return mod.queryDocGraph({ action, target, node: args?.node, depth: args?.depth, kind: kindArg, boundary, unscanned })
132
+ },
133
+ }
134
+ }
135
+
136
+ /** 全量变体(depth-0 主 agent 段):四动作,含 `scan`;未建图仍抛既有指引(逐字不变)。 */
137
+ export const docGraphTool = makeDocGraphTool(ALL_ACTIONS, { readonly: false })
138
+ /** 只读变体(全部 depth>0 角色段与 advisor 面):三动作、无 `scan`;同名不塌缩——两变体互斥装配。
139
+ * 未建图返可读空态(不要求父代跑 scan、不隐式写共享边表)。 */
140
+ export const docGraphReadTool = makeDocGraphTool(READ_ACTIONS, { readonly: true, docName: "doc_graph-read", unscanned: "readonly-empty" })
@@ -19,6 +19,8 @@ import { ENG_ON_REMINDER, ENG_OFF_REMINDER } from "../agent.mjs"
19
19
  import { clearPlanMode } from "./plan.mjs"
20
20
  import { purgeExpiredDesignTokens } from "../token-ttl.mjs"
21
21
  import { resolveEngineeringManifest } from "../manifest.mjs"
22
+ import { resolveWorkMode, setConfigWorkMode } from "../config.mjs"
23
+ import { pushInject } from "../context.mjs"
22
24
  // 描述面 = `tool-docs/eng.md`(#15 描述外置统一——DESC 单一解析面,与内置工具族同径)
23
25
  import { DESC } from "../tools/shared.mjs"
24
26
 
@@ -26,7 +28,7 @@ import { DESC } from "../tools/shared.mjs"
26
28
  /**
27
29
  * 工程模式切换通知注入位(**缺省不覆盖** = no-op——CLI 语义(只进会话),零行为变;端装配层
28
30
  * 可覆盖为本端镜像写盘 / 面板提示)。核内零端名分支(契约 5——本档只认 `onToggle` 函数名)。
29
- * 契约:`onToggle(enabled, ctx) → string | null | undefined | Promise<同>`——非空字符串 =
31
+ * 契约:`onToggle(mode, ctx) → string | null | undefined | Promise<同>`——非空字符串 =
30
32
  * 追加到结果文案尾(如镜像写入碰撞提示);其余值 = 无提示。调用时机 = 状态翻转后(观察新态)。
31
33
  */
32
34
  let injectedMirror = null
@@ -37,8 +39,8 @@ export function configureEngMirror(impl) {
37
39
  export function resetEngMirror() { injectedMirror = null }
38
40
 
39
41
  /** 镜像通知串(缺省空串;仅非空字符串追加)。 */
40
- async function mirrorNotice(enabled, ctx) {
41
- const out = await injectedMirror?.onToggle(enabled, ctx)
42
+ async function mirrorNotice(mode, ctx) {
43
+ const out = await injectedMirror?.onToggle(mode, ctx)
42
44
  return typeof out === "string" && out.length > 0 ? ` ${out}` : ""
43
45
  }
44
46
 
@@ -56,22 +58,21 @@ export const engTool = {
56
58
  async execute(args, ctx) {
57
59
  ctx.agent.config.agent ??= {}
58
60
  if (args.action === "exit") {
59
- ctx.agent.config.agent.engineering = false
61
+ setConfigWorkMode(ctx.agent.config, "normal")
60
62
  // R16 (F-R16a): OFF 不清 token——有效 token 跨模式存活(设计评审过的产物不因
61
63
  // 开关重复烧)。过期清理跑在另外三处(恢复过滤 / 开模式 / spawn 门禁拒)。
62
64
  ctx.agent._advisorRound = 0 // reset convergence budget
63
65
  ctx.agent._advisorRuns = new Map() // AGENT-LOOP-ASYNC-POOL.md §6.10 D-24b: per-review instances die with the mode (fresh cycles)
64
66
  ctx.agent._touchedFiles = [] // clear mutation tracking
65
67
  ctx.agent._lastEngState = false
66
- ctx.agent._pendingReminders = ctx.agent._pendingReminders ?? []
67
- ctx.agent._pendingReminders.push(ENG_OFF_REMINDER)
68
- return "Engineering mode exited. Standard discipline now applies. You may edit files directly." + await mirrorNotice(false, ctx)
68
+ pushInject(ctx.agent, { role: "user", content: ENG_OFF_REMINDER })
69
+ return "Engineering mode exited. Standard discipline now applies. You may edit files directly." + await mirrorNotice(ctx.agent.config.agent.mode, ctx)
69
70
  }
70
71
  if (args.action === "enter") {
71
72
  // Idempotent enter (v2 2026-08-25): already in engineering mode → pure no-op
72
73
  // (cleanup only runs on a real off→on transition — T-R16c precondition: first
73
74
  // exit/OFF, then enter; an already-on enter must not touch tokens at all).
74
- if (ctx.agent.config.agent.engineering) {
75
+ if (resolveWorkMode(ctx.agent.config.agent) === "engineering") {
75
76
  return "Engineering mode already active. Existing design tokens stay valid."
76
77
  }
77
78
  // #41 先判后翻(MANIFEST.md §2.8 F2 / KD-M1-21):判据 = 入口决策树**单源**
@@ -85,7 +86,7 @@ export const engTool = {
85
86
  return `Error: cannot enter engineering mode — ${r.message} (mode unchanged)`
86
87
  }
87
88
  ctx.agent.manifest = r.ok ? r.manifest : null // 工作区放行 ⇒ 零附着(显式置 null——§2.8 F2 放行行)
88
- ctx.agent.config.agent.engineering = true
89
+ setConfigWorkMode(ctx.agent.config, "engineering")
89
90
  // FR31 ③ / KD10(翻转点①):工程模式 ⇒ planMode 恒 false——中途开模式时清残留
90
91
  //(planMode 位 + reminder 计数 + 未注入的 plan 提示语),半状态(工程纪律 × plan 只读)不产生。
91
92
  clearPlanMode(ctx.agent)
@@ -94,13 +95,12 @@ export const engTool = {
94
95
  const cleared = purgeExpiredDesignTokens(ctx.agent)
95
96
  ctx.agent._advisorRuns = new Map() // §6.10 D-24b: per-review instances die with the mode (fresh cycles)
96
97
  ctx.agent._lastEngState = true
97
- ctx.agent._pendingReminders = ctx.agent._pendingReminders ?? []
98
- ctx.agent._pendingReminders.push(ENG_ON_REMINDER)
98
+ pushInject(ctx.agent, { role: "user", content: ENG_ON_REMINDER })
99
99
  let msg = "Engineering mode activated. Design-before-code enforced: write a design document first (location per your project's document conventions), run advisor with type='design', get user approval, then implement via eng-coder subagents."
100
100
  if (cleared > 0) {
101
101
  msg += ` Cleared ${cleared} expired design token${cleared === 1 ? "" : "s"} — 清 ${cleared} 个过期 token,有效 token 保留(TTL 内不重评)。`
102
102
  }
103
- msg += await mirrorNotice(true, ctx)
103
+ msg += await mirrorNotice(ctx.agent.config.agent.mode, ctx)
104
104
  return msg
105
105
  }
106
106
  return "Invalid action: expected 'enter' or 'exit'"
@@ -27,7 +27,7 @@
27
27
  import { relative, isAbsolute } from "node:path"
28
28
  import { runAgent, createAgent, DEFAULT_SUBAGENT_TURNS, excludeSubagentTools } from "../agent.mjs"
29
29
  import { runWithContinue, TURN_CAP_MARK, wrapChildCallbacks } from "../agent/spawn-child.mjs"
30
- // TUI-OOM-ROOTCAUSE·AGENT-LOOP.md §6.15:子代理人读线窗口常量(单源——store 零依赖)。
30
+ // TUI-OOM-ROOTCAUSE·AGENT-LOOP.md §9.2:子代理人读线窗口常量(单源——store 零依赖)。
31
31
  import { RECORD_WINDOW_MESSAGES } from "../session-store.mjs"
32
32
  import { logEvent } from "../log.mjs"
33
33
  import { deathLine } from "../abort-provenance.mjs"
@@ -106,7 +106,7 @@ function touchedFilesNote(child, cwd) {
106
106
  */
107
107
  export function classifyEscalateSettle(parent, entry) {
108
108
  if (entry.cancelled) return { cancelled: true }
109
- // AGENT-LOOP.md §6.15(TUI-OOM-ROOTCAUSE)——childAgent 语义面:settle 分类(touched 摘要/partial
109
+ // AGENT-LOOP-ASYNC-POOL.md §4(TUI-OOM-ROOTCAUSE)——childAgent 语义面:settle 分类(touched 摘要/partial
110
110
  // merge)与 status/observe 摘要的读取源;**消化注入完成后释放**(池内未消化窗口不释放——表 2 候选 2 否决);
111
111
  // fallback 面(无 `_daSession`)由 `releaseSettledEntry`(async-settle.mjs)置 null(逐字沿用);会话态
112
112
  // (`_daSession`)注入后改调 `releaseChildHold`(仅释放 `childAgent`——`report` 保留至销账 / 升级;
@@ -152,7 +152,7 @@ export function launchEscalateAsync(parent, ctx, launch) {
152
152
  const { task, provider, tag, effortNote } = launch
153
153
  parent._asyncSubagents ??= new Map()
154
154
  parent._asyncQueue ??= []
155
- // Async id allocation (AGENT-LOOP-SUBAGENT.md §6.7.3 D-A1 precedent): reserve the relay
155
+ // Async id allocation (AGENT-LOOP-SUBAGENT.md §6.7.3 precedent): reserve the relay
156
156
  // counter at launch — the returned id stays stable while the entry sits queued.
157
157
  // The [model] token (TUI block creation) is DEFERRED to actual start so queued
158
158
  // flights don't paint an empty panel block (subagent-parity).
@@ -204,7 +204,7 @@ export function launchEscalateAsync(parent, ctx, launch) {
204
204
  role: "coder",
205
205
  })
206
206
  entry.childAgent = child // settle 分类/status touched 摘要绑定(start 时刻)
207
- child._historyWindow = RECORD_WINDOW_MESSAGES // TUI-OOM-ROOTCAUSE·AGENT-LOOP.md §6.15:子代理人读线窗口(四处创建点同置)
207
+ child._historyWindow = RECORD_WINDOW_MESSAGES // TUI-OOM-ROOTCAUSE·AGENT-LOOP.md §9.2:子代理人读线窗口(四处创建点同置)
208
208
  child._logId = relayPrefix.slice(0, -1)
209
209
  // SUBAGENT-UPSTREAM-CHANNEL(§6.27.4 W3——escalate **async**:工具返回注走异步形)。
210
210
  child._upstream = { parent, label: relayPrefix.slice(0, -1), sync: false }
@@ -228,7 +228,7 @@ export function launchEscalateAsync(parent, ctx, launch) {
228
228
  signal: entry.controller.signal,
229
229
  // §2.5 #78 并入:escalate 子代理输出流式(VSC subagent-escalate-async 同款豁免)。
230
230
  streamOutput: true,
231
- // SUBAGENT-OBSERVE-SEND 缺口补配(TURN-CAP-CONTINUE.md §3.1 :85):send 注入队列
231
+ // SUBAGENT-OBSERVE-SEND 缺口补配(`docs/core/design/TURN-CAP-CONTINUE.md` §3.1「兑现后的消费路径」):send 注入队列
232
232
  // 回合边界消费(否则续段文本静默丢弃)。空队列 no-op。
233
233
  consumeInjected: (ag) => { drainInjectedQueue(entry, ag ?? child) },
234
234
  }
@@ -1,5 +1,6 @@
1
1
  // F-CC4(CONTEXT-COMPACTION.md §6.16.5):goal 任一状态变更 ⇒ 方向转换轻推(本档只调用;文案/去重单源 = agent-tools/context.mjs)
2
2
  import { pushContextNudge } from "./context.mjs"
3
+ import { flattenHistory } from "../context.mjs"
3
4
  import { DESC } from "../tools/shared.mjs"
4
5
 
5
6
  /**
@@ -54,10 +55,12 @@ export const goalTool = {
54
55
 
55
56
  // Independent judge: verify the goal was actually achieved
56
57
  // Only applies when the agent is at depth 0 (not a subagent) and has history to review
57
- if (ctx.depth === 0 && agent.history.length > 2) {
58
+ // 机读线按轮嵌套:判据与取数都在拍平视图上(外层条数是轮数,不是消息数)。
59
+ const flat = flattenHistory(agent.history)
60
+ if (ctx.depth === 0 && flat.length > 2) {
58
61
  try {
59
62
  // Extract recent activity: last 4 assistant messages (summarizing what was done)
60
- const recent = agent.history.filter(m => m.role === "assistant").slice(-4)
63
+ const recent = flat.filter(m => m.role === "assistant").slice(-4)
61
64
  const activity = recent.map(m => (m.content ?? "").slice(0, 500)).join("\n---\n")
62
65
  const { chat } = await import("../provider/index.mjs")
63
66
  const judgeRes = await chat(agent.provider, {