mixdog 0.8.1 → 0.9.1

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 (299) hide show
  1. package/README.md +47 -23
  2. package/package.json +34 -28
  3. package/scripts/_test-folder-dialog.mjs +30 -0
  4. package/scripts/agent-parallel-smoke.mjs +388 -0
  5. package/scripts/agent-tag-reuse-smoke.mjs +183 -0
  6. package/scripts/background-task-meta-smoke.mjs +38 -0
  7. package/scripts/boot-smoke.mjs +52 -9
  8. package/scripts/build-runtime-linux.sh +348 -0
  9. package/scripts/build-runtime-macos.sh +217 -0
  10. package/scripts/build-runtime-windows.ps1 +242 -0
  11. package/scripts/compact-active-turn-test.mjs +68 -0
  12. package/scripts/compact-smoke.mjs +859 -129
  13. package/scripts/compact-trigger-migration-smoke.mjs +187 -0
  14. package/scripts/fix-brief-fn.mjs +35 -0
  15. package/scripts/fix-format-tool-surface.mjs +24 -0
  16. package/scripts/fix-tool-exec-visible.mjs +42 -0
  17. package/scripts/generate-runtime-manifest.mjs +166 -0
  18. package/scripts/hook-bus-test.mjs +330 -0
  19. package/scripts/lead-workflow-smoke.mjs +33 -39
  20. package/scripts/live-worker-smoke.mjs +43 -37
  21. package/scripts/llm-trace-summary.mjs +315 -0
  22. package/scripts/memory-meta-concurrency-test.mjs +20 -0
  23. package/scripts/output-style-smoke.mjs +56 -15
  24. package/scripts/parent-abort-link-test.mjs +44 -0
  25. package/scripts/patch-agent-brief.mjs +48 -0
  26. package/scripts/patch-app.mjs +21 -0
  27. package/scripts/patch-app2.mjs +18 -0
  28. package/scripts/patch-dist-brief.mjs +96 -0
  29. package/scripts/patch-tool-exec.mjs +70 -0
  30. package/scripts/pretool-ask-runtime-test.mjs +54 -0
  31. package/scripts/provider-toolcall-test.mjs +376 -0
  32. package/scripts/reactive-compact-persist-smoke.mjs +124 -0
  33. package/scripts/sanitize-tool-pairs-test.mjs +260 -0
  34. package/scripts/session-context-bench.mjs +205 -33
  35. package/scripts/session-ingest-smoke.mjs +177 -0
  36. package/scripts/set-effort-config-test.mjs +41 -0
  37. package/scripts/smoke-runtime-negative.ps1 +106 -0
  38. package/scripts/smoke-runtime-negative.sh +97 -0
  39. package/scripts/smoke.mjs +25 -0
  40. package/scripts/tool-result-hook-test.mjs +48 -0
  41. package/scripts/tool-smoke.mjs +1222 -90
  42. package/scripts/toolcall-args-test.mjs +150 -0
  43. package/scripts/tui-background-failure-smoke.mjs +73 -0
  44. package/scripts/usage-metrics-epoch-smoke.mjs +114 -0
  45. package/src/agents/debugger/AGENT.md +8 -0
  46. package/src/agents/explore/AGENT.md +4 -0
  47. package/src/agents/heavy-worker/AGENT.md +9 -3
  48. package/src/agents/maintainer/AGENT.md +4 -0
  49. package/src/agents/reviewer/AGENT.md +8 -0
  50. package/src/agents/scheduler-task/AGENT.md +12 -0
  51. package/src/agents/scheduler-task/agent.json +6 -0
  52. package/src/agents/webhook-handler/AGENT.md +12 -0
  53. package/src/agents/webhook-handler/agent.json +6 -0
  54. package/src/agents/worker/AGENT.md +9 -3
  55. package/src/app.mjs +77 -3
  56. package/src/defaults/hidden-roles.json +17 -12
  57. package/src/headless-role.mjs +117 -0
  58. package/src/help.mjs +30 -0
  59. package/src/hooks/lib/permission-evaluator.cjs +11 -475
  60. package/src/lib/keychain-cjs.cjs +9 -1
  61. package/src/lib/mixdog-debug.cjs +0 -29
  62. package/src/lib/plugin-paths.cjs +1 -7
  63. package/src/lib/rules-builder.cjs +242 -98
  64. package/src/lib/text-utils.cjs +1 -1
  65. package/src/mixdog-session-runtime.mjs +2211 -446
  66. package/src/output-styles/default.md +12 -28
  67. package/src/output-styles/extreme-simple.md +9 -6
  68. package/src/output-styles/simple.md +22 -9
  69. package/src/repl.mjs +108 -59
  70. package/src/rules/agent/00-common.md +15 -0
  71. package/src/rules/{bridge → agent}/20-skip-protocol.md +1 -2
  72. package/src/rules/agent/30-explorer.md +22 -0
  73. package/src/rules/{bridge → agent}/40-cycle1-agent.md +7 -0
  74. package/src/rules/{bridge → agent}/41-cycle2-agent.md +7 -0
  75. package/src/rules/{bridge → agent}/42-cycle3-agent.md +7 -0
  76. package/src/rules/lead/01-general.md +9 -5
  77. package/src/rules/lead/04-workflow.md +51 -12
  78. package/src/rules/lead/lead-tool.md +6 -0
  79. package/src/rules/shared/01-tool.md +12 -1
  80. package/src/runtime/agent/orchestrator/activity-bus.mjs +7 -18
  81. package/src/runtime/agent/orchestrator/agent-owner.mjs +11 -0
  82. package/src/runtime/agent/orchestrator/{smart-bridge/bridge-llm.mjs → agent-runtime/agent-dispatch.mjs} +138 -111
  83. package/src/runtime/agent/orchestrator/agent-runtime/agent-progress-watchdog.mjs +94 -0
  84. package/src/runtime/agent/orchestrator/{smart-bridge → agent-runtime}/cache-strategy.mjs +32 -23
  85. package/src/runtime/agent/orchestrator/{smart-bridge → agent-runtime}/session-builder.mjs +33 -27
  86. package/src/runtime/agent/orchestrator/{bridge-trace.mjs → agent-trace.mjs} +132 -81
  87. package/src/runtime/agent/orchestrator/cache-mtime.mjs +0 -21
  88. package/src/runtime/agent/orchestrator/config.mjs +174 -55
  89. package/src/runtime/agent/orchestrator/context/collect.mjs +195 -487
  90. package/src/runtime/agent/orchestrator/dispatch-persist.mjs +1 -1
  91. package/src/runtime/agent/orchestrator/internal-roles.mjs +77 -29
  92. package/src/runtime/agent/orchestrator/internal-tools.mjs +5 -6
  93. package/src/runtime/agent/orchestrator/mcp/client.mjs +15 -9
  94. package/src/runtime/agent/orchestrator/providers/anthropic-betas.mjs +7 -1
  95. package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +380 -268
  96. package/src/runtime/agent/orchestrator/providers/anthropic.mjs +131 -93
  97. package/src/runtime/agent/orchestrator/providers/api-usage.mjs +236 -4
  98. package/src/runtime/agent/orchestrator/providers/custom-tool-wire.mjs +49 -0
  99. package/src/runtime/agent/orchestrator/providers/gemini.mjs +58 -13
  100. package/src/runtime/agent/orchestrator/providers/grok-oauth.mjs +67 -149
  101. package/src/runtime/agent/orchestrator/providers/media-normalization.mjs +132 -2
  102. package/src/runtime/agent/orchestrator/providers/model-catalog.mjs +4 -1
  103. package/src/runtime/agent/orchestrator/providers/oauth-credential-probes.mjs +45 -0
  104. package/src/runtime/agent/orchestrator/providers/oauth-usage.mjs +61 -116
  105. package/src/runtime/agent/orchestrator/providers/openai-compat-presets.mjs +25 -0
  106. package/src/runtime/agent/orchestrator/providers/openai-compat-stream.mjs +79 -255
  107. package/src/runtime/agent/orchestrator/providers/openai-compat.mjs +203 -71
  108. package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +512 -312
  109. package/src/runtime/agent/orchestrator/providers/openai-oauth.mjs +343 -518
  110. package/src/runtime/agent/orchestrator/providers/openai-ws.mjs +6 -6
  111. package/src/runtime/agent/orchestrator/providers/registry.mjs +88 -51
  112. package/src/runtime/agent/orchestrator/providers/retry-classifier.mjs +289 -11
  113. package/src/runtime/agent/orchestrator/providers/statusline-route-meta.mjs +41 -8
  114. package/src/runtime/agent/orchestrator/session/compact.mjs +1173 -267
  115. package/src/runtime/agent/orchestrator/session/context-utils.mjs +199 -36
  116. package/src/runtime/agent/orchestrator/session/loop.mjs +840 -612
  117. package/src/runtime/agent/orchestrator/session/manager.mjs +1574 -459
  118. package/src/runtime/agent/orchestrator/session/manager.reactive-persist.test.mjs +107 -0
  119. package/src/runtime/agent/orchestrator/session/store.mjs +67 -29
  120. package/src/runtime/agent/orchestrator/session/tool-result-offload.mjs +2 -2
  121. package/src/runtime/agent/orchestrator/stall-policy.mjs +31 -16
  122. package/src/runtime/agent/orchestrator/tool-loop-guard.mjs +3 -219
  123. package/src/runtime/agent/orchestrator/tools/bash-session.mjs +35 -8
  124. package/src/runtime/agent/orchestrator/tools/builtin/arg-guard.mjs +19 -8
  125. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +10 -53
  126. package/src/runtime/agent/orchestrator/tools/builtin/builtin-tools.mjs +60 -37
  127. package/src/runtime/agent/orchestrator/tools/builtin/cache-layers.mjs +21 -2
  128. package/src/runtime/agent/orchestrator/tools/builtin/device-paths.mjs +1 -1
  129. package/src/runtime/agent/orchestrator/tools/builtin/diagnostics-tool.mjs +0 -7
  130. package/src/runtime/agent/orchestrator/tools/builtin/glob-walk.mjs +1 -3
  131. package/src/runtime/agent/orchestrator/tools/builtin/list-tool.mjs +36 -12
  132. package/src/runtime/agent/orchestrator/tools/builtin/read-args.mjs +2 -0
  133. package/src/runtime/agent/orchestrator/tools/builtin/read-constants.mjs +2 -2
  134. package/src/runtime/agent/orchestrator/tools/builtin/read-formatting.mjs +5 -12
  135. package/src/runtime/agent/orchestrator/tools/builtin/read-image-resize.mjs +1 -1
  136. package/src/runtime/agent/orchestrator/tools/builtin/read-single-tool.mjs +4 -36
  137. package/src/runtime/agent/orchestrator/tools/builtin/read-tool.mjs +2 -40
  138. package/src/runtime/agent/orchestrator/tools/builtin/rg-runner.mjs +148 -27
  139. package/src/runtime/agent/orchestrator/tools/builtin/search-builders.mjs +2 -2
  140. package/src/runtime/agent/orchestrator/tools/builtin/search-tool.mjs +43 -75
  141. package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +90 -20
  142. package/src/runtime/agent/orchestrator/tools/builtin.mjs +59 -5
  143. package/src/runtime/agent/orchestrator/tools/code-graph-state.mjs +86 -0
  144. package/src/runtime/agent/orchestrator/tools/code-graph-tool-defs.mjs +11 -11
  145. package/src/runtime/agent/orchestrator/tools/code-graph.mjs +4106 -4019
  146. package/src/runtime/agent/orchestrator/tools/patch-tool-defs.mjs +33 -4
  147. package/src/runtime/agent/orchestrator/tools/patch.mjs +90 -6
  148. package/src/runtime/agent/orchestrator/tools/progress-message.mjs +6 -4
  149. package/src/runtime/agent/orchestrator/tools/result-compression.mjs +4 -4
  150. package/src/runtime/agent/orchestrator/tools/shell-command.mjs +8 -1
  151. package/src/runtime/agent/orchestrator/tools/shell-snapshot.mjs +4 -4
  152. package/src/runtime/channels/index.mjs +149 -51
  153. package/src/runtime/channels/lib/cli-worker-host.mjs +1 -8
  154. package/src/runtime/channels/lib/config.mjs +0 -1
  155. package/src/runtime/channels/lib/drop-trace.mjs +1 -1
  156. package/src/runtime/channels/lib/executor.mjs +0 -3
  157. package/src/runtime/channels/lib/memory-client.mjs +0 -38
  158. package/src/runtime/channels/lib/output-forwarder.mjs +1 -8
  159. package/src/runtime/channels/lib/runtime-paths.mjs +0 -6
  160. package/src/runtime/channels/lib/scheduler.mjs +18 -14
  161. package/src/runtime/channels/lib/session-discovery.mjs +3 -6
  162. package/src/runtime/channels/lib/tool-format.mjs +0 -1
  163. package/src/runtime/channels/lib/transcript-discovery.mjs +4 -12
  164. package/src/runtime/channels/lib/webhook.mjs +1 -1
  165. package/src/runtime/channels/tool-defs.mjs +29 -29
  166. package/src/runtime/lib/keychain-cjs.cjs +0 -1
  167. package/src/runtime/memory/data/runtime-manifest.json +6 -7
  168. package/src/runtime/memory/index.mjs +519 -118
  169. package/src/runtime/memory/lib/agent-ipc.mjs +29 -12
  170. package/src/runtime/memory/lib/core-memory-store.mjs +2 -2
  171. package/src/runtime/memory/lib/embedding-model-config.mjs +55 -0
  172. package/src/runtime/memory/lib/embedding-provider.mjs +31 -4
  173. package/src/runtime/memory/lib/embedding-worker.mjs +19 -10
  174. package/src/runtime/memory/lib/llm-worker-host.mjs +0 -4
  175. package/src/runtime/memory/lib/memory-cycle1.mjs +28 -7
  176. package/src/runtime/memory/lib/memory-cycle2.mjs +4 -5
  177. package/src/runtime/memory/lib/memory-cycle3.mjs +2 -2
  178. package/src/runtime/memory/lib/memory-ops-policy.mjs +2 -2
  179. package/src/runtime/memory/lib/memory-session-merge.mjs +38 -0
  180. package/src/runtime/memory/lib/memory.mjs +88 -9
  181. package/src/runtime/memory/lib/model-profile.mjs +1 -1
  182. package/src/runtime/memory/lib/pg/adapter.mjs +1 -1
  183. package/src/runtime/memory/lib/pg/supervisor.mjs +12 -0
  184. package/src/runtime/memory/lib/runtime-fetcher.mjs +80 -21
  185. package/src/runtime/memory/lib/session-ingest.mjs +196 -0
  186. package/src/runtime/memory/lib/trace-store.mjs +96 -51
  187. package/src/runtime/memory/tool-defs.mjs +46 -37
  188. package/src/runtime/search/index.mjs +104 -473
  189. package/src/runtime/search/lib/config.mjs +0 -4
  190. package/src/runtime/search/lib/state.mjs +1 -15
  191. package/src/runtime/search/lib/web-tools.mjs +44 -25
  192. package/src/runtime/search/tool-defs.mjs +16 -23
  193. package/src/runtime/shared/abort-controller.mjs +1 -1
  194. package/src/runtime/shared/atomic-file.mjs +4 -3
  195. package/src/runtime/shared/background-tasks.mjs +122 -11
  196. package/src/runtime/shared/child-spawn-gate.mjs +139 -0
  197. package/src/runtime/shared/config.mjs +7 -4
  198. package/src/runtime/shared/err-text.mjs +131 -4
  199. package/src/runtime/shared/llm/cost.mjs +2 -2
  200. package/src/runtime/shared/llm/http-agent.mjs +23 -7
  201. package/src/runtime/shared/llm/index.mjs +34 -11
  202. package/src/runtime/shared/llm/usage-log.mjs +4 -4
  203. package/src/runtime/shared/markdown-frontmatter.mjs +56 -0
  204. package/src/runtime/shared/singleton-owner.mjs +104 -0
  205. package/src/runtime/shared/tool-execution-contract.mjs +199 -20
  206. package/src/runtime/shared/tool-execution-contract.test.mjs +183 -0
  207. package/src/runtime/shared/tool-surface.mjs +624 -95
  208. package/src/runtime/shared/user-data-guard.mjs +0 -2
  209. package/src/standalone/agent-task-status.mjs +203 -0
  210. package/src/standalone/agent-task-status.test.mjs +76 -0
  211. package/src/standalone/agent-tool.mjs +1913 -0
  212. package/src/standalone/channel-worker.mjs +370 -14
  213. package/src/standalone/explore-tool.mjs +165 -70
  214. package/src/standalone/folder-dialog.mjs +314 -0
  215. package/src/standalone/hook-bus.mjs +898 -22
  216. package/src/standalone/memory-runtime-proxy.mjs +320 -0
  217. package/src/standalone/projects.mjs +226 -0
  218. package/src/standalone/provider-admin.mjs +41 -24
  219. package/src/standalone/seeds.mjs +1 -78
  220. package/src/standalone/usage-dashboard.mjs +96 -8
  221. package/src/tui/App.jsx +4800 -2140
  222. package/src/tui/components/AnsiText.jsx +39 -28
  223. package/src/tui/components/ContextPanel.jsx +14 -4
  224. package/src/tui/components/Markdown.jsx +43 -77
  225. package/src/tui/components/MarkdownTable.jsx +9 -184
  226. package/src/tui/components/Message.jsx +28 -11
  227. package/src/tui/components/Picker.jsx +95 -56
  228. package/src/tui/components/PromptInput.jsx +428 -239
  229. package/src/tui/components/QueuedCommands.jsx +1 -1
  230. package/src/tui/components/SlashCommandPalette.jsx +27 -21
  231. package/src/tui/components/Spinner.jsx +67 -38
  232. package/src/tui/components/StatusLine.jsx +606 -38
  233. package/src/tui/components/TextEntryPanel.jsx +128 -9
  234. package/src/tui/components/ToolExecution.jsx +597 -362
  235. package/src/tui/components/TurnDone.jsx +3 -3
  236. package/src/tui/components/UsagePanel.jsx +3 -5
  237. package/src/tui/components/tool-output-format.mjs +499 -0
  238. package/src/tui/components/tool-output-format.test.mjs +312 -0
  239. package/src/tui/dist/index.mjs +9192 -2399
  240. package/src/tui/engine-runtime-notification.test.mjs +115 -0
  241. package/src/tui/engine-tool-result-text.test.mjs +75 -0
  242. package/src/tui/engine.mjs +1455 -279
  243. package/src/tui/figures.mjs +21 -40
  244. package/src/tui/index.jsx +75 -31
  245. package/src/tui/input-editing.mjs +25 -0
  246. package/src/tui/markdown/format-token.mjs +671 -69
  247. package/src/tui/markdown/format-token.test.mjs +312 -0
  248. package/src/tui/markdown/render-ansi.mjs +94 -0
  249. package/src/tui/markdown/render-ansi.test.mjs +108 -0
  250. package/src/tui/markdown/stream-fence.mjs +34 -0
  251. package/src/tui/markdown/stream-fence.test.mjs +26 -0
  252. package/src/tui/markdown/table-layout.mjs +250 -0
  253. package/src/tui/paste-attachments.mjs +0 -7
  254. package/src/tui/spinner-verbs.mjs +1 -2
  255. package/src/tui/statusline-ansi-bridge.mjs +172 -0
  256. package/src/tui/statusline-ansi-bridge.test.mjs +159 -0
  257. package/src/tui/theme.mjs +756 -24
  258. package/src/tui/time-format.mjs +1 -1
  259. package/src/tui/transcript-tool-failures.mjs +67 -0
  260. package/src/tui/transcript-tool-failures.test.mjs +111 -0
  261. package/src/ui/ansi.mjs +1 -2
  262. package/src/ui/markdown.mjs +85 -26
  263. package/src/ui/markdown.test.mjs +70 -0
  264. package/src/ui/model-display.mjs +121 -0
  265. package/src/ui/session-stats.mjs +44 -0
  266. package/src/ui/statusline-context-label.test.mjs +15 -0
  267. package/src/ui/statusline.mjs +386 -178
  268. package/src/ui/tool-card.mjs +2 -13
  269. package/src/vendor/statusline/bin/statusline-lib.mjs +1 -620
  270. package/src/vendor/statusline/bin/statusline-route.mjs +169 -37
  271. package/src/vendor/statusline/bin/statusline-route.test.mjs +80 -0
  272. package/src/vendor/statusline/scripts/lib/gateway-settings.mjs +3 -3
  273. package/src/vendor/statusline/src/gateway/claude-current.mjs +1 -1
  274. package/src/vendor/statusline/src/gateway/route-meta.mjs +44 -6
  275. package/src/vendor/statusline/src/gateway/session-routes.mjs +1 -1
  276. package/src/workflows/default/WORKFLOW.md +12 -5
  277. package/src/workflows/default/workflow.json +0 -1
  278. package/src/workflows/solo/WORKFLOW.md +15 -0
  279. package/src/workflows/solo/workflow.json +7 -0
  280. package/vendor/ink/build/ink.js +54 -8
  281. package/vendor/ink/build/output.js +6 -1
  282. package/src/agents/scheduler-task.md +0 -3
  283. package/src/agents/web-researcher/AGENT.md +0 -3
  284. package/src/agents/web-researcher/agent.json +0 -6
  285. package/src/agents/webhook-handler.md +0 -3
  286. package/src/hooks/lib/permission-rules.cjs +0 -170
  287. package/src/hooks/lib/settings-loader.cjs +0 -112
  288. package/src/lib/hook-pipe-path.cjs +0 -10
  289. package/src/rules/bridge/00-common.md +0 -5
  290. package/src/rules/bridge/30-explorer.md +0 -4
  291. package/src/rules/lead/00-tool-lead.md +0 -5
  292. package/src/rules/shared/00-language.md +0 -3
  293. package/src/runtime/agent/orchestrator/tools/builtin/native-edit-runner.mjs +0 -110
  294. package/src/runtime/agent/orchestrator/tools/mutation-content-cache.mjs +0 -67
  295. package/src/runtime/channels/lib/hook-pipe-server.mjs +0 -671
  296. package/src/runtime/memory/lib/bridge-trace-queries.mjs +0 -120
  297. package/src/runtime/shared/llm/pid-cleanup.mjs +0 -27
  298. package/src/standalone/bridge-tool.mjs +0 -1414
  299. package/src/tui/runtime/shared/process-shutdown.mjs +0 -1
package/README.md CHANGED
@@ -1,8 +1,25 @@
1
1
  # mixdog
2
2
 
3
- Standalone coding-agent CLI/TUI workspace for **mixdog**.
4
-
5
- An Ink (React) terminal UI front-end driving multi-provider LLM agents (Anthropic, OpenAI, Google) over MCP, with Mixdog's Ink renderer (`vendor/ink`) for full-screen alt-screen rendering, cursor handling, and scroll support.
3
+ Mixdog is a standalone coding-agent CLI/TUI workspace for developers who want
4
+ one terminal experience across multiple LLM providers.
5
+
6
+ It combines an Ink-based terminal UI, a multi-provider runtime, workflow agents,
7
+ MCP/plugin/skill loading, memory, web search, channel integrations, and focused
8
+ repo tools for reading, editing, testing, and reviewing code.
9
+
10
+ ## Highlights
11
+
12
+ - Multi-provider model routing for Anthropic, OpenAI-compatible APIs, Google,
13
+ XAI/Grok, OAuth-backed providers, and local endpoints.
14
+ - Full-screen TUI with slash commands, model/workflow pickers, provider setup,
15
+ usage dashboards, tool cards, statusline integration, and resumable sessions.
16
+ - Agent task delegation through the `agent` tool and `/agent` command.
17
+ - Focused repo tools for `read`, `grep`, `glob`, `list`, `code_graph`,
18
+ `apply_patch`, `shell`, `cwd`, `explore`, web search, and memory recall.
19
+ - Workflow agents for implementation, review, debugging, maintenance, web
20
+ research, and heavier model routes.
21
+ - Optional Discord/channel/webhook/schedule integrations for remote or event
22
+ driven workflows.
6
23
 
7
24
  ## Requirements
8
25
 
@@ -24,37 +41,44 @@ mixdog --help
24
41
  ## Usage
25
42
 
26
43
  ```bash
27
- # Run the CLI from any project directory
44
+ # Run the TUI from any project directory
28
45
  mixdog
29
46
 
30
- # Build the Ink (React) TUI bundle
31
- npm run build:tui
32
-
33
- # Smoke test
47
+ # Run the basic smoke test
34
48
  npm run smoke
35
49
 
50
+ # Run the core smoke suite
51
+ npm run smoke:all
36
52
  ```
37
53
 
38
- ## Project layout
54
+ Inside the TUI, use `/providers` to configure model access, `/model` to switch
55
+ models, `/workflow` to select a workflow, `/agents` to inspect available
56
+ workflow agents, and `/agent` to manage active agent tasks.
39
57
 
40
- ```
58
+ ## Project Layout
59
+
60
+ ```text
41
61
  src/
42
- cli.mjs # entry point (bin: mixdog)
62
+ cli.mjs # CLI entry point (bin: mixdog)
43
63
  app.mjs # app wiring
44
- repl.mjs # REPL loop
45
- runtime/ # agent runtime
46
- tui/ # canonical Ink (React) TUI (bundled to dist/)
47
- lib/ ui/ hooks/ defaults/ vendor/
64
+ repl.mjs # plain REPL loop
65
+ runtime/ # provider runtime, tools, memory, channels
66
+ tui/ # canonical Ink TUI (bundled to dist/)
67
+ agents/ # workflow agent definitions
68
+ rules/ # Lead and agent instructions
48
69
  scripts/
49
- build-tui.mjs # esbuild bundle of the React TUI
50
- smoke.mjs # smoke test
70
+ smoke*.mjs # smoke checks
71
+ build-tui.mjs # esbuild bundle for the React TUI
51
72
  vendor/
52
- ink/ # Mixdog Ink renderer (alt-screen / cursor / scroll fixes)
73
+ ink/ # Mixdog Ink renderer
53
74
  ```
54
75
 
55
- ## Notes
76
+ ## Data And Configuration
77
+
78
+ Standalone Mixdog uses `~/.mixdog` as its home root. Runtime data lives in
79
+ `~/.mixdog/data` by default. Set `MIXDOG_HOME` to move the root, or
80
+ `MIXDOG_DATA_DIR` to override only the data directory.
56
81
 
57
- - `vendor/ink` is bundled directly into the TUI dist; the build does not rewrite installed dependencies.
58
- - Standalone Mixdog uses `~/.mixdog` as its home root. Runtime data lives in `~/.mixdog/data` by default. Set `MIXDOG_HOME` to move the root, or `MIXDOG_DATA_DIR` to override only the data directory.
59
- - Pi/Codex/OpenCode reference snapshots live outside this package under `C:\Project\refs`.
60
- - The TUI uses alt-screen mode and app-owned mouse wheel scrolling / drag selection by default so redraws during streaming do not clear selections. Set `MIXDOG_TUI_MOUSE=0` to opt into terminal-native mouse behavior.
82
+ The TUI uses alt-screen mode and app-owned mouse wheel scrolling / drag
83
+ selection by default. Set `MIXDOG_TUI_MOUSE=0` to opt into terminal-native mouse
84
+ behavior.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
- {
1
+ {
2
2
  "name": "mixdog",
3
- "version": "0.8.1",
3
+ "version": "0.9.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Standalone mixdog coding-agent CLI/TUI workspace.",
@@ -25,7 +25,6 @@
25
25
  },
26
26
  "files": [
27
27
  "README.md",
28
- "docs/",
29
28
  "scripts/",
30
29
  "src/",
31
30
  "vendor/"
@@ -42,32 +41,39 @@
42
41
  "smoke:loop:report": "node scripts/smoke-loop-report.mjs",
43
42
  "smoke:tools": "node scripts/tool-smoke.mjs",
44
43
  "smoke:output": "node scripts/output-style-smoke.mjs",
44
+ "test:toolcall": "node --test scripts/toolcall-args-test.mjs",
45
+ "test:providers": "node --test scripts/provider-toolcall-test.mjs",
45
46
  "failures": "node scripts/tool-failures.mjs",
47
+ "trace:llm": "node scripts/llm-trace-summary.mjs",
46
48
  "build:tui": "node scripts/build-tui.mjs"
47
49
  },
48
- "engines": {
49
- "node": ">=22.0.0"
50
- },
50
+ "engines": {
51
+ "node": ">=22.0.0"
52
+ },
51
53
  "dependencies": {
52
- "@anthropic-ai/sdk": "^0.105.0",
53
- "@google/generative-ai": "^0.24.1",
54
- "@huggingface/transformers": "^3.8.1",
55
- "@modelcontextprotocol/sdk": "^1.29.0",
56
- "@mozilla/readability": "^0.6.0",
57
- "diff": "^9.0.0",
58
- "discord.js": "^14.26.4",
59
- "ink": "^7.1.0",
60
- "jsdom": "^26.1.0",
61
- "marked": "^14.1.4",
62
- "node-cron": "^4.5.0",
63
- "openai": "^6.44.0",
64
- "pg": "^8.22.0",
65
- "puppeteer-core": "^25.2.0",
66
- "react": "^19.2.7",
67
- "undici": "^8.5.0",
68
- "ws": "^8.21.0",
69
- "zod": "^3.25.76",
70
- "zod-to-json-schema": "^3.25.2"
54
+ "@anthropic-ai/sdk": "^0.105.0",
55
+ "@google/generative-ai": "^0.24.1",
56
+ "@huggingface/transformers": "^3.8.1",
57
+ "@modelcontextprotocol/sdk": "^1.29.0",
58
+ "@mozilla/readability": "^0.6.0",
59
+ "chalk": "^5.6.2",
60
+ "cli-highlight": "^2.1.11",
61
+ "diff": "^9.0.0",
62
+ "discord.js": "^14.26.4",
63
+ "ink": "^7.1.0",
64
+ "jsdom": "^26.1.0",
65
+ "marked": "^14.1.4",
66
+ "node-cron": "^4.5.0",
67
+ "openai": "^6.44.0",
68
+ "pg": "^8.22.0",
69
+ "puppeteer-core": "^25.2.0",
70
+ "react": "^19.2.7",
71
+ "string-width": "^8.2.1",
72
+ "strip-ansi": "^7.2.0",
73
+ "undici": "^8.5.0",
74
+ "wrap-ansi": "^10.0.0",
75
+ "ws": "^8.21.0",
76
+ "zod": "^3.25.76"
71
77
  },
72
78
  "overrides": {
73
79
  "discord.js": {
@@ -78,6 +84,6 @@
78
84
  }
79
85
  },
80
86
  "devDependencies": {
81
- "esbuild": "^0.28.1"
82
- }
83
- }
87
+ "esbuild": "^0.28.1"
88
+ }
89
+ }
@@ -0,0 +1,30 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { readFileSync } from 'node:fs';
3
+
4
+ const src = readFileSync('src/standalone/folder-dialog.mjs', 'utf8');
5
+ const fn = src.match(/function powershellScript[\s\S]*?return \[([\s\S]*?)\]\.join/);
6
+ if (!fn) throw new Error('parse failed');
7
+ // Re-eval powershellScript by importing - use dynamic compile
8
+ const modUrl = new URL('../src/standalone/folder-dialog.mjs', import.meta.url);
9
+ // Call pickFolder with a hook - instead duplicate minimal import
10
+ const { pickFolder } = await import(modUrl.href);
11
+
12
+ const child = spawn('powershell.exe', [
13
+ '-NoLogo', '-NoProfile', '-STA', '-Command',
14
+ [
15
+ '$ErrorActionPreference = "Continue"',
16
+ 'try {',
17
+ ...readFileSync('src/standalone/folder-dialog.mjs', 'utf8')
18
+ .split('\n')
19
+ .filter((l) => l.includes('Add-Type -AssemblyName') || l.includes('Add-Type -TypeDefinition') || l.includes('GetDialogOwnerCenter')),
20
+ '} catch { Write-Error $_; exit 1 }',
21
+ ].join('; '),
22
+ ], { stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
23
+
24
+ let err = '';
25
+ child.stderr.on('data', (d) => { err += d.toString(); });
26
+ child.on('close', (code) => {
27
+ console.log('code', code);
28
+ console.log(err.slice(0, 2000));
29
+ });
30
+
@@ -0,0 +1,388 @@
1
+ #!/usr/bin/env node
2
+ // Focused parallelism smoke for the agent spawn fanout.
3
+ //
4
+ // Goals validated here (no network, fake askSession):
5
+ // 1. A batch of independent spawns fired together each return a task_id
6
+ // *immediately* (sync return is fast and never blocks on prep/model).
7
+ // 2. The fanout returns all task_ids well before any single agent's work
8
+ // finishes — i.e. spawn returns are non-blocking.
9
+ // 3. ensureProvider() is collapsed: N same-provider spawns trigger at most
10
+ // one initProviders() pass (shared in-flight + already-registered guard).
11
+ // 3b. A provider CONFIG CHANGE still re-runs initProviders() (the de-dup is
12
+ // keyed on provider + effective-config signature, not on "is registered"),
13
+ // while an unchanged config is skipped.
14
+ // 4. A wedged prep step trips the independent spawn-prep cap even when the
15
+ // first-response watchdog is explicitly disabled (firstResponseTimeoutMs:0).
16
+ // 5. spawnPrepTimeoutMs:0 disables the prep cap even when an env default cap
17
+ // is set (explicit per-call override beats the env default).
18
+ //
19
+ // Run: node scripts/agent-parallel-smoke.mjs
20
+ import { mkdtempSync, mkdirSync, rmSync } from 'node:fs';
21
+ import { join } from 'node:path';
22
+ import { tmpdir } from 'node:os';
23
+ import {
24
+ closeSession,
25
+ getSession,
26
+ getSessionLastProgressAt,
27
+ getSessionRuntime,
28
+ enqueuePendingMessage,
29
+ listSessions,
30
+ } from '../src/runtime/agent/orchestrator/session/manager.mjs';
31
+ import {
32
+ getProvider as realGetProvider,
33
+ initProviders as realInitProviders,
34
+ } from '../src/runtime/agent/orchestrator/providers/registry.mjs';
35
+
36
+ // Trace flush is irrelevant here and must never hold the loop open.
37
+ process.env.MIXDOG_AGENT_TRACE_DISABLE = '1';
38
+ // Set a real env prep-cap BEFORE importing agent-tool.mjs so its module-load
39
+ // `DEFAULT_SPAWN_PREP_TIMEOUT_MS` actually captures this value — that is what
40
+ // makes the "spawnPrepTimeoutMs:0 disables prep even with an env default"
41
+ // assertion below genuine. Kept large enough that normal (fast) prep never
42
+ // trips it, but small enough that a deliberately slow 200ms prep would.
43
+ const ENV_PREP_CAP_MS = 150;
44
+ process.env.MIXDOG_AGENT_SPAWN_PREP_TIMEOUT_MS = String(ENV_PREP_CAP_MS);
45
+ // Dynamic import AFTER the env is set (static imports hoist and would capture
46
+ // the default before this line runs).
47
+ const { createStandaloneAgent } = await import('../src/standalone/agent-tool.mjs');
48
+
49
+ const root = mkdtempSync(join(tmpdir(), 'mixdog-agent-parallel-'));
50
+ const dataDir = join(root, '.mixdog-data');
51
+ mkdirSync(dataDir, { recursive: true });
52
+
53
+ function assert(condition, message) {
54
+ if (!condition) throw new Error(message);
55
+ }
56
+ function sleep(ms) { return new Promise((r) => setTimeout(r, ms)); }
57
+ function taskId(text) { return String(text).match(/agent task: (\S+)/)?.[1] || null; }
58
+
59
+ // Wrap the REAL registry so createSession()'s internal getProvider() resolves a
60
+ // genuine provider instance, while we still count initProviders() passes and can
61
+ // simulate "not yet registered" to exercise ensureProvider's collapse path.
62
+ let initProvidersCalls = 0;
63
+ let forceProviderMiss = false;
64
+ const reg = {
65
+ getProvider(name) { return forceProviderMiss ? undefined : realGetProvider(name); },
66
+ async initProviders(config) {
67
+ initProvidersCalls += 1;
68
+ await sleep(5); // simulate a small async cost
69
+ return realInitProviders(config);
70
+ },
71
+ };
72
+
73
+ // Mutable provider config so a regression test can change it and assert the
74
+ // signature-keyed ensureProvider() re-runs initProviders().
75
+ let providerConfig = { 'openai-oauth': { enabled: true } };
76
+ const cfgMod = {
77
+ loadConfig() {
78
+ return {
79
+ providers: providerConfig,
80
+ agents: {
81
+ worker: { provider: 'openai-oauth', model: 'gpt-5.5', effort: 'low', fast: true },
82
+ reviewer: { provider: 'openai-oauth', model: 'gpt-5.5', effort: 'low' },
83
+ debugger: { provider: 'openai-oauth', model: 'gpt-5.5', effort: 'low' },
84
+ },
85
+ presets: [
86
+ { id: 'fake-worker', name: 'Fake Worker', provider: 'openai-oauth', model: 'gpt-5.5', tools: 'full', effort: 'low', fast: true },
87
+ ],
88
+ };
89
+ },
90
+ resolveRuntimeSpec(preset, ctx) {
91
+ return { lane: 'agent', scopeKey: `parallel:${ctx.agentId}`, provider: preset.provider, model: preset.model };
92
+ },
93
+ };
94
+
95
+ const askStartedAt = [];
96
+ let askConcurrency = 0;
97
+ let maxAskConcurrency = 0;
98
+ async function fakeAskSession(sessionId, prompt) {
99
+ const session = getSession(sessionId);
100
+ if (session) { session.status = 'running'; session.lastStreamDeltaAt = Date.now(); }
101
+ askStartedAt.push(Date.now());
102
+ askConcurrency += 1;
103
+ maxAskConcurrency = Math.max(maxAskConcurrency, askConcurrency);
104
+ try {
105
+ await sleep(300); // each agent's "work" lasts noticeably longer than spawn return
106
+ return { content: `ack ${session?.role || 'worker'}` };
107
+ } finally {
108
+ askConcurrency -= 1;
109
+ if (session) { session.status = 'idle'; session.lastStreamDeltaAt = Date.now(); }
110
+ }
111
+ }
112
+
113
+ const mgr = {
114
+ getSession,
115
+ listSessions,
116
+ closeSession,
117
+ getSessionRuntime,
118
+ enqueuePendingMessage,
119
+ getSessionLastProgressAt,
120
+ askSession: fakeAskSession,
121
+ };
122
+
123
+ const agent = createStandaloneAgent({ cfgMod, reg, mgr, dataDir, cwd: root });
124
+
125
+ async function waitJob(out, pattern, label, tries = 60) {
126
+ const id = taskId(out);
127
+ assert(id, `missing task ID for ${label}: ${out}`);
128
+ let last = '';
129
+ for (let i = 0; i < tries; i += 1) {
130
+ last = await agent.execute({ type: 'read', task_id: id }, { invocationSource: 'model-tool', cwd: root });
131
+ if (pattern.test(last)) return last;
132
+ if (/status: error/.test(last)) return last;
133
+ await sleep(50);
134
+ }
135
+ throw new Error(`${label} did not finish with ${pattern}: ${last}`);
136
+ }
137
+
138
+ async function main() {
139
+ // Register the real provider once so createSession() can resolve it.
140
+ await realInitProviders({ 'openai-oauth': { enabled: true } });
141
+
142
+ // --- 1+2: parallel spawns return task_ids fast and non-blocking ---
143
+ const batchSize = 6;
144
+ const t0 = Date.now();
145
+ const outs = await Promise.all(
146
+ Array.from({ length: batchSize }, (_, i) => agent.execute({
147
+ type: 'spawn',
148
+ role: i % 2 === 0 ? 'worker' : 'reviewer',
149
+ tag: `par${i}`,
150
+ cwd: root,
151
+ prompt: `parallel task ${i}`,
152
+ }, { invocationSource: 'model-tool', cwd: root })),
153
+ );
154
+ const spawnReturnMs = Date.now() - t0;
155
+ assert(outs.every((o) => /agent task:/.test(o)), `all spawns must return task ids: ${outs.join('\n---\n')}`);
156
+ assert(outs.every((o) => /status: running/.test(o)), 'spawns must report running immediately');
157
+ // The whole batch must return long before any single agent finishes (300ms each).
158
+ assert(spawnReturnMs < 250, `parallel spawn return too slow (${spawnReturnMs}ms) — fanout is blocking`);
159
+
160
+ // Wait for all to finish; they must have overlapped.
161
+ await Promise.all(outs.map((o, i) => waitJob(o, /ack (worker|reviewer)/, `parallel ${i}`)));
162
+ assert(maxAskConcurrency >= 2, `agents did not overlap; maxAskConcurrency=${maxAskConcurrency}`);
163
+
164
+ // --- 3: provider init collapsed across the first fanout ---
165
+ // ensureProvider has no completed-skip entry yet (first run this process), so
166
+ // the batch DOES init once — but the in-flight collapse must keep it to a
167
+ // SINGLE initProviders() pass across all 6 spawns, not one per spawn.
168
+ assert(initProvidersCalls === 1, `first fanout must share a single init; calls=${initProvidersCalls}`);
169
+
170
+ // Force getProvider() to report a miss across a parallel batch so the
171
+ // completed-skip cannot short-circuit; every spawn routes through the init
172
+ // path again, but the in-flight collapse must still produce exactly ONE more
173
+ // init for the batch (before+1).
174
+ forceProviderMiss = true;
175
+ const beforeMissBatch = initProvidersCalls;
176
+ const initBatch = await Promise.all(
177
+ Array.from({ length: 4 }, (_, i) => agent.execute({
178
+ type: 'spawn',
179
+ role: 'worker',
180
+ tag: `init${i}`,
181
+ cwd: root,
182
+ prompt: `init task ${i}`,
183
+ }, { invocationSource: 'model-tool', cwd: root })),
184
+ );
185
+ await Promise.all(initBatch.map((o, i) => waitJob(o, /ack worker/, `init ${i}`)));
186
+ assert(initProvidersCalls === beforeMissBatch + 1,
187
+ `forced-miss fanout must share a single init; before=${beforeMissBatch} after=${initProvidersCalls}`);
188
+ forceProviderMiss = false;
189
+
190
+ // --- 3b: provider CONFIG CHANGE must re-run initProviders() ---
191
+ // The completed-skip cache is keyed on provider + effective-config signature,
192
+ // not on "is the provider registered". The provider stays registered here, so
193
+ // a registered-only fast path would WRONGLY skip init after a config edit.
194
+ // Changing the config must flip the signature and force exactly one new init.
195
+ const callsBeforeChange = initProvidersCalls;
196
+ // Same config first: must be skipped (no new init).
197
+ await waitJob(await agent.execute({
198
+ type: 'spawn', role: 'worker', tag: 'cfgSame', cwd: root, prompt: 'cfg same',
199
+ }, { invocationSource: 'model-tool', cwd: root }), /ack worker/, 'cfg same');
200
+ assert(initProvidersCalls === callsBeforeChange,
201
+ `unchanged config must not re-init; before=${callsBeforeChange} after=${initProvidersCalls}`);
202
+ // Now mutate the provider config and spawn again → must re-init once.
203
+ providerConfig = { 'openai-oauth': { enabled: true, baseUrl: 'https://changed.example' } };
204
+ await waitJob(await agent.execute({
205
+ type: 'spawn', role: 'worker', tag: 'cfgChanged', cwd: root, prompt: 'cfg changed',
206
+ }, { invocationSource: 'model-tool', cwd: root }), /ack worker/, 'cfg changed');
207
+ assert(initProvidersCalls === callsBeforeChange + 1,
208
+ `config change must trigger exactly one re-init; before=${callsBeforeChange} after=${initProvidersCalls}`);
209
+
210
+ // --- 3c: A(slow) -> B(superseded) -> C(latest) ---
211
+ // Three rapid-fire config generations on the same provider:
212
+ // A: baseUrl 'gen-a', init is SLOW (200ms)
213
+ // B: baseUrl 'gen-b', requested while A is still running → SUPERSEDED by C
214
+ // C: baseUrl 'gen-c', the LATEST config, init fast (20ms)
215
+ // Two invariants the guard must hold:
216
+ // (i) the registry ends on the LATEST config (C) — no stale init lands last
217
+ // (ii) NO spawn (incl. the superseded B) runs prepareSpawn/askSession before
218
+ // the LATEST init that was current at its request time has completed.
219
+ // A superseded request must not resolve early against an unprepared
220
+ // provider — it must transitively wait for C.
221
+ const raceRoot = mkdtempSync(join(tmpdir(), 'mixdog-agent-race-'));
222
+ const raceDataDir = join(raceRoot, '.mixdog-data');
223
+ mkdirSync(raceDataDir, { recursive: true });
224
+ let lastAppliedConfig = null; // last config initProviders() actually applied
225
+ let raceInitCalls = 0;
226
+ let providerReadyGen = null; // signature most recently made live
227
+ const askViolations = [];
228
+ const raceReg = {
229
+ getProvider() { return undefined; }, // always force the init path
230
+ async initProviders(config) {
231
+ raceInitCalls += 1;
232
+ const url = config?.['openai-oauth']?.baseUrl || 'base';
233
+ await sleep(url === 'gen-a' ? 200 : 20); // A slow, others fast
234
+ lastAppliedConfig = url;
235
+ providerReadyGen = url;
236
+ },
237
+ };
238
+ let raceConfig = { providers: { 'openai-oauth': { enabled: true, baseUrl: 'gen-a' } } };
239
+ // Each spawn records which config gen was the LATEST at its spawn time; the
240
+ // fake askSession asserts the provider is ready (init completed) before it
241
+ // runs. If a spawn proceeds before ANY init completed, providerReadyGen is
242
+ // null → violation.
243
+ const raceCfgMod = {
244
+ loadConfig() {
245
+ return {
246
+ providers: raceConfig.providers,
247
+ agents: { worker: { provider: 'openai-oauth', model: 'gpt-5.5', effort: 'low' } },
248
+ presets: [{ id: 'fake-worker', name: 'Fake Worker', provider: 'openai-oauth', model: 'gpt-5.5', tools: 'full', effort: 'low' }],
249
+ };
250
+ },
251
+ resolveRuntimeSpec(preset, ctx) {
252
+ return { lane: 'agent', scopeKey: `race:${ctx.agentId}`, provider: preset.provider, model: preset.model };
253
+ },
254
+ };
255
+ async function raceAsk(sessionId, prompt) {
256
+ // Provider MUST be ready (some init completed) before any spawn runs.
257
+ if (providerReadyGen === null) {
258
+ askViolations.push(`${prompt}: ran before any provider init completed`);
259
+ }
260
+ const session = getSession(sessionId);
261
+ if (session) { session.status = 'running'; session.lastStreamDeltaAt = Date.now(); }
262
+ try { await sleep(10); return { content: `ack worker (${providerReadyGen})` }; }
263
+ finally { if (session) { session.status = 'idle'; session.lastStreamDeltaAt = Date.now(); } }
264
+ }
265
+ const raceMgr = { ...mgr, askSession: raceAsk };
266
+ const raceAgent = createStandaloneAgent({ cfgMod: raceCfgMod, reg: raceReg, mgr: raceMgr, dataDir: raceDataDir, cwd: raceRoot });
267
+ // Fire A (slow), then B and C back-to-back while A is still running. B is
268
+ // superseded by C before A's chain link releases.
269
+ const aOut = await raceAgent.execute({
270
+ type: 'spawn', role: 'worker', tag: 'raceA', cwd: raceRoot, prompt: 'race A',
271
+ spawnPrepTimeoutMs: 0, // testing init serialization, not the prep cap
272
+ }, { invocationSource: 'model-tool', cwd: raceRoot });
273
+ // Let A's deferred job reach ensureProvider and START its slow (200ms) init,
274
+ // so B/C arrive while A's init is genuinely in flight — this is what makes the
275
+ // "slow A completes and would clobber the newer config" path real. With the
276
+ // per-provider serialization, the latest (C) still lands last.
277
+ await sleep(60);
278
+ raceConfig = { providers: { 'openai-oauth': { enabled: true, baseUrl: 'gen-b' } } };
279
+ const bOut = await raceAgent.execute({
280
+ type: 'spawn', role: 'worker', tag: 'raceB', cwd: raceRoot, prompt: 'race B',
281
+ spawnPrepTimeoutMs: 0,
282
+ }, { invocationSource: 'model-tool', cwd: raceRoot });
283
+ raceConfig = { providers: { 'openai-oauth': { enabled: true, baseUrl: 'gen-c' } } };
284
+ const cOut = await raceAgent.execute({
285
+ type: 'spawn', role: 'worker', tag: 'raceC', cwd: raceRoot, prompt: 'race C',
286
+ spawnPrepTimeoutMs: 0,
287
+ }, { invocationSource: 'model-tool', cwd: raceRoot });
288
+ await Promise.all([
289
+ waitJob(aOut, /ack worker/, 'race A'),
290
+ waitJob(bOut, /ack worker/, 'race B'),
291
+ waitJob(cOut, /ack worker/, 'race C'),
292
+ ]);
293
+ // Give any (incorrectly) un-serialized slow A init time to land last.
294
+ await sleep(250);
295
+ // (i) registry ends on the latest config C.
296
+ assert(lastAppliedConfig === 'gen-c',
297
+ `stale init overwrote newer config; lastApplied=${lastAppliedConfig}`);
298
+ // (ii) no spawn ran before the provider was ready (incl. superseded B).
299
+ assert(askViolations.length === 0,
300
+ `spawn ran before latest provider init completed: ${askViolations.join('; ')}`);
301
+ // The superseded B must have observed a READY provider that is the latest
302
+ // (gen-c), never gen-a/gen-b stale-then-proceed.
303
+ const bResult = await raceAgent.execute({ type: 'read', task_id: taskId(bOut) }, { invocationSource: 'model-tool', cwd: raceRoot });
304
+ assert(/ack worker \(gen-c\)/.test(bResult),
305
+ `superseded B must proceed only after latest (gen-c) init; got ${bResult}`);
306
+ // B and C must NOT have triggered their own separate inits landing last — the
307
+ // dedup must keep total inits small (A + the latest C = 2; B is dropped).
308
+ assert(raceInitCalls <= 2, `superseded gen must not add an extra init; raceInitCalls=${raceInitCalls}`);
309
+ raceAgent.closeAll('agent-parallel-smoke-race-end');
310
+ rmSync(raceRoot, { recursive: true, force: true });
311
+
312
+ // --- 4: spawn-prep cap fires even with firstResponseTimeoutMs:0 ---
313
+ // Dedicated agent whose provider init hangs forever, so prep can never
314
+ // resolve. The model watchdog is disabled (firstResponseTimeoutMs:0) but the
315
+ // independent prep cap must still abort the job so a single hung prep cannot
316
+ // wedge the whole fanout.
317
+ const hangRoot = mkdtempSync(join(tmpdir(), 'mixdog-agent-hang-'));
318
+ const hangDataDir = join(hangRoot, '.mixdog-data');
319
+ mkdirSync(hangDataDir, { recursive: true });
320
+ const hangReg = {
321
+ getProvider() { return undefined; }, // never registered → init runs
322
+ initProviders() { return new Promise(() => {}); }, // hangs forever
323
+ };
324
+ const hangAgent = createStandaloneAgent({ cfgMod, reg: hangReg, mgr, dataDir: hangDataDir, cwd: hangRoot });
325
+ const wedgeStart = Date.now();
326
+ const wedged = await hangAgent.execute({
327
+ type: 'spawn',
328
+ role: 'worker',
329
+ tag: 'wedge1',
330
+ cwd: hangRoot,
331
+ prompt: 'wedge prep',
332
+ firstResponseTimeoutMs: 0, // model watchdog disabled
333
+ spawnPrepTimeoutMs: 150, // but prep cap is short
334
+ }, { invocationSource: 'model-tool', cwd: hangRoot });
335
+ assert(/agent task:/.test(wedged), 'wedge spawn should still return a task id immediately');
336
+ // Spawn return itself must be immediate even though prep will hang.
337
+ assert(Date.now() - wedgeStart < 100, 'wedge spawn return must not block on hung prep');
338
+ const wedgeResult = await waitJob(wedged, /status: error|timed out/, 'wedge prep cap', 40);
339
+ assert(/timed out/.test(wedgeResult) || /status: error/.test(wedgeResult),
340
+ `prep cap did not abort hung spawn: ${wedgeResult}`);
341
+ try { hangAgent.closeAll('agent-parallel-smoke-hang-end'); } catch {}
342
+ rmSync(hangRoot, { recursive: true, force: true });
343
+
344
+ // --- 5: spawnPrepTimeoutMs:0 disables the prep cap even when an env default
345
+ // is set. The module captured ENV_PREP_CAP_MS (150ms) at load. A prep step
346
+ // that runs longer than that (300ms) would normally be aborted by the env
347
+ // cap, but the explicit per-call spawnPrepTimeoutMs:0 must win and let prep
348
+ // finish.
349
+ const slowRoot = mkdtempSync(join(tmpdir(), 'mixdog-agent-slowprep-'));
350
+ const slowDataDir = join(slowRoot, '.mixdog-data');
351
+ mkdirSync(slowDataDir, { recursive: true });
352
+ let slowInitDone = false;
353
+ const slowReg = {
354
+ getProvider() { return undefined; }, // force init path
355
+ async initProviders(config) {
356
+ await sleep(300); // longer than the 150ms env cap
357
+ slowInitDone = true;
358
+ return realInitProviders({ 'openai-oauth': { enabled: true }, ...config });
359
+ },
360
+ };
361
+ const slowAgent = createStandaloneAgent({ cfgMod, reg: slowReg, mgr, dataDir: slowDataDir, cwd: slowRoot });
362
+ const slowStart = Date.now();
363
+ const slowOut = await slowAgent.execute({
364
+ type: 'spawn',
365
+ role: 'worker',
366
+ tag: 'slowprep1',
367
+ cwd: slowRoot,
368
+ prompt: 'slow prep override',
369
+ spawnPrepTimeoutMs: 0, // explicit disable beats the env cap
370
+ }, { invocationSource: 'model-tool', cwd: slowRoot });
371
+ const slowResult = await waitJob(slowOut, /ack worker/, 'slow prep override', 40);
372
+ assert(/ack worker/.test(slowResult),
373
+ `spawnPrepTimeoutMs:0 must disable prep cap despite env default; got ${slowResult}`);
374
+ assert(slowInitDone, 'slow prep init should have completed, not been aborted by env cap');
375
+ assert(Date.now() - slowStart >= 280,
376
+ 'slow prep should have run its full duration (cap was disabled), not been cut short');
377
+ try { slowAgent.closeAll('agent-parallel-smoke-slowprep-end'); } catch {}
378
+ rmSync(slowRoot, { recursive: true, force: true });
379
+
380
+ process.stdout.write(`agent parallel smoke passed (spawnReturn=${spawnReturnMs}ms, maxConcurrency=${maxAskConcurrency}, initCalls=${initProvidersCalls})\n`);
381
+ }
382
+
383
+ try {
384
+ await main();
385
+ } finally {
386
+ try { agent.closeAll('agent-parallel-smoke-end'); } catch {}
387
+ rmSync(root, { recursive: true, force: true });
388
+ }