mixdog 1.4.3 → 1.4.5

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 (281) hide show
  1. package/package.json +1 -2
  2. package/src/cli.mjs +5 -1
  3. package/src/defaults/shipped-history.json +30 -2
  4. package/src/defaults/skills/browser-use/SKILL.md +148 -273
  5. package/src/defaults/skills/browser-use/references/devtools.md +14 -0
  6. package/src/defaults/skills/browser-use/references/page-flows.md +66 -0
  7. package/src/defaults/skills/browser-use/references/sign-in.md +70 -0
  8. package/src/defaults/skills/code-tidy/SKILL.md +60 -84
  9. package/src/defaults/skills/code-tidy/references/agent-cleanup.md +27 -2
  10. package/src/defaults/skills/computer-use/SKILL.md +145 -229
  11. package/src/defaults/skills/computer-use/references/flows.md +35 -0
  12. package/src/defaults/skills/computer-use/references/operations.md +22 -0
  13. package/src/defaults/skills/computer-use/references/platforms.md +12 -0
  14. package/src/defaults/skills/docx/SKILL.md +23 -31
  15. package/src/defaults/skills/docx/references/native-authoring.md +26 -3
  16. package/src/defaults/skills/docx/references/redlining.md +15 -0
  17. package/src/defaults/skills/image/SKILL.md +37 -77
  18. package/src/defaults/skills/image/references/prompt-forms.md +51 -0
  19. package/src/defaults/skills/image/references/text.md +6 -0
  20. package/src/defaults/skills/local-provider/SKILL.md +75 -105
  21. package/src/defaults/skills/local-provider/references/lifecycle.md +14 -0
  22. package/src/defaults/skills/local-provider/references/maintenance.md +19 -0
  23. package/src/defaults/skills/local-provider/references/recovery.md +30 -0
  24. package/src/defaults/skills/memory-management/SKILL.md +22 -21
  25. package/src/defaults/skills/pdf/SKILL.md +21 -23
  26. package/src/defaults/skills/pdf/references/blocks.md +20 -0
  27. package/src/defaults/skills/pdf/references/forms.md +12 -0
  28. package/src/defaults/skills/pdf/references/html.md +2 -2
  29. package/src/defaults/skills/pdf/references/ocr.md +7 -0
  30. package/src/defaults/skills/pdf/references/security.md +8 -0
  31. package/src/defaults/skills/pptx/SKILL.md +30 -109
  32. package/src/defaults/skills/pptx/references/audit.md +45 -0
  33. package/src/defaults/skills/pptx/references/brief-critique.md +47 -0
  34. package/src/defaults/skills/pptx/references/editing.md +24 -0
  35. package/src/defaults/skills/pptx/references/html.md +1 -1
  36. package/src/defaults/skills/pptx/references/script.md +33 -0
  37. package/src/defaults/skills/setup/SKILL.md +34 -102
  38. package/src/defaults/skills/setup/references/actions.md +73 -14
  39. package/src/defaults/skills/setup/references/surfaces.md +23 -8
  40. package/src/defaults/skills/setup-guide/SKILL.md +28 -115
  41. package/src/defaults/skills/setup-guide/references/features.md +36 -0
  42. package/src/defaults/skills/setup-guide/references/glossary.md +38 -0
  43. package/src/defaults/skills/setup-guide/references/workflow-models.md +62 -0
  44. package/src/defaults/skills/test-suite/SKILL.md +15 -127
  45. package/src/defaults/skills/test-suite/references/case-management.md +17 -9
  46. package/src/defaults/skills/test-suite/references/diagnose.md +23 -0
  47. package/src/defaults/skills/test-suite/references/prune.md +27 -0
  48. package/src/defaults/skills/test-suite/references/write.md +44 -0
  49. package/src/defaults/skills/video/SKILL.md +28 -42
  50. package/src/defaults/skills/video/references/prompting.md +31 -0
  51. package/src/defaults/skills/visualize/SKILL.md +73 -107
  52. package/src/defaults/skills/visualize/references/craft.md +1 -2
  53. package/src/defaults/skills/visualize/references/feedback.md +36 -0
  54. package/src/defaults/skills/visualize/references/showing.md +13 -0
  55. package/src/defaults/skills/xlsx/SKILL.md +23 -50
  56. package/src/defaults/skills/xlsx/references/editing.md +15 -0
  57. package/src/defaults/skills/xlsx/references/model-conventions.md +1 -1
  58. package/src/defaults/skills/xlsx/references/recalculation.md +37 -0
  59. package/src/defaults/skills/xlsx/references/report-design.md +18 -2
  60. package/src/lib/keychain-cjs.cjs +22 -1
  61. package/src/lib/rules-builder.cjs +1 -1
  62. package/src/rules/agent/AGENT.md +3 -0
  63. package/src/rules/agent-mode/MIXY.md +5 -3
  64. package/src/rules/lead/LEAD.md +3 -1
  65. package/src/runtime/agent/orchestrator/agent-runtime/cache-strategy.mjs +8 -30
  66. package/src/runtime/agent/orchestrator/agent-runtime/title-completion.mjs +5 -0
  67. package/src/runtime/agent/orchestrator/mcp/oauth-request.mjs +21 -2
  68. package/src/runtime/agent/orchestrator/providers/account-pool.mjs +3 -0
  69. package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +4 -3
  70. package/src/runtime/agent/orchestrator/providers/anthropic-api-request.mjs +11 -1
  71. package/src/runtime/agent/orchestrator/providers/anthropic-api-transport.mjs +2 -0
  72. package/src/runtime/agent/orchestrator/providers/anthropic-message-threads.mjs +583 -0
  73. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-client-version.mjs +1 -1
  74. package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +81 -19
  75. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events/content-block-start.mjs +4 -0
  76. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-outcome.mjs +2 -0
  77. package/src/runtime/agent/orchestrator/providers/anthropic-sse.mjs +180 -13
  78. package/src/runtime/agent/orchestrator/providers/anthropic-turn-result.mjs +2 -0
  79. package/src/runtime/agent/orchestrator/providers/anthropic.mjs +58 -6
  80. package/src/runtime/agent/orchestrator/providers/cursor-wire.mjs +4 -2
  81. package/src/runtime/agent/orchestrator/providers/custom-provider-config.mjs +121 -9
  82. package/src/runtime/agent/orchestrator/providers/custom-provider.mjs +4 -1
  83. package/src/runtime/agent/orchestrator/providers/gemini-error-contract.mjs +6 -6
  84. package/src/runtime/agent/orchestrator/providers/gemini-model-redirect.mjs +44 -0
  85. package/src/runtime/agent/orchestrator/providers/gemini-reasoning-relay.mjs +5 -0
  86. package/src/runtime/agent/orchestrator/providers/gemini-request-body.mjs +34 -5
  87. package/src/runtime/agent/orchestrator/providers/gemini-response.mjs +10 -0
  88. package/src/runtime/agent/orchestrator/providers/gemini-schema.mjs +11 -6
  89. package/src/runtime/agent/orchestrator/providers/gemini-sdk-request.mjs +4 -100
  90. package/src/runtime/agent/orchestrator/providers/gemini-stream.mjs +3 -227
  91. package/src/runtime/agent/orchestrator/providers/gemini.mjs +226 -118
  92. package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +11 -1
  93. package/src/runtime/agent/orchestrator/providers/lib/claude-bridge-schema.mjs +15 -3
  94. package/src/runtime/agent/orchestrator/providers/lib/gemini-model-catalog.mjs +2 -1
  95. package/src/runtime/agent/orchestrator/providers/lib/generation-window.mjs +9 -0
  96. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-send.mjs +9 -1
  97. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/stream-result.mjs +2 -0
  98. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/stream-state.mjs +5 -0
  99. package/src/runtime/agent/orchestrator/providers/openai-compat-options.mjs +3 -0
  100. package/src/runtime/agent/orchestrator/providers/openai-compat-response-normalization.mjs +2 -0
  101. package/src/runtime/agent/orchestrator/providers/openai-compat-responses.mjs +10 -1
  102. package/src/runtime/agent/orchestrator/providers/openai-direct-request.mjs +5 -28
  103. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-events.mjs +3 -0
  104. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-outcome.mjs +2 -0
  105. package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +50 -28
  106. package/src/runtime/agent/orchestrator/providers/openai-ws-response-state.mjs +9 -2
  107. package/src/runtime/agent/orchestrator/providers/openai-ws-stream/socket-handlers.mjs +14 -10
  108. package/src/runtime/agent/orchestrator/providers/openai-ws.mjs +1 -3
  109. package/src/runtime/agent/orchestrator/providers/openrouter-provider-routing.mjs +28 -0
  110. package/src/runtime/agent/orchestrator/providers/openrouter.mjs +4 -1
  111. package/src/runtime/agent/orchestrator/providers/registry.mjs +30 -25
  112. package/src/runtime/agent/orchestrator/providers/stream-json-pool/worker-slots/slot-spawn.mjs +8 -3
  113. package/src/runtime/agent/orchestrator/providers/vertex-ai-maas.mjs +2 -2
  114. package/src/runtime/agent/orchestrator/runtime-core/ask-user-result.mjs +66 -0
  115. package/src/runtime/agent/orchestrator/runtime-core/config-helpers.mjs +4 -5
  116. package/src/runtime/agent/orchestrator/runtime-core/goal-tool-defs.mjs +2 -2
  117. package/src/runtime/agent/orchestrator/runtime-core/provider-request-tools.mjs +15 -8
  118. package/src/runtime/agent/orchestrator/runtime-core/session-title.mjs +1 -0
  119. package/src/runtime/agent/orchestrator/runtime-core/todo-list.mjs +9 -32
  120. package/src/runtime/agent/orchestrator/runtime-core/todo-tool-defs.mjs +4 -5
  121. package/src/runtime/agent/orchestrator/session/compact/summary-route.mjs +1 -3
  122. package/src/runtime/agent/orchestrator/session/loop/compact-policy.mjs +5 -2
  123. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/todo-check.mjs +2 -17
  124. package/src/runtime/agent/orchestrator/session/loop/usage.mjs +7 -3
  125. package/src/runtime/agent/orchestrator/session/manager/ask-turn-settle.mjs +9 -2
  126. package/src/runtime/agent/orchestrator/session/manager/runtime-liveness.mjs +8 -1
  127. package/src/runtime/agent/orchestrator/session/manager/session-close.mjs +26 -13
  128. package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +4 -5
  129. package/src/runtime/agent/orchestrator/session/manager/usage-metrics.mjs +16 -5
  130. package/src/runtime/agent/orchestrator/session/store/lifecycle-barriers.mjs +22 -1
  131. package/src/runtime/agent/orchestrator/session/store/live-state.mjs +4 -0
  132. package/src/runtime/agent/orchestrator/session/store.mjs +12 -6
  133. package/src/runtime/agent/orchestrator/tools/builtin/cache-layers.mjs +11 -9
  134. package/src/runtime/agent/orchestrator/tools/builtin/grep-formatting.mjs +2 -8
  135. package/src/runtime/agent/orchestrator/tools/builtin/lib/search-input-helpers.mjs +1 -9
  136. package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-output-silence.mjs +64 -0
  137. package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-task-output.mjs +20 -6
  138. package/src/runtime/agent/orchestrator/tools/builtin/local-search-telemetry.mjs +2 -2
  139. package/src/runtime/agent/orchestrator/tools/builtin/native-search-client.mjs +1 -1
  140. package/src/runtime/agent/orchestrator/tools/builtin/runtime-capabilities.mjs +12 -3
  141. package/src/runtime/agent/orchestrator/tools/builtin/task-tool.mjs +12 -1
  142. package/src/runtime/agent/orchestrator/tools/code-graph/ast-calls.mjs +9 -2
  143. package/src/runtime/agent/orchestrator/tools/code-graph/build.mjs +137 -7
  144. package/src/runtime/agent/orchestrator/tools/code-graph/calls-cache.mjs +43 -14
  145. package/src/runtime/agent/orchestrator/tools/code-graph/calls-sidecar-worker.mjs +33 -0
  146. package/src/runtime/agent/orchestrator/tools/code-graph/disk-cache.mjs +146 -11
  147. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +31 -24
  148. package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary/spawn-jsonl.mjs +172 -25
  149. package/src/runtime/agent/orchestrator/tools/code-graph/graph-model.mjs +100 -2
  150. package/src/runtime/agent/orchestrator/tools/code-graph/main-thread-slice.mjs +18 -0
  151. package/src/runtime/agent/orchestrator/tools/code-graph/mask-pool.mjs +219 -0
  152. package/src/runtime/agent/orchestrator/tools/code-graph/mask-worker.mjs +12 -0
  153. package/src/runtime/agent/orchestrator/tools/code-graph/memory-cache.mjs +6 -1
  154. package/src/runtime/agent/orchestrator/tools/code-graph/modes/calls.mjs +9 -2
  155. package/src/runtime/agent/orchestrator/tools/code-graph/modes/dependents.mjs +5 -1
  156. package/src/runtime/agent/orchestrator/tools/code-graph/modes/structure.mjs +8 -2
  157. package/src/runtime/agent/orchestrator/tools/code-graph/modes/symbols.mjs +14 -11
  158. package/src/runtime/agent/orchestrator/tools/code-graph/search-references.mjs +41 -18
  159. package/src/runtime/agent/orchestrator/tools/code-graph/search.mjs +391 -83
  160. package/src/runtime/agent/orchestrator/tools/code-graph/symbol-index.mjs +109 -9
  161. package/src/runtime/agent/orchestrator/tools/code-graph/text-mask.mjs +73 -29
  162. package/src/runtime/agent/orchestrator/tools/code-graph-prewarm-worker.mjs +6 -5
  163. package/src/runtime/agent/orchestrator/tools/lib/native-spawn-client.mjs +7 -3
  164. package/src/runtime/channels/lib/crash-log.mjs +21 -1
  165. package/src/runtime/channels/lib/routines-db.mjs +35 -0
  166. package/src/runtime/channels/lib/schedules-db.mjs +4 -0
  167. package/src/runtime/channels/lib/webhooks-db.mjs +4 -0
  168. package/src/runtime/channels/lib/worker-main.mjs +8 -25
  169. package/src/runtime/computer-bridge/action-schema.mjs +2 -2
  170. package/src/runtime/computer-bridge/core-actions.mjs +16 -2
  171. package/src/runtime/computer-bridge/result-canonical.mjs +6 -0
  172. package/src/runtime/media/jobs.mjs +5 -0
  173. package/src/runtime/media/store.mjs +146 -3
  174. package/src/runtime/memory/tool-defs.mjs +1 -1
  175. package/src/runtime/office/core/office-write-ledger.mjs +2 -2
  176. package/src/runtime/shared/agent-reap-state.mjs +19 -0
  177. package/src/runtime/shared/desktop-notice-host.d.mts +13 -0
  178. package/src/runtime/shared/desktop-notice-host.mjs +87 -0
  179. package/src/runtime/shared/file-lock.mjs +2 -2
  180. package/src/runtime/shared/heap-cap.mjs +9 -11
  181. package/src/runtime/shared/llm/http-agent.mjs +11 -1
  182. package/src/runtime/shared/llm/system-proxy.mjs +100 -25
  183. package/src/runtime/shared/llm/usage-accounting.mjs +121 -19
  184. package/src/runtime/shared/llm/usage-context.mjs +3 -3
  185. package/src/runtime/shared/llm/usage-ledger-quota.mjs +2 -0
  186. package/src/runtime/shared/llm/usage-ledger-requests.mjs +190 -0
  187. package/src/runtime/shared/llm/usage-ledger-rollup.mjs +7 -3
  188. package/src/runtime/shared/llm/usage-ledger-worker.mjs +2 -0
  189. package/src/runtime/shared/llm/usage-ledger.mjs +69 -1
  190. package/src/runtime/shared/llm/usage-request-status.mjs +48 -0
  191. package/src/runtime/shared/provider-accounts.mjs +22 -0
  192. package/src/runtime/shared/provider-auth-binding.mjs +2 -2
  193. package/src/runtime/shared/resource-admission.mjs +2 -2
  194. package/src/runtime/shared/root-async-context.mjs +51 -0
  195. package/src/runtime/shared/run-child.mjs +18 -1
  196. package/src/runtime/shared/slow-span.mjs +2 -2
  197. package/src/runtime/shared/tool-execution-owner.mjs +2 -2
  198. package/src/runtime/shared/tool-result-summary.mjs +1 -1
  199. package/src/runtime/shared/tool-work-units.mjs +2 -0
  200. package/src/runtime/shared/turn-snapshot-store.mjs +75 -18
  201. package/src/runtime/shared/turn-worktree-snapshot.mjs +38 -8
  202. package/src/runtime/shared/user-cwd.mjs +2 -2
  203. package/src/runtime/shared/worker-requests.mjs +3 -1
  204. package/src/runtime/shared/worktrees/lock.mjs +2 -2
  205. package/src/runtime/visualize-bridge/client.mjs +26 -4
  206. package/src/runtime/visualize-bridge/tool-defs.mjs +46 -5
  207. package/src/session-runtime/agent-home-delivery.mjs +76 -8
  208. package/src/session-runtime/agent-task-sessions.mjs +63 -22
  209. package/src/session-runtime/boot/apis.mjs +16 -0
  210. package/src/session-runtime/boot/begin.mjs +2 -0
  211. package/src/session-runtime/boot/tools.mjs +8 -2
  212. package/src/session-runtime/internal-tool-executor/ask-user-tool.mjs +3 -58
  213. package/src/session-runtime/media-api.mjs +15 -0
  214. package/src/session-runtime/model-route/route-persist.mjs +12 -4
  215. package/src/session-runtime/provider-models/row-hydration.mjs +2 -0
  216. package/src/session-runtime/provider-readiness.mjs +10 -2
  217. package/src/session-runtime/routine-owner.mjs +9 -3
  218. package/src/session-runtime/runtime-core.mjs +35 -8
  219. package/src/session-runtime/runtime-review-api.mjs +3 -1
  220. package/src/session-runtime/services/agent-task-status.mjs +29 -1
  221. package/src/session-runtime/services/agent-tool/close-flow.mjs +6 -1
  222. package/src/session-runtime/services/agent-tool/execute-resume.mjs +94 -0
  223. package/src/session-runtime/services/agent-tool/execute-send.mjs +77 -27
  224. package/src/session-runtime/services/agent-tool/execute-spawn.mjs +28 -7
  225. package/src/session-runtime/services/agent-tool/execute.mjs +6 -1
  226. package/src/session-runtime/services/agent-tool/helpers.mjs +11 -0
  227. package/src/session-runtime/services/agent-tool/job-views/job-render.mjs +13 -10
  228. package/src/session-runtime/services/agent-tool/job-views/session-progress.mjs +3 -0
  229. package/src/session-runtime/services/agent-tool/render.mjs +8 -1
  230. package/src/session-runtime/services/agent-tool/send-flow.mjs +1 -0
  231. package/src/session-runtime/services/agent-tool/spawn-flow/spawn-prep.mjs +6 -0
  232. package/src/session-runtime/services/agent-tool/spawn-flow/spawn-run.mjs +2 -1
  233. package/src/session-runtime/services/agent-tool/tag-registry/reaped-sessions.mjs +82 -0
  234. package/src/session-runtime/services/agent-tool/tag-registry/record-facts-worker.mjs +36 -0
  235. package/src/session-runtime/services/agent-tool/tag-registry.mjs +4 -0
  236. package/src/session-runtime/services/agent-tool/terminal-reaper/row-helpers.mjs +29 -0
  237. package/src/session-runtime/services/agent-tool/terminal-reaper/scan-admission.mjs +11 -3
  238. package/src/session-runtime/services/agent-tool/terminal-reaper/stale-rows.mjs +19 -8
  239. package/src/session-runtime/services/agent-tool/terminal-reaper.mjs +5 -2
  240. package/src/session-runtime/services/agent-tool/worker-index.mjs +1 -0
  241. package/src/session-runtime/services/channel-admin.mjs +44 -3
  242. package/src/session-runtime/services/daemon-crash-capture/daemon-exit-record.mjs +2 -2
  243. package/src/session-runtime/services/plugin-admin.mjs +46 -7
  244. package/src/session-runtime/services/provider-admin.mjs +5 -0
  245. package/src/session-runtime/session-create.mjs +5 -0
  246. package/src/session-runtime/setup-tool/agent-settings-actions.mjs +1 -1
  247. package/src/session-runtime/setup-tool/executor.mjs +1 -1
  248. package/src/session-runtime/setup-tool/extended-actions.mjs +1 -1
  249. package/src/session-runtime/setup-tool/settings-contract.mjs +4 -2
  250. package/src/session-runtime/usage-stats-api.mjs +120 -1
  251. package/src/session-runtime/workflow-agents-api/agent-connectors.mjs +36 -29
  252. package/src/session-runtime/workflow-agents-api/agent-editor.mjs +183 -23
  253. package/src/session-runtime/workspace/admission-gate.mjs +25 -7
  254. package/src/session-runtime/workspace/transitions.mjs +4 -0
  255. package/src/standalone/daemon-log.mjs +28 -4
  256. package/src/standalone/daemon-owner.mjs +41 -7
  257. package/src/standalone/daemon-work-gate.mjs +139 -0
  258. package/src/standalone/daemon.mjs +80 -11
  259. package/src/standalone/desktop-service-registry.mjs +11 -4
  260. package/src/standalone/session-client.mjs +57 -5
  261. package/src/standalone/session-protocol.mjs +6 -0
  262. package/src/standalone/session-service/agent-tree/agent-cancel.mjs +17 -1
  263. package/src/standalone/session-service/agent-tree.mjs +7 -0
  264. package/src/standalone/session-service/retention/busy.mjs +3 -2
  265. package/src/standalone/session-service/session-calls/session-turns.mjs +12 -5
  266. package/src/standalone/session-transport/call-route.mjs +10 -4
  267. package/src/standalone/session-transport/routes.mjs +21 -0
  268. package/src/standalone/session-transport/stack.mjs +3 -1
  269. package/src/standalone/session-transport.mjs +5 -0
  270. package/src/tui/app/model-picker/model-footer.mjs +1 -1
  271. package/src/tui/app/model-picker/provider-models-list.mjs +7 -3
  272. package/src/tui/app/model-picker/route-selection/fast-parameters.mjs +23 -3
  273. package/src/tui/app/model-picker/route-selection.mjs +1 -0
  274. package/src/tui/dist/index.mjs +536 -484
  275. package/src/tui/session/session-api/integrations.mjs +3 -0
  276. package/src/tui/session/session-api/media.mjs +5 -0
  277. package/src/tui/session/tool-approval-settle.mjs +24 -4
  278. package/src/tui/session/tool-approval.mjs +35 -10
  279. package/src/tui/session/turn.mjs +13 -0
  280. package/src/runtime/agent/orchestrator/providers/gemini-sdk-stream/cancellation.mjs +0 -71
  281. package/src/runtime/agent/orchestrator/providers/gemini-sdk-stream/reader.mjs +0 -108
@@ -91,19 +91,48 @@ export function readCallsSidecarPayload(file) {
91
91
  }
92
92
  }
93
93
 
94
- // Apply a payload onto a cache-loaded graph. Fingerprint mismatch → the file
95
- // changed since the sidecar was written, so its calls stay unknown.
96
- export function applyCallsSidecarToGraph(graph, payload) {
97
- const files = payload?.files;
98
- if (!files || !graph?.nodes) return 0;
99
- let applied = 0;
100
- for (const node of graph.nodes.values()) {
101
- const entry = files[node.rel];
102
- if (!Array.isArray(entry) || entry.length !== 2) continue;
103
- if (entry[0] !== (node.fingerprint || '')) continue;
104
- if (!Array.isArray(entry[1])) continue;
105
- node.calls = entry[1];
106
- applied += 1;
94
+ const NO_CALLS_KEY = Symbol('no calls key');
95
+
96
+ // Validate and measure one `[rel, [fp, calls], size?]` sidecar entry against a
97
+ // cache-loaded graph WITHOUT touching it; null when it is not accepted.
98
+ // Fingerprint mismatch → the file changed since the sidecar was written, so
99
+ // its calls stay unknown. The record carries the list's size (the entry's
100
+ // measured `size`, else `sizeOf(calls)`) and the size of what it replaces, so
101
+ // installing never walks a call tuple.
102
+ export function stageCallsSidecarEntry(graph, [rel, entry, size], sizeOf) {
103
+ const node = graph.nodes.get(rel);
104
+ if (!node) return null;
105
+ if (!Array.isArray(entry) || entry.length !== 2) return null;
106
+ if (entry[0] !== (node.fingerprint || '')) return null;
107
+ if (!Array.isArray(entry[1])) return null;
108
+ const record = { node, calls: entry[1], bytes: Number(size ?? sizeOf(entry[1])), replaced: null, replacedBytes: 0 };
109
+ measureReplacedCalls(record, sizeOf);
110
+ return record;
111
+ }
112
+
113
+ // (Re)measure what a staged list replaces — an incremental build's re-parsed
114
+ // files already carry calls; a node without a `calls` key gains one.
115
+ export function measureReplacedCalls(record, sizeOf) {
116
+ const { node } = record;
117
+ const had = Object.hasOwn(node, 'calls');
118
+ record.replaced = had ? node.calls : NO_CALLS_KEY;
119
+ record.replacedBytes = had ? sizeOf(node.calls) : -(8 + sizeOf('calls'));
120
+ }
121
+
122
+ /** True when the node's `calls` changed since its record was measured. */
123
+ export function isStagedReplacementStale(record) {
124
+ const { node } = record;
125
+ return (Object.hasOwn(node, 'calls') ? node.calls : NO_CALLS_KEY) !== record.replaced;
126
+ }
127
+
128
+ // Install staged call lists in one synchronous step, so no query observes part
129
+ // of a payload: assignments and precomputed sizes only. `bytes` is the change
130
+ // in the graph's retained size: the staged lists minus what they replaced.
131
+ export function installCallsSidecarEntries(staged) {
132
+ let bytes = 0;
133
+ for (const record of staged) {
134
+ record.node.calls = record.calls;
135
+ bytes += record.bytes - record.replacedBytes;
107
136
  }
108
- return applied;
137
+ return { applied: staged.length, bytes };
109
138
  }
@@ -0,0 +1,33 @@
1
+ // Reads and parses one call-site sidecar off the daemon main thread and posts
2
+ // it back in small chunks: `{ entries: [[rel, [fp, calls], bytes], …] }` …
3
+ // `{ done: true }`. A chunk is a few thousand call tuples, so receiving one is
4
+ // a short main-thread stretch, where one 30+ MB JSON.parse (or a single
5
+ // structured clone of the whole parsed payload) held it for hundreds of ms.
6
+ // `bytes` is each call list's retained size under the graph size estimator.
7
+ // After each chunk the worker waits for the receiver's ack, so chunks arrive
8
+ // one per main-thread event-loop turn instead of being read back to back.
9
+ import { parentPort, workerData } from 'node:worker_threads';
10
+ import { readCallsSidecarPayload } from './calls-cache.mjs';
11
+ import { _estimateValueBytes } from './graph-model.mjs';
12
+
13
+ const CHUNK_TUPLES = 20_000;
14
+ const ack = () => new Promise((resolve) => parentPort.once('message', resolve));
15
+ const payload = readCallsSidecarPayload(workerData.file);
16
+ let entries = [];
17
+ let tuples = 0;
18
+ for (const [rel, entry] of Object.entries(payload?.files || {})) {
19
+ const calls = Array.isArray(entry) ? entry[1] : null;
20
+ entries.push([rel, entry, Array.isArray(calls) ? _estimateValueBytes(calls) : 0]);
21
+ tuples += Array.isArray(calls) ? calls.length + 1 : 1;
22
+ if (tuples >= CHUNK_TUPLES) {
23
+ parentPort.postMessage({ entries });
24
+ entries = [];
25
+ tuples = 0;
26
+ await ack();
27
+ }
28
+ }
29
+ if (entries.length) {
30
+ parentPort.postMessage({ entries });
31
+ await ack();
32
+ }
33
+ parentPort.postMessage({ done: true, found: Boolean(payload) });
@@ -5,6 +5,7 @@
5
5
 
6
6
  import { createHash } from 'node:crypto';
7
7
  import { join } from 'node:path';
8
+ import { Worker } from 'node:worker_threads';
8
9
  import {
9
10
  readdirSync,
10
11
  readFileSync,
@@ -37,15 +38,25 @@ import {
37
38
  RE_CALLS_CACHE_TMP,
38
39
  RE_CALLS_CACHE_LOCK,
39
40
  } from './constants.mjs';
40
- import { _serializeGraph } from './graph-model.mjs';
41
+ import {
42
+ _serializeGraph,
43
+ _estimateGraphBaseBytes,
44
+ _estimateValueBytes,
45
+ _noteGraphCallsHydrated,
46
+ } from './graph-model.mjs';
41
47
  import {
42
48
  callsSidecarPath,
43
49
  callsSidecarHash,
44
50
  buildCallsSidecarPayload,
45
51
  graphHasCallsToPersist,
46
52
  readCallsSidecarPayload,
47
- applyCallsSidecarToGraph,
53
+ installCallsSidecarEntries,
54
+ isStagedReplacementStale,
55
+ measureReplacedCalls,
56
+ stageCallsSidecarEntry,
48
57
  } from './calls-cache.mjs';
58
+ import { _mainThreadSlice } from './main-thread-slice.mjs';
59
+ import { runInRootAsyncContext } from '../../../../shared/root-async-context.mjs';
49
60
 
50
61
  const _diskCodeGraphCache = new Map();
51
62
  // Call-site sidecars waiting for the next persist, keyed by canonical cwd.
@@ -659,25 +670,149 @@ function _stageCallsSidecar(key, graph) {
659
670
  /**
660
671
  * Fill a cache-loaded graph's nodes with their persisted AST call sites.
661
672
  * Called by the callers/callees/references modes only — the first such query
662
- * of a process pays one sidecar read, every other mode pays nothing. Runs at
663
- * most once per graph object (the marker is cleared even on a miss, so a
664
- * missing/corrupt sidecar cannot be re-read on every query).
665
- * Returns the number of files hydrated.
673
+ * of a process pays one sidecar read, every other mode pays nothing. The file
674
+ * is read and parsed in a worker and received chunk by chunk, so the main
675
+ * thread never parses the whole payload. Resolves to the number of files
676
+ * hydrated.
677
+ *
678
+ * Concurrent queries share the attempt in flight. An attempt the reader
679
+ * COMPLETED installs every call list at once and marks the graph done — a
680
+ * missing/corrupt sidecar included, so it is not re-read on every query. An
681
+ * attempt that FAILED (reader crash, stall past its deadline, process
682
+ * shutdown) installed nothing and leaves the graph pending, so the next
683
+ * call-mode query retries instead of answering from half a sidecar forever.
666
684
  */
667
685
  export function hydrateGraphCallsFromSidecar(graph) {
668
- if (graph?._callsHydration !== 'pending') return 0;
669
- graph._callsHydration = 'done';
686
+ if (graph?._callsHydration !== 'pending') return Promise.resolve(0);
687
+ let running = _callsHydrations.get(graph);
688
+ if (!running) {
689
+ running = _hydrateGraphCalls(graph).finally(() => _callsHydrations.delete(graph));
690
+ _callsHydrations.set(graph, running);
691
+ }
692
+ return running;
693
+ }
694
+
695
+ const _callsHydrations = new WeakMap();
696
+
697
+ // Entries are collected while the reader streams, staged off the graph in
698
+ // time slices (validated and measured, including the lists they replace), and
699
+ // installed in one synchronous step that only assigns, once the reader
700
+ // acknowledged the whole file: no query ever sees part of a sidecar, and a
701
+ // failed attempt leaves nothing to roll back.
702
+ async function _hydrateGraphCalls(graph) {
670
703
  try {
671
704
  _loadDiskCodeGraphCache();
672
705
  const key = _canonicalGraphCwd(graph.cwd);
673
- const payload = _pendingCallsSidecars.get(key) || readCallsSidecarPayload(_callsSidecarFileFor(key));
674
- if (!payload) return 0; // old cache without a sidecar → calls stay null
675
- return applyCallsSidecarToGraph(graph, payload);
706
+ const pending = _pendingCallsSidecars.get(key);
707
+ const entries = pending ? Object.entries(pending.files || {}) : [];
708
+ if (!pending) {
709
+ // An old cache without a sidecar streams nothing → calls stay null.
710
+ await _streamCallsSidecar(_callsSidecarFileFor(key), (chunk) => {
711
+ for (const entry of chunk) entries.push(entry);
712
+ });
713
+ }
714
+ const slice = _mainThreadSlice();
715
+ const staged = [];
716
+ for (const entry of entries) {
717
+ const record = stageCallsSidecarEntry(graph, entry, _estimateValueBytes);
718
+ if (record) staged.push(record);
719
+ if (slice.expired()) await slice.yield();
720
+ }
721
+ // A node whose calls changed while staging yielded is re-measured here,
722
+ // never in the install.
723
+ for (;;) {
724
+ const stale = staged.filter(isStagedReplacementStale);
725
+ if (stale.length === 0) break;
726
+ for (const record of stale) {
727
+ measureReplacedCalls(record, _estimateValueBytes);
728
+ if (slice.expired()) await slice.yield();
729
+ }
730
+ }
731
+ // Pre-install size: the estimate then moves by the measured call bytes
732
+ // instead of re-walking the hydrated graph.
733
+ const baseBytes = _estimateGraphBaseBytes(graph);
734
+ const { applied, bytes } = installCallsSidecarEntries(staged);
735
+ _noteGraphCallsHydrated(graph, baseBytes, bytes);
736
+ return applied;
676
737
  } catch {
677
738
  return 0;
678
739
  }
679
740
  }
680
741
 
742
+ // A reader that sends nothing for this long is stalled: its chunks arrive a
743
+ // few ms apart once parsing is done, and parsing a 100+ MB sidecar takes
744
+ // seconds, not tens of seconds.
745
+ const CALLS_READER_STALL_MS = 30_000;
746
+ let _callsReader = null;
747
+ const _liveCallsReaders = new Set();
748
+
749
+ /** Test seam: `{ createWorker, stallMs }` replaces the reader worker; null restores it. */
750
+ export function _setCallsSidecarReaderForTest(reader) {
751
+ _callsReader = reader;
752
+ }
753
+
754
+ // A process exiting mid-read takes its readers down instead of waiting on them.
755
+ process.once('exit', () => {
756
+ for (const worker of _liveCallsReaders) void worker.terminate();
757
+ });
758
+
759
+ // Resolves when the reader acknowledged the whole file (`done`); rejects when
760
+ // it crashed, exited early or stalled.
761
+ function _streamCallsSidecar(file, onEntries) {
762
+ return new Promise((resolve, reject) => {
763
+ const createWorker = _callsReader?.createWorker || ((url, options) => new Worker(url, options));
764
+ const stallMs = _callsReader?.stallMs ?? CALLS_READER_STALL_MS;
765
+ // execArgv: [] — the parent's flags (e.g. --input-type) can make a worker
766
+ // fail to start, as for the build worker.
767
+ // Root context: the hydration is shared across queries, so its worker and
768
+ // timers must not pin the async stores of the query that started it.
769
+ const worker = runInRootAsyncContext(() =>
770
+ createWorker(new URL('./calls-sidecar-worker.mjs', import.meta.url), {
771
+ workerData: { file },
772
+ execArgv: [],
773
+ stdout: true,
774
+ stderr: true,
775
+ })
776
+ );
777
+ _liveCallsReaders.add(worker);
778
+ let settled = false;
779
+ let stallTimer = null;
780
+ const settle = (error) => {
781
+ if (settled) return;
782
+ settled = true;
783
+ clearTimeout(stallTimer);
784
+ _liveCallsReaders.delete(worker);
785
+ void worker.terminate();
786
+ if (error) reject(error);
787
+ else resolve();
788
+ };
789
+ const armStallTimer = () => {
790
+ clearTimeout(stallTimer);
791
+ stallTimer = runInRootAsyncContext(() =>
792
+ setTimeout(() => settle(new Error(`calls sidecar reader stalled for ${stallMs}ms`)), stallMs)
793
+ );
794
+ stallTimer.unref?.();
795
+ };
796
+ armStallTimer();
797
+ worker.on('message', (message) => {
798
+ if (settled) return;
799
+ if (message?.done) return settle(null);
800
+ try {
801
+ if (Array.isArray(message?.entries)) onEntries(message.entries);
802
+ } catch (error) {
803
+ return settle(error);
804
+ }
805
+ armStallTimer();
806
+ // Ack on a later turn: the next chunk is read after other work ran.
807
+ setImmediate(() => {
808
+ if (!settled) worker.postMessage(0);
809
+ });
810
+ });
811
+ worker.once('error', (error) => settle(error));
812
+ worker.once('exit', (code) => settle(new Error(`calls sidecar reader exited (${code}) before done`)));
813
+ });
814
+ }
815
+
681
816
  export function _setDiskCodeGraphEntry(cwd, graph, { persist = true } = {}) {
682
817
  _loadDiskCodeGraphCache();
683
818
  // Stamp the cache entry with the persistence timestamp (not the build
@@ -21,12 +21,13 @@ import {
21
21
  _symbolOutlineRows,
22
22
  _graphHasNativeSymbols,
23
23
  _graphExpectsNativeSymbols,
24
+ _ensureTokenIndex,
24
25
  } from './symbol-index.mjs';
25
26
  import { _findDirProjectRoot } from './project-root.mjs';
26
27
  import { buildCodeGraphAsync, prewarmCodeGraph, prewarmCodeGraphSymbols } from './build.mjs';
27
28
 
28
29
  import { _pruneCodeGraphMemoryCache } from './memory-cache.mjs';
29
- import { _findSymbolAcrossGraph } from './search.mjs';
30
+ import { _findSymbolAcrossGraph, _runCodeGraphQuery } from './search.mjs';
30
31
  import { _graphHasAstCalls } from './ast-calls.mjs';
31
32
  import { callsCapabilityError, symbolsCapabilityError, symbolsCapabilityHint } from './graph-binary.mjs';
32
33
  import { hydrateGraphCallsFromSidecar } from './disk-cache.mjs';
@@ -192,7 +193,8 @@ async function _graphForMode(mode, cwd, signal, options) {
192
193
  // that read call sites pay for it, and only on the first such query of the
193
194
  // process (the graph object carries the marker); overview/symbols/imports/…
194
195
  // never touch the file.
195
- if (CODE_GRAPH_CALL_MODES.has(mode)) hydrateGraphCallsFromSidecar(graph);
196
+ if (CODE_GRAPH_CALL_MODES.has(mode)) await hydrateGraphCallsFromSidecar(graph);
197
+ await _ensureTokenIndex(graph);
196
198
  // Call analysis is AST-only: a graph without call data cannot answer, and an
197
199
  // empty answer would read like "no callers". Fail loudly with the remedy.
198
200
  if (CODE_GRAPH_CALL_ONLY_MODES.has(mode) && !_graphHasAstCalls(graph)) {
@@ -229,18 +231,20 @@ export async function codeGraph(rawArgs, cwd, signal = null, options = {}) {
229
231
  const rel = abs && !fileIsDirectory ? _graphRel(abs, cwd) : null;
230
232
  const scopeRelPrefix = abs && fileIsDirectory ? _scopeRelPrefix(_graphRel(abs, cwd)) : null;
231
233
  const node = rel ? graph.nodes.get(rel) : null;
232
- return handler({
233
- args,
234
- cwd,
235
- defaultCwd: options._defaultCwd ?? cwd,
236
- signal,
237
- graph,
238
- normFile,
239
- rel,
240
- node,
241
- scopeRelPrefix,
242
- symbolsNote,
243
- });
234
+ return _runCodeGraphQuery(() =>
235
+ handler({
236
+ args,
237
+ cwd,
238
+ defaultCwd: options._defaultCwd ?? cwd,
239
+ signal,
240
+ graph,
241
+ normFile,
242
+ rel,
243
+ node,
244
+ scopeRelPrefix,
245
+ symbolsNote,
246
+ })
247
+ );
244
248
  }
245
249
 
246
250
  async function findSymbolTool(args, cwd, signal = null, options = {}) {
@@ -280,18 +284,21 @@ async function findSymbolTool(args, cwd, signal = null, options = {}) {
280
284
  }
281
285
  throw new Error('find_symbol: provide "symbol" (to locate) or "file" (to list its symbols).');
282
286
  }
283
- if (args?.body !== false) await prewarmPrimaryDeclaration(graph, symbol, language, signal);
284
- return _findSymbolAcrossGraph(graph, symbol, cwd, {
285
- defaultCwd: options._defaultCwd ?? cwd,
286
- language,
287
- limit,
288
- fileRel,
289
- body: args?.body !== false,
290
- outsideDeclaration: await resolveOutsideDeclaration(graph, symbol, {
287
+ await _ensureTokenIndex(graph);
288
+ return _runCodeGraphQuery(async () => {
289
+ await prewarmPrimaryDeclaration(graph, symbol, language, signal);
290
+ return _findSymbolAcrossGraph(graph, symbol, cwd, {
291
+ defaultCwd: options._defaultCwd ?? cwd,
291
292
  language,
293
+ limit,
292
294
  fileRel,
293
- signal,
294
- }),
295
+ body: args?.body !== false,
296
+ outsideDeclaration: await resolveOutsideDeclaration(graph, symbol, {
297
+ language,
298
+ fileRel,
299
+ signal,
300
+ }),
301
+ });
295
302
  });
296
303
  }
297
304
 
@@ -5,25 +5,182 @@
5
5
  // threads do not share module-level state with the main thread, so acquiring
6
6
  // here would create an independent semaphore that cannot coordinate with rg.
7
7
  import { spawn } from 'node:child_process';
8
+ import { createHash } from 'node:crypto';
9
+ import { isMainThread } from 'node:worker_threads';
10
+ import { ensureNativeSpawnServer, tryNativeSpawn } from '../../lib/native-spawn-client.mjs';
8
11
  import { createChildKiller } from './child-kill.mjs';
9
12
  import { parseGraphJsonl } from './jsonl-records.mjs';
10
13
 
11
14
  const STDERR_CAP = 8 * 1024;
12
15
  const FORCE_SETTLE_MS = 5000;
13
16
 
14
- export function spawnGraphJsonl({ binPath, absRoot, extraArgs, stdinLines, signal, timeoutMs, requireRel }) {
17
+ // In-flight runs by identical inputs. An entry lives only while its process
18
+ // runs: nothing is cached after completion (the graph caches own that).
19
+ // Parallel sub-agents asking about the same repo used to start N identical
20
+ // processes in the same tick, and each Node `spawn` blocks the main thread.
21
+ const inflight = new Map();
22
+
23
+ function runKey({ binPath, absRoot, extraArgs, stdinLines, timeoutMs, env, cwd }) {
24
+ const hash = createHash('sha256');
25
+ // env and cwd are part of the identity: the child's output can depend on
26
+ // them, and they may change between two calls. Length-prefixed parts keep
27
+ // joins unambiguous.
28
+ const envParts = Object.keys(env)
29
+ .sort()
30
+ .flatMap((name) => [name, env[name]]);
31
+ for (const part of [binPath, absRoot, timeoutMs, cwd, ...extraArgs, '\0env', ...envParts]) {
32
+ const text = String(part);
33
+ hash.update(`${text.length}:${text}`);
34
+ }
35
+ hash.update(Array.isArray(stdinLines) ? `\0stdin${stdinLines.length}\0${stdinLines.join('\n')}` : '\0nostdin');
36
+ return hash.digest('hex');
37
+ }
38
+
39
+ function startShared(key, params) {
40
+ const controller = new AbortController();
41
+ const entry = { waiters: 0, controller, promise: null };
42
+ entry.promise = runGraphProcess({ ...params, signal: controller.signal }).finally(() => {
43
+ if (inflight.get(key) === entry) inflight.delete(key);
44
+ });
45
+ // Waiters each attach their own handlers; this keeps a run whose waiters all
46
+ // aborted from surfacing as an unhandled rejection.
47
+ entry.promise.catch(() => {});
48
+ inflight.set(key, entry);
49
+ return entry;
50
+ }
51
+
52
+ // Concurrent calls with identical inputs share one process and await its
53
+ // stdout. Each waiter parses its own records, so callers never share mutable
54
+ // result objects. A waiter's abort rejects only that waiter; the process is
55
+ // killed when the last waiter leaves.
56
+ export function spawnGraphJsonl(callParams) {
57
+ const { signal, requireRel } = callParams;
58
+ if (signal?.aborted) return Promise.reject(new Error('aborted'));
59
+ // Snapshot synchronously: the launch awaits the spawn server, and a later
60
+ // env/cwd change must not leak into a run this call started or joined.
61
+ const params = { ...callParams, env: { ...process.env }, cwd: process.cwd() };
62
+ const key = runKey(params);
63
+ const entry = inflight.get(key) || startShared(key, params);
64
+ entry.waiters += 1;
65
+ return new Promise((resolve, reject) => {
66
+ let left = false;
67
+ const leave = () => {
68
+ left = true;
69
+ entry.waiters -= 1;
70
+ signal?.removeEventListener('abort', onAbort);
71
+ };
72
+ const onAbort = () => {
73
+ if (left) return;
74
+ leave();
75
+ if (entry.waiters > 0) {
76
+ reject(new Error('aborted'));
77
+ return;
78
+ }
79
+ // Last waiter: stop the process, drop the entry so a new caller starts
80
+ // a fresh run, and settle only once the process is gone (the child gate
81
+ // slot the caller holds must not be released early).
82
+ if (inflight.get(key) === entry) inflight.delete(key);
83
+ entry.controller.abort();
84
+ entry.promise.then(
85
+ () => reject(new Error('aborted')),
86
+ (error) => reject(error)
87
+ );
88
+ };
89
+ signal?.addEventListener('abort', onAbort, { once: true });
90
+ entry.promise.then(
91
+ (stdout) => {
92
+ if (left) return;
93
+ leave();
94
+ try {
95
+ resolve(parseGraphJsonl(stdout, { requireRel }));
96
+ } catch (error) {
97
+ reject(error);
98
+ }
99
+ },
100
+ (error) => {
101
+ if (left) return;
102
+ leave();
103
+ reject(error);
104
+ }
105
+ );
106
+ });
107
+ }
108
+
109
+ // Node's `spawn` runs CreateProcess synchronously on the calling thread (up to
110
+ // ~0.5 s under load), so on the daemon main thread the launch goes through the
111
+ // native spawn server — the established off-thread path (git, shell): the main
112
+ // thread only writes a request line and receives output events. Worker threads
113
+ // (the build worker) are already off the main thread and, being separate
114
+ // module instances, would each start their own server, so they spawn directly,
115
+ // as does a main thread whose server is unavailable.
116
+ const NATIVE_OUTPUT_LIMIT = 1024 * 1024 * 1024;
117
+
118
+ async function launchGraphChild({ binPath, absRoot, extraArgs, wantsStdin, env, cwd }) {
119
+ const args = [absRoot, ...extraArgs];
120
+ if (isMainThread) {
121
+ try {
122
+ await ensureNativeSpawnServer();
123
+ const native = tryNativeSpawn({
124
+ shell: binPath,
125
+ argv: args,
126
+ spawnOptions: {
127
+ env,
128
+ cwd,
129
+ outputLimit: NATIVE_OUTPUT_LIMIT,
130
+ rawOutput: true,
131
+ stdinPipe: wantsStdin,
132
+ },
133
+ });
134
+ if (native?.child) {
135
+ const child = native.child;
136
+ return {
137
+ proc: child,
138
+ // The server drops a stdin write for a request it has not yet
139
+ // registered, so wait for its 'spawned' event.
140
+ writeStdin: (text) => {
141
+ const write = () => child.writeStdin(text, { close: true });
142
+ if (child.pid) write();
143
+ else child.once('spawn', write);
144
+ },
145
+ };
146
+ }
147
+ } catch {
148
+ /* server unavailable or incompatible: fall back to a direct spawn */
149
+ }
150
+ }
151
+ const proc = spawn(binPath, args, {
152
+ env,
153
+ cwd,
154
+ stdio: [wantsStdin ? 'pipe' : 'ignore', 'pipe', 'pipe'],
155
+ // windowsHide: native code-graph binary is a console exe; without this each
156
+ // call flashes a console window when spawned under the detached daemon.
157
+ windowsHide: true,
158
+ });
159
+ return {
160
+ proc,
161
+ writeStdin(text) {
162
+ proc.stdin.on('error', () => {
163
+ /* child may close stdin early; ignore EPIPE */
164
+ });
165
+ proc.stdin.write(text);
166
+ proc.stdin.end();
167
+ },
168
+ };
169
+ }
170
+
171
+ async function runGraphProcess(params) {
172
+ const { binPath, absRoot, extraArgs, stdinLines, env, cwd } = params;
173
+ // When stdinLines is supplied (--files mode), stream one JSON object per
174
+ // line to the child's STDIN — the reused nodes' metadata — so Rust can
175
+ // resolve imports across the WHOLE tree (fresh + reused) while only
176
+ // full-parsing the changed subset passed as argv.
177
+ const wantsStdin = Array.isArray(stdinLines);
178
+ const launched = await launchGraphChild({ binPath, absRoot, extraArgs, wantsStdin, env, cwd });
179
+ return superviseGraphChild(launched, params, wantsStdin);
180
+ }
181
+
182
+ function superviseGraphChild({ proc, writeStdin }, { stdinLines, signal, timeoutMs }, wantsStdin) {
15
183
  return new Promise((resolve, reject) => {
16
- // When stdinLines is supplied (--files mode), stream one JSON object per
17
- // line to the child's STDIN — the reused nodes' metadata — so Rust can
18
- // resolve imports across the WHOLE tree (fresh + reused) while only
19
- // full-parsing the changed subset passed as argv.
20
- const wantsStdin = Array.isArray(stdinLines);
21
- const proc = spawn(binPath, [absRoot, ...extraArgs], {
22
- stdio: [wantsStdin ? 'pipe' : 'ignore', 'pipe', 'pipe'],
23
- // windowsHide: native code-graph binary is a console exe; without this each
24
- // call flashes a console window when spawned under the detached daemon.
25
- windowsHide: true,
26
- });
27
184
  const killer = createChildKiller(proc);
28
185
  const chunks = [];
29
186
  let stderrText = '';
@@ -93,7 +250,7 @@ export function spawnGraphJsonl({ binPath, absRoot, extraArgs, stdinLines, signa
93
250
  else signal.addEventListener('abort', onAbort, { once: true });
94
251
  }
95
252
 
96
- proc.stdout.on('data', (c) => chunks.push(c));
253
+ proc.stdout.on('data', (c) => chunks.push(Buffer.from(c)));
97
254
  proc.stderr.on('data', (c) => {
98
255
  if (stderrText.length >= STDERR_CAP) return;
99
256
  const piece = c.toString('utf8');
@@ -101,13 +258,7 @@ export function spawnGraphJsonl({ binPath, absRoot, extraArgs, stdinLines, signa
101
258
  stderrText += piece.length > room ? piece.slice(0, room) : piece;
102
259
  });
103
260
  proc.on('error', (err) => settle(() => reject(err)));
104
- if (wantsStdin) {
105
- proc.stdin.on('error', () => {
106
- /* child may close stdin early; ignore EPIPE */
107
- });
108
- proc.stdin.write(stdinLines.length ? `${stdinLines.join('\n')}\n` : '');
109
- proc.stdin.end();
110
- }
261
+ if (wantsStdin) writeStdin(stdinLines.length ? `${stdinLines.join('\n')}\n` : '');
111
262
  proc.on('close', (code) =>
112
263
  settle(() => {
113
264
  if (timedOut) {
@@ -124,11 +275,7 @@ export function spawnGraphJsonl({ binPath, absRoot, extraArgs, stdinLines, signa
124
275
  reject(new Error(`[code-graph] mixdog-graph exited ${code}: ${stderrText.trim().slice(0, 200)}`));
125
276
  return;
126
277
  }
127
- try {
128
- resolve(parseGraphJsonl(Buffer.concat(chunks).toString('utf8'), { requireRel }));
129
- } catch (error) {
130
- reject(error);
131
- }
278
+ resolve(Buffer.concat(chunks).toString('utf8'));
132
279
  })
133
280
  );
134
281
  });