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
|
@@ -52,15 +52,26 @@ export function createToolSurface({
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
function modelStandaloneTools() {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
const session = getSession();
|
|
56
|
+
const agentOwned = session?.owner === 'agent' || session?.visibility === 'agent-only';
|
|
57
|
+
const hideAgentTool = agentOwned || !workflowAllowsAgents();
|
|
58
|
+
const workflowTools = hideAgentTool
|
|
59
|
+
? standaloneTools.filter((tool) => !agentToolNames.has(String(tool?.name || '')))
|
|
60
|
+
: standaloneTools;
|
|
58
61
|
const denied = new Set(getFeatureDisallowedTools().map((name) => String(name || '')));
|
|
59
62
|
return denied.size
|
|
60
63
|
? workflowTools.filter((tool) => !denied.has(String(tool?.name || '')))
|
|
61
64
|
: workflowTools;
|
|
62
65
|
}
|
|
63
66
|
|
|
67
|
+
function disallowedTools() {
|
|
68
|
+
return [
|
|
69
|
+
...LEAD_DISALLOWED_TOOLS,
|
|
70
|
+
...getFeatureDisallowedTools(),
|
|
71
|
+
...(workflowAllowsAgents() ? [] : [...agentToolNames]),
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
|
|
64
75
|
function buildPreSessionSurface() {
|
|
65
76
|
const previewTools = typeof mgr.previewSessionTools === 'function'
|
|
66
77
|
? mgr.previewSessionTools(toolSpecForMode(mode), [], {
|
|
@@ -68,15 +79,13 @@ export function createToolSurface({
|
|
|
68
79
|
modelName: getRoute().model,
|
|
69
80
|
})
|
|
70
81
|
: [];
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
...getFeatureDisallowedTools(),
|
|
74
|
-
...(workflowAllowsAgents() ? [] : [...agentToolNames]),
|
|
75
|
-
]);
|
|
82
|
+
const denied = disallowedTools();
|
|
83
|
+
const tools = filterDisallowedTools(previewTools, denied);
|
|
76
84
|
const surface = { tools: Array.isArray(tools) ? tools.slice() : [], mcpScopeId: getMcpScopeId() };
|
|
77
85
|
applyDeferredToolSurface(surface, deferredSurfaceModeForLead(mode), modelStandaloneTools(), {
|
|
78
86
|
provider: getRoute().provider,
|
|
79
87
|
model: getRoute().model,
|
|
88
|
+
disallowed: denied,
|
|
80
89
|
});
|
|
81
90
|
return surface;
|
|
82
91
|
}
|
|
@@ -88,6 +97,7 @@ export function createToolSurface({
|
|
|
88
97
|
applyDeferredToolSurface(session, surfaceMode, modelStandaloneTools(), {
|
|
89
98
|
provider: getRoute().provider,
|
|
90
99
|
model: getRoute().model,
|
|
100
|
+
disallowed: disallowedTools(),
|
|
91
101
|
});
|
|
92
102
|
return selectDeferredTools(session, names, surfaceMode);
|
|
93
103
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { clean, hasOwn
|
|
3
|
+
import { clean, hasOwn } from './session-text.mjs';
|
|
4
4
|
import { serializeFrontmatterDoc } from '../runtime/shared/markdown-frontmatter.mjs';
|
|
5
5
|
import { isHiddenAgent } from '../runtime/agent/orchestrator/internal-agents.mjs';
|
|
6
6
|
import {
|
|
@@ -35,13 +35,13 @@ import {
|
|
|
35
35
|
// session locals plus the closure callbacks.
|
|
36
36
|
export function createWorkflowAgentsApi(deps) {
|
|
37
37
|
const {
|
|
38
|
-
getConfig, getRoute, setRouteState, getSession,
|
|
39
|
-
cfgMod,
|
|
38
|
+
getConfig, getRoute, setRouteState, getSession,
|
|
39
|
+
cfgMod, STANDALONE_DATA_DIR,
|
|
40
40
|
resolveRoute, lookupModelMeta, adoptConfig, saveConfigAndAdopt, displayConfig, ensureProvidersReady,
|
|
41
41
|
agentRouteFromConfig, loadAgentDefinition, activeWorkflowId, listWorkflowPacks,
|
|
42
42
|
loadWorkflowPack, workflowSummary, listCustomAgentIds,
|
|
43
43
|
getOutputStyleStatusCached, seedOutputStyleStatusCache, scheduleOutputStyleSave,
|
|
44
|
-
|
|
44
|
+
invalidateContextStatusCache,
|
|
45
45
|
invalidatePreSessionToolSurface, refreshEmptySessionToolPolicy,
|
|
46
46
|
} = deps;
|
|
47
47
|
return {
|
|
@@ -119,9 +119,7 @@ export function createWorkflowAgentsApi(deps) {
|
|
|
119
119
|
saveConfigAndAdopt(canonicalizeAgentRouteStorage(nextConfig));
|
|
120
120
|
if (defaultRoute) {
|
|
121
121
|
setRouteState(resolveRoute(getConfig(), { provider: defaultRoute.provider, model: defaultRoute.model, effort: defaultRoute.effort }));
|
|
122
|
-
|
|
123
|
-
if (session?.id) mgr.closeSession(session.id, 'cli-onboarding-complete', { tombstone: tombstoneOnClose(session) });
|
|
124
|
-
await recreateCurrentSessionIfReady();
|
|
122
|
+
invalidatePreSessionToolSurface?.();
|
|
125
123
|
}
|
|
126
124
|
return this.getOnboardingStatus();
|
|
127
125
|
},
|
|
@@ -198,24 +196,9 @@ export function createWorkflowAgentsApi(deps) {
|
|
|
198
196
|
scheduleOutputStyleSave(selected.id);
|
|
199
197
|
const freshStatus = { configured: selected.id, current: selected, styles: before.styles };
|
|
200
198
|
seedOutputStyleStatusCache(freshStatus);
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (session?.id && !hasConversation) {
|
|
205
|
-
const closedSessionId = session.id;
|
|
206
|
-
mgr.closeSession(closedSessionId, 'cli-output-style-switch');
|
|
207
|
-
setSession(null);
|
|
208
|
-
setTimeout(() => {
|
|
209
|
-
recreateCurrentSessionIfReady().catch((err) => {
|
|
210
|
-
try {
|
|
211
|
-
notifyFnForSession(closedSessionId)(
|
|
212
|
-
`Failed to start a new session after output style change: ${err?.message || err}`,
|
|
213
|
-
{ level: 'error' },
|
|
214
|
-
);
|
|
215
|
-
} catch {}
|
|
216
|
-
});
|
|
217
|
-
}, 0);
|
|
218
|
-
}
|
|
199
|
+
// Output style is global configuration for future turns/sessions. Never
|
|
200
|
+
// replace an addressed session merely to rebuild its frozen prompt.
|
|
201
|
+
const appliedToCurrentSession = !getSession()?.id;
|
|
219
202
|
invalidateContextStatusCache();
|
|
220
203
|
return { ...freshStatus, appliedToCurrentSession };
|
|
221
204
|
},
|
|
@@ -9,7 +9,11 @@ import { normalizeEffortInput } from './effort.mjs';
|
|
|
9
9
|
import { isLikelyRawModelId } from './config-helpers.mjs';
|
|
10
10
|
import { readTextSafe, readJsonSafe } from './fs-utils.mjs';
|
|
11
11
|
import { isHiddenAgent } from '../runtime/agent/orchestrator/internal-agents.mjs';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
DEFAULT_DISABLED_AGENT_IDS,
|
|
14
|
+
configuredAgentRouteCandidates,
|
|
15
|
+
isAgentDisabled,
|
|
16
|
+
} from '../runtime/shared/agent-route-config.mjs';
|
|
13
17
|
|
|
14
18
|
export const WORKFLOW_ROUTE_SLOTS = ['lead', 'agent', 'memory'];
|
|
15
19
|
export const AGENT_DELETED_MARKER = '.deleted';
|
|
@@ -24,11 +28,9 @@ const AGENT_ROLE_IDS = new Set(FIXED_AGENT_SLOTS.map((agent) => agent.id));
|
|
|
24
28
|
const BUILTIN_SLOT_AGENT_IDS = new Set(
|
|
25
29
|
FIXED_AGENT_SLOTS.filter((agent) => agent.workflowSlot).map((agent) => agent.id),
|
|
26
30
|
);
|
|
27
|
-
const STARTER_AGENT_ORDER = new Map(
|
|
28
|
-
[
|
|
29
|
-
|
|
30
|
-
['reviewer', 2],
|
|
31
|
-
]);
|
|
31
|
+
const STARTER_AGENT_ORDER = new Map(
|
|
32
|
+
DEFAULT_DISABLED_AGENT_IDS.map((id, index) => [id, index]),
|
|
33
|
+
);
|
|
32
34
|
// Fallback workflow for a config with no explicit selection, for an unknown
|
|
33
35
|
// id, and for the pack reset after a delete. Solo is the shipped default
|
|
34
36
|
// working mode; the cowork pack (directory id `default`) is opt-in.
|
|
@@ -60,7 +60,7 @@ export function callerSessionForContext(context = {}) {
|
|
|
60
60
|
export function sessionMatchesContext(session, context = {}) {
|
|
61
61
|
const wantedSession = callerSessionForContext(context);
|
|
62
62
|
if (wantedSession) {
|
|
63
|
-
return clean(session?.
|
|
63
|
+
return clean(session?.parentSessionId || session?.ownerSessionId) === wantedSession;
|
|
64
64
|
}
|
|
65
65
|
const wantedPid = terminalPidForContext(context);
|
|
66
66
|
if (!wantedPid) return true;
|
|
@@ -70,7 +70,7 @@ export function sessionMatchesContext(session, context = {}) {
|
|
|
70
70
|
|
|
71
71
|
export function rowMatchesContext(row, context = {}) {
|
|
72
72
|
const wantedSession = callerSessionForContext(context);
|
|
73
|
-
if (wantedSession) return clean(row?.ownerSessionId) === wantedSession;
|
|
73
|
+
if (wantedSession) return clean(row?.parentSessionId || row?.ownerSessionId) === wantedSession;
|
|
74
74
|
const wantedPid = terminalPidForContext(context);
|
|
75
75
|
if (!wantedPid) return true;
|
|
76
76
|
const rowPid = positiveInt(row?.clientHostPid);
|
|
@@ -231,7 +231,9 @@ export function createJobViews({
|
|
|
231
231
|
&& (typeof m.content === 'string' ? m.content.trim() : m.content));
|
|
232
232
|
const resultText = lastAssistant
|
|
233
233
|
? (typeof lastAssistant.content === 'string' ? lastAssistant.content : JSON.stringify(lastAssistant.content))
|
|
234
|
-
:
|
|
234
|
+
: (typeof session.lastHandoff === 'string' && session.lastHandoff.trim()
|
|
235
|
+
? session.lastHandoff
|
|
236
|
+
: '(worker session has no assistant output yet)');
|
|
235
237
|
return {
|
|
236
238
|
taskId: null,
|
|
237
239
|
operation: 'worker',
|
|
@@ -62,7 +62,11 @@ export function createNotify(mgr, { notifySessionCompletion } = {}) {
|
|
|
62
62
|
|
|
63
63
|
function notifyOwnerAgentCompletionEarly(job, resultValue, notifyContext = {}) {
|
|
64
64
|
if (!job || job._earlyCompletionNotified === true) return false;
|
|
65
|
-
const ownerSessionId = clean(
|
|
65
|
+
const ownerSessionId = clean(
|
|
66
|
+
notifyContext?.callerSessionId
|
|
67
|
+
|| notifyContext?.sessionId
|
|
68
|
+
|| notifyContext?.ownerSessionId
|
|
69
|
+
);
|
|
66
70
|
const finishedAt = new Date().toISOString();
|
|
67
71
|
// An abnormal-empty finish carries an `error` — the early preview must NOT
|
|
68
72
|
// present it as a benign `completed` card, or the Lead sees success before
|
|
@@ -147,6 +147,9 @@ export function renderResult(value) {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
if (value.content !== undefined) {
|
|
150
|
+
if (value.handoffOnly === true) {
|
|
151
|
+
return stripFinalAnswerWrapper(value.content);
|
|
152
|
+
}
|
|
150
153
|
const header = [
|
|
151
154
|
value.respawned ? 'agent respawned' : 'agent result',
|
|
152
155
|
value.tag ? `tag=${value.tag}` : null,
|
|
@@ -45,6 +45,7 @@ export function createSpawnFlow({
|
|
|
45
45
|
emitSubagentEvent,
|
|
46
46
|
notifyStatusChange = () => {},
|
|
47
47
|
notifySessionCompletion,
|
|
48
|
+
sessionSurface = null,
|
|
48
49
|
scheduleReap,
|
|
49
50
|
cfgMod,
|
|
50
51
|
dataDir,
|
|
@@ -56,7 +57,7 @@ export function createSpawnFlow({
|
|
|
56
57
|
}) {
|
|
57
58
|
function closePreparedSpawn(prepared, reason = 'agent-task-cancel') {
|
|
58
59
|
if (!prepared?.session?.id) return;
|
|
59
|
-
try { mgr.closeSession(prepared.session.id, reason); } catch {}
|
|
60
|
+
try { Promise.resolve(mgr.closeSession(prepared.session.id, reason)).catch(() => {}); } catch {}
|
|
60
61
|
try { clearAgentStatuslineRoute(prepared.session.id); } catch {}
|
|
61
62
|
forgetTerminalSession(prepared.tag, prepared.session.id);
|
|
62
63
|
}
|
|
@@ -68,14 +69,17 @@ export function createSpawnFlow({
|
|
|
68
69
|
|
|
69
70
|
function startJob(type, meta, run, notifyContext = null) {
|
|
70
71
|
const clientHostPid = terminalPidForContext(notifyContext);
|
|
71
|
-
const
|
|
72
|
+
const callerSessionId = clean(notifyContext?.callerSessionId || notifyContext?.sessionId);
|
|
73
|
+
const ownerSessionId = clean(notifyContext?.ownerSessionId) || callerSessionId;
|
|
74
|
+
const handoffSessionId = callerSessionId || ownerSessionId;
|
|
72
75
|
const ownerNotifyContext = {
|
|
73
|
-
callerSessionId:
|
|
76
|
+
callerSessionId: callerSessionId || null,
|
|
77
|
+
ownerSessionId: ownerSessionId || null,
|
|
74
78
|
clientHostPid: clientHostPid || null,
|
|
75
|
-
notifyFn:
|
|
76
|
-
? (text, completionMeta = {}) => notifySessionCompletion(
|
|
79
|
+
notifyFn: handoffSessionId && typeof notifySessionCompletion === 'function'
|
|
80
|
+
? (text, completionMeta = {}) => notifySessionCompletion(handoffSessionId, text, {
|
|
77
81
|
...(completionMeta && typeof completionMeta === 'object' ? completionMeta : {}),
|
|
78
|
-
caller_session_id:
|
|
82
|
+
caller_session_id: handoffSessionId,
|
|
79
83
|
})
|
|
80
84
|
: null,
|
|
81
85
|
};
|
|
@@ -98,7 +102,9 @@ export function createSpawnFlow({
|
|
|
98
102
|
try { admissionController.abort(new Error('agent task cancelled before resource admission')); } catch {}
|
|
99
103
|
const currentMeta = task?.meta || jobMeta;
|
|
100
104
|
if (currentMeta?.sessionId) {
|
|
101
|
-
try {
|
|
105
|
+
try {
|
|
106
|
+
Promise.resolve(mgr.closeSession(currentMeta.sessionId, 'agent-task-cancel')).catch(() => {});
|
|
107
|
+
} catch {}
|
|
102
108
|
}
|
|
103
109
|
setImmediate(notifyStatusChange);
|
|
104
110
|
},
|
|
@@ -281,7 +287,10 @@ export function createSpawnFlow({
|
|
|
281
287
|
sourceType: 'cli',
|
|
282
288
|
sourceName: agent,
|
|
283
289
|
parentSessionId: clean(context?.callerSessionId || context?.sessionId) || null,
|
|
284
|
-
ownerSessionId: clean(context?.
|
|
290
|
+
ownerSessionId: clean(context?.ownerSessionId)
|
|
291
|
+
|| clean(context?.callerSessionId || context?.sessionId)
|
|
292
|
+
|| null,
|
|
293
|
+
visibility: 'agent-only',
|
|
285
294
|
clientHostPid: terminalPidForContext(context) || null,
|
|
286
295
|
agentTag: tag,
|
|
287
296
|
taskType: clean(args.taskType) || clean(args.typeHint) || undefined,
|
|
@@ -330,18 +339,31 @@ export function createSpawnFlow({
|
|
|
330
339
|
|
|
331
340
|
async function prepareSpawnInProcess(args, callerCwd = null, context = {}, prepState = null) {
|
|
332
341
|
const plan = await resolveSpawnPlan(args, callerCwd, context, prepState);
|
|
333
|
-
await ensureProvider(plan.config, plan.preset.provider);
|
|
334
|
-
if (prepState?.timedOut) {
|
|
335
|
-
throw new Error('agent spawn prep timed out before session bind');
|
|
336
|
-
}
|
|
337
342
|
const spec = spawnSessionSpec(plan, args, context);
|
|
338
|
-
|
|
343
|
+
let created;
|
|
344
|
+
if (sessionSurface?.canonical === true
|
|
345
|
+
&& typeof sessionSurface.createChild === 'function') {
|
|
346
|
+
created = await sessionSurface.createChild({
|
|
347
|
+
spec,
|
|
348
|
+
prompt: plan.prompt,
|
|
349
|
+
tag: plan.tag,
|
|
350
|
+
});
|
|
351
|
+
} else {
|
|
352
|
+
await ensureProvider(plan.config, plan.preset.provider);
|
|
353
|
+
if (prepState?.timedOut) {
|
|
354
|
+
throw new Error('agent spawn prep timed out before session bind');
|
|
355
|
+
}
|
|
356
|
+
created = prepareAgentSession(spec);
|
|
357
|
+
}
|
|
358
|
+
const { session, effectiveCwd } = created;
|
|
339
359
|
bindSpawnedSession(session, plan);
|
|
340
360
|
// Spawn prewarm builds the materialized stable prompt and keeps the
|
|
341
361
|
// resulting Codex-style client handle reserved for the first turn.
|
|
342
362
|
// Fire-and-forget: failures fall back to the lazy per-send handshake.
|
|
343
363
|
// MIXDOG_AGENT_SPAWN_WS_PREWARM=0 disables.
|
|
344
|
-
|
|
364
|
+
if (sessionSurface?.canonical !== true) {
|
|
365
|
+
maybePrewarmSpawnTransport(plan, session);
|
|
366
|
+
}
|
|
345
367
|
return preparedSpawnResult(
|
|
346
368
|
{ ...plan, workerCwd: effectiveCwd || plan.workerCwd },
|
|
347
369
|
args,
|
|
@@ -403,11 +425,12 @@ export function createSpawnFlow({
|
|
|
403
425
|
effort: preset.effort || null,
|
|
404
426
|
fast: preset.fast === true,
|
|
405
427
|
content: result?.content || '',
|
|
428
|
+
...(sessionSurface?.canonical === true ? { handoffOnly: true } : {}),
|
|
406
429
|
...(abnormalError ? { error: abnormalError } : {}),
|
|
407
430
|
};
|
|
408
431
|
};
|
|
409
432
|
handoffMsgStart = resolveHandoffMessageStartIndex(mgr.getSession(session.id));
|
|
410
|
-
const
|
|
433
|
+
const turnHooks = {
|
|
411
434
|
notifyFn: workerNotifyFn(session.id, notifyContext || {}),
|
|
412
435
|
onToolResult: (message) => turnReview.onToolResult(message),
|
|
413
436
|
...(job ? {
|
|
@@ -419,7 +442,25 @@ export function createSpawnFlow({
|
|
|
419
442
|
reconcileJobTerminalResult(job, value);
|
|
420
443
|
},
|
|
421
444
|
} : {}),
|
|
422
|
-
}
|
|
445
|
+
};
|
|
446
|
+
const result = typeof sessionSurface?.runTurn === 'function'
|
|
447
|
+
&& sessionSurface.canRun?.(session) !== false
|
|
448
|
+
? await sessionSurface.runTurn({
|
|
449
|
+
session,
|
|
450
|
+
prompt,
|
|
451
|
+
context: args.context || null,
|
|
452
|
+
cwd: workerCwd,
|
|
453
|
+
...turnHooks,
|
|
454
|
+
})
|
|
455
|
+
: await mgr.askSession(
|
|
456
|
+
session.id,
|
|
457
|
+
prompt,
|
|
458
|
+
args.context || null,
|
|
459
|
+
null,
|
|
460
|
+
workerCwd,
|
|
461
|
+
null,
|
|
462
|
+
turnHooks,
|
|
463
|
+
);
|
|
423
464
|
// The early preview no longer promises body suppression, so the canonical
|
|
424
465
|
// notifyTaskCompletion is left to fire exactly once with output via the
|
|
425
466
|
// resolve/reconcile/finally path.
|
|
@@ -454,6 +495,10 @@ export function createSpawnFlow({
|
|
|
454
495
|
reconcileJobWatchdogPartial(job, value);
|
|
455
496
|
return value;
|
|
456
497
|
}
|
|
498
|
+
if (job?.status === 'cancelled') {
|
|
499
|
+
finalStatus = 'cancelled';
|
|
500
|
+
throw error;
|
|
501
|
+
}
|
|
457
502
|
finalStatus = 'error';
|
|
458
503
|
reconcileJobStreamStalled(job, error);
|
|
459
504
|
throw error;
|
|
@@ -20,7 +20,7 @@ export const AGENT_TOOL = {
|
|
|
20
20
|
destructiveHint: true,
|
|
21
21
|
idempotentHint: false,
|
|
22
22
|
openWorldHint: true,
|
|
23
|
-
agentHidden:
|
|
23
|
+
agentHidden: false,
|
|
24
24
|
},
|
|
25
25
|
description: 'Run scoped agent work as background tasks. spawn/send return task_id immediately. Reuse one tag for one scope for its whole lifetime; give distinct tags only to independent scopes. Never mint a new tag because a session expired or was lost — same-tag spawn respawns it with the full brief. Wait for completion notifications; use status/read only for manual recovery.',
|
|
26
26
|
inputSchema: {
|
|
@@ -7,6 +7,7 @@ import { readFileSync, statSync } from 'node:fs';
|
|
|
7
7
|
import { resolve } from 'node:path';
|
|
8
8
|
|
|
9
9
|
import { updateJsonAtomicSync } from '../../runtime/shared/atomic-file.mjs';
|
|
10
|
+
import { resolveAgentTerminalReapMs } from '../../session-runtime/config-helpers.mjs';
|
|
10
11
|
import { WORKER_INDEX_FILE } from './tool-def.mjs';
|
|
11
12
|
import { agentTagOf, clean, positiveInt, rowMatchesContext } from './helpers.mjs';
|
|
12
13
|
import {
|
|
@@ -17,8 +18,37 @@ import {
|
|
|
17
18
|
workerRowKey,
|
|
18
19
|
} from './worker-rows.mjs';
|
|
19
20
|
|
|
21
|
+
const ACTIVE_WORKER_STATUS =
|
|
22
|
+
/^(?:connecting|requesting|streaming|tool[-_\s]?running|running|queued|pending|starting|cancelling)$/i;
|
|
23
|
+
const WORKER_POOL_FRESH_MS = 2 * 60 * 1000;
|
|
24
|
+
const exitFlushes = new Set();
|
|
25
|
+
let exitFlushInstalled = false;
|
|
26
|
+
|
|
27
|
+
function registerExitFlush(flush) {
|
|
28
|
+
exitFlushes.add(flush);
|
|
29
|
+
if (exitFlushInstalled) return;
|
|
30
|
+
exitFlushInstalled = true;
|
|
31
|
+
process.on('exit', () => {
|
|
32
|
+
for (const entry of exitFlushes) {
|
|
33
|
+
try { entry(); } catch { /* exit flush is best effort */ }
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function runtimeAlive(pid) {
|
|
39
|
+
const id = Number(pid) || 0;
|
|
40
|
+
if (id <= 0 || id === process.pid) return true;
|
|
41
|
+
try {
|
|
42
|
+
process.kill(id, 0);
|
|
43
|
+
return true;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
return error?.code === 'EPERM';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
20
49
|
export function createWorkerIndex({ dataDir, cfgMod, mgr, tags, tagAgents, tagCwds }) {
|
|
21
50
|
const pendingMutators = [];
|
|
51
|
+
const activeWorkerKeys = new Set();
|
|
22
52
|
let flushTimer = null;
|
|
23
53
|
// Mtime-keyed parse cache. A single spawn calls refreshTagsFromSessions /
|
|
24
54
|
// resolveTag / nextTag, which each re-read and re-parse this file; across a
|
|
@@ -48,6 +78,7 @@ export function createWorkerIndex({ dataDir, cfgMod, mgr, tags, tagAgents, tagCw
|
|
|
48
78
|
.map((row) => ({
|
|
49
79
|
tag: clean(row.tag),
|
|
50
80
|
sessionId: clean(row.sessionId),
|
|
81
|
+
parentSessionId: clean(row.parentSessionId) || null,
|
|
51
82
|
ownerSessionId: clean(row.ownerSessionId || row.parentSessionId) || null,
|
|
52
83
|
agent: clean(row.agent) || null,
|
|
53
84
|
provider: clean(row.provider) || null,
|
|
@@ -64,6 +95,7 @@ export function createWorkerIndex({ dataDir, cfgMod, mgr, tags, tagAgents, tagCw
|
|
|
64
95
|
turnStartedAt: clean(row.turnStartedAt) || null,
|
|
65
96
|
reapAt: clean(row.reapAt) || null,
|
|
66
97
|
clientHostPid: positiveInt(row.clientHostPid),
|
|
98
|
+
runtimePid: positiveInt(row.runtimePid),
|
|
67
99
|
cwd: clean(row.cwd) || null,
|
|
68
100
|
task_id: clean(row.task_id || row.taskId) || null,
|
|
69
101
|
error: clean(row.error) || null,
|
|
@@ -159,6 +191,47 @@ export function createWorkerIndex({ dataDir, cfgMod, mgr, tags, tagAgents, tagCw
|
|
|
159
191
|
}
|
|
160
192
|
}
|
|
161
193
|
|
|
194
|
+
function workerHeartbeatFresh(sessionId, now) {
|
|
195
|
+
const id = clean(sessionId);
|
|
196
|
+
if (!dataDir || !id) return false;
|
|
197
|
+
try {
|
|
198
|
+
const mtimeMs = statSync(resolve(dataDir, 'sessions', `${id}.hb`)).mtimeMs || 0;
|
|
199
|
+
return mtimeMs > 0 && now - mtimeMs <= WORKER_POOL_FRESH_MS;
|
|
200
|
+
} catch {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function staleActiveWorkerRow(row, now) {
|
|
206
|
+
const active = ACTIVE_WORKER_STATUS.test(clean(row?.status))
|
|
207
|
+
|| ACTIVE_WORKER_STATUS.test(clean(row?.stage));
|
|
208
|
+
if (!active) return false;
|
|
209
|
+
if (positiveInt(row.runtimePid) && !runtimeAlive(row.runtimePid)) return true;
|
|
210
|
+
if (workerHeartbeatFresh(row.sessionId, now)) return false;
|
|
211
|
+
const updated = Date.parse(clean(row.updatedAt)) || 0;
|
|
212
|
+
return !(updated > 0 && now - updated <= WORKER_POOL_FRESH_MS);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function terminalReapAt(row, now) {
|
|
216
|
+
let reapMs = null;
|
|
217
|
+
try { reapMs = resolveAgentTerminalReapMs(cfgMod.loadConfig(), row?.provider); }
|
|
218
|
+
catch { reapMs = null; }
|
|
219
|
+
return reapMs == null ? null : new Date(now + reapMs).toISOString();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function idleWorkerRow(row, now, touch = false) {
|
|
223
|
+
const stamp = new Date(now).toISOString();
|
|
224
|
+
return {
|
|
225
|
+
...row,
|
|
226
|
+
status: 'idle',
|
|
227
|
+
stage: 'idle',
|
|
228
|
+
turnStartedAt: null,
|
|
229
|
+
finishedAt: touch ? stamp : (clean(row.finishedAt) || clean(row.updatedAt) || stamp),
|
|
230
|
+
updatedAt: touch ? stamp : (clean(row.updatedAt) || stamp),
|
|
231
|
+
reapAt: touch ? terminalReapAt(row, now) : (clean(row.reapAt) || terminalReapAt(row, now)),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
162
235
|
// Spawn-path writes are batched onto one microtask so a parallel fanout pays
|
|
163
236
|
// a single locked rewrite instead of one per worker.
|
|
164
237
|
function flushWorkerIndexMutations() {
|
|
@@ -197,6 +270,9 @@ export function createWorkerIndex({ dataDir, cfgMod, mgr, tags, tagAgents, tagCw
|
|
|
197
270
|
return {
|
|
198
271
|
tag,
|
|
199
272
|
sessionId,
|
|
273
|
+
parentSessionId: clean(extra.parentSessionId)
|
|
274
|
+
|| clean(session?.parentSessionId)
|
|
275
|
+
|| null,
|
|
200
276
|
ownerSessionId: clean(extra.ownerSessionId || extra.parentSessionId)
|
|
201
277
|
|| clean(session?.ownerSessionId || session?.parentSessionId)
|
|
202
278
|
|| null,
|
|
@@ -219,6 +295,7 @@ export function createWorkerIndex({ dataDir, cfgMod, mgr, tags, tagAgents, tagCw
|
|
|
219
295
|
// the new absolute deadline immediately afterwards via scheduleReap().
|
|
220
296
|
reapAt: clean(extra.reapAt) || null,
|
|
221
297
|
clientHostPid: positiveInt(extra.clientHostPid) || positiveInt(session?.clientHostPid),
|
|
298
|
+
runtimePid: positiveInt(extra.runtimePid) || process.pid,
|
|
222
299
|
cwd: clean(session?.cwd) || clean(extra.cwd) || null,
|
|
223
300
|
task_id: clean(extra.task_id || extra.taskId) || null,
|
|
224
301
|
error: clean(extra.error) || null,
|
|
@@ -234,6 +311,10 @@ export function createWorkerIndex({ dataDir, cfgMod, mgr, tags, tagAgents, tagCw
|
|
|
234
311
|
function upsertWorkerRow(row, { defer = false } = {}) {
|
|
235
312
|
const normalized = normalizeWorkerRows({ workers: [row] })[0];
|
|
236
313
|
if (!normalized) return false;
|
|
314
|
+
const key = workerRowKey(normalized);
|
|
315
|
+
if (ACTIVE_WORKER_STATUS.test(normalized.status)
|
|
316
|
+
|| ACTIVE_WORKER_STATUS.test(normalized.stage)) activeWorkerKeys.add(key);
|
|
317
|
+
else activeWorkerKeys.delete(key);
|
|
237
318
|
const bindTag = !isLeadPoolAgent(normalized.agent);
|
|
238
319
|
if (bindTag) {
|
|
239
320
|
tags.set(normalized.tag, normalized.sessionId);
|
|
@@ -288,6 +369,45 @@ export function createWorkerIndex({ dataDir, cfgMod, mgr, tags, tagAgents, tagCw
|
|
|
288
369
|
return rows;
|
|
289
370
|
}
|
|
290
371
|
|
|
372
|
+
function flushActiveWorkerRows() {
|
|
373
|
+
if (!activeWorkerKeys.size) return;
|
|
374
|
+
const keys = [...activeWorkerKeys];
|
|
375
|
+
activeWorkerKeys.clear();
|
|
376
|
+
const now = Date.now();
|
|
377
|
+
writeWorkerRows((byKey) => {
|
|
378
|
+
for (const key of keys) {
|
|
379
|
+
const current = byKey.get(key);
|
|
380
|
+
if (!current || positiveInt(current.runtimePid) !== process.pid) continue;
|
|
381
|
+
const active = ACTIVE_WORKER_STATUS.test(clean(current.status))
|
|
382
|
+
|| ACTIVE_WORKER_STATUS.test(clean(current.stage));
|
|
383
|
+
if (active) byKey.set(key, idleWorkerRow(current, now, true));
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function recoverStaleWorkerRows() {
|
|
389
|
+
const now = Date.now();
|
|
390
|
+
const stale = readAllWorkerRows().filter((row) => staleActiveWorkerRow(row, now));
|
|
391
|
+
if (!stale.length) return false;
|
|
392
|
+
writeWorkerRows((byKey) => {
|
|
393
|
+
for (const row of stale) {
|
|
394
|
+
const key = workerRowKey(row);
|
|
395
|
+
const current = byKey.get(key);
|
|
396
|
+
if (!current || !staleActiveWorkerRow(current, now)) continue;
|
|
397
|
+
byKey.set(key, idleWorkerRow(current, now));
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function flushWorkerIndexOnExit() {
|
|
404
|
+
flushWorkerIndexMutations();
|
|
405
|
+
flushActiveWorkerRows();
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
recoverStaleWorkerRows();
|
|
409
|
+
registerExitFlush(flushWorkerIndexOnExit);
|
|
410
|
+
|
|
291
411
|
return {
|
|
292
412
|
workerIndexPath,
|
|
293
413
|
invalidateWorkerRowsCache: invalidateCache,
|
|
@@ -304,5 +424,8 @@ export function createWorkerIndex({ dataDir, cfgMod, mgr, tags, tagAgents, tagCw
|
|
|
304
424
|
upsertWorkerSessionDeferred,
|
|
305
425
|
removeWorkerRow,
|
|
306
426
|
refreshTagsFromIndex,
|
|
427
|
+
flushActiveWorkerRows,
|
|
428
|
+
flushWorkerIndexOnExit,
|
|
429
|
+
recoverStaleWorkerRows,
|
|
307
430
|
};
|
|
308
431
|
}
|
|
@@ -74,7 +74,7 @@ export function applyWorkerRowUpsert(byKey, normalized) {
|
|
|
74
74
|
if (!key) return;
|
|
75
75
|
const prev = byKey.get(key) || {};
|
|
76
76
|
const merged = { ...prev, ...normalized };
|
|
77
|
-
for (const field of ['ownerSessionId', 'agent', 'provider', 'model', 'preset', 'effort', 'fast', 'clientHostPid', 'cwd', 'task_id', 'permission', 'toolPermission', 'turnStartedAt']) {
|
|
77
|
+
for (const field of ['parentSessionId', 'ownerSessionId', 'agent', 'provider', 'model', 'preset', 'effort', 'fast', 'clientHostPid', 'runtimePid', 'cwd', 'task_id', 'permission', 'toolPermission', 'turnStartedAt']) {
|
|
78
78
|
if ((merged[field] === null || merged[field] === '') && prev[field] != null && prev[field] !== '') {
|
|
79
79
|
merged[field] = prev[field];
|
|
80
80
|
}
|
|
@@ -89,6 +89,7 @@ export function applyWorkerRowUpsert(byKey, normalized) {
|
|
|
89
89
|
export function workerRowToSession(row = {}) {
|
|
90
90
|
return {
|
|
91
91
|
id: row.sessionId,
|
|
92
|
+
parentSessionId: row.parentSessionId || row.ownerSessionId || null,
|
|
92
93
|
ownerSessionId: row.ownerSessionId || null,
|
|
93
94
|
agentTag: row.tag,
|
|
94
95
|
agent: row.agent || null,
|