thincoder 0.12.61 → 0.12.63

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 (230) hide show
  1. package/CHANGELOG.md +34 -1
  2. package/README.md +13 -12
  3. package/bin/thincoder.mjs +63 -28
  4. package/package.json +6 -5
  5. package/src/acp/bridge.mjs +35 -15
  6. package/src/acp/client-caps.mjs +86 -0
  7. package/src/acp/ext.mjs +86 -0
  8. package/src/acp/handlers-session.mjs +240 -0
  9. package/src/acp/handlers-slots.mjs +196 -0
  10. package/src/acp/login.mjs +48 -0
  11. package/src/acp/session.mjs +6 -4
  12. package/src/acp.mjs +67 -371
  13. package/src/cli/distill-command.mjs +3 -3
  14. package/src/cli/make-agent.mjs +59 -17
  15. package/src/cli/memory-command.mjs +3 -3
  16. package/src/cli/permission.mjs +4 -48
  17. package/src/cli/setup-wizard.mjs +1 -1
  18. package/src/completions.mjs +3 -1
  19. package/src/crash-reports.mjs +32 -10
  20. package/src/distill.mjs +4 -4
  21. package/src/heap-watch.mjs +88 -0
  22. package/src/prompt-injections.mjs +20 -0
  23. package/src/tui/agent-turn.mjs +40 -9
  24. package/src/tui/cmd-advisor.mjs +5 -5
  25. package/src/tui/cmd-clear.mjs +2 -0
  26. package/src/tui/cmd-config.mjs +8 -8
  27. package/src/tui/cmd-eng.mjs +25 -9
  28. package/src/tui/cmd-mcp.mjs +9 -8
  29. package/src/tui/cmd-model.mjs +1 -1
  30. package/src/tui/cmd-new.mjs +10 -5
  31. package/src/tui/cmd-reindex.mjs +1 -1
  32. package/src/tui/cmd-restore.mjs +2 -2
  33. package/src/tui/cmd-session.mjs +31 -4
  34. package/src/tui/cmd-skills.mjs +1 -1
  35. package/src/tui/cmd-think.mjs +22 -9
  36. package/src/tui/config-helpers.mjs +1 -1
  37. package/src/tui/display-budget.mjs +206 -0
  38. package/src/tui/index.mjs +40 -12
  39. package/src/tui/interaction.mjs +16 -7
  40. package/src/tui/key-handler-search.mjs +9 -1
  41. package/src/tui/key-modes.mjs +9 -4
  42. package/src/tui/ledger-surface.mjs +85 -0
  43. package/src/tui/model-catalog.mjs +4 -4
  44. package/src/tui/model-picker.mjs +8 -7
  45. package/src/tui/mouse.mjs +11 -6
  46. package/src/tui/pickers.mjs +15 -2
  47. package/src/tui/render-conversation.mjs +1 -1
  48. package/src/tui/render-frame.mjs +17 -6
  49. package/src/tui/render-loop.mjs +1 -1
  50. package/src/tui/render-segments.mjs +3 -1
  51. package/src/tui/slash-commands.mjs +1 -1
  52. package/src/tui/startup.mjs +49 -17
  53. package/src/tui/subagent-blocks.mjs +21 -3
  54. package/src/tui/subagent-children.mjs +86 -14
  55. package/src/tui/subagent-freeze.mjs +80 -3
  56. package/src/tui/suspension-drive.mjs +48 -22
  57. package/src/tui/tool-args.mjs +5 -2
  58. package/src/tui/tool-display.mjs +16 -2
  59. package/src/tui/tool-events.mjs +64 -22
  60. package/src/tui/tui-lifecycle.mjs +9 -2
  61. package/src/tui/wizard.mjs +3 -3
  62. package/src/tui/wrapped-spawn.mjs +21 -5
  63. package/src/abort-provenance.mjs +0 -116
  64. package/src/advisor/citations.mjs +0 -139
  65. package/src/advisor/compaction.mjs +0 -174
  66. package/src/advisor/convergence.mjs +0 -80
  67. package/src/advisor/history.mjs +0 -77
  68. package/src/advisor/loop.mjs +0 -293
  69. package/src/advisor/messages.mjs +0 -299
  70. package/src/advisor/project-context.mjs +0 -194
  71. package/src/advisor/repos.mjs +0 -150
  72. package/src/advisor/run.mjs +0 -293
  73. package/src/advisor/truncate.mjs +0 -57
  74. package/src/advisor.mjs +0 -290
  75. package/src/agent/completion.mjs +0 -146
  76. package/src/agent/dispatch.mjs +0 -489
  77. package/src/agent/helpers.mjs +0 -384
  78. package/src/agent/post-turn.mjs +0 -70
  79. package/src/agent/record-results.mjs +0 -174
  80. package/src/agent/relay-prefix.mjs +0 -39
  81. package/src/agent/run-stages.mjs +0 -242
  82. package/src/agent/setup-reminders.mjs +0 -69
  83. package/src/agent/setup.mjs +0 -354
  84. package/src/agent/spawn-child.mjs +0 -228
  85. package/src/agent-tools/advisor-async.mjs +0 -346
  86. package/src/agent-tools/advisor-settle.mjs +0 -231
  87. package/src/agent-tools/advisor.mjs +0 -260
  88. package/src/agent-tools/async-settle.mjs +0 -191
  89. package/src/agent-tools/batch-segment.mjs +0 -195
  90. package/src/agent-tools/consult.mjs +0 -468
  91. package/src/agent-tools/design-token.mjs +0 -117
  92. package/src/agent-tools/digest-budget.mjs +0 -76
  93. package/src/agent-tools/eng.mjs +0 -67
  94. package/src/agent-tools/escalate-async.mjs +0 -289
  95. package/src/agent-tools/goal.mjs +0 -119
  96. package/src/agent-tools/plan.mjs +0 -81
  97. package/src/agent-tools/read-history.mjs +0 -294
  98. package/src/agent-tools/recent-changes.mjs +0 -24
  99. package/src/agent-tools/review-streak.mjs +0 -93
  100. package/src/agent-tools/settings.mjs +0 -265
  101. package/src/agent-tools/skill.mjs +0 -47
  102. package/src/agent-tools/subagent-actions.mjs +0 -479
  103. package/src/agent-tools/subagent-async.mjs +0 -434
  104. package/src/agent-tools/subagent-panel.mjs +0 -160
  105. package/src/agent-tools/subagent-run.mjs +0 -205
  106. package/src/agent-tools/subagent-scheduler.mjs +0 -392
  107. package/src/agent-tools/subagent-spawn.mjs +0 -453
  108. package/src/agent-tools/subagent.mjs +0 -404
  109. package/src/agent-tools/task.mjs +0 -87
  110. package/src/agent-tools/timer.mjs +0 -46
  111. package/src/agent-tools/verify.mjs +0 -271
  112. package/src/agent-tools.mjs +0 -17
  113. package/src/agent.mjs +0 -413
  114. package/src/auto-think.mjs +0 -115
  115. package/src/config-migrate.mjs +0 -70
  116. package/src/config.mjs +0 -496
  117. package/src/context.mjs +0 -381
  118. package/src/conventions.mjs +0 -223
  119. package/src/embedding.mjs +0 -120
  120. package/src/escape.mjs +0 -152
  121. package/src/expand-home.mjs +0 -16
  122. package/src/explore-distill.mjs +0 -155
  123. package/src/generate-title.mjs +0 -83
  124. package/src/git/checkpoint.mjs +0 -448
  125. package/src/git/gitmem.mjs +0 -100
  126. package/src/hooks.mjs +0 -97
  127. package/src/log.mjs +0 -195
  128. package/src/markdown.mjs +0 -106
  129. package/src/mcp/helpers.mjs +0 -51
  130. package/src/mcp/transport-http.mjs +0 -248
  131. package/src/mcp/transport-stdio.mjs +0 -140
  132. package/src/mcp/transport-ws.mjs +0 -122
  133. package/src/mcp.mjs +0 -295
  134. package/src/memory/code-index.mjs +0 -219
  135. package/src/memory/code-sync.mjs +0 -413
  136. package/src/memory/core.mjs +0 -300
  137. package/src/memory/delete.mjs +0 -236
  138. package/src/memory/docs.mjs +0 -417
  139. package/src/memory/file-walk.mjs +0 -109
  140. package/src/memory/schema.mjs +0 -452
  141. package/src/memory.mjs +0 -21
  142. package/src/model-ref.mjs +0 -66
  143. package/src/model-specs.mjs +0 -179
  144. package/src/peer-domains.mjs +0 -265
  145. package/src/peer-instances.mjs +0 -231
  146. package/src/prompt-overlays.mjs +0 -82
  147. package/src/prompts/advisor-design.md +0 -41
  148. package/src/prompts/advisor-round1.md +0 -41
  149. package/src/prompts/advisor-round2.md +0 -46
  150. package/src/prompts/advisor-round3.md +0 -42
  151. package/src/prompts/common.md +0 -115
  152. package/src/prompts/consult-base.md +0 -19
  153. package/src/prompts/discipline-engineering.md +0 -217
  154. package/src/prompts/discipline-normal.md +0 -179
  155. package/src/prompts/persona-coder.md +0 -21
  156. package/src/prompts/persona-eng-coder.md +0 -37
  157. package/src/prompts/persona-eng-designer.md +0 -55
  158. package/src/prompts/persona-engineering.md +0 -54
  159. package/src/prompts/persona-explore.md +0 -15
  160. package/src/prompts/persona-normal.md +0 -27
  161. package/src/prompts/persona-plan.md +0 -26
  162. package/src/provider/anthropic.mjs +0 -225
  163. package/src/provider/core.mjs +0 -476
  164. package/src/provider/errors.mjs +0 -101
  165. package/src/provider/google.mjs +0 -257
  166. package/src/provider/index.mjs +0 -7
  167. package/src/provider/list-models.mjs +0 -93
  168. package/src/provider/normalize.mjs +0 -81
  169. package/src/provider/rate.mjs +0 -108
  170. package/src/provider/responses.mjs +0 -495
  171. package/src/provider/retry.mjs +0 -88
  172. package/src/provider/sse.mjs +0 -264
  173. package/src/proxy.mjs +0 -261
  174. package/src/rules.mjs +0 -53
  175. package/src/session-gc.mjs +0 -214
  176. package/src/session-guard.mjs +0 -47
  177. package/src/session-migrate.mjs +0 -48
  178. package/src/session-rename.mjs +0 -38
  179. package/src/session-slots.mjs +0 -489
  180. package/src/session.mjs +0 -475
  181. package/src/skills.mjs +0 -153
  182. package/src/token-ttl.mjs +0 -274
  183. package/src/tools/apply_patch.md +0 -15
  184. package/src/tools/bash.md +0 -37
  185. package/src/tools/bash.mjs +0 -268
  186. package/src/tools/checklist-sync.mjs +0 -181
  187. package/src/tools/checklist.md +0 -13
  188. package/src/tools/checklist.mjs +0 -299
  189. package/src/tools/delete.md +0 -13
  190. package/src/tools/edit-batch.mjs +0 -191
  191. package/src/tools/edit-diff.mjs +0 -348
  192. package/src/tools/edit.md +0 -30
  193. package/src/tools/execute.md +0 -21
  194. package/src/tools/execute.mjs +0 -228
  195. package/src/tools/fetch.md +0 -12
  196. package/src/tools/file.mjs +0 -469
  197. package/src/tools/file_ops.md +0 -17
  198. package/src/tools/get_current_time.md +0 -8
  199. package/src/tools/git-checkpoint.mjs +0 -143
  200. package/src/tools/git-ext.mjs +0 -173
  201. package/src/tools/git.md +0 -54
  202. package/src/tools/git.mjs +0 -356
  203. package/src/tools/glob-dialect.mjs +0 -130
  204. package/src/tools/glob.md +0 -11
  205. package/src/tools/grep.md +0 -19
  206. package/src/tools/hashline_edit.md +0 -14
  207. package/src/tools/index.mjs +0 -36
  208. package/src/tools/insert_after.md +0 -15
  209. package/src/tools/lint.md +0 -10
  210. package/src/tools/linter.mjs +0 -128
  211. package/src/tools/ls.md +0 -12
  212. package/src/tools/lsp.md +0 -10
  213. package/src/tools/lsp.mjs +0 -316
  214. package/src/tools/ops.mjs +0 -299
  215. package/src/tools/patch.mjs +0 -282
  216. package/src/tools/process.md +0 -10
  217. package/src/tools/question.md +0 -16
  218. package/src/tools/question.mjs +0 -26
  219. package/src/tools/read.md +0 -20
  220. package/src/tools/read_image.md +0 -8
  221. package/src/tools/repomap.mjs +0 -314
  222. package/src/tools/search.mjs +0 -236
  223. package/src/tools/shared.mjs +0 -446
  224. package/src/tools/tree.md +0 -14
  225. package/src/tools/tree.mjs +0 -66
  226. package/src/tools/wait_for.md +0 -22
  227. package/src/tools/web.mjs +0 -224
  228. package/src/tools/websearch.md +0 -16
  229. package/src/tools/write.md +0 -11
  230. package/src/traces/trace-store.mjs +0 -224
@@ -1,174 +0,0 @@
1
- /**
2
- * advisor/compaction.mjs — advisor review support (split out of advisor/run.mjs,
3
- * 第 11 批 — run.mjs was 498/500 硬帽): context trimming + the review's resource
4
- * limits + the terminal-state guards + the review-text assembler.
5
- *
6
- * estimateTokens / compactMessages moved VERBATIM (the only edit is the `pinned`
7
- * re-attach — F13/§14.4 #3); renderTimeline moved verbatim too, so the tail
8
- * GENERATOR and the tail CLASSIFIER stay in one file with the assembler they
9
- * feed (§14.3 谓词 ↔ §14.6 结构化尾——同族单源)。拆分线 = 行数硬帽实测(见批次档 §5)。
10
- */
11
-
12
- import { providerSpec } from "../config.mjs" // 第 25 批:预算派生(与 loop.mjs:11 同源导入)
13
- // B4(群 B 批,CLI §18.3——F32):CJK 加权单源(provider/rate.mjs 叶子向无环)
14
- import { estimateText } from "../provider/rate.mjs"
15
-
16
- export const MAX_ADVISOR_TURNS = 100
17
- // NOTE: prompts/advisor-round{1,2,3}.md encourage the model to finish within
18
- // ~30 tool turns — a prompt-level efficiency target, DISTINCT from the
19
- // 100-turn mechanical hard cap (MAX_ADVISOR_TURNS above; pure runaway-loop
20
- // guard). They serve different purposes; do NOT synchronize them.
21
-
22
- // Context window limits
23
- // 上下文预算(第 25 批——120K 硬编码退场):预算跟随评审模型窗口(providerSpec:
24
- // 模型规格表 × provider 级 context 覆盖)。头寸用途 = chars/4 估算误差 + 响应/协议开销
25
- // (内存不构成约束——设计 §16.4);判死线仍是宿主机自限线,服务端窗口约束不变。
26
- export const CONTEXT_LIMIT_RATIO = 0.8 // 判死线 = 窗口 × 0.8
27
- const COMPACT_TRIGGER_RATIO = 0.8 // 压缩触发 = 判死线 × 0.8(既有关系零改)
28
-
29
- /** 评审上下文预算(纯函数——两档阈值可机测;provider 为 null 时退化默认规格)。 */
30
- export function advisorContextBudget(provider) {
31
- const limit = Math.floor(providerSpec(provider).context * CONTEXT_LIMIT_RATIO)
32
- return { limit, compactAt: Math.floor(limit * COMPACT_TRIGGER_RATIO) }
33
- }
34
-
35
- export const TOOL_TIMEOUT_MS = 30_000 // single tool timeout
36
- export const REVIEW_TIMEOUT_MS = 600_000 // whole review timeout (10 minutes)
37
- export const MAX_RESULT_CHARS = 64 * 1024 // tool result truncation (line-aware; 64K, aligned with main offload limit)
38
- const MAX_KEY_FILES_IN_COMPACTION = 5 // files named in the compaction summary
39
-
40
- /** Estimate token count from messages(B4——群 B 批 CLI §18.3:扁平 chars/4 改 `estimateText`
41
- * 加权式——ASCII/4 + 非 ASCII/1;纯 ASCII 与旧式逐值相等;CJK 低估 ~3-4× 修正;
42
- * walker(content / tool_calls 两源)与计数口径零改)。 */
43
- export function estimateTokens(messages) {
44
- return messages.reduce((sum, msg) => {
45
- const content = typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content || "")
46
- const toolCalls = msg.tool_calls ? JSON.stringify(msg.tool_calls) : ""
47
- return sum + estimateText(content + toolCalls)
48
- }, 0)
49
- }
50
-
51
- /** Compact early messages when context grows too large — LOCAL trimming only
52
- * (no LLM summarization). MUTATES in place (splice) so the caller's array
53
- * reference stays valid — a reassignment would leave the caller's logging
54
- * (tool-call count, token estimate) reading a stale array. */
55
- export function compactMessages(messages, pinned = null) {
56
- // Keep: system prompt, last 20 messages (≈ 10 assistant+tool exchanges),
57
- // user message — the rest is summarized.
58
- if (messages.length <= 20) return
59
-
60
- const system = messages[0]
61
- const recent = messages.slice(-20)
62
- const old = messages.slice(1, -20)
63
-
64
- // Count actual tool messages (old.length counts user/assistant rows too)
65
- const toolCount = old.filter((m) => m.role === "tool").length
66
- const keyFiles = old
67
- .filter((m) => m.role === "tool")
68
- .map((m) => m.content?.split("\n")[0]?.slice(0, 50)) // first line of tool results typically names the file that was read/grepped
69
- .filter(Boolean)
70
- .slice(0, MAX_KEY_FILES_IN_COMPACTION)
71
- const filesPart = keyFiles.length > 0 ? ` Key files examined: ${keyFiles.join(", ")}` : ""
72
- const summary = `Earlier exploration: ${toolCount} tool calls completed.${filesPart}`
73
-
74
- // F13(第 11 批 §14.4 #3):压缩丢掉的正是**首条 user 消息**(评审简报,含 token)——
75
- // pinned 由评审参数构建(非模型输出),在本次压缩动作内作为一条 user 消息重挂(幂等可读:
76
- // 重复压缩允许重复挂回,不做存在性判定)。
77
- const pin = pinned ? [{ role: "user", content: pinned }] : []
78
- messages.splice(0, messages.length,
79
- system,
80
- { role: "user", content: `[Context compacted] ${summary}` },
81
- ...pin,
82
- ...recent)
83
- }
84
-
85
- // ─────────────────────────────────────────────────────────────────────────────
86
- // 不完整判定族(A / F16 共用单谓词——§14.3;六 kind = 宿主尾族)
87
- // ─────────────────────────────────────────────────────────────────────────────
88
-
89
- /** 宿主尾族六 kind 的块首行逐字前缀(§14.3 表)。变量段(token 数 / 秒数 / 工具轮数)
90
- * 不入前缀——取各尾的固定字面部分;`review_failed` = run.mjs catch 的字符串 resolve
91
- * 形态(不 throw),其余五条 = renderTimeline 尾(loop.mjs)。 */
92
- const ADVISOR_INCOMPLETE_PREFIXES = [
93
- ["context_limit", "Advisor: context window limit"],
94
- ["turn_cap", "Advisor: stopped after"],
95
- ["timeout", "Advisor: review timeout"],
96
- ["empty", "Advisor: empty response"],
97
- ["interrupted", "Advisor: interrupted."],
98
- ["review_failed", "Advisor: review failed"],
99
- ]
100
-
101
- /** 单谓词(三消费点同源:design 结算 / code 完成守卫 / 报告提示)——**块首行扫描**(按空行
102
- * 分块,逐块取首行 trim 后测前缀;时间线与尾以空行相接,六条尾均以块首行形态落地)。
103
- * 负向精度(§14.3 修正轮):引文中同串的**非块首形态**(围栏内行 / 表格行 / 引用行)不判
104
- * incomplete;块首裸行引用同串的残余误报方向安全(fail-closed——多付一轮重跑,如实登记)。
105
- * @returns {string|null} kind 或 null */
106
- export function advisorIncompleteMarker(text) {
107
- for (const block of String(text ?? "").split(/\n\s*\n/)) {
108
- const first = block.split("\n").find((l) => l.trim() !== "")
109
- if (!first) continue
110
- const line = first.trim()
111
- for (const [kind, prefix] of ADVISOR_INCOMPLETE_PREFIXES) {
112
- if (line.startsWith(prefix)) return kind
113
- }
114
- }
115
- return null
116
- }
117
-
118
- // ─────────────────────────────────────────────────────────────────────────────
119
- // 预算提示 + 结构化超时尾(D / F15——§14.6 #2/#3)
120
- // ─────────────────────────────────────────────────────────────────────────────
121
-
122
- /** 0.75 一次性预算提示判定(纯函数——阈值两侧可机测;每场评审至多一次)。 */
123
- export function shouldBudgetNudge(elapsedMs, budgetMs, nudged) {
124
- return !nudged && Number.isFinite(budgetMs) && budgetMs > 0 && elapsedMs >= budgetMs * 0.75
125
- }
126
-
127
- /** 预算提示文案(逐字——§14.6 #2;由循环注入一条 user 消息)。 */
128
- export function budgetNudgeText(elapsedMs, budgetMs) {
129
- const secs = (ms) => Math.round(ms / 100) / 10
130
- const pct = Math.round((elapsedMs / budgetMs) * 100)
131
- return `⏳ review budget: ~${pct}% consumed (${secs(elapsedMs)}s of ${secs(budgetMs)}s). Converge now: emit your findings table for the evidence you have verified, mark anything you could not verify explicitly as \`unverified\` (unverified evidence must not support a pass), and emit your verdict line.`
132
- }
133
-
134
- /** 结构化超时尾(§14.6 #3):族前缀 `Advisor: review timeout after {S}s.` 逐字保持
135
- * (判定族字面依赖);其后 = 机读统计(rounds / tool calls / review text produced)
136
- * + 可执行恢复指引(narrower scope / 调预算)。 */
137
- export function timeoutTail(timeoutMs, rounds, toolCalls, producedText) {
138
- const s = Math.round(timeoutMs / 1000)
139
- return [
140
- `Advisor: review timeout after ${s}s. Review incomplete — the wall-clock budget was exhausted; partial findings (if any) are above.`,
141
- `- rounds: ${rounds} · tool calls: ${toolCalls} · review text produced: ${producedText ? "yes" : "no"}`,
142
- `- budget: ${s}s (agent.advisor.timeoutMs) — re-run with a narrower scope (split the review across fewer documents) or raise the budget.`,
143
- ].join("\n")
144
- }
145
-
146
- // ─────────────────────────────────────────────────────────────────────────────
147
- // 评审文本装配(loop 的尾经此与时间线合流——与尾族同文件:生成 / 判定 / 装配单源)
148
- // ─────────────────────────────────────────────────────────────────────────────
149
-
150
- // The live "[thinking…]" wait indicator shares its exact text with the TUI
151
- // cleanup regex (agent-turn.mjs strips it before flushing to history) — keep
152
- // them in lockstep.
153
- export const ADVISOR_THINKING_PLACEHOLDER = "\n[thinking…]\n"
154
-
155
- /**
156
- * Tool-call progress line summary delegates to the single source describeToolArgs
157
- * (../tui/tool-args.mjs) — the same function main-agent tool blocks and subagent
158
- * blocks use. 2026-08-31: replaced the local picker (action/path/pattern/command-only)
159
- * so advisor progress lines show the quoted-path forms everywhere else.
160
- */
161
- /**
162
- * Render the ordered review timeline — thinking / tool progress / final text
163
- * interleaved EXACTLY as emitted, so the persisted record shows the review
164
- * process at its real positions. A summary appended at the end would lose the
165
- * order (the user-visible "no tool calls in the advisor record" gap). The
166
- * live "[thinking…]" placeholder is stripped (wait indicator, not content).
167
- */
168
- export function renderTimeline(timeline, tail = "") {
169
- const body = timeline
170
- .map((b) => b.text.replaceAll(ADVISOR_THINKING_PLACEHOLDER, "").trim())
171
- .filter(Boolean)
172
- .join("\n\n")
173
- return [body, tail].filter(Boolean).join("\n\n")
174
- }
@@ -1,80 +0,0 @@
1
- /**
2
- * advisor/convergence.mjs — shared convergence-round message building (round 2+).
3
- * SINGLE source for the round-2+ sections used by BOTH the normal flow
4
- * (buildAdvisorFollowUp in advisor.mjs) and the legacy path (buildAdvisorUserMessage
5
- * in messages.mjs) — fixes must not be replicated in two places. Lives in its
6
- * own module to avoid the messages.mjs ↔ advisor.mjs import cycle.
7
- */
8
-
9
- /**
10
- * Shared convergence-round instructions — single source for BOTH paths
11
- * (buildAdvisorUserMessage's legacy convergence block and
12
- * buildAdvisorFollowUp), so the wording cannot diverge.
13
- * Round 2 may flag obvious new issues; round 3+ is strict verification.
14
- * @param {number} round — convergence round number (2+)
15
- * @param {string[]|null} scopeFiles — optional file list for the no-response fallback
16
- * @returns {string[]} the numbered instruction lines (callers spread them)
17
- */
18
- export function buildConvergenceInstructions(round, scopeFiles = null) {
19
- const fileList = scopeFiles?.length
20
- ? ` The review surface is: ${scopeFiles.slice(0, 10).join(", ")}.`
21
- : ""
22
- return [
23
- `1. IMPORTANT: verify EVERY item of the prior review output against the CURRENT FILE STATE with \`read\` — never decide based on earlier snapshots alone.${fileList}`,
24
- "2. STALE-CONTEXT WARNING: any diff or file content from earlier messages is a historical snapshot — treat it as expired. Only fresh `read` results describe the current state.",
25
- "3. You have no git tool; git output in earlier messages is historical and untrustworthy (committed fixes never show in a diff).",
26
- "4. `read` the files named in the prior review output (or the review surface above) in full — ALWAYS. Batch reads/greps in a single reply.",
27
- "5. Evidence rule: every 'Unfixed'/'New' finding MUST quote the exact line content from THIS round's `read` output (e.g. `run.mjs:180: timeoutId = setTimeout(...)`). Line numbers alone are NOT evidence — they may be stale or fabricated. Findings without a fresh quoted line are treated as unverified and will not be accepted.",
28
- "6. Produce your verification table. Do not re-read content you already have.",
29
- round === 2
30
- ? "7. You may flag obvious NEW issues introduced by the fixes (crashes, data loss, logic errors — not style)."
31
- : "7. Do NOT look for new issues.",
32
- ]
33
- }
34
-
35
- /**
36
- * Shared convergence body — SINGLE source for the round-2+ message sections
37
- * (decision 2026-08-08): the FULL verbatim prior review output is the only
38
- * complete verification list; the agent response table is a focus aid only.
39
- * Used by buildAdvisorFollowUp (the normal flow) and the legacy path in
40
- * messages.mjs (direct external callers of buildAdvisorUserMessage) — fixes
41
- * must not be replicated in two places.
42
- * @param {string} p — full prior review output (verbatim)
43
- * @param {string} response — agent fix-claims table (or fallback text)
44
- * @param {number} round — next round number (>= 2)
45
- * @param {string[]|null} [scopeFiles] — review surface for instructions
46
- * @returns {string} the convergence message
47
- */
48
- export function buildConvergenceBody(p, response, round, scopeFiles) {
49
- const label = round === 2 ? "Verify Prior Table + Flag New Issues" : "Strict Verification"
50
- const reminder = round === 2
51
- ? "verify every item in the prior review output and flag only obvious new issues introduced by the fixes"
52
- : "strictly verify only the prior review output — do NOT look for new issues"
53
- const parts = [
54
- `## Round ${round} — ${label}`,
55
- "",
56
- `[System reminder: this is round ${round} of the convergence protocol. ` +
57
- `The system prompt for this round has already narrowed the review scope — follow it: ${reminder}.]`,
58
- "",
59
- // Prior review output IS in the context (decision 2026-08-08): the FULL
60
- // verbatim output of the last review — the only complete verification list.
61
- // The agent response table covers only issues the agent chose to answer,
62
- // so issues the agent skipped would silently escape convergence without
63
- // the prior output. The model understands the review output directly —
64
- // no table/header/phrase parsing. Restatement risk is handled
65
- // mechanically: host-verified citations reject references that do not
66
- // match the CURRENT disk state, and fresh sessions exclude old read data.
67
- // The agent response table stays as a focus aid ("I fixed X"), not as the
68
- // to-verify list.
69
- "## Prior Review Output (verify every item it raises)",
70
- p,
71
- "",
72
- "## Agent Response (fix claims — reference only)",
73
- response,
74
- "",
75
- "## Instructions",
76
- ...buildConvergenceInstructions(round, scopeFiles),
77
- "",
78
- ]
79
- return parts.join("\n")
80
- }
@@ -1,77 +0,0 @@
1
- /**
2
- * advisor/history.mjs — advisor history extraction: agent response table and conversation background.
3
- */
4
- import { readFileSync } from "node:fs"
5
- import { join } from "node:path"
6
-
7
- export const ADVISOR_MD_PATH = ".thincoder/advisor.md"
8
- const AGENT_RESPONSE_HEADER = "| # | Action | Detail |"
9
-
10
- const DEFAULT_CRITERIA = `Review the code changes, focusing on:
11
- 1. Correctness: logic errors, edge cases, off-by-one, incomplete modifications
12
- 2. Security: unhandled exceptions, null references, resource leaks, race conditions
13
- 3. Consistency: alignment with existing project patterns and conventions
14
- 4. Completeness: missing callers, imports, or follow-up changes
15
- 5. Maintainability: vague naming, missing comments, overly complex logic`
16
-
17
- /**
18
- * Extract the agent's response table (| # | Action | Detail |) — the fix-claims
19
- * reference for convergence rounds.
20
- * Semantics (decision 2026-08-08): without sinceIdx, scan BACKWARD for the
21
- * MOST RECENT response table (no prior-table index is carried anymore — the
22
- * agent response is a focus aid only; format drift falls back to the
23
- * no-response text and never drives control flow). With sinceIdx, scan
24
- * FORWARD from it (legacy callers/tests).
25
- * @param {Array} history — message history
26
- * @param {number} [sinceIdx] — legacy: start scanning forward from this index
27
- * @returns {string|null} the response table content, or null
28
- */
29
- export function extractAgentResponseTable(history, sinceIdx) {
30
- const entries = Array.isArray(history) ? history : []
31
- if (sinceIdx !== undefined) {
32
- for (let i = sinceIdx; i < entries.length; i++) {
33
- const m = entries[i]
34
- if (m.role !== "assistant" || typeof m.content !== "string") continue
35
- if (m.content.includes(AGENT_RESPONSE_HEADER)) return m.content
36
- }
37
- return null
38
- }
39
- for (let i = entries.length - 1; i >= 0; i--) {
40
- const m = entries[i]
41
- if (m.role !== "assistant" || typeof m.content !== "string") continue
42
- if (m.content.includes(AGENT_RESPONSE_HEADER)) return m.content
43
- }
44
- return null
45
- }
46
-
47
- /**
48
- * Load review criteria: project .thincoder/advisor.md if present,
49
- * otherwise the built-in defaults.
50
- */
51
- export function loadAdvisorMd(cwd) {
52
- try {
53
- return readFileSync(join(cwd, ADVISOR_MD_PATH), "utf8")
54
- } catch {
55
- return DEFAULT_CRITERIA
56
- }
57
- }
58
-
59
- /** Extract recent user↔assistant exchanges (up to maxTurns) for intent context. */
60
- export function extractConversationBackground(history, maxTurns = 3) {
61
- const entries = Array.isArray(history) ? history : []
62
- const lines = []
63
- let turns = 0
64
- for (let i = entries.length - 1; i >= 0 && turns < maxTurns; i--) {
65
- const m = entries[i]
66
- if (m.role === "tool" || m.role === "system") continue
67
- if (typeof m.content !== "string") continue
68
- if (m.content.startsWith("[System reminder:") || m.content.startsWith("[System mode:") || m.content.startsWith("[Relevant memories")) continue
69
- // ^ [System mode:] is not currently generated anywhere — kept as forward-looking
70
- // defensive filtering in case convergence messages ever adopt a different prefix.
71
- if (m.role === "user" || m.role === "assistant") {
72
- lines.unshift(`${m.role === "user" ? "User" : "Assistant"}: ${m.content.slice(0, 400)}`)
73
- if (m.role === "user") turns++
74
- }
75
- }
76
- return lines.length > 0 ? lines.join("\n\n") : null
77
- }
@@ -1,293 +0,0 @@
1
- /**
2
- * advisor/loop.mjs — advisor tool loop: chat → execute tools → repeat, plus the
3
- * review timeline (split out of advisor/run.mjs, 第 11 批 — run.mjs was 498/500
4
- * 硬帽;拆分保持既有 import 面:run.mjs 继续 re-export 本文件导出)。
5
- *
6
- * 第 11 批(F15/§14.6):每次 chat 调用携带硬墙信号(`AbortSignal.any([signal,
7
- * AbortSignal.timeout(remaining)])`;墙判定绑信号状态——抛错 / partial 两形态同判),
8
- * 并按 0.75 一次性预算提示 + 结构化超时尾收尾;守卫与限额函数在 compaction.mjs。
9
- */
10
- import { chat } from "../provider/core.mjs"
11
- import { providerSpec } from "../config.mjs"
12
- import { toOpenAISchema } from "../tools/index.mjs"
13
- import { describeToolArgs } from "../tui/tool-args.mjs"
14
- import { truncateAdvisorResult } from "./truncate.mjs"
15
- import { batchSegmentTool } from "../agent-tools/batch-segment.mjs"
16
- import {
17
- estimateTokens, compactMessages, shouldBudgetNudge, budgetNudgeText, timeoutTail, renderTimeline,
18
- MAX_ADVISOR_TURNS, advisorContextBudget, TOOL_TIMEOUT_MS, REVIEW_TIMEOUT_MS, MAX_RESULT_CHARS,
19
- ADVISOR_THINKING_PLACEHOLDER,
20
- } from "./compaction.mjs"
21
-
22
- const { readTool, globTool, grepTool, lsTool } = await import("../tools/index.mjs")
23
- const { lspTool } = await import("../tools/lsp.mjs")
24
- const { codeSearchTool } = await import("../memory/code-sync.mjs")
25
-
26
- /**
27
- * Advisor tool set — ZERO git, read-only ONLY, every round. The change surface
28
- * comes from the review scope (paths / _touchedFiles injected by the caller),
29
- * never from git: git output misled reviews (committed fixes never show in
30
- * `git diff HEAD`, so "no changes" was read as "not fixed") and the user
31
- * mandate is full decoupling (7d49a52 + d3be613). The reviewer reads files
32
- * and searches code; it never touches git and never writes.
33
- * No round parameter — the set is constant across all rounds.
34
- * @param {Object} agent — only used for the code index (agent.memory); the
35
- * semantic code_search tool needs it. Without a memory, the set is 5 tools.
36
- */
37
- function advisorToolsFor(agent, reviewType = "code", batchDoc = null) {
38
- const search = agent?.memory ? codeSearchTool(agent.memory) : null
39
- const tools = search
40
- ? [readTool, globTool, grepTool, lsTool, lspTool, search]
41
- : [readTool, globTool, grepTool, lsTool, lspTool]
42
- // §2.20.3(第 4 批):**只有绑定了批次档的设计评审**额外拿到写通道——代码评审工具集
43
- // 逐字节不变(零 git + 只读不变量,§2.20.8 #1);未绑定 → 不挂载(fail-closed)。
44
- if (reviewType === "design" && batchDoc) tools.push(batchSegmentTool(batchDoc, { review: true }))
45
- return { schemas: tools.map(toOpenAISchema), byName: new Map(tools.map((t) => [t.name, t])) }
46
- }
47
- // Test seam: the tool set is pure (agent.memory → code_search inclusion).
48
- export { advisorToolsFor, advisorToolsFor as _advisorToolsFor }
49
-
50
- /**
51
- * Run the advisor's tool loop: chat → execute tools → repeat.
52
- * Stops when the model produces text without tool calls.
53
- *
54
- * Progress lines (→ tool args) are emitted via onOutput between model bursts so
55
- * the panel keeps moving while the advisor explores — otherwise the panel sits
56
- * frozen through every tool-call phase and the review appears to have stalled.
57
- *
58
- * @param {string|null} [pinned] — 第 11 批:压缩定锚简报(评审参数构建——F13/§14.4 #3)。
59
- * @param {{now?: Function, chat?: Function}} [seams] — 测试缝(默认 Date.now / chat——
60
- * 生产调用不传,默认回退零行为变)。
61
- */
62
- async function runAdvisorToolLoop(provider, messages, onOutput, signal, agent, cwd, toolsOverride = null, reviewType = "code", batchDoc = null, pinned = null, seams = {}) {
63
- const now = seams.now ?? Date.now
64
- const chatCall = seams.chat ?? chat
65
- // 第 11 批硬墙 / 预算 / 尾:实现注解见下方各点;守卫函数与 renderTimeline 在 compaction.mjs。
66
- // Kind-tagged wrappers: the TUI panel colors reasoning / answer / tool progress differently.
67
- // Every chunk is ALSO recorded into an ordered timeline — the persisted record
68
- // must show the review process (thinking ↔ tool progress ↔ final text) at its
69
- // real positions, not a summary appended at the end. Same-kind consecutive
70
- // chunks merge (token streams); kind flips start a new entry.
71
- const timeline = []
72
- const record = (kind, text) => {
73
- const last = timeline.at(-1)
74
- if (last && last.kind === kind) last.text += text
75
- else timeline.push({ kind, text })
76
- }
77
- const emit = (kind) => (text) => { record(kind, text); onOutput?.({ kind, text }) }
78
- const onThink = emit("think")
79
- const onText = emit("text")
80
- const onTool = emit("tool")
81
- // toolsOverride = test seam (T-TS8/9): the real advisor tool set, or a mock
82
- // set with controllable timing/errors.
83
- const { schemas: toolSchemas, byName: toolByName } = toolsOverride ?? advisorToolsFor(agent, reviewType, batchDoc)
84
- let turns = 0
85
- let toolCallCount = 0
86
- let reviewTextProduced = false
87
- let budgetNudged = false
88
- const startTime = now()
89
- // 第 25 批(§16.3):上下文预算跟随评审模型窗口——`providerSpec`(模型规格表 × provider 级
90
- // context 覆盖)派生;函数体内、while 轮次外一次性(provider 全场不变),两档消费见下守卫。
91
- const budget = advisorContextBudget(provider)
92
-
93
- while (true) {
94
- // Interrupted (Ctrl+I) — stop immediately instead of spinning a fresh uncancellable signal
95
- if (signal?.aborted) return renderTimeline(timeline, "Advisor: interrupted.")
96
-
97
- // Check review timeout (10 minutes by default; agent.advisor.timeoutMs overrides)
98
- // 运行时校验(设计评审 #1,2026-08-24):手写 config.json 的非法值(0/负数/字符串)
99
- // 不得静默禁用或立即触发超时——非法一律回退默认。
100
- const cfg = agent.config?.advisor?.timeoutMs
101
- const timeoutMs = (Number.isFinite(cfg) && cfg > 0) ? cfg : REVIEW_TIMEOUT_MS
102
- const elapsed = now() - startTime
103
- const remaining = timeoutMs - elapsed
104
- // 硬墙(§14.6 #1):预算用尽 → 结构化超时尾(首行 = 判定族 timeout 前缀)。
105
- if (remaining <= 0) {
106
- return renderTimeline(timeline, timeoutTail(timeoutMs, turns, toolCallCount, reviewTextProduced))
107
- }
108
- // 0.75 一次性预算提示(§14.6 #2——同一检查点、每场评审至多一次):注入一条 user 消息
109
- // 促模型在墙前收敛产出(不改语义判据、不碰提示词面)。
110
- if (shouldBudgetNudge(elapsed, timeoutMs, budgetNudged)) {
111
- budgetNudged = true
112
- messages.push({ role: "user", content: budgetNudgeText(elapsed, timeoutMs) })
113
- }
114
-
115
- if (++turns > MAX_ADVISOR_TURNS) {
116
- return renderTimeline(timeline, "Advisor: stopped after " + MAX_ADVISOR_TURNS + " tool rounds — the review appears to be looping. You may retry with a narrower scope.")
117
- }
118
-
119
- // Check context window and compact if needed
120
- const currentTokens = estimateTokens(messages)
121
- if (currentTokens > budget.compactAt) {
122
- onText(`\n[Context compacted: ${currentTokens} tokens → reducing to fit window]\n`)
123
- compactMessages(messages, pinned)
124
- if (estimateTokens(messages) > budget.limit) {
125
- // Report the POST-compaction count — the pre-compaction currentTokens
126
- // is stale by the time compaction has run.
127
- return renderTimeline(timeline, `Advisor: context window limit reached (${estimateTokens(messages)} tokens). Review incomplete — too many tool calls. Try a narrower scope.`)
128
- }
129
- }
130
-
131
- // LLM generation silence: the reasoning phase produces no SSE bytes for
132
- // seconds to tens of seconds (server-side prefill on large contexts, per
133
- // tool-round LLM return). A placeholder keeps the panel visibly working.
134
- // kind "think" (NOT "text"): the placeholder must land in the SAME buffer
135
- // and position as the upcoming reasoning — a "text"-kind placeholder
136
- // rendered BELOW the think block, and the reasoning stream appeared ABOVE
137
- // it ("the stream runs back to the front"). Same buffer = same spot; the
138
- // reasoning continues right where the placeholder sits.
139
- onOutput?.({ kind: "think", text: ADVISOR_THINKING_PLACEHOLDER })
140
-
141
- // 硬墙(§14.6 #1):单次请求信号 = 用户信号 × 本调用 deadline(remaining)。复合信号
142
- // 无条件传入(上层检查与本调用之间的中止仍必须取消请求——已 aborted 的 composite 使请求
143
- // 立即失败);此处改正了原指向 provider/core.mjs 组合 AbortSignal 的陈旧注释(§14.10 #3)。
144
- const callSignal = signal
145
- ? AbortSignal.any([signal, AbortSignal.timeout(remaining)])
146
- : AbortSignal.timeout(remaining)
147
- let response
148
- try {
149
- response = await chatCall(provider, {
150
- messages,
151
- tools: toolSchemas,
152
- signal: callSignal,
153
- onToken: (t) => { if (String(t ?? "").trim()) reviewTextProduced = true; onText(t) },
154
- onReasoning: onThink,
155
- // LOGGING(vscode advisor/run.mjs parity——按 stage 可 grep)
156
- // §18.6 D-TR4:轨迹元数据增补——kind=advisor(评审独立于子代理——T-TR2);role
157
- // 透出调用方角色(eng-coder 内嵌评审时为 "eng-coder");session/cwd 供轨迹对回;
158
- // traces 开关沿 agent.config(D-TR6)。
159
- logCtx: {
160
- stage: "advisor",
161
- role: agent?._role ?? null,
162
- kind: "advisor",
163
- session: agent?._sessionStart ?? null,
164
- cwd,
165
- traces: agent?.config?.traces?.enabled !== false,
166
- },
167
- })
168
- } catch (e) {
169
- // 墙判定绑信号状态(§14.6 #1——非异常名):① 用户信号已中止 ⇒ 原样上抛(中断语义
170
- // 零变);② 复合信号已中止(墙触发)而用户信号未中止 ⇒ 结构化超时尾(形态①:抛错;
171
- // AbortError / TimeoutError 两名兜底——AbortSignal.timeout 的 reason 是 TimeoutError
172
- // DOMException);③ 其余错误原样上抛(runAdvisorReview 的失败分类不变)。
173
- if (signal?.aborted) throw e
174
- if (callSignal.aborted || e?.name === "AbortError" || e?.name === "TimeoutError") {
175
- return renderTimeline(timeline, timeoutTail(timeoutMs, turns, toolCallCount, reviewTextProduced))
176
- }
177
- throw e
178
- }
179
- if (signal?.aborted) return renderTimeline(timeline, "Advisor: interrupted.")
180
- // 形态②(§14.6 #1):不抛错而返回 partial(流已有内容时中断以 partial:true 透传)——
181
- // 不得按普通结果收尾:墙触发(复合信号已中止)同判。
182
- if (callSignal.aborted && response?.partial) {
183
- return renderTimeline(timeline, timeoutTail(timeoutMs, turns, toolCallCount, reviewTextProduced))
184
- }
185
-
186
- // No tool calls — this is the final review text. The final answer was
187
- // already streamed into the timeline via onText; fall back to
188
- // response.content only if nothing was recorded.
189
- if (!response.toolCalls?.length) {
190
- if (!response.content?.trim()) return renderTimeline(timeline) || "Advisor: empty response — review was inconclusive"
191
- return renderTimeline(timeline) || response.content.trim()
192
- }
193
-
194
- // Push assistant message with tool calls. reasoning_content ECHO is
195
- // mandatory for reasoningEcho:"required" providers (deepseek/kimi): the
196
- // server stops returning reasoning_content on later rounds when the
197
- // tool-call assistant history lacks it — the observed "reasoning stops
198
- // after the first tool call, returns only at the final answer" symptom.
199
- // Mirrors the main agent's push (agent.mjs).
200
- messages.push({
201
- role: "assistant",
202
- content: response.content || null,
203
- tool_calls: response.toolCalls.map((tc) => ({
204
- id: tc.id, type: "function",
205
- function: { name: tc.name, arguments: tc.arguments },
206
- })),
207
- ...(response.reasoning && providerSpec(provider).reasoningEcho === "required"
208
- ? { reasoning_content: response.reasoning }
209
- : {}),
210
- })
211
-
212
- // B1 (AGENT-LOOP.md §18.7 D-TS7): the SAME LLM reply's multiple read-only
213
- // tool calls run in PARALLEL (Promise.all) — results are backfilled in
214
- // toolCalls order (Promise.all preserves the input order → tool_call_id
215
- // never mismatches); each tool's timeout/error is captured independently
216
- // (the existing TOOL_TIMEOUT stays — one failing tool does not block the
217
- // others); progress lines are emitted in toolCalls order. The read-only
218
- // tool set has no side effects — no sequencing/serialization needed.
219
- // Scope note (round1 review #10): B1 is ONLY in-loop tool parallelism — it
220
- // does NOT solve the TODO "platform execution: advisor parallel calls are
221
- // actually serial" mystery (docs/TODO.md — LOGGING evidence item), which
222
- // concerns multiple advisor CALLS observed as serial, not one reply's
223
- // tool calls.
224
- const parsed = response.toolCalls.map((tc) => {
225
- const tool = toolByName.get(tc.name)
226
- let args = {}
227
- let parseError = null
228
- try {
229
- args = JSON.parse(tc.arguments || "{}")
230
- } catch (e) {
231
- parseError = `Error: invalid JSON in tool arguments: ${e.message}\nRaw arguments: ${(tc.arguments || "").slice(0, 200)}`
232
- }
233
- return { tc, tool, args, parseError }
234
- })
235
- toolCallCount += parsed.length
236
- // Progress lines first, in toolCalls order (emitted before the parallel
237
- // run — display order is independent of completion order).
238
- for (const p of parsed) {
239
- if (p.parseError) continue // parse-error tools get no progress line (legacy behavior)
240
- const argsLine = describeToolArgs(p.tc.name, p.args)
241
- onTool(`\n→ ${p.tc.name}${argsLine ? " " + argsLine : ""}\n`)
242
- }
243
- // Every tool runs CONCURRENTLY; each result/error lands in its own slot —
244
- // Promise.all preserves input order, so index i always matches parsed[i].
245
- const executed = await Promise.all(parsed.map(async (p) => {
246
- // Parse failure → error to model immediately (no execution)
247
- if (p.parseError) return p.parseError
248
- if (!p.tool) return `Error: unknown tool "${p.tc.name}". Available: ${[...toolByName.keys()].join(", ")}`
249
- // Execute with timeout (clear the timer when the tool wins the race —
250
- // otherwise up to MAX_ADVISOR_TURNS dangling timers accumulate)
251
- try {
252
- let timeoutId
253
- const timeoutPromise = new Promise((_, reject) => {
254
- timeoutId = setTimeout(() => reject(new Error(`tool timeout after ${TOOL_TIMEOUT_MS}ms`)), TOOL_TIMEOUT_MS)
255
- })
256
- let toolPromise
257
- try {
258
- toolPromise = p.tool.execute(p.args, { cwd, agent, onOutput, signal })
259
- return await Promise.race([toolPromise, timeoutPromise])
260
- } finally {
261
- clearTimeout(timeoutId)
262
- // Timeout won → toolPromise is still pending; a later rejection
263
- // would surface as an unhandled rejection. The race already
264
- // consumed the result/error in the normal path, so this no-op
265
- // catch only fires for the abandoned-tool case.
266
- toolPromise?.catch(() => {})
267
- }
268
- } catch (e) {
269
- const errorType = e.message.includes("timeout") ? "timeout"
270
- : e.message.includes("ENOENT") ? "file_not_found"
271
- : e.message.includes("permission") ? "permission_denied"
272
- : "execution_error"
273
- return `Error (${errorType}): ${e.message}`
274
- }
275
- }))
276
-
277
- // Backfill in toolCalls order (executed[i] ↔ parsed[i]); per-result
278
- // non-string serialization + dual-end line-aware truncation stay per-tool
279
- // (DUAL-END-TRUNCATION F-2 — truncate.mjs: head ≈60% + tail ≈40% — keep the
280
- // tail verdicts; ≤ MAX_RESULT_CHARS results pass through untouched).
281
- for (let i = 0; i < parsed.length; i++) {
282
- let result = executed[i]
283
- if (typeof result !== "string") result = JSON.stringify(result)
284
-
285
- result = truncateAdvisorResult(result, MAX_RESULT_CHARS)
286
-
287
- messages.push({ role: "tool", tool_call_id: parsed[i].tc.id, content: result })
288
- }
289
- }
290
- }
291
- // Test seam (T-TS8/9): the tool loop itself — toolsOverride injects a mock tool
292
- // set with controllable timing/errors (the real set comes from advisorToolsFor).
293
- export { runAdvisorToolLoop, runAdvisorToolLoop as _runAdvisorToolLoop }