@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,25 @@
1
1
  /**
2
2
  * agent/completion.mjs — handle model response with no tool calls
3
3
  *
4
- * Checks: pending tasks, verify guard, advisor guard.
4
+ * Checks: verify guard, advisor guard.
5
5
  * Returns { action: 'continue' | 'done', content?, guardPushbacks, honestReminderInjected, advisorPushbacks }
6
6
  * 子回合边界(#628):六推回点各触 `callbacks.onSubTurnBreak?.()` —— 零参可选(缺省 no-op);`onTurnEnd` 超集语义零改。
7
7
  */
8
8
  import { hasCodeMutations } from "../advisor/repos.mjs"
9
- import { pushReal } from "../context.mjs"
9
+ import { pushReal, pushInject } from "../context.mjs"
10
+ import { specForModel, assistantTextMessage, isThinkingRequest } from "../config.mjs"
10
11
  import { advisorReviewPending, effectiveAdvisorRound } from "../agent-tools/advisor-async.mjs"
11
- import { poolLive } from "./suspension.mjs"
12
12
 
13
13
  const MAX_VERIFY_PUSHBACKS = 2
14
14
  const MAX_VERIFY_RETRIES = 3
15
15
  const MAX_ADVISOR_PUSHBACKS = 3
16
+ // 层 2(ADVISOR-CONVERGENCE.md §6.4 B):同一未评审周期的提醒硬上限——续跑与段重启都不回满。
17
+ // 取 5 而非 3:进展窗口预算保持原值 3,周期上限再给一次「真改了代码还是漏评审」的宽限。
18
+ const MAX_ADVISOR_REMINDERS = 5
16
19
  const MAX_EMPTY_RETRIES = 2
17
20
 
18
21
  /**
19
- * 响应「有实质」判据(单源——判空面与清零面读同一份;AGENT-LOOP.md §6.5① · D-AL28):有非空正文
22
+ * 响应「有实质」判据(单源——判空面与清零面读同一份;AGENT-LOOP.md §6 完成守卫 · D-AL28):有非空正文
20
23
  * **或** 有工具调用 ⇒ 实质,两种形都证明「刚才那次空是瞬时的」。此处也是唯一判空式,不另写
21
24
  * `.trim() === ""`——两份一漂,判空与清零就不再是同一件事(判空加宽、清零面漏跟)。
22
25
  * 「或」不是「且」:带工具调用但正文为空(提供端常见形态)必须判为实质——写成「且」,工具轮就不清零,
@@ -28,7 +31,17 @@ export function isSubstantiveResponse(response) {
28
31
  }
29
32
 
30
33
  /**
31
- * Handle a model turn with zero tool calls. May push back (verify/advisor/pending tasks)
34
+ * 纯文本收尾入线(#2647 · 回声键的写面):assistant 消息带上 `reasoning_content`——有原文写原文,
35
+ * 无原文在思考模式下写空串。旧写法只 push `content`,服务端给的原文与「没有原文」都进不了机读历史,
36
+ * 下一次以工具结果结尾的请求就缺键 400(真机读数:同一失败体补键 200、缺键 400)。
37
+ */
38
+ function pushAssistantText(agent, response) {
39
+ const spec = specForModel(agent.provider?.model)
40
+ pushReal(agent, assistantTextMessage(response, spec, isThinkingRequest(agent.provider ?? null, spec), agent.provider ?? null))
41
+ }
42
+
43
+ /**
44
+ * Handle a model turn with zero tool calls. May push back (verify/advisor)
32
45
  * or accept the completion.
33
46
  *
34
47
  * @param {object} agent
@@ -50,7 +63,7 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
50
63
  const retries = agent._emptyRetries ?? 0
51
64
  if (retries < MAX_EMPTY_RETRIES) {
52
65
  agent._emptyRetries = retries + 1
53
- agent.history.push({
66
+ pushInject(agent, {
54
67
  role: "user",
55
68
  content: "[System reminder: your last response was empty — the provider returned no content (likely reasoning was exhausted or output was truncated). Respond again, continuing your work from where you left off.]",
56
69
  })
@@ -65,28 +78,6 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
65
78
  )
66
79
  }
67
80
 
68
- // Pending tasks: remind the model ONCE before it declares itself done.
69
- // Deliberately capped at one pushback (reported pain: unbounded looping when a
70
- // pending item can't be resolved). After the single reminder the model is free
71
- // to finish — updating the task list (task tool) resets the budget, so a fresh
72
- // list state earns one fresh reminder.
73
- // F10(催更门连带):工程模式下 task 工具机械停用(装配摘除 + execute 拒)⇒ 不再发指向被拒
74
- // 工具的提醒(死胡同提醒防线);列表本体与 `_taskPushbacks` 预算语义零改。
75
- // TIMEOUT-DIGEST.md §2.3(#29):后台池 live 时不推回——池在飞时回合本就还会被 settle 唤醒,
76
- // 此时催 task 只会拖回合;判据复用 `poolLive`(与挂起尾巴同一口径,不立第二处)。
77
- if (depth === 0 && !agent.config?.agent?.engineering && !poolLive(agent) && agent.tasks.some((t) => t.status === "pending") && (agent._taskPushbacks ?? 0) < 1) {
78
- agent._taskPushbacks = (agent._taskPushbacks ?? 0) + 1
79
- const pending = agent.tasks.filter((t) => t.status === "pending").map((t) => t.title).join(", ")
80
- pushReal(agent, { role: "assistant", content: response.content })
81
- agent.history.push({
82
- role: "user",
83
- content: `[System reminder: you still have pending tasks: ${pending}. Update their status with the task tool before finishing — if they're done, mark them done; if they're not applicable, remove them. (This is your only reminder — if you choose not to, finish anyway.)]`,
84
- })
85
- callbacks.onSubTurnBreak?.()
86
- callbacks.onTurnEnd?.(agent, turn)
87
- return { action: "continue", guardPushbacks, honestReminderInjected, advisorPushbacks }
88
- }
89
-
90
81
  // --- verify guard: push model to verify mutated files before completion ---
91
82
  // OPT-IN ONLY (verifyGuard: true). Engineering mode is excluded because it
92
83
  // uses flow-driven review, not per-turn mechanical pushback (ENGINEERING-MODE.md §2.3).
@@ -96,8 +87,8 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
96
87
  // Not verified yet → pushback to run verify
97
88
  if (agent._mutatedThisRun && !agent._verifiedThisRun && hasCodeMutations(agent) && guardPushbacks < MAX_VERIFY_PUSHBACKS) {
98
89
  guardPushbacks++
99
- pushReal(agent, { role: "assistant", content: response.content })
100
- agent.history.push({
90
+ pushAssistantText(agent, response)
91
+ pushInject(agent, {
101
92
  role: "user",
102
93
  content: "[System reminder: you modified files in this run but have not verified the changes. Before finishing: run the project's verification yourself (per its AGENTS.md test method), then call verify declaring the outcome via verification.status. verify mechanically gates on your declaration. If verification is genuinely impossible here, say so explicitly in your reply.]",
103
94
  })
@@ -110,8 +101,8 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
110
101
  // reason, or not declared — not necessarily that a test failed.
111
102
  if (agent._verifiedThisRun && agent._verifyPassed === false && agent._verifyRetries < MAX_VERIFY_RETRIES) {
112
103
  agent._verifyRetries++
113
- pushReal(agent, { role: "assistant", content: response.content })
114
- agent.history.push({
104
+ pushAssistantText(agent, response)
105
+ pushInject(agent, {
115
106
  role: "user",
116
107
  content: `[System reminder: (retry ${agent._verifyRetries}/${MAX_VERIFY_RETRIES}) verify was not passed — either your verification declared failed, was skipped without a reason, or was not declared. Fix or complete your verification, then call verify again declaring the outcome. If you cannot fix after ${MAX_VERIFY_RETRIES} attempts, explain honestly what's blocking you.]`,
117
108
  })
@@ -122,12 +113,12 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
122
113
  // Exhausted retries — inject honesty reminder once
123
114
  if (agent._verifiedThisRun && agent._verifyPassed === false && agent._verifyRetries >= MAX_VERIFY_RETRIES) {
124
115
  if (honestReminderInjected) {
125
- pushReal(agent, { role: "assistant", content: response.content })
116
+ pushAssistantText(agent, response)
126
117
  return { action: "done", content: response.content, guardPushbacks, honestReminderInjected, advisorPushbacks }
127
118
  }
128
119
  honestReminderInjected = true
129
- pushReal(agent, { role: "assistant", content: response.content })
130
- agent.history.push({
120
+ pushAssistantText(agent, response)
121
+ pushInject(agent, {
131
122
  role: "user",
132
123
  content: `[System reminder: ${MAX_VERIFY_RETRIES} verify attempts exhausted. You have not passed verification. Either state explicitly that your verification could not be completed, or run verify again once it is. If your verification could not be completed, say so explicitly in your reply to the user — state what you tried and what you believe is blocking you, and do not present the work as complete; the user needs to know it is unfinished.]`,
133
124
  })
@@ -152,13 +143,51 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
152
143
  const pending = advisorReviewPending(agent)
153
144
  // rounds 仅作提醒文案显示(撤 cap——轮次不是终止判据;ADVISOR-CONVERGENCE.md §3.1)。
154
145
  const rounds = effectiveAdvisorRound(agent)
155
- if (!pending && agent._mutatedThisRun && !agent._calledAdvisorThisRun && hasCodeMutations(agent)
156
- && advisorPushbacks < MAX_ADVISOR_PUSHBACKS) {
146
+ // 「未评审即收尾」的四项合取(既有判据逐字零改)+ 两支出口(推回一条 ∥ 任一层停推后的到顶诚实提醒,§6.4 A/B)。
147
+ // `!pending` 同属两支的一部分:异步评审在飞 = 未决,不是未评审——此时推「未经评审」的诚实声明
148
+ // 会与正在跑的评审自相矛盾。
149
+ const unreviewed = !pending && agent._mutatedThisRun && !agent._calledAdvisorThisRun && hasCodeMutations(agent)
150
+ // 层 1(进展窗口,§6.4 A)+ 层 2(未评审周期,§6.4 B)都还有余量 ⇒ 推一条。
151
+ // 计数落 agent:回合环那个 `advisorPushbacks` 是 `runAgent` 局部量,续跑重进即归零(上限形同没设)。
152
+ if (unreviewed && (agent._advisorReminders ?? 0) < MAX_ADVISOR_REMINDERS && advisorPushbacks < MAX_ADVISOR_PUSHBACKS) {
153
+ agent._advisorReminders = (agent._advisorReminders ?? 0) + 1
157
154
  advisorPushbacks++
158
- pushReal(agent, { role: "assistant", content: response.content })
159
- agent.history.push({
155
+ pushAssistantText(agent, response)
156
+ pushInject(agent, {
157
+ role: "user",
158
+ content: `[System reminder: you changed code in this run and MUST get an advisor review before finishing (round ${rounds + 1}). Call the \`advisor\` tool now. This is required, not optional — do not skip it even if you believe the changes are trivial — the review will be quick either way. After the review, produce a response table for every issue found (see discipline rules for format).${
159
+ agent._advisorReminders >= MAX_ADVISOR_REMINDERS
160
+ ? ` This is reminder ${MAX_ADVISOR_REMINDERS} of ${MAX_ADVISOR_REMINDERS} — the last one. If you deliver without an advisor review, state explicitly in your reply to the user that this code has not been reviewed.`
161
+ : ""
162
+ }]`,
163
+ })
164
+ callbacks.onSubTurnBreak?.()
165
+ callbacks.onTurnEnd?.(agent, turn)
166
+ return { action: "continue", guardPushbacks, honestReminderInjected, advisorPushbacks }
167
+ }
168
+ // **任一层停推**(层 1 或层 2 耗尽 ⇒ 本轮推不成)⇒ 推**一条**诚实提醒,其后本轮放行收尾。
169
+ // 判据不写成「推满 5 条」:层 1 的预算只在真写了文件时回满(§6.4 A),所以「改过一次代码后只读不写」
170
+ // 是最常见形态——层 1 停在 3 条时只认 5 条的到顶条件永不成真,两支都不进 ⇒ 直接 `done`、零诚实提醒,
171
+ // 正是本机制要挡的「未评审即交付且静默」。
172
+ // 到顶静默放行 = 把「未评审即交付」这条业务失败做成静默成功,而这道 guard 存在的目的就是挡它:
173
+ // 形态照 verify 面到顶(本档上方 `// Exhausted retries — inject honesty reminder once`)——同形、
174
+ // 只换主语,不新增用户可见标记 / 字段 / 配置键。
175
+ // 一次性位的复位口径(§1 20:39 裁定):位**随新进展复位**——与推回预算同一处(`turn-loop.mjs` 的写序推进
176
+ // 点,两行手拉手),另在本周期两处复位点(新用户回合起点 ∥ 评审覆盖成立处)一并归假。故口径是
177
+ // 「每次停推且仍未评审的收尾恰得一条诚实提醒」——不存在「发过一条之后本周期彻底静默」的第二条静默途径,
178
+ // 而「本轮发过就再也不发」会让「诚实提醒 → 又改代码 → 再收尾」整段不吭声(正是本批要堵的形状)。
179
+ // 文案只陈述事实(几条已发 ∥ 代码未评审 ∥ 二选一),**不**许诺「不再推」——层 1 先耗尽的形态下,
180
+ // 后续有新进展仍会再推提醒(§1 20:39 裁定第二条)。条数取 `?? 0`:复位点 2 清零后层 1 耗尽可达,别读出 undefined。
181
+ if (
182
+ unreviewed
183
+ && ((agent._advisorReminders ?? 0) >= MAX_ADVISOR_REMINDERS || advisorPushbacks >= MAX_ADVISOR_PUSHBACKS)
184
+ && !agent._advisorHonestySent
185
+ ) {
186
+ agent._advisorHonestySent = true
187
+ pushAssistantText(agent, response)
188
+ pushInject(agent, {
160
189
  role: "user",
161
- content: `[System reminder: you changed code in this run and MUST get an advisor review before finishing (round ${rounds + 1}). Call the \`advisor\` tool now. This is required, not optional — do not skip it even if you believe the changes are trivial — the review will be quick either way. After the review, produce a response table for every issue found (see discipline rules for format).]`,
190
+ content: `[System reminder: ${agent._advisorReminders ?? 0} advisor reminders sent. You have not had this code reviewed. Either call the \`advisor\` tool now, or state explicitly in your reply that this code has not been reviewed — do not present the work as reviewed. The user needs to know it is unreviewed.]`,
162
191
  })
163
192
  callbacks.onSubTurnBreak?.()
164
193
  callbacks.onTurnEnd?.(agent, turn)
@@ -166,6 +195,6 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
166
195
  }
167
196
  }
168
197
 
169
- pushReal(agent, { role: "assistant", content: response.content })
198
+ pushAssistantText(agent, response)
170
199
  return { action: "done", content: response.content, guardPushbacks, honestReminderInjected, advisorPushbacks }
171
200
  }
@@ -3,23 +3,29 @@
3
3
  * 同形重复族 #127 ④(续跑循环双写——CLI `thincoder-cli/src/tui/agent-turn.mjs` ∥ VSC
4
4
  * `thincoder-vscode/src/extension/panel-turn-loop.mjs`)收口:端壳循环只接线本函数,
5
5
  * 零第二分支;判定口径改一处 ⇒ 两端同轮生效(原双改纪律退役)。
6
- * 三格判定(口径 = TURN-CAP-CONTINUE.md D-TC15 ∕ F8):
7
- * ① ContinueError(撞帽)——无人值守档(autoTurn)⇒ "cap-stop"(不静默自续);
8
- * 人工档 ⇒ "ask"(续期恒须人答——AUTO 亦不自动批准)。
6
+ * 三格判定(口径 = `docs/core/design/TURN-CAP-CONTINUE.md` §2 ∥ §6 D-TC20):
7
+ * ① ContinueError(撞帽)——`autoApprove` 真(AUTO 档:用户已授权无人值守继续)⇒ "resume",
8
+ * 续期不再询问;假(手动档)⇒ "ask"(问「Continue?」,与用户回合问出同一句话)。
9
+ * 轮次类型不进这一支,此刻有没有人可问也不进——判据轴是批准档。
9
10
  * ② 中止(AbortError ∥ reason 在场)——带注入消息的 interrupt(Ctrl+I)⇒ "resume";其余 ⇒ "stop"。
10
11
  * ③ 其余错误 ⇒ "error";无错误(正常完成)⇒ "done"。
11
12
  * `reason` = 调用方解析后的中止 reason(两端同式 = 回合 controller `signal.reason` 单源——#677 修正轮对齐;
12
13
  * 核不臆测宿主 signal 源)。
13
- * `autoApprove` = 接口承载(#127 形);现语义下不改判定(F8 ∕ D-TC15)。
14
+ * `autoApprove` = 必填布尔(本端批准档):缺参 ∥ 非布尔在边界拒收并点名参数——缺省 false 会让
15
+ * 无人值守回合静默停在无人可见的询问上。它是主 agent 回合的判定点;异步子执行体的续跑走父侧
16
+ * 检查点,同步子执行体撞帽由用户卡裁定,都不经本函数(`docs/core/design/TURN-CAP-CONTINUE.md` §2)。
14
17
  */
15
18
  import { ContinueError } from "./helpers.mjs"
16
19
 
17
- /** @returns {"done"|"cap-stop"|"ask"|"resume"|"stop"|"error"} */
18
- export function continueDecision(error, { autoTurn = false, autoApprove = false, reason = null } = {}) {
20
+ /** @returns {"done"|"resume"|"ask"|"stop"|"error"} */
21
+ export function continueDecision(error, { autoApprove, reason = null } = {}) {
22
+ if (typeof autoApprove !== "boolean") {
23
+ throw new Error("continueDecision: autoApprove is required and must be a boolean — pass this end's approval tier (the caller's `autoApprove`); an absent default would park an unattended turn on a question nobody sees")
24
+ }
19
25
  if (error == null) return "done"
20
- if (error instanceof ContinueError) return autoTurn ? "cap-stop" : "ask"
26
+ if (error instanceof ContinueError) return autoApprove ? "resume" : "ask"
21
27
  if (error.name === "AbortError" || reason != null) {
22
28
  return reason?.interrupt && reason?.message ? "resume" : "stop"
23
29
  }
24
30
  return "error"
25
- }
31
+ }
@@ -1,35 +1,39 @@
1
1
  /**
2
- * agent/digest-account.mjs — 消化账务单件(AGENT-LOOP-ASYNC-POOL.md §6.31 · 批 digest-accounting ·
3
- * 台账 #930;批 digest-retry-amplify · 台账 #1850:投递恒一次):投递 ≠ 销账——报告不许无声消失。
2
+ * agent/digest-account.mjs — 消化账务单件(AGENT-LOOP-ASYNC-POOL.md §8 · 批 digest-accounting ·
3
+ * 台账 #930;批 digest-retry-amplify · 台账 #1850:**投递恒一次**——模型明写 `deferred` 与沉默同判,
4
+ * 两者都只计未签收轮、都不触发第二次投递):投递 ≠ 销账——报告不许无声消失。
4
5
  *
5
- * 三角色(§6.31.2):**投递**(注入但留容器——每条恒一次)/ **见账**(消化轮收尾逐条机检账目覆盖)/
6
+ * 三角色(§8.1):**投递**(注入但留容器——每条恒一次)/ **见账**(消化轮收尾逐条机检账目覆盖)/
6
7
  * **销账**(覆盖才离容器 + 释放 report;未覆盖计一个未签收轮,达 `DA_MISS_LIMIT` ⇒ 升级)。本档承载:
7
- * 常量(`DA_MISS_LIMIT`)/ 回合分类(`isDigestRound`)/ 投递门控(`shouldDeliverEntry`)/ 账目合同
8
- * (`coversDigestId` 解析 ∥ `digestAccountRequirement` 要求行)/ 见账 pass(`accountDigestRound`——
9
- * 销账 ∥ 未签收轮 ∥ 升级四步含终局披露)/ 读面(`unsettledRows` · `unsettledRow` · `unsettledCount`)/
10
- * 落痕清位 ∕ 取件助手(`armAccountRound` · `harvestAccountOutput`)。
8
+ * 常量(`DA_MISS_LIMIT`)/ 回合分类(`isDigestRound`)/ 投递门控(`shouldDeliverEntry`)/
9
+ * 账目合同(`digestDisposition` 处置词解析 ∥ `coversDigestId` 薄壳 ∥ `digestAccountRequirement` 要求行)/
10
+ * 见账 pass(`accountDigestRound`——销账 ∥ 未签收轮)/ 升级四步(`escalateUndigested`——满上限 ∥
11
+ * 会话 idle 退出两支共用,终局披露含在内)/
12
+ * 读面(`unsettledRows` · `unsettledRow` · `unsettledCount`)/ 落痕清位 ∕ 取件助手
13
+ * (`armAccountRound` · `harvestAccountOutput`)。
11
14
  *
12
- * 载体(§6.31.2):`_daSession`(会话标记——挂起会话置 / 复位,`agent/suspension.mjs`)与
15
+ * 载体(§8.1):`_daSession`(会话标记——挂起会话置 / 复位,`agent/suspension.mjs`)与
13
16
  * `_unsettledDigests`(升级账本——经 `async-settle.mjs` 写助手);账目态挂条目字段
14
- * (`_daDelivered` / `_daMissRounds`)。**fallback 面**(无 `_daSession`——headless /
15
- * 直连 `runAgent`)零账目动作(不销账 / 不计未签收轮 / 不升级):缺省条逐字沿用取尽语义(先离容后注入);
16
- * 已投递未销账条同判据跳过且留容器(§6.31 出口缝② · 父侧裁定 2026-10-05)。
17
+ * (`_daDelivered` = 内容已在历史 ∥ `_daMissRounds` = 未签收轮数)。
18
+ * **fallback 面**(无 `_daSession`——headless / 直连 `runAgent`)零账目动作(不销账 / 不计未签收轮 /
19
+ * 不升级):缺省条逐字沿用取尽语义(先离容后注入);
20
+ * 已投递未销账条同判据跳过且留容器(§8 出口缝② · 父侧裁定 2026-10-05)。
17
21
  *
18
- * 边界(§6.31.12):不做处理质量机检(只保「不许无声」);升级账本无 TTL(会话期面——
22
+ * 边界(§8.2):不做处理质量机检(只保「不许无声」);升级账本无 TTL(会话期面——
19
23
  * 中止清、idle 存续)。
20
24
  */
21
25
  import { logEvent, errText } from "../log.mjs"
22
- import { pushReal } from "../context.mjs"
26
+ import { pushInject, pushRecord } from "../context.mjs"
23
27
  import { carrierField, releaseSettledEntry, appendUnsettledDigest } from "../agent-tools/async-settle.mjs"
24
28
  import { DIGEST_ACCOUNT_DOMAIN } from "./helpers.mjs"
25
29
 
26
- /** 同条未签收上限(§6.31.5 KD-DA11):积满 DA_MISS_LIMIT 个未签收消化轮 ⇒ 升级(离容器 + 账本 + 提醒 + 终局披露一次)。
30
+ /** 同条未签收上限(§8.3):积满 DA_MISS_LIMIT 个未签收消化轮 ⇒ 升级(离容器 + 账本 + 提醒 + 终局披露一次)。
27
31
  * 依据 = 「连空 3 轮仍须在容器、第 4 轮补签仍能销账」的**下界**(N = 4——无额外余量;可复算;不取观测值——
28
32
  * 修前观测受「总投递 ≤3」删失)。 */
29
33
  export const DA_MISS_LIMIT = 4
30
34
 
31
35
  /**
32
- * 回合分类单点(§6.31.2):账目只属**消化轮**(autoTurn ∧ 非上行唤醒轮 ∧ 非 timer 轮)——
36
+ * 回合分类单点(§8.1):账目只属**消化轮**(autoTurn ∧ 非上行唤醒轮 ∧ 非 timer 轮)——
33
37
  * timer / 上行轮投递不销账(其账目在后续消化轮)。
34
38
  */
35
39
  export function isDigestRound(opts) {
@@ -37,53 +41,82 @@ export function isDigestRound(opts) {
37
41
  }
38
42
 
39
43
  /**
40
- * 投递门控(§6.31.4 单点谓词 · 批 digest-retry-amplify 收为单门):`!_daDelivered` ∧ 本回合 = 系统轮
41
- * (`autoTurn`)⇒ 投(首次投递——**用户回合零投递**);`_daDelivered` 已置 ⇒ 恒跳过(**每条只投一次**——
42
- * 重投回路退场,§6.31.5 KD-DA4)。注入抛错 ⇒ `_daDelivered` 未置 ⇒ 下一系统轮重试注入
43
- * (注入失败的再试,不属投递回路)。
44
+ * 投递门控(§9.1 单点谓词 · 批 digest-retry-amplify 收为单门):未投递 ∧ 本回合 = 系统轮(`autoTurn`)
45
+ * ⇒ 投(首次投递——**用户回合零投递**);已投递 ⇒ 恒跳过(**每条只投一次**——重投回路退场,§9.1)。
46
+ * 模型明写 `deferred` 不换一次重投:推迟与沉默同判,两者都只计未签收轮;内容靠满 `DA_MISS_LIMIT` 的
47
+ * 升级终局披露回会话(`accountDigestRound` 的 ④)。本谓词只读一条事实——`_daDelivered`(内容已在历史)。
48
+ * 注入抛错 ⇒ `_daDelivered` 未置 ⇒ 下一系统轮重试注入(注入失败的再试,不属投递回路)。
44
49
  * 注:`autoTurn` 判据由调用方(`run-start.mjs` 会话态支)传入;回退面(非会话态支)不经本谓词。
45
50
  */
46
51
  export function shouldDeliverEntry(entry, autoTurn) {
47
- if (entry?._daDelivered === true) return false
48
- return autoTurn === true
52
+ if (autoTurn !== true) return false
53
+ return entry?._daDelivered !== true
49
54
  }
50
55
 
51
- /** 账目要求行(§6.31.3):核常量(helpers.mjs)+ 未销账 id 清单动态拼(`<ids>` 占位替换)。 */
56
+ /** 账目要求行(§8.2):核常量(helpers.mjs)+ 两个占位动态代换——未销账 id 清单 `<ids>` ∥
57
+ * 未签收上限 `<limit>`(数的一处真身 = 本档 `DA_MISS_LIMIT`;helpers 反向 import 本档成环)。 */
52
58
  export function digestAccountRequirement(ids) {
53
- return DIGEST_ACCOUNT_DOMAIN.replace("<ids>", ids.map((id) => `#${id}`).join(", "))
59
+ return DIGEST_ACCOUNT_DOMAIN
60
+ .replace("<ids>", ids.map((id) => `#${id}`).join(", "))
61
+ .replace("<limit>", String(DA_MISS_LIMIT))
54
62
  }
55
63
 
56
64
  /**
57
- * 账目覆盖机检(§6.31.3):输出文本内**存在一行**同时含标记 `[digest-ack` 与 `#<id>`
58
- * (id 词界 = 后随非数字)⇒ 该条覆盖;disposition / 要点 / 原因**不参与机检**。
59
- * 无标记 / 无 id / 部分覆盖各按本条判(零工具轮可满足——纯文本判据)。
65
+ * 处置词解析单点(§8.2):输出文本内**存在一行**同时含标记 `[digest-ack` 与 `#<id>`
66
+ * (id 词界 = 后随非数字)⇒ 读标记方括号后第一个词:`digested` 归「已处理」、
67
+ * `deferred` 归「本轮未处理」;别的词 ∥ 缺词 ⇒ null(与零痕迹同判:计轮、不重投)。
68
+ * 要点 ∥ 原因仍是散文,不参与机检。
69
+ * 多行 ∥ 同一行多处同 id 出现:任一处 `deferred` ⇒ deferred(两个相反信号只能取保守侧,
70
+ * 机检读不到散文);否则任一处 `digested` ⇒ digested;否则 null。
71
+ * 词形按 ACK 约定的原样小写比对——大小写变体落到 null 一侧(不销账,保守);
72
+ * 零工具轮可满足(纯文本判据)。
60
73
  * 注:行内扫**全部**出现位(长 id 首现不吻合不弃行——如 id=1 行内先见 `#12` 后见 `#1`)。
61
74
  */
62
- export function coversDigestId(output, id) {
75
+ export function digestDisposition(output, id) {
63
76
  const key = `#${id}`
77
+ let digested = false
64
78
  for (const line of String(output ?? "").split(/\r?\n/)) {
65
79
  const marker = line.indexOf("[digest-ack")
66
80
  if (marker < 0) continue
67
81
  for (let from = marker; ;) {
68
82
  const at = line.indexOf(key, from)
69
83
  if (at < 0) break
84
+ from = at + 1 // 无论判成与否都续扫下一出现位(同长 id 前缀不吞后随正例)
70
85
  const after = line[at + key.length]
71
- if (after === undefined || !/[0-9]/.test(after)) return true
72
- from = at + 1 // 词界不吻合 ⇒ 续扫下一出现位(同长 id 前缀不吞后随正例)
86
+ if (after !== undefined && /[0-9]/.test(after)) continue
87
+ const word = dispositionWord(line, at + key.length)
88
+ if (word === "deferred") return "deferred"
89
+ if (word === "digested") digested = true
73
90
  }
74
91
  }
75
- return false
92
+ return digested ? "digested" : null
93
+ }
94
+
95
+ /** 处置词取词(§8.2):标记 `]`(自 id 之后最近的那一个)之后第一个词;不是两个词之一 ⇒ null。 */
96
+ function dispositionWord(line, from) {
97
+ const close = line.indexOf("]", from)
98
+ if (close < 0) return null
99
+ const word = /^[A-Za-z]+/.exec(line.slice(close + 1).trimStart())?.[0]
100
+ return word === "digested" || word === "deferred" ? word : null
101
+ }
102
+
103
+ /** 账目覆盖机检(§8.2 薄壳):处置词为 `digested` 才算覆盖——导出名与签名照旧,
104
+ * 三值语义由 `digestDisposition` 承载。当前无生产调用者(见账 pass 直调 `digestDisposition`):
105
+ * 保留导出只为导出面兼容,不为新增调用点。 */
106
+ export function coversDigestId(output, id) {
107
+ return digestDisposition(output, id) === "digested"
76
108
  }
77
109
 
78
110
  /**
79
- * 见账 pass(§6.31.5——消化轮收尾 `finalizeAgentTurn` 单点调用;调用方已判 `isDigestRound ∧
111
+ * 见账 pass(§8.3——消化轮收尾 `finalizeAgentTurn` 单点调用;调用方已判 `isDigestRound ∧
80
112
  * `_daSession` ∧ 非会话停止径):
81
- * - 投递账 = pending ∩ `_daDelivered`;覆盖 ⇒ 离容器(splice)+ `releaseSettledEntry`(含 report 释放);
82
- * - 未覆盖(空回合 ∥ 有输出未签收——同判同计)⇒ `_daMissRounds += 1`;< `DA_MISS_LIMIT` ⇒ 条留容器、
83
- * **零投递动作**;达上限 ⇒ **升级**(四步固定先后:账本 → 提醒 → 离容器 → 终局披露)。
84
- * 缺痕(output == null——抛错 / 撞帽 / 未收口 / 整 run 零非空正文)⇒ 按未签收判(与「有输出未签收」同出口)。
113
+ * - 投递账 = pending ∩ `_daDelivered`;处置词 `digested` ⇒ 离容器(splice)+ `releaseSettledEntry`(含 report 释放);
114
+ * - `deferred` 与沉默同判 ⇒ 两者都只 `_daMissRounds += 1`(缺痕 = output == null——抛错 / 撞帽 / 未收口 /
115
+ * 整 run 零非空正文),都不换第二次投递:推迟不兑换成重投,内容靠满上限的升级终局披露回会话(§9.1)。
116
+ * 未覆盖支 < `DA_MISS_LIMIT` ⇒ 条留容器、**零投递动作**;达上限 ⇒ **升级**
117
+ * (四步固定先后:账本 → 提醒 → 离容器 → 终局披露——实现见 `escalateUndigested`),与处置词无关。
85
118
  *
86
- * async(§6.31.5 升级支 ④):披露复用首投注入器 ⇒ pass 变 async——唯一调用点 = `run-stages.mjs` 的
119
+ * async(§8.3 升级支 ④):披露复用首投注入器 ⇒ pass 变 async——唯一调用点 = `run-stages.mjs` 的
87
120
  * finalize 单点(已 await)。披露逐条 try/catch:判据 = **披露失败不得使报告离开可见面**
88
121
  * (账本 + 提醒 + status 面 `preview` 已在披露之前落定,失败降级可见性、留痕不静默)。
89
122
  */
@@ -95,8 +128,11 @@ export async function accountDigestRound(carrier) {
95
128
  const upgraded = []
96
129
  for (const entry of [...pending]) {
97
130
  if (entry?._daDelivered !== true) continue
98
- if (output != null && coversDigestId(output, entry.id)) { covered.push(entry); continue }
131
+ const disposition = output == null ? null : digestDisposition(output, entry.id)
132
+ if (disposition === "digested") { covered.push(entry); continue }
99
133
  entry._daMissRounds = (entry._daMissRounds ?? 0) + 1
134
+ // 未覆盖(含显式 `deferred`)只计未签收轮,不记第二次投递:推迟与沉默同判(§9.1)。
135
+ // 投递账保持为真——它只说「内容已在历史」,起跑回退支 ∥ 退出 idle 清场 ∥ 本 pass 跳过条件都照旧读它(§8.2)。
100
136
  if (entry._daMissRounds >= DA_MISS_LIMIT) upgraded.push(entry)
101
137
  }
102
138
  for (const entry of covered) {
@@ -105,36 +141,60 @@ export async function accountDigestRound(carrier) {
105
141
  releaseSettledEntry(entry)
106
142
  }
107
143
  if (upgraded.length === 0) return { covered: covered.length, unsettled: 0 }
108
- // 升级四步固定先后(§6.31.5——纯内存的两面先落、披露最后:披露是本 pass 唯一的 I/O,
109
- // 抛错会中断余下条目判定并越过 `run-stages.mjs` 的 `_inAutoTurn = false` 与 guard 快照)。
144
+ // 升级四步(§8.3——与周期终点支共用 `escalateUndigested`,本支 reason = "limit")。
145
+ await escalateUndigested(carrier, "limit", upgraded)
146
+ return { covered: covered.length, unsettled: upgraded.length }
147
+ }
148
+
149
+ /**
150
+ * 升级四步(§8.3——两支共用、先到者为准:满 `DA_MISS_LIMIT` 个未签收轮(reason `"limit"`,调用点 =
151
+ * 本档 `accountDigestRound`)∥ 会话进入 idle 退出前结账(reason `"idle"`,调用点 =
152
+ * `thincoder-core/agent/suspension.mjs` 的 `startSuspension` 收尾、`finishSuspension` 之前)。
153
+ * 固定先后:① 账本 → ② 提醒 → ③ 离容器 → ④ 终局披露——纯内存的两面先落、披露最后:披露是四步里唯一
154
+ * 的 I/O,抛错会中断余下条目判定并越过 `run-stages.mjs` 的 `_inAutoTurn = false` 与 guard 快照。
155
+ * 升级不开任何回合:四步都是机械动作,不需要模型轮——会话沉寂后再没有消化轮,保底也不交给运气。
156
+ *
157
+ * @param {object} carrier 载体(容器 `_pendingAsyncResults` ∥ 升级账本 `_unsettledDigests`)
158
+ * @param {"limit"|"idle"} reason 起因——必填、无缺省(缺省会把「会话沉寂」说成「满 4 轮」)
159
+ * @param {object[]} entries 本次升级的条目——必填,选择面各在调用点:上限支 = 达上限集,终点支 =
160
+ * 容器内 `_daDelivered === true` 的条;空集 / 非数组 ⇒ 零动作
161
+ * @returns {Promise<number>} 升级条数
162
+ */
163
+ export async function escalateUndigested(carrier, reason, entries) {
164
+ if (!Array.isArray(entries) || entries.length === 0) return 0
165
+ const pending = carrierField(carrier, "_pendingAsyncResults")
110
166
  // ① 入账本(纯内存):账本记录 = **快照**,只喂 status 面与 `preview`——被注入的对象是原条目(见 ④)。
111
- for (const entry of upgraded) {
167
+ for (const entry of entries) {
112
168
  appendUnsettledDigest(carrier, {
113
169
  id: String(entry.id),
114
170
  role: entry.role ?? "subagent",
115
- missRounds: entry._daMissRounds,
171
+ missRounds: entry._daMissRounds ?? 0,
116
172
  report: entry.report ?? null,
117
173
  at: Date.now(),
118
174
  })
119
175
  }
120
- // ② 提醒:恰一条(机器线 + 人读线——`pushReal`)+ 恰一条留痕(字段单源 = LOGGING.md §6.2)。
176
+ // ② 提醒:恰一条(待发队 + 人读线——`pushInject` + `pushRecord`)+ 恰一条留痕(字段单源 = LOGGING.md §6.2)。
121
177
  // 注:`ids` 以 join 串落盘——`logEvent` 只收标量(数组字段会被静默丢弃——先例 `ev:discarded`)。
122
178
  {
123
- const ids = upgraded.map((entry) => String(entry.id))
124
- pushReal(carrier, { role: "user", content: unsettledReminder(upgraded.length, ids) })
125
- logEvent("ev:unsettled", { n: upgraded.length, ids: ids.join(", ") })
179
+ const ids = entries.map((entry) => String(entry.id))
180
+ const msg = { role: "user", content: unsettledReminder(entries.length, ids, reason) }
181
+ pushInject(carrier, msg)
182
+ pushRecord(carrier, msg)
183
+ logEvent("ev:unsettled", { n: entries.length, ids: ids.join(", ") })
126
184
  }
127
185
  // ③ 离容器(纯结构):至此条目定态「已升级」,不再参与判定 ⇒ 披露结构上至多一次。
128
- for (const entry of upgraded) {
129
- const i = pending.indexOf(entry)
130
- if (i >= 0) pending.splice(i, 1)
186
+ if (Array.isArray(pending)) {
187
+ for (const entry of entries) {
188
+ const i = pending.indexOf(entry)
189
+ if (i >= 0) pending.splice(i, 1)
190
+ }
131
191
  }
132
192
  // ④ 终局披露:**按 role 与首投同分流**(consult → `injectConsultResult`;其余 → `injectAsyncResult`——
133
193
  // 内部已分派 bg / browser);不新造第二投递形。注入的对象 = **原条目**(墓碑值
134
194
  // `error != null ? "failed" : "consumed"` 与评审族投递水印 `entry.run` 都按原条目字段才成立)。
135
195
  const { injectAsyncResult } = await import("../agent-tools/subagent.mjs")
136
196
  const { injectConsultResult } = await import("../agent-tools/consult.mjs")
137
- for (const entry of upgraded) {
197
+ for (const entry of entries) {
138
198
  try {
139
199
  if (entry.role === "consult") await injectConsultResult(carrier, entry)
140
200
  else await injectAsyncResult(carrier, entry)
@@ -144,16 +204,30 @@ export async function accountDigestRound(carrier) {
144
204
  logEvent("ev:unsettled-disclose-failed", { id: String(entry.id), err: errText(e, 200) })
145
205
  }
146
206
  }
147
- return { covered: covered.length, unsettled: upgraded.length }
207
+ return entries.length
148
208
  }
149
209
 
150
- /** 升级提醒行(§6.31.5——含 n / 轮数(恒 = `DA_MISS_LIMIT`,升级只在第 N 个未签收轮发生)/ id 清单与接手指引)。 */
151
- export function unsettledReminder(n, ids) {
152
- return `[System reminder: ${n} background report(s) were delivered but never accounted after ${DA_MISS_LIMIT} digest rounds — they are marked UNSETTLED: ${ids.map((id) => `#${id}`).join(", ")}. Their content was delivered once in this conversation and is re-delivered once right below as the final delivery — if that copy is missing, the delivery failed and the full text stays readable via subagent action:'status'. Process it there or re-spawn the work.]`
210
+ /** 升级提醒行的起因句(§8.3 引文块的两支):值即「被升级成未处理」的那一刻。 */
211
+ const UNSETTLED_CAUSE = {
212
+ limit: `after ${DA_MISS_LIMIT} digest rounds`,
213
+ idle: "before this session went idle",
214
+ }
215
+
216
+ /** 升级提醒行(§8.3——含 n / 起因 / id 清单与接手指引)。两支(满上限 ∥ 会话 idle 退出)措辞只在
217
+ * 起因那一句不同,其余逐字相同。`reason` 必填、无缺省:缺省会静默借用另一支措辞,把「会话沉寂」
218
+ * 说成「满 4 轮」;两个取值之外的 reason 当场抛(枚举闭合,不落回任一支)。 */
219
+ export function unsettledReminder(n, ids, reason) {
220
+ const cause = typeof reason === "string" && Object.prototype.hasOwnProperty.call(UNSETTLED_CAUSE, reason)
221
+ ? UNSETTLED_CAUSE[reason]
222
+ : null
223
+ if (cause === null) {
224
+ throw new Error(`unsettledReminder: unknown reason ${JSON.stringify(reason)} — "limit" | "idle" is required (no default)`)
225
+ }
226
+ return `[System reminder: ${n} background report(s) were delivered but never accounted ${cause} — they are marked UNSETTLED: ${ids.map((id) => `#${id}`).join(", ")}. Their content was delivered once in this conversation and is re-delivered once right below as the final delivery — if that copy is missing, the delivery failed and the full text stays readable via subagent action:'status'. Process it there or re-spawn the work.]`
153
227
  }
154
228
 
155
229
  /**
156
- * 读面(§6.31.6——status 段 ∥ 端面残余行共用单点):行 = `{ id, role, state, attempts }`;
230
+ * 读面(§8.4——status 段 ∥ 端面残余行共用单点):行 = `{ id, role, state, attempts }`;
157
231
  * state ∈ `awaiting-digest`(在途未投递 ∥ 已投递未判 = `attempts == 0`)/ `unaccounted`(判过未签收 =
158
232
  * `attempts > 0`)/ `unsettled`(已升级——随携 `preview` ≤400 字符);`attempts` = 未签收轮数 `_daMissRounds`。
159
233
  */
@@ -182,13 +256,13 @@ export function unsettledRows(carrier) {
182
256
  return rows
183
257
  }
184
258
 
185
- /** 单查 id 同解析(§6.31.6 单查序第三 / 四站):命中 pending / 升级账本 ⇒ 行形同上;未命中 ⇒ null。 */
259
+ /** 单查 id 同解析(§8.4 单查序第三 / 四站):命中 pending / 升级账本 ⇒ 行形同上;未命中 ⇒ null。 */
186
260
  export function unsettledRow(carrier, id) {
187
261
  const key = String(id)
188
262
  return unsettledRows(carrier).find((row) => row.id === key) ?? null
189
263
  }
190
264
 
191
- /** 端面残余行判据(§6.31.6):pending 中 `_daMissRounds > 0` 条数(与状态面 `unaccounted` 同判据;
265
+ /** 端面残余行判据(§8.4):pending 中 `_daMissRounds > 0` 条数(与状态面 `unaccounted` 同判据;
192
266
  * 升级条已离容器——由升级提醒承载)。 */
193
267
  export function unsettledCount(carrier) {
194
268
  const pending = carrierField(carrier, "_pendingAsyncResults")
@@ -197,17 +271,17 @@ export function unsettledCount(carrier) {
197
271
  return n
198
272
  }
199
273
 
200
- /** 落痕清位(§6.31.5——`run-start.mjs` 会话态起跑即清;fallback 零动作):父字段 ∥ history 双清。
274
+ /** 落痕清位(§8.3——`run-start.mjs` 会话态起跑即清;fallback 零动作):父字段 ∥ history 双清。
201
275
  * 注:核内写点落**父字段**(`turn-loop.mjs` 的 `agent._lastRunOutput`——逐轮追加,本批 #939
202
276
  * 收正;抗 `history` 整体替换——`context.mjs` `applyCompression`);`history` 级为兼容读形
203
- * (`harvestAccountOutput` 回退分支)——该痕不属跨 run 字段集,§6.31.5 边界句。 */
277
+ * (`harvestAccountOutput` 回退分支)——该痕不属跨 run 字段集,§8.3 边界句。 */
204
278
  export function armAccountRound(carrier) {
205
279
  if (!carrier || typeof carrier !== "object") return
206
280
  carrier._lastRunOutput = null
207
281
  if (carrier.history && typeof carrier.history === "object") carrier.history._lastRunOutput = null
208
282
  }
209
283
 
210
- /** 落痕取件(§6.31.5——载体吸收读:父字段优先 / 回退 `history`);读值 = 本 run 多轮累积文本(#939);
284
+ /** 落痕取件(§8.3——载体吸收读:父字段优先 / 回退 `history`);读值 = 本 run 多轮累积文本(#939);
211
285
  * 缺痕(本 run 零输出落痕——零模型轮 / 起跑即断 / 每轮正文皆空)⇒ null。 */
212
286
  export function harvestAccountOutput(carrier) {
213
287
  const own = carrier?._lastRunOutput
@@ -132,6 +132,12 @@ export function isSubagentEscalateAction(toolName, args) {
132
132
  export function readonlyActionOf(tool, toolName, args) {
133
133
  return tool?.isReadonlyAction?.(args) ?? isReadonlyAction(toolName, args)
134
134
  }
135
+ /** 只读变体派生面的谓词形(`(tool, args)`——`readonlyActionOf` 的单参适配,单源只此一处)。
136
+ * 消费点 = `agent/helpers.mjs` 的 `makeReadonlyToolVariant` / `deriveReadonlyTools` 注入面:
137
+ * 构造器不 import 本档(本档 import 它——成环),故由调用方把这枚函数传进去(TOOLS.md §6.29 ①)。 */
138
+ export function readonlyActionTest(tool, args) {
139
+ return readonlyActionOf(tool, tool?.name, args)
140
+ }
135
141
  export function controlActionOf(tool, toolName, args) {
136
142
  return tool?.isControlAction?.(args) ?? isSubagentControlAction(toolName, args)
137
143
  }
@@ -13,7 +13,7 @@ import { snapshotForUndo } from "../undo-stack.mjs"
13
13
  import { PEER_WRITE_TOOLS, peerCollabNote, recordPeerWrites, markClaimNoted } from "../peer-domains.mjs"
14
14
  import { logToolError, noteExecutedMutation } from "./dispatch-gates.mjs"
15
15
 
16
- /** console 回显预算(AGENT-LOOP.md §6.4 · #863):采集端 cap = 与 helpers.mjs `TOOL_RESULT_OFFLOAD_LIMIT`
16
+ /** console 回显预算(AGENT-LOOP.md §5.3 结果 · #863):采集端 cap = 与 helpers.mjs `TOOL_RESULT_OFFLOAD_LIMIT`
17
17
  * 同值(65536 字符)——累计到限停收(超出丢弃);发生丢弃 ⇒ 回显段尾恰一行截断标记(逐字——两路径同款)。 */
18
18
  const CONSOLE_CAPTURE_LIMIT = 64 * 1024
19
19
  const CONSOLE_TRUNCATED_MARK = "[console truncated at 65536 chars]"
@@ -114,8 +114,11 @@ export async function executeToolCalls(agent, toolByName, toolCalls, callbacks,
114
114
  }
115
115
  if (blocked) {
116
116
  // Undeclared project → point at ITS declaration file (§4.3 降级可见契约; #1102).
117
+ // 文案不列段名:本支只在 `!conv.declared` 时发,而 `declared` 是值比较(`buildDeclaration`)
118
+ // ⇒ 未声明 ⇒ `codePaths` 与缺省逐项相等 = 空。默认段自 2026-11-10 起清空(KD-M1-31),
119
+ // 原先 `code paths: ${…join}` 的空集渲染会印出一句残句,故改述判据来源(兜底分类)。
117
120
  const convNote = noteConv
118
- ? ` — this path was classified as product code by the default conventions (code paths: ${noteConv.codePaths.join(", ")}); declare project conventions in ${manifestFilePath(noteConv.root)} to adjust.`
121
+ ? ` — this path fell through to product code (no code segment is declared: code paths are empty); declare project conventions in ${manifestFilePath(noteConv.root)} to adjust.`
119
122
  : ""
120
123
  prepared.push({
121
124
  toolCall, tool, denied: true,
@@ -162,8 +165,10 @@ export async function executeToolCalls(agent, toolByName, toolCalls, callbacks,
162
165
  // 写锁(第三道 · 2026-11-03 笔-账绑定批 · 设计档 §2.3):本笔报的 `ledger:"#N"` 必须是**目标所属项目**
163
166
  // 台账里一条 `status = 在途` 的行。位次 = 既有两道之后(既有拒因先报);判序 = 先判目标所属项目
164
167
  // (出辖 ⇒ 门不管),再按号查该根台账;台账读不到 ⇒ 拒(业务门)。
165
- // 入口集 = 十三把(写盘七件 + `bash` ∥ `execute` + `git` + `manifest` ∥ `memory` + `ssh`)——`bash` ∥ `execute`
166
- // 与写盘工具同一判据、不按命令内容分类(决策 36);`git` 只对写型 action 要号(决策 37);`ssh` 只对 `get` 要号。
168
+ // 入口集 = 十一把(写盘七件 + `bash` ∥ `execute` + `memory` + `ssh`)——`bash` ∥ `execute`
169
+ // 与写盘工具同一判据、不按命令内容分类(决策 36);`ssh` 只对 `get` 要号。`git` **不在集内**(决策 37 改判):
170
+ // 它不落新字节,写型与只读同为不要号 ⇒ 本门不问它的 action;`manifest` **不在集内**(决策 44):本门自己要
171
+ // 读它写的那份档(取根 ∥ 写权表),把它也放在门后即构成环 ⇒ 三动作一概不要号。
167
172
  // 只在工程模式生效(`agent.config.agent.engineering`)∥ 只在 depth 0(子代理走既有 token 门)。
168
173
  // 路径集与 `args.ledger` 由判据函数自己取(调形只传 tool + toolName + args)。
169
174
  const ledgerConflict = await ledgerBindWriteConflict(agent, depth, tool, toolCall.name, args)
@@ -253,8 +258,9 @@ export async function executeToolCalls(agent, toolByName, toolCalls, callbacks,
253
258
  // ---- B7 3a JIT 缝(相位一末 ∕ 相位二前——原 VSC「派发前」语义;`depth === 0` 门)--------
254
259
  // 作用域规则注入:打点 = `prepared` 非拒项 `{tool, args}`(即将执行集);注入源 = 本 run 尾块
255
260
  // 读点缓存 `agent._rules.scoped`(核 `prepareRun` 同点写入),去重域 = 会话。子代不注入。
261
+ // 暂停注入(设计档 §7.1「暂停注入」):注入本体不再执行;`history` 形参已退场(线上不再有可写处)。
256
262
  if (depth === 0) {
257
- injectScopedRules(agent, agent.history, prepared.filter((p) => p.tool && p.args).map(({ tool, args }) => ({ tool, args })))
263
+ injectScopedRules(agent, prepared.filter((p) => p.tool && p.args).map(({ tool, args }) => ({ tool, args })))
258
264
  }
259
265
 
260
266
  // ---- Phase 2: order-preserving execution ----