dal-code 1.0.43 → 1.0.45
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 +36 -0
- package/NOTICE +17 -0
- package/PRIVACY.md +159 -102
- package/dal-docs/README.md +1 -1
- package/dal-docs/keybindings.md +1 -0
- package/dal-docs/settings.md +5 -0
- package/dist/cli/credential-print.js +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.js +1 -1
- package/dist/core/agent-session-runtime.js +1 -1
- package/dist/core/agent-session.d.ts +1 -1
- package/dist/core/agent-session.js +7 -7
- package/dist/core/auth-storage.js +1 -1
- package/dist/core/background-processes.js +7 -7
- package/dist/core/export-html/template.js +34 -34
- package/dist/core/extensions/runner.js +1 -1
- package/dist/core/extensions/types.d.ts +7 -1
- package/dist/core/key-id-schema.js +1 -0
- package/dist/core/keybindings-schema.js +1 -0
- package/dist/core/keybindings.d.ts +5 -0
- package/dist/core/keybindings.js +1 -1
- package/dist/core/model-config.d.ts +818 -99
- package/dist/core/model-config.js +5 -5
- package/dist/core/model-resolver.d.ts +30 -10
- package/dist/core/model-resolver.js +1 -1
- package/dist/core/model-runtime.d.ts +1 -0
- package/dist/core/model-runtime.js +2 -2
- package/dist/core/package-manager.d.ts +5 -0
- package/dist/core/package-manager.js +2 -2
- package/dist/core/permissions/shell-words.d.ts +26 -0
- package/dist/core/permissions/tool-policy.d.ts +2 -1
- package/dist/core/permissions/tool-policy.js +1 -1
- package/dist/core/project-trust.js +2 -2
- package/dist/core/prompt-templates.js +2 -2
- package/dist/core/remote-catalog-provider.js +1 -1
- package/dist/core/resource-loader.js +1 -1
- package/dist/core/sandbox/libreoffice.js +1 -0
- package/dist/core/sandbox/runtime.d.ts +1 -0
- package/dist/core/sandbox/runtime.js +1 -1
- package/dist/core/sandbox/shell-sandbox.js +6 -6
- package/dist/core/sandbox/windows.js +4 -4
- package/dist/core/session-manager.d.ts +1 -0
- package/dist/core/session-manager.js +12 -12
- package/dist/core/settings-defaults.js +1 -0
- package/dist/core/settings-manager.d.ts +5 -0
- package/dist/core/settings-manager.js +1 -1
- package/dist/core/settings-schema.d.ts +229 -0
- package/dist/core/settings-schema.js +1 -0
- package/dist/core/tool-denial.d.ts +13 -0
- package/dist/core/tool-denial.js +1 -0
- package/dist/core/tools/bash-read-only.d.ts +1 -0
- package/dist/core/tools/bash.js +13 -13
- package/dist/core/tools/read.js +12 -12
- package/dist/core/tools/render-utils.d.ts +40 -0
- package/dist/core/tools/render-utils.js +7 -7
- package/dist/core/tools/renderers/read.js +8 -8
- package/dist/core/trust-manager.js +1 -1
- package/dist/core/workspace-lock.d.ts +6 -2
- package/dist/core/workspace-lock.js +3 -3
- package/dist/dal/extension-compat.js +4 -4
- package/dist/dal/hooks/config.d.ts +5 -1
- package/dist/dal/hooks/config.js +1 -1
- package/dist/dal/hooks/extension.js +3 -3
- package/dist/dal/hooks/index.d.ts +1 -1
- package/dist/dal/hooks/index.js +1 -1
- package/dist/dal/i18n.js +1 -1
- package/dist/dal/manifest.js +1 -1
- package/dist/extensions/codemode/execute.js +14 -13
- package/dist/extensions/codemode/index.js +1 -1
- package/dist/extensions/codemode/renderer.js +6 -6
- package/dist/extensions/codemode/tool.d.ts +2 -3
- package/dist/extensions/codemode/tool.js +9 -12
- package/dist/extensions/mcp/cli.js +4 -4
- package/dist/extensions/mcp/index.js +12 -12
- package/dist/extensions/mcp/resources.d.ts +0 -5
- package/dist/extensions/mcp/resources.js +1 -1
- package/dist/extensions/mcp/runtime.d.ts +1 -4
- package/dist/extensions/mcp/runtime.js +3 -3
- package/dist/extensions/mcp/tools.js +7 -7
- package/dist/extensions/tool-search/tool.js +3 -3
- package/dist/index.d.ts +6 -2
- package/dist/index.js +1 -1
- package/dist/main.js +3 -3
- package/dist/migrations.js +5 -5
- package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
- package/dist/modes/interactive/components/settings-selector.js +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts +1 -1
- package/dist/modes/interactive/components/status-indicator.js +1 -1
- package/dist/modes/interactive/components/tree-selector.js +1 -1
- package/dist/modes/interactive/interactive-mode.js +17 -17
- package/dist/modes/interactive/session-share.js +2 -2
- package/dist/modes/interactive/theme/dark.json +1 -1
- package/dist/modes/interactive/theme/light.json +1 -1
- package/dist/modes/interactive/theme/theme-schema.d.ts +18 -0
- package/dist/modes/interactive/theme/theme-schema.js +12 -0
- package/dist/modes/interactive/theme/theme-tokens.d.ts +255 -0
- package/dist/modes/interactive/theme/theme-tokens.js +1 -0
- package/dist/modes/interactive/theme/theme.d.ts +7 -10
- package/dist/modes/interactive/theme/theme.js +5 -5
- package/dist/modes/rpc/rpc-client.d.ts +5 -1
- package/dist/modes/rpc/rpc-client.js +2 -2
- package/dist/modes/rpc/rpc-mode.js +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +20 -0
- package/dist/node_modules/@dalcode/dal-advisor/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-advisor/src/index.js +8 -8
- package/dist/node_modules/@dalcode/dal-awake/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-bridge/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-capabilities/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-capabilities/src/index.js +10 -10
- package/dist/node_modules/@dalcode/dal-codeindex/package.json +34 -0
- package/dist/node_modules/@dalcode/dal-codeindex/src/extract.js +3 -0
- package/dist/node_modules/@dalcode/dal-codeindex/src/format.js +11 -0
- package/dist/node_modules/@dalcode/dal-codeindex/src/index.js +4 -0
- package/dist/node_modules/@dalcode/dal-codeindex/src/indexer.js +1 -0
- package/dist/node_modules/@dalcode/dal-codeindex/src/languages.js +176 -0
- package/dist/node_modules/@dalcode/dal-codeindex/src/project.js +1 -0
- package/dist/node_modules/@dalcode/dal-codeindex/src/query.js +2 -0
- package/dist/node_modules/@dalcode/dal-codeindex/src/runtime.js +1 -0
- package/dist/node_modules/@dalcode/dal-codeindex/src/scan.js +1 -0
- package/dist/node_modules/@dalcode/dal-codeindex/src/semantic.js +2 -0
- package/dist/node_modules/@dalcode/dal-codeindex/src/sqlite.js +1 -0
- package/dist/node_modules/@dalcode/dal-codeindex/src/store.js +33 -0
- package/dist/node_modules/@dalcode/dal-codeindex/src/worker.js +1 -0
- package/dist/node_modules/@dalcode/dal-compat/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-dap/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-goal/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-guard/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-guard/src/index.js +4 -2
- package/dist/node_modules/@dalcode/dal-guard/src/mode.js +2 -2
- package/dist/node_modules/@dalcode/dal-guard/src/policy.js +1 -0
- package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-interactive/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-learn/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-lsp/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-lsp/src/index.js +12 -10
- package/dist/node_modules/@dalcode/dal-mcp/package.json +7 -5
- package/dist/node_modules/@dalcode/dal-mcp/src/http-client.d.ts +9 -27
- package/dist/node_modules/@dalcode/dal-mcp/src/http-client.js +1 -2
- package/dist/node_modules/@dalcode/dal-mcp/src/index.js +17 -17
- package/dist/node_modules/@dalcode/dal-mcp/src/protocol-client.d.ts +38 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/protocol-client.js +1 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/proxy.js +6 -6
- package/dist/node_modules/@dalcode/dal-mcp/src/resources.js +1 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.d.ts +9 -18
- package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.js +4 -5
- package/dist/node_modules/@dalcode/dal-mcp/src/types.d.ts +50 -5
- package/dist/node_modules/@dalcode/dal-mcp/src/types.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-office/src/index.d.ts +2 -2
- package/dist/node_modules/@dalcode/dal-office/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/render/docx.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/render/pptx.d.ts +8 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/pptx.js +3 -3
- package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/themes.d.ts +2 -0
- package/dist/node_modules/@dalcode/dal-office/src/themes.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-generate.js +3 -2
- package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-plan.js +2 -2
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +9 -3
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/session-scope.js +1 -0
- package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +9 -3
- package/dist/node_modules/@dalcode/dal-pi-kit/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/src/session-scope.js +1 -0
- package/dist/node_modules/@dalcode/dal-plugins/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-plugins/src/brand.js +1 -1
- package/dist/node_modules/@dalcode/dal-plugins/src/index.js +11 -11
- package/dist/node_modules/@dalcode/dal-recall/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-remote/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-remote/src/cli.js +14 -9
- package/dist/node_modules/@dalcode/dal-remote/src/processes.js +2 -0
- package/dist/node_modules/@dalcode/dal-remote/src/service.js +7 -7
- package/dist/node_modules/@dalcode/dal-remote/src/spec.js +1 -1
- package/dist/node_modules/@dalcode/dal-review/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-rewind/src/core.d.ts +0 -1
- package/dist/node_modules/@dalcode/dal-rewind/src/core.js +8 -8
- package/dist/node_modules/@dalcode/dal-rewind/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-router/package.json +9 -5
- package/dist/node_modules/@dalcode/dal-router/src/advisor.js +1 -1
- package/dist/node_modules/@dalcode/dal-router/src/commands.js +8 -7
- package/dist/node_modules/@dalcode/dal-router/src/config.d.ts +11 -0
- package/dist/node_modules/@dalcode/dal-router/src/config.js +2 -2
- package/dist/node_modules/@dalcode/dal-router/src/index.js +4 -4
- package/dist/node_modules/@dalcode/dal-router/src/roles/changes.js +5 -0
- package/dist/node_modules/@dalcode/dal-router/src/roles/index.js +13 -0
- package/dist/node_modules/@dalcode/dal-router/src/roles/models.d.ts +50 -0
- package/dist/node_modules/@dalcode/dal-router/src/roles/models.js +1 -0
- package/dist/node_modules/@dalcode/dal-router/src/roles/prompts.js +40 -0
- package/dist/node_modules/@dalcode/dal-router/src/roles/signals.js +2 -0
- package/dist/node_modules/@dalcode/dal-router/src/runtime.d.ts +3 -0
- package/dist/node_modules/@dalcode/dal-router/src/runtime.js +1 -1
- package/dist/node_modules/@dalcode/dal-router/src/subagent.js +1 -1
- package/dist/node_modules/@dalcode/dal-rtk/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-skills/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/dal-slides/SKILL.md +74 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled.js +1 -1
- package/dist/node_modules/@dalcode/dal-skills/src/client.js +1 -1
- package/dist/node_modules/@dalcode/dal-skills/src/index.js +14 -14
- package/dist/node_modules/@dalcode/dal-skills/src/packages.js +3 -3
- package/dist/node_modules/@dalcode/dal-skills/src/search.js +1 -1
- package/dist/node_modules/@dalcode/dal-statusline/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-structured/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-subagent/src/background.js +8 -8
- package/dist/node_modules/@dalcode/dal-subagent/src/index.js +21 -21
- package/dist/node_modules/@dalcode/dal-subagent/src/progress.js +1 -1
- package/dist/node_modules/@dalcode/dal-telemetry/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-tool-catalog/src/index.js +4 -4
- package/dist/node_modules/@dalcode/dal-usage/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-web/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-workflow/LICENSE +27 -0
- 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/dal-workflow/src/todo-snapshot.js +2 -0
- package/dist/node_modules/@dalcode/dal-workflow/src/todo.js +4 -4
- package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
- 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/types.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-ai/README.md +5 -34
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +5 -5
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +4 -4
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +6 -6
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +2 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/index.d.ts +0 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/index.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/models.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/models.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/compat-schema.d.ts +359 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/compat-schema.js +1 -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/amazon-bedrock.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/anthropic.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/azure.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cerebras.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/groq.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.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/opencode.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/qwen-token-plan-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.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/data/together.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xai.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-ams.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-sgp.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/model-schema.d.ts +90 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/model-schema.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openrouter-api.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/types.d.ts +5 -146
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-codemode/README.md +195 -11
- package/dist/node_modules/@earendil-works/pi-codemode/dist/cloudflare.js +1 -0
- package/dist/node_modules/@earendil-works/pi-codemode/dist/declarations.d.ts +0 -2
- package/dist/node_modules/@earendil-works/pi-codemode/dist/declarations.js +9 -84
- package/dist/node_modules/@earendil-works/pi-codemode/dist/index.d.ts +5 -2
- package/dist/node_modules/@earendil-works/pi-codemode/dist/index.js +1 -1
- package/dist/node_modules/@earendil-works/pi-codemode/dist/portable.js +1 -0
- package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/execution.d.ts +29 -0
- package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/execution.js +1 -0
- package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/host.d.ts +3 -16
- package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/host.js +1 -1
- package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/inline.d.ts +13 -0
- package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/inline.js +1 -0
- package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/prelude-source.js +14 -6
- package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/protocol.d.ts +72 -0
- package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/protocol.js +1 -1
- package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/remote.d.ts +32 -0
- package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/remote.js +1 -0
- package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/vm.js +3 -0
- package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/worker.js +1 -3
- package/dist/node_modules/@earendil-works/pi-codemode/dist/source.js +4 -3
- package/dist/node_modules/@earendil-works/pi-codemode/dist/types.d.ts +51 -1
- package/dist/node_modules/@earendil-works/pi-codemode/package.json +14 -2
- package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/CHANGELOG.md +13 -0
- package/dist/node_modules/@earendil-works/pi-mcp/dist/client.js +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/index.d.ts +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/errors.d.ts +2 -2
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/errors.js +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/flow.js +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/protocol/content.d.ts +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/streamable-http.d.ts +2 -2
- package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/streamable-http.js +4 -4
- package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/transport.d.ts +4 -1
- package/dist/node_modules/@earendil-works/pi-mcp/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/README.md +5 -3
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/editor.js +6 -6
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.js +2 -2
- package/dist/node_modules/@earendil-works/pi-tui/dist/index.d.ts +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/index.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/keys.js +5 -5
- package/dist/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/terminal-image.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js +3 -3
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-main-screen.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +4 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui.js +2 -2
- package/dist/node_modules/@earendil-works/pi-tui/dist/utils.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/dist/sdk/index.d.ts +3 -3
- package/dist/sdk/index.js +1 -1
- package/dist/sdk/rewind.d.ts +1 -1
- package/dist/sdk/rewind.js +1 -1
- package/dist/utils/clipboard.js +1 -1
- package/dist/utils/output-files.js +1 -1
- package/dist/utils/temp-files.js +1 -0
- package/docs/security.md +24 -7
- package/examples/README.md +0 -3
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/dynamic-resources/dynamic.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/minimal-mode.ts +4 -5
- package/examples/extensions/overlay-test.ts +2 -2
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/subagent/index.ts +4 -6
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +9 -460
- package/package.json +3 -12
- package/dist/modes/interactive/theme/theme-json.d.ts +0 -75
- package/dist/modes/interactive/theme/theme-json.js +0 -12
- package/dist/modes/interactive/theme/theme-schema.json +0 -361
- package/dist/node_modules/@earendil-works/chord/README.md +0 -264
- package/dist/node_modules/@earendil-works/chord/dist/api.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/bundler.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/context/index.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/delta/apply-immutable-trusted.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/delta/diff.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/delta/draft.js +0 -0
- package/dist/node_modules/@earendil-works/chord/dist/delta/index.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/delta/revision-validator.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/delta/tracker.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/facets/host.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/facets/loader.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/index.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/json.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/node/bundle-loader.js +0 -2
- package/dist/node_modules/@earendil-works/chord/dist/node/bundle.js +0 -4
- package/dist/node_modules/@earendil-works/chord/dist/node/manifest.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/node/package.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/node.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/services/consumer.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/services/errors.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/services/handle.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/services/instances.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/services/loopback.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/services/provider.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/services/state-codec.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/services/state-internals.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/services/state.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/services/wire.js +0 -1
- package/dist/node_modules/@earendil-works/chord/dist/types.js +0 -0
- package/dist/node_modules/@earendil-works/chord/package.json +0 -62
- package/dist/node_modules/@earendil-works/chord/src/delta/README.md +0 -191
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/assistant-message-frame.d.ts +0 -63
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/assistant-message-frame.js +0 -1
- package/dist/node_modules/@earendil-works/pi-client/CHANGELOG.md +0 -45
- package/dist/node_modules/@earendil-works/pi-client/LICENSE +0 -21
- package/dist/node_modules/@earendil-works/pi-client/README.md +0 -72
- package/dist/node_modules/@earendil-works/pi-client/dist/client.js +0 -1
- package/dist/node_modules/@earendil-works/pi-client/dist/connection.js +0 -1
- package/dist/node_modules/@earendil-works/pi-client/dist/errors.js +0 -1
- package/dist/node_modules/@earendil-works/pi-client/dist/index.js +0 -1
- package/dist/node_modules/@earendil-works/pi-client/dist/promise.js +0 -1
- package/dist/node_modules/@earendil-works/pi-client/dist/transport.js +0 -0
- package/dist/node_modules/@earendil-works/pi-client/dist/types.js +0 -0
- package/dist/node_modules/@earendil-works/pi-client/dist/unix.js +0 -1
- package/dist/node_modules/@earendil-works/pi-client/package.json +0 -46
- package/dist/node_modules/@earendil-works/pi-protocol/LICENSE +0 -21
- package/dist/node_modules/@earendil-works/pi-protocol/README.md +0 -41
- package/dist/node_modules/@earendil-works/pi-protocol/dist/cbor/decoder.js +0 -1
- package/dist/node_modules/@earendil-works/pi-protocol/dist/cbor/encoder.js +0 -1
- package/dist/node_modules/@earendil-works/pi-protocol/dist/cbor/index.js +0 -1
- package/dist/node_modules/@earendil-works/pi-protocol/dist/cbor/options.js +0 -1
- package/dist/node_modules/@earendil-works/pi-protocol/dist/codec.js +0 -1
- package/dist/node_modules/@earendil-works/pi-protocol/dist/framing.js +0 -1
- package/dist/node_modules/@earendil-works/pi-protocol/dist/index.js +0 -1
- package/dist/node_modules/@earendil-works/pi-protocol/dist/protocol.js +0 -1
- package/dist/node_modules/@earendil-works/pi-protocol/dist/schemas.js +0 -1
- package/dist/node_modules/@earendil-works/pi-protocol/package.json +0 -39
- package/dist/node_modules/@earendil-works/pi-server/CHANGELOG.md +0 -81
- package/dist/node_modules/@earendil-works/pi-server/LICENSE +0 -21
- package/dist/node_modules/@earendil-works/pi-server/README.md +0 -63
- package/dist/node_modules/@earendil-works/pi-server/dist/connection.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/errors.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/index.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/listener.js +0 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/server.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/session-router.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/client.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/host.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/index.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/server.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/address.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/index.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/listener.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/preset.js +0 -1
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/types.js +0 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/types.js +0 -0
- package/dist/node_modules/@earendil-works/pi-server/package.json +0 -45
- package/examples/plugins/pi-example-plugin/README.md +0 -38
- package/examples/plugins/pi-example-plugin/package.json +0 -10
- package/examples/plugins/pi-example-plugin/src/contract.ts +0 -13
- package/examples/plugins/pi-example-plugin/src/session.ts +0 -24
- package/examples/plugins/pi-example-plugin/src/tui.ts +0 -31
- /package/dist/node_modules/{@earendil-works/chord → @dalcode/dal-codeindex}/LICENSE +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var o=Object.defineProperty;var c=(e,t)=>o(e,"name",{value:t,configurable:!0});import{APP_NAME as a,CONFIG_DIR_NAME as i}from"../config.js";import{emitProjectTrustEvent as f}from"./extensions/runner.js";import{SETTINGS_DEFAULTS as l}from"./settings-defaults.js";import{getProjectTrustOptions as d,hasTrustRequiringProjectResources as j}from"./trust-manager.js";function T(e){return`Trust project folder?
|
|
2
2
|
${e}
|
|
3
3
|
|
|
4
|
-
This allows ${
|
|
4
|
+
This allows ${a} to load ${i} settings and resources, install missing project packages, and execute project extensions.`}c(T,"formatProjectTrustPrompt");async function m(e,t){const r=d(e,{includeSessionOnly:!0}),s=await t.ui.select(T(e),r.map(u=>u.label));return r.find(u=>u.label===s)}c(m,"selectProjectTrustOption");function P(e,t){t.updates.length>0&&e.setMany(t.updates)}c(P,"saveProjectTrustPromptResult");async function y(e){if(e.trustOverride!==void 0)return e.trustOverride;if(!j(e.cwd))return!0;if(e.extensionsResult){const{result:s,errors:u}=await f(e.extensionsResult,{type:"project_trust",cwd:e.cwd},e.projectTrustContext);for(const n of u)e.onExtensionError?.(`Extension "${n.extensionPath}" project_trust error: ${n.error}`);if(s){const n=s.trusted==="yes";return s.remember===!0&&e.trustStore.set(e.cwd,n),n}}const t=e.trustStore.get(e.cwd);if(t!==null)return t;switch(e.defaultProjectTrust??l.defaultProjectTrust){case"always":return!0;case"never":return!1;case"ask":break}if(!e.projectTrustContext.hasUI)return!1;const r=await m(e.cwd,e.projectTrustContext);return r!==void 0?(P(e.trustStore,r),r.trusted):!1}c(y,"resolveProjectTrusted");export{y as resolveProjectTrusted};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
`).find(c=>c.trim());l&&(m=l.slice(0,60),l.length>60&&(m+="..."))}const p=typeof
|
|
1
|
+
var j=Object.defineProperty;var f=(t,o)=>j(t,"name",{value:o,configurable:!0});import{existsSync as A,readdirSync as N,readFileSync as R,statSync as y}from"fs";import{basename as T,dirname as $,join as b,resolve as w,sep as E}from"path";import{CONFIG_DIR_NAME as G,getProjectPromptsDir as M}from"../config.js";import{parseFrontmatter as U}from"../utils/frontmatter.js";import{resolvePath as D}from"../utils/paths.js";import{createSyntheticSourceInfo as S}from"./source-info.js";function W(t){const o=[];let e="",i=!1,n=null;for(let s=0;s<t.length;s++){const r=t[s];n?r===n?n=null:e+=r:r==='"'||r==="'"?(n=r,i=!0):/\s/.test(r)?i&&(o.push(e),e="",i=!1):(e+=r,i=!0)}return i&&o.push(e),o}f(W,"parseCommandArgs");function x(t,o){const e=o.join(" ");return t.replace(/\$\{(\d+|ARGUMENTS|@):-([^}]*)\}|\$\{@:(\d+)(?::(\d+))?\}|\$(ARGUMENTS|@|\d+)/g,(i,n,s,r,m,p)=>{if(n){const c=n==="@"||n==="ARGUMENTS"?e:o[parseInt(n,10)-1];return c||s}if(r){let c=parseInt(r,10)-1;if(c<0&&(c=0),m){const g=parseInt(m,10);return o.slice(c,c+g).join(" ")}return o.slice(c).join(" ")}if(p==="ARGUMENTS"||p==="@")return e;const l=parseInt(p,10)-1;return o[l]??""})}f(x,"substituteArgs");function I(t,o){const e=[];let i;try{i=R(t,"utf-8")}catch(l){const c=l instanceof Error?l.message:"failed to read prompt template file";return e.push({type:"warning",message:c,path:t}),{template:null,diagnostics:e}}let n,s;try{({frontmatter:n,body:s}=U(i))}catch(l){const c=l instanceof Error?l.message:"failed to parse prompt template file";return e.push({type:"warning",message:c,path:t}),{template:null,diagnostics:e}}const r=T(t).replace(/\.md$/,"");let m=typeof n.description=="string"?n.description:"";if(!m){const l=s.split(`
|
|
2
|
+
`).find(c=>c.trim());l&&(m=l.slice(0,60),l.length>60&&(m+="..."))}const p=typeof n["argument-hint"]=="string"?n["argument-hint"]:void 0;return{template:{name:r,description:m,...p&&{argumentHint:p},content:s,sourceInfo:o,filePath:t},diagnostics:e}}f(I,"loadTemplateFromFile");function F(t,o){const e=[],i=[];if(!A(t))return{templates:e,diagnostics:i};try{const n=N(t,{withFileTypes:!0});for(const s of n){const r=b(t,s.name);let m=s.isFile();if(s.isSymbolicLink())try{m=y(r).isFile()}catch{continue}if(m&&s.name.endsWith(".md")){const p=I(r,o(r));p.template&&e.push(p.template),i.push(...p.diagnostics)}}}catch{return{templates:e,diagnostics:i}}return{templates:e,diagnostics:i}}f(F,"loadTemplatesFromDir");function O(t){const o=D(t.cwd),e=D(t.agentDir),i=t.promptPaths,n=t.includeDefaults,s=[],r=[],m=f(a=>{s.push(...a.templates),r.push(...a.diagnostics)},"addResult"),p=b(e,"prompts"),l=M(w(o,G)),c=f((a,d)=>{const u=w(d);if(a===u)return!0;const h=u.endsWith(E)?u:`${u}${E}`;return a.startsWith(h)},"isUnderPath"),g=f(a=>c(a,p)?S(a,{source:"local",scope:"user",baseDir:p}):c(a,l)?S(a,{source:"local",scope:"project",baseDir:l}):S(a,{source:"local",baseDir:y(a).isDirectory()?a:$(a)}),"getSourceInfo");n&&(m(F(p,g)),m(F(l,g)));for(const a of i){const d=D(a,o,{trim:!0});if(A(d))try{const u=y(d);if(u.isDirectory())m(F(d,g));else if(u.isFile()&&d.endsWith(".md")){const h=I(d,g(d));h.template&&s.push(h.template),r.push(...h.diagnostics)}}catch(u){const h=u instanceof Error?u.message:"failed to read prompt template path";r.push({type:"warning",message:h,path:d})}}return{templates:s,diagnostics:r}}f(O,"loadPromptTemplates");function Q(t,o){if(!t.startsWith("/"))return t;const e=t.match(/^\/([^\s]+)(?:\s+([\s\S]*))?$/);if(!e)return t;const i=e[1],n=e[2]??"",s=o.find(r=>r.name===i);if(s){const r=W(n);return x(s.content,r)}return t}f(Q,"expandPromptTemplate");export{Q as expandPromptTemplate,O as loadPromptTemplates,W as parseCommandArgs,x as substituteArgs};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var T=Object.defineProperty;var
|
|
1
|
+
var T=Object.defineProperty;var i=(e,t)=>T(e,"name",{value:t,configurable:!0});import{getModelType as y,isModelType as M}from"@earendil-works/pi-ai";import{APP_NAME as _,VERSION as R}from"../config.js";import{fetchWithRetry as C}from"../utils/management-http.js";import{getPiUserAgent as O}from"../utils/pi-user-agent.js";const N="https://pi.dev",k=4e3,L=14400*1e3,m=["chat","image","classifier"];function P(e){return e.type===void 0||typeof e.type=="string"&&m.includes(e.type)}i(P,"isSupportedModelType");function g(e,t){const r=new Map;for(const o of[...e,...t])r.set(`${y(o)}\0${o.id}`,o);return[...r.values()]}i(g,"mergeModels");function S(e,t){const r=Array.isArray(t)?t:typeof t=="object"&&t!==null&&"models"in t&&Array.isArray(t.models)?t.models:typeof t=="object"&&t!==null?Object.values(t):void 0;if(!r)throw new Error(`Invalid model catalog for provider "${e}"`);return r.filter(o=>typeof o=="object"&&o!==null&&"id"in o).filter(P).map(o=>({...o,provider:e}))}i(S,"parseCatalog");async function h(e,t){const r=Date.parse(t.headers.get("last-modified")??"");return{models:S(e,await t.json()),lastModified:Number.isNaN(r)?0:r,etag:t.headers.get("etag")??void 0}}i(h,"readCatalog");function w(e,t){return t===void 0||e!==void 0&&e>t}i(w,"isNewer");function A(e,t){return e&&w(e.lastModified,t)?e.models:[]}i(A,"remoteModels");function b(e,t,r,o){const s=new URL(`/api/models/providers/${encodeURIComponent(e)}`,t);return s.searchParams.set("types",m.join(",")),C(s,{headers:{accept:"application/json","User-Agent":O(R),...o?{"if-none-match":o}:{}},signal:r},{attemptTimeoutMs:k})}i(b,"requestCatalog");function q(e=_){return e==="pi"?N:void 0}i(q,"getDefaultCatalogBaseUrl");function z(e,t,r){let o=[];return{...e,getModels:i(()=>g(e.getModels(),o.filter(s=>M(s,"chat"))),"getModels"),getAllModels:i(()=>g(e.getAllModels?.()??e.getModels(),o),"getAllModels"),refreshModels:i(async s=>{const a=s.stored,u=A(a,r).filter(E=>E.provider===e.id);if(!await s.publish({update:i(()=>{o=u},"update")})||!s.allowNetwork||s.signal.aborted||!s.force&&a?.checkedAt!==void 0&&a.lastModified!==void 0&&Date.now()-a.checkedAt<L)return;const n=a&&a.models.length>0?a.etag:void 0,l=await b(e.id,t,s.signal,n);if(s.signal.aborted)return;const f=Date.now();if(l.status===304&&a){await s.publish({persist:{...a,checkedAt:f}});return}if(l.status===404||l.status===501){await s.publish({persist:{...a??{models:[]},checkedAt:f,lastModified:0,etag:void 0}});return}if(!l.ok)throw await s.publish({persist:{...a??{models:[]},checkedAt:f}}),new Error(`Model catalog request failed for ${e.id}: ${l.status}`);const c=await h(e.id,l);if(s.signal.aborted)return;const d={...c,checkedAt:f},p=A(d,r);await s.publish({persist:d,update:i(()=>{o=p},"update")})},"refreshModels")}}i(z,"withRemoteCatalog");function G(e,t,r,o){let s=[];const a=i(()=>e.getAllModels?.()??e.getModels(),"builtinModels"),u=i(()=>s.length>0?s:a(),"getAllModels");return{...e,getModels:i(()=>u().filter(n=>M(n,"chat")),"getModels"),getAllModels:u,refreshModels:i(async n=>{const l=(n.stored?.models??[]).filter(d=>d.provider===e.id);if(!await n.publish({update:i(()=>{s=l},"update")})||!n.allowNetwork||n.signal.aborted)return;let f=[];if(r!==void 0){const d=await b(e.id,r,n.signal);if(n.signal.aborted)return;if(d.status!==404&&d.status!==501){if(!d.ok)throw new Error(`Model catalog request failed for ${e.id}: ${d.status}`);const p=await h(e.id,d);w(p.lastModified,o)&&(f=p.models)}}const c=await t(g(a(),f),n);n.signal.aborted||await n.publish({persist:{models:c,checkedAt:Date.now()},update:i(()=>{s=c},"update")})},"refreshModels")}}i(G,"withPersonalizedCatalog");export{m as REMOTE_CATALOG_MODEL_TYPES,L as REMOTE_CATALOG_REFRESH_INTERVAL_MS,q as getDefaultCatalogBaseUrl,G as withPersonalizedCatalog,z as withRemoteCatalog};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var lt=Object.defineProperty;var P=(c,t)=>lt(c,"name",{value:t,configurable:!0});import{existsSync as f,readdirSync as ct,readFileSync as $,statSync as T}from"node:fs";import{basename as mt,dirname as Q,join as p,resolve as y,sep as b}from"node:path";import{detectCapabilities as pt,getTerminalColorMode as dt}from"@earendil-works/pi-tui";import V from"chalk";import{APP_NAME as ut,CONFIG_DIR_NAME as v,getExamplesPath as ft,getPackageDir as Pt}from"../config.js";import{dalBuiltinExtensionPaths as gt}from"../dal/builtins.js";import{applyCommunityEnv as xt,hostDependenciesOf as Z,installedHostCopies as St,isAdaptablePackage as yt,tryEnsurePackageAdapted as wt}from"../dal/extension-compat.js";import{fill as A,t as S}from"../dal/i18n.js";import{loadThemeFromPath as vt}from"../modes/interactive/theme/theme.js";import{canonicalizePath as M,isLocalPath as j,resolvePath as w}from"../utils/paths.js";import{stripBom as W}from"../utils/text.js";import{createEventBus as kt}from"./event-bus.js";import{clearExtensionCache as Et,createExtensionRuntime as Dt,loadExtensionFromFactory as tt,loadExtensionsCached as et}from"./extensions/loader.js";import{findGitPaths as Ft}from"./footer-data-provider.js";import{DefaultPackageManager as Tt}from"./package-manager.js";import{loadPromptTemplates as bt}from"./prompt-templates.js";import{SettingsManager as Mt}from"./settings-manager.js";import{loadSkills as It}from"./skills.js";import{BUILTIN_PATH_PREFIX as k,createSourceInfo as I,getSyntheticPathSource as Ot,isSyntheticPath as N}from"./source-info.js";import{resetTimings as Rt}from"./timings.js";function st(c,t,n){let s;try{s=Pt()}catch{s=void 0}xt({agentDir:n.agentDir,packageDir:s});const i=[],e=new Map;for(const o of c){const a=t.get(o);a?.packageRoot&&!e.has(a.packageRoot)&&e.set(a.packageRoot,a)}for(const[o,a]of e){const l=p(o,"package.json");if(!f(l))continue;JSON.parse(W($(l,"utf-8"))),yt(o,a.source,n)&&wt(o);const h=St(o,Z(o));if(h.length===0)continue;const g=Z(o).filter(x=>h.some(d=>d.endsWith(p(...x.split("/")))));i.push({path:l,warning:A(S('\u6269\u5C55\u5305\u5728 dependencies \u91CC\u81EA\u5E26\u4E86 DAL \u5DF2\u63D0\u4F9B\u7684\u5E93\uFF08{names}\uFF09\uFF0C\u8FD9\u4E9B\u526F\u672C\u4F1A\u548C DAL \u81EA\u5DF1\u7684\u91CD\u590D\u52A0\u8F7D\u3002\u8BF7\u628A\u5B83\u4EEC\u6539\u5230 peerDependencies\uFF0C\u7248\u672C\u5199 "*"\u3002'),{names:g.join(", ")})})}return i}P(st,"prepareExtensionPackages");function B(c,t){c.warnings=[...new Map([...c.warnings??[],...t].map(n=>[n.path,n])).values()]}P(B,"mergeExtensionWarnings");function it(c){return typeof c!="function"&&c.builtin===!0}P(it,"isBuiltinExtension");let nt;function Ct(c){return nt??=new Set(gt().map(t=>y(t))),nt.has(y(c))}P(Ct,"isDalBundledExtensionPath");function ot(c,t){const n=P(i=>[...[...i.tools.keys()].map(e=>`tool:${e}`),...[...i.commands.keys()].map(e=>`command:${e}`),...[...i.flags.keys()].map(e=>`flag:${e}`)],"names"),s=new Map(c.filter(i=>!i.replaceable).flatMap(i=>n(i).map(e=>[e,i])));return c.filter(i=>{if(!i.replaceable)return!0;const e=n(i).map(o=>({name:o,extension:s.get(o)})).find(o=>o.extension!==void 0);if(!e)return!0;if(i.path.startsWith(k)&&!Ct(e.extension.path)){const o=i.path.slice(k.length),[a,l]=e.name.split(":",2),h=a==="command"?`/${l}`:a==="flag"?`--${l}`:l;t?.push({path:i.path,warning:A(S("\u6269\u5C55 {path} \u6CE8\u518C\u4E86{kind} `{name}`\uFF0C\u6240\u4EE5\u5185\u7F6E\u6269\u5C55 `{builtin}` \u6CA1\u6709\u52A0\u8F7D\u3002\u8981\u4F7F\u7528 `{builtin}`\uFF0C\u8FD0\u884C `{app} config`\uFF0C\u5728\u5185\u7F6E\u6269\u5C55\u91CC\u786E\u8BA4\u5B83\u5DF2\u542F\u7528\uFF0C\u7136\u540E\u505C\u7528\u6216\u79FB\u9664\u8FD9\u4E2A\u6269\u5C55\u3002\u4E24\u8005\u6700\u597D\u53EA\u4FDD\u7559\u4E00\u4E2A\u3002"),{path:e.extension.path,kind:a==="command"?S("\u4E00\u4E2A\u547D\u4EE4"):a==="flag"?S("\u4E00\u4E2A\u53C2\u6570"):S("\u4E00\u4E2A\u5DE5\u5177"),name:h,builtin:o,app:ut})})}return!1})}P(ot,"omitReplacedExtensions");function at(c,t){if(c){if(f(c))try{return W($(c,"utf-8"))}catch(n){return console.error(V.yellow(A(S("\u8B66\u544A\uFF1A\u65E0\u6CD5\u8BFB\u53D6{what}\u6587\u4EF6 {path}\uFF1A{error}"),{what:t,path:c,error:String(n)}))),c}return c}}P(at,"resolvePromptInput");function L(c){const t=["AGENTS.override.md","AGENTS.md","AGENTS.MD","CLAUDE.md","CLAUDE.MD"];for(const n of t){const s=p(c,n);if(f(s))try{if(!T(s).isFile())continue;return{path:s,content:W($(s,"utf-8"))}}catch(i){console.error(V.yellow(A(S("\u8B66\u544A\uFF1A\u65E0\u6CD5\u8BFB\u53D6 {path}\uFF1A{error}"),{path:s,error:String(i)})))}}return null}P(L,"loadContextFileFromDir");function At(c){const t=Ft(c);if(!t)return;const n=M(t.commonGitDir),s=M(t.repoDir),i=Q(n);if(!s.startsWith(`${i}${b}`)||M(p(i,".git"))!==n)return;const e=L(s);return e?p(i,mt(e.path)):void 0}P(At,"findShadowedContextFile");function Bt(c){const t=w(c.cwd),n=w(c.agentDir),s=[],i=new Set,e=L(n);e&&(s.push(e),i.add(e.path));const o=[],a=At(t);let l=t;for(;;){const h=L(l),g=a!==void 0&&M(h?.path??"")===a;h&&!g&&!i.has(h.path)&&(o.unshift(h),i.add(h.path));const x=Q(l);if(x===l)break;l=x}return s.push(...o),s}P(Bt,"loadProjectContextFiles");class ie{static{P(this,"DefaultResourceLoader")}cwd;agentDir;settingsManager;eventBus;packageManager;additionalExtensionPaths;additionalSkillPaths;additionalPromptTemplatePaths;additionalThemePaths;extensionFactories;builtinExtensions;noExtensions;disabledBuiltinExtensions;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=w(t.cwd),this.agentDir=w(t.agentDir),this.settingsManager=t.settingsManager??Mt.create(this.cwd,this.agentDir),this.eventBus=t.eventBus??kt();const n=t.extensionFactories??[];this.extensionFactories=n.filter(s=>!it(s)),this.builtinExtensions=new Map(n.filter(it).map(s=>[s.name,s])),this.packageManager=new Tt({cwd:this.cwd,agentDir:this.agentDir,settingsManager:this.settingsManager,builtinExtensions:[...this.builtinExtensions.keys()]}),this.additionalExtensionPaths=t.additionalExtensionPaths??[],this.additionalSkillPaths=t.additionalSkillPaths??[],this.additionalPromptTemplatePaths=t.additionalPromptTemplatePaths??[],this.additionalThemePaths=t.additionalThemePaths??[],this.noExtensions=t.noExtensions??!1,this.disabledBuiltinExtensions=new Set(t.disabledBuiltinExtensions),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:Dt()},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 n=this.normalizeExtensionPaths(t.skillPaths??[]),s=this.normalizeExtensionPaths(t.promptPaths??[]),i=this.normalizeExtensionPaths(t.themePaths??[]);for(const e of n)this.extensionSkillSourceInfos.set(e.path,I(e.path,e.metadata));for(const e of s)this.extensionPromptSourceInfos.set(e.path,I(e.path,e.metadata));for(const e of i)this.extensionThemeSourceInfos.set(e.path,I(e.path,e.metadata));n.length>0&&(this.lastSkillPaths=this.mergePaths(this.lastSkillPaths,n.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){Rt("extensions"),this.loaded&&Et();let n;if(t?.resolveProjectTrust){n=await this.loadProjectTrustExtensions();const r=await t.resolveProjectTrust({extensionsResult:n});this.settingsManager.setProjectTrusted(r)}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 o=P(r=>{for(const m of r)e.has(m.path)||e.set(m.path,m.metadata);return r.filter(m=>m.enabled)},"getEnabledResources"),a=P(r=>o(r).map(m=>m.path),"getEnabledPaths"),l=a(s.extensions),h=o(s.skills),g=a(s.prompts),x=a(s.themes),d=h.map(r=>this.mapSkillPath(r,e));for(const r of i.extensions)e.has(r.path)||e.set(r.path,{source:"cli",scope:"temporary",origin:"top-level"});for(const r of i.skills)e.has(r.path)||e.set(r.path,{source:"cli",scope:"temporary",origin:"top-level"});const u=a(i.extensions),E=a(i.skills),z=a(i.prompts),U=a(i.themes),G=(this.noExtensions?u:this.mergePaths(u,l)).filter(r=>!r.startsWith(k)||!this.disabledBuiltinExtensions.has(r.slice(k.length))),rt=st(G,e,{agentDir:this.agentDir,cwd:this.cwd}),O=await this.loadFinalExtensionSet(G,n);B(O,rt);for(const r of this.additionalExtensionPaths)if(j(r)){const m=this.resolveResourcePath(r);f(m)||O.errors.push({path:m,error:`Extension path does not exist: ${m}`})}this.extensionsResult=this.extensionsOverride?this.extensionsOverride(O):O,this.applyExtensionSourceInfo(this.extensionsResult.extensions,e);const D=p(ft(),"skills"),_=!this.noSkills&&f(D)?[D]:[];_.length>0&&!e.has(D)&&e.set(D,{source:"auto",scope:"user",origin:"top-level",baseDir:D});const Y=this.noSkills?this.mergePaths(E,this.additionalSkillPaths):this.mergePaths([...E,...d,..._],this.additionalSkillPaths);this.lastSkillPaths=Y,this.updateSkillsFromPaths(Y,e);for(const r of this.additionalSkillPaths)if(j(r)){const m=this.resolveResourcePath(r);!f(m)&&!this.skillDiagnostics.some(F=>F.path===m)&&this.skillDiagnostics.push({type:"error",message:"Skill path does not exist",path:m})}const H=this.noPromptTemplates?this.mergePaths(z,this.additionalPromptTemplatePaths):this.mergePaths([...z,...g],this.additionalPromptTemplatePaths);this.lastPromptPaths=H,this.updatePromptsFromPaths(H,e);for(const r of this.additionalPromptTemplatePaths)if(j(r)){const m=this.resolveResourcePath(r);!f(m)&&!this.promptDiagnostics.some(F=>F.path===m)&&this.promptDiagnostics.push({type:"error",message:"Prompt template path does not exist",path:m})}const J=this.noThemes?this.mergePaths(U,this.additionalThemePaths):this.mergePaths([...U,...x],this.additionalThemePaths);this.lastThemePaths=J,this.updateThemesFromPaths(J,e);for(const r of this.additionalThemePaths){const m=this.resolveResourcePath(r);!f(m)&&!this.themeDiagnostics.some(F=>F.path===m)&&this.themeDiagnostics.push({type:"error",message:"Theme path does not exist",path:m})}const K={agentsFiles:this.noContextFiles?[]:Bt({cwd:this.cwd,agentDir:this.agentDir})},ht=this.agentsFilesOverride?this.agentsFilesOverride(K):K;this.agentsFiles=ht.agentsFiles;const R=this.systemPromptSource??this.discoverSystemPromptFile(),X=at(R,S("\u7CFB\u7EDF\u63D0\u793A\u8BCD"));this.systemPrompt=this.systemPromptOverride?this.systemPromptOverride(X):X,this.systemPromptSourcePath=R&&f(R)?w(R):void 0;let C=this.appendSystemPromptSource;if(!C){const r=this.discoverAppendSystemPromptFile();C=r?[r]:[]}const q=C.map(r=>at(r,S("\u8FFD\u52A0\u7684\u7CFB\u7EDF\u63D0\u793A\u8BCD"))).filter(r=>r!==void 0);this.appendSystemPrompt=this.appendSystemPromptOverride?this.appendSystemPromptOverride(q):q,this.appendSystemPromptSourcePaths=C.filter(r=>f(r)).map(r=>w(r)),this.loaded=!0}async loadCurrentExtensionSet(t){const n=await this.packageManager.resolve(),s=await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths,{temporary:!0}),i=n.extensions.filter(d=>d.enabled).map(d=>d.path),e=s.extensions.filter(d=>d.enabled).map(d=>d.path),o=(this.noExtensions?e:this.mergePaths(e,i)).filter(d=>!d.startsWith(k)),a=new Map([...n.extensions,...s.extensions].map(d=>[d.path,d.metadata])),l=st(o,a,{agentDir:this.agentDir,cwd:this.cwd}),h=await et(o,this.cwd,this.eventBus);if(B(h,l),!t.includeInlineFactories)return h;const g=await this.loadExtensionFactories(h.runtime);h.extensions.push(...g.extensions),h.errors.push(...g.errors);const x=[];return h.extensions=ot(h.extensions,x),B(h,x),h}resolveExtensionLoadPath(t){return N(t)?t:w(t,this.cwd,{normalizeUnicodeSpaces:!0})}async loadExtensionPaths(t,n){const s=P(e=>e.startsWith(k),"isBuiltinPath"),i=await et(t.filter(e=>!s(e)),this.cwd,this.eventBus,n);for(const e of t.filter(s)){const o=this.builtinExtensions.get(e.slice(k.length));if(!o){i.errors.push({path:e,error:`Unknown built-in extension: ${e}`});continue}try{const a=await tt(o.factory,this.cwd,this.eventBus,i.runtime,e);a.hidden=!0,a.replaceable=o.replaceable===!0,i.extensions.push(a)}catch(a){i.errors.push({path:e,error:a instanceof Error?a.message:"failed to load extension"})}}return i}async loadFinalExtensionSet(t,n){const s=n?.extensions??[],i=new Map(s.filter(u=>!u.path.startsWith("<inline:")).map(u=>[u.resolvedPath,u])),e=new Set((n?.errors??[]).map(u=>this.resolveExtensionLoadPath(u.path))),o=t.filter(u=>{const E=this.resolveExtensionLoadPath(u);return!i.has(E)&&!e.has(E)}),a=await this.loadExtensionPaths(o,n?.runtime),l=new Map(i);for(const u of a.extensions)l.set(u.resolvedPath,u);const h=n?{extensions:s.filter(u=>u.path.startsWith("<inline:")),errors:[]}:await this.loadExtensionFactories(a.runtime),g=t.map(u=>l.get(this.resolveExtensionLoadPath(u))).filter(u=>u!==void 0);g.push(...h.extensions);const x=[],d={extensions:ot(g,x),errors:[...n?.errors??[],...a.errors,...h.errors],warnings:[...n?.warnings??[],...a.warnings??[]],runtime:a.runtime};return B(d,x),this.addExtensionConflictDiagnostics(d),d}addExtensionConflictDiagnostics(t){const n=this.detectExtensionConflicts(t.extensions);for(const s of n)t.errors.push({path:s.path,error:s.message})}mapSkillPath(t,n){if(t.metadata.source!=="auto"&&t.metadata.origin!=="package")return t.path;try{if(!T(t.path).isDirectory())return t.path}catch{return t.path}const s=p(t.path,"SKILL.md");return f(s)?(n.has(s)||n.set(s,t.metadata),s):t.path}normalizeExtensionPaths(t){return t.map(n=>{const s=n.metadata.baseDir?{...n.metadata,baseDir:this.resolveResourcePath(n.metadata.baseDir)}:n.metadata;return{path:this.resolveResourcePath(n.path),metadata:s}})}updateSkillsFromPaths(t,n){let s;this.noSkills&&t.length===0?s={skills:[],diagnostics:[]}:s=It({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,n)??e.sourceInfo??this.getDefaultSourceInfoForPath(e.filePath)})),this.skillDiagnostics=i.diagnostics}updatePromptsFromPaths(t,n){let s;if(this.noPromptTemplates&&t.length===0)s={prompts:[],diagnostics:[]};else{const e=bt({cwd:this.cwd,agentDir:this.agentDir,promptPaths:t,includeDefaults:!1}),o=this.dedupePrompts(e.templates);s={prompts:o.prompts,diagnostics:[...e.diagnostics,...o.diagnostics]}}const i=this.promptsOverride?this.promptsOverride(s):s;this.prompts=i.prompts.map(e=>({...e,sourceInfo:this.findSourceInfoForPath(e.filePath,this.extensionPromptSourceInfos,n)??e.sourceInfo??this.getDefaultSourceInfoForPath(e.filePath)})),this.promptDiagnostics=i.diagnostics}updateThemesFromPaths(t,n){let s;if(this.noThemes&&t.length===0)s={themes:[],diagnostics:[]};else{const e=dt({...pt(()=>!1),...this.settingsManager.getTerminalCapabilityOverrides()}),o=this.loadThemes(t,!1,e),a=this.dedupeThemes(o.themes);s={themes:a.themes,diagnostics:[...o.diagnostics,...a.diagnostics]}}const i=this.themesOverride?this.themesOverride(s):s;this.themes=i.themes.map(e=>{const o=e.sourcePath;return e.sourceInfo=o?this.findSourceInfoForPath(o,this.extensionThemeSourceInfos,n)??e.sourceInfo??this.getDefaultSourceInfoForPath(o):e.sourceInfo,e}),this.themeDiagnostics=i.diagnostics}applyExtensionSourceInfo(t,n){for(const s of t){s.sourceInfo=this.findSourceInfoForPath(s.path,void 0,n)??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,n,s){if(!t)return;if(N(t))return this.getDefaultSourceInfoForPath(t);const i=y(t);if(n)for(const[e,o]of n.entries()){const a=y(e);if(i===a||i.startsWith(`${a}${b}`))return{...o,path:t}}if(s){const e=s.get(i)??s.get(t);if(e)return I(t,e);for(const[o,a]of s.entries()){const l=y(o);if(i===l||i.startsWith(`${l}${b}`))return I(t,a)}}}getDefaultSourceInfoForPath(t){const n=Ot(t);if(n)return{path:t,source:n,scope:"temporary",origin:"top-level"};const s=y(t),i=[p(this.agentDir,"skills"),p(this.agentDir,"prompts"),p(this.agentDir,"themes"),p(this.agentDir,"extensions")],e=[p(this.cwd,v,"skills"),p(this.cwd,v,"prompts"),p(this.cwd,v,"themes"),p(this.cwd,v,"extensions")];for(const o of i)if(this.isUnderPath(s,o))return{path:t,source:"local",scope:"user",origin:"top-level",baseDir:o};for(const o of e)if(this.isUnderPath(s,o))return{path:t,source:"local",scope:"project",origin:"top-level",baseDir:o};return{path:t,source:"local",scope:"temporary",origin:"top-level",baseDir:T(s).isDirectory()?s:y(s,"..")}}mergePaths(t,n){const s=[],i=new Set;for(const e of[...t,...n]){const o=this.resolveResourcePath(e),a=M(o);i.has(a)||(i.add(a),s.push(o))}return s}resolveResourcePath(t){return N(t)?t:w(t,this.cwd,{trim:!0})}loadThemes(t,n,s){const i=[],e=[];if(n){const o=[p(this.agentDir,"themes"),p(this.cwd,v,"themes")];for(const a of o)this.loadThemesFromDir(a,i,e,s)}for(const o of t){const a=this.resolveResourcePath(o);if(!f(a)){e.push({type:"warning",message:"theme path does not exist",path:a});continue}try{const l=T(a);l.isDirectory()?this.loadThemesFromDir(a,i,e,s):l.isFile()&&a.endsWith(".json")?this.loadThemeFromFile(a,i,e,s):e.push({type:"warning",message:"theme path is not a json file",path:a})}catch(l){const h=l instanceof Error?l.message:"failed to read theme path";e.push({type:"warning",message:h,path:a})}}return{themes:i,diagnostics:e}}loadThemesFromDir(t,n,s,i){if(f(t))try{const e=ct(t,{withFileTypes:!0});for(const o of e){let a=o.isFile();if(o.isSymbolicLink())try{a=T(p(t,o.name)).isFile()}catch{continue}a&&o.name.endsWith(".json")&&this.loadThemeFromFile(p(t,o.name),n,s,i)}}catch(e){const o=e instanceof Error?e.message:"failed to read theme directory";s.push({type:"warning",message:o,path:t})}}loadThemeFromFile(t,n,s,i){try{n.push(vt(t,i))}catch(e){const o=e instanceof Error?e.message:"failed to load theme";s.push({type:"warning",message:o,path:t})}}async loadExtensionFactories(t){const n=[],s=[];for(const[i,e]of this.extensionFactories.entries()){const o=typeof e!="function",a=o?e.factory:e,l=`<inline:${o?e.name:i+1}>`;try{const h=await tt(a,this.cwd,this.eventBus,t,l);h.hidden=o&&e.hidden,h.replaceable=o&&e.replaceable===!0,n.push(h)}catch(h){const g=h instanceof Error?h.message:"failed to load extension";s.push({path:l,error:g})}}return{extensions:n,errors:s}}dedupePrompts(t){const n=new Map,s=[];for(const i of t){const e=n.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}}):n.set(i.name,i)}return{prompts:Array.from(n.values()),diagnostics:s}}dedupeThemes(t){const n=new Map,s=[];for(const i of t){const e=i.name??"unnamed",o=n.get(e);o?s.push({type:"collision",message:`name "${e}" collision`,path:i.sourcePath,collision:{resourceType:"theme",name:e,winnerPath:o.sourcePath??"<builtin>",loserPath:i.sourcePath??"<builtin>"}}):n.set(e,i)}return{themes:Array.from(n.values()),diagnostics:s}}discoverSystemPromptFile(){const t=p(this.cwd,v,"SYSTEM.md");if(this.settingsManager.isProjectTrusted()&&f(t))return t;const n=p(this.agentDir,"SYSTEM.md");if(f(n))return n}discoverAppendSystemPromptFile(){const t=p(this.cwd,v,"APPEND_SYSTEM.md");if(this.settingsManager.isProjectTrusted()&&f(t))return t;const n=p(this.agentDir,"APPEND_SYSTEM.md");if(f(n))return n}isUnderPath(t,n){const s=y(n);if(t===s)return!0;const i=s.endsWith(b)?s:`${s}${b}`;return t.startsWith(i)}detectExtensionConflicts(t){const n=[],s=new Map,i=new Map;for(const e of t){for(const o of e.tools.keys()){const a=s.get(o);a&&a!==e.path?n.push({path:e.path,message:`Tool "${o}" conflicts with ${a}`}):s.set(o,e.path)}for(const o of e.flags.keys()){const a=i.get(o);a&&a!==e.path?n.push({path:e.path,message:`Flag "--${o}" conflicts with ${a}`}):i.set(o,e.path)}}return n}}export{ie as DefaultResourceLoader,it as isBuiltinExtension,Bt as loadProjectContextFiles};
|
|
1
|
+
var ct=Object.defineProperty;var P=(c,t)=>ct(c,"name",{value:t,configurable:!0});import{existsSync as f,readdirSync as mt,readFileSync as $,statSync as T}from"node:fs";import{basename as Q,dirname as V,join as m,resolve as y,sep as b}from"node:path";import{detectCapabilities as pt,getTerminalColorMode as dt}from"@earendil-works/pi-tui";import Z from"chalk";import{APP_NAME as ut,CONFIG_DIR_NAME as v,getExamplesPath as ft,getPackageDir as Pt,getProjectPromptsDir as gt}from"../config.js";import{dalBuiltinExtensionPaths as xt}from"../dal/builtins.js";import{applyCommunityEnv as St,hostDependenciesOf as tt,installedHostCopies as yt,isAdaptablePackage as wt,tryEnsurePackageAdapted as vt}from"../dal/extension-compat.js";import{fill as A,t as S}from"../dal/i18n.js";import{loadThemeFromPath as kt}from"../modes/interactive/theme/theme.js";import{canonicalizePath as M,isLocalPath as j,resolvePath as w}from"../utils/paths.js";import{stripBom as W}from"../utils/text.js";import{createEventBus as Et}from"./event-bus.js";import{clearExtensionCache as Dt,createExtensionRuntime as Ft,loadExtensionFromFactory as et,loadExtensionsCached as st}from"./extensions/loader.js";import{findGitPaths as Tt}from"./footer-data-provider.js";import{DefaultPackageManager as bt}from"./package-manager.js";import{loadPromptTemplates as Mt}from"./prompt-templates.js";import{SettingsManager as It}from"./settings-manager.js";import{loadSkills as Ot}from"./skills.js";import{BUILTIN_PATH_PREFIX as k,createSourceInfo as I,getSyntheticPathSource as Rt,isSyntheticPath as N}from"./source-info.js";import{resetTimings as Ct}from"./timings.js";function it(c,t,n){let s;try{s=Pt()}catch{s=void 0}St({agentDir:n.agentDir,packageDir:s});const i=[],e=new Map;for(const o of c){const a=t.get(o);a?.packageRoot&&!e.has(a.packageRoot)&&e.set(a.packageRoot,a)}for(const[o,a]of e){const l=m(o,"package.json");if(!f(l))continue;JSON.parse(W($(l,"utf-8"))),wt(o,a.source,n)&&vt(o);const h=yt(o,tt(o));if(h.length===0)continue;const g=tt(o).filter(x=>h.some(d=>d.endsWith(m(...x.split("/")))));i.push({path:l,warning:A(S('\u6269\u5C55\u5305\u5728 dependencies \u91CC\u81EA\u5E26\u4E86 DAL \u5DF2\u63D0\u4F9B\u7684\u5E93\uFF08{names}\uFF09\uFF0C\u8FD9\u4E9B\u526F\u672C\u4F1A\u548C DAL \u81EA\u5DF1\u7684\u91CD\u590D\u52A0\u8F7D\u3002\u8BF7\u628A\u5B83\u4EEC\u6539\u5230 peerDependencies\uFF0C\u7248\u672C\u5199 "*"\u3002'),{names:g.join(", ")})})}return i}P(it,"prepareExtensionPackages");function B(c,t){c.warnings=[...new Map([...c.warnings??[],...t].map(n=>[n.path,n])).values()]}P(B,"mergeExtensionWarnings");function nt(c){return typeof c!="function"&&c.builtin===!0}P(nt,"isBuiltinExtension");let ot;function At(c){return ot??=new Set(xt().map(t=>y(t))),ot.has(y(c))}P(At,"isDalBundledExtensionPath");function at(c,t){const n=P(i=>[...[...i.tools.keys()].map(e=>`tool:${e}`),...[...i.commands.keys()].map(e=>`command:${e}`),...[...i.flags.keys()].map(e=>`flag:${e}`)],"names"),s=new Map(c.filter(i=>!i.replaceable).flatMap(i=>n(i).map(e=>[e,i])));return c.filter(i=>{if(!i.replaceable)return!0;const e=n(i).map(o=>({name:o,extension:s.get(o)})).find(o=>o.extension!==void 0);if(!e)return!0;if(i.path.startsWith(k)&&!At(e.extension.path)){const o=i.path.slice(k.length),[a,l]=e.name.split(":",2),h=a==="command"?`/${l}`:a==="flag"?`--${l}`:l;t?.push({path:i.path,warning:A(S("\u6269\u5C55 {path} \u6CE8\u518C\u4E86{kind} `{name}`\uFF0C\u6240\u4EE5\u5185\u7F6E\u6269\u5C55 `{builtin}` \u6CA1\u6709\u52A0\u8F7D\u3002\u8981\u4F7F\u7528 `{builtin}`\uFF0C\u8FD0\u884C `{app} config`\uFF0C\u5728\u5185\u7F6E\u6269\u5C55\u91CC\u786E\u8BA4\u5B83\u5DF2\u542F\u7528\uFF0C\u7136\u540E\u505C\u7528\u6216\u79FB\u9664\u8FD9\u4E2A\u6269\u5C55\u3002\u4E24\u8005\u6700\u597D\u53EA\u4FDD\u7559\u4E00\u4E2A\u3002"),{path:e.extension.path,kind:a==="command"?S("\u4E00\u4E2A\u547D\u4EE4"):a==="flag"?S("\u4E00\u4E2A\u53C2\u6570"):S("\u4E00\u4E2A\u5DE5\u5177"),name:h,builtin:o,app:ut})})}return!1})}P(at,"omitReplacedExtensions");function rt(c,t){if(c){if(f(c))try{return W($(c,"utf-8"))}catch(n){return console.error(Z.yellow(A(S("\u8B66\u544A\uFF1A\u65E0\u6CD5\u8BFB\u53D6{what}\u6587\u4EF6 {path}\uFF1A{error}"),{what:t,path:c,error:String(n)}))),c}return c}}P(rt,"resolvePromptInput");function L(c){const t=["AGENTS.override.md","AGENTS.md","AGENTS.MD","CLAUDE.md","CLAUDE.MD"];for(const n of t){const s=m(c,n);if(f(s))try{if(!T(s).isFile())continue;return{path:s,content:W($(s,"utf-8"))}}catch(i){console.error(Z.yellow(A(S("\u8B66\u544A\uFF1A\u65E0\u6CD5\u8BFB\u53D6 {path}\uFF1A{error}"),{path:s,error:String(i)})))}}return null}P(L,"loadContextFileFromDir");function Bt(c){const t=Tt(c);if(!t)return;const n=M(t.commonGitDir),s=M(t.repoDir),i=V(n);if(!s.startsWith(`${i}${b}`)||M(m(i,".git"))!==n)return;const e=L(s);return e?m(i,Q(e.path)):void 0}P(Bt,"findShadowedContextFile");function $t(c){const t=w(c.cwd),n=w(c.agentDir),s=[],i=new Set,e=L(n);e&&(s.push(e),i.add(e.path));const o=[],a=Bt(t);let l=t;for(;;){const h=L(l),g=a!==void 0&&h!==null&&m(M(l),Q(h.path))===a;h&&!g&&!i.has(h.path)&&(o.unshift(h),i.add(h.path));const x=V(l);if(x===l)break;l=x}return s.push(...o),s}P($t,"loadProjectContextFiles");class ne{static{P(this,"DefaultResourceLoader")}cwd;agentDir;settingsManager;eventBus;packageManager;additionalExtensionPaths;additionalSkillPaths;additionalPromptTemplatePaths;additionalThemePaths;extensionFactories;builtinExtensions;noExtensions;disabledBuiltinExtensions;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=w(t.cwd),this.agentDir=w(t.agentDir),this.settingsManager=t.settingsManager??It.create(this.cwd,this.agentDir),this.eventBus=t.eventBus??Et();const n=t.extensionFactories??[];this.extensionFactories=n.filter(s=>!nt(s)),this.builtinExtensions=new Map(n.filter(nt).map(s=>[s.name,s])),this.packageManager=new bt({cwd:this.cwd,agentDir:this.agentDir,settingsManager:this.settingsManager,builtinExtensions:[...this.builtinExtensions.keys()]}),this.additionalExtensionPaths=t.additionalExtensionPaths??[],this.additionalSkillPaths=t.additionalSkillPaths??[],this.additionalPromptTemplatePaths=t.additionalPromptTemplatePaths??[],this.additionalThemePaths=t.additionalThemePaths??[],this.noExtensions=t.noExtensions??!1,this.disabledBuiltinExtensions=new Set(t.disabledBuiltinExtensions),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:Ft()},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 n=this.normalizeExtensionPaths(t.skillPaths??[]),s=this.normalizeExtensionPaths(t.promptPaths??[]),i=this.normalizeExtensionPaths(t.themePaths??[]);for(const e of n)this.extensionSkillSourceInfos.set(e.path,I(e.path,e.metadata));for(const e of s)this.extensionPromptSourceInfos.set(e.path,I(e.path,e.metadata));for(const e of i)this.extensionThemeSourceInfos.set(e.path,I(e.path,e.metadata));n.length>0&&(this.lastSkillPaths=this.mergePaths(this.lastSkillPaths,n.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){Ct("extensions"),this.loaded&&Dt();let n;if(t?.resolveProjectTrust){n=await this.loadProjectTrustExtensions();const r=await t.resolveProjectTrust({extensionsResult:n});this.settingsManager.setProjectTrusted(r)}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 o=P(r=>{for(const p of r)e.has(p.path)||e.set(p.path,p.metadata);return r.filter(p=>p.enabled)},"getEnabledResources"),a=P(r=>o(r).map(p=>p.path),"getEnabledPaths"),l=a(s.extensions),h=o(s.skills),g=a(s.prompts),x=a(s.themes),d=h.map(r=>this.mapSkillPath(r,e));for(const r of i.extensions)e.has(r.path)||e.set(r.path,{source:"cli",scope:"temporary",origin:"top-level"});for(const r of i.skills)e.has(r.path)||e.set(r.path,{source:"cli",scope:"temporary",origin:"top-level"});const u=a(i.extensions),E=a(i.skills),z=a(i.prompts),U=a(i.themes),G=(this.noExtensions?u:this.mergePaths(u,l)).filter(r=>!r.startsWith(k)||!this.disabledBuiltinExtensions.has(r.slice(k.length))),ht=it(G,e,{agentDir:this.agentDir,cwd:this.cwd}),O=await this.loadFinalExtensionSet(G,n);B(O,ht);for(const r of this.additionalExtensionPaths)if(j(r)){const p=this.resolveResourcePath(r);f(p)||O.errors.push({path:p,error:`Extension path does not exist: ${p}`})}this.extensionsResult=this.extensionsOverride?this.extensionsOverride(O):O,this.applyExtensionSourceInfo(this.extensionsResult.extensions,e);const D=m(ft(),"skills"),_=!this.noSkills&&f(D)?[D]:[];_.length>0&&!e.has(D)&&e.set(D,{source:"auto",scope:"user",origin:"top-level",baseDir:D});const Y=this.noSkills?this.mergePaths(E,this.additionalSkillPaths):this.mergePaths([...E,...d,..._],this.additionalSkillPaths);this.lastSkillPaths=Y,this.updateSkillsFromPaths(Y,e);for(const r of this.additionalSkillPaths)if(j(r)){const p=this.resolveResourcePath(r);!f(p)&&!this.skillDiagnostics.some(F=>F.path===p)&&this.skillDiagnostics.push({type:"error",message:"Skill path does not exist",path:p})}const H=this.noPromptTemplates?this.mergePaths(z,this.additionalPromptTemplatePaths):this.mergePaths([...z,...g],this.additionalPromptTemplatePaths);this.lastPromptPaths=H,this.updatePromptsFromPaths(H,e);for(const r of this.additionalPromptTemplatePaths)if(j(r)){const p=this.resolveResourcePath(r);!f(p)&&!this.promptDiagnostics.some(F=>F.path===p)&&this.promptDiagnostics.push({type:"error",message:"Prompt template path does not exist",path:p})}const J=this.noThemes?this.mergePaths(U,this.additionalThemePaths):this.mergePaths([...U,...x],this.additionalThemePaths);this.lastThemePaths=J,this.updateThemesFromPaths(J,e);for(const r of this.additionalThemePaths){const p=this.resolveResourcePath(r);!f(p)&&!this.themeDiagnostics.some(F=>F.path===p)&&this.themeDiagnostics.push({type:"error",message:"Theme path does not exist",path:p})}const K={agentsFiles:this.noContextFiles?[]:$t({cwd:this.cwd,agentDir:this.agentDir})},lt=this.agentsFilesOverride?this.agentsFilesOverride(K):K;this.agentsFiles=lt.agentsFiles;const R=this.systemPromptSource??this.discoverSystemPromptFile(),X=rt(R,S("\u7CFB\u7EDF\u63D0\u793A\u8BCD"));this.systemPrompt=this.systemPromptOverride?this.systemPromptOverride(X):X,this.systemPromptSourcePath=R&&f(R)?w(R):void 0;let C=this.appendSystemPromptSource;if(!C){const r=this.discoverAppendSystemPromptFile();C=r?[r]:[]}const q=C.map(r=>rt(r,S("\u8FFD\u52A0\u7684\u7CFB\u7EDF\u63D0\u793A\u8BCD"))).filter(r=>r!==void 0);this.appendSystemPrompt=this.appendSystemPromptOverride?this.appendSystemPromptOverride(q):q,this.appendSystemPromptSourcePaths=C.filter(r=>f(r)).map(r=>w(r)),this.loaded=!0}async loadCurrentExtensionSet(t){const n=await this.packageManager.resolve(),s=await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths,{temporary:!0}),i=n.extensions.filter(d=>d.enabled).map(d=>d.path),e=s.extensions.filter(d=>d.enabled).map(d=>d.path),o=(this.noExtensions?e:this.mergePaths(e,i)).filter(d=>!d.startsWith(k)),a=new Map([...n.extensions,...s.extensions].map(d=>[d.path,d.metadata])),l=it(o,a,{agentDir:this.agentDir,cwd:this.cwd}),h=await st(o,this.cwd,this.eventBus);if(B(h,l),!t.includeInlineFactories)return h;const g=await this.loadExtensionFactories(h.runtime);h.extensions.push(...g.extensions),h.errors.push(...g.errors);const x=[];return h.extensions=at(h.extensions,x),B(h,x),h}resolveExtensionLoadPath(t){return N(t)?t:w(t,this.cwd,{normalizeUnicodeSpaces:!0})}async loadExtensionPaths(t,n){const s=P(e=>e.startsWith(k),"isBuiltinPath"),i=await st(t.filter(e=>!s(e)),this.cwd,this.eventBus,n);for(const e of t.filter(s)){const o=this.builtinExtensions.get(e.slice(k.length));if(!o){i.errors.push({path:e,error:`Unknown built-in extension: ${e}`});continue}try{const a=await et(o.factory,this.cwd,this.eventBus,i.runtime,e);a.hidden=!0,a.replaceable=o.replaceable===!0,i.extensions.push(a)}catch(a){i.errors.push({path:e,error:a instanceof Error?a.message:"failed to load extension"})}}return i}async loadFinalExtensionSet(t,n){const s=n?.extensions??[],i=new Map(s.filter(u=>!u.path.startsWith("<inline:")).map(u=>[u.resolvedPath,u])),e=new Set((n?.errors??[]).map(u=>this.resolveExtensionLoadPath(u.path))),o=t.filter(u=>{const E=this.resolveExtensionLoadPath(u);return!i.has(E)&&!e.has(E)}),a=await this.loadExtensionPaths(o,n?.runtime),l=new Map(i);for(const u of a.extensions)l.set(u.resolvedPath,u);const h=n?{extensions:s.filter(u=>u.path.startsWith("<inline:")),errors:[]}:await this.loadExtensionFactories(a.runtime),g=t.map(u=>l.get(this.resolveExtensionLoadPath(u))).filter(u=>u!==void 0);g.push(...h.extensions);const x=[],d={extensions:at(g,x),errors:[...n?.errors??[],...a.errors,...h.errors],warnings:[...n?.warnings??[],...a.warnings??[]],runtime:a.runtime};return B(d,x),this.addExtensionConflictDiagnostics(d),d}addExtensionConflictDiagnostics(t){const n=this.detectExtensionConflicts(t.extensions);for(const s of n)t.errors.push({path:s.path,error:s.message})}mapSkillPath(t,n){if(t.metadata.source!=="auto"&&t.metadata.origin!=="package")return t.path;try{if(!T(t.path).isDirectory())return t.path}catch{return t.path}const s=m(t.path,"SKILL.md");return f(s)?(n.has(s)||n.set(s,t.metadata),s):t.path}normalizeExtensionPaths(t){return t.map(n=>{const s=n.metadata.baseDir?{...n.metadata,baseDir:this.resolveResourcePath(n.metadata.baseDir)}:n.metadata;return{path:this.resolveResourcePath(n.path),metadata:s}})}updateSkillsFromPaths(t,n){let s;this.noSkills&&t.length===0?s={skills:[],diagnostics:[]}:s=Ot({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,n)??e.sourceInfo??this.getDefaultSourceInfoForPath(e.filePath)})),this.skillDiagnostics=i.diagnostics}updatePromptsFromPaths(t,n){let s;if(this.noPromptTemplates&&t.length===0)s={prompts:[],diagnostics:[]};else{const e=Mt({cwd:this.cwd,agentDir:this.agentDir,promptPaths:t,includeDefaults:!1}),o=this.dedupePrompts(e.templates);s={prompts:o.prompts,diagnostics:[...e.diagnostics,...o.diagnostics]}}const i=this.promptsOverride?this.promptsOverride(s):s;this.prompts=i.prompts.map(e=>({...e,sourceInfo:this.findSourceInfoForPath(e.filePath,this.extensionPromptSourceInfos,n)??e.sourceInfo??this.getDefaultSourceInfoForPath(e.filePath)})),this.promptDiagnostics=i.diagnostics}updateThemesFromPaths(t,n){let s;if(this.noThemes&&t.length===0)s={themes:[],diagnostics:[]};else{const e=dt({...pt(()=>!1),...this.settingsManager.getTerminalCapabilityOverrides()}),o=this.loadThemes(t,!1,e),a=this.dedupeThemes(o.themes);s={themes:a.themes,diagnostics:[...o.diagnostics,...a.diagnostics]}}const i=this.themesOverride?this.themesOverride(s):s;this.themes=i.themes.map(e=>{const o=e.sourcePath;return e.sourceInfo=o?this.findSourceInfoForPath(o,this.extensionThemeSourceInfos,n)??e.sourceInfo??this.getDefaultSourceInfoForPath(o):e.sourceInfo,e}),this.themeDiagnostics=i.diagnostics}applyExtensionSourceInfo(t,n){for(const s of t){s.sourceInfo=this.findSourceInfoForPath(s.path,void 0,n)??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,n,s){if(!t)return;if(N(t))return this.getDefaultSourceInfoForPath(t);const i=y(t);if(n)for(const[e,o]of n.entries()){const a=y(e);if(i===a||i.startsWith(`${a}${b}`))return{...o,path:t}}if(s){const e=s.get(i)??s.get(t);if(e)return I(t,e);for(const[o,a]of s.entries()){const l=y(o);if(i===l||i.startsWith(`${l}${b}`))return I(t,a)}}}getDefaultSourceInfoForPath(t){const n=Rt(t);if(n)return{path:t,source:n,scope:"temporary",origin:"top-level"};const s=y(t),i=[m(this.agentDir,"skills"),m(this.agentDir,"prompts"),m(this.agentDir,"themes"),m(this.agentDir,"extensions")],e=[m(this.cwd,v,"skills"),gt(m(this.cwd,v)),m(this.cwd,v,"themes"),m(this.cwd,v,"extensions")];for(const o of i)if(this.isUnderPath(s,o))return{path:t,source:"local",scope:"user",origin:"top-level",baseDir:o};for(const o of e)if(this.isUnderPath(s,o))return{path:t,source:"local",scope:"project",origin:"top-level",baseDir:o};return{path:t,source:"local",scope:"temporary",origin:"top-level",baseDir:T(s).isDirectory()?s:y(s,"..")}}mergePaths(t,n){const s=[],i=new Set;for(const e of[...t,...n]){const o=this.resolveResourcePath(e),a=M(o);i.has(a)||(i.add(a),s.push(o))}return s}resolveResourcePath(t){return N(t)?t:w(t,this.cwd,{trim:!0})}loadThemes(t,n,s){const i=[],e=[];if(n){const o=[m(this.agentDir,"themes"),m(this.cwd,v,"themes")];for(const a of o)this.loadThemesFromDir(a,i,e,s)}for(const o of t){const a=this.resolveResourcePath(o);if(!f(a)){e.push({type:"warning",message:"theme path does not exist",path:a});continue}try{const l=T(a);l.isDirectory()?this.loadThemesFromDir(a,i,e,s):l.isFile()&&a.endsWith(".json")?this.loadThemeFromFile(a,i,e,s):e.push({type:"warning",message:"theme path is not a json file",path:a})}catch(l){const h=l instanceof Error?l.message:"failed to read theme path";e.push({type:"warning",message:h,path:a})}}return{themes:i,diagnostics:e}}loadThemesFromDir(t,n,s,i){if(f(t))try{const e=mt(t,{withFileTypes:!0});for(const o of e){let a=o.isFile();if(o.isSymbolicLink())try{a=T(m(t,o.name)).isFile()}catch{continue}a&&o.name.endsWith(".json")&&this.loadThemeFromFile(m(t,o.name),n,s,i)}}catch(e){const o=e instanceof Error?e.message:"failed to read theme directory";s.push({type:"warning",message:o,path:t})}}loadThemeFromFile(t,n,s,i){try{n.push(kt(t,i))}catch(e){const o=e instanceof Error?e.message:"failed to load theme";s.push({type:"warning",message:o,path:t})}}async loadExtensionFactories(t){const n=[],s=[];for(const[i,e]of this.extensionFactories.entries()){const o=typeof e!="function",a=o?e.factory:e,l=`<inline:${o?e.name:i+1}>`;try{const h=await et(a,this.cwd,this.eventBus,t,l);h.hidden=o&&e.hidden,h.replaceable=o&&e.replaceable===!0,n.push(h)}catch(h){const g=h instanceof Error?h.message:"failed to load extension";s.push({path:l,error:g})}}return{extensions:n,errors:s}}dedupePrompts(t){const n=new Map,s=[];for(const i of t){const e=n.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}}):n.set(i.name,i)}return{prompts:Array.from(n.values()),diagnostics:s}}dedupeThemes(t){const n=new Map,s=[];for(const i of t){const e=i.name??"unnamed",o=n.get(e);o?s.push({type:"collision",message:`name "${e}" collision`,path:i.sourcePath,collision:{resourceType:"theme",name:e,winnerPath:o.sourcePath??"<builtin>",loserPath:i.sourcePath??"<builtin>"}}):n.set(e,i)}return{themes:Array.from(n.values()),diagnostics:s}}discoverSystemPromptFile(){const t=m(this.cwd,v,"SYSTEM.md");if(this.settingsManager.isProjectTrusted()&&f(t))return t;const n=m(this.agentDir,"SYSTEM.md");if(f(n))return n}discoverAppendSystemPromptFile(){const t=m(this.cwd,v,"APPEND_SYSTEM.md");if(this.settingsManager.isProjectTrusted()&&f(t))return t;const n=m(this.agentDir,"APPEND_SYSTEM.md");if(f(n))return n}isUnderPath(t,n){const s=y(n);if(t===s)return!0;const i=s.endsWith(b)?s:`${s}${b}`;return t.startsWith(i)}detectExtensionConflicts(t){const n=[],s=new Map,i=new Map;for(const e of t){for(const o of e.tools.keys()){const a=s.get(o);a&&a!==e.path?n.push({path:e.path,message:`Tool "${o}" conflicts with ${a}`}):s.set(o,e.path)}for(const o of e.flags.keys()){const a=i.get(o);a&&a!==e.path?n.push({path:e.path,message:`Flag "--${o}" conflicts with ${a}`}):i.set(o,e.path)}}return n}}export{ne as DefaultResourceLoader,nt as isBuiltinExtension,$t as loadProjectContextFiles};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var p=Object.defineProperty;var o=(e,t)=>p(e,"name",{value:t,configurable:!0});import{createHash as l}from"node:crypto";import{realpathSync as a}from"node:fs";import{join as c}from"node:path";import{pathToFileURL as s}from"node:url";function m(e){return[...l("md5").update(Buffer.from(e,"utf16le")).digest()].map(r=>r.toString(16)).join("")}o(m,"libreOfficePipeHash");function O(e,t=process.platform,r=process.getuid?.()){if(t!=="darwin"||r===void 0)return;let i;try{i=a(e)}catch{i=e}const f=s(c(i,"libreoffice")).href,n=`/private/tmp/OSL_PIPE_${r}_SingleOfficeIPC_${m(f)}`;return{env:{UserInstallation:f},allowWrite:["/private/tm[p]",n],allowUnixSockets:[n]}}o(O,"libreOfficeAccess");export{O as libreOfficeAccess,m as libreOfficePipeHash};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var M=Object.defineProperty;var t=(e,r)=>M(e,"name",{value:r,configurable:!0});import{acquirePlan as W,planBwrapCommand as F,releasePlan as L}from"./bwrap-placeholders.js";import{domainMatches as R,isAlwaysBlockedHost as N}from"./policy.js";const b="dal-sandbox.invalid",u=new Set;let l,c,x,w=Promise.resolve(),y=0;async function A(){return l??=import("@anthropic-ai/sandbox-runtime").then(e=>e.SandboxManager),l}t(A,"loadManager");function D(e){return{network:{allowedDomains:[b],deniedDomains:[],allowLocalBinding:e.allowLocalBinding},filesystem:{denyRead:[],allowWrite:[],denyWrite:[]},...e.ripgrep?{ripgrep:{command:e.ripgrep}}:{}}}t(D,"baseConfig");function B(e){return u.add(e),()=>{u.delete(e)}}t(B,"registerNetworkGrant");function
|
|
1
|
+
var M=Object.defineProperty;var t=(e,r)=>M(e,"name",{value:r,configurable:!0});import{acquirePlan as W,planBwrapCommand as F,releasePlan as L}from"./bwrap-placeholders.js";import{domainMatches as R,isAlwaysBlockedHost as N}from"./policy.js";const b="dal-sandbox.invalid",u=new Set;let l,c,x,w=Promise.resolve(),y=0;async function A(){return l??=import("@anthropic-ai/sandbox-runtime").then(e=>e.SandboxManager),l}t(A,"loadManager");function D(e){return{network:{allowedDomains:[b],deniedDomains:[],allowLocalBinding:e.allowLocalBinding,...e.allowUnixSockets?.length?{allowUnixSockets:e.allowUnixSockets}:{}},filesystem:{denyRead:[],allowWrite:[],denyWrite:[]},...e.ripgrep?{ripgrep:{command:e.ripgrep}}:{}}}t(D,"baseConfig");function B(e){return u.add(e),()=>{u.delete(e)}}t(B,"registerNetworkGrant");function k(e,r){let i=!1;if(!N(e))for(const a of u)a.deniedDomains.some(n=>R(e,n))||a.allowedDomains.some(n=>R(e,n))&&(i=!0);if(!i)for(const a of u)a.refusals.some(n=>n.host===e&&n.port===r)||a.refusals.push({host:e,...r!==void 0?{port:r}:{}});return i}t(k,"decideNetworkRequest");function T(){const e=process._getActiveHandles;return new Set(typeof e=="function"?e.call(process):[])}t(T,"activeHandles");async function H(e,r){c||(x??=(async()=>{const i={SIGINT:new Set(process.listeners("SIGINT")),SIGTERM:new Set(process.listeners("SIGTERM"))},a=T();try{await e.initialize(D(r),async({host:n,port:s})=>k(n,s),!1),c={ready:!0}}catch(n){c={ready:!1,error:n instanceof Error?n.message:String(n)}}finally{for(const n of["SIGINT","SIGTERM"])for(const s of process.listeners(n))i[n].has(s)||process.removeListener(n,s);for(const n of T())!a.has(n)&&typeof n.unref=="function"&&n.unref()}})(),await x)}t(H,"ensureProxy");function X(){return c&&!c.ready?c.error:o&&"error"in o?o.error:void 0}t(X,"proxyUnavailableReason");let o,g,G;function Y(e){G=e?async()=>{const r=await e();return"error"in r?r:{port:r.port,server:{close:t(()=>{},"close")}}}:void 0,o=void 0,g=void 0}t(Y,"setFilteringProxyStarterForTesting");async function U(){try{const{createHttpProxyServer:e}=await import("@anthropic-ai/sandbox-runtime/dist/sandbox/http-proxy.js"),r=e({filter:t((a,n)=>k(n,a),"filter")}),i=await new Promise((a,n)=>{r.once("error",n),r.listen(0,"127.0.0.1",()=>{const s=r.address();a(typeof s=="object"&&s?s.port:0)})});return r.unref(),{port:i,server:r}}catch(e){return{error:e instanceof Error?e.message:String(e)}}}t(U,"startFilteringProxy");async function J(){return o?"error"in o?o:{port:o.port}:(g??=(G??U)(),o=await g,"error"in o?o:{port:o.port})}t(J,"ensureFilteringProxy");function K(){y++}t(K,"acquireSandboxRuntime");async function Q(){y=Math.max(0,y-1),y===0&&await O()}t(Q,"releaseSandboxRuntime");async function Z(e,r){const i=await A(),a=r.allowedDomains.length>0;a&&await H(i,e);const n=t(async()=>{const f={denyRead:e.denyRead,allowWrite:e.allowWrite,denyWrite:e.denyWrite};i.updateConfig({...D(e),filesystem:f});const h=a&&c?.ready===!0,E=Date.now(),v=await i.wrapWithSandbox(e.command,e.shell,{network:{allowedDomains:h?[b]:[],deniedDomains:[]},filesystem:f}),m=process.platform==="linux"?F(v):void 0;return m&&W(m),{wrapped:m?.command??v,proxied:h,plan:m,wrappedAt:E}},"run"),s=w.then(n,n);w=s.catch(()=>{});const{wrapped:p,proxied:d,plan:S,wrappedAt:I}=await s,C=B(r);let P=!1;return{command:p,proxied:d,release:t(()=>{if(P||(P=!0,C(),!S))return;const f=t(()=>{L(S,I)},"cleanup");w=w.then(f,f)},"release")}}t(Z,"wrapCommand");async function $(e,r,i){if(!l)return[];const n=(await l).getSandboxViolationStore();if(n.getTotalCount()===0)return[];const s=Date.now()+i;for(;;){const p=n.getViolationsForCommand(e).filter(d=>d.timestamp.getTime()>=r-1e3);if(p.length>0||Date.now()>=s)return p;await new Promise(d=>setTimeout(d,50))}}t($,"violationsForCommand");async function O(){u.clear(),o&&"server"in o&&o.server.close(),o=void 0,g=void 0;const e=c!==void 0;if(c=void 0,x=void 0,!e||!l)return;await(await l).reset()}t(O,"resetSandboxRuntime");export{K as acquireSandboxRuntime,k as decideNetworkRequest,J as ensureFilteringProxy,X as proxyUnavailableReason,B as registerNetworkGrant,Q as releaseSandboxRuntime,O as resetSandboxRuntime,Y as setFilteringProxyStarterForTesting,$ as violationsForCommand,Z as wrapCommand};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)){const
|
|
3
|
-
`)}planNetworkEscalation(o){if(this.policy.level!=="workspace-write"||!this.availability().available)return;const n=
|
|
4
|
-
${o.command}`,
|
|
5
|
-
`),t=e.mode==="unsandboxed"?[r,s]:[r,l,s],d=v(h("\u52A9\u624B\u60F3\u8981{what}\u3002"),{what:
|
|
1
|
+
var z=Object.defineProperty;var c=(e,o)=>z(e,"name",{value:o,configurable:!0});import{spawnSync as J}from"node:child_process";import{mkdirSync as Z}from"node:fs";import{isAbsolute as O,relative as q,resolve as oo}from"node:path";import{ToolExecutionError as eo}from"@earendil-works/pi-agent-core";import{fill as v,t as h}from"../../dal/i18n.js";import{createTempDir as no,removeTempPath as ao}from"../../utils/temp-files.js";import{toolDenial as io,withToolDenial as to}from"../tool-denial.js";import{detectSandboxAvailability as so}from"./availability.js";import{collectBlockedAccesses as U}from"./denial.js";import{libreOfficeAccess as ro}from"./libreoffice.js";import{detectNetworkCommand as B,FAIL_FAST_NETWORK_ENV as L,networkDomainsFor as lo,packageCacheDirs as co}from"./package-managers.js";import{domainMatches as M,expandPath as F,filesystemRules as mo}from"./policy.js";import{acquireSandboxRuntime as ho,ensureFilteringProxy as fo,proxyUnavailableReason as K,registerNetworkGrant as po,releaseSandboxRuntime as wo,violationsForCommand as uo,wrapCommand as bo}from"./runtime.js";import{prepareWindowsCommand as vo}from"./windows.js";function E(e,o){return new eo(e,to({sandbox:o},io("sandbox",e)))}c(E,"sandboxRefusal");const N=Symbol.for("dal.sandbox.escalationHandlers"),k=globalThis;k[N]instanceof Set||(k[N]=new Set);const R=k[N];function Lo(e){return R.add(e),()=>{R.delete(e)}}c(Lo,"registerSandboxEscalationHandler");const H=Symbol.for("dal.sandbox.processSandbox");function Mo(e){k[H]=e}c(Mo,"setProcessShellSandbox");function Fo(){return k[H]}c(Fo,"getProcessShellSandbox");const X=new Map;function yo(e){const o=X.get(e);if(o)return o;const n=J("git",["rev-parse","--absolute-git-dir","--git-common-dir"],{cwd:e,encoding:"utf8",timeout:3e3}),r=[];if(n.status===0)for(const s of n.stdout.split(`
|
|
2
|
+
`)){const i=s.trim();if(!i)continue;const a=O(i)?i:oo(e,i),t=q(e,a);(t.startsWith("..")||O(t))&&r.push(a)}const l=[...new Set(r)];return X.set(e,l),l}c(yo,"gitDirsOutside");function $(e){return Array.isArray(e)?e.filter(o=>typeof o=="string"&&o.trim().length>0).map(o=>o.trim()):[]}c($,"cleanList");let xo=0;class Ko{static{c(this,"ShellSandbox")}policy;onEscalation;onEvent;availabilityOverride;sessionDomains=new Set;sessionWritable=new Set;holdsRuntime=!1;sharedScratch;ownScratch;constructor(o){this.policy=o.policy,this.onEscalation=o.onEscalation,this.onEvent=o.onEvent,this.availabilityOverride=o.availability,this.sharedScratch=o.scratchDir,this.active&&(ho(),this.holdsRuntime=!0)}scratchDir(){return this.sharedScratch?this.sharedScratch():(this.ownScratch??=Do(),this.ownScratch)}async dispose(){this.ownScratch&&(ao(this.ownScratch),this.ownScratch=void 0),this.holdsRuntime&&(this.holdsRuntime=!1,await wo())}get level(){return this.policy.level}get active(){return this.policy.level!=="off"}availability(){return this.availabilityOverride??so()}status(){const o=this.availability(),n=K();return{level:this.policy.level,levelSource:this.policy.levelSource,enforced:this.active&&o.available,platform:o.platform,...o.mechanism?{mechanism:o.mechanism}:{},...this.active&&!o.available&&o.reason?{unavailableReason:o.reason}:{},...o.isolationTier?{isolationTier:o.isolationTier}:{},...o.limitations?.length?{limitations:[...o.limitations]}:{},network:{allowedDomains:[...this.policy.network.allowedDomains],deniedDomains:[...this.policy.network.deniedDomains],...n?{proxyError:n}:{}},sessionAllowances:{domains:[...this.sessionDomains],writablePaths:[...this.sessionWritable]}}}describeForModel(){if(!this.active)return;const o=this.policy.level==="read-only"?"writes only to $TMPDIR (session scratch)":"writes only to the working directory, $TMPDIR (session scratch) and package caches (agent/editor config, git hooks and .env stay read-only)",n=this.policy.network.allowedDomains,r=(n.length>0?`network off except ${n.join(", ")}`:"network off")+(this.policy.level==="workspace-write"?" (package installs via npm/pnpm/yarn/pip/uv/cargo/go and curl/wget/git clone ask the user for their hosts by themselves: run them plainly, without sandbox_escalation)":"");return`OS sandbox (${this.policy.level}): ${o}; ${r}; ~/.ssh and other credentials unreadable. Use sandbox_escalation only after the result says the sandbox blocked something the task needs.`}unavailableRefusal(){if(!this.active)return;const o=this.availability();if(!o.available)return[`Command refused: the sandbox level is "${this.policy.level}", but ${o.reason??"the OS sandbox is unavailable."}`,"Commands are not run without the sandbox unless the user says so explicitly.",'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
|
+
`)}planNetworkEscalation(o){if(this.policy.level!=="workspace-write"||!this.availability().available)return;const n=B(o.command);if(!n)return;const r=[...this.policy.network.allowedDomains,...this.sessionDomains],l=this.policy.network.deniedDomains,s=lo(n,o.cwd).filter(a=>!r.some(t=>M(a,t))&&!l.some(t=>M(a,t)));if(s.length===0)return;const i=n.ecosystems.length>0?"package-install":"download";return{mode:"allow",allow_domains:s,trigger:i,justification:i==="package-install"?h("\u8FD9\u6761\u547D\u4EE4\u8981\u5B89\u88C5\u4F9D\u8D56\uFF0C\u9700\u8981\u4ECE\u8F6F\u4EF6\u6E90\u4E0B\u8F7D\u3002"):h("\u8FD9\u6761\u547D\u4EE4\u8981\u4ECE\u7F51\u4E0A\u4E0B\u8F7D\u6587\u4EF6\u3002")}}async prepare(o){const n=this.policy.level;if(n==="off")return Y(o.command,{level:n,sandboxed:!1});const r=this.unavailableRefusal();if(r&&o.escalation?.mode!=="unsandboxed")throw E(r,{level:n,sandboxed:!1});let l=[],s=[],i;const a=o.escalation||r?void 0:this.planNetworkEscalation(o),t=a?await this.approveEscalation(o,a,a.trigger):void 0;if(a&&t&&t.decidedBy!=="none"){const f={request:t.request,decision:t.decision};if(i=f,!f.decision.approved)throw E(`The user did not allow network access for this command${f.decision.message?` (${f.decision.message})`:""}: it needs ${a.allow_domains.join(", ")}. Do not retry it with sandbox_escalation; continue without it or ask the user.`,{level:n,sandboxed:!1,escalation:f});l=t.allowDomains,s=t.allowWrite}else if(o.escalation){const{decidedBy:f,allowDomains:D,allowWrite:C,...b}=await this.approveEscalation(o,o.escalation);if(i=b,!b.decision.approved)throw E(`Sandbox escalation refused${b.decision.message?`: ${b.decision.message}`:"."} Do not retry the same escalation; continue without it or ask the user.`,{level:n,sandboxed:!1,escalation:i});if(b.request.mode==="unsandboxed")return Y(o.command,{level:n,sandboxed:!1,escalation:i});l=D,s=C}const d=this.availability(),w=o.shellKind??"bash";if(w!=="bash"&&d.mechanism!=="mxc")throw E(`Command refused: ${w} commands cannot run inside the ${d.mechanism??"OS"} sandbox, and the sandbox level is "${n}". Use the bash tool, or the user can opt out with \`dal --sandbox off\`.`,{level:n,sandboxed:!1});const p=this.scratchDir();n==="workspace-write"&&go(B(o.command)?.managers);const u=mo(this.policy,o.cwd,{gitDirs:this.policy.level==="workspace-write"?yo(o.cwd):[],extraWrite:[...this.sessionWritable,...s],scratchDir:p}),m={allowedDomains:[...this.policy.network.allowedDomains,...this.sessionDomains,...l],deniedDomains:this.policy.network.deniedDomains,refusals:[]},S=`${process.pid}-${++xo}`,x=m.allowedDomains.length===0;if(d.mechanism==="mxc"&&d.mxc){const f=x?{...o.env??process.env,...L}:o.env;return this.prepareWindows({...o,...f?{env:f}:{}},{level:n,shellKind:w,scratch:p,rules:u,grant:m,runId:S,escalation:i,availability:d})}const y=ko(p),W=x?Object.entries(L).map(([f,D])=>` ${f}=${D}`).join(""):"",g=ro(p,d.platform),G=g?` UserInstallation="\${UserInstallation:-${g.env.UserInstallation.replace(/[\\"$`]/g,"\\$&")}}"`:"",A=`export DAL_SANDBOX_RUN=${S} TMPDIR=${y} TMP=${y} TEMP=${y}${W}${G}
|
|
4
|
+
${o.command}`,Q=Date.now(),_=await bo({command:A,shell:o.shell,allowWrite:g?[...u.allowWrite,...g.allowWrite]:u.allowWrite,denyWrite:u.denyWrite,denyRead:u.denyRead,allowLocalBinding:o.background===!0||this.policy.network.allowLocalBinding,...g?{allowUnixSockets:g.allowUnixSockets}:{},...d.ripgrep?{ripgrep:d.ripgrep}:{}},m),j={level:n,sandboxed:!0,...i?{escalation:i}:{}};let P=!1;return{command:_.command,sandboxed:!0,details:j,finish:c(async(f,D)=>{if(P)return j.denial;if(P=!0,_.release(),f===0)return;const C=d.platform==="darwin"?await uo(A,Q,400):[],b=U({refusals:m.refusals,violations:C,output:D});if(!b)return;const T=_.proxied?void 0:K(),I={level:n,platform:d.platform,command:o.command,cwd:o.cwd,blocked:b,scratchDir:p,...T&&b.some(V=>V.kind==="network")?{networkProxyError:T}:{}};return j.denial=I,this.onEvent?.({type:"sandbox_denied",toolCallId:o.toolCallId,toolName:o.toolName,denial:I}),I},"finish")}}async prepareWindows(o,n){const{level:r,grant:l,availability:s}=n,i=s.mxc;if(!i)throw new Error("Command refused: the Windows sandbox (mxc) is not loaded.");let a,t;if(l.allowedDomains.length>0){const m=await fo();"port"in m?a=m.port:t=m.error}const d=vo({runtime:i,kind:n.shellKind,shellPath:o.shell,command:o.command,cwd:o.cwd,level:r,rules:n.rules,env:o.env??process.env,scratchDir:n.scratch,runId:n.runId,...a!==void 0?{proxyPort:a}:{},allowLocalNetwork:o.background===!0||this.policy.network.allowLocalBinding}),w=po(l),p={level:r,sandboxed:!0,...n.escalation?{escalation:n.escalation}:{}};let u=!1;return{command:d.command,sandboxed:!0,details:p,finish:c(async(m,S)=>{if(u)return p.denial;if(u=!0,w(),d.cleanup(),m===0)return;const x=U({refusals:l.refusals,violations:[],output:S});if(!x)return;const y={level:r,platform:s.platform,command:o.command,cwd:o.cwd,blocked:x,scratchDir:n.scratch,...t&&x.some(W=>W.kind==="network")?{networkProxyError:t}:{}};return p.denial=y,this.onEvent?.({type:"sandbox_denied",toolCallId:o.toolCallId,toolName:o.toolName,denial:y}),y},"finish")}}uiApprovals=Promise.resolve();queueUiApproval(o){const n=this.uiApprovals.then(o,o);return this.uiApprovals=n.catch(()=>{}),n}async approveEscalation(o,n,r){const l=n.mode==="unsandboxed"?"unsandboxed":"allow",s={toolCallId:o.toolCallId,toolName:o.toolName,command:o.command,cwd:o.cwd,level:this.policy.level,mode:l,justification:typeof n.justification=="string"?n.justification.trim():"",allowDomains:l==="allow"?$(n.allow_domains):[],allowWrite:l==="allow"?$(n.allow_write).map(a=>F(a,o.cwd)):[],background:o.background===!0,...r?{trigger:r}:{}},i=c((a,t)=>{const d=a.approved&&a.scope==="session"&&l==="unsandboxed"?{...a,scope:"once"}:a,w=d.approved&&l==="allow"?d.grant:void 0,p=[...new Set([...s.allowDomains,...$(w?.allowDomains)])],u=[...new Set([...s.allowWrite,...$(w?.allowWrite).map(m=>F(m,o.cwd))])];if(d.approved&&d.scope==="session"){for(const m of p)this.sessionDomains.add(m);for(const m of u)this.sessionWritable.add(m)}return r&&t==="none"||this.onEvent?.({type:"sandbox_escalation",toolCallId:o.toolCallId,toolName:o.toolName,request:s,decision:d,decidedBy:t}),{request:s,decision:d,decidedBy:t,allowDomains:p,allowWrite:u}},"finish");if(!s.justification)return i({approved:!1,message:"an escalation needs a justification"},"none");if(l==="allow"&&s.allowDomains.length===0&&s.allowWrite.length===0)return i({approved:!1,message:'mode "allow" needs allow_domains or allow_write'},"none");if(this.onEscalation){const a=await this.onEscalation(s,o.ctx);if(a)return i(a,"sdk")}for(const a of R){const t=await a(s,o.ctx);if(t)return i(t,"handler")}if(o.ctx?.hasUI){const a=o.ctx;return i(await this.queueUiApproval(()=>So(s,a,o.signal)),"ui")}return i({approved:!1,message:"nobody is available to approve it (no interactive UI and no approver configured)"},"none")}}function Y(e,o){return{command:e,sandboxed:!1,details:o,finish:c(async()=>{},"finish")}}c(Y,"passthrough");function go(e){if(!(!e||e.length===0))for(const o of co(e))try{Z(o,{recursive:!0,mode:448})}catch{}}c(go,"ensurePackageCaches");function Do(){return no("sandbox")}c(Do,"createScratchDir");function ko(e){return`'${e.replace(/'/g,"'\\''")}'`}c(ko,"shellQuote");async function So(e,o,n){if(n?.aborted)return{approved:!1,message:"the turn was interrupted before the user answered"};const r=h("\u4EC5\u672C\u6B21\u5141\u8BB8"),l=h("\u672C\u4F1A\u8BDD\u5185\u90FD\u5141\u8BB8"),s=h("\u62D2\u7EDD"),i=e.mode==="unsandboxed"?h("\u5728\u6C99\u7BB1\u4E4B\u5916\u8FD0\u884C\u547D\u4EE4\uFF08\u53EF\u8BBF\u95EE\u4F60\u7684\u5168\u90E8\u6587\u4EF6\u548C\u7F51\u7EDC\uFF09"):[e.allowDomains.length>0?v(h("\u8BBF\u95EE {domains}"),{domains:e.allowDomains.join(", ")}):"",e.allowWrite.length>0?v(h("\u5199\u5165 {paths}"),{paths:e.allowWrite.join(", ")}):""].filter(Boolean).join(h("\uFF0C\u5E76")),a=[v(h("\u52A9\u624B\u60F3\u8981{what}\u3002"),{what:i}),v(h("\u547D\u4EE4\uFF1A{command}"),{command:e.command}),v(h("\u76EE\u5F55\uFF1A{cwd}"),{cwd:e.cwd}),e.trigger?v(h("\u539F\u56E0\uFF1A{reason}"),{reason:e.justification}):v(h("\u52A9\u624B\u7ED9\u7684\u7406\u7531\uFF08\u672A\u7ECF\u6838\u5B9E\uFF09\uFF1A{reason}"),{reason:e.justification})].join(`
|
|
5
|
+
`),t=e.mode==="unsandboxed"?[r,s]:[r,l,s],d=v(h("\u52A9\u624B\u60F3\u8981{what}\u3002"),{what:i}),w=await o.ui.select(a,t,{...n?{signal:n}:{},approval:{source:"sandbox",toolCallId:e.toolCallId,toolName:e.toolName,args:{command:e.command,cwd:e.cwd,mode:e.mode,...e.allowDomains.length>0?{allowDomains:e.allowDomains}:{},...e.allowWrite.length>0?{allowWrite:e.allowWrite}:{},justification:e.justification},risk:{level:e.mode==="unsandboxed"?"high":"medium",reason:e.trigger?e.justification:v(h("\u52A9\u624B\u7ED9\u7684\u7406\u7531\uFF08\u672A\u7ECF\u6838\u5B9E\uFF09\uFF1A{reason}"),{reason:e.justification}),ruleId:`sandbox:${e.mode}`},title:d,description:a.split(`
|
|
6
6
|
`).slice(1).join(`
|
|
7
|
-
`),options:e.mode==="unsandboxed"?["allow_once","deny"]:["allow_once","allow_session","deny"]}});return n?.aborted?{approved:!1,message:"the turn was interrupted before the user answered"}:
|
|
7
|
+
`),options:e.mode==="unsandboxed"?["allow_once","deny"]:["allow_once","allow_session","deny"]}});return n?.aborted?{approved:!1,message:"the turn was interrupted before the user answered"}:w===r?{approved:!0,scope:"once"}:w===l?{approved:!0,scope:"session"}:{approved:!1,message:"the user declined"}}c(So,"askThroughUi");export{Ko as ShellSandbox,Do as createScratchDir,Fo as getProcessShellSandbox,Lo as registerSandboxEscalationHandler,Mo as setProcessShellSandbox};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var S=Object.defineProperty;var c=(e,
|
|
2
|
-
${
|
|
1
|
+
var S=Object.defineProperty;var c=(e,o)=>S(e,"name",{value:o,configurable:!0});import{spawnSync as D}from"node:child_process";import{existsSync as u,readFileSync as I,writeFileSync as p}from"node:fs";import{createRequire as w}from"node:module";import{join as d,win32 as m}from"node:path";import{createTempDir as L,removeTempPath as y}from"../../utils/temp-files.js";const x="DAL_MXC_SDK_DIR",P="0.6.0-alpha",O=/^0\.6\.\d+$/,q=["Allowlisted domains are reached through dal's filtering proxy, handed to mxc as its network proxy; mxc does not enforce per-host allow or block lists on Windows.","A background process that may listen locally gets mxc's local-network access, which also reaches other machines on the private network, not only localhost.","Protected names inside a writable folder (.env, .git/hooks, .vscode, .dal, \u2026) are protected only if they already exist when the command starts; creating a missing one is not blocked.","Protected credential files (~/.ssh, cloud credentials, \u2026) are denied only if they exist when the command starts."];let h;function H(e){h=e}c(H,"setMxcRuntimeForTesting");function v(e){const o=e[x]?.trim();if(o)return u(d(o,"package.json"))?{dir:o}:{error:`${x} is set to ${o}, but there is no package there.`};try{const r=w(import.meta.url);return{dir:d(r.resolve("@microsoft/mxc-sdk/package.json"),"..")}}catch{return{error:`Microsoft eXecution Containers (mxc) is not installed. Install it with \`npm install -g @microsoft/mxc-sdk@0.6.0\`, or set ${x} to an @microsoft/mxc-sdk 0.6 package directory.`}}}c(v,"sdkDirectory");function V(e={}){if(h)return h;const o=e.env??process.env,r=v(o);if("error"in r)return r;let t;try{t=JSON.parse(I(d(r.dir,"package.json"),"utf8")).version??""}catch(n){return{error:`cannot read the mxc SDK at ${r.dir}: ${n instanceof Error?n.message:n}`}}if(!O.test(t))return{error:`dal supports @microsoft/mxc-sdk 0.6.x, but ${r.dir} is version ${t||"(unknown)"}. Install @microsoft/mxc-sdk@0.6.0.`};const a=(e.arch??process.arch)==="arm64"?"arm64":"x64",s=d(r.dir,"bin",a,"wxc-exec.exe");if(!u(s))return{error:`the mxc SDK at ${r.dir} has no ${a} wxc-exec.exe.`};let i;try{i=w(import.meta.url)(d(r.dir,"dist","index.js"))}catch(n){return{error:`cannot load the mxc SDK at ${r.dir}: ${n instanceof Error?n.message:n}`}}return{sdkDir:r.dir,sdkVersion:t,wxcExec:s,api:i}}c(V,"loadMxcRuntime");function l(e){return e.replace(/\//g,"\\")}c(l,"toWindowsPath");function f(e){return e.length>0&&!/[\s"]/.test(e)?e:`"${e.replace(/(\\*)"/g,'$1$1\\"').replace(/(\\+)$/,"$1$1")}"`}c(f,"quoteWindowsArgument");function g(e){return`'${e.replace(/'/g,"''")}'`}c(g,"powershellQuote");function $(e){return`'${e.replace(/'/g,"'\\''")}'`}c($,"bashQuote");function T(e){const o=m.dirname(e),r=m.dirname(o);return m.basename(o).toLowerCase()==="bin"&&m.basename(r).toLowerCase()==="usr"?m.dirname(r):m.basename(o).toLowerCase()==="bin"?r:o}c(T,"shellInstallRoot");function E(e,o){const r=m.relative(o,e);return r===""||r!==".."&&!r.startsWith("..\\")&&!m.isAbsolute(r)}c(E,"isWithinWindows");function _(e){const o=c(n=>[...new Set(n.map(l))],"unique"),r=o([...e.rules.allowWrite,...e.tools.readwritePaths]),t=e.rules.denyWrite.filter(n=>!/[*?]/.test(n)&&e.exists(n)&&r.some(b=>E(l(n),b))),a=o([...e.tools.readonlyPaths,e.shellRoot,e.runDir,...e.level==="read-only"?[e.cwd]:[],...t]).filter(n=>!r.includes(n)),s=o(e.rules.denyRead.filter(n=>!/[*?]/.test(n)&&e.exists(n))),i=e.proxyPort!==void 0?{proxy:{localhost:e.proxyPort}}:{allowOutbound:!1,allowLocalNetwork:e.allowLocalNetwork};return{version:P,filesystem:{readwritePaths:r,readonlyPaths:a,deniedPaths:s},network:i,ui:{allowWindows:!0,clipboard:"none",allowInputInjection:!1}}}c(_,"windowsSandboxPolicy");function C(e,o){const r={};for(const[s,i]of Object.entries(e))typeof i=="string"&&(r[s]=i);const t=c((s,i)=>{for(const n of Object.keys(r))n.toLowerCase()===s.toLowerCase()&&delete r[n];r[s]=i},"set"),a=l(o.scratchDir);if(t("TMP",a),t("TEMP",a),t("TMPDIR",a),t("DAL_SANDBOX_RUN",o.runId),o.proxyPort!==void 0){const s=`http://127.0.0.1:${o.proxyPort}`;t("HTTP_PROXY",s),t("HTTPS_PROXY",s),r.http_proxy=s,r.https_proxy=s}return Object.entries(r).map(([s,i])=>`${s}=${i}`)}c(C,"windowsSandboxEnvironment");const R="try { [Console]::OutputEncoding=[System.Text.Encoding]::UTF8 } catch {}";function N(e,o,r,t){return e==="powershell"?{script:`${R}
|
|
2
|
+
${r}
|
|
3
3
|
if (-not $?) { if ($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } }
|
|
4
|
-
`,commandLine:[f(
|
|
5
|
-
`,commandLine:[f(
|
|
4
|
+
`,commandLine:[f(o),"-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",f(t)].join(" ")}:{script:`${r}
|
|
5
|
+
`,commandLine:[f(o),"--noprofile","--norc",f(t)].join(" ")}}c(N,"windowsInnerCommand");function W(e,o,r){if(e==="powershell")return`& ${g(l(o))} ${g(l(r))}; exit $LASTEXITCODE`;const t=c(a=>a.replace(/\\/g,"/"),"forward");return`${$(t(o))} ${$(t(r))}`}c(W,"windowsOuterCommand");function k(){return L("mxc")}c(k,"createRunDirectory");function B(e){const o=e.runDir??k(),r=c(()=>y(o),"cleanup");try{const t=d(o,e.kind==="powershell"?"command.ps1":"command.sh"),a=d(o,"config.json"),s=N(e.kind,l(e.shellPath),e.command,l(t)),i=_({level:e.level,cwd:e.cwd,rules:e.rules,tools:j(e.runtime.api.getAvailableToolsPolicy(e.env,{containerType:"processcontainer"}),e.runtime.api.getUserProfilePolicy()),shellRoot:T(l(e.shellPath)),runDir:l(o),...e.proxyPort!==void 0?{proxyPort:e.proxyPort}:{},allowLocalNetwork:e.allowLocalNetwork,exists:e.exists??u}),n=e.runtime.api.createConfigFromPolicy(i,"process",`dal-${e.runId}`);return n.process={...n.process??{commandLine:""},commandLine:s.commandLine,cwd:l(e.cwd),env:C(e.env,{scratchDir:e.scratchDir,runId:e.runId,...e.proxyPort!==void 0?{proxyPort:e.proxyPort}:{}})},p(t,s.script,{mode:384}),p(a,JSON.stringify(n),{mode:384}),{command:W(e.kind,e.runtime.wxcExec,a),configPath:a,config:n,cleanup:r}}catch(t){throw r(),t}}c(B,"prepareWindowsCommand");function j(...e){return{readonlyPaths:e.flatMap(o=>o.readonlyPaths??[]),readwritePaths:e.flatMap(o=>o.readwritePaths??[])}}c(j,"mergeFragments");function J(e){let o;try{o=e.api.getPlatformSupport()}catch(t){return{ok:!1,reason:`mxc could not check this machine: ${t instanceof Error?t.message:t}`}}if(!o.isSupported)return{ok:!1,reason:`mxc does not support this Windows installation: ${o.reason||"no reason given"}.`};if(!o.availableMethods.includes("processcontainer"))return{ok:!1,reason:`mxc's process container is not available here (available: ${o.availableMethods.join(", ")||"none"}).`};const r=k();try{const t=e.api.createConfigFromPolicy({version:P,filesystem:{readwritePaths:[],readonlyPaths:[],deniedPaths:[]},network:{allowOutbound:!1},ui:{allowWindows:!1,clipboard:"none",allowInputInjection:!1}},"process",`dal-probe-${process.pid}`);t.process={...t.process??{commandLine:""},commandLine:"cmd.exe /d /c exit 0"};const a=d(r,"config.json");p(a,JSON.stringify(t),{mode:384});const s=D(e.wxcExec,[a],{encoding:"utf8",timeout:3e4,windowsHide:!0});return s.status!==0?{ok:!1,reason:`mxc could not start a sandboxed process (${`${s.stderr??""}${s.stdout??""}`.trim()||s.error?.message||`exit code ${s.status}`}).`}:{ok:!0,support:o}}finally{y(r)}}c(J,"probeWindowsSandbox");export{P as MXC_POLICY_VERSION,x as MXC_SDK_DIR_ENV,q as WINDOWS_SANDBOX_LIMITATIONS,k as createRunDirectory,V as loadMxcRuntime,B as prepareWindowsCommand,J as probeWindowsSandbox,f as quoteWindowsArgument,H as setMxcRuntimeForTesting,T as shellInstallRoot,l as toWindowsPath,N as windowsInnerCommand,W as windowsOuterCommand,C as windowsSandboxEnvironment,_ as windowsSandboxPolicy};
|
|
@@ -139,6 +139,7 @@ export declare function sessionEntryToContextMessages(entry: SessionEntry): Agen
|
|
|
139
139
|
export declare function buildContextEntries(entries: SessionEntry[], leafId?: string | null, byId?: Map<string, SessionEntry>): SessionEntry[];
|
|
140
140
|
export declare function buildSessionProjection(entries: SessionEntry[], leafId?: string | null, byId?: Map<string, SessionEntry>): SessionProjection;
|
|
141
141
|
export declare function buildSessionContext(entries: SessionEntry[], leafId?: string | null, byId?: Map<string, SessionEntry>): SessionContext;
|
|
142
|
+
export declare function getDefaultSessionDirs(cwd: string, agentDir?: string): string[];
|
|
142
143
|
export declare function getDefaultSessionDir(cwd: string, agentDir?: string): string;
|
|
143
144
|
export declare function loadEntriesFromFile(filePath: string): FileEntry[];
|
|
144
145
|
export declare function findMostRecentSession(sessionDir: string, cwd?: string): string | null;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var
|
|
2
|
-
`);for(const
|
|
3
|
-
`,
|
|
4
|
-
`,
|
|
5
|
-
`),t)}c(
|
|
6
|
-
`,
|
|
7
|
-
`,
|
|
8
|
-
`).join(""))}isPersisted(){return this.persist}isReadOnly(){return this.newerFormat}getCwd(){return this.cwd}getSessionDir(){return this.sessionDir}usesDefaultSessionDir(){return this.
|
|
9
|
-
`);else{if(!this._hasConversation())return;const t=j(this.sessionFile,"wx");try{for(const
|
|
10
|
-
`)}finally{O(t)}this.flushed=!0}}_appendEntry(e){this.fileEntries.push(e),this.byId.set(e.id,e),this.leafId=e.id,this._persist(e)}appendMessage(e){const t={type:"message",id:S(this.byId),parentId:this.leafId,timestamp:new Date().toISOString(),message:e};return this._appendEntry(t),t.id}appendThinkingLevelChange(e){const t={type:"thinking_level_change",id:S(this.byId),parentId:this.leafId,timestamp:new Date().toISOString(),thinkingLevel:e};return this._appendEntry(t),t.id}appendModelChange(e,t){const
|
|
11
|
-
`,{flag:"wx"});for(const
|
|
12
|
-
`);return new
|
|
1
|
+
var we=Object.defineProperty;var c=(i,e)=>we(i,"name",{value:e,configurable:!0});import{getCurrentSystemMessage as Ee,uuidv7 as be}from"@earendil-works/pi-ai";import{randomUUID as G}from"crypto";import{appendFileSync as L,closeSync as O,createReadStream as _e,existsSync as x,mkdirSync as $,openSync as j,readdirSync as q,readSync as k,realpathSync as xe,statSync as P,writeFileSync as Q}from"fs";import{readdir as H,stat as ee}from"fs/promises";import{basename as te,join as C,resolve as se}from"path";import{createInterface as Ce}from"readline";import{StringDecoder as ne}from"string_decoder";import{APP_NAME as De,APP_TITLE as Fe,getAgentDir as U,getSessionsDir as Te}from"../config.js";import{fill as ve,t as Ne}from"../dal/i18n.js";import{normalizePath as _,resolvePath as b}from"../utils/paths.js";import{createBranchSummaryMessage as Ae,createCompactionSummaryMessage as Be,createCustomMessage as Me}from"./messages.js";import{reportNewerDataFormat as Re,writeFileAtomicSync as Le}from"./shared-data.js";const T=3;function ie(i){return typeof i?.version=="number"&&i.version>T}c(ie,"isNewerSessionFormat");function V(){return be()}c(V,"createSessionId");function re(i){if(!/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/.test(i))throw new Error("Session id must be non-empty, contain only alphanumeric characters, '-', '_', and '.', and start and end with an alphanumeric character")}c(re,"assertValidSessionId");function S(i){for(let e=0;e<100;e++){const t=G().slice(0,8);if(!i.has(t))return t}return G()}c(S,"generateId");function Oe(i){const e=new Set;let t=null;for(const s of i){if(s.type==="session"){s.version=2;continue}if(s.id=S(e),s.parentId=t,t=s.id,s.type==="compaction"){const n=s;if(typeof n.firstKeptEntryIndex=="number"){const r=i[n.firstKeptEntryIndex];r&&r.type!=="session"&&(n.firstKeptEntryId=r.id),delete n.firstKeptEntryIndex}}}}c(Oe,"migrateV1ToV2");function $e(i){for(const e of i){if(e.type==="session"){e.version=3;continue}if(e.type==="message"){const t=e;t.message&&t.message.role==="hookMessage"&&(t.message.role="custom")}}}c($e,"migrateV2ToV3");function oe(i){const t=i.find(s=>s.type==="session")?.version??1;return t>=T?!1:(t<2&&Oe(i),t<3&&$e(i),!0)}c(oe,"migrateToCurrentVersion");function ct(i){oe(i)}c(ct,"migrateSessionEntries");function ft(i){const e=[],t=i.trim().split(`
|
|
2
|
+
`);for(const s of t)if(s.trim())try{const n=JSON.parse(s);e.push(n)}catch{}return e}c(ft,"parseSessionEntries");function ut(i){for(let e=i.length-1;e>=0;e--)if(i[e].type==="compaction")return i[e];return null}c(ut,"getLatestCompactionEntry");function je(i,e){if(e)return e;const t=new Map;for(const s of i)t.set(s.id,s);return t}c(je,"buildEntryIndex");function ae(i,e,t){const s=je(i,t);let n;if(e===null)return[];if(e&&(n=s.get(e)),n??=i[i.length-1],!n)return[];const r=[];let o=n;for(;o;)r.push(o),o=o.parentId?s.get(o.parentId):void 0;return r.reverse(),r}c(ae,"buildSessionPath");function ke(i){let e="off",t=null;for(const s of i)s.type==="thinking_level_change"?e=s.thinkingLevel:s.type==="model_change"?t={provider:s.provider,modelId:s.modelId}:s.type==="message"&&s.message.role==="assistant"&&(t={provider:s.message.provider,modelId:s.message.model});return{thinkingLevel:e,model:t}}c(ke,"getSessionContextSettings");function Pe(i){if(i.type==="message"){const e=i.message;return e.role==="system"&&e.content==null?[{...e,content:""}]:(e.role==="user"||e.role==="assistant"||e.role==="toolResult")&&e.content==null?[{...e,content:[]}]:[e]}if(i.type==="custom_message")return[Me(i.customType,i.content??[],i.display,i.details,i.timestamp)];if(i.type==="branch_summary"&&i.summary)return[Ae(i.summary,i.fromId,i.timestamp)];if(i.type==="compaction"){const e=Be(i.summary,i.tokensBefore,i.timestamp);return i.systemMessage?[i.systemMessage,e]:[e]}return[]}c(Pe,"sessionEntryToContextMessages");function le(i,e,t){const s=ae(i,e,t);let n=null;for(const d of s)d.type==="compaction"&&(n=d);if(!n)return s;const r=s.findIndex(d=>d.id===n.id);if(r<0)return s;const o=[n];let a=!1;for(let d=0;d<r;d++){const l=s[d];l.id===n.firstKeptEntryId&&(a=!0),a&&!(l.type==="message"&&l.message.role==="system")&&o.push(l)}return o.push(...s.slice(r+1)),o}c(le,"buildContextEntries");function He(i,e){const t=Pe(i);if(!e)return t;const s=e.replacement;return s===null?[]:t.map(n=>{if(n.role!=="user"&&n.role!=="assistant"&&n.role!=="toolResult"&&n.role!=="custom")return n;const r=(n.role==="assistant"||n.role==="toolResult")&&typeof s.content=="string"?[{type:"text",text:s.content}]:s.content;return{...n,content:r}})}c(He,"projectContextEntry");function de(i,e,t){const s=ae(i,e,t),{thinkingLevel:n,model:r}=ke(s),o=le(i,e,t),a=new Map;for(const l of o)l.type==="context_edit"&&a.set(l.targetId,l);const d=o.map((l,f)=>({sourceEntry:l,messages:l.type==="compaction"&&f>0?[]:He(l,a.get(l.id))}));return{entries:d,messages:d.flatMap(l=>l.messages),thinkingLevel:n,model:r}}c(de,"buildSessionProjection");function pt(i,e,t){const{messages:s,thinkingLevel:n,model:r}=de(i,e,t);return{messages:s,thinkingLevel:n,model:r}}c(pt,"buildSessionContext");function ce(i,e){const t=`--${i.replace(/^[/\\]/,"").replace(/[/\\:]/g,"-")}--`;return C(b(e),"sessions",t)}c(ce,"sessionDirFor");function Ue(i){const e=b(i);try{return xe.native(e)}catch{return e}}c(Ue,"realCwd");function fe(i,e=U()){return ce(Ue(i),e)}c(fe,"getDefaultSessionDirPath");function A(i,e=U()){const t=fe(i,e),s=ce(b(i),e);return s!==t&&x(s)?[t,s]:[t]}c(A,"getDefaultSessionDirs");function v(i,e=U()){const t=fe(i,e);return x(t)||$(t,{recursive:!0}),t}c(v,"getDefaultSessionDir");const Ve=1024*1024,Ke=4096,K=1024*1024;class ue extends Error{static{c(this,"SessionHeaderScanLimitError")}constructor(e){super(`Session header exceeds ${K}-byte scan limit: ${e}`),this.name="SessionHeaderScanLimitError"}}function B(i){if(!i.trim())return null;try{return JSON.parse(i)}catch{return null}}c(B,"parseSessionEntryLine");function W(i){const e=_(i);if(!x(e))return[];const t=[];let s="";const n=j(e,"r");try{const o=new ne("utf8"),a=Buffer.allocUnsafe(Ve);for(;;){const l=k(n,a,0,a.length,null);if(l===0)break;s+=o.write(a.subarray(0,l));let f=0,h=s.indexOf(`
|
|
3
|
+
`,f);for(;h!==-1;){const m=B(s.slice(f,h));m&&t.push(m),f=h+1,h=s.indexOf(`
|
|
4
|
+
`,f)}s=s.slice(f)}s+=o.end();const d=B(s);d&&t.push(d)}finally{O(n)}if(t.length===0)return t;const r=t[0];return r.type!=="session"||typeof r.id!="string"?[]:(s&&L(e,`
|
|
5
|
+
`),t)}c(W,"loadEntriesFromFile");function z(i){if(!i.trim())return;const e=B(i);if(e)return e.type!=="session"||typeof e.id!="string"?null:e}c(z,"parseSessionHeaderCandidate");function pe(i){const e=j(i,"r");try{const t=new ne("utf8"),s=Buffer.allocUnsafe(Ke),n=[];let r=0;for(;r<K;){const a=Math.min(s.length,K-r),d=k(e,s,0,a,null);if(d===0)return n.push(t.end()),z(n.join(""))??null;r+=d;const l=t.write(s.subarray(0,d));let f=0,h=l.indexOf(`
|
|
6
|
+
`,f);for(;h!==-1;){n.push(l.slice(f,h));const m=z(n.join(""));if(m!==void 0)return m;n.length=0,f=h+1,h=l.indexOf(`
|
|
7
|
+
`,f)}n.push(l.slice(f))}const o=Buffer.allocUnsafe(1);if(k(e,o,0,o.length,null)===0)return n.push(t.end()),z(n.join(""))??null;throw new ue(i)}finally{O(e)}}c(pe,"readSessionHeader");function he(i){try{return pe(i)}catch{return null}}c(he,"readSessionHeaderForDiscovery");function J(i){const e=i.cwd;return typeof e=="string"?e:void 0}c(J,"getSessionHeaderCwd");function Z(i,e){return i!==void 0&&i!==""&&b(i)===e}c(Z,"sessionCwdMatches");function me(i,e){const t=_(i),s=e?b(e):void 0;try{const n=q(t).filter(r=>r.endsWith(".jsonl")).map(r=>C(t,r)).map(r=>({path:r,mtime:P(r).mtimeMs})).sort((r,o)=>o.mtime-r.mtime);for(const{path:r}of n){const o=he(r);if(o&&(!s||Z(J(o),s)))return r}return null}catch{return null}}c(me,"findMostRecentSession");function ye(i){return typeof i.role=="string"&&"content"in i}c(ye,"isMessageWithContent");function We(i){const e=i.content;return typeof e=="string"?e:e.filter(t=>t.type==="text").map(t=>t.text).join(" ")}c(We,"extractTextContent");function ze(i){const e=i.message;if(!ye(e)||e.role!=="user"&&e.role!=="assistant")return;const t=e.timestamp;if(typeof t=="number")return t;const s=new Date(i.timestamp).getTime();return Number.isNaN(s)?void 0:s}c(ze,"getMessageActivityTime");async function Je(i,e,t){try{const s=t??await ee(i);let n=null,r=0,o="";const a=[];let d,l;const f=Ce({input:_e(i,{encoding:"utf8",signal:e}),crlfDelay:1/0});for await(const E of f){const g=B(E);if(!g)continue;if(!n){if(g.type!=="session")return null;n=g;continue}if(g.type==="session_info"&&(d=g.name?.trim()||void 0),g.type!=="message")continue;r++;const p=ze(g);typeof p=="number"&&(l=Math.max(l??0,p));const u=g.message;if(!ye(u)||u.role!=="user"&&u.role!=="assistant")continue;const I=We(u);I&&(a.push(I),!o&&u.role==="user"&&(o=I))}if(!n)return null;const h=typeof n.cwd=="string"?n.cwd:"",m=n.parentSession,y=typeof n.timestamp=="string"?new Date(n.timestamp).getTime():NaN,w=typeof l=="number"&&l>0?new Date(l):Number.isNaN(y)?s.mtime:new Date(y);return{path:i,id:n.id,cwd:h,name:d,parentSessionPath:m,created:new Date(n.timestamp),modified:w,messageCount:r,firstMessage:o||"(no messages)",allMessagesText:a.join(" ")}}catch{return e?.throwIfAborted(),null}}c(Je,"buildSessionInfo");const Ze=10,Ie=64,Ye=10,Xe=100;async function Y(i,e,t,s){const n=new Array(i.length);let r=0;const o=c(async()=>{for(;r<i.length;){s?.throwIfAborted();const a=r++;n[a]=await t(i[a],a)}},"worker");return await Promise.all(Array.from({length:Math.min(e,i.length)},()=>o())),n}c(Y,"mapWithConcurrency");function N(i){return i.sort((e,t)=>t.modified.getTime()-e.modified.getTime())}c(N,"sortSessionInfos");function ge(i,e,t){return Y(i,Ze,async(s,n)=>{const r=await Je(s.path,t,s.stats);return e(r,n),r},t)}c(ge,"buildSessionInfosWithConcurrency");async function X(i,e,t){if(t?.throwIfAborted(),!x(i))return[];try{const n=(await H(i)).filter(l=>l.endsWith(".jsonl")).sort((l,f)=>f.localeCompare(l)).map(l=>({path:C(i,l)})),r=n.length,o=[];let a=0;return(await ge(n,l=>{a++,l&&o.push(l);const f=a===1||a%Ye===0||a===n.length;e?.(a,r,f?N([...o]):void 0)},t)).filter(l=>l!==null)}catch{return t?.throwIfAborted(),[]}}c(X,"listSessionsFromDir");class D{static{c(this,"SessionManager")}sessionId="";sessionFile;sessionDir;cwd;persist;flushed=!1;newerFormat=!1;fileEntries=[];byId=new Map;labelsById=new Map;labelTimestampsById=new Map;leafId=null;constructor(e,t,s,n,r,o){this.cwd=b(e),this.sessionDir=_(t),this.persist=n,n&&this.sessionDir&&!x(this.sessionDir)&&$(this.sessionDir,{recursive:!0}),s?this._setSessionFile(s,o):o?.length?this._loadEntries(o,r):this.newSession(r)}setSessionFile(e){this._setSessionFile(e)}_setSessionFile(e,t){if(this.sessionFile=b(e),x(this.sessionFile)){const s=t??W(this.sessionFile);if(s.length===0){const n=this.sessionFile;if(P(n).size>0)throw new Error(`Session file is not a valid ${De} session: ${n}`);this.newSession(),this.sessionFile=n,this._rewriteFile(),this.flushed=!0;return}this._loadEntries(s),this.flushed=!0}else{const s=this.sessionFile;this.newSession(),this.sessionFile=s}}newSession(e){e?.id!==void 0&&re(e.id),this.sessionId=e?.id??V();const t=new Date().toISOString(),s={type:"session",version:T,id:this.sessionId,timestamp:t,cwd:this.cwd,parentSession:e?.parentSession};if(this.fileEntries=[s],this.newerFormat=!1,this.byId.clear(),this.labelsById.clear(),this.labelTimestampsById.clear(),this.leafId=null,this.flushed=!1,this.persist){const n=t.replace(/[:.]/g,"-");this.sessionFile=C(this.getSessionDir(),`${n}_${this.sessionId}.jsonl`)}return this.sessionFile}_loadEntries(e,t){const s=e.find(n=>n.type==="session");s?(this.fileEntries=e,this.sessionId=s.id,this.newerFormat=ie(s),this.newerFormat?Re(this.sessionFile??s.id):oe(this.fileEntries)&&this._rewriteFile()):(this.newSession(t),this.fileEntries=this.fileEntries.concat(e)),this._buildIndex()}_buildIndex(){this.byId.clear(),this.labelsById.clear(),this.labelTimestampsById.clear(),this.leafId=null;for(const e of this.fileEntries)e.type!=="session"&&(this.byId.set(e.id,e),this.leafId=e.id,e.type==="label"&&(e.label?(this.labelsById.set(e.targetId,e.label),this.labelTimestampsById.set(e.targetId,e.timestamp)):(this.labelsById.delete(e.targetId),this.labelTimestampsById.delete(e.targetId))))}_rewriteFile(){!this.persist||!this.sessionFile||this.newerFormat||Le(this.sessionFile,this.fileEntries.map(e=>`${JSON.stringify(e)}
|
|
8
|
+
`).join(""))}isPersisted(){return this.persist}isReadOnly(){return this.newerFormat}getCwd(){return this.cwd}getSessionDir(){return this.sessionDir}usesDefaultSessionDir(){return A(this.cwd).includes(this.sessionDir)}getSessionId(){return this.sessionId}getSessionFile(){return this.sessionFile}_hasConversation(){return this.fileEntries.some(e=>e.type==="message"&&(e.message.role==="user"||e.message.role==="assistant"))}_persist(e){if(!(!this.persist||!this.sessionFile||this.newerFormat))if(this.flushed)L(this.sessionFile,`${JSON.stringify(e)}
|
|
9
|
+
`);else{if(!this._hasConversation())return;const t=j(this.sessionFile,"wx");try{for(const s of this.fileEntries)Q(t,`${JSON.stringify(s)}
|
|
10
|
+
`)}finally{O(t)}this.flushed=!0}}_appendEntry(e){this.fileEntries.push(e),this.byId.set(e.id,e),this.leafId=e.id,this._persist(e)}appendMessage(e){const t={type:"message",id:S(this.byId),parentId:this.leafId,timestamp:new Date().toISOString(),message:e};return this._appendEntry(t),t.id}appendThinkingLevelChange(e){const t={type:"thinking_level_change",id:S(this.byId),parentId:this.leafId,timestamp:new Date().toISOString(),thinkingLevel:e};return this._appendEntry(t),t.id}appendModelChange(e,t){const s={type:"model_change",id:S(this.byId),parentId:this.leafId,timestamp:new Date().toISOString(),provider:e,modelId:t};return this._appendEntry(s),s.id}appendUsage(e,t,s,n,r){const o={type:"usage",id:S(this.byId),parentId:this.leafId,timestamp:new Date().toISOString(),kind:e,provider:t,model:s,usage:n,...r?{note:r}:{}};return this._appendEntry(o),o}appendCompaction(e,t,s,n,r,o){const a=new Date().toISOString(),d=Ee(this.buildSessionProjection().messages),l=S(this.byId),f={type:"compaction",id:l,parentId:this.leafId,timestamp:a,summary:e,firstKeptEntryId:t??l,tokensBefore:s,details:n,usage:o,fromHook:r,...d?{systemMessage:{...d,timestamp:new Date(a).getTime()}}:{}};return this._appendEntry(f),f.id}appendCustomEntry(e,t){const s={type:"custom",customType:e,data:t,id:S(this.byId),parentId:this.leafId,timestamp:new Date().toISOString()};return this._appendEntry(s),s.id}appendSessionInfo(e){const t=e.replace(/[\r\n]+/g," ").trim(),s={type:"session_info",id:S(this.byId),parentId:this.leafId,timestamp:new Date().toISOString(),name:t};return this._appendEntry(s),s.id}getSessionName(){for(let e=this.fileEntries.length-1;e>=0;e--){const t=this.fileEntries[e];if(t.type==="session_info")return t.name?.trim()||void 0}}appendCustomMessageEntry(e,t,s,n){const r={type:"custom_message",customType:e,content:t,display:s,details:n,id:S(this.byId),parentId:this.leafId,timestamp:new Date().toISOString()};return this._appendEntry(r),r.id}appendContextEdit(e,t){if(t!==null&&(typeof t!="object"||!("content"in t)||typeof t.content!="string"&&!Array.isArray(t.content)))throw new Error("Context edit replacement must be null or contain string/array content");const s=this.byId.get(e);if(!s)throw new Error(`Entry ${e} not found`);if(!this.getBranch().some(d=>d.id===e))throw new Error(`Entry ${e} is not on the active branch`);if(!(s.type==="custom_message"||s.type==="message"&&(s.message.role==="user"||s.message.role==="assistant"||s.message.role==="toolResult")))throw new Error(`Entry ${e} does not contribute editable model content`);const r=s.type==="message"?s.message.role:"custom",o=t!==null&&(r==="assistant"||r==="toolResult")&&typeof t.content=="string"?{content:[{type:"text",text:t.content}]}:t,a={type:"context_edit",id:S(this.byId),parentId:this.leafId,timestamp:new Date().toISOString(),targetId:e,replacement:o};return this._appendEntry(a),a.id}getLeafId(){return this.leafId}getLeafEntry(){return this.leafId?this.byId.get(this.leafId):void 0}getEntry(e){return this.byId.get(e)}getChildren(e){const t=[];for(const s of this.byId.values())s.parentId===e&&t.push(s);return t}getLabel(e){return this.labelsById.get(e)}appendLabelChange(e,t){if(!this.byId.has(e))throw new Error(`Entry ${e} not found`);const s={type:"label",id:S(this.byId),parentId:this.leafId,timestamp:new Date().toISOString(),targetId:e,label:t};return this._appendEntry(s),t?(this.labelsById.set(e,t),this.labelTimestampsById.set(e,s.timestamp)):(this.labelsById.delete(e),this.labelTimestampsById.delete(e)),s.id}getBranch(e){const t=[],s=e??this.leafId;let n=s?this.byId.get(s):void 0;for(;n;)t.push(n),n=n.parentId?this.byId.get(n.parentId):void 0;return t.reverse(),t}buildContextEntries(){return le(this.getEntries(),this.leafId,this.byId)}buildSessionProjection(){return de(this.getEntries(),this.leafId,this.byId)}buildSessionContext(){const{messages:e,thinkingLevel:t,model:s}=this.buildSessionProjection();return{messages:e,thinkingLevel:t,model:s}}getHeader(){const e=this.fileEntries.find(t=>t.type==="session");return e||null}getEntryCount(){return this.byId.size}getEntries(){return this.fileEntries.filter(e=>e.type!=="session")}getTree(){const e=this.getEntries(),t=new Map,s=[];for(const r of e){const o=this.labelsById.get(r.id),a=this.labelTimestampsById.get(r.id);t.set(r.id,{entry:r,children:[],label:o,labelTimestamp:a})}for(const r of e){const o=t.get(r.id);if(r.parentId===null||r.parentId===r.id)s.push(o);else{const a=t.get(r.parentId);a?a.children.push(o):s.push(o)}}const n=[...s];for(;n.length>0;){const r=n.pop();r.children.sort((o,a)=>new Date(o.entry.timestamp).getTime()-new Date(a.entry.timestamp).getTime()),n.push(...r.children)}return s}branch(e){if(!this.byId.has(e))throw new Error(`Entry ${e} not found`);this.leafId=e}resetLeaf(){this.leafId=null}branchWithSummary(e,t,s,n,r){if(e!==null&&!this.byId.has(e))throw new Error(`Entry ${e} not found`);const o=this.leafId??"root";this.leafId=e;const a={type:"branch_summary",id:S(this.byId),parentId:e,timestamp:new Date().toISOString(),fromId:o,summary:t,details:s,usage:r,fromHook:n};return this._appendEntry(a),a.id}createBranchedSession(e){const t=this.sessionFile,s=this.getBranch(e);if(s.length===0)throw new Error(`Entry ${e} not found`);const n=[],r=new Map,o=[];let a=null;for(const p of s){if(p.type==="label"){o.push(p.id);continue}for(const u of o)r.set(u,p.id);o.length=0,n.push(p.type==="compaction"?{...p,parentId:a,firstKeptEntryId:p.firstKeptEntryId===p.id?p.id:r.get(p.firstKeptEntryId)??p.firstKeptEntryId}:{...p,parentId:a}),a=p.id}const d=V(),l=new Date().toISOString(),f=l.replace(/[:.]/g,"-"),h=C(this.getSessionDir(),`${f}_${d}.jsonl`),m={type:"session",version:T,id:d,timestamp:l,cwd:this.cwd,parentSession:this.persist?t:void 0},y=new Set(n.map(p=>p.id)),w=[];for(const[p,u]of this.labelsById)y.has(p)&&w.push({targetId:p,label:u,timestamp:this.labelTimestampsById.get(p)});if(this.persist){let u=n[n.length-1]?.id||null;const I=[];for(const{targetId:F,label:M,timestamp:Se}of w){const R={type:"label",id:S(new Set(y)),parentId:u,timestamp:Se,targetId:F,label:M};y.add(R.id),I.push(R),u=R.id}return this.fileEntries=[m,...n,...I],this.sessionId=d,this.sessionFile=h,this._buildIndex(),this._hasConversation()?(this._rewriteFile(),this.flushed=!0):this.flushed=!1,h}const E=[];let g=n[n.length-1]?.id||null;for(const{targetId:p,label:u,timestamp:I}of w){const F={type:"label",id:S(new Set([...y,...E.map(M=>M.id)])),parentId:g,timestamp:I,targetId:p,label:u};E.push(F),g=F.id}this.fileEntries=[m,...n,...E],this.sessionId=d,this._buildIndex()}static create(e,t,s){const n=t?_(t):v(e);return new D(e,n,void 0,!0,s)}static open(e,t,s){const n=b(e);let r=null,o;if(s===void 0&&x(n))try{r=pe(n)}catch(l){if(!(l instanceof ue))throw l;o=W(n);const f=o[0];r=f?.type==="session"?f:null}const a=s??(r?J(r):void 0)??process.cwd(),d=t?_(t):se(n,"..");return new D(a,d,n,!0,void 0,o)}static continueRecent(e,t){const s=t?_(t):v(e),n=A(e);if(n.includes(s)){const o=n.map(a=>me(a)).filter(a=>a!==null).map(a=>({path:a,mtime:P(a).mtimeMs})).sort((a,d)=>d.mtime-a.mtime)[0];return o?new D(e,se(o.path,".."),o.path,!0):new D(e,n[0],void 0,!0)}const r=me(s,e);return r?new D(e,s,r,!0):new D(e,s,void 0,!0)}static inMemory(e=process.cwd(),t,s){return new D(e,"",void 0,!1,t,s)}static forkFrom(e,t,s,n){const r=b(e),o=b(t),a=W(r);if(a.length===0)throw new Error(`Cannot fork: source session file is empty or invalid: ${r}`);const d=a.find(E=>E.type==="session");if(!d)throw new Error(`Cannot fork: source session has no header: ${r}`);if(ie(d))throw new Error(ve(Ne("{path} \u7531\u66F4\u65B0\u7248\u672C\u7684 {app} \u5199\u5165\uFF0C\u5F53\u524D\u7248\u672C\u53EA\u8BFB\uFF0C\u4E0D\u4F1A\u6539\u52A8\u5B83\uFF1B\u8BF7\u5347\u7EA7 {app}\u3002"),{path:r,app:Fe}));const l=s?_(s):v(o);x(l)||$(l,{recursive:!0}),n?.id!==void 0&&re(n.id);const f=n?.id??V(),h=new Date().toISOString(),m=h.replace(/[:.]/g,"-"),y=C(l,`${m}_${f}.jsonl`);Q(y,`${JSON.stringify({type:"session",version:T,id:f,timestamp:h,cwd:o,parentSession:r})}
|
|
11
|
+
`,{flag:"wx"});for(const E of a)E.type!=="session"&&L(y,`${JSON.stringify(E)}
|
|
12
|
+
`);return new D(o,l,y,!0)}static findById(e,t,s){const n=s?_(s):v(e),r=A(e),o=!r.includes(n),a=o?[n]:r,d=b(e);for(const l of a)try{for(const f of q(l)){if(!f.endsWith(".jsonl"))continue;const h=C(l,f),m=he(h);if(m?.id===t&&!(o&&!Z(J(m),d)))return h}}catch{}}static async list(e,t,s,n){const r=A(e),o=t?_(t):v(e),a=!r.includes(o),d=b(e),l=c(m=>!a||Z(m.cwd,d),"includeSession"),h=(await X(o,s?(m,y,w)=>s(m,y,w?.filter(l)):void 0,n)).filter(l);if(!a)for(const m of r.filter(y=>y!==o))h.push(...await X(m,void 0,n));return N(h)}static async listAll(e,t,s){const n=typeof e=="string"?_(e):void 0,r=typeof e=="function"?e:typeof t=="function"?t:void 0,o=typeof e=="string"||typeof t=="function"?s:t??s;if(o?.throwIfAborted(),n)return N(await X(n,r,o));const a=Te();try{if(!x(a))return[];const l=(await H(a,{withFileTypes:!0})).filter(u=>u.isDirectory()||u.isSymbolicLink()).map(u=>C(a,u.name)),h=(await Y(l,Ie,async u=>{try{return(await H(u)).filter(I=>I.endsWith(".jsonl")).map(I=>C(u,I))}catch{return[]}},o)).flat(),m=await Y(h,Ie,async u=>{try{return{path:u,stats:await ee(u)}}catch{return{path:u}}},o);m.sort((u,I)=>(I.stats?.mtimeMs??Number.NEGATIVE_INFINITY)-(u.stats?.mtimeMs??Number.NEGATIVE_INFINITY)||te(I.path).localeCompare(te(u.path)));const y=m.length;let w=0,E=!1;const g=[],p=await ge(m,(u,I)=>{w++,I===0&&(E=!0),u&&g.push(u);const F=E&&(I===0||w%Xe===0||w===y);r?.(w,y,F?N([...g]):void 0)},o);return N(p.filter(u=>u!==null))}catch{return o?.throwIfAborted(),[]}}}export{T as CURRENT_SESSION_VERSION,D as SessionManager,re as assertValidSessionId,le as buildContextEntries,pt as buildSessionContext,de as buildSessionProjection,me as findMostRecentSession,v as getDefaultSessionDir,A as getDefaultSessionDirs,ut as getLatestCompactionEntry,ie as isNewerSessionFormat,W as loadEntriesFromFile,ct as migrateSessionEntries,ft as parseSessionEntries,Pe as sessionEntryToContextMessages};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{DEFAULT_MAX_AGENT_RETRY_DELAY_MS as e}from"@earendil-works/pi-ai/utils/retry";const t={transport:"auto",sessionShareDestination:"auto",steeringMode:"one-at-a-time",followUpMode:"one-at-a-time",compaction:{enabled:!0,reserveTokens:16384,keepRecentTokens:2e4},branchSummary:{reserveTokens:16384,skipPrompt:!1},retry:{enabled:!0,maxRetries:3,baseDelayMs:2e3,maxAgentDelayMs:e,provider:{maxRetryDelayMs:6e4}},hideThinkingBlock:!1,showCacheMissNotices:!1,quietStartup:!1,defaultProjectTrust:"ask",collapseChangelog:!1,enableInstallTelemetry:!0,enableAnalytics:!1,enableSkillCommands:!0,terminal:{showImages:!0,imageWidthCells:60,clearOnShrink:!1,showTerminalProgress:!1},images:{autoResize:!0,blockImages:!1},doubleEscapeAction:"tree",treeFilterMode:"default",editorPaddingX:0,outputPad:1,autocompleteMaxVisible:5,markdown:{codeBlockIndent:" ",mermaid:"streaming"},warnings:{anthropicExtraUsage:!0},codemode:{mode:"on",inlineBudget:3e3},cacheWarming:"streaming",tuiMode:"fullscreen",fullscreenExitOutput:"transcript",fullscreenScrollbar:"auto",fullscreenCopyOnSelect:!0,fullscreenWheelScrollLines:"auto"};export{t as SETTINGS_DEFAULTS};
|