mixdog 0.9.63 → 0.9.65

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 (408) hide show
  1. package/README.md +3 -0
  2. package/package.json +9 -2
  3. package/scripts/code-graph-description-contract.mjs +3 -3
  4. package/scripts/verify-release-assets.mjs +2 -2
  5. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch.mjs +11 -14
  6. package/src/runtime/agent/orchestrator/agent-runtime/agent-progress-watchdog.mjs +6 -6
  7. package/src/runtime/agent/orchestrator/agent-runtime/cache-strategy.mjs +2 -2
  8. package/src/runtime/agent/orchestrator/agent-trace-format.mjs +1 -0
  9. package/src/runtime/agent/orchestrator/config.mjs +19 -124
  10. package/src/runtime/agent/orchestrator/context/collect.mjs +6 -6
  11. package/src/runtime/agent/orchestrator/dispatch-persist.mjs +2 -2
  12. package/src/runtime/agent/orchestrator/internal-agents.mjs +2 -2
  13. package/src/runtime/agent/orchestrator/mcp/child-tree.mjs +1 -1
  14. package/src/runtime/agent/orchestrator/mcp/client.mjs +4 -4
  15. package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +2 -2
  16. package/src/runtime/agent/orchestrator/providers/anthropic-betas.mjs +4 -4
  17. package/src/runtime/agent/orchestrator/providers/anthropic-effort.mjs +2 -2
  18. package/src/runtime/agent/orchestrator/providers/anthropic-max-tokens.mjs +4 -4
  19. package/src/runtime/agent/orchestrator/providers/anthropic-messages.mjs +333 -0
  20. package/src/runtime/agent/orchestrator/providers/anthropic-model-resolve.mjs +2 -2
  21. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-credentials.mjs +4 -4
  22. package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +1 -1
  23. package/src/runtime/agent/orchestrator/providers/anthropic.mjs +3 -277
  24. package/src/runtime/agent/orchestrator/providers/codex-client-meta.mjs +2 -2
  25. package/src/runtime/agent/orchestrator/providers/custom-tool-wire.mjs +1 -1
  26. package/src/runtime/agent/orchestrator/providers/gemini-cache.mjs +2 -2
  27. package/src/runtime/agent/orchestrator/providers/gemini-stream.mjs +6 -6
  28. package/src/runtime/agent/orchestrator/providers/grok-oauth-login.mjs +196 -0
  29. package/src/runtime/agent/orchestrator/providers/grok-oauth-tokens.mjs +460 -0
  30. package/src/runtime/agent/orchestrator/providers/grok-oauth.mjs +14 -593
  31. package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +1 -1
  32. package/src/runtime/agent/orchestrator/providers/media-normalization.mjs +1 -1
  33. package/src/runtime/agent/orchestrator/providers/openai-compat-wire.mjs +1 -1
  34. package/src/runtime/agent/orchestrator/providers/openai-compat-xai.mjs +4 -4
  35. package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +2 -2
  36. package/src/runtime/agent/orchestrator/providers/openai-oauth.mjs +5 -280
  37. package/src/runtime/agent/orchestrator/providers/openai-responses-payload.mjs +357 -0
  38. package/src/runtime/agent/orchestrator/providers/openai-ws-headers.mjs +216 -0
  39. package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +2 -188
  40. package/src/runtime/agent/orchestrator/providers/openai-ws-stream.mjs +2 -2
  41. package/src/runtime/agent/orchestrator/providers/openai-ws.mjs +2 -2
  42. package/src/runtime/agent/orchestrator/providers/opencode-go.mjs +1 -1
  43. package/src/runtime/agent/orchestrator/providers/provider-catalog-cache.mjs +1 -1
  44. package/src/runtime/agent/orchestrator/providers/registry.mjs +1 -1
  45. package/src/runtime/agent/orchestrator/providers/retry-classifier.mjs +2 -2
  46. package/src/runtime/agent/orchestrator/providers/statusline-route-meta.mjs +1 -1
  47. package/src/runtime/agent/orchestrator/session/cache/prefetch-cache.mjs +1 -1
  48. package/src/runtime/agent/orchestrator/session/cache/scoped-cache.mjs +3 -3
  49. package/src/runtime/agent/orchestrator/session/compact/budget.mjs +2 -2
  50. package/src/runtime/agent/orchestrator/session/compact/file-reattach.mjs +2 -2
  51. package/src/runtime/agent/orchestrator/session/compact/summary-schema.mjs +1 -1
  52. package/src/runtime/agent/orchestrator/session/compact/summary.mjs +1 -1
  53. package/src/runtime/agent/orchestrator/session/compact/text-utils.mjs +2 -2
  54. package/src/runtime/agent/orchestrator/session/context-utils.mjs +4 -4
  55. package/src/runtime/agent/orchestrator/session/loop/deferred-call-through.mjs +1 -1
  56. package/src/runtime/agent/orchestrator/session/loop/pre-dispatch-deny.mjs +17 -0
  57. package/src/runtime/agent/orchestrator/session/loop/steering.mjs +1 -1
  58. package/src/runtime/agent/orchestrator/session/loop/stored-tool-args.mjs +18 -26
  59. package/src/runtime/agent/orchestrator/session/loop/termination.mjs +1 -1
  60. package/src/runtime/agent/orchestrator/session/loop/tool-classify.mjs +3 -3
  61. package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +1 -0
  62. package/src/runtime/agent/orchestrator/session/manager/context-meta.mjs +1 -1
  63. package/src/runtime/agent/orchestrator/session/manager/delivered-completions.mjs +1 -1
  64. package/src/runtime/agent/orchestrator/session/manager/status-telemetry.mjs +1 -1
  65. package/src/runtime/agent/orchestrator/session/store/live-state.mjs +49 -0
  66. package/src/runtime/agent/orchestrator/session/store/load-cache.mjs +49 -0
  67. package/src/runtime/agent/orchestrator/session/store/save-worker.mjs +260 -0
  68. package/src/runtime/agent/orchestrator/session/store/serialize.mjs +72 -0
  69. package/src/runtime/agent/orchestrator/session/store/summary-cache.mjs +163 -0
  70. package/src/runtime/agent/orchestrator/session/store/write-guards.mjs +1 -1
  71. package/src/runtime/agent/orchestrator/session/store-summary-index.mjs +1 -1
  72. package/src/runtime/agent/orchestrator/session/store-summary-reader.mjs +4 -1
  73. package/src/runtime/agent/orchestrator/session/store.mjs +9 -561
  74. package/src/runtime/agent/orchestrator/session/tool-envelope.mjs +1 -1
  75. package/src/runtime/agent/orchestrator/session/tool-result-offload.mjs +2 -2
  76. package/src/runtime/agent/orchestrator/stall-policy.mjs +11 -11
  77. package/src/runtime/agent/orchestrator/tools/bash-policy-scan.mjs +1 -1
  78. package/src/runtime/agent/orchestrator/tools/bash-session.mjs +2 -2
  79. package/src/runtime/agent/orchestrator/tools/builtin/advisory-lock.mjs +1 -1
  80. package/src/runtime/agent/orchestrator/tools/builtin/arg-guard.mjs +2 -2
  81. package/src/runtime/agent/orchestrator/tools/builtin/atomic-write.mjs +1 -1
  82. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +2 -154
  83. package/src/runtime/agent/orchestrator/tools/builtin/cache-layers.mjs +1 -1
  84. package/src/runtime/agent/orchestrator/tools/builtin/cwd-utils.mjs +1 -1
  85. package/src/runtime/agent/orchestrator/tools/builtin/fs-reachability.mjs +1 -1
  86. package/src/runtime/agent/orchestrator/tools/builtin/fuzzy-match.mjs +1 -1
  87. package/src/runtime/agent/orchestrator/tools/builtin/glob-walk.mjs +1 -1
  88. package/src/runtime/agent/orchestrator/tools/builtin/path-locks.mjs +1 -1
  89. package/src/runtime/agent/orchestrator/tools/builtin/path-utils.mjs +1 -1
  90. package/src/runtime/agent/orchestrator/tools/builtin/read-args.mjs +2 -2
  91. package/src/runtime/agent/orchestrator/tools/builtin/read-formatting.mjs +2 -3
  92. package/src/runtime/agent/orchestrator/tools/builtin/read-image-resize.mjs +4 -4
  93. package/src/runtime/agent/orchestrator/tools/builtin/read-open.mjs +1 -1
  94. package/src/runtime/agent/orchestrator/tools/builtin/read-streaming.mjs +1 -1
  95. package/src/runtime/agent/orchestrator/tools/builtin/rg-runner.mjs +2 -2
  96. package/src/runtime/agent/orchestrator/tools/builtin/search-path-diagnostics.mjs +5 -5
  97. package/src/runtime/agent/orchestrator/tools/builtin/shell-analysis.mjs +1 -1
  98. package/src/runtime/agent/orchestrator/tools/builtin/shell-job-paths.mjs +2 -2
  99. package/src/runtime/agent/orchestrator/tools/builtin/shell-job-process.mjs +2 -2
  100. package/src/runtime/agent/orchestrator/tools/builtin/shell-job-spawn.mjs +519 -0
  101. package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +5 -449
  102. package/src/runtime/agent/orchestrator/tools/builtin/snapshot-helpers.mjs +1 -1
  103. package/src/runtime/agent/orchestrator/tools/builtin/task-tool.mjs +212 -0
  104. package/src/runtime/agent/orchestrator/tools/builtin.mjs +1 -1
  105. package/src/runtime/agent/orchestrator/tools/code-graph/build.mjs +1 -7
  106. package/src/runtime/agent/orchestrator/tools/code-graph/disk-cache.mjs +9 -36
  107. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +15 -3
  108. package/src/runtime/agent/orchestrator/tools/code-graph/search-references.mjs +429 -0
  109. package/src/runtime/agent/orchestrator/tools/code-graph/search.mjs +2 -395
  110. package/src/runtime/agent/orchestrator/tools/code-graph/symbol-index.mjs +2 -2
  111. package/src/runtime/agent/orchestrator/tools/code-graph/text-mask.mjs +1 -1
  112. package/src/runtime/agent/orchestrator/tools/code-graph/trusted-roots.mjs +1 -1
  113. package/src/runtime/agent/orchestrator/tools/code-graph-prewarm-worker.mjs +1 -1
  114. package/src/runtime/agent/orchestrator/tools/code-graph-state.mjs +3 -3
  115. package/src/runtime/agent/orchestrator/tools/mutation-planner.mjs +5 -5
  116. package/src/runtime/agent/orchestrator/tools/next-call-utils.mjs +1 -1
  117. package/src/runtime/agent/orchestrator/tools/patch/dispatch.mjs +1 -1
  118. package/src/runtime/agent/orchestrator/tools/patch/matcher.mjs +7 -7
  119. package/src/runtime/agent/orchestrator/tools/patch/orchestrator.mjs +72 -9
  120. package/src/runtime/agent/orchestrator/tools/patch/parsing.mjs +4 -4
  121. package/src/runtime/agent/orchestrator/tools/patch/paths.mjs +1 -1
  122. package/src/runtime/agent/orchestrator/tools/patch/v4a-convert.mjs +1 -1
  123. package/src/runtime/agent/orchestrator/tools/patch-tool-defs.mjs +4 -4
  124. package/src/runtime/agent/orchestrator/tools/patch.mjs +1 -1
  125. package/src/runtime/agent/orchestrator/tools/result-compression.mjs +3 -3
  126. package/src/runtime/agent/orchestrator/tools/shell-command.mjs +2 -444
  127. package/src/runtime/agent/orchestrator/tools/shell-exec-output.mjs +505 -0
  128. package/src/runtime/agent/orchestrator/tools/shell-exec-policy.mjs +2 -2
  129. package/src/runtime/agent/orchestrator/tools/shell-snapshot.mjs +1 -1
  130. package/src/runtime/channels/lib/backend-dispatch.mjs +20 -5
  131. package/src/runtime/channels/lib/scheduler.mjs +1 -1
  132. package/src/runtime/channels/lib/telegram-format.mjs +1 -1
  133. package/src/runtime/channels/lib/voice-runtime-fetcher.mjs +4 -4
  134. package/src/runtime/channels/tool-defs.mjs +2 -3
  135. package/src/runtime/memory/index.mjs +1 -5
  136. package/src/runtime/memory/lib/core-memory-candidates.mjs +357 -0
  137. package/src/runtime/memory/lib/core-memory-store.mjs +7 -357
  138. package/src/runtime/memory/lib/cycle-signatures.mjs +1 -1
  139. package/src/runtime/memory/lib/embedding-model-config.mjs +1 -1
  140. package/src/runtime/memory/lib/embedding-provider.mjs +1 -5
  141. package/src/runtime/memory/lib/embedding-worker.mjs +1 -5
  142. package/src/runtime/memory/lib/ko-morph.mjs +2 -2
  143. package/src/runtime/memory/lib/memory-config-flags.mjs +2 -5
  144. package/src/runtime/memory/lib/memory-cycle-requests.mjs +3 -7
  145. package/src/runtime/memory/lib/memory-cycle1.mjs +4 -8
  146. package/src/runtime/memory/lib/memory-cycle2-gate.mjs +1 -1
  147. package/src/runtime/memory/lib/memory-cycle2-mutations.mjs +1 -1
  148. package/src/runtime/memory/lib/memory-cycle2-shared.mjs +2 -5
  149. package/src/runtime/memory/lib/memory-cycle3.mjs +1 -5
  150. package/src/runtime/memory/lib/memory-embed.mjs +2 -6
  151. package/src/runtime/memory/lib/memory-log.mjs +8 -0
  152. package/src/runtime/memory/lib/memory-ops-policy.mjs +4 -8
  153. package/src/runtime/memory/lib/memory-recall-scope-filter.mjs +1 -1
  154. package/src/runtime/memory/lib/memory-recall-store.mjs +2 -193
  155. package/src/runtime/memory/lib/memory-score.mjs +1 -1
  156. package/src/runtime/memory/lib/memory-text-utils.mjs +2 -2
  157. package/src/runtime/memory/lib/memory.mjs +2 -6
  158. package/src/runtime/memory/lib/pg/adapter.mjs +2 -6
  159. package/src/runtime/memory/lib/pg/process.mjs +1 -5
  160. package/src/runtime/memory/lib/pg/supervisor.mjs +1 -5
  161. package/src/runtime/memory/lib/recall-format.mjs +2 -2
  162. package/src/runtime/memory/lib/recall-scoring.mjs +195 -0
  163. package/src/runtime/memory/lib/runtime-fetcher.mjs +1 -5
  164. package/src/runtime/memory/lib/trace-store.mjs +2 -6
  165. package/src/runtime/search/lib/http-fetch.mjs +6 -6
  166. package/src/runtime/search/lib/web-tools.mjs +2 -2
  167. package/src/runtime/shared/buffered-appender.mjs +1 -1
  168. package/src/runtime/shared/child-guardian.mjs +1 -1
  169. package/src/runtime/shared/child-spawn-gate.mjs +1 -1
  170. package/src/runtime/shared/config.mjs +4 -4
  171. package/src/runtime/shared/launcher-control.mjs +9 -10
  172. package/src/runtime/shared/llm/index.mjs +5 -20
  173. package/src/runtime/shared/markdown-frontmatter.mjs +1 -1
  174. package/src/runtime/shared/memory-snapshot.mjs +4 -4
  175. package/src/runtime/shared/pristine-execution.mjs +1 -1
  176. package/src/runtime/shared/process-lifecycle.mjs +0 -1
  177. package/src/runtime/shared/process-shutdown.mjs +1 -1
  178. package/src/runtime/shared/resource-admission.mjs +2 -2
  179. package/src/runtime/shared/schedule-session-run.mjs +1 -1
  180. package/src/runtime/shared/schedules-db.mjs +1 -1
  181. package/src/runtime/shared/service-discovery.mjs +2 -2
  182. package/src/runtime/shared/staged-update.mjs +6 -6
  183. package/src/runtime/shared/tool-execution-contract.mjs +1 -1
  184. package/src/runtime/shared/tool-primitives.mjs +1 -1
  185. package/src/runtime/shared/tool-surface.mjs +2 -2
  186. package/src/runtime/shared/turn-snapshot.mjs +184 -0
  187. package/src/runtime/shared/update-checker.mjs +1 -1
  188. package/src/runtime/shared/user-cwd.mjs +3 -3
  189. package/src/runtime/shared/user-data-guard.mjs +4 -4
  190. package/src/runtime/shared/workspace-router.mjs +5 -5
  191. package/src/session-runtime/config-helpers.mjs +2 -3
  192. package/src/session-runtime/config-lifecycle.mjs +1 -1
  193. package/src/session-runtime/hitch-profile.mjs +1 -1
  194. package/src/session-runtime/lifecycle-api.mjs +6 -4
  195. package/src/session-runtime/model-recency.mjs +5 -5
  196. package/src/session-runtime/plugin-mcp.mjs +1 -1
  197. package/src/session-runtime/provider-request-snapshot.mjs +338 -0
  198. package/src/session-runtime/runtime-core.mjs +4 -0
  199. package/src/session-runtime/session-text.mjs +4 -4
  200. package/src/session-runtime/session-turn-api.mjs +7 -0
  201. package/src/session-runtime/tool-catalog-schema.mjs +197 -0
  202. package/src/session-runtime/tool-catalog.mjs +6 -483
  203. package/src/session-runtime/tool-defs.mjs +1 -1
  204. package/src/standalone/agent-task-status.mjs +1 -1
  205. package/src/standalone/agent-tool/helpers.mjs +2 -2
  206. package/src/standalone/channel-admin.mjs +4 -4
  207. package/src/standalone/explore-tool.mjs +3 -3
  208. package/src/standalone/hook-bus/config.mjs +1 -1
  209. package/src/standalone/hook-bus/constants.mjs +1 -1
  210. package/src/standalone/hook-bus/rules.mjs +1 -1
  211. package/src/standalone/projects.mjs +1 -1
  212. package/src/standalone/provider-admin.mjs +2 -2
  213. package/src/tui/App.jsx +1 -1
  214. package/src/tui/app/app-format.mjs +2 -2
  215. package/src/tui/app/clipboard.mjs +3 -3
  216. package/src/tui/app/input-parsers.mjs +1 -1
  217. package/src/tui/app/text-layout.mjs +1 -1
  218. package/src/tui/app/transcript-row-estimate.mjs +360 -0
  219. package/src/tui/app/transcript-window.mjs +5 -347
  220. package/src/tui/app/use-mouse-input.mjs +1 -1
  221. package/src/tui/app/use-prompt-handlers.mjs +1 -1
  222. package/src/tui/components/tool-execution/surface-detail.mjs +9 -9
  223. package/src/tui/components/tool-execution/text-format.mjs +2 -2
  224. package/src/tui/components/tool-output-format.mjs +7 -7
  225. package/src/tui/display-width.mjs +4 -4
  226. package/src/tui/dist/index.mjs +187 -99
  227. package/src/tui/engine/agent-envelope.mjs +5 -5
  228. package/src/tui/engine/live-share.mjs +100 -0
  229. package/src/tui/engine/notification-plan.mjs +1 -1
  230. package/src/tui/engine/queue-helpers.mjs +3 -3
  231. package/src/tui/engine/render-timing.mjs +4 -5
  232. package/src/tui/engine/session-api-ext.mjs +6 -3
  233. package/src/tui/engine/tool-result-status.mjs +5 -5
  234. package/src/tui/engine/tool-result-text.mjs +1 -1
  235. package/src/tui/engine/transcript-spill.mjs +585 -0
  236. package/src/tui/engine/tui-steering-persist.mjs +1 -1
  237. package/src/tui/engine.mjs +29 -474
  238. package/src/tui/lib/voice-setup.mjs +1 -1
  239. package/src/tui/markdown/format-token.mjs +1 -1
  240. package/src/tui/markdown/render-ansi.mjs +1 -1
  241. package/src/tui/markdown/table-layout.mjs +4 -4
  242. package/src/tui/paste-attachments.mjs +1 -1
  243. package/src/tui/prompt-history-store.mjs +3 -3
  244. package/src/tui/statusline-ansi-bridge.mjs +2 -2
  245. package/src/tui/theme.mjs +1 -1
  246. package/src/tui/transcript-tool-failures.mjs +2 -2
  247. package/src/ui/ansi.mjs +0 -9
  248. package/src/ui/statusline-format.mjs +2 -4
  249. package/scripts/_bench-cwc.json +0 -20
  250. package/scripts/_jitter-fuzz.jsx +0 -42
  251. package/scripts/_jitter-fuzz2.jsx +0 -30
  252. package/scripts/_jitter-probe.jsx +0 -35
  253. package/scripts/_jp2.jsx +0 -16
  254. package/scripts/_smoke_wd.mjs +0 -7
  255. package/scripts/abort-recovery-test.mjs +0 -175
  256. package/scripts/agent-dispatch-abort-compose-test.mjs +0 -31
  257. package/scripts/agent-live-arg-guard-smoke.mjs +0 -20
  258. package/scripts/agent-live-path-suffix-smoke.mjs +0 -34
  259. package/scripts/agent-live-toolcall-args-smoke.mjs +0 -45
  260. package/scripts/agent-loop-policy-test.mjs +0 -37
  261. package/scripts/agent-model-liveness-test.mjs +0 -763
  262. package/scripts/agent-parallel-smoke.mjs +0 -435
  263. package/scripts/agent-route-batch-test.mjs +0 -40
  264. package/scripts/agent-tag-reuse-smoke.mjs +0 -441
  265. package/scripts/agent-terminal-reap-test.mjs +0 -252
  266. package/scripts/agent-trace-io-test.mjs +0 -133
  267. package/scripts/ansi-color-capability-test.mjs +0 -90
  268. package/scripts/anthropic-admission-retry-integration-test.mjs +0 -119
  269. package/scripts/anthropic-maxtokens-test.mjs +0 -119
  270. package/scripts/anthropic-oauth-refresh-race-test.mjs +0 -397
  271. package/scripts/anthropic-transport-policy-test.mjs +0 -726
  272. package/scripts/apply-patch-edit-smoke.mjs +0 -71
  273. package/scripts/arg-guard-test.mjs +0 -93
  274. package/scripts/async-notify-settlement-test.mjs +0 -99
  275. package/scripts/atomic-lock-tryonce-test.mjs +0 -125
  276. package/scripts/background-task-meta-smoke.mjs +0 -38
  277. package/scripts/bench-run.mjs +0 -508
  278. package/scripts/boot-smoke.mjs +0 -137
  279. package/scripts/build-runtime-windows.ps1 +0 -242
  280. package/scripts/channel-daemon-smoke.mjs +0 -1103
  281. package/scripts/code-graph-aggregate-cwd-test.mjs +0 -158
  282. package/scripts/code-graph-disk-hit-test.mjs +0 -290
  283. package/scripts/code-graph-dispatch-test.mjs +0 -96
  284. package/scripts/code-graph-root-federation-test.mjs +0 -273
  285. package/scripts/compact-active-turn-test.mjs +0 -68
  286. package/scripts/compact-file-reattach-test.mjs +0 -88
  287. package/scripts/compact-pressure-test.mjs +0 -788
  288. package/scripts/compact-prior-context-flatten-test.mjs +0 -252
  289. package/scripts/compact-recall-digest-test.mjs +0 -57
  290. package/scripts/compact-smoke.mjs +0 -1017
  291. package/scripts/compact-trigger-migration-smoke.mjs +0 -261
  292. package/scripts/compacted-placeholder-scrub-test.mjs +0 -63
  293. package/scripts/context-mcp-metering-test.mjs +0 -1406
  294. package/scripts/debounced-skills-async-save-test.mjs +0 -57
  295. package/scripts/deferred-tool-loading-test.mjs +0 -250
  296. package/scripts/desktop-session-bridge-test.mjs +0 -1013
  297. package/scripts/dispatch-persist-recovery-test.mjs +0 -141
  298. package/scripts/embedding-worker-exit-test.mjs +0 -76
  299. package/scripts/execution-completion-dedup-test.mjs +0 -205
  300. package/scripts/execution-pending-resume-kick-test.mjs +0 -151
  301. package/scripts/execution-resume-esc-integration-test.mjs +0 -176
  302. package/scripts/explore-bench-tmp.mjs +0 -36
  303. package/scripts/explore-bench.mjs +0 -248
  304. package/scripts/explore-prompt-policy-test.mjs +0 -256
  305. package/scripts/explore-timeout-cancel-test.mjs +0 -345
  306. package/scripts/find-fuzzy-hidden-test.mjs +0 -267
  307. package/scripts/forwarder-rebind-tail-test.mjs +0 -67
  308. package/scripts/freevar-smoke.mjs +0 -98
  309. package/scripts/gemini-provider-test.mjs +0 -1448
  310. package/scripts/generate-oc-icons.mjs +0 -11
  311. package/scripts/grok-oauth-refresh-race-test.mjs +0 -273
  312. package/scripts/headless-pristine-execution-test.mjs +0 -614
  313. package/scripts/hook-bus-test.mjs +0 -552
  314. package/scripts/ingest-pure-conversation-smoke.mjs +0 -175
  315. package/scripts/internal-comms-bench-test.mjs +0 -226
  316. package/scripts/internal-comms-bench.mjs +0 -853
  317. package/scripts/internal-comms-smoke.mjs +0 -277
  318. package/scripts/internal-tools-normalization-test.mjs +0 -62
  319. package/scripts/interrupted-turn-history-test.mjs +0 -399
  320. package/scripts/lead-workflow-smoke.mjs +0 -592
  321. package/scripts/lifecycle-api-test.mjs +0 -137
  322. package/scripts/live-share-test.mjs +0 -148
  323. package/scripts/live-worker-smoke.mjs +0 -333
  324. package/scripts/log-writer-guard-smoke.mjs +0 -131
  325. package/scripts/maintenance-default-routes-test.mjs +0 -164
  326. package/scripts/max-output-recovery-persist-test.mjs +0 -81
  327. package/scripts/max-output-recovery-test.mjs +0 -368
  328. package/scripts/mcp-client-normalization-test.mjs +0 -45
  329. package/scripts/mcp-grace-deferred-test.mjs +0 -225
  330. package/scripts/memory-core-input-test.mjs +0 -167
  331. package/scripts/memory-cycle-routing-test.mjs +0 -111
  332. package/scripts/memory-meta-concurrency-test.mjs +0 -20
  333. package/scripts/memory-pg-recovery-test.mjs +0 -59
  334. package/scripts/memory-rule-contract-test.mjs +0 -93
  335. package/scripts/model-list-sanitize-test.mjs +0 -37
  336. package/scripts/mouse-tracking-restore-smoke.mjs +0 -107
  337. package/scripts/native-edit-wire-test.mjs +0 -152
  338. package/scripts/notify-completion-mirror-test.mjs +0 -73
  339. package/scripts/openai-oauth-refresh-race-test.mjs +0 -120
  340. package/scripts/openai-oauth-ws-1006-retry-test.mjs +0 -954
  341. package/scripts/openai-ws-early-settle-test.mjs +0 -216
  342. package/scripts/output-style-bench.mjs +0 -292
  343. package/scripts/output-style-smoke.mjs +0 -145
  344. package/scripts/parent-abort-link-test.mjs +0 -90
  345. package/scripts/patch-binary-cache-test.mjs +0 -181
  346. package/scripts/path-suffix-test.mjs +0 -57
  347. package/scripts/pending-completion-drop-test.mjs +0 -239
  348. package/scripts/pending-messages-lock-nonblocking-test.mjs +0 -62
  349. package/scripts/pretool-ask-runtime-test.mjs +0 -54
  350. package/scripts/process-lifecycle-test.mjs +0 -461
  351. package/scripts/prompt-immediate-render-test.mjs +0 -89
  352. package/scripts/prompt-input-parity-test.mjs +0 -145
  353. package/scripts/provider-admission-scheduler-test.mjs +0 -681
  354. package/scripts/provider-contract-test.mjs +0 -632
  355. package/scripts/provider-stream-stall-test.mjs +0 -276
  356. package/scripts/provider-toolcall-test.mjs +0 -3063
  357. package/scripts/reactive-compact-persist-smoke.mjs +0 -203
  358. package/scripts/recall-bench.mjs +0 -359
  359. package/scripts/resource-admission-test.mjs +0 -792
  360. package/scripts/result-classification-test.mjs +0 -75
  361. package/scripts/rg-runner-test.mjs +0 -240
  362. package/scripts/routing-corpus-test.mjs +0 -349
  363. package/scripts/sanitize-tool-pairs-test.mjs +0 -260
  364. package/scripts/session-bench-cache-break-test.mjs +0 -102
  365. package/scripts/session-bench.mjs +0 -1708
  366. package/scripts/session-context-bench.mjs +0 -344
  367. package/scripts/session-heartbeat-lifecycle-test.mjs +0 -68
  368. package/scripts/session-ingest-compaction-smoke.mjs +0 -279
  369. package/scripts/session-ingest-smoke.mjs +0 -177
  370. package/scripts/session-orphan-sweep-test.mjs +0 -109
  371. package/scripts/set-effort-config-test.mjs +0 -41
  372. package/scripts/shell-failure-diagnostics-test.mjs +0 -280
  373. package/scripts/shell-hardening-test.mjs +0 -209
  374. package/scripts/shell-jobs-windows-hide-test.mjs +0 -164
  375. package/scripts/ship-mode-test.mjs +0 -98
  376. package/scripts/smoke-loop-failure-summary-test.mjs +0 -38
  377. package/scripts/smoke-loop-failure-summary.mjs +0 -16
  378. package/scripts/smoke-loop-report.mjs +0 -221
  379. package/scripts/smoke-loop.mjs +0 -202
  380. package/scripts/smoke-runtime-negative.ps1 +0 -106
  381. package/scripts/statusline-quota-hysteresis-test.mjs +0 -62
  382. package/scripts/steering-drain-buckets-test.mjs +0 -467
  383. package/scripts/steering-fold-provenance-test.mjs +0 -71
  384. package/scripts/streaming-tail-window-test.mjs +0 -175
  385. package/scripts/submit-commandbusy-race-test.mjs +0 -257
  386. package/scripts/task-bench.mjs +0 -205
  387. package/scripts/terminal-bench-isolation-guards-test.mjs +0 -102
  388. package/scripts/termio-input-smoke.mjs +0 -199
  389. package/scripts/tool-result-hook-test.mjs +0 -48
  390. package/scripts/tool-smoke.mjs +0 -2453
  391. package/scripts/tool-tui-presentation-test.mjs +0 -286
  392. package/scripts/toolcall-args-test.mjs +0 -239
  393. package/scripts/tui-ambiguous-width-test.mjs +0 -113
  394. package/scripts/tui-background-failure-smoke.mjs +0 -73
  395. package/scripts/tui-perf-run.ps1 +0 -26
  396. package/scripts/tui-render-smoke.mjs +0 -90
  397. package/scripts/tui-runtime-load-bench-entry.jsx +0 -608
  398. package/scripts/tui-runtime-load-bench.mjs +0 -50
  399. package/scripts/tui-store-frame-batch-test.mjs +0 -99
  400. package/scripts/tui-transcript-jitter-harness-entry.jsx +0 -383
  401. package/scripts/tui-transcript-perf-test.mjs +0 -934
  402. package/scripts/usage-metrics-epoch-smoke.mjs +0 -114
  403. package/scripts/verify-release-assets-test.mjs +0 -281
  404. package/scripts/web-fetch-routing-test.mjs +0 -158
  405. package/scripts/webhook-smoke.mjs +0 -201
  406. package/scripts/windows-hide-spawn-options-test.mjs +0 -19
  407. package/scripts/worker-notify-rejection-test.mjs +0 -51
  408. package/scripts/write-backpressure-test.mjs +0 -147
@@ -1,1013 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import test from 'node:test';
3
- import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
4
- import { tmpdir } from 'node:os';
5
- import { join, resolve } from 'node:path';
6
- import { fileURLToPath } from 'node:url';
7
- import { execFileSync } from 'node:child_process';
8
-
9
- import {
10
- SESSION_SUMMARY_INDEX_VERSION,
11
- _normalizeSummaryIndex,
12
- _sessionSummary,
13
- } from '../src/runtime/agent/orchestrator/session/store-summary-index.mjs';
14
- import {
15
- listStoredSessionSummaries as listLightweightSessionSummaries,
16
- } from '../src/runtime/agent/orchestrator/session/store-summary-reader.mjs';
17
- import { createLifecycleApi, resolveResumeCwd } from '../src/session-runtime/lifecycle-api.mjs';
18
- import { createCwdPlugins } from '../src/session-runtime/cwd-plugins.mjs';
19
- import {
20
- normalizeDesktopSessionMetadata,
21
- resumeSession as resumeStoredSession,
22
- } from '../src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs';
23
- import {
24
- drainSessionStore,
25
- deleteSession,
26
- loadSession,
27
- listStoredSessionSummaries,
28
- markSessionClosed,
29
- saveSession,
30
- saveSessionAsync,
31
- saveSessionAsyncDeferred,
32
- setLiveSession,
33
- } from '../src/runtime/agent/orchestrator/session/store.mjs';
34
-
35
- test('deferred terminal save is registered for immediate exit drain', async () => {
36
- const root = mkdtempSync(join(tmpdir(), 'mixdog-deferred-terminal-'));
37
- const previousDataDir = process.env.MIXDOG_DATA_DIR;
38
- process.env.MIXDOG_DATA_DIR = root;
39
- try {
40
- const session = {
41
- id: 'deferred_terminal_exit',
42
- owner: 'user',
43
- createdAt: Date.now(),
44
- updatedAt: Date.now(),
45
- messages: [{ role: 'assistant', content: 'terminal state' }],
46
- };
47
- const pending = saveSessionAsyncDeferred(session);
48
- drainSessionStore();
49
- await pending;
50
- assert.equal(loadSession(session.id)?.messages?.[0]?.content, 'terminal state');
51
- } finally {
52
- drainSessionStore();
53
- if (previousDataDir == null) delete process.env.MIXDOG_DATA_DIR;
54
- else process.env.MIXDOG_DATA_DIR = previousDataDir;
55
- rmSync(root, { recursive: true, force: true });
56
- }
57
- });
58
-
59
- test('exit drain writes deferred terminal state after an older worker-pending save', async () => {
60
- const root = mkdtempSync(join(tmpdir(), 'mixdog-deferred-order-'));
61
- try {
62
- const storeUrl = new URL('../src/runtime/agent/orchestrator/session/store.mjs', import.meta.url).href;
63
- const output = execFileSync(process.execPath, ['--input-type=module', '-e', `
64
- process.env.MIXDOG_DATA_DIR = ${JSON.stringify(root)};
65
- const { saveSessionAsync, saveSessionAsyncDeferred, drainSessionStore, loadSession } = await import(${JSON.stringify(storeUrl)});
66
- const base = { id: 'deferred_order_exit', owner: 'user', createdAt: Date.now(), updatedAt: Date.now() };
67
- saveSessionAsync({ ...base, messages: [{ role: 'assistant', content: 'older worker snapshot' }], padding: 'x'.repeat(2_000_000) }).catch(() => {});
68
- const terminal = saveSessionAsyncDeferred({ ...base, updatedAt: Date.now() + 1, messages: [{ role: 'assistant', content: 'newest terminal snapshot' }] });
69
- drainSessionStore();
70
- await Promise.allSettled([terminal]);
71
- process.stdout.write(loadSession(base.id)?.messages?.[0]?.content || '');
72
- process.exit(0);
73
- `], { encoding: 'utf8' });
74
- assert.equal(output, 'newest terminal snapshot');
75
- } finally {
76
- rmSync(root, { recursive: true, force: true });
77
- }
78
- });
79
-
80
- test('desktop classification is optional and round-trips through the existing summary index', () => {
81
- const task = _sessionSummary({
82
- id: 'lead_task',
83
- owner: 'cli',
84
- agent: 'lead',
85
- cwd: '/app/workspace',
86
- desktopSession: { classification: 'task', projectPath: null },
87
- });
88
- const project = _normalizeSummaryIndex({
89
- rows: [{
90
- id: 'lead_project',
91
- cwd: '/project',
92
- desktopSession: { classification: 'project', projectPath: '/project' },
93
- }],
94
- }).rows[0];
95
- const legacy = _normalizeSummaryIndex({ rows: [{ id: 'legacy', cwd: '/old' }] }).rows[0];
96
- const malformed = _normalizeSummaryIndex({
97
- rows: [{ id: 'malformed', desktopSession: { classification: 'worker' } }],
98
- }).rows[0];
99
-
100
- assert.deepEqual(task.desktopSession, { classification: 'task', projectPath: null });
101
- assert.deepEqual(project.desktopSession, { classification: 'project', projectPath: '/project' });
102
- assert.equal(legacy.desktopSession, null);
103
- assert.equal(malformed.desktopSession, null);
104
- });
105
-
106
- test('cold summary reader loads the sidecar without importing the full store', () => {
107
- const root = mkdtempSync(join(tmpdir(), 'mixdog-cold-summary-reader-'));
108
- const previousDataDir = process.env.MIXDOG_DATA_DIR;
109
- process.env.MIXDOG_DATA_DIR = root;
110
- try {
111
- writeFileSync(join(root, 'session-summaries.json'), JSON.stringify({
112
- version: SESSION_SUMMARY_INDEX_VERSION,
113
- rows: [{
114
- id: 'cold_reader',
115
- updatedAt: 10,
116
- cwd: '/workspace',
117
- preview: 'Cold reader session',
118
- desktopSession: { classification: 'task', projectPath: null },
119
- }],
120
- }));
121
- assert.deepEqual(listLightweightSessionSummaries().map((row) => row.id), ['cold_reader']);
122
- } finally {
123
- if (previousDataDir == null) delete process.env.MIXDOG_DATA_DIR;
124
- else process.env.MIXDOG_DATA_DIR = previousDataDir;
125
- rmSync(root, { recursive: true, force: true });
126
- }
127
- });
128
-
129
- test('loadSession reuses a parsed session until the atomic file identity changes', () => {
130
- const root = mkdtempSync(join(tmpdir(), 'mixdog-session-load-cache-'));
131
- const previousDataDir = process.env.MIXDOG_DATA_DIR;
132
- process.env.MIXDOG_DATA_DIR = root;
133
- try {
134
- const sessions = join(root, 'sessions');
135
- mkdirSync(sessions, { recursive: true });
136
- const target = join(sessions, 'cached_parse.json');
137
- writeFileSync(target, JSON.stringify({
138
- id: 'cached_parse',
139
- messages: [{ role: 'user', content: 'first version' }],
140
- }));
141
- const first = loadSession('cached_parse');
142
- const second = loadSession('cached_parse');
143
- assert.equal(second, first);
144
- writeFileSync(target, JSON.stringify({
145
- id: 'cached_parse',
146
- messages: [{ role: 'user', content: 'changed version with a different size' }],
147
- }));
148
- const changed = loadSession('cached_parse');
149
- assert.notEqual(changed, first);
150
- assert.equal(changed.messages[0].content, 'changed version with a different size');
151
- } finally {
152
- if (previousDataDir == null) delete process.env.MIXDOG_DATA_DIR;
153
- else process.env.MIXDOG_DATA_DIR = previousDataDir;
154
- rmSync(root, { recursive: true, force: true });
155
- }
156
- });
157
-
158
- test('session summaries use the first real user request and remove injected display blocks', () => {
159
- const summary = _sessionSummary({
160
- id: 'clean_title_source',
161
- owner: 'user',
162
- messages: [
163
- { role: 'user', content: '<system-reminder>runtime bootstrap</system-reminder>' },
164
- {
165
- role: 'user',
166
- content: 'A previous model worked on this task and produced the compacted handoff summary below. Build on it.',
167
- },
168
- {
169
- role: 'user',
170
- content: 'Reference files: [Image #1] <mcp-instructions>internal tools</mcp-instructions> Align the project dropdown',
171
- },
172
- { role: 'user', content: 'The async agent task task_agent completed with internal output.' },
173
- { role: 'user', content: 'A later follow-up must not replace the stable title source' },
174
- ],
175
- });
176
-
177
- assert.equal(summary.preview, 'Align the project dropdown');
178
- });
179
-
180
- test('authoritative summary refresh repairs a stale index and skips malformed session files', () => {
181
- const root = mkdtempSync(join(tmpdir(), 'mixdog-desktop-summary-'));
182
- const previousDataDir = process.env.MIXDOG_DATA_DIR;
183
- process.env.MIXDOG_DATA_DIR = root;
184
- try {
185
- const sessions = join(root, 'sessions');
186
- mkdirSync(sessions, { recursive: true });
187
- writeFileSync(join(root, 'session-summaries.json'), JSON.stringify({
188
- version: 1,
189
- rows: [{
190
- id: 'desktop_old',
191
- updatedAt: 1,
192
- cwd: '/old',
193
- desktopSession: { classification: 'task', projectPath: null },
194
- }],
195
- }));
196
- writeFileSync(join(sessions, 'desktop_new.json'), JSON.stringify({
197
- id: 'desktop_new',
198
- owner: 'user',
199
- agent: 'lead',
200
- updatedAt: 20,
201
- cwd: '/app/workspace',
202
- desktopSession: { classification: 'task', projectPath: null },
203
- messages: [{ role: 'user', content: 'Newly persisted desktop task' }],
204
- }));
205
- writeFileSync(join(sessions, 'cli_only.json'), JSON.stringify({
206
- id: 'cli_only',
207
- owner: 'user',
208
- updatedAt: 10,
209
- cwd: '/cli',
210
- messages: [{ role: 'user', content: 'CLI only' }],
211
- }));
212
- writeFileSync(join(sessions, 'broken.json'), '{"id":');
213
-
214
- const rows = listStoredSessionSummaries({ refreshFromStorage: true });
215
- assert.deepEqual(rows.map((row) => row.id), ['desktop_new', 'cli_only']);
216
- assert.deepEqual(
217
- rows.find((row) => row.id === 'desktop_new').desktopSession,
218
- { classification: 'task', projectPath: null },
219
- );
220
- assert.equal(rows.find((row) => row.id === 'cli_only').desktopSession, null);
221
- const repaired = JSON.parse(readFileSync(join(root, 'session-summaries.json'), 'utf8'));
222
- assert.deepEqual(repaired.rows.map((row) => row.id), ['desktop_new', 'cli_only']);
223
- } finally {
224
- drainSessionStore();
225
- if (previousDataDir == null) delete process.env.MIXDOG_DATA_DIR;
226
- else process.env.MIXDOG_DATA_DIR = previousDataDir;
227
- rmSync(root, { recursive: true, force: true, maxRetries: 8, retryDelay: 25 });
228
- }
229
- });
230
-
231
- test('cached summaries reflect local lifecycle mutations and forced refresh reconciles disk', async () => {
232
- const root = mkdtempSync(join(tmpdir(), 'mixdog-summary-cache-'));
233
- const previousDataDir = process.env.MIXDOG_DATA_DIR;
234
- process.env.MIXDOG_DATA_DIR = root;
235
- try {
236
- const sessions = join(root, 'sessions');
237
- mkdirSync(sessions, { recursive: true });
238
- writeFileSync(join(sessions, 'indexed.json'), JSON.stringify({
239
- id: 'indexed', owner: 'user', updatedAt: 10, messages: [],
240
- }));
241
- writeFileSync(join(root, 'session-summaries.json'), JSON.stringify({
242
- version: 1, rows: [{ id: 'indexed', owner: 'user', updatedAt: 10 }],
243
- }));
244
-
245
- assert.deepEqual(listStoredSessionSummaries().map((row) => row.id), ['indexed']);
246
- assert.equal(
247
- JSON.parse(readFileSync(join(root, 'session-summaries.json'), 'utf8')).version,
248
- SESSION_SUMMARY_INDEX_VERSION,
249
- );
250
-
251
- saveSession({
252
- id: 'cached_new', owner: 'user', updatedAt: 20,
253
- messages: [{ role: 'user', content: 'Cached local session' }],
254
- }, { sync: true });
255
- assert.deepEqual(
256
- listStoredSessionSummaries().map((row) => row.id),
257
- ['cached_new', 'indexed'],
258
- );
259
-
260
- await saveSessionAsync({
261
- id: 'cached_async', owner: 'user', updatedAt: 25,
262
- messages: [{ role: 'user', content: 'Cached async session' }],
263
- });
264
- assert.equal(listStoredSessionSummaries().some((row) => row.id === 'cached_async'), true);
265
- assert.equal(deleteSession('cached_async'), true);
266
-
267
- assert.notEqual(markSessionClosed('cached_new', 'test'), null);
268
- assert.equal(
269
- listStoredSessionSummaries().find((row) => row.id === 'cached_new').closed,
270
- true,
271
- );
272
- assert.equal(deleteSession('cached_new'), true);
273
- assert.equal(listStoredSessionSummaries().some((row) => row.id === 'cached_new'), false);
274
-
275
- writeFileSync(join(sessions, 'external.json'), JSON.stringify({
276
- id: 'external', owner: 'user', updatedAt: 30, messages: [],
277
- }));
278
- assert.equal(listStoredSessionSummaries().some((row) => row.id === 'external'), false);
279
- assert.deepEqual(
280
- listStoredSessionSummaries({ refreshFromStorage: true }).map((row) => row.id),
281
- ['external', 'indexed'],
282
- );
283
- unlinkSync(join(sessions, 'external.json'));
284
- assert.deepEqual(
285
- listStoredSessionSummaries({ refreshFromStorage: true }).map((row) => row.id),
286
- ['indexed'],
287
- );
288
- } finally {
289
- drainSessionStore();
290
- if (previousDataDir == null) delete process.env.MIXDOG_DATA_DIR;
291
- else process.env.MIXDOG_DATA_DIR = previousDataDir;
292
- rmSync(root, { recursive: true, force: true, maxRetries: 8, retryDelay: 25 });
293
- }
294
- });
295
-
296
- test('authoritative refresh trusts disk over stale live state while preserving unsettled local writes', async () => {
297
- const root = mkdtempSync(join(tmpdir(), 'mixdog-summary-races-'));
298
- const previousDataDir = process.env.MIXDOG_DATA_DIR;
299
- process.env.MIXDOG_DATA_DIR = root;
300
- try {
301
- const sessions = join(root, 'sessions');
302
- mkdirSync(sessions, { recursive: true });
303
- writeFileSync(join(sessions, 'authoritative.json'), JSON.stringify({
304
- id: 'authoritative',
305
- owner: 'user',
306
- closed: true,
307
- status: 'closed',
308
- updatedAt: 40,
309
- desktopSession: { classification: 'project', projectPath: '/disk-project' },
310
- messages: [],
311
- }));
312
- setLiveSession({
313
- id: 'authoritative',
314
- owner: 'agent:stale',
315
- closed: false,
316
- updatedAt: 99,
317
- desktopSession: { classification: 'task', projectPath: null },
318
- messages: [],
319
- });
320
- let rows = listStoredSessionSummaries({ refreshFromStorage: true });
321
- const authoritative = rows.find((row) => row.id === 'authoritative');
322
- assert.equal(authoritative.closed, true);
323
- assert.equal(authoritative.owner, 'user');
324
- assert.deepEqual(authoritative.desktopSession, { classification: 'project', projectPath: '/disk-project' });
325
-
326
- unlinkSync(join(sessions, 'authoritative.json'));
327
- assert.equal(
328
- listStoredSessionSummaries({ refreshFromStorage: true }).some((row) => row.id === 'authoritative'),
329
- false,
330
- );
331
-
332
- saveSession({
333
- id: 'pending_desktop',
334
- owner: 'user',
335
- updatedAt: 50,
336
- desktopSession: { classification: 'task', projectPath: null },
337
- messages: [{ role: 'user', content: 'Visible before debounce flush' }],
338
- });
339
- assert.equal(existsSync(join(sessions, 'pending_desktop.json')), false);
340
- rows = listStoredSessionSummaries({ refreshFromStorage: true });
341
- assert.equal(rows.some((row) => row.id === 'pending_desktop'), true);
342
- assert.equal(listStoredSessionSummaries().some((row) => row.id === 'pending_desktop'), true);
343
- assert.equal(deleteSession('pending_desktop'), false);
344
- await new Promise((resolve) => setTimeout(resolve, 225));
345
- assert.equal(existsSync(join(sessions, 'pending_desktop.json')), false);
346
- assert.equal(
347
- listStoredSessionSummaries({ refreshFromStorage: true }).some((row) => row.id === 'pending_desktop'),
348
- false,
349
- );
350
-
351
- const first = saveSessionAsync({
352
- id: 'worker_deleted',
353
- owner: 'user',
354
- updatedAt: 60,
355
- messages: [{ role: 'user', content: 'First queued worker write' }],
356
- });
357
- const second = saveSessionAsync({
358
- id: 'worker_deleted',
359
- owner: 'user',
360
- updatedAt: 61,
361
- messages: [{ role: 'user', content: 'Latest queued worker write' }],
362
- });
363
- deleteSession('worker_deleted');
364
- await Promise.all([first, second]);
365
- await new Promise((resolve) => setTimeout(resolve, 25));
366
- assert.equal(existsSync(join(sessions, 'worker_deleted.json')), false);
367
- assert.equal(
368
- listStoredSessionSummaries({ refreshFromStorage: true }).some((row) => row.id === 'worker_deleted'),
369
- false,
370
- );
371
- } finally {
372
- drainSessionStore();
373
- if (previousDataDir == null) delete process.env.MIXDOG_DATA_DIR;
374
- else process.env.MIXDOG_DATA_DIR = previousDataDir;
375
- rmSync(root, { recursive: true, force: true, maxRetries: 8, retryDelay: 25 });
376
- }
377
- });
378
-
379
- test('authoritative refresh rejects filename and embedded session id mismatches', () => {
380
- const root = mkdtempSync(join(tmpdir(), 'mixdog-desktop-identity-'));
381
- const previousDataDir = process.env.MIXDOG_DATA_DIR;
382
- process.env.MIXDOG_DATA_DIR = root;
383
- try {
384
- const sessions = join(root, 'sessions');
385
- mkdirSync(sessions, { recursive: true });
386
- writeFileSync(join(sessions, 'cli_transcript.json'), JSON.stringify({
387
- id: 'cli_transcript',
388
- owner: 'user',
389
- updatedAt: 10,
390
- messages: [{ role: 'user', content: 'Legitimate CLI transcript' }],
391
- }));
392
- // Without filename/id validation this duplicate row could lend desktop
393
- // metadata to cli_transcript, then resume the legitimate CLI-owned file.
394
- writeFileSync(join(sessions, 'desktop_spoof.json'), JSON.stringify({
395
- id: 'cli_transcript',
396
- owner: 'user',
397
- updatedAt: 30,
398
- desktopSession: { classification: 'task', projectPath: null },
399
- messages: [{ role: 'user', content: 'Spoofed desktop authorization' }],
400
- }));
401
- writeFileSync(join(sessions, 'desktop_good.json'), JSON.stringify({
402
- id: 'desktop_good',
403
- owner: 'user',
404
- updatedAt: 20,
405
- desktopSession: { classification: 'task', projectPath: null },
406
- messages: [{ role: 'user', content: 'Legitimate desktop task' }],
407
- }));
408
- writeFileSync(join(sessions, 'duplicate_copy.json'), JSON.stringify({
409
- id: 'desktop_good',
410
- owner: 'user',
411
- updatedAt: 40,
412
- desktopSession: { classification: 'task', projectPath: null },
413
- messages: [{ role: 'user', content: 'Mismatched duplicate' }],
414
- }));
415
-
416
- const rows = listStoredSessionSummaries({ refreshFromStorage: true });
417
- assert.deepEqual(rows.map((row) => row.id), ['desktop_good', 'cli_transcript']);
418
- assert.equal(rows.find((row) => row.id === 'desktop_good').preview, 'Legitimate desktop task');
419
- assert.equal(rows.find((row) => row.id === 'cli_transcript').desktopSession, null);
420
- assert.equal(loadSession('cli_transcript').messages[0].content, 'Legitimate CLI transcript');
421
- assert.equal(loadSession('desktop_spoof'), null);
422
- assert.equal(loadSession('duplicate_copy'), null);
423
- } finally {
424
- if (previousDataDir == null) delete process.env.MIXDOG_DATA_DIR;
425
- else process.env.MIXDOG_DATA_DIR = previousDataDir;
426
- rmSync(root, { recursive: true, force: true });
427
- }
428
- });
429
-
430
- test('authoritative refresh fails closed when the session directory is unreadable', () => {
431
- const root = mkdtempSync(join(tmpdir(), 'mixdog-desktop-unreadable-'));
432
- const previousDataDir = process.env.MIXDOG_DATA_DIR;
433
- process.env.MIXDOG_DATA_DIR = root;
434
- try {
435
- writeFileSync(join(root, 'session-summaries.json'), JSON.stringify({
436
- version: SESSION_SUMMARY_INDEX_VERSION,
437
- rows: [{
438
- id: 'stale_desktop',
439
- updatedAt: 1,
440
- desktopSession: { classification: 'task', projectPath: null },
441
- }],
442
- }));
443
- // A non-directory at the authoritative storage path deterministically
444
- // exercises readdir failure on Windows and POSIX.
445
- writeFileSync(join(root, 'sessions'), 'not a directory');
446
-
447
- assert.deepEqual(listStoredSessionSummaries({ refreshFromStorage: true }), []);
448
- assert.deepEqual(
449
- listStoredSessionSummaries({ rebuildIfMissing: false }).map((row) => row.id),
450
- ['stale_desktop'],
451
- );
452
- } finally {
453
- if (previousDataDir == null) delete process.env.MIXDOG_DATA_DIR;
454
- else process.env.MIXDOG_DATA_DIR = previousDataDir;
455
- rmSync(root, { recursive: true, force: true });
456
- }
457
- });
458
-
459
- test('authoritative refresh includes a desktop session still in the debounce window', () => {
460
- const root = mkdtempSync(join(tmpdir(), 'mixdog-desktop-pending-'));
461
- const previousDataDir = process.env.MIXDOG_DATA_DIR;
462
- process.env.MIXDOG_DATA_DIR = root;
463
- try {
464
- saveSession({
465
- id: 'desktop_pending',
466
- owner: 'user',
467
- agent: 'lead',
468
- updatedAt: 50,
469
- cwd: '/app/workspace',
470
- desktopSession: { classification: 'task', projectPath: null },
471
- messages: [{ role: 'user', content: 'Immediate desktop task' }],
472
- });
473
-
474
- const rows = listStoredSessionSummaries({ refreshFromStorage: true });
475
- assert.equal(rows.some((row) => row.id === 'desktop_pending'), true);
476
- assert.equal(rows.find((row) => row.id === 'desktop_pending').preview, 'Immediate desktop task');
477
- } finally {
478
- drainSessionStore();
479
- if (previousDataDir == null) delete process.env.MIXDOG_DATA_DIR;
480
- else process.env.MIXDOG_DATA_DIR = previousDataDir;
481
- rmSync(root, { recursive: true, force: true });
482
- }
483
- });
484
-
485
- test('invalid existing disk identities block same-id pending and live state', () => {
486
- const root = mkdtempSync(join(tmpdir(), 'mixdog-desktop-live-blocked-'));
487
- const previousDataDir = process.env.MIXDOG_DATA_DIR;
488
- process.env.MIXDOG_DATA_DIR = root;
489
- try {
490
- const sessions = join(root, 'sessions');
491
- mkdirSync(sessions, { recursive: true });
492
- writeFileSync(join(sessions, 'pending_mismatch.json'), JSON.stringify({
493
- id: 'different_transcript',
494
- owner: 'user',
495
- messages: [{ role: 'user', content: 'Mismatched disk transcript' }],
496
- }));
497
- writeFileSync(join(sessions, 'pending_malformed.json'), '{"id":');
498
-
499
- for (const id of ['pending_mismatch', 'pending_malformed']) {
500
- saveSession({
501
- id,
502
- owner: 'user',
503
- agent: 'lead',
504
- updatedAt: 60,
505
- cwd: '/app/workspace',
506
- desktopSession: { classification: 'task', projectPath: null },
507
- messages: [{ role: 'user', content: `Pending replacement ${id}` }],
508
- });
509
- }
510
-
511
- const rows = listStoredSessionSummaries({ refreshFromStorage: true });
512
- assert.equal(rows.some((row) => row.id === 'pending_mismatch'), false);
513
- assert.equal(rows.some((row) => row.id === 'pending_malformed'), false);
514
- assert.equal(loadSession('pending_mismatch'), null);
515
- assert.equal(loadSession('pending_malformed'), null);
516
- } finally {
517
- drainSessionStore();
518
- if (previousDataDir == null) delete process.env.MIXDOG_DATA_DIR;
519
- else process.env.MIXDOG_DATA_DIR = previousDataDir;
520
- rmSync(root, { recursive: true, force: true });
521
- }
522
- });
523
-
524
- test('readFileSync failure blocks same-id pending and live state', () => {
525
- const root = mkdtempSync(join(tmpdir(), 'mixdog-desktop-read-error-'));
526
- const previousDataDir = process.env.MIXDOG_DATA_DIR;
527
- process.env.MIXDOG_DATA_DIR = root;
528
- const readErrorPath = join(root, 'sessions', 'pending_read_error.json');
529
- try {
530
- mkdirSync(join(root, 'sessions'), { recursive: true });
531
- // A directory with a .json storage name is visible to readdirSync and
532
- // existsSync, but readFileSync itself fails on supported desktop platforms.
533
- // This deterministically exercises the I/O catch before JSON.parse.
534
- mkdirSync(readErrorPath);
535
- saveSession({
536
- id: 'pending_read_error',
537
- owner: 'user',
538
- agent: 'lead',
539
- updatedAt: 70,
540
- cwd: '/app/workspace',
541
- desktopSession: { classification: 'task', projectPath: null },
542
- messages: [{ role: 'user', content: 'Pending replacement after read error' }],
543
- });
544
-
545
- const rows = listStoredSessionSummaries({ refreshFromStorage: true });
546
- assert.equal(rows.some((row) => row.id === 'pending_read_error'), false);
547
- assert.equal(loadSession('pending_read_error'), null);
548
- } finally {
549
- // Remove the deliberate directory collision so draining the pending test
550
- // save can complete without changing production failure behavior.
551
- rmSync(readErrorPath, { recursive: true, force: true });
552
- drainSessionStore();
553
- if (previousDataDir == null) delete process.env.MIXDOG_DATA_DIR;
554
- else process.env.MIXDOG_DATA_DIR = previousDataDir;
555
- rmSync(root, { recursive: true, force: true });
556
- }
557
- });
558
-
559
- test('session creation accepts only explicit desktop classification metadata', () => {
560
- assert.deepEqual(
561
- normalizeDesktopSessionMetadata({ classification: 'task', projectPath: '/ignored' }, '/cwd'),
562
- { classification: 'task', projectPath: null },
563
- );
564
- assert.deepEqual(
565
- normalizeDesktopSessionMetadata({ classification: 'project' }, '/project'),
566
- { classification: 'project', projectPath: '/project' },
567
- );
568
- assert.deepEqual(
569
- normalizeDesktopSessionMetadata({ classification: 'project', projectPath: ' /project/trimmed ' }, '/fallback'),
570
- { classification: 'project', projectPath: '/project/trimmed' },
571
- );
572
- assert.equal(normalizeDesktopSessionMetadata({ classification: 'project', projectPath: {} }, null), null);
573
- assert.equal(normalizeDesktopSessionMetadata({ classification: 'project', projectPath: '\0bad' }, null), null);
574
- assert.equal(normalizeDesktopSessionMetadata({ classification: 'project' }, null), null);
575
- assert.equal(normalizeDesktopSessionMetadata({ classification: 'worker' }, '/cwd'), null);
576
- assert.equal(normalizeDesktopSessionMetadata({}, '/cwd'), null);
577
- assert.equal(normalizeDesktopSessionMetadata(null, '/cwd'), null);
578
- });
579
-
580
- test('desktop resume pins projects and unclassified tasks to their host-managed scope', () => {
581
- assert.equal(resolveResumeCwd({
582
- cwd: '/stale',
583
- desktopSession: { classification: 'project', projectPath: '/project' },
584
- }, '/app/workspace'), '/project');
585
- assert.equal(resolveResumeCwd({
586
- cwd: '/transient',
587
- desktopSession: { classification: 'task', projectPath: null },
588
- }, '/app/workspace'), '/app/workspace');
589
- assert.equal(resolveResumeCwd({ cwd: '/cli' }, '/current'), '/cli');
590
- });
591
-
592
- test('new desktop sessions immediately repoint remote transcript forwarding', async () => {
593
- let current = null;
594
- const events = [];
595
- const runtime = createLifecycleApi({
596
- getSession: () => current,
597
- setSession: (value) => { current = value; },
598
- mgr: { closeSession: () => true },
599
- invalidateContextStatusCache: () => events.push('invalidate'),
600
- createCurrentSession: async () => {
601
- events.push('create');
602
- current = { id: 'desktop_new', messages: [] };
603
- },
604
- pushTranscriptRebind: () => events.push('rebind'),
605
- });
606
-
607
- assert.equal(await runtime.newSession(), 'desktop_new');
608
- assert.deepEqual(events, ['invalidate', 'create', 'rebind']);
609
- });
610
-
611
- test('session deletion hard-deletes inactive rows and safely replaces the active row', async () => {
612
- let current = {
613
- id: 'desktop_active',
614
- owner: 'user',
615
- sourceType: 'cli',
616
- messages: [{ role: 'user', content: 'Active session' }],
617
- };
618
- const rows = [
619
- current,
620
- {
621
- id: 'desktop_inactive',
622
- owner: 'user',
623
- sourceType: 'cli',
624
- messages: [{ role: 'user', content: 'Inactive session' }],
625
- },
626
- ];
627
- const events = [];
628
- const runtime = createLifecycleApi({
629
- getSession: () => current,
630
- setSession: (value) => { current = value; },
631
- mgr: {
632
- listSessions: () => rows,
633
- deleteSession: (id) => { events.push(['delete', id]); return true; },
634
- closeSession: (...args) => { events.push(['close', ...args]); return true; },
635
- },
636
- cancelBackgroundTasks: (options) => events.push(['background', options]),
637
- agentTool: { closeAll: (reason) => events.push(['agents', reason]) },
638
- statusRoutes: { clearGatewaySessionRoute: (id) => events.push(['route', id]) },
639
- invalidateContextStatusCache: () => events.push(['context']),
640
- invalidatePreSessionToolSurface: () => events.push(['surface']),
641
- createCurrentSession: async () => {
642
- current = { id: 'desktop_replacement', messages: [] };
643
- events.push(['create', current.id]);
644
- },
645
- pushTranscriptRebind: () => events.push(['rebind']),
646
- });
647
-
648
- assert.equal(await runtime.deleteSession('desktop_inactive'), true);
649
- assert.deepEqual(events.shift(), ['delete', 'desktop_inactive']);
650
- assert.equal(await runtime.deleteSession('desktop_active'), true);
651
- assert.equal(current.id, 'desktop_replacement');
652
- assert.deepEqual(events, [
653
- ['background', {
654
- reason: 'desktop-session-delete',
655
- notify: false,
656
- callerSessionId: 'desktop_active',
657
- }],
658
- ['agents', 'desktop-session-delete'],
659
- ['route', 'desktop_active'],
660
- ['close', 'desktop_active', 'desktop-session-delete', { tombstone: true }],
661
- ['context'],
662
- ['surface'],
663
- ['create', 'desktop_replacement'],
664
- ['rebind'],
665
- ]);
666
- });
667
-
668
- test('runtime resume returns the persisted transcript and restores desktop task scope', async () => {
669
- let current = null;
670
- let cwd = '/app/workspace';
671
- let route = { provider: 'test', model: 'model' };
672
- let transcriptRebinds = 0;
673
- const messages = [
674
- { role: 'user', content: 'Persisted question' },
675
- { role: 'assistant', content: 'Persisted answer' },
676
- ];
677
- const runtime = createLifecycleApi({
678
- getSession: () => current,
679
- setSession: (value) => { current = value; },
680
- getRoute: () => route,
681
- setRoute: (value) => { route = value; },
682
- getConfig: () => ({}),
683
- getMode: () => 'full',
684
- getCurrentCwd: () => cwd,
685
- desktopSession: { classification: 'task', projectPath: null },
686
- setSessionNeedsCwdRefresh: () => {},
687
- mgr: {
688
- resumeSession: async (id, _preset, options) => {
689
- assert.deepEqual(options, {
690
- desktopSession: { classification: 'task', projectPath: null },
691
- });
692
- return {
693
- id,
694
- provider: 'test',
695
- model: 'model',
696
- cwd: '/stale-task-cwd',
697
- desktopSession: { classification: 'task', projectPath: null },
698
- messages,
699
- };
700
- },
701
- },
702
- statusRoutes: {},
703
- createCurrentSession: async () => {},
704
- refreshRouteEffort: async () => {},
705
- invalidateContextStatusCache: () => {},
706
- invalidatePreSessionToolSurface: () => {},
707
- applyResolvedCwd: (value) => { cwd = value; },
708
- resolveRoute: (_config, value) => value,
709
- applyDeferredToolSurface: () => {},
710
- getStandaloneTools: () => [],
711
- pushTranscriptRebind: () => { transcriptRebinds += 1; },
712
- });
713
-
714
- const resumed = await runtime.resume('desktop_task');
715
- assert.deepEqual(resumed.messages, messages);
716
- assert.equal(resumed.cwd, '/app/workspace');
717
- assert.equal(current.cwd, '/app/workspace');
718
- assert.equal(transcriptRebinds, 1);
719
- });
720
-
721
- test('runtime session prefetch warms the manager without changing the active session', () => {
722
- const calls = [];
723
- const current = { id: 'active', messages: [] };
724
- const runtime = createLifecycleApi({
725
- getSession: () => current,
726
- getMode: () => 'full',
727
- mgr: {
728
- prefetchSession: (...args) => {
729
- calls.push(args);
730
- return true;
731
- },
732
- },
733
- });
734
-
735
- assert.equal(runtime.prefetchSession('next'), true);
736
- assert.deepEqual(calls, [['next', 'full']]);
737
- assert.equal(current.id, 'active');
738
- });
739
-
740
- test('desktop context switches retain runtime resources while durably closing the old session', async () => {
741
- let current = {
742
- id: 'old',
743
- messages: [{ role: 'user', content: 'keep me' }],
744
- liveTurnMessages: [],
745
- };
746
- let cwd = '/old';
747
- let desktopSession = { classification: 'task', projectPath: null };
748
- let route = { provider: 'resumed-provider', model: 'resumed-model' };
749
- const closed = [];
750
- const cleanup = [];
751
- let releaseMcp;
752
- const mcpReset = new Promise((resolve) => { releaseMcp = resolve; });
753
- const runtime = createLifecycleApi({
754
- getSession: () => current,
755
- setSession: (value) => { current = value; },
756
- getDesktopSession: () => desktopSession,
757
- setDesktopSession: (value) => { desktopSession = value; },
758
- getRoute: () => route,
759
- setRoute: (value) => { route = value; },
760
- getConfig: () => ({ default: 'workflow-lead' }),
761
- getCurrentCwd: () => cwd,
762
- mgr: { closeSession: (...args) => { closed.push(args); return true; } },
763
- cancelBackgroundTasks: (options) => cleanup.push(['background', options]),
764
- agentTool: { closeAll: (reason) => cleanup.push(['agents', reason]) },
765
- statusRoutes: { clearGatewaySessionRoute: (id) => cleanup.push(['route', id]) },
766
- applyResolvedCwd: (value, options) => {
767
- // Mirror the real contract: the cwd applies in place immediately while
768
- // the project MCP reset continues in the background; the switch must not
769
- // block on it.
770
- cleanup.push(['cwd:start', value, options]);
771
- cwd = value;
772
- void mcpReset.then(() => cleanup.push(['mcp:ready', value]));
773
- return value;
774
- },
775
- invalidateContextStatusCache: () => {},
776
- invalidatePreSessionToolSurface: () => {},
777
- refreshRouteEffort: async () => {},
778
- resolveRoute: (_config, value) => Object.keys(value).length > 0
779
- ? value
780
- : { provider: 'configured-provider', model: 'configured-model' },
781
- });
782
-
783
- let settled = false;
784
- const switching = runtime.switchContext({
785
- cwd: '/project',
786
- desktopSession: { classification: 'project', projectPath: '/project' },
787
- });
788
- switching.then(() => { settled = true; });
789
- // Non-blocking switch: it settles WITHOUT the MCP reset resolving. The
790
- // reconnect gate moved to the ask path (bounded awaitInitialMcpConnect).
791
- await switching;
792
- assert.equal(settled, true);
793
- assert.deepEqual(cleanup.slice(0, 4), [
794
- ['background', {
795
- reason: 'desktop-context-switch',
796
- notify: false,
797
- callerSessionId: 'old',
798
- }],
799
- ['agents', 'desktop-context-switch'],
800
- ['route', 'old'],
801
- ['cwd:start', '/project', { markRefresh: false }],
802
- ]);
803
- releaseMcp();
804
- await mcpReset;
805
-
806
- assert.deepEqual(closed, [['old', 'desktop-context-switch', { tombstone: false }]]);
807
- assert.equal(current, null);
808
- assert.equal(cwd, '/project');
809
- assert.deepEqual(route, { provider: 'configured-provider', model: 'configured-model' });
810
- assert.deepEqual(desktopSession, { classification: 'project', projectPath: '/project' });
811
- });
812
-
813
- test('cleared desktop context resumes legacy rows without reviving the creation marker', async () => {
814
- const taskDesktopSession = { classification: 'task', projectPath: null };
815
- let current = null;
816
- let cwd = '/task';
817
- let desktopSession = taskDesktopSession;
818
- const resumeOptions = [];
819
- const stored = {
820
- legacy: {
821
- id: 'legacy',
822
- provider: 'test',
823
- model: 'model',
824
- cwd: '/legacy',
825
- desktopSession: null,
826
- messages: [],
827
- },
828
- project: {
829
- id: 'project',
830
- provider: 'test',
831
- model: 'model',
832
- cwd: '/project',
833
- desktopSession: { classification: 'project', projectPath: '/project' },
834
- messages: [],
835
- },
836
- };
837
- const runtime = createLifecycleApi({
838
- getSession: () => current,
839
- setSession: (value) => { current = value; },
840
- getDesktopSession: () => desktopSession,
841
- setDesktopSession: (value) => { desktopSession = value; },
842
- getRoute: () => ({ provider: 'test', model: 'model' }),
843
- setRoute: () => {},
844
- getConfig: () => ({}),
845
- getMode: () => 'full',
846
- getCurrentCwd: () => cwd,
847
- setSessionNeedsCwdRefresh: () => {},
848
- desktopSession: taskDesktopSession,
849
- mgr: {
850
- closeSession: () => true,
851
- resumeSession: async (id, _preset, options) => {
852
- resumeOptions.push(options);
853
- const session = stored[id];
854
- const expected = options?.desktopSession;
855
- if (expected && (!session.desktopSession
856
- || expected.classification !== session.desktopSession.classification)) return null;
857
- return session;
858
- },
859
- },
860
- statusRoutes: {},
861
- createCurrentSession: async () => {},
862
- refreshRouteEffort: async () => {},
863
- invalidateContextStatusCache: () => {},
864
- invalidatePreSessionToolSurface: () => {},
865
- applyResolvedCwd: async (value) => { cwd = value; },
866
- resolveRoute: (_config, value) => value,
867
- applyDeferredToolSurface: () => {},
868
- getStandaloneTools: () => [],
869
- });
870
-
871
- await runtime.switchContext({ cwd: '/legacy', desktopSession: null });
872
- assert.equal(desktopSession, null);
873
- assert.equal((await runtime.resume('legacy')).id, 'legacy');
874
- assert.equal(resumeOptions[0], undefined);
875
-
876
- await runtime.switchContext({ cwd: '/task', desktopSession: taskDesktopSession });
877
- assert.equal(await runtime.resume('project'), null);
878
- assert.deepEqual(resumeOptions[1], { desktopSession: taskDesktopSession });
879
- });
880
-
881
- test('desktop cwd application awaits project MCP reset before becoming ready', async () => {
882
- const root = mkdtempSync(join(tmpdir(), 'mixdog-cwd-mcp-order-'));
883
- const oldCwd = join(root, 'old');
884
- const nextCwd = join(root, 'next');
885
- mkdirSync(oldCwd);
886
- mkdirSync(nextCwd);
887
- let currentCwd = oldCwd;
888
- let projectKey = '';
889
- let releaseReset;
890
- const resetGate = new Promise((resolve) => { releaseReset = resolve; });
891
- const events = [];
892
- const cwdPlugins = createCwdPlugins({
893
- getCurrentCwd: () => currentCwd,
894
- setCurrentCwd: (value) => { currentCwd = value; },
895
- getSession: () => null,
896
- getLastProjectMcpKey: () => projectKey,
897
- setLastProjectMcpKey: (value) => { projectKey = value; },
898
- isCodeGraphPrewarmLazy: () => true,
899
- isCodeGraphFirstTurnPrewarmDone: () => false,
900
- getCodeGraphPrewarmDelayMs: () => 0,
901
- connectConfiguredMcp: async (options) => {
902
- events.push(['reset:start', options]);
903
- await resetGate;
904
- events.push(['reset:done']);
905
- },
906
- invalidatePreSessionToolSurface: () => events.push(['surface:invalidated']),
907
- scheduleCodeGraphPrewarm: () => {},
908
- hooks: { dispatch: () => {} },
909
- hookCommonPayload: (value) => value,
910
- bootProfile: () => {},
911
- readProjectMcpServers: () => ({}),
912
- writeLastSessionCwd: () => {},
913
- clean: (value) => String(value || '').trim(),
914
- resolve,
915
- statSync,
916
- });
917
- try {
918
- let ready = false;
919
- const applying = cwdPlugins.applyResolvedCwd(nextCwd, { waitForMcpReset: true });
920
- applying.then(() => { ready = true; });
921
- await Promise.resolve();
922
- assert.equal(ready, false);
923
- assert.deepEqual(events, [['reset:start', { reset: true }]]);
924
- releaseReset();
925
- assert.equal(await applying, resolve(nextCwd));
926
- assert.deepEqual(events, [
927
- ['reset:start', { reset: true }],
928
- ['reset:done'],
929
- ['surface:invalidated'],
930
- ]);
931
- } finally {
932
- rmSync(root, { recursive: true, force: true });
933
- }
934
- });
935
-
936
- test('production runtime composition supplies mutable desktop session bindings', () => {
937
- const source = readFileSync(
938
- fileURLToPath(new URL('../src/session-runtime/runtime-core.mjs', import.meta.url)),
939
- 'utf8',
940
- );
941
- const composition = source.slice(
942
- source.indexOf('const lifecycleApi = createLifecycleApi({'),
943
- source.indexOf('const resourceApi = createResourceApi({'),
944
- );
945
- assert.match(composition, /getDesktopSession:\s*\(\)\s*=>\s*desktopSession/);
946
- assert.match(composition, /setDesktopSession:\s*\(v\)\s*=>\s*\{\s*desktopSession = v;\s*\}/);
947
- });
948
-
949
- test('summary metadata rejects non-string project paths instead of leaking objects', () => {
950
- const withoutFallback = _sessionSummary({
951
- id: 'bad_project_path',
952
- desktopSession: { classification: 'project', projectPath: { untrusted: true } },
953
- });
954
- const withFallback = _normalizeSummaryIndex({
955
- rows: [{
956
- id: 'legacy_project_path',
957
- cwd: ' /legacy/project ',
958
- desktopSession: { classification: 'project', projectPath: null },
959
- }],
960
- }).rows[0];
961
-
962
- assert.equal(withoutFallback.desktopSession, null);
963
- assert.deepEqual(withFallback.desktopSession, {
964
- classification: 'project',
965
- projectPath: '/legacy/project',
966
- });
967
- });
968
-
969
- test('desktop-guarded resume refuses legacy/cross-class rows while the historical path still accepts legacy', async () => {
970
- const root = mkdtempSync(join(tmpdir(), 'mixdog-desktop-resume-guard-'));
971
- const previousDataDir = process.env.MIXDOG_DATA_DIR;
972
- process.env.MIXDOG_DATA_DIR = root;
973
- try {
974
- const sessions = join(root, 'sessions');
975
- mkdirSync(sessions, { recursive: true });
976
- const project = {
977
- id: 'desktop_project_guard',
978
- cwd: '/project',
979
- desktopSession: { classification: 'project', projectPath: '/project' },
980
- messages: [{ role: 'user', content: 'Project transcript' }],
981
- tools: [],
982
- };
983
- const legacy = {
984
- id: 'legacy_cli_guard',
985
- cwd: '/cli',
986
- messages: [{ role: 'user', content: 'CLI transcript' }],
987
- tools: [],
988
- };
989
- writeFileSync(join(sessions, `${project.id}.json`), JSON.stringify(project));
990
- writeFileSync(join(sessions, `${legacy.id}.json`), JSON.stringify(legacy));
991
-
992
- const expectedTask = { desktopSession: { classification: 'task', projectPath: null } };
993
- assert.equal(await resumeStoredSession(project.id, 'full', expectedTask), null);
994
- assert.equal(await resumeStoredSession(legacy.id, 'full', expectedTask), null);
995
- assert.deepEqual(JSON.parse(readFileSync(join(sessions, `${project.id}.json`), 'utf8')), project);
996
- assert.deepEqual(JSON.parse(readFileSync(join(sessions, `${legacy.id}.json`), 'utf8')), legacy);
997
- const resumedLegacy = await resumeStoredSession(legacy.id, 'full');
998
- assert.equal(resumedLegacy.id, legacy.id);
999
- assert.equal(resumedLegacy.desktopSession, undefined);
1000
- } finally {
1001
- drainSessionStore();
1002
- if (previousDataDir == null) delete process.env.MIXDOG_DATA_DIR;
1003
- else process.env.MIXDOG_DATA_DIR = previousDataDir;
1004
- try {
1005
- rmSync(root, { recursive: true, force: true, maxRetries: 8, retryDelay: 25 });
1006
- } catch {
1007
- // The save worker acknowledges the session write before its best-effort
1008
- // summary-index flush has fully released Windows filesystem handles.
1009
- await new Promise((resolve) => setTimeout(resolve, 50));
1010
- rmSync(root, { recursive: true, force: true, maxRetries: 8, retryDelay: 25 });
1011
- }
1012
- }
1013
- });