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