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
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A request's one-word outcome in the request log. Precedence: failed >
|
|
3
|
+
* substituted > retried > completed.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// These providers echo the requested id instead of reporting the model that
|
|
7
|
+
// served, so a difference there would only be our own id mapping.
|
|
8
|
+
const NEVER_REPORTS_SERVED_MODEL = /^(?:gemini|vertex|antigravity)/;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The model id with only what provably names the same model removed: a
|
|
12
|
+
* `vendor/` route prefix (OpenRouter and gateways report `openai/gpt-5`), a
|
|
13
|
+
* `[…]` context-window tag (`[1m]`), a release-date snapshot and `-latest`.
|
|
14
|
+
* Anthropic reports the dated snapshot it served (`message_start.message.model`,
|
|
15
|
+
* anthropic-request-utils.mjs normalizeAnthropicNonStreamingResponse and the
|
|
16
|
+
* SSE turn), OpenAI and compatible providers the dated id in the response
|
|
17
|
+
* `model` (openai-compat-chat-stream/chunk-events.mjs). Dots, other digits
|
|
18
|
+
* and provider tags such as `:free` are kept: `gpt-5.1` is not `gpt-5-1`.
|
|
19
|
+
*/
|
|
20
|
+
export function normalizeServedModelId(model) {
|
|
21
|
+
let id = String(model || '').trim();
|
|
22
|
+
id = id.replace(/\[[^\]]*\]$/, '');
|
|
23
|
+
id = id.slice(id.lastIndexOf('/') + 1);
|
|
24
|
+
let previous;
|
|
25
|
+
do {
|
|
26
|
+
previous = id;
|
|
27
|
+
id = id.replace(/(?:-\d{8}|-\d{4}-\d{2}-\d{2}|@\d{8}|-latest)$/, '');
|
|
28
|
+
} while (id !== previous);
|
|
29
|
+
return id;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Whether the model that answered is not the model asked for. */
|
|
33
|
+
export function servedModelSubstituted({ provider, requestedModel, servedModel, fallback = false }) {
|
|
34
|
+
if (NEVER_REPORTS_SERVED_MODEL.test(String(provider || ''))) return false;
|
|
35
|
+
if (fallback) return true;
|
|
36
|
+
if (!requestedModel || !servedModel) return false;
|
|
37
|
+
const requested = normalizeServedModelId(requestedModel);
|
|
38
|
+
const served = normalizeServedModelId(servedModel);
|
|
39
|
+
// A router alias names no model: whatever it picks is what was asked for.
|
|
40
|
+
if (requested === 'auto' || served === requested) return false;
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function usageRequestStatus({ failed = false, substituted = false, attempts = 1 }) {
|
|
45
|
+
if (failed) return 'failed';
|
|
46
|
+
if (substituted) return 'substituted';
|
|
47
|
+
return attempts > 1 ? 'retried' : 'completed';
|
|
48
|
+
}
|
|
@@ -163,6 +163,28 @@ export function accountScopedSessionId(provider, accountId, sessionId) {
|
|
|
163
163
|
return `account-${createHash('sha256').update(`${provider}:${accountId}:${sessionId}`).digest('hex')}`;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
// Visible session id -> the account-scoped ids it has sent under. Transports
|
|
167
|
+
// key pooled connections by the scoped id, which cannot be derived back, so
|
|
168
|
+
// closing the visible session looks them up here.
|
|
169
|
+
const accountScopedIdsBySession = new Map();
|
|
170
|
+
|
|
171
|
+
/** Record that `sessionId` sent under `scopedId` (account-pool.mjs). */
|
|
172
|
+
export function noteAccountScopedSessionId(sessionId, scopedId) {
|
|
173
|
+
let ids = accountScopedIdsBySession.get(sessionId);
|
|
174
|
+
if (!ids) {
|
|
175
|
+
ids = new Set();
|
|
176
|
+
accountScopedIdsBySession.set(sessionId, ids);
|
|
177
|
+
}
|
|
178
|
+
ids.add(scopedId);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** The account-scoped ids `sessionId` has sent under; `forget` drops the record. */
|
|
182
|
+
export function accountScopedSessionIdsOf(sessionId, { forget = false } = {}) {
|
|
183
|
+
const ids = accountScopedIdsBySession.get(sessionId);
|
|
184
|
+
if (forget) accountScopedIdsBySession.delete(sessionId);
|
|
185
|
+
return ids ? [...ids] : [];
|
|
186
|
+
}
|
|
187
|
+
|
|
166
188
|
export function providerAccountPath(provider, id, dataDir = resolvePluginData()) {
|
|
167
189
|
requireAccountProvider(provider);
|
|
168
190
|
requireAccountId(id);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
1
|
import { ACCOUNT_PROVIDERS, providerAccountPath, readProviderAccountPool } from './provider-accounts.mjs';
|
|
2
|
+
import { runtimeAsyncLocalStorage } from './root-async-context.mjs';
|
|
3
3
|
|
|
4
4
|
const AUTH_BINDINGS = Symbol.for('mixdog.providerAuthBindings');
|
|
5
|
-
const scopedBindings =
|
|
5
|
+
const scopedBindings = runtimeAsyncLocalStorage();
|
|
6
6
|
|
|
7
7
|
export function hasExplicitProviderAuthBinding(provider) {
|
|
8
8
|
return Boolean(globalThis[AUTH_BINDINGS]?.[provider]);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { availableParallelism, freemem, totalmem } from 'node:os';
|
|
2
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
2
|
import { requestMemoryPressureSnapshot } from './memory-snapshot.mjs';
|
|
3
|
+
import { runtimeAsyncLocalStorage } from './root-async-context.mjs';
|
|
4
4
|
import { nonNegativeInt, positiveInt } from './numbers.mjs';
|
|
5
5
|
|
|
6
6
|
const MB = 1024 * 1024;
|
|
@@ -108,7 +108,7 @@ export class ResourceAdmissionController {
|
|
|
108
108
|
this.queue = [];
|
|
109
109
|
// Live leases for saturation diagnostics only (labels/ages in snapshot()).
|
|
110
110
|
this.activeLeases = new Set();
|
|
111
|
-
this.context =
|
|
111
|
+
this.context = runtimeAsyncLocalStorage();
|
|
112
112
|
// Admission waits by pool: first acquisition (agent/shell) and the
|
|
113
113
|
// reacquisition after a yielded provider call (restore). Shows whether
|
|
114
114
|
// the agent cap actually delays work.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// The process's empty async context, for long-lived handles.
|
|
2
|
+
//
|
|
3
|
+
// A handle (socket, timer, worker port) keeps the async context it was created
|
|
4
|
+
// in for its whole life: every AsyncLocalStorage store active at creation stays
|
|
5
|
+
// reachable from it. A pooled connection or shared worker first opened inside
|
|
6
|
+
// one request would otherwise pin that request's session, transcript and tools
|
|
7
|
+
// until the handle dies, long after the session is deleted.
|
|
8
|
+
//
|
|
9
|
+
// Process entries (src/standalone/daemon.mjs, src/cli.mjs) capture the root
|
|
10
|
+
// with initRootAsyncContext() before any request exists. Where nothing did
|
|
11
|
+
// (another host, a test, a module first loaded inside a request), every
|
|
12
|
+
// runtime store is left instead, so no load order can capture a request.
|
|
13
|
+
import { AsyncLocalStorage, AsyncResource } from 'node:async_hooks';
|
|
14
|
+
|
|
15
|
+
// Shared by every copy of this module in the process, so a second copy (a late
|
|
16
|
+
// or duplicated import) sees the same root and the same stores.
|
|
17
|
+
const STATE_KEY = Symbol.for('mixdog.rootAsyncContext');
|
|
18
|
+
globalThis[STATE_KEY] ??= { root: null, stores: new Set() };
|
|
19
|
+
const state = globalThis[STATE_KEY];
|
|
20
|
+
|
|
21
|
+
/** An AsyncLocalStorage the root context leaves: every runtime store is made here. */
|
|
22
|
+
export function runtimeAsyncLocalStorage() {
|
|
23
|
+
const store = new AsyncLocalStorage();
|
|
24
|
+
// Weak: per-instance stores (resource-admission controllers) come and go.
|
|
25
|
+
state.stores.add(new WeakRef(store));
|
|
26
|
+
return store;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function activeStores() {
|
|
30
|
+
const active = [];
|
|
31
|
+
for (const ref of state.stores) {
|
|
32
|
+
const store = ref.deref();
|
|
33
|
+
if (!store) state.stores.delete(ref);
|
|
34
|
+
else if (store.getStore() !== undefined) active.push(store);
|
|
35
|
+
}
|
|
36
|
+
return active;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Capture the current context as the root; refused (false) inside a request. */
|
|
40
|
+
export function initRootAsyncContext() {
|
|
41
|
+
if (state.root) return true;
|
|
42
|
+
if (activeStores().length > 0) return false;
|
|
43
|
+
state.root = new AsyncResource('MixdogRootContext');
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Run `fn` (synchronously) in the root context; returns its result. */
|
|
48
|
+
export function runInRootAsyncContext(fn) {
|
|
49
|
+
if (state.root) return state.root.runInAsyncScope(fn);
|
|
50
|
+
return activeStores().reduce((inner, store) => () => store.exit(inner), fn)();
|
|
51
|
+
}
|
|
@@ -31,6 +31,13 @@ export function killChildTree(child) {
|
|
|
31
31
|
/** The child has exited (an exit code or the signal that ended it). */
|
|
32
32
|
const childEnded = (child) => child.exitCode !== null || child.signalCode !== null;
|
|
33
33
|
|
|
34
|
+
// How long an exited child's pipes may stay open before its output is taken
|
|
35
|
+
// as complete. On Windows a process another thread of this process creates at
|
|
36
|
+
// the same moment (a long-lived server, say) can inherit this child's pipe
|
|
37
|
+
// ends and hold them open for its whole life, so 'close' would never come;
|
|
38
|
+
// what the child wrote before exiting is already in the pipes.
|
|
39
|
+
export const EXIT_DRAIN_MS = 1_000;
|
|
40
|
+
|
|
34
41
|
/**
|
|
35
42
|
* `waitForExitMs` (> 0): a timeout rejects only once the killed child has
|
|
36
43
|
* exited, or after that many more ms; the error then carries `pid` and
|
|
@@ -68,10 +75,12 @@ export function runChild({
|
|
|
68
75
|
let stdinError = null;
|
|
69
76
|
let settled = false;
|
|
70
77
|
let timedOut = false;
|
|
78
|
+
let drainTimer = null;
|
|
71
79
|
const finish = (error, result) => {
|
|
72
80
|
if (settled) return;
|
|
73
81
|
settled = true;
|
|
74
82
|
clearTimeout(timer);
|
|
83
|
+
clearTimeout(drainTimer);
|
|
75
84
|
if (error) rejectPromise(error);
|
|
76
85
|
else resolvePromise(result);
|
|
77
86
|
};
|
|
@@ -129,7 +138,7 @@ export function runChild({
|
|
|
129
138
|
// An error while a timeout terminates the child (a failed kill) is the timeout's.
|
|
130
139
|
if (!timedOut) finish(error);
|
|
131
140
|
});
|
|
132
|
-
|
|
141
|
+
const complete = (code) => {
|
|
133
142
|
// A timed-out child's close is the timeout's to report.
|
|
134
143
|
if (timedOut) return;
|
|
135
144
|
const result = {
|
|
@@ -144,6 +153,14 @@ export function runChild({
|
|
|
144
153
|
return;
|
|
145
154
|
}
|
|
146
155
|
finish(null, result);
|
|
156
|
+
};
|
|
157
|
+
child.once('close', complete);
|
|
158
|
+
child.once('exit', (code) => {
|
|
159
|
+
drainTimer = setTimeout(() => {
|
|
160
|
+
child.stdout.destroy?.();
|
|
161
|
+
child.stderr.destroy?.();
|
|
162
|
+
complete(code);
|
|
163
|
+
}, EXIT_DRAIN_MS);
|
|
147
164
|
});
|
|
148
165
|
if (child.stdin) {
|
|
149
166
|
// A short-lived child can close before stdin is flushed. Keep that
|
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
// names the spans that overlapped the stall window. Spans carry labels and
|
|
7
7
|
// phase durations only — never payloads.
|
|
8
8
|
|
|
9
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
10
9
|
import { performance } from 'node:perf_hooks';
|
|
10
|
+
import { runtimeAsyncLocalStorage } from './root-async-context.mjs';
|
|
11
11
|
|
|
12
12
|
export const SPAN_RING_MIN_MS = 25;
|
|
13
13
|
export const SPAN_SLOW_MS = 1000;
|
|
14
14
|
export const SPAN_RING_CAPACITY = 64;
|
|
15
15
|
|
|
16
|
-
const current =
|
|
16
|
+
const current = runtimeAsyncLocalStorage();
|
|
17
17
|
|
|
18
18
|
/** Short, log-safe id of a session id. */
|
|
19
19
|
export function shortId(id) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { runtimeAsyncLocalStorage } from './root-async-context.mjs';
|
|
2
2
|
|
|
3
|
-
const toolExecutionOwner =
|
|
3
|
+
const toolExecutionOwner = runtimeAsyncLocalStorage();
|
|
4
4
|
|
|
5
5
|
export function runWithToolExecutionOwner(ownerKey, run) {
|
|
6
6
|
const owner =
|
|
@@ -265,7 +265,7 @@ function stripInlineMarkdown(value) {
|
|
|
265
265
|
// Envelope field lines (`status: …`, `task_id: …`) that precede or surround a
|
|
266
266
|
// real agent answer. One list so both scanners below skip exactly the same set.
|
|
267
267
|
const ENVELOPE_FIELD_LINE_RE =
|
|
268
|
-
/^(?:agent task|background task|status|type|target|role|agent|preset|model|effort|fast|limits|session|task-id|task_id|surface|operation|label|exit_code|timed_out|signal|notification|queueDepth|worker|worker_stage|last_progress|silent_for|watchdog|queued_followups|diagnostic|started|finished|elapsed|reused|result|message|output|protocol|version):\s*/i;
|
|
268
|
+
/^(?:agent task|background task|status|type|target|role|agent|preset|model|effort|fast|limits|session|task-id|task_id|surface|operation|label|exit_code|timed_out|signal|notification|queueDepth|worker|worker_stage|last_progress|silent_for|tool_silent_for|watchdog|queued_followups|diagnostic|started|finished|elapsed|reused|result|message|output|protocol|version):\s*/i;
|
|
269
269
|
|
|
270
270
|
// Headers that open an envelope block without a colon (`background task`).
|
|
271
271
|
const ENVELOPE_HEADER_LINE_RE = /^(?:agent result|background task)\b/i;
|
|
@@ -358,6 +358,8 @@ function visualizeUnit(a) {
|
|
|
358
358
|
return unitDescriptor('Visualize', { count: 1, active: 'Checking', done: 'Checked', noun: 'page' });
|
|
359
359
|
if (action === 'inspect')
|
|
360
360
|
return unitDescriptor('Visualize', { count: 1, active: 'Inspecting', done: 'Inspected', noun: 'page' });
|
|
361
|
+
if (action === 'act')
|
|
362
|
+
return unitDescriptor('Visualize', { count: 1, active: 'Operating', done: 'Operated', noun: 'page' });
|
|
361
363
|
if (action === 'close')
|
|
362
364
|
return unitDescriptor('Visualize', { count: 1, active: 'Closing', done: 'Closed', noun: 'tab' });
|
|
363
365
|
return unitDescriptor('Visualize', { count: 1, active: 'Showing', done: 'Showed', noun: 'artifact' });
|
|
@@ -499,16 +499,30 @@ function changesPath(sessionId) {
|
|
|
499
499
|
return join(changesRoot(), `${hash}.json`);
|
|
500
500
|
}
|
|
501
501
|
|
|
502
|
+
/** The session's changes file; null when it is not a changes file of this
|
|
503
|
+
* session. An unreadable or unparsable file throws. */
|
|
504
|
+
async function parseChangesFile(sessionId) {
|
|
505
|
+
const parsed = JSON.parse(await readFile(changesPath(sessionId), 'utf8'));
|
|
506
|
+
if (parsed?.version !== CHANGES_VERSION || parsed.sessionId !== sessionId) return null;
|
|
507
|
+
return Array.isArray(parsed.records) ? parsed : null;
|
|
508
|
+
}
|
|
509
|
+
|
|
502
510
|
async function readChangesFile(sessionId) {
|
|
503
511
|
try {
|
|
504
|
-
|
|
505
|
-
if (parsed?.version !== CHANGES_VERSION || parsed.sessionId !== sessionId) return null;
|
|
506
|
-
return Array.isArray(parsed.records) ? parsed : null;
|
|
512
|
+
return await parseChangesFile(sessionId);
|
|
507
513
|
} catch {
|
|
508
514
|
return null;
|
|
509
515
|
}
|
|
510
516
|
}
|
|
511
517
|
|
|
518
|
+
function deepFreeze(value) {
|
|
519
|
+
if (value && typeof value === 'object' && !Object.isFrozen(value)) {
|
|
520
|
+
Object.freeze(value);
|
|
521
|
+
for (const child of Object.values(value)) deepFreeze(child);
|
|
522
|
+
}
|
|
523
|
+
return value;
|
|
524
|
+
}
|
|
525
|
+
|
|
512
526
|
/** Evict the oldest turns until the session fits its byte budget; a turn that
|
|
513
527
|
* alone exceeds it drops its largest patches (those files stop being
|
|
514
528
|
* revertable) instead of the whole record. */
|
|
@@ -558,7 +572,12 @@ async function writeChangeRecords(sessionId, records) {
|
|
|
558
572
|
changesSweepDone = true;
|
|
559
573
|
void sweepDirectory(changesRoot(), CHANGE_RECORD_TTL_MS, MAX_CHANGE_RECORD_FILES);
|
|
560
574
|
}
|
|
561
|
-
|
|
575
|
+
try {
|
|
576
|
+
await writeJsonAtomically(changesPath(sessionId), { version: CHANGES_VERSION, sessionId, records });
|
|
577
|
+
} finally {
|
|
578
|
+
// A read between the drop above and the rename may have cached the old file.
|
|
579
|
+
changeRecordsCache.delete(sessionId);
|
|
580
|
+
}
|
|
562
581
|
}
|
|
563
582
|
|
|
564
583
|
const changeContent = (record) =>
|
|
@@ -652,39 +671,77 @@ export async function loadTurnChangeRecord(sessionId, checkpointId) {
|
|
|
652
671
|
const id = clean(sessionId);
|
|
653
672
|
const key = clean(checkpointId);
|
|
654
673
|
if (!id || !key) return null;
|
|
655
|
-
const records =
|
|
674
|
+
const records = await loadTurnChangeRecords(id);
|
|
656
675
|
return records.find((record) => record?.checkpointId === key) || null;
|
|
657
676
|
}
|
|
658
677
|
|
|
659
678
|
// Parsed change records by session, valid while the file's mtime and size are
|
|
660
|
-
// unchanged: the session review
|
|
661
|
-
// re-read and re-parse
|
|
679
|
+
// unchanged: the session review and every turn card read the same multi-
|
|
680
|
+
// megabyte file and must not re-read and re-parse it each time. An entry holds
|
|
681
|
+
// the parse's promise, so concurrent readers of one file share a single parse.
|
|
682
|
+
// Least recently used first; bounded by session count and by the summed file
|
|
683
|
+
// bytes (the newest entry always stays, however large). Records are shared and
|
|
684
|
+
// deep-frozen, and every write drops the entry.
|
|
662
685
|
const changeRecordsCache = new Map();
|
|
663
686
|
const CHANGE_RECORDS_CACHE_SESSIONS = 8;
|
|
687
|
+
const CHANGE_RECORDS_CACHE_BYTES = 64 * 1024 * 1024;
|
|
688
|
+
|
|
689
|
+
function trimChangeRecordsCache() {
|
|
690
|
+
let bytes = 0;
|
|
691
|
+
for (const entry of changeRecordsCache.values()) bytes += entry.bytes;
|
|
692
|
+
while (
|
|
693
|
+
changeRecordsCache.size > 1 &&
|
|
694
|
+
(changeRecordsCache.size > CHANGE_RECORDS_CACHE_SESSIONS || bytes > CHANGE_RECORDS_CACHE_BYTES)
|
|
695
|
+
) {
|
|
696
|
+
const [oldest, entry] = changeRecordsCache.entries().next().value;
|
|
697
|
+
changeRecordsCache.delete(oldest);
|
|
698
|
+
bytes -= entry.bytes;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
664
701
|
|
|
665
702
|
/** Every retained turn's change record of a session, oldest first. */
|
|
666
703
|
export async function loadTurnChangeRecords(sessionId) {
|
|
667
704
|
const id = clean(sessionId);
|
|
668
705
|
if (!id) return [];
|
|
669
|
-
let
|
|
706
|
+
let info;
|
|
670
707
|
try {
|
|
671
|
-
|
|
672
|
-
signature = `${info.mtimeMs}:${info.size}`;
|
|
708
|
+
info = await stat(changesPath(id));
|
|
673
709
|
} catch {
|
|
674
710
|
changeRecordsCache.delete(id);
|
|
675
711
|
return [];
|
|
676
712
|
}
|
|
713
|
+
const signature = `${info.mtimeMs}:${info.size}`;
|
|
677
714
|
const cached = changeRecordsCache.get(id);
|
|
678
|
-
if (cached?.signature === signature) return cached.records;
|
|
679
|
-
const records = ((await readChangesFile(id))?.records || [])
|
|
680
|
-
.filter(Boolean)
|
|
681
|
-
.sort((left, right) => (Number(left.createdAt) || 0) - (Number(right.createdAt) || 0));
|
|
682
715
|
changeRecordsCache.delete(id);
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
716
|
+
if (cached?.signature === signature) {
|
|
717
|
+
changeRecordsCache.set(id, cached);
|
|
718
|
+
try {
|
|
719
|
+
return await cached.records;
|
|
720
|
+
} catch {
|
|
721
|
+
if (changeRecordsCache.get(id) === cached) changeRecordsCache.delete(id);
|
|
722
|
+
return [];
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
const entry = {
|
|
726
|
+
signature,
|
|
727
|
+
bytes: info.size,
|
|
728
|
+
records: parseChangesFile(id).then((file) =>
|
|
729
|
+
deepFreeze(
|
|
730
|
+
(file?.records || [])
|
|
731
|
+
.filter(Boolean)
|
|
732
|
+
.sort((left, right) => (Number(left.createdAt) || 0) - (Number(right.createdAt) || 0))
|
|
733
|
+
)
|
|
734
|
+
),
|
|
735
|
+
};
|
|
736
|
+
changeRecordsCache.set(id, entry);
|
|
737
|
+
trimChangeRecordsCache();
|
|
738
|
+
try {
|
|
739
|
+
return await entry.records;
|
|
740
|
+
} catch {
|
|
741
|
+
// A failed read is not remembered: the next call reads the file again.
|
|
742
|
+
if (changeRecordsCache.get(id) === entry) changeRecordsCache.delete(id);
|
|
743
|
+
return [];
|
|
686
744
|
}
|
|
687
|
-
return records;
|
|
688
745
|
}
|
|
689
746
|
|
|
690
747
|
export function _setTurnChangeRecordWriteHookForTest(hook) {
|
|
@@ -161,19 +161,49 @@ function stateForRoot(root) {
|
|
|
161
161
|
return state;
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
// Platforms whose recursive watch backend reports a path as the watched
|
|
165
|
+
// (canonical) root plus a relative name and never descends into a link:
|
|
166
|
+
// ReadDirectoryChangesW on Windows watches one directory handle and its own
|
|
167
|
+
// subtree, and FSEvents on macOS reports resolved paths. inotify on Linux
|
|
168
|
+
// follows links while walking a recursive watch, so it can report an alias
|
|
169
|
+
// of a directory that another tracked root owns. Unlisted platforms are not
|
|
170
|
+
// trusted either.
|
|
171
|
+
const LINK_FREE_WATCH_PLATFORMS = new Set(['win32', 'darwin']);
|
|
172
|
+
|
|
164
173
|
/** Report written paths (or `null`: anything may have changed). The next
|
|
165
|
-
* review poll of an affected worktree captures instead of reusing.
|
|
166
|
-
|
|
174
|
+
* review poll of an affected worktree captures instead of reusing.
|
|
175
|
+
* `canonical`: the paths come from a recursive watch on canonical roots. On a
|
|
176
|
+
* link-free backend a path under a root by its own spelling then needs no
|
|
177
|
+
* filesystem call; one that is not is still canonicalised. Every other
|
|
178
|
+
* source, and every watcher on another platform, may name paths through
|
|
179
|
+
* links, so each is canonicalised. `platform` exists for tests. */
|
|
180
|
+
export function noteTurnWorktreeChange(paths = null, { canonical = false, platform = process.platform } = {}) {
|
|
167
181
|
if (states.size === 0) return;
|
|
168
182
|
const list = Array.isArray(paths) ? paths.filter((value) => clean(value)) : [];
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
183
|
+
if (list.length === 0) {
|
|
184
|
+
for (const state of states.values()) state.changeStamp += 1;
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const roots = [...states.values()].map((state) => ({ state, root: pathKey(state.root) }));
|
|
188
|
+
const stamped = new Set();
|
|
189
|
+
const stampMatches = (key) => {
|
|
190
|
+
let matched = false;
|
|
191
|
+
for (const { state, root } of roots) {
|
|
192
|
+
if (key === root || key.startsWith(`${root}/`)) {
|
|
193
|
+
stamped.add(state);
|
|
194
|
+
matched = true;
|
|
195
|
+
}
|
|
175
196
|
}
|
|
197
|
+
return matched;
|
|
198
|
+
};
|
|
199
|
+
const trustSpelling = canonical && LINK_FREE_WATCH_PLATFORMS.has(platform);
|
|
200
|
+
const dirs = new Map();
|
|
201
|
+
for (const value of list) {
|
|
202
|
+
if (stamped.size === roots.length) break;
|
|
203
|
+
if (trustSpelling && stampMatches(pathKey(resolve(value)))) continue;
|
|
204
|
+
stampMatches(pathKey(canonicalPath(value, dirs)));
|
|
176
205
|
}
|
|
206
|
+
for (const state of stamped) state.changeStamp += 1;
|
|
177
207
|
}
|
|
178
208
|
|
|
179
209
|
// A lock hold (queue wait plus work) at least this long is logged, so a slow
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
* disk reads of user-cwd.txt are negligible.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
23
22
|
import { readFileSync, statSync } from 'node:fs';
|
|
24
23
|
import { join, resolve } from 'node:path';
|
|
25
24
|
import { homedir } from 'node:os';
|
|
26
25
|
import { holdsNoData, writeFileAtomicSync } from './atomic-file.mjs';
|
|
27
26
|
import { resolvePluginData, mixdogRoot } from './plugin-paths.mjs';
|
|
27
|
+
import { runtimeAsyncLocalStorage } from './root-async-context.mjs';
|
|
28
28
|
|
|
29
|
-
const _cwdOverride =
|
|
29
|
+
const _cwdOverride = runtimeAsyncLocalStorage();
|
|
30
30
|
|
|
31
31
|
function _activeCwdOverride() {
|
|
32
32
|
const store = _cwdOverride.getStore();
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// synchronous native work (process creation, SQLite queries) off the host
|
|
3
3
|
// event loop while callers simply await the answer.
|
|
4
4
|
import { parentPort, Worker } from 'node:worker_threads';
|
|
5
|
+
import { runInRootAsyncContext } from './root-async-context.mjs';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Returns `request(payload) → Promise<result>`. The worker starts on first use,
|
|
@@ -46,7 +47,8 @@ export function createWorkerRequestClient(url, { idleExitMs = 0, onEvent = null,
|
|
|
46
47
|
|
|
47
48
|
function ensureWorker() {
|
|
48
49
|
if (worker) return worker;
|
|
49
|
-
|
|
50
|
+
// Shared by every later caller: never let it retain the first caller's context.
|
|
51
|
+
const created = runInRootAsyncContext(() => new Worker(url, { execArgv: [], ...workerOptions }));
|
|
50
52
|
const owned = pending;
|
|
51
53
|
const rejectOwned = (error) => {
|
|
52
54
|
const entries = [...owned.values()];
|
|
@@ -9,16 +9,16 @@
|
|
|
9
9
|
* shared by the runtime daemon and the desktop main process.
|
|
10
10
|
* Re-entrant within one async call chain.
|
|
11
11
|
*/
|
|
12
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
13
12
|
import { join } from 'node:path';
|
|
14
13
|
import { withGitRepoWriteLock } from '../../agent/orchestrator/tools/builtin/git-repo-rw-lock.mjs';
|
|
15
14
|
import { withFileLock } from '../file-lock.mjs';
|
|
16
15
|
import { resolvePluginData } from '../plugin-paths.mjs';
|
|
17
16
|
import { repoHash, WORKTREE_STORE_DIR } from './contract.mjs';
|
|
18
17
|
import { canonicalPath, pathKey } from './paths.mjs';
|
|
18
|
+
import { runtimeAsyncLocalStorage } from '../root-async-context.mjs';
|
|
19
19
|
|
|
20
20
|
const REPO_LOCK_TIMEOUT_MS = 120_000;
|
|
21
|
-
const heldRepoLocks =
|
|
21
|
+
const heldRepoLocks = runtimeAsyncLocalStorage();
|
|
22
22
|
|
|
23
23
|
/** Cross-process lock file for one repository (outside the removable root). */
|
|
24
24
|
function repoLockPath(repoCommonDir, { dataDir = resolvePluginData() } = {}) {
|
|
@@ -14,8 +14,13 @@ const REQUEST_TIMEOUT_MS = 30_000;
|
|
|
14
14
|
* for it (45 s) is shorter, so a timeout is reported by the host, which then
|
|
15
15
|
* writes nothing, rather than raced by this client. */
|
|
16
16
|
const EXPORT_REQUEST_TIMEOUT_MS = 60_000;
|
|
17
|
+
/** `act` loads a page (off screen), runs up to 15 s of steps and may capture;
|
|
18
|
+
* the host bounds each part, so it gets the export's longer wait. */
|
|
19
|
+
const LONG_ACTIONS = new Set(['export', 'act']);
|
|
17
20
|
const MAX_RESPONSE_BYTES = 1024 * 1024;
|
|
18
|
-
const ACTIONS = new Set(['open', 'close', 'annotate', 'capture', 'export', 'check', 'inspect']);
|
|
21
|
+
const ACTIONS = new Set(['open', 'close', 'annotate', 'capture', 'export', 'check', 'inspect', 'act']);
|
|
22
|
+
const ACT_STEP_KINDS = new Set(['click', 'type', 'key', 'scroll', 'wait', 'evaluate']);
|
|
23
|
+
const MAX_ACT_STEPS = 25;
|
|
19
24
|
const INLINE_KINDS = ['mermaid', 'svg', 'chart', 'html', 'markdown'];
|
|
20
25
|
const MAX_INLINE_BYTES = 512 * 1024;
|
|
21
26
|
const BRIDGE_UNAVAILABLE_MESSAGE = 'visualize is unavailable; the Mixdog desktop app must be running';
|
|
@@ -40,7 +45,7 @@ export function validateVisualizeArgs(args) {
|
|
|
40
45
|
return { ok: false, error: 'visualize arguments must be an object' };
|
|
41
46
|
}
|
|
42
47
|
if (!ACTIONS.has(args.action))
|
|
43
|
-
return { ok: false, error: 'action must be open, close, annotate, capture, export, check, or
|
|
48
|
+
return { ok: false, error: 'action must be open, close, annotate, capture, export, check, inspect, or act' };
|
|
44
49
|
const input = args.input ?? {};
|
|
45
50
|
if (typeof input !== 'object' || Array.isArray(input)) return { ok: false, error: 'input must be an object' };
|
|
46
51
|
if (args.action === 'open' && input.verify != null && typeof input.verify !== 'boolean') {
|
|
@@ -86,7 +91,7 @@ export function validateVisualizeArgs(args) {
|
|
|
86
91
|
}
|
|
87
92
|
}
|
|
88
93
|
if (
|
|
89
|
-
['annotate', 'capture', 'export', 'check', 'inspect'].includes(args.action) &&
|
|
94
|
+
['annotate', 'capture', 'export', 'check', 'inspect', 'act'].includes(args.action) &&
|
|
90
95
|
(typeof input.tab !== 'string' || !input.tab)
|
|
91
96
|
) {
|
|
92
97
|
return { ok: false, error: `${args.action} requires input.tab` };
|
|
@@ -114,6 +119,21 @@ export function validateVisualizeArgs(args) {
|
|
|
114
119
|
if (args.action === 'capture' && !(typeof input.output === 'string' && /\.png$/i.test(input.output.trim()))) {
|
|
115
120
|
return { ok: false, error: 'capture requires input.output ending in .png' };
|
|
116
121
|
}
|
|
122
|
+
if (args.action === 'act') {
|
|
123
|
+
const { steps } = input;
|
|
124
|
+
if (!Array.isArray(steps) || steps.length < 1 || steps.length > MAX_ACT_STEPS) {
|
|
125
|
+
return { ok: false, error: `act requires input.steps: 1-${MAX_ACT_STEPS} steps` };
|
|
126
|
+
}
|
|
127
|
+
const bad = steps.findIndex(
|
|
128
|
+
(step) => !step || typeof step !== 'object' || Array.isArray(step) || !ACT_STEP_KINDS.has(step.do)
|
|
129
|
+
);
|
|
130
|
+
if (bad >= 0) {
|
|
131
|
+
return { ok: false, error: `act input.steps[${bad}].do must be click, type, key, scroll, wait, or evaluate` };
|
|
132
|
+
}
|
|
133
|
+
if (input.output != null && !(typeof input.output === 'string' && /\.png$/i.test(input.output.trim()))) {
|
|
134
|
+
return { ok: false, error: 'act input.output must end in .png' };
|
|
135
|
+
}
|
|
136
|
+
}
|
|
117
137
|
if (args.action === 'export') {
|
|
118
138
|
if (input.format !== 'png' && input.format !== 'pdf')
|
|
119
139
|
return { ok: false, error: 'export requires input.format png or pdf' };
|
|
@@ -173,7 +193,9 @@ export async function executeVisualizeTool(args, options = {}) {
|
|
|
173
193
|
if (!discovery) return toolError(unavailableMessage());
|
|
174
194
|
let result;
|
|
175
195
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
176
|
-
const timeout = AbortSignal.timeout(
|
|
196
|
+
const timeout = AbortSignal.timeout(
|
|
197
|
+
LONG_ACTIONS.has(validated.action) ? EXPORT_REQUEST_TIMEOUT_MS : REQUEST_TIMEOUT_MS
|
|
198
|
+
);
|
|
177
199
|
try {
|
|
178
200
|
result = await requestBridge(
|
|
179
201
|
discovery,
|