@xzzpig/pi-subagents 0.22.0 → 0.24.1
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 +355 -0
- package/README.md +2 -2
- package/agents/evidence-auditor.md +1 -0
- package/agents/oracle.md +1 -0
- package/agents/reviewer.md +1 -0
- package/bundle/agent-management.js +16 -0
- package/bundle/agents.js +41 -0
- package/bundle/background-work.js +16 -0
- package/bundle/capability-ceiling.js +22 -0
- package/bundle/child-tool-plan.js +11 -0
- package/bundle/chunk-355ECEP2.js +1321 -0
- package/bundle/chunk-35GII5EF.js +637 -0
- package/bundle/chunk-3U633XDZ.js +749 -0
- package/bundle/chunk-4QFZZV3O.js +57 -0
- package/bundle/chunk-62OCY2S4.js +14 -0
- package/bundle/chunk-6BJUEES3.js +276 -0
- package/bundle/chunk-7J4ZXMY7.js +18 -0
- package/bundle/chunk-BGIYHF2W.js +138 -0
- package/bundle/chunk-CTPAE36Y.js +94 -0
- package/bundle/chunk-D4EHT5SJ.js +14 -0
- package/bundle/chunk-ED55MIC2.js +1681 -0
- package/bundle/chunk-EUPJB4S7.js +5503 -0
- package/bundle/chunk-FG6SQJAR.js +940 -0
- package/bundle/chunk-FJWI64H7.js +490 -0
- package/bundle/chunk-H36HBZB2.js +753 -0
- package/bundle/chunk-ICNYIALB.js +7347 -0
- package/bundle/chunk-JEA2ZKUA.js +1372 -0
- package/bundle/chunk-LCDJWBVM.js +57 -0
- package/bundle/chunk-LMGQAJ3O.js +9872 -0
- package/bundle/chunk-LVWU2HOO.js +1234 -0
- package/bundle/chunk-NIXWDZZV.js +9 -0
- package/bundle/chunk-QXASAHIA.js +173 -0
- package/bundle/chunk-RB4GELQA.js +458 -0
- package/bundle/chunk-RU522D5W.js +1768 -0
- package/bundle/chunk-SLNMBXLL.js +7336 -0
- package/bundle/chunk-SW2VMNIU.js +526 -0
- package/bundle/chunk-TGLFTQWJ.js +143 -0
- package/bundle/chunk-TMHVDPYW.js +4132 -0
- package/bundle/chunk-U4ODUYAG.js +235 -0
- package/bundle/chunk-UKG4V45O.js +228 -0
- package/bundle/chunk-UQDHXMUG.js +264 -0
- package/bundle/chunk-V2KFIGFH.js +8774 -0
- package/bundle/chunk-VO3G7HI3.js +85 -0
- package/bundle/chunk-WPW4V6HM.js +227 -0
- package/bundle/chunk-WW76JRIX.js +175 -0
- package/bundle/chunk-X6LOM3Z4.js +4175 -0
- package/bundle/chunk-XA3DY6UG.js +161 -0
- package/bundle/chunk-Y6H2G6KX.js +1310 -0
- package/bundle/chunk-YFCK7H2S.js +129 -0
- package/bundle/chunk-YYREO77V.js +137 -0
- package/bundle/chunk-Z6TFJ6BR.js +400 -0
- package/bundle/chunk-ZWXU5SPQ.js +16932 -0
- package/bundle/control-channel.js +11 -0
- package/bundle/delegation.js +14 -0
- package/bundle/external-job-provider.js +20 -0
- package/bundle/external-runs.js +21 -0
- package/bundle/index.js +30 -0
- package/bundle/inspectors.js +8 -0
- package/bundle/intercom-bridge.js +11 -0
- package/bundle/preflight.js +468 -0
- package/bundle/project-panes.js +28 -0
- package/bundle/required-child-extensions.js +6 -0
- package/bundle/shared-types.js +8 -0
- package/bundle/supervisor-routing.js +12 -0
- package/bundle/workflow-resources.js +7 -0
- package/docs/agents.md +42 -10
- package/docs/configuration.md +59 -14
- package/docs/extension-api.md +61 -9
- package/docs/goal-auto-continuation-gate.md +26 -0
- package/docs/missions.md +2 -0
- package/docs/observability.md +20 -5
- package/docs/standalone-background.md +8 -6
- package/docs/tool-reference.md +18 -5
- package/docs/workflows.md +25 -7
- package/index.d.ts +3 -0
- package/index.js +14 -0
- package/node_modules/@xzzpig/pi-components/package.json +1 -2
- package/package.json +107 -87
- package/skills/council-mode/SKILL.md +1 -4
- package/skills/pi-subagents/SKILL.md +130 -106
- package/skills/pi-subagents/references/orchestration.md +124 -0
- package/skills/pi-subagents/references/prompting-and-roles.md +96 -291
- package/src/agents/advertised-agent-prompt.d.ts +13 -0
- package/src/agents/advertised-agent-prompt.js +68 -0
- package/src/agents/agent-eject.d.ts +39 -0
- package/src/agents/agent-eject.js +263 -0
- package/src/agents/agent-management.d.ts +33 -0
- package/src/agents/agent-management.js +1541 -0
- package/src/agents/agent-memory.d.ts +48 -0
- package/src/agents/agent-memory.js +350 -0
- package/src/agents/agent-refinements.d.ts +99 -0
- package/src/agents/agent-refinements.js +568 -0
- package/src/agents/agent-scope.d.ts +3 -0
- package/src/agents/agent-scope.js +8 -0
- package/src/agents/agent-selection.d.ts +2 -0
- package/src/agents/agent-selection.js +22 -0
- package/src/agents/agent-serializer.d.ts +7 -0
- package/src/agents/agent-serializer.js +213 -0
- package/src/agents/agents.d.ts +352 -0
- package/src/agents/agents.js +2817 -0
- package/src/agents/builtin-names.d.ts +1 -0
- package/src/agents/builtin-names.js +16 -0
- package/src/agents/chain-serializer.d.ts +6 -0
- package/src/agents/chain-serializer.js +318 -0
- package/src/agents/frontmatter.d.ts +19 -0
- package/src/agents/frontmatter.js +166 -0
- package/src/agents/global-npm-root.d.ts +6 -0
- package/src/agents/global-npm-root.js +57 -0
- package/src/agents/identity.d.ts +7 -0
- package/src/agents/identity.js +29 -0
- package/src/agents/proactive-skills.d.ts +35 -0
- package/src/agents/proactive-skills.js +155 -0
- package/src/agents/runtime-agent-events.d.ts +26 -0
- package/src/agents/runtime-agent-events.js +52 -0
- package/src/agents/runtime-agent-registry.d.ts +66 -0
- package/src/agents/runtime-agent-registry.js +415 -0
- package/src/agents/runtime-discovery.d.ts +13 -0
- package/src/agents/runtime-discovery.js +27 -0
- package/src/agents/skills.d.ts +34 -0
- package/src/agents/skills.js +718 -0
- package/src/api/agent-management.d.ts +2 -0
- package/src/api/agent-management.js +2 -0
- package/src/api/agents.d.ts +6 -0
- package/src/api/agents.js +3 -0
- package/src/api/background-work.d.ts +41 -0
- package/src/api/background-work.js +171 -0
- package/src/api/capability-ceiling.d.ts +1 -0
- package/src/api/capability-ceiling.js +1 -0
- package/src/api/child-tool-plan.d.ts +1 -0
- package/src/api/child-tool-plan.js +1 -0
- package/src/api/control-channel.d.ts +1 -0
- package/src/api/control-channel.js +1 -0
- package/src/api/delegation.d.ts +132 -0
- package/src/api/delegation.js +8 -0
- package/src/api/external-job-provider.d.ts +57 -0
- package/src/api/external-job-provider.js +139 -0
- package/src/api/external-runs.d.ts +47 -0
- package/src/api/external-runs.js +245 -0
- package/src/api/inspectors.d.ts +20 -0
- package/src/api/inspectors.js +11 -0
- package/src/api/intercom-bridge.d.ts +1 -0
- package/src/api/intercom-bridge.js +1 -0
- package/src/api/preflight.d.ts +183 -0
- package/src/api/preflight.js +455 -0
- package/src/api/project-panes.d.ts +7 -0
- package/src/api/project-panes.js +7 -0
- package/src/api/required-child-extensions.d.ts +1 -0
- package/src/api/required-child-extensions.js +1 -0
- package/src/api/shared-types.d.ts +1 -0
- package/src/api/shared-types.js +1 -0
- package/src/api/supervisor-routing.d.ts +110 -0
- package/src/api/supervisor-routing.js +95 -0
- package/src/api/workflow-resources.d.ts +2 -0
- package/src/api/workflow-resources.js +1 -0
- package/src/extension/active-runs-prompt.d.ts +7 -0
- package/src/extension/active-runs-prompt.js +29 -0
- package/src/extension/config.d.ts +7 -0
- package/src/extension/config.js +290 -0
- package/src/extension/context-injection.d.ts +52 -0
- package/src/extension/context-injection.js +102 -0
- package/src/extension/control-notices.d.ts +18 -0
- package/src/extension/control-notices.js +29 -0
- package/src/extension/declaration-pinning.d.ts +18 -0
- package/src/extension/declaration-pinning.js +167 -0
- package/src/extension/doctor.d.ts +34 -0
- package/src/extension/doctor.js +236 -0
- package/src/extension/fanout-child.d.ts +6 -0
- package/src/extension/fanout-child.js +278 -0
- package/src/extension/herdr-pi-bridge.d.ts +16 -0
- package/src/extension/herdr-pi-bridge.js +261 -0
- package/src/extension/index.d.ts +18 -0
- package/src/extension/index.js +1300 -0
- package/src/extension/public-execution.d.ts +71 -0
- package/src/extension/public-execution.js +214 -0
- package/src/extension/reply-workflow-script.d.ts +11 -0
- package/src/extension/reply-workflow-script.js +71 -0
- package/src/extension/rpc.d.ts +84 -0
- package/src/extension/rpc.js +729 -0
- package/src/extension/schemas.d.ts +276 -0
- package/src/extension/schemas.js +311 -0
- package/src/extension/steering-notices.d.ts +14 -0
- package/src/extension/steering-notices.js +22 -0
- package/src/extension/subagent-guide.d.ts +4 -0
- package/src/extension/subagent-guide.js +114 -0
- package/src/extension/subagent-options.d.ts +7 -0
- package/src/extension/subagent-options.js +64 -0
- package/src/extension/tool-activation.d.ts +7 -0
- package/src/extension/tool-activation.js +185 -0
- package/src/extension/tool-description.d.ts +19 -0
- package/src/extension/tool-description.js +169 -0
- package/src/extension/tool-result.d.ts +9 -0
- package/src/extension/tool-result.js +16 -0
- package/src/extension/upgrade-notice.d.ts +6 -0
- package/src/extension/upgrade-notice.js +42 -0
- package/src/goal-auto-continue-gate.d.ts +17 -0
- package/src/goal-auto-continue-gate.js +61 -0
- package/src/goal-auto-continue-state.d.ts +22 -0
- package/src/goal-auto-continue-state.js +20 -0
- package/src/inspectors/actions.d.ts +24 -0
- package/src/inspectors/actions.js +182 -0
- package/src/inspectors/ghostty/actions.d.ts +11 -0
- package/src/inspectors/ghostty/actions.js +62 -0
- package/src/inspectors/ghostty/plugin.d.ts +7 -0
- package/src/inspectors/ghostty/plugin.js +23 -0
- package/src/inspectors/herdr/actions.d.ts +25 -0
- package/src/inspectors/herdr/actions.js +133 -0
- package/src/inspectors/herdr/client.d.ts +41 -0
- package/src/inspectors/herdr/client.js +129 -0
- package/src/inspectors/herdr/focus.d.ts +24 -0
- package/src/inspectors/herdr/focus.js +49 -0
- package/src/inspectors/herdr/plugin.d.ts +6 -0
- package/src/inspectors/herdr/plugin.js +14 -0
- package/src/inspectors/herdr/project-panes.d.ts +136 -0
- package/src/inspectors/herdr/project-panes.js +610 -0
- package/src/inspectors/inspector-runner.d.ts +23 -0
- package/src/inspectors/inspector-runner.js +161 -0
- package/src/inspectors/plugins.d.ts +8 -0
- package/src/inspectors/plugins.js +82 -0
- package/src/inspectors/session-roots-codec.d.ts +15 -0
- package/src/inspectors/session-roots-codec.js +32 -0
- package/src/inspectors/shell-command.d.ts +1 -0
- package/src/inspectors/shell-command.js +16 -0
- package/src/inspectors/tmux/actions.d.ts +25 -0
- package/src/inspectors/tmux/actions.js +181 -0
- package/src/inspectors/tmux/client.d.ts +27 -0
- package/src/inspectors/tmux/client.js +64 -0
- package/src/inspectors/tmux/plugin.d.ts +7 -0
- package/src/inspectors/tmux/plugin.js +14 -0
- package/src/inspectors/types.d.ts +48 -0
- package/src/inspectors/types.js +1 -0
- package/src/integrations/herdr-status.d.ts +47 -0
- package/src/integrations/herdr-status.js +350 -0
- package/src/integrations/pi-web-session-liveness.d.ts +19 -0
- package/src/integrations/pi-web-session-liveness.js +53 -0
- package/src/integrations/program-status.d.ts +30 -0
- package/src/integrations/program-status.js +188 -0
- package/src/intercom/fork-supervisor-routing.d.ts +90 -0
- package/src/intercom/fork-supervisor-routing.js +392 -0
- package/src/intercom/intercom-bridge.d.ts +58 -0
- package/src/intercom/intercom-bridge.js +193 -0
- package/src/intercom/native-supervisor-channel.d.ts +97 -0
- package/src/intercom/native-supervisor-channel.js +1184 -0
- package/src/intercom/result-intercom.d.ts +35 -0
- package/src/intercom/result-intercom.js +376 -0
- package/src/intercom/supervisor-ui.d.ts +29 -0
- package/src/intercom/supervisor-ui.js +49 -0
- package/src/missions/actions.d.ts +54 -0
- package/src/missions/actions.js +400 -0
- package/src/missions/goal-driver.d.ts +16 -0
- package/src/missions/goal-driver.js +171 -0
- package/src/missions/lifecycle.d.ts +50 -0
- package/src/missions/lifecycle.js +388 -0
- package/src/missions/store.d.ts +21 -0
- package/src/missions/store.js +605 -0
- package/src/missions/types.d.ts +169 -0
- package/src/missions/types.js +9 -0
- package/src/missions/workflow-state.d.ts +14 -0
- package/src/missions/workflow-state.js +273 -0
- package/src/policy/authority.d.ts +9 -0
- package/src/policy/authority.js +41 -0
- package/src/profiles/profiles.d.ts +134 -0
- package/src/profiles/profiles.js +526 -0
- package/src/runs/background/active-async-capacity.d.ts +115 -0
- package/src/runs/background/active-async-capacity.js +517 -0
- package/src/runs/background/active-run-index.d.ts +12 -0
- package/src/runs/background/active-run-index.js +157 -0
- package/src/runs/background/async-execution.d.ts +306 -0
- package/src/runs/background/async-execution.js +2210 -0
- package/src/runs/background/async-job-tracker.d.ts +37 -0
- package/src/runs/background/async-job-tracker.js +926 -0
- package/src/runs/background/async-resume.d.ts +60 -0
- package/src/runs/background/async-resume.js +707 -0
- package/src/runs/background/async-retention.d.ts +45 -0
- package/src/runs/background/async-retention.js +932 -0
- package/src/runs/background/async-status-snapshot.d.ts +9 -0
- package/src/runs/background/async-status-snapshot.js +26 -0
- package/src/runs/background/async-status.d.ts +179 -0
- package/src/runs/background/async-status.js +712 -0
- package/src/runs/background/auto-drain.d.ts +16 -0
- package/src/runs/background/auto-drain.js +71 -0
- package/src/runs/background/await-async-run.d.ts +26 -0
- package/src/runs/background/await-async-run.js +83 -0
- package/src/runs/background/binary-bootstrap.d.ts +8 -0
- package/src/runs/background/binary-bootstrap.js +69 -0
- package/src/runs/background/boot-id.d.ts +12 -0
- package/src/runs/background/boot-id.js +47 -0
- package/src/runs/background/calendar-schedule.d.ts +26 -0
- package/src/runs/background/calendar-schedule.js +93 -0
- package/src/runs/background/chain-append.d.ts +34 -0
- package/src/runs/background/chain-append.js +299 -0
- package/src/runs/background/chain-root-attachment.d.ts +51 -0
- package/src/runs/background/chain-root-attachment.js +186 -0
- package/src/runs/background/completion-batcher.d.ts +51 -0
- package/src/runs/background/completion-batcher.js +119 -0
- package/src/runs/background/completion-dedupe.d.ts +13 -0
- package/src/runs/background/completion-dedupe.js +48 -0
- package/src/runs/background/completion-replay.d.ts +47 -0
- package/src/runs/background/completion-replay.js +266 -0
- package/src/runs/background/control-channel.d.ts +170 -0
- package/src/runs/background/control-channel.js +610 -0
- package/src/runs/background/fleet-view.d.ts +63 -0
- package/src/runs/background/fleet-view.js +666 -0
- package/src/runs/background/index-segment.d.ts +16 -0
- package/src/runs/background/index-segment.js +58 -0
- package/src/runs/background/inspect-rpc.d.ts +64 -0
- package/src/runs/background/inspect-rpc.js +422 -0
- package/src/runs/background/interrupted-elsewhere.d.ts +22 -0
- package/src/runs/background/interrupted-elsewhere.js +68 -0
- package/src/runs/background/notify.d.ts +216 -0
- package/src/runs/background/notify.js +1006 -0
- package/src/runs/background/owned-process-tree.d.ts +10 -0
- package/src/runs/background/owned-process-tree.js +116 -0
- package/src/runs/background/parallel-groups.d.ts +3 -0
- package/src/runs/background/parallel-groups.js +46 -0
- package/src/runs/background/pid-namespace.d.ts +2 -0
- package/src/runs/background/pid-namespace.js +19 -0
- package/src/runs/background/process-terminal-candidate.d.ts +17 -0
- package/src/runs/background/process-terminal-candidate.js +96 -0
- package/src/runs/background/process-terminal.d.ts +21 -0
- package/src/runs/background/process-terminal.js +227 -0
- package/src/runs/background/result-delivery-ownership.d.ts +14 -0
- package/src/runs/background/result-delivery-ownership.js +38 -0
- package/src/runs/background/result-files.d.ts +63 -0
- package/src/runs/background/result-files.js +629 -0
- package/src/runs/background/result-watcher.d.ts +92 -0
- package/src/runs/background/result-watcher.js +819 -0
- package/src/runs/background/resume-guidance.d.ts +4 -0
- package/src/runs/background/resume-guidance.js +57 -0
- package/src/runs/background/retained-children.d.ts +24 -0
- package/src/runs/background/retained-children.js +128 -0
- package/src/runs/background/retained-nested-route-tracker.d.ts +12 -0
- package/src/runs/background/retained-nested-route-tracker.js +90 -0
- package/src/runs/background/run-child-session.d.ts +123 -0
- package/src/runs/background/run-child-session.js +670 -0
- package/src/runs/background/run-id-query.d.ts +3 -0
- package/src/runs/background/run-id-query.js +6 -0
- package/src/runs/background/run-id-resolver.d.ts +22 -0
- package/src/runs/background/run-id-resolver.js +172 -0
- package/src/runs/background/run-status.d.ts +25 -0
- package/src/runs/background/run-status.js +850 -0
- package/src/runs/background/runner-aliases.d.ts +17 -0
- package/src/runs/background/runner-aliases.js +191 -0
- package/src/runs/background/runner-child-launch.d.ts +24 -0
- package/src/runs/background/runner-child-launch.js +72 -0
- package/src/runs/background/runner-child-sessions.d.ts +6 -0
- package/src/runs/background/runner-child-sessions.js +34 -0
- package/src/runs/background/runner-http-dispatcher.d.ts +45 -0
- package/src/runs/background/runner-http-dispatcher.js +115 -0
- package/src/runs/background/runner-startup-failure.d.ts +13 -0
- package/src/runs/background/runner-startup-failure.js +46 -0
- package/src/runs/background/scheduled-runs.d.ts +127 -0
- package/src/runs/background/scheduled-runs.js +1265 -0
- package/src/runs/background/stale-run-reconciler.d.ts +62 -0
- package/src/runs/background/stale-run-reconciler.js +509 -0
- package/src/runs/background/steering.d.ts +51 -0
- package/src/runs/background/steering.js +246 -0
- package/src/runs/background/subagent-runner-bootstrap.d.ts +13 -0
- package/src/runs/background/subagent-runner-bootstrap.js +283 -0
- package/src/runs/background/subagent-runner.d.ts +210 -0
- package/src/runs/background/subagent-runner.js +4963 -0
- package/src/runs/background/subagent-wait.d.ts +124 -0
- package/src/runs/background/subagent-wait.js +756 -0
- package/src/runs/background/terminal-run-index.d.ts +10 -0
- package/src/runs/background/terminal-run-index.js +209 -0
- package/src/runs/background/top-level-async.d.ts +7 -0
- package/src/runs/background/top-level-async.js +5 -0
- package/src/runs/background/wait-completions.d.ts +28 -0
- package/src/runs/background/wait-completions.js +264 -0
- package/src/runs/background/wait-config.d.ts +8 -0
- package/src/runs/background/wait-config.js +46 -0
- package/src/runs/background/wait-subscriptions.d.ts +26 -0
- package/src/runs/background/wait-subscriptions.js +339 -0
- package/src/runs/background/wait-tool.d.ts +6 -0
- package/src/runs/background/wait-tool.js +48 -0
- package/src/runs/background/workflow-terminal-proof.d.ts +47 -0
- package/src/runs/background/workflow-terminal-proof.js +116 -0
- package/src/runs/foreground/async-dismiss-action.d.ts +6 -0
- package/src/runs/foreground/async-dismiss-action.js +82 -0
- package/src/runs/foreground/async-steering-action.d.ts +31 -0
- package/src/runs/foreground/async-steering-action.js +294 -0
- package/src/runs/foreground/async-stop-action.d.ts +13 -0
- package/src/runs/foreground/async-stop-action.js +213 -0
- package/src/runs/foreground/command-action.d.ts +12 -0
- package/src/runs/foreground/command-action.js +38 -0
- package/src/runs/foreground/execution.d.ts +10 -0
- package/src/runs/foreground/execution.js +2322 -0
- package/src/runs/foreground/foreground-control.d.ts +24 -0
- package/src/runs/foreground/foreground-control.js +138 -0
- package/src/runs/foreground/foreground-history.d.ts +25 -0
- package/src/runs/foreground/foreground-history.js +267 -0
- package/src/runs/foreground/prompt-audit.d.ts +32 -0
- package/src/runs/foreground/prompt-audit.js +138 -0
- package/src/runs/foreground/subagent-executor.d.ts +316 -0
- package/src/runs/foreground/subagent-executor.js +7990 -0
- package/src/runs/foreground/workflow-detach-reconcile.d.ts +15 -0
- package/src/runs/foreground/workflow-detach-reconcile.js +283 -0
- package/src/runs/foreground/workflow-foreground-steering.d.ts +43 -0
- package/src/runs/foreground/workflow-foreground-steering.js +148 -0
- package/src/runs/shared/abort-recovery.d.ts +26 -0
- package/src/runs/shared/abort-recovery.js +108 -0
- package/src/runs/shared/acceptance.d.ts +144 -0
- package/src/runs/shared/acceptance.js +1616 -0
- package/src/runs/shared/agent-contract.d.ts +5 -0
- package/src/runs/shared/agent-contract.js +35 -0
- package/src/runs/shared/async-status-projection.d.ts +100 -0
- package/src/runs/shared/async-status-projection.js +566 -0
- package/src/runs/shared/background-process-options.d.ts +4 -0
- package/src/runs/shared/background-process-options.js +6 -0
- package/src/runs/shared/capability-ceiling.d.ts +58 -0
- package/src/runs/shared/capability-ceiling.js +179 -0
- package/src/runs/shared/chain-outputs.d.ts +18 -0
- package/src/runs/shared/chain-outputs.js +104 -0
- package/src/runs/shared/child-commands.d.ts +29 -0
- package/src/runs/shared/child-commands.js +254 -0
- package/src/runs/shared/child-hooks.d.ts +31 -0
- package/src/runs/shared/child-hooks.js +173 -0
- package/src/runs/shared/child-identity.d.ts +23 -0
- package/src/runs/shared/child-identity.js +40 -0
- package/src/runs/shared/child-launch-plan.d.ts +70 -0
- package/src/runs/shared/child-launch-plan.js +88 -0
- package/src/runs/shared/child-launch.d.ts +128 -0
- package/src/runs/shared/child-launch.js +262 -0
- package/src/runs/shared/child-lifecycle.d.ts +13 -0
- package/src/runs/shared/child-lifecycle.js +22 -0
- package/src/runs/shared/child-runtime-config.d.ts +111 -0
- package/src/runs/shared/child-runtime-config.js +44 -0
- package/src/runs/shared/child-session.d.ts +178 -0
- package/src/runs/shared/child-session.js +726 -0
- package/src/runs/shared/child-tool-plan.d.ts +101 -0
- package/src/runs/shared/child-tool-plan.js +430 -0
- package/src/runs/shared/claude-code-adapter.d.ts +80 -0
- package/src/runs/shared/claude-code-adapter.js +255 -0
- package/src/runs/shared/codex-exec-adapter.d.ts +25 -0
- package/src/runs/shared/codex-exec-adapter.js +127 -0
- package/src/runs/shared/context-mode.d.ts +12 -0
- package/src/runs/shared/context-mode.js +38 -0
- package/src/runs/shared/cursor-agent-adapter.d.ts +26 -0
- package/src/runs/shared/cursor-agent-adapter.js +99 -0
- package/src/runs/shared/dynamic-fanout.d.ts +49 -0
- package/src/runs/shared/dynamic-fanout.js +273 -0
- package/src/runs/shared/effective-system-prompt.d.ts +17 -0
- package/src/runs/shared/effective-system-prompt.js +23 -0
- package/src/runs/shared/extension-bindings.d.ts +25 -0
- package/src/runs/shared/extension-bindings.js +96 -0
- package/src/runs/shared/external-cli-contract.d.ts +29 -0
- package/src/runs/shared/external-cli-contract.js +145 -0
- package/src/runs/shared/external-cli-preflight.d.ts +41 -0
- package/src/runs/shared/external-cli-preflight.js +159 -0
- package/src/runs/shared/external-cli-runner.d.ts +65 -0
- package/src/runs/shared/external-cli-runner.js +425 -0
- package/src/runs/shared/external-job-bridge.d.ts +24 -0
- package/src/runs/shared/external-job-bridge.js +486 -0
- package/src/runs/shared/external-job-runner.d.ts +44 -0
- package/src/runs/shared/external-job-runner.js +352 -0
- package/src/runs/shared/fast-mode-extension.d.ts +3 -0
- package/src/runs/shared/fast-mode-extension.js +8 -0
- package/src/runs/shared/fork-placed-env.d.ts +4 -0
- package/src/runs/shared/fork-placed-env.js +13 -0
- package/src/runs/shared/git-environment.d.ts +2 -0
- package/src/runs/shared/git-environment.js +27 -0
- package/src/runs/shared/herdr-connection.d.ts +79 -0
- package/src/runs/shared/herdr-connection.js +269 -0
- package/src/runs/shared/herdr-external-adapters.d.ts +148 -0
- package/src/runs/shared/herdr-external-adapters.js +404 -0
- package/src/runs/shared/herdr-machine.d.ts +59 -0
- package/src/runs/shared/herdr-machine.js +294 -0
- package/src/runs/shared/herdr-pane-host.d.ts +88 -0
- package/src/runs/shared/herdr-pane-host.js +155 -0
- package/src/runs/shared/herdr-pi-protocol.d.ts +21 -0
- package/src/runs/shared/herdr-pi-protocol.js +57 -0
- package/src/runs/shared/herdr-placed-run.d.ts +144 -0
- package/src/runs/shared/herdr-placed-run.js +380 -0
- package/src/runs/shared/host-step-status.d.ts +33 -0
- package/src/runs/shared/host-step-status.js +244 -0
- package/src/runs/shared/lane-metadata.d.ts +23 -0
- package/src/runs/shared/lane-metadata.js +126 -0
- package/src/runs/shared/launch-cwd.d.ts +1 -0
- package/src/runs/shared/launch-cwd.js +16 -0
- package/src/runs/shared/local-machine-access.d.ts +5 -0
- package/src/runs/shared/local-machine-access.js +28 -0
- package/src/runs/shared/long-running-guard.d.ts +34 -0
- package/src/runs/shared/long-running-guard.js +256 -0
- package/src/runs/shared/mcp-config-sources.d.ts +33 -0
- package/src/runs/shared/mcp-config-sources.js +418 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +86 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.js +477 -0
- package/src/runs/shared/mcp-direct-tool-grant.d.ts +42 -0
- package/src/runs/shared/mcp-direct-tool-grant.js +159 -0
- package/src/runs/shared/model-resolution-diagnostic.d.ts +44 -0
- package/src/runs/shared/model-resolution-diagnostic.js +116 -0
- package/src/runs/shared/model-resolution.d.ts +109 -0
- package/src/runs/shared/model-resolution.js +411 -0
- package/src/runs/shared/model-scope.d.ts +68 -0
- package/src/runs/shared/model-scope.js +171 -0
- package/src/runs/shared/mutation-evidence.d.ts +18 -0
- package/src/runs/shared/mutation-evidence.js +198 -0
- package/src/runs/shared/nested-events.d.ts +135 -0
- package/src/runs/shared/nested-events.js +1090 -0
- package/src/runs/shared/nested-path.d.ts +8 -0
- package/src/runs/shared/nested-path.js +34 -0
- package/src/runs/shared/nested-render.d.ts +20 -0
- package/src/runs/shared/nested-render.js +115 -0
- package/src/runs/shared/orca-progress-tabs.d.ts +31 -0
- package/src/runs/shared/orca-progress-tabs.js +503 -0
- package/src/runs/shared/parallel-handoff.d.ts +78 -0
- package/src/runs/shared/parallel-handoff.js +783 -0
- package/src/runs/shared/parallel-utils.d.ts +177 -0
- package/src/runs/shared/parallel-utils.js +125 -0
- package/src/runs/shared/partial-output.d.ts +24 -0
- package/src/runs/shared/partial-output.js +35 -0
- package/src/runs/shared/permissions.d.ts +12 -0
- package/src/runs/shared/permissions.js +92 -0
- package/src/runs/shared/pi-spawn.d.ts +31 -0
- package/src/runs/shared/pi-spawn.js +211 -0
- package/src/runs/shared/placed-run-owner.d.ts +49 -0
- package/src/runs/shared/placed-run-owner.js +93 -0
- package/src/runs/shared/placement-host.d.ts +99 -0
- package/src/runs/shared/placement-host.js +157 -0
- package/src/runs/shared/process-signal.d.ts +15 -0
- package/src/runs/shared/process-signal.js +21 -0
- package/src/runs/shared/profile-extensions.d.ts +21 -0
- package/src/runs/shared/profile-extensions.js +122 -0
- package/src/runs/shared/profile-launch-env.d.ts +26 -0
- package/src/runs/shared/profile-launch-env.js +90 -0
- package/src/runs/shared/readonly-drain-observation.d.ts +25 -0
- package/src/runs/shared/readonly-drain-observation.js +50 -0
- package/src/runs/shared/rex-machine.d.ts +25 -0
- package/src/runs/shared/rex-machine.js +83 -0
- package/src/runs/shared/rex-pane-host.d.ts +62 -0
- package/src/runs/shared/rex-pane-host.js +327 -0
- package/src/runs/shared/run-fanout-budget.d.ts +14 -0
- package/src/runs/shared/run-fanout-budget.js +258 -0
- package/src/runs/shared/run-ownership.d.ts +3 -0
- package/src/runs/shared/run-ownership.js +8 -0
- package/src/runs/shared/runner-launcher.d.ts +11 -0
- package/src/runs/shared/runner-launcher.js +24 -0
- package/src/runs/shared/runtime-acknowledged-extensions.d.ts +7 -0
- package/src/runs/shared/runtime-acknowledged-extensions.js +44 -0
- package/src/runs/shared/sandbox-profile-guard.d.ts +23 -0
- package/src/runs/shared/sandbox-profile-guard.js +106 -0
- package/src/runs/shared/sandbox-startup-diagnostics.d.ts +21 -0
- package/src/runs/shared/sandbox-startup-diagnostics.js +51 -0
- package/src/runs/shared/session-lease.d.ts +69 -0
- package/src/runs/shared/session-lease.js +250 -0
- package/src/runs/shared/single-output.d.ts +90 -0
- package/src/runs/shared/single-output.js +349 -0
- package/src/runs/shared/spawn-budget.d.ts +20 -0
- package/src/runs/shared/spawn-budget.js +93 -0
- package/src/runs/shared/structured-output.d.ts +66 -0
- package/src/runs/shared/structured-output.js +483 -0
- package/src/runs/shared/subagent-control.d.ts +50 -0
- package/src/runs/shared/subagent-control.js +247 -0
- package/src/runs/shared/subagent-prompt-runtime.d.ts +90 -0
- package/src/runs/shared/subagent-prompt-runtime.js +776 -0
- package/src/runs/shared/tool-availability.d.ts +16 -0
- package/src/runs/shared/tool-availability.js +29 -0
- package/src/runs/shared/tool-budget.d.ts +21 -0
- package/src/runs/shared/tool-budget.js +78 -0
- package/src/runs/shared/tool-timeout.d.ts +31 -0
- package/src/runs/shared/tool-timeout.js +73 -0
- package/src/runs/shared/usage-budget.d.ts +7 -0
- package/src/runs/shared/usage-budget.js +74 -0
- package/src/runs/shared/usage-reconciliation.d.ts +8 -0
- package/src/runs/shared/usage-reconciliation.js +71 -0
- package/src/runs/shared/workflow-async-child-guidance.d.ts +3 -0
- package/src/runs/shared/workflow-async-child-guidance.js +17 -0
- package/src/runs/shared/workflow-graph.d.ts +31 -0
- package/src/runs/shared/workflow-graph.js +221 -0
- package/src/runs/shared/worktree-cleanup-apply.d.ts +36 -0
- package/src/runs/shared/worktree-cleanup-apply.js +178 -0
- package/src/runs/shared/worktree-cleanup-plan.d.ts +84 -0
- package/src/runs/shared/worktree-cleanup-plan.js +803 -0
- package/src/runs/shared/worktree-lock.d.ts +5 -0
- package/src/runs/shared/worktree-lock.js +40 -0
- package/src/runs/shared/worktree-setup-command.d.ts +38 -0
- package/src/runs/shared/worktree-setup-command.js +200 -0
- package/src/runs/shared/worktree.d.ts +181 -0
- package/src/runs/shared/worktree.js +1346 -0
- package/src/shared/accessible-dir.d.ts +11 -0
- package/src/shared/accessible-dir.js +39 -0
- package/src/shared/agent-stream-options.d.ts +5 -0
- package/src/shared/agent-stream-options.js +3 -0
- package/src/shared/artifacts.d.ts +22 -0
- package/src/shared/artifacts.js +272 -0
- package/src/shared/atomic-json.d.ts +19 -0
- package/src/shared/atomic-json.js +61 -0
- package/src/shared/capacity-resilient-json.d.ts +26 -0
- package/src/shared/capacity-resilient-json.js +86 -0
- package/src/shared/child-cache-retention.d.ts +29 -0
- package/src/shared/child-cache-retention.js +40 -0
- package/src/shared/child-session-name.d.ts +8 -0
- package/src/shared/child-session-name.js +40 -0
- package/src/shared/child-transcript.d.ts +37 -0
- package/src/shared/child-transcript.js +225 -0
- package/src/shared/completion-owner.d.ts +7 -0
- package/src/shared/completion-owner.js +13 -0
- package/src/shared/disabled-features.d.ts +93 -0
- package/src/shared/disabled-features.js +120 -0
- package/src/shared/display-text.d.ts +5 -0
- package/src/shared/display-text.js +154 -0
- package/src/shared/edit-distance.d.ts +4 -0
- package/src/shared/edit-distance.js +32 -0
- package/src/shared/extension-context.d.ts +21 -0
- package/src/shared/extension-context.js +39 -0
- package/src/shared/file-coalescer.d.ts +11 -0
- package/src/shared/file-coalescer.js +34 -0
- package/src/shared/file-lease.d.ts +10 -0
- package/src/shared/file-lease.js +106 -0
- package/src/shared/file-system-retry.d.ts +31 -0
- package/src/shared/file-system-retry.js +84 -0
- package/src/shared/fork-context.d.ts +64 -0
- package/src/shared/fork-context.js +185 -0
- package/src/shared/fork-session-cwd.d.ts +2 -0
- package/src/shared/fork-session-cwd.js +23 -0
- package/src/shared/formatters.d.ts +35 -0
- package/src/shared/formatters.js +137 -0
- package/src/shared/jsonl-writer.d.ts +20 -0
- package/src/shared/jsonl-writer.js +67 -0
- package/src/shared/launch-contract.d.ts +65 -0
- package/src/shared/launch-contract.js +145 -0
- package/src/shared/model-info.d.ts +55 -0
- package/src/shared/model-info.js +103 -0
- package/src/shared/model-response-aliases.d.ts +1 -0
- package/src/shared/model-response-aliases.js +15 -0
- package/src/shared/node-executable.d.ts +1 -0
- package/src/shared/node-executable.js +20 -0
- package/src/shared/opencode-session-headers.d.ts +12 -0
- package/src/shared/opencode-session-headers.js +26 -0
- package/src/shared/package-version.d.ts +2 -0
- package/src/shared/package-version.js +14 -0
- package/src/shared/parent-wake.d.ts +26 -0
- package/src/shared/parent-wake.js +68 -0
- package/src/shared/permission-profile.d.ts +26 -0
- package/src/shared/permission-profile.js +49 -0
- package/src/shared/prompt-resources.d.ts +5 -0
- package/src/shared/prompt-resources.js +10 -0
- package/src/shared/provider-diagnostics.d.ts +9 -0
- package/src/shared/provider-diagnostics.js +75 -0
- package/src/shared/pruned-fork.d.ts +34 -0
- package/src/shared/pruned-fork.js +434 -0
- package/src/shared/required-child-extensions.d.ts +34 -0
- package/src/shared/required-child-extensions.js +105 -0
- package/src/shared/runtime-module-path.d.ts +10 -0
- package/src/shared/runtime-module-path.js +16 -0
- package/src/shared/sandbox-profile.d.ts +12 -0
- package/src/shared/sandbox-profile.js +35 -0
- package/src/shared/session-file-trust.d.ts +1 -0
- package/src/shared/session-file-trust.js +20 -0
- package/src/shared/session-identity.d.ts +8 -0
- package/src/shared/session-identity.js +32 -0
- package/src/shared/session-succession.d.ts +4 -0
- package/src/shared/session-succession.js +24 -0
- package/src/shared/session-tokens.d.ts +2 -0
- package/src/shared/session-tokens.js +58 -0
- package/src/shared/settings-file-lease.d.ts +4 -0
- package/src/shared/settings-file-lease.js +38 -0
- package/src/shared/settings.d.ts +146 -0
- package/src/shared/settings.js +247 -0
- package/src/shared/shortcuts.d.ts +1 -0
- package/src/shared/shortcuts.js +17 -0
- package/src/shared/status-format.d.ts +9 -0
- package/src/shared/status-format.js +60 -0
- package/src/shared/thinking-ceiling.d.ts +13 -0
- package/src/shared/thinking-ceiling.js +37 -0
- package/src/shared/types.d.ts +2842 -0
- package/src/shared/types.js +276 -0
- package/src/shared/utf8.d.ts +5 -0
- package/src/shared/utf8.js +12 -0
- package/src/shared/utils.d.ts +83 -0
- package/src/shared/utils.js +612 -0
- package/src/shared/watch-strategy.d.ts +2 -0
- package/src/shared/watch-strategy.js +5 -0
- package/src/shared/workflow-child-permit.d.ts +58 -0
- package/src/shared/workflow-child-permit.js +159 -0
- package/src/slash/delegation-adapters.d.ts +154 -0
- package/src/slash/delegation-adapters.js +316 -0
- package/src/slash/delegation-json.d.ts +10 -0
- package/src/slash/delegation-json.js +117 -0
- package/src/slash/delegation-request.d.ts +12 -0
- package/src/slash/delegation-request.js +174 -0
- package/src/slash/prompt-template-bridge.d.ts +29 -0
- package/src/slash/prompt-template-bridge.js +399 -0
- package/src/slash/prompt-workflows.d.ts +21 -0
- package/src/slash/prompt-workflows.js +274 -0
- package/src/slash/selector.d.ts +47 -0
- package/src/slash/selector.js +117 -0
- package/src/slash/slash-bridge.d.ts +30 -0
- package/src/slash/slash-bridge.js +132 -0
- package/src/slash/slash-commands.d.ts +10 -0
- package/src/slash/slash-commands.js +1059 -0
- package/src/slash/slash-live-state.d.ts +21 -0
- package/src/slash/slash-live-state.js +263 -0
- package/src/slash/subagent-cost.d.ts +29 -0
- package/src/slash/subagent-cost.js +310 -0
- package/src/slash/subagents-admin.d.ts +3 -0
- package/src/slash/subagents-admin.js +481 -0
- package/src/tui/fleet-layout.d.ts +20 -0
- package/src/tui/fleet-layout.js +17 -0
- package/src/tui/fleet-native-transcript.d.ts +53 -0
- package/src/tui/fleet-native-transcript.js +339 -0
- package/src/tui/fleet-status.d.ts +92 -0
- package/src/tui/fleet-status.js +1132 -0
- package/src/tui/fleet-transcript.d.ts +64 -0
- package/src/tui/fleet-transcript.js +544 -0
- package/src/tui/fleet-viewport.d.ts +12 -0
- package/src/tui/fleet-viewport.js +35 -0
- package/src/tui/fleet.d.ts +196 -0
- package/src/tui/fleet.js +1588 -0
- package/src/tui/mouse-events.d.ts +21 -0
- package/src/tui/mouse-events.js +26 -0
- package/src/tui/render-helpers.d.ts +23 -0
- package/src/tui/render-helpers.js +100 -0
- package/src/tui/render.d.ts +66 -0
- package/src/tui/render.js +3707 -0
- package/src/tui/running-tone.d.ts +10 -0
- package/src/tui/running-tone.js +22 -0
- package/src/tui/subagent-messages.d.ts +22 -0
- package/src/tui/subagent-messages.js +270 -0
- package/src/ui-silent-marker.d.ts +20 -0
- package/src/ui-silent-marker.js +25 -0
- package/src/watchdog/change-signature.d.ts +7 -0
- package/src/watchdog/change-signature.js +243 -0
- package/src/watchdog/child-status.d.ts +53 -0
- package/src/watchdog/child-status.js +187 -0
- package/src/watchdog/diff-tool.d.ts +25 -0
- package/src/watchdog/diff-tool.js +104 -0
- package/src/watchdog/emission-guard.d.ts +36 -0
- package/src/watchdog/emission-guard.js +97 -0
- package/src/watchdog/guidance.d.ts +3 -0
- package/src/watchdog/guidance.js +19 -0
- package/src/watchdog/lsp-diagnostics.d.ts +17 -0
- package/src/watchdog/lsp-diagnostics.js +489 -0
- package/src/watchdog/model-selection.d.ts +24 -0
- package/src/watchdog/model-selection.js +167 -0
- package/src/watchdog/permission-arbiter.d.ts +20 -0
- package/src/watchdog/permission-arbiter.js +135 -0
- package/src/watchdog/register-child.d.ts +13 -0
- package/src/watchdog/register-child.js +128 -0
- package/src/watchdog/register-main.d.ts +11 -0
- package/src/watchdog/register-main.js +400 -0
- package/src/watchdog/render.d.ts +3 -0
- package/src/watchdog/render.js +33 -0
- package/src/watchdog/review.d.ts +36 -0
- package/src/watchdog/review.js +319 -0
- package/src/watchdog/rules.d.ts +21 -0
- package/src/watchdog/rules.js +58 -0
- package/src/watchdog/runtime.d.ts +195 -0
- package/src/watchdog/runtime.js +864 -0
- package/src/watchdog/scope.d.ts +14 -0
- package/src/watchdog/scope.js +44 -0
- package/src/watchdog/settings.d.ts +29 -0
- package/src/watchdog/settings.js +480 -0
- package/src/watchdog/tool-actions.d.ts +17 -0
- package/src/watchdog/tool-actions.js +150 -0
- package/src/watchdog/turn-delta.d.ts +15 -0
- package/src/watchdog/turn-delta.js +188 -0
- package/src/watchdog/types.d.ts +141 -0
- package/src/watchdog/types.js +27 -0
- package/src/watchdog/warning-format.d.ts +7 -0
- package/src/watchdog/warning-format.js +59 -0
- package/src/workflows/chat-progress.d.ts +37 -0
- package/src/workflows/chat-progress.js +129 -0
- package/src/workflows/host-command.d.ts +30 -0
- package/src/workflows/host-command.js +227 -0
- package/src/workflows/scripted-workflow.d.ts +204 -0
- package/src/workflows/scripted-workflow.js +1673 -0
- package/src/workflows/structured-workflow-scripts.d.ts +10 -0
- package/src/workflows/structured-workflow-scripts.js +179 -0
- package/src/workflows/workflow-auto-resume.d.ts +32 -0
- package/src/workflows/workflow-auto-resume.js +102 -0
- package/src/workflows/workflow-checklist.d.ts +127 -0
- package/src/workflows/workflow-checklist.js +314 -0
- package/src/workflows/workflow-child-summary.d.ts +24 -0
- package/src/workflows/workflow-child-summary.js +195 -0
- package/src/workflows/workflow-launch-record.d.ts +27 -0
- package/src/workflows/workflow-launch-record.js +48 -0
- package/src/workflows/workflow-preflight.d.ts +58 -0
- package/src/workflows/workflow-preflight.js +288 -0
- package/src/workflows/workflow-receipt.d.ts +34 -0
- package/src/workflows/workflow-receipt.js +454 -0
- package/src/workflows/workflow-resources.d.ts +55 -0
- package/src/workflows/workflow-resources.js +271 -0
- package/src/workflows/workflow-resume-claim.d.ts +82 -0
- package/src/workflows/workflow-resume-claim.js +210 -0
- package/src/workflows/workflow-resume.d.ts +56 -0
- package/src/workflows/workflow-resume.js +106 -0
- package/src/workflows/workflow-reuse.d.ts +61 -0
- package/src/workflows/workflow-reuse.js +186 -0
- package/src/workflows/workflow-revival.d.ts +33 -0
- package/src/workflows/workflow-revival.js +111 -0
- package/src/workflows/workflow-settlement.d.ts +84 -0
- package/src/workflows/workflow-settlement.js +203 -0
- package/src/workflows/workflow-stop-cause.d.ts +6 -0
- package/src/workflows/workflow-stop-cause.js +8 -0
- package/workflow-script-worker.cjs +1342 -0
- package/index.ts +0 -18
- package/node_modules/@xzzpig/pi-components/src/transcript.ts +0 -1878
- package/skills/pi-subagents/references/constraints-and-recipes.md +0 -74
- package/skills/pi-subagents/references/execution-controls.md +0 -561
- package/skills/pi-subagents/references/management-authoring-rpc.md +0 -165
- package/skills/pi-subagents/references/multi-lane-orchestration.md +0 -61
- package/skills/pi-subagents/references/review-and-validation.md +0 -73
- package/src/agents/advertised-agent-prompt.ts +0 -82
- package/src/agents/agent-eject.ts +0 -339
- package/src/agents/agent-management.ts +0 -1442
- package/src/agents/agent-memory.ts +0 -341
- package/src/agents/agent-refinements.ts +0 -624
- package/src/agents/agent-scope.ts +0 -10
- package/src/agents/agent-selection.ts +0 -25
- package/src/agents/agent-serializer.ts +0 -195
- package/src/agents/agents.ts +0 -3169
- 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/global-npm-root.ts +0 -58
- package/src/agents/identity.ts +0 -30
- package/src/agents/proactive-skills.ts +0 -197
- package/src/agents/runtime-agent-events.ts +0 -70
- package/src/agents/runtime-agent-registry.ts +0 -457
- package/src/agents/runtime-discovery.ts +0 -39
- package/src/agents/skills.ts +0 -787
- package/src/api/agent-management.ts +0 -9
- package/src/api/agents.ts +0 -19
- 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 -131
- package/src/api/external-job-provider.ts +0 -195
- package/src/api/external-runs.ts +0 -282
- package/src/api/inspectors.ts +0 -27
- package/src/api/intercom-bridge.ts +0 -3
- package/src/api/preflight.ts +0 -641
- 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/supervisor-routing.ts +0 -196
- package/src/api/workflow-resources.ts +0 -6
- package/src/extension/config.ts +0 -262
- package/src/extension/context-injection.ts +0 -123
- package/src/extension/control-notices.ts +0 -53
- package/src/extension/declaration-pinning.ts +0 -164
- package/src/extension/doctor.ts +0 -284
- package/src/extension/fanout-child.ts +0 -282
- package/src/extension/herdr-pi-bridge.ts +0 -166
- package/src/extension/index.ts +0 -1212
- package/src/extension/public-execution.ts +0 -262
- package/src/extension/reply-workflow-script.ts +0 -67
- package/src/extension/rpc.ts +0 -881
- package/src/extension/schemas.ts +0 -337
- package/src/extension/steering-notices.ts +0 -35
- package/src/extension/subagent-guide.ts +0 -127
- package/src/extension/subagent-options.ts +0 -47
- package/src/extension/tool-activation.ts +0 -147
- package/src/extension/tool-description.ts +0 -193
- package/src/extension/tool-result.ts +0 -19
- package/src/extension/upgrade-notice.ts +0 -40
- package/src/inspectors/actions.ts +0 -174
- 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 -733
- package/src/inspectors/inspector-runner.ts +0 -153
- package/src/inspectors/plugins.ts +0 -76
- package/src/inspectors/session-roots-codec.ts +0 -31
- package/src/inspectors/shell-command.ts +0 -16
- package/src/inspectors/tmux/actions.ts +0 -204
- package/src/inspectors/tmux/client.ts +0 -85
- package/src/inspectors/tmux/plugin.ts +0 -21
- package/src/inspectors/types.ts +0 -51
- package/src/integrations/herdr-status.ts +0 -385
- package/src/integrations/pi-web-session-liveness.ts +0 -73
- package/src/integrations/program-status.ts +0 -215
- package/src/intercom/fork-supervisor-routing.ts +0 -533
- package/src/intercom/intercom-bridge.ts +0 -235
- package/src/intercom/native-supervisor-channel.ts +0 -1066
- package/src/intercom/result-intercom.ts +0 -433
- package/src/intercom/supervisor-ui.ts +0 -72
- package/src/missions/actions.ts +0 -433
- package/src/missions/goal-driver.ts +0 -177
- package/src/missions/lifecycle.ts +0 -367
- package/src/missions/store.ts +0 -613
- 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 -674
- package/src/runs/background/active-async-capacity.ts +0 -548
- package/src/runs/background/active-run-index.ts +0 -155
- package/src/runs/background/async-execution.ts +0 -2479
- package/src/runs/background/async-job-tracker.ts +0 -869
- package/src/runs/background/async-resume.ts +0 -686
- package/src/runs/background/async-retention.ts +0 -953
- package/src/runs/background/async-status-snapshot.ts +0 -46
- package/src/runs/background/async-status.ts +0 -787
- package/src/runs/background/auto-drain.ts +0 -92
- package/src/runs/background/await-async-run.ts +0 -83
- package/src/runs/background/binary-bootstrap.ts +0 -67
- package/src/runs/background/calendar-schedule.ts +0 -90
- package/src/runs/background/chain-append.ts +0 -321
- package/src/runs/background/chain-root-attachment.ts +0 -263
- 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 -659
- package/src/runs/background/fleet-view.ts +0 -692
- 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 -1083
- package/src/runs/background/owned-process-tree.ts +0 -131
- package/src/runs/background/parallel-groups.ts +0 -45
- package/src/runs/background/pid-namespace.ts +0 -18
- package/src/runs/background/process-terminal-candidate.ts +0 -98
- package/src/runs/background/process-terminal.ts +0 -231
- package/src/runs/background/result-delivery-ownership.ts +0 -45
- package/src/runs/background/result-files.ts +0 -634
- package/src/runs/background/result-watcher.ts +0 -842
- package/src/runs/background/resume-guidance.ts +0 -56
- package/src/runs/background/retained-children.ts +0 -136
- package/src/runs/background/retained-nested-route-tracker.ts +0 -96
- package/src/runs/background/run-child-session.ts +0 -725
- package/src/runs/background/run-id-query.ts +0 -7
- package/src/runs/background/run-id-resolver.ts +0 -183
- package/src/runs/background/run-status.ts +0 -803
- package/src/runs/background/runner-aliases.ts +0 -183
- package/src/runs/background/runner-child-launch.ts +0 -96
- package/src/runs/background/runner-child-sessions.ts +0 -32
- package/src/runs/background/runner-http-dispatcher.ts +0 -122
- package/src/runs/background/runner-startup-failure.ts +0 -56
- package/src/runs/background/scheduled-runs.ts +0 -1222
- package/src/runs/background/stale-run-reconciler.ts +0 -463
- package/src/runs/background/steering.ts +0 -260
- package/src/runs/background/subagent-runner-bootstrap.ts +0 -279
- package/src/runs/background/subagent-runner.ts +0 -5251
- package/src/runs/background/subagent-wait.ts +0 -895
- package/src/runs/background/terminal-run-index.ts +0 -183
- package/src/runs/background/top-level-async.ts +0 -14
- package/src/runs/background/wait-completions.ts +0 -262
- 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 -57
- package/src/runs/background/workflow-terminal-proof.ts +0 -85
- 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 -216
- package/src/runs/foreground/command-action.ts +0 -41
- package/src/runs/foreground/execution.ts +0 -2315
- package/src/runs/foreground/foreground-control.ts +0 -157
- package/src/runs/foreground/foreground-history.ts +0 -164
- package/src/runs/foreground/prompt-audit.ts +0 -172
- package/src/runs/foreground/subagent-executor.ts +0 -8252
- 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 -1664
- package/src/runs/shared/agent-contract.ts +0 -38
- package/src/runs/shared/async-status-projection.ts +0 -664
- package/src/runs/shared/background-process-options.ts +0 -9
- package/src/runs/shared/capability-ceiling.ts +0 -214
- package/src/runs/shared/chain-outputs.ts +0 -116
- package/src/runs/shared/child-commands.ts +0 -229
- package/src/runs/shared/child-hooks.ts +0 -175
- 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 -389
- package/src/runs/shared/child-lifecycle.ts +0 -28
- package/src/runs/shared/child-runtime-config.ts +0 -136
- package/src/runs/shared/child-session.ts +0 -699
- package/src/runs/shared/child-tool-plan.ts +0 -599
- package/src/runs/shared/claude-code-adapter.ts +0 -288
- package/src/runs/shared/codex-exec-adapter.ts +0 -129
- 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 -103
- package/src/runs/shared/external-cli-contract.ts +0 -177
- package/src/runs/shared/external-cli-preflight.ts +0 -190
- package/src/runs/shared/external-cli-runner.ts +0 -437
- package/src/runs/shared/external-job-bridge.ts +0 -514
- package/src/runs/shared/external-job-runner.ts +0 -389
- package/src/runs/shared/fast-mode-extension.ts +0 -10
- package/src/runs/shared/fork-command-result.ts +0 -10
- package/src/runs/shared/git-environment.ts +0 -29
- 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 -264
- 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/long-running-guard.ts +0 -221
- package/src/runs/shared/mcp-config-sources.ts +0 -426
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +0 -579
- package/src/runs/shared/mcp-direct-tool-grant.ts +0 -210
- package/src/runs/shared/model-resolution-diagnostic.ts +0 -101
- package/src/runs/shared/model-resolution.ts +0 -503
- package/src/runs/shared/model-scope.ts +0 -224
- package/src/runs/shared/mutation-evidence.ts +0 -199
- package/src/runs/shared/nested-events.ts +0 -1125
- 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 -511
- package/src/runs/shared/parallel-handoff.ts +0 -789
- package/src/runs/shared/parallel-utils.ts +0 -292
- package/src/runs/shared/partial-output.ts +0 -48
- package/src/runs/shared/permissions.ts +0 -86
- package/src/runs/shared/pi-spawn.ts +0 -205
- package/src/runs/shared/process-signal.ts +0 -35
- package/src/runs/shared/profile-extensions.ts +0 -134
- package/src/runs/shared/profile-launch-env.ts +0 -121
- 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 -288
- package/src/runs/shared/runner-launcher.ts +0 -25
- package/src/runs/shared/runtime-acknowledged-extensions.ts +0 -44
- package/src/runs/shared/sandbox-profile-guard.ts +0 -119
- package/src/runs/shared/sandbox-startup-diagnostics.ts +0 -54
- package/src/runs/shared/session-lease.ts +0 -293
- package/src/runs/shared/single-output.ts +0 -366
- package/src/runs/shared/spawn-budget.ts +0 -128
- package/src/runs/shared/structured-output.ts +0 -463
- package/src/runs/shared/subagent-control.ts +0 -295
- package/src/runs/shared/subagent-prompt-runtime.ts +0 -598
- package/src/runs/shared/tool-availability.ts +0 -37
- package/src/runs/shared/tool-budget.ts +0 -87
- package/src/runs/shared/tool-timeout.ts +0 -93
- package/src/runs/shared/usage-budget.ts +0 -65
- package/src/runs/shared/usage-reconciliation.ts +0 -73
- 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-apply.ts +0 -160
- package/src/runs/shared/worktree-cleanup-plan.ts +0 -891
- package/src/runs/shared/worktree-lock.ts +0 -29
- package/src/runs/shared/worktree-setup-command.ts +0 -213
- package/src/runs/shared/worktree.ts +0 -1554
- 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 -85
- 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 -48
- package/src/shared/child-transcript.ts +0 -264
- package/src/shared/completion-owner.ts +0 -14
- package/src/shared/disabled-features.ts +0 -123
- package/src/shared/display-text.ts +0 -150
- package/src/shared/edit-distance.ts +0 -33
- package/src/shared/extension-context.ts +0 -37
- package/src/shared/file-coalescer.ts +0 -49
- package/src/shared/file-lease.ts +0 -74
- package/src/shared/file-system-retry.ts +0 -95
- package/src/shared/fork-context.ts +0 -243
- package/src/shared/fork-session-cwd.ts +0 -27
- package/src/shared/formatters.ts +0 -142
- package/src/shared/jsonl-writer.ts +0 -92
- package/src/shared/launch-contract.ts +0 -206
- package/src/shared/model-info.ts +0 -132
- 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/package-version.ts +0 -17
- package/src/shared/parent-wake.ts +0 -79
- package/src/shared/permission-profile.ts +0 -56
- package/src/shared/prompt-resources.ts +0 -11
- package/src/shared/pruned-fork.ts +0 -469
- package/src/shared/required-child-extensions.ts +0 -115
- package/src/shared/runtime-module-path.ts +0 -19
- package/src/shared/sandbox-profile.ts +0 -37
- 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-file-lease.ts +0 -36
- 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 -3105
- package/src/shared/utf8.ts +0 -11
- package/src/shared/utils.ts +0 -610
- package/src/shared/watch-strategy.ts +0 -12
- package/src/shared/workflow-child-permit.ts +0 -212
- package/src/slash/delegation-adapters.ts +0 -452
- package/src/slash/delegation-json.ts +0 -108
- package/src/slash/delegation-request.ts +0 -176
- package/src/slash/prompt-template-bridge.ts +0 -435
- package/src/slash/prompt-workflows.ts +0 -298
- package/src/slash/selector.ts +0 -147
- package/src/slash/slash-bridge.ts +0 -192
- package/src/slash/slash-commands.ts +0 -1096
- package/src/slash/slash-live-state.ts +0 -310
- package/src/slash/subagent-cost.ts +0 -317
- package/src/slash/subagents-admin.ts +0 -489
- package/src/tui/fleet-native-transcript.ts +0 -424
- package/src/tui/fleet-status.ts +0 -1139
- package/src/tui/fleet-transcript.ts +0 -591
- package/src/tui/fleet.ts +0 -1618
- package/src/tui/mouse-events.ts +0 -42
- package/src/tui/render-helpers.ts +0 -111
- package/src/tui/render.ts +0 -3824
- package/src/tui/running-tone.ts +0 -28
- package/src/tui/subagent-messages.ts +0 -305
- package/src/ui-silent-marker.ts +0 -32
- package/src/watchdog/change-signature.ts +0 -260
- package/src/watchdog/child-status.ts +0 -225
- package/src/watchdog/diff-tool.ts +0 -112
- 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 -154
- package/src/watchdog/register-child.ts +0 -136
- package/src/watchdog/register-main.ts +0 -425
- package/src/watchdog/render.ts +0 -31
- package/src/watchdog/review.ts +0 -362
- package/src/watchdog/rules.ts +0 -70
- package/src/watchdog/runtime.ts +0 -927
- package/src/watchdog/scope.ts +0 -51
- package/src/watchdog/settings.ts +0 -520
- package/src/watchdog/tool-actions.ts +0 -156
- package/src/watchdog/turn-delta.ts +0 -190
- 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 -2733
- package/src/workflows/structured-workflow-scripts.ts +0 -177
- package/src/workflows/workflow-checklist.ts +0 -442
- package/src/workflows/workflow-child-summary.ts +0 -172
- package/src/workflows/workflow-preflight.ts +0 -297
- package/src/workflows/workflow-receipt.ts +0 -390
- package/src/workflows/workflow-resources.ts +0 -275
- package/src/workflows/workflow-reuse.ts +0 -120
- package/src/workflows/workflow-revival.ts +0 -123
- package/src/workflows/workflow-settlement.ts +0 -252
|
@@ -0,0 +1,1681 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolvePiLaunchToolPlan
|
|
3
|
+
} from "./chunk-355ECEP2.js";
|
|
4
|
+
import {
|
|
5
|
+
listExternalJobProviders
|
|
6
|
+
} from "./chunk-YYREO77V.js";
|
|
7
|
+
import {
|
|
8
|
+
mergeRuntimeAgents
|
|
9
|
+
} from "./chunk-Z6TFJ6BR.js";
|
|
10
|
+
import {
|
|
11
|
+
CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL,
|
|
12
|
+
THINKING_LEVELS,
|
|
13
|
+
buildRuntimeName,
|
|
14
|
+
defaultInheritProjectContext,
|
|
15
|
+
defaultInheritSkills,
|
|
16
|
+
defaultSystemPromptMode,
|
|
17
|
+
discoverAgents,
|
|
18
|
+
discoverAgentsAll,
|
|
19
|
+
discoverAvailableSkills,
|
|
20
|
+
findBlockingAgentDiagnostic,
|
|
21
|
+
formatReviewGateLabel,
|
|
22
|
+
frontmatterNameForConfig,
|
|
23
|
+
getProjectConfigDir,
|
|
24
|
+
isCodeOwnedExternalCliAdapterId,
|
|
25
|
+
mergeAgentsForScope,
|
|
26
|
+
mergeBuiltinAgentOverride,
|
|
27
|
+
parseFrontmatter,
|
|
28
|
+
parsePackageName,
|
|
29
|
+
parseUnquotedList,
|
|
30
|
+
removeBuiltinAgentOverride,
|
|
31
|
+
removeBuiltinAgentOverrideFields,
|
|
32
|
+
resolveAgentName,
|
|
33
|
+
resolveEffectiveThinking,
|
|
34
|
+
resolveExternalCliBinaryAvailability,
|
|
35
|
+
resolveExternalCliRunnerStatus,
|
|
36
|
+
resolveSkills,
|
|
37
|
+
resolveSkillsWithFallback,
|
|
38
|
+
resolveSubagentModelOverride,
|
|
39
|
+
serializeAgent,
|
|
40
|
+
toModelInfo,
|
|
41
|
+
validateAcceptanceInput,
|
|
42
|
+
validateCodeOwnedProfileRunner,
|
|
43
|
+
validatePermissionProfileName,
|
|
44
|
+
validateSandboxProfileName,
|
|
45
|
+
validateToolBudgetConfig
|
|
46
|
+
} from "./chunk-V2KFIGFH.js";
|
|
47
|
+
import {
|
|
48
|
+
capabilityCeilingAgentRestrictionSources,
|
|
49
|
+
isAgentAllowedByCapabilityCeiling,
|
|
50
|
+
resolveCurrentSubagentCapabilityCeiling
|
|
51
|
+
} from "./chunk-QXASAHIA.js";
|
|
52
|
+
import {
|
|
53
|
+
previewDisplayText
|
|
54
|
+
} from "./chunk-YFCK7H2S.js";
|
|
55
|
+
|
|
56
|
+
// src/agents/agent-eject.ts
|
|
57
|
+
import * as fs2 from "node:fs";
|
|
58
|
+
import * as path2 from "node:path";
|
|
59
|
+
|
|
60
|
+
// src/agents/agent-management.ts
|
|
61
|
+
import * as fs from "node:fs";
|
|
62
|
+
import * as path from "node:path";
|
|
63
|
+
|
|
64
|
+
// src/agents/proactive-skills.ts
|
|
65
|
+
var SUBAGENT_ORCHESTRATION_SKILL = "pi-subagents";
|
|
66
|
+
var DEFAULT_MIN_REFERENCES = 2;
|
|
67
|
+
var DEFAULT_MAX_RECOMMENDATIONS = 3;
|
|
68
|
+
var DEFAULT_PREFERRED_AGENT = "reviewer";
|
|
69
|
+
var FALLBACK_AGENT_ORDER = ["reviewer", "delegate"];
|
|
70
|
+
var MAX_RECOMMENDATION_CAP = 5;
|
|
71
|
+
function positiveInteger(value) {
|
|
72
|
+
if (typeof value !== "number") return void 0;
|
|
73
|
+
if (!Number.isInteger(value) || !Number.isFinite(value) || value < 1) return void 0;
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
function resolveProactiveSkillSubagentsConfig(config) {
|
|
77
|
+
if (config === false) {
|
|
78
|
+
return {
|
|
79
|
+
enabled: false,
|
|
80
|
+
minReferences: DEFAULT_MIN_REFERENCES,
|
|
81
|
+
maxRecommendations: DEFAULT_MAX_RECOMMENDATIONS,
|
|
82
|
+
preferredAgent: DEFAULT_PREFERRED_AGENT
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const maxRecommendations = positiveInteger(config?.maxRecommendations) ?? DEFAULT_MAX_RECOMMENDATIONS;
|
|
86
|
+
return {
|
|
87
|
+
enabled: config?.enabled ?? true,
|
|
88
|
+
minReferences: positiveInteger(config?.minReferences) ?? DEFAULT_MIN_REFERENCES,
|
|
89
|
+
maxRecommendations: Math.min(maxRecommendations, MAX_RECOMMENDATION_CAP),
|
|
90
|
+
preferredAgent: typeof config?.preferredAgent === "string" && config.preferredAgent.trim() ? config.preferredAgent.trim() : DEFAULT_PREFERRED_AGENT
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function normalizeSkillNames(value) {
|
|
94
|
+
if (value === false || value === true || value === void 0 || value === null) return [];
|
|
95
|
+
if (Array.isArray(value)) {
|
|
96
|
+
return [...new Set(value.filter((entry) => typeof entry === "string").map((entry) => entry.trim()).filter(Boolean))];
|
|
97
|
+
}
|
|
98
|
+
if (typeof value === "string") {
|
|
99
|
+
return [...new Set(value.split(",").map((entry) => entry.trim()).filter(Boolean))];
|
|
100
|
+
}
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
function collectStepSkills(step, out) {
|
|
104
|
+
for (const skill of normalizeSkillNames(step.skills ?? step.skill)) {
|
|
105
|
+
out.add(skill);
|
|
106
|
+
}
|
|
107
|
+
const parallel = step.parallel;
|
|
108
|
+
if (!parallel) return;
|
|
109
|
+
if (Array.isArray(parallel)) {
|
|
110
|
+
for (const child of parallel) {
|
|
111
|
+
if (child && typeof child === "object" && !Array.isArray(child)) {
|
|
112
|
+
collectStepSkills(child, out);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (typeof parallel === "object") {
|
|
118
|
+
collectStepSkills(parallel, out);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function chooseRecommendationAgent(agents, preferredAgent) {
|
|
122
|
+
const enabled = agents.filter((agent) => !agent.disabled);
|
|
123
|
+
if (enabled.some((agent) => agent.name === preferredAgent)) return preferredAgent;
|
|
124
|
+
for (const name of FALLBACK_AGENT_ORDER) {
|
|
125
|
+
if (enabled.some((agent) => agent.name === name)) return name;
|
|
126
|
+
}
|
|
127
|
+
return enabled[0]?.name;
|
|
128
|
+
}
|
|
129
|
+
function addSource(counts, skill, source) {
|
|
130
|
+
if (skill === SUBAGENT_ORCHESTRATION_SKILL) return;
|
|
131
|
+
const sources = counts.get(skill) ?? /* @__PURE__ */ new Set();
|
|
132
|
+
sources.add(source);
|
|
133
|
+
counts.set(skill, sources);
|
|
134
|
+
}
|
|
135
|
+
function recommendProactiveSkillSubagents(input) {
|
|
136
|
+
const config = resolveProactiveSkillSubagentsConfig(input.config);
|
|
137
|
+
if (!config.enabled) return [];
|
|
138
|
+
const agent = chooseRecommendationAgent(input.agents, config.preferredAgent);
|
|
139
|
+
if (!agent) return [];
|
|
140
|
+
const availableByName = input.availableSkills ? new Map(input.availableSkills.map((skill) => [skill.name, skill])) : void 0;
|
|
141
|
+
const counts = /* @__PURE__ */ new Map();
|
|
142
|
+
for (const candidate of input.agents) {
|
|
143
|
+
if (candidate.disabled) continue;
|
|
144
|
+
for (const skill of candidate.skills ?? []) {
|
|
145
|
+
addSource(counts, skill, `agent:${candidate.name}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
for (const chain of input.chains ?? []) {
|
|
149
|
+
const chainSkills = /* @__PURE__ */ new Set();
|
|
150
|
+
for (const step of chain.steps) {
|
|
151
|
+
collectStepSkills(step, chainSkills);
|
|
152
|
+
}
|
|
153
|
+
for (const skill of chainSkills) {
|
|
154
|
+
addSource(counts, skill, `chain:${chain.name}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return [...counts.entries()].filter(([skill, sources]) => sources.size >= config.minReferences && (!availableByName || availableByName.has(skill)) && availableByName?.get(skill)?.disableModelInvocation !== true).map(([skill, sources]) => {
|
|
158
|
+
const description = availableByName?.get(skill)?.description;
|
|
159
|
+
return {
|
|
160
|
+
skill,
|
|
161
|
+
agent,
|
|
162
|
+
references: sources.size,
|
|
163
|
+
sources: [...sources].sort((a, b) => a.localeCompare(b)),
|
|
164
|
+
...description !== void 0 ? { description } : {},
|
|
165
|
+
reason: `referenced by ${sources.size} configured agents/chains`
|
|
166
|
+
};
|
|
167
|
+
}).sort((a, b) => b.references - a.references || a.skill.localeCompare(b.skill)).slice(0, config.maxRecommendations);
|
|
168
|
+
}
|
|
169
|
+
function formatProactiveSkillSubagentRecommendations(recommendations) {
|
|
170
|
+
if (recommendations.length === 0) return [];
|
|
171
|
+
return [
|
|
172
|
+
"Proactive skill subagent suggestions:",
|
|
173
|
+
...recommendations.map((recommendation) => {
|
|
174
|
+
const sampleSources = recommendation.sources.slice(0, 3).join(", ");
|
|
175
|
+
const extra = recommendation.sources.length > 3 ? `, +${recommendation.sources.length - 3} more` : "";
|
|
176
|
+
const description = recommendation.description ? ` - ${recommendation.description}` : "";
|
|
177
|
+
return `- ${recommendation.skill} via ${recommendation.agent} (${recommendation.reason}; ${sampleSources}${extra})${description}`;
|
|
178
|
+
}),
|
|
179
|
+
"Guardrails: use these for broad tasks where a skill-specialist pass is useful; keep fanout small, use fresh context unless private/session context is explicitly needed, and skip when the user asks for a direct answer."
|
|
180
|
+
];
|
|
181
|
+
}
|
|
182
|
+
function buildProactiveSkillSubagentRecommendationLines(input) {
|
|
183
|
+
if (!resolveProactiveSkillSubagentsConfig(input.config).enabled) return [];
|
|
184
|
+
let availableSkills;
|
|
185
|
+
try {
|
|
186
|
+
availableSkills = input.discoverAvailableSkills();
|
|
187
|
+
} catch {
|
|
188
|
+
availableSkills = [];
|
|
189
|
+
}
|
|
190
|
+
return formatProactiveSkillSubagentRecommendations(recommendProactiveSkillSubagents({
|
|
191
|
+
agents: input.agents,
|
|
192
|
+
...input.chains !== void 0 ? { chains: input.chains } : {},
|
|
193
|
+
availableSkills,
|
|
194
|
+
...input.config !== void 0 ? { config: input.config } : {}
|
|
195
|
+
}));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// src/agents/agent-management.ts
|
|
199
|
+
var AGENT_MANAGEMENT_API_VERSION = 1;
|
|
200
|
+
function discoverCatalog(ctx, cwd = ctx.cwd, provider) {
|
|
201
|
+
return (ctx.discoverAgentsAll ?? discoverAgentsAll)(cwd, provider);
|
|
202
|
+
}
|
|
203
|
+
function result(text, isError = false, details) {
|
|
204
|
+
return { content: [{ type: "text", text }], isError, details: { mode: "management", results: [], ...details } };
|
|
205
|
+
}
|
|
206
|
+
function jsonDetails(value) {
|
|
207
|
+
return JSON.parse(JSON.stringify(value));
|
|
208
|
+
}
|
|
209
|
+
function presentDetails(value) {
|
|
210
|
+
const cleaned = jsonDetails(value);
|
|
211
|
+
return Object.keys(cleaned).length > 0 ? cleaned : void 0;
|
|
212
|
+
}
|
|
213
|
+
function parseCsv(value) {
|
|
214
|
+
return [...new Set(value.split(",").map((v) => v.trim()).filter(Boolean))];
|
|
215
|
+
}
|
|
216
|
+
function configObject(config) {
|
|
217
|
+
let val = config;
|
|
218
|
+
if (typeof val === "string") {
|
|
219
|
+
try {
|
|
220
|
+
val = JSON.parse(val);
|
|
221
|
+
} catch (error) {
|
|
222
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
223
|
+
return { status: "error", message: `config must be valid JSON: ${message}` };
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (!val || typeof val !== "object" || Array.isArray(val)) return { status: "missing" };
|
|
227
|
+
return { status: "ok", value: val };
|
|
228
|
+
}
|
|
229
|
+
function hasKey(obj, key) {
|
|
230
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
231
|
+
}
|
|
232
|
+
function isJsonSerializable(value) {
|
|
233
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return true;
|
|
234
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
235
|
+
if (Array.isArray(value)) return value.every(isJsonSerializable);
|
|
236
|
+
if (value && typeof value === "object") return Object.values(value).every(isJsonSerializable);
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
function asDisambiguationScope(scope) {
|
|
240
|
+
if (scope === "user" || scope === "project") return scope;
|
|
241
|
+
return void 0;
|
|
242
|
+
}
|
|
243
|
+
function actionScope(scope, action) {
|
|
244
|
+
if (scope === void 0) return { scope: "user" };
|
|
245
|
+
const parsed = asDisambiguationScope(scope);
|
|
246
|
+
return parsed ? { scope: parsed } : { error: result(`agentScope must be 'user' or 'project' for ${action}.`, true) };
|
|
247
|
+
}
|
|
248
|
+
function normalizeListScope(scope) {
|
|
249
|
+
if (scope === void 0) return "both";
|
|
250
|
+
if (scope === "user" || scope === "project" || scope === "both") return scope;
|
|
251
|
+
return void 0;
|
|
252
|
+
}
|
|
253
|
+
function sanitizeName(name) {
|
|
254
|
+
return name.toLowerCase().trim().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-+/g, "-").replace(/^-+|-+$/g, "");
|
|
255
|
+
}
|
|
256
|
+
function parsePackageConfig(value) {
|
|
257
|
+
return parsePackageName(value, "config.package");
|
|
258
|
+
}
|
|
259
|
+
function allAgents(d) {
|
|
260
|
+
return [...d.builtin, ...d.package, ...d.user, ...d.project];
|
|
261
|
+
}
|
|
262
|
+
function effectiveAgentsForScope(scope, d, runtimeAgentOwner, preferredModelProvider) {
|
|
263
|
+
let agents = mergeAgentsForScope(scope, d.user, d.project, d.builtin, d.package);
|
|
264
|
+
if (runtimeAgentOwner) {
|
|
265
|
+
agents = mergeRuntimeAgents(runtimeAgentOwner, { agents }, allAgents(d), { cwd: d.cwd, scope, preferredModelProvider }).agents;
|
|
266
|
+
}
|
|
267
|
+
return agents;
|
|
268
|
+
}
|
|
269
|
+
function availableAgentNamesFromDiscovery(d, runtimeAgentOwner, preferredModelProvider) {
|
|
270
|
+
const agents = runtimeAgentOwner ? effectiveAgentsForScope("both", d, runtimeAgentOwner, preferredModelProvider) : allAgents(d);
|
|
271
|
+
return [...new Set(agents.map((agent) => agent.name))].sort((a, b) => a.localeCompare(b));
|
|
272
|
+
}
|
|
273
|
+
function availableAgentNames(ctx, cwd = ctx.cwd) {
|
|
274
|
+
return availableAgentNamesFromDiscovery(discoverCatalog(ctx, cwd));
|
|
275
|
+
}
|
|
276
|
+
function availableAgentNamesForCwd(cwd) {
|
|
277
|
+
return availableAgentNamesFromDiscovery(discoverAgentsAll(cwd));
|
|
278
|
+
}
|
|
279
|
+
function findAgentsInDiscovery(name, d, scope = "both", runtimeAgentOwner, preferredModelProvider) {
|
|
280
|
+
const raw = name.trim();
|
|
281
|
+
const sanitized = sanitizeName(raw);
|
|
282
|
+
const scoped = effectiveAgentsForScope(scope, d, runtimeAgentOwner, preferredModelProvider);
|
|
283
|
+
let resolved = resolveAgentName(raw, scoped);
|
|
284
|
+
if (!resolved.agent && !resolved.error && sanitized !== raw) resolved = resolveAgentName(sanitized, scoped);
|
|
285
|
+
if (resolved.agent) return scoped.filter((agent) => agent.name === resolved.agent.name).sort((a, b) => a.source.localeCompare(b.source));
|
|
286
|
+
return scoped.filter((agent) => Boolean(resolveAgentName(raw, [agent]).agent) || sanitized !== raw && Boolean(resolveAgentName(sanitized, [agent]).agent)).sort((a, b) => a.source.localeCompare(b.source));
|
|
287
|
+
}
|
|
288
|
+
function findAgents(name, ctx, scope = "both") {
|
|
289
|
+
return findAgentsInDiscovery(name, discoverCatalog(ctx), scope);
|
|
290
|
+
}
|
|
291
|
+
function diagnosticsForScope(diagnostics, scope) {
|
|
292
|
+
if (scope === "both") return diagnostics;
|
|
293
|
+
const excludedSource = scope === "user" ? "project" : "user";
|
|
294
|
+
return diagnostics?.filter((diagnostic) => diagnostic.source !== excludedSource);
|
|
295
|
+
}
|
|
296
|
+
var AGENT_SOURCE_PRECEDENCE = { builtin: 0, package: 1, user: 2, project: 3, runtime: 4 };
|
|
297
|
+
function resolveEffectiveAgent(d, name) {
|
|
298
|
+
const raw = name.trim();
|
|
299
|
+
const candidates = allAgents(d);
|
|
300
|
+
let resolved = resolveAgentName(raw, candidates);
|
|
301
|
+
if (!resolved.agent && !resolved.error) {
|
|
302
|
+
const sanitized = sanitizeName(raw);
|
|
303
|
+
if (sanitized !== raw) resolved = resolveAgentName(sanitized, candidates);
|
|
304
|
+
}
|
|
305
|
+
if (resolved.error) return { error: resolved.error };
|
|
306
|
+
if (!resolved.agent) return {};
|
|
307
|
+
const matches = candidates.filter((agent) => agent.name === resolved.agent.name);
|
|
308
|
+
return { agent: matches.reduce((best, agent) => AGENT_SOURCE_PRECEDENCE[agent.source] > AGENT_SOURCE_PRECEDENCE[best.source] ? agent : best) };
|
|
309
|
+
}
|
|
310
|
+
function nameExistsInScope(ctx, scope, name, excludePath) {
|
|
311
|
+
const d = discoverCatalog(ctx);
|
|
312
|
+
for (const a of scope === "user" ? d.user : d.project) {
|
|
313
|
+
if (a.name === name && a.filePath !== excludePath) return true;
|
|
314
|
+
}
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
function nameExistsInScopeForCwd(cwd, scope, name, excludePath) {
|
|
318
|
+
const d = discoverAgentsAll(cwd);
|
|
319
|
+
for (const a of scope === "user" ? d.user : d.project) {
|
|
320
|
+
if (a.name === name && a.filePath !== excludePath) return true;
|
|
321
|
+
}
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
function isMutableSource(source) {
|
|
325
|
+
return source === "user" || source === "project";
|
|
326
|
+
}
|
|
327
|
+
function modelWarning(ctx, model) {
|
|
328
|
+
if (!model) return void 0;
|
|
329
|
+
const found = ctx.modelRegistry.getAvailable().some((m) => `${m.provider}/${m.id}` === model || m.id === model);
|
|
330
|
+
if (found) return void 0;
|
|
331
|
+
return `Warning: model '${model}' is not in the current model registry. Run subagent({ action: "models" }) to list valid provider/id selectors, then use the exact provider/id form (bare ids resolve only when unique).`;
|
|
332
|
+
}
|
|
333
|
+
function skillsWarning(cwd, agent) {
|
|
334
|
+
if (!agent.skills?.length) return void 0;
|
|
335
|
+
const { missing } = resolveSkills(
|
|
336
|
+
agent.skills,
|
|
337
|
+
cwd,
|
|
338
|
+
agent.skillPath,
|
|
339
|
+
agent.filePath ? path.dirname(agent.filePath) : cwd
|
|
340
|
+
);
|
|
341
|
+
return missing.length ? `Warning: skills not found: ${missing.join(", ")}.` : void 0;
|
|
342
|
+
}
|
|
343
|
+
function withDeclaredExtensionPaths(config, filePath) {
|
|
344
|
+
const { frontmatter } = parseFrontmatter(fs.readFileSync(filePath, "utf-8"));
|
|
345
|
+
const { extensions: _extensions, subagentOnlyExtensions: _subagentOnlyExtensions, ...withoutResolvedExtensions } = config;
|
|
346
|
+
return {
|
|
347
|
+
...withoutResolvedExtensions,
|
|
348
|
+
...frontmatter.extensions !== void 0 ? { extensions: parseUnquotedList(frontmatter.extensions) } : {},
|
|
349
|
+
...frontmatter.subagentOnlyExtensions !== void 0 ? { subagentOnlyExtensions: parseUnquotedList(frontmatter.subagentOnlyExtensions) } : {}
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
function editableAgentConfig(agent) {
|
|
353
|
+
const { extensions: _extensions, ...withoutExtensions } = agent;
|
|
354
|
+
const base = agent.override?.base;
|
|
355
|
+
const description = base?.description ?? agent.description;
|
|
356
|
+
const frontmatterFields = agent.source === "builtin" || agent.source === "runtime" ? void 0 : readAgentFrontmatterFields(agent.filePath);
|
|
357
|
+
const hasDeclaredField = (...fields) => frontmatterFields === void 0 || fields.some((field) => frontmatterFields.has(field));
|
|
358
|
+
const withoutSettingsDefaults = (config) => {
|
|
359
|
+
if (!frontmatterFields) return config;
|
|
360
|
+
const next = { ...config };
|
|
361
|
+
if (!hasDeclaredField("model")) delete next.model;
|
|
362
|
+
if (!hasDeclaredField("thinking")) delete next.thinking;
|
|
363
|
+
return next;
|
|
364
|
+
};
|
|
365
|
+
const {
|
|
366
|
+
override: _override,
|
|
367
|
+
description: _description,
|
|
368
|
+
output: _output,
|
|
369
|
+
outputMode: _outputMode,
|
|
370
|
+
defaultReads: _defaultReads,
|
|
371
|
+
model: _model,
|
|
372
|
+
fast: _fast,
|
|
373
|
+
thinking: _thinking,
|
|
374
|
+
systemPromptMode: _systemPromptMode,
|
|
375
|
+
inheritProjectContext: _inheritProjectContext,
|
|
376
|
+
inheritGlobalContext: _inheritGlobalContext,
|
|
377
|
+
inheritSkills: _inheritSkills,
|
|
378
|
+
defaultContext: _defaultContext,
|
|
379
|
+
acceptanceRole: _acceptanceRole,
|
|
380
|
+
disabled: _disabled,
|
|
381
|
+
systemPrompt: _systemPrompt,
|
|
382
|
+
skills: _skills,
|
|
383
|
+
skillPath: _skillPath,
|
|
384
|
+
tools: _tools,
|
|
385
|
+
excludeTools: _excludeTools,
|
|
386
|
+
mcpDirectTools: _mcpDirectTools,
|
|
387
|
+
allowNestedSubagents: _allowNestedSubagents,
|
|
388
|
+
allowedAgents: _allowedAgents,
|
|
389
|
+
subagentOnlyExtensions: _subagentOnlyExtensions,
|
|
390
|
+
mutationTools: _mutationTools,
|
|
391
|
+
toolBudget: _toolBudget,
|
|
392
|
+
...editable
|
|
393
|
+
} = withoutExtensions;
|
|
394
|
+
if (!base) {
|
|
395
|
+
return withDeclaredExtensionPaths(withoutSettingsDefaults({
|
|
396
|
+
...withoutExtensions,
|
|
397
|
+
...agent.extensionsFromDefault ? {} : agent.extensions !== void 0 ? { extensions: [...agent.extensions] } : {}
|
|
398
|
+
}), agent.filePath);
|
|
399
|
+
}
|
|
400
|
+
return withDeclaredExtensionPaths({
|
|
401
|
+
...editable,
|
|
402
|
+
description,
|
|
403
|
+
...base.output !== void 0 ? { output: base.output } : {},
|
|
404
|
+
...base.outputMode !== void 0 ? { outputMode: base.outputMode } : {},
|
|
405
|
+
...base.defaultReads !== void 0 ? { defaultReads: [...base.defaultReads] } : {},
|
|
406
|
+
...base.model !== void 0 && hasDeclaredField("model") ? { model: base.model } : {},
|
|
407
|
+
...base.fast !== void 0 ? { fast: base.fast } : {},
|
|
408
|
+
...base.thinking !== void 0 && hasDeclaredField("thinking") ? { thinking: base.thinking } : {},
|
|
409
|
+
systemPromptMode: base.systemPromptMode,
|
|
410
|
+
inheritProjectContext: base.inheritProjectContext,
|
|
411
|
+
inheritGlobalContext: base.inheritGlobalContext,
|
|
412
|
+
inheritSkills: base.inheritSkills,
|
|
413
|
+
...base.defaultContext !== void 0 ? { defaultContext: base.defaultContext } : {},
|
|
414
|
+
...base.acceptanceRole !== void 0 ? { acceptanceRole: base.acceptanceRole } : {},
|
|
415
|
+
...base.disabled !== void 0 ? { disabled: base.disabled } : {},
|
|
416
|
+
systemPrompt: base.systemPrompt,
|
|
417
|
+
...base.skills !== void 0 ? { skills: [...base.skills] } : {},
|
|
418
|
+
...base.skillPath !== void 0 ? { skillPath: [...base.skillPath] } : {},
|
|
419
|
+
...base.tools !== void 0 ? { tools: [...base.tools] } : {},
|
|
420
|
+
...base.excludeTools !== void 0 ? { excludeTools: [...base.excludeTools] } : {},
|
|
421
|
+
...base.mcpDirectTools !== void 0 ? { mcpDirectTools: [...base.mcpDirectTools] } : {},
|
|
422
|
+
...base.allowNestedSubagents !== void 0 ? { allowNestedSubagents: base.allowNestedSubagents } : {},
|
|
423
|
+
...base.allowedAgents !== void 0 ? { allowedAgents: [...base.allowedAgents] } : {},
|
|
424
|
+
...base.extensions !== void 0 ? { extensions: [...base.extensions] } : {},
|
|
425
|
+
...base.subagentOnlyExtensions !== void 0 ? { subagentOnlyExtensions: [...base.subagentOnlyExtensions] } : {},
|
|
426
|
+
...base.mutationTools !== void 0 ? { mutationTools: [...base.mutationTools] } : {},
|
|
427
|
+
...base.toolBudget !== void 0 ? { toolBudget: base.toolBudget } : {}
|
|
428
|
+
}, agent.filePath);
|
|
429
|
+
}
|
|
430
|
+
function readAgentFrontmatterFields(filePath) {
|
|
431
|
+
try {
|
|
432
|
+
const { frontmatter } = parseFrontmatter(fs.readFileSync(filePath, "utf-8"));
|
|
433
|
+
return new Set(Object.keys(frontmatter));
|
|
434
|
+
} catch {
|
|
435
|
+
return /* @__PURE__ */ new Set();
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
function preservedAgentFrontmatterFields(agent, cfg) {
|
|
439
|
+
const fields = readAgentFrontmatterFields(agent.filePath);
|
|
440
|
+
const changed = (...names) => {
|
|
441
|
+
for (const name of names) fields.delete(name);
|
|
442
|
+
};
|
|
443
|
+
if (hasKey(cfg, "name")) changed("name");
|
|
444
|
+
if (hasKey(cfg, "package")) changed("package");
|
|
445
|
+
if (hasKey(cfg, "description")) changed("description");
|
|
446
|
+
if (hasKey(cfg, "advertise")) changed("advertise");
|
|
447
|
+
if (hasKey(cfg, "aliases")) changed("alias", "aliases");
|
|
448
|
+
if (hasKey(cfg, "systemPrompt")) changed("systemPrompt");
|
|
449
|
+
if (hasKey(cfg, "runner")) changed("runner");
|
|
450
|
+
if (hasKey(cfg, "model")) changed("model");
|
|
451
|
+
if (hasKey(cfg, "tools")) changed("tools");
|
|
452
|
+
if (hasKey(cfg, "excludeTools")) changed("excludeTools");
|
|
453
|
+
if (hasKey(cfg, "skills")) changed("skill", "skills");
|
|
454
|
+
if (hasKey(cfg, "skillPath")) changed("skillPath");
|
|
455
|
+
if (hasKey(cfg, "extensions")) changed("extensions");
|
|
456
|
+
if (hasKey(cfg, "subagentOnlyExtensions")) changed("subagentOnlyExtensions");
|
|
457
|
+
if (hasKey(cfg, "mutationTools")) changed("mutationTools");
|
|
458
|
+
if (hasKey(cfg, "thinking")) changed("thinking");
|
|
459
|
+
if (hasKey(cfg, "systemPromptMode")) {
|
|
460
|
+
changed("systemPromptMode");
|
|
461
|
+
fields.add("systemPromptMode");
|
|
462
|
+
}
|
|
463
|
+
if (hasKey(cfg, "inheritProjectContext")) {
|
|
464
|
+
changed("inheritProjectContext");
|
|
465
|
+
fields.add("inheritProjectContext");
|
|
466
|
+
}
|
|
467
|
+
if (hasKey(cfg, "inheritGlobalContext")) {
|
|
468
|
+
changed("inheritGlobalContext");
|
|
469
|
+
fields.add("inheritGlobalContext");
|
|
470
|
+
}
|
|
471
|
+
if (hasKey(cfg, "inheritSkills")) {
|
|
472
|
+
changed("inheritSkills");
|
|
473
|
+
fields.add("inheritSkills");
|
|
474
|
+
}
|
|
475
|
+
if (hasKey(cfg, "defaultContext")) changed("defaultContext");
|
|
476
|
+
if (hasKey(cfg, "async")) changed("async");
|
|
477
|
+
if (hasKey(cfg, "timeoutMs")) changed("timeoutMs");
|
|
478
|
+
if (hasKey(cfg, "acceptance")) changed("acceptance");
|
|
479
|
+
if (hasKey(cfg, "acceptanceRole")) changed("acceptanceRole");
|
|
480
|
+
if (hasKey(cfg, "output")) changed("output");
|
|
481
|
+
if (hasKey(cfg, "outputMode")) changed("outputMode");
|
|
482
|
+
if (hasKey(cfg, "reads")) changed("defaultReads");
|
|
483
|
+
if (hasKey(cfg, "progress")) changed("defaultProgress");
|
|
484
|
+
if (hasKey(cfg, "maxSubagentDepth")) changed("maxSubagentDepth");
|
|
485
|
+
if (hasKey(cfg, "toolBudget")) changed("toolBudget");
|
|
486
|
+
if (hasKey(cfg, "sandbox")) changed("sandbox");
|
|
487
|
+
if (hasKey(cfg, "permissionProfile")) changed("permission-profile");
|
|
488
|
+
return fields;
|
|
489
|
+
}
|
|
490
|
+
function parseTools(raw) {
|
|
491
|
+
const tools = [];
|
|
492
|
+
const mcpDirectTools = [];
|
|
493
|
+
for (const item of parseCsv(raw)) {
|
|
494
|
+
if (item.startsWith("mcp:")) {
|
|
495
|
+
const direct = item.slice(4).trim();
|
|
496
|
+
if (direct) mcpDirectTools.push(direct);
|
|
497
|
+
} else tools.push(item);
|
|
498
|
+
}
|
|
499
|
+
return {
|
|
500
|
+
...tools.length ? { tools } : {},
|
|
501
|
+
...mcpDirectTools.length ? { mcpDirectTools } : {}
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
function applyAgentConfig(target, cfg) {
|
|
505
|
+
if (hasKey(cfg, "advertise")) {
|
|
506
|
+
if (cfg.advertise === "") delete target.advertise;
|
|
507
|
+
else if (typeof cfg.advertise === "boolean") target.advertise = cfg.advertise;
|
|
508
|
+
else return "config.advertise must be a boolean or empty string when provided.";
|
|
509
|
+
}
|
|
510
|
+
if (hasKey(cfg, "aliases")) {
|
|
511
|
+
if (cfg.aliases === false || cfg.aliases === "") delete target.aliases;
|
|
512
|
+
else if (typeof cfg.aliases === "string") {
|
|
513
|
+
const aliases = parseCsv(cfg.aliases).filter((alias) => alias !== target.name);
|
|
514
|
+
if (aliases.length) target.aliases = aliases;
|
|
515
|
+
else delete target.aliases;
|
|
516
|
+
} else if (Array.isArray(cfg.aliases) && cfg.aliases.every((entry) => typeof entry === "string")) {
|
|
517
|
+
const aliases = [...new Set(cfg.aliases.map((entry) => entry.trim()).filter(Boolean).filter((alias) => alias !== target.name))];
|
|
518
|
+
if (aliases.length) target.aliases = aliases;
|
|
519
|
+
else delete target.aliases;
|
|
520
|
+
} else return "config.aliases must be a comma-separated string, string array, or false when provided.";
|
|
521
|
+
}
|
|
522
|
+
if (hasKey(cfg, "systemPrompt")) {
|
|
523
|
+
if (cfg.systemPrompt === false || cfg.systemPrompt === "") target.systemPrompt = "";
|
|
524
|
+
else if (typeof cfg.systemPrompt === "string") target.systemPrompt = cfg.systemPrompt;
|
|
525
|
+
else return "config.systemPrompt must be a string or false when provided.";
|
|
526
|
+
}
|
|
527
|
+
if (hasKey(cfg, "runner")) {
|
|
528
|
+
if (cfg.runner === false || cfg.runner === "") delete target.runner;
|
|
529
|
+
else if (cfg.runner && typeof cfg.runner === "object" && !Array.isArray(cfg.runner)) {
|
|
530
|
+
const runner = cfg.runner;
|
|
531
|
+
if (runner.type === "pi" && Object.keys(runner).every((key) => key === "type")) target.runner = { type: "pi" };
|
|
532
|
+
else if (runner.type === "external-cli" && typeof runner.command === "string" && runner.command.trim() && (runner.args === void 0 || Array.isArray(runner.args) && runner.args.every((arg) => typeof arg === "string")) && (runner.adapter === void 0 || isCodeOwnedExternalCliAdapterId(runner.adapter)) && (runner.adapter === void 0 || runner.args === void 0 || runner.args.length === 0) && (runner.promptDelivery === void 0 || runner.promptDelivery === "stdin") && Object.keys(runner).every((key) => ["type", "adapter", "command", "args", "promptDelivery"].includes(key))) {
|
|
533
|
+
const runnerArgs = Array.isArray(runner.args) ? runner.args.filter((arg) => typeof arg === "string") : void 0;
|
|
534
|
+
target.runner = { type: "external-cli", ...isCodeOwnedExternalCliAdapterId(runner.adapter) ? { adapter: runner.adapter } : {}, command: runner.command.trim(), ...runnerArgs?.length ? { args: runnerArgs } : {}, ...runner.promptDelivery ? { promptDelivery: "stdin" } : {} };
|
|
535
|
+
} else if (runner.type === "external-job" && typeof runner.provider === "string" && runner.provider.trim() === runner.provider && runner.provider && (runner.options === void 0 || runner.options && typeof runner.options === "object" && !Array.isArray(runner.options) && isJsonSerializable(runner.options)) && Object.keys(runner).every((key) => ["type", "provider", "options"].includes(key))) {
|
|
536
|
+
target.runner = { type: "external-job", provider: runner.provider, ...runner.options ? { options: runner.options } : {} };
|
|
537
|
+
} else return `config.runner must be { type: 'pi' }, { type: 'external-cli', adapter?: ${CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL}, command: string, args?: string[], promptDelivery?: 'stdin' }, or { type: 'external-job', provider: string, options?: object }.`;
|
|
538
|
+
} else return "config.runner must be an object, false, or empty string when provided.";
|
|
539
|
+
}
|
|
540
|
+
if (hasKey(cfg, "launcher")) return "config.launcher is not supported by agent management; edit the agent file's 'launcher' frontmatter directly.";
|
|
541
|
+
if (target.launcher && (target.runner?.type === "external-cli" || target.runner?.type === "external-job")) {
|
|
542
|
+
return `config.runner type '${target.runner.type}' cannot be combined with this agent's 'launcher' frontmatter.`;
|
|
543
|
+
}
|
|
544
|
+
if (hasKey(cfg, "model")) {
|
|
545
|
+
if (cfg.model === false || cfg.model === "") delete target.model;
|
|
546
|
+
else if (typeof cfg.model === "string") {
|
|
547
|
+
const model = cfg.model.trim();
|
|
548
|
+
if (model) target.model = model;
|
|
549
|
+
else delete target.model;
|
|
550
|
+
} else return "config.model must be a string or false when provided.";
|
|
551
|
+
}
|
|
552
|
+
if (hasKey(cfg, "fallbackModels")) return "config.fallbackModels was removed; configure one model instead.";
|
|
553
|
+
if (hasKey(cfg, "tools")) {
|
|
554
|
+
if (cfg.tools === false || cfg.tools === "") {
|
|
555
|
+
delete target.tools;
|
|
556
|
+
delete target.mcpDirectTools;
|
|
557
|
+
} else if (typeof cfg.tools === "string") {
|
|
558
|
+
const parsed = parseTools(cfg.tools);
|
|
559
|
+
if (parsed.tools) target.tools = parsed.tools;
|
|
560
|
+
else delete target.tools;
|
|
561
|
+
if (parsed.mcpDirectTools) target.mcpDirectTools = parsed.mcpDirectTools;
|
|
562
|
+
else delete target.mcpDirectTools;
|
|
563
|
+
} else return "config.tools must be a comma-separated string or false when provided.";
|
|
564
|
+
}
|
|
565
|
+
if (hasKey(cfg, "excludeTools")) {
|
|
566
|
+
if (cfg.excludeTools === false || cfg.excludeTools === "") delete target.excludeTools;
|
|
567
|
+
else if (typeof cfg.excludeTools === "string") {
|
|
568
|
+
const excludeTools = parseCsv(cfg.excludeTools);
|
|
569
|
+
if (excludeTools.length) target.excludeTools = [...new Set(excludeTools)];
|
|
570
|
+
else delete target.excludeTools;
|
|
571
|
+
} else if (Array.isArray(cfg.excludeTools) && cfg.excludeTools.every((entry) => typeof entry === "string")) {
|
|
572
|
+
const excludeTools = [...new Set(cfg.excludeTools.map((entry) => entry.trim()).filter(Boolean))];
|
|
573
|
+
if (excludeTools.length) target.excludeTools = excludeTools;
|
|
574
|
+
else delete target.excludeTools;
|
|
575
|
+
} else return "config.excludeTools must be a comma-separated string, string array, or false when provided.";
|
|
576
|
+
}
|
|
577
|
+
if (hasKey(cfg, "skills")) {
|
|
578
|
+
if (cfg.skills === false || cfg.skills === "") delete target.skills;
|
|
579
|
+
else if (typeof cfg.skills === "string") {
|
|
580
|
+
const skills = parseCsv(cfg.skills);
|
|
581
|
+
if (skills.length) target.skills = skills;
|
|
582
|
+
else delete target.skills;
|
|
583
|
+
} else return "config.skills must be a comma-separated string or false when provided.";
|
|
584
|
+
}
|
|
585
|
+
if (hasKey(cfg, "skillPath")) {
|
|
586
|
+
if (cfg.skillPath === false || cfg.skillPath === "") delete target.skillPath;
|
|
587
|
+
else if (typeof cfg.skillPath === "string") {
|
|
588
|
+
const skillPath = parseCsv(cfg.skillPath);
|
|
589
|
+
if (skillPath.length) target.skillPath = skillPath;
|
|
590
|
+
else delete target.skillPath;
|
|
591
|
+
} else if (Array.isArray(cfg.skillPath) && cfg.skillPath.every((entry) => typeof entry === "string")) {
|
|
592
|
+
const skillPath = [...new Set(cfg.skillPath.map((entry) => entry.trim()).filter(Boolean))];
|
|
593
|
+
if (skillPath.length) target.skillPath = skillPath;
|
|
594
|
+
else delete target.skillPath;
|
|
595
|
+
} else return "config.skillPath must be a comma-separated string, string array, or false when provided.";
|
|
596
|
+
}
|
|
597
|
+
if (hasKey(cfg, "extensions")) {
|
|
598
|
+
if (cfg.extensions === false) delete target.extensions;
|
|
599
|
+
else if (cfg.extensions === "") target.extensions = [];
|
|
600
|
+
else if (typeof cfg.extensions === "string") target.extensions = parseCsv(cfg.extensions);
|
|
601
|
+
else return "config.extensions must be a comma-separated string, empty string, or false when provided.";
|
|
602
|
+
}
|
|
603
|
+
if (hasKey(cfg, "subagentOnlyExtensions")) {
|
|
604
|
+
if (cfg.subagentOnlyExtensions === false) delete target.subagentOnlyExtensions;
|
|
605
|
+
else if (cfg.subagentOnlyExtensions === "") target.subagentOnlyExtensions = [];
|
|
606
|
+
else if (typeof cfg.subagentOnlyExtensions === "string") target.subagentOnlyExtensions = parseCsv(cfg.subagentOnlyExtensions);
|
|
607
|
+
else return "config.subagentOnlyExtensions must be a comma-separated string, empty string, or false when provided.";
|
|
608
|
+
}
|
|
609
|
+
if (hasKey(cfg, "mutationTools")) {
|
|
610
|
+
if (cfg.mutationTools === false) delete target.mutationTools;
|
|
611
|
+
else if (cfg.mutationTools === "") target.mutationTools = [];
|
|
612
|
+
else if (typeof cfg.mutationTools === "string") target.mutationTools = parseCsv(cfg.mutationTools);
|
|
613
|
+
else return "config.mutationTools must be a comma-separated string, empty string, or false when provided.";
|
|
614
|
+
}
|
|
615
|
+
if (hasKey(cfg, "thinking")) {
|
|
616
|
+
const thinking = typeof cfg.thinking === "string" ? cfg.thinking.trim() : cfg.thinking;
|
|
617
|
+
const level = THINKING_LEVELS.find((candidate) => candidate === thinking);
|
|
618
|
+
if (thinking === false || thinking === "") delete target.thinking;
|
|
619
|
+
else if (level) target.thinking = level;
|
|
620
|
+
else return `config.thinking must be one of ${THINKING_LEVELS.join(", ")}, or false when provided.`;
|
|
621
|
+
}
|
|
622
|
+
if (hasKey(cfg, "systemPromptMode")) {
|
|
623
|
+
if (cfg.systemPromptMode === "append" || cfg.systemPromptMode === "replace") target.systemPromptMode = cfg.systemPromptMode;
|
|
624
|
+
else return "config.systemPromptMode must be 'append' or 'replace' when provided.";
|
|
625
|
+
}
|
|
626
|
+
if (hasKey(cfg, "inheritProjectContext")) {
|
|
627
|
+
if (typeof cfg.inheritProjectContext !== "boolean") return "config.inheritProjectContext must be a boolean when provided.";
|
|
628
|
+
target.inheritProjectContext = cfg.inheritProjectContext;
|
|
629
|
+
}
|
|
630
|
+
if (hasKey(cfg, "inheritGlobalContext")) {
|
|
631
|
+
if (typeof cfg.inheritGlobalContext !== "boolean") return "config.inheritGlobalContext must be a boolean when provided.";
|
|
632
|
+
target.inheritGlobalContext = cfg.inheritGlobalContext;
|
|
633
|
+
}
|
|
634
|
+
if (hasKey(cfg, "inheritSkills")) {
|
|
635
|
+
if (typeof cfg.inheritSkills !== "boolean") return "config.inheritSkills must be a boolean when provided.";
|
|
636
|
+
target.inheritSkills = cfg.inheritSkills;
|
|
637
|
+
}
|
|
638
|
+
if (hasKey(cfg, "defaultContext")) {
|
|
639
|
+
if (cfg.defaultContext === false || cfg.defaultContext === "") delete target.defaultContext;
|
|
640
|
+
else if (cfg.defaultContext === "fresh" || cfg.defaultContext === "fork") target.defaultContext = cfg.defaultContext;
|
|
641
|
+
else return "config.defaultContext must be 'fresh', 'fork', or false when provided.";
|
|
642
|
+
}
|
|
643
|
+
if (hasKey(cfg, "async")) {
|
|
644
|
+
if (cfg.async === "") delete target.defaultAsync;
|
|
645
|
+
else if (typeof cfg.async === "boolean") target.defaultAsync = cfg.async;
|
|
646
|
+
else return "config.async must be a boolean or empty string when provided.";
|
|
647
|
+
}
|
|
648
|
+
if (hasKey(cfg, "timeoutMs")) {
|
|
649
|
+
if (cfg.timeoutMs === false || cfg.timeoutMs === "") delete target.defaultTimeoutMs;
|
|
650
|
+
else if (typeof cfg.timeoutMs === "number" && Number.isInteger(cfg.timeoutMs) && cfg.timeoutMs > 0) target.defaultTimeoutMs = cfg.timeoutMs;
|
|
651
|
+
else return "config.timeoutMs must be a positive integer or false when provided.";
|
|
652
|
+
}
|
|
653
|
+
if (hasKey(cfg, "acceptance")) {
|
|
654
|
+
if (cfg.acceptance === "") delete target.defaultAcceptance;
|
|
655
|
+
else {
|
|
656
|
+
const errors = validateAcceptanceInput(cfg.acceptance, "config.acceptance");
|
|
657
|
+
if (errors.length > 0) return errors.join(" ");
|
|
658
|
+
target.defaultAcceptance = cfg.acceptance;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
if (hasKey(cfg, "acceptanceRole")) {
|
|
662
|
+
if (cfg.acceptanceRole === false || cfg.acceptanceRole === "") delete target.acceptanceRole;
|
|
663
|
+
else if (cfg.acceptanceRole === "read-only" || cfg.acceptanceRole === "writer") target.acceptanceRole = cfg.acceptanceRole;
|
|
664
|
+
else return "config.acceptanceRole must be 'read-only', 'writer', or false when provided.";
|
|
665
|
+
}
|
|
666
|
+
if (hasKey(cfg, "output")) {
|
|
667
|
+
if (cfg.output === false || cfg.output === "") delete target.output;
|
|
668
|
+
else if (typeof cfg.output === "string") target.output = cfg.output;
|
|
669
|
+
else return "config.output must be a string or false when provided.";
|
|
670
|
+
}
|
|
671
|
+
if (hasKey(cfg, "outputMode")) {
|
|
672
|
+
if (cfg.outputMode === "inline" || cfg.outputMode === "file-only") target.outputMode = cfg.outputMode;
|
|
673
|
+
else return "config.outputMode must be 'inline' or 'file-only' when provided.";
|
|
674
|
+
}
|
|
675
|
+
if (hasKey(cfg, "reads")) {
|
|
676
|
+
if (cfg.reads === false || cfg.reads === "") delete target.defaultReads;
|
|
677
|
+
else if (typeof cfg.reads === "string") {
|
|
678
|
+
const reads = parseCsv(cfg.reads);
|
|
679
|
+
if (reads.length) target.defaultReads = reads;
|
|
680
|
+
else delete target.defaultReads;
|
|
681
|
+
} else return "config.reads must be a comma-separated string or false when provided.";
|
|
682
|
+
}
|
|
683
|
+
if (hasKey(cfg, "progress")) {
|
|
684
|
+
if (typeof cfg.progress !== "boolean") return "config.progress must be a boolean when provided.";
|
|
685
|
+
target.defaultProgress = cfg.progress;
|
|
686
|
+
}
|
|
687
|
+
if (hasKey(cfg, "maxSubagentDepth")) {
|
|
688
|
+
if (cfg.maxSubagentDepth === false || cfg.maxSubagentDepth === "") delete target.maxSubagentDepth;
|
|
689
|
+
else if (typeof cfg.maxSubagentDepth === "number" && Number.isInteger(cfg.maxSubagentDepth) && cfg.maxSubagentDepth >= 0) {
|
|
690
|
+
target.maxSubagentDepth = cfg.maxSubagentDepth;
|
|
691
|
+
} else return "config.maxSubagentDepth must be an integer >= 0 or false when provided.";
|
|
692
|
+
}
|
|
693
|
+
if (hasKey(cfg, "toolBudget")) {
|
|
694
|
+
if (cfg.toolBudget === false || cfg.toolBudget === "") delete target.toolBudget;
|
|
695
|
+
else {
|
|
696
|
+
const validation = validateToolBudgetConfig(cfg.toolBudget, "config.toolBudget");
|
|
697
|
+
if (validation.error) return validation.error;
|
|
698
|
+
target.toolBudget = cfg.toolBudget;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
if (hasKey(cfg, "sandbox")) {
|
|
702
|
+
if (typeof cfg.sandbox !== "string") return "config.sandbox must be a non-empty sandbox profile name when provided.";
|
|
703
|
+
try {
|
|
704
|
+
target.sandbox = validateSandboxProfileName(cfg.sandbox, "config.sandbox");
|
|
705
|
+
} catch (error) {
|
|
706
|
+
return error instanceof Error ? error.message : String(error);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
if (hasKey(cfg, "permissionProfile")) {
|
|
710
|
+
if (typeof cfg.permissionProfile !== "string") return "config.permissionProfile must be a non-empty permission profile name when provided.";
|
|
711
|
+
try {
|
|
712
|
+
target.permissionProfile = validatePermissionProfileName(cfg.permissionProfile, "config.permissionProfile");
|
|
713
|
+
} catch (error) {
|
|
714
|
+
return error instanceof Error ? error.message : String(error);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
if (target.runner?.type === "external-cli" || target.runner?.type === "external-job") {
|
|
718
|
+
const unsupported = [
|
|
719
|
+
target.tools?.length || target.mcpDirectTools?.length ? "tools" : void 0,
|
|
720
|
+
target.excludeTools?.length ? "excludeTools" : void 0,
|
|
721
|
+
target.model ? "model" : void 0,
|
|
722
|
+
target.thinking ? "thinking" : void 0,
|
|
723
|
+
target.extensions?.length ? "extensions" : void 0,
|
|
724
|
+
target.subagentOnlyExtensions?.length ? "subagentOnlyExtensions" : void 0,
|
|
725
|
+
target.mutationTools?.length ? "mutationTools" : void 0,
|
|
726
|
+
target.skills?.length || target.skillPath?.length ? "skills" : void 0,
|
|
727
|
+
target.maxSubagentDepth !== void 0 ? "maxSubagentDepth" : void 0,
|
|
728
|
+
target.toolBudget ? "toolBudget" : void 0,
|
|
729
|
+
target.sandbox ? "sandbox" : void 0,
|
|
730
|
+
target.permissionProfile ? "permissionProfile" : void 0
|
|
731
|
+
].filter((field) => Boolean(field));
|
|
732
|
+
if (unsupported.length > 0) return `config.runner type '${target.runner.type}' does not support Pi-only fields: ${unsupported.join(", ")}.`;
|
|
733
|
+
}
|
|
734
|
+
return void 0;
|
|
735
|
+
}
|
|
736
|
+
function resolveTarget(name, matches, cwd, ctx, scopeHint) {
|
|
737
|
+
const distinctNames = [...new Set(matches.map((match) => match.name))];
|
|
738
|
+
if (distinctNames.length > 1) return result(`Ambiguous agent alias or name '${name}': ${distinctNames.sort((a, b) => a.localeCompare(b)).join(", ")}`, true);
|
|
739
|
+
const mutable = matches.filter((match) => isMutableSource(match.source));
|
|
740
|
+
if (mutable.length === 0) {
|
|
741
|
+
if (matches.length > 0) return result(`Agent '${name}' is read-only and cannot be modified. Create a same-named agent in user or project scope to override it.`, true);
|
|
742
|
+
return result(`Agent '${name}' not found. Available: ${availableAgentNames(ctx, cwd).join(", ") || "none"}.`, true);
|
|
743
|
+
}
|
|
744
|
+
if (mutable.length === 1) return mutable[0];
|
|
745
|
+
const scope = asDisambiguationScope(scopeHint);
|
|
746
|
+
if (!scope) {
|
|
747
|
+
const paths = mutable.map((match) => `${match.source}: ${match.filePath}`).join("\n");
|
|
748
|
+
return result(`Agent '${name}' exists in both scopes. Specify agentScope: 'user' or 'project'.
|
|
749
|
+
${paths}`, true);
|
|
750
|
+
}
|
|
751
|
+
const scoped = mutable.filter((match) => match.source === scope);
|
|
752
|
+
if (scoped.length === 0) return result(`Agent '${name}' not found in scope '${scope}'.`, true);
|
|
753
|
+
if (scoped.length > 1) return result(`Multiple agents named '${name}' found in scope '${scope}': ${scoped.map((match) => match.filePath).join(", ")}`, true);
|
|
754
|
+
return scoped[0];
|
|
755
|
+
}
|
|
756
|
+
function renamePath(currentPath, newName, scope, ctx) {
|
|
757
|
+
if (nameExistsInScope(ctx, scope, newName, currentPath)) return { error: `Name '${newName}' already exists in ${scope} scope.` };
|
|
758
|
+
const filePath = path.join(path.dirname(currentPath), `${newName}.md`);
|
|
759
|
+
if (fs.existsSync(filePath) && filePath !== currentPath) return { error: `File already exists at ${filePath} but is not a valid agent definition. Remove or rename it first.` };
|
|
760
|
+
fs.renameSync(currentPath, filePath);
|
|
761
|
+
return { filePath };
|
|
762
|
+
}
|
|
763
|
+
function packageSourceLabel(agent) {
|
|
764
|
+
if (!agent.packageSourceName) return agent.source;
|
|
765
|
+
return agent.packageSourceVersion ? `${agent.packageSourceName}@${agent.packageSourceVersion}` : agent.packageSourceName;
|
|
766
|
+
}
|
|
767
|
+
function errorMessage(error) {
|
|
768
|
+
return error instanceof Error ? error.message : String(error);
|
|
769
|
+
}
|
|
770
|
+
function registeredExternalJobProviderStatus() {
|
|
771
|
+
try {
|
|
772
|
+
return { ok: true, names: new Set(listExternalJobProviders().map((provider) => provider.name)) };
|
|
773
|
+
} catch (error) {
|
|
774
|
+
return { ok: false, error: errorMessage(error) };
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
function externalJobProviderSuffix(provider, names) {
|
|
778
|
+
if (!names) return "?";
|
|
779
|
+
return names.has(provider) ? "\u2713" : "missing";
|
|
780
|
+
}
|
|
781
|
+
function externalCliAvailabilityKey(command, machine) {
|
|
782
|
+
return machine ? `ssh@${machine}` : command;
|
|
783
|
+
}
|
|
784
|
+
function externalCliAvailabilityForAgents(agents) {
|
|
785
|
+
const availability = /* @__PURE__ */ new Map();
|
|
786
|
+
for (const agent of agents) {
|
|
787
|
+
const runner = agent.runner;
|
|
788
|
+
if (runner?.type !== "external-cli") continue;
|
|
789
|
+
const key = externalCliAvailabilityKey(runner.command, agent.machine);
|
|
790
|
+
if (availability.has(key)) continue;
|
|
791
|
+
availability.set(key, resolveExternalCliBinaryAvailability(agent.machine ? "ssh" : runner.command, process.env));
|
|
792
|
+
}
|
|
793
|
+
return availability;
|
|
794
|
+
}
|
|
795
|
+
function runnerListBadge(agent, providerNames2, externalCliAvailability) {
|
|
796
|
+
if (agent.runner?.type === "external-job") return `external-job:${agent.runner.provider} ${externalJobProviderSuffix(agent.runner.provider, providerNames2)}`;
|
|
797
|
+
if (agent.runner?.type === "external-cli") {
|
|
798
|
+
const placed = agent.machine ? `${agent.runner.command} @ ${agent.machine}` : agent.runner.command;
|
|
799
|
+
const availability = externalCliAvailability?.get(externalCliAvailabilityKey(agent.runner.command, agent.machine));
|
|
800
|
+
if (!availability) return `external-cli:${placed}`;
|
|
801
|
+
if (agent.machine) return `external-cli:${placed} saved Herdr placement; transport ${availability.available ? "\u2713" : "missing"}; machine not preflighted`;
|
|
802
|
+
return `external-cli:${placed} ${availability.available ? "\u2713" : "missing"}`;
|
|
803
|
+
}
|
|
804
|
+
if (agent.machine) return `machine: ${agent.machine} (saved Herdr placement)`;
|
|
805
|
+
return void 0;
|
|
806
|
+
}
|
|
807
|
+
function agentListMetadata(agent, providerNames2, externalCliAvailability) {
|
|
808
|
+
const source = agent.source === "package" ? packageSourceLabel(agent) : agent.source;
|
|
809
|
+
return [
|
|
810
|
+
source,
|
|
811
|
+
runnerListBadge(agent, providerNames2, externalCliAvailability),
|
|
812
|
+
agent.defaultContext ? `context: ${agent.defaultContext}` : void 0,
|
|
813
|
+
agent.aliases?.length ? `aliases: ${agent.aliases.join(", ")}` : void 0
|
|
814
|
+
].filter((part) => Boolean(part)).join(", ");
|
|
815
|
+
}
|
|
816
|
+
function formatAgentListLine(agent, providerNames2) {
|
|
817
|
+
return `- ${agent.name} (${agentListMetadata(agent, providerNames2)}): ${agent.description}`;
|
|
818
|
+
}
|
|
819
|
+
function formatAgentCapabilitiesLine(agent, providerNames2, externalCliAvailability) {
|
|
820
|
+
const declaredTools = [
|
|
821
|
+
...agent.tools ?? [],
|
|
822
|
+
...(agent.mcpDirectTools ?? []).map((tool) => `mcp:${tool}`)
|
|
823
|
+
];
|
|
824
|
+
let tools = "none";
|
|
825
|
+
if (agent.tools === void 0 && agent.mcpDirectTools === void 0) {
|
|
826
|
+
tools = "default/ambient";
|
|
827
|
+
} else if (declaredTools.length > 0) {
|
|
828
|
+
tools = declaredTools.join(", ");
|
|
829
|
+
}
|
|
830
|
+
if (agent.excludeTools?.length) tools = `${tools}; excludes: ${agent.excludeTools.join(", ")}`;
|
|
831
|
+
let model = "inherits current session";
|
|
832
|
+
if (agent.model !== void 0) {
|
|
833
|
+
model = agent.model;
|
|
834
|
+
if (agent.modelProvider && !agent.model.includes("/")) model = `${agent.modelProvider}/${agent.model}`;
|
|
835
|
+
}
|
|
836
|
+
const thinking = agent.thinking === false ? "off" : agent.thinking ?? "default";
|
|
837
|
+
const machine = agent.machine ? `; Machine: ${agent.machine} (saved Herdr placement)` : "";
|
|
838
|
+
const acceptance = formatAcceptanceSummary(agent);
|
|
839
|
+
return `- ${agent.name} (${agentListMetadata(agent, providerNames2, externalCliAvailability)}): Description: ${previewDisplayText(agent.description, 240)}; Tools: ${tools}; Model: ${model}; Thinking: ${thinking}${machine}${acceptance ? `; ${acceptance}` : ""}`;
|
|
840
|
+
}
|
|
841
|
+
function formatAcceptanceSummary(agent) {
|
|
842
|
+
const policy = agent.defaultAcceptance;
|
|
843
|
+
const summary = [];
|
|
844
|
+
if (policy === false) summary.push("Acceptance: disabled");
|
|
845
|
+
else if (typeof policy === "string") summary.push(`Acceptance: ${policy}`);
|
|
846
|
+
else if (policy) {
|
|
847
|
+
const modifiers = [
|
|
848
|
+
...policy.evidence ?? [],
|
|
849
|
+
...(policy.verify ?? []).map((command) => `verify: ${formatAcceptanceDisplayLabel(command.id)}`),
|
|
850
|
+
...policy.criteria?.length ? [`criteria: ${policy.criteria.length}`] : [],
|
|
851
|
+
...policy.stopRules?.length ? [`stopRules: ${policy.stopRules.length}`] : []
|
|
852
|
+
];
|
|
853
|
+
if (policy.review === false) modifiers.push("review: off");
|
|
854
|
+
else if (policy.review) {
|
|
855
|
+
const displayReview = policy.review.agent ? { ...policy.review, agent: formatAcceptanceDisplayLabel(policy.review.agent) } : policy.review;
|
|
856
|
+
modifiers.push(`review: ${formatReviewGateLabel(displayReview)}`);
|
|
857
|
+
}
|
|
858
|
+
if (policy.report) modifiers.push(`report: ${policy.report}`);
|
|
859
|
+
summary.push(`Acceptance: ${policy.level ?? "auto"}${modifiers.length > 0 ? ` (${modifiers.join(", ")})` : ""}`);
|
|
860
|
+
}
|
|
861
|
+
if (agent.acceptanceRole) summary.push(`Acceptance role: ${agent.acceptanceRole}`);
|
|
862
|
+
return summary.length > 0 ? summary.join("; ") : void 0;
|
|
863
|
+
}
|
|
864
|
+
function formatAcceptanceDisplayLabel(value) {
|
|
865
|
+
return JSON.stringify(previewDisplayText(value, 80));
|
|
866
|
+
}
|
|
867
|
+
var EXTERNAL_JOB_CAPABILITIES = { stop: false, steer: false, resume: false, structuredOutput: false, toolEvents: false };
|
|
868
|
+
var PI_AGENT_RUNNER = { type: "pi" };
|
|
869
|
+
function listOrEmpty(values) {
|
|
870
|
+
return values ?? [];
|
|
871
|
+
}
|
|
872
|
+
function agentCapabilityRunner(agent, providerNames2, externalCliAvailability) {
|
|
873
|
+
const runner = agent.runner;
|
|
874
|
+
if (!runner || runner.type === "pi") return PI_AGENT_RUNNER;
|
|
875
|
+
if (runner.type === "external-cli") {
|
|
876
|
+
const availability = externalCliAvailability.get(externalCliAvailabilityKey(runner.command, agent.machine));
|
|
877
|
+
return {
|
|
878
|
+
type: "external-cli",
|
|
879
|
+
adapter: runner.adapter,
|
|
880
|
+
command: runner.command,
|
|
881
|
+
...agent.machine ? { machine: agent.machine } : {},
|
|
882
|
+
...availability,
|
|
883
|
+
capabilities: resolveExternalCliRunnerStatus(runner).capabilities
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
return { type: "external-job", provider: runner.provider, available: providerNames2?.has(runner.provider), capabilities: EXTERNAL_JOB_CAPABILITIES };
|
|
887
|
+
}
|
|
888
|
+
function agentCapabilityTools(agent) {
|
|
889
|
+
return {
|
|
890
|
+
ambient: agent.tools === void 0 && agent.mcpDirectTools === void 0,
|
|
891
|
+
names: listOrEmpty(agent.tools),
|
|
892
|
+
...agent.excludeTools !== void 0 ? { excludeTools: [...agent.excludeTools] } : {},
|
|
893
|
+
mcpDirectTools: listOrEmpty(agent.mcpDirectTools),
|
|
894
|
+
mutationTools: agent.mutationTools
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
function agentCapabilityRow(agent, options) {
|
|
898
|
+
return {
|
|
899
|
+
name: agent.name,
|
|
900
|
+
description: previewDisplayText(agent.description, 1e3),
|
|
901
|
+
source: agent.source,
|
|
902
|
+
executable: options.executable,
|
|
903
|
+
restrictionSources: options.executable ? void 0 : options.restrictionSources ?? [],
|
|
904
|
+
aliases: agent.aliases ? [...agent.aliases] : void 0,
|
|
905
|
+
runner: agentCapabilityRunner(agent, options.providerNames, options.externalCliAvailability),
|
|
906
|
+
tools: agentCapabilityTools(agent),
|
|
907
|
+
model: presentDetails({ value: agent.model, thinking: agent.thinking }),
|
|
908
|
+
execution: presentDetails({ defaultAsync: agent.defaultAsync, timeoutMs: agent.defaultTimeoutMs }),
|
|
909
|
+
acceptance: presentDetails({ policy: agent.defaultAcceptance, role: agent.acceptanceRole }),
|
|
910
|
+
output: presentDetails({ path: agent.output, mode: agent.outputMode }),
|
|
911
|
+
extensions: presentDetails({ names: agent.extensions, subagentOnly: agent.subagentOnlyExtensions, skills: agent.skills })
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
function agentCapabilitiesSnapshot(input) {
|
|
915
|
+
return {
|
|
916
|
+
agents: [
|
|
917
|
+
...input.agents.map((agent) => agentCapabilityRow(agent, { executable: true, providerNames: input.providerNames, externalCliAvailability: input.externalCliAvailability })),
|
|
918
|
+
...input.restrictedAgents.map((agent) => agentCapabilityRow(agent, { executable: false, providerNames: input.providerNames, externalCliAvailability: input.externalCliAvailability, restrictionSources: input.restrictedSources }))
|
|
919
|
+
],
|
|
920
|
+
restrictedCount: input.restrictedAgents.length,
|
|
921
|
+
...input.restrictedSources?.length ? { capabilityCeilingSources: [...input.restrictedSources] } : {}
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
function providerNames(status) {
|
|
925
|
+
return status.ok ? status.names : void 0;
|
|
926
|
+
}
|
|
927
|
+
function appendRestrictedAgentLines(input) {
|
|
928
|
+
if (input.agents.length === 0) return;
|
|
929
|
+
input.lines.push(
|
|
930
|
+
"",
|
|
931
|
+
`Restricted agents (not executable in this session${input.sources?.length ? `; capability ceiling: ${input.sources.join(", ")}` : ""}):`,
|
|
932
|
+
...input.agents.map((agent) => input.formatLine(agent, input.providerNames))
|
|
933
|
+
);
|
|
934
|
+
}
|
|
935
|
+
function appendExternalJobRegistryLine(lines, agents, status) {
|
|
936
|
+
if (status.ok || !agents.some((agent) => agent.runner?.type === "external-job")) return;
|
|
937
|
+
lines.push("", `External-job provider registry unavailable: ${status.error}`);
|
|
938
|
+
}
|
|
939
|
+
function appendAgentDiagnosticLines(lines, diagnostics) {
|
|
940
|
+
if (!diagnostics?.length) return;
|
|
941
|
+
lines.push(
|
|
942
|
+
"",
|
|
943
|
+
"Invalid agent definitions:",
|
|
944
|
+
...diagnostics.map((diagnostic) => `- ${diagnostic.name ?? diagnostic.filePath} (${diagnostic.source}): ${diagnostic.error}`)
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
function agentCapabilityDetails(input) {
|
|
948
|
+
if (!input.capabilityMode) return void 0;
|
|
949
|
+
return {
|
|
950
|
+
agentCapabilities: jsonDetails(agentCapabilitiesSnapshot({
|
|
951
|
+
agents: input.agents,
|
|
952
|
+
restrictedAgents: input.restrictedAgents,
|
|
953
|
+
providerNames: input.providerNames,
|
|
954
|
+
externalCliAvailability: input.externalCliAvailability,
|
|
955
|
+
restrictedSources: input.restrictedSources
|
|
956
|
+
}))
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
function formatAgentListSections(agents, providerNames2, formatLine = formatAgentListLine) {
|
|
960
|
+
if (agents.length === 0) return ["- (none)"];
|
|
961
|
+
const sections = [
|
|
962
|
+
["package", "Package agents"],
|
|
963
|
+
["user", "User agents"],
|
|
964
|
+
["project", "Project agents"],
|
|
965
|
+
["runtime", "Runtime agents"],
|
|
966
|
+
["builtin", "Builtin agents"]
|
|
967
|
+
];
|
|
968
|
+
const lines = [];
|
|
969
|
+
for (const [source, label] of sections) {
|
|
970
|
+
const matches = agents.filter((agent) => agent.source === source);
|
|
971
|
+
if (matches.length === 0) continue;
|
|
972
|
+
if (lines.length > 0) lines.push("");
|
|
973
|
+
lines.push(label, ...matches.map((agent) => formatLine(agent, providerNames2)));
|
|
974
|
+
}
|
|
975
|
+
return lines;
|
|
976
|
+
}
|
|
977
|
+
function formatRunnerDetail(agent, providerNames2) {
|
|
978
|
+
if (!agent.runner) return void 0;
|
|
979
|
+
if (agent.runner.type === "external-job") return `Runner: external-job via ${agent.runner.provider} ${externalJobProviderSuffix(agent.runner.provider, providerNames2)}`;
|
|
980
|
+
if (agent.runner.type === "external-cli") return `Runner: external-cli ${agent.runner.command}`;
|
|
981
|
+
return `Runner: ${JSON.stringify(agent.runner)}`;
|
|
982
|
+
}
|
|
983
|
+
function formatAgentDetail(agent) {
|
|
984
|
+
const tools = [...agent.tools ?? [], ...(agent.mcpDirectTools ?? []).map((t) => `mcp:${t}`)];
|
|
985
|
+
const providerStatus = registeredExternalJobProviderStatus();
|
|
986
|
+
const lines = [`Agent: ${agent.name} (${agent.source})`, `Path: ${agent.filePath}`, `Description: ${agent.description}`];
|
|
987
|
+
if (agent.source === "package" && agent.packageSourceName) {
|
|
988
|
+
lines.push(`Source package: ${packageSourceLabel(agent)}`);
|
|
989
|
+
if (agent.packageSourceRoot) lines.push(`Package root: ${agent.packageSourceRoot}`);
|
|
990
|
+
}
|
|
991
|
+
if (agent.packageName) {
|
|
992
|
+
lines.push(`Local name: ${frontmatterNameForConfig(agent)}`);
|
|
993
|
+
lines.push(`Package: ${agent.packageName}`);
|
|
994
|
+
}
|
|
995
|
+
if (agent.aliases?.length) lines.push(`Aliases: ${agent.aliases.join(", ")}`);
|
|
996
|
+
if (agent.model) lines.push(`Model: ${agent.model}`);
|
|
997
|
+
if (tools.length) lines.push(`Tools: ${tools.join(", ")}`);
|
|
998
|
+
if (agent.excludeTools?.length) lines.push(`Excluded tools: ${agent.excludeTools.join(", ")}`);
|
|
999
|
+
if (agent.skills?.length) lines.push(`Skills: ${agent.skills.join(", ")}`);
|
|
1000
|
+
if (agent.skillPath?.length) lines.push(`Skill paths: ${agent.skillPath.join(", ")}`);
|
|
1001
|
+
lines.push(`System prompt mode: ${agent.systemPromptMode}`);
|
|
1002
|
+
const runnerDetail = formatRunnerDetail(agent, providerStatus.ok ? providerStatus.names : void 0);
|
|
1003
|
+
if (runnerDetail) {
|
|
1004
|
+
lines.push(runnerDetail);
|
|
1005
|
+
if (agent.runner?.type === "external-job" && !providerStatus.ok) lines.push(`External-job provider registry unavailable: ${providerStatus.error}`);
|
|
1006
|
+
if (agent.runner?.type === "external-job" && agent.runner.options) lines.push(`Runner options: ${JSON.stringify(agent.runner.options)}`);
|
|
1007
|
+
}
|
|
1008
|
+
lines.push(`Inherit project context: ${agent.inheritProjectContext ? "true" : "false"}`);
|
|
1009
|
+
lines.push(`Inherit global context: ${agent.inheritGlobalContext ? "true" : "false"}`);
|
|
1010
|
+
lines.push(`Inherit skills: ${agent.inheritSkills ? "true" : "false"}`);
|
|
1011
|
+
if (agent.defaultContext) lines.push(`Default context: ${agent.defaultContext}`);
|
|
1012
|
+
if (agent.defaultAsync !== void 0) lines.push(`Async: ${agent.defaultAsync ? "true" : "false"}`);
|
|
1013
|
+
if (agent.defaultTimeoutMs !== void 0) lines.push(`Timeout: ${agent.defaultTimeoutMs}ms`);
|
|
1014
|
+
if (agent.defaultAcceptance !== void 0) lines.push(`Acceptance: ${typeof agent.defaultAcceptance === "object" ? JSON.stringify(agent.defaultAcceptance) : String(agent.defaultAcceptance)}`);
|
|
1015
|
+
if (agent.acceptanceRole) lines.push(`Acceptance role: ${agent.acceptanceRole}`);
|
|
1016
|
+
if (agent.source === "builtin") lines.push(`Disabled: ${agent.disabled ? "true" : "false"}`);
|
|
1017
|
+
if (agent.extensions !== void 0) lines.push(`Extensions: ${agent.extensions.length ? agent.extensions.join(", ") : "(none)"}`);
|
|
1018
|
+
if (agent.subagentOnlyExtensions !== void 0) lines.push(`Subagent-only extensions: ${agent.subagentOnlyExtensions.length ? agent.subagentOnlyExtensions.join(", ") : "(none)"}`);
|
|
1019
|
+
if (agent.mutationTools !== void 0) lines.push(`Mutation tools: ${agent.mutationTools.length ? agent.mutationTools.join(", ") : "(none)"}`);
|
|
1020
|
+
if (agent.thinking) lines.push(`Thinking: ${agent.thinking}`);
|
|
1021
|
+
if (agent.output) lines.push(`Output: ${agent.output}`);
|
|
1022
|
+
if (agent.outputMode) lines.push(`Output mode: ${agent.outputMode}`);
|
|
1023
|
+
if (agent.defaultReads?.length) lines.push(`Reads: ${agent.defaultReads.join(", ")}`);
|
|
1024
|
+
if (agent.defaultProgress) lines.push("Progress: true");
|
|
1025
|
+
if (agent.maxSubagentDepth !== void 0) lines.push(`Max subagent depth: ${agent.maxSubagentDepth}`);
|
|
1026
|
+
if (agent.toolBudget) lines.push(`Tool budget: ${JSON.stringify(agent.toolBudget)}`);
|
|
1027
|
+
if (agent.sandbox) lines.push(`Sandbox profile: ${agent.sandbox}`);
|
|
1028
|
+
if (agent.permissionProfile) lines.push(`Permission profile: ${agent.permissionProfile}`);
|
|
1029
|
+
if (agent.memory) lines.push(`Memory: ${agent.memory.scope} scope, path: ${agent.memory.path}`);
|
|
1030
|
+
if (agent.systemPrompt.trim()) lines.push("", "System Prompt:", agent.systemPrompt);
|
|
1031
|
+
return lines.join("\n");
|
|
1032
|
+
}
|
|
1033
|
+
function handleList(params, ctx) {
|
|
1034
|
+
const scope = normalizeListScope(params.agentScope) ?? "both";
|
|
1035
|
+
const d = discoverCatalog(ctx, ctx.cwd, ctx.model?.provider);
|
|
1036
|
+
let scopedAgents = effectiveAgentsForScope(scope, d, ctx.runtimeAgentOwner, ctx.model?.provider);
|
|
1037
|
+
scopedAgents = scopedAgents.sort((a, b) => a.name.localeCompare(b.name));
|
|
1038
|
+
const capabilityCeiling = resolveCurrentSubagentCapabilityCeiling(ctx.piSessionId);
|
|
1039
|
+
const visibleAgents = scopedAgents.filter((a) => !a.disabled);
|
|
1040
|
+
const agents = visibleAgents.filter((a) => isAgentAllowedByCapabilityCeiling(a.name, capabilityCeiling));
|
|
1041
|
+
const restrictedAgents = visibleAgents.filter((a) => !isAgentAllowedByCapabilityCeiling(a.name, capabilityCeiling));
|
|
1042
|
+
const restrictedSources = capabilityCeilingAgentRestrictionSources(capabilityCeiling);
|
|
1043
|
+
const proactiveSuggestions = buildProactiveSkillSubagentRecommendationLines({
|
|
1044
|
+
agents,
|
|
1045
|
+
...ctx.config?.proactiveSkillSubagents !== void 0 ? { config: ctx.config.proactiveSkillSubagents } : {},
|
|
1046
|
+
discoverAvailableSkills: () => discoverAvailableSkills(ctx.cwd)
|
|
1047
|
+
});
|
|
1048
|
+
const providerStatus = registeredExternalJobProviderStatus();
|
|
1049
|
+
const providerNameSet = providerNames(providerStatus);
|
|
1050
|
+
const capabilityMode = params.capabilities === true;
|
|
1051
|
+
const externalCliAvailability = capabilityMode ? externalCliAvailabilityForAgents([...agents, ...restrictedAgents]) : void 0;
|
|
1052
|
+
const formatLine = capabilityMode ? (agent, names) => formatAgentCapabilitiesLine(agent, names, externalCliAvailability) : formatAgentListLine;
|
|
1053
|
+
const lines = [
|
|
1054
|
+
capabilityMode ? "Executable agents (capabilities):" : "Executable agents:",
|
|
1055
|
+
...formatAgentListSections(agents, providerNameSet, formatLine)
|
|
1056
|
+
];
|
|
1057
|
+
appendRestrictedAgentLines({ lines, agents: restrictedAgents, sources: restrictedSources, providerNames: providerNameSet, formatLine });
|
|
1058
|
+
appendExternalJobRegistryLine(lines, [...agents, ...restrictedAgents], providerStatus);
|
|
1059
|
+
appendAgentDiagnosticLines(lines, d.agentDiagnostics);
|
|
1060
|
+
if (proactiveSuggestions.length) lines.push("", ...proactiveSuggestions);
|
|
1061
|
+
return result(lines.join("\n"), false, agentCapabilityDetails({
|
|
1062
|
+
capabilityMode,
|
|
1063
|
+
agents,
|
|
1064
|
+
restrictedAgents,
|
|
1065
|
+
providerNames: providerNameSet,
|
|
1066
|
+
externalCliAvailability: externalCliAvailability ?? /* @__PURE__ */ new Map(),
|
|
1067
|
+
restrictedSources
|
|
1068
|
+
}));
|
|
1069
|
+
}
|
|
1070
|
+
function formatModelSource(agent, currentModel) {
|
|
1071
|
+
if (agent.override && agent.model !== agent.override.base.model) {
|
|
1072
|
+
return `${agent.override.scope} override`;
|
|
1073
|
+
}
|
|
1074
|
+
if (agent.modelSource?.type === "subagents.defaultModel" && agent.model === agent.modelSource.model) {
|
|
1075
|
+
return `${agent.modelSource.scope} defaultModel`;
|
|
1076
|
+
}
|
|
1077
|
+
if (agent.model) return `${agent.source} agent config`;
|
|
1078
|
+
if (currentModel) return "inherits current session model";
|
|
1079
|
+
return "inherit requested, but no current session model is available";
|
|
1080
|
+
}
|
|
1081
|
+
function handleModels(params, ctx) {
|
|
1082
|
+
const requestedAgent = params.agent?.trim();
|
|
1083
|
+
const scope = normalizeListScope(params.agentScope);
|
|
1084
|
+
if (!scope) return result("agentScope must be 'user', 'project', or 'both' for models.", true);
|
|
1085
|
+
const discovered = discoverCatalog(ctx, ctx.cwd, ctx.model?.provider);
|
|
1086
|
+
const effectiveAgents = effectiveAgentsForScope(scope, discovered, ctx.runtimeAgentOwner, ctx.model?.provider).sort((a, b) => a.name.localeCompare(b.name));
|
|
1087
|
+
const availableModels = ctx.modelRegistry.getAvailable().map(toModelInfo);
|
|
1088
|
+
const currentModel = ctx.model ? { provider: ctx.model.provider, id: ctx.model.id } : void 0;
|
|
1089
|
+
const preferredProvider = ctx.model?.provider;
|
|
1090
|
+
const capabilityCeiling = resolveCurrentSubagentCapabilityCeiling(ctx.piSessionId);
|
|
1091
|
+
let selectedAgents = effectiveAgents;
|
|
1092
|
+
if (requestedAgent) {
|
|
1093
|
+
const matches = findAgentsInDiscovery(requestedAgent, discovered, scope, ctx.runtimeAgentOwner, ctx.model?.provider);
|
|
1094
|
+
const diagnostics = diagnosticsForScope(discovered.agentDiagnostics, scope);
|
|
1095
|
+
const normalizedName = sanitizeName(requestedAgent);
|
|
1096
|
+
const diagnostic = findBlockingAgentDiagnostic(requestedAgent, matches, diagnostics) ?? (normalizedName !== requestedAgent ? findBlockingAgentDiagnostic(normalizedName, matches, diagnostics) : void 0);
|
|
1097
|
+
if (diagnostic) return result(`Agent '${params.agent}' has invalid configuration: ${diagnostic.error}`, true);
|
|
1098
|
+
const distinctNames = [...new Set(matches.map((agent) => agent.name))];
|
|
1099
|
+
if (distinctNames.length > 1) return result(`Ambiguous agent alias or name '${params.agent}': ${distinctNames.sort((a, b) => a.localeCompare(b)).join(", ")}`, true);
|
|
1100
|
+
if (!matches.length) {
|
|
1101
|
+
return result(`Agent '${params.agent}' not found. Available: ${availableAgentNamesFromDiscovery(discovered, ctx.runtimeAgentOwner, ctx.model?.provider).join(", ") || "none"}.`, true);
|
|
1102
|
+
}
|
|
1103
|
+
selectedAgents = [matches[0]];
|
|
1104
|
+
}
|
|
1105
|
+
const lines = [
|
|
1106
|
+
requestedAgent ? "Subagent model" : "Subagent models",
|
|
1107
|
+
"",
|
|
1108
|
+
...requestedAgent ? [] : [
|
|
1109
|
+
"Current session model:",
|
|
1110
|
+
` ${currentModel ? `${currentModel.provider}/${currentModel.id}` : "(unavailable)"}`,
|
|
1111
|
+
""
|
|
1112
|
+
]
|
|
1113
|
+
];
|
|
1114
|
+
const modelEntries = selectedAgents.flatMap((agent) => requestedAgent ? [{ agent, name: requestedAgent }] : [{ agent, name: agent.name }, ...(agent.aliases ?? []).map((name) => ({ agent, name }))]);
|
|
1115
|
+
for (const { agent, name } of modelEntries) {
|
|
1116
|
+
const resolvedModel = resolveSubagentModelOverride(agent.model, currentModel, availableModels, agent.modelProvider ?? preferredProvider);
|
|
1117
|
+
const effectiveThinking = resolveEffectiveThinking(resolvedModel, agent.thinking) ?? (agent.thinking === false ? "off" : void 0);
|
|
1118
|
+
const source = `${formatModelSource(agent, currentModel)}${agent.disabled ? "; disabled" : ""}${isAgentAllowedByCapabilityCeiling(agent.name, capabilityCeiling) ? "" : "; restricted"}`;
|
|
1119
|
+
if (requestedAgent) {
|
|
1120
|
+
lines.push(`Agent: ${requestedAgent}`);
|
|
1121
|
+
lines.push("Effective model:");
|
|
1122
|
+
lines.push(` ${resolvedModel ?? "(unresolved)"}`);
|
|
1123
|
+
lines.push(`Source: ${source}`);
|
|
1124
|
+
lines.push(`Thinking: ${effectiveThinking ?? "default"}`);
|
|
1125
|
+
if (agent.override) {
|
|
1126
|
+
lines.push("Override file:");
|
|
1127
|
+
lines.push(` ${agent.override.path}`);
|
|
1128
|
+
}
|
|
1129
|
+
if (agent.model && resolvedModel && agent.model !== resolvedModel) {
|
|
1130
|
+
lines.push("Requested model setting:");
|
|
1131
|
+
lines.push(` ${agent.model}`);
|
|
1132
|
+
}
|
|
1133
|
+
if (agent.disabled) lines.push("Disabled: true");
|
|
1134
|
+
if (!isAgentAllowedByCapabilityCeiling(agent.name, capabilityCeiling)) lines.push("Restricted: true");
|
|
1135
|
+
lines.push("Current session model:");
|
|
1136
|
+
lines.push(` ${currentModel ? `${currentModel.provider}/${currentModel.id}` : "(unavailable)"}`);
|
|
1137
|
+
break;
|
|
1138
|
+
}
|
|
1139
|
+
lines.push(name);
|
|
1140
|
+
lines.push(" model:");
|
|
1141
|
+
lines.push(` ${resolvedModel ?? "(unresolved)"}`);
|
|
1142
|
+
lines.push(` source: ${source}`);
|
|
1143
|
+
lines.push(` thinking: ${effectiveThinking ?? "default"}`);
|
|
1144
|
+
if (agent.override) {
|
|
1145
|
+
lines.push(" override file:");
|
|
1146
|
+
lines.push(` ${agent.override.path}`);
|
|
1147
|
+
}
|
|
1148
|
+
if (agent.model && resolvedModel && agent.model !== resolvedModel) {
|
|
1149
|
+
lines.push(" requested model setting:");
|
|
1150
|
+
lines.push(` ${agent.model}`);
|
|
1151
|
+
}
|
|
1152
|
+
lines.push("");
|
|
1153
|
+
}
|
|
1154
|
+
const availableFullIds = availableModels.map((m) => m.fullId).sort();
|
|
1155
|
+
if (!requestedAgent && availableFullIds.length > 0) {
|
|
1156
|
+
lines.push("Available models in this session's registry (copy an exact provider/id when passing model):");
|
|
1157
|
+
lines.push("");
|
|
1158
|
+
const shown = availableFullIds.slice(0, 80);
|
|
1159
|
+
for (const fullId of shown) lines.push(` ${fullId}`);
|
|
1160
|
+
if (availableFullIds.length > shown.length) lines.push(` ... and ${availableFullIds.length - shown.length} more`);
|
|
1161
|
+
lines.push("");
|
|
1162
|
+
lines.push("Use an exact provider/id from this list when you pass model; bare ids resolve only when unique in the registry.");
|
|
1163
|
+
}
|
|
1164
|
+
if (!requestedAgent) appendAgentDiagnosticLines(lines, diagnosticsForScope(discovered.agentDiagnostics, scope));
|
|
1165
|
+
return result(lines.join("\n"));
|
|
1166
|
+
}
|
|
1167
|
+
function handleGet(params, ctx) {
|
|
1168
|
+
if (!params.agent) return result("Specify 'agent' for get.", true);
|
|
1169
|
+
const scope = normalizeListScope(params.agentScope);
|
|
1170
|
+
if (!scope) return result("agentScope must be 'user', 'project', or 'both' for get.", true);
|
|
1171
|
+
const discovered = discoverCatalog(ctx, ctx.cwd, ctx.model?.provider);
|
|
1172
|
+
const matches = findAgentsInDiscovery(params.agent, discovered, scope);
|
|
1173
|
+
const diagnostics = diagnosticsForScope(discovered.agentDiagnostics, scope);
|
|
1174
|
+
const rawName = params.agent.trim();
|
|
1175
|
+
const normalizedName = sanitizeName(rawName);
|
|
1176
|
+
const diagnostic = findBlockingAgentDiagnostic(rawName, matches, diagnostics) ?? (normalizedName !== rawName ? findBlockingAgentDiagnostic(normalizedName, matches, diagnostics) : void 0);
|
|
1177
|
+
if (diagnostic) return result(`Agent '${params.agent}' has invalid configuration: ${diagnostic.error}`, true);
|
|
1178
|
+
const distinctNames = [...new Set(matches.map((agent) => agent.name))];
|
|
1179
|
+
if (distinctNames.length > 1) return result(`Ambiguous agent alias or name '${params.agent}': ${distinctNames.sort((a, b) => a.localeCompare(b)).join(", ")}`, true);
|
|
1180
|
+
if (!matches.length) {
|
|
1181
|
+
return result(`Agent '${params.agent}' not found. Available: ${availableAgentNamesFromDiscovery(discovered).join(", ") || "none"}.`, true);
|
|
1182
|
+
}
|
|
1183
|
+
return result(matches.map(formatAgentDetail).join("\n\n"));
|
|
1184
|
+
}
|
|
1185
|
+
function handleCreate(params, ctx) {
|
|
1186
|
+
const parsedConfig = configObject(params.config);
|
|
1187
|
+
if (parsedConfig.status === "error") return result(parsedConfig.message, true);
|
|
1188
|
+
if (parsedConfig.status === "missing") return result("config required for create.", true);
|
|
1189
|
+
const cfg = parsedConfig.value;
|
|
1190
|
+
if (typeof cfg.name !== "string" || !cfg.name.trim()) return result("config.name is required and must be a non-empty string.", true);
|
|
1191
|
+
if (typeof cfg.description !== "string" || !cfg.description.trim()) return result("config.description is required and must be a non-empty string.", true);
|
|
1192
|
+
const name = sanitizeName(cfg.name);
|
|
1193
|
+
if (!name) return result("config.name is invalid after sanitization. Use letters, numbers, spaces, or hyphens.", true);
|
|
1194
|
+
const parsedPackage = parsePackageConfig(cfg.package);
|
|
1195
|
+
if (parsedPackage.error) return result(parsedPackage.error, true);
|
|
1196
|
+
const runtimeName = buildRuntimeName(name, parsedPackage.packageName);
|
|
1197
|
+
const scopeRaw = cfg.scope ?? "user";
|
|
1198
|
+
if (scopeRaw !== "user" && scopeRaw !== "project") return result("config.scope must be 'user' or 'project'.", true);
|
|
1199
|
+
const scope = scopeRaw;
|
|
1200
|
+
if (hasKey(cfg, "steps")) return result("Durable chain definitions were removed; use a workflow script or /prompt-workflow for repeatable workflows.", true);
|
|
1201
|
+
const d = discoverCatalog(ctx);
|
|
1202
|
+
const projectConfigDir = getProjectConfigDir(ctx.cwd);
|
|
1203
|
+
const targetDir = scope === "user" ? d.userDir : d.projectDir ?? path.join(projectConfigDir, "agents");
|
|
1204
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
1205
|
+
if (nameExistsInScope(ctx, scope, runtimeName)) return result(`Name '${runtimeName}' already exists in ${scope} scope. Use update instead.`, true);
|
|
1206
|
+
const targetPath = path.join(targetDir, `${runtimeName}.md`);
|
|
1207
|
+
if (fs.existsSync(targetPath)) return result(`File already exists at ${targetPath} but is not a valid agent definition. Remove or rename it first.`, true);
|
|
1208
|
+
const warnings = [];
|
|
1209
|
+
if (d.builtin.some((a) => a.name === runtimeName)) warnings.push(`Note: this shadows the builtin agent '${runtimeName}'.`);
|
|
1210
|
+
const agent = {
|
|
1211
|
+
name: runtimeName,
|
|
1212
|
+
localName: name,
|
|
1213
|
+
...parsedPackage.packageName !== void 0 ? { packageName: parsedPackage.packageName } : {},
|
|
1214
|
+
description: cfg.description.trim(),
|
|
1215
|
+
source: scope,
|
|
1216
|
+
filePath: targetPath,
|
|
1217
|
+
systemPrompt: "",
|
|
1218
|
+
systemPromptMode: defaultSystemPromptMode(name),
|
|
1219
|
+
inheritProjectContext: defaultInheritProjectContext(name),
|
|
1220
|
+
inheritGlobalContext: false,
|
|
1221
|
+
inheritSkills: defaultInheritSkills()
|
|
1222
|
+
};
|
|
1223
|
+
const applyError = applyAgentConfig(agent, cfg);
|
|
1224
|
+
if (applyError) return result(applyError, true);
|
|
1225
|
+
const profileError = validateCodeOwnedProfileRunner(agent);
|
|
1226
|
+
if (profileError) return result(profileError, true);
|
|
1227
|
+
const mw = modelWarning(ctx, agent.model);
|
|
1228
|
+
if (mw) warnings.push(mw);
|
|
1229
|
+
const sw = skillsWarning(ctx.cwd, agent);
|
|
1230
|
+
if (sw) warnings.push(sw);
|
|
1231
|
+
fs.writeFileSync(targetPath, serializeAgent(agent), "utf-8");
|
|
1232
|
+
ctx.onAgentsChanged?.();
|
|
1233
|
+
return result([`Created agent '${runtimeName}' at ${targetPath}.`, ...warnings].join("\n"));
|
|
1234
|
+
}
|
|
1235
|
+
function handleUpdate(params, ctx) {
|
|
1236
|
+
if (!params.agent) return result("Specify 'agent' for update.", true);
|
|
1237
|
+
const parsedConfig = configObject(params.config);
|
|
1238
|
+
if (parsedConfig.status === "error") return result(parsedConfig.message, true);
|
|
1239
|
+
if (parsedConfig.status === "missing") return result("config required for update.", true);
|
|
1240
|
+
const cfg = parsedConfig.value;
|
|
1241
|
+
if (hasKey(cfg, "steps")) return result("Durable chain definitions were removed; use a workflow script or /prompt-workflow for repeatable workflows.", true);
|
|
1242
|
+
const warnings = [];
|
|
1243
|
+
const scopeHint = asDisambiguationScope(params.agentScope);
|
|
1244
|
+
const targetOrError = resolveTarget(params.agent, findAgents(params.agent, ctx, scopeHint ?? "both"), ctx.cwd, ctx, scopeHint);
|
|
1245
|
+
if ("content" in targetOrError) return targetOrError;
|
|
1246
|
+
const target = targetOrError;
|
|
1247
|
+
if (target.source !== "user" && target.source !== "project") return result(`Cannot update ${target.source} agent '${target.name}'. Eject it to user or project scope first.`, true);
|
|
1248
|
+
let updated;
|
|
1249
|
+
try {
|
|
1250
|
+
updated = editableAgentConfig(target);
|
|
1251
|
+
} catch (error) {
|
|
1252
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1253
|
+
return result(`Could not reread agent definition ${target.filePath} before updating '${target.name}': ${message}`, true);
|
|
1254
|
+
}
|
|
1255
|
+
const oldName = target.name;
|
|
1256
|
+
if (hasKey(cfg, "name") && (typeof cfg.name !== "string" || !cfg.name.trim())) return result("config.name must be a non-empty string when provided.", true);
|
|
1257
|
+
if (hasKey(cfg, "description") && (typeof cfg.description !== "string" || !cfg.description.trim())) return result("config.description must be a non-empty string when provided.", true);
|
|
1258
|
+
let newLocalName = target.localName ?? frontmatterNameForConfig(target);
|
|
1259
|
+
if (hasKey(cfg, "name")) {
|
|
1260
|
+
newLocalName = sanitizeName(cfg.name);
|
|
1261
|
+
if (!newLocalName) return result("config.name is invalid after sanitization.", true);
|
|
1262
|
+
}
|
|
1263
|
+
let newPackageName = target.packageName;
|
|
1264
|
+
if (hasKey(cfg, "package")) {
|
|
1265
|
+
const parsedPackage = parsePackageConfig(cfg.package);
|
|
1266
|
+
if (parsedPackage.error) return result(parsedPackage.error, true);
|
|
1267
|
+
newPackageName = parsedPackage.packageName;
|
|
1268
|
+
}
|
|
1269
|
+
const applyError = applyAgentConfig(updated, cfg);
|
|
1270
|
+
if (applyError) return result(applyError, true);
|
|
1271
|
+
const preserveFrontmatterFields = preservedAgentFrontmatterFields(target, cfg);
|
|
1272
|
+
updated.localName = newLocalName;
|
|
1273
|
+
if (newPackageName !== void 0) updated.packageName = newPackageName;
|
|
1274
|
+
else delete updated.packageName;
|
|
1275
|
+
updated.name = buildRuntimeName(newLocalName, newPackageName);
|
|
1276
|
+
const profileError = validateCodeOwnedProfileRunner(updated);
|
|
1277
|
+
if (profileError) return result(profileError, true);
|
|
1278
|
+
if (hasKey(cfg, "description")) updated.description = cfg.description.trim();
|
|
1279
|
+
if (hasKey(cfg, "model")) {
|
|
1280
|
+
const mw = modelWarning(ctx, updated.model);
|
|
1281
|
+
if (mw) warnings.push(mw);
|
|
1282
|
+
}
|
|
1283
|
+
if (hasKey(cfg, "skills") || hasKey(cfg, "skillPath")) {
|
|
1284
|
+
const sw = skillsWarning(ctx.cwd, updated);
|
|
1285
|
+
if (sw) warnings.push(sw);
|
|
1286
|
+
}
|
|
1287
|
+
if (updated.name !== oldName) {
|
|
1288
|
+
const renamed = renamePath(target.filePath, updated.name, target.source, ctx);
|
|
1289
|
+
if (renamed.error) return result(renamed.error, true);
|
|
1290
|
+
updated.filePath = renamed.filePath;
|
|
1291
|
+
}
|
|
1292
|
+
fs.writeFileSync(updated.filePath, serializeAgent(updated, { preserveFrontmatterFields }), "utf-8");
|
|
1293
|
+
ctx.onAgentsChanged?.();
|
|
1294
|
+
const headline = updated.name === oldName ? `Updated agent '${updated.name}' at ${updated.filePath}.` : `Updated agent '${oldName}' to '${updated.name}' at ${updated.filePath}.`;
|
|
1295
|
+
return result([headline, ...warnings].join("\n"));
|
|
1296
|
+
}
|
|
1297
|
+
function handleDelete(params, ctx) {
|
|
1298
|
+
if (!params.agent) return result("Specify 'agent' for delete.", true);
|
|
1299
|
+
const scopeHint = asDisambiguationScope(params.agentScope);
|
|
1300
|
+
const targetOrError = resolveTarget(params.agent, findAgents(params.agent, ctx, scopeHint ?? "both"), ctx.cwd, ctx, scopeHint);
|
|
1301
|
+
if ("content" in targetOrError) return targetOrError;
|
|
1302
|
+
const target = targetOrError;
|
|
1303
|
+
fs.unlinkSync(target.filePath);
|
|
1304
|
+
ctx.onAgentsChanged?.();
|
|
1305
|
+
return result(`Deleted agent '${target.name}' at ${target.filePath}.`);
|
|
1306
|
+
}
|
|
1307
|
+
function handleEject(params, ctx) {
|
|
1308
|
+
if (!params.agent) return result("Specify 'agent' for eject.", true);
|
|
1309
|
+
const parsedScope = actionScope(params.agentScope, "eject");
|
|
1310
|
+
if (parsedScope.error) return parsedScope.error;
|
|
1311
|
+
const scope = parsedScope.scope;
|
|
1312
|
+
const ejected = ejectAgentDefinition({
|
|
1313
|
+
cwd: ctx.cwd,
|
|
1314
|
+
agent: params.agent,
|
|
1315
|
+
scope,
|
|
1316
|
+
// Preserve the existing management-action behavior. Direct public callers
|
|
1317
|
+
// must supply affirmative project trust themselves.
|
|
1318
|
+
...scope === "project" ? { projectTrusted: true } : {}
|
|
1319
|
+
});
|
|
1320
|
+
if (ejected.ok) ctx.onAgentsChanged?.();
|
|
1321
|
+
return result(ejected.message, !ejected.ok);
|
|
1322
|
+
}
|
|
1323
|
+
function handleDisable(params, ctx) {
|
|
1324
|
+
if (!params.agent) return result("Specify 'agent' for disable.", true);
|
|
1325
|
+
const raw = params.agent.trim();
|
|
1326
|
+
const parsedScope = actionScope(params.agentScope, "disable");
|
|
1327
|
+
if (parsedScope.error) return parsedScope.error;
|
|
1328
|
+
const scope = parsedScope.scope;
|
|
1329
|
+
const d = discoverCatalog(ctx);
|
|
1330
|
+
if (scope === "project" && d.projectSettingsPath === null) {
|
|
1331
|
+
return result("Project override is not available here: no project config root (.pi or .agents) was found above the cwd. Use agentScope: 'user' or run from inside a project.", true);
|
|
1332
|
+
}
|
|
1333
|
+
const effective = resolveEffectiveAgent(d, raw);
|
|
1334
|
+
if (effective.error) return result(effective.error, true);
|
|
1335
|
+
if (!effective.agent) {
|
|
1336
|
+
return result(`Agent '${raw}' not found. Available: ${availableAgentNames(ctx).join(", ") || "none"}.`, true);
|
|
1337
|
+
}
|
|
1338
|
+
const runtimeName = effective.agent.name;
|
|
1339
|
+
const settingsPath = mergeBuiltinAgentOverride(ctx.cwd, runtimeName, scope, { disabled: true });
|
|
1340
|
+
const after = resolveEffectiveAgent(discoverCatalog(ctx), raw).agent;
|
|
1341
|
+
if (after?.disabled === true) {
|
|
1342
|
+
ctx.onAgentsChanged?.();
|
|
1343
|
+
return result(`Disabled agent '${runtimeName}' via ${scope} settings override at ${settingsPath}. It is now hidden from runtime discovery and { action: "list" }.`);
|
|
1344
|
+
}
|
|
1345
|
+
return result(`Wrote a disabled override for '${runtimeName}' at ${settingsPath}, but the agent is still enabled. A higher-precedence ${after?.override?.scope ?? "project"} override is likely winning. Try agentScope: '${after?.override?.scope ?? "project"}'.`, true);
|
|
1346
|
+
}
|
|
1347
|
+
function handleEnable(params, ctx) {
|
|
1348
|
+
if (!params.agent) return result("Specify 'agent' for enable.", true);
|
|
1349
|
+
const raw = params.agent.trim();
|
|
1350
|
+
const parsedScope = actionScope(params.agentScope, "enable");
|
|
1351
|
+
if (parsedScope.error) return parsedScope.error;
|
|
1352
|
+
const scope = parsedScope.scope;
|
|
1353
|
+
const d = discoverCatalog(ctx);
|
|
1354
|
+
if (scope === "project" && d.projectSettingsPath === null) {
|
|
1355
|
+
return result("Project override is not available here: no project config root (.pi or .agents) was found above the cwd. Use agentScope: 'user' or run from inside a project.", true);
|
|
1356
|
+
}
|
|
1357
|
+
const effective = resolveEffectiveAgent(d, raw);
|
|
1358
|
+
if (effective.error) return result(effective.error, true);
|
|
1359
|
+
if (!effective.agent) {
|
|
1360
|
+
return result(`Agent '${raw}' not found. Available: ${availableAgentNames(ctx).join(", ") || "none"}.`, true);
|
|
1361
|
+
}
|
|
1362
|
+
const runtimeName = effective.agent.name;
|
|
1363
|
+
const { path: settingsPath, removed } = removeBuiltinAgentOverrideFields(ctx.cwd, runtimeName, scope, ["disabled"]);
|
|
1364
|
+
const after = resolveEffectiveAgent(discoverCatalog(ctx), raw).agent;
|
|
1365
|
+
if (after && after.disabled !== true) {
|
|
1366
|
+
if (removed) ctx.onAgentsChanged?.();
|
|
1367
|
+
if (removed) return result(`Enabled agent '${runtimeName}' (removed disabled override at ${settingsPath}).`);
|
|
1368
|
+
return result(`Agent '${runtimeName}' is already enabled.`);
|
|
1369
|
+
}
|
|
1370
|
+
if (after?.override?.scope && after.override.scope !== scope) {
|
|
1371
|
+
return result(`Agent '${runtimeName}' is still disabled via a ${after.override.scope} scope override at ${after.override.path}. Specify agentScope: '${after.override.scope}' to enable it.`, true);
|
|
1372
|
+
}
|
|
1373
|
+
return result(`Agent '${runtimeName}' is still disabled after removing the ${scope} disabled override. It may be hidden via subagents.disableBuiltins in ${after?.override?.scope ?? scope} settings at ${after?.override?.path ?? settingsPath}.`, true);
|
|
1374
|
+
}
|
|
1375
|
+
function handleReset(params, ctx) {
|
|
1376
|
+
if (!params.agent) return result("Specify 'agent' for reset.", true);
|
|
1377
|
+
const raw = params.agent.trim();
|
|
1378
|
+
const sanitized = sanitizeName(raw);
|
|
1379
|
+
const parsedScope = actionScope(params.agentScope, "reset");
|
|
1380
|
+
if (parsedScope.error) return parsedScope.error;
|
|
1381
|
+
const scope = parsedScope.scope;
|
|
1382
|
+
const d = discoverCatalog(ctx);
|
|
1383
|
+
if (scope === "project" && d.projectSettingsPath === null) {
|
|
1384
|
+
return result("Project override is not available here: no project config root (.pi or .agents) was found above the cwd. Use agentScope: 'user' or run from inside a project.", true);
|
|
1385
|
+
}
|
|
1386
|
+
const bundled = [...d.package, ...d.builtin].find((a) => a.name === raw || a.name === sanitized);
|
|
1387
|
+
if (!bundled) {
|
|
1388
|
+
const custom2 = [...d.user, ...d.project].find((a) => a.name === raw || a.name === sanitized);
|
|
1389
|
+
if (custom2) {
|
|
1390
|
+
return result(`Agent '${raw}' has no bundled default to reset to. Use { action: "delete", agent: "${custom2.name}" } to remove the custom ${custom2.source} agent.`, true);
|
|
1391
|
+
}
|
|
1392
|
+
return result(`Agent '${raw}' not found. Available: ${availableAgentNames(ctx).join(", ") || "none"}.`, true);
|
|
1393
|
+
}
|
|
1394
|
+
const runtimeName = bundled.name;
|
|
1395
|
+
const custom = (scope === "user" ? d.user : d.project).find((a) => a.name === raw || a.name === sanitized);
|
|
1396
|
+
const lines = [];
|
|
1397
|
+
if (custom) {
|
|
1398
|
+
fs.unlinkSync(custom.filePath);
|
|
1399
|
+
lines.push(`Deleted custom ${scope} agent file at ${custom.filePath}.`);
|
|
1400
|
+
}
|
|
1401
|
+
const overrideRemoval = removeBuiltinAgentOverride(ctx.cwd, runtimeName, scope, { preserveMachine: true });
|
|
1402
|
+
if (overrideRemoval.removed) lines.push(`${overrideRemoval.machinePreserved ? "Cleared customization in" : "Removed"} ${scope} settings override at ${overrideRemoval.path}.${overrideRemoval.machinePreserved ? " Retained machine placement." : ""}`);
|
|
1403
|
+
if (lines.length === 0) {
|
|
1404
|
+
const otherScope = scope === "user" ? "project" : "user";
|
|
1405
|
+
const otherCustom = (otherScope === "user" ? d.user : d.project).find((a) => a.name === raw || a.name === sanitized);
|
|
1406
|
+
const hasOtherOverride = bundled.override?.scope === otherScope;
|
|
1407
|
+
const note = otherCustom || hasOtherOverride ? ` Customization exists in ${otherScope} scope; specify agentScope: '${otherScope}' to reset it.` : "";
|
|
1408
|
+
return result(`Agent '${runtimeName}' has no ${scope} customization to reset.${note} It is at its bundled ${bundled.source} default.`);
|
|
1409
|
+
}
|
|
1410
|
+
lines.push(`Reset agent '${runtimeName}' to its bundled ${bundled.source} default.`);
|
|
1411
|
+
ctx.onAgentsChanged?.();
|
|
1412
|
+
return result(lines.join("\n"));
|
|
1413
|
+
}
|
|
1414
|
+
function handleManagementAction(action, params, ctx) {
|
|
1415
|
+
switch (action) {
|
|
1416
|
+
case "list":
|
|
1417
|
+
return handleList(params, ctx);
|
|
1418
|
+
case "get":
|
|
1419
|
+
return handleGet(params, ctx);
|
|
1420
|
+
case "models":
|
|
1421
|
+
return handleModels(params, ctx);
|
|
1422
|
+
case "create":
|
|
1423
|
+
return handleCreate(params, ctx);
|
|
1424
|
+
case "update":
|
|
1425
|
+
return handleUpdate(params, ctx);
|
|
1426
|
+
case "delete":
|
|
1427
|
+
return handleDelete(params, ctx);
|
|
1428
|
+
case "eject":
|
|
1429
|
+
return handleEject(params, ctx);
|
|
1430
|
+
case "disable":
|
|
1431
|
+
return handleDisable(params, ctx);
|
|
1432
|
+
case "enable":
|
|
1433
|
+
return handleEnable(params, ctx);
|
|
1434
|
+
case "reset":
|
|
1435
|
+
return handleReset(params, ctx);
|
|
1436
|
+
default:
|
|
1437
|
+
return result(`Unknown action: ${action}`, true);
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
// src/agents/agent-eject.ts
|
|
1442
|
+
function isRelativeAgentResourcePath(value) {
|
|
1443
|
+
return value === "." || value === ".." || value.startsWith("./") || value.startsWith("../");
|
|
1444
|
+
}
|
|
1445
|
+
function isAgentResourcePath(value) {
|
|
1446
|
+
return isRelativeAgentResourcePath(value) || path2.isAbsolute(value);
|
|
1447
|
+
}
|
|
1448
|
+
function resolvePortableAgentResources(entries, sourceFilePath) {
|
|
1449
|
+
const baseDir = path2.dirname(sourceFilePath);
|
|
1450
|
+
const resourcePaths = (entries ?? []).flatMap(
|
|
1451
|
+
(entry) => isAgentResourcePath(entry) ? [path2.resolve(baseDir, entry)] : []
|
|
1452
|
+
);
|
|
1453
|
+
return {
|
|
1454
|
+
entries: entries?.map((entry) => isAgentResourcePath(entry) ? path2.resolve(baseDir, entry) : entry),
|
|
1455
|
+
resourcePaths
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
function portableEjectedAgentContent(source) {
|
|
1459
|
+
let sourceContent;
|
|
1460
|
+
try {
|
|
1461
|
+
sourceContent = fs2.readFileSync(source.filePath, "utf-8");
|
|
1462
|
+
} catch (error) {
|
|
1463
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1464
|
+
return {
|
|
1465
|
+
error: {
|
|
1466
|
+
ok: false,
|
|
1467
|
+
code: "source_read_failed",
|
|
1468
|
+
message: `Failed to read source agent at ${source.filePath}: ${message}`
|
|
1469
|
+
}
|
|
1470
|
+
};
|
|
1471
|
+
}
|
|
1472
|
+
const extensions = resolvePortableAgentResources(source.extensions, source.filePath);
|
|
1473
|
+
const subagentOnlyExtensions = resolvePortableAgentResources(source.subagentOnlyExtensions, source.filePath);
|
|
1474
|
+
const skillPath = resolvePortableAgentResources(source.skillPath, source.filePath);
|
|
1475
|
+
const tools = resolvePortableAgentResources(source.tools, source.filePath);
|
|
1476
|
+
const resourcePaths = [.../* @__PURE__ */ new Set([
|
|
1477
|
+
...extensions.resourcePaths,
|
|
1478
|
+
...subagentOnlyExtensions.resourcePaths,
|
|
1479
|
+
...skillPath.resourcePaths,
|
|
1480
|
+
...tools.resourcePaths
|
|
1481
|
+
])].sort((a, b) => a.localeCompare(b));
|
|
1482
|
+
const missingResources = resourcePaths.filter((resourcePath) => !fs2.existsSync(resourcePath));
|
|
1483
|
+
if (missingResources.length > 0) {
|
|
1484
|
+
return {
|
|
1485
|
+
error: {
|
|
1486
|
+
ok: false,
|
|
1487
|
+
code: "resource_missing",
|
|
1488
|
+
message: `Agent '${source.name}' cannot be ejected because its relative resource path(s) do not exist: ${missingResources.join(", ")}.`
|
|
1489
|
+
}
|
|
1490
|
+
};
|
|
1491
|
+
}
|
|
1492
|
+
if (resourcePaths.length === 0) return { content: sourceContent, resourcePaths };
|
|
1493
|
+
const { frontmatter } = parseFrontmatter(sourceContent);
|
|
1494
|
+
const portableAgent = {
|
|
1495
|
+
...source,
|
|
1496
|
+
...source.extensions !== void 0 ? { extensions: extensions.entries } : {},
|
|
1497
|
+
...source.subagentOnlyExtensions !== void 0 ? { subagentOnlyExtensions: subagentOnlyExtensions.entries } : {},
|
|
1498
|
+
...source.skillPath !== void 0 ? { skillPath: skillPath.entries } : {},
|
|
1499
|
+
...source.tools !== void 0 ? { tools: tools.entries } : {}
|
|
1500
|
+
};
|
|
1501
|
+
return {
|
|
1502
|
+
content: serializeAgent(portableAgent, { preserveFrontmatterFields: new Set(Object.keys(frontmatter)) }),
|
|
1503
|
+
resourcePaths
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
function cleanupEjectedFile(targetPath, expectedContent) {
|
|
1507
|
+
try {
|
|
1508
|
+
if (fs2.readFileSync(targetPath, "utf-8") === expectedContent) fs2.unlinkSync(targetPath);
|
|
1509
|
+
} catch {
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
function validateEjectedAgentLaunchPreflight(agent, cwd) {
|
|
1513
|
+
const resolvedSkills = resolveSkillsWithFallback(
|
|
1514
|
+
agent.skills ?? [],
|
|
1515
|
+
cwd,
|
|
1516
|
+
void 0,
|
|
1517
|
+
agent.skillPath,
|
|
1518
|
+
agent.filePath ? path2.dirname(agent.filePath) : cwd
|
|
1519
|
+
);
|
|
1520
|
+
if (resolvedSkills.missing.length > 0) {
|
|
1521
|
+
return `Missing skills: ${resolvedSkills.missing.join(", ")}`;
|
|
1522
|
+
}
|
|
1523
|
+
try {
|
|
1524
|
+
resolvePiLaunchToolPlan({
|
|
1525
|
+
tools: agent.tools,
|
|
1526
|
+
extensions: agent.extensions,
|
|
1527
|
+
subagentOnlyExtensions: agent.subagentOnlyExtensions,
|
|
1528
|
+
mcpDirectTools: agent.mcpDirectTools,
|
|
1529
|
+
cwd,
|
|
1530
|
+
requireReadTool: resolvedSkills.resolved.length > 0,
|
|
1531
|
+
agentName: agent.name,
|
|
1532
|
+
sandbox: agent.sandbox,
|
|
1533
|
+
permissionProfile: agent.permissionProfile
|
|
1534
|
+
});
|
|
1535
|
+
} catch (error) {
|
|
1536
|
+
return error instanceof Error ? error.message : String(error);
|
|
1537
|
+
}
|
|
1538
|
+
return void 0;
|
|
1539
|
+
}
|
|
1540
|
+
function ejectAgentDefinition(input) {
|
|
1541
|
+
const raw = input.agent.trim();
|
|
1542
|
+
const sanitized = sanitizeName(raw);
|
|
1543
|
+
if (!raw || !sanitized) {
|
|
1544
|
+
return { ok: false, code: "invalid_agent", message: "agent must be a non-empty valid agent name." };
|
|
1545
|
+
}
|
|
1546
|
+
if (input.scope !== "user" && input.scope !== "project") {
|
|
1547
|
+
return { ok: false, code: "invalid_agent", message: "scope must be 'user' or 'project'." };
|
|
1548
|
+
}
|
|
1549
|
+
if (input.scope === "project" && input.projectTrusted !== true) {
|
|
1550
|
+
return {
|
|
1551
|
+
ok: false,
|
|
1552
|
+
code: "untrusted_project",
|
|
1553
|
+
scope: input.scope,
|
|
1554
|
+
message: "Project scope ejection requires a trusted project. Trust the project and retry."
|
|
1555
|
+
};
|
|
1556
|
+
}
|
|
1557
|
+
let discovered;
|
|
1558
|
+
try {
|
|
1559
|
+
discovered = discoverAgentsAll(input.cwd);
|
|
1560
|
+
} catch (error) {
|
|
1561
|
+
return {
|
|
1562
|
+
ok: false,
|
|
1563
|
+
code: "rediscovery_failed",
|
|
1564
|
+
scope: input.scope,
|
|
1565
|
+
message: `Unable to discover agents before ejecting: ${error instanceof Error ? error.message : String(error)}`
|
|
1566
|
+
};
|
|
1567
|
+
}
|
|
1568
|
+
if (input.scope === "project" && discovered.projectDir === null) {
|
|
1569
|
+
return {
|
|
1570
|
+
ok: false,
|
|
1571
|
+
code: "missing_project_root",
|
|
1572
|
+
scope: input.scope,
|
|
1573
|
+
message: "Project scope ejection is not available here: no project config root (.pi or .agents) was found above the cwd."
|
|
1574
|
+
};
|
|
1575
|
+
}
|
|
1576
|
+
const existingCustom = (input.scope === "user" ? discovered.user : discovered.project).find((candidate) => candidate.name === raw || candidate.name === sanitized);
|
|
1577
|
+
if (existingCustom) {
|
|
1578
|
+
return {
|
|
1579
|
+
ok: false,
|
|
1580
|
+
code: "existing_custom",
|
|
1581
|
+
scope: input.scope,
|
|
1582
|
+
targetPath: existingCustom.filePath,
|
|
1583
|
+
message: `Agent '${existingCustom.name}' is already a custom ${input.scope} agent at ${existingCustom.filePath}. Edit it with { action: "update", agent: "${existingCustom.name}" } or delete it first.`
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1586
|
+
const bundledCandidates = input.scope === "user" ? discoverAgents(input.cwd, "user").agents.filter((candidate) => candidate.source === "builtin" || candidate.source === "package") : [...discovered.package, ...discovered.builtin];
|
|
1587
|
+
const source = bundledCandidates.find((candidate) => candidate.name === raw || candidate.name === sanitized);
|
|
1588
|
+
if (!source) {
|
|
1589
|
+
return {
|
|
1590
|
+
ok: false,
|
|
1591
|
+
code: "missing_source",
|
|
1592
|
+
scope: input.scope,
|
|
1593
|
+
message: `Agent '${raw}' not found or is not a bundled/package agent. eject copies a builtin or package agent to ${input.scope} scope so it can be customized. Available: ${availableAgentNamesForCwd(input.cwd).join(", ") || "none"}.`
|
|
1594
|
+
};
|
|
1595
|
+
}
|
|
1596
|
+
const runtimeName = source.name;
|
|
1597
|
+
if (nameExistsInScopeForCwd(input.cwd, input.scope, runtimeName)) {
|
|
1598
|
+
return {
|
|
1599
|
+
ok: false,
|
|
1600
|
+
code: "name_conflict",
|
|
1601
|
+
scope: input.scope,
|
|
1602
|
+
message: `An agent or chain named '${runtimeName}' already exists in ${input.scope} scope. Remove or rename it first.`
|
|
1603
|
+
};
|
|
1604
|
+
}
|
|
1605
|
+
const targetDir = input.scope === "user" ? discovered.userDir : discovered.projectDir;
|
|
1606
|
+
const targetPath = path2.join(targetDir, `${runtimeName}.md`);
|
|
1607
|
+
if (fs2.existsSync(targetPath)) {
|
|
1608
|
+
return {
|
|
1609
|
+
ok: false,
|
|
1610
|
+
code: "existing_file",
|
|
1611
|
+
scope: input.scope,
|
|
1612
|
+
targetPath,
|
|
1613
|
+
message: `File already exists at ${targetPath} but is not a valid agent definition. Remove or rename it first.`
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
const portable = portableEjectedAgentContent(source);
|
|
1617
|
+
if (portable.error) return { ...portable.error, scope: input.scope, targetPath };
|
|
1618
|
+
const content = portable.content;
|
|
1619
|
+
try {
|
|
1620
|
+
fs2.mkdirSync(targetDir, { recursive: true });
|
|
1621
|
+
fs2.writeFileSync(targetPath, content, { encoding: "utf-8", flag: "wx" });
|
|
1622
|
+
} catch (error) {
|
|
1623
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1624
|
+
return {
|
|
1625
|
+
ok: false,
|
|
1626
|
+
code: "write_failed",
|
|
1627
|
+
scope: input.scope,
|
|
1628
|
+
targetPath,
|
|
1629
|
+
message: `Failed to write ejected agent '${runtimeName}' at ${targetPath}: ${message}`
|
|
1630
|
+
};
|
|
1631
|
+
}
|
|
1632
|
+
const rediscovered = discoverAgentsAll(input.cwd);
|
|
1633
|
+
const copied = (input.scope === "user" ? rediscovered.user : rediscovered.project).find((candidate) => candidate.name === runtimeName && path2.resolve(candidate.filePath) === path2.resolve(targetPath));
|
|
1634
|
+
if (!copied) {
|
|
1635
|
+
cleanupEjectedFile(targetPath, content);
|
|
1636
|
+
return {
|
|
1637
|
+
ok: false,
|
|
1638
|
+
code: "rediscovery_failed",
|
|
1639
|
+
scope: input.scope,
|
|
1640
|
+
targetPath,
|
|
1641
|
+
message: `Ejected agent '${runtimeName}' could not be rediscovered at ${targetPath}; no file was kept.`
|
|
1642
|
+
};
|
|
1643
|
+
}
|
|
1644
|
+
const preflightError = validateEjectedAgentLaunchPreflight(copied, input.cwd);
|
|
1645
|
+
if (preflightError) {
|
|
1646
|
+
cleanupEjectedFile(targetPath, content);
|
|
1647
|
+
return {
|
|
1648
|
+
ok: false,
|
|
1649
|
+
code: "preflight_failed",
|
|
1650
|
+
scope: input.scope,
|
|
1651
|
+
targetPath,
|
|
1652
|
+
message: `Ejected agent '${runtimeName}' failed launch preflight at ${targetPath}: ${preflightError}. No file was kept.`
|
|
1653
|
+
};
|
|
1654
|
+
}
|
|
1655
|
+
const sourceKind = source.source;
|
|
1656
|
+
return {
|
|
1657
|
+
ok: true,
|
|
1658
|
+
code: "ejected",
|
|
1659
|
+
message: `Ejected agent '${runtimeName}' from ${sourceKind} to ${input.scope} scope at ${targetPath}. Edit it there to customize; it shadows the bundled ${sourceKind} agent of the same name.`,
|
|
1660
|
+
agent: runtimeName,
|
|
1661
|
+
source: sourceKind,
|
|
1662
|
+
scope: input.scope,
|
|
1663
|
+
targetPath,
|
|
1664
|
+
verification: {
|
|
1665
|
+
agent: copied.name,
|
|
1666
|
+
scope: input.scope,
|
|
1667
|
+
targetPath,
|
|
1668
|
+
source: sourceKind,
|
|
1669
|
+
resourcePaths: portable.resourcePaths ?? [],
|
|
1670
|
+
launchPreflighted: true
|
|
1671
|
+
}
|
|
1672
|
+
};
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
export {
|
|
1676
|
+
ejectAgentDefinition,
|
|
1677
|
+
AGENT_MANAGEMENT_API_VERSION,
|
|
1678
|
+
editableAgentConfig,
|
|
1679
|
+
preservedAgentFrontmatterFields,
|
|
1680
|
+
handleManagementAction
|
|
1681
|
+
};
|