dal-code 1.0.24 → 1.0.26
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 +42 -0
- package/NOTICE +7 -0
- package/dal-docs/README.md +109 -0
- package/dal-docs/extensions.md +98 -0
- package/dal-docs/keybindings.md +40 -0
- package/dal-docs/packages.md +62 -0
- package/dal-docs/prompt-templates.md +42 -0
- package/dal-docs/settings.md +86 -0
- package/dal-docs/skills.md +65 -0
- package/dal-docs/themes.md +44 -0
- package/dist/cli/args.d.ts +59 -0
- package/dist/cli/args.js +14 -14
- package/dist/config.d.ts +63 -0
- package/dist/config.js +1 -1
- package/dist/core/agent-session-runtime.d.ts +74 -0
- package/dist/core/agent-session-services.d.ts +50 -0
- package/dist/core/agent-session-services.js +1 -1
- package/dist/core/agent-session.d.ts +422 -0
- package/dist/core/agent-session.js +8 -7
- package/dist/core/auth-storage.d.ts +56 -0
- package/dist/core/background-processes.d.ts +73 -0
- package/dist/core/background-processes.js +7 -0
- package/dist/core/bash-executor.d.ts +13 -0
- package/dist/core/cache-warmer.d.ts +60 -0
- package/dist/core/compaction/branch-summarization.d.ts +43 -0
- package/dist/core/compaction/compaction.d.ts +62 -0
- package/dist/core/compaction/index.d.ts +3 -0
- package/dist/core/compaction/utils.d.ts +16 -0
- package/dist/core/diagnostics.d.ts +14 -0
- package/dist/core/event-bus.d.ts +8 -0
- package/dist/core/exec.d.ts +12 -0
- package/dist/core/extensions/index.d.ts +8 -0
- package/dist/core/extensions/loader.d.ts +13 -0
- package/dist/core/extensions/loader.js +1 -1
- package/dist/core/extensions/permission-surface.js +1 -1
- package/dist/core/extensions/runner.d.ts +165 -0
- package/dist/core/extensions/runner.js +1 -1
- package/dist/core/extensions/types.d.ts +1003 -0
- package/dist/core/extensions/wrapper.d.ts +5 -0
- package/dist/core/footer-data-provider.d.ts +46 -0
- package/dist/core/host-capabilities.d.ts +50 -0
- package/dist/core/host-capabilities.js +2 -0
- package/dist/core/keybindings.d.ts +525 -0
- package/dist/core/messages.d.ts +50 -0
- package/dist/core/model-config.d.ts +1212 -0
- package/dist/core/model-registry.d.ts +41 -0
- package/dist/core/model-resolver.d.ts +67 -0
- package/dist/core/model-resolver.js +1 -1
- package/dist/core/model-runtime.d.ts +101 -0
- package/dist/core/model-runtime.js +2 -2
- package/dist/core/package-manager.d.ts +213 -0
- package/dist/core/package-manager.js +2 -2
- package/dist/core/permissions/rules.d.ts +45 -0
- package/dist/core/permissions/rules.js +1 -0
- package/dist/core/permissions/shell-words.js +2 -0
- package/dist/core/permissions/tool-policy.d.ts +46 -0
- package/dist/core/permissions/tool-policy.js +1 -0
- package/dist/core/project-map.d.ts +18 -0
- package/dist/core/prompt-templates.d.ts +24 -0
- package/dist/core/provider-composer.d.ts +55 -0
- package/dist/core/remote-catalog-provider.js +1 -1
- package/dist/core/resolve-config-value.d.ts +11 -0
- package/dist/core/resource-loader.d.ts +220 -0
- package/dist/core/resource-loader.js +1 -1
- package/dist/core/sandbox/availability.d.ts +9 -0
- package/dist/core/sandbox/availability.js +1 -0
- package/dist/core/sandbox/denial.d.ts +25 -0
- package/dist/core/sandbox/denial.js +3 -0
- package/dist/core/sandbox/index.d.ts +5 -0
- package/dist/core/sandbox/index.js +1 -0
- package/dist/core/sandbox/policy.d.ts +66 -0
- package/dist/core/sandbox/policy.js +1 -0
- package/dist/core/sandbox/runtime.d.ts +31 -0
- package/dist/core/sandbox/runtime.js +1 -0
- package/dist/core/sandbox/shell-sandbox.d.ts +119 -0
- package/dist/core/sandbox/shell-sandbox.js +5 -0
- package/dist/core/sdk.d.ts +43 -0
- package/dist/core/sdk.js +1 -1
- package/dist/core/session-manager.d.ts +208 -0
- package/dist/core/settings-manager.d.ts +368 -0
- package/dist/core/settings-manager.js +1 -1
- package/dist/core/skills.d.ts +33 -0
- package/dist/core/slash-commands.d.ts +14 -0
- package/dist/core/source-info.d.ts +17 -0
- package/dist/core/system-prompt.d.ts +39 -0
- package/dist/core/system-prompt.js +15 -11
- package/dist/core/tools/bash.d.ts +89 -0
- package/dist/core/tools/bash.js +16 -14
- package/dist/core/tools/edit-diff.d.ts +44 -0
- package/dist/core/tools/edit.d.ts +48 -0
- package/dist/core/tools/file-mutation-queue.d.ts +1 -0
- package/dist/core/tools/find.d.ts +34 -0
- package/dist/core/tools/find.js +11 -11
- package/dist/core/tools/grep.d.ts +34 -0
- package/dist/core/tools/grep.js +10 -10
- package/dist/core/tools/index.d.ts +43 -0
- package/dist/core/tools/index.js +1 -1
- package/dist/core/tools/ls.d.ts +33 -0
- package/dist/core/tools/ls.js +6 -6
- package/dist/core/tools/powershell.d.ts +17 -0
- package/dist/core/tools/powershell.js +2 -2
- package/dist/core/tools/process.d.ts +26 -0
- package/dist/core/tools/process.js +22 -0
- package/dist/core/tools/read.d.ts +33 -0
- package/dist/core/tools/read.js +15 -15
- package/dist/core/tools/renderers/bash.d.ts +3 -0
- package/dist/core/tools/renderers/edit.d.ts +15 -0
- package/dist/core/tools/renderers/find.d.ts +2 -0
- package/dist/core/tools/renderers/grep.d.ts +2 -0
- package/dist/core/tools/renderers/index.d.ts +13 -0
- package/dist/core/tools/renderers/ls.d.ts +2 -0
- package/dist/core/tools/renderers/read.d.ts +3 -0
- package/dist/core/tools/renderers/read.js +8 -8
- package/dist/core/tools/renderers/write.d.ts +2 -0
- package/dist/core/tools/truncate.d.ts +27 -0
- package/dist/core/tools/write.d.ts +24 -0
- package/dist/core/trust-manager.d.ts +28 -0
- package/dist/core/trust-manager.js +2 -2
- package/dist/dal/builtins.js +2 -2
- package/dist/dal/child-env.d.ts +12 -0
- package/dist/dal/child-env.js +1 -0
- package/dist/dal/hooks/activity.d.ts +17 -0
- package/dist/dal/hooks/activity.js +1 -0
- package/dist/dal/hooks/config.d.ts +47 -0
- package/dist/dal/hooks/config.js +1 -0
- package/dist/dal/hooks/events.d.ts +43 -0
- package/dist/dal/hooks/events.js +4 -0
- package/dist/dal/hooks/extension.d.ts +3 -0
- package/dist/dal/hooks/extension.js +4 -0
- package/dist/dal/hooks/index.d.ts +5 -0
- package/dist/dal/hooks/index.js +1 -0
- package/dist/dal/hooks/runner.d.ts +57 -0
- package/dist/dal/hooks/runner.js +1 -0
- package/dist/dal/manifest.d.ts +32 -0
- package/dist/dal/manifest.js +1 -0
- package/dist/dal/safety-net.js +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +1 -1
- package/dist/main.d.ts +9 -0
- package/dist/main.js +4 -4
- package/dist/modes/acp/acp-mode.d.ts +2 -0
- package/dist/modes/index.d.ts +7 -0
- package/dist/modes/interactive/components/armin.d.ts +30 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +26 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +22 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts +14 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts +11 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +11 -0
- package/dist/modes/interactive/components/config-selector.js +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +21 -0
- package/dist/modes/interactive/components/custom-message.d.ts +17 -0
- package/dist/modes/interactive/components/daxnuts.d.ts +17 -0
- package/dist/modes/interactive/components/diff.d.ts +4 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts +12 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +19 -0
- package/dist/modes/interactive/components/extension-input.d.ts +21 -0
- package/dist/modes/interactive/components/extension-selector.d.ts +22 -0
- package/dist/modes/interactive/components/first-time-setup.d.ts +23 -0
- package/dist/modes/interactive/components/footer.d.ts +18 -0
- package/dist/modes/interactive/components/footer.js +1 -1
- package/dist/modes/interactive/components/index.d.ts +33 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts +9 -0
- package/dist/modes/interactive/components/login-dialog.d.ts +27 -0
- package/dist/modes/interactive/components/model-selector.d.ts +81 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts +29 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +39 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts +20 -0
- package/dist/modes/interactive/components/session-selector.d.ts +88 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +92 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts +6 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +11 -0
- package/dist/modes/interactive/components/status-indicator.d.ts +44 -0
- package/dist/modes/interactive/components/theme-selector.d.ts +7 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +19 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +76 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +65 -0
- package/dist/modes/interactive/components/trust-selector.d.ts +22 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts +23 -0
- package/dist/modes/interactive/components/user-message.d.ts +14 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts +5 -0
- package/dist/modes/interactive/interactive-mode.d.ts +326 -0
- package/dist/modes/interactive/theme/theme-json.d.ts +257 -0
- package/dist/modes/interactive/theme/theme.d.ts +106 -0
- package/dist/modes/interactive/tui-renderer.d.ts +18 -0
- package/dist/modes/json-event.d.ts +26 -0
- package/dist/modes/print-mode.d.ts +9 -0
- package/dist/modes/print-mode.js +6 -4
- package/dist/modes/rpc/rpc-client.d.ts +142 -0
- package/dist/modes/rpc/rpc-client.js +4 -1
- package/dist/modes/rpc/rpc-mode.d.ts +3 -0
- package/dist/modes/rpc/rpc-mode.js +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +565 -0
- package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-bridge/src/ask-user.js +12 -0
- package/dist/node_modules/@dalcode/dal-bridge/src/client.js +1 -1
- package/dist/node_modules/@dalcode/dal-bridge/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-gateway/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-guard/package.json +5 -4
- package/dist/node_modules/@dalcode/dal-guard/src/hooks.js +1 -0
- package/dist/node_modules/@dalcode/dal-guard/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-interactive/LICENSE +21 -0
- package/dist/node_modules/@dalcode/dal-interactive/package.json +33 -0
- package/dist/node_modules/@dalcode/dal-interactive/src/handoff.js +28 -0
- package/dist/node_modules/@dalcode/dal-interactive/src/index.js +1 -0
- package/dist/node_modules/@dalcode/dal-interactive/src/interactive-shell.js +1 -0
- package/dist/node_modules/@dalcode/dal-interactive/src/questionnaire.js +3 -0
- package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-lsp/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-lsp/src/client.js +3 -3
- package/dist/node_modules/@dalcode/dal-mcp/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-mcp/src/command-parser.d.ts +19 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/config-edit.d.ts +19 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/config.d.ts +9 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/http-client.d.ts +16 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.d.ts +22 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.js +2 -2
- package/dist/node_modules/@dalcode/dal-mcp/src/types.d.ts +30 -0
- package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-office/src/extract/csv.d.ts +3 -0
- package/dist/node_modules/@dalcode/dal-office/src/extract/csv.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/extract/ooxml.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/index.d.ts +11 -0
- package/dist/node_modules/@dalcode/dal-office/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/paths.d.ts +3 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/chart.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/render/docx.d.ts +19 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/pptx.d.ts +40 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/pptx.js +2 -2
- package/dist/node_modules/@dalcode/dal-office/src/render/thumbnails.d.ts +19 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/thumbnails.js +1 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.d.ts +14 -0
- package/dist/node_modules/@dalcode/dal-office/src/scratchpad.d.ts +16 -0
- package/dist/node_modules/@dalcode/dal-office/src/themes.d.ts +13 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/docx-edit.js +10 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/edit-shared.js +1 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/pptx-edit.js +9 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/read-file.js +4 -2
- package/dist/node_modules/@dalcode/dal-office/src/tools/xlsx-edit.js +5 -0
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +2 -2
- package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +2 -2
- package/dist/node_modules/@dalcode/dal-plugins/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-review/LICENSE +21 -0
- package/dist/node_modules/@dalcode/dal-review/package.json +34 -0
- package/dist/node_modules/@dalcode/dal-review/src/args.d.ts +13 -0
- package/dist/node_modules/@dalcode/dal-review/src/args.js +1 -0
- package/dist/node_modules/@dalcode/dal-review/src/core.d.ts +6 -0
- package/dist/node_modules/@dalcode/dal-review/src/core.js +1 -0
- package/dist/node_modules/@dalcode/dal-review/src/findings.d.ts +23 -0
- package/dist/node_modules/@dalcode/dal-review/src/findings.js +4 -0
- package/dist/node_modules/@dalcode/dal-review/src/index.js +1 -0
- package/dist/node_modules/@dalcode/dal-review/src/prompt.d.ts +3 -0
- package/dist/node_modules/@dalcode/dal-review/src/prompt.js +29 -0
- package/dist/node_modules/@dalcode/dal-review/src/runner.d.ts +91 -0
- package/dist/node_modules/@dalcode/dal-review/src/runner.js +2 -0
- package/dist/node_modules/@dalcode/dal-review/src/targets.d.ts +33 -0
- package/dist/node_modules/@dalcode/dal-review/src/targets.js +17 -0
- package/dist/node_modules/@dalcode/dal-review/src/types.d.ts +94 -0
- package/dist/node_modules/@dalcode/dal-review/src/types.js +1 -0
- package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-rewind/src/core.d.ts +61 -0
- package/dist/node_modules/@dalcode/dal-router/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-router/src/config.d.ts +50 -0
- package/dist/node_modules/@dalcode/dal-router/src/jev.d.ts +51 -0
- package/dist/node_modules/@dalcode/dal-router/src/pool.d.ts +6 -0
- package/dist/node_modules/@dalcode/dal-router/src/router.d.ts +32 -0
- package/dist/node_modules/@dalcode/dal-router/src/runtime.d.ts +37 -0
- package/dist/node_modules/@dalcode/dal-skills/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-skills/src/discover.js +4 -4
- package/dist/node_modules/@dalcode/dal-skills/src/index.js +9 -9
- package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-subagent/src/agents.js +2 -2
- package/dist/node_modules/@dalcode/dal-subagent/src/index.js +12 -12
- package/dist/node_modules/@dalcode/dal-subagent/src/process-runner.js +3 -3
- package/dist/node_modules/@dalcode/dal-telemetry/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-terminal/LICENSE +21 -0
- package/dist/node_modules/@dalcode/dal-terminal/package.json +33 -0
- package/dist/node_modules/@dalcode/dal-terminal/src/contract.d.ts +60 -0
- package/dist/node_modules/@dalcode/dal-terminal/src/contract.js +7 -0
- package/dist/node_modules/@dalcode/dal-terminal/src/index.js +6 -0
- package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-tool-catalog/src/groups.js +1 -1
- package/dist/node_modules/@dalcode/dal-web/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-web/src/config.js +2 -2
- package/dist/node_modules/@dalcode/dal-web/src/index.js +4 -4
- package/dist/node_modules/@dalcode/dal-web/src/search.js +4 -4
- package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-workflow/src/index.js +4 -4
- package/dist/node_modules/@dalcode/dal-workflow/src/plan-mode.js +13 -13
- package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
- package/dist/node_modules/@dalcode/deepailab/src/index.js +3 -3
- package/dist/node_modules/@dalcode/deepailab/src/model-defaults.js +1 -1
- package/dist/node_modules/@earendil-works/chord/dist/api.d.ts +21 -0
- package/dist/node_modules/@earendil-works/chord/dist/context/index.d.ts +12 -0
- package/dist/node_modules/@earendil-works/chord/dist/delta/index.d.ts +127 -0
- package/dist/node_modules/@earendil-works/chord/dist/index.d.ts +8 -0
- package/dist/node_modules/@earendil-works/chord/dist/json.d.ts +2 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/errors.d.ts +16 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/provider.d.ts +32 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state-codec.d.ts +12 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/wire.d.ts +59 -0
- package/dist/node_modules/@earendil-works/chord/dist/state/draft.d.ts +13 -0
- package/dist/node_modules/@earendil-works/chord/dist/types.d.ts +188 -0
- package/dist/node_modules/@earendil-works/chord/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts +11 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +1 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts +80 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.d.ts +711 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/branch-summarization.d.ts +44 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.d.ts +80 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/utils.d.ts +15 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/context.d.ts +6 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/events.d.ts +22 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/execution/effect-gate.d.ts +17 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/hooks.d.ts +34 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/messages.d.ts +50 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/prompt-templates.d.ts +28 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/result.d.ts +132 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/harness.d.ts +56 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/lane.d.ts +94 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/reducer.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/runtime/types.d.ts +99 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/commit.d.ts +52 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/fork-policy.d.ts +19 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/fork.d.ts +13 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/index.d.ts +10 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/index.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/repo.d.ts +33 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/storage.d.ts +37 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/types.d.ts +36 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory.d.ts +46 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/mutation-line.d.ts +6 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.d.ts +75 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/types.d.ts +473 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/values.d.ts +94 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/skills.d.ts +26 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/system-prompt.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/telemetry.d.ts +1495 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/bash.d.ts +26 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/edit.d.ts +18 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/index.d.ts +5 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/read.d.ts +32 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/tool-context.d.ts +4 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/write.d.ts +10 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/types.d.ts +185 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/output-capture.d.ts +22 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.d.ts +22 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/truncate.d.ts +28 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts +27 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/proxy.d.ts +61 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/search/index.d.ts +28 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/stream-fn.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts +150 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/package.json +4 -4
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts +18 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.lazy.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.d.ts +13 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.lazy.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.d.ts +18 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.lazy.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.d.ts +12 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.lazy.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.d.ts +24 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.d.ts +14 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.lazy.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/lazy.d.ts +8 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.d.ts +15 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.lazy.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.d.ts +30 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.lazy.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts +24 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.lazy.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.d.ts +10 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.lazy.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.d.ts +85 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.lazy.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/auth/context.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/auth/credential-store.d.ts +10 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/auth/helpers.d.ts +8 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts +20 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts +127 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/cli.js +0 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.d.ts +34 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/compat.d.ts +47 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/env-api-keys.d.ts +9 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.d.ts +9 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts +829 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/images-api-registry.d.ts +13 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/images-models.d.ts +37 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/images.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/index.d.ts +38 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/legacy-api-aliases.d.ts +25 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/model-catalog.d.ts +16 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/models-store.d.ts +21 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/models.d.ts +97 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts +84 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/all.d.ts +18 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/ant-ling.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/baseten.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/cerebras.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/azure-openai-responses.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/deepseek.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/faux.d.ts +100 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/fireworks.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/google.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/groq.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/huggingface.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/images/register-builtins.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/meta.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/minimax-cn.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/minimax.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/mistral.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/nvidia.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openai.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan-cn.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan-individual.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/radius.d.ts +7 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/radius.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/together.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-ams.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-cn.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-sgp.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/zai-coding-cn.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/zai.models.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/session-resources.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/types.d.ts +502 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/assistant-message-frame.d.ts +63 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/diagnostics.d.ts +19 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.d.ts +19 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/json-parse.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts +4 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts +16 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/text.d.ts +6 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/transcript.d.ts +29 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/typebox-helpers.d.ts +5 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/uuid.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/validation.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-client/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-coding-agent/LICENSE +21 -0
- package/dist/node_modules/@earendil-works/pi-coding-agent/index.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-coding-agent/index.js +1 -0
- package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +15 -0
- package/dist/node_modules/@earendil-works/pi-protocol/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-server/package.json +5 -5
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/index.d.ts +200 -0
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/memory.d.ts +20 -0
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/noop.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.d.ts +55 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/box.d.ts +20 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.d.ts +9 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/editor.d.ts +151 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/h-stack.d.ts +6 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/image.d.ts +25 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.d.ts +43 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/loader.d.ts +28 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/markdown.d.ts +61 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/mouse-region.d.ts +10 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/scroll-view.d.ts +61 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/select-list.d.ts +52 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/settings-list.d.ts +50 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/spacer.d.ts +8 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/stack.d.ts +35 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/text.d.ts +15 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.d.ts +9 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/v-stack.d.ts +7 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/editor-component.d.ts +17 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.d.ts +6 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/index.d.ts +32 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/keybindings.d.ts +329 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/keys.d.ts +101 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/latex.d.ts +4 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/layout-node.d.ts +41 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/native-platform.d.ts +13 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.d.ts +30 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/terminal-colors.d.ts +9 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/terminal-image.d.ts +82 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts +76 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts +138 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-main-screen.d.ts +32 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +252 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/utils.d.ts +38 -0
- package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/dist/package-manager-cli.js +32 -32
- package/dist/sdk/index.d.ts +18 -0
- package/dist/sdk/index.js +1 -0
- package/dist/sdk/mcp.d.ts +8 -0
- package/dist/sdk/mcp.js +1 -0
- package/dist/sdk/office.d.ts +1 -0
- package/dist/sdk/office.js +1 -0
- package/dist/sdk/review.d.ts +1 -0
- package/dist/sdk/review.js +1 -0
- package/dist/sdk/rewind.d.ts +1 -0
- package/dist/sdk/rewind.js +1 -0
- package/dist/sdk/router.d.ts +6 -0
- package/dist/sdk/router.js +1 -0
- package/dist/sdk/subagents.d.ts +8 -0
- package/dist/sdk/subagents.js +1 -0
- package/dist/utils/clipboard.d.ts +2 -0
- package/dist/utils/frontmatter.d.ts +7 -0
- package/dist/utils/image-convert.d.ts +5 -0
- package/dist/utils/image-resize-core.d.ts +16 -0
- package/dist/utils/image-resize.d.ts +4 -0
- package/dist/utils/mime.d.ts +2 -0
- package/dist/utils/shell.d.ts +20 -0
- package/dist/utils/shell.js +3 -3
- package/dist/utils/version-check.d.ts +20 -0
- 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/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/index.ts +6 -0
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +75 -5
- package/package.json +27 -1
- package/dist/bun/register-bedrock.js +0 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/reducer.js +0 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/errors.js +0 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.js +0 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.js +0 -5
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl.js +0 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.js +0 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.js +0 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo-utils.js +0 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/state.js +0 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/conformance.js +0 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/search/scanning.js +0 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/cloudflare-gateway-binding.js +0 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/deferred-tools.js +0 -1
- package/dist/node_modules/@earendil-works/pi-client/dist/session-handle.js +0 -1
- package/dist/node_modules/@earendil-works/pi-client/dist/state.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/cli.js +0 -16
- package/dist/node_modules/@earendil-works/pi-server/dist/config.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/handler.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/client.js +0 -2
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/protocol.js +0 -2
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/server.js +0 -3
- package/dist/node_modules/@earendil-works/pi-server/dist/protocol.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/radius.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/rpc-process.js +0 -4
- package/dist/node_modules/@earendil-works/pi-server/dist/serve.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/sessions.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/snapshots.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/storage.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/supervisor.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/service.js +0 -1
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/branch-cache.js +0 -7
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/search-backend.js +0 -36
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-entries.js +0 -25
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-tips.js +0 -2
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/entries.js +0 -7
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/facts.js +0 -20
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/lanes.js +0 -26
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/records.js +0 -9
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-sequences.js +0 -1
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-stats.js +0 -10
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/sessions.js +0 -29
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/writer-leases.js +0 -14
- package/dist/server/create-harness.js +0 -1
- package/dist/utils/clipboard-native.js +0 -1
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { type Theme } from "../modes/interactive/theme/theme.ts";
|
|
2
|
+
import type { ResourceDiagnostic } from "./diagnostics.ts";
|
|
3
|
+
export type { ResourceCollision, ResourceDiagnostic } from "./diagnostics.ts";
|
|
4
|
+
import { type EventBus } from "./event-bus.ts";
|
|
5
|
+
import type { InlineExtension, LoadExtensionsResult } from "./extensions/types.ts";
|
|
6
|
+
import { type PathMetadata } from "./package-manager.ts";
|
|
7
|
+
import type { PromptTemplate } from "./prompt-templates.ts";
|
|
8
|
+
import { SettingsManager } from "./settings-manager.ts";
|
|
9
|
+
import type { Skill } from "./skills.ts";
|
|
10
|
+
export interface ResourceExtensionPaths {
|
|
11
|
+
skillPaths?: Array<{
|
|
12
|
+
path: string;
|
|
13
|
+
metadata: PathMetadata;
|
|
14
|
+
}>;
|
|
15
|
+
promptPaths?: Array<{
|
|
16
|
+
path: string;
|
|
17
|
+
metadata: PathMetadata;
|
|
18
|
+
}>;
|
|
19
|
+
themePaths?: Array<{
|
|
20
|
+
path: string;
|
|
21
|
+
metadata: PathMetadata;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
export interface ResourceLoaderReloadOptions {
|
|
25
|
+
resolveProjectTrust?: (input: {
|
|
26
|
+
extensionsResult: LoadExtensionsResult;
|
|
27
|
+
}) => Promise<boolean>;
|
|
28
|
+
}
|
|
29
|
+
export interface ResourceLoader {
|
|
30
|
+
getExtensions(): LoadExtensionsResult;
|
|
31
|
+
getSkills(): {
|
|
32
|
+
skills: Skill[];
|
|
33
|
+
diagnostics: ResourceDiagnostic[];
|
|
34
|
+
};
|
|
35
|
+
getPrompts(): {
|
|
36
|
+
prompts: PromptTemplate[];
|
|
37
|
+
diagnostics: ResourceDiagnostic[];
|
|
38
|
+
};
|
|
39
|
+
getThemes(): {
|
|
40
|
+
themes: Theme[];
|
|
41
|
+
diagnostics: ResourceDiagnostic[];
|
|
42
|
+
};
|
|
43
|
+
getAgentsFiles(): {
|
|
44
|
+
agentsFiles: Array<{
|
|
45
|
+
path: string;
|
|
46
|
+
content: string;
|
|
47
|
+
}>;
|
|
48
|
+
};
|
|
49
|
+
getSystemPrompt(): string | undefined;
|
|
50
|
+
getSystemPromptSource(): {
|
|
51
|
+
path: string;
|
|
52
|
+
} | undefined;
|
|
53
|
+
getAppendSystemPrompt(): string[];
|
|
54
|
+
getAppendSystemPromptSources(): Array<{
|
|
55
|
+
path: string;
|
|
56
|
+
}>;
|
|
57
|
+
extendResources(paths: ResourceExtensionPaths): void;
|
|
58
|
+
reload(options?: ResourceLoaderReloadOptions): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
export declare function loadProjectContextFiles(options: {
|
|
61
|
+
cwd: string;
|
|
62
|
+
agentDir: string;
|
|
63
|
+
}): Array<{
|
|
64
|
+
path: string;
|
|
65
|
+
content: string;
|
|
66
|
+
}>;
|
|
67
|
+
export interface DefaultResourceLoaderOptions {
|
|
68
|
+
cwd: string;
|
|
69
|
+
agentDir: string;
|
|
70
|
+
settingsManager?: SettingsManager;
|
|
71
|
+
eventBus?: EventBus;
|
|
72
|
+
additionalExtensionPaths?: string[];
|
|
73
|
+
additionalSkillPaths?: string[];
|
|
74
|
+
additionalPromptTemplatePaths?: string[];
|
|
75
|
+
additionalThemePaths?: string[];
|
|
76
|
+
extensionFactories?: InlineExtension[];
|
|
77
|
+
noExtensions?: boolean;
|
|
78
|
+
noSkills?: boolean;
|
|
79
|
+
noPromptTemplates?: boolean;
|
|
80
|
+
noThemes?: boolean;
|
|
81
|
+
noContextFiles?: boolean;
|
|
82
|
+
systemPrompt?: string;
|
|
83
|
+
appendSystemPrompt?: string[];
|
|
84
|
+
extensionsOverride?: (base: LoadExtensionsResult) => LoadExtensionsResult;
|
|
85
|
+
skillsOverride?: (base: {
|
|
86
|
+
skills: Skill[];
|
|
87
|
+
diagnostics: ResourceDiagnostic[];
|
|
88
|
+
}) => {
|
|
89
|
+
skills: Skill[];
|
|
90
|
+
diagnostics: ResourceDiagnostic[];
|
|
91
|
+
};
|
|
92
|
+
promptsOverride?: (base: {
|
|
93
|
+
prompts: PromptTemplate[];
|
|
94
|
+
diagnostics: ResourceDiagnostic[];
|
|
95
|
+
}) => {
|
|
96
|
+
prompts: PromptTemplate[];
|
|
97
|
+
diagnostics: ResourceDiagnostic[];
|
|
98
|
+
};
|
|
99
|
+
themesOverride?: (base: {
|
|
100
|
+
themes: Theme[];
|
|
101
|
+
diagnostics: ResourceDiagnostic[];
|
|
102
|
+
}) => {
|
|
103
|
+
themes: Theme[];
|
|
104
|
+
diagnostics: ResourceDiagnostic[];
|
|
105
|
+
};
|
|
106
|
+
agentsFilesOverride?: (base: {
|
|
107
|
+
agentsFiles: Array<{
|
|
108
|
+
path: string;
|
|
109
|
+
content: string;
|
|
110
|
+
}>;
|
|
111
|
+
}) => {
|
|
112
|
+
agentsFiles: Array<{
|
|
113
|
+
path: string;
|
|
114
|
+
content: string;
|
|
115
|
+
}>;
|
|
116
|
+
};
|
|
117
|
+
systemPromptOverride?: (base: string | undefined) => string | undefined;
|
|
118
|
+
appendSystemPromptOverride?: (base: string[]) => string[];
|
|
119
|
+
}
|
|
120
|
+
export declare class DefaultResourceLoader implements ResourceLoader {
|
|
121
|
+
private cwd;
|
|
122
|
+
private agentDir;
|
|
123
|
+
private settingsManager;
|
|
124
|
+
private eventBus;
|
|
125
|
+
private packageManager;
|
|
126
|
+
private additionalExtensionPaths;
|
|
127
|
+
private additionalSkillPaths;
|
|
128
|
+
private additionalPromptTemplatePaths;
|
|
129
|
+
private additionalThemePaths;
|
|
130
|
+
private extensionFactories;
|
|
131
|
+
private noExtensions;
|
|
132
|
+
private noSkills;
|
|
133
|
+
private noPromptTemplates;
|
|
134
|
+
private noThemes;
|
|
135
|
+
private noContextFiles;
|
|
136
|
+
private systemPromptSource?;
|
|
137
|
+
private appendSystemPromptSource?;
|
|
138
|
+
private extensionsOverride?;
|
|
139
|
+
private skillsOverride?;
|
|
140
|
+
private promptsOverride?;
|
|
141
|
+
private themesOverride?;
|
|
142
|
+
private agentsFilesOverride?;
|
|
143
|
+
private systemPromptOverride?;
|
|
144
|
+
private appendSystemPromptOverride?;
|
|
145
|
+
private extensionsResult;
|
|
146
|
+
private skills;
|
|
147
|
+
private skillDiagnostics;
|
|
148
|
+
private prompts;
|
|
149
|
+
private promptDiagnostics;
|
|
150
|
+
private themes;
|
|
151
|
+
private themeDiagnostics;
|
|
152
|
+
private agentsFiles;
|
|
153
|
+
private systemPrompt?;
|
|
154
|
+
private systemPromptSourcePath?;
|
|
155
|
+
private appendSystemPrompt;
|
|
156
|
+
private appendSystemPromptSourcePaths;
|
|
157
|
+
private lastSkillPaths;
|
|
158
|
+
private extensionSkillSourceInfos;
|
|
159
|
+
private extensionPromptSourceInfos;
|
|
160
|
+
private extensionThemeSourceInfos;
|
|
161
|
+
private resourceMetadataByPath;
|
|
162
|
+
private lastPromptPaths;
|
|
163
|
+
private lastThemePaths;
|
|
164
|
+
private loaded;
|
|
165
|
+
constructor(options: DefaultResourceLoaderOptions);
|
|
166
|
+
getExtensions(): LoadExtensionsResult;
|
|
167
|
+
getSkills(): {
|
|
168
|
+
skills: Skill[];
|
|
169
|
+
diagnostics: ResourceDiagnostic[];
|
|
170
|
+
};
|
|
171
|
+
getPrompts(): {
|
|
172
|
+
prompts: PromptTemplate[];
|
|
173
|
+
diagnostics: ResourceDiagnostic[];
|
|
174
|
+
};
|
|
175
|
+
getThemes(): {
|
|
176
|
+
themes: Theme[];
|
|
177
|
+
diagnostics: ResourceDiagnostic[];
|
|
178
|
+
};
|
|
179
|
+
getAgentsFiles(): {
|
|
180
|
+
agentsFiles: Array<{
|
|
181
|
+
path: string;
|
|
182
|
+
content: string;
|
|
183
|
+
}>;
|
|
184
|
+
};
|
|
185
|
+
getSystemPrompt(): string | undefined;
|
|
186
|
+
getSystemPromptSource(): {
|
|
187
|
+
path: string;
|
|
188
|
+
} | undefined;
|
|
189
|
+
getAppendSystemPrompt(): string[];
|
|
190
|
+
getAppendSystemPromptSources(): Array<{
|
|
191
|
+
path: string;
|
|
192
|
+
}>;
|
|
193
|
+
extendResources(paths: ResourceExtensionPaths): void;
|
|
194
|
+
loadProjectTrustExtensions(): Promise<LoadExtensionsResult>;
|
|
195
|
+
reload(options?: ResourceLoaderReloadOptions): Promise<void>;
|
|
196
|
+
private loadCurrentExtensionSet;
|
|
197
|
+
private resolveExtensionLoadPath;
|
|
198
|
+
private loadFinalExtensionSet;
|
|
199
|
+
private addExtensionConflictDiagnostics;
|
|
200
|
+
private mapSkillPath;
|
|
201
|
+
private normalizeExtensionPaths;
|
|
202
|
+
private updateSkillsFromPaths;
|
|
203
|
+
private updatePromptsFromPaths;
|
|
204
|
+
private updateThemesFromPaths;
|
|
205
|
+
private applyExtensionSourceInfo;
|
|
206
|
+
private findSourceInfoForPath;
|
|
207
|
+
private getDefaultSourceInfoForPath;
|
|
208
|
+
private mergePaths;
|
|
209
|
+
private resolveResourcePath;
|
|
210
|
+
private loadThemes;
|
|
211
|
+
private loadThemesFromDir;
|
|
212
|
+
private loadThemeFromFile;
|
|
213
|
+
private loadExtensionFactories;
|
|
214
|
+
private dedupePrompts;
|
|
215
|
+
private dedupeThemes;
|
|
216
|
+
private discoverSystemPromptFile;
|
|
217
|
+
private discoverAppendSystemPromptFile;
|
|
218
|
+
private isUnderPath;
|
|
219
|
+
private detectExtensionConflicts;
|
|
220
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var Z=Object.defineProperty;var P=(p,t)=>Z(p,"name",{value:t,configurable:!0});import{existsSync as u,readdirSync as tt,readFileSync as _,statSync as w}from"node:fs";import{basename as et,dirname as K,join as m,resolve as y,sep as D}from"node:path";import q from"chalk";import{CONFIG_DIR_NAME as x,getExamplesPath as st}from"../config.js";import{fill as H,t as M}from"../dal/i18n.js";import{loadThemeFromPath as ot}from"../modes/interactive/theme/theme.js";import{canonicalizePath as k,isLocalPath as b,resolvePath as g}from"../utils/paths.js";import{stripBom as J}from"../utils/text.js";import{createEventBus as it}from"./event-bus.js";import{clearExtensionCache as nt,createExtensionRuntime as rt,loadExtensionFromFactory as at,loadExtensionsCached as R}from"./extensions/loader.js";import{findGitPaths as ht}from"./footer-data-provider.js";import{DefaultPackageManager as lt}from"./package-manager.js";import{loadPromptTemplates as ct}from"./prompt-templates.js";import{SettingsManager as mt}from"./settings-manager.js";import{loadSkills as dt}from"./skills.js";import{createSourceInfo as E}from"./source-info.js";import{resetTimings as pt}from"./timings.js";function Q(p,t){if(p){if(u(p))try{return J(_(p,"utf-8"))}catch(o){return console.error(q.yellow(H(M("\u8B66\u544A\uFF1A\u65E0\u6CD5\u8BFB\u53D6{what}\u6587\u4EF6 {path}\uFF1A{error}"),{what:t,path:p,error:String(o)}))),p}return p}}P(Q,"resolvePromptInput");function C(p){const t=["AGENTS.override.md","AGENTS.md","AGENTS.MD","CLAUDE.md","CLAUDE.MD"];for(const o of t){const s=m(p,o);if(u(s))try{if(!w(s).isFile())continue;return{path:s,content:J(_(s,"utf-8"))}}catch(i){console.error(q.yellow(H(M("\u8B66\u544A\uFF1A\u65E0\u6CD5\u8BFB\u53D6 {path}\uFF1A{error}"),{path:s,error:String(i)})))}}return null}P(C,"loadContextFileFromDir");function ut(p){const t=ht(p);if(!t)return;const o=k(t.commonGitDir),s=k(t.repoDir),i=K(o);if(!s.startsWith(`${i}${D}`)||k(m(i,".git"))!==o)return;const e=C(s);return e?m(i,et(e.path)):void 0}P(ut,"findShadowedContextFile");function ft(p){const t=g(p.cwd),o=g(p.agentDir),s=[],i=new Set,e=C(o);e&&(s.push(e),i.add(e.path));const n=[],r=ut(t);let d=t;for(;;){const l=C(d),f=r!==void 0&&k(l?.path??"")===r;l&&!f&&!i.has(l.path)&&(n.unshift(l),i.add(l.path));const h=K(d);if(h===d)break;d=h}return s.push(...n),s}P(ft,"loadProjectContextFiles");class At{static{P(this,"DefaultResourceLoader")}cwd;agentDir;settingsManager;eventBus;packageManager;additionalExtensionPaths;additionalSkillPaths;additionalPromptTemplatePaths;additionalThemePaths;extensionFactories;noExtensions;noSkills;noPromptTemplates;noThemes;noContextFiles;systemPromptSource;appendSystemPromptSource;extensionsOverride;skillsOverride;promptsOverride;themesOverride;agentsFilesOverride;systemPromptOverride;appendSystemPromptOverride;extensionsResult;skills;skillDiagnostics;prompts;promptDiagnostics;themes;themeDiagnostics;agentsFiles;systemPrompt;systemPromptSourcePath;appendSystemPrompt;appendSystemPromptSourcePaths;lastSkillPaths;extensionSkillSourceInfos;extensionPromptSourceInfos;extensionThemeSourceInfos;resourceMetadataByPath;lastPromptPaths;lastThemePaths;loaded;constructor(t){this.cwd=g(t.cwd),this.agentDir=g(t.agentDir),this.settingsManager=t.settingsManager??mt.create(this.cwd,this.agentDir),this.eventBus=t.eventBus??it(),this.packageManager=new lt({cwd:this.cwd,agentDir:this.agentDir,settingsManager:this.settingsManager}),this.additionalExtensionPaths=t.additionalExtensionPaths??[],this.additionalSkillPaths=t.additionalSkillPaths??[],this.additionalPromptTemplatePaths=t.additionalPromptTemplatePaths??[],this.additionalThemePaths=t.additionalThemePaths??[],this.extensionFactories=t.extensionFactories??[],this.noExtensions=t.noExtensions??!1,this.noSkills=t.noSkills??!1,this.noPromptTemplates=t.noPromptTemplates??!1,this.noThemes=t.noThemes??!1,this.noContextFiles=t.noContextFiles??!1,this.systemPromptSource=t.systemPrompt,this.appendSystemPromptSource=t.appendSystemPrompt,this.extensionsOverride=t.extensionsOverride,this.skillsOverride=t.skillsOverride,this.promptsOverride=t.promptsOverride,this.themesOverride=t.themesOverride,this.agentsFilesOverride=t.agentsFilesOverride,this.systemPromptOverride=t.systemPromptOverride,this.appendSystemPromptOverride=t.appendSystemPromptOverride,this.extensionsResult={extensions:[],errors:[],runtime:rt()},this.skills=[],this.skillDiagnostics=[],this.prompts=[],this.promptDiagnostics=[],this.themes=[],this.themeDiagnostics=[],this.agentsFiles=[],this.appendSystemPrompt=[],this.appendSystemPromptSourcePaths=[],this.lastSkillPaths=[],this.extensionSkillSourceInfos=new Map,this.extensionPromptSourceInfos=new Map,this.extensionThemeSourceInfos=new Map,this.resourceMetadataByPath=new Map,this.lastPromptPaths=[],this.lastThemePaths=[],this.loaded=!1}getExtensions(){return this.extensionsResult}getSkills(){return{skills:this.skills,diagnostics:this.skillDiagnostics}}getPrompts(){return{prompts:this.prompts,diagnostics:this.promptDiagnostics}}getThemes(){return{themes:this.themes,diagnostics:this.themeDiagnostics}}getAgentsFiles(){return{agentsFiles:this.agentsFiles}}getSystemPrompt(){return this.systemPrompt}getSystemPromptSource(){return this.systemPromptSourcePath?{path:this.systemPromptSourcePath}:void 0}getAppendSystemPrompt(){return this.appendSystemPrompt}getAppendSystemPromptSources(){return this.appendSystemPromptSourcePaths.map(t=>({path:t}))}extendResources(t){const o=this.normalizeExtensionPaths(t.skillPaths??[]),s=this.normalizeExtensionPaths(t.promptPaths??[]),i=this.normalizeExtensionPaths(t.themePaths??[]);for(const e of o)this.extensionSkillSourceInfos.set(e.path,E(e.path,e.metadata));for(const e of s)this.extensionPromptSourceInfos.set(e.path,E(e.path,e.metadata));for(const e of i)this.extensionThemeSourceInfos.set(e.path,E(e.path,e.metadata));o.length>0&&(this.lastSkillPaths=this.mergePaths(this.lastSkillPaths,o.map(e=>e.path)),this.updateSkillsFromPaths(this.lastSkillPaths,this.resourceMetadataByPath)),s.length>0&&(this.lastPromptPaths=this.mergePaths(this.lastPromptPaths,s.map(e=>e.path)),this.updatePromptsFromPaths(this.lastPromptPaths,this.resourceMetadataByPath)),i.length>0&&(this.lastThemePaths=this.mergePaths(this.lastThemePaths,i.map(e=>e.path)),this.updateThemesFromPaths(this.lastThemePaths,this.resourceMetadataByPath))}async loadProjectTrustExtensions(){return this.settingsManager.setProjectTrusted(!1),await this.settingsManager.reload(),this.loadCurrentExtensionSet({includeInlineFactories:!0})}async reload(t){pt("extensions"),this.loaded&&nt();let o;if(t?.resolveProjectTrust){o=await this.loadProjectTrustExtensions();const a=await t.resolveProjectTrust({extensionsResult:o});this.settingsManager.setProjectTrusted(a)}await this.settingsManager.reload();const s=await this.packageManager.resolve(),i=await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths,{temporary:!0});this.resourceMetadataByPath=new Map;const e=this.resourceMetadataByPath;this.extensionSkillSourceInfos=new Map,this.extensionPromptSourceInfos=new Map,this.extensionThemeSourceInfos=new Map;const n=P(a=>{for(const c of a)e.has(c.path)||e.set(c.path,c.metadata);return a.filter(c=>c.enabled)},"getEnabledResources"),r=P(a=>n(a).map(c=>c.path),"getEnabledPaths"),d=r(s.extensions),l=n(s.skills),f=r(s.prompts),h=r(s.themes),S=l.map(a=>this.mapSkillPath(a,e));for(const a of i.extensions)e.has(a.path)||e.set(a.path,{source:"cli",scope:"temporary",origin:"top-level"});for(const a of i.skills)e.has(a.path)||e.set(a.path,{source:"cli",scope:"temporary",origin:"top-level"});const A=r(i.extensions),j=r(i.skills),$=r(i.prompts),B=r(i.themes),V=this.noExtensions?A:this.mergePaths(A,d),O=await this.loadFinalExtensionSet(V,o);for(const a of this.additionalExtensionPaths)if(b(a)){const c=this.resolveResourcePath(a);u(c)||O.errors.push({path:c,error:`Extension path does not exist: ${c}`})}this.extensionsResult=this.extensionsOverride?this.extensionsOverride(O):O,this.applyExtensionSourceInfo(this.extensionsResult.extensions,e);const v=m(st(),"skills"),W=!this.noSkills&&u(v)?[v]:[];W.length>0&&!e.has(v)&&e.set(v,{source:"auto",scope:"user",origin:"top-level",baseDir:v});const z=this.noSkills?this.mergePaths(j,this.additionalSkillPaths):this.mergePaths([...W,...j,...S],this.additionalSkillPaths);this.lastSkillPaths=z,this.updateSkillsFromPaths(z,e);for(const a of this.additionalSkillPaths)if(b(a)){const c=this.resolveResourcePath(a);!u(c)&&!this.skillDiagnostics.some(F=>F.path===c)&&this.skillDiagnostics.push({type:"error",message:"Skill path does not exist",path:c})}const L=this.noPromptTemplates?this.mergePaths($,this.additionalPromptTemplatePaths):this.mergePaths([...$,...f],this.additionalPromptTemplatePaths);this.lastPromptPaths=L,this.updatePromptsFromPaths(L,e);for(const a of this.additionalPromptTemplatePaths)if(b(a)){const c=this.resolveResourcePath(a);!u(c)&&!this.promptDiagnostics.some(F=>F.path===c)&&this.promptDiagnostics.push({type:"error",message:"Prompt template path does not exist",path:c})}const N=this.noThemes?this.mergePaths(B,this.additionalThemePaths):this.mergePaths([...B,...h],this.additionalThemePaths);this.lastThemePaths=N,this.updateThemesFromPaths(N,e);for(const a of this.additionalThemePaths){const c=this.resolveResourcePath(a);!u(c)&&!this.themeDiagnostics.some(F=>F.path===c)&&this.themeDiagnostics.push({type:"error",message:"Theme path does not exist",path:c})}const G={agentsFiles:this.noContextFiles?[]:ft({cwd:this.cwd,agentDir:this.agentDir})},X=this.agentsFilesOverride?this.agentsFilesOverride(G):G;this.agentsFiles=X.agentsFiles;const T=this.systemPromptSource??this.discoverSystemPromptFile(),U=Q(T,M("\u7CFB\u7EDF\u63D0\u793A\u8BCD"));this.systemPrompt=this.systemPromptOverride?this.systemPromptOverride(U):U,this.systemPromptSourcePath=T&&u(T)?g(T):void 0;let I=this.appendSystemPromptSource;if(!I){const a=this.discoverAppendSystemPromptFile();I=a?[a]:[]}const Y=I.map(a=>Q(a,M("\u8FFD\u52A0\u7684\u7CFB\u7EDF\u63D0\u793A\u8BCD"))).filter(a=>a!==void 0);this.appendSystemPrompt=this.appendSystemPromptOverride?this.appendSystemPromptOverride(Y):Y,this.appendSystemPromptSourcePaths=I.filter(a=>u(a)).map(a=>g(a)),this.loaded=!0}async loadCurrentExtensionSet(t){const o=await this.packageManager.resolve(),s=await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths,{temporary:!0}),i=o.extensions.filter(l=>l.enabled).map(l=>l.path),e=s.extensions.filter(l=>l.enabled).map(l=>l.path),n=this.noExtensions?e:this.mergePaths(e,i),r=await R(n,this.cwd,this.eventBus);if(!t.includeInlineFactories)return r;const d=await this.loadExtensionFactories(r.runtime);return r.extensions.push(...d.extensions),r.errors.push(...d.errors),r}resolveExtensionLoadPath(t){return g(t,this.cwd,{normalizeUnicodeSpaces:!0})}async loadFinalExtensionSet(t,o){if(!o){const h=await R(t,this.cwd,this.eventBus),S=await this.loadExtensionFactories(h.runtime);return h.extensions.push(...S.extensions),h.errors.push(...S.errors),this.addExtensionConflictDiagnostics(h),h}const s=new Map(o.extensions.filter(h=>!h.path.startsWith("<inline:")).map(h=>[h.resolvedPath,h])),i=new Set(o.errors.map(h=>this.resolveExtensionLoadPath(h.path))),e=t.filter(h=>{const S=this.resolveExtensionLoadPath(h);return!s.has(S)&&!i.has(S)}),n=await R(e,this.cwd,this.eventBus,o.runtime),r=new Map(s);for(const h of n.extensions)r.set(h.resolvedPath,h);const d=o.extensions.filter(h=>h.path.startsWith("<inline:")),l=t.map(h=>r.get(this.resolveExtensionLoadPath(h))).filter(h=>h!==void 0);l.push(...d);const f={extensions:l,errors:[...o.errors,...n.errors],runtime:o.runtime};return this.addExtensionConflictDiagnostics(f),f}addExtensionConflictDiagnostics(t){const o=this.detectExtensionConflicts(t.extensions);for(const s of o)t.errors.push({path:s.path,error:s.message})}mapSkillPath(t,o){if(t.metadata.source!=="auto"&&t.metadata.origin!=="package")return t.path;try{if(!w(t.path).isDirectory())return t.path}catch{return t.path}const s=m(t.path,"SKILL.md");return u(s)?(o.has(s)||o.set(s,t.metadata),s):t.path}normalizeExtensionPaths(t){return t.map(o=>{const s=o.metadata.baseDir?{...o.metadata,baseDir:this.resolveResourcePath(o.metadata.baseDir)}:o.metadata;return{path:this.resolveResourcePath(o.path),metadata:s}})}updateSkillsFromPaths(t,o){let s;this.noSkills&&t.length===0?s={skills:[],diagnostics:[]}:s=dt({cwd:this.cwd,agentDir:this.agentDir,skillPaths:t,includeDefaults:!1});const i=this.skillsOverride?this.skillsOverride(s):s;this.skills=i.skills.map(e=>({...e,sourceInfo:this.findSourceInfoForPath(e.filePath,this.extensionSkillSourceInfos,o)??e.sourceInfo??this.getDefaultSourceInfoForPath(e.filePath)})),this.skillDiagnostics=i.diagnostics}updatePromptsFromPaths(t,o){let s;if(this.noPromptTemplates&&t.length===0)s={prompts:[],diagnostics:[]};else{const e=ct({cwd:this.cwd,agentDir:this.agentDir,promptPaths:t,includeDefaults:!1}),n=this.dedupePrompts(e.templates);s={prompts:n.prompts,diagnostics:[...e.diagnostics,...n.diagnostics]}}const i=this.promptsOverride?this.promptsOverride(s):s;this.prompts=i.prompts.map(e=>({...e,sourceInfo:this.findSourceInfoForPath(e.filePath,this.extensionPromptSourceInfos,o)??e.sourceInfo??this.getDefaultSourceInfoForPath(e.filePath)})),this.promptDiagnostics=i.diagnostics}updateThemesFromPaths(t,o){let s;if(this.noThemes&&t.length===0)s={themes:[],diagnostics:[]};else{const e=this.loadThemes(t,!1),n=this.dedupeThemes(e.themes);s={themes:n.themes,diagnostics:[...e.diagnostics,...n.diagnostics]}}const i=this.themesOverride?this.themesOverride(s):s;this.themes=i.themes.map(e=>{const n=e.sourcePath;return e.sourceInfo=n?this.findSourceInfoForPath(n,this.extensionThemeSourceInfos,o)??e.sourceInfo??this.getDefaultSourceInfoForPath(n):e.sourceInfo,e}),this.themeDiagnostics=i.diagnostics}applyExtensionSourceInfo(t,o){for(const s of t){s.sourceInfo=this.findSourceInfoForPath(s.path,void 0,o)??this.getDefaultSourceInfoForPath(s.path);for(const i of s.commands.values())i.sourceInfo=s.sourceInfo;for(const i of s.tools.values())i.sourceInfo=s.sourceInfo}}findSourceInfoForPath(t,o,s){if(!t)return;if(t.startsWith("<"))return this.getDefaultSourceInfoForPath(t);const i=y(t);if(o)for(const[e,n]of o.entries()){const r=y(e);if(i===r||i.startsWith(`${r}${D}`))return{...n,path:t}}if(s){const e=s.get(i)??s.get(t);if(e)return E(t,e);for(const[n,r]of s.entries()){const d=y(n);if(i===d||i.startsWith(`${d}${D}`))return E(t,r)}}}getDefaultSourceInfoForPath(t){if(t.startsWith("<")&&t.endsWith(">"))return{path:t,source:t.slice(1,-1).split(":")[0]||"temporary",scope:"temporary",origin:"top-level"};const o=y(t),s=[m(this.agentDir,"skills"),m(this.agentDir,"prompts"),m(this.agentDir,"themes"),m(this.agentDir,"extensions")],i=[m(this.cwd,x,"skills"),m(this.cwd,x,"prompts"),m(this.cwd,x,"themes"),m(this.cwd,x,"extensions")];for(const e of s)if(this.isUnderPath(o,e))return{path:t,source:"local",scope:"user",origin:"top-level",baseDir:e};for(const e of i)if(this.isUnderPath(o,e))return{path:t,source:"local",scope:"project",origin:"top-level",baseDir:e};return{path:t,source:"local",scope:"temporary",origin:"top-level",baseDir:w(o).isDirectory()?o:y(o,"..")}}mergePaths(t,o){const s=[],i=new Set;for(const e of[...t,...o]){const n=this.resolveResourcePath(e),r=k(n);i.has(r)||(i.add(r),s.push(n))}return s}resolveResourcePath(t){return g(t,this.cwd,{trim:!0})}loadThemes(t,o=!0){const s=[],i=[];if(o){const e=[m(this.agentDir,"themes"),m(this.cwd,x,"themes")];for(const n of e)this.loadThemesFromDir(n,s,i)}for(const e of t){const n=this.resolveResourcePath(e);if(!u(n)){i.push({type:"warning",message:"theme path does not exist",path:n});continue}try{const r=w(n);r.isDirectory()?this.loadThemesFromDir(n,s,i):r.isFile()&&n.endsWith(".json")?this.loadThemeFromFile(n,s,i):i.push({type:"warning",message:"theme path is not a json file",path:n})}catch(r){const d=r instanceof Error?r.message:"failed to read theme path";i.push({type:"warning",message:d,path:n})}}return{themes:s,diagnostics:i}}loadThemesFromDir(t,o,s){if(u(t))try{const i=tt(t,{withFileTypes:!0});for(const e of i){let n=e.isFile();if(e.isSymbolicLink())try{n=w(m(t,e.name)).isFile()}catch{continue}n&&e.name.endsWith(".json")&&this.loadThemeFromFile(m(t,e.name),o,s)}}catch(i){const e=i instanceof Error?i.message:"failed to read theme directory";s.push({type:"warning",message:e,path:t})}}loadThemeFromFile(t,o,s){try{o.push(ot(t))}catch(i){const e=i instanceof Error?i.message:"failed to load theme";s.push({type:"warning",message:e,path:t})}}async loadExtensionFactories(t){const o=[],s=[];for(const[i,e]of this.extensionFactories.entries()){const n=typeof e!="function",r=n?e.factory:e,d=`<inline:${n?e.name:i+1}>`;try{const l=await at(r,this.cwd,this.eventBus,t,d);l.hidden=n&&e.hidden,o.push(l)}catch(l){const f=l instanceof Error?l.message:"failed to load extension";s.push({path:d,error:f})}}return{extensions:o,errors:s}}dedupePrompts(t){const o=new Map,s=[];for(const i of t){const e=o.get(i.name);e?s.push({type:"collision",message:`name "/${i.name}" collision`,path:i.filePath,collision:{resourceType:"prompt",name:i.name,winnerPath:e.filePath,loserPath:i.filePath}}):o.set(i.name,i)}return{prompts:Array.from(o.values()),diagnostics:s}}dedupeThemes(t){const o=new Map,s=[];for(const i of t){const e=i.name??"unnamed",n=o.get(e);n?s.push({type:"collision",message:`name "${e}" collision`,path:i.sourcePath,collision:{resourceType:"theme",name:e,winnerPath:n.sourcePath??"<builtin>",loserPath:i.sourcePath??"<builtin>"}}):o.set(e,i)}return{themes:Array.from(o.values()),diagnostics:s}}discoverSystemPromptFile(){const t=m(this.cwd,x,"SYSTEM.md");if(this.settingsManager.isProjectTrusted()&&u(t))return t;const o=m(this.agentDir,"SYSTEM.md");if(u(o))return o}discoverAppendSystemPromptFile(){const t=m(this.cwd,x,"APPEND_SYSTEM.md");if(this.settingsManager.isProjectTrusted()&&u(t))return t;const o=m(this.agentDir,"APPEND_SYSTEM.md");if(u(o))return o}isUnderPath(t,o){const s=y(o);if(t===s)return!0;const i=s.endsWith(D)?s:`${s}${D}`;return t.startsWith(i)}detectExtensionConflicts(t){const o=[],s=new Map,i=new Map;for(const e of t){for(const n of e.tools.keys()){const r=s.get(n);r&&r!==e.path?o.push({path:e.path,message:`Tool "${n}" conflicts with ${r}`}):s.set(n,e.path)}for(const n of e.flags.keys()){const r=i.get(n);r&&r!==e.path?o.push({path:e.path,message:`Flag "--${n}" conflicts with ${r}`}):i.set(n,e.path)}}return o}}export{At as DefaultResourceLoader,ft as loadProjectContextFiles};
|
|
1
|
+
var Z=Object.defineProperty;var P=(p,t)=>Z(p,"name",{value:t,configurable:!0});import{existsSync as u,readdirSync as tt,readFileSync as _,statSync as w}from"node:fs";import{basename as et,dirname as K,join as m,resolve as y,sep as D}from"node:path";import q from"chalk";import{CONFIG_DIR_NAME as x,getExamplesPath as st}from"../config.js";import{fill as H,t as M}from"../dal/i18n.js";import{loadThemeFromPath as ot}from"../modes/interactive/theme/theme.js";import{canonicalizePath as k,isLocalPath as b,resolvePath as g}from"../utils/paths.js";import{stripBom as J}from"../utils/text.js";import{createEventBus as it}from"./event-bus.js";import{clearExtensionCache as nt,createExtensionRuntime as rt,loadExtensionFromFactory as at,loadExtensionsCached as R}from"./extensions/loader.js";import{findGitPaths as ht}from"./footer-data-provider.js";import{DefaultPackageManager as lt}from"./package-manager.js";import{loadPromptTemplates as ct}from"./prompt-templates.js";import{SettingsManager as mt}from"./settings-manager.js";import{loadSkills as dt}from"./skills.js";import{createSourceInfo as E}from"./source-info.js";import{resetTimings as pt}from"./timings.js";function Q(p,t){if(p){if(u(p))try{return J(_(p,"utf-8"))}catch(o){return console.error(q.yellow(H(M("\u8B66\u544A\uFF1A\u65E0\u6CD5\u8BFB\u53D6{what}\u6587\u4EF6 {path}\uFF1A{error}"),{what:t,path:p,error:String(o)}))),p}return p}}P(Q,"resolvePromptInput");function C(p){const t=["AGENTS.override.md","AGENTS.md","AGENTS.MD","CLAUDE.md","CLAUDE.MD"];for(const o of t){const s=m(p,o);if(u(s))try{if(!w(s).isFile())continue;return{path:s,content:J(_(s,"utf-8"))}}catch(i){console.error(q.yellow(H(M("\u8B66\u544A\uFF1A\u65E0\u6CD5\u8BFB\u53D6 {path}\uFF1A{error}"),{path:s,error:String(i)})))}}return null}P(C,"loadContextFileFromDir");function ut(p){const t=ht(p);if(!t)return;const o=k(t.commonGitDir),s=k(t.repoDir),i=K(o);if(!s.startsWith(`${i}${D}`)||k(m(i,".git"))!==o)return;const e=C(s);return e?m(i,et(e.path)):void 0}P(ut,"findShadowedContextFile");function ft(p){const t=g(p.cwd),o=g(p.agentDir),s=[],i=new Set,e=C(o);e&&(s.push(e),i.add(e.path));const n=[],r=ut(t);let d=t;for(;;){const l=C(d),f=r!==void 0&&k(l?.path??"")===r;l&&!f&&!i.has(l.path)&&(n.unshift(l),i.add(l.path));const h=K(d);if(h===d)break;d=h}return s.push(...n),s}P(ft,"loadProjectContextFiles");class At{static{P(this,"DefaultResourceLoader")}cwd;agentDir;settingsManager;eventBus;packageManager;additionalExtensionPaths;additionalSkillPaths;additionalPromptTemplatePaths;additionalThemePaths;extensionFactories;noExtensions;noSkills;noPromptTemplates;noThemes;noContextFiles;systemPromptSource;appendSystemPromptSource;extensionsOverride;skillsOverride;promptsOverride;themesOverride;agentsFilesOverride;systemPromptOverride;appendSystemPromptOverride;extensionsResult;skills;skillDiagnostics;prompts;promptDiagnostics;themes;themeDiagnostics;agentsFiles;systemPrompt;systemPromptSourcePath;appendSystemPrompt;appendSystemPromptSourcePaths;lastSkillPaths;extensionSkillSourceInfos;extensionPromptSourceInfos;extensionThemeSourceInfos;resourceMetadataByPath;lastPromptPaths;lastThemePaths;loaded;constructor(t){this.cwd=g(t.cwd),this.agentDir=g(t.agentDir),this.settingsManager=t.settingsManager??mt.create(this.cwd,this.agentDir),this.eventBus=t.eventBus??it(),this.packageManager=new lt({cwd:this.cwd,agentDir:this.agentDir,settingsManager:this.settingsManager}),this.additionalExtensionPaths=t.additionalExtensionPaths??[],this.additionalSkillPaths=t.additionalSkillPaths??[],this.additionalPromptTemplatePaths=t.additionalPromptTemplatePaths??[],this.additionalThemePaths=t.additionalThemePaths??[],this.extensionFactories=t.extensionFactories??[],this.noExtensions=t.noExtensions??!1,this.noSkills=t.noSkills??!1,this.noPromptTemplates=t.noPromptTemplates??!1,this.noThemes=t.noThemes??!1,this.noContextFiles=t.noContextFiles??!1,this.systemPromptSource=t.systemPrompt,this.appendSystemPromptSource=t.appendSystemPrompt,this.extensionsOverride=t.extensionsOverride,this.skillsOverride=t.skillsOverride,this.promptsOverride=t.promptsOverride,this.themesOverride=t.themesOverride,this.agentsFilesOverride=t.agentsFilesOverride,this.systemPromptOverride=t.systemPromptOverride,this.appendSystemPromptOverride=t.appendSystemPromptOverride,this.extensionsResult={extensions:[],errors:[],runtime:rt()},this.skills=[],this.skillDiagnostics=[],this.prompts=[],this.promptDiagnostics=[],this.themes=[],this.themeDiagnostics=[],this.agentsFiles=[],this.appendSystemPrompt=[],this.appendSystemPromptSourcePaths=[],this.lastSkillPaths=[],this.extensionSkillSourceInfos=new Map,this.extensionPromptSourceInfos=new Map,this.extensionThemeSourceInfos=new Map,this.resourceMetadataByPath=new Map,this.lastPromptPaths=[],this.lastThemePaths=[],this.loaded=!1}getExtensions(){return this.extensionsResult}getSkills(){return{skills:this.skills,diagnostics:this.skillDiagnostics}}getPrompts(){return{prompts:this.prompts,diagnostics:this.promptDiagnostics}}getThemes(){return{themes:this.themes,diagnostics:this.themeDiagnostics}}getAgentsFiles(){return{agentsFiles:this.agentsFiles}}getSystemPrompt(){return this.systemPrompt}getSystemPromptSource(){return this.systemPromptSourcePath?{path:this.systemPromptSourcePath}:void 0}getAppendSystemPrompt(){return this.appendSystemPrompt}getAppendSystemPromptSources(){return this.appendSystemPromptSourcePaths.map(t=>({path:t}))}extendResources(t){const o=this.normalizeExtensionPaths(t.skillPaths??[]),s=this.normalizeExtensionPaths(t.promptPaths??[]),i=this.normalizeExtensionPaths(t.themePaths??[]);for(const e of o)this.extensionSkillSourceInfos.set(e.path,E(e.path,e.metadata));for(const e of s)this.extensionPromptSourceInfos.set(e.path,E(e.path,e.metadata));for(const e of i)this.extensionThemeSourceInfos.set(e.path,E(e.path,e.metadata));o.length>0&&(this.lastSkillPaths=this.mergePaths(this.lastSkillPaths,o.map(e=>e.path)),this.updateSkillsFromPaths(this.lastSkillPaths,this.resourceMetadataByPath)),s.length>0&&(this.lastPromptPaths=this.mergePaths(this.lastPromptPaths,s.map(e=>e.path)),this.updatePromptsFromPaths(this.lastPromptPaths,this.resourceMetadataByPath)),i.length>0&&(this.lastThemePaths=this.mergePaths(this.lastThemePaths,i.map(e=>e.path)),this.updateThemesFromPaths(this.lastThemePaths,this.resourceMetadataByPath))}async loadProjectTrustExtensions(){return this.settingsManager.setProjectTrusted(!1),await this.settingsManager.reload(),this.loadCurrentExtensionSet({includeInlineFactories:!0})}async reload(t){pt("extensions"),this.loaded&&nt();let o;if(t?.resolveProjectTrust){o=await this.loadProjectTrustExtensions();const a=await t.resolveProjectTrust({extensionsResult:o});this.settingsManager.setProjectTrusted(a)}await this.settingsManager.reload();const s=await this.packageManager.resolve(),i=await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths,{temporary:!0});this.resourceMetadataByPath=new Map;const e=this.resourceMetadataByPath;this.extensionSkillSourceInfos=new Map,this.extensionPromptSourceInfos=new Map,this.extensionThemeSourceInfos=new Map;const n=P(a=>{for(const c of a)e.has(c.path)||e.set(c.path,c.metadata);return a.filter(c=>c.enabled)},"getEnabledResources"),r=P(a=>n(a).map(c=>c.path),"getEnabledPaths"),d=r(s.extensions),l=n(s.skills),f=r(s.prompts),h=r(s.themes),S=l.map(a=>this.mapSkillPath(a,e));for(const a of i.extensions)e.has(a.path)||e.set(a.path,{source:"cli",scope:"temporary",origin:"top-level"});for(const a of i.skills)e.has(a.path)||e.set(a.path,{source:"cli",scope:"temporary",origin:"top-level"});const A=r(i.extensions),j=r(i.skills),$=r(i.prompts),B=r(i.themes),V=this.noExtensions?A:this.mergePaths(A,d),O=await this.loadFinalExtensionSet(V,o);for(const a of this.additionalExtensionPaths)if(b(a)){const c=this.resolveResourcePath(a);u(c)||O.errors.push({path:c,error:`Extension path does not exist: ${c}`})}this.extensionsResult=this.extensionsOverride?this.extensionsOverride(O):O,this.applyExtensionSourceInfo(this.extensionsResult.extensions,e);const v=m(st(),"skills"),W=!this.noSkills&&u(v)?[v]:[];W.length>0&&!e.has(v)&&e.set(v,{source:"auto",scope:"user",origin:"top-level",baseDir:v});const z=this.noSkills?this.mergePaths(j,this.additionalSkillPaths):this.mergePaths([...j,...S,...W],this.additionalSkillPaths);this.lastSkillPaths=z,this.updateSkillsFromPaths(z,e);for(const a of this.additionalSkillPaths)if(b(a)){const c=this.resolveResourcePath(a);!u(c)&&!this.skillDiagnostics.some(F=>F.path===c)&&this.skillDiagnostics.push({type:"error",message:"Skill path does not exist",path:c})}const L=this.noPromptTemplates?this.mergePaths($,this.additionalPromptTemplatePaths):this.mergePaths([...$,...f],this.additionalPromptTemplatePaths);this.lastPromptPaths=L,this.updatePromptsFromPaths(L,e);for(const a of this.additionalPromptTemplatePaths)if(b(a)){const c=this.resolveResourcePath(a);!u(c)&&!this.promptDiagnostics.some(F=>F.path===c)&&this.promptDiagnostics.push({type:"error",message:"Prompt template path does not exist",path:c})}const N=this.noThemes?this.mergePaths(B,this.additionalThemePaths):this.mergePaths([...B,...h],this.additionalThemePaths);this.lastThemePaths=N,this.updateThemesFromPaths(N,e);for(const a of this.additionalThemePaths){const c=this.resolveResourcePath(a);!u(c)&&!this.themeDiagnostics.some(F=>F.path===c)&&this.themeDiagnostics.push({type:"error",message:"Theme path does not exist",path:c})}const G={agentsFiles:this.noContextFiles?[]:ft({cwd:this.cwd,agentDir:this.agentDir})},X=this.agentsFilesOverride?this.agentsFilesOverride(G):G;this.agentsFiles=X.agentsFiles;const T=this.systemPromptSource??this.discoverSystemPromptFile(),U=Q(T,M("\u7CFB\u7EDF\u63D0\u793A\u8BCD"));this.systemPrompt=this.systemPromptOverride?this.systemPromptOverride(U):U,this.systemPromptSourcePath=T&&u(T)?g(T):void 0;let I=this.appendSystemPromptSource;if(!I){const a=this.discoverAppendSystemPromptFile();I=a?[a]:[]}const Y=I.map(a=>Q(a,M("\u8FFD\u52A0\u7684\u7CFB\u7EDF\u63D0\u793A\u8BCD"))).filter(a=>a!==void 0);this.appendSystemPrompt=this.appendSystemPromptOverride?this.appendSystemPromptOverride(Y):Y,this.appendSystemPromptSourcePaths=I.filter(a=>u(a)).map(a=>g(a)),this.loaded=!0}async loadCurrentExtensionSet(t){const o=await this.packageManager.resolve(),s=await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths,{temporary:!0}),i=o.extensions.filter(l=>l.enabled).map(l=>l.path),e=s.extensions.filter(l=>l.enabled).map(l=>l.path),n=this.noExtensions?e:this.mergePaths(e,i),r=await R(n,this.cwd,this.eventBus);if(!t.includeInlineFactories)return r;const d=await this.loadExtensionFactories(r.runtime);return r.extensions.push(...d.extensions),r.errors.push(...d.errors),r}resolveExtensionLoadPath(t){return g(t,this.cwd,{normalizeUnicodeSpaces:!0})}async loadFinalExtensionSet(t,o){if(!o){const h=await R(t,this.cwd,this.eventBus),S=await this.loadExtensionFactories(h.runtime);return h.extensions.push(...S.extensions),h.errors.push(...S.errors),this.addExtensionConflictDiagnostics(h),h}const s=new Map(o.extensions.filter(h=>!h.path.startsWith("<inline:")).map(h=>[h.resolvedPath,h])),i=new Set(o.errors.map(h=>this.resolveExtensionLoadPath(h.path))),e=t.filter(h=>{const S=this.resolveExtensionLoadPath(h);return!s.has(S)&&!i.has(S)}),n=await R(e,this.cwd,this.eventBus,o.runtime),r=new Map(s);for(const h of n.extensions)r.set(h.resolvedPath,h);const d=o.extensions.filter(h=>h.path.startsWith("<inline:")),l=t.map(h=>r.get(this.resolveExtensionLoadPath(h))).filter(h=>h!==void 0);l.push(...d);const f={extensions:l,errors:[...o.errors,...n.errors],runtime:o.runtime};return this.addExtensionConflictDiagnostics(f),f}addExtensionConflictDiagnostics(t){const o=this.detectExtensionConflicts(t.extensions);for(const s of o)t.errors.push({path:s.path,error:s.message})}mapSkillPath(t,o){if(t.metadata.source!=="auto"&&t.metadata.origin!=="package")return t.path;try{if(!w(t.path).isDirectory())return t.path}catch{return t.path}const s=m(t.path,"SKILL.md");return u(s)?(o.has(s)||o.set(s,t.metadata),s):t.path}normalizeExtensionPaths(t){return t.map(o=>{const s=o.metadata.baseDir?{...o.metadata,baseDir:this.resolveResourcePath(o.metadata.baseDir)}:o.metadata;return{path:this.resolveResourcePath(o.path),metadata:s}})}updateSkillsFromPaths(t,o){let s;this.noSkills&&t.length===0?s={skills:[],diagnostics:[]}:s=dt({cwd:this.cwd,agentDir:this.agentDir,skillPaths:t,includeDefaults:!1});const i=this.skillsOverride?this.skillsOverride(s):s;this.skills=i.skills.map(e=>({...e,sourceInfo:this.findSourceInfoForPath(e.filePath,this.extensionSkillSourceInfos,o)??e.sourceInfo??this.getDefaultSourceInfoForPath(e.filePath)})),this.skillDiagnostics=i.diagnostics}updatePromptsFromPaths(t,o){let s;if(this.noPromptTemplates&&t.length===0)s={prompts:[],diagnostics:[]};else{const e=ct({cwd:this.cwd,agentDir:this.agentDir,promptPaths:t,includeDefaults:!1}),n=this.dedupePrompts(e.templates);s={prompts:n.prompts,diagnostics:[...e.diagnostics,...n.diagnostics]}}const i=this.promptsOverride?this.promptsOverride(s):s;this.prompts=i.prompts.map(e=>({...e,sourceInfo:this.findSourceInfoForPath(e.filePath,this.extensionPromptSourceInfos,o)??e.sourceInfo??this.getDefaultSourceInfoForPath(e.filePath)})),this.promptDiagnostics=i.diagnostics}updateThemesFromPaths(t,o){let s;if(this.noThemes&&t.length===0)s={themes:[],diagnostics:[]};else{const e=this.loadThemes(t,!1),n=this.dedupeThemes(e.themes);s={themes:n.themes,diagnostics:[...e.diagnostics,...n.diagnostics]}}const i=this.themesOverride?this.themesOverride(s):s;this.themes=i.themes.map(e=>{const n=e.sourcePath;return e.sourceInfo=n?this.findSourceInfoForPath(n,this.extensionThemeSourceInfos,o)??e.sourceInfo??this.getDefaultSourceInfoForPath(n):e.sourceInfo,e}),this.themeDiagnostics=i.diagnostics}applyExtensionSourceInfo(t,o){for(const s of t){s.sourceInfo=this.findSourceInfoForPath(s.path,void 0,o)??this.getDefaultSourceInfoForPath(s.path);for(const i of s.commands.values())i.sourceInfo=s.sourceInfo;for(const i of s.tools.values())i.sourceInfo=s.sourceInfo}}findSourceInfoForPath(t,o,s){if(!t)return;if(t.startsWith("<"))return this.getDefaultSourceInfoForPath(t);const i=y(t);if(o)for(const[e,n]of o.entries()){const r=y(e);if(i===r||i.startsWith(`${r}${D}`))return{...n,path:t}}if(s){const e=s.get(i)??s.get(t);if(e)return E(t,e);for(const[n,r]of s.entries()){const d=y(n);if(i===d||i.startsWith(`${d}${D}`))return E(t,r)}}}getDefaultSourceInfoForPath(t){if(t.startsWith("<")&&t.endsWith(">"))return{path:t,source:t.slice(1,-1).split(":")[0]||"temporary",scope:"temporary",origin:"top-level"};const o=y(t),s=[m(this.agentDir,"skills"),m(this.agentDir,"prompts"),m(this.agentDir,"themes"),m(this.agentDir,"extensions")],i=[m(this.cwd,x,"skills"),m(this.cwd,x,"prompts"),m(this.cwd,x,"themes"),m(this.cwd,x,"extensions")];for(const e of s)if(this.isUnderPath(o,e))return{path:t,source:"local",scope:"user",origin:"top-level",baseDir:e};for(const e of i)if(this.isUnderPath(o,e))return{path:t,source:"local",scope:"project",origin:"top-level",baseDir:e};return{path:t,source:"local",scope:"temporary",origin:"top-level",baseDir:w(o).isDirectory()?o:y(o,"..")}}mergePaths(t,o){const s=[],i=new Set;for(const e of[...t,...o]){const n=this.resolveResourcePath(e),r=k(n);i.has(r)||(i.add(r),s.push(n))}return s}resolveResourcePath(t){return g(t,this.cwd,{trim:!0})}loadThemes(t,o=!0){const s=[],i=[];if(o){const e=[m(this.agentDir,"themes"),m(this.cwd,x,"themes")];for(const n of e)this.loadThemesFromDir(n,s,i)}for(const e of t){const n=this.resolveResourcePath(e);if(!u(n)){i.push({type:"warning",message:"theme path does not exist",path:n});continue}try{const r=w(n);r.isDirectory()?this.loadThemesFromDir(n,s,i):r.isFile()&&n.endsWith(".json")?this.loadThemeFromFile(n,s,i):i.push({type:"warning",message:"theme path is not a json file",path:n})}catch(r){const d=r instanceof Error?r.message:"failed to read theme path";i.push({type:"warning",message:d,path:n})}}return{themes:s,diagnostics:i}}loadThemesFromDir(t,o,s){if(u(t))try{const i=tt(t,{withFileTypes:!0});for(const e of i){let n=e.isFile();if(e.isSymbolicLink())try{n=w(m(t,e.name)).isFile()}catch{continue}n&&e.name.endsWith(".json")&&this.loadThemeFromFile(m(t,e.name),o,s)}}catch(i){const e=i instanceof Error?i.message:"failed to read theme directory";s.push({type:"warning",message:e,path:t})}}loadThemeFromFile(t,o,s){try{o.push(ot(t))}catch(i){const e=i instanceof Error?i.message:"failed to load theme";s.push({type:"warning",message:e,path:t})}}async loadExtensionFactories(t){const o=[],s=[];for(const[i,e]of this.extensionFactories.entries()){const n=typeof e!="function",r=n?e.factory:e,d=`<inline:${n?e.name:i+1}>`;try{const l=await at(r,this.cwd,this.eventBus,t,d);l.hidden=n&&e.hidden,o.push(l)}catch(l){const f=l instanceof Error?l.message:"failed to load extension";s.push({path:d,error:f})}}return{extensions:o,errors:s}}dedupePrompts(t){const o=new Map,s=[];for(const i of t){const e=o.get(i.name);e?s.push({type:"collision",message:`name "/${i.name}" collision`,path:i.filePath,collision:{resourceType:"prompt",name:i.name,winnerPath:e.filePath,loserPath:i.filePath}}):o.set(i.name,i)}return{prompts:Array.from(o.values()),diagnostics:s}}dedupeThemes(t){const o=new Map,s=[];for(const i of t){const e=i.name??"unnamed",n=o.get(e);n?s.push({type:"collision",message:`name "${e}" collision`,path:i.sourcePath,collision:{resourceType:"theme",name:e,winnerPath:n.sourcePath??"<builtin>",loserPath:i.sourcePath??"<builtin>"}}):o.set(e,i)}return{themes:Array.from(o.values()),diagnostics:s}}discoverSystemPromptFile(){const t=m(this.cwd,x,"SYSTEM.md");if(this.settingsManager.isProjectTrusted()&&u(t))return t;const o=m(this.agentDir,"SYSTEM.md");if(u(o))return o}discoverAppendSystemPromptFile(){const t=m(this.cwd,x,"APPEND_SYSTEM.md");if(this.settingsManager.isProjectTrusted()&&u(t))return t;const o=m(this.agentDir,"APPEND_SYSTEM.md");if(u(o))return o}isUnderPath(t,o){const s=y(o);if(t===s)return!0;const i=s.endsWith(D)?s:`${s}${D}`;return t.startsWith(i)}detectExtensionConflicts(t){const o=[],s=new Map,i=new Map;for(const e of t){for(const n of e.tools.keys()){const r=s.get(n);r&&r!==e.path?o.push({path:e.path,message:`Tool "${n}" conflicts with ${r}`}):s.set(n,e.path)}for(const n of e.flags.keys()){const r=i.get(n);r&&r!==e.path?o.push({path:e.path,message:`Flag "--${n}" conflicts with ${r}`}):i.set(n,e.path)}}return o}}export{At as DefaultResourceLoader,ft as loadProjectContextFiles};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface SandboxAvailability {
|
|
2
|
+
available: boolean;
|
|
3
|
+
platform: NodeJS.Platform;
|
|
4
|
+
mechanism?: "seatbelt" | "bubblewrap";
|
|
5
|
+
reason?: string;
|
|
6
|
+
ripgrep?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function detectSandboxAvailability(): SandboxAvailability;
|
|
9
|
+
export declare function setSandboxAvailabilityForTesting(value: SandboxAvailability | undefined): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var b=Object.defineProperty;var r=(e,t)=>b(e,"name",{value:t,configurable:!0});import{spawnSync as n}from"node:child_process";import{existsSync as c}from"node:fs";import{getToolPath as l}from"../../utils/tools-manager.js";let a,i;function p(e){const t=n("which",[e],{encoding:"utf8",timeout:2e3});return t.status===0&&t.stdout.trim()||void 0}r(p,"which");function u(e){return`${e.stderr??""}${e.stdout??""}`.trim()||(e.error?e.error.message:`exit code ${e.status}`)}r(u,"probeOutput");function f(){const e="/usr/bin/sandbox-exec";if(!c(e))return{available:!1,platform:"darwin",reason:`${e} is missing.`};const t=n(e,["-p","(version 1)(allow default)","/usr/bin/true"],{encoding:"utf8",timeout:5e3});return t.status!==0?{available:!1,platform:"darwin",mechanism:"seatbelt",reason:`sandbox-exec cannot apply a profile here (${u(t)}). This happens when dal itself runs inside another sandbox.`}:{available:!0,platform:"darwin",mechanism:"seatbelt",ripgrep:l("rg")??"rg"}}r(f,"detectDarwin");function d(){const e=[],t=p("bwrap");t||e.push("bubblewrap (bwrap)");const s=l("rg")??p("rg");if(s||e.push("ripgrep (rg)"),e.length>0)return{available:!1,platform:"linux",mechanism:"bubblewrap",reason:`missing ${e.join(", ")}. Install them (e.g. \`apt install bubblewrap socat ripgrep\`).`};const o=n(t,["--new-session","--die-with-parent","--ro-bind","/","/","--dev","/dev","--unshare-net","--unshare-pid","--proc","/proc","--","true"],{encoding:"utf8",timeout:5e3});return o.status!==0?{available:!1,platform:"linux",mechanism:"bubblewrap",reason:`bubblewrap cannot create its namespaces here (${u(o)}). Containers often forbid unprivileged user namespaces.`}:{available:!0,platform:"linux",mechanism:"bubblewrap",ripgrep:s}}r(d,"detectLinux");function g(){if(i)return i;if(a)return a;switch(process.platform){case"darwin":a=f();break;case"linux":a=d();break;case"win32":a={available:!1,platform:"win32",reason:"Windows is not supported by the OS sandbox yet."};break;default:a={available:!1,platform:process.platform,reason:`the OS sandbox does not support ${process.platform}.`}}return a}r(g,"detectSandboxAvailability");function v(e){i=e}r(v,"setSandboxAvailabilityForTesting");export{g as detectSandboxAvailability,v as setSandboxAvailabilityForTesting};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SandboxViolationEvent } from "@anthropic-ai/sandbox-runtime";
|
|
2
|
+
import type { SandboxLevel } from "./policy.ts";
|
|
3
|
+
import type { NetworkRefusal } from "./runtime.ts";
|
|
4
|
+
export interface SandboxBlockedAccess {
|
|
5
|
+
kind: "file-read" | "file-write" | "network";
|
|
6
|
+
target: string;
|
|
7
|
+
source: "proxy" | "kernel" | "output";
|
|
8
|
+
detail?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SandboxDenial {
|
|
11
|
+
level: SandboxLevel;
|
|
12
|
+
platform: NodeJS.Platform;
|
|
13
|
+
command: string;
|
|
14
|
+
cwd: string;
|
|
15
|
+
blocked: SandboxBlockedAccess[];
|
|
16
|
+
networkProxyError?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function parseViolationLine(line: string): SandboxBlockedAccess | undefined;
|
|
19
|
+
export declare function parseOutput(output: string): SandboxBlockedAccess[];
|
|
20
|
+
export declare function collectBlockedAccesses(input: {
|
|
21
|
+
refusals: readonly NetworkRefusal[];
|
|
22
|
+
violations: readonly SandboxViolationEvent[];
|
|
23
|
+
output: string;
|
|
24
|
+
}): SandboxBlockedAccess[] | undefined;
|
|
25
|
+
export declare function describeDenialForModel(denial: SandboxDenial): string;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var u=Object.defineProperty;var i=(r,t)=>u(r,"name",{value:t,configurable:!0});const m=20;function f(r){const t=/deny(?:\(\d+\))?\s+(?<operation>[\w-]+)\s+(?<target>.+?)\s*$/.exec(r);if(!t?.groups)return;const{operation:o,target:e}=t.groups;if(o.startsWith("file-write"))return{kind:"file-write",target:e,source:"kernel",detail:o};if(o.startsWith("file-read"))return{kind:"file-read",target:e,source:"kernel",detail:o};if(o.startsWith("network"))return{kind:"network",target:e,source:"kernel",detail:o}}i(f,"parseViolationLine");const p=[{regex:/(?<target>\/[^\s:'"`]+)['"`]?:\s*Read-only file system/,kind:"file-write"},{regex:/Read-only file system[^/\n]*(?<target>\/[^\s'"`]+)/,kind:"file-write"},{regex:/['"`]?(?<target>\/[^\s:'"`]+)['"`]?:\s*Operation not permitted/,kind:"file-write"},{regex:/EPERM: operation not permitted, \w+ ['"](?<target>\/[^'"]+)['"]/,kind:"file-write"},{regex:/EROFS: read-only file system, \w+ ['"](?<target>\/[^'"]+)['"]/,kind:"file-write"},{regex:/Could not resolve host:\s*(?<target>[\w.-]+)/,kind:"network"},{regex:/getaddrinfo (?:ENOTFOUND|EAI_AGAIN) (?<target>[\w.-]+)/,kind:"network"},{regex:/Failed to connect to (?<target>[\w.-]+) port (?<port>\d+)/,kind:"network"},{regex:/Temporary failure in name resolution.*?(?<target>[\w-]+(?:\.[\w-]+)+)?/,kind:"network"}],g=/^(?:\S*\/)?(?:cat|head|tail|less|more|grep|rg|ls|find|wc|stat|file|diff|cmp|od|xxd|strings|base64|sha\d*sum|md5|openssl)\b[^:]*:/;function k(r){const t=[];for(const o of r.split(`
|
|
2
|
+
`)){const e=o.trim();for(const{regex:s,kind:n}of p){const a=s.exec(e);if(!a)continue;const d=a.groups?.target;if(!d){n==="network"&&t.push({kind:n,target:"(unknown host)",source:"output",detail:e});break}const l=a.groups?.port,c=n==="file-write"&&/Operation not permitted/.test(e)&&g.test(e)?"file-read":n;t.push({kind:c,target:l?`${d}:${l}`:d,source:"output",detail:e.slice(0,200)});break}}return t}i(k,"parseOutput");function w(r){const t=new Set,o=[];for(const e of r){const s=`${e.kind}\0${e.target}`;if(!t.has(s)&&(t.add(s),o.push(e),o.length>=20))break}return o}i(w,"dedupe");function x(r){const t=[...r.refusals.map(e=>({kind:"network",target:e.port!==void 0?`${e.host}:${e.port}`:e.host,source:"proxy"})),...r.violations.flatMap(e=>{const s=f(e.line);return s?[s]:[]})];(t.length===0||t.every(e=>e.kind==="network"&&e.target.startsWith("/")))&&t.push(...k(r.output));const o=w(t);return o.length>0?o:void 0}i(x,"collectBlockedAccesses");function b(r){const t=[`[sandbox] The OS sandbox (${r.level}, network off except allowlisted domains) blocked this command:`];for(const n of r.blocked){const a=n.source==="output"?" (inferred from the output)":"";t.push(` - ${n.kind}: ${n.target}${a}`)}r.networkProxyError&&t.push(` (allowlisted domains are unreachable too: the network proxy could not start: ${r.networkProxyError})`);const o=r.blocked.filter(n=>n.kind==="network"&&!n.target.startsWith("/")),e=r.blocked.filter(n=>n.kind==="file-write"),s={mode:"allow",justification:"<why this is needed>"};return o.length>0&&(s.allow_domains=o.map(n=>n.target.replace(/:\d+$/,""))),e.length>0&&(s.allow_write=e.map(n=>n.target)),t.push(`Do not try to work around the sandbox. If the task genuinely needs this access, call the tool again with the same command and sandbox_escalation: ${JSON.stringify(o.length>0||e.length>0?s:{mode:"unsandboxed",justification:"<why this is needed>"})} (or mode "unsandboxed" to run outside the sandbox). The user will be asked to approve.`),t.join(`
|
|
3
|
+
`)}i(b,"describeDenialForModel");export{x as collectBlockedAccesses,b as describeDenialForModel,k as parseOutput,f as parseViolationLine};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { detectSandboxAvailability, type SandboxAvailability, setSandboxAvailabilityForTesting, } from "./availability.ts";
|
|
2
|
+
export { collectBlockedAccesses, describeDenialForModel, parseOutput, parseViolationLine, type SandboxBlockedAccess, type SandboxDenial, } from "./denial.ts";
|
|
3
|
+
export { domainMatches, filesystemRules, isAlwaysBlockedHost, isSandboxLevel, PROTECTED_HOME_READS, PROTECTED_HOME_WRITES, PROTECTED_WRITE_NAMES, type ResolvedSandboxPolicy, readSandboxEnvironment, resolveSandboxPolicy, SANDBOX_ENV, SANDBOX_LEVELS, type SandboxLevel, type SandboxOverride, type SandboxSettings, type SandboxSettingsSources, sandboxEnvironmentValue, stricterLevel, } from "./policy.ts";
|
|
4
|
+
export { decideNetworkRequest, type NetworkGrant, registerNetworkGrant, resetSandboxRuntime } from "./runtime.ts";
|
|
5
|
+
export { getProcessShellSandbox, type PreparedCommand, registerSandboxEscalationHandler, type SandboxEscalationDecision, type SandboxEscalationHandler, type SandboxEscalationInput, type SandboxEscalationRequest, type SandboxEvent, type SandboxOptions, type SandboxRunDetails, type SandboxStatus, ShellSandbox, type ShellSandboxOptions, setProcessShellSandbox, } from "./shell-sandbox.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{detectSandboxAvailability as t,setSandboxAvailabilityForTesting as r}from"./availability.js";import{collectBlockedAccesses as a,describeDenialForModel as l,parseOutput as n,parseViolationLine as i}from"./denial.js";import{domainMatches as S,filesystemRules as E,isAlwaysBlockedHost as x,isSandboxLevel as c,PROTECTED_HOME_READS as b,PROTECTED_HOME_WRITES as m,PROTECTED_WRITE_NAMES as R,readSandboxEnvironment as T,resolveSandboxPolicy as p,SANDBOX_ENV as A,SANDBOX_LEVELS as O,sandboxEnvironmentValue as _,stricterLevel as v}from"./policy.js";import{decideNetworkRequest as f,registerNetworkGrant as u,resetSandboxRuntime as N}from"./runtime.js";import{getProcessShellSandbox as y,registerSandboxEscalationHandler as L,ShellSandbox as M,setProcessShellSandbox as g}from"./shell-sandbox.js";export{b as PROTECTED_HOME_READS,m as PROTECTED_HOME_WRITES,R as PROTECTED_WRITE_NAMES,A as SANDBOX_ENV,O as SANDBOX_LEVELS,M as ShellSandbox,a as collectBlockedAccesses,f as decideNetworkRequest,l as describeDenialForModel,t as detectSandboxAvailability,S as domainMatches,E as filesystemRules,y as getProcessShellSandbox,x as isAlwaysBlockedHost,c as isSandboxLevel,n as parseOutput,i as parseViolationLine,T as readSandboxEnvironment,u as registerNetworkGrant,L as registerSandboxEscalationHandler,N as resetSandboxRuntime,p as resolveSandboxPolicy,_ as sandboxEnvironmentValue,g as setProcessShellSandbox,r as setSandboxAvailabilityForTesting,v as stricterLevel};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export type SandboxLevel = "read-only" | "workspace-write" | "off";
|
|
2
|
+
export declare const SANDBOX_LEVELS: readonly SandboxLevel[];
|
|
3
|
+
export interface SandboxSettings {
|
|
4
|
+
level?: SandboxLevel;
|
|
5
|
+
network?: {
|
|
6
|
+
allowedDomains?: string[];
|
|
7
|
+
deniedDomains?: string[];
|
|
8
|
+
allowLocalBinding?: boolean;
|
|
9
|
+
};
|
|
10
|
+
filesystem?: {
|
|
11
|
+
allowWrite?: string[];
|
|
12
|
+
denyRead?: string[];
|
|
13
|
+
denyWrite?: string[];
|
|
14
|
+
allowRead?: string[];
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface SandboxOverride {
|
|
18
|
+
level?: SandboxLevel;
|
|
19
|
+
allowedDomains?: string[];
|
|
20
|
+
}
|
|
21
|
+
export interface SandboxSettingsSources {
|
|
22
|
+
global?: SandboxSettings;
|
|
23
|
+
project?: SandboxSettings;
|
|
24
|
+
}
|
|
25
|
+
export interface ResolvedSandboxPolicy {
|
|
26
|
+
level: SandboxLevel;
|
|
27
|
+
levelSource: "override" | "environment" | "settings" | "project" | "default";
|
|
28
|
+
network: {
|
|
29
|
+
allowedDomains: string[];
|
|
30
|
+
deniedDomains: string[];
|
|
31
|
+
allowLocalBinding: boolean;
|
|
32
|
+
};
|
|
33
|
+
filesystem: {
|
|
34
|
+
allowWrite: string[];
|
|
35
|
+
denyRead: string[];
|
|
36
|
+
denyWrite: string[];
|
|
37
|
+
allowRead: string[];
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export declare const SANDBOX_ENV = "DAL_SANDBOX";
|
|
41
|
+
export declare function isSandboxLevel(value: unknown): value is SandboxLevel;
|
|
42
|
+
export declare function stricterLevel(a: SandboxLevel, b: SandboxLevel): SandboxLevel;
|
|
43
|
+
export declare function readSandboxEnvironment(env?: NodeJS.ProcessEnv): SandboxOverride | undefined;
|
|
44
|
+
export declare function sandboxEnvironmentValue(policy: ResolvedSandboxPolicy): string;
|
|
45
|
+
export declare function resolveSandboxPolicy(options: {
|
|
46
|
+
settings?: SandboxSettingsSources;
|
|
47
|
+
override?: SandboxOverride;
|
|
48
|
+
env?: NodeJS.ProcessEnv;
|
|
49
|
+
defaultLevel: SandboxLevel;
|
|
50
|
+
}): ResolvedSandboxPolicy;
|
|
51
|
+
export declare const PROTECTED_WRITE_NAMES: readonly string[];
|
|
52
|
+
export declare const PROTECTED_HOME_WRITES: readonly string[];
|
|
53
|
+
export declare const PROTECTED_HOME_READS: readonly string[];
|
|
54
|
+
export declare function expandPath(path: string, cwd: string): string;
|
|
55
|
+
export interface CommandFilesystemRules {
|
|
56
|
+
allowWrite: string[];
|
|
57
|
+
denyWrite: string[];
|
|
58
|
+
denyRead: string[];
|
|
59
|
+
}
|
|
60
|
+
export declare function filesystemRules(policy: ResolvedSandboxPolicy, cwd: string, options?: {
|
|
61
|
+
gitDirs?: string[];
|
|
62
|
+
extraWrite?: string[];
|
|
63
|
+
scratchDir?: string;
|
|
64
|
+
}): CommandFilesystemRules;
|
|
65
|
+
export declare function domainMatches(host: string, pattern: string): boolean;
|
|
66
|
+
export declare function isAlwaysBlockedHost(host: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var L=Object.defineProperty;var i=(e,t)=>L(e,"name",{value:t,configurable:!0});import{existsSync as A,readdirSync as O,realpathSync as N}from"node:fs";import{homedir as h}from"node:os";import{isAbsolute as W,join as u,relative as T,resolve as _}from"node:path";const C=["read-only","workspace-write","off"],g="DAL_SANDBOX",x={off:0,"workspace-write":1,"read-only":2};function y(e){return typeof e=="string"&&C.includes(e)}i(y,"isSandboxLevel");function j(e,t){return x[t]>x[e]?t:e}i(j,"stricterLevel");function a(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}i(a,"strings");function f(e){return[...new Set(e)]}i(f,"unique");const B=process.env[g];function I(e={[g]:B}){const t=e[g];if(t)try{const r=JSON.parse(t);return y(r.level)?{level:r.level,allowedDomains:a(r.allowedDomains)}:void 0}catch{return}}i(I,"readSandboxEnvironment");function q(e){return JSON.stringify({level:e.level,allowedDomains:e.network.allowedDomains})}i(q,"sandboxEnvironmentValue");function G(e){const t=e.settings?.global??{},r=e.settings?.project??{},s=I(e.env),l=e.override??{};let o,c;return l.level?(o=l.level,c="override"):s?.level?(o=s.level,c="environment"):y(t.level)?(o=t.level,c="settings"):(o=e.defaultLevel,c="default"),!l.level&&y(r.level)&&j(o,r.level)!==o&&(o=r.level,c="project"),{level:o,levelSource:c,network:{allowedDomains:f([...a(t.network?.allowedDomains),...a(s?.allowedDomains),...a(l.allowedDomains)]),deniedDomains:f([...a(t.network?.deniedDomains),...a(r.network?.deniedDomains)]),allowLocalBinding:t.network?.allowLocalBinding===!0},filesystem:{allowWrite:a(t.filesystem?.allowWrite),denyRead:f([...a(t.filesystem?.denyRead),...a(r.filesystem?.denyRead)]),denyWrite:f([...a(t.filesystem?.denyWrite),...a(r.filesystem?.denyWrite)]),allowRead:a(t.filesystem?.allowRead)}}}i(G,"resolveSandboxPolicy");const P=[".git/hooks",".git/config",".gitmodules",".dal",".claude",".agents",".mcp.json",".cursor",".vscode",".idea",".env"],z=[".gitconfig",".bashrc",".bash_profile",".zshrc",".zprofile",".profile",".config/fish",".dal"],H=[".ssh",".gnupg",".aws",".config/gcloud",".azure",".kube",".docker/config.json",".netrc",".npmrc",".pypirc",".git-credentials",".config/gh","Library/Keychains","Library/Application Support/Google/Chrome","Library/Application Support/Firefox","Library/Safari",".mozilla",".config/google-chrome",".config/chromium",".dal/agent/auth.json"];function m(e,t){return e==="~"?h():e.startsWith("~/")?u(h(),e.slice(2)):W(e)?e:_(t,e)}i(m,"expandPath");function v(e){try{return N(e)}catch{return e}}i(v,"realpathOrSelf");function D(e,t){const r=T(t,e);return r===""||!r.startsWith("..")&&!W(r)}i(D,"isWithin");function K(e,t,r={}){const s=h(),l=e.level==="workspace-write"?f([t,v(t),...e.filesystem.allowWrite.map(n=>m(n,t))]):[],o=e.level==="workspace-write"?r.gitDirs??[]:[],c=(r.extraWrite??[]).map(n=>m(n,t)),E=r.scratchDir?[r.scratchDir,v(r.scratchDir)]:[],k=f([...l,...o,...c,...E]),d=[];if(e.level==="read-only"){const n=f([t,v(t)]);c.some(w=>n.some(S=>D(w,S)||D(S,w)))||d.push(...n)}for(const n of[...l,...c]){for(const p of P)d.push(u(n,p));d.push(u(n,".env.*"));for(const p of M(n))d.push(u(n,p))}for(const n of o)d.push(u(n,"hooks"),u(n,"config"));for(const n of z)d.push(u(s,n));d.push(...e.filesystem.denyWrite.map(n=>m(n,t)));const R=new Set(e.filesystem.allowRead.map(n=>m(n,t))),b=[...H.map(n=>u(s,n)).filter(n=>!R.has(n)),...e.filesystem.denyRead.map(n=>m(n,t))];return{allowWrite:k,denyWrite:f(d),denyRead:f(b)}}i(K,"filesystemRules");function M(e){if(!A(e))return[];try{return O(e).filter(t=>t.startsWith(".env."))}catch{return[]}}i(M,"listEnvFiles");function $(e,t){const r=e.toLowerCase(),s=t.toLowerCase();return s.startsWith("*.")?r.endsWith(s.slice(1)):r===s}i($,"domainMatches");function Q(e){const t=e.toLowerCase().replace(/^\[|\]$/g,"");if(t==="localhost"||t.endsWith(".localhost")||t==="::1"||t==="0.0.0.0")return!0;if(t.startsWith("fe80:")||t.startsWith("fc")||t.startsWith("fd"))return t.includes(":");const r=t.split(".").map(o=>Number(o));if(r.length!==4||r.some(o=>!Number.isInteger(o)||o<0||o>255))return!1;const[s,l]=r;return s===127||s===10||s===172&&l>=16&&l<=31||s===192&&l===168||s===169&&l===254}i(Q,"isAlwaysBlockedHost");export{H as PROTECTED_HOME_READS,z as PROTECTED_HOME_WRITES,P as PROTECTED_WRITE_NAMES,g as SANDBOX_ENV,C as SANDBOX_LEVELS,$ as domainMatches,m as expandPath,K as filesystemRules,Q as isAlwaysBlockedHost,y as isSandboxLevel,I as readSandboxEnvironment,G as resolveSandboxPolicy,q as sandboxEnvironmentValue,j as stricterLevel};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SandboxViolationEvent } from "@anthropic-ai/sandbox-runtime";
|
|
2
|
+
export interface NetworkRefusal {
|
|
3
|
+
host: string;
|
|
4
|
+
port?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface NetworkGrant {
|
|
7
|
+
allowedDomains: readonly string[];
|
|
8
|
+
deniedDomains: readonly string[];
|
|
9
|
+
refusals: NetworkRefusal[];
|
|
10
|
+
}
|
|
11
|
+
export interface WrapRequest {
|
|
12
|
+
command: string;
|
|
13
|
+
shell: string;
|
|
14
|
+
allowWrite: string[];
|
|
15
|
+
denyWrite: string[];
|
|
16
|
+
denyRead: string[];
|
|
17
|
+
allowLocalBinding: boolean;
|
|
18
|
+
ripgrep?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function registerNetworkGrant(grant: NetworkGrant): () => void;
|
|
21
|
+
export declare function decideNetworkRequest(host: string, port: number | undefined): boolean;
|
|
22
|
+
export declare function proxyUnavailableReason(): string | undefined;
|
|
23
|
+
export declare function acquireSandboxRuntime(): void;
|
|
24
|
+
export declare function releaseSandboxRuntime(): Promise<void>;
|
|
25
|
+
export declare function wrapCommand(request: WrapRequest, grant: NetworkGrant): Promise<{
|
|
26
|
+
command: string;
|
|
27
|
+
release: () => void;
|
|
28
|
+
proxied: boolean;
|
|
29
|
+
}>;
|
|
30
|
+
export declare function violationsForCommand(command: string, since: number, waitMs: number): Promise<SandboxViolationEvent[]>;
|
|
31
|
+
export declare function resetSandboxRuntime(): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var h=Object.defineProperty;var t=(e,o)=>h(e,"name",{value:o,configurable:!0});import{domainMatches as y,isAlwaysBlockedHost as b}from"./policy.js";const g="dal-sandbox.invalid",l=new Set;let d,s,u,x=Promise.resolve(),m=0;async function D(){return d??=import("@anthropic-ai/sandbox-runtime").then(e=>e.SandboxManager),d}t(D,"loadManager");function S(e){return{network:{allowedDomains:[g],deniedDomains:[],allowLocalBinding:e.allowLocalBinding},filesystem:{denyRead:[],allowWrite:[],denyWrite:[]},...e.ripgrep?{ripgrep:{command:e.ripgrep}}:{}}}t(S,"baseConfig");function I(e){return l.add(e),()=>{l.delete(e)}}t(I,"registerNetworkGrant");function T(e,o){let a=!1;if(!b(e))for(const r of l)r.deniedDomains.some(n=>y(e,n))||r.allowedDomains.some(n=>y(e,n))&&(a=!0);if(!a)for(const r of l)r.refusals.some(n=>n.host===e&&n.port===o)||r.refusals.push({host:e,...o!==void 0?{port:o}:{}});return a}t(T,"decideNetworkRequest");function R(){const e=process._getActiveHandles;return new Set(typeof e=="function"?e.call(process):[])}t(R,"activeHandles");async function v(e,o){s||(u??=(async()=>{const a={SIGINT:new Set(process.listeners("SIGINT")),SIGTERM:new Set(process.listeners("SIGTERM"))},r=R();try{await e.initialize(S(o),async({host:n,port:i})=>T(n,i),!1),s={ready:!0}}catch(n){s={ready:!1,error:n instanceof Error?n.message:String(n)}}finally{for(const n of["SIGINT","SIGTERM"])for(const i of process.listeners(n))a[n].has(i)||process.removeListener(n,i);for(const n of R())!r.has(n)&&typeof n.unref=="function"&&n.unref()}})(),await u)}t(v,"ensureProxy");function W(){return s&&!s.ready?s.error:void 0}t(W,"proxyUnavailableReason");function E(){m++}t(E,"acquireSandboxRuntime");async function L(){m=Math.max(0,m-1),m===0&&await G()}t(L,"releaseSandboxRuntime");async function N(e,o){const a=await D(),r=o.allowedDomains.length>0;r&&await v(a,e);const n=t(async()=>{const w={denyRead:e.denyRead,allowWrite:e.allowWrite,denyWrite:e.denyWrite};a.updateConfig({...S(e),filesystem:w});const p=r&&s?.ready===!0;return{wrapped:await a.wrapWithSandbox(e.command,e.shell,{network:{allowedDomains:p?[g]:[],deniedDomains:[]},filesystem:w}),proxied:p}},"run"),i=x.then(n,n);x=i.catch(()=>{});const{wrapped:f,proxied:c}=await i;return{command:f,proxied:c,release:I(o)}}t(N,"wrapCommand");async function P(e,o,a){if(!d)return[];const n=(await d).getSandboxViolationStore();if(n.getTotalCount()===0)return[];const i=Date.now()+a;for(;;){const f=n.getViolationsForCommand(e).filter(c=>c.timestamp.getTime()>=o-1e3);if(f.length>0||Date.now()>=i)return f;await new Promise(c=>setTimeout(c,50))}}t(P,"violationsForCommand");async function G(){l.clear();const e=s!==void 0;if(s=void 0,u=void 0,!e||!d)return;await(await d).reset()}t(G,"resetSandboxRuntime");export{E as acquireSandboxRuntime,T as decideNetworkRequest,W as proxyUnavailableReason,I as registerNetworkGrant,L as releaseSandboxRuntime,G as resetSandboxRuntime,P as violationsForCommand,N as wrapCommand};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { ExtensionContext } from "../extensions/types.ts";
|
|
2
|
+
import { type SandboxAvailability } from "./availability.ts";
|
|
3
|
+
import { type SandboxDenial } from "./denial.ts";
|
|
4
|
+
import { type ResolvedSandboxPolicy, type SandboxLevel, type SandboxOverride } from "./policy.ts";
|
|
5
|
+
export interface SandboxEscalationInput {
|
|
6
|
+
mode: "allow" | "unsandboxed";
|
|
7
|
+
justification: string;
|
|
8
|
+
allow_domains?: string[];
|
|
9
|
+
allow_write?: string[];
|
|
10
|
+
}
|
|
11
|
+
export interface SandboxEscalationRequest {
|
|
12
|
+
toolCallId: string;
|
|
13
|
+
toolName: string;
|
|
14
|
+
command: string;
|
|
15
|
+
cwd: string;
|
|
16
|
+
level: SandboxLevel;
|
|
17
|
+
mode: "allow" | "unsandboxed";
|
|
18
|
+
justification: string;
|
|
19
|
+
allowDomains: string[];
|
|
20
|
+
allowWrite: string[];
|
|
21
|
+
background: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface SandboxEscalationDecision {
|
|
24
|
+
approved: boolean;
|
|
25
|
+
scope?: "once" | "session";
|
|
26
|
+
message?: string;
|
|
27
|
+
}
|
|
28
|
+
export type SandboxEscalationHandler = (request: SandboxEscalationRequest, ctx: ExtensionContext | undefined) => Promise<SandboxEscalationDecision | undefined> | SandboxEscalationDecision | undefined;
|
|
29
|
+
export type SandboxEvent = {
|
|
30
|
+
type: "sandbox_denied";
|
|
31
|
+
toolCallId: string;
|
|
32
|
+
toolName: string;
|
|
33
|
+
denial: SandboxDenial;
|
|
34
|
+
} | {
|
|
35
|
+
type: "sandbox_escalation";
|
|
36
|
+
toolCallId: string;
|
|
37
|
+
toolName: string;
|
|
38
|
+
request: SandboxEscalationRequest;
|
|
39
|
+
decision: SandboxEscalationDecision;
|
|
40
|
+
decidedBy: "sdk" | "handler" | "ui" | "none";
|
|
41
|
+
};
|
|
42
|
+
export interface SandboxStatus {
|
|
43
|
+
level: SandboxLevel;
|
|
44
|
+
levelSource: ResolvedSandboxPolicy["levelSource"];
|
|
45
|
+
enforced: boolean;
|
|
46
|
+
platform: NodeJS.Platform;
|
|
47
|
+
mechanism?: SandboxAvailability["mechanism"];
|
|
48
|
+
unavailableReason?: string;
|
|
49
|
+
network: {
|
|
50
|
+
allowedDomains: string[];
|
|
51
|
+
deniedDomains: string[];
|
|
52
|
+
proxyError?: string;
|
|
53
|
+
};
|
|
54
|
+
sessionAllowances: {
|
|
55
|
+
domains: string[];
|
|
56
|
+
writablePaths: string[];
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export interface SandboxOptions extends SandboxOverride {
|
|
60
|
+
defaultLevel?: SandboxLevel;
|
|
61
|
+
onEscalation?: SandboxEscalationHandler;
|
|
62
|
+
}
|
|
63
|
+
export interface ShellSandboxOptions {
|
|
64
|
+
policy: ResolvedSandboxPolicy;
|
|
65
|
+
onEscalation?: SandboxEscalationHandler;
|
|
66
|
+
onEvent?: (event: SandboxEvent) => void;
|
|
67
|
+
availability?: SandboxAvailability;
|
|
68
|
+
scratchDir?: () => string;
|
|
69
|
+
}
|
|
70
|
+
export interface PreparedCommand {
|
|
71
|
+
command: string;
|
|
72
|
+
sandboxed: boolean;
|
|
73
|
+
details: SandboxRunDetails;
|
|
74
|
+
finish(exitCode: number | null, output: string): Promise<SandboxDenial | undefined>;
|
|
75
|
+
}
|
|
76
|
+
export interface SandboxRunDetails {
|
|
77
|
+
level: SandboxLevel;
|
|
78
|
+
sandboxed: boolean;
|
|
79
|
+
escalation?: {
|
|
80
|
+
request: SandboxEscalationRequest;
|
|
81
|
+
decision: SandboxEscalationDecision;
|
|
82
|
+
};
|
|
83
|
+
denial?: SandboxDenial;
|
|
84
|
+
}
|
|
85
|
+
export declare function registerSandboxEscalationHandler(handler: SandboxEscalationHandler): () => void;
|
|
86
|
+
export declare function setProcessShellSandbox(sandbox: ShellSandbox | undefined): void;
|
|
87
|
+
export declare function getProcessShellSandbox(): ShellSandbox | undefined;
|
|
88
|
+
export declare class ShellSandbox {
|
|
89
|
+
readonly policy: ResolvedSandboxPolicy;
|
|
90
|
+
private readonly onEscalation?;
|
|
91
|
+
private readonly onEvent?;
|
|
92
|
+
private readonly availabilityOverride?;
|
|
93
|
+
private readonly sessionDomains;
|
|
94
|
+
private readonly sessionWritable;
|
|
95
|
+
private holdsRuntime;
|
|
96
|
+
private readonly sharedScratch?;
|
|
97
|
+
private ownScratch;
|
|
98
|
+
constructor(options: ShellSandboxOptions);
|
|
99
|
+
scratchDir(): string;
|
|
100
|
+
dispose(): Promise<void>;
|
|
101
|
+
get level(): SandboxLevel;
|
|
102
|
+
get active(): boolean;
|
|
103
|
+
private availability;
|
|
104
|
+
status(): SandboxStatus;
|
|
105
|
+
describeForModel(): string | undefined;
|
|
106
|
+
unavailableRefusal(): string | undefined;
|
|
107
|
+
prepare(request: {
|
|
108
|
+
command: string;
|
|
109
|
+
cwd: string;
|
|
110
|
+
shell: string;
|
|
111
|
+
toolCallId: string;
|
|
112
|
+
toolName: string;
|
|
113
|
+
escalation?: SandboxEscalationInput;
|
|
114
|
+
background?: boolean;
|
|
115
|
+
ctx?: ExtensionContext;
|
|
116
|
+
}): Promise<PreparedCommand>;
|
|
117
|
+
private approveEscalation;
|
|
118
|
+
}
|
|
119
|
+
export declare function createScratchDir(): string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
var M=Object.defineProperty;var r=(o,e)=>M(o,"name",{value:e,configurable:!0});import{spawnSync as O}from"node:child_process";import{mkdtempSync as B,rmSync as L}from"node:fs";import{tmpdir as U}from"node:os";import{isAbsolute as W,join as H,relative as F,resolve as K}from"node:path";import{fill as f,t as d}from"../../dal/i18n.js";import{detectSandboxAvailability as Q}from"./availability.js";import{collectBlockedAccesses as X}from"./denial.js";import{expandPath as Y,filesystemRules as z}from"./policy.js";import{acquireSandboxRuntime as G,proxyUnavailableReason as R,releaseSandboxRuntime as J,violationsForCommand as V,wrapCommand as Z}from"./runtime.js";const v=Symbol.for("dal.sandbox.escalationHandlers"),x=globalThis;x[v]instanceof Set||(x[v]=new Set);const g=x[v];function ue(o){return g.add(o),()=>{g.delete(o)}}r(ue,"registerSandboxEscalationHandler");let $;function pe(o){$=o}r(pe,"setProcessShellSandbox");function we(){return $}r(we,"getProcessShellSandbox");const j=new Map;function q(o){const e=j.get(o);if(e)return e;const t=O("git",["rev-parse","--absolute-git-dir","--git-common-dir"],{cwd:o,encoding:"utf8",timeout:3e3}),a=[];if(t.status===0)for(const l of t.stdout.split(`
|
|
2
|
+
`)){const n=l.trim();if(!n)continue;const s=W(n)?n:K(o,n),c=F(o,s);(c.startsWith("..")||W(c))&&a.push(s)}const i=[...new Set(a)];return j.set(o,i),i}r(q,"gitDirsOutside");function C(o){return Array.isArray(o)?o.filter(e=>typeof e=="string"&&e.trim().length>0).map(e=>e.trim()):[]}r(C,"cleanList");let ee=0;class be{static{r(this,"ShellSandbox")}policy;onEscalation;onEvent;availabilityOverride;sessionDomains=new Set;sessionWritable=new Set;holdsRuntime=!1;sharedScratch;ownScratch;constructor(e){this.policy=e.policy,this.onEscalation=e.onEscalation,this.onEvent=e.onEvent,this.availabilityOverride=e.availability,this.sharedScratch=e.scratchDir,this.active&&(G(),this.holdsRuntime=!0)}scratchDir(){return this.sharedScratch?this.sharedScratch():(this.ownScratch??=oe(),this.ownScratch)}async dispose(){this.ownScratch&&(L(this.ownScratch,{recursive:!0,force:!0}),this.ownScratch=void 0),this.holdsRuntime&&(this.holdsRuntime=!1,await J())}get level(){return this.policy.level}get active(){return this.policy.level!=="off"}availability(){return this.availabilityOverride??Q()}status(){const e=this.availability(),t=R();return{level:this.policy.level,levelSource:this.policy.levelSource,enforced:this.active&&e.available,platform:e.platform,...e.mechanism?{mechanism:e.mechanism}:{},...this.active&&!e.available&&e.reason?{unavailableReason:e.reason}:{},network:{allowedDomains:[...this.policy.network.allowedDomains],deniedDomains:[...this.policy.network.deniedDomains],...t?{proxyError:t}:{}},sessionAllowances:{domains:[...this.sessionDomains],writablePaths:[...this.sessionWritable]}}}describeForModel(){if(!this.active)return;const e=this.policy.level==="read-only"?"nothing may be written except $TMPDIR (a scratch directory for this session)":"writes are limited to the working directory and $TMPDIR (a scratch directory for this session; agent/editor config, git hooks and .env files stay read-only)",t=this.policy.network.allowedDomains,a=t.length>0?`network is off except ${t.join(", ")}`:"network is off";return`Commands run inside an OS sandbox (${this.policy.level}): ${e}; ${a}; credential files such as ~/.ssh cannot be read. When the sandbox blocks something the result says what; only then, and only if the task needs it, retry with sandbox_escalation.`}unavailableRefusal(){if(!this.active)return;const e=this.availability();if(e.available)return;const t=e.platform==="win32";return[`Command refused: the sandbox level is "${this.policy.level}", but ${e.reason??"the OS sandbox is unavailable."}`,"Commands are not run without the sandbox unless the user says so explicitly.",t?'To run commands on Windows, the user must opt out: `dal --sandbox off`, or "sandbox": { "level": "off" } in ~/.dal/agent/settings.json.':'The user can fix the sandbox, or opt out explicitly with `dal --sandbox off` or "sandbox": { "level": "off" } in ~/.dal/agent/settings.json.','A single command can still run if the user approves it: retry with sandbox_escalation {"mode":"unsandboxed","justification":"..."}.'].join(`
|
|
3
|
+
`)}async prepare(e){const t=this.policy.level;if(t==="off")return I(e.command,{level:t,sandboxed:!1});const a=this.unavailableRefusal();if(a&&e.escalation?.mode!=="unsandboxed")throw new Error(a);let i=[],l=[],n;if(e.escalation){const h=await this.approveEscalation(e,e.escalation);if(n=h,!h.decision.approved)throw new Error(`Sandbox escalation refused${h.decision.message?`: ${h.decision.message}`:"."} Do not retry the same escalation; continue without it or ask the user.`);if(h.request.mode==="unsandboxed")return I(e.command,{level:t,sandboxed:!1,escalation:n});i=h.request.allowDomains,l=h.request.allowWrite}const s=this.availability(),c=this.scratchDir(),m=z(this.policy,e.cwd,{gitDirs:this.policy.level==="workspace-write"?q(e.cwd):[],extraWrite:[...this.sessionWritable,...l],scratchDir:c}),S={allowedDomains:[...this.policy.network.allowedDomains,...this.sessionDomains,...i],deniedDomains:this.policy.network.deniedDomains,refusals:[]},A=`${process.pid}-${++ee}`,u=te(c),D=`export DAL_SANDBOX_RUN=${A} TMPDIR=${u} TMP=${u} TEMP=${u}
|
|
4
|
+
${e.command}`,_=Date.now(),p=await Z({command:D,shell:e.shell,allowWrite:m.allowWrite,denyWrite:m.denyWrite,denyRead:m.denyRead,allowLocalBinding:e.background===!0||this.policy.network.allowLocalBinding,...s.ripgrep?{ripgrep:s.ripgrep}:{}},S),w={level:t,sandboxed:!0,...n?{escalation:n}:{}};let k=!1;return{command:p.command,sandboxed:!0,details:w,finish:r(async(h,P)=>{if(k)return w.denial;if(k=!0,p.release(),h===0)return;const N=s.platform==="darwin"?await V(D,_,400):[],b=X({refusals:S.refusals,violations:N,output:P});if(!b)return;const E=p.proxied?void 0:R(),y={level:t,platform:s.platform,command:e.command,cwd:e.cwd,blocked:b,...E&&b.some(T=>T.kind==="network")?{networkProxyError:E}:{}};return w.denial=y,this.onEvent?.({type:"sandbox_denied",toolCallId:e.toolCallId,toolName:e.toolName,denial:y}),y},"finish")}}async approveEscalation(e,t){const a=t.mode==="unsandboxed"?"unsandboxed":"allow",i={toolCallId:e.toolCallId,toolName:e.toolName,command:e.command,cwd:e.cwd,level:this.policy.level,mode:a,justification:typeof t.justification=="string"?t.justification.trim():"",allowDomains:a==="allow"?C(t.allow_domains):[],allowWrite:a==="allow"?C(t.allow_write).map(n=>Y(n,e.cwd)):[],background:e.background===!0},l=r((n,s)=>{const c=n.approved&&n.scope==="session"&&a==="unsandboxed"?{...n,scope:"once"}:n;if(c.approved&&c.scope==="session"){for(const m of i.allowDomains)this.sessionDomains.add(m);for(const m of i.allowWrite)this.sessionWritable.add(m)}return this.onEvent?.({type:"sandbox_escalation",toolCallId:e.toolCallId,toolName:e.toolName,request:i,decision:c,decidedBy:s}),{request:i,decision:c}},"finish");if(!i.justification)return l({approved:!1,message:"an escalation needs a justification"},"none");if(a==="allow"&&i.allowDomains.length===0&&i.allowWrite.length===0)return l({approved:!1,message:'mode "allow" needs allow_domains or allow_write'},"none");if(this.onEscalation){const n=await this.onEscalation(i,e.ctx);if(n)return l(n,"sdk")}for(const n of g){const s=await n(i,e.ctx);if(s)return l(s,"handler")}return e.ctx?.hasUI?l(await ne(i,e.ctx),"ui"):l({approved:!1,message:"nobody is available to approve it (no interactive UI and no approver configured)"},"none")}}function I(o,e){return{command:o,sandboxed:!1,details:e,finish:r(async()=>{},"finish")}}r(I,"passthrough");function oe(){return B(H(U(),"dal-sandbox-"))}r(oe,"createScratchDir");function te(o){return`'${o.replace(/'/g,"'\\''")}'`}r(te,"shellQuote");async function ne(o,e){const t=d("\u4EC5\u672C\u6B21\u5141\u8BB8"),a=d("\u672C\u4F1A\u8BDD\u5185\u90FD\u5141\u8BB8"),i=d("\u62D2\u7EDD"),l=o.mode==="unsandboxed"?d("\u5728\u6C99\u7BB1\u4E4B\u5916\u8FD0\u884C\u547D\u4EE4\uFF08\u53EF\u8BBF\u95EE\u4F60\u7684\u5168\u90E8\u6587\u4EF6\u548C\u7F51\u7EDC\uFF09"):[o.allowDomains.length>0?f(d("\u8BBF\u95EE {domains}"),{domains:o.allowDomains.join(", ")}):"",o.allowWrite.length>0?f(d("\u5199\u5165 {paths}"),{paths:o.allowWrite.join(", ")}):""].filter(Boolean).join(d("\uFF0C\u5E76")),n=[f(d("\u52A9\u624B\u60F3\u8981{what}\u3002"),{what:l}),f(d("\u547D\u4EE4\uFF1A{command}"),{command:o.command}),f(d("\u76EE\u5F55\uFF1A{cwd}"),{cwd:o.cwd}),f(d("\u52A9\u624B\u7ED9\u7684\u7406\u7531\uFF08\u672A\u7ECF\u6838\u5B9E\uFF09\uFF1A{reason}"),{reason:o.justification})].join(`
|
|
5
|
+
`),s=o.mode==="unsandboxed"?[t,i]:[t,a,i],c=await e.ui.select(n,s);return c===t?{approved:!0,scope:"once"}:c===a?{approved:!0,scope:"session"}:{approved:!1,message:"the user declined"}}r(ne,"askThroughUi");export{be as ShellSandbox,oe as createScratchDir,we as getProcessShellSandbox,ue as registerSandboxEscalationHandler,pe as setProcessShellSandbox};
|