@thincoder/core 0.11.2 → 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 (198) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/advisor/compaction.mjs +7 -5
  3. package/advisor/history.mjs +24 -11
  4. package/advisor/loop.mjs +13 -8
  5. package/advisor/messages.mjs +72 -8
  6. package/advisor/run.mjs +24 -13
  7. package/advisor.mjs +7 -3
  8. package/agent/chat-call.mjs +14 -9
  9. package/agent/completion.mjs +28 -40
  10. package/agent/continue-decision.mjs +14 -8
  11. package/agent/digest-account.mjs +133 -59
  12. package/agent/dispatch-run.mjs +1 -1
  13. package/agent/dispatch.mjs +2 -1
  14. package/agent/family-tools.mjs +12 -13
  15. package/agent/helpers.mjs +17 -72
  16. package/agent/image-heal.mjs +18 -4
  17. package/agent/post-turn.mjs +13 -26
  18. package/agent/record-results.mjs +21 -6
  19. package/agent/run-stages.mjs +72 -37
  20. package/agent/run-start.mjs +148 -113
  21. package/agent/setup-reminders.mjs +187 -91
  22. package/agent/setup.mjs +204 -138
  23. package/agent/spawn-child.mjs +2 -2
  24. package/agent/suspension.mjs +43 -15
  25. package/agent/timers.mjs +4 -1
  26. package/agent/turn-domain-text.mjs +105 -0
  27. package/agent/turn-loop.mjs +54 -22
  28. package/agent/turn-projection.mjs +127 -227
  29. package/agent/turn-tool-process.mjs +32 -37
  30. package/agent-tools/advisor-async.mjs +6 -3
  31. package/agent-tools/advisor-launch.mjs +5 -5
  32. package/agent-tools/advisor.mjs +1 -1
  33. package/agent-tools/async-discard.mjs +7 -2
  34. package/agent-tools/async-settle.mjs +18 -12
  35. package/agent-tools/bash-async.mjs +5 -2
  36. package/agent-tools/batch-closeout.mjs +12 -62
  37. package/agent-tools/batch-ledger-bind.mjs +19 -8
  38. package/agent-tools/batch-lifecycle.mjs +37 -11
  39. package/agent-tools/batch-read.mjs +151 -4
  40. package/agent-tools/batch-record-write.mjs +5 -5
  41. package/agent-tools/batch-segment-vocab.mjs +84 -4
  42. package/agent-tools/batch-skeleton.mjs +18 -14
  43. package/agent-tools/batch-supersede.mjs +1 -1
  44. package/agent-tools/batch-tier-gate.mjs +36 -119
  45. package/agent-tools/batch.mjs +30 -20
  46. package/agent-tools/browser-async.mjs +5 -2
  47. package/agent-tools/consult.mjs +10 -7
  48. package/agent-tools/context.mjs +47 -31
  49. package/agent-tools/digest-budget.mjs +10 -9
  50. package/agent-tools/eng.mjs +3 -4
  51. package/agent-tools/escalate-async.mjs +3 -3
  52. package/agent-tools/goal.mjs +5 -2
  53. package/agent-tools/judge-domain.mjs +347 -0
  54. package/agent-tools/manifest.mjs +2 -2
  55. package/agent-tools/parent-channel.mjs +6 -3
  56. package/agent-tools/plan.mjs +11 -10
  57. package/agent-tools/review-facts.mjs +9 -3
  58. package/agent-tools/skill.mjs +7 -8
  59. package/agent-tools/spawn-gates.mjs +5 -16
  60. package/agent-tools/ssh-session.mjs +6 -3
  61. package/agent-tools/ssh-transfer.mjs +1 -1
  62. package/agent-tools/subagent-actions.mjs +2 -2
  63. package/agent-tools/subagent-async.mjs +11 -8
  64. package/agent-tools/subagent-scheduler.mjs +9 -9
  65. package/agent-tools/subagent-spawn.mjs +2 -2
  66. package/agent-tools/subagent.mjs +5 -18
  67. package/agent-tools/task.mjs +0 -8
  68. package/agent.mjs +15 -15
  69. package/auto-think.mjs +5 -2
  70. package/compaction-work-state.mjs +230 -0
  71. package/compress-form.mjs +41 -6
  72. package/config-defaults.mjs +5 -2
  73. package/config.mjs +53 -17
  74. package/context-degrade.mjs +79 -48
  75. package/context-echo.mjs +6 -26
  76. package/context-push.mjs +328 -31
  77. package/context.mjs +203 -141
  78. package/conventions.mjs +1 -1
  79. package/declaration.mjs +95 -17
  80. package/escape.mjs +6 -5
  81. package/explore-distill.mjs +35 -8
  82. package/generate-title.mjs +10 -1
  83. package/knowledge/prompt-resources.md +5 -1
  84. package/ledger-tools.mjs +50 -50
  85. package/ledger-write-ops.mjs +43 -16
  86. package/memory/docs.mjs +51 -15
  87. package/memory/file-list.mjs +6 -0
  88. package/model-specs.mjs +87 -21
  89. package/origin-guard.mjs +190 -0
  90. package/package.json +1 -1
  91. package/prompt-files.mjs +33 -11
  92. package/prompt-overlays.mjs +12 -5
  93. package/prompts/advisor-design.md +55 -36
  94. package/prompts/advisor-round1.md +18 -7
  95. package/prompts/advisor-round2.md +18 -7
  96. package/prompts/advisor-round3.md +18 -7
  97. package/prompts/common.md +89 -51
  98. package/prompts/consult-base.md +2 -3
  99. package/prompts/discipline-engineering.md +474 -440
  100. package/prompts/discipline-normal.md +107 -31
  101. package/prompts/knowledge/business-gates.md +23 -15
  102. package/prompts/knowledge/decision-quality.md +16 -18
  103. package/prompts/knowledge/doc-lookup.md +22 -27
  104. package/prompts/knowledge/document-writing.md +31 -49
  105. package/prompts/knowledge/documentation-evaluation.md +37 -45
  106. package/prompts/knowledge/evidence-discipline.md +36 -55
  107. package/prompts/knowledge/normal-coding-workflow.md +27 -21
  108. package/prompts/knowledge/normal-delivery-collaboration.md +33 -17
  109. package/prompts/knowledge/normal-work-management.md +10 -7
  110. package/prompts/knowledge/product-security.md +22 -17
  111. package/prompts/knowledge/project-records.md +63 -52
  112. package/prompts/knowledge/tool-apply-patch.md +12 -13
  113. package/prompts/knowledge/tool-bash.md +13 -4
  114. package/prompts/knowledge/tool-batch-eng-coder.md +13 -6
  115. package/prompts/knowledge/tool-batch-eng-designer.md +14 -6
  116. package/prompts/knowledge/tool-batch-review.md +12 -6
  117. package/prompts/knowledge/tool-batch.md +76 -62
  118. package/prompts/knowledge/tool-browser.md +45 -34
  119. package/prompts/knowledge/tool-context.md +2 -2
  120. package/prompts/knowledge/tool-delete.md +5 -1
  121. package/prompts/knowledge/tool-doc-check.md +25 -24
  122. package/prompts/knowledge/tool-doc-graph-read.md +3 -3
  123. package/prompts/knowledge/tool-doc-graph.md +15 -15
  124. package/prompts/knowledge/tool-edit.md +26 -23
  125. package/prompts/knowledge/tool-execute.md +9 -4
  126. package/prompts/knowledge/tool-fetch.md +7 -1
  127. package/prompts/knowledge/tool-file-ops.md +6 -1
  128. package/prompts/knowledge/tool-git-read.md +3 -1
  129. package/prompts/knowledge/tool-git.md +1 -1
  130. package/prompts/knowledge/tool-glob.md +3 -1
  131. package/prompts/knowledge/tool-grep.md +5 -2
  132. package/prompts/knowledge/tool-hashline-edit.md +4 -2
  133. package/prompts/knowledge/tool-insert-after.md +3 -1
  134. package/prompts/knowledge/tool-ledger-read.md +6 -13
  135. package/prompts/knowledge/tool-ledger.md +14 -10
  136. package/prompts/knowledge/tool-ls.md +2 -0
  137. package/prompts/knowledge/tool-manifest.md +10 -7
  138. package/prompts/knowledge/tool-memory.md +15 -11
  139. package/prompts/knowledge/tool-operations.md +59 -71
  140. package/prompts/knowledge/tool-plan.md +1 -2
  141. package/prompts/knowledge/tool-process.md +1 -1
  142. package/prompts/knowledge/tool-read-history.md +6 -7
  143. package/prompts/knowledge/tool-read.md +1 -0
  144. package/prompts/knowledge/tool-settings.md +6 -7
  145. package/prompts/knowledge/tool-ssh.md +37 -15
  146. package/prompts/knowledge/tool-subagent.md +37 -39
  147. package/prompts/knowledge/tool-task.md +3 -1
  148. package/prompts/knowledge/tool-team-ledger.md +5 -1
  149. package/prompts/knowledge/tool-tree.md +2 -0
  150. package/prompts/knowledge/tool-wait-for.md +16 -16
  151. package/prompts/knowledge/tool-write.md +4 -1
  152. package/prompts/knowledge/upstream-protocol.md +39 -37
  153. package/prompts/persona-coder.md +1 -3
  154. package/prompts/persona-eng-coder.md +5 -5
  155. package/prompts/persona-eng-designer.md +34 -17
  156. package/prompts/persona-engineering.md +532 -501
  157. package/prompts/persona-explore.md +0 -2
  158. package/prompts/persona-normal.md +17 -9
  159. package/prompts/persona-plan.md +0 -2
  160. package/prompts/persona-tester.md +0 -2
  161. package/prompts/subagent-base.md +0 -2
  162. package/provider/anthropic.mjs +4 -2
  163. package/provider/core.mjs +5 -3
  164. package/provider/errors.mjs +41 -7
  165. package/provider/google.mjs +5 -3
  166. package/provider/reasoning-echo.mjs +16 -0
  167. package/provider/responses.mjs +4 -2
  168. package/provider/sse.mjs +11 -6
  169. package/rules.mjs +11 -10
  170. package/session-lifecycle.mjs +115 -81
  171. package/session-slot-write.mjs +1 -1
  172. package/session.mjs +23 -20
  173. package/shell-identity.mjs +129 -22
  174. package/skip-dirs.mjs +24 -0
  175. package/team-ledger.mjs +22 -22
  176. package/text-budget.mjs +1 -1
  177. package/think-off.mjs +27 -0
  178. package/token-ttl.mjs +1 -1
  179. package/token-window.mjs +278 -88
  180. package/tool-docs/bash.md +0 -2
  181. package/tool-docs/consult_start.md +2 -2
  182. package/tool-docs/consult_stop.md +2 -2
  183. package/tools/browser.mjs +8 -8
  184. package/tools/execute.mjs +2 -2
  185. package/tools/file.mjs +17 -11
  186. package/tools/git.mjs +12 -12
  187. package/tools/ops.mjs +2 -2
  188. package/tools/patch.mjs +1 -1
  189. package/tools/process-doc-mark.mjs +33 -4
  190. package/tools/repomap.mjs +25 -3
  191. package/tools/search.mjs +74 -26
  192. package/tools/shared.mjs +4 -3
  193. package/tools/ssh.mjs +5 -5
  194. package/tools/tree.mjs +32 -10
  195. package/tools/web-deepseek.mjs +1 -1
  196. package/tools/web.mjs +2 -2
  197. package/tools/write-gate-params.mjs +3 -3
  198. package/window-policy.mjs +118 -78
@@ -1,14 +1,14 @@
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
@@ -19,7 +19,7 @@ const MAX_ADVISOR_REMINDERS = 5
19
19
  const MAX_EMPTY_RETRIES = 2
20
20
 
21
21
  /**
22
- * 响应「有实质」判据(单源——判空面与清零面读同一份;AGENT-LOOP.md §6.5① · D-AL28):有非空正文
22
+ * 响应「有实质」判据(单源——判空面与清零面读同一份;AGENT-LOOP.md §6 完成守卫 · D-AL28):有非空正文
23
23
  * **或** 有工具调用 ⇒ 实质,两种形都证明「刚才那次空是瞬时的」。此处也是唯一判空式,不另写
24
24
  * `.trim() === ""`——两份一漂,判空与清零就不再是同一件事(判空加宽、清零面漏跟)。
25
25
  * 「或」不是「且」:带工具调用但正文为空(提供端常见形态)必须判为实质——写成「且」,工具轮就不清零,
@@ -31,7 +31,17 @@ export function isSubstantiveResponse(response) {
31
31
  }
32
32
 
33
33
  /**
34
- * 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)
35
45
  * or accept the completion.
36
46
  *
37
47
  * @param {object} agent
@@ -53,7 +63,7 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
53
63
  const retries = agent._emptyRetries ?? 0
54
64
  if (retries < MAX_EMPTY_RETRIES) {
55
65
  agent._emptyRetries = retries + 1
56
- agent.history.push({
66
+ pushInject(agent, {
57
67
  role: "user",
58
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.]",
59
69
  })
@@ -68,28 +78,6 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
68
78
  )
69
79
  }
70
80
 
71
- // Pending tasks: remind the model ONCE before it declares itself done.
72
- // Deliberately capped at one pushback (reported pain: unbounded looping when a
73
- // pending item can't be resolved). After the single reminder the model is free
74
- // to finish — updating the task list (task tool) resets the budget, so a fresh
75
- // list state earns one fresh reminder.
76
- // F10(催更门连带):工程模式下 task 工具机械停用(装配摘除 + execute 拒)⇒ 不再发指向被拒
77
- // 工具的提醒(死胡同提醒防线);列表本体与 `_taskPushbacks` 预算语义零改。
78
- // TIMEOUT-DIGEST.md §2.3(#29):后台池 live 时不推回——池在飞时回合本就还会被 settle 唤醒,
79
- // 此时催 task 只会拖回合;判据复用 `poolLive`(与挂起尾巴同一口径,不立第二处)。
80
- if (depth === 0 && !agent.config?.agent?.engineering && !poolLive(agent) && agent.tasks.some((t) => t.status === "pending") && (agent._taskPushbacks ?? 0) < 1) {
81
- agent._taskPushbacks = (agent._taskPushbacks ?? 0) + 1
82
- const pending = agent.tasks.filter((t) => t.status === "pending").map((t) => t.title).join(", ")
83
- pushReal(agent, { role: "assistant", content: response.content })
84
- agent.history.push({
85
- role: "user",
86
- 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.)]`,
87
- })
88
- callbacks.onSubTurnBreak?.()
89
- callbacks.onTurnEnd?.(agent, turn)
90
- return { action: "continue", guardPushbacks, honestReminderInjected, advisorPushbacks }
91
- }
92
-
93
81
  // --- verify guard: push model to verify mutated files before completion ---
94
82
  // OPT-IN ONLY (verifyGuard: true). Engineering mode is excluded because it
95
83
  // uses flow-driven review, not per-turn mechanical pushback (ENGINEERING-MODE.md §2.3).
@@ -99,8 +87,8 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
99
87
  // Not verified yet → pushback to run verify
100
88
  if (agent._mutatedThisRun && !agent._verifiedThisRun && hasCodeMutations(agent) && guardPushbacks < MAX_VERIFY_PUSHBACKS) {
101
89
  guardPushbacks++
102
- pushReal(agent, { role: "assistant", content: response.content })
103
- agent.history.push({
90
+ pushAssistantText(agent, response)
91
+ pushInject(agent, {
104
92
  role: "user",
105
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.]",
106
94
  })
@@ -113,8 +101,8 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
113
101
  // reason, or not declared — not necessarily that a test failed.
114
102
  if (agent._verifiedThisRun && agent._verifyPassed === false && agent._verifyRetries < MAX_VERIFY_RETRIES) {
115
103
  agent._verifyRetries++
116
- pushReal(agent, { role: "assistant", content: response.content })
117
- agent.history.push({
104
+ pushAssistantText(agent, response)
105
+ pushInject(agent, {
118
106
  role: "user",
119
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.]`,
120
108
  })
@@ -125,12 +113,12 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
125
113
  // Exhausted retries — inject honesty reminder once
126
114
  if (agent._verifiedThisRun && agent._verifyPassed === false && agent._verifyRetries >= MAX_VERIFY_RETRIES) {
127
115
  if (honestReminderInjected) {
128
- pushReal(agent, { role: "assistant", content: response.content })
116
+ pushAssistantText(agent, response)
129
117
  return { action: "done", content: response.content, guardPushbacks, honestReminderInjected, advisorPushbacks }
130
118
  }
131
119
  honestReminderInjected = true
132
- pushReal(agent, { role: "assistant", content: response.content })
133
- agent.history.push({
120
+ pushAssistantText(agent, response)
121
+ pushInject(agent, {
134
122
  role: "user",
135
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.]`,
136
124
  })
@@ -164,8 +152,8 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
164
152
  if (unreviewed && (agent._advisorReminders ?? 0) < MAX_ADVISOR_REMINDERS && advisorPushbacks < MAX_ADVISOR_PUSHBACKS) {
165
153
  agent._advisorReminders = (agent._advisorReminders ?? 0) + 1
166
154
  advisorPushbacks++
167
- pushReal(agent, { role: "assistant", content: response.content })
168
- agent.history.push({
155
+ pushAssistantText(agent, response)
156
+ pushInject(agent, {
169
157
  role: "user",
170
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).${
171
159
  agent._advisorReminders >= MAX_ADVISOR_REMINDERS
@@ -196,8 +184,8 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
196
184
  && !agent._advisorHonestySent
197
185
  ) {
198
186
  agent._advisorHonestySent = true
199
- pushReal(agent, { role: "assistant", content: response.content })
200
- agent.history.push({
187
+ pushAssistantText(agent, response)
188
+ pushInject(agent, {
201
189
  role: "user",
202
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.]`,
203
191
  })
@@ -207,6 +195,6 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
207
195
  }
208
196
  }
209
197
 
210
- pushReal(agent, { role: "assistant", content: response.content })
198
+ pushAssistantText(agent, response)
211
199
  return { action: "done", content: response.content, guardPushbacks, honestReminderInjected, advisorPushbacks }
212
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
@@ -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]"
@@ -258,8 +258,9 @@ export async function executeToolCalls(agent, toolByName, toolCalls, callbacks,
258
258
  // ---- B7 3a JIT 缝(相位一末 ∕ 相位二前——原 VSC「派发前」语义;`depth === 0` 门)--------
259
259
  // 作用域规则注入:打点 = `prepared` 非拒项 `{tool, args}`(即将执行集);注入源 = 本 run 尾块
260
260
  // 读点缓存 `agent._rules.scoped`(核 `prepareRun` 同点写入),去重域 = 会话。子代不注入。
261
+ // 暂停注入(设计档 §7.1「暂停注入」):注入本体不再执行;`history` 形参已退场(线上不再有可写处)。
261
262
  if (depth === 0) {
262
- 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 })))
263
264
  }
264
265
 
265
266
  // ---- Phase 2: order-preserving execution ----
@@ -6,9 +6,9 @@
6
6
  * (消灭「同一角色矩阵两份实现」= 本批缺陷的类根因);端差(VSC 装饰链 / settings 追加 /
7
7
  * consult 池来源)经 `decorate` 注入——**不传 = 核默认形态**(CLI = 迁出前逐字)。
8
8
  *
9
- * 返回 = 家族段数组(**非**工程模式:`[task, plan, timer, ...depth 家族 / 角色段]`;工程模式:
10
- * 固定段 = `[timer]`——plan 不入表(FR31 ① / KD8)· task 不入表(F10——工程模式机械停用,
11
- * 同 KD8 卸载处置))——**不含** `agent.tools`
9
+ * 返回 = 家族段数组(**非**工程模式:`[task, plan, timer, knowledge, ...depth 家族 / 角色段]`;
10
+ * 工程模式:`[timer, knowledge, ...depth 家族 / 角色段]`——plan 与 task 都不入表,两个深度同结论
11
+ * (plan:FR31 ① / KD8;task 的理由见 `docs/core/design/TOOLS.md` §1「装配」))——**不含** `agent.tools`
12
12
  * 展开与 `extraTools`(调用点各自展开:核 `agent/setup.mjs` 两段式)。
13
13
  *
14
14
  * 登记册**动态**载入:`agent-tools.mjs` 静态图经 consult/subagent 族可达核 agent 栈
@@ -211,14 +211,13 @@ export async function assembleFamilyTools({
211
211
  : role === "consult" ? [recentChangesTool, ledgerReadTool, teamLedgerReadTool, manifestReadTool, ...docTools]
212
212
  : [parentChannelTool, ledgerReadTool, teamLedgerReadTool, manifestReadTool, ...docTools]
213
213
 
214
- // 固定段(装配序 = agent.tools → 固定段 → 家族段 → extraTools):timer 全模式全深度;
215
- // plan 随模式位——ENG-PLAN-EXCLUSION(FR31 ① · KD8 卸载而非「注册 + 报错」· KD11 全深度两端);
216
- // task 随模式位——F10(task 工程模式机械停用;同 KD8 处置:**不入表**——模型不可见、零 token 税;
217
- // execute 层另有机械拒兜底,见 `agent-tools/task.mjs`)。
218
- // 工程模式固定段 = plan / task 皆**不入表**;普通模式固定段逐字不变(FR31 边界 / F10 边界)。
219
- // 判据 = 单一模式位 `engineering`(不带深度分支——子代理面随同排除,role enum
220
- // `subagentRoles` + spawn 门 / task execute 门已同向)。
221
- return engineering
222
- ? [timerTool, knowledgeTool, ...depthOnly]
223
- : [taskTool, planTool, timerTool, knowledgeTool, ...depthOnly]
214
+ // 固定段(装配序 = agent.tools → 固定段 → 家族段 → extraTools):timer ∥ knowledge 全模式全深度;
215
+ // plan 只进普通模式——ENG-PLAN-EXCLUSION(FR31 ① · KD8 卸载而非「注册 + 报错」· KD11 全深度两端);
216
+ // task 只进普通模式,工程模式不装配——理由见 `docs/core/design/TOOLS.md` §1「装配」。
217
+ // 普通模式固定段逐字不变(FR31 边界)。
218
+ // task 的门只在装配面这一处(`agent-tools/task.mjs` 的 `execute` 不再另判模式)。
219
+ if (engineering) {
220
+ return [timerTool, knowledgeTool, ...depthOnly]
221
+ }
222
+ return [taskTool, planTool, timerTool, knowledgeTool, ...depthOnly]
224
223
  }