pi-subagents 0.68.0 → 0.70.0
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/CHANGELOG.md +62 -1
- package/agents/reviewer.md +3 -2
- package/docs/agents.md +10 -2
- package/docs/configuration.md +1 -1
- package/docs/extension-api.md +1 -1
- package/docs/models.md +3 -1
- package/docs/observability.md +6 -0
- package/docs/tool-reference.md +23 -2
- package/docs/watchdog.md +2 -0
- package/docs/workflows.md +54 -2
- package/index.d.ts +3 -0
- package/index.d.ts.map +1 -0
- package/index.js +10 -0
- package/index.js.map +1 -0
- package/package.json +89 -73
- package/runner-peer-loader.mjs +4 -7
- package/runner-peer-preload.mjs +5 -7
- package/skills/pi-subagents/references/execution-controls.md +3 -1
- package/skills/pi-subagents/references/prompting-and-roles.md +2 -2
- package/src/agents/advertised-agent-prompt.d.ts +8 -0
- package/src/agents/advertised-agent-prompt.d.ts.map +1 -0
- package/src/agents/advertised-agent-prompt.js +77 -0
- package/src/agents/advertised-agent-prompt.js.map +1 -0
- package/src/agents/agent-management.d.ts +27 -0
- package/src/agents/agent-management.d.ts.map +1 -0
- package/src/agents/agent-management.js +1528 -0
- package/src/agents/agent-management.js.map +1 -0
- package/src/agents/agent-memory.d.ts +49 -0
- package/src/agents/agent-memory.d.ts.map +1 -0
- package/src/agents/agent-memory.js +349 -0
- package/src/agents/agent-memory.js.map +1 -0
- package/src/agents/agent-refinements.d.ts +100 -0
- package/src/agents/agent-refinements.d.ts.map +1 -0
- package/src/agents/agent-refinements.js +569 -0
- package/src/agents/agent-refinements.js.map +1 -0
- package/src/agents/agent-scope.d.ts +3 -0
- package/src/agents/agent-scope.d.ts.map +1 -0
- package/src/agents/agent-scope.js +6 -0
- package/src/agents/agent-scope.js.map +1 -0
- package/src/agents/agent-selection.d.ts +3 -0
- package/src/agents/agent-selection.d.ts.map +1 -0
- package/src/agents/agent-selection.js +23 -0
- package/src/agents/agent-selection.js.map +1 -0
- package/src/agents/agent-serializer.d.ts +8 -0
- package/src/agents/agent-serializer.d.ts.map +1 -0
- package/src/agents/agent-serializer.js +200 -0
- package/src/agents/agent-serializer.js.map +1 -0
- package/src/agents/agents.d.ts +313 -0
- package/src/agents/agents.d.ts.map +1 -0
- package/src/agents/agents.js +2622 -0
- package/src/agents/agents.js.map +1 -0
- package/src/agents/builtin-names.d.ts +2 -0
- package/src/agents/builtin-names.d.ts.map +1 -0
- package/src/agents/builtin-names.js +17 -0
- package/src/agents/builtin-names.js.map +1 -0
- package/src/agents/chain-serializer.d.ts +7 -0
- package/src/agents/chain-serializer.d.ts.map +1 -0
- package/src/agents/chain-serializer.js +319 -0
- package/src/agents/chain-serializer.js.map +1 -0
- package/src/agents/frontmatter.d.ts +16 -0
- package/src/agents/frontmatter.d.ts.map +1 -0
- package/src/agents/frontmatter.js +142 -0
- package/src/agents/frontmatter.js.map +1 -0
- package/src/agents/identity.d.ts +8 -0
- package/src/agents/identity.d.ts.map +1 -0
- package/src/agents/identity.js +30 -0
- package/src/agents/identity.js.map +1 -0
- package/src/agents/proactive-skills.d.ts +35 -0
- package/src/agents/proactive-skills.d.ts.map +1 -0
- package/src/agents/proactive-skills.js +154 -0
- package/src/agents/proactive-skills.js.map +1 -0
- package/src/agents/runtime-agent-events.d.ts +27 -0
- package/src/agents/runtime-agent-events.d.ts.map +1 -0
- package/src/agents/runtime-agent-events.js +53 -0
- package/src/agents/runtime-agent-events.js.map +1 -0
- package/src/agents/runtime-agent-registry.d.ts +59 -0
- package/src/agents/runtime-agent-registry.d.ts.map +1 -0
- package/src/agents/runtime-agent-registry.js +390 -0
- package/src/agents/runtime-agent-registry.js.map +1 -0
- package/src/agents/skills.d.ts +33 -0
- package/src/agents/skills.d.ts.map +1 -0
- package/src/agents/skills.js +685 -0
- package/src/agents/skills.js.map +1 -0
- package/src/api/agents.d.ts +5 -0
- package/src/api/agents.d.ts.map +1 -0
- package/src/api/agents.js +3 -0
- package/src/api/agents.js.map +1 -0
- package/src/api/background-work.d.ts +39 -0
- package/src/api/background-work.d.ts.map +1 -0
- package/src/api/background-work.js +165 -0
- package/src/api/background-work.js.map +1 -0
- package/src/api/capability-ceiling.d.ts +2 -0
- package/src/api/capability-ceiling.d.ts.map +1 -0
- package/src/api/capability-ceiling.js +2 -0
- package/src/api/capability-ceiling.js.map +1 -0
- package/src/api/child-tool-plan.d.ts +2 -0
- package/src/api/child-tool-plan.d.ts.map +1 -0
- package/src/api/child-tool-plan.js +2 -0
- package/src/api/child-tool-plan.js.map +1 -0
- package/src/api/control-channel.d.ts +2 -0
- package/src/api/control-channel.d.ts.map +1 -0
- package/src/api/control-channel.js +2 -0
- package/src/api/control-channel.js.map +1 -0
- package/src/api/delegation.d.ts +99 -0
- package/src/api/delegation.d.ts.map +1 -0
- package/src/api/delegation.js +9 -0
- package/src/api/delegation.js.map +1 -0
- package/src/api/external-job-provider.d.ts +58 -0
- package/src/api/external-job-provider.d.ts.map +1 -0
- package/src/api/external-job-provider.js +140 -0
- package/src/api/external-job-provider.js.map +1 -0
- package/src/api/external-runs.d.ts +48 -0
- package/src/api/external-runs.d.ts.map +1 -0
- package/src/api/external-runs.js +245 -0
- package/src/api/external-runs.js.map +1 -0
- package/src/api/intercom-bridge.d.ts +2 -0
- package/src/api/intercom-bridge.d.ts.map +1 -0
- package/src/api/intercom-bridge.js +2 -0
- package/src/api/intercom-bridge.js.map +1 -0
- package/src/api/preflight.d.ts +173 -0
- package/src/api/preflight.d.ts.map +1 -0
- package/src/api/preflight.js +362 -0
- package/src/api/preflight.js.map +1 -0
- package/src/api/project-panes.d.ts +8 -0
- package/src/api/project-panes.d.ts.map +1 -0
- package/src/api/project-panes.js +8 -0
- package/src/api/project-panes.js.map +1 -0
- package/src/api/required-child-extensions.d.ts +2 -0
- package/src/api/required-child-extensions.d.ts.map +1 -0
- package/src/api/required-child-extensions.js +2 -0
- package/src/api/required-child-extensions.js.map +1 -0
- package/src/api/shared-types.d.ts +2 -0
- package/src/api/shared-types.d.ts.map +1 -0
- package/src/api/shared-types.js +2 -0
- package/src/api/shared-types.js.map +1 -0
- package/src/api/workflow-resources.d.ts +3 -0
- package/src/api/workflow-resources.d.ts.map +1 -0
- package/src/api/workflow-resources.js +2 -0
- package/src/api/workflow-resources.js.map +1 -0
- package/src/extension/config.d.ts +8 -0
- package/src/extension/config.d.ts.map +1 -0
- package/src/extension/config.js +245 -0
- package/src/extension/config.js.map +1 -0
- package/src/extension/control-notices.d.ts +19 -0
- package/src/extension/control-notices.d.ts.map +1 -0
- package/src/extension/control-notices.js +34 -0
- package/src/extension/control-notices.js.map +1 -0
- package/src/extension/doctor.d.ts +33 -0
- package/src/extension/doctor.d.ts.map +1 -0
- package/src/extension/doctor.js +231 -0
- package/src/extension/doctor.js.map +1 -0
- package/src/extension/fanout-child.d.ts +7 -0
- package/src/extension/fanout-child.d.ts.map +1 -0
- package/src/extension/fanout-child.js +261 -0
- package/src/extension/fanout-child.js.map +1 -0
- package/src/extension/herdr-pi-bridge.d.ts +17 -0
- package/src/extension/herdr-pi-bridge.d.ts.map +1 -0
- package/src/extension/herdr-pi-bridge.js +243 -0
- package/src/extension/herdr-pi-bridge.js.map +1 -0
- package/src/extension/index.d.ts +20 -0
- package/src/extension/index.d.ts.map +1 -0
- package/src/extension/index.js +1108 -0
- package/src/extension/index.js.map +1 -0
- package/src/extension/public-execution.d.ts +62 -0
- package/src/extension/public-execution.d.ts.map +1 -0
- package/src/extension/public-execution.js +174 -0
- package/src/extension/public-execution.js.map +1 -0
- package/src/extension/rpc.d.ts +83 -0
- package/src/extension/rpc.d.ts.map +1 -0
- package/src/extension/rpc.js +687 -0
- package/src/extension/rpc.js.map +1 -0
- package/src/extension/schemas.d.ts +252 -0
- package/src/extension/schemas.d.ts.map +1 -0
- package/src/extension/schemas.js +396 -0
- package/src/extension/schemas.js.map +1 -0
- package/src/extension/steering-notices.d.ts +15 -0
- package/src/extension/steering-notices.d.ts.map +1 -0
- package/src/extension/steering-notices.js +23 -0
- package/src/extension/steering-notices.js.map +1 -0
- package/src/extension/subagent-guide.d.ts +4 -0
- package/src/extension/subagent-guide.d.ts.map +1 -0
- package/src/extension/subagent-guide.js +35 -0
- package/src/extension/subagent-guide.js.map +1 -0
- package/src/extension/tool-description.d.ts +20 -0
- package/src/extension/tool-description.d.ts.map +1 -0
- package/src/extension/tool-description.js +160 -0
- package/src/extension/tool-description.js.map +1 -0
- package/src/extension/tool-result.d.ts +10 -0
- package/src/extension/tool-result.d.ts.map +1 -0
- package/src/extension/tool-result.js +17 -0
- package/src/extension/tool-result.js.map +1 -0
- package/src/inspectors/actions.d.ts +23 -0
- package/src/inspectors/actions.d.ts.map +1 -0
- package/src/inspectors/actions.js +155 -0
- package/src/inspectors/actions.js.map +1 -0
- package/src/inspectors/ghostty/actions.d.ts +12 -0
- package/src/inspectors/ghostty/actions.d.ts.map +1 -0
- package/src/inspectors/ghostty/actions.js +63 -0
- package/src/inspectors/ghostty/actions.js.map +1 -0
- package/src/inspectors/ghostty/plugin.d.ts +8 -0
- package/src/inspectors/ghostty/plugin.d.ts.map +1 -0
- package/src/inspectors/ghostty/plugin.js +24 -0
- package/src/inspectors/ghostty/plugin.js.map +1 -0
- package/src/inspectors/herdr/actions.d.ts +26 -0
- package/src/inspectors/herdr/actions.d.ts.map +1 -0
- package/src/inspectors/herdr/actions.js +134 -0
- package/src/inspectors/herdr/actions.js.map +1 -0
- package/src/inspectors/herdr/client.d.ts +42 -0
- package/src/inspectors/herdr/client.d.ts.map +1 -0
- package/src/inspectors/herdr/client.js +130 -0
- package/src/inspectors/herdr/client.js.map +1 -0
- package/src/inspectors/herdr/focus.d.ts +25 -0
- package/src/inspectors/herdr/focus.d.ts.map +1 -0
- package/src/inspectors/herdr/focus.js +50 -0
- package/src/inspectors/herdr/focus.js.map +1 -0
- package/src/inspectors/herdr/plugin.d.ts +7 -0
- package/src/inspectors/herdr/plugin.d.ts.map +1 -0
- package/src/inspectors/herdr/plugin.js +15 -0
- package/src/inspectors/herdr/plugin.js.map +1 -0
- package/src/inspectors/herdr/project-panes.d.ts +137 -0
- package/src/inspectors/herdr/project-panes.d.ts.map +1 -0
- package/src/inspectors/herdr/project-panes.js +608 -0
- package/src/inspectors/herdr/project-panes.js.map +1 -0
- package/src/inspectors/inspector-runner.d.ts +24 -0
- package/src/inspectors/inspector-runner.d.ts.map +1 -0
- package/src/inspectors/inspector-runner.js +162 -0
- package/src/inspectors/inspector-runner.js.map +1 -0
- package/src/inspectors/plugins.d.ts +4 -0
- package/src/inspectors/plugins.d.ts.map +1 -0
- package/src/inspectors/plugins.js +7 -0
- package/src/inspectors/plugins.js.map +1 -0
- package/src/inspectors/session-roots-codec.d.ts +16 -0
- package/src/inspectors/session-roots-codec.d.ts.map +1 -0
- package/src/inspectors/session-roots-codec.js +33 -0
- package/src/inspectors/session-roots-codec.js.map +1 -0
- package/src/inspectors/shell-command.d.ts +2 -0
- package/src/inspectors/shell-command.d.ts.map +1 -0
- package/src/inspectors/shell-command.js +17 -0
- package/src/inspectors/shell-command.js.map +1 -0
- package/src/inspectors/types.d.ts +49 -0
- package/src/inspectors/types.d.ts.map +1 -0
- package/src/inspectors/types.js +2 -0
- package/src/inspectors/types.js.map +1 -0
- package/src/integrations/herdr-status.d.ts +46 -0
- package/src/integrations/herdr-status.d.ts.map +1 -0
- package/src/integrations/herdr-status.js +371 -0
- package/src/integrations/herdr-status.js.map +1 -0
- package/src/integrations/pi-web-session-liveness.d.ts +20 -0
- package/src/integrations/pi-web-session-liveness.d.ts.map +1 -0
- package/src/integrations/pi-web-session-liveness.js +54 -0
- package/src/integrations/pi-web-session-liveness.js.map +1 -0
- package/src/intercom/intercom-bridge.d.ts +59 -0
- package/src/intercom/intercom-bridge.d.ts.map +1 -0
- package/src/intercom/intercom-bridge.js +192 -0
- package/src/intercom/intercom-bridge.js.map +1 -0
- package/src/intercom/native-supervisor-channel.d.ts +64 -0
- package/src/intercom/native-supervisor-channel.d.ts.map +1 -0
- package/src/intercom/native-supervisor-channel.js +894 -0
- package/src/intercom/native-supervisor-channel.js.map +1 -0
- package/src/intercom/result-intercom.d.ts +36 -0
- package/src/intercom/result-intercom.d.ts.map +1 -0
- package/src/intercom/result-intercom.js +372 -0
- package/src/intercom/result-intercom.js.map +1 -0
- package/src/intercom/supervisor-ui.d.ts +40 -0
- package/src/intercom/supervisor-ui.d.ts.map +1 -0
- package/src/intercom/supervisor-ui.js +202 -0
- package/src/intercom/supervisor-ui.js.map +1 -0
- package/src/missions/actions.d.ts +55 -0
- package/src/missions/actions.d.ts.map +1 -0
- package/src/missions/actions.js +396 -0
- package/src/missions/actions.js.map +1 -0
- package/src/missions/goal-driver.d.ts +16 -0
- package/src/missions/goal-driver.d.ts.map +1 -0
- package/src/missions/goal-driver.js +157 -0
- package/src/missions/goal-driver.js.map +1 -0
- package/src/missions/lifecycle.d.ts +40 -0
- package/src/missions/lifecycle.d.ts.map +1 -0
- package/src/missions/lifecycle.js +352 -0
- package/src/missions/lifecycle.js.map +1 -0
- package/src/missions/store.d.ts +22 -0
- package/src/missions/store.d.ts.map +1 -0
- package/src/missions/store.js +573 -0
- package/src/missions/store.js.map +1 -0
- package/src/missions/types.d.ts +168 -0
- package/src/missions/types.d.ts.map +1 -0
- package/src/missions/types.js +10 -0
- package/src/missions/types.js.map +1 -0
- package/src/missions/workflow-state.d.ts +15 -0
- package/src/missions/workflow-state.d.ts.map +1 -0
- package/src/missions/workflow-state.js +274 -0
- package/src/missions/workflow-state.js.map +1 -0
- package/src/policy/authority.d.ts +10 -0
- package/src/policy/authority.d.ts.map +1 -0
- package/src/policy/authority.js +42 -0
- package/src/policy/authority.js.map +1 -0
- package/src/profiles/profiles.d.ts +135 -0
- package/src/profiles/profiles.d.ts.map +1 -0
- package/src/profiles/profiles.js +520 -0
- package/src/profiles/profiles.js.map +1 -0
- package/src/runs/background/active-async-capacity.d.ts +100 -0
- package/src/runs/background/active-async-capacity.d.ts.map +1 -0
- package/src/runs/background/active-async-capacity.js +492 -0
- package/src/runs/background/active-async-capacity.js.map +1 -0
- package/src/runs/background/active-run-index.d.ts +13 -0
- package/src/runs/background/active-run-index.d.ts.map +1 -0
- package/src/runs/background/active-run-index.js +158 -0
- package/src/runs/background/active-run-index.js.map +1 -0
- package/src/runs/background/async-execution.d.ts +274 -0
- package/src/runs/background/async-execution.d.ts.map +1 -0
- package/src/runs/background/async-execution.js +1989 -0
- package/src/runs/background/async-execution.js.map +1 -0
- package/src/runs/background/async-job-tracker.d.ts +28 -0
- package/src/runs/background/async-job-tracker.d.ts.map +1 -0
- package/src/runs/background/async-job-tracker.js +876 -0
- package/src/runs/background/async-job-tracker.js.map +1 -0
- package/src/runs/background/async-resume.d.ts +59 -0
- package/src/runs/background/async-resume.d.ts.map +1 -0
- package/src/runs/background/async-resume.js +670 -0
- package/src/runs/background/async-resume.js.map +1 -0
- package/src/runs/background/async-retention.d.ts +45 -0
- package/src/runs/background/async-retention.d.ts.map +1 -0
- package/src/runs/background/async-retention.js +884 -0
- package/src/runs/background/async-retention.js.map +1 -0
- package/src/runs/background/async-status-snapshot.d.ts +10 -0
- package/src/runs/background/async-status-snapshot.d.ts.map +1 -0
- package/src/runs/background/async-status-snapshot.js +25 -0
- package/src/runs/background/async-status-snapshot.js.map +1 -0
- package/src/runs/background/async-status.d.ts +169 -0
- package/src/runs/background/async-status.d.ts.map +1 -0
- package/src/runs/background/async-status.js +673 -0
- package/src/runs/background/async-status.js.map +1 -0
- package/src/runs/background/auto-drain.d.ts +17 -0
- package/src/runs/background/auto-drain.d.ts.map +1 -0
- package/src/runs/background/auto-drain.js +73 -0
- package/src/runs/background/auto-drain.js.map +1 -0
- package/src/runs/background/binary-bootstrap.d.ts +9 -0
- package/src/runs/background/binary-bootstrap.d.ts.map +1 -0
- package/src/runs/background/binary-bootstrap.js +41 -0
- package/src/runs/background/binary-bootstrap.js.map +1 -0
- package/src/runs/background/chain-append.d.ts +35 -0
- package/src/runs/background/chain-append.d.ts.map +1 -0
- package/src/runs/background/chain-append.js +300 -0
- package/src/runs/background/chain-append.js.map +1 -0
- package/src/runs/background/chain-root-attachment.d.ts +49 -0
- package/src/runs/background/chain-root-attachment.d.ts.map +1 -0
- package/src/runs/background/chain-root-attachment.js +184 -0
- package/src/runs/background/chain-root-attachment.js.map +1 -0
- package/src/runs/background/completion-batcher.d.ts +52 -0
- package/src/runs/background/completion-batcher.d.ts.map +1 -0
- package/src/runs/background/completion-batcher.js +120 -0
- package/src/runs/background/completion-batcher.js.map +1 -0
- package/src/runs/background/completion-dedupe.d.ts +14 -0
- package/src/runs/background/completion-dedupe.d.ts.map +1 -0
- package/src/runs/background/completion-dedupe.js +49 -0
- package/src/runs/background/completion-dedupe.js.map +1 -0
- package/src/runs/background/completion-replay.d.ts +48 -0
- package/src/runs/background/completion-replay.d.ts.map +1 -0
- package/src/runs/background/completion-replay.js +267 -0
- package/src/runs/background/completion-replay.js.map +1 -0
- package/src/runs/background/control-channel.d.ts +156 -0
- package/src/runs/background/control-channel.d.ts.map +1 -0
- package/src/runs/background/control-channel.js +521 -0
- package/src/runs/background/control-channel.js.map +1 -0
- package/src/runs/background/fleet-view.d.ts +64 -0
- package/src/runs/background/fleet-view.d.ts.map +1 -0
- package/src/runs/background/fleet-view.js +648 -0
- package/src/runs/background/fleet-view.js.map +1 -0
- package/src/runs/background/index-segment.d.ts +16 -0
- package/src/runs/background/index-segment.d.ts.map +1 -0
- package/src/runs/background/index-segment.js +59 -0
- package/src/runs/background/index-segment.js.map +1 -0
- package/src/runs/background/inspect-rpc.d.ts +60 -0
- package/src/runs/background/inspect-rpc.d.ts.map +1 -0
- package/src/runs/background/inspect-rpc.js +406 -0
- package/src/runs/background/inspect-rpc.js.map +1 -0
- package/src/runs/background/notify.d.ts +162 -0
- package/src/runs/background/notify.d.ts.map +1 -0
- package/src/runs/background/notify.js +665 -0
- package/src/runs/background/notify.js.map +1 -0
- package/src/runs/background/owned-process-tree.d.ts +11 -0
- package/src/runs/background/owned-process-tree.d.ts.map +1 -0
- package/src/runs/background/owned-process-tree.js +117 -0
- package/src/runs/background/owned-process-tree.js.map +1 -0
- package/src/runs/background/parallel-groups.d.ts +4 -0
- package/src/runs/background/parallel-groups.d.ts.map +1 -0
- package/src/runs/background/parallel-groups.js +47 -0
- package/src/runs/background/parallel-groups.js.map +1 -0
- package/src/runs/background/process-terminal.d.ts +34 -0
- package/src/runs/background/process-terminal.d.ts.map +1 -0
- package/src/runs/background/process-terminal.js +305 -0
- package/src/runs/background/process-terminal.js.map +1 -0
- package/src/runs/background/result-delivery-ownership.d.ts +11 -0
- package/src/runs/background/result-delivery-ownership.d.ts.map +1 -0
- package/src/runs/background/result-delivery-ownership.js +37 -0
- package/src/runs/background/result-delivery-ownership.js.map +1 -0
- package/src/runs/background/result-files.d.ts +33 -0
- package/src/runs/background/result-files.d.ts.map +1 -0
- package/src/runs/background/result-files.js +528 -0
- package/src/runs/background/result-files.js.map +1 -0
- package/src/runs/background/result-watcher.d.ts +87 -0
- package/src/runs/background/result-watcher.d.ts.map +1 -0
- package/src/runs/background/result-watcher.js +764 -0
- package/src/runs/background/result-watcher.js.map +1 -0
- package/src/runs/background/resume-guidance.d.ts +5 -0
- package/src/runs/background/resume-guidance.d.ts.map +1 -0
- package/src/runs/background/resume-guidance.js +57 -0
- package/src/runs/background/resume-guidance.js.map +1 -0
- package/src/runs/background/retained-children.d.ts +25 -0
- package/src/runs/background/retained-children.d.ts.map +1 -0
- package/src/runs/background/retained-children.js +128 -0
- package/src/runs/background/retained-children.js.map +1 -0
- package/src/runs/background/retained-nested-route-tracker.d.ts +13 -0
- package/src/runs/background/retained-nested-route-tracker.d.ts.map +1 -0
- package/src/runs/background/retained-nested-route-tracker.js +91 -0
- package/src/runs/background/retained-nested-route-tracker.js.map +1 -0
- package/src/runs/background/run-child-session.d.ts +123 -0
- package/src/runs/background/run-child-session.d.ts.map +1 -0
- package/src/runs/background/run-child-session.js +602 -0
- package/src/runs/background/run-child-session.js.map +1 -0
- package/src/runs/background/run-id-query.d.ts +4 -0
- package/src/runs/background/run-id-query.d.ts.map +1 -0
- package/src/runs/background/run-id-query.js +7 -0
- package/src/runs/background/run-id-query.js.map +1 -0
- package/src/runs/background/run-id-resolver.d.ts +23 -0
- package/src/runs/background/run-id-resolver.d.ts.map +1 -0
- package/src/runs/background/run-id-resolver.js +170 -0
- package/src/runs/background/run-id-resolver.js.map +1 -0
- package/src/runs/background/run-status.d.ts +26 -0
- package/src/runs/background/run-status.d.ts.map +1 -0
- package/src/runs/background/run-status.js +826 -0
- package/src/runs/background/run-status.js.map +1 -0
- package/src/runs/background/runner-aliases.d.ts +17 -0
- package/src/runs/background/runner-aliases.d.ts.map +1 -0
- package/src/runs/background/runner-aliases.js +141 -0
- package/src/runs/background/runner-aliases.js.map +1 -0
- package/src/runs/background/runner-child-launch.d.ts +24 -0
- package/src/runs/background/runner-child-launch.d.ts.map +1 -0
- package/src/runs/background/runner-child-launch.js +68 -0
- package/src/runs/background/runner-child-launch.js.map +1 -0
- package/src/runs/background/runner-child-sessions.d.ts +7 -0
- package/src/runs/background/runner-child-sessions.d.ts.map +1 -0
- package/src/runs/background/runner-child-sessions.js +35 -0
- package/src/runs/background/runner-child-sessions.js.map +1 -0
- package/src/runs/background/runner-http-dispatcher.d.ts +43 -0
- package/src/runs/background/runner-http-dispatcher.d.ts.map +1 -0
- package/src/runs/background/runner-http-dispatcher.js +114 -0
- package/src/runs/background/runner-http-dispatcher.js.map +1 -0
- package/src/runs/background/scheduled-runs.d.ts +116 -0
- package/src/runs/background/scheduled-runs.d.ts.map +1 -0
- package/src/runs/background/scheduled-runs.js +1024 -0
- package/src/runs/background/scheduled-runs.js.map +1 -0
- package/src/runs/background/stale-run-reconciler.d.ts +37 -0
- package/src/runs/background/stale-run-reconciler.d.ts.map +1 -0
- package/src/runs/background/stale-run-reconciler.js +393 -0
- package/src/runs/background/stale-run-reconciler.js.map +1 -0
- package/src/runs/background/steering.d.ts +52 -0
- package/src/runs/background/steering.d.ts.map +1 -0
- package/src/runs/background/steering.js +247 -0
- package/src/runs/background/steering.js.map +1 -0
- package/src/runs/background/subagent-runner.d.ts +201 -0
- package/src/runs/background/subagent-runner.d.ts.map +1 -0
- package/src/runs/background/subagent-runner.js +5134 -0
- package/src/runs/background/subagent-runner.js.map +1 -0
- package/src/runs/background/subagent-wait.d.ts +122 -0
- package/src/runs/background/subagent-wait.d.ts.map +1 -0
- package/src/runs/background/subagent-wait.js +735 -0
- package/src/runs/background/subagent-wait.js.map +1 -0
- package/src/runs/background/terminal-run-index.d.ts +8 -0
- package/src/runs/background/terminal-run-index.d.ts.map +1 -0
- package/src/runs/background/terminal-run-index.js +123 -0
- package/src/runs/background/terminal-run-index.js.map +1 -0
- package/src/runs/background/top-level-async.d.ts +8 -0
- package/src/runs/background/top-level-async.d.ts.map +1 -0
- package/src/runs/background/top-level-async.js +6 -0
- package/src/runs/background/top-level-async.js.map +1 -0
- package/src/runs/background/wait-completions.d.ts +29 -0
- package/src/runs/background/wait-completions.d.ts.map +1 -0
- package/src/runs/background/wait-completions.js +264 -0
- package/src/runs/background/wait-completions.js.map +1 -0
- package/src/runs/background/wait-config.d.ts +9 -0
- package/src/runs/background/wait-config.d.ts.map +1 -0
- package/src/runs/background/wait-config.js +47 -0
- package/src/runs/background/wait-config.js.map +1 -0
- package/src/runs/background/wait-subscriptions.d.ts +27 -0
- package/src/runs/background/wait-subscriptions.d.ts.map +1 -0
- package/src/runs/background/wait-subscriptions.js +337 -0
- package/src/runs/background/wait-subscriptions.js.map +1 -0
- package/src/runs/background/wait-tool.d.ts +7 -0
- package/src/runs/background/wait-tool.d.ts.map +1 -0
- package/src/runs/background/wait-tool.js +36 -0
- package/src/runs/background/wait-tool.js.map +1 -0
- package/src/runs/foreground/async-dismiss-action.d.ts +7 -0
- package/src/runs/foreground/async-dismiss-action.d.ts.map +1 -0
- package/src/runs/foreground/async-dismiss-action.js +82 -0
- package/src/runs/foreground/async-dismiss-action.js.map +1 -0
- package/src/runs/foreground/async-steering-action.d.ts +32 -0
- package/src/runs/foreground/async-steering-action.d.ts.map +1 -0
- package/src/runs/foreground/async-steering-action.js +270 -0
- package/src/runs/foreground/async-steering-action.js.map +1 -0
- package/src/runs/foreground/async-stop-action.d.ts +7 -0
- package/src/runs/foreground/async-stop-action.d.ts.map +1 -0
- package/src/runs/foreground/async-stop-action.js +171 -0
- package/src/runs/foreground/async-stop-action.js.map +1 -0
- package/src/runs/foreground/execution.d.ts +11 -0
- package/src/runs/foreground/execution.d.ts.map +1 -0
- package/src/runs/foreground/execution.js +2186 -0
- package/src/runs/foreground/execution.js.map +1 -0
- package/src/runs/foreground/foreground-control.d.ts +25 -0
- package/src/runs/foreground/foreground-control.d.ts.map +1 -0
- package/src/runs/foreground/foreground-control.js +139 -0
- package/src/runs/foreground/foreground-control.js.map +1 -0
- package/src/runs/foreground/foreground-history.d.ts +12 -0
- package/src/runs/foreground/foreground-history.d.ts.map +1 -0
- package/src/runs/foreground/foreground-history.js +165 -0
- package/src/runs/foreground/foreground-history.js.map +1 -0
- package/src/runs/foreground/prompt-audit.d.ts +33 -0
- package/src/runs/foreground/prompt-audit.d.ts.map +1 -0
- package/src/runs/foreground/prompt-audit.js +143 -0
- package/src/runs/foreground/prompt-audit.js.map +1 -0
- package/src/runs/foreground/subagent-executor.d.ts +296 -0
- package/src/runs/foreground/subagent-executor.d.ts.map +1 -0
- package/src/runs/foreground/subagent-executor.js +7047 -0
- package/src/runs/foreground/subagent-executor.js.map +1 -0
- package/src/runs/foreground/workflow-detach-reconcile.d.ts +16 -0
- package/src/runs/foreground/workflow-detach-reconcile.d.ts.map +1 -0
- package/src/runs/foreground/workflow-detach-reconcile.js +284 -0
- package/src/runs/foreground/workflow-detach-reconcile.js.map +1 -0
- package/src/runs/foreground/workflow-foreground-steering.d.ts +44 -0
- package/src/runs/foreground/workflow-foreground-steering.d.ts.map +1 -0
- package/src/runs/foreground/workflow-foreground-steering.js +149 -0
- package/src/runs/foreground/workflow-foreground-steering.js.map +1 -0
- package/src/runs/shared/abort-recovery.d.ts +27 -0
- package/src/runs/shared/abort-recovery.d.ts.map +1 -0
- package/src/runs/shared/abort-recovery.js +109 -0
- package/src/runs/shared/abort-recovery.js.map +1 -0
- package/src/runs/shared/acceptance.d.ts +145 -0
- package/src/runs/shared/acceptance.d.ts.map +1 -0
- package/src/runs/shared/acceptance.js +1650 -0
- package/src/runs/shared/acceptance.js.map +1 -0
- package/src/runs/shared/agent-contract.d.ts +6 -0
- package/src/runs/shared/agent-contract.d.ts.map +1 -0
- package/src/runs/shared/agent-contract.js +36 -0
- package/src/runs/shared/agent-contract.js.map +1 -0
- package/src/runs/shared/async-status-projection.d.ts +94 -0
- package/src/runs/shared/async-status-projection.d.ts.map +1 -0
- package/src/runs/shared/async-status-projection.js +542 -0
- package/src/runs/shared/async-status-projection.js.map +1 -0
- package/src/runs/shared/background-process-options.d.ts +5 -0
- package/src/runs/shared/background-process-options.d.ts.map +1 -0
- package/src/runs/shared/background-process-options.js +7 -0
- package/src/runs/shared/background-process-options.js.map +1 -0
- package/src/runs/shared/capability-ceiling.d.ts +58 -0
- package/src/runs/shared/capability-ceiling.d.ts.map +1 -0
- package/src/runs/shared/capability-ceiling.js +179 -0
- package/src/runs/shared/capability-ceiling.js.map +1 -0
- package/src/runs/shared/chain-outputs.d.ts +19 -0
- package/src/runs/shared/chain-outputs.d.ts.map +1 -0
- package/src/runs/shared/chain-outputs.js +105 -0
- package/src/runs/shared/chain-outputs.js.map +1 -0
- package/src/runs/shared/child-hooks.d.ts +34 -0
- package/src/runs/shared/child-hooks.d.ts.map +1 -0
- package/src/runs/shared/child-hooks.js +188 -0
- package/src/runs/shared/child-hooks.js.map +1 -0
- package/src/runs/shared/child-identity.d.ts +24 -0
- package/src/runs/shared/child-identity.d.ts.map +1 -0
- package/src/runs/shared/child-identity.js +41 -0
- package/src/runs/shared/child-identity.js.map +1 -0
- package/src/runs/shared/child-launch-plan.d.ts +71 -0
- package/src/runs/shared/child-launch-plan.d.ts.map +1 -0
- package/src/runs/shared/child-launch-plan.js +89 -0
- package/src/runs/shared/child-launch-plan.js.map +1 -0
- package/src/runs/shared/child-launch.d.ts +114 -0
- package/src/runs/shared/child-launch.d.ts.map +1 -0
- package/src/runs/shared/child-launch.js +231 -0
- package/src/runs/shared/child-launch.js.map +1 -0
- package/src/runs/shared/child-lifecycle.d.ts +14 -0
- package/src/runs/shared/child-lifecycle.d.ts.map +1 -0
- package/src/runs/shared/child-lifecycle.js +23 -0
- package/src/runs/shared/child-lifecycle.js.map +1 -0
- package/src/runs/shared/child-runtime-config.d.ts +102 -0
- package/src/runs/shared/child-runtime-config.d.ts.map +1 -0
- package/src/runs/shared/child-runtime-config.js +39 -0
- package/src/runs/shared/child-runtime-config.js.map +1 -0
- package/src/runs/shared/child-session.d.ts +155 -0
- package/src/runs/shared/child-session.d.ts.map +1 -0
- package/src/runs/shared/child-session.js +347 -0
- package/src/runs/shared/child-session.js.map +1 -0
- package/src/runs/shared/child-tool-plan.d.ts +73 -0
- package/src/runs/shared/child-tool-plan.d.ts.map +1 -0
- package/src/runs/shared/child-tool-plan.js +380 -0
- package/src/runs/shared/child-tool-plan.js.map +1 -0
- package/src/runs/shared/claude-code-adapter.d.ts +25 -0
- package/src/runs/shared/claude-code-adapter.d.ts.map +1 -0
- package/src/runs/shared/claude-code-adapter.js +120 -0
- package/src/runs/shared/claude-code-adapter.js.map +1 -0
- package/src/runs/shared/codex-exec-adapter.d.ts +26 -0
- package/src/runs/shared/codex-exec-adapter.d.ts.map +1 -0
- package/src/runs/shared/codex-exec-adapter.js +128 -0
- package/src/runs/shared/codex-exec-adapter.js.map +1 -0
- package/src/runs/shared/completion-evidence.d.ts +31 -0
- package/src/runs/shared/completion-evidence.d.ts.map +1 -0
- package/src/runs/shared/completion-evidence.js +54 -0
- package/src/runs/shared/completion-evidence.js.map +1 -0
- package/src/runs/shared/completion-guard.d.ts +35 -0
- package/src/runs/shared/completion-guard.d.ts.map +1 -0
- package/src/runs/shared/completion-guard.js +214 -0
- package/src/runs/shared/completion-guard.js.map +1 -0
- package/src/runs/shared/context-mode.d.ts +13 -0
- package/src/runs/shared/context-mode.d.ts.map +1 -0
- package/src/runs/shared/context-mode.js +39 -0
- package/src/runs/shared/context-mode.js.map +1 -0
- package/src/runs/shared/cursor-agent-adapter.d.ts +27 -0
- package/src/runs/shared/cursor-agent-adapter.d.ts.map +1 -0
- package/src/runs/shared/cursor-agent-adapter.js +100 -0
- package/src/runs/shared/cursor-agent-adapter.js.map +1 -0
- package/src/runs/shared/dynamic-fanout.d.ts +50 -0
- package/src/runs/shared/dynamic-fanout.d.ts.map +1 -0
- package/src/runs/shared/dynamic-fanout.js +274 -0
- package/src/runs/shared/dynamic-fanout.js.map +1 -0
- package/src/runs/shared/effective-system-prompt.d.ts +18 -0
- package/src/runs/shared/effective-system-prompt.d.ts.map +1 -0
- package/src/runs/shared/effective-system-prompt.js +23 -0
- package/src/runs/shared/effective-system-prompt.js.map +1 -0
- package/src/runs/shared/extension-bindings.d.ts +17 -0
- package/src/runs/shared/extension-bindings.d.ts.map +1 -0
- package/src/runs/shared/extension-bindings.js +83 -0
- package/src/runs/shared/extension-bindings.js.map +1 -0
- package/src/runs/shared/external-cli-contract.d.ts +30 -0
- package/src/runs/shared/external-cli-contract.d.ts.map +1 -0
- package/src/runs/shared/external-cli-contract.js +146 -0
- package/src/runs/shared/external-cli-contract.js.map +1 -0
- package/src/runs/shared/external-cli-preflight.d.ts +32 -0
- package/src/runs/shared/external-cli-preflight.d.ts.map +1 -0
- package/src/runs/shared/external-cli-preflight.js +116 -0
- package/src/runs/shared/external-cli-preflight.js.map +1 -0
- package/src/runs/shared/external-cli-runner.d.ts +66 -0
- package/src/runs/shared/external-cli-runner.d.ts.map +1 -0
- package/src/runs/shared/external-cli-runner.js +421 -0
- package/src/runs/shared/external-cli-runner.js.map +1 -0
- package/src/runs/shared/external-job-bridge.d.ts +18 -0
- package/src/runs/shared/external-job-bridge.d.ts.map +1 -0
- package/src/runs/shared/external-job-bridge.js +424 -0
- package/src/runs/shared/external-job-bridge.js.map +1 -0
- package/src/runs/shared/external-job-runner.d.ts +45 -0
- package/src/runs/shared/external-job-runner.d.ts.map +1 -0
- package/src/runs/shared/external-job-runner.js +353 -0
- package/src/runs/shared/external-job-runner.js.map +1 -0
- package/src/runs/shared/fast-mode-extension.d.ts +4 -0
- package/src/runs/shared/fast-mode-extension.d.ts.map +1 -0
- package/src/runs/shared/fast-mode-extension.js +9 -0
- package/src/runs/shared/fast-mode-extension.js.map +1 -0
- package/src/runs/shared/herdr-connection.d.ts +71 -0
- package/src/runs/shared/herdr-connection.d.ts.map +1 -0
- package/src/runs/shared/herdr-connection.js +258 -0
- package/src/runs/shared/herdr-connection.js.map +1 -0
- package/src/runs/shared/herdr-external-adapters.d.ts +148 -0
- package/src/runs/shared/herdr-external-adapters.d.ts.map +1 -0
- package/src/runs/shared/herdr-external-adapters.js +405 -0
- package/src/runs/shared/herdr-external-adapters.js.map +1 -0
- package/src/runs/shared/herdr-machine.d.ts +48 -0
- package/src/runs/shared/herdr-machine.d.ts.map +1 -0
- package/src/runs/shared/herdr-machine.js +247 -0
- package/src/runs/shared/herdr-machine.js.map +1 -0
- package/src/runs/shared/herdr-pi-protocol.d.ts +22 -0
- package/src/runs/shared/herdr-pi-protocol.d.ts.map +1 -0
- package/src/runs/shared/herdr-pi-protocol.js +58 -0
- package/src/runs/shared/herdr-pi-protocol.js.map +1 -0
- package/src/runs/shared/herdr-placed-run.d.ts +267 -0
- package/src/runs/shared/herdr-placed-run.d.ts.map +1 -0
- package/src/runs/shared/herdr-placed-run.js +716 -0
- package/src/runs/shared/herdr-placed-run.js.map +1 -0
- package/src/runs/shared/host-step-status.d.ts +34 -0
- package/src/runs/shared/host-step-status.d.ts.map +1 -0
- package/src/runs/shared/host-step-status.js +245 -0
- package/src/runs/shared/host-step-status.js.map +1 -0
- package/src/runs/shared/lane-metadata.d.ts +24 -0
- package/src/runs/shared/lane-metadata.d.ts.map +1 -0
- package/src/runs/shared/lane-metadata.js +127 -0
- package/src/runs/shared/lane-metadata.js.map +1 -0
- package/src/runs/shared/launch-cwd.d.ts +2 -0
- package/src/runs/shared/launch-cwd.d.ts.map +1 -0
- package/src/runs/shared/launch-cwd.js +17 -0
- package/src/runs/shared/launch-cwd.js.map +1 -0
- package/src/runs/shared/llm-intent-arbiter.d.ts +48 -0
- package/src/runs/shared/llm-intent-arbiter.d.ts.map +1 -0
- package/src/runs/shared/llm-intent-arbiter.js +235 -0
- package/src/runs/shared/llm-intent-arbiter.js.map +1 -0
- package/src/runs/shared/long-running-guard.d.ts +33 -0
- package/src/runs/shared/long-running-guard.d.ts.map +1 -0
- package/src/runs/shared/long-running-guard.js +199 -0
- package/src/runs/shared/long-running-guard.js.map +1 -0
- package/src/runs/shared/mcp-config-sources.d.ts +30 -0
- package/src/runs/shared/mcp-config-sources.d.ts.map +1 -0
- package/src/runs/shared/mcp-config-sources.js +419 -0
- package/src/runs/shared/mcp-config-sources.js.map +1 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +59 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts.map +1 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.js +400 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.js.map +1 -0
- package/src/runs/shared/mcp-direct-tool-grant.d.ts +41 -0
- package/src/runs/shared/mcp-direct-tool-grant.d.ts.map +1 -0
- package/src/runs/shared/mcp-direct-tool-grant.js +146 -0
- package/src/runs/shared/mcp-direct-tool-grant.js.map +1 -0
- package/src/runs/shared/model-resolution-diagnostic.d.ts +22 -0
- package/src/runs/shared/model-resolution-diagnostic.d.ts.map +1 -0
- package/src/runs/shared/model-resolution-diagnostic.js +65 -0
- package/src/runs/shared/model-resolution-diagnostic.js.map +1 -0
- package/src/runs/shared/model-resolution.d.ts +92 -0
- package/src/runs/shared/model-resolution.d.ts.map +1 -0
- package/src/runs/shared/model-resolution.js +343 -0
- package/src/runs/shared/model-resolution.js.map +1 -0
- package/src/runs/shared/model-scope.d.ts +68 -0
- package/src/runs/shared/model-scope.d.ts.map +1 -0
- package/src/runs/shared/model-scope.js +156 -0
- package/src/runs/shared/model-scope.js.map +1 -0
- package/src/runs/shared/mutation-evidence.d.ts +19 -0
- package/src/runs/shared/mutation-evidence.d.ts.map +1 -0
- package/src/runs/shared/mutation-evidence.js +199 -0
- package/src/runs/shared/mutation-evidence.js.map +1 -0
- package/src/runs/shared/nested-events.d.ts +134 -0
- package/src/runs/shared/nested-events.d.ts.map +1 -0
- package/src/runs/shared/nested-events.js +1056 -0
- package/src/runs/shared/nested-events.js.map +1 -0
- package/src/runs/shared/nested-path.d.ts +9 -0
- package/src/runs/shared/nested-path.d.ts.map +1 -0
- package/src/runs/shared/nested-path.js +35 -0
- package/src/runs/shared/nested-path.js.map +1 -0
- package/src/runs/shared/nested-render.d.ts +21 -0
- package/src/runs/shared/nested-render.d.ts.map +1 -0
- package/src/runs/shared/nested-render.js +116 -0
- package/src/runs/shared/nested-render.js.map +1 -0
- package/src/runs/shared/orca-progress-tabs.d.ts +33 -0
- package/src/runs/shared/orca-progress-tabs.d.ts.map +1 -0
- package/src/runs/shared/orca-progress-tabs.js +527 -0
- package/src/runs/shared/orca-progress-tabs.js.map +1 -0
- package/src/runs/shared/parallel-handoff.d.ts +73 -0
- package/src/runs/shared/parallel-handoff.d.ts.map +1 -0
- package/src/runs/shared/parallel-handoff.js +733 -0
- package/src/runs/shared/parallel-handoff.js.map +1 -0
- package/src/runs/shared/parallel-utils.d.ts +165 -0
- package/src/runs/shared/parallel-utils.d.ts.map +1 -0
- package/src/runs/shared/parallel-utils.js +126 -0
- package/src/runs/shared/parallel-utils.js.map +1 -0
- package/src/runs/shared/permissions.d.ts +13 -0
- package/src/runs/shared/permissions.d.ts.map +1 -0
- package/src/runs/shared/permissions.js +93 -0
- package/src/runs/shared/permissions.js.map +1 -0
- package/src/runs/shared/pi-spawn.d.ts +28 -0
- package/src/runs/shared/pi-spawn.d.ts.map +1 -0
- package/src/runs/shared/pi-spawn.js +156 -0
- package/src/runs/shared/pi-spawn.js.map +1 -0
- package/src/runs/shared/process-signal.d.ts +16 -0
- package/src/runs/shared/process-signal.d.ts.map +1 -0
- package/src/runs/shared/process-signal.js +22 -0
- package/src/runs/shared/process-signal.js.map +1 -0
- package/src/runs/shared/readonly-drain-observation.d.ts +26 -0
- package/src/runs/shared/readonly-drain-observation.d.ts.map +1 -0
- package/src/runs/shared/readonly-drain-observation.js +51 -0
- package/src/runs/shared/readonly-drain-observation.js.map +1 -0
- package/src/runs/shared/run-fanout-budget.d.ts +15 -0
- package/src/runs/shared/run-fanout-budget.d.ts.map +1 -0
- package/src/runs/shared/run-fanout-budget.js +259 -0
- package/src/runs/shared/run-fanout-budget.js.map +1 -0
- package/src/runs/shared/run-history.d.ts +20 -0
- package/src/runs/shared/run-history.d.ts.map +1 -0
- package/src/runs/shared/run-history.js +200 -0
- package/src/runs/shared/run-history.js.map +1 -0
- package/src/runs/shared/runtime-acknowledged-extensions.d.ts +8 -0
- package/src/runs/shared/runtime-acknowledged-extensions.d.ts.map +1 -0
- package/src/runs/shared/runtime-acknowledged-extensions.js +45 -0
- package/src/runs/shared/runtime-acknowledged-extensions.js.map +1 -0
- package/src/runs/shared/session-lease.d.ts +70 -0
- package/src/runs/shared/session-lease.d.ts.map +1 -0
- package/src/runs/shared/session-lease.js +251 -0
- package/src/runs/shared/session-lease.js.map +1 -0
- package/src/runs/shared/single-output.d.ts +61 -0
- package/src/runs/shared/single-output.d.ts.map +1 -0
- package/src/runs/shared/single-output.js +263 -0
- package/src/runs/shared/single-output.js.map +1 -0
- package/src/runs/shared/spawn-budget.d.ts +21 -0
- package/src/runs/shared/spawn-budget.d.ts.map +1 -0
- package/src/runs/shared/spawn-budget.js +94 -0
- package/src/runs/shared/spawn-budget.js.map +1 -0
- package/src/runs/shared/structured-output.d.ts +57 -0
- package/src/runs/shared/structured-output.d.ts.map +1 -0
- package/src/runs/shared/structured-output.js +391 -0
- package/src/runs/shared/structured-output.js.map +1 -0
- package/src/runs/shared/subagent-control.d.ts +50 -0
- package/src/runs/shared/subagent-control.d.ts.map +1 -0
- package/src/runs/shared/subagent-control.js +247 -0
- package/src/runs/shared/subagent-control.js.map +1 -0
- package/src/runs/shared/subagent-prompt-runtime.d.ts +28 -0
- package/src/runs/shared/subagent-prompt-runtime.d.ts.map +1 -0
- package/src/runs/shared/subagent-prompt-runtime.js +548 -0
- package/src/runs/shared/subagent-prompt-runtime.js.map +1 -0
- package/src/runs/shared/task-intent.d.ts +38 -0
- package/src/runs/shared/task-intent.d.ts.map +1 -0
- package/src/runs/shared/task-intent.js +213 -0
- package/src/runs/shared/task-intent.js.map +1 -0
- package/src/runs/shared/tool-availability.d.ts +17 -0
- package/src/runs/shared/tool-availability.d.ts.map +1 -0
- package/src/runs/shared/tool-availability.js +30 -0
- package/src/runs/shared/tool-availability.js.map +1 -0
- package/src/runs/shared/tool-budget.d.ts +22 -0
- package/src/runs/shared/tool-budget.d.ts.map +1 -0
- package/src/runs/shared/tool-budget.js +79 -0
- package/src/runs/shared/tool-budget.js.map +1 -0
- package/src/runs/shared/tool-timeout.d.ts +32 -0
- package/src/runs/shared/tool-timeout.d.ts.map +1 -0
- package/src/runs/shared/tool-timeout.js +74 -0
- package/src/runs/shared/tool-timeout.js.map +1 -0
- package/src/runs/shared/usage-budget.d.ts +8 -0
- package/src/runs/shared/usage-budget.d.ts.map +1 -0
- package/src/runs/shared/usage-budget.js +75 -0
- package/src/runs/shared/usage-budget.js.map +1 -0
- package/src/runs/shared/usage-reconciliation.d.ts +9 -0
- package/src/runs/shared/usage-reconciliation.d.ts.map +1 -0
- package/src/runs/shared/usage-reconciliation.js +72 -0
- package/src/runs/shared/usage-reconciliation.js.map +1 -0
- package/src/runs/shared/workflow-async-child-guidance.d.ts +4 -0
- package/src/runs/shared/workflow-async-child-guidance.d.ts.map +1 -0
- package/src/runs/shared/workflow-async-child-guidance.js +18 -0
- package/src/runs/shared/workflow-async-child-guidance.js.map +1 -0
- package/src/runs/shared/workflow-graph.d.ts +32 -0
- package/src/runs/shared/workflow-graph.d.ts.map +1 -0
- package/src/runs/shared/workflow-graph.js +222 -0
- package/src/runs/shared/workflow-graph.js.map +1 -0
- package/src/runs/shared/worktree-cleanup-plan.d.ts +78 -0
- package/src/runs/shared/worktree-cleanup-plan.d.ts.map +1 -0
- package/src/runs/shared/worktree-cleanup-plan.js +782 -0
- package/src/runs/shared/worktree-cleanup-plan.js.map +1 -0
- package/src/runs/shared/worktree-setup-command.d.ts +39 -0
- package/src/runs/shared/worktree-setup-command.d.ts.map +1 -0
- package/src/runs/shared/worktree-setup-command.js +201 -0
- package/src/runs/shared/worktree-setup-command.js.map +1 -0
- package/src/runs/shared/worktree.d.ts +179 -0
- package/src/runs/shared/worktree.d.ts.map +1 -0
- package/src/runs/shared/worktree.js +1333 -0
- package/src/runs/shared/worktree.js.map +1 -0
- package/src/shared/accessible-dir.d.ts +12 -0
- package/src/shared/accessible-dir.d.ts.map +1 -0
- package/src/shared/accessible-dir.js +37 -0
- package/src/shared/accessible-dir.js.map +1 -0
- package/src/shared/agent-stream-options.d.ts +6 -0
- package/src/shared/agent-stream-options.d.ts.map +1 -0
- package/src/shared/agent-stream-options.js +4 -0
- package/src/shared/agent-stream-options.js.map +1 -0
- package/src/shared/artifacts.d.ts +23 -0
- package/src/shared/artifacts.d.ts.map +1 -0
- package/src/shared/artifacts.js +273 -0
- package/src/shared/artifacts.js.map +1 -0
- package/src/shared/atomic-json.d.ts +19 -0
- package/src/shared/atomic-json.d.ts.map +1 -0
- package/src/shared/atomic-json.js +60 -0
- package/src/shared/atomic-json.js.map +1 -0
- package/src/shared/capacity-resilient-json.d.ts +27 -0
- package/src/shared/capacity-resilient-json.d.ts.map +1 -0
- package/src/shared/capacity-resilient-json.js +87 -0
- package/src/shared/capacity-resilient-json.js.map +1 -0
- package/src/shared/child-cache-retention.d.ts +30 -0
- package/src/shared/child-cache-retention.d.ts.map +1 -0
- package/src/shared/child-cache-retention.js +41 -0
- package/src/shared/child-cache-retention.js.map +1 -0
- package/src/shared/child-session-name.d.ts +9 -0
- package/src/shared/child-session-name.d.ts.map +1 -0
- package/src/shared/child-session-name.js +39 -0
- package/src/shared/child-session-name.js.map +1 -0
- package/src/shared/child-transcript.d.ts +38 -0
- package/src/shared/child-transcript.d.ts.map +1 -0
- package/src/shared/child-transcript.js +226 -0
- package/src/shared/child-transcript.js.map +1 -0
- package/src/shared/completion-owner.d.ts +3 -0
- package/src/shared/completion-owner.d.ts.map +1 -0
- package/src/shared/completion-owner.js +9 -0
- package/src/shared/completion-owner.js.map +1 -0
- package/src/shared/display-text.d.ts +6 -0
- package/src/shared/display-text.d.ts.map +1 -0
- package/src/shared/display-text.js +155 -0
- package/src/shared/display-text.js.map +1 -0
- package/src/shared/extension-context.d.ts +6 -0
- package/src/shared/extension-context.d.ts.map +1 -0
- package/src/shared/extension-context.js +22 -0
- package/src/shared/extension-context.js.map +1 -0
- package/src/shared/file-coalescer.d.ts +12 -0
- package/src/shared/file-coalescer.d.ts.map +1 -0
- package/src/shared/file-coalescer.js +35 -0
- package/src/shared/file-coalescer.js.map +1 -0
- package/src/shared/file-system-retry.d.ts +32 -0
- package/src/shared/file-system-retry.d.ts.map +1 -0
- package/src/shared/file-system-retry.js +85 -0
- package/src/shared/file-system-retry.js.map +1 -0
- package/src/shared/fork-context.d.ts +59 -0
- package/src/shared/fork-context.d.ts.map +1 -0
- package/src/shared/fork-context.js +171 -0
- package/src/shared/fork-context.js.map +1 -0
- package/src/shared/fork-session-cwd.d.ts +3 -0
- package/src/shared/fork-session-cwd.d.ts.map +1 -0
- package/src/shared/fork-session-cwd.js +24 -0
- package/src/shared/fork-session-cwd.js.map +1 -0
- package/src/shared/formatters.d.ts +36 -0
- package/src/shared/formatters.d.ts.map +1 -0
- package/src/shared/formatters.js +143 -0
- package/src/shared/formatters.js.map +1 -0
- package/src/shared/jsonl-writer.d.ts +21 -0
- package/src/shared/jsonl-writer.d.ts.map +1 -0
- package/src/shared/jsonl-writer.js +68 -0
- package/src/shared/jsonl-writer.js.map +1 -0
- package/src/shared/launch-contract.d.ts +64 -0
- package/src/shared/launch-contract.d.ts.map +1 -0
- package/src/shared/launch-contract.js +141 -0
- package/src/shared/launch-contract.js.map +1 -0
- package/src/shared/model-info.d.ts +44 -0
- package/src/shared/model-info.d.ts.map +1 -0
- package/src/shared/model-info.js +73 -0
- package/src/shared/model-info.js.map +1 -0
- package/src/shared/model-response-aliases.d.ts +2 -0
- package/src/shared/model-response-aliases.d.ts.map +1 -0
- package/src/shared/model-response-aliases.js +16 -0
- package/src/shared/model-response-aliases.js.map +1 -0
- package/src/shared/node-executable.d.ts +2 -0
- package/src/shared/node-executable.d.ts.map +1 -0
- package/src/shared/node-executable.js +21 -0
- package/src/shared/node-executable.js.map +1 -0
- package/src/shared/opencode-session-headers.d.ts +13 -0
- package/src/shared/opencode-session-headers.d.ts.map +1 -0
- package/src/shared/opencode-session-headers.js +27 -0
- package/src/shared/opencode-session-headers.js.map +1 -0
- package/src/shared/prompt-resources.d.ts +6 -0
- package/src/shared/prompt-resources.d.ts.map +1 -0
- package/src/shared/prompt-resources.js +11 -0
- package/src/shared/prompt-resources.js.map +1 -0
- package/src/shared/pruned-fork.d.ts +35 -0
- package/src/shared/pruned-fork.d.ts.map +1 -0
- package/src/shared/pruned-fork.js +424 -0
- package/src/shared/pruned-fork.js.map +1 -0
- package/src/shared/required-child-extensions.d.ts +20 -0
- package/src/shared/required-child-extensions.d.ts.map +1 -0
- package/src/shared/required-child-extensions.js +74 -0
- package/src/shared/required-child-extensions.js.map +1 -0
- package/src/shared/session-file-trust.d.ts +2 -0
- package/src/shared/session-file-trust.d.ts.map +1 -0
- package/src/shared/session-file-trust.js +21 -0
- package/src/shared/session-file-trust.js.map +1 -0
- package/src/shared/session-identity.d.ts +7 -0
- package/src/shared/session-identity.d.ts.map +1 -0
- package/src/shared/session-identity.js +7 -0
- package/src/shared/session-identity.js.map +1 -0
- package/src/shared/session-tokens.d.ts +3 -0
- package/src/shared/session-tokens.d.ts.map +1 -0
- package/src/shared/session-tokens.js +59 -0
- package/src/shared/session-tokens.js.map +1 -0
- package/src/shared/settings.d.ts +147 -0
- package/src/shared/settings.d.ts.map +1 -0
- package/src/shared/settings.js +248 -0
- package/src/shared/settings.js.map +1 -0
- package/src/shared/shortcuts.d.ts +2 -0
- package/src/shared/shortcuts.d.ts.map +1 -0
- package/src/shared/shortcuts.js +18 -0
- package/src/shared/shortcuts.js.map +1 -0
- package/src/shared/status-format.d.ts +10 -0
- package/src/shared/status-format.d.ts.map +1 -0
- package/src/shared/status-format.js +61 -0
- package/src/shared/status-format.js.map +1 -0
- package/src/shared/thinking-ceiling.d.ts +14 -0
- package/src/shared/thinking-ceiling.d.ts.map +1 -0
- package/src/shared/thinking-ceiling.js +38 -0
- package/src/shared/thinking-ceiling.js.map +1 -0
- package/src/shared/types.d.ts +2667 -0
- package/src/shared/types.d.ts.map +1 -0
- package/src/shared/types.js +265 -0
- package/src/shared/types.js.map +1 -0
- package/src/shared/utf8.d.ts +6 -0
- package/src/shared/utf8.d.ts.map +1 -0
- package/src/shared/utf8.js +13 -0
- package/src/shared/utf8.js.map +1 -0
- package/src/shared/utils.d.ts +71 -0
- package/src/shared/utils.d.ts.map +1 -0
- package/src/shared/utils.js +593 -0
- package/src/shared/utils.js.map +1 -0
- package/src/shared/watch-strategy.d.ts +3 -0
- package/src/shared/watch-strategy.d.ts.map +1 -0
- package/src/shared/watch-strategy.js +6 -0
- package/src/shared/watch-strategy.js.map +1 -0
- package/src/shared/workflow-child-permit.d.ts +59 -0
- package/src/shared/workflow-child-permit.d.ts.map +1 -0
- package/src/shared/workflow-child-permit.js +160 -0
- package/src/shared/workflow-child-permit.js.map +1 -0
- package/src/slash/delegation-adapters.d.ts +147 -0
- package/src/slash/delegation-adapters.d.ts.map +1 -0
- package/src/slash/delegation-adapters.js +293 -0
- package/src/slash/delegation-adapters.js.map +1 -0
- package/src/slash/delegation-json.d.ts +11 -0
- package/src/slash/delegation-json.d.ts.map +1 -0
- package/src/slash/delegation-json.js +118 -0
- package/src/slash/delegation-json.js.map +1 -0
- package/src/slash/delegation-request.d.ts +13 -0
- package/src/slash/delegation-request.d.ts.map +1 -0
- package/src/slash/delegation-request.js +175 -0
- package/src/slash/delegation-request.js.map +1 -0
- package/src/slash/prompt-template-bridge.d.ts +27 -0
- package/src/slash/prompt-template-bridge.d.ts.map +1 -0
- package/src/slash/prompt-template-bridge.js +380 -0
- package/src/slash/prompt-template-bridge.js.map +1 -0
- package/src/slash/prompt-workflows.d.ts +22 -0
- package/src/slash/prompt-workflows.d.ts.map +1 -0
- package/src/slash/prompt-workflows.js +261 -0
- package/src/slash/prompt-workflows.js.map +1 -0
- package/src/slash/selector.d.ts +48 -0
- package/src/slash/selector.d.ts.map +1 -0
- package/src/slash/selector.js +118 -0
- package/src/slash/selector.js.map +1 -0
- package/src/slash/slash-bridge.d.ts +31 -0
- package/src/slash/slash-bridge.d.ts.map +1 -0
- package/src/slash/slash-bridge.js +133 -0
- package/src/slash/slash-bridge.js.map +1 -0
- package/src/slash/slash-commands.d.ts +9 -0
- package/src/slash/slash-commands.d.ts.map +1 -0
- package/src/slash/slash-commands.js +1295 -0
- package/src/slash/slash-commands.js.map +1 -0
- package/src/slash/slash-live-state.d.ts +22 -0
- package/src/slash/slash-live-state.d.ts.map +1 -0
- package/src/slash/slash-live-state.js +264 -0
- package/src/slash/slash-live-state.js.map +1 -0
- package/src/slash/subagents-admin.d.ts +3 -0
- package/src/slash/subagents-admin.d.ts.map +1 -0
- package/src/slash/subagents-admin.js +454 -0
- package/src/slash/subagents-admin.js.map +1 -0
- package/src/tui/fleet-status.d.ts +86 -0
- package/src/tui/fleet-status.d.ts.map +1 -0
- package/src/tui/fleet-status.js +1083 -0
- package/src/tui/fleet-status.js.map +1 -0
- package/src/tui/fleet-transcript.d.ts +50 -0
- package/src/tui/fleet-transcript.d.ts.map +1 -0
- package/src/tui/fleet-transcript.js +497 -0
- package/src/tui/fleet-transcript.js.map +1 -0
- package/src/tui/fleet.d.ts +169 -0
- package/src/tui/fleet.d.ts.map +1 -0
- package/src/tui/fleet.js +1412 -0
- package/src/tui/fleet.js.map +1 -0
- package/src/tui/render-helpers.d.ts +24 -0
- package/src/tui/render-helpers.d.ts.map +1 -0
- package/src/tui/render-helpers.js +101 -0
- package/src/tui/render-helpers.js.map +1 -0
- package/src/tui/render.d.ts +61 -0
- package/src/tui/render.d.ts.map +1 -0
- package/src/tui/render.js +3607 -0
- package/src/tui/render.js.map +1 -0
- package/src/watchdog/change-signature.d.ts +8 -0
- package/src/watchdog/change-signature.d.ts.map +1 -0
- package/src/watchdog/change-signature.js +246 -0
- package/src/watchdog/change-signature.js.map +1 -0
- package/src/watchdog/child-status.d.ts +54 -0
- package/src/watchdog/child-status.d.ts.map +1 -0
- package/src/watchdog/child-status.js +188 -0
- package/src/watchdog/child-status.js.map +1 -0
- package/src/watchdog/diff-tool.d.ts +23 -0
- package/src/watchdog/diff-tool.d.ts.map +1 -0
- package/src/watchdog/diff-tool.js +84 -0
- package/src/watchdog/diff-tool.js.map +1 -0
- package/src/watchdog/emission-guard.d.ts +37 -0
- package/src/watchdog/emission-guard.d.ts.map +1 -0
- package/src/watchdog/emission-guard.js +98 -0
- package/src/watchdog/emission-guard.js.map +1 -0
- package/src/watchdog/guidance.d.ts +4 -0
- package/src/watchdog/guidance.d.ts.map +1 -0
- package/src/watchdog/guidance.js +20 -0
- package/src/watchdog/guidance.js.map +1 -0
- package/src/watchdog/lsp-diagnostics.d.ts +18 -0
- package/src/watchdog/lsp-diagnostics.d.ts.map +1 -0
- package/src/watchdog/lsp-diagnostics.js +490 -0
- package/src/watchdog/lsp-diagnostics.js.map +1 -0
- package/src/watchdog/model-selection.d.ts +25 -0
- package/src/watchdog/model-selection.d.ts.map +1 -0
- package/src/watchdog/model-selection.js +168 -0
- package/src/watchdog/model-selection.js.map +1 -0
- package/src/watchdog/permission-arbiter.d.ts +21 -0
- package/src/watchdog/permission-arbiter.d.ts.map +1 -0
- package/src/watchdog/permission-arbiter.js +136 -0
- package/src/watchdog/permission-arbiter.js.map +1 -0
- package/src/watchdog/register-child.d.ts +12 -0
- package/src/watchdog/register-child.d.ts.map +1 -0
- package/src/watchdog/register-child.js +120 -0
- package/src/watchdog/register-child.js.map +1 -0
- package/src/watchdog/register-main.d.ts +10 -0
- package/src/watchdog/register-main.d.ts.map +1 -0
- package/src/watchdog/register-main.js +419 -0
- package/src/watchdog/register-main.js.map +1 -0
- package/src/watchdog/render.d.ts +12 -0
- package/src/watchdog/render.d.ts.map +1 -0
- package/src/watchdog/render.js +52 -0
- package/src/watchdog/render.js.map +1 -0
- package/src/watchdog/review.d.ts +36 -0
- package/src/watchdog/review.d.ts.map +1 -0
- package/src/watchdog/review.js +318 -0
- package/src/watchdog/review.js.map +1 -0
- package/src/watchdog/rules.d.ts +22 -0
- package/src/watchdog/rules.d.ts.map +1 -0
- package/src/watchdog/rules.js +59 -0
- package/src/watchdog/rules.js.map +1 -0
- package/src/watchdog/runtime.d.ts +196 -0
- package/src/watchdog/runtime.d.ts.map +1 -0
- package/src/watchdog/runtime.js +862 -0
- package/src/watchdog/runtime.js.map +1 -0
- package/src/watchdog/scope.d.ts +15 -0
- package/src/watchdog/scope.d.ts.map +1 -0
- package/src/watchdog/scope.js +45 -0
- package/src/watchdog/scope.js.map +1 -0
- package/src/watchdog/settings.d.ts +30 -0
- package/src/watchdog/settings.d.ts.map +1 -0
- package/src/watchdog/settings.js +476 -0
- package/src/watchdog/settings.js.map +1 -0
- package/src/watchdog/tool-actions.d.ts +18 -0
- package/src/watchdog/tool-actions.d.ts.map +1 -0
- package/src/watchdog/tool-actions.js +151 -0
- package/src/watchdog/tool-actions.js.map +1 -0
- package/src/watchdog/turn-delta.d.ts +12 -0
- package/src/watchdog/turn-delta.d.ts.map +1 -0
- package/src/watchdog/turn-delta.js +185 -0
- package/src/watchdog/turn-delta.js.map +1 -0
- package/src/watchdog/types.d.ts +142 -0
- package/src/watchdog/types.d.ts.map +1 -0
- package/src/watchdog/types.js +28 -0
- package/src/watchdog/types.js.map +1 -0
- package/src/watchdog/warning-format.d.ts +8 -0
- package/src/watchdog/warning-format.d.ts.map +1 -0
- package/src/watchdog/warning-format.js +60 -0
- package/src/watchdog/warning-format.js.map +1 -0
- package/src/workflows/chat-progress.d.ts +38 -0
- package/src/workflows/chat-progress.d.ts.map +1 -0
- package/src/workflows/chat-progress.js +130 -0
- package/src/workflows/chat-progress.js.map +1 -0
- package/src/workflows/host-command.d.ts +31 -0
- package/src/workflows/host-command.d.ts.map +1 -0
- package/src/workflows/host-command.js +228 -0
- package/src/workflows/host-command.js.map +1 -0
- package/src/workflows/scripted-workflow.d.ts +195 -0
- package/src/workflows/scripted-workflow.d.ts.map +1 -0
- package/src/workflows/scripted-workflow.js +2636 -0
- package/src/workflows/scripted-workflow.js.map +1 -0
- package/src/workflows/workflow-checklist.d.ts +124 -0
- package/src/workflows/workflow-checklist.d.ts.map +1 -0
- package/src/workflows/workflow-checklist.js +312 -0
- package/src/workflows/workflow-checklist.js.map +1 -0
- package/src/workflows/workflow-child-summary.d.ts +20 -0
- package/src/workflows/workflow-child-summary.d.ts.map +1 -0
- package/src/workflows/workflow-child-summary.js +179 -0
- package/src/workflows/workflow-child-summary.js.map +1 -0
- package/src/workflows/workflow-preflight.d.ts +59 -0
- package/src/workflows/workflow-preflight.d.ts.map +1 -0
- package/src/workflows/workflow-preflight.js +289 -0
- package/src/workflows/workflow-preflight.js.map +1 -0
- package/src/workflows/workflow-receipt.d.ts +35 -0
- package/src/workflows/workflow-receipt.d.ts.map +1 -0
- package/src/workflows/workflow-receipt.js +449 -0
- package/src/workflows/workflow-receipt.js.map +1 -0
- package/src/workflows/workflow-resources.d.ts +43 -0
- package/src/workflows/workflow-resources.d.ts.map +1 -0
- package/src/workflows/workflow-resources.js +230 -0
- package/src/workflows/workflow-resources.js.map +1 -0
- package/src/workflows/workflow-settlement.d.ts +85 -0
- package/src/workflows/workflow-settlement.d.ts.map +1 -0
- package/src/workflows/workflow-settlement.js +204 -0
- package/src/workflows/workflow-settlement.js.map +1 -0
- package/index.ts +0 -13
- package/src/agents/advertised-agent-prompt.ts +0 -94
- package/src/agents/agent-management.ts +0 -1417
- package/src/agents/agent-memory.ts +0 -254
- package/src/agents/agent-refinements.ts +0 -624
- package/src/agents/agent-scope.ts +0 -6
- package/src/agents/agent-selection.ts +0 -25
- package/src/agents/agent-serializer.ts +0 -182
- package/src/agents/agents.ts +0 -2917
- package/src/agents/builtin-names.ts +0 -16
- package/src/agents/chain-serializer.ts +0 -285
- package/src/agents/frontmatter.ts +0 -153
- package/src/agents/identity.ts +0 -30
- package/src/agents/proactive-skills.ts +0 -194
- package/src/agents/runtime-agent-events.ts +0 -70
- package/src/agents/runtime-agent-registry.ts +0 -430
- package/src/agents/skills.ts +0 -754
- package/src/api/agents.ts +0 -12
- package/src/api/background-work.ts +0 -206
- package/src/api/capability-ceiling.ts +0 -16
- package/src/api/child-tool-plan.ts +0 -5
- package/src/api/control-channel.ts +0 -4
- package/src/api/delegation.ts +0 -116
- package/src/api/external-job-provider.ts +0 -195
- package/src/api/external-runs.ts +0 -282
- package/src/api/intercom-bridge.ts +0 -3
- package/src/api/preflight.ts +0 -539
- package/src/api/project-panes.ts +0 -32
- package/src/api/required-child-extensions.ts +0 -6
- package/src/api/shared-types.ts +0 -29
- package/src/api/workflow-resources.ts +0 -6
- package/src/extension/config.ts +0 -230
- package/src/extension/control-notices.ts +0 -58
- package/src/extension/doctor.ts +0 -270
- package/src/extension/fanout-child.ts +0 -265
- package/src/extension/herdr-pi-bridge.ts +0 -160
- package/src/extension/index.ts +0 -1205
- package/src/extension/public-execution.ts +0 -225
- package/src/extension/rpc.ts +0 -848
- package/src/extension/schemas.ts +0 -422
- package/src/extension/steering-notices.ts +0 -35
- package/src/extension/subagent-guide.ts +0 -39
- package/src/extension/tool-description.ts +0 -175
- package/src/extension/tool-result.ts +0 -19
- package/src/inspectors/actions.ts +0 -148
- package/src/inspectors/ghostty/actions.ts +0 -74
- package/src/inspectors/ghostty/plugin.ts +0 -17
- package/src/inspectors/herdr/actions.ts +0 -155
- package/src/inspectors/herdr/client.ts +0 -130
- package/src/inspectors/herdr/focus.ts +0 -55
- package/src/inspectors/herdr/plugin.ts +0 -20
- package/src/inspectors/herdr/project-panes.ts +0 -730
- package/src/inspectors/inspector-runner.ts +0 -153
- package/src/inspectors/plugins.ts +0 -8
- package/src/inspectors/session-roots-codec.ts +0 -31
- package/src/inspectors/shell-command.ts +0 -16
- package/src/inspectors/types.ts +0 -51
- package/src/integrations/herdr-status.ts +0 -400
- package/src/integrations/pi-web-session-liveness.ts +0 -73
- package/src/intercom/intercom-bridge.ts +0 -233
- package/src/intercom/native-supervisor-channel.ts +0 -917
- package/src/intercom/result-intercom.ts +0 -423
- package/src/intercom/supervisor-ui.ts +0 -244
- package/src/missions/actions.ts +0 -433
- package/src/missions/goal-driver.ts +0 -164
- package/src/missions/lifecycle.ts +0 -367
- package/src/missions/store.ts +0 -584
- package/src/missions/types.ts +0 -190
- package/src/missions/workflow-state.ts +0 -281
- package/src/policy/authority.ts +0 -50
- package/src/profiles/profiles.ts +0 -668
- package/src/runs/background/active-async-capacity.ts +0 -520
- package/src/runs/background/active-run-index.ts +0 -155
- package/src/runs/background/async-execution.ts +0 -2278
- package/src/runs/background/async-job-tracker.ts +0 -826
- package/src/runs/background/async-resume.ts +0 -647
- package/src/runs/background/async-retention.ts +0 -912
- package/src/runs/background/async-status-snapshot.ts +0 -46
- package/src/runs/background/async-status.ts +0 -771
- package/src/runs/background/auto-drain.ts +0 -92
- package/src/runs/background/binary-bootstrap.ts +0 -38
- package/src/runs/background/chain-append.ts +0 -321
- package/src/runs/background/chain-root-attachment.ts +0 -259
- package/src/runs/background/completion-batcher.ts +0 -168
- package/src/runs/background/completion-dedupe.ts +0 -58
- package/src/runs/background/completion-replay.ts +0 -287
- package/src/runs/background/control-channel.ts +0 -600
- package/src/runs/background/fleet-view.ts +0 -648
- package/src/runs/background/index-segment.ts +0 -59
- package/src/runs/background/inspect-rpc.ts +0 -443
- package/src/runs/background/notify.ts +0 -819
- package/src/runs/background/owned-process-tree.ts +0 -131
- package/src/runs/background/parallel-groups.ts +0 -45
- package/src/runs/background/process-terminal.ts +0 -310
- package/src/runs/background/result-delivery-ownership.ts +0 -45
- package/src/runs/background/result-files.ts +0 -523
- package/src/runs/background/result-watcher.ts +0 -809
- package/src/runs/background/resume-guidance.ts +0 -56
- package/src/runs/background/retained-children.ts +0 -135
- package/src/runs/background/retained-nested-route-tracker.ts +0 -96
- package/src/runs/background/run-child-session.ts +0 -690
- package/src/runs/background/run-id-query.ts +0 -7
- package/src/runs/background/run-id-resolver.ts +0 -175
- package/src/runs/background/run-status.ts +0 -786
- package/src/runs/background/runner-aliases.ts +0 -142
- package/src/runs/background/runner-child-launch.ts +0 -91
- package/src/runs/background/runner-child-sessions.ts +0 -32
- package/src/runs/background/runner-http-dispatcher.ts +0 -119
- package/src/runs/background/scheduled-runs.ts +0 -1012
- package/src/runs/background/stale-run-reconciler.ts +0 -436
- package/src/runs/background/steering.ts +0 -260
- package/src/runs/background/subagent-runner.ts +0 -5341
- package/src/runs/background/subagent-wait.ts +0 -876
- package/src/runs/background/terminal-run-index.ts +0 -138
- package/src/runs/background/top-level-async.ts +0 -14
- package/src/runs/background/wait-completions.ts +0 -261
- package/src/runs/background/wait-config.ts +0 -50
- package/src/runs/background/wait-subscriptions.ts +0 -354
- package/src/runs/background/wait-tool.ts +0 -45
- package/src/runs/foreground/async-dismiss-action.ts +0 -86
- package/src/runs/foreground/async-steering-action.ts +0 -276
- package/src/runs/foreground/async-stop-action.ts +0 -176
- package/src/runs/foreground/execution.ts +0 -2231
- package/src/runs/foreground/foreground-control.ts +0 -157
- package/src/runs/foreground/foreground-history.ts +0 -163
- package/src/runs/foreground/prompt-audit.ts +0 -178
- package/src/runs/foreground/subagent-executor.ts +0 -7511
- package/src/runs/foreground/workflow-detach-reconcile.ts +0 -304
- package/src/runs/foreground/workflow-foreground-steering.ts +0 -169
- package/src/runs/shared/abort-recovery.ts +0 -119
- package/src/runs/shared/acceptance.ts +0 -1565
- package/src/runs/shared/agent-contract.ts +0 -38
- package/src/runs/shared/async-status-projection.ts +0 -659
- package/src/runs/shared/background-process-options.ts +0 -9
- package/src/runs/shared/capability-ceiling.ts +0 -211
- package/src/runs/shared/chain-outputs.ts +0 -116
- package/src/runs/shared/child-hooks.ts +0 -189
- package/src/runs/shared/child-identity.ts +0 -62
- package/src/runs/shared/child-launch-plan.ts +0 -163
- package/src/runs/shared/child-launch.ts +0 -342
- package/src/runs/shared/child-lifecycle.ts +0 -28
- package/src/runs/shared/child-runtime-config.ts +0 -133
- package/src/runs/shared/child-session.ts +0 -448
- package/src/runs/shared/child-tool-plan.ts +0 -661
- package/src/runs/shared/claude-code-adapter.ts +0 -133
- package/src/runs/shared/codex-exec-adapter.ts +0 -129
- package/src/runs/shared/completion-evidence.ts +0 -89
- package/src/runs/shared/completion-guard.ts +0 -255
- package/src/runs/shared/context-mode.ts +0 -44
- package/src/runs/shared/cursor-agent-adapter.ts +0 -114
- package/src/runs/shared/dynamic-fanout.ts +0 -297
- package/src/runs/shared/effective-system-prompt.ts +0 -33
- package/src/runs/shared/extension-bindings.ts +0 -78
- package/src/runs/shared/external-cli-contract.ts +0 -177
- package/src/runs/shared/external-cli-preflight.ts +0 -142
- package/src/runs/shared/external-cli-runner.ts +0 -431
- package/src/runs/shared/external-job-bridge.ts +0 -460
- package/src/runs/shared/external-job-runner.ts +0 -389
- package/src/runs/shared/fast-mode-extension.ts +0 -10
- package/src/runs/shared/herdr-connection.ts +0 -134
- package/src/runs/shared/herdr-external-adapters.ts +0 -169
- package/src/runs/shared/herdr-machine.ts +0 -279
- package/src/runs/shared/herdr-pi-protocol.ts +0 -59
- package/src/runs/shared/herdr-placed-run.ts +0 -263
- package/src/runs/shared/host-step-status.ts +0 -231
- package/src/runs/shared/lane-metadata.ts +0 -126
- package/src/runs/shared/launch-cwd.ts +0 -16
- package/src/runs/shared/llm-intent-arbiter.ts +0 -321
- package/src/runs/shared/long-running-guard.ts +0 -221
- package/src/runs/shared/mcp-config-sources.ts +0 -422
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +0 -484
- package/src/runs/shared/mcp-direct-tool-grant.ts +0 -194
- package/src/runs/shared/model-resolution-diagnostic.ts +0 -76
- package/src/runs/shared/model-resolution.ts +0 -441
- package/src/runs/shared/model-scope.ts +0 -205
- package/src/runs/shared/mutation-evidence.ts +0 -199
- package/src/runs/shared/nested-events.ts +0 -1079
- package/src/runs/shared/nested-path.ts +0 -38
- package/src/runs/shared/nested-render.ts +0 -127
- package/src/runs/shared/orca-progress-tabs.ts +0 -510
- package/src/runs/shared/parallel-handoff.ts +0 -741
- package/src/runs/shared/parallel-utils.ts +0 -279
- package/src/runs/shared/permissions.ts +0 -86
- package/src/runs/shared/pi-spawn.ts +0 -207
- package/src/runs/shared/process-signal.ts +0 -35
- package/src/runs/shared/readonly-drain-observation.ts +0 -42
- package/src/runs/shared/run-fanout-budget.ts +0 -267
- package/src/runs/shared/run-history.ts +0 -201
- package/src/runs/shared/runtime-acknowledged-extensions.ts +0 -44
- package/src/runs/shared/session-lease.ts +0 -293
- package/src/runs/shared/single-output.ts +0 -304
- package/src/runs/shared/spawn-budget.ts +0 -128
- package/src/runs/shared/structured-output.ts +0 -236
- package/src/runs/shared/subagent-control.ts +0 -294
- package/src/runs/shared/subagent-prompt-runtime.ts +0 -545
- package/src/runs/shared/task-intent.ts +0 -244
- package/src/runs/shared/tool-availability.ts +0 -37
- package/src/runs/shared/tool-budget.ts +0 -66
- package/src/runs/shared/tool-timeout.ts +0 -93
- package/src/runs/shared/usage-budget.ts +0 -65
- package/src/runs/shared/workflow-async-child-guidance.ts +0 -18
- package/src/runs/shared/workflow-graph.ts +0 -225
- package/src/runs/shared/worktree-cleanup-plan.ts +0 -869
- package/src/runs/shared/worktree-setup-command.ts +0 -213
- package/src/runs/shared/worktree.ts +0 -1516
- package/src/shared/accessible-dir.ts +0 -47
- package/src/shared/agent-stream-options.ts +0 -5
- package/src/shared/artifacts.ts +0 -281
- package/src/shared/atomic-json.ts +0 -83
- package/src/shared/capacity-resilient-json.ts +0 -102
- package/src/shared/child-cache-retention.ts +0 -43
- package/src/shared/child-session-name.ts +0 -46
- package/src/shared/child-transcript.ts +0 -264
- package/src/shared/completion-owner.ts +0 -14
- package/src/shared/display-text.ts +0 -150
- package/src/shared/extension-context.ts +0 -24
- package/src/shared/file-coalescer.ts +0 -49
- package/src/shared/file-system-retry.ts +0 -95
- package/src/shared/fork-context.ts +0 -236
- package/src/shared/fork-session-cwd.ts +0 -27
- package/src/shared/formatters.ts +0 -146
- package/src/shared/jsonl-writer.ts +0 -92
- package/src/shared/launch-contract.ts +0 -198
- package/src/shared/model-info.ts +0 -101
- package/src/shared/model-response-aliases.ts +0 -13
- package/src/shared/node-executable.ts +0 -21
- package/src/shared/opencode-session-headers.ts +0 -30
- package/src/shared/prompt-resources.ts +0 -11
- package/src/shared/pruned-fork.ts +0 -450
- package/src/shared/required-child-extensions.ts +0 -81
- package/src/shared/session-file-trust.ts +0 -19
- package/src/shared/session-identity.ts +0 -10
- package/src/shared/session-tokens.ts +0 -55
- package/src/shared/settings.ts +0 -412
- package/src/shared/shortcuts.ts +0 -13
- package/src/shared/status-format.ts +0 -55
- package/src/shared/thinking-ceiling.ts +0 -46
- package/src/shared/types.ts +0 -2972
- package/src/shared/utf8.ts +0 -11
- package/src/shared/utils.ts +0 -608
- package/src/shared/watch-strategy.ts +0 -12
- package/src/shared/workflow-child-permit.ts +0 -212
- package/src/slash/delegation-adapters.ts +0 -428
- package/src/slash/delegation-json.ts +0 -108
- package/src/slash/delegation-request.ts +0 -176
- package/src/slash/prompt-template-bridge.ts +0 -419
- package/src/slash/prompt-workflows.ts +0 -287
- package/src/slash/selector.ts +0 -147
- package/src/slash/slash-bridge.ts +0 -192
- package/src/slash/slash-commands.ts +0 -1325
- package/src/slash/slash-live-state.ts +0 -310
- package/src/slash/subagents-admin.ts +0 -460
- package/src/tui/fleet-status.ts +0 -1109
- package/src/tui/fleet-transcript.ts +0 -536
- package/src/tui/fleet.ts +0 -1448
- package/src/tui/render-helpers.ts +0 -111
- package/src/tui/render.ts +0 -3721
- package/src/types/pi-runtime-compat.d.ts +0 -8
- package/src/watchdog/change-signature.ts +0 -260
- package/src/watchdog/child-status.ts +0 -225
- package/src/watchdog/diff-tool.ts +0 -77
- package/src/watchdog/emission-guard.ts +0 -125
- package/src/watchdog/guidance.ts +0 -20
- package/src/watchdog/lsp-diagnostics.ts +0 -538
- package/src/watchdog/model-selection.ts +0 -187
- package/src/watchdog/permission-arbiter.ts +0 -156
- package/src/watchdog/register-child.ts +0 -128
- package/src/watchdog/register-main.ts +0 -445
- package/src/watchdog/render.ts +0 -53
- package/src/watchdog/review.ts +0 -363
- package/src/watchdog/rules.ts +0 -70
- package/src/watchdog/runtime.ts +0 -924
- package/src/watchdog/scope.ts +0 -51
- package/src/watchdog/settings.ts +0 -515
- package/src/watchdog/tool-actions.ts +0 -156
- package/src/watchdog/turn-delta.ts +0 -184
- package/src/watchdog/types.ts +0 -186
- package/src/watchdog/warning-format.ts +0 -72
- package/src/workflows/chat-progress.ts +0 -152
- package/src/workflows/host-command.ts +0 -235
- package/src/workflows/scripted-workflow.ts +0 -2553
- package/src/workflows/workflow-checklist.ts +0 -436
- package/src/workflows/workflow-child-summary.ts +0 -170
- package/src/workflows/workflow-preflight.ts +0 -297
- package/src/workflows/workflow-receipt.ts +0 -384
- package/src/workflows/workflow-resources.ts +0 -236
- package/src/workflows/workflow-settlement.ts +0 -249
|
@@ -0,0 +1,2186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core execution logic for running subagents
|
|
3
|
+
*/
|
|
4
|
+
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import * as path from "node:path";
|
|
6
|
+
import { discoverAgents, formatUnknownAgentError, unknownAgentDiagnosticContext } from "../../agents/agents.js";
|
|
7
|
+
import { alignForkedSessionCwd } from "../../shared/fork-session-cwd.js";
|
|
8
|
+
import { buildEffectiveSystemPrompt } from "../shared/effective-system-prompt.js";
|
|
9
|
+
import { ensureArtifactsDir, formatOutputArtifactContent, getArtifactPaths, writeArtifact, writeMetadata, } from "../../shared/artifacts.js";
|
|
10
|
+
import { createChildTranscriptWriter } from "../../shared/child-transcript.js";
|
|
11
|
+
import { DEFAULT_MAX_OUTPUT, INTERCOM_DETACH_REQUEST_EVENT, INTERCOM_DETACH_RESPONSE_EVENT, truncateOutput, } from "../../shared/types.js";
|
|
12
|
+
import { DEFAULT_CONTROL_CONFIG, buildControlEvent, claimControlNotification, deriveActivityState, shouldEmitOpenToolAttention, shouldNotifyControlEvent, } from "../shared/subagent-control.js";
|
|
13
|
+
import { getFinalOutput, findLatestSessionFile, detectSubagentError, hasEmptyTerminalAssistantResponse, formatEmptyTerminalAssistantResponseError, extractToolArgsPreview, extractTextFromContent, MAX_STREAMED_RECENT_TOOLS, boundStreamedRecentTools, boundStreamedRecentOutput, boundStreamedToolCalls, } from "../../shared/utils.js";
|
|
14
|
+
import { resolveSkillsWithFallback } from "../../agents/skills.js";
|
|
15
|
+
import { effectiveToolTimeoutMs, formatToolTimeoutMessage, resolveToolTimeoutMs, toolTimeoutCallKey, toolTimeoutFromEnv } from "../shared/tool-timeout.js";
|
|
16
|
+
import { evaluateCompletionMutationGuard, expectsImplementationMutation, hasMutationToolCapability, validateImplementationToolContract } from "../shared/completion-guard.js";
|
|
17
|
+
import { planCompletionEvidence } from "../shared/completion-evidence.js";
|
|
18
|
+
import { arbitrateCompletionGuardRescue } from "../shared/llm-intent-arbiter.js";
|
|
19
|
+
import { preflightLaunchCwd } from "../shared/launch-cwd.js";
|
|
20
|
+
import { createJsonlWriter } from "../../shared/jsonl-writer.js";
|
|
21
|
+
import { createOrcaProgressTab } from "../shared/orca-progress-tabs.js";
|
|
22
|
+
import { resolvePermissionRules } from "../shared/permissions.js";
|
|
23
|
+
import { applyThinkingSuffix, deriveForkPromptCacheKey } from "../shared/child-tool-plan.js";
|
|
24
|
+
import { deriveChildSessionName } from "../../shared/child-session-name.js";
|
|
25
|
+
import { assertAgentAllowedByCapabilityCeiling, intersectSubagentCapabilityCeilings, resolveCurrentSubagentCapabilityCeiling } from "../shared/capability-ceiling.js";
|
|
26
|
+
import { resolveEffectiveThinking } from "../../shared/model-info.js";
|
|
27
|
+
import { assertThinkingWithinCeiling, intersectThinkingCeilings } from "../../shared/thinking-ceiling.js";
|
|
28
|
+
import { MISSING_STRUCTURED_ACCEPTANCE_REPORT_ERROR, MISSING_STRUCTURED_OUTPUT_CALL_ERROR } from "../shared/structured-output.js";
|
|
29
|
+
import { formatMidToolExitError, isOrdinaryToolForMidToolExit } from "../shared/process-signal.js";
|
|
30
|
+
import { formatChildToolDiagnostic } from "../shared/tool-availability.js";
|
|
31
|
+
import { formatChildModelResolutionDiagnostic, isChildModelResolutionFailure } from "../shared/model-resolution-diagnostic.js";
|
|
32
|
+
import { planAbortRecovery } from "../shared/abort-recovery.js";
|
|
33
|
+
import { buildTimeoutRecoverySummary, collectTrackedMutationEvidence, snapshotTrackedMutations } from "../shared/mutation-evidence.js";
|
|
34
|
+
import { captureSingleOutputSnapshot, extractChildWrittenOutput, finalizeSingleOutput, formatSavedOutputReference, hasSingleOutputChangedSinceSnapshot, resolveSingleOutput, validateFileOnlyOutputMode } from "../shared/single-output.js";
|
|
35
|
+
import { formatSubagentModelVerificationError, isContextOverflow, resolveModelSelection, } from "../shared/model-resolution.js";
|
|
36
|
+
import { createMutatingFailureState, didMutatingToolFail, isMutatingTool, nextLongRunningTrigger, recordMutatingFailure, resetMutatingFailureState, resolveCurrentPath, shouldEscalateMutatingFailures, summarizeRecentMutatingFailures, } from "../shared/long-running-guard.js";
|
|
37
|
+
import { acceptanceFailureMessage, buildSkippedAcceptanceLedger, captureStagedIndexBaseline, evaluateAcceptance, formatAcceptancePrompt, resolveEffectiveAcceptance, stripAcceptanceReport, validateAcceptanceInput, typedVerifyOutput } from "../shared/acceptance.js";
|
|
38
|
+
import { PROMPT_REDACTED } from "../../shared/utils.js";
|
|
39
|
+
import { attachContractProjections, isAgentContract } from "../shared/agent-contract.js";
|
|
40
|
+
import { initialToolBudgetState, isToolBudgetBlockedMessage, toolBudgetState } from "../shared/tool-budget.js";
|
|
41
|
+
import { resolveWatchdogConfig } from "../../watchdog/settings.js";
|
|
42
|
+
import { resolveLaunchBinding } from "../../shared/launch-contract.js";
|
|
43
|
+
import { consumeWorkflowChildPermit } from "../../shared/workflow-child-permit.js";
|
|
44
|
+
import { projectChildLifecycle } from "../shared/child-lifecycle.js";
|
|
45
|
+
import { acceptChildWatchdogEvent, applyChildWatchdogMessage, childWatchdogIsActive, isChildWatchdogStatusEvent, resolveChildWatchdogConfig, } from "../../watchdog/child-status.js";
|
|
46
|
+
import { buildInProcessChildLaunch, createReportedChildSessionInput } from "../shared/child-launch.js";
|
|
47
|
+
import { childSessionFactory, childSessionHasQueuedMessages, projectChildSessionEventForJson } from "../shared/child-session.js";
|
|
48
|
+
import { reconcileAttemptUsage } from "../shared/usage-reconciliation.js";
|
|
49
|
+
const artifactOutputByResult = new WeakMap();
|
|
50
|
+
const acceptanceOutputByResult = new WeakMap();
|
|
51
|
+
function emptyUsage() {
|
|
52
|
+
return { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0 };
|
|
53
|
+
}
|
|
54
|
+
function withRunContext(result, context) {
|
|
55
|
+
if (!context)
|
|
56
|
+
return result;
|
|
57
|
+
result.context = context;
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
function redactResultPrompt(result) {
|
|
61
|
+
result.task = PROMPT_REDACTED;
|
|
62
|
+
if (result.progress)
|
|
63
|
+
result.progress.task = PROMPT_REDACTED;
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
function sumUsage(target, source) {
|
|
67
|
+
target.input += source.input;
|
|
68
|
+
target.output += source.output;
|
|
69
|
+
target.cacheRead += source.cacheRead;
|
|
70
|
+
target.cacheWrite += source.cacheWrite;
|
|
71
|
+
target.cost += source.cost;
|
|
72
|
+
target.turns += source.turns;
|
|
73
|
+
}
|
|
74
|
+
function persistSingleResultMetadata(input) {
|
|
75
|
+
if (!input.enabled || !input.metadataPath)
|
|
76
|
+
return;
|
|
77
|
+
const target = input.result;
|
|
78
|
+
writeMetadata(input.metadataPath, {
|
|
79
|
+
runId: input.runId,
|
|
80
|
+
agent: input.agent,
|
|
81
|
+
task: PROMPT_REDACTED,
|
|
82
|
+
exitCode: target.exitCode,
|
|
83
|
+
processSignal: target.processSignal,
|
|
84
|
+
usage: target.usage,
|
|
85
|
+
model: target.model,
|
|
86
|
+
requestedModel: target.requestedModel,
|
|
87
|
+
durationMs: target.progressSummary?.durationMs,
|
|
88
|
+
toolCount: target.progressSummary?.toolCount,
|
|
89
|
+
error: target.error,
|
|
90
|
+
agentContract: target.agentContract,
|
|
91
|
+
launchContractDigest: target.launchContractDigest,
|
|
92
|
+
launchResolvedExtensions: target.launchResolvedExtensions,
|
|
93
|
+
runtimeAcknowledgedExtensions: target.runtimeAcknowledgedExtensions,
|
|
94
|
+
execution: target.execution,
|
|
95
|
+
acceptance: target.acceptance,
|
|
96
|
+
capabilityCeiling: target.capabilityCeiling,
|
|
97
|
+
capabilityAudit: target.capabilityAudit,
|
|
98
|
+
review: target.review,
|
|
99
|
+
effects: target.effects,
|
|
100
|
+
transcriptPath: target.transcriptPath,
|
|
101
|
+
transcriptError: target.transcriptError,
|
|
102
|
+
skills: target.skills,
|
|
103
|
+
skillsWarning: target.skillsWarning,
|
|
104
|
+
timestamp: Date.now(),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function formatTimeoutMessage(timeoutMs) {
|
|
108
|
+
return `Subagent timed out after ${timeoutMs}ms.`;
|
|
109
|
+
}
|
|
110
|
+
function resolveAttemptTimeout(options) {
|
|
111
|
+
if (options.timeoutMs === undefined)
|
|
112
|
+
return undefined;
|
|
113
|
+
const deadlineAt = options.deadlineAt ?? Date.now() + options.timeoutMs;
|
|
114
|
+
return {
|
|
115
|
+
timeoutMs: options.timeoutMs,
|
|
116
|
+
remainingMs: Math.max(0, deadlineAt - Date.now()),
|
|
117
|
+
message: formatTimeoutMessage(options.timeoutMs),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function buildPendingAcceptanceLedger(acceptance) {
|
|
121
|
+
return {
|
|
122
|
+
status: "pending",
|
|
123
|
+
evidenceStatus: "pending",
|
|
124
|
+
explicit: acceptance.explicit,
|
|
125
|
+
effectiveAcceptance: acceptance,
|
|
126
|
+
inferredReason: acceptance.inferredReason,
|
|
127
|
+
criteria: acceptance.criteria,
|
|
128
|
+
runtimeChecks: [],
|
|
129
|
+
verifyRuns: [],
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function buildInterruptedAcceptanceLedger(acceptance) {
|
|
133
|
+
const pending = buildPendingAcceptanceLedger(acceptance);
|
|
134
|
+
if (acceptance.level === "none") {
|
|
135
|
+
pending.status = "not-required";
|
|
136
|
+
pending.evidenceStatus = "not-required";
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
pending.runtimeChecks = [{
|
|
140
|
+
id: "interrupted",
|
|
141
|
+
status: "not-applicable",
|
|
142
|
+
message: "Acceptance was not evaluated because the subagent was interrupted.",
|
|
143
|
+
}];
|
|
144
|
+
}
|
|
145
|
+
return pending;
|
|
146
|
+
}
|
|
147
|
+
function appendRecentOutput(progress, lines) {
|
|
148
|
+
if (lines.length === 0)
|
|
149
|
+
return;
|
|
150
|
+
progress.recentOutput.push(...lines.filter((line) => line.trim()));
|
|
151
|
+
if (progress.recentOutput.length > 50) {
|
|
152
|
+
progress.recentOutput.splice(0, progress.recentOutput.length - 50);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function stripAcceptanceReportsFromMessages(messages) {
|
|
156
|
+
for (const message of messages ?? []) {
|
|
157
|
+
if (message.role !== "assistant" || !Array.isArray(message.content))
|
|
158
|
+
continue;
|
|
159
|
+
for (const part of message.content) {
|
|
160
|
+
if (part.type === "text" && "text" in part && typeof part.text === "string") {
|
|
161
|
+
part.text = stripAcceptanceReport(part.text);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function snapshotProgress(progress) {
|
|
167
|
+
return {
|
|
168
|
+
...progress,
|
|
169
|
+
task: PROMPT_REDACTED,
|
|
170
|
+
skills: progress.skills ? [...progress.skills] : undefined,
|
|
171
|
+
recentTools: boundStreamedRecentTools(progress.recentTools),
|
|
172
|
+
recentOutput: boundStreamedRecentOutput(progress.recentOutput),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function snapshotResult(result, progress) {
|
|
176
|
+
return {
|
|
177
|
+
...result,
|
|
178
|
+
task: PROMPT_REDACTED,
|
|
179
|
+
messages: result.outputMode === "file-only" && result.savedOutputPath ? undefined : result.messages ? [...result.messages] : undefined,
|
|
180
|
+
usage: { ...result.usage },
|
|
181
|
+
skills: result.skills ? [...result.skills] : undefined,
|
|
182
|
+
controlEvents: result.controlEvents ? result.controlEvents.map((event) => ({ ...event })) : undefined,
|
|
183
|
+
progress,
|
|
184
|
+
progressSummary: result.progressSummary ? { ...result.progressSummary } : undefined,
|
|
185
|
+
artifactPaths: result.artifactPaths ? { ...result.artifactPaths } : undefined,
|
|
186
|
+
truncation: result.truncation ? { ...result.truncation } : undefined,
|
|
187
|
+
outputReference: result.outputReference ? { ...result.outputReference } : undefined,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Streaming variant of snapshotResult for `onUpdate` progress events: it drops the
|
|
192
|
+
* unbounded `messages` transcript in favour of compact tool-call summaries so a
|
|
193
|
+
* single `tool_execution_update` event stays small; the parent records every
|
|
194
|
+
* one in its transcript and `events.jsonl`. Non-streaming consumers such as
|
|
195
|
+
* foreground detach receipts and terminal consumers use snapshotResult directly.
|
|
196
|
+
*/
|
|
197
|
+
function snapshotStreamResult(result, progress) {
|
|
198
|
+
const snapshot = snapshotResult(result, progress);
|
|
199
|
+
snapshot.messages = undefined;
|
|
200
|
+
snapshot.toolCalls = boundStreamedToolCalls(result);
|
|
201
|
+
return snapshot;
|
|
202
|
+
}
|
|
203
|
+
function captureStructuredDelegationProgressState(progress, result) {
|
|
204
|
+
return {
|
|
205
|
+
currentTool: progress.currentTool,
|
|
206
|
+
currentToolArgs: progress.currentToolArgs,
|
|
207
|
+
recentOutput: [...progress.recentOutput],
|
|
208
|
+
recentTools: progress.recentTools.slice(-MAX_STREAMED_RECENT_TOOLS).map(({ tool, args }) => ({ tool, args })),
|
|
209
|
+
activityState: progress.activityState,
|
|
210
|
+
model: progress.model ?? result.model,
|
|
211
|
+
toolCount: progress.toolCount,
|
|
212
|
+
tokens: progress.tokens,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function structuredDelegationProgressChanged(previous, progress, result) {
|
|
216
|
+
if (previous.currentTool !== progress.currentTool
|
|
217
|
+
|| previous.currentToolArgs !== progress.currentToolArgs
|
|
218
|
+
|| previous.activityState !== progress.activityState
|
|
219
|
+
|| previous.model !== (progress.model ?? result.model)
|
|
220
|
+
|| previous.toolCount !== progress.toolCount
|
|
221
|
+
|| previous.tokens !== progress.tokens
|
|
222
|
+
|| previous.recentOutput.length !== progress.recentOutput.length)
|
|
223
|
+
return true;
|
|
224
|
+
for (let index = 0; index < progress.recentOutput.length; index++) {
|
|
225
|
+
if (previous.recentOutput[index] !== progress.recentOutput[index])
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
const recentToolsStart = Math.max(0, progress.recentTools.length - MAX_STREAMED_RECENT_TOOLS);
|
|
229
|
+
if (previous.recentTools.length !== progress.recentTools.length - recentToolsStart)
|
|
230
|
+
return true;
|
|
231
|
+
for (let index = recentToolsStart; index < progress.recentTools.length; index++) {
|
|
232
|
+
const previousTool = previous.recentTools[index - recentToolsStart];
|
|
233
|
+
const currentTool = progress.recentTools[index];
|
|
234
|
+
if (previousTool?.tool !== currentTool?.tool || previousTool?.args !== currentTool?.args)
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
const STOPPED_BEFORE_COMPLETION_ERROR = "Subagent stopped before completion.";
|
|
240
|
+
const AFTER_COMPACTION_SETTLEMENT = Symbol("afterCompactionSettlement");
|
|
241
|
+
async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared) {
|
|
242
|
+
const effectiveThinking = options.thinkingOverride ?? agent.thinking;
|
|
243
|
+
const modelArg = applyThinkingSuffix(model, effectiveThinking, options.thinkingOverride !== undefined);
|
|
244
|
+
assertThinkingWithinCeiling({ model: modelArg, configThinking: effectiveThinking, ceiling: options.thinkingCeiling, agent: agent.name, runId: options.runId });
|
|
245
|
+
const expectedModelForVerification = shared.verifyModel ? modelArg : undefined;
|
|
246
|
+
const resolvedThinking = resolveEffectiveThinking(modelArg, effectiveThinking);
|
|
247
|
+
// Display name for the child session: applied inside the child through its
|
|
248
|
+
// runtime config and echoed back on the result payload so hosts can label
|
|
249
|
+
// this run without reading the child's session file.
|
|
250
|
+
const childSessionName = deriveChildSessionName({ agent: agent.name, task: shared.originalTask ?? task });
|
|
251
|
+
const watchdogConfig = resolveWatchdogConfig(options.cwd ?? runtimeCwd);
|
|
252
|
+
const childWatchdog = watchdogConfig.ok
|
|
253
|
+
? resolveChildWatchdogConfig({
|
|
254
|
+
config: watchdogConfig.config,
|
|
255
|
+
agent: agent.name,
|
|
256
|
+
runId: options.runId,
|
|
257
|
+
childIndex: options.index ?? 0,
|
|
258
|
+
})
|
|
259
|
+
: undefined;
|
|
260
|
+
const permissionRules = resolvePermissionRules(options.permissions, agent.permissions);
|
|
261
|
+
const permissionAuditPath = permissionRules && options.artifactsDir
|
|
262
|
+
? path.join(options.artifactsDir, "permission-audit", `${options.runId}-${options.index ?? 0}.jsonl`)
|
|
263
|
+
: undefined;
|
|
264
|
+
let onWatchdogStatus;
|
|
265
|
+
const launch = buildInProcessChildLaunch({
|
|
266
|
+
machine: options.machine,
|
|
267
|
+
remoteSkillNames: options.skills ?? agent.skills,
|
|
268
|
+
remoteReads: options.remoteReads,
|
|
269
|
+
extensionBindings: options.extensionBindings,
|
|
270
|
+
requiredExtensions: options.requiredExtensions,
|
|
271
|
+
sessionEnabled: shared.sessionEnabled,
|
|
272
|
+
sessionDir: options.sessionDir,
|
|
273
|
+
sessionFile: options.sessionFile,
|
|
274
|
+
model: modelArg,
|
|
275
|
+
systemPromptMode: agent.systemPromptMode,
|
|
276
|
+
inheritProjectContext: agent.inheritProjectContext,
|
|
277
|
+
inheritGlobalContext: agent.inheritGlobalContext,
|
|
278
|
+
inheritSkills: agent.inheritSkills,
|
|
279
|
+
requireReadTool: Boolean(shared.resolvedSkillNames?.length),
|
|
280
|
+
tools: agent.tools,
|
|
281
|
+
excludeTools: agent.excludeTools,
|
|
282
|
+
allowNestedSubagents: agent.allowNestedSubagents,
|
|
283
|
+
descendantAllowedAgents: agent.allowedAgents,
|
|
284
|
+
extensions: agent.extensions,
|
|
285
|
+
subagentOnlyExtensions: agent.subagentOnlyExtensions,
|
|
286
|
+
// Exact terminal protocol belongs to session resources, not compactable history.
|
|
287
|
+
systemPrompt: shared.acceptancePrompt ? `${shared.systemPrompt}\n${shared.acceptancePrompt}` : shared.systemPrompt,
|
|
288
|
+
mcpDirectTools: agent.mcpDirectTools,
|
|
289
|
+
cwd: options.cwd ?? runtimeCwd,
|
|
290
|
+
intercomSessionName: options.intercomSessionName,
|
|
291
|
+
sessionName: childSessionName,
|
|
292
|
+
orchestratorIntercomTarget: options.orchestratorIntercomTarget,
|
|
293
|
+
runId: options.runId,
|
|
294
|
+
childAgentName: agent.name,
|
|
295
|
+
childIndex: options.index ?? 0,
|
|
296
|
+
nestedRoute: options.nestedRoute,
|
|
297
|
+
runFanoutBudget: options.runFanoutBudget,
|
|
298
|
+
parentSessionId: options.parentSessionId,
|
|
299
|
+
forkCacheKey: options.context === "fork" ? deriveForkPromptCacheKey(options.parentSessionId) : undefined,
|
|
300
|
+
structuredOutput: options.structuredOutput,
|
|
301
|
+
fast: options.fast ?? agent.fast,
|
|
302
|
+
toolBudget: options.toolBudget,
|
|
303
|
+
permissionRules,
|
|
304
|
+
permissionAuditPath,
|
|
305
|
+
childWatchdog,
|
|
306
|
+
// registerChildWatchdog returns before reading the sink when no watchdog exists.
|
|
307
|
+
watchdogStatus: childWatchdog ? (event) => onWatchdogStatus?.(event) : undefined,
|
|
308
|
+
waitToolEnabled: options.waitToolEnabled,
|
|
309
|
+
waitToolDefaultTimeoutMs: options.waitToolDefaultTimeoutMs,
|
|
310
|
+
capabilityCeiling: options.capabilityCeiling,
|
|
311
|
+
thinkingCeiling: options.thinkingCeiling,
|
|
312
|
+
maxSubagentDepth: options.maxSubagentDepth,
|
|
313
|
+
runtimeSnapshotHost: options.runtimeSnapshotHost,
|
|
314
|
+
inherited: options.childRuntime,
|
|
315
|
+
host: "parent",
|
|
316
|
+
});
|
|
317
|
+
if (!options.machine && options.parentProviderRegistry)
|
|
318
|
+
launch.session.parentProviderRegistry = options.parentProviderRegistry;
|
|
319
|
+
const { toolPlan, capabilityAudit, warnings, launchResolvedExtensions, capture } = launch;
|
|
320
|
+
if (!shared.launchWarnings.emitted && warnings.length > 0) {
|
|
321
|
+
for (const warning of warnings)
|
|
322
|
+
console.warn(`[pi-subagents] ${warning}`);
|
|
323
|
+
shared.launchWarnings.emitted = true;
|
|
324
|
+
}
|
|
325
|
+
const effectiveSystemPrompt = shared.systemPrompt;
|
|
326
|
+
const contractTools = toolPlan.explicitToolAllowlist ? toolPlan.effectiveToolAllowlist : undefined;
|
|
327
|
+
const contractError = validateImplementationToolContract({
|
|
328
|
+
agent: agent.name,
|
|
329
|
+
task: shared.originalTask ?? task,
|
|
330
|
+
tools: contractTools,
|
|
331
|
+
mcpDirectTools: toolPlan.effectiveMcpTools,
|
|
332
|
+
configuredExtensions: toolPlan.configuredExtensions,
|
|
333
|
+
requestedTools: toolPlan.requestedBuiltinTools,
|
|
334
|
+
acceptanceRole: agent.acceptanceRole,
|
|
335
|
+
completionGuard: agent.completionGuard,
|
|
336
|
+
});
|
|
337
|
+
if (contractError) {
|
|
338
|
+
return {
|
|
339
|
+
index: options.index ?? 0,
|
|
340
|
+
agent: agent.name,
|
|
341
|
+
task,
|
|
342
|
+
...(childSessionName ? { sessionName: childSessionName } : {}),
|
|
343
|
+
messages: [],
|
|
344
|
+
finalOutput: "",
|
|
345
|
+
exitCode: 1,
|
|
346
|
+
error: contractError,
|
|
347
|
+
usage: emptyUsage(),
|
|
348
|
+
model: modelArg,
|
|
349
|
+
progressSummary: { status: "failed", toolCount: 0, tokens: 0, durationMs: 0 },
|
|
350
|
+
...(toolPlan.capabilityCeiling ? { capabilityCeiling: toolPlan.capabilityCeiling } : {}),
|
|
351
|
+
...(toolPlan.capabilityAudit ? { capabilityAudit: toolPlan.capabilityAudit } : {}),
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
const fast = options.fast ?? agent.fast;
|
|
355
|
+
const { launchContractDigest } = resolveLaunchBinding({
|
|
356
|
+
agent,
|
|
357
|
+
task: shared.originalTask ?? task,
|
|
358
|
+
model: modelArg,
|
|
359
|
+
...(fast !== undefined ? { fast } : {}),
|
|
360
|
+
...(resolvedThinking ? { thinking: resolvedThinking } : {}),
|
|
361
|
+
systemPrompt: effectiveSystemPrompt,
|
|
362
|
+
skills: shared.resolvedSkillNames ?? [],
|
|
363
|
+
toolPlan,
|
|
364
|
+
...(options.outputPath ? { outputPath: options.outputPath } : {}),
|
|
365
|
+
outputMode: options.outputMode ?? "inline",
|
|
366
|
+
...(options.structuredOutput ? { structuredOutputSchema: options.structuredOutput.schema } : {}),
|
|
367
|
+
...(options.extensionBindings ? { extensionBindings: options.extensionBindings } : {}),
|
|
368
|
+
});
|
|
369
|
+
const result = withRunContext({
|
|
370
|
+
index: options.index ?? 0,
|
|
371
|
+
agent: agent.name,
|
|
372
|
+
task: shared.originalTask ?? task,
|
|
373
|
+
...(childSessionName ? { sessionName: childSessionName } : {}),
|
|
374
|
+
...(options.agentContract ? { agentContract: options.agentContract } : {}),
|
|
375
|
+
launchContractDigest,
|
|
376
|
+
launchResolvedExtensions,
|
|
377
|
+
exitCode: 0,
|
|
378
|
+
outputState: "absent",
|
|
379
|
+
messages: [],
|
|
380
|
+
usage: emptyUsage(),
|
|
381
|
+
model: modelArg,
|
|
382
|
+
...(resolvedThinking ? { thinking: resolvedThinking } : {}),
|
|
383
|
+
artifactPaths: shared.artifactPaths,
|
|
384
|
+
transcriptPath: shared.transcriptWriter ? shared.artifactPaths?.transcriptPath : undefined,
|
|
385
|
+
skills: shared.resolvedSkillNames,
|
|
386
|
+
skillsWarning: shared.skillsWarning,
|
|
387
|
+
...(options.toolBudget ? { toolBudget: initialToolBudgetState(options.toolBudget) } : {}),
|
|
388
|
+
...(options.capabilityCeiling ? { capabilityCeiling: options.capabilityCeiling } : {}),
|
|
389
|
+
...(capabilityAudit ? { capabilityAudit } : {}),
|
|
390
|
+
}, options.context);
|
|
391
|
+
const startTime = Date.now();
|
|
392
|
+
const controlConfig = options.controlConfig ?? DEFAULT_CONTROL_CONFIG;
|
|
393
|
+
let interruptedByControl = false;
|
|
394
|
+
const allControlEvents = [];
|
|
395
|
+
let pendingControlEvents = [];
|
|
396
|
+
const emittedControlEventKeys = new Set();
|
|
397
|
+
const emitControlEvent = (event) => {
|
|
398
|
+
if (!shouldNotifyControlEvent(controlConfig, event))
|
|
399
|
+
return;
|
|
400
|
+
if (!claimControlNotification(controlConfig, event, emittedControlEventKeys))
|
|
401
|
+
return;
|
|
402
|
+
allControlEvents.push(event);
|
|
403
|
+
pendingControlEvents.push(event);
|
|
404
|
+
options.onControlEvent?.(event);
|
|
405
|
+
};
|
|
406
|
+
const progress = {
|
|
407
|
+
index: options.index ?? 0,
|
|
408
|
+
agent: agent.name,
|
|
409
|
+
...(childSessionName ? { sessionName: childSessionName } : {}),
|
|
410
|
+
status: "running",
|
|
411
|
+
task,
|
|
412
|
+
skills: shared.resolvedSkillNames,
|
|
413
|
+
recentTools: [],
|
|
414
|
+
recentOutput: [...shared.attemptNotes],
|
|
415
|
+
toolCount: 0,
|
|
416
|
+
tokens: 0,
|
|
417
|
+
...(modelArg ? { model: modelArg } : {}),
|
|
418
|
+
...(resolvedThinking ? { thinking: resolvedThinking } : {}),
|
|
419
|
+
inputTokens: 0,
|
|
420
|
+
outputTokens: 0,
|
|
421
|
+
durationMs: 0,
|
|
422
|
+
lastActivityAt: startTime,
|
|
423
|
+
};
|
|
424
|
+
result.progress = progress;
|
|
425
|
+
const attemptTimeout = resolveAttemptTimeout(options);
|
|
426
|
+
if (attemptTimeout?.remainingMs === 0) {
|
|
427
|
+
result.exitCode = 1;
|
|
428
|
+
result.timedOut = true;
|
|
429
|
+
result.error = attemptTimeout.message;
|
|
430
|
+
result.finalOutput = attemptTimeout.message;
|
|
431
|
+
progress.status = "failed";
|
|
432
|
+
progress.error = attemptTimeout.message;
|
|
433
|
+
result.progressSummary = {
|
|
434
|
+
toolCount: progress.toolCount,
|
|
435
|
+
tokens: progress.tokens,
|
|
436
|
+
durationMs: progress.durationMs,
|
|
437
|
+
};
|
|
438
|
+
return result;
|
|
439
|
+
}
|
|
440
|
+
const mutationSnapshot = options.machine ? { source: "tracked-files", trackedOnly: true, cwd: options.cwd ?? runtimeCwd, dirtyFiles: [], fingerprints: {}, unavailable: "Local Git evidence is not authoritative for a pane-native remote run." } : snapshotTrackedMutations(options.cwd ?? runtimeCwd);
|
|
441
|
+
let observedMutationAttempt = false;
|
|
442
|
+
let structuredOutputToolInvoked = false;
|
|
443
|
+
let structuredOutputMessageStartIndex;
|
|
444
|
+
let toolAvailabilityError;
|
|
445
|
+
let abortedBySignal = options.signal?.aborted === true;
|
|
446
|
+
let afterCompactionSettlement = false;
|
|
447
|
+
if (options.workflowChildPermitLaunch) {
|
|
448
|
+
const permitError = consumeWorkflowChildPermit(options.workflowChildPermitLaunch.permit, {
|
|
449
|
+
workflowRunId: options.workflowChildPermitLaunch.workflowRunId,
|
|
450
|
+
childKey: options.workflowChildPermitLaunch.childKey,
|
|
451
|
+
agent: agent.name,
|
|
452
|
+
launchContractDigest,
|
|
453
|
+
context: options.context ?? "fresh",
|
|
454
|
+
runner: "pi",
|
|
455
|
+
});
|
|
456
|
+
if (permitError) {
|
|
457
|
+
result.exitCode = 1;
|
|
458
|
+
result.error = permitError;
|
|
459
|
+
result.finalOutput = permitError;
|
|
460
|
+
progress.status = "failed";
|
|
461
|
+
progress.error = permitError;
|
|
462
|
+
return result;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
const childSessions = options.childSessionFactory ?? childSessionFactory();
|
|
466
|
+
const exitCode = await new Promise((resolve) => {
|
|
467
|
+
const jsonlWriter = createJsonlWriter(shared.jsonlPath, { pause() { }, resume() { } });
|
|
468
|
+
let session;
|
|
469
|
+
let messageBaseline;
|
|
470
|
+
let unsubscribe;
|
|
471
|
+
let sessionSettled = false;
|
|
472
|
+
let lifecycleFinished = false;
|
|
473
|
+
let detached = false;
|
|
474
|
+
let intercomStarted = false;
|
|
475
|
+
let assistantError;
|
|
476
|
+
let removeAbortListener;
|
|
477
|
+
let removeInterruptListener;
|
|
478
|
+
let activityTimer;
|
|
479
|
+
let timeoutTimer;
|
|
480
|
+
let timeoutHardFinishTimer;
|
|
481
|
+
const clearTimeoutTimers = () => {
|
|
482
|
+
if (timeoutTimer) {
|
|
483
|
+
clearTimeout(timeoutTimer);
|
|
484
|
+
timeoutTimer = undefined;
|
|
485
|
+
}
|
|
486
|
+
if (timeoutHardFinishTimer) {
|
|
487
|
+
clearTimeout(timeoutHardFinishTimer);
|
|
488
|
+
timeoutHardFinishTimer = undefined;
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
const abortChild = () => {
|
|
492
|
+
if (!session || sessionSettled || lifecycleFinished)
|
|
493
|
+
return;
|
|
494
|
+
void session.abort().catch(() => {
|
|
495
|
+
// The session settles through its prompt promise; abort failures are not separately actionable.
|
|
496
|
+
});
|
|
497
|
+
};
|
|
498
|
+
const detachForeground = (reason) => {
|
|
499
|
+
if (detached || sessionSettled || lifecycleFinished || options.signal?.aborted)
|
|
500
|
+
return false;
|
|
501
|
+
const receiptProgress = snapshotProgress(progress);
|
|
502
|
+
receiptProgress.status = "detached";
|
|
503
|
+
receiptProgress.durationMs = Date.now() - startTime;
|
|
504
|
+
const receipt = snapshotResult(result, receiptProgress);
|
|
505
|
+
receipt.exitCode = -2;
|
|
506
|
+
receipt.detached = true;
|
|
507
|
+
receipt.detachedReason = reason;
|
|
508
|
+
receipt.finalOutput = reason === "intercom coordination"
|
|
509
|
+
? "Detached for intercom coordination before task completion."
|
|
510
|
+
: reason === "user request"
|
|
511
|
+
? "Detached at user request before task completion."
|
|
512
|
+
: `Detached for ${reason} before task completion.`;
|
|
513
|
+
receipt.outputMode = options.outputMode ?? "inline";
|
|
514
|
+
if (options.outputPath) {
|
|
515
|
+
receipt.outputSaveError = reason === "user request"
|
|
516
|
+
? "Output file was not finalized because the subagent detached at user request."
|
|
517
|
+
: `Output file was not finalized because the subagent detached for ${reason}.`;
|
|
518
|
+
}
|
|
519
|
+
receipt.progressSummary = {
|
|
520
|
+
toolCount: receiptProgress.toolCount,
|
|
521
|
+
tokens: receiptProgress.tokens,
|
|
522
|
+
durationMs: receiptProgress.durationMs,
|
|
523
|
+
};
|
|
524
|
+
// The attempt is not detached until the outer coordinator has accepted and
|
|
525
|
+
// synchronously published the receipt. A persistence/callback failure must
|
|
526
|
+
// leave this attempt attached and abortable rather than orphaning it.
|
|
527
|
+
let accepted = false;
|
|
528
|
+
try {
|
|
529
|
+
accepted = options.onDetachReceipt?.(receipt) === true;
|
|
530
|
+
}
|
|
531
|
+
catch {
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
if (!accepted)
|
|
535
|
+
return false;
|
|
536
|
+
detached = true;
|
|
537
|
+
if (session)
|
|
538
|
+
session.detached = true;
|
|
539
|
+
return true;
|
|
540
|
+
};
|
|
541
|
+
// If the child emits a terminal assistant stop but its run never settles
|
|
542
|
+
// (a hook is stuck), abort it after a short grace period and then finish
|
|
543
|
+
// without it.
|
|
544
|
+
const FINAL_STOP_GRACE_MS = 1000;
|
|
545
|
+
const HARD_FINISH_MS = 3000;
|
|
546
|
+
let forcedTermination = false;
|
|
547
|
+
let cleanTerminalAssistantStopReceived = false;
|
|
548
|
+
let agentSettledReceived = false;
|
|
549
|
+
let queuedDrainHold = false;
|
|
550
|
+
let compactionStartedReceived = false;
|
|
551
|
+
let finalDrainTimer;
|
|
552
|
+
let finalHardFinishTimer;
|
|
553
|
+
let watchdogTailTimer;
|
|
554
|
+
let childWatchdogState;
|
|
555
|
+
const updateChildWatchdogState = (snapshot) => {
|
|
556
|
+
childWatchdogState = snapshot;
|
|
557
|
+
result.watchdog = snapshot;
|
|
558
|
+
progress.watchdog = snapshot;
|
|
559
|
+
};
|
|
560
|
+
const clearWatchdogTailTimer = () => {
|
|
561
|
+
if (watchdogTailTimer) {
|
|
562
|
+
clearTimeout(watchdogTailTimer);
|
|
563
|
+
watchdogTailTimer = undefined;
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
const clearFinalDrainTimers = () => {
|
|
567
|
+
if (finalDrainTimer) {
|
|
568
|
+
clearTimeout(finalDrainTimer);
|
|
569
|
+
finalDrainTimer = undefined;
|
|
570
|
+
}
|
|
571
|
+
if (finalHardFinishTimer) {
|
|
572
|
+
clearTimeout(finalHardFinishTimer);
|
|
573
|
+
finalHardFinishTimer = undefined;
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
const observeQueuedDrainHold = () => {
|
|
577
|
+
if (childSessionHasQueuedMessages(session))
|
|
578
|
+
queuedDrainHold = true;
|
|
579
|
+
return queuedDrainHold;
|
|
580
|
+
};
|
|
581
|
+
const startFinalDrain = () => {
|
|
582
|
+
if (childWatchdogIsActive(childWatchdogState)) {
|
|
583
|
+
armWatchdogTail();
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
if (sessionSettled || finalDrainTimer || lifecycleFinished)
|
|
587
|
+
return;
|
|
588
|
+
if (observeQueuedDrainHold())
|
|
589
|
+
return;
|
|
590
|
+
armFinalDrainTimer();
|
|
591
|
+
};
|
|
592
|
+
const armFinalDrainTimer = () => {
|
|
593
|
+
if (sessionSettled || finalDrainTimer || lifecycleFinished)
|
|
594
|
+
return;
|
|
595
|
+
finalDrainTimer = setTimeout(() => {
|
|
596
|
+
if (lifecycleFinished || sessionSettled)
|
|
597
|
+
return;
|
|
598
|
+
if (capture.finalDrainHeld() || observeQueuedDrainHold()) {
|
|
599
|
+
finalDrainTimer = undefined;
|
|
600
|
+
armFinalDrainTimer();
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
forcedTermination = true;
|
|
604
|
+
if (!cleanTerminalAssistantStopReceived && !agentSettledReceived && !assistantError) {
|
|
605
|
+
result.error = result.error ?? `Subagent session did not settle within ${FINAL_STOP_GRACE_MS}ms after its terminal event. Aborting it.`;
|
|
606
|
+
}
|
|
607
|
+
abortChild();
|
|
608
|
+
finalHardFinishTimer = setTimeout(() => {
|
|
609
|
+
if (lifecycleFinished || sessionSettled)
|
|
610
|
+
return;
|
|
611
|
+
settle(undefined, true);
|
|
612
|
+
}, HARD_FINISH_MS);
|
|
613
|
+
finalHardFinishTimer.unref?.();
|
|
614
|
+
}, FINAL_STOP_GRACE_MS);
|
|
615
|
+
finalDrainTimer.unref?.();
|
|
616
|
+
};
|
|
617
|
+
function armWatchdogTail() {
|
|
618
|
+
if ((!cleanTerminalAssistantStopReceived && !agentSettledReceived) || watchdogTailTimer || lifecycleFinished || sessionSettled)
|
|
619
|
+
return;
|
|
620
|
+
watchdogTailTimer = setTimeout(() => {
|
|
621
|
+
watchdogTailTimer = undefined;
|
|
622
|
+
updateChildWatchdogState({
|
|
623
|
+
phase: "stale",
|
|
624
|
+
seq: (childWatchdogState?.seq ?? 0) + 1,
|
|
625
|
+
lastUpdate: Date.now(),
|
|
626
|
+
reason: "child watchdog tail timeout",
|
|
627
|
+
timedOut: true,
|
|
628
|
+
});
|
|
629
|
+
startFinalDrain();
|
|
630
|
+
fireUpdate();
|
|
631
|
+
}, childWatchdog?.watchdogTailTimeoutMs ?? 120_000);
|
|
632
|
+
watchdogTailTimer.unref?.();
|
|
633
|
+
}
|
|
634
|
+
const applyChildLifecycle = (action) => {
|
|
635
|
+
if (action === "cancel-drain") {
|
|
636
|
+
cleanTerminalAssistantStopReceived = false;
|
|
637
|
+
agentSettledReceived = false;
|
|
638
|
+
clearFinalDrainTimers();
|
|
639
|
+
clearWatchdogTailTimer();
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
if (action === "start-drain")
|
|
643
|
+
startFinalDrain();
|
|
644
|
+
};
|
|
645
|
+
const childLifecycleState = { compactionRetryActive: false };
|
|
646
|
+
const unsubscribeIntercomDetach = options.intercomEvents?.on?.(INTERCOM_DETACH_REQUEST_EVENT, (payload) => {
|
|
647
|
+
if (!options.allowIntercomDetach || sessionSettled)
|
|
648
|
+
return;
|
|
649
|
+
if (!payload || typeof payload !== "object")
|
|
650
|
+
return;
|
|
651
|
+
const event = payload;
|
|
652
|
+
const requestId = event.requestId;
|
|
653
|
+
if (typeof requestId !== "string" || requestId.length === 0)
|
|
654
|
+
return;
|
|
655
|
+
const hasRoute = event.runId !== undefined || event.agent !== undefined || event.childIndex !== undefined;
|
|
656
|
+
if (hasRoute) {
|
|
657
|
+
if (typeof event.runId === "string" && event.runId !== options.runId)
|
|
658
|
+
return;
|
|
659
|
+
if (typeof event.agent === "string" && event.agent !== agent.name)
|
|
660
|
+
return;
|
|
661
|
+
if (typeof event.childIndex === "number" && event.childIndex !== (options.index ?? 0))
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
else if (!intercomStarted)
|
|
665
|
+
return;
|
|
666
|
+
const accepted = detachForeground("intercom coordination");
|
|
667
|
+
options.intercomEvents?.emit(INTERCOM_DETACH_RESPONSE_EVENT, { requestId, accepted, runId: options.runId, agent: agent.name, childIndex: options.index ?? 0 });
|
|
668
|
+
});
|
|
669
|
+
const finish = (code) => {
|
|
670
|
+
if (lifecycleFinished)
|
|
671
|
+
return;
|
|
672
|
+
lifecycleFinished = true;
|
|
673
|
+
clearFinalDrainTimers();
|
|
674
|
+
clearWatchdogTailTimer();
|
|
675
|
+
clearTimeoutTimers();
|
|
676
|
+
clearAllToolTimeouts();
|
|
677
|
+
if (activityTimer) {
|
|
678
|
+
clearInterval(activityTimer);
|
|
679
|
+
activityTimer = undefined;
|
|
680
|
+
}
|
|
681
|
+
unsubscribeIntercomDetach?.();
|
|
682
|
+
removeAbortListener?.();
|
|
683
|
+
removeInterruptListener?.();
|
|
684
|
+
unsubscribe?.();
|
|
685
|
+
onWatchdogStatus = undefined;
|
|
686
|
+
void jsonlWriter.close().catch(() => {
|
|
687
|
+
// JSONL artifact flush is best effort.
|
|
688
|
+
});
|
|
689
|
+
// Report the run only after the child's extensions have shut down.
|
|
690
|
+
void Promise.resolve().then(() => session?.dispose()).catch(() => undefined).then(() => {
|
|
691
|
+
resolve(code);
|
|
692
|
+
});
|
|
693
|
+
};
|
|
694
|
+
const drainPendingControlEvents = () => {
|
|
695
|
+
if (pendingControlEvents.length === 0)
|
|
696
|
+
return undefined;
|
|
697
|
+
const events = pendingControlEvents;
|
|
698
|
+
pendingControlEvents = [];
|
|
699
|
+
return events;
|
|
700
|
+
};
|
|
701
|
+
let activeLongRunningNotified = false;
|
|
702
|
+
let pendingToolResult;
|
|
703
|
+
let activeToolSequence = 0;
|
|
704
|
+
const activeToolCalls = new Map();
|
|
705
|
+
const activeToolKeysByName = new Map();
|
|
706
|
+
const latestActiveToolCall = () => [...activeToolCalls.values()].sort((left, right) => right.startedAt - left.startedAt)[0];
|
|
707
|
+
const refreshCurrentTool = () => {
|
|
708
|
+
const active = latestActiveToolCall();
|
|
709
|
+
if (!active) {
|
|
710
|
+
progress.currentTool = undefined;
|
|
711
|
+
progress.currentToolArgs = undefined;
|
|
712
|
+
progress.currentToolStartedAt = undefined;
|
|
713
|
+
progress.currentPath = undefined;
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
progress.currentTool = active.tool;
|
|
717
|
+
progress.currentToolArgs = active.args;
|
|
718
|
+
progress.currentToolStartedAt = active.startedAt;
|
|
719
|
+
progress.currentPath = active.path;
|
|
720
|
+
};
|
|
721
|
+
const recordActiveToolCall = (event, args, now) => {
|
|
722
|
+
const key = toolTimeoutCallKey(event, ++activeToolSequence);
|
|
723
|
+
const path = resolveCurrentPath(event.toolName, args);
|
|
724
|
+
const active = {
|
|
725
|
+
key,
|
|
726
|
+
tool: event.toolName,
|
|
727
|
+
args: extractToolArgsPreview(args),
|
|
728
|
+
startedAt: now,
|
|
729
|
+
...(path !== undefined ? { path } : {}),
|
|
730
|
+
};
|
|
731
|
+
activeToolCalls.set(key, active);
|
|
732
|
+
const keys = activeToolKeysByName.get(active.tool) ?? [];
|
|
733
|
+
keys.push(key);
|
|
734
|
+
activeToolKeysByName.set(active.tool, keys);
|
|
735
|
+
refreshCurrentTool();
|
|
736
|
+
return active;
|
|
737
|
+
};
|
|
738
|
+
const removeActiveToolCallKey = (key) => {
|
|
739
|
+
const active = activeToolCalls.get(key);
|
|
740
|
+
if (!active)
|
|
741
|
+
return undefined;
|
|
742
|
+
activeToolCalls.delete(key);
|
|
743
|
+
const keys = activeToolKeysByName.get(active.tool)?.filter((candidate) => candidate !== key) ?? [];
|
|
744
|
+
if (keys.length > 0)
|
|
745
|
+
activeToolKeysByName.set(active.tool, keys);
|
|
746
|
+
else
|
|
747
|
+
activeToolKeysByName.delete(active.tool);
|
|
748
|
+
return active;
|
|
749
|
+
};
|
|
750
|
+
const removeActiveToolCall = (event) => {
|
|
751
|
+
const key = typeof event.toolCallId === "string" && event.toolCallId.length > 0
|
|
752
|
+
? `id:${event.toolCallId}`
|
|
753
|
+
: typeof event.toolName === "string"
|
|
754
|
+
? activeToolKeysByName.get(event.toolName)?.[0]
|
|
755
|
+
: activeToolCalls.size === 1
|
|
756
|
+
? [...activeToolCalls.keys()][0]
|
|
757
|
+
: undefined;
|
|
758
|
+
return key ? removeActiveToolCallKey(key) : undefined;
|
|
759
|
+
};
|
|
760
|
+
const openToolAttentionTarget = (now) => [...activeToolCalls.values()]
|
|
761
|
+
.filter((active) => shouldEmitOpenToolAttention({ config: controlConfig, currentTool: active.tool, currentToolStartedAt: active.startedAt, now }))
|
|
762
|
+
.sort((left, right) => left.startedAt - right.startedAt)[0];
|
|
763
|
+
const mutatingFailures = createMutatingFailureState();
|
|
764
|
+
const mutatingFailureWindowMs = 5 * 60_000;
|
|
765
|
+
const currentToolDurationMs = (now) => progress.currentToolStartedAt ? Math.max(0, now - progress.currentToolStartedAt) : undefined;
|
|
766
|
+
const emitNeedsAttention = (now, input = {}) => {
|
|
767
|
+
if (!controlConfig.enabled)
|
|
768
|
+
return false;
|
|
769
|
+
const previous = progress.activityState;
|
|
770
|
+
progress.activityState = "needs_attention";
|
|
771
|
+
const event = buildControlEvent({
|
|
772
|
+
type: "needs_attention",
|
|
773
|
+
from: previous,
|
|
774
|
+
to: "needs_attention",
|
|
775
|
+
runId: options.runId,
|
|
776
|
+
agent: agent.name,
|
|
777
|
+
index: options.index,
|
|
778
|
+
ts: now,
|
|
779
|
+
lastActivityAt: progress.lastActivityAt,
|
|
780
|
+
message: input.message,
|
|
781
|
+
reason: input.reason ?? "idle",
|
|
782
|
+
turns: result.usage.turns,
|
|
783
|
+
tokens: progress.tokens,
|
|
784
|
+
toolCount: progress.toolCount,
|
|
785
|
+
currentTool: input.currentTool ?? progress.currentTool,
|
|
786
|
+
currentToolDurationMs: input.currentToolDurationMs ?? currentToolDurationMs(now),
|
|
787
|
+
currentPath: input.currentPath ?? progress.currentPath,
|
|
788
|
+
recentFailureSummary: input.recentFailureSummary,
|
|
789
|
+
taskPreview: task,
|
|
790
|
+
});
|
|
791
|
+
emitControlEvent(event);
|
|
792
|
+
return previous !== "needs_attention";
|
|
793
|
+
};
|
|
794
|
+
const emitActiveLongRunning = (now, reason) => {
|
|
795
|
+
if (!controlConfig.enabled || activeLongRunningNotified || progress.activityState === "needs_attention")
|
|
796
|
+
return false;
|
|
797
|
+
activeLongRunningNotified = true;
|
|
798
|
+
const previous = progress.activityState;
|
|
799
|
+
progress.activityState = "active_long_running";
|
|
800
|
+
emitControlEvent(buildControlEvent({
|
|
801
|
+
type: "active_long_running",
|
|
802
|
+
from: previous,
|
|
803
|
+
to: "active_long_running",
|
|
804
|
+
runId: options.runId,
|
|
805
|
+
agent: agent.name,
|
|
806
|
+
index: options.index,
|
|
807
|
+
ts: now,
|
|
808
|
+
message: `${agent.name} is still active but long-running`,
|
|
809
|
+
reason,
|
|
810
|
+
turns: result.usage.turns,
|
|
811
|
+
tokens: progress.tokens,
|
|
812
|
+
toolCount: progress.toolCount,
|
|
813
|
+
currentTool: progress.currentTool,
|
|
814
|
+
currentToolDurationMs: currentToolDurationMs(now),
|
|
815
|
+
currentPath: progress.currentPath,
|
|
816
|
+
elapsedMs: now - startTime,
|
|
817
|
+
taskPreview: task,
|
|
818
|
+
}));
|
|
819
|
+
return true;
|
|
820
|
+
};
|
|
821
|
+
const updateActivityState = (now) => {
|
|
822
|
+
if (!controlConfig.enabled)
|
|
823
|
+
return false;
|
|
824
|
+
const idleState = deriveActivityState({
|
|
825
|
+
config: controlConfig,
|
|
826
|
+
startedAt: startTime,
|
|
827
|
+
lastActivityAt: progress.lastActivityAt,
|
|
828
|
+
turnCount: progress.turnCount,
|
|
829
|
+
currentTool: progress.currentTool,
|
|
830
|
+
thinking: resolvedThinking,
|
|
831
|
+
now,
|
|
832
|
+
});
|
|
833
|
+
if (idleState === "needs_attention") {
|
|
834
|
+
return progress.activityState === "needs_attention" ? false : emitNeedsAttention(now);
|
|
835
|
+
}
|
|
836
|
+
const toolAttentionTarget = progress.activityState !== "needs_attention" ? openToolAttentionTarget(now) : undefined;
|
|
837
|
+
if (toolAttentionTarget) {
|
|
838
|
+
const durationMs = Math.max(0, now - toolAttentionTarget.startedAt);
|
|
839
|
+
return emitNeedsAttention(now, {
|
|
840
|
+
message: `${agent.name} has had tool '${toolAttentionTarget.tool}' open for ${Math.floor(durationMs / 1000)}s`,
|
|
841
|
+
reason: "tool_open_threshold",
|
|
842
|
+
currentTool: toolAttentionTarget.tool,
|
|
843
|
+
currentPath: toolAttentionTarget.path,
|
|
844
|
+
currentToolDurationMs: durationMs,
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
const activeReason = nextLongRunningTrigger(controlConfig, {
|
|
848
|
+
startedAt: startTime,
|
|
849
|
+
now,
|
|
850
|
+
turns: result.usage.turns,
|
|
851
|
+
tokens: progress.tokens,
|
|
852
|
+
});
|
|
853
|
+
return activeReason ? emitActiveLongRunning(now, activeReason) : false;
|
|
854
|
+
};
|
|
855
|
+
let lastStructuredDelegationProgressState;
|
|
856
|
+
const emitUpdateSnapshot = (text) => {
|
|
857
|
+
if (!options.onUpdate || sessionSettled)
|
|
858
|
+
return;
|
|
859
|
+
const progressSnapshot = snapshotProgress(progress);
|
|
860
|
+
const resultSnapshot = snapshotStreamResult(result, progressSnapshot);
|
|
861
|
+
const controlEvents = drainPendingControlEvents();
|
|
862
|
+
options.onUpdate({
|
|
863
|
+
content: [{ type: "text", text }],
|
|
864
|
+
details: {
|
|
865
|
+
mode: "single",
|
|
866
|
+
results: [resultSnapshot],
|
|
867
|
+
progress: [progressSnapshot],
|
|
868
|
+
controlEvents,
|
|
869
|
+
},
|
|
870
|
+
});
|
|
871
|
+
};
|
|
872
|
+
const fireUpdate = () => {
|
|
873
|
+
if (!options.onUpdate || sessionSettled)
|
|
874
|
+
return;
|
|
875
|
+
progress.durationMs = Date.now() - startTime;
|
|
876
|
+
if (options.suppressUnchangedDelegationUpdates) {
|
|
877
|
+
if (lastStructuredDelegationProgressState && !structuredDelegationProgressChanged(lastStructuredDelegationProgressState, progress, result))
|
|
878
|
+
return;
|
|
879
|
+
lastStructuredDelegationProgressState = captureStructuredDelegationProgressState(progress, result);
|
|
880
|
+
}
|
|
881
|
+
const output = result.timedOut && result.finalOutput ? result.finalOutput : getFinalOutput(result.messages ?? []);
|
|
882
|
+
emitUpdateSnapshot(output || "(running...)");
|
|
883
|
+
};
|
|
884
|
+
const processEvent = (evt) => {
|
|
885
|
+
if (lifecycleFinished)
|
|
886
|
+
return;
|
|
887
|
+
jsonlWriter.writeLine(JSON.stringify(projectChildSessionEventForJson(evt)));
|
|
888
|
+
shared.transcriptWriter?.writeChildEvent(evt);
|
|
889
|
+
shared.orcaProgressTab?.event(evt);
|
|
890
|
+
if (evt.type === "compaction_start")
|
|
891
|
+
compactionStartedReceived = true;
|
|
892
|
+
if (evt.type === "compaction_end" && evt.willRetry === true) {
|
|
893
|
+
compactionStartedReceived = false;
|
|
894
|
+
afterCompactionSettlement = false;
|
|
895
|
+
}
|
|
896
|
+
if (evt.type === "turn_start" || evt.type === "agent_start" || evt.type === "auto_retry_start") {
|
|
897
|
+
queuedDrainHold = false;
|
|
898
|
+
}
|
|
899
|
+
if (evt.type === "agent_start" || evt.type === "auto_retry_start") {
|
|
900
|
+
compactionStartedReceived = false;
|
|
901
|
+
afterCompactionSettlement = false;
|
|
902
|
+
}
|
|
903
|
+
if (evt.type === "agent_start") {
|
|
904
|
+
const diagnostic = capture.toolDiagnostic();
|
|
905
|
+
if (diagnostic) {
|
|
906
|
+
const message = formatChildToolDiagnostic(diagnostic, { host: "parent" });
|
|
907
|
+
toolAvailabilityError = message;
|
|
908
|
+
result.error = message;
|
|
909
|
+
result.finalOutput = message;
|
|
910
|
+
progress.status = "failed";
|
|
911
|
+
progress.error = message;
|
|
912
|
+
fireUpdate();
|
|
913
|
+
abortChild();
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
const lifecycleAction = projectChildLifecycle(evt, false, childLifecycleState);
|
|
918
|
+
if (evt.type === "agent_settled" && lifecycleAction === "start-drain") {
|
|
919
|
+
agentSettledReceived = true;
|
|
920
|
+
afterCompactionSettlement = compactionStartedReceived;
|
|
921
|
+
}
|
|
922
|
+
applyChildLifecycle(lifecycleAction);
|
|
923
|
+
if (isChildWatchdogStatusEvent(evt)) {
|
|
924
|
+
if (!childWatchdog)
|
|
925
|
+
return;
|
|
926
|
+
const next = acceptChildWatchdogEvent({
|
|
927
|
+
current: childWatchdogState,
|
|
928
|
+
event: evt,
|
|
929
|
+
runId: options.runId,
|
|
930
|
+
agent: agent.name,
|
|
931
|
+
childIndex: options.index ?? 0,
|
|
932
|
+
});
|
|
933
|
+
if (!next)
|
|
934
|
+
return;
|
|
935
|
+
updateChildWatchdogState(next);
|
|
936
|
+
if (childWatchdogIsActive(next)) {
|
|
937
|
+
clearFinalDrainTimers();
|
|
938
|
+
armWatchdogTail();
|
|
939
|
+
}
|
|
940
|
+
else {
|
|
941
|
+
clearWatchdogTailTimer();
|
|
942
|
+
if (cleanTerminalAssistantStopReceived || agentSettledReceived)
|
|
943
|
+
startFinalDrain();
|
|
944
|
+
}
|
|
945
|
+
fireUpdate();
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
const now = Date.now();
|
|
949
|
+
progress.durationMs = now - startTime;
|
|
950
|
+
progress.lastActivityAt = now;
|
|
951
|
+
updateActivityState(now);
|
|
952
|
+
if (evt.type === "tool_execution_start") {
|
|
953
|
+
const toolArgs = evt.args && typeof evt.args === "object" && !Array.isArray(evt.args)
|
|
954
|
+
? evt.args
|
|
955
|
+
: {};
|
|
956
|
+
const activeTool = evt.toolName !== undefined ? recordActiveToolCall(evt, toolArgs, now) : undefined;
|
|
957
|
+
if (evt.toolName !== undefined)
|
|
958
|
+
armToolTimeout(evt);
|
|
959
|
+
if (options.structuredOutput && evt.toolName === "structured_output") {
|
|
960
|
+
structuredOutputToolInvoked = true;
|
|
961
|
+
structuredOutputMessageStartIndex = result.messages?.length ?? 0;
|
|
962
|
+
}
|
|
963
|
+
if (options.allowIntercomDetach && (evt.toolName === "intercom" || evt.toolName === "contact_supervisor")) {
|
|
964
|
+
intercomStarted = true;
|
|
965
|
+
}
|
|
966
|
+
progress.toolCount++;
|
|
967
|
+
if (options.toolBudget) {
|
|
968
|
+
result.toolBudget = toolBudgetState(options.toolBudget, progress.toolCount);
|
|
969
|
+
}
|
|
970
|
+
const mutates = isMutatingTool(evt.toolName, toolArgs, agent.mutationTools);
|
|
971
|
+
observedMutationAttempt = observedMutationAttempt || mutates;
|
|
972
|
+
pendingToolResult = { tool: evt.toolName ?? "tool", path: activeTool?.path, mutates, startedAt: now };
|
|
973
|
+
fireUpdate();
|
|
974
|
+
}
|
|
975
|
+
if (evt.type === "tool_execution_end") {
|
|
976
|
+
clearActiveToolTimeout(evt);
|
|
977
|
+
const endedTool = removeActiveToolCall(evt);
|
|
978
|
+
if (endedTool) {
|
|
979
|
+
progress.recentTools.push({
|
|
980
|
+
tool: endedTool.tool,
|
|
981
|
+
args: endedTool.args,
|
|
982
|
+
endMs: now,
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
refreshCurrentTool();
|
|
986
|
+
fireUpdate();
|
|
987
|
+
}
|
|
988
|
+
if (evt.type === "message_end" && evt.message) {
|
|
989
|
+
result.messages.push(evt.message);
|
|
990
|
+
if (childWatchdog) {
|
|
991
|
+
const next = applyChildWatchdogMessage(childWatchdogState, evt.message);
|
|
992
|
+
if (next)
|
|
993
|
+
updateChildWatchdogState(next);
|
|
994
|
+
}
|
|
995
|
+
if (evt.message.role === "assistant") {
|
|
996
|
+
result.usage.turns++;
|
|
997
|
+
progress.turnCount = result.usage.turns;
|
|
998
|
+
const toolCalls = Array.isArray(evt.message.content)
|
|
999
|
+
? evt.message.content.filter((part) => part.type === "toolCall")
|
|
1000
|
+
: [];
|
|
1001
|
+
const hasToolCall = toolCalls.length > 0;
|
|
1002
|
+
const terminalAssistantStop = evt.message.stopReason === "stop" && !hasToolCall;
|
|
1003
|
+
const u = evt.message.usage;
|
|
1004
|
+
if (u) {
|
|
1005
|
+
const window = (u.input || 0) + (u.cacheRead || 0);
|
|
1006
|
+
result.usage.input += u.input || 0;
|
|
1007
|
+
result.usage.output += u.output || 0;
|
|
1008
|
+
result.usage.cacheRead += u.cacheRead || 0;
|
|
1009
|
+
result.usage.cacheWrite += u.cacheWrite || 0;
|
|
1010
|
+
result.usage.cost += u.cost?.total || 0;
|
|
1011
|
+
progress.tokens = result.usage.input + result.usage.output;
|
|
1012
|
+
progress.inputTokens = result.usage.input;
|
|
1013
|
+
progress.outputTokens = result.usage.output;
|
|
1014
|
+
progress.window = window;
|
|
1015
|
+
progress.windowPeak = Math.max(progress.windowPeak ?? 0, window);
|
|
1016
|
+
}
|
|
1017
|
+
if (evt.message.model) {
|
|
1018
|
+
progress.model = evt.message.model;
|
|
1019
|
+
if (!result.model)
|
|
1020
|
+
result.model = evt.message.model;
|
|
1021
|
+
if (expectedModelForVerification && !hasToolCall) {
|
|
1022
|
+
const modelVerificationError = formatSubagentModelVerificationError(expectedModelForVerification, evt.message.model, options.availableModels, options.modelResponseAliases);
|
|
1023
|
+
if (modelVerificationError && !result.error)
|
|
1024
|
+
result.error = modelVerificationError;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
if (evt.message.errorMessage)
|
|
1028
|
+
assistantError = evt.message.errorMessage;
|
|
1029
|
+
else if (hasToolCall && evt.message.stopReason === "toolUse") {
|
|
1030
|
+
// A recovered request can finish via a terminating tool, without a text stop.
|
|
1031
|
+
assistantError = undefined;
|
|
1032
|
+
}
|
|
1033
|
+
const assistantText = extractTextFromContent(evt.message.content);
|
|
1034
|
+
appendRecentOutput(progress, assistantText.split("\n").slice(-10));
|
|
1035
|
+
// Final assistant message: start the settle drain window.
|
|
1036
|
+
if (terminalAssistantStop) {
|
|
1037
|
+
if (!evt.message.errorMessage && assistantText.trim())
|
|
1038
|
+
assistantError = undefined;
|
|
1039
|
+
cleanTerminalAssistantStopReceived ||= !evt.message.errorMessage;
|
|
1040
|
+
clearAllToolTimeouts();
|
|
1041
|
+
activeToolCalls.clear();
|
|
1042
|
+
activeToolKeysByName.clear();
|
|
1043
|
+
refreshCurrentTool();
|
|
1044
|
+
applyChildLifecycle(projectChildLifecycle(evt, true, childLifecycleState));
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
updateActivityState(now);
|
|
1048
|
+
fireUpdate();
|
|
1049
|
+
}
|
|
1050
|
+
if (evt.type === "tool_result_end" && evt.message) {
|
|
1051
|
+
const toolResultCompletion = {
|
|
1052
|
+
toolCallId: evt.message.toolCallId ?? evt.toolCallId,
|
|
1053
|
+
toolName: evt.message.toolName ?? evt.toolName,
|
|
1054
|
+
};
|
|
1055
|
+
clearActiveToolTimeout(toolResultCompletion);
|
|
1056
|
+
const endedTool = removeActiveToolCall(toolResultCompletion);
|
|
1057
|
+
if (endedTool) {
|
|
1058
|
+
progress.recentTools.push({
|
|
1059
|
+
tool: endedTool.tool,
|
|
1060
|
+
args: endedTool.args,
|
|
1061
|
+
endMs: now,
|
|
1062
|
+
});
|
|
1063
|
+
refreshCurrentTool();
|
|
1064
|
+
}
|
|
1065
|
+
result.messages.push(evt.message);
|
|
1066
|
+
const resultText = extractTextFromContent(evt.message.content);
|
|
1067
|
+
// The result event's own tool name is authoritative; the single pending slot can
|
|
1068
|
+
// describe a different, overlapping call and serves only as a fallback.
|
|
1069
|
+
const blockedTool = (typeof toolResultCompletion.toolName === "string" && toolResultCompletion.toolName.length > 0
|
|
1070
|
+
? toolResultCompletion.toolName
|
|
1071
|
+
: undefined) ?? pendingToolResult?.tool;
|
|
1072
|
+
if (options.toolBudget && isToolBudgetBlockedMessage(options.toolBudget, resultText, blockedTool)) {
|
|
1073
|
+
result.toolBudgetBlocked = true;
|
|
1074
|
+
result.toolBudget = toolBudgetState(options.toolBudget, Math.max(progress.toolCount, options.toolBudget.hard + 1), blockedTool);
|
|
1075
|
+
}
|
|
1076
|
+
appendRecentOutput(progress, resultText.split("\n").slice(-10));
|
|
1077
|
+
const toolSnapshot = pendingToolResult;
|
|
1078
|
+
pendingToolResult = undefined;
|
|
1079
|
+
if (toolSnapshot?.mutates && didMutatingToolFail(resultText)) {
|
|
1080
|
+
recordMutatingFailure(mutatingFailures, {
|
|
1081
|
+
tool: toolSnapshot.tool,
|
|
1082
|
+
path: toolSnapshot.path,
|
|
1083
|
+
error: resultText.split("\n").find((line) => line.trim())?.trim().slice(0, 180) ?? "mutating tool failed",
|
|
1084
|
+
ts: now,
|
|
1085
|
+
}, mutatingFailureWindowMs);
|
|
1086
|
+
if (shouldEscalateMutatingFailures(mutatingFailures, controlConfig.failedToolAttemptsBeforeAttention)) {
|
|
1087
|
+
emitNeedsAttention(now, {
|
|
1088
|
+
message: `${agent.name} needs attention after repeated mutating tool failures`,
|
|
1089
|
+
reason: "tool_failures",
|
|
1090
|
+
currentTool: toolSnapshot.tool,
|
|
1091
|
+
currentPath: toolSnapshot.path,
|
|
1092
|
+
currentToolDurationMs: toolSnapshot.startedAt ? Math.max(0, now - toolSnapshot.startedAt) : undefined,
|
|
1093
|
+
recentFailureSummary: summarizeRecentMutatingFailures(mutatingFailures),
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
else if (toolSnapshot?.mutates) {
|
|
1098
|
+
resetMutatingFailureState(mutatingFailures);
|
|
1099
|
+
}
|
|
1100
|
+
fireUpdate();
|
|
1101
|
+
}
|
|
1102
|
+
};
|
|
1103
|
+
onWatchdogStatus = (event) => processEvent(event);
|
|
1104
|
+
fireUpdate();
|
|
1105
|
+
if (controlConfig.enabled || options.onUpdate) {
|
|
1106
|
+
activityTimer = setInterval(() => {
|
|
1107
|
+
if (sessionSettled || lifecycleFinished) {
|
|
1108
|
+
return;
|
|
1109
|
+
}
|
|
1110
|
+
updateActivityState(Date.now());
|
|
1111
|
+
fireUpdate();
|
|
1112
|
+
}, 1000);
|
|
1113
|
+
activityTimer.unref?.();
|
|
1114
|
+
}
|
|
1115
|
+
if (attemptTimeout) {
|
|
1116
|
+
timeoutTimer = setTimeout(() => {
|
|
1117
|
+
if (sessionSettled || lifecycleFinished || interruptedByControl)
|
|
1118
|
+
return;
|
|
1119
|
+
result.timedOut = true;
|
|
1120
|
+
clearAllToolTimeouts();
|
|
1121
|
+
result.error = attemptTimeout.message;
|
|
1122
|
+
result.finalOutput = attemptTimeout.message;
|
|
1123
|
+
progress.status = "failed";
|
|
1124
|
+
progress.error = attemptTimeout.message;
|
|
1125
|
+
progress.durationMs = Date.now() - startTime;
|
|
1126
|
+
fireUpdate();
|
|
1127
|
+
abortChild();
|
|
1128
|
+
timeoutHardFinishTimer = setTimeout(() => {
|
|
1129
|
+
if (sessionSettled || lifecycleFinished)
|
|
1130
|
+
return;
|
|
1131
|
+
settle(undefined, true);
|
|
1132
|
+
}, 4000);
|
|
1133
|
+
timeoutHardFinishTimer.unref?.();
|
|
1134
|
+
}, attemptTimeout.remainingMs);
|
|
1135
|
+
timeoutTimer.unref?.();
|
|
1136
|
+
}
|
|
1137
|
+
let toolTimeoutSequence = 0;
|
|
1138
|
+
const activeToolTimeouts = new Map();
|
|
1139
|
+
const activeToolTimeoutKeysByName = new Map();
|
|
1140
|
+
let toolTimeoutHardFinishTimer;
|
|
1141
|
+
const removeToolTimeoutKey = (key) => {
|
|
1142
|
+
const active = activeToolTimeouts.get(key);
|
|
1143
|
+
if (!active)
|
|
1144
|
+
return;
|
|
1145
|
+
clearTimeout(active.timer);
|
|
1146
|
+
activeToolTimeouts.delete(key);
|
|
1147
|
+
const keys = activeToolTimeoutKeysByName.get(active.toolName)?.filter((candidate) => candidate !== key) ?? [];
|
|
1148
|
+
if (keys.length > 0)
|
|
1149
|
+
activeToolTimeoutKeysByName.set(active.toolName, keys);
|
|
1150
|
+
else
|
|
1151
|
+
activeToolTimeoutKeysByName.delete(active.toolName);
|
|
1152
|
+
};
|
|
1153
|
+
const clearActiveToolTimeout = (event) => {
|
|
1154
|
+
const key = typeof event.toolCallId === "string" && event.toolCallId.length > 0
|
|
1155
|
+
? `id:${event.toolCallId}`
|
|
1156
|
+
: typeof event.toolName === "string"
|
|
1157
|
+
? activeToolTimeoutKeysByName.get(event.toolName)?.[0]
|
|
1158
|
+
: activeToolTimeouts.size === 1
|
|
1159
|
+
? [...activeToolTimeouts.keys()][0]
|
|
1160
|
+
: undefined;
|
|
1161
|
+
if (key)
|
|
1162
|
+
removeToolTimeoutKey(key);
|
|
1163
|
+
};
|
|
1164
|
+
const clearAllToolTimeouts = () => {
|
|
1165
|
+
for (const key of [...activeToolTimeouts.keys()])
|
|
1166
|
+
removeToolTimeoutKey(key);
|
|
1167
|
+
if (toolTimeoutHardFinishTimer) {
|
|
1168
|
+
clearTimeout(toolTimeoutHardFinishTimer);
|
|
1169
|
+
toolTimeoutHardFinishTimer = undefined;
|
|
1170
|
+
}
|
|
1171
|
+
};
|
|
1172
|
+
const terminateForToolTimeout = (message) => {
|
|
1173
|
+
if (sessionSettled || lifecycleFinished || interruptedByControl)
|
|
1174
|
+
return;
|
|
1175
|
+
result.timedOut = true;
|
|
1176
|
+
result.error = message;
|
|
1177
|
+
result.finalOutput = message;
|
|
1178
|
+
progress.status = "failed";
|
|
1179
|
+
progress.error = message;
|
|
1180
|
+
progress.durationMs = Date.now() - startTime;
|
|
1181
|
+
fireUpdate();
|
|
1182
|
+
abortChild();
|
|
1183
|
+
toolTimeoutHardFinishTimer = setTimeout(() => {
|
|
1184
|
+
if (sessionSettled || lifecycleFinished)
|
|
1185
|
+
return;
|
|
1186
|
+
settle(undefined, true);
|
|
1187
|
+
}, 4000);
|
|
1188
|
+
toolTimeoutHardFinishTimer.unref?.();
|
|
1189
|
+
};
|
|
1190
|
+
const armToolTimeout = (event) => {
|
|
1191
|
+
const timeoutForTool = effectiveToolTimeoutMs(event.toolName, options.toolTimeoutMs);
|
|
1192
|
+
if (timeoutForTool === undefined)
|
|
1193
|
+
return;
|
|
1194
|
+
const elapsed = Date.now() - startTime;
|
|
1195
|
+
const runRemaining = attemptTimeout ? Math.max(0, attemptTimeout.remainingMs - elapsed) : undefined;
|
|
1196
|
+
if (runRemaining !== undefined && timeoutForTool >= runRemaining)
|
|
1197
|
+
return;
|
|
1198
|
+
const key = toolTimeoutCallKey(event, ++toolTimeoutSequence);
|
|
1199
|
+
const toolName = event.toolName;
|
|
1200
|
+
const timer = setTimeout(() => {
|
|
1201
|
+
removeToolTimeoutKey(key);
|
|
1202
|
+
terminateForToolTimeout(formatToolTimeoutMessage(toolName, timeoutForTool));
|
|
1203
|
+
}, timeoutForTool);
|
|
1204
|
+
timer.unref?.();
|
|
1205
|
+
activeToolTimeouts.set(key, { toolName, timer });
|
|
1206
|
+
const keys = activeToolTimeoutKeysByName.get(toolName) ?? [];
|
|
1207
|
+
keys.push(key);
|
|
1208
|
+
activeToolTimeoutKeysByName.set(toolName, keys);
|
|
1209
|
+
};
|
|
1210
|
+
/** The child run ended (or was forced to end); fold in the captures and finish. */
|
|
1211
|
+
const settle = (promptError, forced = false) => {
|
|
1212
|
+
if (lifecycleFinished || sessionSettled)
|
|
1213
|
+
return;
|
|
1214
|
+
sessionSettled = true;
|
|
1215
|
+
clearFinalDrainTimers();
|
|
1216
|
+
const diagnostic = capture.toolDiagnostic();
|
|
1217
|
+
const toolDiagnosticError = diagnostic ? formatChildToolDiagnostic(diagnostic, { host: "parent" }) : undefined;
|
|
1218
|
+
toolAvailabilityError = toolDiagnosticError;
|
|
1219
|
+
result.runtimeAcknowledgedExtensions = capture.runtimeAcknowledgedExtensions();
|
|
1220
|
+
if (session?.machineEvidence)
|
|
1221
|
+
result.nativeMachine = { provider: "herdr", machineId: session.machineEvidence.machineId, ...(session.machineEvidence.initial ? { initialGit: session.machineEvidence.initial } : {}), ...(session.machineEvidence.final ? { finalGit: session.machineEvidence.final } : {}) };
|
|
1222
|
+
let closeError = result.error ?? toolDiagnosticError ?? assistantError;
|
|
1223
|
+
const promptErrorMessage = promptError === undefined ? undefined : promptError instanceof Error ? promptError.message : String(promptError);
|
|
1224
|
+
if (!closeError && promptErrorMessage !== undefined) {
|
|
1225
|
+
closeError = promptErrorMessage;
|
|
1226
|
+
}
|
|
1227
|
+
// A foreground child never loads the parent's ambient extensions, so a
|
|
1228
|
+
// provider one registers resolves as "not found" before the child starts.
|
|
1229
|
+
// Annotate only a creation/prompt failure that produced no turn; keep the
|
|
1230
|
+
// core error and add the host rule and both remedies after it.
|
|
1231
|
+
if (promptErrorMessage !== undefined
|
|
1232
|
+
&& closeError === promptErrorMessage
|
|
1233
|
+
&& isChildModelResolutionFailure(promptErrorMessage)
|
|
1234
|
+
&& (result.messages?.length ?? 0) === 0
|
|
1235
|
+
&& result.usage.turns === 0
|
|
1236
|
+
&& !launch.session.ambientExtensions) {
|
|
1237
|
+
closeError = `${promptErrorMessage}\n\n${formatChildModelResolutionDiagnostic({ agent: agent.name, model: launch.session.model, host: "parent", capabilityCeiling: launch.toolPlan.capabilityCeiling })}`;
|
|
1238
|
+
}
|
|
1239
|
+
const forcedDrainAfterFinalSuccess = (forced || forcedTermination) && (cleanTerminalAssistantStopReceived || agentSettledReceived) && !closeError;
|
|
1240
|
+
const forcedDrainAfterEmptyTerminal = forcedDrainAfterFinalSuccess && hasEmptyTerminalAssistantResponse(result.messages ?? []);
|
|
1241
|
+
if (!closeError && (abortedBySignal || session?.shutDown) && !result.interrupted && !result.timedOut) {
|
|
1242
|
+
closeError = session?.shutDown ? "Subagent stopped because the parent session shut down." : STOPPED_BEFORE_COMPLETION_ERROR;
|
|
1243
|
+
}
|
|
1244
|
+
if (!closeError && forced && !forcedDrainAfterFinalSuccess) {
|
|
1245
|
+
closeError = "Subagent session did not settle after it was aborted.";
|
|
1246
|
+
}
|
|
1247
|
+
const finalCode = forcedDrainAfterFinalSuccess && !forcedDrainAfterEmptyTerminal ? 0 : closeError || promptError !== undefined ? 1 : 0;
|
|
1248
|
+
if (!result.error && closeError)
|
|
1249
|
+
result.error = closeError;
|
|
1250
|
+
if (session && messageBaseline !== undefined) {
|
|
1251
|
+
result.usage = reconcileAttemptUsage(result.usage, session.messages, messageBaseline);
|
|
1252
|
+
progress.tokens = result.usage.input + result.usage.output;
|
|
1253
|
+
progress.inputTokens = result.usage.input;
|
|
1254
|
+
progress.outputTokens = result.usage.output;
|
|
1255
|
+
progress.turnCount = result.usage.turns;
|
|
1256
|
+
}
|
|
1257
|
+
finish(finalCode);
|
|
1258
|
+
};
|
|
1259
|
+
if (options.signal) {
|
|
1260
|
+
const kill = () => {
|
|
1261
|
+
if (sessionSettled || lifecycleFinished)
|
|
1262
|
+
return;
|
|
1263
|
+
abortedBySignal = true;
|
|
1264
|
+
abortChild();
|
|
1265
|
+
const hardTimer = setTimeout(() => {
|
|
1266
|
+
if (sessionSettled || lifecycleFinished)
|
|
1267
|
+
return;
|
|
1268
|
+
settle(undefined, true);
|
|
1269
|
+
}, 3000);
|
|
1270
|
+
hardTimer.unref?.();
|
|
1271
|
+
};
|
|
1272
|
+
if (options.signal.aborted)
|
|
1273
|
+
kill();
|
|
1274
|
+
else {
|
|
1275
|
+
options.signal.addEventListener("abort", kill, { once: true });
|
|
1276
|
+
removeAbortListener = () => options.signal?.removeEventListener("abort", kill);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
if (options.interruptSignal) {
|
|
1280
|
+
const interrupt = () => {
|
|
1281
|
+
if (sessionSettled || lifecycleFinished)
|
|
1282
|
+
return;
|
|
1283
|
+
if (result.timedOut)
|
|
1284
|
+
return;
|
|
1285
|
+
interruptedByControl = true;
|
|
1286
|
+
clearTimeoutTimers();
|
|
1287
|
+
clearAllToolTimeouts();
|
|
1288
|
+
progress.status = "running";
|
|
1289
|
+
progress.durationMs = Date.now() - startTime;
|
|
1290
|
+
result.interrupted = true;
|
|
1291
|
+
result.finalOutput = "Interrupted. Waiting for explicit next action.";
|
|
1292
|
+
progress.activityState = undefined;
|
|
1293
|
+
fireUpdate();
|
|
1294
|
+
abortChild();
|
|
1295
|
+
const hardTimer = setTimeout(() => {
|
|
1296
|
+
if (sessionSettled || lifecycleFinished)
|
|
1297
|
+
return;
|
|
1298
|
+
settle(undefined, true);
|
|
1299
|
+
}, 3000);
|
|
1300
|
+
hardTimer.unref?.();
|
|
1301
|
+
};
|
|
1302
|
+
if (options.interruptSignal.aborted)
|
|
1303
|
+
interrupt();
|
|
1304
|
+
else {
|
|
1305
|
+
options.interruptSignal.addEventListener("abort", interrupt, { once: true });
|
|
1306
|
+
removeInterruptListener = () => options.interruptSignal?.removeEventListener("abort", interrupt);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
// Publish only after every callback and cleanup guard captured by detach or
|
|
1310
|
+
// later lifecycle events has initialized. Consumers may invoke synchronously.
|
|
1311
|
+
try {
|
|
1312
|
+
options.onDetachReady?.((reason = "user request") => detachForeground(reason));
|
|
1313
|
+
}
|
|
1314
|
+
catch (error) {
|
|
1315
|
+
// A consumer callback is advisory. Keep the child attached and observable
|
|
1316
|
+
// rather than rejecting this attempt and orphaning its live session.
|
|
1317
|
+
appendRecentOutput(progress, [`Foreground detach callback failed: ${error instanceof Error ? error.message : String(error)}`]);
|
|
1318
|
+
}
|
|
1319
|
+
void (async () => {
|
|
1320
|
+
try {
|
|
1321
|
+
const input = createReportedChildSessionInput(launch, shared.transcriptWriter);
|
|
1322
|
+
const created = await childSessions.create(input);
|
|
1323
|
+
if (lifecycleFinished) {
|
|
1324
|
+
void created.dispose();
|
|
1325
|
+
return;
|
|
1326
|
+
}
|
|
1327
|
+
session = created;
|
|
1328
|
+
const steer = created.steer.bind(created);
|
|
1329
|
+
const followUp = created.followUp.bind(created);
|
|
1330
|
+
created.steer = async (text) => {
|
|
1331
|
+
if (cleanTerminalAssistantStopReceived || agentSettledReceived)
|
|
1332
|
+
queuedDrainHold = true;
|
|
1333
|
+
return steer(text);
|
|
1334
|
+
};
|
|
1335
|
+
created.followUp = async (text) => {
|
|
1336
|
+
if (cleanTerminalAssistantStopReceived || agentSettledReceived)
|
|
1337
|
+
queuedDrainHold = true;
|
|
1338
|
+
return followUp(text);
|
|
1339
|
+
};
|
|
1340
|
+
created.detached = detached;
|
|
1341
|
+
unsubscribe = created.subscribe((event) => processEvent(event));
|
|
1342
|
+
if (abortedBySignal || interruptedByControl || result.timedOut) {
|
|
1343
|
+
abortChild();
|
|
1344
|
+
}
|
|
1345
|
+
options.onChildSession?.({ steer: (text) => created.steer(text), followUp: (text) => created.followUp(text) });
|
|
1346
|
+
messageBaseline = created.messages.length;
|
|
1347
|
+
await created.prompt(`Task: ${task}`);
|
|
1348
|
+
settle(undefined);
|
|
1349
|
+
}
|
|
1350
|
+
catch (error) {
|
|
1351
|
+
settle(error ?? new Error("Child session failed."));
|
|
1352
|
+
}
|
|
1353
|
+
})();
|
|
1354
|
+
});
|
|
1355
|
+
result.exitCode = exitCode;
|
|
1356
|
+
if (afterCompactionSettlement) {
|
|
1357
|
+
result[AFTER_COMPACTION_SETTLEMENT] = true;
|
|
1358
|
+
}
|
|
1359
|
+
if (interruptedByControl) {
|
|
1360
|
+
result.exitCode = 0;
|
|
1361
|
+
result.interrupted = true;
|
|
1362
|
+
result.error = undefined;
|
|
1363
|
+
result.finalOutput = result.finalOutput || "Interrupted. Waiting for explicit next action.";
|
|
1364
|
+
result.controlEvents = allControlEvents.length ? allControlEvents : undefined;
|
|
1365
|
+
progress.activityState = undefined;
|
|
1366
|
+
progress.durationMs = Date.now() - startTime;
|
|
1367
|
+
result.progressSummary = {
|
|
1368
|
+
toolCount: progress.toolCount,
|
|
1369
|
+
tokens: progress.tokens,
|
|
1370
|
+
durationMs: progress.durationMs,
|
|
1371
|
+
};
|
|
1372
|
+
return result;
|
|
1373
|
+
}
|
|
1374
|
+
if (progress.currentTool
|
|
1375
|
+
&& isOrdinaryToolForMidToolExit(progress.currentTool)
|
|
1376
|
+
&& !abortedBySignal
|
|
1377
|
+
&& !result.timedOut
|
|
1378
|
+
&& !result.stopped
|
|
1379
|
+
&& !toolAvailabilityError) {
|
|
1380
|
+
result.exitCode = 1;
|
|
1381
|
+
result.error = formatMidToolExitError({ toolName: progress.currentTool });
|
|
1382
|
+
}
|
|
1383
|
+
if (result.error && result.exitCode === 0) {
|
|
1384
|
+
result.exitCode = 1;
|
|
1385
|
+
}
|
|
1386
|
+
let validatedStructuredOutput = false;
|
|
1387
|
+
if (options.structuredOutput && result.exitCode === 0 && !result.error) {
|
|
1388
|
+
result.structuredOutputSchemaPath = options.structuredOutput.schemaPath;
|
|
1389
|
+
result.structuredOutputPath = options.structuredOutput.outputPath;
|
|
1390
|
+
const structured = capture.structuredOutput();
|
|
1391
|
+
if (!structuredOutputToolInvoked || !structured.called) {
|
|
1392
|
+
result.exitCode = 1;
|
|
1393
|
+
result.error = MISSING_STRUCTURED_OUTPUT_CALL_ERROR;
|
|
1394
|
+
result.structuredOutputFailed = true;
|
|
1395
|
+
}
|
|
1396
|
+
else {
|
|
1397
|
+
result.structuredOutput = structured.value;
|
|
1398
|
+
const acceptanceMode = options.structuredOutput.acceptanceReportPath
|
|
1399
|
+
? options.structuredOutput.acceptanceReportRequired ? "required" : "optional"
|
|
1400
|
+
: undefined;
|
|
1401
|
+
const acceptanceReportError = acceptanceMode === "required" && !structured.acceptanceReportProvided
|
|
1402
|
+
? MISSING_STRUCTURED_ACCEPTANCE_REPORT_ERROR
|
|
1403
|
+
: undefined;
|
|
1404
|
+
result.structuredAcceptanceReport = acceptanceMode ? structured.acceptanceReport : undefined;
|
|
1405
|
+
result.structuredAcceptanceReportError = acceptanceReportError;
|
|
1406
|
+
writeStructuredOutputArtifacts(options.structuredOutput, structured.value, acceptanceMode ? structured.acceptanceReport : undefined);
|
|
1407
|
+
validatedStructuredOutput = true;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
if (result.exitCode === 0 && !result.error) {
|
|
1411
|
+
const messages = result.messages ?? [];
|
|
1412
|
+
const finalText = getFinalOutput(messages);
|
|
1413
|
+
const errorMessages = validatedStructuredOutput
|
|
1414
|
+
? messages.slice(structuredOutputMessageStartIndex ?? messages.length)
|
|
1415
|
+
: messages;
|
|
1416
|
+
const errInfo = detectSubagentError(errorMessages);
|
|
1417
|
+
const missingOutput = !finalText?.trim() && !validatedStructuredOutput;
|
|
1418
|
+
const terminalEmptyAfterUsefulWork = !validatedStructuredOutput
|
|
1419
|
+
&& hasEmptyTerminalAssistantResponse(messages)
|
|
1420
|
+
&& (progress.toolCount > 0 || Boolean(finalText?.trim()));
|
|
1421
|
+
if ((missingOutput || terminalEmptyAfterUsefulWork) && (!errInfo.hasError || hasEmptyTerminalAssistantResponse(messages))) {
|
|
1422
|
+
result.exitCode = 1;
|
|
1423
|
+
result.error = formatEmptyTerminalAssistantResponseError(messages);
|
|
1424
|
+
}
|
|
1425
|
+
else if (errInfo.hasError) {
|
|
1426
|
+
result.exitCode = errInfo.exitCode ?? 1;
|
|
1427
|
+
result.error = errInfo.details
|
|
1428
|
+
? `${errInfo.errorType} failed (exit ${errInfo.exitCode}): ${errInfo.details}`
|
|
1429
|
+
: `${errInfo.errorType} failed with exit code ${errInfo.exitCode}`;
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
progress.status = result.exitCode === 0 ? "completed" : "failed";
|
|
1433
|
+
progress.durationMs = Date.now() - startTime;
|
|
1434
|
+
if (result.error) {
|
|
1435
|
+
progress.error = result.error;
|
|
1436
|
+
if (progress.currentTool) {
|
|
1437
|
+
progress.failedTool = progress.currentTool;
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
result.progressSummary = {
|
|
1441
|
+
...(childSessionName ? { sessionName: childSessionName } : {}),
|
|
1442
|
+
toolCount: progress.toolCount,
|
|
1443
|
+
tokens: progress.tokens,
|
|
1444
|
+
durationMs: progress.durationMs,
|
|
1445
|
+
};
|
|
1446
|
+
const remoteGitChanged = result.nativeMachine?.initialGit && result.nativeMachine.finalGit ? result.nativeMachine.initialGit.head !== result.nativeMachine.finalGit.head || result.nativeMachine.initialGit.dirty !== result.nativeMachine.finalGit.dirty : undefined;
|
|
1447
|
+
const mutationEvidence = result.nativeMachine ? { source: "tracked-files", trackedOnly: true, changedFiles: [], attemptedMutation: remoteGitChanged === true, ...(remoteGitChanged === undefined ? { unavailable: "Remote Git before/after evidence was incomplete." } : {}) } : collectTrackedMutationEvidence(mutationSnapshot, options.cwd ?? runtimeCwd);
|
|
1448
|
+
const acceptanceOutput = getFinalOutput(result.messages ?? []);
|
|
1449
|
+
let fullOutput = stripAcceptanceReport(acceptanceOutput);
|
|
1450
|
+
if (!fullOutput.trim() && result.structuredOutput !== undefined)
|
|
1451
|
+
fullOutput = JSON.stringify(result.structuredOutput, null, 2);
|
|
1452
|
+
result.outputState = fullOutput.trim() || result.structuredOutput !== undefined ? "present" : "absent";
|
|
1453
|
+
if (result.timedOut) {
|
|
1454
|
+
const timeoutMessage = formatTimeoutMessage(options.timeoutMs ?? 0);
|
|
1455
|
+
let requiredOutputMissing;
|
|
1456
|
+
if (options.outputMode === "file-only" && options.outputPath) {
|
|
1457
|
+
const outputChanged = hasSingleOutputChangedSinceSnapshot(options.outputPath, shared.outputSnapshot);
|
|
1458
|
+
requiredOutputMissing = outputChanged === undefined ? undefined : !outputChanged;
|
|
1459
|
+
}
|
|
1460
|
+
else if (options.structuredOutput) {
|
|
1461
|
+
requiredOutputMissing = !capture.structuredOutput().called;
|
|
1462
|
+
}
|
|
1463
|
+
result.timeoutRecovery = buildTimeoutRecoverySummary({
|
|
1464
|
+
termination: "timed-out",
|
|
1465
|
+
evidence: mutationEvidence,
|
|
1466
|
+
requiredOutputMissing,
|
|
1467
|
+
currentTool: progress.currentTool,
|
|
1468
|
+
currentToolArgs: progress.currentToolArgs,
|
|
1469
|
+
currentPath: progress.currentPath,
|
|
1470
|
+
sessionFile: options.sessionFile,
|
|
1471
|
+
transcriptPath: shared.transcriptWriter ? shared.artifactPaths?.transcriptPath : undefined,
|
|
1472
|
+
artifactPaths: shared.artifactPaths,
|
|
1473
|
+
});
|
|
1474
|
+
fullOutput = fullOutput.trim()
|
|
1475
|
+
? `${timeoutMessage}\n\n${result.timeoutRecovery.message}\n\nPartial output before timeout:\n${fullOutput}`
|
|
1476
|
+
: `${timeoutMessage}\n\n${result.timeoutRecovery.message}`;
|
|
1477
|
+
}
|
|
1478
|
+
const completionGuardEnabled = isAgentContract(options.agentContract) ? agent.completionGuard === true : agent.completionGuard !== false;
|
|
1479
|
+
const completionGuard = ((result.exitCode === 0 && !result.error) || toolAvailabilityError) && completionGuardEnabled
|
|
1480
|
+
? evaluateCompletionMutationGuard({
|
|
1481
|
+
agent: agent.name,
|
|
1482
|
+
task: shared.originalTask ?? task,
|
|
1483
|
+
messages: result.messages ?? [],
|
|
1484
|
+
tools: contractTools,
|
|
1485
|
+
mcpDirectTools: toolPlan.effectiveMcpTools,
|
|
1486
|
+
mutationTools: agent.mutationTools,
|
|
1487
|
+
toolAvailabilityError,
|
|
1488
|
+
mutationEvidence,
|
|
1489
|
+
})
|
|
1490
|
+
: undefined;
|
|
1491
|
+
const mutationAttemptObserved = observedMutationAttempt || mutationEvidence.attemptedMutation;
|
|
1492
|
+
let completionGuardTriggered = completionGuard?.triggered === true && !mutationAttemptObserved;
|
|
1493
|
+
// The classifier is deliberately narrow, so a read-only review task can
|
|
1494
|
+
// still be misread as implementation. Arbitrate BEFORE any failure side
|
|
1495
|
+
// effect is published (effects, exit code, progress, notifications,
|
|
1496
|
+
// acceptance, output persistence): only a confident read-only verdict
|
|
1497
|
+
// rescues, and the task text alone is evidence — never the child's own
|
|
1498
|
+
// final message.
|
|
1499
|
+
let arbiterRescued = false;
|
|
1500
|
+
if (completionGuardTriggered) {
|
|
1501
|
+
const arbitration = await arbitrateCompletionGuardRescue({
|
|
1502
|
+
guardTriggered: true,
|
|
1503
|
+
task: shared.originalTask ?? task,
|
|
1504
|
+
arbiter: options.llmIntentArbiter,
|
|
1505
|
+
});
|
|
1506
|
+
completionGuardTriggered = arbitration.triggered;
|
|
1507
|
+
arbiterRescued = arbitration.rescued;
|
|
1508
|
+
}
|
|
1509
|
+
const completionEvidence = planCompletionEvidence({
|
|
1510
|
+
guard: completionGuard,
|
|
1511
|
+
guardTriggered: completionGuardTriggered,
|
|
1512
|
+
completionGuardEnabled,
|
|
1513
|
+
mutationCapable: hasMutationToolCapability(contractTools, toolPlan.effectiveMcpTools),
|
|
1514
|
+
implementationMutationExpected: expectsImplementationMutation(agent.name, shared.originalTask ?? task),
|
|
1515
|
+
mutationAttemptObserved,
|
|
1516
|
+
mutationEvidence,
|
|
1517
|
+
arbiterRescued,
|
|
1518
|
+
agentContractEnabled: isAgentContract(options.agentContract),
|
|
1519
|
+
});
|
|
1520
|
+
if (completionEvidence.fileMutation) {
|
|
1521
|
+
result.effects = {
|
|
1522
|
+
...(result.effects ?? {}),
|
|
1523
|
+
fileMutation: completionEvidence.fileMutation,
|
|
1524
|
+
};
|
|
1525
|
+
}
|
|
1526
|
+
if (completionEvidence.legacyFailureError) {
|
|
1527
|
+
result.exitCode = 1;
|
|
1528
|
+
result.error = completionEvidence.legacyFailureError;
|
|
1529
|
+
progress.status = "failed";
|
|
1530
|
+
progress.error = result.error;
|
|
1531
|
+
emitControlEvent(buildControlEvent({
|
|
1532
|
+
from: progress.activityState,
|
|
1533
|
+
to: "needs_attention",
|
|
1534
|
+
runId: options.runId ?? agent.name,
|
|
1535
|
+
agent: agent.name,
|
|
1536
|
+
index: options.index,
|
|
1537
|
+
ts: Date.now(),
|
|
1538
|
+
message: `${agent.name} completed without making edits for an implementation task`,
|
|
1539
|
+
reason: "completion_guard",
|
|
1540
|
+
}));
|
|
1541
|
+
}
|
|
1542
|
+
if (options.outputPath && result.exitCode === 0) {
|
|
1543
|
+
const resolvedOutput = resolveSingleOutput(options.outputPath, fullOutput, shared.outputSnapshot, options.outputClaimPath);
|
|
1544
|
+
fullOutput = stripAcceptanceReport(resolvedOutput.fullOutput);
|
|
1545
|
+
result.savedOutputPath = resolvedOutput.savedPath;
|
|
1546
|
+
result.outputSaveError = resolvedOutput.saveError;
|
|
1547
|
+
if (resolvedOutput.fatalError) {
|
|
1548
|
+
result.exitCode = 1;
|
|
1549
|
+
result.error = result.error ? `${result.error}\n${resolvedOutput.saveError}` : resolvedOutput.saveError;
|
|
1550
|
+
}
|
|
1551
|
+
if (resolvedOutput.savedPath) {
|
|
1552
|
+
result.outputReference = formatSavedOutputReference(resolvedOutput.savedPath, fullOutput);
|
|
1553
|
+
if (result.outputState === "absent")
|
|
1554
|
+
result.outputState = "unknown";
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
artifactOutputByResult.set(result, fullOutput);
|
|
1558
|
+
acceptanceOutputByResult.set(result, acceptanceOutput);
|
|
1559
|
+
result.outputMode = options.outputMode ?? "inline";
|
|
1560
|
+
result.finalOutput = options.outputMode === "file-only" && result.savedOutputPath && result.outputReference
|
|
1561
|
+
? result.outputReference.message
|
|
1562
|
+
: fullOutput;
|
|
1563
|
+
result.controlEvents = allControlEvents.length ? allControlEvents : undefined;
|
|
1564
|
+
if (options.onUpdate) {
|
|
1565
|
+
const finalText = result.finalOutput || result.error || "(no output)";
|
|
1566
|
+
const progressSnapshot = snapshotProgress(progress);
|
|
1567
|
+
const resultSnapshot = snapshotStreamResult(result, progressSnapshot);
|
|
1568
|
+
options.onUpdate({
|
|
1569
|
+
content: [{ type: "text", text: finalText }],
|
|
1570
|
+
details: {
|
|
1571
|
+
mode: "single",
|
|
1572
|
+
results: [resultSnapshot],
|
|
1573
|
+
progress: [progressSnapshot],
|
|
1574
|
+
controlEvents: allControlEvents.length ? allControlEvents : undefined,
|
|
1575
|
+
},
|
|
1576
|
+
});
|
|
1577
|
+
}
|
|
1578
|
+
return result;
|
|
1579
|
+
}
|
|
1580
|
+
/** Keep the structured output artifact files other consumers read by path. */
|
|
1581
|
+
function writeStructuredOutputArtifacts(runtime, value, acceptanceReport) {
|
|
1582
|
+
try {
|
|
1583
|
+
mkdirSync(path.dirname(runtime.outputPath), { recursive: true });
|
|
1584
|
+
writeFileSync(runtime.outputPath, JSON.stringify(value), { mode: 0o600 });
|
|
1585
|
+
if (runtime.acceptanceReportPath) {
|
|
1586
|
+
if (acceptanceReport !== undefined)
|
|
1587
|
+
writeFileSync(runtime.acceptanceReportPath, JSON.stringify(acceptanceReport), { mode: 0o600 });
|
|
1588
|
+
else
|
|
1589
|
+
rmSync(runtime.acceptanceReportPath, { force: true });
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
catch {
|
|
1593
|
+
// The captured value is already on the result; the file is observability only.
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
/**
|
|
1597
|
+
* Run a subagent synchronously (blocking until complete)
|
|
1598
|
+
*/
|
|
1599
|
+
async function runSyncCompletionInner(runtimeCwd, agents, agentName, task, options) {
|
|
1600
|
+
const effectiveCwd = options.cwd ?? runtimeCwd;
|
|
1601
|
+
const cwdError = preflightLaunchCwd(options.requestedCwd ?? effectiveCwd, effectiveCwd);
|
|
1602
|
+
if (cwdError) {
|
|
1603
|
+
return redactResultPrompt(withRunContext({
|
|
1604
|
+
index: options.index ?? 0,
|
|
1605
|
+
agent: agentName,
|
|
1606
|
+
task,
|
|
1607
|
+
exitCode: 1,
|
|
1608
|
+
messages: [],
|
|
1609
|
+
usage: emptyUsage(),
|
|
1610
|
+
error: cwdError,
|
|
1611
|
+
}, options.context));
|
|
1612
|
+
}
|
|
1613
|
+
options = {
|
|
1614
|
+
...options,
|
|
1615
|
+
capabilityCeiling: intersectSubagentCapabilityCeilings(options.capabilityCeiling ?? resolveCurrentSubagentCapabilityCeiling(options.parentSessionId), options.childRuntime?.capabilityCeiling),
|
|
1616
|
+
};
|
|
1617
|
+
const childSessionName = deriveChildSessionName({ agent: agentName, task });
|
|
1618
|
+
const agent = agents.find((a) => a.name === agentName);
|
|
1619
|
+
if (!agent) {
|
|
1620
|
+
const diagnosticContext = options.unknownAgentDiagnosticContext
|
|
1621
|
+
?? unknownAgentDiagnosticContext(discoverAgents(path.resolve(options.cwd ?? runtimeCwd), "both"));
|
|
1622
|
+
return redactResultPrompt(withRunContext({
|
|
1623
|
+
index: options.index ?? 0,
|
|
1624
|
+
agent: agentName,
|
|
1625
|
+
task,
|
|
1626
|
+
exitCode: 1,
|
|
1627
|
+
messages: [],
|
|
1628
|
+
usage: emptyUsage(),
|
|
1629
|
+
error: formatUnknownAgentError(agentName, diagnosticContext),
|
|
1630
|
+
}, options.context));
|
|
1631
|
+
}
|
|
1632
|
+
options = {
|
|
1633
|
+
...options,
|
|
1634
|
+
thinkingCeiling: intersectThinkingCeilings(options.thinkingCeiling, agent.maxThinking, options.childRuntime?.thinkingCeiling),
|
|
1635
|
+
};
|
|
1636
|
+
try {
|
|
1637
|
+
assertAgentAllowedByCapabilityCeiling(agent.name, options.capabilityCeiling);
|
|
1638
|
+
}
|
|
1639
|
+
catch (error) {
|
|
1640
|
+
return redactResultPrompt(withRunContext({
|
|
1641
|
+
index: options.index ?? 0,
|
|
1642
|
+
agent: agent.name,
|
|
1643
|
+
task,
|
|
1644
|
+
exitCode: 1,
|
|
1645
|
+
messages: [],
|
|
1646
|
+
usage: emptyUsage(),
|
|
1647
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1648
|
+
...(options.capabilityCeiling ? { capabilityCeiling: options.capabilityCeiling } : {}),
|
|
1649
|
+
}, options.context));
|
|
1650
|
+
}
|
|
1651
|
+
const acceptanceErrors = validateAcceptanceInput(options.acceptance);
|
|
1652
|
+
if (acceptanceErrors.length > 0) {
|
|
1653
|
+
return redactResultPrompt(withRunContext({
|
|
1654
|
+
index: options.index ?? 0,
|
|
1655
|
+
agent: agentName,
|
|
1656
|
+
task,
|
|
1657
|
+
exitCode: 1,
|
|
1658
|
+
messages: [],
|
|
1659
|
+
usage: emptyUsage(),
|
|
1660
|
+
error: acceptanceErrors.join(" "),
|
|
1661
|
+
}, options.context));
|
|
1662
|
+
}
|
|
1663
|
+
const toolTimeout = resolveToolTimeoutMs({
|
|
1664
|
+
callValue: options.toolTimeoutMs,
|
|
1665
|
+
agentValue: agent.defaultToolTimeoutMs,
|
|
1666
|
+
configValue: options.configToolTimeoutMs,
|
|
1667
|
+
envValue: toolTimeoutFromEnv(),
|
|
1668
|
+
});
|
|
1669
|
+
if (toolTimeout.error) {
|
|
1670
|
+
return redactResultPrompt(withRunContext({
|
|
1671
|
+
index: options.index ?? 0,
|
|
1672
|
+
agent: agentName,
|
|
1673
|
+
task,
|
|
1674
|
+
exitCode: 1,
|
|
1675
|
+
messages: [],
|
|
1676
|
+
usage: emptyUsage(),
|
|
1677
|
+
error: toolTimeout.error,
|
|
1678
|
+
}, options.context));
|
|
1679
|
+
}
|
|
1680
|
+
options = { ...options, toolTimeoutMs: toolTimeout.toolTimeoutMs };
|
|
1681
|
+
const outputModeValidationError = validateFileOnlyOutputMode(options.outputMode, options.outputPath, `Single run (${agentName})`);
|
|
1682
|
+
if (outputModeValidationError) {
|
|
1683
|
+
return redactResultPrompt(withRunContext({
|
|
1684
|
+
index: options.index ?? 0,
|
|
1685
|
+
agent: agentName,
|
|
1686
|
+
task,
|
|
1687
|
+
exitCode: 1,
|
|
1688
|
+
messages: [],
|
|
1689
|
+
usage: emptyUsage(),
|
|
1690
|
+
outputMode: options.outputMode,
|
|
1691
|
+
error: outputModeValidationError,
|
|
1692
|
+
}, options.context));
|
|
1693
|
+
}
|
|
1694
|
+
const shareEnabled = options.share === true;
|
|
1695
|
+
const effectiveAcceptance = resolveEffectiveAcceptance({
|
|
1696
|
+
explicit: options.acceptance,
|
|
1697
|
+
agentName,
|
|
1698
|
+
acceptanceRole: agent.acceptanceRole,
|
|
1699
|
+
task,
|
|
1700
|
+
mode: options.acceptanceContext?.mode ?? "single",
|
|
1701
|
+
async: options.acceptanceContext?.async,
|
|
1702
|
+
dynamic: options.acceptanceContext?.dynamic,
|
|
1703
|
+
dynamicGroup: options.acceptanceContext?.dynamicGroup,
|
|
1704
|
+
agentContract: options.agentContract,
|
|
1705
|
+
});
|
|
1706
|
+
const acceptancePrompt = formatAcceptancePrompt(effectiveAcceptance, { reportOptional: isAgentContract(options.agentContract), structuredOutput: Boolean(options.structuredOutput?.acceptanceReportPath) });
|
|
1707
|
+
const taskWithAcceptance = acceptancePrompt ? `${task}\n${acceptancePrompt}` : task;
|
|
1708
|
+
options.onEffectivePrompt?.(taskWithAcceptance);
|
|
1709
|
+
const sessionEnabled = Boolean(options.sessionFile || options.sessionDir) || shareEnabled;
|
|
1710
|
+
if (options.context === "fork" && options.sessionFile && existsSync(options.sessionFile)) {
|
|
1711
|
+
alignForkedSessionCwd(options.sessionFile, options.cwd ?? runtimeCwd);
|
|
1712
|
+
}
|
|
1713
|
+
const skillNames = options.skills ?? agent.skills ?? [];
|
|
1714
|
+
const skillCwd = options.cwd ?? runtimeCwd;
|
|
1715
|
+
const { resolved: resolvedSkills, missing: missingSkills } = resolveSkillsWithFallback(skillNames, skillCwd, runtimeCwd, agent.skillPath, agent.filePath ? path.dirname(agent.filePath) : skillCwd);
|
|
1716
|
+
if (skillNames.some((skill) => skill.trim() === "pi-subagents") && missingSkills.includes("pi-subagents")) {
|
|
1717
|
+
return redactResultPrompt(withRunContext({
|
|
1718
|
+
index: options.index ?? 0,
|
|
1719
|
+
agent: agentName,
|
|
1720
|
+
task,
|
|
1721
|
+
exitCode: 1,
|
|
1722
|
+
messages: [],
|
|
1723
|
+
usage: emptyUsage(),
|
|
1724
|
+
error: "Skills not found: pi-subagents",
|
|
1725
|
+
}, options.context));
|
|
1726
|
+
}
|
|
1727
|
+
const systemPrompt = buildEffectiveSystemPrompt({ agent, resolvedSkills, cwd: skillCwd, ...(options.outputPath ? { outputPath: options.outputPath } : {}) });
|
|
1728
|
+
const { model: selectedModel, requestedModel } = resolveModelSelection(options.modelOverride ?? agent.model, options.availableModels, agent.modelProvider ?? options.preferredModelProvider, {
|
|
1729
|
+
scope: options.modelScope,
|
|
1730
|
+
primaryModelFromParent: options.modelOverrideFromParent,
|
|
1731
|
+
origin: options.modelOrigin ?? (options.modelOverrideFromParent ? "inherited" : "configured"),
|
|
1732
|
+
});
|
|
1733
|
+
try {
|
|
1734
|
+
const model = applyThinkingSuffix(selectedModel, options.thinkingOverride ?? agent.thinking, options.thinkingOverride !== undefined);
|
|
1735
|
+
assertThinkingWithinCeiling({ model, configThinking: options.thinkingOverride ?? agent.thinking, ceiling: options.thinkingCeiling, agent: agent.name, runId: options.runId });
|
|
1736
|
+
}
|
|
1737
|
+
catch (error) {
|
|
1738
|
+
return redactResultPrompt(withRunContext({
|
|
1739
|
+
index: options.index ?? 0,
|
|
1740
|
+
agent: agent.name,
|
|
1741
|
+
task,
|
|
1742
|
+
exitCode: 1,
|
|
1743
|
+
messages: [],
|
|
1744
|
+
usage: emptyUsage(),
|
|
1745
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1746
|
+
}, options.context));
|
|
1747
|
+
}
|
|
1748
|
+
const aggregateUsage = emptyUsage();
|
|
1749
|
+
const attemptNotes = [];
|
|
1750
|
+
const launchWarnings = { emitted: false };
|
|
1751
|
+
let totalToolCount = 0;
|
|
1752
|
+
let totalDurationMs = 0;
|
|
1753
|
+
let artifactPathsResult;
|
|
1754
|
+
let jsonlPath;
|
|
1755
|
+
let transcriptWriter;
|
|
1756
|
+
if (options.artifactsDir && options.artifactConfig?.enabled !== false) {
|
|
1757
|
+
artifactPathsResult = getArtifactPaths(options.artifactsDir, options.runId, agentName, options.index);
|
|
1758
|
+
ensureArtifactsDir(options.artifactsDir);
|
|
1759
|
+
if (options.artifactConfig?.includeInput !== false) {
|
|
1760
|
+
writeArtifact(artifactPathsResult.inputPath, `# Task for ${agentName}\n\n${PROMPT_REDACTED}; live Prompt Audit only.\n`);
|
|
1761
|
+
}
|
|
1762
|
+
if (options.artifactConfig?.includeJsonl !== false) {
|
|
1763
|
+
jsonlPath = artifactPathsResult.jsonlPath;
|
|
1764
|
+
}
|
|
1765
|
+
if (options.artifactConfig?.includeTranscript !== false) {
|
|
1766
|
+
transcriptWriter = createChildTranscriptWriter({
|
|
1767
|
+
transcriptPath: artifactPathsResult.transcriptPath,
|
|
1768
|
+
source: "foreground",
|
|
1769
|
+
runId: options.runId,
|
|
1770
|
+
agent: agentName,
|
|
1771
|
+
childIndex: options.index,
|
|
1772
|
+
cwd: options.cwd ?? runtimeCwd,
|
|
1773
|
+
});
|
|
1774
|
+
transcriptWriter.writeInitialUserMessage(`${PROMPT_REDACTED}; live Prompt Audit only.`);
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
const orcaProgressTab = createOrcaProgressTab({
|
|
1778
|
+
cwd: options.cwd ?? runtimeCwd,
|
|
1779
|
+
runId: options.runId,
|
|
1780
|
+
agent: agentName,
|
|
1781
|
+
index: options.index ?? 0,
|
|
1782
|
+
});
|
|
1783
|
+
if (orcaProgressTab)
|
|
1784
|
+
options.onOrcaProgressTabCreated?.(orcaProgressTab);
|
|
1785
|
+
const persistResultMetadata = (target) => {
|
|
1786
|
+
persistSingleResultMetadata({
|
|
1787
|
+
metadataPath: artifactPathsResult?.metadataPath,
|
|
1788
|
+
enabled: options.artifactConfig?.enabled !== false && options.artifactConfig?.includeMetadata !== false,
|
|
1789
|
+
runId: options.runId,
|
|
1790
|
+
agent: agentName,
|
|
1791
|
+
task,
|
|
1792
|
+
result: target,
|
|
1793
|
+
});
|
|
1794
|
+
};
|
|
1795
|
+
let detachedReason;
|
|
1796
|
+
const logicalDeadline = options.deadlineAt ?? (options.timeoutMs === undefined ? undefined : Date.now() + options.timeoutMs);
|
|
1797
|
+
const attemptOptions = {
|
|
1798
|
+
...options,
|
|
1799
|
+
deadlineAt: logicalDeadline,
|
|
1800
|
+
onDetachReceipt: (receipt) => {
|
|
1801
|
+
receipt.acceptance = buildPendingAcceptanceLedger(effectiveAcceptance);
|
|
1802
|
+
try {
|
|
1803
|
+
persistResultMetadata(receipt);
|
|
1804
|
+
}
|
|
1805
|
+
catch (error) {
|
|
1806
|
+
receipt.metadataSaveError = error instanceof Error ? error.message : String(error);
|
|
1807
|
+
}
|
|
1808
|
+
const accepted = options.onDetachReceipt?.(receipt) === true;
|
|
1809
|
+
if (accepted) {
|
|
1810
|
+
detachedReason = receipt.detachedReason;
|
|
1811
|
+
}
|
|
1812
|
+
return accepted;
|
|
1813
|
+
},
|
|
1814
|
+
};
|
|
1815
|
+
const candidate = selectedModel;
|
|
1816
|
+
const verifyModel = Boolean(candidate) && !options.modelOverrideFromParent;
|
|
1817
|
+
let lastResult;
|
|
1818
|
+
let recoveryPrompt = task;
|
|
1819
|
+
let stagedIndexBaseline;
|
|
1820
|
+
if (effectiveAcceptance.preserveStagedIndex) {
|
|
1821
|
+
try {
|
|
1822
|
+
stagedIndexBaseline = captureStagedIndexBaseline(options.cwd ?? runtimeCwd);
|
|
1823
|
+
}
|
|
1824
|
+
catch (error) {
|
|
1825
|
+
return redactResultPrompt(withRunContext({
|
|
1826
|
+
index: options.index ?? 0,
|
|
1827
|
+
agent: agentName,
|
|
1828
|
+
task,
|
|
1829
|
+
exitCode: 1,
|
|
1830
|
+
messages: [],
|
|
1831
|
+
usage: emptyUsage(),
|
|
1832
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1833
|
+
}, options.context));
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
for (let attemptIndex = 0; attemptIndex < 2; attemptIndex++) {
|
|
1837
|
+
const outputSnapshot = captureSingleOutputSnapshot(options.outputPath);
|
|
1838
|
+
const attemptResult = await runSingleAttempt(runtimeCwd, agent, recoveryPrompt, candidate, attemptOptions, {
|
|
1839
|
+
sessionEnabled,
|
|
1840
|
+
systemPrompt,
|
|
1841
|
+
acceptancePrompt,
|
|
1842
|
+
resolvedSkillNames: resolvedSkills.length > 0 ? resolvedSkills.map((skill) => skill.name) : undefined,
|
|
1843
|
+
skillsWarning: missingSkills.length > 0 ? `Skills not found: ${missingSkills.join(", ")}` : undefined,
|
|
1844
|
+
jsonlPath,
|
|
1845
|
+
artifactPaths: artifactPathsResult,
|
|
1846
|
+
transcriptWriter,
|
|
1847
|
+
attemptNotes,
|
|
1848
|
+
outputSnapshot,
|
|
1849
|
+
originalTask: task,
|
|
1850
|
+
orcaProgressTab,
|
|
1851
|
+
launchWarnings,
|
|
1852
|
+
verifyModel,
|
|
1853
|
+
});
|
|
1854
|
+
lastResult = attemptResult;
|
|
1855
|
+
sumUsage(aggregateUsage, attemptResult.usage);
|
|
1856
|
+
totalToolCount += attemptResult.progressSummary?.toolCount ?? 0;
|
|
1857
|
+
totalDurationMs += attemptResult.progressSummary?.durationMs ?? 0;
|
|
1858
|
+
if (attemptResult.exitCode === 0 && !attemptResult.error)
|
|
1859
|
+
break;
|
|
1860
|
+
const recovery = planAbortRecovery({
|
|
1861
|
+
messages: attemptResult.messages ?? [],
|
|
1862
|
+
error: attemptResult.error,
|
|
1863
|
+
processSignal: attemptResult.processSignal,
|
|
1864
|
+
sessionAvailable: Boolean(options.sessionFile && existsSync(options.sessionFile)),
|
|
1865
|
+
alreadyResumed: attemptIndex > 0,
|
|
1866
|
+
stopped: attemptResult.stopped || attemptResult.detached || Boolean(detachedReason) || Boolean(options.workflowChildPermitLaunch) || options.signal?.aborted,
|
|
1867
|
+
interrupted: attemptResult.interrupted || options.interruptSignal?.aborted,
|
|
1868
|
+
timedOut: attemptResult.timedOut,
|
|
1869
|
+
toolBudgetExhausted: attemptResult.toolBudgetBlocked,
|
|
1870
|
+
usageBudgetExhausted: false,
|
|
1871
|
+
structuredOutputFailed: attemptResult.structuredOutputFailed,
|
|
1872
|
+
acceptanceFailed: false,
|
|
1873
|
+
currentTool: attemptResult.progress?.currentTool,
|
|
1874
|
+
afterCompactionSettlement: attemptResult[AFTER_COMPACTION_SETTLEMENT],
|
|
1875
|
+
});
|
|
1876
|
+
if (recovery.action === "resume") {
|
|
1877
|
+
recoveryPrompt = recovery.prompt;
|
|
1878
|
+
attemptNotes.push("[abort-recovery] compaction abort after useful progress; resuming the retained child session once on the same model.");
|
|
1879
|
+
continue;
|
|
1880
|
+
}
|
|
1881
|
+
if (recovery.diagnostic) {
|
|
1882
|
+
attemptResult.error = attemptResult.error ? `${attemptResult.error}\n${recovery.diagnostic}` : recovery.diagnostic;
|
|
1883
|
+
}
|
|
1884
|
+
break;
|
|
1885
|
+
}
|
|
1886
|
+
if (!lastResult)
|
|
1887
|
+
throw new Error("Subagent did not produce a result.");
|
|
1888
|
+
if (isContextOverflow(lastResult.error))
|
|
1889
|
+
lastResult.contextOverflow = true;
|
|
1890
|
+
const result = withRunContext(lastResult ?? {
|
|
1891
|
+
index: options.index ?? 0,
|
|
1892
|
+
agent: agentName,
|
|
1893
|
+
task,
|
|
1894
|
+
exitCode: 1,
|
|
1895
|
+
messages: [],
|
|
1896
|
+
usage: emptyUsage(),
|
|
1897
|
+
error: "Subagent did not produce a result.",
|
|
1898
|
+
}, options.context);
|
|
1899
|
+
result.task = task;
|
|
1900
|
+
result.usage = aggregateUsage;
|
|
1901
|
+
result.requestedModel = requestedModel;
|
|
1902
|
+
result.progressSummary = {
|
|
1903
|
+
...(childSessionName ? { sessionName: childSessionName } : {}),
|
|
1904
|
+
toolCount: totalToolCount,
|
|
1905
|
+
tokens: aggregateUsage.input + aggregateUsage.output,
|
|
1906
|
+
durationMs: totalDurationMs,
|
|
1907
|
+
};
|
|
1908
|
+
if (transcriptWriter)
|
|
1909
|
+
result.transcriptPath = artifactPathsResult?.transcriptPath;
|
|
1910
|
+
if (transcriptWriter?.getError())
|
|
1911
|
+
result.transcriptError = transcriptWriter.getError();
|
|
1912
|
+
try {
|
|
1913
|
+
if (artifactPathsResult && options.artifactConfig?.enabled !== false) {
|
|
1914
|
+
result.artifactPaths = artifactPathsResult;
|
|
1915
|
+
if (options.artifactConfig?.includeOutput !== false) {
|
|
1916
|
+
writeArtifact(artifactPathsResult.outputPath, formatOutputArtifactContent({
|
|
1917
|
+
output: artifactOutputByResult.get(result) ?? result.finalOutput ?? "",
|
|
1918
|
+
error: result.error,
|
|
1919
|
+
transcriptPath: result.transcriptPath,
|
|
1920
|
+
metadataPath: options.artifactConfig?.includeMetadata === false ? undefined : artifactPathsResult.metadataPath,
|
|
1921
|
+
}));
|
|
1922
|
+
}
|
|
1923
|
+
if (options.maxOutput) {
|
|
1924
|
+
const config = { ...DEFAULT_MAX_OUTPUT, ...options.maxOutput };
|
|
1925
|
+
const truncationResult = truncateOutput(result.finalOutput ?? "", config, artifactPathsResult.outputPath);
|
|
1926
|
+
if (truncationResult.truncated)
|
|
1927
|
+
result.truncation = truncationResult;
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
else if (options.maxOutput) {
|
|
1931
|
+
const config = { ...DEFAULT_MAX_OUTPUT, ...options.maxOutput };
|
|
1932
|
+
const truncationResult = truncateOutput(result.finalOutput ?? "", config);
|
|
1933
|
+
if (truncationResult.truncated)
|
|
1934
|
+
result.truncation = truncationResult;
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
catch (error) {
|
|
1938
|
+
const message = `Artifact output post-processing failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
1939
|
+
result.outputSaveError = result.outputSaveError ? `${result.outputSaveError}\n${message}` : message;
|
|
1940
|
+
}
|
|
1941
|
+
if (options.sessionFile && (existsSync(options.sessionFile) || result.messages?.length)) {
|
|
1942
|
+
result.sessionFile = options.sessionFile;
|
|
1943
|
+
}
|
|
1944
|
+
else if (shareEnabled && options.sessionDir) {
|
|
1945
|
+
const sessionFile = findLatestSessionFile(options.sessionDir);
|
|
1946
|
+
if (sessionFile)
|
|
1947
|
+
result.sessionFile = sessionFile;
|
|
1948
|
+
}
|
|
1949
|
+
const childWrittenOutput = options.outputPath
|
|
1950
|
+
? extractChildWrittenOutput(result.messages, options.outputPath, options.cwd ?? runtimeCwd)
|
|
1951
|
+
: undefined;
|
|
1952
|
+
try {
|
|
1953
|
+
if (result.interrupted && detachedReason === "user request") {
|
|
1954
|
+
// Only an accepted user-detach receipt needs a non-rejecting terminal
|
|
1955
|
+
// ledger. Attached and background execution retain their baseline
|
|
1956
|
+
// acceptance behavior.
|
|
1957
|
+
result.acceptance = buildInterruptedAcceptanceLedger(effectiveAcceptance);
|
|
1958
|
+
}
|
|
1959
|
+
else if (result.stopped) {
|
|
1960
|
+
result.acceptance = buildSkippedAcceptanceLedger(effectiveAcceptance, { id: "stopped", message: "Acceptance was not evaluated because the subagent was stopped." });
|
|
1961
|
+
}
|
|
1962
|
+
else if (result.timedOut) {
|
|
1963
|
+
result.acceptance = buildSkippedAcceptanceLedger(effectiveAcceptance, { id: "timeout", message: "Acceptance was not evaluated because the subagent timed out." });
|
|
1964
|
+
}
|
|
1965
|
+
else {
|
|
1966
|
+
result.acceptance = await evaluateAcceptance({
|
|
1967
|
+
acceptance: effectiveAcceptance,
|
|
1968
|
+
output: acceptanceOutputByResult.get(result) ?? result.finalOutput ?? "",
|
|
1969
|
+
report: result.structuredAcceptanceReport,
|
|
1970
|
+
reportError: result.structuredAcceptanceReportError,
|
|
1971
|
+
fileOutput: childWrittenOutput !== undefined && options.outputPath
|
|
1972
|
+
? { content: childWrittenOutput, path: options.outputPath, authoritative: options.outputMode === "file-only", durable: result.savedOutputPath !== undefined }
|
|
1973
|
+
: undefined,
|
|
1974
|
+
cwd: options.cwd ?? runtimeCwd,
|
|
1975
|
+
stagedIndexBaseline,
|
|
1976
|
+
reportOptional: isAgentContract(options.agentContract),
|
|
1977
|
+
artifactsDir: options.artifactsDir,
|
|
1978
|
+
runId: options.runId,
|
|
1979
|
+
watchdog: result.watchdog,
|
|
1980
|
+
});
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
catch (error) {
|
|
1984
|
+
const message = `Acceptance evaluation failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
1985
|
+
result.acceptance = buildSkippedAcceptanceLedger(effectiveAcceptance, { id: "acceptance-evaluation", message });
|
|
1986
|
+
}
|
|
1987
|
+
const acceptanceFailure = acceptanceFailureMessage(result.acceptance);
|
|
1988
|
+
stripAcceptanceReportsFromMessages(result.messages);
|
|
1989
|
+
// A passing typed gate supplies the structured output for runs that have no
|
|
1990
|
+
// outputSchema of their own; preflight rejects the combination.
|
|
1991
|
+
const typedGate = typedVerifyOutput(result.acceptance);
|
|
1992
|
+
if (typedGate && result.structuredOutput === undefined && !acceptanceFailure && result.exitCode === 0) {
|
|
1993
|
+
result.structuredOutput = typedGate.value;
|
|
1994
|
+
}
|
|
1995
|
+
if (acceptanceFailure && result.acceptance.explicit && result.exitCode === 0 && !result.interrupted && !result.timedOut && !isAgentContract(options.agentContract)) {
|
|
1996
|
+
result.exitCode = 1;
|
|
1997
|
+
if (result.savedOutputPath) {
|
|
1998
|
+
result.finalOutput = finalizeSingleOutput({
|
|
1999
|
+
fullOutput: result.finalOutput ?? "",
|
|
2000
|
+
outputPath: options.outputPath,
|
|
2001
|
+
outputMode: result.outputMode,
|
|
2002
|
+
exitCode: result.exitCode,
|
|
2003
|
+
preserveSavedOutput: true,
|
|
2004
|
+
savedPath: result.savedOutputPath,
|
|
2005
|
+
outputReference: result.outputReference,
|
|
2006
|
+
}).displayOutput;
|
|
2007
|
+
}
|
|
2008
|
+
result.error = result.error ? `${result.error}\n${acceptanceFailure}` : acceptanceFailure;
|
|
2009
|
+
if (artifactPathsResult && options.artifactConfig?.enabled !== false && options.artifactConfig?.includeOutput !== false) {
|
|
2010
|
+
try {
|
|
2011
|
+
writeArtifact(artifactPathsResult.outputPath, formatOutputArtifactContent({
|
|
2012
|
+
output: artifactOutputByResult.get(result) ?? result.finalOutput ?? "",
|
|
2013
|
+
error: result.error,
|
|
2014
|
+
transcriptPath: result.transcriptPath,
|
|
2015
|
+
metadataPath: options.artifactConfig?.includeMetadata === false ? undefined : artifactPathsResult.metadataPath,
|
|
2016
|
+
}));
|
|
2017
|
+
}
|
|
2018
|
+
catch (error) {
|
|
2019
|
+
const message = `Artifact output post-processing failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
2020
|
+
result.outputSaveError = result.outputSaveError ? `${result.outputSaveError}\n${message}` : message;
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
if (result.progress) {
|
|
2024
|
+
result.progress.status = "failed";
|
|
2025
|
+
result.progress.error = result.error;
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
if (isAgentContract(options.agentContract))
|
|
2029
|
+
attachContractProjections(result);
|
|
2030
|
+
redactResultPrompt(result);
|
|
2031
|
+
try {
|
|
2032
|
+
persistResultMetadata(result);
|
|
2033
|
+
}
|
|
2034
|
+
catch (error) {
|
|
2035
|
+
result.metadataSaveError = error instanceof Error ? error.message : String(error);
|
|
2036
|
+
}
|
|
2037
|
+
return result;
|
|
2038
|
+
}
|
|
2039
|
+
async function runSyncCompletion(runtimeCwd, agents, agentName, task, options) {
|
|
2040
|
+
let orcaProgressTab;
|
|
2041
|
+
try {
|
|
2042
|
+
const result = await runSyncCompletionInner(runtimeCwd, agents, agentName, task, {
|
|
2043
|
+
...options,
|
|
2044
|
+
onOrcaProgressTabCreated: (tab) => { orcaProgressTab = tab; },
|
|
2045
|
+
});
|
|
2046
|
+
orcaProgressTab?.finish(result.stopped ? "stopped" : result.exitCode === 0 && !result.error ? "completed" : "failed", result.sessionFile);
|
|
2047
|
+
return result;
|
|
2048
|
+
}
|
|
2049
|
+
catch (error) {
|
|
2050
|
+
orcaProgressTab?.finish("failed");
|
|
2051
|
+
throw error;
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
/**
|
|
2055
|
+
* Runs the authoritative completion pipeline independently from the foreground
|
|
2056
|
+
* receipt. Detachment is same-runtime only: it does not adopt or daemonize work.
|
|
2057
|
+
*/
|
|
2058
|
+
export async function runSync(runtimeCwd, agents, agentName, task, options) {
|
|
2059
|
+
// Capture the strict contract before consumer-owned objects can be mutated
|
|
2060
|
+
// after a detached receipt is published.
|
|
2061
|
+
const strictContract = isAgentContract(options.agentContract);
|
|
2062
|
+
let detachedReason;
|
|
2063
|
+
let publishedReceipt;
|
|
2064
|
+
let activeDetachAttempt;
|
|
2065
|
+
let detachReadyPublished = false;
|
|
2066
|
+
let resolveReceipt;
|
|
2067
|
+
const receipt = new Promise((resolve) => { resolveReceipt = resolve; });
|
|
2068
|
+
const originSignal = options.signal;
|
|
2069
|
+
const originController = new AbortController();
|
|
2070
|
+
const forwardOriginAbort = () => {
|
|
2071
|
+
if (!detachedReason)
|
|
2072
|
+
originController.abort(originSignal?.reason);
|
|
2073
|
+
};
|
|
2074
|
+
if (originSignal?.aborted)
|
|
2075
|
+
forwardOriginAbort();
|
|
2076
|
+
else
|
|
2077
|
+
originSignal?.addEventListener("abort", forwardOriginAbort, { once: true });
|
|
2078
|
+
const completion = runSyncCompletion(runtimeCwd, agents, agentName, task, {
|
|
2079
|
+
...options,
|
|
2080
|
+
signal: originController.signal,
|
|
2081
|
+
onDetachedExit: undefined,
|
|
2082
|
+
onDetachReceipt: (detachedReceipt) => {
|
|
2083
|
+
if (detachedReason || publishedReceipt)
|
|
2084
|
+
return false;
|
|
2085
|
+
// Keep the authoritative result, fallback snapshot, and caller receipt
|
|
2086
|
+
// separately owned while the completion pipeline remains live.
|
|
2087
|
+
publishedReceipt = structuredClone(detachedReceipt);
|
|
2088
|
+
const callerReceipt = structuredClone(detachedReceipt);
|
|
2089
|
+
// A strict contract was already validated before detach; normalize private
|
|
2090
|
+
// and caller snapshots to the only safely known version.
|
|
2091
|
+
publishedReceipt.agentContract = strictContract ? { version: 1 } : undefined;
|
|
2092
|
+
callerReceipt.agentContract = strictContract ? { version: 1 } : undefined;
|
|
2093
|
+
detachedReason = detachedReceipt.detachedReason ?? "user request";
|
|
2094
|
+
resolveReceipt(callerReceipt);
|
|
2095
|
+
return true;
|
|
2096
|
+
},
|
|
2097
|
+
onDetachReady: (detachAttempt) => {
|
|
2098
|
+
activeDetachAttempt = detachAttempt;
|
|
2099
|
+
if (detachReadyPublished)
|
|
2100
|
+
return;
|
|
2101
|
+
detachReadyPublished = true;
|
|
2102
|
+
options.onDetachReady?.((reason = "user request") => {
|
|
2103
|
+
if (detachedReason || originController.signal.aborted)
|
|
2104
|
+
return false;
|
|
2105
|
+
return activeDetachAttempt?.(reason) ?? false;
|
|
2106
|
+
});
|
|
2107
|
+
},
|
|
2108
|
+
});
|
|
2109
|
+
const authoritativeCompletion = completion.catch((error) => {
|
|
2110
|
+
if (!publishedReceipt || !detachedReason)
|
|
2111
|
+
throw error;
|
|
2112
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2113
|
+
const failureMessage = `Detached completion pipeline failed after receipt: ${message}`;
|
|
2114
|
+
const failedProgress = publishedReceipt.progress
|
|
2115
|
+
? { ...publishedReceipt.progress, status: "failed", error: failureMessage }
|
|
2116
|
+
: {
|
|
2117
|
+
index: options.index ?? 0,
|
|
2118
|
+
agent: publishedReceipt.agent,
|
|
2119
|
+
status: "failed",
|
|
2120
|
+
task: publishedReceipt.task,
|
|
2121
|
+
recentTools: [],
|
|
2122
|
+
recentOutput: [],
|
|
2123
|
+
toolCount: publishedReceipt.progressSummary?.toolCount ?? 0,
|
|
2124
|
+
tokens: publishedReceipt.progressSummary?.tokens ?? 0,
|
|
2125
|
+
durationMs: publishedReceipt.progressSummary?.durationMs ?? 0,
|
|
2126
|
+
error: failureMessage,
|
|
2127
|
+
};
|
|
2128
|
+
const failedResult = redactResultPrompt({
|
|
2129
|
+
...publishedReceipt,
|
|
2130
|
+
detached: undefined,
|
|
2131
|
+
detachedReason,
|
|
2132
|
+
exitCode: 1,
|
|
2133
|
+
error: failureMessage,
|
|
2134
|
+
finalOutput: failureMessage,
|
|
2135
|
+
progress: failedProgress,
|
|
2136
|
+
progressSummary: {
|
|
2137
|
+
toolCount: failedProgress.toolCount,
|
|
2138
|
+
tokens: failedProgress.tokens,
|
|
2139
|
+
durationMs: failedProgress.durationMs,
|
|
2140
|
+
},
|
|
2141
|
+
acceptance: publishedReceipt.acceptance
|
|
2142
|
+
? buildSkippedAcceptanceLedger(publishedReceipt.acceptance.effectiveAcceptance, { id: "completion-pipeline", message: failureMessage })
|
|
2143
|
+
: undefined,
|
|
2144
|
+
});
|
|
2145
|
+
if (strictContract)
|
|
2146
|
+
attachContractProjections(failedResult);
|
|
2147
|
+
try {
|
|
2148
|
+
// Replace the provisional detach receipt metadata with the authoritative
|
|
2149
|
+
// terminal failure. Persistence remains best-effort and cannot orphan work.
|
|
2150
|
+
persistSingleResultMetadata({
|
|
2151
|
+
metadataPath: failedResult.artifactPaths?.metadataPath,
|
|
2152
|
+
enabled: options.artifactConfig?.enabled !== false && options.artifactConfig?.includeMetadata !== false,
|
|
2153
|
+
runId: options.runId,
|
|
2154
|
+
agent: failedResult.agent,
|
|
2155
|
+
task: failedResult.task,
|
|
2156
|
+
result: failedResult,
|
|
2157
|
+
});
|
|
2158
|
+
}
|
|
2159
|
+
catch (metadataError) {
|
|
2160
|
+
failedResult.metadataSaveError = metadataError instanceof Error ? metadataError.message : String(metadataError);
|
|
2161
|
+
}
|
|
2162
|
+
return failedResult;
|
|
2163
|
+
});
|
|
2164
|
+
let terminalCallbackInvoked = false;
|
|
2165
|
+
void authoritativeCompletion.then(async (terminalResult) => {
|
|
2166
|
+
if (!detachedReason || terminalCallbackInvoked)
|
|
2167
|
+
return;
|
|
2168
|
+
terminalCallbackInvoked = true;
|
|
2169
|
+
terminalResult.detached = undefined;
|
|
2170
|
+
terminalResult.detachedReason = detachedReason;
|
|
2171
|
+
try {
|
|
2172
|
+
await options.onDetachedExit?.(terminalResult);
|
|
2173
|
+
}
|
|
2174
|
+
catch {
|
|
2175
|
+
// The authoritative result has settled. Consumer callback failures are
|
|
2176
|
+
// contained here; each consumer owns cleanup through its own finally block.
|
|
2177
|
+
}
|
|
2178
|
+
}).catch(() => {
|
|
2179
|
+
// Attached completion rejection remains observable through the returned
|
|
2180
|
+
// promise without becoming an unhandled side-channel rejection.
|
|
2181
|
+
}).finally(() => {
|
|
2182
|
+
originSignal?.removeEventListener("abort", forwardOriginAbort);
|
|
2183
|
+
});
|
|
2184
|
+
return Promise.race([authoritativeCompletion, receipt]);
|
|
2185
|
+
}
|
|
2186
|
+
//# sourceMappingURL=execution.js.map
|