mixdog 1.4.4 → 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 (218) hide show
  1. package/package.json +1 -2
  2. package/src/cli.mjs +5 -1
  3. package/src/defaults/shipped-history.json +26 -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 -240
  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 +16 -20
  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 +72 -13
  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/lead/LEAD.md +3 -1
  64. package/src/runtime/agent/orchestrator/agent-runtime/cache-strategy.mjs +8 -30
  65. package/src/runtime/agent/orchestrator/agent-runtime/title-completion.mjs +5 -0
  66. package/src/runtime/agent/orchestrator/mcp/oauth-request.mjs +21 -2
  67. package/src/runtime/agent/orchestrator/providers/account-pool.mjs +3 -0
  68. package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +2 -2
  69. package/src/runtime/agent/orchestrator/providers/anthropic-api-transport.mjs +2 -0
  70. package/src/runtime/agent/orchestrator/providers/anthropic-message-threads.mjs +583 -0
  71. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-client-version.mjs +1 -1
  72. package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +81 -19
  73. package/src/runtime/agent/orchestrator/providers/anthropic-sse.mjs +180 -13
  74. package/src/runtime/agent/orchestrator/providers/anthropic.mjs +56 -6
  75. package/src/runtime/agent/orchestrator/providers/cursor-wire.mjs +4 -2
  76. package/src/runtime/agent/orchestrator/providers/gemini-error-contract.mjs +6 -6
  77. package/src/runtime/agent/orchestrator/providers/gemini-model-redirect.mjs +44 -0
  78. package/src/runtime/agent/orchestrator/providers/gemini-reasoning-relay.mjs +5 -0
  79. package/src/runtime/agent/orchestrator/providers/gemini-request-body.mjs +34 -5
  80. package/src/runtime/agent/orchestrator/providers/gemini-response.mjs +10 -0
  81. package/src/runtime/agent/orchestrator/providers/gemini-schema.mjs +11 -6
  82. package/src/runtime/agent/orchestrator/providers/gemini-sdk-request.mjs +4 -100
  83. package/src/runtime/agent/orchestrator/providers/gemini-stream.mjs +3 -227
  84. package/src/runtime/agent/orchestrator/providers/gemini.mjs +226 -118
  85. package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +11 -1
  86. package/src/runtime/agent/orchestrator/providers/lib/claude-bridge-schema.mjs +15 -3
  87. package/src/runtime/agent/orchestrator/providers/lib/gemini-model-catalog.mjs +2 -1
  88. package/src/runtime/agent/orchestrator/providers/openai-direct-request.mjs +5 -28
  89. package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +50 -28
  90. package/src/runtime/agent/orchestrator/providers/openai-ws-stream/socket-handlers.mjs +14 -10
  91. package/src/runtime/agent/orchestrator/providers/openai-ws.mjs +1 -3
  92. package/src/runtime/agent/orchestrator/providers/stream-json-pool/worker-slots/slot-spawn.mjs +8 -3
  93. package/src/runtime/agent/orchestrator/providers/vertex-ai-maas.mjs +2 -2
  94. package/src/runtime/agent/orchestrator/runtime-core/config-helpers.mjs +4 -5
  95. package/src/runtime/agent/orchestrator/runtime-core/goal-tool-defs.mjs +2 -2
  96. package/src/runtime/agent/orchestrator/runtime-core/provider-request-tools.mjs +15 -8
  97. package/src/runtime/agent/orchestrator/runtime-core/session-title.mjs +1 -0
  98. package/src/runtime/agent/orchestrator/runtime-core/todo-list.mjs +9 -32
  99. package/src/runtime/agent/orchestrator/runtime-core/todo-tool-defs.mjs +4 -5
  100. package/src/runtime/agent/orchestrator/session/compact/summary-route.mjs +1 -3
  101. package/src/runtime/agent/orchestrator/session/loop/compact-policy.mjs +5 -2
  102. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/todo-check.mjs +2 -17
  103. package/src/runtime/agent/orchestrator/session/loop/usage.mjs +7 -3
  104. package/src/runtime/agent/orchestrator/session/manager/ask-turn-settle.mjs +9 -2
  105. package/src/runtime/agent/orchestrator/session/manager/session-close.mjs +26 -13
  106. package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +4 -5
  107. package/src/runtime/agent/orchestrator/session/manager/usage-metrics.mjs +16 -5
  108. package/src/runtime/agent/orchestrator/session/store/lifecycle-barriers.mjs +22 -1
  109. package/src/runtime/agent/orchestrator/session/store/live-state.mjs +4 -0
  110. package/src/runtime/agent/orchestrator/tools/builtin/cache-layers.mjs +11 -9
  111. package/src/runtime/agent/orchestrator/tools/builtin/grep-formatting.mjs +2 -8
  112. package/src/runtime/agent/orchestrator/tools/builtin/lib/search-input-helpers.mjs +1 -9
  113. package/src/runtime/agent/orchestrator/tools/builtin/local-search-telemetry.mjs +2 -2
  114. package/src/runtime/agent/orchestrator/tools/builtin/native-search-client.mjs +1 -1
  115. package/src/runtime/agent/orchestrator/tools/builtin/runtime-capabilities.mjs +12 -3
  116. package/src/runtime/agent/orchestrator/tools/code-graph/ast-calls.mjs +9 -2
  117. package/src/runtime/agent/orchestrator/tools/code-graph/build.mjs +137 -7
  118. package/src/runtime/agent/orchestrator/tools/code-graph/calls-cache.mjs +43 -14
  119. package/src/runtime/agent/orchestrator/tools/code-graph/calls-sidecar-worker.mjs +33 -0
  120. package/src/runtime/agent/orchestrator/tools/code-graph/disk-cache.mjs +146 -11
  121. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +31 -24
  122. package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary/spawn-jsonl.mjs +172 -25
  123. package/src/runtime/agent/orchestrator/tools/code-graph/graph-model.mjs +100 -2
  124. package/src/runtime/agent/orchestrator/tools/code-graph/main-thread-slice.mjs +18 -0
  125. package/src/runtime/agent/orchestrator/tools/code-graph/mask-pool.mjs +219 -0
  126. package/src/runtime/agent/orchestrator/tools/code-graph/mask-worker.mjs +12 -0
  127. package/src/runtime/agent/orchestrator/tools/code-graph/memory-cache.mjs +6 -1
  128. package/src/runtime/agent/orchestrator/tools/code-graph/modes/calls.mjs +9 -2
  129. package/src/runtime/agent/orchestrator/tools/code-graph/modes/dependents.mjs +5 -1
  130. package/src/runtime/agent/orchestrator/tools/code-graph/modes/structure.mjs +8 -2
  131. package/src/runtime/agent/orchestrator/tools/code-graph/modes/symbols.mjs +14 -11
  132. package/src/runtime/agent/orchestrator/tools/code-graph/search-references.mjs +41 -18
  133. package/src/runtime/agent/orchestrator/tools/code-graph/search.mjs +391 -83
  134. package/src/runtime/agent/orchestrator/tools/code-graph/symbol-index.mjs +109 -9
  135. package/src/runtime/agent/orchestrator/tools/code-graph/text-mask.mjs +73 -29
  136. package/src/runtime/agent/orchestrator/tools/code-graph-prewarm-worker.mjs +6 -5
  137. package/src/runtime/agent/orchestrator/tools/lib/native-spawn-client.mjs +7 -3
  138. package/src/runtime/channels/lib/crash-log.mjs +21 -1
  139. package/src/runtime/channels/lib/worker-main.mjs +8 -25
  140. package/src/runtime/media/jobs.mjs +5 -0
  141. package/src/runtime/media/store.mjs +146 -3
  142. package/src/runtime/office/core/office-write-ledger.mjs +2 -2
  143. package/src/runtime/shared/agent-reap-state.mjs +19 -0
  144. package/src/runtime/shared/desktop-notice-host.d.mts +13 -0
  145. package/src/runtime/shared/desktop-notice-host.mjs +87 -0
  146. package/src/runtime/shared/file-lock.mjs +2 -2
  147. package/src/runtime/shared/heap-cap.mjs +9 -11
  148. package/src/runtime/shared/llm/http-agent.mjs +11 -1
  149. package/src/runtime/shared/llm/system-proxy.mjs +100 -25
  150. package/src/runtime/shared/llm/usage-accounting.mjs +18 -7
  151. package/src/runtime/shared/llm/usage-context.mjs +2 -2
  152. package/src/runtime/shared/llm/usage-ledger-requests.mjs +10 -3
  153. package/src/runtime/shared/llm/usage-ledger.mjs +13 -1
  154. package/src/runtime/shared/provider-accounts.mjs +22 -0
  155. package/src/runtime/shared/provider-auth-binding.mjs +2 -2
  156. package/src/runtime/shared/resource-admission.mjs +2 -2
  157. package/src/runtime/shared/root-async-context.mjs +51 -0
  158. package/src/runtime/shared/run-child.mjs +18 -1
  159. package/src/runtime/shared/slow-span.mjs +2 -2
  160. package/src/runtime/shared/tool-execution-owner.mjs +2 -2
  161. package/src/runtime/shared/tool-work-units.mjs +2 -0
  162. package/src/runtime/shared/turn-snapshot-store.mjs +75 -18
  163. package/src/runtime/shared/turn-worktree-snapshot.mjs +38 -8
  164. package/src/runtime/shared/user-cwd.mjs +2 -2
  165. package/src/runtime/shared/worker-requests.mjs +3 -1
  166. package/src/runtime/shared/worktrees/lock.mjs +2 -2
  167. package/src/runtime/visualize-bridge/client.mjs +26 -4
  168. package/src/runtime/visualize-bridge/tool-defs.mjs +46 -5
  169. package/src/session-runtime/boot/apis.mjs +1 -0
  170. package/src/session-runtime/boot/begin.mjs +2 -0
  171. package/src/session-runtime/media-api.mjs +15 -0
  172. package/src/session-runtime/provider-readiness.mjs +10 -2
  173. package/src/session-runtime/runtime-core.mjs +35 -8
  174. package/src/session-runtime/runtime-review-api.mjs +3 -1
  175. package/src/session-runtime/services/agent-tool/close-flow.mjs +6 -1
  176. package/src/session-runtime/services/agent-tool/execute-resume.mjs +94 -0
  177. package/src/session-runtime/services/agent-tool/execute-send.mjs +77 -27
  178. package/src/session-runtime/services/agent-tool/execute-spawn.mjs +28 -7
  179. package/src/session-runtime/services/agent-tool/execute.mjs +6 -1
  180. package/src/session-runtime/services/agent-tool/helpers.mjs +11 -0
  181. package/src/session-runtime/services/agent-tool/job-views/job-render.mjs +13 -10
  182. package/src/session-runtime/services/agent-tool/render.mjs +2 -0
  183. package/src/session-runtime/services/agent-tool/send-flow.mjs +1 -0
  184. package/src/session-runtime/services/agent-tool/spawn-flow/spawn-prep.mjs +6 -0
  185. package/src/session-runtime/services/agent-tool/spawn-flow/spawn-run.mjs +2 -1
  186. package/src/session-runtime/services/agent-tool/tag-registry/reaped-sessions.mjs +82 -0
  187. package/src/session-runtime/services/agent-tool/tag-registry/record-facts-worker.mjs +36 -0
  188. package/src/session-runtime/services/agent-tool/tag-registry.mjs +4 -0
  189. package/src/session-runtime/services/agent-tool/terminal-reaper/row-helpers.mjs +29 -0
  190. package/src/session-runtime/services/agent-tool/terminal-reaper/scan-admission.mjs +11 -3
  191. package/src/session-runtime/services/agent-tool/terminal-reaper/stale-rows.mjs +19 -8
  192. package/src/session-runtime/services/agent-tool/terminal-reaper.mjs +5 -2
  193. package/src/session-runtime/services/agent-tool/worker-index.mjs +1 -0
  194. package/src/session-runtime/services/daemon-crash-capture/daemon-exit-record.mjs +2 -2
  195. package/src/session-runtime/session-create.mjs +5 -0
  196. package/src/session-runtime/setup-tool/settings-contract.mjs +2 -0
  197. package/src/session-runtime/usage-stats-api.mjs +3 -0
  198. package/src/session-runtime/workspace/admission-gate.mjs +25 -7
  199. package/src/session-runtime/workspace/transitions.mjs +4 -0
  200. package/src/standalone/daemon-log.mjs +28 -4
  201. package/src/standalone/daemon-owner.mjs +41 -7
  202. package/src/standalone/daemon-work-gate.mjs +139 -0
  203. package/src/standalone/daemon.mjs +80 -11
  204. package/src/standalone/desktop-service-registry.mjs +11 -4
  205. package/src/standalone/session-client.mjs +57 -5
  206. package/src/standalone/session-protocol.mjs +5 -0
  207. package/src/standalone/session-service/agent-tree/agent-cancel.mjs +17 -1
  208. package/src/standalone/session-service/agent-tree.mjs +7 -0
  209. package/src/standalone/session-service/session-calls/session-turns.mjs +12 -5
  210. package/src/standalone/session-transport/call-route.mjs +10 -4
  211. package/src/standalone/session-transport/routes.mjs +21 -0
  212. package/src/standalone/session-transport/stack.mjs +3 -1
  213. package/src/standalone/session-transport.mjs +5 -0
  214. package/src/tui/dist/index.mjs +495 -477
  215. package/src/tui/session/session-api/media.mjs +5 -0
  216. package/src/tui/session/turn.mjs +13 -0
  217. package/src/runtime/agent/orchestrator/providers/gemini-sdk-stream/cancellation.mjs +0 -71
  218. 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 };
@@ -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
  }
@@ -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
  },
@@ -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) {
@@ -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