@prometheus-ai/agent 0.5.0
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 +7 -0
- package/README.md +36 -0
- package/dist/types/async/index.d.ts +2 -0
- package/dist/types/async/job-manager.d.ts +88 -0
- package/dist/types/async/support.d.ts +2 -0
- package/dist/types/auto-thinking/classifier.d.ts +35 -0
- package/dist/types/autoresearch/dashboard.d.ts +4 -0
- package/dist/types/autoresearch/git.d.ts +36 -0
- package/dist/types/autoresearch/helpers.d.ts +24 -0
- package/dist/types/autoresearch/index.d.ts +2 -0
- package/dist/types/autoresearch/state.d.ts +17 -0
- package/dist/types/autoresearch/storage.d.ts +142 -0
- package/dist/types/autoresearch/tools/init-experiment.d.ts +31 -0
- package/dist/types/autoresearch/tools/log-experiment.d.ts +23 -0
- package/dist/types/autoresearch/tools/run-experiment.d.ts +8 -0
- package/dist/types/autoresearch/tools/update-notes.d.ts +12 -0
- package/dist/types/autoresearch/types.d.ts +154 -0
- package/dist/types/capability/context-file.d.ts +30 -0
- package/dist/types/capability/extension-module.d.ts +15 -0
- package/dist/types/capability/extension.d.ts +28 -0
- package/dist/types/capability/fs.d.ts +20 -0
- package/dist/types/capability/hook.d.ts +19 -0
- package/dist/types/capability/index.d.ts +80 -0
- package/dist/types/capability/instruction.d.ts +17 -0
- package/dist/types/capability/mcp.d.ts +45 -0
- package/dist/types/capability/prompt.d.ts +15 -0
- package/dist/types/capability/rule-buckets.d.ts +30 -0
- package/dist/types/capability/rule.d.ts +68 -0
- package/dist/types/capability/settings.d.ts +15 -0
- package/dist/types/capability/skill.d.ts +43 -0
- package/dist/types/capability/slash-command.d.ts +17 -0
- package/dist/types/capability/ssh.d.ts +23 -0
- package/dist/types/capability/system-prompt.d.ts +15 -0
- package/dist/types/capability/tool.d.ts +19 -0
- package/dist/types/capability/types.d.ts +158 -0
- package/dist/types/cli/agents-cli.d.ts +12 -0
- package/dist/types/cli/args.d.ts +55 -0
- package/dist/types/cli/auth-broker-cli.d.ts +25 -0
- package/dist/types/cli/auth-gateway-cli.d.ts +26 -0
- package/dist/types/cli/classify-install-target.d.ts +12 -0
- package/dist/types/cli/claude-trace-cli.d.ts +52 -0
- package/dist/types/cli/commands/init-xdg.d.ts +1 -0
- package/dist/types/cli/completion-gen.d.ts +80 -0
- package/dist/types/cli/config-cli.d.ts +22 -0
- package/dist/types/cli/dry-balance-cli.d.ts +104 -0
- package/dist/types/cli/extension-flags.d.ts +36 -0
- package/dist/types/cli/file-processor.d.ts +11 -0
- package/dist/types/cli/gateway-cli.d.ts +95 -0
- package/dist/types/cli/grep-cli.d.ts +17 -0
- package/dist/types/cli/grievances-cli.d.ts +37 -0
- package/dist/types/cli/initial-message.d.ts +17 -0
- package/dist/types/cli/list-models.d.ts +30 -0
- package/dist/types/cli/plugin-cli.d.ts +32 -0
- package/dist/types/cli/read-cli.d.ts +4 -0
- package/dist/types/cli/session-picker.d.ts +10 -0
- package/dist/types/cli/setup-cli.d.ts +24 -0
- package/dist/types/cli/shell-cli.d.ts +8 -0
- package/dist/types/cli/ssh-cli.d.ts +21 -0
- package/dist/types/cli/stats-cli.d.ts +17 -0
- package/dist/types/cli/tiny-models-cli.d.ts +9 -0
- package/dist/types/cli/update-cli.d.ts +106 -0
- package/dist/types/cli/web-search-cli.d.ts +20 -0
- package/dist/types/cli/worktree-cli.d.ts +26 -0
- package/dist/types/cli-commands.d.ts +19 -0
- package/dist/types/cli.d.ts +3 -0
- package/dist/types/commands/acp.d.ts +12 -0
- package/dist/types/commands/agents.d.ts +34 -0
- package/dist/types/commands/auth-broker.d.ts +54 -0
- package/dist/types/commands/auth-gateway.d.ts +35 -0
- package/dist/types/commands/commit.d.ts +27 -0
- package/dist/types/commands/complete.d.ts +6 -0
- package/dist/types/commands/completions.d.ts +13 -0
- package/dist/types/commands/config.d.ts +30 -0
- package/dist/types/commands/dry-balance.d.ts +31 -0
- package/dist/types/commands/gateway.d.ts +69 -0
- package/dist/types/commands/grep.d.ts +42 -0
- package/dist/types/commands/grievances.d.ts +40 -0
- package/dist/types/commands/install.d.ts +51 -0
- package/dist/types/commands/launch.d.ts +129 -0
- package/dist/types/commands/plugin.d.ts +52 -0
- package/dist/types/commands/read.d.ts +15 -0
- package/dist/types/commands/setup.d.ts +34 -0
- package/dist/types/commands/shell.d.ts +21 -0
- package/dist/types/commands/ssh.d.ts +48 -0
- package/dist/types/commands/stats.d.ts +25 -0
- package/dist/types/commands/tiny-models.d.ts +22 -0
- package/dist/types/commands/update.d.ts +20 -0
- package/dist/types/commands/web-search.d.ts +33 -0
- package/dist/types/commands/worktree.d.ts +34 -0
- package/dist/types/commit/agentic/agent.d.ts +31 -0
- package/dist/types/commit/agentic/fallback.d.ts +5 -0
- package/dist/types/commit/agentic/index.d.ts +2 -0
- package/dist/types/commit/agentic/state.d.ts +58 -0
- package/dist/types/commit/agentic/tools/analyze-file.d.ts +19 -0
- package/dist/types/commit/agentic/tools/git-file-diff.d.ts +10 -0
- package/dist/types/commit/agentic/tools/git-hunk.d.ts +9 -0
- package/dist/types/commit/agentic/tools/git-overview.d.ts +9 -0
- package/dist/types/commit/agentic/tools/index.d.ts +16 -0
- package/dist/types/commit/agentic/tools/propose-changelog.d.ts +28 -0
- package/dist/types/commit/agentic/tools/propose-commit.d.ts +36 -0
- package/dist/types/commit/agentic/tools/recent-commits.d.ts +7 -0
- package/dist/types/commit/agentic/tools/schemas.d.ts +27 -0
- package/dist/types/commit/agentic/tools/split-commit.d.ts +53 -0
- package/dist/types/commit/agentic/topo-sort.d.ts +4 -0
- package/dist/types/commit/agentic/trivial.d.ts +7 -0
- package/dist/types/commit/agentic/validation.d.ts +20 -0
- package/dist/types/commit/analysis/conventional.d.ts +22 -0
- package/dist/types/commit/analysis/index.d.ts +4 -0
- package/dist/types/commit/analysis/scope.d.ts +6 -0
- package/dist/types/commit/analysis/summary.d.ts +19 -0
- package/dist/types/commit/analysis/validation.d.ts +8 -0
- package/dist/types/commit/changelog/detect.d.ts +2 -0
- package/dist/types/commit/changelog/generate.d.ts +30 -0
- package/dist/types/commit/changelog/index.d.ts +30 -0
- package/dist/types/commit/changelog/parse.d.ts +2 -0
- package/dist/types/commit/cli.d.ts +3 -0
- package/dist/types/commit/git/diff.d.ts +5 -0
- package/dist/types/commit/index.d.ts +4 -0
- package/dist/types/commit/map-reduce/index.d.ts +28 -0
- package/dist/types/commit/map-reduce/map-phase.d.ts +17 -0
- package/dist/types/commit/map-reduce/reduce-phase.d.ts +13 -0
- package/dist/types/commit/map-reduce/utils.d.ts +2 -0
- package/dist/types/commit/message.d.ts +2 -0
- package/dist/types/commit/model-selection.d.ts +15 -0
- package/dist/types/commit/pipeline.d.ts +5 -0
- package/dist/types/commit/shared-llm.d.ts +54 -0
- package/dist/types/commit/types.d.ts +78 -0
- package/dist/types/commit/utils/exclusions.d.ts +4 -0
- package/dist/types/commit/utils.d.ts +20 -0
- package/dist/types/config/append-only-context-mode.d.ts +8 -0
- package/dist/types/config/config-file.d.ts +62 -0
- package/dist/types/config/file-lock.d.ts +29 -0
- package/dist/types/config/keybindings.d.ts +352 -0
- package/dist/types/config/model-equivalence.d.ts +24 -0
- package/dist/types/config/model-id-affixes.d.ts +10 -0
- package/dist/types/config/model-registry.d.ts +400 -0
- package/dist/types/config/model-resolver.d.ts +230 -0
- package/dist/types/config/models-config-schema.d.ts +523 -0
- package/dist/types/config/prompt-templates.d.ts +32 -0
- package/dist/types/config/resolve-config-value.d.ts +17 -0
- package/dist/types/config/settings-schema.d.ts +4352 -0
- package/dist/types/config/settings.d.ts +156 -0
- package/dist/types/config.d.ts +92 -0
- package/dist/types/cursor.d.ts +22 -0
- package/dist/types/dap/client.d.ts +38 -0
- package/dist/types/dap/config.d.ts +6 -0
- package/dist/types/dap/index.d.ts +4 -0
- package/dist/types/dap/session.d.ts +108 -0
- package/dist/types/dap/types.d.ts +524 -0
- package/dist/types/debug/index.d.ts +15 -0
- package/dist/types/debug/log-formatting.d.ts +4 -0
- package/dist/types/debug/log-viewer.d.ts +68 -0
- package/dist/types/debug/profiler.d.ts +24 -0
- package/dist/types/debug/protocol-probe.d.ts +38 -0
- package/dist/types/debug/raw-sse-buffer.d.ts +44 -0
- package/dist/types/debug/raw-sse.d.ts +18 -0
- package/dist/types/debug/report-bundle.d.ts +55 -0
- package/dist/types/debug/system-info.d.ts +26 -0
- package/dist/types/debug/terminal-info.d.ts +34 -0
- package/dist/types/discovery/agents-md.d.ts +1 -0
- package/dist/types/discovery/agents.d.ts +12 -0
- package/dist/types/discovery/builtin-defaults.d.ts +1 -0
- package/dist/types/discovery/builtin-rules/index.d.ts +7 -0
- package/dist/types/discovery/builtin.d.ts +1 -0
- package/dist/types/discovery/claude-plugins.d.ts +1 -0
- package/dist/types/discovery/claude.d.ts +1 -0
- package/dist/types/discovery/cline.d.ts +1 -0
- package/dist/types/discovery/codex.d.ts +1 -0
- package/dist/types/discovery/context-files.d.ts +17 -0
- package/dist/types/discovery/cursor.d.ts +16 -0
- package/dist/types/discovery/gemini.d.ts +1 -0
- package/dist/types/discovery/github.d.ts +1 -0
- package/dist/types/discovery/helpers.d.ts +269 -0
- package/dist/types/discovery/index.d.ts +53 -0
- package/dist/types/discovery/mcp-json.d.ts +1 -0
- package/dist/types/discovery/opencode.d.ts +1 -0
- package/dist/types/discovery/plugin-dir-roots.d.ts +15 -0
- package/dist/types/discovery/prometheus-extension-roots.d.ts +43 -0
- package/dist/types/discovery/prometheus-plugins.d.ts +1 -0
- package/dist/types/discovery/ssh.d.ts +1 -0
- package/dist/types/discovery/substitute-plugin-root.d.ts +1 -0
- package/dist/types/discovery/vscode.d.ts +1 -0
- package/dist/types/discovery/windsurf.d.ts +13 -0
- package/dist/types/edit/apply-patch/index.d.ts +35 -0
- package/dist/types/edit/apply-patch/parser.d.ts +34 -0
- package/dist/types/edit/diff.d.ts +59 -0
- package/dist/types/edit/file-snapshot-store.d.ts +40 -0
- package/dist/types/edit/hashline/block-resolver.d.ts +9 -0
- package/dist/types/edit/hashline/diff.d.ts +40 -0
- package/dist/types/edit/hashline/execute.d.ts +28 -0
- package/dist/types/edit/hashline/filesystem.d.ts +57 -0
- package/dist/types/edit/hashline/index.d.ts +5 -0
- package/dist/types/edit/hashline/params.d.ts +11 -0
- package/dist/types/edit/index.d.ts +62 -0
- package/dist/types/edit/modes/apply-patch.d.ts +24 -0
- package/dist/types/edit/modes/patch.d.ts +99 -0
- package/dist/types/edit/modes/replace.d.ts +142 -0
- package/dist/types/edit/normalize.d.ts +31 -0
- package/dist/types/edit/notebook.d.ts +23 -0
- package/dist/types/edit/read-file.d.ts +2 -0
- package/dist/types/edit/renderer.d.ts +109 -0
- package/dist/types/edit/streaming.d.ts +75 -0
- package/dist/types/eval/__tests__/agent-bridge.test.d.ts +1 -0
- package/dist/types/eval/__tests__/bridge-timeout.test.d.ts +1 -0
- package/dist/types/eval/__tests__/budget-bridge.test.d.ts +1 -0
- package/dist/types/eval/__tests__/idle-timeout.test.d.ts +1 -0
- package/dist/types/eval/__tests__/kernel-spawn.test.d.ts +1 -0
- package/dist/types/eval/__tests__/llm-bridge.test.d.ts +1 -0
- package/dist/types/eval/__tests__/shared-executors.test.d.ts +1 -0
- package/dist/types/eval/agent-bridge.d.ts +25 -0
- package/dist/types/eval/backend.d.ts +55 -0
- package/dist/types/eval/bridge-timeout.d.ts +27 -0
- package/dist/types/eval/budget-bridge.d.ts +29 -0
- package/dist/types/eval/concurrency-bridge.d.ts +26 -0
- package/dist/types/eval/idle-timeout.d.ts +30 -0
- package/dist/types/eval/index.d.ts +4 -0
- package/dist/types/eval/js/context-manager.d.ts +24 -0
- package/dist/types/eval/js/executor.d.ts +36 -0
- package/dist/types/eval/js/index.d.ts +10 -0
- package/dist/types/eval/js/shared/helpers.d.ts +38 -0
- package/dist/types/eval/js/shared/indirect-eval.d.ts +14 -0
- package/dist/types/eval/js/shared/local-module-loader.d.ts +16 -0
- package/dist/types/eval/js/shared/prelude.d.ts +1 -0
- package/dist/types/eval/js/shared/rewrite-imports.d.ts +25 -0
- package/dist/types/eval/js/shared/runtime.d.ts +53 -0
- package/dist/types/eval/js/shared/types.d.ts +24 -0
- package/dist/types/eval/js/tool-bridge.d.ts +20 -0
- package/dist/types/eval/js/worker-core.d.ts +5 -0
- package/dist/types/eval/js/worker-entry.d.ts +1 -0
- package/dist/types/eval/js/worker-protocol.d.ts +77 -0
- package/dist/types/eval/llm-bridge.d.ts +25 -0
- package/dist/types/eval/py/display.d.ts +25 -0
- package/dist/types/eval/py/executor.d.ts +95 -0
- package/dist/types/eval/py/index.d.ts +11 -0
- package/dist/types/eval/py/kernel.d.ts +70 -0
- package/dist/types/eval/py/prelude.d.ts +1 -0
- package/dist/types/eval/py/runtime.d.ts +31 -0
- package/dist/types/eval/py/spawn-options.d.ts +58 -0
- package/dist/types/eval/py/tool-bridge.d.ts +16 -0
- package/dist/types/eval/session-id.d.ts +3 -0
- package/dist/types/eval/types.d.ts +52 -0
- package/dist/types/exa/factory.d.ts +13 -0
- package/dist/types/exa/index.d.ts +20 -0
- package/dist/types/exa/mcp-client.d.ts +46 -0
- package/dist/types/exa/render.d.ts +19 -0
- package/dist/types/exa/researcher.d.ts +9 -0
- package/dist/types/exa/search.d.ts +9 -0
- package/dist/types/exa/types.d.ts +155 -0
- package/dist/types/exa/websets.d.ts +9 -0
- package/dist/types/exec/bash-executor.d.ts +42 -0
- package/dist/types/exec/exec.d.ts +25 -0
- package/dist/types/exec/idle-timeout-watchdog.d.ts +18 -0
- package/dist/types/exec/non-interactive-env.d.ts +1 -0
- package/dist/types/export/custom-share.d.ts +20 -0
- package/dist/types/export/html/index.d.ts +10 -0
- package/dist/types/export/html/template.generated.d.ts +1 -0
- package/dist/types/export/html/template.macro.d.ts +5 -0
- package/dist/types/export/ttsr.d.ts +53 -0
- package/dist/types/extensibility/custom-commands/bundled/ci-green/index.d.ts +9 -0
- package/dist/types/extensibility/custom-commands/bundled/review/index.d.ts +10 -0
- package/dist/types/extensibility/custom-commands/index.d.ts +2 -0
- package/dist/types/extensibility/custom-commands/loader.d.ts +29 -0
- package/dist/types/extensibility/custom-commands/types.d.ts +106 -0
- package/dist/types/extensibility/custom-tools/index.d.ts +6 -0
- package/dist/types/extensibility/custom-tools/loader.d.ts +69 -0
- package/dist/types/extensibility/custom-tools/types.d.ts +232 -0
- package/dist/types/extensibility/custom-tools/wrapper.d.ts +23 -0
- package/dist/types/extensibility/extensions/compact-handler.d.ts +26 -0
- package/dist/types/extensibility/extensions/get-commands-handler.d.ts +29 -0
- package/dist/types/extensibility/extensions/index.d.ts +8 -0
- package/dist/types/extensibility/extensions/loader.d.ts +43 -0
- package/dist/types/extensibility/extensions/runner.d.ts +142 -0
- package/dist/types/extensibility/extensions/types.d.ts +892 -0
- package/dist/types/extensibility/extensions/wrapper.d.ts +54 -0
- package/dist/types/extensibility/hooks/index.d.ts +5 -0
- package/dist/types/extensibility/hooks/loader.d.ts +89 -0
- package/dist/types/extensibility/hooks/runner.d.ts +126 -0
- package/dist/types/extensibility/hooks/tool-wrapper.d.ts +25 -0
- package/dist/types/extensibility/hooks/types.d.ts +435 -0
- package/dist/types/extensibility/legacy-pi-ai-shim.d.ts +23 -0
- package/dist/types/extensibility/legacy-pi-coding-agent-shim.d.ts +14 -0
- package/dist/types/extensibility/plugins/doctor.d.ts +3 -0
- package/dist/types/extensibility/plugins/git-url.d.ts +44 -0
- package/dist/types/extensibility/plugins/index.d.ts +7 -0
- package/dist/types/extensibility/plugins/installer.d.ts +5 -0
- package/dist/types/extensibility/plugins/legacy-pi-compat.d.ts +29 -0
- package/dist/types/extensibility/plugins/loader.d.ts +41 -0
- package/dist/types/extensibility/plugins/manager.d.ts +76 -0
- package/dist/types/extensibility/plugins/marketplace/cache.d.ts +41 -0
- package/dist/types/extensibility/plugins/marketplace/fetcher.d.ts +48 -0
- package/dist/types/extensibility/plugins/marketplace/index.d.ts +6 -0
- package/dist/types/extensibility/plugins/marketplace/manager.d.ts +57 -0
- package/dist/types/extensibility/plugins/marketplace/registry.d.ts +34 -0
- package/dist/types/extensibility/plugins/marketplace/source-resolver.d.ts +28 -0
- package/dist/types/extensibility/plugins/marketplace/types.d.ts +130 -0
- package/dist/types/extensibility/plugins/parser.d.ts +52 -0
- package/dist/types/extensibility/plugins/types.d.ts +149 -0
- package/dist/types/extensibility/shared-events.d.ts +279 -0
- package/dist/types/extensibility/skills.d.ts +57 -0
- package/dist/types/extensibility/slash-commands.d.ts +48 -0
- package/dist/types/extensibility/tool-proxy.d.ts +4 -0
- package/dist/types/extensibility/typebox.d.ts +155 -0
- package/dist/types/extensibility/utils.d.ts +12 -0
- package/dist/types/gateway/adapters/telegram/access.d.ts +11 -0
- package/dist/types/gateway/adapters/telegram/commands.d.ts +41 -0
- package/dist/types/gateway/adapters/telegram/expressions.d.ts +60 -0
- package/dist/types/gateway/adapters/telegram/media.d.ts +58 -0
- package/dist/types/gateway/adapters/telegram/native-command-policy.d.ts +6 -0
- package/dist/types/gateway/adapters/telegram/native-commands.d.ts +23 -0
- package/dist/types/gateway/adapters/telegram/normalize.d.ts +8 -0
- package/dist/types/gateway/adapters/telegram/send-message.d.ts +388 -0
- package/dist/types/gateway/adapters/telegram/service.d.ts +65 -0
- package/dist/types/gateway/adapters/telegram/setup-api.d.ts +39 -0
- package/dist/types/gateway/adapters/telegram/setup-config.d.ts +11 -0
- package/dist/types/gateway/adapters/telegram/types.d.ts +187 -0
- package/dist/types/gateway/adapters/telegram/webhook.d.ts +53 -0
- package/dist/types/gateway/commands.d.ts +33 -0
- package/dist/types/gateway/context.d.ts +30 -0
- package/dist/types/gateway/native-slash-policy.d.ts +12 -0
- package/dist/types/gateway/prometheus-dispatch.d.ts +29 -0
- package/dist/types/gateway/router.d.ts +52 -0
- package/dist/types/gateway/session-key.d.ts +3 -0
- package/dist/types/gateway/types.d.ts +98 -0
- package/dist/types/goals/index.d.ts +3 -0
- package/dist/types/goals/runtime.d.ts +67 -0
- package/dist/types/goals/state.d.ts +35 -0
- package/dist/types/goals/tools/goal-tool.d.ts +66 -0
- package/dist/types/hindsight/backend.d.ts +13 -0
- package/dist/types/hindsight/bank.d.ts +62 -0
- package/dist/types/hindsight/client.d.ts +224 -0
- package/dist/types/hindsight/config.d.ts +51 -0
- package/dist/types/hindsight/content.d.ts +70 -0
- package/dist/types/hindsight/index.d.ts +8 -0
- package/dist/types/hindsight/mental-models.d.ts +125 -0
- package/dist/types/hindsight/state.d.ts +105 -0
- package/dist/types/hindsight/transcript.d.ts +28 -0
- package/dist/types/index.d.ts +36 -0
- package/dist/types/internal-urls/agent-protocol.d.ts +13 -0
- package/dist/types/internal-urls/artifact-protocol.d.ts +7 -0
- package/dist/types/internal-urls/docs-index.generated.d.ts +2 -0
- package/dist/types/internal-urls/index.d.ts +23 -0
- package/dist/types/internal-urls/issue-pr-protocol.d.ts +17 -0
- package/dist/types/internal-urls/json-query.d.ts +30 -0
- package/dist/types/internal-urls/local-protocol.d.ts +50 -0
- package/dist/types/internal-urls/mcp-protocol.d.ts +12 -0
- package/dist/types/internal-urls/memory-protocol.d.ts +24 -0
- package/dist/types/internal-urls/parse.d.ts +19 -0
- package/dist/types/internal-urls/prometheus-protocol.d.ts +13 -0
- package/dist/types/internal-urls/registry-helpers.d.ts +10 -0
- package/dist/types/internal-urls/router.d.ts +21 -0
- package/dist/types/internal-urls/rule-protocol.d.ts +7 -0
- package/dist/types/internal-urls/skill-protocol.d.ts +14 -0
- package/dist/types/internal-urls/types.d.ts +145 -0
- package/dist/types/internal-urls/vault-protocol.d.ts +93 -0
- package/dist/types/lib/xai-http.d.ts +40 -0
- package/dist/types/lsp/client.d.ts +68 -0
- package/dist/types/lsp/clients/biome-client.d.ts +16 -0
- package/dist/types/lsp/clients/index.d.ts +19 -0
- package/dist/types/lsp/clients/lsp-linter-client.d.ts +16 -0
- package/dist/types/lsp/clients/swiftlint-client.d.ts +20 -0
- package/dist/types/lsp/config.d.ts +65 -0
- package/dist/types/lsp/diagnostics-ledger.d.ts +10 -0
- package/dist/types/lsp/edits.d.ts +23 -0
- package/dist/types/lsp/index.d.ts +140 -0
- package/dist/types/lsp/lspmux.d.ts +58 -0
- package/dist/types/lsp/render.d.ts +32 -0
- package/dist/types/lsp/startup-events.d.ts +11 -0
- package/dist/types/lsp/types.d.ts +302 -0
- package/dist/types/lsp/utils.d.ts +112 -0
- package/dist/types/main.d.ts +56 -0
- package/dist/types/mcp/client.d.ts +75 -0
- package/dist/types/mcp/config-writer.d.ts +53 -0
- package/dist/types/mcp/config.d.ts +75 -0
- package/dist/types/mcp/index.d.ts +18 -0
- package/dist/types/mcp/json-rpc.d.ts +27 -0
- package/dist/types/mcp/loader.d.ts +43 -0
- package/dist/types/mcp/manager.d.ts +202 -0
- package/dist/types/mcp/oauth-discovery.d.ts +41 -0
- package/dist/types/mcp/oauth-flow.d.ts +59 -0
- package/dist/types/mcp/render.d.ts +25 -0
- package/dist/types/mcp/smithery-auth.d.ts +16 -0
- package/dist/types/mcp/smithery-connect.d.ts +38 -0
- package/dist/types/mcp/smithery-registry.d.ts +51 -0
- package/dist/types/mcp/timeout.d.ts +9 -0
- package/dist/types/mcp/tool-bridge.d.ts +90 -0
- package/dist/types/mcp/tool-cache.d.ts +8 -0
- package/dist/types/mcp/transports/http.d.ts +45 -0
- package/dist/types/mcp/transports/index.d.ts +5 -0
- package/dist/types/mcp/transports/stdio.d.ts +60 -0
- package/dist/types/mcp/types.d.ts +333 -0
- package/dist/types/memories/index.d.ts +43 -0
- package/dist/types/memories/storage.d.ts +120 -0
- package/dist/types/memory-backend/index.d.ts +5 -0
- package/dist/types/memory-backend/local-backend.d.ts +9 -0
- package/dist/types/memory-backend/off-backend.d.ts +7 -0
- package/dist/types/memory-backend/resolve.d.ts +16 -0
- package/dist/types/memory-backend/types.d.ts +67 -0
- package/dist/types/mnemopi/backend.d.ts +4 -0
- package/dist/types/mnemopi/config.d.ts +29 -0
- package/dist/types/mnemopi/index.d.ts +3 -0
- package/dist/types/mnemopi/state.d.ts +72 -0
- package/dist/types/modes/acp/acp-agent.d.ts +61 -0
- package/dist/types/modes/acp/acp-client-bridge.d.ts +9 -0
- package/dist/types/modes/acp/acp-event-mapper.d.ts +32 -0
- package/dist/types/modes/acp/acp-mode.d.ts +5 -0
- package/dist/types/modes/acp/index.d.ts +2 -0
- package/dist/types/modes/acp/terminal-auth.d.ts +6 -0
- package/dist/types/modes/components/agent-dashboard.d.ts +22 -0
- package/dist/types/modes/components/assistant-message.d.ts +35 -0
- package/dist/types/modes/components/bash-execution.d.ts +29 -0
- package/dist/types/modes/components/bordered-loader.d.ts +11 -0
- package/dist/types/modes/components/branch-summary-message.d.ts +13 -0
- package/dist/types/modes/components/btw-panel.d.ts +16 -0
- package/dist/types/modes/components/compaction-summary-message.d.ts +13 -0
- package/dist/types/modes/components/copy-selector.d.ts +22 -0
- package/dist/types/modes/components/countdown-timer.d.ts +14 -0
- package/dist/types/modes/components/custom-editor.d.ts +53 -0
- package/dist/types/modes/components/custom-message.d.ts +15 -0
- package/dist/types/modes/components/diff.d.ts +11 -0
- package/dist/types/modes/components/dynamic-border.d.ts +14 -0
- package/dist/types/modes/components/error-banner.d.ts +11 -0
- package/dist/types/modes/components/eval-execution.d.ts +23 -0
- package/dist/types/modes/components/execution-shared.d.ts +46 -0
- package/dist/types/modes/components/extensions/extension-dashboard.d.ts +27 -0
- package/dist/types/modes/components/extensions/extension-list.d.ts +39 -0
- package/dist/types/modes/components/extensions/index.d.ts +8 -0
- package/dist/types/modes/components/extensions/inspector-panel.d.ts +8 -0
- package/dist/types/modes/components/extensions/state-manager.d.ts +50 -0
- package/dist/types/modes/components/extensions/types.d.ts +147 -0
- package/dist/types/modes/components/footer.d.ts +30 -0
- package/dist/types/modes/components/history-search.d.ts +7 -0
- package/dist/types/modes/components/hook-editor.d.ts +18 -0
- package/dist/types/modes/components/hook-input.d.ts +15 -0
- package/dist/types/modes/components/hook-message.d.ts +15 -0
- package/dist/types/modes/components/hook-selector.d.ts +70 -0
- package/dist/types/modes/components/index.d.ts +37 -0
- package/dist/types/modes/components/keybinding-hints.d.ts +40 -0
- package/dist/types/modes/components/login-dialog.d.ts +32 -0
- package/dist/types/modes/components/mcp-add-wizard.d.ts +25 -0
- package/dist/types/modes/components/message-frame.d.ts +42 -0
- package/dist/types/modes/components/model-selector.d.ts +28 -0
- package/dist/types/modes/components/oauth-selector.d.ts +14 -0
- package/dist/types/modes/components/omfg-panel.d.ts +19 -0
- package/dist/types/modes/components/plugin-selector.d.ts +26 -0
- package/dist/types/modes/components/plugin-settings.d.ts +98 -0
- package/dist/types/modes/components/queue-mode-selector.d.ts +9 -0
- package/dist/types/modes/components/read-tool-group.d.ts +30 -0
- package/dist/types/modes/components/segment-track.d.ts +22 -0
- package/dist/types/modes/components/session-observer-overlay.d.ts +11 -0
- package/dist/types/modes/components/session-selector.d.ts +62 -0
- package/dist/types/modes/components/settings-defs.d.ts +50 -0
- package/dist/types/modes/components/settings-selector.d.ts +54 -0
- package/dist/types/modes/components/show-images-selector.d.ts +9 -0
- package/dist/types/modes/components/skill-message.d.ts +9 -0
- package/dist/types/modes/components/status-line/context-thresholds.d.ts +10 -0
- package/dist/types/modes/components/status-line/git-utils.d.ts +22 -0
- package/dist/types/modes/components/status-line/index.d.ts +4 -0
- package/dist/types/modes/components/status-line/presets.d.ts +3 -0
- package/dist/types/modes/components/status-line/segments.d.ts +5 -0
- package/dist/types/modes/components/status-line/separators.d.ts +3 -0
- package/dist/types/modes/components/status-line/token-rate.d.ts +10 -0
- package/dist/types/modes/components/status-line/types.d.ts +80 -0
- package/dist/types/modes/components/status-line.d.ts +77 -0
- package/dist/types/modes/components/theme-selector.d.ts +10 -0
- package/dist/types/modes/components/thinking-selector.d.ts +10 -0
- package/dist/types/modes/components/tiny-title-download-progress.d.ts +11 -0
- package/dist/types/modes/components/todo-reminder.d.ts +13 -0
- package/dist/types/modes/components/tool-execution.d.ts +77 -0
- package/dist/types/modes/components/transcript-container.d.ts +38 -0
- package/dist/types/modes/components/tree-selector.d.ts +31 -0
- package/dist/types/modes/components/ttsr-notification.d.ts +13 -0
- package/dist/types/modes/components/user-message-selector.d.ts +28 -0
- package/dist/types/modes/components/user-message.d.ts +8 -0
- package/dist/types/modes/components/visual-truncate.d.ts +19 -0
- package/dist/types/modes/components/welcome.d.ts +55 -0
- package/dist/types/modes/controllers/btw-controller.d.ts +10 -0
- package/dist/types/modes/controllers/command-controller-shared.d.ts +47 -0
- package/dist/types/modes/controllers/command-controller.d.ts +41 -0
- package/dist/types/modes/controllers/event-controller.d.ts +12 -0
- package/dist/types/modes/controllers/extension-ui-controller.d.ts +83 -0
- package/dist/types/modes/controllers/input-controller.d.ts +34 -0
- package/dist/types/modes/controllers/mcp-command-controller.d.ts +10 -0
- package/dist/types/modes/controllers/omfg-controller.d.ts +10 -0
- package/dist/types/modes/controllers/omfg-rule.d.ts +26 -0
- package/dist/types/modes/controllers/selector-controller.d.ts +46 -0
- package/dist/types/modes/controllers/ssh-command-controller.d.ts +10 -0
- package/dist/types/modes/controllers/todo-command-controller.d.ts +7 -0
- package/dist/types/modes/emoji-autocomplete.d.ts +16 -0
- package/dist/types/modes/gradient-highlight.d.ts +27 -0
- package/dist/types/modes/image-references.d.ts +17 -0
- package/dist/types/modes/index.d.ts +9 -0
- package/dist/types/modes/interactive-mode.d.ts +291 -0
- package/dist/types/modes/internal-url-autocomplete.d.ts +43 -0
- package/dist/types/modes/loop-limit.d.ts +22 -0
- package/dist/types/modes/magic-keywords.d.ts +14 -0
- package/dist/types/modes/markdown-prose.d.ts +27 -0
- package/dist/types/modes/oauth-manual-input.d.ts +8 -0
- package/dist/types/modes/orchestrate.d.ts +15 -0
- package/dist/types/modes/print-mode.d.ts +27 -0
- package/dist/types/modes/prompt-action-autocomplete.d.ts +46 -0
- package/dist/types/modes/rpc/host-tools.d.ts +16 -0
- package/dist/types/modes/rpc/host-uris.d.ts +38 -0
- package/dist/types/modes/rpc/rpc-client.d.ts +249 -0
- package/dist/types/modes/rpc/rpc-mode.d.ts +17 -0
- package/dist/types/modes/rpc/rpc-types.d.ts +586 -0
- package/dist/types/modes/runtime-init.d.ts +21 -0
- package/dist/types/modes/session-observer-registry.d.ts +26 -0
- package/dist/types/modes/setup-wizard/index.d.ts +16 -0
- package/dist/types/modes/setup-wizard/scenes/channels.d.ts +14 -0
- package/dist/types/modes/setup-wizard/scenes/glyph.d.ts +2 -0
- package/dist/types/modes/setup-wizard/scenes/outro.d.ts +2 -0
- package/dist/types/modes/setup-wizard/scenes/providers.d.ts +2 -0
- package/dist/types/modes/setup-wizard/scenes/sign-in.d.ts +19 -0
- package/dist/types/modes/setup-wizard/scenes/splash.d.ts +11 -0
- package/dist/types/modes/setup-wizard/scenes/telegram.d.ts +20 -0
- package/dist/types/modes/setup-wizard/scenes/theme.d.ts +2 -0
- package/dist/types/modes/setup-wizard/scenes/types.d.ts +43 -0
- package/dist/types/modes/setup-wizard/scenes/web-search.d.ts +19 -0
- package/dist/types/modes/setup-wizard/wizard-overlay.d.ts +14 -0
- package/dist/types/modes/shared.d.ts +15 -0
- package/dist/types/modes/theme/defaults/index.d.ts +9436 -0
- package/dist/types/modes/theme/mermaid-cache.d.ts +9 -0
- package/dist/types/modes/theme/shimmer.d.ts +40 -0
- package/dist/types/modes/theme/theme.d.ts +305 -0
- package/dist/types/modes/turn-budget.d.ts +18 -0
- package/dist/types/modes/types.d.ts +294 -0
- package/dist/types/modes/ultrathink.d.ts +15 -0
- package/dist/types/modes/utils/context-usage.d.ts +47 -0
- package/dist/types/modes/utils/copy-targets.d.ts +53 -0
- package/dist/types/modes/utils/hotkeys-markdown.d.ts +5 -0
- package/dist/types/modes/utils/keybinding-matchers.d.ts +19 -0
- package/dist/types/modes/utils/tools-markdown.d.ts +5 -0
- package/dist/types/modes/utils/ui-helpers.d.ts +55 -0
- package/dist/types/modes/workflow.d.ts +15 -0
- package/dist/types/plan-mode/approved-plan.d.ts +49 -0
- package/dist/types/plan-mode/plan-handoff.d.ts +20 -0
- package/dist/types/plan-mode/plan-protection.d.ts +12 -0
- package/dist/types/plan-mode/state.d.ts +6 -0
- package/dist/types/registry/agent-registry.d.ts +62 -0
- package/dist/types/sdk.d.ts +271 -0
- package/dist/types/secrets/index.d.ts +9 -0
- package/dist/types/secrets/obfuscator.d.ts +23 -0
- package/dist/types/secrets/regex.d.ts +2 -0
- package/dist/types/session/agent-session.d.ts +1032 -0
- package/dist/types/session/agent-storage.d.ts +94 -0
- package/dist/types/session/artifacts.d.ts +61 -0
- package/dist/types/session/auth-broker-config.d.ts +13 -0
- package/dist/types/session/auth-storage.d.ts +6 -0
- package/dist/types/session/blob-store.d.ts +64 -0
- package/dist/types/session/client-bridge.d.ts +88 -0
- package/dist/types/session/history-storage.d.ts +30 -0
- package/dist/types/session/indexed-session-storage.d.ts +59 -0
- package/dist/types/session/messages.d.ts +173 -0
- package/dist/types/session/redis-session-storage.d.ts +51 -0
- package/dist/types/session/session-dump-format.d.ts +22 -0
- package/dist/types/session/session-manager.d.ts +594 -0
- package/dist/types/session/session-storage.d.ts +86 -0
- package/dist/types/session/shake-types.d.ts +24 -0
- package/dist/types/session/sql-session-storage.d.ts +72 -0
- package/dist/types/session/streaming-output.d.ts +185 -0
- package/dist/types/session/tool-choice-queue.d.ts +78 -0
- package/dist/types/session/yield-queue.d.ts +24 -0
- package/dist/types/slash-commands/acp-builtins.d.ts +18 -0
- package/dist/types/slash-commands/builtin-registry.d.ts +23 -0
- package/dist/types/slash-commands/headless-plan.d.ts +3 -0
- package/dist/types/slash-commands/helpers/context-report.d.ts +7 -0
- package/dist/types/slash-commands/helpers/format.d.ts +10 -0
- package/dist/types/slash-commands/helpers/marketplace-manager.d.ts +8 -0
- package/dist/types/slash-commands/helpers/mcp.d.ts +3 -0
- package/dist/types/slash-commands/helpers/parse.d.ts +33 -0
- package/dist/types/slash-commands/helpers/ssh.d.ts +3 -0
- package/dist/types/slash-commands/helpers/todo.d.ts +3 -0
- package/dist/types/slash-commands/helpers/usage-report.d.ts +7 -0
- package/dist/types/slash-commands/marketplace-install-parser.d.ts +33 -0
- package/dist/types/slash-commands/types.d.ts +129 -0
- package/dist/types/ssh/config-writer.d.ts +49 -0
- package/dist/types/ssh/connection-manager.d.ts +33 -0
- package/dist/types/ssh/ssh-executor.d.ts +37 -0
- package/dist/types/ssh/sshfs-mount.d.ts +6 -0
- package/dist/types/ssh/utils.d.ts +2 -0
- package/dist/types/stt/downloader.d.ts +9 -0
- package/dist/types/stt/index.d.ts +3 -0
- package/dist/types/stt/recorder.d.ts +13 -0
- package/dist/types/stt/setup.d.ts +18 -0
- package/dist/types/stt/stt-controller.d.ts +16 -0
- package/dist/types/stt/transcriber.d.ts +16 -0
- package/dist/types/system-prompt.d.ts +97 -0
- package/dist/types/task/agents.d.ts +28 -0
- package/dist/types/task/commands.d.ts +35 -0
- package/dist/types/task/discovery.d.ts +18 -0
- package/dist/types/task/executor.d.ts +121 -0
- package/dist/types/task/index.d.ts +42 -0
- package/dist/types/task/name-generator.d.ts +16 -0
- package/dist/types/task/output-manager.d.ts +27 -0
- package/dist/types/task/parallel.d.ts +34 -0
- package/dist/types/task/prometheus-command.d.ts +7 -0
- package/dist/types/task/render.d.ts +26 -0
- package/dist/types/task/repair-args.d.ts +52 -0
- package/dist/types/task/simple-mode.d.ts +8 -0
- package/dist/types/task/subprocess-tool-registry.d.ts +72 -0
- package/dist/types/task/types.d.ts +300 -0
- package/dist/types/task/worktree.d.ts +94 -0
- package/dist/types/telemetry-export.d.ts +43 -0
- package/dist/types/thinking.d.ts +68 -0
- package/dist/types/tiny/compiled-runtime.d.ts +35 -0
- package/dist/types/tiny/device.d.ts +78 -0
- package/dist/types/tiny/dtype.d.ts +85 -0
- package/dist/types/tiny/models.d.ts +204 -0
- package/dist/types/tiny/text.d.ts +36 -0
- package/dist/types/tiny/title-client.d.ts +73 -0
- package/dist/types/tiny/title-protocol.d.ts +77 -0
- package/dist/types/tiny/worker.d.ts +2 -0
- package/dist/types/tool-discovery/mode.d.ts +8 -0
- package/dist/types/tool-discovery/tool-index.d.ts +57 -0
- package/dist/types/tools/approval.d.ts +46 -0
- package/dist/types/tools/archive-reader.d.ts +44 -0
- package/dist/types/tools/ask.d.ts +113 -0
- package/dist/types/tools/ast-edit.d.ts +79 -0
- package/dist/types/tools/ast-grep.d.ts +70 -0
- package/dist/types/tools/auto-generated-guard.d.ts +17 -0
- package/dist/types/tools/bash-command-fixup.d.ts +11 -0
- package/dist/types/tools/bash-interactive.d.ts +16 -0
- package/dist/types/tools/bash-interceptor.d.ts +24 -0
- package/dist/types/tools/bash-pty-selection.d.ts +7 -0
- package/dist/types/tools/bash-skill-urls.d.ts +31 -0
- package/dist/types/tools/bash.d.ts +142 -0
- package/dist/types/tools/browser/attach.d.ts +34 -0
- package/dist/types/tools/browser/launch.d.ts +62 -0
- package/dist/types/tools/browser/readable.d.ts +17 -0
- package/dist/types/tools/browser/registry.d.ts +42 -0
- package/dist/types/tools/browser/render.d.ts +50 -0
- package/dist/types/tools/browser/tab-protocol.d.ts +144 -0
- package/dist/types/tools/browser/tab-supervisor.d.ts +63 -0
- package/dist/types/tools/browser/tab-worker-entry.d.ts +1 -0
- package/dist/types/tools/browser/tab-worker.d.ts +19 -0
- package/dist/types/tools/browser.d.ts +116 -0
- package/dist/types/tools/checkpoint.d.ts +65 -0
- package/dist/types/tools/conflict-detect.d.ts +205 -0
- package/dist/types/tools/context.d.ts +19 -0
- package/dist/types/tools/debug.d.ts +217 -0
- package/dist/types/tools/eval-backends.d.ts +12 -0
- package/dist/types/tools/eval-render.d.ts +60 -0
- package/dist/types/tools/eval.d.ts +77 -0
- package/dist/types/tools/fetch.d.ts +80 -0
- package/dist/types/tools/file-recorder.d.ts +13 -0
- package/dist/types/tools/find.d.ts +103 -0
- package/dist/types/tools/fs-cache-invalidation.d.ts +15 -0
- package/dist/types/tools/gh-format.d.ts +6 -0
- package/dist/types/tools/gh-renderer.d.ts +25 -0
- package/dist/types/tools/gh.d.ts +357 -0
- package/dist/types/tools/github-cache.d.ts +103 -0
- package/dist/types/tools/grouped-file-output.d.ts +36 -0
- package/dist/types/tools/image-gen.d.ts +82 -0
- package/dist/types/tools/index.d.ts +269 -0
- package/dist/types/tools/inspect-image-renderer.d.ts +26 -0
- package/dist/types/tools/inspect-image.d.ts +32 -0
- package/dist/types/tools/irc.d.ts +80 -0
- package/dist/types/tools/job.d.ts +66 -0
- package/dist/types/tools/json-tree.d.ts +23 -0
- package/dist/types/tools/jtd-to-json-schema.d.ts +29 -0
- package/dist/types/tools/jtd-to-typescript.d.ts +26 -0
- package/dist/types/tools/jtd-utils.d.ts +42 -0
- package/dist/types/tools/list-limit.d.ts +12 -0
- package/dist/types/tools/match-line-format.d.ts +11 -0
- package/dist/types/tools/memory-edit.d.ts +40 -0
- package/dist/types/tools/memory-recall.d.ts +24 -0
- package/dist/types/tools/memory-reflect.d.ts +26 -0
- package/dist/types/tools/memory-render.d.ts +60 -0
- package/dist/types/tools/memory-retain.d.ts +30 -0
- package/dist/types/tools/output-meta.d.ts +204 -0
- package/dist/types/tools/output-schema-validator.d.ts +64 -0
- package/dist/types/tools/path-utils.d.ts +199 -0
- package/dist/types/tools/plan-mode-guard.d.ts +17 -0
- package/dist/types/tools/read.d.ts +86 -0
- package/dist/types/tools/render-mermaid.d.ts +38 -0
- package/dist/types/tools/render-utils.d.ts +185 -0
- package/dist/types/tools/renderers.d.ts +26 -0
- package/dist/types/tools/report-tool-issue.d.ts +123 -0
- package/dist/types/tools/resolve.d.ts +91 -0
- package/dist/types/tools/review.d.ts +63 -0
- package/dist/types/tools/search-tool-bm25.d.ts +66 -0
- package/dist/types/tools/search.d.ts +95 -0
- package/dist/types/tools/sqlite-reader.d.ts +110 -0
- package/dist/types/tools/ssh.d.ts +69 -0
- package/dist/types/tools/todo.d.ts +159 -0
- package/dist/types/tools/tool-errors.d.ts +33 -0
- package/dist/types/tools/tool-result.d.ts +32 -0
- package/dist/types/tools/tool-timeouts.d.ts +51 -0
- package/dist/types/tools/tts.d.ts +18 -0
- package/dist/types/tools/write.d.ts +65 -0
- package/dist/types/tools/yield.d.ts +26 -0
- package/dist/types/tui/code-cell.d.ts +40 -0
- package/dist/types/tui/file-list.d.ts +22 -0
- package/dist/types/tui/hyperlink.d.ts +54 -0
- package/dist/types/tui/index.d.ts +11 -0
- package/dist/types/tui/output-block.d.ts +57 -0
- package/dist/types/tui/status-line.d.ts +18 -0
- package/dist/types/tui/tree-list.d.ts +19 -0
- package/dist/types/tui/types.d.ts +13 -0
- package/dist/types/tui/utils.d.ts +36 -0
- package/dist/types/utils/changelog.d.ts +25 -0
- package/dist/types/utils/clipboard.d.ts +26 -0
- package/dist/types/utils/command-args.d.ts +9 -0
- package/dist/types/utils/commit-message-generator.d.ts +7 -0
- package/dist/types/utils/edit-mode.d.ts +13 -0
- package/dist/types/utils/event-bus.d.ts +6 -0
- package/dist/types/utils/external-editor.d.ts +17 -0
- package/dist/types/utils/file-display-mode.d.ts +27 -0
- package/dist/types/utils/file-mentions.d.ts +13 -0
- package/dist/types/utils/git.d.ts +361 -0
- package/dist/types/utils/image-loading.d.ts +26 -0
- package/dist/types/utils/image-resize.d.ts +39 -0
- package/dist/types/utils/jj.d.ts +49 -0
- package/dist/types/utils/lang-from-path.d.ts +8 -0
- package/dist/types/utils/markit.d.ts +7 -0
- package/dist/types/utils/open.d.ts +2 -0
- package/dist/types/utils/session-color.d.ts +15 -0
- package/dist/types/utils/shell-snapshot.d.ts +5 -0
- package/dist/types/utils/sixel.d.ts +21 -0
- package/dist/types/utils/title-generator.d.ts +34 -0
- package/dist/types/utils/tool-choice.d.ts +7 -0
- package/dist/types/utils/tools-manager.d.ts +9 -0
- package/dist/types/web/kagi.d.ts +99 -0
- package/dist/types/web/parallel.d.ts +58 -0
- package/dist/types/web/scrapers/artifacthub.d.ts +6 -0
- package/dist/types/web/scrapers/arxiv.d.ts +5 -0
- package/dist/types/web/scrapers/aur.d.ts +5 -0
- package/dist/types/web/scrapers/biorxiv.d.ts +5 -0
- package/dist/types/web/scrapers/bluesky.d.ts +5 -0
- package/dist/types/web/scrapers/brew.d.ts +5 -0
- package/dist/types/web/scrapers/cheatsh.d.ts +8 -0
- package/dist/types/web/scrapers/chocolatey.d.ts +5 -0
- package/dist/types/web/scrapers/choosealicense.d.ts +2 -0
- package/dist/types/web/scrapers/cisa-kev.d.ts +5 -0
- package/dist/types/web/scrapers/clojars.d.ts +5 -0
- package/dist/types/web/scrapers/coingecko.d.ts +5 -0
- package/dist/types/web/scrapers/crates-io.d.ts +5 -0
- package/dist/types/web/scrapers/crossref.d.ts +2 -0
- package/dist/types/web/scrapers/devto.d.ts +5 -0
- package/dist/types/web/scrapers/discogs.d.ts +8 -0
- package/dist/types/web/scrapers/discourse.d.ts +5 -0
- package/dist/types/web/scrapers/dockerhub.d.ts +5 -0
- package/dist/types/web/scrapers/docs-rs.d.ts +2 -0
- package/dist/types/web/scrapers/fdroid.d.ts +5 -0
- package/dist/types/web/scrapers/firefox-addons.d.ts +2 -0
- package/dist/types/web/scrapers/flathub.d.ts +2 -0
- package/dist/types/web/scrapers/github-gist.d.ts +5 -0
- package/dist/types/web/scrapers/github.d.ts +12 -0
- package/dist/types/web/scrapers/gitlab.d.ts +5 -0
- package/dist/types/web/scrapers/go-pkg.d.ts +5 -0
- package/dist/types/web/scrapers/hackage.d.ts +5 -0
- package/dist/types/web/scrapers/hackernews.d.ts +2 -0
- package/dist/types/web/scrapers/hex.d.ts +5 -0
- package/dist/types/web/scrapers/huggingface.d.ts +2 -0
- package/dist/types/web/scrapers/iacr.d.ts +5 -0
- package/dist/types/web/scrapers/index.d.ts +84 -0
- package/dist/types/web/scrapers/jetbrains-marketplace.d.ts +2 -0
- package/dist/types/web/scrapers/lemmy.d.ts +2 -0
- package/dist/types/web/scrapers/lobsters.d.ts +5 -0
- package/dist/types/web/scrapers/mastodon.d.ts +5 -0
- package/dist/types/web/scrapers/maven.d.ts +6 -0
- package/dist/types/web/scrapers/mdn.d.ts +2 -0
- package/dist/types/web/scrapers/metacpan.d.ts +5 -0
- package/dist/types/web/scrapers/musicbrainz.d.ts +5 -0
- package/dist/types/web/scrapers/npm.d.ts +5 -0
- package/dist/types/web/scrapers/nuget.d.ts +5 -0
- package/dist/types/web/scrapers/nvd.d.ts +5 -0
- package/dist/types/web/scrapers/ollama.d.ts +2 -0
- package/dist/types/web/scrapers/open-vsx.d.ts +5 -0
- package/dist/types/web/scrapers/opencorporates.d.ts +5 -0
- package/dist/types/web/scrapers/openlibrary.d.ts +5 -0
- package/dist/types/web/scrapers/orcid.d.ts +5 -0
- package/dist/types/web/scrapers/osv.d.ts +5 -0
- package/dist/types/web/scrapers/packagist.d.ts +5 -0
- package/dist/types/web/scrapers/pub-dev.d.ts +5 -0
- package/dist/types/web/scrapers/pubmed.d.ts +5 -0
- package/dist/types/web/scrapers/pypi.d.ts +5 -0
- package/dist/types/web/scrapers/rawg.d.ts +2 -0
- package/dist/types/web/scrapers/readthedocs.d.ts +2 -0
- package/dist/types/web/scrapers/reddit.d.ts +5 -0
- package/dist/types/web/scrapers/repology.d.ts +5 -0
- package/dist/types/web/scrapers/rfc.d.ts +5 -0
- package/dist/types/web/scrapers/rubygems.d.ts +5 -0
- package/dist/types/web/scrapers/searchcode.d.ts +2 -0
- package/dist/types/web/scrapers/sec-edgar.d.ts +5 -0
- package/dist/types/web/scrapers/semantic-scholar.d.ts +2 -0
- package/dist/types/web/scrapers/snapcraft.d.ts +2 -0
- package/dist/types/web/scrapers/sourcegraph.d.ts +2 -0
- package/dist/types/web/scrapers/spdx.d.ts +5 -0
- package/dist/types/web/scrapers/spotify.d.ts +8 -0
- package/dist/types/web/scrapers/stackoverflow.d.ts +6 -0
- package/dist/types/web/scrapers/terraform.d.ts +5 -0
- package/dist/types/web/scrapers/tldr.d.ts +7 -0
- package/dist/types/web/scrapers/twitter.d.ts +5 -0
- package/dist/types/web/scrapers/types.d.ts +78 -0
- package/dist/types/web/scrapers/utils.d.ts +26 -0
- package/dist/types/web/scrapers/vimeo.d.ts +5 -0
- package/dist/types/web/scrapers/vscode-marketplace.d.ts +5 -0
- package/dist/types/web/scrapers/w3c.d.ts +2 -0
- package/dist/types/web/scrapers/wikidata.d.ts +5 -0
- package/dist/types/web/scrapers/wikipedia.d.ts +5 -0
- package/dist/types/web/scrapers/youtube.d.ts +5 -0
- package/dist/types/web/search/index.d.ts +85 -0
- package/dist/types/web/search/provider.d.ts +21 -0
- package/dist/types/web/search/providers/anthropic.d.ts +32 -0
- package/dist/types/web/search/providers/base.d.ts +81 -0
- package/dist/types/web/search/providers/brave.d.ts +27 -0
- package/dist/types/web/search/providers/codex.d.ts +35 -0
- package/dist/types/web/search/providers/exa.d.ts +67 -0
- package/dist/types/web/search/providers/gemini.d.ts +57 -0
- package/dist/types/web/search/providers/jina.d.ts +26 -0
- package/dist/types/web/search/providers/kagi.d.ts +25 -0
- package/dist/types/web/search/providers/kimi.d.ts +27 -0
- package/dist/types/web/search/providers/parallel.d.ts +15 -0
- package/dist/types/web/search/providers/perplexity.d.ts +38 -0
- package/dist/types/web/search/providers/searxng.d.ts +44 -0
- package/dist/types/web/search/providers/synthetic.d.ts +21 -0
- package/dist/types/web/search/providers/tavily.d.ts +29 -0
- package/dist/types/web/search/providers/utils.d.ts +52 -0
- package/dist/types/web/search/providers/zai.d.ts +28 -0
- package/dist/types/web/search/render.d.ts +34 -0
- package/dist/types/web/search/types.d.ts +409 -0
- package/dist/types/web/search/utils.d.ts +4 -0
- package/dist/types/workspace-tree.d.ts +42 -0
- package/examples/README.md +21 -0
- package/examples/custom-tools/README.md +104 -0
- package/examples/custom-tools/hello/index.ts +20 -0
- package/examples/extensions/README.md +142 -0
- package/examples/extensions/api-demo.ts +79 -0
- package/examples/extensions/chalk-logger.ts +25 -0
- package/examples/extensions/hello.ts +31 -0
- package/examples/extensions/pirate.ts +43 -0
- package/examples/extensions/plan-mode.ts +549 -0
- package/examples/extensions/reload-runtime.ts +38 -0
- package/examples/extensions/thinking-note.ts +13 -0
- package/examples/extensions/tools.ts +144 -0
- package/examples/extensions/with-deps/index.ts +36 -0
- package/examples/extensions/with-deps/package-lock.json +31 -0
- package/examples/extensions/with-deps/package.json +16 -0
- package/examples/hooks/README.md +56 -0
- package/examples/hooks/auto-commit-on-exit.ts +48 -0
- package/examples/hooks/confirm-destructive.ts +58 -0
- package/examples/hooks/custom-compaction.ts +116 -0
- package/examples/hooks/dirty-repo-guard.ts +51 -0
- package/examples/hooks/file-trigger.ts +40 -0
- package/examples/hooks/git-checkpoint.ts +52 -0
- package/examples/hooks/handoff.ts +150 -0
- package/examples/hooks/permission-gate.ts +33 -0
- package/examples/hooks/protected-paths.ts +29 -0
- package/examples/hooks/qna.ts +119 -0
- package/examples/hooks/status-line.ts +39 -0
- package/examples/sdk/01-minimal.ts +21 -0
- package/examples/sdk/02-custom-model.ts +50 -0
- package/examples/sdk/03-custom-prompt.ts +46 -0
- package/examples/sdk/04-skills.ts +43 -0
- package/examples/sdk/06-extensions.ts +82 -0
- package/examples/sdk/06-hooks.ts +61 -0
- package/examples/sdk/07-context-files.ts +35 -0
- package/examples/sdk/08-prompt-templates.ts +36 -0
- package/examples/sdk/08-slash-commands.ts +41 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +54 -0
- package/examples/sdk/11-sessions.ts +47 -0
- package/examples/sdk/12-redis-sessions.ts +54 -0
- package/examples/sdk/13-sql-sessions.ts +61 -0
- package/examples/sdk/README.md +172 -0
- package/package.json +548 -0
- package/scripts/build-binary.ts +105 -0
- package/scripts/format-prompts.ts +68 -0
- package/scripts/generate-docs-index.ts +40 -0
- package/scripts/generate-template.ts +33 -0
- package/src/async/index.ts +2 -0
- package/src/async/job-manager.ts +571 -0
- package/src/async/support.ts +5 -0
- package/src/auto-thinking/classifier.ts +180 -0
- package/src/autoresearch/command-resume.md +14 -0
- package/src/autoresearch/dashboard.ts +436 -0
- package/src/autoresearch/git.ts +319 -0
- package/src/autoresearch/helpers.ts +218 -0
- package/src/autoresearch/index.ts +536 -0
- package/src/autoresearch/prompt-setup.md +43 -0
- package/src/autoresearch/prompt.md +103 -0
- package/src/autoresearch/resume-message.md +10 -0
- package/src/autoresearch/state.ts +273 -0
- package/src/autoresearch/storage.ts +699 -0
- package/src/autoresearch/tools/init-experiment.ts +272 -0
- package/src/autoresearch/tools/log-experiment.ts +524 -0
- package/src/autoresearch/tools/run-experiment.ts +407 -0
- package/src/autoresearch/tools/update-notes.ts +109 -0
- package/src/autoresearch/types.ts +168 -0
- package/src/bun-imports.d.ts +28 -0
- package/src/capability/context-file.ts +58 -0
- package/src/capability/extension-module.ts +34 -0
- package/src/capability/extension.ts +47 -0
- package/src/capability/fs.ts +107 -0
- package/src/capability/hook.ts +40 -0
- package/src/capability/index.ts +441 -0
- package/src/capability/instruction.ts +37 -0
- package/src/capability/mcp.ts +74 -0
- package/src/capability/prompt.ts +35 -0
- package/src/capability/rule-buckets.ts +64 -0
- package/src/capability/rule.ts +252 -0
- package/src/capability/settings.ts +34 -0
- package/src/capability/skill.ts +63 -0
- package/src/capability/slash-command.ts +40 -0
- package/src/capability/ssh.ts +41 -0
- package/src/capability/system-prompt.ts +34 -0
- package/src/capability/tool.ts +38 -0
- package/src/capability/types.ts +172 -0
- package/src/cli/agents-cli.ts +138 -0
- package/src/cli/args.ts +335 -0
- package/src/cli/auth-broker-cli.ts +898 -0
- package/src/cli/auth-gateway-cli.ts +612 -0
- package/src/cli/classify-install-target.ts +76 -0
- package/src/cli/claude-trace-cli.ts +813 -0
- package/src/cli/commands/init-xdg.ts +27 -0
- package/src/cli/completion-gen.ts +550 -0
- package/src/cli/config-cli.ts +418 -0
- package/src/cli/dry-balance-cli.ts +823 -0
- package/src/cli/extension-flags.ts +48 -0
- package/src/cli/file-processor.ts +133 -0
- package/src/cli/gateway-cli.ts +664 -0
- package/src/cli/grep-cli.ts +160 -0
- package/src/cli/grievances-cli.ts +260 -0
- package/src/cli/initial-message.ts +58 -0
- package/src/cli/list-models.ts +194 -0
- package/src/cli/plugin-cli.ts +996 -0
- package/src/cli/read-cli.ts +57 -0
- package/src/cli/session-picker.ts +79 -0
- package/src/cli/setup-cli.ts +231 -0
- package/src/cli/shell-cli.ts +176 -0
- package/src/cli/ssh-cli.ts +181 -0
- package/src/cli/stats-cli.ts +238 -0
- package/src/cli/tiny-models-cli.ts +127 -0
- package/src/cli/update-cli.ts +739 -0
- package/src/cli/web-search-cli.ts +132 -0
- package/src/cli/worktree-cli.ts +291 -0
- package/src/cli-commands.ts +49 -0
- package/src/cli.ts +123 -0
- package/src/commands/acp.ts +24 -0
- package/src/commands/agents.ts +57 -0
- package/src/commands/auth-broker.ts +99 -0
- package/src/commands/auth-gateway.ts +69 -0
- package/src/commands/commit.ts +46 -0
- package/src/commands/complete.ts +66 -0
- package/src/commands/completions.ts +60 -0
- package/src/commands/config.ts +51 -0
- package/src/commands/dry-balance.ts +43 -0
- package/src/commands/gateway.ts +103 -0
- package/src/commands/grep.ts +48 -0
- package/src/commands/grievances.ts +51 -0
- package/src/commands/install.ts +107 -0
- package/src/commands/launch.ts +162 -0
- package/src/commands/plugin.ts +78 -0
- package/src/commands/read.ts +35 -0
- package/src/commands/setup.ts +67 -0
- package/src/commands/shell.ts +29 -0
- package/src/commands/ssh.ts +60 -0
- package/src/commands/stats.ts +29 -0
- package/src/commands/tiny-models.ts +36 -0
- package/src/commands/update.ts +21 -0
- package/src/commands/web-search.ts +42 -0
- package/src/commands/worktree.ts +56 -0
- package/src/commit/agentic/agent.ts +316 -0
- package/src/commit/agentic/fallback.ts +96 -0
- package/src/commit/agentic/index.ts +355 -0
- package/src/commit/agentic/prompts/analyze-file.md +22 -0
- package/src/commit/agentic/prompts/session-user.md +25 -0
- package/src/commit/agentic/prompts/split-confirm.md +1 -0
- package/src/commit/agentic/prompts/system.md +38 -0
- package/src/commit/agentic/state.ts +60 -0
- package/src/commit/agentic/tools/analyze-file.ts +127 -0
- package/src/commit/agentic/tools/git-file-diff.ts +191 -0
- package/src/commit/agentic/tools/git-hunk.ts +50 -0
- package/src/commit/agentic/tools/git-overview.ts +81 -0
- package/src/commit/agentic/tools/index.ts +54 -0
- package/src/commit/agentic/tools/propose-changelog.ts +144 -0
- package/src/commit/agentic/tools/propose-commit.ts +109 -0
- package/src/commit/agentic/tools/recent-commits.ts +81 -0
- package/src/commit/agentic/tools/schemas.ts +23 -0
- package/src/commit/agentic/tools/split-commit.ts +238 -0
- package/src/commit/agentic/topo-sort.ts +44 -0
- package/src/commit/agentic/trivial.ts +51 -0
- package/src/commit/agentic/validation.ts +183 -0
- package/src/commit/analysis/conventional.ts +64 -0
- package/src/commit/analysis/index.ts +4 -0
- package/src/commit/analysis/scope.ts +242 -0
- package/src/commit/analysis/summary.ts +105 -0
- package/src/commit/analysis/validation.ts +66 -0
- package/src/commit/changelog/detect.ts +40 -0
- package/src/commit/changelog/generate.ts +97 -0
- package/src/commit/changelog/index.ts +234 -0
- package/src/commit/changelog/parse.ts +44 -0
- package/src/commit/cli.ts +85 -0
- package/src/commit/git/diff.ts +148 -0
- package/src/commit/index.ts +5 -0
- package/src/commit/map-reduce/index.ts +69 -0
- package/src/commit/map-reduce/map-phase.ts +193 -0
- package/src/commit/map-reduce/reduce-phase.ts +49 -0
- package/src/commit/map-reduce/utils.ts +9 -0
- package/src/commit/message.ts +11 -0
- package/src/commit/model-selection.ts +66 -0
- package/src/commit/pipeline.ts +243 -0
- package/src/commit/prompts/analysis-system.md +148 -0
- package/src/commit/prompts/analysis-user.md +38 -0
- package/src/commit/prompts/changelog-system.md +50 -0
- package/src/commit/prompts/changelog-user.md +18 -0
- package/src/commit/prompts/file-observer-system.md +24 -0
- package/src/commit/prompts/file-observer-user.md +8 -0
- package/src/commit/prompts/reduce-system.md +50 -0
- package/src/commit/prompts/reduce-user.md +17 -0
- package/src/commit/prompts/summary-retry.md +3 -0
- package/src/commit/prompts/summary-system.md +38 -0
- package/src/commit/prompts/summary-user.md +13 -0
- package/src/commit/prompts/types-description.md +2 -0
- package/src/commit/shared-llm.ts +77 -0
- package/src/commit/types.ts +118 -0
- package/src/commit/utils/exclusions.ts +42 -0
- package/src/commit/utils.ts +58 -0
- package/src/config/append-only-context-mode.ts +37 -0
- package/src/config/config-file.ts +317 -0
- package/src/config/file-lock.ts +164 -0
- package/src/config/keybindings.ts +623 -0
- package/src/config/mcp-schema.json +230 -0
- package/src/config/model-equivalence.ts +852 -0
- package/src/config/model-id-affixes.ts +64 -0
- package/src/config/model-registry.ts +2650 -0
- package/src/config/model-resolver.ts +1402 -0
- package/src/config/models-config-schema.ts +177 -0
- package/src/config/prompt-templates.ts +185 -0
- package/src/config/resolve-config-value.ts +94 -0
- package/src/config/settings-schema.ts +3752 -0
- package/src/config/settings.ts +1017 -0
- package/src/config.ts +242 -0
- package/src/cursor.ts +340 -0
- package/src/dap/client.ts +675 -0
- package/src/dap/config.ts +150 -0
- package/src/dap/defaults.json +211 -0
- package/src/dap/index.ts +4 -0
- package/src/dap/session.ts +1339 -0
- package/src/dap/types.ts +600 -0
- package/src/debug/index.ts +525 -0
- package/src/debug/log-formatting.ts +58 -0
- package/src/debug/log-viewer.ts +908 -0
- package/src/debug/profiler.ts +162 -0
- package/src/debug/protocol-probe.ts +267 -0
- package/src/debug/raw-sse-buffer.ts +270 -0
- package/src/debug/raw-sse.ts +292 -0
- package/src/debug/report-bundle.ts +365 -0
- package/src/debug/system-info.ts +111 -0
- package/src/debug/terminal-info.ts +127 -0
- package/src/discovery/agents-md.ts +63 -0
- package/src/discovery/agents.ts +236 -0
- package/src/discovery/builtin-defaults.ts +39 -0
- package/src/discovery/builtin-rules/index.ts +50 -0
- package/src/discovery/builtin-rules/rs-box-leak.md +48 -0
- package/src/discovery/builtin-rules/rs-future-prelude.md +23 -0
- package/src/discovery/builtin-rules/rs-lazylock.md +51 -0
- package/src/discovery/builtin-rules/rs-match-ergonomics.md +67 -0
- package/src/discovery/builtin-rules/rs-parking-lot.md +44 -0
- package/src/discovery/builtin-rules/rs-result-type.md +19 -0
- package/src/discovery/builtin-rules/ts-bare-catch.md +38 -0
- package/src/discovery/builtin-rules/ts-import-type.md +42 -0
- package/src/discovery/builtin-rules/ts-no-any.md +56 -0
- package/src/discovery/builtin-rules/ts-no-deprecated-leftovers.md +44 -0
- package/src/discovery/builtin-rules/ts-no-dynamic-import.md +39 -0
- package/src/discovery/builtin-rules/ts-no-return-type.md +45 -0
- package/src/discovery/builtin-rules/ts-no-tiny-functions.md +51 -0
- package/src/discovery/builtin-rules/ts-promise-with-resolvers.md +65 -0
- package/src/discovery/builtin-rules/ts-set-map.md +28 -0
- package/src/discovery/builtin.ts +906 -0
- package/src/discovery/claude-plugins.ts +386 -0
- package/src/discovery/claude.ts +584 -0
- package/src/discovery/cline.ts +83 -0
- package/src/discovery/codex.ts +522 -0
- package/src/discovery/context-files.ts +49 -0
- package/src/discovery/cursor.ts +220 -0
- package/src/discovery/gemini.ts +383 -0
- package/src/discovery/github.ts +154 -0
- package/src/discovery/helpers.ts +1015 -0
- package/src/discovery/index.ts +81 -0
- package/src/discovery/mcp-json.ts +171 -0
- package/src/discovery/opencode.ts +398 -0
- package/src/discovery/plugin-dir-roots.ts +28 -0
- package/src/discovery/prometheus-extension-roots.ts +190 -0
- package/src/discovery/prometheus-plugins.ts +385 -0
- package/src/discovery/ssh.ts +153 -0
- package/src/discovery/substitute-plugin-root.ts +29 -0
- package/src/discovery/vscode.ts +105 -0
- package/src/discovery/windsurf.ts +147 -0
- package/src/edit/apply-patch/index.ts +87 -0
- package/src/edit/apply-patch/parser.ts +174 -0
- package/src/edit/diff.ts +812 -0
- package/src/edit/file-snapshot-store.ts +59 -0
- package/src/edit/hashline/block-resolver.ts +14 -0
- package/src/edit/hashline/diff.ts +169 -0
- package/src/edit/hashline/execute.ts +187 -0
- package/src/edit/hashline/filesystem.ts +129 -0
- package/src/edit/hashline/index.ts +5 -0
- package/src/edit/hashline/params.ts +18 -0
- package/src/edit/index.ts +542 -0
- package/src/edit/modes/apply-patch.lark +19 -0
- package/src/edit/modes/apply-patch.ts +53 -0
- package/src/edit/modes/patch.ts +1835 -0
- package/src/edit/modes/replace.ts +1103 -0
- package/src/edit/normalize.ts +345 -0
- package/src/edit/notebook.ts +222 -0
- package/src/edit/read-file.ts +25 -0
- package/src/edit/renderer.ts +660 -0
- package/src/edit/streaming.ts +517 -0
- package/src/eval/__tests__/agent-bridge.test.ts +650 -0
- package/src/eval/__tests__/bridge-timeout.test.ts +64 -0
- package/src/eval/__tests__/budget-bridge.test.ts +69 -0
- package/src/eval/__tests__/idle-timeout.test.ts +80 -0
- package/src/eval/__tests__/kernel-spawn.test.ts +103 -0
- package/src/eval/__tests__/llm-bridge.test.ts +327 -0
- package/src/eval/__tests__/shared-executors.test.ts +609 -0
- package/src/eval/agent-bridge.ts +303 -0
- package/src/eval/backend.ts +58 -0
- package/src/eval/bridge-timeout.ts +44 -0
- package/src/eval/budget-bridge.ts +48 -0
- package/src/eval/concurrency-bridge.ts +34 -0
- package/src/eval/idle-timeout.ts +98 -0
- package/src/eval/index.ts +4 -0
- package/src/eval/js/context-manager.ts +425 -0
- package/src/eval/js/executor.ts +166 -0
- package/src/eval/js/index.ts +47 -0
- package/src/eval/js/shared/helpers.ts +237 -0
- package/src/eval/js/shared/indirect-eval.ts +30 -0
- package/src/eval/js/shared/local-module-loader.ts +342 -0
- package/src/eval/js/shared/prelude.ts +2 -0
- package/src/eval/js/shared/prelude.txt +169 -0
- package/src/eval/js/shared/rewrite-imports.ts +508 -0
- package/src/eval/js/shared/runtime.ts +344 -0
- package/src/eval/js/shared/types.ts +18 -0
- package/src/eval/js/tool-bridge.ts +162 -0
- package/src/eval/js/worker-core.ts +131 -0
- package/src/eval/js/worker-entry.ts +24 -0
- package/src/eval/js/worker-protocol.ts +41 -0
- package/src/eval/llm-bridge.ts +186 -0
- package/src/eval/py/display.ts +71 -0
- package/src/eval/py/executor.ts +698 -0
- package/src/eval/py/index.ts +59 -0
- package/src/eval/py/kernel.ts +709 -0
- package/src/eval/py/prelude.py +620 -0
- package/src/eval/py/prelude.ts +3 -0
- package/src/eval/py/runner.py +1028 -0
- package/src/eval/py/runtime.ts +239 -0
- package/src/eval/py/spawn-options.ts +126 -0
- package/src/eval/py/tool-bridge.ts +182 -0
- package/src/eval/session-id.ts +8 -0
- package/src/eval/types.ts +48 -0
- package/src/exa/factory.ts +60 -0
- package/src/exa/index.ts +27 -0
- package/src/exa/mcp-client.ts +370 -0
- package/src/exa/render.ts +244 -0
- package/src/exa/researcher.ts +36 -0
- package/src/exa/search.ts +47 -0
- package/src/exa/types.ts +166 -0
- package/src/exa/websets.ts +248 -0
- package/src/exec/bash-executor.ts +338 -0
- package/src/exec/exec.ts +53 -0
- package/src/exec/idle-timeout-watchdog.ts +126 -0
- package/src/exec/non-interactive-env.ts +48 -0
- package/src/export/custom-share.ts +65 -0
- package/src/export/html/index.ts +164 -0
- package/src/export/html/template.css +1051 -0
- package/src/export/html/template.generated.ts +2 -0
- package/src/export/html/template.html +46 -0
- package/src/export/html/template.js +2244 -0
- package/src/export/html/template.macro.ts +25 -0
- package/src/export/html/vendor/highlight.min.js +1213 -0
- package/src/export/html/vendor/marked.min.js +6 -0
- package/src/export/ttsr.ts +462 -0
- package/src/extensibility/custom-commands/bundled/ci-green/index.ts +54 -0
- package/src/extensibility/custom-commands/bundled/review/index.ts +489 -0
- package/src/extensibility/custom-commands/index.ts +2 -0
- package/src/extensibility/custom-commands/loader.ts +238 -0
- package/src/extensibility/custom-commands/types.ts +113 -0
- package/src/extensibility/custom-tools/index.ts +7 -0
- package/src/extensibility/custom-tools/loader.ts +240 -0
- package/src/extensibility/custom-tools/types.ts +268 -0
- package/src/extensibility/custom-tools/wrapper.ts +47 -0
- package/src/extensibility/extensions/compact-handler.ts +40 -0
- package/src/extensibility/extensions/get-commands-handler.ts +77 -0
- package/src/extensibility/extensions/index.ts +15 -0
- package/src/extensibility/extensions/loader.ts +552 -0
- package/src/extensibility/extensions/runner.ts +917 -0
- package/src/extensibility/extensions/types.ts +1303 -0
- package/src/extensibility/extensions/wrapper.ts +223 -0
- package/src/extensibility/hooks/index.ts +5 -0
- package/src/extensibility/hooks/loader.ts +257 -0
- package/src/extensibility/hooks/runner.ts +425 -0
- package/src/extensibility/hooks/tool-wrapper.ts +107 -0
- package/src/extensibility/hooks/types.ts +606 -0
- package/src/extensibility/legacy-pi-ai-shim.ts +24 -0
- package/src/extensibility/legacy-pi-coding-agent-shim.ts +15 -0
- package/src/extensibility/plugins/doctor.ts +66 -0
- package/src/extensibility/plugins/git-url.ts +367 -0
- package/src/extensibility/plugins/index.ts +9 -0
- package/src/extensibility/plugins/installer.ts +192 -0
- package/src/extensibility/plugins/legacy-pi-compat.ts +661 -0
- package/src/extensibility/plugins/loader.ts +313 -0
- package/src/extensibility/plugins/manager.ts +827 -0
- package/src/extensibility/plugins/marketplace/cache.ts +136 -0
- package/src/extensibility/plugins/marketplace/fetcher.ts +317 -0
- package/src/extensibility/plugins/marketplace/index.ts +6 -0
- package/src/extensibility/plugins/marketplace/manager.ts +770 -0
- package/src/extensibility/plugins/marketplace/registry.ts +196 -0
- package/src/extensibility/plugins/marketplace/source-resolver.ts +147 -0
- package/src/extensibility/plugins/marketplace/types.ts +191 -0
- package/src/extensibility/plugins/parser.ts +105 -0
- package/src/extensibility/plugins/types.ts +194 -0
- package/src/extensibility/shared-events.ts +343 -0
- package/src/extensibility/skills.ts +312 -0
- package/src/extensibility/slash-commands.ts +227 -0
- package/src/extensibility/tool-proxy.ts +25 -0
- package/src/extensibility/typebox.ts +418 -0
- package/src/extensibility/utils.ts +44 -0
- package/src/gateway/adapters/telegram/access.ts +53 -0
- package/src/gateway/adapters/telegram/commands.ts +206 -0
- package/src/gateway/adapters/telegram/expressions.ts +678 -0
- package/src/gateway/adapters/telegram/media.ts +831 -0
- package/src/gateway/adapters/telegram/native-command-policy.ts +83 -0
- package/src/gateway/adapters/telegram/native-commands.ts +197 -0
- package/src/gateway/adapters/telegram/normalize.ts +593 -0
- package/src/gateway/adapters/telegram/send-message.ts +1465 -0
- package/src/gateway/adapters/telegram/service.ts +577 -0
- package/src/gateway/adapters/telegram/setup-api.ts +196 -0
- package/src/gateway/adapters/telegram/setup-config.ts +72 -0
- package/src/gateway/adapters/telegram/types.ts +206 -0
- package/src/gateway/adapters/telegram/webhook.ts +364 -0
- package/src/gateway/commands.ts +196 -0
- package/src/gateway/context.ts +276 -0
- package/src/gateway/native-slash-policy.ts +19 -0
- package/src/gateway/prometheus-dispatch.ts +362 -0
- package/src/gateway/router.ts +123 -0
- package/src/gateway/session-key.ts +55 -0
- package/src/gateway/types.ts +119 -0
- package/src/goals/index.ts +3 -0
- package/src/goals/runtime.ts +528 -0
- package/src/goals/state.ts +37 -0
- package/src/goals/tools/goal-tool.ts +241 -0
- package/src/hindsight/backend.ts +354 -0
- package/src/hindsight/bank.ts +141 -0
- package/src/hindsight/client.ts +598 -0
- package/src/hindsight/config.ts +175 -0
- package/src/hindsight/content.ts +210 -0
- package/src/hindsight/index.ts +8 -0
- package/src/hindsight/mental-models.ts +382 -0
- package/src/hindsight/seeds.json +32 -0
- package/src/hindsight/state.ts +483 -0
- package/src/hindsight/transcript.ts +71 -0
- package/src/index.ts +59 -0
- package/src/internal-urls/agent-protocol.ts +146 -0
- package/src/internal-urls/artifact-protocol.ts +98 -0
- package/src/internal-urls/docs-index.generated.ts +107 -0
- package/src/internal-urls/index.ts +24 -0
- package/src/internal-urls/issue-pr-protocol.ts +577 -0
- package/src/internal-urls/json-query.ts +126 -0
- package/src/internal-urls/local-protocol.ts +274 -0
- package/src/internal-urls/mcp-protocol.ts +151 -0
- package/src/internal-urls/memory-protocol.ts +196 -0
- package/src/internal-urls/parse.ts +72 -0
- package/src/internal-urls/prometheus-protocol.ts +93 -0
- package/src/internal-urls/registry-helpers.ts +25 -0
- package/src/internal-urls/router.ts +103 -0
- package/src/internal-urls/rule-protocol.ts +45 -0
- package/src/internal-urls/skill-protocol.ts +96 -0
- package/src/internal-urls/types.ts +152 -0
- package/src/internal-urls/vault-protocol.ts +936 -0
- package/src/lib/xai-http.ts +124 -0
- package/src/lsp/client.ts +1052 -0
- package/src/lsp/clients/biome-client.ts +202 -0
- package/src/lsp/clients/index.ts +50 -0
- package/src/lsp/clients/lsp-linter-client.ts +93 -0
- package/src/lsp/clients/swiftlint-client.ts +120 -0
- package/src/lsp/config.ts +492 -0
- package/src/lsp/defaults.json +493 -0
- package/src/lsp/diagnostics-ledger.ts +51 -0
- package/src/lsp/edits.ts +219 -0
- package/src/lsp/index.ts +2340 -0
- package/src/lsp/lspmux.ts +233 -0
- package/src/lsp/render.ts +692 -0
- package/src/lsp/startup-events.ts +13 -0
- package/src/lsp/types.ts +443 -0
- package/src/lsp/utils.ts +699 -0
- package/src/main.ts +1167 -0
- package/src/mcp/client.ts +484 -0
- package/src/mcp/config-writer.ts +225 -0
- package/src/mcp/config.ts +365 -0
- package/src/mcp/index.ts +29 -0
- package/src/mcp/json-rpc.ts +92 -0
- package/src/mcp/loader.ts +124 -0
- package/src/mcp/manager.ts +1274 -0
- package/src/mcp/oauth-discovery.ts +437 -0
- package/src/mcp/oauth-flow.ts +435 -0
- package/src/mcp/render.ts +126 -0
- package/src/mcp/smithery-auth.ts +104 -0
- package/src/mcp/smithery-connect.ts +145 -0
- package/src/mcp/smithery-registry.ts +477 -0
- package/src/mcp/timeout.ts +59 -0
- package/src/mcp/tool-bridge.ts +424 -0
- package/src/mcp/tool-cache.ts +117 -0
- package/src/mcp/transports/http.ts +519 -0
- package/src/mcp/transports/index.ts +6 -0
- package/src/mcp/transports/stdio.ts +386 -0
- package/src/mcp/types.ts +423 -0
- package/src/memories/index.ts +2227 -0
- package/src/memories/storage.ts +617 -0
- package/src/memory-backend/index.ts +5 -0
- package/src/memory-backend/local-backend.ts +30 -0
- package/src/memory-backend/off-backend.ts +16 -0
- package/src/memory-backend/resolve.ts +27 -0
- package/src/memory-backend/types.ts +86 -0
- package/src/mnemopi/backend.ts +374 -0
- package/src/mnemopi/config.ts +160 -0
- package/src/mnemopi/index.ts +3 -0
- package/src/mnemopi/state.ts +549 -0
- package/src/modes/acp/acp-agent.ts +2292 -0
- package/src/modes/acp/acp-client-bridge.ts +154 -0
- package/src/modes/acp/acp-event-mapper.ts +929 -0
- package/src/modes/acp/acp-mode.ts +23 -0
- package/src/modes/acp/index.ts +2 -0
- package/src/modes/acp/terminal-auth.ts +37 -0
- package/src/modes/components/agent-dashboard.ts +1201 -0
- package/src/modes/components/assistant-message.ts +309 -0
- package/src/modes/components/bash-execution.ts +220 -0
- package/src/modes/components/bordered-loader.ts +41 -0
- package/src/modes/components/branch-summary-message.ts +45 -0
- package/src/modes/components/btw-panel.ts +104 -0
- package/src/modes/components/compaction-summary-message.ts +51 -0
- package/src/modes/components/copy-selector.ts +249 -0
- package/src/modes/components/countdown-timer.ts +75 -0
- package/src/modes/components/custom-editor.ts +267 -0
- package/src/modes/components/custom-message.ts +65 -0
- package/src/modes/components/diff.ts +266 -0
- package/src/modes/components/dynamic-border.ts +25 -0
- package/src/modes/components/error-banner.ts +33 -0
- package/src/modes/components/eval-execution.ts +158 -0
- package/src/modes/components/execution-shared.ts +102 -0
- package/src/modes/components/extensions/extension-dashboard.ts +396 -0
- package/src/modes/components/extensions/extension-list.ts +502 -0
- package/src/modes/components/extensions/index.ts +9 -0
- package/src/modes/components/extensions/inspector-panel.ts +317 -0
- package/src/modes/components/extensions/state-manager.ts +632 -0
- package/src/modes/components/extensions/types.ts +186 -0
- package/src/modes/components/footer.ts +272 -0
- package/src/modes/components/history-search.ts +280 -0
- package/src/modes/components/hook-editor.ts +159 -0
- package/src/modes/components/hook-input.ts +79 -0
- package/src/modes/components/hook-message.ts +68 -0
- package/src/modes/components/hook-selector.ts +660 -0
- package/src/modes/components/index.ts +38 -0
- package/src/modes/components/keybinding-hints.ts +65 -0
- package/src/modes/components/login-dialog.ts +164 -0
- package/src/modes/components/mcp-add-wizard.ts +1340 -0
- package/src/modes/components/message-frame.ts +88 -0
- package/src/modes/components/model-selector.ts +1213 -0
- package/src/modes/components/oauth-selector.ts +342 -0
- package/src/modes/components/omfg-panel.ts +141 -0
- package/src/modes/components/plugin-selector.ts +95 -0
- package/src/modes/components/plugin-settings.ts +728 -0
- package/src/modes/components/queue-mode-selector.ts +56 -0
- package/src/modes/components/read-tool-group.ts +267 -0
- package/src/modes/components/segment-track.ts +52 -0
- package/src/modes/components/session-observer-overlay.ts +852 -0
- package/src/modes/components/session-selector.ts +571 -0
- package/src/modes/components/settings-defs.ts +189 -0
- package/src/modes/components/settings-selector.ts +647 -0
- package/src/modes/components/show-images-selector.ts +45 -0
- package/src/modes/components/skill-message.ts +90 -0
- package/src/modes/components/status-line/context-thresholds.ts +79 -0
- package/src/modes/components/status-line/git-utils.ts +42 -0
- package/src/modes/components/status-line/index.ts +4 -0
- package/src/modes/components/status-line/presets.ts +106 -0
- package/src/modes/components/status-line/segments.ts +590 -0
- package/src/modes/components/status-line/separators.ts +55 -0
- package/src/modes/components/status-line/token-rate.ts +66 -0
- package/src/modes/components/status-line/types.ts +93 -0
- package/src/modes/components/status-line.ts +794 -0
- package/src/modes/components/theme-selector.ts +63 -0
- package/src/modes/components/thinking-selector.ts +52 -0
- package/src/modes/components/tiny-title-download-progress.ts +90 -0
- package/src/modes/components/tips.txt +18 -0
- package/src/modes/components/todo-reminder.ts +40 -0
- package/src/modes/components/tool-execution.ts +1017 -0
- package/src/modes/components/transcript-container.ts +181 -0
- package/src/modes/components/tree-selector.ts +978 -0
- package/src/modes/components/ttsr-notification.ts +80 -0
- package/src/modes/components/user-message-selector.ts +227 -0
- package/src/modes/components/user-message.ts +52 -0
- package/src/modes/components/visual-truncate.ts +63 -0
- package/src/modes/components/welcome.ts +435 -0
- package/src/modes/controllers/btw-controller.ts +105 -0
- package/src/modes/controllers/command-controller-shared.ts +108 -0
- package/src/modes/controllers/command-controller.ts +1546 -0
- package/src/modes/controllers/event-controller.ts +926 -0
- package/src/modes/controllers/extension-ui-controller.ts +933 -0
- package/src/modes/controllers/input-controller.ts +947 -0
- package/src/modes/controllers/mcp-command-controller.ts +1938 -0
- package/src/modes/controllers/omfg-controller.ts +283 -0
- package/src/modes/controllers/omfg-rule.ts +647 -0
- package/src/modes/controllers/selector-controller.ts +1117 -0
- package/src/modes/controllers/ssh-command-controller.ts +384 -0
- package/src/modes/controllers/todo-command-controller.ts +485 -0
- package/src/modes/data/emojis.json +1 -0
- package/src/modes/emoji-autocomplete.ts +285 -0
- package/src/modes/gradient-highlight.ts +87 -0
- package/src/modes/image-references.ts +111 -0
- package/src/modes/index.ts +34 -0
- package/src/modes/interactive-mode.ts +3151 -0
- package/src/modes/internal-url-autocomplete.ts +143 -0
- package/src/modes/loop-limit.ts +140 -0
- package/src/modes/magic-keywords.ts +20 -0
- package/src/modes/markdown-prose.ts +247 -0
- package/src/modes/oauth-manual-input.ts +42 -0
- package/src/modes/orchestrate.ts +42 -0
- package/src/modes/print-mode.ts +126 -0
- package/src/modes/prompt-action-autocomplete.ts +260 -0
- package/src/modes/rpc/host-tools.ts +186 -0
- package/src/modes/rpc/host-uris.ts +235 -0
- package/src/modes/rpc/rpc-client.ts +812 -0
- package/src/modes/rpc/rpc-mode.ts +862 -0
- package/src/modes/rpc/rpc-types.ts +378 -0
- package/src/modes/runtime-init.ts +116 -0
- package/src/modes/session-observer-registry.ts +146 -0
- package/src/modes/setup-wizard/index.ts +88 -0
- package/src/modes/setup-wizard/scenes/channels.ts +104 -0
- package/src/modes/setup-wizard/scenes/glyph.ts +96 -0
- package/src/modes/setup-wizard/scenes/outro.ts +35 -0
- package/src/modes/setup-wizard/scenes/providers.ts +70 -0
- package/src/modes/setup-wizard/scenes/sign-in.ts +213 -0
- package/src/modes/setup-wizard/scenes/splash.ts +201 -0
- package/src/modes/setup-wizard/scenes/telegram.ts +695 -0
- package/src/modes/setup-wizard/scenes/theme.ts +299 -0
- package/src/modes/setup-wizard/scenes/types.ts +48 -0
- package/src/modes/setup-wizard/scenes/web-search.ts +128 -0
- package/src/modes/setup-wizard/wizard-overlay.ts +275 -0
- package/src/modes/shared.ts +47 -0
- package/src/modes/theme/dark.json +95 -0
- package/src/modes/theme/defaults/alabaster.json +93 -0
- package/src/modes/theme/defaults/amethyst.json +96 -0
- package/src/modes/theme/defaults/anthracite.json +93 -0
- package/src/modes/theme/defaults/basalt.json +91 -0
- package/src/modes/theme/defaults/birch.json +95 -0
- package/src/modes/theme/defaults/dark-abyss.json +91 -0
- package/src/modes/theme/defaults/dark-arctic.json +104 -0
- package/src/modes/theme/defaults/dark-aurora.json +95 -0
- package/src/modes/theme/defaults/dark-catppuccin.json +107 -0
- package/src/modes/theme/defaults/dark-cavern.json +91 -0
- package/src/modes/theme/defaults/dark-copper.json +95 -0
- package/src/modes/theme/defaults/dark-cosmos.json +90 -0
- package/src/modes/theme/defaults/dark-cyberpunk.json +102 -0
- package/src/modes/theme/defaults/dark-dracula.json +98 -0
- package/src/modes/theme/defaults/dark-eclipse.json +91 -0
- package/src/modes/theme/defaults/dark-ember.json +95 -0
- package/src/modes/theme/defaults/dark-equinox.json +90 -0
- package/src/modes/theme/defaults/dark-forest.json +96 -0
- package/src/modes/theme/defaults/dark-github.json +105 -0
- package/src/modes/theme/defaults/dark-gruvbox.json +112 -0
- package/src/modes/theme/defaults/dark-lavender.json +95 -0
- package/src/modes/theme/defaults/dark-lunar.json +89 -0
- package/src/modes/theme/defaults/dark-midnight.json +95 -0
- package/src/modes/theme/defaults/dark-monochrome.json +94 -0
- package/src/modes/theme/defaults/dark-monokai.json +98 -0
- package/src/modes/theme/defaults/dark-nebula.json +90 -0
- package/src/modes/theme/defaults/dark-nord.json +97 -0
- package/src/modes/theme/defaults/dark-ocean.json +101 -0
- package/src/modes/theme/defaults/dark-one.json +100 -0
- package/src/modes/theme/defaults/dark-poimandres.json +142 -0
- package/src/modes/theme/defaults/dark-rainforest.json +91 -0
- package/src/modes/theme/defaults/dark-reef.json +91 -0
- package/src/modes/theme/defaults/dark-retro.json +92 -0
- package/src/modes/theme/defaults/dark-rose-pine.json +96 -0
- package/src/modes/theme/defaults/dark-sakura.json +95 -0
- package/src/modes/theme/defaults/dark-slate.json +95 -0
- package/src/modes/theme/defaults/dark-solarized.json +97 -0
- package/src/modes/theme/defaults/dark-solstice.json +90 -0
- package/src/modes/theme/defaults/dark-starfall.json +91 -0
- package/src/modes/theme/defaults/dark-sunset.json +99 -0
- package/src/modes/theme/defaults/dark-swamp.json +90 -0
- package/src/modes/theme/defaults/dark-synthwave.json +103 -0
- package/src/modes/theme/defaults/dark-taiga.json +91 -0
- package/src/modes/theme/defaults/dark-terminal.json +95 -0
- package/src/modes/theme/defaults/dark-tokyo-night.json +101 -0
- package/src/modes/theme/defaults/dark-tundra.json +91 -0
- package/src/modes/theme/defaults/dark-twilight.json +91 -0
- package/src/modes/theme/defaults/dark-volcanic.json +91 -0
- package/src/modes/theme/defaults/graphite.json +92 -0
- package/src/modes/theme/defaults/index.ts +199 -0
- package/src/modes/theme/defaults/light-arctic.json +107 -0
- package/src/modes/theme/defaults/light-aurora-day.json +91 -0
- package/src/modes/theme/defaults/light-canyon.json +91 -0
- package/src/modes/theme/defaults/light-catppuccin.json +106 -0
- package/src/modes/theme/defaults/light-cirrus.json +90 -0
- package/src/modes/theme/defaults/light-coral.json +95 -0
- package/src/modes/theme/defaults/light-cyberpunk.json +96 -0
- package/src/modes/theme/defaults/light-dawn.json +90 -0
- package/src/modes/theme/defaults/light-dunes.json +91 -0
- package/src/modes/theme/defaults/light-eucalyptus.json +95 -0
- package/src/modes/theme/defaults/light-forest.json +100 -0
- package/src/modes/theme/defaults/light-frost.json +95 -0
- package/src/modes/theme/defaults/light-github.json +115 -0
- package/src/modes/theme/defaults/light-glacier.json +91 -0
- package/src/modes/theme/defaults/light-gruvbox.json +108 -0
- package/src/modes/theme/defaults/light-haze.json +90 -0
- package/src/modes/theme/defaults/light-honeycomb.json +95 -0
- package/src/modes/theme/defaults/light-lagoon.json +91 -0
- package/src/modes/theme/defaults/light-lavender.json +95 -0
- package/src/modes/theme/defaults/light-meadow.json +91 -0
- package/src/modes/theme/defaults/light-mint.json +95 -0
- package/src/modes/theme/defaults/light-monochrome.json +101 -0
- package/src/modes/theme/defaults/light-ocean.json +99 -0
- package/src/modes/theme/defaults/light-one.json +99 -0
- package/src/modes/theme/defaults/light-opal.json +91 -0
- package/src/modes/theme/defaults/light-orchard.json +91 -0
- package/src/modes/theme/defaults/light-paper.json +95 -0
- package/src/modes/theme/defaults/light-poimandres.json +142 -0
- package/src/modes/theme/defaults/light-prism.json +90 -0
- package/src/modes/theme/defaults/light-retro.json +98 -0
- package/src/modes/theme/defaults/light-sand.json +95 -0
- package/src/modes/theme/defaults/light-savanna.json +91 -0
- package/src/modes/theme/defaults/light-solarized.json +102 -0
- package/src/modes/theme/defaults/light-soleil.json +90 -0
- package/src/modes/theme/defaults/light-sunset.json +99 -0
- package/src/modes/theme/defaults/light-synthwave.json +98 -0
- package/src/modes/theme/defaults/light-tokyo-night.json +111 -0
- package/src/modes/theme/defaults/light-wetland.json +91 -0
- package/src/modes/theme/defaults/light-zenith.json +89 -0
- package/src/modes/theme/defaults/limestone.json +94 -0
- package/src/modes/theme/defaults/mahogany.json +97 -0
- package/src/modes/theme/defaults/marble.json +93 -0
- package/src/modes/theme/defaults/obsidian.json +91 -0
- package/src/modes/theme/defaults/onyx.json +91 -0
- package/src/modes/theme/defaults/pearl.json +93 -0
- package/src/modes/theme/defaults/porcelain.json +91 -0
- package/src/modes/theme/defaults/quartz.json +96 -0
- package/src/modes/theme/defaults/sandstone.json +95 -0
- package/src/modes/theme/defaults/titanium.json +90 -0
- package/src/modes/theme/light.json +93 -0
- package/src/modes/theme/mermaid-cache.ts +29 -0
- package/src/modes/theme/shimmer.ts +224 -0
- package/src/modes/theme/theme-schema.json +459 -0
- package/src/modes/theme/theme.ts +2569 -0
- package/src/modes/turn-budget.ts +31 -0
- package/src/modes/types.ts +338 -0
- package/src/modes/ultrathink.ts +41 -0
- package/src/modes/utils/context-usage.ts +335 -0
- package/src/modes/utils/copy-targets.ts +254 -0
- package/src/modes/utils/hotkeys-markdown.ts +60 -0
- package/src/modes/utils/keybinding-matchers.ts +51 -0
- package/src/modes/utils/tools-markdown.ts +27 -0
- package/src/modes/utils/ui-helpers.ts +772 -0
- package/src/modes/workflow.ts +42 -0
- package/src/plan-mode/approved-plan.ts +163 -0
- package/src/plan-mode/plan-handoff.ts +37 -0
- package/src/plan-mode/plan-protection.ts +31 -0
- package/src/plan-mode/state.ts +6 -0
- package/src/priority.json +41 -0
- package/src/prompts/agents/designer.md +66 -0
- package/src/prompts/agents/explore.md +58 -0
- package/src/prompts/agents/frontmatter.md +11 -0
- package/src/prompts/agents/init.md +33 -0
- package/src/prompts/agents/librarian.md +120 -0
- package/src/prompts/agents/oracle.md +55 -0
- package/src/prompts/agents/plan.md +48 -0
- package/src/prompts/agents/reviewer.md +140 -0
- package/src/prompts/agents/task.md +16 -0
- package/src/prompts/ci-green-request.md +38 -0
- package/src/prompts/dry-balance-bench.md +8 -0
- package/src/prompts/goals/goal-budget-limit.md +16 -0
- package/src/prompts/goals/goal-continuation.md +28 -0
- package/src/prompts/goals/goal-mode-active.md +23 -0
- package/src/prompts/memories/consolidation.md +35 -0
- package/src/prompts/memories/identity_review.md +38 -0
- package/src/prompts/memories/post_turn_review.md +37 -0
- package/src/prompts/memories/read-path.md +16 -0
- package/src/prompts/memories/stage_one_input.md +6 -0
- package/src/prompts/memories/stage_one_system.md +21 -0
- package/src/prompts/review-custom-request.md +22 -0
- package/src/prompts/review-headless-request.md +16 -0
- package/src/prompts/review-request.md +69 -0
- package/src/prompts/steering/user-interjection.md +10 -0
- package/src/prompts/system/agent-creation-architect.md +50 -0
- package/src/prompts/system/agent-creation-user.md +6 -0
- package/src/prompts/system/auto-continue.md +1 -0
- package/src/prompts/system/auto-thinking-difficulty-local.md +14 -0
- package/src/prompts/system/auto-thinking-difficulty.md +12 -0
- package/src/prompts/system/btw-user.md +8 -0
- package/src/prompts/system/commit-message-system.md +2 -0
- package/src/prompts/system/custom-system-prompt.md +64 -0
- package/src/prompts/system/eager-todo.md +13 -0
- package/src/prompts/system/empty-stop-retry.md +6 -0
- package/src/prompts/system/irc-incoming.md +8 -0
- package/src/prompts/system/memory-consolidation-system.md +8 -0
- package/src/prompts/system/memory-extraction-system.md +26 -0
- package/src/prompts/system/omfg-user.md +51 -0
- package/src/prompts/system/orchestrate-notice.md +40 -0
- package/src/prompts/system/plan-mode-active.md +116 -0
- package/src/prompts/system/plan-mode-approved.md +25 -0
- package/src/prompts/system/plan-mode-compact-instructions.md +16 -0
- package/src/prompts/system/plan-mode-reference.md +11 -0
- package/src/prompts/system/plan-mode-subagent.md +34 -0
- package/src/prompts/system/plan-mode-tool-decision-reminder.md +9 -0
- package/src/prompts/system/project-prompt.md +52 -0
- package/src/prompts/system/subagent-system-prompt.md +69 -0
- package/src/prompts/system/subagent-user-prompt.md +3 -0
- package/src/prompts/system/subagent-yield-reminder.md +12 -0
- package/src/prompts/system/system-prompt.md +275 -0
- package/src/prompts/system/tiny-title-system.md +8 -0
- package/src/prompts/system/title-system.md +3 -0
- package/src/prompts/system/ttsr-interrupt.md +7 -0
- package/src/prompts/system/ttsr-tool-reminder.md +5 -0
- package/src/prompts/system/ultrathink-notice.md +3 -0
- package/src/prompts/system/web-search.md +25 -0
- package/src/prompts/system/workflow-notice.md +70 -0
- package/src/prompts/tools/apply-patch.md +65 -0
- package/src/prompts/tools/ask.md +30 -0
- package/src/prompts/tools/ast-edit.md +39 -0
- package/src/prompts/tools/ast-grep.md +42 -0
- package/src/prompts/tools/async-result.md +8 -0
- package/src/prompts/tools/bash.md +39 -0
- package/src/prompts/tools/browser.md +73 -0
- package/src/prompts/tools/checkpoint.md +16 -0
- package/src/prompts/tools/debug.md +34 -0
- package/src/prompts/tools/eval.md +89 -0
- package/src/prompts/tools/find.md +37 -0
- package/src/prompts/tools/github.md +20 -0
- package/src/prompts/tools/goal.md +18 -0
- package/src/prompts/tools/image-gen.md +7 -0
- package/src/prompts/tools/inspect-image-system.md +20 -0
- package/src/prompts/tools/inspect-image.md +32 -0
- package/src/prompts/tools/irc.md +49 -0
- package/src/prompts/tools/job.md +19 -0
- package/src/prompts/tools/lsp.md +42 -0
- package/src/prompts/tools/memory-edit.md +8 -0
- package/src/prompts/tools/patch.md +70 -0
- package/src/prompts/tools/read.md +86 -0
- package/src/prompts/tools/recall.md +5 -0
- package/src/prompts/tools/reflect.md +5 -0
- package/src/prompts/tools/render-mermaid.md +9 -0
- package/src/prompts/tools/replace.md +36 -0
- package/src/prompts/tools/resolve.md +9 -0
- package/src/prompts/tools/retain.md +6 -0
- package/src/prompts/tools/rewind.md +13 -0
- package/src/prompts/tools/search-tool-bm25.md +40 -0
- package/src/prompts/tools/search.md +25 -0
- package/src/prompts/tools/ssh.md +35 -0
- package/src/prompts/tools/task-summary.md +28 -0
- package/src/prompts/tools/task.md +80 -0
- package/src/prompts/tools/todo.md +58 -0
- package/src/prompts/tools/web-search.md +10 -0
- package/src/prompts/tools/write.md +14 -0
- package/src/registry/agent-registry.ts +140 -0
- package/src/sdk.ts +2374 -0
- package/src/secrets/index.ts +116 -0
- package/src/secrets/obfuscator.ts +277 -0
- package/src/secrets/regex.ts +21 -0
- package/src/session/agent-session.ts +9765 -0
- package/src/session/agent-storage.ts +455 -0
- package/src/session/artifacts.ts +135 -0
- package/src/session/auth-broker-config.ts +102 -0
- package/src/session/auth-storage.ts +27 -0
- package/src/session/blob-store.ts +255 -0
- package/src/session/client-bridge.ts +85 -0
- package/src/session/history-storage.ts +348 -0
- package/src/session/indexed-session-storage.ts +430 -0
- package/src/session/messages.ts +575 -0
- package/src/session/redis-session-storage.ts +170 -0
- package/src/session/session-dump-format.ts +209 -0
- package/src/session/session-manager.ts +3541 -0
- package/src/session/session-storage.ts +529 -0
- package/src/session/shake-types.ts +43 -0
- package/src/session/sql-session-storage.ts +314 -0
- package/src/session/streaming-output.ts +1093 -0
- package/src/session/tool-choice-queue.ts +213 -0
- package/src/session/yield-queue.ts +155 -0
- package/src/slash-commands/acp-builtins.ts +46 -0
- package/src/slash-commands/builtin-registry.ts +1726 -0
- package/src/slash-commands/headless-plan.ts +142 -0
- package/src/slash-commands/helpers/context-report.ts +39 -0
- package/src/slash-commands/helpers/format.ts +46 -0
- package/src/slash-commands/helpers/marketplace-manager.ts +25 -0
- package/src/slash-commands/helpers/mcp.ts +532 -0
- package/src/slash-commands/helpers/parse.ts +85 -0
- package/src/slash-commands/helpers/ssh.ts +195 -0
- package/src/slash-commands/helpers/todo.ts +279 -0
- package/src/slash-commands/helpers/usage-report.ts +93 -0
- package/src/slash-commands/marketplace-install-parser.ts +99 -0
- package/src/slash-commands/types.ts +139 -0
- package/src/ssh/config-writer.ts +183 -0
- package/src/ssh/connection-manager.ts +482 -0
- package/src/ssh/ssh-executor.ts +133 -0
- package/src/ssh/sshfs-mount.ts +140 -0
- package/src/ssh/utils.ts +8 -0
- package/src/stt/downloader.ts +71 -0
- package/src/stt/index.ts +3 -0
- package/src/stt/recorder.ts +351 -0
- package/src/stt/setup.ts +52 -0
- package/src/stt/stt-controller.ts +160 -0
- package/src/stt/transcribe.py +70 -0
- package/src/stt/transcriber.ts +91 -0
- package/src/system-prompt.ts +591 -0
- package/src/task/agents.ts +167 -0
- package/src/task/commands.ts +131 -0
- package/src/task/discovery.ts +129 -0
- package/src/task/executor.ts +1659 -0
- package/src/task/index.ts +1401 -0
- package/src/task/name-generator.ts +1577 -0
- package/src/task/output-manager.ts +99 -0
- package/src/task/parallel.ts +116 -0
- package/src/task/prometheus-command.ts +26 -0
- package/src/task/render.ts +1211 -0
- package/src/task/repair-args.ts +117 -0
- package/src/task/simple-mode.ts +27 -0
- package/src/task/subprocess-tool-registry.ts +88 -0
- package/src/task/types.ts +320 -0
- package/src/task/worktree.ts +506 -0
- package/src/telemetry-export.ts +127 -0
- package/src/thinking.ts +165 -0
- package/src/tiny/compiled-runtime.ts +179 -0
- package/src/tiny/device.ts +111 -0
- package/src/tiny/dtype.ts +101 -0
- package/src/tiny/models.ts +242 -0
- package/src/tiny/text.ts +165 -0
- package/src/tiny/title-client.ts +491 -0
- package/src/tiny/title-protocol.ts +56 -0
- package/src/tiny/worker.ts +566 -0
- package/src/tool-discovery/mode.ts +24 -0
- package/src/tool-discovery/tool-index.ts +256 -0
- package/src/tools/approval.ts +189 -0
- package/src/tools/archive-reader.ts +629 -0
- package/src/tools/ask.ts +879 -0
- package/src/tools/ast-edit.ts +595 -0
- package/src/tools/ast-grep.ts +458 -0
- package/src/tools/auto-generated-guard.ts +305 -0
- package/src/tools/bash-command-fixup.ts +37 -0
- package/src/tools/bash-interactive.ts +388 -0
- package/src/tools/bash-interceptor.ts +67 -0
- package/src/tools/bash-pty-selection.ts +14 -0
- package/src/tools/bash-skill-urls.ts +248 -0
- package/src/tools/bash.ts +1238 -0
- package/src/tools/browser/attach.ts +175 -0
- package/src/tools/browser/launch.ts +651 -0
- package/src/tools/browser/readable.ts +95 -0
- package/src/tools/browser/registry.ts +194 -0
- package/src/tools/browser/render.ts +213 -0
- package/src/tools/browser/tab-protocol.ts +105 -0
- package/src/tools/browser/tab-supervisor.ts +577 -0
- package/src/tools/browser/tab-worker-entry.ts +21 -0
- package/src/tools/browser/tab-worker.ts +1058 -0
- package/src/tools/browser.ts +316 -0
- package/src/tools/checkpoint.ts +136 -0
- package/src/tools/conflict-detect.ts +672 -0
- package/src/tools/context.ts +39 -0
- package/src/tools/debug.ts +1052 -0
- package/src/tools/eval-backends.ts +27 -0
- package/src/tools/eval-render.ts +765 -0
- package/src/tools/eval.ts +568 -0
- package/src/tools/fetch.ts +1586 -0
- package/src/tools/file-recorder.ts +35 -0
- package/src/tools/find.ts +571 -0
- package/src/tools/fs-cache-invalidation.ts +28 -0
- package/src/tools/gh-format.ts +12 -0
- package/src/tools/gh-renderer.ts +428 -0
- package/src/tools/gh.ts +3582 -0
- package/src/tools/github-cache.ts +548 -0
- package/src/tools/grouped-file-output.ts +103 -0
- package/src/tools/image-gen.ts +1448 -0
- package/src/tools/index.ts +516 -0
- package/src/tools/inspect-image-renderer.ts +103 -0
- package/src/tools/inspect-image.ts +166 -0
- package/src/tools/irc.ts +294 -0
- package/src/tools/job.ts +521 -0
- package/src/tools/json-tree.ts +243 -0
- package/src/tools/jtd-to-json-schema.ts +219 -0
- package/src/tools/jtd-to-typescript.ts +136 -0
- package/src/tools/jtd-utils.ts +102 -0
- package/src/tools/list-limit.ts +40 -0
- package/src/tools/match-line-format.ts +20 -0
- package/src/tools/memory-edit.ts +59 -0
- package/src/tools/memory-recall.ts +104 -0
- package/src/tools/memory-reflect.ts +92 -0
- package/src/tools/memory-render.ts +185 -0
- package/src/tools/memory-retain.ts +91 -0
- package/src/tools/output-meta.ts +754 -0
- package/src/tools/output-schema-validator.ts +132 -0
- package/src/tools/path-utils.ts +1031 -0
- package/src/tools/plan-mode-guard.ts +81 -0
- package/src/tools/puppeteer/00_stealth_tampering.txt +63 -0
- package/src/tools/puppeteer/01_stealth_activity.txt +20 -0
- package/src/tools/puppeteer/02_stealth_hairline.txt +11 -0
- package/src/tools/puppeteer/03_stealth_botd.txt +384 -0
- package/src/tools/puppeteer/04_stealth_iframe.txt +81 -0
- package/src/tools/puppeteer/05_stealth_webgl.txt +75 -0
- package/src/tools/puppeteer/06_stealth_screen.txt +72 -0
- package/src/tools/puppeteer/07_stealth_fonts.txt +97 -0
- package/src/tools/puppeteer/08_stealth_audio.txt +51 -0
- package/src/tools/puppeteer/09_stealth_locale.txt +46 -0
- package/src/tools/puppeteer/10_stealth_plugins.txt +206 -0
- package/src/tools/puppeteer/11_stealth_hardware.txt +8 -0
- package/src/tools/puppeteer/12_stealth_codecs.txt +40 -0
- package/src/tools/puppeteer/13_stealth_worker.txt +74 -0
- package/src/tools/read.ts +2557 -0
- package/src/tools/render-mermaid.ts +69 -0
- package/src/tools/render-utils.ts +836 -0
- package/src/tools/renderers.ts +75 -0
- package/src/tools/report-tool-issue.ts +528 -0
- package/src/tools/resolve.ts +259 -0
- package/src/tools/review.ts +253 -0
- package/src/tools/search-tool-bm25.ts +338 -0
- package/src/tools/search.ts +1475 -0
- package/src/tools/sqlite-reader.ts +819 -0
- package/src/tools/ssh.ts +347 -0
- package/src/tools/todo.ts +856 -0
- package/src/tools/tool-errors.ts +62 -0
- package/src/tools/tool-result.ts +94 -0
- package/src/tools/tool-timeouts.ts +30 -0
- package/src/tools/tts.ts +133 -0
- package/src/tools/write.ts +1085 -0
- package/src/tools/yield.ts +260 -0
- package/src/tui/code-cell.ts +221 -0
- package/src/tui/file-list.ts +55 -0
- package/src/tui/hyperlink.ts +161 -0
- package/src/tui/index.ts +12 -0
- package/src/tui/output-block.ts +288 -0
- package/src/tui/status-line.ts +50 -0
- package/src/tui/tree-list.ts +84 -0
- package/src/tui/types.ts +15 -0
- package/src/tui/utils.ts +103 -0
- package/src/utils/changelog.ts +106 -0
- package/src/utils/clipboard.ts +193 -0
- package/src/utils/command-args.ts +76 -0
- package/src/utils/commit-message-generator.ts +142 -0
- package/src/utils/edit-mode.ts +41 -0
- package/src/utils/event-bus.ts +33 -0
- package/src/utils/external-editor.ts +65 -0
- package/src/utils/file-display-mode.ts +45 -0
- package/src/utils/file-mentions.ts +280 -0
- package/src/utils/git.ts +1538 -0
- package/src/utils/image-loading.ts +102 -0
- package/src/utils/image-resize.ts +309 -0
- package/src/utils/jj.ts +248 -0
- package/src/utils/lang-from-path.ts +239 -0
- package/src/utils/markit.ts +89 -0
- package/src/utils/open.ts +55 -0
- package/src/utils/session-color.ts +68 -0
- package/src/utils/shell-snapshot.ts +187 -0
- package/src/utils/sixel.ts +69 -0
- package/src/utils/title-generator.ts +353 -0
- package/src/utils/tool-choice.ts +33 -0
- package/src/utils/tools-manager.ts +363 -0
- package/src/web/kagi.ts +302 -0
- package/src/web/parallel.ts +349 -0
- package/src/web/scrapers/artifacthub.ts +207 -0
- package/src/web/scrapers/arxiv.ts +83 -0
- package/src/web/scrapers/aur.ts +162 -0
- package/src/web/scrapers/biorxiv.ts +133 -0
- package/src/web/scrapers/bluesky.ts +262 -0
- package/src/web/scrapers/brew.ts +172 -0
- package/src/web/scrapers/cheatsh.ts +68 -0
- package/src/web/scrapers/chocolatey.ts +196 -0
- package/src/web/scrapers/choosealicense.ts +95 -0
- package/src/web/scrapers/cisa-kev.ts +87 -0
- package/src/web/scrapers/clojars.ts +154 -0
- package/src/web/scrapers/coingecko.ts +177 -0
- package/src/web/scrapers/crates-io.ts +97 -0
- package/src/web/scrapers/crossref.ts +136 -0
- package/src/web/scrapers/devto.ts +147 -0
- package/src/web/scrapers/discogs.ts +306 -0
- package/src/web/scrapers/discourse.ts +197 -0
- package/src/web/scrapers/dockerhub.ts +138 -0
- package/src/web/scrapers/docs-rs.ts +653 -0
- package/src/web/scrapers/fdroid.ts +134 -0
- package/src/web/scrapers/firefox-addons.ts +191 -0
- package/src/web/scrapers/flathub.ts +223 -0
- package/src/web/scrapers/github-gist.ts +58 -0
- package/src/web/scrapers/github.ts +452 -0
- package/src/web/scrapers/gitlab.ts +401 -0
- package/src/web/scrapers/go-pkg.ts +266 -0
- package/src/web/scrapers/hackage.ts +140 -0
- package/src/web/scrapers/hackernews.ts +189 -0
- package/src/web/scrapers/hex.ts +105 -0
- package/src/web/scrapers/huggingface.ts +321 -0
- package/src/web/scrapers/iacr.ts +89 -0
- package/src/web/scrapers/index.ts +252 -0
- package/src/web/scrapers/jetbrains-marketplace.ts +159 -0
- package/src/web/scrapers/lemmy.ts +203 -0
- package/src/web/scrapers/lobsters.ts +175 -0
- package/src/web/scrapers/mastodon.ts +292 -0
- package/src/web/scrapers/maven.ts +138 -0
- package/src/web/scrapers/mdn.ts +173 -0
- package/src/web/scrapers/metacpan.ts +222 -0
- package/src/web/scrapers/musicbrainz.ts +250 -0
- package/src/web/scrapers/npm.ts +98 -0
- package/src/web/scrapers/nuget.ts +183 -0
- package/src/web/scrapers/nvd.ts +222 -0
- package/src/web/scrapers/ollama.ts +239 -0
- package/src/web/scrapers/open-vsx.ts +106 -0
- package/src/web/scrapers/opencorporates.ts +292 -0
- package/src/web/scrapers/openlibrary.ts +336 -0
- package/src/web/scrapers/orcid.ts +286 -0
- package/src/web/scrapers/osv.ts +176 -0
- package/src/web/scrapers/packagist.ts +160 -0
- package/src/web/scrapers/pub-dev.ts +143 -0
- package/src/web/scrapers/pubmed.ts +211 -0
- package/src/web/scrapers/pypi.ts +112 -0
- package/src/web/scrapers/rawg.ts +110 -0
- package/src/web/scrapers/readthedocs.ts +120 -0
- package/src/web/scrapers/reddit.ts +95 -0
- package/src/web/scrapers/repology.ts +251 -0
- package/src/web/scrapers/rfc.ts +201 -0
- package/src/web/scrapers/rubygems.ts +103 -0
- package/src/web/scrapers/searchcode.ts +189 -0
- package/src/web/scrapers/sec-edgar.ts +261 -0
- package/src/web/scrapers/semantic-scholar.ts +171 -0
- package/src/web/scrapers/snapcraft.ts +187 -0
- package/src/web/scrapers/sourcegraph.ts +336 -0
- package/src/web/scrapers/spdx.ts +108 -0
- package/src/web/scrapers/spotify.ts +198 -0
- package/src/web/scrapers/stackoverflow.ts +120 -0
- package/src/web/scrapers/terraform.ts +277 -0
- package/src/web/scrapers/tldr.ts +47 -0
- package/src/web/scrapers/twitter.ts +93 -0
- package/src/web/scrapers/types.ts +318 -0
- package/src/web/scrapers/utils.ts +109 -0
- package/src/web/scrapers/vimeo.ts +133 -0
- package/src/web/scrapers/vscode-marketplace.ts +187 -0
- package/src/web/scrapers/w3c.ts +156 -0
- package/src/web/scrapers/wikidata.ts +344 -0
- package/src/web/scrapers/wikipedia.ts +84 -0
- package/src/web/scrapers/youtube.ts +319 -0
- package/src/web/search/index.ts +292 -0
- package/src/web/search/provider.ts +157 -0
- package/src/web/search/providers/anthropic.ts +302 -0
- package/src/web/search/providers/base.ts +88 -0
- package/src/web/search/providers/brave.ts +149 -0
- package/src/web/search/providers/codex.ts +557 -0
- package/src/web/search/providers/exa.ts +309 -0
- package/src/web/search/providers/gemini.ts +455 -0
- package/src/web/search/providers/jina.ts +101 -0
- package/src/web/search/providers/kagi.ts +79 -0
- package/src/web/search/providers/kimi.ts +171 -0
- package/src/web/search/providers/parallel.ts +210 -0
- package/src/web/search/providers/perplexity.ts +579 -0
- package/src/web/search/providers/searxng.ts +309 -0
- package/src/web/search/providers/synthetic.ts +110 -0
- package/src/web/search/providers/tavily.ts +173 -0
- package/src/web/search/providers/utils.ts +128 -0
- package/src/web/search/providers/zai.ts +320 -0
- package/src/web/search/render.ts +267 -0
- package/src/web/search/types.ts +478 -0
- package/src/web/search/utils.ts +17 -0
- package/src/workspace-tree.ts +286 -0
package/src/sdk.ts
ADDED
|
@@ -0,0 +1,2374 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Agent,
|
|
3
|
+
type AgentEvent,
|
|
4
|
+
type AgentMessage,
|
|
5
|
+
type AgentTelemetryConfig,
|
|
6
|
+
type AgentTool,
|
|
7
|
+
AppendOnlyContextManager,
|
|
8
|
+
INTENT_FIELD,
|
|
9
|
+
type ThinkingLevel,
|
|
10
|
+
} from "@prometheus-ai/agent-core";
|
|
11
|
+
import {
|
|
12
|
+
type CredentialDisabledEvent,
|
|
13
|
+
isUsageLimitError,
|
|
14
|
+
type Message,
|
|
15
|
+
type Model,
|
|
16
|
+
type SimpleStreamOptions,
|
|
17
|
+
streamSimple,
|
|
18
|
+
} from "@prometheus-ai/ai";
|
|
19
|
+
import {
|
|
20
|
+
getOpenAICodexTransportDetails,
|
|
21
|
+
prewarmOpenAICodexResponses,
|
|
22
|
+
} from "@prometheus-ai/ai/providers/openai-codex-responses";
|
|
23
|
+
import type { Component } from "@prometheus-ai/tui";
|
|
24
|
+
import {
|
|
25
|
+
$env,
|
|
26
|
+
$flag,
|
|
27
|
+
extractRetryHint,
|
|
28
|
+
getAgentDbPath,
|
|
29
|
+
getAgentDir,
|
|
30
|
+
getAuthBrokerSnapshotCachePath,
|
|
31
|
+
getProjectDir,
|
|
32
|
+
logger,
|
|
33
|
+
postmortem,
|
|
34
|
+
prompt,
|
|
35
|
+
Snowflake,
|
|
36
|
+
} from "@prometheus-ai/utils";
|
|
37
|
+
import chalk from "chalk";
|
|
38
|
+
import { type AsyncJob, AsyncJobManager, isBackgroundJobSupportEnabled } from "./async";
|
|
39
|
+
import { createAutoresearchExtension } from "./autoresearch";
|
|
40
|
+
import { loadCapability } from "./capability";
|
|
41
|
+
import { type Rule, ruleCapability, setActiveRules } from "./capability/rule";
|
|
42
|
+
import { bucketRules } from "./capability/rule-buckets";
|
|
43
|
+
import { shouldEnableAppendOnlyContext } from "./config/append-only-context-mode";
|
|
44
|
+
import { ModelRegistry } from "./config/model-registry";
|
|
45
|
+
import {
|
|
46
|
+
formatModelString,
|
|
47
|
+
parseModelPattern,
|
|
48
|
+
parseModelString,
|
|
49
|
+
resolveAllowedModels,
|
|
50
|
+
resolveModelRoleValue,
|
|
51
|
+
} from "./config/model-resolver";
|
|
52
|
+
import { loadPromptTemplates as loadPromptTemplatesInternal, type PromptTemplate } from "./config/prompt-templates";
|
|
53
|
+
import { Settings, type SkillsSettings } from "./config/settings";
|
|
54
|
+
import { CursorExecHandlers } from "./cursor";
|
|
55
|
+
import "./discovery";
|
|
56
|
+
import { resolveConfigValue } from "./config/resolve-config-value";
|
|
57
|
+
import { initializeWithSettings } from "./discovery";
|
|
58
|
+
import { disposeAllKernelSessions, disposeKernelSessionsByOwner } from "./eval/py/executor";
|
|
59
|
+
import { defaultEvalSessionId } from "./eval/session-id";
|
|
60
|
+
import { TtsrManager } from "./export/ttsr";
|
|
61
|
+
import {
|
|
62
|
+
type CustomCommandsLoadResult,
|
|
63
|
+
type LoadedCustomCommand,
|
|
64
|
+
loadCustomCommands as loadCustomCommandsInternal,
|
|
65
|
+
} from "./extensibility/custom-commands";
|
|
66
|
+
import { discoverAndLoadCustomTools } from "./extensibility/custom-tools";
|
|
67
|
+
import type { CustomTool, CustomToolContext, CustomToolSessionEvent } from "./extensibility/custom-tools/types";
|
|
68
|
+
import {
|
|
69
|
+
discoverAndLoadExtensions,
|
|
70
|
+
type ExtensionContext,
|
|
71
|
+
type ExtensionFactory,
|
|
72
|
+
ExtensionRunner,
|
|
73
|
+
ExtensionToolWrapper,
|
|
74
|
+
type ExtensionUIContext,
|
|
75
|
+
type LoadExtensionsResult,
|
|
76
|
+
loadExtensionFromFactory,
|
|
77
|
+
loadExtensions,
|
|
78
|
+
type ToolDefinition,
|
|
79
|
+
wrapRegisteredTools,
|
|
80
|
+
} from "./extensibility/extensions";
|
|
81
|
+
import {
|
|
82
|
+
loadSkills as loadSkillsInternal,
|
|
83
|
+
type Skill,
|
|
84
|
+
type SkillWarning,
|
|
85
|
+
setActiveSkills,
|
|
86
|
+
} from "./extensibility/skills";
|
|
87
|
+
import { type FileSlashCommand, loadSlashCommands as loadSlashCommandsInternal } from "./extensibility/slash-commands";
|
|
88
|
+
import type { HindsightSessionState } from "./hindsight/state";
|
|
89
|
+
import { LocalProtocolHandler, type LocalProtocolOptions } from "./internal-urls";
|
|
90
|
+
import { LSP_STARTUP_EVENT_CHANNEL, type LspStartupEvent } from "./lsp/startup-events";
|
|
91
|
+
import { discoverAndLoadMCPTools, MCPManager, type MCPToolsLoadResult } from "./mcp";
|
|
92
|
+
import { resolveMemoryBackend } from "./memory-backend";
|
|
93
|
+
import { getMnemopiSessionState, type MnemopiSessionState } from "./mnemopi/state";
|
|
94
|
+
import asyncResultTemplate from "./prompts/tools/async-result.md" with { type: "text" };
|
|
95
|
+
import { AgentRegistry, MAIN_AGENT_ID } from "./registry/agent-registry";
|
|
96
|
+
import {
|
|
97
|
+
collectEnvSecrets,
|
|
98
|
+
deobfuscateSessionContext,
|
|
99
|
+
loadSecrets,
|
|
100
|
+
obfuscateMessages,
|
|
101
|
+
SecretObfuscator,
|
|
102
|
+
} from "./secrets";
|
|
103
|
+
import { AgentSession } from "./session/agent-session";
|
|
104
|
+
import { resolveAuthBrokerConfig } from "./session/auth-broker-config";
|
|
105
|
+
import {
|
|
106
|
+
AuthBrokerClient,
|
|
107
|
+
AuthStorage,
|
|
108
|
+
DEFAULT_SNAPSHOT_CACHE_TTL_MS,
|
|
109
|
+
RemoteAuthCredentialStore,
|
|
110
|
+
readAuthBrokerSnapshotCache,
|
|
111
|
+
type SnapshotResponse,
|
|
112
|
+
writeAuthBrokerSnapshotCache,
|
|
113
|
+
} from "./session/auth-storage";
|
|
114
|
+
import { type CustomMessage, convertToLlm, wrapSteeringForModel } from "./session/messages";
|
|
115
|
+
import { getRestorableSessionModels, SessionManager } from "./session/session-manager";
|
|
116
|
+
import { closeAllConnections } from "./ssh/connection-manager";
|
|
117
|
+
import { unmountAll } from "./ssh/sshfs-mount";
|
|
118
|
+
import {
|
|
119
|
+
type BuildSystemPromptResult,
|
|
120
|
+
buildSystemPrompt as buildSystemPromptInternal,
|
|
121
|
+
buildSystemPromptToolMetadata,
|
|
122
|
+
loadProjectContextFiles as loadContextFilesInternal,
|
|
123
|
+
} from "./system-prompt";
|
|
124
|
+
import { AgentOutputManager } from "./task/output-manager";
|
|
125
|
+
import {
|
|
126
|
+
AUTO_THINKING,
|
|
127
|
+
type ConfiguredThinkingLevel,
|
|
128
|
+
parseThinkingLevel,
|
|
129
|
+
resolveProvisionalAutoLevel,
|
|
130
|
+
resolveThinkingLevelForModel,
|
|
131
|
+
toReasoningEffort,
|
|
132
|
+
} from "./thinking";
|
|
133
|
+
import { countToolsForAutoDiscovery, resolveEffectiveToolDiscoveryMode } from "./tool-discovery/mode";
|
|
134
|
+
import {
|
|
135
|
+
collectDiscoverableTools,
|
|
136
|
+
type DiscoverableTool,
|
|
137
|
+
filterBySource,
|
|
138
|
+
formatDiscoverableToolServerSummary,
|
|
139
|
+
selectDiscoverableToolNamesByServer,
|
|
140
|
+
summarizeDiscoverableTools,
|
|
141
|
+
} from "./tool-discovery/tool-index";
|
|
142
|
+
import {
|
|
143
|
+
BashTool,
|
|
144
|
+
BUILTIN_TOOLS,
|
|
145
|
+
computeEssentialBuiltinNames,
|
|
146
|
+
createTools,
|
|
147
|
+
discoverStartupLspServers,
|
|
148
|
+
EditTool,
|
|
149
|
+
EvalTool,
|
|
150
|
+
FindTool,
|
|
151
|
+
getSearchTools,
|
|
152
|
+
HIDDEN_TOOLS,
|
|
153
|
+
isImageProviderPreference,
|
|
154
|
+
isSearchProviderPreference,
|
|
155
|
+
type LspStartupServerInfo,
|
|
156
|
+
loadSshTool,
|
|
157
|
+
ReadTool,
|
|
158
|
+
ResolveTool,
|
|
159
|
+
renderSearchToolBm25Description,
|
|
160
|
+
SearchTool,
|
|
161
|
+
SearchToolBm25Tool,
|
|
162
|
+
setPreferredImageProvider,
|
|
163
|
+
setPreferredSearchProvider,
|
|
164
|
+
type Tool,
|
|
165
|
+
type ToolSession,
|
|
166
|
+
WebSearchTool,
|
|
167
|
+
WriteTool,
|
|
168
|
+
warmupLspServers,
|
|
169
|
+
} from "./tools";
|
|
170
|
+
import { ToolContextStore } from "./tools/context";
|
|
171
|
+
import { getImageGenTools } from "./tools/image-gen";
|
|
172
|
+
import { wrapToolWithMetaNotice } from "./tools/output-meta";
|
|
173
|
+
import { queueResolveHandler } from "./tools/resolve";
|
|
174
|
+
import { ttsTool } from "./tools/tts";
|
|
175
|
+
import { EventBus } from "./utils/event-bus";
|
|
176
|
+
import { buildNamedToolChoice } from "./utils/tool-choice";
|
|
177
|
+
import { buildWorkspaceTree, type WorkspaceTree } from "./workspace-tree";
|
|
178
|
+
|
|
179
|
+
type AsyncResultEntry = {
|
|
180
|
+
jobId: string;
|
|
181
|
+
result: string;
|
|
182
|
+
job: AsyncJob | undefined;
|
|
183
|
+
durationMs: number | undefined;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
type AsyncResultJobDetails = {
|
|
187
|
+
jobId: string;
|
|
188
|
+
type?: "bash" | "task";
|
|
189
|
+
label?: string;
|
|
190
|
+
durationMs?: number;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
type AsyncResultDetails = {
|
|
194
|
+
jobs: AsyncResultJobDetails[];
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
type McpNotificationEntry = {
|
|
198
|
+
serverName: string;
|
|
199
|
+
uri: string;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
function buildAsyncResultBatchMessage(entries: AsyncResultEntry[]): CustomMessage<AsyncResultDetails> | null {
|
|
203
|
+
if (entries.length === 0) return null;
|
|
204
|
+
const jobs = entries.map(entry => ({
|
|
205
|
+
jobId: entry.jobId,
|
|
206
|
+
result: entry.result,
|
|
207
|
+
type: entry.job?.type,
|
|
208
|
+
label: entry.job?.label,
|
|
209
|
+
durationMs: entry.durationMs,
|
|
210
|
+
}));
|
|
211
|
+
const details: AsyncResultDetails = {
|
|
212
|
+
jobs: jobs.map(job => ({
|
|
213
|
+
jobId: job.jobId,
|
|
214
|
+
type: job.type,
|
|
215
|
+
label: job.label,
|
|
216
|
+
durationMs: job.durationMs,
|
|
217
|
+
})),
|
|
218
|
+
};
|
|
219
|
+
return {
|
|
220
|
+
role: "custom",
|
|
221
|
+
customType: "async-result",
|
|
222
|
+
content: prompt.render(asyncResultTemplate, {
|
|
223
|
+
multiple: jobs.length > 1,
|
|
224
|
+
jobs,
|
|
225
|
+
}),
|
|
226
|
+
display: true,
|
|
227
|
+
attribution: "agent",
|
|
228
|
+
details,
|
|
229
|
+
timestamp: Date.now(),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function buildMcpNotificationBatchMessage(entries: McpNotificationEntry[]): AgentMessage | null {
|
|
234
|
+
const resources: McpNotificationEntry[] = [];
|
|
235
|
+
const seen = new Set<string>();
|
|
236
|
+
for (const entry of entries) {
|
|
237
|
+
const key = `${entry.serverName}\0${entry.uri}`;
|
|
238
|
+
if (seen.has(key)) continue;
|
|
239
|
+
seen.add(key);
|
|
240
|
+
resources.push(entry);
|
|
241
|
+
}
|
|
242
|
+
if (resources.length === 0) return null;
|
|
243
|
+
const lines = [`[MCP notification] ${resources.length} resource(s) updated:`];
|
|
244
|
+
for (const resource of resources) {
|
|
245
|
+
lines.push(`- server="${resource.serverName}" uri=${resource.uri}`);
|
|
246
|
+
}
|
|
247
|
+
lines.push('Use read(path="mcp://<uri>") to inspect if relevant.');
|
|
248
|
+
return {
|
|
249
|
+
role: "user",
|
|
250
|
+
content: [{ type: "text", text: lines.join("\n") }],
|
|
251
|
+
attribution: "agent",
|
|
252
|
+
timestamp: Date.now(),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Types
|
|
257
|
+
export interface CreateAgentSessionOptions {
|
|
258
|
+
/** Working directory for project-local discovery. Default: getProjectDir() */
|
|
259
|
+
cwd?: string;
|
|
260
|
+
/** Global config directory. Default: ~/.prometheus/agent */
|
|
261
|
+
agentDir?: string;
|
|
262
|
+
/** Spawns to allow. Default: "*" */
|
|
263
|
+
spawns?: string;
|
|
264
|
+
|
|
265
|
+
/** Auth storage for credentials. Default: discoverAuthStorage(agentDir) */
|
|
266
|
+
authStorage?: AuthStorage;
|
|
267
|
+
/** Model registry. Default: discoverModels(authStorage, agentDir) */
|
|
268
|
+
modelRegistry?: ModelRegistry;
|
|
269
|
+
|
|
270
|
+
/** Model to use. Default: from settings, else first available */
|
|
271
|
+
model?: Model;
|
|
272
|
+
/** Raw model pattern string (e.g. from --model CLI flag) to resolve after extensions load.
|
|
273
|
+
* Used when model lookup is deferred because extension-provided models aren't registered yet. */
|
|
274
|
+
modelPattern?: string;
|
|
275
|
+
/** Thinking selector. Default: from settings, else unset */
|
|
276
|
+
thinkingLevel?: ConfiguredThinkingLevel;
|
|
277
|
+
/** Models available for cycling (Ctrl+P in interactive mode) */
|
|
278
|
+
scopedModels?: Array<{ model: Model; thinkingLevel?: ThinkingLevel }>;
|
|
279
|
+
|
|
280
|
+
/** System prompt blocks. Array replaces default, function receives default blocks and returns final blocks. */
|
|
281
|
+
systemPrompt?: string[] | ((defaultPrompt: string[]) => string[]);
|
|
282
|
+
/** Optional provider-facing session identifier for prompt caches and sticky auth selection.
|
|
283
|
+
* Keeps persisted session files isolated while reusing provider-side caches. */
|
|
284
|
+
providerSessionId?: string;
|
|
285
|
+
|
|
286
|
+
/** Custom tools to register (in addition to built-in tools). Accepts both CustomTool and ToolDefinition. */
|
|
287
|
+
customTools?: (CustomTool | ToolDefinition)[];
|
|
288
|
+
/** Inline extensions (merged with discovery). */
|
|
289
|
+
extensions?: ExtensionFactory[];
|
|
290
|
+
/** Additional extension paths to load (merged with discovery). */
|
|
291
|
+
additionalExtensionPaths?: string[];
|
|
292
|
+
/** Disable extension discovery (explicit paths still load). */
|
|
293
|
+
disableExtensionDiscovery?: boolean;
|
|
294
|
+
/**
|
|
295
|
+
* Pre-loaded extensions (skips file discovery).
|
|
296
|
+
* @internal Used by CLI when extensions are loaded early to parse custom flags.
|
|
297
|
+
*/
|
|
298
|
+
preloadedExtensions?: LoadExtensionsResult;
|
|
299
|
+
|
|
300
|
+
/** Shared event bus for tool/extension communication. Default: creates new bus. */
|
|
301
|
+
eventBus?: EventBus;
|
|
302
|
+
|
|
303
|
+
/** Skills. Default: discovered from multiple locations */
|
|
304
|
+
skills?: Skill[];
|
|
305
|
+
/** Rules. Default: discovered from multiple locations */
|
|
306
|
+
rules?: Rule[];
|
|
307
|
+
/** Context files (AGENTS.md content). Default: discovered walking up from cwd */
|
|
308
|
+
contextFiles?: Array<{ path: string; content: string }>;
|
|
309
|
+
/** Pre-built workspace tree (skips re-scanning; passed by parents to subagents). */
|
|
310
|
+
workspaceTree?: WorkspaceTree;
|
|
311
|
+
/** Prompt templates. Default: discovered from cwd/.prometheus/prompts/ + agentDir/prompts/ */
|
|
312
|
+
promptTemplates?: PromptTemplate[];
|
|
313
|
+
/** File-based slash commands. Default: discovered from commands/ directories */
|
|
314
|
+
slashCommands?: FileSlashCommand[];
|
|
315
|
+
|
|
316
|
+
/** Enable MCP server discovery from .mcp.json files. Default: true */
|
|
317
|
+
enableMCP?: boolean;
|
|
318
|
+
/** Existing MCP manager to reuse (skips discovery, propagates to toolSession). */
|
|
319
|
+
mcpManager?: MCPManager;
|
|
320
|
+
|
|
321
|
+
/** Enable LSP integration (tool, formatting, diagnostics, warmup). Default: true */
|
|
322
|
+
enableLsp?: boolean;
|
|
323
|
+
/** Skip Python kernel availability check and prelude warmup */
|
|
324
|
+
skipPythonPreflight?: boolean;
|
|
325
|
+
/** Tool names explicitly requested (enables disabled-by-default tools) */
|
|
326
|
+
toolNames?: string[];
|
|
327
|
+
|
|
328
|
+
/** Output schema for structured completion (subagents) */
|
|
329
|
+
outputSchema?: unknown;
|
|
330
|
+
/** Whether to include the yield tool by default */
|
|
331
|
+
requireYieldTool?: boolean;
|
|
332
|
+
/** Task recursion depth (for subagent sessions). Default: 0 */
|
|
333
|
+
taskDepth?: number;
|
|
334
|
+
/** Parent Hindsight state to alias for subagent memory tools. */
|
|
335
|
+
parentHindsightSessionState?: HindsightSessionState;
|
|
336
|
+
/** Parent Mnemopi state to alias for subagent memory tools. */
|
|
337
|
+
parentMnemopiSessionState?: MnemopiSessionState;
|
|
338
|
+
/** Pre-allocated agent identity for IRC routing. Default: "Main" for top-level, parentTaskPrefix-derived for sub. */
|
|
339
|
+
agentId?: string;
|
|
340
|
+
/** Display name for the agent in IRC. Default: "main" or "sub". */
|
|
341
|
+
agentDisplayName?: string;
|
|
342
|
+
/** Optional shared agent registry for IRC routing. Default: AgentRegistry.global(). */
|
|
343
|
+
agentRegistry?: AgentRegistry;
|
|
344
|
+
/** Parent task ID prefix for nested artifact naming (e.g., "Extensions") */
|
|
345
|
+
parentTaskPrefix?: string;
|
|
346
|
+
/** Inherited eval executor session id for subagents sharing parent eval state. */
|
|
347
|
+
parentEvalSessionId?: string;
|
|
348
|
+
|
|
349
|
+
/** Session manager. Default: session stored under the configured agentDir sessions root */
|
|
350
|
+
sessionManager?: SessionManager;
|
|
351
|
+
|
|
352
|
+
/** Override local:// protocol options for subagent local:// sharing. Default: uses the session's own artifacts dir and session ID. */
|
|
353
|
+
localProtocolOptions?: LocalProtocolOptions;
|
|
354
|
+
|
|
355
|
+
/** Settings instance. Default: Settings.init({ cwd, agentDir }) */
|
|
356
|
+
settings?: Settings;
|
|
357
|
+
|
|
358
|
+
/** Whether UI is available (enables interactive tools like ask). Default: false */
|
|
359
|
+
hasUI?: boolean;
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Opt-in OpenTelemetry instrumentation forwarded to the underlying Agent.
|
|
363
|
+
* Passing `{}` enables the loop's GenAI-semantic-convention spans. See
|
|
364
|
+
* {@link AgentTelemetryConfig} for the full surface (hooks, content capture,
|
|
365
|
+
* cost estimator, agent identity).
|
|
366
|
+
*
|
|
367
|
+
* Safe to enable without an OTEL SDK registered in the host: the
|
|
368
|
+
* `@opentelemetry/api` package returns a no-op tracer in that case.
|
|
369
|
+
*/
|
|
370
|
+
telemetry?: AgentTelemetryConfig;
|
|
371
|
+
|
|
372
|
+
/** Whether to auto-approve all tool calls (--auto-approve CLI flag). Default: false */
|
|
373
|
+
autoApprove?: boolean;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/** Result from createAgentSession */
|
|
377
|
+
export interface CreateAgentSessionResult {
|
|
378
|
+
/** The created session */
|
|
379
|
+
session: AgentSession;
|
|
380
|
+
/** Extensions result (loaded extensions + runtime) */
|
|
381
|
+
extensionsResult: LoadExtensionsResult;
|
|
382
|
+
/** Update tool UI context (interactive mode) */
|
|
383
|
+
setToolUIContext: (uiContext: ExtensionUIContext, hasUI: boolean) => void;
|
|
384
|
+
/** MCP manager for server lifecycle management (undefined if MCP disabled) */
|
|
385
|
+
mcpManager?: MCPManager;
|
|
386
|
+
/** Warning if session was restored with a different model than saved */
|
|
387
|
+
modelFallbackMessage?: string;
|
|
388
|
+
/** LSP servers detected for startup; warmup may continue in the background */
|
|
389
|
+
lspServers?: LspStartupServerInfo[];
|
|
390
|
+
/** Shared event bus for tool/extension communication */
|
|
391
|
+
eventBus: EventBus;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// Re-exports
|
|
395
|
+
|
|
396
|
+
export type { PromptTemplate } from "./config/prompt-templates";
|
|
397
|
+
export { Settings, type SkillsSettings } from "./config/settings";
|
|
398
|
+
export type { CustomCommand, CustomCommandFactory } from "./extensibility/custom-commands/types";
|
|
399
|
+
export type { CustomTool, CustomToolFactory } from "./extensibility/custom-tools/types";
|
|
400
|
+
export type * from "./extensibility/extensions";
|
|
401
|
+
export type { Skill } from "./extensibility/skills";
|
|
402
|
+
export type { FileSlashCommand } from "./extensibility/slash-commands";
|
|
403
|
+
export type { MCPManager, MCPServerConfig, MCPServerConnection, MCPToolsLoadResult } from "./mcp";
|
|
404
|
+
export type { Tool } from "./tools";
|
|
405
|
+
export { buildDirectoryTree, buildWorkspaceTree, type DirectoryTree, type WorkspaceTree } from "./workspace-tree";
|
|
406
|
+
|
|
407
|
+
export {
|
|
408
|
+
// Individual tool classes (for custom usage)
|
|
409
|
+
BashTool,
|
|
410
|
+
// Tool classes and factories
|
|
411
|
+
BUILTIN_TOOLS,
|
|
412
|
+
createTools,
|
|
413
|
+
EditTool,
|
|
414
|
+
EvalTool,
|
|
415
|
+
FindTool,
|
|
416
|
+
HIDDEN_TOOLS,
|
|
417
|
+
loadSshTool,
|
|
418
|
+
ReadTool,
|
|
419
|
+
ResolveTool,
|
|
420
|
+
SearchTool,
|
|
421
|
+
type ToolSession,
|
|
422
|
+
WebSearchTool,
|
|
423
|
+
WriteTool,
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
// Helper Functions
|
|
427
|
+
|
|
428
|
+
function getDefaultAgentDir(): string {
|
|
429
|
+
return getAgentDir();
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function resolveSnapshotTtlMs(): number {
|
|
433
|
+
const raw = process.env.PROMETHEUS_AUTH_BROKER_SNAPSHOT_TTL_MS;
|
|
434
|
+
if (raw === undefined) return DEFAULT_SNAPSHOT_CACHE_TTL_MS;
|
|
435
|
+
const value = raw.trim();
|
|
436
|
+
if (value === "") return DEFAULT_SNAPSHOT_CACHE_TTL_MS;
|
|
437
|
+
const ttlMs = Number(value);
|
|
438
|
+
if (Number.isFinite(ttlMs) && ttlMs >= 0) return ttlMs;
|
|
439
|
+
logger.warn("Invalid PROMETHEUS_AUTH_BROKER_SNAPSHOT_TTL_MS; using default", { value: raw });
|
|
440
|
+
return DEFAULT_SNAPSHOT_CACHE_TTL_MS;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// Discovery Functions
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Create an AuthStorage instance.
|
|
447
|
+
*
|
|
448
|
+
* Default: local SQLite store at `<agentDir>/agent.db`.
|
|
449
|
+
*
|
|
450
|
+
* Broker mode: when `PROMETHEUS_AUTH_BROKER_URL` is set, credentials are pulled from
|
|
451
|
+
* a remote auth-broker over the wire. Refresh tokens never leave the broker;
|
|
452
|
+
* the client receives access tokens with `refresh = "__remote__"` and calls
|
|
453
|
+
* back into the broker through the {@link AuthStorageOptions.refreshOAuthCredential}
|
|
454
|
+
* override to re-mint access tokens when needed.
|
|
455
|
+
*/
|
|
456
|
+
export async function discoverAuthStorage(agentDir: string = getDefaultAgentDir()): Promise<AuthStorage> {
|
|
457
|
+
const brokerConfig = await resolveAuthBrokerConfig();
|
|
458
|
+
if (brokerConfig) {
|
|
459
|
+
const client = new AuthBrokerClient({ url: brokerConfig.url, token: brokerConfig.token });
|
|
460
|
+
const ttlMs = resolveSnapshotTtlMs();
|
|
461
|
+
const cachePath = getAuthBrokerSnapshotCachePath();
|
|
462
|
+
const persist =
|
|
463
|
+
ttlMs > 0
|
|
464
|
+
? (snapshot: SnapshotResponse): void => {
|
|
465
|
+
void writeAuthBrokerSnapshotCache({
|
|
466
|
+
path: cachePath,
|
|
467
|
+
token: brokerConfig.token,
|
|
468
|
+
url: brokerConfig.url,
|
|
469
|
+
snapshot,
|
|
470
|
+
}).catch(error => {
|
|
471
|
+
logger.debug("auth-broker snapshot cache write failed", { error: String(error) });
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
: undefined;
|
|
475
|
+
|
|
476
|
+
let initialSnapshot: SnapshotResponse | undefined;
|
|
477
|
+
if (ttlMs > 0) {
|
|
478
|
+
initialSnapshot =
|
|
479
|
+
(await readAuthBrokerSnapshotCache({
|
|
480
|
+
path: cachePath,
|
|
481
|
+
token: brokerConfig.token,
|
|
482
|
+
url: brokerConfig.url,
|
|
483
|
+
ttlMs,
|
|
484
|
+
}).catch(error => {
|
|
485
|
+
logger.debug("auth-broker snapshot cache read failed", { error: String(error) });
|
|
486
|
+
return null;
|
|
487
|
+
})) ?? undefined;
|
|
488
|
+
}
|
|
489
|
+
if (!initialSnapshot) {
|
|
490
|
+
const initialResult = await client.fetchSnapshot();
|
|
491
|
+
if (initialResult.status !== 200) throw new Error("Auth broker returned no initial snapshot");
|
|
492
|
+
initialSnapshot = initialResult.snapshot;
|
|
493
|
+
persist?.(initialSnapshot);
|
|
494
|
+
}
|
|
495
|
+
const store = new RemoteAuthCredentialStore({ client, initialSnapshot, onSnapshot: persist });
|
|
496
|
+
// Refresh + usage hooks live on RemoteAuthCredentialStore; AuthStorage
|
|
497
|
+
// discovers them automatically when no explicit option overrides them.
|
|
498
|
+
const storage = new AuthStorage(store, {
|
|
499
|
+
configValueResolver: resolveConfigValue,
|
|
500
|
+
sourceLabel: `broker ${brokerConfig.url}`,
|
|
501
|
+
});
|
|
502
|
+
await storage.reload();
|
|
503
|
+
return storage;
|
|
504
|
+
}
|
|
505
|
+
const dbPath = getAgentDbPath(agentDir);
|
|
506
|
+
const storage = await AuthStorage.create(dbPath, {
|
|
507
|
+
configValueResolver: resolveConfigValue,
|
|
508
|
+
sourceLabel: `local ${dbPath}`,
|
|
509
|
+
});
|
|
510
|
+
await storage.reload();
|
|
511
|
+
return storage;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Discover extensions from cwd.
|
|
516
|
+
*/
|
|
517
|
+
export async function discoverExtensions(cwd?: string): Promise<LoadExtensionsResult> {
|
|
518
|
+
const resolvedCwd = cwd ?? getProjectDir();
|
|
519
|
+
|
|
520
|
+
return discoverAndLoadExtensions([], resolvedCwd);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Load the discovered/configured extensions for a session — everything {@link
|
|
525
|
+
* createAgentSession} would load except the inline factory extensions it appends
|
|
526
|
+
* itself. Extracted so the CLI can resolve extension-registered flags (and thus
|
|
527
|
+
* classify `@file` arguments extension-aware) *before* a session — and its
|
|
528
|
+
* terminal breadcrumb — is created, then hand the result back through
|
|
529
|
+
* {@link CreateAgentSessionOptions.preloadedExtensions} so the work is not
|
|
530
|
+
* repeated. Keep this the single source of the discovery branch logic.
|
|
531
|
+
*/
|
|
532
|
+
export async function loadSessionExtensions(
|
|
533
|
+
options: Pick<CreateAgentSessionOptions, "disableExtensionDiscovery" | "additionalExtensionPaths">,
|
|
534
|
+
cwd: string,
|
|
535
|
+
settings: Settings,
|
|
536
|
+
eventBus: EventBus,
|
|
537
|
+
): Promise<LoadExtensionsResult> {
|
|
538
|
+
let result: LoadExtensionsResult;
|
|
539
|
+
if (options.disableExtensionDiscovery) {
|
|
540
|
+
const configuredPaths = options.additionalExtensionPaths ?? [];
|
|
541
|
+
result = await logger.time("loadExtensions", loadExtensions, configuredPaths, cwd, eventBus);
|
|
542
|
+
} else {
|
|
543
|
+
// Merge CLI extension paths with settings extension paths.
|
|
544
|
+
const configuredPaths = [...(options.additionalExtensionPaths ?? []), ...(settings.get("extensions") ?? [])];
|
|
545
|
+
const disabledExtensionIds = settings.get("disabledExtensions") ?? [];
|
|
546
|
+
result = await logger.time(
|
|
547
|
+
"discoverAndLoadExtensions",
|
|
548
|
+
discoverAndLoadExtensions,
|
|
549
|
+
configuredPaths,
|
|
550
|
+
cwd,
|
|
551
|
+
eventBus,
|
|
552
|
+
disabledExtensionIds,
|
|
553
|
+
);
|
|
554
|
+
}
|
|
555
|
+
for (const { path, error } of result.errors) {
|
|
556
|
+
logger.error("Failed to load extension", { path, error });
|
|
557
|
+
}
|
|
558
|
+
return result;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Discover skills from cwd and agentDir.
|
|
563
|
+
*/
|
|
564
|
+
export async function discoverSkills(
|
|
565
|
+
cwd?: string,
|
|
566
|
+
_agentDir?: string,
|
|
567
|
+
settings?: SkillsSettings,
|
|
568
|
+
): Promise<{ skills: Skill[]; warnings: SkillWarning[] }> {
|
|
569
|
+
return await loadSkillsInternal({
|
|
570
|
+
...settings,
|
|
571
|
+
cwd: cwd ?? getProjectDir(),
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Discover context files (AGENTS.md) walking up from cwd.
|
|
577
|
+
* Returns files sorted by depth (farther from cwd first, so closer files appear last/more prominent).
|
|
578
|
+
*/
|
|
579
|
+
export async function discoverContextFiles(
|
|
580
|
+
cwd?: string,
|
|
581
|
+
_agentDir?: string,
|
|
582
|
+
): Promise<Array<{ path: string; content: string; depth?: number }>> {
|
|
583
|
+
return await loadContextFilesInternal({
|
|
584
|
+
cwd: cwd ?? getProjectDir(),
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Discover prompt templates from cwd and agentDir.
|
|
590
|
+
*/
|
|
591
|
+
export async function discoverPromptTemplates(cwd?: string, agentDir?: string): Promise<PromptTemplate[]> {
|
|
592
|
+
return await loadPromptTemplatesInternal({
|
|
593
|
+
cwd: cwd ?? getProjectDir(),
|
|
594
|
+
agentDir: agentDir ?? getDefaultAgentDir(),
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Discover file-based slash commands from commands/ directories.
|
|
600
|
+
*/
|
|
601
|
+
export async function discoverSlashCommands(cwd?: string): Promise<FileSlashCommand[]> {
|
|
602
|
+
return loadSlashCommandsInternal({ cwd: cwd ?? getProjectDir() });
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Discover custom commands (TypeScript slash commands) from cwd and agentDir.
|
|
607
|
+
*/
|
|
608
|
+
export async function discoverCustomTSCommands(cwd?: string, agentDir?: string): Promise<CustomCommandsLoadResult> {
|
|
609
|
+
const resolvedCwd = cwd ?? getProjectDir();
|
|
610
|
+
const resolvedAgentDir = agentDir ?? getDefaultAgentDir();
|
|
611
|
+
|
|
612
|
+
return loadCustomCommandsInternal({
|
|
613
|
+
cwd: resolvedCwd,
|
|
614
|
+
agentDir: resolvedAgentDir,
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Discover MCP servers from .mcp.json files.
|
|
620
|
+
* Returns the manager and loaded tools.
|
|
621
|
+
*/
|
|
622
|
+
export async function discoverMCPServers(cwd?: string): Promise<MCPToolsLoadResult> {
|
|
623
|
+
const resolvedCwd = cwd ?? getProjectDir();
|
|
624
|
+
return discoverAndLoadMCPTools(resolvedCwd);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// API Key Helpers
|
|
628
|
+
|
|
629
|
+
// System Prompt
|
|
630
|
+
|
|
631
|
+
export interface BuildSystemPromptOptions {
|
|
632
|
+
tools?: Tool[];
|
|
633
|
+
skills?: Skill[];
|
|
634
|
+
contextFiles?: Array<{ path: string; content: string }>;
|
|
635
|
+
cwd?: string;
|
|
636
|
+
appendPrompt?: string;
|
|
637
|
+
repeatToolDescriptions?: boolean;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Build the default provider-facing system prompt blocks.
|
|
642
|
+
*
|
|
643
|
+
* The returned `systemPrompt` preserves the stable harness prompt and dynamic project context
|
|
644
|
+
* as separate entries so providers can cache prompt prefixes without concatenating blocks.
|
|
645
|
+
*/
|
|
646
|
+
export async function buildSystemPrompt(options: BuildSystemPromptOptions = {}): Promise<BuildSystemPromptResult> {
|
|
647
|
+
return await buildSystemPromptInternal({
|
|
648
|
+
cwd: options.cwd,
|
|
649
|
+
skills: options.skills,
|
|
650
|
+
contextFiles: options.contextFiles,
|
|
651
|
+
appendSystemPrompt: options.appendPrompt,
|
|
652
|
+
repeatToolDescriptions: options.repeatToolDescriptions,
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// Internal Helpers
|
|
657
|
+
|
|
658
|
+
function createCustomToolContext(ctx: ExtensionContext): CustomToolContext {
|
|
659
|
+
return {
|
|
660
|
+
sessionManager: ctx.sessionManager,
|
|
661
|
+
modelRegistry: ctx.modelRegistry,
|
|
662
|
+
model: ctx.model,
|
|
663
|
+
isIdle: ctx.isIdle,
|
|
664
|
+
hasQueuedMessages: ctx.hasPendingMessages,
|
|
665
|
+
abort: ctx.abort,
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
function isCustomTool(tool: CustomTool | ToolDefinition): tool is CustomTool {
|
|
670
|
+
// To distinguish, we mark converted tools with a hidden symbol property.
|
|
671
|
+
// If the tool doesn't have this marker, it's a CustomTool that needs conversion.
|
|
672
|
+
return !(tool as any).__isToolDefinition;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
const TOOL_DEFINITION_MARKER = Symbol("__isToolDefinition");
|
|
676
|
+
|
|
677
|
+
/** Matches the truncation applied to per-server instructions inside `rebuildSystemPrompt`. */
|
|
678
|
+
const MAX_MCP_INSTRUCTIONS_LENGTH = 4000;
|
|
679
|
+
|
|
680
|
+
let sshCleanupRegistered = false;
|
|
681
|
+
|
|
682
|
+
async function cleanupSshResources(): Promise<void> {
|
|
683
|
+
const results = await Promise.allSettled([closeAllConnections(), unmountAll()]);
|
|
684
|
+
for (const result of results) {
|
|
685
|
+
if (result.status === "rejected") {
|
|
686
|
+
logger.warn("SSH cleanup failed", { error: String(result.reason) });
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
function registerSshCleanup(): void {
|
|
692
|
+
if (sshCleanupRegistered) return;
|
|
693
|
+
sshCleanupRegistered = true;
|
|
694
|
+
postmortem.register("ssh-cleanup", cleanupSshResources);
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
let pythonCleanupRegistered = false;
|
|
698
|
+
|
|
699
|
+
function registerPythonCleanup(): void {
|
|
700
|
+
if (pythonCleanupRegistered) return;
|
|
701
|
+
pythonCleanupRegistered = true;
|
|
702
|
+
postmortem.register("python-cleanup", disposeAllKernelSessions);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
function customToolToDefinition(tool: CustomTool): ToolDefinition {
|
|
706
|
+
const definition: ToolDefinition & { [TOOL_DEFINITION_MARKER]: true } = {
|
|
707
|
+
name: tool.name,
|
|
708
|
+
label: tool.label,
|
|
709
|
+
description: tool.description,
|
|
710
|
+
parameters: tool.parameters,
|
|
711
|
+
hidden: tool.hidden,
|
|
712
|
+
deferrable: tool.deferrable,
|
|
713
|
+
mcpServerName: tool.mcpServerName,
|
|
714
|
+
mcpToolName: tool.mcpToolName,
|
|
715
|
+
execute: (toolCallId, params, signal, onUpdate, ctx) =>
|
|
716
|
+
tool.execute(toolCallId, params, onUpdate, createCustomToolContext(ctx), signal),
|
|
717
|
+
onSession: tool.onSession ? (event, ctx) => tool.onSession?.(event, createCustomToolContext(ctx)) : undefined,
|
|
718
|
+
renderCall: tool.renderCall,
|
|
719
|
+
renderResult: tool.renderResult
|
|
720
|
+
? (result, options, theme): Component => {
|
|
721
|
+
const component = tool.renderResult?.(
|
|
722
|
+
result,
|
|
723
|
+
{ expanded: options.expanded, isPartial: options.isPartial, spinnerFrame: options.spinnerFrame },
|
|
724
|
+
theme,
|
|
725
|
+
);
|
|
726
|
+
// Return empty component if undefined to match Component type requirement
|
|
727
|
+
return component ?? ({ render: () => [] } as unknown as Component);
|
|
728
|
+
}
|
|
729
|
+
: undefined,
|
|
730
|
+
[TOOL_DEFINITION_MARKER]: true,
|
|
731
|
+
};
|
|
732
|
+
return definition;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
function createCustomToolsExtension(tools: CustomTool[]): ExtensionFactory {
|
|
736
|
+
return api => {
|
|
737
|
+
for (const tool of tools) {
|
|
738
|
+
api.registerTool(customToolToDefinition(tool));
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
const runOnSession = async (event: CustomToolSessionEvent, ctx: ExtensionContext) => {
|
|
742
|
+
for (const tool of tools) {
|
|
743
|
+
if (!tool.onSession) continue;
|
|
744
|
+
try {
|
|
745
|
+
await tool.onSession(event, createCustomToolContext(ctx));
|
|
746
|
+
} catch (err) {
|
|
747
|
+
logger.warn("Custom tool onSession error", { tool: tool.name, error: String(err) });
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
|
|
752
|
+
api.on("session_start", async (_event, ctx) =>
|
|
753
|
+
runOnSession({ reason: "start", previousSessionFile: undefined }, ctx),
|
|
754
|
+
);
|
|
755
|
+
api.on("session_switch", async (event, ctx) =>
|
|
756
|
+
runOnSession({ reason: "switch", previousSessionFile: event.previousSessionFile }, ctx),
|
|
757
|
+
);
|
|
758
|
+
api.on("session_branch", async (event, ctx) =>
|
|
759
|
+
runOnSession({ reason: "branch", previousSessionFile: event.previousSessionFile }, ctx),
|
|
760
|
+
);
|
|
761
|
+
api.on("session_tree", async (_event, ctx) =>
|
|
762
|
+
runOnSession({ reason: "tree", previousSessionFile: undefined }, ctx),
|
|
763
|
+
);
|
|
764
|
+
api.on("session_shutdown", async (_event, ctx) =>
|
|
765
|
+
runOnSession({ reason: "shutdown", previousSessionFile: undefined }, ctx),
|
|
766
|
+
);
|
|
767
|
+
api.on("auto_compaction_start", async (event, ctx) =>
|
|
768
|
+
runOnSession({ reason: "auto_compaction_start", trigger: event.reason, action: event.action }, ctx),
|
|
769
|
+
);
|
|
770
|
+
api.on("auto_compaction_end", async (event, ctx) =>
|
|
771
|
+
runOnSession(
|
|
772
|
+
{
|
|
773
|
+
reason: "auto_compaction_end",
|
|
774
|
+
action: event.action,
|
|
775
|
+
result: event.result,
|
|
776
|
+
aborted: event.aborted,
|
|
777
|
+
willRetry: event.willRetry,
|
|
778
|
+
errorMessage: event.errorMessage,
|
|
779
|
+
},
|
|
780
|
+
ctx,
|
|
781
|
+
),
|
|
782
|
+
);
|
|
783
|
+
api.on("auto_retry_start", async (event, ctx) =>
|
|
784
|
+
runOnSession(
|
|
785
|
+
{
|
|
786
|
+
reason: "auto_retry_start",
|
|
787
|
+
attempt: event.attempt,
|
|
788
|
+
maxAttempts: event.maxAttempts,
|
|
789
|
+
delayMs: event.delayMs,
|
|
790
|
+
errorMessage: event.errorMessage,
|
|
791
|
+
},
|
|
792
|
+
ctx,
|
|
793
|
+
),
|
|
794
|
+
);
|
|
795
|
+
api.on("auto_retry_end", async (event, ctx) =>
|
|
796
|
+
runOnSession(
|
|
797
|
+
{
|
|
798
|
+
reason: "auto_retry_end",
|
|
799
|
+
success: event.success,
|
|
800
|
+
attempt: event.attempt,
|
|
801
|
+
finalError: event.finalError,
|
|
802
|
+
},
|
|
803
|
+
ctx,
|
|
804
|
+
),
|
|
805
|
+
);
|
|
806
|
+
api.on("ttsr_triggered", async (event, ctx) =>
|
|
807
|
+
runOnSession({ reason: "ttsr_triggered", rules: event.rules }, ctx),
|
|
808
|
+
);
|
|
809
|
+
api.on("todo_reminder", async (event, ctx) =>
|
|
810
|
+
runOnSession(
|
|
811
|
+
{
|
|
812
|
+
reason: "todo_reminder",
|
|
813
|
+
todos: event.todos,
|
|
814
|
+
attempt: event.attempt,
|
|
815
|
+
maxAttempts: event.maxAttempts,
|
|
816
|
+
},
|
|
817
|
+
ctx,
|
|
818
|
+
),
|
|
819
|
+
);
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
// Factory
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* Build LoadedCustomCommand entries for all MCP prompts across connected servers.
|
|
827
|
+
* These are re-created whenever prompts change (setOnPromptsChanged callback).
|
|
828
|
+
*/
|
|
829
|
+
function buildMCPPromptCommands(manager: MCPManager): LoadedCustomCommand[] {
|
|
830
|
+
const commands: LoadedCustomCommand[] = [];
|
|
831
|
+
for (const serverName of manager.getConnectedServers()) {
|
|
832
|
+
const prompts = manager.getServerPrompts(serverName);
|
|
833
|
+
if (!prompts?.length) continue;
|
|
834
|
+
for (const prompt of prompts) {
|
|
835
|
+
const commandName = `${serverName}:${prompt.name}`;
|
|
836
|
+
commands.push({
|
|
837
|
+
path: `mcp:${commandName}`,
|
|
838
|
+
resolvedPath: `mcp:${commandName}`,
|
|
839
|
+
source: "bundled",
|
|
840
|
+
command: {
|
|
841
|
+
name: commandName,
|
|
842
|
+
description: prompt.description ?? `MCP prompt from ${serverName}`,
|
|
843
|
+
async execute(args: string[]) {
|
|
844
|
+
const promptArgs: Record<string, string> = {};
|
|
845
|
+
for (const arg of args) {
|
|
846
|
+
const eqIdx = arg.indexOf("=");
|
|
847
|
+
if (eqIdx > 0) {
|
|
848
|
+
promptArgs[arg.slice(0, eqIdx)] = arg.slice(eqIdx + 1);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
const result = await manager.executePrompt(serverName, prompt.name, promptArgs);
|
|
852
|
+
if (!result) return "";
|
|
853
|
+
const parts: string[] = [];
|
|
854
|
+
for (const msg of result.messages) {
|
|
855
|
+
const contentItems = Array.isArray(msg.content) ? msg.content : [msg.content];
|
|
856
|
+
for (const item of contentItems) {
|
|
857
|
+
if (item.type === "text") {
|
|
858
|
+
parts.push(item.text);
|
|
859
|
+
} else if (item.type === "resource") {
|
|
860
|
+
const resource = item.resource;
|
|
861
|
+
if (resource.text) parts.push(resource.text);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
return parts.join("\n\n");
|
|
866
|
+
},
|
|
867
|
+
},
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
return commands;
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* Create an AgentSession with the specified options.
|
|
875
|
+
*
|
|
876
|
+
* @example
|
|
877
|
+
* ```typescript
|
|
878
|
+
* // Minimal - uses defaults
|
|
879
|
+
* const { session } = await createAgentSession();
|
|
880
|
+
*
|
|
881
|
+
* // With explicit model
|
|
882
|
+
* import { getModel } from '@prometheus-ai/ai';
|
|
883
|
+
* const { session } = await createAgentSession({
|
|
884
|
+
* model: getModel('anthropic', 'claude-opus-4-5'),
|
|
885
|
+
* thinkingLevel: 'high',
|
|
886
|
+
* });
|
|
887
|
+
*
|
|
888
|
+
* // Continue previous session
|
|
889
|
+
* const { session, modelFallbackMessage } = await createAgentSession({
|
|
890
|
+
* continueSession: true,
|
|
891
|
+
* });
|
|
892
|
+
*
|
|
893
|
+
* // Full control
|
|
894
|
+
* const { session } = await createAgentSession({
|
|
895
|
+
* model: myModel,
|
|
896
|
+
* getApiKey: async () => Bun.env.MY_KEY,
|
|
897
|
+
* systemPrompt: ['You are helpful.'],
|
|
898
|
+
* tools: codingTools({ cwd: getProjectDir() }),
|
|
899
|
+
* skills: [],
|
|
900
|
+
* sessionManager: SessionManager.inMemory(),
|
|
901
|
+
* });
|
|
902
|
+
* ```
|
|
903
|
+
*/
|
|
904
|
+
export async function createAgentSession(options: CreateAgentSessionOptions = {}): Promise<CreateAgentSessionResult> {
|
|
905
|
+
const cwd = options.cwd ?? getProjectDir();
|
|
906
|
+
const agentDir = options.agentDir ?? getDefaultAgentDir();
|
|
907
|
+
const eventBus = options.eventBus ?? new EventBus();
|
|
908
|
+
|
|
909
|
+
registerSshCleanup();
|
|
910
|
+
registerPythonCleanup();
|
|
911
|
+
|
|
912
|
+
// Pin authStorage to modelRegistry.authStorage: ModelRegistry.getApiKey() routes refresh
|
|
913
|
+
// failures through that instance, so any divergent storage handed to the bridge / mcpManager
|
|
914
|
+
// / session would silently miss credential_disabled events.
|
|
915
|
+
const modelRegistry =
|
|
916
|
+
options.modelRegistry ??
|
|
917
|
+
new ModelRegistry(options.authStorage ?? (await logger.time("discoverModels", discoverAuthStorage, agentDir)));
|
|
918
|
+
const authStorage = modelRegistry.authStorage;
|
|
919
|
+
if (options.authStorage && options.authStorage !== authStorage) {
|
|
920
|
+
throw new Error(
|
|
921
|
+
"options.authStorage and options.modelRegistry.authStorage must be the same instance when both are provided",
|
|
922
|
+
);
|
|
923
|
+
}
|
|
924
|
+
// Subscribe before any getApiKey() call so startup model probes can't fire a
|
|
925
|
+
// credential_disabled event past us. An embedder's constructor handler makes the
|
|
926
|
+
// listener set non-empty from construction, which defeats AuthStorage's no-listener
|
|
927
|
+
// buffer — so we can't rely on it to catch startup events for the extension runner.
|
|
928
|
+
const startupCredentialDisabledEvents: CredentialDisabledEvent[] = [];
|
|
929
|
+
let credentialDisabledTarget: ExtensionRunner | undefined;
|
|
930
|
+
const unsubscribeCredentialDisabled: (() => void) | undefined = authStorage.onCredentialDisabled(event => {
|
|
931
|
+
if (credentialDisabledTarget) {
|
|
932
|
+
// Discard return: any handler error is routed through runner.onError listeners.
|
|
933
|
+
void credentialDisabledTarget.emitCredentialDisabled(event);
|
|
934
|
+
} else {
|
|
935
|
+
startupCredentialDisabledEvents.push(event);
|
|
936
|
+
}
|
|
937
|
+
});
|
|
938
|
+
const settings = options.settings ?? (await logger.time("settings", Settings.init, { cwd, agentDir }));
|
|
939
|
+
logger.time("initializeWithSettings", initializeWithSettings, settings);
|
|
940
|
+
if (!options.modelRegistry) {
|
|
941
|
+
modelRegistry.refreshInBackground();
|
|
942
|
+
}
|
|
943
|
+
// Kick off workspace tree discovery early. The native workspace scan returns
|
|
944
|
+
// both the rendered-tree input and the AGENTS.md directory-context index, so
|
|
945
|
+
// startup does not perform a second recursive filesystem search. Subagents
|
|
946
|
+
// inherit the parent's resolved values via options.
|
|
947
|
+
const STARTUP_SCAN_DEADLINE_MS = 5000;
|
|
948
|
+
const workspaceTreePromise: Promise<WorkspaceTree> = options.workspaceTree
|
|
949
|
+
? Promise.resolve(options.workspaceTree)
|
|
950
|
+
: logger.time("buildWorkspaceTree", () => buildWorkspaceTree(cwd, { timeoutMs: STARTUP_SCAN_DEADLINE_MS }));
|
|
951
|
+
workspaceTreePromise.catch(() => {});
|
|
952
|
+
|
|
953
|
+
// Independent discoveries that depend only on cwd/agentDir — kicked off in parallel and awaited
|
|
954
|
+
// at their respective consumer sites. Their work can overlap with model resolution, secret loading,
|
|
955
|
+
// session-context build, tool creation, MCP discovery, and extension discovery.
|
|
956
|
+
const contextFilesPromise = options.contextFiles
|
|
957
|
+
? Promise.resolve(options.contextFiles)
|
|
958
|
+
: logger.time("discoverContextFiles", discoverContextFiles, cwd, agentDir);
|
|
959
|
+
contextFilesPromise.catch(() => {});
|
|
960
|
+
const promptTemplatesPromise = options.promptTemplates
|
|
961
|
+
? Promise.resolve(options.promptTemplates)
|
|
962
|
+
: logger.time("discoverPromptTemplates", discoverPromptTemplates, cwd, agentDir);
|
|
963
|
+
promptTemplatesPromise.catch(() => {});
|
|
964
|
+
const slashCommandsPromise = options.slashCommands
|
|
965
|
+
? Promise.resolve(options.slashCommands)
|
|
966
|
+
: logger.time("discoverSlashCommands", discoverSlashCommands, cwd);
|
|
967
|
+
slashCommandsPromise.catch(() => {});
|
|
968
|
+
const skillsSettings = settings.getGroup("skills");
|
|
969
|
+
const disabledExtensionIds = settings.get("disabledExtensions") ?? [];
|
|
970
|
+
const discoveredSkillsPromise =
|
|
971
|
+
options.skills === undefined
|
|
972
|
+
? logger.time("discoverSkills", discoverSkills, cwd, agentDir, {
|
|
973
|
+
...skillsSettings,
|
|
974
|
+
disabledExtensions: disabledExtensionIds,
|
|
975
|
+
})
|
|
976
|
+
: undefined;
|
|
977
|
+
discoveredSkillsPromise?.catch(() => {});
|
|
978
|
+
|
|
979
|
+
// Initialize provider preferences from settings
|
|
980
|
+
const webSearchProvider = settings.get("providers.webSearch");
|
|
981
|
+
if (typeof webSearchProvider === "string" && isSearchProviderPreference(webSearchProvider)) {
|
|
982
|
+
setPreferredSearchProvider(webSearchProvider);
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
const imageProvider = settings.get("providers.image");
|
|
986
|
+
if (isImageProviderPreference(imageProvider)) {
|
|
987
|
+
setPreferredImageProvider(imageProvider);
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
const sessionManager =
|
|
991
|
+
options.sessionManager ??
|
|
992
|
+
logger.time("sessionManager", () =>
|
|
993
|
+
SessionManager.create(cwd, SessionManager.getDefaultSessionDir(cwd, agentDir)),
|
|
994
|
+
);
|
|
995
|
+
const providerSessionId = options.providerSessionId ?? sessionManager.getSessionId();
|
|
996
|
+
const modelApiKeyAvailability = new Map<string, boolean>();
|
|
997
|
+
const getModelAvailabilityKey = (candidate: Model): string =>
|
|
998
|
+
`${candidate.provider}\u0000${candidate.baseUrl ?? ""}`;
|
|
999
|
+
const hasModelApiKey = async (candidate: Model): Promise<boolean> => {
|
|
1000
|
+
const availabilityKey = getModelAvailabilityKey(candidate);
|
|
1001
|
+
const cached = modelApiKeyAvailability.get(availabilityKey);
|
|
1002
|
+
if (cached !== undefined) {
|
|
1003
|
+
return cached;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
const hasKey = !!(await modelRegistry.getApiKey(candidate, providerSessionId));
|
|
1007
|
+
modelApiKeyAvailability.set(availabilityKey, hasKey);
|
|
1008
|
+
return hasKey;
|
|
1009
|
+
};
|
|
1010
|
+
|
|
1011
|
+
// Load and create secret obfuscator early so resumed session state and prompt warnings
|
|
1012
|
+
// reflect actual loaded secrets, not just the setting toggle.
|
|
1013
|
+
let obfuscator: SecretObfuscator | undefined;
|
|
1014
|
+
if (settings.get("secrets.enabled")) {
|
|
1015
|
+
const fileEntries = await logger.time("loadSecrets", loadSecrets, cwd, agentDir);
|
|
1016
|
+
const envEntries = collectEnvSecrets();
|
|
1017
|
+
const allEntries = [...envEntries, ...fileEntries];
|
|
1018
|
+
if (allEntries.length > 0) {
|
|
1019
|
+
obfuscator = new SecretObfuscator(allEntries);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
const secretsEnabled = obfuscator?.hasSecrets() === true;
|
|
1023
|
+
|
|
1024
|
+
// Check if session has existing data to restore
|
|
1025
|
+
const existingSession = logger.time("loadSessionContext", () =>
|
|
1026
|
+
deobfuscateSessionContext(sessionManager.buildSessionContext(), obfuscator),
|
|
1027
|
+
);
|
|
1028
|
+
const existingBranch = logger.time("getSessionBranch", () => sessionManager.getBranch());
|
|
1029
|
+
const hasExistingSession = existingBranch.length > 0;
|
|
1030
|
+
const hasThinkingEntry = existingBranch.some(entry => entry.type === "thinking_level_change");
|
|
1031
|
+
const hasServiceTierEntry = existingBranch.some(entry => entry.type === "service_tier_change");
|
|
1032
|
+
|
|
1033
|
+
const hasExplicitModel = options.model !== undefined || options.modelPattern !== undefined;
|
|
1034
|
+
const modelMatchPreferences = {
|
|
1035
|
+
usageOrder: settings.getStorage()?.getModelUsageOrder(),
|
|
1036
|
+
};
|
|
1037
|
+
const allowedModels = await logger.time("resolveAllowedModels", () =>
|
|
1038
|
+
resolveAllowedModels(modelRegistry, settings, modelMatchPreferences),
|
|
1039
|
+
);
|
|
1040
|
+
const defaultRoleSpec = logger.time("resolveDefaultModelRole", () =>
|
|
1041
|
+
resolveModelRoleValue(settings.getModelRole("default"), allowedModels, {
|
|
1042
|
+
settings,
|
|
1043
|
+
matchPreferences: modelMatchPreferences,
|
|
1044
|
+
modelRegistry,
|
|
1045
|
+
}),
|
|
1046
|
+
);
|
|
1047
|
+
let model = options.model;
|
|
1048
|
+
let modelFallbackMessage: string | undefined;
|
|
1049
|
+
// Identify session model strings to restore in fallback order. We do an
|
|
1050
|
+
// initial pass here so model-dependent setup (thinking-level resolution,
|
|
1051
|
+
// host preconnect) can use the restored model; extension-registered
|
|
1052
|
+
// providers aren't visible yet, so we retry the preferred candidates once
|
|
1053
|
+
// extensions register below.
|
|
1054
|
+
const sessionModelStrings =
|
|
1055
|
+
!hasExplicitModel && hasExistingSession
|
|
1056
|
+
? getRestorableSessionModels(existingSession.models, sessionManager.getLastModelChangeRole())
|
|
1057
|
+
: [];
|
|
1058
|
+
let restoredSessionModelIndex = -1;
|
|
1059
|
+
if (!hasExplicitModel && !model && sessionModelStrings.length > 0) {
|
|
1060
|
+
await logger.time("restoreSessionModel", async () => {
|
|
1061
|
+
let failedSessionModel: string | undefined;
|
|
1062
|
+
for (let i = 0; i < sessionModelStrings.length; i++) {
|
|
1063
|
+
const sessionModelStr = sessionModelStrings[i];
|
|
1064
|
+
const parsedModel = parseModelString(sessionModelStr);
|
|
1065
|
+
if (!parsedModel) {
|
|
1066
|
+
failedSessionModel ??= sessionModelStr;
|
|
1067
|
+
continue;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
const restoredModel = modelRegistry.find(parsedModel.provider, parsedModel.id);
|
|
1071
|
+
if (restoredModel && (await hasModelApiKey(restoredModel))) {
|
|
1072
|
+
model = restoredModel;
|
|
1073
|
+
restoredSessionModelIndex = i;
|
|
1074
|
+
break;
|
|
1075
|
+
}
|
|
1076
|
+
failedSessionModel ??= sessionModelStr;
|
|
1077
|
+
}
|
|
1078
|
+
if (failedSessionModel) {
|
|
1079
|
+
modelFallbackMessage = `Could not restore model ${failedSessionModel}`;
|
|
1080
|
+
}
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
// If still no model, try settings default.
|
|
1085
|
+
// Skip settings fallback when an explicit model was requested.
|
|
1086
|
+
if (!hasExplicitModel && !model && defaultRoleSpec.model) {
|
|
1087
|
+
const settingsDefaultModel = defaultRoleSpec.model;
|
|
1088
|
+
logger.time("resolveSettingsDefaultModel", () => {
|
|
1089
|
+
// defaultRoleSpec.model already comes from modelRegistry.getAvailable(),
|
|
1090
|
+
// so re-validating auth here just repeats the expensive lookup path.
|
|
1091
|
+
model = settingsDefaultModel;
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
const taskDepth = options.taskDepth ?? 0;
|
|
1096
|
+
|
|
1097
|
+
// Resolves the session/agent thinking level using the same precedence we
|
|
1098
|
+
// apply at startup: explicit option → persisted session entry → default
|
|
1099
|
+
// role's explicit selector → selected model's defaultLevel → global
|
|
1100
|
+
// settings default. Run again after extension role reclaim so the final
|
|
1101
|
+
// model's own defaults aren't masked by an earlier fallback model's.
|
|
1102
|
+
const pickInitialThinkingLevel = (selectedModel: Model | undefined): ConfiguredThinkingLevel | undefined => {
|
|
1103
|
+
let level = options.thinkingLevel;
|
|
1104
|
+
if (level === undefined && hasExistingSession && hasThinkingEntry) {
|
|
1105
|
+
level = parseThinkingLevel(existingSession.thinkingLevel);
|
|
1106
|
+
}
|
|
1107
|
+
if (level === undefined && !hasExplicitModel && !hasThinkingEntry && defaultRoleSpec.explicitThinkingLevel) {
|
|
1108
|
+
level = defaultRoleSpec.thinkingLevel;
|
|
1109
|
+
}
|
|
1110
|
+
if (level === undefined && selectedModel?.thinking?.defaultLevel !== undefined) {
|
|
1111
|
+
level = selectedModel.thinking.defaultLevel;
|
|
1112
|
+
}
|
|
1113
|
+
if (level === undefined) {
|
|
1114
|
+
level = settings.get("defaultThinkingLevel");
|
|
1115
|
+
}
|
|
1116
|
+
return level;
|
|
1117
|
+
};
|
|
1118
|
+
let thinkingLevel = pickInitialThinkingLevel(model);
|
|
1119
|
+
let autoThinking = thinkingLevel === AUTO_THINKING;
|
|
1120
|
+
// Concrete level the agent/session start with. With `auto` this is the
|
|
1121
|
+
// provisional level shown until the first per-turn classification resolves;
|
|
1122
|
+
// `auto` itself stays a session-only concept handled by AgentSession.
|
|
1123
|
+
let effectiveThinkingLevel: ThinkingLevel | undefined = thinkingLevel === AUTO_THINKING ? undefined : thinkingLevel;
|
|
1124
|
+
if (model) {
|
|
1125
|
+
const resolvedModel = model;
|
|
1126
|
+
effectiveThinkingLevel = logger.time("resolveThinkingLevelForModel", () =>
|
|
1127
|
+
autoThinking
|
|
1128
|
+
? resolveProvisionalAutoLevel(resolvedModel)
|
|
1129
|
+
: resolveThinkingLevelForModel(resolvedModel, effectiveThinkingLevel),
|
|
1130
|
+
);
|
|
1131
|
+
// Fire-and-forget TLS+H2 handshake to the model's host so it overlaps
|
|
1132
|
+
// with the rest of session setup (extension/skill load, tool registry,
|
|
1133
|
+
// system prompt build). Without this, the first `fetch(...)` pays the
|
|
1134
|
+
// full handshake serially — 100–300 ms transcontinental for
|
|
1135
|
+
// api.anthropic.com from a residential IP. Every mode benefits
|
|
1136
|
+
// (interactive, print, rpc, acp).
|
|
1137
|
+
preconnectModelHost(model.baseUrl);
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
let skills: Skill[];
|
|
1141
|
+
let skillWarnings: SkillWarning[];
|
|
1142
|
+
if (options.skills !== undefined) {
|
|
1143
|
+
skills = options.skills;
|
|
1144
|
+
skillWarnings = [];
|
|
1145
|
+
} else {
|
|
1146
|
+
const discovered = await (discoveredSkillsPromise ?? Promise.resolve({ skills: [], warnings: [] }));
|
|
1147
|
+
skills = discovered.skills;
|
|
1148
|
+
skillWarnings = discovered.warnings;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
// Discover rules and bucket them in one pass to avoid repeated scans over large rule sets.
|
|
1152
|
+
const { ttsrManager, rulebookRules, alwaysApplyRules } = await logger.time("discoverTtsrRules", async () => {
|
|
1153
|
+
const ttsrSettings = settings.getGroup("ttsr");
|
|
1154
|
+
const ttsrManager = new TtsrManager(ttsrSettings);
|
|
1155
|
+
const rulesResult =
|
|
1156
|
+
options.rules !== undefined
|
|
1157
|
+
? { items: options.rules, warnings: undefined }
|
|
1158
|
+
: await loadCapability<Rule>(ruleCapability.id, { cwd });
|
|
1159
|
+
const { rulebookRules, alwaysApplyRules } = bucketRules(rulesResult.items, ttsrManager, {
|
|
1160
|
+
builtinRules: ttsrSettings.builtinRules,
|
|
1161
|
+
disabledRules: ttsrSettings.disabledRules,
|
|
1162
|
+
});
|
|
1163
|
+
if (existingSession.injectedTtsrRules.length > 0) {
|
|
1164
|
+
ttsrManager.restoreInjected(existingSession.injectedTtsrRules);
|
|
1165
|
+
}
|
|
1166
|
+
return { ttsrManager, rulebookRules, alwaysApplyRules };
|
|
1167
|
+
});
|
|
1168
|
+
|
|
1169
|
+
// Resolve contextFiles up-front (it's needed before tool creation). The
|
|
1170
|
+
// workspace tree scan is slow on large repos and we MUST NOT block startup on
|
|
1171
|
+
// it. On timeout we forward `undefined` to ToolSession; buildSystemPromptInternal
|
|
1172
|
+
// will re-race the same promise through its own withDeadline path. Background
|
|
1173
|
+
// work continues so caches still warm.
|
|
1174
|
+
const raceWithDeadline = async <T>(name: string, work: Promise<T>): Promise<T | undefined> => {
|
|
1175
|
+
let timedOut = false;
|
|
1176
|
+
const result = await Promise.race([
|
|
1177
|
+
work,
|
|
1178
|
+
Bun.sleep(STARTUP_SCAN_DEADLINE_MS).then(() => {
|
|
1179
|
+
timedOut = true;
|
|
1180
|
+
return undefined;
|
|
1181
|
+
}),
|
|
1182
|
+
]);
|
|
1183
|
+
if (timedOut) {
|
|
1184
|
+
logger.warn("Startup scan exceeded deadline; deferring to system prompt fallback", {
|
|
1185
|
+
name,
|
|
1186
|
+
timeoutMs: STARTUP_SCAN_DEADLINE_MS,
|
|
1187
|
+
cwd,
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
return result;
|
|
1191
|
+
};
|
|
1192
|
+
const [contextFiles, resolvedWorkspaceTree] = await Promise.all([
|
|
1193
|
+
contextFilesPromise,
|
|
1194
|
+
raceWithDeadline("buildWorkspaceTree", workspaceTreePromise),
|
|
1195
|
+
]);
|
|
1196
|
+
|
|
1197
|
+
let agent: Agent;
|
|
1198
|
+
let session!: AgentSession;
|
|
1199
|
+
let hasSession = false;
|
|
1200
|
+
let hasRegistered = false;
|
|
1201
|
+
const enableLsp = options.enableLsp ?? true;
|
|
1202
|
+
const backgroundJobsEnabled = isBackgroundJobSupportEnabled(settings);
|
|
1203
|
+
const asyncMaxJobs = Math.min(100, Math.max(1, settings.get("async.maxJobs") ?? 100));
|
|
1204
|
+
const ASYNC_INLINE_RESULT_MAX_CHARS = 12_000;
|
|
1205
|
+
const ASYNC_PREVIEW_MAX_CHARS = 4_000;
|
|
1206
|
+
const formatAsyncResultForFollowUp = async (result: string): Promise<string> => {
|
|
1207
|
+
if (result.length <= ASYNC_INLINE_RESULT_MAX_CHARS) {
|
|
1208
|
+
return result;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
const preview = `${result.slice(0, ASYNC_PREVIEW_MAX_CHARS)}\n\n[Output truncated. Showing first ${ASYNC_PREVIEW_MAX_CHARS.toLocaleString()} characters.]`;
|
|
1212
|
+
try {
|
|
1213
|
+
const { path: artifactPath, id: artifactId } = await sessionManager.allocateArtifactPath("async");
|
|
1214
|
+
if (artifactPath && artifactId) {
|
|
1215
|
+
await Bun.write(artifactPath, result);
|
|
1216
|
+
return `${preview}\nFull output: artifact://${artifactId}`;
|
|
1217
|
+
}
|
|
1218
|
+
} catch (error) {
|
|
1219
|
+
logger.warn("Failed to persist async follow-up artifact", {
|
|
1220
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
return preview;
|
|
1225
|
+
};
|
|
1226
|
+
// Only the first top-level session in a process owns an AsyncJobManager.
|
|
1227
|
+
// Subagents inherit the parent's manager via `AsyncJobManager.instance()`
|
|
1228
|
+
// (set below), and any additional top-level session spun up in-process
|
|
1229
|
+
// (e.g. the agent-creation architect in `agent-dashboard.ts`) must share
|
|
1230
|
+
// the live singleton — otherwise its dispose path would clobber the
|
|
1231
|
+
// owning session's manager and break the `task`/`bash` async paths
|
|
1232
|
+
// (issue #1923). The `instance()` guard means later sessions also skip
|
|
1233
|
+
// constructing an orphaned manager that nothing would ever route to.
|
|
1234
|
+
const asyncJobManager =
|
|
1235
|
+
backgroundJobsEnabled && !options.parentTaskPrefix && !AsyncJobManager.instance()
|
|
1236
|
+
? new AsyncJobManager({
|
|
1237
|
+
maxRunningJobs: asyncMaxJobs,
|
|
1238
|
+
onJobComplete: async (jobId, result, job) => {
|
|
1239
|
+
if (!session || asyncJobManager!.isDeliverySuppressed(jobId)) return;
|
|
1240
|
+
const formattedResult = await formatAsyncResultForFollowUp(result);
|
|
1241
|
+
if (asyncJobManager!.isDeliverySuppressed(jobId)) return;
|
|
1242
|
+
|
|
1243
|
+
const durationMs = job ? Math.max(0, Date.now() - job.startTime) : undefined;
|
|
1244
|
+
session.yieldQueue.enqueue<AsyncResultEntry>("async-result", {
|
|
1245
|
+
jobId,
|
|
1246
|
+
result: formattedResult,
|
|
1247
|
+
job,
|
|
1248
|
+
durationMs,
|
|
1249
|
+
});
|
|
1250
|
+
},
|
|
1251
|
+
})
|
|
1252
|
+
: undefined;
|
|
1253
|
+
|
|
1254
|
+
const scopedAsyncJobManager = asyncJobManager ?? (options.parentTaskPrefix ? AsyncJobManager.instance() : undefined);
|
|
1255
|
+
|
|
1256
|
+
const agentRegistry = options.agentRegistry ?? AgentRegistry.global();
|
|
1257
|
+
const resolvedAgentId = options.agentId ?? options.parentTaskPrefix ?? MAIN_AGENT_ID;
|
|
1258
|
+
const resolvedAgentDisplayName =
|
|
1259
|
+
options.agentDisplayName ?? ((options.taskDepth ?? 0) > 0 || options.parentTaskPrefix ? "sub" : "main");
|
|
1260
|
+
const evalKernelOwnerId = `agent-session:${Snowflake.next()}`;
|
|
1261
|
+
|
|
1262
|
+
try {
|
|
1263
|
+
const getActiveModelString = (): string | undefined => {
|
|
1264
|
+
const activeModel = agent?.state.model;
|
|
1265
|
+
if (activeModel) return formatModelString(activeModel);
|
|
1266
|
+
if (model) return formatModelString(model);
|
|
1267
|
+
return undefined;
|
|
1268
|
+
};
|
|
1269
|
+
const toolSession: ToolSession = {
|
|
1270
|
+
get cwd() {
|
|
1271
|
+
return sessionManager.getCwd();
|
|
1272
|
+
},
|
|
1273
|
+
hasUI: options.hasUI ?? false,
|
|
1274
|
+
enableLsp,
|
|
1275
|
+
get hasEditTool() {
|
|
1276
|
+
const requestedToolNames = options.toolNames
|
|
1277
|
+
? [...new Set(options.toolNames.map(name => name.toLowerCase()))]
|
|
1278
|
+
: undefined;
|
|
1279
|
+
return !requestedToolNames || requestedToolNames.includes("edit");
|
|
1280
|
+
},
|
|
1281
|
+
skipPythonPreflight: options.skipPythonPreflight,
|
|
1282
|
+
contextFiles,
|
|
1283
|
+
workspaceTree: resolvedWorkspaceTree,
|
|
1284
|
+
skills,
|
|
1285
|
+
eventBus,
|
|
1286
|
+
outputSchema: options.outputSchema,
|
|
1287
|
+
requireYieldTool: options.requireYieldTool,
|
|
1288
|
+
taskDepth: options.taskDepth ?? 0,
|
|
1289
|
+
getSessionFile: () => sessionManager.getSessionFile() ?? null,
|
|
1290
|
+
getEvalKernelOwnerId: () => evalKernelOwnerId,
|
|
1291
|
+
getEvalSessionId: () =>
|
|
1292
|
+
session?.getEvalSessionId() ?? options.parentEvalSessionId ?? defaultEvalSessionId(toolSession),
|
|
1293
|
+
assertEvalExecutionAllowed: () => session?.assertEvalExecutionAllowed(),
|
|
1294
|
+
trackEvalExecution: (execution, abortController) =>
|
|
1295
|
+
session ? session.trackEvalExecution(execution, abortController) : execution,
|
|
1296
|
+
getSessionId: () => sessionManager.getSessionId?.() ?? null,
|
|
1297
|
+
getHindsightSessionState: () => session?.getHindsightSessionState(),
|
|
1298
|
+
getMnemopiSessionState: () => getMnemopiSessionState(session),
|
|
1299
|
+
getAgentId: () => resolvedAgentId,
|
|
1300
|
+
getToolByName: name => session?.getToolByName(name),
|
|
1301
|
+
agentRegistry,
|
|
1302
|
+
getSessionSpawns: () => options.spawns ?? "*",
|
|
1303
|
+
getModelString: () => (hasExplicitModel && model ? formatModelString(model) : undefined),
|
|
1304
|
+
getActiveModelString,
|
|
1305
|
+
getPlanModeState: () => session?.getPlanModeState(),
|
|
1306
|
+
getPlanReferencePath: () => session?.getPlanReferencePath() ?? "local://PLAN.md",
|
|
1307
|
+
getGoalModeState: () => session?.getGoalModeState(),
|
|
1308
|
+
getGoalRuntime: () => session?.goalRuntime,
|
|
1309
|
+
getUsageStatistics: () => sessionManager.getUsageStatistics(),
|
|
1310
|
+
getTurnBudget: () => sessionManager.getTurnBudget(),
|
|
1311
|
+
recordEvalSubagentUsage: output => sessionManager.recordEvalSubagentOutput(output),
|
|
1312
|
+
getClientBridge: () => session?.clientBridge,
|
|
1313
|
+
getCompactContext: () => session.formatCompactContext(),
|
|
1314
|
+
getTodoPhases: () => session.getTodoPhases(),
|
|
1315
|
+
setTodoPhases: phases => session.setTodoPhases(phases),
|
|
1316
|
+
isMCPDiscoveryEnabled: () => session.isMCPDiscoveryEnabled(),
|
|
1317
|
+
getSelectedMCPToolNames: () => session.getSelectedMCPToolNames(),
|
|
1318
|
+
activateDiscoveredMCPTools: toolNames => session.activateDiscoveredMCPTools(toolNames),
|
|
1319
|
+
// Generic tool discovery (unified — covers built-in + MCP + extension)
|
|
1320
|
+
isToolDiscoveryEnabled: () => session.isToolDiscoveryEnabled(),
|
|
1321
|
+
getDiscoverableTools: filter => session.getDiscoverableTools(filter),
|
|
1322
|
+
getDiscoverableToolSearchIndex: () => session.getDiscoverableToolSearchIndex(),
|
|
1323
|
+
getSelectedDiscoveredToolNames: () => session.getSelectedDiscoveredToolNames(),
|
|
1324
|
+
activateDiscoveredTools: toolNames => session.activateDiscoveredTools(toolNames),
|
|
1325
|
+
getCheckpointState: () => session.getCheckpointState(),
|
|
1326
|
+
setCheckpointState: state => session.setCheckpointState(state ?? undefined),
|
|
1327
|
+
getToolChoiceQueue: () => session.toolChoiceQueue,
|
|
1328
|
+
buildToolChoice: name => {
|
|
1329
|
+
const m = session.model;
|
|
1330
|
+
return m ? buildNamedToolChoice(name, m) : undefined;
|
|
1331
|
+
},
|
|
1332
|
+
steer: msg =>
|
|
1333
|
+
session.agent.steer({
|
|
1334
|
+
role: "custom",
|
|
1335
|
+
customType: msg.customType,
|
|
1336
|
+
content: msg.content,
|
|
1337
|
+
display: false,
|
|
1338
|
+
details: msg.details,
|
|
1339
|
+
attribution: "agent",
|
|
1340
|
+
timestamp: Date.now(),
|
|
1341
|
+
}),
|
|
1342
|
+
peekQueueInvoker: () => session.peekQueueInvoker(),
|
|
1343
|
+
peekStandingResolveHandler: () => session.peekStandingResolveHandler(),
|
|
1344
|
+
setStandingResolveHandler: handler => session.setStandingResolveHandler(handler),
|
|
1345
|
+
allocateOutputArtifact: async toolType => {
|
|
1346
|
+
try {
|
|
1347
|
+
return await sessionManager.allocateArtifactPath(toolType);
|
|
1348
|
+
} catch {
|
|
1349
|
+
return {};
|
|
1350
|
+
}
|
|
1351
|
+
},
|
|
1352
|
+
getArtifactManager: () => sessionManager.getArtifactManager(),
|
|
1353
|
+
settings,
|
|
1354
|
+
authStorage,
|
|
1355
|
+
modelRegistry,
|
|
1356
|
+
getTelemetry: () => agent?.telemetry,
|
|
1357
|
+
// Subagents inherit the singleton (the parent's manager) so their bash/task
|
|
1358
|
+
// completions still flow into the spawning conversation's yieldQueue.
|
|
1359
|
+
// Secondary in-process top-level sessions (no parentTaskPrefix, no
|
|
1360
|
+
// constructed manager because the singleton was already installed) leave
|
|
1361
|
+
// this undefined so tools and session job snapshots refuse async work
|
|
1362
|
+
// instead of silently routing into the owning session (issue #1923).
|
|
1363
|
+
asyncJobManager: scopedAsyncJobManager,
|
|
1364
|
+
};
|
|
1365
|
+
|
|
1366
|
+
// Wire process-wide internal URL singletons owned by their real classes.
|
|
1367
|
+
// Top-level sessions install the active snapshots; subagents inherit them.
|
|
1368
|
+
// Artifact and agent-output URLs resolve via `AgentRegistry.global()` —
|
|
1369
|
+
// the protocol handlers walk each ref's `sessionManager.getArtifactsDir()`,
|
|
1370
|
+
// which collapses to the parent's dir for subagents (they adopt the
|
|
1371
|
+
// parent's ArtifactManager) so one lookup hits everything.
|
|
1372
|
+
const getArtifactsDir = () => sessionManager.getArtifactsDir();
|
|
1373
|
+
if (!options.parentTaskPrefix) {
|
|
1374
|
+
setActiveSkills(skills);
|
|
1375
|
+
setActiveRules([...rulebookRules, ...alwaysApplyRules]);
|
|
1376
|
+
if (asyncJobManager) AsyncJobManager.setInstance(asyncJobManager);
|
|
1377
|
+
}
|
|
1378
|
+
const localProtocolOptions = options.localProtocolOptions ?? {
|
|
1379
|
+
getArtifactsDir,
|
|
1380
|
+
getSessionId: () => sessionManager.getSessionId?.() ?? null,
|
|
1381
|
+
};
|
|
1382
|
+
if (options.localProtocolOptions) {
|
|
1383
|
+
LocalProtocolHandler.setOverride(options.localProtocolOptions);
|
|
1384
|
+
}
|
|
1385
|
+
toolSession.getArtifactsDir = getArtifactsDir;
|
|
1386
|
+
toolSession.localProtocolOptions = localProtocolOptions;
|
|
1387
|
+
toolSession.agentOutputManager = new AgentOutputManager(
|
|
1388
|
+
getArtifactsDir,
|
|
1389
|
+
options.parentTaskPrefix ? { parentPrefix: options.parentTaskPrefix } : undefined,
|
|
1390
|
+
);
|
|
1391
|
+
|
|
1392
|
+
// Create built-in tools (already wrapped with meta notice formatting)
|
|
1393
|
+
const builtinTools = await logger.time("createAllTools", createTools, toolSession, options.toolNames);
|
|
1394
|
+
|
|
1395
|
+
// Discover MCP tools from .mcp.json files
|
|
1396
|
+
let mcpManager: MCPManager | undefined = options.mcpManager;
|
|
1397
|
+
toolSession.mcpManager = mcpManager;
|
|
1398
|
+
const enableMCP = options.enableMCP ?? true;
|
|
1399
|
+
const customTools: CustomTool[] = [];
|
|
1400
|
+
if (enableMCP && !mcpManager) {
|
|
1401
|
+
const mcpResult = await logger.time("discoverAndLoadMCPTools", discoverAndLoadMCPTools, cwd, {
|
|
1402
|
+
onConnecting: serverNames => {
|
|
1403
|
+
if (options.hasUI && serverNames.length > 0) {
|
|
1404
|
+
process.stderr.write(`${chalk.gray(`Connecting to MCP servers: ${serverNames.join(", ")}…`)}\n`);
|
|
1405
|
+
}
|
|
1406
|
+
},
|
|
1407
|
+
enableProjectConfig: settings.get("mcp.enableProjectConfig") ?? true,
|
|
1408
|
+
// Always filter Exa - we have native integration
|
|
1409
|
+
filterExa: true,
|
|
1410
|
+
// Filter browser MCP servers when builtin browser tool is active
|
|
1411
|
+
filterBrowser: settings.get("browser.enabled") ?? false,
|
|
1412
|
+
cacheStorage: settings.getStorage(),
|
|
1413
|
+
authStorage,
|
|
1414
|
+
});
|
|
1415
|
+
mcpManager = mcpResult.manager;
|
|
1416
|
+
toolSession.mcpManager = mcpManager;
|
|
1417
|
+
|
|
1418
|
+
if (settings.get("mcp.notifications")) {
|
|
1419
|
+
mcpManager.setNotificationsEnabled(true);
|
|
1420
|
+
}
|
|
1421
|
+
// If we extracted Exa API keys from MCP configs and EXA_API_KEY isn't set, use the first one
|
|
1422
|
+
if (mcpResult.exaApiKeys.length > 0 && !$env.EXA_API_KEY) {
|
|
1423
|
+
Bun.env.EXA_API_KEY = mcpResult.exaApiKeys[0];
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
// Log MCP errors
|
|
1427
|
+
for (const { path, error } of mcpResult.errors) {
|
|
1428
|
+
logger.error("MCP tool load failed", { path, error });
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
if (mcpResult.tools.length > 0) {
|
|
1432
|
+
// MCP tools are LoadedCustomTool, extract the tool property
|
|
1433
|
+
customTools.push(...mcpResult.tools.map(loaded => loaded.tool));
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
// Only top-level sessions own the global MCPManager. Subagents already
|
|
1437
|
+
// receive the parent's manager via `options.mcpManager`, and reassigning
|
|
1438
|
+
// the singleton to the same value is a no-op \u2014 keep the gate explicit
|
|
1439
|
+
// to mirror the AsyncJobManager ownership rule.
|
|
1440
|
+
if (mcpManager && !options.parentTaskPrefix) MCPManager.setInstance(mcpManager);
|
|
1441
|
+
|
|
1442
|
+
// Add image tools when the active model or configured image providers can generate images.
|
|
1443
|
+
const imageGenTools = await logger.time("getImageGenTools", () => getImageGenTools(modelRegistry, model));
|
|
1444
|
+
if (imageGenTools.length > 0) {
|
|
1445
|
+
customTools.push(...(imageGenTools as unknown as CustomTool[]));
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
if (settings.get("tts.enabled")) {
|
|
1449
|
+
customTools.push(ttsTool as unknown as CustomTool);
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
// Add web search tools
|
|
1453
|
+
if (options.toolNames?.includes("web_search")) {
|
|
1454
|
+
customTools.push(...getSearchTools());
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
// Discover and load custom tools from .prometheus/tools/, .claude/tools/, etc.
|
|
1458
|
+
const builtInToolNames = builtinTools.map(t => t.name);
|
|
1459
|
+
const discoveredCustomTools = await logger.time(
|
|
1460
|
+
"discoverAndLoadCustomTools",
|
|
1461
|
+
discoverAndLoadCustomTools,
|
|
1462
|
+
[],
|
|
1463
|
+
cwd,
|
|
1464
|
+
builtInToolNames,
|
|
1465
|
+
action => queueResolveHandler(toolSession, action),
|
|
1466
|
+
);
|
|
1467
|
+
for (const { path, error } of discoveredCustomTools.errors) {
|
|
1468
|
+
logger.error("Custom tool load failed", { path, error });
|
|
1469
|
+
}
|
|
1470
|
+
if (discoveredCustomTools.tools.length > 0) {
|
|
1471
|
+
customTools.push(...discoveredCustomTools.tools.map(loaded => loaded.tool));
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
const inlineExtensions: ExtensionFactory[] = options.extensions ? [...options.extensions] : [];
|
|
1475
|
+
inlineExtensions.push(createAutoresearchExtension);
|
|
1476
|
+
if (customTools.length > 0) {
|
|
1477
|
+
inlineExtensions.push(createCustomToolsExtension(customTools));
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
// Load extensions. A preloaded result (e.g. resolved by the CLI before
|
|
1481
|
+
// session creation so it can classify `@file` args extension-aware without
|
|
1482
|
+
// a session/breadcrumb existing yet) is reused as-is; otherwise discover now
|
|
1483
|
+
// through the shared helper. Preloaded wins over `disableExtensionDiscovery`
|
|
1484
|
+
// because the preloaded result already reflects that choice — re-running the
|
|
1485
|
+
// loader here would double-load.
|
|
1486
|
+
const extensionsResult: LoadExtensionsResult =
|
|
1487
|
+
options.preloadedExtensions ?? (await loadSessionExtensions(options, cwd, settings, eventBus));
|
|
1488
|
+
|
|
1489
|
+
// Load inline extensions from factories
|
|
1490
|
+
if (inlineExtensions.length > 0) {
|
|
1491
|
+
for (let i = 0; i < inlineExtensions.length; i++) {
|
|
1492
|
+
const factory = inlineExtensions[i];
|
|
1493
|
+
const loaded = await loadExtensionFromFactory(
|
|
1494
|
+
factory,
|
|
1495
|
+
cwd,
|
|
1496
|
+
eventBus,
|
|
1497
|
+
extensionsResult.runtime,
|
|
1498
|
+
`<inline-${i}>`,
|
|
1499
|
+
);
|
|
1500
|
+
extensionsResult.extensions.push(loaded);
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
// Process provider registrations queued during extension loading.
|
|
1505
|
+
// This must happen before the runner is created so that models registered by
|
|
1506
|
+
// extensions are available for model selection on session resume / fallback.
|
|
1507
|
+
const activeExtensionSources = extensionsResult.extensions.map(extension => extension.path);
|
|
1508
|
+
modelRegistry.syncExtensionSources(activeExtensionSources);
|
|
1509
|
+
for (const sourceId of new Set(activeExtensionSources)) {
|
|
1510
|
+
modelRegistry.clearSourceRegistrations(sourceId);
|
|
1511
|
+
}
|
|
1512
|
+
if (extensionsResult.runtime.pendingProviderRegistrations.length > 0) {
|
|
1513
|
+
for (const { name, config, sourceId } of extensionsResult.runtime.pendingProviderRegistrations) {
|
|
1514
|
+
modelRegistry.registerProvider(name, config, sourceId);
|
|
1515
|
+
}
|
|
1516
|
+
extensionsResult.runtime.pendingProviderRegistrations = [];
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
// Retry session-model candidates now that extension providers are
|
|
1520
|
+
// registered. The initial restore runs before extensions load, so a role
|
|
1521
|
+
// model supplied by an extension would have either fallen back to the
|
|
1522
|
+
// saved default (`restoredSessionModelIndex > 0`) or failed entirely
|
|
1523
|
+
// (`restoredSessionModelIndex === -1`, with the settings default or
|
|
1524
|
+
// downstream fallback filling `model`). Reclaim it here so resume
|
|
1525
|
+
// honors the last active role in either case.
|
|
1526
|
+
const sessionRetryLimit = restoredSessionModelIndex >= 0 ? restoredSessionModelIndex : sessionModelStrings.length;
|
|
1527
|
+
if (!hasExplicitModel && sessionRetryLimit > 0) {
|
|
1528
|
+
for (let i = 0; i < sessionRetryLimit; i++) {
|
|
1529
|
+
const sessionModelStr = sessionModelStrings[i];
|
|
1530
|
+
const parsedModel = parseModelString(sessionModelStr);
|
|
1531
|
+
if (!parsedModel) continue;
|
|
1532
|
+
const restoredModel = modelRegistry.find(parsedModel.provider, parsedModel.id);
|
|
1533
|
+
if (restoredModel && (await hasModelApiKey(restoredModel))) {
|
|
1534
|
+
model = restoredModel;
|
|
1535
|
+
modelFallbackMessage = undefined;
|
|
1536
|
+
restoredSessionModelIndex = i;
|
|
1537
|
+
// Recompute thinking-level from scratch against the reclaimed
|
|
1538
|
+
// model: any value derived from the earlier fallback model's
|
|
1539
|
+
// `thinking.defaultLevel` must not become sticky.
|
|
1540
|
+
thinkingLevel = pickInitialThinkingLevel(restoredModel);
|
|
1541
|
+
autoThinking = thinkingLevel === AUTO_THINKING;
|
|
1542
|
+
effectiveThinkingLevel = thinkingLevel === AUTO_THINKING ? undefined : thinkingLevel;
|
|
1543
|
+
effectiveThinkingLevel = logger.time("resolveThinkingLevelForModel", () =>
|
|
1544
|
+
autoThinking
|
|
1545
|
+
? resolveProvisionalAutoLevel(restoredModel)
|
|
1546
|
+
: resolveThinkingLevelForModel(restoredModel, effectiveThinkingLevel),
|
|
1547
|
+
);
|
|
1548
|
+
preconnectModelHost(restoredModel.baseUrl);
|
|
1549
|
+
break;
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
// Resolve deferred --model pattern now that extension models are registered.
|
|
1554
|
+
if (!model && options.modelPattern) {
|
|
1555
|
+
const availableModels = modelRegistry.getAll();
|
|
1556
|
+
const matchPreferences = {
|
|
1557
|
+
usageOrder: settings.getStorage()?.getModelUsageOrder(),
|
|
1558
|
+
};
|
|
1559
|
+
const { model: resolved } = parseModelPattern(options.modelPattern, availableModels, matchPreferences, {
|
|
1560
|
+
modelRegistry,
|
|
1561
|
+
});
|
|
1562
|
+
if (resolved) {
|
|
1563
|
+
model = resolved;
|
|
1564
|
+
modelFallbackMessage = undefined;
|
|
1565
|
+
} else {
|
|
1566
|
+
modelFallbackMessage = `Model "${options.modelPattern}" not found`;
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
// Fall back to first available model with a valid API key, honoring the
|
|
1571
|
+
// path-scoped `enabledModels` allow-list when configured. Skip when the
|
|
1572
|
+
// user explicitly requested a model via --model that wasn't found.
|
|
1573
|
+
if (!model && !options.modelPattern) {
|
|
1574
|
+
// Re-resolve the allowed set: extension factories above may have
|
|
1575
|
+
// registered providers/models that weren't visible at startup.
|
|
1576
|
+
const fallbackCandidates = await resolveAllowedModels(modelRegistry, settings, modelMatchPreferences);
|
|
1577
|
+
for (const candidate of fallbackCandidates) {
|
|
1578
|
+
if (await hasModelApiKey(candidate)) {
|
|
1579
|
+
model = candidate;
|
|
1580
|
+
break;
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
if (model) {
|
|
1584
|
+
if (modelFallbackMessage) {
|
|
1585
|
+
modelFallbackMessage += `. Using ${model.provider}/${model.id}`;
|
|
1586
|
+
}
|
|
1587
|
+
} else {
|
|
1588
|
+
const patterns = settings.get("enabledModels");
|
|
1589
|
+
modelFallbackMessage =
|
|
1590
|
+
patterns && patterns.length > 0
|
|
1591
|
+
? `No model available matching enabledModels (${patterns.join(", ")}) with usable credentials. Configure auth for an allowed provider or adjust enabledModels.`
|
|
1592
|
+
: "No models available. Use /login or set an API key environment variable. Then use /model to select a model.";
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
// Discover custom commands (TypeScript slash commands)
|
|
1597
|
+
const customCommandsResult: CustomCommandsLoadResult = options.disableExtensionDiscovery
|
|
1598
|
+
? { commands: [], errors: [] }
|
|
1599
|
+
: await logger.time("discoverCustomCommands", loadCustomCommandsInternal, { cwd, agentDir });
|
|
1600
|
+
if (!options.disableExtensionDiscovery) {
|
|
1601
|
+
for (const { path, error } of customCommandsResult.errors) {
|
|
1602
|
+
logger.error("Failed to load custom command", { path, error });
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
// The runner is created unconditionally — even with zero extensions loaded — because the
|
|
1607
|
+
// `ExtensionToolWrapper` installed below is the only place the per-tool approval gate runs.
|
|
1608
|
+
// A conditional runner means the approval system silently disappears for users with no
|
|
1609
|
+
// extensions, contradicting non-yolo `tools.approvalMode` settings without feedback.
|
|
1610
|
+
// (Today `createAutoresearchExtension` is unconditionally pushed below, so this scenario
|
|
1611
|
+
// is unreachable; the unconditional construction makes that invariant explicit instead of
|
|
1612
|
+
// implicit, so a future change to make autoresearch optional cannot silently re-open the hole.)
|
|
1613
|
+
const extensionRunner: ExtensionRunner = new ExtensionRunner(
|
|
1614
|
+
extensionsResult.extensions,
|
|
1615
|
+
extensionsResult.runtime,
|
|
1616
|
+
cwd,
|
|
1617
|
+
sessionManager,
|
|
1618
|
+
modelRegistry,
|
|
1619
|
+
);
|
|
1620
|
+
|
|
1621
|
+
credentialDisabledTarget = extensionRunner;
|
|
1622
|
+
for (const event of startupCredentialDisabledEvents.splice(0)) {
|
|
1623
|
+
// Discard return: any handler error is routed through runner.onError listeners.
|
|
1624
|
+
void extensionRunner.emitCredentialDisabled(event);
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
const getSessionContext = () => ({
|
|
1628
|
+
sessionManager,
|
|
1629
|
+
modelRegistry,
|
|
1630
|
+
model: agent.state.model,
|
|
1631
|
+
isIdle: () => !session.isStreaming,
|
|
1632
|
+
hasQueuedMessages: () => session.queuedMessageCount > 0,
|
|
1633
|
+
abort: () => {
|
|
1634
|
+
session.abort();
|
|
1635
|
+
},
|
|
1636
|
+
settings,
|
|
1637
|
+
autoApprove: options.autoApprove ?? false,
|
|
1638
|
+
});
|
|
1639
|
+
const toolContextStore = new ToolContextStore(getSessionContext);
|
|
1640
|
+
|
|
1641
|
+
const registeredTools = extensionRunner.getAllRegisteredTools();
|
|
1642
|
+
const allCustomTools = [
|
|
1643
|
+
...registeredTools,
|
|
1644
|
+
...(options.customTools?.map(tool => {
|
|
1645
|
+
const definition = isCustomTool(tool) ? customToolToDefinition(tool) : tool;
|
|
1646
|
+
return { definition, extensionPath: "<sdk>" };
|
|
1647
|
+
}) ?? []),
|
|
1648
|
+
];
|
|
1649
|
+
const wrappedExtensionTools: Tool[] = wrapRegisteredTools(allCustomTools, extensionRunner);
|
|
1650
|
+
|
|
1651
|
+
// All built-in tools are active (conditional tools like git/ask return null from factory if disabled)
|
|
1652
|
+
const toolRegistry = new Map<string, Tool>();
|
|
1653
|
+
for (const tool of builtinTools) {
|
|
1654
|
+
toolRegistry.set(tool.name, tool);
|
|
1655
|
+
}
|
|
1656
|
+
if (!toolRegistry.has("goal") && settings.get("goal.enabled")) {
|
|
1657
|
+
const goalTool = await logger.time("createTools:goal:session", HIDDEN_TOOLS.goal, toolSession);
|
|
1658
|
+
if (goalTool) {
|
|
1659
|
+
toolRegistry.set(goalTool.name, wrapToolWithMetaNotice(goalTool));
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
for (const tool of wrappedExtensionTools) {
|
|
1663
|
+
toolRegistry.set(tool.name, tool);
|
|
1664
|
+
}
|
|
1665
|
+
// Wrap every tool with `ExtensionToolWrapper` so the per-tool approval gate runs on every
|
|
1666
|
+
// call site, regardless of whether any user extensions are loaded. See the runner-construction
|
|
1667
|
+
// comment above for the safety invariant this enforces.
|
|
1668
|
+
for (const tool of toolRegistry.values()) {
|
|
1669
|
+
toolRegistry.set(tool.name, new ExtensionToolWrapper(tool, extensionRunner));
|
|
1670
|
+
}
|
|
1671
|
+
if (model?.provider === "cursor") {
|
|
1672
|
+
toolRegistry.delete("edit");
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
// `resolve` is hidden but must stay in the registry whenever any code path can invoke it:
|
|
1676
|
+
// either a deferrable tool stages a preview action, or plan mode installs a standing handler
|
|
1677
|
+
// that consumes `resolve { action: "apply" }` to submit the plan for approval (issue #1428).
|
|
1678
|
+
// Dropping it on read-only sessions (e.g. plan-mode toolset `read`, `search`, `find`,
|
|
1679
|
+
// `web_search`) leaves plan mode unable to exit through the intended path.
|
|
1680
|
+
const hasDeferrableTools = Array.from(toolRegistry.values()).some(tool => tool.deferrable === true);
|
|
1681
|
+
const planModeAvailable = settings.get("plan.enabled");
|
|
1682
|
+
const needsResolveTool = hasDeferrableTools || planModeAvailable;
|
|
1683
|
+
if (!needsResolveTool) {
|
|
1684
|
+
toolRegistry.delete("resolve");
|
|
1685
|
+
} else if (!toolRegistry.has("resolve")) {
|
|
1686
|
+
const resolveTool = await logger.time("createTools:resolve:session", HIDDEN_TOOLS.resolve, toolSession);
|
|
1687
|
+
if (resolveTool) {
|
|
1688
|
+
toolRegistry.set(resolveTool.name, wrapToolWithMetaNotice(resolveTool));
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
const effectiveDiscoveryMode = resolveEffectiveToolDiscoveryMode(
|
|
1693
|
+
settings,
|
|
1694
|
+
countToolsForAutoDiscovery(toolRegistry.keys()),
|
|
1695
|
+
);
|
|
1696
|
+
if (effectiveDiscoveryMode !== "off" && !toolRegistry.has("search_tool_bm25")) {
|
|
1697
|
+
const searchTool: Tool = new SearchToolBm25Tool(toolSession);
|
|
1698
|
+
toolRegistry.set(
|
|
1699
|
+
searchTool.name,
|
|
1700
|
+
new ExtensionToolWrapper(wrapToolWithMetaNotice(searchTool), extensionRunner) as Tool,
|
|
1701
|
+
);
|
|
1702
|
+
}
|
|
1703
|
+
const mcpDiscoveryEnabled = effectiveDiscoveryMode !== "off"; // back-compat: true when any discovery active
|
|
1704
|
+
|
|
1705
|
+
const reloadSshTool = async (): Promise<AgentTool | null> => {
|
|
1706
|
+
if (!requestedToolNameSet.has("ssh")) return null;
|
|
1707
|
+
const sshTool = (await loadSshTool({
|
|
1708
|
+
...toolSession,
|
|
1709
|
+
cwd: sessionManager.getCwd(),
|
|
1710
|
+
})) as unknown as AgentTool | null;
|
|
1711
|
+
if (!sshTool) return null;
|
|
1712
|
+
const wrapped = wrapToolWithMetaNotice(sshTool);
|
|
1713
|
+
return new ExtensionToolWrapper(wrapped, extensionRunner) as AgentTool;
|
|
1714
|
+
};
|
|
1715
|
+
|
|
1716
|
+
let cursorEventEmitter: ((event: AgentEvent) => void) | undefined;
|
|
1717
|
+
const cursorExecHandlers = new CursorExecHandlers({
|
|
1718
|
+
cwd,
|
|
1719
|
+
tools: toolRegistry,
|
|
1720
|
+
getToolContext: () => toolContextStore.getContext(),
|
|
1721
|
+
emitEvent: event => cursorEventEmitter?.(event),
|
|
1722
|
+
});
|
|
1723
|
+
|
|
1724
|
+
const repeatToolDescriptions = settings.get("repeatToolDescriptions");
|
|
1725
|
+
const eagerTasks = settings.get("task.eager");
|
|
1726
|
+
const intentField = $flag("PROMETHEUS_INTENT_TRACING", settings.get("tools.intentTracing"))
|
|
1727
|
+
? INTENT_FIELD
|
|
1728
|
+
: undefined;
|
|
1729
|
+
const rebuildSystemPrompt = async (
|
|
1730
|
+
toolNames: string[],
|
|
1731
|
+
tools: Map<string, AgentTool>,
|
|
1732
|
+
): Promise<BuildSystemPromptResult> => {
|
|
1733
|
+
toolContextStore.setToolNames(toolNames);
|
|
1734
|
+
const discoverableMCPTools: DiscoverableTool[] = mcpDiscoveryEnabled
|
|
1735
|
+
? filterBySource(collectDiscoverableTools(tools.values()), "mcp")
|
|
1736
|
+
: [];
|
|
1737
|
+
const activeToolNames = new Set(toolNames);
|
|
1738
|
+
const discoverableBuiltinTools: DiscoverableTool[] =
|
|
1739
|
+
effectiveDiscoveryMode === "all"
|
|
1740
|
+
? collectDiscoverableTools(
|
|
1741
|
+
Array.from(tools.values()).filter(
|
|
1742
|
+
tool => tool.loadMode === "discoverable" && !activeToolNames.has(tool.name),
|
|
1743
|
+
),
|
|
1744
|
+
{ source: "builtin" },
|
|
1745
|
+
)
|
|
1746
|
+
: [];
|
|
1747
|
+
const discoverableToolsForDesc: DiscoverableTool[] = [...discoverableBuiltinTools, ...discoverableMCPTools];
|
|
1748
|
+
const discoverableToolSummary = summarizeDiscoverableTools(discoverableToolsForDesc);
|
|
1749
|
+
const hasDiscoverableTools =
|
|
1750
|
+
mcpDiscoveryEnabled && toolNames.includes("search_tool_bm25") && discoverableToolsForDesc.length > 0;
|
|
1751
|
+
const promptTools = buildSystemPromptToolMetadata(tools, {
|
|
1752
|
+
search_tool_bm25: { description: renderSearchToolBm25Description(discoverableToolsForDesc) },
|
|
1753
|
+
});
|
|
1754
|
+
const memoryBackend = resolveMemoryBackend(settings);
|
|
1755
|
+
const memoryInstructions = await memoryBackend.buildDeveloperInstructions(agentDir, settings, session);
|
|
1756
|
+
|
|
1757
|
+
// Build combined append prompt: memory instructions + MCP server instructions
|
|
1758
|
+
const serverInstructions = mcpManager?.getServerInstructions();
|
|
1759
|
+
let appendPrompt: string | undefined = memoryInstructions ?? undefined;
|
|
1760
|
+
if (serverInstructions && serverInstructions.size > 0) {
|
|
1761
|
+
const parts: string[] = [];
|
|
1762
|
+
if (appendPrompt) parts.push(appendPrompt);
|
|
1763
|
+
parts.push(
|
|
1764
|
+
"## MCP Server Instructions\n\nThe following instructions are provided by connected MCP servers. They are server-controlled and may not be verified.",
|
|
1765
|
+
);
|
|
1766
|
+
for (const [srvName, srvInstructions] of serverInstructions) {
|
|
1767
|
+
const truncated =
|
|
1768
|
+
srvInstructions.length > MAX_MCP_INSTRUCTIONS_LENGTH
|
|
1769
|
+
? `${srvInstructions.slice(0, MAX_MCP_INSTRUCTIONS_LENGTH)}\n[truncated]`
|
|
1770
|
+
: srvInstructions;
|
|
1771
|
+
parts.push(`### ${srvName}\n${truncated}`);
|
|
1772
|
+
}
|
|
1773
|
+
appendPrompt = parts.join("\n\n");
|
|
1774
|
+
}
|
|
1775
|
+
const defaultPrompt = await buildSystemPromptInternal({
|
|
1776
|
+
cwd,
|
|
1777
|
+
skills,
|
|
1778
|
+
contextFiles,
|
|
1779
|
+
tools: promptTools,
|
|
1780
|
+
toolNames,
|
|
1781
|
+
rules: rulebookRules,
|
|
1782
|
+
alwaysApplyRules,
|
|
1783
|
+
skillsSettings: settings.getGroup("skills"),
|
|
1784
|
+
appendSystemPrompt: appendPrompt,
|
|
1785
|
+
repeatToolDescriptions,
|
|
1786
|
+
intentField,
|
|
1787
|
+
mcpDiscoveryMode: hasDiscoverableTools,
|
|
1788
|
+
mcpDiscoveryServerSummaries: discoverableToolSummary.servers.map(formatDiscoverableToolServerSummary),
|
|
1789
|
+
eagerTasks,
|
|
1790
|
+
secretsEnabled,
|
|
1791
|
+
workspaceTree: workspaceTreePromise,
|
|
1792
|
+
memoryRootEnabled: memoryBackend.id === "local",
|
|
1793
|
+
model: settings.get("includeModelInPrompt") ? getActiveModelString() : undefined,
|
|
1794
|
+
});
|
|
1795
|
+
|
|
1796
|
+
if (options.systemPrompt === undefined) {
|
|
1797
|
+
return defaultPrompt;
|
|
1798
|
+
}
|
|
1799
|
+
if (Array.isArray(options.systemPrompt)) {
|
|
1800
|
+
return { systemPrompt: options.systemPrompt };
|
|
1801
|
+
}
|
|
1802
|
+
return {
|
|
1803
|
+
systemPrompt: options.systemPrompt(defaultPrompt.systemPrompt),
|
|
1804
|
+
};
|
|
1805
|
+
};
|
|
1806
|
+
|
|
1807
|
+
const toolNamesFromRegistry = Array.from(toolRegistry.keys());
|
|
1808
|
+
const explicitlyRequestedToolNames = options.toolNames
|
|
1809
|
+
? [...new Set(options.toolNames.map(name => name.toLowerCase()))]
|
|
1810
|
+
: undefined;
|
|
1811
|
+
// When `requireYieldTool` is set, the subagent's prompts and idle-reminders demand a
|
|
1812
|
+
// `yield` call to terminate. The tool registry already includes `yield` (see
|
|
1813
|
+
// `createTools`), but an explicit `toolNames` list would otherwise drop it from the
|
|
1814
|
+
// active set — leaving the model unable to satisfy the contract. Mirror the same
|
|
1815
|
+
// invariant `parseAgentFields` enforces on frontmatter `tools`.
|
|
1816
|
+
if (
|
|
1817
|
+
options.requireYieldTool === true &&
|
|
1818
|
+
explicitlyRequestedToolNames &&
|
|
1819
|
+
!explicitlyRequestedToolNames.includes("yield")
|
|
1820
|
+
) {
|
|
1821
|
+
explicitlyRequestedToolNames.push("yield");
|
|
1822
|
+
}
|
|
1823
|
+
const requestedToolNames = explicitlyRequestedToolNames ?? toolNamesFromRegistry;
|
|
1824
|
+
const normalizedRequested = requestedToolNames.filter(name => toolRegistry.has(name));
|
|
1825
|
+
const requestedToolNameSet = new Set(normalizedRequested);
|
|
1826
|
+
// Effective discovery mode is resolved after the full registry exists so auto mode can count MCP/extension tools.
|
|
1827
|
+
const defaultInactiveToolNames = new Set(
|
|
1828
|
+
registeredTools.filter(tool => tool.definition.defaultInactive).map(tool => tool.definition.name),
|
|
1829
|
+
);
|
|
1830
|
+
const requestedActiveToolNames = normalizedRequested.filter(name => name !== "goal");
|
|
1831
|
+
const initialRequestedActiveToolNames = options.toolNames
|
|
1832
|
+
? requestedActiveToolNames
|
|
1833
|
+
: requestedActiveToolNames.filter(name => !defaultInactiveToolNames.has(name));
|
|
1834
|
+
const explicitlyRequestedMCPToolNames = options.toolNames
|
|
1835
|
+
? requestedActiveToolNames.filter(name => name.startsWith("mcp__"))
|
|
1836
|
+
: [];
|
|
1837
|
+
const discoveryDefaultServers = new Set(
|
|
1838
|
+
(settings.get("mcp.discoveryDefaultServers") ?? []).map(serverName => serverName.trim()).filter(Boolean),
|
|
1839
|
+
);
|
|
1840
|
+
const discoveryDefaultServerToolNames = mcpDiscoveryEnabled
|
|
1841
|
+
? selectDiscoverableToolNamesByServer(
|
|
1842
|
+
filterBySource(collectDiscoverableTools(toolRegistry.values()), "mcp"),
|
|
1843
|
+
discoveryDefaultServers,
|
|
1844
|
+
)
|
|
1845
|
+
: [];
|
|
1846
|
+
let initialSelectedMCPToolNames: string[] = [];
|
|
1847
|
+
let defaultSelectedMCPToolNames: string[] = [];
|
|
1848
|
+
let initialToolNames = [...initialRequestedActiveToolNames];
|
|
1849
|
+
if (mcpDiscoveryEnabled) {
|
|
1850
|
+
const restoredSelectedMCPToolNames = existingSession.selectedMCPToolNames.filter(name =>
|
|
1851
|
+
toolRegistry.has(name),
|
|
1852
|
+
);
|
|
1853
|
+
defaultSelectedMCPToolNames = [
|
|
1854
|
+
...new Set([...discoveryDefaultServerToolNames, ...explicitlyRequestedMCPToolNames]),
|
|
1855
|
+
];
|
|
1856
|
+
initialSelectedMCPToolNames = existingSession.hasPersistedMCPToolSelection
|
|
1857
|
+
? restoredSelectedMCPToolNames
|
|
1858
|
+
: [...new Set([...restoredSelectedMCPToolNames, ...defaultSelectedMCPToolNames])];
|
|
1859
|
+
initialToolNames = [
|
|
1860
|
+
...new Set([
|
|
1861
|
+
...initialRequestedActiveToolNames.filter(name => !name.startsWith("mcp__")),
|
|
1862
|
+
...initialSelectedMCPToolNames,
|
|
1863
|
+
]),
|
|
1864
|
+
];
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
// Custom tools and extension-registered tools are always included regardless of toolNames filter
|
|
1868
|
+
const alwaysInclude: string[] = [
|
|
1869
|
+
...(options.customTools?.map(t => (isCustomTool(t) ? t.name : t.name)) ?? []),
|
|
1870
|
+
...registeredTools.filter(t => !t.definition.defaultInactive).map(t => t.definition.name),
|
|
1871
|
+
];
|
|
1872
|
+
for (const name of alwaysInclude) {
|
|
1873
|
+
if (mcpDiscoveryEnabled && name.startsWith("mcp__")) {
|
|
1874
|
+
continue;
|
|
1875
|
+
}
|
|
1876
|
+
if (toolRegistry.has(name) && !initialToolNames.includes(name)) {
|
|
1877
|
+
initialToolNames.push(name);
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
// When tools.discoveryMode === "all", hide non-essential built-in discoverable tools
|
|
1882
|
+
// from the initial set unless they were explicitly requested or restored from persistence.
|
|
1883
|
+
// The model finds them via search_tool_bm25 and activates them on demand.
|
|
1884
|
+
if (effectiveDiscoveryMode === "all") {
|
|
1885
|
+
const essentialBuiltinNames = new Set(computeEssentialBuiltinNames(settings));
|
|
1886
|
+
const explicitlyRequestedToolNames = new Set(options.toolNames?.map(name => name.toLowerCase()) ?? []);
|
|
1887
|
+
// Back-compat: persisted activations live under selectedMCPToolNames today (built-in
|
|
1888
|
+
// activation persistence is a follow-up). MCP names won't collide with built-in names.
|
|
1889
|
+
const restoredDiscoveredNames = new Set(existingSession.selectedMCPToolNames);
|
|
1890
|
+
initialToolNames = initialToolNames.filter(name => {
|
|
1891
|
+
const tool = toolRegistry.get(name);
|
|
1892
|
+
if (!tool?.loadMode) return true; // not a built-in — leave MCP/custom/extension to existing logic
|
|
1893
|
+
if (tool.loadMode === "essential") return true;
|
|
1894
|
+
if (essentialBuiltinNames.has(name)) return true;
|
|
1895
|
+
if (explicitlyRequestedToolNames.has(name)) return true;
|
|
1896
|
+
if (restoredDiscoveredNames.has(name)) return true;
|
|
1897
|
+
return false;
|
|
1898
|
+
});
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
// Pre-register in the global agent registry BEFORE building the system prompt,
|
|
1902
|
+
// so that subagents launched in the same parallel batch can see each other in
|
|
1903
|
+
// their initial `# IRC Peers` block (rendered inside `rebuildSystemPrompt`).
|
|
1904
|
+
// The session reference is attached after construction below.
|
|
1905
|
+
agentRegistry.register({
|
|
1906
|
+
id: resolvedAgentId,
|
|
1907
|
+
displayName: resolvedAgentDisplayName,
|
|
1908
|
+
kind: (options.taskDepth ?? 0) > 0 || options.parentTaskPrefix ? "sub" : "main",
|
|
1909
|
+
parentId: options.parentTaskPrefix,
|
|
1910
|
+
session: null,
|
|
1911
|
+
sessionFile: sessionManager.getSessionFile() ?? null,
|
|
1912
|
+
status: "running",
|
|
1913
|
+
});
|
|
1914
|
+
hasRegistered = true;
|
|
1915
|
+
|
|
1916
|
+
const { systemPrompt } = await logger.time(
|
|
1917
|
+
"buildSystemPrompt",
|
|
1918
|
+
rebuildSystemPrompt,
|
|
1919
|
+
initialToolNames,
|
|
1920
|
+
toolRegistry,
|
|
1921
|
+
);
|
|
1922
|
+
|
|
1923
|
+
const promptTemplates = await promptTemplatesPromise;
|
|
1924
|
+
toolSession.promptTemplates = promptTemplates;
|
|
1925
|
+
|
|
1926
|
+
const slashCommands = await slashCommandsPromise;
|
|
1927
|
+
|
|
1928
|
+
// Create convertToLlm wrapper that filters images if blockImages is enabled (defense-in-depth)
|
|
1929
|
+
const convertToLlmWithBlockImages = (messages: AgentMessage[]): Message[] => {
|
|
1930
|
+
const converted = convertToLlm(messages);
|
|
1931
|
+
// Check setting dynamically so mid-session changes take effect
|
|
1932
|
+
if (!settings.get("images.blockImages")) {
|
|
1933
|
+
return converted;
|
|
1934
|
+
}
|
|
1935
|
+
// Filter out ImageContent from all messages, replacing with text placeholder
|
|
1936
|
+
return converted.map(msg => {
|
|
1937
|
+
if (msg.role === "user" || msg.role === "toolResult") {
|
|
1938
|
+
const content = msg.content;
|
|
1939
|
+
if (Array.isArray(content)) {
|
|
1940
|
+
const hasImages = content.some(c => c.type === "image");
|
|
1941
|
+
if (hasImages) {
|
|
1942
|
+
const filteredContent = content
|
|
1943
|
+
.map(c =>
|
|
1944
|
+
c.type === "image" ? { type: "text" as const, text: "Image reading is disabled." } : c,
|
|
1945
|
+
)
|
|
1946
|
+
.filter((c, i, arr) => {
|
|
1947
|
+
// Dedupe consecutive "Image reading is disabled." texts
|
|
1948
|
+
if (!(c.type === "text" && c.text === "Image reading is disabled." && i > 0)) return true;
|
|
1949
|
+
const prev = arr[i - 1];
|
|
1950
|
+
return !(prev.type === "text" && prev.text === "Image reading is disabled.");
|
|
1951
|
+
});
|
|
1952
|
+
return { ...msg, content: filteredContent };
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
return msg;
|
|
1957
|
+
});
|
|
1958
|
+
};
|
|
1959
|
+
|
|
1960
|
+
// Final convertToLlm: chain block-images filter with secret obfuscation
|
|
1961
|
+
const convertToLlmFinal = (messages: AgentMessage[]): Message[] => {
|
|
1962
|
+
const converted = convertToLlmWithBlockImages(messages);
|
|
1963
|
+
if (!obfuscator?.hasSecrets()) return converted;
|
|
1964
|
+
return obfuscateMessages(obfuscator, converted);
|
|
1965
|
+
};
|
|
1966
|
+
const transformContext = async (messages: AgentMessage[], _signal?: AbortSignal) => {
|
|
1967
|
+
const withContext = await extensionRunner.emitContext(messages);
|
|
1968
|
+
return wrapSteeringForModel(withContext);
|
|
1969
|
+
};
|
|
1970
|
+
const onPayload = async (payload: unknown, _model?: Model) => {
|
|
1971
|
+
return await extensionRunner.emitBeforeProviderRequest(payload);
|
|
1972
|
+
};
|
|
1973
|
+
const onResponse: SimpleStreamOptions["onResponse"] = async (response, model) => {
|
|
1974
|
+
await extensionRunner.emitAfterProviderResponse(response, model);
|
|
1975
|
+
};
|
|
1976
|
+
|
|
1977
|
+
const setToolUIContext = (uiContext: ExtensionUIContext, hasUI: boolean) => {
|
|
1978
|
+
toolContextStore.setUIContext(uiContext, hasUI);
|
|
1979
|
+
};
|
|
1980
|
+
|
|
1981
|
+
const initialTools = initialToolNames
|
|
1982
|
+
.map(name => toolRegistry.get(name))
|
|
1983
|
+
.filter((tool): tool is AgentTool => tool !== undefined);
|
|
1984
|
+
|
|
1985
|
+
const openaiWebsocketSetting = settings.get("providers.openaiWebsockets") ?? "off";
|
|
1986
|
+
const preferOpenAICodexWebsockets =
|
|
1987
|
+
openaiWebsocketSetting === "on" ? true : openaiWebsocketSetting === "off" ? false : undefined;
|
|
1988
|
+
const serviceTierSetting = settings.get("serviceTier");
|
|
1989
|
+
|
|
1990
|
+
const initialServiceTier = hasServiceTierEntry
|
|
1991
|
+
? existingSession.serviceTier
|
|
1992
|
+
: serviceTierSetting === "none"
|
|
1993
|
+
? undefined
|
|
1994
|
+
: serviceTierSetting;
|
|
1995
|
+
|
|
1996
|
+
agent = new Agent({
|
|
1997
|
+
initialState: {
|
|
1998
|
+
systemPrompt,
|
|
1999
|
+
model,
|
|
2000
|
+
thinkingLevel: toReasoningEffort(effectiveThinkingLevel),
|
|
2001
|
+
tools: initialTools,
|
|
2002
|
+
},
|
|
2003
|
+
convertToLlm: convertToLlmFinal,
|
|
2004
|
+
onPayload,
|
|
2005
|
+
onResponse,
|
|
2006
|
+
sessionId: providerSessionId,
|
|
2007
|
+
transformContext,
|
|
2008
|
+
steeringMode: settings.get("steeringMode") ?? "one-at-a-time",
|
|
2009
|
+
followUpMode: settings.get("followUpMode") ?? "one-at-a-time",
|
|
2010
|
+
interruptMode: settings.get("interruptMode") ?? "immediate",
|
|
2011
|
+
thinkingBudgets: settings.getGroup("thinkingBudgets"),
|
|
2012
|
+
temperature: settings.get("temperature") >= 0 ? settings.get("temperature") : undefined,
|
|
2013
|
+
topP: settings.get("topP") >= 0 ? settings.get("topP") : undefined,
|
|
2014
|
+
topK: settings.get("topK") >= 0 ? settings.get("topK") : undefined,
|
|
2015
|
+
minP: settings.get("minP") >= 0 ? settings.get("minP") : undefined,
|
|
2016
|
+
presencePenalty: settings.get("presencePenalty") >= 0 ? settings.get("presencePenalty") : undefined,
|
|
2017
|
+
repetitionPenalty: settings.get("repetitionPenalty") >= 0 ? settings.get("repetitionPenalty") : undefined,
|
|
2018
|
+
serviceTier: initialServiceTier,
|
|
2019
|
+
hideThinkingSummary: settings.get("hideThinkingBlock"),
|
|
2020
|
+
kimiApiFormat: settings.get("providers.kimiApiFormat") ?? "anthropic",
|
|
2021
|
+
preferWebsockets: preferOpenAICodexWebsockets,
|
|
2022
|
+
getToolContext: tc => toolContextStore.getContext(tc),
|
|
2023
|
+
getApiKey: async provider => {
|
|
2024
|
+
// Read agent.sessionId at call time so credential selection stays aligned
|
|
2025
|
+
// with metadataResolver after /new, fork, resume, or branch switches.
|
|
2026
|
+
const key = await modelRegistry.getApiKeyForProvider(provider, agent.sessionId);
|
|
2027
|
+
if (!key) {
|
|
2028
|
+
throw new Error(`No API key found for provider "${provider}"`);
|
|
2029
|
+
}
|
|
2030
|
+
return key;
|
|
2031
|
+
},
|
|
2032
|
+
streamFn: (streamModel, context, streamOptions) => {
|
|
2033
|
+
const openrouterRoutingPreset = settings.get("providers.openrouterVariant");
|
|
2034
|
+
const openrouterVariant =
|
|
2035
|
+
openrouterRoutingPreset && openrouterRoutingPreset !== "default" ? openrouterRoutingPreset : undefined;
|
|
2036
|
+
return streamSimple(streamModel, context, {
|
|
2037
|
+
...streamOptions,
|
|
2038
|
+
openrouterVariant: streamOptions?.openrouterVariant ?? openrouterVariant,
|
|
2039
|
+
onAuthError: async (provider, oldKey, error) => {
|
|
2040
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2041
|
+
// streamSimple invokes this for both 401 auth failures AND
|
|
2042
|
+
// rotatable usage-limit errors (Codex usage_limit_reached,
|
|
2043
|
+
// Anthropic usage_limit_reached, etc.). The two need
|
|
2044
|
+
// different storage actions: a real 401 means the credential
|
|
2045
|
+
// is bad and should be marked suspect; a usage limit just
|
|
2046
|
+
// means this account is parked until reset and should be
|
|
2047
|
+
// temporarily blocked so a sibling can pick the request up.
|
|
2048
|
+
if (isUsageLimitError(message)) {
|
|
2049
|
+
const retryAfterMs = extractRetryHint(undefined, message);
|
|
2050
|
+
const switched = await modelRegistry.authStorage.markUsageLimitReached(provider, agent.sessionId, {
|
|
2051
|
+
retryAfterMs,
|
|
2052
|
+
signal: streamOptions?.signal,
|
|
2053
|
+
});
|
|
2054
|
+
logger.debug("Retrying provider request after usage-limit block", {
|
|
2055
|
+
provider,
|
|
2056
|
+
switched,
|
|
2057
|
+
retryAfterMs,
|
|
2058
|
+
error: message,
|
|
2059
|
+
});
|
|
2060
|
+
if (!switched) return undefined;
|
|
2061
|
+
return modelRegistry.getApiKeyForProvider(provider, agent.sessionId);
|
|
2062
|
+
}
|
|
2063
|
+
await modelRegistry.authStorage.invalidateCredentialMatching(provider, oldKey, {
|
|
2064
|
+
signal: streamOptions?.signal,
|
|
2065
|
+
sessionId: agent.sessionId,
|
|
2066
|
+
});
|
|
2067
|
+
logger.debug("Retrying provider request after credential invalidation", {
|
|
2068
|
+
provider,
|
|
2069
|
+
error: message,
|
|
2070
|
+
});
|
|
2071
|
+
return modelRegistry.getApiKeyForProvider(provider, agent.sessionId);
|
|
2072
|
+
},
|
|
2073
|
+
});
|
|
2074
|
+
},
|
|
2075
|
+
cursorExecHandlers,
|
|
2076
|
+
transformToolCallArguments: (args, _toolName) => {
|
|
2077
|
+
let result = args;
|
|
2078
|
+
const maxTimeout = settings.get("tools.maxTimeout");
|
|
2079
|
+
if (maxTimeout > 0 && typeof result.timeout === "number") {
|
|
2080
|
+
result = { ...result, timeout: Math.min(result.timeout, maxTimeout) };
|
|
2081
|
+
}
|
|
2082
|
+
if (obfuscator?.hasSecrets()) {
|
|
2083
|
+
result = obfuscator.deobfuscateObject(result);
|
|
2084
|
+
}
|
|
2085
|
+
return result;
|
|
2086
|
+
},
|
|
2087
|
+
intentTracing: !!intentField,
|
|
2088
|
+
getToolChoice: () => session?.nextToolChoice(),
|
|
2089
|
+
telemetry: options.telemetry,
|
|
2090
|
+
appendOnlyContext: model
|
|
2091
|
+
? shouldEnableAppendOnlyContext(settings.get("provider.appendOnlyContext"), model)
|
|
2092
|
+
? new AppendOnlyContextManager()
|
|
2093
|
+
: undefined
|
|
2094
|
+
: undefined,
|
|
2095
|
+
});
|
|
2096
|
+
|
|
2097
|
+
cursorEventEmitter = event => agent.emitExternalEvent(event);
|
|
2098
|
+
|
|
2099
|
+
// Restore messages if session has existing data
|
|
2100
|
+
if (hasExistingSession) {
|
|
2101
|
+
agent.replaceMessages(existingSession.messages);
|
|
2102
|
+
} else {
|
|
2103
|
+
// Save initial model, thinking level, and service tier for new sessions so they can be restored on resume.
|
|
2104
|
+
if (model) {
|
|
2105
|
+
sessionManager.appendModelChange(`${model.provider}/${model.id}`);
|
|
2106
|
+
}
|
|
2107
|
+
if (!autoThinking) {
|
|
2108
|
+
// Do not write the `auto` selector before the first turn resolves; auto
|
|
2109
|
+
// classification persists its concrete effort once a real user turn runs.
|
|
2110
|
+
sessionManager.appendThinkingLevelChange(effectiveThinkingLevel);
|
|
2111
|
+
}
|
|
2112
|
+
if (initialServiceTier) {
|
|
2113
|
+
sessionManager.appendServiceTierChange(initialServiceTier);
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
session = new AgentSession({
|
|
2118
|
+
agent,
|
|
2119
|
+
thinkingLevel: autoThinking ? AUTO_THINKING : effectiveThinkingLevel,
|
|
2120
|
+
sessionManager,
|
|
2121
|
+
settings,
|
|
2122
|
+
evalKernelOwnerId,
|
|
2123
|
+
// Defined only for top-level sessions (creation is gated above).
|
|
2124
|
+
// AgentSession uses this to decide whether it may dispose the global
|
|
2125
|
+
// AsyncJobManager on teardown; subagents inherit the parent's and
|
|
2126
|
+
// **MUST NOT** tear it down.
|
|
2127
|
+
ownedAsyncJobManager: asyncJobManager,
|
|
2128
|
+
asyncJobManager: scopedAsyncJobManager,
|
|
2129
|
+
scopedModels: options.scopedModels,
|
|
2130
|
+
promptTemplates,
|
|
2131
|
+
slashCommands,
|
|
2132
|
+
extensionRunner,
|
|
2133
|
+
customCommands: customCommandsResult.commands,
|
|
2134
|
+
skills,
|
|
2135
|
+
skillWarnings,
|
|
2136
|
+
skillsSettings: settings.getGroup("skills"),
|
|
2137
|
+
modelRegistry,
|
|
2138
|
+
toolRegistry,
|
|
2139
|
+
transformContext,
|
|
2140
|
+
onPayload,
|
|
2141
|
+
onResponse,
|
|
2142
|
+
convertToLlm: convertToLlmFinal,
|
|
2143
|
+
rebuildSystemPrompt,
|
|
2144
|
+
reloadSshTool,
|
|
2145
|
+
requestedToolNames: requestedToolNameSet,
|
|
2146
|
+
getMcpServerInstructions: mcpManager
|
|
2147
|
+
? () => {
|
|
2148
|
+
const raw = mcpManager.getServerInstructions();
|
|
2149
|
+
if (!raw || raw.size === 0) return raw;
|
|
2150
|
+
const out = new Map<string, string>();
|
|
2151
|
+
for (const [name, text] of raw) {
|
|
2152
|
+
out.set(
|
|
2153
|
+
name,
|
|
2154
|
+
text.length > MAX_MCP_INSTRUCTIONS_LENGTH ? text.slice(0, MAX_MCP_INSTRUCTIONS_LENGTH) : text,
|
|
2155
|
+
);
|
|
2156
|
+
}
|
|
2157
|
+
return out;
|
|
2158
|
+
}
|
|
2159
|
+
: undefined,
|
|
2160
|
+
mcpDiscoveryEnabled,
|
|
2161
|
+
initialSelectedMCPToolNames,
|
|
2162
|
+
defaultSelectedMCPToolNames,
|
|
2163
|
+
persistInitialMCPToolSelection: !hasExistingSession,
|
|
2164
|
+
defaultSelectedMCPServerNames: [...discoveryDefaultServers],
|
|
2165
|
+
ttsrManager,
|
|
2166
|
+
obfuscator,
|
|
2167
|
+
agentId: resolvedAgentId,
|
|
2168
|
+
agentRegistry,
|
|
2169
|
+
providerSessionId: options.providerSessionId,
|
|
2170
|
+
parentEvalSessionId: options.parentEvalSessionId,
|
|
2171
|
+
});
|
|
2172
|
+
hasSession = true;
|
|
2173
|
+
if (asyncJobManager) {
|
|
2174
|
+
session.yieldQueue.register<AsyncResultEntry>("async-result", {
|
|
2175
|
+
isStale: entry => asyncJobManager.isDeliverySuppressed(entry.jobId),
|
|
2176
|
+
build: buildAsyncResultBatchMessage,
|
|
2177
|
+
});
|
|
2178
|
+
}
|
|
2179
|
+
session.yieldQueue.register<McpNotificationEntry>("mcp-notification", {
|
|
2180
|
+
build: buildMcpNotificationBatchMessage,
|
|
2181
|
+
});
|
|
2182
|
+
|
|
2183
|
+
// Attach the live session to the pre-registered ref so peers can route IRC
|
|
2184
|
+
// messages here. Refresh sessionFile in case it was unavailable at pre-register
|
|
2185
|
+
// time. The dispose wrapper below unregisters on teardown.
|
|
2186
|
+
agentRegistry.attachSession(resolvedAgentId, session, sessionManager.getSessionFile() ?? null);
|
|
2187
|
+
{
|
|
2188
|
+
const originalDispose = session.dispose.bind(session);
|
|
2189
|
+
session.dispose = async () => {
|
|
2190
|
+
try {
|
|
2191
|
+
await originalDispose();
|
|
2192
|
+
} finally {
|
|
2193
|
+
agentRegistry.unregister(resolvedAgentId);
|
|
2194
|
+
unsubscribeCredentialDisabled?.();
|
|
2195
|
+
}
|
|
2196
|
+
};
|
|
2197
|
+
}
|
|
2198
|
+
|
|
2199
|
+
if (model?.api === "openai-codex-responses") {
|
|
2200
|
+
const codexModel = model;
|
|
2201
|
+
const codexTransport = getOpenAICodexTransportDetails(codexModel, {
|
|
2202
|
+
sessionId: providerSessionId,
|
|
2203
|
+
baseUrl: codexModel.baseUrl,
|
|
2204
|
+
preferWebsockets: preferOpenAICodexWebsockets,
|
|
2205
|
+
providerSessionState: session.providerSessionState,
|
|
2206
|
+
});
|
|
2207
|
+
if (codexTransport.websocketPreferred) {
|
|
2208
|
+
void (async () => {
|
|
2209
|
+
try {
|
|
2210
|
+
const codexPrewarmApiKey = await modelRegistry.getApiKey(codexModel, providerSessionId);
|
|
2211
|
+
if (!codexPrewarmApiKey) return;
|
|
2212
|
+
await logger.time("prewarmOpenAICodexResponses", prewarmOpenAICodexResponses, codexModel, {
|
|
2213
|
+
apiKey: codexPrewarmApiKey,
|
|
2214
|
+
sessionId: providerSessionId,
|
|
2215
|
+
preferWebsockets: preferOpenAICodexWebsockets,
|
|
2216
|
+
providerSessionState: session.providerSessionState,
|
|
2217
|
+
});
|
|
2218
|
+
} catch (error) {
|
|
2219
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
2220
|
+
logger.debug("Codex websocket prewarm failed", {
|
|
2221
|
+
error: errorMessage,
|
|
2222
|
+
provider: codexModel.provider,
|
|
2223
|
+
model: codexModel.id,
|
|
2224
|
+
});
|
|
2225
|
+
}
|
|
2226
|
+
})();
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
// Start LSP warmup in the background so startup does not block on language server initialization.
|
|
2231
|
+
// Print/script invocations (`hasUI=false`) don't render the warmup status indicator AND typically
|
|
2232
|
+
// finish before LSP servers would have stabilized — warming them just spends CPU parsing big
|
|
2233
|
+
// `initialize` responses concurrently with the LLM stream consumer, jittering perceived latency.
|
|
2234
|
+
// Tools that need an LSP server still spin one up on demand through `getOrCreateClient`.
|
|
2235
|
+
let lspServers: CreateAgentSessionResult["lspServers"];
|
|
2236
|
+
if (enableLsp && options.hasUI && settings.get("lsp.diagnosticsOnWrite")) {
|
|
2237
|
+
lspServers = discoverStartupLspServers(cwd);
|
|
2238
|
+
if (lspServers.length > 0) {
|
|
2239
|
+
void (async () => {
|
|
2240
|
+
try {
|
|
2241
|
+
const result = await logger.time("warmupLspServers", warmupLspServers, cwd);
|
|
2242
|
+
const serversByName = new Map(result.servers.map(server => [server.name, server] as const));
|
|
2243
|
+
for (const server of lspServers ?? []) {
|
|
2244
|
+
const next = serversByName.get(server.name);
|
|
2245
|
+
if (!next) continue;
|
|
2246
|
+
server.status = next.status;
|
|
2247
|
+
server.fileTypes = next.fileTypes;
|
|
2248
|
+
server.error = next.error;
|
|
2249
|
+
}
|
|
2250
|
+
const event: LspStartupEvent = {
|
|
2251
|
+
type: "completed",
|
|
2252
|
+
servers: result.servers,
|
|
2253
|
+
};
|
|
2254
|
+
eventBus.emit(LSP_STARTUP_EVENT_CHANNEL, event);
|
|
2255
|
+
} catch (error) {
|
|
2256
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
2257
|
+
logger.warn("LSP server warmup failed", { cwd, error: errorMessage });
|
|
2258
|
+
for (const server of lspServers ?? []) {
|
|
2259
|
+
server.status = "error";
|
|
2260
|
+
server.error = errorMessage;
|
|
2261
|
+
}
|
|
2262
|
+
const event: LspStartupEvent = {
|
|
2263
|
+
type: "failed",
|
|
2264
|
+
error: errorMessage,
|
|
2265
|
+
};
|
|
2266
|
+
eventBus.emit(LSP_STARTUP_EVENT_CHANNEL, event);
|
|
2267
|
+
}
|
|
2268
|
+
})();
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
|
|
2272
|
+
logger.time("startMemoryStartupTask", () =>
|
|
2273
|
+
Promise.resolve(
|
|
2274
|
+
resolveMemoryBackend(settings).start({
|
|
2275
|
+
session,
|
|
2276
|
+
settings,
|
|
2277
|
+
modelRegistry,
|
|
2278
|
+
agentDir,
|
|
2279
|
+
taskDepth,
|
|
2280
|
+
parentHindsightSessionState: options.parentHindsightSessionState,
|
|
2281
|
+
parentMnemopiSessionState: options.parentMnemopiSessionState,
|
|
2282
|
+
}),
|
|
2283
|
+
),
|
|
2284
|
+
);
|
|
2285
|
+
|
|
2286
|
+
// Wire MCP manager callbacks to session for reactive tool updates.
|
|
2287
|
+
// Skip when reusing a parent's manager — the parent owns the callbacks.
|
|
2288
|
+
if (mcpManager && !options.mcpManager) {
|
|
2289
|
+
mcpManager.setOnToolsChanged(tools => {
|
|
2290
|
+
void session.refreshMCPTools(tools);
|
|
2291
|
+
});
|
|
2292
|
+
// Wire prompt refresh → rebuild MCP prompt slash commands
|
|
2293
|
+
mcpManager.setOnPromptsChanged(serverName => {
|
|
2294
|
+
const promptCommands = buildMCPPromptCommands(mcpManager);
|
|
2295
|
+
session.setMCPPromptCommands(promptCommands);
|
|
2296
|
+
logger.debug("MCP prompt commands refreshed", { path: `mcp:${serverName}` });
|
|
2297
|
+
});
|
|
2298
|
+
const notificationDebounceTimers = new Map<string, Timer>();
|
|
2299
|
+
const clearDebounceTimers = () => {
|
|
2300
|
+
for (const timer of notificationDebounceTimers.values()) clearTimeout(timer);
|
|
2301
|
+
notificationDebounceTimers.clear();
|
|
2302
|
+
};
|
|
2303
|
+
postmortem.register("mcp-notification-cleanup", clearDebounceTimers);
|
|
2304
|
+
mcpManager.setOnResourcesChanged((serverName, uri) => {
|
|
2305
|
+
logger.debug("MCP resources changed", { path: `mcp:${serverName}`, uri });
|
|
2306
|
+
if (!settings.get("mcp.notifications")) return;
|
|
2307
|
+
const debounceMs = settings.get("mcp.notificationDebounceMs");
|
|
2308
|
+
const key = `${serverName}:${uri}`;
|
|
2309
|
+
const existing = notificationDebounceTimers.get(key);
|
|
2310
|
+
if (existing) clearTimeout(existing);
|
|
2311
|
+
notificationDebounceTimers.set(
|
|
2312
|
+
key,
|
|
2313
|
+
setTimeout(() => {
|
|
2314
|
+
notificationDebounceTimers.delete(key);
|
|
2315
|
+
// Re-check: user may have disabled notifications during the debounce window
|
|
2316
|
+
if (!settings.get("mcp.notifications")) return;
|
|
2317
|
+
session.yieldQueue.enqueue<McpNotificationEntry>("mcp-notification", { serverName, uri });
|
|
2318
|
+
}, debounceMs),
|
|
2319
|
+
);
|
|
2320
|
+
});
|
|
2321
|
+
}
|
|
2322
|
+
|
|
2323
|
+
return {
|
|
2324
|
+
session,
|
|
2325
|
+
extensionsResult,
|
|
2326
|
+
setToolUIContext,
|
|
2327
|
+
mcpManager,
|
|
2328
|
+
modelFallbackMessage,
|
|
2329
|
+
lspServers,
|
|
2330
|
+
eventBus,
|
|
2331
|
+
};
|
|
2332
|
+
} catch (error) {
|
|
2333
|
+
// Release the subscription if the throw happened after install but before the
|
|
2334
|
+
// dispose-wrap took ownership. Idempotent with dispose() — Set.delete is a no-op
|
|
2335
|
+
// for already-removed listeners.
|
|
2336
|
+
unsubscribeCredentialDisabled?.();
|
|
2337
|
+
try {
|
|
2338
|
+
if (hasSession) {
|
|
2339
|
+
await session.dispose();
|
|
2340
|
+
} else {
|
|
2341
|
+
if (hasRegistered) agentRegistry.unregister(resolvedAgentId);
|
|
2342
|
+
if (asyncJobManager) {
|
|
2343
|
+
if (AsyncJobManager.instance() === asyncJobManager) {
|
|
2344
|
+
AsyncJobManager.setInstance(undefined);
|
|
2345
|
+
}
|
|
2346
|
+
await asyncJobManager.dispose({ timeoutMs: 3_000 });
|
|
2347
|
+
}
|
|
2348
|
+
await disposeKernelSessionsByOwner(evalKernelOwnerId);
|
|
2349
|
+
}
|
|
2350
|
+
} catch (cleanupError) {
|
|
2351
|
+
logger.warn("Failed to clean up createAgentSession resources after startup error", {
|
|
2352
|
+
error: cleanupError instanceof Error ? cleanupError.message : String(cleanupError),
|
|
2353
|
+
});
|
|
2354
|
+
}
|
|
2355
|
+
throw error;
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
|
|
2359
|
+
/**
|
|
2360
|
+
* Best-effort preconnect to the model's API host. Bun's `fetch.preconnect`
|
|
2361
|
+
* primes DNS + TCP + TLS + H2 so the first real request reuses the warm
|
|
2362
|
+
* connection. Errors are swallowed: preconnect is an optimization, never a
|
|
2363
|
+
* hard dependency.
|
|
2364
|
+
*/
|
|
2365
|
+
function preconnectModelHost(baseUrl: string | undefined): void {
|
|
2366
|
+
if (!baseUrl) return;
|
|
2367
|
+
const preconnect = (globalThis.fetch as typeof fetch & { preconnect?: (url: string) => void }).preconnect;
|
|
2368
|
+
if (typeof preconnect !== "function") return;
|
|
2369
|
+
try {
|
|
2370
|
+
preconnect(baseUrl);
|
|
2371
|
+
} catch {
|
|
2372
|
+
// Best effort.
|
|
2373
|
+
}
|
|
2374
|
+
}
|