mixdog 0.9.171 → 0.9.173

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 (1708) hide show
  1. package/package.json +4 -3
  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/code-graph-description-contract.mjs +1 -2
  6. package/scripts/context-renewal-live-check.mjs +1 -1
  7. package/scripts/coverage-query.mjs +27 -0
  8. package/scripts/daemon-stub.mjs +1 -2
  9. package/scripts/fixtures/patch-replay-corpus.json +85 -28
  10. package/scripts/generate-runtime-manifest.mjs +13 -17
  11. package/scripts/graph-parity.mjs +312 -226
  12. package/scripts/lib/coverage.mjs +309 -0
  13. package/scripts/lib/embedding-model-bench-core.mjs +9 -11
  14. package/scripts/lib/embedding-model-bench-core.test.mjs +47 -0
  15. package/scripts/lib/parse-since.mjs +22 -0
  16. package/scripts/lib/recall-bench-eval.mjs +8 -16
  17. package/scripts/lib/run-node-tests.mjs +152 -0
  18. package/scripts/lib/test-failure-records.mjs +46 -0
  19. package/scripts/lib/test-failure-summary.mjs +59 -0
  20. package/scripts/lib/test-summary-reporter.mjs +30 -0
  21. package/scripts/llm-trace-summary.mjs +2 -23
  22. package/scripts/local-provider-live-check.mjs +1 -1
  23. package/scripts/media-image-live.mjs +4 -6
  24. package/scripts/mouse-probe.mjs +2 -14
  25. package/scripts/native-binary-arch.mjs +1 -1
  26. package/scripts/office/author-deck.mjs +4 -1
  27. package/scripts/office/build-pptx-icons.mjs +0 -1
  28. package/scripts/patch-replay.mjs +4 -1
  29. package/scripts/perf/transcript-baseline.mjs +10 -8
  30. package/scripts/perf/transcript-runtime-probe.mjs +20 -4
  31. package/scripts/pg-memory-diet.mjs +10 -9
  32. package/scripts/prune-embedding-runtime.mjs +1 -20
  33. package/scripts/recall-bench-cases.json +64 -9
  34. package/scripts/recall-event-cases.json +398 -41
  35. package/scripts/recall-history-cases.json +396 -36
  36. package/scripts/recall-quality-cases.json +146 -17
  37. package/scripts/recall-repo-cases.json +188 -24
  38. package/scripts/recall-usecase-cases.json +96 -16
  39. package/scripts/release-timing-report.mjs +4 -1
  40. package/scripts/routing-corpus.mjs +113 -143
  41. package/scripts/run-office-live-tests.mjs +2 -1
  42. package/scripts/session-diag.mjs +2 -28
  43. package/scripts/session-sweep.mjs +103 -57
  44. package/scripts/smoke-runtime-negative.sh +22 -16
  45. package/scripts/test-direct.mjs +5 -0
  46. package/scripts/test.mjs +117 -54
  47. package/scripts/tool-efficiency-diag.mjs +4 -1
  48. package/scripts/tool-failures.mjs +1 -20
  49. package/scripts/tui-frame-harness.mjs +7 -8
  50. package/src/app.mjs +79 -74
  51. package/src/cli.mjs +0 -2
  52. package/src/defaults/skills/browser-use/SKILL.md +41 -15
  53. package/src/defaults/skills/code-tidy/SKILL.md +212 -77
  54. package/src/defaults/skills/code-tidy/references/agent-cleanup.md +149 -52
  55. package/src/defaults/skills/code-tidy/references/dead-code.md +61 -19
  56. package/src/defaults/skills/computer-use/SKILL.md +28 -8
  57. package/src/defaults/skills/docx/SKILL.md +2 -0
  58. package/src/defaults/skills/docx/references/native-authoring.md +7 -2
  59. package/src/defaults/skills/goal-management/SKILL.md +25 -11
  60. package/src/defaults/skills/local-provider/SKILL.md +1 -1
  61. package/src/defaults/skills/memory-management/SKILL.md +1 -1
  62. package/src/defaults/skills/pdf/SKILL.md +3 -2
  63. package/src/defaults/skills/pptx/SKILL.md +18 -13
  64. package/src/defaults/skills/pptx/references/charts.md +10 -5
  65. package/src/defaults/skills/pptx/references/direction.md +1 -1
  66. package/src/defaults/skills/pptx/references/kit.md +153 -44
  67. package/src/defaults/skills/pptx/references/pictures.md +10 -1
  68. package/src/defaults/skills/pptx/scripts/qc-pages.mjs +161 -116
  69. package/src/defaults/skills/setup/SKILL.md +1 -1
  70. package/src/defaults/skills/skill-creator/SKILL.md +3 -3
  71. package/src/defaults/skills/skill-creator/references/design.md +3 -3
  72. package/src/defaults/skills/xlsx/SKILL.md +10 -7
  73. package/src/headless-exec.mjs +329 -698
  74. package/src/headless-json-lifecycle.mjs +461 -0
  75. package/src/headless-role.mjs +1 -1
  76. package/src/help.mjs +2 -2
  77. package/src/lib/keychain-cjs.cjs +7 -8
  78. package/src/lib/mixdog-debug.cjs +4 -5
  79. package/src/lib/plugin-paths.cjs +2 -2
  80. package/src/lib/rules-builder.cjs +22 -61
  81. package/src/lib/text-utils.cjs +1 -3
  82. package/src/repl/runtime-handle.mjs +46 -0
  83. package/src/repl/slash-commands.mjs +130 -0
  84. package/src/repl/stream-sink.mjs +129 -0
  85. package/src/repl/turn-output.mjs +51 -0
  86. package/src/repl.mjs +99 -381
  87. package/src/rules/agent/40-cycle1-agent.md +4 -3
  88. package/src/rules/agent/AGENT.md +11 -11
  89. package/src/rules/lead/LEAD.md +14 -12
  90. package/src/rules/shared/05-parallel-calls.md +3 -5
  91. package/src/rules/shared/15-skills.md +4 -0
  92. package/src/rules/shared/45-destructive.md +4 -4
  93. package/src/rules/shared/70-delivery.md +10 -3
  94. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/abort-link.mjs +44 -0
  95. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/ask-args.mjs +128 -0
  96. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/preset.mjs +72 -0
  97. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/session-prep.mjs +114 -0
  98. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/turn.mjs +111 -0
  99. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/watchdog.mjs +80 -0
  100. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch.mjs +112 -606
  101. package/src/runtime/agent/orchestrator/agent-runtime/agent-progress-watchdog.mjs +1 -2
  102. package/src/runtime/agent/orchestrator/agent-runtime/cache-strategy.mjs +84 -88
  103. package/src/runtime/agent/orchestrator/agent-trace-format.mjs +41 -44
  104. package/src/runtime/agent/orchestrator/agent-trace-io.mjs +18 -25
  105. package/src/runtime/agent/orchestrator/agent-trace.mjs +6 -41
  106. package/src/runtime/agent/orchestrator/cache-break-trace.mjs +3 -2
  107. package/src/runtime/agent/orchestrator/cache-mtime.mjs +2 -2
  108. package/src/runtime/agent/orchestrator/config-presets.mjs +1 -1
  109. package/src/runtime/agent/orchestrator/config-providers-merge.mjs +56 -0
  110. package/src/runtime/agent/orchestrator/config-storage.mjs +9 -11
  111. package/src/runtime/agent/orchestrator/config.mjs +37 -77
  112. package/src/runtime/agent/orchestrator/context/deferred-tools.mjs +5 -14
  113. package/src/runtime/agent/orchestrator/context/role-instructions.mjs +9 -17
  114. package/src/runtime/agent/orchestrator/context/skill-catalog.mjs +11 -17
  115. package/src/runtime/agent/orchestrator/context/skill-state.mjs +0 -16
  116. package/src/runtime/agent/orchestrator/dispatch-persist.mjs +2 -2
  117. package/src/runtime/agent/orchestrator/internal-agents.mjs +4 -7
  118. package/src/runtime/agent/orchestrator/mcp/child-tree.mjs +1 -2
  119. package/src/runtime/agent/orchestrator/mcp/client-config.mjs +238 -0
  120. package/src/runtime/agent/orchestrator/mcp/client-handshake.mjs +70 -0
  121. package/src/runtime/agent/orchestrator/mcp/client-transport.mjs +110 -0
  122. package/src/runtime/agent/orchestrator/mcp/client.mjs +89 -438
  123. package/src/runtime/agent/orchestrator/providers/account-pool.mjs +167 -71
  124. package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +55 -116
  125. package/src/runtime/agent/orchestrator/providers/anthropic-api-recovery.mjs +75 -0
  126. package/src/runtime/agent/orchestrator/providers/anthropic-api-request.mjs +152 -0
  127. package/src/runtime/agent/orchestrator/providers/anthropic-api-transport.mjs +168 -0
  128. package/src/runtime/agent/orchestrator/providers/anthropic-betas.mjs +0 -10
  129. package/src/runtime/agent/orchestrator/providers/anthropic-effort.mjs +1 -1
  130. package/src/runtime/agent/orchestrator/providers/anthropic-fast-mode.mjs +3 -11
  131. package/src/runtime/agent/orchestrator/providers/anthropic-leaked-toolcall.mjs +8 -4
  132. package/src/runtime/agent/orchestrator/providers/anthropic-max-tokens.mjs +2 -3
  133. package/src/runtime/agent/orchestrator/providers/anthropic-messages.mjs +25 -13
  134. package/src/runtime/agent/orchestrator/providers/anthropic-midstream-recovery.mjs +248 -0
  135. package/src/runtime/agent/orchestrator/providers/anthropic-model-resolve.mjs +11 -4
  136. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-client-version.mjs +2 -3
  137. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-credentials.mjs +6 -6
  138. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-midstream.mjs +33 -0
  139. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-recovery.mjs +131 -0
  140. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-request/abort-wiring.mjs +67 -0
  141. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-request/gzip-post.mjs +52 -0
  142. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-request/initial-status.mjs +75 -0
  143. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-request.mjs +136 -0
  144. package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +205 -798
  145. package/src/runtime/agent/orchestrator/providers/anthropic-recovery-guards.mjs +86 -0
  146. package/src/runtime/agent/orchestrator/providers/anthropic-server-fallback.mjs +2 -1
  147. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/leak-guard.mjs +75 -0
  148. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-blocks.mjs +112 -0
  149. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events/content-block-delta.mjs +86 -0
  150. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events/content-block-start.mjs +82 -0
  151. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events/content-block-stop.mjs +101 -0
  152. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events/message-events.mjs +67 -0
  153. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events.mjs +22 -0
  154. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-outcome.mjs +156 -0
  155. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-state.mjs +37 -0
  156. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn.mjs +55 -0
  157. package/src/runtime/agent/orchestrator/providers/anthropic-sse-watchdogs.mjs +162 -0
  158. package/src/runtime/agent/orchestrator/providers/anthropic-sse.mjs +78 -918
  159. package/src/runtime/agent/orchestrator/providers/anthropic-turn-result.mjs +88 -0
  160. package/src/runtime/agent/orchestrator/providers/anthropic.mjs +88 -594
  161. package/src/runtime/agent/orchestrator/providers/antigravity-oauth-catalog.mjs +7 -2
  162. package/src/runtime/agent/orchestrator/providers/antigravity-oauth-login.mjs +4 -5
  163. package/src/runtime/agent/orchestrator/providers/antigravity-oauth-tokens.mjs +2 -2
  164. package/src/runtime/agent/orchestrator/providers/antigravity-oauth.mjs +42 -299
  165. package/src/runtime/agent/orchestrator/providers/antigravity-request.mjs +31 -24
  166. package/src/runtime/agent/orchestrator/providers/antigravity-response.mjs +101 -0
  167. package/src/runtime/agent/orchestrator/providers/antigravity-stream.mjs +161 -0
  168. package/src/runtime/agent/orchestrator/providers/antigravity-transport.mjs +114 -0
  169. package/src/runtime/agent/orchestrator/providers/api-usage.mjs +2 -7
  170. package/src/runtime/agent/orchestrator/providers/cursor-auth.mjs +8 -9
  171. package/src/runtime/agent/orchestrator/providers/cursor-wire-exec.mjs +368 -0
  172. package/src/runtime/agent/orchestrator/providers/cursor-wire-models.mjs +96 -0
  173. package/src/runtime/agent/orchestrator/providers/cursor-wire-normalization.mjs +182 -103
  174. package/src/runtime/agent/orchestrator/providers/cursor-wire-protobuf.mjs +2 -2
  175. package/src/runtime/agent/orchestrator/providers/cursor-wire-request.mjs +197 -0
  176. package/src/runtime/agent/orchestrator/providers/cursor-wire-stream-bridge.mjs +157 -0
  177. package/src/runtime/agent/orchestrator/providers/cursor-wire-stream-messages.mjs +106 -0
  178. package/src/runtime/agent/orchestrator/providers/cursor-wire-stream-sink.mjs +53 -0
  179. package/src/runtime/agent/orchestrator/providers/cursor-wire-transport.mjs +269 -0
  180. package/src/runtime/agent/orchestrator/providers/cursor-wire.mjs +117 -1246
  181. package/src/runtime/agent/orchestrator/providers/cursor.mjs +261 -183
  182. package/src/runtime/agent/orchestrator/providers/custom-tool-wire.mjs +1 -1
  183. package/src/runtime/agent/orchestrator/providers/gemini-cache-policy.mjs +266 -0
  184. package/src/runtime/agent/orchestrator/providers/gemini-cache.mjs +3 -2
  185. package/src/runtime/agent/orchestrator/providers/gemini-request-body.mjs +54 -0
  186. package/src/runtime/agent/orchestrator/providers/gemini-response.mjs +145 -0
  187. package/src/runtime/agent/orchestrator/providers/gemini-rest-stream/sse-lines.mjs +21 -0
  188. package/src/runtime/agent/orchestrator/providers/gemini-rest-stream/watchdogs.mjs +68 -0
  189. package/src/runtime/agent/orchestrator/providers/gemini-schema.mjs +65 -56
  190. package/src/runtime/agent/orchestrator/providers/gemini-sdk-request.mjs +107 -0
  191. package/src/runtime/agent/orchestrator/providers/gemini-sdk-stream/cancellation.mjs +71 -0
  192. package/src/runtime/agent/orchestrator/providers/gemini-sdk-stream/reader.mjs +108 -0
  193. package/src/runtime/agent/orchestrator/providers/gemini-stream.mjs +71 -283
  194. package/src/runtime/agent/orchestrator/providers/gemini.mjs +431 -781
  195. package/src/runtime/agent/orchestrator/providers/grok-oauth-login.mjs +3 -4
  196. package/src/runtime/agent/orchestrator/providers/grok-oauth-tokens.mjs +16 -24
  197. package/src/runtime/agent/orchestrator/providers/grok-oauth.mjs +2 -8
  198. package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +17 -12
  199. package/src/runtime/agent/orchestrator/providers/lib/gemini-model-catalog.mjs +9 -7
  200. package/src/runtime/agent/orchestrator/providers/lib/grok-tool-schema.mjs +77 -63
  201. package/src/runtime/agent/orchestrator/providers/lib/oauth-pkce.mjs +1 -1
  202. package/src/runtime/agent/orchestrator/providers/lib/openai-tool-args.mjs +4 -2
  203. package/src/runtime/agent/orchestrator/providers/lib/responses-terminal-fields.mjs +28 -0
  204. package/src/runtime/agent/orchestrator/providers/lib/stream-outcome.mjs +3 -1
  205. package/src/runtime/agent/orchestrator/providers/lib/usage-primitives.mjs +0 -7
  206. package/src/runtime/agent/orchestrator/providers/media-normalization.mjs +93 -50
  207. package/src/runtime/agent/orchestrator/providers/model-cache.mjs +2 -2
  208. package/src/runtime/agent/orchestrator/providers/model-catalog-projection.mjs +9 -7
  209. package/src/runtime/agent/orchestrator/providers/model-catalog.mjs +21 -21
  210. package/src/runtime/agent/orchestrator/providers/model-list-sanitize.mjs +2 -2
  211. package/src/runtime/agent/orchestrator/providers/model-pricing-rates.mjs +8 -7
  212. package/src/runtime/agent/orchestrator/providers/oauth-usage.mjs +167 -124
  213. package/src/runtime/agent/orchestrator/providers/openai-codex-metadata.mjs +5 -5
  214. package/src/runtime/agent/orchestrator/providers/openai-codex-model.mjs +5 -8
  215. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-send.mjs +243 -0
  216. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/chunk-events.mjs +46 -0
  217. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/stream-result.mjs +82 -0
  218. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/stream-state.mjs +127 -0
  219. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/tool-call-acc.mjs +69 -0
  220. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream.mjs +35 -302
  221. package/src/runtime/agent/orchestrator/providers/openai-compat-models.mjs +78 -0
  222. package/src/runtime/agent/orchestrator/providers/openai-compat-options.mjs +76 -0
  223. package/src/runtime/agent/orchestrator/providers/openai-compat-response-normalization.mjs +358 -0
  224. package/src/runtime/agent/orchestrator/providers/openai-compat-responses-events.mjs +342 -0
  225. package/src/runtime/agent/orchestrator/providers/openai-compat-responses-state.mjs +172 -0
  226. package/src/runtime/agent/orchestrator/providers/openai-compat-responses.mjs +51 -43
  227. package/src/runtime/agent/orchestrator/providers/openai-compat-stream-common.mjs +24 -1
  228. package/src/runtime/agent/orchestrator/providers/openai-compat-stream.mjs +32 -534
  229. package/src/runtime/agent/orchestrator/providers/openai-compat-trace.mjs +2 -8
  230. package/src/runtime/agent/orchestrator/providers/openai-compat-wire.mjs +11 -11
  231. package/src/runtime/agent/orchestrator/providers/openai-compat-xai-send.mjs +262 -0
  232. package/src/runtime/agent/orchestrator/providers/openai-compat-xai.mjs +23 -24
  233. package/src/runtime/agent/orchestrator/providers/openai-compat.mjs +35 -970
  234. package/src/runtime/agent/orchestrator/providers/openai-http-sse-request.mjs +228 -0
  235. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-events/output-items.mjs +110 -0
  236. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-events/terminal-frames.mjs +122 -0
  237. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-events.mjs +69 -0
  238. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-items.mjs +142 -0
  239. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-outcome.mjs +101 -0
  240. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-stamps.mjs +114 -0
  241. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-state.mjs +74 -0
  242. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/text-relay.mjs +114 -0
  243. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state.mjs +45 -0
  244. package/src/runtime/agent/orchestrator/providers/openai-http-sse-watchdogs.mjs +176 -0
  245. package/src/runtime/agent/orchestrator/providers/openai-oauth-catalog.mjs +1 -1
  246. package/src/runtime/agent/orchestrator/providers/openai-oauth-dispatch.mjs +258 -0
  247. package/src/runtime/agent/orchestrator/providers/openai-oauth-http-sse.mjs +70 -1095
  248. package/src/runtime/agent/orchestrator/providers/openai-oauth-login.mjs +3 -3
  249. package/src/runtime/agent/orchestrator/providers/openai-oauth-tokens.mjs +3 -3
  250. package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +98 -1504
  251. package/src/runtime/agent/orchestrator/providers/openai-oauth.mjs +49 -215
  252. package/src/runtime/agent/orchestrator/providers/openai-responses-input.mjs +80 -60
  253. package/src/runtime/agent/orchestrator/providers/openai-responses-payload.mjs +160 -141
  254. package/src/runtime/agent/orchestrator/providers/openai-startup-prewarm.mjs +4 -7
  255. package/src/runtime/agent/orchestrator/providers/openai-transport-policy.mjs +6 -1
  256. package/src/runtime/agent/orchestrator/providers/openai-ws-delta.mjs +12 -11
  257. package/src/runtime/agent/orchestrator/providers/openai-ws-events.mjs +4 -11
  258. package/src/runtime/agent/orchestrator/providers/openai-ws-handshake.mjs +108 -0
  259. package/src/runtime/agent/orchestrator/providers/openai-ws-headers.mjs +5 -18
  260. package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +193 -306
  261. package/src/runtime/agent/orchestrator/providers/openai-ws-response-state/citations.mjs +53 -0
  262. package/src/runtime/agent/orchestrator/providers/openai-ws-response-state/replay-items.mjs +80 -0
  263. package/src/runtime/agent/orchestrator/providers/openai-ws-response-state/tool-calls.mjs +245 -0
  264. package/src/runtime/agent/orchestrator/providers/openai-ws-response-state/usage.mjs +15 -0
  265. package/src/runtime/agent/orchestrator/providers/openai-ws-response-state.mjs +227 -0
  266. package/src/runtime/agent/orchestrator/providers/openai-ws-send/acquire-attempt.mjs +94 -0
  267. package/src/runtime/agent/orchestrator/providers/openai-ws-send/attempt-request.mjs +145 -0
  268. package/src/runtime/agent/orchestrator/providers/openai-ws-send/reasoning-replay.mjs +36 -0
  269. package/src/runtime/agent/orchestrator/providers/openai-ws-send/send-context.mjs +154 -0
  270. package/src/runtime/agent/orchestrator/providers/openai-ws-send-attempts/attempt-context.mjs +74 -0
  271. package/src/runtime/agent/orchestrator/providers/openai-ws-send-attempts/handshake-failure.mjs +105 -0
  272. package/src/runtime/agent/orchestrator/providers/openai-ws-send-attempts/policy.mjs +142 -0
  273. package/src/runtime/agent/orchestrator/providers/openai-ws-send-attempts/stream-failure-stamps.mjs +81 -0
  274. package/src/runtime/agent/orchestrator/providers/openai-ws-send-attempts/stream-failure.mjs +109 -0
  275. package/src/runtime/agent/orchestrator/providers/openai-ws-send-attempts.mjs +63 -0
  276. package/src/runtime/agent/orchestrator/providers/openai-ws-send-outcome.mjs +384 -0
  277. package/src/runtime/agent/orchestrator/providers/openai-ws-send-span.mjs +93 -0
  278. package/src/runtime/agent/orchestrator/providers/openai-ws-send-trace.mjs +316 -0
  279. package/src/runtime/agent/orchestrator/providers/openai-ws-stream/event-switch.mjs +125 -0
  280. package/src/runtime/agent/orchestrator/providers/openai-ws-stream/outcome.mjs +28 -0
  281. package/src/runtime/agent/orchestrator/providers/openai-ws-stream/socket-handlers.mjs +192 -0
  282. package/src/runtime/agent/orchestrator/providers/openai-ws-stream/terminal-frames.mjs +118 -0
  283. package/src/runtime/agent/orchestrator/providers/openai-ws-stream/turn-state-headers.mjs +106 -0
  284. package/src/runtime/agent/orchestrator/providers/openai-ws-stream.mjs +139 -1447
  285. package/src/runtime/agent/orchestrator/providers/openai-ws-terminal.mjs +120 -0
  286. package/src/runtime/agent/orchestrator/providers/openai-ws-text-relay.mjs +84 -0
  287. package/src/runtime/agent/orchestrator/providers/openai-ws-warmup.mjs +171 -0
  288. package/src/runtime/agent/orchestrator/providers/openai-ws-watchdogs.mjs +204 -0
  289. package/src/runtime/agent/orchestrator/providers/opencode-go-usage.mjs +76 -253
  290. package/src/runtime/agent/orchestrator/providers/provider-catalog-cache.mjs +3 -3
  291. package/src/runtime/agent/orchestrator/providers/registry.mjs +13 -0
  292. package/src/runtime/agent/orchestrator/providers/retry-backoff.mjs +219 -0
  293. package/src/runtime/agent/orchestrator/providers/retry-classification.mjs +575 -0
  294. package/src/runtime/agent/orchestrator/providers/retry-classifier.mjs +52 -1317
  295. package/src/runtime/agent/orchestrator/providers/retry-executor.mjs +263 -0
  296. package/src/runtime/agent/orchestrator/providers/retry-midstream.mjs +345 -0
  297. package/src/runtime/agent/orchestrator/providers/stream-json-pool/owner-affinity.mjs +121 -0
  298. package/src/runtime/agent/orchestrator/providers/stream-json-pool/pool-tasks.mjs +74 -0
  299. package/src/runtime/agent/orchestrator/providers/stream-json-pool/stream-order.mjs +71 -0
  300. package/src/runtime/agent/orchestrator/providers/stream-json-pool/worker-slots/pending-queue.mjs +54 -0
  301. package/src/runtime/agent/orchestrator/providers/stream-json-pool/worker-slots/slot-pick.mjs +28 -0
  302. package/src/runtime/agent/orchestrator/providers/stream-json-pool/worker-slots/slot-spawn.mjs +92 -0
  303. package/src/runtime/agent/orchestrator/providers/stream-json-pool/worker-slots.mjs +165 -0
  304. package/src/runtime/agent/orchestrator/providers/stream-json-pool.mjs +66 -492
  305. package/src/runtime/agent/orchestrator/providers/trace-utils.mjs +10 -4
  306. package/src/runtime/agent/orchestrator/session/agent-loop.mjs +28 -551
  307. package/src/runtime/agent/orchestrator/session/cache/read-cache.mjs +1 -1
  308. package/src/runtime/agent/orchestrator/session/cache/scoped-cache.mjs +105 -117
  309. package/src/runtime/agent/orchestrator/session/compact/budget.mjs +18 -17
  310. package/src/runtime/agent/orchestrator/session/compact/constants.mjs +3 -0
  311. package/src/runtime/agent/orchestrator/session/compact/execution-tail.mjs +9 -8
  312. package/src/runtime/agent/orchestrator/session/compact/runner.mjs +333 -246
  313. package/src/runtime/agent/orchestrator/session/compact/summary-schema.mjs +4 -3
  314. package/src/runtime/agent/orchestrator/session/compact/summary.mjs +47 -341
  315. package/src/runtime/agent/orchestrator/session/compact/text-utils.mjs +3 -2
  316. package/src/runtime/agent/orchestrator/session/context-compaction-policy.mjs +9 -13
  317. package/src/runtime/agent/orchestrator/session/context-tool-pairs.mjs +295 -0
  318. package/src/runtime/agent/orchestrator/session/context-utils.mjs +220 -434
  319. package/src/runtime/agent/orchestrator/session/eager-dispatch/admission.mjs +132 -0
  320. package/src/runtime/agent/orchestrator/session/eager-dispatch/barriers.mjs +120 -0
  321. package/src/runtime/agent/orchestrator/session/eager-dispatch/entry.mjs +98 -0
  322. package/src/runtime/agent/orchestrator/session/eager-dispatch.mjs +51 -323
  323. package/src/runtime/agent/orchestrator/session/evidence-union.mjs +21 -551
  324. package/src/runtime/agent/orchestrator/session/explicit-skills.mjs +0 -3
  325. package/src/runtime/agent/orchestrator/session/loop/arg-schema-coerce.mjs +3 -1
  326. package/src/runtime/agent/orchestrator/session/loop/assistant-commit.mjs +3 -1
  327. package/src/runtime/agent/orchestrator/session/loop/compact-debug.mjs +1 -1
  328. package/src/runtime/agent/orchestrator/session/loop/compact-policy.mjs +147 -100
  329. package/src/runtime/agent/orchestrator/session/loop/completion-guards.mjs +3 -3
  330. package/src/runtime/agent/orchestrator/session/loop/context-overflow.mjs +11 -5
  331. package/src/runtime/agent/orchestrator/session/loop/diagnostics.mjs +1 -8
  332. package/src/runtime/agent/orchestrator/session/loop/fresh-context.mjs +142 -81
  333. package/src/runtime/agent/orchestrator/session/loop/hidden-agents.mjs +5 -5
  334. package/src/runtime/agent/orchestrator/session/loop/loop-state.mjs +183 -0
  335. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/continuation.mjs +48 -0
  336. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/diagnostic.mjs +8 -0
  337. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/empty-nudge.mjs +32 -0
  338. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/output-limit.mjs +39 -0
  339. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/refusal.mjs +25 -0
  340. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/segments.mjs +42 -0
  341. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn.mjs +42 -200
  342. package/src/runtime/agent/orchestrator/session/loop/pre-dispatch-deny.mjs +1 -1
  343. package/src/runtime/agent/orchestrator/session/loop/request-projection.mjs +5 -8
  344. package/src/runtime/agent/orchestrator/session/loop/send-phase.mjs +297 -0
  345. package/src/runtime/agent/orchestrator/session/loop/steering.mjs +11 -13
  346. package/src/runtime/agent/orchestrator/session/loop/stored-tool-args.mjs +7 -7
  347. package/src/runtime/agent/orchestrator/session/loop/termination.mjs +1 -1
  348. package/src/runtime/agent/orchestrator/session/loop/test-isolation.mjs +73 -0
  349. package/src/runtime/agent/orchestrator/session/loop/tool-classify.mjs +3 -6
  350. package/src/runtime/agent/orchestrator/session/loop/tool-exec/after-hook.mjs +36 -0
  351. package/src/runtime/agent/orchestrator/session/loop/tool-exec/before-hook.mjs +74 -0
  352. package/src/runtime/agent/orchestrator/session/loop/tool-exec/call-prep.mjs +106 -0
  353. package/src/runtime/agent/orchestrator/session/loop/tool-exec/dispatch.mjs +103 -0
  354. package/src/runtime/agent/orchestrator/session/loop/tool-exec/read-only-deadline.mjs +113 -0
  355. package/src/runtime/agent/orchestrator/session/loop/tool-exec.mjs +59 -422
  356. package/src/runtime/agent/orchestrator/session/loop/tool-helpers.mjs +9 -12
  357. package/src/runtime/agent/orchestrator/session/loop/tool-phase.mjs +86 -0
  358. package/src/runtime/agent/orchestrator/session/loop/transcript-repair.mjs +1 -1
  359. package/src/runtime/agent/orchestrator/session/loop/usage.mjs +5 -1
  360. package/src/runtime/agent/orchestrator/session/manager/agent-runtime-singleton.mjs +1 -1
  361. package/src/runtime/agent/orchestrator/session/manager/ask-call-interrupt.mjs +52 -0
  362. package/src/runtime/agent/orchestrator/session/manager/ask-queue.mjs +96 -0
  363. package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +149 -1447
  364. package/src/runtime/agent/orchestrator/session/manager/ask-support.mjs +48 -0
  365. package/src/runtime/agent/orchestrator/session/manager/ask-turn-commit.mjs +184 -0
  366. package/src/runtime/agent/orchestrator/session/manager/ask-turn-execute.mjs +180 -0
  367. package/src/runtime/agent/orchestrator/session/manager/ask-turn-failure.mjs +209 -0
  368. package/src/runtime/agent/orchestrator/session/manager/ask-turn-loop-options.mjs +191 -0
  369. package/src/runtime/agent/orchestrator/session/manager/ask-turn-open.mjs +132 -0
  370. package/src/runtime/agent/orchestrator/session/manager/ask-turn-prepare.mjs +247 -0
  371. package/src/runtime/agent/orchestrator/session/manager/ask-turn-settle.mjs +199 -0
  372. package/src/runtime/agent/orchestrator/session/manager/ask-turn-state.mjs +126 -0
  373. package/src/runtime/agent/orchestrator/session/manager/ask-turn-steering-drain.mjs +63 -0
  374. package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +301 -256
  375. package/src/runtime/agent/orchestrator/session/manager/delivered-completions.mjs +3 -2
  376. package/src/runtime/agent/orchestrator/session/manager/failed-turn-rewind.mjs +47 -0
  377. package/src/runtime/agent/orchestrator/session/manager/foreign-pending-messages.mjs +81 -66
  378. package/src/runtime/agent/orchestrator/session/manager/idle-cleanup.mjs +2 -2
  379. package/src/runtime/agent/orchestrator/session/manager/message-sanitize.mjs +6 -25
  380. package/src/runtime/agent/orchestrator/session/manager/pending-claim-ledger.mjs +68 -0
  381. package/src/runtime/agent/orchestrator/session/manager/pending-delivered-ledger.mjs +56 -0
  382. package/src/runtime/agent/orchestrator/session/manager/pending-lifecycle-epoch.mjs +84 -0
  383. package/src/runtime/agent/orchestrator/session/manager/pending-message-entry.mjs +13 -12
  384. package/src/runtime/agent/orchestrator/session/manager/pending-messages.mjs +58 -670
  385. package/src/runtime/agent/orchestrator/session/manager/pending-persist-queue.mjs +264 -0
  386. package/src/runtime/agent/orchestrator/session/manager/pending-spool-file.mjs +131 -0
  387. package/src/runtime/agent/orchestrator/session/manager/pending-spool-sweep.mjs +73 -0
  388. package/src/runtime/agent/orchestrator/session/manager/prefetch-bridge/file-entries.mjs +36 -0
  389. package/src/runtime/agent/orchestrator/session/manager/prefetch-bridge/file-prefetch.mjs +85 -0
  390. package/src/runtime/agent/orchestrator/session/manager/prefetch-bridge/symbol-prefetch.mjs +31 -0
  391. package/src/runtime/agent/orchestrator/session/manager/prefetch-bridge.mjs +36 -203
  392. package/src/runtime/agent/orchestrator/session/manager/prepared-resume-cache.mjs +122 -0
  393. package/src/runtime/agent/orchestrator/session/manager/prompt-utils.mjs +2 -1
  394. package/src/runtime/agent/orchestrator/session/manager/rules-cache.mjs +2 -31
  395. package/src/runtime/agent/orchestrator/session/manager/rules-source-cache.mjs +3 -2
  396. package/src/runtime/agent/orchestrator/session/manager/runtime-liveness.mjs +10 -6
  397. package/src/runtime/agent/orchestrator/session/manager/runtime-loaders.mjs +1 -1
  398. package/src/runtime/agent/orchestrator/session/manager/session-close.mjs +60 -33
  399. package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +156 -163
  400. package/src/runtime/agent/orchestrator/session/manager/session-id.mjs +3 -3
  401. package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +195 -714
  402. package/src/runtime/agent/orchestrator/session/manager/session-owner-liveness.mjs +135 -0
  403. package/src/runtime/agent/orchestrator/session/manager/session-prompt-composition.mjs +150 -0
  404. package/src/runtime/agent/orchestrator/session/manager/session-record.mjs +154 -0
  405. package/src/runtime/agent/orchestrator/session/manager/session-tool-surface.mjs +135 -0
  406. package/src/runtime/agent/orchestrator/session/manager/tool-resolution.mjs +7 -20
  407. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-context.mjs +5 -12
  408. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.mjs +4 -10
  409. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint.mjs +3 -5
  410. package/src/runtime/agent/orchestrator/session/manager/turn-interruption-journal.mjs +114 -0
  411. package/src/runtime/agent/orchestrator/session/manager/turn-interruption.mjs +75 -164
  412. package/src/runtime/agent/orchestrator/session/manager/usage-metrics.mjs +204 -173
  413. package/src/runtime/agent/orchestrator/session/manager.mjs +1 -1
  414. package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +448 -464
  415. package/src/runtime/agent/orchestrator/session/provider-prefix-guard.mjs +24 -33
  416. package/src/runtime/agent/orchestrator/session/runtime-user-context.mjs +2 -5
  417. package/src/runtime/agent/orchestrator/session/save-session-worker.mjs +1 -1
  418. package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +662 -620
  419. package/src/runtime/agent/orchestrator/session/store/fs-probe.mjs +1 -1
  420. package/src/runtime/agent/orchestrator/session/store/lifecycle-barriers.mjs +275 -0
  421. package/src/runtime/agent/orchestrator/session/store/lifecycle-read.mjs +67 -0
  422. package/src/runtime/agent/orchestrator/session/store/listing.mjs +8 -585
  423. package/src/runtime/agent/orchestrator/session/store/live-cache-eviction.mjs +72 -0
  424. package/src/runtime/agent/orchestrator/session/store/liveness-veto.mjs +53 -0
  425. package/src/runtime/agent/orchestrator/session/store/load-cache.mjs +1 -1
  426. package/src/runtime/agent/orchestrator/session/store/load-session.mjs +60 -0
  427. package/src/runtime/agent/orchestrator/session/store/paths-heartbeat.mjs +3 -3
  428. package/src/runtime/agent/orchestrator/session/store/pending-saves.mjs +55 -0
  429. package/src/runtime/agent/orchestrator/session/store/save-fault.mjs +15 -14
  430. package/src/runtime/agent/orchestrator/session/store/save-worker.mjs +221 -207
  431. package/src/runtime/agent/orchestrator/session/store/serialize.mjs +9 -17
  432. package/src/runtime/agent/orchestrator/session/store/session-delete.mjs +149 -0
  433. package/src/runtime/agent/orchestrator/session/store/session-observers.mjs +55 -0
  434. package/src/runtime/agent/orchestrator/session/store/summary-cache.mjs +2 -2
  435. package/src/runtime/agent/orchestrator/session/store/summary-rebuild-worker.mjs +1 -1
  436. package/src/runtime/agent/orchestrator/session/store/sweep/stale-sweep.mjs +74 -0
  437. package/src/runtime/agent/orchestrator/session/store/sweep/sweep-finish.mjs +90 -0
  438. package/src/runtime/agent/orchestrator/session/store/sweep/sweep-plan.mjs +81 -0
  439. package/src/runtime/agent/orchestrator/session/store/sweep/sweep-record.mjs +92 -0
  440. package/src/runtime/agent/orchestrator/session/store/sweep/sweep-row.mjs +313 -0
  441. package/src/runtime/agent/orchestrator/session/store/write-admission.mjs +108 -0
  442. package/src/runtime/agent/orchestrator/session/store-agent-worker-pool.mjs +37 -0
  443. package/src/runtime/agent/orchestrator/session/store-agent-worker-rows.mjs +531 -0
  444. package/src/runtime/agent/orchestrator/session/store-summary-archived-agent.mjs +126 -0
  445. package/src/runtime/agent/orchestrator/session/store-summary-fields.mjs +24 -0
  446. package/src/runtime/agent/orchestrator/session/store-summary-index.mjs +5 -13
  447. package/src/runtime/agent/orchestrator/session/store-summary-locations.mjs +46 -0
  448. package/src/runtime/agent/orchestrator/session/store-summary-reader.mjs +14 -763
  449. package/src/runtime/agent/orchestrator/session/store-transcript-projection.mjs +126 -0
  450. package/src/runtime/agent/orchestrator/session/store.mjs +41 -779
  451. package/src/runtime/agent/orchestrator/session/synthetic-user-envelope.mjs +6 -2
  452. package/src/runtime/agent/orchestrator/session/tool-batch/execute-call.mjs +265 -0
  453. package/src/runtime/agent/orchestrator/session/tool-batch/finalize.mjs +259 -0
  454. package/src/runtime/agent/orchestrator/session/tool-batch/flush.mjs +65 -0
  455. package/src/runtime/agent/orchestrator/session/tool-batch/plan.mjs +99 -0
  456. package/src/runtime/agent/orchestrator/session/tool-batch/pre-dispatch.mjs +123 -0
  457. package/src/runtime/agent/orchestrator/session/tool-batch/record-outcome.mjs +160 -0
  458. package/src/runtime/agent/orchestrator/session/tool-batch/state.mjs +54 -0
  459. package/src/runtime/agent/orchestrator/session/tool-batch.mjs +24 -1061
  460. package/src/runtime/agent/orchestrator/session/tool-envelope.mjs +7 -5
  461. package/src/runtime/agent/orchestrator/session/tool-result-offload.mjs +19 -13
  462. package/src/runtime/agent/orchestrator/stable-hash-stringify.mjs +10 -0
  463. package/src/runtime/agent/orchestrator/tool-loop-guard.mjs +1 -1
  464. package/src/runtime/agent/orchestrator/tools/bash-policy-scan.mjs +1 -1
  465. package/src/runtime/agent/orchestrator/tools/builtin/advisory-lock.mjs +5 -8
  466. package/src/runtime/agent/orchestrator/tools/builtin/arg-guard.mjs +67 -87
  467. package/src/runtime/agent/orchestrator/tools/builtin/atomic-write.mjs +155 -159
  468. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/abort-signals.mjs +66 -0
  469. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/backgrounded-result.mjs +82 -0
  470. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/benign-exit.mjs +86 -0
  471. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/command-preflight.mjs +46 -0
  472. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/completed-result.mjs +169 -0
  473. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/deadline-plan.mjs +75 -0
  474. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/inline-hoist.mjs +36 -0
  475. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/invocation-plan.mjs +84 -0
  476. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/result-format.mjs +113 -0
  477. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/spawn-env.mjs +24 -0
  478. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/transport-artifacts.mjs +114 -0
  479. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +109 -905
  480. package/src/runtime/agent/orchestrator/tools/builtin/binary-file.mjs +2 -2
  481. package/src/runtime/agent/orchestrator/tools/builtin/builtin-tools.mjs +9 -4
  482. package/src/runtime/agent/orchestrator/tools/builtin/cache-layers.mjs +80 -132
  483. package/src/runtime/agent/orchestrator/tools/builtin/diff-utils.mjs +7 -2
  484. package/src/runtime/agent/orchestrator/tools/builtin/external-tool-adapters.mjs +251 -210
  485. package/src/runtime/agent/orchestrator/tools/builtin/find-files-tool.mjs +529 -0
  486. package/src/runtime/agent/orchestrator/tools/builtin/git-command-policy.mjs +45 -27
  487. package/src/runtime/agent/orchestrator/tools/builtin/git-command-tool.mjs +174 -713
  488. package/src/runtime/agent/orchestrator/tools/builtin/git-partial-stage.mjs +45 -20
  489. package/src/runtime/agent/orchestrator/tools/builtin/glob-walk.mjs +5 -5
  490. package/src/runtime/agent/orchestrator/tools/builtin/grep-formatting.mjs +1 -1
  491. package/src/runtime/agent/orchestrator/tools/builtin/hash-utils.mjs +1 -1
  492. package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-context-expander.mjs +124 -107
  493. package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-output.mjs +107 -54
  494. package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-path-fanout.mjs +243 -212
  495. package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-pattern-fanout.mjs +330 -331
  496. package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-request.mjs +290 -0
  497. package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-single-file-rescue.mjs +80 -67
  498. package/src/runtime/agent/orchestrator/tools/builtin/lib/search-grep-chunks.mjs +7 -6
  499. package/src/runtime/agent/orchestrator/tools/builtin/lib/search-input-helpers.mjs +13 -0
  500. package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-task-output.mjs +112 -0
  501. package/src/runtime/agent/orchestrator/tools/builtin/lib/tool-progress.mjs +10 -0
  502. package/src/runtime/agent/orchestrator/tools/builtin/list-tool-shared.mjs +48 -0
  503. package/src/runtime/agent/orchestrator/tools/builtin/list-tool.mjs +314 -791
  504. package/src/runtime/agent/orchestrator/tools/builtin/native-search-client.mjs +9 -8
  505. package/src/runtime/agent/orchestrator/tools/builtin/path-diagnostics.mjs +69 -80
  506. package/src/runtime/agent/orchestrator/tools/builtin/path-utils.mjs +19 -10
  507. package/src/runtime/agent/orchestrator/tools/builtin/read-args.mjs +1 -1
  508. package/src/runtime/agent/orchestrator/tools/builtin/read-batch.mjs +16 -21
  509. package/src/runtime/agent/orchestrator/tools/builtin/read-formatting.mjs +0 -5
  510. package/src/runtime/agent/orchestrator/tools/builtin/read-image-resize.mjs +174 -103
  511. package/src/runtime/agent/orchestrator/tools/builtin/read-image.mjs +2 -2
  512. package/src/runtime/agent/orchestrator/tools/builtin/read-line-collector.mjs +160 -0
  513. package/src/runtime/agent/orchestrator/tools/builtin/read-mode-tool.mjs +14 -14
  514. package/src/runtime/agent/orchestrator/tools/builtin/read-office-files.mjs +8 -11
  515. package/src/runtime/agent/orchestrator/tools/builtin/read-open.mjs +3 -4
  516. package/src/runtime/agent/orchestrator/tools/builtin/read-range-index.mjs +16 -19
  517. package/src/runtime/agent/orchestrator/tools/builtin/read-single-fast-paths.mjs +178 -0
  518. package/src/runtime/agent/orchestrator/tools/builtin/read-single-guards.mjs +161 -0
  519. package/src/runtime/agent/orchestrator/tools/builtin/read-single-media.mjs +53 -0
  520. package/src/runtime/agent/orchestrator/tools/builtin/read-single-render.mjs +207 -0
  521. package/src/runtime/agent/orchestrator/tools/builtin/read-single-stream.mjs +79 -0
  522. package/src/runtime/agent/orchestrator/tools/builtin/read-single-tool.mjs +122 -832
  523. package/src/runtime/agent/orchestrator/tools/builtin/read-snapshot-runtime.mjs +3 -4
  524. package/src/runtime/agent/orchestrator/tools/builtin/read-special-files.mjs +5 -11
  525. package/src/runtime/agent/orchestrator/tools/builtin/read-streaming.mjs +140 -226
  526. package/src/runtime/agent/orchestrator/tools/builtin/read-tool/batch-dispatch.mjs +126 -0
  527. package/src/runtime/agent/orchestrator/tools/builtin/read-tool/batch-entries.mjs +137 -0
  528. package/src/runtime/agent/orchestrator/tools/builtin/read-tool/batch-render.mjs +158 -0
  529. package/src/runtime/agent/orchestrator/tools/builtin/read-tool/batch-snapshot.mjs +88 -0
  530. package/src/runtime/agent/orchestrator/tools/builtin/read-tool/glob-survey.mjs +100 -0
  531. package/src/runtime/agent/orchestrator/tools/builtin/read-tool/image-fast-path.mjs +32 -0
  532. package/src/runtime/agent/orchestrator/tools/builtin/read-tool/reach-preflight.mjs +95 -0
  533. package/src/runtime/agent/orchestrator/tools/builtin/read-tool.mjs +116 -704
  534. package/src/runtime/agent/orchestrator/tools/builtin/read-window-widen.mjs +42 -0
  535. package/src/runtime/agent/orchestrator/tools/builtin/read-windows.mjs +11 -4
  536. package/src/runtime/agent/orchestrator/tools/builtin/runtime-capabilities.mjs +47 -30
  537. package/src/runtime/agent/orchestrator/tools/builtin/search-builders.mjs +5 -5
  538. package/src/runtime/agent/orchestrator/tools/builtin/search-glob-tool.mjs +494 -427
  539. package/src/runtime/agent/orchestrator/tools/builtin/search-grep-tool.mjs +552 -787
  540. package/src/runtime/agent/orchestrator/tools/builtin/search-path-diagnostics.mjs +5 -5
  541. package/src/runtime/agent/orchestrator/tools/builtin/shell-analysis.mjs +34 -42
  542. package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +16 -22
  543. package/src/runtime/agent/orchestrator/tools/builtin/shell-lossless-compact.mjs +1 -4
  544. package/src/runtime/agent/orchestrator/tools/builtin/shell-output.mjs +1 -1
  545. package/src/runtime/agent/orchestrator/tools/builtin/shell-runtime.mjs +3 -5
  546. package/src/runtime/agent/orchestrator/tools/builtin/snapshot-store.mjs +2 -2
  547. package/src/runtime/agent/orchestrator/tools/builtin/snapshot-validation.mjs +5 -5
  548. package/src/runtime/agent/orchestrator/tools/builtin/task-tool.mjs +26 -17
  549. package/src/runtime/agent/orchestrator/tools/builtin/text-stats.mjs +7 -4
  550. package/src/runtime/agent/orchestrator/tools/builtin.mjs +22 -24
  551. package/src/runtime/agent/orchestrator/tools/code-graph/aggregate-roots.mjs +9 -10
  552. package/src/runtime/agent/orchestrator/tools/code-graph/ast-calls.mjs +1 -4
  553. package/src/runtime/agent/orchestrator/tools/code-graph/build-file-infos.mjs +182 -0
  554. package/src/runtime/agent/orchestrator/tools/code-graph/build.mjs +15 -160
  555. package/src/runtime/agent/orchestrator/tools/code-graph/constants.mjs +2 -3
  556. package/src/runtime/agent/orchestrator/tools/code-graph/disk-cache.mjs +94 -87
  557. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch/abort-race.mjs +33 -0
  558. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch/federation.mjs +144 -0
  559. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch/root-resolution.mjs +142 -0
  560. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch/work.mjs +125 -0
  561. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +192 -1055
  562. package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary/child-kill.mjs +55 -0
  563. package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary/jsonl-records.mjs +22 -0
  564. package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary/spawn-jsonl.mjs +135 -0
  565. package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary.mjs +43 -235
  566. package/src/runtime/agent/orchestrator/tools/code-graph/modes/calls.mjs +152 -0
  567. package/src/runtime/agent/orchestrator/tools/code-graph/modes/dependents.mjs +91 -0
  568. package/src/runtime/agent/orchestrator/tools/code-graph/modes/shared.mjs +81 -0
  569. package/src/runtime/agent/orchestrator/tools/code-graph/modes/structure.mjs +75 -0
  570. package/src/runtime/agent/orchestrator/tools/code-graph/modes/symbols.mjs +150 -0
  571. package/src/runtime/agent/orchestrator/tools/code-graph/project-root.mjs +1 -1
  572. package/src/runtime/agent/orchestrator/tools/code-graph/search-references.mjs +43 -42
  573. package/src/runtime/agent/orchestrator/tools/code-graph/search.mjs +5 -7
  574. package/src/runtime/agent/orchestrator/tools/code-graph/symbol-index.mjs +1 -2
  575. package/src/runtime/agent/orchestrator/tools/code-graph/text-columns.mjs +1 -1
  576. package/src/runtime/agent/orchestrator/tools/code-graph/text-mask.golden.json +47 -0
  577. package/src/runtime/agent/orchestrator/tools/code-graph/text-mask.mjs +243 -290
  578. package/src/runtime/agent/orchestrator/tools/code-graph-prewarm-worker.mjs +1 -1
  579. package/src/runtime/agent/orchestrator/tools/code-graph-state.mjs +1 -1
  580. package/src/runtime/agent/orchestrator/tools/env-scrub.mjs +7 -11
  581. package/src/runtime/agent/orchestrator/tools/graph-manifest.json +11 -11
  582. package/src/runtime/agent/orchestrator/tools/lib/isolated-test-env.mjs +30 -0
  583. package/src/runtime/agent/orchestrator/tools/lib/native-spawn-client.mjs +2 -2
  584. package/src/runtime/agent/orchestrator/tools/lib/shell-run-background/promote-job.mjs +90 -0
  585. package/src/runtime/agent/orchestrator/tools/lib/shell-run-background/promotion-results.mjs +158 -0
  586. package/src/runtime/agent/orchestrator/tools/lib/shell-run-background.mjs +142 -0
  587. package/src/runtime/agent/orchestrator/tools/lib/shell-run-settle.mjs +165 -0
  588. package/src/runtime/agent/orchestrator/tools/lib/shell-run-spawn.mjs +208 -0
  589. package/src/runtime/agent/orchestrator/tools/lib/shell-run-state.mjs +175 -0
  590. package/src/runtime/agent/orchestrator/tools/lib/shell-spawn-retry.mjs +2 -2
  591. package/src/runtime/agent/orchestrator/tools/lib/shell-warm-standby.mjs +2 -2
  592. package/src/runtime/agent/orchestrator/tools/patch/apply-patch/codex-batch.mjs +245 -0
  593. package/src/runtime/agent/orchestrator/tools/patch/apply-patch/request.mjs +96 -0
  594. package/src/runtime/agent/orchestrator/tools/patch/apply-patch/route.mjs +46 -0
  595. package/src/runtime/agent/orchestrator/tools/patch/constants.mjs +1 -2
  596. package/src/runtime/agent/orchestrator/tools/patch/dispatch/native-proofs.mjs +65 -0
  597. package/src/runtime/agent/orchestrator/tools/patch/dispatch/native-report.mjs +65 -0
  598. package/src/runtime/agent/orchestrator/tools/patch/dispatch/native-snapshots.mjs +72 -0
  599. package/src/runtime/agent/orchestrator/tools/patch/dispatch.mjs +35 -174
  600. package/src/runtime/agent/orchestrator/tools/patch/matcher.mjs +116 -358
  601. package/src/runtime/agent/orchestrator/tools/patch/mutation-output.mjs +30 -0
  602. package/src/runtime/agent/orchestrator/tools/patch/native-server.mjs +25 -39
  603. package/src/runtime/agent/orchestrator/tools/patch/orchestrator.mjs +69 -1401
  604. package/src/runtime/agent/orchestrator/tools/patch/parsing.mjs +13 -16
  605. package/src/runtime/agent/orchestrator/tools/patch/paths.mjs +11 -6
  606. package/src/runtime/agent/orchestrator/tools/patch/post-patch-excerpts.mjs +99 -0
  607. package/src/runtime/agent/orchestrator/tools/patch/read-redirects.mjs +81 -0
  608. package/src/runtime/agent/orchestrator/tools/patch/replay-capture.mjs +183 -0
  609. package/src/runtime/agent/orchestrator/tools/patch/rollback-state.mjs +51 -0
  610. package/src/runtime/agent/orchestrator/tools/patch/section-coalesce.mjs +82 -0
  611. package/src/runtime/agent/orchestrator/tools/patch/sequence/report.mjs +88 -0
  612. package/src/runtime/agent/orchestrator/tools/patch/sequence/run.mjs +70 -0
  613. package/src/runtime/agent/orchestrator/tools/patch/sequence/units.mjs +132 -0
  614. package/src/runtime/agent/orchestrator/tools/patch/sequence.mjs +84 -0
  615. package/src/runtime/agent/orchestrator/tools/patch/text-lines.mjs +267 -0
  616. package/src/runtime/agent/orchestrator/tools/patch/ui-diff.mjs +108 -0
  617. package/src/runtime/agent/orchestrator/tools/patch/v4a-anchors.mjs +14 -12
  618. package/src/runtime/agent/orchestrator/tools/patch/v4a-convert.mjs +447 -455
  619. package/src/runtime/agent/orchestrator/tools/patch/v4a-windows.mjs +4 -19
  620. package/src/runtime/agent/orchestrator/tools/patch/wave.mjs +125 -0
  621. package/src/runtime/agent/orchestrator/tools/patch-binary-fetcher.mjs +1 -1
  622. package/src/runtime/agent/orchestrator/tools/patch-manifest.json +11 -11
  623. package/src/runtime/agent/orchestrator/tools/patch.mjs +0 -19
  624. package/src/runtime/agent/orchestrator/tools/progress-message.mjs +6 -5
  625. package/src/runtime/agent/orchestrator/tools/shell-command.mjs +271 -994
  626. package/src/runtime/agent/orchestrator/tools/shell-exec-output.mjs +7 -13
  627. package/src/runtime/agent/orchestrator/tools/shell-exec-policy.mjs +2 -2
  628. package/src/runtime/agent/orchestrator/tools/shell-policy.mjs +12 -13
  629. package/src/runtime/agent/orchestrator/tools/shell-powershell.mjs +2 -2
  630. package/src/runtime/agent/orchestrator/tools/shell-snapshot.mjs +4 -5
  631. package/src/runtime/agent/orchestrator/tools/spawn-manifest.json +11 -11
  632. package/src/runtime/agent/orchestrator/tools/tool-batch-trace.mjs +9 -13
  633. package/src/runtime/attachments/store.mjs +16 -21
  634. package/src/runtime/browser-bridge/action-schema.mjs +396 -325
  635. package/src/runtime/browser-bridge/client.mjs +20 -18
  636. package/src/runtime/browser-bridge/input-fields.mjs +13 -9
  637. package/src/runtime/channels/index.mjs +1 -1
  638. package/src/runtime/channels/lib/config.mjs +1 -10
  639. package/src/runtime/channels/lib/crash-log.mjs +4 -4
  640. package/src/runtime/channels/lib/event-pipeline.mjs +8 -8
  641. package/src/runtime/channels/lib/event-queue.mjs +18 -24
  642. package/src/runtime/channels/lib/executor.mjs +12 -91
  643. package/src/runtime/channels/lib/owned-runtime/automation-services.mjs +105 -0
  644. package/src/runtime/channels/lib/owned-runtime/automation-start.mjs +44 -0
  645. package/src/runtime/channels/lib/owned-runtime/config-reload.mjs +79 -0
  646. package/src/runtime/channels/lib/owned-runtime/owned-start.mjs +172 -0
  647. package/src/runtime/channels/lib/owned-runtime/owned-stop.mjs +59 -0
  648. package/src/runtime/channels/lib/owned-runtime/ownership-refresh.mjs +36 -0
  649. package/src/runtime/channels/lib/owned-runtime/state.mjs +22 -0
  650. package/src/runtime/channels/lib/owned-runtime.mjs +45 -488
  651. package/src/runtime/channels/lib/owner-heartbeat.mjs +0 -4
  652. package/src/runtime/channels/lib/parent-bridge.mjs +2 -2
  653. package/src/runtime/channels/lib/runtime-paths.mjs +35 -41
  654. package/src/runtime/channels/lib/scheduler.mjs +155 -147
  655. package/src/runtime/channels/lib/settings.mjs +1 -1
  656. package/src/runtime/channels/lib/state-file.mjs +1 -6
  657. package/src/runtime/channels/lib/status-snapshot.mjs +53 -53
  658. package/src/runtime/channels/lib/voice-runtime-fetcher.mjs +17 -25
  659. package/src/runtime/channels/lib/voice-transcription.mjs +132 -109
  660. package/src/runtime/channels/lib/webhook/deliveries.mjs +0 -5
  661. package/src/runtime/channels/lib/webhook/listener-lifecycle.mjs +119 -0
  662. package/src/runtime/channels/lib/webhook/log.mjs +3 -3
  663. package/src/runtime/channels/lib/webhook/relay-tunnel/leg-heartbeat.mjs +35 -0
  664. package/src/runtime/channels/lib/webhook/relay-tunnel/limits.mjs +6 -0
  665. package/src/runtime/channels/lib/webhook/relay-tunnel/local-forward.mjs +93 -0
  666. package/src/runtime/channels/lib/webhook/relay-tunnel.mjs +50 -168
  667. package/src/runtime/channels/lib/webhook/request-handler.mjs +258 -0
  668. package/src/runtime/channels/lib/webhook/session-dispatch.mjs +132 -0
  669. package/src/runtime/channels/lib/webhook/signature.mjs +1 -1
  670. package/src/runtime/channels/lib/webhook/verification.mjs +103 -0
  671. package/src/runtime/channels/lib/webhook.mjs +46 -497
  672. package/src/runtime/channels/lib/whisper-language.mjs +3 -10
  673. package/src/runtime/channels/lib/worker-bootstrap.mjs +51 -43
  674. package/src/runtime/channels/lib/worker-ipc.mjs +4 -4
  675. package/src/runtime/channels/lib/worker-main.mjs +9 -13
  676. package/src/runtime/computer-bridge/action-schema.mjs +200 -133
  677. package/src/runtime/computer-bridge/actions.mjs +19 -2
  678. package/src/runtime/computer-bridge/capture-size.mjs +8 -2
  679. package/src/runtime/computer-bridge/client.mjs +179 -147
  680. package/src/runtime/computer-bridge/core-actions.mjs +158 -101
  681. package/src/runtime/computer-bridge/pending-continuation.mjs +4 -7
  682. package/src/runtime/github/client.mjs +7 -10
  683. package/src/runtime/github/commands.mjs +9 -3
  684. package/src/runtime/github/contract.mjs +10 -1
  685. package/src/runtime/local-provider/asset-installer.mjs +5 -7
  686. package/src/runtime/local-provider/catalog.mjs +4 -3
  687. package/src/runtime/local-provider/hardware.mjs +7 -20
  688. package/src/runtime/local-provider/model-state.mjs +8 -6
  689. package/src/runtime/local-provider/resumable-installations.mjs +12 -19
  690. package/src/runtime/local-provider/server-process/child-state.mjs +73 -0
  691. package/src/runtime/local-provider/server-process/readiness.mjs +42 -0
  692. package/src/runtime/local-provider/server-process.mjs +28 -113
  693. package/src/runtime/media/adapters/codex-image.mjs +1 -1
  694. package/src/runtime/media/adapters/xai-media.mjs +7 -2
  695. package/src/runtime/media/auth.mjs +16 -13
  696. package/src/runtime/media/catalog-errors.mjs +3 -5
  697. package/src/runtime/media/catalog.mjs +18 -12
  698. package/src/runtime/media/defaults.mjs +2 -2
  699. package/src/runtime/media/jobs.mjs +1 -2
  700. package/src/runtime/media/lanes.mjs +2 -1
  701. package/src/runtime/media/renditions.mjs +11 -10
  702. package/src/runtime/media/store.mjs +7 -9
  703. package/src/runtime/media/tool.mjs +1 -5
  704. package/src/runtime/memory/data/runtime-manifest.json +9 -9
  705. package/src/runtime/memory/index.mjs +13 -25
  706. package/src/runtime/memory/lib/agent-ipc.mjs +1 -1
  707. package/src/runtime/memory/lib/core-memory-file.mjs +7 -5
  708. package/src/runtime/memory/lib/core-memory-store.mjs +3 -7
  709. package/src/runtime/memory/lib/cycle-llm-adapters.mjs +1 -1
  710. package/src/runtime/memory/lib/cycle-scheduler/backlog-probe.mjs +65 -0
  711. package/src/runtime/memory/lib/cycle-scheduler/cycle1-runs.mjs +120 -0
  712. package/src/runtime/memory/lib/cycle-scheduler/cycle2-runs.mjs +120 -0
  713. package/src/runtime/memory/lib/cycle-scheduler/health-ledger.mjs +96 -0
  714. package/src/runtime/memory/lib/cycle-scheduler/scheduled-enqueue.mjs +50 -0
  715. package/src/runtime/memory/lib/cycle-scheduler/tick-loop.mjs +104 -0
  716. package/src/runtime/memory/lib/cycle-scheduler.mjs +71 -475
  717. package/src/runtime/memory/lib/cycle-signatures.mjs +1 -2
  718. package/src/runtime/memory/lib/cycle1/cycle1-plan.mjs +94 -0
  719. package/src/runtime/memory/lib/cycle1/cycle1-result.mjs +113 -0
  720. package/src/runtime/memory/lib/cycle1/cycle1-rows.mjs +194 -0
  721. package/src/runtime/memory/lib/cycle1/cycle1-window.mjs +193 -0
  722. package/src/runtime/memory/lib/embedding-provider.mjs +12 -22
  723. package/src/runtime/memory/lib/embedding-worker.mjs +31 -37
  724. package/src/runtime/memory/lib/http-router/admin-routes.mjs +167 -0
  725. package/src/runtime/memory/lib/http-router/admin-trace-routes.mjs +65 -0
  726. package/src/runtime/memory/lib/http-router/ingest-routes.mjs +122 -0
  727. package/src/runtime/memory/lib/http-router/lifecycle-routes.mjs +96 -0
  728. package/src/runtime/memory/lib/http-router/mcp-route.mjs +49 -0
  729. package/src/runtime/memory/lib/http-router/session-routes.mjs +67 -0
  730. package/src/runtime/memory/lib/http-router/tool-routes.mjs +84 -0
  731. package/src/runtime/memory/lib/http-router.mjs +43 -659
  732. package/src/runtime/memory/lib/http-wire.mjs +1 -2
  733. package/src/runtime/memory/lib/ingest/ingest-embed-flush.mjs +72 -0
  734. package/src/runtime/memory/lib/ingest/ingest-insert.mjs +66 -0
  735. package/src/runtime/memory/lib/ingest/ingest-occurrences.mjs +109 -0
  736. package/src/runtime/memory/lib/ingest/ordinal-state.mjs +181 -0
  737. package/src/runtime/memory/lib/ingest/transcript-discovery.mjs +52 -0
  738. package/src/runtime/memory/lib/ingest/transcript-offsets.mjs +54 -0
  739. package/src/runtime/memory/lib/ingest/transcript-rows.mjs +81 -0
  740. package/src/runtime/memory/lib/ingest/transcript-tail.mjs +110 -0
  741. package/src/runtime/memory/lib/ingest/transcript-watcher.mjs +216 -0
  742. package/src/runtime/memory/lib/light-ko-morph.mjs +1 -1
  743. package/src/runtime/memory/lib/memory-action-handlers/core-actions.mjs +127 -0
  744. package/src/runtime/memory/lib/memory-action-handlers/cycle-actions.mjs +153 -0
  745. package/src/runtime/memory/lib/memory-action-handlers/cycle-backfill-action.mjs +84 -0
  746. package/src/runtime/memory/lib/memory-action-handlers/cycle-rebuild-action.mjs +94 -0
  747. package/src/runtime/memory/lib/memory-action-handlers/maintenance-actions.mjs +76 -0
  748. package/src/runtime/memory/lib/memory-action-handlers/manage-actions.mjs +220 -0
  749. package/src/runtime/memory/lib/memory-action-handlers.mjs +49 -679
  750. package/src/runtime/memory/lib/memory-categories.mjs +13 -0
  751. package/src/runtime/memory/lib/memory-chunk-quality.mjs +193 -94
  752. package/src/runtime/memory/lib/memory-config-flags.mjs +1 -1
  753. package/src/runtime/memory/lib/memory-cycle-requests.mjs +70 -88
  754. package/src/runtime/memory/lib/memory-cycle1.mjs +66 -558
  755. package/src/runtime/memory/lib/memory-cycle2-mutations.mjs +4 -3
  756. package/src/runtime/memory/lib/memory-cycle2-review.mjs +5 -3
  757. package/src/runtime/memory/lib/memory-cycle2-shared.mjs +2 -2
  758. package/src/runtime/memory/lib/memory-embed.mjs +14 -11
  759. package/src/runtime/memory/lib/memory-extraction.mjs +1 -1
  760. package/src/runtime/memory/lib/memory-ops-policy.mjs +3 -2
  761. package/src/runtime/memory/lib/memory-process-lock.mjs +1 -1
  762. package/src/runtime/memory/lib/memory-recall-scope-filter.mjs +8 -4
  763. package/src/runtime/memory/lib/memory-recall-store.mjs +70 -678
  764. package/src/runtime/memory/lib/memory-schema/core-and-meta.mjs +60 -0
  765. package/src/runtime/memory/lib/memory-schema/entries.mjs +94 -0
  766. package/src/runtime/memory/lib/memory-schema/entry-triggers.mjs +54 -0
  767. package/src/runtime/memory/lib/memory-schema/score-params.mjs +66 -0
  768. package/src/runtime/memory/lib/memory-text-utils.mjs +10 -10
  769. package/src/runtime/memory/lib/memory.mjs +21 -295
  770. package/src/runtime/memory/lib/model-profile.mjs +1 -1
  771. package/src/runtime/memory/lib/pg/adapter.mjs +7 -6
  772. package/src/runtime/memory/lib/pg/process.mjs +259 -267
  773. package/src/runtime/memory/lib/pg/supervisor.mjs +11 -17
  774. package/src/runtime/memory/lib/query-core-recall.mjs +82 -0
  775. package/src/runtime/memory/lib/query-fan-out.mjs +66 -0
  776. package/src/runtime/memory/lib/query-handlers.mjs +61 -1124
  777. package/src/runtime/memory/lib/query-hybrid-search.mjs +369 -0
  778. package/src/runtime/memory/lib/query-id-lookup.mjs +60 -0
  779. package/src/runtime/memory/lib/query-last-browse.mjs +266 -0
  780. package/src/runtime/memory/lib/query-maintenance-handlers.mjs +115 -91
  781. package/src/runtime/memory/lib/query-ranking.mjs +13 -14
  782. package/src/runtime/memory/lib/query-raw-merge.mjs +27 -0
  783. package/src/runtime/memory/lib/query-raw-window.mjs +64 -0
  784. package/src/runtime/memory/lib/query-search-plan.mjs +117 -0
  785. package/src/runtime/memory/lib/query-session-recall.mjs +153 -0
  786. package/src/runtime/memory/lib/query-window-browse.mjs +63 -0
  787. package/src/runtime/memory/lib/recall-event-context.mjs +1 -1
  788. package/src/runtime/memory/lib/recall-format.mjs +322 -289
  789. package/src/runtime/memory/lib/recall-hybrid/concept-expansion.mjs +211 -0
  790. package/src/runtime/memory/lib/recall-hybrid/hybrid-sql.mjs +250 -0
  791. package/src/runtime/memory/lib/recall-hybrid/members.mjs +33 -0
  792. package/src/runtime/memory/lib/recall-hybrid/plan.mjs +80 -0
  793. package/src/runtime/memory/lib/recall-hybrid/root-resolution.mjs +131 -0
  794. package/src/runtime/memory/lib/runtime-fetcher.mjs +77 -71
  795. package/src/runtime/memory/lib/session-ingest-runtime.mjs +50 -433
  796. package/src/runtime/memory/lib/session-ingest.mjs +8 -136
  797. package/src/runtime/memory/lib/tool-call-handler.mjs +2 -3
  798. package/src/runtime/memory/lib/trace-store/agent-call-inserts.mjs +90 -0
  799. package/src/runtime/memory/lib/trace-store/agent-call-rows.mjs +81 -0
  800. package/src/runtime/memory/lib/trace-store/agent-session-summary.mjs +65 -0
  801. package/src/runtime/memory/lib/trace-store.mjs +21 -260
  802. package/src/runtime/memory/lib/transcript-ingest.mjs +38 -478
  803. package/src/runtime/memory/tool-defs.mjs +5 -8
  804. package/src/runtime/office/README.md +3 -2
  805. package/src/runtime/office/authoring/pptx-author-action.mjs +140 -72
  806. package/src/runtime/office/authoring/pptx-author-session.mjs +6 -9
  807. package/src/runtime/office/authoring/pptx-brief.mjs +63 -20
  808. package/src/runtime/office/authoring/pptx-contact-sheet.mjs +3 -1
  809. package/src/runtime/office/authoring/pptx-receipt.mjs +89 -69
  810. package/src/runtime/office/authoring/pptx-script-normalize.mjs +1 -1
  811. package/src/runtime/office/bench/benchmark.mjs +102 -82
  812. package/src/runtime/office/bench/deck-bench.mjs +6 -3
  813. package/src/runtime/office/bench/quality-live-benchmark.mjs +33 -0
  814. package/src/runtime/office/capabilities-aliases.mjs +61 -0
  815. package/src/runtime/office/capabilities-catalog.mjs +593 -0
  816. package/src/runtime/office/capabilities-signatures.mjs +588 -0
  817. package/src/runtime/office/capabilities.mjs +265 -1460
  818. package/src/runtime/office/com/com-adapter.mjs +15 -3
  819. package/src/runtime/office/com/office-com-host.ps1 +5246 -4978
  820. package/src/runtime/office/core/office-actions-batch.mjs +365 -324
  821. package/src/runtime/office/core/office-actions-inspect.mjs +108 -115
  822. package/src/runtime/office/core/office-actions-lifecycle.mjs +39 -253
  823. package/src/runtime/office/core/office-actions-open.mjs +30 -41
  824. package/src/runtime/office/core/office-actions-render.mjs +30 -258
  825. package/src/runtime/office/core/office-core.mjs +34 -25
  826. package/src/runtime/office/core/office-documents.mjs +3 -1
  827. package/src/runtime/office/core/office-finalize/commit-stage.mjs +54 -0
  828. package/src/runtime/office/core/office-finalize/holds.mjs +57 -0
  829. package/src/runtime/office/core/office-finalize/review-stage.mjs +90 -0
  830. package/src/runtime/office/core/office-finalize/session-save.mjs +50 -0
  831. package/src/runtime/office/core/office-qa/design-review-stage.mjs +80 -0
  832. package/src/runtime/office/core/office-qa/fix-operations.mjs +47 -0
  833. package/src/runtime/office/core/office-qa/preview-stage.mjs +90 -0
  834. package/src/runtime/office/core/office-qa/review-assembly.mjs +87 -0
  835. package/src/runtime/office/core/office-recalculation.mjs +2 -2
  836. package/src/runtime/office/core/office-render-preview.mjs +11 -13
  837. package/src/runtime/office/core/office-session-dispatch.mjs +86 -0
  838. package/src/runtime/office/core/office-sessionless-actions.mjs +115 -0
  839. package/src/runtime/office/core/office-sessions.mjs +275 -288
  840. package/src/runtime/office/core/office-transactions.mjs +2 -4
  841. package/src/runtime/office/core/pagination.mjs +6 -6
  842. package/src/runtime/office/core/pptx-page-cache.mjs +1 -1
  843. package/src/runtime/office/core/tabular.mjs +24 -22
  844. package/src/runtime/office/design/composition-system.mjs +35 -29
  845. package/src/runtime/office/design/content-model.mjs +5 -2
  846. package/src/runtime/office/design/design-art-direction.mjs +22 -15
  847. package/src/runtime/office/design/design-creative-director.mjs +8 -9
  848. package/src/runtime/office/design/design-discipline.mjs +23 -18
  849. package/src/runtime/office/design/design-system.mjs +5 -8
  850. package/src/runtime/office/design/design-tokens.mjs +42 -33
  851. package/src/runtime/office/design/docx/design-docx/front-matter.mjs +81 -0
  852. package/src/runtime/office/design/docx/design-docx/section.mjs +114 -0
  853. package/src/runtime/office/design/docx/design-docx/writer.mjs +57 -0
  854. package/src/runtime/office/design/docx/design-docx-components.mjs +104 -173
  855. package/src/runtime/office/design/docx/design-docx.mjs +19 -222
  856. package/src/runtime/office/design/library/design-library-core.mjs +1 -1
  857. package/src/runtime/office/design/library/design-library-pack.mjs +11 -23
  858. package/src/runtime/office/design/library/design-library.mjs +23 -43
  859. package/src/runtime/office/design/library/design-template-fill.mjs +159 -0
  860. package/src/runtime/office/design/library/design-template-index.mjs +213 -174
  861. package/src/runtime/office/design/library/design-template-induct.mjs +223 -0
  862. package/src/runtime/office/design/library/design-template-inspect.mjs +165 -121
  863. package/src/runtime/office/design/native-design.mjs +2 -3
  864. package/src/runtime/office/design/xlsx/design-xlsx-components.mjs +12 -15
  865. package/src/runtime/office/design/xlsx/design-xlsx.mjs +450 -359
  866. package/src/runtime/office/index.mjs +7 -158
  867. package/src/runtime/office/pdf/pdf-adapter.mjs +41 -817
  868. package/src/runtime/office/pdf/pdf-analysis.mjs +385 -585
  869. package/src/runtime/office/pdf/pdf-batch-content.mjs +349 -0
  870. package/src/runtime/office/pdf/pdf-batch-structure.mjs +240 -0
  871. package/src/runtime/office/pdf/pdf-document.mjs +41 -0
  872. package/src/runtime/office/pdf/pdf-draw.mjs +1 -1
  873. package/src/runtime/office/pdf/pdf-edit-document.mjs +142 -0
  874. package/src/runtime/office/pdf/pdf-fonts.mjs +1 -1
  875. package/src/runtime/office/pdf/pdf-forms.mjs +3 -1
  876. package/src/runtime/office/pdf/pdf-marks.mjs +123 -0
  877. package/src/runtime/office/pdf/pdf-ocr.mjs +348 -0
  878. package/src/runtime/office/pdf/pdf-render.mjs +12 -13
  879. package/src/runtime/office/pdf/pdf-search.mjs +4 -1
  880. package/src/runtime/office/pdf/pdf-security.mjs +37 -9
  881. package/src/runtime/office/pdf/pdf-writer.mjs +670 -412
  882. package/src/runtime/office/portable/docx-revisions.mjs +15 -13
  883. package/src/runtime/office/portable/docx-runs.mjs +7 -12
  884. package/src/runtime/office/portable/docx-tracked-edits.mjs +15 -11
  885. package/src/runtime/office/portable/font-provisioner.mjs +2 -2
  886. package/src/runtime/office/portable/ooxml-validator.mjs +4 -1
  887. package/src/runtime/office/portable/portable-cells.mjs +67 -79
  888. package/src/runtime/office/portable/portable-chart-faults.mjs +42 -11
  889. package/src/runtime/office/portable/portable-chart.mjs +21 -17
  890. package/src/runtime/office/portable/portable-docx-edits.mjs +771 -0
  891. package/src/runtime/office/portable/portable-docx-operations.mjs +742 -0
  892. package/src/runtime/office/portable/portable-docx-parts.mjs +83 -63
  893. package/src/runtime/office/portable/portable-docx-xml.mjs +93 -65
  894. package/src/runtime/office/portable/portable-docx.mjs +84 -1340
  895. package/src/runtime/office/portable/portable-ooxml.mjs +5 -6
  896. package/src/runtime/office/portable/portable-opc.mjs +128 -34
  897. package/src/runtime/office/portable/portable-package.mjs +21 -30
  898. package/src/runtime/office/portable/portable-pivot.mjs +35 -30
  899. package/src/runtime/office/portable/portable-pptx-chart.mjs +7 -6
  900. package/src/runtime/office/portable/portable-pptx-charts.mjs +75 -65
  901. package/src/runtime/office/portable/portable-pptx-core.mjs +103 -113
  902. package/src/runtime/office/portable/portable-pptx-deck.mjs +21 -21
  903. package/src/runtime/office/portable/portable-pptx-package.mjs +23 -30
  904. package/src/runtime/office/portable/portable-pptx-shapes.mjs +370 -326
  905. package/src/runtime/office/portable/portable-shared-formulas.mjs +92 -0
  906. package/src/runtime/office/portable/portable-sheet-audits.mjs +394 -0
  907. package/src/runtime/office/portable/portable-sheet-page.mjs +22 -23
  908. package/src/runtime/office/portable/portable-sheet-parts.mjs +4 -5
  909. package/src/runtime/office/portable/portable-sheet-styles.mjs +19 -26
  910. package/src/runtime/office/portable/portable-sheet-xml.mjs +43 -36
  911. package/src/runtime/office/portable/portable-slide-shapes.mjs +48 -28
  912. package/src/runtime/office/portable/portable-snapshot-docx.mjs +622 -0
  913. package/src/runtime/office/portable/portable-snapshot-pptx.mjs +254 -0
  914. package/src/runtime/office/portable/portable-snapshot-shared.mjs +106 -0
  915. package/src/runtime/office/portable/portable-snapshot-xlsx.mjs +452 -0
  916. package/src/runtime/office/portable/portable-snapshot.mjs +8 -1134
  917. package/src/runtime/office/portable/portable-soffice.mjs +395 -234
  918. package/src/runtime/office/portable/portable-validation-package.mjs +310 -0
  919. package/src/runtime/office/portable/portable-validation.mjs +652 -1109
  920. package/src/runtime/office/portable/portable-xlsx-cell-values.mjs +15 -0
  921. package/src/runtime/office/portable/portable-xlsx-charts.mjs +192 -0
  922. package/src/runtime/office/portable/portable-xlsx-drawings.mjs +323 -0
  923. package/src/runtime/office/portable/portable-xlsx-operations.mjs +404 -0
  924. package/src/runtime/office/portable/portable-xlsx-pivot-ops.mjs +94 -0
  925. package/src/runtime/office/portable/portable-xlsx-range-layout.mjs +236 -0
  926. package/src/runtime/office/portable/portable-xlsx-sheet-edits.mjs +536 -0
  927. package/src/runtime/office/portable/portable-xlsx.mjs +135 -1387
  928. package/src/runtime/office/portable/portable-xml.mjs +13 -8
  929. package/src/runtime/office/portable/pptx-relations.mjs +12 -1
  930. package/src/runtime/office/portable/pptx-targets.mjs +2 -1
  931. package/src/runtime/office/portable/review-editability.mjs +7 -12
  932. package/src/runtime/office/portable/text-metrics.mjs +156 -139
  933. package/src/runtime/office/portable/xlsx-assertions.mjs +2 -15
  934. package/src/runtime/office/portable/xlsx-audit-support.mjs +2 -6
  935. package/src/runtime/office/portable/xlsx-contract.mjs +136 -106
  936. package/src/runtime/office/portable/xlsx-formula-audit.mjs +253 -118
  937. package/src/runtime/office/portable/xlsx-formula-engine.mjs +549 -0
  938. package/src/runtime/office/portable/xlsx-recalculate.mjs +278 -0
  939. package/src/runtime/office/portable/xlsx-sheet-hygiene.mjs +103 -27
  940. package/src/runtime/office/quality/assurance-checklist.mjs +82 -60
  941. package/src/runtime/office/quality/assurance-issue.mjs +5 -0
  942. package/src/runtime/office/quality/assurance-rendered.mjs +3 -2
  943. package/src/runtime/office/quality/assurance-structure-docx.mjs +205 -0
  944. package/src/runtime/office/quality/assurance-structure-pptx.mjs +763 -0
  945. package/src/runtime/office/quality/assurance-structure-xlsx.mjs +256 -0
  946. package/src/runtime/office/quality/assurance-structure.mjs +4 -798
  947. package/src/runtime/office/quality/assurance-trust.mjs +65 -55
  948. package/src/runtime/office/quality/design-aesthetics.mjs +175 -151
  949. package/src/runtime/office/quality/design-deck-diversity.mjs +87 -53
  950. package/src/runtime/office/quality/design-review-authored.mjs +2 -2
  951. package/src/runtime/office/quality/design-review-critique.mjs +43 -43
  952. package/src/runtime/office/quality/design-review.mjs +123 -109
  953. package/src/runtime/office/quality/document-acceptance.mjs +18 -10
  954. package/src/runtime/office/quality/inline-audit.mjs +9 -3
  955. package/src/runtime/office/quality/pptx-deck-rubric.mjs +14 -6
  956. package/src/runtime/office/quality/pptx-slide-roles.mjs +7 -9
  957. package/src/runtime/office/quality/presentation-acceptance.mjs +4 -12
  958. package/src/runtime/office/quality/quality-pipeline.mjs +70 -25
  959. package/src/runtime/office/quality/quality-score.mjs +7 -9
  960. package/src/runtime/office/quality/render-air.mjs +12 -5
  961. package/src/runtime/office/quality/visual-diff.mjs +0 -2
  962. package/src/runtime/shared/abort-controller.mjs +1 -1
  963. package/src/runtime/shared/agent-reap-state.mjs +35 -0
  964. package/src/runtime/shared/atomic-file.mjs +24 -13
  965. package/src/runtime/shared/automation-attachments.mjs +5 -4
  966. package/src/runtime/shared/background-tasks.mjs +44 -9
  967. package/src/runtime/shared/boot-profile.mjs +6 -2
  968. package/src/runtime/shared/buffered-appender.mjs +1 -1
  969. package/src/runtime/shared/child-spawn-gate.mjs +2 -2
  970. package/src/runtime/shared/code-point-order.mjs +5 -0
  971. package/src/runtime/shared/config-patch.mjs +9 -12
  972. package/src/runtime/shared/config.mjs +12 -18
  973. package/src/runtime/shared/err-text.mjs +11 -6
  974. package/src/runtime/shared/error-presentation.mjs +2 -8
  975. package/src/runtime/shared/extension-scopes.mjs +3 -1
  976. package/src/runtime/shared/file-lock.mjs +12 -7
  977. package/src/runtime/shared/injected-display-text.mjs +38 -0
  978. package/src/runtime/shared/inline-file-kind.mjs +51 -0
  979. package/src/runtime/shared/llm/cost.mjs +6 -9
  980. package/src/runtime/shared/llm/http-agent.mjs +1 -1
  981. package/src/runtime/shared/llm/index.mjs +1 -1
  982. package/src/runtime/shared/llm/reasoning-usage.mjs +42 -0
  983. package/src/runtime/shared/llm/usage-accounting.mjs +9 -6
  984. package/src/runtime/shared/llm/usage-ledger-import.mjs +3 -1
  985. package/src/runtime/shared/llm/usage-ledger-repair.mjs +6 -14
  986. package/src/runtime/shared/llm/usage-ledger-rollup.mjs +272 -0
  987. package/src/runtime/shared/llm/usage-ledger.mjs +30 -239
  988. package/src/runtime/shared/llm/usage-rollup.mjs +8 -2
  989. package/src/runtime/shared/loopback-listener.mjs +1 -6
  990. package/src/runtime/shared/open-url.mjs +1 -1
  991. package/src/runtime/shared/orchestration.mjs +2 -2
  992. package/src/runtime/shared/plugin-paths.mjs +3 -3
  993. package/src/runtime/shared/pristine-execution.mjs +2 -6
  994. package/src/runtime/shared/process-lifecycle.mjs +34 -52
  995. package/src/runtime/shared/process-shutdown.mjs +5 -5
  996. package/src/runtime/shared/provider-accounts.mjs +109 -11
  997. package/src/runtime/shared/resource-admission.mjs +32 -8
  998. package/src/runtime/shared/review-diff.mjs +34 -0
  999. package/src/runtime/shared/schedule-model-ref.mjs +14 -0
  1000. package/src/runtime/shared/schedule-session-run.mjs +3 -13
  1001. package/src/runtime/shared/schedules-db.mjs +17 -40
  1002. package/src/runtime/shared/schema-value-error.mjs +3 -5
  1003. package/src/runtime/shared/skill-selection.mjs +3 -1
  1004. package/src/runtime/shared/staged-child-result.mjs +2 -9
  1005. package/src/runtime/shared/staged-update.mjs +2 -6
  1006. package/src/runtime/shared/task-notification-envelope.mjs +130 -58
  1007. package/src/runtime/shared/time-format.mjs +6 -5
  1008. package/src/runtime/shared/tool-card-model/agent-surface.mjs +175 -0
  1009. package/src/runtime/shared/tool-card-model/aggregate-card.mjs +66 -0
  1010. package/src/runtime/shared/tool-card-model/background-task.mjs +171 -0
  1011. package/src/runtime/shared/tool-card-model/card-detail.mjs +115 -0
  1012. package/src/runtime/shared/tool-card-model/card-header.mjs +48 -0
  1013. package/src/runtime/shared/tool-card-model/card-input.mjs +85 -0
  1014. package/src/runtime/shared/tool-card-model/card-status.mjs +84 -0
  1015. package/src/runtime/shared/tool-card-model/displayed-result.mjs +43 -0
  1016. package/src/runtime/shared/tool-card-model/generic-detail.mjs +81 -0
  1017. package/src/runtime/shared/tool-card-model/git-result.mjs +9 -0
  1018. package/src/runtime/shared/tool-card-model/inline-text.mjs +78 -0
  1019. package/src/runtime/shared/tool-card-model/shell-surface.mjs +45 -0
  1020. package/src/runtime/shared/tool-card-model/terminal-status.mjs +109 -0
  1021. package/src/runtime/shared/tool-card-model.golden-cases.mjs +216 -0
  1022. package/src/runtime/shared/tool-card-model.golden.json +955 -0
  1023. package/src/runtime/shared/tool-card-model.mjs +110 -893
  1024. package/src/runtime/shared/tool-execution-contract.mjs +123 -83
  1025. package/src/runtime/shared/tool-primitives.mjs +2 -1
  1026. package/src/runtime/shared/tool-result-summary.mjs +242 -238
  1027. package/src/runtime/shared/tool-surface.mjs +63 -494
  1028. package/src/runtime/shared/tool-work-units.mjs +508 -0
  1029. package/src/runtime/shared/transcript-writer/rotation.mjs +90 -0
  1030. package/src/runtime/shared/transcript-writer/session-record.mjs +49 -0
  1031. package/src/runtime/shared/transcript-writer/transcript-file.mjs +108 -0
  1032. package/src/runtime/shared/transcript-writer.mjs +35 -239
  1033. package/src/runtime/shared/transport-error-text.mjs +53 -66
  1034. package/src/runtime/shared/turn-snapshot-store.mjs +16 -4
  1035. package/src/runtime/shared/turn-snapshot.mjs +31 -16
  1036. package/src/runtime/shared/turn-worktree-snapshot.mjs +131 -27
  1037. package/src/runtime/shared/update-checker.mjs +6 -1
  1038. package/src/runtime/shared/user-cwd.mjs +4 -4
  1039. package/src/runtime/shared/user-data-guard.mjs +32 -24
  1040. package/src/runtime/shared/webhook-session-run.mjs +3 -15
  1041. package/src/runtime/shared/webhooks-db.mjs +1 -1
  1042. package/src/runtime/tidy/extract.mjs +1 -1
  1043. package/src/runtime/tidy/history-comment.mjs +43 -17
  1044. package/src/runtime/tidy/languages.mjs +20 -15
  1045. package/src/runtime/tidy/process.mjs +18 -21
  1046. package/src/runtime/tidy/report.mjs +210 -44
  1047. package/src/runtime/tidy/resolve.mjs +16 -20
  1048. package/src/runtime/tidy/rules/kotlin/no-history-comment.yml +1 -1
  1049. package/src/runtime/tidy/rules/kotlin/todo-marker.yml +1 -1
  1050. package/src/runtime/tidy/run-engines.mjs +29 -14
  1051. package/src/runtime/tidy/runners/air.mjs +2 -20
  1052. package/src/runtime/tidy/runners/biome.mjs +15 -19
  1053. package/src/runtime/tidy/runners/dprint.mjs +2 -23
  1054. package/src/runtime/tidy/runners/mago.mjs +5 -21
  1055. package/src/runtime/tidy/runners/ruff.mjs +2 -8
  1056. package/src/runtime/tidy/runners/shared.mjs +35 -9
  1057. package/src/runtime/tidy/runners/stylua.mjs +2 -20
  1058. package/src/runtime/tidy/shadow.mjs +138 -0
  1059. package/src/runtime/tidy/structural.mjs +67 -47
  1060. package/src/runtime/tidy/tool-defs.mjs +26 -6
  1061. package/src/runtime/tidy/tool.mjs +260 -41
  1062. package/src/runtime/tidy/worktree.mjs +114 -0
  1063. package/src/runtime/web-search/index.mjs +71 -77
  1064. package/src/runtime/web-search/lib/cache.mjs +1 -1
  1065. package/src/runtime/web-search/lib/config.mjs +3 -3
  1066. package/src/runtime/web-search/lib/document-content.mjs +3 -5
  1067. package/src/runtime/web-search/lib/fetch-pipeline.mjs +3 -1
  1068. package/src/runtime/web-search/lib/formatter.mjs +16 -9
  1069. package/src/runtime/web-search/lib/http-fetch.mjs +42 -56
  1070. package/src/runtime/web-search/lib/ssrf-guard.mjs +22 -60
  1071. package/src/runtime/web-search/lib/state.mjs +0 -4
  1072. package/src/runtime/web-search/lib/web-tools.mjs +3 -6
  1073. package/src/session-runtime/agent-tool-routing.mjs +3 -5
  1074. package/src/session-runtime/boot/apis.mjs +487 -0
  1075. package/src/session-runtime/boot/begin.mjs +123 -0
  1076. package/src/session-runtime/boot/config.mjs +108 -0
  1077. package/src/session-runtime/boot/facade.mjs +88 -0
  1078. package/src/session-runtime/boot/infrastructure.mjs +250 -0
  1079. package/src/session-runtime/boot/providers.mjs +240 -0
  1080. package/src/session-runtime/boot/session.mjs +125 -0
  1081. package/src/session-runtime/boot/shared.mjs +33 -0
  1082. package/src/session-runtime/boot/tools.mjs +250 -0
  1083. package/src/session-runtime/builtin-features.mjs +1 -1
  1084. package/src/session-runtime/config-helpers.mjs +35 -53
  1085. package/src/session-runtime/config-lifecycle/config-writers.mjs +152 -0
  1086. package/src/session-runtime/config-lifecycle/output-style-cache.mjs +42 -0
  1087. package/src/session-runtime/config-lifecycle.mjs +26 -184
  1088. package/src/session-runtime/context-inspection.mjs +434 -148
  1089. package/src/session-runtime/context-status-cache.mjs +124 -0
  1090. package/src/session-runtime/context-status-inspection.mjs +90 -0
  1091. package/src/session-runtime/context-status-shape.mjs +254 -0
  1092. package/src/session-runtime/context-status.mjs +40 -370
  1093. package/src/session-runtime/cwd-plugins/core-memory-context.mjs +60 -0
  1094. package/src/session-runtime/cwd-plugins/cwd-apply.mjs +83 -0
  1095. package/src/session-runtime/cwd-plugins/plugin-status.mjs +124 -0
  1096. package/src/session-runtime/cwd-plugins.mjs +16 -252
  1097. package/src/session-runtime/fs-utils.mjs +11 -1
  1098. package/src/session-runtime/goal-control.mjs +154 -0
  1099. package/src/session-runtime/goal-deadlines.mjs +4 -4
  1100. package/src/session-runtime/goal-facade-api.mjs +15 -12
  1101. package/src/session-runtime/goal-mutations.mjs +258 -0
  1102. package/src/session-runtime/goal-runtime.mjs +61 -794
  1103. package/src/session-runtime/goal-state.mjs +18 -15
  1104. package/src/session-runtime/goal-store.mjs +118 -0
  1105. package/src/session-runtime/goal-tasks.mjs +7 -10
  1106. package/src/session-runtime/goal-text.mjs +75 -27
  1107. package/src/session-runtime/goal-title.mjs +52 -0
  1108. package/src/session-runtime/goal-tool-defs.mjs +7 -8
  1109. package/src/session-runtime/goal-tool-exec.mjs +156 -0
  1110. package/src/session-runtime/goal-turns.mjs +217 -0
  1111. package/src/session-runtime/hook-payload.mjs +2 -1
  1112. package/src/session-runtime/inheritance-fit.mjs +3 -3
  1113. package/src/session-runtime/internal-tool-executor/bridge-tools.mjs +63 -0
  1114. package/src/session-runtime/internal-tool-executor/feature-tools.mjs +42 -0
  1115. package/src/session-runtime/internal-tool-executor/knowledge-tools.mjs +59 -0
  1116. package/src/session-runtime/internal-tool-executor/workspace-tools.mjs +63 -0
  1117. package/src/session-runtime/internal-tool-executor.mjs +40 -189
  1118. package/src/session-runtime/lifecycle/inheritance.mjs +192 -0
  1119. package/src/session-runtime/lifecycle/memory-ingest.mjs +42 -0
  1120. package/src/session-runtime/lifecycle/session-catalog.mjs +98 -0
  1121. package/src/session-runtime/lifecycle/session-switch/context-switch.mjs +70 -0
  1122. package/src/session-runtime/lifecycle/session-switch/resume.mjs +158 -0
  1123. package/src/session-runtime/lifecycle/session-switch/session-delete.mjs +93 -0
  1124. package/src/session-runtime/lifecycle/session-switch.mjs +45 -0
  1125. package/src/session-runtime/lifecycle/shared.mjs +32 -0
  1126. package/src/session-runtime/lifecycle/teardown/runtime-stops.mjs +94 -0
  1127. package/src/session-runtime/lifecycle/teardown/session-close.mjs +87 -0
  1128. package/src/session-runtime/lifecycle/teardown.mjs +172 -0
  1129. package/src/session-runtime/lifecycle-api.mjs +36 -850
  1130. package/src/session-runtime/mcp-glue/connect.mjs +159 -0
  1131. package/src/session-runtime/mcp-glue/server-catalog.mjs +100 -0
  1132. package/src/session-runtime/mcp-glue/server-input.mjs +79 -0
  1133. package/src/session-runtime/mcp-glue.mjs +21 -322
  1134. package/src/session-runtime/model-capabilities.mjs +1 -3
  1135. package/src/session-runtime/model-route/route-persist.mjs +49 -0
  1136. package/src/session-runtime/model-route/route-tuning.mjs +60 -0
  1137. package/src/session-runtime/model-route/set-route.mjs +156 -0
  1138. package/src/session-runtime/model-route/web-search-route.mjs +103 -0
  1139. package/src/session-runtime/model-route-api.mjs +21 -304
  1140. package/src/session-runtime/native-web-search/routes.mjs +74 -0
  1141. package/src/session-runtime/native-web-search/tool-shape.mjs +115 -0
  1142. package/src/session-runtime/native-web-search.mjs +83 -237
  1143. package/src/session-runtime/notification-bus.mjs +30 -7
  1144. package/src/session-runtime/orchestration.mjs +10 -5
  1145. package/src/session-runtime/plugin-mcp.mjs +7 -60
  1146. package/src/session-runtime/prewarm/channel-start.mjs +95 -0
  1147. package/src/session-runtime/prewarm/code-graph-prewarm.mjs +94 -0
  1148. package/src/session-runtime/prewarm/tool-runtime-warmup.mjs +79 -0
  1149. package/src/session-runtime/prewarm.mjs +13 -243
  1150. package/src/session-runtime/provider-auth/accounts.mjs +79 -0
  1151. package/src/session-runtime/provider-auth/login.mjs +78 -0
  1152. package/src/session-runtime/provider-auth/refresh.mjs +57 -0
  1153. package/src/session-runtime/provider-auth/setup.mjs +51 -0
  1154. package/src/session-runtime/provider-auth-api.mjs +18 -251
  1155. package/src/session-runtime/provider-models/catalog-load.mjs +90 -0
  1156. package/src/session-runtime/provider-models/model-meta.mjs +77 -0
  1157. package/src/session-runtime/provider-models/row-hydration.mjs +46 -0
  1158. package/src/session-runtime/provider-models/web-search-catalog.mjs +111 -0
  1159. package/src/session-runtime/provider-models.mjs +71 -286
  1160. package/src/session-runtime/provider-request-snapshot.mjs +1 -1
  1161. package/src/session-runtime/provider-usage.mjs +4 -4
  1162. package/src/session-runtime/quick-model-rows/model-meta.mjs +32 -0
  1163. package/src/session-runtime/quick-model-rows/provider-rows.mjs +77 -0
  1164. package/src/session-runtime/quick-model-rows/web-search-rows.mjs +144 -0
  1165. package/src/session-runtime/quick-model-rows.mjs +27 -221
  1166. package/src/session-runtime/resource-api.mjs +28 -522
  1167. package/src/session-runtime/resource-extension-sync.mjs +89 -0
  1168. package/src/session-runtime/resource-mcp-api.mjs +199 -0
  1169. package/src/session-runtime/resource-plugins-api.mjs +85 -0
  1170. package/src/session-runtime/resource-recall-api.mjs +92 -0
  1171. package/src/session-runtime/resource-scope-decorate.mjs +58 -0
  1172. package/src/session-runtime/resource-skills-api.mjs +50 -0
  1173. package/src/session-runtime/route-resolution.mjs +71 -0
  1174. package/src/session-runtime/route-state.mjs +86 -0
  1175. package/src/session-runtime/runtime-bootstrap.mjs +3 -3
  1176. package/src/session-runtime/runtime-core.mjs +37 -1375
  1177. package/src/session-runtime/runtime-paths.mjs +1 -3
  1178. package/src/session-runtime/self-update.mjs +2 -3
  1179. package/src/session-runtime/session-create/materialize.mjs +77 -0
  1180. package/src/session-runtime/session-create/route-prep.mjs +49 -0
  1181. package/src/session-runtime/session-create/session-options.mjs +73 -0
  1182. package/src/session-runtime/session-create/session-start-hook.mjs +39 -0
  1183. package/src/session-runtime/session-create.mjs +69 -0
  1184. package/src/session-runtime/session-hooks.mjs +40 -100
  1185. package/src/session-runtime/session-lifecycle.mjs +43 -417
  1186. package/src/session-runtime/session-text.mjs +7 -37
  1187. package/src/session-runtime/session-transcript.mjs +2 -4
  1188. package/src/session-runtime/session-turn-api.mjs +37 -757
  1189. package/src/session-runtime/settings-api.mjs +29 -528
  1190. package/src/session-runtime/settings-builtin-tools-api.mjs +191 -0
  1191. package/src/session-runtime/settings-compaction-api.mjs +161 -0
  1192. package/src/session-runtime/settings-profile-api.mjs +100 -0
  1193. package/src/session-runtime/settings-system-api.mjs +82 -0
  1194. package/src/session-runtime/setup-tool/executor.mjs +354 -315
  1195. package/src/session-runtime/setup-tool/extended-actions.mjs +42 -16
  1196. package/src/session-runtime/setup-tool/settings-contract.mjs +99 -39
  1197. package/src/session-runtime/setup-tool/tool-defs.mjs +22 -4
  1198. package/src/session-runtime/setup-tool/ui-requests.mjs +25 -7
  1199. package/src/session-runtime/skill-tool-loading.mjs +15 -8
  1200. package/src/session-runtime/skills-api.mjs +7 -8
  1201. package/src/session-runtime/statusline-route.mjs +1 -4
  1202. package/src/session-runtime/tool-catalog-data.mjs +1 -2
  1203. package/src/session-runtime/tool-catalog-schema.mjs +1 -7
  1204. package/src/session-runtime/tool-catalog.mjs +30 -33
  1205. package/src/session-runtime/tool-defs.mjs +2 -2
  1206. package/src/session-runtime/tool-policy-refresh.mjs +33 -21
  1207. package/src/session-runtime/tool-profile.mjs +0 -1
  1208. package/src/session-runtime/tool-surface.mjs +6 -4
  1209. package/src/session-runtime/turn/agent-ops.mjs +98 -0
  1210. package/src/session-runtime/turn/session-ops.mjs +132 -0
  1211. package/src/session-runtime/turn/share-ops.mjs +73 -0
  1212. package/src/session-runtime/turn/turn-run/ask-callbacks.mjs +90 -0
  1213. package/src/session-runtime/turn/turn-run/snapshot-tracker.mjs +51 -0
  1214. package/src/session-runtime/turn/turn-run/transcript.mjs +47 -0
  1215. package/src/session-runtime/turn/turn-run/turn-open.mjs +60 -0
  1216. package/src/session-runtime/turn/turn-run/turn-prepare.mjs +142 -0
  1217. package/src/session-runtime/turn/turn-run/turn-settle.mjs +105 -0
  1218. package/src/session-runtime/turn/turn-run/turn-timing.mjs +52 -0
  1219. package/src/session-runtime/turn/turn-run.mjs +121 -0
  1220. package/src/session-runtime/usage-stats-api.mjs +48 -33
  1221. package/src/session-runtime/warmup/catalog-warmup.mjs +34 -0
  1222. package/src/session-runtime/warmup/provider-warmups.mjs +105 -0
  1223. package/src/session-runtime/warmup/statusline-usage-warmup.mjs +82 -0
  1224. package/src/session-runtime/warmup/timer-arm.mjs +22 -0
  1225. package/src/session-runtime/warmup-schedulers.mjs +11 -232
  1226. package/src/session-runtime/workflow/agents.mjs +91 -0
  1227. package/src/session-runtime/workflow/context.mjs +89 -0
  1228. package/src/session-runtime/workflow/packs.mjs +68 -0
  1229. package/src/session-runtime/workflow-agents-api/agent-editor.mjs +152 -0
  1230. package/src/session-runtime/workflow-agents-api/agent-route.mjs +98 -0
  1231. package/src/session-runtime/workflow-agents-api/onboarding.mjs +113 -0
  1232. package/src/session-runtime/workflow-agents-api/shared.mjs +23 -0
  1233. package/src/session-runtime/workflow-agents-api/style-and-mode.mjs +61 -0
  1234. package/src/session-runtime/workflow-agents-api/workflow-packs.mjs +117 -0
  1235. package/src/session-runtime/workflow-agents-api.mjs +16 -515
  1236. package/src/session-runtime/workflow-ids.mjs +56 -0
  1237. package/src/session-runtime/workflow.mjs +17 -289
  1238. package/src/standalone/agent-task-status.mjs +9 -4
  1239. package/src/standalone/agent-tool/close-flow/close-all.mjs +67 -0
  1240. package/src/standalone/agent-tool/close-flow.mjs +107 -0
  1241. package/src/standalone/agent-tool/execute-send.mjs +91 -0
  1242. package/src/standalone/agent-tool/execute-spawn.mjs +76 -0
  1243. package/src/standalone/agent-tool/execute.mjs +83 -0
  1244. package/src/standalone/agent-tool/helpers.mjs +6 -23
  1245. package/src/standalone/agent-tool/job-views/agent-list.mjs +71 -0
  1246. package/src/standalone/agent-tool/job-views/job-lookup.mjs +84 -0
  1247. package/src/standalone/agent-tool/job-views/job-render.mjs +98 -0
  1248. package/src/standalone/agent-tool/job-views/session-progress.mjs +81 -0
  1249. package/src/standalone/agent-tool/job-views/spawn-meta.mjs +62 -0
  1250. package/src/standalone/agent-tool/job-views.mjs +24 -373
  1251. package/src/standalone/agent-tool/lead-worker-index/index-file.mjs +45 -0
  1252. package/src/standalone/agent-tool/lead-worker-index/lead-rows.mjs +39 -0
  1253. package/src/standalone/agent-tool/lead-worker-index/reap-timers.mjs +31 -0
  1254. package/src/standalone/agent-tool/lead-worker-index/row-settlement.mjs +59 -0
  1255. package/src/standalone/agent-tool/lead-worker-index.mjs +28 -163
  1256. package/src/standalone/agent-tool/notify/early-completion.mjs +58 -0
  1257. package/src/standalone/agent-tool/notify.mjs +10 -58
  1258. package/src/standalone/agent-tool/provider-init.mjs +76 -68
  1259. package/src/standalone/agent-tool/render.mjs +130 -118
  1260. package/src/standalone/agent-tool/send-flow.mjs +186 -0
  1261. package/src/standalone/agent-tool/spawn-flow/deferred-spawn.mjs +97 -0
  1262. package/src/standalone/agent-tool/spawn-flow/job-start.mjs +83 -0
  1263. package/src/standalone/agent-tool/spawn-flow/spawn-plan.mjs +89 -0
  1264. package/src/standalone/agent-tool/spawn-flow/spawn-prep.mjs +120 -0
  1265. package/src/standalone/agent-tool/spawn-flow/spawn-run.mjs +222 -0
  1266. package/src/standalone/agent-tool/spawn-flow.mjs +30 -557
  1267. package/src/standalone/agent-tool/tag-maps.mjs +29 -0
  1268. package/src/standalone/agent-tool/tag-registry/tag-lookup.mjs +106 -0
  1269. package/src/standalone/agent-tool/tag-registry/tag-refresh.mjs +34 -0
  1270. package/src/standalone/agent-tool/tag-registry.mjs +63 -524
  1271. package/src/standalone/agent-tool/terminal-reaper/reap-timers.mjs +142 -0
  1272. package/src/standalone/agent-tool/terminal-reaper/row-helpers.mjs +25 -0
  1273. package/src/standalone/agent-tool/terminal-reaper/scan-admission.mjs +89 -0
  1274. package/src/standalone/agent-tool/terminal-reaper/stale-rows.mjs +52 -0
  1275. package/src/standalone/agent-tool/terminal-reaper/tombstones.mjs +113 -0
  1276. package/src/standalone/agent-tool/terminal-reaper.mjs +46 -0
  1277. package/src/standalone/agent-tool/terminal-trace.mjs +40 -0
  1278. package/src/standalone/agent-tool/tool-def.mjs +1 -2
  1279. package/src/standalone/agent-tool/turn-review.mjs +27 -0
  1280. package/src/standalone/agent-tool/worker-index/mutation-batch.mjs +41 -0
  1281. package/src/standalone/agent-tool/worker-index/row-liveness.mjs +65 -0
  1282. package/src/standalone/agent-tool/worker-index/row-shape.mjs +109 -0
  1283. package/src/standalone/agent-tool/worker-index/row-store.mjs +100 -0
  1284. package/src/standalone/agent-tool/worker-index.mjs +66 -345
  1285. package/src/standalone/agent-tool/worker-rows.mjs +34 -16
  1286. package/src/standalone/agent-tool.mjs +61 -650
  1287. package/src/standalone/agent-watchdog-registry.mjs +36 -8
  1288. package/src/standalone/channel-admin.mjs +16 -23
  1289. package/src/standalone/channel-client/daemon-request.mjs +136 -0
  1290. package/src/standalone/channel-client/notify-stream.mjs +130 -0
  1291. package/src/standalone/channel-client/reconnect.mjs +113 -0
  1292. package/src/standalone/channel-client/registration.mjs +87 -0
  1293. package/src/standalone/channel-client.mjs +58 -460
  1294. package/src/standalone/channel-transport/call-dispatch.mjs +209 -0
  1295. package/src/standalone/channel-transport/client-registry/client-grace.mjs +69 -0
  1296. package/src/standalone/channel-transport/client-registry/registration-replays.mjs +96 -0
  1297. package/src/standalone/channel-transport/client-registry/sse-attach.mjs +44 -0
  1298. package/src/standalone/channel-transport/client-registry.mjs +228 -0
  1299. package/src/standalone/channel-transport/http-routes.mjs +171 -0
  1300. package/src/standalone/channel-transport/remote-binding.mjs +99 -0
  1301. package/src/standalone/channel-transport/remote-intent.mjs +52 -0
  1302. package/src/standalone/channel-transport/remote-notify.mjs +46 -0
  1303. package/src/standalone/channel-transport/remote-pointer.mjs +124 -0
  1304. package/src/standalone/channel-transport/remote-state.mjs +47 -0
  1305. package/src/standalone/channel-transport.mjs +111 -982
  1306. package/src/standalone/channel-worker/client-heartbeat.mjs +103 -0
  1307. package/src/standalone/channel-worker/daemon-attach.mjs +157 -0
  1308. package/src/standalone/channel-worker/daemon-spawn.mjs +93 -0
  1309. package/src/standalone/channel-worker.mjs +55 -342
  1310. package/src/standalone/daemon-agent-control.mjs +65 -0
  1311. package/src/standalone/daemon-boot-coordinator.mjs +6 -2
  1312. package/src/standalone/daemon-channels-loader.mjs +60 -0
  1313. package/src/standalone/daemon-crash-capture/paths.mjs +16 -0
  1314. package/src/standalone/daemon-crash-capture/retention.mjs +217 -0
  1315. package/src/standalone/daemon-crash-capture/spawn-capture.mjs +370 -0
  1316. package/src/standalone/daemon-crash-capture.mjs +14 -568
  1317. package/src/standalone/daemon-desktop-runtime.mjs +28 -0
  1318. package/src/standalone/daemon-local-session-bridge.mjs +62 -0
  1319. package/src/standalone/daemon-stored-session-views.mjs +55 -0
  1320. package/src/standalone/daemon.mjs +175 -323
  1321. package/src/standalone/desktop-service-registry.mjs +13 -14
  1322. package/src/standalone/fair-call-scheduler/owner-groups.mjs +90 -0
  1323. package/src/standalone/fair-call-scheduler/queue-item.mjs +21 -0
  1324. package/src/standalone/fair-call-scheduler.mjs +94 -167
  1325. package/src/standalone/folder-dialog.mjs +11 -12
  1326. package/src/standalone/hook-bus/command-handler.mjs +61 -50
  1327. package/src/standalone/hook-bus/config-loader.mjs +130 -0
  1328. package/src/standalone/hook-bus/config.mjs +8 -9
  1329. package/src/standalone/hook-bus/event-log.mjs +30 -0
  1330. package/src/standalone/hook-bus/event-runner.mjs +108 -0
  1331. package/src/standalone/hook-bus/handler-dispatch.mjs +75 -0
  1332. package/src/standalone/hook-bus/rule-store.mjs +149 -0
  1333. package/src/standalone/hook-bus/tool-gate.mjs +72 -0
  1334. package/src/standalone/hook-bus.mjs +65 -511
  1335. package/src/standalone/memory-runtime-proxy/calls.mjs +121 -0
  1336. package/src/standalone/memory-runtime-proxy/client-registry.mjs +93 -0
  1337. package/src/standalone/memory-runtime-proxy/daemon-spawn.mjs +158 -0
  1338. package/src/standalone/memory-runtime-proxy/discovery.mjs +98 -0
  1339. package/src/standalone/memory-runtime-proxy/owner-claim.mjs +67 -0
  1340. package/src/standalone/memory-runtime-proxy/rpc.mjs +122 -0
  1341. package/src/standalone/memory-runtime-proxy/start.mjs +51 -0
  1342. package/src/standalone/memory-runtime-proxy/state.mjs +21 -0
  1343. package/src/standalone/memory-runtime-proxy/tool-wire.mjs +32 -0
  1344. package/src/standalone/memory-runtime-proxy.mjs +52 -712
  1345. package/src/standalone/plugin-admin.mjs +4 -9
  1346. package/src/standalone/provider-admin.mjs +197 -193
  1347. package/src/standalone/seeds.mjs +132 -5
  1348. package/src/standalone/session-client/attachment-calls.mjs +67 -0
  1349. package/src/standalone/session-client/frame-stream.mjs +125 -0
  1350. package/src/standalone/session-client/stream-link.mjs +85 -0
  1351. package/src/standalone/session-client/stream-reconnect.mjs +119 -0
  1352. package/src/standalone/session-client.mjs +87 -338
  1353. package/src/standalone/session-frame-stream.mjs +7 -8
  1354. package/src/standalone/session-protocol.mjs +1 -1
  1355. package/src/standalone/session-proxy/project-routes.mjs +25 -0
  1356. package/src/standalone/session-proxy/projection.mjs +112 -0
  1357. package/src/standalone/session-proxy/proxy-view.mjs +50 -0
  1358. package/src/standalone/session-proxy/remote-actions.mjs +121 -0
  1359. package/src/standalone/session-proxy/resync.mjs +67 -0
  1360. package/src/standalone/session-proxy/transitions.mjs +99 -0
  1361. package/src/standalone/session-proxy/transport-calls.mjs +121 -0
  1362. package/src/standalone/session-proxy.mjs +49 -527
  1363. package/src/standalone/session-runtime-agent-control-client.mjs +13 -31
  1364. package/src/standalone/session-runtime-agent-control.mjs +85 -0
  1365. package/src/standalone/session-runtime-host.mjs +36 -582
  1366. package/src/standalone/session-runtime-inline-host/agent-dispatch.mjs +66 -0
  1367. package/src/standalone/session-runtime-inline-host/boot-loaders.mjs +96 -0
  1368. package/src/standalone/session-runtime-inline-host/runtime-records.mjs +66 -0
  1369. package/src/standalone/session-runtime-inline-host/telemetry.mjs +38 -0
  1370. package/src/standalone/session-runtime-inline-host.mjs +33 -219
  1371. package/src/standalone/session-runtime-proxy.mjs +164 -0
  1372. package/src/standalone/session-runtime-shard-router.mjs +4 -7
  1373. package/src/standalone/session-runtime-spawn-leases.mjs +82 -0
  1374. package/src/standalone/session-runtime-worker.mjs +29 -13
  1375. package/src/standalone/session-runtime-workload.mjs +98 -0
  1376. package/src/standalone/session-service/agent-tree/agent-cancel.mjs +79 -0
  1377. package/src/standalone/session-service/agent-tree/agent-child.mjs +59 -0
  1378. package/src/standalone/session-service/agent-tree/agent-registry.mjs +73 -0
  1379. package/src/standalone/session-service/agent-tree/agent-rehydrate.mjs +163 -0
  1380. package/src/standalone/session-service/agent-tree/agent-turns.mjs +71 -0
  1381. package/src/standalone/session-service/agent-tree.mjs +93 -388
  1382. package/src/standalone/session-service/entries/disposal.mjs +72 -0
  1383. package/src/standalone/session-service/entries/external-binding.mjs +63 -0
  1384. package/src/standalone/session-service/entries/lifecycle.mjs +96 -0
  1385. package/src/standalone/session-service/entries/session-loads.mjs +109 -0
  1386. package/src/standalone/session-service/entries.mjs +95 -0
  1387. package/src/standalone/session-service/projection/address-index.mjs +54 -0
  1388. package/src/standalone/session-service/projection/external-views.mjs +91 -0
  1389. package/src/standalone/session-service/projection/frames.mjs +79 -0
  1390. package/src/standalone/session-service/projection/revisions.mjs +100 -0
  1391. package/src/standalone/session-service/projection.mjs +36 -274
  1392. package/src/standalone/session-service/retention/busy.mjs +50 -0
  1393. package/src/standalone/session-service/retention.mjs +119 -0
  1394. package/src/standalone/session-service/session-calls/goal-recovery.mjs +44 -0
  1395. package/src/standalone/session-service/session-calls/session-action.mjs +94 -0
  1396. package/src/standalone/session-service/session-calls/session-turns.mjs +135 -0
  1397. package/src/standalone/session-service/session-calls/session-views.mjs +192 -0
  1398. package/src/standalone/session-service/session-calls.mjs +59 -0
  1399. package/src/standalone/session-service/viewers.mjs +111 -0
  1400. package/src/standalone/session-service.mjs +135 -992
  1401. package/src/standalone/session-state-projection.mjs +5 -1
  1402. package/src/standalone/session-transport/call-lanes.mjs +113 -0
  1403. package/src/standalone/session-transport/call-route.mjs +104 -0
  1404. package/src/standalone/session-transport/client-registry/client-grace.mjs +81 -0
  1405. package/src/standalone/session-transport/client-registry/registration-replays.mjs +69 -0
  1406. package/src/standalone/session-transport/client-registry.mjs +129 -0
  1407. package/src/standalone/session-transport/routes.mjs +185 -0
  1408. package/src/standalone/session-transport/stack.mjs +131 -0
  1409. package/src/standalone/session-transport.mjs +31 -594
  1410. package/src/standalone/sse-frames.mjs +27 -0
  1411. package/src/standalone/usage-dashboard-model.mjs +28 -22
  1412. package/src/standalone/usage-dashboard.mjs +167 -163
  1413. package/src/standalone/usage-stats-hours.mjs +2 -6
  1414. package/src/standalone/usage-stats-model.mjs +133 -120
  1415. package/src/standalone/usage-stats-period.mjs +83 -22
  1416. package/src/tui/App.jsx +27 -216
  1417. package/src/tui/app/app-format.mjs +14 -1
  1418. package/src/tui/app/app-view/floating-panel.jsx +229 -0
  1419. package/src/tui/app/app-view/text-entry-labels.mjs +81 -0
  1420. package/src/tui/app/app-view/transcript-viewport/trailing-bands.jsx +94 -0
  1421. package/src/tui/app/app-view/transcript-viewport/transcript-rows.jsx +87 -0
  1422. package/src/tui/app/app-view/transcript-viewport.jsx +74 -0
  1423. package/src/tui/app/app-view.jsx +16 -427
  1424. package/src/tui/app/clipboard.mjs +1 -1
  1425. package/src/tui/app/core-memory-picker/core-rows.mjs +32 -0
  1426. package/src/tui/app/core-memory-picker/entry-prompts.mjs +45 -0
  1427. package/src/tui/app/core-memory-picker/list-panels.mjs +75 -0
  1428. package/src/tui/app/core-memory-picker.mjs +33 -131
  1429. package/src/tui/app/create-app-pickers.mjs +2 -2
  1430. package/src/tui/app/doctor.mjs +163 -135
  1431. package/src/tui/app/extension-pickers/mcp-servers-picker.mjs +115 -0
  1432. package/src/tui/app/extension-pickers/plugins-pickers.mjs +236 -0
  1433. package/src/tui/app/extension-pickers/scope-note.mjs +30 -0
  1434. package/src/tui/app/extension-pickers/skills-pickers/project-skills.mjs +38 -0
  1435. package/src/tui/app/extension-pickers/skills-pickers/skill-detail.mjs +80 -0
  1436. package/src/tui/app/extension-pickers/skills-pickers/skill-items.mjs +44 -0
  1437. package/src/tui/app/extension-pickers/skills-pickers.mjs +95 -0
  1438. package/src/tui/app/extension-pickers.mjs +29 -532
  1439. package/src/tui/app/input-parsers.mjs +6 -5
  1440. package/src/tui/app/maintenance-pickers/auto-clear-picker.mjs +167 -0
  1441. package/src/tui/app/maintenance-pickers/profile-picker.mjs +147 -0
  1442. package/src/tui/app/maintenance-pickers/update-picker.mjs +175 -0
  1443. package/src/tui/app/maintenance-pickers.mjs +18 -449
  1444. package/src/tui/app/model-options.mjs +5 -39
  1445. package/src/tui/app/model-picker/catalog-load.mjs +101 -0
  1446. package/src/tui/app/model-picker/model-footer.mjs +79 -0
  1447. package/src/tui/app/model-picker/provider-models-list.mjs +115 -0
  1448. package/src/tui/app/model-picker/route-selection/context-window.mjs +47 -0
  1449. package/src/tui/app/model-picker/route-selection/effort.mjs +87 -0
  1450. package/src/tui/app/model-picker/route-selection/fast-parameters.mjs +84 -0
  1451. package/src/tui/app/model-picker/route-selection/model-key.mjs +5 -0
  1452. package/src/tui/app/model-picker/route-selection.mjs +61 -0
  1453. package/src/tui/app/model-picker.mjs +57 -460
  1454. package/src/tui/app/mouse-input/edge-autoscroll.mjs +53 -0
  1455. package/src/tui/app/mouse-input/geometry.mjs +109 -0
  1456. package/src/tui/app/mouse-input/sgr-buttons.mjs +14 -0
  1457. package/src/tui/app/mouse-input/wheel-router.mjs +96 -0
  1458. package/src/tui/app/onboarding/models-step.mjs +106 -0
  1459. package/src/tui/app/onboarding/persist.mjs +49 -0
  1460. package/src/tui/app/onboarding/role-model-picker.mjs +141 -0
  1461. package/src/tui/app/onboarding/step-data.mjs +65 -0
  1462. package/src/tui/app/onboarding-steps.mjs +45 -346
  1463. package/src/tui/app/panel-signature.mjs +58 -0
  1464. package/src/tui/app/panel-surface.mjs +2 -1
  1465. package/src/tui/app/project-picker/create-flow.mjs +76 -0
  1466. package/src/tui/app/project-picker/picker-state.mjs +78 -0
  1467. package/src/tui/app/project-picker/project-service.mjs +57 -0
  1468. package/src/tui/app/project-picker.mjs +29 -221
  1469. package/src/tui/app/prompt-handlers/history-navigation.mjs +32 -0
  1470. package/src/tui/app/prompt-handlers/paste-pipeline.mjs +72 -0
  1471. package/src/tui/app/prompt-handlers/use-prompt-history-nav.mjs +31 -0
  1472. package/src/tui/app/prompt-handlers/use-prompt-interrupt.mjs +102 -0
  1473. package/src/tui/app/prompt-handlers/use-prompt-paste.mjs +48 -0
  1474. package/src/tui/app/prompt-submit/chat-submit.mjs +66 -0
  1475. package/src/tui/app/prompt-submit/panel-write.mjs +54 -0
  1476. package/src/tui/app/prompt-submit/provider-prompts.mjs +103 -0
  1477. package/src/tui/app/prompt-submit/settings-prompts.mjs +337 -0
  1478. package/src/tui/app/prompt-submit.mjs +23 -561
  1479. package/src/tui/app/provider-setup/api-key-actions.mjs +91 -0
  1480. package/src/tui/app/provider-setup/oauth-actions.mjs +222 -0
  1481. package/src/tui/app/provider-setup/provider-items.mjs +97 -0
  1482. package/src/tui/app/provider-setup-picker.mjs +81 -499
  1483. package/src/tui/app/resume-picker.mjs +2 -5
  1484. package/src/tui/app/route-pickers/agents-picker.mjs +155 -0
  1485. package/src/tui/app/route-pickers/output-style-picker.mjs +123 -0
  1486. package/src/tui/app/route-pickers/workflow-picker.mjs +84 -0
  1487. package/src/tui/app/route-pickers.mjs +13 -322
  1488. package/src/tui/app/settings-picker/settings-navigation.mjs +69 -0
  1489. package/src/tui/app/settings-picker/settings-rows.mjs +200 -0
  1490. package/src/tui/app/settings-picker/settings-toggles/cycled.mjs +4 -0
  1491. package/src/tui/app/settings-picker/settings-toggles/listed-cyclers.mjs +77 -0
  1492. package/src/tui/app/settings-picker/settings-toggles/store-toggles.mjs +61 -0
  1493. package/src/tui/app/settings-picker/settings-toggles/theme-cycler.mjs +36 -0
  1494. package/src/tui/app/settings-picker/settings-toggles.mjs +62 -0
  1495. package/src/tui/app/settings-picker.mjs +42 -431
  1496. package/src/tui/app/shell-layout/panel-transition.mjs +140 -0
  1497. package/src/tui/app/shell-layout/row-budgets.mjs +268 -0
  1498. package/src/tui/app/shell-layout/surfaces.mjs +93 -0
  1499. package/src/tui/app/shell-layout/viewport.mjs +151 -0
  1500. package/src/tui/app/shell-layout.mjs +34 -568
  1501. package/src/tui/app/slash-commands.mjs +14 -4
  1502. package/src/tui/app/slash-dispatch/panel-commands.mjs +84 -0
  1503. package/src/tui/app/slash-dispatch/route-commands.mjs +191 -0
  1504. package/src/tui/app/slash-dispatch/session-commands.mjs +128 -0
  1505. package/src/tui/app/slash-dispatch/slash-panel.mjs +43 -0
  1506. package/src/tui/app/slash-dispatch.mjs +19 -449
  1507. package/src/tui/app/store-service-call.mjs +17 -0
  1508. package/src/tui/app/text-entry-policy.mjs +1 -3
  1509. package/src/tui/app/theme-effort-pickers.mjs +4 -11
  1510. package/src/tui/app/transcript-anchor-lock.mjs +120 -0
  1511. package/src/tui/app/transcript-anchor-sync.mjs +173 -0
  1512. package/src/tui/app/transcript-measure.mjs +245 -0
  1513. package/src/tui/app/transcript-row-estimate.mjs +38 -122
  1514. package/src/tui/app/transcript-scroll-anchor.mjs +42 -0
  1515. package/src/tui/app/transcript-window.mjs +121 -122
  1516. package/src/tui/app/usage-context-panels/context-model.mjs +282 -0
  1517. package/src/tui/app/usage-context-panels/usage-panel.mjs +48 -0
  1518. package/src/tui/app/usage-context-panels.mjs +24 -282
  1519. package/src/tui/app/use-copy-selection.mjs +5 -4
  1520. package/src/tui/app/use-disabled-skills.mjs +52 -0
  1521. package/src/tui/app/use-global-key-input/copy-first.mjs +43 -0
  1522. package/src/tui/app/use-global-key-input/shift-arrow.mjs +30 -0
  1523. package/src/tui/app/use-global-key-input.mjs +12 -70
  1524. package/src/tui/app/use-model-catalog-cache.mjs +86 -0
  1525. package/src/tui/app/use-mouse-input.mjs +71 -229
  1526. package/src/tui/app/use-pasted-buffers.mjs +56 -82
  1527. package/src/tui/app/use-prompt-draft-flow/draft-change.mjs +66 -0
  1528. package/src/tui/app/use-prompt-draft-flow/prompt-cancels.mjs +40 -0
  1529. package/src/tui/app/use-prompt-draft-flow.mjs +39 -78
  1530. package/src/tui/app/use-prompt-handlers.mjs +32 -257
  1531. package/src/tui/app/use-prompt-hint.mjs +1 -1
  1532. package/src/tui/app/use-prompt-queue-history/prompt-history.mjs +22 -0
  1533. package/src/tui/app/use-prompt-queue-history/restore-to-prompt.mjs +147 -0
  1534. package/src/tui/app/use-prompt-queue-history.mjs +21 -118
  1535. package/src/tui/app/use-selection-focus.mjs +133 -0
  1536. package/src/tui/app/use-selection-geometry.mjs +105 -0
  1537. package/src/tui/app/use-selection-paint/paint-queue.mjs +90 -0
  1538. package/src/tui/app/use-selection-paint/selection-clip.mjs +33 -0
  1539. package/src/tui/app/use-selection-paint.mjs +121 -0
  1540. package/src/tui/app/use-selection-stitch.mjs +128 -0
  1541. package/src/tui/app/use-terminal-chrome.mjs +1 -1
  1542. package/src/tui/app/use-transcript-activity.mjs +5 -4
  1543. package/src/tui/app/use-transcript-follow.mjs +91 -0
  1544. package/src/tui/app/use-transcript-scroll.mjs +220 -737
  1545. package/src/tui/app/use-transcript-window/geometry.mjs +139 -0
  1546. package/src/tui/app/use-transcript-window/instance-state.mjs +80 -0
  1547. package/src/tui/app/use-transcript-window/selection-shift.mjs +57 -0
  1548. package/src/tui/app/use-transcript-window/visible-items.mjs +46 -0
  1549. package/src/tui/app/use-transcript-window.mjs +101 -827
  1550. package/src/tui/app/use-welcome-prompt-hint.mjs +2 -2
  1551. package/src/tui/app/workflow-cycle.mjs +63 -0
  1552. package/src/tui/components/AnsiText.jsx +49 -19
  1553. package/src/tui/components/ContextInspector.jsx +87 -39
  1554. package/src/tui/components/ContextPanel.jsx +18 -34
  1555. package/src/tui/components/ItemRightHintOverprint.jsx +2 -15
  1556. package/src/tui/components/Markdown.jsx +4 -1
  1557. package/src/tui/components/Message.jsx +9 -2
  1558. package/src/tui/components/Picker.jsx +53 -62
  1559. package/src/tui/components/PromptInput.jsx +89 -335
  1560. package/src/tui/components/QueuedCommands.jsx +5 -6
  1561. package/src/tui/components/SlashCommandPalette.jsx +1 -18
  1562. package/src/tui/components/Spinner.jsx +26 -23
  1563. package/src/tui/components/StatusLine.jsx +18 -51
  1564. package/src/tui/components/TextEntryPanel.jsx +5 -52
  1565. package/src/tui/components/ToolExecution.jsx +27 -43
  1566. package/src/tui/components/TranscriptItem.jsx +5 -15
  1567. package/src/tui/components/TurnDone.jsx +26 -46
  1568. package/src/tui/components/UsagePanel.jsx +55 -66
  1569. package/src/tui/components/panel-cell-text.mjs +19 -0
  1570. package/src/tui/components/prompt-input/cursor-anchor.mjs +65 -0
  1571. package/src/tui/components/prompt-input/edit-helpers.mjs +9 -6
  1572. package/src/tui/components/prompt-input/key-signals.mjs +122 -0
  1573. package/src/tui/components/prompt-input/mouse-selection.mjs +114 -0
  1574. package/src/tui/components/prompt-input/restore-policy.d.mts +0 -1
  1575. package/src/tui/components/prompt-input/restore-policy.mjs +3 -8
  1576. package/src/tui/components/prompt-input/selected-text.jsx +25 -0
  1577. package/src/tui/components/prompt-input/undo-stack.mjs +75 -0
  1578. package/src/tui/components/tool-execution/text-format.mjs +2 -3
  1579. package/src/tui/components/tool-output-format.mjs +4 -5
  1580. package/src/tui/dist/index.mjs +10283 -8687
  1581. package/src/tui/hooks/useSharedTick.mjs +3 -9
  1582. package/src/tui/index.jsx +2 -2
  1583. package/src/tui/input-editing.mjs +3 -1
  1584. package/src/tui/markdown/ansi-line-wrap.mjs +37 -0
  1585. package/src/tui/markdown/format-token.mjs +6 -41
  1586. package/src/tui/markdown/measure-rendered-rows.mjs +14 -34
  1587. package/src/tui/markdown/render-ansi.mjs +5 -5
  1588. package/src/tui/markdown/stream-fence.mjs +1 -2
  1589. package/src/tui/markdown/streaming-markdown.mjs +1 -7
  1590. package/src/tui/markdown/table-layout/box-lines.mjs +46 -0
  1591. package/src/tui/markdown/table-layout/cells.mjs +23 -0
  1592. package/src/tui/markdown/table-layout/column-widths.mjs +65 -0
  1593. package/src/tui/markdown/table-layout/vertical-lines.mjs +46 -0
  1594. package/src/tui/markdown/table-layout.mjs +22 -189
  1595. package/src/tui/paste-attachments.mjs +1 -2
  1596. package/src/tui/prompt-history-store.mjs +1 -10
  1597. package/src/tui/session/active-tool-summary.mjs +63 -0
  1598. package/src/tui/session/agent-envelope.mjs +51 -22
  1599. package/src/tui/session/agent-job-feed/agent-job-card.mjs +30 -0
  1600. package/src/tui/session/agent-job-feed/agent-status-refresh.mjs +37 -0
  1601. package/src/tui/session/agent-job-feed/execution-dedup.mjs +80 -0
  1602. package/src/tui/session/agent-job-feed/execution-delivery.mjs +103 -0
  1603. package/src/tui/session/agent-job-feed/model-notification.mjs +79 -0
  1604. package/src/tui/session/agent-job-feed/notification-chain.mjs +64 -0
  1605. package/src/tui/session/agent-job-feed/notification-router.mjs +66 -0
  1606. package/src/tui/session/agent-job-feed/pending-resume.mjs +131 -0
  1607. package/src/tui/session/agent-job-feed.mjs +57 -513
  1608. package/src/tui/session/agent-response-tail.mjs +1 -1
  1609. package/src/tui/session/context-state.mjs +5 -2
  1610. package/src/tui/session/cross-surface-share.mjs +411 -0
  1611. package/src/tui/session/draft-store.mjs +85 -0
  1612. package/src/tui/session/goal-continuation/continuation-queue.mjs +90 -0
  1613. package/src/tui/session/goal-continuation/deadline-delivery.mjs +76 -0
  1614. package/src/tui/session/goal-continuation/goal-visibility.mjs +38 -0
  1615. package/src/tui/session/goal-continuation.mjs +34 -178
  1616. package/src/tui/session/initial-state.mjs +50 -0
  1617. package/src/tui/session/live-share/delta.mjs +153 -0
  1618. package/src/tui/session/live-share/mirror.mjs +106 -0
  1619. package/src/tui/session/live-share/owner.mjs +237 -0
  1620. package/src/tui/session/live-share/retry.mjs +54 -0
  1621. package/src/tui/session/live-share/viewer/frame-router.mjs +32 -0
  1622. package/src/tui/session/live-share/viewer/pipe-client.mjs +108 -0
  1623. package/src/tui/session/live-share/viewer/submit-acks.mjs +65 -0
  1624. package/src/tui/session/live-share/viewer/sync-waiters.mjs +53 -0
  1625. package/src/tui/session/live-share/viewer.mjs +99 -0
  1626. package/src/tui/session/live-share/wire.mjs +41 -0
  1627. package/src/tui/session/live-share.mjs +34 -775
  1628. package/src/tui/session/notice-surface.mjs +77 -0
  1629. package/src/tui/session/notice-text.mjs +21 -17
  1630. package/src/tui/session/notification-plan.mjs +7 -9
  1631. package/src/tui/session/oauth-flows.mjs +4 -4
  1632. package/src/tui/session/prompt-history.mjs +1 -1
  1633. package/src/tui/session/queue-helpers.mjs +15 -15
  1634. package/src/tui/session/render-timing.mjs +0 -1
  1635. package/src/tui/session/session-api/commands.mjs +163 -0
  1636. package/src/tui/session/session-api/controls.mjs +119 -0
  1637. package/src/tui/session/session-api/extensions.mjs +154 -0
  1638. package/src/tui/session/session-api/intake/abort.mjs +150 -0
  1639. package/src/tui/session/session-api/intake/rewind.mjs +47 -0
  1640. package/src/tui/session/session-api/intake/submission.mjs +106 -0
  1641. package/src/tui/session/session-api/intake.mjs +54 -0
  1642. package/src/tui/session/session-api/integrations.mjs +160 -0
  1643. package/src/tui/session/session-api/lifecycle/dispose.mjs +50 -0
  1644. package/src/tui/session/session-api/lifecycle/inheritance.mjs +73 -0
  1645. package/src/tui/session/session-api/lifecycle/resume.mjs +78 -0
  1646. package/src/tui/session/session-api/lifecycle/session-reset.mjs +147 -0
  1647. package/src/tui/session/session-api/lifecycle.mjs +51 -0
  1648. package/src/tui/session/session-api/media.mjs +125 -0
  1649. package/src/tui/session/session-api/routes.mjs +205 -0
  1650. package/src/tui/session/session-api/settings.mjs +163 -0
  1651. package/src/tui/session/session-api/shared.mjs +34 -0
  1652. package/src/tui/session/session-api-ext.mjs +18 -867
  1653. package/src/tui/session/session-api.mjs +14 -1026
  1654. package/src/tui/session/session-flow/auto-clear.mjs +185 -0
  1655. package/src/tui/session/session-flow/drain.mjs +282 -0
  1656. package/src/tui/session/session-flow/failed-turn-rewind.mjs +27 -0
  1657. package/src/tui/session/session-flow/queue/entry-shape.mjs +53 -0
  1658. package/src/tui/session/session-flow/queue/take-entries.mjs +82 -0
  1659. package/src/tui/session/session-flow/queue.mjs +111 -0
  1660. package/src/tui/session/session-flow/session-reset.mjs +130 -0
  1661. package/src/tui/session/session-flow/steering.mjs +190 -0
  1662. package/src/tui/session/session-flow.mjs +43 -846
  1663. package/src/tui/session/tool-approval.mjs +14 -20
  1664. package/src/tui/session/tool-card-results/aggregate-result.mjs +98 -0
  1665. package/src/tui/session/tool-card-results/grouped-result.mjs +94 -0
  1666. package/src/tui/session/tool-card-results/item-patch.mjs +28 -0
  1667. package/src/tui/session/tool-card-results.mjs +45 -234
  1668. package/src/tui/session/tool-result-status.mjs +14 -22
  1669. package/src/tui/session/tool-result-text.mjs +17 -31
  1670. package/src/tui/session/transcript-intake.mjs +151 -0
  1671. package/src/tui/session/transcript-spill/spill-dir.mjs +102 -0
  1672. package/src/tui/session/transcript-spill/spill-writer.mjs +160 -0
  1673. package/src/tui/session/transcript-spill.mjs +44 -267
  1674. package/src/tui/session/transcript-store/replace-items.mjs +66 -0
  1675. package/src/tui/session/transcript-store/streaming-tail.mjs +49 -0
  1676. package/src/tui/session/transcript-store.mjs +114 -0
  1677. package/src/tui/session/tui-steering-persist.mjs +2 -2
  1678. package/src/tui/session/turn-aggregate-cards/early-complete.mjs +62 -0
  1679. package/src/tui/session/turn-aggregate-cards/header-sync.mjs +71 -0
  1680. package/src/tui/session/turn-aggregate-cards.mjs +19 -122
  1681. package/src/tui/session/turn-deferred-cards.mjs +2 -21
  1682. package/src/tui/session/turn-stream.mjs +464 -0
  1683. package/src/tui/session/turn-tool-cards.mjs +338 -0
  1684. package/src/tui/session/turn.mjs +531 -1252
  1685. package/src/tui/session-local.mjs +63 -910
  1686. package/src/tui/spinner-meta.mjs +2 -2
  1687. package/src/tui/statusline-ansi-bridge.mjs +1 -40
  1688. package/src/tui/theme.mjs +3 -3
  1689. package/src/tui/transcript-tool-failures.mjs +4 -7
  1690. package/src/ui/ansi.mjs +6 -28
  1691. package/src/ui/context-inspection.mjs +22 -10
  1692. package/src/ui/context-measurement.mjs +10 -7
  1693. package/src/ui/markdown.mjs +18 -19
  1694. package/src/ui/model-display.mjs +5 -6
  1695. package/src/ui/statusline-agents.mjs +9 -14
  1696. package/src/ui/statusline-format.mjs +5 -3
  1697. package/src/ui/statusline.mjs +214 -223
  1698. package/src/ui/streaming-markdown-heal.mjs +7 -3
  1699. package/src/ui/tool-card.mjs +1 -1
  1700. package/src/workflows/default/WORKFLOW.md +4 -0
  1701. package/src/rules/routes/common.md +0 -4
  1702. package/src/runtime/agent/orchestrator/providers/anthropic-turn-reminder.mjs +0 -96
  1703. package/src/runtime/agent/orchestrator/session/batching-nudge.mjs +0 -461
  1704. package/src/runtime/channels/lib/cli-worker-host.mjs +0 -2
  1705. package/src/runtime/channels/lib/index-drop-trace.mjs +0 -89
  1706. package/src/runtime/channels/lib/network-retry.mjs +0 -24
  1707. package/src/runtime/memory/lib/llm-worker-host.mjs +0 -11
  1708. package/src/standalone/opencode-go-login.mjs +0 -140
@@ -1,4 +1,4 @@
1
- import { Worker } from 'worker_threads';
1
+ import { Worker } from 'node:worker_threads';
2
2
  import { guardedSaveOptions as _guardedSaveOptions } from './write-guards.mjs';
3
3
  import { _ensureLifecycleFields, _messagesForDisk, _sessionForDisk } from './serialize.mjs';
4
4
  import {
@@ -245,6 +245,217 @@ function _workerSaveError(message, code, injected) {
245
245
  return err;
246
246
  }
247
247
 
248
+ /**
249
+ * Settle a reply whose session was hard-deleted after the write was posted.
250
+ * Its outcome is about a file that no longer exists: settle every caller
251
+ * exactly once, then touch NOTHING — no drop/failure marker, no summary
252
+ * publish, no live pin, no delta baseline. The id may already belong to a NEW
253
+ * incarnation, so only slots this very request still owns may be cleared.
254
+ */
255
+ function _settleStaleIncarnationWrite(p, reqId, { ok, error, errorCode, injectedSaveFault }) {
256
+ const { id, incarnation, waiters } = p;
257
+ if (_saveAsyncInflight.get(id) === reqId) _saveAsyncInflight.delete(id);
258
+ const stale = _saveAsyncQueued.get(id);
259
+ if (stale && stale.incarnation === incarnation) {
260
+ _saveAsyncQueued.delete(id);
261
+ _releaseSessionIncarnation(stale.incarnation);
262
+ for (const w of stale.waiters) w.resolve();
263
+ }
264
+ if (ok) for (const w of waiters) w.resolve();
265
+ else for (const w of waiters) w.reject(_workerSaveError(error, errorCode, injectedSaveFault));
266
+ }
267
+
268
+ /**
269
+ * The worker restarted or evicted this id's base mid-chain. Not a drop: retry
270
+ * once as a FULL snapshot of the current live session (latest-wins
271
+ * durability, same waiters). The queued slot stays queued and promotes after
272
+ * the retry settles. Returns false when the retry could not be posted — its
273
+ * failure is recorded here and the caller promotes the queued slot.
274
+ */
275
+ function _retryFullAfterDeltaMiss(p, isCurrentIncarnation) {
276
+ const { id, session, waiters, summaryVersion, epoch, revision, incarnation } = p;
277
+ _invalidateDeltaBaseline(id);
278
+ try {
279
+ _postAsyncWrite(id, session, p.opts, waiters, summaryVersion, epoch, revision, {
280
+ forceFull: true,
281
+ retriedFull: true,
282
+ });
283
+ return true;
284
+ } catch (err) {
285
+ // The RETRY is its own attempt: only its projected payload may
286
+ // stand as evidence. Falling back to the original delta
287
+ // snapshot would publish bytes this failure never attempted.
288
+ _failWorkerWrite(
289
+ id,
290
+ summaryVersion,
291
+ waiters,
292
+ err,
293
+ epoch,
294
+ incarnation,
295
+ err?.attemptSnapshot ?? null,
296
+ isCurrentIncarnation
297
+ );
298
+ return false;
299
+ }
300
+ }
301
+
302
+ /**
303
+ * Resolve/reject every caller whose payload this write represents (the
304
+ * originating call plus any that coalesced onto it before it was posted). A
305
+ * supersede never lands here as a rejection — only a real worker failure does.
306
+ */
307
+ function _settleLandedWrite(p, { ok, saved, outcome, error, errorCode, injectedSaveFault }, isCurrentIncarnation) {
308
+ const { id, attemptSnapshot, summaryVersion, summaryRow, waiters, epoch, incarnation } = p;
309
+ if (!ok) {
310
+ _failWorkerWrite(
311
+ id,
312
+ summaryVersion,
313
+ waiters,
314
+ _workerSaveError(error, errorCode, injectedSaveFault),
315
+ epoch,
316
+ incarnation,
317
+ attemptSnapshot,
318
+ isCurrentIncarnation
319
+ );
320
+ return;
321
+ }
322
+ // A close/delete may have completed while the worker was writing.
323
+ // Do not let this older completion put an open row back in the
324
+ // process-local cache after its tombstone/removal.
325
+ if (saved) {
326
+ // Publish the IMMUTABLE row captured when this payload was
327
+ // built — never a row re-derived from the live session, which
328
+ // may already carry a newer (unwritten, possibly failing) turn.
329
+ _queueSessionSummaryUpsertRow(summaryRow, summaryVersion);
330
+ // ONLY a landed write proves durability, so this is the only
331
+ // place the save-failure flag may be cleared — and only when
332
+ // THIS payload is at least as new as the newest failed/dropped
333
+ // one. An older worker write finishing after a newer sync/async
334
+ // failure carries stale content and must leave the markers (and
335
+ // therefore the live pin) exactly where they are.
336
+ _clearSaveStateIfCurrent(id, epoch);
337
+ } else if (outcome === SAVE_OUTCOME_STALE) {
338
+ // A strictly NEWER write for this id already landed: disk is
339
+ // AHEAD of this payload, not behind it. Nothing was lost, so
340
+ // no drop marker, no save error and no live pin — the snapshot
341
+ // stays immediately evictable. Only the optimistic summary row
342
+ // for these bytes is rolled back.
343
+ _invalidateDeltaBaseline(id);
344
+ _rollbackCachedSessionSummary(id, summaryVersion);
345
+ } else {
346
+ // The worker's _shouldDrop declined the write: disk ownership
347
+ // moved past this snapshot — flag the split-brain so eviction
348
+ // and disk-over-live arbitration keep the richer local copy.
349
+ // Nothing was written, so an earlier save failure for this id
350
+ // STAYS recorded (clearing it here would un-pin the only good
351
+ // in-memory transcript for an id whose disk copy is behind).
352
+ _invalidateDeltaBaseline(id);
353
+ _rollbackCachedSessionSummary(id, summaryVersion);
354
+ _recordSaveDrop(id, epoch);
355
+ }
356
+ for (const w of waiters) w.resolve();
357
+ }
358
+
359
+ /**
360
+ * Promote the latest-wins queued payload (if any) into the now-free in-flight
361
+ * slot for this id. Runs regardless of the settled outcome: the queued write
362
+ * is a newer, independent payload and must still be attempted so its
363
+ * (possibly superseded) waiters resolve when it lands.
364
+ */
365
+ function _promoteQueuedWrite(id) {
366
+ const q = _saveAsyncQueued.get(id);
367
+ if (!q) return;
368
+ _saveAsyncQueued.delete(id);
369
+ // The promotion KEEPS the queued reference through projection, the
370
+ // post and any immediate failure settlement: releasing first would
371
+ // let cap eviction drop the token and make a real current failure
372
+ // look like a stale post-delete outcome (no marker, no live pin).
373
+ const queuedCurrent = _isCurrentSessionIncarnation(id, q.incarnation);
374
+ try {
375
+ _postAsyncWrite(id, q.session, q.opts, q.waiters, q.summaryVersion, q.epoch, q.revision);
376
+ } catch (err) {
377
+ // Evidence is this promotion's OWN projected attempt when it
378
+ // got that far, never the queued (unprojected) live session.
379
+ _failWorkerWrite(
380
+ id,
381
+ q.summaryVersion,
382
+ q.waiters,
383
+ err,
384
+ q.epoch,
385
+ q.incarnation,
386
+ err?.attemptSnapshot ?? null,
387
+ queuedCurrent
388
+ );
389
+ } finally {
390
+ _releaseSessionIncarnation(q.incarnation);
391
+ }
392
+ }
393
+
394
+ /** One settled write reply from the live worker instance. */
395
+ function _onWorkerReply(worker, reply) {
396
+ const { reqId } = reply;
397
+ const p = _saveWorkerPending.get(reqId);
398
+ if (!p) return;
399
+ _saveWorkerPending.delete(reqId);
400
+ // Drop the ref AFTER pending was registered ref-up'd so the worker
401
+ // becomes unref'd again once all in-flight writes settle.
402
+ // Never let the count go negative (a drain may have retired the
403
+ // bookkeeping while this write was still in the worker's queue),
404
+ // otherwise the `=== 0` unref below can never fire again and the
405
+ // process stays alive on a ref'd worker.
406
+ if (_saveWorkerRefCount > 0) _saveWorkerRefCount--;
407
+ if (_saveWorkerRefCount === 0) worker.unref();
408
+ const { id, incarnation } = p;
409
+ const isCurrentIncarnation = _isCurrentSessionIncarnation(id, incarnation);
410
+ // NOTE: the reference is released in the finally below, AFTER every
411
+ // marker decision, so release-time eviction cannot change the verdict.
412
+ try {
413
+ if (!isCurrentIncarnation) {
414
+ _settleStaleIncarnationWrite(p, reqId, reply);
415
+ return;
416
+ }
417
+ _saveAsyncInflight.delete(id);
418
+ if (reply.ok && reply.deltaMiss && !p.retriedFull) {
419
+ if (_retryFullAfterDeltaMiss(p, isCurrentIncarnation)) return;
420
+ } else {
421
+ // (A deltaMiss on a retried FULL is unreachable — the worker only
422
+ // misses on delta payloads.)
423
+ _settleLandedWrite(p, reply, isCurrentIncarnation);
424
+ }
425
+ _promoteQueuedWrite(id);
426
+ } finally {
427
+ _releaseSessionIncarnation(incarnation);
428
+ }
429
+ }
430
+
431
+ /**
432
+ * Retire the shared bookkeeping of a worker that died or was detached: every
433
+ * in-flight and queued write is settled as failed (failure recorded first,
434
+ * live snapshot pinned) and its incarnation reference released; the module
435
+ * pointer is cleared so the next save spawns a replacement that re-syncs the
436
+ * fault state.
437
+ */
438
+ function _retireWorkerBookkeeping(err) {
439
+ _saveWorker = null;
440
+ _faultSyncedKey = null;
441
+ _deltaBaseline.clear();
442
+ for (const [, p] of _saveWorkerPending) {
443
+ _failWorkerWrite(p.id, p.summaryVersion, p.waiters, err, p.epoch, p.incarnation, p.attemptSnapshot);
444
+ _releaseSessionIncarnation(p.incarnation);
445
+ }
446
+ _saveWorkerPending.clear();
447
+ for (const [id, q] of _saveAsyncQueued) {
448
+ // A queued payload was never projected or posted: it is settled and the
449
+ // operational error is recorded, but it may NEVER stand as recovery
450
+ // evidence (that must be an attempted, immutable payload).
451
+ _failWorkerWrite(id, q.summaryVersion, q.waiters, err, q.epoch, q.incarnation, null);
452
+ _releaseSessionIncarnation(q.incarnation);
453
+ }
454
+ _saveAsyncQueued.clear();
455
+ _saveAsyncInflight.clear();
456
+ _saveWorkerRefCount = 0;
457
+ }
458
+
248
459
  function _getOrSpawnWorker() {
249
460
  if (_saveWorker) return _saveWorker;
250
461
  // Every handler below is bound to THIS instance: a worker that already
@@ -268,218 +479,34 @@ function _getOrSpawnWorker() {
268
479
  // to forward through this channel, which keeps stray prints off the TUI
269
480
  // frame (routed through the parent's guardable stderr) without holding
270
481
  // the event loop.
271
- worker.on('message', ({ __log, ok, saved, outcome, deltaMiss, error, errorCode, injectedSaveFault, reqId }) => {
272
- if (__log !== undefined) {
482
+ worker.on('message', (message) => {
483
+ if (message.__log !== undefined) {
273
484
  try {
274
- process.stderr.write(String(__log));
485
+ process.stderr.write(String(message.__log));
275
486
  } catch {
276
487
  /* best-effort */
277
488
  }
278
489
  return;
279
490
  }
280
491
  if (worker !== _saveWorker) return; // stale instance: not our bookkeeping
281
- const p = _saveWorkerPending.get(reqId);
282
- if (!p) return;
283
- _saveWorkerPending.delete(reqId);
284
- // Drop the ref AFTER pending was registered ref-up'd so the worker
285
- // becomes unref'd again once all in-flight writes settle.
286
- // Never let the count go negative (a drain may have retired the
287
- // bookkeeping while this write was still in the worker's queue),
288
- // otherwise the `=== 0` unref below can never fire again and the
289
- // process stays alive on a ref'd worker.
290
- if (_saveWorkerRefCount > 0) _saveWorkerRefCount--;
291
- if (_saveWorkerRefCount === 0) worker.unref();
292
- const { id, session, attemptSnapshot, summaryVersion, summaryRow, waiters, epoch, revision, incarnation } = p;
293
- const isCurrentIncarnation = _isCurrentSessionIncarnation(id, incarnation);
294
- // NOTE: the reference is released in the finally below, AFTER every
295
- // marker decision, so release-time eviction cannot change the verdict.
296
- try {
297
- if (!isCurrentIncarnation) {
298
- // Hard delete landed after this write was posted. Its outcome is
299
- // about a file that no longer exists: settle every caller exactly
300
- // once, then touch NOTHING — no drop/failure marker, no summary
301
- // publish, no live pin, no delta baseline. The id may already
302
- // belong to a NEW incarnation, so only slots this very request
303
- // still owns may be cleared.
304
- if (_saveAsyncInflight.get(id) === reqId) _saveAsyncInflight.delete(id);
305
- const stale = _saveAsyncQueued.get(id);
306
- if (stale && stale.incarnation === incarnation) {
307
- _saveAsyncQueued.delete(id);
308
- _releaseSessionIncarnation(stale.incarnation);
309
- for (const w of stale.waiters) w.resolve();
310
- }
311
- if (ok) for (const w of waiters) w.resolve();
312
- else for (const w of waiters) w.reject(_workerSaveError(error, errorCode, injectedSaveFault));
313
- return;
314
- }
315
- _saveAsyncInflight.delete(id);
316
- if (ok && deltaMiss && !p.retriedFull) {
317
- // The worker restarted or evicted this id's base mid-chain. Not a
318
- // drop: retry once as a FULL snapshot of the current live session
319
- // (latest-wins durability, same waiters). The queued slot stays
320
- // queued and promotes after the retry settles.
321
- _invalidateDeltaBaseline(id);
322
- try {
323
- _postAsyncWrite(id, session, p.opts, waiters, summaryVersion, epoch, revision, {
324
- forceFull: true,
325
- retriedFull: true,
326
- });
327
- return;
328
- } catch (err) {
329
- // The RETRY is its own attempt: only its projected payload may
330
- // stand as evidence. Falling back to the original delta
331
- // snapshot would publish bytes this failure never attempted.
332
- _failWorkerWrite(
333
- id,
334
- summaryVersion,
335
- waiters,
336
- err,
337
- epoch,
338
- incarnation,
339
- err?.attemptSnapshot ?? null,
340
- isCurrentIncarnation
341
- );
342
- }
343
- }
344
- // Resolve/reject every caller whose payload this write represents
345
- // (the originating call plus any that coalesced onto it before it was
346
- // posted). A supersede never lands here as a rejection — only a real
347
- // worker failure does. (A deltaMiss on a retried FULL is unreachable —
348
- // the worker only misses on delta payloads.)
349
- else if (ok) {
350
- // A close/delete may have completed while the worker was writing.
351
- // Do not let this older completion put an open row back in the
352
- // process-local cache after its tombstone/removal.
353
- if (saved) {
354
- // Publish the IMMUTABLE row captured when this payload was
355
- // built — never a row re-derived from the live session, which
356
- // may already carry a newer (unwritten, possibly failing) turn.
357
- _queueSessionSummaryUpsertRow(summaryRow, summaryVersion);
358
- // ONLY a landed write proves durability, so this is the only
359
- // place the save-failure flag may be cleared — and only when
360
- // THIS payload is at least as new as the newest failed/dropped
361
- // one. An older worker write finishing after a newer sync/async
362
- // failure carries stale content and must leave the markers (and
363
- // therefore the live pin) exactly where they are.
364
- _clearSaveStateIfCurrent(id, epoch);
365
- } else if (outcome === SAVE_OUTCOME_STALE) {
366
- // A strictly NEWER write for this id already landed: disk is
367
- // AHEAD of this payload, not behind it. Nothing was lost, so
368
- // no drop marker, no save error and no live pin — the snapshot
369
- // stays immediately evictable. Only the optimistic summary row
370
- // for these bytes is rolled back.
371
- _invalidateDeltaBaseline(id);
372
- _rollbackCachedSessionSummary(id, summaryVersion);
373
- } else {
374
- // The worker's _shouldDrop declined the write: disk ownership
375
- // moved past this snapshot — flag the split-brain so eviction
376
- // and disk-over-live arbitration keep the richer local copy.
377
- // Nothing was written, so an earlier save failure for this id
378
- // STAYS recorded (clearing it here would un-pin the only good
379
- // in-memory transcript for an id whose disk copy is behind).
380
- _invalidateDeltaBaseline(id);
381
- _rollbackCachedSessionSummary(id, summaryVersion);
382
- _recordSaveDrop(id, epoch);
383
- }
384
- for (const w of waiters) w.resolve();
385
- } else {
386
- _failWorkerWrite(
387
- id,
388
- summaryVersion,
389
- waiters,
390
- _workerSaveError(error, errorCode, injectedSaveFault),
391
- epoch,
392
- incarnation,
393
- attemptSnapshot,
394
- isCurrentIncarnation
395
- );
396
- }
397
- // Promote the latest-wins queued payload (if any) into the now-free
398
- // in-flight slot for this id. Runs regardless of ok: the queued write
399
- // is a newer, independent payload and must still be attempted so its
400
- // (possibly superseded) waiters resolve when it lands.
401
- const q = _saveAsyncQueued.get(id);
402
- if (q) {
403
- _saveAsyncQueued.delete(id);
404
- // The promotion KEEPS the queued reference through projection, the
405
- // post and any immediate failure settlement: releasing first would
406
- // let cap eviction drop the token and make a real current failure
407
- // look like a stale post-delete outcome (no marker, no live pin).
408
- const queuedCurrent = _isCurrentSessionIncarnation(id, q.incarnation);
409
- try {
410
- _postAsyncWrite(id, q.session, q.opts, q.waiters, q.summaryVersion, q.epoch, q.revision);
411
- } catch (err) {
412
- // Evidence is this promotion's OWN projected attempt when it
413
- // got that far, never the queued (unprojected) live session.
414
- _failWorkerWrite(
415
- id,
416
- q.summaryVersion,
417
- q.waiters,
418
- err,
419
- q.epoch,
420
- q.incarnation,
421
- err?.attemptSnapshot ?? null,
422
- queuedCurrent
423
- );
424
- } finally {
425
- _releaseSessionIncarnation(q.incarnation);
426
- }
427
- }
428
- } finally {
429
- _releaseSessionIncarnation(incarnation);
430
- }
492
+ _onWorkerReply(worker, message);
431
493
  });
432
494
  worker.on('error', (err) => {
433
495
  if (worker !== _saveWorker) return; // a replacement owns the maps now
434
- _deltaBaseline.clear();
435
- for (const [, p] of _saveWorkerPending) {
436
- _failWorkerWrite(p.id, p.summaryVersion, p.waiters, err, p.epoch, p.incarnation, p.attemptSnapshot);
437
- _releaseSessionIncarnation(p.incarnation);
438
- }
439
- _saveWorkerPending.clear();
440
- for (const [id, q] of _saveAsyncQueued) {
441
- // A queued payload was never projected or posted: it is settled and the
442
- // operational error is recorded, but it may NEVER stand as recovery
443
- // evidence (that must be an attempted, immutable payload).
444
- _failWorkerWrite(id, q.summaryVersion, q.waiters, err, q.epoch, q.incarnation, null);
445
- _releaseSessionIncarnation(q.incarnation);
446
- }
447
- _saveAsyncQueued.clear();
448
- _saveAsyncInflight.clear();
449
- _saveWorkerRefCount = 0;
450
- _faultSyncedKey = null;
451
- _saveWorker = null;
496
+ _retireWorkerBookkeeping(err);
452
497
  });
453
498
  worker.on('exit', (code) => {
454
499
  // 'exit' ALWAYS follows 'error' (which already nulled _saveWorker) and
455
500
  // can arrive after a replacement spawned: only the current instance may
456
501
  // retire the shared bookkeeping.
457
502
  if (worker !== _saveWorker) return;
458
- _deltaBaseline.clear();
459
503
  // Reject pending resolvers on ANY exit (code 0 included) so an idle
460
504
  // worker that races a pending postMessage cannot leak resolvers. The
461
505
  // map is empty on the normal idle-exit path so the loop is a no-op,
462
506
  // but it remains safe for the race window where exit fires after
463
507
  // saveSessionAsync registered a resolver but before the worker
464
508
  // received the message.
465
- const err = new Error(`[session-store] save worker exited with code ${code}`);
466
- for (const [, p] of _saveWorkerPending) {
467
- _failWorkerWrite(p.id, p.summaryVersion, p.waiters, err, p.epoch, p.incarnation, p.attemptSnapshot);
468
- _releaseSessionIncarnation(p.incarnation);
469
- }
470
- _saveWorkerPending.clear();
471
- for (const [id, q] of _saveAsyncQueued) {
472
- // A queued payload was never projected or posted: it is settled and the
473
- // operational error is recorded, but it may NEVER stand as recovery
474
- // evidence (that must be an attempted, immutable payload).
475
- _failWorkerWrite(id, q.summaryVersion, q.waiters, err, q.epoch, q.incarnation, null);
476
- _releaseSessionIncarnation(q.incarnation);
477
- }
478
- _saveAsyncQueued.clear();
479
- _saveAsyncInflight.clear();
480
- _saveWorkerRefCount = 0;
481
- _faultSyncedKey = null;
482
- _saveWorker = null;
509
+ _retireWorkerBookkeeping(new Error(`[session-store] save worker exited with code ${code}`));
483
510
  });
484
511
  worker.unref(); // don't keep process alive
485
512
  return worker;
@@ -852,20 +879,8 @@ export function _detachSaveWorkerForTest() {
852
879
  if (!_sessionStoreTestMode()) return null;
853
880
  const worker = _saveWorker;
854
881
  if (!worker) return null;
855
- _saveWorker = null;
856
- _faultSyncedKey = null;
857
- const detached = new Error('[session-store] save worker detached before this write settled');
858
- for (const [, p] of _saveWorkerPending) {
859
- _failWorkerWrite(p.id, p.summaryVersion, p.waiters, detached, p.epoch, p.incarnation, p.attemptSnapshot);
860
- _releaseSessionIncarnation(p.incarnation);
861
- }
862
- _saveWorkerPending.clear();
863
- for (const [id, q] of _saveAsyncQueued) {
864
- _failWorkerWrite(id, q.summaryVersion, q.waiters, detached, q.epoch, q.incarnation, null);
865
- _releaseSessionIncarnation(q.incarnation);
866
- }
867
- _saveAsyncQueued.clear();
868
- _saveAsyncInflight.clear();
882
+ // The detached instance stays alive, so the ref its in-flight writes held
883
+ // is dropped here (a dead worker's own handlers have nothing to unref).
869
884
  if (_saveWorkerRefCount > 0) {
870
885
  try {
871
886
  worker.unref();
@@ -873,8 +888,7 @@ export function _detachSaveWorkerForTest() {
873
888
  /* worker already gone */
874
889
  }
875
890
  }
876
- _saveWorkerRefCount = 0;
877
- _deltaBaseline.clear();
891
+ _retireWorkerBookkeeping(new Error('[session-store] save worker detached before this write settled'));
878
892
  return worker;
879
893
  }
880
894
 
@@ -1,5 +1,5 @@
1
- import { readFileSync } from 'fs';
2
- import { join } from 'path';
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
3
  import { renameWithRetrySync } from '../../../../shared/atomic-file.mjs';
4
4
  import { sanitizeContentForStoredHistory } from '../../providers/media-normalization.mjs';
5
5
  import { readTopLevelLifecycleRecord, isLifecycleUnreadable } from '../lifecycle-scan.mjs';
@@ -45,32 +45,24 @@ export function _sessionForDisk(session) {
45
45
  const messages = Array.isArray(session?.messages) ? session.messages : null;
46
46
  if (!messages || messages.length === 0) {
47
47
  if (!hasTransient) return session;
48
- const {
49
- liveTurnMessages: _dropLTM,
50
- toolApprovalHook: _dropTAH,
51
- _providerPrefixGuardState: _dropPPGS,
52
- ...rest
53
- } = session;
54
- return _withMidTurnContextAnchor(rest, session);
48
+ return _withMidTurnContextAnchor(_withoutTransientFields(session), session);
55
49
  }
56
50
  const out = _messagesForDisk(messages);
57
51
  if (out === messages) {
58
52
  if (!hasTransient) return session;
59
- const {
60
- liveTurnMessages: _dropLTM,
61
- toolApprovalHook: _dropTAH,
62
- _providerPrefixGuardState: _dropPPGS,
63
- ...rest
64
- } = session;
65
- return _withMidTurnContextAnchor(rest, session);
53
+ return _withMidTurnContextAnchor(_withoutTransientFields(session), session);
66
54
  }
55
+ return _withMidTurnContextAnchor({ ..._withoutTransientFields(session), messages: out }, session);
56
+ }
57
+
58
+ function _withoutTransientFields(session) {
67
59
  const {
68
60
  liveTurnMessages: _dropLTM,
69
61
  toolApprovalHook: _dropTAH,
70
62
  _providerPrefixGuardState: _dropPPGS,
71
63
  ...rest
72
64
  } = session;
73
- return _withMidTurnContextAnchor({ ...rest, messages: out }, session);
65
+ return rest;
74
66
  }
75
67
 
76
68
  /**
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Hard delete of a session and the strict enumeration that feeds it. The
3
+ * unlink is irreversible, so this owns its own ownership proof at the commit
4
+ * edge plus the full local-state purge that must happen under the same lock
5
+ * (incarnation retirement, pending slots, purge hooks, markers, summary row).
6
+ */
7
+ import { readFileSync, readdirSync, unlinkSync } from 'node:fs';
8
+ import { join } from 'node:path';
9
+ import { isAgentOwner } from '../../agent-owner.mjs';
10
+ import { readTopLevelLifecycleRecord, isLifecycleUnreadable } from '../lifecycle-scan.mjs';
11
+ import { getStoreDir, sessionPath, deleteSessionPresence } from './paths-heartbeat.mjs';
12
+ import {
13
+ readCanonicalSessionRecord as _readCanonicalRecord,
14
+ CANONICAL_RECORD_UNREADABLE as LIFECYCLE_AMBIGUOUS,
15
+ } from './canonical-reader.mjs';
16
+ import { probePath, PROBE_PRESENT, PROBE_ABSENT } from './fs-probe.mjs';
17
+ import {
18
+ guardedSaveOptions as _guardedSaveOptions,
19
+ cancelSessionWrites as _cancelSessionWrites,
20
+ acquireWriteCommit as _acquireWriteCommit,
21
+ releaseWriteCommit as _releaseWriteCommit,
22
+ } from './write-guards.mjs';
23
+ import {
24
+ _clearLiveSession,
25
+ _retireSessionIncarnation,
26
+ _clearSessionSaveState,
27
+ clearSessionLifecycleCommitError,
28
+ } from './live-state.mjs';
29
+ import { purgeSessionSaveBookkeeping as _purgeSessionSaveBookkeeping } from './save-worker.mjs';
30
+ import { _uncacheSessionSummary, _queueSessionSummaryRemoval } from './summary-cache.mjs';
31
+ import { _savePending, _clearDebounce, _releasePendingSlot } from './pending-saves.mjs';
32
+ import { _runtimeLivenessVeto, _heartbeatLivenessVeto, _deleteHeartbeatUnlessNewer } from './liveness-veto.mjs';
33
+ import { _runSessionPurgeHooks } from './session-observers.mjs';
34
+
35
+ /** Strictly enumerate child-agent session files linked to one visible parent.
36
+ * Used only by explicit parent deletion; ordinary close/context switches keep
37
+ * the relationship intact. */
38
+ export function listOwnedAgentSessionIds(ownerSessionId) {
39
+ const ownerId = String(ownerSessionId || '').trim();
40
+ if (!/^[A-Za-z0-9_-]+$/.test(ownerId)) return [];
41
+ const dir = getStoreDir();
42
+ if (probePath(dir).state !== PROBE_PRESENT) return [];
43
+ let files;
44
+ try {
45
+ files = readdirSync(dir).filter((file) => file.endsWith('.json'));
46
+ } catch {
47
+ return [];
48
+ }
49
+ const ids = [];
50
+ for (const file of files) {
51
+ const candidateId = file.slice(0, -5);
52
+ if (!candidateId || candidateId === ownerId || !/^[A-Za-z0-9_-]+$/.test(candidateId)) continue;
53
+ try {
54
+ const record = readTopLevelLifecycleRecord(readFileSync(join(dir, file), 'utf8'));
55
+ if (isLifecycleUnreadable(record) || record.id !== candidateId) continue;
56
+ const session = record.doc;
57
+ if (!isAgentOwner(session)) continue;
58
+ const linkedOwner = String(session.ownerSessionId || session.parentSessionId || '').trim();
59
+ if (linkedOwner === ownerId) ids.push(candidateId);
60
+ } catch {
61
+ /* unreadable/vanished records are never deletion targets */
62
+ }
63
+ }
64
+ return ids;
65
+ }
66
+
67
+ export function deleteSession(id, options = {}) {
68
+ // Keep caller probes and all vetoes ahead of the non-reentrant lock and
69
+ // ahead of pending-save disruption, matching markSessionClosed().
70
+ if (_runtimeLivenessVeto(id, options) || _heartbeatLivenessVeto(id, options)) return false;
71
+ const deleteGuard = _guardedSaveOptions(id);
72
+ const commitControl = _acquireWriteCommit(deleteGuard);
73
+ if (commitControl === false) return false;
74
+ try {
75
+ // Cross-process revival after full-TTL silence remains best-effort; the
76
+ // tombstone resurrection guard is authoritative. Only re-stat .hb here.
77
+ if (_heartbeatLivenessVeto(id, options)) return false;
78
+ // ── 1. unlink FIRST, still holding the commit lock ─────────────────────
79
+ // A failed unlink is NOT a delete: the canonical bytes are still there, so
80
+ // nothing may be purged, cancelled or closed — every pending write, parked
81
+ // snapshot and metrics timer stays usable and persistable.
82
+ const path = sessionPath(id);
83
+ const probe = probePath(path);
84
+ // An unreadable probe is NOT absence: purging markers/pending state while
85
+ // the canonical bytes survive would strand a live session behind a file
86
+ // nobody owns any more. Nothing was deleted, so report exactly that.
87
+ if (probe.state !== PROBE_PRESENT && probe.state !== PROBE_ABSENT) return false;
88
+ // CONTRACT: an ABSENT canonical record is a SUCCESSFUL (idempotent)
89
+ // delete — the session does not exist once this call returns, so the id's
90
+ // local state is purged and `true` is reported. `false` is reserved for
91
+ // "nothing was deleted AND nothing was mutated": a liveness veto, a
92
+ // contended commit lock, an unreadable probe, ambiguous/foreign bytes, or
93
+ // a failed unlink.
94
+ if (probe.state === PROBE_PRESENT) {
95
+ // STRICT OWNERSHIP AT THE COMMIT EDGE. The bytes are re-read here,
96
+ // under the same commit lock, immediately before the unlink — not
97
+ // inferred from the earlier stat, and not from any cache: between the
98
+ // probe and this read another process can rename a different session's
99
+ // record (or a torn write) onto this path, and an unlink is
100
+ // irreversible. Ambiguous/foreign bytes are therefore never deleted.
101
+ const record = _readCanonicalRecord(path);
102
+ if (record === LIFECYCLE_AMBIGUOUS) return false;
103
+ if (record !== null) {
104
+ if (record.id !== id) return false;
105
+ try {
106
+ unlinkSync(path);
107
+ } catch {
108
+ return false; // canonical file survives → nothing was deleted
109
+ }
110
+ }
111
+ // record === null: the file vanished inside this window — fall through
112
+ // to the absent contract (nothing removed, local state still purged).
113
+ }
114
+ // ── 2. finalize UNDER THE SAME LOCK ────────────────────────────────────
115
+ // The file is gone. Cancellation + purge happen before the lock is
116
+ // released, so a writer waiting for the lock is refused by its own
117
+ // cancellation re-check instead of renaming the file back, and no parked
118
+ // snapshot, timer or deferred entry survives to resurrect it.
119
+ // Retire the id's incarnation: every write, queued payload and parked
120
+ // snapshot stamped BEFORE this point becomes permanently non-current, so
121
+ // its settlement moves no marker and touches no bookkeeping — and a
122
+ // re-created id gets a brand new incarnation of its own.
123
+ _retireSessionIncarnation(id);
124
+ _cancelSessionWrites(id);
125
+ _clearDebounce(id);
126
+ _releasePendingSlot(_savePending.get(id));
127
+ _savePending.delete(id);
128
+ _purgeSessionSaveBookkeeping(id);
129
+ _runSessionPurgeHooks(id);
130
+ // Preserve a sidecar published strictly after the sweep's scan snapshot.
131
+ _deleteHeartbeatUnlessNewer(id, options);
132
+ deleteSessionPresence(id);
133
+ _clearLiveSession(id);
134
+ // The file is gone: every marker of the retired incarnation goes with it
135
+ // (save error + failed-snapshot evidence, split-brain drop flag, lifecycle
136
+ // commit error), so a re-created id starts clean.
137
+ _clearSessionSaveState(id);
138
+ clearSessionLifecycleCommitError(id);
139
+ // deferSummaryUpdate: bulk callers (tombstone sweep) remove thousands of
140
+ // rows — a per-id _removeSessionSummary would parse+rewrite the multi-MB
141
+ // summary index once PER DELETION. They batch the index update themselves.
142
+ if (options.deferSummaryUpdate === true) _uncacheSessionSummary(id);
143
+ else _queueSessionSummaryRemoval(id);
144
+ // Both PRESENT-and-unlinked and ABSENT reach here: the session is gone.
145
+ return true;
146
+ } finally {
147
+ _releaseWriteCommit(commitControl);
148
+ }
149
+ }