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
@@ -13,6 +13,7 @@ import { EXTRACTION_SYMBOL_LANGS } from './constants.mjs';
13
13
  import { _getSourceTextForNode, _graphRel } from './source-access.mjs';
14
14
  import { _symbolParentIndex, _symbolLevel } from './text-columns.mjs';
15
15
  import { oneLine } from '../../../../shared/clean.mjs';
16
+ import { _mainThreadSlice } from './main-thread-slice.mjs';
16
17
 
17
18
  export function _escapeRegExp(text) {
18
19
  return String(text ?? '').replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
@@ -43,9 +44,113 @@ export function _getTokenSymbolsForNode(node) {
43
44
  return Array.isArray(node?.tokenSymbols) ? node.tokenSymbols : null;
44
45
  }
45
46
 
46
- // Per-symbol candidate lookup over the native token lists, memoized in
47
- // `_symbolTokenIndex` so repeat lookups are O(1). The scan is O(N) over the
48
- // node count and each node's check is an Array.includes on its shipped tokens.
47
+ // Inverted token index of a graph: token → ascending ordinal(s) into the
48
+ // graph.nodes order, so a candidate lookup costs O(hits) instead of an
49
+ // Array.includes over every token of every file (up to ~750 ms per new name on
50
+ // a large root, repeated for each callee name).
51
+ //
52
+ // Kept in a WeakMap rather than on the graph: it is derived from immutable node
53
+ // data, so it must survive the per-call runtime-cache clear (rebuilding it each
54
+ // query would cost what it saves); it is not part of the persisted or
55
+ // structured-clone shape; and its byte size is computed once at build time so
56
+ // the per-call memory estimate never re-walks millions of postings. Postings
57
+ // are bounded by the graph's own token lists (one ordinal per distinct token per
58
+ // file), and _estimateGraphRetainedBytes adds them to the graph's size.
59
+ const _tokenIndexes = new WeakMap();
60
+
61
+ function _tokenIndexIsCurrent(graph, entry) {
62
+ if (!entry?.complete || entry.nodeMap !== graph.nodes || entry.nodes.length !== graph.nodes.size) return false;
63
+ let ordinal = 0;
64
+ for (const node of graph.nodes.values()) {
65
+ if (entry.nodes[ordinal] !== node || entry.tokens[ordinal] !== node.tokenSymbols) return false;
66
+ ordinal += 1;
67
+ }
68
+ return true;
69
+ }
70
+
71
+ async function _buildTokenIndex(graph, entry) {
72
+ const slice = _mainThreadSlice();
73
+ const byToken = new Map();
74
+ let bytes = 48 + 2 * 24;
75
+ for (const node of graph.nodes.values()) {
76
+ const ordinal = entry.nodes.length;
77
+ entry.nodes.push(node);
78
+ entry.tokens.push(node.tokenSymbols);
79
+ const tokens = _getTokenSymbolsForNode(node);
80
+ for (const token of tokens || []) {
81
+ // Most tokens occur in one file: their posting is the bare ordinal, and
82
+ // only a second file turns it into an array (the _estimateValueBytes
83
+ // rules: Map slot + key, then 8 per number or 24 + 16 per array item).
84
+ const list = byToken.get(token);
85
+ if (list === undefined) {
86
+ byToken.set(token, ordinal);
87
+ bytes += 24 + (typeof token === 'string' ? 16 + token.length * 2 : 8) + 8;
88
+ } else if (typeof list === 'number') {
89
+ if (list !== ordinal) {
90
+ byToken.set(token, [list, ordinal]);
91
+ bytes += 24 + 2 * 16 - 8;
92
+ }
93
+ } else if (list[list.length - 1] !== ordinal) {
94
+ list.push(ordinal);
95
+ bytes += 16;
96
+ }
97
+ }
98
+ bytes += 16;
99
+ if (slice.expired()) await slice.yield();
100
+ }
101
+ entry.byToken = byToken;
102
+ entry.bytes = bytes;
103
+ entry.complete = true;
104
+ }
105
+
106
+ /**
107
+ * Build (time-sliced) or revalidate the token index of `graph`. Every query
108
+ * awaits this before its synchronous evaluation; until it resolves, lookups
109
+ * fall back to the linear scan, which returns the same candidates.
110
+ */
111
+ export function _ensureTokenIndex(graph) {
112
+ if (!graph?.nodes) return Promise.resolve();
113
+ const current = _tokenIndexes.get(graph);
114
+ if (current && (!current.complete || _tokenIndexIsCurrent(graph, current))) return current.ready;
115
+ const entry = { nodeMap: graph.nodes, nodes: [], tokens: [], byToken: null, bytes: 0, complete: false };
116
+ entry.ready = _buildTokenIndex(graph, entry).catch(() => {
117
+ if (_tokenIndexes.get(graph) === entry) _tokenIndexes.delete(graph);
118
+ });
119
+ _tokenIndexes.set(graph, entry);
120
+ return entry.ready;
121
+ }
122
+
123
+ /** Retained bytes of the graph's token index (0 when none is built). */
124
+ export function _tokenIndexRetainedBytes(graph) {
125
+ const entry = graph && typeof graph === 'object' ? _tokenIndexes.get(graph) : null;
126
+ return entry?.complete ? entry.bytes : 0;
127
+ }
128
+
129
+ // The nodes whose native tokens include `symbol`, in graph.nodes order: O(hits)
130
+ // through the token index when it is built, otherwise a linear scan with an
131
+ // Array.includes on each node's shipped tokens — the same nodes either way.
132
+ export function _tokenCandidateNodes(graph, symbol, language = null) {
133
+ if (!graph?.nodes) return [];
134
+ const entry = _tokenIndexes.get(graph);
135
+ const candidates = [];
136
+ if (entry?.complete && entry.nodeMap === graph.nodes && entry.nodes.length === graph.nodes.size) {
137
+ const posting = entry.byToken.get(symbol);
138
+ for (const ordinal of typeof posting === 'number' ? [posting] : posting || []) {
139
+ const node = entry.nodes[ordinal];
140
+ if (!language || node.lang === language) candidates.push(node);
141
+ }
142
+ return candidates;
143
+ }
144
+ for (const node of graph.nodes.values()) {
145
+ if (language && node.lang !== language) continue;
146
+ const tokens = _getTokenSymbolsForNode(node);
147
+ if (tokens?.includes(symbol)) candidates.push(node);
148
+ }
149
+ return candidates;
150
+ }
151
+
152
+ // Per-symbol candidate lookup, memoized in `_symbolTokenIndex` so repeat
153
+ // lookups are O(1).
49
154
  //
50
155
  // A node without tokens contributes nothing, and a miss is cached as the empty
51
156
  // set: the previous "no candidate → return EVERY node" fallback turned a token
@@ -58,12 +163,7 @@ export function _lookupCandidateNodes(graph, symbol, language = null) {
58
163
  const rels = graph._symbolTokenIndex.get(cacheKey);
59
164
  return rels.map((rel) => graph.nodes.get(rel)).filter(Boolean);
60
165
  }
61
- const candidates = [];
62
- for (const node of graph.nodes.values()) {
63
- if (language && node.lang !== language) continue;
64
- const tokens = _getTokenSymbolsForNode(node);
65
- if (tokens?.includes(symbol)) candidates.push(node);
66
- }
166
+ const candidates = _tokenCandidateNodes(graph, symbol, language);
67
167
  graph._symbolTokenIndex?.set(
68
168
  cacheKey,
69
169
  candidates.map((n) => n.rel)
@@ -1,6 +1,12 @@
1
1
  // Non-code text masker: blanks comment/string/regex bytes so downstream
2
2
  // identifier scans never match inside them. Byte-offset preserving (fills
3
3
  // with spaces, keeps newlines) so match.index maps back to the raw source.
4
+ //
5
+ // The scanner marks masked positions in a flag array (`out[j] = MASKED`) and
6
+ // renders text from the source and the flags. Every step only marks positions
7
+ // before the cursor it leaves, so the output up to the cursor is final after
8
+ // any step: the scan can stop, render what it has, and resume
9
+ // (_createNonCodeMasker), with the same result as one pass.
4
10
 
5
11
  import {
6
12
  _supportsHashComments,
@@ -16,46 +22,48 @@ import {
16
22
  REGEX_PRECEDENT_CHARS,
17
23
  } from './lang-predicates.mjs';
18
24
 
25
+ const MASKED = 1;
26
+
19
27
  // Mask a JS regex literal body starting at `start` (which points at `/`).
20
28
  // Handles `\` escapes and `[...]` character classes per ECMAScript spec.
21
29
  // Returns the index just past the closing `/flags`. Bytes between the
22
30
  // delimiters are replaced with spaces in `out` so downstream identifier
23
31
  // searches do not see them.
24
32
  function _maskJsRegexLiteral(src, out, start) {
25
- if (src[start] !== '\n') out[start] = ' ';
33
+ if (src[start] !== '\n') out[start] = MASKED;
26
34
  let j = start + 1;
27
35
  let inCharClass = false;
28
36
  while (j < src.length) {
29
37
  const c = src[j];
30
38
  if (c === '\n') return j;
31
39
  if (c === '\\') {
32
- if (src[j] !== '\n') out[j] = ' ';
33
- if (j + 1 < src.length && src[j + 1] !== '\n') out[j + 1] = ' ';
40
+ if (src[j] !== '\n') out[j] = MASKED;
41
+ if (j + 1 < src.length && src[j + 1] !== '\n') out[j + 1] = MASKED;
34
42
  j += 2;
35
43
  continue;
36
44
  }
37
45
  if (c === '[' && !inCharClass) {
38
46
  inCharClass = true;
39
- if (src[j] !== '\n') out[j] = ' ';
47
+ if (src[j] !== '\n') out[j] = MASKED;
40
48
  j++;
41
49
  continue;
42
50
  }
43
51
  if (c === ']' && inCharClass) {
44
52
  inCharClass = false;
45
- if (src[j] !== '\n') out[j] = ' ';
53
+ if (src[j] !== '\n') out[j] = MASKED;
46
54
  j++;
47
55
  continue;
48
56
  }
49
57
  if (c === '/' && !inCharClass) {
50
- if (src[j] !== '\n') out[j] = ' ';
58
+ if (src[j] !== '\n') out[j] = MASKED;
51
59
  j++;
52
60
  while (j < src.length && src[j] >= 'a' && src[j] <= 'z') {
53
- if (src[j] !== '\n') out[j] = ' ';
61
+ if (src[j] !== '\n') out[j] = MASKED;
54
62
  j++;
55
63
  }
56
64
  return j;
57
65
  }
58
- if (src[j] !== '\n') out[j] = ' ';
66
+ if (src[j] !== '\n') out[j] = MASKED;
59
67
  j++;
60
68
  }
61
69
  return j;
@@ -105,8 +113,8 @@ function _handleInterpolationInString(src, out, i, frame, stack) {
105
113
  if (!kind) return -1;
106
114
  if (kind === 'brace' && src[i] === '{' && src[i + 1] === '{') {
107
115
  // `{{` is an escaped literal brace inside an f-string / $"…".
108
- if (src[i] !== '\n') out[i] = ' ';
109
- if (src[i + 1] !== '\n') out[i + 1] = ' ';
116
+ if (src[i] !== '\n') out[i] = MASKED;
117
+ if (src[i + 1] !== '\n') out[i + 1] = MASKED;
110
118
  return i + 2;
111
119
  }
112
120
  const opened = _interpolationOpenerAt(src, i, kind);
@@ -123,7 +131,7 @@ function _handleInterpolationInString(src, out, i, frame, stack) {
123
131
  src[i] === '$' &&
124
132
  _isWordStartChar(src[i + 1])
125
133
  ) {
126
- if (src[i] !== '\n') out[i] = ' ';
134
+ if (src[i] !== '\n') out[i] = MASKED;
127
135
  let j = i + 1;
128
136
  while (j < src.length && _isWordChar(src[j])) j += 1;
129
137
  return j;
@@ -171,18 +179,18 @@ function _interpolationOpenerAt(src, i, kind) {
171
179
 
172
180
  function blank(s, start, count) {
173
181
  for (let j = start; j < start + count && j < s.src.length; j++) {
174
- if (s.src[j] !== '\n') s.out[j] = ' ';
182
+ if (s.src[j] !== '\n') s.out[j] = MASKED;
175
183
  }
176
184
  }
177
185
 
178
186
  function blankOne(s) {
179
- if (s.src[s.i] !== '\n') s.out[s.i] = ' ';
187
+ if (s.src[s.i] !== '\n') s.out[s.i] = MASKED;
180
188
  s.i++;
181
189
  }
182
190
 
183
191
  function maskToLineEnd(s) {
184
192
  while (s.i < s.src.length && s.src[s.i] !== '\n') {
185
- s.out[s.i] = ' ';
193
+ s.out[s.i] = MASKED;
186
194
  s.i++;
187
195
  }
188
196
  }
@@ -382,20 +390,56 @@ function codeStep(s, topLevel) {
382
390
  tokenStep(s);
383
391
  }
384
392
 
385
- export function _maskNonCodeText(text, lang) {
386
- const src = String(text || '');
387
- const s = { src, out: src.split(''), i: 0, lang, stack: [], prevToken: 'expr', blockComment: false };
388
- while (s.i < src.length) {
389
- if (s.blockComment) {
390
- blockCommentStep(s);
391
- continue;
392
- }
393
- const frame = s.stack.length ? s.stack[s.stack.length - 1] : null;
394
- if (frame?.kind === 'triple') tripleStep(s, frame);
395
- else if (frame?.kind === 'luablock') luaBlockStep(s, frame);
396
- else if (frame?.kind === 'string') stringStep(s, frame);
397
- else if (frame?.kind === 'interp') interpStep(s, frame);
398
- else codeStep(s, true);
393
+ function scanStep(s) {
394
+ if (s.blockComment) return blockCommentStep(s);
395
+ const frame = s.stack.length ? s.stack[s.stack.length - 1] : null;
396
+ if (frame?.kind === 'triple') tripleStep(s, frame);
397
+ else if (frame?.kind === 'luablock') luaBlockStep(s, frame);
398
+ else if (frame?.kind === 'string') stringStep(s, frame);
399
+ else if (frame?.kind === 'interp') interpStep(s, frame);
400
+ else codeStep(s, true);
401
+ }
402
+
403
+ // Append src[start, end) with its masked positions blanked, run by run.
404
+ function renderRange(src, out, start, end, parts) {
405
+ let j = start;
406
+ while (j < end) {
407
+ const masked = out[j];
408
+ let k = j + 1;
409
+ while (k < end && out[k] === masked) k++;
410
+ parts.push(masked ? ' '.repeat(k - j) : src.slice(j, k));
411
+ j = k;
399
412
  }
400
- return s.out.join('');
413
+ }
414
+
415
+ /**
416
+ * Resumable masker: `advance(chars)` scans at least `chars` more source chars
417
+ * (whole scanner steps) and returns true once the text is done; `result()` is
418
+ * then exactly _maskNonCodeText(text, lang).
419
+ */
420
+ export function _createNonCodeMasker(text, lang) {
421
+ const src = String(text || '');
422
+ const s = { src, out: new Uint8Array(src.length), i: 0, lang, stack: [], prevToken: 'expr', blockComment: false };
423
+ // One joined string per advance: joining every run at the end would itself
424
+ // be a long stretch for a large text.
425
+ const chunks = [];
426
+ let rendered = 0;
427
+ return {
428
+ advance(chars) {
429
+ const stop = Math.min(src.length, s.i + chars);
430
+ while (s.i < stop) scanStep(s);
431
+ const parts = [];
432
+ renderRange(src, s.out, rendered, s.i, parts);
433
+ chunks.push(parts.join(''));
434
+ rendered = s.i;
435
+ return s.i >= src.length;
436
+ },
437
+ result: () => chunks.join(''),
438
+ };
439
+ }
440
+
441
+ export function _maskNonCodeText(text, lang) {
442
+ const masker = _createNonCodeMasker(text, lang);
443
+ masker.advance(Number.POSITIVE_INFINITY);
444
+ return masker.result();
401
445
  }
@@ -5,10 +5,9 @@
5
5
  //
6
6
  // Contract:
7
7
  // - cwd arrives via workerData.cwd.
8
- // - On success: postMessage({ ok: true, signature, graph }). Main thread
9
- // seeds _codeGraphCache directly. Graph is structuredClone-transferred —
10
- // Maps/Sets of plain objects only, runtime caches are empty Maps that
11
- // survive the clone.
8
+ // - On success: the graph is posted in ack-paced chunks
9
+ // (_postCodeGraphWorkerSuccess) and reassembled by the main thread, which
10
+ // seeds _codeGraphCache directly. Maps/Sets of plain objects only.
12
11
  // - On any failure: postMessage({ ok: false, error }). Main thread propagates
13
12
  // the worker error — find_symbol / code_graph tools throw. No sync fallback.
14
13
  import { parentPort, workerData } from 'node:worker_threads';
@@ -34,8 +33,10 @@ try {
34
33
  };
35
34
  const graph = await _buildCodeGraph(cwd, buildOptions);
36
35
  if (graph && typeof graph.signature === 'string') {
37
- _postCodeGraphWorkerSuccess(graph, (message) => parentPort.postMessage(message), undefined, {
36
+ await _postCodeGraphWorkerSuccess(graph, (message) => parentPort.postMessage(message), undefined, {
38
37
  cache: buildOptions.cache,
38
+ // Chunks are paced by the main thread's ack (see build.mjs).
39
+ nextChunk: () => new Promise((resolve) => parentPort.once('message', resolve)),
39
40
  });
40
41
  } else {
41
42
  parentPort.postMessage({ ok: false });
@@ -687,10 +687,14 @@ export function tryNativeSpawn({ shell, argv, spawnOptions = {}, cwd } = {}) {
687
687
  fail(error) {
688
688
  server.pending.delete(id);
689
689
  const err = error instanceof Error ? error : new Error(String(error || 'native spawn failed'));
690
- if (fake.exitCode == null) {
691
- fake.exitCode = 1;
690
+ // `root_exit` sets exitCode before the output pumps drain and 'close'
691
+ // arrives; a transport lost in that window must still end the request
692
+ // (with the known exit), or its waiters hang until their own timeout.
693
+ if (!fake._closed) {
694
+ if (fake.exitCode == null) fake.exitCode = 1;
695
+ fake._closed = true;
692
696
  fake.emit('error', err);
693
- fake.emit('close', 1, null);
697
+ fake.emit('close', fake.exitCode, fake.signalCode);
694
698
  }
695
699
  _recomputeServerRef(server);
696
700
  },
@@ -142,4 +142,24 @@ function _isBenignCrash(err) {
142
142
  return BENIGN_CRASH_MESSAGE_RE.test(msg);
143
143
  }
144
144
 
145
- export { isChannelsDegraded, logCrash, _isBenignCrash, BENIGN_CRASH_FATAL_THRESHOLD, BENIGN_CRASH_STREAK_WINDOW_MS };
145
+ // Zombie-Lead repro (2026-07-02): logCrash-then-survive left a worker alive
146
+ // after an unhandled rejection whose async state was already corrupted
147
+ // (observed: EPERM on active-instance.json rename retry), so it spun
148
+ // forever doing nothing useful — a zombie Lead. A benign error is fatal on repeat.
149
+ let _benignCrashStreak = 0;
150
+ let _lastBenignCrashAt = 0;
151
+ /** Records an uncaught error to crash.log and says whether the process must
152
+ * now exit: every non-benign error, and a benign one on its Nth repeat. */
153
+ function crashEndsProcess(label, err) {
154
+ logCrash(label, err);
155
+ if (!_isBenignCrash(err)) {
156
+ _benignCrashStreak = 0;
157
+ return true;
158
+ }
159
+ const now = Date.now();
160
+ _benignCrashStreak = now - _lastBenignCrashAt <= BENIGN_CRASH_STREAK_WINDOW_MS ? _benignCrashStreak + 1 : 1;
161
+ _lastBenignCrashAt = now;
162
+ return _benignCrashStreak >= BENIGN_CRASH_FATAL_THRESHOLD;
163
+ }
164
+
165
+ export { isChannelsDegraded, logCrash, crashEndsProcess };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Every routine (schedule and webhook) one bot owns, deleted as its bot is
3
+ * deleted. One statement over both stores, keyed by the rows' current owner:
4
+ * it removes all of them with their run state (on the rows) and the webhooks'
5
+ * delivery logs, or — failing — none; a row moved to another bot is never
6
+ * matched.
7
+ */
8
+ import { openSchedulesDb } from './schedules-db.mjs';
9
+ import { openWebhooksDb } from './webhooks-db.mjs';
10
+
11
+ /** Resolves `{ schedules, webhooks }`: the names removed. */
12
+ export async function deleteRoutinesOwnedBy(ownerAgentId, { dataDir } = {}) {
13
+ if (typeof ownerAgentId !== 'string' || !ownerAgentId) throw new Error('deleteRoutinesOwnedBy: an owner is required');
14
+ // Both stores' tables exist before the one statement names them.
15
+ const [db] = await Promise.all([openSchedulesDb({ dataDir }), openWebhooksDb({ dataDir })]);
16
+ const { rows } = await db.query(
17
+ `WITH schedules AS (
18
+ DELETE FROM scheduler.schedules WHERE owner_agent_id = $1 RETURNING name
19
+ ), endpoints AS (
20
+ DELETE FROM webhooks.endpoints WHERE owner_agent_id = $1 RETURNING name
21
+ ), deliveries AS (
22
+ DELETE FROM webhooks.deliveries WHERE endpoint IN (SELECT name FROM endpoints)
23
+ )
24
+ SELECT 'schedule' AS kind, name FROM schedules
25
+ UNION ALL
26
+ SELECT 'webhook' AS kind, name FROM endpoints`,
27
+ [ownerAgentId]
28
+ );
29
+ const names = (kind) =>
30
+ rows
31
+ .filter((row) => row.kind === kind)
32
+ .map((row) => row.name)
33
+ .sort();
34
+ return { schedules: names('schedule'), webhooks: names('webhook') };
35
+ }
@@ -79,6 +79,10 @@ const getDb = createPgSchemaDb({
79
79
  withLock: withSchemaBootstrapLock,
80
80
  });
81
81
 
82
+ /** The store's handle, its tables created: for a statement that spans the
83
+ * routine stores (routines-db.mjs). */
84
+ export const openSchedulesDb = ({ dataDir } = {}) => getDb(dataDir);
85
+
82
86
  // ---------------------------------------------------------------------------
83
87
  // Row <-> def mapping
84
88
  // ---------------------------------------------------------------------------
@@ -82,6 +82,10 @@ const getDb = createPgSchemaDb({
82
82
  withLock: withSchemaBootstrapLock,
83
83
  });
84
84
 
85
+ /** The store's handle, its tables created: for a statement that spans the
86
+ * routine stores (routines-db.mjs). */
87
+ export const openWebhooksDb = ({ dataDir } = {}) => getDb(dataDir);
88
+
85
89
  // ---------------------------------------------------------------------------
86
90
  // Row <-> def mapping
87
91
  // ---------------------------------------------------------------------------
@@ -20,13 +20,7 @@ import {
20
20
  } from './runtime-paths.mjs';
21
21
  import { createConfigReloadWatch } from './config-reload-watch.mjs';
22
22
  import { bootProfile, utcTimestamp } from './boot-profile.mjs';
23
- import {
24
- isChannelsDegraded,
25
- logCrash,
26
- _isBenignCrash,
27
- BENIGN_CRASH_FATAL_THRESHOLD,
28
- BENIGN_CRASH_STREAK_WINDOW_MS,
29
- } from './crash-log.mjs';
23
+ import { isChannelsDegraded, crashEndsProcess } from './crash-log.mjs';
30
24
  import { createParentBridge } from './parent-bridge.mjs';
31
25
  import { createToolDispatch } from './tool-dispatch.mjs';
32
26
  import { createOwnerHeartbeat } from './owner-heartbeat.mjs';
@@ -34,23 +28,8 @@ import { runWorkerIpc } from './worker-ipc.mjs';
34
28
  import { createOwnedRuntime } from './owned-runtime.mjs';
35
29
  import { runWorkerBootstrap } from './worker-bootstrap.mjs';
36
30
  const _require = createRequire(import.meta.url);
37
- // Zombie-Lead repro (2026-07-02): logCrash-then-survive left a worker alive
38
- // after an unhandled rejection whose async state was already corrupted
39
- // (observed: EPERM on active-instance.json rename retry), so it spun
40
- // forever doing nothing useful — a zombie Lead. Fatal-exit on repeat.
41
- let _benignCrashStreak = 0;
42
- let _lastBenignCrashAt = 0;
43
31
  function _fatalCrash(label, err) {
44
- logCrash(label, err);
45
- const benign = _isBenignCrash(err);
46
- if (benign) {
47
- const now = Date.now();
48
- _benignCrashStreak = now - _lastBenignCrashAt <= BENIGN_CRASH_STREAK_WINDOW_MS ? _benignCrashStreak + 1 : 1;
49
- _lastBenignCrashAt = now;
50
- if (_benignCrashStreak < BENIGN_CRASH_FATAL_THRESHOLD) return;
51
- } else {
52
- _benignCrashStreak = 0;
53
- }
32
+ if (!crashEndsProcess(label, err)) return;
54
33
  Promise.resolve()
55
34
  .then(() => (typeof stop === 'function' ? stop(`fatal:${label}`) : null))
56
35
  .catch(() => {})
@@ -69,8 +48,12 @@ function _fatalCrash(label, err) {
69
48
  } catch {}
70
49
  }, 3000).unref?.();
71
50
  }
72
- process.on('unhandledRejection', (err) => _fatalCrash('unhandled rejection', err));
73
- process.on('uncaughtException', (err) => _fatalCrash('uncaught exception', err));
51
+ // Inside the daemon host the daemon owns fatal handling: exiting from here
52
+ // would skip its shutdown (log line, PG stop, session teardown).
53
+ if (process.env.MIXDOG_DAEMON_HOST !== '1') {
54
+ process.on('unhandledRejection', (err) => _fatalCrash('unhandled rejection', err));
55
+ process.on('uncaughtException', (err) => _fatalCrash('uncaught exception', err));
56
+ }
74
57
  if (process.env.MIXDOG_CHANNELS_NO_CONNECT) {
75
58
  process.exit(0);
76
59
  }
@@ -229,13 +229,13 @@ export const COMPUTER_ACTION_CONTRACTS = [
229
229
  minItems: 1,
230
230
  maxItems: 6,
231
231
  description:
232
- 'First: an input action. Then type/key/wait reusing focus, or click/double_click/triple_click/scroll/set_value/type/key on a ref from the same observation (no marks or coordinates). Waits total ≤10s; transition/failure or a changed, disabled, or off-screen ref stops the rest.',
232
+ 'First: an input action. Then type/key/wait reusing focus, or click/double_click/triple_click/scroll/set_value/type/key on a ref from the same observation (no marks or coordinates). act already settles after each action; wait is a fixed pause for a known async delay (quiet:true ends it early once windows stop changing; see wait.quiet) and totals ≤10s; use verify for a real condition. Transition/failure or a changed, disabled, or off-screen ref stops the rest.',
233
233
  },
234
234
  observe: {
235
235
  type: 'string',
236
236
  enum: ['state', 'ax'],
237
237
  description:
238
- 'Returned observation. Default: ax when the first action targets a ref (full state if the tree is unusable), otherwise state. state includes the frame for coordinates or visual checks; ax skips the screenshot.',
238
+ 'Returned observation. Default: ax when the first action targets a ref (full state if the tree is unusable), otherwise state. state includes the frame for coordinates or visual checks; ax skips the screenshot. A repeat observation of the same window may send elements_delta instead of elements: unchanged lists "old ref=live ref" ranges for rows that look identical to the list you hold (s1:e0..e4=s9:e0..e4), added has every other row in full, removed the old refs that are gone. Every ref from an earlier observation is retired: act only with the live ref on the right of "=" or on an added row. A new window, a dialog or a large change returns the full elements list, and capture always does.',
239
239
  },
240
240
  ...delivery,
241
241
  },
@@ -90,7 +90,18 @@ export const COMPUTER_CORE_ACTION_SCHEMA = {
90
90
  'Key name or chord. Keyboard chords with ctrl/shift/alt require explicit foreground delivery; background supports plain keys.',
91
91
  pattern: '^[^\\u0000-\\u001F\\u007F-\\u009F]+$',
92
92
  },
93
- duration: { type: 'number', minimum: 0, maximum: 5 },
93
+ duration: {
94
+ type: 'number',
95
+ minimum: 0,
96
+ maximum: 5,
97
+ description:
98
+ 'wait: cap in seconds. act already settles after every action; use wait only for a known async delay.',
99
+ },
100
+ quiet: {
101
+ type: 'boolean',
102
+ description:
103
+ 'wait: opt-in (default false, a fixed pause). true ends before duration once the window set, foreground, focused window, title and bounds stop changing (3 equal samples 200 ms apart); use it when waiting for a window or dialog to open, close or move. Content changes inside a window (canvas, text) are not seen: use verify for those.',
104
+ },
94
105
  },
95
106
  required: ['type'],
96
107
  additionalProperties: false,
@@ -114,7 +125,7 @@ const FIELDS_BY_TYPE = {
114
125
  key: new Set(['type', 'ref', 'keys']),
115
126
  key_down: new Set(['type', 'ref', 'keys']),
116
127
  key_up: new Set(['type', 'ref', 'keys']),
117
- wait: new Set(['type', 'duration']),
128
+ wait: new Set(['type', 'duration', 'quiet']),
118
129
  };
119
130
 
120
131
  function targetFormError(action, { required = true, frameId = '' } = {}) {
@@ -153,6 +164,9 @@ function fieldValueError(field, value, label) {
153
164
  if (schema.type === 'number' && (typeof value !== 'number' || !Number.isFinite(value))) {
154
165
  return `${label}.${field} must be a finite number`;
155
166
  }
167
+ if (schema.type === 'boolean' && typeof value !== 'boolean') {
168
+ return `${label}.${field} must be a boolean`;
169
+ }
156
170
  if (typeof value === 'number') {
157
171
  if (schema.minimum !== undefined && value < schema.minimum) {
158
172
  return `${label}.${field} must be at least ${schema.minimum}`;
@@ -111,6 +111,12 @@ function ocrTextLine(row) {
111
111
  function renderObservationLines(frame) {
112
112
  if (!frame || typeof frame !== 'object') return;
113
113
  if (Array.isArray(frame.elements)) frame.elements = frame.elements.map(elementLine);
114
+ const delta = frame.elements_delta;
115
+ if (delta && typeof delta === 'object') {
116
+ if (Array.isArray(delta.added)) delta.added = delta.added.map(elementLine);
117
+ // The delta already says what changed; the host's count summary repeats it.
118
+ delete frame.changes;
119
+ }
114
120
  for (const key of ['lines', 'words']) {
115
121
  if (Array.isArray(frame.ocr?.[key])) frame.ocr[key] = frame.ocr[key].map(ocrTextLine);
116
122
  }
@@ -33,6 +33,7 @@ function snapshot(job) {
33
33
  model: job.model,
34
34
  prompt: job.prompt,
35
35
  options: job.options,
36
+ boardId: job.boardId,
36
37
  progress: job.progress,
37
38
  assetId: job.assetId,
38
39
  error: job.error,
@@ -101,6 +102,7 @@ async function beginMediaJob({
101
102
  references = [],
102
103
  sessionId = '',
103
104
  sourceType = '',
105
+ boardId = '',
104
106
  } = {}) {
105
107
  const text = String(prompt || '').trim();
106
108
  if (!text) throw mediaError('prompt is required', 'MEDIA_PROMPT_REQUIRED');
@@ -143,6 +145,8 @@ async function beginMediaJob({
143
145
  model: resolved.model,
144
146
  prompt: text,
145
147
  options: { ...options },
148
+ // The Studio board the result joins when it lands ('' = none).
149
+ boardId: typeof boardId === 'string' ? boardId.slice(0, 64) : '',
146
150
  progress: 0,
147
151
  assetId: null,
148
152
  error: null,
@@ -209,6 +213,7 @@ async function runJob(job, resolved, { requestModel, options, references, sessio
209
213
  mime: result.mime,
210
214
  bytes: result.bytes,
211
215
  meta: {
216
+ ...(job.boardId ? { boardId: job.boardId } : {}),
212
217
  ...(result.revisedPrompt ? { revisedPrompt: result.revisedPrompt } : {}),
213
218
  ...(result.durationSeconds ? { durationSeconds: result.durationSeconds } : {}),
214
219
  },