mixdog 0.9.152 → 0.9.154
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/LICENSES/browser-import-NOTICE.txt +11 -0
- package/NOTICE.md +11 -0
- package/README.md +8 -10
- package/package.json +19 -3
- package/scripts/computer-task-cost-report.mjs +144 -0
- package/scripts/run-office-live-tests.mjs +32 -0
- package/src/agents/front-worker/AGENT.md +13 -0
- package/src/agents/front-worker/agent.json +6 -0
- package/src/agents/heavy-worker/AGENT.md +10 -11
- package/src/agents/heavy-worker/agent.json +1 -1
- package/src/agents/maintainer/AGENT.md +0 -2
- package/src/agents/reviewer/AGENT.md +9 -13
- package/src/agents/reviewer/agent.json +1 -1
- package/src/agents/security/AGENT.md +14 -0
- package/src/agents/security/agent.json +6 -0
- package/src/agents/worker/AGENT.md +8 -8
- package/src/agents/worker/agent.json +1 -1
- package/src/agents/writer/AGENT.md +14 -0
- package/src/agents/writer/agent.json +6 -0
- package/src/rules/agent/00-common.md +4 -7
- package/src/rules/lead/01-general.md +0 -3
- package/src/rules/shared/10-tool-workflow.md +10 -2
- package/src/rules/shared/60-verification.md +2 -0
- package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch.mjs +183 -26
- package/src/runtime/agent/orchestrator/agent-runtime/session-builder.mjs +4 -0
- package/src/runtime/agent/orchestrator/cache-break-trace.mjs +109 -0
- package/src/runtime/agent/orchestrator/config.mjs +7 -2
- package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +16 -3
- package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +9 -1
- package/src/runtime/agent/orchestrator/providers/media-normalization.mjs +30 -9
- package/src/runtime/agent/orchestrator/providers/openai-codex-metadata.mjs +18 -26
- package/src/runtime/agent/orchestrator/providers/openai-oauth-http-sse.mjs +25 -2
- package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +103 -10
- package/src/runtime/agent/orchestrator/providers/openai-turn-state.mjs +68 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-delta.mjs +36 -11
- package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +140 -86
- package/src/runtime/agent/orchestrator/providers/openai-ws-stream.mjs +9 -13
- package/src/runtime/agent/orchestrator/session/agent-loop.mjs +72 -4
- package/src/runtime/agent/orchestrator/session/browser-snapshot-supersession.mjs +61 -0
- package/src/runtime/agent/orchestrator/session/compact/handoff.mjs +0 -22
- package/src/runtime/agent/orchestrator/session/compact/messages.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/compact/runner.mjs +11 -23
- package/src/runtime/agent/orchestrator/session/compact/summary.mjs +28 -269
- package/src/runtime/agent/orchestrator/session/compact.mjs +0 -6
- package/src/runtime/agent/orchestrator/session/context-utils.mjs +86 -11
- package/src/runtime/agent/orchestrator/session/eager-dispatch.mjs +17 -1
- package/src/runtime/agent/orchestrator/session/image-strip-recovery.mjs +12 -8
- package/src/runtime/agent/orchestrator/session/loop/compact-policy.mjs +110 -2
- package/src/runtime/agent/orchestrator/session/loop/pre-dispatch-deny.mjs +3 -16
- package/src/runtime/agent/orchestrator/session/loop/recall-fasttrack.mjs +80 -18
- package/src/runtime/agent/orchestrator/session/loop/steering.mjs +6 -0
- package/src/runtime/agent/orchestrator/session/loop/tool-exec.mjs +3 -0
- package/src/runtime/agent/orchestrator/session/loop/tool-helpers.mjs +6 -0
- package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +80 -21
- package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +33 -72
- package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +21 -2
- package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +25 -51
- package/src/runtime/agent/orchestrator/session/manager/status-telemetry.mjs +3 -0
- package/src/runtime/agent/orchestrator/session/manager/tool-resolution.mjs +4 -110
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.mjs +39 -15
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint.mjs +14 -4
- package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +41 -8
- package/src/runtime/agent/orchestrator/session/provider-prefix-guard.mjs +129 -12
- package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/store/listing.mjs +8 -1
- package/src/runtime/agent/orchestrator/session/store/save-worker.mjs +15 -1
- package/src/runtime/agent/orchestrator/session/store-summary-index.mjs +36 -2
- package/src/runtime/agent/orchestrator/session/store-summary-reader.mjs +157 -30
- package/src/runtime/agent/orchestrator/session/store-summary-visibility.mjs +57 -0
- package/src/runtime/agent/orchestrator/session/store.mjs +3 -1
- package/src/runtime/agent/orchestrator/session/tool-batch.mjs +22 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-special-files.mjs +6 -6
- package/src/runtime/agent/orchestrator/tools/progress-message.mjs +4 -0
- package/src/runtime/attachments/pdf-extract.mjs +3 -0
- package/src/runtime/attachments/pdfjs-runtime.mjs +13 -0
- package/src/runtime/browser-bridge/action-schema.mjs +251 -0
- package/src/runtime/browser-bridge/client.mjs +75 -26
- package/src/runtime/browser-bridge/tool-defs.mjs +132 -15
- package/src/runtime/computer-bridge/action-schema.mjs +653 -0
- package/src/runtime/computer-bridge/client.mjs +211 -28
- package/src/runtime/computer-bridge/tool-defs.mjs +25 -45
- package/src/runtime/office/assurance-benchmark.mjs +358 -0
- package/src/runtime/office/assurance.mjs +833 -0
- package/src/runtime/office/benchmark.mjs +496 -0
- package/src/runtime/office/capabilities.mjs +551 -0
- package/src/runtime/office/com-adapter.mjs +283 -0
- package/src/runtime/office/content-model.mjs +183 -0
- package/src/runtime/office/contract-benchmark.mjs +105 -0
- package/src/runtime/office/design-library.mjs +1562 -0
- package/src/runtime/office/design-system.mjs +1966 -0
- package/src/runtime/office/index.mjs +2413 -0
- package/src/runtime/office/journal.mjs +82 -0
- package/src/runtime/office/office-com-host.ps1 +3781 -0
- package/src/runtime/office/office-com-session-host.ps1 +855 -0
- package/src/runtime/office/ooxml-validator.mjs +271 -0
- package/src/runtime/office/pagination.mjs +132 -0
- package/src/runtime/office/pdf-adapter.mjs +591 -0
- package/src/runtime/office/pdf-analysis.mjs +372 -0
- package/src/runtime/office/pdf-render.mjs +167 -0
- package/src/runtime/office/pdf-security.mjs +63 -0
- package/src/runtime/office/polish-benchmark.mjs +190 -0
- package/src/runtime/office/portable-ooxml.mjs +1867 -0
- package/src/runtime/office/quality-live-benchmark.mjs +486 -0
- package/src/runtime/office/quality-pipeline.mjs +136 -0
- package/src/runtime/office/tabular.mjs +302 -0
- package/src/runtime/office/templates/mixdog-executive.pptx +0 -0
- package/src/runtime/office/templates/mixdog-executive.pptx.mixdog.json +190 -0
- package/src/runtime/office/tool-defs.mjs +113 -0
- package/src/runtime/office/visual-diff.mjs +89 -0
- package/src/runtime/office/xlsx-assertions.mjs +172 -0
- package/src/runtime/office/xlsx-contract.mjs +147 -0
- package/src/runtime/shared/agent-route-config.mjs +9 -0
- package/src/runtime/shared/tool-execution-contract.mjs +16 -0
- package/src/runtime/shared/tool-surface.mjs +9 -0
- package/src/session-runtime/context-status.mjs +9 -3
- package/src/session-runtime/deferred-tool-delta.mjs +104 -0
- package/src/session-runtime/goal-runtime.mjs +617 -197
- package/src/session-runtime/lifecycle-api.mjs +50 -8
- package/src/session-runtime/provider-request-snapshot.mjs +33 -9
- package/src/session-runtime/resource-api.mjs +31 -94
- package/src/session-runtime/runtime-core.mjs +78 -26
- package/src/session-runtime/session-lifecycle.mjs +34 -12
- package/src/session-runtime/session-title.mjs +2 -2
- package/src/session-runtime/session-turn-api.mjs +15 -14
- package/src/session-runtime/tool-catalog-data.mjs +1 -1
- package/src/session-runtime/tool-catalog.mjs +38 -99
- package/src/session-runtime/tool-defs.mjs +6 -1
- package/src/session-runtime/tool-surface.mjs +18 -8
- package/src/session-runtime/workflow-agents-api.mjs +8 -25
- package/src/session-runtime/workflow.mjs +8 -6
- package/src/standalone/agent-tool/helpers.mjs +2 -2
- package/src/standalone/agent-tool/job-views.mjs +3 -1
- package/src/standalone/agent-tool/notify.mjs +5 -1
- package/src/standalone/agent-tool/render.mjs +3 -0
- package/src/standalone/agent-tool/spawn-flow.mjs +61 -16
- package/src/standalone/agent-tool/tool-def.mjs +1 -1
- package/src/standalone/agent-tool/worker-index.mjs +123 -0
- package/src/standalone/agent-tool/worker-rows.mjs +2 -1
- package/src/standalone/agent-tool.mjs +57 -10
- package/src/standalone/daemon.mjs +105 -6
- package/src/standalone/session-runtime-host.mjs +61 -48
- package/src/standalone/session-runtime-inline-host.mjs +34 -127
- package/src/standalone/session-runtime-worker.mjs +20 -198
- package/src/standalone/session-service.mjs +632 -7
- package/src/tui/dist/index.mjs +24 -1
- package/src/tui/lib/voice-setup.mjs +4 -1
- package/src/tui/session/context-state.mjs +2 -13
- package/src/tui/session/goal-continuation.mjs +38 -7
- package/src/tui/session/session-api-ext.mjs +9 -0
- package/src/tui/session/session-api.mjs +15 -1
- package/src/tui/session/session-flow.mjs +25 -1
- package/src/tui/session/turn.mjs +88 -16
- package/src/tui/session-local.mjs +25 -3
- package/src/vendor/statusline/src/gateway/route-meta.mjs +31 -0
- package/scripts/generate-voice-runtime-manifest.test.mjs +0 -135
- package/scripts/native-binary-arch.test.mjs +0 -111
- package/scripts/patch-replay.test.mjs +0 -94
- package/src/headless-exec.test.mjs +0 -539
- package/src/runtime/agent/orchestrator/agent-trace-timing.test.mjs +0 -57
- package/src/runtime/agent/orchestrator/context/collect-skills.test.mjs +0 -153
- package/src/runtime/agent/orchestrator/mcp/cancellation.test.mjs +0 -139
- package/src/runtime/agent/orchestrator/mcp/features.test.mjs +0 -66
- package/src/runtime/agent/orchestrator/mcp/security.test.mjs +0 -80
- package/src/runtime/agent/orchestrator/providers/anthropic-fast-mode.test.mjs +0 -90
- package/src/runtime/agent/orchestrator/providers/anthropic-server-fallback.test.mjs +0 -215
- package/src/runtime/agent/orchestrator/providers/antigravity-oauth.test.mjs +0 -165
- package/src/runtime/agent/orchestrator/providers/media-parity.test.mjs +0 -142
- package/src/runtime/agent/orchestrator/providers/openai-codex-identity.test.mjs +0 -153
- package/src/runtime/agent/orchestrator/providers/openai-codex-model.test.mjs +0 -24
- package/src/runtime/agent/orchestrator/providers/openai-ws-delta-parity.test.mjs +0 -190
- package/src/runtime/agent/orchestrator/providers/provider-replay.test.mjs +0 -235
- package/src/runtime/agent/orchestrator/providers/sse-framing.test.mjs +0 -719
- package/src/runtime/agent/orchestrator/session/cache/prefetch-cache.test.mjs +0 -40
- package/src/runtime/agent/orchestrator/session/compact-policy.test.mjs +0 -176
- package/src/runtime/agent/orchestrator/session/compaction-read-reset.test.mjs +0 -161
- package/src/runtime/agent/orchestrator/session/eager-dispatch.test.mjs +0 -115
- package/src/runtime/agent/orchestrator/session/evidence-union.test.mjs +0 -228
- package/src/runtime/agent/orchestrator/session/image-strip-recovery.test.mjs +0 -245
- package/src/runtime/agent/orchestrator/session/lossless-tool-output.test.mjs +0 -125
- package/src/runtime/agent/orchestrator/session/manager/pending-messages-persistence.test.mjs +0 -325
- package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.test.mjs +0 -70
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.test.mjs +0 -457
- package/src/runtime/agent/orchestrator/session/provider-prefix-guard.test.mjs +0 -117
- package/src/runtime/agent/orchestrator/session/reduction-metrics.test.mjs +0 -87
- package/src/runtime/agent/orchestrator/session/store/serialize.test.mjs +0 -60
- package/src/runtime/agent/orchestrator/session/store-summary-reader.test.mjs +0 -583
- package/src/runtime/agent/orchestrator/session/task-wait-control.test.mjs +0 -78
- package/src/runtime/agent/orchestrator/tools/builtin/absence-absorption.test.mjs +0 -43
- package/src/runtime/agent/orchestrator/tools/builtin/absolute-glob-expand.test.mjs +0 -63
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool-cwd-env.test.mjs +0 -14
- package/src/runtime/agent/orchestrator/tools/builtin/edit-encoding-eol.test.mjs +0 -224
- package/src/runtime/agent/orchestrator/tools/builtin/edit-sequential-occupation.test.mjs +0 -224
- package/src/runtime/agent/orchestrator/tools/builtin/enoent-outside-project.test.mjs +0 -56
- package/src/runtime/agent/orchestrator/tools/builtin/find-search-budget.test.mjs +0 -103
- package/src/runtime/agent/orchestrator/tools/builtin/git-command-policy.test.mjs +0 -30
- package/src/runtime/agent/orchestrator/tools/builtin/git-command-tool.test.mjs +0 -390
- package/src/runtime/agent/orchestrator/tools/builtin/git-repo-rw-lock.test.mjs +0 -83
- package/src/runtime/agent/orchestrator/tools/builtin/grep-output-budget.test.mjs +0 -31
- package/src/runtime/agent/orchestrator/tools/builtin/grep-single-file-rescue.test.mjs +0 -106
- package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-job-records.test.mjs +0 -102
- package/src/runtime/agent/orchestrator/tools/builtin/list-tool-integrity.test.mjs +0 -152
- package/src/runtime/agent/orchestrator/tools/builtin/native-search-health.test.mjs +0 -24
- package/src/runtime/agent/orchestrator/tools/builtin/native-search-transport.test.mjs +0 -24
- package/src/runtime/agent/orchestrator/tools/builtin/noise-dir-visibility.test.mjs +0 -69
- package/src/runtime/agent/orchestrator/tools/builtin/read-glob-survey.test.mjs +0 -71
- package/src/runtime/agent/orchestrator/tools/builtin/runtime-capabilities.test.mjs +0 -56
- package/src/runtime/agent/orchestrator/tools/builtin/search-builders.test.mjs +0 -16
- package/src/runtime/agent/orchestrator/tools/builtin/search-glob-top-k.test.mjs +0 -39
- package/src/runtime/agent/orchestrator/tools/builtin/write-symlink.test.mjs +0 -153
- package/src/runtime/agent/orchestrator/tools/code-graph/aggregate-anchor-relocation.test.mjs +0 -55
- package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.test.mjs +0 -88
- package/src/runtime/agent/orchestrator/tools/code-graph/loose-file-target.test.mjs +0 -72
- package/src/runtime/agent/orchestrator/tools/code-graph/memory-cache.test.mjs +0 -54
- package/src/runtime/agent/orchestrator/tools/code-graph/search-references.test.mjs +0 -20
- package/src/runtime/agent/orchestrator/tools/code-graph/symbol-search-scope.test.mjs +0 -55
- package/src/runtime/agent/orchestrator/tools/code-graph/text-span-mask.test.mjs +0 -268
- package/src/runtime/agent/orchestrator/tools/env-scrub.test.mjs +0 -57
- package/src/runtime/agent/orchestrator/tools/graph-binary-fetcher.test.mjs +0 -19
- package/src/runtime/agent/orchestrator/tools/lib/native-spawn-client.test.mjs +0 -104
- package/src/runtime/agent/orchestrator/tools/patch/engine-contract-gate.test.mjs +0 -661
- package/src/runtime/agent/orchestrator/tools/patch/patch-codec-eol.test.mjs +0 -552
- package/src/runtime/agent/orchestrator/tools/patch/patch-symlink.test.mjs +0 -141
- package/src/runtime/agent/orchestrator/tools/patch/v4a-pure-move.test.mjs +0 -57
- package/src/runtime/agent/orchestrator/tools/patch/v4a-section-coalesce.test.mjs +0 -81
- package/src/runtime/agent/orchestrator/tools/spawn-binary-fetcher.test.mjs +0 -52
- package/src/runtime/attachments/store.test.mjs +0 -209
- package/src/runtime/channels/lib/voice-runtime-fetcher.test.mjs +0 -17
- package/src/runtime/channels/lib/webhook/deliveries.test.mjs +0 -18
- package/src/runtime/channels/lib/webhook/relay-tunnel.test.mjs +0 -68
- package/src/runtime/media/adapters/codex-image.test.mjs +0 -22
- package/src/runtime/media/download.test.mjs +0 -52
- package/src/runtime/media/renditions.test.mjs +0 -99
- package/src/runtime/media/store.test.mjs +0 -159
- package/src/runtime/memory/lib/archive-security.test.mjs +0 -128
- package/src/runtime/memory/lib/embedding-model-config.test.mjs +0 -33
- package/src/runtime/memory/lib/http-wire.test.mjs +0 -15
- package/src/runtime/memory/lib/memory-cycle-packets.test.mjs +0 -49
- package/src/runtime/memory/lib/memory-cycle2-shared.test.mjs +0 -78
- package/src/runtime/memory/lib/memory-embedding-migration.test.mjs +0 -50
- package/src/runtime/memory/lib/pg/process.test.mjs +0 -36
- package/src/runtime/memory/lib/trace-store.test.mjs +0 -57
- package/src/runtime/memory/lib/transcript-ingest.test.mjs +0 -52
- package/src/runtime/shared/background-tasks.test.mjs +0 -78
- package/src/runtime/shared/bounded-download.test.mjs +0 -41
- package/src/runtime/shared/channel-notification-routing.test.mjs +0 -25
- package/src/runtime/shared/child-spawn-remote.test.mjs +0 -124
- package/src/runtime/shared/remote-intent.test.mjs +0 -40
- package/src/runtime/shared/resource-admission.test.mjs +0 -43
- package/src/runtime/shared/runtime-root.test.mjs +0 -34
- package/src/runtime/shared/schedule-time.test.mjs +0 -29
- package/src/runtime/shared/session-runtime-health.test.mjs +0 -83
- package/src/runtime/shared/skill-document.test.mjs +0 -81
- package/src/runtime/shared/tool-surface.test.mjs +0 -87
- package/src/runtime/shared/update-checker.test.mjs +0 -33
- package/src/runtime/shared/user-cwd.test.mjs +0 -43
- package/src/runtime/shared/webhook-session-run.test.mjs +0 -14
- package/src/session-runtime/agent-disable.test.mjs +0 -123
- package/src/session-runtime/cwd-plugins.test.mjs +0 -75
- package/src/session-runtime/cwd-tool-routing.test.mjs +0 -61
- package/src/session-runtime/global-extensions.test.mjs +0 -28
- package/src/session-runtime/goal-runtime.test.mjs +0 -108
- package/src/session-runtime/lifecycle-api.test.mjs +0 -21
- package/src/session-runtime/model-settings-persist.test.mjs +0 -105
- package/src/session-runtime/notification-bus.test.mjs +0 -148
- package/src/session-runtime/plugin-mcp-standard.test.mjs +0 -177
- package/src/session-runtime/prewarm.test.mjs +0 -52
- package/src/session-runtime/provider-request-snapshot.test.mjs +0 -37
- package/src/session-runtime/resource-api-global.test.mjs +0 -69
- package/src/session-runtime/session-lifecycle.test.mjs +0 -125
- package/src/session-runtime/session-title.test.mjs +0 -36
- package/src/session-runtime/skills-api.test.mjs +0 -99
- package/src/session-runtime/tool-policy-surface.test.mjs +0 -331
- package/src/standalone/agent-tool/helpers.test.mjs +0 -62
- package/src/standalone/agent-tool/notify.test.mjs +0 -37
- package/src/standalone/agent-tool/spawn-flow.test.mjs +0 -63
- package/src/standalone/channel-restart.test.mjs +0 -145
- package/src/standalone/channel-session-router.test.mjs +0 -37
- package/src/standalone/channel-worker-heartbeat.test.mjs +0 -30
- package/src/standalone/hook-bus/handlers.test.mjs +0 -88
- package/src/standalone/plugin-admin.test.mjs +0 -173
- package/src/standalone/session-runtime-agent-control-client.test.mjs +0 -71
- package/src/standalone/session-runtime-dispatch-cancel.test.mjs +0 -139
- package/src/standalone/session-runtime-host-factory.test.mjs +0 -31
- package/src/standalone/session-runtime-host-health.test.mjs +0 -160
- package/src/standalone/session-runtime-inline-host.test.mjs +0 -83
- package/src/standalone/session-runtime-provider-cooldown.test.mjs +0 -80
- package/src/standalone/session-runtime-shard-host.test.mjs +0 -569
- package/src/standalone/session-runtime-shard-router.test.mjs +0 -101
- package/src/tui/app/live-spinner-visibility.test.mjs +0 -44
- package/src/tui/app/panel-epoch.test.mjs +0 -1009
- package/src/tui/app/panel-handoff.test.mjs +0 -311
- package/src/tui/app/prompt-submit.test.mjs +0 -206
- package/src/tui/session/completion-card-restore.test.mjs +0 -111
- package/src/tui/session/goal-continuation.test.mjs +0 -84
- package/src/tui/session/oauth-flows.test.mjs +0 -134
- package/src/tui/session/queue-helpers.test.mjs +0 -46
- package/src/tui/session/session-action-surface.test.mjs +0 -108
- package/src/tui/session/task-wait-submit.test.mjs +0 -80
- package/src/tui/session/tool-result-status.test.mjs +0 -131
- package/src/tui/session/tui-steering-persist.test.mjs +0 -104
|
@@ -97,10 +97,13 @@ export function createStandaloneAgent({
|
|
|
97
97
|
mcpScopeId = null,
|
|
98
98
|
onSubagentEvent,
|
|
99
99
|
notifySessionCompletion,
|
|
100
|
+
sessionSurface = null,
|
|
100
101
|
awaitKeychainPrewarm = async () => {},
|
|
101
102
|
isKeychainPrewarmReady = () => true,
|
|
102
103
|
}) {
|
|
103
104
|
const mgr = baseMgr;
|
|
105
|
+
const canUseSessionSurface = (session) => typeof sessionSurface?.runTurn === 'function'
|
|
106
|
+
&& sessionSurface.canRun?.(session) !== false;
|
|
104
107
|
const statusListeners = new Set();
|
|
105
108
|
const notifyStatusChange = () => {
|
|
106
109
|
for (const listener of [...statusListeners]) {
|
|
@@ -118,6 +121,8 @@ export function createStandaloneAgent({
|
|
|
118
121
|
notifyContext?.callerSessionId
|
|
119
122
|
|| notifyContext?.sessionId
|
|
120
123
|
|| notifyContext?.routingSessionId
|
|
124
|
+
|| session?.parentSessionId
|
|
125
|
+
|| notifyContext?.ownerSessionId
|
|
121
126
|
|| session?.ownerSessionId,
|
|
122
127
|
);
|
|
123
128
|
const handle = beginAgentTurnReview(ownerSessionId, session?.id, { tag, agent });
|
|
@@ -230,6 +235,7 @@ export function createStandaloneAgent({
|
|
|
230
235
|
emitSubagentEvent,
|
|
231
236
|
notifyStatusChange,
|
|
232
237
|
notifySessionCompletion,
|
|
238
|
+
sessionSurface,
|
|
233
239
|
scheduleReap,
|
|
234
240
|
cfgMod,
|
|
235
241
|
dataDir,
|
|
@@ -288,11 +294,12 @@ export function createStandaloneAgent({
|
|
|
288
294
|
provider: session.provider,
|
|
289
295
|
model: session.model,
|
|
290
296
|
content: result?.content || '',
|
|
297
|
+
...(sessionSurface?.canonical === true ? { handoffOnly: true } : {}),
|
|
291
298
|
...(abnormalError ? { error: abnormalError } : {}),
|
|
292
299
|
};
|
|
293
300
|
};
|
|
294
301
|
handoffMsgStart = resolveHandoffMessageStartIndex(mgr.getSession(sessionId));
|
|
295
|
-
const
|
|
302
|
+
const turnHooks = {
|
|
296
303
|
notifyFn: workerNotifyFn(sessionId, notifyContext || {}),
|
|
297
304
|
onToolResult: (message) => turnReview.onToolResult(message),
|
|
298
305
|
...(job ? {
|
|
@@ -304,7 +311,24 @@ export function createStandaloneAgent({
|
|
|
304
311
|
reconcileJobTerminalResult(job, value);
|
|
305
312
|
},
|
|
306
313
|
} : {}),
|
|
307
|
-
}
|
|
314
|
+
};
|
|
315
|
+
const result = canUseSessionSurface(session)
|
|
316
|
+
? await sessionSurface.runTurn({
|
|
317
|
+
session,
|
|
318
|
+
prompt,
|
|
319
|
+
context: args.context || null,
|
|
320
|
+
cwd: session.cwd || defaultCwd,
|
|
321
|
+
...turnHooks,
|
|
322
|
+
})
|
|
323
|
+
: await mgr.askSession(
|
|
324
|
+
sessionId,
|
|
325
|
+
prompt,
|
|
326
|
+
args.context || null,
|
|
327
|
+
null,
|
|
328
|
+
session.cwd || defaultCwd,
|
|
329
|
+
null,
|
|
330
|
+
turnHooks,
|
|
331
|
+
);
|
|
308
332
|
// Early preview no longer suppresses the canonical body notification;
|
|
309
333
|
// notifyTaskCompletion fires once with output via resolve/reconcile.
|
|
310
334
|
const finalValue = completionValue(result);
|
|
@@ -359,7 +383,9 @@ export function createStandaloneAgent({
|
|
|
359
383
|
// live session (reuse path). Busy sessions queue the prompt; idle ones run a
|
|
360
384
|
// background send job that continues the existing session (context kept).
|
|
361
385
|
function dispatchToExistingSession(prepared, notifyContext, extras = {}) {
|
|
362
|
-
if (
|
|
386
|
+
if (!canUseSessionSurface(prepared.session)
|
|
387
|
+
&& isSessionBusy(prepared.sessionId)
|
|
388
|
+
&& typeof mgr.enqueuePendingMessage === 'function') {
|
|
363
389
|
const queueDepth = mgr.enqueuePendingMessage(prepared.sessionId, prepared.prompt);
|
|
364
390
|
return renderResult({
|
|
365
391
|
queued: true,
|
|
@@ -383,7 +409,7 @@ export function createStandaloneAgent({
|
|
|
383
409
|
return renderResult({ ...extras, ...renderJob(job, false) });
|
|
384
410
|
}
|
|
385
411
|
|
|
386
|
-
function close(args, context = {}) {
|
|
412
|
+
async function close(args, context = {}) {
|
|
387
413
|
const scopedContext = agentScope(args, context);
|
|
388
414
|
refreshTagsFromSessions({ scanSessions: wantsSessionScan(args), context: scopedContext });
|
|
389
415
|
const taskId = taskIdFromArgs(args);
|
|
@@ -415,6 +441,9 @@ export function createStandaloneAgent({
|
|
|
415
441
|
throw new Error(`agent close: target "${target}" is a Lead session`);
|
|
416
442
|
}
|
|
417
443
|
cancelReap(sessionId);
|
|
444
|
+
const descendantSessionIds = typeof mgr.descendantSessionIds === 'function'
|
|
445
|
+
? mgr.descendantSessionIds(sessionId)
|
|
446
|
+
: [];
|
|
418
447
|
const tag = tagForSession(sessionId);
|
|
419
448
|
clearAgentStatuslineRoute(sessionId);
|
|
420
449
|
// Cancel any running background task bound to this session BEFORE closing
|
|
@@ -430,13 +459,18 @@ export function createStandaloneAgent({
|
|
|
430
459
|
// Close (and stamp cancelStatus) BEFORE dropping the worker row. Removing
|
|
431
460
|
// the row first left the next pool read with only a leftover heartbeat,
|
|
432
461
|
// which republished the session as `running`.
|
|
433
|
-
const ok = mgr.closeSession(sessionId, 'cli-agent-close');
|
|
462
|
+
const ok = await mgr.closeSession(sessionId, 'cli-agent-close');
|
|
434
463
|
if (task?.taskId) cancelBackgroundTask(task.taskId, 'cancelled by agent close');
|
|
435
464
|
// Drop the row only once the cancellation is DURABLY recorded. A close that
|
|
436
465
|
// failed still forgot the row, leaving the next pool read with a fresh
|
|
437
466
|
// heartbeat and no cancelled state — which republished the session as
|
|
438
467
|
// `running`, the exact lingering row this whole path exists to prevent.
|
|
439
468
|
if (ok) forgetTerminalSession(tag, sessionId);
|
|
469
|
+
if (ok) {
|
|
470
|
+
for (const descendantSessionId of descendantSessionIds) {
|
|
471
|
+
removeWorkerRow({ sessionId: descendantSessionId });
|
|
472
|
+
}
|
|
473
|
+
}
|
|
440
474
|
return { closed: ok, tag, sessionId, task_id: task?.taskId || null };
|
|
441
475
|
}
|
|
442
476
|
|
|
@@ -455,7 +489,7 @@ export function createStandaloneAgent({
|
|
|
455
489
|
};
|
|
456
490
|
}
|
|
457
491
|
|
|
458
|
-
function closeAll(reason = 'cli-agent-close-all', scope = {}) {
|
|
492
|
+
async function closeAll(reason = 'cli-agent-close-all', scope = {}) {
|
|
459
493
|
// Scoped teardown (one Lead closing/deleting/switching) must close ONLY
|
|
460
494
|
// that Lead's workers: the worker index and task registry are shared by
|
|
461
495
|
// every Lead in the process, and the old unscoped sweep wiped sibling
|
|
@@ -467,7 +501,7 @@ export function createStandaloneAgent({
|
|
|
467
501
|
const failed = [];
|
|
468
502
|
for (const { tag, session } of agentSessionEntries({ scanSessions: false, context })) {
|
|
469
503
|
try {
|
|
470
|
-
closed.push(close({ sessionId: session.id }, context));
|
|
504
|
+
closed.push(await close({ sessionId: session.id }, context));
|
|
471
505
|
} catch (err) {
|
|
472
506
|
failed.push({ tag, error: presentErrorText(err, { surface: 'agent' }) });
|
|
473
507
|
}
|
|
@@ -538,12 +572,25 @@ export function createStandaloneAgent({
|
|
|
538
572
|
const callerCwd = clean(context.cwd || context.callerCwd);
|
|
539
573
|
const scopedContext = agentScope(args, context);
|
|
540
574
|
const notifyContext = context;
|
|
575
|
+
if (typeof mgr.rehydrateAgentSessions === 'function') {
|
|
576
|
+
await mgr.rehydrateAgentSessions();
|
|
577
|
+
// Rebuild tag ownership from canonical records even if a daemon crash
|
|
578
|
+
// happened before the auxiliary worker row was flushed.
|
|
579
|
+
refreshTagsFromSessions({ scanSessions: true, context: scopedContext });
|
|
580
|
+
}
|
|
541
581
|
if (type === 'list') return renderResult({ workers: list({ scanSessions: wantsSessionScan(args), context: scopedContext }), jobs: listJobs(scopedContext) });
|
|
542
582
|
if (type === 'status') return renderResult(renderJob(getJobOrWorker(args, scopedContext), false));
|
|
543
|
-
if (type === 'read')
|
|
583
|
+
if (type === 'read') {
|
|
584
|
+
const job = getJobOrWorker(args, scopedContext);
|
|
585
|
+
if (job?.taskId == null && typeof mgr.readSessionHandoff === 'function') {
|
|
586
|
+
const handoff = await mgr.readSessionHandoff(job.meta?.sessionId);
|
|
587
|
+
if (handoff) job.result = handoff;
|
|
588
|
+
}
|
|
589
|
+
return renderResult(renderJob(job, true));
|
|
590
|
+
}
|
|
544
591
|
if (type === 'cleanup') return renderResult(cleanup(args, scopedContext));
|
|
545
|
-
if (type === 'cancel') return renderResult(close(args, scopedContext));
|
|
546
|
-
if (type === 'close') return renderResult(close(args, scopedContext));
|
|
592
|
+
if (type === 'cancel') return renderResult(await close(args, scopedContext));
|
|
593
|
+
if (type === 'close') return renderResult(await close(args, scopedContext));
|
|
547
594
|
if (type === 'send') {
|
|
548
595
|
try {
|
|
549
596
|
const prepared = await prepareSend(args, scopedContext);
|
|
@@ -45,6 +45,7 @@ import { PLUGIN_LOG_MAX_BYTES, PLUGIN_LOG_KEEP_BYTES } from '../lib/mixdog-debug
|
|
|
45
45
|
import { setChannelNotifySink } from '../runtime/channels/lib/parent-bridge.mjs';
|
|
46
46
|
import { setOwnerContext } from '../runtime/channels/lib/runtime-paths.mjs';
|
|
47
47
|
import { safeIpcSend } from '../runtime/shared/safe-ipc-send.mjs';
|
|
48
|
+
import { releaseAllComputerSessions } from '../runtime/computer-bridge/client.mjs';
|
|
48
49
|
import { resourceAdmission } from '../runtime/shared/resource-admission.mjs';
|
|
49
50
|
import { snapshot as childSpawnSnapshot } from '../runtime/shared/child-spawn-gate.mjs';
|
|
50
51
|
import { toolWorkloadSnapshot } from '../runtime/shared/tool-workload-gates.mjs';
|
|
@@ -59,6 +60,10 @@ import { createChannelSessionRouter } from './channel-session-router.mjs';
|
|
|
59
60
|
import { createSessionTransport } from './session-transport.mjs';
|
|
60
61
|
import { createSessionService } from './session-service.mjs';
|
|
61
62
|
import { createSessionProtocolClient } from './session-protocol.mjs';
|
|
63
|
+
import {
|
|
64
|
+
listStoredActiveGoalSessionIds,
|
|
65
|
+
readStoredGoalSnapshot,
|
|
66
|
+
} from '../session-runtime/goal-runtime.mjs';
|
|
62
67
|
import { createDaemonSessionRuntimeHost } from './session-runtime-host-factory.mjs';
|
|
63
68
|
import { getStandaloneMemoryRuntime } from './memory-runtime-proxy.mjs';
|
|
64
69
|
import {
|
|
@@ -272,6 +277,10 @@ function eventLoopStatus() {
|
|
|
272
277
|
};
|
|
273
278
|
}
|
|
274
279
|
|
|
280
|
+
/** Ceiling for the whole teardown sequence, above the slowest individual stop
|
|
281
|
+
* (channels/memory) so a healthy shutdown always finishes on its own. */
|
|
282
|
+
const SHUTDOWN_BUDGET_MS = 15_000;
|
|
283
|
+
|
|
275
284
|
async function shutdown(reason, code = 0) {
|
|
276
285
|
if (shuttingDown) return;
|
|
277
286
|
shuttingDown = true;
|
|
@@ -280,9 +289,21 @@ async function shutdown(reason, code = 0) {
|
|
|
280
289
|
shutdownRecheckTimer = null;
|
|
281
290
|
}
|
|
282
291
|
log(`shutting down (${reason})`);
|
|
292
|
+
// Backstop: one wedged stop step must never keep the daemon — and with it the
|
|
293
|
+
// listening port, singleton claim and discovery file — alive. Unref'd so the
|
|
294
|
+
// clean path still exits the moment teardown finishes.
|
|
295
|
+
const forcedExit = setTimeout(() => {
|
|
296
|
+
log('shutdown budget exceeded, forcing exit');
|
|
297
|
+
process.exit(code);
|
|
298
|
+
}, SHUTDOWN_BUDGET_MS);
|
|
299
|
+
forcedExit.unref?.();
|
|
283
300
|
try { setChannelNotifySink(null); } catch {}
|
|
284
301
|
try { await sessionService?.stop?.(reason); } catch (e) { log(`session service stop failed: ${e?.message || e}`); }
|
|
285
302
|
try { await sessionRuntimeHost?.close?.(reason); } catch (e) { log(`session runtime host stop failed: ${e?.message || e}`); }
|
|
303
|
+
// Host-side Computer Use workers and target claims are reaped only on an
|
|
304
|
+
// explicit release; the runtime's deferred timer is unref'd and never fires
|
|
305
|
+
// once this process exits.
|
|
306
|
+
try { await releaseAllComputerSessions(); } catch (e) { log(`computer session release failed: ${e?.message || e}`); }
|
|
286
307
|
try { await localSessionBridge?.close?.(reason); } catch (e) { log(`local session bridge.close failed: ${e?.message || e}`); }
|
|
287
308
|
try { await sessionTransport?.stop?.(); } catch (e) { log(`session transport stop failed: ${e?.message || e}`); }
|
|
288
309
|
try { await channels?.stop?.(); } catch (e) { log(`channels.stop failed: ${e?.message || e}`); }
|
|
@@ -577,9 +598,59 @@ async function main() {
|
|
|
577
598
|
};
|
|
578
599
|
let sessionRuntimePrewarmStarted = false;
|
|
579
600
|
let sessionRuntimePrewarmPromise = null;
|
|
601
|
+
let canonicalAgentToolPromise = null;
|
|
602
|
+
function canonicalAgentTool() {
|
|
603
|
+
if (!sessionService) {
|
|
604
|
+
return Promise.reject(new Error('canonical session service is not ready'));
|
|
605
|
+
}
|
|
606
|
+
canonicalAgentToolPromise ??= Promise.all([
|
|
607
|
+
import('./agent-tool.mjs'),
|
|
608
|
+
import('../runtime/agent/orchestrator/config.mjs'),
|
|
609
|
+
import('../runtime/agent/orchestrator/providers/registry.mjs'),
|
|
610
|
+
]).then(([agentModule, cfgMod, reg]) => agentModule.createStandaloneAgent({
|
|
611
|
+
cfgMod,
|
|
612
|
+
reg,
|
|
613
|
+
mgr: sessionService.agentManager,
|
|
614
|
+
dataDir: cfgMod.getPluginData(),
|
|
615
|
+
cwd: CWD,
|
|
616
|
+
awaitKeychainPrewarm: async () => {},
|
|
617
|
+
isKeychainPrewarmReady: () => true,
|
|
618
|
+
sessionSurface: sessionService.agentSurface,
|
|
619
|
+
notifySessionCompletion(ownerSessionId, text, meta = {}) {
|
|
620
|
+
return sessionRuntimeHost?.notifySessionCompletion?.(ownerSessionId, text, meta) === true;
|
|
621
|
+
},
|
|
622
|
+
})).catch((error) => {
|
|
623
|
+
canonicalAgentToolPromise = null;
|
|
624
|
+
throw error;
|
|
625
|
+
});
|
|
626
|
+
return canonicalAgentToolPromise;
|
|
627
|
+
}
|
|
628
|
+
async function executeCanonicalAgentControl(args = {}, context = {}) {
|
|
629
|
+
const tool = await canonicalAgentTool();
|
|
630
|
+
const parentSessionId = String(context?.callerSessionId || '').trim();
|
|
631
|
+
await sessionService.rehydrateAgentSessions();
|
|
632
|
+
const scopedContext = {
|
|
633
|
+
...context,
|
|
634
|
+
callerSessionId: parentSessionId || null,
|
|
635
|
+
ownerSessionId: sessionService.rootOwnerSessionId(parentSessionId),
|
|
636
|
+
};
|
|
637
|
+
if (String(args?.type || '') === '__close_all') {
|
|
638
|
+
await tool.closeAll?.(
|
|
639
|
+
String(args?.reason || 'agent owner closed'),
|
|
640
|
+
{ callerSessionId: parentSessionId || null },
|
|
641
|
+
);
|
|
642
|
+
await sessionService.cancelAgentDescendants(
|
|
643
|
+
parentSessionId,
|
|
644
|
+
String(args?.reason || 'agent owner closed'),
|
|
645
|
+
);
|
|
646
|
+
return 'agent close all: ok';
|
|
647
|
+
}
|
|
648
|
+
return await tool.execute(args, scopedContext);
|
|
649
|
+
}
|
|
580
650
|
sessionRuntimeHost = createDaemonSessionRuntimeHost({
|
|
581
651
|
cwd: CWD,
|
|
582
652
|
log,
|
|
653
|
+
executeAgentControl: executeCanonicalAgentControl,
|
|
583
654
|
});
|
|
584
655
|
// Codex-style runtime: daemon routing and independent async session actors
|
|
585
656
|
// share one V8 isolate and module graph. CPU-heavy work stays in bounded
|
|
@@ -602,12 +673,10 @@ async function main() {
|
|
|
602
673
|
log(`session runtime/keychain prewarm failed (non-fatal): ${error?.message || error}`);
|
|
603
674
|
return false;
|
|
604
675
|
});
|
|
605
|
-
|
|
676
|
+
return sessionRuntimePrewarmPromise;
|
|
606
677
|
}
|
|
607
678
|
sessionService = createSessionService({
|
|
608
679
|
createSessionRuntime: (options) => sessionRuntimeHost.create(options),
|
|
609
|
-
subscribeExternalSessionStates: (listener) =>
|
|
610
|
-
sessionRuntimeHost.subscribeAgentSessionStates(listener),
|
|
611
680
|
sessionExists: async (sessionId) => {
|
|
612
681
|
const store = await desktopRuntime.loadSessionStore();
|
|
613
682
|
return store.storedSessionExists?.(sessionId) === true;
|
|
@@ -620,7 +689,31 @@ async function main() {
|
|
|
620
689
|
if (typeof store.readStoredSessionTranscript !== 'function') return null;
|
|
621
690
|
return await store.readStoredSessionTranscript(sessionId, options) ?? null;
|
|
622
691
|
},
|
|
692
|
+
readStoredGoal: async (sessionId) => readStoredGoalSnapshot({
|
|
693
|
+
dataDir: DATA_DIR,
|
|
694
|
+
sessionId,
|
|
695
|
+
}),
|
|
696
|
+
listStoredActiveGoalSessionIds: async () => listStoredActiveGoalSessionIds({
|
|
697
|
+
dataDir: DATA_DIR,
|
|
698
|
+
}),
|
|
623
699
|
listSessions: async (options = {}) => {
|
|
700
|
+
if (options.includeAgentOnly === true) {
|
|
701
|
+
// Agent discovery is metadata-only. Exact session reads/subscriptions
|
|
702
|
+
// keep using the canonical session id after the user opens a worker.
|
|
703
|
+
const store = await import('../runtime/agent/orchestrator/session/store.mjs');
|
|
704
|
+
const summaries = store.listStoredSessionSummaries({
|
|
705
|
+
refreshFromStorage: options.refreshFromStorage === true,
|
|
706
|
+
});
|
|
707
|
+
const viewStore = await desktopRuntime.loadSessionStore();
|
|
708
|
+
const links = viewStore.listStoredAgentWorkerLinks?.() || [];
|
|
709
|
+
if (!links.length) return summaries;
|
|
710
|
+
const linksById = new Map(links.map((link) => [link.sessionId, link]));
|
|
711
|
+
return summaries.map((row) => {
|
|
712
|
+
if (row?.parentSessionId) return row;
|
|
713
|
+
const link = linksById.get(row?.id);
|
|
714
|
+
return link ? { ...row, ...link, id: row.id } : row;
|
|
715
|
+
});
|
|
716
|
+
}
|
|
624
717
|
const store = await desktopRuntime.loadSessionStore();
|
|
625
718
|
return store.listStoredSessionSummaries({
|
|
626
719
|
refreshFromStorage: options.refreshFromStorage === true,
|
|
@@ -673,9 +766,7 @@ async function main() {
|
|
|
673
766
|
...eventLoopStatus(),
|
|
674
767
|
}),
|
|
675
768
|
onClientsEmpty: () => { maybeSelfShutdown('no live session clients'); },
|
|
676
|
-
onClientRegistered: () => {
|
|
677
|
-
void prewarmSessionRuntime();
|
|
678
|
-
},
|
|
769
|
+
onClientRegistered: () => { void prewarmSessionRuntime(); },
|
|
679
770
|
onClientDropped: (token) => { try { sessionService.releaseClient(token); } catch {} },
|
|
680
771
|
onUpgradeRequested: requestDaemonReplacement,
|
|
681
772
|
});
|
|
@@ -720,6 +811,14 @@ async function main() {
|
|
|
720
811
|
safeIpcSend(process, { type: 'ready', port, token });
|
|
721
812
|
}
|
|
722
813
|
log(`ready port=${port} pid=${process.pid} in ${(performance.now() - startedAt).toFixed(0)}ms`);
|
|
814
|
+
void prewarmSessionRuntime()
|
|
815
|
+
.then(() => sessionService.recoverActiveGoals())
|
|
816
|
+
.then(({ found, resumed, skipped, failed }) => {
|
|
817
|
+
log(`active Goal recovery found=${found} resumed=${resumed} skipped=${skipped} failed=${failed}`);
|
|
818
|
+
})
|
|
819
|
+
.catch((error) => {
|
|
820
|
+
log(`active Goal recovery failed: ${error?.message || error}`);
|
|
821
|
+
});
|
|
723
822
|
eventLoopLagTimer = setInterval(() => {
|
|
724
823
|
const status = eventLoopStatus();
|
|
725
824
|
if (status.eventLoopP99Ms >= 250) {
|
|
@@ -35,7 +35,9 @@ const RUNTIME_METHODS = new Set([
|
|
|
35
35
|
'reserveSession',
|
|
36
36
|
'resume',
|
|
37
37
|
'submitAsync',
|
|
38
|
+
'submitAndWait',
|
|
38
39
|
'abort',
|
|
40
|
+
'closeCanonicalSession',
|
|
39
41
|
'resolveToolApproval',
|
|
40
42
|
'dispose',
|
|
41
43
|
]);
|
|
@@ -157,14 +159,6 @@ class SessionRuntimeShard {
|
|
|
157
159
|
this.recycleUnhealthy(child, message.detail);
|
|
158
160
|
return;
|
|
159
161
|
}
|
|
160
|
-
if (message.type === 'agent-session-state') {
|
|
161
|
-
const sessionId = String(message.sessionId || '');
|
|
162
|
-
const snapshot = message.snapshot;
|
|
163
|
-
if (sessionId && snapshot && typeof snapshot === 'object') {
|
|
164
|
-
this.onAgentSessionState?.({ sessionId, snapshot });
|
|
165
|
-
}
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
162
|
if (message.type === 'state') {
|
|
169
163
|
this.proxies.get(String(message.runtimeId || ''))?.applyFrame(message);
|
|
170
164
|
return;
|
|
@@ -728,17 +722,29 @@ class SessionRuntimeProxy {
|
|
|
728
722
|
* capacity cooldowns discovered by one shard are replayed into the others.
|
|
729
723
|
*/
|
|
730
724
|
class SessionRuntimeShardPool {
|
|
731
|
-
constructor({
|
|
725
|
+
constructor({
|
|
726
|
+
workerEntry,
|
|
727
|
+
cwd,
|
|
728
|
+
env,
|
|
729
|
+
log,
|
|
730
|
+
shardCount,
|
|
731
|
+
onAgentSessionState,
|
|
732
|
+
executeAgentControl,
|
|
733
|
+
}) {
|
|
732
734
|
this.log = typeof log === 'function' ? log : () => {};
|
|
733
735
|
this.closed = false;
|
|
734
736
|
this.ownership = createShardOwnership();
|
|
735
737
|
this.dispatchOwners = new Map(); // dispatchId -> shard index
|
|
736
738
|
this.agentControlOwners = new Map(); // controlId -> shard index
|
|
739
|
+
this.agentControlRuns = new Map(); // controlId -> AbortController
|
|
737
740
|
this.agentTaskOwners = new Map(); // taskId -> shard index
|
|
738
741
|
this.agentTagOwners = new Map(); // ownerSessionId\0tag -> shard index
|
|
739
742
|
this.agentSessionOwners = new Map(); // agent sessionId -> shard index
|
|
740
743
|
this.agentOwnerOrigins = new Map(); // owner sessionId -> source shard index
|
|
741
744
|
this.providerCooldown = { untilMs: 0, disabledReason: null, updatedAt: 0 };
|
|
745
|
+
this.executeCanonicalAgentControl = typeof executeAgentControl === 'function'
|
|
746
|
+
? executeAgentControl
|
|
747
|
+
: null;
|
|
742
748
|
this.prewarmRequested = false;
|
|
743
749
|
this.workloadCache = { refreshedAt: 0, shards: [] };
|
|
744
750
|
this.workloadRefresh = null;
|
|
@@ -942,12 +948,20 @@ class SessionRuntimeShardPool {
|
|
|
942
948
|
handleAgentControl(originShard, originChild, message) {
|
|
943
949
|
const controlId = String(message?.controlId || '');
|
|
944
950
|
if (!controlId) return;
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
message.context || {},
|
|
949
|
-
|
|
950
|
-
|
|
951
|
+
const controller = new AbortController();
|
|
952
|
+
this.agentControlRuns.set(controlId, controller);
|
|
953
|
+
const context = {
|
|
954
|
+
...(message.context || {}),
|
|
955
|
+
signal: controller.signal,
|
|
956
|
+
};
|
|
957
|
+
const ownerSessionId = String(context?.callerSessionId || '');
|
|
958
|
+
if (ownerSessionId) {
|
|
959
|
+
this.agentOwnerOrigins.set(ownerSessionId, originShard.index);
|
|
960
|
+
}
|
|
961
|
+
const execution = this.executeCanonicalAgentControl
|
|
962
|
+
? this.executeCanonicalAgentControl(message.args || {}, context)
|
|
963
|
+
: Promise.reject(new Error('canonical Agent control is unavailable'));
|
|
964
|
+
void Promise.resolve(execution).then((value) => {
|
|
951
965
|
if (originShard.child !== originChild || originChild?.killed) return;
|
|
952
966
|
safeIpcSend(originChild, {
|
|
953
967
|
type: 'agent-control-result',
|
|
@@ -968,11 +982,18 @@ class SessionRuntimeShardPool {
|
|
|
968
982
|
code: error?.code || null,
|
|
969
983
|
},
|
|
970
984
|
}, { onError: () => {} });
|
|
985
|
+
}).finally(() => {
|
|
986
|
+
this.agentControlRuns.delete(controlId);
|
|
971
987
|
});
|
|
972
988
|
}
|
|
973
989
|
|
|
974
990
|
cancelAgentControl(message) {
|
|
975
991
|
const controlId = String(message?.controlId || '');
|
|
992
|
+
const canonical = this.agentControlRuns.get(controlId);
|
|
993
|
+
if (canonical) {
|
|
994
|
+
try { canonical.abort(new Error(String(message?.reason || 'agent control canceled'))); } catch {}
|
|
995
|
+
return true;
|
|
996
|
+
}
|
|
976
997
|
const index = this.agentControlOwners.get(controlId);
|
|
977
998
|
if (index == null) return false;
|
|
978
999
|
const shard = this.shardAt(index);
|
|
@@ -1092,23 +1113,8 @@ export function createSessionRuntimeHost({
|
|
|
1092
1113
|
env = process.env,
|
|
1093
1114
|
log = () => {},
|
|
1094
1115
|
shardCount = null,
|
|
1116
|
+
executeAgentControl = null,
|
|
1095
1117
|
} = {}) {
|
|
1096
|
-
const agentSessionListeners = new Set();
|
|
1097
|
-
const agentSessionSnapshots = new Map();
|
|
1098
|
-
const publishAgentSessionState = (update) => {
|
|
1099
|
-
const sessionId = String(update?.sessionId || '');
|
|
1100
|
-
if (!sessionId || !update?.snapshot) return;
|
|
1101
|
-
agentSessionSnapshots.delete(sessionId);
|
|
1102
|
-
agentSessionSnapshots.set(sessionId, update.snapshot);
|
|
1103
|
-
while (agentSessionSnapshots.size > 256) {
|
|
1104
|
-
const oldest = agentSessionSnapshots.keys().next().value;
|
|
1105
|
-
if (oldest === undefined) break;
|
|
1106
|
-
agentSessionSnapshots.delete(oldest);
|
|
1107
|
-
}
|
|
1108
|
-
for (const listener of [...agentSessionListeners]) {
|
|
1109
|
-
try { listener({ sessionId, snapshot: update.snapshot }); } catch {}
|
|
1110
|
-
}
|
|
1111
|
-
};
|
|
1112
1118
|
const pool = new SessionRuntimeShardPool({
|
|
1113
1119
|
workerEntry,
|
|
1114
1120
|
cwd,
|
|
@@ -1117,7 +1123,7 @@ export function createSessionRuntimeHost({
|
|
|
1117
1123
|
shardCount: Number(shardCount) > 0
|
|
1118
1124
|
? normalizeShardCount(shardCount)
|
|
1119
1125
|
: resolveShardCount(),
|
|
1120
|
-
|
|
1126
|
+
executeAgentControl,
|
|
1121
1127
|
});
|
|
1122
1128
|
// One machine-global native counter stays warm in the daemon. Session
|
|
1123
1129
|
// runtimes relay requests over the worker IPC channel and never spawn
|
|
@@ -1175,23 +1181,32 @@ export function createSessionRuntimeHost({
|
|
|
1175
1181
|
},
|
|
1176
1182
|
async agentControl(args = {}, context = {}) {
|
|
1177
1183
|
if (closed) throw new Error('session runtime host is closed');
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1184
|
+
if (typeof executeAgentControl === 'function') {
|
|
1185
|
+
return await executeAgentControl(args, context);
|
|
1186
|
+
}
|
|
1187
|
+
throw new Error('canonical Agent control is unavailable');
|
|
1188
|
+
},
|
|
1189
|
+
notifySessionCompletion(ownerSessionId, text, meta = {}) {
|
|
1190
|
+
return pool.routeAgentControlNotification({
|
|
1191
|
+
ownerSessionId: String(ownerSessionId || ''),
|
|
1192
|
+
text: String(text || ''),
|
|
1193
|
+
meta,
|
|
1194
|
+
});
|
|
1195
|
+
},
|
|
1196
|
+
async agentSessionAction(sessionId, action, args = []) {
|
|
1197
|
+
void sessionId;
|
|
1198
|
+
void action;
|
|
1199
|
+
void args;
|
|
1200
|
+
throw new Error('Agent sessions are owned by the canonical session service');
|
|
1186
1201
|
},
|
|
1187
1202
|
refreshRuntimeWorkload,
|
|
1188
1203
|
subscribeAgentSessionStates(listener) {
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
return
|
|
1204
|
+
void listener;
|
|
1205
|
+
return () => {};
|
|
1206
|
+
},
|
|
1207
|
+
agentSessionState(sessionId) {
|
|
1208
|
+
void sessionId;
|
|
1209
|
+
return null;
|
|
1195
1210
|
},
|
|
1196
1211
|
get workloads() {
|
|
1197
1212
|
if (!closed && Date.now() - pool.workloadCache.refreshedAt > WORKLOAD_TTL_MS) {
|
|
@@ -1211,8 +1226,6 @@ export function createSessionRuntimeHost({
|
|
|
1211
1226
|
async close(reason = 'session runtime host closed') {
|
|
1212
1227
|
if (closed) return;
|
|
1213
1228
|
closed = true;
|
|
1214
|
-
agentSessionListeners.clear();
|
|
1215
|
-
agentSessionSnapshots.clear();
|
|
1216
1229
|
await pool.close(reason);
|
|
1217
1230
|
},
|
|
1218
1231
|
get status() {
|