dal-code 1.0.45 → 1.0.47
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 +83 -0
- package/NOTICE +49 -1
- package/PRIVACY.md +18 -11
- package/dal-docs/extensions.md +16 -4
- package/dist/cli/args.js +2 -2
- package/dist/cli/auth-check.js +1 -1
- package/dist/cli/auth-command.js +6 -5
- package/dist/cli/list-models.js +2 -2
- package/dist/cli/piped-stdin.js +2 -0
- package/dist/cli/startup-diagnostics.js +1 -0
- package/dist/core/agent-log.d.ts +6 -0
- package/dist/core/agent-log.js +3 -0
- package/dist/core/agent-session-services.d.ts +0 -1
- package/dist/core/agent-session-services.js +1 -1
- package/dist/core/agent-session.d.ts +19 -2
- package/dist/core/agent-session.js +8 -8
- package/dist/core/client-identity.js +1 -0
- package/dist/core/compaction/branch-summarization.js +3 -3
- package/dist/core/compaction/compaction.d.ts +2 -2
- package/dist/core/compaction/compaction.js +11 -9
- package/dist/core/compaction-backoff.js +1 -0
- package/dist/core/dal-session-headers.js +1 -0
- package/dist/core/export-html/index.js +2 -2
- package/dist/core/export-html/template.html +1 -0
- package/dist/core/export-html/template.js +6 -6
- package/dist/core/export-html/vendor/marked-cjk-friendly.min.js +6 -0
- package/dist/core/export-html/vendor/marked.min.js +30 -29
- package/dist/core/extensions/engine-specifiers.js +1 -0
- package/dist/core/extensions/errors.d.ts +12 -0
- package/dist/core/extensions/errors.js +1 -0
- package/dist/core/extensions/index.d.ts +1 -0
- package/dist/core/extensions/index.js +1 -1
- package/dist/core/extensions/loader.js +1 -1
- package/dist/core/extensions/runner.d.ts +7 -1
- package/dist/core/extensions/runner.js +1 -1
- package/dist/core/extensions/types.d.ts +4 -0
- package/dist/core/extensions/virtual-modules.js +1 -1
- package/dist/core/http-dispatcher.js +1 -1
- package/dist/core/model-config.d.ts +984 -0
- package/dist/core/model-config.js +5 -5
- package/dist/core/model-identity.js +2 -0
- package/dist/core/model-resolver.js +1 -1
- package/dist/core/model-runtime.d.ts +2 -0
- package/dist/core/model-runtime.js +2 -2
- package/dist/core/package-manager.d.ts +2 -0
- package/dist/core/package-manager.js +2 -2
- package/dist/core/provider-composer.d.ts +2 -1
- package/dist/core/provider-composer.js +1 -1
- package/dist/core/sandbox/bwrap-placeholders.js +1 -1
- package/dist/core/sandbox/index.d.ts +1 -1
- package/dist/core/sandbox/index.js +1 -1
- package/dist/core/sandbox/policy.d.ts +4 -0
- package/dist/core/sandbox/policy.js +1 -1
- package/dist/core/sandbox/runtime.d.ts +2 -0
- package/dist/core/sandbox/runtime.js +1 -1
- package/dist/core/sandbox/shell-sandbox.d.ts +2 -0
- package/dist/core/sandbox/shell-sandbox.js +6 -6
- package/dist/core/sdk.js +1 -1
- package/dist/core/session-stall-monitor.d.ts +41 -0
- package/dist/core/session-stall-monitor.js +2 -0
- package/dist/core/settings-manager.d.ts +4 -0
- package/dist/core/settings-manager.js +1 -1
- package/dist/core/settings-schema.d.ts +2 -0
- package/dist/core/settings-schema.js +1 -1
- package/dist/core/stall-watchdog.d.ts +55 -0
- package/dist/core/stall-watchdog.js +1 -0
- package/dist/core/system-prompt.js +10 -10
- package/dist/core/tools/bash.d.ts +1 -0
- package/dist/core/tools/bash.js +14 -14
- package/dist/core/tools/edit.d.ts +1 -1
- package/dist/core/tools/edit.js +3 -3
- package/dist/core/tools/grep.js +1 -1
- package/dist/core/tools/path-utils.d.ts +1 -0
- package/dist/core/tools/path-utils.js +1 -1
- package/dist/dal/builtins.js +2 -2
- package/dist/dal/manifest.d.ts +1 -0
- package/dist/dal/manifest.js +1 -1
- package/dist/dal/safety-net.js +3 -1
- package/dist/extensions/codemode/execute.js +22 -16
- package/dist/extensions/mcp/config.js +2 -2
- package/dist/extensions/mcp/oauth.js +2 -2
- package/dist/index.d.ts +5 -4
- package/dist/index.js +1 -1
- package/dist/main.js +4 -4
- package/dist/migrations.js +3 -5
- package/dist/modes/index.d.ts +2 -2
- package/dist/modes/index.js +1 -1
- package/dist/modes/interactive/external-editor.js +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +7 -7
- package/dist/modes/interactive/interactive-mode.js +25 -25
- package/dist/modes/interactive/session-share.js +1 -1
- package/dist/modes/print-mode.d.ts +1 -0
- package/dist/modes/print-mode.js +8 -7
- package/dist/modes/rpc/rpc-client.d.ts +13 -1
- package/dist/modes/rpc/rpc-client.js +3 -3
- package/dist/modes/rpc/rpc-mode.js +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +14 -0
- package/dist/node_modules/@dalcode/dal-advisor/package.json +3 -3
- 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-capabilities/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-capabilities/src/catalogue.js +1 -1
- package/dist/node_modules/@dalcode/dal-capabilities/src/index.js +10 -10
- package/dist/node_modules/@dalcode/dal-capabilities/src/match.js +1 -1
- package/dist/node_modules/@dalcode/dal-capabilities/src/state.js +3 -3
- package/dist/node_modules/@dalcode/dal-codeindex/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-codeindex/src/index.js +4 -4
- 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-dap/src/install.js +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 +5 -4
- package/dist/node_modules/@dalcode/dal-guard/src/credentials.js +7 -1
- package/dist/node_modules/@dalcode/dal-guard/src/edit-anchor-core.js +25 -23
- package/dist/node_modules/@dalcode/dal-guard/src/edit-anchor.js +4 -4
- package/dist/node_modules/@dalcode/dal-guard/src/index.js +4 -4
- package/dist/node_modules/@dalcode/dal-guard/src/policy.js +1 -1
- package/dist/node_modules/@dalcode/dal-guard/src/session-files.js +1 -0
- package/dist/node_modules/@dalcode/dal-guard/src/suspicion.js +1 -0
- package/dist/node_modules/@dalcode/dal-guard/src/workspace.js +2 -2
- 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 +4 -2
- package/dist/node_modules/@dalcode/dal-learn/src/engine.js +4 -4
- package/dist/node_modules/@dalcode/dal-learn/src/index.js +15 -14
- package/dist/node_modules/@dalcode/dal-learn/src/revisions.js +3 -0
- package/dist/node_modules/@dalcode/dal-learn/src/safety.js +1 -1
- package/dist/node_modules/@dalcode/dal-learn/src/skill-evolution.js +14 -14
- package/dist/node_modules/@dalcode/dal-lsp/package.json +5 -3
- package/dist/node_modules/@dalcode/dal-lsp/src/config.js +1 -1
- package/dist/node_modules/@dalcode/dal-lsp/src/index.js +14 -13
- package/dist/node_modules/@dalcode/dal-lsp/src/managed.js +1 -0
- package/dist/node_modules/@dalcode/dal-mcp/package.json +7 -6
- package/dist/node_modules/@dalcode/dal-mcp/src/child-env.js +3 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.d.ts +1 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.js +3 -3
- package/dist/node_modules/@dalcode/dal-office/package.json +3 -2
- package/dist/node_modules/@dalcode/dal-office/src/extract/cell.js +1 -0
- package/dist/node_modules/@dalcode/dal-office/src/extract/index.js +2 -2
- package/dist/node_modules/@dalcode/dal-office/src/extract/ooxml.js +4 -4
- package/dist/node_modules/@dalcode/dal-office/src/extract/pdf.js +4 -4
- package/dist/node_modules/@dalcode/dal-office/src/facts.d.ts +15 -0
- package/dist/node_modules/@dalcode/dal-office/src/facts.js +4 -0
- package/dist/node_modules/@dalcode/dal-office/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/lazy.js +1 -0
- package/dist/node_modules/@dalcode/dal-office/src/{index.d.ts → office.d.ts} +2 -3
- package/dist/node_modules/@dalcode/dal-office/src/office.js +1 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/capture.d.ts +21 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/capture.js +13 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/chart.d.ts +15 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/chart.js +3 -3
- package/dist/node_modules/@dalcode/dal-office/src/render/docx.d.ts +4 -0
- 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 +2 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/pptx.js +4 -3
- package/dist/node_modules/@dalcode/dal-office/src/render/table-layout.js +1 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/xlsx-chart.d.ts +24 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/xlsx-chart.js +1 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.d.ts +9 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/scratchpad.d.ts +2 -0
- package/dist/node_modules/@dalcode/dal-office/src/scratchpad.js +1 -1
- package/dist/node_modules/@dalcode/dal-office/src/table-stats.js +2 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/chart-generate.js +4 -3
- package/dist/node_modules/@dalcode/dal-office/src/tools/doc-generate.js +2 -3
- package/dist/node_modules/@dalcode/dal-office/src/tools/docx-edit.js +5 -5
- package/dist/node_modules/@dalcode/dal-office/src/tools/drawio-generate.js +2 -3
- package/dist/node_modules/@dalcode/dal-office/src/tools/md-generate.js +2 -3
- package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-generate.js +5 -3
- package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-plan.js +4 -2
- package/dist/node_modules/@dalcode/dal-office/src/tools/pptx-edit.js +5 -5
- package/dist/node_modules/@dalcode/dal-office/src/tools/read-file.js +4 -3
- package/dist/node_modules/@dalcode/dal-office/src/tools/render-page.js +4 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/sheet-generate.js +3 -3
- package/dist/node_modules/@dalcode/dal-office/src/tools/xlsx-edit.js +3 -3
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +15 -15
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/project-size.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 +15 -15
- package/dist/node_modules/@dalcode/dal-pi-kit/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/src/project-size.js +1 -0
- package/dist/node_modules/@dalcode/dal-plugins/package.json +4 -5
- package/dist/node_modules/@dalcode/dal-plugins/src/index.js +11 -11
- package/dist/node_modules/@dalcode/dal-plugins/src/manage.js +7 -7
- package/dist/node_modules/@dalcode/dal-recall/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-recall/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-remote/package.json +2 -2
- 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/commands.js +1 -1
- package/dist/node_modules/@dalcode/dal-rewind/src/core.d.ts +2 -0
- package/dist/node_modules/@dalcode/dal-rewind/src/core.js +6 -6
- package/dist/node_modules/@dalcode/dal-rewind/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-rewind/src/state.js +1 -1
- package/dist/node_modules/@dalcode/dal-router/package.json +9 -9
- package/dist/node_modules/@dalcode/dal-router/src/commands.js +8 -9
- package/dist/node_modules/@dalcode/dal-router/src/config.d.ts +4 -36
- package/dist/node_modules/@dalcode/dal-router/src/config.js +2 -2
- package/dist/node_modules/@dalcode/dal-router/src/index.js +2 -4
- package/dist/node_modules/@dalcode/dal-router/src/notice.js +1 -0
- package/dist/node_modules/@dalcode/dal-router/src/roles/deliverables.js +4 -0
- package/dist/node_modules/@dalcode/dal-router/src/roles/index.js +10 -8
- package/dist/node_modules/@dalcode/dal-router/src/roles/planner.js +5 -0
- package/dist/node_modules/@dalcode/dal-router/src/roles/prompts.js +28 -17
- package/dist/node_modules/@dalcode/dal-router/src/roles/signals.js +2 -2
- package/dist/node_modules/@dalcode/dal-router/src/runtime.d.ts +0 -13
- 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-router/src/task-shape.d.ts +8 -0
- package/dist/node_modules/@dalcode/dal-router/src/task-shape.js +1 -0
- package/dist/node_modules/@dalcode/dal-rtk/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-skills/package.json +4 -3
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/chart-design/SKILL.md +35 -0
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/dal-slides/SKILL.md +17 -9
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/diagram-design/SKILL.md +7 -5
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/poster-design/SKILL.md +8 -6
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/print-design/SKILL.md +21 -8
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/diagram.html +1 -1
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/mindmap.html +1 -1
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/event-poster.html +1 -1
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/poster.css +1 -1
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/square-card.html +1 -1
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/wechat-cover.html +1 -1
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/xhs-card.html +1 -1
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/posters/xhs-cover.html +8 -5
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/print/letter.html +1 -1
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/print/report.html +1 -1
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/visual-kit/print/resume.html +7 -3
- package/dist/node_modules/@dalcode/dal-skills/src/bundled/web-design/SKILL.md +4 -4
- package/dist/node_modules/@dalcode/dal-skills/src/bundled.js +1 -1
- package/dist/node_modules/@dalcode/dal-skills/src/catalog.js +3 -2
- package/dist/node_modules/@dalcode/dal-skills/src/hint.js +1 -0
- package/dist/node_modules/@dalcode/dal-skills/src/index.js +13 -14
- 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 +10 -10
- package/dist/node_modules/@dalcode/dal-subagent/src/index.js +18 -20
- package/dist/node_modules/@dalcode/dal-sync/LICENSE +21 -0
- package/dist/node_modules/@dalcode/dal-sync/package.json +35 -0
- package/dist/node_modules/@dalcode/dal-sync/src/client.js +1 -0
- package/dist/node_modules/@dalcode/dal-sync/src/core.js +2 -0
- package/dist/node_modules/@dalcode/dal-sync/src/index.js +4 -0
- package/dist/node_modules/@dalcode/dal-telemetry/package.json +4 -3
- package/dist/node_modules/@dalcode/dal-telemetry/src/config.js +3 -3
- package/dist/node_modules/@dalcode/dal-telemetry/src/failure-queue.js +3 -3
- package/dist/node_modules/@dalcode/dal-telemetry/src/failure-reporting.js +3 -5
- package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +3 -2
- package/dist/node_modules/@dalcode/dal-tool-catalog/src/groups.js +1 -1
- package/dist/node_modules/@dalcode/dal-tool-catalog/src/index.js +4 -4
- package/dist/node_modules/@dalcode/dal-tool-catalog/src/repair-hook.js +2 -2
- package/dist/node_modules/@dalcode/dal-tool-catalog/src/repair.js +2 -2
- 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/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-workflow/src/announce-check.js +3 -1
- package/dist/node_modules/@dalcode/dal-workflow/src/deliverable-scope.js +1 -0
- package/dist/node_modules/@dalcode/dal-workflow/src/index.js +4 -4
- package/dist/node_modules/@dalcode/dal-workflow/src/test-proof-note.js +3 -0
- package/dist/node_modules/@dalcode/dal-workflow/src/todo-snapshot.js +2 -2
- package/dist/node_modules/@dalcode/dal-workflow/src/todo.js +4 -4
- package/dist/node_modules/@dalcode/dal-workflow/src/truncation-check.js +1 -0
- package/dist/node_modules/@dalcode/dal-workflow/src/working-contract.js +1 -1
- package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
- package/dist/node_modules/@dalcode/deepailab/src/index.js +3 -3
- package/dist/node_modules/@earendil-works/pi-agent-core/README.md +5 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts +2 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +1 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts +3 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/agent.js +1 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-ai/README.md +78 -3
- 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/azure-openai-responses.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/classifier-shared.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/cloudflare-workers-ai-system-one.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js +1 -1
- 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/google-vertex.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/lazy.d.ts +6 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/lazy.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/llama-cpp-classify.js +5 -5
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +2 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +6 -6
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +5 -5
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +10 -5
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +3 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openrouter-images.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js +4 -4
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/simple-options.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/system-one-shared.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/typesafe-system-one.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/cli.js +0 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/index.d.ts +2 -0
- 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 +4 -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 +180 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/compat-schema.js +1 -1
- 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/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/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/moonshotai.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/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/typesafe.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/model-schema.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/telemetry.d.ts +286 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/telemetry.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/types.d.ts +20 -4
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.d.ts +4 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/identity.d.ts +27 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/identity.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/provider-retry.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/transcript.d.ts +3 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/transcript.js +2 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.d.ts +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-codemode/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/CHANGELOG.md +2 -0
- package/dist/node_modules/@earendil-works/pi-mcp/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-telemetry/README.md +167 -21
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/index.d.ts +77 -2
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/index.js +1 -1
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/memory.d.ts +35 -2
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/memory.js +1 -1
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/metrics.d.ts +70 -0
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/metrics.js +1 -0
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/noop.d.ts +5 -2
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/noop.js +1 -1
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/render.js +2 -0
- package/dist/node_modules/@earendil-works/pi-telemetry/dist/testing/conformance.js +1 -1
- package/dist/node_modules/@earendil-works/pi-telemetry/package.json +6 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.js +2 -2
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/markdown.js +8 -7
- package/dist/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.d.ts +3 -0
- 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/terminal.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/terminal.js +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js +4 -4
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui.js +2 -2
- package/dist/node_modules/@earendil-works/pi-tui/package.json +3 -2
- package/dist/package-manager-cli.js +9 -9
- package/dist/sdk/index.d.ts +2 -2
- package/dist/sdk/index.js +1 -1
- package/dist/sdk/office.d.ts +1 -1
- package/dist/sdk/office.js +1 -1
- package/dist/sdk/router.d.ts +4 -4
- package/dist/sdk/router.js +1 -1
- package/dist/utils/clipboard-command.js +1 -1
- package/dist/utils/pi-user-agent.js +1 -1
- package/dist/utils/shell.js +2 -2
- package/dist/utils/tools-manager.js +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +15 -2
- package/package.json +6 -2
- package/dist/core/provider-attribution.js +0 -1
- package/dist/node_modules/@dalcode/dal-guard/src/review.js +0 -3
- package/dist/node_modules/@dalcode/dal-office/src/scenes.js +0 -1
- package/dist/node_modules/@dalcode/dal-plugins/src/rank.js +0 -4
- package/dist/node_modules/@dalcode/dal-router/src/assist.js +0 -4
- package/dist/node_modules/@dalcode/dal-router/src/compact-defer.js +0 -3
- package/dist/node_modules/@dalcode/dal-router/src/jev.d.ts +0 -52
- package/dist/node_modules/@dalcode/dal-router/src/jev.js +0 -5
- package/dist/node_modules/@dalcode/dal-router/src/router.d.ts +0 -32
- package/dist/node_modules/@dalcode/dal-router/src/router.js +0 -1
- package/dist/node_modules/@dalcode/dal-router/src/services.js +0 -1
- package/dist/node_modules/@dalcode/dal-subagent/src/role-pick.js +0 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/pi-user-agent.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var R=Object.defineProperty;var u=(s,r)=>R(s,"name",{value:r,configurable:!0});import{spawn as A,spawnSync as T}from"node:child_process";import*as P from"node:crypto";import*as g from"node:fs";import*as U from"node:os";import*as w from"node:path";import{DEFAULT_RADIUS_GATEWAY as j}from"@earendil-works/pi-ai/providers/radius-config";import{hyperlink as y}from"@earendil-works/pi-tui";import{getAuthCredential as v}from"../../cli/auth-command.js";import{APP_TITLE as F,getShareViewerUrl as L}from"../../config.js";import{houseProvidersEnforced as b}from"../../core/house-providers.js";import{exportSessionToJsonl as I}from"../../core/session-export.js";import{fill as n,t}from"../../dal/i18n.js";import{BorderedLoader as C}from"./components/bordered-loader.js";import{theme as S}from"./theme/theme.js";function D(s,r,o){return[{type:"custom",customType:"pi.share",id:P.randomUUID().slice(0,8),parentId:r,timestamp:o,data:{systemPrompt:s.state.systemPrompt,tools:s.state.tools.map(i=>({name:i.name,description:i.description,parameters:i.parameters}))}}]}u(D,"createShareTrailingEntries");function k(s,r){I(r.sessionManager,s,(o,i)=>D(r,o,i))}u(k,"exportSessionForShare");async function Y(s){const r=g.mkdtempSync(w.join(U.tmpdir(),"
|
|
1
|
+
var R=Object.defineProperty;var u=(s,r)=>R(s,"name",{value:r,configurable:!0});import{spawn as A,spawnSync as T}from"node:child_process";import*as P from"node:crypto";import*as g from"node:fs";import*as U from"node:os";import*as w from"node:path";import{DEFAULT_RADIUS_GATEWAY as j}from"@earendil-works/pi-ai/providers/radius-config";import{hyperlink as y}from"@earendil-works/pi-tui";import{getAuthCredential as v}from"../../cli/auth-command.js";import{APP_TITLE as F,getShareViewerUrl as L}from"../../config.js";import{houseProvidersEnforced as b}from"../../core/house-providers.js";import{exportSessionToJsonl as I}from"../../core/session-export.js";import{fill as n,t}from"../../dal/i18n.js";import{BorderedLoader as C}from"./components/bordered-loader.js";import{theme as S}from"./theme/theme.js";function D(s,r,o){return[{type:"custom",customType:"pi.share",id:P.randomUUID().slice(0,8),parentId:r,timestamp:o,data:{systemPrompt:s.state.systemPrompt,tools:s.state.tools.map(i=>({name:i.name,description:i.description,parameters:i.parameters}))}}]}u(D,"createShareTrailingEntries");function k(s,r){I(r.sessionManager,s,(o,i)=>D(r,o,i))}u(k,"exportSessionForShare");async function Y(s){const r=g.mkdtempSync(w.join(U.tmpdir(),"dal-share-")),o=w.join(r,"session.jsonl"),i=w.join(r,"session.html");try{try{k(o,s.session)}catch(a){s.showError(n(t("\u4F1A\u8BDD\u5BFC\u51FA\u5931\u8D25\uFF1A{error}"),{error:c(a)}));return}const e=b()?"gist":s.session.settingsManager.getSessionShareDestination();if(e!=="gist"){if(await G(o,s))return;if(e==="radius"){s.showError(t("\u8FD8\u6CA1\u6709\u767B\u5F55 Radius\uFF0C\u8BF7\u5148\u8FD0\u884C /login radius\u3002"));return}}try{if(T("gh",["auth","status"],{encoding:"utf-8"}).status!==0){s.showError(t("GitHub CLI \u5C1A\u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u8FD0\u884C gh auth login\u3002"));return}}catch{s.showError(t("\u672A\u5B89\u88C5 GitHub CLI\uFF08gh\uFF09\uFF0C\u8BF7\u4ECE https://cli.github.com/ \u5B89\u88C5\u3002"));return}try{await s.session.exportToHtml(i,{themeName:S.name})}catch(a){s.showError(n(t("\u4F1A\u8BDD\u5BFC\u51FA\u5931\u8D25\uFF1A{error}"),{error:c(a)}));return}await _(i,s)}finally{try{g.rmSync(r,{recursive:!0,force:!0})}catch{}}}u(Y,"shareSession");async function G(s,r){if(b()||!r.session.modelRuntime.getProvider("radius"))return!1;const i=v(await r.session.modelRuntime.getAuth("radius",{minOAuthValidityMs:5*6e4}));if(!i)return!1;const e=new C(r.ui,S,t("\u6B63\u5728\u4E0A\u4F20\u5230 Radius\u2026"));r.editorContainer.clear(),r.editorContainer.addChild(e),r.ui.setFocus(e),r.ui.requestRender(),e.onAbort=()=>{m(e,r),r.showStatus(t("\u5DF2\u53D6\u6D88\u5206\u4EAB"))};try{const a=g.readFileSync(s),l=new URL("/v1/artifacts",j);l.searchParams.set("visibility","organization"),l.searchParams.set("title",`${F} session`);const d=await fetch(l,{method:"POST",headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/x-ndjson","Content-Length":String(a.byteLength)},body:a,signal:e.signal});if(e.signal.aborted)return!0;const h=await d.json().catch(()=>null);if(e.signal.aborted)return!0;if(m(e,r),!d.ok||!h?.artifact)return r.showError(n(t("\u4E0A\u4F20\u5230 Radius \u5931\u8D25\uFF1A{error}"),{error:h?.error||d.statusText||d.status})),!0;const p=h.artifact.canonical_url;return r.showStatus(n(t("\u5206\u4EAB\u94FE\u63A5\uFF1A{url}"),{url:y(p,p)})),!0}catch(a){return e.signal.aborted||(m(e,r),r.showError(n(t("\u4E0A\u4F20\u5230 Radius \u5931\u8D25\uFF1A{error}"),{error:c(a)}))),!0}}u(G,"tryShareViaRadius");async function _(s,r){const o=new C(r.ui,S,t("\u6B63\u5728\u521B\u5EFA gist\u2026"));r.editorContainer.clear(),r.editorContainer.addChild(o),r.ui.setFocus(o),r.ui.requestRender();let i=null;o.onAbort=()=>{i?.kill(),m(o,r),r.showStatus(t("\u5DF2\u53D6\u6D88\u5206\u4EAB"))};try{const e=await new Promise(h=>{i=A("gh",["gist","create","--public=false",s]);let p="",E="";i.stdout?.on("data",f=>{p+=f.toString()}),i.stderr?.on("data",f=>{E+=f.toString()}),i.on("close",f=>h({stdout:p,stderr:E,code:f}))});if(o.signal.aborted)return;if(m(o,r),e.code!==0){r.showError(n(t("\u521B\u5EFA gist \u5931\u8D25\uFF1A{error}"),{error:e.stderr?.trim()||t("\u672A\u77E5\u9519\u8BEF")}));return}const a=e.stdout?.trim(),l=a?.split("/").pop();if(!l){r.showError(t("\u65E0\u6CD5\u4ECE gh \u7684\u8F93\u51FA\u4E2D\u89E3\u6790 gist ID"));return}const d=L(l,a);r.showStatus(`${n(t("\u5206\u4EAB\u94FE\u63A5\uFF1A{url}"),{url:y(d,d)})}
|
|
2
2
|
${n(t("Gist\uFF1A{url}"),{url:y(a,a)})}`)}catch(e){o.signal.aborted||(m(o,r),r.showError(n(t("\u521B\u5EFA gist \u5931\u8D25\uFF1A{error}"),{error:c(e)})))}}u(_,"shareViaGist");function m(s,r){s.dispose(),r.editorContainer.clear(),r.editorContainer.addChild(r.editor),r.ui.setFocus(r.editor)}u(m,"restoreEditor");function c(s){return s instanceof Error?s.message:t("\u672A\u77E5\u9519\u8BEF")}u(c,"errorMessage");export{D as createShareTrailingEntries,k as exportSessionForShare,Y as shareSession};
|
|
@@ -6,4 +6,5 @@ export interface PrintModeOptions {
|
|
|
6
6
|
initialMessage?: string;
|
|
7
7
|
initialImages?: ImageContent[];
|
|
8
8
|
}
|
|
9
|
+
export declare const PRINT_MODE_PENDING_WORK_SLOT: unique symbol;
|
|
9
10
|
export declare function runPrintMode(runtimeHost: AgentSessionRuntime, options: PrintModeOptions): Promise<number>;
|
package/dist/modes/print-mode.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)
|
|
3
|
-
`)}
|
|
4
|
-
`)
|
|
5
|
-
`)
|
|
6
|
-
`)
|
|
7
|
-
`);t.stopReason==="
|
|
1
|
+
var R=Object.defineProperty;var r=(n,a)=>R(n,"name",{value:a,configurable:!0});import{isNetworkAssistantError as x}from"@earendil-works/pi-ai";import{flushRawStdout as M,waitForRawStdoutBackpressure as k,writeRawStdout as p}from"../core/output-guard.js";import{formatStallNotice as E}from"../core/stall-watchdog.js";import{fill as P,t as f}from"../dal/i18n.js";import{killTrackedDetachedChildren as N}from"../utils/shell.js";import{toJsonEvent as T}from"./json-event.js";const j=Symbol.for("dalcode.printMode.pendingWork");function G(){return[...globalThis[j]?.values()??[]].map(a=>a()).filter(a=>a!==void 0)}r(G,"pendingWork");async function _(n){for(;;){await n.waitForIdle();const a=G();if(a.length===0)return;await Promise.allSettled(a),await new Promise(l=>setImmediate(l))}}r(_,"waitForPendingWork");async function B(n,a){const{mode:l,messages:b=[],initialMessage:m,initialImages:I}=a;let c=0,d,o=n.session,g,u,w=!1;const y=[],S=r(async()=>{w||(w=!0,g?.(),u?.(),await n.dispose())},"disposeRuntime");r(()=>{const e=["SIGTERM","SIGINT"];process.platform!=="win32"&&e.push("SIGHUP");for(const s of e){const t=r(()=>{N(),S().finally(()=>{process.exit(s==="SIGHUP"?129:s==="SIGINT"?130:143)})},"handler");process.on(s,t),y.push(()=>process.off(s,t))}},"registerSignalHandlers")(),n.setRebindSession(async()=>{await h()});const h=r(async()=>{o=n.session,await o.bindExtensions({mode:l==="json"?"json":"print",commandContextActions:{waitForIdle:r(()=>o.waitForIdle(),"waitForIdle"),newSession:r(async e=>n.newSession(e),"newSession"),fork:r(async(e,s)=>({cancelled:(await n.fork(e,s)).cancelled}),"fork"),navigateTree:r(async(e,s)=>({cancelled:(await o.navigateTree(e,{summarize:s?.summarize,customInstructions:s?.customInstructions,replaceInstructions:s?.replaceInstructions,label:s?.label})).cancelled}),"navigateTree"),switchSession:r(async(e,s)=>n.switchSession(e,s),"switchSession"),reload:r(async()=>{await o.reload()},"reload")},onError:r(e=>{console.error(P(f("\u6269\u5C55\u51FA\u9519\uFF08{path}\uFF09\uFF1A{error}"),{path:e.extensionPath,error:String(e.error)}))},"onError")}),g?.(),u?.(),g=o.subscribe(e=>{e.type==="message_end"&&e.message.role==="assistant"&&(d=e.message),l==="json"?p(`${JSON.stringify(T(e))}
|
|
2
|
+
`):e.type==="stall_watchdog"&&process.stderr.write(`[dal] ${E(e)}
|
|
3
|
+
`)}),u=l==="json"?o.agent.subscribe(async()=>{const e=o.enterStallStage("host:stdout","host");try{await k()}finally{e()}}):void 0},"rebindSession");try{if(l==="json"){const e=o.sessionManager.getHeader();e&&p(`${JSON.stringify(e)}
|
|
4
|
+
`)}await h(),m&&await o.prompt(m,{images:I});for(const e of b)await o.prompt(e);if(await _(o),l==="text"){const e=o.state,s=e.messages[e.messages.length-1];if(s?.role==="custom"&&s.display){const t=typeof s.content=="string"?s.content:s.content.filter(i=>i.type==="text").map(i=>i.text).join(`
|
|
5
|
+
`);t&&p(`${t}
|
|
6
|
+
`)}else if(s?.role==="toolResult"&&s.isError){const t=s.content.filter(i=>i.type==="text").map(i=>i.text).join(`
|
|
7
|
+
`);console.error(t||f("\u8BF7\u6C42\u51FA\u9519")),c=1}else if(d||s?.role==="assistant"){const t=d??s;if(t.stopReason==="error"||t.stopReason==="aborted")console.error(t.errorMessage||(t.stopReason==="aborted"?f("\u8BF7\u6C42\u5DF2\u4E2D\u6B62"):f("\u8BF7\u6C42\u51FA\u9519"))),x(t)&&o.sessionManager.isPersisted()&&console.error(f("\u7F51\u7EDC\u8FDE\u63A5\u4E2D\u65AD\uFF0C\u81EA\u52A8\u91CD\u8FDE\u540E\u4ECD\u672A\u6062\u590D\u3002\u4F1A\u8BDD\u5DF2\u4FDD\u5B58\uFF0C\u7F51\u7EDC\u6062\u590D\u540E\u7528 dal -c \u63A5\u7740\u505A\u3002")),c=1;else{for(const i of t.content)i.type==="text"&&p(`${i.text}
|
|
8
|
+
`);t.stopReason==="length"&&(console.error(f("\u56DE\u7B54\u88AB\u622A\u65AD\uFF1A\u6A21\u578B\u5DF2\u8FBE\u5230\u8F93\u51FA\u957F\u5EA6\u4E0A\u9650\u3002")),c=1)}}}else{const e=o.state,s=e.messages[e.messages.length-1],t=d??(s?.role==="assistant"?s:void 0);(s?.role==="toolResult"&&s.isError||t&&(t.stopReason==="error"||t.stopReason==="aborted"||t.stopReason==="length"))&&(c=1)}return c}catch(e){return console.error(e instanceof Error?e.message:String(e)),1}finally{for(const e of y)e();await S(),await M()}}r(B,"runPrintMode");export{j as PRINT_MODE_PENDING_WORK_SLOT,B as runPrintMode};
|
|
@@ -9,7 +9,19 @@ import type { HostCapability } from "../../core/host-capabilities.ts";
|
|
|
9
9
|
import type { SandboxStatus } from "../../core/sandbox/shell-sandbox.ts";
|
|
10
10
|
import type { SessionEntry, SessionTreeNode } from "../../core/session-manager.ts";
|
|
11
11
|
import type { JsonAgentSessionEvent } from "../json-event.ts";
|
|
12
|
-
import type { PermissionModeStatus, RpcApprovalRequest, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcHostRequest, RpcMessageMeta, RpcPermissionMode, RpcSessionState, RpcSlashCommand, TelemetryConsentStatus } from "./rpc-types.ts";
|
|
12
|
+
import type { PermissionModeStatus, RpcApprovalRequest, RpcErrorCode, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcHostRequest, RpcMessageMeta, RpcPermissionMode, RpcResponse, RpcSessionState, RpcSlashCommand, TelemetryConsentStatus } from "./rpc-types.ts";
|
|
13
|
+
export declare class RpcCommandError extends Error {
|
|
14
|
+
readonly command: string;
|
|
15
|
+
readonly code?: RpcErrorCode;
|
|
16
|
+
readonly extensionError?: {
|
|
17
|
+
extensionPath: string;
|
|
18
|
+
event: string;
|
|
19
|
+
error: string;
|
|
20
|
+
};
|
|
21
|
+
constructor(response: Extract<RpcResponse, {
|
|
22
|
+
success: false;
|
|
23
|
+
}>);
|
|
24
|
+
}
|
|
13
25
|
export interface RpcClientOptions {
|
|
14
26
|
cliPath?: string;
|
|
15
27
|
cwd?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var w=Object.defineProperty;var h=(
|
|
2
|
-
`);return e.length>u?e.slice(-u):e}h(E,"rpcStderrTail");const x=new Set(["select","confirm","input","editor","requestInput","requestChoice"]);class S{static{h(this,"RpcClient")}process=null;stopReadingStdout=null;eventListeners=[];pendingRequests=new Map;requestId=0;extensionUIHandler=null;approvalHandler=null;hostRequestHandler=null;stderr="";exitError=null;options;exitListeners=new Set;exitInfo;stopping=!1;turnInFlight=!1;constructor(t={}){this.options=t}async start(){if(this.process)throw new Error("Client already started");this.exitError=null,this.exitInfo=void 0,this.stopping=!1,this.turnInFlight=!1;const t=this.options.cliPath??"dist/cli.js",e=["--mode","rpc"];this.options.provider&&e.push("--provider",this.options.provider),this.options.model&&e.push("--model",this.options.model),this.options.args&&e.push(...this.options.args);const s=_(process.execPath,[t,...e],{cwd:this.options.cwd,env:{...this.options.inheritEnv===!1?{}:process.env,...this.options.env},stdio:["pipe","pipe","pipe"]});if(this.process=s,s.stderr?.on("data",r=>{this.stderr+=r.toString(),process.stderr.write(r)}),s.once("exit",(r,n)=>{if(this.process!==s)return;this.reportExit({code:r,signal:n});const o=this.createProcessExitError(r,n);this.exitError=o,this.rejectPendingRequests(o)}),s.once("error",r=>{if(this.process!==s)return;const n=new Error(`Agent process error: ${r.message}. Stderr: ${this.stderr}`);s.exitCode===null&&s.signalCode===null&&this.reportExit({code:null,signal:null,error:r.message}),this.exitError=n,this.rejectPendingRequests(n)}),s.stdin?.on("error",r=>{if(this.process!==s)return;const n=this.exitError??new Error(`Agent process stdin error: ${r.message}. Stderr: ${this.stderr}`);this.exitError=n,this.rejectPendingRequests(n)}),this.stopReadingStdout=m(s.stdout,r=>{this.handleLine(r)}),await new Promise(r=>setTimeout(r,100)),this.process.exitCode!==null){const r=this.exitError??this.createProcessExitError(this.process.exitCode,this.process.signalCode);throw this.exitError=r,r}}async stop(){this.process&&(this.stopReadingStdout?.(),this.stopReadingStdout=null,this.stopping=!0,this.process.kill("SIGTERM"),await new Promise(t=>{const e=setTimeout(()=>{this.process?.kill("SIGKILL"),t()},1e3);this.process?.on("exit",()=>{clearTimeout(e),t()})}),this.process=null,this.pendingRequests.clear())}onExit(t){const e=this.exitInfo;return e?(queueMicrotask(()=>t(e)),()=>{}):(this.exitListeners.add(t),()=>{this.exitListeners.delete(t)})}getExit(){return this.exitInfo}onEvent(t){return this.eventListeners.push(t),()=>{const e=this.eventListeners.indexOf(t);e!==-1&&this.eventListeners.splice(e,1)}}setExtensionUIHandler(t){this.extensionUIHandler=t}setApprovalHandler(t){this.approvalHandler=t}getStderr(){return this.stderr}async prompt(t,e,s){const r=await this.send({type:"prompt",message:t,images:e,streamingBehavior:s}),{disposition:n}=this.getData(r);return n!=="handled"&&(this.turnInFlight=!0),n}async steer(t,e){const s=await this.send({type:"steer",message:t,images:e});return this.getData(s).disposition}async followUp(t,e){const s=await this.send({type:"follow_up",message:t,images:e});return this.getData(s).disposition}async abort(){await this.send({type:"abort"})}async clearQueue(){const t=await this.send({type:"clear_queue"});return this.getData(t)}async newSession(t){const e=await this.send({type:"new_session",parentSession:t});return this.getData(e)}async getState(){const t=await this.send({type:"get_state"});return this.getData(t)}async setModel(t,e){const s=await this.send({type:"set_model",provider:t,modelId:e});return this.getData(s)}async cycleModel(){const t=await this.send({type:"cycle_model"});return this.getData(t)}async getAvailableModels(){const t=await this.send({type:"get_available_models"});return this.getData(t).models}async setThinkingLevel(t){await this.send({type:"set_thinking_level",level:t})}async cycleThinkingLevel(){const t=await this.send({type:"cycle_thinking_level"});return this.getData(t)}async getAvailableThinkingLevels(){const t=await this.send({type:"get_available_thinking_levels"});return this.getData(t).levels}async setSteeringMode(t){await this.send({type:"set_steering_mode",mode:t})}async setFollowUpMode(t){await this.send({type:"set_follow_up_mode",mode:t})}async compact(t){const e=await this.send({type:"compact",customInstructions:t});return this.getData(e)}async setAutoCompaction(t){await this.send({type:"set_auto_compaction",enabled:t})}async setAutoRetry(t){await this.send({type:"set_auto_retry",enabled:t})}async abortRetry(){await this.send({type:"abort_retry"})}async bash(t){const e=await this.send({type:"bash",command:t});return this.getData(e)}async abortBash(){await this.send({type:"abort_bash"})}async getSandboxStatus(){const t=await this.send({type:"get_sandbox_status"});return this.getData(t)}async listBackgroundProcesses(){const t=await this.send({type:"list_background_processes"});return this.getData(t).processes}async readBackgroundProcess(t,e){const s=await this.send({type:"read_background_process",processId:t,...e!==void 0?{tail:e}:{}});return this.getData(s)}async stopBackgroundProcess(t){const e=await this.send({type:"stop_background_process",processId:t});return this.getData(e).process}async setEnvironment(t){const e=await this.send({type:"set_environment",...t});return this.getData(e).changed}async setTelemetryConsent(t){const e=await this.send({type:"set_telemetry_consent",usage:t.usage,...t.failures!==void 0?{failures:t.failures}:{}});return this.getData(e)}async getPermissionMode(){const t=await this.send({type:"get_permission_mode"});return this.getData(t)}async setPermissionMode(t,e={}){const s=await this.send({type:"set_permission_mode",mode:t,...e.save!==void 0?{save:e.save}:{}});return this.getData(s)}async getSessionStats(){const t=await this.send({type:"get_session_stats"});return this.getData(t)}async exportHtml(t){const e=await this.send({type:"export_html",outputPath:t});return this.getData(e)}async switchSession(t){const e=await this.send({type:"switch_session",sessionPath:t});return this.getData(e)}async fork(t){const e=await this.send({type:"fork",entryId:t});return this.getData(e)}async clone(){const t=await this.send({type:"clone"});return this.getData(t)}async getForkMessages(){const t=await this.send({type:"get_fork_messages"});return this.getData(t).messages}async getEntries(t){const e=await this.send({type:"get_entries",since:t});return this.getData(e)}async getTree(){const t=await this.send({type:"get_tree"});return this.getData(t)}async getLastAssistantText(){const t=await this.send({type:"get_last_assistant_text"});return this.getData(t).text}async setSessionName(t){await this.send({type:"set_session_name",name:t})}async getMessages(){const t=await this.send({type:"get_messages"});return this.getData(t).messages}async getMessagesWithMeta(){const t=await this.send({type:"get_messages"});return this.getData(t)}async respondToApproval(t,e){const s=await this.send({type:"approval_response",optionId:e},t);return this.getData(s)}async getCommands(){const t=await this.send({type:"get_commands"});return this.getData(t).commands}async setHostCapabilities(t,e){this.hostRequestHandler=e;const s=await this.send({type:"set_host_capabilities",capabilities:t});return this.getData(s).capabilities}waitForIdle(t=6e4){return new Promise((e,s)=>{const r=setTimeout(()=>{n(),o(),s(new Error(`Timeout waiting for agent to become idle. Stderr: ${this.stderr}`))},t),n=this.onEvent(i=>{i.type==="agent_settled"&&(clearTimeout(r),n(),o(),e())}),o=this.onExit(i=>{clearTimeout(r),n(),s(this.createExitWhileWaitingError(i))})})}collectEvents(t=6e4){return new Promise((e,s)=>{const r=[],n=setTimeout(()=>{o(),i(),s(new Error(`Timeout collecting events. Stderr: ${this.stderr}`))},t),o=this.onEvent(a=>{r.push(a),a.type==="agent_settled"&&(clearTimeout(n),o(),i(),e(r))}),i=this.onExit(a=>{clearTimeout(n),o(),s(this.createExitWhileWaitingError(a))})})}async promptAndWait(t,e,s=6e4){const r=this.collectEvents(s);return await this.prompt(t,e),r}handleLine(t){try{const e=JSON.parse(t);if(e.type==="agent_start"?this.turnInFlight=!0:e.type==="agent_settled"&&(this.turnInFlight=!1),e.type==="response"&&e.id&&this.pendingRequests.has(e.id)){const s=this.pendingRequests.get(e.id);this.pendingRequests.delete(e.id),s.resolve(e);return}if(e.type==="approval_request"&&this.approvalHandler&&this.answerApprovalRequest(e),e.type==="extension_ui_request"&&x.has(e.method)&&!(e.approval===!0&&this.approvalHandler)&&this.answerExtensionUIRequest(e),e.type==="host_request"){this.answerHostRequest(e);return}for(const s of[...this.eventListeners])s(e)}catch{}}async answerExtensionUIRequest(t){const e={type:"extension_ui_response",id:t.id,cancelled:!0};let s=e;if(this.extensionUIHandler)try{s=await this.extensionUIHandler(t)??e}catch{s=e}const r=this.process?.stdin;if(!(!r||r.destroyed||!r.writable))try{r.write(d({...s,id:t.id}))}catch{}}async answerApprovalRequest(t){let e="deny";try{e=await this.approvalHandler?.(t)??"deny"}catch{e="deny"}try{await this.respondToApproval(t.id,e)}catch{}}async answerHostRequest(t){let e;if(!this.hostRequestHandler)e={type:"host_response",id:t.id,error:"host has no handler for host requests"};else try{const r=await this.hostRequestHandler(t);e={type:"host_response",id:t.id,result:r??null}}catch(r){e={type:"host_response",id:t.id,error:r instanceof Error?r.message:String(r)}}const s=this.process?.stdin;if(!(!s||s.destroyed||!s.writable))try{s.write(d(e))}catch{}}reportExit(t){if(this.exitInfo)return;const e={code:t.code,signal:t.signal,stderrTail:E(this.stderr),expected:this.stopping,turnInFlight:this.turnInFlight,...t.error?{error:t.error}:{}};this.exitInfo=e,this.turnInFlight=!1;const s=[...this.exitListeners];this.exitListeners.clear();for(const r of s)try{r(e)}catch{}}createExitWhileWaitingError(t){const e=t.signal?`signal ${t.signal}`:`code ${t.code??"unknown"}`,s=t.stderrTail?`
|
|
1
|
+
var w=Object.defineProperty;var h=(d,t)=>w(d,"name",{value:t,configurable:!0});import{spawn as m}from"node:child_process";import{attachJsonlLineReader as f,serializeJsonLine as p}from"./jsonl.js";class _ extends Error{static{h(this,"RpcCommandError")}command;code;extensionError;constructor(t){super(t.error),this.name="RpcCommandError",this.command=t.command,t.code!==void 0&&(this.code=t.code),t.extensionError!==void 0&&(this.extensionError=t.extensionError)}}const E=20,u=2e3;function x(d){const e=d.split(/\r?\n/u).filter(s=>s.trim().length>0).slice(-E).join(`
|
|
2
|
+
`);return e.length>u?e.slice(-u):e}h(x,"rpcStderrTail");const v=new Set(["select","confirm","input","editor","requestInput","requestChoice"]);class S{static{h(this,"RpcClient")}process=null;stopReadingStdout=null;eventListeners=[];pendingRequests=new Map;requestId=0;extensionUIHandler=null;approvalHandler=null;hostRequestHandler=null;stderr="";exitError=null;options;exitListeners=new Set;exitInfo;stopping=!1;turnInFlight=!1;constructor(t={}){this.options=t}async start(){if(this.process)throw new Error("Client already started");this.exitError=null,this.exitInfo=void 0,this.stopping=!1,this.turnInFlight=!1;const t=this.options.cliPath??"dist/cli.js",e=["--mode","rpc"];this.options.provider&&e.push("--provider",this.options.provider),this.options.model&&e.push("--model",this.options.model),this.options.args&&e.push(...this.options.args);const s=m(process.execPath,[t,...e],{cwd:this.options.cwd,env:{...this.options.inheritEnv===!1?{}:process.env,...this.options.env},stdio:["pipe","pipe","pipe"],detached:process.platform!=="win32"});if(this.process=s,s.stderr?.on("data",n=>{this.stderr+=n.toString(),process.stderr.write(n)}),s.once("exit",(n,r)=>{if(this.process!==s)return;this.reportExit({code:n,signal:r});const o=this.createProcessExitError(n,r);this.exitError=o,this.rejectPendingRequests(o)}),s.once("error",n=>{if(this.process!==s)return;const r=new Error(`Agent process error: ${n.message}. Stderr: ${this.stderr}`);s.exitCode===null&&s.signalCode===null&&this.reportExit({code:null,signal:null,error:n.message}),this.exitError=r,this.rejectPendingRequests(r)}),s.stdin?.on("error",n=>{if(this.process!==s)return;const r=this.exitError??new Error(`Agent process stdin error: ${n.message}. Stderr: ${this.stderr}`);this.exitError=r,this.rejectPendingRequests(r)}),this.stopReadingStdout=f(s.stdout,n=>{this.handleLine(n)}),await new Promise(n=>setTimeout(n,100)),this.process.exitCode!==null){const n=this.exitError??this.createProcessExitError(this.process.exitCode,this.process.signalCode);throw this.exitError=n,n}}async stop(){if(!this.process)return;this.stopReadingStdout?.(),this.stopReadingStdout=null,this.stopping=!0;const t=this.process,e=h(n=>{try{t.pid!==void 0&&process.platform!=="win32"?process.kill(-t.pid,n):t.kill(n)}catch{t.kill(n)}},"signal"),s=t.exitCode!==null||t.signalCode!==null;s||e("SIGTERM"),await new Promise(n=>{if(s){n();return}const r=setTimeout(()=>{e("SIGKILL"),n()},1e3);t.on("exit",()=>{clearTimeout(r),e("SIGKILL"),n()})}),this.process=null,this.pendingRequests.clear()}onExit(t){const e=this.exitInfo;return e?(queueMicrotask(()=>t(e)),()=>{}):(this.exitListeners.add(t),()=>{this.exitListeners.delete(t)})}getExit(){return this.exitInfo}onEvent(t){return this.eventListeners.push(t),()=>{const e=this.eventListeners.indexOf(t);e!==-1&&this.eventListeners.splice(e,1)}}setExtensionUIHandler(t){this.extensionUIHandler=t}setApprovalHandler(t){this.approvalHandler=t}getStderr(){return this.stderr}async prompt(t,e,s){const n=await this.send({type:"prompt",message:t,images:e,streamingBehavior:s}),{disposition:r}=this.getData(n);return r!=="handled"&&(this.turnInFlight=!0),r}async steer(t,e){const s=await this.send({type:"steer",message:t,images:e});return this.getData(s).disposition}async followUp(t,e){const s=await this.send({type:"follow_up",message:t,images:e});return this.getData(s).disposition}async abort(){await this.send({type:"abort"})}async clearQueue(){const t=await this.send({type:"clear_queue"});return this.getData(t)}async newSession(t){const e=await this.send({type:"new_session",parentSession:t});return this.getData(e)}async getState(){const t=await this.send({type:"get_state"});return this.getData(t)}async setModel(t,e){const s=await this.send({type:"set_model",provider:t,modelId:e});return this.getData(s)}async cycleModel(){const t=await this.send({type:"cycle_model"});return this.getData(t)}async getAvailableModels(){const t=await this.send({type:"get_available_models"});return this.getData(t).models}async setThinkingLevel(t){await this.send({type:"set_thinking_level",level:t})}async cycleThinkingLevel(){const t=await this.send({type:"cycle_thinking_level"});return this.getData(t)}async getAvailableThinkingLevels(){const t=await this.send({type:"get_available_thinking_levels"});return this.getData(t).levels}async setSteeringMode(t){await this.send({type:"set_steering_mode",mode:t})}async setFollowUpMode(t){await this.send({type:"set_follow_up_mode",mode:t})}async compact(t){const e=await this.send({type:"compact",customInstructions:t});return this.getData(e)}async setAutoCompaction(t){await this.send({type:"set_auto_compaction",enabled:t})}async setAutoRetry(t){await this.send({type:"set_auto_retry",enabled:t})}async abortRetry(){await this.send({type:"abort_retry"})}async bash(t){const e=await this.send({type:"bash",command:t});return this.getData(e)}async abortBash(){await this.send({type:"abort_bash"})}async getSandboxStatus(){const t=await this.send({type:"get_sandbox_status"});return this.getData(t)}async listBackgroundProcesses(){const t=await this.send({type:"list_background_processes"});return this.getData(t).processes}async readBackgroundProcess(t,e){const s=await this.send({type:"read_background_process",processId:t,...e!==void 0?{tail:e}:{}});return this.getData(s)}async stopBackgroundProcess(t){const e=await this.send({type:"stop_background_process",processId:t});return this.getData(e).process}async setEnvironment(t){const e=await this.send({type:"set_environment",...t});return this.getData(e).changed}async setTelemetryConsent(t){const e=await this.send({type:"set_telemetry_consent",usage:t.usage,...t.failures!==void 0?{failures:t.failures}:{}});return this.getData(e)}async getPermissionMode(){const t=await this.send({type:"get_permission_mode"});return this.getData(t)}async setPermissionMode(t,e={}){const s=await this.send({type:"set_permission_mode",mode:t,...e.save!==void 0?{save:e.save}:{}});return this.getData(s)}async getSessionStats(){const t=await this.send({type:"get_session_stats"});return this.getData(t)}async exportHtml(t){const e=await this.send({type:"export_html",outputPath:t});return this.getData(e)}async switchSession(t){const e=await this.send({type:"switch_session",sessionPath:t});return this.getData(e)}async fork(t){const e=await this.send({type:"fork",entryId:t});return this.getData(e)}async clone(){const t=await this.send({type:"clone"});return this.getData(t)}async getForkMessages(){const t=await this.send({type:"get_fork_messages"});return this.getData(t).messages}async getEntries(t){const e=await this.send({type:"get_entries",since:t});return this.getData(e)}async getTree(){const t=await this.send({type:"get_tree"});return this.getData(t)}async getLastAssistantText(){const t=await this.send({type:"get_last_assistant_text"});return this.getData(t).text}async setSessionName(t){await this.send({type:"set_session_name",name:t})}async getMessages(){const t=await this.send({type:"get_messages"});return this.getData(t).messages}async getMessagesWithMeta(){const t=await this.send({type:"get_messages"});return this.getData(t)}async respondToApproval(t,e){const s=await this.send({type:"approval_response",optionId:e},t);return this.getData(s)}async getCommands(){const t=await this.send({type:"get_commands"});return this.getData(t).commands}async setHostCapabilities(t,e){this.hostRequestHandler=e;const s=await this.send({type:"set_host_capabilities",capabilities:t});return this.getData(s).capabilities}waitForIdle(t=6e4){return new Promise((e,s)=>{const n=setTimeout(()=>{r(),o(),s(new Error(`Timeout waiting for agent to become idle. Stderr: ${this.stderr}`))},t),r=this.onEvent(i=>{i.type==="agent_settled"&&(clearTimeout(n),r(),o(),e())}),o=this.onExit(i=>{clearTimeout(n),r(),s(this.createExitWhileWaitingError(i))})})}collectEvents(t=6e4){return new Promise((e,s)=>{const n=[],r=setTimeout(()=>{o(),i(),s(new Error(`Timeout collecting events. Stderr: ${this.stderr}`))},t),o=this.onEvent(a=>{n.push(a),a.type==="agent_settled"&&(clearTimeout(r),o(),i(),e(n))}),i=this.onExit(a=>{clearTimeout(r),o(),s(this.createExitWhileWaitingError(a))})})}async promptAndWait(t,e,s=6e4){const n=this.collectEvents(s);return await this.prompt(t,e),n}handleLine(t){try{const e=JSON.parse(t);if(e.type==="agent_start"?this.turnInFlight=!0:e.type==="agent_settled"&&(this.turnInFlight=!1),e.type==="response"&&e.id&&this.pendingRequests.has(e.id)){const s=this.pendingRequests.get(e.id);this.pendingRequests.delete(e.id),s.resolve(e);return}if(e.type==="approval_request"&&this.approvalHandler&&this.answerApprovalRequest(e),e.type==="extension_ui_request"&&v.has(e.method)&&!(e.approval===!0&&this.approvalHandler)&&this.answerExtensionUIRequest(e),e.type==="host_request"){this.answerHostRequest(e);return}for(const s of[...this.eventListeners])s(e)}catch{}}async answerExtensionUIRequest(t){const e={type:"extension_ui_response",id:t.id,cancelled:!0};let s=e;if(this.extensionUIHandler)try{s=await this.extensionUIHandler(t)??e}catch{s=e}const n=this.process?.stdin;if(!(!n||n.destroyed||!n.writable))try{n.write(p({...s,id:t.id}))}catch{}}async answerApprovalRequest(t){let e="deny";try{e=await this.approvalHandler?.(t)??"deny"}catch{e="deny"}try{await this.respondToApproval(t.id,e)}catch{}}async answerHostRequest(t){let e;if(!this.hostRequestHandler)e={type:"host_response",id:t.id,error:"host has no handler for host requests"};else try{const n=await this.hostRequestHandler(t);e={type:"host_response",id:t.id,result:n??null}}catch(n){e={type:"host_response",id:t.id,error:n instanceof Error?n.message:String(n)}}const s=this.process?.stdin;if(!(!s||s.destroyed||!s.writable))try{s.write(p(e))}catch{}}reportExit(t){if(this.exitInfo)return;const e={code:t.code,signal:t.signal,stderrTail:x(this.stderr),expected:this.stopping,turnInFlight:this.turnInFlight,...t.error?{error:t.error}:{}};this.exitInfo=e,this.turnInFlight=!1;const s=[...this.exitListeners];this.exitListeners.clear();for(const n of s)try{n(e)}catch{}}createExitWhileWaitingError(t){const e=t.signal?`signal ${t.signal}`:`code ${t.code??"unknown"}`,s=t.stderrTail?`
|
|
3
3
|
Last stderr output:
|
|
4
|
-
${t.stderrTail}`:"";return new Error(`Agent process exited (${e}) before the turn finished.${s}`)}createProcessExitError(t,e){return new Error(`Agent process exited (code=${t} signal=${e}). Stderr: ${this.stderr}`)}rejectPendingRequests(t){for(const e of this.pendingRequests.values())e.reject(t);this.pendingRequests.clear()}async send(t,e){const s=this.process,
|
|
4
|
+
${t.stderrTail}`:"";return new Error(`Agent process exited (${e}) before the turn finished.${s}`)}createProcessExitError(t,e){return new Error(`Agent process exited (code=${t} signal=${e}). Stderr: ${this.stderr}`)}rejectPendingRequests(t){for(const e of this.pendingRequests.values())e.reject(t);this.pendingRequests.clear()}async send(t,e){const s=this.process,n=s?.stdin;if(!s||!n)throw new Error("Client not started");if(this.exitError)throw this.exitError;if(s.exitCode!==null){const i=this.createProcessExitError(s.exitCode,s.signalCode);throw this.exitError=i,i}if(n.destroyed||!n.writable){const i=new Error(`Agent process stdin is not writable. Stderr: ${this.stderr}`);throw this.exitError=i,i}const r=e??`req_${++this.requestId}`,o={...t,id:r};return new Promise((i,a)=>{const l=setTimeout(()=>{this.pendingRequests.delete(r),a(new Error(`Timeout waiting for response to ${t.type}. Stderr: ${this.stderr}`))},this.options.requestTimeoutMs??3e4);this.pendingRequests.set(r,{resolve:h(c=>{clearTimeout(l),i(c)},"resolve"),reject:h(c=>{clearTimeout(l),a(c)},"reject")});try{n.write(p(o))}catch(c){const g=c instanceof Error?c:new Error(String(c)),y=this.pendingRequests.get(r);this.pendingRequests.delete(r),y?.reject(g)}})}getData(t){if(!t.success)throw new _(t);return t.data}}export{S as RpcClient,_ as RpcCommandError,x as rpcStderrTail};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var z=Object.defineProperty;var i=(u,o)=>z(u,"name",{value:o,configurable:!0});import*as f from"node:crypto";import{resolveExtensionNotify as K}from"../../core/extensions/index.js";import{DEFAULT_HOST_CALL_TIMEOUT_MS as Q,getHostCapabilities as N,HostCallError as k,parseHostCapabilities as V}from"../../core/host-capabilities.js";import{flushRawStdout as X,takeOverStdout as Y,waitForRawStdoutBackpressure as S,writeRawStdout as Z}from"../../core/output-guard.js";import{killTrackedDetachedChildren as ee}from"../../utils/shell.js";import{theme as te}from"../interactive/theme/theme.js";import{toJsonEvent as se}from"../json-event.js";import{openApproval as ne,ResolvedApprovals as oe}from"./approvals.js";import{applyEnvironmentUpdate as re}from"./environment-update.js";import{attachJsonlLineReader as ie,serializeJsonLine as ae}from"./jsonl.js";import{buildMessageMeta as le}from"./message-meta.js";const ce="Prompt aborted before it started";async function we(u){Y();let o=u.session,T,E;const c=i(e=>{Z(ae(e))},"output"),r=i((e,t,s)=>s===void 0?{id:e,type:"response",command:t,success:!0}:{id:e,type:"response",command:t,success:!0,data:s},"success"),d=i((e,t,s)=>({id:e,type:"response",command:t,success:!1,error:s}),"error"),g=new Map,R=new oe,w=new Map,O=i((e,t)=>{const s=f.randomUUID();return new Promise((n,a)=>{const l=i(()=>{clearTimeout(U),t.signal?.removeEventListener("abort",h),w.delete(s)},"cleanup"),p=i(_=>{l(),c({type:"host_request_cancelled",id:s}),a(_)},"giveUp"),h=i(()=>p(new k("aborted","host call aborted")),"onAbort"),U=setTimeout(()=>p(new k("timeout","host did not answer in time")),t.timeoutMs??Q);t.signal?.addEventListener("abort",h,{once:!0}),w.set(s,{resolve:i(_=>{l(),n(_)},"resolve"),reject:i(_=>{l(),a(_)},"reject")});const y={type:"host_request",id:s,capability:e.capability,method:e.method,params:e.params};c(y)})},"rpcHostTransport");let A=!1,P=!1;const L=[];function v(e,t,s,n){if(e?.signal?.aborted)return Promise.resolve(t);const a=f.randomUUID(),l=s.method,p=e?.approval&&(l==="select"||l==="confirm")?ne(a,l,e.approval,{options:Array.isArray(s.options)?s.options:void 0,timeout:e.timeout}):void 0;return new Promise((h,U)=>{let y;const _=i((b,x)=>{if(!p)return;const I=x?p.kindOf(x):void 0,B=b==="dialog"&&!I?"cancelled":b;R.remember(a,I,B);const H={type:"approval_resolved",id:a,...I?{optionId:I}:{},via:B};c(H)},"settleApproval"),M=i(()=>{y&&clearTimeout(y),e?.signal?.removeEventListener("abort",$),g.delete(a)},"cleanup"),$=i(()=>{M(),_("aborted"),h(t)},"onAbort");e?.signal?.addEventListener("abort",$,{once:!0}),e?.timeout&&(y=setTimeout(()=>{M(),_("timeout"),h(t)},e.timeout)),g.set(a,{resolve:i((b,x="dialog")=>{M(),_(x,b),h(n(b))},"resolve"),reject:U,...p?{approval:p}:{}}),p&&c(p.request),c({type:"extension_ui_request",id:a,...s,...p?{approval:!0}:{}})})}i(v,"createDialogPromise");const j=i(()=>({select:i((e,t,s)=>v(s,void 0,{method:"select",title:e,options:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?void 0:"value"in n?n.value:void 0),"select"),confirm:i((e,t,s)=>v(s,!1,{method:"confirm",title:e,message:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?!1:"confirmed"in n?n.confirmed:!1),"confirm"),input:i((e,t,s)=>v(s,void 0,{method:"input",title:e,placeholder:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?void 0:"value"in n?n.value:void 0),"input"),notify(e,t){const s=K(e,t);c({type:"extension_ui_request",id:f.randomUUID(),method:"notify",message:s.message,notifyType:s.type})},setPanel(e,t){c({type:"extension_ui_request",id:f.randomUUID(),method:"setPanel",panelId:e,panel:t})},requestInput:i(e=>v(e,void 0,{method:"requestInput",title:e.title,placeholder:e.placeholder,timeout:e.timeout},t=>"cancelled"in t&&t.cancelled?void 0:"value"in t?t.value:void 0),"requestInput"),requestChoice:i(e=>v(e,void 0,{method:"requestChoice",title:e.title,items:e.items,timeout:e.timeout},t=>"cancelled"in t&&t.cancelled?void 0:"value"in t?t.value:void 0),"requestChoice"),onTerminalInput(){return()=>{}},setStatus(e,t){c({type:"extension_ui_request",id:f.randomUUID(),method:"setStatus",statusKey:e,statusText:t})},setWorkingMessage(e){},setWorkingVisible(e){},setWorkingIndicator(e){},setHiddenThinkingLabel(e){},setWidget(e,t,s){(t===void 0||Array.isArray(t))&&c({type:"extension_ui_request",id:f.randomUUID(),method:"setWidget",widgetKey:e,widgetLines:t,widgetPlacement:s?.placement})},setFooter(e){},setHeader(e){},setTitle(e){c({type:"extension_ui_request",id:f.randomUUID(),method:"setTitle",title:e})},async custom(){},pasteToEditor(e){this.setEditorText(e)},setEditorText(e){c({type:"extension_ui_request",id:f.randomUUID(),method:"set_editor_text",text:e})},getEditorText(){return""},async editor(e,t){const s=f.randomUUID();return new Promise((n,a)=>{g.set(s,{resolve:i(l=>{"cancelled"in l&&l.cancelled?n(void 0):"value"in l?n(l.value):n(void 0)},"resolve"),reject:a}),c({type:"extension_ui_request",id:s,method:"editor",title:e,prefill:t})})},addAutocompleteProvider(){},setEditorComponent(){},getEditorComponent(){},get theme(){return te},getAllThemes(){return[]},getTheme(e){},setTheme(e){return{success:!1,error:"Theme switching not supported in RPC mode"}},getToolsExpanded(){return!1},setToolsExpanded(e){}}),"createExtensionUIContext");u.setRebindSession(async()=>{await m()});const m=i(async()=>{o=u.session,T?.(),E?.(),T=o.subscribe(e=>{c(se(e)),e.type==="agent_settled"&&q()}),E=o.agent.subscribe(async()=>{await S()}),await o.bindExtensions({uiContext:j(),mode:"rpc",commandContextActions:{waitForIdle:i(()=>o.waitForIdle(),"waitForIdle"),newSession:i(async e=>u.newSession(e),"newSession"),fork:i(async(e,t)=>({cancelled:(await u.fork(e,t)).cancelled}),"fork"),navigateTree:i(async(e,t)=>({cancelled:(await o.navigateTree(e,{summarize:t?.summarize,customInstructions:t?.customInstructions,replaceInstructions:t?.replaceInstructions,label:t?.label})).cancelled}),"navigateTree"),switchSession:i(async(e,t)=>u.switchSession(e,t),"switchSession"),reload:i(async()=>{await o.reload()},"reload")},shutdownHandler:i(()=>{A=!0},"shutdownHandler"),onError:i(e=>{c({type:"extension_error",extensionPath:e.extensionPath,event:e.event,error:e.error})},"onError")})},"rebindSession"),G=i(()=>{const e=["SIGTERM","SIGINT"];process.platform!=="win32"&&e.push("SIGHUP");for(const t of e){const s=i(()=>{ee(),C(t==="SIGHUP"?129:t==="SIGINT"?130:143,t)},"handler");process.on(t,s),L.push(()=>process.off(t,s))}},"registerSignalHandlers");await m(),G();const J=i(async e=>{const t=e.id;switch(e.type){case"prompt":{let s=!1,n=!1;o.prompt(e.message,{images:e.images,streamingBehavior:e.streamingBehavior,source:"rpc",preflightResult:i(a=>{if(a==="cancelled"){n=!0;return}s=!0,c(r(t,"prompt",{disposition:a}))},"preflightResult")}).then(()=>{n&&!s&&c(d(t,"prompt",ce))},a=>{s||c(d(t,"prompt",a.message))});return}case"steer":{const s=await o.steer(e.message,e.images,{source:"rpc"});return r(t,"steer",{disposition:s})}case"follow_up":{const s=await o.followUp(e.message,e.images,{source:"rpc"});return r(t,"follow_up",{disposition:s})}case"abort":return await o.abort(),r(t,"abort");case"clear_queue":return r(t,"clear_queue",o.clearQueue());case"new_session":{const s=e.parentSession?{parentSession:e.parentSession}:void 0,n=await u.newSession(s);return n.cancelled||await m(),r(t,"new_session",n)}case"get_state":{const s={model:o.model,thinkingLevel:o.thinkingLevel,isStreaming:o.isStreaming,isCompacting:o.isCompacting,steeringMode:o.steeringMode,followUpMode:o.followUpMode,sessionFile:o.sessionFile,sessionId:o.sessionId,sessionName:o.sessionName,autoCompactionEnabled:o.autoCompactionEnabled,messageCount:o.messages.length,pendingMessageCount:o.pendingMessageCount};return r(t,"get_state",s)}case"set_model":{const n=o.modelRuntime.getAvailableSnapshot().find(a=>a.provider===e.provider&&a.id===e.modelId);return n?(await o.setModel(n),r(t,"set_model",n)):d(t,"set_model",`Model not found: ${e.provider}/${e.modelId}`)}case"cycle_model":{const s=await o.cycleModel();return s?r(t,"cycle_model",s):r(t,"cycle_model",null)}case"get_available_models":{const s=o.modelRuntime.getAvailableSnapshot();return r(t,"get_available_models",{models:s})}case"set_thinking_level":return o.setThinkingLevel(e.level),r(t,"set_thinking_level");case"cycle_thinking_level":{const s=o.cycleThinkingLevel();return s?r(t,"cycle_thinking_level",{level:s}):r(t,"cycle_thinking_level",null)}case"get_available_thinking_levels":{const s=o.getAvailableThinkingLevels();return r(t,"get_available_thinking_levels",{levels:s})}case"set_steering_mode":return o.setSteeringMode(e.mode),r(t,"set_steering_mode");case"set_follow_up_mode":return o.setFollowUpMode(e.mode),r(t,"set_follow_up_mode");case"compact":{const s=await o.compact(e.customInstructions);return r(t,"compact",s)}case"set_auto_compaction":return o.setAutoCompactionEnabled(e.enabled),r(t,"set_auto_compaction");case"set_auto_retry":return o.setAutoRetryEnabled(e.enabled),r(t,"set_auto_retry");case"abort_retry":return o.abortRetry(),r(t,"abort_retry");case"bash":{const s=await o.extensionRunner.emitUserBash({type:"user_bash",command:e.command,excludeFromContext:e.excludeFromContext??!1,cwd:o.sessionManager.getCwd()});if(s?.result)return o.recordBashResult(e.command,s.result,{excludeFromContext:e.excludeFromContext}),r(t,"bash",s.result);const n=await o.executeBash(e.command,void 0,{excludeFromContext:e.excludeFromContext,id:t,operations:s?.operations});return r(t,"bash",n)}case"abort_bash":return o.abortBash(),r(t,"abort_bash");case"get_sandbox_status":return r(t,"get_sandbox_status",o.getSandboxStatus()??null);case"list_background_processes":return r(t,"list_background_processes",{processes:o.backgroundProcesses.list()});case"read_background_process":{const{text:s,truncated:n,info:a}=o.backgroundProcesses.read(e.processId,e.tail!==void 0?{tail:e.tail}:{tail:200});return r(t,"read_background_process",{text:s,truncated:n,process:a})}case"stop_background_process":{const s=await o.backgroundProcesses.stop(e.processId);return r(t,"stop_background_process",{process:s})}case"get_session_stats":{const s=o.getSessionStats();return r(t,"get_session_stats",s)}case"export_html":{const s=await o.exportToHtml(e.outputPath);return r(t,"export_html",{path:s})}case"switch_session":{const s=await u.switchSession(e.sessionPath);return s.cancelled||await m(),r(t,"switch_session",s)}case"fork":{const s=await u.fork(e.entryId);return s.cancelled||await m(),r(t,"fork",{text:s.selectedText,cancelled:s.cancelled})}case"clone":{const s=o.sessionManager.getLeafId();if(!s)return d(t,"clone","Cannot clone session: no current entry selected");const n=await u.fork(s,{position:"at"});return n.cancelled||await m(),r(t,"clone",{cancelled:n.cancelled})}case"get_fork_messages":{const s=o.getUserMessagesForForking();return r(t,"get_fork_messages",{messages:s})}case"get_entries":{const s=o.sessionManager;let n=s.getEntries();if(e.since!==void 0){const a=n.findIndex(l=>l.id===e.since);if(a===-1)return d(t,"get_entries",`Entry not found: ${e.since}`);n=n.slice(a+1)}return r(t,"get_entries",{entries:n,leafId:s.getLeafId()})}case"get_tree":{const s=o.sessionManager;return r(t,"get_tree",{tree:s.getTree(),leafId:s.getLeafId()})}case"get_last_assistant_text":{const s=o.getLastAssistantText();return r(t,"get_last_assistant_text",{text:s})}case"set_session_name":{const s=e.name.trim();return s?(o.setSessionName(s),r(t,"set_session_name")):d(t,"set_session_name","Session name cannot be empty")}case"get_messages":{const s=o.messages,n=le(s,o.sessionManager.buildSessionProjection());return r(t,"get_messages",{messages:s,meta:n})}case"get_commands":{const s=[];for(const n of o.extensionRunner.getRegisteredCommands())s.push({name:n.invocationName,description:n.description,source:"extension",sourceInfo:n.sourceInfo});for(const n of o.promptTemplates)s.push({name:n.name,description:n.description,source:"prompt",sourceInfo:n.sourceInfo});for(const n of o.resourceLoader.getSkills().skills)s.push({name:`skill:${n.name}`,description:n.description,source:"skill",sourceInfo:n.sourceInfo});return r(t,"get_commands",{commands:s})}case"set_host_capabilities":{const s=N();return s.set("rpc",V(e.capabilities),O),r(t,"set_host_capabilities",{capabilities:s.list()})}case"set_environment":{const s=re({set:e.set,unset:e.unset});return r(t,"set_environment",{changed:s})}case"set_telemetry_consent":{const{usage:s,failures:n}=e;if(typeof s!="boolean"||n!==void 0&&typeof n!="boolean")return d(t,"set_telemetry_consent","set_telemetry_consent: usage must be a boolean, failures a boolean or omitted");const a=globalThis[Symbol.for("dalcode.telemetry.consentApi")];return a?r(t,"set_telemetry_consent",a.set({usage:s,failures:n})):d(t,"set_telemetry_consent","set_telemetry_consent: telemetry is not loaded in this engine")}case"get_permission_mode":case"set_permission_mode":{const s=globalThis[Symbol.for("dalcode.guard.modeApi")];if(!s)return d(t,e.type,`${e.type}: the permission extension is not loaded in this engine`);if(e.type==="get_permission_mode")return r(t,"get_permission_mode",s.get());const{mode:n,save:a}=e,l=s.set({mode:n,save:a});return"error"in l?d(t,"set_permission_mode",`set_permission_mode: ${l.error}`):r(t,"set_permission_mode",l)}case"approval_response":{const s=g.get(e.id);if(s?.approval){const a=s.approval.request.options.find(l=>l.id===e.optionId);return a?(s.resolve(s.approval.responseFor(a.kind),"approval_response"),r(t,"approval_response",{accepted:!0,optionId:a.kind,via:"approval_response"})):d(t,"approval_response",`Unknown option ${String(e.optionId)} for approval ${e.id}; expected one of ${s.approval.request.options.map(l=>l.id).join(", ")}`)}const n=R.get(e.id);return n?r(t,"approval_response",{accepted:!1,...n}):d(t,"approval_response",`Unknown approval: ${e.id}`)}default:{const s=e;return d(t,s.type,`Unknown command: ${s.type}`)}}},"handleCommand");let F=i(()=>{},"detachInput");async function C(e=0,t){P&&process.exit(e),P=!0;for(const s of L)s();T?.(),E?.(),N().clear("rpc");for(const s of w.values())s.reject(new k("unavailable","RPC host disconnected"));await u.dispose(),F(),process.stdin.pause(),t!=="SIGTERM"&&await X(),process.exit(e)}i(C,"shutdown");async function q(){A&&await C()}i(q,"checkShutdownRequested");const W=i(async e=>{let t;try{t=JSON.parse(e)}catch(n){c(d(void 0,"parse",`Failed to parse command: ${n instanceof Error?n.message:String(n)}`)),await S();return}if(typeof t=="object"&&t!==null&&"type"in t&&t.type==="extension_ui_response"){const n=t,a=g.get(n.id);a&&(g.delete(n.id),a.resolve(n));return}if(typeof t=="object"&&t!==null&&"type"in t&&t.type==="host_response"){const n=t,a=w.get(n.id);a&&("error"in n?a.reject(new k("host_error",String(n.error))):a.resolve(n.result));return}const s=t;try{const n=await J(s);n&&(c(n),await S()),await q()}catch(n){c(d(s.id,s.type,n instanceof Error?n.message:String(n))),await S()}},"handleInputLine"),D=i(()=>{C()},"onInputEnd");return process.stdin.on("end",D),F=(()=>{const e=ie(process.stdin,t=>{W(t)});return()=>{e(),process.stdin.off("end",D)}})(),new Promise(()=>{})}i(we,"runRpcMode");export{ce as PROMPT_ABORTED_BEFORE_START,we as runRpcMode};
|
|
1
|
+
var z=Object.defineProperty;var a=(u,o)=>z(u,"name",{value:o,configurable:!0});import*as f from"node:crypto";import{RequiredExtensionError as K,resolveExtensionNotify as Q}from"../../core/extensions/index.js";import{DEFAULT_HOST_CALL_TIMEOUT_MS as V,getHostCapabilities as N,HostCallError as k,parseHostCapabilities as X}from"../../core/host-capabilities.js";import{flushRawStdout as Y,takeOverStdout as Z,waitForRawStdoutBackpressure as S,writeRawStdout as ee}from"../../core/output-guard.js";import{killTrackedDetachedChildren as te}from"../../utils/shell.js";import{theme as se}from"../interactive/theme/theme.js";import{toJsonEvent as ne}from"../json-event.js";import{openApproval as oe,ResolvedApprovals as re}from"./approvals.js";import{applyEnvironmentUpdate as ie}from"./environment-update.js";import{attachJsonlLineReader as ae,serializeJsonLine as le}from"./jsonl.js";import{buildMessageMeta as ce}from"./message-meta.js";const de="Prompt aborted before it started";async function xe(u){Z();let o=u.session,T,E;const c=a(e=>{ee(le(e))},"output"),r=a((e,t,s)=>s===void 0?{id:e,type:"response",command:t,success:!0}:{id:e,type:"response",command:t,success:!0,data:s},"success"),d=a((e,t,s,n)=>n instanceof K?{id:e,type:"response",command:t,success:!1,error:s,code:n.code,extensionError:{extensionPath:n.extensionError.extensionPath,event:n.extensionError.event,error:n.extensionError.error}}:{id:e,type:"response",command:t,success:!1,error:s},"error"),g=new Map,R=new re,w=new Map,O=a((e,t)=>{const s=f.randomUUID();return new Promise((n,i)=>{const l=a(()=>{clearTimeout(U),t.signal?.removeEventListener("abort",h),w.delete(s)},"cleanup"),p=a(_=>{l(),c({type:"host_request_cancelled",id:s}),i(_)},"giveUp"),h=a(()=>p(new k("aborted","host call aborted")),"onAbort"),U=setTimeout(()=>p(new k("timeout","host did not answer in time")),t.timeoutMs??V);t.signal?.addEventListener("abort",h,{once:!0}),w.set(s,{resolve:a(_=>{l(),n(_)},"resolve"),reject:a(_=>{l(),i(_)},"reject")});const y={type:"host_request",id:s,capability:e.capability,method:e.method,params:e.params};c(y)})},"rpcHostTransport");let P=!1,A=!1;const L=[];function v(e,t,s,n){if(e?.signal?.aborted)return Promise.resolve(t);const i=f.randomUUID(),l=s.method,p=e?.approval&&(l==="select"||l==="confirm")?oe(i,l,e.approval,{options:Array.isArray(s.options)?s.options:void 0,timeout:e.timeout}):void 0;return new Promise((h,U)=>{let y;const _=a((b,x)=>{if(!p)return;const I=x?p.kindOf(x):void 0,B=b==="dialog"&&!I?"cancelled":b;R.remember(i,I,B);const H={type:"approval_resolved",id:i,...I?{optionId:I}:{},via:B};c(H)},"settleApproval"),M=a(()=>{y&&clearTimeout(y),e?.signal?.removeEventListener("abort",$),g.delete(i)},"cleanup"),$=a(()=>{M(),_("aborted"),h(t)},"onAbort");e?.signal?.addEventListener("abort",$,{once:!0}),e?.timeout&&(y=setTimeout(()=>{M(),_("timeout"),h(t)},e.timeout)),g.set(i,{resolve:a((b,x="dialog")=>{M(),_(x,b),h(n(b))},"resolve"),reject:U,...p?{approval:p}:{}}),p&&c(p.request),c({type:"extension_ui_request",id:i,...s,...p?{approval:!0}:{}})})}a(v,"createDialogPromise");const j=a(()=>({select:a((e,t,s)=>v(s,void 0,{method:"select",title:e,options:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?void 0:"value"in n?n.value:void 0),"select"),confirm:a((e,t,s)=>v(s,!1,{method:"confirm",title:e,message:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?!1:"confirmed"in n?n.confirmed:!1),"confirm"),input:a((e,t,s)=>v(s,void 0,{method:"input",title:e,placeholder:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?void 0:"value"in n?n.value:void 0),"input"),notify(e,t){const s=Q(e,t);c({type:"extension_ui_request",id:f.randomUUID(),method:"notify",message:s.message,notifyType:s.type})},setPanel(e,t){c({type:"extension_ui_request",id:f.randomUUID(),method:"setPanel",panelId:e,panel:t})},requestInput:a(e=>v(e,void 0,{method:"requestInput",title:e.title,placeholder:e.placeholder,timeout:e.timeout},t=>"cancelled"in t&&t.cancelled?void 0:"value"in t?t.value:void 0),"requestInput"),requestChoice:a(e=>v(e,void 0,{method:"requestChoice",title:e.title,items:e.items,timeout:e.timeout},t=>"cancelled"in t&&t.cancelled?void 0:"value"in t?t.value:void 0),"requestChoice"),onTerminalInput(){return()=>{}},setStatus(e,t){c({type:"extension_ui_request",id:f.randomUUID(),method:"setStatus",statusKey:e,statusText:t})},setWorkingMessage(e){},setWorkingVisible(e){},setWorkingIndicator(e){},setHiddenThinkingLabel(e){},setWidget(e,t,s){(t===void 0||Array.isArray(t))&&c({type:"extension_ui_request",id:f.randomUUID(),method:"setWidget",widgetKey:e,widgetLines:t,widgetPlacement:s?.placement})},setFooter(e){},setHeader(e){},setTitle(e){c({type:"extension_ui_request",id:f.randomUUID(),method:"setTitle",title:e})},async custom(){},pasteToEditor(e){this.setEditorText(e)},setEditorText(e){c({type:"extension_ui_request",id:f.randomUUID(),method:"set_editor_text",text:e})},getEditorText(){return""},async editor(e,t){const s=f.randomUUID();return new Promise((n,i)=>{g.set(s,{resolve:a(l=>{"cancelled"in l&&l.cancelled?n(void 0):"value"in l?n(l.value):n(void 0)},"resolve"),reject:i}),c({type:"extension_ui_request",id:s,method:"editor",title:e,prefill:t})})},addAutocompleteProvider(){},setEditorComponent(){},getEditorComponent(){},get theme(){return se},getAllThemes(){return[]},getTheme(e){},setTheme(e){return{success:!1,error:"Theme switching not supported in RPC mode"}},getToolsExpanded(){return!1},setToolsExpanded(e){}}),"createExtensionUIContext");u.setRebindSession(async()=>{await m()});const m=a(async()=>{o=u.session,T?.(),E?.(),T=o.subscribe(e=>{c(ne(e)),e.type==="agent_settled"&&F()}),E=o.agent.subscribe(async()=>{const e=o.enterStallStage("host:stdout","host");try{await S()}finally{e()}}),await o.bindExtensions({uiContext:j(),mode:"rpc",commandContextActions:{waitForIdle:a(()=>o.waitForIdle(),"waitForIdle"),newSession:a(async e=>u.newSession(e),"newSession"),fork:a(async(e,t)=>({cancelled:(await u.fork(e,t)).cancelled}),"fork"),navigateTree:a(async(e,t)=>({cancelled:(await o.navigateTree(e,{summarize:t?.summarize,customInstructions:t?.customInstructions,replaceInstructions:t?.replaceInstructions,label:t?.label})).cancelled}),"navigateTree"),switchSession:a(async(e,t)=>u.switchSession(e,t),"switchSession"),reload:a(async()=>{await o.reload()},"reload")},shutdownHandler:a(()=>{P=!0},"shutdownHandler"),onError:a(e=>{const t={type:"extension_error",extensionPath:e.extensionPath,event:e.event,error:e.error};e.fatal&&(t.fatal=!0),c(t)},"onError")})},"rebindSession"),G=a(()=>{const e=["SIGTERM","SIGINT"];process.platform!=="win32"&&e.push("SIGHUP");for(const t of e){const s=a(()=>{te(),C(t==="SIGHUP"?129:t==="SIGINT"?130:143,t)},"handler");process.on(t,s),L.push(()=>process.off(t,s))}},"registerSignalHandlers");await m(),G();const J=a(async e=>{const t=e.id;switch(e.type){case"prompt":{let s=!1,n=!1;o.prompt(e.message,{images:e.images,streamingBehavior:e.streamingBehavior,source:"rpc",preflightResult:a(i=>{if(i==="cancelled"){n=!0;return}s=!0,c(r(t,"prompt",{disposition:i}))},"preflightResult")}).then(()=>{n&&!s&&c(d(t,"prompt",de))},i=>{s||c(d(t,"prompt",i.message,i))});return}case"steer":{const s=await o.steer(e.message,e.images,{source:"rpc"});return r(t,"steer",{disposition:s})}case"follow_up":{const s=await o.followUp(e.message,e.images,{source:"rpc"});return r(t,"follow_up",{disposition:s})}case"abort":return await o.abort(),r(t,"abort");case"clear_queue":return r(t,"clear_queue",o.clearQueue());case"new_session":{const s=e.parentSession?{parentSession:e.parentSession}:void 0,n=await u.newSession(s);return n.cancelled||await m(),r(t,"new_session",n)}case"get_state":{const s={model:o.model,thinkingLevel:o.thinkingLevel,isStreaming:o.isStreaming,isCompacting:o.isCompacting,steeringMode:o.steeringMode,followUpMode:o.followUpMode,sessionFile:o.sessionFile,sessionId:o.sessionId,sessionName:o.sessionName,autoCompactionEnabled:o.autoCompactionEnabled,messageCount:o.messages.length,pendingMessageCount:o.pendingMessageCount};return r(t,"get_state",s)}case"set_model":{const n=o.modelRuntime.getAvailableSnapshot().find(i=>i.provider===e.provider&&i.id===e.modelId);return n?(await o.setModel(n),r(t,"set_model",n)):d(t,"set_model",`Model not found: ${e.provider}/${e.modelId}`)}case"cycle_model":{const s=await o.cycleModel();return s?r(t,"cycle_model",s):r(t,"cycle_model",null)}case"get_available_models":{const s=o.modelRuntime.getAvailableSnapshot();return r(t,"get_available_models",{models:s})}case"set_thinking_level":return o.setThinkingLevel(e.level),r(t,"set_thinking_level");case"cycle_thinking_level":{const s=o.cycleThinkingLevel();return s?r(t,"cycle_thinking_level",{level:s}):r(t,"cycle_thinking_level",null)}case"get_available_thinking_levels":{const s=o.getAvailableThinkingLevels();return r(t,"get_available_thinking_levels",{levels:s})}case"set_steering_mode":return o.setSteeringMode(e.mode),r(t,"set_steering_mode");case"set_follow_up_mode":return o.setFollowUpMode(e.mode),r(t,"set_follow_up_mode");case"compact":{const s=await o.compact(e.customInstructions);return r(t,"compact",s)}case"set_auto_compaction":return o.setAutoCompactionEnabled(e.enabled),r(t,"set_auto_compaction");case"set_auto_retry":return o.setAutoRetryEnabled(e.enabled),r(t,"set_auto_retry");case"abort_retry":return o.abortRetry(),r(t,"abort_retry");case"bash":{const s=await o.extensionRunner.emitUserBash({type:"user_bash",command:e.command,excludeFromContext:e.excludeFromContext??!1,cwd:o.sessionManager.getCwd()});if(s?.result)return o.recordBashResult(e.command,s.result,{excludeFromContext:e.excludeFromContext}),r(t,"bash",s.result);const n=await o.executeBash(e.command,void 0,{excludeFromContext:e.excludeFromContext,id:t,operations:s?.operations});return r(t,"bash",n)}case"abort_bash":return o.abortBash(),r(t,"abort_bash");case"get_sandbox_status":return r(t,"get_sandbox_status",o.getSandboxStatus()??null);case"list_background_processes":return r(t,"list_background_processes",{processes:o.backgroundProcesses.list()});case"read_background_process":{const{text:s,truncated:n,info:i}=o.backgroundProcesses.read(e.processId,e.tail!==void 0?{tail:e.tail}:{tail:200});return r(t,"read_background_process",{text:s,truncated:n,process:i})}case"stop_background_process":{const s=await o.backgroundProcesses.stop(e.processId);return r(t,"stop_background_process",{process:s})}case"get_session_stats":{const s=o.getSessionStats();return r(t,"get_session_stats",s)}case"export_html":{const s=await o.exportToHtml(e.outputPath);return r(t,"export_html",{path:s})}case"switch_session":{const s=await u.switchSession(e.sessionPath);return s.cancelled||await m(),r(t,"switch_session",s)}case"fork":{const s=await u.fork(e.entryId);return s.cancelled||await m(),r(t,"fork",{text:s.selectedText,cancelled:s.cancelled})}case"clone":{const s=o.sessionManager.getLeafId();if(!s)return d(t,"clone","Cannot clone session: no current entry selected");const n=await u.fork(s,{position:"at"});return n.cancelled||await m(),r(t,"clone",{cancelled:n.cancelled})}case"get_fork_messages":{const s=o.getUserMessagesForForking();return r(t,"get_fork_messages",{messages:s})}case"get_entries":{const s=o.sessionManager;let n=s.getEntries();if(e.since!==void 0){const i=n.findIndex(l=>l.id===e.since);if(i===-1)return d(t,"get_entries",`Entry not found: ${e.since}`);n=n.slice(i+1)}return r(t,"get_entries",{entries:n,leafId:s.getLeafId()})}case"get_tree":{const s=o.sessionManager;return r(t,"get_tree",{tree:s.getTree(),leafId:s.getLeafId()})}case"get_last_assistant_text":{const s=o.getLastAssistantText();return r(t,"get_last_assistant_text",{text:s})}case"set_session_name":{const s=e.name.trim();return s?(o.setSessionName(s),r(t,"set_session_name")):d(t,"set_session_name","Session name cannot be empty")}case"get_messages":{const s=o.messages,n=ce(s,o.sessionManager.buildSessionProjection());return r(t,"get_messages",{messages:s,meta:n})}case"get_commands":{const s=[];for(const n of o.extensionRunner.getRegisteredCommands())s.push({name:n.invocationName,description:n.description,source:"extension",sourceInfo:n.sourceInfo});for(const n of o.promptTemplates)s.push({name:n.name,description:n.description,source:"prompt",sourceInfo:n.sourceInfo});for(const n of o.resourceLoader.getSkills().skills)s.push({name:`skill:${n.name}`,description:n.description,source:"skill",sourceInfo:n.sourceInfo});return r(t,"get_commands",{commands:s})}case"set_host_capabilities":{const s=N();return s.set("rpc",X(e.capabilities),O),r(t,"set_host_capabilities",{capabilities:s.list()})}case"set_environment":{const s=ie({set:e.set,unset:e.unset});return r(t,"set_environment",{changed:s})}case"set_telemetry_consent":{const{usage:s,failures:n}=e;if(typeof s!="boolean"||n!==void 0&&typeof n!="boolean")return d(t,"set_telemetry_consent","set_telemetry_consent: usage must be a boolean, failures a boolean or omitted");const i=globalThis[Symbol.for("dalcode.telemetry.consentApi")];return i?r(t,"set_telemetry_consent",i.set({usage:s,failures:n})):d(t,"set_telemetry_consent","set_telemetry_consent: telemetry is not loaded in this engine")}case"get_permission_mode":case"set_permission_mode":{const s=globalThis[Symbol.for("dalcode.guard.modeApi")];if(!s)return d(t,e.type,`${e.type}: the permission extension is not loaded in this engine`);if(e.type==="get_permission_mode")return r(t,"get_permission_mode",s.get());const{mode:n,save:i}=e,l=s.set({mode:n,save:i});return"error"in l?d(t,"set_permission_mode",`set_permission_mode: ${l.error}`):r(t,"set_permission_mode",l)}case"approval_response":{const s=g.get(e.id);if(s?.approval){const i=s.approval.request.options.find(l=>l.id===e.optionId);return i?(s.resolve(s.approval.responseFor(i.kind),"approval_response"),r(t,"approval_response",{accepted:!0,optionId:i.kind,via:"approval_response"})):d(t,"approval_response",`Unknown option ${String(e.optionId)} for approval ${e.id}; expected one of ${s.approval.request.options.map(l=>l.id).join(", ")}`)}const n=R.get(e.id);return n?r(t,"approval_response",{accepted:!1,...n}):d(t,"approval_response",`Unknown approval: ${e.id}`)}default:{const s=e;return d(t,s.type,`Unknown command: ${s.type}`)}}},"handleCommand");let q=a(()=>{},"detachInput");async function C(e=0,t){A&&process.exit(e),A=!0;for(const s of L)s();T?.(),E?.(),N().clear("rpc");for(const s of w.values())s.reject(new k("unavailable","RPC host disconnected"));await u.dispose(),q(),process.stdin.pause(),t!=="SIGTERM"&&await Y(),process.exit(e)}a(C,"shutdown");async function F(){P&&await C()}a(F,"checkShutdownRequested");const W=a(async e=>{let t;try{t=JSON.parse(e)}catch(n){c(d(void 0,"parse",`Failed to parse command: ${n instanceof Error?n.message:String(n)}`)),await S();return}if(typeof t=="object"&&t!==null&&"type"in t&&t.type==="extension_ui_response"){const n=t,i=g.get(n.id);i&&(g.delete(n.id),i.resolve(n));return}if(typeof t=="object"&&t!==null&&"type"in t&&t.type==="host_response"){const n=t,i=w.get(n.id);i&&("error"in n?i.reject(new k("host_error",String(n.error))):i.resolve(n.result));return}const s=t;try{const n=await J(s);n&&(c(n),await S()),await F()}catch(n){c(d(s.id,s.type,n instanceof Error?n.message:String(n),n)),await S()}},"handleInputLine"),D=a(()=>{C()},"onInputEnd");return process.stdin.on("end",D),q=(()=>{const e=ae(process.stdin,t=>{W(t)});return()=>{e(),process.stdin.off("end",D)}})(),new Promise(()=>{})}a(xe,"runRpcMode");export{de as PROMPT_ABORTED_BEFORE_START,xe as runRpcMode};
|
|
@@ -522,7 +522,21 @@ export type RpcResponse = {
|
|
|
522
522
|
command: string;
|
|
523
523
|
success: false;
|
|
524
524
|
error: string;
|
|
525
|
+
code?: RpcErrorCode;
|
|
526
|
+
extensionError?: {
|
|
527
|
+
extensionPath: string;
|
|
528
|
+
event: string;
|
|
529
|
+
error: string;
|
|
530
|
+
};
|
|
525
531
|
};
|
|
532
|
+
export type RpcErrorCode = "required_extension_failed";
|
|
533
|
+
export interface RpcExtensionErrorEvent {
|
|
534
|
+
type: "extension_error";
|
|
535
|
+
extensionPath: string;
|
|
536
|
+
event: string;
|
|
537
|
+
error: string;
|
|
538
|
+
fatal?: true;
|
|
539
|
+
}
|
|
526
540
|
export type RpcExtensionUIRequest = {
|
|
527
541
|
type: "extension_ui_request";
|
|
528
542
|
id: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-advisor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.47",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "advisor: the model asks another strong model to review its current plan and point out risks. Adapted from @juicesharp/rpiv-advisor 2.13.8 (MIT).",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
]
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
24
|
-
"@dalcode/dal-router": "1.0.
|
|
23
|
+
"@dalcode/dal-pi-kit": "1.0.47",
|
|
24
|
+
"@dalcode/dal-router": "1.0.47",
|
|
25
25
|
"typebox": "1.3.27"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-awake",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.47",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Keeps the computer from going to sleep while a long agent run is in progress, and lets it sleep again when the run ends. Adapted from @narumitw/pi-caffeinate (MIT).",
|
|
6
6
|
"type": "module",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
]
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
21
|
+
"@dalcode/dal-pi-kit": "1.0.47"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@earendil-works/pi-coding-agent": "^1.0.9"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-bridge",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.47",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
]
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
21
|
+
"@dalcode/dal-pi-kit": "1.0.47",
|
|
22
22
|
"typebox": "1.3.7"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-capabilities",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.47",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Capability center for DAL: switches on the reviewed MCP connectors, skills and engine packages a task needs (installed automatically from the signed DAL market), with /capabilities to list, disable and enable them.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
]
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@dalcode/dal-mcp": "1.0.
|
|
27
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
28
|
-
"@dalcode/deepailab": "1.0.
|
|
26
|
+
"@dalcode/dal-mcp": "1.0.47",
|
|
27
|
+
"@dalcode/dal-pi-kit": "1.0.47",
|
|
28
|
+
"@dalcode/deepailab": "1.0.47"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@earendil-works/pi-coding-agent": "^1.0.9"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var z=Object.defineProperty;var o=(t,u)=>z(t,"name",{value:u,configurable:!0});var S=Object.defineProperty,n=o((t,u)=>S(t,"name",{value:u,configurable:!0}),"a");import{readSignedSection as N}from"@earendil-works/pi-coding-agent";import{pinnedPackageArg as $}from"./install.js";function c(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}o(c,"d"),n(c,"isRecord");function r(t){return typeof t=="string"&&t.trim()?t.trim():void 0}o(r,"i"),n(r,"text");function f(t){return Array.isArray(t)?t.filter(u=>typeof u=="string"):[]}o(f,"g"),n(f,"strings");const L=["write","credentials","account","delete","git-clean","messages","payments","download"];function g(t){if(!Array.isArray(t.risk))return["unreviewed"];const u=new Set;for(const e of t.risk){const i=typeof e=="string"?L.find(s=>s===e.trim()):void 0;u.add(i??"unreviewed")}return[...u]}o(g,"h"),n(g,"riskOf");function m(t){const u=t.activation;if(!c(u))return;const e=r(u.hint);if(!e)return;const i=f(u.keywords).map(s=>s.trim()).filter(Boolean).slice(0,20);return{hint:e,keywords:i}}o(m,"f"),n(m,"activationOf");function B(t){if(!Array.isArray(t))return[];const u=[];for(const e of t){if(!c(e))continue;const i=r(e.key),s=r(e.label),a=e.target==="header"||e.target==="arg"?e.target:e.target==="env"?"env":void 0;!i||!s||!a||u.push({key:i,target:a,label:s,required:e.required===!0,secret:e.secret===!0,...r(e.template)?{template:r(e.template)}:{},...r(e.help)?{help:r(e.help)}:{},...r(e.placeholder)?{placeholder:r(e.placeholder)}:{}})}return u}o(B,"S"),n(B,"inputsOf");function A(t){const u={};if(!c(t))return u;for(const[e,i]of Object.entries(t))typeof i=="string"&&(u[e]=i);return u}o(A,"P"),n(A,"stringRecord");const h=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/,w=/^sha512-[A-Za-z0-9+/]{86}==$/,T=/^[0-9a-f]{64}$/,j=/^[a-z0-9][a-z0-9-]{0,40}$/;function E(t,u,e){return e.some(i=>i.id===t&&(i.version==="*"||i.version===u))}o(E,"O"),n(E,"isRevoked");function C(t){const u=r(t.id),e=m(t);if(!u||!h.test(u)||!e)return;const i=c(t.install)?t.install:t,s=t.transport==="http"?"http":"stdio",a=s==="http"?r(t.url)??r(i.url):void 0,p=r(i.command)??"";if(s==="http"?!a?.startsWith("https://"):!p)return;const l=r(t.summary)??r(t.description),d=c(t.source)?t.source:void 0,F=r(d?.spec),R=$(f(i.args))?.replace(/^npm:/,""),b=!F||F.replace(/^npm:/,"")===R,y=b?r(d?.integrity)??r(t.integrity):void 0,k=b?(r(d?.sha256)??r(t.sha256))?.toLowerCase():void 0;return{id:u,kind:"mcp",name:r(t.displayName)??r(t.name)??u,hint:e.hint,keywords:e.keywords,...l?{summary:l}:{},...r(t.category)?{category:r(t.category)}:{},risk:g(t),inputs:B(t.inputs),mcp:{transport:s,command:s==="http"?"":p,args:s==="http"?[]:f(i.args),env:s==="http"?{}:A(i.env),...a?{url:a}:{},...y&&w.test(y)?{integrity:y}:{},...k&&T.test(k)?{sha256:k}:{}},installable:t.installable!==!1}}o(C,"F"),n(C,"mcpRow");function D(t){const u=r(t.id),e=m(t);if(!(!u||!h.test(u)||!e))return{id:u,kind:"skill",name:r(t.displayName)??r(t.name)??u,hint:e.hint,keywords:e.keywords,risk:[],inputs:[],installable:!1}}o(D,"_"),n(D,"skillRow");function x(t){const u=r(t.id),e=m(t);if(!u||!h.test(u)||!e)return;const i=t.source,s=typeof i=="string"?i:c(i)?r(i.spec):r(t.spec),a=c(i)?r(i.integrity):r(t.integrity),p=r(t.summary)??r(t.description),l=r(t.exclusiveGroup),d=l&&j.test(l)?l:void 0;return{id:u,kind:"package",name:r(t.displayName)??r(t.name)??u,hint:e.hint,keywords:e.keywords,...p?{summary:p}:{},risk:g(t),inputs:[],...s?{packageSpec:s.replace(/^npm:/,"")}:{},...a&&w.test(a)?{packageIntegrity:a}:{},installable:t.installable!==!1&&!!s&&!!a,...d?{exclusiveGroup:d}:{}}}o(x,"z"),n(x,"packageRow");function I(t){return r(t.version)}o(I,"G"),n(I,"rowVersion");function v(t){const u=t.section==="mcp"?C:t.section==="skills"?D:x,e=[];for(const i of t.rows){const s=u(i);s&&(E(s.id,I(i),t.revoked)||e.push(s))}return e}o(v,"L"),n(v,"capabilitiesOf");const O=[{id:"office",kind:"builtin",name:"\u529E\u516C\u6587\u6863",hint:"\u8981\u751F\u6210\u3001\u8BFB\u53D6\u6216\u4FEE\u6539 PPT\u3001Word\u3001Excel \u6587\u6863\u6216\u56FE\u8868\u65F6\u542F\u7528\u3002",keywords:["PPT","\u5E7B\u706F\u7247","Word","docx","Excel","xlsx","\u8868\u683C","\u6F14\u793A\u6587\u7A3F","\u62A5\u544A\u6587\u6863"],risk:[],inputs:[],installable:!1},{id:"web",kind:"builtin",name:"\u8054\u7F51",hint:"\u8981\u641C\u7D22\u7F51\u9875\u6216\u8BFB\u53D6\u7F51\u9875\u5185\u5BB9\u65F6\u542F\u7528\u3002",keywords:["\u8054\u7F51","\u641C\u7D22\u4E00\u4E0B","\u4E0A\u7F51\u67E5","\u7F51\u9875\u5185\u5BB9","\u6700\u65B0\u6D88\u606F","\u8BFB\u4E00\u4E0B\u8FD9\u4E2A\u94FE\u63A5"],risk:[],inputs:[],installable:!1},{id:"debug",kind:"builtin",name:"\u8C03\u8BD5\u5668",hint:"\u8981\u7528\u8C03\u8BD5\u5668\u65AD\u70B9\u3001\u5355\u6B65\u8FD0\u884C\u7A0B\u5E8F\uFF0C\u67E5\u770B\u8FD0\u884C\u65F6\u53D8\u91CF\u7684\u503C\u65F6\u542F\u7528\u3002",keywords:["\u8C03\u8BD5\u5668","\u65AD\u70B9","\u5355\u6B65","debugger","breakpoint","debugpy","\u8C03\u7528\u6808"],risk:[],inputs:[],installable:!1}];function P(t={}){const u=[...O],e={};for(const i of["mcp","skills","packages"]){const s=N(i,t);if(!s.ok){e[i]=s.reason;continue}e[i]=`v${s.value.catalogVersion}`,u.push(...v(s.value))}return{capabilities:u,sources:e}}o(P,"q"),n(P,"readInventory");export{O as BUILTIN_CAPABILITIES,v as capabilitiesOf,P as readInventory};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var
|
|
2
|
-
${
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
${
|
|
6
|
-
${
|
|
7
|
-
</skill>`))}if(!p&&s.tied.length===0&&n.length===0&&
|
|
1
|
+
var vu=Object.defineProperty;var B=(d,D)=>vu(d,"name",{value:D,configurable:!0});var Iu=Object.defineProperty,c=B((d,D)=>Iu(d,"name",{value:D,configurable:!0}),"c");import{readFileSync as z}from"node:fs";import{join as Q}from"node:path";import{loadMcpServerConfigs as $u,takeMcpConfigProblems as Su}from"@dalcode/dal-mcp/config";import{t as r,tm as x}from"@dalcode/dal-pi-kit";import{defaultConfig as Tu}from"@dalcode/deepailab/oidc";import{appendAgentLog as xu,CONFIG_DIR_NAME as j,DefaultPackageManager as ju,ENGINE_MARKET_CACHE_FILE as _u,fetchSignedMarket as Mu,getAgentDir as Pu,marketCacheDir as Lu,resolveMarketEndpoint as Nu,SettingsManager as Ru,tryEnsurePackageAdapted as Ou}from"@earendil-works/pi-coding-agent";import{readInventory as X}from"./catalogue.js";import{autoInstallBlocker as Z,buildMcpEntry as qu,checkReachable as Uu,chooseRegistry as Wu,endpointOf as Gu,pinOf as R,removeMcpEntry as Hu,setMcpEntryDisabled as uu,userMcpEntries as Vu,userRegistries as Ku,writeMcpEntry as Yu}from"./install.js";import{breakTieByProject as eu,buildIndex as tu,route as Ju,scoreRequest as au}from"./match.js";import{isCiLike as iu,markApproved as zu,markDeclined as nu,markDisabled as ru,markInstalled as ou,markUninstalled as Qu,readSettings as _,readState as su,writeAutoInstall as Xu}from"./state.js";import{BUILTIN_CAPABILITIES as Zu,capabilitiesOf as ue,readInventory as ee}from"./catalogue.js";import{buildIndex as te,route as ae,scoreRequest as ie}from"./match.js";function lu(){return globalThis[Symbol.for("dalcode.tool-catalog.api")]}B(lu,"qe"),c(lu,"toolCatalog");function cu(){return globalThis[Symbol.for("dalcode.mcp.api")]}B(cu,"Ge"),c(cu,"mcpRuntime");function Fu(d,D){return globalThis[Symbol.for("dalcode.guard.modeApi")]?.wouldAsk?.(`mcp__${d}__call`,D)===!0}B(Fu,"He"),c(Fu,"guardRefusesMcp");function du(){return globalThis[Symbol.for("dalcode.skills.search")]}B(du,"Ke"),c(du,"skillSearch");const ne={write:"\u4F1A\u4FEE\u6539\u6587\u4EF6\u6216\u4ED3\u5E93",credentials:"\u4F1A\u4F7F\u7528\u4F60\u7684\u51ED\u636E",account:"\u4F1A\u64CD\u4F5C\u4F60\u7684\u5916\u90E8\u8D26\u53F7",delete:"\u53EF\u80FD\u5220\u9664\u6570\u636E","git-clean":"\u53EF\u80FD\u6267\u884C git clean \u5220\u9664\u672A\u63D0\u4EA4\u7684\u6587\u4EF6",messages:"\u4F1A\u4EE5\u4F60\u7684\u540D\u4E49\u53D1\u9001\u6D88\u606F",payments:"\u6D89\u53CA\u652F\u4ED8",download:"\u542F\u7528\u524D\u8981\u4E0B\u8F7D\u8F83\u5927\u7684\u8FD0\u884C\u65F6\u3001\u6D4F\u89C8\u5668\u6216\u6A21\u578B",unreviewed:"\u8FD8\u6CA1\u6709\u7ECF\u8FC7\u98CE\u9669\u5BA1\u6838"},re=["package.json",".env",".env.example",".env.local","docker-compose.yml","docker-compose.yaml","compose.yaml","pyproject.toml","requirements.txt","prisma/schema.prisma","go.mod","Cargo.toml","Gemfile","application.yml","application.properties"];function O(d){let D="";for(const A of re)try{D+=`
|
|
2
|
+
${z(Q(d,A),"utf8").slice(0,64*1024)}`}catch{}return D}B(O,"ae"),c(O,"readProjectText");const oe=/(接入|对接|集成|打通|调用.{0,12}(api|接口)|连上|连接到|没有.{0,6}工具|需要.{0,6}工具|做一个.{0,8}工具|integrate with|connect to|a tool (to|that|for))/i,se=360*60*1e3;function pu(d,D){try{const A=JSON.parse(z(Q(Lu(d),_u),"utf8")),E=Object.values(A.sections??{}).map(k=>Date.parse(k.fetchedAt??"")).filter(k=>!Number.isNaN(k));return E.length===3?D-Math.min(...E):Number.POSITIVE_INFINITY}catch{return Number.POSITIVE_INFINITY}}B(pu,"Qe"),c(pu,"engineCacheAgeMs");const mu=Symbol.for("dalcode.capabilities.handle"),Eu="capabilities_route",fu="capabilities_install";function Du(){return globalThis[mu]}B(Du,"gn"),c(Du,"capabilitiesHandle");function q(d={}){return D=>{const A=d.env??process.env;let E;const k={settled:c(async()=>{for(let e=0;e<5&&E;e++){const u=E.pending;if(await u,E.pending===u)break}},"settled"),inventory:c(()=>E?.inventory,"inventory")};globalThis[mu]=k;const M=c(e=>{E&&(E.pending=Promise.all([E.pending,e.then(()=>{},()=>{})]).then(()=>{}))},"later"),w=c((e,u,t="info")=>{e.hasUI?e.ui.notify(u,t):xu("capabilities",u,{level:t})},"say"),v=c((e,u,t="info")=>{E===e&&w(e.ctx,u,t)},"sayInSession"),y=c((e,u,t)=>{const i={id:e.id,name:e.name,kind:e.kind,status:u,...t!==void 0?{error:t instanceof Error?t.message:String(t)}:{}};D.emitHostEvent(fu,i)},"installEvent"),h=c((e,u,t,i="info")=>{e.noted.has(u)||(e.noted.add(u),w(e.ctx,t,i))},"noteOnce"),Au=c(e=>{e.inventory=X({env:A,...d.catalogueFiles?{files:d.catalogueFiles}:{}}),e.index=tu(e.inventory.capabilities)},"reload"),I=c(e=>d.packageManager?.(e.cwd,e.agentDir)??new ju({cwd:e.cwd,agentDir:e.agentDir,settingsManager:Ru.create(e.cwd,e.agentDir),quiet:!0}),"packageManager"),U=c((e,u)=>u.kind==="builtin"?!0:u.kind==="mcp"?$(e,u)!==void 0:u.kind==="package"?W(e,u):!1,"isAvailable"),$=c((e,u)=>{const t=$u(e.cwd,{projectTrusted:e.ctx.isProjectTrusted()});if(Su(),t[u.id])return u.id;const i=R(u);for(const[o,n]of Object.entries(t)){if("url"in n){if(u.mcp?.url&&n.url===u.mcp.url)return o;continue}const s=n.args??[];if(i&&s.some(a=>a.startsWith(`${i.name}@`)||a.startsWith(`${i.name}==`)))return o}},"mcpInstalledName"),S=c(e=>e.slice(0,e.lastIndexOf("@")>0?e.lastIndexOf("@"):e.length),"packageName"),P=c((e,u)=>{let t=u instanceof Error?u.message:String(u);const i=[e.packageSpec,e.packageSpec?S(e.packageSpec):void 0,R(e)?.name,e.id].filter(o=>!!o&&o!==e.name);for(const o of i.sort((n,s)=>s.length-n.length))t=t.replaceAll(o,e.name);return t},"userText"),W=c((e,u)=>{if(!u.packageSpec)return!1;const t=S(u.packageSpec);try{return I(e).listConfiguredPackages().some(i=>{const o=i.source.replace(/^npm:/,"");return o===t||o.startsWith(`${t}@`)})}catch{return!1}},"packageInstalled"),G=c((e,u)=>{const t=u.kind==="package"?u.exclusiveGroup:void 0;if(!t)return[];let i;try{i=I(e).listConfiguredPackages()}catch{return[]}const o=[];for(const n of e.inventory.capabilities){if(n.id===u.id||n.kind!=="package"||n.exclusiveGroup!==t||!n.packageSpec)continue;const s=S(n.packageSpec);for(const a of i){const F=a.source.replace(/^npm:/,"");(F===s||F.startsWith(`${s}@`))&&o.push({capability:n,source:a.source,scope:a.scope})}}return o},"installedRivals"),H=c(async(e,u)=>{const t=G(e,u);if(t.length===0)return[];const i=I(e),o=[],n=[];for(const a of t){if(a.scope!=="user"){n.push(a.capability.name);continue}try{await i.removeAndPersist(a.source)}catch{n.push(a.capability.name);continue}Qu(e.agentDir,a.capability.id),e.enabled.delete(a.capability.id),o.push(a.capability.name)}const s=[];return o.length>0&&s.push(r("\u5DF2\u6362\u7528\u300C{name}\u300D\uFF0C\u540C\u7C7B\u7684\u300C{others}\u300D\u5DF2\u5378\u8F7D\uFF08\u4E24\u8005\u4F5C\u7528\u76F8\u540C\uFF0C\u53EA\u80FD\u4E8C\u9009\u4E00\uFF09\u3002").replace("{name}",u.name).replace("{others}",o.join("\u3001"))),n.length>0&&s.push(r("\u300C{others}\u300D\u6CA1\u80FD\u81EA\u52A8\u5378\u8F7D\uFF1B\u5B83\u548C\u300C{name}\u300D\u4F5C\u7528\u76F8\u540C\uFF0C\u540C\u65F6\u542F\u7528\u4F1A\u4E92\u76F8\u8986\u76D6\uFF0C\u8BF7\u624B\u52A8\u79FB\u9664\u3002").replace("{others}",n.join("\u3001")).replace("{name}",u.name)),s},"retireRivals"),L=c((e,u)=>su(e.agentDir).disabled.includes(u.id)?!0:u.kind!=="mcp"?!1:Vu(e.agentDir).get(u.id)?.disabled===!0,"userDisabled"),V=c(e=>{const u=lu();return u?u.inactiveGroups().some(t=>t.id===e)?u.activate(e):[]:[]},"activateGroup"),Cu=c(async(e,u)=>{const t={};for(const i of u.inputs.filter(o=>o.required)){const o=`${r("\u300C{name}\u300D\u9700\u8981\uFF1A").replace("{name}",u.name)}${i.label}${i.help?`
|
|
3
|
+
${i.help}`:""}`,n=(await e.ctx.ui.requestInput({title:o,...i.placeholder?{placeholder:i.placeholder}:{}}))?.trim();if(!n)return;t[i.key]=n}return t},"askInputs"),gu=c(async e=>{for(const u of Object.values(e)){const t=Gu(u);if(t)try{await(d.checkReachable??Uu)(t.host,t.port)}catch(i){const o=i instanceof Error?i.message:String(i);return r("\u8FDE\u4E0D\u5230 {host}:{port}\uFF08{why}\uFF09").replace("{host}",t.host).replace("{port}",String(t.port)).replace("{why}",o)}}},"firstUnreachable"),K=c((e,u)=>{const t=e.inputs.filter(o=>o.required).map(o=>o.label).join("\u3001"),i=t?r("\u8BF7\u68C0\u67E5{labels}\u662F\u5426\u6B63\u786E\uFF0C\u4E0B\u6B21\u7528\u5230\u65F6\u4F1A\u91CD\u65B0\u8BE2\u95EE\u3002").replace("{labels}",t):r("\u8BF7\u68C0\u67E5\u7F51\u7EDC\u540E\u91CD\u8BD5\uFF0C\u6216\u7528 /capabilities enable {name} \u518D\u8BD5\u4E00\u6B21\u3002").replace("{name}",e.name);return`${r("\u300C{name}\u300D\u8FDE\u63A5\u4E0D\u4E0A\uFF1A").replace("{name}",e.name)}${u}${r("\u3002")}${i}`},"cannotConnect"),Bu=c(async(e,u,t)=>{const i=R(u);let o;if(i){const a=i.ecosystem==="npm"?u.mcp?.integrity:u.mcp?.sha256;if(!a)return{outcome:"no-digest"};const F=await(d.userRegistries??((p,C)=>Ku(p,C,A)))(i.ecosystem,e.cwd);o=await Wu(i,a,{env:A,user:F,...d.fetch?{fetch:d.fetch}:{}})}let n=qu(u,t,o?.env??{});d.adjustMcpEntry&&(n=d.adjustMcpEntry(u,n));const s=u.inputs.some(a=>a.secret&&t[a.key]!==void 0);return Yu(e.agentDir,u.id,n,s),{outcome:"written",...o?{registry:o}:{},...i?{version:i.version}:{}}},"installMcp"),Y=c(async(e,u,t)=>{if(t.outcome!=="written")return t;const i=t,o=i.registry?{registry:i.registry}:{},n=cu(),s=n?(await n.connectAdded([u.id]))[u.id]:void 0;if(s?.status==="connected"&&s.tools.length>0)return ou(e.agentDir,u.id,"mcp",i.version),y(u,"installed"),{outcome:"installed",...o,line:r("\u5DF2\u4E3A\u8FD9\u4E2A\u4EFB\u52A1\u542F\u7528\uFF1A{name}").replace("{name}",u.name),note:x("\u5DF2\u4E3A\u672C\u4EFB\u52A1\u5B89\u88C5\u5E76\u542F\u7528 MCP \u8FDE\u63A5\u5668\u300C{name}\u300D\uFF08{hint}\uFF09\uFF0C\u53EF\u76F4\u63A5\u8C03\u7528\uFF1A{tools}").replace("{name}",u.name).replace("{hint}",u.hint).replace("{tools}",s.tools.join(", "))};Hu(e.agentDir,u.id,u.id),e.enabled.delete(u.id);const a=s?.error??(s?.status==="connected"?r("\u6CA1\u6709\u63D0\u4F9B\u4EFB\u4F55\u5DE5\u5177"):n?r("\u672A\u8FDE\u63A5"):r("MCP \u652F\u6301\u672A\u52A0\u8F7D"));return y(u,"failed",a),{outcome:"connect-failed",...o,line:K(u,P(u,a))}},"connectInstalled"),bu=c((e,u,t)=>{const i=u.packageSpec,o=u.packageIntegrity;if(!i||!o)return;const n=`npm:${i}`,s=(async()=>{const a=I(e),F=await a.getRegistryIntegrity(n);if(F!==o)throw new Error(r("\u5B89\u88C5\u5305\u6821\u9A8C\u4E0D\u4E00\u81F4\uFF1ADAL \u767B\u8BB0\u7684\u662F {want}\uFF0C\u4E0B\u8F7D\u6E90\u73B0\u5728\u662F {got}").replace("{want}",o).replace("{got}",F??"?"));await a.installAndPersist(n);const p=a.getRecordedIntegrity(S(i),"user");if(p!==void 0&&p!==o)throw await a.removeAndPersist(n),new Error(r("\u88C5\u4E0B\u6765\u7684\u5B89\u88C5\u5305\u6821\u9A8C\u4E0D\u4E00\u81F4\uFF0C\u5DF2\u79FB\u9664"));const C=a.getInstalledPath(n,"user");if(C&&Ou(C),ou(e.agentDir,u.id,"package",i.slice(i.lastIndexOf("@")+1)),y(u,"installed"),v(e,r("\u5DF2\u5B89\u88C5\u300C{name}\u300D\uFF0C\u4E0B\u4E2A\u4F1A\u8BDD\u8D77\u53EF\u7528\uFF08\u6216\u8F93\u5165 /reload \u7ACB\u5373\u52A0\u8F7D\uFF09").replace("{name}",u.name)),t)for(const g of await H(e,u))w(e.ctx,g)})().catch(a=>{y(u,"failed",a),v(e,`${r("\u672A\u80FD\u5B89\u88C5\u300C{name}\u300D\uFF1A").replace("{name}",u.name)}${P(u,a)}`,"warning")});M(s)},"installPackage"),J=c(async(e,u,t)=>{if(!t&&L(e,u))return{outcome:"disabled"};if(e.enabled.has(u.id)&&!t)return{outcome:"already"};const i=e.ctx;if(u.kind==="mcp"&&!i.hasUI&&Fu($(e,u)??u.id,e.cwd))return h(e,`guard:${u.id}`,r("\u300C{name}\u300D\u53EF\u4EE5\u5904\u7406\u8FD9\u4E2A\u4EFB\u52A1\uFF0C\u4F46\u5F53\u524D\u6743\u9650\u6A21\u5F0F\u4F1A\u62D2\u7EDD\u65E0\u4EBA\u503C\u5B88\u8FD0\u884C\u4E2D\u7684 MCP \u8C03\u7528\uFF0C\u6CA1\u6709\u542F\u7528\u3002").replace("{name}",u.name)),V("web"),{outcome:"guard-refuses",note:x("\u300C{name}\u300D\uFF08{hint}\uFF09\u5728\u5F53\u524D\u6743\u9650\u6A21\u5F0F\u4E0B\u4E0D\u80FD\u7528\uFF1AMCP \u8C03\u7528\u9700\u8981\u7528\u6237\u6279\u51C6\uFF0C\u800C\u8FD9\u6B21\u8FD0\u884C\u6CA1\u6709\u4EBA\u53EF\u4EE5\u6279\u51C6\u3002\u6539\u7528\u5185\u7F6E\u5DE5\u5177\u5B8C\u6210\u4EFB\u52A1\uFF1A\u8BFB\u7F51\u9875\u7528 web_fetch\u3001\u641C\u7D22\u7528 web_search\uFF0C\u8BFB\u6587\u4EF6\u7528 read / grep\u3002").replace("{name}",u.name).replace("{hint}",u.hint)};if(u.kind==="builtin"||u.kind==="mcp"&&$(e,u)){const l=u.kind==="mcp"?$(e,u)??u.id:u.id;e.enabled.add(u.id);const f=V(l);return f.length===0?{outcome:"ready"}:{outcome:"activated",line:r("\u5DF2\u4E3A\u8FD9\u4E2A\u4EFB\u52A1\u542F\u7528\uFF1A{name}").replace("{name}",u.name),note:x("\u5DF2\u4E3A\u672C\u4EFB\u52A1\u542F\u7528\u300C{name}\u300D\uFF0C\u53EF\u76F4\u63A5\u8C03\u7528\uFF1A{tools}").replace("{name}",u.name).replace("{tools}",f.join(", "))}}if(u.kind==="package"&&W(e,u)){e.enabled.add(u.id);const l=t?await H(e,u):[];return{outcome:"ready",...l.length>0?{line:l.join(`
|
|
4
|
+
`)}:{}}}if(!t&&u.kind==="package"){const l=G(e,u)[0];if(l)return h(e,`exclusive:${u.id}`,r("\u300C{name}\u300D\u548C\u5DF2\u542F\u7528\u7684\u300C{other}\u300D\u4F5C\u7528\u76F8\u540C\uFF0C\u53EA\u80FD\u4E8C\u9009\u4E00\uFF0C\u6CA1\u6709\u81EA\u52A8\u5B89\u88C5\uFF1B\u8981\u6362\u7528\u53EF\u8F93\u5165 /capabilities enable {name}\u3002").replaceAll("{name}",u.name).replace("{other}",l.capability.name)),{outcome:"exclusive"}}const o=Z(u);if(o)return o!=="not-installable"&&h(e,`blocked:${u.id}`,r("\u300C{name}\u300D\u53EF\u4EE5\u5904\u7406\u8FD9\u4E2A\u4EFB\u52A1\uFF0C\u4F46\u76EE\u5F55\u91CC\u6CA1\u6709\u767B\u8BB0\u5B83\u7684\u5B89\u88C5\u5305\u6821\u9A8C\u503C\uFF0C\u4E0D\u4F1A\u81EA\u52A8\u5B89\u88C5\u3002").replace("{name}",u.name)),{outcome:o};if(u.kind==="mcp"&&D.getToolAllowlist()?.some(l=>l.startsWith("mcp__"))===!1)return{outcome:"allowlist"};const n=_(e.agentDir,e.cwd,A,j);if(!t&&!n.autoInstall)return h(e,`auto-off:${u.id}`,r("\u300C{name}\u300D\u53EF\u4EE5\u5904\u7406\u8FD9\u4E2A\u4EFB\u52A1\uFF1B\u81EA\u52A8\u5B89\u88C5\u5DF2\u5173\u95ED\uFF0C\u53EF\u7528 /capabilities enable {name} \u542F\u7528\u3002").replaceAll("{name}",u.name)),{outcome:"auto-off"};if(!t&&iu(A)&&!n.allowInCI)return h(e,`ci:${u.id}`,r("CI \u73AF\u5883\u4E2D\u4E0D\u81EA\u52A8\u5B89\u88C5\u300C{name}\u300D\uFF08\u8BBE\u7F6E capabilities.allowInCI \u6216 DAL_CAPABILITIES_AUTO_INSTALL=1 \u53EF\u5141\u8BB8\uFF09\u3002").replace("{name}",u.name)),{outcome:"ci"};const s=su(e.agentDir);if(!t&&s.declined.includes(u.id))return{outcome:"declined"};if(u.risk.length>0&&!t&&!s.approved.includes(u.id)){const l=u.risk.map(f=>r(ne[f])).join("\u3001");if(!i.hasUI)return h(e,`risk:${u.id}`,r("\u300C{name}\u300D{risks}\uFF0C\u9700\u8981\u4F60\u786E\u8BA4\u540E\u624D\u80FD\u542F\u7528\uFF1B\u8FD9\u6B21\u8FD0\u884C\u6CA1\u6709\u754C\u9762\uFF0C\u5DF2\u8DF3\u8FC7\u3002\u5728\u4EA4\u4E92\u6A21\u5F0F\u4E2D\u7528\u5230\u65F6\u4F1A\u8BE2\u95EE\u4E00\u6B21\u3002").replace("{name}",u.name).replace("{risks}",l)),{outcome:"risk-skipped"};if(!await i.ui.confirm(r("\u4E3A\u8FD9\u4E2A\u4EFB\u52A1\u542F\u7528\u300C{name}\u300D\uFF1F").replace("{name}",u.name),`${u.summary??u.hint}
|
|
5
|
+
${r("\u6CE8\u610F\uFF1A")}${l}`))return nu(e.agentDir,u.id),{outcome:"declined"};zu(e.agentDir,u.id)}let a={};if(u.inputs.some(l=>l.required)){if(!i.hasUI){const N=u.inputs.filter(m=>m.required).map(m=>m.label).join("\u3001");return h(e,`inputs:${u.id}`,r("\u300C{name}\u300D\u9700\u8981\u5148\u586B\u5199{labels}\uFF1B\u8FD9\u6B21\u8FD0\u884C\u6CA1\u6709\u754C\u9762\uFF0C\u5DF2\u8DF3\u8FC7\u3002\u5728\u4EA4\u4E92\u6A21\u5F0F\u4E2D\u7528\u5230\u65F6\u4F1A\u8BE2\u95EE\u4E00\u6B21\u3002").replace("{name}",u.name).replace("{labels}",N)),{outcome:"inputs-skipped"}}const l=await Cu(e,u);if(!l)return nu(e.agentDir,u.id),{outcome:"declined"};a=l;const f=await gu(a);if(f)return y(u,"failed",f),{outcome:"connect-failed",line:K(u,f)}}if(e.enabled.add(u.id),u.kind==="package")return bu(e,u,t),{outcome:"installing",line:r("\u6B63\u5728\u4E3A\u8FD9\u4E2A\u4EFB\u52A1\u5B89\u88C5\uFF1A{name}\uFF08\u540E\u53F0\u8FDB\u884C\uFF0C\u4E0B\u4E2A\u4F1A\u8BDD\u8D77\u53EF\u7528\uFF09").replace("{name}",u.name)};const F=Bu(e,u,a),p=c(l=>`${r("\u672A\u80FD\u542F\u7528\u300C{name}\u300D\uFF1A").replace("{name}",u.name)}${P(u,l)}`,"failedLine"),C=d.installBudgetMs??2e4;let g;const b=new Promise(l=>{g=setTimeout(()=>l("timeout"),C),g.unref?.()});try{const l=await Promise.race([F,b]);if(l!=="timeout")return await Y(e,u,l)}catch(l){return e.enabled.delete(u.id),y(u,"failed",l),{outcome:"failed",line:p(l)}}finally{clearTimeout(g)}return M(F.then(l=>Y(e,u,l)).then(l=>{l.line&&v(e,l.line,l.outcome==="installed"?"info":"warning")},l=>{e.enabled.delete(u.id),y(u,"failed",l),v(e,p(l),"warning")})),{outcome:"installing",line:r("\u6B63\u5728\u4E3A\u8FD9\u4E2A\u4EFB\u52A1\u542F\u7528\uFF1A{name}\u2026").replace("{name}",u.name)}},"enable"),hu=c(async(e,u)=>{e.projectText??=O(e.cwd);const t=eu(u,e.projectText);if(t)return t;const i=`tie:${u.map(n=>n.capability.id).join(",")}`;if(!e.ctx.hasUI){h(e,i,r("\u6709\u51E0\u4E2A\u80FD\u529B\u90FD\u53EF\u80FD\u9002\u5408\u8FD9\u4E2A\u4EFB\u52A1\uFF08{names}\uFF09\uFF0C\u6CA1\u6709\u81EA\u52A8\u542F\u7528\uFF1B\u53EF\u7528 /capabilities enable <\u540D\u79F0> \u6307\u5B9A\u3002").replace("{names}",u.map(n=>n.capability.name).join("\u3001")));return}if(e.noted.has(i))return;e.noted.add(i);const o=await e.ctx.ui.requestChoice({title:r("\u8FD9\u4E2A\u4EFB\u52A1\u53EF\u4EE5\u7528\u4EE5\u4E0B\u80FD\u529B\uFF0C\u9009\u4E00\u4E2A\u542F\u7528\uFF1A"),items:[...u.map(n=>({id:n.capability.id,label:n.capability.name,description:n.capability.hint})),{id:"__none__",label:r("\u90FD\u4E0D\u7528")}]});return u.find(n=>n.capability.id===o)},"resolveTie");D.on("session_start",async(e,u)=>{const t=Pu(),i=_(t,u.cwd,A,j),o=X({env:A,...d.catalogueFiles?{files:d.catalogueFiles}:{}});if(E={ctx:u,cwd:u.cwd,agentDir:t,inventory:o,index:tu(o.capabilities),enabled:new Set,noted:new Set,pending:Promise.resolve()},!i.enabled||d.skipMarketFetch||pu(A,Date.now())<se)return;const n=E;M((async()=>{const s=await u.modelRegistry?.getApiKeyForProvider?.("deepailab").catch(()=>{}),a=Nu({env:A,apiBase:Tu().apiBase,...s?{virtualKey:s}:{}});a&&(await Mu({endpoint:a,env:A,...d.fetch?{fetch:d.fetch}:{}})).updated.length>0&&E===n&&Au(n)})())}),D.on("before_agent_start",async(e,u)=>{const t=E;if(!t||e.messageType!=="user")return;const i=e.prompt.trim();if(!i||i.startsWith("/")||!_(t.agentDir,t.cwd,A,j).enabled)return;const o=performance.now(),n=au(t.index,i);let s=Ju(n,m=>{const T=t.inventory.capabilities.find(wu=>wu.id===m);return T?U(t,T):!1});t.projectText??=s.tied.length>0?O(t.cwd):void 0;const a=s.tied.length>0?eu(s.tied,t.projectText??""):void 0;a&&(s={...s,tool:a,tied:[]});const F=performance.now()-o;t.lastRouteMs=F;let p=s.tool;!p&&s.tied.length>0&&(p=await hu(t,s.tied));const C=[],g=[];let b,l;if(p){const m=await J(t,p.capability,!1);b=m.outcome,l=m.registry,m.line&&C.push(m.line),m.note&&g.push(m.note)}const f=s.skill?.capability;if(f&&!t.enabled.has(f.id)&&!L(t,f)){const m=await du()?.load?.(f.id).catch(()=>{});m&&(t.enabled.add(f.id),C.push(r("\u5DF2\u4E3A\u8FD9\u4E2A\u4EFB\u52A1\u542F\u7528\uFF1A{name}").replace("{name}",f.name)),g.push(`<skill name="${f.id}">
|
|
6
|
+
${m.trim()}
|
|
7
|
+
</skill>`))}if(!p&&s.tied.length===0&&n.length===0&&oe.test(i)&&g.push(x("DAL \u5BA1\u6838\u8FC7\u7684\u80FD\u529B\u91CC\u6CA1\u6709\u9002\u5408\u8FD9\u4E2A\u4EFB\u52A1\u7684\u5DE5\u5177\u3002\u5982\u679C\u786E\u5B9E\u9700\u8981\u4E00\u4E2A\u65B0\u5DE5\u5177\uFF0C\u53EF\u4EE5\u5411\u7528\u6237\u63D0\u8BAE\u4E3A\u5B83\u7F16\u5199\u4E00\u4E2A DAL \u6269\u5C55\uFF08\u6269\u5C55\u5199\u6CD5\u89C1 DAL \u6587\u6863\u91CC\u7684\u6269\u5C55\u793A\u4F8B\uFF09\uFF0C\u7528\u6237\u540C\u610F\u540E\u518D\u52A8\u624B\uFF1B\u4E0D\u8981\u4ECE\u7F51\u4E0A\u5B89\u88C5\u672A\u7ECF\u5BA1\u6838\u7684\u5305\u3002")),d.onRoute?.({prompt:i,routeMs:F,tied:s.tied.map(m=>m.capability.id),...p?{chosen:p.capability.id}:{},...s.skill?{skill:s.skill.capability.id}:{},...b?{outcome:b}:{},...l?{registry:l}:{}}),p||s.tied.length>0||s.skill){const m={routeMs:F,tied:s.tied.map(T=>T.capability.id),lines:C,...p?{chosen:{id:p.capability.id,name:p.capability.name,kind:p.capability.kind}}:{},...b?{outcome:b}:{},...f?{skill:{id:f.id,name:f.name}}:{},...l?{registry:{source:l.source,registry:l.registry.replace(/\/\/[^/@\s]+@/,"//"),...l.fallback?{fallback:l.fallback}:{}}}:{}};D.emitHostEvent(Eu,m)}const N=b==="connect-failed"||b==="failed";for(const m of C)w(u,m,N?"warning":"info");if(g.length!==0)return{message:{customType:"dal-capabilities",content:g.join(`
|
|
8
8
|
|
|
9
|
-
`),display:!1}}}),
|
|
10
|
-
`):
|
|
11
|
-
`)},"listText")}}
|
|
9
|
+
`),display:!1}}}),D.on("session_shutdown",async()=>{E=void 0}),D.registerCommand("capabilities",{description:r("\u67E5\u770B\u3001\u505C\u7528\u6216\u542F\u7528\u4E3A\u4EFB\u52A1\u81EA\u52A8\u542F\u7528\u7684\u80FD\u529B\uFF08list | enable <\u540D\u79F0> | disable <\u540D\u79F0> | auto on|off\uFF09"),getArgumentCompletions:c(e=>{const u=e.trimStart(),t=u.indexOf(" ");if(t===-1)return["list","enable","disable","auto","why"].filter(n=>n.startsWith(u)).map(n=>({value:`${n} `,label:n}));const i=u.slice(0,t),o=u.slice(t+1);return(i==="enable"||i==="disable")&&E?E.inventory.capabilities.filter(n=>n.name.toLowerCase().startsWith(o.toLowerCase())).slice(0,30).map(n=>({value:`${i} ${n.name}`,label:n.name})):null},"getArgumentCompletions"),handler:c(async(e,u)=>{const t=E;if(!t)return;const[i="list",...o]=e.trim().split(/\s+/).filter(Boolean),n=o.join(" "),s=c(()=>t.inventory.capabilities.find(a=>a.name===n)??t.inventory.capabilities.find(a=>a.name.toLowerCase()===n.toLowerCase())??t.inventory.capabilities.find(a=>a.id===n),"find");switch(i){case"list":{const a=o[0]==="all";u.ui.notify(ku(t,a),"info");return}case"enable":{const a=s();if(!a){u.ui.notify(`${r("\u76EE\u5F55\u91CC\u6CA1\u6709\u8FD9\u4E2A\u80FD\u529B\uFF1A")}${n||"?"}`,"warning");return}if(ru(t.agentDir,a.id,!1),a.kind==="mcp"&&uu(t.agentDir,a.id,!1)){u.ui.notify(r("\u5DF2\u91CD\u65B0\u542F\u7528\uFF1A{name}").replace("{name}",a.name),"info");return}const F=await J(t,a,!0);u.ui.notify(F.line??r("\u300C{name}\u300D\u5DF2\u53EF\u7528\u3002").replace("{name}",a.name),F.outcome==="failed"?"warning":"info");return}case"disable":{const a=s();if(!a){u.ui.notify(`${r("\u76EE\u5F55\u91CC\u6CA1\u6709\u8FD9\u4E2A\u80FD\u529B\uFF1A")}${n||"?"}`,"warning");return}ru(t.agentDir,a.id,!0),t.enabled.delete(a.id),a.kind==="mcp"&&uu(t.agentDir,a.id,!0),u.ui.notify(r("\u5DF2\u505C\u7528\uFF1A{name}\uFF0C\u4E0D\u4F1A\u518D\u81EA\u52A8\u542F\u7528\u3002").replace("{name}",a.name),"info");return}case"auto":{const a=o[0];if(a!=="on"&&a!=="off"){u.ui.notify(r("\u7528\u6CD5\uFF1A/capabilities auto on|off"),"info");return}Xu(t.agentDir,a==="on"),u.ui.notify(a==="on"?r("\u5DF2\u5F00\u542F\u81EA\u52A8\u5B89\u88C5\u3002"):r("\u5DF2\u5173\u95ED\u81EA\u52A8\u5B89\u88C5\uFF1A\u53EA\u542F\u7528\u5DF2\u5B89\u88C5\u7684\u80FD\u529B\u3002"),"info");return}case"why":{const a=au(t.index,n).slice(0,5).map(F=>`${F.capability.name} ${F.score.toFixed(1)} [${[...F.keywords,...F.pieces].join(", ")}]`);u.ui.notify(a.length>0?a.join(`
|
|
10
|
+
`):r("\u6CA1\u6709\u5339\u914D\u7684\u80FD\u529B\u3002"),"info");return}default:u.ui.notify(r("\u7528\u6CD5\uFF1A/capabilities list [all] | enable <\u540D\u79F0> | disable <\u540D\u79F0> | auto on|off | why <\u4EFB\u52A1>"),"info")}},"handler")});const yu=c((e,u)=>{if(L(e,u))return r("\u5DF2\u505C\u7528");if(e.enabled.has(u.id))return r("\u672C\u4F1A\u8BDD\u5DF2\u542F\u7528");if(U(e,u))return u.kind==="builtin"?r("\u5185\u7F6E"):r("\u5DF2\u5B89\u88C5");if(u.kind==="skill")return r("\u6280\u80FD");if(Z(u))return r("\u9700\u624B\u52A8\u5B89\u88C5");const t=u.risk.length>0?r("\uFF08\u542F\u7528\u524D\u786E\u8BA4\uFF09"):"",i=u.inputs.some(o=>o.required)?r("\uFF08\u9700\u8981\u586B\u5199\u914D\u7F6E\uFF09"):"";return`${r("\u53EF\u81EA\u52A8\u5B89\u88C5")}${t}${i}`},"statusOf"),ku=c((e,u)=>{const t=_(e.agentDir,e.cwd,A,j),i=e.inventory.capabilities.map(F=>({capability:F,status:yu(e,F)})).filter(F=>u||![r("\u53EF\u81EA\u52A8\u5B89\u88C5"),r("\u6280\u80FD"),r("\u9700\u624B\u52A8\u5B89\u88C5")].some(p=>F.status.startsWith(p))),o=Object.entries(e.inventory.sources).map(([F,p])=>`${F} ${p}`).join(" \xB7 "),n=[`${r("\u80FD\u529B\u4E2D\u5FC3")}\uFF1A${r("\u81EA\u52A8\u5B89\u88C5")}${t.autoInstall?r("\u5F00"):r("\u5173")}${iu(A)&&!t.allowInCI?r("\uFF08CI \u73AF\u5883\u4E2D\u4E0D\u5B89\u88C5\uFF09"):""}`,`${r("\u5BA1\u6838\u76EE\u5F55\uFF1A")}${o}`,e.lastRouteMs!==void 0?`${r("\u4E0A\u4E00\u8F6E\u5339\u914D\u8017\u65F6\uFF1A")}${e.lastRouteMs.toFixed(2)} ms`:void 0].filter(Boolean),s=i.map(F=>`- ${F.capability.name} \u2014 ${F.status}`),a=u?[]:[r("\u5171 {n} \u9879\u80FD\u529B\uFF0C/capabilities list all \u67E5\u770B\u5168\u90E8\u3002").replace("{n}",String(e.inventory.capabilities.length))];return[...n,"",...s.length>0?s:[r("\uFF08\u8FD8\u6CA1\u6709\u542F\u7528\u6216\u5B89\u88C5\u4EFB\u4F55\u80FD\u529B\uFF09")],...a].join(`
|
|
11
|
+
`)},"listText")}}B(q,"en"),c(q,"createDalCapabilities");var le=q();export{Zu as BUILTIN_CAPABILITIES,fu as CAPABILITIES_INSTALL_EVENT,Eu as CAPABILITIES_ROUTE_EVENT,te as buildIndex,Du as capabilitiesHandle,ue as capabilitiesOf,q as createDalCapabilities,le as default,ee as readInventory,ae as route,ie as scoreRequest};
|