@thincoder/core 0.11.3 → 0.11.5

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 (183) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/advisor/compaction.mjs +40 -17
  3. package/advisor/loop.mjs +14 -6
  4. package/advisor/notice.mjs +1 -1
  5. package/advisor/timeline.mjs +4 -4
  6. package/agent/completion.mjs +19 -0
  7. package/agent/dispatch-gates.mjs +2 -0
  8. package/agent/dispatch.mjs +2 -2
  9. package/agent/family-tools.mjs +13 -9
  10. package/agent/helpers.mjs +10 -6
  11. package/agent/planning-step.mjs +453 -0
  12. package/agent/post-turn.mjs +70 -2
  13. package/agent/run-stages.mjs +22 -50
  14. package/agent/run-start.mjs +17 -0
  15. package/agent/setup-reminders.mjs +71 -8
  16. package/agent/setup.mjs +8 -39
  17. package/agent/spawn-child.mjs +6 -2
  18. package/agent/task-lifecycle.mjs +146 -0
  19. package/agent/turn-loop.mjs +73 -11
  20. package/agent-tools/batch-closeout.mjs +21 -34
  21. package/agent-tools/batch-gate.mjs +7 -5
  22. package/agent-tools/batch-ledger-bind.mjs +21 -1
  23. package/agent-tools/batch-lifecycle.mjs +7 -7
  24. package/agent-tools/batch-record-write.mjs +237 -280
  25. package/agent-tools/batch-supersede.mjs +3 -3
  26. package/agent-tools/batch.mjs +42 -9
  27. package/agent-tools/context.mjs +0 -13
  28. package/agent-tools/escalate-async.mjs +7 -1
  29. package/agent-tools/parent-channel.mjs +7 -6
  30. package/agent-tools/plan.mjs +103 -67
  31. package/agent-tools/review-facts.mjs +3 -3
  32. package/agent-tools/settings.mjs +2 -0
  33. package/agent-tools/spawn-gates.mjs +37 -11
  34. package/agent-tools/ssh-session.mjs +68 -25
  35. package/agent-tools/ssh-transfer.mjs +7 -2
  36. package/agent-tools/ssh-transport.mjs +2 -2
  37. package/agent-tools/ssh-vault.mjs +2 -2
  38. package/agent-tools/step.mjs +462 -0
  39. package/agent-tools/subagent-actions.mjs +6 -1
  40. package/agent-tools/subagent-run.mjs +7 -0
  41. package/agent-tools/subagent-spawn.mjs +1 -1
  42. package/agent-tools/subagent.mjs +17 -11
  43. package/agent-tools/task.mjs +178 -26
  44. package/agent-tools.mjs +1 -0
  45. package/agent.mjs +2 -0
  46. package/config-defaults.mjs +17 -1
  47. package/config-migrate.mjs +8 -5
  48. package/config.mjs +7 -0
  49. package/context.mjs +5 -4
  50. package/declaration.mjs +4 -4
  51. package/generate-title.mjs +0 -6
  52. package/i18n.mjs +4 -0
  53. package/ledger-cmd.mjs +11 -1
  54. package/ledger-tools.mjs +15 -4
  55. package/manifest-schema.mjs +1 -0
  56. package/model-context.mjs +34 -11
  57. package/model-specs.mjs +5 -2
  58. package/package.json +1 -1
  59. package/prompt-files.mjs +48 -11
  60. package/prompt-overlays.mjs +79 -8
  61. package/prompts/advisor-design.md +253 -206
  62. package/prompts/advisor-round1.md +151 -145
  63. package/prompts/advisor-round2.md +136 -130
  64. package/prompts/advisor-round3.md +140 -134
  65. package/prompts/common.md +244 -96
  66. package/prompts/consult-base.md +29 -30
  67. package/prompts/discipline-engineering.md +73 -519
  68. package/prompts/discipline-normal.md +28 -136
  69. package/prompts/knowledge/batch-before-write.md +8 -0
  70. package/prompts/knowledge/batch-cycle-register.md +15 -0
  71. package/prompts/knowledge/batch-progress-ledger.md +29 -0
  72. package/prompts/knowledge/business-gates.md +24 -24
  73. package/prompts/knowledge/decision-quality.md +8 -19
  74. package/prompts/knowledge/doc-discipline-d-rules.md +63 -0
  75. package/prompts/knowledge/doc-lookup.md +25 -24
  76. package/prompts/knowledge/document-writing.md +11 -32
  77. package/prompts/knowledge/documentation-evaluation.md +42 -42
  78. package/prompts/knowledge/eng-dispatch-ops.md +34 -0
  79. package/prompts/knowledge/eng-ledger-ops.md +26 -0
  80. package/prompts/knowledge/evidence-discipline.md +10 -32
  81. package/prompts/knowledge/normal-batch-discipline.md +13 -0
  82. package/prompts/knowledge/normal-coding-workflow.md +97 -99
  83. package/prompts/knowledge/normal-delivery-collaboration.md +107 -112
  84. package/prompts/knowledge/normal-work-management.md +44 -44
  85. package/prompts/knowledge/product-security.md +7 -26
  86. package/prompts/knowledge/project-records.md +69 -64
  87. package/prompts/knowledge/tool-advisor.md +17 -17
  88. package/prompts/knowledge/tool-apply-patch.md +14 -14
  89. package/prompts/knowledge/tool-bash.md +32 -31
  90. package/prompts/knowledge/tool-batch-eng-coder.md +19 -13
  91. package/prompts/knowledge/tool-batch-eng-designer.md +21 -14
  92. package/prompts/knowledge/tool-batch-review.md +18 -12
  93. package/prompts/knowledge/tool-batch.md +93 -85
  94. package/prompts/knowledge/tool-browser.md +59 -59
  95. package/prompts/knowledge/tool-code-search.md +2 -2
  96. package/prompts/knowledge/tool-consult-start.md +6 -6
  97. package/prompts/knowledge/tool-consult-stop.md +3 -3
  98. package/prompts/knowledge/tool-context.md +4 -4
  99. package/prompts/knowledge/tool-delete.md +16 -16
  100. package/prompts/knowledge/tool-doc-check.md +39 -39
  101. package/prompts/knowledge/tool-doc-graph-read.md +11 -11
  102. package/prompts/knowledge/tool-doc-graph.md +48 -48
  103. package/prompts/knowledge/tool-doc-search.md +3 -3
  104. package/prompts/knowledge/tool-edit.md +30 -30
  105. package/prompts/knowledge/tool-eng.md +1 -1
  106. package/prompts/knowledge/tool-execute.md +16 -16
  107. package/prompts/knowledge/tool-fetch.md +15 -15
  108. package/prompts/knowledge/tool-file-ops.md +15 -15
  109. package/prompts/knowledge/tool-get-current-time.md +3 -3
  110. package/prompts/knowledge/tool-git-read.md +15 -15
  111. package/prompts/knowledge/tool-git.md +26 -26
  112. package/prompts/knowledge/tool-glob.md +14 -14
  113. package/prompts/knowledge/tool-goal.md +5 -5
  114. package/prompts/knowledge/tool-grep.md +19 -18
  115. package/prompts/knowledge/tool-hashline-edit.md +13 -13
  116. package/prompts/knowledge/tool-insert-after.md +14 -14
  117. package/prompts/knowledge/tool-instance-list.md +3 -3
  118. package/prompts/knowledge/tool-instance-send.md +5 -5
  119. package/prompts/knowledge/tool-knowledge.md +12 -12
  120. package/prompts/knowledge/tool-ledger-read.md +20 -20
  121. package/prompts/knowledge/tool-ledger.md +44 -44
  122. package/prompts/knowledge/tool-lint.md +10 -10
  123. package/prompts/knowledge/tool-ls.md +11 -11
  124. package/prompts/knowledge/tool-lsp.md +8 -8
  125. package/prompts/knowledge/tool-main-history.md +1 -1
  126. package/prompts/knowledge/tool-manifest-read.md +7 -7
  127. package/prompts/knowledge/tool-manifest.md +43 -32
  128. package/prompts/knowledge/tool-memory-read.md +12 -12
  129. package/prompts/knowledge/tool-memory.md +14 -14
  130. package/prompts/knowledge/tool-notify-parent.md +10 -10
  131. package/prompts/knowledge/tool-operations.md +88 -88
  132. package/prompts/knowledge/tool-peek.md +10 -0
  133. package/prompts/knowledge/tool-peer-instances.md +1 -1
  134. package/prompts/knowledge/tool-plan.md +6 -3
  135. package/prompts/knowledge/tool-process-read.md +8 -8
  136. package/prompts/knowledge/tool-process.md +11 -11
  137. package/prompts/knowledge/tool-question.md +11 -13
  138. package/prompts/knowledge/tool-read-history-batch.md +13 -13
  139. package/prompts/knowledge/tool-read-history.md +19 -19
  140. package/prompts/knowledge/tool-read-image.md +8 -8
  141. package/prompts/knowledge/tool-read.md +17 -17
  142. package/prompts/knowledge/tool-recent-changes.md +4 -4
  143. package/prompts/knowledge/tool-repo-outline.md +2 -2
  144. package/prompts/knowledge/tool-settings-read.md +5 -7
  145. package/prompts/knowledge/tool-settings.md +10 -10
  146. package/prompts/knowledge/tool-skill.md +4 -4
  147. package/prompts/knowledge/tool-ssh.md +66 -66
  148. package/prompts/knowledge/tool-step.md +26 -0
  149. package/prompts/knowledge/tool-subagent.md +52 -50
  150. package/prompts/knowledge/tool-task.md +14 -11
  151. package/prompts/knowledge/tool-team-ledger-read.md +7 -7
  152. package/prompts/knowledge/tool-team-ledger.md +13 -13
  153. package/prompts/knowledge/tool-timer.md +14 -14
  154. package/prompts/knowledge/tool-tree.md +11 -11
  155. package/prompts/knowledge/tool-verify.md +11 -11
  156. package/prompts/knowledge/tool-wait-for.md +20 -20
  157. package/prompts/knowledge/tool-websearch.md +16 -14
  158. package/prompts/knowledge/tool-write.md +10 -10
  159. package/prompts/knowledge/upstream-protocol.md +37 -38
  160. package/prompts/persona-coder.md +22 -22
  161. package/prompts/persona-eng-coder.md +87 -81
  162. package/prompts/persona-eng-designer.md +173 -153
  163. package/prompts/persona-engineering.md +53 -554
  164. package/prompts/persona-explore.md +18 -15
  165. package/prompts/persona-normal.md +62 -63
  166. package/prompts/persona-plan.md +36 -32
  167. package/prompts/persona-tester.md +39 -39
  168. package/prompts/planning-next-moves.md +9 -0
  169. package/prompts/subagent-base.md +4 -16
  170. package/provider/errors.mjs +0 -24
  171. package/provider/list-models.mjs +20 -2
  172. package/session-lifecycle.mjs +4 -3
  173. package/tool-args.mjs +25 -0
  174. package/tool-docs/peek.md +3 -0
  175. package/tool-docs/plan.md +1 -1
  176. package/tool-docs/question.md +1 -1
  177. package/tool-docs/step.md +3 -0
  178. package/tools/edit-diff.mjs +4 -4
  179. package/tools/index.mjs +3 -2
  180. package/tools/peek.mjs +447 -0
  181. package/tools/question.mjs +87 -9
  182. package/tools/ssh.mjs +1 -1
  183. package/window-policy.mjs +107 -80
package/CHANGELOG.md CHANGED
@@ -3,6 +3,29 @@
3
3
  All notable changes to the core package are documented here.
4
4
  Format: Keep a Changelog · 中文 · 号在发布时定(CalVer——见 `docs/RELEASE.md` §4)。
5
5
 
6
+ ## [0.11.5] — 2026-11-28
7
+
8
+ ### Fixed
9
+
10
+ - **越窗守卫被短路**:`runCompactionCheck` 收缩检查的两个 `return` 把 `enforceContextFit` 挡在 `try` 外,溢出守卫永远到不了——历史压不下去、发送前净判直接拒发。现改为布尔移出 `try`、守卫在 `catch` 闭合后与 `return` 前执行(仍不被压缩失败吞掉)。
11
+
12
+ ## [0.11.4] — 2026-11-28
13
+
14
+ ### Added
15
+
16
+ - **任务清单生命周期**:连续 5 轮工具未更新 `task` 时经 B 段发一次性轻推;收尾前对未闭项至多推回 1 次;全员 `done` 自动清表。
17
+ - **规划步核实评审结论**:`advisor` 触发按 `design` / `code` 分型,要求先核对源码与实跑读数,严禁照单全收。
18
+
19
+ ### Changed
20
+
21
+ - **开局规划不设条件**:任意非空用户输入在首轮前先做开局规划,不再按任务复杂度或短确认筛选。
22
+
23
+ ### Fixed
24
+
25
+ - **规划步失败退避**:失败后跳过紧随其后的一轮,不再每轮重打;默认值改为从 `DEFAULTS` 单源派生。
26
+ - **SSH 凭据被拒有界重试**:最多 3 次并沿用上次用户名,失败分类补齐 `Access denied` 等。
27
+ - **槽恢复点入参**:`resolveSessionWorkMode` 去掉已废弃的 config 入参。
28
+
6
29
  ## [0.11.3] — 2026-11-23
7
30
 
8
31
  ### Added
@@ -4,8 +4,9 @@
4
4
  * limits + the terminal-state guards + the review-text assembler.
5
5
  *
6
6
  * estimateTokens / compactMessages moved VERBATIM (the only edit is the `pinned`
7
- * re-attach — F13/`ADVISOR-GUARDS.md §2` #3); renderTimeline moved verbatim too, so the tail
8
- * GENERATOR and the tail CLASSIFIER stay in one file with the assembler they
7
+ * re-attach — F13/`ADVISOR-GUARDS.md §2` #3); renderTimeline lives here too — it assembles the
8
+ * timeline and shapes the report through `stripProcessNarration` (`ADVISOR-CONVERGENCE.md` §4.4),
9
+ * so the tail GENERATOR and the tail CLASSIFIER stay in one file with the assembler they
9
10
  * feed (`ADVISOR-GUARDS.md §1` 谓词 ↔ §4 结构化尾——同族单源)。拆分线 = 行数硬帽实测(见批次档 §5)。
10
11
  * advisor-loop-split 批:loop 的压缩检查点归位本档(`compactContextIfNeeded`——`context_limit` 尾串生成点同迁;时间线面 ⇒ `advisor/timeline.mjs`)。
11
12
  */
@@ -31,10 +32,9 @@ const COMPACT_TRIGGER_RATIO = 0.8 // 压缩触发 = 判死线 × 0.8(既
31
32
  /** 评审上下文预算(纯函数——两档阈值可机测;provider 为 null 时退化默认规格)。
32
33
  * 基数 = **可用窗口 = 窗口 − 完成预留**(#975/用户 2026-10-06 裁定——预留坐在窗口里 ⇒
33
34
  * 先压缩、不许 provider 先拒:provider 口径 = 输入 + max_tokens ≤ 窗口;预留 = `outputReserve`)。
34
- * 派生走 `requestBudget`(模型窗口出口的同一次算式、同一处判据与夹点,`CONTEXT-COMPACTION.md` §2.4):
35
- * 并立第二套处置会让这条线在配置矛盾上抛,而主链已是响应一声、夹住、放行。
36
- * 矛盾预算上 `limit` 已被夹到 `BUDGET_FLOOR_TOKENS`,比例项随之落到 0——评审面自己按「上下文受限」收尾
37
- * (`compactContextIfNeeded` 的 `context_limit` 尾),不抛。 */
35
+ * 派生走 `requestBudget`(模型窗口出口的同一次算式、同一处判据,`CONTEXT-COMPACTION.md` §2.2):
36
+ * 并立第二套处置会让这条线在配置变化时与主链分叉。派生链没有无解格(`reserve` 已封顶在 `window − threshold` 以下),
37
+ * `limit` 恒为正,评审面按正常预算判。 */
38
38
  export function advisorContextBudget(provider) {
39
39
  const limit = Math.floor(requestBudget(provider).limit * CONTEXT_LIMIT_RATIO)
40
40
  return { limit, compactAt: Math.floor(limit * COMPACT_TRIGGER_RATIO) }
@@ -178,24 +178,47 @@ export function timeoutTail(timeoutMs, rounds, toolCalls, producedText) {
178
178
  // them in lockstep.
179
179
  export const ADVISOR_THINKING_PLACEHOLDER = "\n[thinking…]\n"
180
180
 
181
+ /** 结论锚点(闭集——`ADVISOR-CONVERGENCE.md` §4.4):行首 `|`(结论表头行)· 行首 `VERDICT:`(判词行)·
182
+ * 宿主尾族前缀。宿主尾前缀表复用 `ADVISOR_INCOMPLETE_PREFIXES`(不另立第二份)。 */
183
+ function isConclusionAnchor(line) {
184
+ if (line.startsWith("|")) return true
185
+ if (line.startsWith("VERDICT:")) return true
186
+ return ADVISOR_INCOMPLETE_PREFIXES.some(([, prefix]) => line.startsWith(prefix))
187
+ }
188
+
181
189
  /**
182
- * Tool-call progress line summary delegates to the single source describeToolArgs
183
- * (../tool-args.mjs — B7 1a 上提核件单源;CLI `tui/tool-args.mjs` = 核件同名转口) — the same
184
- * function main-agent tool blocks and subagent blocks use. 2026-08-31: replaced the local
185
- * picker (action/path/pattern/command-only) so advisor progress lines show the quoted-path
186
- * forms everywhere else.
190
+ * 报告定形(`ADVISOR-CONVERGENCE.md` §4.4):剥掉首个结论锚点之前的过程流水,报告自锚点起原文返回
191
+ * (去尾空白);锚点就在首行或整篇无锚点 ⇒ 原样返回——没有可锚的结论就不猜切口。
192
+ * 锚点按行扫描、围栏内的行不参与、且只在块首行成立(首行或上一行为空行)。纯函数、零状态;
193
+ * 宿主在定形之后追加的文案不过这一关(只剥一次)。
194
+ * @param {string} report — 装配器合流后的报告正文
195
+ * @returns {string} 定形后的报告正文
187
196
  */
197
+ export function stripProcessNarration(report) {
198
+ const text = String(report ?? "")
199
+ const lines = text.split("\n")
200
+ let fenced = false
201
+ for (let i = 0; i < lines.length; i++) {
202
+ if (lines[i].trim().startsWith("```")) { fenced = !fenced; continue }
203
+ if (fenced || (i > 0 && lines[i - 1].trim() !== "")) continue
204
+ if (!isConclusionAnchor(lines[i])) continue
205
+ return i === 0 ? text : lines.slice(i).join("\n").trimEnd()
206
+ }
207
+ return text
208
+ }
209
+
188
210
  /**
189
- * Render the ordered review timeline — thinking / tool progress / final text
190
- * interleaved EXACTLY as emitted, so the persisted record shows the review
191
- * process at its real positions. A summary appended at the end would lose the
192
- * order (the user-visible "no tool calls in the advisor record" gap). The
193
- * live "[thinking…]" placeholder is stripped (wait indicator, not content).
211
+ * Render the ordered review timeline and define the report: thinking / tool
212
+ * progress / final text are assembled in emission order, then
213
+ * `stripProcessNarration` drops everything before the first conclusion anchor,
214
+ * so the report handed to the digest and the tool receipt carries the
215
+ * conclusion face only (`ADVISOR-CONVERGENCE.md` §4.4). The live "[thinking…]"
216
+ * placeholder is stripped (wait indicator, not content).
194
217
  */
195
218
  export function renderTimeline(timeline, tail = "") {
196
219
  const body = timeline
197
220
  .map((b) => b.text.replaceAll(ADVISOR_THINKING_PLACEHOLDER, "").trim())
198
221
  .filter(Boolean)
199
222
  .join("\n\n")
200
- return [body, tail].filter(Boolean).join("\n\n")
223
+ return stripProcessNarration([body, tail].filter(Boolean).join("\n\n"))
201
224
  }
package/advisor/loop.mjs CHANGED
@@ -27,6 +27,7 @@ import { docCheckTool } from "../agent-tools/doc-check.mjs"
27
27
  import { docGraphReadTool } from "../agent-tools/doc-graph.mjs"
28
28
  import {
29
29
  shouldBudgetNudge, budgetNudgeText, timeoutTail, renderTimeline, compactContextIfNeeded,
30
+ stripProcessNarration,
30
31
  MAX_ADVISOR_TURNS, advisorContextBudget, TOOL_TIMEOUT_MS, REVIEW_TIMEOUT_MS, MAX_RESULT_CHARS,
31
32
  ADVISOR_THINKING_PLACEHOLDER,
32
33
  } from "./compaction.mjs"
@@ -76,7 +77,8 @@ function advisorToolsFor(agent, reviewType, batchDoc = null) {
76
77
  // 就靠这一条)。未绑定 → 不挂载(fail-closed)。
77
78
  if (reviewHoldsBatchWrite(agent, reviewType, batchDoc)) tools.push(batchTool(batchDoc, { review: true, reviewType }))
78
79
  // 工具描述取完整档(设计 TOOLS §1):评审是独立基底,不随会话 mode 变化(requirements §9.1)。
79
- return { schemas: tools.map((tool) => toOpenAISchema(tool, "normal")), byName: new Map(tools.map((t) => [t.name, t])) }
80
+ const ordered = [...tools].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
81
+ return { schemas: ordered.map((tool) => toOpenAISchema(tool, "normal")), byName: new Map(ordered.map((t) => [t.name, t])) }
80
82
  }
81
83
  // Test seam: the tool set is pure(恒在六工具 + 批次档绑定條件)。
82
84
  export { advisorToolsFor, advisorToolsFor as _advisorToolsFor }
@@ -221,12 +223,18 @@ async function runAdvisorToolLoop(provider, messages, onOutput, signal, agent, c
221
223
  return renderTimeline(timeline, timeoutTail(timeoutMs, turns, toolCallCount, reviewTextProduced))
222
224
  }
223
225
 
224
- // No tool calls — this is the final review text. The final answer was
225
- // already streamed into the timeline via onText; fall back to
226
- // response.content only if nothing was recorded.
226
+ // No tool calls — this is the final review text. The report is this round's
227
+ // own output, shaped through the same report-defining strip; the timeline
228
+ // (every earlier round's exploration) is only the fallback when this round
229
+ // produced no text (`ADVISOR-CONVERGENCE.md` §4.4).
227
230
  if (!response.toolCalls?.length) {
228
- if (!response.content?.trim()) return renderTimeline(timeline) || "Advisor: empty response — review was inconclusive"
229
- return renderTimeline(timeline) || response.content.trim()
231
+ const conclusion = stripProcessNarration(response.content?.trim() || "")
232
+ // A rescued partial stream (network error after the first bytes, no signal
233
+ // abort) is an exception path, not this round's conclusion: its report
234
+ // stays the timeline and the partial text only backs it up. Same value as
235
+ // before this change (batch §1 criterion C).
236
+ const report = response.partial ? renderTimeline(timeline) || conclusion : conclusion || renderTimeline(timeline)
237
+ return report || "Advisor: empty response — review was inconclusive"
230
238
  }
231
239
 
232
240
  // Push assistant message with tool calls. reasoning_content ECHO is
@@ -78,7 +78,7 @@ export function buildTypeGateRefusal({ criterion, received = null, declared = nu
78
78
  }
79
79
  parts.push(
80
80
  ' • type="code" — code review: reviews the code you changed; pass paths=[...] to scope files/directories (documents=[...] adds acceptance-criteria context).',
81
- ' • type="design" — design review: reviews design / requirement documents; pass documents=[...] (the explicit list) and batchDoc — required, the batch record this review belongs to.',
81
+ ' • type="design" — design review: reviews design documents (requirement docs are the ruler, not the object under review); pass documents=[...] (the explicit list) and batchDoc — required, the batch record this review belongs to.',
82
82
  "Nothing was sent: no review instance, no round consumed, no design token minted, no LLM call.",
83
83
  )
84
84
  return parts.join("\n")
@@ -8,10 +8,10 @@
8
8
  */
9
9
  export function createTimelineRecorder(onOutput) {
10
10
  // Kind-tagged wrappers: the TUI panel colors reasoning / answer / tool progress differently.
11
- // Every chunk is ALSO recorded into an ordered timeline — the persisted record
12
- // must show the review process (thinking ↔ tool progress ↔ final text) at its
13
- // real positions, not a summary appended at the end. Same-kind consecutive
14
- // chunks merge (token streams); kind flips start a new entry.
11
+ // Every chunk is ALSO recorded into an ordered timeline so the report assembler
12
+ // (renderTimeline, compaction.mjs) sees the emission order; the report it returns keeps
13
+ // only the conclusion face (`ADVISOR-CONVERGENCE.md` §4.4). Same-kind consecutive chunks
14
+ // merge (token streams); kind flips start a new entry.
15
15
  const timeline = []
16
16
  const record = (kind, text) => {
17
17
  const last = timeline.at(-1)
@@ -9,6 +9,8 @@ import { hasCodeMutations } from "../advisor/repos.mjs"
9
9
  import { pushReal, pushInject } from "../context.mjs"
10
10
  import { specForModel, assistantTextMessage, isThinkingRequest } from "../config.mjs"
11
11
  import { advisorReviewPending, effectiveAdvisorRound } from "../agent-tools/advisor-async.mjs"
12
+ import { poolLive } from "./suspension.mjs"
13
+ import { shouldPushbackUnclosedTasks } from "./task-lifecycle.mjs"
12
14
 
13
15
  const MAX_VERIFY_PUSHBACKS = 2
14
16
  const MAX_VERIFY_RETRIES = 3
@@ -195,6 +197,23 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
195
197
  }
196
198
  }
197
199
 
200
+ // --- task closeout check: bounded 1-time reminder when stale/in_progress tasks remain ---
201
+ // 允许刻意刚记录 `pending` 后立即交接(`inProgress === 0 && _turnsSinceTaskUpdate === 0` 不触发);
202
+ // 在途异步池或 `timer` 存在、工程模式、自动回合与子代理均跳过。
203
+ const taskCheck = shouldPushbackUnclosedTasks(agent, {
204
+ depth,
205
+ taskPushbacks: agent._taskClosePushbacks ?? 0,
206
+ poolActive: poolLive(agent),
207
+ })
208
+ if (taskCheck.pushback && taskCheck.reminder) {
209
+ agent._taskClosePushbacks = (agent._taskClosePushbacks ?? 0) + 1
210
+ pushAssistantText(agent, response)
211
+ pushInject(agent, { role: "user", content: taskCheck.reminder })
212
+ callbacks.onSubTurnBreak?.()
213
+ callbacks.onTurnEnd?.(agent, turn)
214
+ return { action: "continue", guardPushbacks, honestReminderInjected, advisorPushbacks }
215
+ }
216
+
198
217
  pushAssistantText(agent, response)
199
218
  return { action: "done", content: response.content, guardPushbacks, honestReminderInjected, advisorPushbacks }
200
219
  }
@@ -87,6 +87,8 @@ export function isReadonlyAction(toolName, args) {
87
87
  // #9(TOOLS.md §6.19):process 动作分级——list 保持只读分类(planMode 放行/免审批/可批并行);
88
88
  // kill 是破坏性动作(审批门 + planMode 拒)。
89
89
  if (toolName === "process") return args?.action !== "kill"
90
+ // `step` 分叉微步(`STEP-FORK.md` §3):readonly=true 为只读动作(planMode 放行 / 免审批 / 同轮并行)
91
+ if (toolName === "step") return args?.readonly === true
90
92
  if (toolName !== "subagent" || !args || typeof args !== "object") return false
91
93
  const action = args.action
92
94
  // AGENT-LOOP-SUBAGENT.md §6.7.5: check 动作已删除——只读面仅剩 status(planMode 放行/免权限审批/可批并行)
@@ -92,7 +92,7 @@ export async function executeToolCalls(agent, toolByName, toolCalls, callbacks,
92
92
  // DESIGN-TOKEN-SETTLEMENT D3(2026-09-08):资格判据 = 权威槽"任一活槽存在"
93
93
  // (anyLiveDesignSlot——查内存 Map,miss 回读槽文件——单值镜像 `_engDesignToken`
94
94
  // 已退役,门禁不再读镜像——AC4)。
95
- if (agent.config?.agent?.engineering && depth === 0
95
+ if (agent.config?.agent?.engineering && (depth === 0 || agent._forkedStep)
96
96
  && !anyLiveDesignSlot(agent)
97
97
  && FILE_MUTATORS.has(toolCall.name)) {
98
98
  const paths = toolTouchPaths(tool, args)
@@ -277,7 +277,7 @@ export async function executeToolCalls(agent, toolByName, toolCalls, callbacks,
277
277
  // parallel flag): it flushes the batch and runs alone in call order (AGENT-LOOP-SUBAGENT.md §6.7 —
278
278
  // spawn stays parallel; status classifies as readonly and batch freely).
279
279
  if (item.tool && !item.tool.readonly
280
- && (!item.tool.parallel || isSubagentEscalateAction(item.tool.name, item.args))) {
280
+ && (!(item.tool.parallel || item.tool.isParallelAction?.(item.args)) || isSubagentEscalateAction(item.tool.name, item.args))) {
281
281
  await flush()
282
282
  results.push(await runPreparedItem(item, agent, depth, signal, callbacks))
283
283
  } else {
@@ -25,10 +25,11 @@ export async function assembleFamilyTools({
25
25
  engineering = false, // boolean depth-0 role enum 注入用(工程模式)
26
26
  consultModels = [], // array consult 池([] ⇒ consult 工具不注册)
27
27
  batchDoc = null, // string 批次档绑定路径(eng 角色恒挂 ∥ 普通面 coder 携绑定挂——batchTool 绑定)
28
+ sync = false, // boolean 同步阻塞子代理(async:false / 嵌套)不挂 notify_parent(父阻塞不可答)
28
29
  decorate = null, // object 端差面:{ subagent?, consultStart?, consultStop?, settings? }
29
30
  } = {}) {
30
31
  // CORE-UNIFICATION TOOLS #83:consult 家族随统一登记册自 `../agent-tools.mjs` 取用(单一来源)
31
- const { planTool, subagentTool, taskTool, skillTool, goalTool, verifyTool, recentChangesTool, timerTool, advisorTool, engTool, readHistoryTool, contextTool, batchTool, manifestTool, manifestReadTool, consultStartTool, consultStopTool, parentChannelTool, docCheckTool, docGraphTool, docGraphReadTool } = await import("../agent-tools.mjs")
32
+ const { planTool, subagentTool, stepTool, stepReadTool, taskTool, skillTool, goalTool, verifyTool, recentChangesTool, timerTool, advisorTool, engTool, readHistoryTool, contextTool, batchTool, manifestTool, manifestReadTool, consultStartTool, consultStopTool, parentChannelTool, docCheckTool, docGraphTool, docGraphReadTool } = await import("../agent-tools.mjs")
32
33
  // 台账统一入口(2026-10-05 统一入口批——台账 #923):全量变体 = depth-0 段 ∥ 只读变体 = 全部
33
34
  // depth>0 段。动态 import——ledger 链静态达 node:sqlite(W8 契约②);两变体同名单对象、schema 窄化。
34
35
  const { ledgerTool, ledgerReadTool } = await import("../ledger.mjs")
@@ -59,7 +60,7 @@ export async function assembleFamilyTools({
59
60
  suffix: " In engineering mode, use role='eng-coder' for implementation (coder is disabled) and role='eng-designer' for writing the requirements/design documents." + testerSuffix,
60
61
  }
61
62
  : {
62
- enum: ["explore", "plan", "coder", "tester"],
63
+ enum: ["explore", "coder", "tester"],
63
64
  description: "The sub-agent role — see the tool description for the role capability matrix. Exact spelling required.",
64
65
  suffix: testerSuffix,
65
66
  }
@@ -131,8 +132,8 @@ export async function assembleFamilyTools({
131
132
  ...subagentTool,
132
133
  name: "subagent",
133
134
  description: designer
134
- ? "Spawn a read-only `explore` sub-agent to SURVEY the current state for the design: it reads code / docs / existing designs and reports evidence with file:line. BLOCKING ONLY (no async) and action:'spawn' ONLY — the survey channel is read-only; escalate/status/cancel/panel/consume-design/observe/send are not available. Survey budget: ≤6 explore spawns per batch — the main agent's survey result is reference only; do your own. The spawn carries the five task-book parameters (four core: goal / knownFacts / acceptance / reportFormat + `scope`); a task-only spawn is refused."
135
- : "Spawn a read-only `explore` sub-agent to AUDIT your delivery against the design: it compares the delivered code with the design for divergence — partially implemented acceptance criteria, silent simplifications, doc drift, changes outside the approved file list. BLOCKING ONLY (no async — the audit report decides your next protocol step). action:'spawn' ONLY — the audit channel is a read-only spawn; escalate/status/cancel/panel/consume-design/observe/send are not available. The audit context is appended MECHANICALLY — the batch record path (its §2 is the delivery's task book, read it before judging) plus the files you actually touched; never hand the audit a self-written file list (a self-report could omit exactly the out-of-scope file it must catch). The spawn carries the five task-book parameters (four core: goal / knownFacts / acceptance / reportFormat + `scope`); a task-only spawn is refused.",
135
+ ? "Spawn a read-only `explore` sub-agent to SURVEY the current state for the design: it reads code / docs / existing designs and reports evidence with file:line. BLOCKING ONLY (no async) and action:'spawn' ONLY — the survey channel is read-only; escalate/status/cancel/panel/consume-design/observe/send are not available. Survey budget: ≤6 explore spawns per batch — the main agent's survey result is reference only; do your own. Requires `goal` and `scope` (`knownFacts` / `acceptance` / `reportFormat` / `thoroughness` optional); a task-only spawn is refused."
136
+ : "Spawn a read-only `explore` sub-agent to AUDIT your delivery against the design: it compares the delivered code with the design for divergence — partially implemented acceptance criteria, silent simplifications, doc drift, changes outside the approved file list. BLOCKING ONLY (no async — the audit report decides your next protocol step). action:'spawn' ONLY — the audit channel is a read-only spawn; escalate/status/cancel/panel/consume-design/observe/send are not available. The audit context is appended MECHANICALLY — the batch record path (its §2 is the delivery's task book, read it before judging) plus the files you actually touched; never hand the audit a self-written file list (a self-report could omit exactly the out-of-scope file it must catch). Requires `goal` and `scope` (`knownFacts` / `acceptance` / `reportFormat` / `thoroughness` optional); a task-only spawn is refused.",
136
137
  parameters: { ...subagentTool.parameters, properties: props },
137
138
  // `async` 不在本变体 schema 里(`delete props.async`)= 这条通道**没有异步选项**。`async` 必填化后
138
139
  // 由变体自己声明固定值(同步),而不是给模型留一个缺省——缺省就是替调用方拿主意,同步才是本通道的契约。
@@ -155,9 +156,12 @@ export async function assembleFamilyTools({
155
156
  // (三动作、无 `scan`:子代理段的台账是只读变体,扫由父侧做——D-DT1)。五段各写一遍字面就是五份会各自漂的
156
157
  // 单子(D-DT4);并成一段又会抹掉各段真实差异。depth-0 段不展开本组:那边挂的是全量 `docGraphTool` + `docCheckTool`。
157
158
  const docTools = [docCheckTool, docGraphReadTool]
159
+ // 同步阻塞子代理(sync=true)期间父代理被 await 阻塞无法响应 send,不挂载 notify_parent
160
+ // (避免子代理白耗一轮发 ask 并污染 _childUpstream 触发幽灵唤醒);待裁项随最终报告同步返回。
161
+ const upstreamTools = sync ? [] : [parentChannelTool]
158
162
 
159
163
  const depthOnly = depth === 0
160
- ? [decorate?.subagent ?? filteredSubagent, skillTool, goalTool, engTool, verifyTool, recentChangesTool, readHistoryTool, contextTool, advisorTool, batchTool(null),
164
+ ? [decorate?.subagent ?? filteredSubagent, engineering ? stepReadTool : stepTool, skillTool, goalTool, engTool, verifyTool, recentChangesTool, readHistoryTool, contextTool, advisorTool, batchTool(null),
161
165
  ...consultTools,
162
166
  // 台账全量变体(五 action——仅主 agent 装配;fail-closed:子代理段只挂读变体 = 写面机械不可达)
163
167
  ledgerTool,
@@ -203,13 +207,13 @@ export async function assembleFamilyTools({
203
207
  // 团队台账只读变体(team-ledger 批)同律。
204
208
  // manifest 只读变体(MANIFEST.md §2.10.1 · 2026-10-22 · 台账 #1738):同名 `manifest`、action 枚举只剩 `read`;
205
209
  // 与上两条只读先例同律挂在全部 depth>0 角色段(全量变体仅 depth-0——两变体互斥装配,同名不塌缩)。
206
- : engChildRole === "eng-coder" ? [parentChannelTool, ledgerReadTool, teamLedgerReadTool, manifestReadTool, advisorTool, verifyTool, batchTool(batchDoc, { role: "eng-coder" }), ...docTools,
210
+ : engChildRole === "eng-coder" ? [...upstreamTools, ledgerReadTool, teamLedgerReadTool, manifestReadTool, advisorTool, verifyTool, batchTool(batchDoc, { role: "eng-coder" }), ...docTools,
207
211
  ...(engChildSubagent ? [engChildSubagent] : [])]
208
- : engChildRole === "eng-designer" ? [parentChannelTool, ledgerReadTool, teamLedgerReadTool, manifestReadTool, batchTool(batchDoc, { role: "eng-designer" }), ...docTools,
212
+ : engChildRole === "eng-designer" ? [...upstreamTools, ledgerReadTool, teamLedgerReadTool, manifestReadTool, batchTool(batchDoc, { role: "eng-designer" }), ...docTools,
209
213
  ...(engChildSubagent ? [engChildSubagent] : [])]
210
- : role === "coder" ? [parentChannelTool, ledgerReadTool, teamLedgerReadTool, manifestReadTool, verifyTool, advisorTool, ...docTools, ...(batchDoc ? [batchTool(batchDoc, { role: "coder" })] : [])]
214
+ : role === "coder" ? [...upstreamTools, ledgerReadTool, teamLedgerReadTool, manifestReadTool, verifyTool, advisorTool, ...docTools, ...(batchDoc ? [batchTool(batchDoc, { role: "coder" })] : [])]
211
215
  : role === "consult" ? [recentChangesTool, ledgerReadTool, teamLedgerReadTool, manifestReadTool, ...docTools]
212
- : [parentChannelTool, ledgerReadTool, teamLedgerReadTool, manifestReadTool, ...docTools]
216
+ : [...upstreamTools, ledgerReadTool, teamLedgerReadTool, manifestReadTool, ...docTools]
213
217
 
214
218
  // 固定段(装配序 = agent.tools → 固定段 → 家族段 → extraTools):timer ∥ knowledge 全模式全深度;
215
219
  // plan 只进普通模式——ENG-PLAN-EXCLUSION(FR31 ① · KD8 卸载而非「注册 + 报错」· KD11 全深度两端);
package/agent/helpers.mjs CHANGED
@@ -404,12 +404,16 @@ export function deriveReadonlyTools(tools, isReadonly) {
404
404
  return out
405
405
  }
406
406
 
407
- /** Depth>0 tool exclusions — subagents never get the interactive main-session tools (`question`:
408
- * no user to ask; `ssh`: the credential window is a user-facing event AND the session pool
409
- * belongs to the main session — no UI at depth>0 and no session to hand back; the routing
410
- * guidance already lives in every persona file). Single source for the repo: the shell-side
411
- * depth>0 filter consumes this set (design = TOOLS.md §6.16 / D-TO11 + §6.22). */
412
- export const SUBAGENT_TOOL_EXCLUSIONS = new Set(["question", "ssh"])
407
+ /** Depth>0 tool exclusions — subagents never get the interactive main-session tool `question`
408
+ * (no user to ask at depth>0; its schema-only face would just hang a child with nobody to ask).
409
+ * `ssh` is NO LONGER here: a child builds its own `_sshSessions` pool (lazily, `ssh-session.mjs`),
410
+ * so it cannot squeeze the main session's 4 slots; the password-credential window already returns a
411
+ * readable error when no UI exists (`ssh-vault.mjs` §6.22 ⑧), so a child on a password host fails
412
+ * loudly instead of hanging; and the child's pool is drained when the child settles
413
+ * (`discardSshSessions`) — a child's remote sessions must never outlive the child.
414
+ * Single source for the repo: the shell-side depth>0 filter consumes this set
415
+ * (design = TOOLS.md §6.4 轮次收尾与子代理上抛 + §6.1 池帽). */
416
+ export const SUBAGENT_TOOL_EXCLUSIONS = new Set(["question"])
413
417
 
414
418
  /** Apply the depth>0 exclusion set — always returns a NEW array (parent table untouched).
415
419
  * #9(TOOLS.md §6.19):`bash` 的 `async` 参仅 depth-0——子代副本删参(照 `family-tools.mjs` 的 `engChildSubagent`