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
@@ -248,9 +248,143 @@ export function saveMediaAsset({ kind, lane, model, prompt, options = {}, mime,
248
248
  return entry;
249
249
  }
250
250
 
251
- export function listMediaAssets({ limit = 60, offset = 0, kind = null } = {}) {
251
+ // ---- Boards: user-named collections of Studio results. The board list lives
252
+ // in boards.json; membership is the asset entry's `boardId` (one board per
253
+ // result), so a result never leaves the catalog ("전체") by joining a board.
254
+
255
+ function boardsPath() {
256
+ return join(mediaDir(), 'boards.json');
257
+ }
258
+
259
+ function catalogBoards(parsed) {
260
+ if (!parsed || !Array.isArray(parsed.boards)) throw new Error(`media boards are malformed: ${boardsPath()}`);
261
+ return parsed.boards;
262
+ }
263
+
264
+ function readBoards() {
265
+ return readJsonStateSync(boardsPath(), { validate: catalogBoards, fallback: [] });
266
+ }
267
+
268
+ /** As `mutateIndex`: a damaged boards.json is set aside and its backup
269
+ * restored BEFORE the write, so a mutation never reads it as an empty list
270
+ * and writes that over both the catalog and its good .bak. */
271
+ function mutateBoards(mutate) {
272
+ mkdirSync(mediaDir(), { recursive: true });
273
+ readBoards();
274
+ let written = null;
275
+ updateJsonAtomicSync(
276
+ boardsPath(),
277
+ (current) => {
278
+ const next = mutate(current == null ? [] : catalogBoards(current));
279
+ if (!next) return undefined;
280
+ written = next;
281
+ return { version: 1, boards: next };
282
+ },
283
+ { backup: true }
284
+ );
285
+ return written;
286
+ }
287
+
288
+ function boardIdText(id) {
289
+ if (typeof id !== 'string' || !id || id.length > 128) throw new TypeError('board id must be a string');
290
+ return id;
291
+ }
292
+
293
+ function boardName(name) {
294
+ if (typeof name !== 'string') throw new TypeError('board name must be a string');
295
+ const text = name.replace(/\s+/g, ' ').trim().slice(0, 120);
296
+ if (!text) throw new Error('board name is required');
297
+ return text;
298
+ }
299
+
300
+ /** Boards newest first, each with its result count, plus the catalog total
301
+ * for "전체". */
302
+ export function listMediaBoards() {
252
303
  ensureDirs();
253
- const all = readIndex().filter((entry) => (kind ? entry.kind === kind : true));
304
+ const assets = readIndex();
305
+ const counts = new Map();
306
+ for (const entry of assets) {
307
+ if (entry.boardId) counts.set(entry.boardId, (counts.get(entry.boardId) || 0) + 1);
308
+ }
309
+ const boards = [...readBoards()]
310
+ .sort((a, b) => Number(b.createdAt) - Number(a.createdAt))
311
+ .map((board) => ({
312
+ id: board.id,
313
+ name: board.name,
314
+ createdAt: board.createdAt,
315
+ count: counts.get(board.id) || 0,
316
+ }));
317
+ return { total: assets.length, boards };
318
+ }
319
+
320
+ export function createMediaBoard(name) {
321
+ const board = { id: randomUUID(), name: boardName(name), createdAt: Date.now() };
322
+ mutateBoards((boards) => [board, ...boards]);
323
+ return board;
324
+ }
325
+
326
+ export function renameMediaBoard(id, name) {
327
+ boardIdText(id);
328
+ const next = boardName(name);
329
+ let renamed = null;
330
+ mutateBoards((boards) => {
331
+ const board = boards.find((row) => row.id === id);
332
+ if (!board) return null;
333
+ renamed = { ...board, name: next };
334
+ return boards.map((row) => (row === board ? renamed : row));
335
+ });
336
+ if (!renamed) throw new Error('board not found');
337
+ return renamed;
338
+ }
339
+
340
+ /** Deletes the board only; its results stay in the catalog without a board. */
341
+ export function deleteMediaBoard(id) {
342
+ boardIdText(id);
343
+ let removed = false;
344
+ mutateBoards((boards) => {
345
+ if (!boards.some((row) => row.id === id)) return null;
346
+ removed = true;
347
+ return boards.filter((row) => row.id !== id);
348
+ });
349
+ mutateIndex((assets) => {
350
+ if (!assets.some((row) => row.boardId === id)) return null;
351
+ return assets.map((row) => {
352
+ if (row.boardId !== id) return row;
353
+ const { boardId: _drop, ...rest } = row;
354
+ return rest;
355
+ });
356
+ });
357
+ return { id, removed };
358
+ }
359
+
360
+ /** Moves results into a board; only `null` takes them out of any board. */
361
+ export function setMediaAssetBoard(ids, boardId) {
362
+ const list = Array.isArray(ids) ? ids : [ids];
363
+ if (list.some((id) => typeof id !== 'string' || !id)) throw new TypeError('asset ids must be strings');
364
+ const idSet = new Set(list);
365
+ const target = boardId === null ? '' : boardIdText(boardId);
366
+ if (target && !readBoards().some((row) => row.id === target)) throw new Error('board not found');
367
+ ensureDirs();
368
+ let moved = [];
369
+ mutateIndex((assets) => {
370
+ moved = [];
371
+ const next = assets.map((row) => {
372
+ if (!idSet.has(row.id) || (row.boardId || '') === target) return row;
373
+ moved.push(row.id);
374
+ if (target) return { ...row, boardId: target };
375
+ const { boardId: _drop, ...rest } = row;
376
+ return rest;
377
+ });
378
+ return moved.length ? next : null;
379
+ });
380
+ return { ids: moved, boardId: target };
381
+ }
382
+
383
+ export function listMediaAssets({ limit = 60, offset = 0, kind = null, boardId = '' } = {}) {
384
+ ensureDirs();
385
+ const all = readIndex().filter(
386
+ (entry) => (kind ? entry.kind === kind : true) && (boardId ? entry.boardId === boardId : true)
387
+ );
254
388
  const start = Math.max(0, Math.trunc(Number(offset) || 0));
255
389
  const count = Math.min(200, Math.max(1, Math.trunc(Number(limit) || 60)));
256
390
  const assets = all.slice(start, start + count);
@@ -452,7 +586,15 @@ export function deleteMediaAsset(id) {
452
586
  * `dryRun` answers the matching ids without deleting: the Studio confirms that
453
587
  * exact list, then deletes it by id.
454
588
  */
455
- export function deleteMediaAssets({ ids, kind = null, before, missing = false, all = false, dryRun = false } = {}) {
589
+ export function deleteMediaAssets({
590
+ ids,
591
+ kind = null,
592
+ boardId = '',
593
+ before,
594
+ missing = false,
595
+ all = false,
596
+ dryRun = false,
597
+ } = {}) {
456
598
  const idSet = Array.isArray(ids) ? new Set(ids.map(String)) : null;
457
599
  const cutoff = Number(before);
458
600
  const hasCutoff = Number.isFinite(cutoff) && cutoff > 0;
@@ -462,6 +604,7 @@ export function deleteMediaAssets({ ids, kind = null, before, missing = false, a
462
604
  ensureDirs();
463
605
  const matches = (entry) => {
464
606
  if (kind && entry.kind !== kind) return false;
607
+ if (boardId && entry.boardId !== boardId) return false;
465
608
  if (idSet && !idSet.has(entry.id)) return false;
466
609
  if (hasCutoff && !(Number(entry.createdAt || 0) < cutoff)) return false;
467
610
  if (missing) {
@@ -22,7 +22,7 @@ export const TOOL_DEFS = [
22
22
  openWorldHint: false,
23
23
  },
24
24
  description:
25
- 'Manage standing user preferences and constraints. Before add/edit, obtain approval for the exact content and scope unless already explicitly requested. Load memory-management for curation policy; stored history uses recall.',
25
+ "Manage standing user preferences and constraints. Save what the user asks you to remember and report its exact text and scope; an entry you propose yourself, or one whose scope is unclear, waits for the user's approval. Load memory-management for curation policy; stored history uses recall.",
26
26
  inputSchema: {
27
27
  type: 'object',
28
28
  properties: {
@@ -12,13 +12,13 @@
12
12
  * files outside the workspace (the system temp folder, the Office data
13
13
  * folder) are never noted.
14
14
  */
15
- import { AsyncLocalStorage } from 'node:async_hooks';
16
15
  import { statSync } from 'node:fs';
17
16
  import { tmpdir } from 'node:os';
18
17
  import { isAbsolute, relative, resolve } from 'node:path';
19
18
  import { PATCH_EDIT_BUDGET_BYTES, createSnapshotBudget, reviewFileContent } from '../../shared/bounded-file-read.mjs';
19
+ import { runtimeAsyncLocalStorage } from '../../shared/root-async-context.mjs';
20
20
 
21
- const ledgers = new AsyncLocalStorage();
21
+ const ledgers = runtimeAsyncLocalStorage();
22
22
 
23
23
  const pathKey = (path) => (process.platform === 'win32' ? path.toLowerCase() : path);
24
24
 
@@ -26,6 +26,25 @@ export function stampMs(value) {
26
26
  return Number.isFinite(parsed) && parsed > 0 ? parsed : 0;
27
27
  }
28
28
 
29
+ /** Stamped as `closeProvenance` on a record by every completed turn, beside
30
+ * that turn's completion time (`lastTurnCompletedAt`): from that turn on, an
31
+ * owner close of the session is recorded on the record (`ownerClosedAt`). A
32
+ * record without it last ran under a build that did not record owner closes,
33
+ * so its absence proves nothing. */
34
+ export const CLOSE_PROVENANCE_VERSION = 1;
35
+
36
+ /** Whether a reaped tag may continue this stored session: its record carries
37
+ * close provenance (absent → never; fail closed) and its owner did not close
38
+ * it (the agent tool's `close`, which keeps the conversation open) after its
39
+ * last completed turn. Only a turn completed after that close — the owner
40
+ * reusing it — lifts it; `lastUsedAt` also moves without a turn (a rewind),
41
+ * so it never counts. */
42
+ export function resumableAfterReap(record) {
43
+ if (record?.closeProvenance !== CLOSE_PROVENANCE_VERSION) return false;
44
+ const closedAt = stampMs(record.ownerClosedAt);
45
+ return !(closedAt > 0 && closedAt >= stampMs(record.lastTurnCompletedAt));
46
+ }
47
+
29
48
  export function tagTombstoneKey(row = {}) {
30
49
  const parent = clean(row.parentSessionId || row.ownerSessionId);
31
50
  if (parent) return `session:${parent}\0${clean(row.tag)}`;
@@ -0,0 +1,13 @@
1
+ export interface RaisedDesktopNotice {
2
+ key: string;
3
+ code: string;
4
+ params: Record<string, string>;
5
+ }
6
+ export function raiseDesktopNotice(key: string, code: string, params?: Record<string, unknown>): boolean;
7
+ export function clearDesktopNotice(key: string): void;
8
+ export function deliverPendingDesktopNotices(): void;
9
+ /** `sink` returns false when it had nobody to deliver to; the notice then
10
+ * waits and is offered again with `replay` true. */
11
+ export function registerDesktopNoticeSink(
12
+ sink: (notice: RaisedDesktopNotice, replay: boolean) => boolean | undefined
13
+ ): () => void;
@@ -0,0 +1,87 @@
1
+ // The few problems the desktop app tells the user as a toast (sign-in expired,
2
+ // secure storage failing, a conversation not saved), raised wherever they are
3
+ // detected — the runtime, MCP, the keychain, the session store — and handed to
4
+ // the desktop service (or the Electron main process) that reaches the window.
5
+ // A notice is raised once per key until clearDesktopNotice(key) re-arms it, so
6
+ // a retry or a poll never repeats it. A notice no sink delivered (no window or
7
+ // client attached) waits, one per key, for the next delivery chance.
8
+ //
9
+ // Deliberately dependency-free: the desktop service bundle imports this file
10
+ // too, and every copy (and keychain-cjs.cjs, through `raise`) shares one
11
+ // registry through a global symbol.
12
+
13
+ const KEY = Symbol.for('mixdog.desktopNoticeHost.v1');
14
+ /** Undelivered notices kept; the oldest go first. */
15
+ const PENDING_LIMIT = 20;
16
+
17
+ function registry() {
18
+ globalThis[KEY] ??= { raised: new Set(), sinks: [], pending: [], raise: null };
19
+ return globalThis[KEY];
20
+ }
21
+
22
+ /** Whether some sink took `notice`: a sink returns false when nobody was
23
+ * there to receive it. `replay`: it was offered before and waited. */
24
+ function offer(host, notice, replay = false) {
25
+ let delivered = false;
26
+ for (const { sink } of host.sinks) {
27
+ try {
28
+ if (sink(notice, replay) !== false) delivered = true;
29
+ } catch {}
30
+ }
31
+ return delivered;
32
+ }
33
+
34
+ function hold(host, notice) {
35
+ host.pending = host.pending.filter((held) => held.key !== notice.key);
36
+ host.pending.push(notice);
37
+ if (host.pending.length > PENDING_LIMIT) host.pending.shift();
38
+ }
39
+
40
+ /** Raise notice `code` (with string `params`) under `key`. False when that
41
+ * key is already raised. */
42
+ export function raiseDesktopNotice(key, code, params = {}) {
43
+ const host = registry();
44
+ const id = String(key || '');
45
+ if (!id || !code || host.raised.has(id)) return false;
46
+ host.raised.add(id);
47
+ const notice = {
48
+ key: id,
49
+ code: String(code),
50
+ params: Object.fromEntries(Object.entries(params || {}).map(([name, value]) => [name, String(value ?? '')])),
51
+ };
52
+ if (!offer(host, notice)) hold(host, notice);
53
+ return true;
54
+ }
55
+
56
+ /** The condition behind `key` is over: the next raise shows again. */
57
+ export function clearDesktopNotice(key) {
58
+ const host = registry();
59
+ const id = String(key || '');
60
+ if (!host.raised.delete(id)) return;
61
+ host.pending = host.pending.filter((notice) => notice.key !== id);
62
+ }
63
+
64
+ /** Offer every waiting notice again (a client just attached); the ones still
65
+ * undelivered keep waiting. */
66
+ export function deliverPendingDesktopNotices() {
67
+ const host = registry();
68
+ const pending = host.pending;
69
+ host.pending = [];
70
+ for (const notice of pending) if (!offer(host, notice, true)) hold(host, notice);
71
+ }
72
+
73
+ /** `sink(notice, replay)` receives every notice from now on, the waiting ones
74
+ * first (`replay` true); it returns false when it had nobody to deliver to.
75
+ * Returns the unregister. */
76
+ export function registerDesktopNoticeSink(sink) {
77
+ const host = registry();
78
+ const entry = { sink };
79
+ host.sinks.push(entry);
80
+ deliverPendingDesktopNotices();
81
+ return () => {
82
+ const index = host.sinks.indexOf(entry);
83
+ if (index >= 0) host.sinks.splice(index, 1);
84
+ };
85
+ }
86
+
87
+ registry().raise = raiseDesktopNotice;
@@ -10,7 +10,7 @@ import {
10
10
  } from 'node:fs/promises';
11
11
  import { basename, dirname, join } from 'node:path';
12
12
  import { randomBytes } from 'node:crypto';
13
- import { AsyncLocalStorage } from 'node:async_hooks';
13
+ import { runtimeAsyncLocalStorage } from './root-async-context.mjs';
14
14
  import { enforceOwnerOnlyAclWin32, enforceOwnerOnlyAclWin32Async } from './file-permissions.mjs';
15
15
  import { createKeyedSerialQueue } from './keyed-serial-queue.mjs';
16
16
  import { sleep, sleepSync } from './sleep.mjs';
@@ -34,7 +34,7 @@ const OWNER_TOKEN = randomBytes(12).toString('hex');
34
34
  const osHeldPaths = new Map();
35
35
  // In-process waiters queue per lock path before contending for the OS lock.
36
36
  const lockQueue = createKeyedSerialQueue();
37
- const heldLockPaths = new AsyncLocalStorage();
37
+ const heldLockPaths = runtimeAsyncLocalStorage();
38
38
  // A reclaim guard is held for a few metadata calls; one older than this whose
39
39
  // owner is dead was stranded by a process that died inside the reclaim.
40
40
  const RECLAIM_GUARD_STALE_MS = 30_000;
@@ -9,16 +9,14 @@
9
9
  // Capping old space makes V8 pace its major GCs against a realistic size. On
10
10
  // this exact runtime, one identical workload settled at RSS 401MB uncapped
11
11
  // versus 245MB under a 768MB cap (39% lower) while the live set was unchanged;
12
- // the gap between heapTotal and RSS fell from 274MB to 100MB. The desktop
13
- // renderer already banks the same win from its own cap — see the note above
14
- // `rendererHeapMb` in apps/desktop/src/main/index.ts, which reached this
15
- // conclusion first and named forced collection as the path that does NOT work.
12
+ // the gap between heapTotal and RSS fell from 274MB to 100MB.
16
13
  //
17
- // Memory and session-runtime keep caps well above their measured peaks so the
18
- // ceiling shapes GC pacing. The daemon is left to V8's own sizing by default:
19
- // a fixed 768MB ceiling was tight enough to risk avoidable exits. An explicit
20
- // `<ROLE>_HEAP_MB` still applies; `0` restores V8's own sizing, mirroring the
21
- // MIXDOG_RENDERER_HEAP_MB escape hatch.
14
+ // Every role is nevertheless left to V8's own sizing by default, like the
15
+ // desktop renderer (`rendererHeapMb` in apps/desktop/src/main/index.ts): a
16
+ // fixed ceiling turns a spike past it into an exit while the machine still
17
+ // has memory to spare, and an exit costs the work running in that process.
18
+ // An explicit `<ROLE>_HEAP_MB` still applies; `0` leaves V8's own sizing,
19
+ // mirroring the MIXDOG_RENDERER_HEAP_MB escape hatch.
22
20
 
23
21
  import { nonNegativeInt } from './numbers.mjs';
24
22
 
@@ -29,9 +27,9 @@ const ROLES = {
29
27
  // Default 0 leaves V8's own sizing; MIXDOG_DAEMON_HEAP_MB still applies.
30
28
  daemon: { env: 'MIXDOG_DAEMON_HEAP_MB', defaultMb: 0 },
31
29
  // Memory runtime observed resident at 259MB with the embedding model cold.
32
- memory: { env: 'MIXDOG_MEMORY_HEAP_MB', defaultMb: 512 },
30
+ memory: { env: 'MIXDOG_MEMORY_HEAP_MB', defaultMb: 0 },
33
31
  // Shard-mode session runtime holds the same transcripts the daemon would.
34
- 'session-runtime': { env: 'MIXDOG_SESSION_RUNTIME_HEAP_MB', defaultMb: 768 },
32
+ 'session-runtime': { env: 'MIXDOG_SESSION_RUNTIME_HEAP_MB', defaultMb: 0 },
35
33
  };
36
34
 
37
35
  /** Cap in MB for a role; 0 means "leave V8's own sizing alone". */
@@ -21,6 +21,7 @@
21
21
 
22
22
  import { createRequire } from 'node:module';
23
23
  import { BlockList, isIP } from 'node:net';
24
+ import { runInRootAsyncContext } from '../root-async-context.mjs';
24
25
 
25
26
  const require = createRequire(import.meta.url);
26
27
  let _undici = null;
@@ -371,10 +372,19 @@ function llmAgent() {
371
372
  _agent = null;
372
373
  _globalInstalled = false;
373
374
  }
374
- _agent ??= new (undici().Agent)(llmAgentOptions());
375
+ _agent ??= new (undici().Agent)({ ...llmAgentOptions(), connect: rootContextConnector() });
375
376
  return _agent;
376
377
  }
377
378
 
379
+ // A kept-alive socket serves later requests of any session: connect it in the
380
+ // root context so it never retains the request that opened it. buildConnector
381
+ // with no options matches the connector undici builds for an Agent without
382
+ // TLS/connect options.
383
+ function rootContextConnector() {
384
+ const connect = undici().buildConnector({});
385
+ return (options, callback) => runInRootAsyncContext(() => connect(options, callback));
386
+ }
387
+
378
388
  /**
379
389
  * The shared singleton dispatcher for LLM API requests. Created on first use.
380
390
  *
@@ -25,9 +25,10 @@
25
25
  * Any read failure means no system proxy.
26
26
  */
27
27
 
28
- import { execFileSync } from 'node:child_process';
28
+ import { execFile, execFileSync } from 'node:child_process';
29
29
  import { isIP } from 'node:net';
30
30
  import { join } from 'node:path';
31
+ import { promisify } from 'node:util';
31
32
  import { adoptPrivateProxy, isLocalHost, normalizeHost } from './http-agent.mjs';
32
33
 
33
34
  const INTERNET_SETTINGS_KEY = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings';
@@ -69,36 +70,51 @@ const lookups = new Map();
69
70
  let socksReported = false;
70
71
  let failureReported = false;
71
72
 
72
- /** The rows of `reg query <key>` output as a name → data map; null when the query failed. */
73
+ const execFileAsync = promisify(execFile);
74
+ const REG_QUERY_OPTIONS = {
75
+ encoding: 'utf8',
76
+ timeout: 2000,
77
+ maxBuffer: 256 * 1024,
78
+ windowsHide: true,
79
+ };
80
+
81
+ function regExe() {
82
+ return join(process.env.SystemRoot || 'C:\\Windows', 'System32', 'reg.exe');
83
+ }
84
+
85
+ /** The rows of `reg query` output as a name → data map. */
86
+ function parseRegistryOutput(out) {
87
+ const values = new Map();
88
+ for (const row of out.split(/\r?\n/)) {
89
+ // " Name REG_TYPE data" (data is absent for an empty string)
90
+ const match = row.match(/^ {4}(\S.*?) {4}(REG_[A-Z_]+)(?: {4}(.*))?$/);
91
+ if (match) values.set(match[1].toLowerCase(), (match[3] ?? '').trim());
92
+ }
93
+ return values;
94
+ }
95
+
96
+ /** `reg query <key>` as a name → data map; null when the query failed. */
73
97
  function queryRegistryKey(key) {
74
98
  try {
75
- const exe = join(process.env.SystemRoot || 'C:\\Windows', 'System32', 'reg.exe');
76
- const out = execFileSync(exe, ['query', key], {
77
- encoding: 'utf8',
78
- stdio: ['ignore', 'pipe', 'ignore'],
79
- timeout: 2000,
80
- maxBuffer: 256 * 1024,
81
- windowsHide: true,
82
- });
83
- const values = new Map();
84
- for (const row of out.split(/\r?\n/)) {
85
- // " Name REG_TYPE data" (data is absent for an empty string)
86
- const match = row.match(/^ {4}(\S.*?) {4}(REG_[A-Z_]+)(?: {4}(.*))?$/);
87
- if (match) values.set(match[1].toLowerCase(), (match[3] ?? '').trim());
88
- }
89
- return values;
99
+ return parseRegistryOutput(
100
+ execFileSync(regExe(), ['query', key], { ...REG_QUERY_OPTIONS, stdio: ['ignore', 'pipe', 'ignore'] })
101
+ );
90
102
  } catch {
91
103
  return null;
92
104
  }
93
105
  }
94
106
 
95
- /**
96
- * Raw registry values: `{ proxyEnable, proxyServer, proxyOverride, autoConfigUrl }`
97
- * (strings as `reg query` prints them, null when absent), or null when the
98
- * Internet Settings key cannot be read.
99
- */
100
- function readWindowsProxyRegistry() {
101
- const settings = queryRegistryKey(INTERNET_SETTINGS_KEY);
107
+ /** queryRegistryKey without holding the event loop for the reg.exe spawn. */
108
+ async function queryRegistryKeyAsync(key) {
109
+ try {
110
+ const { stdout } = await execFileAsync(regExe(), ['query', key], REG_QUERY_OPTIONS);
111
+ return parseRegistryOutput(stdout);
112
+ } catch {
113
+ return null;
114
+ }
115
+ }
116
+
117
+ function proxySettings(settings) {
102
118
  if (!settings) return null;
103
119
  return {
104
120
  proxyEnable: settings.get('proxyenable') ?? null,
@@ -108,6 +124,19 @@ function readWindowsProxyRegistry() {
108
124
  };
109
125
  }
110
126
 
127
+ /**
128
+ * Raw registry values: `{ proxyEnable, proxyServer, proxyOverride, autoConfigUrl }`
129
+ * (strings as `reg query` prints them, null when absent), or null when the
130
+ * Internet Settings key cannot be read.
131
+ */
132
+ function readWindowsProxyRegistry() {
133
+ return proxySettings(queryRegistryKey(INTERNET_SETTINGS_KEY));
134
+ }
135
+
136
+ async function readWindowsProxyRegistryAsync() {
137
+ return proxySettings(await queryRegistryKeyAsync(INTERNET_SETTINGS_KEY));
138
+ }
139
+
111
140
  const PROXY_ADDRESS = /^(https?:\/\/)?((?:[a-z0-9_-]+\.)*[a-z0-9_-]+|\[[0-9a-f:]+\]):(\d{1,5})$/i;
112
141
 
113
142
  function proxyUrl(address) {
@@ -256,6 +285,20 @@ function discover(reader, log) {
256
285
  } catch {
257
286
  return { proxy: null };
258
287
  }
288
+ return discovered(found, log);
289
+ }
290
+
291
+ async function discoverAsync(reader, log) {
292
+ let found;
293
+ try {
294
+ found = systemProxyFromRegistry(await reader());
295
+ } catch {
296
+ return { proxy: null };
297
+ }
298
+ return discovered(found, log);
299
+ }
300
+
301
+ function discovered(found, log) {
259
302
  if (!found.proxy) {
260
303
  if (!found.silent) log(`[mixdog] system proxy not used: ${found.reason}`);
261
304
  return { proxy: null };
@@ -387,6 +430,33 @@ export function adoptSystemProxy(
387
430
  apply = adoptPrivateProxy,
388
431
  } = {}
389
432
  ) {
433
+ const begun = beginAdoption(env, platform, logLine, apply);
434
+ return begun === DISCOVER ? finishAdoption(discover(reader, log)) : begun;
435
+ }
436
+
437
+ /**
438
+ * adoptSystemProxy for a process that may have to read the Windows registry
439
+ * (the daemon, the CLI): the reg.exe spawn is awaited instead of held on the
440
+ * event loop. Everything but that read is shared with adoptSystemProxy; the
441
+ * decision is settled when the returned promise resolves.
442
+ */
443
+ export async function adoptSystemProxyAsync(
444
+ env = process.env,
445
+ {
446
+ platform = process.platform,
447
+ reader = readWindowsProxyRegistryAsync,
448
+ log: logLine = (line) => process.stderr.write(`${line}\n`),
449
+ apply = adoptPrivateProxy,
450
+ } = {}
451
+ ) {
452
+ const begun = beginAdoption(env, platform, logLine, apply);
453
+ return begun === DISCOVER ? finishAdoption(await discoverAsync(reader, log)) : begun;
454
+ }
455
+
456
+ const DISCOVER = Symbol('discover');
457
+
458
+ /** Everything before the registry read: the final result, or DISCOVER when the registry decides. */
459
+ function beginAdoption(env, platform, logLine, apply) {
390
460
  const handoff = parseHandoff(env[HANDOFF_VAR]);
391
461
  delete env[HANDOFF_VAR];
392
462
  active = null;
@@ -402,7 +472,12 @@ export function adoptSystemProxy(
402
472
  active = { proxy: null };
403
473
  return false;
404
474
  }
405
- active = handoff ?? (platform === 'win32' ? discover(reader, log) : null);
475
+ if (!handoff && platform === 'win32') return DISCOVER;
476
+ return finishAdoption(handoff);
477
+ }
478
+
479
+ function finishAdoption(decision) {
480
+ active = decision;
406
481
  if (!active?.proxy) return false;
407
482
  return ensureRouting();
408
483
  }