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
@@ -1,6 +1,7 @@
1
1
  // Symbol search / callers / callees / references / impact query layer over a
2
2
  // built graph. Pure over {graph,cwd,args}; owns no cache state.
3
3
  import { readFile } from 'node:fs/promises';
4
+ import { runtimeAsyncLocalStorage } from '../../../../shared/root-async-context.mjs';
4
5
  import { existsSync } from 'node:fs';
5
6
  import { resolve as pathResolve, dirname as pathDirname, basename as pathBasename } from 'node:path';
6
7
  import { normalizeOutputPath } from '../builtin/path-utils.mjs';
@@ -12,7 +13,17 @@ import {
12
13
  _graphRel,
13
14
  _isExistingFile,
14
15
  } from './source-access.mjs';
15
- import { _escapeRegExp, _unicodeBoundaryPattern, _lookupCandidateNodes, _symbolLine } from './symbol-index.mjs';
16
+ import {
17
+ _escapeRegExp,
18
+ _unicodeBoundaryPattern,
19
+ _lookupCandidateNodes,
20
+ _tokenCandidateNodes,
21
+ _symbolLine,
22
+ } from './symbol-index.mjs';
23
+ import { _mainThreadSlice } from './main-thread-slice.mjs';
24
+ import { _maskTextsOffThread } from './mask-pool.mjs';
25
+ import { _createNonCodeMasker } from './text-mask.mjs';
26
+ import { _noteRuntimeCacheEntryBytes } from './graph-model.mjs';
16
27
  import { CODE_GRAPH_MAX_FILES } from './constants.mjs';
17
28
  import { _symbolPathForSymbol } from './text-columns.mjs';
18
29
  import { _keywordSymbolSortKey, _tokenizeKeyword, _keywordMatchesSymbolName } from './keyword-match.mjs';
@@ -49,7 +60,12 @@ export {
49
60
  // cannot resolve is simply reported as external. Rows are deduped by
50
61
  // (kind, recv, name) and carry kind/recv. A file whose `calls` is absent or
51
62
  // malformed contributes no rows at all.
52
- export function _extractCallees(graph, declHit, _cwd, { cap = 200, callerSymbol = null, language = null } = {}) {
63
+ export async function _extractCallees(
64
+ graph,
65
+ declHit,
66
+ _cwd,
67
+ { cap = 200, callerSymbol = null, language = null, signal = null } = {}
68
+ ) {
53
69
  if (!declHit) return [];
54
70
  const declNode = graph.nodes.get(declHit.rel);
55
71
  if (!declNode) return [];
@@ -62,11 +78,17 @@ export function _extractCallees(graph, declHit, _cwd, { cap = 200, callerSymbol
62
78
  }
63
79
  const all = [...seen.values()];
64
80
  const sliced = all.slice(0, cap);
81
+ await _prewarmSymbolSources(graph, [...new Set(sliced.map((call) => call.name))], language, {
82
+ declaringOnly: true,
83
+ signal,
84
+ });
65
85
  const sourceLines = _getSourceLinesForNode(graph, declNode);
66
86
  const importedRels = _astImportedRels(declNode, graph?.cwd || _cwd);
67
87
  const declLookupCache = new Map();
68
88
  const rows = [];
89
+ const slice = _mainThreadSlice();
69
90
  for (const call of sliced) {
91
+ if (slice.expired()) await slice.yield();
70
92
  let declPath = '';
71
93
  let declLine = 0;
72
94
  let resolved = false;
@@ -189,6 +211,195 @@ export async function _prewarmSourceTextNodes(
189
211
  return sourceNodes;
190
212
  }
191
213
 
214
+ // ~1M chars per worker message: large enough to amortize the round trip, small
215
+ // enough that copying one batch in or out is a short main-thread stretch.
216
+ const MASK_BATCH_CHARS = 1 << 20;
217
+ const MASK_BATCHES_IN_FLIGHT = 2;
218
+ // Largest file of a refused or failed batch masked here at once instead of
219
+ // waiting for pool admission; also the size from which a line split runs in
220
+ // slices (a split of a 4 MB file is a ~10 ms stretch, ~35 ms on a slow runner).
221
+ const INLINE_MASK_MAX_CHARS = 128 * 1024;
222
+ // Source chars a resumable mask scans between slice checks: ~0.06 ms warm, but
223
+ // the first steps of a cold process run before the JIT has the scanner (2.4 ms
224
+ // at 4K chars, 6 ms at 16K).
225
+ const MASK_STEP_CHARS = 4 * 1024;
226
+
227
+ // `text.split(/\r?\n/)` in yielding slices, for texts too large to split in one.
228
+ async function _splitLinesSliced(text, slice) {
229
+ const lines = [];
230
+ let start = 0;
231
+ for (;;) {
232
+ const end = text.indexOf('\n', start);
233
+ if (end < 0) {
234
+ lines.push(text.slice(start));
235
+ return lines;
236
+ }
237
+ lines.push(text.slice(start, end > start && text.charCodeAt(end - 1) === 13 ? end - 1 : end));
238
+ start = end + 1;
239
+ if ((lines.length & 1023) === 0 && slice.expired()) await slice.yield();
240
+ }
241
+ }
242
+
243
+ // _getSourceLinesForNode, with the split of a large text in slices.
244
+ async function _prewarmSourceLines(graph, node, text, slice) {
245
+ const fingerprint = node.fingerprint || '';
246
+ if (text.length > INLINE_MASK_MAX_CHARS && graph._sourceLinesCache?.get(node.rel)?.fingerprint !== fingerprint) {
247
+ const lines = await _splitLinesSliced(text, slice);
248
+ // Lines must come from the text the synchronous path would read.
249
+ if (
250
+ graph._sourceTextCache?.get(node.rel)?.text === text &&
251
+ graph._sourceLinesCache?.get(node.rel)?.fingerprint !== fingerprint
252
+ ) {
253
+ graph._sourceLinesCache?.set(node.rel, { fingerprint, lines });
254
+ }
255
+ }
256
+ _getSourceLinesForNode(graph, node);
257
+ await _noteRuntimeCacheEntryBytes(graph._sourceLinesCache?.get(node.rel), slice);
258
+ }
259
+
260
+ // Source text, source lines and (unless `masked:false`) masked lines of
261
+ // `nodes`, computed before a query's synchronous evaluation reads them: the
262
+ // reads are async, masking runs in the mask worker pool, and the line splits
263
+ // are time-sliced. The caches are the ones the synchronous accessors read, so
264
+ // the answer is unchanged; a node this misses (unreadable, evicted mid-query)
265
+ // is simply computed on demand as before. Of a batch the pool refuses or
266
+ // fails, small files are masked here in slices and larger ones wait for pool
267
+ // admission.
268
+ export async function _prewarmMaskedSourceNodes(graph, nodes, { masked = true, signal = null, ...options } = {}) {
269
+ const sourceNodes = await _prewarmSourceTextNodes(graph, nodes, { ...options, signal });
270
+ const ready = [];
271
+ for (const node of sourceNodes) {
272
+ const cached = graph._sourceTextCache?.get(node.rel);
273
+ if (cached && cached.fingerprint === (node.fingerprint || '')) ready.push({ node, text: cached.text });
274
+ }
275
+ const pending = masked
276
+ ? ready.filter(({ node }) => graph._maskedLinesCache?.get(node.rel)?.fingerprint !== (node.fingerprint || ''))
277
+ : [];
278
+ const slice = _mainThreadSlice();
279
+ // A hard cap checked before a file joins a batch; a file larger than the cap
280
+ // goes alone.
281
+ const batches = [];
282
+ let start = 0;
283
+ for (let i = 0, bytes = 0; i < pending.length; i++) {
284
+ const size = pending[i].text.length;
285
+ if (i > start && bytes + size > MASK_BATCH_CHARS) {
286
+ batches.push(pending.slice(start, i));
287
+ start = i;
288
+ bytes = 0;
289
+ }
290
+ bytes += size;
291
+ }
292
+ if (start < pending.length) batches.push(pending.slice(start));
293
+ // Two batches in flight: posting copies a batch's texts on this thread, so
294
+ // posting every batch at once was itself a long stretch on a common name.
295
+ const inFlight = [];
296
+ let nextBatch = 0;
297
+ const launch = () => {
298
+ const batch = batches[nextBatch++];
299
+ const texts = batch.map(({ text }) => text);
300
+ const langs = batch.map(({ node }) => node.lang);
301
+ // A refused or failed batch (pool saturated, deadline, crash) is handled
302
+ // below file by file, rather than in one unyielding stretch when
303
+ // evaluation reads it.
304
+ inFlight.push({ batch, reply: _maskTextsOffThread(texts, langs, { signal }).catch(() => null) });
305
+ };
306
+ while (inFlight.length < MASK_BATCHES_IN_FLIGHT && nextBatch < batches.length) launch();
307
+ for (const { node, text } of ready) {
308
+ if (signal?.aborted) return sourceNodes;
309
+ await _prewarmSourceLines(graph, node, text, slice);
310
+ if (slice.expired()) await slice.yield();
311
+ }
312
+ // Files over INLINE_MASK_MAX_CHARS of a refused or failed batch: masking one
313
+ // is a single unyielding stretch, so they wait for pool admission instead.
314
+ const waiting = [];
315
+ const store = async (node, text, masked) => {
316
+ const fingerprint = node.fingerprint || '';
317
+ // Masked lines must come from the text the synchronous path would read.
318
+ if (graph._sourceTextCache?.get(node.rel)?.text !== text) return;
319
+ if (graph._maskedLinesCache?.get(node.rel)?.fingerprint === fingerprint) return;
320
+ if (masked === null) {
321
+ // The pool refused or failed this file: mask it here, resumably, in slices.
322
+ const masker = _createNonCodeMasker(text, node.lang);
323
+ while (!masker.advance(MASK_STEP_CHARS)) {
324
+ if (slice.expired()) await slice.yield();
325
+ if (signal?.aborted) return;
326
+ }
327
+ masked = masker.result();
328
+ }
329
+ const lines =
330
+ masked.length > INLINE_MASK_MAX_CHARS ? await _splitLinesSliced(masked, slice) : masked.split(/\r?\n/);
331
+ if (graph._maskedLinesCache?.get(node.rel)?.fingerprint === fingerprint) return;
332
+ const entry = { fingerprint, lines };
333
+ graph._maskedLinesCache?.set(node.rel, entry);
334
+ await _noteRuntimeCacheEntryBytes(entry, slice);
335
+ if (slice.expired()) await slice.yield();
336
+ };
337
+ while (inFlight.length) {
338
+ const { batch, reply } = inFlight.shift();
339
+ const results = await reply;
340
+ if (signal?.aborted) return sourceNodes;
341
+ if (nextBatch < batches.length) launch();
342
+ for (const [i, { node, text }] of batch.entries()) {
343
+ if (signal?.aborted) return sourceNodes;
344
+ if (!results && text.length > INLINE_MASK_MAX_CHARS) {
345
+ const masked = _maskTextsOffThread([text], [node.lang], { signal, waitForAdmission: true });
346
+ waiting.push({ node, text, reply: masked.then(([one]) => one).catch(() => null) });
347
+ continue;
348
+ }
349
+ await store(node, text, results ? results[i] : null);
350
+ }
351
+ }
352
+ for (const { node, text, reply } of waiting) {
353
+ const masked = await reply;
354
+ if (signal?.aborted) return sourceNodes;
355
+ // Still failed after waiting its turn (deadline, crash): `store` masks it
356
+ // on this thread with the resumable masker, in slices.
357
+ await store(node, text, masked);
358
+ }
359
+ return sourceNodes;
360
+ }
361
+
362
+ // Every node the synchronous evaluation of `symbols` reads: the token
363
+ // candidates of each name and of its last path segment (the name
364
+ // _findSymbolHits looks up), or — `declaringOnly` — just the files whose
365
+ // record declares the name (what a callee resolution reads).
366
+ export async function _prewarmSymbolSources(graph, symbols, language, { declaringOnly = false, ...options } = {}) {
367
+ // Unmemoized lookups: the per-call lookup memo also feeds the casing hint of
368
+ // a no-match answer, so a prewarm must not add keys the query never asked.
369
+ const nodes = [];
370
+ const plainNames = [];
371
+ const slice = _mainThreadSlice();
372
+ for (const symbol of symbols) {
373
+ if (slice.expired()) await slice.yield();
374
+ const clean = String(symbol || '').trim();
375
+ if (clean && !clean.includes('/')) {
376
+ const candidates = _tokenCandidateNodes(graph, clean, language);
377
+ const scanned = declaringOnly ? candidates.filter((node) => _declaresName(node, clean)) : candidates;
378
+ nodes.push(...scanned);
379
+ plainNames.push({ key: _symbolHitsKey(declaringOnly ? 'decl' : 'all', clean, language), clean, scanned });
380
+ if (declaringOnly) continue;
381
+ }
382
+ const leaf =
383
+ clean
384
+ .replace(/^\/+|\/+$/g, '')
385
+ .split('/')
386
+ .at(-1) || '';
387
+ if (leaf !== clean) nodes.push(..._tokenCandidateNodes(graph, leaf, language));
388
+ if (symbol !== clean) nodes.push(..._tokenCandidateNodes(graph, symbol, language));
389
+ }
390
+ const sourceNodes = await _prewarmMaskedSourceNodes(graph, nodes, options);
391
+ // The hit scans themselves, time-sliced, for _findSymbolHits /
392
+ // _resolveCalleeDeclaration to answer from.
393
+ const memo = _queryHitsMemo(graph);
394
+ for (const { key, clean, scanned } of plainNames) {
395
+ if (!memo || options.signal?.aborted) break;
396
+ if (memo.has(key)) continue;
397
+ const hits = await _findSymbolHitsOnNodesSliced(graph, clean, scanned, { language });
398
+ if (_sourcesReadable(graph, scanned)) _memoSymbolHits(memo, key, hits);
399
+ }
400
+ return sourceNodes;
401
+ }
402
+
192
403
  export async function _prewarmReferenceSourceText(graph, symbol, language, options = {}) {
193
404
  const candidateNodes = _lookupCandidateNodes(graph, symbol, language);
194
405
  // Return the resolved candidate set so the immediately-following
@@ -238,7 +449,8 @@ export function _cheapReferenceSearch(
238
449
  const rawLines = _getSourceLinesForNode(graph, node);
239
450
  for (let i = 0; i < fileLines.length; i++) {
240
451
  const line = fileLines[i];
241
- if (!line.trim()) continue;
452
+ // Every match contains the literal symbol: skip before building the regex.
453
+ if (!line.includes(symbol) || !line.trim()) continue;
242
454
  const boundaryLang = language || node.lang;
243
455
  const re = new RegExp(_unicodeBoundaryPattern(escaped, boundaryLang, symbol), 'gu');
244
456
  for (const match of line.matchAll(re)) {
@@ -341,12 +553,27 @@ function _isCanonicalSrcRel(rel) {
341
553
  return /^src\//.test(rel || '');
342
554
  }
343
555
 
556
+ // The path-derived sort keys of a hit, computed once per hit instead of per
557
+ // comparison (a common name sorts thousands of hits).
558
+ const _hitRelRanks = new WeakMap();
559
+
560
+ function _relRank(hit) {
561
+ let rank = _hitRelRanks.get(hit);
562
+ if (!rank) {
563
+ rank = [Number(_isTypeDeclarationRel(hit.rel)), Number(_isCanonicalSrcRel(hit.rel)), _relDepth(hit.rel)];
564
+ _hitRelRanks.set(hit, rank);
565
+ }
566
+ return rank;
567
+ }
568
+
344
569
  function _compareSymbolHits(a, b) {
570
+ const ra = _relRank(a);
571
+ const rb = _relRank(b);
345
572
  return (
346
573
  Number(b.declarationLike) - Number(a.declarationLike) ||
347
- Number(_isTypeDeclarationRel(a.rel)) - Number(_isTypeDeclarationRel(b.rel)) ||
348
- Number(_isCanonicalSrcRel(b.rel)) - Number(_isCanonicalSrcRel(a.rel)) ||
349
- _relDepth(a.rel) - _relDepth(b.rel) ||
574
+ ra[0] - rb[0] ||
575
+ rb[1] - ra[1] ||
576
+ ra[2] - rb[2] ||
350
577
  b.matchCount - a.matchCount ||
351
578
  a.rel.localeCompare(b.rel) ||
352
579
  a.line - b.line
@@ -404,9 +631,54 @@ export function _findSymbolHits(graph, symbol, { language = null } = {}) {
404
631
  }
405
632
  return _sortSymbolHits(hits);
406
633
  }
634
+ const memo = _queryHitsMemo(graph)?.get(_symbolHitsKey('all', cleanSymbol, language));
635
+ if (memo) return memo.slice();
407
636
  return _findSymbolHitsOnNodes(graph, cleanSymbol, candidateNodes, { language });
408
637
  }
409
638
 
639
+ // Hits of a plain name computed ahead by _prewarmSymbolSources (time-sliced)
640
+ // for the synchronous evaluation of the SAME query. The memo is query-local
641
+ // (an async context opened by _runCodeGraphQuery around one mode call), so no
642
+ // later query can answer from it: a result computed while a source was
643
+ // unreadable, or before the file changed, ends with the query that saw it.
644
+ // Within the query it is bounded here, and a scan that met an unreadable
645
+ // candidate is not memoized at all — the synchronous call re-reads, as before.
646
+ const SYMBOL_HITS_MEMO_MAX = 256;
647
+ // A runtime store: shared handles (the mask pool's workers and timers, the
648
+ // sidecar reader) are created in the root context, which leaves it.
649
+ const _queryHitsMemos = runtimeAsyncLocalStorage();
650
+
651
+ /** Run one code_graph query with its own hit memo. */
652
+ export function _runCodeGraphQuery(fn) {
653
+ return _queryHitsMemos.run(new WeakMap(), fn);
654
+ }
655
+
656
+ function _queryHitsMemo(graph) {
657
+ const byGraph = _queryHitsMemos.getStore();
658
+ if (!byGraph || !graph || typeof graph !== 'object') return null;
659
+ let memo = byGraph.get(graph);
660
+ if (!memo) {
661
+ memo = new Map();
662
+ byGraph.set(graph, memo);
663
+ }
664
+ return memo;
665
+ }
666
+
667
+ function _symbolHitsKey(kind, cleanSymbol, language) {
668
+ return `${kind}\u0000${language || '*'}\u0000${cleanSymbol}`;
669
+ }
670
+
671
+ function _memoSymbolHits(memo, key, hits) {
672
+ memo.delete(key);
673
+ memo.set(key, hits);
674
+ while (memo.size > SYMBOL_HITS_MEMO_MAX) memo.delete(memo.keys().next().value);
675
+ }
676
+
677
+ // Every node's source was readable (cached under its fingerprint) for the scan.
678
+ function _sourcesReadable(graph, nodes) {
679
+ return nodes.every((node) => graph._sourceTextCache?.get(node.rel)?.fingerprint === (node.fingerprint || ''));
680
+ }
681
+
410
682
  // Declarations come from the native record ONLY. A regex fallback would mark
411
683
  // `declarationLike` on lines the extractor never called a declaration, so the
412
684
  // hit ranking (and, through it, the caller/callee anchors) would depend on
@@ -414,86 +686,101 @@ export function _findSymbolHits(graph, symbol, { language = null } = {}) {
414
686
  // hits — it just declares nothing.
415
687
  function _findSymbolHitsOnNodes(graph, cleanSymbol, candidateNodes, { language = null } = {}) {
416
688
  if (!cleanSymbol) return [];
417
- const escaped = _escapeRegExp(cleanSymbol);
418
689
  const hits = [];
690
+ for (const node of candidateNodes) _symbolHitsOnNode(graph, node, cleanSymbol, language, hits);
691
+ return hits.length ? _sortSymbolHits(hits) : [];
692
+ }
693
+
694
+ // _findSymbolHitsOnNodes, time-sliced between files.
695
+ async function _findSymbolHitsOnNodesSliced(graph, cleanSymbol, candidateNodes, { language = null } = {}) {
696
+ if (!cleanSymbol) return [];
697
+ const hits = [];
698
+ const slice = _mainThreadSlice();
419
699
  for (const node of candidateNodes) {
420
- const nativeSymbols = (Array.isArray(node.symbols) ? node.symbols : []).filter(
421
- (symbol) => symbol?.name === cleanSymbol
422
- );
423
- const sourceText = _getSourceTextForNode(graph, node);
424
- if (!sourceText.includes(cleanSymbol)) {
425
- for (const nativeSymbol of nativeSymbols) {
426
- const hit = _nativeSymbolHit(node, nativeSymbol);
427
- if (hit) hits.push(hit);
428
- }
429
- continue;
430
- }
431
- const boundaryLang = language || node.lang;
432
- const re = new RegExp(_unicodeBoundaryPattern(escaped, boundaryLang, cleanSymbol), 'gu');
433
- const sourceLines = _getSourceLinesForNode(graph, node);
434
- const lines = _getMaskedLinesForNode(graph, node);
435
- let firstLine = null;
436
- let firstCol = null;
437
- let matchCount = 0;
438
- let firstContent = '';
439
- let contextLines = [];
440
- let declarationLike = Array.isArray(node.topLevelTypes) && node.topLevelTypes.includes(cleanSymbol);
441
- const nativeDeclSymbols = new Map();
700
+ _symbolHitsOnNode(graph, node, cleanSymbol, language, hits);
701
+ if (slice.expired()) await slice.yield();
702
+ }
703
+ return hits.length ? _sortSymbolHits(hits) : [];
704
+ }
705
+
706
+ // Appends the hits one candidate file contributes to `hits`.
707
+ function _symbolHitsOnNode(graph, node, cleanSymbol, language, hits) {
708
+ const nativeSymbols = (Array.isArray(node.symbols) ? node.symbols : []).filter(
709
+ (symbol) => symbol?.name === cleanSymbol
710
+ );
711
+ const sourceText = _getSourceTextForNode(graph, node);
712
+ if (!sourceText.includes(cleanSymbol)) {
442
713
  for (const nativeSymbol of nativeSymbols) {
443
- const line = _symbolLine(nativeSymbol);
444
- if (line && !nativeDeclSymbols.has(line)) nativeDeclSymbols.set(line, nativeSymbol);
714
+ const hit = _nativeSymbolHit(node, nativeSymbol);
715
+ if (hit) hits.push(hit);
445
716
  }
446
- let declLine = null;
447
- let declCol = null;
448
- let declContent = '';
449
- let declContext = [];
450
- let declSymbol = null;
451
- for (let i = 0; i < lines.length; i++) {
452
- const line = lines[i];
453
- if (!line.trim()) continue;
454
- let localHit = false;
455
- for (const match of line.matchAll(re)) {
456
- matchCount += 1;
457
- localHit = true;
458
- if (firstLine == null) {
459
- firstLine = i + 1;
460
- firstCol = match.index + 1;
461
- firstContent = String(sourceLines[i] || '').trim();
462
- contextLines = _hitContextLines(sourceLines, i);
463
- }
464
- if (declLine == null && nativeDeclSymbols.has(i + 1)) {
465
- declLine = i + 1;
466
- declCol = match.index + 1;
467
- declContent = String(sourceLines[i] || '').trim();
468
- declContext = _hitContextLines(sourceLines, i);
469
- declSymbol = nativeDeclSymbols.get(i + 1);
470
- }
717
+ return;
718
+ }
719
+ const boundaryLang = language || node.lang;
720
+ const re = new RegExp(_unicodeBoundaryPattern(_escapeRegExp(cleanSymbol), boundaryLang, cleanSymbol), 'gu');
721
+ const sourceLines = _getSourceLinesForNode(graph, node);
722
+ const lines = _getMaskedLinesForNode(graph, node);
723
+ let firstLine = null;
724
+ let firstCol = null;
725
+ let matchCount = 0;
726
+ let firstContent = '';
727
+ let contextLines = [];
728
+ let declarationLike = Array.isArray(node.topLevelTypes) && node.topLevelTypes.includes(cleanSymbol);
729
+ const nativeDeclSymbols = new Map();
730
+ for (const nativeSymbol of nativeSymbols) {
731
+ const line = _symbolLine(nativeSymbol);
732
+ if (line && !nativeDeclSymbols.has(line)) nativeDeclSymbols.set(line, nativeSymbol);
733
+ }
734
+ let declLine = null;
735
+ let declCol = null;
736
+ let declContent = '';
737
+ let declContext = [];
738
+ let declSymbol = null;
739
+ for (let i = 0; i < lines.length; i++) {
740
+ const line = lines[i];
741
+ // Every match contains the literal name, so a line without it is skipped
742
+ // before the per-line regex iterator is allocated.
743
+ if (!line.includes(cleanSymbol) || !line.trim()) continue;
744
+ let localHit = false;
745
+ for (const match of line.matchAll(re)) {
746
+ matchCount += 1;
747
+ localHit = true;
748
+ if (firstLine == null) {
749
+ firstLine = i + 1;
750
+ firstCol = match.index + 1;
751
+ firstContent = String(sourceLines[i] || '').trim();
752
+ contextLines = _hitContextLines(sourceLines, i);
753
+ }
754
+ if (declLine == null && nativeDeclSymbols.has(i + 1)) {
755
+ declLine = i + 1;
756
+ declCol = match.index + 1;
757
+ declContent = String(sourceLines[i] || '').trim();
758
+ declContext = _hitContextLines(sourceLines, i);
759
+ declSymbol = nativeDeclSymbols.get(i + 1);
471
760
  }
472
- if (localHit && nativeDeclSymbols.has(i + 1)) declarationLike = true;
473
761
  }
474
- if (firstLine == null) continue;
475
- const hasDeclPos = declLine != null;
476
- const declLineForEnd = hasDeclPos ? declLine : firstLine;
477
- const endLine = _nativeEndLineForDecl(node, cleanSymbol, declLineForEnd);
478
- hits.push({
479
- rel: node.rel,
480
- lang: node.lang,
481
- line: hasDeclPos ? declLine : firstLine,
482
- col: hasDeclPos ? declCol : firstCol || 1,
483
- ...(Number.isFinite(endLine) && endLine >= declLineForEnd ? { endLine } : {}),
484
- declarationLike,
485
- matchCount,
486
- content: hasDeclPos ? declContent : firstContent,
487
- context: hasDeclPos ? declContext : contextLines,
488
- firstLine,
489
- firstCol: firstCol || 1,
490
- firstContent,
491
- firstContext: contextLines,
492
- ..._symbolFacts(declSymbol),
493
- });
762
+ if (localHit && nativeDeclSymbols.has(i + 1)) declarationLike = true;
494
763
  }
495
- if (!hits.length) return [];
496
- return _sortSymbolHits(hits);
764
+ if (firstLine == null) return;
765
+ const hasDeclPos = declLine != null;
766
+ const declLineForEnd = hasDeclPos ? declLine : firstLine;
767
+ const endLine = _nativeEndLineForDecl(node, cleanSymbol, declLineForEnd);
768
+ hits.push({
769
+ rel: node.rel,
770
+ lang: node.lang,
771
+ line: hasDeclPos ? declLine : firstLine,
772
+ col: hasDeclPos ? declCol : firstCol || 1,
773
+ ...(Number.isFinite(endLine) && endLine >= declLineForEnd ? { endLine } : {}),
774
+ declarationLike,
775
+ matchCount,
776
+ content: hasDeclPos ? declContent : firstContent,
777
+ context: hasDeclPos ? declContext : contextLines,
778
+ firstLine,
779
+ firstCol: firstCol || 1,
780
+ firstContent,
781
+ firstContext: contextLines,
782
+ ..._symbolFacts(declSymbol),
783
+ });
497
784
  }
498
785
 
499
786
  function _pickCalleeDeclHit(hits, preferRel) {
@@ -504,8 +791,26 @@ function _pickCalleeDeclHit(hits, preferRel) {
504
791
  return sorted.find((h) => h.declarationLike) || sorted[0];
505
792
  }
506
793
 
794
+ // A callee row only uses a declaration-like hit, and only a node whose native
795
+ // record declares the name (symbols or topLevelTypes) can yield one. Scanning
796
+ // just those nodes picks the same hit (the comparator is a total order over
797
+ // hit fields) without reading and masking every file that merely mentions a
798
+ // common name like `push` — a multi-second main-thread stall per callees call.
507
799
  function _resolveCalleeDeclaration(graph, name, { language = null, preferRel = null } = {}) {
508
- return _pickCalleeDeclHit(_findSymbolHits(graph, name, { language }), preferRel);
800
+ const cleanName = String(name || '').trim();
801
+ if (!cleanName || cleanName.includes('/')) {
802
+ return _pickCalleeDeclHit(_findSymbolHits(graph, name, { language }), preferRel);
803
+ }
804
+ const declaring = _lookupCandidateNodes(graph, cleanName, language).filter((node) => _declaresName(node, cleanName));
805
+ const memo = _queryHitsMemo(graph)?.get(_symbolHitsKey('decl', cleanName, language));
806
+ return _pickCalleeDeclHit(memo || _findSymbolHitsOnNodes(graph, cleanName, declaring, { language }), preferRel);
807
+ }
808
+
809
+ function _declaresName(node, name) {
810
+ return (
811
+ (Array.isArray(node.topLevelTypes) && node.topLevelTypes.includes(name)) ||
812
+ (Array.isArray(node.symbols) && node.symbols.some((symbol) => symbol?.name === name))
813
+ );
509
814
  }
510
815
 
511
816
  // The record facts every symbol-mode row reports: the unified kind, the
@@ -545,7 +850,8 @@ function _nativeSymbolHit(node, sym) {
545
850
  };
546
851
  }
547
852
 
548
- function _collectNativeKeywordSymbolEntries(
853
+ // Time-sliced: it matches the keyword against every symbol of every file.
854
+ async function _collectNativeKeywordSymbolEntries(
549
855
  graph,
550
856
  keyword,
551
857
  { language = null, fileRel = null, scopeRelPrefix = null } = {}
@@ -554,7 +860,9 @@ function _collectNativeKeywordSymbolEntries(
554
860
  if (!lowerKey) return [];
555
861
  const keyTokens = _tokenizeKeyword(keyword);
556
862
  const byName = new Map();
863
+ const slice = _mainThreadSlice();
557
864
  for (const node of graph?.nodes?.values?.() || []) {
865
+ if (slice.expired()) await slice.yield();
558
866
  if (language && node.lang !== language) continue;
559
867
  if (!_nodeInAstScope(node, fileRel, scopeRelPrefix)) continue;
560
868
  const symbols = Array.isArray(node?.symbols) ? node.symbols : [];
@@ -781,7 +1089,7 @@ function _setKeywordSearchCache(graph, cacheKey, value) {
781
1089
  return value;
782
1090
  }
783
1091
 
784
- export function _searchSymbolsByKeyword(
1092
+ export async function _searchSymbolsByKeyword(
785
1093
  graph,
786
1094
  keyword,
787
1095
  cwd,
@@ -809,7 +1117,7 @@ export function _searchSymbolsByKeyword(
809
1117
  const _memo = (s) => _setKeywordSearchCache(graph, cacheKey, s);
810
1118
  // Native symbols are the only source: a node without them contributes no
811
1119
  // keyword match (it has no declarations the extractor could name).
812
- const entries = _collectNativeKeywordSymbolEntries(graph, clean, scope);
1120
+ const entries = await _collectNativeKeywordSymbolEntries(graph, clean, scope);
813
1121
  if (!entries.length) {
814
1122
  const nodeCount = graph?.nodes?.size ?? 0;
815
1123
  return _memo(