mixdog 0.9.62 → 0.9.64

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 (403) hide show
  1. package/README.md +3 -0
  2. package/package.json +9 -2
  3. package/scripts/code-graph-description-contract.mjs +3 -3
  4. package/scripts/verify-release-assets.mjs +2 -2
  5. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch.mjs +11 -14
  6. package/src/runtime/agent/orchestrator/agent-runtime/agent-progress-watchdog.mjs +6 -6
  7. package/src/runtime/agent/orchestrator/agent-runtime/cache-strategy.mjs +2 -2
  8. package/src/runtime/agent/orchestrator/agent-trace-format.mjs +1 -0
  9. package/src/runtime/agent/orchestrator/config.mjs +19 -124
  10. package/src/runtime/agent/orchestrator/context/collect.mjs +6 -6
  11. package/src/runtime/agent/orchestrator/dispatch-persist.mjs +2 -2
  12. package/src/runtime/agent/orchestrator/internal-agents.mjs +2 -2
  13. package/src/runtime/agent/orchestrator/mcp/child-tree.mjs +1 -1
  14. package/src/runtime/agent/orchestrator/mcp/client.mjs +4 -4
  15. package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +2 -2
  16. package/src/runtime/agent/orchestrator/providers/anthropic-betas.mjs +4 -4
  17. package/src/runtime/agent/orchestrator/providers/anthropic-effort.mjs +2 -2
  18. package/src/runtime/agent/orchestrator/providers/anthropic-max-tokens.mjs +4 -4
  19. package/src/runtime/agent/orchestrator/providers/anthropic-messages.mjs +333 -0
  20. package/src/runtime/agent/orchestrator/providers/anthropic-model-resolve.mjs +2 -2
  21. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-credentials.mjs +4 -4
  22. package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +1 -1
  23. package/src/runtime/agent/orchestrator/providers/anthropic.mjs +3 -277
  24. package/src/runtime/agent/orchestrator/providers/codex-client-meta.mjs +2 -2
  25. package/src/runtime/agent/orchestrator/providers/custom-tool-wire.mjs +1 -1
  26. package/src/runtime/agent/orchestrator/providers/gemini-cache.mjs +2 -2
  27. package/src/runtime/agent/orchestrator/providers/gemini-stream.mjs +6 -6
  28. package/src/runtime/agent/orchestrator/providers/grok-oauth-login.mjs +196 -0
  29. package/src/runtime/agent/orchestrator/providers/grok-oauth-tokens.mjs +460 -0
  30. package/src/runtime/agent/orchestrator/providers/grok-oauth.mjs +14 -593
  31. package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +1 -1
  32. package/src/runtime/agent/orchestrator/providers/media-normalization.mjs +1 -1
  33. package/src/runtime/agent/orchestrator/providers/openai-compat-wire.mjs +1 -1
  34. package/src/runtime/agent/orchestrator/providers/openai-compat-xai.mjs +4 -4
  35. package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +2 -2
  36. package/src/runtime/agent/orchestrator/providers/openai-oauth.mjs +5 -280
  37. package/src/runtime/agent/orchestrator/providers/openai-responses-payload.mjs +357 -0
  38. package/src/runtime/agent/orchestrator/providers/openai-ws-headers.mjs +216 -0
  39. package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +2 -188
  40. package/src/runtime/agent/orchestrator/providers/openai-ws-stream.mjs +2 -2
  41. package/src/runtime/agent/orchestrator/providers/openai-ws.mjs +2 -2
  42. package/src/runtime/agent/orchestrator/providers/opencode-go.mjs +1 -1
  43. package/src/runtime/agent/orchestrator/providers/provider-catalog-cache.mjs +1 -1
  44. package/src/runtime/agent/orchestrator/providers/registry.mjs +1 -1
  45. package/src/runtime/agent/orchestrator/providers/retry-classifier.mjs +2 -2
  46. package/src/runtime/agent/orchestrator/providers/statusline-route-meta.mjs +1 -1
  47. package/src/runtime/agent/orchestrator/session/cache/prefetch-cache.mjs +1 -1
  48. package/src/runtime/agent/orchestrator/session/cache/scoped-cache.mjs +3 -3
  49. package/src/runtime/agent/orchestrator/session/compact/budget.mjs +2 -2
  50. package/src/runtime/agent/orchestrator/session/compact/file-reattach.mjs +2 -2
  51. package/src/runtime/agent/orchestrator/session/compact/summary-schema.mjs +1 -1
  52. package/src/runtime/agent/orchestrator/session/compact/summary.mjs +1 -1
  53. package/src/runtime/agent/orchestrator/session/compact/text-utils.mjs +2 -2
  54. package/src/runtime/agent/orchestrator/session/context-utils.mjs +4 -4
  55. package/src/runtime/agent/orchestrator/session/loop/deferred-call-through.mjs +1 -1
  56. package/src/runtime/agent/orchestrator/session/loop/pre-dispatch-deny.mjs +17 -0
  57. package/src/runtime/agent/orchestrator/session/loop/steering.mjs +1 -1
  58. package/src/runtime/agent/orchestrator/session/loop/stored-tool-args.mjs +18 -26
  59. package/src/runtime/agent/orchestrator/session/loop/termination.mjs +1 -1
  60. package/src/runtime/agent/orchestrator/session/loop/tool-classify.mjs +3 -3
  61. package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +1 -0
  62. package/src/runtime/agent/orchestrator/session/manager/context-meta.mjs +1 -1
  63. package/src/runtime/agent/orchestrator/session/manager/delivered-completions.mjs +1 -1
  64. package/src/runtime/agent/orchestrator/session/manager/status-telemetry.mjs +1 -1
  65. package/src/runtime/agent/orchestrator/session/store/live-state.mjs +49 -0
  66. package/src/runtime/agent/orchestrator/session/store/load-cache.mjs +49 -0
  67. package/src/runtime/agent/orchestrator/session/store/save-worker.mjs +260 -0
  68. package/src/runtime/agent/orchestrator/session/store/serialize.mjs +72 -0
  69. package/src/runtime/agent/orchestrator/session/store/summary-cache.mjs +163 -0
  70. package/src/runtime/agent/orchestrator/session/store/write-guards.mjs +1 -1
  71. package/src/runtime/agent/orchestrator/session/store-summary-index.mjs +1 -1
  72. package/src/runtime/agent/orchestrator/session/store-summary-reader.mjs +4 -1
  73. package/src/runtime/agent/orchestrator/session/store.mjs +9 -561
  74. package/src/runtime/agent/orchestrator/session/tool-envelope.mjs +1 -1
  75. package/src/runtime/agent/orchestrator/session/tool-result-offload.mjs +2 -2
  76. package/src/runtime/agent/orchestrator/stall-policy.mjs +11 -11
  77. package/src/runtime/agent/orchestrator/tools/bash-policy-scan.mjs +1 -1
  78. package/src/runtime/agent/orchestrator/tools/bash-session.mjs +2 -2
  79. package/src/runtime/agent/orchestrator/tools/builtin/advisory-lock.mjs +1 -1
  80. package/src/runtime/agent/orchestrator/tools/builtin/arg-guard.mjs +2 -2
  81. package/src/runtime/agent/orchestrator/tools/builtin/atomic-write.mjs +1 -1
  82. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +2 -154
  83. package/src/runtime/agent/orchestrator/tools/builtin/cache-layers.mjs +1 -1
  84. package/src/runtime/agent/orchestrator/tools/builtin/cwd-utils.mjs +1 -1
  85. package/src/runtime/agent/orchestrator/tools/builtin/fs-reachability.mjs +1 -1
  86. package/src/runtime/agent/orchestrator/tools/builtin/fuzzy-match.mjs +1 -1
  87. package/src/runtime/agent/orchestrator/tools/builtin/glob-walk.mjs +1 -1
  88. package/src/runtime/agent/orchestrator/tools/builtin/path-locks.mjs +1 -1
  89. package/src/runtime/agent/orchestrator/tools/builtin/path-utils.mjs +1 -1
  90. package/src/runtime/agent/orchestrator/tools/builtin/read-args.mjs +2 -2
  91. package/src/runtime/agent/orchestrator/tools/builtin/read-formatting.mjs +2 -3
  92. package/src/runtime/agent/orchestrator/tools/builtin/read-image-resize.mjs +4 -4
  93. package/src/runtime/agent/orchestrator/tools/builtin/read-open.mjs +1 -1
  94. package/src/runtime/agent/orchestrator/tools/builtin/read-streaming.mjs +1 -1
  95. package/src/runtime/agent/orchestrator/tools/builtin/rg-runner.mjs +2 -2
  96. package/src/runtime/agent/orchestrator/tools/builtin/search-path-diagnostics.mjs +5 -5
  97. package/src/runtime/agent/orchestrator/tools/builtin/shell-analysis.mjs +1 -1
  98. package/src/runtime/agent/orchestrator/tools/builtin/shell-job-paths.mjs +2 -2
  99. package/src/runtime/agent/orchestrator/tools/builtin/shell-job-process.mjs +2 -2
  100. package/src/runtime/agent/orchestrator/tools/builtin/shell-job-spawn.mjs +519 -0
  101. package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +5 -449
  102. package/src/runtime/agent/orchestrator/tools/builtin/snapshot-helpers.mjs +1 -1
  103. package/src/runtime/agent/orchestrator/tools/builtin/task-tool.mjs +212 -0
  104. package/src/runtime/agent/orchestrator/tools/builtin.mjs +1 -1
  105. package/src/runtime/agent/orchestrator/tools/code-graph/build.mjs +1 -7
  106. package/src/runtime/agent/orchestrator/tools/code-graph/disk-cache.mjs +9 -36
  107. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +15 -3
  108. package/src/runtime/agent/orchestrator/tools/code-graph/search-references.mjs +429 -0
  109. package/src/runtime/agent/orchestrator/tools/code-graph/search.mjs +2 -395
  110. package/src/runtime/agent/orchestrator/tools/code-graph/symbol-index.mjs +2 -2
  111. package/src/runtime/agent/orchestrator/tools/code-graph/text-mask.mjs +1 -1
  112. package/src/runtime/agent/orchestrator/tools/code-graph/trusted-roots.mjs +1 -1
  113. package/src/runtime/agent/orchestrator/tools/code-graph-prewarm-worker.mjs +1 -1
  114. package/src/runtime/agent/orchestrator/tools/code-graph-state.mjs +3 -3
  115. package/src/runtime/agent/orchestrator/tools/mutation-planner.mjs +5 -5
  116. package/src/runtime/agent/orchestrator/tools/next-call-utils.mjs +1 -1
  117. package/src/runtime/agent/orchestrator/tools/patch/dispatch.mjs +1 -1
  118. package/src/runtime/agent/orchestrator/tools/patch/matcher.mjs +7 -7
  119. package/src/runtime/agent/orchestrator/tools/patch/orchestrator.mjs +72 -9
  120. package/src/runtime/agent/orchestrator/tools/patch/parsing.mjs +4 -4
  121. package/src/runtime/agent/orchestrator/tools/patch/paths.mjs +1 -1
  122. package/src/runtime/agent/orchestrator/tools/patch/v4a-convert.mjs +1 -1
  123. package/src/runtime/agent/orchestrator/tools/patch-tool-defs.mjs +4 -4
  124. package/src/runtime/agent/orchestrator/tools/patch.mjs +1 -1
  125. package/src/runtime/agent/orchestrator/tools/result-compression.mjs +3 -3
  126. package/src/runtime/agent/orchestrator/tools/shell-command.mjs +2 -444
  127. package/src/runtime/agent/orchestrator/tools/shell-exec-output.mjs +505 -0
  128. package/src/runtime/agent/orchestrator/tools/shell-exec-policy.mjs +2 -2
  129. package/src/runtime/agent/orchestrator/tools/shell-snapshot.mjs +1 -1
  130. package/src/runtime/channels/lib/backend-dispatch.mjs +20 -5
  131. package/src/runtime/channels/lib/scheduler.mjs +1 -1
  132. package/src/runtime/channels/lib/telegram-format.mjs +1 -1
  133. package/src/runtime/channels/lib/voice-runtime-fetcher.mjs +4 -4
  134. package/src/runtime/channels/tool-defs.mjs +2 -3
  135. package/src/runtime/memory/index.mjs +1 -5
  136. package/src/runtime/memory/lib/core-memory-candidates.mjs +357 -0
  137. package/src/runtime/memory/lib/core-memory-store.mjs +7 -357
  138. package/src/runtime/memory/lib/cycle-signatures.mjs +1 -1
  139. package/src/runtime/memory/lib/embedding-model-config.mjs +1 -1
  140. package/src/runtime/memory/lib/embedding-provider.mjs +1 -5
  141. package/src/runtime/memory/lib/embedding-worker.mjs +1 -5
  142. package/src/runtime/memory/lib/ko-morph.mjs +2 -2
  143. package/src/runtime/memory/lib/memory-config-flags.mjs +2 -5
  144. package/src/runtime/memory/lib/memory-cycle-requests.mjs +3 -7
  145. package/src/runtime/memory/lib/memory-cycle1.mjs +4 -8
  146. package/src/runtime/memory/lib/memory-cycle2-gate.mjs +1 -1
  147. package/src/runtime/memory/lib/memory-cycle2-mutations.mjs +1 -1
  148. package/src/runtime/memory/lib/memory-cycle2-shared.mjs +2 -5
  149. package/src/runtime/memory/lib/memory-cycle3.mjs +1 -5
  150. package/src/runtime/memory/lib/memory-embed.mjs +2 -6
  151. package/src/runtime/memory/lib/memory-log.mjs +8 -0
  152. package/src/runtime/memory/lib/memory-ops-policy.mjs +4 -8
  153. package/src/runtime/memory/lib/memory-recall-scope-filter.mjs +1 -1
  154. package/src/runtime/memory/lib/memory-recall-store.mjs +2 -193
  155. package/src/runtime/memory/lib/memory-score.mjs +1 -1
  156. package/src/runtime/memory/lib/memory-text-utils.mjs +2 -2
  157. package/src/runtime/memory/lib/memory.mjs +2 -6
  158. package/src/runtime/memory/lib/pg/adapter.mjs +2 -6
  159. package/src/runtime/memory/lib/pg/process.mjs +1 -5
  160. package/src/runtime/memory/lib/pg/supervisor.mjs +1 -5
  161. package/src/runtime/memory/lib/recall-format.mjs +2 -2
  162. package/src/runtime/memory/lib/recall-scoring.mjs +195 -0
  163. package/src/runtime/memory/lib/runtime-fetcher.mjs +1 -5
  164. package/src/runtime/memory/lib/trace-store.mjs +2 -6
  165. package/src/runtime/search/lib/http-fetch.mjs +6 -6
  166. package/src/runtime/search/lib/web-tools.mjs +2 -2
  167. package/src/runtime/shared/buffered-appender.mjs +1 -1
  168. package/src/runtime/shared/child-guardian.mjs +1 -1
  169. package/src/runtime/shared/child-spawn-gate.mjs +1 -1
  170. package/src/runtime/shared/config.mjs +4 -4
  171. package/src/runtime/shared/launcher-control.mjs +9 -10
  172. package/src/runtime/shared/llm/index.mjs +5 -20
  173. package/src/runtime/shared/markdown-frontmatter.mjs +1 -1
  174. package/src/runtime/shared/memory-snapshot.mjs +4 -4
  175. package/src/runtime/shared/pristine-execution.mjs +1 -1
  176. package/src/runtime/shared/process-lifecycle.mjs +0 -1
  177. package/src/runtime/shared/process-shutdown.mjs +1 -1
  178. package/src/runtime/shared/resource-admission.mjs +2 -2
  179. package/src/runtime/shared/schedule-session-run.mjs +1 -1
  180. package/src/runtime/shared/schedules-db.mjs +1 -1
  181. package/src/runtime/shared/service-discovery.mjs +2 -2
  182. package/src/runtime/shared/staged-update.mjs +6 -6
  183. package/src/runtime/shared/tool-execution-contract.mjs +1 -1
  184. package/src/runtime/shared/tool-primitives.mjs +1 -1
  185. package/src/runtime/shared/tool-surface.mjs +2 -2
  186. package/src/runtime/shared/update-checker.mjs +1 -1
  187. package/src/runtime/shared/user-cwd.mjs +3 -3
  188. package/src/runtime/shared/user-data-guard.mjs +4 -4
  189. package/src/runtime/shared/workspace-router.mjs +5 -5
  190. package/src/session-runtime/config-helpers.mjs +2 -3
  191. package/src/session-runtime/config-lifecycle.mjs +1 -1
  192. package/src/session-runtime/hitch-profile.mjs +1 -1
  193. package/src/session-runtime/lifecycle-api.mjs +6 -4
  194. package/src/session-runtime/model-recency.mjs +5 -5
  195. package/src/session-runtime/plugin-mcp.mjs +1 -1
  196. package/src/session-runtime/provider-request-snapshot.mjs +338 -0
  197. package/src/session-runtime/session-text.mjs +4 -4
  198. package/src/session-runtime/tool-catalog-schema.mjs +197 -0
  199. package/src/session-runtime/tool-catalog.mjs +6 -483
  200. package/src/session-runtime/tool-defs.mjs +1 -1
  201. package/src/standalone/agent-task-status.mjs +1 -1
  202. package/src/standalone/agent-tool/helpers.mjs +2 -2
  203. package/src/standalone/channel-admin.mjs +4 -4
  204. package/src/standalone/explore-tool.mjs +3 -3
  205. package/src/standalone/hook-bus/config.mjs +1 -1
  206. package/src/standalone/hook-bus/constants.mjs +1 -1
  207. package/src/standalone/hook-bus/rules.mjs +1 -1
  208. package/src/standalone/projects.mjs +1 -1
  209. package/src/standalone/provider-admin.mjs +2 -2
  210. package/src/tui/app/app-format.mjs +2 -2
  211. package/src/tui/app/clipboard.mjs +3 -3
  212. package/src/tui/app/input-parsers.mjs +1 -1
  213. package/src/tui/app/text-layout.mjs +1 -1
  214. package/src/tui/app/transcript-row-estimate.mjs +360 -0
  215. package/src/tui/app/transcript-window.mjs +5 -347
  216. package/src/tui/app/use-mouse-input.mjs +1 -1
  217. package/src/tui/app/use-prompt-handlers.mjs +1 -1
  218. package/src/tui/components/tool-execution/surface-detail.mjs +9 -9
  219. package/src/tui/components/tool-execution/text-format.mjs +2 -2
  220. package/src/tui/components/tool-output-format.mjs +7 -7
  221. package/src/tui/display-width.mjs +4 -4
  222. package/src/tui/dist/index.mjs +63 -97
  223. package/src/tui/engine/agent-envelope.mjs +5 -5
  224. package/src/tui/engine/notification-plan.mjs +1 -1
  225. package/src/tui/engine/queue-helpers.mjs +3 -3
  226. package/src/tui/engine/render-timing.mjs +4 -5
  227. package/src/tui/engine/session-api-ext.mjs +3 -3
  228. package/src/tui/engine/tool-result-status.mjs +5 -5
  229. package/src/tui/engine/tool-result-text.mjs +1 -1
  230. package/src/tui/engine/transcript-spill.mjs +585 -0
  231. package/src/tui/engine/tui-steering-persist.mjs +1 -1
  232. package/src/tui/engine.mjs +2 -474
  233. package/src/tui/lib/voice-setup.mjs +1 -1
  234. package/src/tui/markdown/format-token.mjs +1 -1
  235. package/src/tui/markdown/render-ansi.mjs +1 -1
  236. package/src/tui/markdown/table-layout.mjs +4 -4
  237. package/src/tui/paste-attachments.mjs +1 -1
  238. package/src/tui/prompt-history-store.mjs +3 -3
  239. package/src/tui/statusline-ansi-bridge.mjs +2 -2
  240. package/src/tui/theme.mjs +1 -1
  241. package/src/tui/transcript-tool-failures.mjs +2 -2
  242. package/src/ui/ansi.mjs +0 -9
  243. package/src/ui/statusline-format.mjs +2 -4
  244. package/scripts/_bench-cwc.json +0 -20
  245. package/scripts/_jitter-fuzz.jsx +0 -42
  246. package/scripts/_jitter-fuzz2.jsx +0 -30
  247. package/scripts/_jitter-probe.jsx +0 -35
  248. package/scripts/_jp2.jsx +0 -16
  249. package/scripts/_smoke_wd.mjs +0 -7
  250. package/scripts/abort-recovery-test.mjs +0 -175
  251. package/scripts/agent-dispatch-abort-compose-test.mjs +0 -31
  252. package/scripts/agent-live-arg-guard-smoke.mjs +0 -20
  253. package/scripts/agent-live-path-suffix-smoke.mjs +0 -34
  254. package/scripts/agent-live-toolcall-args-smoke.mjs +0 -45
  255. package/scripts/agent-loop-policy-test.mjs +0 -37
  256. package/scripts/agent-model-liveness-test.mjs +0 -763
  257. package/scripts/agent-parallel-smoke.mjs +0 -435
  258. package/scripts/agent-route-batch-test.mjs +0 -40
  259. package/scripts/agent-tag-reuse-smoke.mjs +0 -441
  260. package/scripts/agent-terminal-reap-test.mjs +0 -252
  261. package/scripts/agent-trace-io-test.mjs +0 -133
  262. package/scripts/ansi-color-capability-test.mjs +0 -90
  263. package/scripts/anthropic-admission-retry-integration-test.mjs +0 -119
  264. package/scripts/anthropic-maxtokens-test.mjs +0 -119
  265. package/scripts/anthropic-oauth-refresh-race-test.mjs +0 -397
  266. package/scripts/anthropic-transport-policy-test.mjs +0 -726
  267. package/scripts/apply-patch-edit-smoke.mjs +0 -71
  268. package/scripts/arg-guard-test.mjs +0 -93
  269. package/scripts/async-notify-settlement-test.mjs +0 -99
  270. package/scripts/atomic-lock-tryonce-test.mjs +0 -125
  271. package/scripts/background-task-meta-smoke.mjs +0 -38
  272. package/scripts/bench-run.mjs +0 -508
  273. package/scripts/boot-smoke.mjs +0 -137
  274. package/scripts/build-runtime-windows.ps1 +0 -242
  275. package/scripts/channel-daemon-smoke.mjs +0 -1103
  276. package/scripts/code-graph-aggregate-cwd-test.mjs +0 -158
  277. package/scripts/code-graph-disk-hit-test.mjs +0 -290
  278. package/scripts/code-graph-dispatch-test.mjs +0 -96
  279. package/scripts/code-graph-root-federation-test.mjs +0 -273
  280. package/scripts/compact-active-turn-test.mjs +0 -68
  281. package/scripts/compact-file-reattach-test.mjs +0 -88
  282. package/scripts/compact-pressure-test.mjs +0 -788
  283. package/scripts/compact-prior-context-flatten-test.mjs +0 -252
  284. package/scripts/compact-recall-digest-test.mjs +0 -57
  285. package/scripts/compact-smoke.mjs +0 -1017
  286. package/scripts/compact-trigger-migration-smoke.mjs +0 -261
  287. package/scripts/compacted-placeholder-scrub-test.mjs +0 -63
  288. package/scripts/context-mcp-metering-test.mjs +0 -1406
  289. package/scripts/debounced-skills-async-save-test.mjs +0 -57
  290. package/scripts/deferred-tool-loading-test.mjs +0 -250
  291. package/scripts/desktop-session-bridge-test.mjs +0 -1013
  292. package/scripts/dispatch-persist-recovery-test.mjs +0 -141
  293. package/scripts/embedding-worker-exit-test.mjs +0 -76
  294. package/scripts/execution-completion-dedup-test.mjs +0 -205
  295. package/scripts/execution-pending-resume-kick-test.mjs +0 -151
  296. package/scripts/execution-resume-esc-integration-test.mjs +0 -176
  297. package/scripts/explore-bench-tmp.mjs +0 -36
  298. package/scripts/explore-bench.mjs +0 -248
  299. package/scripts/explore-prompt-policy-test.mjs +0 -256
  300. package/scripts/explore-timeout-cancel-test.mjs +0 -345
  301. package/scripts/find-fuzzy-hidden-test.mjs +0 -267
  302. package/scripts/forwarder-rebind-tail-test.mjs +0 -67
  303. package/scripts/freevar-smoke.mjs +0 -98
  304. package/scripts/gemini-provider-test.mjs +0 -1448
  305. package/scripts/generate-oc-icons.mjs +0 -11
  306. package/scripts/grok-oauth-refresh-race-test.mjs +0 -273
  307. package/scripts/headless-pristine-execution-test.mjs +0 -614
  308. package/scripts/hook-bus-test.mjs +0 -552
  309. package/scripts/ingest-pure-conversation-smoke.mjs +0 -175
  310. package/scripts/internal-comms-bench-test.mjs +0 -226
  311. package/scripts/internal-comms-bench.mjs +0 -853
  312. package/scripts/internal-comms-smoke.mjs +0 -277
  313. package/scripts/internal-tools-normalization-test.mjs +0 -62
  314. package/scripts/interrupted-turn-history-test.mjs +0 -399
  315. package/scripts/lead-workflow-smoke.mjs +0 -592
  316. package/scripts/lifecycle-api-test.mjs +0 -137
  317. package/scripts/live-share-test.mjs +0 -148
  318. package/scripts/live-worker-smoke.mjs +0 -333
  319. package/scripts/log-writer-guard-smoke.mjs +0 -131
  320. package/scripts/maintenance-default-routes-test.mjs +0 -164
  321. package/scripts/max-output-recovery-persist-test.mjs +0 -81
  322. package/scripts/max-output-recovery-test.mjs +0 -368
  323. package/scripts/mcp-client-normalization-test.mjs +0 -45
  324. package/scripts/mcp-grace-deferred-test.mjs +0 -225
  325. package/scripts/memory-core-input-test.mjs +0 -167
  326. package/scripts/memory-cycle-routing-test.mjs +0 -111
  327. package/scripts/memory-meta-concurrency-test.mjs +0 -20
  328. package/scripts/memory-pg-recovery-test.mjs +0 -59
  329. package/scripts/memory-rule-contract-test.mjs +0 -93
  330. package/scripts/model-list-sanitize-test.mjs +0 -37
  331. package/scripts/mouse-tracking-restore-smoke.mjs +0 -107
  332. package/scripts/native-edit-wire-test.mjs +0 -152
  333. package/scripts/notify-completion-mirror-test.mjs +0 -73
  334. package/scripts/openai-oauth-refresh-race-test.mjs +0 -120
  335. package/scripts/openai-oauth-ws-1006-retry-test.mjs +0 -954
  336. package/scripts/openai-ws-early-settle-test.mjs +0 -216
  337. package/scripts/output-style-bench.mjs +0 -292
  338. package/scripts/output-style-smoke.mjs +0 -145
  339. package/scripts/parent-abort-link-test.mjs +0 -90
  340. package/scripts/patch-binary-cache-test.mjs +0 -181
  341. package/scripts/path-suffix-test.mjs +0 -57
  342. package/scripts/pending-completion-drop-test.mjs +0 -239
  343. package/scripts/pending-messages-lock-nonblocking-test.mjs +0 -62
  344. package/scripts/pretool-ask-runtime-test.mjs +0 -54
  345. package/scripts/process-lifecycle-test.mjs +0 -461
  346. package/scripts/prompt-immediate-render-test.mjs +0 -89
  347. package/scripts/prompt-input-parity-test.mjs +0 -145
  348. package/scripts/provider-admission-scheduler-test.mjs +0 -681
  349. package/scripts/provider-contract-test.mjs +0 -632
  350. package/scripts/provider-stream-stall-test.mjs +0 -276
  351. package/scripts/provider-toolcall-test.mjs +0 -3063
  352. package/scripts/reactive-compact-persist-smoke.mjs +0 -203
  353. package/scripts/recall-bench.mjs +0 -359
  354. package/scripts/resource-admission-test.mjs +0 -792
  355. package/scripts/result-classification-test.mjs +0 -75
  356. package/scripts/rg-runner-test.mjs +0 -240
  357. package/scripts/routing-corpus-test.mjs +0 -349
  358. package/scripts/sanitize-tool-pairs-test.mjs +0 -260
  359. package/scripts/session-bench-cache-break-test.mjs +0 -102
  360. package/scripts/session-bench.mjs +0 -1708
  361. package/scripts/session-context-bench.mjs +0 -344
  362. package/scripts/session-heartbeat-lifecycle-test.mjs +0 -68
  363. package/scripts/session-ingest-compaction-smoke.mjs +0 -279
  364. package/scripts/session-ingest-smoke.mjs +0 -177
  365. package/scripts/session-orphan-sweep-test.mjs +0 -109
  366. package/scripts/set-effort-config-test.mjs +0 -41
  367. package/scripts/shell-failure-diagnostics-test.mjs +0 -280
  368. package/scripts/shell-hardening-test.mjs +0 -209
  369. package/scripts/shell-jobs-windows-hide-test.mjs +0 -164
  370. package/scripts/ship-mode-test.mjs +0 -98
  371. package/scripts/smoke-loop-failure-summary-test.mjs +0 -38
  372. package/scripts/smoke-loop-failure-summary.mjs +0 -16
  373. package/scripts/smoke-loop-report.mjs +0 -221
  374. package/scripts/smoke-loop.mjs +0 -202
  375. package/scripts/smoke-runtime-negative.ps1 +0 -106
  376. package/scripts/statusline-quota-hysteresis-test.mjs +0 -62
  377. package/scripts/steering-drain-buckets-test.mjs +0 -467
  378. package/scripts/steering-fold-provenance-test.mjs +0 -71
  379. package/scripts/streaming-tail-window-test.mjs +0 -175
  380. package/scripts/submit-commandbusy-race-test.mjs +0 -257
  381. package/scripts/task-bench.mjs +0 -205
  382. package/scripts/terminal-bench-isolation-guards-test.mjs +0 -102
  383. package/scripts/termio-input-smoke.mjs +0 -199
  384. package/scripts/tool-result-hook-test.mjs +0 -48
  385. package/scripts/tool-smoke.mjs +0 -2453
  386. package/scripts/tool-tui-presentation-test.mjs +0 -286
  387. package/scripts/toolcall-args-test.mjs +0 -239
  388. package/scripts/tui-ambiguous-width-test.mjs +0 -113
  389. package/scripts/tui-background-failure-smoke.mjs +0 -73
  390. package/scripts/tui-perf-run.ps1 +0 -26
  391. package/scripts/tui-render-smoke.mjs +0 -90
  392. package/scripts/tui-runtime-load-bench-entry.jsx +0 -608
  393. package/scripts/tui-runtime-load-bench.mjs +0 -50
  394. package/scripts/tui-store-frame-batch-test.mjs +0 -99
  395. package/scripts/tui-transcript-jitter-harness-entry.jsx +0 -383
  396. package/scripts/tui-transcript-perf-test.mjs +0 -934
  397. package/scripts/usage-metrics-epoch-smoke.mjs +0 -114
  398. package/scripts/verify-release-assets-test.mjs +0 -281
  399. package/scripts/web-fetch-routing-test.mjs +0 -158
  400. package/scripts/webhook-smoke.mjs +0 -201
  401. package/scripts/windows-hide-spawn-options-test.mjs +0 -19
  402. package/scripts/worker-notify-rejection-test.mjs +0 -51
  403. package/scripts/write-backpressure-test.mjs +0 -147
@@ -1,934 +0,0 @@
1
- import test from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import { EventEmitter } from 'node:events';
4
- import { existsSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
5
-
6
- import {
7
- TRANSCRIPT_LIVE_ITEM_CAP,
8
- createEngineItemMutators,
9
- createTranscriptSpillBuffer,
10
- refillTranscriptViewOverlap,
11
- replaceEngineItemsState,
12
- } from '../src/tui/engine.mjs';
13
- import { createSessionFlow } from '../src/tui/engine/session-flow.mjs';
14
- import { createEngineApiA } from '../src/tui/engine/session-api.mjs';
15
- import { createRunTurn } from '../src/tui/engine/turn.mjs';
16
- import { createContextState } from '../src/tui/engine/context-state.mjs';
17
- import {
18
- restoreTranscriptItems,
19
- restoredAssistantTranscriptItems,
20
- restoredTranscriptMetadata,
21
- } from '../src/tui/engine/session-api-ext.mjs';
22
- import {
23
- attachAssistantTranscriptCompletion,
24
- persistedAssistantTranscriptMetadata,
25
- } from '../src/runtime/agent/orchestrator/session/manager/ask-session.mjs';
26
- import { attachAssistantTranscriptMetadata } from '../src/runtime/agent/orchestrator/session/agent-loop.mjs';
27
- import {
28
- buildTranscriptRowIndexIncremental,
29
- transcriptItemsWithStableTail,
30
- transcriptStructureSignature,
31
- } from '../src/tui/app/transcript-window.mjs';
32
- import {
33
- isCompletedTranscriptTail,
34
- isCompletedTranscriptTailAppendedThisCommit,
35
- isLiveSpinnerMetaVisible,
36
- } from '../src/tui/app/live-spinner-visibility.mjs';
37
-
38
- const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
39
-
40
- function makeTurnHarness(ask, stateOverrides = {}, bagOverrides = {}) {
41
- let seq = 0;
42
- let state = {
43
- items: [],
44
- structureRevision: 0,
45
- streamingTail: null,
46
- stats: { turns: 0, inputTokens: 0, outputTokens: 0 },
47
- busy: false,
48
- spinner: null,
49
- thinking: null,
50
- ...stateOverrides,
51
- };
52
- const itemIndexById = new Map();
53
- const set = (patch) => { state = { ...state, ...patch }; return true; };
54
- const pushItem = (item) => {
55
- const items = [...state.items, item];
56
- if (item?.id != null) itemIndexById.set(item.id, items.length - 1);
57
- set({ items, structureRevision: state.structureRevision + 1 });
58
- };
59
- const updateStreamingTail = (id, patch) => set({
60
- streamingTail: {
61
- ...(state.streamingTail?.id === id ? state.streamingTail : {}),
62
- ...patch,
63
- kind: 'assistant',
64
- id,
65
- streaming: true,
66
- },
67
- });
68
- const { patchItem, settleStreamingTail } = createEngineItemMutators({
69
- getState: () => state,
70
- set,
71
- itemIndexById,
72
- });
73
- const clearStreamingTail = (id = null) => {
74
- if (id == null || state.streamingTail?.id === id) set({ streamingTail: null });
75
- };
76
- const replaceItems = (items, options = {}) => {
77
- state = replaceEngineItemsState({
78
- state,
79
- items,
80
- itemIndexById,
81
- preserveStreamingTail: options.preserveStreamingTail === true,
82
- });
83
- return items;
84
- };
85
- const bag = {
86
- runtime: { id: null, toolMode: 'auto', ask, abort: () => true },
87
- nextId: () => `id_${++seq}`,
88
- tuiDebug: () => {},
89
- LEAD_TURN_TIMEOUT_MS: 300_000,
90
- flags: { leadTurnEpoch: 0, disposed: false },
91
- pending: [],
92
- itemIndexById,
93
- getState: () => state,
94
- set,
95
- pushItem,
96
- patchItem,
97
- replaceItems,
98
- updateStreamingTail,
99
- settleStreamingTail,
100
- clearStreamingTail,
101
- pushNotice: () => {},
102
- pushUserOrSyntheticItem: () => {},
103
- markToolCallActive: () => {},
104
- markToolCallDone: () => {},
105
- clearActiveToolSummary: () => {},
106
- agentStatusState: () => ({}),
107
- routeState: () => ({}),
108
- syncContextStats: () => {},
109
- denyAllToolApprovals: () => {},
110
- requestToolApproval: async () => ({ approved: false }),
111
- patchToolCardResult: () => {},
112
- flushToolResults: () => {},
113
- flushDeferredExecutionPendingResumeKick: () => {},
114
- drain: async () => {},
115
- drainPendingSteering: () => [],
116
- ...bagOverrides,
117
- };
118
- return { runTurn: createRunTurn(bag), getState: () => state };
119
- }
120
-
121
- test('successful mid-turn compact trims history but preserves live turn references', async () => {
122
- let preservedTail = false;
123
- let compactKeepsSpinnerVisible = false;
124
- let contextSyncs = 0;
125
- const harness = makeTurnHarness(async (_text, options) => {
126
- options.onTextDelta('before compact\n');
127
- await wait(30);
128
- options.onCompactEvent({ status: 'compacted', trigger: 'reactive' });
129
- assert.equal(contextSyncs, 1, 'compact event must refresh context before returning');
130
- preservedTail = harness.getState().streamingTail?.text === 'before compact\n';
131
- compactKeepsSpinnerVisible = harness.getState().spinner?.active === true
132
- && harness.getState().items.at(-1)?.kind === 'statusdone';
133
- options.onCompactEvent({ status: 'compacted', trigger: 'reactive' });
134
- assert.equal(contextSyncs, 2, 'each compact event refreshes context immediately');
135
- options.onTextDelta('after compact\n');
136
- return { result: { content: 'before compact\nafter compact\n' }, session: { messages: [] } };
137
- }, {
138
- items: [
139
- { id: 'old', kind: 'assistant', text: 'old history' },
140
- { id: 'current-user', kind: 'user', text: 'go' },
141
- ],
142
- }, {
143
- syncContextStats: () => { contextSyncs += 1; },
144
- });
145
-
146
- assert.equal(await harness.runTurn('go', { submittedIds: ['current-user'] }), 'done');
147
- assert.equal(preservedTail, true);
148
- assert.equal(compactKeepsSpinnerVisible, true, 'a compact status leaves the active turn spinner in place');
149
- assert.equal(harness.getState().items.some((item) => item.id === 'old'), false);
150
- assert.equal(harness.getState().items.some((item) => item.id === 'current-user'), true);
151
- assert.equal(
152
- harness.getState().items.filter((item) => item.label === 'Compact complete (overflow recovery)').length,
153
- 2,
154
- );
155
- assert.equal(
156
- harness.getState().items.find((item) => item.kind === 'assistant')?.text,
157
- 'before compact\nafter compact\n',
158
- );
159
- });
160
-
161
- test('live spinner remains visible across compact status and follows turn teardown', () => {
162
- const activeTurnSpinner = { active: true };
163
- const visible = (liveSpinner, liveSpinnerIsCommand, kind) => isLiveSpinnerMetaVisible({
164
- inputBoxHidden: false,
165
- slashPaletteOpen: false,
166
- liveSpinner,
167
- liveSpinnerIsCommand,
168
- latestTranscriptItem: kind ? { kind } : null,
169
- });
170
-
171
- assert.equal(visible(activeTurnSpinner, false, 'statusdone'), true);
172
- assert.equal(visible(activeTurnSpinner, false, 'turndone'), false);
173
- assert.equal(visible(null, false, 'turndone'), false);
174
- assert.equal(visible({ active: true }, true, 'turndone'), true);
175
- });
176
-
177
- test('completed transcript tail masking requires a new done tail', () => {
178
- assert.equal(isCompletedTranscriptTail({ id: 'turn', kind: 'turndone' }), true);
179
- assert.equal(isCompletedTranscriptTail({ id: 'status', kind: 'statusdone' }), true);
180
- assert.equal(isCompletedTranscriptTail({ id: 'assistant', kind: 'assistant' }), false);
181
- assert.equal(isCompletedTranscriptTail({ id: 'user', kind: 'user' }), false);
182
- assert.equal(isCompletedTranscriptTail(null), false);
183
- assert.equal(isCompletedTranscriptTailAppendedThisCommit({ id: 'turn', kind: 'turndone' }, 'turn'), false);
184
- assert.equal(isCompletedTranscriptTailAppendedThisCommit({ id: 'status', kind: 'statusdone' }, 'status'), false);
185
- assert.equal(isCompletedTranscriptTailAppendedThisCommit({ id: 'next', kind: 'turndone' }, 'previous'), true);
186
- assert.equal(isCompletedTranscriptTailAppendedThisCommit({ id: 'next-status', kind: 'statusdone' }, 'previous'), true);
187
- assert.equal(isCompletedTranscriptTailAppendedThisCommit({ id: 'assistant', kind: 'assistant' }, 'previous'), false);
188
- });
189
-
190
- test('failed mid-turn compact leaves prior transcript items untouched', async () => {
191
- const harness = makeTurnHarness(async (_text, options) => {
192
- options.onCompactEvent({ status: 'failed' });
193
- return { result: { content: '' }, session: { messages: [] } };
194
- }, {
195
- items: [{ id: 'old', kind: 'assistant', text: 'old history' }],
196
- });
197
-
198
- assert.equal(await harness.runTurn('go'), 'done');
199
- assert.equal(harness.getState().items.some((item) => item.id === 'old'), true);
200
- assert.equal(harness.getState().items.some((item) => item.label === 'Compact failed'), true);
201
- });
202
-
203
- test('stream flush keeps settled items identity and finalize appends one assistant', async () => {
204
- let identityStable = false;
205
- let persistedAssistantMessage = null;
206
- const harness = makeTurnHarness(async (_text, options) => {
207
- const before = harness.getState().items;
208
- options.onTextDelta('settled line\n');
209
- await wait(30);
210
- identityStable = harness.getState().items === before;
211
- assert.match(harness.getState().streamingTail?.text || '', /settled line/);
212
- persistedAssistantMessage = {
213
- meta: { transcript: persistedAssistantTranscriptMetadata(options.transcriptMeta, Date.now()) },
214
- };
215
- return { result: { content: 'settled line\n' }, session: { messages: [] } };
216
- });
217
-
218
- assert.equal(await harness.runTurn('go'), 'done');
219
- assert.equal(identityStable, true, 'tail flush must not swap settled items');
220
- assert.equal(harness.getState().streamingTail, null);
221
- const assistants = harness.getState().items.filter((item) => item.kind === 'assistant');
222
- assert.equal(assistants.length, 1);
223
- assert.equal(assistants[0].streaming, false);
224
- assert.equal(assistants[0].text, 'settled line\n');
225
- assert.equal(
226
- restoredTranscriptMetadata(persistedAssistantMessage).at,
227
- assistants[0].at,
228
- 'restored assistant timestamp must match its live creation timestamp',
229
- );
230
- });
231
-
232
- test('no-delta final assistant persists the timestamp later used by the live item', async () => {
233
- let persistedAssistantMessage = null;
234
- const harness = makeTurnHarness(async (_text, options) => {
235
- persistedAssistantMessage = {
236
- meta: { transcript: persistedAssistantTranscriptMetadata(options.transcriptMeta, Date.now()) },
237
- };
238
- return { result: { content: 'final without deltas' }, session: { messages: [] } };
239
- });
240
-
241
- assert.equal(await harness.runTurn('go'), 'done');
242
- const assistant = harness.getState().items.find((item) => item.kind === 'assistant');
243
- assert.equal(assistant?.text, 'final without deltas');
244
- assert.equal(restoredTranscriptMetadata(persistedAssistantMessage).at, assistant?.at);
245
- });
246
-
247
- test('assistant completion metadata survives session resume projection', () => {
248
- const turnStartedAt = Date.parse('2026-07-18T01:00:00Z');
249
- const messages = [
250
- { role: 'user', content: 'Question', meta: { transcript: { at: turnStartedAt } } },
251
- {
252
- role: 'assistant',
253
- content: 'Answer',
254
- meta: { transcript: { at: turnStartedAt + 1_000, model: 'model-a' } },
255
- },
256
- ];
257
- assert.equal(attachAssistantTranscriptCompletion(messages, {
258
- status: 'done',
259
- verb: 'Mapped',
260
- elapsedMs: 2_000,
261
- }, turnStartedAt), true);
262
- let sequence = 0;
263
- const restored = restoredAssistantTranscriptItems(messages[1], () => `restored-${++sequence}`);
264
- assert.equal(restored.length, 2);
265
- assert.deepEqual(restored[0], {
266
- kind: 'assistant',
267
- id: 'restored-1',
268
- text: 'Answer',
269
- at: turnStartedAt + 1_000,
270
- model: 'model-a',
271
- });
272
- assert.deepEqual(restored[1], {
273
- kind: 'turndone',
274
- id: 'restored-2',
275
- status: 'done',
276
- verb: 'Mapped',
277
- elapsedMs: 2_000,
278
- at: turnStartedAt + 1_000,
279
- });
280
- });
281
-
282
- test('cold transcript restore incrementally projects only the visible tail', () => {
283
- let oldBodyReads = 0;
284
- const oldMessages = Array.from({ length: 4_000 }, (_, index) => {
285
- const message = { role: index % 2 === 0 ? 'user' : 'assistant' };
286
- Object.defineProperty(message, 'content', {
287
- enumerable: true,
288
- get() {
289
- oldBodyReads += 1;
290
- return `old body ${index}`;
291
- },
292
- });
293
- return message;
294
- });
295
- const recentMessages = Array.from({ length: 400 }, (_, index) => ({
296
- role: index % 2 === 0 ? 'user' : 'assistant',
297
- content: `recent body ${index}`,
298
- ...(index % 2 === 1
299
- ? { meta: { transcript: { completion: { status: 'done', elapsedMs: index } } } }
300
- : {}),
301
- }));
302
- const messages = [...oldMessages, ...recentMessages];
303
- const restored = restoreTranscriptItems(messages, {
304
- sessionId: 'fast',
305
- itemLimit: 64,
306
- });
307
- const recentFull = restoreTranscriptItems(recentMessages, { sessionId: 'recent' });
308
-
309
- assert.equal(oldBodyReads, 0, 'tail restore must not read old message bodies');
310
- assert.equal(restored.length, 64);
311
- assert.deepEqual(
312
- restored.map((item) => [item.kind, item.text || '', item.status || '']),
313
- recentFull.slice(-64).map((item) => [item.kind, item.text || '', item.status || '']),
314
- );
315
- assert.match(restored[0].id, /^hist_fast_4\d{3}_\d+$/);
316
- });
317
-
318
- test('restored transcripts publish estimated context before a new provider turn', () => {
319
- let state = {
320
- stats: { inputTokens: 0, latestInputTokens: 0, latestPromptTokens: 0 },
321
- busy: false,
322
- spinner: null,
323
- thinking: null,
324
- };
325
- const context = createContextState({
326
- runtime: {
327
- contextStatus: () => ({
328
- contextWindow: 20_000,
329
- currentEstimatedTokens: 1_250,
330
- usedTokens: 1_250,
331
- usedSource: 'estimated',
332
- messages: { count: 2 },
333
- }),
334
- },
335
- getState: () => state,
336
- updateState: (patch) => { state = { ...state, ...patch }; },
337
- getPendingSessionReset: () => false,
338
- });
339
- context.syncContextStats({ allowEstimated: true });
340
- assert.equal(state.stats.currentContextTokens, 0);
341
- assert.equal(state.stats.currentEstimatedContextTokens, 1_250);
342
- assert.equal(state.stats.currentContextSource, 'estimated');
343
- });
344
-
345
- test('multi-tool preamble and final assistant preserve distinct live timestamps on restore', async () => {
346
- const persistedAssistantMessages = [];
347
- const takeAssistantTranscriptMetadata = (options) => {
348
- const transcript = persistedAssistantTranscriptMetadata(options.transcriptMeta, Date.now());
349
- delete options.transcriptMeta.assistantAt;
350
- return transcript;
351
- };
352
- const harness = makeTurnHarness(async (_text, options) => {
353
- options.onAssistantText('tool preamble');
354
- await options.onToolCall(1, [{ id: 'call_1', name: 'grep', input: { pattern: 'x' } }]);
355
- persistedAssistantMessages.push(attachAssistantTranscriptMetadata(
356
- { role: 'assistant', content: 'tool preamble', toolCalls: [] },
357
- { takeAssistantTranscriptMetadata: () => takeAssistantTranscriptMetadata(options) },
358
- ));
359
- options.onToolResult({ tool_call_id: 'call_1', content: 'ok' });
360
- persistedAssistantMessages.push({
361
- role: 'assistant',
362
- content: 'final answer',
363
- meta: { transcript: persistedAssistantTranscriptMetadata(options.transcriptMeta, Date.now()) },
364
- });
365
- return { result: { content: 'final answer' }, session: { messages: [] } };
366
- });
367
-
368
- assert.equal(await harness.runTurn('go'), 'done');
369
- const liveAssistants = harness.getState().items.filter((item) => item.kind === 'assistant');
370
- assert.equal(liveAssistants.length, 2);
371
- assert.equal(new Set(liveAssistants.map((item) => item.at)).size, 2);
372
- assert.deepEqual(
373
- persistedAssistantMessages.map((message) => restoredTranscriptMetadata(message).at),
374
- liveAssistants.map((item) => item.at),
375
- );
376
- });
377
-
378
- test('abort after stream progress settles the tail and leaves no orphan', async () => {
379
- const harness = makeTurnHarness(async (_text, options) => {
380
- options.onTextDelta('partial line\n');
381
- await wait(30);
382
- const error = new Error('interrupted');
383
- error.name = 'SessionClosedError';
384
- throw error;
385
- });
386
-
387
- assert.equal(await harness.runTurn('go'), 'cancelled');
388
- assert.equal(harness.getState().streamingTail, null);
389
- const assistants = harness.getState().items.filter((item) => item.kind === 'assistant');
390
- assert.equal(assistants.length, 1);
391
- assert.equal(assistants[0].streaming, false);
392
- assert.match(assistants[0].text, /partial line/);
393
- });
394
-
395
- test('abort before a newline settles the accumulated partial response', async () => {
396
- const harness = makeTurnHarness(async (_text, options) => {
397
- options.onTextDelta('partial without newline');
398
- await wait(30);
399
- const error = new Error('interrupted');
400
- error.name = 'SessionClosedError';
401
- throw error;
402
- });
403
-
404
- assert.equal(await harness.runTurn('go'), 'cancelled');
405
- assert.equal(harness.getState().streamingTail, null);
406
- const assistants = harness.getState().items.filter((item) => item.kind === 'assistant');
407
- assert.equal(assistants.length, 1);
408
- assert.equal(assistants[0].streaming, false);
409
- assert.equal(assistants[0].text, 'partial without newline');
410
- });
411
-
412
- test('abort after tool boundaries does not replay committed progress as one giant assistant row', async () => {
413
- const harness = makeTurnHarness(async (_text, options) => {
414
- options.onAssistantText('first progress');
415
- await options.onToolCall(1, [{
416
- id: 'call_1',
417
- name: 'shell',
418
- input: { command: 'first' },
419
- }]);
420
- options.onToolResult({ tool_call_id: 'call_1', content: 'ok' });
421
- options.onAssistantText('second progress');
422
- await options.onToolCall(2, [{
423
- id: 'call_2',
424
- name: 'shell',
425
- input: { command: 'second' },
426
- }]);
427
- const error = new Error('interrupted');
428
- error.name = 'SessionClosedError';
429
- throw error;
430
- });
431
-
432
- assert.equal(await harness.runTurn('go'), 'cancelled');
433
- assert.equal(harness.getState().streamingTail, null);
434
- const assistants = harness.getState().items.filter((item) => item.kind === 'assistant');
435
- assert.deepEqual(assistants.map((item) => item.text), ['first progress', 'second progress']);
436
- });
437
-
438
- // Codifies pre-existing parity: the old in-items completed-line snapshot survived starved recovery.
439
- test('starved Esc recovery settles a non-empty tail exactly once', async () => {
440
- let state = {
441
- items: [],
442
- structureRevision: 0,
443
- streamingTail: { id: 'tail_abort', kind: 'assistant', text: 'visible partial\n', streaming: true },
444
- queued: [],
445
- busy: true,
446
- commandBusy: false,
447
- spinner: { active: true },
448
- thinking: null,
449
- lastTurn: null,
450
- };
451
- const itemIndexById = new Map();
452
- const set = (patch) => { state = { ...state, ...patch }; return true; };
453
- const { patchItem, settleStreamingTail } = createEngineItemMutators({
454
- getState: () => state,
455
- set,
456
- itemIndexById,
457
- });
458
- const bag = {
459
- runtime: { abort: () => true },
460
- nextId: () => 'notice',
461
- flags: { leadTurnEpoch: 1, disposed: false, draining: false, manualAbortRecoveryMs: 10 },
462
- pending: [],
463
- listeners: new Set(),
464
- getState: () => state,
465
- set,
466
- pushItem: () => {},
467
- patchItem,
468
- replaceItems: (items) => items,
469
- settleStreamingTail,
470
- clearStreamingTail: () => set({ streamingTail: null }),
471
- pushNotice: () => {},
472
- autoClearState: () => ({}),
473
- agentStatusState: () => ({}),
474
- routeState: () => ({}),
475
- syncContextStats: () => {},
476
- denyAllToolApprovals: () => {},
477
- updateAgentJobCard: () => {},
478
- requeueEntriesFront: () => {},
479
- enqueue: () => {},
480
- autoClearBeforeSubmit: async () => {},
481
- restoreQueued: () => {},
482
- resetStatsAndSyncContext: () => {},
483
- drain: async () => {},
484
- flushDeferredExecutionPendingResumeKick: () => {},
485
- discardExecutionPendingResume: () => {},
486
- };
487
-
488
- createEngineApiA(bag).abort();
489
- await wait(30);
490
- assert.equal(state.streamingTail, null);
491
- const assistants = state.items.filter((item) => item.kind === 'assistant');
492
- assert.equal(assistants.length, 1);
493
- assert.equal(assistants[0].id, 'tail_abort');
494
- assert.equal(assistants[0].streaming, false);
495
- });
496
-
497
- test('Esc reclaim preserves spill pages while removing the submitted live item', () => {
498
- const spill = createTranscriptSpillBuffer();
499
- const original = Array.from({ length: TRANSCRIPT_LIVE_ITEM_CAP + 20 }, (_, index) => ({
500
- id: index === TRANSCRIPT_LIVE_ITEM_CAP + 19 ? 'submitted-live' : `esc-${index}`,
501
- kind: 'user',
502
- text: `${index}`,
503
- }));
504
- let state = {
505
- items: spill.capLive(original),
506
- busy: true,
507
- queued: [],
508
- streamingTail: null,
509
- spinner: { active: true },
510
- };
511
- let preserveSpill = false;
512
- const set = (patch) => { state = { ...state, ...patch }; return true; };
513
- const bag = {
514
- runtime: { abort: () => true },
515
- flags: {
516
- leadTurnEpoch: 1,
517
- disposed: false,
518
- activePromptRestore: {
519
- restorable: true,
520
- text: 'restore me',
521
- submittedIds: ['submitted-live'],
522
- discardExecutionPendingResumeKeys: [],
523
- requeueEntries: [],
524
- },
525
- },
526
- pending: [],
527
- listeners: new Set(),
528
- getState: () => state,
529
- set,
530
- replaceItems: (items, options = {}) => {
531
- preserveSpill = options.preserveSpill === true;
532
- if (!preserveSpill) spill.reset();
533
- state = { ...state, items };
534
- return items;
535
- },
536
- denyAllToolApprovals: () => {},
537
- discardExecutionPendingResume: () => {},
538
- requeueEntriesFront: () => {},
539
- clearStreamingTail: () => true,
540
- settleStreamingTail: () => true,
541
- };
542
-
543
- createEngineApiA(bag).abort();
544
- state = { ...state, busy: false };
545
- assert.equal(preserveSpill, true);
546
- assert.equal(state.items.some((item) => item.id === 'submitted-live'), false);
547
- const older = spill.restoreOlder(state.items);
548
- assert.ok(older.some((item) => item.id === 'esc-0'), 'older spill history remains reachable');
549
- spill.dispose();
550
- });
551
-
552
- test('removeNotice-style replacement preserves the live tail and later settles once', () => {
553
- let state = {
554
- items: [{ id: 'notice', kind: 'notice', text: 'temporary' }],
555
- structureRevision: 4,
556
- streamingTail: { id: 'tail_notice', kind: 'assistant', text: 'visible\n', streaming: true },
557
- };
558
- const itemIndexById = new Map([['notice', 0]]);
559
- const set = (patch) => { state = { ...state, ...patch }; return true; };
560
- const { settleStreamingTail } = createEngineItemMutators({
561
- getState: () => state,
562
- set,
563
- itemIndexById,
564
- });
565
- state = replaceEngineItemsState({
566
- state,
567
- items: state.items.filter((item) => item.id !== 'notice'),
568
- itemIndexById,
569
- preserveStreamingTail: true,
570
- });
571
-
572
- assert.equal(state.streamingTail?.id, 'tail_notice');
573
- assert.equal(settleStreamingTail('tail_notice', { text: 'complete final text' }), true);
574
- assert.equal(state.items.length, 1);
575
- assert.equal(state.items[0].text, 'complete final text');
576
- assert.equal(state.items[0].streaming, false);
577
- assert.equal(settleStreamingTail('tail_notice', { text: 'duplicate' }), false);
578
- assert.equal(state.items.length, 1);
579
- });
580
-
581
- test('bulk replacement clears the tail and stale settle cannot append into reset transcript', () => {
582
- let state = {
583
- items: [{ id: 'old', kind: 'user', text: 'old prompt' }],
584
- structureRevision: 8,
585
- streamingTail: { id: 'stale_tail', kind: 'assistant', text: 'old response\n', streaming: true },
586
- };
587
- const itemIndexById = new Map([['old', 0]]);
588
- const set = (patch) => { state = { ...state, ...patch }; return true; };
589
- const { settleStreamingTail } = createEngineItemMutators({
590
- getState: () => state,
591
- set,
592
- itemIndexById,
593
- });
594
- state = replaceEngineItemsState({ state, items: [], itemIndexById });
595
-
596
- assert.equal(state.streamingTail, null);
597
- assert.equal(settleStreamingTail('stale_tail', { text: 'must not reappear' }), false);
598
- assert.deepEqual(state.items, []);
599
- });
600
-
601
- test('tool-card revision invalidates the incremental prefix cache', () => {
602
- const cacheRef = { current: null };
603
- const tail = { id: 'tail', kind: 'assistant', text: 'live\n', streaming: true };
604
- let state = {
605
- items: [{ id: 'tool', kind: 'tool', name: 'shell', text: 'ok', result: 'ok' }],
606
- structureRevision: 1,
607
- streamingTail: tail,
608
- };
609
- const itemIndexById = new Map([['tool', 0]]);
610
- const set = (patch) => { state = { ...state, ...patch }; return true; };
611
- const { patchItem } = createEngineItemMutators({
612
- getState: () => state,
613
- set,
614
- itemIndexById,
615
- });
616
- const before = buildTranscriptRowIndexIncremental([...state.items, state.streamingTail], {
617
- columns: 24,
618
- cacheRef,
619
- prefixRevision: state.structureRevision,
620
- });
621
- const cachedBeforePatch = cacheRef.current;
622
- assert.equal(patchItem('tool', {
623
- text: 'a much longer tool result '.repeat(20),
624
- result: 'a much longer tool result '.repeat(20),
625
- }), true);
626
- assert.equal(state.structureRevision, 2, 'real engine patchItem bumps revision');
627
- const after = buildTranscriptRowIndexIncremental([...state.items, state.streamingTail], {
628
- columns: 24,
629
- cacheRef,
630
- prefixRevision: state.structureRevision,
631
- });
632
-
633
- assert.notEqual(cacheRef.current, cachedBeforePatch, 'revision bump rebuilds the prefix cache');
634
- assert.equal(after.rows.length, before.rows.length);
635
- assert.equal(cacheRef.current.prefixRevision, 2);
636
- });
637
-
638
- test('signature and streaming row-index fast paths retain O(1) prefix storage', () => {
639
- const items = Array.from({ length: 200 }, (_, index) => ({
640
- id: `fixed-${index}`, kind: 'notice', text: `row ${index}`,
641
- }));
642
- let tail = { id: 'tail-fast', kind: 'assistant', text: 'one', streaming: true };
643
- const cacheRef = { current: null };
644
- const firstIndex = buildTranscriptRowIndexIncremental([...items, tail], {
645
- cacheRef, prefixRevision: 9,
646
- });
647
- const firstTotal = firstIndex.totalRows;
648
- const prefixRowsArr = cacheRef.current.prefixRowsArr;
649
- const prefixPrefixRows = cacheRef.current.prefixPrefixRows;
650
- const beforeSig = transcriptStructureSignature([...items, tail], 80, false, 9);
651
- tail = { ...tail, text: 'one two three' };
652
- const secondIndex = buildTranscriptRowIndexIncremental([...items, tail], {
653
- cacheRef, prefixRevision: 9,
654
- });
655
- assert.equal(cacheRef.current.prefixRowsArr, prefixRowsArr);
656
- assert.equal(cacheRef.current.prefixPrefixRows, prefixPrefixRows);
657
- assert.equal(firstIndex.totalRows, firstTotal);
658
- assert.notEqual(firstIndex.prefixRows, secondIndex.prefixRows);
659
- assert.equal(
660
- transcriptStructureSignature([...items, tail], 80, false, 10)
661
- .startsWith('10|'),
662
- true,
663
- );
664
- assert.equal(beforeSig.startsWith('9|'), true);
665
- });
666
-
667
- test('tail height changes reuse the settled transcript container', () => {
668
- const settled = Array.from({ length: 200 }, (_, index) => ({
669
- id: `settled-${index}`, kind: 'notice', text: `${index}`,
670
- }));
671
- const cacheRef = { current: null };
672
- const before = transcriptItemsWithStableTail(
673
- settled,
674
- { id: 'stable-tail', kind: 'assistant', streaming: true, text: 'short' },
675
- cacheRef,
676
- );
677
- const after = transcriptItemsWithStableTail(
678
- settled,
679
- { id: 'stable-tail', kind: 'assistant', streaming: true, text: 'much longer text '.repeat(20) },
680
- cacheRef,
681
- );
682
- assert.equal(after, before, 'tail growth must not spread/copy the settled prefix');
683
- });
684
-
685
- test('transcript spill caps the live window and restores every item in order', () => {
686
- const spill = createTranscriptSpillBuffer();
687
- const original = Array.from({ length: TRANSCRIPT_LIVE_ITEM_CAP + 300 }, (_, index) => ({
688
- id: `history-${index}`, kind: 'notice', text: `history ${index}`,
689
- }));
690
- let live = spill.capLive(original);
691
- const canonicalLive = live;
692
- const seen = new Set(live.map((item) => item.id));
693
- assert.ok(live.length <= TRANSCRIPT_LIVE_ITEM_CAP);
694
- assert.equal(spill.hasOlder, true);
695
- while (spill.hasOlder) {
696
- live = spill.restoreOlder(live);
697
- for (const item of live) seen.add(item.id);
698
- for (let index = 1; index < live.length; index++) {
699
- assert.ok(Number(live[index - 1].id.slice(8)) < Number(live[index].id.slice(8)));
700
- }
701
- }
702
- assert.equal(seen.size, original.length);
703
- while (spill.hasNewer) {
704
- const restored = spill.restoreNewer(canonicalLive);
705
- live = restored?.atLive ? canonicalLive : restored;
706
- }
707
- assert.equal(live, canonicalLive, 'paging must return to the authoritative live array');
708
- assert.deepEqual(live, original.slice(-live.length));
709
- assert.ok(live.length <= TRANSCRIPT_LIVE_ITEM_CAP);
710
- spill.reset();
711
- spill.dispose();
712
- });
713
-
714
- test('spill restore succeeds before its asynchronous worker write completes', () => {
715
- const spill = createTranscriptSpillBuffer({ cap: 2, chunkSize: 1 });
716
- const live = spill.capLive([
717
- { id: 'async-old', kind: 'notice', text: 'old' },
718
- { id: 'async-mid', kind: 'notice', text: 'mid' },
719
- { id: 'async-new', kind: 'notice', text: 'new' },
720
- ]);
721
- const restored = spill.restoreOlder(live);
722
- assert.equal(restored[0].id, 'async-old');
723
- assert.deepEqual(restored.map((item) => item.id), ['async-old', 'async-mid', 'async-new']);
724
- spill.dispose();
725
- });
726
-
727
- test('failed reset restores retained spill pages transactionally', () => {
728
- const spill = createTranscriptSpillBuffer({ cap: 2, chunkSize: 1 });
729
- const oldLive = spill.capLive([
730
- { id: 'rollback-old', kind: 'notice', text: 'old' },
731
- { id: 'rollback-mid', kind: 'notice', text: 'mid' },
732
- { id: 'rollback-new', kind: 'notice', text: 'new' },
733
- ]);
734
- const snapshot = spill.snapshot();
735
- spill.reset();
736
- spill.capLive([
737
- { id: 'replacement-old', kind: 'notice', text: 'replacement' },
738
- { id: 'replacement-new', kind: 'notice', text: 'replacement' },
739
- ]);
740
- assert.equal(spill.restoreSnapshot(snapshot), true);
741
- assert.equal(spill.restoreOlder(oldLive)[0].id, 'rollback-old');
742
- spill.dispose();
743
- });
744
-
745
- test('burst spill reuses one worker and serializes all page writes', async () => {
746
- const workers = [];
747
- const workerFactory = () => {
748
- const worker = new EventEmitter();
749
- worker.unref = () => {};
750
- worker.terminate = () => {};
751
- worker.postMessage = ({ id }) => {
752
- queueMicrotask(() => worker.emit('message', { id, ok: true }));
753
- };
754
- workers.push(worker);
755
- return worker;
756
- };
757
- const spill = createTranscriptSpillBuffer({ cap: 2, chunkSize: 1, workerFactory });
758
- spill.capLive(Array.from({ length: 22 }, (_, index) => ({
759
- id: `burst-${index}`, kind: 'notice', text: `${index}`,
760
- })));
761
- await wait(10);
762
- assert.equal(workers.length, 1);
763
- assert.equal(spill.workerCount, 1);
764
- assert.equal(spill.pendingWriteCount, 0);
765
- spill.dispose();
766
- });
767
-
768
- test('terminal spill write failure pins history and warns once', async () => {
769
- let warnings = 0;
770
- const workerFactory = () => {
771
- const worker = new EventEmitter();
772
- worker.unref = () => {};
773
- worker.terminate = () => {};
774
- worker.postMessage = ({ id }) => {
775
- queueMicrotask(() => worker.emit('message', { id, ok: false, error: 'disk full' }));
776
- };
777
- return worker;
778
- };
779
- const spill = createTranscriptSpillBuffer({
780
- cap: 2,
781
- chunkSize: 1,
782
- workerFactory,
783
- onWarning: () => { warnings += 1; },
784
- });
785
- const live = spill.capLive([
786
- { id: 'pinned-old', kind: 'notice', text: 'old' },
787
- { id: 'pinned-mid', kind: 'notice', text: 'mid' },
788
- { id: 'pinned-new', kind: 'notice', text: 'new' },
789
- ]);
790
- await wait(10);
791
- assert.equal(spill.pinnedPageCount, 1);
792
- assert.equal(warnings, 1);
793
- assert.equal(spill.restoreOlder(live)[0].id, 'pinned-old');
794
- const afterFailure = [
795
- { id: 'disabled-a' },
796
- { id: 'disabled-b' },
797
- { id: 'disabled-c' },
798
- { id: 'disabled-d' },
799
- ];
800
- assert.equal(spill.disabled, true);
801
- assert.equal(spill.capLive(afterFailure), afterFailure);
802
- assert.equal(spill.workerCount, 1, 'disabled spilling must not create more work');
803
- spill.dispose();
804
- });
805
-
806
- test('spill worker exit retries in-flight history on one replacement worker', async () => {
807
- let spawn = 0;
808
- const workerFactory = () => {
809
- const worker = new EventEmitter();
810
- const thisSpawn = ++spawn;
811
- worker.unref = () => {};
812
- worker.terminate = () => {};
813
- worker.postMessage = ({ id, targetPath, tempPath, items }) => {
814
- queueMicrotask(() => {
815
- if (thisSpawn === 1) worker.emit('exit', 1);
816
- else {
817
- writeFileSync(tempPath, JSON.stringify(items), 'utf8');
818
- renameSync(tempPath, targetPath);
819
- worker.emit('message', { id, ok: true });
820
- }
821
- });
822
- };
823
- return worker;
824
- };
825
- const spill = createTranscriptSpillBuffer({
826
- cap: 2,
827
- chunkSize: 1,
828
- workerFactory,
829
- writeTimeoutMs: 100,
830
- });
831
- const live = spill.capLive([
832
- { id: 'exit-old', kind: 'notice', text: 'old' },
833
- { id: 'exit-mid', kind: 'notice', text: 'mid' },
834
- { id: 'exit-new', kind: 'notice', text: 'new' },
835
- ]);
836
- await wait(10);
837
- assert.equal(spill.workerCount, 2);
838
- assert.equal(spill.pendingWriteCount, 0);
839
- assert.equal(spill.pinnedPageCount, 0);
840
- assert.equal(spill.restoreOlder(live)[0].id, 'exit-old');
841
- spill.dispose();
842
- });
843
-
844
- test('spill attempt exposes history only after atomic rename commit', async () => {
845
- let firstTarget = '';
846
- let firstTemp = '';
847
- let spawn = 0;
848
- const workerFactory = () => {
849
- const worker = new EventEmitter();
850
- const thisSpawn = ++spawn;
851
- worker.unref = () => {};
852
- worker.terminate = () => {};
853
- worker.postMessage = ({ id, targetPath, tempPath, items }) => {
854
- if (thisSpawn === 1) {
855
- firstTarget = targetPath;
856
- firstTemp = tempPath;
857
- writeFileSync(tempPath, '{"partial":', 'utf8');
858
- return; // force timeout; the partial attempt never reaches targetPath
859
- }
860
- queueMicrotask(() => {
861
- writeFileSync(tempPath, JSON.stringify(items), 'utf8');
862
- renameSync(tempPath, targetPath);
863
- worker.emit('message', { id, ok: true });
864
- });
865
- };
866
- return worker;
867
- };
868
- const spill = createTranscriptSpillBuffer({
869
- cap: 2,
870
- chunkSize: 1,
871
- workerFactory,
872
- writeTimeoutMs: 5,
873
- });
874
- const live = spill.capLive([
875
- { id: 'atomic-old', kind: 'notice', text: 'old' },
876
- { id: 'atomic-mid', kind: 'notice', text: 'mid' },
877
- { id: 'atomic-new', kind: 'notice', text: 'new' },
878
- ]);
879
- const beforeCommit = spill.restoreOlder(live);
880
- assert.equal(beforeCommit[0].id, 'atomic-old', 'pending memory serves restore');
881
- assert.equal(existsSync(firstTemp), true);
882
- assert.equal(existsSync(firstTarget), false, 'partial attempt is never the committed page');
883
- await wait(20);
884
- assert.equal(JSON.parse(readFileSync(firstTarget, 'utf8'))[0].id, 'atomic-old');
885
- spill.dispose();
886
- });
887
-
888
- test('reclaim refills the nearest historical overlap from updated live items', () => {
889
- const historical = Array.from({ length: 3 }, (_, index) => ({ id: `old-${index}` }));
890
- const previousLive = Array.from({ length: 70 }, (_, index) => ({ id: `live-${index}` }));
891
- const view = [...historical, ...previousLive.slice(0, 64)];
892
- const nextLive = previousLive.filter((item) => item.id !== 'live-0');
893
- const refilled = refillTranscriptViewOverlap(view, previousLive, nextLive);
894
- assert.deepEqual(refilled.slice(0, 3), historical);
895
- assert.deepEqual(refilled.slice(3), nextLive.slice(0, 64));
896
- assert.equal(refilled.length, 67);
897
- });
898
-
899
- test('failed reset restores the historical transcript view', () => {
900
- let state = {
901
- items: [{ id: 'live' }],
902
- transcriptViewItems: [{ id: 'history' }, { id: 'live' }],
903
- transcriptViewRevision: 7,
904
- toasts: [],
905
- queued: [],
906
- thinking: null,
907
- spinner: null,
908
- lastTurn: null,
909
- busy: false,
910
- stats: {},
911
- sessionId: 'session',
912
- };
913
- const set = (patch) => { state = { ...state, ...patch }; };
914
- const flow = createSessionFlow({
915
- runtime: { id: 'session' },
916
- flags: {},
917
- pending: [],
918
- pendingNotificationKeys: new Set(),
919
- displayedExecutionNotificationKeys: new Set(),
920
- getState: () => state,
921
- set,
922
- replaceItems: (items) => items,
923
- snapshotTranscriptSpill: () => ({ token: 1 }),
924
- restoreTranscriptSpill: () => true,
925
- syncContextStats: () => {},
926
- routeState: () => ({}),
927
- agentStatusState: () => ({}),
928
- });
929
- const snapshot = flow.snapshotTuiBeforeSessionReset();
930
- state = { ...state, transcriptViewItems: null, transcriptViewRevision: 8 };
931
- flow.restoreTuiAfterFailedSessionReset(snapshot);
932
- assert.deepEqual(state.transcriptViewItems, [{ id: 'history' }, { id: 'live' }]);
933
- assert.equal(state.transcriptViewRevision, 7);
934
- });