pi-subagents 0.69.0 → 0.70.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/agents/reviewer.md +3 -2
- package/docs/agents.md +6 -2
- package/docs/configuration.md +1 -1
- package/docs/extension-api.md +1 -1
- package/docs/models.md +3 -1
- package/docs/observability.md +6 -0
- package/docs/watchdog.md +2 -0
- package/docs/workflows.md +6 -2
- package/index.d.ts +3 -0
- package/index.d.ts.map +1 -0
- package/index.js +10 -0
- package/index.js.map +1 -0
- package/package.json +89 -73
- package/runner-peer-loader.mjs +4 -7
- package/runner-peer-preload.mjs +5 -7
- package/skills/pi-subagents/references/prompting-and-roles.md +2 -2
- package/src/agents/advertised-agent-prompt.d.ts +8 -0
- package/src/agents/advertised-agent-prompt.d.ts.map +1 -0
- package/src/agents/advertised-agent-prompt.js +77 -0
- package/src/agents/advertised-agent-prompt.js.map +1 -0
- package/src/agents/agent-management.d.ts +27 -0
- package/src/agents/agent-management.d.ts.map +1 -0
- package/src/agents/agent-management.js +1528 -0
- package/src/agents/agent-management.js.map +1 -0
- package/src/agents/agent-memory.d.ts +49 -0
- package/src/agents/agent-memory.d.ts.map +1 -0
- package/src/agents/agent-memory.js +349 -0
- package/src/agents/agent-memory.js.map +1 -0
- package/src/agents/agent-refinements.d.ts +100 -0
- package/src/agents/agent-refinements.d.ts.map +1 -0
- package/src/agents/agent-refinements.js +569 -0
- package/src/agents/agent-refinements.js.map +1 -0
- package/src/agents/agent-scope.d.ts +3 -0
- package/src/agents/agent-scope.d.ts.map +1 -0
- package/src/agents/agent-scope.js +6 -0
- package/src/agents/agent-scope.js.map +1 -0
- package/src/agents/agent-selection.d.ts +3 -0
- package/src/agents/agent-selection.d.ts.map +1 -0
- package/src/agents/agent-selection.js +23 -0
- package/src/agents/agent-selection.js.map +1 -0
- package/src/agents/agent-serializer.d.ts +8 -0
- package/src/agents/agent-serializer.d.ts.map +1 -0
- package/src/agents/agent-serializer.js +200 -0
- package/src/agents/agent-serializer.js.map +1 -0
- package/src/agents/agents.d.ts +313 -0
- package/src/agents/agents.d.ts.map +1 -0
- package/src/agents/agents.js +2622 -0
- package/src/agents/agents.js.map +1 -0
- package/src/agents/builtin-names.d.ts +2 -0
- package/src/agents/builtin-names.d.ts.map +1 -0
- package/src/agents/builtin-names.js +17 -0
- package/src/agents/builtin-names.js.map +1 -0
- package/src/agents/chain-serializer.d.ts +7 -0
- package/src/agents/chain-serializer.d.ts.map +1 -0
- package/src/agents/chain-serializer.js +319 -0
- package/src/agents/chain-serializer.js.map +1 -0
- package/src/agents/frontmatter.d.ts +16 -0
- package/src/agents/frontmatter.d.ts.map +1 -0
- package/src/agents/frontmatter.js +142 -0
- package/src/agents/frontmatter.js.map +1 -0
- package/src/agents/identity.d.ts +8 -0
- package/src/agents/identity.d.ts.map +1 -0
- package/src/agents/identity.js +30 -0
- package/src/agents/identity.js.map +1 -0
- package/src/agents/proactive-skills.d.ts +35 -0
- package/src/agents/proactive-skills.d.ts.map +1 -0
- package/src/agents/proactive-skills.js +154 -0
- package/src/agents/proactive-skills.js.map +1 -0
- package/src/agents/runtime-agent-events.d.ts +27 -0
- package/src/agents/runtime-agent-events.d.ts.map +1 -0
- package/src/agents/runtime-agent-events.js +53 -0
- package/src/agents/runtime-agent-events.js.map +1 -0
- package/src/agents/runtime-agent-registry.d.ts +59 -0
- package/src/agents/runtime-agent-registry.d.ts.map +1 -0
- package/src/agents/runtime-agent-registry.js +390 -0
- package/src/agents/runtime-agent-registry.js.map +1 -0
- package/src/agents/skills.d.ts +33 -0
- package/src/agents/skills.d.ts.map +1 -0
- package/src/agents/skills.js +685 -0
- package/src/agents/skills.js.map +1 -0
- package/src/api/agents.d.ts +5 -0
- package/src/api/agents.d.ts.map +1 -0
- package/src/api/agents.js +3 -0
- package/src/api/agents.js.map +1 -0
- package/src/api/background-work.d.ts +39 -0
- package/src/api/background-work.d.ts.map +1 -0
- package/src/api/background-work.js +165 -0
- package/src/api/background-work.js.map +1 -0
- package/src/api/capability-ceiling.d.ts +2 -0
- package/src/api/capability-ceiling.d.ts.map +1 -0
- package/src/api/capability-ceiling.js +2 -0
- package/src/api/capability-ceiling.js.map +1 -0
- package/src/api/child-tool-plan.d.ts +2 -0
- package/src/api/child-tool-plan.d.ts.map +1 -0
- package/src/api/child-tool-plan.js +2 -0
- package/src/api/child-tool-plan.js.map +1 -0
- package/src/api/control-channel.d.ts +2 -0
- package/src/api/control-channel.d.ts.map +1 -0
- package/src/api/control-channel.js +2 -0
- package/src/api/control-channel.js.map +1 -0
- package/src/api/delegation.d.ts +99 -0
- package/src/api/delegation.d.ts.map +1 -0
- package/src/api/delegation.js +9 -0
- package/src/api/delegation.js.map +1 -0
- package/src/api/external-job-provider.d.ts +58 -0
- package/src/api/external-job-provider.d.ts.map +1 -0
- package/src/api/external-job-provider.js +140 -0
- package/src/api/external-job-provider.js.map +1 -0
- package/src/api/external-runs.d.ts +48 -0
- package/src/api/external-runs.d.ts.map +1 -0
- package/src/api/external-runs.js +245 -0
- package/src/api/external-runs.js.map +1 -0
- package/src/api/intercom-bridge.d.ts +2 -0
- package/src/api/intercom-bridge.d.ts.map +1 -0
- package/src/api/intercom-bridge.js +2 -0
- package/src/api/intercom-bridge.js.map +1 -0
- package/src/api/preflight.d.ts +173 -0
- package/src/api/preflight.d.ts.map +1 -0
- package/src/api/preflight.js +362 -0
- package/src/api/preflight.js.map +1 -0
- package/src/api/project-panes.d.ts +8 -0
- package/src/api/project-panes.d.ts.map +1 -0
- package/src/api/project-panes.js +8 -0
- package/src/api/project-panes.js.map +1 -0
- package/src/api/required-child-extensions.d.ts +2 -0
- package/src/api/required-child-extensions.d.ts.map +1 -0
- package/src/api/required-child-extensions.js +2 -0
- package/src/api/required-child-extensions.js.map +1 -0
- package/src/api/shared-types.d.ts +2 -0
- package/src/api/shared-types.d.ts.map +1 -0
- package/src/api/shared-types.js +2 -0
- package/src/api/shared-types.js.map +1 -0
- package/src/api/workflow-resources.d.ts +3 -0
- package/src/api/workflow-resources.d.ts.map +1 -0
- package/src/api/workflow-resources.js +2 -0
- package/src/api/workflow-resources.js.map +1 -0
- package/src/extension/config.d.ts +8 -0
- package/src/extension/config.d.ts.map +1 -0
- package/src/extension/config.js +245 -0
- package/src/extension/config.js.map +1 -0
- package/src/extension/control-notices.d.ts +19 -0
- package/src/extension/control-notices.d.ts.map +1 -0
- package/src/extension/control-notices.js +34 -0
- package/src/extension/control-notices.js.map +1 -0
- package/src/extension/doctor.d.ts +33 -0
- package/src/extension/doctor.d.ts.map +1 -0
- package/src/extension/doctor.js +231 -0
- package/src/extension/doctor.js.map +1 -0
- package/src/extension/fanout-child.d.ts +7 -0
- package/src/extension/fanout-child.d.ts.map +1 -0
- package/src/extension/fanout-child.js +261 -0
- package/src/extension/fanout-child.js.map +1 -0
- package/src/extension/herdr-pi-bridge.d.ts +17 -0
- package/src/extension/herdr-pi-bridge.d.ts.map +1 -0
- package/src/extension/herdr-pi-bridge.js +243 -0
- package/src/extension/herdr-pi-bridge.js.map +1 -0
- package/src/extension/index.d.ts +20 -0
- package/src/extension/index.d.ts.map +1 -0
- package/src/extension/index.js +1108 -0
- package/src/extension/index.js.map +1 -0
- package/src/extension/public-execution.d.ts +62 -0
- package/src/extension/public-execution.d.ts.map +1 -0
- package/src/extension/public-execution.js +174 -0
- package/src/extension/public-execution.js.map +1 -0
- package/src/extension/rpc.d.ts +83 -0
- package/src/extension/rpc.d.ts.map +1 -0
- package/src/extension/rpc.js +687 -0
- package/src/extension/rpc.js.map +1 -0
- package/src/extension/schemas.d.ts +252 -0
- package/src/extension/schemas.d.ts.map +1 -0
- package/src/extension/schemas.js +396 -0
- package/src/extension/schemas.js.map +1 -0
- package/src/extension/steering-notices.d.ts +15 -0
- package/src/extension/steering-notices.d.ts.map +1 -0
- package/src/extension/steering-notices.js +23 -0
- package/src/extension/steering-notices.js.map +1 -0
- package/src/extension/subagent-guide.d.ts +4 -0
- package/src/extension/subagent-guide.d.ts.map +1 -0
- package/src/extension/subagent-guide.js +35 -0
- package/src/extension/subagent-guide.js.map +1 -0
- package/src/extension/tool-description.d.ts +20 -0
- package/src/extension/tool-description.d.ts.map +1 -0
- package/src/extension/tool-description.js +160 -0
- package/src/extension/tool-description.js.map +1 -0
- package/src/extension/tool-result.d.ts +10 -0
- package/src/extension/tool-result.d.ts.map +1 -0
- package/src/extension/tool-result.js +17 -0
- package/src/extension/tool-result.js.map +1 -0
- package/src/inspectors/actions.d.ts +23 -0
- package/src/inspectors/actions.d.ts.map +1 -0
- package/src/inspectors/actions.js +155 -0
- package/src/inspectors/actions.js.map +1 -0
- package/src/inspectors/ghostty/actions.d.ts +12 -0
- package/src/inspectors/ghostty/actions.d.ts.map +1 -0
- package/src/inspectors/ghostty/actions.js +63 -0
- package/src/inspectors/ghostty/actions.js.map +1 -0
- package/src/inspectors/ghostty/plugin.d.ts +8 -0
- package/src/inspectors/ghostty/plugin.d.ts.map +1 -0
- package/src/inspectors/ghostty/plugin.js +24 -0
- package/src/inspectors/ghostty/plugin.js.map +1 -0
- package/src/inspectors/herdr/actions.d.ts +26 -0
- package/src/inspectors/herdr/actions.d.ts.map +1 -0
- package/src/inspectors/herdr/actions.js +134 -0
- package/src/inspectors/herdr/actions.js.map +1 -0
- package/src/inspectors/herdr/client.d.ts +42 -0
- package/src/inspectors/herdr/client.d.ts.map +1 -0
- package/src/inspectors/herdr/client.js +130 -0
- package/src/inspectors/herdr/client.js.map +1 -0
- package/src/inspectors/herdr/focus.d.ts +25 -0
- package/src/inspectors/herdr/focus.d.ts.map +1 -0
- package/src/inspectors/herdr/focus.js +50 -0
- package/src/inspectors/herdr/focus.js.map +1 -0
- package/src/inspectors/herdr/plugin.d.ts +7 -0
- package/src/inspectors/herdr/plugin.d.ts.map +1 -0
- package/src/inspectors/herdr/plugin.js +15 -0
- package/src/inspectors/herdr/plugin.js.map +1 -0
- package/src/inspectors/herdr/project-panes.d.ts +137 -0
- package/src/inspectors/herdr/project-panes.d.ts.map +1 -0
- package/src/inspectors/herdr/project-panes.js +608 -0
- package/src/inspectors/herdr/project-panes.js.map +1 -0
- package/src/inspectors/inspector-runner.d.ts +24 -0
- package/src/inspectors/inspector-runner.d.ts.map +1 -0
- package/src/inspectors/inspector-runner.js +162 -0
- package/src/inspectors/inspector-runner.js.map +1 -0
- package/src/inspectors/plugins.d.ts +4 -0
- package/src/inspectors/plugins.d.ts.map +1 -0
- package/src/inspectors/plugins.js +7 -0
- package/src/inspectors/plugins.js.map +1 -0
- package/src/inspectors/session-roots-codec.d.ts +16 -0
- package/src/inspectors/session-roots-codec.d.ts.map +1 -0
- package/src/inspectors/session-roots-codec.js +33 -0
- package/src/inspectors/session-roots-codec.js.map +1 -0
- package/src/inspectors/shell-command.d.ts +2 -0
- package/src/inspectors/shell-command.d.ts.map +1 -0
- package/src/inspectors/shell-command.js +17 -0
- package/src/inspectors/shell-command.js.map +1 -0
- package/src/inspectors/types.d.ts +49 -0
- package/src/inspectors/types.d.ts.map +1 -0
- package/src/inspectors/types.js +2 -0
- package/src/inspectors/types.js.map +1 -0
- package/src/integrations/herdr-status.d.ts +46 -0
- package/src/integrations/herdr-status.d.ts.map +1 -0
- package/src/integrations/herdr-status.js +371 -0
- package/src/integrations/herdr-status.js.map +1 -0
- package/src/integrations/pi-web-session-liveness.d.ts +20 -0
- package/src/integrations/pi-web-session-liveness.d.ts.map +1 -0
- package/src/integrations/pi-web-session-liveness.js +54 -0
- package/src/integrations/pi-web-session-liveness.js.map +1 -0
- package/src/intercom/intercom-bridge.d.ts +59 -0
- package/src/intercom/intercom-bridge.d.ts.map +1 -0
- package/src/intercom/intercom-bridge.js +192 -0
- package/src/intercom/intercom-bridge.js.map +1 -0
- package/src/intercom/native-supervisor-channel.d.ts +64 -0
- package/src/intercom/native-supervisor-channel.d.ts.map +1 -0
- package/src/intercom/native-supervisor-channel.js +894 -0
- package/src/intercom/native-supervisor-channel.js.map +1 -0
- package/src/intercom/result-intercom.d.ts +36 -0
- package/src/intercom/result-intercom.d.ts.map +1 -0
- package/src/intercom/result-intercom.js +372 -0
- package/src/intercom/result-intercom.js.map +1 -0
- package/src/intercom/supervisor-ui.d.ts +40 -0
- package/src/intercom/supervisor-ui.d.ts.map +1 -0
- package/src/intercom/supervisor-ui.js +202 -0
- package/src/intercom/supervisor-ui.js.map +1 -0
- package/src/missions/actions.d.ts +55 -0
- package/src/missions/actions.d.ts.map +1 -0
- package/src/missions/actions.js +396 -0
- package/src/missions/actions.js.map +1 -0
- package/src/missions/goal-driver.d.ts +16 -0
- package/src/missions/goal-driver.d.ts.map +1 -0
- package/src/missions/goal-driver.js +157 -0
- package/src/missions/goal-driver.js.map +1 -0
- package/src/missions/lifecycle.d.ts +40 -0
- package/src/missions/lifecycle.d.ts.map +1 -0
- package/src/missions/lifecycle.js +352 -0
- package/src/missions/lifecycle.js.map +1 -0
- package/src/missions/store.d.ts +22 -0
- package/src/missions/store.d.ts.map +1 -0
- package/src/missions/store.js +573 -0
- package/src/missions/store.js.map +1 -0
- package/src/missions/types.d.ts +168 -0
- package/src/missions/types.d.ts.map +1 -0
- package/src/missions/types.js +10 -0
- package/src/missions/types.js.map +1 -0
- package/src/missions/workflow-state.d.ts +15 -0
- package/src/missions/workflow-state.d.ts.map +1 -0
- package/src/missions/workflow-state.js +274 -0
- package/src/missions/workflow-state.js.map +1 -0
- package/src/policy/authority.d.ts +10 -0
- package/src/policy/authority.d.ts.map +1 -0
- package/src/policy/authority.js +42 -0
- package/src/policy/authority.js.map +1 -0
- package/src/profiles/profiles.d.ts +135 -0
- package/src/profiles/profiles.d.ts.map +1 -0
- package/src/profiles/profiles.js +520 -0
- package/src/profiles/profiles.js.map +1 -0
- package/src/runs/background/active-async-capacity.d.ts +100 -0
- package/src/runs/background/active-async-capacity.d.ts.map +1 -0
- package/src/runs/background/active-async-capacity.js +492 -0
- package/src/runs/background/active-async-capacity.js.map +1 -0
- package/src/runs/background/active-run-index.d.ts +13 -0
- package/src/runs/background/active-run-index.d.ts.map +1 -0
- package/src/runs/background/active-run-index.js +158 -0
- package/src/runs/background/active-run-index.js.map +1 -0
- package/src/runs/background/async-execution.d.ts +274 -0
- package/src/runs/background/async-execution.d.ts.map +1 -0
- package/src/runs/background/async-execution.js +1989 -0
- package/src/runs/background/async-execution.js.map +1 -0
- package/src/runs/background/async-job-tracker.d.ts +28 -0
- package/src/runs/background/async-job-tracker.d.ts.map +1 -0
- package/src/runs/background/async-job-tracker.js +876 -0
- package/src/runs/background/async-job-tracker.js.map +1 -0
- package/src/runs/background/async-resume.d.ts +59 -0
- package/src/runs/background/async-resume.d.ts.map +1 -0
- package/src/runs/background/async-resume.js +670 -0
- package/src/runs/background/async-resume.js.map +1 -0
- package/src/runs/background/async-retention.d.ts +45 -0
- package/src/runs/background/async-retention.d.ts.map +1 -0
- package/src/runs/background/async-retention.js +884 -0
- package/src/runs/background/async-retention.js.map +1 -0
- package/src/runs/background/async-status-snapshot.d.ts +10 -0
- package/src/runs/background/async-status-snapshot.d.ts.map +1 -0
- package/src/runs/background/async-status-snapshot.js +25 -0
- package/src/runs/background/async-status-snapshot.js.map +1 -0
- package/src/runs/background/async-status.d.ts +169 -0
- package/src/runs/background/async-status.d.ts.map +1 -0
- package/src/runs/background/async-status.js +673 -0
- package/src/runs/background/async-status.js.map +1 -0
- package/src/runs/background/auto-drain.d.ts +17 -0
- package/src/runs/background/auto-drain.d.ts.map +1 -0
- package/src/runs/background/auto-drain.js +73 -0
- package/src/runs/background/auto-drain.js.map +1 -0
- package/src/runs/background/binary-bootstrap.d.ts +9 -0
- package/src/runs/background/binary-bootstrap.d.ts.map +1 -0
- package/src/runs/background/binary-bootstrap.js +41 -0
- package/src/runs/background/binary-bootstrap.js.map +1 -0
- package/src/runs/background/chain-append.d.ts +35 -0
- package/src/runs/background/chain-append.d.ts.map +1 -0
- package/src/runs/background/chain-append.js +300 -0
- package/src/runs/background/chain-append.js.map +1 -0
- package/src/runs/background/chain-root-attachment.d.ts +49 -0
- package/src/runs/background/chain-root-attachment.d.ts.map +1 -0
- package/src/runs/background/chain-root-attachment.js +184 -0
- package/src/runs/background/chain-root-attachment.js.map +1 -0
- package/src/runs/background/completion-batcher.d.ts +52 -0
- package/src/runs/background/completion-batcher.d.ts.map +1 -0
- package/src/runs/background/completion-batcher.js +120 -0
- package/src/runs/background/completion-batcher.js.map +1 -0
- package/src/runs/background/completion-dedupe.d.ts +14 -0
- package/src/runs/background/completion-dedupe.d.ts.map +1 -0
- package/src/runs/background/completion-dedupe.js +49 -0
- package/src/runs/background/completion-dedupe.js.map +1 -0
- package/src/runs/background/completion-replay.d.ts +48 -0
- package/src/runs/background/completion-replay.d.ts.map +1 -0
- package/src/runs/background/completion-replay.js +267 -0
- package/src/runs/background/completion-replay.js.map +1 -0
- package/src/runs/background/control-channel.d.ts +156 -0
- package/src/runs/background/control-channel.d.ts.map +1 -0
- package/src/runs/background/control-channel.js +521 -0
- package/src/runs/background/control-channel.js.map +1 -0
- package/src/runs/background/fleet-view.d.ts +64 -0
- package/src/runs/background/fleet-view.d.ts.map +1 -0
- package/src/runs/background/fleet-view.js +648 -0
- package/src/runs/background/fleet-view.js.map +1 -0
- package/src/runs/background/index-segment.d.ts +16 -0
- package/src/runs/background/index-segment.d.ts.map +1 -0
- package/src/runs/background/index-segment.js +59 -0
- package/src/runs/background/index-segment.js.map +1 -0
- package/src/runs/background/inspect-rpc.d.ts +60 -0
- package/src/runs/background/inspect-rpc.d.ts.map +1 -0
- package/src/runs/background/inspect-rpc.js +406 -0
- package/src/runs/background/inspect-rpc.js.map +1 -0
- package/src/runs/background/notify.d.ts +162 -0
- package/src/runs/background/notify.d.ts.map +1 -0
- package/src/runs/background/notify.js +665 -0
- package/src/runs/background/notify.js.map +1 -0
- package/src/runs/background/owned-process-tree.d.ts +11 -0
- package/src/runs/background/owned-process-tree.d.ts.map +1 -0
- package/src/runs/background/owned-process-tree.js +117 -0
- package/src/runs/background/owned-process-tree.js.map +1 -0
- package/src/runs/background/parallel-groups.d.ts +4 -0
- package/src/runs/background/parallel-groups.d.ts.map +1 -0
- package/src/runs/background/parallel-groups.js +47 -0
- package/src/runs/background/parallel-groups.js.map +1 -0
- package/src/runs/background/process-terminal.d.ts +34 -0
- package/src/runs/background/process-terminal.d.ts.map +1 -0
- package/src/runs/background/process-terminal.js +305 -0
- package/src/runs/background/process-terminal.js.map +1 -0
- package/src/runs/background/result-delivery-ownership.d.ts +11 -0
- package/src/runs/background/result-delivery-ownership.d.ts.map +1 -0
- package/src/runs/background/result-delivery-ownership.js +37 -0
- package/src/runs/background/result-delivery-ownership.js.map +1 -0
- package/src/runs/background/result-files.d.ts +33 -0
- package/src/runs/background/result-files.d.ts.map +1 -0
- package/src/runs/background/result-files.js +528 -0
- package/src/runs/background/result-files.js.map +1 -0
- package/src/runs/background/result-watcher.d.ts +87 -0
- package/src/runs/background/result-watcher.d.ts.map +1 -0
- package/src/runs/background/result-watcher.js +764 -0
- package/src/runs/background/result-watcher.js.map +1 -0
- package/src/runs/background/resume-guidance.d.ts +5 -0
- package/src/runs/background/resume-guidance.d.ts.map +1 -0
- package/src/runs/background/resume-guidance.js +57 -0
- package/src/runs/background/resume-guidance.js.map +1 -0
- package/src/runs/background/retained-children.d.ts +25 -0
- package/src/runs/background/retained-children.d.ts.map +1 -0
- package/src/runs/background/retained-children.js +128 -0
- package/src/runs/background/retained-children.js.map +1 -0
- package/src/runs/background/retained-nested-route-tracker.d.ts +13 -0
- package/src/runs/background/retained-nested-route-tracker.d.ts.map +1 -0
- package/src/runs/background/retained-nested-route-tracker.js +91 -0
- package/src/runs/background/retained-nested-route-tracker.js.map +1 -0
- package/src/runs/background/run-child-session.d.ts +123 -0
- package/src/runs/background/run-child-session.d.ts.map +1 -0
- package/src/runs/background/run-child-session.js +602 -0
- package/src/runs/background/run-child-session.js.map +1 -0
- package/src/runs/background/run-id-query.d.ts +4 -0
- package/src/runs/background/run-id-query.d.ts.map +1 -0
- package/src/runs/background/run-id-query.js +7 -0
- package/src/runs/background/run-id-query.js.map +1 -0
- package/src/runs/background/run-id-resolver.d.ts +23 -0
- package/src/runs/background/run-id-resolver.d.ts.map +1 -0
- package/src/runs/background/run-id-resolver.js +170 -0
- package/src/runs/background/run-id-resolver.js.map +1 -0
- package/src/runs/background/run-status.d.ts +26 -0
- package/src/runs/background/run-status.d.ts.map +1 -0
- package/src/runs/background/run-status.js +826 -0
- package/src/runs/background/run-status.js.map +1 -0
- package/src/runs/background/runner-aliases.d.ts +17 -0
- package/src/runs/background/runner-aliases.d.ts.map +1 -0
- package/src/runs/background/runner-aliases.js +141 -0
- package/src/runs/background/runner-aliases.js.map +1 -0
- package/src/runs/background/runner-child-launch.d.ts +24 -0
- package/src/runs/background/runner-child-launch.d.ts.map +1 -0
- package/src/runs/background/runner-child-launch.js +68 -0
- package/src/runs/background/runner-child-launch.js.map +1 -0
- package/src/runs/background/runner-child-sessions.d.ts +7 -0
- package/src/runs/background/runner-child-sessions.d.ts.map +1 -0
- package/src/runs/background/runner-child-sessions.js +35 -0
- package/src/runs/background/runner-child-sessions.js.map +1 -0
- package/src/runs/background/runner-http-dispatcher.d.ts +43 -0
- package/src/runs/background/runner-http-dispatcher.d.ts.map +1 -0
- package/src/runs/background/runner-http-dispatcher.js +114 -0
- package/src/runs/background/runner-http-dispatcher.js.map +1 -0
- package/src/runs/background/scheduled-runs.d.ts +116 -0
- package/src/runs/background/scheduled-runs.d.ts.map +1 -0
- package/src/runs/background/scheduled-runs.js +1024 -0
- package/src/runs/background/scheduled-runs.js.map +1 -0
- package/src/runs/background/stale-run-reconciler.d.ts +37 -0
- package/src/runs/background/stale-run-reconciler.d.ts.map +1 -0
- package/src/runs/background/stale-run-reconciler.js +393 -0
- package/src/runs/background/stale-run-reconciler.js.map +1 -0
- package/src/runs/background/steering.d.ts +52 -0
- package/src/runs/background/steering.d.ts.map +1 -0
- package/src/runs/background/steering.js +247 -0
- package/src/runs/background/steering.js.map +1 -0
- package/src/runs/background/subagent-runner.d.ts +201 -0
- package/src/runs/background/subagent-runner.d.ts.map +1 -0
- package/src/runs/background/subagent-runner.js +5134 -0
- package/src/runs/background/subagent-runner.js.map +1 -0
- package/src/runs/background/subagent-wait.d.ts +122 -0
- package/src/runs/background/subagent-wait.d.ts.map +1 -0
- package/src/runs/background/subagent-wait.js +735 -0
- package/src/runs/background/subagent-wait.js.map +1 -0
- package/src/runs/background/terminal-run-index.d.ts +8 -0
- package/src/runs/background/terminal-run-index.d.ts.map +1 -0
- package/src/runs/background/terminal-run-index.js +123 -0
- package/src/runs/background/terminal-run-index.js.map +1 -0
- package/src/runs/background/top-level-async.d.ts +8 -0
- package/src/runs/background/top-level-async.d.ts.map +1 -0
- package/src/runs/background/top-level-async.js +6 -0
- package/src/runs/background/top-level-async.js.map +1 -0
- package/src/runs/background/wait-completions.d.ts +29 -0
- package/src/runs/background/wait-completions.d.ts.map +1 -0
- package/src/runs/background/wait-completions.js +264 -0
- package/src/runs/background/wait-completions.js.map +1 -0
- package/src/runs/background/wait-config.d.ts +9 -0
- package/src/runs/background/wait-config.d.ts.map +1 -0
- package/src/runs/background/wait-config.js +47 -0
- package/src/runs/background/wait-config.js.map +1 -0
- package/src/runs/background/wait-subscriptions.d.ts +27 -0
- package/src/runs/background/wait-subscriptions.d.ts.map +1 -0
- package/src/runs/background/wait-subscriptions.js +337 -0
- package/src/runs/background/wait-subscriptions.js.map +1 -0
- package/src/runs/background/wait-tool.d.ts +7 -0
- package/src/runs/background/wait-tool.d.ts.map +1 -0
- package/src/runs/background/wait-tool.js +36 -0
- package/src/runs/background/wait-tool.js.map +1 -0
- package/src/runs/foreground/async-dismiss-action.d.ts +7 -0
- package/src/runs/foreground/async-dismiss-action.d.ts.map +1 -0
- package/src/runs/foreground/async-dismiss-action.js +82 -0
- package/src/runs/foreground/async-dismiss-action.js.map +1 -0
- package/src/runs/foreground/async-steering-action.d.ts +32 -0
- package/src/runs/foreground/async-steering-action.d.ts.map +1 -0
- package/src/runs/foreground/async-steering-action.js +270 -0
- package/src/runs/foreground/async-steering-action.js.map +1 -0
- package/src/runs/foreground/async-stop-action.d.ts +7 -0
- package/src/runs/foreground/async-stop-action.d.ts.map +1 -0
- package/src/runs/foreground/async-stop-action.js +171 -0
- package/src/runs/foreground/async-stop-action.js.map +1 -0
- package/src/runs/foreground/execution.d.ts +11 -0
- package/src/runs/foreground/execution.d.ts.map +1 -0
- package/src/runs/foreground/execution.js +2186 -0
- package/src/runs/foreground/execution.js.map +1 -0
- package/src/runs/foreground/foreground-control.d.ts +25 -0
- package/src/runs/foreground/foreground-control.d.ts.map +1 -0
- package/src/runs/foreground/foreground-control.js +139 -0
- package/src/runs/foreground/foreground-control.js.map +1 -0
- package/src/runs/foreground/foreground-history.d.ts +12 -0
- package/src/runs/foreground/foreground-history.d.ts.map +1 -0
- package/src/runs/foreground/foreground-history.js +165 -0
- package/src/runs/foreground/foreground-history.js.map +1 -0
- package/src/runs/foreground/prompt-audit.d.ts +33 -0
- package/src/runs/foreground/prompt-audit.d.ts.map +1 -0
- package/src/runs/foreground/prompt-audit.js +143 -0
- package/src/runs/foreground/prompt-audit.js.map +1 -0
- package/src/runs/foreground/subagent-executor.d.ts +296 -0
- package/src/runs/foreground/subagent-executor.d.ts.map +1 -0
- package/src/runs/foreground/subagent-executor.js +7047 -0
- package/src/runs/foreground/subagent-executor.js.map +1 -0
- package/src/runs/foreground/workflow-detach-reconcile.d.ts +16 -0
- package/src/runs/foreground/workflow-detach-reconcile.d.ts.map +1 -0
- package/src/runs/foreground/workflow-detach-reconcile.js +284 -0
- package/src/runs/foreground/workflow-detach-reconcile.js.map +1 -0
- package/src/runs/foreground/workflow-foreground-steering.d.ts +44 -0
- package/src/runs/foreground/workflow-foreground-steering.d.ts.map +1 -0
- package/src/runs/foreground/workflow-foreground-steering.js +149 -0
- package/src/runs/foreground/workflow-foreground-steering.js.map +1 -0
- package/src/runs/shared/abort-recovery.d.ts +27 -0
- package/src/runs/shared/abort-recovery.d.ts.map +1 -0
- package/src/runs/shared/abort-recovery.js +109 -0
- package/src/runs/shared/abort-recovery.js.map +1 -0
- package/src/runs/shared/acceptance.d.ts +145 -0
- package/src/runs/shared/acceptance.d.ts.map +1 -0
- package/src/runs/shared/acceptance.js +1650 -0
- package/src/runs/shared/acceptance.js.map +1 -0
- package/src/runs/shared/agent-contract.d.ts +6 -0
- package/src/runs/shared/agent-contract.d.ts.map +1 -0
- package/src/runs/shared/agent-contract.js +36 -0
- package/src/runs/shared/agent-contract.js.map +1 -0
- package/src/runs/shared/async-status-projection.d.ts +94 -0
- package/src/runs/shared/async-status-projection.d.ts.map +1 -0
- package/src/runs/shared/async-status-projection.js +542 -0
- package/src/runs/shared/async-status-projection.js.map +1 -0
- package/src/runs/shared/background-process-options.d.ts +5 -0
- package/src/runs/shared/background-process-options.d.ts.map +1 -0
- package/src/runs/shared/background-process-options.js +7 -0
- package/src/runs/shared/background-process-options.js.map +1 -0
- package/src/runs/shared/capability-ceiling.d.ts +58 -0
- package/src/runs/shared/capability-ceiling.d.ts.map +1 -0
- package/src/runs/shared/capability-ceiling.js +179 -0
- package/src/runs/shared/capability-ceiling.js.map +1 -0
- package/src/runs/shared/chain-outputs.d.ts +19 -0
- package/src/runs/shared/chain-outputs.d.ts.map +1 -0
- package/src/runs/shared/chain-outputs.js +105 -0
- package/src/runs/shared/chain-outputs.js.map +1 -0
- package/src/runs/shared/child-hooks.d.ts +34 -0
- package/src/runs/shared/child-hooks.d.ts.map +1 -0
- package/src/runs/shared/child-hooks.js +188 -0
- package/src/runs/shared/child-hooks.js.map +1 -0
- package/src/runs/shared/child-identity.d.ts +24 -0
- package/src/runs/shared/child-identity.d.ts.map +1 -0
- package/src/runs/shared/child-identity.js +41 -0
- package/src/runs/shared/child-identity.js.map +1 -0
- package/src/runs/shared/child-launch-plan.d.ts +71 -0
- package/src/runs/shared/child-launch-plan.d.ts.map +1 -0
- package/src/runs/shared/child-launch-plan.js +89 -0
- package/src/runs/shared/child-launch-plan.js.map +1 -0
- package/src/runs/shared/child-launch.d.ts +114 -0
- package/src/runs/shared/child-launch.d.ts.map +1 -0
- package/src/runs/shared/child-launch.js +231 -0
- package/src/runs/shared/child-launch.js.map +1 -0
- package/src/runs/shared/child-lifecycle.d.ts +14 -0
- package/src/runs/shared/child-lifecycle.d.ts.map +1 -0
- package/src/runs/shared/child-lifecycle.js +23 -0
- package/src/runs/shared/child-lifecycle.js.map +1 -0
- package/src/runs/shared/child-runtime-config.d.ts +102 -0
- package/src/runs/shared/child-runtime-config.d.ts.map +1 -0
- package/src/runs/shared/child-runtime-config.js +39 -0
- package/src/runs/shared/child-runtime-config.js.map +1 -0
- package/src/runs/shared/child-session.d.ts +155 -0
- package/src/runs/shared/child-session.d.ts.map +1 -0
- package/src/runs/shared/child-session.js +347 -0
- package/src/runs/shared/child-session.js.map +1 -0
- package/src/runs/shared/child-tool-plan.d.ts +73 -0
- package/src/runs/shared/child-tool-plan.d.ts.map +1 -0
- package/src/runs/shared/child-tool-plan.js +380 -0
- package/src/runs/shared/child-tool-plan.js.map +1 -0
- package/src/runs/shared/claude-code-adapter.d.ts +25 -0
- package/src/runs/shared/claude-code-adapter.d.ts.map +1 -0
- package/src/runs/shared/claude-code-adapter.js +120 -0
- package/src/runs/shared/claude-code-adapter.js.map +1 -0
- package/src/runs/shared/codex-exec-adapter.d.ts +26 -0
- package/src/runs/shared/codex-exec-adapter.d.ts.map +1 -0
- package/src/runs/shared/codex-exec-adapter.js +128 -0
- package/src/runs/shared/codex-exec-adapter.js.map +1 -0
- package/src/runs/shared/completion-evidence.d.ts +31 -0
- package/src/runs/shared/completion-evidence.d.ts.map +1 -0
- package/src/runs/shared/completion-evidence.js +54 -0
- package/src/runs/shared/completion-evidence.js.map +1 -0
- package/src/runs/shared/completion-guard.d.ts +35 -0
- package/src/runs/shared/completion-guard.d.ts.map +1 -0
- package/src/runs/shared/completion-guard.js +214 -0
- package/src/runs/shared/completion-guard.js.map +1 -0
- package/src/runs/shared/context-mode.d.ts +13 -0
- package/src/runs/shared/context-mode.d.ts.map +1 -0
- package/src/runs/shared/context-mode.js +39 -0
- package/src/runs/shared/context-mode.js.map +1 -0
- package/src/runs/shared/cursor-agent-adapter.d.ts +27 -0
- package/src/runs/shared/cursor-agent-adapter.d.ts.map +1 -0
- package/src/runs/shared/cursor-agent-adapter.js +100 -0
- package/src/runs/shared/cursor-agent-adapter.js.map +1 -0
- package/src/runs/shared/dynamic-fanout.d.ts +50 -0
- package/src/runs/shared/dynamic-fanout.d.ts.map +1 -0
- package/src/runs/shared/dynamic-fanout.js +274 -0
- package/src/runs/shared/dynamic-fanout.js.map +1 -0
- package/src/runs/shared/effective-system-prompt.d.ts +18 -0
- package/src/runs/shared/effective-system-prompt.d.ts.map +1 -0
- package/src/runs/shared/effective-system-prompt.js +23 -0
- package/src/runs/shared/effective-system-prompt.js.map +1 -0
- package/src/runs/shared/extension-bindings.d.ts +17 -0
- package/src/runs/shared/extension-bindings.d.ts.map +1 -0
- package/src/runs/shared/extension-bindings.js +83 -0
- package/src/runs/shared/extension-bindings.js.map +1 -0
- package/src/runs/shared/external-cli-contract.d.ts +30 -0
- package/src/runs/shared/external-cli-contract.d.ts.map +1 -0
- package/src/runs/shared/external-cli-contract.js +146 -0
- package/src/runs/shared/external-cli-contract.js.map +1 -0
- package/src/runs/shared/external-cli-preflight.d.ts +32 -0
- package/src/runs/shared/external-cli-preflight.d.ts.map +1 -0
- package/src/runs/shared/external-cli-preflight.js +116 -0
- package/src/runs/shared/external-cli-preflight.js.map +1 -0
- package/src/runs/shared/external-cli-runner.d.ts +66 -0
- package/src/runs/shared/external-cli-runner.d.ts.map +1 -0
- package/src/runs/shared/external-cli-runner.js +421 -0
- package/src/runs/shared/external-cli-runner.js.map +1 -0
- package/src/runs/shared/external-job-bridge.d.ts +18 -0
- package/src/runs/shared/external-job-bridge.d.ts.map +1 -0
- package/src/runs/shared/external-job-bridge.js +424 -0
- package/src/runs/shared/external-job-bridge.js.map +1 -0
- package/src/runs/shared/external-job-runner.d.ts +45 -0
- package/src/runs/shared/external-job-runner.d.ts.map +1 -0
- package/src/runs/shared/external-job-runner.js +353 -0
- package/src/runs/shared/external-job-runner.js.map +1 -0
- package/src/runs/shared/fast-mode-extension.d.ts +4 -0
- package/src/runs/shared/fast-mode-extension.d.ts.map +1 -0
- package/src/runs/shared/fast-mode-extension.js +9 -0
- package/src/runs/shared/fast-mode-extension.js.map +1 -0
- package/src/runs/shared/herdr-connection.d.ts +71 -0
- package/src/runs/shared/herdr-connection.d.ts.map +1 -0
- package/src/runs/shared/herdr-connection.js +258 -0
- package/src/runs/shared/herdr-connection.js.map +1 -0
- package/src/runs/shared/herdr-external-adapters.d.ts +148 -0
- package/src/runs/shared/herdr-external-adapters.d.ts.map +1 -0
- package/src/runs/shared/herdr-external-adapters.js +405 -0
- package/src/runs/shared/herdr-external-adapters.js.map +1 -0
- package/src/runs/shared/herdr-machine.d.ts +48 -0
- package/src/runs/shared/herdr-machine.d.ts.map +1 -0
- package/src/runs/shared/herdr-machine.js +247 -0
- package/src/runs/shared/herdr-machine.js.map +1 -0
- package/src/runs/shared/herdr-pi-protocol.d.ts +22 -0
- package/src/runs/shared/herdr-pi-protocol.d.ts.map +1 -0
- package/src/runs/shared/herdr-pi-protocol.js +58 -0
- package/src/runs/shared/herdr-pi-protocol.js.map +1 -0
- package/src/runs/shared/herdr-placed-run.d.ts +267 -0
- package/src/runs/shared/herdr-placed-run.d.ts.map +1 -0
- package/src/runs/shared/herdr-placed-run.js +716 -0
- package/src/runs/shared/herdr-placed-run.js.map +1 -0
- package/src/runs/shared/host-step-status.d.ts +34 -0
- package/src/runs/shared/host-step-status.d.ts.map +1 -0
- package/src/runs/shared/host-step-status.js +245 -0
- package/src/runs/shared/host-step-status.js.map +1 -0
- package/src/runs/shared/lane-metadata.d.ts +24 -0
- package/src/runs/shared/lane-metadata.d.ts.map +1 -0
- package/src/runs/shared/lane-metadata.js +127 -0
- package/src/runs/shared/lane-metadata.js.map +1 -0
- package/src/runs/shared/launch-cwd.d.ts +2 -0
- package/src/runs/shared/launch-cwd.d.ts.map +1 -0
- package/src/runs/shared/launch-cwd.js +17 -0
- package/src/runs/shared/launch-cwd.js.map +1 -0
- package/src/runs/shared/llm-intent-arbiter.d.ts +48 -0
- package/src/runs/shared/llm-intent-arbiter.d.ts.map +1 -0
- package/src/runs/shared/llm-intent-arbiter.js +235 -0
- package/src/runs/shared/llm-intent-arbiter.js.map +1 -0
- package/src/runs/shared/long-running-guard.d.ts +33 -0
- package/src/runs/shared/long-running-guard.d.ts.map +1 -0
- package/src/runs/shared/long-running-guard.js +199 -0
- package/src/runs/shared/long-running-guard.js.map +1 -0
- package/src/runs/shared/mcp-config-sources.d.ts +30 -0
- package/src/runs/shared/mcp-config-sources.d.ts.map +1 -0
- package/src/runs/shared/mcp-config-sources.js +419 -0
- package/src/runs/shared/mcp-config-sources.js.map +1 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +59 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts.map +1 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.js +400 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.js.map +1 -0
- package/src/runs/shared/mcp-direct-tool-grant.d.ts +41 -0
- package/src/runs/shared/mcp-direct-tool-grant.d.ts.map +1 -0
- package/src/runs/shared/mcp-direct-tool-grant.js +146 -0
- package/src/runs/shared/mcp-direct-tool-grant.js.map +1 -0
- package/src/runs/shared/model-resolution-diagnostic.d.ts +22 -0
- package/src/runs/shared/model-resolution-diagnostic.d.ts.map +1 -0
- package/src/runs/shared/model-resolution-diagnostic.js +65 -0
- package/src/runs/shared/model-resolution-diagnostic.js.map +1 -0
- package/src/runs/shared/model-resolution.d.ts +92 -0
- package/src/runs/shared/model-resolution.d.ts.map +1 -0
- package/src/runs/shared/model-resolution.js +343 -0
- package/src/runs/shared/model-resolution.js.map +1 -0
- package/src/runs/shared/model-scope.d.ts +68 -0
- package/src/runs/shared/model-scope.d.ts.map +1 -0
- package/src/runs/shared/model-scope.js +156 -0
- package/src/runs/shared/model-scope.js.map +1 -0
- package/src/runs/shared/mutation-evidence.d.ts +19 -0
- package/src/runs/shared/mutation-evidence.d.ts.map +1 -0
- package/src/runs/shared/mutation-evidence.js +199 -0
- package/src/runs/shared/mutation-evidence.js.map +1 -0
- package/src/runs/shared/nested-events.d.ts +134 -0
- package/src/runs/shared/nested-events.d.ts.map +1 -0
- package/src/runs/shared/nested-events.js +1056 -0
- package/src/runs/shared/nested-events.js.map +1 -0
- package/src/runs/shared/nested-path.d.ts +9 -0
- package/src/runs/shared/nested-path.d.ts.map +1 -0
- package/src/runs/shared/nested-path.js +35 -0
- package/src/runs/shared/nested-path.js.map +1 -0
- package/src/runs/shared/nested-render.d.ts +21 -0
- package/src/runs/shared/nested-render.d.ts.map +1 -0
- package/src/runs/shared/nested-render.js +116 -0
- package/src/runs/shared/nested-render.js.map +1 -0
- package/src/runs/shared/orca-progress-tabs.d.ts +33 -0
- package/src/runs/shared/orca-progress-tabs.d.ts.map +1 -0
- package/src/runs/shared/orca-progress-tabs.js +527 -0
- package/src/runs/shared/orca-progress-tabs.js.map +1 -0
- package/src/runs/shared/parallel-handoff.d.ts +73 -0
- package/src/runs/shared/parallel-handoff.d.ts.map +1 -0
- package/src/runs/shared/parallel-handoff.js +733 -0
- package/src/runs/shared/parallel-handoff.js.map +1 -0
- package/src/runs/shared/parallel-utils.d.ts +165 -0
- package/src/runs/shared/parallel-utils.d.ts.map +1 -0
- package/src/runs/shared/parallel-utils.js +126 -0
- package/src/runs/shared/parallel-utils.js.map +1 -0
- package/src/runs/shared/permissions.d.ts +13 -0
- package/src/runs/shared/permissions.d.ts.map +1 -0
- package/src/runs/shared/permissions.js +93 -0
- package/src/runs/shared/permissions.js.map +1 -0
- package/src/runs/shared/pi-spawn.d.ts +28 -0
- package/src/runs/shared/pi-spawn.d.ts.map +1 -0
- package/src/runs/shared/pi-spawn.js +156 -0
- package/src/runs/shared/pi-spawn.js.map +1 -0
- package/src/runs/shared/process-signal.d.ts +16 -0
- package/src/runs/shared/process-signal.d.ts.map +1 -0
- package/src/runs/shared/process-signal.js +22 -0
- package/src/runs/shared/process-signal.js.map +1 -0
- package/src/runs/shared/readonly-drain-observation.d.ts +26 -0
- package/src/runs/shared/readonly-drain-observation.d.ts.map +1 -0
- package/src/runs/shared/readonly-drain-observation.js +51 -0
- package/src/runs/shared/readonly-drain-observation.js.map +1 -0
- package/src/runs/shared/run-fanout-budget.d.ts +15 -0
- package/src/runs/shared/run-fanout-budget.d.ts.map +1 -0
- package/src/runs/shared/run-fanout-budget.js +259 -0
- package/src/runs/shared/run-fanout-budget.js.map +1 -0
- package/src/runs/shared/run-history.d.ts +20 -0
- package/src/runs/shared/run-history.d.ts.map +1 -0
- package/src/runs/shared/run-history.js +200 -0
- package/src/runs/shared/run-history.js.map +1 -0
- package/src/runs/shared/runtime-acknowledged-extensions.d.ts +8 -0
- package/src/runs/shared/runtime-acknowledged-extensions.d.ts.map +1 -0
- package/src/runs/shared/runtime-acknowledged-extensions.js +45 -0
- package/src/runs/shared/runtime-acknowledged-extensions.js.map +1 -0
- package/src/runs/shared/session-lease.d.ts +70 -0
- package/src/runs/shared/session-lease.d.ts.map +1 -0
- package/src/runs/shared/session-lease.js +251 -0
- package/src/runs/shared/session-lease.js.map +1 -0
- package/src/runs/shared/single-output.d.ts +61 -0
- package/src/runs/shared/single-output.d.ts.map +1 -0
- package/src/runs/shared/single-output.js +263 -0
- package/src/runs/shared/single-output.js.map +1 -0
- package/src/runs/shared/spawn-budget.d.ts +21 -0
- package/src/runs/shared/spawn-budget.d.ts.map +1 -0
- package/src/runs/shared/spawn-budget.js +94 -0
- package/src/runs/shared/spawn-budget.js.map +1 -0
- package/src/runs/shared/structured-output.d.ts +57 -0
- package/src/runs/shared/structured-output.d.ts.map +1 -0
- package/src/runs/shared/structured-output.js +391 -0
- package/src/runs/shared/structured-output.js.map +1 -0
- package/src/runs/shared/subagent-control.d.ts +50 -0
- package/src/runs/shared/subagent-control.d.ts.map +1 -0
- package/src/runs/shared/subagent-control.js +247 -0
- package/src/runs/shared/subagent-control.js.map +1 -0
- package/src/runs/shared/subagent-prompt-runtime.d.ts +28 -0
- package/src/runs/shared/subagent-prompt-runtime.d.ts.map +1 -0
- package/src/runs/shared/subagent-prompt-runtime.js +548 -0
- package/src/runs/shared/subagent-prompt-runtime.js.map +1 -0
- package/src/runs/shared/task-intent.d.ts +38 -0
- package/src/runs/shared/task-intent.d.ts.map +1 -0
- package/src/runs/shared/task-intent.js +213 -0
- package/src/runs/shared/task-intent.js.map +1 -0
- package/src/runs/shared/tool-availability.d.ts +17 -0
- package/src/runs/shared/tool-availability.d.ts.map +1 -0
- package/src/runs/shared/tool-availability.js +30 -0
- package/src/runs/shared/tool-availability.js.map +1 -0
- package/src/runs/shared/tool-budget.d.ts +22 -0
- package/src/runs/shared/tool-budget.d.ts.map +1 -0
- package/src/runs/shared/tool-budget.js +79 -0
- package/src/runs/shared/tool-budget.js.map +1 -0
- package/src/runs/shared/tool-timeout.d.ts +32 -0
- package/src/runs/shared/tool-timeout.d.ts.map +1 -0
- package/src/runs/shared/tool-timeout.js +74 -0
- package/src/runs/shared/tool-timeout.js.map +1 -0
- package/src/runs/shared/usage-budget.d.ts +8 -0
- package/src/runs/shared/usage-budget.d.ts.map +1 -0
- package/src/runs/shared/usage-budget.js +75 -0
- package/src/runs/shared/usage-budget.js.map +1 -0
- package/src/runs/shared/usage-reconciliation.d.ts +9 -0
- package/src/runs/shared/usage-reconciliation.d.ts.map +1 -0
- package/src/runs/shared/usage-reconciliation.js +72 -0
- package/src/runs/shared/usage-reconciliation.js.map +1 -0
- package/src/runs/shared/workflow-async-child-guidance.d.ts +4 -0
- package/src/runs/shared/workflow-async-child-guidance.d.ts.map +1 -0
- package/src/runs/shared/workflow-async-child-guidance.js +18 -0
- package/src/runs/shared/workflow-async-child-guidance.js.map +1 -0
- package/src/runs/shared/workflow-graph.d.ts +32 -0
- package/src/runs/shared/workflow-graph.d.ts.map +1 -0
- package/src/runs/shared/workflow-graph.js +222 -0
- package/src/runs/shared/workflow-graph.js.map +1 -0
- package/src/runs/shared/worktree-cleanup-plan.d.ts +78 -0
- package/src/runs/shared/worktree-cleanup-plan.d.ts.map +1 -0
- package/src/runs/shared/worktree-cleanup-plan.js +782 -0
- package/src/runs/shared/worktree-cleanup-plan.js.map +1 -0
- package/src/runs/shared/worktree-setup-command.d.ts +39 -0
- package/src/runs/shared/worktree-setup-command.d.ts.map +1 -0
- package/src/runs/shared/worktree-setup-command.js +201 -0
- package/src/runs/shared/worktree-setup-command.js.map +1 -0
- package/src/runs/shared/worktree.d.ts +179 -0
- package/src/runs/shared/worktree.d.ts.map +1 -0
- package/src/runs/shared/worktree.js +1333 -0
- package/src/runs/shared/worktree.js.map +1 -0
- package/src/shared/accessible-dir.d.ts +12 -0
- package/src/shared/accessible-dir.d.ts.map +1 -0
- package/src/shared/accessible-dir.js +37 -0
- package/src/shared/accessible-dir.js.map +1 -0
- package/src/shared/agent-stream-options.d.ts +6 -0
- package/src/shared/agent-stream-options.d.ts.map +1 -0
- package/src/shared/agent-stream-options.js +4 -0
- package/src/shared/agent-stream-options.js.map +1 -0
- package/src/shared/artifacts.d.ts +23 -0
- package/src/shared/artifacts.d.ts.map +1 -0
- package/src/shared/artifacts.js +273 -0
- package/src/shared/artifacts.js.map +1 -0
- package/src/shared/atomic-json.d.ts +19 -0
- package/src/shared/atomic-json.d.ts.map +1 -0
- package/src/shared/atomic-json.js +60 -0
- package/src/shared/atomic-json.js.map +1 -0
- package/src/shared/capacity-resilient-json.d.ts +27 -0
- package/src/shared/capacity-resilient-json.d.ts.map +1 -0
- package/src/shared/capacity-resilient-json.js +87 -0
- package/src/shared/capacity-resilient-json.js.map +1 -0
- package/src/shared/child-cache-retention.d.ts +30 -0
- package/src/shared/child-cache-retention.d.ts.map +1 -0
- package/src/shared/child-cache-retention.js +41 -0
- package/src/shared/child-cache-retention.js.map +1 -0
- package/src/shared/child-session-name.d.ts +9 -0
- package/src/shared/child-session-name.d.ts.map +1 -0
- package/src/shared/child-session-name.js +39 -0
- package/src/shared/child-session-name.js.map +1 -0
- package/src/shared/child-transcript.d.ts +38 -0
- package/src/shared/child-transcript.d.ts.map +1 -0
- package/src/shared/child-transcript.js +226 -0
- package/src/shared/child-transcript.js.map +1 -0
- package/src/shared/completion-owner.d.ts +3 -0
- package/src/shared/completion-owner.d.ts.map +1 -0
- package/src/shared/completion-owner.js +9 -0
- package/src/shared/completion-owner.js.map +1 -0
- package/src/shared/display-text.d.ts +6 -0
- package/src/shared/display-text.d.ts.map +1 -0
- package/src/shared/display-text.js +155 -0
- package/src/shared/display-text.js.map +1 -0
- package/src/shared/extension-context.d.ts +6 -0
- package/src/shared/extension-context.d.ts.map +1 -0
- package/src/shared/extension-context.js +22 -0
- package/src/shared/extension-context.js.map +1 -0
- package/src/shared/file-coalescer.d.ts +12 -0
- package/src/shared/file-coalescer.d.ts.map +1 -0
- package/src/shared/file-coalescer.js +35 -0
- package/src/shared/file-coalescer.js.map +1 -0
- package/src/shared/file-system-retry.d.ts +32 -0
- package/src/shared/file-system-retry.d.ts.map +1 -0
- package/src/shared/file-system-retry.js +85 -0
- package/src/shared/file-system-retry.js.map +1 -0
- package/src/shared/fork-context.d.ts +59 -0
- package/src/shared/fork-context.d.ts.map +1 -0
- package/src/shared/fork-context.js +171 -0
- package/src/shared/fork-context.js.map +1 -0
- package/src/shared/fork-session-cwd.d.ts +3 -0
- package/src/shared/fork-session-cwd.d.ts.map +1 -0
- package/src/shared/fork-session-cwd.js +24 -0
- package/src/shared/fork-session-cwd.js.map +1 -0
- package/src/shared/formatters.d.ts +36 -0
- package/src/shared/formatters.d.ts.map +1 -0
- package/src/shared/formatters.js +143 -0
- package/src/shared/formatters.js.map +1 -0
- package/src/shared/jsonl-writer.d.ts +21 -0
- package/src/shared/jsonl-writer.d.ts.map +1 -0
- package/src/shared/jsonl-writer.js +68 -0
- package/src/shared/jsonl-writer.js.map +1 -0
- package/src/shared/launch-contract.d.ts +64 -0
- package/src/shared/launch-contract.d.ts.map +1 -0
- package/src/shared/launch-contract.js +141 -0
- package/src/shared/launch-contract.js.map +1 -0
- package/src/shared/model-info.d.ts +44 -0
- package/src/shared/model-info.d.ts.map +1 -0
- package/src/shared/model-info.js +73 -0
- package/src/shared/model-info.js.map +1 -0
- package/src/shared/model-response-aliases.d.ts +2 -0
- package/src/shared/model-response-aliases.d.ts.map +1 -0
- package/src/shared/model-response-aliases.js +16 -0
- package/src/shared/model-response-aliases.js.map +1 -0
- package/src/shared/node-executable.d.ts +2 -0
- package/src/shared/node-executable.d.ts.map +1 -0
- package/src/shared/node-executable.js +21 -0
- package/src/shared/node-executable.js.map +1 -0
- package/src/shared/opencode-session-headers.d.ts +13 -0
- package/src/shared/opencode-session-headers.d.ts.map +1 -0
- package/src/shared/opencode-session-headers.js +27 -0
- package/src/shared/opencode-session-headers.js.map +1 -0
- package/src/shared/prompt-resources.d.ts +6 -0
- package/src/shared/prompt-resources.d.ts.map +1 -0
- package/src/shared/prompt-resources.js +11 -0
- package/src/shared/prompt-resources.js.map +1 -0
- package/src/shared/pruned-fork.d.ts +35 -0
- package/src/shared/pruned-fork.d.ts.map +1 -0
- package/src/shared/pruned-fork.js +424 -0
- package/src/shared/pruned-fork.js.map +1 -0
- package/src/shared/required-child-extensions.d.ts +20 -0
- package/src/shared/required-child-extensions.d.ts.map +1 -0
- package/src/shared/required-child-extensions.js +74 -0
- package/src/shared/required-child-extensions.js.map +1 -0
- package/src/shared/session-file-trust.d.ts +2 -0
- package/src/shared/session-file-trust.d.ts.map +1 -0
- package/src/shared/session-file-trust.js +21 -0
- package/src/shared/session-file-trust.js.map +1 -0
- package/src/shared/session-identity.d.ts +7 -0
- package/src/shared/session-identity.d.ts.map +1 -0
- package/src/shared/session-identity.js +7 -0
- package/src/shared/session-identity.js.map +1 -0
- package/src/shared/session-tokens.d.ts +3 -0
- package/src/shared/session-tokens.d.ts.map +1 -0
- package/src/shared/session-tokens.js +59 -0
- package/src/shared/session-tokens.js.map +1 -0
- package/src/shared/settings.d.ts +147 -0
- package/src/shared/settings.d.ts.map +1 -0
- package/src/shared/settings.js +248 -0
- package/src/shared/settings.js.map +1 -0
- package/src/shared/shortcuts.d.ts +2 -0
- package/src/shared/shortcuts.d.ts.map +1 -0
- package/src/shared/shortcuts.js +18 -0
- package/src/shared/shortcuts.js.map +1 -0
- package/src/shared/status-format.d.ts +10 -0
- package/src/shared/status-format.d.ts.map +1 -0
- package/src/shared/status-format.js +61 -0
- package/src/shared/status-format.js.map +1 -0
- package/src/shared/thinking-ceiling.d.ts +14 -0
- package/src/shared/thinking-ceiling.d.ts.map +1 -0
- package/src/shared/thinking-ceiling.js +38 -0
- package/src/shared/thinking-ceiling.js.map +1 -0
- package/src/shared/types.d.ts +2667 -0
- package/src/shared/types.d.ts.map +1 -0
- package/src/shared/types.js +265 -0
- package/src/shared/types.js.map +1 -0
- package/src/shared/utf8.d.ts +6 -0
- package/src/shared/utf8.d.ts.map +1 -0
- package/src/shared/utf8.js +13 -0
- package/src/shared/utf8.js.map +1 -0
- package/src/shared/utils.d.ts +71 -0
- package/src/shared/utils.d.ts.map +1 -0
- package/src/shared/utils.js +593 -0
- package/src/shared/utils.js.map +1 -0
- package/src/shared/watch-strategy.d.ts +3 -0
- package/src/shared/watch-strategy.d.ts.map +1 -0
- package/src/shared/watch-strategy.js +6 -0
- package/src/shared/watch-strategy.js.map +1 -0
- package/src/shared/workflow-child-permit.d.ts +59 -0
- package/src/shared/workflow-child-permit.d.ts.map +1 -0
- package/src/shared/workflow-child-permit.js +160 -0
- package/src/shared/workflow-child-permit.js.map +1 -0
- package/src/slash/delegation-adapters.d.ts +147 -0
- package/src/slash/delegation-adapters.d.ts.map +1 -0
- package/src/slash/delegation-adapters.js +293 -0
- package/src/slash/delegation-adapters.js.map +1 -0
- package/src/slash/delegation-json.d.ts +11 -0
- package/src/slash/delegation-json.d.ts.map +1 -0
- package/src/slash/delegation-json.js +118 -0
- package/src/slash/delegation-json.js.map +1 -0
- package/src/slash/delegation-request.d.ts +13 -0
- package/src/slash/delegation-request.d.ts.map +1 -0
- package/src/slash/delegation-request.js +175 -0
- package/src/slash/delegation-request.js.map +1 -0
- package/src/slash/prompt-template-bridge.d.ts +27 -0
- package/src/slash/prompt-template-bridge.d.ts.map +1 -0
- package/src/slash/prompt-template-bridge.js +380 -0
- package/src/slash/prompt-template-bridge.js.map +1 -0
- package/src/slash/prompt-workflows.d.ts +22 -0
- package/src/slash/prompt-workflows.d.ts.map +1 -0
- package/src/slash/prompt-workflows.js +261 -0
- package/src/slash/prompt-workflows.js.map +1 -0
- package/src/slash/selector.d.ts +48 -0
- package/src/slash/selector.d.ts.map +1 -0
- package/src/slash/selector.js +118 -0
- package/src/slash/selector.js.map +1 -0
- package/src/slash/slash-bridge.d.ts +31 -0
- package/src/slash/slash-bridge.d.ts.map +1 -0
- package/src/slash/slash-bridge.js +133 -0
- package/src/slash/slash-bridge.js.map +1 -0
- package/src/slash/slash-commands.d.ts +9 -0
- package/src/slash/slash-commands.d.ts.map +1 -0
- package/src/slash/slash-commands.js +1295 -0
- package/src/slash/slash-commands.js.map +1 -0
- package/src/slash/slash-live-state.d.ts +22 -0
- package/src/slash/slash-live-state.d.ts.map +1 -0
- package/src/slash/slash-live-state.js +264 -0
- package/src/slash/slash-live-state.js.map +1 -0
- package/src/slash/subagents-admin.d.ts +3 -0
- package/src/slash/subagents-admin.d.ts.map +1 -0
- package/src/slash/subagents-admin.js +454 -0
- package/src/slash/subagents-admin.js.map +1 -0
- package/src/tui/fleet-status.d.ts +86 -0
- package/src/tui/fleet-status.d.ts.map +1 -0
- package/src/tui/fleet-status.js +1083 -0
- package/src/tui/fleet-status.js.map +1 -0
- package/src/tui/fleet-transcript.d.ts +50 -0
- package/src/tui/fleet-transcript.d.ts.map +1 -0
- package/src/tui/fleet-transcript.js +497 -0
- package/src/tui/fleet-transcript.js.map +1 -0
- package/src/tui/fleet.d.ts +169 -0
- package/src/tui/fleet.d.ts.map +1 -0
- package/src/tui/fleet.js +1412 -0
- package/src/tui/fleet.js.map +1 -0
- package/src/tui/render-helpers.d.ts +24 -0
- package/src/tui/render-helpers.d.ts.map +1 -0
- package/src/tui/render-helpers.js +101 -0
- package/src/tui/render-helpers.js.map +1 -0
- package/src/tui/render.d.ts +61 -0
- package/src/tui/render.d.ts.map +1 -0
- package/src/tui/render.js +3607 -0
- package/src/tui/render.js.map +1 -0
- package/src/watchdog/change-signature.d.ts +8 -0
- package/src/watchdog/change-signature.d.ts.map +1 -0
- package/src/watchdog/change-signature.js +246 -0
- package/src/watchdog/change-signature.js.map +1 -0
- package/src/watchdog/child-status.d.ts +54 -0
- package/src/watchdog/child-status.d.ts.map +1 -0
- package/src/watchdog/child-status.js +188 -0
- package/src/watchdog/child-status.js.map +1 -0
- package/src/watchdog/diff-tool.d.ts +23 -0
- package/src/watchdog/diff-tool.d.ts.map +1 -0
- package/src/watchdog/diff-tool.js +84 -0
- package/src/watchdog/diff-tool.js.map +1 -0
- package/src/watchdog/emission-guard.d.ts +37 -0
- package/src/watchdog/emission-guard.d.ts.map +1 -0
- package/src/watchdog/emission-guard.js +98 -0
- package/src/watchdog/emission-guard.js.map +1 -0
- package/src/watchdog/guidance.d.ts +4 -0
- package/src/watchdog/guidance.d.ts.map +1 -0
- package/src/watchdog/guidance.js +20 -0
- package/src/watchdog/guidance.js.map +1 -0
- package/src/watchdog/lsp-diagnostics.d.ts +18 -0
- package/src/watchdog/lsp-diagnostics.d.ts.map +1 -0
- package/src/watchdog/lsp-diagnostics.js +490 -0
- package/src/watchdog/lsp-diagnostics.js.map +1 -0
- package/src/watchdog/model-selection.d.ts +25 -0
- package/src/watchdog/model-selection.d.ts.map +1 -0
- package/src/watchdog/model-selection.js +168 -0
- package/src/watchdog/model-selection.js.map +1 -0
- package/src/watchdog/permission-arbiter.d.ts +21 -0
- package/src/watchdog/permission-arbiter.d.ts.map +1 -0
- package/src/watchdog/permission-arbiter.js +136 -0
- package/src/watchdog/permission-arbiter.js.map +1 -0
- package/src/watchdog/register-child.d.ts +12 -0
- package/src/watchdog/register-child.d.ts.map +1 -0
- package/src/watchdog/register-child.js +120 -0
- package/src/watchdog/register-child.js.map +1 -0
- package/src/watchdog/register-main.d.ts +10 -0
- package/src/watchdog/register-main.d.ts.map +1 -0
- package/src/watchdog/register-main.js +419 -0
- package/src/watchdog/register-main.js.map +1 -0
- package/src/watchdog/render.d.ts +12 -0
- package/src/watchdog/render.d.ts.map +1 -0
- package/src/watchdog/render.js +52 -0
- package/src/watchdog/render.js.map +1 -0
- package/src/watchdog/review.d.ts +36 -0
- package/src/watchdog/review.d.ts.map +1 -0
- package/src/watchdog/review.js +318 -0
- package/src/watchdog/review.js.map +1 -0
- package/src/watchdog/rules.d.ts +22 -0
- package/src/watchdog/rules.d.ts.map +1 -0
- package/src/watchdog/rules.js +59 -0
- package/src/watchdog/rules.js.map +1 -0
- package/src/watchdog/runtime.d.ts +196 -0
- package/src/watchdog/runtime.d.ts.map +1 -0
- package/src/watchdog/runtime.js +862 -0
- package/src/watchdog/runtime.js.map +1 -0
- package/src/watchdog/scope.d.ts +15 -0
- package/src/watchdog/scope.d.ts.map +1 -0
- package/src/watchdog/scope.js +45 -0
- package/src/watchdog/scope.js.map +1 -0
- package/src/watchdog/settings.d.ts +30 -0
- package/src/watchdog/settings.d.ts.map +1 -0
- package/src/watchdog/settings.js +476 -0
- package/src/watchdog/settings.js.map +1 -0
- package/src/watchdog/tool-actions.d.ts +18 -0
- package/src/watchdog/tool-actions.d.ts.map +1 -0
- package/src/watchdog/tool-actions.js +151 -0
- package/src/watchdog/tool-actions.js.map +1 -0
- package/src/watchdog/turn-delta.d.ts +12 -0
- package/src/watchdog/turn-delta.d.ts.map +1 -0
- package/src/watchdog/turn-delta.js +185 -0
- package/src/watchdog/turn-delta.js.map +1 -0
- package/src/watchdog/types.d.ts +142 -0
- package/src/watchdog/types.d.ts.map +1 -0
- package/src/watchdog/types.js +28 -0
- package/src/watchdog/types.js.map +1 -0
- package/src/watchdog/warning-format.d.ts +8 -0
- package/src/watchdog/warning-format.d.ts.map +1 -0
- package/src/watchdog/warning-format.js +60 -0
- package/src/watchdog/warning-format.js.map +1 -0
- package/src/workflows/chat-progress.d.ts +38 -0
- package/src/workflows/chat-progress.d.ts.map +1 -0
- package/src/workflows/chat-progress.js +130 -0
- package/src/workflows/chat-progress.js.map +1 -0
- package/src/workflows/host-command.d.ts +31 -0
- package/src/workflows/host-command.d.ts.map +1 -0
- package/src/workflows/host-command.js +228 -0
- package/src/workflows/host-command.js.map +1 -0
- package/src/workflows/scripted-workflow.d.ts +195 -0
- package/src/workflows/scripted-workflow.d.ts.map +1 -0
- package/src/workflows/scripted-workflow.js +2636 -0
- package/src/workflows/scripted-workflow.js.map +1 -0
- package/src/workflows/workflow-checklist.d.ts +124 -0
- package/src/workflows/workflow-checklist.d.ts.map +1 -0
- package/src/workflows/workflow-checklist.js +312 -0
- package/src/workflows/workflow-checklist.js.map +1 -0
- package/src/workflows/workflow-child-summary.d.ts +20 -0
- package/src/workflows/workflow-child-summary.d.ts.map +1 -0
- package/src/workflows/workflow-child-summary.js +179 -0
- package/src/workflows/workflow-child-summary.js.map +1 -0
- package/src/workflows/workflow-preflight.d.ts +59 -0
- package/src/workflows/workflow-preflight.d.ts.map +1 -0
- package/src/workflows/workflow-preflight.js +289 -0
- package/src/workflows/workflow-preflight.js.map +1 -0
- package/src/workflows/workflow-receipt.d.ts +35 -0
- package/src/workflows/workflow-receipt.d.ts.map +1 -0
- package/src/workflows/workflow-receipt.js +449 -0
- package/src/workflows/workflow-receipt.js.map +1 -0
- package/src/workflows/workflow-resources.d.ts +43 -0
- package/src/workflows/workflow-resources.d.ts.map +1 -0
- package/src/workflows/workflow-resources.js +230 -0
- package/src/workflows/workflow-resources.js.map +1 -0
- package/src/workflows/workflow-settlement.d.ts +85 -0
- package/src/workflows/workflow-settlement.d.ts.map +1 -0
- package/src/workflows/workflow-settlement.js +204 -0
- package/src/workflows/workflow-settlement.js.map +1 -0
- package/index.ts +0 -13
- package/src/agents/advertised-agent-prompt.ts +0 -94
- package/src/agents/agent-management.ts +0 -1417
- package/src/agents/agent-memory.ts +0 -254
- package/src/agents/agent-refinements.ts +0 -624
- package/src/agents/agent-scope.ts +0 -6
- package/src/agents/agent-selection.ts +0 -25
- package/src/agents/agent-serializer.ts +0 -182
- package/src/agents/agents.ts +0 -2917
- package/src/agents/builtin-names.ts +0 -16
- package/src/agents/chain-serializer.ts +0 -285
- package/src/agents/frontmatter.ts +0 -153
- package/src/agents/identity.ts +0 -30
- package/src/agents/proactive-skills.ts +0 -194
- package/src/agents/runtime-agent-events.ts +0 -70
- package/src/agents/runtime-agent-registry.ts +0 -430
- package/src/agents/skills.ts +0 -754
- package/src/api/agents.ts +0 -12
- package/src/api/background-work.ts +0 -206
- package/src/api/capability-ceiling.ts +0 -16
- package/src/api/child-tool-plan.ts +0 -5
- package/src/api/control-channel.ts +0 -4
- package/src/api/delegation.ts +0 -116
- package/src/api/external-job-provider.ts +0 -195
- package/src/api/external-runs.ts +0 -282
- package/src/api/intercom-bridge.ts +0 -3
- package/src/api/preflight.ts +0 -539
- package/src/api/project-panes.ts +0 -32
- package/src/api/required-child-extensions.ts +0 -6
- package/src/api/shared-types.ts +0 -29
- package/src/api/workflow-resources.ts +0 -6
- package/src/extension/config.ts +0 -230
- package/src/extension/control-notices.ts +0 -58
- package/src/extension/doctor.ts +0 -270
- package/src/extension/fanout-child.ts +0 -265
- package/src/extension/herdr-pi-bridge.ts +0 -160
- package/src/extension/index.ts +0 -1205
- package/src/extension/public-execution.ts +0 -225
- package/src/extension/rpc.ts +0 -848
- package/src/extension/schemas.ts +0 -428
- package/src/extension/steering-notices.ts +0 -35
- package/src/extension/subagent-guide.ts +0 -39
- package/src/extension/tool-description.ts +0 -175
- package/src/extension/tool-result.ts +0 -19
- package/src/inspectors/actions.ts +0 -148
- package/src/inspectors/ghostty/actions.ts +0 -74
- package/src/inspectors/ghostty/plugin.ts +0 -29
- package/src/inspectors/herdr/actions.ts +0 -155
- package/src/inspectors/herdr/client.ts +0 -130
- package/src/inspectors/herdr/focus.ts +0 -55
- package/src/inspectors/herdr/plugin.ts +0 -20
- package/src/inspectors/herdr/project-panes.ts +0 -730
- package/src/inspectors/inspector-runner.ts +0 -153
- package/src/inspectors/plugins.ts +0 -8
- package/src/inspectors/session-roots-codec.ts +0 -31
- package/src/inspectors/shell-command.ts +0 -16
- package/src/inspectors/types.ts +0 -51
- package/src/integrations/herdr-status.ts +0 -400
- package/src/integrations/pi-web-session-liveness.ts +0 -73
- package/src/intercom/intercom-bridge.ts +0 -233
- package/src/intercom/native-supervisor-channel.ts +0 -917
- package/src/intercom/result-intercom.ts +0 -423
- package/src/intercom/supervisor-ui.ts +0 -244
- package/src/missions/actions.ts +0 -433
- package/src/missions/goal-driver.ts +0 -164
- package/src/missions/lifecycle.ts +0 -367
- package/src/missions/store.ts +0 -584
- package/src/missions/types.ts +0 -190
- package/src/missions/workflow-state.ts +0 -281
- package/src/policy/authority.ts +0 -50
- package/src/profiles/profiles.ts +0 -668
- package/src/runs/background/active-async-capacity.ts +0 -520
- package/src/runs/background/active-run-index.ts +0 -155
- package/src/runs/background/async-execution.ts +0 -2278
- package/src/runs/background/async-job-tracker.ts +0 -826
- package/src/runs/background/async-resume.ts +0 -647
- package/src/runs/background/async-retention.ts +0 -912
- package/src/runs/background/async-status-snapshot.ts +0 -46
- package/src/runs/background/async-status.ts +0 -771
- package/src/runs/background/auto-drain.ts +0 -92
- package/src/runs/background/binary-bootstrap.ts +0 -38
- package/src/runs/background/chain-append.ts +0 -321
- package/src/runs/background/chain-root-attachment.ts +0 -259
- package/src/runs/background/completion-batcher.ts +0 -168
- package/src/runs/background/completion-dedupe.ts +0 -58
- package/src/runs/background/completion-replay.ts +0 -287
- package/src/runs/background/control-channel.ts +0 -600
- package/src/runs/background/fleet-view.ts +0 -648
- package/src/runs/background/index-segment.ts +0 -59
- package/src/runs/background/inspect-rpc.ts +0 -443
- package/src/runs/background/notify.ts +0 -819
- package/src/runs/background/owned-process-tree.ts +0 -131
- package/src/runs/background/parallel-groups.ts +0 -45
- package/src/runs/background/process-terminal.ts +0 -310
- package/src/runs/background/result-delivery-ownership.ts +0 -45
- package/src/runs/background/result-files.ts +0 -523
- package/src/runs/background/result-watcher.ts +0 -809
- package/src/runs/background/resume-guidance.ts +0 -56
- package/src/runs/background/retained-children.ts +0 -135
- package/src/runs/background/retained-nested-route-tracker.ts +0 -96
- package/src/runs/background/run-child-session.ts +0 -690
- package/src/runs/background/run-id-query.ts +0 -7
- package/src/runs/background/run-id-resolver.ts +0 -175
- package/src/runs/background/run-status.ts +0 -786
- package/src/runs/background/runner-aliases.ts +0 -142
- package/src/runs/background/runner-child-launch.ts +0 -91
- package/src/runs/background/runner-child-sessions.ts +0 -32
- package/src/runs/background/runner-http-dispatcher.ts +0 -119
- package/src/runs/background/scheduled-runs.ts +0 -1012
- package/src/runs/background/stale-run-reconciler.ts +0 -436
- package/src/runs/background/steering.ts +0 -260
- package/src/runs/background/subagent-runner.ts +0 -5357
- package/src/runs/background/subagent-wait.ts +0 -876
- package/src/runs/background/terminal-run-index.ts +0 -138
- package/src/runs/background/top-level-async.ts +0 -14
- package/src/runs/background/wait-completions.ts +0 -261
- package/src/runs/background/wait-config.ts +0 -50
- package/src/runs/background/wait-subscriptions.ts +0 -354
- package/src/runs/background/wait-tool.ts +0 -45
- package/src/runs/foreground/async-dismiss-action.ts +0 -86
- package/src/runs/foreground/async-steering-action.ts +0 -276
- package/src/runs/foreground/async-stop-action.ts +0 -176
- package/src/runs/foreground/execution.ts +0 -2254
- package/src/runs/foreground/foreground-control.ts +0 -157
- package/src/runs/foreground/foreground-history.ts +0 -163
- package/src/runs/foreground/prompt-audit.ts +0 -178
- package/src/runs/foreground/subagent-executor.ts +0 -7526
- package/src/runs/foreground/workflow-detach-reconcile.ts +0 -304
- package/src/runs/foreground/workflow-foreground-steering.ts +0 -169
- package/src/runs/shared/abort-recovery.ts +0 -119
- package/src/runs/shared/acceptance.ts +0 -1698
- package/src/runs/shared/agent-contract.ts +0 -38
- package/src/runs/shared/async-status-projection.ts +0 -659
- package/src/runs/shared/background-process-options.ts +0 -9
- package/src/runs/shared/capability-ceiling.ts +0 -211
- package/src/runs/shared/chain-outputs.ts +0 -116
- package/src/runs/shared/child-hooks.ts +0 -189
- package/src/runs/shared/child-identity.ts +0 -62
- package/src/runs/shared/child-launch-plan.ts +0 -163
- package/src/runs/shared/child-launch.ts +0 -342
- package/src/runs/shared/child-lifecycle.ts +0 -28
- package/src/runs/shared/child-runtime-config.ts +0 -133
- package/src/runs/shared/child-session.ts +0 -448
- package/src/runs/shared/child-tool-plan.ts +0 -661
- package/src/runs/shared/claude-code-adapter.ts +0 -133
- package/src/runs/shared/codex-exec-adapter.ts +0 -129
- package/src/runs/shared/completion-evidence.ts +0 -89
- package/src/runs/shared/completion-guard.ts +0 -255
- package/src/runs/shared/context-mode.ts +0 -44
- package/src/runs/shared/cursor-agent-adapter.ts +0 -114
- package/src/runs/shared/dynamic-fanout.ts +0 -297
- package/src/runs/shared/effective-system-prompt.ts +0 -33
- package/src/runs/shared/extension-bindings.ts +0 -78
- package/src/runs/shared/external-cli-contract.ts +0 -177
- package/src/runs/shared/external-cli-preflight.ts +0 -142
- package/src/runs/shared/external-cli-runner.ts +0 -431
- package/src/runs/shared/external-job-bridge.ts +0 -460
- package/src/runs/shared/external-job-runner.ts +0 -389
- package/src/runs/shared/fast-mode-extension.ts +0 -10
- package/src/runs/shared/herdr-connection.ts +0 -134
- package/src/runs/shared/herdr-external-adapters.ts +0 -169
- package/src/runs/shared/herdr-machine.ts +0 -279
- package/src/runs/shared/herdr-pi-protocol.ts +0 -59
- package/src/runs/shared/herdr-placed-run.ts +0 -263
- package/src/runs/shared/host-step-status.ts +0 -231
- package/src/runs/shared/lane-metadata.ts +0 -126
- package/src/runs/shared/launch-cwd.ts +0 -16
- package/src/runs/shared/llm-intent-arbiter.ts +0 -321
- package/src/runs/shared/long-running-guard.ts +0 -221
- package/src/runs/shared/mcp-config-sources.ts +0 -422
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +0 -484
- package/src/runs/shared/mcp-direct-tool-grant.ts +0 -194
- package/src/runs/shared/model-resolution-diagnostic.ts +0 -76
- package/src/runs/shared/model-resolution.ts +0 -441
- package/src/runs/shared/model-scope.ts +0 -205
- package/src/runs/shared/mutation-evidence.ts +0 -199
- package/src/runs/shared/nested-events.ts +0 -1079
- package/src/runs/shared/nested-path.ts +0 -38
- package/src/runs/shared/nested-render.ts +0 -127
- package/src/runs/shared/orca-progress-tabs.ts +0 -510
- package/src/runs/shared/parallel-handoff.ts +0 -741
- package/src/runs/shared/parallel-utils.ts +0 -279
- package/src/runs/shared/permissions.ts +0 -86
- package/src/runs/shared/pi-spawn.ts +0 -207
- package/src/runs/shared/process-signal.ts +0 -35
- package/src/runs/shared/readonly-drain-observation.ts +0 -42
- package/src/runs/shared/run-fanout-budget.ts +0 -267
- package/src/runs/shared/run-history.ts +0 -201
- package/src/runs/shared/runtime-acknowledged-extensions.ts +0 -44
- package/src/runs/shared/session-lease.ts +0 -293
- package/src/runs/shared/single-output.ts +0 -304
- package/src/runs/shared/spawn-budget.ts +0 -128
- package/src/runs/shared/structured-output.ts +0 -236
- package/src/runs/shared/subagent-control.ts +0 -294
- package/src/runs/shared/subagent-prompt-runtime.ts +0 -545
- package/src/runs/shared/task-intent.ts +0 -244
- package/src/runs/shared/tool-availability.ts +0 -37
- package/src/runs/shared/tool-budget.ts +0 -66
- package/src/runs/shared/tool-timeout.ts +0 -93
- package/src/runs/shared/usage-budget.ts +0 -65
- package/src/runs/shared/workflow-async-child-guidance.ts +0 -18
- package/src/runs/shared/workflow-graph.ts +0 -225
- package/src/runs/shared/worktree-cleanup-plan.ts +0 -869
- package/src/runs/shared/worktree-setup-command.ts +0 -213
- package/src/runs/shared/worktree.ts +0 -1538
- package/src/shared/accessible-dir.ts +0 -47
- package/src/shared/agent-stream-options.ts +0 -5
- package/src/shared/artifacts.ts +0 -281
- package/src/shared/atomic-json.ts +0 -83
- package/src/shared/capacity-resilient-json.ts +0 -102
- package/src/shared/child-cache-retention.ts +0 -43
- package/src/shared/child-session-name.ts +0 -46
- package/src/shared/child-transcript.ts +0 -264
- package/src/shared/completion-owner.ts +0 -14
- package/src/shared/display-text.ts +0 -150
- package/src/shared/extension-context.ts +0 -24
- package/src/shared/file-coalescer.ts +0 -49
- package/src/shared/file-system-retry.ts +0 -95
- package/src/shared/fork-context.ts +0 -236
- package/src/shared/fork-session-cwd.ts +0 -27
- package/src/shared/formatters.ts +0 -146
- package/src/shared/jsonl-writer.ts +0 -92
- package/src/shared/launch-contract.ts +0 -198
- package/src/shared/model-info.ts +0 -101
- package/src/shared/model-response-aliases.ts +0 -13
- package/src/shared/node-executable.ts +0 -21
- package/src/shared/opencode-session-headers.ts +0 -30
- package/src/shared/prompt-resources.ts +0 -11
- package/src/shared/pruned-fork.ts +0 -450
- package/src/shared/required-child-extensions.ts +0 -81
- package/src/shared/session-file-trust.ts +0 -19
- package/src/shared/session-identity.ts +0 -10
- package/src/shared/session-tokens.ts +0 -55
- package/src/shared/settings.ts +0 -412
- package/src/shared/shortcuts.ts +0 -13
- package/src/shared/status-format.ts +0 -55
- package/src/shared/thinking-ceiling.ts +0 -46
- package/src/shared/types.ts +0 -2983
- package/src/shared/utf8.ts +0 -11
- package/src/shared/utils.ts +0 -608
- package/src/shared/watch-strategy.ts +0 -12
- package/src/shared/workflow-child-permit.ts +0 -212
- package/src/slash/delegation-adapters.ts +0 -428
- package/src/slash/delegation-json.ts +0 -108
- package/src/slash/delegation-request.ts +0 -176
- package/src/slash/prompt-template-bridge.ts +0 -419
- package/src/slash/prompt-workflows.ts +0 -287
- package/src/slash/selector.ts +0 -147
- package/src/slash/slash-bridge.ts +0 -192
- package/src/slash/slash-commands.ts +0 -1325
- package/src/slash/slash-live-state.ts +0 -310
- package/src/slash/subagents-admin.ts +0 -460
- package/src/tui/fleet-status.ts +0 -1109
- package/src/tui/fleet-transcript.ts +0 -536
- package/src/tui/fleet.ts +0 -1448
- package/src/tui/render-helpers.ts +0 -111
- package/src/tui/render.ts +0 -3721
- package/src/types/pi-runtime-compat.d.ts +0 -8
- package/src/watchdog/change-signature.ts +0 -260
- package/src/watchdog/child-status.ts +0 -225
- package/src/watchdog/diff-tool.ts +0 -77
- package/src/watchdog/emission-guard.ts +0 -125
- package/src/watchdog/guidance.ts +0 -20
- package/src/watchdog/lsp-diagnostics.ts +0 -538
- package/src/watchdog/model-selection.ts +0 -187
- package/src/watchdog/permission-arbiter.ts +0 -156
- package/src/watchdog/register-child.ts +0 -128
- package/src/watchdog/register-main.ts +0 -445
- package/src/watchdog/render.ts +0 -53
- package/src/watchdog/review.ts +0 -363
- package/src/watchdog/rules.ts +0 -70
- package/src/watchdog/runtime.ts +0 -924
- package/src/watchdog/scope.ts +0 -51
- package/src/watchdog/settings.ts +0 -515
- package/src/watchdog/tool-actions.ts +0 -156
- package/src/watchdog/turn-delta.ts +0 -184
- package/src/watchdog/types.ts +0 -186
- package/src/watchdog/warning-format.ts +0 -72
- package/src/workflows/chat-progress.ts +0 -152
- package/src/workflows/host-command.ts +0 -235
- package/src/workflows/scripted-workflow.ts +0 -2575
- package/src/workflows/workflow-checklist.ts +0 -436
- package/src/workflows/workflow-child-summary.ts +0 -170
- package/src/workflows/workflow-preflight.ts +0 -297
- package/src/workflows/workflow-receipt.ts +0 -384
- package/src/workflows/workflow-resources.ts +0 -236
- package/src/workflows/workflow-settlement.ts +0 -249
|
@@ -0,0 +1,1333 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { runSetupCommand } from "./worktree-setup-command.js";
|
|
4
|
+
import * as fs from "node:fs";
|
|
5
|
+
import * as os from "node:os";
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
import { resolveAuthorityDecision } from "../../policy/authority.js";
|
|
8
|
+
import { PROJECT_SUBAGENTS_RELATIVE_DIR } from "../../shared/artifacts.js";
|
|
9
|
+
import { getAgentDir } from "../../shared/utils.js";
|
|
10
|
+
export const DEFAULT_WORKTREE_PROVIDER = "auto";
|
|
11
|
+
export const DEFAULT_WORKTREE_BASE_REF = "HEAD";
|
|
12
|
+
export const DEFAULT_WORKTREE_BRANCH_PREFIX = "pi-subagents/";
|
|
13
|
+
/** Internal marker used to defer Worktrunk-dependent instruction paths to launch time. */
|
|
14
|
+
export const WORKTREE_AGENT_CWD_PLACEHOLDER = path.join(path.parse(process.cwd()).root, "__pi_subagents_worktree_cwd__");
|
|
15
|
+
const WORKTREE_NAMING_COMPONENT_MAX_BYTES = 96;
|
|
16
|
+
const WORKTREE_NAMING_LABEL_MAX_BYTES = 256;
|
|
17
|
+
const WORKTREE_NAMING_BRANCH_MAX_BYTES = 256;
|
|
18
|
+
const WORKTREE_COMMAND_OUTPUT_MAX_BYTES = 128 * 1024;
|
|
19
|
+
const WORKTRUNK_COMMAND = process.platform === "win32" ? "git" : "wt";
|
|
20
|
+
const WORKTRUNK_ARG_PREFIX = process.platform === "win32" ? ["wt"] : [];
|
|
21
|
+
export const MACHINE_DIFF_OPTIONS = ["--no-color", "--no-ext-diff", "--no-textconv", "--default-prefix", "--line-prefix=", "--no-relative"];
|
|
22
|
+
const MACHINE_PATCH_OPTIONS = [...MACHINE_DIFF_OPTIONS, "--binary"];
|
|
23
|
+
const PATCH_VALIDATION_OPTIONS = ["apply", "--check", "--cached", "--reverse", "--binary", "--whitespace=nowarn"];
|
|
24
|
+
const DEFAULT_WORKTREE_SETUP_HOOK_TIMEOUT_MS = 30000;
|
|
25
|
+
export class WorktreeSetupError extends Error {
|
|
26
|
+
snapshot;
|
|
27
|
+
constructor(error, snapshot) {
|
|
28
|
+
super(`${error instanceof Error ? error.message : String(error)}${snapshot.unknown ? `; setup settlement unknown: ${snapshot.unknown}; manual reconciliation required` : ""}`, { cause: error });
|
|
29
|
+
this.name = "WorktreeSetupError";
|
|
30
|
+
this.snapshot = snapshot;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
let worktreeTurn = Promise.resolve();
|
|
34
|
+
let setupActive = false;
|
|
35
|
+
let setupPoison;
|
|
36
|
+
function assertWorktreeMutationAllowed() {
|
|
37
|
+
if (setupPoison)
|
|
38
|
+
throw new Error(`Worktree mutation blocked: ${setupPoison}`);
|
|
39
|
+
if (setupActive)
|
|
40
|
+
throw new Error("Worktree setup is active; finalization must await withWorktreeTransaction");
|
|
41
|
+
}
|
|
42
|
+
/** Later async finalization owners wrap their synchronous diff/cleanup as ONE turn. */
|
|
43
|
+
export async function withWorktreeTransaction(action) {
|
|
44
|
+
const previous = worktreeTurn;
|
|
45
|
+
let release;
|
|
46
|
+
worktreeTurn = new Promise((resolve) => { release = resolve; });
|
|
47
|
+
await previous;
|
|
48
|
+
try {
|
|
49
|
+
if (setupPoison)
|
|
50
|
+
throw new Error(`Worktree mutation blocked: ${setupPoison}`);
|
|
51
|
+
return await action();
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
release();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
class SetupTransaction {
|
|
58
|
+
progress;
|
|
59
|
+
options;
|
|
60
|
+
constructor(cwd, options) {
|
|
61
|
+
this.options = options;
|
|
62
|
+
this.progress = { setup: { cwd, baseCommit: "", worktrees: [] }, attempts: [], phase: "preflight" };
|
|
63
|
+
}
|
|
64
|
+
snapshot() {
|
|
65
|
+
return structuredClone(this.progress);
|
|
66
|
+
}
|
|
67
|
+
publish() { this.options.onProgress?.(this.snapshot()); }
|
|
68
|
+
check() {
|
|
69
|
+
if (setupPoison)
|
|
70
|
+
throw new Error(setupPoison);
|
|
71
|
+
if (this.options.signal?.aborted)
|
|
72
|
+
throw new Error("Worktree setup aborted");
|
|
73
|
+
if (this.options.deadlineAt !== undefined && Date.now() >= this.options.deadlineAt)
|
|
74
|
+
throw new Error("Worktree setup deadline exceeded");
|
|
75
|
+
}
|
|
76
|
+
unknown(error) {
|
|
77
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
78
|
+
this.progress.unknown ??= reason;
|
|
79
|
+
setupPoison ??= reason;
|
|
80
|
+
}
|
|
81
|
+
async command(command, args, options = {}) {
|
|
82
|
+
this.check();
|
|
83
|
+
this.progress.command = { command, args };
|
|
84
|
+
if (this.progress.phase === "allocation")
|
|
85
|
+
this.progress.attempts.at(-1).command = this.progress.command;
|
|
86
|
+
if (this.progress.phase === "hook")
|
|
87
|
+
this.progress.attempts.find((attempt) => attempt.path === options.cwd).hookCommand = this.progress.command;
|
|
88
|
+
const result = await runSetupCommand(command, args, {
|
|
89
|
+
...options, signal: this.options.signal, deadlineAt: this.options.deadlineAt,
|
|
90
|
+
onSpawn: (process) => { Object.assign(this.progress.command, process); this.publish(); },
|
|
91
|
+
});
|
|
92
|
+
const { stdout: _stdout, stdoutBuffer: _stdoutBuffer, stderr: _stderr, ...metadata } = result;
|
|
93
|
+
this.progress.command.result = metadata;
|
|
94
|
+
if (result.processTree?.state === "unknown")
|
|
95
|
+
this.unknown(result.error ?? "Command tree settlement unverified");
|
|
96
|
+
this.publish();
|
|
97
|
+
if (result.error)
|
|
98
|
+
throw result.error;
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
async git(cwd, args, acceptedExitCodes) {
|
|
102
|
+
return this.command("git", ["-C", cwd, ...args], { acceptedExitCodes });
|
|
103
|
+
}
|
|
104
|
+
async gitChecked(cwd, args) {
|
|
105
|
+
const result = await this.git(cwd, args);
|
|
106
|
+
return result.stdout;
|
|
107
|
+
}
|
|
108
|
+
attempt(index, branch, worktreePath) {
|
|
109
|
+
this.check();
|
|
110
|
+
this.progress.phase = "allocation";
|
|
111
|
+
this.progress.command = undefined;
|
|
112
|
+
this.progress.attempts.push({ index, branch, path: worktreePath, validated: false });
|
|
113
|
+
this.publish();
|
|
114
|
+
}
|
|
115
|
+
validated(worktree) {
|
|
116
|
+
this.progress.phase = "validated";
|
|
117
|
+
Object.assign(this.progress.attempts.at(-1), { path: worktree.path, validated: true });
|
|
118
|
+
this.progress.setup.worktrees.push(worktree);
|
|
119
|
+
this.publish();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function runGit(cwd, args, env) {
|
|
123
|
+
const result = spawnSync("git", ["-C", cwd, ...args], { encoding: "utf-8", windowsHide: true, shell: false, ...(env ? { env: { ...process.env, ...env } } : {}) });
|
|
124
|
+
return {
|
|
125
|
+
stdout: result.stdout ?? "",
|
|
126
|
+
stderr: result.stderr ?? "",
|
|
127
|
+
status: result.status,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function runGitChecked(cwd, args) {
|
|
131
|
+
const result = runGit(cwd, args);
|
|
132
|
+
if (result.status !== 0) {
|
|
133
|
+
const command = `git -C ${cwd} ${args.join(" ")}`;
|
|
134
|
+
const message = result.stderr.trim() || result.stdout.trim() || `${command} failed`;
|
|
135
|
+
throw new Error(message);
|
|
136
|
+
}
|
|
137
|
+
return result.stdout;
|
|
138
|
+
}
|
|
139
|
+
/** Validate a captured patch against the worktree index without changing either. */
|
|
140
|
+
export function validateWorktreePatch(worktreePath, patchPath) {
|
|
141
|
+
const result = runGit(worktreePath, [...PATCH_VALIDATION_OPTIONS, patchPath]);
|
|
142
|
+
if (result.status === 0)
|
|
143
|
+
return undefined;
|
|
144
|
+
return result.stderr.trim() || result.stdout.trim() || `git -C ${worktreePath} apply --check failed`;
|
|
145
|
+
}
|
|
146
|
+
function currentWorktreePatch(worktreePath, baseCommit) {
|
|
147
|
+
assertWorktreeMutationAllowed();
|
|
148
|
+
let tempDir;
|
|
149
|
+
try {
|
|
150
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-worktree-index-"));
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
return { error: error instanceof Error ? error.message : String(error) };
|
|
154
|
+
}
|
|
155
|
+
const env = { GIT_INDEX_FILE: path.join(tempDir, "index") };
|
|
156
|
+
try {
|
|
157
|
+
const readTree = runGit(worktreePath, ["read-tree", "HEAD"], env);
|
|
158
|
+
if (readTree.status !== 0)
|
|
159
|
+
return { error: readTree.stderr.trim() || readTree.stdout.trim() || "git read-tree failed" };
|
|
160
|
+
const add = runGit(worktreePath, ["add", "-A"], env);
|
|
161
|
+
if (add.status !== 0)
|
|
162
|
+
return { error: add.stderr.trim() || add.stdout.trim() || "git add failed" };
|
|
163
|
+
const diff = runGit(worktreePath, ["diff", "--cached", ...MACHINE_PATCH_OPTIONS, baseCommit], env);
|
|
164
|
+
if (diff.status !== 0)
|
|
165
|
+
return { error: diff.stderr.trim() || diff.stdout.trim() || "git diff failed" };
|
|
166
|
+
return { patch: diff.stdout };
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
try {
|
|
170
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
// Cleanup safety depends on preserving the worktree, not on best-effort temp-index deletion.
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
export function validateWorktreePatchRepresentsCurrentWorktree(worktreePath, baseCommit, patchPath) {
|
|
178
|
+
const validationError = validateWorktreePatch(worktreePath, patchPath);
|
|
179
|
+
if (validationError)
|
|
180
|
+
return validationError;
|
|
181
|
+
let capturedPatch;
|
|
182
|
+
try {
|
|
183
|
+
capturedPatch = fs.readFileSync(patchPath, "utf-8");
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
return error instanceof Error ? error.message : String(error);
|
|
187
|
+
}
|
|
188
|
+
const current = currentWorktreePatch(worktreePath, baseCommit);
|
|
189
|
+
if ("error" in current)
|
|
190
|
+
return current.error || "failed to capture current worktree patch";
|
|
191
|
+
if (capturedPatch !== current.patch)
|
|
192
|
+
return "captured handoff patch does not match current worktree changes";
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
async function probeWorktreeSource(tx, cwd) {
|
|
196
|
+
const repoCheck = await tx.git(cwd, ["rev-parse", "--is-inside-work-tree"], [0, 128]);
|
|
197
|
+
if (repoCheck.status !== 0 || repoCheck.stdout.trim() !== "true")
|
|
198
|
+
throw new Error("worktree isolation requires a git repository");
|
|
199
|
+
const toplevel = (await tx.gitChecked(cwd, ["rev-parse", "--show-toplevel"])).trim();
|
|
200
|
+
// pi-subagents writes durable runtime state under .pi/subagents/ by default;
|
|
201
|
+
// that state must not make managed isolation unusable for later runs.
|
|
202
|
+
const status = await tx.gitChecked(toplevel, ["status", "--porcelain", "--", `:!${PROJECT_SUBAGENTS_RELATIVE_DIR}`]);
|
|
203
|
+
if (status.trim().length > 0) {
|
|
204
|
+
throw new Error("worktree isolation requires a clean git working tree. Commit or stash changes first.");
|
|
205
|
+
}
|
|
206
|
+
return toplevel;
|
|
207
|
+
}
|
|
208
|
+
/** Read-only admission check; allocation repeats it because source state can change. */
|
|
209
|
+
export async function preflightWorktreeSource(cwd, options = {}) {
|
|
210
|
+
const git = async (cwd, args, acceptedExitCodes = [0]) => {
|
|
211
|
+
const result = await runSetupCommand("git", ["-C", cwd, ...args], { ...options, acceptedExitCodes });
|
|
212
|
+
if (result.error)
|
|
213
|
+
throw result.error;
|
|
214
|
+
if (result.outputIncomplete || result.status === null || !acceptedExitCodes.includes(result.status)) {
|
|
215
|
+
throw new Error(result.stderr.trim().slice(0, 2000) || "Worktree source probe failed");
|
|
216
|
+
}
|
|
217
|
+
return result;
|
|
218
|
+
};
|
|
219
|
+
await probeWorktreeSource({ git, gitChecked: async (cwd, args) => (await git(cwd, args)).stdout }, cwd);
|
|
220
|
+
}
|
|
221
|
+
async function resolveRepoState(tx, cwd, requestedBaseRef) {
|
|
222
|
+
const toplevel = await probeWorktreeSource(tx, cwd);
|
|
223
|
+
const rawPrefix = (await tx.gitChecked(cwd, ["rev-parse", "--show-prefix"])).trim();
|
|
224
|
+
const cwdRelative = rawPrefix ? path.normalize(rawPrefix.replace(/[\\/]+$/, "")) : "";
|
|
225
|
+
const baseRef = normalizeWorktreeBaseRef(requestedBaseRef) ?? DEFAULT_WORKTREE_BASE_REF;
|
|
226
|
+
let baseCommit;
|
|
227
|
+
try {
|
|
228
|
+
const base = await tx.git(toplevel, ["rev-parse", "--verify", "--end-of-options", `${baseRef}^{commit}`], [0, 128]);
|
|
229
|
+
if (base.status !== 0)
|
|
230
|
+
throw new Error(base.stderr.trim() || "ref not found");
|
|
231
|
+
baseCommit = base.stdout.trim();
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
throw new Error(`baseRef '${baseRef}' could not be resolved to a commit: ${error instanceof Error ? error.message : String(error)}`, { cause: error instanceof Error ? error : undefined });
|
|
235
|
+
}
|
|
236
|
+
if (!baseCommit)
|
|
237
|
+
throw new Error(`baseRef '${baseRef}' could not be resolved to a commit`);
|
|
238
|
+
return { toplevel, cwdRelative, baseCommit };
|
|
239
|
+
}
|
|
240
|
+
function normalizeComparableCwd(cwd) {
|
|
241
|
+
const resolved = path.resolve(cwd);
|
|
242
|
+
let existing = resolved;
|
|
243
|
+
const missingSegments = [];
|
|
244
|
+
while (true) {
|
|
245
|
+
try {
|
|
246
|
+
let realpath;
|
|
247
|
+
try {
|
|
248
|
+
realpath = fs.realpathSync.native(existing);
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
realpath = fs.realpathSync(existing);
|
|
252
|
+
}
|
|
253
|
+
return path.join(realpath, ...missingSegments.reverse());
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
const parent = path.dirname(existing);
|
|
257
|
+
if (parent === existing)
|
|
258
|
+
return resolved;
|
|
259
|
+
missingSegments.push(path.basename(existing));
|
|
260
|
+
existing = parent;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
export function findWorktreeTaskCwdConflict(tasks, sharedCwd) {
|
|
265
|
+
const normalizedSharedCwd = normalizeComparableCwd(sharedCwd);
|
|
266
|
+
for (let index = 0; index < tasks.length; index++) {
|
|
267
|
+
const task = tasks[index];
|
|
268
|
+
if (!task.cwd)
|
|
269
|
+
continue;
|
|
270
|
+
const taskCwd = path.isAbsolute(task.cwd) ? task.cwd : path.resolve(sharedCwd, task.cwd);
|
|
271
|
+
if (normalizeComparableCwd(taskCwd) === normalizedSharedCwd)
|
|
272
|
+
continue;
|
|
273
|
+
return { index, agent: task.agent, cwd: task.cwd };
|
|
274
|
+
}
|
|
275
|
+
return undefined;
|
|
276
|
+
}
|
|
277
|
+
export function formatWorktreeTaskCwdConflict(conflict, sharedCwd) {
|
|
278
|
+
return `worktree isolation uses the shared cwd (${sharedCwd}); task ${conflict.index + 1} (${conflict.agent}) sets cwd to ${conflict.cwd}. Remove task-level cwd overrides or disable worktree.`;
|
|
279
|
+
}
|
|
280
|
+
function safePatchAgentName(agent) {
|
|
281
|
+
return agent.replace(/[^\w.-]/g, "_");
|
|
282
|
+
}
|
|
283
|
+
function shortWorktreeHash(value) {
|
|
284
|
+
return createHash("sha256").update(value, "utf-8").digest("hex").slice(0, 8);
|
|
285
|
+
}
|
|
286
|
+
function truncateUtf8(value, maxBytes) {
|
|
287
|
+
if (Buffer.byteLength(value, "utf-8") <= maxBytes)
|
|
288
|
+
return value;
|
|
289
|
+
const truncated = Buffer.from(value, "utf-8").subarray(0, maxBytes).toString("utf-8");
|
|
290
|
+
return /[\uD800-\uDFFF]$/u.test(truncated) ? truncated.slice(0, -1) : truncated;
|
|
291
|
+
}
|
|
292
|
+
/** Convert an arbitrary label to a single safe filesystem/branch component. */
|
|
293
|
+
export function sanitizeWorktreePathComponent(value, maxBytes = WORKTREE_NAMING_COMPONENT_MAX_BYTES) {
|
|
294
|
+
const raw = value.trim();
|
|
295
|
+
let normalized = raw
|
|
296
|
+
.replace(/[\\/\s]+/g, "-")
|
|
297
|
+
.replace(/[^A-Za-z0-9._-]+/g, "-")
|
|
298
|
+
.replace(/-+/g, "-")
|
|
299
|
+
.replace(/^[._-]+|[._-]+$/g, "");
|
|
300
|
+
if (!normalized)
|
|
301
|
+
return "task";
|
|
302
|
+
const changed = normalized !== raw;
|
|
303
|
+
if (changed || Buffer.byteLength(normalized, "utf-8") > maxBytes) {
|
|
304
|
+
const suffix = `-${shortWorktreeHash(raw || "task")}`;
|
|
305
|
+
const prefix = truncateUtf8(normalized, Math.max(1, maxBytes - Buffer.byteLength(suffix, "utf-8"))).replace(/[._-]+$/g, "");
|
|
306
|
+
normalized = `${prefix || "task"}${suffix}`;
|
|
307
|
+
}
|
|
308
|
+
return truncateUtf8(normalized, maxBytes).replace(/^[._-]+|[._-]+$/g, "") || "task";
|
|
309
|
+
}
|
|
310
|
+
function validGitRef(ref) {
|
|
311
|
+
if (!ref || ref === "@" || Buffer.byteLength(ref, "utf-8") > 1024 || ref.startsWith("/") || ref.endsWith("/") || ref.includes("//") || ref.includes("..") || ref.includes("@{"))
|
|
312
|
+
return false;
|
|
313
|
+
if (/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/iu.test(ref))
|
|
314
|
+
return false;
|
|
315
|
+
if (/[[\]\\~^:?*\u0000-\u0020\u007f]/u.test(ref) || ref.endsWith(".") || ref.endsWith(".lock"))
|
|
316
|
+
return false;
|
|
317
|
+
return ref.split("/").every((component) => component.length > 0 && component !== "." && component !== ".." && !component.startsWith(".") && !component.endsWith(".") && !component.endsWith(".lock"));
|
|
318
|
+
}
|
|
319
|
+
/** Normalize and validate a configured worktree base ref without resolving it. */
|
|
320
|
+
export function normalizeWorktreeBaseRef(value) {
|
|
321
|
+
if (value === undefined)
|
|
322
|
+
return undefined;
|
|
323
|
+
if (typeof value !== "string" || !validGitRef(value))
|
|
324
|
+
throw new Error("baseRef must be a valid Git ref: use HEAD or a supported named ref (for example, refs/heads/main). Full 40/64-character commit IDs and revision expressions are unsupported.");
|
|
325
|
+
return value;
|
|
326
|
+
}
|
|
327
|
+
/** Normalize and validate the configured Git branch namespace. */
|
|
328
|
+
export function normalizeWorktreeBranchPrefix(value) {
|
|
329
|
+
const raw = value === undefined ? DEFAULT_WORKTREE_BRANCH_PREFIX : value.trim();
|
|
330
|
+
if (!raw)
|
|
331
|
+
throw new Error("worktree branch prefix cannot be empty");
|
|
332
|
+
if (raw.includes("\\") || /[\u0000-\u001f\u007f\s]/u.test(raw) || raw.startsWith("/") || raw.includes("//") || raw.includes("..") || raw.includes("@{")) {
|
|
333
|
+
throw new Error("worktree branch prefix contains invalid Git ref characters");
|
|
334
|
+
}
|
|
335
|
+
const withoutTrailingSlash = raw.replace(/\/+$/u, "");
|
|
336
|
+
if (!withoutTrailingSlash || withoutTrailingSlash.startsWith("-") || withoutTrailingSlash.split("/").some((component) => component === "." || component === ".." || component.startsWith("."))) {
|
|
337
|
+
throw new Error("worktree branch prefix contains an invalid Git ref component");
|
|
338
|
+
}
|
|
339
|
+
const prefix = `${withoutTrailingSlash}/`;
|
|
340
|
+
if (!validGitRef(`${prefix}task`))
|
|
341
|
+
throw new Error("worktree branch prefix is not a valid Git ref namespace");
|
|
342
|
+
return prefix;
|
|
343
|
+
}
|
|
344
|
+
function runShortId(runId) {
|
|
345
|
+
const base = runId.replace(/-s\d+$/u, "");
|
|
346
|
+
const normalized = sanitizeWorktreePathComponent(base || runId, 16);
|
|
347
|
+
return normalized.length > 12 ? normalized.slice(0, 12) : normalized;
|
|
348
|
+
}
|
|
349
|
+
function nonNegativeNamingIndex(value, label, fallback) {
|
|
350
|
+
const resolved = value ?? fallback;
|
|
351
|
+
if (!Number.isSafeInteger(resolved) || resolved < 0)
|
|
352
|
+
throw new Error(`${label} must be a non-negative integer`);
|
|
353
|
+
return resolved;
|
|
354
|
+
}
|
|
355
|
+
/** Build the shared branch identity used by native and Worktrunk allocation. */
|
|
356
|
+
export function buildWorktreeNaming(input) {
|
|
357
|
+
if (!input.runId.trim())
|
|
358
|
+
throw new Error("worktree run id cannot be empty");
|
|
359
|
+
const index = nonNegativeNamingIndex(input.index, "worktree index", 0);
|
|
360
|
+
const stepIndex = nonNegativeNamingIndex(input.stepIndex, "worktree step index", Number(input.runId.match(/-s(\d+)$/u)?.[1] ?? 0));
|
|
361
|
+
const taskIndex = nonNegativeNamingIndex(input.taskIndex, "worktree task index", index);
|
|
362
|
+
const label = input.laneKey?.trim()
|
|
363
|
+
|| input.workflowKey?.trim()
|
|
364
|
+
|| input.outputName?.trim()
|
|
365
|
+
|| input.taskKey?.trim()
|
|
366
|
+
|| input.label?.trim()
|
|
367
|
+
|| (input.agent?.trim() && input.task?.trim() ? `${input.agent.trim()}-${input.task.trim()}` : undefined)
|
|
368
|
+
|| input.agent?.trim()
|
|
369
|
+
|| "task";
|
|
370
|
+
const branchPrefix = normalizeWorktreeBranchPrefix(input.branchPrefix);
|
|
371
|
+
const labelComponent = sanitizeWorktreePathComponent(label);
|
|
372
|
+
const pathComponentBase = `${labelComponent}-${runShortId(input.runId)}-s${stepIndex}-t${taskIndex}`;
|
|
373
|
+
const sanitizedPathComponent = validGitRef(`${branchPrefix}${pathComponentBase}`)
|
|
374
|
+
? pathComponentBase
|
|
375
|
+
: sanitizeWorktreePathComponent(pathComponentBase, WORKTREE_NAMING_COMPONENT_MAX_BYTES);
|
|
376
|
+
let requestedBranch = `${branchPrefix}${sanitizedPathComponent}`;
|
|
377
|
+
if (!validGitRef(requestedBranch) || Buffer.byteLength(requestedBranch, "utf-8") > WORKTREE_NAMING_BRANCH_MAX_BYTES) {
|
|
378
|
+
const suffix = `-${shortWorktreeHash(pathComponentBase)}`;
|
|
379
|
+
const available = Math.max(1, WORKTREE_NAMING_BRANCH_MAX_BYTES - Buffer.byteLength(branchPrefix, "utf-8") - Buffer.byteLength(suffix, "utf-8"));
|
|
380
|
+
requestedBranch = `${branchPrefix}${truncateUtf8(pathComponentBase, available).replace(/[._-]+$/g, "")}${suffix}`;
|
|
381
|
+
}
|
|
382
|
+
if (!validGitRef(requestedBranch) || Buffer.byteLength(requestedBranch, "utf-8") > WORKTREE_NAMING_BRANCH_MAX_BYTES)
|
|
383
|
+
throw new Error(`generated worktree branch is not a valid Git ref: ${requestedBranch}`);
|
|
384
|
+
const metadataLabel = truncateUtf8(label.replace(/[\u0000-\u001f\u007f]+/gu, " ").replace(/\s+/gu, " ").trim() || "task", WORKTREE_NAMING_LABEL_MAX_BYTES);
|
|
385
|
+
return {
|
|
386
|
+
requestedBranch,
|
|
387
|
+
branchPrefix,
|
|
388
|
+
label: metadataLabel,
|
|
389
|
+
sanitizedPathComponent: requestedBranch.slice(branchPrefix.length),
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
function hasConfiguredWorktreeBaseDir(baseDir) {
|
|
393
|
+
return baseDir !== undefined
|
|
394
|
+
? true
|
|
395
|
+
: (process.env.PI_SUBAGENTS_WORKTREE_DIR?.trim().length ?? 0) > 0;
|
|
396
|
+
}
|
|
397
|
+
function isInsidePiExtensionsDirectory(targetPath) {
|
|
398
|
+
const extensionsDir = normalizeComparableCwd(path.join(getAgentDir(), "extensions"));
|
|
399
|
+
return isPathInside(extensionsDir, normalizeComparableCwd(targetPath));
|
|
400
|
+
}
|
|
401
|
+
function runWorktrunk(args, cwd) {
|
|
402
|
+
try {
|
|
403
|
+
const result = spawnSync(WORKTRUNK_COMMAND, [...WORKTRUNK_ARG_PREFIX, ...args], {
|
|
404
|
+
cwd,
|
|
405
|
+
encoding: "utf-8",
|
|
406
|
+
windowsHide: true,
|
|
407
|
+
shell: false,
|
|
408
|
+
maxBuffer: WORKTREE_COMMAND_OUTPUT_MAX_BYTES,
|
|
409
|
+
});
|
|
410
|
+
const stdout = result.stdout ?? "";
|
|
411
|
+
const stderr = result.stderr ?? "";
|
|
412
|
+
if (Buffer.byteLength(stdout, "utf-8") > WORKTREE_COMMAND_OUTPUT_MAX_BYTES)
|
|
413
|
+
throw new Error("Worktrunk stdout exceeds the output limit");
|
|
414
|
+
return { stdout, stderr, status: result.status, ...(result.error ? { error: result.error } : {}) };
|
|
415
|
+
}
|
|
416
|
+
catch (error) {
|
|
417
|
+
return { stdout: "", stderr: "", status: null, error: error instanceof Error ? error : new Error(String(error)) };
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
function probeWorktrunk() {
|
|
421
|
+
const result = runWorktrunk(["--version"]);
|
|
422
|
+
if (result.status !== 0)
|
|
423
|
+
return { available: false, reason: result.error?.message || result.stderr.trim() || "Worktrunk is unavailable" };
|
|
424
|
+
const version = result.stdout.trim().match(/\b(?:wt\s+)?v?(\d+\.\d+(?:\.\d+)?)\b/i)?.[1];
|
|
425
|
+
if (!version)
|
|
426
|
+
return { available: false, reason: "Worktrunk returned an invalid version" };
|
|
427
|
+
const help = runWorktrunk(["switch", "--help"]);
|
|
428
|
+
if (help.status !== 0)
|
|
429
|
+
return { available: false, reason: help.error?.message || help.stderr.trim() || "Worktrunk switch capability is unavailable" };
|
|
430
|
+
const helpText = `${help.stdout}\n${help.stderr}`;
|
|
431
|
+
const requiredCapabilities = ["--create", "--base", "--no-cd", "--no-hooks", "--format"];
|
|
432
|
+
const missing = requiredCapabilities.filter((flag) => !helpText.includes(flag));
|
|
433
|
+
if (missing.length > 0)
|
|
434
|
+
return { available: false, reason: `Worktrunk switch is missing required capabilities: ${missing.join(", ")}` };
|
|
435
|
+
return { available: true };
|
|
436
|
+
}
|
|
437
|
+
/** Resolve a requested provider without silently switching after allocation starts. */
|
|
438
|
+
export function resolveWorktreeProvider(requested, baseDir) {
|
|
439
|
+
const selection = requested ?? DEFAULT_WORKTREE_PROVIDER;
|
|
440
|
+
if (selection !== "auto" && selection !== "native" && selection !== "worktrunk")
|
|
441
|
+
throw new Error(`worktree provider must be "auto", "native", or "worktrunk"`);
|
|
442
|
+
if (selection === "native")
|
|
443
|
+
return "native";
|
|
444
|
+
if (hasConfiguredWorktreeBaseDir(baseDir)) {
|
|
445
|
+
if (selection === "worktrunk")
|
|
446
|
+
throw new Error("worktreeProvider='worktrunk' cannot be combined with worktreeBaseDir or PI_SUBAGENTS_WORKTREE_DIR");
|
|
447
|
+
return "native";
|
|
448
|
+
}
|
|
449
|
+
const capability = probeWorktrunk();
|
|
450
|
+
if (capability.available)
|
|
451
|
+
return "worktrunk";
|
|
452
|
+
if (selection === "worktrunk")
|
|
453
|
+
throw new Error(`Worktrunk provider is unavailable: ${capability.reason ?? "unknown capability failure"}`);
|
|
454
|
+
return "native";
|
|
455
|
+
}
|
|
456
|
+
async function resolveSetupProvider(tx, requested, baseDir, repoRoot) {
|
|
457
|
+
const selection = requested ?? DEFAULT_WORKTREE_PROVIDER;
|
|
458
|
+
if (selection !== "auto" && selection !== "native" && selection !== "worktrunk")
|
|
459
|
+
throw new Error('worktree provider must be "auto", "native", or "worktrunk"');
|
|
460
|
+
if (selection === "native")
|
|
461
|
+
return "native";
|
|
462
|
+
if (hasConfiguredWorktreeBaseDir(baseDir)) {
|
|
463
|
+
if (selection === "worktrunk")
|
|
464
|
+
throw new Error("worktreeProvider='worktrunk' cannot be combined with worktreeBaseDir or PI_SUBAGENTS_WORKTREE_DIR");
|
|
465
|
+
return "native";
|
|
466
|
+
}
|
|
467
|
+
if (selection === "auto" && isInsidePiExtensionsDirectory(repoRoot))
|
|
468
|
+
return "native";
|
|
469
|
+
let reason;
|
|
470
|
+
try {
|
|
471
|
+
const probeExitCodes = Array.from({ length: 256 }, (_, code) => code);
|
|
472
|
+
const version = await tx.command(WORKTRUNK_COMMAND, [...WORKTRUNK_ARG_PREFIX, "--version"], { maxBuffer: WORKTREE_COMMAND_OUTPUT_MAX_BYTES, acceptedExitCodes: probeExitCodes });
|
|
473
|
+
if (version.status !== 0 || !/\b(?:wt\s+)?v?(\d+\.\d+(?:\.\d+)?)\b/i.test(version.stdout.trim()))
|
|
474
|
+
reason = "Worktrunk is unavailable or returned an invalid version";
|
|
475
|
+
else {
|
|
476
|
+
const help = await tx.command(WORKTRUNK_COMMAND, [...WORKTRUNK_ARG_PREFIX, "switch", "--help"], { maxBuffer: WORKTREE_COMMAND_OUTPUT_MAX_BYTES, acceptedExitCodes: probeExitCodes });
|
|
477
|
+
const missing = ["--create", "--base", "--no-cd", "--no-hooks", "--format"].filter((flag) => !`${help.stdout}\n${help.stderr}`.includes(flag));
|
|
478
|
+
if (help.status !== 0 || missing.length)
|
|
479
|
+
reason = `Worktrunk switch capability unavailable: ${missing.join(", ")}`;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
catch (error) {
|
|
483
|
+
if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT")
|
|
484
|
+
throw error;
|
|
485
|
+
reason = error.message;
|
|
486
|
+
}
|
|
487
|
+
if (!reason)
|
|
488
|
+
return "worktrunk";
|
|
489
|
+
if (selection === "worktrunk")
|
|
490
|
+
throw new Error(`Worktrunk provider is unavailable: ${reason}`);
|
|
491
|
+
return "native";
|
|
492
|
+
}
|
|
493
|
+
/** Whether a launch must bind its worktree-dependent paths after allocation. */
|
|
494
|
+
export function shouldDeferWorktreeCwd(requested, baseDir) {
|
|
495
|
+
return (requested ?? DEFAULT_WORKTREE_PROVIDER) !== "native" && !hasConfiguredWorktreeBaseDir(baseDir);
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Resolves the dedicated worktree root: the configured base directory or
|
|
499
|
+
* PI_SUBAGENTS_WORKTREE_DIR when set, otherwise a `worktrees` folder sibling
|
|
500
|
+
* to the repository. Managed leaves always nest one level deeper under the
|
|
501
|
+
* project folder (`basename(repoRoot)`).
|
|
502
|
+
*/
|
|
503
|
+
function resolveWorktreeDedicatedRoot(configuredBaseDir, repoRoot, relocateExtensionRepo = true) {
|
|
504
|
+
const rawBaseDir = configuredBaseDir ?? process.env.PI_SUBAGENTS_WORKTREE_DIR;
|
|
505
|
+
let expanded;
|
|
506
|
+
if (rawBaseDir === undefined || (configuredBaseDir === undefined && !rawBaseDir.trim())) {
|
|
507
|
+
expanded = relocateExtensionRepo && isInsidePiExtensionsDirectory(repoRoot)
|
|
508
|
+
? path.join(getAgentDir(), "worktrees")
|
|
509
|
+
: path.join(path.dirname(repoRoot), "worktrees");
|
|
510
|
+
}
|
|
511
|
+
else {
|
|
512
|
+
const trimmed = rawBaseDir.trim();
|
|
513
|
+
if (!trimmed)
|
|
514
|
+
throw new Error("worktree base directory cannot be empty");
|
|
515
|
+
const candidate = trimmed.startsWith("~/") ? path.join(os.homedir(), trimmed.slice(2)) : trimmed;
|
|
516
|
+
expanded = path.isAbsolute(candidate) ? candidate : path.resolve(repoRoot, candidate);
|
|
517
|
+
}
|
|
518
|
+
const extensionsDir = normalizeComparableCwd(path.join(getAgentDir(), "extensions"));
|
|
519
|
+
if (isPathInside(extensionsDir, normalizeComparableCwd(expanded))) {
|
|
520
|
+
throw new Error(`worktree base directory cannot be inside Pi extensions directory: ${extensionsDir}. Choose a directory outside it.`);
|
|
521
|
+
}
|
|
522
|
+
return expanded;
|
|
523
|
+
}
|
|
524
|
+
function buildNativeProjectPath(dedicatedRoot, repoRoot) {
|
|
525
|
+
return path.join(dedicatedRoot, path.basename(repoRoot));
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Creates the project folder (parents included) so `git worktree add` can create
|
|
529
|
+
* the leaf inside it. Must only run after `assertSafeWorktreeLocation` accepted
|
|
530
|
+
* the planned leaf — an unsafe base must never be materialized on disk.
|
|
531
|
+
*/
|
|
532
|
+
function ensureProjectWorktreeDir(dedicatedRoot, repoRoot) {
|
|
533
|
+
try {
|
|
534
|
+
fs.mkdirSync(buildNativeProjectPath(dedicatedRoot, repoRoot), { recursive: true });
|
|
535
|
+
}
|
|
536
|
+
catch (error) {
|
|
537
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
538
|
+
throw new Error(`failed to create worktree base directory ${dedicatedRoot}: ${message}`);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
function buildNativeWorktreePath(dedicatedRoot, repoRoot, runId, index) {
|
|
542
|
+
return path.join(buildNativeProjectPath(dedicatedRoot, repoRoot), `pi-worktree-${sanitizeWorktreePathComponent(runId, 120)}-${index}`);
|
|
543
|
+
}
|
|
544
|
+
function isPathInside(parent, child) {
|
|
545
|
+
const relative = path.relative(parent, child);
|
|
546
|
+
if (!relative || relative === ".")
|
|
547
|
+
return true;
|
|
548
|
+
return relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
549
|
+
}
|
|
550
|
+
function isStrictChildPath(parent, child) {
|
|
551
|
+
const relative = path.relative(parent, child);
|
|
552
|
+
return Boolean(relative) && relative !== "." && relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
553
|
+
}
|
|
554
|
+
/** Fail closed before `git worktree add`: reject unsafe planned/realpath locations. */
|
|
555
|
+
function assertSafeWorktreeLocation(worktreePath, repoRoot, dedicatedRoot) {
|
|
556
|
+
const resolvedLeaf = normalizeComparableCwd(worktreePath);
|
|
557
|
+
const resolvedRepoRoot = normalizeComparableCwd(repoRoot);
|
|
558
|
+
const projectDir = normalizeComparableCwd(buildNativeProjectPath(dedicatedRoot, repoRoot));
|
|
559
|
+
const repoParent = normalizeComparableCwd(path.dirname(resolvedRepoRoot));
|
|
560
|
+
const leafParent = normalizeComparableCwd(path.dirname(resolvedLeaf));
|
|
561
|
+
const extensionsDir = normalizeComparableCwd(path.join(getAgentDir(), "extensions"));
|
|
562
|
+
if (isPathInside(extensionsDir, projectDir) || isPathInside(extensionsDir, resolvedLeaf)) {
|
|
563
|
+
throw new Error(`worktree path cannot be inside Pi extensions directory: ${extensionsDir}. Choose a directory outside it.`);
|
|
564
|
+
}
|
|
565
|
+
if (isPathInside(resolvedRepoRoot, resolvedLeaf)) {
|
|
566
|
+
throw new Error(`worktree path would land inside the repository checkout: ${resolvedLeaf}`);
|
|
567
|
+
}
|
|
568
|
+
if (leafParent === repoParent) {
|
|
569
|
+
throw new Error(`worktree path would be a direct child of the repository parent: ${resolvedLeaf}`);
|
|
570
|
+
}
|
|
571
|
+
if (!isStrictChildPath(projectDir, resolvedLeaf)) {
|
|
572
|
+
throw new Error(`worktree path must be a strict child of the project worktree directory ${projectDir}: ${resolvedLeaf}`);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
function resolveRepoCwdRelative(cwd) {
|
|
576
|
+
const repoCheck = runGit(cwd, ["rev-parse", "--is-inside-work-tree"]);
|
|
577
|
+
if (repoCheck.status !== 0 || repoCheck.stdout.trim() !== "true") {
|
|
578
|
+
throw new Error("worktree isolation requires a git repository");
|
|
579
|
+
}
|
|
580
|
+
const rawPrefix = runGitChecked(cwd, ["rev-parse", "--show-prefix"]).trim();
|
|
581
|
+
const normalizedPrefix = rawPrefix
|
|
582
|
+
? path.normalize(rawPrefix.replace(/[\\/]+$/, ""))
|
|
583
|
+
: "";
|
|
584
|
+
return normalizedPrefix === "." ? "" : normalizedPrefix;
|
|
585
|
+
}
|
|
586
|
+
export function resolveExpectedWorktreeAgentCwd(cwd, runId, index, baseDir) {
|
|
587
|
+
const cwdRelative = resolveRepoCwdRelative(cwd);
|
|
588
|
+
const repoRoot = runGitChecked(cwd, ["rev-parse", "--show-toplevel"]).trim();
|
|
589
|
+
const dedicatedRoot = resolveWorktreeDedicatedRoot(baseDir, repoRoot);
|
|
590
|
+
const worktreePath = buildNativeWorktreePath(dedicatedRoot, repoRoot, runId, index);
|
|
591
|
+
assertSafeWorktreeLocation(worktreePath, repoRoot, dedicatedRoot);
|
|
592
|
+
return cwdRelative ? path.join(worktreePath, cwdRelative) : worktreePath;
|
|
593
|
+
}
|
|
594
|
+
function linkNodeModulesIfPresent(toplevel, worktreePath) {
|
|
595
|
+
const nodeModulesPath = path.join(toplevel, "node_modules");
|
|
596
|
+
const nodeModulesLinkPath = path.join(worktreePath, "node_modules");
|
|
597
|
+
const hasDirectoryEntry = (candidate) => {
|
|
598
|
+
try {
|
|
599
|
+
fs.lstatSync(candidate);
|
|
600
|
+
return true;
|
|
601
|
+
}
|
|
602
|
+
catch (error) {
|
|
603
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT")
|
|
604
|
+
return false;
|
|
605
|
+
throw error;
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
try {
|
|
609
|
+
if (hasDirectoryEntry(nodeModulesLinkPath))
|
|
610
|
+
return false;
|
|
611
|
+
let sourceRealPath;
|
|
612
|
+
try {
|
|
613
|
+
if (!fs.statSync(nodeModulesPath).isDirectory())
|
|
614
|
+
throw new Error("source node_modules is not a directory");
|
|
615
|
+
sourceRealPath = fs.realpathSync.native(nodeModulesPath);
|
|
616
|
+
}
|
|
617
|
+
catch (error) {
|
|
618
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT")
|
|
619
|
+
return false;
|
|
620
|
+
throw error;
|
|
621
|
+
}
|
|
622
|
+
fs.symlinkSync(nodeModulesPath, nodeModulesLinkPath, process.platform === "win32" ? "junction" : "dir");
|
|
623
|
+
if (!fs.lstatSync(nodeModulesLinkPath).isSymbolicLink()
|
|
624
|
+
|| fs.realpathSync.native(nodeModulesLinkPath) !== sourceRealPath) {
|
|
625
|
+
throw new Error("created link does not resolve to the source node_modules");
|
|
626
|
+
}
|
|
627
|
+
return true;
|
|
628
|
+
}
|
|
629
|
+
catch (error) {
|
|
630
|
+
const code = error instanceof Error && "code" in error && typeof error.code === "string" ? `${error.code}: ` : "";
|
|
631
|
+
throw new Error(`failed to link node_modules from ${nodeModulesPath} to ${nodeModulesLinkPath}: ${code}${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
function parseHookTimeout(timeoutMs) {
|
|
635
|
+
if (timeoutMs === undefined)
|
|
636
|
+
return DEFAULT_WORKTREE_SETUP_HOOK_TIMEOUT_MS;
|
|
637
|
+
if (!Number.isInteger(timeoutMs) || timeoutMs <= 0) {
|
|
638
|
+
throw new Error("worktree setup hook timeout must be an integer greater than 0");
|
|
639
|
+
}
|
|
640
|
+
return timeoutMs;
|
|
641
|
+
}
|
|
642
|
+
function resolveWorktreeSetupHook(repoRoot, config) {
|
|
643
|
+
if (!config)
|
|
644
|
+
return undefined;
|
|
645
|
+
const hookPath = config.hookPath.trim();
|
|
646
|
+
if (!hookPath) {
|
|
647
|
+
throw new Error("worktree setup hook path cannot be empty");
|
|
648
|
+
}
|
|
649
|
+
const expandedHookPath = hookPath.startsWith("~/") ? path.join(os.homedir(), hookPath.slice(2)) : hookPath;
|
|
650
|
+
let resolvedPath;
|
|
651
|
+
if (path.isAbsolute(expandedHookPath)) {
|
|
652
|
+
resolvedPath = expandedHookPath;
|
|
653
|
+
}
|
|
654
|
+
else if (expandedHookPath.includes("/") || expandedHookPath.includes("\\")) {
|
|
655
|
+
resolvedPath = path.resolve(repoRoot, expandedHookPath);
|
|
656
|
+
}
|
|
657
|
+
else {
|
|
658
|
+
throw new Error("worktree setup hook must be an absolute path or a repo-relative path");
|
|
659
|
+
}
|
|
660
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
661
|
+
throw new Error(`worktree setup hook not found: ${resolvedPath}`);
|
|
662
|
+
}
|
|
663
|
+
if (fs.statSync(resolvedPath).isDirectory()) {
|
|
664
|
+
throw new Error(`worktree setup hook must be a file, got directory: ${resolvedPath}`);
|
|
665
|
+
}
|
|
666
|
+
return {
|
|
667
|
+
hookPath: resolvedPath,
|
|
668
|
+
timeoutMs: parseHookTimeout(config.timeoutMs),
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
function normalizeSyntheticPath(worktreePath, rawPath) {
|
|
672
|
+
const trimmed = rawPath.trim();
|
|
673
|
+
if (!trimmed)
|
|
674
|
+
throw new Error("synthetic path cannot be empty");
|
|
675
|
+
if (path.isAbsolute(trimmed))
|
|
676
|
+
throw new Error(`synthetic path must be relative: ${rawPath}`);
|
|
677
|
+
const resolved = path.resolve(worktreePath, trimmed);
|
|
678
|
+
const relative = path.relative(worktreePath, resolved);
|
|
679
|
+
if (!relative || relative === ".") {
|
|
680
|
+
throw new Error(`synthetic path cannot target the worktree root: ${rawPath}`);
|
|
681
|
+
}
|
|
682
|
+
if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
683
|
+
throw new Error(`synthetic path escapes the worktree root: ${rawPath}`);
|
|
684
|
+
}
|
|
685
|
+
return path.normalize(relative);
|
|
686
|
+
}
|
|
687
|
+
function parseWorktreeSetupHookOutput(rawStdout) {
|
|
688
|
+
const trimmed = rawStdout.trim();
|
|
689
|
+
if (!trimmed) {
|
|
690
|
+
throw new Error("worktree setup hook returned empty stdout; expected JSON object");
|
|
691
|
+
}
|
|
692
|
+
let parsed;
|
|
693
|
+
try {
|
|
694
|
+
parsed = JSON.parse(trimmed);
|
|
695
|
+
}
|
|
696
|
+
catch (error) {
|
|
697
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
698
|
+
throw new Error(`worktree setup hook returned invalid JSON: ${message}`);
|
|
699
|
+
}
|
|
700
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
701
|
+
throw new Error("worktree setup hook stdout must be a JSON object");
|
|
702
|
+
}
|
|
703
|
+
return parsed;
|
|
704
|
+
}
|
|
705
|
+
async function runWorktreeSetupHook(tx, hook, input) {
|
|
706
|
+
tx.progress.phase = "hook";
|
|
707
|
+
let result;
|
|
708
|
+
try {
|
|
709
|
+
result = await tx.command(hook.hookPath, [], {
|
|
710
|
+
cwd: input.worktreePath,
|
|
711
|
+
input: JSON.stringify(input),
|
|
712
|
+
hookTimeoutMs: hook.timeoutMs,
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
catch (error) {
|
|
716
|
+
throw new Error(`worktree setup hook failed: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
717
|
+
}
|
|
718
|
+
tx.progress.phase = "hook-validation";
|
|
719
|
+
try {
|
|
720
|
+
const output = parseWorktreeSetupHookOutput(result.stdout);
|
|
721
|
+
if (output.syntheticPaths === undefined)
|
|
722
|
+
return [];
|
|
723
|
+
if (!Array.isArray(output.syntheticPaths)) {
|
|
724
|
+
throw new Error("worktree setup hook output field 'syntheticPaths' must be an array of relative paths");
|
|
725
|
+
}
|
|
726
|
+
const uniquePaths = new Set();
|
|
727
|
+
for (const candidate of output.syntheticPaths) {
|
|
728
|
+
if (typeof candidate !== "string")
|
|
729
|
+
throw new Error("worktree setup hook output field 'syntheticPaths' must contain only strings");
|
|
730
|
+
const normalizedPath = normalizeSyntheticPath(input.worktreePath, candidate);
|
|
731
|
+
if ((await tx.gitChecked(input.worktreePath, ["ls-files", "--", normalizedPath])).trim()) {
|
|
732
|
+
throw new Error(`worktree setup hook cannot mark tracked paths as synthetic: ${normalizedPath}`);
|
|
733
|
+
}
|
|
734
|
+
uniquePaths.add(normalizedPath);
|
|
735
|
+
}
|
|
736
|
+
return [...uniquePaths];
|
|
737
|
+
}
|
|
738
|
+
catch (error) {
|
|
739
|
+
// Semantic rejection occurs after exit: retain uncertainty, never signal an old PID.
|
|
740
|
+
tx.unknown(error);
|
|
741
|
+
throw error;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
async function finalizeCreatedWorktree(tx, toplevel, cwdRelative, runId, baseCommit, setupHook, agent, worktree) {
|
|
745
|
+
const agentCwd = cwdRelative ? path.join(worktree.path, cwdRelative) : worktree.path;
|
|
746
|
+
tx.check();
|
|
747
|
+
const nodeModulesLinked = linkNodeModulesIfPresent(toplevel, worktree.path);
|
|
748
|
+
const syntheticPaths = nodeModulesLinked ? ["node_modules"] : [];
|
|
749
|
+
if (setupHook) {
|
|
750
|
+
const hookSyntheticPaths = await runWorktreeSetupHook(tx, setupHook, {
|
|
751
|
+
version: 1, repoRoot: toplevel, worktreePath: worktree.path, agentCwd,
|
|
752
|
+
branch: worktree.branch, index: worktree.index, runId, baseCommit, agent,
|
|
753
|
+
});
|
|
754
|
+
syntheticPaths.push(...hookSyntheticPaths);
|
|
755
|
+
}
|
|
756
|
+
return { ...worktree, agentCwd, nodeModulesLinked, syntheticPaths };
|
|
757
|
+
}
|
|
758
|
+
async function createNativeWorktree(tx, toplevel, cwdRelative, runId, index, baseCommit, setupHook, agent, dedicatedRoot, labels, tasks, branchPrefix) {
|
|
759
|
+
const naming = buildWorktreeNaming({ runId, index, agent, label: labels?.[index], task: tasks?.[index], branchPrefix });
|
|
760
|
+
const worktreePath = buildNativeWorktreePath(dedicatedRoot, toplevel, runId, index);
|
|
761
|
+
assertSafeWorktreeLocation(worktreePath, toplevel, dedicatedRoot);
|
|
762
|
+
// Absence is required before claiming any partial artifacts from this attempt.
|
|
763
|
+
const branch = await tx.git(toplevel, ["show-ref", "--verify", "--quiet", `refs/heads/${naming.requestedBranch}`], [0, 1]);
|
|
764
|
+
let pathExists = false;
|
|
765
|
+
try {
|
|
766
|
+
fs.lstatSync(worktreePath);
|
|
767
|
+
pathExists = true;
|
|
768
|
+
}
|
|
769
|
+
catch (error) {
|
|
770
|
+
if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT")
|
|
771
|
+
throw error;
|
|
772
|
+
}
|
|
773
|
+
if (branch.status !== 1 || pathExists)
|
|
774
|
+
throw new Error(`worktree path or branch already exists: ${worktreePath}, ${naming.requestedBranch}`);
|
|
775
|
+
tx.attempt(index, naming.requestedBranch, worktreePath);
|
|
776
|
+
ensureProjectWorktreeDir(dedicatedRoot, toplevel);
|
|
777
|
+
await tx.git(toplevel, ["worktree", "add", worktreePath, "-b", naming.requestedBranch, baseCommit]);
|
|
778
|
+
const worktree = {
|
|
779
|
+
path: worktreePath,
|
|
780
|
+
agentCwd: worktreePath,
|
|
781
|
+
branch: naming.requestedBranch,
|
|
782
|
+
index,
|
|
783
|
+
nodeModulesLinked: false,
|
|
784
|
+
syntheticPaths: [],
|
|
785
|
+
provider: "native",
|
|
786
|
+
naming,
|
|
787
|
+
};
|
|
788
|
+
tx.validated(worktree);
|
|
789
|
+
return finalizeCreatedWorktree(tx, toplevel, cwdRelative, runId, baseCommit, setupHook, agent, worktree);
|
|
790
|
+
}
|
|
791
|
+
function parseWorktrunkSwitchOutput(rawStdout) {
|
|
792
|
+
if (Buffer.byteLength(rawStdout, "utf-8") > WORKTREE_COMMAND_OUTPUT_MAX_BYTES)
|
|
793
|
+
throw new Error("Worktrunk provisioning output exceeds the output limit");
|
|
794
|
+
const trimmed = rawStdout.trim();
|
|
795
|
+
if (!trimmed)
|
|
796
|
+
throw new Error("Worktrunk provisioning returned empty stdout; expected JSON object");
|
|
797
|
+
let parsed;
|
|
798
|
+
try {
|
|
799
|
+
parsed = JSON.parse(trimmed);
|
|
800
|
+
}
|
|
801
|
+
catch (error) {
|
|
802
|
+
throw new Error(`Worktrunk provisioning returned invalid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
803
|
+
}
|
|
804
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
805
|
+
throw new Error("Worktrunk provisioning stdout must be a JSON object");
|
|
806
|
+
return parsed;
|
|
807
|
+
}
|
|
808
|
+
async function createWorktrunkWorktree(tx, toplevel, cwdRelative, runId, index, baseCommit, agents, labels, tasks, branchPrefix) {
|
|
809
|
+
const naming = buildWorktreeNaming({ runId, index, agent: agents?.[index], label: labels?.[index], task: tasks?.[index], branchPrefix });
|
|
810
|
+
const args = ["-C", toplevel, "switch", "--create", naming.requestedBranch, "--base", baseCommit, "--no-cd", "--no-hooks", "--format", "json"];
|
|
811
|
+
tx.attempt(index, naming.requestedBranch);
|
|
812
|
+
const result = await tx.command(WORKTRUNK_COMMAND, [...WORKTRUNK_ARG_PREFIX, ...args], { cwd: toplevel, maxBuffer: WORKTREE_COMMAND_OUTPUT_MAX_BYTES });
|
|
813
|
+
tx.progress.phase = "validation";
|
|
814
|
+
try {
|
|
815
|
+
const output = parseWorktrunkSwitchOutput(result.stdout);
|
|
816
|
+
if (output.action !== "created" || output.created_branch !== true || output.branch !== naming.requestedBranch || output.base_branch !== baseCommit) {
|
|
817
|
+
throw new Error("Worktrunk provisioning returned inconsistent creation metadata");
|
|
818
|
+
}
|
|
819
|
+
if (typeof output.path !== "string" || !path.isAbsolute(output.path))
|
|
820
|
+
throw new Error("Worktrunk provisioning returned a non-absolute worktree path");
|
|
821
|
+
const worktreePathCandidate = path.resolve(output.path);
|
|
822
|
+
let stat;
|
|
823
|
+
try {
|
|
824
|
+
stat = fs.lstatSync(worktreePathCandidate);
|
|
825
|
+
}
|
|
826
|
+
catch (error) {
|
|
827
|
+
throw new Error(`Worktrunk provisioning returned a missing worktree path: ${worktreePathCandidate}`, { cause: error instanceof Error ? error : undefined });
|
|
828
|
+
}
|
|
829
|
+
if (!stat.isDirectory() || stat.isSymbolicLink())
|
|
830
|
+
throw new Error("Worktrunk provisioning returned a path that is not a real directory");
|
|
831
|
+
const worktreePath = normalizeComparableCwd(worktreePathCandidate);
|
|
832
|
+
if (worktreePath === normalizeComparableCwd(toplevel))
|
|
833
|
+
throw new Error("Worktrunk provisioning returned the source checkout path");
|
|
834
|
+
const sourceCommonDirRaw = (await tx.gitChecked(toplevel, ["rev-parse", "--git-common-dir"])).trim();
|
|
835
|
+
const returnedCommonDirRaw = (await tx.gitChecked(worktreePath, ["rev-parse", "--git-common-dir"])).trim();
|
|
836
|
+
const sourceCommonDir = normalizeComparableCwd(path.isAbsolute(sourceCommonDirRaw) ? sourceCommonDirRaw : path.resolve(toplevel, sourceCommonDirRaw));
|
|
837
|
+
const returnedCommonDir = normalizeComparableCwd(path.isAbsolute(returnedCommonDirRaw) ? returnedCommonDirRaw : path.resolve(worktreePath, returnedCommonDirRaw));
|
|
838
|
+
if (returnedCommonDir !== sourceCommonDir)
|
|
839
|
+
throw new Error("Worktrunk provisioning returned a worktree for a different repository");
|
|
840
|
+
const returnedBranch = (await tx.gitChecked(worktreePath, ["symbolic-ref", "--quiet", "--short", "HEAD"])).trim();
|
|
841
|
+
if (returnedBranch !== naming.requestedBranch)
|
|
842
|
+
throw new Error("Worktrunk provisioning returned a worktree on a different branch");
|
|
843
|
+
const returnedHead = (await tx.gitChecked(worktreePath, ["rev-parse", "HEAD"])).trim();
|
|
844
|
+
if (returnedHead !== baseCommit)
|
|
845
|
+
throw new Error("Worktrunk provisioning returned a worktree at a different base commit");
|
|
846
|
+
const worktree = {
|
|
847
|
+
path: worktreePath,
|
|
848
|
+
agentCwd: cwdRelative ? path.join(worktreePath, cwdRelative) : worktreePath,
|
|
849
|
+
branch: naming.requestedBranch,
|
|
850
|
+
index,
|
|
851
|
+
nodeModulesLinked: false,
|
|
852
|
+
syntheticPaths: [],
|
|
853
|
+
provider: "worktrunk",
|
|
854
|
+
naming,
|
|
855
|
+
};
|
|
856
|
+
tx.validated(worktree);
|
|
857
|
+
return worktree;
|
|
858
|
+
}
|
|
859
|
+
catch (error) {
|
|
860
|
+
tx.unknown(error);
|
|
861
|
+
throw error;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
function removeSyntheticPath(worktree, syntheticPath) {
|
|
865
|
+
assertWorktreeMutationAllowed();
|
|
866
|
+
const resolved = path.resolve(worktree.path, syntheticPath);
|
|
867
|
+
const relative = path.relative(worktree.path, resolved);
|
|
868
|
+
if (!relative || relative === "." || relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
869
|
+
return;
|
|
870
|
+
}
|
|
871
|
+
let stat;
|
|
872
|
+
try {
|
|
873
|
+
stat = fs.lstatSync(resolved);
|
|
874
|
+
}
|
|
875
|
+
catch (error) {
|
|
876
|
+
const code = error && typeof error === "object" && "code" in error ? error.code : undefined;
|
|
877
|
+
if (code === "ENOENT")
|
|
878
|
+
return;
|
|
879
|
+
throw error;
|
|
880
|
+
}
|
|
881
|
+
if (stat.isSymbolicLink()) {
|
|
882
|
+
fs.unlinkSync(resolved);
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
if (stat.isDirectory()) {
|
|
886
|
+
fs.rmSync(resolved, { recursive: true, force: true });
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
fs.rmSync(resolved, { force: true });
|
|
890
|
+
}
|
|
891
|
+
function removeSyntheticPathsBeforeDiff(worktree) {
|
|
892
|
+
if (worktree.syntheticPaths.length === 0)
|
|
893
|
+
return;
|
|
894
|
+
const seen = new Set();
|
|
895
|
+
for (const syntheticPath of worktree.syntheticPaths) {
|
|
896
|
+
if (seen.has(syntheticPath))
|
|
897
|
+
continue;
|
|
898
|
+
seen.add(syntheticPath);
|
|
899
|
+
removeSyntheticPath(worktree, syntheticPath);
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
function emptyDiff(index, agent, branch, patchPath, error) {
|
|
903
|
+
return {
|
|
904
|
+
index,
|
|
905
|
+
agent,
|
|
906
|
+
branch,
|
|
907
|
+
diffStat: "",
|
|
908
|
+
filesChanged: 0,
|
|
909
|
+
insertions: 0,
|
|
910
|
+
deletions: 0,
|
|
911
|
+
patchPath,
|
|
912
|
+
...(error ? { error } : {}),
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
function parseNumstat(numstat) {
|
|
916
|
+
const lines = numstat
|
|
917
|
+
.split("\n")
|
|
918
|
+
.map((line) => line.trim())
|
|
919
|
+
.filter(Boolean);
|
|
920
|
+
let filesChanged = 0;
|
|
921
|
+
let insertions = 0;
|
|
922
|
+
let deletions = 0;
|
|
923
|
+
for (const line of lines) {
|
|
924
|
+
const [rawInsertions, rawDeletions] = line.split("\t");
|
|
925
|
+
if (rawInsertions === undefined || rawDeletions === undefined)
|
|
926
|
+
continue;
|
|
927
|
+
filesChanged++;
|
|
928
|
+
if (/^\d+$/.test(rawInsertions))
|
|
929
|
+
insertions += parseInt(rawInsertions, 10);
|
|
930
|
+
if (/^\d+$/.test(rawDeletions))
|
|
931
|
+
deletions += parseInt(rawDeletions, 10);
|
|
932
|
+
}
|
|
933
|
+
return { filesChanged, insertions, deletions };
|
|
934
|
+
}
|
|
935
|
+
function captureWorktreeDiff(setup, worktree, agent, patchPath) {
|
|
936
|
+
removeSyntheticPathsBeforeDiff(worktree);
|
|
937
|
+
runGitChecked(worktree.path, ["add", "-A"]);
|
|
938
|
+
const diffStat = runGitChecked(worktree.path, ["diff", "--cached", ...MACHINE_DIFF_OPTIONS, "--stat", setup.baseCommit]).trim();
|
|
939
|
+
const patch = runGitChecked(worktree.path, ["diff", "--cached", ...MACHINE_PATCH_OPTIONS, setup.baseCommit]);
|
|
940
|
+
const numstat = runGitChecked(worktree.path, ["diff", "--cached", ...MACHINE_DIFF_OPTIONS, "--numstat", setup.baseCommit]);
|
|
941
|
+
fs.writeFileSync(patchPath, patch, "utf-8");
|
|
942
|
+
if (!patch.trim()) {
|
|
943
|
+
return emptyDiff(worktree.index, agent, worktree.branch, patchPath);
|
|
944
|
+
}
|
|
945
|
+
const validationError = validateWorktreePatch(worktree.path, patchPath);
|
|
946
|
+
if (validationError)
|
|
947
|
+
throw new Error(`captured worktree patch is not machine-applyable: ${validationError}`);
|
|
948
|
+
const parsed = parseNumstat(numstat);
|
|
949
|
+
return {
|
|
950
|
+
index: worktree.index,
|
|
951
|
+
agent,
|
|
952
|
+
branch: worktree.branch,
|
|
953
|
+
diffStat,
|
|
954
|
+
filesChanged: parsed.filesChanged,
|
|
955
|
+
insertions: parsed.insertions,
|
|
956
|
+
deletions: parsed.deletions,
|
|
957
|
+
patchPath,
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
function writeEmptyPatch(patchPath) {
|
|
961
|
+
try {
|
|
962
|
+
fs.writeFileSync(patchPath, "", "utf-8");
|
|
963
|
+
}
|
|
964
|
+
catch {
|
|
965
|
+
// Diff artifact writing is best-effort in error paths.
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
function handoffRecordsPatch(manifestPath, patchPath) {
|
|
969
|
+
if (!manifestPath || !fs.existsSync(manifestPath))
|
|
970
|
+
return false;
|
|
971
|
+
try {
|
|
972
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
|
|
973
|
+
if (manifest.version !== 1 || !Array.isArray(manifest.groups))
|
|
974
|
+
return false;
|
|
975
|
+
const resolvedPatchPath = path.resolve(patchPath);
|
|
976
|
+
return manifest.groups.some((group) => Array.isArray(group.children) && group.children.some((child) => child.patch?.error === undefined
|
|
977
|
+
&& typeof child.patch?.path === "string"
|
|
978
|
+
&& path.resolve(child.patch.path) === resolvedPatchPath));
|
|
979
|
+
}
|
|
980
|
+
catch {
|
|
981
|
+
return false;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
function cleanupSingleWorktree(setup, worktree, intent) {
|
|
985
|
+
const errors = [];
|
|
986
|
+
let worktreeRemoved = false;
|
|
987
|
+
let branchRemoved = false;
|
|
988
|
+
if (intent.kind === "preserve" && intent.cleanupBlocker) {
|
|
989
|
+
return {
|
|
990
|
+
index: worktree.index,
|
|
991
|
+
path: worktree.path,
|
|
992
|
+
branch: worktree.branch,
|
|
993
|
+
...(worktree.provider ? { provider: worktree.provider } : {}),
|
|
994
|
+
...(worktree.naming ? { naming: worktree.naming } : {}),
|
|
995
|
+
worktreeRemoved: false,
|
|
996
|
+
branchRemoved: false,
|
|
997
|
+
preserved: true,
|
|
998
|
+
reason: intent.cleanupBlocker,
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
if (intent.kind !== "setup-rollback") {
|
|
1002
|
+
try {
|
|
1003
|
+
removeSyntheticPathsBeforeDiff(worktree);
|
|
1004
|
+
}
|
|
1005
|
+
catch (error) {
|
|
1006
|
+
errors.push(`synthetic path cleanup failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1007
|
+
}
|
|
1008
|
+
const status = runGit(worktree.path, ["status", "--porcelain"]);
|
|
1009
|
+
const baseDiff = runGit(worktree.path, ["diff", "--quiet", ...MACHINE_DIFF_OPTIONS, setup.baseCommit, "--"]);
|
|
1010
|
+
if (status.status !== 0 || (baseDiff.status !== 0 && baseDiff.status !== 1)) {
|
|
1011
|
+
const reason = status.status !== 0
|
|
1012
|
+
? status.stderr.trim() || status.stdout.trim() || "git status failed"
|
|
1013
|
+
: baseDiff.stderr.trim() || baseDiff.stdout.trim() || "git diff check failed";
|
|
1014
|
+
return {
|
|
1015
|
+
index: worktree.index,
|
|
1016
|
+
path: worktree.path,
|
|
1017
|
+
branch: worktree.branch,
|
|
1018
|
+
...(worktree.provider ? { provider: worktree.provider } : {}),
|
|
1019
|
+
...(worktree.naming ? { naming: worktree.naming } : {}),
|
|
1020
|
+
worktreeRemoved: false,
|
|
1021
|
+
branchRemoved: false,
|
|
1022
|
+
preserved: true,
|
|
1023
|
+
reason: "cleanup safety check failed",
|
|
1024
|
+
errors: [...errors, `cleanup refused: ${reason}`],
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
const hasWork = status.stdout.trim().length > 0 || baseDiff.status === 1;
|
|
1028
|
+
if (hasWork && intent.kind === "preserve") {
|
|
1029
|
+
const captured = (intent.capturedDiffs ?? setup.capturedDiffs)?.find((diff) => diff.index === worktree.index);
|
|
1030
|
+
let patchValidationError;
|
|
1031
|
+
let patchCaptured = false;
|
|
1032
|
+
if (captured !== undefined
|
|
1033
|
+
&& captured.error === undefined
|
|
1034
|
+
&& fs.existsSync(captured.patchPath)
|
|
1035
|
+
&& handoffRecordsPatch(intent.handoffManifestPath, captured.patchPath)) {
|
|
1036
|
+
try {
|
|
1037
|
+
if (fs.statSync(captured.patchPath).size > 0) {
|
|
1038
|
+
patchValidationError = validateWorktreePatchRepresentsCurrentWorktree(worktree.path, setup.baseCommit, captured.patchPath);
|
|
1039
|
+
patchCaptured = patchValidationError === undefined;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
catch (error) {
|
|
1043
|
+
patchValidationError = error instanceof Error ? error.message : String(error);
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
if (!patchCaptured) {
|
|
1047
|
+
const reason = patchValidationError
|
|
1048
|
+
? `captured handoff patch failed validation: ${patchValidationError}`
|
|
1049
|
+
: "worktree contains changes that are not represented by a captured handoff patch";
|
|
1050
|
+
return {
|
|
1051
|
+
index: worktree.index,
|
|
1052
|
+
path: worktree.path,
|
|
1053
|
+
branch: worktree.branch,
|
|
1054
|
+
...(worktree.provider ? { provider: worktree.provider } : {}),
|
|
1055
|
+
...(worktree.naming ? { naming: worktree.naming } : {}),
|
|
1056
|
+
worktreeRemoved: false,
|
|
1057
|
+
branchRemoved: false,
|
|
1058
|
+
preserved: true,
|
|
1059
|
+
reason,
|
|
1060
|
+
errors: [...errors, `cleanup refused: ${reason}; preserved ${worktree.path}`],
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
if (hasWork && intent.kind === "discard") {
|
|
1065
|
+
const decision = resolveAuthorityDecision({ action: "discardWorktree", policy: intent.authorization.policy });
|
|
1066
|
+
const authorized = decision === "auto" || (decision === "confirm" && intent.authorization.kind === "confirmed");
|
|
1067
|
+
if (!authorized) {
|
|
1068
|
+
const reason = decision === "forbid"
|
|
1069
|
+
? "authority policy forbids worktree discard"
|
|
1070
|
+
: "worktree discard requires explicit user confirmation";
|
|
1071
|
+
return {
|
|
1072
|
+
index: worktree.index,
|
|
1073
|
+
path: worktree.path,
|
|
1074
|
+
branch: worktree.branch,
|
|
1075
|
+
...(worktree.provider ? { provider: worktree.provider } : {}),
|
|
1076
|
+
...(worktree.naming ? { naming: worktree.naming } : {}),
|
|
1077
|
+
worktreeRemoved: false,
|
|
1078
|
+
branchRemoved: false,
|
|
1079
|
+
preserved: true,
|
|
1080
|
+
reason,
|
|
1081
|
+
errors: [...errors, `cleanup refused: ${reason}; preserved ${worktree.path}`],
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
try {
|
|
1087
|
+
runGitChecked(setup.cwd, ["worktree", "remove", "--force", worktree.path]);
|
|
1088
|
+
worktreeRemoved = true;
|
|
1089
|
+
}
|
|
1090
|
+
catch (error) {
|
|
1091
|
+
errors.push(`worktree removal failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1092
|
+
}
|
|
1093
|
+
if (worktreeRemoved) {
|
|
1094
|
+
try {
|
|
1095
|
+
runGitChecked(setup.cwd, ["branch", "-D", worktree.branch]);
|
|
1096
|
+
branchRemoved = true;
|
|
1097
|
+
}
|
|
1098
|
+
catch (error) {
|
|
1099
|
+
errors.push(`branch removal failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
return {
|
|
1103
|
+
index: worktree.index,
|
|
1104
|
+
path: worktree.path,
|
|
1105
|
+
branch: worktree.branch,
|
|
1106
|
+
...(worktree.provider ? { provider: worktree.provider } : {}),
|
|
1107
|
+
...(worktree.naming ? { naming: worktree.naming } : {}),
|
|
1108
|
+
worktreeRemoved,
|
|
1109
|
+
branchRemoved,
|
|
1110
|
+
...(errors.length ? { errors } : {}),
|
|
1111
|
+
};
|
|
1112
|
+
}
|
|
1113
|
+
function hasWorktreeChanges(diff) {
|
|
1114
|
+
return diff.filesChanged > 0 || diff.insertions > 0 || diff.deletions > 0 || diff.diffStat.trim().length > 0;
|
|
1115
|
+
}
|
|
1116
|
+
async function compensateSetup(tx) {
|
|
1117
|
+
const { setup, attempts } = tx.progress;
|
|
1118
|
+
const report = { state: "partial", tasks: [], pruned: false, errors: [] };
|
|
1119
|
+
tx.progress.cleanup = report;
|
|
1120
|
+
tx.progress.phase = "rollback";
|
|
1121
|
+
// Cancellation stops allocation, not accounting. Compensation has ONLY the
|
|
1122
|
+
// remaining original absolute deadline; it does not reuse the launch signal.
|
|
1123
|
+
const git = async (args, acceptedExitCodes = [0]) => {
|
|
1124
|
+
if (setupPoison)
|
|
1125
|
+
throw new Error(setupPoison);
|
|
1126
|
+
tx.progress.command = { command: "git", args: ["-C", setup.cwd, ...args] };
|
|
1127
|
+
const result = await runSetupCommand("git", tx.progress.command.args, {
|
|
1128
|
+
deadlineAt: tx.options.deadlineAt, acceptedExitCodes,
|
|
1129
|
+
onSpawn: (process) => { Object.assign(tx.progress.command, process); tx.publish(); },
|
|
1130
|
+
});
|
|
1131
|
+
const { stdout: _stdout, stdoutBuffer: _stdoutBuffer, stderr: _stderr, ...metadata } = result;
|
|
1132
|
+
tx.progress.command.result = metadata;
|
|
1133
|
+
if (result.processTree?.state === "unknown")
|
|
1134
|
+
tx.unknown(result.error ?? "Rollback command settlement unverified");
|
|
1135
|
+
tx.publish();
|
|
1136
|
+
if (result.error || result.status === null || !acceptedExitCodes.includes(result.status))
|
|
1137
|
+
throw result.error ?? new Error(result.stderr.trim() || "Rollback command failed");
|
|
1138
|
+
return result;
|
|
1139
|
+
};
|
|
1140
|
+
for (const attempt of [...attempts].reverse()) {
|
|
1141
|
+
if (!attempt.path) {
|
|
1142
|
+
tx.unknown(`Allocation path unconfirmed for branch ${attempt.branch}`);
|
|
1143
|
+
report.errors.push(tx.progress.unknown);
|
|
1144
|
+
continue;
|
|
1145
|
+
}
|
|
1146
|
+
const known = setup.worktrees.find((worktree) => worktree.index === attempt.index);
|
|
1147
|
+
const task = { index: attempt.index, path: attempt.path, branch: attempt.branch,
|
|
1148
|
+
provider: known?.provider ?? "native", naming: known?.naming, worktreeRemoved: false, branchRemoved: false };
|
|
1149
|
+
report.tasks.push(task);
|
|
1150
|
+
try {
|
|
1151
|
+
if (normalizeComparableCwd(attempt.path) === normalizeComparableCwd(setup.cwd))
|
|
1152
|
+
throw new Error("Refusing source-checkout removal");
|
|
1153
|
+
if (attempt.validated) {
|
|
1154
|
+
await git(["worktree", "remove", "--force", attempt.path]);
|
|
1155
|
+
task.worktreeRemoved = true;
|
|
1156
|
+
}
|
|
1157
|
+
else {
|
|
1158
|
+
// Native attempts were absent before mutation. Reconcile only exact
|
|
1159
|
+
// registered path/branch identity; never recursively delete a guessed leaf.
|
|
1160
|
+
const listed = (await git(["worktree", "list", "--porcelain"])).stdout;
|
|
1161
|
+
const entry = listed.split("\n\n").find((block) => block.split("\n").includes(`worktree ${attempt.path}`));
|
|
1162
|
+
if (entry) {
|
|
1163
|
+
if (!entry.split("\n").includes(`branch refs/heads/${attempt.branch}`)) {
|
|
1164
|
+
tx.unknown("Partial allocation ownership mismatch");
|
|
1165
|
+
throw new Error(tx.progress.unknown);
|
|
1166
|
+
}
|
|
1167
|
+
await git(["worktree", "remove", "--force", attempt.path]);
|
|
1168
|
+
}
|
|
1169
|
+
else if (fs.existsSync(attempt.path)) {
|
|
1170
|
+
tx.unknown("Unregistered partial allocation retained");
|
|
1171
|
+
throw new Error(tx.progress.unknown);
|
|
1172
|
+
}
|
|
1173
|
+
task.worktreeRemoved = true;
|
|
1174
|
+
}
|
|
1175
|
+
const branch = await git(["show-ref", "--verify", "--quiet", `refs/heads/${attempt.branch}`], [0, 1]);
|
|
1176
|
+
if (branch.status === 0)
|
|
1177
|
+
await git(["branch", "-D", attempt.branch]);
|
|
1178
|
+
task.branchRemoved = true;
|
|
1179
|
+
}
|
|
1180
|
+
catch (error) {
|
|
1181
|
+
task.preserved = true;
|
|
1182
|
+
task.errors = [error instanceof Error ? error.message : String(error)];
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
try {
|
|
1186
|
+
if (attempts.length > 0) {
|
|
1187
|
+
await git(["worktree", "prune"]);
|
|
1188
|
+
report.pruned = true;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
catch (error) {
|
|
1192
|
+
report.errors.push(error instanceof Error ? error.message : String(error));
|
|
1193
|
+
}
|
|
1194
|
+
if (tx.progress.unknown)
|
|
1195
|
+
report.errors.push(tx.progress.unknown);
|
|
1196
|
+
report.tasks.sort((a, b) => a.index - b.index);
|
|
1197
|
+
if (!setupPoison && (report.pruned || attempts.length === 0) && report.tasks.every((task) => task.worktreeRemoved && task.branchRemoved) && !report.errors.length)
|
|
1198
|
+
report.state = "complete";
|
|
1199
|
+
return report;
|
|
1200
|
+
}
|
|
1201
|
+
async function allocateWorktrees(tx, cwd, runId, count) {
|
|
1202
|
+
const options = tx.options;
|
|
1203
|
+
tx.check();
|
|
1204
|
+
if (!Number.isSafeInteger(count) || count < 0)
|
|
1205
|
+
throw new Error("worktree count must be a non-negative integer");
|
|
1206
|
+
const repo = await resolveRepoState(tx, cwd, options?.baseRef);
|
|
1207
|
+
tx.progress.setup.cwd = repo.toplevel;
|
|
1208
|
+
tx.progress.setup.baseCommit = repo.baseCommit;
|
|
1209
|
+
const setupHook = resolveWorktreeSetupHook(repo.toplevel, options?.setupHook);
|
|
1210
|
+
const provider = await resolveSetupProvider(tx, options?.provider, options?.baseDir, repo.toplevel);
|
|
1211
|
+
const branchPrefix = normalizeWorktreeBranchPrefix(options?.branchPrefix);
|
|
1212
|
+
const dedicatedRoot = provider === "native"
|
|
1213
|
+
? resolveWorktreeDedicatedRoot(options?.baseDir, repo.toplevel, (options?.provider ?? DEFAULT_WORKTREE_PROVIDER) === "auto")
|
|
1214
|
+
: undefined;
|
|
1215
|
+
const worktrees = tx.progress.setup.worktrees;
|
|
1216
|
+
try {
|
|
1217
|
+
if (provider === "native") {
|
|
1218
|
+
for (let index = 0; index < count; index++) {
|
|
1219
|
+
worktrees[index] = await createNativeWorktree(tx, repo.toplevel, repo.cwdRelative, runId, index, repo.baseCommit, setupHook, options?.agents?.[index], dedicatedRoot, options?.labels, options?.tasks, branchPrefix);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
else {
|
|
1223
|
+
for (let index = 0; index < count; index++) {
|
|
1224
|
+
await createWorktrunkWorktree(tx, repo.toplevel, repo.cwdRelative, runId, index, repo.baseCommit, options?.agents, options?.labels, options?.tasks, branchPrefix);
|
|
1225
|
+
}
|
|
1226
|
+
for (let index = 0; index < worktrees.length; index++) {
|
|
1227
|
+
worktrees[index] = await finalizeCreatedWorktree(tx, repo.toplevel, repo.cwdRelative, runId, repo.baseCommit, setupHook, options?.agents?.[index], worktrees[index]);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
tx.check();
|
|
1231
|
+
tx.progress.phase = "ready";
|
|
1232
|
+
tx.publish();
|
|
1233
|
+
tx.check();
|
|
1234
|
+
return tx.progress.setup;
|
|
1235
|
+
}
|
|
1236
|
+
catch (error) {
|
|
1237
|
+
await compensateSetup(tx);
|
|
1238
|
+
throw error;
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
export async function createWorktrees(cwd, runId, count, options = {}) {
|
|
1242
|
+
const tx = new SetupTransaction(cwd, options);
|
|
1243
|
+
try {
|
|
1244
|
+
return await withWorktreeTransaction(async () => {
|
|
1245
|
+
setupActive = true;
|
|
1246
|
+
try {
|
|
1247
|
+
return await allocateWorktrees(tx, cwd, runId, count);
|
|
1248
|
+
}
|
|
1249
|
+
finally {
|
|
1250
|
+
setupActive = false;
|
|
1251
|
+
}
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
1254
|
+
catch (error) {
|
|
1255
|
+
if (setupPoison)
|
|
1256
|
+
tx.progress.unknown ??= setupPoison;
|
|
1257
|
+
tx.progress.cleanup ??= { state: tx.progress.unknown ? "partial" : "complete", tasks: [], pruned: false, errors: tx.progress.unknown ? [tx.progress.unknown] : [] };
|
|
1258
|
+
try {
|
|
1259
|
+
tx.publish();
|
|
1260
|
+
}
|
|
1261
|
+
catch (publicationError) {
|
|
1262
|
+
tx.progress.cleanup?.errors?.push(`Recovery publication failed: ${String(publicationError)}`);
|
|
1263
|
+
}
|
|
1264
|
+
throw new WorktreeSetupError(error, tx.snapshot());
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
export function diffWorktrees(setup, agents, diffsDir) {
|
|
1268
|
+
assertWorktreeMutationAllowed();
|
|
1269
|
+
try {
|
|
1270
|
+
fs.mkdirSync(diffsDir, { recursive: true });
|
|
1271
|
+
}
|
|
1272
|
+
catch {
|
|
1273
|
+
// Returning no diffs is safer than failing the whole command on artifact-dir issues.
|
|
1274
|
+
return [];
|
|
1275
|
+
}
|
|
1276
|
+
const diffs = [];
|
|
1277
|
+
for (let index = 0; index < setup.worktrees.length; index++) {
|
|
1278
|
+
const worktree = setup.worktrees[index];
|
|
1279
|
+
const agent = agents[index] ?? `task-${index + 1}`;
|
|
1280
|
+
const patchPath = path.join(diffsDir, `task-${index}-${safePatchAgentName(agent)}.patch`);
|
|
1281
|
+
try {
|
|
1282
|
+
diffs.push(captureWorktreeDiff(setup, worktree, agent, patchPath));
|
|
1283
|
+
}
|
|
1284
|
+
catch (error) {
|
|
1285
|
+
// Preserve execution flow while retaining the failed capture as handoff evidence.
|
|
1286
|
+
writeEmptyPatch(patchPath);
|
|
1287
|
+
diffs.push(emptyDiff(index, agent, worktree.branch, patchPath, error instanceof Error ? error.message : String(error)));
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
setup.capturedDiffs = diffs;
|
|
1291
|
+
return diffs;
|
|
1292
|
+
}
|
|
1293
|
+
export function cleanupWorktrees(setup, intent = { kind: "preserve", ...(setup.capturedDiffs ? { capturedDiffs: setup.capturedDiffs } : {}) }) {
|
|
1294
|
+
assertWorktreeMutationAllowed();
|
|
1295
|
+
const tasks = [];
|
|
1296
|
+
for (let index = setup.worktrees.length - 1; index >= 0; index--) {
|
|
1297
|
+
tasks.push(cleanupSingleWorktree(setup, setup.worktrees[index], intent));
|
|
1298
|
+
}
|
|
1299
|
+
tasks.sort((left, right) => left.index - right.index);
|
|
1300
|
+
const errors = [];
|
|
1301
|
+
let pruned = false;
|
|
1302
|
+
try {
|
|
1303
|
+
runGitChecked(setup.cwd, ["worktree", "prune"]);
|
|
1304
|
+
pruned = true;
|
|
1305
|
+
}
|
|
1306
|
+
catch (error) {
|
|
1307
|
+
errors.push(`worktree prune failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1308
|
+
}
|
|
1309
|
+
const state = tasks.every((task) => task.worktreeRemoved && task.branchRemoved) && pruned ? "complete" : "partial";
|
|
1310
|
+
return {
|
|
1311
|
+
state,
|
|
1312
|
+
tasks,
|
|
1313
|
+
pruned,
|
|
1314
|
+
...(errors.length ? { errors } : {}),
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
export function formatWorktreeDiffSummary(diffs) {
|
|
1318
|
+
const changed = diffs.filter(hasWorktreeChanges);
|
|
1319
|
+
if (changed.length === 0)
|
|
1320
|
+
return "";
|
|
1321
|
+
const lines = ["=== Worktree Changes ===", ""];
|
|
1322
|
+
for (const diff of changed) {
|
|
1323
|
+
lines.push(`--- Task ${diff.index + 1} (${diff.agent}): ${diff.filesChanged} files changed, +${diff.insertions} -${diff.deletions} ---`);
|
|
1324
|
+
if (diff.diffStat.trim().length > 0) {
|
|
1325
|
+
lines.push(diff.diffStat);
|
|
1326
|
+
}
|
|
1327
|
+
lines.push("");
|
|
1328
|
+
}
|
|
1329
|
+
const patchesDir = path.dirname(changed[0].patchPath);
|
|
1330
|
+
lines.push(`Full patches: ${patchesDir}`);
|
|
1331
|
+
return lines.join("\n").trimEnd();
|
|
1332
|
+
}
|
|
1333
|
+
//# sourceMappingURL=worktree.js.map
|