oma-coding-agent 1.1.4
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 +12164 -0
- package/README.md +35 -0
- package/dist/cli.js +18266 -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 +145 -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 +17 -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 +115 -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 +149 -0
- package/examples/hooks/permission-gate.ts +33 -0
- package/examples/hooks/protected-paths.ts +29 -0
- package/examples/hooks/qna.ts +118 -0
- package/examples/hooks/status-line.ts +39 -0
- package/examples/sdk/01-minimal.ts +21 -0
- package/examples/sdk/02-custom-model.ts +49 -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 +41 -0
- package/examples/sdk/08-slash-commands.ts +46 -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 +573 -0
- package/scripts/bench-guard.ts +71 -0
- package/scripts/build-binary.ts +108 -0
- package/scripts/bundle-dist.ts +110 -0
- package/scripts/embed-mupdf-wasm.ts +67 -0
- package/scripts/format-prompts.ts +68 -0
- package/scripts/generate-docs-index.ts +56 -0
- package/scripts/generate-share-viewer.ts +34 -0
- package/scripts/measure-prompt-tokens.ts +63 -0
- package/scripts/omp +42 -0
- package/scripts/omp.ts +19 -0
- package/src/advisor/__tests__/advisor.test.ts +915 -0
- package/src/advisor/advise-tool.ts +165 -0
- package/src/advisor/index.ts +4 -0
- package/src/advisor/runtime.ts +270 -0
- package/src/advisor/transcript-recorder.ts +136 -0
- package/src/advisor/watchdog.ts +83 -0
- package/src/async/index.ts +1 -0
- package/src/async/job-manager.ts +674 -0
- package/src/auto-thinking/classifier.ts +190 -0
- package/src/autolearn/controller.ts +139 -0
- package/src/autolearn/managed-skills.ts +255 -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 +700 -0
- package/src/autoresearch/tools/init-experiment.ts +269 -0
- package/src/autoresearch/tools/log-experiment.ts +521 -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/capability/context-file.ts +44 -0
- package/src/capability/extension-module.ts +34 -0
- package/src/capability/extension.ts +47 -0
- package/src/capability/fs.ts +117 -0
- package/src/capability/hook.ts +40 -0
- package/src/capability/index.ts +436 -0
- package/src/capability/instruction.ts +37 -0
- package/src/capability/mcp.ts +76 -0
- package/src/capability/prompt.ts +35 -0
- package/src/capability/rule-buckets.ts +66 -0
- package/src/capability/rule.ts +261 -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 +168 -0
- package/src/cli/agents-cli.ts +138 -0
- package/src/cli/args.ts +361 -0
- package/src/cli/auth-broker-cli.ts +893 -0
- package/src/cli/auth-gateway-cli.ts +608 -0
- package/src/cli/bench-cli.ts +552 -0
- package/src/cli/classify-install-target.ts +76 -0
- package/src/cli/claude-trace-cli.ts +795 -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 +858 -0
- package/src/cli/extension-flags.ts +48 -0
- package/src/cli/file-processor.ts +133 -0
- package/src/cli/flag-tables.ts +280 -0
- package/src/cli/gallery-cli.ts +231 -0
- package/src/cli/gallery-fixtures/agentic.ts +407 -0
- package/src/cli/gallery-fixtures/codeintel.ts +187 -0
- package/src/cli/gallery-fixtures/edit.ts +194 -0
- package/src/cli/gallery-fixtures/fs.ts +220 -0
- package/src/cli/gallery-fixtures/index.ts +40 -0
- package/src/cli/gallery-fixtures/interaction.ts +49 -0
- package/src/cli/gallery-fixtures/memory.ts +81 -0
- package/src/cli/gallery-fixtures/misc.ts +250 -0
- package/src/cli/gallery-fixtures/search.ts +213 -0
- package/src/cli/gallery-fixtures/shell.ts +167 -0
- package/src/cli/gallery-fixtures/types.ts +57 -0
- package/src/cli/gallery-fixtures/web.ts +158 -0
- package/src/cli/gallery-screenshot.ts +279 -0
- package/src/cli/grep-cli.ts +160 -0
- package/src/cli/grievances-cli.ts +256 -0
- package/src/cli/initial-message.ts +58 -0
- package/src/cli/models-cli.ts +427 -0
- package/src/cli/plugin-cli.ts +996 -0
- package/src/cli/profile-alias.ts +338 -0
- package/src/cli/profile-bootstrap.ts +243 -0
- package/src/cli/read-cli.ts +57 -0
- package/src/cli/session-picker.ts +80 -0
- package/src/cli/setup-cli.ts +332 -0
- package/src/cli/setup-model-picker.ts +43 -0
- package/src/cli/shell-cli.ts +176 -0
- package/src/cli/ssh-cli.ts +179 -0
- package/src/cli/startup-cwd.ts +58 -0
- package/src/cli/stats-cli.ts +229 -0
- package/src/cli/tiny-models-cli.ts +127 -0
- package/src/cli/ttsr-cli.ts +995 -0
- package/src/cli/update-cli.ts +671 -0
- package/src/cli/usage-cli.ts +774 -0
- package/src/cli/web-search-cli.ts +132 -0
- package/src/cli/worktree-cli.ts +291 -0
- package/src/cli-commands.ts +85 -0
- package/src/cli.ts +326 -0
- package/src/collab/crypto.ts +63 -0
- package/src/collab/guest.ts +450 -0
- package/src/collab/host.ts +577 -0
- package/src/collab/protocol.ts +274 -0
- package/src/collab/relay-client.ts +216 -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/bench.ts +42 -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/gallery.ts +52 -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/join.ts +39 -0
- package/src/commands/launch.ts +182 -0
- package/src/commands/models.ts +61 -0
- package/src/commands/plugin.ts +78 -0
- package/src/commands/read.ts +38 -0
- package/src/commands/say.ts +102 -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/token.ts +108 -0
- package/src/commands/ttsr.ts +125 -0
- package/src/commands/update.ts +21 -0
- package/src/commands/usage.ts +43 -0
- package/src/commands/web-search.ts +42 -0
- package/src/commands/worktree.ts +56 -0
- package/src/commit/agentic/agent.ts +318 -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 +149 -0
- package/src/commit/agentic/tools/git-file-diff.ts +191 -0
- package/src/commit/agentic/tools/git-hunk.ts +52 -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 +147 -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 +11 -0
- package/src/commit/agentic/tools/split-commit.ts +241 -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 +107 -0
- package/src/commit/analysis/validation.ts +66 -0
- package/src/commit/changelog/detect.ts +40 -0
- package/src/commit/changelog/generate.ts +101 -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 +89 -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 +70 -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/api-key-resolver.ts +67 -0
- package/src/config/append-only-context-mode.ts +76 -0
- package/src/config/config-file.ts +315 -0
- package/src/config/file-lock.ts +164 -0
- package/src/config/keybindings.ts +634 -0
- package/src/config/mcp-schema.json +238 -0
- package/src/config/model-discovery.ts +589 -0
- package/src/config/model-registry.ts +2260 -0
- package/src/config/model-resolver.ts +1819 -0
- package/src/config/model-roles.ts +99 -0
- package/src/config/models-config-schema.ts +266 -0
- package/src/config/models-config.ts +131 -0
- package/src/config/prompt-templates.ts +185 -0
- package/src/config/resolve-config-value.ts +94 -0
- package/src/config/settings-schema.ts +4740 -0
- package/src/config/settings.ts +1243 -0
- package/src/config.ts +242 -0
- package/src/cursor.ts +340 -0
- package/src/dap/client.ts +760 -0
- package/src/dap/config.ts +189 -0
- package/src/dap/defaults.json +212 -0
- package/src/dap/index.ts +4 -0
- package/src/dap/session.ts +1441 -0
- package/src/dap/types.ts +610 -0
- package/src/debug/index.ts +559 -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 +294 -0
- package/src/debug/raw-sse.ts +292 -0
- package/src/debug/remote-debugger.ts +151 -0
- package/src/debug/report-bundle.ts +375 -0
- package/src/debug/system-info.ts +111 -0
- package/src/debug/terminal-info.ts +124 -0
- package/src/discovery/agents-md.ts +67 -0
- package/src/discovery/agents.ts +230 -0
- package/src/discovery/at-imports.ts +273 -0
- package/src/discovery/builtin-defaults.ts +39 -0
- package/src/discovery/builtin-rules/index.ts +63 -0
- package/src/discovery/builtin-rules/low-end/no-hallucinated-apis.md +14 -0
- package/src/discovery/builtin-rules/low-end/no-hallucinated-paths.md +14 -0
- package/src/discovery/builtin-rules/low-end/no-premature-completion.md +14 -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 +65 -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-inline-cast-access.md +55 -0
- package/src/discovery/builtin-rules/ts-no-return-type.md +44 -0
- package/src/discovery/builtin-rules/ts-no-test-timers.md +55 -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-redundant-clear-guard.md +75 -0
- package/src/discovery/builtin-rules/ts-set-map.md +28 -0
- package/src/discovery/builtin.ts +934 -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/cursor.ts +220 -0
- package/src/discovery/gemini.ts +383 -0
- package/src/discovery/github.ts +337 -0
- package/src/discovery/helpers.ts +1092 -0
- package/src/discovery/index.ts +81 -0
- package/src/discovery/mcp-json.ts +172 -0
- package/src/discovery/omp-extension-roots.ts +190 -0
- package/src/discovery/omp-plugins.ts +383 -0
- package/src/discovery/opencode.ts +398 -0
- package/src/discovery/plugin-dir-roots.ts +28 -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 +999 -0
- package/src/edit/file-snapshot-store.ts +143 -0
- package/src/edit/hashline/block-resolver.ts +33 -0
- package/src/edit/hashline/diff.ts +290 -0
- package/src/edit/hashline/execute.ts +237 -0
- package/src/edit/hashline/filesystem.ts +130 -0
- package/src/edit/hashline/index.ts +5 -0
- package/src/edit/hashline/noop-loop-guard.ts +99 -0
- package/src/edit/hashline/params.ts +19 -0
- package/src/edit/index.ts +620 -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 +1888 -0
- package/src/edit/modes/replace.ts +1133 -0
- package/src/edit/normalize.ts +345 -0
- package/src/edit/notebook.ts +242 -0
- package/src/edit/read-file.ts +25 -0
- package/src/edit/renderer.ts +823 -0
- package/src/edit/streaming.ts +517 -0
- package/src/eval/__tests__/agent-bridge.test.ts +769 -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__/completion-bridge.test.ts +412 -0
- package/src/eval/__tests__/helpers-local-roots.test.ts +58 -0
- package/src/eval/__tests__/idle-timeout.test.ts +80 -0
- package/src/eval/__tests__/js-context-manager.test.ts +291 -0
- package/src/eval/__tests__/kernel-spawn.test.ts +103 -0
- package/src/eval/__tests__/prelude-agent.test.ts +73 -0
- package/src/eval/agent-bridge.ts +319 -0
- package/src/eval/backend.ts +71 -0
- package/src/eval/bridge-timeout.ts +44 -0
- package/src/eval/budget-bridge.ts +48 -0
- package/src/eval/completion-bridge.ts +211 -0
- package/src/eval/concurrency-bridge.ts +34 -0
- package/src/eval/idle-timeout.ts +91 -0
- package/src/eval/index.ts +4 -0
- package/src/eval/js/context-manager.ts +621 -0
- package/src/eval/js/executor.ts +173 -0
- package/src/eval/js/index.ts +51 -0
- package/src/eval/js/shared/helpers.ts +283 -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 +307 -0
- package/src/eval/js/shared/rewrite-imports.ts +532 -0
- package/src/eval/js/shared/runtime.ts +580 -0
- package/src/eval/js/shared/types.ts +18 -0
- package/src/eval/js/tool-bridge.ts +163 -0
- package/src/eval/js/worker-core.ts +151 -0
- package/src/eval/js/worker-entry.ts +37 -0
- package/src/eval/js/worker-protocol.ts +47 -0
- package/src/eval/py/__tests__/prelude.test.ts +19 -0
- package/src/eval/py/display.ts +71 -0
- package/src/eval/py/executor.ts +742 -0
- package/src/eval/py/index.ts +68 -0
- package/src/eval/py/kernel.ts +748 -0
- package/src/eval/py/prelude.py +683 -0
- package/src/eval/py/prelude.ts +3 -0
- package/src/eval/py/runner.py +1177 -0
- package/src/eval/py/runtime.ts +276 -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/index.ts +2 -0
- package/src/exa/mcp-client.ts +370 -0
- package/src/exa/types.ts +69 -0
- package/src/exec/bash-executor.ts +434 -0
- package/src/exec/exec.ts +53 -0
- package/src/exec/non-interactive-env.ts +119 -0
- package/src/export/custom-share.ts +65 -0
- package/src/export/html/index.ts +266 -0
- package/src/export/html/share-loader.js +102 -0
- package/src/export/html/template.css +1337 -0
- package/src/export/html/template.html +49 -0
- package/src/export/html/template.js +1626 -0
- package/src/export/html/tool-views.generated.js +37 -0
- package/src/export/html/vendor/highlight.min.js +1213 -0
- package/src/export/html/vendor/marked.min.js +6 -0
- package/src/export/share.ts +268 -0
- package/src/export/ttsr.ts +583 -0
- package/src/extensibility/custom-commands/bundled/ci-green/index.ts +54 -0
- package/src/extensibility/custom-commands/bundled/review/index.ts +698 -0
- package/src/extensibility/custom-commands/index.ts +2 -0
- package/src/extensibility/custom-commands/loader.ts +242 -0
- package/src/extensibility/custom-commands/types.ts +119 -0
- package/src/extensibility/custom-tools/index.ts +7 -0
- package/src/extensibility/custom-tools/loader.ts +268 -0
- package/src/extensibility/custom-tools/types.ts +277 -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 +78 -0
- package/src/extensibility/extensions/index.ts +16 -0
- package/src/extensibility/extensions/loader.ts +587 -0
- package/src/extensibility/extensions/model-api.ts +41 -0
- package/src/extensibility/extensions/runner.ts +989 -0
- package/src/extensibility/extensions/types.ts +1394 -0
- package/src/extensibility/extensions/wrapper.ts +259 -0
- package/src/extensibility/hooks/index.ts +6 -0
- package/src/extensibility/hooks/loader.ts +262 -0
- package/src/extensibility/hooks/runner.ts +425 -0
- package/src/extensibility/hooks/tool-wrapper.ts +107 -0
- package/src/extensibility/hooks/types.ts +613 -0
- package/src/extensibility/legacy-pi-ai-shim.ts +61 -0
- package/src/extensibility/legacy-pi-coding-agent-shim.ts +128 -0
- package/src/extensibility/plugins/doctor.ts +65 -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 +712 -0
- package/src/extensibility/plugins/loader.ts +458 -0
- package/src/extensibility/plugins/manager.ts +1026 -0
- package/src/extensibility/plugins/marketplace/cache.ts +136 -0
- package/src/extensibility/plugins/marketplace/fetcher.ts +315 -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/marketplace-auto-update.ts +49 -0
- package/src/extensibility/plugins/parser.ts +105 -0
- package/src/extensibility/plugins/runtime-config.ts +9 -0
- package/src/extensibility/plugins/types.ts +194 -0
- package/src/extensibility/shared-events.ts +367 -0
- package/src/extensibility/skills.ts +408 -0
- package/src/extensibility/slash-commands.ts +131 -0
- package/src/extensibility/tool-proxy.ts +28 -0
- package/src/extensibility/typebox.ts +945 -0
- package/src/extensibility/utils.ts +44 -0
- package/src/goals/guided-setup.ts +142 -0
- package/src/goals/index.ts +3 -0
- package/src/goals/runtime.ts +521 -0
- package/src/goals/state.ts +37 -0
- package/src/goals/tools/goal-tool.ts +251 -0
- package/src/hindsight/backend.ts +354 -0
- package/src/hindsight/bank.ts +156 -0
- package/src/hindsight/client.ts +623 -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 +429 -0
- package/src/hindsight/seeds.json +32 -0
- package/src/hindsight/state.ts +492 -0
- package/src/hindsight/transcript.ts +71 -0
- package/src/index.ts +66 -0
- package/src/internal-urls/agent-protocol.ts +146 -0
- package/src/internal-urls/artifact-protocol.ts +107 -0
- package/src/internal-urls/docs-index.generated.txt +2 -0
- package/src/internal-urls/docs-index.ts +102 -0
- package/src/internal-urls/history-protocol.ts +118 -0
- package/src/internal-urls/index.ts +25 -0
- package/src/internal-urls/issue-pr-protocol.ts +594 -0
- package/src/internal-urls/json-query.ts +126 -0
- package/src/internal-urls/local-protocol.ts +309 -0
- package/src/internal-urls/mcp-protocol.ts +151 -0
- package/src/internal-urls/memory-protocol.ts +169 -0
- package/src/internal-urls/omp-protocol.ts +94 -0
- package/src/internal-urls/parse.ts +72 -0
- package/src/internal-urls/registry-helpers.ts +25 -0
- package/src/internal-urls/router.ts +105 -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/irc/bus.ts +311 -0
- package/src/lib/xai-http.ts +124 -0
- package/src/lsp/client.ts +1217 -0
- package/src/lsp/clients/biome-client.ts +264 -0
- package/src/lsp/clients/index.ts +50 -0
- package/src/lsp/clients/lsp-linter-client.ts +85 -0
- package/src/lsp/clients/swiftlint-client.ts +120 -0
- package/src/lsp/config.ts +502 -0
- package/src/lsp/defaults.json +499 -0
- package/src/lsp/diagnostics-ledger.ts +51 -0
- package/src/lsp/edits.ts +267 -0
- package/src/lsp/format-options.ts +119 -0
- package/src/lsp/index.ts +2480 -0
- package/src/lsp/lspmux.ts +233 -0
- package/src/lsp/render.ts +668 -0
- package/src/lsp/startup-events.ts +13 -0
- package/src/lsp/types.ts +444 -0
- package/src/lsp/utils.ts +718 -0
- package/src/main.ts +1421 -0
- package/src/markit/NOTICE +32 -0
- package/src/markit/converters/docx.ts +56 -0
- package/src/markit/converters/epub.ts +136 -0
- package/src/markit/converters/mammoth.d.ts +24 -0
- package/src/markit/converters/pdf/columns.ts +103 -0
- package/src/markit/converters/pdf/extract.ts +574 -0
- package/src/markit/converters/pdf/grid.ts +780 -0
- package/src/markit/converters/pdf/headers.ts +106 -0
- package/src/markit/converters/pdf/index.ts +146 -0
- package/src/markit/converters/pdf/render.ts +501 -0
- package/src/markit/converters/pdf/types.ts +84 -0
- package/src/markit/converters/pptx.ts +325 -0
- package/src/markit/converters/xlsx.ts +173 -0
- package/src/markit/index.ts +2 -0
- package/src/markit/registry.ts +59 -0
- package/src/markit/types.ts +35 -0
- package/src/mcp/client.ts +509 -0
- package/src/mcp/config-writer.ts +229 -0
- package/src/mcp/config.ts +365 -0
- package/src/mcp/index.ts +29 -0
- package/src/mcp/json-rpc.ts +122 -0
- package/src/mcp/loader.ts +124 -0
- package/src/mcp/manager.ts +1326 -0
- package/src/mcp/oauth-credentials.ts +104 -0
- package/src/mcp/oauth-discovery.ts +467 -0
- package/src/mcp/oauth-flow.ts +555 -0
- package/src/mcp/render.ts +155 -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/startup-events.ts +21 -0
- package/src/mcp/timeout.ts +59 -0
- package/src/mcp/tool-bridge.ts +429 -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 +606 -0
- package/src/mcp/types.ts +427 -0
- package/src/memories/index.ts +1281 -0
- package/src/memories/storage.ts +578 -0
- package/src/memory-backend/index.ts +18 -0
- package/src/memory-backend/local-backend.ts +45 -0
- package/src/memory-backend/off-backend.ts +25 -0
- package/src/memory-backend/resolve.ts +25 -0
- package/src/memory-backend/runtime.ts +66 -0
- package/src/memory-backend/types.ts +166 -0
- package/src/mnemopi/backend.ts +612 -0
- package/src/mnemopi/config.ts +265 -0
- package/src/mnemopi/embed-client.ts +401 -0
- package/src/mnemopi/embed-protocol.ts +35 -0
- package/src/mnemopi/embed-worker.ts +113 -0
- package/src/mnemopi/index.ts +3 -0
- package/src/mnemopi/state.ts +657 -0
- package/src/modes/acp/acp-agent.ts +2362 -0
- package/src/modes/acp/acp-client-bridge.ts +154 -0
- package/src/modes/acp/acp-event-mapper.ts +933 -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/__tests__/skill-message.test.ts +92 -0
- package/src/modes/components/advisor-message.ts +99 -0
- package/src/modes/components/agent-dashboard.ts +1206 -0
- package/src/modes/components/agent-hub.ts +566 -0
- package/src/modes/components/agent-transcript-viewer.ts +461 -0
- package/src/modes/components/assistant-message.ts +612 -0
- package/src/modes/components/background-tan-message.ts +36 -0
- package/src/modes/components/bash-execution.ts +220 -0
- package/src/modes/components/bordered-loader.ts +41 -0
- package/src/modes/components/btw-panel.ts +112 -0
- package/src/modes/components/cache-invalidation-marker.ts +110 -0
- package/src/modes/components/chat-block.ts +111 -0
- package/src/modes/components/chat-transcript-builder.ts +476 -0
- package/src/modes/components/collab-prompt-message.ts +32 -0
- package/src/modes/components/compaction-summary-message.ts +215 -0
- package/src/modes/components/copy-selector.ts +206 -0
- package/src/modes/components/countdown-timer.ts +75 -0
- package/src/modes/components/custom-editor.test.ts +142 -0
- package/src/modes/components/custom-editor.ts +620 -0
- package/src/modes/components/custom-message.ts +67 -0
- package/src/modes/components/diff.ts +254 -0
- package/src/modes/components/dynamic-border.ts +34 -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 +101 -0
- package/src/modes/components/extensions/extension-dashboard.ts +399 -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 +321 -0
- package/src/modes/components/extensions/state-manager.ts +627 -0
- package/src/modes/components/extensions/types.ts +186 -0
- package/src/modes/components/footer.ts +275 -0
- package/src/modes/components/history-search.ts +280 -0
- package/src/modes/components/hook-editor.ts +167 -0
- package/src/modes/components/hook-input.ts +87 -0
- package/src/modes/components/hook-message.ts +67 -0
- package/src/modes/components/hook-selector.ts +659 -0
- package/src/modes/components/index.ts +38 -0
- package/src/modes/components/keybinding-hints.ts +65 -0
- package/src/modes/components/late-diagnostics-message.ts +60 -0
- package/src/modes/components/login-dialog.ts +164 -0
- package/src/modes/components/logout-account-selector.ts +130 -0
- package/src/modes/components/mcp-add-wizard.ts +1360 -0
- package/src/modes/components/message-frame.ts +92 -0
- package/src/modes/components/model-selector.ts +1315 -0
- package/src/modes/components/oauth-selector.ts +457 -0
- package/src/modes/components/omfg-panel.ts +141 -0
- package/src/modes/components/overlay-box.ts +109 -0
- package/src/modes/components/plan-review-overlay.ts +847 -0
- package/src/modes/components/plan-toc.ts +138 -0
- package/src/modes/components/plugin-selector.ts +95 -0
- package/src/modes/components/plugin-settings.ts +739 -0
- package/src/modes/components/queue-mode-selector.ts +56 -0
- package/src/modes/components/read-tool-group.ts +676 -0
- package/src/modes/components/reset-usage-selector.ts +161 -0
- package/src/modes/components/segment-track.ts +89 -0
- package/src/modes/components/session-selector.ts +631 -0
- package/src/modes/components/settings-defs.ts +225 -0
- package/src/modes/components/settings-selector.ts +1095 -0
- package/src/modes/components/show-images-selector.ts +45 -0
- package/src/modes/components/skill-message.ts +110 -0
- package/src/modes/components/snapcompact-shape-preview-doc.md +18 -0
- package/src/modes/components/snapcompact-shape-preview.ts +192 -0
- package/src/modes/components/status-line/component.ts +1001 -0
- package/src/modes/components/status-line/context-thresholds.ts +78 -0
- package/src/modes/components/status-line/git-utils.ts +42 -0
- package/src/modes/components/status-line/index.ts +5 -0
- package/src/modes/components/status-line/presets.ts +106 -0
- package/src/modes/components/status-line/segments.ts +616 -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 +124 -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 +24 -0
- package/src/modes/components/todo-reminder.ts +39 -0
- package/src/modes/components/tool-execution.ts +1165 -0
- package/src/modes/components/transcript-container.ts +806 -0
- package/src/modes/components/tree-selector.ts +994 -0
- package/src/modes/components/ttsr-notification.ts +123 -0
- package/src/modes/components/usage-row.ts +18 -0
- package/src/modes/components/user-message-selector.ts +227 -0
- package/src/modes/components/user-message.ts +68 -0
- package/src/modes/components/visual-truncate.ts +63 -0
- package/src/modes/components/welcome.ts +581 -0
- package/src/modes/controllers/btw-controller.ts +173 -0
- package/src/modes/controllers/command-controller-shared.ts +109 -0
- package/src/modes/controllers/command-controller.ts +1653 -0
- package/src/modes/controllers/event-controller.ts +1153 -0
- package/src/modes/controllers/extension-ui-controller.ts +893 -0
- package/src/modes/controllers/input-controller.ts +1627 -0
- package/src/modes/controllers/mcp-command-controller.ts +2162 -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 +1285 -0
- package/src/modes/controllers/session-focus-controller.ts +112 -0
- package/src/modes/controllers/ssh-command-controller.ts +384 -0
- package/src/modes/controllers/streaming-reveal.ts +295 -0
- package/src/modes/controllers/tan-command-controller.ts +190 -0
- package/src/modes/controllers/todo-command-controller.ts +485 -0
- package/src/modes/controllers/tool-args-reveal.ts +174 -0
- package/src/modes/data/emojis.json +1 -0
- package/src/modes/emoji-autocomplete.ts +285 -0
- package/src/modes/gradient-highlight.ts +99 -0
- package/src/modes/image-references.ts +137 -0
- package/src/modes/index.ts +17 -0
- package/src/modes/interactive-mode.ts +3940 -0
- package/src/modes/internal-url-autocomplete.ts +143 -0
- package/src/modes/loop-limit.ts +192 -0
- package/src/modes/magic-keywords.ts +42 -0
- package/src/modes/markdown-prose.ts +247 -0
- package/src/modes/oauth-manual-input.ts +69 -0
- package/src/modes/orchestrate.ts +42 -0
- package/src/modes/print-mode.ts +130 -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 +995 -0
- package/src/modes/rpc/rpc-mode.ts +1156 -0
- package/src/modes/rpc/rpc-subagents.ts +265 -0
- package/src/modes/rpc/rpc-types.ts +487 -0
- package/src/modes/runtime-init.ts +142 -0
- package/src/modes/session-observer-registry.ts +215 -0
- package/src/modes/setup-version.ts +11 -0
- package/src/modes/setup-wizard/index.ts +101 -0
- package/src/modes/setup-wizard/lazy.ts +16 -0
- package/src/modes/setup-wizard/scenes/glyph.ts +114 -0
- package/src/modes/setup-wizard/scenes/outro.ts +35 -0
- package/src/modes/setup-wizard/scenes/providers.ts +103 -0
- package/src/modes/setup-wizard/scenes/sign-in.ts +286 -0
- package/src/modes/setup-wizard/scenes/splash.ts +201 -0
- package/src/modes/setup-wizard/scenes/theme.ts +326 -0
- package/src/modes/setup-wizard/scenes/types.ts +57 -0
- package/src/modes/setup-wizard/scenes/web-search.ts +145 -0
- package/src/modes/setup-wizard/startup-splash.ts +107 -0
- package/src/modes/setup-wizard/wizard-overlay.ts +334 -0
- package/src/modes/shared.ts +49 -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 +92 -0
- package/src/modes/theme/shimmer.ts +235 -0
- package/src/modes/theme/theme-schema.json +459 -0
- package/src/modes/theme/theme.ts +2915 -0
- package/src/modes/turn-budget.ts +31 -0
- package/src/modes/types.ts +406 -0
- package/src/modes/ultrathink.ts +41 -0
- package/src/modes/utils/context-usage.ts +432 -0
- package/src/modes/utils/copy-targets.ts +360 -0
- package/src/modes/utils/hotkeys-markdown.ts +62 -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 +886 -0
- package/src/modes/workflow.ts +42 -0
- package/src/plan-mode/approved-plan.ts +186 -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 +45 -0
- package/src/prompts/advisor/advise-tool.md +3 -0
- package/src/prompts/advisor/system.md +113 -0
- package/src/prompts/agents/designer.md +74 -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 +119 -0
- package/src/prompts/agents/oracle.md +54 -0
- package/src/prompts/agents/plan.md +48 -0
- package/src/prompts/agents/reviewer.md +139 -0
- package/src/prompts/agents/task.md +17 -0
- package/src/prompts/bench.md +12 -0
- package/src/prompts/ci-green-request.md +36 -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/goals/guided-goal-interview.md +8 -0
- package/src/prompts/goals/guided-goal-system.md +12 -0
- package/src/prompts/low-end/system.md +47 -0
- package/src/prompts/memories/consolidation.md +30 -0
- package/src/prompts/memories/consolidation_system.md +4 -0
- package/src/prompts/memories/read-path.md +17 -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 +9 -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/autolearn-guidance-learn.md +1 -0
- package/src/prompts/system/autolearn-guidance.md +7 -0
- package/src/prompts/system/autolearn-nudge.md +3 -0
- package/src/prompts/system/background-tan-dispatch.md +8 -0
- package/src/prompts/system/btw-user.md +8 -0
- package/src/prompts/system/commit-message-system.md +14 -0
- package/src/prompts/system/custom-system-prompt.md +64 -0
- package/src/prompts/system/eager-task.md +7 -0
- package/src/prompts/system/eager-todo.md +18 -0
- package/src/prompts/system/empty-stop-retry.md +4 -0
- package/src/prompts/system/irc-autoreply.md +6 -0
- package/src/prompts/system/irc-incoming.md +7 -0
- package/src/prompts/system/manual-continue.md +7 -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 +50 -0
- package/src/prompts/system/orchestrate-notice.md +40 -0
- package/src/prompts/system/personalities/default.md +18 -0
- package/src/prompts/system/personalities/friendly.md +17 -0
- package/src/prompts/system/personalities/pragmatic.md +15 -0
- package/src/prompts/system/plan-mode-active.md +109 -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 +33 -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/snapcompact-context-frames-note.md +1 -0
- package/src/prompts/system/snapcompact-context-stub.md +1 -0
- package/src/prompts/system/snapcompact-system-frames-note.md +1 -0
- package/src/prompts/system/snapcompact-system-stub.md +1 -0
- package/src/prompts/system/snapcompact-toolresult-note.md +1 -0
- package/src/prompts/system/subagent-system-prompt.md +71 -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 +251 -0
- package/src/prompts/system/tiny-title-system.md +8 -0
- package/src/prompts/system/title-marker-instruction.md +1 -0
- package/src/prompts/system/title-system-marker.md +16 -0
- package/src/prompts/system/title-system.md +16 -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/unexpected-stop-classifier.md +17 -0
- package/src/prompts/system/unexpected-stop-retry.md +4 -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 +22 -0
- package/src/prompts/tools/ast-edit.md +22 -0
- package/src/prompts/tools/ast-grep.md +25 -0
- package/src/prompts/tools/async-result.md +8 -0
- package/src/prompts/tools/bash.md +45 -0
- package/src/prompts/tools/browser.md +42 -0
- package/src/prompts/tools/checkpoint.md +15 -0
- package/src/prompts/tools/debug.md +17 -0
- package/src/prompts/tools/eval.md +70 -0
- package/src/prompts/tools/find.md +19 -0
- package/src/prompts/tools/github.md +17 -0
- package/src/prompts/tools/goal.md +11 -0
- package/src/prompts/tools/image-attachment-describe-system.md +8 -0
- package/src/prompts/tools/image-attachment-describe.md +10 -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 +22 -0
- package/src/prompts/tools/irc.md +33 -0
- package/src/prompts/tools/job.md +17 -0
- package/src/prompts/tools/learn.md +7 -0
- package/src/prompts/tools/lsp-late-diagnostic.md +8 -0
- package/src/prompts/tools/lsp.md +39 -0
- package/src/prompts/tools/manage-skill.md +9 -0
- package/src/prompts/tools/memory-edit.md +8 -0
- package/src/prompts/tools/patch.md +57 -0
- package/src/prompts/tools/read.md +76 -0
- package/src/prompts/tools/recall.md +5 -0
- package/src/prompts/tools/reflect.md +5 -0
- package/src/prompts/tools/replace.md +29 -0
- package/src/prompts/tools/resolve.md +4 -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 +32 -0
- package/src/prompts/tools/search.md +22 -0
- package/src/prompts/tools/ssh.md +22 -0
- package/src/prompts/tools/task-summary.md +17 -0
- package/src/prompts/tools/task.md +91 -0
- package/src/prompts/tools/todo.md +39 -0
- package/src/prompts/tools/web-search.md +6 -0
- package/src/prompts/tools/write.md +14 -0
- package/src/registry/agent-lifecycle.ts +270 -0
- package/src/registry/agent-registry.ts +190 -0
- package/src/sdk.ts +2919 -0
- package/src/secrets/index.ts +123 -0
- package/src/secrets/obfuscator.ts +298 -0
- package/src/secrets/regex.ts +21 -0
- package/src/session/agent-session.ts +12539 -0
- package/src/session/agent-storage.ts +478 -0
- package/src/session/artifacts.ts +153 -0
- package/src/session/auth-broker-config.ts +92 -0
- package/src/session/auth-storage.ts +24 -0
- package/src/session/blob-store.ts +255 -0
- package/src/session/client-bridge.ts +85 -0
- package/src/session/codex-auto-reset.ts +202 -0
- package/src/session/compact-modes.ts +105 -0
- package/src/session/history-storage.ts +361 -0
- package/src/session/indexed-session-storage.ts +427 -0
- package/src/session/messages.ts +546 -0
- package/src/session/redis-session-storage.ts +170 -0
- package/src/session/session-context.ts +399 -0
- package/src/session/session-dump-format.ts +216 -0
- package/src/session/session-entries.ts +198 -0
- package/src/session/session-history-format.ts +308 -0
- package/src/session/session-listing.ts +588 -0
- package/src/session/session-loader.ts +93 -0
- package/src/session/session-manager.ts +1748 -0
- package/src/session/session-migrations.ts +78 -0
- package/src/session/session-paths.ts +193 -0
- package/src/session/session-persistence.ts +147 -0
- package/src/session/session-storage.ts +590 -0
- package/src/session/shake-types.ts +43 -0
- package/src/session/snapcompact-inline.ts +542 -0
- package/src/session/snapcompact-savings-journal.ts +113 -0
- package/src/session/sql-session-storage.ts +314 -0
- package/src/session/streaming-output.ts +1330 -0
- package/src/session/tool-choice-queue.ts +290 -0
- package/src/session/unexpected-stop-classifier.ts +129 -0
- package/src/session/yield-queue.ts +183 -0
- package/src/slash-commands/acp-builtins.ts +70 -0
- package/src/slash-commands/available-commands.ts +105 -0
- package/src/slash-commands/builtin-registry.ts +2332 -0
- package/src/slash-commands/helpers/active-oauth-account.ts +44 -0
- package/src/slash-commands/helpers/collab-qrcode.ts +28 -0
- package/src/slash-commands/helpers/context-report.ts +66 -0
- package/src/slash-commands/helpers/format.ts +46 -0
- package/src/slash-commands/helpers/logout.ts +88 -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/reset-usage.ts +66 -0
- package/src/slash-commands/helpers/ssh.ts +195 -0
- package/src/slash-commands/helpers/stats-dashboard.ts +85 -0
- package/src/slash-commands/helpers/todo.ts +279 -0
- package/src/slash-commands/helpers/usage-report.ts +128 -0
- package/src/slash-commands/marketplace-install-parser.ts +99 -0
- package/src/slash-commands/types.ts +135 -0
- package/src/ssh/config-writer.ts +183 -0
- package/src/ssh/connection-manager.ts +510 -0
- package/src/ssh/ssh-executor.ts +189 -0
- package/src/ssh/sshfs-mount.ts +140 -0
- package/src/ssh/utils.ts +8 -0
- package/src/startup-splash.ts +19 -0
- package/src/stt/asr-client.ts +521 -0
- package/src/stt/asr-protocol.ts +65 -0
- package/src/stt/asr-worker.ts +790 -0
- package/src/stt/downloader.ts +138 -0
- package/src/stt/endpointer.ts +259 -0
- package/src/stt/index.ts +7 -0
- package/src/stt/models.ts +150 -0
- package/src/stt/recorder.ts +538 -0
- package/src/stt/stt-controller.ts +380 -0
- package/src/stt/transcriber.ts +60 -0
- package/src/stt/wav.ts +173 -0
- package/src/system-prompt.ts +709 -0
- package/src/task/agents.ts +166 -0
- package/src/task/commands.ts +132 -0
- package/src/task/discovery.ts +122 -0
- package/src/task/executor.ts +2356 -0
- package/src/task/index.ts +1580 -0
- package/src/task/name-generator.ts +1577 -0
- package/src/task/omp-command.ts +26 -0
- package/src/task/output-manager.ts +93 -0
- package/src/task/parallel.ts +116 -0
- package/src/task/persisted-revive.ts +128 -0
- package/src/task/render.ts +1558 -0
- package/src/task/repair-args.ts +129 -0
- package/src/task/subprocess-tool-registry.ts +88 -0
- package/src/task/types.ts +401 -0
- package/src/task/worktree.ts +514 -0
- package/src/telemetry-export.ts +144 -0
- package/src/thinking.ts +187 -0
- package/src/tiny/device.ts +111 -0
- package/src/tiny/dtype.ts +101 -0
- package/src/tiny/models.ts +252 -0
- package/src/tiny/text.ts +169 -0
- package/src/tiny/title-client.ts +538 -0
- package/src/tiny/title-protocol.ts +56 -0
- package/src/tiny/worker.ts +491 -0
- package/src/tool-discovery/mode.ts +24 -0
- package/src/tool-discovery/tool-index.ts +271 -0
- package/src/tools/__tests__/json-tree.test.ts +35 -0
- package/src/tools/approval.ts +189 -0
- package/src/tools/ask.ts +977 -0
- package/src/tools/ast-edit.ts +700 -0
- package/src/tools/ast-grep.ts +483 -0
- package/src/tools/auto-generated-guard.ts +322 -0
- package/src/tools/bash-command-fixup.ts +37 -0
- package/src/tools/bash-interactive.ts +408 -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 +1405 -0
- package/src/tools/browser/attach.ts +194 -0
- package/src/tools/browser/cmux/cmux-tab.ts +1264 -0
- package/src/tools/browser/cmux/rpc.ts +156 -0
- package/src/tools/browser/cmux/socket-client.ts +309 -0
- package/src/tools/browser/launch.ts +673 -0
- package/src/tools/browser/readable.ts +112 -0
- package/src/tools/browser/registry.ts +241 -0
- package/src/tools/browser/render.ts +221 -0
- package/src/tools/browser/tab-protocol.ts +107 -0
- package/src/tools/browser/tab-supervisor.ts +799 -0
- package/src/tools/browser/tab-worker-entry.ts +29 -0
- package/src/tools/browser/tab-worker.ts +1226 -0
- package/src/tools/browser.ts +403 -0
- package/src/tools/builtin-names.ts +34 -0
- package/src/tools/checkpoint.ts +136 -0
- package/src/tools/conflict-detect.ts +718 -0
- package/src/tools/context.ts +39 -0
- package/src/tools/debug.ts +1087 -0
- package/src/tools/eval-backends.ts +27 -0
- package/src/tools/eval-render.ts +762 -0
- package/src/tools/eval.ts +600 -0
- package/src/tools/fetch.ts +1902 -0
- package/src/tools/file-recorder.ts +35 -0
- package/src/tools/find.ts +629 -0
- package/src/tools/fs-cache-invalidation.ts +28 -0
- package/src/tools/gh-cache-invalidation.ts +255 -0
- package/src/tools/gh-format.ts +12 -0
- package/src/tools/gh-renderer.ts +481 -0
- package/src/tools/gh.ts +3752 -0
- package/src/tools/github-cache.ts +663 -0
- package/src/tools/grouped-file-output.ts +210 -0
- package/src/tools/image-gen.ts +1586 -0
- package/src/tools/index.ts +649 -0
- package/src/tools/inspect-image-renderer.ts +132 -0
- package/src/tools/inspect-image.ts +260 -0
- package/src/tools/irc.ts +788 -0
- package/src/tools/job.ts +612 -0
- package/src/tools/json-tree.ts +260 -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/learn.ts +141 -0
- package/src/tools/list-limit.ts +40 -0
- package/src/tools/manage-skill.ts +100 -0
- package/src/tools/match-line-format.ts +20 -0
- package/src/tools/memory-edit.ts +59 -0
- package/src/tools/memory-recall.ts +102 -0
- package/src/tools/memory-reflect.ts +88 -0
- package/src/tools/memory-render.ts +202 -0
- package/src/tools/memory-retain.ts +89 -0
- package/src/tools/output-meta.ts +768 -0
- package/src/tools/output-schema-validator.ts +132 -0
- package/src/tools/path-utils.ts +1116 -0
- package/src/tools/plan-mode-guard.ts +142 -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 +208 -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 +3124 -0
- package/src/tools/render-utils.ts +895 -0
- package/src/tools/renderers.ts +86 -0
- package/src/tools/report-tool-issue.ts +530 -0
- package/src/tools/resolve.ts +302 -0
- package/src/tools/review.ts +251 -0
- package/src/tools/search-tool-bm25.ts +351 -0
- package/src/tools/search.ts +1583 -0
- package/src/tools/sqlite-reader.ts +828 -0
- package/src/tools/ssh.ts +369 -0
- package/src/tools/todo.ts +938 -0
- package/src/tools/tool-errors.ts +62 -0
- package/src/tools/tool-result.ts +102 -0
- package/src/tools/tool-timeouts.ts +30 -0
- package/src/tools/tts.ts +265 -0
- package/src/tools/write.ts +1182 -0
- package/src/tools/yield.ts +269 -0
- package/src/tts/downloader.ts +64 -0
- package/src/tts/index.ts +8 -0
- package/src/tts/models.ts +137 -0
- package/src/tts/player.ts +137 -0
- package/src/tts/runtime.ts +21 -0
- package/src/tts/streaming-player.ts +266 -0
- package/src/tts/tts-client.ts +642 -0
- package/src/tts/tts-protocol.ts +60 -0
- package/src/tts/tts-worker.ts +505 -0
- package/src/tts/vocalizer.ts +162 -0
- package/src/tts/wav.ts +58 -0
- package/src/tui/code-cell.ts +257 -0
- package/src/tui/file-list.ts +55 -0
- package/src/tui/hyperlink.ts +178 -0
- package/src/tui/index.ts +13 -0
- package/src/tui/output-block.ts +240 -0
- package/src/tui/status-line.ts +54 -0
- package/src/tui/tree-list.ts +133 -0
- package/src/tui/types.ts +15 -0
- package/src/tui/utils.ts +103 -0
- package/src/tui/width-aware-text.ts +58 -0
- package/src/utils/block-context.ts +312 -0
- package/src/utils/changelog.ts +132 -0
- package/src/utils/clipboard.ts +262 -0
- package/src/utils/command-args.ts +76 -0
- package/src/utils/commit-message-generator.ts +147 -0
- package/src/utils/edit-mode.ts +41 -0
- package/src/utils/enhanced-paste.ts +230 -0
- package/src/utils/event-bus.ts +33 -0
- package/src/utils/external-editor.ts +78 -0
- package/src/utils/file-display-mode.ts +45 -0
- package/src/utils/file-mentions.ts +284 -0
- package/src/utils/git.ts +1838 -0
- package/src/utils/image-loading.ts +231 -0
- package/src/utils/image-resize.ts +309 -0
- package/src/utils/image-vision-fallback.ts +197 -0
- package/src/utils/ipc.ts +38 -0
- package/src/utils/jj.ts +248 -0
- package/src/utils/lang-from-path.ts +244 -0
- package/src/utils/markit.ts +143 -0
- package/src/utils/mupdf-wasm-embed.ts +12 -0
- package/src/utils/open.ts +55 -0
- package/src/utils/qrcode.ts +535 -0
- package/src/utils/session-color.ts +142 -0
- package/src/utils/shell-snapshot.ts +187 -0
- package/src/utils/sixel.ts +69 -0
- package/src/utils/thinking-display.ts +11 -0
- package/src/utils/title-generator.ts +416 -0
- package/src/utils/tool-choice.ts +49 -0
- package/src/utils/tools-manager.ts +372 -0
- package/src/utils/turndown.ts +83 -0
- package/src/utils/zip.ts +1091 -0
- package/src/web/kagi.ts +304 -0
- package/src/web/parallel.ts +353 -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 +652 -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 +800 -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 +94 -0
- package/src/web/scrapers/types.ts +354 -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 +325 -0
- package/src/web/search/index.ts +317 -0
- package/src/web/search/provider.ts +169 -0
- package/src/web/search/providers/anthropic.ts +343 -0
- package/src/web/search/providers/base.ts +90 -0
- package/src/web/search/providers/brave.ts +152 -0
- package/src/web/search/providers/codex.ts +593 -0
- package/src/web/search/providers/exa.ts +400 -0
- package/src/web/search/providers/gemini.ts +518 -0
- package/src/web/search/providers/jina.ts +111 -0
- package/src/web/search/providers/kagi.ts +86 -0
- package/src/web/search/providers/kimi.ts +196 -0
- package/src/web/search/providers/parallel.ts +225 -0
- package/src/web/search/providers/perplexity-auth.ts +133 -0
- package/src/web/search/providers/perplexity.ts +866 -0
- package/src/web/search/providers/searxng.ts +325 -0
- package/src/web/search/providers/synthetic.ts +114 -0
- package/src/web/search/providers/tavily.ts +176 -0
- package/src/web/search/providers/utils.ts +128 -0
- package/src/web/search/providers/zai.ts +333 -0
- package/src/web/search/render.ts +262 -0
- package/src/web/search/types.ts +462 -0
- package/src/web/search/utils.ts +17 -0
- package/src/workspace-tree.ts +326 -0
|
@@ -0,0 +1,2162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Command Controller
|
|
3
|
+
*
|
|
4
|
+
* Handles /mcp subcommands for managing MCP servers.
|
|
5
|
+
*/
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
import { type Component, replaceTabs, Spacer, Text } from "@oh-my-pi/pi-tui";
|
|
8
|
+
import { getMCPConfigPath, getProjectDir } from "@oh-my-pi/pi-utils";
|
|
9
|
+
import type { SourceMeta } from "../../capability/types";
|
|
10
|
+
import { expandEnvVarsDeep } from "../../discovery/helpers";
|
|
11
|
+
import { analyzeAuthError, discoverOAuthEndpoints, MCPManager } from "../../mcp";
|
|
12
|
+
import { connectToServer, disconnectServer, listTools } from "../../mcp/client";
|
|
13
|
+
import {
|
|
14
|
+
addMCPServer,
|
|
15
|
+
readDisabledServers,
|
|
16
|
+
readMCPConfigFile,
|
|
17
|
+
removeMCPServer,
|
|
18
|
+
setServerDisabled,
|
|
19
|
+
updateMCPServer,
|
|
20
|
+
} from "../../mcp/config-writer";
|
|
21
|
+
import {
|
|
22
|
+
lookupMcpOAuthCredentialForServer,
|
|
23
|
+
mcpOAuthCredentialIdsForServerUrl,
|
|
24
|
+
removeManagedMcpOAuthCredential,
|
|
25
|
+
removeManagedMcpOAuthCredentials,
|
|
26
|
+
} from "../../mcp/oauth-credentials";
|
|
27
|
+
import { MCPOAuthFlow, type MCPStoredOAuthCredential, mcpOAuthCredentialId } from "../../mcp/oauth-flow";
|
|
28
|
+
import {
|
|
29
|
+
clearSmitheryApiKey,
|
|
30
|
+
createSmitheryCliAuthSession,
|
|
31
|
+
getSmitheryApiKey,
|
|
32
|
+
getSmitheryLoginUrl,
|
|
33
|
+
pollSmitheryCliAuthSession,
|
|
34
|
+
saveSmitheryApiKey,
|
|
35
|
+
} from "../../mcp/smithery-auth";
|
|
36
|
+
import { SmitheryConnectError } from "../../mcp/smithery-connect";
|
|
37
|
+
import {
|
|
38
|
+
SmitheryRegistryError,
|
|
39
|
+
type SmitherySearchResult,
|
|
40
|
+
searchSmitheryRegistry,
|
|
41
|
+
toConfigName,
|
|
42
|
+
} from "../../mcp/smithery-registry";
|
|
43
|
+
import type { MCPAuthConfig, MCPServerConfig, MCPServerConnection } from "../../mcp/types";
|
|
44
|
+
import { shortenPath } from "../../tools/render-utils";
|
|
45
|
+
import { urlHyperlinkAlways } from "../../tui";
|
|
46
|
+
import { openPath } from "../../utils/open";
|
|
47
|
+
import { ChatBlock } from "../components/chat-block";
|
|
48
|
+
import { MCPAddWizard } from "../components/mcp-add-wizard";
|
|
49
|
+
import { TranscriptBlock } from "../components/transcript-container";
|
|
50
|
+
import { parseCommandArgs } from "../shared";
|
|
51
|
+
import { theme } from "../theme/theme";
|
|
52
|
+
import type { InteractiveModeContext } from "../types";
|
|
53
|
+
import { groupBySource, parseRemoveArgs, readScopeFlag, showCommandMessage } from "./command-controller-shared";
|
|
54
|
+
|
|
55
|
+
const MCP_MANUAL_INPUT_PROVIDER_ID = "mcp";
|
|
56
|
+
const MCP_MANUAL_LOGIN_TIP = "Headless? Paste the redirect URL or code with /login <value>.";
|
|
57
|
+
function withTimeout<T>(promise: Promise<T>, timeoutMs: number, message: string, onTimeout?: () => void): Promise<T> {
|
|
58
|
+
const { promise: timeoutPromise, reject } = Promise.withResolvers<T>();
|
|
59
|
+
const timer = setTimeout(() => {
|
|
60
|
+
onTimeout?.();
|
|
61
|
+
reject(new Error(message));
|
|
62
|
+
}, timeoutMs);
|
|
63
|
+
return Promise.race([promise, timeoutPromise]).finally(() => clearTimeout(timer));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Renders the MCP OAuth fallback URL without hard-wrapping the copy target. */
|
|
67
|
+
export class MCPAuthorizationLinkPrompt implements Component {
|
|
68
|
+
readonly #url: string;
|
|
69
|
+
|
|
70
|
+
constructor(url: string) {
|
|
71
|
+
this.#url = url;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
invalidate(): void {}
|
|
75
|
+
|
|
76
|
+
render(_width: number): readonly string[] {
|
|
77
|
+
const link = urlHyperlinkAlways(this.#url, "Click here to authorize");
|
|
78
|
+
return [
|
|
79
|
+
` ${theme.fg("success", "Open authorization URL:")}`,
|
|
80
|
+
` ${theme.fg("accent", link)}`,
|
|
81
|
+
` ${theme.fg("muted", `Copy URL: ${replaceTabs(this.#url)}`)}`,
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Animated "Connecting to …" transcript block. Owns its spinner interval: it
|
|
88
|
+
* starts on mount and is cleared on {@link ChatBlock.finish}/dispose, so callers
|
|
89
|
+
* never juggle `setInterval`/`clearInterval` or `requestRender` by hand.
|
|
90
|
+
*/
|
|
91
|
+
class McpConnectingBlock extends ChatBlock {
|
|
92
|
+
readonly #text: Text;
|
|
93
|
+
|
|
94
|
+
constructor(private readonly serverName: string) {
|
|
95
|
+
super();
|
|
96
|
+
this.addChild(new Spacer(1));
|
|
97
|
+
const frame = theme.spinnerFrames[0] ?? "|";
|
|
98
|
+
this.#text = new Text(theme.fg("muted", `${frame} Connecting to "${serverName}"...`), 1, 0);
|
|
99
|
+
this.addChild(this.#text);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
protected override onMount(): void {
|
|
103
|
+
const frames = theme.spinnerFrames;
|
|
104
|
+
let frame = 0;
|
|
105
|
+
const interval = setInterval(() => {
|
|
106
|
+
frame++;
|
|
107
|
+
this.#text.setText(
|
|
108
|
+
theme.fg("muted", `${frames[frame % frames.length] ?? "|"} Connecting to "${this.serverName}"...`),
|
|
109
|
+
);
|
|
110
|
+
this.requestRender();
|
|
111
|
+
}, 80);
|
|
112
|
+
this.onCleanup(() => clearInterval(interval));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Replace the spinner line with a terminal status; pair with {@link finish}. */
|
|
116
|
+
setStatus(text: string): void {
|
|
117
|
+
this.#text.setText(text);
|
|
118
|
+
this.requestRender();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Outcome of {@link MCPCommandController}'s OAuth handler.
|
|
124
|
+
*
|
|
125
|
+
* `credentialId` is deterministic per server URL when the URL was supplied, so
|
|
126
|
+
* every profile resolves its own credential row under the same id. Refresh
|
|
127
|
+
* material (token URL, client id/secret) is embedded in the stored credential;
|
|
128
|
+
* the returned `clientId` may be folded into `mcp.json` for pre-auth reuse.
|
|
129
|
+
* DCR-issued client secrets stay embedded in the stored credential and are
|
|
130
|
+
* deliberately not surfaced here, so they cannot leak into config files.
|
|
131
|
+
*/
|
|
132
|
+
interface OAuthFlowResult {
|
|
133
|
+
credentialId: string;
|
|
134
|
+
clientId?: string;
|
|
135
|
+
resource?: string;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
type MCPAddScope = "user" | "project";
|
|
139
|
+
type MCPAddTransport = "http" | "sse";
|
|
140
|
+
|
|
141
|
+
type MCPAddParsed = {
|
|
142
|
+
initialName?: string;
|
|
143
|
+
scope: MCPAddScope;
|
|
144
|
+
quickConfig?: MCPServerConfig;
|
|
145
|
+
isCommandQuickAdd?: boolean;
|
|
146
|
+
hasAuthToken?: boolean;
|
|
147
|
+
error?: string;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
type MCPSearchParsed = {
|
|
151
|
+
keyword: string;
|
|
152
|
+
scope: MCPAddScope;
|
|
153
|
+
limit: number;
|
|
154
|
+
semantic: boolean;
|
|
155
|
+
error?: string;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export class MCPCommandController {
|
|
159
|
+
constructor(private ctx: InteractiveModeContext) {}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Handle /mcp command and route to subcommands
|
|
163
|
+
*/
|
|
164
|
+
async handle(text: string): Promise<void> {
|
|
165
|
+
const parts = text.trim().split(/\s+/);
|
|
166
|
+
const subcommand = parts[1]?.toLowerCase();
|
|
167
|
+
|
|
168
|
+
if (!subcommand || subcommand === "help") {
|
|
169
|
+
this.#showHelp();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
switch (subcommand) {
|
|
174
|
+
case "add":
|
|
175
|
+
await this.#handleAdd(text);
|
|
176
|
+
break;
|
|
177
|
+
case "list":
|
|
178
|
+
await this.#handleList();
|
|
179
|
+
break;
|
|
180
|
+
case "remove":
|
|
181
|
+
case "rm":
|
|
182
|
+
await this.#handleRemove(text);
|
|
183
|
+
break;
|
|
184
|
+
case "test":
|
|
185
|
+
await this.#handleTest(parts[2]);
|
|
186
|
+
break;
|
|
187
|
+
case "reauth":
|
|
188
|
+
await this.#handleReauth(parts[2]);
|
|
189
|
+
break;
|
|
190
|
+
case "unauth":
|
|
191
|
+
await this.#handleUnauth(parts[2]);
|
|
192
|
+
break;
|
|
193
|
+
case "enable":
|
|
194
|
+
await this.#handleSetEnabled(parts[2], true);
|
|
195
|
+
break;
|
|
196
|
+
case "disable":
|
|
197
|
+
await this.#handleSetEnabled(parts[2], false);
|
|
198
|
+
break;
|
|
199
|
+
case "resources":
|
|
200
|
+
await this.#handleResources();
|
|
201
|
+
break;
|
|
202
|
+
case "prompts":
|
|
203
|
+
await this.#handlePrompts();
|
|
204
|
+
break;
|
|
205
|
+
case "notifications":
|
|
206
|
+
await this.#handleNotifications();
|
|
207
|
+
break;
|
|
208
|
+
case "smithery-search":
|
|
209
|
+
await this.#handleSearch(text);
|
|
210
|
+
break;
|
|
211
|
+
case "smithery-login":
|
|
212
|
+
await this.#handleSmitheryLogin();
|
|
213
|
+
break;
|
|
214
|
+
case "smithery-logout":
|
|
215
|
+
await this.#handleSmitheryLogout();
|
|
216
|
+
break;
|
|
217
|
+
case "reconnect":
|
|
218
|
+
await this.#handleReconnect(parts[2]);
|
|
219
|
+
break;
|
|
220
|
+
case "reload":
|
|
221
|
+
await this.#handleReload();
|
|
222
|
+
break;
|
|
223
|
+
default:
|
|
224
|
+
this.ctx.showError(`Unknown subcommand: ${subcommand}. Type /mcp help for usage.`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Show help text
|
|
230
|
+
*/
|
|
231
|
+
#showHelp(): void {
|
|
232
|
+
const helpText = [
|
|
233
|
+
"",
|
|
234
|
+
theme.bold("MCP Server Management"),
|
|
235
|
+
"",
|
|
236
|
+
"Manage Model Context Protocol (MCP) servers for external tool integrations.",
|
|
237
|
+
"",
|
|
238
|
+
theme.fg("accent", "Commands:"),
|
|
239
|
+
" /mcp add Add a new MCP server (interactive wizard)",
|
|
240
|
+
" /mcp add <name> [--scope project|user] [--url <url> --transport http|sse] [--token <token>] [-- <command...>]",
|
|
241
|
+
" /mcp list List all configured MCP servers",
|
|
242
|
+
" /mcp remove <name> [--scope project|user] Remove an MCP server (default: project)",
|
|
243
|
+
" /mcp test <name> Test connection to an MCP server",
|
|
244
|
+
" /mcp reauth <name> Reauthorize OAuth for an MCP server",
|
|
245
|
+
" /mcp unauth <name> Remove OAuth auth from an MCP server",
|
|
246
|
+
" /mcp enable <name> Enable an MCP server",
|
|
247
|
+
" /mcp disable <name> Disable an MCP server",
|
|
248
|
+
" /mcp smithery-search <keyword> [--scope project|user] [--limit <1-100>] [--semantic]",
|
|
249
|
+
" Search Smithery registry and deploy from picker",
|
|
250
|
+
" /mcp smithery-login Login to Smithery and cache API key",
|
|
251
|
+
" /mcp smithery-logout Remove cached Smithery API key",
|
|
252
|
+
" /mcp reconnect <name> Reconnect to a specific MCP server",
|
|
253
|
+
" /mcp reload Force reload and rediscover MCP runtime tools",
|
|
254
|
+
" /mcp resources List available resources from connected servers",
|
|
255
|
+
" /mcp prompts List available prompts from connected servers",
|
|
256
|
+
" /mcp notifications Show notification capabilities and subscription state",
|
|
257
|
+
" /mcp help Show this help message",
|
|
258
|
+
"",
|
|
259
|
+
].join("\n");
|
|
260
|
+
|
|
261
|
+
this.#showMessage(helpText);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
#parseAddCommand(text: string): MCPAddParsed {
|
|
265
|
+
const prefixMatch = text.match(/^\/mcp\s+add\b\s*(.*)$/i);
|
|
266
|
+
const rest = prefixMatch?.[1]?.trim() ?? "";
|
|
267
|
+
if (!rest) {
|
|
268
|
+
return { scope: "project" };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const tokens = parseCommandArgs(rest);
|
|
272
|
+
if (tokens.length === 0) {
|
|
273
|
+
return { scope: "project" };
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
let name: string | undefined;
|
|
277
|
+
let scope: MCPAddScope = "project";
|
|
278
|
+
let url: string | undefined;
|
|
279
|
+
let transport: MCPAddTransport = "http";
|
|
280
|
+
let authToken: string | undefined;
|
|
281
|
+
let commandTokens: string[] | undefined;
|
|
282
|
+
|
|
283
|
+
let i = 0;
|
|
284
|
+
if (!tokens[0].startsWith("-")) {
|
|
285
|
+
name = tokens[0];
|
|
286
|
+
i = 1;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
while (i < tokens.length) {
|
|
290
|
+
const argToken = tokens[i];
|
|
291
|
+
if (argToken === "--") {
|
|
292
|
+
commandTokens = tokens.slice(i + 1);
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
if (argToken === "--scope") {
|
|
296
|
+
const r = readScopeFlag(tokens[i + 1]);
|
|
297
|
+
if (!r.ok) {
|
|
298
|
+
return { scope, error: r.error };
|
|
299
|
+
}
|
|
300
|
+
scope = r.scope;
|
|
301
|
+
i += 2;
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
if (argToken === "--url") {
|
|
305
|
+
const value = tokens[i + 1];
|
|
306
|
+
if (!value) {
|
|
307
|
+
return { scope, error: "Missing value for --url." };
|
|
308
|
+
}
|
|
309
|
+
url = value;
|
|
310
|
+
i += 2;
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (argToken === "--transport") {
|
|
314
|
+
const value = tokens[i + 1];
|
|
315
|
+
if (!value || (value !== "http" && value !== "sse")) {
|
|
316
|
+
return { scope, error: "Invalid --transport value. Use http or sse." };
|
|
317
|
+
}
|
|
318
|
+
transport = value;
|
|
319
|
+
i += 2;
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
if (argToken === "--token") {
|
|
323
|
+
const value = tokens[i + 1];
|
|
324
|
+
if (!value) {
|
|
325
|
+
return { scope, error: "Missing value for --token." };
|
|
326
|
+
}
|
|
327
|
+
authToken = value;
|
|
328
|
+
i += 2;
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
return { scope, error: `Unknown option: ${argToken}` };
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const hasQuick = Boolean(url) || Boolean(commandTokens && commandTokens.length > 0);
|
|
335
|
+
if (!hasQuick) {
|
|
336
|
+
return { scope, initialName: name };
|
|
337
|
+
}
|
|
338
|
+
if (!name) {
|
|
339
|
+
return { scope, error: "Server name required for quick add. Usage: /mcp add <name> ..." };
|
|
340
|
+
}
|
|
341
|
+
if (url && commandTokens && commandTokens.length > 0) {
|
|
342
|
+
return { scope, error: "Use either --url or -- <command...>, not both." };
|
|
343
|
+
}
|
|
344
|
+
if (authToken && !url) {
|
|
345
|
+
return { scope, error: "--token requires --url (HTTP/SSE transport)." };
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (commandTokens && commandTokens.length > 0) {
|
|
349
|
+
const [command, ...args] = commandTokens;
|
|
350
|
+
const config: MCPServerConfig = {
|
|
351
|
+
type: "stdio",
|
|
352
|
+
command,
|
|
353
|
+
args: args.length > 0 ? args : undefined,
|
|
354
|
+
};
|
|
355
|
+
return { scope, initialName: name, quickConfig: config, isCommandQuickAdd: true };
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const useHttpTransport = transport === "http";
|
|
359
|
+
let normalizedUrl = url!;
|
|
360
|
+
if (!/^https?:\/\//i.test(normalizedUrl)) {
|
|
361
|
+
normalizedUrl = `https://${normalizedUrl}`;
|
|
362
|
+
}
|
|
363
|
+
const config: MCPServerConfig = {
|
|
364
|
+
type: useHttpTransport ? "http" : "sse",
|
|
365
|
+
url: normalizedUrl,
|
|
366
|
+
headers: authToken ? { Authorization: `Bearer ${authToken}` } : undefined,
|
|
367
|
+
};
|
|
368
|
+
return {
|
|
369
|
+
scope,
|
|
370
|
+
initialName: name,
|
|
371
|
+
quickConfig: config,
|
|
372
|
+
isCommandQuickAdd: false,
|
|
373
|
+
hasAuthToken: Boolean(authToken),
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
#parseSearchCommand(text: string): MCPSearchParsed {
|
|
378
|
+
const prefixMatch = text.match(/^\/mcp\s+smithery-search\b\s*(.*)$/i);
|
|
379
|
+
const rest = prefixMatch?.[1]?.trim() ?? "";
|
|
380
|
+
const tokens = parseCommandArgs(rest);
|
|
381
|
+
if (tokens.length === 0) {
|
|
382
|
+
return {
|
|
383
|
+
keyword: "",
|
|
384
|
+
scope: "project",
|
|
385
|
+
limit: 20,
|
|
386
|
+
semantic: false,
|
|
387
|
+
error: "Keyword required. Usage: /mcp smithery-search <keyword> [--scope project|user] [--limit <1-100>] [--semantic]",
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const keywordParts: string[] = [];
|
|
392
|
+
let scope: MCPAddScope = "project";
|
|
393
|
+
let limit = 20;
|
|
394
|
+
let semantic = false;
|
|
395
|
+
|
|
396
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
397
|
+
const token = tokens[i];
|
|
398
|
+
if (token === "--scope") {
|
|
399
|
+
const value = tokens[i + 1];
|
|
400
|
+
if (!value || (value !== "project" && value !== "user")) {
|
|
401
|
+
return { keyword: "", scope, limit, semantic, error: "Invalid --scope value. Use project or user." };
|
|
402
|
+
}
|
|
403
|
+
scope = value;
|
|
404
|
+
i++;
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
if (token === "--limit") {
|
|
408
|
+
const value = tokens[i + 1];
|
|
409
|
+
if (!value) {
|
|
410
|
+
return { keyword: "", scope, limit, semantic, error: "Missing value for --limit." };
|
|
411
|
+
}
|
|
412
|
+
const parsed = Number(value);
|
|
413
|
+
if (!Number.isInteger(parsed) || parsed < 1 || parsed > 100) {
|
|
414
|
+
return {
|
|
415
|
+
keyword: "",
|
|
416
|
+
scope,
|
|
417
|
+
limit,
|
|
418
|
+
semantic,
|
|
419
|
+
error: "Invalid --limit value. Use an integer between 1 and 100.",
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
limit = parsed;
|
|
423
|
+
i++;
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
if (token === "--semantic") {
|
|
427
|
+
semantic = true;
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
if (token.startsWith("--")) {
|
|
431
|
+
return { keyword: "", scope, limit, semantic, error: `Unknown option: ${token}` };
|
|
432
|
+
}
|
|
433
|
+
keywordParts.push(token);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const keyword = keywordParts.join(" ").trim();
|
|
437
|
+
if (!keyword) {
|
|
438
|
+
return {
|
|
439
|
+
keyword: "",
|
|
440
|
+
scope,
|
|
441
|
+
limit,
|
|
442
|
+
semantic,
|
|
443
|
+
error: "Keyword required. Usage: /mcp smithery-search <keyword> [--scope project|user] [--limit <1-100>] [--semantic]",
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
return { keyword, scope, limit, semantic };
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Handle /mcp add - Launch interactive wizard or quick-add from args
|
|
452
|
+
*/
|
|
453
|
+
async #handleAdd(text: string): Promise<void> {
|
|
454
|
+
const parsed = this.#parseAddCommand(text);
|
|
455
|
+
if (parsed.error) {
|
|
456
|
+
this.ctx.showError(parsed.error);
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (parsed.quickConfig && parsed.initialName) {
|
|
460
|
+
let finalConfig = parsed.quickConfig;
|
|
461
|
+
|
|
462
|
+
// Quick-add with URL should still perform auth detection and OAuth flow,
|
|
463
|
+
// matching wizard behavior. Command quick-add intentionally skips this.
|
|
464
|
+
if (!parsed.isCommandQuickAdd && (finalConfig.type === "http" || finalConfig.type === "sse")) {
|
|
465
|
+
try {
|
|
466
|
+
await this.#handleTestConnection(finalConfig);
|
|
467
|
+
} catch (error) {
|
|
468
|
+
if (parsed.hasAuthToken) {
|
|
469
|
+
this.ctx.showError(
|
|
470
|
+
`Authentication failed for "${parsed.initialName}": ${error instanceof Error ? error.message : String(error)}`,
|
|
471
|
+
);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
const authResult = analyzeAuthError(error as Error, finalConfig.url);
|
|
475
|
+
if (authResult.requiresAuth) {
|
|
476
|
+
let oauth = authResult.authType === "oauth" ? (authResult.oauth ?? null) : null;
|
|
477
|
+
if (!oauth && finalConfig.url) {
|
|
478
|
+
try {
|
|
479
|
+
oauth = await discoverOAuthEndpoints(
|
|
480
|
+
finalConfig.url,
|
|
481
|
+
authResult.authServerUrl,
|
|
482
|
+
authResult.resourceMetadataUrl,
|
|
483
|
+
);
|
|
484
|
+
} catch {
|
|
485
|
+
// Ignore discovery error and handle below.
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
if (!oauth) {
|
|
490
|
+
this.ctx.showError(
|
|
491
|
+
`Authentication required for "${parsed.initialName}", but OAuth endpoints could not be discovered. ` +
|
|
492
|
+
`Use /mcp add ${parsed.initialName} (wizard) or configure auth manually.`,
|
|
493
|
+
);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
try {
|
|
498
|
+
const oauthResource = oauth.resource ?? finalConfig.url;
|
|
499
|
+
const oauthResult = await this.#handleOAuthFlow(
|
|
500
|
+
oauth.authorizationUrl,
|
|
501
|
+
oauth.tokenUrl,
|
|
502
|
+
oauth.clientId ?? finalConfig.oauth?.clientId ?? "",
|
|
503
|
+
finalConfig.oauth?.clientSecret ?? "",
|
|
504
|
+
oauth.scopes ?? "",
|
|
505
|
+
{
|
|
506
|
+
callbackPort: finalConfig.oauth?.callbackPort,
|
|
507
|
+
callbackPath: finalConfig.oauth?.callbackPath,
|
|
508
|
+
redirectUri: finalConfig.oauth?.redirectUri,
|
|
509
|
+
prompt: finalConfig.oauth?.prompt,
|
|
510
|
+
serverUrl: finalConfig.url,
|
|
511
|
+
resource: oauthResource,
|
|
512
|
+
},
|
|
513
|
+
);
|
|
514
|
+
finalConfig = this.#persistOAuthResult(finalConfig, oauthResult, {
|
|
515
|
+
tokenUrl: oauth.tokenUrl,
|
|
516
|
+
resource: oauthResource,
|
|
517
|
+
clientId: oauth.clientId,
|
|
518
|
+
userClientSecret: finalConfig.oauth?.clientSecret,
|
|
519
|
+
});
|
|
520
|
+
} catch (oauthError) {
|
|
521
|
+
this.ctx.showError(
|
|
522
|
+
`OAuth flow failed for "${parsed.initialName}": ${oauthError instanceof Error ? oauthError.message : String(oauthError)}`,
|
|
523
|
+
);
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
await this.#handleWizardComplete(parsed.initialName, finalConfig, parsed.scope);
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// Save current editor state
|
|
535
|
+
const done = () => {
|
|
536
|
+
this.ctx.editorContainer.clear();
|
|
537
|
+
this.ctx.editorContainer.addChild(this.ctx.editor);
|
|
538
|
+
this.ctx.ui.setFocus(this.ctx.editor);
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
// Create wizard with OAuth handler and connection test
|
|
542
|
+
const wizard = new MCPAddWizard(
|
|
543
|
+
async (name: string, config: MCPServerConfig, scope: "user" | "project") => {
|
|
544
|
+
done();
|
|
545
|
+
await this.#handleWizardComplete(name, config, scope);
|
|
546
|
+
},
|
|
547
|
+
() => {
|
|
548
|
+
done();
|
|
549
|
+
this.#handleWizardCancel();
|
|
550
|
+
},
|
|
551
|
+
async (authUrl: string, tokenUrl: string, clientId: string, clientSecret: string, scopes: string, options) => {
|
|
552
|
+
return await this.#handleOAuthFlow(authUrl, tokenUrl, clientId, clientSecret, scopes, options);
|
|
553
|
+
},
|
|
554
|
+
async (config: MCPServerConfig) => {
|
|
555
|
+
return await this.#handleTestConnection(config);
|
|
556
|
+
},
|
|
557
|
+
() => {
|
|
558
|
+
this.ctx.ui.requestRender();
|
|
559
|
+
},
|
|
560
|
+
parsed.initialName,
|
|
561
|
+
);
|
|
562
|
+
|
|
563
|
+
// Replace editor with wizard
|
|
564
|
+
this.ctx.editorContainer.clear();
|
|
565
|
+
this.ctx.editorContainer.addChild(wizard);
|
|
566
|
+
this.ctx.ui.setFocus(wizard);
|
|
567
|
+
this.ctx.ui.requestRender();
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Handle OAuth authentication flow for MCP server
|
|
572
|
+
*/
|
|
573
|
+
async #handleOAuthFlow(
|
|
574
|
+
authUrl: string,
|
|
575
|
+
tokenUrl: string,
|
|
576
|
+
clientId: string,
|
|
577
|
+
clientSecret: string,
|
|
578
|
+
scopes: string,
|
|
579
|
+
opts?: {
|
|
580
|
+
callbackPort?: number;
|
|
581
|
+
callbackPath?: string;
|
|
582
|
+
redirectUri?: string;
|
|
583
|
+
prompt?: string;
|
|
584
|
+
serverUrl?: string;
|
|
585
|
+
resource?: string;
|
|
586
|
+
},
|
|
587
|
+
): Promise<OAuthFlowResult> {
|
|
588
|
+
const authStorage = this.ctx.session.modelRegistry.authStorage;
|
|
589
|
+
let parsedAuthUrl: URL;
|
|
590
|
+
|
|
591
|
+
// Validate OAuth URLs
|
|
592
|
+
try {
|
|
593
|
+
parsedAuthUrl = new URL(authUrl);
|
|
594
|
+
new URL(tokenUrl);
|
|
595
|
+
} catch (_error) {
|
|
596
|
+
throw new Error(
|
|
597
|
+
`Invalid OAuth URLs. Please check:\n Authorization URL: ${authUrl}\n Token URL: ${tokenUrl}`,
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const resolvedClientId = clientId.trim() || parsedAuthUrl.searchParams.get("client_id") || undefined;
|
|
602
|
+
const resolvedClientSecret = clientSecret.trim() || undefined;
|
|
603
|
+
|
|
604
|
+
const manualInput = this.ctx.oauthManualInput;
|
|
605
|
+
if (manualInput.hasPending()) {
|
|
606
|
+
const pendingProvider = manualInput.pendingProviderId ?? "another provider";
|
|
607
|
+
throw new Error(
|
|
608
|
+
`OAuth login already in progress for ${pendingProvider}. Complete or cancel it before starting MCP OAuth.`,
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
let manualInputClaim: { promise: Promise<string>; clear: (reason?: string) => void } | undefined;
|
|
612
|
+
const oauthTimeout = new AbortController();
|
|
613
|
+
try {
|
|
614
|
+
// Create OAuth flow
|
|
615
|
+
const flow = new MCPOAuthFlow(
|
|
616
|
+
{
|
|
617
|
+
authorizationUrl: authUrl,
|
|
618
|
+
tokenUrl: tokenUrl,
|
|
619
|
+
clientId: resolvedClientId,
|
|
620
|
+
clientSecret: resolvedClientSecret,
|
|
621
|
+
scopes: scopes || undefined,
|
|
622
|
+
prompt: opts?.prompt,
|
|
623
|
+
redirectUri: opts?.redirectUri,
|
|
624
|
+
callbackPort: opts?.callbackPort,
|
|
625
|
+
callbackPath: opts?.callbackPath,
|
|
626
|
+
resource: opts?.resource,
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
onAuth: (info: { url: string; instructions?: string }) => {
|
|
630
|
+
// Show auth URL prominently in chat as one block
|
|
631
|
+
const block = new TranscriptBlock();
|
|
632
|
+
this.ctx.present(block);
|
|
633
|
+
block.addChild(new Text(theme.fg("accent", "━━━ OAuth Authorization Required ━━━"), 1, 0));
|
|
634
|
+
block.addChild(new Spacer(1));
|
|
635
|
+
block.addChild(new Text(theme.fg("muted", "Preparing browser authorization..."), 1, 0));
|
|
636
|
+
block.addChild(new Spacer(1));
|
|
637
|
+
block.addChild(
|
|
638
|
+
new Text(
|
|
639
|
+
theme.fg("muted", "Waiting for authorization... (Press Ctrl+C to cancel, 5 minute timeout)"),
|
|
640
|
+
1,
|
|
641
|
+
0,
|
|
642
|
+
),
|
|
643
|
+
);
|
|
644
|
+
block.addChild(new Text(theme.fg("muted", MCP_MANUAL_LOGIN_TIP), 1, 0));
|
|
645
|
+
block.addChild(new Spacer(1));
|
|
646
|
+
block.addChild(new Text(theme.fg("accent", "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"), 1, 0));
|
|
647
|
+
// Try to open browser automatically
|
|
648
|
+
try {
|
|
649
|
+
openPath(info.url);
|
|
650
|
+
|
|
651
|
+
// Show confirmation that browser should open
|
|
652
|
+
block.addChild(new Spacer(1));
|
|
653
|
+
block.addChild(new Text(theme.fg("success", "→ Opening browser automatically..."), 1, 0));
|
|
654
|
+
block.addChild(new Spacer(1));
|
|
655
|
+
block.addChild(new Text(theme.fg("muted", "Alternative if browser did not open:"), 1, 0));
|
|
656
|
+
block.addChild(new MCPAuthorizationLinkPrompt(info.url));
|
|
657
|
+
this.ctx.ui.requestRender();
|
|
658
|
+
} catch (_error) {
|
|
659
|
+
// Show error if browser doesn't open
|
|
660
|
+
block.addChild(new Spacer(1));
|
|
661
|
+
block.addChild(new Text(theme.fg("warning", "→ Could not open browser automatically"), 1, 0));
|
|
662
|
+
block.addChild(new MCPAuthorizationLinkPrompt(info.url));
|
|
663
|
+
this.ctx.ui.requestRender();
|
|
664
|
+
}
|
|
665
|
+
},
|
|
666
|
+
onProgress: (message: string) => {
|
|
667
|
+
this.ctx.present([new Spacer(1), new Text(theme.fg("muted", message), 1, 0)]);
|
|
668
|
+
},
|
|
669
|
+
onManualCodeInput: () => {
|
|
670
|
+
if (manualInputClaim) return manualInputClaim.promise;
|
|
671
|
+
const pendingInput = manualInput.tryClaimInput(MCP_MANUAL_INPUT_PROVIDER_ID);
|
|
672
|
+
if (!pendingInput) {
|
|
673
|
+
const pendingProvider = manualInput.pendingProviderId ?? "another provider";
|
|
674
|
+
throw new Error(
|
|
675
|
+
`OAuth login already in progress for ${pendingProvider}. Complete or cancel it before starting MCP OAuth.`,
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
manualInputClaim = pendingInput;
|
|
679
|
+
return pendingInput.promise;
|
|
680
|
+
},
|
|
681
|
+
signal: oauthTimeout.signal,
|
|
682
|
+
},
|
|
683
|
+
);
|
|
684
|
+
|
|
685
|
+
// Execute OAuth flow with 5 minute timeout
|
|
686
|
+
const credentials = await withTimeout(
|
|
687
|
+
flow.login(),
|
|
688
|
+
5 * 60 * 1000,
|
|
689
|
+
"OAuth flow timed out after 5 minutes",
|
|
690
|
+
() => oauthTimeout.abort("MCP OAuth flow timed out"),
|
|
691
|
+
);
|
|
692
|
+
|
|
693
|
+
this.ctx.present([
|
|
694
|
+
new Spacer(1),
|
|
695
|
+
new Text(theme.fg("success", "✓ Authorization completed in browser."), 1, 0),
|
|
696
|
+
]);
|
|
697
|
+
|
|
698
|
+
// Deterministic per-URL id: every profile resolves its own credential row
|
|
699
|
+
// under the same key, so shared project configs stay profile-isolated.
|
|
700
|
+
// Random fallback only for flows that never knew the server URL.
|
|
701
|
+
const credentialId = opts?.serverUrl
|
|
702
|
+
? mcpOAuthCredentialId(opts.serverUrl)
|
|
703
|
+
: `mcp_oauth_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;
|
|
704
|
+
|
|
705
|
+
// Embed refresh material so the credential is self-contained: token
|
|
706
|
+
// refresh must work for configs that carry no auth block at all.
|
|
707
|
+
const oauthCredential: MCPStoredOAuthCredential = {
|
|
708
|
+
type: "oauth",
|
|
709
|
+
...credentials,
|
|
710
|
+
tokenUrl,
|
|
711
|
+
clientId: flow.resolvedClientId ?? resolvedClientId,
|
|
712
|
+
clientSecret: flow.registeredClientSecret ?? resolvedClientSecret,
|
|
713
|
+
resource: flow.resource,
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
await authStorage.set(credentialId, oauthCredential);
|
|
717
|
+
|
|
718
|
+
return {
|
|
719
|
+
credentialId,
|
|
720
|
+
clientId: flow.resolvedClientId,
|
|
721
|
+
resource: flow.resource,
|
|
722
|
+
};
|
|
723
|
+
} catch (error) {
|
|
724
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
725
|
+
|
|
726
|
+
// Provide helpful error messages based on failure type
|
|
727
|
+
if (errorMsg.includes("timeout") || errorMsg.includes("timed out")) {
|
|
728
|
+
throw new Error("OAuth flow timed out. Please try again.");
|
|
729
|
+
} else if (errorMsg.includes("403") || errorMsg.includes("unauthorized")) {
|
|
730
|
+
throw new Error("OAuth authorization failed. Please check your client credentials.");
|
|
731
|
+
} else if (errorMsg.includes("invalid_grant")) {
|
|
732
|
+
throw new Error("OAuth authorization code is invalid or expired. Please try again.");
|
|
733
|
+
} else if (errorMsg.includes("ECONNREFUSED") || errorMsg.includes("fetch failed")) {
|
|
734
|
+
throw new Error("Could not connect to OAuth server. Please check the URLs and your network connection.");
|
|
735
|
+
} else {
|
|
736
|
+
throw new Error(`OAuth authentication failed: ${errorMsg}`);
|
|
737
|
+
}
|
|
738
|
+
} finally {
|
|
739
|
+
manualInputClaim?.clear("Manual MCP OAuth input cleared");
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* Fold a completed OAuth flow back into a server config. Owns the
|
|
745
|
+
* persistence policy in one place: the auth block records the credential
|
|
746
|
+
* pointer plus refresh material, the oauth block echoes the client id for
|
|
747
|
+
* pre-auth reuse, and only a user-supplied client secret is ever written —
|
|
748
|
+
* DCR-issued secrets stay embedded in the stored credential so they cannot
|
|
749
|
+
* leak into (possibly shared/committed) config files.
|
|
750
|
+
*/
|
|
751
|
+
#persistOAuthResult(
|
|
752
|
+
config: MCPServerConfig,
|
|
753
|
+
result: OAuthFlowResult,
|
|
754
|
+
opts: { tokenUrl: string; resource?: string; clientId?: string; userClientSecret?: string },
|
|
755
|
+
): MCPServerConfig {
|
|
756
|
+
const clientId = result.clientId ?? opts.clientId ?? config.oauth?.clientId;
|
|
757
|
+
const resource = result.resource ?? opts.resource ?? config.auth?.resource;
|
|
758
|
+
return {
|
|
759
|
+
...config,
|
|
760
|
+
auth: {
|
|
761
|
+
type: "oauth",
|
|
762
|
+
credentialId: result.credentialId,
|
|
763
|
+
tokenUrl: opts.tokenUrl,
|
|
764
|
+
clientId,
|
|
765
|
+
clientSecret: opts.userClientSecret,
|
|
766
|
+
resource,
|
|
767
|
+
},
|
|
768
|
+
oauth: {
|
|
769
|
+
...config.oauth,
|
|
770
|
+
clientId,
|
|
771
|
+
},
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* Test connection to an MCP server.
|
|
777
|
+
* Throws an error if connection fails (used for auto-detection).
|
|
778
|
+
*/
|
|
779
|
+
async #handleTestConnection(config: MCPServerConfig, options?: { oauth?: boolean }): Promise<void> {
|
|
780
|
+
// Create temporary connection using a test name
|
|
781
|
+
const testName = `test_${Date.now()}`;
|
|
782
|
+
let resolvedConfig: MCPServerConfig;
|
|
783
|
+
if (this.ctx.mcpManager) {
|
|
784
|
+
resolvedConfig = await this.ctx.mcpManager.prepareConfig(config, options);
|
|
785
|
+
} else {
|
|
786
|
+
const tempManager = new MCPManager(getProjectDir());
|
|
787
|
+
tempManager.setAuthStorage(this.ctx.session.modelRegistry.authStorage);
|
|
788
|
+
resolvedConfig = await tempManager.prepareConfig(config, options);
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
const connection = await connectToServer(testName, resolvedConfig);
|
|
792
|
+
await disconnectServer(connection);
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
async #findConfiguredServer(
|
|
796
|
+
name: string,
|
|
797
|
+
): Promise<{ filePath: string; scope: "user" | "project"; config: MCPServerConfig } | null> {
|
|
798
|
+
const cwd = getProjectDir();
|
|
799
|
+
const userPath = getMCPConfigPath("user", cwd);
|
|
800
|
+
const projectPath = getMCPConfigPath("project", cwd);
|
|
801
|
+
|
|
802
|
+
const [userConfig, projectConfig] = await Promise.all([
|
|
803
|
+
readMCPConfigFile(userPath),
|
|
804
|
+
readMCPConfigFile(projectPath),
|
|
805
|
+
]);
|
|
806
|
+
|
|
807
|
+
if (userConfig.mcpServers?.[name]) {
|
|
808
|
+
return { filePath: userPath, scope: "user", config: userConfig.mcpServers[name] };
|
|
809
|
+
}
|
|
810
|
+
if (projectConfig.mcpServers?.[name]) {
|
|
811
|
+
return { filePath: projectPath, scope: "project", config: projectConfig.mcpServers[name] };
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
// Check standalone fallback files (mcp.json, .mcp.json) in the project root —
|
|
815
|
+
// these match the discovery paths used by the mcp-json provider. Reads run in
|
|
816
|
+
// parallel (mirroring user/project above) but precedence is preserved by the
|
|
817
|
+
// for-loop's iteration order: mcp.json wins over .mcp.json on a same-name hit.
|
|
818
|
+
const standalonePaths = [path.join(cwd, "mcp.json"), path.join(cwd, ".mcp.json")];
|
|
819
|
+
const fallbackConfigs = await Promise.all(
|
|
820
|
+
standalonePaths.map(async fallbackPath => {
|
|
821
|
+
try {
|
|
822
|
+
return await readMCPConfigFile(fallbackPath);
|
|
823
|
+
} catch {
|
|
824
|
+
// Malformed JSON in a standalone file — skip and continue lookup.
|
|
825
|
+
return null;
|
|
826
|
+
}
|
|
827
|
+
}),
|
|
828
|
+
);
|
|
829
|
+
for (const [index, fallbackConfig] of fallbackConfigs.entries()) {
|
|
830
|
+
const config = fallbackConfig?.mcpServers?.[name];
|
|
831
|
+
if (config) {
|
|
832
|
+
return { filePath: standalonePaths[index]!, scope: "project", config };
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
return null;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* Resolve a server for an auth/test operation.
|
|
840
|
+
*
|
|
841
|
+
* Unlike {@link #findConfiguredServer} (which only reads writable OMP config
|
|
842
|
+
* files), this also recognizes runtime-discovered servers that `/mcp list`
|
|
843
|
+
* surfaces but that live in no writable config — e.g. servers from a Claude
|
|
844
|
+
* Code marketplace plugin (`cloudflare:cloudflare-api`), `.cursor/mcp.json`,
|
|
845
|
+
* etc. Without this, `/mcp reauth|test|unauth` reports "not found" for a
|
|
846
|
+
* server the list just showed.
|
|
847
|
+
*
|
|
848
|
+
* For a discovered server, any persisted change is written into the *user*
|
|
849
|
+
* config under the same (namespaced) name; the native provider (priority 100)
|
|
850
|
+
* shadows the discovered entry on the next reload, so an OAuth `auth` block
|
|
851
|
+
* persisted by `/mcp reauth` takes effect. `discovered` lets callers tailor
|
|
852
|
+
* messaging and skip pointless writes when there is nothing to persist.
|
|
853
|
+
*/
|
|
854
|
+
async #resolveServerForAuth(name: string): Promise<{
|
|
855
|
+
filePath: string;
|
|
856
|
+
scope: "user" | "project";
|
|
857
|
+
config: MCPServerConfig;
|
|
858
|
+
discovered: boolean;
|
|
859
|
+
} | null> {
|
|
860
|
+
const found = await this.#findConfiguredServer(name);
|
|
861
|
+
if (found) return { ...found, discovered: false };
|
|
862
|
+
|
|
863
|
+
const config = this.ctx.mcpManager?.getServerConfig(name);
|
|
864
|
+
const source = this.ctx.mcpManager?.getSource(name);
|
|
865
|
+
if (!config || !source) return null;
|
|
866
|
+
|
|
867
|
+
return {
|
|
868
|
+
filePath: getMCPConfigPath("user", getProjectDir()),
|
|
869
|
+
scope: "user",
|
|
870
|
+
config,
|
|
871
|
+
discovered: true,
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
#stripOAuthAuth(config: MCPServerConfig): MCPServerConfig {
|
|
876
|
+
const next = { ...config } as MCPServerConfig & { auth?: MCPAuthConfig };
|
|
877
|
+
delete next.auth;
|
|
878
|
+
return next;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
async #resolveOAuthEndpointsFromServer(config: MCPServerConfig): Promise<{
|
|
882
|
+
authorizationUrl: string;
|
|
883
|
+
tokenUrl: string;
|
|
884
|
+
clientId?: string;
|
|
885
|
+
scopes?: string;
|
|
886
|
+
resource?: string;
|
|
887
|
+
}> {
|
|
888
|
+
// Stdio servers manage credentials inside the child process; OMP's OAuth
|
|
889
|
+
// flow only applies to http/sse transports. Without this guard the
|
|
890
|
+
// unauthenticated preflight below spawns the child, which happily reuses
|
|
891
|
+
// its own cached tokens (e.g. mcp-remote's machine-wide ~/.mcp-auth) and
|
|
892
|
+
// produces the misleading "reauthorization is not required".
|
|
893
|
+
if (config.type !== "http" && config.type !== "sse") {
|
|
894
|
+
const remoteUrl = config.args?.find(arg => /^https?:\/\//.test(arg));
|
|
895
|
+
const httpHint = `{ "type": "http", "url": ${JSON.stringify(remoteUrl ?? "<remote url>")} }`;
|
|
896
|
+
const usesMcpRemote = [config.command, ...(config.args ?? [])].some(part => part?.includes("mcp-remote"));
|
|
897
|
+
throw new Error(
|
|
898
|
+
usesMcpRemote
|
|
899
|
+
? `this server proxies OAuth through mcp-remote, which caches tokens machine-wide in ~/.mcp-auth (shared across every OMP profile). Clear ~/.mcp-auth to force a fresh login, or replace the proxy with ${httpHint} so OMP manages OAuth per profile.`
|
|
900
|
+
: `stdio servers manage their own credentials, so OMP has no OAuth to reauthorize. If the service supports OAuth over HTTP, configure it as ${httpHint} instead.`,
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
// First test if server actually needs auth by connecting without OAuth
|
|
904
|
+
let connectionSucceeded = false;
|
|
905
|
+
let connectionError: Error | undefined;
|
|
906
|
+
try {
|
|
907
|
+
await this.#handleTestConnection(this.#stripOAuthAuth(config), { oauth: false });
|
|
908
|
+
connectionSucceeded = true;
|
|
909
|
+
} catch (error) {
|
|
910
|
+
connectionError = error as Error;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// Server connected fine without auth — reauth is not needed
|
|
914
|
+
if (connectionSucceeded) {
|
|
915
|
+
throw new Error("Server connection succeeded without OAuth; reauthorization is not required.");
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
// Analyze the connection error to extract OAuth endpoints
|
|
919
|
+
const authResult = analyzeAuthError(connectionError!, "url" in config ? config.url : undefined);
|
|
920
|
+
let oauth = authResult.authType === "oauth" ? (authResult.oauth ?? null) : null;
|
|
921
|
+
|
|
922
|
+
if (!oauth && (config.type === "http" || config.type === "sse") && config.url) {
|
|
923
|
+
oauth = await discoverOAuthEndpoints(config.url, authResult.authServerUrl, authResult.resourceMetadataUrl);
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
if (!oauth) {
|
|
927
|
+
throw new Error("Could not discover OAuth endpoints from server response.");
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
return oauth;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
async #waitForServerConnectionWithAnimation(
|
|
934
|
+
name: string,
|
|
935
|
+
options?: { suppressDisconnectedWarning?: boolean },
|
|
936
|
+
): Promise<"connected" | "connecting" | "disconnected"> {
|
|
937
|
+
if (!this.ctx.mcpManager) return "disconnected";
|
|
938
|
+
|
|
939
|
+
const block = new McpConnectingBlock(name);
|
|
940
|
+
this.ctx.present(block);
|
|
941
|
+
|
|
942
|
+
try {
|
|
943
|
+
try {
|
|
944
|
+
await withTimeout(this.ctx.mcpManager.waitForConnection(name), 10_000, "Connection still pending");
|
|
945
|
+
} catch {
|
|
946
|
+
// Ignore timeout/errors here and use status check below.
|
|
947
|
+
}
|
|
948
|
+
const state = this.ctx.mcpManager.getConnectionStatus(name);
|
|
949
|
+
if (state === "connected") {
|
|
950
|
+
// Connection may complete after initial reload; rebind runtime MCP tools now.
|
|
951
|
+
await this.ctx.session.refreshMCPTools(this.ctx.mcpManager.getTools());
|
|
952
|
+
}
|
|
953
|
+
if (state === "connected") {
|
|
954
|
+
block.setStatus(theme.fg("success", `${theme.status.enabled} Connected to "${name}"`));
|
|
955
|
+
} else if (state === "connecting") {
|
|
956
|
+
block.setStatus(theme.fg("muted", `◌ "${name}" is still connecting...`));
|
|
957
|
+
} else {
|
|
958
|
+
block.setStatus(
|
|
959
|
+
options?.suppressDisconnectedWarning
|
|
960
|
+
? theme.fg("muted", `◌ Connection check complete for "${name}"`)
|
|
961
|
+
: theme.fg("warning", `⚠ Could not connect to "${name}" yet`),
|
|
962
|
+
);
|
|
963
|
+
}
|
|
964
|
+
return state;
|
|
965
|
+
} finally {
|
|
966
|
+
block.finish();
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
async #syncManagerConnection(name: string, config: MCPServerConfig): Promise<void> {
|
|
971
|
+
if (!this.ctx.mcpManager) return;
|
|
972
|
+
if (this.ctx.mcpManager.getConnectionStatus(name) !== "disconnected") return;
|
|
973
|
+
await this.ctx.mcpManager.connectServers({ [name]: config }, {});
|
|
974
|
+
if (this.ctx.mcpManager.getConnectionStatus(name) === "connected") {
|
|
975
|
+
await this.ctx.session.refreshMCPTools(this.ctx.mcpManager.getTools());
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
async #handleWizardComplete(name: string, config: MCPServerConfig, scope: "user" | "project"): Promise<void> {
|
|
980
|
+
try {
|
|
981
|
+
// Determine file path
|
|
982
|
+
const cwd = getProjectDir();
|
|
983
|
+
const filePath = getMCPConfigPath(scope, cwd);
|
|
984
|
+
|
|
985
|
+
// Add server to config
|
|
986
|
+
await addMCPServer(filePath, name, config);
|
|
987
|
+
|
|
988
|
+
// Reload MCP manager
|
|
989
|
+
await this.#reloadMCP();
|
|
990
|
+
const state =
|
|
991
|
+
config.enabled === false
|
|
992
|
+
? "disconnected"
|
|
993
|
+
: await this.#waitForServerConnectionWithAnimation(name, { suppressDisconnectedWarning: true });
|
|
994
|
+
let isConnected = state === "connected";
|
|
995
|
+
const isConnecting = state === "connecting";
|
|
996
|
+
|
|
997
|
+
// Fallback: if manager state is still disconnected but direct test works,
|
|
998
|
+
// report as connected to avoid false-negative messaging.
|
|
999
|
+
if (!isConnected && !isConnecting && config.enabled !== false) {
|
|
1000
|
+
try {
|
|
1001
|
+
await this.#handleTestConnection(config);
|
|
1002
|
+
isConnected = true;
|
|
1003
|
+
await this.#syncManagerConnection(name, config);
|
|
1004
|
+
} catch {
|
|
1005
|
+
// Keep disconnected status
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
// refreshMCPTools preserves the prior MCP tool selection, so tools from
|
|
1010
|
+
// brand-new servers are registered in the registry but never activated.
|
|
1011
|
+
// Explicitly activate the newly added server's tools now.
|
|
1012
|
+
if (isConnected && this.ctx.mcpManager) {
|
|
1013
|
+
const serverTools = this.ctx.mcpManager.getTools().filter(t => t.mcpServerName === name);
|
|
1014
|
+
if (serverTools.length > 0) {
|
|
1015
|
+
const currentActive = this.ctx.session.getActiveToolNames();
|
|
1016
|
+
const toActivate = serverTools.map(t => t.name).filter(n => this.ctx.session.getToolByName(n));
|
|
1017
|
+
if (toActivate.length > 0) {
|
|
1018
|
+
await this.ctx.session.setActiveToolsByName([...new Set([...currentActive, ...toActivate])]);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
// Show success message
|
|
1024
|
+
const scopeLabel = scope === "user" ? "user" : "project";
|
|
1025
|
+
const lines = ["", theme.fg("success", `+ Added server "${name}" to ${scopeLabel} config`), ""];
|
|
1026
|
+
|
|
1027
|
+
if (isConnected) {
|
|
1028
|
+
lines.push(theme.fg("success", `${theme.status.enabled} Successfully connected to server`));
|
|
1029
|
+
lines.push("");
|
|
1030
|
+
} else if (isConnecting) {
|
|
1031
|
+
lines.push(theme.fg("muted", `◌ Server is connecting in background...`));
|
|
1032
|
+
lines.push(theme.fg("muted", ` Run ${theme.fg("accent", `/mcp test ${name}`)} in a few seconds.`));
|
|
1033
|
+
lines.push("");
|
|
1034
|
+
} else {
|
|
1035
|
+
lines.push(theme.fg("warning", `⚠ Server added but not yet connected`));
|
|
1036
|
+
lines.push(theme.fg("muted", ` Run ${theme.fg("accent", `/mcp test ${name}`)} to test the connection.`));
|
|
1037
|
+
lines.push("");
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
lines.push(theme.fg("muted", `Run ${theme.fg("accent", "/mcp list")} to see all configured servers.`));
|
|
1041
|
+
lines.push("");
|
|
1042
|
+
|
|
1043
|
+
this.#showMessage(lines.join("\n"));
|
|
1044
|
+
} catch (error) {
|
|
1045
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
1046
|
+
|
|
1047
|
+
// Provide helpful error messages
|
|
1048
|
+
let helpText = "";
|
|
1049
|
+
if (errorMsg.includes("EACCES") || errorMsg.includes("permission denied")) {
|
|
1050
|
+
helpText = "\n\nTip: Check file permissions for the config directory.";
|
|
1051
|
+
} else if (errorMsg.includes("ENOSPC")) {
|
|
1052
|
+
helpText = "\n\nTip: Insufficient disk space.";
|
|
1053
|
+
} else if (errorMsg.includes("already exists")) {
|
|
1054
|
+
helpText = `\n\nTip: Use ${theme.fg("accent", "/mcp list")} to see existing servers.`;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
this.ctx.showError(`Failed to add server: ${errorMsg}${helpText}`);
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
#handleWizardCancel(): void {
|
|
1062
|
+
this.#showMessage(
|
|
1063
|
+
[
|
|
1064
|
+
"",
|
|
1065
|
+
theme.fg("muted", "Server creation cancelled."),
|
|
1066
|
+
"",
|
|
1067
|
+
theme.fg("dim", "Tip: Press Ctrl+C or Esc anytime to cancel"),
|
|
1068
|
+
"",
|
|
1069
|
+
].join("\n"),
|
|
1070
|
+
);
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
/**
|
|
1074
|
+
* Handle /mcp list - Show all configured servers
|
|
1075
|
+
*/
|
|
1076
|
+
async #handleList(): Promise<void> {
|
|
1077
|
+
try {
|
|
1078
|
+
const cwd = getProjectDir();
|
|
1079
|
+
|
|
1080
|
+
// Load from both user and project configs
|
|
1081
|
+
const userPath = getMCPConfigPath("user", cwd);
|
|
1082
|
+
const projectPath = getMCPConfigPath("project", cwd);
|
|
1083
|
+
|
|
1084
|
+
const userPathLabel = shortenPath(userPath);
|
|
1085
|
+
const projectPathLabel = shortenPath(projectPath);
|
|
1086
|
+
const [userConfig, projectConfig] = await Promise.all([
|
|
1087
|
+
readMCPConfigFile(userPath),
|
|
1088
|
+
readMCPConfigFile(projectPath),
|
|
1089
|
+
]);
|
|
1090
|
+
|
|
1091
|
+
const userServers = Object.keys(userConfig.mcpServers ?? {});
|
|
1092
|
+
const projectServers = Object.keys(projectConfig.mcpServers ?? {});
|
|
1093
|
+
|
|
1094
|
+
// Collect runtime-discovered servers not in config files
|
|
1095
|
+
const configServerNames = new Set([...userServers, ...projectServers]);
|
|
1096
|
+
const disabledServerNames = new Set(await readDisabledServers(userPath));
|
|
1097
|
+
const discoveredServers: { name: string; source: SourceMeta }[] = [];
|
|
1098
|
+
if (this.ctx.mcpManager) {
|
|
1099
|
+
for (const name of this.ctx.mcpManager.getAllServerNames()) {
|
|
1100
|
+
if (configServerNames.has(name)) continue;
|
|
1101
|
+
if (disabledServerNames.has(name)) continue;
|
|
1102
|
+
const source = this.ctx.mcpManager.getSource(name);
|
|
1103
|
+
if (source) {
|
|
1104
|
+
discoveredServers.push({ name, source });
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
if (
|
|
1110
|
+
userServers.length === 0 &&
|
|
1111
|
+
projectServers.length === 0 &&
|
|
1112
|
+
discoveredServers.length === 0 &&
|
|
1113
|
+
disabledServerNames.size === 0
|
|
1114
|
+
) {
|
|
1115
|
+
this.#showMessage(
|
|
1116
|
+
[
|
|
1117
|
+
"",
|
|
1118
|
+
theme.fg("muted", "No MCP servers configured."),
|
|
1119
|
+
"",
|
|
1120
|
+
`Use ${theme.fg("accent", "/mcp add")} to add a server.`,
|
|
1121
|
+
"",
|
|
1122
|
+
].join("\n"),
|
|
1123
|
+
);
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
const lines: string[] = ["", theme.bold("Configured MCP Servers"), ""];
|
|
1128
|
+
|
|
1129
|
+
// Show user-level servers
|
|
1130
|
+
if (userServers.length > 0) {
|
|
1131
|
+
lines.push(theme.fg("accent", "User level") + theme.fg("muted", ` (${userPathLabel}):`));
|
|
1132
|
+
for (const name of userServers) {
|
|
1133
|
+
const config = userConfig.mcpServers![name];
|
|
1134
|
+
const type = config.type ?? "stdio";
|
|
1135
|
+
const state =
|
|
1136
|
+
config.enabled === false
|
|
1137
|
+
? "inactive"
|
|
1138
|
+
: (this.ctx.mcpManager?.getConnectionStatus(name) ?? "disconnected");
|
|
1139
|
+
const status =
|
|
1140
|
+
state === "inactive"
|
|
1141
|
+
? theme.fg("warning", " ◌ inactive")
|
|
1142
|
+
: state === "connected"
|
|
1143
|
+
? theme.fg("success", " ● connected")
|
|
1144
|
+
: state === "connecting"
|
|
1145
|
+
? theme.fg("muted", " ◌ connecting")
|
|
1146
|
+
: theme.fg("muted", " ○ not connected");
|
|
1147
|
+
lines.push(` ${theme.fg("accent", name)}${status} ${theme.fg("dim", `[${type}]`)}`);
|
|
1148
|
+
}
|
|
1149
|
+
lines.push("");
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
// Show project-level servers
|
|
1153
|
+
if (projectServers.length > 0) {
|
|
1154
|
+
lines.push(theme.fg("accent", "Project level") + theme.fg("muted", ` (${projectPathLabel}):`));
|
|
1155
|
+
for (const name of projectServers) {
|
|
1156
|
+
const config = projectConfig.mcpServers![name];
|
|
1157
|
+
const type = config.type ?? "stdio";
|
|
1158
|
+
const state =
|
|
1159
|
+
config.enabled === false
|
|
1160
|
+
? "inactive"
|
|
1161
|
+
: (this.ctx.mcpManager?.getConnectionStatus(name) ?? "disconnected");
|
|
1162
|
+
const status =
|
|
1163
|
+
state === "inactive"
|
|
1164
|
+
? theme.fg("warning", " ◌ inactive")
|
|
1165
|
+
: state === "connected"
|
|
1166
|
+
? theme.fg("success", " ● connected")
|
|
1167
|
+
: state === "connecting"
|
|
1168
|
+
? theme.fg("muted", " ◌ connecting")
|
|
1169
|
+
: theme.fg("muted", " ○ not connected");
|
|
1170
|
+
lines.push(` ${theme.fg("accent", name)}${status} ${theme.fg("dim", `[${type}]`)}`);
|
|
1171
|
+
}
|
|
1172
|
+
lines.push("");
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
// Show discovered servers (from .claude.json, .cursor/mcp.json, .vscode/mcp.json, etc.)
|
|
1176
|
+
if (discoveredServers.length > 0) {
|
|
1177
|
+
for (const { providerName, shortPath, items: entries } of groupBySource(discoveredServers, e => e.source)) {
|
|
1178
|
+
lines.push(theme.fg("accent", providerName) + theme.fg("muted", ` (${shortPath}):`));
|
|
1179
|
+
for (const { name } of entries) {
|
|
1180
|
+
const state = this.ctx.mcpManager!.getConnectionStatus(name);
|
|
1181
|
+
const status =
|
|
1182
|
+
state === "connected"
|
|
1183
|
+
? theme.fg("success", " ● connected")
|
|
1184
|
+
: state === "connecting"
|
|
1185
|
+
? theme.fg("muted", " ◌ connecting")
|
|
1186
|
+
: theme.fg("muted", " ○ not connected");
|
|
1187
|
+
lines.push(` ${theme.fg("accent", name)}${status}`);
|
|
1188
|
+
}
|
|
1189
|
+
lines.push("");
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
// Show servers disabled via /mcp disable (from third-party configs)
|
|
1194
|
+
const relevantDisabled = [...disabledServerNames].filter(n => !configServerNames.has(n));
|
|
1195
|
+
if (relevantDisabled.length > 0) {
|
|
1196
|
+
lines.push(theme.fg("accent", "Disabled") + theme.fg("muted", " (discovered servers):"));
|
|
1197
|
+
for (const name of relevantDisabled) {
|
|
1198
|
+
lines.push(` ${theme.fg("accent", name)}${theme.fg("warning", " ◌ disabled")}`);
|
|
1199
|
+
}
|
|
1200
|
+
lines.push("");
|
|
1201
|
+
}
|
|
1202
|
+
this.#showMessage(lines.join("\n"));
|
|
1203
|
+
} catch (error) {
|
|
1204
|
+
this.ctx.showError(`Failed to list servers: ${error instanceof Error ? error.message : String(error)}`);
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
/**
|
|
1209
|
+
* Handle /mcp remove <name> - Remove a server
|
|
1210
|
+
*/
|
|
1211
|
+
async #handleRemove(text: string): Promise<void> {
|
|
1212
|
+
const match = text.match(/^\/mcp\s+(?:remove|rm)\b\s*(.*)$/i);
|
|
1213
|
+
const rest = match?.[1]?.trim() ?? "";
|
|
1214
|
+
const parsed = parseRemoveArgs(rest);
|
|
1215
|
+
if (!parsed.ok) {
|
|
1216
|
+
this.ctx.showError(parsed.error);
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1219
|
+
const { name, scope } = parsed.value;
|
|
1220
|
+
|
|
1221
|
+
if (!name) {
|
|
1222
|
+
this.ctx.showError("Server name required. Usage: /mcp remove <name> [--scope project|user]");
|
|
1223
|
+
return;
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
try {
|
|
1227
|
+
const cwd = getProjectDir();
|
|
1228
|
+
const userPath = getMCPConfigPath("user", cwd);
|
|
1229
|
+
const projectPath = getMCPConfigPath("project", cwd);
|
|
1230
|
+
const filePath = scope === "user" ? userPath : projectPath;
|
|
1231
|
+
const config = await readMCPConfigFile(filePath);
|
|
1232
|
+
if (!config.mcpServers?.[name]) {
|
|
1233
|
+
this.ctx.showError(`Server "${name}" not found in ${scope} config.`);
|
|
1234
|
+
return;
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
// Disconnect if connected
|
|
1238
|
+
if (this.ctx.mcpManager?.getConnection(name)) {
|
|
1239
|
+
await this.ctx.mcpManager.disconnectServer(name);
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
// Remove from config
|
|
1243
|
+
await removeMCPServer(filePath, name);
|
|
1244
|
+
|
|
1245
|
+
// Reload MCP manager
|
|
1246
|
+
await this.#reloadMCP();
|
|
1247
|
+
|
|
1248
|
+
this.#showMessage(["", theme.fg("success", `- Removed server "${name}" from ${scope} config`), ""].join("\n"));
|
|
1249
|
+
} catch (error) {
|
|
1250
|
+
this.ctx.showError(`Failed to remove server: ${error instanceof Error ? error.message : String(error)}`);
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
/**
|
|
1255
|
+
* Handle /mcp test <name> - Test connection to a server
|
|
1256
|
+
*/
|
|
1257
|
+
async #handleTest(name: string | undefined): Promise<void> {
|
|
1258
|
+
if (!name) {
|
|
1259
|
+
this.ctx.showError("Server name required. Usage: /mcp test <name>");
|
|
1260
|
+
return;
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
const originalOnEscape = this.ctx.editor.onEscape;
|
|
1264
|
+
const abortController = new AbortController();
|
|
1265
|
+
this.ctx.editor.onEscape = () => {
|
|
1266
|
+
abortController.abort();
|
|
1267
|
+
};
|
|
1268
|
+
|
|
1269
|
+
let connection: MCPServerConnection | undefined;
|
|
1270
|
+
try {
|
|
1271
|
+
const found = await this.#resolveServerForAuth(name);
|
|
1272
|
+
|
|
1273
|
+
if (!found) {
|
|
1274
|
+
this.ctx.showError(
|
|
1275
|
+
`Server "${name}" not found.\n\nTip: Run ${theme.fg("accent", "/mcp list")} to see available servers.`,
|
|
1276
|
+
);
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
const { config } = found;
|
|
1281
|
+
if (config.enabled === false) {
|
|
1282
|
+
this.ctx.showError(`Server "${name}" is disabled. Run /mcp enable ${name} first.`);
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
this.#showMessage(
|
|
1287
|
+
["", theme.fg("muted", `Testing connection to "${name}"... (esc to cancel)`), ""].join("\n"),
|
|
1288
|
+
);
|
|
1289
|
+
|
|
1290
|
+
// Resolve auth config if needed
|
|
1291
|
+
let resolvedConfig: MCPServerConfig;
|
|
1292
|
+
if (this.ctx.mcpManager) {
|
|
1293
|
+
resolvedConfig = await this.ctx.mcpManager.prepareConfig(config);
|
|
1294
|
+
} else {
|
|
1295
|
+
const tempManager = new MCPManager(getProjectDir());
|
|
1296
|
+
tempManager.setAuthStorage(this.ctx.session.modelRegistry.authStorage);
|
|
1297
|
+
resolvedConfig = await tempManager.prepareConfig(config);
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
// Create temporary connection
|
|
1301
|
+
connection = await connectToServer(name, resolvedConfig, { signal: abortController.signal });
|
|
1302
|
+
|
|
1303
|
+
// List tools to verify connection
|
|
1304
|
+
const tools = await listTools(connection, { signal: abortController.signal });
|
|
1305
|
+
|
|
1306
|
+
const lines = [
|
|
1307
|
+
"",
|
|
1308
|
+
theme.fg("success", `${theme.status.enabled} Successfully connected to "${name}"`),
|
|
1309
|
+
"",
|
|
1310
|
+
` Server: ${connection.serverInfo.name} v${connection.serverInfo.version}`,
|
|
1311
|
+
` Tools: ${tools.length}`,
|
|
1312
|
+
];
|
|
1313
|
+
|
|
1314
|
+
// Show tool names if there are any
|
|
1315
|
+
if (tools.length > 0 && tools.length <= 10) {
|
|
1316
|
+
lines.push("");
|
|
1317
|
+
lines.push(" Available tools:");
|
|
1318
|
+
for (const tool of tools) {
|
|
1319
|
+
lines.push(` • ${tool.name}`);
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
lines.push("");
|
|
1324
|
+
await this.#syncManagerConnection(name, config);
|
|
1325
|
+
this.#showMessage(lines.join("\n"));
|
|
1326
|
+
} catch (error) {
|
|
1327
|
+
if (abortController.signal.aborted || (error instanceof Error && error.name === "AbortError")) {
|
|
1328
|
+
this.ctx.showStatus(`Cancelled MCP test for "${name}"`);
|
|
1329
|
+
return;
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
1333
|
+
|
|
1334
|
+
// Provide helpful error messages
|
|
1335
|
+
let helpText = "";
|
|
1336
|
+
if (errorMsg.includes("ENOENT") || errorMsg.includes("not found")) {
|
|
1337
|
+
helpText = "\n\nTip: Check that the command or URL is correct.";
|
|
1338
|
+
} else if (errorMsg.includes("EACCES")) {
|
|
1339
|
+
helpText = "\n\nTip: Check file/command permissions.";
|
|
1340
|
+
} else if (errorMsg.includes("ECONNREFUSED")) {
|
|
1341
|
+
helpText = "\n\nTip: Check that the server is running and the URL/port is correct.";
|
|
1342
|
+
} else if (errorMsg.includes("timeout")) {
|
|
1343
|
+
helpText = "\n\nTip: The server may be slow or unresponsive. Try increasing the timeout.";
|
|
1344
|
+
} else if (errorMsg.includes("401") || errorMsg.includes("403")) {
|
|
1345
|
+
helpText = "\n\nTip: Check your authentication credentials.";
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
this.ctx.showError(`Failed to connect to "${name}": ${errorMsg}${helpText}`);
|
|
1349
|
+
} finally {
|
|
1350
|
+
this.ctx.editor.onEscape = originalOnEscape;
|
|
1351
|
+
if (connection) {
|
|
1352
|
+
// Best-effort: don't block UI on cleanup.
|
|
1353
|
+
void disconnectServer(connection);
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
async #handleSetEnabled(name: string | undefined, enabled: boolean): Promise<void> {
|
|
1359
|
+
if (!name) {
|
|
1360
|
+
this.ctx.showError(`Server name required. Usage: /mcp ${enabled ? "enable" : "disable"} <name>`);
|
|
1361
|
+
return;
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
try {
|
|
1365
|
+
const found = await this.#findConfiguredServer(name);
|
|
1366
|
+
if (!found) {
|
|
1367
|
+
// Check if this is a discovered server from a third-party config
|
|
1368
|
+
const userConfigPath = getMCPConfigPath("user", getProjectDir());
|
|
1369
|
+
const disabledServers = new Set(await readDisabledServers(userConfigPath));
|
|
1370
|
+
const isDiscovered = this.ctx.mcpManager?.getSource(name);
|
|
1371
|
+
const isCurrentlyDisabled = disabledServers.has(name);
|
|
1372
|
+
if (!isDiscovered && !isCurrentlyDisabled) {
|
|
1373
|
+
this.ctx.showError(`Server "${name}" not found.`);
|
|
1374
|
+
return;
|
|
1375
|
+
}
|
|
1376
|
+
if (isCurrentlyDisabled === !enabled) {
|
|
1377
|
+
this.#showMessage(
|
|
1378
|
+
["", theme.fg("muted", `Server "${name}" is already ${enabled ? "enabled" : "disabled"}.`), ""].join(
|
|
1379
|
+
"\n",
|
|
1380
|
+
),
|
|
1381
|
+
);
|
|
1382
|
+
return;
|
|
1383
|
+
}
|
|
1384
|
+
await setServerDisabled(userConfigPath, name, !enabled);
|
|
1385
|
+
if (enabled) {
|
|
1386
|
+
await this.#reloadMCP();
|
|
1387
|
+
const state = await this.#waitForServerConnectionWithAnimation(name);
|
|
1388
|
+
const status =
|
|
1389
|
+
state === "connected"
|
|
1390
|
+
? theme.fg("success", "Connected")
|
|
1391
|
+
: state === "connecting"
|
|
1392
|
+
? theme.fg("muted", "Connecting")
|
|
1393
|
+
: theme.fg("warning", "Not connected yet");
|
|
1394
|
+
this.#showMessage(
|
|
1395
|
+
[
|
|
1396
|
+
"",
|
|
1397
|
+
theme.fg("success", `${theme.status.enabled} Enabled "${name}"`),
|
|
1398
|
+
"",
|
|
1399
|
+
` Status: ${status}`,
|
|
1400
|
+
"",
|
|
1401
|
+
].join("\n"),
|
|
1402
|
+
);
|
|
1403
|
+
} else {
|
|
1404
|
+
await this.ctx.mcpManager?.disconnectServer(name);
|
|
1405
|
+
await this.ctx.session.refreshMCPTools(this.ctx.mcpManager?.getTools() ?? []);
|
|
1406
|
+
this.#showMessage(["", theme.fg("muted", `${theme.status.disabled} Disabled "${name}"`), ""].join("\n"));
|
|
1407
|
+
}
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
if ((found.config.enabled ?? true) === enabled) {
|
|
1412
|
+
this.#showMessage(
|
|
1413
|
+
["", theme.fg("muted", `Server "${name}" is already ${enabled ? "enabled" : "disabled"}.`), ""].join(
|
|
1414
|
+
"\n",
|
|
1415
|
+
),
|
|
1416
|
+
);
|
|
1417
|
+
return;
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
const updated: MCPServerConfig = { ...found.config, enabled };
|
|
1421
|
+
await updateMCPServer(found.filePath, name, updated);
|
|
1422
|
+
await this.#reloadMCP();
|
|
1423
|
+
|
|
1424
|
+
let status = "";
|
|
1425
|
+
if (enabled) {
|
|
1426
|
+
const state = await this.#waitForServerConnectionWithAnimation(name);
|
|
1427
|
+
status =
|
|
1428
|
+
state === "connected"
|
|
1429
|
+
? theme.fg("success", "Connected")
|
|
1430
|
+
: state === "connecting"
|
|
1431
|
+
? theme.fg("muted", "Connecting")
|
|
1432
|
+
: theme.fg("warning", "Not connected yet");
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
const lines = [
|
|
1436
|
+
"",
|
|
1437
|
+
enabled
|
|
1438
|
+
? theme.fg("success", `${theme.status.enabled} Enabled "${name}" (${found.scope} config)`)
|
|
1439
|
+
: theme.fg("muted", `${theme.status.disabled} Disabled "${name}" (${found.scope} config)`),
|
|
1440
|
+
];
|
|
1441
|
+
if (status) {
|
|
1442
|
+
lines.push("");
|
|
1443
|
+
lines.push(` Status: ${status}`);
|
|
1444
|
+
}
|
|
1445
|
+
lines.push("");
|
|
1446
|
+
this.#showMessage(lines.join("\n"));
|
|
1447
|
+
} catch (error) {
|
|
1448
|
+
this.ctx.showError(
|
|
1449
|
+
`Failed to ${enabled ? "enable" : "disable"} server: ${error instanceof Error ? error.message : String(error)}`,
|
|
1450
|
+
);
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
async #handleUnauth(name: string | undefined): Promise<void> {
|
|
1455
|
+
if (!name) {
|
|
1456
|
+
this.ctx.showError("Server name required. Usage: /mcp unauth <name>");
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
try {
|
|
1461
|
+
const found = await this.#resolveServerForAuth(name);
|
|
1462
|
+
if (!found) {
|
|
1463
|
+
this.ctx.showError(`Server "${name}" not found.`);
|
|
1464
|
+
return;
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
const currentAuth = (found.config as MCPServerConfig & { auth?: MCPAuthConfig }).auth;
|
|
1468
|
+
const authStorage = this.ctx.session.modelRegistry.authStorage;
|
|
1469
|
+
if (currentAuth?.type === "oauth") {
|
|
1470
|
+
await removeManagedMcpOAuthCredential(authStorage, currentAuth.credentialId);
|
|
1471
|
+
}
|
|
1472
|
+
// Also drop this profile's url-keyed binding so the server is truly
|
|
1473
|
+
// signed out even when the config carries no auth block. Runtime
|
|
1474
|
+
// discovery expands `${...}` URL values before MCPManager looks up the
|
|
1475
|
+
// deterministic credential row, so unauth must clear that same key.
|
|
1476
|
+
let removedUrlKeyedCredential = false;
|
|
1477
|
+
if ((found.config.type === "http" || found.config.type === "sse") && found.config.url) {
|
|
1478
|
+
removedUrlKeyedCredential = await removeManagedMcpOAuthCredentials(
|
|
1479
|
+
authStorage,
|
|
1480
|
+
mcpOAuthCredentialIdsForServerUrl(found.config.url),
|
|
1481
|
+
);
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
if (found.discovered && currentAuth?.type !== "oauth") {
|
|
1485
|
+
if (!removedUrlKeyedCredential) {
|
|
1486
|
+
this.#showMessage(
|
|
1487
|
+
["", theme.fg("muted", `No stored OAuth auth to remove for "${name}".`), ""].join("\n"),
|
|
1488
|
+
);
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1491
|
+
await this.#reloadMCP();
|
|
1492
|
+
this.#showMessage(
|
|
1493
|
+
["", theme.fg("success", `- Cleared auth for "${name}" (${found.scope} config)`), ""].join("\n"),
|
|
1494
|
+
);
|
|
1495
|
+
return;
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
const updated = this.#stripOAuthAuth(found.config);
|
|
1499
|
+
await updateMCPServer(found.filePath, name, updated);
|
|
1500
|
+
await this.#reloadMCP();
|
|
1501
|
+
|
|
1502
|
+
this.#showMessage(
|
|
1503
|
+
["", theme.fg("success", `- Cleared auth for "${name}" (${found.scope} config)`), ""].join("\n"),
|
|
1504
|
+
);
|
|
1505
|
+
} catch (error) {
|
|
1506
|
+
this.ctx.showError(`Failed to clear auth: ${error instanceof Error ? error.message : String(error)}`);
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
async #handleReauth(name: string | undefined): Promise<void> {
|
|
1511
|
+
if (!name) {
|
|
1512
|
+
this.ctx.showError("Server name required. Usage: /mcp reauth <name>");
|
|
1513
|
+
return;
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
try {
|
|
1517
|
+
const found = await this.#resolveServerForAuth(name);
|
|
1518
|
+
if (!found) {
|
|
1519
|
+
this.ctx.showError(`Server "${name}" not found.`);
|
|
1520
|
+
return;
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
if (found.config.enabled === false) {
|
|
1524
|
+
this.ctx.showError(`Server "${name}" is disabled. Run /mcp enable ${name} first.`);
|
|
1525
|
+
return;
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
const currentAuth = (found.config as MCPServerConfig & { auth?: MCPAuthConfig }).auth;
|
|
1529
|
+
const authStorage = this.ctx.session.modelRegistry.authStorage;
|
|
1530
|
+
const baseConfig = this.#stripOAuthAuth(found.config);
|
|
1531
|
+
const runtimeBaseConfig = expandEnvVarsDeep(baseConfig);
|
|
1532
|
+
// Resolve endpoints first: this fails fast for stdio transports and
|
|
1533
|
+
// probes http/sse with { oauth: false }, so nothing destructive has
|
|
1534
|
+
// happened yet if the server turns out not to need (or support) OAuth.
|
|
1535
|
+
// Use the same env-expanded config shape runtime discovery passes to
|
|
1536
|
+
// MCPManager; the raw file value may contain `${...}` placeholders.
|
|
1537
|
+
const oauth = await this.#resolveOAuthEndpointsFromServer(runtimeBaseConfig);
|
|
1538
|
+
const serverUrl =
|
|
1539
|
+
runtimeBaseConfig.type === "http" || runtimeBaseConfig.type === "sse" ? runtimeBaseConfig.url : undefined;
|
|
1540
|
+
// A user-supplied client secret may live in either block (the wizard
|
|
1541
|
+
// writes it to auth.clientSecret); DCR secrets are embedded in the
|
|
1542
|
+
// stored credential and never echoed back into config files.
|
|
1543
|
+
const configuredClientId = found.config.oauth?.clientId ?? currentAuth?.clientId;
|
|
1544
|
+
const existingCredential = lookupMcpOAuthCredentialForServer(authStorage, currentAuth, serverUrl)?.credential;
|
|
1545
|
+
const flowClientId = oauth.clientId ?? configuredClientId ?? existingCredential?.clientId ?? "";
|
|
1546
|
+
const storedClientSecret =
|
|
1547
|
+
existingCredential?.clientId === flowClientId ? existingCredential.clientSecret : undefined;
|
|
1548
|
+
const userClientSecret = found.config.oauth?.clientSecret ?? currentAuth?.clientSecret;
|
|
1549
|
+
const flowClientSecret = userClientSecret ?? storedClientSecret ?? "";
|
|
1550
|
+
|
|
1551
|
+
this.#showMessage(["", theme.fg("muted", `Reauthorizing "${name}"...`), ""].join("\n"));
|
|
1552
|
+
|
|
1553
|
+
const currentAuthResource = currentAuth?.resource ? expandEnvVarsDeep(currentAuth.resource) : undefined;
|
|
1554
|
+
const oauthResource =
|
|
1555
|
+
oauth.resource ?? currentAuthResource ?? ("url" in runtimeBaseConfig ? runtimeBaseConfig.url : undefined);
|
|
1556
|
+
|
|
1557
|
+
const oauthResult = await this.#handleOAuthFlow(
|
|
1558
|
+
oauth.authorizationUrl,
|
|
1559
|
+
oauth.tokenUrl,
|
|
1560
|
+
flowClientId,
|
|
1561
|
+
flowClientSecret,
|
|
1562
|
+
oauth.scopes ?? "",
|
|
1563
|
+
{
|
|
1564
|
+
callbackPort: found.config.oauth?.callbackPort,
|
|
1565
|
+
callbackPath: found.config.oauth?.callbackPath,
|
|
1566
|
+
redirectUri: found.config.oauth?.redirectUri,
|
|
1567
|
+
prompt: found.config.oauth?.prompt,
|
|
1568
|
+
serverUrl,
|
|
1569
|
+
resource: oauthResource,
|
|
1570
|
+
},
|
|
1571
|
+
);
|
|
1572
|
+
|
|
1573
|
+
// The flow overwrote (or minted) this profile's row; a superseded
|
|
1574
|
+
// pointer row from the legacy random-id era is now orphaned. GC only
|
|
1575
|
+
// after success so cancelling the browser step leaves the previous
|
|
1576
|
+
// session signed in.
|
|
1577
|
+
if (currentAuth?.type === "oauth" && currentAuth.credentialId !== oauthResult.credentialId) {
|
|
1578
|
+
await removeManagedMcpOAuthCredential(authStorage, currentAuth.credentialId);
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
// Definition-only entries resolve through the url-keyed binding alone;
|
|
1582
|
+
// skip the write-back so a committed project mcp.json stays clean.
|
|
1583
|
+
const urlKeyedId = serverUrl ? mcpOAuthCredentialId(serverUrl) : undefined;
|
|
1584
|
+
if (currentAuth || oauthResult.credentialId !== urlKeyedId) {
|
|
1585
|
+
const updated = this.#persistOAuthResult(baseConfig, oauthResult, {
|
|
1586
|
+
tokenUrl: oauth.tokenUrl,
|
|
1587
|
+
clientId: oauth.clientId,
|
|
1588
|
+
userClientSecret,
|
|
1589
|
+
resource: oauthResource,
|
|
1590
|
+
});
|
|
1591
|
+
await updateMCPServer(found.filePath, name, updated);
|
|
1592
|
+
}
|
|
1593
|
+
await this.#reloadMCP();
|
|
1594
|
+
const state = await this.#waitForServerConnectionWithAnimation(name);
|
|
1595
|
+
|
|
1596
|
+
const lines = [
|
|
1597
|
+
"",
|
|
1598
|
+
theme.fg("success", `✓ Reauthorized "${name}" (${found.scope} config)`),
|
|
1599
|
+
"",
|
|
1600
|
+
` Status: ${
|
|
1601
|
+
state === "connected"
|
|
1602
|
+
? theme.fg("success", "connected")
|
|
1603
|
+
: state === "connecting"
|
|
1604
|
+
? theme.fg("muted", "connecting")
|
|
1605
|
+
: theme.fg("warning", "not connected")
|
|
1606
|
+
}`,
|
|
1607
|
+
"",
|
|
1608
|
+
];
|
|
1609
|
+
this.#showMessage(lines.join("\n"));
|
|
1610
|
+
} catch (error) {
|
|
1611
|
+
this.ctx.showError(`Failed to reauthorize server: ${error instanceof Error ? error.message : String(error)}`);
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
async #handleReload(): Promise<void> {
|
|
1616
|
+
try {
|
|
1617
|
+
this.#showMessage(["", theme.fg("muted", "Reloading MCP servers and runtime tools..."), ""].join("\n"));
|
|
1618
|
+
await this.#reloadMCP();
|
|
1619
|
+
const connectedCount = this.ctx.mcpManager?.getConnectedServers().length ?? 0;
|
|
1620
|
+
this.#showMessage(
|
|
1621
|
+
[
|
|
1622
|
+
"",
|
|
1623
|
+
theme.fg("success", `${theme.icon.loop} MCP reload complete`),
|
|
1624
|
+
` Connected servers: ${connectedCount}`,
|
|
1625
|
+
"",
|
|
1626
|
+
].join("\n"),
|
|
1627
|
+
);
|
|
1628
|
+
} catch (error) {
|
|
1629
|
+
this.ctx.showError(`Failed to reload MCP: ${error instanceof Error ? error.message : String(error)}`);
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
/**
|
|
1634
|
+
* Handle /mcp reconnect <name> - Reconnect to a specific server.
|
|
1635
|
+
*/
|
|
1636
|
+
async #handleReconnect(name: string | undefined): Promise<void> {
|
|
1637
|
+
if (!name) {
|
|
1638
|
+
this.ctx.showError("Server name required. Usage: /mcp reconnect <name>");
|
|
1639
|
+
return;
|
|
1640
|
+
}
|
|
1641
|
+
if (!this.ctx.mcpManager) {
|
|
1642
|
+
this.ctx.showError("MCP manager not available.");
|
|
1643
|
+
return;
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
this.#showMessage(["", theme.fg("muted", `Reconnecting to "${name}"...`), ""].join("\n"));
|
|
1647
|
+
|
|
1648
|
+
try {
|
|
1649
|
+
const connection = await this.ctx.mcpManager.reconnectServer(name, { manual: true });
|
|
1650
|
+
if (connection) {
|
|
1651
|
+
// refreshMCPTools re-registers tools and preserves the user's prior
|
|
1652
|
+
// MCP tool selection. No need to call activateDiscoveredMCPTools —
|
|
1653
|
+
// that would broaden the selection to all server tools.
|
|
1654
|
+
await this.ctx.session.refreshMCPTools(this.ctx.mcpManager.getTools());
|
|
1655
|
+
const serverTools = this.ctx.mcpManager.getTools().filter(t => t.mcpServerName === name);
|
|
1656
|
+
this.#showMessage(
|
|
1657
|
+
[
|
|
1658
|
+
"\n",
|
|
1659
|
+
theme.fg("success", `${theme.status.enabled} Reconnected to "${name}"`),
|
|
1660
|
+
` Tools: ${serverTools.length}`,
|
|
1661
|
+
"\n",
|
|
1662
|
+
].join("\n"),
|
|
1663
|
+
);
|
|
1664
|
+
} else {
|
|
1665
|
+
this.ctx.showError(`Failed to reconnect to "${name}". Check server status and logs.`);
|
|
1666
|
+
}
|
|
1667
|
+
} catch (error) {
|
|
1668
|
+
this.ctx.showError(
|
|
1669
|
+
`Failed to reconnect to "${name}": ${error instanceof Error ? error.message : String(error)}`,
|
|
1670
|
+
);
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
/**
|
|
1675
|
+
* Reload MCP manager with new configs
|
|
1676
|
+
*/
|
|
1677
|
+
async #reloadMCP(): Promise<void> {
|
|
1678
|
+
if (!this.ctx.mcpManager) {
|
|
1679
|
+
return;
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
// Disconnect all existing servers
|
|
1683
|
+
await this.ctx.mcpManager.disconnectAll();
|
|
1684
|
+
|
|
1685
|
+
// Rediscover and connect
|
|
1686
|
+
const result = await this.ctx.mcpManager.discoverAndConnect();
|
|
1687
|
+
await this.ctx.session.refreshMCPTools(this.ctx.mcpManager.getTools());
|
|
1688
|
+
|
|
1689
|
+
// Show any connection errors
|
|
1690
|
+
if (result.errors.size > 0) {
|
|
1691
|
+
const errorLines = ["", theme.fg("warning", "Some servers failed to connect:"), ""];
|
|
1692
|
+
for (const [serverName, error] of result.errors.entries()) {
|
|
1693
|
+
errorLines.push(` ${serverName}: ${error}`);
|
|
1694
|
+
}
|
|
1695
|
+
errorLines.push("");
|
|
1696
|
+
this.#showMessage(errorLines.join("\n"));
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
/**
|
|
1701
|
+
* Handle /mcp resources - Show available resources from connected servers
|
|
1702
|
+
*/
|
|
1703
|
+
async #handleResources(): Promise<void> {
|
|
1704
|
+
if (!this.ctx.mcpManager) {
|
|
1705
|
+
this.ctx.showError("No MCP manager available.");
|
|
1706
|
+
return;
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
const servers = this.ctx.mcpManager.getConnectedServers();
|
|
1710
|
+
const lines: string[] = ["", theme.bold("MCP Resources"), ""];
|
|
1711
|
+
let hasAny = false;
|
|
1712
|
+
|
|
1713
|
+
for (const name of servers) {
|
|
1714
|
+
const data = this.ctx.mcpManager.getServerResources(name);
|
|
1715
|
+
if (!data) continue;
|
|
1716
|
+
const { resources, templates } = data;
|
|
1717
|
+
if (resources.length === 0 && templates.length === 0) continue;
|
|
1718
|
+
hasAny = true;
|
|
1719
|
+
|
|
1720
|
+
lines.push(`${theme.fg("accent", name)}:`);
|
|
1721
|
+
for (const r of resources) {
|
|
1722
|
+
const desc = r.description ? ` ${theme.fg("dim", r.description)}` : "";
|
|
1723
|
+
const mime = r.mimeType ? ` ${theme.fg("dim", `[${r.mimeType}]`)}` : "";
|
|
1724
|
+
lines.push(` ${theme.fg("success", r.uri)}${mime}${desc}`);
|
|
1725
|
+
}
|
|
1726
|
+
if (templates.length > 0) {
|
|
1727
|
+
lines.push(` ${theme.fg("muted", "Templates:")}`);
|
|
1728
|
+
for (const t of templates) {
|
|
1729
|
+
const desc = t.description ? ` ${theme.fg("dim", t.description)}` : "";
|
|
1730
|
+
lines.push(` ${theme.fg("accent", t.uriTemplate)}${desc}`);
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
lines.push("");
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
if (!hasAny) {
|
|
1737
|
+
lines.push(theme.fg("muted", "No resources available on connected servers."));
|
|
1738
|
+
lines.push("");
|
|
1739
|
+
}
|
|
1740
|
+
this.#showMessage(lines.join("\n"));
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
/**
|
|
1744
|
+
* Handle /mcp prompts - Show available prompts from connected servers
|
|
1745
|
+
*/
|
|
1746
|
+
async #handlePrompts(): Promise<void> {
|
|
1747
|
+
if (!this.ctx.mcpManager) {
|
|
1748
|
+
this.ctx.showError("No MCP manager available.");
|
|
1749
|
+
return;
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
const servers = this.ctx.mcpManager.getConnectedServers();
|
|
1753
|
+
const lines: string[] = ["", theme.bold("MCP Prompts"), ""];
|
|
1754
|
+
let hasAny = false;
|
|
1755
|
+
|
|
1756
|
+
for (const name of servers) {
|
|
1757
|
+
const prompts = this.ctx.mcpManager.getServerPrompts(name);
|
|
1758
|
+
if (!prompts?.length) continue;
|
|
1759
|
+
hasAny = true;
|
|
1760
|
+
|
|
1761
|
+
lines.push(`${theme.fg("accent", name)}:`);
|
|
1762
|
+
for (const p of prompts) {
|
|
1763
|
+
const commandName = `${name}:${p.name}`;
|
|
1764
|
+
const desc = p.description ? ` ${theme.fg("dim", p.description)}` : "";
|
|
1765
|
+
lines.push(` ${theme.fg("success", `/${commandName}`)}${desc}`);
|
|
1766
|
+
if (p.arguments?.length) {
|
|
1767
|
+
for (const arg of p.arguments) {
|
|
1768
|
+
const required = arg.required ? theme.fg("warning", " *") : "";
|
|
1769
|
+
const argDesc = arg.description ? ` - ${arg.description}` : "";
|
|
1770
|
+
lines.push(` ${arg.name}=${required}${theme.fg("dim", argDesc)}`);
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
lines.push("");
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
if (!hasAny) {
|
|
1778
|
+
lines.push(theme.fg("muted", "No prompts available on connected servers."));
|
|
1779
|
+
lines.push("");
|
|
1780
|
+
}
|
|
1781
|
+
this.#showMessage(lines.join("\n"));
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
/**
|
|
1785
|
+
* Handle /mcp notifications - Show notification and subscription state
|
|
1786
|
+
*/
|
|
1787
|
+
async #handleNotifications(): Promise<void> {
|
|
1788
|
+
if (!this.ctx.mcpManager) {
|
|
1789
|
+
this.ctx.showError("No MCP manager available.");
|
|
1790
|
+
return;
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
const { enabled, subscriptions } = this.ctx.mcpManager.getNotificationState();
|
|
1794
|
+
const servers = this.ctx.mcpManager.getConnectedServers();
|
|
1795
|
+
const statusIcon = enabled ? theme.fg("success", "enabled") : theme.fg("warning", "disabled");
|
|
1796
|
+
const lines: string[] = ["", theme.bold("MCP Notifications"), ""];
|
|
1797
|
+
lines.push(` Status: ${statusIcon} ${theme.fg("dim", "(mcp.notifications setting)")}`);
|
|
1798
|
+
lines.push("");
|
|
1799
|
+
|
|
1800
|
+
let hasAny = false;
|
|
1801
|
+
for (const name of servers) {
|
|
1802
|
+
const connection = this.ctx.mcpManager.getConnection(name);
|
|
1803
|
+
if (!connection) continue;
|
|
1804
|
+
const caps = connection.capabilities;
|
|
1805
|
+
const supportsResources = caps.resources !== undefined;
|
|
1806
|
+
const supportsSubscribe = caps.resources?.subscribe === true;
|
|
1807
|
+
const supportsToolsChanged = caps.tools?.listChanged === true;
|
|
1808
|
+
const supportsPromptsChanged = caps.prompts?.listChanged === true;
|
|
1809
|
+
const supportsResourcesChanged = caps.resources?.listChanged === true;
|
|
1810
|
+
|
|
1811
|
+
const hasNotifications =
|
|
1812
|
+
supportsToolsChanged || supportsPromptsChanged || supportsResourcesChanged || supportsSubscribe;
|
|
1813
|
+
if (!hasNotifications) continue;
|
|
1814
|
+
hasAny = true;
|
|
1815
|
+
|
|
1816
|
+
lines.push(`${theme.fg("accent", name)}:`);
|
|
1817
|
+
const check = theme.fg("success", "✓");
|
|
1818
|
+
const cross = theme.fg("dim", "✗");
|
|
1819
|
+
if (supportsToolsChanged) lines.push(` ${check} tools/list_changed`);
|
|
1820
|
+
if (supportsResourcesChanged) lines.push(` ${check} resources/list_changed`);
|
|
1821
|
+
if (supportsPromptsChanged) lines.push(` ${check} prompts/list_changed`);
|
|
1822
|
+
|
|
1823
|
+
if (supportsSubscribe) {
|
|
1824
|
+
const subscribedUris = subscriptions.get(name);
|
|
1825
|
+
const subCount = subscribedUris?.size ?? 0;
|
|
1826
|
+
const subStatus =
|
|
1827
|
+
enabled && subCount > 0
|
|
1828
|
+
? theme.fg("success", `subscribed (${subCount} URI${subCount !== 1 ? "s" : ""})`)
|
|
1829
|
+
: enabled
|
|
1830
|
+
? theme.fg("muted", "no active subscriptions")
|
|
1831
|
+
: theme.fg("dim", "inactive (notifications disabled)");
|
|
1832
|
+
lines.push(` ${check} resources/subscribe ${subStatus}`);
|
|
1833
|
+
if (enabled && subscribedUris && subscribedUris.size > 0) {
|
|
1834
|
+
for (const uri of subscribedUris) {
|
|
1835
|
+
lines.push(` ${theme.fg("success", "✓")} ${theme.fg("dim", uri)}`);
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
} else if (supportsResources) {
|
|
1839
|
+
lines.push(` ${cross} resources/subscribe ${theme.fg("dim", "not supported")}`);
|
|
1840
|
+
}
|
|
1841
|
+
lines.push("");
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
if (!hasAny) {
|
|
1845
|
+
lines.push(theme.fg("muted", "No servers support notifications."));
|
|
1846
|
+
lines.push("");
|
|
1847
|
+
}
|
|
1848
|
+
this.#showMessage(lines.join("\n"));
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
async #validateSmitheryApiKey(apiKey: string): Promise<void> {
|
|
1852
|
+
await searchSmitheryRegistry("mcp", { limit: 1, apiKey });
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
async #promptSmitheryApiKey(promptLabel: string): Promise<string | null> {
|
|
1856
|
+
for (;;) {
|
|
1857
|
+
const input = await this.ctx.showHookInput(promptLabel);
|
|
1858
|
+
if (input === undefined) return null;
|
|
1859
|
+
const apiKey = input.trim();
|
|
1860
|
+
if (!apiKey) {
|
|
1861
|
+
this.ctx.showError("Smithery API key cannot be empty.");
|
|
1862
|
+
continue;
|
|
1863
|
+
}
|
|
1864
|
+
try {
|
|
1865
|
+
await this.#validateSmitheryApiKey(apiKey);
|
|
1866
|
+
return apiKey;
|
|
1867
|
+
} catch (error) {
|
|
1868
|
+
this.ctx.showError(
|
|
1869
|
+
`Smithery API key validation failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
1870
|
+
);
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
async #handleSmitheryLoginWithApiKey(): Promise<boolean> {
|
|
1876
|
+
const apiKey = await this.#promptSmitheryApiKey("Smithery API key (Esc to cancel)");
|
|
1877
|
+
if (!apiKey) return false;
|
|
1878
|
+
await saveSmitheryApiKey(apiKey);
|
|
1879
|
+
this.ctx.showStatus("Smithery API key saved.");
|
|
1880
|
+
return true;
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
async #waitForSmitheryCliApiKey(sessionId: string, signal: AbortSignal): Promise<string> {
|
|
1884
|
+
const pollIntervalMs = 2_000;
|
|
1885
|
+
const timeoutMs = 300_000;
|
|
1886
|
+
const startedAt = Date.now();
|
|
1887
|
+
|
|
1888
|
+
while (!signal.aborted) {
|
|
1889
|
+
if (Date.now() - startedAt >= timeoutMs) {
|
|
1890
|
+
throw new Error("Smithery authorization timed out after 5 minutes.");
|
|
1891
|
+
}
|
|
1892
|
+
const response = await pollSmitheryCliAuthSession(sessionId, signal);
|
|
1893
|
+
if (response.status === "success" && response.apiKey) {
|
|
1894
|
+
return response.apiKey;
|
|
1895
|
+
}
|
|
1896
|
+
if (response.status === "error") {
|
|
1897
|
+
throw new Error(response.message ?? "Smithery authorization failed.");
|
|
1898
|
+
}
|
|
1899
|
+
await Bun.sleep(pollIntervalMs);
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
throw new Error("Smithery authorization cancelled.");
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
async #handleSmitheryBrowserLogin(): Promise<boolean> {
|
|
1906
|
+
const session = await createSmitheryCliAuthSession();
|
|
1907
|
+
const fallbackLoginUrl = getSmitheryLoginUrl();
|
|
1908
|
+
this.#showMessage(
|
|
1909
|
+
[
|
|
1910
|
+
"",
|
|
1911
|
+
theme.bold("Smithery Login"),
|
|
1912
|
+
theme.fg("muted", "Browser authorization started. Complete auth in your browser."),
|
|
1913
|
+
theme.fg("dim", "Authorize URL:"),
|
|
1914
|
+
theme.fg("accent", session.authUrl),
|
|
1915
|
+
theme.fg("dim", `Fallback: ${fallbackLoginUrl}`),
|
|
1916
|
+
"",
|
|
1917
|
+
].join("\n"),
|
|
1918
|
+
);
|
|
1919
|
+
try {
|
|
1920
|
+
openPath(session.authUrl);
|
|
1921
|
+
} catch {
|
|
1922
|
+
// URL is already shown above.
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
const apiKey = await this.#waitForSmitheryCliApiKey(session.sessionId, new AbortController().signal);
|
|
1926
|
+
await this.#validateSmitheryApiKey(apiKey);
|
|
1927
|
+
await saveSmitheryApiKey(apiKey);
|
|
1928
|
+
this.ctx.showStatus("Smithery API key saved.");
|
|
1929
|
+
return true;
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
async #promptSmitheryLogin(reason: string): Promise<boolean> {
|
|
1933
|
+
this.#showMessage(
|
|
1934
|
+
[
|
|
1935
|
+
"",
|
|
1936
|
+
theme.fg("muted", `Smithery authentication required (${reason}).`),
|
|
1937
|
+
theme.fg("muted", "If browser auth fails, you can paste an API key."),
|
|
1938
|
+
"",
|
|
1939
|
+
].join("\n"),
|
|
1940
|
+
);
|
|
1941
|
+
try {
|
|
1942
|
+
return await this.#handleSmitheryBrowserLogin();
|
|
1943
|
+
} catch (error) {
|
|
1944
|
+
this.ctx.showWarning(
|
|
1945
|
+
`Browser authorization failed: ${error instanceof Error ? error.message : String(error)}. Falling back to API key.`,
|
|
1946
|
+
);
|
|
1947
|
+
return await this.#handleSmitheryLoginWithApiKey();
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
#getSmitheryErrorStatus(error: unknown): number | undefined {
|
|
1952
|
+
if (error instanceof SmitheryRegistryError || error instanceof SmitheryConnectError) {
|
|
1953
|
+
return error.status;
|
|
1954
|
+
}
|
|
1955
|
+
return undefined;
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
#toSmitheryAuthReason(status: number): string {
|
|
1959
|
+
return status === 429 ? "rate limited by Smithery" : "forbidden/unauthorized with Smithery";
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
async #requireSmitheryApiKey(reason: string): Promise<string> {
|
|
1963
|
+
let apiKey = await getSmitheryApiKey();
|
|
1964
|
+
if (apiKey) return apiKey;
|
|
1965
|
+
|
|
1966
|
+
const loggedIn = await this.#promptSmitheryLogin(reason);
|
|
1967
|
+
if (!loggedIn) {
|
|
1968
|
+
throw new Error("Smithery login cancelled. Run /mcp smithery-login, then retry /mcp smithery-search.");
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
apiKey = await getSmitheryApiKey();
|
|
1972
|
+
if (!apiKey) {
|
|
1973
|
+
throw new Error("Smithery API key not found after login.");
|
|
1974
|
+
}
|
|
1975
|
+
return apiKey;
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
async #runSmitheryOperationWithAuthRetry<T>(operation: (apiKey: string) => Promise<T>, reason: string): Promise<T> {
|
|
1979
|
+
const apiKey = await this.#requireSmitheryApiKey(reason);
|
|
1980
|
+
try {
|
|
1981
|
+
return await operation(apiKey);
|
|
1982
|
+
} catch (error) {
|
|
1983
|
+
const status = this.#getSmitheryErrorStatus(error);
|
|
1984
|
+
if (status === undefined || ![401, 403, 429].includes(status)) {
|
|
1985
|
+
throw error;
|
|
1986
|
+
}
|
|
1987
|
+
const loggedIn = await this.#promptSmitheryLogin(this.#toSmitheryAuthReason(status));
|
|
1988
|
+
if (!loggedIn) {
|
|
1989
|
+
throw error;
|
|
1990
|
+
}
|
|
1991
|
+
const retryApiKey = await this.#requireSmitheryApiKey(reason);
|
|
1992
|
+
return await operation(retryApiKey);
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
async #handleSmitheryLogin(): Promise<void> {
|
|
1997
|
+
const ok = await this.#promptSmitheryLogin("login");
|
|
1998
|
+
if (!ok) {
|
|
1999
|
+
this.ctx.showStatus("Smithery login cancelled.");
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
|
|
2003
|
+
async #handleSmitheryLogout(): Promise<void> {
|
|
2004
|
+
const removed = await clearSmitheryApiKey();
|
|
2005
|
+
this.ctx.showStatus(removed ? "Smithery API key removed." : "No cached Smithery API key found.");
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
async #nextAvailableServerName(scope: MCPAddScope, baseName: string): Promise<string> {
|
|
2009
|
+
const filePath = getMCPConfigPath(scope, getProjectDir());
|
|
2010
|
+
const config = await readMCPConfigFile(filePath);
|
|
2011
|
+
const existingNames = new Set(Object.keys(config.mcpServers ?? {}));
|
|
2012
|
+
if (!existingNames.has(baseName)) return baseName;
|
|
2013
|
+
for (let i = 2; i <= 999; i++) {
|
|
2014
|
+
const candidate = `${baseName}-${i}`;
|
|
2015
|
+
if (!existingNames.has(candidate)) return candidate;
|
|
2016
|
+
}
|
|
2017
|
+
return `${baseName}-${Date.now()}`;
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
async #promptDeploymentServerName(scope: MCPAddScope, defaultName: string): Promise<string | null> {
|
|
2021
|
+
for (;;) {
|
|
2022
|
+
const input = await this.ctx.showHookInput(`Server name for deploy (default: ${defaultName})`, defaultName);
|
|
2023
|
+
if (input === undefined) return null;
|
|
2024
|
+
const proposed = input.trim() || defaultName;
|
|
2025
|
+
if (!proposed) {
|
|
2026
|
+
this.ctx.showError("Server name cannot be empty.");
|
|
2027
|
+
continue;
|
|
2028
|
+
}
|
|
2029
|
+
const filePath = getMCPConfigPath(scope, getProjectDir());
|
|
2030
|
+
const config = await readMCPConfigFile(filePath);
|
|
2031
|
+
if (config.mcpServers?.[proposed]) {
|
|
2032
|
+
this.ctx.showError(`Server "${proposed}" already exists in ${scope} config.`);
|
|
2033
|
+
continue;
|
|
2034
|
+
}
|
|
2035
|
+
return proposed;
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
async #promptRequiredRegistryInputs(result: SmitherySearchResult): Promise<Record<string, string> | null> {
|
|
2040
|
+
const values: Record<string, string> = {};
|
|
2041
|
+
for (const input of result.requiredInputs) {
|
|
2042
|
+
const label = input.required ? `${input.key} (required)` : `${input.key} (optional)`;
|
|
2043
|
+
const prompt = `${label}${input.description ? ` - ${input.description}` : ""}`;
|
|
2044
|
+
const userInput = await this.ctx.showHookInput(prompt, input.defaultValue);
|
|
2045
|
+
if (userInput === undefined) {
|
|
2046
|
+
if (input.required) return null;
|
|
2047
|
+
continue;
|
|
2048
|
+
}
|
|
2049
|
+
const value = userInput.trim();
|
|
2050
|
+
if (!value) {
|
|
2051
|
+
if (input.required) {
|
|
2052
|
+
this.ctx.showError(`Missing required value for "${input.key}".`);
|
|
2053
|
+
return null;
|
|
2054
|
+
}
|
|
2055
|
+
continue;
|
|
2056
|
+
}
|
|
2057
|
+
values[input.key] = value;
|
|
2058
|
+
}
|
|
2059
|
+
return values;
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
#applyRegistryInputOverrides(config: MCPServerConfig, values: Record<string, string>): MCPServerConfig {
|
|
2063
|
+
if (Object.keys(values).length === 0) return config;
|
|
2064
|
+
if (config.type !== "stdio") {
|
|
2065
|
+
return config;
|
|
2066
|
+
}
|
|
2067
|
+
const args = [...(config.args ?? [])];
|
|
2068
|
+
const configJson = JSON.stringify(values);
|
|
2069
|
+
const index = args.indexOf("--config");
|
|
2070
|
+
if (index >= 0) {
|
|
2071
|
+
if (index + 1 < args.length) {
|
|
2072
|
+
args[index + 1] = configJson;
|
|
2073
|
+
} else {
|
|
2074
|
+
args.push(configJson);
|
|
2075
|
+
}
|
|
2076
|
+
} else {
|
|
2077
|
+
args.push("--config", configJson);
|
|
2078
|
+
}
|
|
2079
|
+
return { ...config, args };
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
async #pickRegistryResult(results: SmitherySearchResult[], keyword: string): Promise<SmitherySearchResult | null> {
|
|
2083
|
+
const options = results.map((result, index) => {
|
|
2084
|
+
const label = `${index + 1}. ${result.display.displayName} (${result.display.transport}, uses ${result.display.useCount})`;
|
|
2085
|
+
return label.length > 120 ? `${label.slice(0, 117)}...` : label;
|
|
2086
|
+
});
|
|
2087
|
+
const selected = await this.ctx.showHookSelector(`Registry results for "${keyword}"`, options);
|
|
2088
|
+
if (!selected) return null;
|
|
2089
|
+
const prefix = selected.split(".", 1)[0];
|
|
2090
|
+
const index = Number(prefix) - 1;
|
|
2091
|
+
if (!Number.isInteger(index) || index < 0 || index >= results.length) return null;
|
|
2092
|
+
return results[index] ?? null;
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
async #deployRegistryResult(result: SmitherySearchResult, scope: MCPAddScope): Promise<void> {
|
|
2096
|
+
const baseName = toConfigName(result.name);
|
|
2097
|
+
const defaultName = await this.#nextAvailableServerName(scope, baseName);
|
|
2098
|
+
const serverName = await this.#promptDeploymentServerName(scope, defaultName);
|
|
2099
|
+
if (!serverName) {
|
|
2100
|
+
this.ctx.showStatus("MCP deploy cancelled.");
|
|
2101
|
+
return;
|
|
2102
|
+
}
|
|
2103
|
+
const inputValues = await this.#promptRequiredRegistryInputs(result);
|
|
2104
|
+
if (inputValues === null) {
|
|
2105
|
+
this.ctx.showStatus("MCP deploy cancelled.");
|
|
2106
|
+
return;
|
|
2107
|
+
}
|
|
2108
|
+
const config = this.#applyRegistryInputOverrides(result.config, inputValues);
|
|
2109
|
+
await this.#handleWizardComplete(serverName, config, scope);
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
async #handleSearch(text: string): Promise<void> {
|
|
2113
|
+
const parsed = this.#parseSearchCommand(text);
|
|
2114
|
+
if (parsed.error) {
|
|
2115
|
+
this.ctx.showError(parsed.error);
|
|
2116
|
+
return;
|
|
2117
|
+
}
|
|
2118
|
+
|
|
2119
|
+
try {
|
|
2120
|
+
this.#showMessage(
|
|
2121
|
+
["", theme.fg("muted", `Searching Smithery registry for "${parsed.keyword}"...`), ""].join("\n"),
|
|
2122
|
+
);
|
|
2123
|
+
const results = await this.#runSmitheryOperationWithAuthRetry(
|
|
2124
|
+
apiKey =>
|
|
2125
|
+
searchSmitheryRegistry(parsed.keyword, {
|
|
2126
|
+
limit: parsed.limit,
|
|
2127
|
+
apiKey,
|
|
2128
|
+
includeSemantic: parsed.semantic,
|
|
2129
|
+
}),
|
|
2130
|
+
"required for smithery-search",
|
|
2131
|
+
);
|
|
2132
|
+
if (results.length === 0) {
|
|
2133
|
+
this.#showMessage(
|
|
2134
|
+
["", theme.fg("warning", `No Smithery results found for "${parsed.keyword}".`), ""].join("\n"),
|
|
2135
|
+
);
|
|
2136
|
+
return;
|
|
2137
|
+
}
|
|
2138
|
+
|
|
2139
|
+
const selected = await this.#pickRegistryResult(results, parsed.keyword);
|
|
2140
|
+
if (!selected) {
|
|
2141
|
+
this.ctx.showStatus("MCP Smithery selection cancelled.");
|
|
2142
|
+
return;
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
await this.#deployRegistryResult(selected, parsed.scope);
|
|
2146
|
+
} catch (error) {
|
|
2147
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2148
|
+
if (/authentication was cancelled|login cancelled/i.test(message)) {
|
|
2149
|
+
this.ctx.showError(`${message} Run /mcp smithery-login to authenticate first.`);
|
|
2150
|
+
return;
|
|
2151
|
+
}
|
|
2152
|
+
this.ctx.showError(`Smithery search failed: ${message}`);
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
|
|
2156
|
+
/**
|
|
2157
|
+
* Show a message in the chat
|
|
2158
|
+
*/
|
|
2159
|
+
#showMessage(text: string): void {
|
|
2160
|
+
showCommandMessage(this.ctx, text);
|
|
2161
|
+
}
|
|
2162
|
+
}
|