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,2622 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent discovery and configuration
|
|
3
|
+
*/
|
|
4
|
+
import { execSync } from "node:child_process";
|
|
5
|
+
import * as fs from "node:fs";
|
|
6
|
+
import { parse as parseYaml } from "yaml";
|
|
7
|
+
import * as os from "node:os";
|
|
8
|
+
import * as path from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL, isCodeOwnedExternalCliAdapterId, parseExternalCliCapabilityNarrowing, validateCodeOwnedProfileRunner } from "../runs/shared/external-cli-contract.js";
|
|
11
|
+
import { getAgentDir, getProjectConfigDir } from "../shared/utils.js";
|
|
12
|
+
import { expandHomePath } from "../shared/settings.js";
|
|
13
|
+
import { KNOWN_FIELDS } from "./agent-serializer.js";
|
|
14
|
+
import { parseChain, parseJsonChain } from "./chain-serializer.js";
|
|
15
|
+
import { mergeAgentsForScope } from "./agent-selection.js";
|
|
16
|
+
import { parseFrontmatter, parseFrontmatterList } from "./frontmatter.js";
|
|
17
|
+
import { buildRuntimeName, parsePackageName } from "./identity.js";
|
|
18
|
+
import { parseModelScopeConfig } from "../runs/shared/model-scope.js";
|
|
19
|
+
export { BUILTIN_AGENT_NAMES } from "./builtin-names.js";
|
|
20
|
+
export { buildRuntimeName, frontmatterNameForConfig, parsePackageName } from "./identity.js";
|
|
21
|
+
import { parseMemoryFrontmatter } from "./agent-memory.js";
|
|
22
|
+
import { validateAcceptanceInput } from "../runs/shared/acceptance.js";
|
|
23
|
+
import { validatePermissionRules } from "../runs/shared/permissions.js";
|
|
24
|
+
import { parseThinkingLevel } from "../shared/thinking-ceiling.js";
|
|
25
|
+
import { assertJsonSchemaObject } from "../runs/shared/structured-output.js";
|
|
26
|
+
import { normalizeCapabilityCeilingAllowedAgents } from "../runs/shared/capability-ceiling.js";
|
|
27
|
+
export function defaultSystemPromptMode(name) {
|
|
28
|
+
return name === "delegate" ? "append" : "replace";
|
|
29
|
+
}
|
|
30
|
+
export function defaultInheritProjectContext(name) {
|
|
31
|
+
return name === "delegate";
|
|
32
|
+
}
|
|
33
|
+
export function defaultInheritSkills() {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const EMPTY_SUBAGENT_SETTINGS = { overrides: {}, providerOverrides: {} };
|
|
37
|
+
const agentFrontmatterFields = new WeakMap();
|
|
38
|
+
const AGENT_SOURCE_PRIORITY = {
|
|
39
|
+
builtin: 0,
|
|
40
|
+
package: 1,
|
|
41
|
+
user: 2,
|
|
42
|
+
project: 3,
|
|
43
|
+
runtime: 4,
|
|
44
|
+
};
|
|
45
|
+
function agentDefinitionPriority(definition) {
|
|
46
|
+
return AGENT_SOURCE_PRIORITY[definition.source] * 1_000_000
|
|
47
|
+
+ (definition.discoveryPriority ?? 0);
|
|
48
|
+
}
|
|
49
|
+
export function findBlockingAgentDiagnostic(name, agent, diagnostics) {
|
|
50
|
+
const normalizedName = name.trim();
|
|
51
|
+
const agents = Array.isArray(agent) ? agent : agent ? [agent] : [];
|
|
52
|
+
let match;
|
|
53
|
+
for (const diagnostic of diagnostics ?? []) {
|
|
54
|
+
if ((diagnostic.runtimeName === normalizedName
|
|
55
|
+
|| (diagnostic.name === normalizedName && (!diagnostic.packageSpecified
|
|
56
|
+
|| diagnostic.runtimeName === undefined
|
|
57
|
+
|| agents.some((agent) => agent.name === diagnostic.runtimeName && agent.localName === diagnostic.name))))
|
|
58
|
+
&& (!match || agentDefinitionPriority(diagnostic) > agentDefinitionPriority(match))) {
|
|
59
|
+
match = diagnostic;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const highestPriority = Math.max(...agents.map(agentDefinitionPriority), -Infinity);
|
|
63
|
+
return !agents.length || (match && agentDefinitionPriority(match) > highestPriority) ? match : undefined;
|
|
64
|
+
}
|
|
65
|
+
/** Create formatter input from the exact discovery operation used for resolution. */
|
|
66
|
+
export function unknownAgentDiagnosticContext(discovered) {
|
|
67
|
+
return {
|
|
68
|
+
cwd: discovered.cwd,
|
|
69
|
+
scope: discovered.scope,
|
|
70
|
+
directories: discovered.directories,
|
|
71
|
+
agents: discovered.agents,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** Render local discovery evidence without exposing filesystem error details. */
|
|
75
|
+
export function formatUnknownAgentError(name, context, prefix = "Unknown agent") {
|
|
76
|
+
const directories = context.directories.map((directory) => {
|
|
77
|
+
const state = directory.state === "candidates"
|
|
78
|
+
? `${directory.candidateCount ?? 0} candidate${directory.candidateCount === 1 ? "" : "s"}`
|
|
79
|
+
: directory.state === "empty" ? "present but empty"
|
|
80
|
+
: directory.state === "not-directory" ? "not a directory"
|
|
81
|
+
: directory.state;
|
|
82
|
+
return `- ${directory.source}: ${directory.path} (${state})`;
|
|
83
|
+
});
|
|
84
|
+
const agents = [...context.agents]
|
|
85
|
+
.sort((left, right) => left.name.localeCompare(right.name) || left.source.localeCompare(right.source))
|
|
86
|
+
.map((agent) => `- ${agent.name} (${agent.source})`);
|
|
87
|
+
return [
|
|
88
|
+
`${prefix}: ${name}`,
|
|
89
|
+
`Effective cwd: ${path.resolve(context.cwd)}`,
|
|
90
|
+
"Consulted agent-definition directories:",
|
|
91
|
+
...(directories.length ? directories : ["- (none)"]),
|
|
92
|
+
"Discovered agents:",
|
|
93
|
+
...(agents.length ? agents : ["- (none)"]),
|
|
94
|
+
].join("\n");
|
|
95
|
+
}
|
|
96
|
+
function getUserChainDir() {
|
|
97
|
+
return path.join(getAgentDir(), "chains");
|
|
98
|
+
}
|
|
99
|
+
let cachedGlobalNpmRoot = null;
|
|
100
|
+
function readJsonFileBestEffort(filePath) {
|
|
101
|
+
try {
|
|
102
|
+
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
// Installed package scans are opportunistic; bad third-party manifests
|
|
106
|
+
// should not break local agent discovery.
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function isSafePackagePath(value) {
|
|
111
|
+
return value.length > 0
|
|
112
|
+
&& !path.isAbsolute(value)
|
|
113
|
+
&& value.split(/[\\/]/).every((part) => part.length > 0 && part !== "." && part !== "..");
|
|
114
|
+
}
|
|
115
|
+
function parseNpmPackageName(source) {
|
|
116
|
+
const spec = source.slice(4).trim();
|
|
117
|
+
if (!spec)
|
|
118
|
+
return undefined;
|
|
119
|
+
const match = spec.match(/^(@?[^@]+(?:\/[^@]+)?)(?:@(.+))?$/);
|
|
120
|
+
const packageName = match?.[1] ?? spec;
|
|
121
|
+
return isSafePackagePath(packageName) ? packageName : undefined;
|
|
122
|
+
}
|
|
123
|
+
function stripGitRef(repoPath) {
|
|
124
|
+
const atIndex = repoPath.indexOf("@");
|
|
125
|
+
const hashIndex = repoPath.indexOf("#");
|
|
126
|
+
const refIndex = [atIndex, hashIndex].filter((index) => index >= 0).sort((a, b) => a - b)[0];
|
|
127
|
+
return refIndex === undefined ? repoPath : repoPath.slice(0, refIndex);
|
|
128
|
+
}
|
|
129
|
+
function parseGitPackagePath(source) {
|
|
130
|
+
const spec = source.slice(4).trim();
|
|
131
|
+
if (!spec)
|
|
132
|
+
return undefined;
|
|
133
|
+
let host = "";
|
|
134
|
+
let repoPath = "";
|
|
135
|
+
const scpLike = spec.match(/^git@([^:]+):(.+)$/);
|
|
136
|
+
if (scpLike) {
|
|
137
|
+
host = scpLike[1] ?? "";
|
|
138
|
+
repoPath = scpLike[2] ?? "";
|
|
139
|
+
}
|
|
140
|
+
else if (/^[a-z][a-z0-9+.-]*:\/\//i.test(spec)) {
|
|
141
|
+
try {
|
|
142
|
+
const url = new URL(spec);
|
|
143
|
+
host = url.hostname;
|
|
144
|
+
repoPath = url.pathname.replace(/^\/+/, "");
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const slashIndex = spec.indexOf("/");
|
|
152
|
+
if (slashIndex < 0)
|
|
153
|
+
return undefined;
|
|
154
|
+
host = spec.slice(0, slashIndex);
|
|
155
|
+
repoPath = spec.slice(slashIndex + 1);
|
|
156
|
+
}
|
|
157
|
+
const normalizedPath = stripGitRef(repoPath).replace(/\.git$/, "").replace(/^\/+/, "");
|
|
158
|
+
if (!host || !isSafePackagePath(host) || !isSafePackagePath(normalizedPath) || normalizedPath.split(/[\\/]/).length < 2) {
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
return { host, repoPath: normalizedPath };
|
|
162
|
+
}
|
|
163
|
+
function resolveSettingsPackageRoot(source, baseDir) {
|
|
164
|
+
const trimmed = source.trim();
|
|
165
|
+
if (!trimmed)
|
|
166
|
+
return undefined;
|
|
167
|
+
if (trimmed.startsWith("git:")) {
|
|
168
|
+
const parsed = parseGitPackagePath(trimmed);
|
|
169
|
+
return parsed ? path.join(baseDir, "git", parsed.host, parsed.repoPath) : undefined;
|
|
170
|
+
}
|
|
171
|
+
if (trimmed.startsWith("npm:")) {
|
|
172
|
+
const packageName = parseNpmPackageName(trimmed);
|
|
173
|
+
return packageName ? path.join(baseDir, "npm", "node_modules", packageName) : undefined;
|
|
174
|
+
}
|
|
175
|
+
const normalized = trimmed.startsWith("file:") ? trimmed.slice(5) : trimmed;
|
|
176
|
+
if (normalized === "~")
|
|
177
|
+
return os.homedir();
|
|
178
|
+
if (normalized.startsWith("~/"))
|
|
179
|
+
return path.join(os.homedir(), normalized.slice(2));
|
|
180
|
+
if (path.isAbsolute(normalized))
|
|
181
|
+
return normalized;
|
|
182
|
+
if (normalized === "." || normalized === ".." || normalized.startsWith("./") || normalized.startsWith("../")) {
|
|
183
|
+
return path.resolve(baseDir, normalized);
|
|
184
|
+
}
|
|
185
|
+
if (/^https?:\/\//i.test(trimmed)) {
|
|
186
|
+
const parsed = parseGitPackagePath(`git:${trimmed}`);
|
|
187
|
+
return parsed ? path.join(baseDir, "git", parsed.host, parsed.repoPath) : undefined;
|
|
188
|
+
}
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
function getGlobalNpmRoot() {
|
|
192
|
+
const offline = process.env.PI_OFFLINE?.toLowerCase();
|
|
193
|
+
if (offline === "1" || offline === "true" || offline === "yes")
|
|
194
|
+
return null;
|
|
195
|
+
if (cachedGlobalNpmRoot !== null)
|
|
196
|
+
return cachedGlobalNpmRoot;
|
|
197
|
+
const windowsGlobalRoot = process.platform === "win32" && process.env.APPDATA
|
|
198
|
+
? path.join(process.env.APPDATA, "npm", "node_modules")
|
|
199
|
+
: undefined;
|
|
200
|
+
if (windowsGlobalRoot) {
|
|
201
|
+
try {
|
|
202
|
+
if (fs.statSync(windowsGlobalRoot).isDirectory()) {
|
|
203
|
+
cachedGlobalNpmRoot = fs.realpathSync(windowsGlobalRoot);
|
|
204
|
+
return cachedGlobalNpmRoot;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
// Fall through if the directory disappears while resolving it.
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
cachedGlobalNpmRoot = fs.realpathSync(execSync("npm root -g", { encoding: "utf-8", timeout: 5000, windowsHide: true, stdio: ["ignore", "pipe", "ignore"] }).trim());
|
|
213
|
+
return cachedGlobalNpmRoot;
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
cachedGlobalNpmRoot = "";
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function stringArray(value) {
|
|
221
|
+
if (!Array.isArray(value))
|
|
222
|
+
return [];
|
|
223
|
+
return value.filter((entry) => typeof entry === "string" && entry.trim().length > 0);
|
|
224
|
+
}
|
|
225
|
+
function packageMetadata(pkg, packageRoot) {
|
|
226
|
+
const name = typeof pkg.name === "string" && pkg.name.trim() ? pkg.name.trim() : undefined;
|
|
227
|
+
const version = typeof pkg.version === "string" && pkg.version.trim() ? pkg.version.trim() : undefined;
|
|
228
|
+
return {
|
|
229
|
+
packageRoot,
|
|
230
|
+
...(name ? { packageName: name } : {}),
|
|
231
|
+
...(version ? { packageVersion: version } : {}),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
function extractSubagentPathsFromPackageRoot(packageRoot, scope) {
|
|
235
|
+
const packageJsonPath = path.join(packageRoot, "package.json");
|
|
236
|
+
const pkg = readJsonFileBestEffort(packageJsonPath);
|
|
237
|
+
if (!pkg || typeof pkg !== "object" || Array.isArray(pkg))
|
|
238
|
+
return { agents: [], chains: [], watchPaths: [packageJsonPath], settingsErrors: {} };
|
|
239
|
+
const pkgRecord = pkg;
|
|
240
|
+
const metadata = packageMetadata(pkgRecord, packageRoot);
|
|
241
|
+
const roots = [];
|
|
242
|
+
const piSubagents = pkgRecord["pi-subagents"];
|
|
243
|
+
if (piSubagents && typeof piSubagents === "object" && !Array.isArray(piSubagents)) {
|
|
244
|
+
roots.push(piSubagents);
|
|
245
|
+
}
|
|
246
|
+
const pi = pkgRecord.pi;
|
|
247
|
+
if (pi && typeof pi === "object" && !Array.isArray(pi)) {
|
|
248
|
+
const subagents = pi.subagents;
|
|
249
|
+
if (subagents && typeof subagents === "object" && !Array.isArray(subagents)) {
|
|
250
|
+
roots.push(subagents);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const agents = [];
|
|
254
|
+
const chains = [];
|
|
255
|
+
for (const root of roots) {
|
|
256
|
+
for (const entry of stringArray(root.agents))
|
|
257
|
+
agents.push({ dir: path.resolve(packageRoot, entry), scope, ...metadata });
|
|
258
|
+
for (const entry of stringArray(root.chains))
|
|
259
|
+
chains.push({ dir: path.resolve(packageRoot, entry), scope, packageRoot });
|
|
260
|
+
}
|
|
261
|
+
return { agents, chains, watchPaths: [packageJsonPath], settingsErrors: {} };
|
|
262
|
+
}
|
|
263
|
+
function collectPackageRootsFromNodeModules(nodeModulesDir, watchPaths) {
|
|
264
|
+
const roots = [];
|
|
265
|
+
watchPaths?.push(nodeModulesDir);
|
|
266
|
+
if (!fs.existsSync(nodeModulesDir))
|
|
267
|
+
return roots;
|
|
268
|
+
let entries;
|
|
269
|
+
try {
|
|
270
|
+
entries = fs.readdirSync(nodeModulesDir, { withFileTypes: true });
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
return roots;
|
|
274
|
+
}
|
|
275
|
+
for (const entry of entries) {
|
|
276
|
+
if (entry.name.startsWith("."))
|
|
277
|
+
continue;
|
|
278
|
+
if (!entry.isDirectory() && !entry.isSymbolicLink())
|
|
279
|
+
continue;
|
|
280
|
+
if (entry.name.startsWith("@")) {
|
|
281
|
+
const scopeDir = path.join(nodeModulesDir, entry.name);
|
|
282
|
+
watchPaths?.push(scopeDir);
|
|
283
|
+
let scopeEntries;
|
|
284
|
+
try {
|
|
285
|
+
scopeEntries = fs.readdirSync(scopeDir, { withFileTypes: true });
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
for (const scopeEntry of scopeEntries) {
|
|
291
|
+
if (scopeEntry.name.startsWith("."))
|
|
292
|
+
continue;
|
|
293
|
+
if (!scopeEntry.isDirectory() && !scopeEntry.isSymbolicLink())
|
|
294
|
+
continue;
|
|
295
|
+
roots.push(path.join(scopeDir, scopeEntry.name));
|
|
296
|
+
}
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
roots.push(path.join(nodeModulesDir, entry.name));
|
|
300
|
+
}
|
|
301
|
+
return roots;
|
|
302
|
+
}
|
|
303
|
+
function collectSettingsPackageRoots(settingsFile, baseDir) {
|
|
304
|
+
const settings = readSettingsFileStrict(settingsFile);
|
|
305
|
+
const packages = settings.packages;
|
|
306
|
+
if (!Array.isArray(packages))
|
|
307
|
+
return [];
|
|
308
|
+
const roots = [];
|
|
309
|
+
for (const entry of packages) {
|
|
310
|
+
const packageSource = typeof entry === "string"
|
|
311
|
+
? entry
|
|
312
|
+
: typeof entry === "object" && entry !== null && "source" in entry && typeof entry.source === "string"
|
|
313
|
+
? entry.source
|
|
314
|
+
: undefined;
|
|
315
|
+
if (!packageSource)
|
|
316
|
+
continue;
|
|
317
|
+
const packageRoot = resolveSettingsPackageRoot(packageSource, baseDir);
|
|
318
|
+
if (packageRoot)
|
|
319
|
+
roots.push(packageRoot);
|
|
320
|
+
}
|
|
321
|
+
return roots;
|
|
322
|
+
}
|
|
323
|
+
function collectPackageSubagentPaths(cwd, options = { includeUser: true, includeProject: true }) {
|
|
324
|
+
const agentDir = getAgentDir();
|
|
325
|
+
const projectRoot = findConfiguredProjectRoot(cwd) ?? cwd;
|
|
326
|
+
const packageRoots = [
|
|
327
|
+
{ root: projectRoot, scope: "root" },
|
|
328
|
+
];
|
|
329
|
+
const watchPaths = [path.join(projectRoot, "package.json")];
|
|
330
|
+
const settingsErrors = {};
|
|
331
|
+
const collectScopedSettingsRoots = (scope, settingsFile, baseDir) => {
|
|
332
|
+
try {
|
|
333
|
+
return collectSettingsPackageRoots(settingsFile, baseDir);
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
// The raw source snapshot includes both settings scopes. Defer a
|
|
337
|
+
// strict failure until a projection actually selects this scope so an
|
|
338
|
+
// unrelated malformed settings file stays out of scoped discovery.
|
|
339
|
+
settingsErrors[scope] = error instanceof Error
|
|
340
|
+
? error
|
|
341
|
+
: new Error(`Failed to read settings file '${settingsFile}': ${String(error)}`, { cause: error });
|
|
342
|
+
return [];
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
if (options.includeProject) {
|
|
346
|
+
const projectConfigDir = getProjectConfigDir(projectRoot);
|
|
347
|
+
const nodeModulesDir = path.join(projectConfigDir, "npm", "node_modules");
|
|
348
|
+
packageRoots.push(...collectPackageRootsFromNodeModules(nodeModulesDir, watchPaths).map((root) => ({ root, scope: "project" })));
|
|
349
|
+
packageRoots.push(...collectScopedSettingsRoots("project", path.join(projectConfigDir, "settings.json"), projectConfigDir).map((root) => ({ root, scope: "project" })));
|
|
350
|
+
}
|
|
351
|
+
if (options.includeUser) {
|
|
352
|
+
const nodeModulesDir = path.join(agentDir, "npm", "node_modules");
|
|
353
|
+
packageRoots.push(...collectPackageRootsFromNodeModules(nodeModulesDir, watchPaths).map((root) => ({ root, scope: "user" })));
|
|
354
|
+
packageRoots.push(...collectScopedSettingsRoots("user", path.join(agentDir, "settings.json"), agentDir).map((root) => ({ root, scope: "user" })));
|
|
355
|
+
}
|
|
356
|
+
if (options.includeUser) {
|
|
357
|
+
const globalRoot = getGlobalNpmRoot();
|
|
358
|
+
if (globalRoot) {
|
|
359
|
+
packageRoots.push(...collectPackageRootsFromNodeModules(globalRoot, watchPaths).map((root) => ({ root, scope: "user" })));
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
const seenRoots = new Map();
|
|
363
|
+
const seenAgents = new Map();
|
|
364
|
+
const seenChains = new Map();
|
|
365
|
+
const agents = [];
|
|
366
|
+
const chains = [];
|
|
367
|
+
for (const { root: packageRoot, scope } of packageRoots) {
|
|
368
|
+
const resolvedRoot = path.resolve(packageRoot);
|
|
369
|
+
const scopes = seenRoots.get(resolvedRoot);
|
|
370
|
+
if (scopes !== undefined) {
|
|
371
|
+
scopes.add(scope);
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
const packageScopes = new Set([scope]);
|
|
375
|
+
seenRoots.set(resolvedRoot, packageScopes);
|
|
376
|
+
const paths = extractSubagentPathsFromPackageRoot(resolvedRoot, packageScopes);
|
|
377
|
+
watchPaths.push(...paths.watchPaths);
|
|
378
|
+
for (const agentPath of paths.agents) {
|
|
379
|
+
const agentKey = `${agentPath.dir}\u0000${agentPath.packageRoot}`;
|
|
380
|
+
const existing = seenAgents.get(agentKey);
|
|
381
|
+
if (existing) {
|
|
382
|
+
for (const packageScope of agentPath.scope)
|
|
383
|
+
existing.scope.add(packageScope);
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
seenAgents.set(agentKey, agentPath);
|
|
387
|
+
agents.push(agentPath);
|
|
388
|
+
}
|
|
389
|
+
for (const chainDir of paths.chains) {
|
|
390
|
+
const chainKey = `${chainDir.dir}\u0000${chainDir.packageRoot}`;
|
|
391
|
+
const existing = seenChains.get(chainKey);
|
|
392
|
+
if (existing) {
|
|
393
|
+
for (const packageScope of chainDir.scope)
|
|
394
|
+
existing.scope.add(packageScope);
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
seenChains.set(chainKey, chainDir);
|
|
398
|
+
chains.push(chainDir);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return { agents, chains, watchPaths, settingsErrors };
|
|
402
|
+
}
|
|
403
|
+
function normalizeAgentAliases(rawAliases, agentName) {
|
|
404
|
+
const aliases = [...new Set((rawAliases ?? []).map((alias) => alias.trim()).filter(Boolean))]
|
|
405
|
+
.filter((alias) => alias !== agentName);
|
|
406
|
+
return aliases.length > 0 ? aliases : undefined;
|
|
407
|
+
}
|
|
408
|
+
function effectiveAgentMatch(matches) {
|
|
409
|
+
const distinctNames = [...new Set(matches.map((agent) => agent.name))];
|
|
410
|
+
if (distinctNames.length === 1) {
|
|
411
|
+
const sourceRank = new Map([["builtin", 0], ["package", 1], ["user", 2], ["project", 3], ["runtime", 4]]);
|
|
412
|
+
const agent = [...matches].sort((a, b) => (sourceRank.get(b.source) ?? 0) - (sourceRank.get(a.source) ?? 0))[0];
|
|
413
|
+
return agent ? { agent } : {};
|
|
414
|
+
}
|
|
415
|
+
return {};
|
|
416
|
+
}
|
|
417
|
+
export function resolveAgentName(name, agents) {
|
|
418
|
+
const raw = name.trim();
|
|
419
|
+
const canonical = agents.filter((agent) => agent.name === raw);
|
|
420
|
+
if (canonical.length === 1)
|
|
421
|
+
return canonical[0] ? { agent: canonical[0] } : {};
|
|
422
|
+
if (canonical.length > 1) {
|
|
423
|
+
const effective = effectiveAgentMatch(canonical);
|
|
424
|
+
if (effective.agent)
|
|
425
|
+
return effective;
|
|
426
|
+
return { error: `Ambiguous agent name '${name}': ${canonical.map((agent) => agent.name).join(", ")}` };
|
|
427
|
+
}
|
|
428
|
+
const local = agents.filter((agent) => agent.localName === raw);
|
|
429
|
+
if (local.length === 1)
|
|
430
|
+
return local[0] ? { agent: local[0] } : {};
|
|
431
|
+
if (local.length > 1) {
|
|
432
|
+
const effective = effectiveAgentMatch(local);
|
|
433
|
+
if (effective.agent)
|
|
434
|
+
return effective;
|
|
435
|
+
return { error: `Ambiguous local agent name '${name}': ${local.map((agent) => agent.name).join(", ")}` };
|
|
436
|
+
}
|
|
437
|
+
const aliases = agents.filter((agent) => agent.aliases?.includes(raw));
|
|
438
|
+
if (aliases.length === 1)
|
|
439
|
+
return aliases[0] ? { agent: aliases[0] } : {};
|
|
440
|
+
if (aliases.length > 1) {
|
|
441
|
+
const effective = effectiveAgentMatch(aliases);
|
|
442
|
+
if (effective.agent)
|
|
443
|
+
return effective;
|
|
444
|
+
return { error: `Ambiguous agent alias '${name}': ${aliases.map((agent) => agent.name).join(", ")}` };
|
|
445
|
+
}
|
|
446
|
+
return {};
|
|
447
|
+
}
|
|
448
|
+
function splitToolList(rawTools) {
|
|
449
|
+
const mcpDirectTools = [];
|
|
450
|
+
const tools = [];
|
|
451
|
+
for (const tool of rawTools ?? []) {
|
|
452
|
+
if (tool.startsWith("mcp:")) {
|
|
453
|
+
mcpDirectTools.push(tool.slice(4));
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
tools.push(tool);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return {
|
|
460
|
+
...(rawTools !== undefined ? { tools } : {}),
|
|
461
|
+
...(mcpDirectTools.length > 0 ? { mcpDirectTools } : {}),
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
function joinToolList(config) {
|
|
465
|
+
const joined = [
|
|
466
|
+
...(config.tools ?? []),
|
|
467
|
+
...(config.mcpDirectTools ?? []).map((tool) => `mcp:${tool}`),
|
|
468
|
+
];
|
|
469
|
+
return joined.length > 0 ? joined : undefined;
|
|
470
|
+
}
|
|
471
|
+
function arraysEqual(a, b) {
|
|
472
|
+
if (!a && !b)
|
|
473
|
+
return true;
|
|
474
|
+
if (!a || !b)
|
|
475
|
+
return false;
|
|
476
|
+
if (a.length !== b.length)
|
|
477
|
+
return false;
|
|
478
|
+
for (let i = 0; i < a.length; i++) {
|
|
479
|
+
if (a[i] !== b[i])
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
function cloneOverrideBase(agent) {
|
|
485
|
+
return {
|
|
486
|
+
description: agent.description,
|
|
487
|
+
...(agent.machine !== undefined ? { machine: agent.machine } : {}),
|
|
488
|
+
...(agent.output !== undefined ? { output: agent.output } : {}),
|
|
489
|
+
...(agent.outputMode !== undefined ? { outputMode: agent.outputMode } : {}),
|
|
490
|
+
...(agent.defaultReads !== undefined ? { defaultReads: [...agent.defaultReads] } : {}),
|
|
491
|
+
...(agent.model !== undefined ? { model: agent.model } : {}),
|
|
492
|
+
...(agent.modelProvider !== undefined ? { modelProvider: agent.modelProvider } : {}),
|
|
493
|
+
...(agent.fast !== undefined ? { fast: agent.fast } : {}),
|
|
494
|
+
...(agent.thinking !== undefined ? { thinking: agent.thinking } : {}),
|
|
495
|
+
systemPromptMode: agent.systemPromptMode,
|
|
496
|
+
inheritProjectContext: agent.inheritProjectContext,
|
|
497
|
+
inheritGlobalContext: agent.inheritGlobalContext,
|
|
498
|
+
inheritSkills: agent.inheritSkills,
|
|
499
|
+
...(agent.defaultContext !== undefined ? { defaultContext: agent.defaultContext } : {}),
|
|
500
|
+
...(agent.acceptanceRole !== undefined ? { acceptanceRole: agent.acceptanceRole } : {}),
|
|
501
|
+
...(agent.disabled !== undefined ? { disabled: agent.disabled } : {}),
|
|
502
|
+
systemPrompt: agent.systemPrompt,
|
|
503
|
+
...(agent.skills ? { skills: [...agent.skills] } : {}),
|
|
504
|
+
...(agent.skillPath ? { skillPath: [...agent.skillPath] } : {}),
|
|
505
|
+
...(agent.tools ? { tools: [...agent.tools] } : {}),
|
|
506
|
+
...(agent.excludeTools ? { excludeTools: [...agent.excludeTools] } : {}),
|
|
507
|
+
...(agent.allowNestedSubagents !== undefined ? { allowNestedSubagents: agent.allowNestedSubagents } : {}),
|
|
508
|
+
...(agent.allowedAgents !== undefined ? { allowedAgents: [...agent.allowedAgents] } : {}),
|
|
509
|
+
...(agent.mcpDirectTools ? { mcpDirectTools: [...agent.mcpDirectTools] } : {}),
|
|
510
|
+
...(!agent.extensionsFromDefault && agent.extensions ? { extensions: [...agent.extensions] } : {}),
|
|
511
|
+
...(agent.subagentOnlyExtensions ? { subagentOnlyExtensions: [...agent.subagentOnlyExtensions] } : {}),
|
|
512
|
+
...(agent.mutationTools ? { mutationTools: [...agent.mutationTools] } : {}),
|
|
513
|
+
...(agent.completionGuard !== undefined ? { completionGuard: agent.completionGuard } : {}),
|
|
514
|
+
...(agent.toolBudget !== undefined ? { toolBudget: agent.toolBudget } : {}),
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
function cloneOverrideValue(override) {
|
|
518
|
+
return {
|
|
519
|
+
...(override.description !== undefined ? { description: override.description } : {}),
|
|
520
|
+
...(override.machine !== undefined ? { machine: override.machine } : {}),
|
|
521
|
+
...(override.output !== undefined ? { output: override.output } : {}),
|
|
522
|
+
...(override.outputMode !== undefined ? { outputMode: override.outputMode } : {}),
|
|
523
|
+
...(override.defaultReads !== undefined ? { defaultReads: override.defaultReads === false ? false : [...override.defaultReads] } : {}),
|
|
524
|
+
...(override.model !== undefined ? { model: override.model } : {}),
|
|
525
|
+
...(override.defaultProvider !== undefined ? { defaultProvider: override.defaultProvider } : {}),
|
|
526
|
+
...(override.fast !== undefined ? { fast: override.fast } : {}),
|
|
527
|
+
...(override.thinking !== undefined ? { thinking: override.thinking } : {}),
|
|
528
|
+
...(override.systemPromptMode !== undefined ? { systemPromptMode: override.systemPromptMode } : {}),
|
|
529
|
+
...(override.inheritProjectContext !== undefined ? { inheritProjectContext: override.inheritProjectContext } : {}),
|
|
530
|
+
...(override.inheritGlobalContext !== undefined ? { inheritGlobalContext: override.inheritGlobalContext } : {}),
|
|
531
|
+
...(override.inheritSkills !== undefined ? { inheritSkills: override.inheritSkills } : {}),
|
|
532
|
+
...(override.defaultContext !== undefined ? { defaultContext: override.defaultContext } : {}),
|
|
533
|
+
...(override.acceptanceRole !== undefined ? { acceptanceRole: override.acceptanceRole } : {}),
|
|
534
|
+
...(override.disabled !== undefined ? { disabled: override.disabled } : {}),
|
|
535
|
+
...(override.systemPrompt !== undefined ? { systemPrompt: override.systemPrompt } : {}),
|
|
536
|
+
...(override.skills !== undefined ? { skills: override.skills === false ? false : [...override.skills] } : {}),
|
|
537
|
+
...(override.tools !== undefined ? { tools: Array.isArray(override.tools) ? [...override.tools] : override.tools } : {}),
|
|
538
|
+
...(override.excludeTools !== undefined ? { excludeTools: override.excludeTools === false ? false : [...override.excludeTools] } : {}),
|
|
539
|
+
...(override.allowNestedSubagents !== undefined ? { allowNestedSubagents: override.allowNestedSubagents } : {}),
|
|
540
|
+
...(override.allowedAgents !== undefined ? { allowedAgents: override.allowedAgents === false ? false : [...override.allowedAgents] } : {}),
|
|
541
|
+
...(override.extensions !== undefined ? { extensions: override.extensions === false ? false : [...override.extensions] } : {}),
|
|
542
|
+
...(override.subagentOnlyExtensions !== undefined ? { subagentOnlyExtensions: override.subagentOnlyExtensions === false ? false : [...override.subagentOnlyExtensions] } : {}),
|
|
543
|
+
...(override.mutationTools !== undefined ? { mutationTools: override.mutationTools === false ? false : [...override.mutationTools] } : {}),
|
|
544
|
+
...(override.completionGuard !== undefined ? { completionGuard: override.completionGuard } : {}),
|
|
545
|
+
...(override.toolBudget !== undefined ? { toolBudget: override.toolBudget === false ? false : { ...override.toolBudget, ...(Array.isArray(override.toolBudget.block) ? { block: [...override.toolBudget.block] } : {}) } } : {}),
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
function isProjectRootCandidate(dir) {
|
|
549
|
+
return isDirectory(getProjectConfigDir(dir)) || isDirectory(path.join(dir, ".agents"));
|
|
550
|
+
}
|
|
551
|
+
function findProjectRootCandidates(cwd) {
|
|
552
|
+
const roots = [];
|
|
553
|
+
const windowsProfile = process.env.HOMEDRIVE && process.env.HOMEPATH
|
|
554
|
+
? `${process.env.HOMEDRIVE}${process.env.HOMEPATH}`
|
|
555
|
+
: undefined;
|
|
556
|
+
const homeDirs = new Set([os.homedir(), process.env.HOME, process.env.USERPROFILE, windowsProfile]
|
|
557
|
+
.filter((value) => Boolean(value?.trim()))
|
|
558
|
+
.filter(isDirectory)
|
|
559
|
+
.map((value) => fs.realpathSync.native(value)));
|
|
560
|
+
let currentDir = cwd;
|
|
561
|
+
while (true) {
|
|
562
|
+
// ~/.pi and ~/.agents are user configuration, never an implicit project.
|
|
563
|
+
if (isDirectory(currentDir) && homeDirs.has(fs.realpathSync.native(currentDir)))
|
|
564
|
+
return roots;
|
|
565
|
+
if (isProjectRootCandidate(currentDir))
|
|
566
|
+
roots.push(currentDir);
|
|
567
|
+
const parentDir = path.dirname(currentDir);
|
|
568
|
+
if (parentDir === currentDir)
|
|
569
|
+
return roots;
|
|
570
|
+
currentDir = parentDir;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
export function findNearestGitRoot(cwd) {
|
|
574
|
+
let currentDir = cwd;
|
|
575
|
+
while (true) {
|
|
576
|
+
if (fs.existsSync(path.join(currentDir, ".git")))
|
|
577
|
+
return currentDir;
|
|
578
|
+
const parentDir = path.dirname(currentDir);
|
|
579
|
+
if (parentDir === currentDir)
|
|
580
|
+
return null;
|
|
581
|
+
currentDir = parentDir;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
function readProjectRootResolution(projectRoot) {
|
|
585
|
+
const settingsPath = path.join(getProjectConfigDir(projectRoot), "settings.json");
|
|
586
|
+
if (!fs.existsSync(settingsPath))
|
|
587
|
+
return undefined;
|
|
588
|
+
const settings = readSettingsFileStrict(settingsPath);
|
|
589
|
+
const subagents = settings.subagents;
|
|
590
|
+
if (!subagents || typeof subagents !== "object" || Array.isArray(subagents))
|
|
591
|
+
return undefined;
|
|
592
|
+
const value = subagents.projectRootResolution;
|
|
593
|
+
if (value === undefined)
|
|
594
|
+
return undefined;
|
|
595
|
+
if (value === "nearest" || value === "git-root")
|
|
596
|
+
return value;
|
|
597
|
+
throw new Error(`Subagent settings in '${settingsPath}' have invalid 'projectRootResolution'; expected 'nearest' or 'git-root'.`);
|
|
598
|
+
}
|
|
599
|
+
export function findNearestProjectRoot(cwd) {
|
|
600
|
+
return findProjectRootCandidates(cwd)[0] ?? null;
|
|
601
|
+
}
|
|
602
|
+
export function findConfiguredProjectRoot(cwd) {
|
|
603
|
+
const candidates = findProjectRootCandidates(cwd);
|
|
604
|
+
const nearestRoot = candidates[0];
|
|
605
|
+
if (!nearestRoot)
|
|
606
|
+
return null;
|
|
607
|
+
let policyRoot;
|
|
608
|
+
let policyRootIndex = -1;
|
|
609
|
+
for (const [index, candidate] of candidates.entries()) {
|
|
610
|
+
const mode = readProjectRootResolution(candidate);
|
|
611
|
+
if (mode === "nearest")
|
|
612
|
+
return nearestRoot;
|
|
613
|
+
if (mode === "git-root") {
|
|
614
|
+
policyRoot = candidate;
|
|
615
|
+
policyRootIndex = index;
|
|
616
|
+
break;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
if (!policyRoot)
|
|
620
|
+
return nearestRoot;
|
|
621
|
+
const gitRoot = findNearestGitRoot(cwd);
|
|
622
|
+
const gitProjectRoot = gitRoot
|
|
623
|
+
? candidates.slice(policyRootIndex).find((candidate) => path.resolve(candidate) === path.resolve(gitRoot))
|
|
624
|
+
: undefined;
|
|
625
|
+
const configuredGitRoot = fs.existsSync(path.join(policyRoot, ".git")) ? policyRoot : undefined;
|
|
626
|
+
return gitProjectRoot ?? configuredGitRoot ?? nearestRoot;
|
|
627
|
+
}
|
|
628
|
+
function getUserAgentSettingsPath() {
|
|
629
|
+
return path.join(getAgentDir(), "settings.json");
|
|
630
|
+
}
|
|
631
|
+
function getProjectAgentSettingsPath(cwd) {
|
|
632
|
+
const projectRoot = findConfiguredProjectRoot(cwd);
|
|
633
|
+
return projectRoot ? path.join(getProjectConfigDir(projectRoot), "settings.json") : null;
|
|
634
|
+
}
|
|
635
|
+
function readSettingsFileStrict(filePath) {
|
|
636
|
+
if (!fs.existsSync(filePath))
|
|
637
|
+
return {};
|
|
638
|
+
let raw;
|
|
639
|
+
try {
|
|
640
|
+
raw = fs.readFileSync(filePath, "utf-8");
|
|
641
|
+
}
|
|
642
|
+
catch (error) {
|
|
643
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
644
|
+
throw new Error(`Failed to read settings file '${filePath}': ${message}`, { cause: error });
|
|
645
|
+
}
|
|
646
|
+
let parsed;
|
|
647
|
+
try {
|
|
648
|
+
parsed = JSON.parse(raw);
|
|
649
|
+
}
|
|
650
|
+
catch (error) {
|
|
651
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
652
|
+
throw new Error(`Failed to parse settings file '${filePath}': ${message}`, { cause: error });
|
|
653
|
+
}
|
|
654
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
655
|
+
throw new Error(`Settings file '${filePath}' must contain a JSON object.`);
|
|
656
|
+
}
|
|
657
|
+
return parsed;
|
|
658
|
+
}
|
|
659
|
+
function writeSettingsFile(filePath, settings) {
|
|
660
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
661
|
+
fs.writeFileSync(filePath, JSON.stringify(settings, null, 2) + "\n", "utf-8");
|
|
662
|
+
}
|
|
663
|
+
function parseOverrideStringArrayOrFalse(value, meta) {
|
|
664
|
+
if (value === undefined)
|
|
665
|
+
return undefined;
|
|
666
|
+
if (value === false)
|
|
667
|
+
return false;
|
|
668
|
+
if (!Array.isArray(value)) {
|
|
669
|
+
throw new Error(`Builtin override '${meta.name}' in '${meta.filePath}' has invalid '${meta.field}'; expected an array of strings or false.`);
|
|
670
|
+
}
|
|
671
|
+
const items = [];
|
|
672
|
+
for (const item of value) {
|
|
673
|
+
if (typeof item !== "string") {
|
|
674
|
+
throw new Error(`Builtin override '${meta.name}' in '${meta.filePath}' has invalid '${meta.field}'; expected an array of strings or false.`);
|
|
675
|
+
}
|
|
676
|
+
const trimmed = item.trim();
|
|
677
|
+
if (trimmed)
|
|
678
|
+
items.push(trimmed);
|
|
679
|
+
}
|
|
680
|
+
return items;
|
|
681
|
+
}
|
|
682
|
+
function parseToolsOverride(value, meta) {
|
|
683
|
+
if (typeof value === "string" && value.trim() === "inherit")
|
|
684
|
+
return "inherit";
|
|
685
|
+
if (value === undefined || value === false || Array.isArray(value)) {
|
|
686
|
+
return parseOverrideStringArrayOrFalse(value, { ...meta, field: "tools" });
|
|
687
|
+
}
|
|
688
|
+
throw new Error(`Builtin override '${meta.name}' in '${meta.filePath}' has invalid 'tools'; expected an array of strings, "inherit", or false.`);
|
|
689
|
+
}
|
|
690
|
+
function validateOptionalMachine(value, label) {
|
|
691
|
+
if (value === undefined || value === false)
|
|
692
|
+
return undefined;
|
|
693
|
+
if (typeof value !== "string" || !value.trim())
|
|
694
|
+
throw new Error(label + " must be a non-empty string or false.");
|
|
695
|
+
const machine = value.trim();
|
|
696
|
+
if (machine.length > 128)
|
|
697
|
+
throw new Error(label + " must be 128 characters or fewer.");
|
|
698
|
+
if (/[\u0000-\u001f\u007f]/u.test(machine))
|
|
699
|
+
throw new Error(label + " contains control characters.");
|
|
700
|
+
return machine;
|
|
701
|
+
}
|
|
702
|
+
function parseBuiltinOverrideEntry(name, value, filePath) {
|
|
703
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
704
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' must be an object.`);
|
|
705
|
+
}
|
|
706
|
+
const input = value;
|
|
707
|
+
if (Object.hasOwn(input, "fallbackModels")) {
|
|
708
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' uses removed field 'fallbackModels'; configure one model instead.`);
|
|
709
|
+
}
|
|
710
|
+
const override = {};
|
|
711
|
+
if ("description" in input) {
|
|
712
|
+
if (typeof input.description === "string" && input.description.trim()) {
|
|
713
|
+
override.description = input.description.trim();
|
|
714
|
+
}
|
|
715
|
+
else {
|
|
716
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'description'; expected a non-empty string.`);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
if ("output" in input) {
|
|
720
|
+
if ((typeof input.output === "string" && input.output.trim()) || input.output === false)
|
|
721
|
+
override.output = input.output;
|
|
722
|
+
else
|
|
723
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'output'; expected a non-empty string or false.`);
|
|
724
|
+
}
|
|
725
|
+
if ("outputMode" in input) {
|
|
726
|
+
if (input.outputMode === "inline" || input.outputMode === "file-only") {
|
|
727
|
+
override.outputMode = input.outputMode;
|
|
728
|
+
}
|
|
729
|
+
else {
|
|
730
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'outputMode'; expected 'inline' or 'file-only'.`);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
if ("model" in input) {
|
|
734
|
+
if (typeof input.model === "string" || input.model === false)
|
|
735
|
+
override.model = input.model;
|
|
736
|
+
else
|
|
737
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'model'; expected a string or false.`);
|
|
738
|
+
}
|
|
739
|
+
if ("fast" in input) {
|
|
740
|
+
if (typeof input.fast === "boolean")
|
|
741
|
+
override.fast = input.fast;
|
|
742
|
+
else
|
|
743
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'fast'; expected a boolean.`);
|
|
744
|
+
}
|
|
745
|
+
if ("thinking" in input) {
|
|
746
|
+
if (typeof input.thinking === "string" || input.thinking === false)
|
|
747
|
+
override.thinking = input.thinking;
|
|
748
|
+
else
|
|
749
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'thinking'; expected a string or false.`);
|
|
750
|
+
}
|
|
751
|
+
if ("systemPromptMode" in input) {
|
|
752
|
+
if (input.systemPromptMode === "append" || input.systemPromptMode === "replace") {
|
|
753
|
+
override.systemPromptMode = input.systemPromptMode;
|
|
754
|
+
}
|
|
755
|
+
else {
|
|
756
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'systemPromptMode'; expected 'append' or 'replace'.`);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
if ("inheritProjectContext" in input) {
|
|
760
|
+
if (typeof input.inheritProjectContext === "boolean") {
|
|
761
|
+
override.inheritProjectContext = input.inheritProjectContext;
|
|
762
|
+
}
|
|
763
|
+
else {
|
|
764
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'inheritProjectContext'; expected a boolean.`);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
if ("inheritGlobalContext" in input) {
|
|
768
|
+
if (typeof input.inheritGlobalContext === "boolean") {
|
|
769
|
+
override.inheritGlobalContext = input.inheritGlobalContext;
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'inheritGlobalContext'; expected a boolean.`);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
if ("inheritSkills" in input) {
|
|
776
|
+
if (typeof input.inheritSkills === "boolean") {
|
|
777
|
+
override.inheritSkills = input.inheritSkills;
|
|
778
|
+
}
|
|
779
|
+
else {
|
|
780
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'inheritSkills'; expected a boolean.`);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
if ("defaultContext" in input) {
|
|
784
|
+
if (input.defaultContext === "fresh" || input.defaultContext === "fork" || input.defaultContext === false) {
|
|
785
|
+
override.defaultContext = input.defaultContext;
|
|
786
|
+
}
|
|
787
|
+
else {
|
|
788
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'defaultContext'; expected 'fresh', 'fork', or false.`);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
if ("acceptanceRole" in input) {
|
|
792
|
+
if (input.acceptanceRole === "read-only" || input.acceptanceRole === "writer" || input.acceptanceRole === false) {
|
|
793
|
+
override.acceptanceRole = input.acceptanceRole;
|
|
794
|
+
}
|
|
795
|
+
else {
|
|
796
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'acceptanceRole'; expected 'read-only', 'writer', or false.`);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
if ("disabled" in input) {
|
|
800
|
+
if (typeof input.disabled === "boolean") {
|
|
801
|
+
override.disabled = input.disabled;
|
|
802
|
+
}
|
|
803
|
+
else {
|
|
804
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'disabled'; expected a boolean.`);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
if ("completionGuard" in input) {
|
|
808
|
+
if (typeof input.completionGuard === "boolean") {
|
|
809
|
+
override.completionGuard = input.completionGuard;
|
|
810
|
+
}
|
|
811
|
+
else {
|
|
812
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'completionGuard'; expected a boolean.`);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
if ("toolBudget" in input) {
|
|
816
|
+
if (input.toolBudget === false) {
|
|
817
|
+
override.toolBudget = false;
|
|
818
|
+
}
|
|
819
|
+
else if (input.toolBudget && typeof input.toolBudget === "object" && !Array.isArray(input.toolBudget)) {
|
|
820
|
+
override.toolBudget = input.toolBudget;
|
|
821
|
+
}
|
|
822
|
+
else {
|
|
823
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'toolBudget'; expected an object or false.`);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
if ("systemPrompt" in input) {
|
|
827
|
+
if (typeof input.systemPrompt === "string")
|
|
828
|
+
override.systemPrompt = input.systemPrompt;
|
|
829
|
+
else
|
|
830
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'systemPrompt'; expected a string.`);
|
|
831
|
+
}
|
|
832
|
+
if (input.machine === false)
|
|
833
|
+
override.machine = false;
|
|
834
|
+
else {
|
|
835
|
+
const machine = validateOptionalMachine(input.machine, `Builtin override '${name}' in '${filePath}' field 'machine'`);
|
|
836
|
+
if (machine !== undefined)
|
|
837
|
+
override.machine = machine;
|
|
838
|
+
}
|
|
839
|
+
const defaultReads = parseOverrideStringArrayOrFalse(input.defaultReads, { filePath, name, field: "defaultReads" });
|
|
840
|
+
if (defaultReads !== undefined)
|
|
841
|
+
override.defaultReads = defaultReads;
|
|
842
|
+
if ("defaultProvider" in input) {
|
|
843
|
+
if (input.defaultProvider === false)
|
|
844
|
+
override.defaultProvider = false;
|
|
845
|
+
else if (typeof input.defaultProvider === "string" && input.defaultProvider.trim())
|
|
846
|
+
override.defaultProvider = input.defaultProvider.trim();
|
|
847
|
+
else
|
|
848
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'defaultProvider'; expected a non-empty string or false.`);
|
|
849
|
+
}
|
|
850
|
+
const skills = parseOverrideStringArrayOrFalse(input.skills, { filePath, name, field: "skills" });
|
|
851
|
+
if (skills !== undefined)
|
|
852
|
+
override.skills = skills;
|
|
853
|
+
const tools = parseToolsOverride(input.tools, { filePath, name });
|
|
854
|
+
if (tools !== undefined)
|
|
855
|
+
override.tools = tools;
|
|
856
|
+
const excludeTools = parseOverrideStringArrayOrFalse(input.excludeTools, { filePath, name, field: "excludeTools" });
|
|
857
|
+
if (excludeTools !== undefined)
|
|
858
|
+
override.excludeTools = excludeTools;
|
|
859
|
+
if ("allowNestedSubagents" in input) {
|
|
860
|
+
if (typeof input.allowNestedSubagents === "boolean")
|
|
861
|
+
override.allowNestedSubagents = input.allowNestedSubagents;
|
|
862
|
+
else
|
|
863
|
+
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'allowNestedSubagents'; expected a boolean.`);
|
|
864
|
+
}
|
|
865
|
+
const allowedAgents = parseOverrideStringArrayOrFalse(input.allowedAgents, { filePath, name, field: "allowedAgents" });
|
|
866
|
+
if (allowedAgents !== undefined)
|
|
867
|
+
override.allowedAgents = allowedAgents === false ? false : normalizeCapabilityCeilingAllowedAgents(allowedAgents);
|
|
868
|
+
const extensions = parseOverrideStringArrayOrFalse(input.extensions, { filePath, name, field: "extensions" });
|
|
869
|
+
if (extensions !== undefined)
|
|
870
|
+
override.extensions = extensions;
|
|
871
|
+
const subagentOnlyExtensions = parseOverrideStringArrayOrFalse(input.subagentOnlyExtensions, { filePath, name, field: "subagentOnlyExtensions" });
|
|
872
|
+
if (subagentOnlyExtensions !== undefined)
|
|
873
|
+
override.subagentOnlyExtensions = subagentOnlyExtensions;
|
|
874
|
+
const mutationTools = parseOverrideStringArrayOrFalse(input.mutationTools, { filePath, name, field: "mutationTools" });
|
|
875
|
+
if (mutationTools !== undefined)
|
|
876
|
+
override.mutationTools = mutationTools;
|
|
877
|
+
return Object.keys(override).length > 0 ? override : undefined;
|
|
878
|
+
}
|
|
879
|
+
function readSubagentSettings(filePath) {
|
|
880
|
+
if (!filePath)
|
|
881
|
+
return EMPTY_SUBAGENT_SETTINGS;
|
|
882
|
+
const settings = readSettingsFileStrict(filePath);
|
|
883
|
+
const subagents = settings.subagents;
|
|
884
|
+
if (!subagents || typeof subagents !== "object" || Array.isArray(subagents))
|
|
885
|
+
return EMPTY_SUBAGENT_SETTINGS;
|
|
886
|
+
const subagentsObject = subagents;
|
|
887
|
+
let disableBuiltins;
|
|
888
|
+
if ("disableBuiltins" in subagentsObject) {
|
|
889
|
+
if (typeof subagentsObject.disableBuiltins === "boolean") {
|
|
890
|
+
disableBuiltins = subagentsObject.disableBuiltins;
|
|
891
|
+
}
|
|
892
|
+
else {
|
|
893
|
+
throw new Error(`Subagent settings in '${filePath}' have invalid 'disableBuiltins'; expected a boolean.`);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
let disableThinking;
|
|
897
|
+
if ("disableThinking" in subagentsObject) {
|
|
898
|
+
if (typeof subagentsObject.disableThinking === "boolean") {
|
|
899
|
+
disableThinking = subagentsObject.disableThinking;
|
|
900
|
+
}
|
|
901
|
+
else {
|
|
902
|
+
throw new Error(`Subagent settings in '${filePath}' have invalid 'disableThinking'; expected a boolean.`);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
let defaultModel;
|
|
906
|
+
if ("defaultModel" in subagentsObject) {
|
|
907
|
+
if (typeof subagentsObject.defaultModel === "string" && subagentsObject.defaultModel.trim()) {
|
|
908
|
+
defaultModel = subagentsObject.defaultModel.trim();
|
|
909
|
+
}
|
|
910
|
+
else {
|
|
911
|
+
throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultModel'; expected a non-empty string.`);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
let defaultProvider;
|
|
915
|
+
if ("defaultProvider" in subagentsObject) {
|
|
916
|
+
if (typeof subagentsObject.defaultProvider === "string" && subagentsObject.defaultProvider.trim()) {
|
|
917
|
+
defaultProvider = subagentsObject.defaultProvider.trim();
|
|
918
|
+
}
|
|
919
|
+
else {
|
|
920
|
+
throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultProvider'; expected a non-empty string.`);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
let defaultThinking;
|
|
924
|
+
if ("defaultThinking" in subagentsObject) {
|
|
925
|
+
if (typeof subagentsObject.defaultThinking === "string" && subagentsObject.defaultThinking.trim()) {
|
|
926
|
+
defaultThinking = subagentsObject.defaultThinking.trim();
|
|
927
|
+
}
|
|
928
|
+
else {
|
|
929
|
+
throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultThinking'; expected a non-empty string.`);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
let maxThinking;
|
|
933
|
+
if ("maxThinking" in subagentsObject) {
|
|
934
|
+
try {
|
|
935
|
+
maxThinking = parseThinkingLevel(subagentsObject.maxThinking, `'${filePath}' subagents.maxThinking`);
|
|
936
|
+
}
|
|
937
|
+
catch (error) {
|
|
938
|
+
throw new Error(`Subagent settings in '${filePath}' have invalid 'maxThinking'; expected one of off, minimal, low, medium, high, xhigh, or max.`, { cause: error instanceof Error ? error : undefined });
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
let defaultExtensions;
|
|
942
|
+
if ("defaultExtensions" in subagentsObject) {
|
|
943
|
+
if (!Array.isArray(subagentsObject.defaultExtensions)
|
|
944
|
+
|| subagentsObject.defaultExtensions.some((item) => typeof item !== "string" || !item.trim())) {
|
|
945
|
+
throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultExtensions'; expected an array of non-empty strings.`);
|
|
946
|
+
}
|
|
947
|
+
defaultExtensions = subagentsObject.defaultExtensions.map((item) => item.trim());
|
|
948
|
+
}
|
|
949
|
+
let defaultSubagentOnlyExtensions;
|
|
950
|
+
if ("defaultSubagentOnlyExtensions" in subagentsObject) {
|
|
951
|
+
if (!Array.isArray(subagentsObject.defaultSubagentOnlyExtensions)
|
|
952
|
+
|| subagentsObject.defaultSubagentOnlyExtensions.some((item) => typeof item !== "string" || !item.trim())) {
|
|
953
|
+
throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultSubagentOnlyExtensions'; expected an array of non-empty strings.`);
|
|
954
|
+
}
|
|
955
|
+
defaultSubagentOnlyExtensions = subagentsObject.defaultSubagentOnlyExtensions.map((item) => item.trim());
|
|
956
|
+
}
|
|
957
|
+
let agentScanDirs;
|
|
958
|
+
if ("agentScanDirs" in subagentsObject) {
|
|
959
|
+
if (!Array.isArray(subagentsObject.agentScanDirs)
|
|
960
|
+
|| subagentsObject.agentScanDirs.some((item) => typeof item !== "string" || !item.trim())) {
|
|
961
|
+
throw new Error(`Subagent settings in '${filePath}' have invalid 'agentScanDirs'; expected an array of non-empty strings.`);
|
|
962
|
+
}
|
|
963
|
+
agentScanDirs = subagentsObject.agentScanDirs.map((item) => item.trim());
|
|
964
|
+
}
|
|
965
|
+
let agentExcludeDirs;
|
|
966
|
+
if ("agentExcludeDirs" in subagentsObject) {
|
|
967
|
+
if (!Array.isArray(subagentsObject.agentExcludeDirs)
|
|
968
|
+
|| subagentsObject.agentExcludeDirs.some((item) => typeof item !== "string" || !item.trim())) {
|
|
969
|
+
throw new Error(`Subagent settings in '${filePath}' have invalid 'agentExcludeDirs'; expected an array of non-empty strings.`);
|
|
970
|
+
}
|
|
971
|
+
agentExcludeDirs = subagentsObject.agentExcludeDirs.map((item) => item.trim());
|
|
972
|
+
}
|
|
973
|
+
const modelScope = parseModelScopeConfig(subagentsObject.modelScope, { filePath });
|
|
974
|
+
const parsed = {};
|
|
975
|
+
const providerOverrides = {};
|
|
976
|
+
const agentOverrides = subagentsObject.agentOverrides;
|
|
977
|
+
const agentOverridesByProvider = subagentsObject.agentOverridesByProvider;
|
|
978
|
+
const parsedSettings = {
|
|
979
|
+
overrides: parsed,
|
|
980
|
+
providerOverrides,
|
|
981
|
+
...(defaultModel !== undefined ? { defaultModel } : {}),
|
|
982
|
+
...(defaultProvider !== undefined ? { defaultProvider } : {}),
|
|
983
|
+
...(defaultThinking !== undefined ? { defaultThinking } : {}),
|
|
984
|
+
...(maxThinking !== undefined ? { maxThinking } : {}),
|
|
985
|
+
...(defaultExtensions !== undefined ? { defaultExtensions } : {}),
|
|
986
|
+
...(defaultSubagentOnlyExtensions !== undefined ? { defaultSubagentOnlyExtensions } : {}),
|
|
987
|
+
...(agentScanDirs !== undefined ? { agentScanDirs } : {}),
|
|
988
|
+
...(agentExcludeDirs !== undefined ? { agentExcludeDirs } : {}),
|
|
989
|
+
...(disableBuiltins !== undefined ? { disableBuiltins } : {}),
|
|
990
|
+
...(disableThinking !== undefined ? { disableThinking } : {}),
|
|
991
|
+
...(modelScope !== undefined ? { modelScope } : {}),
|
|
992
|
+
};
|
|
993
|
+
if (agentOverrides && typeof agentOverrides === "object" && !Array.isArray(agentOverrides)) {
|
|
994
|
+
for (const [name, value] of Object.entries(agentOverrides)) {
|
|
995
|
+
const override = parseBuiltinOverrideEntry(name, value, filePath);
|
|
996
|
+
if (override)
|
|
997
|
+
parsed[name] = override;
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
if (agentOverridesByProvider !== undefined) {
|
|
1001
|
+
if (!agentOverridesByProvider || typeof agentOverridesByProvider !== "object" || Array.isArray(agentOverridesByProvider)) {
|
|
1002
|
+
throw new Error(`Subagent settings in '${filePath}' have invalid 'agentOverridesByProvider'; expected an object keyed by provider.`);
|
|
1003
|
+
}
|
|
1004
|
+
for (const [provider, value] of Object.entries(agentOverridesByProvider)) {
|
|
1005
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1006
|
+
throw new Error(`Subagent settings in '${filePath}' have invalid 'agentOverridesByProvider.${provider}'; expected an object keyed by agent.`);
|
|
1007
|
+
}
|
|
1008
|
+
const entries = {};
|
|
1009
|
+
for (const [agentName, agentValue] of Object.entries(value)) {
|
|
1010
|
+
const override = parseBuiltinOverrideEntry(`agentOverridesByProvider.${provider}.${agentName}`, agentValue, filePath);
|
|
1011
|
+
if (override)
|
|
1012
|
+
entries[agentName] = override;
|
|
1013
|
+
}
|
|
1014
|
+
providerOverrides[provider] = entries;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
return parsedSettings;
|
|
1018
|
+
}
|
|
1019
|
+
function selectProviderOverrides(settings, provider) {
|
|
1020
|
+
if (!provider)
|
|
1021
|
+
return settings;
|
|
1022
|
+
const selected = settings.providerOverrides[provider];
|
|
1023
|
+
if (!selected)
|
|
1024
|
+
return settings;
|
|
1025
|
+
const overrides = { ...settings.overrides };
|
|
1026
|
+
for (const [name, override] of Object.entries(selected)) {
|
|
1027
|
+
overrides[name] = { ...overrides[name], ...override };
|
|
1028
|
+
}
|
|
1029
|
+
return { ...settings, overrides };
|
|
1030
|
+
}
|
|
1031
|
+
function resolveSubagentDefaultProvider(userSettings, projectSettings, projectSettingsPath) {
|
|
1032
|
+
if (projectSettingsPath && projectSettings.defaultProvider !== undefined)
|
|
1033
|
+
return projectSettings.defaultProvider;
|
|
1034
|
+
return userSettings.defaultProvider;
|
|
1035
|
+
}
|
|
1036
|
+
function resolveSubagentDefaultModel(userSettings, projectSettings, userSettingsPath, projectSettingsPath, defaultProvider) {
|
|
1037
|
+
if (projectSettingsPath && projectSettings.defaultModel !== undefined) {
|
|
1038
|
+
return { type: "subagents.defaultModel", scope: "project", path: projectSettingsPath, model: projectSettings.defaultModel, ...(defaultProvider ? { defaultProvider } : {}) };
|
|
1039
|
+
}
|
|
1040
|
+
return userSettings.defaultModel !== undefined
|
|
1041
|
+
? { type: "subagents.defaultModel", scope: "user", path: userSettingsPath, model: userSettings.defaultModel, ...(defaultProvider ? { defaultProvider } : {}) }
|
|
1042
|
+
: undefined;
|
|
1043
|
+
}
|
|
1044
|
+
function applySubagentDefaultModel(agents, defaultModel, defaultProvider) {
|
|
1045
|
+
if (!defaultModel && !defaultProvider)
|
|
1046
|
+
return agents;
|
|
1047
|
+
return agents.map((agent) => {
|
|
1048
|
+
if (agent.model !== undefined && (agent.modelProvider !== undefined || !defaultProvider))
|
|
1049
|
+
return agent;
|
|
1050
|
+
const next = {
|
|
1051
|
+
...agent,
|
|
1052
|
+
...(agent.model === undefined && defaultModel ? { model: defaultModel.model, modelSource: defaultModel } : {}),
|
|
1053
|
+
...(defaultProvider ? { modelProvider: defaultProvider } : {}),
|
|
1054
|
+
};
|
|
1055
|
+
const frontmatterFields = agentFrontmatterFields.get(agent);
|
|
1056
|
+
if (frontmatterFields)
|
|
1057
|
+
agentFrontmatterFields.set(next, frontmatterFields);
|
|
1058
|
+
return next;
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
function resolveSubagentDefaultThinking(userSettings, projectSettings, projectSettingsPath) {
|
|
1062
|
+
if (projectSettingsPath && projectSettings.defaultThinking !== undefined)
|
|
1063
|
+
return projectSettings.defaultThinking;
|
|
1064
|
+
return userSettings.defaultThinking;
|
|
1065
|
+
}
|
|
1066
|
+
function applySubagentDefaultThinking(agents, defaultThinking) {
|
|
1067
|
+
if (defaultThinking === undefined)
|
|
1068
|
+
return agents;
|
|
1069
|
+
return agents.map((agent) => {
|
|
1070
|
+
if (agent.thinking !== undefined)
|
|
1071
|
+
return agent;
|
|
1072
|
+
const next = { ...agent, thinking: defaultThinking };
|
|
1073
|
+
const frontmatterFields = agentFrontmatterFields.get(agent);
|
|
1074
|
+
if (frontmatterFields)
|
|
1075
|
+
agentFrontmatterFields.set(next, frontmatterFields);
|
|
1076
|
+
return next;
|
|
1077
|
+
});
|
|
1078
|
+
}
|
|
1079
|
+
function resolveSubagentMaxThinking(userSettings, projectSettings, projectSettingsPath) {
|
|
1080
|
+
if (projectSettingsPath && projectSettings.maxThinking !== undefined)
|
|
1081
|
+
return projectSettings.maxThinking;
|
|
1082
|
+
return userSettings.maxThinking;
|
|
1083
|
+
}
|
|
1084
|
+
function applySubagentMaxThinking(agents, maxThinking) {
|
|
1085
|
+
if (maxThinking === undefined)
|
|
1086
|
+
return agents;
|
|
1087
|
+
return agents.map((agent) => agent.maxThinking === maxThinking ? agent : { ...agent, maxThinking });
|
|
1088
|
+
}
|
|
1089
|
+
function resolveSubagentDefaultExtensions(userSettings, projectSettings, projectSettingsPath) {
|
|
1090
|
+
if (projectSettingsPath && projectSettings.defaultExtensions !== undefined)
|
|
1091
|
+
return projectSettings.defaultExtensions;
|
|
1092
|
+
return userSettings.defaultExtensions;
|
|
1093
|
+
}
|
|
1094
|
+
function applySubagentDefaultExtensions(agents, defaultExtensions) {
|
|
1095
|
+
if (defaultExtensions === undefined)
|
|
1096
|
+
return agents;
|
|
1097
|
+
return agents.map((agent) => {
|
|
1098
|
+
if (agent.extensions !== undefined)
|
|
1099
|
+
return agent;
|
|
1100
|
+
const next = { ...agent, extensions: [...defaultExtensions], extensionsFromDefault: true };
|
|
1101
|
+
const frontmatterFields = agentFrontmatterFields.get(agent);
|
|
1102
|
+
if (frontmatterFields)
|
|
1103
|
+
agentFrontmatterFields.set(next, frontmatterFields);
|
|
1104
|
+
return next;
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
function resolveSubagentDefaultSubagentOnlyExtensions(userSettings, projectSettings, projectSettingsPath) {
|
|
1108
|
+
if (projectSettingsPath && projectSettings.defaultSubagentOnlyExtensions !== undefined)
|
|
1109
|
+
return projectSettings.defaultSubagentOnlyExtensions;
|
|
1110
|
+
return userSettings.defaultSubagentOnlyExtensions;
|
|
1111
|
+
}
|
|
1112
|
+
function applySubagentDefaultSubagentOnlyExtensions(agents, defaultSubagentOnlyExtensions) {
|
|
1113
|
+
if (defaultSubagentOnlyExtensions === undefined)
|
|
1114
|
+
return agents;
|
|
1115
|
+
return agents.map((agent) => {
|
|
1116
|
+
if (agent.subagentOnlyExtensions !== undefined)
|
|
1117
|
+
return agent;
|
|
1118
|
+
const next = { ...agent, subagentOnlyExtensions: [...defaultSubagentOnlyExtensions] };
|
|
1119
|
+
const frontmatterFields = agentFrontmatterFields.get(agent);
|
|
1120
|
+
if (frontmatterFields)
|
|
1121
|
+
agentFrontmatterFields.set(next, frontmatterFields);
|
|
1122
|
+
return next;
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
function applySubagentDefaults(agents, defaultModel, defaultProvider, defaultThinking, defaultExtensions, defaultSubagentOnlyExtensions) {
|
|
1126
|
+
return applySubagentDefaultSubagentOnlyExtensions(applySubagentDefaultExtensions(applySubagentDefaultThinking(applySubagentDefaultModel(agents, defaultModel, defaultProvider), defaultThinking), defaultExtensions), defaultSubagentOnlyExtensions);
|
|
1127
|
+
}
|
|
1128
|
+
function applyToolsOverride(target, toolsOverride) {
|
|
1129
|
+
if (toolsOverride === "inherit") {
|
|
1130
|
+
delete target.tools;
|
|
1131
|
+
delete target.mcpDirectTools;
|
|
1132
|
+
return;
|
|
1133
|
+
}
|
|
1134
|
+
const { tools, mcpDirectTools } = splitToolList(toolsOverride === false ? [] : toolsOverride);
|
|
1135
|
+
if (tools === undefined)
|
|
1136
|
+
delete target.tools;
|
|
1137
|
+
else
|
|
1138
|
+
target.tools = tools;
|
|
1139
|
+
if (mcpDirectTools === undefined)
|
|
1140
|
+
delete target.mcpDirectTools;
|
|
1141
|
+
else
|
|
1142
|
+
target.mcpDirectTools = mcpDirectTools;
|
|
1143
|
+
}
|
|
1144
|
+
function applyBuiltinOverride(agent, override, meta) {
|
|
1145
|
+
const overrideInfo = {
|
|
1146
|
+
...meta,
|
|
1147
|
+
base: agent.override?.base ?? cloneOverrideBase(agent),
|
|
1148
|
+
fields: [...new Set([...(agent.override?.fields ?? []), ...Object.keys(override)])].sort(),
|
|
1149
|
+
fieldScopes: Object.fromEntries(Object.entries({ ...(agent.override?.fieldScopes ?? {}) }).map(([field, scopes]) => [field, [...scopes]])),
|
|
1150
|
+
};
|
|
1151
|
+
for (const field of Object.keys(override)) {
|
|
1152
|
+
const scopes = overrideInfo.fieldScopes[field] ?? [];
|
|
1153
|
+
overrideInfo.fieldScopes[field] = [...new Set([...scopes, meta.scope])].sort();
|
|
1154
|
+
}
|
|
1155
|
+
const next = {
|
|
1156
|
+
...agent,
|
|
1157
|
+
override: overrideInfo,
|
|
1158
|
+
};
|
|
1159
|
+
if (override.description !== undefined)
|
|
1160
|
+
next.description = override.description;
|
|
1161
|
+
if (override.machine !== undefined) {
|
|
1162
|
+
if (override.machine === false)
|
|
1163
|
+
delete next.machine;
|
|
1164
|
+
else
|
|
1165
|
+
next.machine = override.machine;
|
|
1166
|
+
}
|
|
1167
|
+
if (override.output !== undefined) {
|
|
1168
|
+
if (override.output === false)
|
|
1169
|
+
delete next.output;
|
|
1170
|
+
else
|
|
1171
|
+
next.output = override.output;
|
|
1172
|
+
}
|
|
1173
|
+
if (override.outputMode !== undefined)
|
|
1174
|
+
next.outputMode = override.outputMode;
|
|
1175
|
+
if (override.defaultReads !== undefined) {
|
|
1176
|
+
if (override.defaultReads === false)
|
|
1177
|
+
delete next.defaultReads;
|
|
1178
|
+
else
|
|
1179
|
+
next.defaultReads = [...override.defaultReads];
|
|
1180
|
+
}
|
|
1181
|
+
if (override.model !== undefined) {
|
|
1182
|
+
if (override.model === false)
|
|
1183
|
+
delete next.model;
|
|
1184
|
+
else
|
|
1185
|
+
next.model = override.model;
|
|
1186
|
+
delete next.modelSource;
|
|
1187
|
+
}
|
|
1188
|
+
if (override.defaultProvider !== undefined) {
|
|
1189
|
+
if (override.defaultProvider === false)
|
|
1190
|
+
delete next.modelProvider;
|
|
1191
|
+
else
|
|
1192
|
+
next.modelProvider = override.defaultProvider;
|
|
1193
|
+
}
|
|
1194
|
+
if (override.fast !== undefined)
|
|
1195
|
+
next.fast = override.fast;
|
|
1196
|
+
if (override.thinking !== undefined) {
|
|
1197
|
+
if (override.thinking === false)
|
|
1198
|
+
delete next.thinking;
|
|
1199
|
+
else
|
|
1200
|
+
next.thinking = override.thinking;
|
|
1201
|
+
}
|
|
1202
|
+
if (override.systemPromptMode !== undefined)
|
|
1203
|
+
next.systemPromptMode = override.systemPromptMode;
|
|
1204
|
+
if (override.inheritProjectContext !== undefined)
|
|
1205
|
+
next.inheritProjectContext = override.inheritProjectContext;
|
|
1206
|
+
if (override.inheritGlobalContext !== undefined)
|
|
1207
|
+
next.inheritGlobalContext = override.inheritGlobalContext;
|
|
1208
|
+
if (override.inheritSkills !== undefined)
|
|
1209
|
+
next.inheritSkills = override.inheritSkills;
|
|
1210
|
+
if (override.defaultContext !== undefined) {
|
|
1211
|
+
if (override.defaultContext === false)
|
|
1212
|
+
delete next.defaultContext;
|
|
1213
|
+
else
|
|
1214
|
+
next.defaultContext = override.defaultContext;
|
|
1215
|
+
}
|
|
1216
|
+
if (override.acceptanceRole !== undefined) {
|
|
1217
|
+
if (override.acceptanceRole === false)
|
|
1218
|
+
delete next.acceptanceRole;
|
|
1219
|
+
else
|
|
1220
|
+
next.acceptanceRole = override.acceptanceRole;
|
|
1221
|
+
}
|
|
1222
|
+
if (override.disabled !== undefined)
|
|
1223
|
+
next.disabled = override.disabled;
|
|
1224
|
+
if (override.systemPrompt !== undefined)
|
|
1225
|
+
next.systemPrompt = override.systemPrompt;
|
|
1226
|
+
if (override.skills !== undefined) {
|
|
1227
|
+
if (override.skills === false)
|
|
1228
|
+
delete next.skills;
|
|
1229
|
+
else
|
|
1230
|
+
next.skills = [...override.skills];
|
|
1231
|
+
}
|
|
1232
|
+
if (override.tools !== undefined)
|
|
1233
|
+
applyToolsOverride(next, override.tools);
|
|
1234
|
+
if (override.excludeTools !== undefined) {
|
|
1235
|
+
if (override.excludeTools === false)
|
|
1236
|
+
delete next.excludeTools;
|
|
1237
|
+
else
|
|
1238
|
+
next.excludeTools = [...override.excludeTools];
|
|
1239
|
+
}
|
|
1240
|
+
if (override.allowNestedSubagents !== undefined)
|
|
1241
|
+
next.allowNestedSubagents = override.allowNestedSubagents;
|
|
1242
|
+
if (override.allowedAgents !== undefined) {
|
|
1243
|
+
if (override.allowedAgents === false)
|
|
1244
|
+
delete next.allowedAgents;
|
|
1245
|
+
else
|
|
1246
|
+
next.allowedAgents = [...override.allowedAgents];
|
|
1247
|
+
}
|
|
1248
|
+
if (override.extensions !== undefined) {
|
|
1249
|
+
if (override.extensions === false)
|
|
1250
|
+
delete next.extensions;
|
|
1251
|
+
else
|
|
1252
|
+
next.extensions = [...override.extensions];
|
|
1253
|
+
}
|
|
1254
|
+
if (override.subagentOnlyExtensions !== undefined) {
|
|
1255
|
+
if (override.subagentOnlyExtensions === false)
|
|
1256
|
+
delete next.subagentOnlyExtensions;
|
|
1257
|
+
else
|
|
1258
|
+
next.subagentOnlyExtensions = [...override.subagentOnlyExtensions];
|
|
1259
|
+
}
|
|
1260
|
+
if (override.mutationTools !== undefined) {
|
|
1261
|
+
if (override.mutationTools === false)
|
|
1262
|
+
delete next.mutationTools;
|
|
1263
|
+
else
|
|
1264
|
+
next.mutationTools = [...override.mutationTools];
|
|
1265
|
+
}
|
|
1266
|
+
if (override.completionGuard !== undefined)
|
|
1267
|
+
next.completionGuard = override.completionGuard;
|
|
1268
|
+
if (override.toolBudget !== undefined) {
|
|
1269
|
+
if (override.toolBudget === false)
|
|
1270
|
+
delete next.toolBudget;
|
|
1271
|
+
else
|
|
1272
|
+
next.toolBudget = override.toolBudget;
|
|
1273
|
+
}
|
|
1274
|
+
return next;
|
|
1275
|
+
}
|
|
1276
|
+
function clearBuiltinThinking(agent, meta) {
|
|
1277
|
+
if (agent.thinking === undefined)
|
|
1278
|
+
return agent;
|
|
1279
|
+
const { thinking: _thinking, ...next } = agent;
|
|
1280
|
+
return { ...next, override: agent.override ?? { ...meta, base: cloneOverrideBase(agent) } };
|
|
1281
|
+
}
|
|
1282
|
+
function applyBuiltinOverrides(builtinAgents, userSettings, projectSettings, userSettingsPath, projectSettingsPath) {
|
|
1283
|
+
const projectBulkDisabled = projectSettings.disableBuiltins === true && projectSettingsPath !== null;
|
|
1284
|
+
const userBulkDisabled = projectSettings.disableBuiltins === undefined && userSettings.disableBuiltins === true;
|
|
1285
|
+
const projectThinkingConfigured = projectSettings.disableThinking !== undefined && projectSettingsPath !== null;
|
|
1286
|
+
const disableThinking = projectThinkingConfigured ? projectSettings.disableThinking === true : userSettings.disableThinking === true;
|
|
1287
|
+
const disableThinkingMeta = projectThinkingConfigured
|
|
1288
|
+
? { scope: "project", path: projectSettingsPath }
|
|
1289
|
+
: { scope: "user", path: userSettingsPath };
|
|
1290
|
+
const applyGlobalThinking = (agent, hasExplicitThinkingOverride) => {
|
|
1291
|
+
if (!disableThinking || hasExplicitThinkingOverride)
|
|
1292
|
+
return agent;
|
|
1293
|
+
return clearBuiltinThinking(agent, disableThinkingMeta);
|
|
1294
|
+
};
|
|
1295
|
+
return builtinAgents.map((agent) => {
|
|
1296
|
+
const projectOverride = projectSettings.overrides[agent.name];
|
|
1297
|
+
if (projectOverride && projectSettingsPath) {
|
|
1298
|
+
return applyGlobalThinking(applyBuiltinOverride(agent, projectOverride, { scope: "project", path: projectSettingsPath }), projectOverride.thinking !== undefined);
|
|
1299
|
+
}
|
|
1300
|
+
if (projectBulkDisabled && projectSettingsPath) {
|
|
1301
|
+
return applyGlobalThinking(applyBuiltinOverride(agent, { disabled: true }, { scope: "project", path: projectSettingsPath }), false);
|
|
1302
|
+
}
|
|
1303
|
+
const userOverride = userSettings.overrides[agent.name];
|
|
1304
|
+
if (userOverride) {
|
|
1305
|
+
return applyGlobalThinking(applyBuiltinOverride(agent, userOverride, { scope: "user", path: userSettingsPath }), !projectThinkingConfigured && userOverride.thinking !== undefined);
|
|
1306
|
+
}
|
|
1307
|
+
if (userBulkDisabled) {
|
|
1308
|
+
return applyGlobalThinking(applyBuiltinOverride(agent, { disabled: true }, { scope: "user", path: userSettingsPath }), false);
|
|
1309
|
+
}
|
|
1310
|
+
return applyGlobalThinking(agent, false);
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
function applyCustomAgentOverride(agent, override, meta) {
|
|
1314
|
+
const next = applyBuiltinOverride(agent, override, meta);
|
|
1315
|
+
const frontmatterFields = agentFrontmatterFields.get(agent);
|
|
1316
|
+
if (frontmatterFields)
|
|
1317
|
+
agentFrontmatterFields.set(next, frontmatterFields);
|
|
1318
|
+
return next;
|
|
1319
|
+
}
|
|
1320
|
+
function applyCustomAgentOverrides(agents, userSettings, projectSettings, userSettingsPath, projectSettingsPath) {
|
|
1321
|
+
// Apply user then project so project fields win without dropping user-only fields.
|
|
1322
|
+
return agents.map((agent) => {
|
|
1323
|
+
const userOverride = userSettings.overrides[agent.name];
|
|
1324
|
+
const withUserOverride = userOverride
|
|
1325
|
+
? applyCustomAgentOverride(agent, userOverride, { scope: "user", path: userSettingsPath })
|
|
1326
|
+
: agent;
|
|
1327
|
+
const projectOverride = projectSettings.overrides[agent.name];
|
|
1328
|
+
if (projectOverride && projectSettingsPath) {
|
|
1329
|
+
return applyCustomAgentOverride(withUserOverride, projectOverride, { scope: "project", path: projectSettingsPath });
|
|
1330
|
+
}
|
|
1331
|
+
return withUserOverride;
|
|
1332
|
+
});
|
|
1333
|
+
}
|
|
1334
|
+
export function buildBuiltinOverrideConfig(base, draft) {
|
|
1335
|
+
const override = {};
|
|
1336
|
+
if (draft.machine !== base.machine)
|
|
1337
|
+
override.machine = draft.machine ?? false;
|
|
1338
|
+
if (draft.description !== undefined) {
|
|
1339
|
+
const description = draft.description.trim();
|
|
1340
|
+
if (description && description !== base.description)
|
|
1341
|
+
override.description = description;
|
|
1342
|
+
}
|
|
1343
|
+
if (draft.output !== base.output)
|
|
1344
|
+
override.output = draft.output ?? false;
|
|
1345
|
+
if (draft.outputMode !== undefined && draft.outputMode !== base.outputMode)
|
|
1346
|
+
override.outputMode = draft.outputMode;
|
|
1347
|
+
if (!arraysEqual(draft.defaultReads, base.defaultReads))
|
|
1348
|
+
override.defaultReads = draft.defaultReads ? [...draft.defaultReads] : false;
|
|
1349
|
+
if (draft.model !== base.model)
|
|
1350
|
+
override.model = draft.model ?? false;
|
|
1351
|
+
if (draft.modelProvider !== base.modelProvider)
|
|
1352
|
+
override.defaultProvider = draft.modelProvider ?? false;
|
|
1353
|
+
if (draft.fast !== base.fast)
|
|
1354
|
+
override.fast = draft.fast === true;
|
|
1355
|
+
if (draft.thinking !== base.thinking)
|
|
1356
|
+
override.thinking = draft.thinking ?? false;
|
|
1357
|
+
if (draft.systemPromptMode !== base.systemPromptMode)
|
|
1358
|
+
override.systemPromptMode = draft.systemPromptMode;
|
|
1359
|
+
if (draft.inheritProjectContext !== base.inheritProjectContext)
|
|
1360
|
+
override.inheritProjectContext = draft.inheritProjectContext;
|
|
1361
|
+
if (draft.inheritGlobalContext !== base.inheritGlobalContext)
|
|
1362
|
+
override.inheritGlobalContext = draft.inheritGlobalContext;
|
|
1363
|
+
if (draft.inheritSkills !== base.inheritSkills)
|
|
1364
|
+
override.inheritSkills = draft.inheritSkills;
|
|
1365
|
+
if (draft.defaultContext !== base.defaultContext)
|
|
1366
|
+
override.defaultContext = draft.defaultContext ?? false;
|
|
1367
|
+
if (draft.acceptanceRole !== base.acceptanceRole)
|
|
1368
|
+
override.acceptanceRole = draft.acceptanceRole ?? false;
|
|
1369
|
+
if (draft.disabled !== base.disabled)
|
|
1370
|
+
override.disabled = draft.disabled ?? false;
|
|
1371
|
+
if (draft.systemPrompt !== base.systemPrompt)
|
|
1372
|
+
override.systemPrompt = draft.systemPrompt;
|
|
1373
|
+
if (!arraysEqual(draft.skills, base.skills))
|
|
1374
|
+
override.skills = draft.skills ? [...draft.skills] : false;
|
|
1375
|
+
const baseTools = joinToolList(base);
|
|
1376
|
+
const draftTools = joinToolList(draft);
|
|
1377
|
+
if (!arraysEqual(draftTools, baseTools))
|
|
1378
|
+
override.tools = draftTools ? [...draftTools] : false;
|
|
1379
|
+
if (!arraysEqual(draft.excludeTools, base.excludeTools))
|
|
1380
|
+
override.excludeTools = draft.excludeTools ? [...draft.excludeTools] : false;
|
|
1381
|
+
if (draft.allowNestedSubagents !== base.allowNestedSubagents)
|
|
1382
|
+
override.allowNestedSubagents = draft.allowNestedSubagents === true;
|
|
1383
|
+
if (!arraysEqual(draft.extensions, base.extensions))
|
|
1384
|
+
override.extensions = draft.extensions ? [...draft.extensions] : false;
|
|
1385
|
+
if (!arraysEqual(draft.subagentOnlyExtensions, base.subagentOnlyExtensions)) {
|
|
1386
|
+
override.subagentOnlyExtensions = draft.subagentOnlyExtensions ? [...draft.subagentOnlyExtensions] : false;
|
|
1387
|
+
}
|
|
1388
|
+
if (!arraysEqual(draft.mutationTools, base.mutationTools))
|
|
1389
|
+
override.mutationTools = draft.mutationTools ? [...draft.mutationTools] : false;
|
|
1390
|
+
if ((draft.completionGuard !== false) !== (base.completionGuard !== false)) {
|
|
1391
|
+
override.completionGuard = draft.completionGuard !== false;
|
|
1392
|
+
}
|
|
1393
|
+
if (JSON.stringify(draft.toolBudget) !== JSON.stringify(base.toolBudget))
|
|
1394
|
+
override.toolBudget = draft.toolBudget ?? false;
|
|
1395
|
+
return Object.keys(override).length > 0 ? override : undefined;
|
|
1396
|
+
}
|
|
1397
|
+
export function saveBuiltinAgentOverride(cwd, name, scope, override) {
|
|
1398
|
+
const filePath = scope === "project" ? getProjectAgentSettingsPath(cwd) : getUserAgentSettingsPath();
|
|
1399
|
+
if (!filePath)
|
|
1400
|
+
throw new Error("Project override is not available here. No project config root was found.");
|
|
1401
|
+
const settings = readSettingsFileStrict(filePath);
|
|
1402
|
+
const subagents = settings.subagents && typeof settings.subagents === "object" && !Array.isArray(settings.subagents)
|
|
1403
|
+
? { ...settings.subagents }
|
|
1404
|
+
: {};
|
|
1405
|
+
const agentOverrides = subagents.agentOverrides && typeof subagents.agentOverrides === "object" && !Array.isArray(subagents.agentOverrides)
|
|
1406
|
+
? { ...subagents.agentOverrides }
|
|
1407
|
+
: {};
|
|
1408
|
+
agentOverrides[name] = cloneOverrideValue(override);
|
|
1409
|
+
subagents.agentOverrides = agentOverrides;
|
|
1410
|
+
settings.subagents = subagents;
|
|
1411
|
+
writeSettingsFile(filePath, settings);
|
|
1412
|
+
return filePath;
|
|
1413
|
+
}
|
|
1414
|
+
export function removeBuiltinAgentOverride(cwd, name, scope, options) {
|
|
1415
|
+
const filePath = scope === "project" ? getProjectAgentSettingsPath(cwd) : getUserAgentSettingsPath();
|
|
1416
|
+
if (!filePath)
|
|
1417
|
+
throw new Error("Project override is not available here. No project config root was found.");
|
|
1418
|
+
if (!fs.existsSync(filePath))
|
|
1419
|
+
return { path: filePath, removed: false, machinePreserved: false };
|
|
1420
|
+
const settings = readSettingsFileStrict(filePath);
|
|
1421
|
+
const subagents = settings.subagents;
|
|
1422
|
+
if (!subagents || typeof subagents !== "object" || Array.isArray(subagents))
|
|
1423
|
+
return { path: filePath, removed: false, machinePreserved: false };
|
|
1424
|
+
const nextSubagents = { ...subagents };
|
|
1425
|
+
const agentOverrides = nextSubagents.agentOverrides;
|
|
1426
|
+
if (!agentOverrides || typeof agentOverrides !== "object" || Array.isArray(agentOverrides))
|
|
1427
|
+
return { path: filePath, removed: false, machinePreserved: false };
|
|
1428
|
+
const nextOverrides = { ...agentOverrides };
|
|
1429
|
+
const current = nextOverrides[name];
|
|
1430
|
+
if (!Object.prototype.hasOwnProperty.call(nextOverrides, name))
|
|
1431
|
+
return { path: filePath, removed: false, machinePreserved: false };
|
|
1432
|
+
const configuredMachine = current && typeof current === "object" && !Array.isArray(current) ? current.machine : undefined;
|
|
1433
|
+
const machine = configuredMachine === false || (typeof configuredMachine === "string" && configuredMachine.trim()) ? configuredMachine : undefined;
|
|
1434
|
+
if (options?.preserveMachine && machine !== undefined)
|
|
1435
|
+
nextOverrides[name] = { machine };
|
|
1436
|
+
else
|
|
1437
|
+
delete nextOverrides[name];
|
|
1438
|
+
if (Object.keys(nextOverrides).length > 0)
|
|
1439
|
+
nextSubagents.agentOverrides = nextOverrides;
|
|
1440
|
+
else
|
|
1441
|
+
delete nextSubagents.agentOverrides;
|
|
1442
|
+
if (Object.keys(nextSubagents).length > 0)
|
|
1443
|
+
settings.subagents = nextSubagents;
|
|
1444
|
+
else
|
|
1445
|
+
delete settings.subagents;
|
|
1446
|
+
writeSettingsFile(filePath, settings);
|
|
1447
|
+
return { path: filePath, removed: true, machinePreserved: options?.preserveMachine === true && machine !== undefined };
|
|
1448
|
+
}
|
|
1449
|
+
export function mergeBuiltinAgentOverride(cwd, name, scope, fields) {
|
|
1450
|
+
const filePath = scope === "project" ? getProjectAgentSettingsPath(cwd) : getUserAgentSettingsPath();
|
|
1451
|
+
if (!filePath)
|
|
1452
|
+
throw new Error("Project override is not available here. No project config root was found.");
|
|
1453
|
+
const settings = readSettingsFileStrict(filePath);
|
|
1454
|
+
const subagents = settings.subagents && typeof settings.subagents === "object" && !Array.isArray(settings.subagents)
|
|
1455
|
+
? { ...settings.subagents }
|
|
1456
|
+
: {};
|
|
1457
|
+
const agentOverrides = subagents.agentOverrides && typeof subagents.agentOverrides === "object" && !Array.isArray(subagents.agentOverrides)
|
|
1458
|
+
? { ...subagents.agentOverrides }
|
|
1459
|
+
: {};
|
|
1460
|
+
const existing = agentOverrides[name];
|
|
1461
|
+
const base = existing && typeof existing === "object" && !Array.isArray(existing)
|
|
1462
|
+
? existing
|
|
1463
|
+
: {};
|
|
1464
|
+
agentOverrides[name] = { ...base, ...cloneOverrideValue(fields) };
|
|
1465
|
+
subagents.agentOverrides = agentOverrides;
|
|
1466
|
+
settings.subagents = subagents;
|
|
1467
|
+
writeSettingsFile(filePath, settings);
|
|
1468
|
+
return filePath;
|
|
1469
|
+
}
|
|
1470
|
+
export function removeBuiltinAgentOverrideFields(cwd, name, scope, fields) {
|
|
1471
|
+
const filePath = scope === "project" ? getProjectAgentSettingsPath(cwd) : getUserAgentSettingsPath();
|
|
1472
|
+
if (!filePath)
|
|
1473
|
+
throw new Error("Project override is not available here. No project config root was found.");
|
|
1474
|
+
if (!fs.existsSync(filePath))
|
|
1475
|
+
return { path: filePath, removed: false };
|
|
1476
|
+
const settings = readSettingsFileStrict(filePath);
|
|
1477
|
+
const subagents = settings.subagents;
|
|
1478
|
+
if (!subagents || typeof subagents !== "object" || Array.isArray(subagents))
|
|
1479
|
+
return { path: filePath, removed: false };
|
|
1480
|
+
const agentOverrides = subagents.agentOverrides;
|
|
1481
|
+
if (!agentOverrides || typeof agentOverrides !== "object" || Array.isArray(agentOverrides))
|
|
1482
|
+
return { path: filePath, removed: false };
|
|
1483
|
+
const entry = agentOverrides[name];
|
|
1484
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
1485
|
+
return { path: filePath, removed: false };
|
|
1486
|
+
const nextEntry = { ...entry };
|
|
1487
|
+
let removed = false;
|
|
1488
|
+
for (const field of fields) {
|
|
1489
|
+
if (Object.prototype.hasOwnProperty.call(nextEntry, field)) {
|
|
1490
|
+
delete nextEntry[field];
|
|
1491
|
+
removed = true;
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
if (!removed)
|
|
1495
|
+
return { path: filePath, removed: false };
|
|
1496
|
+
const nextSubagents = { ...subagents };
|
|
1497
|
+
if (Object.keys(nextEntry).length > 0) {
|
|
1498
|
+
nextSubagents.agentOverrides[name] = nextEntry;
|
|
1499
|
+
}
|
|
1500
|
+
else {
|
|
1501
|
+
const nextOverrides = { ...agentOverrides };
|
|
1502
|
+
delete nextOverrides[name];
|
|
1503
|
+
if (Object.keys(nextOverrides).length > 0)
|
|
1504
|
+
nextSubagents.agentOverrides = nextOverrides;
|
|
1505
|
+
else
|
|
1506
|
+
delete nextSubagents.agentOverrides;
|
|
1507
|
+
}
|
|
1508
|
+
if (Object.keys(nextSubagents).length > 0)
|
|
1509
|
+
settings.subagents = nextSubagents;
|
|
1510
|
+
else
|
|
1511
|
+
delete settings.subagents;
|
|
1512
|
+
writeSettingsFile(filePath, settings);
|
|
1513
|
+
return { path: filePath, removed: true };
|
|
1514
|
+
}
|
|
1515
|
+
const DISCOVERY_PRUNED_DIR_NAMES = new Set([".git", "node_modules", ".pi", "sync-backups"]);
|
|
1516
|
+
function isDiscoveryNestedProjectRoot(dir) {
|
|
1517
|
+
return isDirectory(getProjectConfigDir(dir)) || isDirectory(path.join(dir, ".agents"));
|
|
1518
|
+
}
|
|
1519
|
+
function shouldPruneDiscoveryDir(rootDir, dir, dirName) {
|
|
1520
|
+
if (DISCOVERY_PRUNED_DIR_NAMES.has(dirName))
|
|
1521
|
+
return true;
|
|
1522
|
+
if (fs.existsSync(path.join(dir, ".git")))
|
|
1523
|
+
return true;
|
|
1524
|
+
return path.resolve(dir) !== path.resolve(rootDir) && isDiscoveryNestedProjectRoot(dir);
|
|
1525
|
+
}
|
|
1526
|
+
function listFilesRecursive(dir, predicate, rootDir = dir, visitedDirectories = new Set(), inspectedDirectories = new Set()) {
|
|
1527
|
+
const files = [];
|
|
1528
|
+
if (!fs.existsSync(dir))
|
|
1529
|
+
return files;
|
|
1530
|
+
inspectedDirectories.add(path.resolve(dir));
|
|
1531
|
+
let realDir;
|
|
1532
|
+
try {
|
|
1533
|
+
realDir = fs.realpathSync(dir);
|
|
1534
|
+
}
|
|
1535
|
+
catch {
|
|
1536
|
+
return files;
|
|
1537
|
+
}
|
|
1538
|
+
if (visitedDirectories.has(realDir))
|
|
1539
|
+
return files;
|
|
1540
|
+
visitedDirectories.add(realDir);
|
|
1541
|
+
let entries;
|
|
1542
|
+
try {
|
|
1543
|
+
entries = fs.readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
1544
|
+
}
|
|
1545
|
+
catch {
|
|
1546
|
+
return files;
|
|
1547
|
+
}
|
|
1548
|
+
for (const entry of entries) {
|
|
1549
|
+
const filePath = path.join(dir, entry.name);
|
|
1550
|
+
let isDirectory = entry.isDirectory();
|
|
1551
|
+
if (entry.isSymbolicLink()) {
|
|
1552
|
+
try {
|
|
1553
|
+
isDirectory = fs.statSync(filePath).isDirectory();
|
|
1554
|
+
}
|
|
1555
|
+
catch {
|
|
1556
|
+
isDirectory = false;
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
if (isDirectory) {
|
|
1560
|
+
if (!shouldPruneDiscoveryDir(rootDir, filePath, entry.name)) {
|
|
1561
|
+
files.push(...listFilesRecursive(filePath, predicate, rootDir, visitedDirectories, inspectedDirectories));
|
|
1562
|
+
}
|
|
1563
|
+
continue;
|
|
1564
|
+
}
|
|
1565
|
+
if (!entry.isFile() && !entry.isSymbolicLink())
|
|
1566
|
+
continue;
|
|
1567
|
+
if (!predicate(entry.name))
|
|
1568
|
+
continue;
|
|
1569
|
+
files.push(filePath);
|
|
1570
|
+
}
|
|
1571
|
+
return files;
|
|
1572
|
+
}
|
|
1573
|
+
const agentDefinitionInspectionDirectories = new WeakMap();
|
|
1574
|
+
function rememberAgentDefinitionInspection(inspection, directories) {
|
|
1575
|
+
agentDefinitionInspectionDirectories.set(inspection, [...new Set([...directories].map((directory) => path.resolve(directory)))]);
|
|
1576
|
+
return inspection;
|
|
1577
|
+
}
|
|
1578
|
+
function inspectedAgentDefinitionDirectories(inspection, root) {
|
|
1579
|
+
return agentDefinitionInspectionDirectories.get(inspection) ?? [path.resolve(root)];
|
|
1580
|
+
}
|
|
1581
|
+
const DEFAULT_AGENT_DEFINITION_INSPECTION_FS = {
|
|
1582
|
+
existsSync: fs.existsSync,
|
|
1583
|
+
realpathSync: fs.realpathSync,
|
|
1584
|
+
statSync: fs.statSync,
|
|
1585
|
+
readdirSync: (dir) => fs.readdirSync(dir, { withFileTypes: true }),
|
|
1586
|
+
};
|
|
1587
|
+
/**
|
|
1588
|
+
* Inspect one agent-definition directory while retaining traversal failure
|
|
1589
|
+
* state. A nested unreadable directory makes the whole inspection unavailable,
|
|
1590
|
+
* preventing a partial traversal from being reported as empty or complete.
|
|
1591
|
+
*/
|
|
1592
|
+
export function inspectAgentDefinitionDirectory(dir, operations = DEFAULT_AGENT_DEFINITION_INSPECTION_FS, isExcluded = () => false) {
|
|
1593
|
+
const root = path.resolve(dir);
|
|
1594
|
+
if (isExcluded(root))
|
|
1595
|
+
return rememberAgentDefinitionInspection({ files: [], state: "empty" }, []);
|
|
1596
|
+
try {
|
|
1597
|
+
if (!operations.existsSync(root))
|
|
1598
|
+
return rememberAgentDefinitionInspection({ files: [], state: "absent" }, [root]);
|
|
1599
|
+
if (!operations.statSync(root).isDirectory())
|
|
1600
|
+
return rememberAgentDefinitionInspection({ files: [], state: "not-directory" }, [root]);
|
|
1601
|
+
}
|
|
1602
|
+
catch {
|
|
1603
|
+
return rememberAgentDefinitionInspection({ files: [], state: "unreadable" }, [root]);
|
|
1604
|
+
}
|
|
1605
|
+
const files = [];
|
|
1606
|
+
let unreadable = false;
|
|
1607
|
+
const visitedDirectories = new Set();
|
|
1608
|
+
const inspectedDirectories = new Set();
|
|
1609
|
+
const visit = (current) => {
|
|
1610
|
+
inspectedDirectories.add(path.resolve(current));
|
|
1611
|
+
let realDir;
|
|
1612
|
+
try {
|
|
1613
|
+
realDir = operations.realpathSync?.(current) ?? path.resolve(current);
|
|
1614
|
+
}
|
|
1615
|
+
catch {
|
|
1616
|
+
unreadable = true;
|
|
1617
|
+
return;
|
|
1618
|
+
}
|
|
1619
|
+
if (visitedDirectories.has(realDir))
|
|
1620
|
+
return;
|
|
1621
|
+
visitedDirectories.add(realDir);
|
|
1622
|
+
let entries;
|
|
1623
|
+
try {
|
|
1624
|
+
entries = operations.readdirSync(current).sort((a, b) => a.name.localeCompare(b.name));
|
|
1625
|
+
}
|
|
1626
|
+
catch {
|
|
1627
|
+
unreadable = true;
|
|
1628
|
+
return;
|
|
1629
|
+
}
|
|
1630
|
+
for (const entry of entries) {
|
|
1631
|
+
const filePath = path.join(current, entry.name);
|
|
1632
|
+
if (isExcluded(filePath))
|
|
1633
|
+
continue;
|
|
1634
|
+
let isDirectory = entry.isDirectory();
|
|
1635
|
+
if (entry.isSymbolicLink()) {
|
|
1636
|
+
try {
|
|
1637
|
+
isDirectory = operations.statSync(filePath).isDirectory();
|
|
1638
|
+
}
|
|
1639
|
+
catch {
|
|
1640
|
+
isDirectory = false;
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
if (isDirectory) {
|
|
1644
|
+
if (!shouldPruneDiscoveryDir(root, filePath, entry.name))
|
|
1645
|
+
visit(filePath);
|
|
1646
|
+
continue;
|
|
1647
|
+
}
|
|
1648
|
+
if ((entry.isFile() || entry.isSymbolicLink()) && entry.name.endsWith(".md") && !entry.name.endsWith(".chain.md") && !isLegacyAgentSkillPath(root, filePath))
|
|
1649
|
+
files.push(filePath);
|
|
1650
|
+
}
|
|
1651
|
+
};
|
|
1652
|
+
visit(root);
|
|
1653
|
+
return rememberAgentDefinitionInspection({ files, state: unreadable ? "unreadable" : files.length ? "candidates" : "empty" }, inspectedDirectories);
|
|
1654
|
+
}
|
|
1655
|
+
function isLegacyAgentSkillPath(rootDir, filePath) {
|
|
1656
|
+
const relative = path.relative(rootDir, filePath);
|
|
1657
|
+
const parts = relative.split(path.sep).map((part) => part.toLowerCase());
|
|
1658
|
+
if (path.basename(rootDir).toLowerCase() === ".agents") {
|
|
1659
|
+
parts.unshift(".agents");
|
|
1660
|
+
}
|
|
1661
|
+
return parts.some((part, index) => part === ".agents" && parts[index + 1] === "skills");
|
|
1662
|
+
}
|
|
1663
|
+
function isJsonSerializable(value) {
|
|
1664
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
1665
|
+
return true;
|
|
1666
|
+
if (typeof value === "number")
|
|
1667
|
+
return Number.isFinite(value);
|
|
1668
|
+
if (Array.isArray(value))
|
|
1669
|
+
return value.every(isJsonSerializable);
|
|
1670
|
+
if (value && typeof value === "object")
|
|
1671
|
+
return Object.values(value).every(isJsonSerializable);
|
|
1672
|
+
return false;
|
|
1673
|
+
}
|
|
1674
|
+
function parseAgentRunnerFrontmatter(raw, agentName) {
|
|
1675
|
+
if (raw === undefined || !raw.trim())
|
|
1676
|
+
return undefined;
|
|
1677
|
+
let parsed;
|
|
1678
|
+
try {
|
|
1679
|
+
parsed = parseYaml(raw);
|
|
1680
|
+
}
|
|
1681
|
+
catch (error) {
|
|
1682
|
+
throw new Error(`Agent '${agentName}' has invalid runner frontmatter: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
1683
|
+
}
|
|
1684
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
1685
|
+
throw new Error(`Agent '${agentName}' has invalid runner frontmatter; expected an object.`);
|
|
1686
|
+
}
|
|
1687
|
+
const runner = parsed;
|
|
1688
|
+
if (runner.type === "pi") {
|
|
1689
|
+
if (Object.keys(runner).some((key) => key !== "type"))
|
|
1690
|
+
throw new Error(`Agent '${agentName}' has invalid Pi runner frontmatter; only 'type' is supported.`);
|
|
1691
|
+
return { type: "pi" };
|
|
1692
|
+
}
|
|
1693
|
+
if (runner.type === "external-job") {
|
|
1694
|
+
if (typeof runner.provider !== "string" || !runner.provider.trim() || runner.provider.trim() !== runner.provider) {
|
|
1695
|
+
throw new Error(`Agent '${agentName}' external-job runner requires a non-empty trimmed provider string.`);
|
|
1696
|
+
}
|
|
1697
|
+
if (runner.options !== undefined && (!runner.options || typeof runner.options !== "object" || Array.isArray(runner.options) || !isJsonSerializable(runner.options))) {
|
|
1698
|
+
throw new Error(`Agent '${agentName}' external-job runner options must be a JSON-serializable object.`);
|
|
1699
|
+
}
|
|
1700
|
+
const supported = new Set(["type", "provider", "options"]);
|
|
1701
|
+
const unknown = Object.keys(runner).filter((key) => !supported.has(key));
|
|
1702
|
+
if (unknown.length > 0)
|
|
1703
|
+
throw new Error(`Agent '${agentName}' external-job runner has unsupported fields: ${unknown.join(", ")}.`);
|
|
1704
|
+
return {
|
|
1705
|
+
type: "external-job",
|
|
1706
|
+
provider: runner.provider,
|
|
1707
|
+
...(runner.options ? { options: runner.options } : {}),
|
|
1708
|
+
};
|
|
1709
|
+
}
|
|
1710
|
+
if (runner.type !== "external-cli") {
|
|
1711
|
+
throw new Error(`Agent '${agentName}' has invalid runner.type; expected 'pi', 'external-cli', or 'external-job'.`);
|
|
1712
|
+
}
|
|
1713
|
+
if (typeof runner.command !== "string" || !runner.command.trim()) {
|
|
1714
|
+
throw new Error(`Agent '${agentName}' external-cli runner requires a non-empty command string.`);
|
|
1715
|
+
}
|
|
1716
|
+
if (runner.args !== undefined && (!Array.isArray(runner.args) || runner.args.some((arg) => typeof arg !== "string"))) {
|
|
1717
|
+
throw new Error(`Agent '${agentName}' external-cli runner args must be an array of strings.`);
|
|
1718
|
+
}
|
|
1719
|
+
if (runner.adapter !== undefined && !isCodeOwnedExternalCliAdapterId(runner.adapter))
|
|
1720
|
+
throw new Error(`Agent '${agentName}' external-cli runner adapter must be ${CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL}.`);
|
|
1721
|
+
if (runner.adapter !== undefined && Array.isArray(runner.args) && runner.args.length > 0)
|
|
1722
|
+
throw new Error(`Agent '${agentName}' ${runner.adapter} adapter owns its argv; runner args are not supported.`);
|
|
1723
|
+
if (runner.promptDelivery !== undefined && runner.promptDelivery !== "stdin") {
|
|
1724
|
+
throw new Error(`Agent '${agentName}' external-cli runner promptDelivery must be 'stdin'.`);
|
|
1725
|
+
}
|
|
1726
|
+
const capabilities = parseExternalCliCapabilityNarrowing(runner.capabilities, `Agent '${agentName}' external-cli runner capabilities`);
|
|
1727
|
+
const supported = new Set(["type", "adapter", "command", "args", "promptDelivery", "capabilities"]);
|
|
1728
|
+
const unknown = Object.keys(runner).filter((key) => !supported.has(key));
|
|
1729
|
+
if (unknown.length > 0)
|
|
1730
|
+
throw new Error(`Agent '${agentName}' external-cli runner has unsupported fields: ${unknown.join(", ")}.`);
|
|
1731
|
+
const runnerArgs = Array.isArray(runner.args) ? runner.args.filter((arg) => typeof arg === "string") : undefined;
|
|
1732
|
+
return {
|
|
1733
|
+
type: "external-cli",
|
|
1734
|
+
...(isCodeOwnedExternalCliAdapterId(runner.adapter) ? { adapter: runner.adapter } : {}),
|
|
1735
|
+
command: runner.command.trim(),
|
|
1736
|
+
...(runnerArgs?.length ? { args: runnerArgs } : {}),
|
|
1737
|
+
...(runner.promptDelivery ? { promptDelivery: "stdin" } : {}),
|
|
1738
|
+
...(capabilities ? { capabilities } : {}),
|
|
1739
|
+
};
|
|
1740
|
+
}
|
|
1741
|
+
function validateExternalRunnerProfile(frontmatter, agentName, runner) {
|
|
1742
|
+
if (runner?.type !== "external-cli" && runner?.type !== "external-job")
|
|
1743
|
+
return;
|
|
1744
|
+
const unsupported = ["tools", "excludeTools", "allowNestedSubagents", "allowedAgents", "model", "thinking", "extensions", "subagentOnlyExtensions", "mutationTools", "maxSubagentDepth", "completionGuard", "skills", "skill", "skillPath", "toolBudget", "permission", "permissions"]
|
|
1745
|
+
.filter((field) => frontmatter[field] !== undefined);
|
|
1746
|
+
if (unsupported.length > 0) {
|
|
1747
|
+
throw new Error(`Agent '${agentName}' uses runner.type='${runner.type}' and declares unsupported Pi-only fields: ${unsupported.join(", ")}.`);
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
function parseAgentAcceptanceFrontmatter(raw, agentName) {
|
|
1751
|
+
if (raw === undefined || !raw.trim())
|
|
1752
|
+
return undefined;
|
|
1753
|
+
let parsed;
|
|
1754
|
+
try {
|
|
1755
|
+
parsed = parseYaml(raw);
|
|
1756
|
+
}
|
|
1757
|
+
catch (error) {
|
|
1758
|
+
throw new Error(`Agent '${agentName}' has invalid acceptance frontmatter: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
1759
|
+
}
|
|
1760
|
+
const errors = validateAcceptanceInput(parsed, `Agent '${agentName}' acceptance frontmatter`);
|
|
1761
|
+
if (errors.length > 0)
|
|
1762
|
+
throw new Error(errors.join(" "));
|
|
1763
|
+
return parsed;
|
|
1764
|
+
}
|
|
1765
|
+
function readAgentDefinitionFiles(dir, inspection = inspectAgentDefinitionDirectory(dir)) {
|
|
1766
|
+
const files = [];
|
|
1767
|
+
for (const filePath of inspection.files) {
|
|
1768
|
+
if (isLegacyAgentSkillPath(dir, filePath)) {
|
|
1769
|
+
continue;
|
|
1770
|
+
}
|
|
1771
|
+
try {
|
|
1772
|
+
files.push({ filePath, content: fs.readFileSync(filePath, "utf-8") });
|
|
1773
|
+
}
|
|
1774
|
+
catch {
|
|
1775
|
+
continue;
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
return files;
|
|
1779
|
+
}
|
|
1780
|
+
function resolveAgentRelativeExtensionPaths(paths, agentFilePath) {
|
|
1781
|
+
if (paths === undefined)
|
|
1782
|
+
return undefined;
|
|
1783
|
+
const baseDir = path.dirname(agentFilePath);
|
|
1784
|
+
return paths.map((entry) => {
|
|
1785
|
+
const trimmed = entry.trim();
|
|
1786
|
+
if (trimmed === "." || trimmed === ".." || trimmed.startsWith("./") || trimmed.startsWith("../")) {
|
|
1787
|
+
return path.resolve(baseDir, trimmed);
|
|
1788
|
+
}
|
|
1789
|
+
return entry;
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1792
|
+
function loadAgentsFromDefinitionFiles(files, source, discoveryPriority, packageSource) {
|
|
1793
|
+
const agents = [];
|
|
1794
|
+
const diagnostics = [];
|
|
1795
|
+
for (const { filePath, content } of files) {
|
|
1796
|
+
let name;
|
|
1797
|
+
let runtimeName;
|
|
1798
|
+
let packageSpecified = false;
|
|
1799
|
+
try {
|
|
1800
|
+
const { frontmatter, body } = parseFrontmatter(content);
|
|
1801
|
+
if (!frontmatter.name || !frontmatter.description) {
|
|
1802
|
+
continue;
|
|
1803
|
+
}
|
|
1804
|
+
const localName = frontmatter.name;
|
|
1805
|
+
name = localName;
|
|
1806
|
+
const parsedPackage = parsePackageName(frontmatter.package, `Agent '${localName}' package`);
|
|
1807
|
+
packageSpecified = parsedPackage.packageName !== undefined || parsedPackage.error !== undefined;
|
|
1808
|
+
if (parsedPackage.error)
|
|
1809
|
+
throw new Error(parsedPackage.error);
|
|
1810
|
+
const packageName = parsedPackage.packageName;
|
|
1811
|
+
runtimeName = buildRuntimeName(localName, packageName);
|
|
1812
|
+
const runner = parseAgentRunnerFrontmatter(frontmatter.runner, localName);
|
|
1813
|
+
validateExternalRunnerProfile(frontmatter, localName, runner);
|
|
1814
|
+
let advertise;
|
|
1815
|
+
if (frontmatter.advertise !== undefined) {
|
|
1816
|
+
if (frontmatter.advertise === "true")
|
|
1817
|
+
advertise = true;
|
|
1818
|
+
else if (frontmatter.advertise === "false")
|
|
1819
|
+
advertise = false;
|
|
1820
|
+
else
|
|
1821
|
+
throw new Error(`Agent '${localName}' has invalid advertise frontmatter; expected true or false.`);
|
|
1822
|
+
}
|
|
1823
|
+
const rawTools = parseFrontmatterList(frontmatter.tools);
|
|
1824
|
+
const parsedTools = splitToolList(rawTools);
|
|
1825
|
+
const tools = parsedTools.tools ?? [];
|
|
1826
|
+
const mcpDirectTools = parsedTools.mcpDirectTools ?? [];
|
|
1827
|
+
const excludeTools = parseFrontmatterList(frontmatter.excludeTools);
|
|
1828
|
+
const parsedAllowedAgents = parseFrontmatterList(frontmatter.allowedAgents);
|
|
1829
|
+
const allowedAgents = parsedAllowedAgents === undefined ? undefined : normalizeCapabilityCeilingAllowedAgents(parsedAllowedAgents);
|
|
1830
|
+
const defaultReads = parseFrontmatterList(frontmatter.defaultReads);
|
|
1831
|
+
const aliases = normalizeAgentAliases(parseFrontmatterList(frontmatter.aliases ?? frontmatter.alias), runtimeName);
|
|
1832
|
+
const profileError = validateCodeOwnedProfileRunner({ name: runtimeName, localName, aliases, runner });
|
|
1833
|
+
if (profileError)
|
|
1834
|
+
throw new Error(profileError);
|
|
1835
|
+
const skillStr = frontmatter.skill || frontmatter.skills;
|
|
1836
|
+
const skills = parseFrontmatterList(skillStr);
|
|
1837
|
+
const skillPath = parseFrontmatterList(frontmatter.skillPath);
|
|
1838
|
+
if (frontmatter.fallbackModels !== undefined)
|
|
1839
|
+
throw new Error(`Agent '${filePath}' uses removed frontmatter field 'fallbackModels'. Configure one model instead.`);
|
|
1840
|
+
const systemPromptMode = frontmatter.systemPromptMode === "replace"
|
|
1841
|
+
? "replace"
|
|
1842
|
+
: frontmatter.systemPromptMode === "append"
|
|
1843
|
+
? "append"
|
|
1844
|
+
: defaultSystemPromptMode(localName);
|
|
1845
|
+
const inheritProjectContext = frontmatter.inheritProjectContext === "true"
|
|
1846
|
+
? true
|
|
1847
|
+
: frontmatter.inheritProjectContext === "false"
|
|
1848
|
+
? false
|
|
1849
|
+
: defaultInheritProjectContext(localName);
|
|
1850
|
+
const inheritGlobalContext = frontmatter.inheritGlobalContext === "true";
|
|
1851
|
+
const inheritSkills = frontmatter.inheritSkills === "true"
|
|
1852
|
+
? true
|
|
1853
|
+
: frontmatter.inheritSkills === "false"
|
|
1854
|
+
? false
|
|
1855
|
+
: defaultInheritSkills();
|
|
1856
|
+
const defaultContext = frontmatter.defaultContext === "fork"
|
|
1857
|
+
? "fork"
|
|
1858
|
+
: frontmatter.defaultContext === "fresh"
|
|
1859
|
+
? "fresh"
|
|
1860
|
+
: undefined;
|
|
1861
|
+
let defaultAsync;
|
|
1862
|
+
if (frontmatter.async !== undefined) {
|
|
1863
|
+
if (frontmatter.async === "true")
|
|
1864
|
+
defaultAsync = true;
|
|
1865
|
+
else if (frontmatter.async === "false")
|
|
1866
|
+
defaultAsync = false;
|
|
1867
|
+
else
|
|
1868
|
+
throw new Error(`Agent '${localName}' has invalid async frontmatter; expected true or false.`);
|
|
1869
|
+
}
|
|
1870
|
+
let defaultTimeoutMs;
|
|
1871
|
+
if (frontmatter.timeoutMs !== undefined) {
|
|
1872
|
+
const parsed = Number(frontmatter.timeoutMs);
|
|
1873
|
+
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
1874
|
+
throw new Error(`Agent '${localName}' has invalid timeoutMs frontmatter; expected a positive integer.`);
|
|
1875
|
+
}
|
|
1876
|
+
defaultTimeoutMs = parsed;
|
|
1877
|
+
}
|
|
1878
|
+
let defaultToolTimeoutMs;
|
|
1879
|
+
if (frontmatter.toolTimeoutMs !== undefined) {
|
|
1880
|
+
const parsed = Number(frontmatter.toolTimeoutMs);
|
|
1881
|
+
if (!Number.isInteger(parsed) || parsed <= 0 || parsed > 2_147_483_647) {
|
|
1882
|
+
throw new Error(`Agent '${localName}' has invalid toolTimeoutMs frontmatter; expected a positive integer no larger than 2147483647.`);
|
|
1883
|
+
}
|
|
1884
|
+
defaultToolTimeoutMs = parsed;
|
|
1885
|
+
}
|
|
1886
|
+
const defaultAcceptance = parseAgentAcceptanceFrontmatter(frontmatter.acceptance, localName);
|
|
1887
|
+
let outputMode;
|
|
1888
|
+
if (frontmatter.outputMode !== undefined) {
|
|
1889
|
+
if (frontmatter.outputMode === "inline" || frontmatter.outputMode === "file-only")
|
|
1890
|
+
outputMode = frontmatter.outputMode;
|
|
1891
|
+
else
|
|
1892
|
+
throw new Error(`Agent '${localName}' has invalid outputMode frontmatter; expected 'inline' or 'file-only'.`);
|
|
1893
|
+
}
|
|
1894
|
+
let acceptanceRole;
|
|
1895
|
+
if (frontmatter.acceptanceRole !== undefined && frontmatter.acceptanceRole.trim()) {
|
|
1896
|
+
if (frontmatter.acceptanceRole === "read-only" || frontmatter.acceptanceRole === "writer")
|
|
1897
|
+
acceptanceRole = frontmatter.acceptanceRole;
|
|
1898
|
+
else
|
|
1899
|
+
throw new Error(`Agent '${localName}' has invalid acceptanceRole frontmatter; expected 'read-only' or 'writer'.`);
|
|
1900
|
+
}
|
|
1901
|
+
const extensions = resolveAgentRelativeExtensionPaths(parseFrontmatterList(frontmatter.extensions), filePath);
|
|
1902
|
+
const subagentOnlyExtensions = resolveAgentRelativeExtensionPaths(parseFrontmatterList(frontmatter.subagentOnlyExtensions), filePath);
|
|
1903
|
+
const mutationTools = parseFrontmatterList(frontmatter.mutationTools);
|
|
1904
|
+
let fast;
|
|
1905
|
+
if (frontmatter.fast !== undefined) {
|
|
1906
|
+
if (frontmatter.fast === "true")
|
|
1907
|
+
fast = true;
|
|
1908
|
+
else if (frontmatter.fast === "false")
|
|
1909
|
+
fast = false;
|
|
1910
|
+
else
|
|
1911
|
+
throw new Error(`Agent '${localName}' has invalid fast frontmatter; expected true or false.`);
|
|
1912
|
+
}
|
|
1913
|
+
let allowNestedSubagents;
|
|
1914
|
+
if (frontmatter.allowNestedSubagents !== undefined) {
|
|
1915
|
+
if (frontmatter.allowNestedSubagents === "true")
|
|
1916
|
+
allowNestedSubagents = true;
|
|
1917
|
+
else if (frontmatter.allowNestedSubagents === "false")
|
|
1918
|
+
allowNestedSubagents = false;
|
|
1919
|
+
else
|
|
1920
|
+
throw new Error(`Agent '${localName}' has invalid allowNestedSubagents frontmatter; expected true or false.`);
|
|
1921
|
+
}
|
|
1922
|
+
const extraFields = {};
|
|
1923
|
+
for (const [key, value] of Object.entries(frontmatter)) {
|
|
1924
|
+
if (!KNOWN_FIELDS.has(key))
|
|
1925
|
+
extraFields[key] = value;
|
|
1926
|
+
}
|
|
1927
|
+
const parsedMaxSubagentDepth = Number(frontmatter.maxSubagentDepth);
|
|
1928
|
+
if (frontmatter.permission !== undefined && frontmatter.permissions !== undefined) {
|
|
1929
|
+
throw new Error(`Agent '${localName}' cannot declare both permission and permissions frontmatter.`);
|
|
1930
|
+
}
|
|
1931
|
+
const permissionSource = frontmatter.permissions ?? frontmatter.permission;
|
|
1932
|
+
const permissions = permissionSource?.trim()
|
|
1933
|
+
? validatePermissionRules(parseYaml(permissionSource), `Agent '${localName}' permissions`)
|
|
1934
|
+
: undefined;
|
|
1935
|
+
let toolBudget;
|
|
1936
|
+
if (frontmatter.toolBudget !== undefined && frontmatter.toolBudget.trim()) {
|
|
1937
|
+
const parsed = JSON.parse(frontmatter.toolBudget);
|
|
1938
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
1939
|
+
throw new Error(`Agent '${localName}' has invalid toolBudget frontmatter; expected a JSON object.`);
|
|
1940
|
+
}
|
|
1941
|
+
toolBudget = parsed;
|
|
1942
|
+
}
|
|
1943
|
+
let outputSchema;
|
|
1944
|
+
if (frontmatter.outputSchema !== undefined && frontmatter.outputSchema.trim()) {
|
|
1945
|
+
const parsed = JSON.parse(frontmatter.outputSchema);
|
|
1946
|
+
assertJsonSchemaObject(parsed, `Agent '${localName}' outputSchema`);
|
|
1947
|
+
outputSchema = parsed;
|
|
1948
|
+
}
|
|
1949
|
+
const completionGuard = frontmatter.completionGuard === "false"
|
|
1950
|
+
? false
|
|
1951
|
+
: frontmatter.completionGuard === "true"
|
|
1952
|
+
? true
|
|
1953
|
+
: undefined;
|
|
1954
|
+
const maxSubagentDepth = Number.isInteger(parsedMaxSubagentDepth) && parsedMaxSubagentDepth >= 0
|
|
1955
|
+
? parsedMaxSubagentDepth
|
|
1956
|
+
: undefined;
|
|
1957
|
+
const memory = parseMemoryFrontmatter(frontmatter.memory);
|
|
1958
|
+
const machine = validateOptionalMachine(frontmatter.machine, `Agent '${runtimeName}' frontmatter 'machine'`);
|
|
1959
|
+
const agent = {
|
|
1960
|
+
name: runtimeName,
|
|
1961
|
+
...(runner !== undefined ? { runner } : {}),
|
|
1962
|
+
localName,
|
|
1963
|
+
...(packageName !== undefined ? { packageName } : {}),
|
|
1964
|
+
...(packageSource?.packageName ? { packageSourceName: packageSource.packageName } : {}),
|
|
1965
|
+
...(packageSource?.packageVersion ? { packageSourceVersion: packageSource.packageVersion } : {}),
|
|
1966
|
+
...(packageSource?.packageRoot ? { packageSourceRoot: packageSource.packageRoot } : {}),
|
|
1967
|
+
description: frontmatter.description,
|
|
1968
|
+
...(advertise !== undefined ? { advertise } : {}),
|
|
1969
|
+
...(aliases !== undefined ? { aliases } : {}),
|
|
1970
|
+
...(rawTools !== undefined ? { tools } : {}),
|
|
1971
|
+
...(excludeTools !== undefined ? { excludeTools } : {}),
|
|
1972
|
+
...(allowNestedSubagents !== undefined ? { allowNestedSubagents } : {}),
|
|
1973
|
+
...(allowedAgents !== undefined ? { allowedAgents } : {}),
|
|
1974
|
+
...(mcpDirectTools.length > 0 ? { mcpDirectTools } : {}),
|
|
1975
|
+
...(frontmatter.model !== undefined ? { model: frontmatter.model } : {}),
|
|
1976
|
+
...(fast !== undefined ? { fast } : {}),
|
|
1977
|
+
...(frontmatter.thinking !== undefined ? { thinking: frontmatter.thinking === "false" ? false : frontmatter.thinking } : {}),
|
|
1978
|
+
systemPromptMode,
|
|
1979
|
+
inheritProjectContext,
|
|
1980
|
+
inheritGlobalContext,
|
|
1981
|
+
inheritSkills,
|
|
1982
|
+
...(defaultContext !== undefined ? { defaultContext } : {}),
|
|
1983
|
+
...(defaultAsync !== undefined ? { defaultAsync } : {}),
|
|
1984
|
+
...(defaultTimeoutMs !== undefined ? { defaultTimeoutMs } : {}),
|
|
1985
|
+
...(defaultToolTimeoutMs !== undefined ? { defaultToolTimeoutMs } : {}),
|
|
1986
|
+
...(defaultAcceptance !== undefined ? { defaultAcceptance } : {}),
|
|
1987
|
+
...(acceptanceRole !== undefined ? { acceptanceRole } : {}),
|
|
1988
|
+
systemPrompt: body,
|
|
1989
|
+
source,
|
|
1990
|
+
filePath,
|
|
1991
|
+
...(discoveryPriority !== undefined ? { discoveryPriority } : {}),
|
|
1992
|
+
...(skills?.length ? { skills } : {}),
|
|
1993
|
+
...(skillPath?.length ? { skillPath } : {}),
|
|
1994
|
+
...(extensions !== undefined ? { extensions } : {}),
|
|
1995
|
+
...(subagentOnlyExtensions !== undefined ? { subagentOnlyExtensions } : {}),
|
|
1996
|
+
...(mutationTools?.length ? { mutationTools } : {}),
|
|
1997
|
+
...(machine !== undefined ? { machine } : {}),
|
|
1998
|
+
...(frontmatter.output !== undefined ? { output: frontmatter.output } : {}),
|
|
1999
|
+
...(outputMode !== undefined ? { outputMode } : {}),
|
|
2000
|
+
...(outputSchema !== undefined ? { outputSchema } : {}),
|
|
2001
|
+
...(defaultReads?.length ? { defaultReads } : {}),
|
|
2002
|
+
defaultProgress: frontmatter.defaultProgress === "true",
|
|
2003
|
+
interactive: frontmatter.interactive === "true",
|
|
2004
|
+
...(maxSubagentDepth !== undefined ? { maxSubagentDepth } : {}),
|
|
2005
|
+
...(completionGuard !== undefined ? { completionGuard } : {}),
|
|
2006
|
+
...(toolBudget !== undefined ? { toolBudget } : {}),
|
|
2007
|
+
...(permissions !== undefined ? { permissions } : {}),
|
|
2008
|
+
...(memory !== undefined ? { memory } : {}),
|
|
2009
|
+
...(Object.keys(extraFields).length > 0 ? { extraFields } : {}),
|
|
2010
|
+
};
|
|
2011
|
+
agentFrontmatterFields.set(agent, new Set(Object.keys(frontmatter)));
|
|
2012
|
+
agents.push(agent);
|
|
2013
|
+
}
|
|
2014
|
+
catch (error) {
|
|
2015
|
+
diagnostics.push({ source, filePath, ...(name ? { name } : {}), ...(runtimeName && runtimeName !== name ? { runtimeName } : {}), ...(packageSpecified ? { packageSpecified: true } : {}), ...(discoveryPriority !== undefined ? { discoveryPriority } : {}), error: error instanceof Error ? error.message : String(error) });
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
return { agents, diagnostics };
|
|
2019
|
+
}
|
|
2020
|
+
function loadAgentsFromDir(dir, source, discoveryPriority, packageSource, inspection = inspectAgentDefinitionDirectory(dir)) {
|
|
2021
|
+
return loadAgentsFromDefinitionFiles(readAgentDefinitionFiles(dir, inspection), source, discoveryPriority, packageSource);
|
|
2022
|
+
}
|
|
2023
|
+
function reportAgentDefinitionDirectory(source, dir, inspection) {
|
|
2024
|
+
return {
|
|
2025
|
+
source,
|
|
2026
|
+
path: path.resolve(dir),
|
|
2027
|
+
state: inspection.state,
|
|
2028
|
+
...(inspection.state === "candidates" ? { candidateCount: inspection.files.length } : {}),
|
|
2029
|
+
};
|
|
2030
|
+
}
|
|
2031
|
+
function loadChainsFromDir(dir, source) {
|
|
2032
|
+
const chains = new Map();
|
|
2033
|
+
const diagnostics = [];
|
|
2034
|
+
const directories = new Set();
|
|
2035
|
+
const files = listFilesRecursive(dir, (fileName) => fileName.endsWith(".chain.md") || fileName.endsWith(".chain.json"), dir, new Set(), directories);
|
|
2036
|
+
for (const filePath of files) {
|
|
2037
|
+
let content;
|
|
2038
|
+
try {
|
|
2039
|
+
content = fs.readFileSync(filePath, "utf-8");
|
|
2040
|
+
}
|
|
2041
|
+
catch {
|
|
2042
|
+
continue;
|
|
2043
|
+
}
|
|
2044
|
+
try {
|
|
2045
|
+
const chain = filePath.endsWith(".chain.json") ? parseJsonChain(content, source, filePath) : parseChain(content, source, filePath);
|
|
2046
|
+
const existing = chains.get(chain.name);
|
|
2047
|
+
if (existing && existing.filePath.endsWith(".chain.json") && filePath.endsWith(".chain.md"))
|
|
2048
|
+
continue;
|
|
2049
|
+
chains.set(chain.name, chain);
|
|
2050
|
+
}
|
|
2051
|
+
catch (error) {
|
|
2052
|
+
diagnostics.push({ source, filePath, error: error instanceof Error ? error.message : String(error) });
|
|
2053
|
+
continue;
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
return { chains: Array.from(chains.values()), diagnostics, files, directories: [...directories] };
|
|
2057
|
+
}
|
|
2058
|
+
function isDirectory(p) {
|
|
2059
|
+
try {
|
|
2060
|
+
return fs.statSync(p).isDirectory();
|
|
2061
|
+
}
|
|
2062
|
+
catch {
|
|
2063
|
+
return false;
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
function resolveNearestProjectAgentDirs(cwd) {
|
|
2067
|
+
const projectRoot = findConfiguredProjectRoot(cwd);
|
|
2068
|
+
if (!projectRoot)
|
|
2069
|
+
return { readDirs: [], candidateDirs: [], preferredDir: null };
|
|
2070
|
+
const legacyDir = path.join(projectRoot, ".agents");
|
|
2071
|
+
const preferredDir = path.join(getProjectConfigDir(projectRoot), "agents");
|
|
2072
|
+
const candidateDirs = [legacyDir, preferredDir];
|
|
2073
|
+
const readDirs = [];
|
|
2074
|
+
if (isDirectory(legacyDir))
|
|
2075
|
+
readDirs.push(legacyDir);
|
|
2076
|
+
if (isDirectory(preferredDir))
|
|
2077
|
+
readDirs.push(preferredDir);
|
|
2078
|
+
return { readDirs, candidateDirs, preferredDir };
|
|
2079
|
+
}
|
|
2080
|
+
function resolveNearestProjectChainDirs(cwd) {
|
|
2081
|
+
const projectRoot = findConfiguredProjectRoot(cwd);
|
|
2082
|
+
if (!projectRoot)
|
|
2083
|
+
return { readDirs: [], preferredDir: null };
|
|
2084
|
+
const preferredDir = path.join(getProjectConfigDir(projectRoot), "chains");
|
|
2085
|
+
return {
|
|
2086
|
+
readDirs: isDirectory(preferredDir) ? [preferredDir] : [],
|
|
2087
|
+
preferredDir,
|
|
2088
|
+
};
|
|
2089
|
+
}
|
|
2090
|
+
const BUILTIN_AGENTS_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "agents");
|
|
2091
|
+
// Candidate files and inspection state must describe the same cached builtin scan.
|
|
2092
|
+
const BUILTIN_AGENT_DEFINITION_INSPECTION = inspectAgentDefinitionDirectory(BUILTIN_AGENTS_DIR);
|
|
2093
|
+
const BUILTIN_AGENT_DEFINITION_FILES = readAgentDefinitionFiles(BUILTIN_AGENTS_DIR, BUILTIN_AGENT_DEFINITION_INSPECTION);
|
|
2094
|
+
export const EXTRA_AGENT_DIRS_ENV = "PI_SUBAGENT_EXTRA_AGENT_DIRS";
|
|
2095
|
+
// Additional read-only directories to scan for agent definitions, supplied by the
|
|
2096
|
+
// launcher via PI_SUBAGENT_EXTRA_AGENT_DIRS (PATH-style, split on os/path delimiter).
|
|
2097
|
+
// Lets a hermetic wrapper (e.g. a Nix-store install) expose bundled agents without
|
|
2098
|
+
// copying or symlinking them into the writable agent dir. Loaded as "user" source,
|
|
2099
|
+
// at lower precedence than agents the user placed in their own agent dir.
|
|
2100
|
+
function extraUserAgentDirs() {
|
|
2101
|
+
const raw = process.env[EXTRA_AGENT_DIRS_ENV];
|
|
2102
|
+
if (!raw)
|
|
2103
|
+
return [];
|
|
2104
|
+
return raw
|
|
2105
|
+
.split(path.delimiter)
|
|
2106
|
+
.map((dir) => dir.trim())
|
|
2107
|
+
.filter((dir) => dir.length > 0);
|
|
2108
|
+
}
|
|
2109
|
+
function readConfiguredAgentScanDirs(filePath, key = "agentScanDirs") {
|
|
2110
|
+
if (!filePath)
|
|
2111
|
+
return [];
|
|
2112
|
+
try {
|
|
2113
|
+
const settings = readSettingsFileStrict(filePath);
|
|
2114
|
+
const subagents = settings.subagents;
|
|
2115
|
+
if (!subagents || typeof subagents !== "object" || Array.isArray(subagents))
|
|
2116
|
+
return [];
|
|
2117
|
+
const dirs = subagents[key];
|
|
2118
|
+
return Array.isArray(dirs) ? dirs.filter((dir) => typeof dir === "string" && dir.trim().length > 0) : [];
|
|
2119
|
+
}
|
|
2120
|
+
catch {
|
|
2121
|
+
return [];
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
// Resolve existing ancestors to canonicalize missing descendants of symlinks.
|
|
2125
|
+
function canonicalAgentPath(filePath) {
|
|
2126
|
+
const resolved = path.resolve(filePath);
|
|
2127
|
+
try {
|
|
2128
|
+
return fs.realpathSync(resolved);
|
|
2129
|
+
}
|
|
2130
|
+
catch {
|
|
2131
|
+
const parent = path.dirname(resolved);
|
|
2132
|
+
return parent === resolved ? resolved : path.join(canonicalAgentPath(parent), path.basename(resolved));
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
function agentExclusionRoots(userSettingsPath, projectSettingsPath) {
|
|
2136
|
+
return [userSettingsPath, projectSettingsPath].flatMap((settingsPath) => settingsPath
|
|
2137
|
+
? readConfiguredAgentScanDirs(settingsPath, "agentExcludeDirs").map((entry) => {
|
|
2138
|
+
const resolved = path.resolve(path.dirname(settingsPath), expandHomePath(entry.trim()).replace(/[\\/]+/g, path.sep));
|
|
2139
|
+
return { resolved, real: canonicalAgentPath(resolved) };
|
|
2140
|
+
}) : []);
|
|
2141
|
+
}
|
|
2142
|
+
function agentExclusions(roots) {
|
|
2143
|
+
return (filePath) => {
|
|
2144
|
+
if (!roots.length)
|
|
2145
|
+
return false;
|
|
2146
|
+
if (roots.some((root) => isPathWithin(root.resolved, filePath)))
|
|
2147
|
+
return true;
|
|
2148
|
+
const real = canonicalAgentPath(filePath);
|
|
2149
|
+
return roots.some((root) => isPathWithin(root.real, real));
|
|
2150
|
+
};
|
|
2151
|
+
}
|
|
2152
|
+
function expandAgentScanDirPattern(pattern, isExcluded) {
|
|
2153
|
+
const expanded = expandHomePath(pattern.trim()).replace(/[\\/]+/g, path.sep);
|
|
2154
|
+
if (!expanded)
|
|
2155
|
+
return { dirs: [], watchPaths: [] };
|
|
2156
|
+
const wildcardMatches = [...expanded.matchAll(/\*/g)];
|
|
2157
|
+
if (wildcardMatches.length === 0) {
|
|
2158
|
+
const dir = path.resolve(expanded);
|
|
2159
|
+
return { dirs: !isExcluded(dir) && fs.existsSync(dir) ? [dir] : [], watchPaths: [dir] };
|
|
2160
|
+
}
|
|
2161
|
+
const parts = expanded.split(path.sep);
|
|
2162
|
+
const wildcardIndex = parts.findIndex((part) => part.includes("*"));
|
|
2163
|
+
if (wildcardMatches.length !== 1 || wildcardIndex === -1 || parts[wildcardIndex] !== "*")
|
|
2164
|
+
return { dirs: [], watchPaths: [] };
|
|
2165
|
+
const base = path.resolve(parts.slice(0, wildcardIndex).join(path.sep) || path.sep);
|
|
2166
|
+
if (isExcluded(base))
|
|
2167
|
+
return { dirs: [], watchPaths: [base] };
|
|
2168
|
+
const rest = parts.slice(wildcardIndex + 1);
|
|
2169
|
+
let entries;
|
|
2170
|
+
try {
|
|
2171
|
+
entries = fs.readdirSync(base, { withFileTypes: true });
|
|
2172
|
+
}
|
|
2173
|
+
catch {
|
|
2174
|
+
return { dirs: [], watchPaths: [base] };
|
|
2175
|
+
}
|
|
2176
|
+
const candidateDirs = entries.filter((entry) => entry.isDirectory()).map((entry) => path.join(base, entry.name, ...rest));
|
|
2177
|
+
return {
|
|
2178
|
+
dirs: candidateDirs.filter((dir) => !isExcluded(dir) && fs.existsSync(dir)),
|
|
2179
|
+
watchPaths: [base, ...candidateDirs],
|
|
2180
|
+
};
|
|
2181
|
+
}
|
|
2182
|
+
function settingsAgentScanDirs(entries, isExcluded) {
|
|
2183
|
+
const dirs = new Set();
|
|
2184
|
+
const watchPaths = new Set();
|
|
2185
|
+
for (const entry of entries) {
|
|
2186
|
+
const expanded = expandAgentScanDirPattern(entry, isExcluded);
|
|
2187
|
+
for (const dir of expanded.dirs)
|
|
2188
|
+
dirs.add(dir);
|
|
2189
|
+
for (const watchPath of expanded.watchPaths)
|
|
2190
|
+
watchPaths.add(watchPath);
|
|
2191
|
+
}
|
|
2192
|
+
return { dirs: [...dirs], watchPaths: [...watchPaths] };
|
|
2193
|
+
}
|
|
2194
|
+
const agentDiscoveryCache = new Map();
|
|
2195
|
+
function isPathWithin(root, candidate) {
|
|
2196
|
+
const relative = path.relative(path.resolve(root), path.resolve(candidate));
|
|
2197
|
+
return relative === "" || (relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative));
|
|
2198
|
+
}
|
|
2199
|
+
function addDirectoryWatchPaths(paths, root, files, directories = []) {
|
|
2200
|
+
const resolvedRoot = path.resolve(root);
|
|
2201
|
+
paths.add(resolvedRoot);
|
|
2202
|
+
// The initial recursive inspection is already bounded to this discovery
|
|
2203
|
+
// root. Keep every visited directory in the fingerprint so a file added to
|
|
2204
|
+
// an existing empty nested directory invalidates the snapshot too.
|
|
2205
|
+
for (const directory of directories) {
|
|
2206
|
+
if (isPathWithin(resolvedRoot, directory))
|
|
2207
|
+
paths.add(path.resolve(directory));
|
|
2208
|
+
}
|
|
2209
|
+
for (const file of files) {
|
|
2210
|
+
paths.add(path.resolve(file));
|
|
2211
|
+
let current = path.resolve(path.dirname(file));
|
|
2212
|
+
while (isPathWithin(resolvedRoot, current)) {
|
|
2213
|
+
paths.add(current);
|
|
2214
|
+
if (current === resolvedRoot)
|
|
2215
|
+
break;
|
|
2216
|
+
current = path.dirname(current);
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
function watchPathSignature(filePath, isExcluded) {
|
|
2221
|
+
try {
|
|
2222
|
+
const stat = fs.statSync(filePath);
|
|
2223
|
+
if (stat.isDirectory()) {
|
|
2224
|
+
const entries = fs.readdirSync(filePath, { withFileTypes: true })
|
|
2225
|
+
.filter((entry) => !isExcluded || !isExcluded(path.join(filePath, entry.name)))
|
|
2226
|
+
.sort((left, right) => left.name.localeCompare(right.name))
|
|
2227
|
+
.map((entry) => `${entry.name}:${entry.isDirectory() ? "d" : entry.isSymbolicLink() ? (isExcluded ? `l:${canonicalAgentPath(path.join(filePath, entry.name))}` : "l") : "f"}`)
|
|
2228
|
+
.join("|");
|
|
2229
|
+
return `directory:${entries}`;
|
|
2230
|
+
}
|
|
2231
|
+
return `file:${stat.size}:${stat.mtimeMs}`;
|
|
2232
|
+
}
|
|
2233
|
+
catch {
|
|
2234
|
+
return "missing";
|
|
2235
|
+
}
|
|
2236
|
+
}
|
|
2237
|
+
function discoveryFingerprint(sources) {
|
|
2238
|
+
const exclusionIdentity = JSON.stringify(sources.exclusionRoots.map((root) => ({ resolved: root.resolved, real: canonicalAgentPath(root.resolved) })));
|
|
2239
|
+
// A retargeted exclusion needs a fresh scan before fingerprinting old roots.
|
|
2240
|
+
if (exclusionIdentity !== JSON.stringify(sources.exclusionRoots))
|
|
2241
|
+
return exclusionIdentity;
|
|
2242
|
+
const rootIdentities = JSON.stringify(sources.identityWatchPaths.map((root) => [root, canonicalAgentPath(root)]));
|
|
2243
|
+
// Package metadata can redirect agents outside an excluded tree without chains.
|
|
2244
|
+
const unfilteredPaths = new Set([...sources.packageSubagentPaths.watchPaths, ...(sources.chainWatchPaths ?? [])]);
|
|
2245
|
+
return exclusionIdentity + "\n" + rootIdentities + "\n" + [...new Set([...sources.watchPaths, ...unfilteredPaths])]
|
|
2246
|
+
.filter((filePath) => unfilteredPaths.has(filePath) || filePath === sources.userSettingsPath || filePath === sources.projectSettingsPath || !sources.isExcluded(filePath))
|
|
2247
|
+
.sort((left, right) => left.localeCompare(right))
|
|
2248
|
+
.map((filePath) => `${filePath}:${watchPathSignature(filePath, sources.exclusionRoots.length && !unfilteredPaths.has(filePath) ? sources.isExcluded : undefined)}`)
|
|
2249
|
+
.join("\n");
|
|
2250
|
+
}
|
|
2251
|
+
function discoveryCacheKey(cwd, preferredModelProvider) {
|
|
2252
|
+
return JSON.stringify([
|
|
2253
|
+
path.resolve(cwd),
|
|
2254
|
+
preferredModelProvider ?? null,
|
|
2255
|
+
getProjectConfigDir(path.resolve(cwd)),
|
|
2256
|
+
getAgentDir(),
|
|
2257
|
+
os.homedir(),
|
|
2258
|
+
process.env.HOME ?? "",
|
|
2259
|
+
process.env.USERPROFILE ?? "",
|
|
2260
|
+
process.env[EXTRA_AGENT_DIRS_ENV] ?? "",
|
|
2261
|
+
process.env.PI_OFFLINE ?? "",
|
|
2262
|
+
process.env.APPDATA ?? "",
|
|
2263
|
+
]);
|
|
2264
|
+
}
|
|
2265
|
+
function projectDiscoveryWatchPaths(cwd) {
|
|
2266
|
+
const paths = [];
|
|
2267
|
+
let current = path.resolve(cwd);
|
|
2268
|
+
while (true) {
|
|
2269
|
+
paths.push(getProjectConfigDir(current), path.join(current, ".agents"), path.join(current, ".git"));
|
|
2270
|
+
const parent = path.dirname(current);
|
|
2271
|
+
if (parent === current)
|
|
2272
|
+
break;
|
|
2273
|
+
current = parent;
|
|
2274
|
+
}
|
|
2275
|
+
return paths;
|
|
2276
|
+
}
|
|
2277
|
+
function packageEntryIncluded(scope, packageScopes) {
|
|
2278
|
+
if (scope === "both" || packageScopes.has("root"))
|
|
2279
|
+
return true;
|
|
2280
|
+
return packageScopes.has(scope);
|
|
2281
|
+
}
|
|
2282
|
+
function buildAgentDiscoverySources(cwd, preferredModelProvider) {
|
|
2283
|
+
const effectiveCwd = path.resolve(cwd);
|
|
2284
|
+
const userDirOld = path.join(getAgentDir(), "agents");
|
|
2285
|
+
const userDirNew = path.join(os.homedir(), ".agents");
|
|
2286
|
+
const userChainDir = getUserChainDir();
|
|
2287
|
+
const { readDirs: projectAgentDirs, candidateDirs: projectCandidateDirs, preferredDir: projectAgentsDir } = resolveNearestProjectAgentDirs(effectiveCwd);
|
|
2288
|
+
const { readDirs: projectChainDirs, preferredDir: projectChainDir } = resolveNearestProjectChainDirs(effectiveCwd);
|
|
2289
|
+
const userSettingsPath = getUserAgentSettingsPath();
|
|
2290
|
+
const projectSettingsPath = getProjectAgentSettingsPath(effectiveCwd);
|
|
2291
|
+
const packageSubagentPaths = collectPackageSubagentPaths(effectiveCwd);
|
|
2292
|
+
const exclusionRoots = agentExclusionRoots(userSettingsPath, projectSettingsPath);
|
|
2293
|
+
const isExcluded = agentExclusions(exclusionRoots);
|
|
2294
|
+
const userScanDirs = settingsAgentScanDirs(readConfiguredAgentScanDirs(userSettingsPath), isExcluded);
|
|
2295
|
+
const projectScanDirs = settingsAgentScanDirs(readConfiguredAgentScanDirs(projectSettingsPath), isExcluded);
|
|
2296
|
+
const builtinLoaded = loadAgentsFromDefinitionFiles(BUILTIN_AGENT_DEFINITION_FILES, "builtin");
|
|
2297
|
+
const userLoaded = [...extraUserAgentDirs(), ...userScanDirs.dirs, userDirOld, userDirNew].filter((dir) => !isExcluded(dir)).map((dir, discoveryPriority) => {
|
|
2298
|
+
const inspection = inspectAgentDefinitionDirectory(dir, undefined, isExcluded);
|
|
2299
|
+
return { dir, inspection, loaded: loadAgentsFromDir(dir, "user", discoveryPriority, undefined, inspection) };
|
|
2300
|
+
});
|
|
2301
|
+
const projectInspections = new Map(projectCandidateDirs.filter((dir) => !isExcluded(dir)).map((dir) => [dir, inspectAgentDefinitionDirectory(dir, undefined, isExcluded)]));
|
|
2302
|
+
const projectLoaded = [...projectScanDirs.dirs, ...projectAgentDirs].filter((dir) => !isExcluded(dir)).map((dir, discoveryPriority) => {
|
|
2303
|
+
const inspection = projectInspections.get(dir) ?? inspectAgentDefinitionDirectory(dir, undefined, isExcluded);
|
|
2304
|
+
return { dir, inspection, loaded: loadAgentsFromDir(dir, "project", dir === projectAgentsDir ? 1 : discoveryPriority, undefined, inspection) };
|
|
2305
|
+
});
|
|
2306
|
+
const packageLoaded = packageSubagentPaths.agents.filter((entry) => !isExcluded(entry.dir)).map((entry, index) => {
|
|
2307
|
+
const inspection = inspectAgentDefinitionDirectory(entry.dir, undefined, isExcluded);
|
|
2308
|
+
return { dir: entry.dir, inspection, packageEntry: entry, loaded: loadAgentsFromDir(entry.dir, "package", packageSubagentPaths.agents.length - index, entry, inspection) };
|
|
2309
|
+
});
|
|
2310
|
+
const watchPaths = new Set([
|
|
2311
|
+
userSettingsPath,
|
|
2312
|
+
...(projectSettingsPath ? [projectSettingsPath] : []),
|
|
2313
|
+
...projectDiscoveryWatchPaths(effectiveCwd),
|
|
2314
|
+
...findProjectRootCandidates(effectiveCwd).map((root) => path.join(getProjectConfigDir(root), "settings.json")),
|
|
2315
|
+
...userScanDirs.watchPaths,
|
|
2316
|
+
...projectScanDirs.watchPaths,
|
|
2317
|
+
...packageSubagentPaths.watchPaths,
|
|
2318
|
+
]);
|
|
2319
|
+
for (const directory of userLoaded)
|
|
2320
|
+
addDirectoryWatchPaths(watchPaths, directory.dir, directory.inspection.files, inspectedAgentDefinitionDirectories(directory.inspection, directory.dir));
|
|
2321
|
+
for (const dir of projectCandidateDirs) {
|
|
2322
|
+
const inspection = projectInspections.get(dir);
|
|
2323
|
+
addDirectoryWatchPaths(watchPaths, dir, inspection?.files ?? [], inspection ? inspectedAgentDefinitionDirectories(inspection, dir) : []);
|
|
2324
|
+
}
|
|
2325
|
+
for (const directory of projectLoaded)
|
|
2326
|
+
addDirectoryWatchPaths(watchPaths, directory.dir, directory.inspection.files, inspectedAgentDefinitionDirectories(directory.inspection, directory.dir));
|
|
2327
|
+
for (const directory of packageLoaded)
|
|
2328
|
+
addDirectoryWatchPaths(watchPaths, directory.dir, directory.inspection.files, inspectedAgentDefinitionDirectories(directory.inspection, directory.dir));
|
|
2329
|
+
const userDir = process.env.PI_CODING_AGENT_DIR ? userDirOld : fs.existsSync(userDirNew) ? userDirNew : userDirOld;
|
|
2330
|
+
return {
|
|
2331
|
+
cwd: effectiveCwd,
|
|
2332
|
+
...(preferredModelProvider !== undefined ? { preferredModelProvider } : {}),
|
|
2333
|
+
userDir,
|
|
2334
|
+
userDirOld,
|
|
2335
|
+
userDirNew,
|
|
2336
|
+
userChainDir,
|
|
2337
|
+
projectAgentDirs,
|
|
2338
|
+
projectCandidateDirs: projectCandidateDirs.filter((dir) => !isExcluded(dir)),
|
|
2339
|
+
projectAgentsDir,
|
|
2340
|
+
projectChainDirs,
|
|
2341
|
+
projectChainDir,
|
|
2342
|
+
userSettingsPath,
|
|
2343
|
+
projectSettingsPath,
|
|
2344
|
+
packageSubagentPaths,
|
|
2345
|
+
builtinLoaded,
|
|
2346
|
+
userLoaded,
|
|
2347
|
+
projectLoaded,
|
|
2348
|
+
projectInspections,
|
|
2349
|
+
packageLoaded,
|
|
2350
|
+
isExcluded,
|
|
2351
|
+
exclusionRoots,
|
|
2352
|
+
// Aliases outside excluded lexical subtrees can be retargeted into allowed
|
|
2353
|
+
// storage. Watch only their identity, never the excluded target's contents.
|
|
2354
|
+
identityWatchPaths: [...new Set([
|
|
2355
|
+
...userScanDirs.watchPaths, ...projectScanDirs.watchPaths,
|
|
2356
|
+
...extraUserAgentDirs(), userDirOld, userDirNew, ...projectCandidateDirs,
|
|
2357
|
+
...packageSubagentPaths.agents.map((entry) => entry.dir),
|
|
2358
|
+
])]
|
|
2359
|
+
.filter((dir) => !exclusionRoots.some((root) => isPathWithin(root.resolved, dir)) && isExcluded(dir)),
|
|
2360
|
+
watchPaths: [...watchPaths].filter((filePath) => !isExcluded(filePath) || filePath === userSettingsPath || filePath === projectSettingsPath),
|
|
2361
|
+
};
|
|
2362
|
+
}
|
|
2363
|
+
function ensureDiscoveryChains(sources) {
|
|
2364
|
+
if (sources.userChains)
|
|
2365
|
+
return;
|
|
2366
|
+
sources.packageChainLoaded = sources.packageSubagentPaths.chains.map((entry) => ({ entry, loaded: loadChainsFromDir(entry.dir, "package") }));
|
|
2367
|
+
sources.userChains = loadChainsFromDir(sources.userChainDir, "user");
|
|
2368
|
+
sources.projectChainLoaded = sources.projectChainDirs.map((dir) => ({ dir, loaded: loadChainsFromDir(dir, "project") }));
|
|
2369
|
+
const watchPaths = new Set(sources.packageSubagentPaths.watchPaths);
|
|
2370
|
+
addDirectoryWatchPaths(watchPaths, sources.userChainDir, sources.userChains.files, sources.userChains.directories);
|
|
2371
|
+
for (const chain of sources.projectChainLoaded)
|
|
2372
|
+
addDirectoryWatchPaths(watchPaths, chain.dir, chain.loaded.files, chain.loaded.directories);
|
|
2373
|
+
for (const chain of sources.packageChainLoaded)
|
|
2374
|
+
addDirectoryWatchPaths(watchPaths, chain.entry.dir, chain.loaded.files, chain.loaded.directories);
|
|
2375
|
+
sources.chainWatchPaths = watchPaths;
|
|
2376
|
+
sources.watchPaths = [...new Set([...sources.watchPaths, ...watchPaths])];
|
|
2377
|
+
}
|
|
2378
|
+
function getAgentDiscoverySources(cwd, preferredModelProvider, includeChains = false) {
|
|
2379
|
+
const key = discoveryCacheKey(cwd, preferredModelProvider);
|
|
2380
|
+
const cached = agentDiscoveryCache.get(key);
|
|
2381
|
+
if (cached && cached.fingerprint === discoveryFingerprint(cached.sources)) {
|
|
2382
|
+
if (includeChains) {
|
|
2383
|
+
ensureDiscoveryChains(cached.sources);
|
|
2384
|
+
cached.fingerprint = discoveryFingerprint(cached.sources);
|
|
2385
|
+
}
|
|
2386
|
+
return cached.sources;
|
|
2387
|
+
}
|
|
2388
|
+
const sources = buildAgentDiscoverySources(cwd, preferredModelProvider);
|
|
2389
|
+
const entry = { sources, fingerprint: discoveryFingerprint(sources) };
|
|
2390
|
+
agentDiscoveryCache.set(key, entry);
|
|
2391
|
+
if (includeChains) {
|
|
2392
|
+
ensureDiscoveryChains(sources);
|
|
2393
|
+
entry.fingerprint = discoveryFingerprint(sources);
|
|
2394
|
+
}
|
|
2395
|
+
return sources;
|
|
2396
|
+
}
|
|
2397
|
+
/** Clear process-local discovery snapshots, primarily for hosts that reload settings in place. */
|
|
2398
|
+
export function clearAgentDiscoveryCache() {
|
|
2399
|
+
agentDiscoveryCache.clear();
|
|
2400
|
+
}
|
|
2401
|
+
function ensureSettingsForScope(sources, scope, preferredModelProvider) {
|
|
2402
|
+
if (scope !== "project" && sources.userSettings === undefined) {
|
|
2403
|
+
if (sources.packageSubagentPaths.settingsErrors.user)
|
|
2404
|
+
throw sources.packageSubagentPaths.settingsErrors.user;
|
|
2405
|
+
sources.userSettings = selectProviderOverrides(readSubagentSettings(sources.userSettingsPath), preferredModelProvider);
|
|
2406
|
+
}
|
|
2407
|
+
if (scope !== "user" && sources.projectSettings === undefined) {
|
|
2408
|
+
if (sources.packageSubagentPaths.settingsErrors.project)
|
|
2409
|
+
throw sources.packageSubagentPaths.settingsErrors.project;
|
|
2410
|
+
sources.projectSettings = selectProviderOverrides(readSubagentSettings(sources.projectSettingsPath), preferredModelProvider);
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
function settingsForScope(sources, scope) {
|
|
2414
|
+
// Parse only settings that participate in this projection. The source cache
|
|
2415
|
+
// still retains both source trees, while malformed out-of-scope settings do
|
|
2416
|
+
// not make an otherwise valid scoped projection fail.
|
|
2417
|
+
ensureSettingsForScope(sources, scope, sources.preferredModelProvider);
|
|
2418
|
+
return {
|
|
2419
|
+
user: scope === "project" ? EMPTY_SUBAGENT_SETTINGS : sources.userSettings ?? EMPTY_SUBAGENT_SETTINGS,
|
|
2420
|
+
project: scope === "user" ? EMPTY_SUBAGENT_SETTINGS : sources.projectSettings ?? EMPTY_SUBAGENT_SETTINGS,
|
|
2421
|
+
};
|
|
2422
|
+
}
|
|
2423
|
+
function configuredAgentsForScope(sources, scope, settingsScope = scope) {
|
|
2424
|
+
const { user: userSettings, project: projectSettings } = settingsForScope(sources, settingsScope);
|
|
2425
|
+
const defaultProvider = resolveSubagentDefaultProvider(userSettings, projectSettings, sources.projectSettingsPath);
|
|
2426
|
+
const defaultModel = resolveSubagentDefaultModel(userSettings, projectSettings, sources.userSettingsPath, sources.projectSettingsPath, defaultProvider);
|
|
2427
|
+
const defaultThinking = resolveSubagentDefaultThinking(userSettings, projectSettings, sources.projectSettingsPath);
|
|
2428
|
+
const maxThinking = resolveSubagentMaxThinking(userSettings, projectSettings, sources.projectSettingsPath);
|
|
2429
|
+
const defaultExtensions = resolveSubagentDefaultExtensions(userSettings, projectSettings, sources.projectSettingsPath);
|
|
2430
|
+
const defaultSubagentOnlyExtensions = resolveSubagentDefaultSubagentOnlyExtensions(userSettings, projectSettings, sources.projectSettingsPath);
|
|
2431
|
+
const applyDefaults = (agents) => applySubagentDefaults(agents, defaultModel, defaultProvider, defaultThinking, defaultExtensions, defaultSubagentOnlyExtensions);
|
|
2432
|
+
const builtin = applyBuiltinOverrides(applyDefaults(sources.builtinLoaded.agents), userSettings, projectSettings, sources.userSettingsPath, sources.projectSettingsPath);
|
|
2433
|
+
const user = applyCustomAgentOverrides(applyDefaults(scope === "project" ? [] : sources.userLoaded.flatMap((loaded) => loaded.loaded.agents)), userSettings, projectSettings, sources.userSettingsPath, sources.projectSettingsPath);
|
|
2434
|
+
const projectMap = new Map();
|
|
2435
|
+
if (scope !== "user")
|
|
2436
|
+
for (const loaded of sources.projectLoaded)
|
|
2437
|
+
for (const agent of loaded.loaded.agents)
|
|
2438
|
+
projectMap.set(agent.name, agent);
|
|
2439
|
+
const project = applyCustomAgentOverrides(applyDefaults(Array.from(projectMap.values())), userSettings, projectSettings, sources.userSettingsPath, sources.projectSettingsPath);
|
|
2440
|
+
const packageMap = new Map();
|
|
2441
|
+
for (const loaded of sources.packageLoaded) {
|
|
2442
|
+
if (!loaded.packageEntry || !packageEntryIncluded(scope, loaded.packageEntry.scope))
|
|
2443
|
+
continue;
|
|
2444
|
+
for (const agent of loaded.loaded.agents)
|
|
2445
|
+
if (!packageMap.has(agent.name))
|
|
2446
|
+
packageMap.set(agent.name, agent);
|
|
2447
|
+
}
|
|
2448
|
+
const packageAgents = applyCustomAgentOverrides(applyDefaults(Array.from(packageMap.values())), userSettings, projectSettings, sources.userSettingsPath, sources.projectSettingsPath);
|
|
2449
|
+
return {
|
|
2450
|
+
builtin,
|
|
2451
|
+
package: packageAgents,
|
|
2452
|
+
user,
|
|
2453
|
+
project,
|
|
2454
|
+
userSettings,
|
|
2455
|
+
projectSettings,
|
|
2456
|
+
maxThinking,
|
|
2457
|
+
modelScope: projectSettings.modelScope ?? userSettings.modelScope,
|
|
2458
|
+
};
|
|
2459
|
+
}
|
|
2460
|
+
function discoveryDirectories(sources, scope) {
|
|
2461
|
+
const directories = [reportAgentDefinitionDirectory("builtin", BUILTIN_AGENTS_DIR, BUILTIN_AGENT_DEFINITION_INSPECTION)];
|
|
2462
|
+
if (scope !== "project")
|
|
2463
|
+
for (const directory of sources.userLoaded)
|
|
2464
|
+
directories.push(reportAgentDefinitionDirectory("user", directory.dir, directory.inspection));
|
|
2465
|
+
if (scope !== "user") {
|
|
2466
|
+
const reported = new Set();
|
|
2467
|
+
for (const dir of sources.projectCandidateDirs) {
|
|
2468
|
+
reported.add(path.resolve(dir));
|
|
2469
|
+
directories.push(reportAgentDefinitionDirectory("project", dir, sources.projectInspections.get(dir)));
|
|
2470
|
+
}
|
|
2471
|
+
for (const directory of sources.projectLoaded) {
|
|
2472
|
+
if (!reported.has(path.resolve(directory.dir)))
|
|
2473
|
+
directories.push(reportAgentDefinitionDirectory("project", directory.dir, directory.inspection));
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
for (const directory of sources.packageLoaded) {
|
|
2477
|
+
if (directory.packageEntry && packageEntryIncluded(scope, directory.packageEntry.scope))
|
|
2478
|
+
directories.push(reportAgentDefinitionDirectory("package", directory.dir, directory.inspection));
|
|
2479
|
+
}
|
|
2480
|
+
return directories;
|
|
2481
|
+
}
|
|
2482
|
+
function discoveryDiagnostics(sources, scope) {
|
|
2483
|
+
return [
|
|
2484
|
+
...sources.builtinLoaded.diagnostics,
|
|
2485
|
+
...(scope === "project" ? [] : sources.userLoaded.flatMap((loaded) => loaded.loaded.diagnostics)),
|
|
2486
|
+
...(scope === "user" ? [] : sources.projectLoaded.flatMap((loaded) => loaded.loaded.diagnostics)),
|
|
2487
|
+
...sources.packageLoaded
|
|
2488
|
+
.filter((loaded) => loaded.packageEntry && packageEntryIncluded(scope, loaded.packageEntry.scope))
|
|
2489
|
+
.flatMap((loaded) => loaded.loaded.diagnostics),
|
|
2490
|
+
];
|
|
2491
|
+
}
|
|
2492
|
+
function buildEffectiveDiscovery(sources, scope) {
|
|
2493
|
+
const configured = configuredAgentsForScope(sources, scope);
|
|
2494
|
+
const agents = applySubagentMaxThinking(mergeAgentsForScope(scope, configured.user, configured.project, configured.builtin, configured.package).filter((agent) => agent.disabled !== true), configured.maxThinking);
|
|
2495
|
+
return {
|
|
2496
|
+
agents,
|
|
2497
|
+
agentDiagnostics: discoveryDiagnostics(sources, scope),
|
|
2498
|
+
projectAgentsDir: sources.projectAgentsDir,
|
|
2499
|
+
cwd: sources.cwd,
|
|
2500
|
+
scope,
|
|
2501
|
+
directories: discoveryDirectories(sources, scope),
|
|
2502
|
+
...(configured.modelScope !== undefined ? { modelScope: configured.modelScope } : {}),
|
|
2503
|
+
...(configured.maxThinking !== undefined ? { maxThinking: configured.maxThinking } : {}),
|
|
2504
|
+
};
|
|
2505
|
+
}
|
|
2506
|
+
function buildAllDiscovery(sources, includeChains, settingsScope) {
|
|
2507
|
+
if (includeChains)
|
|
2508
|
+
ensureDiscoveryChains(sources);
|
|
2509
|
+
const configured = configuredAgentsForScope(sources, "both", settingsScope);
|
|
2510
|
+
const packageChainMap = new Map();
|
|
2511
|
+
const packageChainDiagnostics = [];
|
|
2512
|
+
for (const chain of sources.packageChainLoaded ?? []) {
|
|
2513
|
+
packageChainDiagnostics.push(...chain.loaded.diagnostics);
|
|
2514
|
+
for (const definition of chain.loaded.chains)
|
|
2515
|
+
if (!packageChainMap.has(definition.name))
|
|
2516
|
+
packageChainMap.set(definition.name, definition);
|
|
2517
|
+
}
|
|
2518
|
+
const projectChainMap = new Map();
|
|
2519
|
+
const projectChainDiagnostics = [];
|
|
2520
|
+
for (const chain of sources.projectChainLoaded ?? []) {
|
|
2521
|
+
projectChainDiagnostics.push(...chain.loaded.diagnostics);
|
|
2522
|
+
for (const definition of chain.loaded.chains)
|
|
2523
|
+
projectChainMap.set(definition.name, definition);
|
|
2524
|
+
}
|
|
2525
|
+
const chains = [
|
|
2526
|
+
...Array.from(packageChainMap.values()),
|
|
2527
|
+
...(sources.userChains?.chains ?? []),
|
|
2528
|
+
...Array.from(projectChainMap.values()),
|
|
2529
|
+
];
|
|
2530
|
+
return {
|
|
2531
|
+
builtin: applySubagentMaxThinking(configured.builtin, configured.maxThinking),
|
|
2532
|
+
package: applySubagentMaxThinking(configured.package, configured.maxThinking),
|
|
2533
|
+
user: applySubagentMaxThinking(configured.user, configured.maxThinking),
|
|
2534
|
+
project: applySubagentMaxThinking(configured.project, configured.maxThinking),
|
|
2535
|
+
agentDiagnostics: [
|
|
2536
|
+
...sources.builtinLoaded.diagnostics,
|
|
2537
|
+
...sources.userLoaded.flatMap((loaded) => loaded.loaded.diagnostics),
|
|
2538
|
+
...sources.packageLoaded.flatMap((loaded) => loaded.loaded.diagnostics),
|
|
2539
|
+
...sources.projectLoaded.flatMap((loaded) => loaded.loaded.diagnostics),
|
|
2540
|
+
],
|
|
2541
|
+
chains,
|
|
2542
|
+
chainDiagnostics: [...packageChainDiagnostics, ...(sources.userChains?.diagnostics ?? []), ...projectChainDiagnostics],
|
|
2543
|
+
userDir: sources.userDir,
|
|
2544
|
+
projectDir: sources.projectAgentsDir,
|
|
2545
|
+
userChainDir: sources.userChainDir,
|
|
2546
|
+
projectChainDir: sources.projectChainDir,
|
|
2547
|
+
userSettingsPath: sources.userSettingsPath,
|
|
2548
|
+
projectSettingsPath: sources.projectSettingsPath,
|
|
2549
|
+
...(configured.maxThinking !== undefined ? { maxThinking: configured.maxThinking } : {}),
|
|
2550
|
+
};
|
|
2551
|
+
}
|
|
2552
|
+
export function discoverAgentSnapshot(cwd, scope, preferredModelProvider, options = {}) {
|
|
2553
|
+
const includeChains = options.includeChains !== false;
|
|
2554
|
+
const sources = getAgentDiscoverySources(cwd, preferredModelProvider, includeChains);
|
|
2555
|
+
return { effective: buildEffectiveDiscovery(sources, scope), all: buildAllDiscovery(sources, includeChains, scope) };
|
|
2556
|
+
}
|
|
2557
|
+
function discoverAgentsUncached(cwd, scope, preferredModelProvider) {
|
|
2558
|
+
const effectiveCwd = path.resolve(cwd);
|
|
2559
|
+
const userDirOld = path.join(getAgentDir(), "agents");
|
|
2560
|
+
const userDirNew = path.join(os.homedir(), ".agents");
|
|
2561
|
+
const { readDirs: projectAgentDirs, candidateDirs: projectCandidateDirs, preferredDir: projectAgentsDir } = resolveNearestProjectAgentDirs(effectiveCwd);
|
|
2562
|
+
const userSettingsPath = getUserAgentSettingsPath();
|
|
2563
|
+
const projectSettingsPath = getProjectAgentSettingsPath(effectiveCwd);
|
|
2564
|
+
const userSettings = selectProviderOverrides(scope === "project" ? EMPTY_SUBAGENT_SETTINGS : readSubagentSettings(userSettingsPath), preferredModelProvider);
|
|
2565
|
+
const projectSettings = selectProviderOverrides(scope === "user" ? EMPTY_SUBAGENT_SETTINGS : readSubagentSettings(projectSettingsPath), preferredModelProvider);
|
|
2566
|
+
const defaultProvider = resolveSubagentDefaultProvider(userSettings, projectSettings, projectSettingsPath);
|
|
2567
|
+
const defaultModel = resolveSubagentDefaultModel(userSettings, projectSettings, userSettingsPath, projectSettingsPath, defaultProvider);
|
|
2568
|
+
const defaultThinking = resolveSubagentDefaultThinking(userSettings, projectSettings, projectSettingsPath);
|
|
2569
|
+
const maxThinking = resolveSubagentMaxThinking(userSettings, projectSettings, projectSettingsPath);
|
|
2570
|
+
const defaultExtensions = resolveSubagentDefaultExtensions(userSettings, projectSettings, projectSettingsPath);
|
|
2571
|
+
const defaultSubagentOnlyExtensions = resolveSubagentDefaultSubagentOnlyExtensions(userSettings, projectSettings, projectSettingsPath);
|
|
2572
|
+
const modelScope = projectSettings.modelScope ?? userSettings.modelScope;
|
|
2573
|
+
const packageSubagentPaths = collectPackageSubagentPaths(effectiveCwd, { includeUser: scope !== "project", includeProject: scope !== "user" });
|
|
2574
|
+
const isExcluded = agentExclusions(agentExclusionRoots(userSettingsPath, projectSettingsPath));
|
|
2575
|
+
const directories = [reportAgentDefinitionDirectory("builtin", BUILTIN_AGENTS_DIR, BUILTIN_AGENT_DEFINITION_INSPECTION)];
|
|
2576
|
+
const builtinLoaded = loadAgentsFromDefinitionFiles(BUILTIN_AGENT_DEFINITION_FILES, "builtin");
|
|
2577
|
+
const applyDefaults = (agents) => applySubagentDefaults(agents, defaultModel, defaultProvider, defaultThinking, defaultExtensions, defaultSubagentOnlyExtensions);
|
|
2578
|
+
const builtinAgents = applyBuiltinOverrides(applyDefaults(builtinLoaded.agents), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
|
|
2579
|
+
const userScanDirs = settingsAgentScanDirs(userSettings.agentScanDirs ?? [], isExcluded);
|
|
2580
|
+
const projectScanDirs = settingsAgentScanDirs(projectSettings.agentScanDirs ?? [], isExcluded);
|
|
2581
|
+
const userLoaded = scope === "project" ? [] : [...extraUserAgentDirs(), ...userScanDirs.dirs, userDirOld, userDirNew].filter((dir) => !isExcluded(dir)).map((dir, discoveryPriority) => {
|
|
2582
|
+
const inspection = inspectAgentDefinitionDirectory(dir, undefined, isExcluded);
|
|
2583
|
+
directories.push(reportAgentDefinitionDirectory("user", dir, inspection));
|
|
2584
|
+
return loadAgentsFromDir(dir, "user", discoveryPriority, undefined, inspection);
|
|
2585
|
+
});
|
|
2586
|
+
const userAgents = applyCustomAgentOverrides(applyDefaults(userLoaded.flatMap((loaded) => loaded.agents)), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
|
|
2587
|
+
const projectInspections = scope === "user" ? new Map() : new Map(projectCandidateDirs.filter((dir) => !isExcluded(dir)).map((dir) => [dir, inspectAgentDefinitionDirectory(dir, undefined, isExcluded)]));
|
|
2588
|
+
if (scope !== "user")
|
|
2589
|
+
for (const [dir, inspection] of projectInspections)
|
|
2590
|
+
directories.push(reportAgentDefinitionDirectory("project", dir, inspection));
|
|
2591
|
+
const projectLoaded = scope === "user" ? [] : [...projectScanDirs.dirs, ...projectAgentDirs].filter((dir) => !isExcluded(dir)).map((dir, discoveryPriority) => {
|
|
2592
|
+
const inspection = projectInspections.get(dir) ?? inspectAgentDefinitionDirectory(dir, undefined, isExcluded);
|
|
2593
|
+
if (!projectInspections.has(dir))
|
|
2594
|
+
directories.push(reportAgentDefinitionDirectory("project", dir, inspection));
|
|
2595
|
+
return loadAgentsFromDir(dir, "project", dir === projectAgentsDir ? 1 : discoveryPriority, undefined, inspection);
|
|
2596
|
+
});
|
|
2597
|
+
const projectAgents = applyCustomAgentOverrides(applyDefaults(projectLoaded.flatMap((loaded) => loaded.agents)), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
|
|
2598
|
+
const packageLoaded = packageSubagentPaths.agents.filter((entry) => !isExcluded(entry.dir)).map((entry, index) => {
|
|
2599
|
+
const inspection = inspectAgentDefinitionDirectory(entry.dir, undefined, isExcluded);
|
|
2600
|
+
directories.push(reportAgentDefinitionDirectory("package", entry.dir, inspection));
|
|
2601
|
+
return loadAgentsFromDir(entry.dir, "package", packageSubagentPaths.agents.length - index, entry, inspection);
|
|
2602
|
+
});
|
|
2603
|
+
const packageMap = new Map();
|
|
2604
|
+
for (const loaded of packageLoaded)
|
|
2605
|
+
for (const agent of loaded.agents)
|
|
2606
|
+
if (!packageMap.has(agent.name))
|
|
2607
|
+
packageMap.set(agent.name, agent);
|
|
2608
|
+
const packageAgents = applyCustomAgentOverrides(applyDefaults(Array.from(packageMap.values())), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
|
|
2609
|
+
const agents = applySubagentMaxThinking(mergeAgentsForScope(scope, userAgents, projectAgents, builtinAgents, packageAgents).filter((agent) => agent.disabled !== true), maxThinking);
|
|
2610
|
+
const agentDiagnostics = [...builtinLoaded.diagnostics, ...userLoaded.flatMap((loaded) => loaded.diagnostics), ...projectLoaded.flatMap((loaded) => loaded.diagnostics), ...packageLoaded.flatMap((loaded) => loaded.diagnostics)];
|
|
2611
|
+
return { agents, agentDiagnostics, projectAgentsDir, cwd: effectiveCwd, scope, directories, ...(modelScope !== undefined ? { modelScope } : {}), ...(maxThinking !== undefined ? { maxThinking } : {}) };
|
|
2612
|
+
}
|
|
2613
|
+
export function discoverAgents(cwd, scope, preferredModelProvider) {
|
|
2614
|
+
if (scope !== "both")
|
|
2615
|
+
return discoverAgentsUncached(cwd, scope, preferredModelProvider);
|
|
2616
|
+
const sources = getAgentDiscoverySources(cwd, preferredModelProvider);
|
|
2617
|
+
return buildEffectiveDiscovery(sources, scope);
|
|
2618
|
+
}
|
|
2619
|
+
export function discoverAgentsAll(cwd, preferredModelProvider) {
|
|
2620
|
+
return discoverAgentSnapshot(cwd, "both", preferredModelProvider).all;
|
|
2621
|
+
}
|
|
2622
|
+
//# sourceMappingURL=agents.js.map
|