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
|
@@ -0,0 +1,1989 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Async execution logic for subagent tool
|
|
3
|
+
*/
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
import * as fs from "node:fs";
|
|
7
|
+
import * as path from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import * as nodeModule from "node:module";
|
|
10
|
+
import { discoverAgents, formatUnknownAgentError, unknownAgentDiagnosticContext } from "../../agents/agents.js";
|
|
11
|
+
import { createAtomicJsonWriter, writePrivateAtomicJson } from "../../shared/atomic-json.js";
|
|
12
|
+
import { childCacheRetentionEnv } from "../../shared/child-cache-retention.js";
|
|
13
|
+
import { buildEffectiveSystemPrompt } from "../shared/effective-system-prompt.js";
|
|
14
|
+
import { currentCompletionOwnerId } from "../../shared/completion-owner.js";
|
|
15
|
+
import { planChildLaunch, projectChainOutputSchemas, resolveStepBehavior, suppressProgressForReadOnlyTask } from "../shared/child-launch-plan.js";
|
|
16
|
+
import { formatHerdrMachineRunnerUnsupported, resolveHerdrMachinePlacement } from "../shared/herdr-machine.js";
|
|
17
|
+
import { applyThinkingSuffix, projectLaunchResolvedChildExtensions, resolvePiLaunchToolPlan } from "../shared/child-tool-plan.js";
|
|
18
|
+
import { injectSingleOutputInstruction, normalizeSingleOutputOverride, resolveSingleOutputPath, validateFileOnlyOutputMode } from "../shared/single-output.js";
|
|
19
|
+
import { applyWatchdogLaunchRules, sendRuleViolationWarning } from "../../watchdog/rules.js";
|
|
20
|
+
import { buildChainInstructions, isDynamicParallelStep, isParallelStep, resolveExistingReadInstructionPaths, resolveExistingReadPaths, writeInitialProgressFile } from "../../shared/settings.js";
|
|
21
|
+
import { isDynamicRunnerGroup, isParallelGroup } from "../shared/parallel-utils.js";
|
|
22
|
+
import { PI_CODING_AGENT_PACKAGE, resolveBunPiExecutable, resolveInstalledPiPackageRoot, resolvePiPackageRoot } from "../shared/pi-spawn.js";
|
|
23
|
+
import { JITI_ALIAS_ENV, resolveHostPeerAliases } from "./runner-aliases.js";
|
|
24
|
+
import { preflightLaunchCwd } from "../shared/launch-cwd.js";
|
|
25
|
+
import { resolveNodeExecutable } from "../../shared/node-executable.js";
|
|
26
|
+
import { backgroundProcessOptions } from "../shared/background-process-options.js";
|
|
27
|
+
import { normalizeSkillInput, resolveSkillsWithFallback } from "../../agents/skills.js";
|
|
28
|
+
import { PI_CODING_AGENT_PACKAGE_ROOT_ENV, PROMPT_REDACTED, resolveChildCwd } from "../../shared/utils.js";
|
|
29
|
+
import { resolveEffectiveSubagentModel, resolveModelOrigin, resolveModelSelection, resolveSubagentModelOverride } from "../shared/model-resolution.js";
|
|
30
|
+
import { resolveToolTimeoutMs, toolTimeoutFromEnv } from "../shared/tool-timeout.js";
|
|
31
|
+
import { resolveModelScopesForAgent } from "../shared/model-scope.js";
|
|
32
|
+
import { findModelInfo, resolveEffectiveThinking } from "../../shared/model-info.js";
|
|
33
|
+
import { assertThinkingWithinCeiling, intersectThinkingCeilings } from "../../shared/thinking-ceiling.js";
|
|
34
|
+
import { resolveExpectedWorktreeAgentCwd, resolveWorktreeProvider, shouldDeferWorktreeCwd, WORKTREE_AGENT_CWD_PLACEHOLDER } from "../shared/worktree.js";
|
|
35
|
+
import { buildWorkflowGraphSnapshot } from "../shared/workflow-graph.js";
|
|
36
|
+
import { ChainOutputValidationError, validateChainOutputBindings } from "../shared/chain-outputs.js";
|
|
37
|
+
import { createStructuredOutputRuntime } from "../shared/structured-output.js";
|
|
38
|
+
import { resolveAcceptanceReportMode, resolveEffectiveAcceptance, validateAcceptanceInput, validateExecutionAcceptance } from "../shared/acceptance.js";
|
|
39
|
+
import { createRunFanoutBudget, writeRunFanoutBudgetDescriptor } from "../shared/run-fanout-budget.js";
|
|
40
|
+
import { validateImplementationToolContract } from "../shared/completion-guard.js";
|
|
41
|
+
import { DIRS, SUBAGENT_ASYNC_STARTED_EVENT, SUBAGENT_LIFECYCLE_ARTIFACT_VERSION, TEMP_ROOT_DIR, getAsyncConfigPath, resolveChildMaxSubagentDepth, } from "../../shared/types.js";
|
|
42
|
+
import { inheritedNestedParentAddressOf, inheritedNestedRouteOf, nestedResultsPath, nestedSummaryFromAsyncStatus, writeNestedEvent } from "../shared/nested-events.js";
|
|
43
|
+
import { SUBAGENT_PARENT_SESSION_ENV } from "../shared/child-runtime-config.js";
|
|
44
|
+
import { childSessionFactoryModule } from "../shared/child-session.js";
|
|
45
|
+
import { inheritedChildRuntime } from "../shared/child-launch.js";
|
|
46
|
+
import { resultFilePath } from "./result-files.js";
|
|
47
|
+
import { updateActiveRunIndex } from "./active-run-index.js";
|
|
48
|
+
import { validateToolBudgetConfig } from "../shared/tool-budget.js";
|
|
49
|
+
import { usageBudgetState } from "../shared/usage-budget.js";
|
|
50
|
+
import { finalizeProcessTerminal, initializeProcessTerminal, readProcessTerminal } from "./process-terminal.js";
|
|
51
|
+
import { statusStepDescription } from "./chain-append.js";
|
|
52
|
+
import { SUBAGENT_PROCESS_TERMINAL_EVENT } from "../../shared/types.js";
|
|
53
|
+
import { assertAgentAllowedByCapabilityCeiling, intersectSubagentCapabilityCeilings, resolveCurrentSubagentCapabilityCeiling } from "../shared/capability-ceiling.js";
|
|
54
|
+
import { resolveLaunchBinding } from "../../shared/launch-contract.js";
|
|
55
|
+
import { resolvePermissionRules } from "../shared/permissions.js";
|
|
56
|
+
import { normalizeExtensionBindings, omitExtensionBindingsEnv } from "../shared/extension-bindings.js";
|
|
57
|
+
import { assertWorkflowLaneKey, normalizeWorkflowLaneMetadata } from "../shared/lane-metadata.js";
|
|
58
|
+
import { resolveRequiredChildExtensions } from "../../shared/required-child-extensions.js";
|
|
59
|
+
const require = nodeModule.createRequire(import.meta.url);
|
|
60
|
+
const piPackageRoot = resolveAsyncPiPackageRoot();
|
|
61
|
+
/**
|
|
62
|
+
* The detached runner resolves the same host package the foreground
|
|
63
|
+
* `resolvePiCliScript` path resolves, so an explicit
|
|
64
|
+
* `PI_SUBAGENTS_PI_CODING_AGENT_PACKAGE_ROOT` override must be honored here
|
|
65
|
+
* too. Precedence mirrors the foreground resolver: argv-based discovery wins
|
|
66
|
+
* first (the foreground returns the argv script before any candidate), the
|
|
67
|
+
* environment override is consulted when that discovery cannot identify the
|
|
68
|
+
* host (wrapper installs, non-standard layouts), and the
|
|
69
|
+
* package-manager entry is last. Without the override, such hosts fail
|
|
70
|
+
* closed with "neither is available" while foreground children launch fine.
|
|
71
|
+
*/
|
|
72
|
+
function resolveAsyncPiPackageRoot(env = process.env) {
|
|
73
|
+
return resolvePiPackageRoot() || env[PI_CODING_AGENT_PACKAGE_ROOT_ENV]?.trim() || resolveInstalledPiPackageRoot();
|
|
74
|
+
}
|
|
75
|
+
function resolveJitiCliFromPackageJson(packageJsonPath) {
|
|
76
|
+
if (!fs.existsSync(packageJsonPath))
|
|
77
|
+
return undefined;
|
|
78
|
+
const packageRoot = path.dirname(packageJsonPath);
|
|
79
|
+
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
80
|
+
const binField = pkg.bin;
|
|
81
|
+
const binPath = typeof binField === "string"
|
|
82
|
+
? binField
|
|
83
|
+
: binField?.jiti ?? Object.values(binField ?? {})[0];
|
|
84
|
+
const candidates = [binPath, "lib/jiti-cli.mjs"].filter((candidate) => Boolean(candidate));
|
|
85
|
+
for (const candidate of candidates) {
|
|
86
|
+
const cliPath = path.resolve(packageRoot, candidate);
|
|
87
|
+
if (fs.existsSync(cliPath))
|
|
88
|
+
return cliPath;
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
function resolveJitiCliPath() {
|
|
93
|
+
const candidates = [
|
|
94
|
+
() => require.resolve("jiti/package.json"),
|
|
95
|
+
() => piPackageRoot
|
|
96
|
+
? nodeModule.createRequire(path.join(piPackageRoot, "package.json")).resolve("jiti/package.json")
|
|
97
|
+
: undefined,
|
|
98
|
+
() => {
|
|
99
|
+
if (!process.argv[1])
|
|
100
|
+
return undefined;
|
|
101
|
+
const piEntry = fs.realpathSync(process.argv[1]);
|
|
102
|
+
return nodeModule.createRequire(piEntry).resolve("jiti/package.json");
|
|
103
|
+
},
|
|
104
|
+
() => piPackageRoot ? path.join(piPackageRoot, "node_modules", "jiti", "package.json") : undefined,
|
|
105
|
+
];
|
|
106
|
+
for (const candidate of candidates) {
|
|
107
|
+
try {
|
|
108
|
+
const packageJsonPath = candidate();
|
|
109
|
+
if (!packageJsonPath)
|
|
110
|
+
continue;
|
|
111
|
+
const cliPath = resolveJitiCliFromPackageJson(packageJsonPath);
|
|
112
|
+
if (cliPath)
|
|
113
|
+
return cliPath;
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// Candidate not available in this install, continue probing.
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
const jitiCliPath = resolveJitiCliPath();
|
|
122
|
+
const asyncRunnerSourcePath = path.join(path.dirname(fileURLToPath(import.meta.url)), `subagent-runner${path.extname(fileURLToPath(import.meta.url))}`);
|
|
123
|
+
const sourceUnderNodeModules = asyncRunnerSourcePath.split(path.sep).some((segment) => segment.toLowerCase() === "node_modules");
|
|
124
|
+
function supportsNativeRunner(nodeExecutable) {
|
|
125
|
+
return Boolean(process.features.typescript)
|
|
126
|
+
&& typeof nodeModule.registerHooks === "function"
|
|
127
|
+
&& nodeExecutable === process.execPath
|
|
128
|
+
&& !sourceUnderNodeModules;
|
|
129
|
+
}
|
|
130
|
+
export const DEFAULT_ASYNC_TIMEOUT_MS = 30 * 60 * 1000;
|
|
131
|
+
export function formatAsyncStartedMessage(headline, interactive) {
|
|
132
|
+
const guidance = interactive
|
|
133
|
+
? [
|
|
134
|
+
"The async run is detached and running in the background.",
|
|
135
|
+
"You are in an interactive session. Return control to the user now; Pi will wake you through the native completion notification when this subagent completes or needs attention. Do not run sleep/polling loops to wait for this async subagent; it does not need a wait call.",
|
|
136
|
+
"Use bg_wait only for provider, detached, or other background work that lacks a native completion notification.",
|
|
137
|
+
"If the current turn must receive results from work without a native notification before it ends, call blocking bg_wait(); ordinary async subagent runs do not need a wait call because their completion is delivered natively.",
|
|
138
|
+
"Otherwise, continue any independent work or return control to the user. Use subagent({ action: \"status\", id: \"...\" }) for a one-shot status/result or to inspect a blocked/stale run, never as a wait loop.",
|
|
139
|
+
]
|
|
140
|
+
: [
|
|
141
|
+
"The async run is detached. Do not run sleep timers or polling loops just to wait for it.",
|
|
142
|
+
"This is a non-interactive run: Pi auto-drains current-session subagent work at agent_end so detached children are not abandoned. Use bg_wait only when this turn must receive provider, detached, or other background-work results that have no native completion notification.",
|
|
143
|
+
"Use subagent({ action: \"status\", id: \"...\" }) when you need a one-shot status/result or to inspect a blocked/stale run; do not poll in a loop.",
|
|
144
|
+
];
|
|
145
|
+
return [headline, "", ...guidance].join("\n");
|
|
146
|
+
}
|
|
147
|
+
/** Check whether detached async execution has a supported runtime. */
|
|
148
|
+
export function isAsyncAvailable() {
|
|
149
|
+
return resolveBunPiExecutable() !== undefined || supportsNativeRunner(resolveNodeExecutable()) || jitiCliPath !== undefined;
|
|
150
|
+
}
|
|
151
|
+
export function resolveAsyncRunnerLogPaths(cfg) {
|
|
152
|
+
const asyncDir = typeof cfg.asyncDir === "string"
|
|
153
|
+
? cfg.asyncDir
|
|
154
|
+
: undefined;
|
|
155
|
+
if (!asyncDir)
|
|
156
|
+
return undefined;
|
|
157
|
+
return {
|
|
158
|
+
stdoutPath: path.join(asyncDir, "runner.stdout.log"),
|
|
159
|
+
stderrPath: path.join(asyncDir, "runner.stderr.log"),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function closeFd(fd) {
|
|
163
|
+
if (fd === undefined)
|
|
164
|
+
return;
|
|
165
|
+
try {
|
|
166
|
+
fs.closeSync(fd);
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
// Best-effort cleanup; child process already owns its duplicated stdio fd.
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Spawn the async runner process
|
|
174
|
+
*/
|
|
175
|
+
const RUNNER_STARTUP_TIMEOUT_MS = 10_000;
|
|
176
|
+
function waitForStartupInterval(delayMs = 20) {
|
|
177
|
+
return new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
178
|
+
}
|
|
179
|
+
function readRunnerStartup(startupPath, expectedState, expectedToken) {
|
|
180
|
+
if (!fs.existsSync(startupPath))
|
|
181
|
+
return undefined;
|
|
182
|
+
try {
|
|
183
|
+
const payload = JSON.parse(fs.readFileSync(startupPath, "utf-8"));
|
|
184
|
+
if (payload.state === "error" && typeof payload.error === "string")
|
|
185
|
+
return { ok: false, error: payload.error, startupDidNotProceed: true };
|
|
186
|
+
if (payload.state !== expectedState)
|
|
187
|
+
return undefined;
|
|
188
|
+
if (typeof payload.token !== "string" || (expectedToken !== undefined && payload.token !== expectedToken)) {
|
|
189
|
+
return { ok: false, error: `Async runner wrote an invalid ${expectedState} startup handshake: ${startupPath}`, startupDidNotProceed: true };
|
|
190
|
+
}
|
|
191
|
+
return { ok: true, token: payload.token };
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
return { ok: false, error: `Failed to read async runner startup handshake '${startupPath}': ${error instanceof Error ? error.message : String(error)}`, startupDidNotProceed: true };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async function waitForRunnerStartup(startupPath, expectedState, timeoutMs, expectedToken, processClosed) {
|
|
198
|
+
const confirmOpen = async (result) => {
|
|
199
|
+
if (!processClosed || result.ok === false)
|
|
200
|
+
return result;
|
|
201
|
+
const outcome = await Promise.race([processClosed.then((exit) => ({ exit })), new Promise((resolve) => setImmediate(() => resolve(undefined)))]);
|
|
202
|
+
if (!outcome)
|
|
203
|
+
return result;
|
|
204
|
+
const finalResult = readRunnerStartup(startupPath, expectedState, expectedToken);
|
|
205
|
+
if (finalResult?.ok === false)
|
|
206
|
+
return finalResult;
|
|
207
|
+
const { exitCode, signal } = outcome.exit;
|
|
208
|
+
return { ok: false, error: `Async runner exited before startup state '${expectedState}' (exit code ${exitCode ?? "unknown"}, signal ${signal ?? "none"}).`, startupDidNotProceed: true };
|
|
209
|
+
};
|
|
210
|
+
const deadline = Date.now() + timeoutMs;
|
|
211
|
+
while (Date.now() <= deadline) {
|
|
212
|
+
const result = readRunnerStartup(startupPath, expectedState, expectedToken);
|
|
213
|
+
if (result)
|
|
214
|
+
return await confirmOpen(result);
|
|
215
|
+
const delay = waitForStartupInterval(Math.min(20, Math.max(1, deadline - Date.now())));
|
|
216
|
+
if (processClosed) {
|
|
217
|
+
const outcome = await Promise.race([delay.then(() => undefined), processClosed.then((exit) => ({ exit }))]);
|
|
218
|
+
if (outcome) {
|
|
219
|
+
const finalResult = readRunnerStartup(startupPath, expectedState, expectedToken);
|
|
220
|
+
if (finalResult?.ok === false)
|
|
221
|
+
return finalResult;
|
|
222
|
+
const { exitCode, signal } = outcome.exit;
|
|
223
|
+
return { ok: false, error: `Async runner exited before startup state '${expectedState}' (exit code ${exitCode ?? "unknown"}, signal ${signal ?? "none"}).`, startupDidNotProceed: true };
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
await delay;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const finalResult = readRunnerStartup(startupPath, expectedState, expectedToken);
|
|
231
|
+
if (finalResult)
|
|
232
|
+
return finalResult;
|
|
233
|
+
return { ok: false, error: `Timed out after ${timeoutMs}ms waiting for the async runner startup state '${expectedState}'.`, startupDidNotProceed: true };
|
|
234
|
+
}
|
|
235
|
+
const writePrivateStartupControlJson = createAtomicJsonWriter({ mode: 0o600, ignoreCleanupErrorAfterSuccess: true });
|
|
236
|
+
function writeRunnerStartupControl(filePath, payload) {
|
|
237
|
+
// Delegate to the shared atomic JSON writer (temp file + rename, retrying
|
|
238
|
+
// transient Windows EPERM/EBUSY/EACCES locks and cleaning up the temp file
|
|
239
|
+
// on failure), so the startup handshake gets the same locking resilience as
|
|
240
|
+
// every other async control/result file. This is exercised by
|
|
241
|
+
// test/unit/atomic-json.test.ts.
|
|
242
|
+
writePrivateStartupControlJson(filePath, payload);
|
|
243
|
+
}
|
|
244
|
+
function runnerIsAlive(pid) {
|
|
245
|
+
try {
|
|
246
|
+
process.kill(pid, 0);
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
return error.code === "EPERM";
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
function waitForStartupIntervalSync(delayMs = 20) {
|
|
254
|
+
const waitUntil = Date.now() + delayMs;
|
|
255
|
+
while (Date.now() < waitUntil) {
|
|
256
|
+
// Pre-handshake failures happen before the runner can be observed asynchronously.
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function terminateRunnerBeforeProceed(pid) {
|
|
260
|
+
for (const signal of ["SIGTERM", "SIGKILL"]) {
|
|
261
|
+
if (!runnerIsAlive(pid))
|
|
262
|
+
return true;
|
|
263
|
+
try {
|
|
264
|
+
process.kill(pid, signal);
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
if (!runnerIsAlive(pid))
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
const deadline = Date.now() + 1000;
|
|
271
|
+
while (runnerIsAlive(pid) && Date.now() < deadline)
|
|
272
|
+
waitForStartupIntervalSync();
|
|
273
|
+
}
|
|
274
|
+
return !runnerIsAlive(pid);
|
|
275
|
+
}
|
|
276
|
+
async function terminateRunnerBeforeProceedAsync(proc, processClosed) {
|
|
277
|
+
for (const signal of ["SIGTERM", "SIGKILL"]) {
|
|
278
|
+
if (proc.pid === undefined || !runnerIsAlive(proc.pid))
|
|
279
|
+
return true;
|
|
280
|
+
try {
|
|
281
|
+
process.kill(proc.pid, signal);
|
|
282
|
+
}
|
|
283
|
+
catch {
|
|
284
|
+
if (proc.pid === undefined || !runnerIsAlive(proc.pid))
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
const exited = await Promise.race([processClosed.then(() => true), waitForStartupInterval(1000).then(() => false)]);
|
|
288
|
+
if (exited || proc.pid === undefined || !runnerIsAlive(proc.pid))
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
return proc.pid === undefined || !runnerIsAlive(proc.pid);
|
|
292
|
+
}
|
|
293
|
+
async function completeRunnerStartupHandshake(startupPath, startupAckPath, startupConfirmPath, startupProceedPath, proc, processClosed, getObservedProcessExit, runnerProcessInstanceId, persistStartupFailure) {
|
|
294
|
+
try {
|
|
295
|
+
const ready = await waitForRunnerStartup(startupPath, "ready", RUNNER_STARTUP_TIMEOUT_MS, undefined, processClosed);
|
|
296
|
+
if (ready.ok === false) {
|
|
297
|
+
persistStartupFailure(ready.error);
|
|
298
|
+
const terminationObserved = await terminateRunnerBeforeProceedAsync(proc, processClosed);
|
|
299
|
+
return { pid: proc.pid, runnerProcessInstanceId, error: ready.error, terminationObserved, startupDidNotProceed: true };
|
|
300
|
+
}
|
|
301
|
+
try {
|
|
302
|
+
writeRunnerStartupControl(startupAckPath, { action: "ack", token: ready.token });
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
const message = `Failed to acknowledge async runner startup: ${error instanceof Error ? error.message : String(error)}`;
|
|
306
|
+
persistStartupFailure(message);
|
|
307
|
+
const terminationObserved = await terminateRunnerBeforeProceedAsync(proc, processClosed);
|
|
308
|
+
return { pid: proc.pid, runnerProcessInstanceId, error: message, terminationObserved, startupDidNotProceed: true };
|
|
309
|
+
}
|
|
310
|
+
const acknowledged = await waitForRunnerStartup(startupPath, "acknowledged", RUNNER_STARTUP_TIMEOUT_MS, ready.token, processClosed);
|
|
311
|
+
if (acknowledged.ok === false) {
|
|
312
|
+
persistStartupFailure(acknowledged.error);
|
|
313
|
+
const terminationObserved = await terminateRunnerBeforeProceedAsync(proc, processClosed);
|
|
314
|
+
return { pid: proc.pid, runnerProcessInstanceId, error: acknowledged.error, terminationObserved, startupDidNotProceed: true };
|
|
315
|
+
}
|
|
316
|
+
try {
|
|
317
|
+
writeRunnerStartupControl(startupConfirmPath, { action: "confirm", token: ready.token });
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
const message = `Failed to confirm async runner startup: ${error instanceof Error ? error.message : String(error)}`;
|
|
321
|
+
persistStartupFailure(message);
|
|
322
|
+
const terminationObserved = await terminateRunnerBeforeProceedAsync(proc, processClosed);
|
|
323
|
+
return { pid: proc.pid, runnerProcessInstanceId, error: message, terminationObserved, startupDidNotProceed: true };
|
|
324
|
+
}
|
|
325
|
+
const confirmed = await waitForRunnerStartup(startupPath, "confirmed", RUNNER_STARTUP_TIMEOUT_MS, ready.token, processClosed);
|
|
326
|
+
if (confirmed.ok === false) {
|
|
327
|
+
persistStartupFailure(confirmed.error);
|
|
328
|
+
const terminationObserved = await terminateRunnerBeforeProceedAsync(proc, processClosed);
|
|
329
|
+
return { pid: proc.pid, runnerProcessInstanceId, error: confirmed.error, terminationObserved, startupDidNotProceed: true };
|
|
330
|
+
}
|
|
331
|
+
const closedAtCommit = await Promise.race([
|
|
332
|
+
processClosed.then((exit) => exit),
|
|
333
|
+
new Promise((resolve) => setImmediate(() => resolve(undefined))),
|
|
334
|
+
]);
|
|
335
|
+
const observedExit = closedAtCommit ?? getObservedProcessExit();
|
|
336
|
+
if (observedExit) {
|
|
337
|
+
const message = `Async runner exited after startup state 'acknowledged' before proceed (exit code ${observedExit.exitCode ?? "unknown"}, signal ${observedExit.signal ?? "none"}).`;
|
|
338
|
+
persistStartupFailure(message);
|
|
339
|
+
const terminationObserved = await terminateRunnerBeforeProceedAsync(proc, processClosed);
|
|
340
|
+
return { pid: proc.pid, runnerProcessInstanceId, error: message, terminationObserved, startupDidNotProceed: true };
|
|
341
|
+
}
|
|
342
|
+
try {
|
|
343
|
+
writeRunnerStartupControl(startupProceedPath, { action: "proceed", token: ready.token });
|
|
344
|
+
}
|
|
345
|
+
catch (error) {
|
|
346
|
+
const message = `Failed to authorize async runner startup: ${error instanceof Error ? error.message : String(error)}`;
|
|
347
|
+
persistStartupFailure(message);
|
|
348
|
+
const terminationObserved = await terminateRunnerBeforeProceedAsync(proc, processClosed);
|
|
349
|
+
return { pid: proc.pid, runnerProcessInstanceId, error: message, terminationObserved, startupDidNotProceed: true };
|
|
350
|
+
}
|
|
351
|
+
try {
|
|
352
|
+
fs.rmSync(startupPath, { force: true });
|
|
353
|
+
}
|
|
354
|
+
catch { }
|
|
355
|
+
return { pid: proc.pid, runnerProcessInstanceId };
|
|
356
|
+
}
|
|
357
|
+
finally {
|
|
358
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function persistPreProceedStartupFailure(asyncDir, runId, runnerProcessInstanceId, sessionId, completionOwnerId, message) {
|
|
362
|
+
const now = Date.now();
|
|
363
|
+
try {
|
|
364
|
+
const statusPath = path.join(asyncDir, "status.json");
|
|
365
|
+
let status = {};
|
|
366
|
+
try {
|
|
367
|
+
status = JSON.parse(fs.readFileSync(statusPath, "utf-8"));
|
|
368
|
+
}
|
|
369
|
+
catch { }
|
|
370
|
+
const existingProcessTerminal = status.processTerminal?.state === "observed" || status.processTerminal?.state === "unknown"
|
|
371
|
+
? status.processTerminal : undefined;
|
|
372
|
+
writePrivateAtomicJson(statusPath, {
|
|
373
|
+
...status,
|
|
374
|
+
runId,
|
|
375
|
+
...(sessionId ? { sessionId } : {}),
|
|
376
|
+
...(completionOwnerId ? { completionOwnerId } : {}),
|
|
377
|
+
state: "failed",
|
|
378
|
+
lastUpdate: now,
|
|
379
|
+
error: message,
|
|
380
|
+
processTerminal: existingProcessTerminal ?? {
|
|
381
|
+
version: 1,
|
|
382
|
+
state: "not-started",
|
|
383
|
+
runId,
|
|
384
|
+
runnerProcessInstanceId,
|
|
385
|
+
},
|
|
386
|
+
});
|
|
387
|
+
writePrivateAtomicJson(path.join(asyncDir, "process-terminal-candidate.json"), {
|
|
388
|
+
version: 1,
|
|
389
|
+
runId,
|
|
390
|
+
runnerProcessInstanceId,
|
|
391
|
+
writers: {},
|
|
392
|
+
expectedWriters: { 0: 0 },
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
catch {
|
|
396
|
+
// Startup failures must still return the original launch error.
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function isStaleExtensionContextError(error) {
|
|
400
|
+
return error instanceof Error && /extension ctx is stale|stale after session replacement or reload/i.test(error.message);
|
|
401
|
+
}
|
|
402
|
+
export function emitProcessTerminalEvent(ctx, proof) {
|
|
403
|
+
try {
|
|
404
|
+
ctx.pi.events.emit(SUBAGENT_PROCESS_TERMINAL_EVENT, proof);
|
|
405
|
+
}
|
|
406
|
+
catch (error) {
|
|
407
|
+
if (isStaleExtensionContextError(error))
|
|
408
|
+
return;
|
|
409
|
+
console.error("Failed to emit subagent process-terminal event:", error);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
function spawnRunner(cfg, suffix, cwd, initialStatus, initialStatusPath, launchParentSessionId, onProcessTerminal, onBeforeProceed, requestedCwd = cwd) {
|
|
413
|
+
const cwdError = preflightLaunchCwd(requestedCwd, cwd);
|
|
414
|
+
if (cwdError)
|
|
415
|
+
return { error: cwdError };
|
|
416
|
+
if (launchParentSessionId !== undefined && (!launchParentSessionId || launchParentSessionId.trim() !== launchParentSessionId)) {
|
|
417
|
+
return { error: "Background runner parent session identity is invalid." };
|
|
418
|
+
}
|
|
419
|
+
const steps = cfg.steps;
|
|
420
|
+
if (!Array.isArray(steps))
|
|
421
|
+
return { error: "Background runner launch is missing its steps." };
|
|
422
|
+
const inconsistentParent = steps.some((step) => isParallelGroup(step)
|
|
423
|
+
? step.parallel.some((child) => child.parentSessionId !== launchParentSessionId)
|
|
424
|
+
: (isDynamicRunnerGroup(step) ? step.parallel.parentSessionId : step.parentSessionId) !== launchParentSessionId);
|
|
425
|
+
if (inconsistentParent)
|
|
426
|
+
return { error: "Background runner steps have inconsistent parent session identities." };
|
|
427
|
+
// The compiled host exposes its SDK only through Pi's extension loader.
|
|
428
|
+
const binaryHost = resolveBunPiExecutable();
|
|
429
|
+
const nodeExecutable = resolveNodeExecutable();
|
|
430
|
+
const nativeRunnerSupported = supportsNativeRunner(nodeExecutable);
|
|
431
|
+
const runner = asyncRunnerSourcePath;
|
|
432
|
+
const runnerIsJavaScript = path.extname(runner) === ".js";
|
|
433
|
+
const bootstrap = path.join(path.dirname(runner), `binary-bootstrap${path.extname(fileURLToPath(import.meta.url))}`);
|
|
434
|
+
if (binaryHost && !fs.existsSync(bootstrap))
|
|
435
|
+
return { error: `Background runner bootstrap not found: ${bootstrap}` };
|
|
436
|
+
if (!binaryHost && !runnerIsJavaScript && !nativeRunnerSupported && !jitiCliPath) {
|
|
437
|
+
return { error: sourceUnderNodeModules
|
|
438
|
+
? "Background runner source is installed under node_modules, so upstream jiti is required for TypeScript execution."
|
|
439
|
+
: "Background runner requires enabled native TypeScript with synchronous module hooks, or installed upstream jiti for TypeScript execution." };
|
|
440
|
+
}
|
|
441
|
+
if (!binaryHost && !piPackageRoot) {
|
|
442
|
+
return { error: `Background children require a supported standalone Pi host or the installed npm package (${PI_CODING_AGENT_PACKAGE}); neither is available.` };
|
|
443
|
+
}
|
|
444
|
+
const hostPeerAliases = !binaryHost && piPackageRoot ? resolveHostPeerAliases(piPackageRoot) : { aliases: {}, missing: [] };
|
|
445
|
+
if (hostPeerAliases.missing.length > 0) {
|
|
446
|
+
return { error: `Background children require the host npm package (${PI_CODING_AGENT_PACKAGE}) with its dependencies; ${piPackageRoot} does not provide ${hostPeerAliases.missing.join(", ")}.` };
|
|
447
|
+
}
|
|
448
|
+
fs.mkdirSync(TEMP_ROOT_DIR, { recursive: true });
|
|
449
|
+
const cfgPath = getAsyncConfigPath(suffix);
|
|
450
|
+
const runnerProcessInstanceId = randomUUID();
|
|
451
|
+
const hasRevivalLease = typeof cfg.revivalLease === "object";
|
|
452
|
+
const launchBarrierToken = hasRevivalLease ? undefined : runnerProcessInstanceId;
|
|
453
|
+
const launchConfig = { ...cfg, runnerProcessInstanceId, ...(launchBarrierToken ? { launchBarrierToken } : {}) };
|
|
454
|
+
writePrivateAtomicJson(cfgPath, launchConfig);
|
|
455
|
+
const command = binaryHost ?? nodeExecutable;
|
|
456
|
+
const launchForStartup = launchConfig;
|
|
457
|
+
const launchAsyncDir = typeof launchForStartup.asyncDir === "string" ? launchForStartup.asyncDir : undefined;
|
|
458
|
+
const launchRunId = typeof launchForStartup.id === "string" ? launchForStartup.id : suffix;
|
|
459
|
+
const launchSessionId = typeof launchForStartup.sessionId === "string" ? launchForStartup.sessionId : undefined;
|
|
460
|
+
const launchCompletionOwnerId = typeof launchForStartup.completionOwnerId === "string" ? launchForStartup.completionOwnerId : undefined;
|
|
461
|
+
const startupPath = typeof launchForStartup.revivalLease === "object" && launchAsyncDir
|
|
462
|
+
? path.join(launchAsyncDir, "runner-startup.json")
|
|
463
|
+
: undefined;
|
|
464
|
+
const startupAckPath = startupPath ? path.join(path.dirname(startupPath), "runner-startup-ack.json") : undefined;
|
|
465
|
+
const startupConfirmPath = startupPath ? path.join(path.dirname(startupPath), "runner-startup-confirm.json") : undefined;
|
|
466
|
+
const startupProceedPath = launchAsyncDir && (startupPath || launchBarrierToken)
|
|
467
|
+
? path.join(launchAsyncDir, "runner-startup-proceed.json")
|
|
468
|
+
: undefined;
|
|
469
|
+
if (startupPath)
|
|
470
|
+
fs.rmSync(startupPath, { force: true });
|
|
471
|
+
if (startupAckPath)
|
|
472
|
+
fs.rmSync(startupAckPath, { force: true });
|
|
473
|
+
if (startupConfirmPath)
|
|
474
|
+
fs.rmSync(startupConfirmPath, { force: true });
|
|
475
|
+
if (startupProceedPath)
|
|
476
|
+
fs.rmSync(startupProceedPath, { force: true });
|
|
477
|
+
const logPaths = resolveAsyncRunnerLogPaths(launchConfig);
|
|
478
|
+
let stdoutFd;
|
|
479
|
+
let stderrFd;
|
|
480
|
+
try {
|
|
481
|
+
if (logPaths) {
|
|
482
|
+
fs.mkdirSync(path.dirname(logPaths.stdoutPath), { recursive: true });
|
|
483
|
+
stdoutFd = fs.openSync(logPaths.stdoutPath, "a");
|
|
484
|
+
stderrFd = fs.openSync(logPaths.stderrPath, "a");
|
|
485
|
+
}
|
|
486
|
+
// Short-circuit native peer aliases so Pi's loader and generated factories preserve filesystem resolution semantics.
|
|
487
|
+
const preload = Object.keys(hostPeerAliases.aliases).length > 0
|
|
488
|
+
? ["--import", new URL("../../../runner-peer-preload.mjs", import.meta.url).href]
|
|
489
|
+
: [];
|
|
490
|
+
const args = binaryHost
|
|
491
|
+
? ["--no-extensions", "--no-skills", "--no-prompt-templates", "--no-session", "--mode", "rpc", "--extension", bootstrap]
|
|
492
|
+
: runnerIsJavaScript
|
|
493
|
+
? [...preload, runner, cfgPath]
|
|
494
|
+
: nativeRunnerSupported
|
|
495
|
+
? [...preload, "--experimental-strip-types", runner, cfgPath]
|
|
496
|
+
: [...preload, jitiCliPath, runner, cfgPath];
|
|
497
|
+
const runnerEnv = {
|
|
498
|
+
...omitExtensionBindingsEnv(process.env),
|
|
499
|
+
...childCacheRetentionEnv(),
|
|
500
|
+
[PI_CODING_AGENT_PACKAGE_ROOT_ENV]: binaryHost ? undefined : piPackageRoot,
|
|
501
|
+
// npm must override inherited bundled layouts (#2071); binaries retain release assets.
|
|
502
|
+
PI_PACKAGE_DIR: binaryHost ? process.env.PI_PACKAGE_DIR : piPackageRoot,
|
|
503
|
+
[JITI_ALIAS_ENV]: binaryHost ? undefined : JSON.stringify(hostPeerAliases.aliases),
|
|
504
|
+
PI_ASYNC_NATIVE_RUNNER: !binaryHost && (runnerIsJavaScript || nativeRunnerSupported) ? "1" : "0",
|
|
505
|
+
PI_SUBAGENT_RUNNER_CONFIG: binaryHost ? cfgPath : undefined,
|
|
506
|
+
};
|
|
507
|
+
if (launchParentSessionId === undefined)
|
|
508
|
+
delete runnerEnv[SUBAGENT_PARENT_SESSION_ENV];
|
|
509
|
+
else
|
|
510
|
+
runnerEnv[SUBAGENT_PARENT_SESSION_ENV] = launchParentSessionId;
|
|
511
|
+
const proc = spawn(command, args, {
|
|
512
|
+
cwd,
|
|
513
|
+
...backgroundProcessOptions(),
|
|
514
|
+
stdio: ["ignore", stdoutFd ?? "ignore", stderrFd ?? "ignore"],
|
|
515
|
+
env: runnerEnv,
|
|
516
|
+
});
|
|
517
|
+
let observedProcessExit;
|
|
518
|
+
proc.once("exit", (exitCode, signal) => { observedProcessExit = { exitCode, signal }; });
|
|
519
|
+
const processClosed = new Promise((resolve) => {
|
|
520
|
+
proc.once("close", (exitCode, signal) => {
|
|
521
|
+
observedProcessExit ??= { exitCode, signal };
|
|
522
|
+
resolve({ exitCode, signal });
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
closeFd(stdoutFd);
|
|
526
|
+
closeFd(stderrFd);
|
|
527
|
+
proc.on("error", (error) => {
|
|
528
|
+
console.error(`[pi-subagents] async spawn failed: ${error.message}`);
|
|
529
|
+
});
|
|
530
|
+
proc.once("close", (exitCode, signal) => {
|
|
531
|
+
const finalize = () => {
|
|
532
|
+
const launch = launchConfig;
|
|
533
|
+
const asyncDir = launch.asyncDir;
|
|
534
|
+
const runId = launch.id;
|
|
535
|
+
if (typeof asyncDir !== "string" || typeof runId !== "string")
|
|
536
|
+
return;
|
|
537
|
+
finalizeProcessTerminal(asyncDir, runId, {
|
|
538
|
+
processInstanceId: runnerProcessInstanceId,
|
|
539
|
+
closeObservedAt: Date.now(),
|
|
540
|
+
exitCode,
|
|
541
|
+
signal,
|
|
542
|
+
});
|
|
543
|
+
const persisted = readProcessTerminal(asyncDir, { runId, runnerProcessInstanceId });
|
|
544
|
+
if (!persisted)
|
|
545
|
+
return;
|
|
546
|
+
if (launch.nestedRoute && launch.nestedSelf) {
|
|
547
|
+
try {
|
|
548
|
+
let status;
|
|
549
|
+
try {
|
|
550
|
+
status = JSON.parse(fs.readFileSync(path.join(asyncDir, "status.json"), "utf-8"));
|
|
551
|
+
status.processTerminal = persisted;
|
|
552
|
+
}
|
|
553
|
+
catch {
|
|
554
|
+
status = {
|
|
555
|
+
runId,
|
|
556
|
+
mode: "single",
|
|
557
|
+
state: persisted.state === "observed" ? "complete" : "failed",
|
|
558
|
+
startedAt: persisted.observedAt ?? Date.now(),
|
|
559
|
+
lastUpdate: Date.now(),
|
|
560
|
+
processTerminal: persisted,
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
writeNestedEvent(launch.nestedRoute, {
|
|
564
|
+
type: "subagent.nested.completed",
|
|
565
|
+
ts: Date.now(),
|
|
566
|
+
parentRunId: launch.nestedSelf.parentRunId,
|
|
567
|
+
parentStepIndex: launch.nestedSelf.parentStepIndex,
|
|
568
|
+
child: nestedSummaryFromAsyncStatus(status, asyncDir, {
|
|
569
|
+
id: runId,
|
|
570
|
+
parentRunId: launch.nestedSelf.parentRunId,
|
|
571
|
+
parentStepIndex: launch.nestedSelf.parentStepIndex,
|
|
572
|
+
depth: launch.nestedSelf.depth,
|
|
573
|
+
path: launch.nestedSelf.path,
|
|
574
|
+
mode: status.mode,
|
|
575
|
+
ts: Date.now(),
|
|
576
|
+
}),
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
catch (error) {
|
|
580
|
+
console.error("Failed to emit final nested process-terminal status:", error);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
onProcessTerminal?.(persisted);
|
|
584
|
+
};
|
|
585
|
+
if (startupPath)
|
|
586
|
+
setImmediate(finalize);
|
|
587
|
+
else
|
|
588
|
+
finalize();
|
|
589
|
+
});
|
|
590
|
+
if (typeof proc.pid !== "number") {
|
|
591
|
+
return { error: `async runner did not produce a pid for cwd: ${cwd}` };
|
|
592
|
+
}
|
|
593
|
+
try {
|
|
594
|
+
writePrivateAtomicJson(initialStatusPath, {
|
|
595
|
+
...initialStatus,
|
|
596
|
+
pid: proc.pid,
|
|
597
|
+
processTerminal: { version: 1, state: "pending", runId: initialStatus.runId, runnerProcessInstanceId },
|
|
598
|
+
});
|
|
599
|
+
// Aggregate waits must see the launch before the runner's first status update.
|
|
600
|
+
updateActiveRunIndex(path.dirname(initialStatusPath), initialStatus.state, initialStatus.toolCallId);
|
|
601
|
+
}
|
|
602
|
+
catch (error) {
|
|
603
|
+
const message = `Failed to persist initial async status: ${error instanceof Error ? error.message : String(error)}`;
|
|
604
|
+
if (launchAsyncDir)
|
|
605
|
+
persistPreProceedStartupFailure(launchAsyncDir, launchRunId, runnerProcessInstanceId, launchSessionId, launchCompletionOwnerId, message);
|
|
606
|
+
const terminationObserved = terminateRunnerBeforeProceed(proc.pid);
|
|
607
|
+
return { pid: proc.pid, runnerProcessInstanceId, error: message, terminationObserved, startupDidNotProceed: true };
|
|
608
|
+
}
|
|
609
|
+
try {
|
|
610
|
+
if (!launchAsyncDir)
|
|
611
|
+
throw new Error("Async runner is missing its lifecycle directory.");
|
|
612
|
+
initializeProcessTerminal(launchAsyncDir, launchRunId, runnerProcessInstanceId);
|
|
613
|
+
}
|
|
614
|
+
catch (error) {
|
|
615
|
+
const message = `Failed to establish async runner lifecycle sidecar: ${error instanceof Error ? error.message : String(error)}`;
|
|
616
|
+
if (launchAsyncDir)
|
|
617
|
+
persistPreProceedStartupFailure(launchAsyncDir, launchRunId, runnerProcessInstanceId, launchSessionId, launchCompletionOwnerId, message);
|
|
618
|
+
const terminationObserved = terminateRunnerBeforeProceed(proc.pid);
|
|
619
|
+
return { pid: proc.pid, runnerProcessInstanceId, error: message, terminationObserved, startupDidNotProceed: true };
|
|
620
|
+
}
|
|
621
|
+
try {
|
|
622
|
+
onBeforeProceed?.(runnerProcessInstanceId);
|
|
623
|
+
}
|
|
624
|
+
catch (error) {
|
|
625
|
+
const message = `Failed to establish async runner capacity ownership: ${error instanceof Error ? error.message : String(error)}`;
|
|
626
|
+
if (launchAsyncDir)
|
|
627
|
+
persistPreProceedStartupFailure(launchAsyncDir, launchRunId, runnerProcessInstanceId, launchSessionId, launchCompletionOwnerId, message);
|
|
628
|
+
const terminationObserved = terminateRunnerBeforeProceed(proc.pid);
|
|
629
|
+
return { pid: proc.pid, runnerProcessInstanceId, error: message, terminationObserved, startupDidNotProceed: true };
|
|
630
|
+
}
|
|
631
|
+
if (launchBarrierToken && startupProceedPath) {
|
|
632
|
+
try {
|
|
633
|
+
writeRunnerStartupControl(startupProceedPath, { action: "proceed", token: launchBarrierToken });
|
|
634
|
+
}
|
|
635
|
+
catch (error) {
|
|
636
|
+
const message = `Failed to authorize async runner startup: ${error instanceof Error ? error.message : String(error)}`;
|
|
637
|
+
if (launchAsyncDir)
|
|
638
|
+
persistPreProceedStartupFailure(launchAsyncDir, launchRunId, runnerProcessInstanceId, launchSessionId, launchCompletionOwnerId, message);
|
|
639
|
+
const terminationObserved = terminateRunnerBeforeProceed(proc.pid);
|
|
640
|
+
return { pid: proc.pid, runnerProcessInstanceId, error: message, terminationObserved, startupDidNotProceed: true };
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
proc.unref();
|
|
644
|
+
if (startupPath && startupAckPath && startupConfirmPath && startupProceedPath) {
|
|
645
|
+
const persistStartupFailure = (message) => {
|
|
646
|
+
if (launchAsyncDir)
|
|
647
|
+
persistPreProceedStartupFailure(launchAsyncDir, launchRunId, runnerProcessInstanceId, launchSessionId, launchCompletionOwnerId, message);
|
|
648
|
+
};
|
|
649
|
+
return completeRunnerStartupHandshake(startupPath, startupAckPath, startupConfirmPath, startupProceedPath, proc, processClosed, () => observedProcessExit ?? (proc.exitCode !== null || proc.signalCode !== null ? { exitCode: proc.exitCode, signal: proc.signalCode } : undefined), runnerProcessInstanceId, persistStartupFailure);
|
|
650
|
+
}
|
|
651
|
+
return { pid: proc.pid, runnerProcessInstanceId };
|
|
652
|
+
}
|
|
653
|
+
catch (error) {
|
|
654
|
+
closeFd(stdoutFd);
|
|
655
|
+
closeFd(stderrFd);
|
|
656
|
+
return { error: error instanceof Error ? error.message : String(error) };
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
function formatAsyncStartError(mode, message) {
|
|
660
|
+
return {
|
|
661
|
+
content: [{ type: "text", text: message }],
|
|
662
|
+
isError: true,
|
|
663
|
+
details: { mode, results: [] },
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
const UNAVAILABLE_SUBAGENT_SKILL_ERROR = "Skills not found: pi-subagents";
|
|
667
|
+
class UnavailableSubagentSkillError extends Error {
|
|
668
|
+
}
|
|
669
|
+
class AsyncStartValidationError extends Error {
|
|
670
|
+
}
|
|
671
|
+
export function buildAsyncRunnerSteps(id, params) {
|
|
672
|
+
const { chain, agents, ctx, cwd, sessionFilesByFlatIndex, thinkingOverridesByFlatIndex, maxSubagentDepth, worktreeBaseDir, worktreeProvider, worktreeBranchPrefix, asyncDir, } = params;
|
|
673
|
+
const launchParentSessionId = ctx.parentSessionId ?? ctx.currentSessionId;
|
|
674
|
+
const outputBaseDir = params.outputBaseDir;
|
|
675
|
+
const resultMode = params.resultMode ?? "chain";
|
|
676
|
+
const chainSkills = params.chainSkills ?? [];
|
|
677
|
+
const availableModels = params.availableModels;
|
|
678
|
+
const runnerCwd = resolveChildCwd(ctx.cwd, cwd);
|
|
679
|
+
const launchMachine = params.machine;
|
|
680
|
+
let managedWorktreeProvider;
|
|
681
|
+
try {
|
|
682
|
+
if (chain.some((step) => "worktree" in step && step.worktree === true)) {
|
|
683
|
+
const resolved = resolveWorktreeProvider(worktreeProvider, worktreeBaseDir);
|
|
684
|
+
managedWorktreeProvider = shouldDeferWorktreeCwd(worktreeProvider, worktreeBaseDir) ? "worktrunk" : resolved;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
catch (error) {
|
|
688
|
+
return { error: error instanceof Error ? error.message : String(error) };
|
|
689
|
+
}
|
|
690
|
+
const progressDir = params.progressDir ?? runnerCwd;
|
|
691
|
+
const graphChain = params.attachRoot
|
|
692
|
+
? [{
|
|
693
|
+
agent: params.attachRoot.agent,
|
|
694
|
+
task: `Attach async root ${params.attachRoot.runId}`,
|
|
695
|
+
label: params.attachRoot.label ?? `Attached root ${params.attachRoot.runId}`,
|
|
696
|
+
...(params.attachRoot.outputName ? { as: params.attachRoot.outputName } : {}),
|
|
697
|
+
}, ...chain]
|
|
698
|
+
: chain;
|
|
699
|
+
const firstStep = chain[0];
|
|
700
|
+
const originalTask = params.task ?? (firstStep
|
|
701
|
+
? (isParallelStep(firstStep)
|
|
702
|
+
? firstStep.parallel[0]?.task
|
|
703
|
+
: isDynamicParallelStep(firstStep)
|
|
704
|
+
? firstStep.parallel.task
|
|
705
|
+
: firstStep.task)
|
|
706
|
+
: undefined);
|
|
707
|
+
try {
|
|
708
|
+
if (params.validateOutputBindings !== false) {
|
|
709
|
+
validateChainOutputBindings(chain, { maxItems: params.dynamicFanoutMaxItems });
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
catch (error) {
|
|
713
|
+
if (error instanceof ChainOutputValidationError)
|
|
714
|
+
return { error: error.message };
|
|
715
|
+
throw error;
|
|
716
|
+
}
|
|
717
|
+
const diagnosticContext = params.unknownAgentDiagnosticContext
|
|
718
|
+
?? unknownAgentDiagnosticContext(discoverAgents(path.resolve(runnerCwd), "both"));
|
|
719
|
+
for (const s of chain) {
|
|
720
|
+
const stepAgents = isParallelStep(s)
|
|
721
|
+
? s.parallel.map((t) => t.agent)
|
|
722
|
+
: isDynamicParallelStep(s)
|
|
723
|
+
? [s.parallel.agent]
|
|
724
|
+
: [s.agent];
|
|
725
|
+
for (const agentName of stepAgents) {
|
|
726
|
+
if (!agents.find((x) => x.name === agentName))
|
|
727
|
+
return { error: formatUnknownAgentError(agentName, diagnosticContext) };
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
const graphSteps = projectChainOutputSchemas(graphChain, agents);
|
|
731
|
+
const workflowGraph = buildWorkflowGraphSnapshot({ runId: id, mode: resultMode, steps: graphSteps });
|
|
732
|
+
let progressInstructionCreated = false;
|
|
733
|
+
const buildStepOverrides = (s) => {
|
|
734
|
+
const stepSkillInput = normalizeSkillInput(s.skill);
|
|
735
|
+
return {
|
|
736
|
+
...(s.output !== undefined ? { output: s.output } : {}),
|
|
737
|
+
...(s.outputMode !== undefined ? { outputMode: s.outputMode } : {}),
|
|
738
|
+
...(s.reads !== undefined ? { reads: s.reads } : {}),
|
|
739
|
+
...(s.progress !== undefined ? { progress: s.progress } : {}),
|
|
740
|
+
...(stepSkillInput !== undefined ? { skills: stepSkillInput } : {}),
|
|
741
|
+
...(s.model !== undefined ? { model: s.model } : {}),
|
|
742
|
+
...(s.fast !== undefined ? { fast: s.fast } : {}),
|
|
743
|
+
...(s.outputSchema !== undefined ? { outputSchema: s.outputSchema } : {}),
|
|
744
|
+
};
|
|
745
|
+
};
|
|
746
|
+
const buildSeqStep = (s, sessionFile, behaviorCwd, progressPrecreated = false, resolvedBehavior, flatIndex, parallelOutputNamespace, runFanoutPath) => {
|
|
747
|
+
const a = agents.find((x) => x.name === s.agent);
|
|
748
|
+
const effectiveBehavior = resolvedBehavior ?? suppressProgressForReadOnlyTask(resolveStepBehavior(a, buildStepOverrides(s), chainSkills), s.task, originalTask);
|
|
749
|
+
const requestedMachine = s.machine ?? launchMachine ?? a.machine;
|
|
750
|
+
const externalRunner = a.runner?.type === "external-cli" || a.runner?.type === "external-job";
|
|
751
|
+
const externalRunnerType = a.runner?.type;
|
|
752
|
+
const machineUnsupported = formatHerdrMachineRunnerUnsupported({ machine: requestedMachine, agentName: a.name, runnerType: a.runner?.type, adapter: a.runner?.type === "external-cli" ? a.runner.adapter : undefined, worktree: s.worktree });
|
|
753
|
+
if (machineUnsupported)
|
|
754
|
+
throw new AsyncStartValidationError(machineUnsupported);
|
|
755
|
+
let machine;
|
|
756
|
+
let machineEnv;
|
|
757
|
+
if (requestedMachine) {
|
|
758
|
+
try {
|
|
759
|
+
const placement = resolveHerdrMachinePlacement({ machine: requestedMachine, cwd: runnerCwd, stepCwd: s.cwd ?? params.machineCwd });
|
|
760
|
+
machine = placement.machine;
|
|
761
|
+
machineEnv = placement.env;
|
|
762
|
+
}
|
|
763
|
+
catch (error) {
|
|
764
|
+
throw new AsyncStartValidationError(error instanceof Error ? error.message : String(error));
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
if (externalRunner) {
|
|
768
|
+
const unsupported = [];
|
|
769
|
+
if (s.model !== undefined)
|
|
770
|
+
unsupported.push("model override");
|
|
771
|
+
if (effectiveBehavior.outputSchema !== undefined)
|
|
772
|
+
unsupported.push("structured output");
|
|
773
|
+
if (s.acceptance !== undefined || params.agentContract !== undefined || s.agentContract !== undefined)
|
|
774
|
+
unsupported.push("acceptance/agent contract");
|
|
775
|
+
if (s.toolBudget !== undefined || params.toolBudget !== undefined || a.toolBudget !== undefined || params.configToolBudget !== undefined)
|
|
776
|
+
unsupported.push("tool budget");
|
|
777
|
+
if ((s.fast ?? params.fast ?? a.fast) === true)
|
|
778
|
+
unsupported.push("fast mode");
|
|
779
|
+
if (params.contextForAgent?.(s.agent) === "fork")
|
|
780
|
+
unsupported.push("fork context");
|
|
781
|
+
if (unsupported.length > 0)
|
|
782
|
+
throw new AsyncStartValidationError(`Agent '${a.name}' uses runner.type='${externalRunnerType}' and does not support: ${unsupported.join(", ")}.`);
|
|
783
|
+
}
|
|
784
|
+
try {
|
|
785
|
+
assertAgentAllowedByCapabilityCeiling(a.name, intersectSubagentCapabilityCeilings(params.capabilityCeiling, ctx.childRuntime?.capabilityCeiling));
|
|
786
|
+
}
|
|
787
|
+
catch (error) {
|
|
788
|
+
throw new AsyncStartValidationError(error instanceof Error ? error.message : String(error));
|
|
789
|
+
}
|
|
790
|
+
const toolBudgetInput = s.toolBudget ?? params.toolBudget ?? a.toolBudget ?? params.configToolBudget;
|
|
791
|
+
const resolvedToolBudget = validateToolBudgetConfig(toolBudgetInput, s.toolBudget ? "toolBudget" : a.toolBudget ? "agent.toolBudget" : "config.toolBudget");
|
|
792
|
+
if (resolvedToolBudget.error)
|
|
793
|
+
throw new AsyncStartValidationError(resolvedToolBudget.error);
|
|
794
|
+
const resolvedToolTimeout = resolveToolTimeoutMs({
|
|
795
|
+
callValue: params.callToolTimeoutMs,
|
|
796
|
+
agentValue: a.defaultToolTimeoutMs,
|
|
797
|
+
configValue: params.configToolTimeoutMs,
|
|
798
|
+
envValue: params.toolTimeoutMsEnv ?? toolTimeoutFromEnv(),
|
|
799
|
+
});
|
|
800
|
+
if (resolvedToolTimeout.error)
|
|
801
|
+
throw new AsyncStartValidationError(resolvedToolTimeout.error);
|
|
802
|
+
const launchPlan = planChildLaunch({
|
|
803
|
+
agentConfig: a,
|
|
804
|
+
stepOverrides: buildStepOverrides(s),
|
|
805
|
+
task: s.task,
|
|
806
|
+
originalTask,
|
|
807
|
+
runnerCwd,
|
|
808
|
+
runtimeCwd: ctx.cwd,
|
|
809
|
+
stepCwdInput: s.cwd,
|
|
810
|
+
behaviorCwd,
|
|
811
|
+
...(machine ? { machineCwd: machine.cwd } : {}),
|
|
812
|
+
chainSkills,
|
|
813
|
+
outputBaseDir,
|
|
814
|
+
parallelOutputNamespace,
|
|
815
|
+
resolvedBehavior: effectiveBehavior,
|
|
816
|
+
});
|
|
817
|
+
const { stepCwd, instructionCwd, readExistenceCwd, behavior, namespaceOutputPath, outputPath, skillNames } = launchPlan;
|
|
818
|
+
const { resolved: resolvedSkills, missing: missingSkills } = resolveSkillsWithFallback(skillNames, stepCwd, ctx.cwd, a.skillPath, a.filePath ? path.dirname(a.filePath) : stepCwd);
|
|
819
|
+
if (missingSkills.includes("pi-subagents"))
|
|
820
|
+
throw new UnavailableSubagentSkillError(UNAVAILABLE_SUBAGENT_SKILL_ERROR);
|
|
821
|
+
// A namespaced parallel output is injected by the runner, not the prompt.
|
|
822
|
+
const systemPrompt = buildEffectiveSystemPrompt({ agent: a, resolvedSkills, cwd: stepCwd, ...(!namespaceOutputPath && outputPath ? { outputPath } : {}) });
|
|
823
|
+
const readInstructions = buildChainInstructions({ ...behavior, output: false, progress: false }, instructionCwd, false, undefined, readExistenceCwd);
|
|
824
|
+
const isFirstProgressAgent = behavior.progress && !progressPrecreated && !progressInstructionCreated;
|
|
825
|
+
if (behavior.progress)
|
|
826
|
+
progressInstructionCreated = true;
|
|
827
|
+
const progressInstructions = buildChainInstructions({ ...behavior, output: false, reads: false }, progressDir, isFirstProgressAgent);
|
|
828
|
+
const validationError = validateFileOnlyOutputMode(behavior.outputMode, outputPath, `Async step (${s.agent})`);
|
|
829
|
+
if (validationError)
|
|
830
|
+
throw new AsyncStartValidationError(validationError);
|
|
831
|
+
let taskTemplate = s.task ?? "{previous}";
|
|
832
|
+
taskTemplate = taskTemplate.replace(/\{task\}/g, originalTask ?? "");
|
|
833
|
+
taskTemplate = taskTemplate.replace(/\{chain_dir\}/g, behaviorCwd ?? runnerCwd);
|
|
834
|
+
const taskText = `${readInstructions.prefix}${taskTemplate}${progressInstructions.suffix}`;
|
|
835
|
+
const task = namespaceOutputPath ? taskText : injectSingleOutputInstruction(taskText, outputPath, a);
|
|
836
|
+
const modelScopes = resolveModelScopesForAgent(ctx.modelScope, a.name, ctx.currentModel);
|
|
837
|
+
const modelOrigin = resolveModelOrigin({ explicitModel: s.model, agentModel: a.model, parentModel: ctx.currentModel });
|
|
838
|
+
const primaryModelFromParent = modelOrigin === "inherited";
|
|
839
|
+
const primaryModel = externalRunner ? undefined : resolveEffectiveSubagentModel(s.model, a.model, ctx.currentModel, availableModels, a.modelProvider ?? ctx.currentModelProvider, { scope: modelScopes, source: modelOrigin === "explicit" ? "explicit" : "inherited" });
|
|
840
|
+
const thinkingOverride = flatIndex === undefined ? undefined : thinkingOverridesByFlatIndex?.[flatIndex];
|
|
841
|
+
const effectiveThinking = externalRunner ? undefined : thinkingOverride ?? a.thinking;
|
|
842
|
+
const model = externalRunner ? undefined : applyThinkingSuffix(primaryModel, effectiveThinking, thinkingOverride !== undefined);
|
|
843
|
+
const contextLimit = model ? findModelInfo(model, availableModels, a.modelProvider ?? ctx.currentModelProvider)?.contextWindow : undefined;
|
|
844
|
+
const thinkingCeiling = externalRunner ? undefined : intersectThinkingCeilings(params.thinkingCeiling, a.maxThinking, ctx.childRuntime?.thinkingCeiling);
|
|
845
|
+
if (!externalRunner) {
|
|
846
|
+
try {
|
|
847
|
+
assertThinkingWithinCeiling({ model, configThinking: effectiveThinking, ceiling: thinkingCeiling, agent: a.name, runId: id });
|
|
848
|
+
}
|
|
849
|
+
catch (error) {
|
|
850
|
+
throw new AsyncStartValidationError(error instanceof Error ? error.message : String(error));
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
const agentContract = s.agentContract ?? params.agentContract;
|
|
854
|
+
const permissionRules = resolvePermissionRules(ctx.permissions, a.permissions);
|
|
855
|
+
let selectedModel = model;
|
|
856
|
+
let requestedModel;
|
|
857
|
+
if (!externalRunner) {
|
|
858
|
+
try {
|
|
859
|
+
const modelEvidence = resolveModelSelection(primaryModel, availableModels, a.modelProvider ?? ctx.currentModelProvider, {
|
|
860
|
+
scope: modelScopes,
|
|
861
|
+
primaryModelFromParent,
|
|
862
|
+
origin: modelOrigin,
|
|
863
|
+
});
|
|
864
|
+
requestedModel = modelEvidence.requestedModel;
|
|
865
|
+
selectedModel = applyThinkingSuffix(modelEvidence.model, effectiveThinking, thinkingOverride !== undefined);
|
|
866
|
+
assertThinkingWithinCeiling({ model: selectedModel, configThinking: effectiveThinking, ceiling: thinkingCeiling, agent: a.name, runId: id });
|
|
867
|
+
}
|
|
868
|
+
catch (error) {
|
|
869
|
+
throw new AsyncStartValidationError(error instanceof Error ? error.message : String(error));
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
const launchRuleError = applyWatchdogLaunchRules({ cwd: machine ? runnerCwd : stepCwd, agent: a.name, model: selectedModel, warn: (violation) => sendRuleViolationWarning(ctx.pi, violation) });
|
|
873
|
+
if (launchRuleError)
|
|
874
|
+
throw new AsyncStartValidationError(launchRuleError);
|
|
875
|
+
const fast = s.fast ?? params.fast ?? a.fast;
|
|
876
|
+
const requiredExtensions = externalRunner ? [] : ctx.childRuntime?.requiredExtensions ?? resolveRequiredChildExtensions(ctx.parentSessionId ?? ctx.currentSessionId ?? undefined);
|
|
877
|
+
const toolPlan = resolvePiLaunchToolPlan({
|
|
878
|
+
tools: a.tools,
|
|
879
|
+
excludeTools: a.excludeTools,
|
|
880
|
+
allowNestedSubagents: a.allowNestedSubagents,
|
|
881
|
+
extensions: a.extensions,
|
|
882
|
+
subagentOnlyExtensions: a.subagentOnlyExtensions,
|
|
883
|
+
requiredExtensions,
|
|
884
|
+
mcpDirectTools: a.mcpDirectTools,
|
|
885
|
+
cwd: stepCwd,
|
|
886
|
+
requireReadTool: Boolean(resolvedSkills.length),
|
|
887
|
+
structuredOutput: Boolean(behavior.outputSchema),
|
|
888
|
+
fast,
|
|
889
|
+
model: selectedModel,
|
|
890
|
+
capabilityCeiling: params.capabilityCeiling,
|
|
891
|
+
inheritedCapabilityCeiling: ctx.childRuntime?.capabilityCeiling,
|
|
892
|
+
agentName: a.name,
|
|
893
|
+
permissionRules,
|
|
894
|
+
runtimeSnapshotHost: ctx.pi,
|
|
895
|
+
});
|
|
896
|
+
const launchResolvedExtensions = externalRunner ? undefined : projectLaunchResolvedChildExtensions(toolPlan);
|
|
897
|
+
if (externalRunner && permissionRules) {
|
|
898
|
+
throw new AsyncStartValidationError(`Agent '${a.name}' uses runner.type='${externalRunnerType}', which cannot enforce native Pi child permission rules.`);
|
|
899
|
+
}
|
|
900
|
+
if (!externalRunner) {
|
|
901
|
+
const contractTools = toolPlan.explicitToolAllowlist ? toolPlan.effectiveToolAllowlist : undefined;
|
|
902
|
+
const contractError = validateImplementationToolContract({
|
|
903
|
+
agent: a.name,
|
|
904
|
+
task,
|
|
905
|
+
tools: contractTools,
|
|
906
|
+
mcpDirectTools: toolPlan.effectiveMcpTools,
|
|
907
|
+
configuredExtensions: toolPlan.configuredExtensions,
|
|
908
|
+
requestedTools: toolPlan.requestedBuiltinTools,
|
|
909
|
+
acceptanceRole: a.acceptanceRole,
|
|
910
|
+
completionGuard: a.completionGuard,
|
|
911
|
+
});
|
|
912
|
+
if (contractError)
|
|
913
|
+
throw new AsyncStartValidationError(contractError);
|
|
914
|
+
}
|
|
915
|
+
return {
|
|
916
|
+
parentSessionId: launchParentSessionId,
|
|
917
|
+
permissionRules,
|
|
918
|
+
...(params.capabilityCeiling ? { capabilityCeiling: params.capabilityCeiling } : {}),
|
|
919
|
+
...(runFanoutPath ? { runFanoutPath } : {}),
|
|
920
|
+
agent: s.agent,
|
|
921
|
+
task,
|
|
922
|
+
...(a.runner ? { runner: a.runner } : {}),
|
|
923
|
+
...(machine ? { machine } : {}),
|
|
924
|
+
...(machineEnv ? { machineEnv } : {}),
|
|
925
|
+
...(params.contextForAgent ? { context: params.contextForAgent(s.agent) } : {}),
|
|
926
|
+
...(agentContract ? { agentContract } : {}),
|
|
927
|
+
phase: s.phase,
|
|
928
|
+
label: s.label,
|
|
929
|
+
outputName: s.as,
|
|
930
|
+
structured: Boolean(behavior.outputSchema),
|
|
931
|
+
cwd: stepCwd,
|
|
932
|
+
requestedCwd: machine ? machine.cwd : s.cwd ?? stepCwd,
|
|
933
|
+
model: selectedModel,
|
|
934
|
+
...(contextLimit !== undefined ? { contextLimit } : {}),
|
|
935
|
+
...(fast !== undefined ? { fast } : {}),
|
|
936
|
+
thinking: resolveEffectiveThinking(selectedModel, effectiveThinking),
|
|
937
|
+
...(thinkingCeiling ? { thinkingCeiling } : {}),
|
|
938
|
+
launchResolvedExtensions,
|
|
939
|
+
...(requestedModel ? { requestedModel } : {}),
|
|
940
|
+
...(primaryModelFromParent ? { skipPrimaryModelVerification: true } : {}),
|
|
941
|
+
...(availableModels && availableModels.length > 0 ? { modelVerificationRegistry: availableModels } : {}),
|
|
942
|
+
...(ctx.modelResponseAliases ? { modelResponseAliases: ctx.modelResponseAliases } : {}),
|
|
943
|
+
tools: a.tools,
|
|
944
|
+
excludeTools: a.excludeTools,
|
|
945
|
+
allowNestedSubagents: a.allowNestedSubagents,
|
|
946
|
+
allowedAgents: a.allowedAgents,
|
|
947
|
+
extensions: a.extensions,
|
|
948
|
+
subagentOnlyExtensions: a.subagentOnlyExtensions,
|
|
949
|
+
...(!externalRunner ? { requiredExtensions } : {}),
|
|
950
|
+
mcpDirectTools: a.mcpDirectTools,
|
|
951
|
+
mutationTools: a.mutationTools,
|
|
952
|
+
completionGuard: a.completionGuard,
|
|
953
|
+
systemPrompt,
|
|
954
|
+
systemPromptMode: a.systemPromptMode,
|
|
955
|
+
inheritProjectContext: a.inheritProjectContext,
|
|
956
|
+
inheritGlobalContext: a.inheritGlobalContext,
|
|
957
|
+
inheritSkills: a.inheritSkills,
|
|
958
|
+
skills: resolvedSkills.map((r) => r.name),
|
|
959
|
+
outputPath,
|
|
960
|
+
...(namespaceOutputPath ? { namespaceOutputPath: true } : {}),
|
|
961
|
+
outputMode: behavior.outputMode,
|
|
962
|
+
sessionFile,
|
|
963
|
+
maxSubagentDepth: resolveChildMaxSubagentDepth(maxSubagentDepth, a.maxSubagentDepth),
|
|
964
|
+
timeoutMs: a.defaultTimeoutMs ?? DEFAULT_ASYNC_TIMEOUT_MS,
|
|
965
|
+
toolTimeoutMs: resolvedToolTimeout.toolTimeoutMs,
|
|
966
|
+
waitToolEnabled: params.waitToolEnabled,
|
|
967
|
+
waitToolDefaultTimeoutMs: params.waitToolDefaultTimeoutMs,
|
|
968
|
+
effectiveAcceptance: resolveEffectiveAcceptance({
|
|
969
|
+
explicit: s.acceptance,
|
|
970
|
+
agentName: s.agent,
|
|
971
|
+
acceptanceRole: a.acceptanceRole,
|
|
972
|
+
task,
|
|
973
|
+
mode: resultMode,
|
|
974
|
+
async: true,
|
|
975
|
+
dynamic: false,
|
|
976
|
+
agentContract,
|
|
977
|
+
}),
|
|
978
|
+
acceptanceInput: s.acceptance,
|
|
979
|
+
acceptanceRole: a.acceptanceRole,
|
|
980
|
+
...(s.gateOn ? { gateOn: s.gateOn } : {}),
|
|
981
|
+
...(behavior.outputSchema ? { structuredOutputSchema: behavior.outputSchema } : {}),
|
|
982
|
+
...(behavior.outputSchema ? { structuredOutput: createStructuredOutputRuntime(behavior.outputSchema, path.join(asyncDir, "structured-output"), { acceptanceReport: resolveAcceptanceReportMode(s.acceptance) }) } : {}),
|
|
983
|
+
...(resolvedToolBudget.budget ? { toolBudget: resolvedToolBudget.budget } : {}),
|
|
984
|
+
...(s.worktree ? { worktree: true } : {}),
|
|
985
|
+
};
|
|
986
|
+
};
|
|
987
|
+
let flatStepIndex = 0;
|
|
988
|
+
const nextFlatStep = () => {
|
|
989
|
+
const index = flatStepIndex;
|
|
990
|
+
const sessionFile = sessionFilesByFlatIndex?.[flatStepIndex];
|
|
991
|
+
const thinkingOverride = thinkingOverridesByFlatIndex?.[flatStepIndex];
|
|
992
|
+
flatStepIndex++;
|
|
993
|
+
return {
|
|
994
|
+
index,
|
|
995
|
+
...(sessionFile ? { sessionFile } : {}),
|
|
996
|
+
...(thinkingOverride ? { thinkingOverride } : {}),
|
|
997
|
+
};
|
|
998
|
+
};
|
|
999
|
+
try {
|
|
1000
|
+
const builtSteps = chain.map((s, stepIndex) => {
|
|
1001
|
+
if (isParallelStep(s)) {
|
|
1002
|
+
const parallelBehaviors = s.parallel.map((task) => {
|
|
1003
|
+
const agent = agents.find((candidate) => candidate.name === task.agent);
|
|
1004
|
+
return suppressProgressForReadOnlyTask(resolveStepBehavior(agent, buildStepOverrides(task), chainSkills), task.task, originalTask);
|
|
1005
|
+
});
|
|
1006
|
+
const progressPrecreated = parallelBehaviors.some((behavior) => behavior.progress);
|
|
1007
|
+
if (progressPrecreated) {
|
|
1008
|
+
if (!s.worktree || params.progressDir)
|
|
1009
|
+
writeInitialProgressFile(progressDir);
|
|
1010
|
+
progressInstructionCreated = true;
|
|
1011
|
+
}
|
|
1012
|
+
return {
|
|
1013
|
+
parallel: s.parallel.map((t, taskIndex) => {
|
|
1014
|
+
let behaviorCwd;
|
|
1015
|
+
if (s.worktree && managedWorktreeProvider === "worktrunk") {
|
|
1016
|
+
behaviorCwd = WORKTREE_AGENT_CWD_PLACEHOLDER;
|
|
1017
|
+
}
|
|
1018
|
+
else if (s.worktree && managedWorktreeProvider === "native") {
|
|
1019
|
+
try {
|
|
1020
|
+
behaviorCwd = resolveExpectedWorktreeAgentCwd(runnerCwd, `${id}-s${stepIndex}`, taskIndex, worktreeBaseDir);
|
|
1021
|
+
}
|
|
1022
|
+
catch {
|
|
1023
|
+
behaviorCwd = undefined;
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
const staticStep = nextFlatStep();
|
|
1027
|
+
return buildSeqStep({ ...t, machine: t.machine ?? s.machine, worktree: s.worktree, agentContract: t.agentContract ?? s.agentContract, gateOn: t.gateOn ?? s.gateOn }, staticStep.sessionFile, behaviorCwd, progressPrecreated, parallelBehaviors[taskIndex], staticStep.index, { stepIndex, taskIndex }, resultMode === "parallel" ? `tasks[${taskIndex}]` : `chain[${stepIndex}].parallel[${taskIndex}]`);
|
|
1028
|
+
}),
|
|
1029
|
+
concurrency: s.concurrency,
|
|
1030
|
+
failFast: s.failFast,
|
|
1031
|
+
worktree: s.worktree,
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
if (isDynamicParallelStep(s)) {
|
|
1035
|
+
const agent = agents.find((candidate) => candidate.name === s.parallel.agent);
|
|
1036
|
+
const behavior = suppressProgressForReadOnlyTask(resolveStepBehavior(agent, buildStepOverrides(s.parallel), chainSkills), s.parallel.task, originalTask);
|
|
1037
|
+
const progressPrecreated = behavior.progress;
|
|
1038
|
+
if (progressPrecreated) {
|
|
1039
|
+
writeInitialProgressFile(progressDir);
|
|
1040
|
+
progressInstructionCreated = true;
|
|
1041
|
+
}
|
|
1042
|
+
const maxItems = s.expand.maxItems ?? params.dynamicFanoutMaxItems ?? 0;
|
|
1043
|
+
const dynamicFlatSteps = Array.from({ length: maxItems }, () => nextFlatStep());
|
|
1044
|
+
const parallel = buildSeqStep({ ...s.parallel, agentContract: s.parallel.agentContract ?? s.agentContract, gateOn: s.parallel.gateOn ?? s.gateOn }, undefined, undefined, progressPrecreated, behavior, undefined, { stepIndex });
|
|
1045
|
+
return {
|
|
1046
|
+
expand: s.expand,
|
|
1047
|
+
parallel,
|
|
1048
|
+
collect: s.collect,
|
|
1049
|
+
concurrency: s.concurrency,
|
|
1050
|
+
failFast: s.failFast,
|
|
1051
|
+
phase: s.phase,
|
|
1052
|
+
label: s.label,
|
|
1053
|
+
sessionFiles: dynamicFlatSteps.map((step) => step.sessionFile),
|
|
1054
|
+
thinkingOverrides: dynamicFlatSteps.map((step) => step.thinkingOverride),
|
|
1055
|
+
effectiveAcceptance: resolveEffectiveAcceptance({
|
|
1056
|
+
explicit: s.acceptance,
|
|
1057
|
+
agentName: s.parallel.agent,
|
|
1058
|
+
acceptanceRole: agent.acceptanceRole,
|
|
1059
|
+
task: parallel.task,
|
|
1060
|
+
mode: resultMode,
|
|
1061
|
+
async: true,
|
|
1062
|
+
dynamicGroup: true,
|
|
1063
|
+
agentContract: s.agentContract ?? params.agentContract,
|
|
1064
|
+
}),
|
|
1065
|
+
acceptanceInput: s.acceptance,
|
|
1066
|
+
acceptanceRole: agent.acceptanceRole,
|
|
1067
|
+
...(s.agentContract ?? params.agentContract ? { agentContract: s.agentContract ?? params.agentContract } : {}),
|
|
1068
|
+
...(s.gateOn ? { gateOn: s.gateOn } : {}),
|
|
1069
|
+
...(parallel.thinkingCeiling ? { thinkingCeiling: parallel.thinkingCeiling } : {}),
|
|
1070
|
+
};
|
|
1071
|
+
}
|
|
1072
|
+
const sequential = s;
|
|
1073
|
+
let behaviorCwd;
|
|
1074
|
+
if (sequential.worktree && managedWorktreeProvider === "worktrunk") {
|
|
1075
|
+
behaviorCwd = WORKTREE_AGENT_CWD_PLACEHOLDER;
|
|
1076
|
+
}
|
|
1077
|
+
else if (sequential.worktree && managedWorktreeProvider === "native") {
|
|
1078
|
+
try {
|
|
1079
|
+
behaviorCwd = resolveExpectedWorktreeAgentCwd(runnerCwd, `${id}-s${stepIndex}`, 0, worktreeBaseDir);
|
|
1080
|
+
}
|
|
1081
|
+
catch {
|
|
1082
|
+
behaviorCwd = undefined;
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
const staticStep = nextFlatStep();
|
|
1086
|
+
return buildSeqStep(sequential, staticStep.sessionFile, behaviorCwd, false, undefined, staticStep.index, undefined, `chain[${stepIndex}]`);
|
|
1087
|
+
});
|
|
1088
|
+
const steps = params.attachRoot
|
|
1089
|
+
? [{
|
|
1090
|
+
parentSessionId: launchParentSessionId,
|
|
1091
|
+
agent: params.attachRoot.agent,
|
|
1092
|
+
task: "",
|
|
1093
|
+
label: params.attachRoot.label ?? `Attached root ${params.attachRoot.runId}`,
|
|
1094
|
+
outputName: params.attachRoot.outputName,
|
|
1095
|
+
importAsyncRoot: {
|
|
1096
|
+
runId: params.attachRoot.runId,
|
|
1097
|
+
asyncDir: params.attachRoot.asyncDir,
|
|
1098
|
+
resultPath: params.attachRoot.resultPath,
|
|
1099
|
+
index: params.attachRoot.index,
|
|
1100
|
+
},
|
|
1101
|
+
inheritProjectContext: false,
|
|
1102
|
+
inheritGlobalContext: false,
|
|
1103
|
+
inheritSkills: false,
|
|
1104
|
+
}, ...builtSteps]
|
|
1105
|
+
: builtSteps;
|
|
1106
|
+
for (const step of steps) {
|
|
1107
|
+
if (!("parallel" in step) || !Array.isArray(step.parallel))
|
|
1108
|
+
continue;
|
|
1109
|
+
const seen = new Map();
|
|
1110
|
+
for (let index = 0; index < step.parallel.length; index++) {
|
|
1111
|
+
const task = step.parallel[index];
|
|
1112
|
+
if (!task.outputPath)
|
|
1113
|
+
continue;
|
|
1114
|
+
const previous = seen.get(task.outputPath);
|
|
1115
|
+
if (previous) {
|
|
1116
|
+
throw new AsyncStartValidationError(`Parallel tasks ${previous.index + 1} (${previous.agent}) and ${index + 1} (${task.agent}) resolve output to the same path: ${task.outputPath}. Use distinct output paths.`);
|
|
1117
|
+
}
|
|
1118
|
+
seen.set(task.outputPath, { index, agent: task.agent });
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
return { steps: steps, runnerCwd, workflowGraph, eventChain: graphChain, ...(originalTask !== undefined ? { originalTask } : {}) };
|
|
1122
|
+
}
|
|
1123
|
+
catch (error) {
|
|
1124
|
+
if (error instanceof UnavailableSubagentSkillError || error instanceof AsyncStartValidationError)
|
|
1125
|
+
return { error: error.message };
|
|
1126
|
+
throw error;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Execute a chain asynchronously
|
|
1131
|
+
*/
|
|
1132
|
+
export function executeAsyncChain(id, params) {
|
|
1133
|
+
const { chain, agents, ctx, cwd, maxOutput, artifactsDir, artifactConfig, shareEnabled, sessionRoot, sessionFilesByFlatIndex, thinkingOverridesByFlatIndex, maxSubagentDepth, worktreeSetupHook, worktreeSetupHookTimeoutMs, worktreeBaseDir, baseRef, worktreeProvider, worktreeBranchPrefix, controlConfig, controlIntercomTarget, childIntercomTarget, nestedRoute, } = params;
|
|
1134
|
+
const resultMode = params.resultMode ?? "chain";
|
|
1135
|
+
const acceptanceErrors = validateExecutionAcceptance({
|
|
1136
|
+
chain: projectChainOutputSchemas(chain, agents, (step, outputSchema) => ({ acceptance: step.acceptance, outputSchema }), (step, parallel) => Array.isArray(step.parallel) ? { parallel } : { acceptance: "acceptance" in step ? step.acceptance : undefined, parallel }),
|
|
1137
|
+
});
|
|
1138
|
+
if (acceptanceErrors.length > 0)
|
|
1139
|
+
return formatAsyncStartError(resultMode, acceptanceErrors.join(" "));
|
|
1140
|
+
const capabilityCeiling = params.capabilityCeiling ?? resolveCurrentSubagentCapabilityCeiling(ctx.currentSessionId);
|
|
1141
|
+
const inheritedNestedRoute = inheritedNestedRouteOf(ctx.childRuntime);
|
|
1142
|
+
const nestedAddress = inheritedNestedRoute ? inheritedNestedParentAddressOf(ctx.childRuntime) : undefined;
|
|
1143
|
+
const asyncDir = inheritedNestedRoute
|
|
1144
|
+
? path.join(TEMP_ROOT_DIR, "nested-subagent-runs", inheritedNestedRoute.rootRunId, id)
|
|
1145
|
+
: path.join(DIRS.async, id);
|
|
1146
|
+
let runFanoutBudget;
|
|
1147
|
+
try {
|
|
1148
|
+
runFanoutBudget = params.runFanoutBudget ?? createRunFanoutBudget(id, 64);
|
|
1149
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
1150
|
+
writeRunFanoutBudgetDescriptor(asyncDir, runFanoutBudget);
|
|
1151
|
+
}
|
|
1152
|
+
catch (error) {
|
|
1153
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1154
|
+
return {
|
|
1155
|
+
content: [{ type: "text", text: `Failed to create async run directory '${asyncDir}': ${message}` }],
|
|
1156
|
+
isError: true,
|
|
1157
|
+
details: { mode: resultMode, results: [] },
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
const built = buildAsyncRunnerSteps(id, {
|
|
1161
|
+
chain,
|
|
1162
|
+
task: params.task,
|
|
1163
|
+
attachRoot: params.attachRoot,
|
|
1164
|
+
resultMode,
|
|
1165
|
+
agents,
|
|
1166
|
+
unknownAgentDiagnosticContext: params.unknownAgentDiagnosticContext,
|
|
1167
|
+
ctx,
|
|
1168
|
+
availableModels: params.availableModels,
|
|
1169
|
+
cwd,
|
|
1170
|
+
chainSkills: params.chainSkills,
|
|
1171
|
+
machine: params.machine,
|
|
1172
|
+
machineCwd: params.machineCwd,
|
|
1173
|
+
sessionFilesByFlatIndex,
|
|
1174
|
+
thinkingOverridesByFlatIndex,
|
|
1175
|
+
contextForAgent: params.contextForAgent,
|
|
1176
|
+
progressDir: params.progressDir ?? (artifactsDir ? path.join(artifactsDir, "progress", id) : resultMode === "parallel" ? path.join(asyncDir, "progress") : undefined),
|
|
1177
|
+
agentContract: params.agentContract,
|
|
1178
|
+
outputBaseDir: artifactsDir ? path.join(artifactsDir, "outputs", id) : undefined,
|
|
1179
|
+
dynamicFanoutMaxItems: params.dynamicFanoutMaxItems,
|
|
1180
|
+
maxSubagentDepth,
|
|
1181
|
+
waitToolEnabled: params.waitToolEnabled,
|
|
1182
|
+
waitToolDefaultTimeoutMs: params.waitToolDefaultTimeoutMs,
|
|
1183
|
+
worktreeBaseDir,
|
|
1184
|
+
worktreeProvider,
|
|
1185
|
+
worktreeBranchPrefix,
|
|
1186
|
+
asyncDir,
|
|
1187
|
+
fast: params.fast,
|
|
1188
|
+
toolBudget: params.toolBudget,
|
|
1189
|
+
configToolBudget: params.configToolBudget,
|
|
1190
|
+
callToolTimeoutMs: params.callToolTimeoutMs,
|
|
1191
|
+
configToolTimeoutMs: params.configToolTimeoutMs,
|
|
1192
|
+
toolTimeoutMsEnv: params.toolTimeoutMsEnv ?? toolTimeoutFromEnv(),
|
|
1193
|
+
capabilityCeiling,
|
|
1194
|
+
thinkingCeiling: params.thinkingCeiling,
|
|
1195
|
+
});
|
|
1196
|
+
if ("error" in built) {
|
|
1197
|
+
try {
|
|
1198
|
+
fs.rmSync(asyncDir, { recursive: true, force: true });
|
|
1199
|
+
}
|
|
1200
|
+
catch {
|
|
1201
|
+
// Best-effort cleanup for validation failures before the runner is spawned.
|
|
1202
|
+
}
|
|
1203
|
+
return formatAsyncStartError(resultMode, built.error);
|
|
1204
|
+
}
|
|
1205
|
+
const { steps, runnerCwd, workflowGraph, eventChain } = built;
|
|
1206
|
+
const deadlineAt = params.timeoutMs !== undefined ? Date.now() + params.timeoutMs : undefined;
|
|
1207
|
+
const initialUsageBudget = usageBudgetState(params.usageBudget, undefined);
|
|
1208
|
+
let childTargetIndex = 0;
|
|
1209
|
+
const childIntercomTargets = childIntercomTarget ? steps.flatMap((step) => {
|
|
1210
|
+
if (!("parallel" in step) && "importAsyncRoot" in step && step.importAsyncRoot) {
|
|
1211
|
+
childTargetIndex++;
|
|
1212
|
+
return [undefined];
|
|
1213
|
+
}
|
|
1214
|
+
if ("parallel" in step) {
|
|
1215
|
+
if (!Array.isArray(step.parallel)) {
|
|
1216
|
+
childTargetIndex++;
|
|
1217
|
+
return [undefined];
|
|
1218
|
+
}
|
|
1219
|
+
return step.parallel.map((task) => childIntercomTarget(task.agent, childTargetIndex++));
|
|
1220
|
+
}
|
|
1221
|
+
return "agent" in step ? [childIntercomTarget(step.agent, childTargetIndex++)] : [undefined];
|
|
1222
|
+
}) : undefined;
|
|
1223
|
+
const initialStatusSteps = eventChain.flatMap((step) => isParallelStep(step)
|
|
1224
|
+
? step.parallel.map((task) => ({ agent: task.agent, ...(statusStepDescription(task.task) ? { description: statusStepDescription(task.task) } : {}), ...(task.label ? { label: task.label } : {}), ...(task.as ? { outputName: task.as } : {}), status: "pending" }))
|
|
1225
|
+
: isDynamicParallelStep(step)
|
|
1226
|
+
? [{ agent: `expand:${step.parallel.agent}`, label: step.label ?? step.parallel.label ?? `Dynamic fanout (${step.collect.as})`, outputName: step.collect.as, status: "pending" }]
|
|
1227
|
+
: [{ agent: step.agent, ...(statusStepDescription(step.task) ? { description: statusStepDescription(step.task) } : {}), ...(step.label ? { label: step.label } : {}), ...(step.as ? { outputName: step.as } : {}), status: "pending" }]);
|
|
1228
|
+
const initialParallelGroups = [];
|
|
1229
|
+
let initialFlatIndex = 0;
|
|
1230
|
+
for (let stepIndex = 0; stepIndex < eventChain.length; stepIndex++) {
|
|
1231
|
+
const step = eventChain[stepIndex];
|
|
1232
|
+
if (isParallelStep(step))
|
|
1233
|
+
initialParallelGroups.push({ start: initialFlatIndex, count: step.parallel.length, stepIndex });
|
|
1234
|
+
else if (isDynamicParallelStep(step))
|
|
1235
|
+
initialParallelGroups.push({ start: initialFlatIndex, count: 1, stepIndex });
|
|
1236
|
+
initialFlatIndex += isParallelStep(step) ? step.parallel.length : 1;
|
|
1237
|
+
}
|
|
1238
|
+
const initialStatusAt = Date.now();
|
|
1239
|
+
const initialCompletionOwnerId = ctx.completionOwnerId ?? currentCompletionOwnerId();
|
|
1240
|
+
const launchParentSessionId = ctx.parentSessionId ?? ctx.currentSessionId;
|
|
1241
|
+
let spawnResult = {};
|
|
1242
|
+
try {
|
|
1243
|
+
spawnResult = spawnRunner({
|
|
1244
|
+
id,
|
|
1245
|
+
steps,
|
|
1246
|
+
resultPath: inheritedNestedRoute ? nestedResultsPath(inheritedNestedRoute.rootRunId, id) : resultFilePath(DIRS.results, id),
|
|
1247
|
+
cwd: runnerCwd,
|
|
1248
|
+
placeholder: "{previous}",
|
|
1249
|
+
maxOutput,
|
|
1250
|
+
artifactsDir: artifactConfig.enabled ? artifactsDir : undefined,
|
|
1251
|
+
artifactConfig,
|
|
1252
|
+
share: shareEnabled,
|
|
1253
|
+
sessionDir: sessionRoot ? path.join(sessionRoot, `async-${id}`) : undefined,
|
|
1254
|
+
asyncDir,
|
|
1255
|
+
sessionId: ctx.currentSessionId,
|
|
1256
|
+
completionOwnerId: ctx.completionOwnerId ?? currentCompletionOwnerId(),
|
|
1257
|
+
...(capabilityCeiling ? { capabilityCeiling } : {}),
|
|
1258
|
+
piPackageRoot,
|
|
1259
|
+
childSessionFactoryModule: childSessionFactoryModule(),
|
|
1260
|
+
inheritedChildRuntime: inheritedChildRuntime(ctx.childRuntime),
|
|
1261
|
+
worktreeSetupHook,
|
|
1262
|
+
worktreeSetupHookTimeoutMs,
|
|
1263
|
+
worktreeBaseDir,
|
|
1264
|
+
baseRef,
|
|
1265
|
+
worktreeProvider,
|
|
1266
|
+
worktreeBranchPrefix,
|
|
1267
|
+
controlConfig,
|
|
1268
|
+
toolBudget: params.toolBudget,
|
|
1269
|
+
usageBudget: params.usageBudget,
|
|
1270
|
+
controlIntercomTarget,
|
|
1271
|
+
childIntercomTargets,
|
|
1272
|
+
resultMode,
|
|
1273
|
+
dynamicFanoutMaxItems: params.dynamicFanoutMaxItems,
|
|
1274
|
+
timeoutMs: params.timeoutMs,
|
|
1275
|
+
deadlineAt,
|
|
1276
|
+
globalConcurrencyLimit: params.globalConcurrencyLimit,
|
|
1277
|
+
runFanoutBudget,
|
|
1278
|
+
workflowGraph,
|
|
1279
|
+
...(params.parentWorkflowRunId ? { parentWorkflowRunId: params.parentWorkflowRunId } : {}),
|
|
1280
|
+
...(params.workflowKey ? { workflowKey: params.workflowKey } : {}),
|
|
1281
|
+
nestedRoute: nestedRoute ?? inheritedNestedRoute,
|
|
1282
|
+
nestedSelf: inheritedNestedRoute && nestedAddress ? {
|
|
1283
|
+
parentRunId: nestedAddress.parentRunId,
|
|
1284
|
+
parentStepIndex: nestedAddress.parentStepIndex,
|
|
1285
|
+
depth: nestedAddress.depth,
|
|
1286
|
+
path: nestedAddress.path,
|
|
1287
|
+
} : undefined,
|
|
1288
|
+
}, id, runnerCwd, {
|
|
1289
|
+
lifecycleArtifactVersion: SUBAGENT_LIFECYCLE_ARTIFACT_VERSION,
|
|
1290
|
+
runId: id,
|
|
1291
|
+
...(ctx.currentSessionId ? { sessionId: ctx.currentSessionId } : {}),
|
|
1292
|
+
...(initialCompletionOwnerId ? { completionOwnerId: initialCompletionOwnerId } : {}),
|
|
1293
|
+
mode: resultMode,
|
|
1294
|
+
state: "running",
|
|
1295
|
+
startedAt: initialStatusAt,
|
|
1296
|
+
lastUpdate: initialStatusAt,
|
|
1297
|
+
currentStep: 0,
|
|
1298
|
+
chainStepCount: eventChain.length,
|
|
1299
|
+
...(initialParallelGroups.length ? { parallelGroups: initialParallelGroups } : {}),
|
|
1300
|
+
steps: initialStatusSteps,
|
|
1301
|
+
}, path.join(asyncDir, "status.json"), launchParentSessionId, (proof) => emitProcessTerminalEvent(ctx, proof), (runnerProcessInstanceId) => params.activeAsyncCapacity?.markStarted(runnerProcessInstanceId));
|
|
1302
|
+
}
|
|
1303
|
+
catch (error) {
|
|
1304
|
+
params.activeAsyncCapacity?.rollback();
|
|
1305
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1306
|
+
return formatAsyncStartError(resultMode, `Failed to start async ${resultMode} '${id}': ${message}`);
|
|
1307
|
+
}
|
|
1308
|
+
if (spawnResult.error) {
|
|
1309
|
+
if (spawnResult.startupDidNotProceed) {
|
|
1310
|
+
if (!spawnResult.runnerProcessInstanceId || params.activeAsyncCapacity?.rollbackBeforeRunnerProceed(spawnResult.runnerProcessInstanceId) !== true)
|
|
1311
|
+
params.activeAsyncCapacity?.rollback();
|
|
1312
|
+
}
|
|
1313
|
+
else if (!spawnResult.pid || !spawnResult.runnerProcessInstanceId)
|
|
1314
|
+
params.activeAsyncCapacity?.rollback();
|
|
1315
|
+
else
|
|
1316
|
+
params.activeAsyncCapacity?.markStarted(spawnResult.runnerProcessInstanceId);
|
|
1317
|
+
return formatAsyncStartError(resultMode, `Failed to start async ${resultMode} '${id}': ${spawnResult.error}`);
|
|
1318
|
+
}
|
|
1319
|
+
if (!spawnResult.pid || !spawnResult.runnerProcessInstanceId) {
|
|
1320
|
+
params.activeAsyncCapacity?.rollback();
|
|
1321
|
+
return formatAsyncStartError(resultMode, `Failed to start async ${resultMode} '${id}': runner identity unavailable`);
|
|
1322
|
+
}
|
|
1323
|
+
if (spawnResult.pid) {
|
|
1324
|
+
const eventFirstStep = eventChain[0];
|
|
1325
|
+
if (!eventFirstStep) {
|
|
1326
|
+
return formatAsyncStartError(resultMode, `Failed to start async ${resultMode} '${id}': event chain has no steps`);
|
|
1327
|
+
}
|
|
1328
|
+
const firstAgents = isParallelStep(eventFirstStep)
|
|
1329
|
+
? eventFirstStep.parallel.map((t) => t.agent)
|
|
1330
|
+
: isDynamicParallelStep(eventFirstStep)
|
|
1331
|
+
? [eventFirstStep.parallel.agent]
|
|
1332
|
+
: [eventFirstStep.agent];
|
|
1333
|
+
const firstTask = isParallelStep(eventFirstStep)
|
|
1334
|
+
? eventFirstStep.parallel[0]?.task
|
|
1335
|
+
: isDynamicParallelStep(eventFirstStep)
|
|
1336
|
+
? eventFirstStep.parallel.task
|
|
1337
|
+
: eventFirstStep.task;
|
|
1338
|
+
const workflowGoal = params.goal ?? (params.task?.trim() || firstTask);
|
|
1339
|
+
const parallelGroups = [];
|
|
1340
|
+
const flatAgents = [];
|
|
1341
|
+
let flatStepStart = 0;
|
|
1342
|
+
for (let stepIndex = 0; stepIndex < eventChain.length; stepIndex++) {
|
|
1343
|
+
const step = eventChain[stepIndex];
|
|
1344
|
+
if (isParallelStep(step)) {
|
|
1345
|
+
parallelGroups.push({ start: flatStepStart, count: step.parallel.length, stepIndex });
|
|
1346
|
+
flatAgents.push(...step.parallel.map((task) => task.agent));
|
|
1347
|
+
flatStepStart += step.parallel.length;
|
|
1348
|
+
}
|
|
1349
|
+
else if (isDynamicParallelStep(step)) {
|
|
1350
|
+
parallelGroups.push({ start: flatStepStart, count: 1, stepIndex });
|
|
1351
|
+
flatAgents.push(step.parallel.agent);
|
|
1352
|
+
flatStepStart++;
|
|
1353
|
+
}
|
|
1354
|
+
else {
|
|
1355
|
+
flatAgents.push(step.agent);
|
|
1356
|
+
flatStepStart++;
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
if (inheritedNestedRoute && nestedAddress) {
|
|
1360
|
+
const now = Date.now();
|
|
1361
|
+
try {
|
|
1362
|
+
writeNestedEvent(inheritedNestedRoute, {
|
|
1363
|
+
type: "subagent.nested.started",
|
|
1364
|
+
ts: now,
|
|
1365
|
+
parentRunId: nestedAddress.parentRunId,
|
|
1366
|
+
parentStepIndex: nestedAddress.parentStepIndex,
|
|
1367
|
+
child: {
|
|
1368
|
+
id,
|
|
1369
|
+
parentRunId: nestedAddress.parentRunId,
|
|
1370
|
+
parentStepIndex: nestedAddress.parentStepIndex,
|
|
1371
|
+
depth: nestedAddress.depth,
|
|
1372
|
+
path: nestedAddress.path,
|
|
1373
|
+
asyncDir,
|
|
1374
|
+
pid: spawnResult.pid,
|
|
1375
|
+
ownerIntercomTarget: ctx.childRuntime?.intercomSessionName,
|
|
1376
|
+
leafIntercomTarget: childIntercomTargets?.[0],
|
|
1377
|
+
intercomTarget: childIntercomTargets?.[0],
|
|
1378
|
+
ownerState: "live",
|
|
1379
|
+
mode: resultMode,
|
|
1380
|
+
state: "running",
|
|
1381
|
+
agent: firstAgents[0],
|
|
1382
|
+
agents: flatAgents,
|
|
1383
|
+
chainStepCount: eventChain.length,
|
|
1384
|
+
parallelGroups,
|
|
1385
|
+
...(params.timeoutMs !== undefined ? { timeoutMs: params.timeoutMs, deadlineAt } : {}),
|
|
1386
|
+
startedAt: now,
|
|
1387
|
+
lastUpdate: now,
|
|
1388
|
+
...(capabilityCeiling ? { capabilityCeiling } : {}),
|
|
1389
|
+
},
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
catch (error) {
|
|
1393
|
+
console.error("Failed to emit nested async start event:", error);
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
ctx.pi.events.emit(SUBAGENT_ASYNC_STARTED_EVENT, {
|
|
1397
|
+
lifecycleArtifactVersion: SUBAGENT_LIFECYCLE_ARTIFACT_VERSION,
|
|
1398
|
+
id,
|
|
1399
|
+
pid: spawnResult.pid,
|
|
1400
|
+
sessionId: ctx.currentSessionId,
|
|
1401
|
+
completionOwnerId: ctx.completionOwnerId ?? currentCompletionOwnerId(),
|
|
1402
|
+
mode: resultMode,
|
|
1403
|
+
agent: firstAgents[0],
|
|
1404
|
+
agents: flatAgents,
|
|
1405
|
+
task: firstTask?.trim() ? PROMPT_REDACTED : undefined,
|
|
1406
|
+
goal: workflowGoal?.trim() ? PROMPT_REDACTED : undefined,
|
|
1407
|
+
chain: eventChain.map((s) => isParallelStep(s) ? `[${s.parallel.map((t) => t.agent).join("+")}]` : isDynamicParallelStep(s) ? `expand:${s.parallel.agent}` : s.agent),
|
|
1408
|
+
chainStepCount: eventChain.length,
|
|
1409
|
+
parallelGroups,
|
|
1410
|
+
workflowGraph,
|
|
1411
|
+
cwd: runnerCwd,
|
|
1412
|
+
asyncDir,
|
|
1413
|
+
...(sessionRoot ? { sessionRoot } : {}),
|
|
1414
|
+
...(params.timeoutMs !== undefined ? { timeoutMs: params.timeoutMs, deadlineAt } : {}),
|
|
1415
|
+
...(initialUsageBudget ? { usageBudget: initialUsageBudget } : {}),
|
|
1416
|
+
...(capabilityCeiling ? { capabilityCeiling } : {}),
|
|
1417
|
+
...(params.parentWorkflowRunId ? { parentWorkflowRunId: params.parentWorkflowRunId } : {}),
|
|
1418
|
+
...(params.workflowKey ? { workflowKey: params.workflowKey } : {}),
|
|
1419
|
+
nestedRoute,
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
const chainDesc = chain
|
|
1423
|
+
.map((s) => isParallelStep(s) ? `[${s.parallel.map((t) => t.agent).join("+")}]` : isDynamicParallelStep(s) ? `expand:${s.parallel.agent}` : s.agent)
|
|
1424
|
+
.join(" -> ");
|
|
1425
|
+
return {
|
|
1426
|
+
content: [{ type: "text", text: formatAsyncStartedMessage(`Async ${resultMode}: ${chainDesc} [${id}]`, ctx.interactive === true) }],
|
|
1427
|
+
details: { mode: resultMode, runId: id, results: [], asyncId: id, asyncDir, workflowGraph, ...(capabilityCeiling ? { capabilityCeiling } : {}), ...(params.parentWorkflowRunId ? { parentWorkflowRunId: params.parentWorkflowRunId } : {}), ...(params.workflowKey ? { workflowKey: params.workflowKey } : {}), ...(params.timeoutMs !== undefined ? { timeoutMs: params.timeoutMs, deadlineAt } : {}), ...(params.toolBudget ? { toolBudget: params.toolBudget } : {}), ...(initialUsageBudget ? { usageBudget: initialUsageBudget } : {}) },
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
/**
|
|
1431
|
+
* Execute a single agent asynchronously
|
|
1432
|
+
*/
|
|
1433
|
+
export function workflowAwaitedAsyncResultPath(asyncDir) {
|
|
1434
|
+
return path.join(asyncDir, "workflow-result.json");
|
|
1435
|
+
}
|
|
1436
|
+
export function executeAsyncSingle(id, params) {
|
|
1437
|
+
const { agent, agentConfig, ctx, cwd, maxOutput, artifactsDir, artifactConfig, shareEnabled, sessionRoot, sessionFile, maxSubagentDepth, worktreeSetupHook, worktreeSetupHookTimeoutMs, worktreeBaseDir, baseRef, worktreeProvider, worktreeBranchPrefix, controlConfig, controlIntercomTarget, childIntercomTarget, nestedRoute, } = params;
|
|
1438
|
+
let lane;
|
|
1439
|
+
try {
|
|
1440
|
+
lane = normalizeWorkflowLaneMetadata(params.lane, "lane");
|
|
1441
|
+
assertWorkflowLaneKey(lane, params.workflowKey, "lane");
|
|
1442
|
+
}
|
|
1443
|
+
catch (error) {
|
|
1444
|
+
return formatAsyncStartError("single", error instanceof Error ? error.message : String(error));
|
|
1445
|
+
}
|
|
1446
|
+
const task = params.task ?? "";
|
|
1447
|
+
let extensionBindings;
|
|
1448
|
+
try {
|
|
1449
|
+
extensionBindings = normalizeExtensionBindings(params.extensionBindings)?.value;
|
|
1450
|
+
}
|
|
1451
|
+
catch (error) {
|
|
1452
|
+
return formatAsyncStartError("single", error instanceof Error ? error.message : String(error));
|
|
1453
|
+
}
|
|
1454
|
+
const acceptanceErrors = validateAcceptanceInput(params.acceptance);
|
|
1455
|
+
if (acceptanceErrors.length > 0)
|
|
1456
|
+
return formatAsyncStartError("single", acceptanceErrors.join(" "));
|
|
1457
|
+
const externalRunner = agentConfig.runner?.type === "external-cli" || agentConfig.runner?.type === "external-job";
|
|
1458
|
+
const externalRunnerType = agentConfig.runner?.type;
|
|
1459
|
+
const permissionRules = resolvePermissionRules(ctx.permissions, agentConfig.permissions);
|
|
1460
|
+
if (externalRunner) {
|
|
1461
|
+
const unsupported = [];
|
|
1462
|
+
if (params.modelOverride !== undefined)
|
|
1463
|
+
unsupported.push("model override");
|
|
1464
|
+
if ((params.fast ?? agentConfig.fast) === true)
|
|
1465
|
+
unsupported.push("fast mode");
|
|
1466
|
+
if (params.thinkingOverride !== undefined)
|
|
1467
|
+
unsupported.push("thinking override");
|
|
1468
|
+
if (params.structuredOutputSchema !== undefined)
|
|
1469
|
+
unsupported.push("structured output");
|
|
1470
|
+
if (params.acceptance !== undefined || params.agentContract !== undefined)
|
|
1471
|
+
unsupported.push("acceptance/agent contract");
|
|
1472
|
+
if (params.toolBudget !== undefined || agentConfig.toolBudget !== undefined || params.configToolBudget !== undefined)
|
|
1473
|
+
unsupported.push("tool budget");
|
|
1474
|
+
if (params.context === "fork")
|
|
1475
|
+
unsupported.push("fork context");
|
|
1476
|
+
if ((params.skills?.length ?? 0) > 0)
|
|
1477
|
+
unsupported.push("skills");
|
|
1478
|
+
if (permissionRules)
|
|
1479
|
+
unsupported.push("native Pi child permissions");
|
|
1480
|
+
if (extensionBindings !== undefined)
|
|
1481
|
+
unsupported.push("extension bindings");
|
|
1482
|
+
if (unsupported.length > 0)
|
|
1483
|
+
return formatAsyncStartError("single", `Agent '${agentConfig.name}' uses runner.type='${externalRunnerType}' and does not support: ${unsupported.join(", ")}.`);
|
|
1484
|
+
}
|
|
1485
|
+
const capabilityCeiling = intersectSubagentCapabilityCeilings(params.capabilityCeiling ?? resolveCurrentSubagentCapabilityCeiling(ctx.currentSessionId), ctx.childRuntime?.capabilityCeiling);
|
|
1486
|
+
try {
|
|
1487
|
+
assertAgentAllowedByCapabilityCeiling(agentConfig.name, capabilityCeiling);
|
|
1488
|
+
}
|
|
1489
|
+
catch (error) {
|
|
1490
|
+
return formatAsyncStartError("single", error instanceof Error ? error.message : String(error));
|
|
1491
|
+
}
|
|
1492
|
+
const runnerCwd = resolveChildCwd(ctx.cwd, cwd);
|
|
1493
|
+
const requestedMachine = params.machine ?? agentConfig.machine;
|
|
1494
|
+
const machineUnsupported = formatHerdrMachineRunnerUnsupported({ machine: requestedMachine, agentName: agentConfig.name, runnerType: agentConfig.runner?.type, adapter: agentConfig.runner?.type === "external-cli" ? agentConfig.runner.adapter : undefined, worktree: params.worktree });
|
|
1495
|
+
if (machineUnsupported)
|
|
1496
|
+
return formatAsyncStartError("single", machineUnsupported);
|
|
1497
|
+
let machine;
|
|
1498
|
+
let machineEnv;
|
|
1499
|
+
if (requestedMachine) {
|
|
1500
|
+
try {
|
|
1501
|
+
const placement = resolveHerdrMachinePlacement({ machine: requestedMachine, cwd: runnerCwd, stepCwd: params.machineCwd });
|
|
1502
|
+
machine = placement.machine;
|
|
1503
|
+
machineEnv = placement.env;
|
|
1504
|
+
}
|
|
1505
|
+
catch (error) {
|
|
1506
|
+
return formatAsyncStartError("single", error instanceof Error ? error.message : String(error));
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
let managedWorktreeProvider;
|
|
1510
|
+
if (params.worktree === true) {
|
|
1511
|
+
try {
|
|
1512
|
+
const resolved = resolveWorktreeProvider(params.worktreeProvider, worktreeBaseDir);
|
|
1513
|
+
managedWorktreeProvider = shouldDeferWorktreeCwd(params.worktreeProvider, worktreeBaseDir) ? "worktrunk" : resolved;
|
|
1514
|
+
}
|
|
1515
|
+
catch (error) {
|
|
1516
|
+
return formatAsyncStartError("single", error instanceof Error ? error.message : String(error));
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
const instructionCwd = params.worktree === true && managedWorktreeProvider === "worktrunk"
|
|
1520
|
+
? WORKTREE_AGENT_CWD_PLACEHOLDER
|
|
1521
|
+
: params.worktree === true && managedWorktreeProvider === "native"
|
|
1522
|
+
? resolveExpectedWorktreeAgentCwd(runnerCwd, `${id}-s0`, 0, worktreeBaseDir)
|
|
1523
|
+
: machine?.cwd ?? runnerCwd;
|
|
1524
|
+
const readExistenceCwd = params.worktree === true ? runnerCwd : instructionCwd;
|
|
1525
|
+
const skillNames = params.skills ?? agentConfig.skills ?? [];
|
|
1526
|
+
const availableModels = params.availableModels;
|
|
1527
|
+
const { resolved: resolvedSkills, missing: missingSkills } = resolveSkillsWithFallback(skillNames, runnerCwd, ctx.cwd, agentConfig.skillPath, agentConfig.filePath ? path.dirname(agentConfig.filePath) : runnerCwd);
|
|
1528
|
+
if (missingSkills.includes("pi-subagents"))
|
|
1529
|
+
return formatAsyncStartError("single", UNAVAILABLE_SUBAGENT_SKILL_ERROR);
|
|
1530
|
+
const inheritedNestedRoute = inheritedNestedRouteOf(ctx.childRuntime);
|
|
1531
|
+
const nestedAddress = inheritedNestedRoute ? inheritedNestedParentAddressOf(ctx.childRuntime) : undefined;
|
|
1532
|
+
const asyncDir = inheritedNestedRoute
|
|
1533
|
+
? path.join(TEMP_ROOT_DIR, "nested-subagent-runs", inheritedNestedRoute.rootRunId, id)
|
|
1534
|
+
: path.join(DIRS.async, id);
|
|
1535
|
+
let runFanoutBudget;
|
|
1536
|
+
try {
|
|
1537
|
+
runFanoutBudget = params.runFanoutBudget ?? createRunFanoutBudget(id, 64);
|
|
1538
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
1539
|
+
writeRunFanoutBudgetDescriptor(asyncDir, runFanoutBudget);
|
|
1540
|
+
}
|
|
1541
|
+
catch (error) {
|
|
1542
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1543
|
+
return {
|
|
1544
|
+
content: [{ type: "text", text: `Failed to create async run directory '${asyncDir}': ${message}` }],
|
|
1545
|
+
isError: true,
|
|
1546
|
+
details: { mode: "single", results: [] },
|
|
1547
|
+
};
|
|
1548
|
+
}
|
|
1549
|
+
const effectiveOutput = normalizeSingleOutputOverride(params.output, agentConfig.output);
|
|
1550
|
+
const outputPath = resolveSingleOutputPath(effectiveOutput, ctx.cwd, instructionCwd, params.outputBaseDir ?? (artifactsDir ? path.join(artifactsDir, "outputs", id) : undefined));
|
|
1551
|
+
const systemPrompt = buildEffectiveSystemPrompt({ agent: agentConfig, resolvedSkills, cwd: runnerCwd, ...(outputPath ? { outputPath } : {}) });
|
|
1552
|
+
const outputMode = params.outputMode ?? agentConfig.outputMode ?? "inline";
|
|
1553
|
+
const validationError = validateFileOnlyOutputMode(outputMode, outputPath, `Async single run (${agent})`);
|
|
1554
|
+
if (validationError)
|
|
1555
|
+
return formatAsyncStartError("single", validationError);
|
|
1556
|
+
const taskWithOutputInstruction = injectSingleOutputInstruction(task, outputPath, agentConfig);
|
|
1557
|
+
// Reads: caller override > agent defaultReads > none. `~`/`~/` expand to home;
|
|
1558
|
+
// absolute paths pass through; relative paths resolve against the child cwd.
|
|
1559
|
+
const reads = params.reads !== undefined ? params.reads : agentConfig.defaultReads ?? false;
|
|
1560
|
+
const readPaths = Array.isArray(reads)
|
|
1561
|
+
? machine
|
|
1562
|
+
? externalRunner
|
|
1563
|
+
? reads.map((read) => read === "~" || read.startsWith("~/") || path.posix.isAbsolute(read) ? read : path.posix.resolve(instructionCwd, read))
|
|
1564
|
+
: []
|
|
1565
|
+
: managedWorktreeProvider === "worktrunk"
|
|
1566
|
+
? resolveExistingReadInstructionPaths(reads, instructionCwd, readExistenceCwd)
|
|
1567
|
+
: resolveExistingReadPaths(reads, readExistenceCwd)
|
|
1568
|
+
: [];
|
|
1569
|
+
const readsInstruction = readPaths.length > 0
|
|
1570
|
+
? `[Read from: ${readPaths.join(", ")}]\n\n`
|
|
1571
|
+
: "";
|
|
1572
|
+
const taskText = readsInstruction + taskWithOutputInstruction;
|
|
1573
|
+
const modelScopes = resolveModelScopesForAgent(ctx.modelScope, agentConfig.name, ctx.currentModel);
|
|
1574
|
+
const modelOrigin = resolveModelOrigin({
|
|
1575
|
+
fromParent: params.modelOverrideFromParent,
|
|
1576
|
+
storedOrigin: params.modelOrigin,
|
|
1577
|
+
explicitModel: params.modelOverrideFromParent ? undefined : params.modelOverride,
|
|
1578
|
+
agentModel: agentConfig.model,
|
|
1579
|
+
parentModel: ctx.currentModel,
|
|
1580
|
+
});
|
|
1581
|
+
let primaryModel;
|
|
1582
|
+
try {
|
|
1583
|
+
primaryModel = externalRunner ? undefined : modelOrigin === "inherited"
|
|
1584
|
+
? params.modelOverride ?? (ctx.currentModel ? `${ctx.currentModel.provider}/${ctx.currentModel.id}` : undefined)
|
|
1585
|
+
: resolveSubagentModelOverride(params.modelOverride ?? agentConfig.model, ctx.currentModel, availableModels, ctx.currentModelProvider, { scope: modelScopes, source: modelOrigin === "explicit" ? "explicit" : "inherited" });
|
|
1586
|
+
}
|
|
1587
|
+
catch (error) {
|
|
1588
|
+
return formatAsyncStartError("single", error instanceof Error ? error.message : String(error));
|
|
1589
|
+
}
|
|
1590
|
+
const effectiveThinking = externalRunner ? undefined : params.thinkingOverride ?? agentConfig.thinking;
|
|
1591
|
+
const model = externalRunner ? undefined : applyThinkingSuffix(primaryModel, effectiveThinking, params.thinkingOverride !== undefined);
|
|
1592
|
+
const contextLimit = model ? findModelInfo(model, availableModels, agentConfig.modelProvider ?? ctx.currentModelProvider)?.contextWindow : undefined;
|
|
1593
|
+
const thinkingCeiling = externalRunner ? undefined : intersectThinkingCeilings(params.thinkingCeiling, agentConfig.maxThinking, ctx.childRuntime?.thinkingCeiling);
|
|
1594
|
+
if (!externalRunner) {
|
|
1595
|
+
try {
|
|
1596
|
+
assertThinkingWithinCeiling({ model, configThinking: effectiveThinking, ceiling: thinkingCeiling, agent: agentConfig.name, runId: id });
|
|
1597
|
+
}
|
|
1598
|
+
catch (error) {
|
|
1599
|
+
return formatAsyncStartError("single", error instanceof Error ? error.message : String(error));
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
const toolBudgetInput = params.toolBudget ?? agentConfig.toolBudget ?? params.configToolBudget;
|
|
1603
|
+
const resolvedToolBudget = validateToolBudgetConfig(toolBudgetInput, params.toolBudget ? "toolBudget" : agentConfig.toolBudget ? "agent.toolBudget" : "config.toolBudget");
|
|
1604
|
+
if (resolvedToolBudget.error)
|
|
1605
|
+
return formatAsyncStartError("single", resolvedToolBudget.error);
|
|
1606
|
+
const deadlineAt = params.absoluteDeadlineAt ?? (params.timeoutMs !== undefined ? Date.now() + params.timeoutMs : undefined);
|
|
1607
|
+
const timeoutMs = params.absoluteDeadlineAt !== undefined && deadlineAt !== undefined
|
|
1608
|
+
? deadlineAt - Date.now()
|
|
1609
|
+
: params.timeoutMs;
|
|
1610
|
+
if (timeoutMs !== undefined && timeoutMs <= 0)
|
|
1611
|
+
return formatAsyncStartError("single", "The source run's absolute deadline expired before recovery could launch.");
|
|
1612
|
+
const resolvedToolTimeout = resolveToolTimeoutMs({
|
|
1613
|
+
callValue: params.toolTimeoutMs,
|
|
1614
|
+
agentValue: agentConfig.defaultToolTimeoutMs,
|
|
1615
|
+
configValue: params.configToolTimeoutMs,
|
|
1616
|
+
envValue: params.toolTimeoutMsEnv ?? toolTimeoutFromEnv(),
|
|
1617
|
+
});
|
|
1618
|
+
if (resolvedToolTimeout.error)
|
|
1619
|
+
return formatAsyncStartError("single", resolvedToolTimeout.error);
|
|
1620
|
+
const toolTimeoutMs = resolvedToolTimeout.toolTimeoutMs;
|
|
1621
|
+
const initialUsageBudget = usageBudgetState(params.usageBudget, undefined);
|
|
1622
|
+
const resolvedSessionDir = params.sessionDir ?? (sessionRoot ? path.join(sessionRoot, `async-${id}`) : undefined);
|
|
1623
|
+
const structuredOutput = params.structuredOutputSchema
|
|
1624
|
+
? createStructuredOutputRuntime(params.structuredOutputSchema, path.join(asyncDir, "structured-output"), { acceptanceReport: resolveAcceptanceReportMode(params.acceptance) })
|
|
1625
|
+
: undefined;
|
|
1626
|
+
let selectedModel = model;
|
|
1627
|
+
let requestedModel;
|
|
1628
|
+
if (!externalRunner) {
|
|
1629
|
+
try {
|
|
1630
|
+
const modelEvidence = resolveModelSelection(primaryModel, availableModels, agentConfig.modelProvider ?? ctx.currentModelProvider, {
|
|
1631
|
+
scope: modelScopes,
|
|
1632
|
+
primaryModelFromParent: modelOrigin === "inherited",
|
|
1633
|
+
origin: modelOrigin,
|
|
1634
|
+
});
|
|
1635
|
+
requestedModel = modelEvidence.requestedModel;
|
|
1636
|
+
selectedModel = applyThinkingSuffix(modelEvidence.model, effectiveThinking, params.thinkingOverride !== undefined);
|
|
1637
|
+
assertThinkingWithinCeiling({ model: selectedModel, configThinking: effectiveThinking, ceiling: thinkingCeiling, agent: agentConfig.name, runId: id });
|
|
1638
|
+
}
|
|
1639
|
+
catch (error) {
|
|
1640
|
+
return formatAsyncStartError("single", error instanceof Error ? error.message : String(error));
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
const requiredExtensions = externalRunner ? [] : params.requiredExtensions ?? ctx.childRuntime?.requiredExtensions ?? resolveRequiredChildExtensions(ctx.parentSessionId ?? ctx.currentSessionId ?? undefined);
|
|
1644
|
+
const toolPlan = resolvePiLaunchToolPlan({
|
|
1645
|
+
tools: agentConfig.tools,
|
|
1646
|
+
excludeTools: agentConfig.excludeTools,
|
|
1647
|
+
allowNestedSubagents: agentConfig.allowNestedSubagents,
|
|
1648
|
+
extensions: agentConfig.extensions,
|
|
1649
|
+
subagentOnlyExtensions: agentConfig.subagentOnlyExtensions,
|
|
1650
|
+
requiredExtensions,
|
|
1651
|
+
mcpDirectTools: agentConfig.mcpDirectTools,
|
|
1652
|
+
cwd: runnerCwd,
|
|
1653
|
+
requireReadTool: Boolean(resolvedSkills.length),
|
|
1654
|
+
structuredOutput: Boolean(params.structuredOutputSchema),
|
|
1655
|
+
fast: params.fast ?? agentConfig.fast,
|
|
1656
|
+
model: selectedModel,
|
|
1657
|
+
capabilityCeiling,
|
|
1658
|
+
inheritedCapabilityCeiling: ctx.childRuntime?.capabilityCeiling,
|
|
1659
|
+
agentName: agentConfig.name,
|
|
1660
|
+
permissionRules: resolvePermissionRules(ctx.permissions, agentConfig.permissions),
|
|
1661
|
+
runtimeSnapshotHost: ctx.pi,
|
|
1662
|
+
});
|
|
1663
|
+
const launchResolvedExtensions = externalRunner ? undefined : projectLaunchResolvedChildExtensions(toolPlan);
|
|
1664
|
+
if (!externalRunner) {
|
|
1665
|
+
const contractTools = toolPlan.explicitToolAllowlist ? toolPlan.effectiveToolAllowlist : undefined;
|
|
1666
|
+
const contractError = validateImplementationToolContract({
|
|
1667
|
+
agent: agentConfig.name,
|
|
1668
|
+
task: taskText,
|
|
1669
|
+
tools: contractTools,
|
|
1670
|
+
mcpDirectTools: toolPlan.effectiveMcpTools,
|
|
1671
|
+
configuredExtensions: toolPlan.configuredExtensions,
|
|
1672
|
+
requestedTools: toolPlan.requestedBuiltinTools,
|
|
1673
|
+
acceptanceRole: agentConfig.acceptanceRole,
|
|
1674
|
+
completionGuard: agentConfig.completionGuard,
|
|
1675
|
+
});
|
|
1676
|
+
if (contractError)
|
|
1677
|
+
return formatAsyncStartError("single", contractError);
|
|
1678
|
+
}
|
|
1679
|
+
const fast = params.fast ?? agentConfig.fast;
|
|
1680
|
+
const launchThinking = resolveEffectiveThinking(selectedModel, effectiveThinking);
|
|
1681
|
+
const { definitionDigest, launchContractDigest } = resolveLaunchBinding({
|
|
1682
|
+
agent: agentConfig,
|
|
1683
|
+
task,
|
|
1684
|
+
model: selectedModel,
|
|
1685
|
+
...(fast !== undefined ? { fast } : {}),
|
|
1686
|
+
...(launchThinking ? { thinking: launchThinking } : {}),
|
|
1687
|
+
systemPrompt,
|
|
1688
|
+
skills: resolvedSkills.map((skill) => skill.name),
|
|
1689
|
+
toolPlan,
|
|
1690
|
+
...(outputPath ? { outputPath } : {}),
|
|
1691
|
+
outputMode,
|
|
1692
|
+
...(params.structuredOutputSchema ? { structuredOutputSchema: params.structuredOutputSchema } : {}),
|
|
1693
|
+
...(extensionBindings ? { extensionBindings } : {}),
|
|
1694
|
+
});
|
|
1695
|
+
const resolvedAcceptance = resolveEffectiveAcceptance({
|
|
1696
|
+
explicit: params.acceptance,
|
|
1697
|
+
agentName: agent,
|
|
1698
|
+
acceptanceRole: agentConfig.acceptanceRole,
|
|
1699
|
+
task,
|
|
1700
|
+
mode: "single",
|
|
1701
|
+
async: true,
|
|
1702
|
+
agentContract: params.agentContract,
|
|
1703
|
+
});
|
|
1704
|
+
const recoveryAgentConfig = params.recoveryAgentConfig ?? agentConfig;
|
|
1705
|
+
const recoveryDescriptor = {
|
|
1706
|
+
...(ctx.modelResponseAliases ? { modelResponseAliases: ctx.modelResponseAliases } : {}),
|
|
1707
|
+
version: 1,
|
|
1708
|
+
...(lane ? { lane } : {}),
|
|
1709
|
+
launchContractDigest,
|
|
1710
|
+
...(extensionBindings ? { extensionBindings } : {}),
|
|
1711
|
+
...(requiredExtensions.length > 0 ? { requiredExtensions } : {}),
|
|
1712
|
+
runFanoutBudget,
|
|
1713
|
+
sourceRunId: id,
|
|
1714
|
+
...(params.agentContract ? { agentContract: params.agentContract } : {}),
|
|
1715
|
+
agent,
|
|
1716
|
+
launchResolvedExtensions,
|
|
1717
|
+
...(sessionFile ? { sessionFile } : {}),
|
|
1718
|
+
cwd: runnerCwd,
|
|
1719
|
+
...(selectedModel ? { model: selectedModel } : {}),
|
|
1720
|
+
...(params.fast ?? recoveryAgentConfig.fast ? { fast: params.fast ?? recoveryAgentConfig.fast } : {}),
|
|
1721
|
+
...(recoveryAgentConfig.modelProvider ? { modelProvider: recoveryAgentConfig.modelProvider } : {}),
|
|
1722
|
+
...(modelOrigin === "inherited" ? { modelOverrideFromParent: true } : {}),
|
|
1723
|
+
modelOrigin,
|
|
1724
|
+
...(effectiveThinking ? { thinking: resolveEffectiveThinking(selectedModel, effectiveThinking) } : {}),
|
|
1725
|
+
...(thinkingCeiling ? { thinkingCeiling } : {}),
|
|
1726
|
+
...(recoveryAgentConfig.tools ? { tools: [...recoveryAgentConfig.tools] } : {}),
|
|
1727
|
+
...(recoveryAgentConfig.excludeTools ? { excludeTools: [...recoveryAgentConfig.excludeTools] } : {}),
|
|
1728
|
+
...(recoveryAgentConfig.allowNestedSubagents !== undefined ? { allowNestedSubagents: recoveryAgentConfig.allowNestedSubagents } : {}),
|
|
1729
|
+
...(recoveryAgentConfig.allowedAgents !== undefined ? { allowedAgents: [...recoveryAgentConfig.allowedAgents] } : {}),
|
|
1730
|
+
...(recoveryAgentConfig.extensions ? { extensions: [...recoveryAgentConfig.extensions] } : {}),
|
|
1731
|
+
...(recoveryAgentConfig.subagentOnlyExtensions ? { subagentOnlyExtensions: [...recoveryAgentConfig.subagentOnlyExtensions] } : {}),
|
|
1732
|
+
...(recoveryAgentConfig.mcpDirectTools ? { mcpDirectTools: [...recoveryAgentConfig.mcpDirectTools] } : {}),
|
|
1733
|
+
...(recoveryAgentConfig.mutationTools ? { mutationTools: [...recoveryAgentConfig.mutationTools] } : {}),
|
|
1734
|
+
...(recoveryAgentConfig.systemPrompt ? { systemPrompt: recoveryAgentConfig.systemPrompt } : {}),
|
|
1735
|
+
systemPromptMode: recoveryAgentConfig.systemPromptMode,
|
|
1736
|
+
inheritProjectContext: recoveryAgentConfig.inheritProjectContext,
|
|
1737
|
+
inheritGlobalContext: recoveryAgentConfig.inheritGlobalContext,
|
|
1738
|
+
inheritSkills: recoveryAgentConfig.inheritSkills,
|
|
1739
|
+
...(resolvedSkills.length ? { skills: resolvedSkills.map((skill) => skill.name) } : {}),
|
|
1740
|
+
...(recoveryAgentConfig.skillPath ? { skillPath: [...recoveryAgentConfig.skillPath] } : {}),
|
|
1741
|
+
...(recoveryAgentConfig.filePath ? { agentFilePath: recoveryAgentConfig.filePath } : {}),
|
|
1742
|
+
...(recoveryAgentConfig.completionGuard !== undefined ? { completionGuard: recoveryAgentConfig.completionGuard } : {}),
|
|
1743
|
+
...(recoveryAgentConfig.memory ? { memory: { ...recoveryAgentConfig.memory } } : {}),
|
|
1744
|
+
...(outputPath ? { outputPath } : {}),
|
|
1745
|
+
outputMode,
|
|
1746
|
+
...(params.structuredOutputSchema ? { structuredOutputSchema: params.structuredOutputSchema } : {}),
|
|
1747
|
+
...(params.acceptance !== undefined ? { acceptance: params.acceptance } : {}),
|
|
1748
|
+
...(controlConfig ? { controlConfig } : {}),
|
|
1749
|
+
...(params.context ? { context: params.context } : {}),
|
|
1750
|
+
...(params.intercomBridge !== undefined ? { intercomBridge: params.intercomBridge } : {}),
|
|
1751
|
+
...(params.baseRef !== undefined ? { baseRef: params.baseRef } : {}),
|
|
1752
|
+
...(deadlineAt !== undefined ? { absoluteDeadlineAt: deadlineAt } : {}),
|
|
1753
|
+
...(resolvedToolBudget.budget ? { initialToolBudget: resolvedToolBudget.budget } : {}),
|
|
1754
|
+
maxSubagentDepth: resolveChildMaxSubagentDepth(maxSubagentDepth, recoveryAgentConfig.maxSubagentDepth),
|
|
1755
|
+
...(maxOutput ? { maxOutput } : {}),
|
|
1756
|
+
share: shareEnabled,
|
|
1757
|
+
...(resolvedSessionDir ? { sessionDir: resolvedSessionDir } : {}),
|
|
1758
|
+
...(artifactsDir ? { artifactsDir } : {}),
|
|
1759
|
+
artifactConfig,
|
|
1760
|
+
...(capabilityCeiling ? { capabilityCeiling } : {}),
|
|
1761
|
+
};
|
|
1762
|
+
if (!externalRunner) {
|
|
1763
|
+
try {
|
|
1764
|
+
writePrivateAtomicJson(path.join(asyncDir, "recovery-descriptor.json"), recoveryDescriptor);
|
|
1765
|
+
}
|
|
1766
|
+
catch (error) {
|
|
1767
|
+
return formatAsyncStartError("single", `Failed to persist async recovery descriptor for '${id}': ${error instanceof Error ? error.message : String(error)}`);
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
let spawnResultOrPromise = {};
|
|
1771
|
+
const initialStatusAt = Date.now();
|
|
1772
|
+
const initialCompletionOwnerId = ctx.completionOwnerId ?? currentCompletionOwnerId();
|
|
1773
|
+
const launchParentSessionId = ctx.parentSessionId ?? ctx.currentSessionId;
|
|
1774
|
+
try {
|
|
1775
|
+
spawnResultOrPromise = spawnRunner({
|
|
1776
|
+
id,
|
|
1777
|
+
steps: [
|
|
1778
|
+
{
|
|
1779
|
+
parentSessionId: launchParentSessionId,
|
|
1780
|
+
permissionRules,
|
|
1781
|
+
...(capabilityCeiling ? { capabilityCeiling } : {}),
|
|
1782
|
+
agent,
|
|
1783
|
+
task: taskText,
|
|
1784
|
+
...(agentConfig.runner ? { runner: agentConfig.runner } : {}),
|
|
1785
|
+
...(machine ? { machine } : {}),
|
|
1786
|
+
...(!externalRunner && machine && params.reads !== undefined ? { remoteReads: params.reads } : {}),
|
|
1787
|
+
...(machineEnv ? { machineEnv } : {}),
|
|
1788
|
+
...(params.externalJobFollowUp ? { externalJobFollowUp: params.externalJobFollowUp } : {}),
|
|
1789
|
+
...(params.context ? { context: params.context } : {}),
|
|
1790
|
+
cwd: machine?.cwd ?? runnerCwd,
|
|
1791
|
+
requestedCwd: machine?.cwd ?? params.requestedCwd ?? runnerCwd,
|
|
1792
|
+
model: selectedModel,
|
|
1793
|
+
...(contextLimit !== undefined ? { contextLimit } : {}),
|
|
1794
|
+
...(params.fast ?? agentConfig.fast ? { fast: params.fast ?? agentConfig.fast } : {}),
|
|
1795
|
+
thinking: resolveEffectiveThinking(selectedModel, effectiveThinking),
|
|
1796
|
+
...(thinkingCeiling ? { thinkingCeiling } : {}),
|
|
1797
|
+
...(requestedModel ? { requestedModel } : {}),
|
|
1798
|
+
...(modelOrigin === "inherited" ? { skipPrimaryModelVerification: true } : {}),
|
|
1799
|
+
...(availableModels && availableModels.length > 0 ? { modelVerificationRegistry: availableModels } : {}),
|
|
1800
|
+
...(ctx.modelResponseAliases ? { modelResponseAliases: ctx.modelResponseAliases } : {}),
|
|
1801
|
+
tools: agentConfig.tools,
|
|
1802
|
+
excludeTools: agentConfig.excludeTools,
|
|
1803
|
+
allowNestedSubagents: agentConfig.allowNestedSubagents,
|
|
1804
|
+
allowedAgents: agentConfig.allowedAgents,
|
|
1805
|
+
extensions: agentConfig.extensions,
|
|
1806
|
+
subagentOnlyExtensions: agentConfig.subagentOnlyExtensions,
|
|
1807
|
+
...(!externalRunner ? { requiredExtensions } : {}),
|
|
1808
|
+
mcpDirectTools: agentConfig.mcpDirectTools,
|
|
1809
|
+
mutationTools: agentConfig.mutationTools,
|
|
1810
|
+
completionGuard: agentConfig.completionGuard,
|
|
1811
|
+
systemPrompt,
|
|
1812
|
+
systemPromptMode: agentConfig.systemPromptMode,
|
|
1813
|
+
inheritProjectContext: agentConfig.inheritProjectContext,
|
|
1814
|
+
inheritGlobalContext: agentConfig.inheritGlobalContext,
|
|
1815
|
+
inheritSkills: agentConfig.inheritSkills,
|
|
1816
|
+
skills: resolvedSkills.map((r) => r.name),
|
|
1817
|
+
outputPath,
|
|
1818
|
+
...(params.outputClaimPath ? { outputClaimPath: params.outputClaimPath } : {}),
|
|
1819
|
+
outputMode,
|
|
1820
|
+
...(!externalRunner && sessionFile ? { sessionFile } : {}),
|
|
1821
|
+
maxSubagentDepth: resolveChildMaxSubagentDepth(maxSubagentDepth, agentConfig.maxSubagentDepth),
|
|
1822
|
+
waitToolEnabled: params.waitToolEnabled,
|
|
1823
|
+
waitToolDefaultTimeoutMs: params.waitToolDefaultTimeoutMs,
|
|
1824
|
+
...(params.agentContract ? { agentContract: params.agentContract } : {}),
|
|
1825
|
+
definitionDigest,
|
|
1826
|
+
launchBindingTask: task,
|
|
1827
|
+
launchContractDigest,
|
|
1828
|
+
...(extensionBindings ? { extensionBindings } : {}),
|
|
1829
|
+
launchResolvedExtensions,
|
|
1830
|
+
effectiveAcceptance: resolvedAcceptance,
|
|
1831
|
+
acceptanceInput: params.acceptance,
|
|
1832
|
+
...(structuredOutput ? { structuredOutput } : {}),
|
|
1833
|
+
...(params.structuredOutputSchema ? { structuredOutputSchema: params.structuredOutputSchema } : {}),
|
|
1834
|
+
...(resolvedToolBudget.budget ? { toolBudget: resolvedToolBudget.budget } : {}),
|
|
1835
|
+
...(params.worktree === true ? { worktree: true } : {}),
|
|
1836
|
+
...(lane ? { lane } : {}),
|
|
1837
|
+
},
|
|
1838
|
+
],
|
|
1839
|
+
resultPath: params.parentWorkflowRunId !== undefined && (params.revivalLease !== undefined || params.workflowAwaitAsync === true)
|
|
1840
|
+
? workflowAwaitedAsyncResultPath(asyncDir)
|
|
1841
|
+
: inheritedNestedRoute ? nestedResultsPath(inheritedNestedRoute.rootRunId, id) : resultFilePath(DIRS.results, id),
|
|
1842
|
+
cwd: runnerCwd,
|
|
1843
|
+
placeholder: "{previous}",
|
|
1844
|
+
maxOutput,
|
|
1845
|
+
artifactsDir: artifactConfig.enabled ? artifactsDir : undefined,
|
|
1846
|
+
artifactConfig,
|
|
1847
|
+
share: shareEnabled,
|
|
1848
|
+
sessionDir: resolvedSessionDir,
|
|
1849
|
+
asyncDir,
|
|
1850
|
+
sessionId: ctx.currentSessionId,
|
|
1851
|
+
completionOwnerId: ctx.completionOwnerId ?? currentCompletionOwnerId(),
|
|
1852
|
+
...(capabilityCeiling ? { capabilityCeiling } : {}),
|
|
1853
|
+
piPackageRoot,
|
|
1854
|
+
childSessionFactoryModule: childSessionFactoryModule(),
|
|
1855
|
+
inheritedChildRuntime: inheritedChildRuntime(ctx.childRuntime),
|
|
1856
|
+
worktreeSetupHook,
|
|
1857
|
+
worktreeSetupHookTimeoutMs,
|
|
1858
|
+
worktreeBaseDir,
|
|
1859
|
+
baseRef,
|
|
1860
|
+
worktreeProvider,
|
|
1861
|
+
worktreeBranchPrefix,
|
|
1862
|
+
controlConfig,
|
|
1863
|
+
timeoutMs,
|
|
1864
|
+
deadlineAt,
|
|
1865
|
+
toolTimeoutMs,
|
|
1866
|
+
checkpointBeforeDeadlineMs: params.checkpointBeforeDeadlineMs,
|
|
1867
|
+
toolBudget: params.toolBudget,
|
|
1868
|
+
usageBudget: params.usageBudget,
|
|
1869
|
+
controlIntercomTarget,
|
|
1870
|
+
childIntercomTargets: childIntercomTarget ? [childIntercomTarget(agent, 0)] : undefined,
|
|
1871
|
+
resultMode: "single",
|
|
1872
|
+
launchContractDigest,
|
|
1873
|
+
launchResolvedExtensions,
|
|
1874
|
+
runFanoutBudget,
|
|
1875
|
+
...(params.parentWorkflowRunId ? { parentWorkflowRunId: params.parentWorkflowRunId } : {}),
|
|
1876
|
+
...(params.workflowKey ? { workflowKey: params.workflowKey } : {}),
|
|
1877
|
+
...(lane ? { lane } : {}),
|
|
1878
|
+
...(params.revivalLease ? { revivalLease: params.revivalLease } : {}),
|
|
1879
|
+
nestedRoute: nestedRoute ?? inheritedNestedRoute,
|
|
1880
|
+
nestedSelf: inheritedNestedRoute && nestedAddress ? {
|
|
1881
|
+
parentRunId: nestedAddress.parentRunId,
|
|
1882
|
+
parentStepIndex: nestedAddress.parentStepIndex,
|
|
1883
|
+
depth: nestedAddress.depth,
|
|
1884
|
+
path: nestedAddress.path,
|
|
1885
|
+
} : undefined,
|
|
1886
|
+
}, id, runnerCwd, {
|
|
1887
|
+
lifecycleArtifactVersion: SUBAGENT_LIFECYCLE_ARTIFACT_VERSION,
|
|
1888
|
+
runId: id,
|
|
1889
|
+
...(ctx.currentSessionId ? { sessionId: ctx.currentSessionId } : {}),
|
|
1890
|
+
...(initialCompletionOwnerId ? { completionOwnerId: initialCompletionOwnerId } : {}),
|
|
1891
|
+
mode: "single",
|
|
1892
|
+
state: "running",
|
|
1893
|
+
startedAt: initialStatusAt,
|
|
1894
|
+
lastUpdate: initialStatusAt,
|
|
1895
|
+
currentStep: 0,
|
|
1896
|
+
chainStepCount: 1,
|
|
1897
|
+
...(lane ? { lane } : {}),
|
|
1898
|
+
steps: [{ agent, status: "pending", ...(lane ? { lane } : {}), ...(model ? { model } : {}), ...(contextLimit !== undefined ? { contextLimit } : {}) }],
|
|
1899
|
+
}, path.join(asyncDir, "status.json"), launchParentSessionId, (proof) => emitProcessTerminalEvent(ctx, proof), (runnerProcessInstanceId) => params.activeAsyncCapacity?.markStarted(runnerProcessInstanceId), params.requestedCwd ?? runnerCwd);
|
|
1900
|
+
}
|
|
1901
|
+
catch (error) {
|
|
1902
|
+
params.activeAsyncCapacity?.rollback();
|
|
1903
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1904
|
+
return formatAsyncStartError("single", `Failed to start async run '${id}': ${message}`);
|
|
1905
|
+
}
|
|
1906
|
+
const finishSpawnResult = (spawnResult) => {
|
|
1907
|
+
if (spawnResult.error) {
|
|
1908
|
+
if (spawnResult.startupDidNotProceed) {
|
|
1909
|
+
if (!spawnResult.runnerProcessInstanceId || params.activeAsyncCapacity?.rollbackBeforeRunnerProceed(spawnResult.runnerProcessInstanceId) !== true)
|
|
1910
|
+
params.activeAsyncCapacity?.rollback();
|
|
1911
|
+
}
|
|
1912
|
+
else if (!spawnResult.pid || !spawnResult.runnerProcessInstanceId)
|
|
1913
|
+
params.activeAsyncCapacity?.rollback();
|
|
1914
|
+
else
|
|
1915
|
+
params.activeAsyncCapacity?.markStarted(spawnResult.runnerProcessInstanceId);
|
|
1916
|
+
return formatAsyncStartError("single", `Failed to start async run '${id}': ${spawnResult.error}`);
|
|
1917
|
+
}
|
|
1918
|
+
if (!spawnResult.pid || !spawnResult.runnerProcessInstanceId) {
|
|
1919
|
+
params.activeAsyncCapacity?.rollback();
|
|
1920
|
+
return formatAsyncStartError("single", `Failed to start async run '${id}': runner identity unavailable`);
|
|
1921
|
+
}
|
|
1922
|
+
if (spawnResult.pid) {
|
|
1923
|
+
if (inheritedNestedRoute && nestedAddress) {
|
|
1924
|
+
const now = Date.now();
|
|
1925
|
+
try {
|
|
1926
|
+
writeNestedEvent(inheritedNestedRoute, {
|
|
1927
|
+
type: "subagent.nested.started",
|
|
1928
|
+
ts: now,
|
|
1929
|
+
parentRunId: nestedAddress.parentRunId,
|
|
1930
|
+
parentStepIndex: nestedAddress.parentStepIndex,
|
|
1931
|
+
child: {
|
|
1932
|
+
id,
|
|
1933
|
+
parentRunId: nestedAddress.parentRunId,
|
|
1934
|
+
parentStepIndex: nestedAddress.parentStepIndex,
|
|
1935
|
+
depth: nestedAddress.depth,
|
|
1936
|
+
path: nestedAddress.path,
|
|
1937
|
+
asyncDir,
|
|
1938
|
+
pid: spawnResult.pid,
|
|
1939
|
+
ownerIntercomTarget: ctx.childRuntime?.intercomSessionName,
|
|
1940
|
+
leafIntercomTarget: childIntercomTarget?.(agent, 0),
|
|
1941
|
+
intercomTarget: childIntercomTarget?.(agent, 0),
|
|
1942
|
+
ownerState: "live",
|
|
1943
|
+
mode: "single",
|
|
1944
|
+
state: "running",
|
|
1945
|
+
agent,
|
|
1946
|
+
agents: [agent],
|
|
1947
|
+
chainStepCount: 1,
|
|
1948
|
+
...(timeoutMs !== undefined ? { timeoutMs, deadlineAt } : {}),
|
|
1949
|
+
startedAt: now,
|
|
1950
|
+
lastUpdate: now,
|
|
1951
|
+
...(capabilityCeiling ? { capabilityCeiling } : {}),
|
|
1952
|
+
},
|
|
1953
|
+
});
|
|
1954
|
+
}
|
|
1955
|
+
catch (error) {
|
|
1956
|
+
console.error("Failed to emit nested async start event:", error);
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
ctx.pi.events.emit(SUBAGENT_ASYNC_STARTED_EVENT, {
|
|
1960
|
+
lifecycleArtifactVersion: SUBAGENT_LIFECYCLE_ARTIFACT_VERSION,
|
|
1961
|
+
id,
|
|
1962
|
+
pid: spawnResult.pid,
|
|
1963
|
+
sessionId: ctx.currentSessionId,
|
|
1964
|
+
completionOwnerId: ctx.completionOwnerId ?? currentCompletionOwnerId(),
|
|
1965
|
+
mode: "single",
|
|
1966
|
+
agent,
|
|
1967
|
+
task: task?.trim() ? PROMPT_REDACTED : undefined,
|
|
1968
|
+
goal: (params.goal ?? task).trim() ? PROMPT_REDACTED : undefined,
|
|
1969
|
+
cwd: runnerCwd,
|
|
1970
|
+
asyncDir,
|
|
1971
|
+
...(sessionRoot ? { sessionRoot } : {}),
|
|
1972
|
+
launchContractDigest,
|
|
1973
|
+
launchResolvedExtensions,
|
|
1974
|
+
...(params.parentWorkflowRunId ? { parentWorkflowRunId: params.parentWorkflowRunId } : {}),
|
|
1975
|
+
...(params.workflowKey ? { workflowKey: params.workflowKey } : {}),
|
|
1976
|
+
...(timeoutMs !== undefined ? { timeoutMs, deadlineAt } : {}),
|
|
1977
|
+
...(initialUsageBudget ? { usageBudget: initialUsageBudget } : {}),
|
|
1978
|
+
...(capabilityCeiling ? { capabilityCeiling } : {}),
|
|
1979
|
+
nestedRoute,
|
|
1980
|
+
});
|
|
1981
|
+
}
|
|
1982
|
+
return {
|
|
1983
|
+
content: [{ type: "text", text: formatAsyncStartedMessage(`Async: ${agent} [${id}]`, ctx.interactive === true) }],
|
|
1984
|
+
details: { mode: "single", runId: id, results: [], asyncId: id, asyncDir, launchContractDigest, launchResolvedExtensions, ...(capabilityCeiling ? { capabilityCeiling } : {}), ...(params.context ? { context: params.context } : {}), ...(timeoutMs !== undefined ? { timeoutMs, deadlineAt } : {}), ...(params.toolBudget ? { toolBudget: resolvedToolBudget.budget ?? params.toolBudget } : {}), ...(initialUsageBudget ? { usageBudget: initialUsageBudget } : {}) },
|
|
1985
|
+
};
|
|
1986
|
+
};
|
|
1987
|
+
return spawnResultOrPromise instanceof Promise ? spawnResultOrPromise.then(finishSpawnResult) : finishSpawnResult(spawnResultOrPromise);
|
|
1988
|
+
}
|
|
1989
|
+
//# sourceMappingURL=async-execution.js.map
|