@ashx-j/lunr 0.2.11 → 0.2.13
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 +13 -0
- package/README.md +211 -236
- package/dist/builtin-extensions/ashxj-tui.d.ts +3 -0
- package/dist/builtin-extensions/ashxj-tui.d.ts.map +1 -1
- package/dist/builtin-extensions/ashxj-tui.js +28 -11
- package/dist/builtin-extensions/ashxj-tui.js.map +1 -1
- package/dist/builtin-extensions/index.d.ts.map +1 -1
- package/dist/builtin-extensions/index.js +0 -2
- package/dist/builtin-extensions/index.js.map +1 -1
- package/dist/builtin-extensions/lunr-cron.d.ts +1 -1
- package/dist/builtin-extensions/lunr-cron.d.ts.map +1 -1
- package/dist/builtin-extensions/lunr-cron.js +1 -1
- package/dist/builtin-extensions/lunr-cron.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/chain-validation.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/chain-validation.js +3 -3
- package/dist/builtin-extensions/pi-subagents/src/extension/chain-validation.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/doctor.d.ts +0 -2
- package/dist/builtin-extensions/pi-subagents/src/extension/doctor.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/doctor.js +1 -23
- package/dist/builtin-extensions/pi-subagents/src/extension/doctor.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/fanout-child.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/fanout-child.js +6 -7
- package/dist/builtin-extensions/pi-subagents/src/extension/fanout-child.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/index.d.ts +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/index.js +7 -14
- package/dist/builtin-extensions/pi-subagents/src/extension/index.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/schemas.d.ts +12 -9
- package/dist/builtin-extensions/pi-subagents/src/extension/schemas.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/schemas.js +38 -34
- package/dist/builtin-extensions/pi-subagents/src/extension/schemas.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.d.ts +3 -3
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.js +32 -47
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/intercom-bridge.d.ts +2 -2
- package/dist/builtin-extensions/pi-subagents/src/intercom/intercom-bridge.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/intercom-bridge.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.d.ts +7 -10
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.js +90 -109
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-resume.d.ts +3 -2
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-resume.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-resume.js +37 -50
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-resume.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/run-status.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/run-status.js +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/run-status.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/scheduled-runs.d.ts +4 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/scheduled-runs.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/scheduled-runs.js +5 -5
- package/dist/builtin-extensions/pi-subagents/src/runs/background/scheduled-runs.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js +31 -13
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-clarify.d.ts +2 -2
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-clarify.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-clarify.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.d.ts +4 -3
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.js +48 -20
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.d.ts +2 -2
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js +90 -64
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.d.ts +6 -8
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js +262 -161
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/acceptance.d.ts +2 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/acceptance.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/acceptance.js +24 -33
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/acceptance.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.d.ts +25 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.d.ts.map +1 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.js +51 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.js.map +1 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/dynamic-fanout.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/dynamic-fanout.js +20 -3
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/dynamic-fanout.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/parallel-utils.d.ts +4 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/parallel-utils.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/parallel-utils.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.d.ts +5 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.js +9 -3
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.js +2 -2
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/task-intent.d.ts +2 -2
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/task-intent.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/task-intent.js +20 -17
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/task-intent.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/child-spec.d.ts +70 -0
- package/dist/builtin-extensions/pi-subagents/src/shared/child-spec.d.ts.map +1 -0
- package/dist/builtin-extensions/pi-subagents/src/shared/child-spec.js +153 -0
- package/dist/builtin-extensions/pi-subagents/src/shared/child-spec.js.map +1 -0
- package/dist/builtin-extensions/pi-subagents/src/shared/settings.d.ts +13 -8
- package/dist/builtin-extensions/pi-subagents/src/shared/settings.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/settings.js +20 -51
- package/dist/builtin-extensions/pi-subagents/src/shared/settings.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/types.d.ts +80 -20
- package/dist/builtin-extensions/pi-subagents/src/shared/types.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/types.js +10 -2
- package/dist/builtin-extensions/pi-subagents/src/shared/types.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/slash/prompt-workflows.d.ts +2 -2
- package/dist/builtin-extensions/pi-subagents/src/slash/prompt-workflows.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/slash/prompt-workflows.js +20 -32
- package/dist/builtin-extensions/pi-subagents/src/slash/prompt-workflows.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.d.ts +2 -1
- package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.js +23 -449
- package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts +2 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/render.js +13 -11
- package/dist/builtin-extensions/pi-subagents/src/tui/render.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/watchdog/runtime.d.ts +2 -1
- package/dist/builtin-extensions/pi-subagents/src/watchdog/runtime.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/watchdog/runtime.js +18 -17
- package/dist/builtin-extensions/pi-subagents/src/watchdog/runtime.js.map +1 -1
- package/dist/builtin-extensions/simple-pi-memory.d.ts +2 -2
- package/dist/builtin-extensions/simple-pi-memory.d.ts.map +1 -1
- package/dist/builtin-extensions/simple-pi-memory.js +41 -17
- package/dist/builtin-extensions/simple-pi-memory.js.map +1 -1
- package/dist/catalog/models.json +1 -1
- package/dist/catalog/providers/amazon-bedrock.json +1 -1
- package/dist/catalog/providers/azure-openai-responses.json +1 -1
- package/dist/catalog/providers/cloudflare-ai-gateway.json +1 -1
- package/dist/catalog/providers/cloudflare-workers-ai.json +1 -1
- package/dist/catalog/providers/fireworks.json +1 -1
- package/dist/catalog/providers/github-copilot.json +1 -1
- package/dist/catalog/providers/huggingface.json +1 -1
- package/dist/catalog/providers/minimax-cn.json +1 -1
- package/dist/catalog/providers/minimax.json +1 -1
- package/dist/catalog/providers/mistral.json +1 -1
- package/dist/catalog/providers/nvidia.json +1 -1
- package/dist/catalog/providers/openai.json +1 -1
- package/dist/catalog/providers/opencode-go.json +1 -1
- package/dist/catalog/providers/opencode.json +1 -1
- package/dist/catalog/providers/openrouter.json +1 -1
- package/dist/catalog/providers/qwen-cloud-cn.json +1 -1
- package/dist/catalog/providers/qwen-cloud.json +1 -1
- package/dist/catalog/providers/qwen-token-plan-cn.json +1 -1
- package/dist/catalog/providers/qwen-token-plan.json +1 -1
- package/dist/catalog/providers/together.json +1 -1
- package/dist/catalog/providers/vercel-ai-gateway.json +1 -1
- package/dist/catalog/providers/zai-coding-cn.json +1 -1
- package/dist/catalog/providers/zai.json +1 -1
- package/dist/catalog/publication.json +3 -3
- package/dist/core/agent-session.d.ts +7 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +34 -4
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/context-breakdown.d.ts +3 -1
- package/dist/core/context-breakdown.d.ts.map +1 -1
- package/dist/core/context-breakdown.js +5 -2
- package/dist/core/context-breakdown.js.map +1 -1
- package/dist/core/customize.d.ts +2 -0
- package/dist/core/customize.d.ts.map +1 -1
- package/dist/core/customize.js +6 -0
- package/dist/core/customize.js.map +1 -1
- package/dist/core/memory-cap.d.ts +4 -8
- package/dist/core/memory-cap.d.ts.map +1 -1
- package/dist/core/memory-cap.js +8 -8
- package/dist/core/memory-cap.js.map +1 -1
- package/dist/core/permissions.d.ts +2 -0
- package/dist/core/permissions.d.ts.map +1 -1
- package/dist/core/permissions.js +30 -14
- package/dist/core/permissions.js.map +1 -1
- package/dist/core/plan-mode.d.ts.map +1 -1
- package/dist/core/plan-mode.js +1 -9
- package/dist/core/plan-mode.js.map +1 -1
- package/dist/core/rollback.d.ts.map +1 -1
- package/dist/core/rollback.js +1 -1
- package/dist/core/rollback.js.map +1 -1
- package/dist/core/settings-manager.d.ts +16 -5
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +37 -10
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -5
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/subagent-permission-inherit.d.ts +34 -22
- package/dist/core/subagent-permission-inherit.d.ts.map +1 -1
- package/dist/core/subagent-permission-inherit.js +37 -80
- package/dist/core/subagent-permission-inherit.js.map +1 -1
- package/dist/core/swarm.d.ts.map +1 -1
- package/dist/core/swarm.js +13 -7
- package/dist/core/swarm.js.map +1 -1
- package/dist/core/system-prompt.d.ts +6 -4
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +38 -48
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/usage-adapters/openai-codex.d.ts +1 -1
- package/dist/core/usage-adapters/openai-codex.d.ts.map +1 -1
- package/dist/core/usage-adapters/openai-codex.js +22 -17
- package/dist/core/usage-adapters/openai-codex.js.map +1 -1
- package/dist/core/usage-service.d.ts +10 -1
- package/dist/core/usage-service.d.ts.map +1 -1
- package/dist/core/usage-service.js +17 -6
- package/dist/core/usage-service.js.map +1 -1
- package/dist/gateway/agent-bridge.d.ts.map +1 -1
- package/dist/gateway/agent-bridge.js +1 -4
- package/dist/gateway/agent-bridge.js.map +1 -1
- package/dist/gateway/cron.d.ts.map +1 -1
- package/dist/gateway/cron.js +1 -4
- package/dist/gateway/cron.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +0 -5
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts +2 -0
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +21 -0
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +7 -4
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +122 -162
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/usage-view.d.ts +1 -1
- package/dist/modes/interactive/components/usage-view.d.ts.map +1 -1
- package/dist/modes/interactive/components/usage-view.js +7 -4
- package/dist/modes/interactive/components/usage-view.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1 -2
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +55 -96
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/skill-tag-autocomplete.d.ts +13 -0
- package/dist/modes/interactive/skill-tag-autocomplete.d.ts.map +1 -0
- package/dist/modes/interactive/skill-tag-autocomplete.js +72 -0
- package/dist/modes/interactive/skill-tag-autocomplete.js.map +1 -0
- package/docs/compaction.md +23 -23
- package/docs/containerization.md +24 -24
- package/docs/custom-provider.md +18 -18
- package/docs/development.md +16 -15
- package/docs/docs.json +6 -2
- package/docs/extensions.md +82 -80
- package/docs/features.md +102 -0
- package/docs/index.md +25 -19
- package/docs/json.md +7 -7
- package/docs/keybindings.md +4 -4
- package/docs/models.md +2 -2
- package/docs/packages.md +38 -42
- package/docs/prompt-templates.md +4 -4
- package/docs/providers.md +22 -10
- package/docs/quickstart.md +81 -46
- package/docs/rpc.md +7 -13
- package/docs/sdk.md +43 -41
- package/docs/security.md +18 -18
- package/docs/session-format.md +9 -9
- package/docs/sessions.md +13 -12
- package/docs/settings.md +63 -24
- package/docs/shell-aliases.md +2 -2
- package/docs/skills.md +21 -11
- package/docs/terminal-setup.md +5 -5
- package/docs/termux.md +7 -7
- package/docs/themes.md +12 -14
- package/docs/tmux.md +4 -4
- package/docs/tui.md +23 -23
- package/docs/usage.md +112 -87
- package/docs/windows.md +10 -2
- package/examples/README.md +3 -1
- package/examples/extensions/README.md +6 -6
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/doom-overlay/README.md +2 -2
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/plan-mode/README.md +3 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/subagent/README.md +13 -11
- package/examples/extensions/todo.ts +2 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/README.md +9 -5
- package/package.json +6 -7
- package/dist/builtin-extensions/lunr-behavior.d.ts +0 -44
- package/dist/builtin-extensions/lunr-behavior.d.ts.map +0 -1
- package/dist/builtin-extensions/lunr-behavior.js +0 -213
- package/dist/builtin-extensions/lunr-behavior.js.map +0 -1
- package/dist/builtin-extensions/pi-subagents/agents/context-builder.md +0 -46
- package/dist/builtin-extensions/pi-subagents/agents/deep-researcher.md +0 -36
- package/dist/builtin-extensions/pi-subagents/agents/delegate.md +0 -12
- package/dist/builtin-extensions/pi-subagents/agents/oracle.md +0 -73
- package/dist/builtin-extensions/pi-subagents/agents/planner.md +0 -55
- package/dist/builtin-extensions/pi-subagents/agents/research-writer.md +0 -37
- package/dist/builtin-extensions/pi-subagents/agents/researcher.md +0 -52
- package/dist/builtin-extensions/pi-subagents/agents/reviewer.md +0 -79
- package/dist/builtin-extensions/pi-subagents/agents/scout.md +0 -50
- package/dist/builtin-extensions/pi-subagents/agents/worker.md +0 -55
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-management.d.ts +0 -20
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-management.d.ts.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-management.js +0 -1273
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-management.js.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-memory.d.ts +0 -49
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-memory.d.ts.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-memory.js +0 -252
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-memory.js.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-scope.d.ts +0 -3
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-scope.d.ts.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-scope.js +0 -6
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-scope.js.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-selection.d.ts +0 -3
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-selection.d.ts.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-selection.js +0 -23
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-selection.js.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-serializer.d.ts +0 -8
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-serializer.d.ts.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-serializer.js +0 -143
- package/dist/builtin-extensions/pi-subagents/src/agents/agent-serializer.js.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/agents/agents.d.ts +0 -176
- package/dist/builtin-extensions/pi-subagents/src/agents/agents.d.ts.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/agents/agents.js +0 -1326
- package/dist/builtin-extensions/pi-subagents/src/agents/agents.js.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/agents/chain-serializer.d.ts +0 -7
- package/dist/builtin-extensions/pi-subagents/src/agents/chain-serializer.d.ts.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/agents/chain-serializer.js +0 -307
- package/dist/builtin-extensions/pi-subagents/src/agents/chain-serializer.js.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/agents/identity.d.ts +0 -8
- package/dist/builtin-extensions/pi-subagents/src/agents/identity.d.ts.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/agents/identity.js +0 -30
- package/dist/builtin-extensions/pi-subagents/src/agents/identity.js.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/agents/proactive-skills.d.ts +0 -35
- package/dist/builtin-extensions/pi-subagents/src/agents/proactive-skills.d.ts.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/agents/proactive-skills.js +0 -151
- package/dist/builtin-extensions/pi-subagents/src/agents/proactive-skills.js.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/profiles/profiles.d.ts +0 -131
- package/dist/builtin-extensions/pi-subagents/src/profiles/profiles.d.ts.map +0 -1
- package/dist/builtin-extensions/pi-subagents/src/profiles/profiles.js +0 -491
- package/dist/builtin-extensions/pi-subagents/src/profiles/profiles.js.map +0 -1
- package/dist/core/behavior-preset.d.ts +0 -60
- package/dist/core/behavior-preset.d.ts.map +0 -1
- package/dist/core/behavior-preset.js +0 -257
- package/dist/core/behavior-preset.js.map +0 -1
|
@@ -1,1326 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/**
|
|
3
|
-
* Agent discovery and configuration
|
|
4
|
-
*/
|
|
5
|
-
import { execSync } from "node:child_process";
|
|
6
|
-
import * as fs from "node:fs";
|
|
7
|
-
import { parse as parseYaml } from "yaml";
|
|
8
|
-
import * as os from "node:os";
|
|
9
|
-
import * as path from "node:path";
|
|
10
|
-
import { fileURLToPath } from "node:url";
|
|
11
|
-
import { getAgentDir, getProjectConfigDir } from "../shared/utils.js";
|
|
12
|
-
import { KNOWN_FIELDS } from "./agent-serializer.js";
|
|
13
|
-
import { parseChain, parseJsonChain } from "./chain-serializer.js";
|
|
14
|
-
import { mergeAgentsForScope } from "./agent-selection.js";
|
|
15
|
-
import { parseFrontmatter } from "./frontmatter.js";
|
|
16
|
-
import { buildRuntimeName, parsePackageName } from "./identity.js";
|
|
17
|
-
import { parseModelScopeConfig } from "../runs/shared/model-scope.js";
|
|
18
|
-
export { buildRuntimeName, frontmatterNameForConfig, parsePackageName } from "./identity.js";
|
|
19
|
-
import { parseMemoryFrontmatter } from "./agent-memory.js";
|
|
20
|
-
import { resolveTurnBudgetConfig } from "../runs/shared/turn-budget.js";
|
|
21
|
-
import { validateAcceptanceInput } from "../runs/shared/acceptance.js";
|
|
22
|
-
export const BUILTIN_AGENT_NAMES = [
|
|
23
|
-
"context-builder",
|
|
24
|
-
"delegate",
|
|
25
|
-
"oracle",
|
|
26
|
-
"planner",
|
|
27
|
-
"researcher",
|
|
28
|
-
"reviewer",
|
|
29
|
-
"scout",
|
|
30
|
-
"worker",
|
|
31
|
-
];
|
|
32
|
-
export function defaultSystemPromptMode(name) {
|
|
33
|
-
return name === "delegate" ? "append" : "replace";
|
|
34
|
-
}
|
|
35
|
-
export function defaultInheritProjectContext(name) {
|
|
36
|
-
return name === "delegate";
|
|
37
|
-
}
|
|
38
|
-
export function defaultInheritSkills() {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
const EMPTY_SUBAGENT_SETTINGS = { overrides: {} };
|
|
42
|
-
const agentFrontmatterFields = new WeakMap();
|
|
43
|
-
function getUserChainDir() {
|
|
44
|
-
return path.join(getAgentDir(), "chains");
|
|
45
|
-
}
|
|
46
|
-
let cachedGlobalNpmRoot = null;
|
|
47
|
-
function readJsonFileBestEffort(filePath) {
|
|
48
|
-
try {
|
|
49
|
-
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
// Installed package scans are opportunistic; bad third-party manifests
|
|
53
|
-
// should not break local agent discovery.
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
function readOptionalJsonFile(filePath) {
|
|
58
|
-
try {
|
|
59
|
-
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
const code = typeof error === "object" && error !== null && "code" in error
|
|
63
|
-
? error.code
|
|
64
|
-
: undefined;
|
|
65
|
-
if (code === "ENOENT")
|
|
66
|
-
return null;
|
|
67
|
-
throw error;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
function isSafePackagePath(value) {
|
|
71
|
-
return value.length > 0
|
|
72
|
-
&& !path.isAbsolute(value)
|
|
73
|
-
&& value.split(/[\\/]/).every((part) => part.length > 0 && part !== "." && part !== "..");
|
|
74
|
-
}
|
|
75
|
-
function parseNpmPackageName(source) {
|
|
76
|
-
const spec = source.slice(4).trim();
|
|
77
|
-
if (!spec)
|
|
78
|
-
return undefined;
|
|
79
|
-
const match = spec.match(/^(@?[^@]+(?:\/[^@]+)?)(?:@(.+))?$/);
|
|
80
|
-
const packageName = match?.[1] ?? spec;
|
|
81
|
-
return isSafePackagePath(packageName) ? packageName : undefined;
|
|
82
|
-
}
|
|
83
|
-
function stripGitRef(repoPath) {
|
|
84
|
-
const atIndex = repoPath.indexOf("@");
|
|
85
|
-
const hashIndex = repoPath.indexOf("#");
|
|
86
|
-
const refIndex = [atIndex, hashIndex].filter((index) => index >= 0).sort((a, b) => a - b)[0];
|
|
87
|
-
return refIndex === undefined ? repoPath : repoPath.slice(0, refIndex);
|
|
88
|
-
}
|
|
89
|
-
function parseGitPackagePath(source) {
|
|
90
|
-
const spec = source.slice(4).trim();
|
|
91
|
-
if (!spec)
|
|
92
|
-
return undefined;
|
|
93
|
-
let host = "";
|
|
94
|
-
let repoPath = "";
|
|
95
|
-
const scpLike = spec.match(/^git@([^:]+):(.+)$/);
|
|
96
|
-
if (scpLike) {
|
|
97
|
-
host = scpLike[1] ?? "";
|
|
98
|
-
repoPath = scpLike[2] ?? "";
|
|
99
|
-
}
|
|
100
|
-
else if (/^[a-z][a-z0-9+.-]*:\/\//i.test(spec)) {
|
|
101
|
-
try {
|
|
102
|
-
const url = new URL(spec);
|
|
103
|
-
host = url.hostname;
|
|
104
|
-
repoPath = url.pathname.replace(/^\/+/, "");
|
|
105
|
-
}
|
|
106
|
-
catch {
|
|
107
|
-
return undefined;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
const slashIndex = spec.indexOf("/");
|
|
112
|
-
if (slashIndex < 0)
|
|
113
|
-
return undefined;
|
|
114
|
-
host = spec.slice(0, slashIndex);
|
|
115
|
-
repoPath = spec.slice(slashIndex + 1);
|
|
116
|
-
}
|
|
117
|
-
const normalizedPath = stripGitRef(repoPath).replace(/\.git$/, "").replace(/^\/+/, "");
|
|
118
|
-
if (!host || !isSafePackagePath(host) || !isSafePackagePath(normalizedPath) || normalizedPath.split(/[\\/]/).length < 2) {
|
|
119
|
-
return undefined;
|
|
120
|
-
}
|
|
121
|
-
return { host, repoPath: normalizedPath };
|
|
122
|
-
}
|
|
123
|
-
function resolveSettingsPackageRoot(source, baseDir) {
|
|
124
|
-
const trimmed = source.trim();
|
|
125
|
-
if (!trimmed)
|
|
126
|
-
return undefined;
|
|
127
|
-
if (trimmed.startsWith("git:")) {
|
|
128
|
-
const parsed = parseGitPackagePath(trimmed);
|
|
129
|
-
return parsed ? path.join(baseDir, "git", parsed.host, parsed.repoPath) : undefined;
|
|
130
|
-
}
|
|
131
|
-
if (trimmed.startsWith("npm:")) {
|
|
132
|
-
const packageName = parseNpmPackageName(trimmed);
|
|
133
|
-
return packageName ? path.join(baseDir, "npm", "node_modules", packageName) : undefined;
|
|
134
|
-
}
|
|
135
|
-
const normalized = trimmed.startsWith("file:") ? trimmed.slice(5) : trimmed;
|
|
136
|
-
if (normalized === "~")
|
|
137
|
-
return os.homedir();
|
|
138
|
-
if (normalized.startsWith("~/"))
|
|
139
|
-
return path.join(os.homedir(), normalized.slice(2));
|
|
140
|
-
if (path.isAbsolute(normalized))
|
|
141
|
-
return normalized;
|
|
142
|
-
if (normalized === "." || normalized === ".." || normalized.startsWith("./") || normalized.startsWith("../")) {
|
|
143
|
-
return path.resolve(baseDir, normalized);
|
|
144
|
-
}
|
|
145
|
-
return undefined;
|
|
146
|
-
}
|
|
147
|
-
function getGlobalNpmRoot() {
|
|
148
|
-
if (cachedGlobalNpmRoot !== null)
|
|
149
|
-
return cachedGlobalNpmRoot;
|
|
150
|
-
try {
|
|
151
|
-
cachedGlobalNpmRoot = fs.realpathSync(execSync("npm root -g", { encoding: "utf-8", timeout: 5000 }).trim());
|
|
152
|
-
return cachedGlobalNpmRoot;
|
|
153
|
-
}
|
|
154
|
-
catch {
|
|
155
|
-
cachedGlobalNpmRoot = "";
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
function stringArray(value) {
|
|
160
|
-
if (!Array.isArray(value))
|
|
161
|
-
return [];
|
|
162
|
-
return value.filter((entry) => typeof entry === "string" && entry.trim().length > 0);
|
|
163
|
-
}
|
|
164
|
-
function extractSubagentPathsFromPackageRoot(packageRoot) {
|
|
165
|
-
const packageJsonPath = path.join(packageRoot, "package.json");
|
|
166
|
-
const pkg = readJsonFileBestEffort(packageJsonPath);
|
|
167
|
-
if (!pkg || typeof pkg !== "object" || Array.isArray(pkg))
|
|
168
|
-
return { agents: [], chains: [] };
|
|
169
|
-
const roots = [];
|
|
170
|
-
const piSubagents = pkg["pi-subagents"];
|
|
171
|
-
if (piSubagents && typeof piSubagents === "object" && !Array.isArray(piSubagents)) {
|
|
172
|
-
roots.push(piSubagents);
|
|
173
|
-
}
|
|
174
|
-
const pi = pkg.pi;
|
|
175
|
-
if (pi && typeof pi === "object" && !Array.isArray(pi)) {
|
|
176
|
-
const subagents = pi.subagents;
|
|
177
|
-
if (subagents && typeof subagents === "object" && !Array.isArray(subagents)) {
|
|
178
|
-
roots.push(subagents);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
const agents = [];
|
|
182
|
-
const chains = [];
|
|
183
|
-
for (const root of roots) {
|
|
184
|
-
for (const entry of stringArray(root.agents))
|
|
185
|
-
agents.push(path.resolve(packageRoot, entry));
|
|
186
|
-
for (const entry of stringArray(root.chains))
|
|
187
|
-
chains.push(path.resolve(packageRoot, entry));
|
|
188
|
-
}
|
|
189
|
-
return { agents, chains };
|
|
190
|
-
}
|
|
191
|
-
function collectPackageRootsFromNodeModules(nodeModulesDir) {
|
|
192
|
-
const roots = [];
|
|
193
|
-
if (!fs.existsSync(nodeModulesDir))
|
|
194
|
-
return roots;
|
|
195
|
-
let entries;
|
|
196
|
-
try {
|
|
197
|
-
entries = fs.readdirSync(nodeModulesDir, { withFileTypes: true });
|
|
198
|
-
}
|
|
199
|
-
catch {
|
|
200
|
-
return roots;
|
|
201
|
-
}
|
|
202
|
-
for (const entry of entries) {
|
|
203
|
-
if (entry.name.startsWith("."))
|
|
204
|
-
continue;
|
|
205
|
-
if (!entry.isDirectory() && !entry.isSymbolicLink())
|
|
206
|
-
continue;
|
|
207
|
-
if (entry.name.startsWith("@")) {
|
|
208
|
-
const scopeDir = path.join(nodeModulesDir, entry.name);
|
|
209
|
-
let scopeEntries;
|
|
210
|
-
try {
|
|
211
|
-
scopeEntries = fs.readdirSync(scopeDir, { withFileTypes: true });
|
|
212
|
-
}
|
|
213
|
-
catch {
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
for (const scopeEntry of scopeEntries) {
|
|
217
|
-
if (scopeEntry.name.startsWith("."))
|
|
218
|
-
continue;
|
|
219
|
-
if (!scopeEntry.isDirectory() && !scopeEntry.isSymbolicLink())
|
|
220
|
-
continue;
|
|
221
|
-
roots.push(path.join(scopeDir, scopeEntry.name));
|
|
222
|
-
}
|
|
223
|
-
continue;
|
|
224
|
-
}
|
|
225
|
-
roots.push(path.join(nodeModulesDir, entry.name));
|
|
226
|
-
}
|
|
227
|
-
return roots;
|
|
228
|
-
}
|
|
229
|
-
function collectSettingsPackageRoots(settingsFile, baseDir) {
|
|
230
|
-
const settings = readOptionalJsonFile(settingsFile);
|
|
231
|
-
if (!settings || typeof settings !== "object" || Array.isArray(settings))
|
|
232
|
-
return [];
|
|
233
|
-
const packages = settings.packages;
|
|
234
|
-
if (!Array.isArray(packages))
|
|
235
|
-
return [];
|
|
236
|
-
const roots = [];
|
|
237
|
-
for (const entry of packages) {
|
|
238
|
-
const packageSource = typeof entry === "string"
|
|
239
|
-
? entry
|
|
240
|
-
: typeof entry === "object" && entry !== null && typeof entry.source === "string"
|
|
241
|
-
? entry.source
|
|
242
|
-
: undefined;
|
|
243
|
-
if (!packageSource)
|
|
244
|
-
continue;
|
|
245
|
-
const packageRoot = resolveSettingsPackageRoot(packageSource, baseDir);
|
|
246
|
-
if (packageRoot)
|
|
247
|
-
roots.push(packageRoot);
|
|
248
|
-
}
|
|
249
|
-
return roots;
|
|
250
|
-
}
|
|
251
|
-
function collectPackageSubagentPaths(cwd, options = { includeUser: true, includeProject: true }) {
|
|
252
|
-
const agentDir = getAgentDir();
|
|
253
|
-
const projectRoot = findNearestProjectRoot(cwd) ?? cwd;
|
|
254
|
-
const packageRoots = [
|
|
255
|
-
projectRoot,
|
|
256
|
-
];
|
|
257
|
-
if (options.includeProject) {
|
|
258
|
-
const projectConfigDir = getProjectConfigDir(projectRoot);
|
|
259
|
-
packageRoots.push(...collectPackageRootsFromNodeModules(path.join(projectConfigDir, "npm", "node_modules")), ...collectSettingsPackageRoots(path.join(projectConfigDir, "settings.json"), projectConfigDir));
|
|
260
|
-
}
|
|
261
|
-
if (options.includeUser) {
|
|
262
|
-
packageRoots.push(...collectPackageRootsFromNodeModules(path.join(agentDir, "npm", "node_modules")), ...collectSettingsPackageRoots(path.join(agentDir, "settings.json"), agentDir));
|
|
263
|
-
}
|
|
264
|
-
if (options.includeUser) {
|
|
265
|
-
const globalRoot = getGlobalNpmRoot();
|
|
266
|
-
if (globalRoot)
|
|
267
|
-
packageRoots.push(...collectPackageRootsFromNodeModules(globalRoot));
|
|
268
|
-
}
|
|
269
|
-
const seenRoots = new Set();
|
|
270
|
-
const seenAgents = new Set();
|
|
271
|
-
const seenChains = new Set();
|
|
272
|
-
const agents = [];
|
|
273
|
-
const chains = [];
|
|
274
|
-
for (const packageRoot of packageRoots) {
|
|
275
|
-
const resolvedRoot = path.resolve(packageRoot);
|
|
276
|
-
if (seenRoots.has(resolvedRoot))
|
|
277
|
-
continue;
|
|
278
|
-
seenRoots.add(resolvedRoot);
|
|
279
|
-
const paths = extractSubagentPathsFromPackageRoot(resolvedRoot);
|
|
280
|
-
for (const agentDir of paths.agents) {
|
|
281
|
-
if (seenAgents.has(agentDir))
|
|
282
|
-
continue;
|
|
283
|
-
seenAgents.add(agentDir);
|
|
284
|
-
agents.push(agentDir);
|
|
285
|
-
}
|
|
286
|
-
for (const chainDir of paths.chains) {
|
|
287
|
-
if (seenChains.has(chainDir))
|
|
288
|
-
continue;
|
|
289
|
-
seenChains.add(chainDir);
|
|
290
|
-
chains.push(chainDir);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
return { agents, chains };
|
|
294
|
-
}
|
|
295
|
-
function splitToolList(rawTools) {
|
|
296
|
-
const mcpDirectTools = [];
|
|
297
|
-
const tools = [];
|
|
298
|
-
for (const tool of rawTools ?? []) {
|
|
299
|
-
if (tool.startsWith("mcp:")) {
|
|
300
|
-
mcpDirectTools.push(tool.slice(4));
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
tools.push(tool);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
return {
|
|
307
|
-
...(tools.length > 0 ? { tools } : {}),
|
|
308
|
-
...(mcpDirectTools.length > 0 ? { mcpDirectTools } : {}),
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
function joinToolList(config) {
|
|
312
|
-
const joined = [
|
|
313
|
-
...(config.tools ?? []),
|
|
314
|
-
...(config.mcpDirectTools ?? []).map((tool) => `mcp:${tool}`),
|
|
315
|
-
];
|
|
316
|
-
return joined.length > 0 ? joined : undefined;
|
|
317
|
-
}
|
|
318
|
-
function arraysEqual(a, b) {
|
|
319
|
-
if (!a && !b)
|
|
320
|
-
return true;
|
|
321
|
-
if (!a || !b)
|
|
322
|
-
return false;
|
|
323
|
-
if (a.length !== b.length)
|
|
324
|
-
return false;
|
|
325
|
-
for (let i = 0; i < a.length; i++) {
|
|
326
|
-
if (a[i] !== b[i])
|
|
327
|
-
return false;
|
|
328
|
-
}
|
|
329
|
-
return true;
|
|
330
|
-
}
|
|
331
|
-
function cloneOverrideBase(agent) {
|
|
332
|
-
return {
|
|
333
|
-
model: agent.model,
|
|
334
|
-
fallbackModels: agent.fallbackModels ? [...agent.fallbackModels] : undefined,
|
|
335
|
-
thinking: agent.thinking,
|
|
336
|
-
systemPromptMode: agent.systemPromptMode,
|
|
337
|
-
inheritProjectContext: agent.inheritProjectContext,
|
|
338
|
-
inheritSkills: agent.inheritSkills,
|
|
339
|
-
defaultContext: agent.defaultContext,
|
|
340
|
-
acceptanceRole: agent.acceptanceRole,
|
|
341
|
-
disabled: agent.disabled,
|
|
342
|
-
systemPrompt: agent.systemPrompt,
|
|
343
|
-
skills: agent.skills ? [...agent.skills] : undefined,
|
|
344
|
-
skillPath: agent.skillPath ? [...agent.skillPath] : undefined,
|
|
345
|
-
tools: agent.tools ? [...agent.tools] : undefined,
|
|
346
|
-
mcpDirectTools: agent.mcpDirectTools ? [...agent.mcpDirectTools] : undefined,
|
|
347
|
-
subagentOnlyExtensions: agent.subagentOnlyExtensions ? [...agent.subagentOnlyExtensions] : undefined,
|
|
348
|
-
completionGuard: agent.completionGuard,
|
|
349
|
-
toolBudget: agent.toolBudget,
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
function cloneOverrideValue(override) {
|
|
353
|
-
return {
|
|
354
|
-
...(override.model !== undefined ? { model: override.model } : {}),
|
|
355
|
-
...(override.fallbackModels !== undefined
|
|
356
|
-
? { fallbackModels: override.fallbackModels === false ? false : [...override.fallbackModels] }
|
|
357
|
-
: {}),
|
|
358
|
-
...(override.thinking !== undefined ? { thinking: override.thinking } : {}),
|
|
359
|
-
...(override.systemPromptMode !== undefined ? { systemPromptMode: override.systemPromptMode } : {}),
|
|
360
|
-
...(override.inheritProjectContext !== undefined ? { inheritProjectContext: override.inheritProjectContext } : {}),
|
|
361
|
-
...(override.inheritSkills !== undefined ? { inheritSkills: override.inheritSkills } : {}),
|
|
362
|
-
...(override.defaultContext !== undefined ? { defaultContext: override.defaultContext } : {}),
|
|
363
|
-
...(override.acceptanceRole !== undefined ? { acceptanceRole: override.acceptanceRole } : {}),
|
|
364
|
-
...(override.disabled !== undefined ? { disabled: override.disabled } : {}),
|
|
365
|
-
...(override.systemPrompt !== undefined ? { systemPrompt: override.systemPrompt } : {}),
|
|
366
|
-
...(override.skills !== undefined ? { skills: override.skills === false ? false : [...override.skills] } : {}),
|
|
367
|
-
...(override.tools !== undefined ? { tools: override.tools === false ? false : [...override.tools] } : {}),
|
|
368
|
-
...(override.subagentOnlyExtensions !== undefined ? { subagentOnlyExtensions: override.subagentOnlyExtensions === false ? false : [...override.subagentOnlyExtensions] } : {}),
|
|
369
|
-
...(override.completionGuard !== undefined ? { completionGuard: override.completionGuard } : {}),
|
|
370
|
-
...(override.toolBudget !== undefined ? { toolBudget: override.toolBudget === false ? false : { ...override.toolBudget, ...(Array.isArray(override.toolBudget.block) ? { block: [...override.toolBudget.block] } : {}) } } : {}),
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
export function findNearestProjectRoot(cwd) {
|
|
374
|
-
let currentDir = cwd;
|
|
375
|
-
while (true) {
|
|
376
|
-
if (isDirectory(getProjectConfigDir(currentDir)) || isDirectory(path.join(currentDir, ".agents"))) {
|
|
377
|
-
return currentDir;
|
|
378
|
-
}
|
|
379
|
-
const parentDir = path.dirname(currentDir);
|
|
380
|
-
if (parentDir === currentDir)
|
|
381
|
-
return null;
|
|
382
|
-
currentDir = parentDir;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
function getUserAgentSettingsPath() {
|
|
386
|
-
return path.join(getAgentDir(), "settings.json");
|
|
387
|
-
}
|
|
388
|
-
function getProjectAgentSettingsPath(cwd) {
|
|
389
|
-
const projectRoot = findNearestProjectRoot(cwd);
|
|
390
|
-
return projectRoot ? path.join(getProjectConfigDir(projectRoot), "settings.json") : null;
|
|
391
|
-
}
|
|
392
|
-
function readSettingsFileStrict(filePath) {
|
|
393
|
-
if (!fs.existsSync(filePath))
|
|
394
|
-
return {};
|
|
395
|
-
let raw;
|
|
396
|
-
try {
|
|
397
|
-
raw = fs.readFileSync(filePath, "utf-8");
|
|
398
|
-
}
|
|
399
|
-
catch (error) {
|
|
400
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
401
|
-
throw new Error(`Failed to read settings file '${filePath}': ${message}`, { cause: error });
|
|
402
|
-
}
|
|
403
|
-
let parsed;
|
|
404
|
-
try {
|
|
405
|
-
parsed = JSON.parse(raw);
|
|
406
|
-
}
|
|
407
|
-
catch (error) {
|
|
408
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
409
|
-
throw new Error(`Failed to parse settings file '${filePath}': ${message}`, { cause: error });
|
|
410
|
-
}
|
|
411
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
412
|
-
throw new Error(`Settings file '${filePath}' must contain a JSON object.`);
|
|
413
|
-
}
|
|
414
|
-
return parsed;
|
|
415
|
-
}
|
|
416
|
-
function writeSettingsFile(filePath, settings) {
|
|
417
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
418
|
-
fs.writeFileSync(filePath, JSON.stringify(settings, null, 2) + "\n", "utf-8");
|
|
419
|
-
}
|
|
420
|
-
function parseOverrideStringArrayOrFalse(value, meta) {
|
|
421
|
-
if (value === undefined)
|
|
422
|
-
return undefined;
|
|
423
|
-
if (value === false)
|
|
424
|
-
return false;
|
|
425
|
-
if (!Array.isArray(value)) {
|
|
426
|
-
throw new Error(`Builtin override '${meta.name}' in '${meta.filePath}' has invalid '${meta.field}'; expected an array of strings or false.`);
|
|
427
|
-
}
|
|
428
|
-
const items = [];
|
|
429
|
-
for (const item of value) {
|
|
430
|
-
if (typeof item !== "string") {
|
|
431
|
-
throw new Error(`Builtin override '${meta.name}' in '${meta.filePath}' has invalid '${meta.field}'; expected an array of strings or false.`);
|
|
432
|
-
}
|
|
433
|
-
const trimmed = item.trim();
|
|
434
|
-
if (trimmed)
|
|
435
|
-
items.push(trimmed);
|
|
436
|
-
}
|
|
437
|
-
return items;
|
|
438
|
-
}
|
|
439
|
-
function parseBuiltinOverrideEntry(name, value, filePath) {
|
|
440
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
441
|
-
throw new Error(`Builtin override '${name}' in '${filePath}' must be an object.`);
|
|
442
|
-
}
|
|
443
|
-
const input = value;
|
|
444
|
-
const override = {};
|
|
445
|
-
if ("model" in input) {
|
|
446
|
-
if (typeof input.model === "string" || input.model === false)
|
|
447
|
-
override.model = input.model;
|
|
448
|
-
else
|
|
449
|
-
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'model'; expected a string or false.`);
|
|
450
|
-
}
|
|
451
|
-
if ("thinking" in input) {
|
|
452
|
-
if (typeof input.thinking === "string" || input.thinking === false)
|
|
453
|
-
override.thinking = input.thinking;
|
|
454
|
-
else
|
|
455
|
-
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'thinking'; expected a string or false.`);
|
|
456
|
-
}
|
|
457
|
-
if ("systemPromptMode" in input) {
|
|
458
|
-
if (input.systemPromptMode === "append" || input.systemPromptMode === "replace") {
|
|
459
|
-
override.systemPromptMode = input.systemPromptMode;
|
|
460
|
-
}
|
|
461
|
-
else {
|
|
462
|
-
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'systemPromptMode'; expected 'append' or 'replace'.`);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
if ("inheritProjectContext" in input) {
|
|
466
|
-
if (typeof input.inheritProjectContext === "boolean") {
|
|
467
|
-
override.inheritProjectContext = input.inheritProjectContext;
|
|
468
|
-
}
|
|
469
|
-
else {
|
|
470
|
-
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'inheritProjectContext'; expected a boolean.`);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
if ("inheritSkills" in input) {
|
|
474
|
-
if (typeof input.inheritSkills === "boolean") {
|
|
475
|
-
override.inheritSkills = input.inheritSkills;
|
|
476
|
-
}
|
|
477
|
-
else {
|
|
478
|
-
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'inheritSkills'; expected a boolean.`);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
if ("defaultContext" in input) {
|
|
482
|
-
if (input.defaultContext === "fresh" || input.defaultContext === "fork" || input.defaultContext === false) {
|
|
483
|
-
override.defaultContext = input.defaultContext;
|
|
484
|
-
}
|
|
485
|
-
else {
|
|
486
|
-
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'defaultContext'; expected 'fresh', 'fork', or false.`);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
if ("acceptanceRole" in input) {
|
|
490
|
-
if (input.acceptanceRole === "read-only" || input.acceptanceRole === "writer" || input.acceptanceRole === false) {
|
|
491
|
-
override.acceptanceRole = input.acceptanceRole;
|
|
492
|
-
}
|
|
493
|
-
else {
|
|
494
|
-
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'acceptanceRole'; expected 'read-only', 'writer', or false.`);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
if ("disabled" in input) {
|
|
498
|
-
if (typeof input.disabled === "boolean") {
|
|
499
|
-
override.disabled = input.disabled;
|
|
500
|
-
}
|
|
501
|
-
else {
|
|
502
|
-
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'disabled'; expected a boolean.`);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
if ("completionGuard" in input) {
|
|
506
|
-
if (typeof input.completionGuard === "boolean") {
|
|
507
|
-
override.completionGuard = input.completionGuard;
|
|
508
|
-
}
|
|
509
|
-
else {
|
|
510
|
-
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'completionGuard'; expected a boolean.`);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
if ("toolBudget" in input) {
|
|
514
|
-
if (input.toolBudget === false) {
|
|
515
|
-
override.toolBudget = false;
|
|
516
|
-
}
|
|
517
|
-
else if (input.toolBudget && typeof input.toolBudget === "object" && !Array.isArray(input.toolBudget)) {
|
|
518
|
-
override.toolBudget = input.toolBudget;
|
|
519
|
-
}
|
|
520
|
-
else {
|
|
521
|
-
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'toolBudget'; expected an object or false.`);
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
if ("systemPrompt" in input) {
|
|
525
|
-
if (typeof input.systemPrompt === "string")
|
|
526
|
-
override.systemPrompt = input.systemPrompt;
|
|
527
|
-
else
|
|
528
|
-
throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'systemPrompt'; expected a string.`);
|
|
529
|
-
}
|
|
530
|
-
const fallbackModels = parseOverrideStringArrayOrFalse(input.fallbackModels, { filePath, name, field: "fallbackModels" });
|
|
531
|
-
if (fallbackModels !== undefined)
|
|
532
|
-
override.fallbackModels = fallbackModels;
|
|
533
|
-
const skills = parseOverrideStringArrayOrFalse(input.skills, { filePath, name, field: "skills" });
|
|
534
|
-
if (skills !== undefined)
|
|
535
|
-
override.skills = skills;
|
|
536
|
-
const tools = parseOverrideStringArrayOrFalse(input.tools, { filePath, name, field: "tools" });
|
|
537
|
-
if (tools !== undefined)
|
|
538
|
-
override.tools = tools;
|
|
539
|
-
const subagentOnlyExtensions = parseOverrideStringArrayOrFalse(input.subagentOnlyExtensions, { filePath, name, field: "subagentOnlyExtensions" });
|
|
540
|
-
if (subagentOnlyExtensions !== undefined)
|
|
541
|
-
override.subagentOnlyExtensions = subagentOnlyExtensions;
|
|
542
|
-
return Object.keys(override).length > 0 ? override : undefined;
|
|
543
|
-
}
|
|
544
|
-
function readSubagentSettings(filePath) {
|
|
545
|
-
if (!filePath)
|
|
546
|
-
return EMPTY_SUBAGENT_SETTINGS;
|
|
547
|
-
const settings = readSettingsFileStrict(filePath);
|
|
548
|
-
const subagents = settings.subagents;
|
|
549
|
-
if (!subagents || typeof subagents !== "object" || Array.isArray(subagents))
|
|
550
|
-
return EMPTY_SUBAGENT_SETTINGS;
|
|
551
|
-
const subagentsObject = subagents;
|
|
552
|
-
let disableBuiltins;
|
|
553
|
-
if ("disableBuiltins" in subagentsObject) {
|
|
554
|
-
if (typeof subagentsObject.disableBuiltins === "boolean") {
|
|
555
|
-
disableBuiltins = subagentsObject.disableBuiltins;
|
|
556
|
-
}
|
|
557
|
-
else {
|
|
558
|
-
throw new Error(`Subagent settings in '${filePath}' have invalid 'disableBuiltins'; expected a boolean.`);
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
let disableThinking;
|
|
562
|
-
if ("disableThinking" in subagentsObject) {
|
|
563
|
-
if (typeof subagentsObject.disableThinking === "boolean") {
|
|
564
|
-
disableThinking = subagentsObject.disableThinking;
|
|
565
|
-
}
|
|
566
|
-
else {
|
|
567
|
-
throw new Error(`Subagent settings in '${filePath}' have invalid 'disableThinking'; expected a boolean.`);
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
let defaultModel;
|
|
571
|
-
if ("defaultModel" in subagentsObject) {
|
|
572
|
-
if (typeof subagentsObject.defaultModel === "string" && subagentsObject.defaultModel.trim()) {
|
|
573
|
-
defaultModel = subagentsObject.defaultModel.trim();
|
|
574
|
-
}
|
|
575
|
-
else {
|
|
576
|
-
throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultModel'; expected a non-empty string.`);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
const modelScope = parseModelScopeConfig(subagentsObject.modelScope, { filePath });
|
|
580
|
-
const parsed = {};
|
|
581
|
-
const agentOverrides = subagentsObject.agentOverrides;
|
|
582
|
-
if (!agentOverrides || typeof agentOverrides !== "object" || Array.isArray(agentOverrides)) {
|
|
583
|
-
return { overrides: parsed, defaultModel, disableBuiltins, disableThinking, modelScope };
|
|
584
|
-
}
|
|
585
|
-
for (const [name, value] of Object.entries(agentOverrides)) {
|
|
586
|
-
const override = parseBuiltinOverrideEntry(name, value, filePath);
|
|
587
|
-
if (override)
|
|
588
|
-
parsed[name] = override;
|
|
589
|
-
}
|
|
590
|
-
return { overrides: parsed, defaultModel, disableBuiltins, disableThinking, modelScope };
|
|
591
|
-
}
|
|
592
|
-
function resolveSubagentDefaultModel(userSettings, projectSettings, userSettingsPath, projectSettingsPath) {
|
|
593
|
-
if (projectSettingsPath && projectSettings.defaultModel !== undefined) {
|
|
594
|
-
return { type: "subagents.defaultModel", scope: "project", path: projectSettingsPath, model: projectSettings.defaultModel };
|
|
595
|
-
}
|
|
596
|
-
return userSettings.defaultModel !== undefined
|
|
597
|
-
? { type: "subagents.defaultModel", scope: "user", path: userSettingsPath, model: userSettings.defaultModel }
|
|
598
|
-
: undefined;
|
|
599
|
-
}
|
|
600
|
-
function applySubagentDefaultModel(agents, defaultModel) {
|
|
601
|
-
if (!defaultModel)
|
|
602
|
-
return agents;
|
|
603
|
-
return agents.map((agent) => {
|
|
604
|
-
if (agent.model !== undefined)
|
|
605
|
-
return agent;
|
|
606
|
-
const next = { ...agent, model: defaultModel.model, modelSource: defaultModel };
|
|
607
|
-
const frontmatterFields = agentFrontmatterFields.get(agent);
|
|
608
|
-
if (frontmatterFields)
|
|
609
|
-
agentFrontmatterFields.set(next, frontmatterFields);
|
|
610
|
-
return next;
|
|
611
|
-
});
|
|
612
|
-
}
|
|
613
|
-
function applyBuiltinOverride(agent, override, meta) {
|
|
614
|
-
const next = {
|
|
615
|
-
...agent,
|
|
616
|
-
override: { ...meta, base: cloneOverrideBase(agent) },
|
|
617
|
-
};
|
|
618
|
-
if (override.model !== undefined)
|
|
619
|
-
next.model = override.model === false ? undefined : override.model;
|
|
620
|
-
if (override.fallbackModels !== undefined) {
|
|
621
|
-
next.fallbackModels = override.fallbackModels === false ? undefined : [...override.fallbackModels];
|
|
622
|
-
}
|
|
623
|
-
if (override.thinking !== undefined)
|
|
624
|
-
next.thinking = override.thinking === false ? undefined : override.thinking;
|
|
625
|
-
if (override.systemPromptMode !== undefined)
|
|
626
|
-
next.systemPromptMode = override.systemPromptMode;
|
|
627
|
-
if (override.inheritProjectContext !== undefined)
|
|
628
|
-
next.inheritProjectContext = override.inheritProjectContext;
|
|
629
|
-
if (override.inheritSkills !== undefined)
|
|
630
|
-
next.inheritSkills = override.inheritSkills;
|
|
631
|
-
if (override.defaultContext !== undefined)
|
|
632
|
-
next.defaultContext = override.defaultContext === false ? undefined : override.defaultContext;
|
|
633
|
-
if (override.acceptanceRole !== undefined)
|
|
634
|
-
next.acceptanceRole = override.acceptanceRole === false ? undefined : override.acceptanceRole;
|
|
635
|
-
if (override.disabled !== undefined)
|
|
636
|
-
next.disabled = override.disabled;
|
|
637
|
-
if (override.systemPrompt !== undefined)
|
|
638
|
-
next.systemPrompt = override.systemPrompt;
|
|
639
|
-
if (override.skills !== undefined)
|
|
640
|
-
next.skills = override.skills === false ? undefined : [...override.skills];
|
|
641
|
-
if (override.tools !== undefined) {
|
|
642
|
-
const { tools, mcpDirectTools } = splitToolList(override.tools === false ? [] : override.tools);
|
|
643
|
-
next.tools = tools;
|
|
644
|
-
next.mcpDirectTools = mcpDirectTools;
|
|
645
|
-
}
|
|
646
|
-
if (override.subagentOnlyExtensions !== undefined) {
|
|
647
|
-
next.subagentOnlyExtensions = override.subagentOnlyExtensions === false ? undefined : [...override.subagentOnlyExtensions];
|
|
648
|
-
}
|
|
649
|
-
if (override.completionGuard !== undefined)
|
|
650
|
-
next.completionGuard = override.completionGuard;
|
|
651
|
-
if (override.toolBudget !== undefined)
|
|
652
|
-
next.toolBudget = override.toolBudget === false ? undefined : override.toolBudget;
|
|
653
|
-
return next;
|
|
654
|
-
}
|
|
655
|
-
function clearBuiltinThinking(agent, meta) {
|
|
656
|
-
if (agent.thinking === undefined)
|
|
657
|
-
return agent;
|
|
658
|
-
return {
|
|
659
|
-
...agent,
|
|
660
|
-
thinking: undefined,
|
|
661
|
-
override: agent.override ?? { ...meta, base: cloneOverrideBase(agent) },
|
|
662
|
-
};
|
|
663
|
-
}
|
|
664
|
-
function applyBuiltinOverrides(builtinAgents, userSettings, projectSettings, userSettingsPath, projectSettingsPath) {
|
|
665
|
-
const projectBulkDisabled = projectSettings.disableBuiltins === true && projectSettingsPath !== null;
|
|
666
|
-
const userBulkDisabled = projectSettings.disableBuiltins === undefined && userSettings.disableBuiltins === true;
|
|
667
|
-
const projectThinkingConfigured = projectSettings.disableThinking !== undefined && projectSettingsPath !== null;
|
|
668
|
-
const disableThinking = projectThinkingConfigured ? projectSettings.disableThinking === true : userSettings.disableThinking === true;
|
|
669
|
-
const disableThinkingMeta = projectThinkingConfigured
|
|
670
|
-
? { scope: "project", path: projectSettingsPath }
|
|
671
|
-
: { scope: "user", path: userSettingsPath };
|
|
672
|
-
const applyGlobalThinking = (agent, hasExplicitThinkingOverride) => {
|
|
673
|
-
if (!disableThinking || hasExplicitThinkingOverride)
|
|
674
|
-
return agent;
|
|
675
|
-
return clearBuiltinThinking(agent, disableThinkingMeta);
|
|
676
|
-
};
|
|
677
|
-
return builtinAgents.map((agent) => {
|
|
678
|
-
const projectOverride = projectSettings.overrides[agent.name];
|
|
679
|
-
if (projectOverride && projectSettingsPath) {
|
|
680
|
-
return applyGlobalThinking(applyBuiltinOverride(agent, projectOverride, { scope: "project", path: projectSettingsPath }), projectOverride.thinking !== undefined);
|
|
681
|
-
}
|
|
682
|
-
if (projectBulkDisabled && projectSettingsPath) {
|
|
683
|
-
return applyGlobalThinking(applyBuiltinOverride(agent, { disabled: true }, { scope: "project", path: projectSettingsPath }), false);
|
|
684
|
-
}
|
|
685
|
-
const userOverride = userSettings.overrides[agent.name];
|
|
686
|
-
if (userOverride) {
|
|
687
|
-
return applyGlobalThinking(applyBuiltinOverride(agent, userOverride, { scope: "user", path: userSettingsPath }), !projectThinkingConfigured && userOverride.thinking !== undefined);
|
|
688
|
-
}
|
|
689
|
-
if (userBulkDisabled) {
|
|
690
|
-
return applyGlobalThinking(applyBuiltinOverride(agent, { disabled: true }, { scope: "user", path: userSettingsPath }), false);
|
|
691
|
-
}
|
|
692
|
-
return applyGlobalThinking(agent, false);
|
|
693
|
-
});
|
|
694
|
-
}
|
|
695
|
-
function customAgentHasFrontmatterField(agent, ...fields) {
|
|
696
|
-
const frontmatterFields = agentFrontmatterFields.get(agent);
|
|
697
|
-
return frontmatterFields ? fields.some((field) => frontmatterFields.has(field)) : false;
|
|
698
|
-
}
|
|
699
|
-
function applyCustomAgentOverride(agent, override, meta) {
|
|
700
|
-
let next;
|
|
701
|
-
let anyFilled = false;
|
|
702
|
-
const mutable = () => {
|
|
703
|
-
next ??= { ...agent };
|
|
704
|
-
return next;
|
|
705
|
-
};
|
|
706
|
-
const fill = (field, frontmatterFields, value) => {
|
|
707
|
-
if (customAgentHasFrontmatterField(agent, ...frontmatterFields))
|
|
708
|
-
return;
|
|
709
|
-
mutable()[field] = value;
|
|
710
|
-
anyFilled = true;
|
|
711
|
-
};
|
|
712
|
-
if (override.model !== undefined) {
|
|
713
|
-
fill("model", ["model"], override.model === false ? undefined : override.model);
|
|
714
|
-
}
|
|
715
|
-
if (override.fallbackModels !== undefined) {
|
|
716
|
-
fill("fallbackModels", ["fallbackModels"], override.fallbackModels === false ? undefined : [...override.fallbackModels]);
|
|
717
|
-
}
|
|
718
|
-
if (override.thinking !== undefined) {
|
|
719
|
-
fill("thinking", ["thinking"], override.thinking === false ? undefined : override.thinking);
|
|
720
|
-
}
|
|
721
|
-
if (override.systemPromptMode !== undefined) {
|
|
722
|
-
fill("systemPromptMode", ["systemPromptMode"], override.systemPromptMode);
|
|
723
|
-
}
|
|
724
|
-
if (override.inheritProjectContext !== undefined) {
|
|
725
|
-
fill("inheritProjectContext", ["inheritProjectContext"], override.inheritProjectContext);
|
|
726
|
-
}
|
|
727
|
-
if (override.inheritSkills !== undefined) {
|
|
728
|
-
fill("inheritSkills", ["inheritSkills"], override.inheritSkills);
|
|
729
|
-
}
|
|
730
|
-
if (override.defaultContext !== undefined) {
|
|
731
|
-
fill("defaultContext", ["defaultContext"], override.defaultContext === false ? undefined : override.defaultContext);
|
|
732
|
-
}
|
|
733
|
-
if (override.acceptanceRole !== undefined) {
|
|
734
|
-
fill("acceptanceRole", ["acceptanceRole"], override.acceptanceRole === false ? undefined : override.acceptanceRole);
|
|
735
|
-
}
|
|
736
|
-
if (override.disabled !== undefined && agent.disabled === undefined) {
|
|
737
|
-
mutable().disabled = override.disabled;
|
|
738
|
-
anyFilled = true;
|
|
739
|
-
}
|
|
740
|
-
if (override.skills !== undefined) {
|
|
741
|
-
fill("skills", ["skill", "skills"], override.skills === false ? undefined : [...override.skills]);
|
|
742
|
-
}
|
|
743
|
-
if (override.tools !== undefined && !customAgentHasFrontmatterField(agent, "tools")) {
|
|
744
|
-
const { tools, mcpDirectTools } = splitToolList(override.tools === false ? [] : override.tools);
|
|
745
|
-
const target = mutable();
|
|
746
|
-
target.tools = tools;
|
|
747
|
-
target.mcpDirectTools = mcpDirectTools;
|
|
748
|
-
anyFilled = true;
|
|
749
|
-
}
|
|
750
|
-
if (override.subagentOnlyExtensions !== undefined) {
|
|
751
|
-
fill("subagentOnlyExtensions", ["subagentOnlyExtensions"], override.subagentOnlyExtensions === false ? undefined : [...override.subagentOnlyExtensions]);
|
|
752
|
-
}
|
|
753
|
-
if (override.completionGuard !== undefined) {
|
|
754
|
-
fill("completionGuard", ["completionGuard"], override.completionGuard);
|
|
755
|
-
}
|
|
756
|
-
if (override.toolBudget !== undefined) {
|
|
757
|
-
fill("toolBudget", ["toolBudget"], override.toolBudget === false ? undefined : override.toolBudget);
|
|
758
|
-
}
|
|
759
|
-
if (!anyFilled || !next)
|
|
760
|
-
return agent;
|
|
761
|
-
next.override = { ...meta, base: cloneOverrideBase(agent) };
|
|
762
|
-
return next;
|
|
763
|
-
}
|
|
764
|
-
function applyCustomAgentOverrides(agents, userSettings, projectSettings, userSettingsPath, projectSettingsPath) {
|
|
765
|
-
return agents.map((agent) => {
|
|
766
|
-
const projectOverride = projectSettings.overrides[agent.name];
|
|
767
|
-
if (projectOverride && projectSettingsPath) {
|
|
768
|
-
return applyCustomAgentOverride(agent, projectOverride, { scope: "project", path: projectSettingsPath });
|
|
769
|
-
}
|
|
770
|
-
const userOverride = userSettings.overrides[agent.name];
|
|
771
|
-
if (userOverride) {
|
|
772
|
-
return applyCustomAgentOverride(agent, userOverride, { scope: "user", path: userSettingsPath });
|
|
773
|
-
}
|
|
774
|
-
return agent;
|
|
775
|
-
});
|
|
776
|
-
}
|
|
777
|
-
export function buildBuiltinOverrideConfig(base, draft) {
|
|
778
|
-
const override = {};
|
|
779
|
-
if (draft.model !== base.model)
|
|
780
|
-
override.model = draft.model ?? false;
|
|
781
|
-
if (!arraysEqual(draft.fallbackModels, base.fallbackModels))
|
|
782
|
-
override.fallbackModels = draft.fallbackModels ? [...draft.fallbackModels] : false;
|
|
783
|
-
if (draft.thinking !== base.thinking)
|
|
784
|
-
override.thinking = draft.thinking ?? false;
|
|
785
|
-
if (draft.systemPromptMode !== base.systemPromptMode)
|
|
786
|
-
override.systemPromptMode = draft.systemPromptMode;
|
|
787
|
-
if (draft.inheritProjectContext !== base.inheritProjectContext)
|
|
788
|
-
override.inheritProjectContext = draft.inheritProjectContext;
|
|
789
|
-
if (draft.inheritSkills !== base.inheritSkills)
|
|
790
|
-
override.inheritSkills = draft.inheritSkills;
|
|
791
|
-
if (draft.defaultContext !== base.defaultContext)
|
|
792
|
-
override.defaultContext = draft.defaultContext ?? false;
|
|
793
|
-
if (draft.acceptanceRole !== base.acceptanceRole)
|
|
794
|
-
override.acceptanceRole = draft.acceptanceRole ?? false;
|
|
795
|
-
if (draft.disabled !== base.disabled)
|
|
796
|
-
override.disabled = draft.disabled ?? false;
|
|
797
|
-
if (draft.systemPrompt !== base.systemPrompt)
|
|
798
|
-
override.systemPrompt = draft.systemPrompt;
|
|
799
|
-
if (!arraysEqual(draft.skills, base.skills))
|
|
800
|
-
override.skills = draft.skills ? [...draft.skills] : false;
|
|
801
|
-
const baseTools = joinToolList(base);
|
|
802
|
-
const draftTools = joinToolList(draft);
|
|
803
|
-
if (!arraysEqual(draftTools, baseTools))
|
|
804
|
-
override.tools = draftTools ? [...draftTools] : false;
|
|
805
|
-
if (!arraysEqual(draft.subagentOnlyExtensions, base.subagentOnlyExtensions)) {
|
|
806
|
-
override.subagentOnlyExtensions = draft.subagentOnlyExtensions ? [...draft.subagentOnlyExtensions] : false;
|
|
807
|
-
}
|
|
808
|
-
if ((draft.completionGuard !== false) !== (base.completionGuard !== false)) {
|
|
809
|
-
override.completionGuard = draft.completionGuard !== false;
|
|
810
|
-
}
|
|
811
|
-
if (JSON.stringify(draft.toolBudget) !== JSON.stringify(base.toolBudget))
|
|
812
|
-
override.toolBudget = draft.toolBudget ?? false;
|
|
813
|
-
return Object.keys(override).length > 0 ? override : undefined;
|
|
814
|
-
}
|
|
815
|
-
export function saveBuiltinAgentOverride(cwd, name, scope, override) {
|
|
816
|
-
const filePath = scope === "project" ? getProjectAgentSettingsPath(cwd) : getUserAgentSettingsPath();
|
|
817
|
-
if (!filePath)
|
|
818
|
-
throw new Error("Project override is not available here. No project config root was found.");
|
|
819
|
-
const settings = readSettingsFileStrict(filePath);
|
|
820
|
-
const subagents = settings.subagents && typeof settings.subagents === "object" && !Array.isArray(settings.subagents)
|
|
821
|
-
? { ...settings.subagents }
|
|
822
|
-
: {};
|
|
823
|
-
const agentOverrides = subagents.agentOverrides && typeof subagents.agentOverrides === "object" && !Array.isArray(subagents.agentOverrides)
|
|
824
|
-
? { ...subagents.agentOverrides }
|
|
825
|
-
: {};
|
|
826
|
-
agentOverrides[name] = cloneOverrideValue(override);
|
|
827
|
-
subagents.agentOverrides = agentOverrides;
|
|
828
|
-
settings.subagents = subagents;
|
|
829
|
-
writeSettingsFile(filePath, settings);
|
|
830
|
-
return filePath;
|
|
831
|
-
}
|
|
832
|
-
export function removeBuiltinAgentOverride(cwd, name, scope) {
|
|
833
|
-
const filePath = scope === "project" ? getProjectAgentSettingsPath(cwd) : getUserAgentSettingsPath();
|
|
834
|
-
if (!filePath)
|
|
835
|
-
throw new Error("Project override is not available here. No project config root was found.");
|
|
836
|
-
if (!fs.existsSync(filePath))
|
|
837
|
-
return { path: filePath, removed: false };
|
|
838
|
-
const settings = readSettingsFileStrict(filePath);
|
|
839
|
-
const subagents = settings.subagents;
|
|
840
|
-
if (!subagents || typeof subagents !== "object" || Array.isArray(subagents))
|
|
841
|
-
return { path: filePath, removed: false };
|
|
842
|
-
const nextSubagents = { ...subagents };
|
|
843
|
-
const agentOverrides = nextSubagents.agentOverrides;
|
|
844
|
-
if (!agentOverrides || typeof agentOverrides !== "object" || Array.isArray(agentOverrides))
|
|
845
|
-
return { path: filePath, removed: false };
|
|
846
|
-
const nextOverrides = { ...agentOverrides };
|
|
847
|
-
if (!Object.prototype.hasOwnProperty.call(nextOverrides, name))
|
|
848
|
-
return { path: filePath, removed: false };
|
|
849
|
-
delete nextOverrides[name];
|
|
850
|
-
if (Object.keys(nextOverrides).length > 0)
|
|
851
|
-
nextSubagents.agentOverrides = nextOverrides;
|
|
852
|
-
else
|
|
853
|
-
delete nextSubagents.agentOverrides;
|
|
854
|
-
if (Object.keys(nextSubagents).length > 0)
|
|
855
|
-
settings.subagents = nextSubagents;
|
|
856
|
-
else
|
|
857
|
-
delete settings.subagents;
|
|
858
|
-
writeSettingsFile(filePath, settings);
|
|
859
|
-
return { path: filePath, removed: true };
|
|
860
|
-
}
|
|
861
|
-
export function mergeBuiltinAgentOverride(cwd, name, scope, fields) {
|
|
862
|
-
const filePath = scope === "project" ? getProjectAgentSettingsPath(cwd) : getUserAgentSettingsPath();
|
|
863
|
-
if (!filePath)
|
|
864
|
-
throw new Error("Project override is not available here. No project config root was found.");
|
|
865
|
-
const settings = readSettingsFileStrict(filePath);
|
|
866
|
-
const subagents = settings.subagents && typeof settings.subagents === "object" && !Array.isArray(settings.subagents)
|
|
867
|
-
? { ...settings.subagents }
|
|
868
|
-
: {};
|
|
869
|
-
const agentOverrides = subagents.agentOverrides && typeof subagents.agentOverrides === "object" && !Array.isArray(subagents.agentOverrides)
|
|
870
|
-
? { ...subagents.agentOverrides }
|
|
871
|
-
: {};
|
|
872
|
-
const existing = agentOverrides[name];
|
|
873
|
-
const base = existing && typeof existing === "object" && !Array.isArray(existing)
|
|
874
|
-
? existing
|
|
875
|
-
: {};
|
|
876
|
-
agentOverrides[name] = { ...base, ...cloneOverrideValue(fields) };
|
|
877
|
-
subagents.agentOverrides = agentOverrides;
|
|
878
|
-
settings.subagents = subagents;
|
|
879
|
-
writeSettingsFile(filePath, settings);
|
|
880
|
-
return filePath;
|
|
881
|
-
}
|
|
882
|
-
export function removeBuiltinAgentOverrideFields(cwd, name, scope, fields) {
|
|
883
|
-
const filePath = scope === "project" ? getProjectAgentSettingsPath(cwd) : getUserAgentSettingsPath();
|
|
884
|
-
if (!filePath)
|
|
885
|
-
throw new Error("Project override is not available here. No project config root was found.");
|
|
886
|
-
if (!fs.existsSync(filePath))
|
|
887
|
-
return { path: filePath, removed: false };
|
|
888
|
-
const settings = readSettingsFileStrict(filePath);
|
|
889
|
-
const subagents = settings.subagents;
|
|
890
|
-
if (!subagents || typeof subagents !== "object" || Array.isArray(subagents))
|
|
891
|
-
return { path: filePath, removed: false };
|
|
892
|
-
const agentOverrides = subagents.agentOverrides;
|
|
893
|
-
if (!agentOverrides || typeof agentOverrides !== "object" || Array.isArray(agentOverrides))
|
|
894
|
-
return { path: filePath, removed: false };
|
|
895
|
-
const entry = agentOverrides[name];
|
|
896
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
897
|
-
return { path: filePath, removed: false };
|
|
898
|
-
const nextEntry = { ...entry };
|
|
899
|
-
let removed = false;
|
|
900
|
-
for (const field of fields) {
|
|
901
|
-
if (Object.prototype.hasOwnProperty.call(nextEntry, field)) {
|
|
902
|
-
delete nextEntry[field];
|
|
903
|
-
removed = true;
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
if (!removed)
|
|
907
|
-
return { path: filePath, removed: false };
|
|
908
|
-
const nextSubagents = { ...subagents };
|
|
909
|
-
if (Object.keys(nextEntry).length > 0) {
|
|
910
|
-
nextSubagents.agentOverrides[name] = nextEntry;
|
|
911
|
-
}
|
|
912
|
-
else {
|
|
913
|
-
const nextOverrides = { ...agentOverrides };
|
|
914
|
-
delete nextOverrides[name];
|
|
915
|
-
if (Object.keys(nextOverrides).length > 0)
|
|
916
|
-
nextSubagents.agentOverrides = nextOverrides;
|
|
917
|
-
else
|
|
918
|
-
delete nextSubagents.agentOverrides;
|
|
919
|
-
}
|
|
920
|
-
if (Object.keys(nextSubagents).length > 0)
|
|
921
|
-
settings.subagents = nextSubagents;
|
|
922
|
-
else
|
|
923
|
-
delete settings.subagents;
|
|
924
|
-
writeSettingsFile(filePath, settings);
|
|
925
|
-
return { path: filePath, removed: true };
|
|
926
|
-
}
|
|
927
|
-
function listFilesRecursive(dir, predicate) {
|
|
928
|
-
const files = [];
|
|
929
|
-
if (!fs.existsSync(dir))
|
|
930
|
-
return files;
|
|
931
|
-
let entries;
|
|
932
|
-
try {
|
|
933
|
-
entries = fs.readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
934
|
-
}
|
|
935
|
-
catch {
|
|
936
|
-
return files;
|
|
937
|
-
}
|
|
938
|
-
for (const entry of entries) {
|
|
939
|
-
const filePath = path.join(dir, entry.name);
|
|
940
|
-
if (entry.isDirectory()) {
|
|
941
|
-
files.push(...listFilesRecursive(filePath, predicate));
|
|
942
|
-
continue;
|
|
943
|
-
}
|
|
944
|
-
if (!entry.isFile() && !entry.isSymbolicLink())
|
|
945
|
-
continue;
|
|
946
|
-
if (!predicate(entry.name))
|
|
947
|
-
continue;
|
|
948
|
-
files.push(filePath);
|
|
949
|
-
}
|
|
950
|
-
return files;
|
|
951
|
-
}
|
|
952
|
-
function isLegacyAgentSkillPath(rootDir, filePath) {
|
|
953
|
-
const relative = path.relative(rootDir, filePath);
|
|
954
|
-
const parts = relative.split(path.sep).map((part) => part.toLowerCase());
|
|
955
|
-
if (path.basename(rootDir).toLowerCase() === ".agents") {
|
|
956
|
-
parts.unshift(".agents");
|
|
957
|
-
}
|
|
958
|
-
return parts.some((part, index) => part === ".agents" && parts[index + 1] === "skills");
|
|
959
|
-
}
|
|
960
|
-
function parseAgentAcceptanceFrontmatter(raw, agentName) {
|
|
961
|
-
if (raw === undefined || !raw.trim())
|
|
962
|
-
return undefined;
|
|
963
|
-
let parsed;
|
|
964
|
-
try {
|
|
965
|
-
parsed = parseYaml(raw);
|
|
966
|
-
}
|
|
967
|
-
catch (error) {
|
|
968
|
-
throw new Error(`Agent '${agentName}' has invalid acceptance frontmatter: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
969
|
-
}
|
|
970
|
-
const errors = validateAcceptanceInput(parsed, `Agent '${agentName}' acceptance frontmatter`);
|
|
971
|
-
if (errors.length > 0)
|
|
972
|
-
throw new Error(errors.join(" "));
|
|
973
|
-
return parsed;
|
|
974
|
-
}
|
|
975
|
-
function loadAgentsFromDir(dir, source) {
|
|
976
|
-
const agents = [];
|
|
977
|
-
for (const filePath of listFilesRecursive(dir, (fileName) => fileName.endsWith(".md") && !fileName.endsWith(".chain.md"))) {
|
|
978
|
-
if (isLegacyAgentSkillPath(dir, filePath)) {
|
|
979
|
-
continue;
|
|
980
|
-
}
|
|
981
|
-
let content;
|
|
982
|
-
try {
|
|
983
|
-
content = fs.readFileSync(filePath, "utf-8");
|
|
984
|
-
}
|
|
985
|
-
catch {
|
|
986
|
-
continue;
|
|
987
|
-
}
|
|
988
|
-
const { frontmatter, body } = parseFrontmatter(content);
|
|
989
|
-
if (!frontmatter.name || !frontmatter.description) {
|
|
990
|
-
continue;
|
|
991
|
-
}
|
|
992
|
-
const localName = frontmatter.name;
|
|
993
|
-
const parsedPackage = parsePackageName(frontmatter.package, `Agent '${localName}' package`);
|
|
994
|
-
if (parsedPackage.error)
|
|
995
|
-
continue;
|
|
996
|
-
const packageName = parsedPackage.packageName;
|
|
997
|
-
const runtimeName = buildRuntimeName(localName, packageName);
|
|
998
|
-
const rawTools = frontmatter.tools
|
|
999
|
-
?.split(",")
|
|
1000
|
-
.map((t) => t.trim())
|
|
1001
|
-
.filter(Boolean);
|
|
1002
|
-
const mcpDirectTools = [];
|
|
1003
|
-
const tools = [];
|
|
1004
|
-
if (rawTools) {
|
|
1005
|
-
for (const tool of rawTools) {
|
|
1006
|
-
if (tool.startsWith("mcp:")) {
|
|
1007
|
-
mcpDirectTools.push(tool.slice(4));
|
|
1008
|
-
}
|
|
1009
|
-
else {
|
|
1010
|
-
tools.push(tool);
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
const defaultReads = frontmatter.defaultReads
|
|
1015
|
-
?.split(",")
|
|
1016
|
-
.map((f) => f.trim())
|
|
1017
|
-
.filter(Boolean);
|
|
1018
|
-
const skillStr = frontmatter.skill || frontmatter.skills;
|
|
1019
|
-
const skills = skillStr
|
|
1020
|
-
?.split(",")
|
|
1021
|
-
.map((s) => s.trim())
|
|
1022
|
-
.filter(Boolean);
|
|
1023
|
-
const skillPath = frontmatter.skillPath
|
|
1024
|
-
?.split(",")
|
|
1025
|
-
.map((entry) => entry.trim())
|
|
1026
|
-
.filter(Boolean);
|
|
1027
|
-
const fallbackModels = frontmatter.fallbackModels
|
|
1028
|
-
?.split(",")
|
|
1029
|
-
.map((model) => model.trim())
|
|
1030
|
-
.filter(Boolean);
|
|
1031
|
-
const systemPromptMode = frontmatter.systemPromptMode === "replace"
|
|
1032
|
-
? "replace"
|
|
1033
|
-
: frontmatter.systemPromptMode === "append"
|
|
1034
|
-
? "append"
|
|
1035
|
-
: defaultSystemPromptMode(localName);
|
|
1036
|
-
const inheritProjectContext = frontmatter.inheritProjectContext === "true"
|
|
1037
|
-
? true
|
|
1038
|
-
: frontmatter.inheritProjectContext === "false"
|
|
1039
|
-
? false
|
|
1040
|
-
: defaultInheritProjectContext(localName);
|
|
1041
|
-
const inheritSkills = frontmatter.inheritSkills === "true"
|
|
1042
|
-
? true
|
|
1043
|
-
: frontmatter.inheritSkills === "false"
|
|
1044
|
-
? false
|
|
1045
|
-
: defaultInheritSkills();
|
|
1046
|
-
const defaultContext = frontmatter.defaultContext === "fork"
|
|
1047
|
-
? "fork"
|
|
1048
|
-
: frontmatter.defaultContext === "fresh"
|
|
1049
|
-
? "fresh"
|
|
1050
|
-
: undefined;
|
|
1051
|
-
let defaultAsync;
|
|
1052
|
-
if (frontmatter.async !== undefined) {
|
|
1053
|
-
if (frontmatter.async === "true")
|
|
1054
|
-
defaultAsync = true;
|
|
1055
|
-
else if (frontmatter.async === "false")
|
|
1056
|
-
defaultAsync = false;
|
|
1057
|
-
else
|
|
1058
|
-
throw new Error(`Agent '${localName}' has invalid async frontmatter; expected true or false.`);
|
|
1059
|
-
}
|
|
1060
|
-
let defaultTimeoutMs;
|
|
1061
|
-
if (frontmatter.timeoutMs !== undefined) {
|
|
1062
|
-
const parsed = Number(frontmatter.timeoutMs);
|
|
1063
|
-
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
1064
|
-
throw new Error(`Agent '${localName}' has invalid timeoutMs frontmatter; expected a positive integer.`);
|
|
1065
|
-
}
|
|
1066
|
-
defaultTimeoutMs = parsed;
|
|
1067
|
-
}
|
|
1068
|
-
let defaultTurnBudget;
|
|
1069
|
-
if (frontmatter.turnBudget !== undefined && frontmatter.turnBudget.trim()) {
|
|
1070
|
-
const parsed = JSON.parse(frontmatter.turnBudget);
|
|
1071
|
-
const resolved = resolveTurnBudgetConfig(parsed, `Agent '${localName}' turnBudget frontmatter`);
|
|
1072
|
-
if (resolved.error)
|
|
1073
|
-
throw new Error(resolved.error);
|
|
1074
|
-
defaultTurnBudget = resolved.turnBudget;
|
|
1075
|
-
}
|
|
1076
|
-
const defaultAcceptance = parseAgentAcceptanceFrontmatter(frontmatter.acceptance, localName);
|
|
1077
|
-
let acceptanceRole;
|
|
1078
|
-
if (frontmatter.acceptanceRole !== undefined && frontmatter.acceptanceRole.trim()) {
|
|
1079
|
-
if (frontmatter.acceptanceRole === "read-only" || frontmatter.acceptanceRole === "writer")
|
|
1080
|
-
acceptanceRole = frontmatter.acceptanceRole;
|
|
1081
|
-
else
|
|
1082
|
-
throw new Error(`Agent '${localName}' has invalid acceptanceRole frontmatter; expected 'read-only' or 'writer'.`);
|
|
1083
|
-
}
|
|
1084
|
-
let extensions;
|
|
1085
|
-
if (frontmatter.extensions !== undefined) {
|
|
1086
|
-
extensions = frontmatter.extensions
|
|
1087
|
-
.split(",")
|
|
1088
|
-
.map((e) => e.trim())
|
|
1089
|
-
.filter(Boolean);
|
|
1090
|
-
}
|
|
1091
|
-
let subagentOnlyExtensions;
|
|
1092
|
-
if (frontmatter.subagentOnlyExtensions !== undefined) {
|
|
1093
|
-
subagentOnlyExtensions = frontmatter.subagentOnlyExtensions
|
|
1094
|
-
.split(",")
|
|
1095
|
-
.map((e) => e.trim())
|
|
1096
|
-
.filter(Boolean);
|
|
1097
|
-
}
|
|
1098
|
-
const extraFields = {};
|
|
1099
|
-
for (const [key, value] of Object.entries(frontmatter)) {
|
|
1100
|
-
if (!KNOWN_FIELDS.has(key))
|
|
1101
|
-
extraFields[key] = value;
|
|
1102
|
-
}
|
|
1103
|
-
const parsedMaxSubagentDepth = Number(frontmatter.maxSubagentDepth);
|
|
1104
|
-
let toolBudget;
|
|
1105
|
-
if (frontmatter.toolBudget !== undefined && frontmatter.toolBudget.trim()) {
|
|
1106
|
-
const parsed = JSON.parse(frontmatter.toolBudget);
|
|
1107
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
1108
|
-
throw new Error(`Agent '${localName}' has invalid toolBudget frontmatter; expected a JSON object.`);
|
|
1109
|
-
}
|
|
1110
|
-
toolBudget = parsed;
|
|
1111
|
-
}
|
|
1112
|
-
const completionGuard = frontmatter.completionGuard === "false"
|
|
1113
|
-
? false
|
|
1114
|
-
: frontmatter.completionGuard === "true"
|
|
1115
|
-
? true
|
|
1116
|
-
: undefined;
|
|
1117
|
-
const agent = {
|
|
1118
|
-
name: runtimeName,
|
|
1119
|
-
localName,
|
|
1120
|
-
packageName,
|
|
1121
|
-
description: frontmatter.description,
|
|
1122
|
-
tools: tools.length > 0 ? tools : undefined,
|
|
1123
|
-
mcpDirectTools: mcpDirectTools.length > 0 ? mcpDirectTools : undefined,
|
|
1124
|
-
model: frontmatter.model,
|
|
1125
|
-
fallbackModels: fallbackModels && fallbackModels.length > 0 ? fallbackModels : undefined,
|
|
1126
|
-
thinking: frontmatter.thinking === "false" ? false : frontmatter.thinking,
|
|
1127
|
-
systemPromptMode,
|
|
1128
|
-
inheritProjectContext,
|
|
1129
|
-
inheritSkills,
|
|
1130
|
-
defaultContext,
|
|
1131
|
-
defaultAsync,
|
|
1132
|
-
defaultTimeoutMs,
|
|
1133
|
-
defaultTurnBudget,
|
|
1134
|
-
defaultAcceptance,
|
|
1135
|
-
acceptanceRole,
|
|
1136
|
-
systemPrompt: body,
|
|
1137
|
-
source,
|
|
1138
|
-
filePath,
|
|
1139
|
-
skills: skills && skills.length > 0 ? skills : undefined,
|
|
1140
|
-
skillPath: skillPath && skillPath.length > 0 ? skillPath : undefined,
|
|
1141
|
-
extensions,
|
|
1142
|
-
subagentOnlyExtensions,
|
|
1143
|
-
output: frontmatter.output,
|
|
1144
|
-
defaultReads: defaultReads && defaultReads.length > 0 ? defaultReads : undefined,
|
|
1145
|
-
defaultProgress: frontmatter.defaultProgress === "true",
|
|
1146
|
-
interactive: frontmatter.interactive === "true",
|
|
1147
|
-
maxSubagentDepth: Number.isInteger(parsedMaxSubagentDepth) && parsedMaxSubagentDepth >= 0
|
|
1148
|
-
? parsedMaxSubagentDepth
|
|
1149
|
-
: undefined,
|
|
1150
|
-
completionGuard,
|
|
1151
|
-
toolBudget,
|
|
1152
|
-
memory: parseMemoryFrontmatter(frontmatter.memory),
|
|
1153
|
-
extraFields: Object.keys(extraFields).length > 0 ? extraFields : undefined,
|
|
1154
|
-
};
|
|
1155
|
-
agentFrontmatterFields.set(agent, new Set(Object.keys(frontmatter)));
|
|
1156
|
-
agents.push(agent);
|
|
1157
|
-
}
|
|
1158
|
-
return agents;
|
|
1159
|
-
}
|
|
1160
|
-
function loadChainsFromDir(dir, source) {
|
|
1161
|
-
const chains = new Map();
|
|
1162
|
-
const diagnostics = [];
|
|
1163
|
-
for (const filePath of listFilesRecursive(dir, (fileName) => fileName.endsWith(".chain.md") || fileName.endsWith(".chain.json"))) {
|
|
1164
|
-
let content;
|
|
1165
|
-
try {
|
|
1166
|
-
content = fs.readFileSync(filePath, "utf-8");
|
|
1167
|
-
}
|
|
1168
|
-
catch {
|
|
1169
|
-
continue;
|
|
1170
|
-
}
|
|
1171
|
-
try {
|
|
1172
|
-
const chain = filePath.endsWith(".chain.json") ? parseJsonChain(content, source, filePath) : parseChain(content, source, filePath);
|
|
1173
|
-
const existing = chains.get(chain.name);
|
|
1174
|
-
if (existing && existing.filePath.endsWith(".chain.json") && filePath.endsWith(".chain.md"))
|
|
1175
|
-
continue;
|
|
1176
|
-
chains.set(chain.name, chain);
|
|
1177
|
-
}
|
|
1178
|
-
catch (error) {
|
|
1179
|
-
diagnostics.push({ source, filePath, error: error instanceof Error ? error.message : String(error) });
|
|
1180
|
-
continue;
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1183
|
-
return { chains: Array.from(chains.values()), diagnostics };
|
|
1184
|
-
}
|
|
1185
|
-
function isDirectory(p) {
|
|
1186
|
-
try {
|
|
1187
|
-
return fs.statSync(p).isDirectory();
|
|
1188
|
-
}
|
|
1189
|
-
catch {
|
|
1190
|
-
return false;
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
function resolveNearestProjectAgentDirs(cwd) {
|
|
1194
|
-
const projectRoot = findNearestProjectRoot(cwd);
|
|
1195
|
-
if (!projectRoot)
|
|
1196
|
-
return { readDirs: [], preferredDir: null };
|
|
1197
|
-
const legacyDir = path.join(projectRoot, ".agents");
|
|
1198
|
-
const preferredDir = path.join(getProjectConfigDir(projectRoot), "agents");
|
|
1199
|
-
const readDirs = [];
|
|
1200
|
-
if (isDirectory(legacyDir))
|
|
1201
|
-
readDirs.push(legacyDir);
|
|
1202
|
-
if (isDirectory(preferredDir))
|
|
1203
|
-
readDirs.push(preferredDir);
|
|
1204
|
-
return {
|
|
1205
|
-
readDirs,
|
|
1206
|
-
preferredDir,
|
|
1207
|
-
};
|
|
1208
|
-
}
|
|
1209
|
-
function resolveNearestProjectChainDirs(cwd) {
|
|
1210
|
-
const projectRoot = findNearestProjectRoot(cwd);
|
|
1211
|
-
if (!projectRoot)
|
|
1212
|
-
return { readDirs: [], preferredDir: null };
|
|
1213
|
-
const preferredDir = path.join(getProjectConfigDir(projectRoot), "chains");
|
|
1214
|
-
return {
|
|
1215
|
-
readDirs: isDirectory(preferredDir) ? [preferredDir] : [],
|
|
1216
|
-
preferredDir,
|
|
1217
|
-
};
|
|
1218
|
-
}
|
|
1219
|
-
const BUILTIN_AGENTS_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "agents");
|
|
1220
|
-
export const EXTRA_AGENT_DIRS_ENV = "PI_SUBAGENT_EXTRA_AGENT_DIRS";
|
|
1221
|
-
// Additional read-only directories to scan for agent definitions, supplied by the
|
|
1222
|
-
// launcher via PI_SUBAGENT_EXTRA_AGENT_DIRS (PATH-style, split on os/path delimiter).
|
|
1223
|
-
// Lets a hermetic wrapper (e.g. a Nix-store install) expose bundled agents without
|
|
1224
|
-
// copying or symlinking them into the writable agent dir. Loaded as "user" source,
|
|
1225
|
-
// at lower precedence than agents the user placed in their own agent dir.
|
|
1226
|
-
function extraUserAgentDirs() {
|
|
1227
|
-
const raw = process.env[EXTRA_AGENT_DIRS_ENV];
|
|
1228
|
-
if (!raw)
|
|
1229
|
-
return [];
|
|
1230
|
-
return raw
|
|
1231
|
-
.split(path.delimiter)
|
|
1232
|
-
.map((dir) => dir.trim())
|
|
1233
|
-
.filter((dir) => dir.length > 0);
|
|
1234
|
-
}
|
|
1235
|
-
export function discoverAgents(cwd, scope) {
|
|
1236
|
-
const userDirOld = path.join(getAgentDir(), "agents");
|
|
1237
|
-
const userDirNew = path.join(os.homedir(), ".agents");
|
|
1238
|
-
const { readDirs: projectAgentDirs, preferredDir: projectAgentsDir } = resolveNearestProjectAgentDirs(cwd);
|
|
1239
|
-
const userSettingsPath = getUserAgentSettingsPath();
|
|
1240
|
-
const projectSettingsPath = getProjectAgentSettingsPath(cwd);
|
|
1241
|
-
const userSettings = scope === "project" ? EMPTY_SUBAGENT_SETTINGS : readSubagentSettings(userSettingsPath);
|
|
1242
|
-
const projectSettings = scope === "user" ? EMPTY_SUBAGENT_SETTINGS : readSubagentSettings(projectSettingsPath);
|
|
1243
|
-
const defaultModel = resolveSubagentDefaultModel(userSettings, projectSettings, userSettingsPath, projectSettingsPath);
|
|
1244
|
-
const modelScope = projectSettings.modelScope ?? userSettings.modelScope;
|
|
1245
|
-
const packageSubagentPaths = collectPackageSubagentPaths(cwd, {
|
|
1246
|
-
includeUser: scope !== "project",
|
|
1247
|
-
includeProject: scope !== "user",
|
|
1248
|
-
});
|
|
1249
|
-
const builtinAgents = applyBuiltinOverrides(applySubagentDefaultModel(loadAgentsFromDir(BUILTIN_AGENTS_DIR, "builtin"), defaultModel), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
|
|
1250
|
-
const userAgentsExtra = scope === "project" ? [] : extraUserAgentDirs().flatMap((dir) => loadAgentsFromDir(dir, "user"));
|
|
1251
|
-
const userAgentsOld = scope === "project" ? [] : loadAgentsFromDir(userDirOld, "user");
|
|
1252
|
-
const userAgentsNew = scope === "project" ? [] : loadAgentsFromDir(userDirNew, "user");
|
|
1253
|
-
const userAgents = applyCustomAgentOverrides(applySubagentDefaultModel([...userAgentsExtra, ...userAgentsOld, ...userAgentsNew], defaultModel), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
|
|
1254
|
-
const projectAgents = applyCustomAgentOverrides(applySubagentDefaultModel(scope === "user" ? [] : projectAgentDirs.flatMap((dir) => loadAgentsFromDir(dir, "project")), defaultModel), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
|
|
1255
|
-
const packageAgents = applyCustomAgentOverrides(applySubagentDefaultModel(packageSubagentPaths.agents.flatMap((dir) => loadAgentsFromDir(dir, "package")), defaultModel), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
|
|
1256
|
-
const agents = mergeAgentsForScope(scope, userAgents, projectAgents, builtinAgents, packageAgents)
|
|
1257
|
-
.filter((agent) => agent.disabled !== true);
|
|
1258
|
-
return { agents, projectAgentsDir, modelScope };
|
|
1259
|
-
}
|
|
1260
|
-
export function discoverAgentsAll(cwd) {
|
|
1261
|
-
const userDirOld = path.join(getAgentDir(), "agents");
|
|
1262
|
-
const userDirNew = path.join(os.homedir(), ".agents");
|
|
1263
|
-
const userChainDir = getUserChainDir();
|
|
1264
|
-
const { readDirs: projectDirs, preferredDir: projectDir } = resolveNearestProjectAgentDirs(cwd);
|
|
1265
|
-
const { readDirs: projectChainDirs, preferredDir: projectChainDir } = resolveNearestProjectChainDirs(cwd);
|
|
1266
|
-
const userSettingsPath = getUserAgentSettingsPath();
|
|
1267
|
-
const projectSettingsPath = getProjectAgentSettingsPath(cwd);
|
|
1268
|
-
const userSettings = readSubagentSettings(userSettingsPath);
|
|
1269
|
-
const projectSettings = readSubagentSettings(projectSettingsPath);
|
|
1270
|
-
const defaultModel = resolveSubagentDefaultModel(userSettings, projectSettings, userSettingsPath, projectSettingsPath);
|
|
1271
|
-
const packageSubagentPaths = collectPackageSubagentPaths(cwd);
|
|
1272
|
-
const builtin = applyBuiltinOverrides(applySubagentDefaultModel(loadAgentsFromDir(BUILTIN_AGENTS_DIR, "builtin"), defaultModel), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
|
|
1273
|
-
const user = applyCustomAgentOverrides(applySubagentDefaultModel([
|
|
1274
|
-
...extraUserAgentDirs().flatMap((dir) => loadAgentsFromDir(dir, "user")),
|
|
1275
|
-
...loadAgentsFromDir(userDirOld, "user"),
|
|
1276
|
-
...loadAgentsFromDir(userDirNew, "user"),
|
|
1277
|
-
], defaultModel), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
|
|
1278
|
-
const packageMap = new Map();
|
|
1279
|
-
for (const dir of packageSubagentPaths.agents) {
|
|
1280
|
-
for (const agent of loadAgentsFromDir(dir, "package")) {
|
|
1281
|
-
if (!packageMap.has(agent.name))
|
|
1282
|
-
packageMap.set(agent.name, agent);
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
const packageAgents = applyCustomAgentOverrides(applySubagentDefaultModel(Array.from(packageMap.values()), defaultModel), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
|
|
1286
|
-
const projectMap = new Map();
|
|
1287
|
-
for (const dir of projectDirs) {
|
|
1288
|
-
for (const agent of loadAgentsFromDir(dir, "project")) {
|
|
1289
|
-
projectMap.set(agent.name, agent);
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
const project = applyCustomAgentOverrides(applySubagentDefaultModel(Array.from(projectMap.values()), defaultModel), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
|
|
1293
|
-
const chainMap = new Map();
|
|
1294
|
-
const packageChainDiagnostics = [];
|
|
1295
|
-
const packageChainMap = new Map();
|
|
1296
|
-
for (const dir of packageSubagentPaths.chains) {
|
|
1297
|
-
const loaded = loadChainsFromDir(dir, "package");
|
|
1298
|
-
packageChainDiagnostics.push(...loaded.diagnostics);
|
|
1299
|
-
for (const chain of loaded.chains) {
|
|
1300
|
-
if (!packageChainMap.has(chain.name))
|
|
1301
|
-
packageChainMap.set(chain.name, chain);
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
const projectChainDiagnostics = [];
|
|
1305
|
-
for (const dir of projectChainDirs) {
|
|
1306
|
-
const loaded = loadChainsFromDir(dir, "project");
|
|
1307
|
-
projectChainDiagnostics.push(...loaded.diagnostics);
|
|
1308
|
-
for (const chain of loaded.chains) {
|
|
1309
|
-
chainMap.set(chain.name, chain);
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
const userChains = loadChainsFromDir(userChainDir, "user");
|
|
1313
|
-
const chains = [
|
|
1314
|
-
...Array.from(packageChainMap.values()),
|
|
1315
|
-
...userChains.chains,
|
|
1316
|
-
...Array.from(chainMap.values()),
|
|
1317
|
-
];
|
|
1318
|
-
const chainDiagnostics = [
|
|
1319
|
-
...packageChainDiagnostics,
|
|
1320
|
-
...userChains.diagnostics,
|
|
1321
|
-
...projectChainDiagnostics,
|
|
1322
|
-
];
|
|
1323
|
-
const userDir = process.env.PI_CODING_AGENT_DIR ? userDirOld : fs.existsSync(userDirNew) ? userDirNew : userDirOld;
|
|
1324
|
-
return { builtin, package: packageAgents, user, project, chains, chainDiagnostics, userDir, projectDir, userChainDir, projectChainDir, userSettingsPath, projectSettingsPath };
|
|
1325
|
-
}
|
|
1326
|
-
//# sourceMappingURL=agents.js.map
|