mixdog 0.9.152 → 0.9.154

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 (300) hide show
  1. package/LICENSES/browser-import-NOTICE.txt +11 -0
  2. package/NOTICE.md +11 -0
  3. package/README.md +8 -10
  4. package/package.json +19 -3
  5. package/scripts/computer-task-cost-report.mjs +144 -0
  6. package/scripts/run-office-live-tests.mjs +32 -0
  7. package/src/agents/front-worker/AGENT.md +13 -0
  8. package/src/agents/front-worker/agent.json +6 -0
  9. package/src/agents/heavy-worker/AGENT.md +10 -11
  10. package/src/agents/heavy-worker/agent.json +1 -1
  11. package/src/agents/maintainer/AGENT.md +0 -2
  12. package/src/agents/reviewer/AGENT.md +9 -13
  13. package/src/agents/reviewer/agent.json +1 -1
  14. package/src/agents/security/AGENT.md +14 -0
  15. package/src/agents/security/agent.json +6 -0
  16. package/src/agents/worker/AGENT.md +8 -8
  17. package/src/agents/worker/agent.json +1 -1
  18. package/src/agents/writer/AGENT.md +14 -0
  19. package/src/agents/writer/agent.json +6 -0
  20. package/src/rules/agent/00-common.md +4 -7
  21. package/src/rules/lead/01-general.md +0 -3
  22. package/src/rules/shared/10-tool-workflow.md +10 -2
  23. package/src/rules/shared/60-verification.md +2 -0
  24. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch.mjs +183 -26
  25. package/src/runtime/agent/orchestrator/agent-runtime/session-builder.mjs +4 -0
  26. package/src/runtime/agent/orchestrator/cache-break-trace.mjs +109 -0
  27. package/src/runtime/agent/orchestrator/config.mjs +7 -2
  28. package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +16 -3
  29. package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +9 -1
  30. package/src/runtime/agent/orchestrator/providers/media-normalization.mjs +30 -9
  31. package/src/runtime/agent/orchestrator/providers/openai-codex-metadata.mjs +18 -26
  32. package/src/runtime/agent/orchestrator/providers/openai-oauth-http-sse.mjs +25 -2
  33. package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +103 -10
  34. package/src/runtime/agent/orchestrator/providers/openai-turn-state.mjs +68 -0
  35. package/src/runtime/agent/orchestrator/providers/openai-ws-delta.mjs +36 -11
  36. package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +140 -86
  37. package/src/runtime/agent/orchestrator/providers/openai-ws-stream.mjs +9 -13
  38. package/src/runtime/agent/orchestrator/session/agent-loop.mjs +72 -4
  39. package/src/runtime/agent/orchestrator/session/browser-snapshot-supersession.mjs +61 -0
  40. package/src/runtime/agent/orchestrator/session/compact/handoff.mjs +0 -22
  41. package/src/runtime/agent/orchestrator/session/compact/messages.mjs +2 -2
  42. package/src/runtime/agent/orchestrator/session/compact/runner.mjs +11 -23
  43. package/src/runtime/agent/orchestrator/session/compact/summary.mjs +28 -269
  44. package/src/runtime/agent/orchestrator/session/compact.mjs +0 -6
  45. package/src/runtime/agent/orchestrator/session/context-utils.mjs +86 -11
  46. package/src/runtime/agent/orchestrator/session/eager-dispatch.mjs +17 -1
  47. package/src/runtime/agent/orchestrator/session/image-strip-recovery.mjs +12 -8
  48. package/src/runtime/agent/orchestrator/session/loop/compact-policy.mjs +110 -2
  49. package/src/runtime/agent/orchestrator/session/loop/pre-dispatch-deny.mjs +3 -16
  50. package/src/runtime/agent/orchestrator/session/loop/recall-fasttrack.mjs +80 -18
  51. package/src/runtime/agent/orchestrator/session/loop/steering.mjs +6 -0
  52. package/src/runtime/agent/orchestrator/session/loop/tool-exec.mjs +3 -0
  53. package/src/runtime/agent/orchestrator/session/loop/tool-helpers.mjs +6 -0
  54. package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +80 -21
  55. package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +33 -72
  56. package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +21 -2
  57. package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +25 -51
  58. package/src/runtime/agent/orchestrator/session/manager/status-telemetry.mjs +3 -0
  59. package/src/runtime/agent/orchestrator/session/manager/tool-resolution.mjs +4 -110
  60. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.mjs +39 -15
  61. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint.mjs +14 -4
  62. package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +41 -8
  63. package/src/runtime/agent/orchestrator/session/provider-prefix-guard.mjs +129 -12
  64. package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +2 -2
  65. package/src/runtime/agent/orchestrator/session/store/listing.mjs +8 -1
  66. package/src/runtime/agent/orchestrator/session/store/save-worker.mjs +15 -1
  67. package/src/runtime/agent/orchestrator/session/store-summary-index.mjs +36 -2
  68. package/src/runtime/agent/orchestrator/session/store-summary-reader.mjs +157 -30
  69. package/src/runtime/agent/orchestrator/session/store-summary-visibility.mjs +57 -0
  70. package/src/runtime/agent/orchestrator/session/store.mjs +3 -1
  71. package/src/runtime/agent/orchestrator/session/tool-batch.mjs +22 -0
  72. package/src/runtime/agent/orchestrator/tools/builtin/read-special-files.mjs +6 -6
  73. package/src/runtime/agent/orchestrator/tools/progress-message.mjs +4 -0
  74. package/src/runtime/attachments/pdf-extract.mjs +3 -0
  75. package/src/runtime/attachments/pdfjs-runtime.mjs +13 -0
  76. package/src/runtime/browser-bridge/action-schema.mjs +251 -0
  77. package/src/runtime/browser-bridge/client.mjs +75 -26
  78. package/src/runtime/browser-bridge/tool-defs.mjs +132 -15
  79. package/src/runtime/computer-bridge/action-schema.mjs +653 -0
  80. package/src/runtime/computer-bridge/client.mjs +211 -28
  81. package/src/runtime/computer-bridge/tool-defs.mjs +25 -45
  82. package/src/runtime/office/assurance-benchmark.mjs +358 -0
  83. package/src/runtime/office/assurance.mjs +833 -0
  84. package/src/runtime/office/benchmark.mjs +496 -0
  85. package/src/runtime/office/capabilities.mjs +551 -0
  86. package/src/runtime/office/com-adapter.mjs +283 -0
  87. package/src/runtime/office/content-model.mjs +183 -0
  88. package/src/runtime/office/contract-benchmark.mjs +105 -0
  89. package/src/runtime/office/design-library.mjs +1562 -0
  90. package/src/runtime/office/design-system.mjs +1966 -0
  91. package/src/runtime/office/index.mjs +2413 -0
  92. package/src/runtime/office/journal.mjs +82 -0
  93. package/src/runtime/office/office-com-host.ps1 +3781 -0
  94. package/src/runtime/office/office-com-session-host.ps1 +855 -0
  95. package/src/runtime/office/ooxml-validator.mjs +271 -0
  96. package/src/runtime/office/pagination.mjs +132 -0
  97. package/src/runtime/office/pdf-adapter.mjs +591 -0
  98. package/src/runtime/office/pdf-analysis.mjs +372 -0
  99. package/src/runtime/office/pdf-render.mjs +167 -0
  100. package/src/runtime/office/pdf-security.mjs +63 -0
  101. package/src/runtime/office/polish-benchmark.mjs +190 -0
  102. package/src/runtime/office/portable-ooxml.mjs +1867 -0
  103. package/src/runtime/office/quality-live-benchmark.mjs +486 -0
  104. package/src/runtime/office/quality-pipeline.mjs +136 -0
  105. package/src/runtime/office/tabular.mjs +302 -0
  106. package/src/runtime/office/templates/mixdog-executive.pptx +0 -0
  107. package/src/runtime/office/templates/mixdog-executive.pptx.mixdog.json +190 -0
  108. package/src/runtime/office/tool-defs.mjs +113 -0
  109. package/src/runtime/office/visual-diff.mjs +89 -0
  110. package/src/runtime/office/xlsx-assertions.mjs +172 -0
  111. package/src/runtime/office/xlsx-contract.mjs +147 -0
  112. package/src/runtime/shared/agent-route-config.mjs +9 -0
  113. package/src/runtime/shared/tool-execution-contract.mjs +16 -0
  114. package/src/runtime/shared/tool-surface.mjs +9 -0
  115. package/src/session-runtime/context-status.mjs +9 -3
  116. package/src/session-runtime/deferred-tool-delta.mjs +104 -0
  117. package/src/session-runtime/goal-runtime.mjs +617 -197
  118. package/src/session-runtime/lifecycle-api.mjs +50 -8
  119. package/src/session-runtime/provider-request-snapshot.mjs +33 -9
  120. package/src/session-runtime/resource-api.mjs +31 -94
  121. package/src/session-runtime/runtime-core.mjs +78 -26
  122. package/src/session-runtime/session-lifecycle.mjs +34 -12
  123. package/src/session-runtime/session-title.mjs +2 -2
  124. package/src/session-runtime/session-turn-api.mjs +15 -14
  125. package/src/session-runtime/tool-catalog-data.mjs +1 -1
  126. package/src/session-runtime/tool-catalog.mjs +38 -99
  127. package/src/session-runtime/tool-defs.mjs +6 -1
  128. package/src/session-runtime/tool-surface.mjs +18 -8
  129. package/src/session-runtime/workflow-agents-api.mjs +8 -25
  130. package/src/session-runtime/workflow.mjs +8 -6
  131. package/src/standalone/agent-tool/helpers.mjs +2 -2
  132. package/src/standalone/agent-tool/job-views.mjs +3 -1
  133. package/src/standalone/agent-tool/notify.mjs +5 -1
  134. package/src/standalone/agent-tool/render.mjs +3 -0
  135. package/src/standalone/agent-tool/spawn-flow.mjs +61 -16
  136. package/src/standalone/agent-tool/tool-def.mjs +1 -1
  137. package/src/standalone/agent-tool/worker-index.mjs +123 -0
  138. package/src/standalone/agent-tool/worker-rows.mjs +2 -1
  139. package/src/standalone/agent-tool.mjs +57 -10
  140. package/src/standalone/daemon.mjs +105 -6
  141. package/src/standalone/session-runtime-host.mjs +61 -48
  142. package/src/standalone/session-runtime-inline-host.mjs +34 -127
  143. package/src/standalone/session-runtime-worker.mjs +20 -198
  144. package/src/standalone/session-service.mjs +632 -7
  145. package/src/tui/dist/index.mjs +24 -1
  146. package/src/tui/lib/voice-setup.mjs +4 -1
  147. package/src/tui/session/context-state.mjs +2 -13
  148. package/src/tui/session/goal-continuation.mjs +38 -7
  149. package/src/tui/session/session-api-ext.mjs +9 -0
  150. package/src/tui/session/session-api.mjs +15 -1
  151. package/src/tui/session/session-flow.mjs +25 -1
  152. package/src/tui/session/turn.mjs +88 -16
  153. package/src/tui/session-local.mjs +25 -3
  154. package/src/vendor/statusline/src/gateway/route-meta.mjs +31 -0
  155. package/scripts/generate-voice-runtime-manifest.test.mjs +0 -135
  156. package/scripts/native-binary-arch.test.mjs +0 -111
  157. package/scripts/patch-replay.test.mjs +0 -94
  158. package/src/headless-exec.test.mjs +0 -539
  159. package/src/runtime/agent/orchestrator/agent-trace-timing.test.mjs +0 -57
  160. package/src/runtime/agent/orchestrator/context/collect-skills.test.mjs +0 -153
  161. package/src/runtime/agent/orchestrator/mcp/cancellation.test.mjs +0 -139
  162. package/src/runtime/agent/orchestrator/mcp/features.test.mjs +0 -66
  163. package/src/runtime/agent/orchestrator/mcp/security.test.mjs +0 -80
  164. package/src/runtime/agent/orchestrator/providers/anthropic-fast-mode.test.mjs +0 -90
  165. package/src/runtime/agent/orchestrator/providers/anthropic-server-fallback.test.mjs +0 -215
  166. package/src/runtime/agent/orchestrator/providers/antigravity-oauth.test.mjs +0 -165
  167. package/src/runtime/agent/orchestrator/providers/media-parity.test.mjs +0 -142
  168. package/src/runtime/agent/orchestrator/providers/openai-codex-identity.test.mjs +0 -153
  169. package/src/runtime/agent/orchestrator/providers/openai-codex-model.test.mjs +0 -24
  170. package/src/runtime/agent/orchestrator/providers/openai-ws-delta-parity.test.mjs +0 -190
  171. package/src/runtime/agent/orchestrator/providers/provider-replay.test.mjs +0 -235
  172. package/src/runtime/agent/orchestrator/providers/sse-framing.test.mjs +0 -719
  173. package/src/runtime/agent/orchestrator/session/cache/prefetch-cache.test.mjs +0 -40
  174. package/src/runtime/agent/orchestrator/session/compact-policy.test.mjs +0 -176
  175. package/src/runtime/agent/orchestrator/session/compaction-read-reset.test.mjs +0 -161
  176. package/src/runtime/agent/orchestrator/session/eager-dispatch.test.mjs +0 -115
  177. package/src/runtime/agent/orchestrator/session/evidence-union.test.mjs +0 -228
  178. package/src/runtime/agent/orchestrator/session/image-strip-recovery.test.mjs +0 -245
  179. package/src/runtime/agent/orchestrator/session/lossless-tool-output.test.mjs +0 -125
  180. package/src/runtime/agent/orchestrator/session/manager/pending-messages-persistence.test.mjs +0 -325
  181. package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.test.mjs +0 -70
  182. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.test.mjs +0 -457
  183. package/src/runtime/agent/orchestrator/session/provider-prefix-guard.test.mjs +0 -117
  184. package/src/runtime/agent/orchestrator/session/reduction-metrics.test.mjs +0 -87
  185. package/src/runtime/agent/orchestrator/session/store/serialize.test.mjs +0 -60
  186. package/src/runtime/agent/orchestrator/session/store-summary-reader.test.mjs +0 -583
  187. package/src/runtime/agent/orchestrator/session/task-wait-control.test.mjs +0 -78
  188. package/src/runtime/agent/orchestrator/tools/builtin/absence-absorption.test.mjs +0 -43
  189. package/src/runtime/agent/orchestrator/tools/builtin/absolute-glob-expand.test.mjs +0 -63
  190. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool-cwd-env.test.mjs +0 -14
  191. package/src/runtime/agent/orchestrator/tools/builtin/edit-encoding-eol.test.mjs +0 -224
  192. package/src/runtime/agent/orchestrator/tools/builtin/edit-sequential-occupation.test.mjs +0 -224
  193. package/src/runtime/agent/orchestrator/tools/builtin/enoent-outside-project.test.mjs +0 -56
  194. package/src/runtime/agent/orchestrator/tools/builtin/find-search-budget.test.mjs +0 -103
  195. package/src/runtime/agent/orchestrator/tools/builtin/git-command-policy.test.mjs +0 -30
  196. package/src/runtime/agent/orchestrator/tools/builtin/git-command-tool.test.mjs +0 -390
  197. package/src/runtime/agent/orchestrator/tools/builtin/git-repo-rw-lock.test.mjs +0 -83
  198. package/src/runtime/agent/orchestrator/tools/builtin/grep-output-budget.test.mjs +0 -31
  199. package/src/runtime/agent/orchestrator/tools/builtin/grep-single-file-rescue.test.mjs +0 -106
  200. package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-job-records.test.mjs +0 -102
  201. package/src/runtime/agent/orchestrator/tools/builtin/list-tool-integrity.test.mjs +0 -152
  202. package/src/runtime/agent/orchestrator/tools/builtin/native-search-health.test.mjs +0 -24
  203. package/src/runtime/agent/orchestrator/tools/builtin/native-search-transport.test.mjs +0 -24
  204. package/src/runtime/agent/orchestrator/tools/builtin/noise-dir-visibility.test.mjs +0 -69
  205. package/src/runtime/agent/orchestrator/tools/builtin/read-glob-survey.test.mjs +0 -71
  206. package/src/runtime/agent/orchestrator/tools/builtin/runtime-capabilities.test.mjs +0 -56
  207. package/src/runtime/agent/orchestrator/tools/builtin/search-builders.test.mjs +0 -16
  208. package/src/runtime/agent/orchestrator/tools/builtin/search-glob-top-k.test.mjs +0 -39
  209. package/src/runtime/agent/orchestrator/tools/builtin/write-symlink.test.mjs +0 -153
  210. package/src/runtime/agent/orchestrator/tools/code-graph/aggregate-anchor-relocation.test.mjs +0 -55
  211. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.test.mjs +0 -88
  212. package/src/runtime/agent/orchestrator/tools/code-graph/loose-file-target.test.mjs +0 -72
  213. package/src/runtime/agent/orchestrator/tools/code-graph/memory-cache.test.mjs +0 -54
  214. package/src/runtime/agent/orchestrator/tools/code-graph/search-references.test.mjs +0 -20
  215. package/src/runtime/agent/orchestrator/tools/code-graph/symbol-search-scope.test.mjs +0 -55
  216. package/src/runtime/agent/orchestrator/tools/code-graph/text-span-mask.test.mjs +0 -268
  217. package/src/runtime/agent/orchestrator/tools/env-scrub.test.mjs +0 -57
  218. package/src/runtime/agent/orchestrator/tools/graph-binary-fetcher.test.mjs +0 -19
  219. package/src/runtime/agent/orchestrator/tools/lib/native-spawn-client.test.mjs +0 -104
  220. package/src/runtime/agent/orchestrator/tools/patch/engine-contract-gate.test.mjs +0 -661
  221. package/src/runtime/agent/orchestrator/tools/patch/patch-codec-eol.test.mjs +0 -552
  222. package/src/runtime/agent/orchestrator/tools/patch/patch-symlink.test.mjs +0 -141
  223. package/src/runtime/agent/orchestrator/tools/patch/v4a-pure-move.test.mjs +0 -57
  224. package/src/runtime/agent/orchestrator/tools/patch/v4a-section-coalesce.test.mjs +0 -81
  225. package/src/runtime/agent/orchestrator/tools/spawn-binary-fetcher.test.mjs +0 -52
  226. package/src/runtime/attachments/store.test.mjs +0 -209
  227. package/src/runtime/channels/lib/voice-runtime-fetcher.test.mjs +0 -17
  228. package/src/runtime/channels/lib/webhook/deliveries.test.mjs +0 -18
  229. package/src/runtime/channels/lib/webhook/relay-tunnel.test.mjs +0 -68
  230. package/src/runtime/media/adapters/codex-image.test.mjs +0 -22
  231. package/src/runtime/media/download.test.mjs +0 -52
  232. package/src/runtime/media/renditions.test.mjs +0 -99
  233. package/src/runtime/media/store.test.mjs +0 -159
  234. package/src/runtime/memory/lib/archive-security.test.mjs +0 -128
  235. package/src/runtime/memory/lib/embedding-model-config.test.mjs +0 -33
  236. package/src/runtime/memory/lib/http-wire.test.mjs +0 -15
  237. package/src/runtime/memory/lib/memory-cycle-packets.test.mjs +0 -49
  238. package/src/runtime/memory/lib/memory-cycle2-shared.test.mjs +0 -78
  239. package/src/runtime/memory/lib/memory-embedding-migration.test.mjs +0 -50
  240. package/src/runtime/memory/lib/pg/process.test.mjs +0 -36
  241. package/src/runtime/memory/lib/trace-store.test.mjs +0 -57
  242. package/src/runtime/memory/lib/transcript-ingest.test.mjs +0 -52
  243. package/src/runtime/shared/background-tasks.test.mjs +0 -78
  244. package/src/runtime/shared/bounded-download.test.mjs +0 -41
  245. package/src/runtime/shared/channel-notification-routing.test.mjs +0 -25
  246. package/src/runtime/shared/child-spawn-remote.test.mjs +0 -124
  247. package/src/runtime/shared/remote-intent.test.mjs +0 -40
  248. package/src/runtime/shared/resource-admission.test.mjs +0 -43
  249. package/src/runtime/shared/runtime-root.test.mjs +0 -34
  250. package/src/runtime/shared/schedule-time.test.mjs +0 -29
  251. package/src/runtime/shared/session-runtime-health.test.mjs +0 -83
  252. package/src/runtime/shared/skill-document.test.mjs +0 -81
  253. package/src/runtime/shared/tool-surface.test.mjs +0 -87
  254. package/src/runtime/shared/update-checker.test.mjs +0 -33
  255. package/src/runtime/shared/user-cwd.test.mjs +0 -43
  256. package/src/runtime/shared/webhook-session-run.test.mjs +0 -14
  257. package/src/session-runtime/agent-disable.test.mjs +0 -123
  258. package/src/session-runtime/cwd-plugins.test.mjs +0 -75
  259. package/src/session-runtime/cwd-tool-routing.test.mjs +0 -61
  260. package/src/session-runtime/global-extensions.test.mjs +0 -28
  261. package/src/session-runtime/goal-runtime.test.mjs +0 -108
  262. package/src/session-runtime/lifecycle-api.test.mjs +0 -21
  263. package/src/session-runtime/model-settings-persist.test.mjs +0 -105
  264. package/src/session-runtime/notification-bus.test.mjs +0 -148
  265. package/src/session-runtime/plugin-mcp-standard.test.mjs +0 -177
  266. package/src/session-runtime/prewarm.test.mjs +0 -52
  267. package/src/session-runtime/provider-request-snapshot.test.mjs +0 -37
  268. package/src/session-runtime/resource-api-global.test.mjs +0 -69
  269. package/src/session-runtime/session-lifecycle.test.mjs +0 -125
  270. package/src/session-runtime/session-title.test.mjs +0 -36
  271. package/src/session-runtime/skills-api.test.mjs +0 -99
  272. package/src/session-runtime/tool-policy-surface.test.mjs +0 -331
  273. package/src/standalone/agent-tool/helpers.test.mjs +0 -62
  274. package/src/standalone/agent-tool/notify.test.mjs +0 -37
  275. package/src/standalone/agent-tool/spawn-flow.test.mjs +0 -63
  276. package/src/standalone/channel-restart.test.mjs +0 -145
  277. package/src/standalone/channel-session-router.test.mjs +0 -37
  278. package/src/standalone/channel-worker-heartbeat.test.mjs +0 -30
  279. package/src/standalone/hook-bus/handlers.test.mjs +0 -88
  280. package/src/standalone/plugin-admin.test.mjs +0 -173
  281. package/src/standalone/session-runtime-agent-control-client.test.mjs +0 -71
  282. package/src/standalone/session-runtime-dispatch-cancel.test.mjs +0 -139
  283. package/src/standalone/session-runtime-host-factory.test.mjs +0 -31
  284. package/src/standalone/session-runtime-host-health.test.mjs +0 -160
  285. package/src/standalone/session-runtime-inline-host.test.mjs +0 -83
  286. package/src/standalone/session-runtime-provider-cooldown.test.mjs +0 -80
  287. package/src/standalone/session-runtime-shard-host.test.mjs +0 -569
  288. package/src/standalone/session-runtime-shard-router.test.mjs +0 -101
  289. package/src/tui/app/live-spinner-visibility.test.mjs +0 -44
  290. package/src/tui/app/panel-epoch.test.mjs +0 -1009
  291. package/src/tui/app/panel-handoff.test.mjs +0 -311
  292. package/src/tui/app/prompt-submit.test.mjs +0 -206
  293. package/src/tui/session/completion-card-restore.test.mjs +0 -111
  294. package/src/tui/session/goal-continuation.test.mjs +0 -84
  295. package/src/tui/session/oauth-flows.test.mjs +0 -134
  296. package/src/tui/session/queue-helpers.test.mjs +0 -46
  297. package/src/tui/session/session-action-surface.test.mjs +0 -108
  298. package/src/tui/session/task-wait-submit.test.mjs +0 -80
  299. package/src/tui/session/tool-result-status.test.mjs +0 -131
  300. package/src/tui/session/tui-steering-persist.test.mjs +0 -104
@@ -1,457 +0,0 @@
1
- // Focused coverage for the append/coalesced turn-checkpoint journal that
2
- // replaced the 150ms full growing-turn snapshot:
3
- // * prompt durability still lands synchronously on the first flush,
4
- // * replay reproduces the exact full-snapshot object (messages + partial
5
- // text/reasoning + tool pairing) at bounded write cost,
6
- // * crash-torn tails, stale journals, wholesale transcript rewrites,
7
- // cancellation and clear all keep latest-wins recovery semantics.
8
- import assert from 'node:assert/strict';
9
- import { spawnSync } from 'node:child_process';
10
- import {
11
- appendFileSync,
12
- existsSync,
13
- mkdtempSync,
14
- readFileSync,
15
- rmSync,
16
- statSync,
17
- writeFileSync,
18
- } from 'node:fs';
19
- import { tmpdir } from 'node:os';
20
- import { join } from 'node:path';
21
- import test from 'node:test';
22
-
23
- // MIXDOG_DATA_DIR must be set before the modules resolve the checkpoint dir.
24
- const root = mkdtempSync(join(tmpdir(), 'mixdog-turn-journal-'));
25
- process.env.MIXDOG_DATA_DIR = root;
26
- process.on('exit', () => { try { rmSync(root, { recursive: true, force: true }); } catch { /* best-effort */ } });
27
-
28
- const {
29
- clearTurnCheckpoint,
30
- createTurnCheckpointRecorder,
31
- readTurnCheckpoint,
32
- recoverTurnCheckpoint,
33
- settleTurnCheckpointWrites,
34
- turnMessagesForCheckpoint,
35
- } = await import('./turn-checkpoint.mjs');
36
- const {
37
- _setJournalOpGateForTest,
38
- turnCheckpointPath,
39
- turnJournalPath,
40
- } = await import('./turn-checkpoint-journal.mjs');
41
- const {
42
- createTurnInterruptionTracker,
43
- finalizeTurnInterruptionSnapshot,
44
- } = await import('./turn-interruption.mjs');
45
-
46
- function startTurn(sessionId, prompt = 'do the thing') {
47
- const tracker = createTurnInterruptionTracker();
48
- const outgoing = [
49
- { role: 'system', content: 'sys' },
50
- { role: 'user', content: prompt },
51
- ];
52
- const recorder = createTurnCheckpointRecorder({
53
- sessionId,
54
- generation: 3,
55
- turnToken: `tok-${sessionId}`,
56
- startedAt: 1000,
57
- });
58
- const flush = () => recorder.record({
59
- currentUserContent: prompt,
60
- turnOutgoing: outgoing,
61
- interruption: tracker,
62
- });
63
- return { tracker, outgoing, recorder, flush, prompt };
64
- }
65
-
66
- /**
67
- * Hold every async journal operation in the write lane so reset/clear/stop/
68
- * overflow can be driven while a write is GENUINELY in flight (entry.writing
69
- * is true and its bytes are not on disk) instead of after settlement.
70
- */
71
- function holdJournalWrites() {
72
- let open = () => {};
73
- const gate = new Promise((resolve) => { open = resolve; });
74
- let released = false;
75
- _setJournalOpGateForTest(() => gate);
76
- return {
77
- release() {
78
- if (released) return;
79
- released = true;
80
- _setJournalOpGateForTest(null);
81
- open();
82
- },
83
- };
84
- }
85
-
86
- test('first flush anchors the prompt synchronously', () => {
87
- const sessionId = 'sess-anchor';
88
- const turn = startTurn(sessionId);
89
- assert.equal(turn.flush(), true);
90
- // No await: the header is the crash-durability anchor and must be on disk
91
- // before the provider call returns control.
92
- const checkpoint = readTurnCheckpoint(sessionId);
93
- assert.equal(checkpoint.turnToken, `tok-${sessionId}`);
94
- assert.equal(checkpoint.generation, 3);
95
- assert.deepEqual(checkpoint.turnMessages, [{ role: 'user', content: 'do the thing' }]);
96
- });
97
-
98
- test('journal replay reproduces the full snapshot at bounded cost', async () => {
99
- const sessionId = 'sess-replay';
100
- const turn = startTurn(sessionId);
101
- turn.flush();
102
- const headerBytes = statSync(turnCheckpointPath(sessionId)).size;
103
- const body = 'x'.repeat(2000);
104
- for (let i = 0; i < 40; i += 1) {
105
- turn.tracker.recordTextDelta(`chunk-${i} `);
106
- const call = { id: `call-${i}`, name: 'shell', arguments: '{}' };
107
- turn.outgoing.push({ role: 'assistant', content: `${body}${i}`, toolCalls: [call] });
108
- turn.tracker.recordToolCalls([call]);
109
- turn.outgoing.push({ role: 'tool', content: body, toolCallId: call.id });
110
- turn.flush();
111
- }
112
- await settleTurnCheckpointWrites(sessionId);
113
-
114
- // The header is written exactly once per turn — it still holds only the
115
- // opening prompt, so the growing turn never rewrites it.
116
- assert.equal(statSync(turnCheckpointPath(sessionId)).size, headerBytes);
117
- const checkpoint = readTurnCheckpoint(sessionId);
118
- assert.deepEqual(
119
- checkpoint.turnMessages,
120
- turnMessagesForCheckpoint(turn.outgoing, turn.prompt),
121
- );
122
- assert.deepEqual(checkpoint.interruption, turn.tracker.snapshot());
123
-
124
- // Bounded cost: total bytes written stay proportional to the turn payload
125
- // instead of flushes x turn size (the old writer re-serialized everything
126
- // on every flush, ~40x this volume for the same turn).
127
- const payloadBytes = Buffer.byteLength(JSON.stringify(checkpoint.turnMessages));
128
- const journalBytes = statSync(turnJournalPath(sessionId)).size;
129
- assert.ok(
130
- journalBytes < payloadBytes * 2,
131
- `journal ${journalBytes} bytes should stay near payload ${payloadBytes} bytes`,
132
- );
133
- });
134
-
135
- test('crash recovery matches the live finalize path (text reset, tool pairing)', async () => {
136
- const sessionId = 'sess-recover';
137
- const prompt = 'run the tool';
138
- const turn = startTurn(sessionId, prompt);
139
- turn.flush();
140
- turn.tracker.markProviderSendStarted();
141
- turn.tracker.recordTextDelta('partial answer');
142
- turn.tracker.recordReasoningDelta('thinking');
143
- turn.flush();
144
- // A UI-acknowledged reset tombstones the tail; a crash cannot complete the
145
- // replacement, so the same visible bytes must survive.
146
- turn.tracker.tombstoneText(7);
147
- turn.flush();
148
- const call = { id: 'call-a', name: 'read', arguments: '{}' };
149
- turn.tracker.recordToolCalls([call]);
150
- turn.outgoing.push({ role: 'assistant', content: '', toolCalls: [call] });
151
- turn.tracker.markToolPhaseStarted();
152
- turn.tracker.recordToolResult({ toolCallId: 'call-a', content: 'early', __earlyNotify: true });
153
- turn.flush();
154
- await settleTurnCheckpointWrites(sessionId);
155
-
156
- const checkpoint = readTurnCheckpoint(sessionId);
157
- assert.deepEqual(checkpoint.interruption, turn.tracker.snapshot());
158
- assert.equal(checkpoint.interruption.partialAssistantContent, 'partial answer');
159
-
160
- const session = {
161
- id: sessionId,
162
- generation: 3,
163
- updatedAt: 0,
164
- messages: [{ role: 'system', content: 'sys' }, { role: 'user', content: prompt }],
165
- activeTurnCheckpoint: { turnToken: `tok-${sessionId}` },
166
- _providerPrefixGuardState: { messageHashes: ['stale'], requestPrefixHash: 'stale' },
167
- };
168
- const recovery = recoverTurnCheckpoint(session);
169
- assert.equal(recovery.recovered, true);
170
- // A recovered (rewritten) transcript must never keep the mid-turn provider
171
- // prefix snapshot: a stale one flags every following send as
172
- // history_shrink ("Session state changed unexpectedly.").
173
- assert.equal(Object.prototype.hasOwnProperty.call(session, '_providerPrefixGuardState'), false);
174
- const expected = finalizeTurnInterruptionSnapshot({
175
- turnOutgoing: checkpoint.turnMessages,
176
- currentUserContent: checkpoint.currentUserContent,
177
- snapshot: turn.tracker.snapshot(),
178
- abortReason: 'process-crash',
179
- });
180
- assert.deepEqual(session.messages, [{ role: 'system', content: 'sys' }, ...expected.messages]);
181
- assert.equal(session.messages.at(-1).content, '[Request interrupted by process restart]');
182
- // Every observed call is paired with a result in the recovered transcript.
183
- assert.ok(session.messages.some((m) => m.role === 'tool' && m.toolCallId === 'call-a'));
184
- });
185
-
186
- test('a crash-torn trailing record is discarded and the durable prefix survives', async () => {
187
- const sessionId = 'sess-torn';
188
- const turn = startTurn(sessionId);
189
- turn.flush();
190
- turn.tracker.recordTextDelta('durable text');
191
- turn.outgoing.push({ role: 'assistant', content: 'committed' });
192
- turn.flush();
193
- await settleTurnCheckpointWrites(sessionId);
194
- appendFileSync(turnJournalPath(sessionId), '{"t":"m","i":2,"m":{"role":"tool","con');
195
-
196
- const checkpoint = readTurnCheckpoint(sessionId);
197
- assert.equal(checkpoint.turnMessages.length, 2);
198
- assert.equal(checkpoint.turnMessages[1].content, 'committed');
199
- assert.equal(checkpoint.interruption.partialAssistantContent, 'durable text');
200
- });
201
-
202
- test('a journal from another turn never replays onto a new header', async () => {
203
- const sessionId = 'sess-stale';
204
- const turn = startTurn(sessionId);
205
- turn.flush();
206
- turn.tracker.recordTextDelta('old turn text');
207
- turn.flush();
208
- await settleTurnCheckpointWrites(sessionId);
209
- const header = JSON.parse(readFileSync(turnCheckpointPath(sessionId), 'utf8'));
210
- writeFileSync(
211
- turnCheckpointPath(sessionId),
212
- JSON.stringify({ ...header, turnToken: 'other-token' }),
213
- 'utf8',
214
- );
215
-
216
- const checkpoint = readTurnCheckpoint(sessionId);
217
- assert.equal(checkpoint.turnToken, 'other-token');
218
- assert.equal(checkpoint.interruption.partialAssistantContent, '');
219
- });
220
-
221
- test('rewritten and truncated transcripts replay latest-wins', async () => {
222
- const sessionId = 'sess-rewrite';
223
- const turn = startTurn(sessionId);
224
- turn.flush();
225
- turn.outgoing.push({ role: 'assistant', content: 'first' }, { role: 'assistant', content: 'second' });
226
- turn.flush();
227
- // Wholesale replacement (image-strip splice / pre-send compaction).
228
- turn.outgoing.splice(
229
- 0,
230
- turn.outgoing.length,
231
- { role: 'system', content: 'sys' },
232
- { role: 'user', content: turn.prompt },
233
- { role: 'assistant', content: 'rewritten' },
234
- );
235
- turn.flush();
236
- await settleTurnCheckpointWrites(sessionId);
237
-
238
- const checkpoint = readTurnCheckpoint(sessionId);
239
- assert.deepEqual(checkpoint.turnMessages, [
240
- { role: 'user', content: turn.prompt },
241
- { role: 'assistant', content: 'rewritten' },
242
- ]);
243
- });
244
-
245
- test('clear is token-guarded and removes header + journal', async () => {
246
- const sessionId = 'sess-clear';
247
- const turn = startTurn(sessionId);
248
- turn.flush();
249
- turn.tracker.recordTextDelta('x');
250
- turn.flush();
251
- await settleTurnCheckpointWrites(sessionId);
252
-
253
- assert.equal(clearTurnCheckpoint(sessionId, 'someone-elses-token'), false);
254
- assert.ok(existsSync(turnCheckpointPath(sessionId)));
255
- assert.equal(clearTurnCheckpoint(sessionId, `tok-${sessionId}`), true);
256
- assert.equal(existsSync(turnCheckpointPath(sessionId)), false);
257
- assert.equal(existsSync(turnJournalPath(sessionId)), false);
258
- assert.equal(readTurnCheckpoint(sessionId), null);
259
- });
260
-
261
- // ── In-flight write races (regressions) ─────────────────────────────────────
262
-
263
- test('a new turn fences an older IN-FLIGHT append (no stale turn under a new token)', async () => {
264
- const sessionId = 'sess-fence';
265
- const first = startTurn(sessionId, 'first prompt');
266
- first.flush();
267
- const hold = holdJournalWrites();
268
- let during;
269
- let second;
270
- try {
271
- first.outgoing.push({ role: 'assistant', content: 'STALE_OLD_TURN' });
272
- first.tracker.recordTextDelta('STALE_OLD_TURN partial');
273
- first.flush(); // genuinely in flight: accepted, not on disk
274
- first.recorder.stop();
275
-
276
- second = createTurnCheckpointRecorder({
277
- sessionId,
278
- generation: 3,
279
- turnToken: 'tok-second',
280
- startedAt: 2000,
281
- });
282
- const secondOutgoing = [
283
- { role: 'system', content: 'sys' },
284
- { role: 'user', content: 'second prompt' },
285
- ];
286
- assert.equal(second.record({
287
- currentUserContent: 'second prompt',
288
- turnOutgoing: secondOutgoing,
289
- interruption: createTurnInterruptionTracker(),
290
- }), true);
291
- // Interim window: header is the new turn, the journal is still the old
292
- // one. Replay must reject it rather than merge an old turn.
293
- during = readTurnCheckpoint(sessionId);
294
- } finally {
295
- hold.release();
296
- }
297
- assert.equal(during.turnToken, 'tok-second');
298
- assert.ok(!JSON.stringify(during).includes('STALE_OLD_TURN'));
299
-
300
- await settleTurnCheckpointWrites(sessionId);
301
- const after = readTurnCheckpoint(sessionId);
302
- assert.equal(after.turnToken, 'tok-second');
303
- assert.ok(!JSON.stringify(after).includes('STALE_OLD_TURN'), 'old turn replayed under the new token');
304
- assert.deepEqual(after.turnMessages, [{ role: 'user', content: 'second prompt' }]);
305
- const journal = readFileSync(turnJournalPath(sessionId), 'utf8').trim().split('\n');
306
- assert.equal(JSON.parse(journal[0]).turnToken, 'tok-second');
307
- assert.ok(!journal.some((line) => line.includes('STALE_OLD_TURN')));
308
- });
309
-
310
- test('overflow never writes ahead of an older IN-FLIGHT append (latest-wins holds)', async () => {
311
- const sessionId = 'sess-overflow';
312
- const turn = startTurn(sessionId);
313
- turn.flush();
314
- const headBytes = statSync(turnJournalPath(sessionId)).size;
315
- const hold = holdJournalWrites();
316
- try {
317
- turn.outgoing.push({ role: 'assistant', content: 'OLD_IN_FLIGHT' });
318
- turn.flush(); // in flight
319
- // >4MB of NEWER records queue behind it and cross the overflow ceiling.
320
- const filler = 'y'.repeat(512 * 1024);
321
- for (let i = 0; i < 9; i += 1) {
322
- turn.outgoing[2] = { role: 'assistant', content: `${filler}-${i}` };
323
- turn.flush();
324
- }
325
- turn.outgoing[2] = { role: 'assistant', content: 'NEWEST' };
326
- turn.flush();
327
- // Nothing may reach disk while an older write is outstanding.
328
- assert.equal(
329
- statSync(turnJournalPath(sessionId)).size,
330
- headBytes,
331
- 'overflow drain overtook an in-flight append',
332
- );
333
- } finally {
334
- hold.release();
335
- }
336
- await settleTurnCheckpointWrites(sessionId);
337
- const checkpoint = readTurnCheckpoint(sessionId);
338
- assert.deepEqual(checkpoint.turnMessages[1], { role: 'assistant', content: 'NEWEST' });
339
- });
340
-
341
- test('explicit process exit flushes in-flight AND queued deltas in order', () => {
342
- const sessionId = 'sess-exit';
343
- const source = `
344
- const checkpoint = await import(${JSON.stringify(new URL('./turn-checkpoint.mjs', import.meta.url).href)});
345
- const journal = await import(${JSON.stringify(new URL('./turn-checkpoint-journal.mjs', import.meta.url).href)});
346
- const interruption = await import(${JSON.stringify(new URL('./turn-interruption.mjs', import.meta.url).href)});
347
- const sessionId = ${JSON.stringify(sessionId)};
348
- const prompt = 'exit prompt';
349
- const tracker = interruption.createTurnInterruptionTracker();
350
- const outgoing = [{ role: 'system', content: 'sys' }, { role: 'user', content: prompt }];
351
- const recorder = checkpoint.createTurnCheckpointRecorder({ sessionId, generation: 3, turnToken: 'tok-exit', startedAt: 1000 });
352
- const flush = () => recorder.record({ currentUserContent: prompt, turnOutgoing: outgoing, interruption: tracker });
353
- flush();
354
- // Never resolves: the next append stays in flight, the one after it queues.
355
- journal._setJournalOpGateForTest(() => new Promise(() => {}));
356
- tracker.recordTextDelta('IN_FLIGHT ');
357
- outgoing.push({ role: 'assistant', content: 'IN_FLIGHT_MESSAGE' });
358
- flush();
359
- tracker.recordTextDelta('QUEUED');
360
- outgoing.push({ role: 'tool', content: 'QUEUED_MESSAGE', toolCallId: 'call-q' });
361
- flush();
362
- process.exit(0);
363
- `;
364
- const result = spawnSync(process.execPath, ['--input-type=module', '-e', source], {
365
- encoding: 'utf8',
366
- env: { ...process.env, MIXDOG_DATA_DIR: root },
367
- });
368
- assert.equal(result.status, 0, `child failed: ${result.stderr}`);
369
-
370
- const checkpoint = readTurnCheckpoint(sessionId);
371
- assert.equal(checkpoint.turnMessages.length, 3, 'exit persisted only the journal head');
372
- assert.equal(checkpoint.turnMessages[1].content, 'IN_FLIGHT_MESSAGE');
373
- assert.equal(checkpoint.turnMessages[2].content, 'QUEUED_MESSAGE');
374
- assert.equal(checkpoint.interruption.partialAssistantContent, 'IN_FLIGHT QUEUED');
375
- });
376
-
377
- test('clear while a write is IN FLIGHT drops the header now and the journal after', async () => {
378
- const sessionId = 'sess-clear-race';
379
- const turn = startTurn(sessionId);
380
- turn.flush();
381
- const hold = holdJournalWrites();
382
- try {
383
- turn.outgoing.push({ role: 'assistant', content: 'inflight' });
384
- turn.flush();
385
- assert.equal(clearTurnCheckpoint(sessionId, `tok-${sessionId}`), true);
386
- // The header is the recovery gate; it must be gone immediately.
387
- assert.equal(existsSync(turnCheckpointPath(sessionId)), false);
388
- assert.equal(readTurnCheckpoint(sessionId), null);
389
- } finally {
390
- hold.release();
391
- }
392
- await settleTurnCheckpointWrites(sessionId);
393
- assert.equal(existsSync(turnJournalPath(sessionId)), false, 'in-flight append resurrected the journal');
394
- assert.equal(readTurnCheckpoint(sessionId), null);
395
- });
396
-
397
- test('stop while a write is IN FLIGHT keeps that write and drops only queued deltas', async () => {
398
- const sessionId = 'sess-stop-race';
399
- const turn = startTurn(sessionId);
400
- turn.flush();
401
- const hold = holdJournalWrites();
402
- try {
403
- turn.outgoing.push({ role: 'assistant', content: 'inflight-kept' });
404
- turn.flush(); // in flight
405
- turn.outgoing.push({ role: 'assistant', content: 'queued-dropped' });
406
- turn.flush(); // queued
407
- turn.recorder.stop();
408
- assert.equal(turn.flush(), false);
409
- } finally {
410
- hold.release();
411
- }
412
- await settleTurnCheckpointWrites(sessionId);
413
- const checkpoint = readTurnCheckpoint(sessionId);
414
- assert.equal(checkpoint.turnMessages.length, 2);
415
- assert.equal(checkpoint.turnMessages[1].content, 'inflight-kept');
416
- assert.ok(!JSON.stringify(checkpoint).includes('queued-dropped'));
417
- });
418
-
419
- test('replay skips a duplicated re-flushed record and stops at a real gap', async () => {
420
- const sessionId = 'sess-seq';
421
- const turn = startTurn(sessionId);
422
- turn.flush();
423
- turn.outgoing.push({ role: 'assistant', content: 'first' });
424
- turn.flush();
425
- await settleTurnCheckpointWrites(sessionId);
426
- const lines = readFileSync(turnJournalPath(sessionId), 'utf8').trim().split('\n');
427
- // Exit-handler style duplicate of the last accepted record, then a record
428
- // from beyond the durable prefix.
429
- appendFileSync(turnJournalPath(sessionId), `${lines[lines.length - 1]}\n`);
430
- appendFileSync(
431
- turnJournalPath(sessionId),
432
- `${JSON.stringify({ t: 'm', i: 2, m: { role: 'assistant', content: 'after-gap' }, s: 99 })}\n`,
433
- );
434
-
435
- const checkpoint = readTurnCheckpoint(sessionId);
436
- assert.equal(checkpoint.turnMessages.length, 2);
437
- assert.equal(checkpoint.turnMessages[1].content, 'first');
438
- assert.ok(!JSON.stringify(checkpoint).includes('after-gap'));
439
- });
440
-
441
- test('stop retires further flushes without dropping the durable prefix', async () => {
442
- const sessionId = 'sess-stop';
443
- const turn = startTurn(sessionId);
444
- turn.flush();
445
- turn.tracker.recordTextDelta('durable');
446
- turn.flush();
447
- await settleTurnCheckpointWrites(sessionId);
448
-
449
- turn.tracker.recordTextDelta('-late');
450
- turn.recorder.stop();
451
- assert.equal(turn.flush(), false);
452
- await settleTurnCheckpointWrites(sessionId);
453
-
454
- const checkpoint = readTurnCheckpoint(sessionId);
455
- assert.equal(checkpoint.interruption.partialAssistantContent, 'durable');
456
- assert.deepEqual(checkpoint.turnMessages, [{ role: 'user', content: 'do the thing' }]);
457
- });
@@ -1,117 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import test from 'node:test';
3
- import {
4
- prepareProviderPrefixGuard,
5
- ProviderPrefixMutationError,
6
- } from './provider-prefix-guard.mjs';
7
-
8
- const CACHE_PROVIDERS = [
9
- 'anthropic',
10
- 'anthropic-oauth',
11
- 'openai',
12
- 'openai-oauth',
13
- 'xai',
14
- 'grok-oauth',
15
- 'gemini',
16
- 'deepseek',
17
- 'opencode-go',
18
- 'cursor-oauth',
19
- 'ollama',
20
- 'lmstudio',
21
- ];
22
-
23
- test('accepts append-only provider history for every provider surface', () => {
24
- for (const provider of CACHE_PROVIDERS) {
25
- const first = prepareProviderPrefixGuard(
26
- null,
27
- [{ role: 'user', content: 'one' }],
28
- { tools: [{ name: 'read' }], nativeTools: [] },
29
- { provider },
30
- );
31
- assert.doesNotThrow(() => prepareProviderPrefixGuard(
32
- first,
33
- [
34
- { role: 'user', content: 'one' },
35
- { role: 'assistant', content: 'two' },
36
- ],
37
- { tools: [{ name: 'read' }], nativeTools: [] },
38
- { provider },
39
- ), provider);
40
- }
41
- });
42
-
43
- test('rejects prior-message rewrites outside compaction', () => {
44
- const first = prepareProviderPrefixGuard(
45
- null,
46
- [{ role: 'user', content: 'one' }],
47
- { tools: [{ name: 'read' }], nativeTools: [] },
48
- );
49
- assert.throws(
50
- () => prepareProviderPrefixGuard(
51
- first,
52
- [{ role: 'user', content: 'rewritten' }],
53
- { tools: [{ name: 'read' }], nativeTools: [] },
54
- ),
55
- ProviderPrefixMutationError,
56
- );
57
- });
58
-
59
- test('rebaselines tool-prefix changes while preserving transcript integrity checks', () => {
60
- const first = prepareProviderPrefixGuard(
61
- null,
62
- [{ role: 'user', content: 'one' }],
63
- { tools: [{ name: 'read' }], nativeTools: [] },
64
- );
65
- const changed = prepareProviderPrefixGuard(
66
- first,
67
- [{ role: 'user', content: 'one' }],
68
- { tools: [{ name: 'read' }, { name: 'shell' }], nativeTools: [] },
69
- );
70
- assert.notEqual(changed.requestPrefixHash, first.requestPrefixHash);
71
- assert.doesNotThrow(() => prepareProviderPrefixGuard(
72
- changed,
73
- [
74
- { role: 'user', content: 'one' },
75
- { role: 'assistant', content: 'two' },
76
- ],
77
- { tools: [{ name: 'read' }, { name: 'shell' }], nativeTools: [] },
78
- ));
79
- assert.throws(
80
- () => prepareProviderPrefixGuard(
81
- changed,
82
- [{ role: 'user', content: 'rewritten' }],
83
- { tools: [{ name: 'read' }, { name: 'shell' }], nativeTools: [] },
84
- ),
85
- ProviderPrefixMutationError,
86
- );
87
- });
88
-
89
- test('allows only compaction intents to establish a new prefix', () => {
90
- const first = prepareProviderPrefixGuard(
91
- null,
92
- [{ role: 'user', content: 'one' }],
93
- { tools: [{ name: 'read' }], nativeTools: [] },
94
- );
95
- for (const cacheBreakIntent of [
96
- 'automatic_compaction',
97
- 'deferred_body_compaction',
98
- 'manual_compaction',
99
- 'post_turn_compaction',
100
- ]) {
101
- assert.doesNotThrow(() => prepareProviderPrefixGuard(
102
- first,
103
- [{ role: 'user', content: 'compacted' }],
104
- { tools: [{ name: 'read' }], nativeTools: [] },
105
- { cacheBreakIntent },
106
- ));
107
- }
108
- assert.throws(
109
- () => prepareProviderPrefixGuard(
110
- first,
111
- [{ role: 'user', content: 'repaired' }],
112
- { tools: [{ name: 'read' }], nativeTools: [] },
113
- { cacheBreakIntent: 'transcript_rebuild' },
114
- ),
115
- ProviderPrefixMutationError,
116
- );
117
- });
@@ -1,87 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import test from 'node:test';
3
- import { buildToolOutputTelemetryPayload } from '../agent-trace-format.mjs';
4
- import { summarizeReductionTraceRows } from './reduction-metrics.mjs';
5
-
6
- test('generic offload telemetry records only byte counts and reduction', () => {
7
- assert.deepEqual(buildToolOutputTelemetryPayload({
8
- toolCallId: 'call_list_1',
9
- preOffloadBytes: 50_000,
10
- postOffloadBytes: 700,
11
- modelVisibleBytes: 700,
12
- offloaded: true,
13
- resultKind: 'normal',
14
- }), {
15
- tool_call_id: 'call_list_1',
16
- result_kind: 'normal',
17
- pre_offload_bytes: 50_000,
18
- post_offload_bytes: 700,
19
- model_visible_bytes: 700,
20
- saved_bytes: 49_300,
21
- reduction_pct: 99,
22
- offloaded: true,
23
- });
24
- });
25
-
26
- test('reduction report separates evidence, artifact, and shell savings without double counting', () => {
27
- const summary = summarizeReductionTraceRows([
28
- {
29
- kind: 'evidence_union',
30
- payload: {
31
- before_bytes: 1_000,
32
- after_bytes: 700,
33
- reused_rows: 3,
34
- exact_result_refs: 1,
35
- exact_result_bytes_saved: 100,
36
- },
37
- },
38
- {
39
- kind: 'tool_output',
40
- payload: {
41
- pre_offload_bytes: 5_000,
42
- model_visible_bytes: 500,
43
- },
44
- },
45
- {
46
- kind: 'shell_output',
47
- payload: {
48
- command_output_bytes: 10_000,
49
- model_visible_bytes: 300,
50
- },
51
- },
52
- { kind: 'usage_raw', input_tokens: 12_000, cached_tokens: 8_000, output_tokens: 900 },
53
- { kind: 'batch', payload: { tool_call_count: 2 } },
54
- { kind: 'tool', tool_name: 'list', tool_args: { path: 'src' } },
55
- ]);
56
- assert.deepEqual(summary.evidence, {
57
- projections: 1,
58
- beforeBytes: 1_000,
59
- afterBytes: 700,
60
- savedBytes: 300,
61
- rowSavedBytes: 200,
62
- exactSavedBytes: 100,
63
- reusedRows: 3,
64
- exactRefs: 1,
65
- });
66
- assert.equal(summary.artifactOffload.savedBytes, 4_500);
67
- assert.equal(summary.shell.savedBytes, 9_700);
68
- assert.equal(summary.totalSavedBytes, 14_500);
69
- assert.deepEqual(summary.activity, {
70
- providerRequests: 1,
71
- toolBatches: 1,
72
- toolCalls: 1,
73
- artifactReads: 0,
74
- });
75
- assert.deepEqual(summary.tokens, { input: 12_000, cached: 8_000, output: 900 });
76
- });
77
-
78
- test('reduction report exposes artifact reads that may add a model turn', () => {
79
- const summary = summarizeReductionTraceRows([
80
- {
81
- kind: 'tool',
82
- tool_name: 'read',
83
- tool_args: { file_path: 'C:/data/tool-results/session/abc.txt' },
84
- },
85
- ]);
86
- assert.equal(summary.activity.artifactReads, 1);
87
- });