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
|
@@ -74,8 +74,15 @@ export function createProviderReadiness({ rt, keychain, getReg, getWarmProviderM
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// A keyring unlocked after boot: every cache built while stored keys read as
|
|
77
|
-
// absent (provider setup, init gates) is stale.
|
|
78
|
-
|
|
77
|
+
// absent (provider setup, init gates) is stale. The keychain module outlives
|
|
78
|
+
// every runtime, so the listener (which holds this runtime and its caches)
|
|
79
|
+
// is released by dispose().
|
|
80
|
+
const unsubscribeKeychainRecovered = keychain.onKeychainRecovered?.(() => invalidateProviderCaches());
|
|
81
|
+
|
|
82
|
+
/** Release the keychain subscription; the runtime's teardown calls it. Idempotent. */
|
|
83
|
+
function dispose() {
|
|
84
|
+
unsubscribeKeychainRecovered?.();
|
|
85
|
+
}
|
|
79
86
|
|
|
80
87
|
// The one edit a caller makes to the provider config it passes is turning a
|
|
81
88
|
// route's provider on (ensureProviderEnabled); those providers, judged
|
|
@@ -178,6 +185,7 @@ export function createProviderReadiness({ rt, keychain, getReg, getWarmProviderM
|
|
|
178
185
|
invalidateProviderCaches,
|
|
179
186
|
reinitProviders,
|
|
180
187
|
ensureProvidersReady,
|
|
188
|
+
dispose,
|
|
181
189
|
modelMetaByRoute,
|
|
182
190
|
providerModelCaches,
|
|
183
191
|
providerUsageCaches,
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
* Routines are bot-based: a schedule or webhook runs in its owner bot's home
|
|
3
3
|
* thread (routine-home-turn.mjs) and nowhere else. An owner that does not
|
|
4
4
|
* exist — Mixy before the representative bot was created, a bot archived or
|
|
5
|
-
* deleted — makes the routine paused: it does not fire
|
|
6
|
-
*
|
|
5
|
+
* deleted — makes the routine paused: it does not fire and a new routine
|
|
6
|
+
* cannot name it. An archived bot's routines are also hidden from the lists
|
|
7
|
+
* and come back, untouched, when it is restored; deleting it for good deletes
|
|
8
|
+
* them (agent-editor.mjs). The lists show why any other one is paused.
|
|
7
9
|
*/
|
|
8
10
|
import { MIXY_AGENT_ID } from '../runtime/agent/orchestrator/session/agent-home.mjs';
|
|
9
11
|
import { mixyExists } from '../runtime/shared/mixy-presence.mjs';
|
|
@@ -12,6 +14,7 @@ import { scheduleOwnerAgentId } from './agent-home-delivery.mjs';
|
|
|
12
14
|
/** `ownerProblem` codes and the error each one raises. */
|
|
13
15
|
export const ROUTINE_OWNER_PROBLEMS = Object.freeze({
|
|
14
16
|
'no-mixy': 'Create the representative bot first.',
|
|
17
|
+
'owner-archived': 'The bot that owns this routine is deleted (in Archived). Restore it, or pick another bot.',
|
|
15
18
|
'owner-deleted': 'The bot that owns this routine no longer exists. Pick another bot.',
|
|
16
19
|
});
|
|
17
20
|
|
|
@@ -56,6 +59,7 @@ async function defaultProbe() {
|
|
|
56
59
|
return {
|
|
57
60
|
mixyExists: (ownsRoutine) => readMixyExists(null, { ownsRoutine }),
|
|
58
61
|
presence: (agentId) => api.agentDefinitionPresence([agentId])[agentId],
|
|
62
|
+
archived: (agentId) => Boolean(api.archivedAgentIdentities([agentId])[agentId]),
|
|
59
63
|
};
|
|
60
64
|
}
|
|
61
65
|
|
|
@@ -69,7 +73,9 @@ export async function routineOwnerProblem(ownerAgentId, probe = null, { stored =
|
|
|
69
73
|
const owner = scheduleOwnerAgentId({ ownerAgentId });
|
|
70
74
|
const check = probe || (await defaultProbe());
|
|
71
75
|
if (owner === MIXY_AGENT_ID) return (await check.mixyExists(stored)) ? '' : 'no-mixy';
|
|
72
|
-
|
|
76
|
+
if (check.presence(owner) !== 'deleted') return '';
|
|
77
|
+
// Archived (restorable): its routines wait, hidden, for the restore.
|
|
78
|
+
return check.archived?.(owner) ? 'owner-archived' : 'owner-deleted';
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
/** Rejects with the owner's problem; resolves when it can own a routine. */
|
|
@@ -62,14 +62,41 @@ function bootParams({
|
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
// A boot that throws returns no runtime to close, so whatever its stages already
|
|
66
|
+
// subscribed to process-wide registries is released here. Each release is
|
|
67
|
+
// independent of the late disposeGlobalExtensionSubscription aggregate (wired by
|
|
68
|
+
// the last stage) and tolerates a stage that never ran.
|
|
69
|
+
function releaseFailedBoot(boot) {
|
|
70
|
+
for (const release of [
|
|
71
|
+
() => boot.disposeProviderReadiness(),
|
|
72
|
+
() => boot.disposeConfigSync?.(),
|
|
73
|
+
() => boot.disposeAgentProfileChanges?.(),
|
|
74
|
+
() => boot.resourceApi?.disposeGlobalExtensionSubscription?.(),
|
|
75
|
+
() => boot.setupTool?.dispose(),
|
|
76
|
+
() => boot.disposeInternalTools?.(),
|
|
77
|
+
() => boot.sessionTitles?.disposeAll(),
|
|
78
|
+
]) {
|
|
79
|
+
try {
|
|
80
|
+
release();
|
|
81
|
+
} catch {
|
|
82
|
+
/* the boot error is the one to report */
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
65
87
|
export async function createMixdogSessionRuntime(options = {}) {
|
|
66
88
|
const boot = beginBoot(bootParams(options));
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
89
|
+
try {
|
|
90
|
+
await loadModules(boot);
|
|
91
|
+
await resolveConfig(boot);
|
|
92
|
+
wireInfrastructure(boot);
|
|
93
|
+
wireTools(boot);
|
|
94
|
+
wireProviders(boot);
|
|
95
|
+
wireSessionLifecycle(boot);
|
|
96
|
+
wireApis(boot);
|
|
97
|
+
return buildFacade(boot);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
releaseFailedBoot(boot);
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
75
102
|
}
|
|
@@ -32,7 +32,9 @@ registerSessionPurgeHook((sessionId) => {
|
|
|
32
32
|
// reach the turn's worktree snapshot as its change signal: a session review
|
|
33
33
|
// read right after them captures the worktree, an unsignaled one may reuse
|
|
34
34
|
// the last capture.
|
|
35
|
-
registerCacheInvalidationListener((paths) =>
|
|
35
|
+
registerCacheInvalidationListener((paths, source) =>
|
|
36
|
+
noteTurnWorktreeChange(paths, { canonical: source?.canonical === true })
|
|
37
|
+
);
|
|
36
38
|
|
|
37
39
|
export function createRuntimeReviewApi({ getCwd, getSessionId }) {
|
|
38
40
|
return {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { formatDuration } from '../../runtime/shared/time-format.mjs';
|
|
1
2
|
import {
|
|
2
3
|
agentWatchdogPolicyActive,
|
|
3
4
|
evaluateAgentWatchdogAbort,
|
|
@@ -66,6 +67,7 @@ export function buildAgentTaskProgressFields({
|
|
|
66
67
|
queuedFollowups = null,
|
|
67
68
|
taskStatus = null,
|
|
68
69
|
lastToolCall = null,
|
|
70
|
+
toolSilence = null,
|
|
69
71
|
} = {}) {
|
|
70
72
|
const stage = cleanStage(runtimeStage || snapshot?.stage || sessionStatus || 'unknown');
|
|
71
73
|
const silentFor = resolveSilentForSeconds(now, snapshot, runtime);
|
|
@@ -93,6 +95,7 @@ export function buildAgentTaskProgressFields({
|
|
|
93
95
|
queued,
|
|
94
96
|
policy,
|
|
95
97
|
now,
|
|
98
|
+
toolSilence,
|
|
96
99
|
});
|
|
97
100
|
|
|
98
101
|
const out = {
|
|
@@ -102,6 +105,11 @@ export function buildAgentTaskProgressFields({
|
|
|
102
105
|
};
|
|
103
106
|
if (silentFor != null && ACTIVE_RUNTIME_STAGES.has(stage)) out.silent_for = silentFor;
|
|
104
107
|
if (watchdog) out.watchdog = watchdog;
|
|
108
|
+
// The tool's own silence: the activity heartbeat keeps `silent_for` fresh
|
|
109
|
+
// while a tool runs, so a wait on a job that prints nothing needs its own clock.
|
|
110
|
+
if (toolSilence && stage === 'tool_running') {
|
|
111
|
+
out.tool_silent_for = `${formatToolSilence(toolSilence.silentMs)} (shell job ${toolSilence.taskId} no output)`;
|
|
112
|
+
}
|
|
105
113
|
if (queued != null) out.queued_followups = queued;
|
|
106
114
|
return out;
|
|
107
115
|
}
|
|
@@ -150,7 +158,21 @@ function describeLastProgress({ stage, snapshot, runtime, silentFor, lastToolCal
|
|
|
150
158
|
return stage;
|
|
151
159
|
}
|
|
152
160
|
|
|
153
|
-
function
|
|
161
|
+
function formatToolSilence(ms) {
|
|
162
|
+
return formatDuration(ms, { mostSignificantOnly: true }) || '0s';
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function describeAgentDiagnostic({
|
|
166
|
+
taskStatus,
|
|
167
|
+
sessionStatus,
|
|
168
|
+
stage,
|
|
169
|
+
snapshot,
|
|
170
|
+
silentFor,
|
|
171
|
+
queued,
|
|
172
|
+
policy,
|
|
173
|
+
now,
|
|
174
|
+
toolSilence,
|
|
175
|
+
}) {
|
|
154
176
|
const normalizedTask = cleanStage(taskStatus).toLowerCase();
|
|
155
177
|
if (normalizedTask === 'cancelled' || normalizedTask === 'canceled') return 'task cancelled';
|
|
156
178
|
if (normalizedTask === 'failed' || normalizedTask === 'error') return 'task failed';
|
|
@@ -158,6 +180,12 @@ function describeAgentDiagnostic({ taskStatus, sessionStatus, stage, snapshot, s
|
|
|
158
180
|
return sessionStatus === 'error' ? 'task completed (worker error)' : 'task completed; worker idle';
|
|
159
181
|
}
|
|
160
182
|
|
|
183
|
+
// Stalled for notification purposes, never aborted: a quiet job can be a
|
|
184
|
+
// legitimate build, so the Lead is told and decides.
|
|
185
|
+
if (toolSilence?.hung && stage === 'tool_running') {
|
|
186
|
+
return `tool possibly hung: shell job ${toolSilence.taskId} no output for ${formatToolSilence(toolSilence.silentMs)}; inspect or cancel it`;
|
|
187
|
+
}
|
|
188
|
+
|
|
161
189
|
if (queued) {
|
|
162
190
|
if (ACTIVE_RUNTIME_STAGES.has(stage)) {
|
|
163
191
|
return `${stage}, ${queued} follow-up${queued === 1 ? '' : 's'} queued`;
|
|
@@ -83,7 +83,12 @@ export function createCloseFlow({ mgr, registry, views }) {
|
|
|
83
83
|
// below is an idempotent no-op fallback once terminal.
|
|
84
84
|
// Closing a runtime cancels its work; only explicit session deletion
|
|
85
85
|
// may tombstone the conversation.
|
|
86
|
-
|
|
86
|
+
// An owner's close (not a process exit's) is recorded on the session itself,
|
|
87
|
+
// so a later reuse of its reaped tag never continues it.
|
|
88
|
+
const ok = await closeManagedSession(mgr, sessionId, 'cli-agent-close', {
|
|
89
|
+
tombstone: false,
|
|
90
|
+
...(keepRow ? {} : { ownerClose: true }),
|
|
91
|
+
});
|
|
87
92
|
if (task?.taskId) cancelBackgroundTask(task.taskId, CLOSE_REASON);
|
|
88
93
|
// Drop the row only once the cancellation is DURABLY recorded: a failed
|
|
89
94
|
// close that still forgot the row would leave no cancelled state behind.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import {
|
|
3
|
+
callerSessionForContext,
|
|
4
|
+
clean,
|
|
5
|
+
isExistingDirectory,
|
|
6
|
+
normalizeAgentName,
|
|
7
|
+
resolvePrompt,
|
|
8
|
+
terminalPidForContext,
|
|
9
|
+
} from './helpers.mjs';
|
|
10
|
+
|
|
11
|
+
// Continuing a reaped tag's own saved session: the prompt is appended to the
|
|
12
|
+
// stored transcript as one more turn (nothing earlier is rewritten), so the
|
|
13
|
+
// worker keeps its context and a provider's prompt cache keeps its prefix.
|
|
14
|
+
//
|
|
15
|
+
// Inputs: `registry` (resumable-session reads, tag binding, tombstones),
|
|
16
|
+
// `sendFlow` (the existing-session dispatch) and `defaultCwd`. Output:
|
|
17
|
+
// { serialized, resumeTag }; one instance is shared by `send` and `spawn`.
|
|
18
|
+
export function createTagResume({ registry, sendFlow, defaultCwd }) {
|
|
19
|
+
const inFlight = new Map(); // owner scope + tag -> tail promise
|
|
20
|
+
|
|
21
|
+
/** Runs `run` after every earlier call for this owner's `tag` settled, so
|
|
22
|
+
* a competing send or spawn sees the tag the first one resumed (or
|
|
23
|
+
* respawned) instead of resuming it a second time. */
|
|
24
|
+
function serialized(tag, context, run) {
|
|
25
|
+
const owner = callerSessionForContext(context) || `pid:${terminalPidForContext(context) || 0}`;
|
|
26
|
+
const key = `${owner}\0${tag}`;
|
|
27
|
+
const previous = inFlight.get(key) || Promise.resolve();
|
|
28
|
+
const current = previous.then(run, run);
|
|
29
|
+
const tail = current.then(
|
|
30
|
+
() => {},
|
|
31
|
+
() => {}
|
|
32
|
+
);
|
|
33
|
+
inFlight.set(key, tail);
|
|
34
|
+
tail.then(() => {
|
|
35
|
+
if (inFlight.get(key) === tail) inFlight.delete(key);
|
|
36
|
+
});
|
|
37
|
+
return current;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// A request naming another agent or directory asks for different work than
|
|
41
|
+
// the saved session did; that gets a fresh session instead.
|
|
42
|
+
function requestFits(session, args, callerCwd) {
|
|
43
|
+
const agent = clean(args.agent);
|
|
44
|
+
if (agent && normalizeAgentName(agent) !== normalizeAgentName(session.agent)) return false;
|
|
45
|
+
const cwd = clean(args.cwd);
|
|
46
|
+
if (!cwd) return true;
|
|
47
|
+
return Boolean(clean(session.cwd)) && resolve(callerCwd || defaultCwd, cwd) === resolve(clean(session.cwd));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// The saved working directory is gone: a fresh session may start only in a
|
|
51
|
+
// directory the caller names that exists, never in the missing one.
|
|
52
|
+
async function refuseMissingCwd(operation, tag, missingCwd, args, callerCwd) {
|
|
53
|
+
const named = clean(args.cwd) ? resolve(callerCwd || defaultCwd, clean(args.cwd)) : '';
|
|
54
|
+
if (named && (await isExistingDirectory(named))) return;
|
|
55
|
+
const gone = missingCwd ? `"${missingCwd}"` : '(unknown)';
|
|
56
|
+
throw new Error(
|
|
57
|
+
`agent ${operation}: tag "${tag}" cannot continue: its working directory ${gone} no longer exists` +
|
|
58
|
+
`${named ? ` and cwd "${named}" is not a directory` : ''}; pass an existing cwd to start a fresh session there`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Dispatches `args` onto `sessionId` under `tag` and returns the rendered
|
|
63
|
+
* result, or null when that session cannot be resumed for this caller (the
|
|
64
|
+
* caller then starts a fresh session). Throws when only its working
|
|
65
|
+
* directory is gone and the caller named no existing one. A consumed
|
|
66
|
+
* `tombstone` is the reap record the resume replaces. Call inside
|
|
67
|
+
* `serialized` for this tag. */
|
|
68
|
+
async function resumeTag(
|
|
69
|
+
tag,
|
|
70
|
+
sessionId,
|
|
71
|
+
{ operation, args, callerCwd, context, notifyContext, tombstone = null, route = null }
|
|
72
|
+
) {
|
|
73
|
+
const found = await registry.resumableTagSession(tag, sessionId, context);
|
|
74
|
+
if (!found) return null;
|
|
75
|
+
if (!found.session) {
|
|
76
|
+
await refuseMissingCwd(operation, tag, found.missingCwd, args, callerCwd);
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const { session } = found;
|
|
80
|
+
if (!requestFits(session, args, callerCwd)) return null;
|
|
81
|
+
const prompt = await resolvePrompt(args, session.cwd || defaultCwd);
|
|
82
|
+
const prepared = { args: { ...args, tag }, session, sessionId: session.id, prompt, ...(route ? { route } : {}) };
|
|
83
|
+
await sendFlow.adoptCaller(prepared, notifyContext);
|
|
84
|
+
const result = await sendFlow.dispatchToExistingSession(prepared, notifyContext, { resumed: true });
|
|
85
|
+
// Only once the turn was admitted on the session: the tag resolves to it
|
|
86
|
+
// again (its row is stamped fresh, so nothing ages it out before the turn
|
|
87
|
+
// writes its own), and the reap record goes.
|
|
88
|
+
registry.bindTag(tag, session, { turnStartedAt: new Date().toISOString() });
|
|
89
|
+
if (tombstone) registry.consumeTagTombstone(tombstone);
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return { serialized, resumeTag };
|
|
94
|
+
}
|
|
@@ -1,18 +1,30 @@
|
|
|
1
|
+
import { createTagResume } from './execute-resume.mjs';
|
|
1
2
|
import { clean, resolvePrompt } from './helpers.mjs';
|
|
2
3
|
|
|
3
|
-
// Tag-addressed send, including the dead-tag
|
|
4
|
-
// `send` request type needs once the
|
|
4
|
+
// Tag-addressed send, including the dead-tag fallback (resume the saved
|
|
5
|
+
// session, else respawn): everything the `send` request type needs once the
|
|
6
|
+
// caller's scope is resolved.
|
|
5
7
|
//
|
|
6
|
-
// Inputs: `registry` (tag maps, worker rows, tombstones),
|
|
7
|
-
// `sendFlow`, `spawnFlow`,
|
|
8
|
-
// Output: { send }.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
// Inputs: `registry` (tag maps, worker rows, tombstones, session records),
|
|
9
|
+
// `defaultCwd`, `sendFlow`, `spawnFlow`, `spawnResult` (job -> rendered tool
|
|
10
|
+
// output) and `tagResume` (shared with spawn). Output: { send }.
|
|
11
|
+
const isDeadTarget = (err) => /not found|is closed/i.test(String(err?.message || ''));
|
|
12
|
+
|
|
13
|
+
export function createSendDispatch({
|
|
14
|
+
registry,
|
|
15
|
+
defaultCwd,
|
|
16
|
+
sendFlow,
|
|
17
|
+
spawnFlow,
|
|
18
|
+
spawnResult,
|
|
19
|
+
tagResume = createTagResume({ registry, sendFlow, defaultCwd }),
|
|
20
|
+
}) {
|
|
21
|
+
// A retained row, a reap tombstone, or (once a pruned row's tombstone has
|
|
22
|
+
// expired or been capped out) the tag's own session record proves that this
|
|
23
|
+
// terminal owned the tag. Unknown tags stay errors even when the caller
|
|
24
|
+
// supplies an agent/cwd: typo absorption requires persisted same-tag
|
|
25
|
+
// evidence. Absorption identity is always terminal-local, even when live
|
|
26
|
+
// resolution was explicitly requested across all terminals; a local proof
|
|
27
|
+
// wins even if another terminal also owns this tag.
|
|
16
28
|
function inheritedTagIdentity(fallbackTag, ownershipContext, args, callerCwd) {
|
|
17
29
|
let row = null;
|
|
18
30
|
try {
|
|
@@ -21,11 +33,19 @@ export function createSendDispatch({ registry, defaultCwd, sendFlow, spawnFlow,
|
|
|
21
33
|
row = null;
|
|
22
34
|
}
|
|
23
35
|
const tombstone = registry.tagTombstoneForTag(fallbackTag, ownershipContext);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
36
|
+
const record = row || tombstone ? null : registry.lastTagSession(fallbackTag, ownershipContext);
|
|
37
|
+
if (!row && !tombstone && !record) return null;
|
|
38
|
+
const agent = clean(args.agent) || clean(row?.agent) || clean(tombstone?.agent) || clean(record?.agent);
|
|
39
|
+
const cwd = clean(args.cwd) || clean(row?.cwd) || clean(tombstone?.cwd) || clean(record?.cwd) || clean(callerCwd);
|
|
27
40
|
if (!agent || !cwd) return null;
|
|
28
|
-
return {
|
|
41
|
+
return {
|
|
42
|
+
row,
|
|
43
|
+
tombstone,
|
|
44
|
+
sessionId: clean(row?.sessionId),
|
|
45
|
+
resumeSessionId: clean(row?.sessionId) || clean(tombstone?.sessionId) || clean(record?.id),
|
|
46
|
+
agent,
|
|
47
|
+
cwd,
|
|
48
|
+
};
|
|
29
49
|
}
|
|
30
50
|
|
|
31
51
|
// Drop this terminal's in-memory trace and remove ONLY the persisted row
|
|
@@ -38,20 +58,45 @@ export function createSendDispatch({ registry, defaultCwd, sendFlow, spawnFlow,
|
|
|
38
58
|
if (inherited.tombstone) registry.consumeTagTombstone(inherited.tombstone);
|
|
39
59
|
}
|
|
40
60
|
|
|
41
|
-
// Dead-tag fallback: a same-scope follow-up can land after its
|
|
42
|
-
// closed or deleted.
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
|
|
61
|
+
// Dead-tag fallback: a same-scope follow-up can land after its tag was
|
|
62
|
+
// reaped, or after its session was closed or deleted. A reaped tag whose
|
|
63
|
+
// saved session is still stored and open continues that session (`resumed`,
|
|
64
|
+
// prior context kept). Otherwise, instead of bouncing an error back to Lead
|
|
65
|
+
// (who would just re-issue the same content as a spawn), respawn a FRESH
|
|
66
|
+
// session under the same tag with the message as its brief; `respawned:
|
|
67
|
+
// true` in the result tells Lead the worker has no prior session context.
|
|
68
|
+
// Only tag-addressed sends fall back; explicit sessionId sends keep erroring
|
|
69
|
+
// (the caller pinned a specific session on purpose).
|
|
70
|
+
async function respawnDeadTagSend(err, args, { scopedContext, callerCwd, context, notifyContext }) {
|
|
49
71
|
const fallbackTag = clean(args.tag);
|
|
50
|
-
|
|
51
|
-
|
|
72
|
+
if (!fallbackTag || fallbackTag.startsWith('sess_') || !isDeadTarget(err)) throw err;
|
|
73
|
+
return tagResume.serialized(fallbackTag, context, async () => {
|
|
74
|
+
// A competing send or spawn of this tag may have resumed or respawned
|
|
75
|
+
// it while this one waited: then this is an ordinary send to it.
|
|
76
|
+
let prepared = null;
|
|
77
|
+
try {
|
|
78
|
+
prepared = await sendFlow.prepareSend(args, scopedContext);
|
|
79
|
+
} catch (retryErr) {
|
|
80
|
+
if (!isDeadTarget(retryErr)) throw retryErr;
|
|
81
|
+
}
|
|
82
|
+
if (prepared) return dispatchPrepared(prepared, notifyContext);
|
|
83
|
+
return await resumeOrRespawn(err, fallbackTag, args, { callerCwd, context, notifyContext });
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function resumeOrRespawn(err, fallbackTag, args, { callerCwd, context, notifyContext }) {
|
|
52
88
|
const prompt = await resolvePrompt(args, callerCwd || defaultCwd);
|
|
53
89
|
const inherited = inheritedTagIdentity(fallbackTag, context, args, callerCwd);
|
|
54
90
|
if (!inherited) throw err;
|
|
91
|
+
const resumed = await tagResume.resumeTag(fallbackTag, inherited.resumeSessionId, {
|
|
92
|
+
operation: 'send',
|
|
93
|
+
args,
|
|
94
|
+
callerCwd,
|
|
95
|
+
context,
|
|
96
|
+
notifyContext,
|
|
97
|
+
tombstone: inherited.tombstone,
|
|
98
|
+
});
|
|
99
|
+
if (resumed) return resumed;
|
|
55
100
|
consumeInheritedTag(fallbackTag, inherited);
|
|
56
101
|
const spawnArgs = {
|
|
57
102
|
...args,
|
|
@@ -67,13 +112,18 @@ export function createSendDispatch({ registry, defaultCwd, sendFlow, spawnFlow,
|
|
|
67
112
|
);
|
|
68
113
|
}
|
|
69
114
|
|
|
115
|
+
async function dispatchPrepared(prepared, notifyContext) {
|
|
116
|
+
await sendFlow.adoptCaller(prepared, notifyContext);
|
|
117
|
+
return sendFlow.dispatchToExistingSession(prepared, notifyContext);
|
|
118
|
+
}
|
|
119
|
+
|
|
70
120
|
async function send(args, { scopedContext, callerCwd, context, notifyContext }) {
|
|
71
121
|
try {
|
|
72
122
|
const prepared = await sendFlow.prepareSend(args, scopedContext);
|
|
73
123
|
await sendFlow.adoptCaller(prepared, notifyContext);
|
|
74
124
|
return sendFlow.dispatchToExistingSession(prepared, notifyContext);
|
|
75
125
|
} catch (err) {
|
|
76
|
-
return await respawnDeadTagSend(err, args, { callerCwd, context, notifyContext });
|
|
126
|
+
return await respawnDeadTagSend(err, args, { scopedContext, callerCwd, context, notifyContext });
|
|
77
127
|
}
|
|
78
128
|
}
|
|
79
129
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createTagResume } from './execute-resume.mjs';
|
|
1
2
|
import { clean, rowMatchesContext } from './helpers.mjs';
|
|
2
3
|
import { resolveRequestedModel } from './model-select.mjs';
|
|
3
4
|
|
|
@@ -21,9 +22,10 @@ function requestedRoute(args) {
|
|
|
21
22
|
// Spawn request dispatch: deciding what an explicitly tagged spawn means before
|
|
22
23
|
// a job is started, and starting it.
|
|
23
24
|
//
|
|
24
|
-
// Inputs: `registry` (tag resolution, live sessions, tombstones
|
|
25
|
-
// `terminalTrace`, `sendFlow` (reuse path), `spawnFlow`,
|
|
26
|
-
// (job -> rendered tool output)
|
|
25
|
+
// Inputs: `registry` (tag resolution, live sessions, tombstones, session
|
|
26
|
+
// records), `terminalTrace`, `sendFlow` (reuse path), `spawnFlow`,
|
|
27
|
+
// `spawnResult` (job -> rendered tool output), `defaultCwd` and `tagResume`
|
|
28
|
+
// (shared with send). Output: { spawn }.
|
|
27
29
|
export function createSpawnDispatch({
|
|
28
30
|
registry,
|
|
29
31
|
terminalTrace,
|
|
@@ -31,13 +33,20 @@ export function createSpawnDispatch({
|
|
|
31
33
|
spawnFlow,
|
|
32
34
|
spawnResult,
|
|
33
35
|
listProviderModels = null,
|
|
36
|
+
defaultCwd = process.cwd(),
|
|
37
|
+
tagResume = createTagResume({ registry, sendFlow, defaultCwd }),
|
|
34
38
|
}) {
|
|
39
|
+
const { resumeTag } = tagResume;
|
|
40
|
+
|
|
35
41
|
// Explicit-tag spawn priority (auto nextTag always creates a fresh session):
|
|
36
42
|
// 1) live + busy -> queue the prompt (reuse)
|
|
37
43
|
// 2) live + idle -> continue existing session (reuse)
|
|
38
44
|
// 3) lingering terminal trace -> reap trace and fresh spawn under same tag
|
|
39
|
-
// 4)
|
|
40
|
-
|
|
45
|
+
// 4) reaped tag (tombstone, or past it this owner's last session record)
|
|
46
|
+
// whose saved session can continue -> resume it; a tombstone whose
|
|
47
|
+
// session cannot -> fresh spawn inheriting agent/cwd (`respawned`)
|
|
48
|
+
// 5) genuinely new tag -> fresh deferred spawn
|
|
49
|
+
async function resolveExplicitTagSpawn(explicitTag, args, { scopedContext, context, notifyContext, callerCwd }) {
|
|
41
50
|
let liveSessionId = null;
|
|
42
51
|
try {
|
|
43
52
|
liveSessionId = registry.resolveTag(explicitTag, scopedContext, {
|
|
@@ -63,9 +72,12 @@ export function createSpawnDispatch({
|
|
|
63
72
|
terminalTrace.reapTerminalTraceForTag(explicitTag, scopedContext);
|
|
64
73
|
return { spawnArgs: args, respawned: true };
|
|
65
74
|
}
|
|
66
|
-
// Tombstone inheritance never
|
|
75
|
+
// Tombstone inheritance and resume never honor allTerminals/global scope.
|
|
76
|
+
const resumeOptions = { operation: 'spawn', args, callerCwd, context, notifyContext, route: requestedRoute(args) };
|
|
67
77
|
const tombstone = registry.tagTombstoneForTag(explicitTag, context);
|
|
68
78
|
if (tombstone) {
|
|
79
|
+
const resumed = await resumeTag(explicitTag, tombstone.sessionId, { ...resumeOptions, tombstone });
|
|
80
|
+
if (resumed) return { reused: resumed };
|
|
69
81
|
registry.consumeTagTombstone(tombstone);
|
|
70
82
|
return {
|
|
71
83
|
spawnArgs: {
|
|
@@ -80,6 +92,11 @@ export function createSpawnDispatch({
|
|
|
80
92
|
.readAllTagTombstones()
|
|
81
93
|
.find((row) => clean(row.tag) === explicitTag && !rowMatchesContext(row, context));
|
|
82
94
|
if (foreignTombstone) throw new Error(`agent spawn: tag "${explicitTag}" belongs to another terminal`);
|
|
95
|
+
const record = registry.lastTagSession(explicitTag, context);
|
|
96
|
+
if (record) {
|
|
97
|
+
const resumed = await resumeTag(explicitTag, record.id, resumeOptions);
|
|
98
|
+
if (resumed) return { reused: resumed };
|
|
99
|
+
}
|
|
83
100
|
return { spawnArgs: args, respawned: false };
|
|
84
101
|
}
|
|
85
102
|
|
|
@@ -91,7 +108,11 @@ export function createSpawnDispatch({
|
|
|
91
108
|
let spawnArgs = args;
|
|
92
109
|
let respawned = false;
|
|
93
110
|
if (explicitTag) {
|
|
94
|
-
|
|
111
|
+
// One decision at a time per owner's tag: a spawn queued behind a send
|
|
112
|
+
// or spawn that resumed this tag reuses it instead of resuming it again.
|
|
113
|
+
const plan = await tagResume.serialized(explicitTag, request.context, () =>
|
|
114
|
+
resolveExplicitTagSpawn(explicitTag, args, request)
|
|
115
|
+
);
|
|
95
116
|
if (plan.reused) return plan.reused;
|
|
96
117
|
spawnArgs = plan.spawnArgs;
|
|
97
118
|
respawned = plan.respawned;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { errorLine } from '../../../runtime/shared/err-text.mjs';
|
|
2
2
|
import { createSendDispatch } from './execute-send.mjs';
|
|
3
3
|
import { createSpawnDispatch } from './execute-spawn.mjs';
|
|
4
|
+
import { createTagResume } from './execute-resume.mjs';
|
|
4
5
|
import { agentScope, clean } from './helpers.mjs';
|
|
5
6
|
import { renderResult } from './render.mjs';
|
|
6
7
|
|
|
@@ -30,7 +31,9 @@ export function createAgentExecute({
|
|
|
30
31
|
return renderResult(views.renderJob(job, true));
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
// Shared so a send and a spawn of one reaped tag are serialized together.
|
|
35
|
+
const tagResume = createTagResume({ registry, sendFlow, defaultCwd });
|
|
36
|
+
const { send } = createSendDispatch({ registry, defaultCwd, sendFlow, spawnFlow, spawnResult, tagResume });
|
|
34
37
|
const { spawn } = createSpawnDispatch({
|
|
35
38
|
registry,
|
|
36
39
|
terminalTrace,
|
|
@@ -38,6 +41,8 @@ export function createAgentExecute({
|
|
|
38
41
|
spawnFlow,
|
|
39
42
|
spawnResult,
|
|
40
43
|
listProviderModels,
|
|
44
|
+
defaultCwd,
|
|
45
|
+
tagResume,
|
|
41
46
|
});
|
|
42
47
|
|
|
43
48
|
return async function execute(args = {}, context = {}) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Dependency-light helpers for the agent-tool facade.
|
|
2
2
|
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { stat } from 'node:fs/promises';
|
|
3
4
|
import { isAbsolute, join, resolve } from 'node:path';
|
|
4
5
|
import {
|
|
5
6
|
normalizeAgentPermissionOrNone,
|
|
@@ -67,6 +68,16 @@ export function runtimeAlive(pid) {
|
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
/** Whether `path` is an existing directory (probed without blocking). */
|
|
72
|
+
export async function isExistingDirectory(path) {
|
|
73
|
+
if (!clean(path)) return false;
|
|
74
|
+
try {
|
|
75
|
+
return (await stat(path)).isDirectory();
|
|
76
|
+
} catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
70
81
|
export function agentTagOf(session) {
|
|
71
82
|
return clean(session?.agentTag);
|
|
72
83
|
}
|
|
@@ -67,16 +67,19 @@ export function createJobRender({ progress }) {
|
|
|
67
67
|
|
|
68
68
|
function renderJob(job, includeResult = false) {
|
|
69
69
|
const meta = job.meta || {};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
:
|
|
79
|
-
|
|
70
|
+
let reapNote = {};
|
|
71
|
+
if (meta.respawned === true) {
|
|
72
|
+
reapNote = {
|
|
73
|
+
respawned: true,
|
|
74
|
+
note: 'previous session reaped — fresh session, no prior context; re-supply anchors if needed',
|
|
75
|
+
};
|
|
76
|
+
} else if (meta.resumed === true) {
|
|
77
|
+
reapNote = {
|
|
78
|
+
resumed: true,
|
|
79
|
+
note: 'previous session reaped — resumed from its saved transcript, prior context kept',
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const head = jobHead({ ...job, type: job.operation }, meta, reapNote);
|
|
80
83
|
const tail = includeResult && job.result !== undefined ? { result: job.result } : {};
|
|
81
84
|
// Frozen terminal view: never re-read the (possibly reused) live session.
|
|
82
85
|
if (isTerminalJobStatus(job.status)) {
|
|
@@ -6,6 +6,7 @@ import { buildAgentTaskProgressFields } from '../../agent-task-status.mjs';
|
|
|
6
6
|
import { getProgressWatchdogState } from '../../agent-watchdog-registry.mjs';
|
|
7
7
|
import { _liveSessions } from '../../../../runtime/agent/orchestrator/session/store/live-state.mjs';
|
|
8
8
|
import { todoProgress } from '../../../../runtime/agent/orchestrator/runtime-core/todo-list.mjs';
|
|
9
|
+
import { waitedJobSilence } from '../../../../runtime/agent/orchestrator/tools/builtin/lib/shell-output-silence.mjs';
|
|
9
10
|
|
|
10
11
|
// Job statuses that can never progress again (mirrors TERMINAL_STATUSES in
|
|
11
12
|
// runtime/shared/background-tasks.mjs; 'canceled' accepted defensively).
|
|
@@ -55,6 +56,7 @@ export function liveAgentStatusRow(row) {
|
|
|
55
56
|
if (todo) row = { ...row, todo };
|
|
56
57
|
const {
|
|
57
58
|
silent_for: _silentFor,
|
|
59
|
+
tool_silent_for: _toolSilentFor,
|
|
58
60
|
staleSeconds: _staleSeconds,
|
|
59
61
|
lastStreamDeltaAt: _lastStreamDeltaAt,
|
|
60
62
|
last_progress: _lastProgress,
|
|
@@ -95,6 +97,7 @@ export function createSessionProgress({ mgr }) {
|
|
|
95
97
|
queuedFollowups,
|
|
96
98
|
taskStatus,
|
|
97
99
|
lastToolCall: runtime?.lastToolCall || null,
|
|
100
|
+
toolSilence: runtime?.taskWaits > 0 ? waitedJobSilence(runtime.taskWaitJobIds, { now }) : null,
|
|
98
101
|
});
|
|
99
102
|
}
|
|
100
103
|
|