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,84 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import test from 'node:test';
3
-
4
- import { createGoalContinuation } from './goal-continuation.mjs';
5
-
6
- const settleImmediate = () => new Promise((resolve) => setImmediate(resolve));
7
-
8
- test('idle Goal schedules one hidden continuation and user input cancels it', async () => {
9
- const goal = { id: 'goal-1', status: 'active', objective: 'Finish it' };
10
- const state = { busy: false, commandBusy: false, sessionId: 'sess_goal', goal };
11
- const pending = [];
12
- let listener = null;
13
- let archived = 0;
14
- const controller = createGoalContinuation({
15
- runtime: {
16
- id: 'sess_goal',
17
- goalStatus: () => goal,
18
- goalContinuation: () => ({ run: true, reason: 'idle', goal, prompt: 'hidden continuation' }),
19
- onGoalStatusChange: (next) => {
20
- listener = next;
21
- return () => { listener = null; };
22
- },
23
- archiveCompletedGoalOnUserInput: async () => { archived += 1; },
24
- },
25
- flags: { disposed: false, pendingSessionReset: false },
26
- getState: () => state,
27
- set: (patch) => Object.assign(state, patch),
28
- getPending: () => pending,
29
- enqueue: (text, options) => {
30
- pending.push({ content: text, ...options });
31
- return true;
32
- },
33
- });
34
- try {
35
- assert.equal(controller.scheduleGoalContinuation(), true);
36
- controller.scheduleGoalContinuation();
37
- await settleImmediate();
38
- assert.equal(pending.length, 1);
39
- assert.equal(pending[0].mode, 'goal-continuation');
40
- assert.equal(pending[0].priority, 'later');
41
- assert.equal(controller.shouldRunGoalContinuation(pending[0]), true);
42
-
43
- controller.archiveCompletedGoalOnUserInput();
44
- assert.equal(pending.length, 0);
45
- await settleImmediate();
46
- assert.equal(archived, 1);
47
-
48
- listener?.({ sessionId: 'sess_goal', goal: { ...goal, status: 'paused' } });
49
- await settleImmediate();
50
- assert.equal(pending.length, 0);
51
- } finally {
52
- controller.disposeGoalContinuation();
53
- }
54
- });
55
-
56
- test('busy or agent-parked Goal does not enqueue a continuation', async () => {
57
- const goal = { id: 'goal-2', status: 'active' };
58
- const state = { busy: true, commandBusy: false, sessionId: 'sess_goal_busy', goal };
59
- const pending = [];
60
- const controller = createGoalContinuation({
61
- runtime: {
62
- id: 'sess_goal_busy',
63
- goalStatus: () => goal,
64
- goalContinuation: () => ({ run: false, reason: 'agent-running', goal }),
65
- onGoalStatusChange: () => () => {},
66
- },
67
- flags: { disposed: false, pendingSessionReset: false },
68
- getState: () => state,
69
- set: (patch) => Object.assign(state, patch),
70
- getPending: () => pending,
71
- enqueue: (text, options) => pending.push({ content: text, ...options }),
72
- });
73
- try {
74
- controller.scheduleGoalContinuation();
75
- await settleImmediate();
76
- assert.equal(pending.length, 0);
77
- state.busy = false;
78
- controller.onGoalTurnSettled('done');
79
- await settleImmediate();
80
- assert.equal(pending.length, 0);
81
- } finally {
82
- controller.disposeGoalContinuation();
83
- }
84
- });
@@ -1,134 +0,0 @@
1
- import test from 'node:test';
2
- import assert from 'node:assert/strict';
3
-
4
- import { createSessionOAuthFlowRegistry } from './oauth-flows.mjs';
5
-
6
- function deferred() {
7
- let resolve;
8
- let reject;
9
- const promise = new Promise((nextResolve, nextReject) => {
10
- resolve = nextResolve;
11
- reject = nextReject;
12
- });
13
- return { promise, resolve, reject };
14
- }
15
-
16
- async function settle() {
17
- await new Promise((resolve) => setTimeout(resolve, 0));
18
- }
19
-
20
- test('OAuth flow records null completion and rejection as terminal failures', async () => {
21
- const registry = createSessionOAuthFlowRegistry();
22
- const empty = deferred();
23
- const first = registry.register({ provider: 'openai-oauth', waitForCallback: empty.promise });
24
- empty.resolve(null);
25
- await settle();
26
- assert.deepEqual(
27
- { state: registry.status(first.flowId).state, error: registry.status(first.flowId).error },
28
- { state: 'failed', error: 'OAuth login did not complete.' },
29
- );
30
-
31
- const rejected = deferred();
32
- const second = registry.register({ provider: 'grok-oauth', waitForCallback: rejected.promise });
33
- rejected.reject(new Error('token exchange rejected'));
34
- await settle();
35
- assert.deepEqual(
36
- { state: registry.status(second.flowId).state, error: registry.status(second.flowId).error },
37
- { state: 'failed', error: 'token exchange rejected' },
38
- );
39
- registry.cancelAll();
40
- });
41
-
42
- test('OAuth flow cancellation remains queryable and duplicate provider login supersedes only the active flow', async () => {
43
- const registry = createSessionOAuthFlowRegistry();
44
- let cancelled = 0;
45
- const firstWait = deferred();
46
- const first = registry.register({
47
- provider: 'anthropic-oauth',
48
- waitForCallback: firstWait.promise,
49
- cancel: () => { cancelled += 1; firstWait.resolve(null); },
50
- });
51
- const secondWait = deferred();
52
- const second = registry.register({
53
- provider: 'anthropic-oauth',
54
- waitForCallback: secondWait.promise,
55
- cancel: () => { cancelled += 1; secondWait.resolve(null); },
56
- });
57
- await settle();
58
- assert.equal(registry.status(first.flowId).state, 'cancelled');
59
- assert.equal(registry.status(second.flowId).state, 'pending');
60
- assert.equal(cancelled, 1);
61
-
62
- await registry.cancel(second.flowId);
63
- await settle();
64
- assert.equal(registry.status(second.flowId).state, 'cancelled');
65
- assert.equal(cancelled, 2);
66
- registry.cancelAll();
67
- });
68
-
69
- test('OAuth flow expiry remains queryable and cancels provider work', async () => {
70
- const registry = createSessionOAuthFlowRegistry({ ttlMs: 5 });
71
- let cancelled = false;
72
- const waiting = deferred();
73
- const flow = registry.register({
74
- provider: 'cursor-oauth',
75
- waitForCallback: waiting.promise,
76
- cancel: () => { cancelled = true; waiting.resolve(null); },
77
- });
78
- await new Promise((resolve) => setTimeout(resolve, 20));
79
- const status = registry.status(flow.flowId);
80
- assert.equal(status.state, 'expired');
81
- assert.equal(status.error, 'OAuth login expired.');
82
- assert.equal(cancelled, true);
83
- registry.cancelAll();
84
- });
85
-
86
- test('manual OAuth completion is single-use and preserves its terminal result', async () => {
87
- const registry = createSessionOAuthFlowRegistry();
88
- const waiting = deferred();
89
- const flow = registry.register({
90
- provider: 'anthropic-oauth',
91
- waitForCallback: waiting.promise,
92
- completeCode: async (code) => {
93
- assert.equal(code, 'authorization-code');
94
- waiting.resolve({ access_token: 'saved' });
95
- return { access_token: 'saved' };
96
- },
97
- });
98
- const completed = await registry.complete(flow.flowId, 'authorization-code');
99
- assert.equal(completed.state, 'complete');
100
- await assert.rejects(
101
- registry.complete(flow.flowId, 'authorization-code'),
102
- /no longer pending/,
103
- );
104
- assert.equal(registry.status(flow.flowId).state, 'complete');
105
- registry.cancelAll();
106
- });
107
-
108
- test('manual OAuth completion cannot run twice or lose to its callback settling empty', async () => {
109
- const registry = createSessionOAuthFlowRegistry();
110
- const callback = deferred();
111
- const exchange = deferred();
112
- let exchanges = 0;
113
- const flow = registry.register({
114
- provider: 'anthropic-oauth',
115
- waitForCallback: callback.promise,
116
- completeCode: async () => {
117
- exchanges += 1;
118
- return exchange.promise;
119
- },
120
- });
121
-
122
- const first = registry.complete(flow.flowId, 'authorization-code');
123
- await assert.rejects(
124
- registry.complete(flow.flowId, 'authorization-code'),
125
- /already being completed/,
126
- );
127
- callback.resolve(null);
128
- await settle();
129
- assert.equal(registry.status(flow.flowId).state, 'pending');
130
- exchange.resolve(true);
131
- assert.equal((await first).state, 'complete');
132
- assert.equal(exchanges, 1);
133
- registry.cancelAll();
134
- });
@@ -1,46 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import test from 'node:test';
3
-
4
- import { mergePromptContents, promptDisplayText } from './queue-helpers.mjs';
5
-
6
- test('merging keeps an externalized single text part as a parts array', () => {
7
- // Prompts over the attachment externalization threshold arrive as
8
- // [{ type:'text', attachmentRef, sizeBytes }] with NO inline .text.
9
- // Collapsing that part to `.text` returned undefined and the turn ran with
10
- // an invisible prompt (silent empty worker turns on long agent briefs).
11
- const ref = {
12
- type: 'text',
13
- attachmentRef: 'a'.repeat(64),
14
- sizeBytes: 1286,
15
- };
16
- const merged = mergePromptContents([{ content: [ref] }]);
17
- assert.deepEqual(merged, [ref]);
18
- });
19
-
20
- test('merging still collapses a single inline text part to a string', () => {
21
- assert.equal(mergePromptContents([{ content: 'plain prompt' }]), 'plain prompt');
22
- assert.equal(
23
- mergePromptContents([{ content: [{ type: 'text', text: 'inline part' }] }]),
24
- 'inline part',
25
- );
26
- });
27
-
28
- test('merging joins mixed inline and externalized parts without dropping refs', () => {
29
- const ref = { type: 'text', attachmentRef: 'b'.repeat(64), sizeBytes: 900 };
30
- const merged = mergePromptContents([
31
- { content: 'first' },
32
- { content: [ref] },
33
- ]);
34
- assert.ok(Array.isArray(merged));
35
- assert.ok(merged.some((part) => part?.attachmentRef === ref.attachmentRef));
36
- assert.ok(merged.some((part) => part?.text === 'first'));
37
- });
38
-
39
- test('empty display text falls back to structured attachment content', () => {
40
- assert.equal(
41
- promptDisplayText([{ type: 'image', data: 'AA==', mimeType: 'image/png' }], {
42
- displayText: '',
43
- }),
44
- '[Image]',
45
- );
46
- });
@@ -1,108 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import test from 'node:test';
3
-
4
- import { createSessionApi } from './session-api.mjs';
5
- import {
6
- SESSION_CONFIGURE_ACTIONS,
7
- SESSION_READ_ACTIONS,
8
- } from '../../standalone/session-protocol.mjs';
9
-
10
- // The daemon resolves every session action by NAME on the object
11
- // createLocalSessionRuntime returns — this surface. An action that only exists
12
- // on the runtime beneath it passes the protocol allowlist and then dies in the
13
- // session runtime worker as "session action <name> is unavailable" (desktop
14
- // /inherit shipped exactly that way).
15
- function stubBag(overrides = {}) {
16
- const defaults = {
17
- flags: {},
18
- autoClearState: {},
19
- pending: [],
20
- listeners: new Set(),
21
- };
22
- return new Proxy({}, {
23
- get: (_target, key) => {
24
- if (key in overrides) return overrides[key];
25
- if (key in defaults) return defaults[key];
26
- return () => ({});
27
- },
28
- has: () => true,
29
- });
30
- }
31
-
32
- test('every advertised session action exists on the session surface', () => {
33
- const api = createSessionApi(stubBag());
34
- const missing = [...SESSION_READ_ACTIONS, ...SESSION_CONFIGURE_ACTIONS]
35
- .filter((action) => typeof api[action] !== 'function');
36
- assert.deepEqual(missing, []);
37
- });
38
-
39
- test('extension editor actions are advertised and forwarded', async () => {
40
- const calls = [];
41
- let state = { commandBusy: false, stats: {} };
42
- const api = createSessionApi(stubBag({
43
- runtime: {
44
- getMcpServerConfig: (name) => {
45
- calls.push(['getMcpServerConfig', name]);
46
- return { name };
47
- },
48
- saveMcpServer: async (input) => {
49
- calls.push(['saveMcpServer', input]);
50
- return { name: input.name };
51
- },
52
- saveSkill: async (input) => {
53
- calls.push(['saveSkill', input]);
54
- return { skill: { name: input.name } };
55
- },
56
- },
57
- getState: () => state,
58
- set: (patch) => { state = { ...state, ...patch }; },
59
- routeState: () => ({}),
60
- }));
61
-
62
- assert.ok(SESSION_READ_ACTIONS.includes('getMcpServerConfig'));
63
- assert.ok(SESSION_CONFIGURE_ACTIONS.includes('saveMcpServer'));
64
- assert.ok(SESSION_CONFIGURE_ACTIONS.includes('saveSkill'));
65
- assert.deepEqual(api.getMcpServerConfig('UnityMCP'), { name: 'UnityMCP' });
66
- await api.saveMcpServer({ name: 'UnityMCP' });
67
- await api.saveSkill({ name: 'unity-helper' });
68
- assert.deepEqual(calls, [
69
- ['getMcpServerConfig', 'UnityMCP'],
70
- ['saveMcpServer', { name: 'UnityMCP' }],
71
- ['saveSkill', { name: 'unity-helper' }],
72
- ]);
73
- });
74
-
75
- test('inheritFrom carries the conversation and rebuilds the heir transcript', async () => {
76
- const carried = [
77
- { role: 'system', content: 'target system prompt' },
78
- { role: 'user', content: 'first question' },
79
- { role: 'assistant', content: 'first answer' },
80
- ];
81
- let state = { sessionId: 'sess_heir', stats: {}, items: [] };
82
- const calls = [];
83
- const api = createSessionApi(stubBag({
84
- runtime: {
85
- inheritFrom: (sourceSessionId) => {
86
- calls.push(sourceSessionId);
87
- return { sessionId: 'sess_heir', sourceSessionId, messages: 2 };
88
- },
89
- readModelMessages: () => ({ messageCount: carried.length, messages: carried }),
90
- },
91
- getState: () => state,
92
- set: (patch) => { state = { ...state, ...patch }; },
93
- replaceItems: (items) => items,
94
- routeState: () => ({}),
95
- }));
96
-
97
- const result = await api.inheritFrom('sess_source');
98
-
99
- assert.deepEqual(calls, ['sess_source']);
100
- assert.equal(result.messages, 2);
101
- assert.equal(state.sessionId, 'sess_heir');
102
- // Only the conversation travels: the target's own system block never becomes
103
- // a transcript item.
104
- assert.deepEqual(
105
- state.items.map((item) => [item.kind, item.text]),
106
- [['user', 'first question'], ['assistant', 'first answer']],
107
- );
108
- });
@@ -1,80 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import test from 'node:test';
3
-
4
- import { SPINNER_MODE_OVERRIDE_VERBS } from '../spinner-verbs.mjs';
5
- import { createSessionApiA } from './session-api.mjs';
6
-
7
- function createHarness({ enqueueResult = true } = {}) {
8
- let state = {
9
- busy: true,
10
- commandBusy: false,
11
- };
12
- let interruptCount = 0;
13
- const queued = [];
14
- const api = createSessionApiA({
15
- runtime: {
16
- interruptTaskWait(reason) {
17
- assert.equal(reason, 'user-message');
18
- interruptCount += 1;
19
- },
20
- },
21
- nextId: () => `submission_${queued.length + 1}`,
22
- flags: { autoClearRunning: false },
23
- pending: [],
24
- listeners: new Set(),
25
- getState: () => state,
26
- getPublishedState: () => state,
27
- set: (patch) => { state = { ...state, ...patch }; },
28
- flushEmitImmediate() {},
29
- pushItem() {},
30
- patchItem() {},
31
- replaceItems: (items) => items,
32
- restoreOlderTranscript() {},
33
- restoreNewerTranscript() {},
34
- settleStreamingTail() {},
35
- clearStreamingTail() {},
36
- pushNotice() {},
37
- autoClearState: {},
38
- agentStatusState: () => ({}),
39
- routeState: () => ({}),
40
- syncContextStats() {},
41
- denyAllToolApprovals() {},
42
- updateAgentJobCard() {},
43
- requeueEntriesFront() {},
44
- enqueue(text, options) {
45
- queued.push({ text, options });
46
- return enqueueResult;
47
- },
48
- autoClearBeforeSubmit: async () => {},
49
- restoreQueued() {},
50
- prioritizeQueued() {},
51
- resetStatsAndSyncContext() {},
52
- drain() {},
53
- flushDeferredExecutionPendingResumeKick() {},
54
- discardExecutionPendingResume() {},
55
- });
56
- return {
57
- api,
58
- queued,
59
- interruptCount: () => interruptCount,
60
- };
61
- }
62
-
63
- test('accepted user input wakes an active task wait', () => {
64
- const harness = createHarness();
65
-
66
- assert.equal(harness.api.submit('새 지시'), true);
67
- assert.equal(harness.queued.length, 1);
68
- assert.equal(harness.interruptCount(), 1);
69
- });
70
-
71
- test('rejected user input does not wake a task wait', () => {
72
- const harness = createHarness({ enqueueResult: false });
73
-
74
- assert.equal(harness.api.submit('중복 지시'), false);
75
- assert.equal(harness.interruptCount(), 0);
76
- });
77
-
78
- test('task wait spinner has the dedicated waiting label', () => {
79
- assert.equal(SPINNER_MODE_OVERRIDE_VERBS['task-wait'], '작업 대기 중');
80
- });
@@ -1,131 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import test from 'node:test';
3
-
4
- import {
5
- aggregateToolMembers,
6
- failureDetailText,
7
- shellCommandExitCode,
8
- toolCallOutcome,
9
- } from './tool-result-status.mjs';
10
- import {
11
- deriveToolOutcomeTone,
12
- displayTerminalStatus,
13
- shellDisplayStatus,
14
- } from '../../runtime/shared/tool-card-model.mjs';
15
-
16
- // Outcome taxonomy contract (user report: "Exit 0" rendered as if failed):
17
- // - exit 0 → plain success ("Ok" bucket, success tone)
18
- // - non-zero exit → command failure (warning tone, never red)
19
- // - envelope isError → real call failure ("Failed", red)
20
-
21
- test('exit 0 is a plain success, never the Exit bucket', () => {
22
- const rawText = '[exit code: 0]\nall good';
23
- assert.equal(shellCommandExitCode(rawText), 0);
24
- assert.deepEqual(toolCallOutcome({ isError: false }, rawText), {
25
- isCallError: false,
26
- isExitError: false,
27
- exitCode: 0,
28
- });
29
- });
30
-
31
- test('a recognized exit 0 wins over a provider error envelope', () => {
32
- const outcome = toolCallOutcome({ isError: true }, '[exit code: 0]\nnoise on stderr');
33
- assert.equal(outcome.isCallError, false);
34
- assert.equal(outcome.isExitError, false);
35
- });
36
-
37
- test('non-zero exit is a command failure, not a call error', () => {
38
- assert.deepEqual(toolCallOutcome({ isError: true }, '[exit code: 2]\nboom'), {
39
- isCallError: false,
40
- isExitError: true,
41
- exitCode: 2,
42
- });
43
- });
44
-
45
- test('offloaded shell previews retain exit classification', () => {
46
- const rawText = `[tool output offloaded: shell → C:/safe/result.txt (60 KB, 900 lines, sha256 ${'a'.repeat(64)})]\n\n[exit code: 2]\nboom`;
47
- assert.equal(shellCommandExitCode(rawText), 2);
48
- assert.deepEqual(toolCallOutcome({ isError: false }, rawText), {
49
- isCallError: false,
50
- isExitError: true,
51
- exitCode: 2,
52
- });
53
- });
54
-
55
- test('recognized no-match is a successful completed probe', () => {
56
- const rawText = '[exit code: 1]\n[outcome: no-match]\n[completed: shell executed the command]\n\n(no output)';
57
- assert.deepEqual(toolCallOutcome({ isError: true }, rawText), {
58
- isCallError: false,
59
- isExitError: false,
60
- exitCode: 1,
61
- });
62
- });
63
-
64
- test('timeout/signal results never classify as a plain command exit', () => {
65
- assert.equal(shellCommandExitCode('[timeout: 5000ms signal: SIGKILL]\n[exit code: 1]'), null);
66
- const outcome = toolCallOutcome({ isError: true }, '[signal: SIGTERM]\nkilled');
67
- assert.equal(outcome.isCallError, true);
68
- assert.equal(outcome.isExitError, false);
69
- });
70
-
71
- test('provider envelope error without an exit header is a call failure', () => {
72
- const outcome = toolCallOutcome({ isError: true }, 'Error: transport failed');
73
- assert.equal(outcome.isCallError, true);
74
- assert.equal(outcome.isExitError, false);
75
- });
76
-
77
- test('read-only navigation misses stay neutral even with an error envelope', () => {
78
- const rawText = 'Error: no such path C:\\Users\\missing\\.mixdog\\.';
79
- assert.deepEqual(toolCallOutcome({ isError: true, toolName: 'find' }, rawText), {
80
- isCallError: false,
81
- isExitError: false,
82
- exitCode: null,
83
- });
84
- assert.equal(toolCallOutcome(
85
- { isError: true, toolName: 'read' },
86
- 'Error: EACCES: permission denied, open C:\\private.txt',
87
- ).isCallError, true);
88
- });
89
-
90
- test('failure detail keeps Ok / Failed / command-failure buckets distinct', () => {
91
- assert.equal(failureDetailText({ succeeded: 1, realErrors: 1, exitErrors: 1, exitCode: 3 }), '1 Ok · 1 Failed · 1 Exited non-zero');
92
- assert.equal(failureDetailText({ succeeded: 0, realErrors: 0, exitErrors: 1, exitCode: 3 }), 'Exited 3');
93
- // Exit 0 no longer feeds exitErrors, so an all-success group is pure Ok.
94
- assert.equal(failureDetailText({ succeeded: 2, realErrors: 0, exitErrors: 0 }), '2 Ok');
95
- });
96
-
97
- test('shared TUI/desktop tone keeps command failures warning and tool failures red', () => {
98
- assert.equal(shellDisplayStatus({ exitFailedCount: 1 }), 'exit');
99
- assert.equal(displayTerminalStatus('exit'), 'Exited');
100
- assert.equal(deriveToolOutcomeTone({ terminalStatus: 'exit', exitFailedCount: 1 }), 'warning');
101
- assert.equal(deriveToolOutcomeTone({ terminalStatus: 'failed', callFailedCount: 1 }), 'error');
102
- });
103
-
104
- test('aggregate members preserve atomic tool identity, inputs, outputs, and order', () => {
105
- const members = aggregateToolMembers([
106
- {
107
- callId: 'call-read',
108
- name: 'read',
109
- args: { file_path: 'a.ts' },
110
- resultText: 'source',
111
- resolved: true,
112
- isError: false,
113
- },
114
- {
115
- callId: 'call-shell',
116
- name: 'shell',
117
- args: { command: 'exit 2' },
118
- resultText: 'boom',
119
- rawResultText: '[exit code: 2]\nboom',
120
- resolved: true,
121
- isError: false,
122
- isExitError: true,
123
- },
124
- ]);
125
- assert.deepEqual(members.map(({ id, name, args, result, rawResult, exitErrorCount }) => ({
126
- id, name, args, result, rawResult, exitErrorCount,
127
- })), [
128
- { id: 'call-read', name: 'read', args: { file_path: 'a.ts' }, result: 'source', rawResult: 'source', exitErrorCount: 0 },
129
- { id: 'call-shell', name: 'shell', args: { command: 'exit 2' }, result: 'boom', rawResult: '[exit code: 2]\nboom', exitErrorCount: 1 },
130
- ]);
131
- });
@@ -1,104 +0,0 @@
1
- // session-pending-messages.json is SHARED between the TUI steering mirror and
2
- // the runtime/manager pending-message spool. Every TUI write passes the whole
3
- // store through normalizePendingStore, so these tests pin the invariant that a
4
- // TUI write is lossless for foreign rows — including the handoffAt/handoffPid
5
- // parking stamp that lets accepted user input survive an owner crash — and
6
- // that orphan cleanup only reaps TUI-owned (`tui_`) buckets.
7
- import assert from 'node:assert/strict';
8
- import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
9
- import { tmpdir } from 'node:os';
10
- import { join } from 'node:path';
11
- import test from 'node:test';
12
-
13
- const dataDir = mkdtempSync(join(tmpdir(), 'mixdog-tui-steering-persist-'));
14
- mkdirSync(dataDir, { recursive: true });
15
- process.env.MIXDOG_DATA_DIR = dataDir;
16
-
17
- const {
18
- appendTuiSteeringPersist,
19
- drainTuiSteeringPersist,
20
- flushTuiSteeringPersist,
21
- } = await import('./tui-steering-persist.mjs');
22
-
23
- const spoolPath = join(dataDir, 'session-pending-messages.json');
24
- const readSpool = () => JSON.parse(readFileSync(spoolPath, 'utf8'));
25
-
26
- // Older than the TUI restore TTL (30m) and than the runtime orphan window, so
27
- // the pre-fix orphan sweep would have reaped this whole bucket.
28
- const OLD_AT = Date.now() - (10 * 24 * 60 * 60 * 1000);
29
- // Runtime-shaped rows: a parked structured row (handoffAt/handoffPid +
30
- // content array + options) and a completion-notification row.
31
- const foreignRows = [
32
- {
33
- id: 'pm_structured_1',
34
- content: [
35
- { type: 'text', text: 'look at this shot' },
36
- { type: 'image', data: 'ZmFrZS1pbWFnZQ==', mimeType: 'image/png' },
37
- ],
38
- text: 'look at this shot',
39
- enqueuedAt: OLD_AT,
40
- handoffAt: OLD_AT,
41
- handoffPid: 4242,
42
- options: { mode: 'user', priority: 'next', displayText: 'look at this shot' },
43
- },
44
- {
45
- id: 'pm_notification_2',
46
- message: 'agent task finished',
47
- enqueuedAt: OLD_AT,
48
- notificationKind: 'completion_notification',
49
- executionId: 'exec_7',
50
- },
51
- ];
52
-
53
- writeFileSync(spoolPath, `${JSON.stringify({
54
- version: 1,
55
- updatedAt: OLD_AT,
56
- sessions: {
57
- sess_runtime_owner: foreignRows,
58
- tui_staleother: [{ id: 'ts_old', text: 'old steering', at: OLD_AT }],
59
- },
60
- sessionTouchedAt: { sess_runtime_owner: OLD_AT, tui_staleother: OLD_AT },
61
- }, null, 2)}\n`, { mode: 0o600 });
62
-
63
- test.after(() => {
64
- try { rmSync(dataDir, { recursive: true, force: true }); } catch { /* temp dir */ }
65
- });
66
-
67
- test('a TUI steering append round-trips foreign runtime spool rows losslessly', async () => {
68
- await appendTuiSteeringPersist('leadsessionone', { text: 'steer me' });
69
- await flushTuiSteeringPersist();
70
-
71
- const store = readSpool();
72
- // Every field of every foreign row survives the TUI write untouched.
73
- assert.deepEqual(store.sessions.sess_runtime_owner, foreignRows);
74
- const parked = store.sessions.sess_runtime_owner[0];
75
- assert.equal(parked.handoffAt, OLD_AT);
76
- assert.equal(parked.handoffPid, 4242);
77
- assert.equal(parked.id, 'pm_structured_1');
78
- assert.equal(parked.enqueuedAt, OLD_AT);
79
- assert.deepEqual(parked.options, { mode: 'user', priority: 'next', displayText: 'look at this shot' });
80
- assert.equal(Array.isArray(parked.content), true);
81
- assert.equal(parked.content[1].mimeType, 'image/png');
82
- assert.equal(store.sessions.sess_runtime_owner[1].notificationKind, 'completion_notification');
83
- assert.equal(store.sessions.sess_runtime_owner[1].executionId, 'exec_7');
84
- // A foreign session's touch stamp is carried, never refreshed by our write.
85
- assert.equal(store.sessionTouchedAt.sess_runtime_owner, OLD_AT);
86
-
87
- const steering = store.sessions.tui_leadsessionone;
88
- assert.equal(Array.isArray(steering), true);
89
- assert.equal(steering.length, 1);
90
- assert.equal(steering[0].text, 'steer me');
91
- });
92
-
93
- test('drain reaps only stale tui_ buckets and leaves foreign spool rows in place', async () => {
94
- const drained = await drainTuiSteeringPersist('leadsessionone');
95
- assert.deepEqual(drained.map((row) => row.text), ['steer me']);
96
-
97
- const store = readSpool();
98
- assert.deepEqual(store.sessions.sess_runtime_owner, foreignRows);
99
- assert.equal(store.sessionTouchedAt.sess_runtime_owner, OLD_AT);
100
- // Own bucket drained, other TUI lead session's stale bucket pruned.
101
- assert.equal(store.sessions.tui_leadsessionone, undefined);
102
- assert.equal(store.sessions.tui_staleother, undefined);
103
- assert.equal(store.sessionTouchedAt.tui_staleother, undefined);
104
- });