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.
- package/package.json +1 -2
- package/src/cli.mjs +5 -1
- package/src/defaults/shipped-history.json +30 -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 -229
- 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 +22 -21
- 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 +73 -14
- 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/agent-mode/MIXY.md +5 -3
- 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 +4 -3
- package/src/runtime/agent/orchestrator/providers/anthropic-api-request.mjs +11 -1
- 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-turn/turn-events/content-block-start.mjs +4 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-outcome.mjs +2 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-sse.mjs +180 -13
- package/src/runtime/agent/orchestrator/providers/anthropic-turn-result.mjs +2 -0
- package/src/runtime/agent/orchestrator/providers/anthropic.mjs +58 -6
- package/src/runtime/agent/orchestrator/providers/cursor-wire.mjs +4 -2
- package/src/runtime/agent/orchestrator/providers/custom-provider-config.mjs +121 -9
- package/src/runtime/agent/orchestrator/providers/custom-provider.mjs +4 -1
- 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/lib/generation-window.mjs +9 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-chat-send.mjs +9 -1
- package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/stream-result.mjs +2 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/stream-state.mjs +5 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-options.mjs +3 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-response-normalization.mjs +2 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-responses.mjs +10 -1
- package/src/runtime/agent/orchestrator/providers/openai-direct-request.mjs +5 -28
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-events.mjs +3 -0
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-outcome.mjs +2 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +50 -28
- package/src/runtime/agent/orchestrator/providers/openai-ws-response-state.mjs +9 -2
- 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/openrouter-provider-routing.mjs +28 -0
- package/src/runtime/agent/orchestrator/providers/openrouter.mjs +4 -1
- package/src/runtime/agent/orchestrator/providers/registry.mjs +30 -25
- 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/ask-user-result.mjs +66 -0
- 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/runtime-liveness.mjs +8 -1
- 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/session/store.mjs +12 -6
- 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/lib/shell-output-silence.mjs +64 -0
- package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-task-output.mjs +20 -6
- 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/builtin/task-tool.mjs +12 -1
- 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/routines-db.mjs +35 -0
- package/src/runtime/channels/lib/schedules-db.mjs +4 -0
- package/src/runtime/channels/lib/webhooks-db.mjs +4 -0
- package/src/runtime/channels/lib/worker-main.mjs +8 -25
- package/src/runtime/computer-bridge/action-schema.mjs +2 -2
- package/src/runtime/computer-bridge/core-actions.mjs +16 -2
- package/src/runtime/computer-bridge/result-canonical.mjs +6 -0
- package/src/runtime/media/jobs.mjs +5 -0
- package/src/runtime/media/store.mjs +146 -3
- package/src/runtime/memory/tool-defs.mjs +1 -1
- 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 +121 -19
- package/src/runtime/shared/llm/usage-context.mjs +3 -3
- package/src/runtime/shared/llm/usage-ledger-quota.mjs +2 -0
- package/src/runtime/shared/llm/usage-ledger-requests.mjs +190 -0
- package/src/runtime/shared/llm/usage-ledger-rollup.mjs +7 -3
- package/src/runtime/shared/llm/usage-ledger-worker.mjs +2 -0
- package/src/runtime/shared/llm/usage-ledger.mjs +69 -1
- package/src/runtime/shared/llm/usage-request-status.mjs +48 -0
- 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-result-summary.mjs +1 -1
- 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/agent-home-delivery.mjs +76 -8
- package/src/session-runtime/agent-task-sessions.mjs +63 -22
- package/src/session-runtime/boot/apis.mjs +16 -0
- package/src/session-runtime/boot/begin.mjs +2 -0
- package/src/session-runtime/boot/tools.mjs +8 -2
- package/src/session-runtime/internal-tool-executor/ask-user-tool.mjs +3 -58
- package/src/session-runtime/media-api.mjs +15 -0
- package/src/session-runtime/model-route/route-persist.mjs +12 -4
- package/src/session-runtime/provider-models/row-hydration.mjs +2 -0
- package/src/session-runtime/provider-readiness.mjs +10 -2
- package/src/session-runtime/routine-owner.mjs +9 -3
- 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-task-status.mjs +29 -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/job-views/session-progress.mjs +3 -0
- package/src/session-runtime/services/agent-tool/render.mjs +8 -1
- 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/channel-admin.mjs +44 -3
- package/src/session-runtime/services/daemon-crash-capture/daemon-exit-record.mjs +2 -2
- package/src/session-runtime/services/plugin-admin.mjs +46 -7
- package/src/session-runtime/services/provider-admin.mjs +5 -0
- package/src/session-runtime/session-create.mjs +5 -0
- package/src/session-runtime/setup-tool/agent-settings-actions.mjs +1 -1
- package/src/session-runtime/setup-tool/executor.mjs +1 -1
- package/src/session-runtime/setup-tool/extended-actions.mjs +1 -1
- package/src/session-runtime/setup-tool/settings-contract.mjs +4 -2
- package/src/session-runtime/usage-stats-api.mjs +120 -1
- package/src/session-runtime/workflow-agents-api/agent-connectors.mjs +36 -29
- package/src/session-runtime/workflow-agents-api/agent-editor.mjs +183 -23
- 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 +6 -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/retention/busy.mjs +3 -2
- 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/app/model-picker/model-footer.mjs +1 -1
- package/src/tui/app/model-picker/provider-models-list.mjs +7 -3
- package/src/tui/app/model-picker/route-selection/fast-parameters.mjs +23 -3
- package/src/tui/app/model-picker/route-selection.mjs +1 -0
- package/src/tui/dist/index.mjs +536 -484
- package/src/tui/session/session-api/integrations.mjs +3 -0
- package/src/tui/session/session-api/media.mjs +5 -0
- package/src/tui/session/tool-approval-settle.mjs +24 -4
- package/src/tui/session/tool-approval.mjs +35 -10
- 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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { contentCarriesLiveMedia } from '../../providers/media-normalization.mjs';
|
|
2
2
|
import { publishSessionPersistence } from './session-persistence-events.mjs';
|
|
3
|
+
import { raiseDesktopNotice } from '../../../../shared/desktop-notice-host.mjs';
|
|
3
4
|
|
|
4
5
|
const _lastSaveError = new Map(); // id -> { message, at }
|
|
5
6
|
|
|
@@ -243,6 +244,9 @@ function _failedSaveClone(session) {
|
|
|
243
244
|
*/
|
|
244
245
|
export function _recordSaveFailure(id, err, epoch = null, session = null) {
|
|
245
246
|
if (!id) return;
|
|
247
|
+
// The only notice of a transcript the disk no longer keeps up with; told
|
|
248
|
+
// once per run, whichever session it was.
|
|
249
|
+
raiseDesktopNotice('conversation-save', 'conversation-save-failed');
|
|
246
250
|
_lastSaveError.set(id, { message: err?.message ?? String(err), at: Date.now() });
|
|
247
251
|
_droppedSaveIds.add(id);
|
|
248
252
|
_markFailureEpoch(id, epoch);
|
|
@@ -515,8 +515,13 @@ function _collectNewestDrainPayloads() {
|
|
|
515
515
|
// (the ref was replaced behind the write). Map/source order must never
|
|
516
516
|
// decide that, and minting a newer epoch here would hand an old snapshot
|
|
517
517
|
// fresh write authority.
|
|
518
|
-
const record = (id, session, opts, epoch, revision) => {
|
|
518
|
+
const record = (id, session, opts, epoch, revision, incarnation) => {
|
|
519
519
|
if (!id || !session) return;
|
|
520
|
+
// A hard delete retired this payload's incarnation. The drain writes
|
|
521
|
+
// under a FRESH guard, so the delete's cancellation cannot stop it here:
|
|
522
|
+
// an in-flight worker write of a deleted id (its slot outlives the purge
|
|
523
|
+
// until the reply settles) would re-create the unlinked file.
|
|
524
|
+
if (!_isCurrentSessionIncarnation(id, incarnation)) return;
|
|
520
525
|
const issued = Number.isFinite(epoch) ? epoch : 0;
|
|
521
526
|
const rev = Number.isFinite(revision) ? revision : 0;
|
|
522
527
|
const current = newest.get(id);
|
|
@@ -526,14 +531,15 @@ function _collectNewestDrainPayloads() {
|
|
|
526
531
|
for (const [id, pending] of _savePending) {
|
|
527
532
|
// Both slots are candidates; the payload's own epoch decides, so a
|
|
528
533
|
// `queued` follow-up wins because it is NEWER, not because of its slot.
|
|
529
|
-
|
|
530
|
-
record(id,
|
|
534
|
+
const { payload, queued } = pending;
|
|
535
|
+
record(id, payload?.session, payload?.opts, payload?.epoch, 0, payload?.settlement ?? payload?.incarnation);
|
|
536
|
+
record(id, queued?.session, queued?.opts, queued?.epoch, 0, queued?.settlement ?? queued?.incarnation);
|
|
531
537
|
}
|
|
532
538
|
for (const [, pending] of _saveWorkerPending)
|
|
533
|
-
record(pending.id, pending.session, pending.opts, pending.epoch, pending.revision);
|
|
534
|
-
for (const [id, q] of _saveAsyncQueued) record(id, q.session, q.opts, q.epoch, q.revision);
|
|
539
|
+
record(pending.id, pending.session, pending.opts, pending.epoch, pending.revision, pending.incarnation);
|
|
540
|
+
for (const [id, q] of _saveAsyncQueued) record(id, q.session, q.opts, q.epoch, q.revision, q.incarnation);
|
|
535
541
|
for (const [, pending] of _deferredSessionSaves)
|
|
536
|
-
record(pending.session?.id, pending.session, pending.opts, pending.epoch, pending.revision);
|
|
542
|
+
record(pending.session?.id, pending.session, pending.opts, pending.epoch, pending.revision, pending.incarnation);
|
|
537
543
|
return newest;
|
|
538
544
|
}
|
|
539
545
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { statSync } from 'node:fs';
|
|
2
2
|
import * as fsPromises from 'node:fs/promises';
|
|
3
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
3
|
import { isAbsolute, sep } from 'node:path';
|
|
4
|
+
import { runtimeAsyncLocalStorage } from '../../../../shared/root-async-context.mjs';
|
|
5
5
|
import { canonicalCachePath, deleteReadRangeIndexForPath } from './read-range-index.mjs';
|
|
6
6
|
import { resolveAgainstCwd } from './path-utils.mjs';
|
|
7
7
|
import { fileVersion, sameFileVersion } from './file-version.mjs';
|
|
@@ -9,8 +9,8 @@ import { canCacheReadFile } from './read-cache-policy.mjs';
|
|
|
9
9
|
|
|
10
10
|
const RESULT_CACHE = new Map(); // key → { ts, value, paths, scopes, readSnapshotMeta, contentPrefixHash, bytes }
|
|
11
11
|
const RESULT_CACHE_INFLIGHT = new Map(); // key → { promise, controller, subscribers, settled }
|
|
12
|
-
const RESULT_CACHE_COMPUTE =
|
|
13
|
-
const READ_CACHE_PUBLICATION =
|
|
12
|
+
const RESULT_CACHE_COMPUTE = runtimeAsyncLocalStorage();
|
|
13
|
+
const READ_CACHE_PUBLICATION = runtimeAsyncLocalStorage();
|
|
14
14
|
// Only active reads retain a slot. Invalidating an inactive path creates
|
|
15
15
|
// no history, and the final reader releases its path in a finally block.
|
|
16
16
|
const ACTIVE_READ_CACHE_PATHS = new Map();
|
|
@@ -491,10 +491,10 @@ export function registerCacheInvalidationListener(fn) {
|
|
|
491
491
|
if (typeof fn === 'function') EXTRA_INVALIDATION_LISTENERS.add(fn);
|
|
492
492
|
return () => EXTRA_INVALIDATION_LISTENERS.delete(fn);
|
|
493
493
|
}
|
|
494
|
-
function runExtraInvalidationListeners(affectedPaths = null) {
|
|
494
|
+
function runExtraInvalidationListeners(affectedPaths = null, source = {}) {
|
|
495
495
|
for (const fn of EXTRA_INVALIDATION_LISTENERS) {
|
|
496
496
|
try {
|
|
497
|
-
fn(affectedPaths);
|
|
497
|
+
fn(affectedPaths, source);
|
|
498
498
|
} catch {
|
|
499
499
|
/* best-effort: one listener must not block others */
|
|
500
500
|
}
|
|
@@ -517,7 +517,7 @@ function cacheInvalidateAll() {
|
|
|
517
517
|
runExtraInvalidationListeners();
|
|
518
518
|
}
|
|
519
519
|
|
|
520
|
-
function cacheInvalidatePaths(paths) {
|
|
520
|
+
function cacheInvalidatePaths(paths, source) {
|
|
521
521
|
const affectedPaths = normalizeCacheMetaPaths(Array.isArray(paths) ? paths : [paths]);
|
|
522
522
|
if (affectedPaths.length === 0) {
|
|
523
523
|
cacheInvalidateAll();
|
|
@@ -559,12 +559,14 @@ function cacheInvalidatePaths(paths) {
|
|
|
559
559
|
for (const affected of affectedPaths) {
|
|
560
560
|
deleteReadRangeIndexForPath(affected);
|
|
561
561
|
}
|
|
562
|
-
runExtraInvalidationListeners(affectedPaths);
|
|
562
|
+
runExtraInvalidationListeners(affectedPaths, source);
|
|
563
563
|
}
|
|
564
564
|
|
|
565
|
-
|
|
565
|
+
/** `source.canonical`: the paths come from a link-free watch on canonical
|
|
566
|
+
* roots, so listeners may match them by spelling alone. */
|
|
567
|
+
export function invalidateBuiltinResultCache(paths = null, source = {}) {
|
|
566
568
|
if (Array.isArray(paths) ? paths.length > 0 : Boolean(paths)) {
|
|
567
|
-
cacheInvalidatePaths(paths);
|
|
569
|
+
cacheInvalidatePaths(paths, source);
|
|
568
570
|
return;
|
|
569
571
|
}
|
|
570
572
|
cacheInvalidateAll();
|
|
@@ -13,7 +13,7 @@ export function splitGrepLinePrefix(line, matchOnly = false) {
|
|
|
13
13
|
const text = String(line || '');
|
|
14
14
|
if (!text) return null;
|
|
15
15
|
const searchFrom = /^[A-Za-z]:/.test(text) ? 2 : 0;
|
|
16
|
-
//
|
|
16
|
+
// Content mode — rg emits, after any optional drive-letter prefix:
|
|
17
17
|
// match: path:lineNo:content (output_mode content default)
|
|
18
18
|
// context: path-lineNo-content (-A / -B / -C context lines)
|
|
19
19
|
// Caller context decides whether line-number-only output is possible. A
|
|
@@ -87,16 +87,10 @@ export function normalizeGrepLine(
|
|
|
87
87
|
// There is no path prefix to normalise; everything after ^\d+[:\-] is
|
|
88
88
|
// source content and must remain byte-exact.
|
|
89
89
|
if (filenameOmitted && splitGrepLineNumberOnlyPrefix(line)) return line;
|
|
90
|
-
const split = splitGrepLinePrefix(line, matchOnly);
|
|
90
|
+
const split = outputMode === 'count' ? splitGrepCountPrefix(line) : splitGrepLinePrefix(line, matchOnly);
|
|
91
91
|
if (split) {
|
|
92
92
|
return line.slice(0, split.pathEnd).replace(/\\/g, '/') + line.slice(split.pathEnd);
|
|
93
93
|
}
|
|
94
|
-
if (outputMode === 'count') {
|
|
95
|
-
const countSplit = splitGrepCountPrefix(line);
|
|
96
|
-
if (countSplit) {
|
|
97
|
-
return line.slice(0, countSplit.pathEnd).replace(/\\/g, '/') + line.slice(countSplit.pathEnd);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
94
|
// No confirmed path prefix. Do not fall back to "first colon" slicing:
|
|
101
95
|
// single-file context lines are `N-content`, so their first colon may be a
|
|
102
96
|
// ternary/object literal inside CONTENT. Replacing `\` before that colon
|
|
@@ -15,18 +15,10 @@ export function relativeGrepLine(
|
|
|
15
15
|
if (!workDir) return normalized;
|
|
16
16
|
if (pathOnly) return relativePathPrefix(normalized, workDir);
|
|
17
17
|
if (filenameOmitted) return normalized;
|
|
18
|
-
const split = splitGrepLinePrefix(normalized, matchOnly);
|
|
18
|
+
const split = outputMode === 'count' ? splitGrepCountPrefix(normalized) : splitGrepLinePrefix(normalized, matchOnly);
|
|
19
19
|
if (split) {
|
|
20
20
|
return relativePathPrefix(normalized.slice(0, split.pathEnd), workDir) + normalized.slice(split.pathEnd);
|
|
21
21
|
}
|
|
22
|
-
if (outputMode === 'count') {
|
|
23
|
-
const countSplit = splitGrepCountPrefix(normalized);
|
|
24
|
-
if (countSplit) {
|
|
25
|
-
return (
|
|
26
|
-
relativePathPrefix(normalized.slice(0, countSplit.pathEnd), workDir) + normalized.slice(countSplit.pathEnd)
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
22
|
return normalized;
|
|
31
23
|
}
|
|
32
24
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// How long a running shell job has gone without writing to stdout or stderr.
|
|
2
|
+
// Silence is read from the capture files' mtime (the writer is the child, so
|
|
3
|
+
// nothing has to poll), floored at the job's start. It is a warning only:
|
|
4
|
+
// builds and installs can be legitimately quiet, so nothing is ever killed
|
|
5
|
+
// from here, and any output at all resets the clock.
|
|
6
|
+
import { statSync } from 'node:fs';
|
|
7
|
+
import { formatDuration } from '../../../../../shared/time-format.mjs';
|
|
8
|
+
import { getBackgroundTask } from '../../../../../shared/background-tasks.mjs';
|
|
9
|
+
import { STALL_ABORT_S, resolveTimeoutMs } from '../../../stall-policy.mjs';
|
|
10
|
+
|
|
11
|
+
// Defaults to the agent stall budget (600 s): a quiet job past the point where
|
|
12
|
+
// a silent model turn would be reaped is worth a look.
|
|
13
|
+
export const SHELL_OUTPUT_SILENCE_WARN_MS = resolveTimeoutMs(
|
|
14
|
+
'MIXDOG_SHELL_OUTPUT_SILENCE_WARN_MS',
|
|
15
|
+
STALL_ABORT_S * 1000
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
/** Milliseconds since the job last wrote to stdout/stderr (or started), or null
|
|
19
|
+
* when silence is unknown. The spawner creates both capture files before the
|
|
20
|
+
* command runs (mixdog-spawn open_capture_files, or the paired spill open), so
|
|
21
|
+
* a stream whose file cannot be stat'd (even ENOENT) is unknown, not quiet:
|
|
22
|
+
* its recent output could be what we cannot see. `task` is the background
|
|
23
|
+
* task; the stream paths come from `result` or the task meta. */
|
|
24
|
+
export function shellOutputSilenceMs(task, { now = Date.now(), result = task?.result } = {}) {
|
|
25
|
+
let last = null;
|
|
26
|
+
for (const path of [result?.stdout_path || task?.meta?.stdout, result?.stderr_path || task?.meta?.stderr]) {
|
|
27
|
+
if (!path) continue;
|
|
28
|
+
try {
|
|
29
|
+
last = Math.max(last ?? 0, statSync(path).mtimeMs);
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (last == null) return null;
|
|
35
|
+
return Math.max(0, now - Math.max(last, Number(task?.startedAtMs) || 0));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The warning text for a silence at or past the threshold, else null. */
|
|
39
|
+
export function describeShellOutputSilence(silentMs, warnMs = SHELL_OUTPUT_SILENCE_WARN_MS) {
|
|
40
|
+
if (!(silentMs >= warnMs)) return null;
|
|
41
|
+
return `no output for ${formatDuration(silentMs, { mostSignificantOnly: true })} — may be hung; inspect or cancel`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const isRunningShell = (task) => task?.surface === 'shell' && task.status === 'running';
|
|
45
|
+
|
|
46
|
+
/** The warning for one running shell task, else null. */
|
|
47
|
+
export function shellTaskSilenceNote(task, { now = Date.now(), warnMs = SHELL_OUTPUT_SILENCE_WARN_MS, result } = {}) {
|
|
48
|
+
if (!isRunningShell(task)) return null;
|
|
49
|
+
return describeShellOutputSilence(shellOutputSilenceMs(task, { now, result: result ?? task.result }), warnMs);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The quietest of the running shell jobs an agent's `task wait` is parked on:
|
|
53
|
+
* `{ taskId, silentMs, hung }`, or null when it waits on none. */
|
|
54
|
+
export function waitedJobSilence(taskIds, { now = Date.now(), warnMs = SHELL_OUTPUT_SILENCE_WARN_MS } = {}) {
|
|
55
|
+
let worst = null;
|
|
56
|
+
for (const taskId of taskIds || []) {
|
|
57
|
+
const task = getBackgroundTask(taskId);
|
|
58
|
+
if (!isRunningShell(task)) continue;
|
|
59
|
+
const silentMs = shellOutputSilenceMs(task, { now });
|
|
60
|
+
if (silentMs != null && (!worst || silentMs > worst.silentMs))
|
|
61
|
+
worst = { taskId, silentMs, hung: silentMs >= warnMs };
|
|
62
|
+
}
|
|
63
|
+
return worst;
|
|
64
|
+
}
|
|
@@ -20,6 +20,11 @@ import {
|
|
|
20
20
|
prepareShellText,
|
|
21
21
|
textPiece,
|
|
22
22
|
} from './shell-delivery.mjs';
|
|
23
|
+
import {
|
|
24
|
+
SHELL_OUTPUT_SILENCE_WARN_MS,
|
|
25
|
+
describeShellOutputSilence,
|
|
26
|
+
shellOutputSilenceMs,
|
|
27
|
+
} from './shell-output-silence.mjs';
|
|
23
28
|
|
|
24
29
|
const cursors = new WeakMap();
|
|
25
30
|
const ESC = '\x1b';
|
|
@@ -121,16 +126,16 @@ function lastMatch(pattern, text) {
|
|
|
121
126
|
|
|
122
127
|
/** What changed since the agent last saw the job: growth, last line, any
|
|
123
128
|
* visible percent/ETA. Used where a still-running job is reported. */
|
|
124
|
-
function progressDigest(growth) {
|
|
129
|
+
function progressDigest(growth, hung) {
|
|
125
130
|
const bytes = growth.reduce((sum, entry) => sum + entry.bytes, 0);
|
|
126
131
|
const lines = growth.reduce((sum, entry) => sum + entry.lines, 0);
|
|
127
132
|
const text = growth
|
|
128
133
|
.map((entry) => entry.text)
|
|
129
134
|
.filter(Boolean)
|
|
130
135
|
.join('\n');
|
|
131
|
-
const parts = [
|
|
132
|
-
|
|
133
|
-
|
|
136
|
+
const parts = [];
|
|
137
|
+
if (bytes > 0) parts.push(`+${formatKb(bytes)}, +${lines} lines since you last saw it`);
|
|
138
|
+
else if (!hung) parts.push('no new output since you last saw it');
|
|
134
139
|
const last = text
|
|
135
140
|
.split('\n')
|
|
136
141
|
.reverse()
|
|
@@ -140,6 +145,8 @@ function progressDigest(growth) {
|
|
|
140
145
|
if (percent && Number(percent[1]) <= 100) parts.push(`${percent[1]}%`);
|
|
141
146
|
const eta = lastMatch(ETA_RE, text);
|
|
142
147
|
if (eta) parts.push(`ETA ${eta[1].trim()}`);
|
|
148
|
+
// A job quiet past the threshold is no longer reassured as "not an error".
|
|
149
|
+
if (hung) return `[progress] ${[...parts, hung].join(' · ')}`;
|
|
143
150
|
return `[progress] ${parts.join(' · ')} — still running, not an error`;
|
|
144
151
|
}
|
|
145
152
|
|
|
@@ -169,7 +176,13 @@ export function shellLogPiece(path) {
|
|
|
169
176
|
export function readShellTaskOutput(
|
|
170
177
|
task,
|
|
171
178
|
result = {},
|
|
172
|
-
{
|
|
179
|
+
{
|
|
180
|
+
output = 'new',
|
|
181
|
+
terminal = task.status !== 'running',
|
|
182
|
+
digest = false,
|
|
183
|
+
now = Date.now(),
|
|
184
|
+
silenceWarnMs = SHELL_OUTPUT_SILENCE_WARN_MS,
|
|
185
|
+
} = {}
|
|
173
186
|
) {
|
|
174
187
|
const replay = output === 'tail';
|
|
175
188
|
const growth = [];
|
|
@@ -253,5 +266,6 @@ export function readShellTaskOutput(
|
|
|
253
266
|
const body =
|
|
254
267
|
sections.map((item) => (item.piece ? `${item.prefix}${bodies[pieces.indexOf(item)]}` : item)).join('\n\n') ||
|
|
255
268
|
(replay ? '(no output)' : '(no new output)');
|
|
256
|
-
|
|
269
|
+
const hung = digest ? describeShellOutputSilence(shellOutputSilenceMs(task, { now, result }), silenceWarnMs) : null;
|
|
270
|
+
return escapeHarnessTags(digest ? `${progressDigest(growth, hung)}\n\n${body}` : body);
|
|
257
271
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { runtimeAsyncLocalStorage } from '../../../../shared/root-async-context.mjs';
|
|
2
2
|
|
|
3
|
-
const localSearchTelemetry =
|
|
3
|
+
const localSearchTelemetry = runtimeAsyncLocalStorage();
|
|
4
4
|
|
|
5
5
|
export function runWithLocalSearchTelemetry(telemetry, run) {
|
|
6
6
|
return telemetry && typeof telemetry === 'object' ? localSearchTelemetry.run(telemetry, run) : run();
|
|
@@ -338,7 +338,7 @@ function _ensureServer() {
|
|
|
338
338
|
return;
|
|
339
339
|
}
|
|
340
340
|
if (message?.event === 'invalidate' && Array.isArray(message.paths)) {
|
|
341
|
-
invalidateBuiltinResultCache(message.paths.map(String));
|
|
341
|
+
invalidateBuiltinResultCache(message.paths.map(String), { canonical: true });
|
|
342
342
|
return;
|
|
343
343
|
}
|
|
344
344
|
if (message?.event === 'cancelled') {
|
|
@@ -355,11 +355,15 @@ function _gitIgnoredEntries(directory, names) {
|
|
|
355
355
|
* Boot-time prewarm: start the off-thread `git status` and `git check-ignore`
|
|
356
356
|
* probes for directories a session is likely to open, so the first session's
|
|
357
357
|
* prompt composition finds finished answers instead of spawning git on the
|
|
358
|
-
* event loop. Never
|
|
359
|
-
*
|
|
360
|
-
*
|
|
358
|
+
* event loop. Never throws; a directory whose prewarm has not answered yet
|
|
359
|
+
* when a session composes its prompt takes the synchronous probe exactly as
|
|
360
|
+
* without prewarm. The returned promise (never rejects) settles once the
|
|
361
|
+
* probes of these directories that were not yet answered have: an async
|
|
362
|
+
* session-creation path awaits it before the synchronous composition, so that
|
|
363
|
+
* composition never has to take the blocking probe.
|
|
361
364
|
*/
|
|
362
365
|
export function prewarmGitStartupProbes(directories) {
|
|
366
|
+
const unanswered = [];
|
|
363
367
|
for (const raw of Array.isArray(directories) ? directories : []) {
|
|
364
368
|
if (!raw) continue;
|
|
365
369
|
let directory;
|
|
@@ -392,7 +396,12 @@ export function prewarmGitStartupProbes(directories) {
|
|
|
392
396
|
entry.pending = null;
|
|
393
397
|
});
|
|
394
398
|
}
|
|
399
|
+
const changeState = _repositoryChangeStates.get(found.root);
|
|
400
|
+
if (!changeState.ready) unanswered.push(changeState.pending);
|
|
401
|
+
const ignored = _gitIgnoreObservations.get(directory);
|
|
402
|
+
if (!ignored.observation) unanswered.push(ignored.pending);
|
|
395
403
|
}
|
|
404
|
+
return Promise.all(unanswered).then(() => {});
|
|
396
405
|
}
|
|
397
406
|
|
|
398
407
|
/** Resolves once every in-flight startup git probe has finished. */
|
|
@@ -32,6 +32,7 @@ import { recordDeliveredCompletion } from '../../session/manager/delivered-compl
|
|
|
32
32
|
import { listShellJobRecords, readShellJobRecord } from './lib/shell-job-records.mjs';
|
|
33
33
|
import { resourceAdmission } from '../../../../shared/resource-admission.mjs';
|
|
34
34
|
import { readShellTaskOutput } from './lib/shell-task-output.mjs';
|
|
35
|
+
import { shellTaskSilenceNote } from './lib/shell-output-silence.mjs';
|
|
35
36
|
|
|
36
37
|
// Ceiling for confirming that a cancelled task's process really exited. The
|
|
37
38
|
// wait returns the moment the native task settles, so this only bounds a
|
|
@@ -89,6 +90,11 @@ function refreshShellTask(taskId, { includeRunning = false } = {}) {
|
|
|
89
90
|
if (task) {
|
|
90
91
|
task.result = publicResult;
|
|
91
92
|
task.resultText = JSON.stringify(publicResult, null, 2);
|
|
93
|
+
// The job's own status line: set while it is quiet past the threshold,
|
|
94
|
+
// gone again the moment it prints.
|
|
95
|
+
const silence = shellTaskSilenceNote(task);
|
|
96
|
+
if (silence) task.meta = { ...task.meta, output_silence: silence };
|
|
97
|
+
else if (task.meta?.output_silence) delete task.meta.output_silence;
|
|
92
98
|
}
|
|
93
99
|
}
|
|
94
100
|
return job;
|
|
@@ -144,6 +150,11 @@ async function listTasks(options) {
|
|
|
144
150
|
(record) => recoveredTaskMatches(record, options) && !liveIds.has(record.jobId)
|
|
145
151
|
);
|
|
146
152
|
const sections = [rendered];
|
|
153
|
+
const quiet = listBackgroundTasks({ context: options, surface: 'shell' })
|
|
154
|
+
.map((row) => [row.task_id, shellTaskSilenceNote(getBackgroundTask(row.task_id))])
|
|
155
|
+
.filter(([, note]) => note)
|
|
156
|
+
.map(([id, note]) => `- ${id} ${note}`);
|
|
157
|
+
if (quiet.length > 0) sections.push(`[output silence]\n${quiet.join('\n')}`);
|
|
147
158
|
if (recovered.length > 0) {
|
|
148
159
|
const rows = recovered.map(
|
|
149
160
|
(record) =>
|
|
@@ -175,7 +186,7 @@ async function waitForShellTask(task, taskId, args, options) {
|
|
|
175
186
|
turnSignal = null;
|
|
176
187
|
}
|
|
177
188
|
const waitControl = beginInterruptibleTaskWait(options?.sessionId, turnSignal);
|
|
178
|
-
const releaseWaitState = beginSessionTaskWait(options?.sessionId);
|
|
189
|
+
const releaseWaitState = beginSessionTaskWait(options?.sessionId, taskId);
|
|
179
190
|
const waitSignal = waitControl.signal;
|
|
180
191
|
const waitTimeoutMs = resolveTaskWaitTimeoutMs(args.timeout_ms, await defaultTaskWaitMs(options?.sessionId));
|
|
181
192
|
let interruptedByUser = false;
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
import { _graphRel } from './source-access.mjs';
|
|
31
31
|
import { CONTAINER_SYMBOL_KINDS } from './constants.mjs';
|
|
32
32
|
import { _symbolParentIndex, _symbolAncestors } from './text-columns.mjs';
|
|
33
|
+
import { _mainThreadSlice } from './main-thread-slice.mjs';
|
|
33
34
|
|
|
34
35
|
// Receivers that keep a `method` call attributable to the declaring file
|
|
35
36
|
// itself (an unqualified / self call), independent of imports.
|
|
@@ -253,8 +254,9 @@ function _astReachableTargetRels(graph, targetRels, name) {
|
|
|
253
254
|
//
|
|
254
255
|
// Node order: the cheap reachability/scope filters run BEFORE `_astCalls`, so
|
|
255
256
|
// a query normalizes the call arrays of the declaring files and their
|
|
256
|
-
// importers only — never of every node in the graph.
|
|
257
|
-
|
|
257
|
+
// importers only — never of every node in the graph. The walk is time-sliced:
|
|
258
|
+
// a common name reaches thousands of importers on a large root.
|
|
259
|
+
export async function _astCallerCallSites(
|
|
258
260
|
graph,
|
|
259
261
|
symbol,
|
|
260
262
|
targetRels,
|
|
@@ -266,12 +268,17 @@ export function _astCallerCallSites(
|
|
|
266
268
|
if (!name || !roots.length || !graph?.nodes) return out;
|
|
267
269
|
const cwd = graph.cwd || '';
|
|
268
270
|
const targets = _astReachableTargetRels(graph, roots, name);
|
|
271
|
+
const slice = _mainThreadSlice();
|
|
269
272
|
for (const node of graph.nodes.values()) {
|
|
273
|
+
if (slice.expired()) await slice.yield();
|
|
270
274
|
if (language && node.lang !== language) continue;
|
|
271
275
|
if (!_nodeInAstScope(node, fileRel, scopeRelPrefix)) continue;
|
|
272
276
|
const sameFile = targets.has(node.rel);
|
|
273
277
|
const importsTarget = _astImportedRels(node, cwd).some((rel) => targets.has(rel));
|
|
274
278
|
if (!sameFile && !importsTarget && !_astImportsUnresolved(node, cwd)) continue;
|
|
279
|
+
// No raw tuple named S → no row from this file, valid payload or not, so
|
|
280
|
+
// its call list is never normalized (thousands of importers on a large root).
|
|
281
|
+
if (!node.calls?.some?.((raw) => Array.isArray(raw) && raw[0] === name)) continue;
|
|
275
282
|
const calls = _astCalls(node);
|
|
276
283
|
if (!calls?.length) continue;
|
|
277
284
|
for (const call of calls) {
|
|
@@ -29,7 +29,13 @@ import {
|
|
|
29
29
|
CODE_GRAPH_WORKER_TIMEOUT_MS,
|
|
30
30
|
SYMBOL_SCHEMA_VERSION,
|
|
31
31
|
} from './constants.mjs';
|
|
32
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
_computeGraphSignature,
|
|
34
|
+
_deserializeGraph,
|
|
35
|
+
_attachGraphRuntimeCaches,
|
|
36
|
+
_estimateGraphBaseBytes,
|
|
37
|
+
_seedGraphBaseBytes,
|
|
38
|
+
} from './graph-model.mjs';
|
|
33
39
|
import { _touchCodeGraphCache, _setCodeGraphCache } from './memory-cache.mjs';
|
|
34
40
|
import {
|
|
35
41
|
ensureDiskCodeGraphLoaded,
|
|
@@ -40,7 +46,7 @@ import {
|
|
|
40
46
|
} from './disk-cache.mjs';
|
|
41
47
|
import { _runGraphManifest, callsWireSignatureToken, awaitCallsWireProbe } from './graph-binary.mjs';
|
|
42
48
|
import { assembleGraphNodes, linkGraphImports, resolveGraphFileInfos } from './build-file-infos.mjs';
|
|
43
|
-
import { _lookupCandidateNodes } from './symbol-index.mjs';
|
|
49
|
+
import { _ensureTokenIndex, _lookupCandidateNodes } from './symbol-index.mjs';
|
|
44
50
|
import { _findDirProjectRoot } from './project-root.mjs';
|
|
45
51
|
import { raceAbort } from './dispatch/abort-race.mjs';
|
|
46
52
|
|
|
@@ -172,6 +178,37 @@ async function _validateDiskCodeGraphHit({
|
|
|
172
178
|
return { graph, manifest, signature };
|
|
173
179
|
}
|
|
174
180
|
|
|
181
|
+
// A resident graph past its TTL is revalidated with the same manifest
|
|
182
|
+
// signature check a disk entry gets, instead of being rebuilt in a Worker and
|
|
183
|
+
// structured-cloned back onto the main thread (hundreds of MB for a large
|
|
184
|
+
// root). A mismatch hands the manifest to the Worker so it is not re-run.
|
|
185
|
+
export async function _revalidateResidentCodeGraph({
|
|
186
|
+
graphCwd,
|
|
187
|
+
entry,
|
|
188
|
+
genAtStart,
|
|
189
|
+
signal = null,
|
|
190
|
+
acquireSlot = (signal) => acquireChildSpawnSlot(signal, 'code-graph-query'),
|
|
191
|
+
runManifest = _runGraphManifest,
|
|
192
|
+
computeSignature = _graphSignatureForCapability,
|
|
193
|
+
getGeneration = _getCodeGraphGen,
|
|
194
|
+
setMemoryCache = _setCodeGraphCache,
|
|
195
|
+
}) {
|
|
196
|
+
const release = await acquireSlot(signal || null);
|
|
197
|
+
let manifest;
|
|
198
|
+
try {
|
|
199
|
+
_throwIfAborted(signal);
|
|
200
|
+
manifest = await runManifest(graphCwd, signal);
|
|
201
|
+
} finally {
|
|
202
|
+
release();
|
|
203
|
+
}
|
|
204
|
+
_throwIfAborted(signal);
|
|
205
|
+
const signature = computeSignature(manifest);
|
|
206
|
+
if (entry.signature !== signature) return { graph: null, manifest, signature };
|
|
207
|
+
if (getGeneration(graphCwd) !== genAtStart) throw codeGraphBuildInvalidatedError(entry.graph);
|
|
208
|
+
setMemoryCache(graphCwd, { ...entry, ts: Date.now() });
|
|
209
|
+
return { graph: entry.graph, manifest, signature };
|
|
210
|
+
}
|
|
211
|
+
|
|
175
212
|
// Validates the disk graph under a read-only query slot; a miss releases it
|
|
176
213
|
// and spawnWorker queues for a build slot, so queries never wait behind
|
|
177
214
|
// builds. Keeping this seam dependency-injectable makes slot/abort behavior
|
|
@@ -223,14 +260,89 @@ function _prepareDiskCodeGraphFastPath({
|
|
|
223
260
|
// Worker disk writes are debounced with an unref'd timer. Drain before sending
|
|
224
261
|
// success so every loaded cwd persists before this Worker can
|
|
225
262
|
// exit; a drain failure is intentionally thrown to the worker's failure path.
|
|
226
|
-
|
|
263
|
+
//
|
|
264
|
+
// The graph goes out in pieces: a header carrying the graph with every Map
|
|
265
|
+
// emptied, then each Map's entries in bounded chunks, then `done`. A single
|
|
266
|
+
// message holding the whole graph is deserialized on the receiving main thread
|
|
267
|
+
// in one uninterruptible structured-clone read (150-450 ms for a large root);
|
|
268
|
+
// chunks are each a short read. `nextChunk` (the worker awaits the receiver's
|
|
269
|
+
// ack) paces them one per main-thread event-loop turn — a port delivers every
|
|
270
|
+
// message already queued in one go, so unpaced chunks would be read back to
|
|
271
|
+
// back. Map order is preserved, so node iteration order — which answers depend
|
|
272
|
+
// on — is too.
|
|
273
|
+
const GRAPH_CHUNK_WEIGHT = 50_000;
|
|
274
|
+
|
|
275
|
+
function _graphChunkWeight(value) {
|
|
276
|
+
if (value instanceof Set) return value.size + 1;
|
|
277
|
+
if (typeof value?.text === 'string') return (value.text.length >> 6) + 1;
|
|
278
|
+
const calls = Array.isArray(value?.calls) ? value.calls.length : 0;
|
|
279
|
+
const tokens = Array.isArray(value?.tokenSymbols) ? value.tokenSymbols.length : 0;
|
|
280
|
+
const symbols = Array.isArray(value?.symbols) ? value.symbols.length : 0;
|
|
281
|
+
return 16 + calls * 8 + tokens + symbols * 8;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export async function _postCodeGraphWorkerSuccess(
|
|
227
285
|
graph,
|
|
228
286
|
postMessage,
|
|
229
287
|
drainCache = drainCodeGraphCacheStrict,
|
|
230
|
-
{ cache = true } = {}
|
|
288
|
+
{ cache = true, nextChunk = null } = {}
|
|
231
289
|
) {
|
|
232
290
|
if (cache) drainCache();
|
|
233
|
-
|
|
291
|
+
const baseBytes = _estimateGraphBaseBytes(graph);
|
|
292
|
+
const shell = {};
|
|
293
|
+
const maps = [];
|
|
294
|
+
for (const [key, value] of Object.entries(graph)) {
|
|
295
|
+
if (value instanceof Map) {
|
|
296
|
+
shell[key] = new Map();
|
|
297
|
+
maps.push([key, value]);
|
|
298
|
+
} else {
|
|
299
|
+
shell[key] = value;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
postMessage({ ok: true, signature: graph.signature, shell, baseBytes });
|
|
303
|
+
const post = async (message) => {
|
|
304
|
+
await nextChunk?.();
|
|
305
|
+
postMessage(message);
|
|
306
|
+
};
|
|
307
|
+
for (const [key, map] of maps) {
|
|
308
|
+
let entries = [];
|
|
309
|
+
let weight = 0;
|
|
310
|
+
for (const entry of map) {
|
|
311
|
+
entries.push(entry);
|
|
312
|
+
weight += _graphChunkWeight(entry[1]);
|
|
313
|
+
if (weight >= GRAPH_CHUNK_WEIGHT) {
|
|
314
|
+
await post({ key, entries });
|
|
315
|
+
entries = [];
|
|
316
|
+
weight = 0;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (entries.length) await post({ key, entries });
|
|
320
|
+
}
|
|
321
|
+
await post({ done: true });
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// The receiver's ack that lets a paced sender post its next chunk.
|
|
325
|
+
export const CODE_GRAPH_CHUNK_ACK = 'code-graph-chunk-ack';
|
|
326
|
+
|
|
327
|
+
// Main-thread side of the chunked protocol: feed every worker message in
|
|
328
|
+
// order; returns null until the result is complete, then the result message
|
|
329
|
+
// ({ ok, signature, graph, baseBytes }) — or a failure message as is.
|
|
330
|
+
export function _codeGraphWorkerReceiver() {
|
|
331
|
+
let header = null;
|
|
332
|
+
return (message) => {
|
|
333
|
+
if (!header) {
|
|
334
|
+
if (!message?.ok || !message.shell) return message;
|
|
335
|
+
header = message;
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
338
|
+
if (typeof message?.key === 'string') {
|
|
339
|
+
const map = header.shell[message.key];
|
|
340
|
+
for (const [key, value] of message.entries) map.set(key, value);
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
if (!message?.done) return null;
|
|
344
|
+
return { ok: true, signature: header.signature, graph: header.shell, baseBytes: header.baseBytes };
|
|
345
|
+
};
|
|
234
346
|
}
|
|
235
347
|
|
|
236
348
|
// Structured keys avoid both separator collisions inside roots/prefixes and
|
|
@@ -258,8 +370,9 @@ export function prewarmCodeGraphSymbols(cwd, symbols, { language = null } = {})
|
|
|
258
370
|
if (!cwd) return;
|
|
259
371
|
const wanted = (Array.isArray(symbols) ? symbols : [symbols]).map((s) => String(s || '').trim()).filter(Boolean);
|
|
260
372
|
buildCodeGraphAsync(cwd, null, { bestEffort: true })
|
|
261
|
-
.then((graph) => {
|
|
373
|
+
.then(async (graph) => {
|
|
262
374
|
if (!graph) return;
|
|
375
|
+
await _ensureTokenIndex(graph);
|
|
263
376
|
for (const symbol of wanted) {
|
|
264
377
|
try {
|
|
265
378
|
_lookupCandidateNodes(graph, symbol, language);
|
|
@@ -318,6 +431,12 @@ export async function buildCodeGraphAsync(
|
|
|
318
431
|
cacheResult: false,
|
|
319
432
|
});
|
|
320
433
|
}
|
|
434
|
+
const resident = _codeGraphCache.get(graphCwd);
|
|
435
|
+
if (resident?.graph) {
|
|
436
|
+
const hit = await _revalidateResidentCodeGraph({ graphCwd, entry: resident, genAtStart, signal });
|
|
437
|
+
if (hit.graph) return hit.graph;
|
|
438
|
+
return _spawnCodeGraphWorker(cwd, graphCwd, genAtStart, signal, hit.manifest, hit.signature);
|
|
439
|
+
}
|
|
321
440
|
return _prepareDiskCodeGraphFastPath({
|
|
322
441
|
graphCwd,
|
|
323
442
|
runFastPath: (diskProbe) =>
|
|
@@ -453,11 +572,22 @@ export function _spawnCodeGraphWorker(
|
|
|
453
572
|
};
|
|
454
573
|
signal.addEventListener('abort', _onSignalAbort, { once: true });
|
|
455
574
|
}
|
|
456
|
-
|
|
575
|
+
const receive = _codeGraphWorkerReceiver();
|
|
576
|
+
w.on('message', (part) => {
|
|
577
|
+
if (settled) return;
|
|
457
578
|
try {
|
|
579
|
+
const msg = receive(part);
|
|
580
|
+
if (!msg) {
|
|
581
|
+
// Next chunk on a later turn, so other work runs between reads.
|
|
582
|
+
setImmediate(() => {
|
|
583
|
+
if (!settled) w.postMessage?.(CODE_GRAPH_CHUNK_ACK);
|
|
584
|
+
});
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
458
587
|
if (msg?.ok && msg.graph && typeof msg.signature === 'string') {
|
|
459
588
|
const genStillCurrent = getGeneration(graphCwd) === genAtStart;
|
|
460
589
|
if (genStillCurrent && cacheResult) {
|
|
590
|
+
_seedGraphBaseBytes(msg.graph, msg.baseBytes);
|
|
461
591
|
setMemoryCache(graphCwd, { ts: Date.now(), signature: msg.signature, graph: msg.graph });
|
|
462
592
|
// The Worker strictly persisted this graph before posting
|
|
463
593
|
// success. Adopt it in the main process without scheduling a
|