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.
- package/package.json +1 -2
- package/src/cli.mjs +5 -1
- package/src/defaults/shipped-history.json +26 -2
- package/src/defaults/skills/browser-use/SKILL.md +148 -273
- package/src/defaults/skills/browser-use/references/devtools.md +14 -0
- package/src/defaults/skills/browser-use/references/page-flows.md +66 -0
- package/src/defaults/skills/browser-use/references/sign-in.md +70 -0
- package/src/defaults/skills/code-tidy/SKILL.md +60 -84
- package/src/defaults/skills/code-tidy/references/agent-cleanup.md +27 -2
- package/src/defaults/skills/computer-use/SKILL.md +145 -240
- package/src/defaults/skills/computer-use/references/flows.md +35 -0
- package/src/defaults/skills/computer-use/references/operations.md +22 -0
- package/src/defaults/skills/computer-use/references/platforms.md +12 -0
- package/src/defaults/skills/docx/SKILL.md +23 -31
- package/src/defaults/skills/docx/references/native-authoring.md +26 -3
- package/src/defaults/skills/docx/references/redlining.md +15 -0
- package/src/defaults/skills/image/SKILL.md +37 -77
- package/src/defaults/skills/image/references/prompt-forms.md +51 -0
- package/src/defaults/skills/image/references/text.md +6 -0
- package/src/defaults/skills/local-provider/SKILL.md +75 -105
- package/src/defaults/skills/local-provider/references/lifecycle.md +14 -0
- package/src/defaults/skills/local-provider/references/maintenance.md +19 -0
- package/src/defaults/skills/local-provider/references/recovery.md +30 -0
- package/src/defaults/skills/memory-management/SKILL.md +16 -20
- package/src/defaults/skills/pdf/SKILL.md +21 -23
- package/src/defaults/skills/pdf/references/blocks.md +20 -0
- package/src/defaults/skills/pdf/references/forms.md +12 -0
- package/src/defaults/skills/pdf/references/html.md +2 -2
- package/src/defaults/skills/pdf/references/ocr.md +7 -0
- package/src/defaults/skills/pdf/references/security.md +8 -0
- package/src/defaults/skills/pptx/SKILL.md +30 -109
- package/src/defaults/skills/pptx/references/audit.md +45 -0
- package/src/defaults/skills/pptx/references/brief-critique.md +47 -0
- package/src/defaults/skills/pptx/references/editing.md +24 -0
- package/src/defaults/skills/pptx/references/html.md +1 -1
- package/src/defaults/skills/pptx/references/script.md +33 -0
- package/src/defaults/skills/setup/SKILL.md +34 -102
- package/src/defaults/skills/setup/references/actions.md +72 -13
- package/src/defaults/skills/setup/references/surfaces.md +23 -8
- package/src/defaults/skills/setup-guide/SKILL.md +28 -115
- package/src/defaults/skills/setup-guide/references/features.md +36 -0
- package/src/defaults/skills/setup-guide/references/glossary.md +38 -0
- package/src/defaults/skills/setup-guide/references/workflow-models.md +62 -0
- package/src/defaults/skills/test-suite/SKILL.md +15 -127
- package/src/defaults/skills/test-suite/references/case-management.md +17 -9
- package/src/defaults/skills/test-suite/references/diagnose.md +23 -0
- package/src/defaults/skills/test-suite/references/prune.md +27 -0
- package/src/defaults/skills/test-suite/references/write.md +44 -0
- package/src/defaults/skills/video/SKILL.md +28 -42
- package/src/defaults/skills/video/references/prompting.md +31 -0
- package/src/defaults/skills/visualize/SKILL.md +73 -107
- package/src/defaults/skills/visualize/references/craft.md +1 -2
- package/src/defaults/skills/visualize/references/feedback.md +36 -0
- package/src/defaults/skills/visualize/references/showing.md +13 -0
- package/src/defaults/skills/xlsx/SKILL.md +23 -50
- package/src/defaults/skills/xlsx/references/editing.md +15 -0
- package/src/defaults/skills/xlsx/references/model-conventions.md +1 -1
- package/src/defaults/skills/xlsx/references/recalculation.md +37 -0
- package/src/defaults/skills/xlsx/references/report-design.md +18 -2
- package/src/lib/keychain-cjs.cjs +22 -1
- package/src/lib/rules-builder.cjs +1 -1
- package/src/rules/agent/AGENT.md +3 -0
- package/src/rules/lead/LEAD.md +3 -1
- package/src/runtime/agent/orchestrator/agent-runtime/cache-strategy.mjs +8 -30
- package/src/runtime/agent/orchestrator/agent-runtime/title-completion.mjs +5 -0
- package/src/runtime/agent/orchestrator/mcp/oauth-request.mjs +21 -2
- package/src/runtime/agent/orchestrator/providers/account-pool.mjs +3 -0
- package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +2 -2
- package/src/runtime/agent/orchestrator/providers/anthropic-api-transport.mjs +2 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-message-threads.mjs +583 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth-client-version.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +81 -19
- package/src/runtime/agent/orchestrator/providers/anthropic-sse.mjs +180 -13
- package/src/runtime/agent/orchestrator/providers/anthropic.mjs +56 -6
- package/src/runtime/agent/orchestrator/providers/cursor-wire.mjs +4 -2
- package/src/runtime/agent/orchestrator/providers/gemini-error-contract.mjs +6 -6
- package/src/runtime/agent/orchestrator/providers/gemini-model-redirect.mjs +44 -0
- package/src/runtime/agent/orchestrator/providers/gemini-reasoning-relay.mjs +5 -0
- package/src/runtime/agent/orchestrator/providers/gemini-request-body.mjs +34 -5
- package/src/runtime/agent/orchestrator/providers/gemini-response.mjs +10 -0
- package/src/runtime/agent/orchestrator/providers/gemini-schema.mjs +11 -6
- package/src/runtime/agent/orchestrator/providers/gemini-sdk-request.mjs +4 -100
- package/src/runtime/agent/orchestrator/providers/gemini-stream.mjs +3 -227
- package/src/runtime/agent/orchestrator/providers/gemini.mjs +226 -118
- package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +11 -1
- package/src/runtime/agent/orchestrator/providers/lib/claude-bridge-schema.mjs +15 -3
- package/src/runtime/agent/orchestrator/providers/lib/gemini-model-catalog.mjs +2 -1
- package/src/runtime/agent/orchestrator/providers/openai-direct-request.mjs +5 -28
- package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +50 -28
- package/src/runtime/agent/orchestrator/providers/openai-ws-stream/socket-handlers.mjs +14 -10
- package/src/runtime/agent/orchestrator/providers/openai-ws.mjs +1 -3
- package/src/runtime/agent/orchestrator/providers/stream-json-pool/worker-slots/slot-spawn.mjs +8 -3
- package/src/runtime/agent/orchestrator/providers/vertex-ai-maas.mjs +2 -2
- package/src/runtime/agent/orchestrator/runtime-core/config-helpers.mjs +4 -5
- package/src/runtime/agent/orchestrator/runtime-core/goal-tool-defs.mjs +2 -2
- package/src/runtime/agent/orchestrator/runtime-core/provider-request-tools.mjs +15 -8
- package/src/runtime/agent/orchestrator/runtime-core/session-title.mjs +1 -0
- package/src/runtime/agent/orchestrator/runtime-core/todo-list.mjs +9 -32
- package/src/runtime/agent/orchestrator/runtime-core/todo-tool-defs.mjs +4 -5
- package/src/runtime/agent/orchestrator/session/compact/summary-route.mjs +1 -3
- package/src/runtime/agent/orchestrator/session/loop/compact-policy.mjs +5 -2
- package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/todo-check.mjs +2 -17
- package/src/runtime/agent/orchestrator/session/loop/usage.mjs +7 -3
- package/src/runtime/agent/orchestrator/session/manager/ask-turn-settle.mjs +9 -2
- package/src/runtime/agent/orchestrator/session/manager/session-close.mjs +26 -13
- package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +4 -5
- package/src/runtime/agent/orchestrator/session/manager/usage-metrics.mjs +16 -5
- package/src/runtime/agent/orchestrator/session/store/lifecycle-barriers.mjs +22 -1
- package/src/runtime/agent/orchestrator/session/store/live-state.mjs +4 -0
- package/src/runtime/agent/orchestrator/tools/builtin/cache-layers.mjs +11 -9
- package/src/runtime/agent/orchestrator/tools/builtin/grep-formatting.mjs +2 -8
- package/src/runtime/agent/orchestrator/tools/builtin/lib/search-input-helpers.mjs +1 -9
- package/src/runtime/agent/orchestrator/tools/builtin/local-search-telemetry.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/builtin/native-search-client.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/runtime-capabilities.mjs +12 -3
- package/src/runtime/agent/orchestrator/tools/code-graph/ast-calls.mjs +9 -2
- package/src/runtime/agent/orchestrator/tools/code-graph/build.mjs +137 -7
- package/src/runtime/agent/orchestrator/tools/code-graph/calls-cache.mjs +43 -14
- package/src/runtime/agent/orchestrator/tools/code-graph/calls-sidecar-worker.mjs +33 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/disk-cache.mjs +146 -11
- package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +31 -24
- package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary/spawn-jsonl.mjs +172 -25
- package/src/runtime/agent/orchestrator/tools/code-graph/graph-model.mjs +100 -2
- package/src/runtime/agent/orchestrator/tools/code-graph/main-thread-slice.mjs +18 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/mask-pool.mjs +219 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/mask-worker.mjs +12 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/memory-cache.mjs +6 -1
- package/src/runtime/agent/orchestrator/tools/code-graph/modes/calls.mjs +9 -2
- package/src/runtime/agent/orchestrator/tools/code-graph/modes/dependents.mjs +5 -1
- package/src/runtime/agent/orchestrator/tools/code-graph/modes/structure.mjs +8 -2
- package/src/runtime/agent/orchestrator/tools/code-graph/modes/symbols.mjs +14 -11
- package/src/runtime/agent/orchestrator/tools/code-graph/search-references.mjs +41 -18
- package/src/runtime/agent/orchestrator/tools/code-graph/search.mjs +391 -83
- package/src/runtime/agent/orchestrator/tools/code-graph/symbol-index.mjs +109 -9
- package/src/runtime/agent/orchestrator/tools/code-graph/text-mask.mjs +73 -29
- package/src/runtime/agent/orchestrator/tools/code-graph-prewarm-worker.mjs +6 -5
- package/src/runtime/agent/orchestrator/tools/lib/native-spawn-client.mjs +7 -3
- package/src/runtime/channels/lib/crash-log.mjs +21 -1
- package/src/runtime/channels/lib/worker-main.mjs +8 -25
- package/src/runtime/media/jobs.mjs +5 -0
- package/src/runtime/media/store.mjs +146 -3
- package/src/runtime/office/core/office-write-ledger.mjs +2 -2
- package/src/runtime/shared/agent-reap-state.mjs +19 -0
- package/src/runtime/shared/desktop-notice-host.d.mts +13 -0
- package/src/runtime/shared/desktop-notice-host.mjs +87 -0
- package/src/runtime/shared/file-lock.mjs +2 -2
- package/src/runtime/shared/heap-cap.mjs +9 -11
- package/src/runtime/shared/llm/http-agent.mjs +11 -1
- package/src/runtime/shared/llm/system-proxy.mjs +100 -25
- package/src/runtime/shared/llm/usage-accounting.mjs +18 -7
- package/src/runtime/shared/llm/usage-context.mjs +2 -2
- package/src/runtime/shared/llm/usage-ledger-requests.mjs +10 -3
- package/src/runtime/shared/llm/usage-ledger.mjs +13 -1
- package/src/runtime/shared/provider-accounts.mjs +22 -0
- package/src/runtime/shared/provider-auth-binding.mjs +2 -2
- package/src/runtime/shared/resource-admission.mjs +2 -2
- package/src/runtime/shared/root-async-context.mjs +51 -0
- package/src/runtime/shared/run-child.mjs +18 -1
- package/src/runtime/shared/slow-span.mjs +2 -2
- package/src/runtime/shared/tool-execution-owner.mjs +2 -2
- package/src/runtime/shared/tool-work-units.mjs +2 -0
- package/src/runtime/shared/turn-snapshot-store.mjs +75 -18
- package/src/runtime/shared/turn-worktree-snapshot.mjs +38 -8
- package/src/runtime/shared/user-cwd.mjs +2 -2
- package/src/runtime/shared/worker-requests.mjs +3 -1
- package/src/runtime/shared/worktrees/lock.mjs +2 -2
- package/src/runtime/visualize-bridge/client.mjs +26 -4
- package/src/runtime/visualize-bridge/tool-defs.mjs +46 -5
- package/src/session-runtime/boot/apis.mjs +1 -0
- package/src/session-runtime/boot/begin.mjs +2 -0
- package/src/session-runtime/media-api.mjs +15 -0
- package/src/session-runtime/provider-readiness.mjs +10 -2
- package/src/session-runtime/runtime-core.mjs +35 -8
- package/src/session-runtime/runtime-review-api.mjs +3 -1
- package/src/session-runtime/services/agent-tool/close-flow.mjs +6 -1
- package/src/session-runtime/services/agent-tool/execute-resume.mjs +94 -0
- package/src/session-runtime/services/agent-tool/execute-send.mjs +77 -27
- package/src/session-runtime/services/agent-tool/execute-spawn.mjs +28 -7
- package/src/session-runtime/services/agent-tool/execute.mjs +6 -1
- package/src/session-runtime/services/agent-tool/helpers.mjs +11 -0
- package/src/session-runtime/services/agent-tool/job-views/job-render.mjs +13 -10
- package/src/session-runtime/services/agent-tool/render.mjs +2 -0
- package/src/session-runtime/services/agent-tool/send-flow.mjs +1 -0
- package/src/session-runtime/services/agent-tool/spawn-flow/spawn-prep.mjs +6 -0
- package/src/session-runtime/services/agent-tool/spawn-flow/spawn-run.mjs +2 -1
- package/src/session-runtime/services/agent-tool/tag-registry/reaped-sessions.mjs +82 -0
- package/src/session-runtime/services/agent-tool/tag-registry/record-facts-worker.mjs +36 -0
- package/src/session-runtime/services/agent-tool/tag-registry.mjs +4 -0
- package/src/session-runtime/services/agent-tool/terminal-reaper/row-helpers.mjs +29 -0
- package/src/session-runtime/services/agent-tool/terminal-reaper/scan-admission.mjs +11 -3
- package/src/session-runtime/services/agent-tool/terminal-reaper/stale-rows.mjs +19 -8
- package/src/session-runtime/services/agent-tool/terminal-reaper.mjs +5 -2
- package/src/session-runtime/services/agent-tool/worker-index.mjs +1 -0
- package/src/session-runtime/services/daemon-crash-capture/daemon-exit-record.mjs +2 -2
- package/src/session-runtime/session-create.mjs +5 -0
- package/src/session-runtime/setup-tool/settings-contract.mjs +2 -0
- package/src/session-runtime/usage-stats-api.mjs +3 -0
- package/src/session-runtime/workspace/admission-gate.mjs +25 -7
- package/src/session-runtime/workspace/transitions.mjs +4 -0
- package/src/standalone/daemon-log.mjs +28 -4
- package/src/standalone/daemon-owner.mjs +41 -7
- package/src/standalone/daemon-work-gate.mjs +139 -0
- package/src/standalone/daemon.mjs +80 -11
- package/src/standalone/desktop-service-registry.mjs +11 -4
- package/src/standalone/session-client.mjs +57 -5
- package/src/standalone/session-protocol.mjs +5 -0
- package/src/standalone/session-service/agent-tree/agent-cancel.mjs +17 -1
- package/src/standalone/session-service/agent-tree.mjs +7 -0
- package/src/standalone/session-service/session-calls/session-turns.mjs +12 -5
- package/src/standalone/session-transport/call-route.mjs +10 -4
- package/src/standalone/session-transport/routes.mjs +21 -0
- package/src/standalone/session-transport/stack.mjs +3 -1
- package/src/standalone/session-transport.mjs +5 -0
- package/src/tui/dist/index.mjs +495 -477
- package/src/tui/session/session-api/media.mjs +5 -0
- package/src/tui/session/turn.mjs +13 -0
- package/src/runtime/agent/orchestrator/providers/gemini-sdk-stream/cancellation.mjs +0 -71
- package/src/runtime/agent/orchestrator/providers/gemini-sdk-stream/reader.mjs +0 -108
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { createHash } from 'node:crypto';
|
|
6
6
|
import { resolve as pathResolve } from 'node:path';
|
|
7
7
|
import { SYMBOL_SCHEMA_VERSION, CODE_GRAPH_MAX_FILES } from './constants.mjs';
|
|
8
|
+
import { _tokenIndexRetainedBytes } from './symbol-index.mjs';
|
|
8
9
|
|
|
9
10
|
export function _computeGraphSignature(fileMetas) {
|
|
10
11
|
const hash = createHash('sha1');
|
|
@@ -147,8 +148,105 @@ export function _attachGraphRuntimeCaches(graph) {
|
|
|
147
148
|
return graph;
|
|
148
149
|
}
|
|
149
150
|
|
|
151
|
+
const GRAPH_RUNTIME_CACHE_KEYS = new Set([
|
|
152
|
+
'_referenceSearchCache',
|
|
153
|
+
'_keywordSearchCache',
|
|
154
|
+
'_maskedLinesCache',
|
|
155
|
+
'_sourceLinesCache',
|
|
156
|
+
'_sourceTextCache',
|
|
157
|
+
'_symbolTokenIndex',
|
|
158
|
+
]);
|
|
159
|
+
// The base graph is immutable once built except for the one-time call-site
|
|
160
|
+
// hydration, so its walk is memoized per hydration state. The memory-cache
|
|
161
|
+
// prune runs after every code_graph call; re-walking a resident multi-hundred-MB
|
|
162
|
+
// graph each time cost 140-400 ms of main-thread time and millions of
|
|
163
|
+
// short-lived Object.entries arrays.
|
|
164
|
+
const _baseGraphBytes = new WeakMap();
|
|
165
|
+
|
|
166
|
+
/** Base (non-runtime-cache) size of a graph, memoized per hydration state. */
|
|
167
|
+
export function _estimateGraphBaseBytes(graph) {
|
|
168
|
+
let base = _baseGraphBytes.get(graph);
|
|
169
|
+
if (!base || base.hydration !== graph._callsHydration) {
|
|
170
|
+
const seen = new WeakSet();
|
|
171
|
+
let bytes = 48;
|
|
172
|
+
for (const [key, item] of Object.entries(graph)) {
|
|
173
|
+
if (!GRAPH_RUNTIME_CACHE_KEYS.has(key)) bytes += 8 + _estimateValueBytes(key) + _estimateValueBytes(item, seen);
|
|
174
|
+
}
|
|
175
|
+
base = { hydration: graph._callsHydration, bytes };
|
|
176
|
+
_baseGraphBytes.set(graph, base);
|
|
177
|
+
}
|
|
178
|
+
return base.bytes;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// A build Worker measures its graph before posting it; the structured clone
|
|
182
|
+
// has the same own keys and values, so the main thread adopts that number
|
|
183
|
+
// instead of re-walking a multi-hundred-MB graph on arrival.
|
|
184
|
+
export function _seedGraphBaseBytes(graph, bytes) {
|
|
185
|
+
if (!graph || typeof graph !== 'object' || !Number.isFinite(bytes)) return;
|
|
186
|
+
_baseGraphBytes.set(graph, { hydration: graph._callsHydration, bytes });
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Call-site hydration changes a graph whose base size is already known by
|
|
190
|
+
// `addedBytes` (applyCallsSidecarEntries: applied lists minus the lists they
|
|
191
|
+
// replaced) and by the marker flip itself, so the estimate moves to the
|
|
192
|
+
// hydrated state without re-walking every call tuple on the main thread (300+
|
|
193
|
+
// ms for a large root). `baseBytes` is the pre-hydration size the caller took
|
|
194
|
+
// before applying anything. Same rules as the walk, so the result equals it.
|
|
195
|
+
export function _noteGraphCallsHydrated(graph, baseBytes, addedBytes) {
|
|
196
|
+
const markerBytes = (present, value) =>
|
|
197
|
+
present ? 8 + _estimateValueBytes('_callsHydration') + _estimateValueBytes(value) : 0;
|
|
198
|
+
const before = markerBytes(Object.hasOwn(graph, '_callsHydration'), graph._callsHydration);
|
|
199
|
+
graph._callsHydration = 'done';
|
|
200
|
+
const bytes = baseBytes + addedBytes + markerBytes(true, 'done') - before;
|
|
201
|
+
_baseGraphBytes.set(graph, { hydration: 'done', bytes });
|
|
202
|
+
}
|
|
203
|
+
|
|
150
204
|
export function _estimateGraphRetainedBytes(graph) {
|
|
151
|
-
|
|
205
|
+
if (!graph || typeof graph !== 'object' || graph instanceof Map || Array.isArray(graph)) {
|
|
206
|
+
return _estimateValueBytes(graph);
|
|
207
|
+
}
|
|
208
|
+
let bytes = _estimateGraphBaseBytes(graph) + _tokenIndexRetainedBytes(graph);
|
|
209
|
+
for (const key of GRAPH_RUNTIME_CACHE_KEYS) {
|
|
210
|
+
if (Object.hasOwn(graph, key)) bytes += 8 + _estimateValueBytes(key) + _estimateRuntimeCacheBytes(graph[key]);
|
|
211
|
+
}
|
|
212
|
+
return bytes;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Runtime-cache entries are immutable once stored (a refresh stores a new
|
|
216
|
+
// object), so an entry measured where it was produced — in a time-sliced
|
|
217
|
+
// prewarm — is not re-walked by the prune after every call. That walk over the
|
|
218
|
+
// line arrays of thousands of files was a 50-90 ms main-thread stretch per call
|
|
219
|
+
// on a large root. Same rules as _estimateValueBytes, so the total is unchanged.
|
|
220
|
+
const _runtimeEntryBytes = new WeakMap();
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Measure a `{ fingerprint, lines }` entry (an array of strings) now rather
|
|
224
|
+
* than at the prune. The walk over the lines of a multi-MB file is its own
|
|
225
|
+
* 10 ms stretch (30+ ms on a slow CI runner), so it runs in `slice`d steps; the
|
|
226
|
+
* total is the one _estimateValueBytes gives: the entry with an empty array,
|
|
227
|
+
* plus a pointer and a string per line.
|
|
228
|
+
*/
|
|
229
|
+
export async function _noteRuntimeCacheEntryBytes(entry, slice) {
|
|
230
|
+
if (!entry || _runtimeEntryBytes.has(entry)) return;
|
|
231
|
+
const { lines } = entry;
|
|
232
|
+
let bytes = _estimateValueBytes({ ...entry, lines: [] }) + lines.length * 8;
|
|
233
|
+
for (let i = 0; i < lines.length; i++) {
|
|
234
|
+
bytes += 16 + lines[i].length * 2;
|
|
235
|
+
if ((i & 1023) === 1023 && slice.expired()) await slice.yield();
|
|
236
|
+
}
|
|
237
|
+
_runtimeEntryBytes.set(entry, bytes);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function _estimateRuntimeCacheBytes(cache) {
|
|
241
|
+
if (!(cache instanceof Map)) return _estimateValueBytes(cache);
|
|
242
|
+
let bytes = 48 + cache.size * 24;
|
|
243
|
+
for (const [key, value] of cache) {
|
|
244
|
+
bytes += _estimateValueBytes(key) + (_runtimeEntryBytes.get(value) ?? _estimateValueBytes(value));
|
|
245
|
+
}
|
|
246
|
+
return bytes;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function _estimateValueBytes(root, seen = new WeakSet()) {
|
|
152
250
|
const estimate = (value) => {
|
|
153
251
|
if (value == null) return 0;
|
|
154
252
|
const type = typeof value;
|
|
@@ -181,7 +279,7 @@ export function _estimateGraphRetainedBytes(graph) {
|
|
|
181
279
|
}
|
|
182
280
|
return bytes;
|
|
183
281
|
};
|
|
184
|
-
return estimate(
|
|
282
|
+
return estimate(root);
|
|
185
283
|
}
|
|
186
284
|
|
|
187
285
|
export function _clearGraphRuntimeCaches(graph) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Cooperative time slicing for graph-wide work that has to run on the daemon
|
|
2
|
+
// main thread: a loop checks `expired()` between items and awaits `yield()`
|
|
3
|
+
// once the budget is spent, so no single stretch holds the event loop longer
|
|
4
|
+
// than one budget plus one item.
|
|
5
|
+
import { performance } from 'node:perf_hooks';
|
|
6
|
+
|
|
7
|
+
export const MAIN_THREAD_SLICE_MS = 8;
|
|
8
|
+
|
|
9
|
+
export function _mainThreadSlice(budgetMs = MAIN_THREAD_SLICE_MS) {
|
|
10
|
+
let deadline = performance.now() + budgetMs;
|
|
11
|
+
return {
|
|
12
|
+
expired: () => performance.now() >= deadline,
|
|
13
|
+
async yield() {
|
|
14
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
15
|
+
deadline = performance.now() + budgetMs;
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// Off-main-thread comment/string masking. Masking every file that mentions a
|
|
2
|
+
// queried name was the largest share of a code_graph query's main-thread time
|
|
3
|
+
// (seconds for a common name on a large root), and it is a pure function of
|
|
4
|
+
// (text, lang), so it runs in a small worker pool.
|
|
5
|
+
//
|
|
6
|
+
// Every refusal or failure rejects, and the caller then masks that text on its
|
|
7
|
+
// own thread (in yielding slices, _prewarmMaskedSourceNodes):
|
|
8
|
+
// - outstanding work is bounded: queued + running texts may not exceed
|
|
9
|
+
// MAX_OUTSTANDING_CHARS (one request is always admitted when nothing is
|
|
10
|
+
// outstanding), so concurrent queries cannot grow the queue without bound;
|
|
11
|
+
// past it a request is refused, or (`waitForAdmission`) waits its turn;
|
|
12
|
+
// - an aborted caller's queued request is dropped;
|
|
13
|
+
// - each worker runs one request at a time under a deadline; a worker past it
|
|
14
|
+
// is terminated (a replacement spawns for the next request), as is one that
|
|
15
|
+
// crashed;
|
|
16
|
+
// - a worker is ref'd only while it runs a request, exits after an idle
|
|
17
|
+
// period, and every worker is terminated on process exit.
|
|
18
|
+
import { Worker } from 'node:worker_threads';
|
|
19
|
+
import { runInRootAsyncContext } from '../../../../shared/root-async-context.mjs';
|
|
20
|
+
|
|
21
|
+
const POOL_SIZE = 2;
|
|
22
|
+
const IDLE_EXIT_MS = 15_000;
|
|
23
|
+
const REQUEST_DEADLINE_MS = 30_000;
|
|
24
|
+
const MAX_OUTSTANDING_CHARS = 16 * 1024 * 1024;
|
|
25
|
+
const DEFAULT_CONFIG = {
|
|
26
|
+
createWorker: (url, options) => new Worker(url, options),
|
|
27
|
+
deadlineMs: REQUEST_DEADLINE_MS,
|
|
28
|
+
maxOutstandingChars: MAX_OUTSTANDING_CHARS,
|
|
29
|
+
};
|
|
30
|
+
let _config = DEFAULT_CONFIG;
|
|
31
|
+
const _slots = [];
|
|
32
|
+
const _queue = [];
|
|
33
|
+
// Requests waiting for admission (`waitForAdmission`); they hold no chars.
|
|
34
|
+
const _waiting = [];
|
|
35
|
+
let _outstandingChars = 0;
|
|
36
|
+
let _nextId = 0;
|
|
37
|
+
|
|
38
|
+
function _maskPoolError(message, code) {
|
|
39
|
+
const error = new Error(message);
|
|
40
|
+
error.code = code;
|
|
41
|
+
return error;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function _spawn() {
|
|
45
|
+
// execArgv: [] — inherited parent flags (e.g. --input-type) can stop a worker from starting.
|
|
46
|
+
// Root context: a shared worker first spawned inside one query must not pin
|
|
47
|
+
// that query's async stores (its hit memo) for the worker's whole life.
|
|
48
|
+
const worker = runInRootAsyncContext(() =>
|
|
49
|
+
_config.createWorker(new URL('./mask-worker.mjs', import.meta.url), {
|
|
50
|
+
execArgv: [],
|
|
51
|
+
stdout: true,
|
|
52
|
+
stderr: true,
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
const slot = { worker, request: null, idleTimer: null };
|
|
56
|
+
worker.on('message', ({ id, masked, error }) => {
|
|
57
|
+
const request = slot.request;
|
|
58
|
+
if (!request || request.id !== id) return;
|
|
59
|
+
clearTimeout(request.timer);
|
|
60
|
+
slot.request = null;
|
|
61
|
+
_release(request);
|
|
62
|
+
_settle(request, error ? new Error(error) : null, masked);
|
|
63
|
+
_idle(slot);
|
|
64
|
+
_dispatch();
|
|
65
|
+
});
|
|
66
|
+
worker.on('error', (error) => _retire(slot, error));
|
|
67
|
+
worker.on('exit', () => _retire(slot, _maskPoolError('mask worker exited', 'ERR_MASK_WORKER_EXITED')));
|
|
68
|
+
worker.unref();
|
|
69
|
+
_slots.push(slot);
|
|
70
|
+
return slot;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Drop a worker (crashed, exited, stalled or shut down) and fail its request.
|
|
74
|
+
function _retire(slot, error) {
|
|
75
|
+
const index = _slots.indexOf(slot);
|
|
76
|
+
if (index < 0) return;
|
|
77
|
+
_slots.splice(index, 1);
|
|
78
|
+
clearTimeout(slot.idleTimer);
|
|
79
|
+
void slot.worker.terminate();
|
|
80
|
+
const request = slot.request;
|
|
81
|
+
slot.request = null;
|
|
82
|
+
if (request) {
|
|
83
|
+
clearTimeout(request.timer);
|
|
84
|
+
_release(request);
|
|
85
|
+
_settle(request, error);
|
|
86
|
+
}
|
|
87
|
+
_dispatch();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function _idle(slot) {
|
|
91
|
+
slot.worker.unref();
|
|
92
|
+
clearTimeout(slot.idleTimer);
|
|
93
|
+
slot.idleTimer = runInRootAsyncContext(() =>
|
|
94
|
+
setTimeout(() => {
|
|
95
|
+
if (!slot.request) _retire(slot, null);
|
|
96
|
+
}, IDLE_EXIT_MS)
|
|
97
|
+
);
|
|
98
|
+
slot.idleTimer.unref?.();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function _release(request) {
|
|
102
|
+
if (request.released) return;
|
|
103
|
+
request.released = true;
|
|
104
|
+
_outstandingChars -= request.chars;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function _settle(request, error, value) {
|
|
108
|
+
if (request.settled) return;
|
|
109
|
+
request.settled = true;
|
|
110
|
+
request.signal?.removeEventListener('abort', request.onAbort);
|
|
111
|
+
if (error) request.reject(error);
|
|
112
|
+
else request.resolve(value);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Admit waiting requests in arrival order while the outstanding bound allows.
|
|
116
|
+
function _admitWaiting() {
|
|
117
|
+
while (_waiting.length) {
|
|
118
|
+
const next = _waiting[0];
|
|
119
|
+
if (_outstandingChars > 0 && _outstandingChars + next.chars > _config.maxOutstandingChars) return;
|
|
120
|
+
_waiting.shift();
|
|
121
|
+
_outstandingChars += next.chars;
|
|
122
|
+
_queue.push(next);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function _dispatch() {
|
|
127
|
+
_admitWaiting();
|
|
128
|
+
while (_queue.length) {
|
|
129
|
+
let slot = _slots.find((candidate) => !candidate.request);
|
|
130
|
+
if (!slot && _slots.length < POOL_SIZE) {
|
|
131
|
+
try {
|
|
132
|
+
slot = _spawn();
|
|
133
|
+
} catch (error) {
|
|
134
|
+
// Construction failed: fail the head request (the caller falls back)
|
|
135
|
+
// rather than leave it queued with its chars and abort listener.
|
|
136
|
+
const failed = _queue.shift();
|
|
137
|
+
_release(failed);
|
|
138
|
+
_settle(failed, error);
|
|
139
|
+
// Its released charge may admit a waiter that nothing else would wake.
|
|
140
|
+
_admitWaiting();
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (!slot) return;
|
|
145
|
+
const request = _queue.shift();
|
|
146
|
+
slot.request = request;
|
|
147
|
+
clearTimeout(slot.idleTimer);
|
|
148
|
+
slot.worker.ref();
|
|
149
|
+
request.timer = runInRootAsyncContext(() =>
|
|
150
|
+
setTimeout(
|
|
151
|
+
() => _retire(slot, _maskPoolError(`mask worker exceeded ${_config.deadlineMs}ms`, 'ERR_MASK_WORKER_DEADLINE')),
|
|
152
|
+
_config.deadlineMs
|
|
153
|
+
)
|
|
154
|
+
);
|
|
155
|
+
request.timer.unref?.();
|
|
156
|
+
slot.worker.postMessage({ id: request.id, texts: request.texts, langs: request.langs });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Mask `texts[i]` as language `langs[i]` in a worker; resolves to the masked
|
|
162
|
+
* strings, or rejects (saturated, aborted, deadline, crash) and the caller
|
|
163
|
+
* masks on its own path. `waitForAdmission` turns a saturated refusal into
|
|
164
|
+
* backpressure: the request waits (holding no outstanding chars, honouring
|
|
165
|
+
* `signal`) until the bound admits it, in arrival order; while any request
|
|
166
|
+
* waits, a non-waiting one is refused rather than overtaking it.
|
|
167
|
+
*/
|
|
168
|
+
export function _maskTextsOffThread(texts, langs, { signal = null, waitForAdmission = false } = {}) {
|
|
169
|
+
if (signal?.aborted) return Promise.reject(_maskPoolError('aborted', 'ABORT_ERR'));
|
|
170
|
+
const chars = texts.reduce((sum, text) => sum + text.length, 0);
|
|
171
|
+
const admissible =
|
|
172
|
+
_waiting.length === 0 && (_outstandingChars === 0 || _outstandingChars + chars <= _config.maxOutstandingChars);
|
|
173
|
+
if (!admissible && !waitForAdmission) {
|
|
174
|
+
return Promise.reject(_maskPoolError('mask pool saturated', 'ERR_MASK_POOL_SATURATED'));
|
|
175
|
+
}
|
|
176
|
+
return new Promise((resolve, reject) => {
|
|
177
|
+
const request = { id: ++_nextId, texts, langs, chars, signal, resolve, reject, timer: null };
|
|
178
|
+
request.onAbort = () => {
|
|
179
|
+
const waiting = _waiting.indexOf(request);
|
|
180
|
+
if (waiting >= 0) _waiting.splice(waiting, 1);
|
|
181
|
+
const queued = _queue.indexOf(request);
|
|
182
|
+
if (queued >= 0) {
|
|
183
|
+
_queue.splice(queued, 1);
|
|
184
|
+
_release(request);
|
|
185
|
+
}
|
|
186
|
+
// A running request keeps its worker (and its chars) until the worker
|
|
187
|
+
// answers; only the caller stops waiting.
|
|
188
|
+
_settle(request, _maskPoolError('aborted', 'ABORT_ERR'));
|
|
189
|
+
_dispatch();
|
|
190
|
+
};
|
|
191
|
+
signal?.addEventListener('abort', request.onAbort, { once: true });
|
|
192
|
+
_waiting.push(request);
|
|
193
|
+
_dispatch();
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Reject everything outstanding and terminate every worker. */
|
|
198
|
+
export function _shutdownMaskPool() {
|
|
199
|
+
const error = _maskPoolError('mask pool shut down', 'ERR_MASK_POOL_SHUTDOWN');
|
|
200
|
+
for (const request of _waiting.splice(0)) _settle(request, error);
|
|
201
|
+
for (const request of _queue.splice(0)) {
|
|
202
|
+
_release(request);
|
|
203
|
+
_settle(request, error);
|
|
204
|
+
}
|
|
205
|
+
for (const slot of [..._slots]) _retire(slot, error);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Test seam: override `{ createWorker, deadlineMs, maxOutstandingChars }`; no argument restores the defaults. */
|
|
209
|
+
export function _configureMaskPoolForTest(overrides = null) {
|
|
210
|
+
_shutdownMaskPool();
|
|
211
|
+
_config = overrides ? { ...DEFAULT_CONFIG, ...overrides } : DEFAULT_CONFIG;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Chars queued or running — the quantity the outstanding-work bound applies to. */
|
|
215
|
+
export function _maskPoolOutstandingChars() {
|
|
216
|
+
return _outstandingChars;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
process.once('exit', _shutdownMaskPool);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Worker side of mask-pool.mjs: masks batches of source texts off the daemon
|
|
2
|
+
// main thread with the same _maskNonCodeText the synchronous path runs.
|
|
3
|
+
import { parentPort } from 'node:worker_threads';
|
|
4
|
+
import { _maskNonCodeText } from './text-mask.mjs';
|
|
5
|
+
|
|
6
|
+
parentPort?.on('message', ({ id, texts, langs }) => {
|
|
7
|
+
try {
|
|
8
|
+
parentPort.postMessage({ id, masked: texts.map((text, i) => _maskNonCodeText(text, langs[i])) });
|
|
9
|
+
} catch (error) {
|
|
10
|
+
parentPort.postMessage({ id, error: String(error?.message || error) });
|
|
11
|
+
}
|
|
12
|
+
});
|
|
@@ -49,9 +49,14 @@ export function _pruneCodeGraphMemoryCache(options = {}) {
|
|
|
49
49
|
totalRetainedBytes -= freed;
|
|
50
50
|
if (freed > 0) evicted.push({ cwd: row.cwd, reason: 'max-bytes-runtime', freed });
|
|
51
51
|
}
|
|
52
|
+
// The most recently used graph is never evicted for bytes: it is the root
|
|
53
|
+
// being worked in, and a graph larger than the whole budget was otherwise
|
|
54
|
+
// dropped right after every query, so each next query re-ran the build
|
|
55
|
+
// Worker and structured-cloned the full graph back onto the main thread.
|
|
56
|
+
const newestCwd = [..._codeGraphCache.keys()].at(-1);
|
|
52
57
|
for (const row of rows) {
|
|
53
58
|
if (totalRetainedBytes <= maxBytes) break;
|
|
54
|
-
if (!_codeGraphCache.has(row.cwd)) continue;
|
|
59
|
+
if (row.cwd === newestCwd || !_codeGraphCache.has(row.cwd)) continue;
|
|
55
60
|
_codeGraphCache.delete(row.cwd);
|
|
56
61
|
totalRetainedBytes -= row.retainedBytes;
|
|
57
62
|
evicted.push({ cwd: row.cwd, reason: 'max-bytes-graph', freed: row.retainedBytes });
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
_formatCalleeRow,
|
|
11
11
|
_resolveReferenceLanguageNode,
|
|
12
12
|
_prewarmSourceTextNodes,
|
|
13
|
+
_prewarmSymbolSources,
|
|
13
14
|
_prewarmReferenceSourceText,
|
|
14
15
|
_cheapReferenceSearch,
|
|
15
16
|
_formatReferenceDetails,
|
|
@@ -27,6 +28,7 @@ export async function callees(ctx) {
|
|
|
27
28
|
const symbol = requiredSymbol('callees', args);
|
|
28
29
|
const explicitLanguage = languageArg(args);
|
|
29
30
|
if (rel && !node) return fileNotFound('callees', ctx);
|
|
31
|
+
await _prewarmSymbolSources(graph, [symbol], explicitLanguage, { signal });
|
|
30
32
|
const allHits = _findSymbolHits(graph, symbol, { language: explicitLanguage });
|
|
31
33
|
const hits = rel ? allHits.filter((h) => h.rel === rel) : allHits;
|
|
32
34
|
const declHit = hits.find((h) => h.declarationLike) || hits[0];
|
|
@@ -38,10 +40,11 @@ export async function callees(ctx) {
|
|
|
38
40
|
// did not extract simply has no callees to report.
|
|
39
41
|
const declNode = graph.nodes.get(declHit.rel) || null;
|
|
40
42
|
await _prewarmSourceTextNodes(graph, [declNode].filter(Boolean), { signal });
|
|
41
|
-
const rows = _extractCallees(graph, declHit, cwd, {
|
|
43
|
+
const rows = await _extractCallees(graph, declHit, cwd, {
|
|
42
44
|
cap: 200,
|
|
43
45
|
callerSymbol: symbol,
|
|
44
46
|
language: explicitLanguage,
|
|
47
|
+
signal,
|
|
45
48
|
});
|
|
46
49
|
if (!rows.length) return `(no callees)`;
|
|
47
50
|
const out = ['# callees'];
|
|
@@ -57,6 +60,8 @@ async function scopedCallContext(mode, ctx) {
|
|
|
57
60
|
const explicitLanguage = languageArg(args);
|
|
58
61
|
const narrowedByCaller = Boolean(rel || scopeRelPrefix || explicitLanguage);
|
|
59
62
|
if (node) await _prewarmSourceTextNodes(graph, [node], { signal });
|
|
63
|
+
// Covers every narrower language the query may settle on below.
|
|
64
|
+
await _prewarmSymbolSources(graph, [symbol], explicitLanguage, { signal });
|
|
60
65
|
const resolved = _resolveReferenceLanguageNode(graph, symbol, rel, explicitLanguage);
|
|
61
66
|
if (rel && resolved.kind === 'file-not-found') return { error: fileNotFound(mode, ctx) };
|
|
62
67
|
if (rel && resolved.kind === 'symbol-not-present') {
|
|
@@ -64,6 +69,7 @@ async function scopedCallContext(mode, ctx) {
|
|
|
64
69
|
}
|
|
65
70
|
const resolvedNode = resolved.kind === 'ok' ? resolved.node : null;
|
|
66
71
|
const lang = explicitLanguage || (narrowedByCaller && resolvedNode ? resolvedNode.lang : null);
|
|
72
|
+
if (lang !== explicitLanguage) await _prewarmSymbolSources(graph, [symbol], lang, { signal });
|
|
67
73
|
return { symbol, lang, narrowedByCaller, userLimit: userLimitArg(args) };
|
|
68
74
|
}
|
|
69
75
|
|
|
@@ -135,13 +141,14 @@ export async function callers(ctx) {
|
|
|
135
141
|
page: args?.page,
|
|
136
142
|
fileRel: rel,
|
|
137
143
|
scopeRelPrefix,
|
|
144
|
+
signal,
|
|
138
145
|
...(userLimit ? { pageSize: userLimit } : {}),
|
|
139
146
|
});
|
|
140
147
|
}
|
|
141
148
|
// The DECLARING files anchor the caller rule (same file or an importer);
|
|
142
149
|
// a `file`/directory anchor scopes the scan AND narrows those
|
|
143
150
|
// declarations to the one the caller pointed at.
|
|
144
|
-
const callerResult = _formatCallerReferences(graph, symbol, {
|
|
151
|
+
const callerResult = await _formatCallerReferences(graph, symbol, {
|
|
145
152
|
...(userLimit ? { limit: userLimit } : {}),
|
|
146
153
|
targetRels: _astCallerTargetRels(graph, symbol, lang, { fileRel: rel, scopeRelPrefix }),
|
|
147
154
|
language: lang,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { isAbsolute, resolve as pathResolve } from 'node:path';
|
|
7
7
|
import { _graphRel } from '../source-access.mjs';
|
|
8
|
-
import { _findSymbolHits, _prewarmSourceTextNodes } from '../search.mjs';
|
|
8
|
+
import { _findSymbolHits, _prewarmSourceTextNodes, _prewarmSymbolSources } from '../search.mjs';
|
|
9
9
|
import { fileNotFound, GRAPH_LIST_CAP } from './shared.mjs';
|
|
10
10
|
|
|
11
11
|
const KNOWN_SRC_EXT =
|
|
@@ -74,6 +74,10 @@ function importLineRef(graph, dep, basename, stem) {
|
|
|
74
74
|
|
|
75
75
|
export async function dependents(ctx) {
|
|
76
76
|
const { args, cwd, signal, graph, rel, normFile } = ctx;
|
|
77
|
+
if (!rel && !normFile) {
|
|
78
|
+
const symbols = [...(Array.isArray(args?.symbols) ? args.symbols : []), args?.symbol].filter(Boolean);
|
|
79
|
+
await _prewarmSymbolSources(graph, symbols.map(String), null, { signal });
|
|
80
|
+
}
|
|
77
81
|
const anchor = rel || normFile ? { rel, norm: normFile, note: null } : inferAnchor(args, cwd, graph);
|
|
78
82
|
const depFileNode = anchor.rel ? graph.nodes.get(anchor.rel) : null;
|
|
79
83
|
if (!depFileNode) return fileNotFound('dependents', { normFile: anchor.norm, graph });
|
|
@@ -6,7 +6,13 @@
|
|
|
6
6
|
import { CODE_GRAPH_MAX_FILES } from '../constants.mjs';
|
|
7
7
|
import { _graphRel } from '../source-access.mjs';
|
|
8
8
|
import { _buildExplainerFileSummary } from '../symbol-index.mjs';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
_formatRelated,
|
|
11
|
+
_formatImpact,
|
|
12
|
+
_impactSourceNodes,
|
|
13
|
+
_prewarmSourceTextNodes,
|
|
14
|
+
_prewarmMaskedSourceNodes,
|
|
15
|
+
} from '../search.mjs';
|
|
10
16
|
import { fileNotFound, GRAPH_LIST_CAP } from './shared.mjs';
|
|
11
17
|
|
|
12
18
|
export async function overview(ctx) {
|
|
@@ -70,6 +76,6 @@ export async function impact(ctx) {
|
|
|
70
76
|
if (!node) return fileNotFound('impact', ctx);
|
|
71
77
|
const targetSymbol = String(args?.symbol || '').trim();
|
|
72
78
|
await _prewarmSourceTextNodes(graph, [node], { signal });
|
|
73
|
-
await
|
|
79
|
+
await _prewarmMaskedSourceNodes(graph, _impactSourceNodes(node, graph, targetSymbol), { signal });
|
|
74
80
|
return _formatImpact(node, graph, cwd, targetSymbol);
|
|
75
81
|
}
|
|
@@ -9,13 +9,14 @@ import { statSync } from 'node:fs';
|
|
|
9
9
|
import { _graphRel } from '../source-access.mjs';
|
|
10
10
|
import { _capGraphList, _symbolOutlineRows } from '../symbol-index.mjs';
|
|
11
11
|
import {
|
|
12
|
-
_findSymbolHits,
|
|
13
12
|
_findSymbolAcrossGraph,
|
|
14
13
|
_searchSymbolsByKeyword,
|
|
15
14
|
_declarationOutsideScope,
|
|
16
15
|
_isVendorPath,
|
|
17
|
-
|
|
16
|
+
_prewarmMaskedSourceNodes,
|
|
17
|
+
_prewarmSymbolSources,
|
|
18
18
|
} from '../search.mjs';
|
|
19
|
+
import { _nodeInAstScope } from '../ast-calls.mjs';
|
|
19
20
|
import { _buildExactFileGraph } from '../exact-file-graph.mjs';
|
|
20
21
|
import {
|
|
21
22
|
collectGraphSymbolList,
|
|
@@ -52,6 +53,11 @@ export async function resolveOutsideDeclaration(
|
|
|
52
53
|
symbol,
|
|
53
54
|
{ language = null, fileRel = null, scopeRelPrefix = null, signal = null } = {}
|
|
54
55
|
) {
|
|
56
|
+
// The scope's files are scanned line by line for an import of the symbol.
|
|
57
|
+
if (fileRel || scopeRelPrefix) {
|
|
58
|
+
const scoped = [...graph.nodes.values()].filter((node) => _nodeInAstScope(node, fileRel, scopeRelPrefix));
|
|
59
|
+
await _prewarmMaskedSourceNodes(graph, scoped, { masked: false, signal });
|
|
60
|
+
}
|
|
55
61
|
const outside = _declarationOutsideScope(graph, symbol, { language, fileRel, scopeRelPrefix });
|
|
56
62
|
if (!outside?.viaImport || !outside.abs) return outside;
|
|
57
63
|
if (!outlineLanguageForPath(outside.abs)) return outside;
|
|
@@ -80,14 +86,11 @@ export async function resolveOutsideDeclaration(
|
|
|
80
86
|
};
|
|
81
87
|
}
|
|
82
88
|
|
|
83
|
-
//
|
|
84
|
-
//
|
|
89
|
+
// Every file the declaration search reads and masks — the declaring file a
|
|
90
|
+
// `body:true` answer renders included — is read and masked ahead, so the
|
|
91
|
+
// synchronous search runs over cached text instead of a sync read per file.
|
|
85
92
|
export async function prewarmPrimaryDeclaration(graph, symbol, language, signal) {
|
|
86
|
-
|
|
87
|
-
const primary = hits.find((hit) => hit.declarationLike) || hits[0];
|
|
88
|
-
await _prewarmSourceTextNodes(graph, [primary?.rel ? graph.nodes.get(primary.rel) : null].filter(Boolean), {
|
|
89
|
-
signal,
|
|
90
|
-
});
|
|
93
|
+
await _prewarmSymbolSources(graph, [symbol], language, { signal });
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
export async function symbols(ctx) {
|
|
@@ -103,7 +106,7 @@ export async function findSymbol(ctx) {
|
|
|
103
106
|
const language = languageArg(args);
|
|
104
107
|
const limit = Math.max(1, Math.min(50, Number(args?.limit || 20)));
|
|
105
108
|
if (rel && !node) return fileNotFound('find_symbol', ctx);
|
|
106
|
-
|
|
109
|
+
await prewarmPrimaryDeclaration(graph, symbol, language, signal);
|
|
107
110
|
return _findSymbolAcrossGraph(graph, symbol, cwd, {
|
|
108
111
|
defaultCwd,
|
|
109
112
|
language,
|
|
@@ -141,7 +144,7 @@ export async function symbolSearch(ctx) {
|
|
|
141
144
|
const seen = new Set();
|
|
142
145
|
const sections = [];
|
|
143
146
|
for (const kw of keywords) {
|
|
144
|
-
const result = search(kw);
|
|
147
|
+
const result = await search(kw);
|
|
145
148
|
if (seen.has(result)) continue;
|
|
146
149
|
seen.add(result);
|
|
147
150
|
sections.push(`# symbol_search: ${kw}\n${result}`);
|