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