mixdog 0.9.170 → 0.9.172

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 (1479) hide show
  1. package/package.json +2 -1
  2. package/scripts/build-ffmpeg-runtime.sh +57 -58
  3. package/scripts/build-runtime-linux.sh +211 -191
  4. package/scripts/build-runtime-macos.sh +94 -76
  5. package/scripts/daemon-stub.mjs +1 -2
  6. package/scripts/fixtures/patch-replay-corpus.json +85 -28
  7. package/scripts/generate-runtime-manifest.mjs +1 -1
  8. package/scripts/graph-parity.mjs +204 -151
  9. package/scripts/lib/embedding-model-bench-core.mjs +5 -9
  10. package/scripts/lib/embedding-model-bench-core.test.mjs +47 -0
  11. package/scripts/lib/parse-since.mjs +22 -0
  12. package/scripts/lib/recall-bench-eval.mjs +4 -12
  13. package/scripts/lib/run-node-tests.mjs +28 -0
  14. package/scripts/lib/test-summary-reporter.mjs +26 -0
  15. package/scripts/llm-trace-summary.mjs +2 -23
  16. package/scripts/local-provider-live-check.mjs +1 -1
  17. package/scripts/media-image-live.mjs +4 -6
  18. package/scripts/mouse-probe.mjs +1 -11
  19. package/scripts/native-binary-arch.mjs +1 -1
  20. package/scripts/office/author-deck.mjs +4 -1
  21. package/scripts/patch-replay.mjs +4 -1
  22. package/scripts/perf/transcript-baseline.mjs +10 -8
  23. package/scripts/pg-memory-diet.mjs +8 -5
  24. package/scripts/prune-embedding-runtime.mjs +1 -20
  25. package/scripts/recall-bench-cases.json +64 -9
  26. package/scripts/recall-event-cases.json +398 -41
  27. package/scripts/recall-history-cases.json +396 -36
  28. package/scripts/recall-quality-cases.json +146 -17
  29. package/scripts/recall-repo-cases.json +188 -24
  30. package/scripts/recall-usecase-cases.json +96 -16
  31. package/scripts/release-timing-report.mjs +4 -1
  32. package/scripts/routing-corpus.mjs +113 -141
  33. package/scripts/run-office-live-tests.mjs +2 -1
  34. package/scripts/session-diag.mjs +2 -21
  35. package/scripts/session-sweep.mjs +4 -4
  36. package/scripts/smoke-runtime-negative.sh +22 -16
  37. package/scripts/test-direct.mjs +5 -0
  38. package/scripts/test.mjs +11 -24
  39. package/scripts/tool-efficiency-diag.mjs +4 -1
  40. package/scripts/tool-failures.mjs +1 -20
  41. package/scripts/tui-frame-harness.mjs +6 -7
  42. package/src/defaults/skills/browser-use/SKILL.md +33 -9
  43. package/src/defaults/skills/code-tidy/SKILL.md +158 -73
  44. package/src/defaults/skills/code-tidy/references/agent-cleanup.md +126 -52
  45. package/src/defaults/skills/code-tidy/references/dead-code.md +61 -19
  46. package/src/defaults/skills/computer-use/SKILL.md +19 -6
  47. package/src/defaults/skills/docx/SKILL.md +2 -0
  48. package/src/defaults/skills/docx/references/native-authoring.md +7 -2
  49. package/src/defaults/skills/goal-management/SKILL.md +10 -3
  50. package/src/defaults/skills/local-provider/SKILL.md +1 -1
  51. package/src/defaults/skills/memory-management/SKILL.md +1 -1
  52. package/src/defaults/skills/pdf/SKILL.md +1 -1
  53. package/src/defaults/skills/pptx/SKILL.md +18 -13
  54. package/src/defaults/skills/pptx/references/charts.md +10 -5
  55. package/src/defaults/skills/pptx/references/direction.md +1 -1
  56. package/src/defaults/skills/pptx/references/kit.md +153 -44
  57. package/src/defaults/skills/pptx/references/pictures.md +10 -1
  58. package/src/defaults/skills/pptx/scripts/qc-pages.mjs +161 -116
  59. package/src/defaults/skills/setup/SKILL.md +1 -1
  60. package/src/defaults/skills/skill-creator/SKILL.md +3 -3
  61. package/src/defaults/skills/skill-creator/references/design.md +3 -3
  62. package/src/defaults/skills/xlsx/SKILL.md +8 -5
  63. package/src/headless-exec.mjs +328 -696
  64. package/src/headless-json-lifecycle.mjs +461 -0
  65. package/src/headless-role.mjs +1 -1
  66. package/src/lib/keychain-cjs.cjs +7 -8
  67. package/src/lib/mixdog-debug.cjs +4 -5
  68. package/src/lib/plugin-paths.cjs +2 -2
  69. package/src/lib/rules-builder.cjs +22 -38
  70. package/src/lib/text-utils.cjs +1 -3
  71. package/src/repl/runtime-handle.mjs +46 -0
  72. package/src/repl/slash-commands.mjs +134 -0
  73. package/src/repl/stream-sink.mjs +129 -0
  74. package/src/repl/turn-output.mjs +51 -0
  75. package/src/repl.mjs +99 -381
  76. package/src/rules/agent/40-cycle1-agent.md +4 -3
  77. package/src/rules/agent/AGENT.md +11 -11
  78. package/src/rules/lead/LEAD.md +14 -12
  79. package/src/rules/shared/05-parallel-calls.md +3 -5
  80. package/src/rules/shared/15-skills.md +4 -0
  81. package/src/rules/shared/45-destructive.md +4 -4
  82. package/src/rules/shared/70-delivery.md +10 -3
  83. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/abort-link.mjs +44 -0
  84. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/ask-args.mjs +128 -0
  85. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/preset.mjs +72 -0
  86. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/session-prep.mjs +114 -0
  87. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/turn.mjs +111 -0
  88. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/watchdog.mjs +80 -0
  89. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch.mjs +112 -606
  90. package/src/runtime/agent/orchestrator/agent-runtime/agent-progress-watchdog.mjs +1 -2
  91. package/src/runtime/agent/orchestrator/agent-runtime/cache-strategy.mjs +61 -49
  92. package/src/runtime/agent/orchestrator/agent-trace-format.mjs +18 -22
  93. package/src/runtime/agent/orchestrator/agent-trace-io.mjs +3 -3
  94. package/src/runtime/agent/orchestrator/agent-trace.mjs +6 -19
  95. package/src/runtime/agent/orchestrator/cache-break-trace.mjs +3 -2
  96. package/src/runtime/agent/orchestrator/cache-mtime.mjs +2 -2
  97. package/src/runtime/agent/orchestrator/config-presets.mjs +1 -1
  98. package/src/runtime/agent/orchestrator/config-storage.mjs +9 -11
  99. package/src/runtime/agent/orchestrator/config.mjs +6 -4
  100. package/src/runtime/agent/orchestrator/context/deferred-tools.mjs +5 -14
  101. package/src/runtime/agent/orchestrator/context/role-instructions.mjs +8 -16
  102. package/src/runtime/agent/orchestrator/context/skill-catalog.mjs +11 -17
  103. package/src/runtime/agent/orchestrator/context/skill-state.mjs +0 -16
  104. package/src/runtime/agent/orchestrator/dispatch-persist.mjs +2 -2
  105. package/src/runtime/agent/orchestrator/internal-agents.mjs +4 -7
  106. package/src/runtime/agent/orchestrator/mcp/child-tree.mjs +1 -2
  107. package/src/runtime/agent/orchestrator/mcp/client-config.mjs +238 -0
  108. package/src/runtime/agent/orchestrator/mcp/client-handshake.mjs +70 -0
  109. package/src/runtime/agent/orchestrator/mcp/client-transport.mjs +110 -0
  110. package/src/runtime/agent/orchestrator/mcp/client.mjs +89 -438
  111. package/src/runtime/agent/orchestrator/providers/account-pool.mjs +167 -71
  112. package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +16 -78
  113. package/src/runtime/agent/orchestrator/providers/anthropic-betas.mjs +0 -10
  114. package/src/runtime/agent/orchestrator/providers/anthropic-effort.mjs +1 -1
  115. package/src/runtime/agent/orchestrator/providers/anthropic-fast-mode.mjs +3 -11
  116. package/src/runtime/agent/orchestrator/providers/anthropic-leaked-toolcall.mjs +8 -4
  117. package/src/runtime/agent/orchestrator/providers/anthropic-max-tokens.mjs +2 -3
  118. package/src/runtime/agent/orchestrator/providers/anthropic-messages.mjs +23 -12
  119. package/src/runtime/agent/orchestrator/providers/anthropic-model-resolve.mjs +11 -4
  120. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-client-version.mjs +2 -3
  121. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-credentials.mjs +6 -6
  122. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-midstream.mjs +223 -0
  123. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-recovery.mjs +183 -0
  124. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-request/abort-wiring.mjs +67 -0
  125. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-request/gzip-post.mjs +52 -0
  126. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-request/initial-status.mjs +75 -0
  127. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-request.mjs +136 -0
  128. package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +205 -798
  129. package/src/runtime/agent/orchestrator/providers/anthropic-server-fallback.mjs +2 -1
  130. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/leak-guard.mjs +75 -0
  131. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-blocks.mjs +112 -0
  132. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events/content-block-delta.mjs +86 -0
  133. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events/content-block-start.mjs +82 -0
  134. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events/content-block-stop.mjs +101 -0
  135. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events/message-events.mjs +67 -0
  136. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events.mjs +22 -0
  137. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-outcome.mjs +156 -0
  138. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-state.mjs +37 -0
  139. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn.mjs +55 -0
  140. package/src/runtime/agent/orchestrator/providers/anthropic-sse-watchdogs.mjs +162 -0
  141. package/src/runtime/agent/orchestrator/providers/anthropic-sse.mjs +78 -918
  142. package/src/runtime/agent/orchestrator/providers/anthropic.mjs +16 -18
  143. package/src/runtime/agent/orchestrator/providers/antigravity-oauth-catalog.mjs +7 -2
  144. package/src/runtime/agent/orchestrator/providers/antigravity-oauth-login.mjs +4 -5
  145. package/src/runtime/agent/orchestrator/providers/antigravity-oauth-tokens.mjs +2 -2
  146. package/src/runtime/agent/orchestrator/providers/antigravity-oauth.mjs +14 -15
  147. package/src/runtime/agent/orchestrator/providers/antigravity-request.mjs +31 -24
  148. package/src/runtime/agent/orchestrator/providers/api-usage.mjs +2 -7
  149. package/src/runtime/agent/orchestrator/providers/cursor-auth.mjs +8 -9
  150. package/src/runtime/agent/orchestrator/providers/cursor-wire-exec.mjs +368 -0
  151. package/src/runtime/agent/orchestrator/providers/cursor-wire-models.mjs +96 -0
  152. package/src/runtime/agent/orchestrator/providers/cursor-wire-normalization.mjs +182 -103
  153. package/src/runtime/agent/orchestrator/providers/cursor-wire-protobuf.mjs +2 -2
  154. package/src/runtime/agent/orchestrator/providers/cursor-wire-request.mjs +197 -0
  155. package/src/runtime/agent/orchestrator/providers/cursor-wire-stream-bridge.mjs +157 -0
  156. package/src/runtime/agent/orchestrator/providers/cursor-wire-stream-messages.mjs +106 -0
  157. package/src/runtime/agent/orchestrator/providers/cursor-wire-stream-sink.mjs +53 -0
  158. package/src/runtime/agent/orchestrator/providers/cursor-wire-transport.mjs +269 -0
  159. package/src/runtime/agent/orchestrator/providers/cursor-wire.mjs +117 -1246
  160. package/src/runtime/agent/orchestrator/providers/cursor.mjs +261 -183
  161. package/src/runtime/agent/orchestrator/providers/custom-tool-wire.mjs +1 -1
  162. package/src/runtime/agent/orchestrator/providers/gemini-cache.mjs +3 -2
  163. package/src/runtime/agent/orchestrator/providers/gemini-rest-stream/sse-lines.mjs +21 -0
  164. package/src/runtime/agent/orchestrator/providers/gemini-rest-stream/watchdogs.mjs +68 -0
  165. package/src/runtime/agent/orchestrator/providers/gemini-schema.mjs +9 -17
  166. package/src/runtime/agent/orchestrator/providers/gemini-sdk-stream/cancellation.mjs +71 -0
  167. package/src/runtime/agent/orchestrator/providers/gemini-sdk-stream/reader.mjs +108 -0
  168. package/src/runtime/agent/orchestrator/providers/gemini-stream.mjs +71 -283
  169. package/src/runtime/agent/orchestrator/providers/gemini.mjs +913 -753
  170. package/src/runtime/agent/orchestrator/providers/grok-oauth-login.mjs +3 -4
  171. package/src/runtime/agent/orchestrator/providers/grok-oauth-tokens.mjs +16 -24
  172. package/src/runtime/agent/orchestrator/providers/grok-oauth.mjs +2 -8
  173. package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +7 -8
  174. package/src/runtime/agent/orchestrator/providers/lib/gemini-model-catalog.mjs +9 -7
  175. package/src/runtime/agent/orchestrator/providers/lib/grok-tool-schema.mjs +77 -63
  176. package/src/runtime/agent/orchestrator/providers/lib/oauth-pkce.mjs +1 -1
  177. package/src/runtime/agent/orchestrator/providers/lib/openai-tool-args.mjs +4 -2
  178. package/src/runtime/agent/orchestrator/providers/lib/responses-terminal-fields.mjs +28 -0
  179. package/src/runtime/agent/orchestrator/providers/lib/stream-outcome.mjs +3 -1
  180. package/src/runtime/agent/orchestrator/providers/lib/usage-primitives.mjs +0 -7
  181. package/src/runtime/agent/orchestrator/providers/media-normalization.mjs +10 -18
  182. package/src/runtime/agent/orchestrator/providers/model-cache.mjs +2 -2
  183. package/src/runtime/agent/orchestrator/providers/model-catalog-projection.mjs +9 -7
  184. package/src/runtime/agent/orchestrator/providers/model-catalog.mjs +21 -21
  185. package/src/runtime/agent/orchestrator/providers/model-list-sanitize.mjs +2 -2
  186. package/src/runtime/agent/orchestrator/providers/model-pricing-rates.mjs +8 -7
  187. package/src/runtime/agent/orchestrator/providers/oauth-usage.mjs +167 -124
  188. package/src/runtime/agent/orchestrator/providers/openai-codex-metadata.mjs +5 -5
  189. package/src/runtime/agent/orchestrator/providers/openai-codex-model.mjs +5 -8
  190. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-send.mjs +243 -0
  191. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/chunk-events.mjs +46 -0
  192. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/stream-result.mjs +82 -0
  193. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/stream-state.mjs +127 -0
  194. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/tool-call-acc.mjs +69 -0
  195. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream.mjs +35 -302
  196. package/src/runtime/agent/orchestrator/providers/openai-compat-models.mjs +78 -0
  197. package/src/runtime/agent/orchestrator/providers/openai-compat-options.mjs +76 -0
  198. package/src/runtime/agent/orchestrator/providers/openai-compat-response-normalization.mjs +358 -0
  199. package/src/runtime/agent/orchestrator/providers/openai-compat-responses-events.mjs +342 -0
  200. package/src/runtime/agent/orchestrator/providers/openai-compat-responses-state.mjs +172 -0
  201. package/src/runtime/agent/orchestrator/providers/openai-compat-responses.mjs +10 -18
  202. package/src/runtime/agent/orchestrator/providers/openai-compat-stream-common.mjs +24 -1
  203. package/src/runtime/agent/orchestrator/providers/openai-compat-stream.mjs +32 -534
  204. package/src/runtime/agent/orchestrator/providers/openai-compat-trace.mjs +2 -8
  205. package/src/runtime/agent/orchestrator/providers/openai-compat-wire.mjs +11 -11
  206. package/src/runtime/agent/orchestrator/providers/openai-compat-xai-send.mjs +262 -0
  207. package/src/runtime/agent/orchestrator/providers/openai-compat-xai.mjs +23 -24
  208. package/src/runtime/agent/orchestrator/providers/openai-compat.mjs +35 -970
  209. package/src/runtime/agent/orchestrator/providers/openai-http-sse-request.mjs +228 -0
  210. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-events/output-items.mjs +110 -0
  211. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-events/terminal-frames.mjs +122 -0
  212. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-events.mjs +69 -0
  213. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-items.mjs +142 -0
  214. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-outcome.mjs +195 -0
  215. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-state.mjs +74 -0
  216. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/text-relay.mjs +114 -0
  217. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state.mjs +45 -0
  218. package/src/runtime/agent/orchestrator/providers/openai-http-sse-watchdogs.mjs +176 -0
  219. package/src/runtime/agent/orchestrator/providers/openai-oauth-catalog.mjs +1 -1
  220. package/src/runtime/agent/orchestrator/providers/openai-oauth-http-sse.mjs +70 -1095
  221. package/src/runtime/agent/orchestrator/providers/openai-oauth-login.mjs +3 -3
  222. package/src/runtime/agent/orchestrator/providers/openai-oauth-tokens.mjs +3 -3
  223. package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +98 -1504
  224. package/src/runtime/agent/orchestrator/providers/openai-oauth.mjs +1 -1
  225. package/src/runtime/agent/orchestrator/providers/openai-responses-payload.mjs +160 -141
  226. package/src/runtime/agent/orchestrator/providers/openai-startup-prewarm.mjs +4 -7
  227. package/src/runtime/agent/orchestrator/providers/openai-transport-policy.mjs +6 -1
  228. package/src/runtime/agent/orchestrator/providers/openai-ws-delta.mjs +12 -11
  229. package/src/runtime/agent/orchestrator/providers/openai-ws-events.mjs +4 -11
  230. package/src/runtime/agent/orchestrator/providers/openai-ws-headers.mjs +5 -18
  231. package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +193 -227
  232. package/src/runtime/agent/orchestrator/providers/openai-ws-response-state/citations.mjs +53 -0
  233. package/src/runtime/agent/orchestrator/providers/openai-ws-response-state/replay-items.mjs +80 -0
  234. package/src/runtime/agent/orchestrator/providers/openai-ws-response-state/tool-calls.mjs +245 -0
  235. package/src/runtime/agent/orchestrator/providers/openai-ws-response-state/usage.mjs +15 -0
  236. package/src/runtime/agent/orchestrator/providers/openai-ws-response-state.mjs +227 -0
  237. package/src/runtime/agent/orchestrator/providers/openai-ws-send/acquire-attempt.mjs +94 -0
  238. package/src/runtime/agent/orchestrator/providers/openai-ws-send/attempt-request.mjs +145 -0
  239. package/src/runtime/agent/orchestrator/providers/openai-ws-send/reasoning-replay.mjs +36 -0
  240. package/src/runtime/agent/orchestrator/providers/openai-ws-send/send-context.mjs +154 -0
  241. package/src/runtime/agent/orchestrator/providers/openai-ws-send-attempts/attempt-context.mjs +74 -0
  242. package/src/runtime/agent/orchestrator/providers/openai-ws-send-attempts/handshake-failure.mjs +105 -0
  243. package/src/runtime/agent/orchestrator/providers/openai-ws-send-attempts/policy.mjs +142 -0
  244. package/src/runtime/agent/orchestrator/providers/openai-ws-send-attempts/stream-failure-stamps.mjs +81 -0
  245. package/src/runtime/agent/orchestrator/providers/openai-ws-send-attempts/stream-failure.mjs +109 -0
  246. package/src/runtime/agent/orchestrator/providers/openai-ws-send-attempts.mjs +63 -0
  247. package/src/runtime/agent/orchestrator/providers/openai-ws-send-outcome.mjs +625 -0
  248. package/src/runtime/agent/orchestrator/providers/openai-ws-send-span.mjs +93 -0
  249. package/src/runtime/agent/orchestrator/providers/openai-ws-stream/event-switch.mjs +125 -0
  250. package/src/runtime/agent/orchestrator/providers/openai-ws-stream/outcome.mjs +28 -0
  251. package/src/runtime/agent/orchestrator/providers/openai-ws-stream/socket-handlers.mjs +192 -0
  252. package/src/runtime/agent/orchestrator/providers/openai-ws-stream/terminal-frames.mjs +118 -0
  253. package/src/runtime/agent/orchestrator/providers/openai-ws-stream/turn-state-headers.mjs +106 -0
  254. package/src/runtime/agent/orchestrator/providers/openai-ws-stream.mjs +139 -1447
  255. package/src/runtime/agent/orchestrator/providers/openai-ws-terminal.mjs +120 -0
  256. package/src/runtime/agent/orchestrator/providers/openai-ws-text-relay.mjs +84 -0
  257. package/src/runtime/agent/orchestrator/providers/openai-ws-warmup.mjs +171 -0
  258. package/src/runtime/agent/orchestrator/providers/openai-ws-watchdogs.mjs +204 -0
  259. package/src/runtime/agent/orchestrator/providers/provider-catalog-cache.mjs +3 -3
  260. package/src/runtime/agent/orchestrator/providers/registry.mjs +13 -0
  261. package/src/runtime/agent/orchestrator/providers/retry-backoff.mjs +219 -0
  262. package/src/runtime/agent/orchestrator/providers/retry-classification.mjs +575 -0
  263. package/src/runtime/agent/orchestrator/providers/retry-classifier.mjs +52 -1317
  264. package/src/runtime/agent/orchestrator/providers/retry-executor.mjs +263 -0
  265. package/src/runtime/agent/orchestrator/providers/retry-midstream.mjs +345 -0
  266. package/src/runtime/agent/orchestrator/providers/stream-json-pool/owner-affinity.mjs +121 -0
  267. package/src/runtime/agent/orchestrator/providers/stream-json-pool/pool-tasks.mjs +74 -0
  268. package/src/runtime/agent/orchestrator/providers/stream-json-pool/stream-order.mjs +71 -0
  269. package/src/runtime/agent/orchestrator/providers/stream-json-pool/worker-slots/pending-queue.mjs +54 -0
  270. package/src/runtime/agent/orchestrator/providers/stream-json-pool/worker-slots/slot-pick.mjs +28 -0
  271. package/src/runtime/agent/orchestrator/providers/stream-json-pool/worker-slots/slot-spawn.mjs +92 -0
  272. package/src/runtime/agent/orchestrator/providers/stream-json-pool/worker-slots.mjs +165 -0
  273. package/src/runtime/agent/orchestrator/providers/stream-json-pool.mjs +66 -492
  274. package/src/runtime/agent/orchestrator/providers/trace-utils.mjs +10 -4
  275. package/src/runtime/agent/orchestrator/session/agent-loop.mjs +28 -551
  276. package/src/runtime/agent/orchestrator/session/cache/read-cache.mjs +1 -1
  277. package/src/runtime/agent/orchestrator/session/cache/scoped-cache.mjs +111 -117
  278. package/src/runtime/agent/orchestrator/session/compact/budget.mjs +1 -1
  279. package/src/runtime/agent/orchestrator/session/compact/constants.mjs +3 -0
  280. package/src/runtime/agent/orchestrator/session/compact/execution-tail.mjs +9 -8
  281. package/src/runtime/agent/orchestrator/session/compact/runner.mjs +327 -242
  282. package/src/runtime/agent/orchestrator/session/compact/summary-schema.mjs +3 -2
  283. package/src/runtime/agent/orchestrator/session/compact/summary.mjs +47 -341
  284. package/src/runtime/agent/orchestrator/session/compact/text-utils.mjs +3 -2
  285. package/src/runtime/agent/orchestrator/session/context-tool-pairs.mjs +295 -0
  286. package/src/runtime/agent/orchestrator/session/context-utils.mjs +219 -432
  287. package/src/runtime/agent/orchestrator/session/eager-dispatch/admission.mjs +132 -0
  288. package/src/runtime/agent/orchestrator/session/eager-dispatch/barriers.mjs +120 -0
  289. package/src/runtime/agent/orchestrator/session/eager-dispatch/entry.mjs +98 -0
  290. package/src/runtime/agent/orchestrator/session/eager-dispatch.mjs +51 -323
  291. package/src/runtime/agent/orchestrator/session/evidence-union.mjs +26 -553
  292. package/src/runtime/agent/orchestrator/session/explicit-skills.mjs +0 -3
  293. package/src/runtime/agent/orchestrator/session/loop/arg-schema-coerce.mjs +3 -1
  294. package/src/runtime/agent/orchestrator/session/loop/assistant-commit.mjs +3 -1
  295. package/src/runtime/agent/orchestrator/session/loop/compact-debug.mjs +1 -1
  296. package/src/runtime/agent/orchestrator/session/loop/compact-policy.mjs +145 -97
  297. package/src/runtime/agent/orchestrator/session/loop/completion-guards.mjs +3 -3
  298. package/src/runtime/agent/orchestrator/session/loop/context-overflow.mjs +11 -5
  299. package/src/runtime/agent/orchestrator/session/loop/fresh-context.mjs +142 -81
  300. package/src/runtime/agent/orchestrator/session/loop/hidden-agents.mjs +5 -5
  301. package/src/runtime/agent/orchestrator/session/loop/loop-state.mjs +183 -0
  302. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/continuation.mjs +48 -0
  303. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/diagnostic.mjs +8 -0
  304. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/empty-nudge.mjs +32 -0
  305. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/output-limit.mjs +39 -0
  306. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/refusal.mjs +25 -0
  307. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/segments.mjs +42 -0
  308. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn.mjs +42 -200
  309. package/src/runtime/agent/orchestrator/session/loop/pre-dispatch-deny.mjs +1 -1
  310. package/src/runtime/agent/orchestrator/session/loop/request-projection.mjs +5 -8
  311. package/src/runtime/agent/orchestrator/session/loop/send-phase.mjs +297 -0
  312. package/src/runtime/agent/orchestrator/session/loop/steering.mjs +11 -13
  313. package/src/runtime/agent/orchestrator/session/loop/stored-tool-args.mjs +7 -7
  314. package/src/runtime/agent/orchestrator/session/loop/termination.mjs +1 -1
  315. package/src/runtime/agent/orchestrator/session/loop/test-isolation.mjs +73 -0
  316. package/src/runtime/agent/orchestrator/session/loop/tool-classify.mjs +3 -4
  317. package/src/runtime/agent/orchestrator/session/loop/tool-exec/after-hook.mjs +36 -0
  318. package/src/runtime/agent/orchestrator/session/loop/tool-exec/before-hook.mjs +74 -0
  319. package/src/runtime/agent/orchestrator/session/loop/tool-exec/call-prep.mjs +110 -0
  320. package/src/runtime/agent/orchestrator/session/loop/tool-exec/dispatch.mjs +103 -0
  321. package/src/runtime/agent/orchestrator/session/loop/tool-exec/read-only-deadline.mjs +113 -0
  322. package/src/runtime/agent/orchestrator/session/loop/tool-exec.mjs +59 -422
  323. package/src/runtime/agent/orchestrator/session/loop/tool-helpers.mjs +9 -12
  324. package/src/runtime/agent/orchestrator/session/loop/tool-phase.mjs +86 -0
  325. package/src/runtime/agent/orchestrator/session/loop/transcript-repair.mjs +1 -1
  326. package/src/runtime/agent/orchestrator/session/loop/usage.mjs +5 -1
  327. package/src/runtime/agent/orchestrator/session/manager/agent-runtime-singleton.mjs +1 -1
  328. package/src/runtime/agent/orchestrator/session/manager/ask-call-interrupt.mjs +52 -0
  329. package/src/runtime/agent/orchestrator/session/manager/ask-queue.mjs +96 -0
  330. package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +149 -1447
  331. package/src/runtime/agent/orchestrator/session/manager/ask-support.mjs +48 -0
  332. package/src/runtime/agent/orchestrator/session/manager/ask-turn-commit.mjs +184 -0
  333. package/src/runtime/agent/orchestrator/session/manager/ask-turn-execute.mjs +181 -0
  334. package/src/runtime/agent/orchestrator/session/manager/ask-turn-failure.mjs +209 -0
  335. package/src/runtime/agent/orchestrator/session/manager/ask-turn-loop-options.mjs +242 -0
  336. package/src/runtime/agent/orchestrator/session/manager/ask-turn-open.mjs +132 -0
  337. package/src/runtime/agent/orchestrator/session/manager/ask-turn-prepare.mjs +247 -0
  338. package/src/runtime/agent/orchestrator/session/manager/ask-turn-settle.mjs +199 -0
  339. package/src/runtime/agent/orchestrator/session/manager/ask-turn-state.mjs +126 -0
  340. package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +300 -255
  341. package/src/runtime/agent/orchestrator/session/manager/delivered-completions.mjs +3 -2
  342. package/src/runtime/agent/orchestrator/session/manager/failed-turn-rewind.mjs +47 -0
  343. package/src/runtime/agent/orchestrator/session/manager/foreign-pending-messages.mjs +1 -1
  344. package/src/runtime/agent/orchestrator/session/manager/idle-cleanup.mjs +2 -2
  345. package/src/runtime/agent/orchestrator/session/manager/message-sanitize.mjs +6 -25
  346. package/src/runtime/agent/orchestrator/session/manager/pending-message-entry.mjs +13 -12
  347. package/src/runtime/agent/orchestrator/session/manager/pending-messages.mjs +12 -24
  348. package/src/runtime/agent/orchestrator/session/manager/prefetch-bridge/file-entries.mjs +36 -0
  349. package/src/runtime/agent/orchestrator/session/manager/prefetch-bridge/file-prefetch.mjs +85 -0
  350. package/src/runtime/agent/orchestrator/session/manager/prefetch-bridge/symbol-prefetch.mjs +31 -0
  351. package/src/runtime/agent/orchestrator/session/manager/prefetch-bridge.mjs +36 -203
  352. package/src/runtime/agent/orchestrator/session/manager/rules-cache.mjs +2 -31
  353. package/src/runtime/agent/orchestrator/session/manager/rules-source-cache.mjs +3 -2
  354. package/src/runtime/agent/orchestrator/session/manager/runtime-liveness.mjs +5 -2
  355. package/src/runtime/agent/orchestrator/session/manager/runtime-loaders.mjs +1 -1
  356. package/src/runtime/agent/orchestrator/session/manager/session-close.mjs +5 -3
  357. package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +155 -163
  358. package/src/runtime/agent/orchestrator/session/manager/session-id.mjs +3 -3
  359. package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +371 -266
  360. package/src/runtime/agent/orchestrator/session/manager/tool-resolution.mjs +3 -9
  361. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-context.mjs +5 -12
  362. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.mjs +4 -4
  363. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint.mjs +3 -5
  364. package/src/runtime/agent/orchestrator/session/manager/turn-interruption-journal.mjs +114 -0
  365. package/src/runtime/agent/orchestrator/session/manager/turn-interruption.mjs +75 -164
  366. package/src/runtime/agent/orchestrator/session/manager/usage-metrics.mjs +206 -173
  367. package/src/runtime/agent/orchestrator/session/manager.mjs +1 -1
  368. package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +447 -462
  369. package/src/runtime/agent/orchestrator/session/provider-prefix-guard.mjs +1 -1
  370. package/src/runtime/agent/orchestrator/session/runtime-user-context.mjs +2 -5
  371. package/src/runtime/agent/orchestrator/session/save-session-worker.mjs +1 -1
  372. package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +662 -620
  373. package/src/runtime/agent/orchestrator/session/store/fs-probe.mjs +1 -1
  374. package/src/runtime/agent/orchestrator/session/store/listing.mjs +9 -586
  375. package/src/runtime/agent/orchestrator/session/store/load-cache.mjs +1 -1
  376. package/src/runtime/agent/orchestrator/session/store/paths-heartbeat.mjs +3 -3
  377. package/src/runtime/agent/orchestrator/session/store/save-fault.mjs +15 -14
  378. package/src/runtime/agent/orchestrator/session/store/save-worker.mjs +221 -207
  379. package/src/runtime/agent/orchestrator/session/store/serialize.mjs +2 -2
  380. package/src/runtime/agent/orchestrator/session/store/summary-cache.mjs +2 -2
  381. package/src/runtime/agent/orchestrator/session/store/summary-rebuild-worker.mjs +1 -1
  382. package/src/runtime/agent/orchestrator/session/store/sweep/stale-sweep.mjs +74 -0
  383. package/src/runtime/agent/orchestrator/session/store/sweep/sweep-finish.mjs +90 -0
  384. package/src/runtime/agent/orchestrator/session/store/sweep/sweep-plan.mjs +81 -0
  385. package/src/runtime/agent/orchestrator/session/store/sweep/sweep-record.mjs +92 -0
  386. package/src/runtime/agent/orchestrator/session/store/sweep/sweep-row.mjs +313 -0
  387. package/src/runtime/agent/orchestrator/session/store-agent-worker-pool.mjs +37 -0
  388. package/src/runtime/agent/orchestrator/session/store-summary-index.mjs +3 -3
  389. package/src/runtime/agent/orchestrator/session/store-summary-reader.mjs +259 -228
  390. package/src/runtime/agent/orchestrator/session/store.mjs +13 -13
  391. package/src/runtime/agent/orchestrator/session/synthetic-user-envelope.mjs +6 -2
  392. package/src/runtime/agent/orchestrator/session/tool-batch/execute-call.mjs +265 -0
  393. package/src/runtime/agent/orchestrator/session/tool-batch/finalize.mjs +259 -0
  394. package/src/runtime/agent/orchestrator/session/tool-batch/flush.mjs +65 -0
  395. package/src/runtime/agent/orchestrator/session/tool-batch/plan.mjs +99 -0
  396. package/src/runtime/agent/orchestrator/session/tool-batch/pre-dispatch.mjs +123 -0
  397. package/src/runtime/agent/orchestrator/session/tool-batch/record-outcome.mjs +160 -0
  398. package/src/runtime/agent/orchestrator/session/tool-batch/state.mjs +54 -0
  399. package/src/runtime/agent/orchestrator/session/tool-batch.mjs +24 -1061
  400. package/src/runtime/agent/orchestrator/session/tool-envelope.mjs +7 -5
  401. package/src/runtime/agent/orchestrator/session/tool-result-offload.mjs +6 -6
  402. package/src/runtime/agent/orchestrator/tool-loop-guard.mjs +1 -1
  403. package/src/runtime/agent/orchestrator/tools/bash-policy-scan.mjs +1 -1
  404. package/src/runtime/agent/orchestrator/tools/builtin/advisory-lock.mjs +5 -8
  405. package/src/runtime/agent/orchestrator/tools/builtin/arg-guard.mjs +17 -12
  406. package/src/runtime/agent/orchestrator/tools/builtin/atomic-write.mjs +155 -159
  407. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/abort-signals.mjs +66 -0
  408. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/backgrounded-result.mjs +82 -0
  409. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/benign-exit.mjs +86 -0
  410. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/command-preflight.mjs +46 -0
  411. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/completed-result.mjs +169 -0
  412. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/deadline-plan.mjs +75 -0
  413. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/inline-hoist.mjs +36 -0
  414. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/invocation-plan.mjs +84 -0
  415. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/result-format.mjs +113 -0
  416. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/spawn-env.mjs +24 -0
  417. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/transport-artifacts.mjs +114 -0
  418. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +109 -905
  419. package/src/runtime/agent/orchestrator/tools/builtin/binary-file.mjs +2 -2
  420. package/src/runtime/agent/orchestrator/tools/builtin/builtin-tools.mjs +8 -4
  421. package/src/runtime/agent/orchestrator/tools/builtin/cache-layers.mjs +58 -111
  422. package/src/runtime/agent/orchestrator/tools/builtin/diff-utils.mjs +7 -2
  423. package/src/runtime/agent/orchestrator/tools/builtin/external-tool-adapters.mjs +251 -208
  424. package/src/runtime/agent/orchestrator/tools/builtin/find-files-tool.mjs +529 -0
  425. package/src/runtime/agent/orchestrator/tools/builtin/git-command-policy.mjs +1 -0
  426. package/src/runtime/agent/orchestrator/tools/builtin/git-command-tool.mjs +145 -666
  427. package/src/runtime/agent/orchestrator/tools/builtin/git-partial-stage.mjs +43 -21
  428. package/src/runtime/agent/orchestrator/tools/builtin/glob-walk.mjs +5 -5
  429. package/src/runtime/agent/orchestrator/tools/builtin/grep-formatting.mjs +1 -1
  430. package/src/runtime/agent/orchestrator/tools/builtin/hash-utils.mjs +1 -1
  431. package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-context-expander.mjs +121 -107
  432. package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-output.mjs +100 -56
  433. package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-path-fanout.mjs +243 -212
  434. package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-pattern-fanout.mjs +330 -331
  435. package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-request.mjs +291 -0
  436. package/src/runtime/agent/orchestrator/tools/builtin/lib/search-grep-chunks.mjs +7 -6
  437. package/src/runtime/agent/orchestrator/tools/builtin/lib/search-input-helpers.mjs +13 -0
  438. package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-task-output.mjs +104 -0
  439. package/src/runtime/agent/orchestrator/tools/builtin/lib/tool-progress.mjs +10 -0
  440. package/src/runtime/agent/orchestrator/tools/builtin/list-tool-shared.mjs +48 -0
  441. package/src/runtime/agent/orchestrator/tools/builtin/list-tool.mjs +314 -791
  442. package/src/runtime/agent/orchestrator/tools/builtin/native-search-client.mjs +8 -4
  443. package/src/runtime/agent/orchestrator/tools/builtin/path-diagnostics.mjs +8 -8
  444. package/src/runtime/agent/orchestrator/tools/builtin/path-utils.mjs +19 -10
  445. package/src/runtime/agent/orchestrator/tools/builtin/read-args.mjs +1 -1
  446. package/src/runtime/agent/orchestrator/tools/builtin/read-batch.mjs +16 -21
  447. package/src/runtime/agent/orchestrator/tools/builtin/read-image-resize.mjs +174 -103
  448. package/src/runtime/agent/orchestrator/tools/builtin/read-image.mjs +2 -2
  449. package/src/runtime/agent/orchestrator/tools/builtin/read-line-collector.mjs +160 -0
  450. package/src/runtime/agent/orchestrator/tools/builtin/read-mode-tool.mjs +14 -14
  451. package/src/runtime/agent/orchestrator/tools/builtin/read-office-files.mjs +5 -8
  452. package/src/runtime/agent/orchestrator/tools/builtin/read-open.mjs +3 -4
  453. package/src/runtime/agent/orchestrator/tools/builtin/read-range-index.mjs +5 -5
  454. package/src/runtime/agent/orchestrator/tools/builtin/read-single-fast-paths.mjs +178 -0
  455. package/src/runtime/agent/orchestrator/tools/builtin/read-single-guards.mjs +161 -0
  456. package/src/runtime/agent/orchestrator/tools/builtin/read-single-media.mjs +53 -0
  457. package/src/runtime/agent/orchestrator/tools/builtin/read-single-render.mjs +210 -0
  458. package/src/runtime/agent/orchestrator/tools/builtin/read-single-stream.mjs +79 -0
  459. package/src/runtime/agent/orchestrator/tools/builtin/read-single-tool.mjs +122 -832
  460. package/src/runtime/agent/orchestrator/tools/builtin/read-snapshot-runtime.mjs +3 -4
  461. package/src/runtime/agent/orchestrator/tools/builtin/read-special-files.mjs +6 -11
  462. package/src/runtime/agent/orchestrator/tools/builtin/read-streaming.mjs +23 -139
  463. package/src/runtime/agent/orchestrator/tools/builtin/read-tool/batch-dispatch.mjs +123 -0
  464. package/src/runtime/agent/orchestrator/tools/builtin/read-tool/batch-entries.mjs +137 -0
  465. package/src/runtime/agent/orchestrator/tools/builtin/read-tool/batch-render.mjs +158 -0
  466. package/src/runtime/agent/orchestrator/tools/builtin/read-tool/batch-snapshot.mjs +88 -0
  467. package/src/runtime/agent/orchestrator/tools/builtin/read-tool/glob-survey.mjs +100 -0
  468. package/src/runtime/agent/orchestrator/tools/builtin/read-tool/image-fast-path.mjs +32 -0
  469. package/src/runtime/agent/orchestrator/tools/builtin/read-tool/reach-preflight.mjs +95 -0
  470. package/src/runtime/agent/orchestrator/tools/builtin/read-tool.mjs +115 -703
  471. package/src/runtime/agent/orchestrator/tools/builtin/read-window-widen.mjs +42 -0
  472. package/src/runtime/agent/orchestrator/tools/builtin/read-windows.mjs +9 -2
  473. package/src/runtime/agent/orchestrator/tools/builtin/runtime-capabilities.mjs +47 -30
  474. package/src/runtime/agent/orchestrator/tools/builtin/search-builders.mjs +4 -4
  475. package/src/runtime/agent/orchestrator/tools/builtin/search-glob-tool.mjs +494 -427
  476. package/src/runtime/agent/orchestrator/tools/builtin/search-grep-tool.mjs +550 -785
  477. package/src/runtime/agent/orchestrator/tools/builtin/search-path-diagnostics.mjs +5 -5
  478. package/src/runtime/agent/orchestrator/tools/builtin/shell-analysis.mjs +13 -7
  479. package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +16 -19
  480. package/src/runtime/agent/orchestrator/tools/builtin/shell-lossless-compact.mjs +1 -2
  481. package/src/runtime/agent/orchestrator/tools/builtin/shell-runtime.mjs +3 -3
  482. package/src/runtime/agent/orchestrator/tools/builtin/snapshot-store.mjs +2 -2
  483. package/src/runtime/agent/orchestrator/tools/builtin/snapshot-validation.mjs +5 -5
  484. package/src/runtime/agent/orchestrator/tools/builtin/task-tool.mjs +25 -17
  485. package/src/runtime/agent/orchestrator/tools/builtin/text-stats.mjs +1 -1
  486. package/src/runtime/agent/orchestrator/tools/builtin.mjs +22 -20
  487. package/src/runtime/agent/orchestrator/tools/code-graph/aggregate-roots.mjs +9 -10
  488. package/src/runtime/agent/orchestrator/tools/code-graph/ast-calls.mjs +1 -1
  489. package/src/runtime/agent/orchestrator/tools/code-graph/build.mjs +1 -1
  490. package/src/runtime/agent/orchestrator/tools/code-graph/disk-cache.mjs +94 -87
  491. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch/abort-race.mjs +33 -0
  492. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch/federation.mjs +144 -0
  493. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch/root-resolution.mjs +142 -0
  494. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch/work.mjs +125 -0
  495. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +180 -1056
  496. package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary/child-kill.mjs +55 -0
  497. package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary/jsonl-records.mjs +22 -0
  498. package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary/spawn-jsonl.mjs +135 -0
  499. package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary.mjs +43 -232
  500. package/src/runtime/agent/orchestrator/tools/code-graph/modes/calls.mjs +152 -0
  501. package/src/runtime/agent/orchestrator/tools/code-graph/modes/dependents.mjs +91 -0
  502. package/src/runtime/agent/orchestrator/tools/code-graph/modes/shared.mjs +81 -0
  503. package/src/runtime/agent/orchestrator/tools/code-graph/modes/structure.mjs +75 -0
  504. package/src/runtime/agent/orchestrator/tools/code-graph/modes/symbols.mjs +150 -0
  505. package/src/runtime/agent/orchestrator/tools/code-graph/project-root.mjs +1 -1
  506. package/src/runtime/agent/orchestrator/tools/code-graph/search-references.mjs +40 -41
  507. package/src/runtime/agent/orchestrator/tools/code-graph/search.mjs +3 -4
  508. package/src/runtime/agent/orchestrator/tools/code-graph/text-columns.mjs +1 -1
  509. package/src/runtime/agent/orchestrator/tools/code-graph/text-mask.golden.json +47 -0
  510. package/src/runtime/agent/orchestrator/tools/code-graph/text-mask.mjs +244 -290
  511. package/src/runtime/agent/orchestrator/tools/code-graph-prewarm-worker.mjs +1 -1
  512. package/src/runtime/agent/orchestrator/tools/code-graph-state.mjs +1 -1
  513. package/src/runtime/agent/orchestrator/tools/env-scrub.mjs +7 -11
  514. package/src/runtime/agent/orchestrator/tools/graph-manifest.json +11 -11
  515. package/src/runtime/agent/orchestrator/tools/lib/isolated-test-env.mjs +30 -0
  516. package/src/runtime/agent/orchestrator/tools/lib/native-spawn-client.mjs +2 -2
  517. package/src/runtime/agent/orchestrator/tools/lib/shell-run-background/promote-job.mjs +90 -0
  518. package/src/runtime/agent/orchestrator/tools/lib/shell-run-background/promotion-results.mjs +158 -0
  519. package/src/runtime/agent/orchestrator/tools/lib/shell-run-background.mjs +142 -0
  520. package/src/runtime/agent/orchestrator/tools/lib/shell-run-settle.mjs +165 -0
  521. package/src/runtime/agent/orchestrator/tools/lib/shell-run-spawn.mjs +208 -0
  522. package/src/runtime/agent/orchestrator/tools/lib/shell-run-state.mjs +175 -0
  523. package/src/runtime/agent/orchestrator/tools/lib/shell-spawn-retry.mjs +2 -2
  524. package/src/runtime/agent/orchestrator/tools/lib/shell-warm-standby.mjs +1 -1
  525. package/src/runtime/agent/orchestrator/tools/patch/apply-patch/codex-batch.mjs +245 -0
  526. package/src/runtime/agent/orchestrator/tools/patch/apply-patch/request.mjs +96 -0
  527. package/src/runtime/agent/orchestrator/tools/patch/apply-patch/route.mjs +46 -0
  528. package/src/runtime/agent/orchestrator/tools/patch/constants.mjs +1 -2
  529. package/src/runtime/agent/orchestrator/tools/patch/dispatch/native-proofs.mjs +65 -0
  530. package/src/runtime/agent/orchestrator/tools/patch/dispatch/native-report.mjs +65 -0
  531. package/src/runtime/agent/orchestrator/tools/patch/dispatch/native-snapshots.mjs +72 -0
  532. package/src/runtime/agent/orchestrator/tools/patch/dispatch.mjs +32 -168
  533. package/src/runtime/agent/orchestrator/tools/patch/matcher.mjs +116 -358
  534. package/src/runtime/agent/orchestrator/tools/patch/mutation-output.mjs +30 -0
  535. package/src/runtime/agent/orchestrator/tools/patch/orchestrator.mjs +69 -1401
  536. package/src/runtime/agent/orchestrator/tools/patch/parsing.mjs +4 -2
  537. package/src/runtime/agent/orchestrator/tools/patch/post-patch-excerpts.mjs +99 -0
  538. package/src/runtime/agent/orchestrator/tools/patch/read-redirects.mjs +81 -0
  539. package/src/runtime/agent/orchestrator/tools/patch/replay-capture.mjs +184 -0
  540. package/src/runtime/agent/orchestrator/tools/patch/rollback-state.mjs +51 -0
  541. package/src/runtime/agent/orchestrator/tools/patch/section-coalesce.mjs +82 -0
  542. package/src/runtime/agent/orchestrator/tools/patch/sequence/report.mjs +88 -0
  543. package/src/runtime/agent/orchestrator/tools/patch/sequence/run.mjs +70 -0
  544. package/src/runtime/agent/orchestrator/tools/patch/sequence/units.mjs +132 -0
  545. package/src/runtime/agent/orchestrator/tools/patch/sequence.mjs +84 -0
  546. package/src/runtime/agent/orchestrator/tools/patch/text-lines.mjs +267 -0
  547. package/src/runtime/agent/orchestrator/tools/patch/ui-diff.mjs +108 -0
  548. package/src/runtime/agent/orchestrator/tools/patch/v4a-anchors.mjs +4 -5
  549. package/src/runtime/agent/orchestrator/tools/patch/v4a-convert.mjs +434 -432
  550. package/src/runtime/agent/orchestrator/tools/patch/wave.mjs +114 -0
  551. package/src/runtime/agent/orchestrator/tools/patch-binary-fetcher.mjs +1 -1
  552. package/src/runtime/agent/orchestrator/tools/patch-manifest.json +11 -11
  553. package/src/runtime/agent/orchestrator/tools/progress-message.mjs +6 -5
  554. package/src/runtime/agent/orchestrator/tools/shell-command.mjs +249 -996
  555. package/src/runtime/agent/orchestrator/tools/shell-exec-output.mjs +7 -9
  556. package/src/runtime/agent/orchestrator/tools/shell-exec-policy.mjs +2 -2
  557. package/src/runtime/agent/orchestrator/tools/shell-policy.mjs +6 -6
  558. package/src/runtime/agent/orchestrator/tools/shell-powershell.mjs +2 -2
  559. package/src/runtime/agent/orchestrator/tools/shell-snapshot.mjs +4 -5
  560. package/src/runtime/agent/orchestrator/tools/spawn-manifest.json +11 -11
  561. package/src/runtime/agent/orchestrator/tools/tool-batch-trace.mjs +9 -13
  562. package/src/runtime/attachments/store.mjs +3 -9
  563. package/src/runtime/browser-bridge/action-schema.mjs +396 -325
  564. package/src/runtime/browser-bridge/client.mjs +1 -9
  565. package/src/runtime/browser-bridge/input-fields.mjs +13 -9
  566. package/src/runtime/channels/lib/config.mjs +1 -10
  567. package/src/runtime/channels/lib/crash-log.mjs +4 -4
  568. package/src/runtime/channels/lib/event-queue.mjs +5 -6
  569. package/src/runtime/channels/lib/executor.mjs +2 -84
  570. package/src/runtime/channels/lib/owned-runtime/automation-services.mjs +105 -0
  571. package/src/runtime/channels/lib/owned-runtime/automation-start.mjs +44 -0
  572. package/src/runtime/channels/lib/owned-runtime/config-reload.mjs +79 -0
  573. package/src/runtime/channels/lib/owned-runtime/owned-start.mjs +172 -0
  574. package/src/runtime/channels/lib/owned-runtime/owned-stop.mjs +59 -0
  575. package/src/runtime/channels/lib/owned-runtime/ownership-refresh.mjs +36 -0
  576. package/src/runtime/channels/lib/owned-runtime/state.mjs +22 -0
  577. package/src/runtime/channels/lib/owned-runtime.mjs +45 -488
  578. package/src/runtime/channels/lib/parent-bridge.mjs +2 -2
  579. package/src/runtime/channels/lib/runtime-paths.mjs +5 -8
  580. package/src/runtime/channels/lib/scheduler.mjs +152 -135
  581. package/src/runtime/channels/lib/settings.mjs +1 -1
  582. package/src/runtime/channels/lib/state-file.mjs +1 -6
  583. package/src/runtime/channels/lib/status-snapshot.mjs +53 -53
  584. package/src/runtime/channels/lib/voice-runtime-fetcher.mjs +17 -21
  585. package/src/runtime/channels/lib/voice-transcription.mjs +5 -5
  586. package/src/runtime/channels/lib/webhook/deliveries.mjs +0 -5
  587. package/src/runtime/channels/lib/webhook/listener-lifecycle.mjs +119 -0
  588. package/src/runtime/channels/lib/webhook/log.mjs +3 -3
  589. package/src/runtime/channels/lib/webhook/relay-tunnel/leg-heartbeat.mjs +35 -0
  590. package/src/runtime/channels/lib/webhook/relay-tunnel/limits.mjs +6 -0
  591. package/src/runtime/channels/lib/webhook/relay-tunnel/local-forward.mjs +93 -0
  592. package/src/runtime/channels/lib/webhook/relay-tunnel.mjs +50 -168
  593. package/src/runtime/channels/lib/webhook/request-handler.mjs +258 -0
  594. package/src/runtime/channels/lib/webhook/session-dispatch.mjs +132 -0
  595. package/src/runtime/channels/lib/webhook/signature.mjs +1 -1
  596. package/src/runtime/channels/lib/webhook/verification.mjs +90 -0
  597. package/src/runtime/channels/lib/webhook.mjs +46 -497
  598. package/src/runtime/channels/lib/whisper-language.mjs +3 -10
  599. package/src/runtime/channels/lib/worker-bootstrap.mjs +51 -41
  600. package/src/runtime/channels/lib/worker-ipc.mjs +4 -4
  601. package/src/runtime/channels/lib/worker-main.mjs +7 -11
  602. package/src/runtime/computer-bridge/action-schema.mjs +180 -133
  603. package/src/runtime/computer-bridge/actions.mjs +19 -2
  604. package/src/runtime/computer-bridge/capture-size.mjs +8 -2
  605. package/src/runtime/computer-bridge/client.mjs +179 -147
  606. package/src/runtime/computer-bridge/core-actions.mjs +143 -101
  607. package/src/runtime/computer-bridge/pending-continuation.mjs +4 -7
  608. package/src/runtime/github/client.mjs +5 -7
  609. package/src/runtime/github/contract.mjs +3 -1
  610. package/src/runtime/local-provider/asset-installer.mjs +5 -7
  611. package/src/runtime/local-provider/model-state.mjs +8 -6
  612. package/src/runtime/local-provider/server-process/child-state.mjs +73 -0
  613. package/src/runtime/local-provider/server-process/readiness.mjs +42 -0
  614. package/src/runtime/local-provider/server-process.mjs +28 -113
  615. package/src/runtime/media/adapters/codex-image.mjs +1 -1
  616. package/src/runtime/media/adapters/xai-media.mjs +7 -2
  617. package/src/runtime/media/catalog-errors.mjs +3 -5
  618. package/src/runtime/media/catalog.mjs +4 -6
  619. package/src/runtime/media/defaults.mjs +2 -2
  620. package/src/runtime/media/jobs.mjs +1 -2
  621. package/src/runtime/media/renditions.mjs +11 -10
  622. package/src/runtime/media/store.mjs +7 -9
  623. package/src/runtime/media/tool.mjs +1 -5
  624. package/src/runtime/memory/data/runtime-manifest.json +9 -9
  625. package/src/runtime/memory/index.mjs +8 -15
  626. package/src/runtime/memory/lib/agent-ipc.mjs +1 -1
  627. package/src/runtime/memory/lib/core-memory-file.mjs +7 -5
  628. package/src/runtime/memory/lib/cycle-llm-adapters.mjs +1 -1
  629. package/src/runtime/memory/lib/cycle-scheduler/backlog-probe.mjs +65 -0
  630. package/src/runtime/memory/lib/cycle-scheduler/cycle1-runs.mjs +120 -0
  631. package/src/runtime/memory/lib/cycle-scheduler/cycle2-runs.mjs +120 -0
  632. package/src/runtime/memory/lib/cycle-scheduler/health-ledger.mjs +96 -0
  633. package/src/runtime/memory/lib/cycle-scheduler/scheduled-enqueue.mjs +50 -0
  634. package/src/runtime/memory/lib/cycle-scheduler/tick-loop.mjs +104 -0
  635. package/src/runtime/memory/lib/cycle-scheduler.mjs +71 -475
  636. package/src/runtime/memory/lib/cycle-signatures.mjs +1 -2
  637. package/src/runtime/memory/lib/cycle1/cycle1-plan.mjs +94 -0
  638. package/src/runtime/memory/lib/cycle1/cycle1-result.mjs +113 -0
  639. package/src/runtime/memory/lib/cycle1/cycle1-rows.mjs +194 -0
  640. package/src/runtime/memory/lib/cycle1/cycle1-window.mjs +193 -0
  641. package/src/runtime/memory/lib/embedding-provider.mjs +3 -3
  642. package/src/runtime/memory/lib/embedding-worker.mjs +7 -9
  643. package/src/runtime/memory/lib/http-router/admin-routes.mjs +213 -0
  644. package/src/runtime/memory/lib/http-router/ingest-routes.mjs +122 -0
  645. package/src/runtime/memory/lib/http-router/lifecycle-routes.mjs +96 -0
  646. package/src/runtime/memory/lib/http-router/mcp-route.mjs +49 -0
  647. package/src/runtime/memory/lib/http-router/session-routes.mjs +67 -0
  648. package/src/runtime/memory/lib/http-router/tool-routes.mjs +84 -0
  649. package/src/runtime/memory/lib/http-router.mjs +43 -659
  650. package/src/runtime/memory/lib/http-wire.mjs +1 -2
  651. package/src/runtime/memory/lib/ingest/ingest-embed-flush.mjs +72 -0
  652. package/src/runtime/memory/lib/ingest/ingest-insert.mjs +66 -0
  653. package/src/runtime/memory/lib/ingest/ingest-occurrences.mjs +109 -0
  654. package/src/runtime/memory/lib/ingest/ordinal-state.mjs +181 -0
  655. package/src/runtime/memory/lib/ingest/transcript-discovery.mjs +52 -0
  656. package/src/runtime/memory/lib/ingest/transcript-offsets.mjs +54 -0
  657. package/src/runtime/memory/lib/ingest/transcript-rows.mjs +81 -0
  658. package/src/runtime/memory/lib/ingest/transcript-tail.mjs +110 -0
  659. package/src/runtime/memory/lib/ingest/transcript-watcher.mjs +216 -0
  660. package/src/runtime/memory/lib/light-ko-morph.mjs +1 -1
  661. package/src/runtime/memory/lib/memory-action-handlers/core-actions.mjs +127 -0
  662. package/src/runtime/memory/lib/memory-action-handlers/cycle-actions.mjs +278 -0
  663. package/src/runtime/memory/lib/memory-action-handlers/maintenance-actions.mjs +76 -0
  664. package/src/runtime/memory/lib/memory-action-handlers/manage-actions.mjs +181 -0
  665. package/src/runtime/memory/lib/memory-action-handlers.mjs +49 -679
  666. package/src/runtime/memory/lib/memory-chunk-quality.mjs +59 -20
  667. package/src/runtime/memory/lib/memory-config-flags.mjs +1 -1
  668. package/src/runtime/memory/lib/memory-cycle-requests.mjs +9 -21
  669. package/src/runtime/memory/lib/memory-cycle1.mjs +49 -525
  670. package/src/runtime/memory/lib/memory-cycle2-mutations.mjs +4 -3
  671. package/src/runtime/memory/lib/memory-cycle2-review.mjs +5 -3
  672. package/src/runtime/memory/lib/memory-cycle2-shared.mjs +2 -2
  673. package/src/runtime/memory/lib/memory-embed.mjs +4 -9
  674. package/src/runtime/memory/lib/memory-extraction.mjs +1 -1
  675. package/src/runtime/memory/lib/memory-process-lock.mjs +1 -1
  676. package/src/runtime/memory/lib/memory-recall-scope-filter.mjs +7 -3
  677. package/src/runtime/memory/lib/memory-recall-store.mjs +70 -678
  678. package/src/runtime/memory/lib/memory-schema/core-and-meta.mjs +60 -0
  679. package/src/runtime/memory/lib/memory-schema/entries.mjs +94 -0
  680. package/src/runtime/memory/lib/memory-schema/entry-triggers.mjs +54 -0
  681. package/src/runtime/memory/lib/memory-schema/score-params.mjs +66 -0
  682. package/src/runtime/memory/lib/memory-text-utils.mjs +10 -10
  683. package/src/runtime/memory/lib/memory.mjs +14 -260
  684. package/src/runtime/memory/lib/model-profile.mjs +1 -1
  685. package/src/runtime/memory/lib/pg/adapter.mjs +4 -2
  686. package/src/runtime/memory/lib/pg/process.mjs +251 -254
  687. package/src/runtime/memory/lib/pg/supervisor.mjs +1 -6
  688. package/src/runtime/memory/lib/query-core-recall.mjs +82 -0
  689. package/src/runtime/memory/lib/query-fan-out.mjs +66 -0
  690. package/src/runtime/memory/lib/query-handlers.mjs +61 -1124
  691. package/src/runtime/memory/lib/query-hybrid-search.mjs +369 -0
  692. package/src/runtime/memory/lib/query-id-lookup.mjs +60 -0
  693. package/src/runtime/memory/lib/query-last-browse.mjs +266 -0
  694. package/src/runtime/memory/lib/query-maintenance-handlers.mjs +18 -17
  695. package/src/runtime/memory/lib/query-ranking.mjs +5 -3
  696. package/src/runtime/memory/lib/query-raw-merge.mjs +27 -0
  697. package/src/runtime/memory/lib/query-raw-window.mjs +64 -0
  698. package/src/runtime/memory/lib/query-search-plan.mjs +117 -0
  699. package/src/runtime/memory/lib/query-session-recall.mjs +153 -0
  700. package/src/runtime/memory/lib/query-window-browse.mjs +63 -0
  701. package/src/runtime/memory/lib/recall-event-context.mjs +1 -1
  702. package/src/runtime/memory/lib/recall-format.mjs +318 -279
  703. package/src/runtime/memory/lib/recall-hybrid/concept-expansion.mjs +211 -0
  704. package/src/runtime/memory/lib/recall-hybrid/hybrid-sql.mjs +250 -0
  705. package/src/runtime/memory/lib/recall-hybrid/members.mjs +33 -0
  706. package/src/runtime/memory/lib/recall-hybrid/plan.mjs +80 -0
  707. package/src/runtime/memory/lib/recall-hybrid/root-resolution.mjs +131 -0
  708. package/src/runtime/memory/lib/runtime-fetcher.mjs +4 -6
  709. package/src/runtime/memory/lib/session-ingest-runtime.mjs +50 -433
  710. package/src/runtime/memory/lib/session-ingest.mjs +8 -136
  711. package/src/runtime/memory/lib/tool-call-handler.mjs +2 -3
  712. package/src/runtime/memory/lib/trace-store/agent-call-inserts.mjs +90 -0
  713. package/src/runtime/memory/lib/trace-store/agent-call-rows.mjs +81 -0
  714. package/src/runtime/memory/lib/trace-store/agent-session-summary.mjs +65 -0
  715. package/src/runtime/memory/lib/trace-store.mjs +12 -242
  716. package/src/runtime/memory/lib/transcript-ingest.mjs +32 -475
  717. package/src/runtime/office/README.md +3 -2
  718. package/src/runtime/office/authoring/pptx-author-action.mjs +138 -70
  719. package/src/runtime/office/authoring/pptx-brief.mjs +52 -16
  720. package/src/runtime/office/authoring/pptx-contact-sheet.mjs +3 -1
  721. package/src/runtime/office/authoring/pptx-receipt.mjs +13 -12
  722. package/src/runtime/office/authoring/pptx-script-normalize.mjs +1 -1
  723. package/src/runtime/office/bench/deck-bench.mjs +6 -3
  724. package/src/runtime/office/bench/quality-live-benchmark.mjs +33 -0
  725. package/src/runtime/office/capabilities-aliases.mjs +61 -0
  726. package/src/runtime/office/capabilities-catalog.mjs +591 -0
  727. package/src/runtime/office/capabilities-signatures.mjs +580 -0
  728. package/src/runtime/office/capabilities.mjs +266 -1460
  729. package/src/runtime/office/com/com-adapter.mjs +2 -2
  730. package/src/runtime/office/com/office-com-host.ps1 +5185 -4979
  731. package/src/runtime/office/core/office-actions-batch.mjs +353 -312
  732. package/src/runtime/office/core/office-actions-inspect.mjs +108 -115
  733. package/src/runtime/office/core/office-actions-lifecycle.mjs +39 -253
  734. package/src/runtime/office/core/office-actions-open.mjs +28 -34
  735. package/src/runtime/office/core/office-actions-render.mjs +30 -258
  736. package/src/runtime/office/core/office-core.mjs +14 -24
  737. package/src/runtime/office/core/office-documents.mjs +3 -1
  738. package/src/runtime/office/core/office-finalize/commit-stage.mjs +54 -0
  739. package/src/runtime/office/core/office-finalize/holds.mjs +57 -0
  740. package/src/runtime/office/core/office-finalize/review-stage.mjs +90 -0
  741. package/src/runtime/office/core/office-finalize/session-save.mjs +47 -0
  742. package/src/runtime/office/core/office-qa/design-review-stage.mjs +80 -0
  743. package/src/runtime/office/core/office-qa/fix-operations.mjs +47 -0
  744. package/src/runtime/office/core/office-qa/preview-stage.mjs +90 -0
  745. package/src/runtime/office/core/office-qa/review-assembly.mjs +87 -0
  746. package/src/runtime/office/core/office-recalculation.mjs +2 -2
  747. package/src/runtime/office/core/office-render-preview.mjs +11 -13
  748. package/src/runtime/office/core/office-sessions.mjs +273 -286
  749. package/src/runtime/office/core/pagination.mjs +6 -6
  750. package/src/runtime/office/core/pptx-page-cache.mjs +1 -1
  751. package/src/runtime/office/core/tabular.mjs +11 -6
  752. package/src/runtime/office/design/composition-system.mjs +3 -1
  753. package/src/runtime/office/design/content-model.mjs +3 -1
  754. package/src/runtime/office/design/design-art-direction.mjs +5 -1
  755. package/src/runtime/office/design/design-creative-director.mjs +7 -8
  756. package/src/runtime/office/design/design-discipline.mjs +15 -18
  757. package/src/runtime/office/design/design-system.mjs +5 -8
  758. package/src/runtime/office/design/design-tokens.mjs +33 -28
  759. package/src/runtime/office/design/docx/design-docx/front-matter.mjs +81 -0
  760. package/src/runtime/office/design/docx/design-docx/section.mjs +114 -0
  761. package/src/runtime/office/design/docx/design-docx/writer.mjs +57 -0
  762. package/src/runtime/office/design/docx/design-docx-components.mjs +18 -19
  763. package/src/runtime/office/design/docx/design-docx.mjs +19 -222
  764. package/src/runtime/office/design/library/design-library-core.mjs +1 -1
  765. package/src/runtime/office/design/library/design-library.mjs +8 -6
  766. package/src/runtime/office/design/library/design-template-fill.mjs +159 -0
  767. package/src/runtime/office/design/library/design-template-index.mjs +221 -174
  768. package/src/runtime/office/design/library/design-template-induct.mjs +222 -0
  769. package/src/runtime/office/design/library/design-template-inspect.mjs +165 -121
  770. package/src/runtime/office/design/xlsx/design-xlsx-components.mjs +12 -15
  771. package/src/runtime/office/design/xlsx/design-xlsx.mjs +450 -359
  772. package/src/runtime/office/index.mjs +3 -1
  773. package/src/runtime/office/pdf/pdf-adapter.mjs +25 -816
  774. package/src/runtime/office/pdf/pdf-analysis.mjs +385 -585
  775. package/src/runtime/office/pdf/pdf-batch-content.mjs +349 -0
  776. package/src/runtime/office/pdf/pdf-batch-structure.mjs +240 -0
  777. package/src/runtime/office/pdf/pdf-document.mjs +41 -0
  778. package/src/runtime/office/pdf/pdf-draw.mjs +1 -1
  779. package/src/runtime/office/pdf/pdf-edit-document.mjs +142 -0
  780. package/src/runtime/office/pdf/pdf-fonts.mjs +1 -1
  781. package/src/runtime/office/pdf/pdf-forms.mjs +3 -1
  782. package/src/runtime/office/pdf/pdf-marks.mjs +123 -0
  783. package/src/runtime/office/pdf/pdf-ocr.mjs +347 -0
  784. package/src/runtime/office/pdf/pdf-search.mjs +4 -1
  785. package/src/runtime/office/pdf/pdf-security.mjs +37 -9
  786. package/src/runtime/office/pdf/pdf-writer.mjs +541 -412
  787. package/src/runtime/office/portable/docx-revisions.mjs +10 -8
  788. package/src/runtime/office/portable/docx-runs.mjs +3 -5
  789. package/src/runtime/office/portable/docx-tracked-edits.mjs +1 -2
  790. package/src/runtime/office/portable/font-provisioner.mjs +1 -1
  791. package/src/runtime/office/portable/portable-cells.mjs +67 -79
  792. package/src/runtime/office/portable/portable-chart-faults.mjs +42 -11
  793. package/src/runtime/office/portable/portable-chart.mjs +21 -17
  794. package/src/runtime/office/portable/portable-docx-edits.mjs +755 -0
  795. package/src/runtime/office/portable/portable-docx-operations.mjs +733 -0
  796. package/src/runtime/office/portable/portable-docx-parts.mjs +35 -4
  797. package/src/runtime/office/portable/portable-docx-xml.mjs +90 -60
  798. package/src/runtime/office/portable/portable-docx.mjs +84 -1340
  799. package/src/runtime/office/portable/portable-ooxml.mjs +5 -6
  800. package/src/runtime/office/portable/portable-opc.mjs +73 -3
  801. package/src/runtime/office/portable/portable-package.mjs +16 -7
  802. package/src/runtime/office/portable/portable-pivot.mjs +35 -30
  803. package/src/runtime/office/portable/portable-pptx-charts.mjs +48 -45
  804. package/src/runtime/office/portable/portable-pptx-core.mjs +94 -93
  805. package/src/runtime/office/portable/portable-pptx-deck.mjs +16 -13
  806. package/src/runtime/office/portable/portable-pptx-shapes.mjs +356 -276
  807. package/src/runtime/office/portable/portable-shared-formulas.mjs +92 -0
  808. package/src/runtime/office/portable/portable-sheet-audits.mjs +416 -0
  809. package/src/runtime/office/portable/portable-sheet-styles.mjs +8 -7
  810. package/src/runtime/office/portable/portable-sheet-xml.mjs +28 -29
  811. package/src/runtime/office/portable/portable-slide-shapes.mjs +44 -28
  812. package/src/runtime/office/portable/portable-snapshot-docx.mjs +622 -0
  813. package/src/runtime/office/portable/portable-snapshot-pptx.mjs +254 -0
  814. package/src/runtime/office/portable/portable-snapshot-shared.mjs +106 -0
  815. package/src/runtime/office/portable/portable-snapshot-xlsx.mjs +453 -0
  816. package/src/runtime/office/portable/portable-snapshot.mjs +8 -1134
  817. package/src/runtime/office/portable/portable-soffice.mjs +230 -232
  818. package/src/runtime/office/portable/portable-validation-package.mjs +312 -0
  819. package/src/runtime/office/portable/portable-validation.mjs +615 -1098
  820. package/src/runtime/office/portable/portable-xlsx-operations.mjs +1002 -0
  821. package/src/runtime/office/portable/portable-xlsx-sheet-edits.mjs +531 -0
  822. package/src/runtime/office/portable/portable-xlsx.mjs +103 -1387
  823. package/src/runtime/office/portable/portable-xml.mjs +4 -8
  824. package/src/runtime/office/portable/pptx-relations.mjs +1 -1
  825. package/src/runtime/office/portable/review-editability.mjs +3 -1
  826. package/src/runtime/office/portable/text-metrics.mjs +121 -84
  827. package/src/runtime/office/portable/xlsx-assertions.mjs +1 -1
  828. package/src/runtime/office/portable/xlsx-contract.mjs +132 -106
  829. package/src/runtime/office/portable/xlsx-formula-audit.mjs +246 -118
  830. package/src/runtime/office/portable/xlsx-formula-engine.mjs +549 -0
  831. package/src/runtime/office/portable/xlsx-recalculate.mjs +278 -0
  832. package/src/runtime/office/portable/xlsx-sheet-hygiene.mjs +98 -26
  833. package/src/runtime/office/quality/assurance-checklist.mjs +82 -60
  834. package/src/runtime/office/quality/assurance-issue.mjs +5 -0
  835. package/src/runtime/office/quality/assurance-structure-docx.mjs +205 -0
  836. package/src/runtime/office/quality/assurance-structure-pptx.mjs +762 -0
  837. package/src/runtime/office/quality/assurance-structure-xlsx.mjs +256 -0
  838. package/src/runtime/office/quality/assurance-structure.mjs +4 -798
  839. package/src/runtime/office/quality/assurance-trust.mjs +44 -49
  840. package/src/runtime/office/quality/design-aesthetics.mjs +3 -6
  841. package/src/runtime/office/quality/design-deck-diversity.mjs +85 -48
  842. package/src/runtime/office/quality/design-review-critique.mjs +7 -6
  843. package/src/runtime/office/quality/design-review.mjs +10 -13
  844. package/src/runtime/office/quality/document-acceptance.mjs +8 -7
  845. package/src/runtime/office/quality/inline-audit.mjs +2 -1
  846. package/src/runtime/office/quality/presentation-acceptance.mjs +3 -7
  847. package/src/runtime/office/quality/quality-pipeline.mjs +49 -11
  848. package/src/runtime/office/quality/quality-score.mjs +5 -7
  849. package/src/runtime/office/quality/visual-diff.mjs +0 -2
  850. package/src/runtime/shared/abort-controller.mjs +1 -1
  851. package/src/runtime/shared/agent-reap-state.mjs +35 -0
  852. package/src/runtime/shared/atomic-file.mjs +5 -5
  853. package/src/runtime/shared/automation-attachments.mjs +5 -4
  854. package/src/runtime/shared/background-tasks.mjs +44 -9
  855. package/src/runtime/shared/boot-profile.mjs +6 -2
  856. package/src/runtime/shared/buffered-appender.mjs +1 -1
  857. package/src/runtime/shared/child-spawn-gate.mjs +2 -2
  858. package/src/runtime/shared/code-point-order.mjs +5 -0
  859. package/src/runtime/shared/config-patch.mjs +9 -12
  860. package/src/runtime/shared/config.mjs +5 -5
  861. package/src/runtime/shared/error-presentation.mjs +2 -8
  862. package/src/runtime/shared/extension-scopes.mjs +3 -1
  863. package/src/runtime/shared/file-lock.mjs +2 -1
  864. package/src/runtime/shared/injected-display-text.mjs +38 -0
  865. package/src/runtime/shared/llm/cost.mjs +6 -9
  866. package/src/runtime/shared/llm/http-agent.mjs +1 -1
  867. package/src/runtime/shared/llm/index.mjs +1 -1
  868. package/src/runtime/shared/llm/reasoning-usage.mjs +42 -0
  869. package/src/runtime/shared/llm/usage-ledger-import.mjs +3 -1
  870. package/src/runtime/shared/llm/usage-ledger-repair.mjs +6 -14
  871. package/src/runtime/shared/llm/usage-ledger.mjs +31 -30
  872. package/src/runtime/shared/llm/usage-rollup.mjs +8 -2
  873. package/src/runtime/shared/loopback-listener.mjs +1 -6
  874. package/src/runtime/shared/open-url.mjs +1 -1
  875. package/src/runtime/shared/orchestration.mjs +2 -2
  876. package/src/runtime/shared/plugin-paths.mjs +3 -3
  877. package/src/runtime/shared/process-shutdown.mjs +4 -4
  878. package/src/runtime/shared/provider-accounts.mjs +109 -11
  879. package/src/runtime/shared/resource-admission.mjs +32 -8
  880. package/src/runtime/shared/review-diff.mjs +34 -0
  881. package/src/runtime/shared/schedules-db.mjs +1 -1
  882. package/src/runtime/shared/schema-value-error.mjs +3 -5
  883. package/src/runtime/shared/skill-selection.mjs +3 -1
  884. package/src/runtime/shared/staged-child-result.mjs +0 -2
  885. package/src/runtime/shared/staged-update.mjs +1 -1
  886. package/src/runtime/shared/task-notification-envelope.mjs +130 -58
  887. package/src/runtime/shared/time-format.mjs +6 -5
  888. package/src/runtime/shared/tool-card-model/agent-surface.mjs +170 -0
  889. package/src/runtime/shared/tool-card-model/aggregate-card.mjs +66 -0
  890. package/src/runtime/shared/tool-card-model/background-task.mjs +171 -0
  891. package/src/runtime/shared/tool-card-model/card-detail.mjs +115 -0
  892. package/src/runtime/shared/tool-card-model/card-header.mjs +48 -0
  893. package/src/runtime/shared/tool-card-model/card-input.mjs +85 -0
  894. package/src/runtime/shared/tool-card-model/card-status.mjs +83 -0
  895. package/src/runtime/shared/tool-card-model/displayed-result.mjs +44 -0
  896. package/src/runtime/shared/tool-card-model/generic-detail.mjs +79 -0
  897. package/src/runtime/shared/tool-card-model/git-result.mjs +9 -0
  898. package/src/runtime/shared/tool-card-model/inline-text.mjs +78 -0
  899. package/src/runtime/shared/tool-card-model/shell-surface.mjs +45 -0
  900. package/src/runtime/shared/tool-card-model/terminal-status.mjs +109 -0
  901. package/src/runtime/shared/tool-card-model.golden-cases.mjs +208 -0
  902. package/src/runtime/shared/tool-card-model.golden.json +964 -0
  903. package/src/runtime/shared/tool-card-model.mjs +110 -893
  904. package/src/runtime/shared/tool-execution-contract.mjs +104 -60
  905. package/src/runtime/shared/tool-primitives.mjs +2 -1
  906. package/src/runtime/shared/tool-result-summary.mjs +244 -233
  907. package/src/runtime/shared/tool-surface.mjs +33 -461
  908. package/src/runtime/shared/tool-work-units.mjs +504 -0
  909. package/src/runtime/shared/transcript-writer/rotation.mjs +90 -0
  910. package/src/runtime/shared/transcript-writer/session-record.mjs +49 -0
  911. package/src/runtime/shared/transcript-writer/transcript-file.mjs +108 -0
  912. package/src/runtime/shared/transcript-writer.mjs +35 -239
  913. package/src/runtime/shared/transport-error-text.mjs +53 -66
  914. package/src/runtime/shared/turn-snapshot-store.mjs +14 -0
  915. package/src/runtime/shared/turn-snapshot.mjs +31 -16
  916. package/src/runtime/shared/turn-worktree-snapshot.mjs +120 -13
  917. package/src/runtime/shared/update-checker.mjs +1 -1
  918. package/src/runtime/shared/user-cwd.mjs +4 -4
  919. package/src/runtime/shared/user-data-guard.mjs +22 -7
  920. package/src/runtime/shared/webhooks-db.mjs +1 -1
  921. package/src/runtime/tidy/extract.mjs +1 -1
  922. package/src/runtime/tidy/history-comment.mjs +23 -2
  923. package/src/runtime/tidy/languages.mjs +20 -15
  924. package/src/runtime/tidy/report.mjs +169 -44
  925. package/src/runtime/tidy/resolve.mjs +3 -6
  926. package/src/runtime/tidy/rules/kotlin/no-history-comment.yml +1 -1
  927. package/src/runtime/tidy/rules/kotlin/todo-marker.yml +1 -1
  928. package/src/runtime/tidy/run-engines.mjs +29 -14
  929. package/src/runtime/tidy/runners/biome.mjs +11 -13
  930. package/src/runtime/tidy/runners/mago.mjs +3 -1
  931. package/src/runtime/tidy/structural.mjs +67 -47
  932. package/src/runtime/tidy/tool-defs.mjs +26 -6
  933. package/src/runtime/tidy/tool.mjs +227 -41
  934. package/src/runtime/web-search/index.mjs +7 -9
  935. package/src/runtime/web-search/lib/cache.mjs +1 -1
  936. package/src/runtime/web-search/lib/config.mjs +3 -3
  937. package/src/runtime/web-search/lib/document-content.mjs +3 -5
  938. package/src/runtime/web-search/lib/fetch-pipeline.mjs +3 -1
  939. package/src/runtime/web-search/lib/formatter.mjs +16 -9
  940. package/src/runtime/web-search/lib/http-fetch.mjs +3 -2
  941. package/src/runtime/web-search/lib/ssrf-guard.mjs +4 -9
  942. package/src/runtime/web-search/lib/state.mjs +0 -4
  943. package/src/runtime/web-search/lib/web-tools.mjs +1 -4
  944. package/src/session-runtime/agent-tool-routing.mjs +3 -5
  945. package/src/session-runtime/boot/apis.mjs +487 -0
  946. package/src/session-runtime/boot/begin.mjs +123 -0
  947. package/src/session-runtime/boot/config.mjs +108 -0
  948. package/src/session-runtime/boot/facade.mjs +88 -0
  949. package/src/session-runtime/boot/infrastructure.mjs +250 -0
  950. package/src/session-runtime/boot/providers.mjs +240 -0
  951. package/src/session-runtime/boot/session.mjs +125 -0
  952. package/src/session-runtime/boot/shared.mjs +33 -0
  953. package/src/session-runtime/boot/tools.mjs +250 -0
  954. package/src/session-runtime/builtin-features.mjs +1 -1
  955. package/src/session-runtime/config-helpers.mjs +26 -44
  956. package/src/session-runtime/config-lifecycle/config-writers.mjs +152 -0
  957. package/src/session-runtime/config-lifecycle/output-style-cache.mjs +42 -0
  958. package/src/session-runtime/config-lifecycle.mjs +26 -184
  959. package/src/session-runtime/context-inspection.mjs +390 -145
  960. package/src/session-runtime/context-status-cache.mjs +126 -0
  961. package/src/session-runtime/context-status-inspection.mjs +61 -0
  962. package/src/session-runtime/context-status-shape.mjs +271 -0
  963. package/src/session-runtime/context-status.mjs +40 -370
  964. package/src/session-runtime/cwd-plugins/core-memory-context.mjs +60 -0
  965. package/src/session-runtime/cwd-plugins/cwd-apply.mjs +83 -0
  966. package/src/session-runtime/cwd-plugins/plugin-status.mjs +124 -0
  967. package/src/session-runtime/cwd-plugins.mjs +16 -252
  968. package/src/session-runtime/fs-utils.mjs +11 -1
  969. package/src/session-runtime/goal-control.mjs +154 -0
  970. package/src/session-runtime/goal-deadlines.mjs +4 -4
  971. package/src/session-runtime/goal-mutations.mjs +257 -0
  972. package/src/session-runtime/goal-runtime.mjs +56 -794
  973. package/src/session-runtime/goal-state.mjs +18 -15
  974. package/src/session-runtime/goal-store.mjs +118 -0
  975. package/src/session-runtime/goal-tasks.mjs +3 -1
  976. package/src/session-runtime/goal-text.mjs +30 -19
  977. package/src/session-runtime/goal-title.mjs +52 -0
  978. package/src/session-runtime/goal-tool-exec.mjs +156 -0
  979. package/src/session-runtime/goal-turns.mjs +166 -0
  980. package/src/session-runtime/internal-tool-executor/bridge-tools.mjs +63 -0
  981. package/src/session-runtime/internal-tool-executor/feature-tools.mjs +42 -0
  982. package/src/session-runtime/internal-tool-executor/knowledge-tools.mjs +59 -0
  983. package/src/session-runtime/internal-tool-executor/workspace-tools.mjs +63 -0
  984. package/src/session-runtime/internal-tool-executor.mjs +40 -189
  985. package/src/session-runtime/lifecycle/inheritance.mjs +192 -0
  986. package/src/session-runtime/lifecycle/memory-ingest.mjs +42 -0
  987. package/src/session-runtime/lifecycle/session-catalog.mjs +98 -0
  988. package/src/session-runtime/lifecycle/session-switch/context-switch.mjs +70 -0
  989. package/src/session-runtime/lifecycle/session-switch/resume.mjs +158 -0
  990. package/src/session-runtime/lifecycle/session-switch/session-delete.mjs +93 -0
  991. package/src/session-runtime/lifecycle/session-switch.mjs +45 -0
  992. package/src/session-runtime/lifecycle/shared.mjs +32 -0
  993. package/src/session-runtime/lifecycle/teardown/runtime-stops.mjs +94 -0
  994. package/src/session-runtime/lifecycle/teardown/session-close.mjs +87 -0
  995. package/src/session-runtime/lifecycle/teardown.mjs +164 -0
  996. package/src/session-runtime/lifecycle-api.mjs +36 -850
  997. package/src/session-runtime/mcp-glue/connect.mjs +159 -0
  998. package/src/session-runtime/mcp-glue/server-catalog.mjs +102 -0
  999. package/src/session-runtime/mcp-glue/server-input.mjs +79 -0
  1000. package/src/session-runtime/mcp-glue.mjs +21 -322
  1001. package/src/session-runtime/model-route/route-persist.mjs +49 -0
  1002. package/src/session-runtime/model-route/route-tuning.mjs +60 -0
  1003. package/src/session-runtime/model-route/set-route.mjs +156 -0
  1004. package/src/session-runtime/model-route/web-search-route.mjs +103 -0
  1005. package/src/session-runtime/model-route-api.mjs +21 -304
  1006. package/src/session-runtime/native-web-search/routes.mjs +74 -0
  1007. package/src/session-runtime/native-web-search/tool-shape.mjs +115 -0
  1008. package/src/session-runtime/native-web-search.mjs +83 -237
  1009. package/src/session-runtime/orchestration.mjs +10 -5
  1010. package/src/session-runtime/plugin-mcp.mjs +7 -58
  1011. package/src/session-runtime/prewarm/channel-start.mjs +95 -0
  1012. package/src/session-runtime/prewarm/code-graph-prewarm.mjs +94 -0
  1013. package/src/session-runtime/prewarm/tool-runtime-warmup.mjs +79 -0
  1014. package/src/session-runtime/prewarm.mjs +13 -243
  1015. package/src/session-runtime/provider-auth/accounts.mjs +79 -0
  1016. package/src/session-runtime/provider-auth/login.mjs +85 -0
  1017. package/src/session-runtime/provider-auth/refresh.mjs +57 -0
  1018. package/src/session-runtime/provider-auth/setup.mjs +51 -0
  1019. package/src/session-runtime/provider-auth-api.mjs +18 -251
  1020. package/src/session-runtime/provider-models/catalog-load.mjs +90 -0
  1021. package/src/session-runtime/provider-models/model-meta.mjs +77 -0
  1022. package/src/session-runtime/provider-models/row-hydration.mjs +46 -0
  1023. package/src/session-runtime/provider-models/web-search-catalog.mjs +111 -0
  1024. package/src/session-runtime/provider-models.mjs +71 -286
  1025. package/src/session-runtime/provider-request-snapshot.mjs +1 -1
  1026. package/src/session-runtime/provider-usage.mjs +3 -3
  1027. package/src/session-runtime/quick-model-rows/model-meta.mjs +32 -0
  1028. package/src/session-runtime/quick-model-rows/provider-rows.mjs +77 -0
  1029. package/src/session-runtime/quick-model-rows/web-search-rows.mjs +144 -0
  1030. package/src/session-runtime/quick-model-rows.mjs +27 -221
  1031. package/src/session-runtime/resource-api.mjs +28 -522
  1032. package/src/session-runtime/resource-extension-sync.mjs +89 -0
  1033. package/src/session-runtime/resource-mcp-api.mjs +199 -0
  1034. package/src/session-runtime/resource-plugins-api.mjs +85 -0
  1035. package/src/session-runtime/resource-recall-api.mjs +92 -0
  1036. package/src/session-runtime/resource-scope-decorate.mjs +58 -0
  1037. package/src/session-runtime/resource-skills-api.mjs +50 -0
  1038. package/src/session-runtime/route-resolution.mjs +71 -0
  1039. package/src/session-runtime/route-state.mjs +86 -0
  1040. package/src/session-runtime/runtime-bootstrap.mjs +3 -3
  1041. package/src/session-runtime/runtime-core.mjs +37 -1375
  1042. package/src/session-runtime/self-update.mjs +2 -3
  1043. package/src/session-runtime/session-create/materialize.mjs +77 -0
  1044. package/src/session-runtime/session-create/route-prep.mjs +49 -0
  1045. package/src/session-runtime/session-create/session-options.mjs +73 -0
  1046. package/src/session-runtime/session-create/session-start-hook.mjs +39 -0
  1047. package/src/session-runtime/session-create.mjs +69 -0
  1048. package/src/session-runtime/session-hooks.mjs +3 -4
  1049. package/src/session-runtime/session-lifecycle.mjs +43 -417
  1050. package/src/session-runtime/session-text.mjs +7 -37
  1051. package/src/session-runtime/session-transcript.mjs +2 -4
  1052. package/src/session-runtime/session-turn-api.mjs +37 -757
  1053. package/src/session-runtime/settings-api.mjs +29 -528
  1054. package/src/session-runtime/settings-builtin-tools-api.mjs +191 -0
  1055. package/src/session-runtime/settings-compaction-api.mjs +161 -0
  1056. package/src/session-runtime/settings-profile-api.mjs +100 -0
  1057. package/src/session-runtime/settings-system-api.mjs +82 -0
  1058. package/src/session-runtime/setup-tool/executor.mjs +354 -315
  1059. package/src/session-runtime/setup-tool/extended-actions.mjs +42 -16
  1060. package/src/session-runtime/setup-tool/settings-contract.mjs +99 -39
  1061. package/src/session-runtime/setup-tool/tool-defs.mjs +22 -4
  1062. package/src/session-runtime/setup-tool/ui-requests.mjs +25 -7
  1063. package/src/session-runtime/skill-tool-loading.mjs +15 -8
  1064. package/src/session-runtime/skills-api.mjs +7 -8
  1065. package/src/session-runtime/tool-catalog-data.mjs +1 -2
  1066. package/src/session-runtime/tool-catalog-schema.mjs +1 -1
  1067. package/src/session-runtime/tool-catalog.mjs +21 -19
  1068. package/src/session-runtime/tool-defs.mjs +2 -2
  1069. package/src/session-runtime/tool-policy-refresh.mjs +33 -21
  1070. package/src/session-runtime/tool-profile.mjs +0 -1
  1071. package/src/session-runtime/tool-surface.mjs +6 -4
  1072. package/src/session-runtime/turn/agent-ops.mjs +98 -0
  1073. package/src/session-runtime/turn/session-ops.mjs +132 -0
  1074. package/src/session-runtime/turn/share-ops.mjs +73 -0
  1075. package/src/session-runtime/turn/turn-run/ask-callbacks.mjs +90 -0
  1076. package/src/session-runtime/turn/turn-run/snapshot-tracker.mjs +51 -0
  1077. package/src/session-runtime/turn/turn-run/transcript.mjs +47 -0
  1078. package/src/session-runtime/turn/turn-run/turn-open.mjs +60 -0
  1079. package/src/session-runtime/turn/turn-run/turn-prepare.mjs +142 -0
  1080. package/src/session-runtime/turn/turn-run/turn-settle.mjs +105 -0
  1081. package/src/session-runtime/turn/turn-run/turn-timing.mjs +52 -0
  1082. package/src/session-runtime/turn/turn-run.mjs +121 -0
  1083. package/src/session-runtime/usage-stats-api.mjs +48 -33
  1084. package/src/session-runtime/warmup/catalog-warmup.mjs +34 -0
  1085. package/src/session-runtime/warmup/provider-warmups.mjs +105 -0
  1086. package/src/session-runtime/warmup/statusline-usage-warmup.mjs +82 -0
  1087. package/src/session-runtime/warmup/timer-arm.mjs +22 -0
  1088. package/src/session-runtime/warmup-schedulers.mjs +11 -232
  1089. package/src/session-runtime/workflow/agents.mjs +91 -0
  1090. package/src/session-runtime/workflow/context.mjs +89 -0
  1091. package/src/session-runtime/workflow/packs.mjs +68 -0
  1092. package/src/session-runtime/workflow-agents-api/agent-editor.mjs +152 -0
  1093. package/src/session-runtime/workflow-agents-api/agent-route.mjs +98 -0
  1094. package/src/session-runtime/workflow-agents-api/onboarding.mjs +113 -0
  1095. package/src/session-runtime/workflow-agents-api/shared.mjs +23 -0
  1096. package/src/session-runtime/workflow-agents-api/style-and-mode.mjs +61 -0
  1097. package/src/session-runtime/workflow-agents-api/workflow-packs.mjs +117 -0
  1098. package/src/session-runtime/workflow-agents-api.mjs +16 -515
  1099. package/src/session-runtime/workflow-ids.mjs +57 -0
  1100. package/src/session-runtime/workflow.mjs +17 -289
  1101. package/src/standalone/agent-task-status.mjs +8 -2
  1102. package/src/standalone/agent-tool/close-flow.mjs +163 -0
  1103. package/src/standalone/agent-tool/execute.mjs +223 -0
  1104. package/src/standalone/agent-tool/helpers.mjs +3 -17
  1105. package/src/standalone/agent-tool/job-views/agent-list.mjs +71 -0
  1106. package/src/standalone/agent-tool/job-views/job-lookup.mjs +84 -0
  1107. package/src/standalone/agent-tool/job-views/job-render.mjs +98 -0
  1108. package/src/standalone/agent-tool/job-views/session-progress.mjs +81 -0
  1109. package/src/standalone/agent-tool/job-views/spawn-meta.mjs +62 -0
  1110. package/src/standalone/agent-tool/job-views.mjs +24 -373
  1111. package/src/standalone/agent-tool/lead-worker-index/index-file.mjs +45 -0
  1112. package/src/standalone/agent-tool/lead-worker-index/lead-rows.mjs +39 -0
  1113. package/src/standalone/agent-tool/lead-worker-index/reap-timers.mjs +31 -0
  1114. package/src/standalone/agent-tool/lead-worker-index/row-settlement.mjs +59 -0
  1115. package/src/standalone/agent-tool/lead-worker-index.mjs +28 -163
  1116. package/src/standalone/agent-tool/notify.mjs +6 -6
  1117. package/src/standalone/agent-tool/provider-init.mjs +3 -4
  1118. package/src/standalone/agent-tool/render.mjs +26 -22
  1119. package/src/standalone/agent-tool/send-flow.mjs +186 -0
  1120. package/src/standalone/agent-tool/spawn-flow/deferred-spawn.mjs +97 -0
  1121. package/src/standalone/agent-tool/spawn-flow/job-start.mjs +83 -0
  1122. package/src/standalone/agent-tool/spawn-flow/spawn-prep.mjs +179 -0
  1123. package/src/standalone/agent-tool/spawn-flow/spawn-run.mjs +222 -0
  1124. package/src/standalone/agent-tool/spawn-flow.mjs +30 -557
  1125. package/src/standalone/agent-tool/tag-maps.mjs +29 -0
  1126. package/src/standalone/agent-tool/tag-registry/tag-lookup.mjs +106 -0
  1127. package/src/standalone/agent-tool/tag-registry/tag-refresh.mjs +34 -0
  1128. package/src/standalone/agent-tool/tag-registry.mjs +63 -524
  1129. package/src/standalone/agent-tool/terminal-reaper/reap-timers.mjs +142 -0
  1130. package/src/standalone/agent-tool/terminal-reaper/row-helpers.mjs +25 -0
  1131. package/src/standalone/agent-tool/terminal-reaper/scan-admission.mjs +89 -0
  1132. package/src/standalone/agent-tool/terminal-reaper/stale-rows.mjs +52 -0
  1133. package/src/standalone/agent-tool/terminal-reaper/tombstones.mjs +113 -0
  1134. package/src/standalone/agent-tool/terminal-reaper.mjs +46 -0
  1135. package/src/standalone/agent-tool/terminal-trace.mjs +40 -0
  1136. package/src/standalone/agent-tool/tool-def.mjs +1 -2
  1137. package/src/standalone/agent-tool/turn-review.mjs +27 -0
  1138. package/src/standalone/agent-tool/worker-index/mutation-batch.mjs +41 -0
  1139. package/src/standalone/agent-tool/worker-index/row-liveness.mjs +65 -0
  1140. package/src/standalone/agent-tool/worker-index/row-shape.mjs +109 -0
  1141. package/src/standalone/agent-tool/worker-index/row-store.mjs +100 -0
  1142. package/src/standalone/agent-tool/worker-index.mjs +66 -345
  1143. package/src/standalone/agent-tool/worker-rows.mjs +34 -9
  1144. package/src/standalone/agent-tool.mjs +61 -650
  1145. package/src/standalone/agent-watchdog-registry.mjs +36 -8
  1146. package/src/standalone/channel-admin.mjs +3 -5
  1147. package/src/standalone/channel-client/daemon-request.mjs +136 -0
  1148. package/src/standalone/channel-client/notify-stream.mjs +130 -0
  1149. package/src/standalone/channel-client/reconnect.mjs +113 -0
  1150. package/src/standalone/channel-client/registration.mjs +87 -0
  1151. package/src/standalone/channel-client.mjs +58 -460
  1152. package/src/standalone/channel-transport/call-dispatch.mjs +209 -0
  1153. package/src/standalone/channel-transport/client-registry/client-grace.mjs +69 -0
  1154. package/src/standalone/channel-transport/client-registry/registration-replays.mjs +96 -0
  1155. package/src/standalone/channel-transport/client-registry/sse-attach.mjs +44 -0
  1156. package/src/standalone/channel-transport/client-registry.mjs +228 -0
  1157. package/src/standalone/channel-transport/http-routes.mjs +171 -0
  1158. package/src/standalone/channel-transport/remote-binding.mjs +168 -0
  1159. package/src/standalone/channel-transport/remote-notify.mjs +138 -0
  1160. package/src/standalone/channel-transport.mjs +111 -982
  1161. package/src/standalone/channel-worker/client-heartbeat.mjs +103 -0
  1162. package/src/standalone/channel-worker/daemon-attach.mjs +157 -0
  1163. package/src/standalone/channel-worker/daemon-spawn.mjs +93 -0
  1164. package/src/standalone/channel-worker.mjs +55 -342
  1165. package/src/standalone/daemon-boot-coordinator.mjs +6 -2
  1166. package/src/standalone/daemon-crash-capture/paths.mjs +16 -0
  1167. package/src/standalone/daemon-crash-capture/retention.mjs +217 -0
  1168. package/src/standalone/daemon-crash-capture/spawn-capture.mjs +370 -0
  1169. package/src/standalone/daemon-crash-capture.mjs +14 -568
  1170. package/src/standalone/daemon.mjs +0 -3
  1171. package/src/standalone/desktop-service-registry.mjs +4 -7
  1172. package/src/standalone/fair-call-scheduler/owner-groups.mjs +90 -0
  1173. package/src/standalone/fair-call-scheduler/queue-item.mjs +21 -0
  1174. package/src/standalone/fair-call-scheduler.mjs +94 -167
  1175. package/src/standalone/hook-bus/command-handler.mjs +1 -1
  1176. package/src/standalone/hook-bus/config-loader.mjs +130 -0
  1177. package/src/standalone/hook-bus/config.mjs +8 -9
  1178. package/src/standalone/hook-bus/event-log.mjs +30 -0
  1179. package/src/standalone/hook-bus/event-runner.mjs +175 -0
  1180. package/src/standalone/hook-bus/rule-store.mjs +149 -0
  1181. package/src/standalone/hook-bus/tool-gate.mjs +72 -0
  1182. package/src/standalone/hook-bus.mjs +65 -511
  1183. package/src/standalone/memory-runtime-proxy/calls.mjs +121 -0
  1184. package/src/standalone/memory-runtime-proxy/client-registry.mjs +93 -0
  1185. package/src/standalone/memory-runtime-proxy/daemon-spawn.mjs +158 -0
  1186. package/src/standalone/memory-runtime-proxy/discovery.mjs +98 -0
  1187. package/src/standalone/memory-runtime-proxy/owner-claim.mjs +67 -0
  1188. package/src/standalone/memory-runtime-proxy/rpc.mjs +122 -0
  1189. package/src/standalone/memory-runtime-proxy/start.mjs +51 -0
  1190. package/src/standalone/memory-runtime-proxy/state.mjs +21 -0
  1191. package/src/standalone/memory-runtime-proxy/tool-wire.mjs +32 -0
  1192. package/src/standalone/memory-runtime-proxy.mjs +52 -712
  1193. package/src/standalone/opencode-go-login.mjs +1 -1
  1194. package/src/standalone/plugin-admin.mjs +4 -9
  1195. package/src/standalone/provider-admin.mjs +186 -161
  1196. package/src/standalone/seeds.mjs +132 -5
  1197. package/src/standalone/session-client/frame-stream.mjs +125 -0
  1198. package/src/standalone/session-client/stream-reconnect.mjs +119 -0
  1199. package/src/standalone/session-client.mjs +83 -259
  1200. package/src/standalone/session-frame-stream.mjs +3 -6
  1201. package/src/standalone/session-protocol.mjs +1 -0
  1202. package/src/standalone/session-proxy/project-routes.mjs +25 -0
  1203. package/src/standalone/session-proxy/projection.mjs +112 -0
  1204. package/src/standalone/session-proxy/proxy-view.mjs +50 -0
  1205. package/src/standalone/session-proxy/remote-actions.mjs +121 -0
  1206. package/src/standalone/session-proxy/resync.mjs +67 -0
  1207. package/src/standalone/session-proxy/transitions.mjs +99 -0
  1208. package/src/standalone/session-proxy/transport-calls.mjs +121 -0
  1209. package/src/standalone/session-proxy.mjs +49 -527
  1210. package/src/standalone/session-runtime-agent-control-client.mjs +2 -4
  1211. package/src/standalone/session-runtime-host.mjs +6 -110
  1212. package/src/standalone/session-runtime-inline-host/agent-dispatch.mjs +66 -0
  1213. package/src/standalone/session-runtime-inline-host/boot-loaders.mjs +96 -0
  1214. package/src/standalone/session-runtime-inline-host/runtime-records.mjs +66 -0
  1215. package/src/standalone/session-runtime-inline-host.mjs +27 -182
  1216. package/src/standalone/session-runtime-worker.mjs +2 -6
  1217. package/src/standalone/session-runtime-workload.mjs +98 -0
  1218. package/src/standalone/session-service/agent-tree/agent-cancel.mjs +79 -0
  1219. package/src/standalone/session-service/agent-tree/agent-registry.mjs +73 -0
  1220. package/src/standalone/session-service/agent-tree/agent-rehydrate.mjs +163 -0
  1221. package/src/standalone/session-service/agent-tree/agent-turns.mjs +122 -0
  1222. package/src/standalone/session-service/agent-tree.mjs +91 -388
  1223. package/src/standalone/session-service/entries/external-binding.mjs +60 -0
  1224. package/src/standalone/session-service/entries/lifecycle.mjs +140 -0
  1225. package/src/standalone/session-service/entries/session-loads.mjs +109 -0
  1226. package/src/standalone/session-service/entries.mjs +95 -0
  1227. package/src/standalone/session-service/projection/address-index.mjs +54 -0
  1228. package/src/standalone/session-service/projection/external-views.mjs +91 -0
  1229. package/src/standalone/session-service/projection/frames.mjs +79 -0
  1230. package/src/standalone/session-service/projection/revisions.mjs +100 -0
  1231. package/src/standalone/session-service/projection.mjs +36 -274
  1232. package/src/standalone/session-service/retention.mjs +158 -0
  1233. package/src/standalone/session-service/session-calls/session-action.mjs +97 -0
  1234. package/src/standalone/session-service/session-calls/session-turns.mjs +165 -0
  1235. package/src/standalone/session-service/session-calls/session-views.mjs +192 -0
  1236. package/src/standalone/session-service/session-calls.mjs +59 -0
  1237. package/src/standalone/session-service/viewers.mjs +111 -0
  1238. package/src/standalone/session-service.mjs +135 -992
  1239. package/src/standalone/session-state-projection.mjs +5 -1
  1240. package/src/standalone/session-transport/call-lanes.mjs +113 -0
  1241. package/src/standalone/session-transport/call-route.mjs +104 -0
  1242. package/src/standalone/session-transport/client-registry/client-grace.mjs +81 -0
  1243. package/src/standalone/session-transport/client-registry/registration-replays.mjs +69 -0
  1244. package/src/standalone/session-transport/client-registry.mjs +129 -0
  1245. package/src/standalone/session-transport/routes.mjs +185 -0
  1246. package/src/standalone/session-transport.mjs +104 -574
  1247. package/src/standalone/sse-frames.mjs +27 -0
  1248. package/src/standalone/usage-dashboard-model.mjs +28 -22
  1249. package/src/standalone/usage-dashboard.mjs +6 -4
  1250. package/src/standalone/usage-stats-hours.mjs +2 -6
  1251. package/src/standalone/usage-stats-model.mjs +22 -29
  1252. package/src/standalone/usage-stats-period.mjs +83 -22
  1253. package/src/tui/App.jsx +0 -6
  1254. package/src/tui/app/app-format.mjs +7 -1
  1255. package/src/tui/app/app-view.jsx +253 -226
  1256. package/src/tui/app/clipboard.mjs +1 -1
  1257. package/src/tui/app/core-memory-picker.mjs +10 -14
  1258. package/src/tui/app/create-app-pickers.mjs +2 -2
  1259. package/src/tui/app/doctor.mjs +158 -135
  1260. package/src/tui/app/extension-pickers/mcp-servers-picker.mjs +115 -0
  1261. package/src/tui/app/extension-pickers/plugins-pickers.mjs +236 -0
  1262. package/src/tui/app/extension-pickers/scope-note.mjs +30 -0
  1263. package/src/tui/app/extension-pickers/skills-pickers.mjs +201 -0
  1264. package/src/tui/app/extension-pickers.mjs +29 -532
  1265. package/src/tui/app/input-parsers.mjs +6 -5
  1266. package/src/tui/app/maintenance-pickers/auto-clear-picker.mjs +167 -0
  1267. package/src/tui/app/maintenance-pickers/profile-picker.mjs +147 -0
  1268. package/src/tui/app/maintenance-pickers/update-picker.mjs +175 -0
  1269. package/src/tui/app/maintenance-pickers.mjs +18 -449
  1270. package/src/tui/app/model-options.mjs +5 -39
  1271. package/src/tui/app/model-picker/catalog-load.mjs +101 -0
  1272. package/src/tui/app/model-picker/model-footer.mjs +79 -0
  1273. package/src/tui/app/model-picker/provider-models-list.mjs +115 -0
  1274. package/src/tui/app/model-picker/route-selection.mjs +227 -0
  1275. package/src/tui/app/model-picker.mjs +57 -460
  1276. package/src/tui/app/onboarding/models-step.mjs +106 -0
  1277. package/src/tui/app/onboarding/persist.mjs +49 -0
  1278. package/src/tui/app/onboarding/role-model-picker.mjs +141 -0
  1279. package/src/tui/app/onboarding/step-data.mjs +65 -0
  1280. package/src/tui/app/onboarding-steps.mjs +45 -346
  1281. package/src/tui/app/panel-surface.mjs +2 -1
  1282. package/src/tui/app/project-picker/create-flow.mjs +76 -0
  1283. package/src/tui/app/project-picker/picker-state.mjs +78 -0
  1284. package/src/tui/app/project-picker/project-service.mjs +61 -0
  1285. package/src/tui/app/project-picker.mjs +29 -221
  1286. package/src/tui/app/prompt-handlers/history-navigation.mjs +32 -0
  1287. package/src/tui/app/prompt-handlers/paste-pipeline.mjs +72 -0
  1288. package/src/tui/app/prompt-handlers/use-prompt-history-nav.mjs +31 -0
  1289. package/src/tui/app/prompt-handlers/use-prompt-interrupt.mjs +102 -0
  1290. package/src/tui/app/prompt-handlers/use-prompt-paste.mjs +48 -0
  1291. package/src/tui/app/prompt-submit/chat-submit.mjs +66 -0
  1292. package/src/tui/app/prompt-submit/panel-write.mjs +54 -0
  1293. package/src/tui/app/prompt-submit/provider-prompts.mjs +103 -0
  1294. package/src/tui/app/prompt-submit/settings-prompts.mjs +337 -0
  1295. package/src/tui/app/prompt-submit.mjs +21 -554
  1296. package/src/tui/app/provider-setup/api-key-actions.mjs +164 -0
  1297. package/src/tui/app/provider-setup/oauth-actions.mjs +230 -0
  1298. package/src/tui/app/provider-setup/provider-items.mjs +80 -0
  1299. package/src/tui/app/provider-setup-picker.mjs +81 -499
  1300. package/src/tui/app/resume-picker.mjs +2 -5
  1301. package/src/tui/app/route-pickers/agents-picker.mjs +155 -0
  1302. package/src/tui/app/route-pickers/output-style-picker.mjs +123 -0
  1303. package/src/tui/app/route-pickers/workflow-picker.mjs +84 -0
  1304. package/src/tui/app/route-pickers.mjs +13 -322
  1305. package/src/tui/app/settings-picker/settings-navigation.mjs +69 -0
  1306. package/src/tui/app/settings-picker/settings-rows.mjs +200 -0
  1307. package/src/tui/app/settings-picker/settings-toggles.mjs +190 -0
  1308. package/src/tui/app/settings-picker.mjs +42 -431
  1309. package/src/tui/app/shell-layout/panel-transition.mjs +140 -0
  1310. package/src/tui/app/shell-layout/row-budgets.mjs +268 -0
  1311. package/src/tui/app/shell-layout/surfaces.mjs +93 -0
  1312. package/src/tui/app/shell-layout/viewport.mjs +151 -0
  1313. package/src/tui/app/shell-layout.mjs +34 -568
  1314. package/src/tui/app/slash-dispatch/panel-commands.mjs +84 -0
  1315. package/src/tui/app/slash-dispatch/route-commands.mjs +191 -0
  1316. package/src/tui/app/slash-dispatch/session-commands.mjs +128 -0
  1317. package/src/tui/app/slash-dispatch/slash-panel.mjs +43 -0
  1318. package/src/tui/app/slash-dispatch.mjs +19 -449
  1319. package/src/tui/app/theme-effort-pickers.mjs +4 -11
  1320. package/src/tui/app/transcript-anchor-lock.mjs +120 -0
  1321. package/src/tui/app/transcript-anchor-sync.mjs +173 -0
  1322. package/src/tui/app/transcript-measure.mjs +245 -0
  1323. package/src/tui/app/transcript-row-estimate.mjs +10 -34
  1324. package/src/tui/app/transcript-scroll-anchor.mjs +42 -0
  1325. package/src/tui/app/transcript-window.mjs +102 -122
  1326. package/src/tui/app/usage-context-panels/context-model.mjs +282 -0
  1327. package/src/tui/app/usage-context-panels/usage-panel.mjs +48 -0
  1328. package/src/tui/app/usage-context-panels.mjs +24 -282
  1329. package/src/tui/app/use-copy-selection.mjs +5 -4
  1330. package/src/tui/app/use-global-key-input.mjs +2 -3
  1331. package/src/tui/app/use-mouse-input.mjs +7 -11
  1332. package/src/tui/app/use-pasted-buffers.mjs +2 -2
  1333. package/src/tui/app/use-prompt-draft-flow.mjs +1 -1
  1334. package/src/tui/app/use-prompt-handlers.mjs +32 -257
  1335. package/src/tui/app/use-prompt-hint.mjs +1 -1
  1336. package/src/tui/app/use-prompt-queue-history.mjs +1 -1
  1337. package/src/tui/app/use-selection-focus.mjs +132 -0
  1338. package/src/tui/app/use-selection-geometry.mjs +108 -0
  1339. package/src/tui/app/use-selection-paint.mjs +192 -0
  1340. package/src/tui/app/use-selection-stitch.mjs +128 -0
  1341. package/src/tui/app/use-terminal-chrome.mjs +1 -1
  1342. package/src/tui/app/use-transcript-activity.mjs +4 -3
  1343. package/src/tui/app/use-transcript-follow.mjs +91 -0
  1344. package/src/tui/app/use-transcript-scroll.mjs +220 -737
  1345. package/src/tui/app/use-transcript-window/geometry.mjs +139 -0
  1346. package/src/tui/app/use-transcript-window/instance-state.mjs +80 -0
  1347. package/src/tui/app/use-transcript-window/selection-shift.mjs +57 -0
  1348. package/src/tui/app/use-transcript-window/visible-items.mjs +46 -0
  1349. package/src/tui/app/use-transcript-window.mjs +101 -827
  1350. package/src/tui/app/use-welcome-prompt-hint.mjs +1 -1
  1351. package/src/tui/components/AnsiText.jsx +2 -4
  1352. package/src/tui/components/ContextInspector.jsx +87 -39
  1353. package/src/tui/components/ContextPanel.jsx +18 -34
  1354. package/src/tui/components/Markdown.jsx +4 -1
  1355. package/src/tui/components/Message.jsx +9 -2
  1356. package/src/tui/components/Picker.jsx +48 -43
  1357. package/src/tui/components/QueuedCommands.jsx +6 -5
  1358. package/src/tui/components/SlashCommandPalette.jsx +1 -18
  1359. package/src/tui/components/Spinner.jsx +25 -21
  1360. package/src/tui/components/StatusLine.jsx +7 -30
  1361. package/src/tui/components/ToolExecution.jsx +22 -29
  1362. package/src/tui/components/TranscriptItem.jsx +5 -13
  1363. package/src/tui/components/TurnDone.jsx +27 -35
  1364. package/src/tui/components/UsagePanel.jsx +55 -66
  1365. package/src/tui/components/panel-cell-text.mjs +19 -0
  1366. package/src/tui/components/prompt-input/edit-helpers.mjs +8 -4
  1367. package/src/tui/components/tool-execution/text-format.mjs +2 -3
  1368. package/src/tui/components/tool-output-format.mjs +3 -3
  1369. package/src/tui/dist/index.mjs +8446 -7222
  1370. package/src/tui/hooks/useSharedTick.mjs +3 -9
  1371. package/src/tui/input-editing.mjs +3 -1
  1372. package/src/tui/markdown/ansi-line-wrap.mjs +37 -0
  1373. package/src/tui/markdown/format-token.mjs +6 -41
  1374. package/src/tui/markdown/measure-rendered-rows.mjs +7 -2
  1375. package/src/tui/markdown/stream-fence.mjs +1 -2
  1376. package/src/tui/markdown/streaming-markdown.mjs +1 -7
  1377. package/src/tui/markdown/table-layout.mjs +3 -40
  1378. package/src/tui/paste-attachments.mjs +1 -2
  1379. package/src/tui/prompt-history-store.mjs +1 -1
  1380. package/src/tui/session/active-tool-summary.mjs +71 -0
  1381. package/src/tui/session/agent-envelope.mjs +42 -13
  1382. package/src/tui/session/agent-job-feed/agent-job-card.mjs +30 -0
  1383. package/src/tui/session/agent-job-feed/agent-status-refresh.mjs +37 -0
  1384. package/src/tui/session/agent-job-feed/execution-dedup.mjs +80 -0
  1385. package/src/tui/session/agent-job-feed/execution-delivery.mjs +103 -0
  1386. package/src/tui/session/agent-job-feed/model-notification.mjs +79 -0
  1387. package/src/tui/session/agent-job-feed/notification-chain.mjs +64 -0
  1388. package/src/tui/session/agent-job-feed/notification-router.mjs +66 -0
  1389. package/src/tui/session/agent-job-feed/pending-resume.mjs +131 -0
  1390. package/src/tui/session/agent-job-feed.mjs +57 -513
  1391. package/src/tui/session/agent-response-tail.mjs +1 -1
  1392. package/src/tui/session/context-state.mjs +5 -2
  1393. package/src/tui/session/cross-surface-share.mjs +411 -0
  1394. package/src/tui/session/draft-store.mjs +85 -0
  1395. package/src/tui/session/goal-continuation/continuation-queue.mjs +90 -0
  1396. package/src/tui/session/goal-continuation/deadline-delivery.mjs +76 -0
  1397. package/src/tui/session/goal-continuation/goal-visibility.mjs +38 -0
  1398. package/src/tui/session/goal-continuation.mjs +34 -178
  1399. package/src/tui/session/initial-state.mjs +50 -0
  1400. package/src/tui/session/live-share/delta.mjs +153 -0
  1401. package/src/tui/session/live-share/mirror.mjs +106 -0
  1402. package/src/tui/session/live-share/owner.mjs +235 -0
  1403. package/src/tui/session/live-share/retry.mjs +39 -0
  1404. package/src/tui/session/live-share/viewer/submit-acks.mjs +65 -0
  1405. package/src/tui/session/live-share/viewer/sync-waiters.mjs +53 -0
  1406. package/src/tui/session/live-share/viewer.mjs +190 -0
  1407. package/src/tui/session/live-share/wire.mjs +41 -0
  1408. package/src/tui/session/live-share.mjs +34 -775
  1409. package/src/tui/session/notice-surface.mjs +77 -0
  1410. package/src/tui/session/notification-plan.mjs +7 -9
  1411. package/src/tui/session/oauth-flows.mjs +4 -4
  1412. package/src/tui/session/prompt-history.mjs +1 -1
  1413. package/src/tui/session/queue-helpers.mjs +3 -1
  1414. package/src/tui/session/render-timing.mjs +0 -1
  1415. package/src/tui/session/session-api/commands.mjs +163 -0
  1416. package/src/tui/session/session-api/controls.mjs +119 -0
  1417. package/src/tui/session/session-api/extensions.mjs +154 -0
  1418. package/src/tui/session/session-api/intake/abort.mjs +150 -0
  1419. package/src/tui/session/session-api/intake/rewind.mjs +47 -0
  1420. package/src/tui/session/session-api/intake/submission.mjs +111 -0
  1421. package/src/tui/session/session-api/intake.mjs +54 -0
  1422. package/src/tui/session/session-api/integrations.mjs +171 -0
  1423. package/src/tui/session/session-api/lifecycle/dispose.mjs +50 -0
  1424. package/src/tui/session/session-api/lifecycle/inheritance.mjs +73 -0
  1425. package/src/tui/session/session-api/lifecycle/resume.mjs +78 -0
  1426. package/src/tui/session/session-api/lifecycle/session-reset.mjs +145 -0
  1427. package/src/tui/session/session-api/lifecycle.mjs +51 -0
  1428. package/src/tui/session/session-api/media.mjs +125 -0
  1429. package/src/tui/session/session-api/routes.mjs +205 -0
  1430. package/src/tui/session/session-api/settings.mjs +163 -0
  1431. package/src/tui/session/session-api/shared.mjs +34 -0
  1432. package/src/tui/session/session-api-ext.mjs +18 -867
  1433. package/src/tui/session/session-api.mjs +14 -1026
  1434. package/src/tui/session/session-flow/auto-clear.mjs +185 -0
  1435. package/src/tui/session/session-flow/drain.mjs +269 -0
  1436. package/src/tui/session/session-flow/failed-turn-rewind.mjs +27 -0
  1437. package/src/tui/session/session-flow/queue.mjs +213 -0
  1438. package/src/tui/session/session-flow/session-reset.mjs +135 -0
  1439. package/src/tui/session/session-flow/steering.mjs +190 -0
  1440. package/src/tui/session/session-flow.mjs +43 -846
  1441. package/src/tui/session/tool-approval.mjs +1 -3
  1442. package/src/tui/session/tool-card-results/aggregate-result.mjs +98 -0
  1443. package/src/tui/session/tool-card-results/grouped-result.mjs +94 -0
  1444. package/src/tui/session/tool-card-results/item-patch.mjs +28 -0
  1445. package/src/tui/session/tool-card-results.mjs +45 -234
  1446. package/src/tui/session/tool-result-status.mjs +14 -22
  1447. package/src/tui/session/tool-result-text.mjs +1 -3
  1448. package/src/tui/session/transcript-intake.mjs +151 -0
  1449. package/src/tui/session/transcript-spill/spill-dir.mjs +102 -0
  1450. package/src/tui/session/transcript-spill/spill-writer.mjs +160 -0
  1451. package/src/tui/session/transcript-spill.mjs +42 -261
  1452. package/src/tui/session/transcript-store.mjs +193 -0
  1453. package/src/tui/session/tui-steering-persist.mjs +2 -2
  1454. package/src/tui/session/turn-aggregate-cards/early-complete.mjs +62 -0
  1455. package/src/tui/session/turn-aggregate-cards/header-sync.mjs +71 -0
  1456. package/src/tui/session/turn-aggregate-cards.mjs +19 -122
  1457. package/src/tui/session/turn-deferred-cards.mjs +2 -21
  1458. package/src/tui/session/turn-stream.mjs +464 -0
  1459. package/src/tui/session/turn-tool-cards.mjs +338 -0
  1460. package/src/tui/session/turn.mjs +531 -1252
  1461. package/src/tui/session-local.mjs +63 -910
  1462. package/src/tui/spinner-meta.mjs +2 -2
  1463. package/src/tui/theme.mjs +3 -3
  1464. package/src/tui/transcript-tool-failures.mjs +4 -7
  1465. package/src/ui/ansi.mjs +6 -28
  1466. package/src/ui/context-inspection.mjs +22 -10
  1467. package/src/ui/context-measurement.mjs +10 -7
  1468. package/src/ui/markdown.mjs +15 -17
  1469. package/src/ui/model-display.mjs +5 -6
  1470. package/src/ui/statusline-format.mjs +5 -3
  1471. package/src/ui/statusline.mjs +214 -223
  1472. package/src/ui/streaming-markdown-heal.mjs +7 -3
  1473. package/src/ui/tool-card.mjs +1 -1
  1474. package/src/workflows/default/WORKFLOW.md +4 -0
  1475. package/src/rules/routes/common.md +0 -4
  1476. package/src/runtime/agent/orchestrator/providers/anthropic-turn-reminder.mjs +0 -96
  1477. package/src/runtime/agent/orchestrator/session/batching-nudge.mjs +0 -461
  1478. package/src/runtime/channels/lib/index-drop-trace.mjs +0 -89
  1479. package/src/runtime/channels/lib/network-retry.mjs +0 -24
@@ -1,12 +1,12 @@
1
- // provider.send wrapper with stall/overflow recovery, extracted from
2
- // agent-loop.mjs. Returns { action } so the loop keeps control of the
1
+ // provider.send wrapper with stall/overflow recovery.
2
+ // Returns { action } so the loop keeps control of the
3
3
  // while-loop: proceed carries the response, retry signals a reactive
4
4
  // context-overflow compact retry (caller re-enters the pre-send compact
5
- // pass), and unrecoverable errors throw. Behavior identical to the inline
6
- // try/catch it replaced.
5
+ // pass), and unrecoverable errors throw.
7
6
  import { appendAgentTrace } from '../agent-trace.mjs';
8
7
  import {
9
8
  classifyError,
9
+ isConnectionFailure,
10
10
  isContextOverflowError,
11
11
  isCursorTransientTransportError,
12
12
  isNonTerminalStreamClose,
@@ -28,7 +28,7 @@ import {
28
28
  isThinkingReplayRejection,
29
29
  repairThinkingReplayInPlace,
30
30
  } from './thinking-replay-recovery.mjs';
31
- import { setTimeout as sleepMs } from 'timers/promises';
31
+ import { setTimeout as sleepMs } from 'node:timers/promises';
32
32
  import { readStreamOutcome } from '../providers/lib/stream-outcome.mjs';
33
33
  import { cloneProviderReplay } from '../providers/lib/provider-replay.mjs';
34
34
  import { resolveWorkerCompactPolicy } from './loop/compact-policy.mjs';
@@ -73,39 +73,63 @@ function normalizedIncompleteUsage(raw) {
73
73
  // real waits and an operator can widen the window for a flaky uplink; the
74
74
  // LENGTH of the list is the retry budget, like a conventional
75
75
  // stream-max-retries + backoff table.
76
- const TRANSPORT_RETRY_BACKOFF_MS = Object.freeze(
77
- (() => {
78
- const raw = process.env.MIXDOG_TRANSPORT_RETRY_BACKOFF_MS;
79
- if (typeof raw === 'string' && raw.trim()) {
80
- const parsed = raw
81
- .split(',')
82
- .map((value) => Number(value.trim()))
83
- .filter((value) => Number.isFinite(value) && value >= 0);
84
- if (parsed.length) return parsed;
85
- }
86
- // Three steps (~50s of outage) instead of two: the provider envelope
87
- // already covers short blips, so this ladder exists for the long ones.
88
- // Comparable runtimes allow 5-10 retries for this outage class.
89
- return [5_000, 15_000, 30_000];
90
- })()
91
- );
76
+ function retryLadderFromEnv(envName, fallback) {
77
+ const raw = process.env[envName];
78
+ if (typeof raw === 'string' && raw.trim()) {
79
+ const parsed = raw
80
+ .split(',')
81
+ .map((value) => Number(value.trim()))
82
+ .filter((value) => Number.isFinite(value) && value >= 0);
83
+ if (parsed.length) return Object.freeze(parsed);
84
+ }
85
+ return Object.freeze(fallback);
86
+ }
87
+
88
+ // Three steps (~50s of outage) instead of two: the provider envelope
89
+ // already covers short blips, so this ladder exists for the long ones.
90
+ const TRANSPORT_RETRY_BACKOFF_MS = retryLadderFromEnv('MIXDOG_TRANSPORT_RETRY_BACKOFF_MS', [5_000, 15_000, 30_000]);
92
91
  export const TRANSPORT_RETRY_MAX = TRANSPORT_RETRY_BACKOFF_MS.length;
93
92
 
93
+ // A lost NETWORK is not a provider fault, so it gets its own far longer
94
+ // ladder: exponential to a one-minute ceiling, ~10 minutes of total cover.
95
+ // Failing the turn after ~50s discarded real work for an outage the user
96
+ // often never noticed (a lift, a sleeping laptop, a router reboot), while the
97
+ // identical request succeeds the moment the link returns. Comparable runtimes
98
+ // retry this class until the network comes back; the cap is what keeps a
99
+ // parked background session from waiting forever with nobody watching.
100
+ const CONNECTION_RETRY_BACKOFF_MS = retryLadderFromEnv('MIXDOG_CONNECTION_RETRY_BACKOFF_MS', [
101
+ 5_000,
102
+ 10_000,
103
+ 20_000,
104
+ 40_000,
105
+ ...Array(9).fill(60_000),
106
+ ]);
107
+
94
108
  // Jittering every backoff by 0.9–1.1 keeps parallel workers that lose the
95
109
  // same uplink do not resume in lockstep; our provider layers already jitter
96
110
  // (10% WS / 20% shared), this brings the loop ladder in line.
97
111
  const TRANSPORT_RETRY_JITTER_RATIO = 0.1;
98
112
 
99
- function transportRetryWaitMs(attemptIndex) {
100
- const base = TRANSPORT_RETRY_BACKOFF_MS[attemptIndex];
113
+ /** The ladder this failure class is entitled to: lost uplink vs ordinary fault. */
114
+ function retryLadderFor(error) {
115
+ return isConnectionFailure(error) ? CONNECTION_RETRY_BACKOFF_MS : TRANSPORT_RETRY_BACKOFF_MS;
116
+ }
117
+
118
+ function retryBudgetFor(error) {
119
+ return retryLadderFor(error).length;
120
+ }
121
+
122
+ function transportRetryWaitMs(attemptIndex, error) {
123
+ const ladder = retryLadderFor(error);
124
+ const base = ladder[Math.min(Math.max(attemptIndex, 0), ladder.length - 1)];
101
125
  return jitterDelayMs(base, TRANSPORT_RETRY_JITTER_RATIO);
102
126
  }
103
127
 
104
128
  // Every loop-level replay is a NEW request, so it opens a new stall window.
105
129
  // Inheriting the spent one aborted healthy replacement responses mid-flight.
106
- function beginFreshTransportAttempt(opts) {
130
+ function beginFreshTransportAttempt(opts, retryMax) {
107
131
  resetStallRetryBudget(opts);
108
- return { action: 'retry_transport' };
132
+ return { action: 'retry_transport', transportRetryMax: retryMax };
109
133
  }
110
134
 
111
135
  export async function sendWithRecovery(ctx) {
@@ -114,51 +138,130 @@ export async function sendWithRecovery(ctx) {
114
138
  messages,
115
139
  model,
116
140
  sendTools,
117
- tools,
118
141
  opts,
119
- recoveryMessages = messages,
120
142
  sessionId,
121
- sessionRef,
122
- nextIteration,
123
- contextOverflowRetryUsed,
124
143
  transportRetriesUsed = 0,
125
- imageStripUsed = false,
126
- thinkingReplayRepairUsed = false,
127
- signal,
144
+ transportRetryMax = 0,
128
145
  } = ctx;
129
146
  // Establishes the in-request stall window the provider layer shares through
130
147
  // opts. A fresh replay below resets it: the loop's own TRANSPORT_RETRY_MAX
131
148
  // is what bounds replays, not a window already spent detecting the stall.
132
149
  resolveStallRetryBudget(opts);
133
- let response;
134
- // Bench-only turn timing (MIXDOG_TURN_TIMING=1): one stderr line per
135
- // provider request — TTFT (first visible model progress) and total stream
136
- // time. Transport/header and response-created acknowledgements do not count.
137
- // Inert unless the env flag is set; used to profile harness vs model
138
- // latency in Terminal-Bench runs.
150
+ // Reconnect chrome for THIS attempt. The ladder that actually bounds the
151
+ // replays is picked per failure class below and carried back through the
152
+ // loop, so "Reconnecting... n/max" reports the budget the outage is really
153
+ // getting instead of the default one.
154
+ const retryMaxForDisplay =
155
+ Number(transportRetryMax) > 0 ? Math.floor(Number(transportRetryMax)) : TRANSPORT_RETRY_MAX;
156
+ const hooks = instrumentSendCallbacks(opts, {
157
+ model,
158
+ retryAttemptNumber: Math.max(0, Number(transportRetriesUsed) || 0),
159
+ retryMaxForDisplay,
160
+ });
161
+ try {
162
+ let response;
163
+ try {
164
+ const { timedOpts } = hooks;
165
+ const admittedOpts = timedOpts?.admissionOwner ? timedOpts : { ...(timedOpts || {}), admissionOwner: sessionId };
166
+ response = await provider.send(messages, model, sendTools.length ? sendTools : undefined, admittedOpts);
167
+ hooks.logTurnTiming('ok');
168
+ } catch (sendErr) {
169
+ hooks.logTurnTiming(`err:${sendErr?.code || sendErr?.name || 'unknown'}`);
170
+ return await recoverFromSendError(sendErr, { ...ctx, relayWitness: hooks.relayWitness });
171
+ }
172
+ return { action: 'proceed', response };
173
+ } finally {
174
+ hooks.restore();
175
+ }
176
+ }
177
+
178
+ // Bench-only turn timing (MIXDOG_TURN_TIMING=1): one stderr line per
179
+ // provider request — TTFT (first visible model progress) and total stream
180
+ // time. Transport/header and response-created acknowledgements do not count.
181
+ // Inert unless the env flag is set; used to profile harness vs model
182
+ // latency in Terminal-Bench runs.
183
+ function beginTurnTiming(opts, model) {
139
184
  const turnT0 = process.env.MIXDOG_TURN_TIMING === '1' ? Date.now() : 0;
185
+ if (!turnT0) return { timedOpts: opts, log() {} };
140
186
  let turnFirstDelta = 0;
141
- let timedOpts = opts;
142
- if (turnT0) {
143
- const prevDelta = typeof opts?.onStreamDelta === 'function' ? opts.onStreamDelta : null;
144
- timedOpts = {
145
- ...(opts || {}),
146
- onStreamDelta: (kind) => {
147
- if (!turnFirstDelta && isVisibleStreamProgress(kind)) turnFirstDelta = Date.now();
148
- if (prevDelta) prevDelta(kind);
149
- },
150
- };
151
- }
152
- const logTurnTiming = (status) => {
153
- if (!turnT0) return;
154
- const now = Date.now();
155
- const ttft = turnFirstDelta ? turnFirstDelta - turnT0 : -1;
156
- try {
157
- console.error(`[turn-timing] status=${status} ttft=${ttft}ms total=${now - turnT0}ms model=${model}`);
158
- } catch {
159
- /* logging must never break the send path */
187
+ const prevDelta = typeof opts?.onStreamDelta === 'function' ? opts.onStreamDelta : null;
188
+ const timedOpts = {
189
+ ...(opts || {}),
190
+ onStreamDelta: (kind) => {
191
+ if (!turnFirstDelta && isVisibleStreamProgress(kind)) turnFirstDelta = Date.now();
192
+ if (prevDelta) prevDelta(kind);
193
+ },
194
+ };
195
+ return {
196
+ timedOpts,
197
+ log(status) {
198
+ const now = Date.now();
199
+ const ttft = turnFirstDelta ? turnFirstDelta - turnT0 : -1;
200
+ try {
201
+ console.error(`[turn-timing] status=${status} ttft=${ttft}ms total=${now - turnT0}ms model=${model}`);
202
+ } catch {
203
+ /* logging must never break the send path */
204
+ }
205
+ },
206
+ };
207
+ }
208
+
209
+ // Retry visibility (reference parity). codex surfaces EVERY stream retry to
210
+ // the front-end ("Reconnecting... n/max") precisely so a replayed request
211
+ // cannot read as ordinary thinking; gemini-cli requires an onRetry hook for
212
+ // the same reason. Emitting the reconnect stage only for the backoff wait
213
+ // let the replayed send report plain 'requesting'/'streaming' again, so
214
+ // three stalled retries rendered as ~20 minutes of a normal spinner with
215
+ // nothing to explain it. Hold the reconnect stage across the whole replay
216
+ // until THIS attempt shows visible progress: the replacement stream's first
217
+ // visible delta ends the reconnect display, and from that point the turn is
218
+ // healthy and must read as a normal response.
219
+ function retryVisibilityWrappers(opts, timedOpts, retryAttemptNumber, retryMaxForDisplay) {
220
+ const prevOnStageChange = typeof opts?.onStageChange === 'function' ? opts.onStageChange : null;
221
+ const prevOptsOnStreamDelta = typeof opts?.onStreamDelta === 'function' ? opts.onStreamDelta : null;
222
+ const retryDeltaBase = timedOpts || opts;
223
+ const prevOnStreamDeltaForRetry =
224
+ typeof retryDeltaBase?.onStreamDelta === 'function' ? retryDeltaBase.onStreamDelta : null;
225
+ const wrappers = {
226
+ onStageChange: null,
227
+ onStreamDelta: null,
228
+ prevOnStageChange,
229
+ prevOptsOnStreamDelta,
230
+ prevOnStreamDeltaForRetry,
231
+ };
232
+ if (!(retryAttemptNumber > 0 && prevOnStageChange)) return wrappers;
233
+ let progressObserved = false;
234
+ wrappers.onStageChange = (stage, detail) => {
235
+ if (!progressObserved && (stage === 'requesting' || stage === 'streaming')) {
236
+ return prevOnStageChange('reconnecting', {
237
+ ...(detail && typeof detail === 'object' ? detail : {}),
238
+ attempt: retryAttemptNumber,
239
+ max: retryMaxForDisplay,
240
+ message: `Reconnecting... ${retryAttemptNumber}/${retryMaxForDisplay}`,
241
+ });
242
+ }
243
+ return prevOnStageChange(stage, detail);
244
+ };
245
+ wrappers.onStreamDelta = (kind, ...rest) => {
246
+ if (!progressObserved && isVisibleStreamProgress(kind)) {
247
+ progressObserved = true;
248
+ try {
249
+ prevOnStageChange('streaming', { recoveredAfterRetry: retryAttemptNumber });
250
+ } catch {
251
+ /* display-only */
252
+ }
160
253
  }
254
+ return prevOnStreamDeltaForRetry?.(kind, ...rest);
161
255
  };
256
+ return wrappers;
257
+ }
258
+
259
+ // Wraps the caller's stream callbacks in place for ONE send — bench-only
260
+ // turn timing, the loop-side exposure witness and the retry-visibility
261
+ // relay — and hands back the restore that unwinds only our own wrappers.
262
+ function instrumentSendCallbacks(opts, { model, retryAttemptNumber, retryMaxForDisplay }) {
263
+ const timing = beginTurnTiming(opts, model);
264
+ const { timedOpts } = timing;
162
265
  // Loop-side exposure witness. Some providers throw truncation/stall
163
266
  // errors that carry only partialContent — neither liveTextEmitted nor
164
267
  // unsafeToRetry — so an outcome read from the ERROR alone can report
@@ -166,586 +269,525 @@ export async function sendWithRecovery(ctx) {
166
269
  // client through opts.onTextDelta, or dispatched a tool call through
167
270
  // opts.onToolCall. Replaying such a send would duplicate output the user
168
271
  // already saw (or re-run a side effect), so record what THIS send
169
- // actually exposed and merge it into every outcome read below. The
170
- // callbacks are wrapped in place and restored conditionally: the
171
- // overflow-retry branch intentionally clears opts.onToolCall, and that
172
- // clear must survive the restore.
173
- const relayWitness = { textEmitted: false, toolCallsDispatched: 0 };
174
- // Caller-visible reconnect progress for LOOP-level replays, mirroring the
175
- // transports' own emitReconnectProgress (openai-oauth-ws). Without it the
176
- // 5s/15s wait rendered as a frozen turn with no explanation, so the
177
- // stage change surfaces "Reconnecting... n/max" instead of leaving
178
- // the user staring at a stalled stream.
179
- const emitLoopReconnectProgress = (attempt, waitMs, classifier, error) => {
180
- try {
181
- opts?.onStageChange?.('reconnecting', {
182
- attempt,
183
- max: TRANSPORT_RETRY_MAX,
184
- classifier: classifier || null,
185
- waitMs,
186
- wsCloseCode: error?.wsCloseCode ?? null,
187
- httpStatus: error?.httpStatus ?? error?.status ?? null,
188
- message: providerRetryStatusText(error, {
189
- attempt,
190
- maxAttempts: TRANSPORT_RETRY_MAX,
191
- delayMs: waitMs,
192
- }),
193
- });
194
- } catch {
195
- /* progress reporting must never break recovery */
196
- }
272
+ // actually exposed and merge it into every outcome read. The callbacks
273
+ // are wrapped in place and restored conditionally: the overflow-retry
274
+ // branch intentionally clears opts.onToolCall, and that clear must
275
+ // survive the restore.
276
+ const witness = relayWitnessWrappers(opts);
277
+ const retry = retryVisibilityWrappers(opts, timedOpts, retryAttemptNumber, retryMaxForDisplay);
278
+ const install = (target) => {
279
+ if (witness.onTextDelta) target.onTextDelta = witness.onTextDelta;
280
+ if (witness.onToolCall) target.onToolCall = witness.onToolCall;
281
+ if (retry.onStageChange) target.onStageChange = retry.onStageChange;
282
+ if (retry.onStreamDelta) target.onStreamDelta = retry.onStreamDelta;
197
283
  };
198
- // Retry visibility (reference parity). codex surfaces EVERY stream retry to
199
- // the front-end ("Reconnecting... n/max") precisely so a replayed request
200
- // cannot read as ordinary thinking; gemini-cli requires an onRetry hook for
201
- // the same reason. Our loop emitted the reconnect stage only for the
202
- // backoff wait — the replayed send then reported plain
203
- // 'requesting'/'streaming' again, so three stalled retries rendered as ~20
204
- // minutes of a normal spinner with nothing to explain it. Hold the
205
- // reconnect stage across the whole replay until THIS attempt shows visible
206
- // progress.
207
- const retryAttemptNumber = Math.max(0, Number(transportRetriesUsed) || 0);
208
- const prevOnStageChange = typeof opts?.onStageChange === 'function' ? opts.onStageChange : null;
209
- const retryVisibilityActive = retryAttemptNumber > 0 && !!prevOnStageChange;
210
- let retryProgressObserved = !retryVisibilityActive;
211
- const retryAwareOnStageChange = retryVisibilityActive
212
- ? (stage, detail) => {
213
- if (!retryProgressObserved && (stage === 'requesting' || stage === 'streaming')) {
214
- return prevOnStageChange('reconnecting', {
215
- ...(detail && typeof detail === 'object' ? detail : {}),
216
- attempt: retryAttemptNumber,
217
- max: TRANSPORT_RETRY_MAX,
218
- message: `Reconnecting... ${retryAttemptNumber}/${TRANSPORT_RETRY_MAX}`,
219
- });
220
- }
221
- return prevOnStageChange(stage, detail);
222
- }
223
- : null;
224
- // The replacement stream's first visible delta ends the reconnect display:
225
- // from that point the turn is healthy and must read as a normal response.
226
- const prevOptsOnStreamDelta = typeof opts?.onStreamDelta === 'function' ? opts.onStreamDelta : null;
227
- const retryDeltaBase = timedOpts || opts;
228
- const prevOnStreamDeltaForRetry =
229
- typeof retryDeltaBase?.onStreamDelta === 'function' ? retryDeltaBase.onStreamDelta : null;
230
- const retryAwareOnStreamDelta = retryVisibilityActive
231
- ? (kind, ...rest) => {
232
- if (!retryProgressObserved && isVisibleStreamProgress(kind)) {
233
- retryProgressObserved = true;
234
- try {
235
- prevOnStageChange('streaming', { recoveredAfterRetry: retryAttemptNumber });
236
- } catch {
237
- /* display-only */
238
- }
239
- }
240
- return prevOnStreamDeltaForRetry?.(kind, ...rest);
241
- }
242
- : null;
284
+ if (opts) install(opts);
285
+ if (timedOpts !== opts && timedOpts) install(timedOpts);
286
+ return {
287
+ timedOpts,
288
+ relayWitness: witness.relayWitness,
289
+ logTurnTiming: timing.log,
290
+ restore: () => restoreSendCallbacks(opts, timedOpts, witness, retry),
291
+ };
292
+ }
293
+
294
+ // Wraps opts.onTextDelta / opts.onToolCall so the witness records what this
295
+ // send actually relayed; null wrappers where the caller subscribed to nothing.
296
+ function relayWitnessWrappers(opts) {
297
+ const relayWitness = { textEmitted: false, toolCallsDispatched: 0 };
243
298
  const prevOnTextDelta = typeof opts?.onTextDelta === 'function' ? opts.onTextDelta : null;
244
299
  const prevOnToolCall = typeof opts?.onToolCall === 'function' ? opts.onToolCall : null;
245
- const witnessedOnTextDelta = prevOnTextDelta
300
+ const onTextDelta = prevOnTextDelta
246
301
  ? (...args) => {
247
302
  if (typeof args[0] === 'string' && args[0].length > 0) relayWitness.textEmitted = true;
248
303
  return prevOnTextDelta(...args);
249
304
  }
250
305
  : null;
251
- const witnessedOnToolCall = prevOnToolCall
306
+ const onToolCall = prevOnToolCall
252
307
  ? (...args) => {
253
308
  relayWitness.toolCallsDispatched += 1;
254
309
  return prevOnToolCall(...args);
255
310
  }
256
311
  : null;
312
+ return { relayWitness, onTextDelta, onToolCall, prevOnTextDelta, prevOnToolCall };
313
+ }
314
+
315
+ // Conditional restore: only unwind our own wrappers. An intentional
316
+ // opts.onToolCall = undefined (overflow-retry branch) stays cleared.
317
+ function restoreSendCallbacks(opts, timedOpts, witness, retry) {
257
318
  if (opts) {
258
- if (witnessedOnTextDelta) opts.onTextDelta = witnessedOnTextDelta;
259
- if (witnessedOnToolCall) opts.onToolCall = witnessedOnToolCall;
260
- if (retryAwareOnStageChange) opts.onStageChange = retryAwareOnStageChange;
261
- if (retryAwareOnStreamDelta) opts.onStreamDelta = retryAwareOnStreamDelta;
319
+ if (witness.onTextDelta && opts.onTextDelta === witness.onTextDelta) opts.onTextDelta = witness.prevOnTextDelta;
320
+ if (witness.onToolCall && opts.onToolCall === witness.onToolCall) opts.onToolCall = witness.prevOnToolCall;
321
+ if (retry.onStageChange && opts.onStageChange === retry.onStageChange) {
322
+ opts.onStageChange = retry.prevOnStageChange;
323
+ }
324
+ if (retry.onStreamDelta && opts.onStreamDelta === retry.onStreamDelta) {
325
+ opts.onStreamDelta = retry.prevOptsOnStreamDelta;
326
+ }
262
327
  }
263
- if (timedOpts !== opts && timedOpts) {
264
- if (witnessedOnTextDelta) timedOpts.onTextDelta = witnessedOnTextDelta;
265
- if (witnessedOnToolCall) timedOpts.onToolCall = witnessedOnToolCall;
266
- if (retryAwareOnStageChange) timedOpts.onStageChange = retryAwareOnStageChange;
267
- if (retryAwareOnStreamDelta) timedOpts.onStreamDelta = retryAwareOnStreamDelta;
328
+ if (timedOpts && timedOpts !== opts) {
329
+ if (retry.onStageChange && timedOpts.onStageChange === retry.onStageChange) {
330
+ timedOpts.onStageChange = retry.prevOnStageChange;
331
+ }
332
+ if (retry.onStreamDelta && timedOpts.onStreamDelta === retry.onStreamDelta) {
333
+ timedOpts.onStreamDelta = retry.prevOnStreamDeltaForRetry;
334
+ }
335
+ }
336
+ }
337
+
338
+ function loopTag({ sessionId, nextIteration }) {
339
+ return `sess=${sessionId || 'unknown'} iter=${nextIteration}`;
340
+ }
341
+
342
+ function logLoop(line) {
343
+ try {
344
+ process.stderr.write(`${line}\n`);
345
+ } catch {
346
+ /* best-effort */
347
+ }
348
+ }
349
+
350
+ function traceLoop({ sessionId, nextIteration }, kind, fields) {
351
+ try {
352
+ appendAgentTrace({ kind, sessionId: sessionId || null, iteration: nextIteration, ...fields });
353
+ } catch {
354
+ /* best-effort */
268
355
  }
356
+ }
357
+
358
+ // Caller-visible reconnect progress for LOOP-level replays, mirroring the
359
+ // transports' own emitReconnectProgress (openai-oauth-ws). Without it the
360
+ // 5s/15s wait rendered as a frozen turn with no explanation, so the stage
361
+ // change surfaces "Reconnecting... n/max" instead of leaving the user
362
+ // staring at a stalled stream.
363
+ function emitLoopReconnectProgress(opts, { attempt, maxAttempts, waitMs, classifier, error }) {
269
364
  try {
365
+ opts?.onStageChange?.('reconnecting', {
366
+ attempt,
367
+ max: maxAttempts,
368
+ classifier: classifier || null,
369
+ waitMs,
370
+ wsCloseCode: error?.wsCloseCode ?? null,
371
+ httpStatus: error?.httpStatus ?? error?.status ?? null,
372
+ message: providerRetryStatusText(error, { attempt, maxAttempts, delayMs: waitMs }),
373
+ });
374
+ } catch {
375
+ /* progress reporting must never break recovery */
376
+ }
377
+ }
378
+
379
+ // Text-only exposure retraction (cross-provider): a stream that died after
380
+ // relaying ONLY text — no dispatched or complete tool calls, no terminal —
381
+ // is replayable IF the ask owner retracts the exposed characters
382
+ // (onTextReset ack === true: the TUI truncates its live tail, the bench
383
+ // driver truncates its accumulator). This is the loop-level analogue of
384
+ // anthropic's recoverNonStreaming for providers WITHOUT a non-streaming
385
+ // fallback (gemini, openai-compat, openai WS) and for stalls that outlived
386
+ // the provider's in-place recovery. Observed live: make-mips-interpreter
387
+ // died with 31 exposed chars + a pending never-dispatched tool input and
388
+ // burned the whole trial.
389
+ async function retractExposedTextForReplay({ outcome, sendErr, opts, relayWitness }) {
390
+ if (outcome.terminalObserved === true) return false;
391
+ if (outcome.sideEffectDispatched === true) return false;
392
+ if (outcome.dispatchAmbiguous === true) return false;
393
+ if (Number(outcome.toolCallsDispatched) > 0) return false;
394
+ if (Number(outcome.toolCallsComplete) > 0) return false;
395
+ if (relayWitness.toolCallsDispatched > 0) return false;
396
+ const chars =
397
+ Math.max(0, Number(outcome.textObservedChars) || 0) ||
398
+ (typeof sendErr.partialContent === 'string' ? sendErr.partialContent.length : 0);
399
+ const reasoningOnly = outcome.reasoningEmitted === true && chars <= 0;
400
+ if (chars <= 0 && !reasoningOnly) return false;
401
+ if (typeof opts?.onTextReset === 'function') {
402
+ let acked = false;
270
403
  try {
271
- const admittedOpts = timedOpts?.admissionOwner ? timedOpts : { ...(timedOpts || {}), admissionOwner: sessionId };
272
- response = await provider.send(messages, model, sendTools.length ? sendTools : undefined, admittedOpts);
273
- logTurnTiming('ok');
274
- } catch (sendErr) {
275
- logTurnTiming(`err:${sendErr?.code || sendErr?.name || 'unknown'}`);
276
- // Canonical stream outcome: ONE fail-closed read of what the
277
- // provider stream actually produced (terminal vs continuation,
278
- // observed text/reasoning, partial/complete/dispatched tool calls).
279
- // Every branch below consumes it instead of re-inferring safety
280
- // from provider-specific flags.
281
- const outcome = readStreamOutcome(sendErr, relayWitness);
282
- // Text-only exposure retraction (cross-provider): a stream that
283
- // died after relaying ONLY text — no dispatched or complete tool
284
- // calls, no terminal — is replayable IF the ask owner retracts the
285
- // exposed characters (onTextReset ack === true: the TUI truncates
286
- // its live tail, the bench driver truncates its accumulator).
287
- // This is the loop-level analogue of anthropic's
288
- // recoverNonStreaming for providers WITHOUT a non-streaming
289
- // fallback (gemini, openai-compat, openai WS) and for stalls that
290
- // outlived the provider's in-place recovery. Observed live:
291
- // make-mips-interpreter died with 31 exposed chars + a pending
292
- // never-dispatched tool input and burned the whole trial.
293
- const retractExposedTextForReplay = async () => {
294
- if (outcome.terminalObserved === true) return false;
295
- if (outcome.sideEffectDispatched === true) return false;
296
- if (outcome.dispatchAmbiguous === true) return false;
297
- if (Number(outcome.toolCallsDispatched) > 0) return false;
298
- if (Number(outcome.toolCallsComplete) > 0) return false;
299
- if (relayWitness.toolCallsDispatched > 0) return false;
300
- const chars =
301
- Math.max(0, Number(outcome.textObservedChars) || 0) ||
302
- (typeof sendErr.partialContent === 'string' ? sendErr.partialContent.length : 0);
303
- const reasoningOnly = outcome.reasoningEmitted === true && chars <= 0;
304
- if (chars <= 0 && !reasoningOnly) return false;
305
- if (typeof opts?.onTextReset === 'function') {
306
- let acked = false;
307
- try {
308
- acked =
309
- (await opts.onTextReset({
310
- chars,
311
- reasoning: outcome.reasoningEmitted === true,
312
- reason: 'loop-transport-retraction',
313
- })) === true;
314
- } catch {
315
- acked = false;
316
- }
317
- if (!acked && !reasoningOnly) return false;
318
- } else if (!reasoningOnly) {
319
- return false;
320
- }
321
- relayWitness.textEmitted = false;
322
- return true;
323
- };
324
- // Gemini REST/SDK reports MAX_TOKENS by throwing a typed
325
- // ProviderIncompleteError after preserving the streamed candidate.
326
- // Normalize only that exact, safe no-tool output-limit shape into a
327
- // regular truncated response; all moderation/OTHER/tool-bearing and
328
- // unrelated errors continue through their existing error paths.
329
- if (
330
- sendErr?.providerIncomplete === true &&
331
- sendErr.code === 'PROVIDER_INCOMPLETE' &&
332
- isOutputLimitStopReason(sendErr.finishReason) &&
333
- typeof sendErr.partialContent === 'string' &&
334
- sendErr.partialContent.trim().length > 0 &&
335
- // Terminal observed (explicit finish reason) and no tool
336
- // exposure at all: the only shape safe to promote to success.
337
- outcome.successEligible === true &&
338
- outcome.toolCallsStarted !== true &&
339
- outcome.sideEffectDispatched !== true
340
- ) {
341
- const partialProviderReplay = cloneProviderReplay(sendErr.partialProviderReplay);
342
- response = {
343
- content: sendErr.partialContent,
344
- model: sendErr.model || model,
345
- toolCalls: undefined,
346
- usage: normalizedIncompleteUsage(sendErr.rawUsage),
347
- stopReason: sendErr.finishReason,
348
- truncated: true,
349
- ...(partialProviderReplay ? { providerReplay: partialProviderReplay } : {}),
350
- providerMetadata: sendErr.providerMetadata,
351
- providerState: opts.providerState,
352
- providerIncompleteRecovery: true,
353
- };
354
- return { action: 'proceed', response };
355
- }
356
- // Exhausted no-tool stall: NOT a success. A FINAL, no-tool stream
357
- // that wedges (ping-only) carries streamed assistant text on the
358
- // StreamStalledError, but the turn never completed — the model may
359
- // have been mid-sentence, and there is no completion signal that
360
- // says the work is done. Promoting it to a normal terminal response
361
- // silently reported truncated/aborted turns as finished. Keep it an
362
- // explicit failure (no completion signal means no completed turn,
363
- // and the partial is persisted): the already-streamed text
364
- // is preserved by the interruption/error persistence path
365
- // (turn-interruption.mjs records the deltas and commits them as the
366
- // partial assistant message alongside the error), so nothing visible
367
- // is lost while the caller/owner-notify still sees a failed turn.
368
- // A stall WITH complete parsed tool calls is a different, genuinely
369
- // recoverable case and is handled by the next branch.
370
- else if (
371
- outcome.stallObserved === true &&
372
- outcome.terminalObserved !== true &&
373
- typeof sendErr.partialContent === 'string' &&
374
- sendErr.partialContent.trim().length > 0 &&
375
- outcome.toolCallsComplete === 0
376
- ) {
377
- // Retractable shape: text-only exposure with the owner's
378
- // acknowledgement replays on a fresh request instead of
379
- // failing the turn. Non-acked (or tool-bearing) shapes keep
380
- // the explicit-failure contract below unchanged.
381
- // NOTE: no classifyError gate here — an exposed stall is
382
- // stamped unsafeToRetry, which the general classifier reads as
383
- // terminal, but that unsafety is exactly what the retraction
384
- // removes (observed live: make-mips-interpreter failed twice
385
- // because this guard demanded 'transient' and never fired).
386
- if (
387
- transportRetriesUsed < TRANSPORT_RETRY_MAX &&
388
- !isProviderRecoveryExhausted(sendErr) &&
389
- (await retractExposedTextForReplay())
390
- ) {
391
- const waitMs = transportRetryWaitMs(transportRetriesUsed);
392
- try {
393
- process.stderr.write(
394
- `[loop] exposed-text stall retracted (sess=${sessionId || 'unknown'} ` +
395
- `iter=${nextIteration} len=${sendErr.partialContent.length}); ` +
396
- `transport retry ${transportRetriesUsed + 1}/${TRANSPORT_RETRY_MAX} after ${waitMs}ms\n`
397
- );
398
- } catch {
399
- /* best-effort */
400
- }
401
- try {
402
- appendAgentTrace({
403
- kind: 'exposed_text_retraction_retry',
404
- sessionId: sessionId || null,
405
- iteration: nextIteration,
406
- attempt: transportRetriesUsed + 1,
407
- waitMs,
408
- partialContentLen: sendErr.partialContent.length,
409
- });
410
- } catch {
411
- /* best-effort */
412
- }
413
- emitLoopReconnectProgress(
414
- transportRetriesUsed + 1,
415
- waitMs,
416
- outcome.stallObserved ? 'stream_stalled' : 'stream_closed',
417
- sendErr
418
- );
419
- await sleepMs(waitMs, undefined, signal ? { signal } : undefined);
420
- return beginFreshTransportAttempt(opts);
421
- }
422
- try {
423
- process.stderr.write(
424
- `[loop] final stream stalled with partial text (sess=${sessionId || 'unknown'} ` +
425
- `iter=${nextIteration} len=${sendErr.partialContent.length}); ` +
426
- `failing the turn (partial preserved via interrupted-turn persistence)\n`
427
- );
428
- } catch {
429
- /* best-effort */
430
- }
431
- try {
432
- appendAgentTrace({
433
- kind: 'stall_partial_final_rejected',
434
- sessionId: sessionId || null,
435
- iteration: nextIteration,
436
- partialContentLen: sendErr.partialContent.length,
437
- pendingToolUse: outcome.pendingToolInput,
438
- emittedToolCall: outcome.sideEffectDispatched,
439
- terminalObserved: outcome.terminalObserved,
440
- });
441
- } catch {
442
- /* best-effort */
443
- }
444
- throw sendErr;
445
- }
446
- // Partial tool-call recovery (agent-hang fix): a stream that stalls
447
- // AFTER fully-parsed tool calls were emitted used to lose the whole
448
- // turn — unsafeToRetry blocks the mid-stream replay (correct: a
449
- // replay would re-run side-effecting tools) and the old code threw,
450
- // discarding tool work that had ALREADY completed via eager dispatch.
451
- // But the parsed calls are complete (pendingToolUse false ⇒ no
452
- // half-streamed tool input), so instead of replaying the request we
453
- // accept the partial as a normal tool-call turn and fall through to
454
- // the standard execution path: eager-dispatched (read-only) calls
455
- // resolve from the pending map without re-running, side-effecting
456
- // calls were never started during streaming and execute exactly
457
- // once. providerState stays undefined so the next iteration resends
458
- // a full frame on a fresh stream.
459
- else if (
460
- outcome.stallObserved === true &&
461
- outcome.pendingToolInput !== true &&
462
- outcome.toolCallsComplete > 0 &&
463
- Array.isArray(sendErr.partialToolCalls) &&
464
- sendErr.partialToolCalls.length > 0
465
- ) {
466
- try {
467
- process.stderr.write(
468
- `[loop] stream stalled after ${sendErr.partialToolCalls.length} complete tool call(s) ` +
469
- `(sess=${sessionId || 'unknown'} iter=${nextIteration}); ` +
470
- `recovering as tool-call turn instead of failing\n`
471
- );
472
- } catch {
473
- /* best-effort */
474
- }
475
- try {
476
- appendAgentTrace({
477
- kind: 'stall_tool_recovery',
478
- sessionId: sessionId || null,
479
- iteration: nextIteration,
480
- toolCalls: sendErr.partialToolCalls.length,
481
- partialContentLen: typeof sendErr.partialContent === 'string' ? sendErr.partialContent.length : 0,
482
- });
483
- } catch {
484
- /* best-effort */
485
- }
486
- const partialProviderReplay = cloneProviderReplay(sendErr.partialProviderReplay);
487
- response = {
488
- content: typeof sendErr.partialContent === 'string' ? sendErr.partialContent : '',
489
- model: sendErr.partialModel || model,
490
- toolCalls: sendErr.partialToolCalls.slice(),
491
- usage: sendErr.partialUsage || undefined,
492
- stopReason: 'tool_use',
493
- hasThinkingContent: sendErr.partialHasThinking === true,
494
- // Ordered provider block state captured before the stall.
495
- // Anthropic REQUIRES the verbatim thinking blocks (with
496
- // their signatures) back ahead of tool_use on the
497
- // continuation turn, and a native `server_tool_use` call is
498
- // only valid immediately followed by its result block — so
499
- // the recovered tool turn must replay exactly what a
500
- // successful turn would have returned. The loop's committer
501
- // already drops the redundant `thinkingBlocks` copy when
502
- // `assistantBlocks` is present (which contains them
503
- // verbatim), so blocks are neither lost nor doubled.
504
- ...(Array.isArray(sendErr.partialThinkingBlocks) && sendErr.partialThinkingBlocks.length
505
- ? { thinkingBlocks: sendErr.partialThinkingBlocks }
506
- : {}),
507
- ...(Array.isArray(sendErr.partialAssistantBlocks) && sendErr.partialAssistantBlocks.length
508
- ? { assistantBlocks: sendErr.partialAssistantBlocks }
509
- : {}),
510
- ...(partialProviderReplay ? { providerReplay: partialProviderReplay } : {}),
511
- providerMetadata: sendErr.providerMetadata,
512
- partialToolRecovery: true,
513
- };
514
- return { action: 'proceed', response };
515
- }
516
- // Clean transient transport failure with zero exposure: replay the
517
- // send after a bounded wait instead of failing the turn.
518
- else if (
519
- transportRetriesUsed < TRANSPORT_RETRY_MAX &&
520
- !isProviderRecoveryExhausted(sendErr) &&
521
- ((outcome.replaySafe === true && classifyError(sendErr) === 'transient') ||
522
- // classifyError reports 'permanent' the moment anything
523
- // was exposed, so an exposed disconnect could never
524
- // reach the retraction path: name the transport
525
- // symptoms directly (stall OR non-terminal close).
526
- ((classifyError(sendErr) === 'transient' ||
527
- outcome.stallObserved === true ||
528
- // Same inversion for the truncated-stream class
529
- // (anthropic message_start-without-message_stop,
530
- // gemini/compat EOF): classifyError calls it
531
- // 'transient' only while nothing was exposed.
532
- outcome.truncatedStream === true ||
533
- // And for retryable wire error events
534
- // (response.failed server_error & co.): exposed
535
- // text is retracted, then the send is replayed.
536
- isRetryableWireErrorEvent(sendErr) ||
537
- isRetryableStreamErrorEvent(sendErr) ||
538
- // Cursor continuation streams carry a typed
539
- // transport code even when reasoning/text exposure
540
- // makes classifyError() intentionally permanent.
541
- isCursorTransientTransportError(sendErr) ||
542
- isNonTerminalStreamClose(sendErr)) &&
543
- (await retractExposedTextForReplay())))
544
- ) {
545
- const waitMs = transportRetryWaitMs(transportRetriesUsed);
546
- try {
547
- process.stderr.write(
548
- `[loop] transient send failure with no dispatched tools (sess=${sessionId || 'unknown'} ` +
549
- `iter=${nextIteration} code=${sendErr?.code ?? 'n/a'} ` +
550
- `wsCloseCode=${sendErr?.wsCloseCode ?? 'n/a'} ` +
551
- `httpStatus=${sendErr?.httpStatus ?? sendErr?.status ?? 'n/a'}); ` +
552
- `transport retry ${transportRetriesUsed + 1}/${TRANSPORT_RETRY_MAX} after ${waitMs}ms\n`
553
- );
554
- } catch {
555
- /* best-effort */
556
- }
557
- try {
558
- appendAgentTrace({
559
- kind: 'transport_retry',
560
- sessionId: sessionId || null,
561
- iteration: nextIteration,
562
- attempt: transportRetriesUsed + 1,
563
- waitMs,
564
- code: sendErr?.code ?? null,
565
- status: sendErr?.httpStatus ?? sendErr?.status ?? null,
566
- ws_close_code: sendErr?.wsCloseCode ?? null,
567
- retry_owner: 'loop',
568
- });
569
- } catch {
570
- /* best-effort */
571
- }
572
- emitLoopReconnectProgress(
573
- transportRetriesUsed + 1,
574
- waitMs,
575
- sendErr?.retryClassifier || sendErr?.midstreamClassifier || sendErr?.code || null,
576
- sendErr
577
- );
578
- await sleepMs(waitMs, undefined, signal ? { signal } : undefined);
579
- return beginFreshTransportAttempt(opts);
580
- }
581
- // Anthropic replay-shape refusal: the latest assistant turn carries
582
- // thinking blocks the API will not accept back (a thinking run it
583
- // did not produce, or an empty text block). This is deterministic —
584
- // the same body fails forever and the turn is already persisted, so
585
- // without this repair the session is dead. Drop that turn's
586
- // reasoning replay in place (its text and tool calls stay) and
587
- // replay once. No exposure guard: the request was rejected at
588
- // validation, before any generation.
589
- else if (
590
- thinkingReplayRepairUsed !== true &&
591
- isThinkingReplayRejection(sendErr) &&
592
- canRepairThinkingReplay(recoveryMessages)
593
- ) {
594
- const repairedIndex = repairThinkingReplayInPlace(recoveryMessages);
595
- try {
596
- process.stderr.write(
597
- `[loop] thinking-replay repair (sess=${sessionId || 'unknown'} ` +
598
- `iter=${nextIteration} message=${repairedIndex}); ` +
599
- 'dropped the rejected reasoning replay and replaying once\n'
600
- );
601
- } catch {
602
- /* best-effort */
603
- }
604
- try {
605
- appendAgentTrace({
606
- kind: 'thinking_replay_repair',
607
- sessionId: sessionId || null,
608
- iteration: nextIteration,
609
- messageIndex: repairedIndex,
610
- });
611
- } catch {
612
- /* best-effort */
613
- }
614
- return { action: 'retry_replay_repair' };
615
- }
616
- // Grok Build RetryWithImageStrip: drop inline images and replay
617
- // once. Safe only when no tool was dispatched. Text exposure must
618
- // be retracted first; reasoning-only high-effort streams can retry
619
- // without a text reset.
620
- else if (
621
- transportRetriesUsed < TRANSPORT_RETRY_MAX &&
622
- (shouldStripImagesForRetry(sendErr, {
623
- hasImages: promptHasInlineImages(recoveryMessages),
624
- alreadyStripped: imageStripUsed === true,
625
- }) ||
626
- (imageStripUsed !== true &&
627
- promptHasInlineImages(recoveryMessages) &&
628
- isRetryableStreamErrorEvent(sendErr))) &&
629
- outcome.sideEffectDispatched !== true &&
630
- Number(outcome.toolCallsDispatched) === 0 &&
631
- Number(outcome.toolCallsComplete) === 0 &&
632
- relayWitness.toolCallsDispatched === 0 &&
633
- (outcome.replaySafe === true || (await retractExposedTextForReplay()))
634
- ) {
635
- const stripped = stripInlineImagesFromLatestTurn(recoveryMessages);
636
- if (stripped.stripped > 0) {
637
- try {
638
- process.stderr.write(
639
- '[loop] image-strip retry (sess=' +
640
- String(sessionId || 'unknown') +
641
- ' iter=' +
642
- String(nextIteration) +
643
- ' stripped=' +
644
- String(stripped.stripped) +
645
- '); transport retry ' +
646
- String(transportRetriesUsed + 1) +
647
- '/' +
648
- String(TRANSPORT_RETRY_MAX) +
649
- '\n'
650
- );
651
- } catch {
652
- /* best-effort */
653
- }
654
- try {
655
- appendAgentTrace({
656
- kind: 'image_strip_retry',
657
- sessionId: sessionId || null,
658
- iteration: nextIteration,
659
- attempt: transportRetriesUsed + 1,
660
- stripped: stripped.stripped,
661
- });
662
- } catch {
663
- /* best-effort */
664
- }
665
- emitLoopReconnectProgress(transportRetriesUsed + 1, 0, 'image_strip');
666
- return {
667
- action: 'retry_image_strip',
668
- messages: stripped.messages,
669
- persistMessages: persistenceMessagesForConfirmedImageRejection(sendErr, recoveryMessages),
670
- };
671
- }
672
- }
673
- // Context-window-exceeded is a deterministic refusal from the API.
674
- // Recover context overflow reactively by compacting and retrying
675
- // in the same active turn. MixDog's proactive estimator can miss a
676
- // provider-specific overhead spike, so do one reactive retry by
677
- // marking the live session over-threshold and looping back through
678
- // the normal pre-send auto-compact path. If compaction/retry still
679
- // fails, surface the overflow normally.
680
- else if (!isContextOverflowError(sendErr) || !(sessionRef && typeof sessionRef.contextWindow === 'number')) {
681
- throw sendErr;
682
- }
683
- const compactPolicyForRetry = resolveWorkerCompactPolicy(sessionRef, sendTools.length ? sendTools : tools);
684
- // The reactive retry RE-SENDS the turn, so it is a replay: denied
685
- // once visible text/reasoning was relayed or a tool call was
686
- // dispatched (or ambiguously dispatched). A deterministic overflow
687
- // refusal that exposed nothing may compact and re-send.
688
- const replayPermitted = outcome.replaySafe === true;
689
- if (!contextOverflowRetryUsed && compactPolicyForRetry?.auto && replayPermitted) {
690
- // Mark the next pre-send compact as REACTIVE (driven by a
691
- // provider overflow refusal) rather than the normal proactive
692
- // pressure trigger, so the compact event/telemetry the loop
693
- // emits on the retry is distinguishable downstream.
694
- opts.onToolCall = undefined;
695
- try {
696
- process.stderr.write(
697
- `[loop] context overflow on send (sess=${sessionId || 'unknown'} iter=${nextIteration}); ` +
698
- `reactive compact retry messages=${messages.length}\n`
699
- );
700
- } catch {
701
- /* best-effort */
702
- }
703
- return { action: 'retry' };
704
- }
705
- try {
706
- process.stderr.write(
707
- `[loop] context overflow on send (sess=${sessionId || 'unknown'} iter=${nextIteration}); ` +
708
- `surfacing overflow (retryUsed=${contextOverflowRetryUsed === true} ` +
709
- `replaySafe=${outcome.replaySafe === true} replayUnsafe=${outcome.replayUnsafe === true}) ` +
710
- `messages=${messages.length}\n`
711
- );
712
- } catch {
713
- /* best-effort */
714
- }
715
- throw agentContextOverflowError(
716
- {
717
- stage: 'send',
718
- sessionId,
719
- sessionRef,
720
- model,
721
- budgetTokens: sessionRef.contextWindow,
722
- reserveTokens: compactPolicyForRetry?.reserveTokens,
723
- messageTokensEst: estimateMessagesTokensSafe(messages),
724
- },
725
- sendErr
726
- );
727
- }
728
- } finally {
729
- // Conditional restore: only unwind our own wrappers. An intentional
730
- // opts.onToolCall = undefined (overflow-retry branch) stays cleared.
731
- if (opts) {
732
- if (witnessedOnTextDelta && opts.onTextDelta === witnessedOnTextDelta) opts.onTextDelta = prevOnTextDelta;
733
- if (witnessedOnToolCall && opts.onToolCall === witnessedOnToolCall) opts.onToolCall = prevOnToolCall;
734
- if (retryAwareOnStageChange && opts.onStageChange === retryAwareOnStageChange) {
735
- opts.onStageChange = prevOnStageChange;
736
- }
737
- if (retryAwareOnStreamDelta && opts.onStreamDelta === retryAwareOnStreamDelta) {
738
- opts.onStreamDelta = prevOptsOnStreamDelta;
739
- }
740
- }
741
- if (timedOpts && timedOpts !== opts) {
742
- if (retryAwareOnStageChange && timedOpts.onStageChange === retryAwareOnStageChange) {
743
- timedOpts.onStageChange = prevOnStageChange;
744
- }
745
- if (retryAwareOnStreamDelta && timedOpts.onStreamDelta === retryAwareOnStreamDelta) {
746
- timedOpts.onStreamDelta = prevOnStreamDeltaForRetry;
747
- }
404
+ acked =
405
+ (await opts.onTextReset({
406
+ chars,
407
+ reasoning: outcome.reasoningEmitted === true,
408
+ reason: 'loop-transport-retraction',
409
+ })) === true;
410
+ } catch {
411
+ acked = false;
748
412
  }
413
+ if (!acked && !reasoningOnly) return false;
414
+ } else if (!reasoningOnly) {
415
+ return false;
416
+ }
417
+ relayWitness.textEmitted = false;
418
+ return true;
419
+ }
420
+
421
+ // One failed provider.send. Canonical stream outcome first: ONE fail-closed
422
+ // read of what the provider stream actually produced (terminal vs
423
+ // continuation, observed text/reasoning, partial/complete/dispatched tool
424
+ // calls); every branch consumes it instead of re-inferring safety from
425
+ // provider-specific flags. Branch order is the recovery precedence.
426
+ async function recoverFromSendError(sendErr, state) {
427
+ const {
428
+ opts,
429
+ model,
430
+ messages,
431
+ recoveryMessages = messages,
432
+ sessionRef,
433
+ transportRetriesUsed = 0,
434
+ imageStripUsed = false,
435
+ thinkingReplayRepairUsed = false,
436
+ relayWitness,
437
+ } = state;
438
+ const outcome = readStreamOutcome(sendErr, relayWitness);
439
+ const retract = () => retractExposedTextForReplay({ outcome, sendErr, opts, relayWitness });
440
+ if (isPromotableIncomplete(sendErr, outcome)) {
441
+ return { action: 'proceed', response: promotedIncompleteResponse(sendErr, model, opts) };
442
+ }
443
+ if (isExposedNoToolStall(sendErr, outcome)) {
444
+ return recoverExposedStall(sendErr, outcome, state, retract);
445
+ }
446
+ if (isCompleteToolCallStall(sendErr, outcome)) {
447
+ return recoverPartialToolCalls(sendErr, state);
448
+ }
449
+ // Clean transient transport failure with zero exposure: replay the send
450
+ // after a bounded wait instead of failing the turn.
451
+ if (
452
+ transportRetriesUsed < retryBudgetFor(sendErr) &&
453
+ !isProviderRecoveryExhausted(sendErr) &&
454
+ (await transportReplayPermitted(sendErr, outcome, retract))
455
+ ) {
456
+ return retryTransport(sendErr, state);
457
+ }
458
+ // Anthropic replay-shape refusal: the latest assistant turn carries
459
+ // thinking blocks the API will not accept back (a thinking run it did not
460
+ // produce, or an empty text block). This is deterministic — the same body
461
+ // fails forever and the turn is already persisted, so without this repair
462
+ // the session is dead. No exposure guard: the request was rejected at
463
+ // validation, before any generation.
464
+ if (
465
+ thinkingReplayRepairUsed !== true &&
466
+ isThinkingReplayRejection(sendErr) &&
467
+ canRepairThinkingReplay(recoveryMessages)
468
+ ) {
469
+ return repairThinkingReplay(recoveryMessages, state);
470
+ }
471
+ // Grok Build RetryWithImageStrip: drop inline images and replay once. Safe
472
+ // only when no tool was dispatched. Text exposure must be retracted first;
473
+ // reasoning-only high-effort streams can retry without a text reset.
474
+ if (
475
+ imageStripEligible(sendErr, outcome, { recoveryMessages, imageStripUsed, transportRetriesUsed, relayWitness }) &&
476
+ (outcome.replaySafe === true || (await retract()))
477
+ ) {
478
+ const stripped = retryWithImageStrip(sendErr, recoveryMessages, state);
479
+ if (stripped) return stripped;
480
+ } else if (!isContextOverflowError(sendErr) || !(sessionRef && typeof sessionRef.contextWindow === 'number')) {
481
+ throw sendErr;
482
+ }
483
+ return recoverContextOverflow(sendErr, outcome, state);
484
+ }
485
+
486
+ // Gemini REST/SDK reports MAX_TOKENS by throwing a typed
487
+ // ProviderIncompleteError after preserving the streamed candidate. Only that
488
+ // exact, safe no-tool output-limit shape — terminal observed (explicit finish
489
+ // reason) and no tool exposure at all — is promoted to a regular truncated
490
+ // response; moderation/OTHER/tool-bearing and unrelated errors continue
491
+ // through their existing error paths.
492
+ function isPromotableIncomplete(sendErr, outcome) {
493
+ return (
494
+ sendErr?.providerIncomplete === true &&
495
+ sendErr.code === 'PROVIDER_INCOMPLETE' &&
496
+ isOutputLimitStopReason(sendErr.finishReason) &&
497
+ typeof sendErr.partialContent === 'string' &&
498
+ sendErr.partialContent.trim().length > 0 &&
499
+ outcome.successEligible === true &&
500
+ outcome.toolCallsStarted !== true &&
501
+ outcome.sideEffectDispatched !== true
502
+ );
503
+ }
504
+
505
+ function promotedIncompleteResponse(sendErr, model, opts) {
506
+ const partialProviderReplay = cloneProviderReplay(sendErr.partialProviderReplay);
507
+ return {
508
+ content: sendErr.partialContent,
509
+ model: sendErr.model || model,
510
+ toolCalls: undefined,
511
+ usage: normalizedIncompleteUsage(sendErr.rawUsage),
512
+ stopReason: sendErr.finishReason,
513
+ truncated: true,
514
+ ...(partialProviderReplay ? { providerReplay: partialProviderReplay } : {}),
515
+ providerMetadata: sendErr.providerMetadata,
516
+ providerState: opts.providerState,
517
+ providerIncompleteRecovery: true,
518
+ };
519
+ }
520
+
521
+ // Exhausted no-tool stall: NOT a success. A FINAL, no-tool stream that
522
+ // wedges (ping-only) carries streamed assistant text on the
523
+ // StreamStalledError, but the turn never completed — the model may have been
524
+ // mid-sentence, and there is no completion signal that says the work is
525
+ // done. Promoting it to a normal terminal response silently reported
526
+ // truncated/aborted turns as finished. A stall WITH complete parsed tool
527
+ // calls is a different, genuinely recoverable case (isCompleteToolCallStall).
528
+ function isExposedNoToolStall(sendErr, outcome) {
529
+ return (
530
+ outcome.stallObserved === true &&
531
+ outcome.terminalObserved !== true &&
532
+ typeof sendErr.partialContent === 'string' &&
533
+ sendErr.partialContent.trim().length > 0 &&
534
+ outcome.toolCallsComplete === 0
535
+ );
536
+ }
537
+
538
+ // Retractable shape: text-only exposure with the owner's acknowledgement
539
+ // replays on a fresh request instead of failing the turn. Non-acked (or
540
+ // tool-bearing) shapes keep the explicit-failure contract: no completion
541
+ // signal means no completed turn, and the partial is persisted — the
542
+ // already-streamed text is preserved by the interruption/error persistence
543
+ // path (turn-interruption.mjs records the deltas and commits them as the
544
+ // partial assistant message alongside the error), so nothing visible is
545
+ // lost while the caller/owner-notify still sees a failed turn.
546
+ // NOTE: no classifyError gate here — an exposed stall is stamped
547
+ // unsafeToRetry, which the general classifier reads as terminal, but that
548
+ // unsafety is exactly what the retraction removes (observed live:
549
+ // make-mips-interpreter failed twice because this guard demanded
550
+ // 'transient' and never fired).
551
+ async function recoverExposedStall(sendErr, outcome, state, retract) {
552
+ const { transportRetriesUsed = 0 } = state;
553
+ const exposedRetryBudget = retryBudgetFor(sendErr);
554
+ const len = sendErr.partialContent.length;
555
+ if (transportRetriesUsed < exposedRetryBudget && !isProviderRecoveryExhausted(sendErr) && (await retract())) {
556
+ return scheduleTransportReplay(sendErr, state, {
557
+ budget: exposedRetryBudget,
558
+ note: `[loop] exposed-text stall retracted (${loopTag(state)} len=${len})`,
559
+ trace: { kind: 'exposed_text_retraction_retry', partialContentLen: len },
560
+ classifier: outcome.stallObserved ? 'stream_stalled' : 'stream_closed',
561
+ });
562
+ }
563
+ logLoop(
564
+ `[loop] final stream stalled with partial text (${loopTag(state)} len=${len}); failing the turn (partial preserved via interrupted-turn persistence)`
565
+ );
566
+ traceLoop(state, 'stall_partial_final_rejected', {
567
+ partialContentLen: len,
568
+ pendingToolUse: outcome.pendingToolInput,
569
+ emittedToolCall: outcome.sideEffectDispatched,
570
+ terminalObserved: outcome.terminalObserved,
571
+ });
572
+ throw sendErr;
573
+ }
574
+
575
+ // Loop-level replay after a bounded wait: the stderr note, the trace entry,
576
+ // the caller-visible "Reconnecting... n/max" stage, then a fresh attempt.
577
+ async function scheduleTransportReplay(sendErr, state, { budget, note, trace, classifier }) {
578
+ const { opts, signal, transportRetriesUsed = 0 } = state;
579
+ const attempt = transportRetriesUsed + 1;
580
+ const waitMs = transportRetryWaitMs(transportRetriesUsed, sendErr);
581
+ logLoop(`${note}; transport retry ${attempt}/${budget} after ${waitMs}ms`);
582
+ const { kind, ...fields } = trace;
583
+ traceLoop(state, kind, { attempt, waitMs, ...fields });
584
+ emitLoopReconnectProgress(opts, { attempt, maxAttempts: budget, waitMs, classifier, error: sendErr });
585
+ await sleepMs(waitMs, undefined, signal ? { signal } : undefined);
586
+ return beginFreshTransportAttempt(opts, budget);
587
+ }
588
+
589
+ // Partial tool-call recovery (agent-hang fix): a stream that ends AFTER
590
+ // fully-parsed tool calls were emitted used to lose the whole turn —
591
+ // unsafeToRetry blocks the mid-stream replay (correct: a replay would re-run
592
+ // side-effecting tools) and the loop gave up, discarding tool work that had
593
+ // ALREADY completed via eager dispatch. ANY non-terminal end qualifies, not
594
+ // just a watchdog stall: continuing is not replaying — the parsed calls
595
+ // resolve from the pending map without re-running, their results commit to
596
+ // history, and the NEXT request carries them forward. pendingToolInput stays
597
+ // the hard guard: half-streamed arguments are not a tool call. Named
598
+ // TRANSPORT symptoms only: a typed refusal (context overflow, policy, quota)
599
+ // also arrives without a terminal frame, but nothing was generated there and
600
+ // continuing would paper over the refusal.
601
+ function isCompleteToolCallStall(sendErr, outcome) {
602
+ return (
603
+ outcome.terminalObserved !== true &&
604
+ (outcome.stallObserved === true ||
605
+ outcome.truncatedStream === true ||
606
+ isNonTerminalStreamClose(sendErr) ||
607
+ isConnectionFailure(sendErr)) &&
608
+ outcome.pendingToolInput !== true &&
609
+ outcome.toolCallsComplete > 0 &&
610
+ Array.isArray(sendErr.partialToolCalls) &&
611
+ sendErr.partialToolCalls.length > 0
612
+ );
613
+ }
614
+
615
+ // The recovered partial as a normal tool-call turn: eager-dispatched
616
+ // (read-only) calls resolve from the pending map without re-running,
617
+ // side-effecting calls were never started during streaming and execute
618
+ // exactly once. providerState stays undefined so the next iteration resends
619
+ // a full frame on a fresh stream.
620
+ function recoveredToolCallResponse(sendErr, model) {
621
+ const partialProviderReplay = cloneProviderReplay(sendErr.partialProviderReplay);
622
+ return {
623
+ content: typeof sendErr.partialContent === 'string' ? sendErr.partialContent : '',
624
+ model: sendErr.partialModel || model,
625
+ toolCalls: sendErr.partialToolCalls.slice(),
626
+ usage: sendErr.partialUsage || undefined,
627
+ stopReason: 'tool_use',
628
+ hasThinkingContent: sendErr.partialHasThinking === true,
629
+ // Ordered provider block state captured before the stall. Anthropic
630
+ // REQUIRES the verbatim thinking blocks (with their signatures) back
631
+ // ahead of tool_use on the continuation turn, and a native
632
+ // `server_tool_use` call is only valid immediately followed by its
633
+ // result block — so the recovered tool turn must replay exactly what a
634
+ // successful turn would have returned. The loop's committer already
635
+ // drops the redundant `thinkingBlocks` copy when `assistantBlocks` is
636
+ // present (which contains them verbatim), so blocks are neither lost
637
+ // nor doubled.
638
+ ...(Array.isArray(sendErr.partialThinkingBlocks) && sendErr.partialThinkingBlocks.length
639
+ ? { thinkingBlocks: sendErr.partialThinkingBlocks }
640
+ : {}),
641
+ ...(Array.isArray(sendErr.partialAssistantBlocks) && sendErr.partialAssistantBlocks.length
642
+ ? { assistantBlocks: sendErr.partialAssistantBlocks }
643
+ : {}),
644
+ ...(partialProviderReplay ? { providerReplay: partialProviderReplay } : {}),
645
+ providerMetadata: sendErr.providerMetadata,
646
+ partialToolRecovery: true,
647
+ };
648
+ }
649
+
650
+ function recoverPartialToolCalls(sendErr, state) {
651
+ const toolCalls = sendErr.partialToolCalls.length;
652
+ logLoop(
653
+ `[loop] stream ended after ${toolCalls} complete tool call(s) (${loopTag(state)}); recovering as tool-call turn instead of failing`
654
+ );
655
+ traceLoop(state, 'partial_tool_recovery', {
656
+ toolCalls,
657
+ partialContentLen: typeof sendErr.partialContent === 'string' ? sendErr.partialContent.length : 0,
658
+ });
659
+ return { action: 'proceed', response: recoveredToolCallResponse(sendErr, state.model) };
660
+ }
661
+
662
+ // Zero-exposure transient failures replay outright. classifyError reports
663
+ // 'permanent' the moment anything was exposed, so an exposed disconnect
664
+ // could never reach the retraction path: name the transport symptoms
665
+ // directly — stall, truncated stream (anthropic
666
+ // message_start-without-message_stop, gemini/compat EOF), retryable wire /
667
+ // stream error events (response.failed server_error & co.), Cursor
668
+ // continuation streams that carry a typed transport code even when
669
+ // reasoning/text exposure makes classifyError() intentionally permanent,
670
+ // non-terminal close — then retract the exposed text and replay.
671
+ async function transportReplayPermitted(sendErr, outcome, retract) {
672
+ if (outcome.replaySafe === true && classifyError(sendErr) === 'transient') return true;
673
+ const transportSymptom =
674
+ classifyError(sendErr) === 'transient' ||
675
+ outcome.stallObserved === true ||
676
+ outcome.truncatedStream === true ||
677
+ isRetryableWireErrorEvent(sendErr) ||
678
+ isRetryableStreamErrorEvent(sendErr) ||
679
+ isCursorTransientTransportError(sendErr) ||
680
+ isNonTerminalStreamClose(sendErr);
681
+ return transportSymptom && (await retract());
682
+ }
683
+
684
+ function retryTransport(sendErr, state) {
685
+ return scheduleTransportReplay(sendErr, state, {
686
+ budget: retryBudgetFor(sendErr),
687
+ note:
688
+ `[loop] transient send failure with no dispatched tools (${loopTag(state)} code=${sendErr?.code ?? 'n/a'} ` +
689
+ `wsCloseCode=${sendErr?.wsCloseCode ?? 'n/a'} httpStatus=${sendErr?.httpStatus ?? sendErr?.status ?? 'n/a'})`,
690
+ trace: {
691
+ kind: 'transport_retry',
692
+ code: sendErr?.code ?? null,
693
+ status: sendErr?.httpStatus ?? sendErr?.status ?? null,
694
+ ws_close_code: sendErr?.wsCloseCode ?? null,
695
+ retry_owner: 'loop',
696
+ },
697
+ classifier: sendErr?.retryClassifier || sendErr?.midstreamClassifier || sendErr?.code || null,
698
+ });
699
+ }
700
+
701
+ // Drops that turn's reasoning replay in place (its text and tool calls
702
+ // stay) and replays once.
703
+ function repairThinkingReplay(recoveryMessages, state) {
704
+ const repairedIndex = repairThinkingReplayInPlace(recoveryMessages);
705
+ logLoop(
706
+ `[loop] thinking-replay repair (${loopTag(state)} message=${repairedIndex}); dropped the rejected reasoning replay and replaying once`
707
+ );
708
+ traceLoop(state, 'thinking_replay_repair', { messageIndex: repairedIndex });
709
+ return { action: 'retry_replay_repair' };
710
+ }
711
+
712
+ function imageStripEligible(
713
+ sendErr,
714
+ outcome,
715
+ { recoveryMessages, imageStripUsed, transportRetriesUsed, relayWitness }
716
+ ) {
717
+ return (
718
+ transportRetriesUsed < TRANSPORT_RETRY_MAX &&
719
+ (shouldStripImagesForRetry(sendErr, {
720
+ hasImages: promptHasInlineImages(recoveryMessages),
721
+ alreadyStripped: imageStripUsed === true,
722
+ }) ||
723
+ (imageStripUsed !== true && promptHasInlineImages(recoveryMessages) && isRetryableStreamErrorEvent(sendErr))) &&
724
+ outcome.sideEffectDispatched !== true &&
725
+ Number(outcome.toolCallsDispatched) === 0 &&
726
+ Number(outcome.toolCallsComplete) === 0 &&
727
+ relayWitness.toolCallsDispatched === 0
728
+ );
729
+ }
730
+
731
+ function retryWithImageStrip(sendErr, recoveryMessages, state) {
732
+ const { opts, transportRetriesUsed = 0 } = state;
733
+ const stripped = stripInlineImagesFromLatestTurn(recoveryMessages);
734
+ if (!(stripped.stripped > 0)) return null;
735
+ const attempt = transportRetriesUsed + 1;
736
+ logLoop(
737
+ `[loop] image-strip retry (${loopTag(state)} stripped=${stripped.stripped}); transport retry ${attempt}/${TRANSPORT_RETRY_MAX}`
738
+ );
739
+ traceLoop(state, 'image_strip_retry', { attempt, stripped: stripped.stripped });
740
+ emitLoopReconnectProgress(opts, {
741
+ attempt,
742
+ maxAttempts: TRANSPORT_RETRY_MAX,
743
+ waitMs: 0,
744
+ classifier: 'image_strip',
745
+ error: null,
746
+ });
747
+ return {
748
+ action: 'retry_image_strip',
749
+ messages: stripped.messages,
750
+ persistMessages: persistenceMessagesForConfirmedImageRejection(sendErr, recoveryMessages),
751
+ };
752
+ }
753
+
754
+ // Context-window-exceeded is a deterministic refusal from the API. Recover
755
+ // context overflow reactively by compacting and retrying in the same active
756
+ // turn: the proactive estimator can miss a provider-specific overhead
757
+ // spike, so do one reactive retry by marking the live session
758
+ // over-threshold and looping back through the normal pre-send auto-compact
759
+ // path. If compaction/retry still fails, surface the overflow normally.
760
+ function recoverContextOverflow(sendErr, outcome, state) {
761
+ const { opts, messages, sendTools, tools, sessionId, sessionRef, model, contextOverflowRetryUsed } = state;
762
+ const compactPolicyForRetry = resolveWorkerCompactPolicy(sessionRef, sendTools.length ? sendTools : tools);
763
+ // The reactive retry RE-SENDS the turn, so it is a replay: denied once
764
+ // visible text/reasoning was relayed or a tool call was dispatched (or
765
+ // ambiguously dispatched). A deterministic overflow refusal that exposed
766
+ // nothing may compact and re-send.
767
+ const replayPermitted = outcome.replaySafe === true;
768
+ if (!contextOverflowRetryUsed && compactPolicyForRetry?.auto && replayPermitted) {
769
+ // Mark the next pre-send compact as REACTIVE (driven by a provider
770
+ // overflow refusal) rather than the normal proactive pressure trigger,
771
+ // so the compact event/telemetry the loop emits on the retry is
772
+ // distinguishable downstream.
773
+ opts.onToolCall = undefined;
774
+ logLoop(`[loop] context overflow on send (${loopTag(state)}); reactive compact retry messages=${messages.length}`);
775
+ return { action: 'retry' };
749
776
  }
750
- return { action: 'proceed', response };
777
+ logLoop(
778
+ `[loop] context overflow on send (${loopTag(state)}); surfacing overflow (retryUsed=${contextOverflowRetryUsed === true} ` +
779
+ `replaySafe=${outcome.replaySafe === true} replayUnsafe=${outcome.replayUnsafe === true}) messages=${messages.length}`
780
+ );
781
+ throw agentContextOverflowError(
782
+ {
783
+ stage: 'send',
784
+ sessionId,
785
+ sessionRef,
786
+ model,
787
+ budgetTokens: sessionRef.contextWindow,
788
+ reserveTokens: compactPolicyForRetry?.reserveTokens,
789
+ messageTokensEst: estimateMessagesTokensSafe(messages),
790
+ },
791
+ sendErr
792
+ );
751
793
  }