@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
@@ -0,0 +1,347 @@
1
+ /**
2
+ * agent-tools/judge-domain.mjs — 判域机检(命令行面)。
3
+ * 判据句单源 = `docs/core/design/PROMPT-SYSTEM.md` §10.8「机检入口」与「读法」。
4
+ *
5
+ * 用法:`node thincoder-core/agent-tools/judge-domain.mjs --doc <设计档> --record <批档>`
6
+ * 两个参数都必填,缺一个在边界拒绝并点名该参数,没有默认值。
7
+ * 调用面 = 验收对照表里跑本件的那些行(带 `--doc` 与 `--record`)与收口 `doc_check` gate。
8
+ *
9
+ * 首行 `JUDGE-DOMAIN: PASS`(其后零条问题行)或 `JUDGE-DOMAIN: REFUSED`(其后逐条问题行)。
10
+ * `## 验收对照` 节在、但一条含 `判法「` 的验收行都没有时,两行都不写——边界拒绝,点名 `--record` 的路径与「zero 验收行」:零行时 PASS 会把「一行都没判」读成「全过」。
11
+ * 它报三类问题,各一行,点名判据或验收行:
12
+ * 1. `判域行不成形 <判法名>` —— 缺 对象/排除/止于 之一,某字段重复或为空,某字段值含占位词(「视情况」「按需」,或以「等」收尾一份列举),
13
+ * 判域行条数与判法行条数不等,行首判法名对不上判法行。
14
+ * 2. `验收行指不到判据 <首句>` —— 验收行点名的判据首句,在 §10.4 的判据条目里找不到。
15
+ * 验收行整格没点名判据首句时,同一个类报成 `验收行指不到判据(未点名判据首句) —— 验收行 <# 格>`:没有首句可点,仍属这一类,不是第四类。
16
+ * 3. `验收尺带判据没有的数 <数字>` —— 判法名文本里的每个数(连写的数字算一个数),在判据正文(判法在内)里以同一个数出现至少一次。两侧都按整串数读:判据正文里的数也连写读,尺上的 4 不因正文有 45 就算出现过。
17
+ * 三类之外不多报一行:验收行带了一个判据没有的判法名,由收口逐条读(§10.8「两处不一致即缺陷」),不是机检的第四类。
18
+ *
19
+ * 读法(照 §10.8「读法」原文解析,不另立一套):
20
+ * - 判据 = §10.4 里以 `- ` 起头、条目正文含 `**判域**:` 行的条目;条目正文 = 该行之后以空白起首的续行。
21
+ * - 判据首句 = 该条目第一个 `:` 之前的文字。
22
+ * - 判法行 = 条目正文里以 `判法「<判法名>」:` 起头的行(去首尾空白后)。
23
+ * - 判域行 = 条目正文里以 `**判域**:<判法名> —— ` 起头的行,字段形 `对象 = …;排除 = …;止于 = …。`
24
+ * - 判据正文 = 判据句加条目正文;判法行与判域行都在里面(设计原话:该判据自己的正文,判法在内)。
25
+ * - 验收行 = 批档「验收对照」表里含 `判法「` 的行;数字比对面只取它那一格里 `判法「…」` 的判法名文本。
26
+ * - 判据首句是配对键:§10.4 两条判据同首句时无法配对,边界拒绝并点名该首句。
27
+ *
28
+ * 比对面:数字只取验收行内 `判法「…」` 的判法名文本;`#` 列标签、期望列与引用坐标 `design §10.4` 的段号都不参与。
29
+ * 边界:本件只判形、配对与数字来源,不判判据在语义上是否完备。
30
+ * 退出码:0 = PASS,1 = REFUSED,2 = 边界拒绝(缺参数、档读不到、两份档缺本条读法要的章节、零条验收行、§10.4 两条判据同首句)。
31
+ */
32
+ import { readFileSync } from "node:fs"
33
+
34
+ /** 判域行三字段的闭集与顺序。 */
35
+ const FIELD_LABELS = Object.freeze(["对象", "排除", "止于"])
36
+
37
+ /** 占位词:字段值是正文,不写「视情况」「按需」「等」。前两个按出现在值里算。 */
38
+ const PLACEHOLDER_MARKERS = Object.freeze(["视情况", "按需"])
39
+
40
+ /** 「等」只在它收尾一份列举时算占位词:整值就是它,或以它收尾而前一字不是构成「相等」「同等」的相/同。 */
41
+ const PLACEHOLDER_ETC_RE = /(?:^|[^相同])等\s*$/
42
+
43
+ /** 判法行:去首尾空白后以 `判法「<判法名>」:` 起头。 */
44
+ const JUDGE_LAW_RE = /^判法「([^」]+)」:/
45
+
46
+ /** 判域行:去首尾空白后以 `**判域**:<判法名> —— ` 起头,余下是字段正文。 */
47
+ const JUDGE_DOMAIN_RE = /^\*\*判域\*\*:([^—\s]+)\s*——\s*(.+)$/
48
+
49
+ const USAGE = "node thincoder-core/agent-tools/judge-domain.mjs --doc <设计档> --record <批档>"
50
+
51
+ /**
52
+ * 边界拒绝:点名该输入与用法,退出码 2,零判决行。
53
+ * @param {string} message 拒绝原因(须点出缺哪个参数或哪份档)。
54
+ * @returns {never}
55
+ */
56
+ function boundary(message) {
57
+ process.stderr.write(`judge-domain: ${message}\n用法:${USAGE}\n`)
58
+ process.exit(2)
59
+ }
60
+
61
+ /**
62
+ * 取 `--doc` 与 `--record` 两个路径。两形都收:`--doc <path>` 与 `--doc=<path>`。
63
+ * 缺一个即边界拒绝并点名该参数;没有默认值。
64
+ * @param {string[]} argv `process.argv.slice(2)`
65
+ * @returns {{ doc: string, record: string }}
66
+ */
67
+ function parseArgs(argv) {
68
+ const picked = { doc: null, record: null }
69
+ for (let i = 0; i < argv.length; i += 1) {
70
+ const raw = argv[i]
71
+ if (!raw.startsWith("--")) boundary(`unexpected argument "${raw}" — only --doc and --record are taken`)
72
+ const eq = raw.indexOf("=")
73
+ const flag = eq > 0 ? raw.slice(0, eq) : raw
74
+ const key = flag === "--doc" ? "doc" : flag === "--record" ? "record" : null
75
+ if (key === null) boundary(`unknown argument "${flag}" — only --doc and --record are taken`)
76
+ if (picked[key] !== null) boundary(`duplicate ${flag} — pass each of --doc and --record exactly once`)
77
+ let value = eq > 0 ? raw.slice(eq + 1) : null
78
+ if (value === null) {
79
+ const next = argv[i + 1]
80
+ if (next === undefined || next.startsWith("--")) {
81
+ boundary(`missing value for ${flag} — both --doc and --record are required and carry no default`)
82
+ }
83
+ value = next
84
+ i += 1
85
+ }
86
+ if (value.trim() === "") boundary(`empty value for ${flag} — pass the path to the document it names`)
87
+ picked[key] = value
88
+ }
89
+ if (picked.doc === null) boundary("missing --doc <设计档> — the design document carrying §10.4 and §10.8 is required; there is no default")
90
+ if (picked.record === null) boundary("missing --record <批档> — the batch record carrying the 验收对照 table is required; there is no default")
91
+ return picked
92
+ }
93
+
94
+ /**
95
+ * 读一份 UTF-8 档;读不到就在边界拒绝并点名该参数与路径。
96
+ * @param {string} flag 参数名(`--doc` ∥ `--record`)
97
+ * @param {string} path 盘上路径
98
+ * @returns {string}
99
+ */
100
+ function readUtf8(flag, path) {
101
+ try {
102
+ return readFileSync(path, "utf8")
103
+ } catch (e) {
104
+ boundary(`${flag} ${path} is unreadable (${e?.code ?? e?.message ?? "unknown"}) — pass an absolute path or a path relative to the current directory`)
105
+ }
106
+ }
107
+
108
+ /**
109
+ * 取一份档里以某行起头的一节正文:从该行之后到下一个同级或更高级标题之前。
110
+ * @param {string} text 档全文
111
+ * @param {RegExp} headingRe 起头标题的匹配式(如 `/^### 10\.4\s/`)
112
+ * @returns {{ heading: string, lines: { text: string }[] } | null}
113
+ */
114
+ function sectionOf(text, headingRe) {
115
+ const lines = String(text).split(/\r?\n/)
116
+ const start = lines.findIndex((line) => headingRe.test(line))
117
+ if (start < 0) return null
118
+ const level = (lines[start].match(/^#+/) ?? [""])[0].length
119
+ const body = []
120
+ for (let i = start + 1; i < lines.length; i += 1) {
121
+ const nested = lines[i].match(/^(#+)\s/)
122
+ if (nested && nested[1].length <= level) break
123
+ body.push({ text: lines[i] })
124
+ }
125
+ return { heading: lines[start], lines: body }
126
+ }
127
+
128
+ /**
129
+ * 把一节正文读成 §10.4 的条目。条目 = 以 `- ` 起头的行 + 其后以空白起首的续行。
130
+ * 续行之间可以隔空行;未缩进的非空行结束该条目。围栏块整块不入条目正文(示例不是判据句子)。
131
+ * @param {{ text: string }[]} lines 一节的正文行
132
+ * @returns {{ firstLine: string, body: string[] }[]}
133
+ */
134
+ function entriesOf(lines) {
135
+ const entries = []
136
+ let current = null
137
+ let fenced = false
138
+ const close = () => {
139
+ if (current) entries.push(current)
140
+ current = null
141
+ }
142
+ for (const { text } of lines) {
143
+ if (/^\s*```/.test(text)) {
144
+ fenced = !fenced
145
+ continue
146
+ }
147
+ if (fenced) continue
148
+ if (/^-\s+/.test(text)) {
149
+ close()
150
+ current = { firstLine: text.replace(/^-\s+/, "").trim(), body: [] }
151
+ continue
152
+ }
153
+ if (current === null) continue
154
+ if (text.trim() === "") continue
155
+ if (/^[ \t]+\S/.test(text)) current.body.push(text.trim())
156
+ else close()
157
+ }
158
+ close()
159
+ return entries
160
+ }
161
+
162
+ /**
163
+ * 判据首句:该条目第一个 `:` 之前的文字;整条没有 `:` 时取该行全文。
164
+ * @param {string} firstLine 条目的 `- ` 行正文
165
+ * @returns {string}
166
+ */
167
+ function firstSentenceOf(firstLine) {
168
+ const cut = firstLine.indexOf(":")
169
+ return (cut < 0 ? firstLine : firstLine.slice(0, cut)).trim()
170
+ }
171
+
172
+ /**
173
+ * 读一条判域行的三字段。
174
+ * @param {string} rest `**判域**:<判法名> —— ` 之后的字段正文
175
+ * @returns {{ ok: true, fields: Map<string, string> } | { ok: false, reason: string }}
176
+ */
177
+ function domainFields(rest) {
178
+ const body = rest.trim().replace(/[。.]$/, "")
179
+ const fields = new Map()
180
+ for (const segment of body.split(";").map((s) => s.trim()).filter(Boolean)) {
181
+ const hit = segment.match(/^(对象|排除|止于)\s*=\s*([\s\S]*)$/)
182
+ if (!hit) return { ok: false, reason: `unlabeled segment "${segment}"` }
183
+ const label = hit[1]
184
+ const value = hit[2].trim()
185
+ if (fields.has(label)) return { ok: false, reason: `duplicate field ${label}` }
186
+ if (value === "") return { ok: false, reason: `empty field ${label}` }
187
+ if (PLACEHOLDER_MARKERS.some((marker) => value.includes(marker)) || PLACEHOLDER_ETC_RE.test(value)) {
188
+ return { ok: false, reason: `placeholder value in ${label}` }
189
+ }
190
+ fields.set(label, value)
191
+ }
192
+ for (const label of FIELD_LABELS) {
193
+ if (!fields.has(label)) return { ok: false, reason: `missing field ${label}` }
194
+ }
195
+ return { ok: true, fields }
196
+ }
197
+
198
+ /**
199
+ * 读 §10.4 的判据条目:每条带首句、判法行、判域行与判据正文(判法在内)。
200
+ * @param {string} docText 设计档全文
201
+ * @returns {{ firstSentence: string, laws: { name: string }[], domains: { name: string, rest: string }[], text: string }[] | null}
202
+ */
203
+ function criteriaOf(docText) {
204
+ const section = sectionOf(docText, /^#{2,4}\s*10\.4\s/)
205
+ if (section === null) return null
206
+ return entriesOf(section.lines).map((entry) => {
207
+ const laws = []
208
+ const domains = []
209
+ for (const line of entry.body) {
210
+ const law = line.match(JUDGE_LAW_RE)
211
+ if (law) {
212
+ laws.push({ name: law[1] })
213
+ continue
214
+ }
215
+ const domain = line.match(JUDGE_DOMAIN_RE)
216
+ if (domain) domains.push({ name: domain[1], rest: domain[2] })
217
+ }
218
+ // 判据正文 = 判据句 + 条目正文:判法行与判域行都在里面(§10.8「该判据自己的正文(判法在内)」)。
219
+ return { firstSentence: firstSentenceOf(entry.firstLine), laws, domains, text: [entry.firstLine, ...entry.body].join("\n") }
220
+ })
221
+ }
222
+
223
+ /**
224
+ * 读批档「验收对照」表里含 `判法「` 的数据行。判法名文本 = 验收行那一格里每个「…」,去掉点名前的那一个判据首句(`§10.4「…」`);`#` 列标签与期望列不参与。
225
+ * @param {string} recordText 批档全文
226
+ * @returns {{ label: string, firstSentence: string | null, lawNames: string[] }[] | null}
227
+ */
228
+ function acceptanceRowsOf(recordText) {
229
+ const section = sectionOf(recordText, /^#{2,4}\s*验收对照\s*$/)
230
+ if (section === null) return null
231
+ const rows = []
232
+ for (const line of section.lines) {
233
+ const text = line.text
234
+ if (!text.startsWith("|")) continue
235
+ if (/^\|[\s|:-]+\|?\s*$/.test(text)) continue
236
+ if (!text.includes("判法「")) continue
237
+ const cells = text.split("|").map((cell) => cell.trim())
238
+ const label = (cells[1] ?? "").replace(/`/g, "")
239
+ // 数字比对面 = 验收行那一格;`#` 列标签与期望列里的引文不进比对面。
240
+ const row = cells.find((each) => each.includes("判法「")) ?? ""
241
+ const first = row.match(/§10\.4「([^」]*)」/)
242
+ // 判法名文本 = 该格里每个「…」,去掉点名前那个判据首句:A6 形「判法「按行判」与「按义务判」」两个判法名都收。
243
+ const rest = first ? row.replace(first[0], "") : row
244
+ const lawNames = [...rest.matchAll(/「([^」]+)」/g)].map((m) => m[1])
245
+ rows.push({ label, firstSentence: first ? first[1] : null, lawNames })
246
+ }
247
+ return rows
248
+ }
249
+
250
+ /**
251
+ * 判据侧:判域行与判法行配不上对即报。条数不等、行首判法名不认判法行、三字段不成形都算。§10.8「判域行不成形」。
252
+ * @param {{ laws: { name: string }[], domains: { name: string, rest: string }[] }[]} criteria §10.4 的判据条目
253
+ * @param {(line: string) => void} report 收一条问题行(同一问题行只收一次)
254
+ */
255
+ function reportDomainPairing(criteria, report) {
256
+ for (const entry of criteria) {
257
+ if (entry.laws.length === 0 && entry.domains.length === 0) continue
258
+ const lawNames = entry.laws.map((law) => law.name)
259
+ for (const name of new Set(lawNames)) {
260
+ const lawCount = lawNames.filter((each) => each === name).length
261
+ const domainCount = entry.domains.filter((each) => each.name === name).length
262
+ if (lawCount !== domainCount) report(`判域行不成形 ${name}`)
263
+ }
264
+ for (const domain of entry.domains) {
265
+ if (!lawNames.includes(domain.name)) {
266
+ report(`判域行不成形 ${domain.name}`)
267
+ continue
268
+ }
269
+ if (!domainFields(domain.rest).ok) report(`判域行不成形 ${domain.name}`)
270
+ }
271
+ }
272
+ }
273
+
274
+ /**
275
+ * 验收侧:点不到判据首句、带判据正文没有的数,各报一行。§10.8 机检入口三类,第四类不报。
276
+ * @param {{ label: string, firstSentence: string | null, lawNames: string[] }[]} rows 批档验收行
277
+ * @param {Map<string, { text: string }>} byFirstSentence 判据首句 → 判据
278
+ * @param {(line: string) => void} report 收一条问题行
279
+ */
280
+ function reportAcceptanceRows(rows, byFirstSentence, report) {
281
+ for (const row of rows) {
282
+ if (row.firstSentence === null) {
283
+ report(`验收行指不到判据(未点名判据首句) —— 验收行 ${row.label}`)
284
+ continue
285
+ }
286
+ const criterion = byFirstSentence.get(row.firstSentence)
287
+ if (criterion === undefined) {
288
+ report(`验收行指不到判据 ${row.firstSentence} —— 验收行 ${row.label}`)
289
+ continue
290
+ }
291
+ // 两侧都按一个数比:判据正文也取连写的数字串,尺上的 4 不会因正文里有 45 就算「出现过」。
292
+ const criterionNumbers = new Set(criterion.text.match(/\d+/g) ?? [])
293
+ for (const name of row.lawNames) {
294
+ for (const run of name.match(/\d+/g) ?? []) {
295
+ if (!criterionNumbers.has(run)) report(`验收尺带判据没有的数 ${run} —— 验收行 ${row.label}`)
296
+ }
297
+ }
298
+ }
299
+ }
300
+
301
+ /**
302
+ * 判定入口:两份档缺本条读法要的章节、以及一条验收行都没有,都在边界拒绝;其余交给判据侧与验收侧分别收行。
303
+ * @param {{ docText: string, recordText: string, recordPath: string }} input 两份档的全文与批档路径(拒绝句要点名它)
304
+ * @returns {string[]} 问题行(零条 ⇒ PASS)
305
+ */
306
+ function judgeDomains({ docText, recordText, recordPath }) {
307
+ const criteria = criteriaOf(docText)
308
+ if (criteria === null) boundary("--doc carries no `### 10.4` section — §10.4 is the only place 判据 and their 判法 live")
309
+ const rows = acceptanceRowsOf(recordText)
310
+ if (rows === null) boundary("--record carries no `### 验收对照` section — that table is the only place 验收行 live")
311
+ // 零条验收行 = 这一趟什么都判不到:写 PASS 会把「一行都没判」报成「全过」,写 REFUSED 又指不出一条不成立的行。
312
+ // 两个判决词都不成立时走边界拒绝(与缺参数、缺章节同一出口),点名这一份档。
313
+ if (rows.length === 0) {
314
+ boundary(`--record ${recordPath} carries zero 验收行 — the \`## 验收对照\` table has 0 rows carrying 判法「, so nothing is judged and no verdict line is written`)
315
+ }
316
+
317
+ const problems = []
318
+ const seen = new Set()
319
+ const report = (line) => {
320
+ if (seen.has(line)) return
321
+ seen.add(line)
322
+ problems.push(line)
323
+ }
324
+
325
+ // 首句查表按 §10.4 读法:判据 = 条目正文含判域行的条目。首句是配对键,两条判据同句即无法配对,边界拒绝并点名。
326
+ const byFirstSentence = new Map()
327
+ for (const entry of criteria) {
328
+ if (entry.domains.length === 0) continue
329
+ if (byFirstSentence.has(entry.firstSentence)) {
330
+ boundary(`--doc has two §10.4 criteria with the same 首句「${entry.firstSentence}」 — the first sentence is the pairing key and has to be unique`)
331
+ }
332
+ byFirstSentence.set(entry.firstSentence, entry)
333
+ }
334
+
335
+ reportDomainPairing(criteria, report)
336
+ reportAcceptanceRows(rows, byFirstSentence, report)
337
+ return problems
338
+ }
339
+
340
+ const args = parseArgs(process.argv.slice(2))
341
+ const docText = readUtf8("--doc", args.doc)
342
+ const recordText = readUtf8("--record", args.record)
343
+
344
+ const found = judgeDomains({ docText, recordText, recordPath: args.record })
345
+ const verdict = found.length === 0 ? "JUDGE-DOMAIN: PASS" : "JUDGE-DOMAIN: REFUSED"
346
+ process.stdout.write([verdict, ...found].join("\n") + "\n")
347
+ process.exitCode = found.length === 0 ? 0 : 1
@@ -11,8 +11,8 @@
11
11
  * - `write` ⇒ **点改**:读现档 → 设节点 → 落盘(`writeManifest` 内先 `validateManifest`——
12
12
  * 编辑结果非法 ⇒ 拒 + 盘零变);**缺档 ⇒ 拒** + 引导 `init`(写不建档)。
13
13
  *
14
- * 写面白名单(判据单源 = `MANIFEST_SCHEMA`——钉死谓词):**13 个可写节点** = `keys` 中**非** `nestedKeys`
15
- * 父键者(`version` / `phase` / `codePaths` 整键)+ `nestedKeys` 子键(`docRoot.*` 六子键 / `index.*` 四子键);
14
+ * 写面白名单(判据单源 = `MANIFEST_SCHEMA`——钉死谓词):**15 个可写节点** = `keys` 中**非** `nestedKeys`
15
+ * 父键者(`version` / `phase` / `codePaths` 整键)+ `nestedKeys` 子键(`docRoot.*` 六子键 / `index.*` 六子键);
16
16
  * **两族整键写(传整个对象)⇒ 拒**;白名单外 ⇒ 拒(拼写保护——未知键写盘 = 静默死键,KD-M1-36 问题本体)。
17
17
  * `value` 解析 = 同款口径 `settings.mjs` 的 `parseValue`(先 `JSON.parse`,失败取字面串;`"null"` ⇒ `null`
18
18
  * ——`docRoot.*` 的「本面无」,KD-M1-37)。
@@ -22,7 +22,14 @@
22
22
  * 工作区塌缩 `null`(**回落发生在调用方 `writeRoot`,非本函数**)⇒ 写 / 建两动作**不得**直用。
23
23
  *
24
24
  * 写路径复用(零新写路径):落盘恒经 `writeManifest` / `initManifest`——`writer` 恒显式 `'main'`
25
- * (缺省 `'subagent'` = 写门 fail-closed 缺省,KD-M1-3 / AC-M1-5 零改)。
25
+ * (缺省 `'subagent'` = 写门 fail-closed 缺省,KD-M1-3 / AC-M1-5 零改)。**这里的「写门」= `writer` 身份闸**,
26
+ * 与下面那道不是同一道。
27
+ *
28
+ * **不在笔-账绑定写锁的入口集**(2026-11-10 整把出集批 · 决策 44):`read` ∥ `init` ∥ `write` 三动作一律不要
29
+ * 台账号、不要项目声明——本工具写的这份档正是写锁的输入(取根 ∥ 读 `index.writableRepos` 判跨仓),把写它
30
+ * 也放在门后就成环(档缺失建不出项目、档坏修不回来)。机制与理由单源 = `docs/core/design/BATCH-LEDGER-REVIEW-UNIFY.md`
31
+ * §2.3「`manifest` 不进写门」;该出口因此不在 `thincoder-core/agent/write-gate-ledger.mjs` 的入口集里,
32
+ * `ledger` ∥ `project` 两格也不在本工具的 `parameters.properties`(名字只为被读的地方存在)。
26
33
  *
27
34
  * 报告面随动(KD-M1-40):本工具**不写** `agent.manifest`(第二值源否——工具目标可为非锚项目)——
28
35
  * 写盘 = 盘面变化,情境行经既有 ③b mtime 门控于下回合采纳(`agent/setup-reminders.mjs`)。
@@ -37,9 +44,9 @@
37
44
  * (`readonly: false` = 动作级分类面,只读性归 `dispatch-gates` 的 `read` 判定)。
38
45
  */
39
46
  import { existsSync } from "node:fs"
40
- import { join, resolve } from "node:path"
47
+ import { isAbsolute, join, resolve } from "node:path"
41
48
  import { MANIFEST_REL, MANIFEST_SCHEMA, initManifest, projectRootView, projectView, readManifest, writeManifest } from "../manifest.mjs"
42
- import { DESC, LEDGER_PARAM_DESC_MANIFEST, PROJECT_PARAM_DESC } from "../tools/shared.mjs"
49
+ import { DESC } from "../tools/shared.mjs"
43
50
  import { clearDeclarationCache } from "../conventions.mjs" // #1367 面⑦:写档成功 ⇒ 缓存失效(fix 轮接线)
44
51
 
45
52
  /** 拒面统一前缀(设计 §2.10:`manifest <action>: refused — …`)——盘零变类拒绝一律经此抛错。 */
@@ -47,11 +54,23 @@ function refuse(action, reason) {
47
54
  return new Error(`manifest ${action}: refused — ${reason}`)
48
55
  }
49
56
 
50
- /** `target` 解析(先例 `eng.mjs` 的 `resolveEngineeringManifest` 缺省会话锚 ∥ `git.mjs` 的 `resolveBaseDir` 相对形归一):缺省 = 会话锚
51
- * (`ctx.agent.cwd ?? ctx.cwd`);显式相对形按会话锚归一(绝对形原样)。 */
52
- function resolveTarget(args, ctx) {
57
+ /** `target` 解析:`target` 必填;`base` 只作相对形基根。缺 ∥ 空串 ∥ `null` ⇒ 抛、报文点名 `target`,零判定
58
+ * (不拿锚替调用方选根)。`base` = `ctx.agent.cwd ?? ctx.cwd`(KD-9);绝对形原样。 */
59
+ function resolveTarget(action, args, ctx) {
53
60
  const base = ctx?.agent?.cwd ?? ctx?.cwd
54
- return args?.target ? resolve(base, String(args.target)) : resolve(base)
61
+ const given = args?.target
62
+ if (typeof given !== "string" || given.trim() === "") {
63
+ throw new Error(`manifest ${action}: target is required — pass the project root or directory you mean (an absolute path, or a path relative to the session anchor); there is no default.`)
64
+ }
65
+ // 锚只作**相对形**的基根(KD-9):锚缺位 + 相对形 ⇒ 拒、点名锚——不许落 `process.cwd()`
66
+ // (同 `thincoder-core/agent-tools/doc-check.mjs` 的同支,全批共用契约)。
67
+ if (!base) {
68
+ if (!isAbsolute(given)) {
69
+ throw new Error(`manifest ${action}: target is required as an absolute path — no session anchor is available (\`ctx.agent.cwd\` / \`ctx.cwd\` both empty), so a relative \`target\` has no base to resolve against.`)
70
+ }
71
+ return resolve(given)
72
+ }
73
+ return resolve(base, given)
55
74
  }
56
75
 
57
76
  /** 写面白名单谓词(**钉死**——设计 §2.10):点分路径恰两形——
@@ -131,14 +150,11 @@ export const manifestTool = {
131
150
  type: "object",
132
151
  properties: {
133
152
  action: { type: "string", enum: ["read", "init", "write"], description: "read — current manifest + validation state (five-state anchor, never throws); init — create the default manifest when missing (refused when one already exists); write — point-edit one node (key + value) of an existing manifest" },
134
- target: { type: "string", description: "Explicit target directory — defaults to the session anchor; relative paths resolve against it. A workspace target (several projects below it) is refused with the full project list — pass the project root you mean." },
153
+ target: { type: "string", description: "Required — pass the project root or directory you mean (relative paths resolve against the session anchor; a workspace target is reported with its project list)" },
135
154
  key: { type: "string", description: "(write) Dot path of the node to set — version / phase / codePaths, or a sub-key of docRoot / index (e.g. docRoot.design / index.publicRepos); whole-object writes of those two families are refused", },
136
155
  value: { type: "string", description: "(write) New value — parsed as JSON first (null / true / 5 / [\"a\"]), otherwise kept as a literal string; \"null\" is the explicit no-such-face for docRoot.<key>" },
137
- ledger: { type: "string", description: LEDGER_PARAM_DESC_MANIFEST },
138
- // 项目声明面(决策 40):`target` 缺位时才被读(定位参数优先);纯声明,不改查/建的目标目录。
139
- project: { type: "string", description: PROJECT_PARAM_DESC },
140
156
  },
141
- required: ["action"],
157
+ required: ["action", "target"],
142
158
  },
143
159
  readonly: false, // 动作级分类(dispatch-gates `isReadonlyAction`):read = 只读类;init / write 保持侧效门
144
160
  async execute(args, ctx) {
@@ -146,7 +162,7 @@ export const manifestTool = {
146
162
  if (!["read", "init", "write"].includes(action)) {
147
163
  throw new Error(`manifest: action must be one of read/init/write — got ${JSON.stringify(action)}`)
148
164
  }
149
- const target = resolveTarget(args, ctx)
165
+ const target = resolveTarget(action, args, ctx)
150
166
 
151
167
  if (action === "read") return readAction(target)
152
168
 
@@ -220,15 +236,15 @@ export const manifestReadTool = {
220
236
  type: "object",
221
237
  properties: {
222
238
  action: { type: "string", enum: ["read"], description: "read — current manifest + validation state (five-state anchor, never throws)" },
223
- target: { type: "string", description: "Explicit target directory — defaults to the session anchor; relative paths resolve against it. A workspace target (several projects below it) is reported with the full project list — pass the project root you mean." },
239
+ target: { type: "string", description: "Required — pass the project root or directory you mean (relative paths resolve against the session anchor; a workspace target is reported with its project list)" },
224
240
  },
225
- required: ["action"],
241
+ required: ["action", "target"],
226
242
  },
227
243
  readonly: true,
228
244
  async execute(args, ctx) {
229
245
  if (args?.action !== "read") {
230
246
  throw new Error(`manifest read: refused — this read-only variant exposes only action=read (got ${JSON.stringify(args?.action)})`)
231
247
  }
232
- return readAction(resolveTarget(args, ctx), { canInit: false })
248
+ return readAction(resolveTarget("read", args, ctx), { canInit: false })
233
249
  },
234
250
  }
@@ -14,7 +14,7 @@
14
14
  * consult / depth-0 不装配);调用**同步返回**(零 await、零等待态——本档不提供任何拉取 /
15
15
  * 轮询 / 等答复动作:D-UC3 非阻塞 = 结构保证)。
16
16
  * - 父侧接收 = 队列 `_childUpstream`(数组;条目 `{seq, from, kind, message, ts}`)+ 单调计数
17
- * `_childUpstreamSeq`——**两字段皆属载体字段集**(AGENT-LOOP.md §2.3,与 `_asyncQueue` /
17
+ * `_childUpstreamSeq`——**两字段皆属载体字段集**(AGENT-LOOP.md §9.1,与 `_asyncQueue` /
18
18
  * `_asyncAdvisorQueue` 同列):读单点 = `async-settle.mjs` 的 `carrierField`,写单点 = 本档的
19
19
  * `upstreamHolder`(父字段优先 / `history` 命中即借用 / 皆无则建在父字段 + 载体别名)。
20
20
  * 生命周期与子代理生命周期**解耦**(settle / cancel 不迁移、不清队列——F3)。
@@ -40,7 +40,7 @@
40
40
  * 登记册导出(`agent-tools.mjs`)→ 家族矩阵装配(`agent/family-tools.mjs` depth>0 段)。
41
41
  */
42
42
  import { carrierField, getAsyncPool, tombstoneOf, wakeAsyncWaiters } from "./async-settle.mjs"
43
- import { pushReal } from "../context.mjs"
43
+ import { pushInject, pushRecord } from "../context.mjs"
44
44
  import { escapeXml } from "../agent/helpers.mjs"
45
45
  import { logEvent } from "../log.mjs"
46
46
  // #15 描述外置:描述文本单点 = tool-docs/notify_parent.md(DESC 单解析面,缺档抛错语义不变)
@@ -172,7 +172,10 @@ export function drainChildUpstream(agent) {
172
172
  : `[System reminder: in-flight message from your subagent ${entries[0].from} — it keeps working on the unaffected parts. `
173
173
  + "Answer with subagent action:'send' (id + message) if the decision is yours; an unanswered ask means the child skips that part and reports it as not done.]"
174
174
  const rows = entries.map((e) => `${many ? "- " : ""}${KIND_MARK[e.kind] ?? e.kind} · ${e.from}: ${escapeXml(e.message)}${endNote(agent, e)}`)
175
- pushReal(agent, { role: "user", content: [header, ...rows].join("\n") })
175
+ const msg = { role: "user", content: [header, ...rows].join("\n") }
176
+ // B 段:一次性投递走待发队,持久写入只落人读线(机读线零触)。
177
+ pushInject(agent, msg)
178
+ pushRecord(agent, msg)
176
179
  return entries.length
177
180
  }
178
181
 
@@ -7,6 +7,7 @@
7
7
  * user sends a new message — so the constraint never fades from context.
8
8
  */
9
9
  import { DESC } from "../tools/shared.mjs"
10
+ import { pushInject } from "../context.mjs"
10
11
 
11
12
  const PLAN_FULL_REMINDER =
12
13
  "[System reminder: plan mode is ON. Workflow: (1) explore/read codebase with read-only tools, " +
@@ -35,12 +36,14 @@ const FULL_INTERVAL = 5
35
36
  export const PLAN_ENGINEERING_REFUSED =
36
37
  "plan mode is disabled in engineering mode — engineering mode already runs design-before-code (design → review → approval → implementation)."
37
38
 
38
- /** ENG-PLAN-EXCLUSION(FR31 ③ · KD10):未注入 plan 提示语判据 = 三条 reminder 常量逐字组成员。 */
39
- const isPlanReminder = (r) => r === PLAN_FULL_REMINDER || r === PLAN_SPARSE_REMINDER || r === PLAN_EXIT_REMINDER
39
+ /** ENG-PLAN-EXCLUSION(FR31 ③ · KD10):未注入 plan 提示语判据 = 三条 reminder 常量逐字组成员。
40
+ * 待发队(B 段)里的条目已升级为消息对象 ⇒ 判据读 `content`(与 `history` 时代同一个逐字面)。 */
41
+ const isPlanReminder = (content) => content === PLAN_FULL_REMINDER || content === PLAN_SPARSE_REMINDER || content === PLAN_EXIT_REMINDER
42
+ const isPlanInject = (m) => isPlanReminder(m?.content)
40
43
 
41
44
  /**
42
45
  * ENG-PLAN-EXCLUSION(FR31 ③ / KD10——单点复用):工程模式 ⇒ `planMode` 恒 false。
43
- * 清 `planMode` + 两 reminder 计数 + **未注入的 plan 提示语**(`_pendingReminders` 中的三条
46
+ * 清 `planMode` + 两 reminder 计数 + **未注入的 plan 提示语**(待发队 `_pendingInject` 中的三条
44
47
  * plan 提醒——否则排队的 `PLAN_EXIT_REMINDER`「Present your plan … wait for their explicit approval …」会在模式翻转后
45
48
  * 落地,与工程链条打架)。五个挂点复用本函数:三翻转(核 `eng` 工具 / CLI `/eng` / VSC 面板开关)
46
49
  * + 两恢复(CLI `applySession` / VSC `applySlotSessionState`)。
@@ -49,13 +52,13 @@ const isPlanReminder = (r) => r === PLAN_FULL_REMINDER || r === PLAN_SPARSE_REMI
49
52
  */
50
53
  export function clearPlanMode(agent) {
51
54
  if (!agent) return false
52
- const queued = Array.isArray(agent._pendingReminders) ? agent._pendingReminders.filter(isPlanReminder).length : 0
55
+ const queued = Array.isArray(agent._pendingInject) ? agent._pendingInject.filter(isPlanInject).length : 0
53
56
  const had = agent.planMode === true || queued > 0
54
57
  agent.planMode = false
55
58
  agent._planTurnsSinceReminder = 0
56
59
  agent._planTurnsSinceSparse = 0
57
- if (Array.isArray(agent._pendingReminders)) {
58
- agent._pendingReminders = agent._pendingReminders.filter((r) => !isPlanReminder(r))
60
+ if (Array.isArray(agent._pendingInject)) {
61
+ agent._pendingInject = agent._pendingInject.filter((m) => !isPlanInject(m))
59
62
  }
60
63
  return had
61
64
  }
@@ -103,8 +106,7 @@ export const planTool = {
103
106
  if (args.action === "exit") {
104
107
  ctx.agent.planMode = false
105
108
  ctx.agent._planTurnsSinceReminder = 0
106
- ctx.agent._pendingReminders = ctx.agent._pendingReminders ?? []
107
- ctx.agent._pendingReminders.push(PLAN_EXIT_REMINDER)
109
+ pushInject(ctx.agent, { role: "user", content: PLAN_EXIT_REMINDER })
108
110
  return "Plan mode exited. Present your plan to the user and wait for their explicit approval before writing any code."
109
111
  }
110
112
  if (args.action !== "enter") {
@@ -112,8 +114,7 @@ export const planTool = {
112
114
  }
113
115
  ctx.agent.planMode = true
114
116
  ctx.agent._planTurnsSinceReminder = 0
115
- ctx.agent._pendingReminders = ctx.agent._pendingReminders ?? []
116
- ctx.agent._pendingReminders.push(PLAN_FULL_REMINDER)
117
+ pushInject(ctx.agent, { role: "user", content: PLAN_FULL_REMINDER })
117
118
  return "Plan mode activated. You are now restricted to READ-ONLY tools. Explore the codebase, understand the architecture, design a solution. Present your plan to the user for approval before writing any code."
118
119
  },
119
120
  }