@punch-bot/cli 1.5.0 → 1.5.3
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 +168 -1
- package/README.md +6 -8
- package/dist/bundle/chunks/anthropic-messages-WIBS5YKY.js +6 -0
- package/dist/bundle/chunks/azure-openai-responses-GP5GDEGO.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +7 -4
- package/dist/bundle/chunks/chunk-35EHANXE.js +2 -0
- package/dist/bundle/chunks/chunk-3IMHRFLG.js +6 -0
- package/dist/bundle/chunks/chunk-77CRE5SV.js +9 -0
- package/dist/bundle/chunks/chunk-CE33JMCE.js +861 -0
- package/dist/bundle/chunks/{chunk-MYNHUMKE.js → chunk-CXY7BILM.js} +2 -44
- package/dist/bundle/chunks/chunk-EISXNXOQ.js +41 -0
- package/dist/bundle/chunks/chunk-ENMVUQHE.js +26 -0
- package/dist/bundle/chunks/chunk-FFMDRXC4.js +10 -0
- package/dist/bundle/chunks/chunk-GFUN2N5K.js +2 -0
- package/dist/bundle/chunks/chunk-HQH636GU.js +361 -0
- package/dist/bundle/chunks/chunk-IEBK4HQA.js +2 -0
- package/dist/bundle/chunks/chunk-JAJLG57O.js +4 -0
- package/dist/bundle/chunks/{chunk-RFVYQ7ZX.js → chunk-LOHGXPCL.js} +2 -2
- package/dist/bundle/chunks/{chunk-NO2FNWW3.js → chunk-OV2VGRRS.js} +1 -1
- package/dist/bundle/chunks/chunk-P7FPUEYA.js +2 -0
- package/dist/bundle/chunks/chunk-PDENR63J.js +16 -0
- package/dist/bundle/chunks/chunk-RHOWRSGK.js +2 -0
- package/dist/bundle/chunks/{chunk-BRECMFDT.js → chunk-UZ3LUZDC.js} +1 -1
- package/dist/bundle/chunks/chunk-WN2D4UD4.js +2 -0
- package/dist/bundle/chunks/chunk-X4T5TGM4.js +82 -0
- package/dist/bundle/chunks/chunk-ZG74NES2.js +2 -0
- package/dist/bundle/chunks/cli-OQNR6ESL.js +53 -0
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-FDCKYGTP.js → cloudflare-workers-ai-system-one-36EDUVVN.js} +1 -1
- package/dist/bundle/chunks/codemode-worker.js +2 -0
- package/dist/bundle/chunks/{execute-HXULRBCI.js → execute-EHT55MW7.js} +5 -3
- package/dist/bundle/chunks/github-copilot.js +1 -1
- package/dist/bundle/chunks/{google-generative-ai-2ESDEFYR.js → google-generative-ai-KA6FZCHM.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-YERBWL2T.js → google-vertex-DXKQ4IYR.js} +1 -1
- package/dist/bundle/chunks/image-resize-worker.js +1 -1
- package/dist/bundle/chunks/kimi-coding.js +1 -1
- package/dist/bundle/chunks/{llama-cpp-classify-M4KMJHPS.js → llama-cpp-classify-676UCBOD.js} +1 -1
- package/dist/bundle/chunks/meta.js +1 -1
- package/dist/bundle/chunks/mistral-conversations-PJ56UMXO.js +5 -0
- package/dist/bundle/chunks/openai-codex-responses-DWVG7MAQ.js +10 -0
- package/dist/bundle/chunks/openai-completions-OKI6KBNP.js +7 -0
- package/dist/bundle/chunks/{openai-decisions-PPJMQ3W4.js → openai-decisions-SO57QA6O.js} +1 -1
- package/dist/bundle/chunks/openai-responses-3HV234HB.js +4 -0
- package/dist/bundle/chunks/{openrouter-images-WWPCCAPX.js → openrouter-images-5X6D7HFS.js} +1 -1
- package/dist/bundle/chunks/pi-messages-BS5Z34RE.js +8 -0
- package/dist/bundle/chunks/radius.js +1 -1
- package/dist/bundle/chunks/{runtime-R5GXO4CV.js → runtime-74PFKASL.js} +1 -1
- package/dist/bundle/chunks/{typesafe-system-one-NLWRPIRL.js → typesafe-system-one-IPNULX2M.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-2Y422I6U.js +2 -0
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/cli/args.d.ts +0 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +8 -12
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/auth-command.d.ts.map +1 -1
- package/dist/cli/auth-command.js +26 -2
- package/dist/cli/auth-command.js.map +1 -1
- package/dist/cli/auth-login.d.ts +15 -0
- package/dist/cli/auth-login.d.ts.map +1 -0
- package/dist/cli/auth-login.js +232 -0
- package/dist/cli/auth-login.js.map +1 -0
- package/dist/cli/auth-logout.d.ts +14 -0
- package/dist/cli/auth-logout.d.ts.map +1 -0
- package/dist/cli/auth-logout.js +63 -0
- package/dist/cli/auth-logout.js.map +1 -0
- package/dist/cli/auth-terminal.d.ts +17 -0
- package/dist/cli/auth-terminal.d.ts.map +1 -0
- package/dist/cli/auth-terminal.js +63 -0
- package/dist/cli/auth-terminal.js.map +1 -0
- package/dist/cli/project-trust.js +1 -1
- package/dist/cli/project-trust.js.map +1 -1
- package/dist/config.d.ts +10 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +24 -11
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +5 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +20 -5
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +31 -15
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +158 -71
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +3 -2
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +3 -1
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/cache-warmer.d.ts +4 -37
- package/dist/core/cache-warmer.d.ts.map +1 -1
- package/dist/core/cache-warmer.js +11 -89
- package/dist/core/cache-warmer.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +4 -2
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +16 -4
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/utils.d.ts.map +1 -1
- package/dist/core/compaction/utils.js +2 -1
- package/dist/core/compaction/utils.js.map +1 -1
- package/dist/core/exec.d.ts +9 -1
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/exec.js +104 -60
- package/dist/core/exec.js.map +1 -1
- package/dist/core/export-html/template.css +9 -0
- package/dist/core/export-html/template.js +165 -45
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +10 -13
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/pi-ai-extension-view.d.ts +19 -0
- package/dist/core/extensions/pi-ai-extension-view.d.ts.map +1 -0
- package/dist/core/extensions/pi-ai-extension-view.js +22 -0
- package/dist/core/extensions/pi-ai-extension-view.js.map +1 -0
- package/dist/core/extensions/runner.d.ts +1 -4
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +0 -14
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +5 -18
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/virtual-modules.js +8 -7
- package/dist/core/extensions/virtual-modules.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/mcp-servers.d.ts +23 -41
- package/dist/core/mcp-servers.d.ts.map +1 -1
- package/dist/core/mcp-servers.js +51 -120
- package/dist/core/mcp-servers.js.map +1 -1
- package/dist/core/model-config.d.ts +1730 -2029
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +2 -3
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +36 -29
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +5 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +11 -4
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/package-manager.d.ts +24 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +210 -51
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/pi-ai-schemas.d.ts +167 -0
- package/dist/core/pi-ai-schemas.d.ts.map +1 -0
- package/dist/core/pi-ai-schemas.js +21 -0
- package/dist/core/pi-ai-schemas.js.map +1 -0
- package/dist/core/pi-manifest.d.ts +1 -0
- package/dist/core/pi-manifest.d.ts.map +1 -1
- package/dist/core/pi-manifest.js +4 -0
- package/dist/core/pi-manifest.js.map +1 -1
- package/dist/core/preferred-providers.d.ts +17 -0
- package/dist/core/preferred-providers.d.ts.map +1 -0
- package/dist/core/preferred-providers.js +24 -0
- package/dist/core/preferred-providers.js.map +1 -0
- package/dist/core/project-trust.d.ts +1 -1
- package/dist/core/project-trust.d.ts.map +1 -1
- package/dist/core/project-trust.js +1 -1
- package/dist/core/project-trust.js.map +1 -1
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +18 -2
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +3 -1
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/provider-matching.d.ts +11 -0
- package/dist/core/provider-matching.d.ts.map +1 -0
- package/dist/core/provider-matching.js +14 -0
- package/dist/core/provider-matching.js.map +1 -0
- package/dist/core/radius-mcp.d.ts +13 -0
- package/dist/core/radius-mcp.d.ts.map +1 -0
- package/dist/core/radius-mcp.js +29 -0
- package/dist/core/radius-mcp.js.map +1 -0
- package/dist/core/radius.d.ts +0 -3
- package/dist/core/radius.d.ts.map +1 -1
- package/dist/core/radius.js +0 -5
- package/dist/core/radius.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +2 -0
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resource-loader.d.ts +4 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +40 -25
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/runtime-credentials.d.ts +8 -0
- package/dist/core/runtime-credentials.d.ts.map +1 -1
- package/dist/core/runtime-credentials.js +15 -1
- package/dist/core/runtime-credentials.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +3 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-cwd.d.ts +0 -1
- package/dist/core/session-cwd.d.ts.map +1 -1
- package/dist/core/session-cwd.js +0 -3
- package/dist/core/session-cwd.js.map +1 -1
- package/dist/core/session-manager.d.ts +7 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +32 -13
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-defaults.d.ts +1 -31
- package/dist/core/settings-defaults.d.ts.map +1 -1
- package/dist/core/settings-defaults.js +1 -31
- package/dist/core/settings-defaults.js.map +1 -1
- package/dist/core/settings-manager.d.ts +4 -56
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +11 -247
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +4 -54
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +7 -101
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +6 -14
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts +0 -6
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -27
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/source-info.d.ts +9 -0
- package/dist/core/source-info.d.ts.map +1 -1
- package/dist/core/source-info.js +13 -0
- package/dist/core/source-info.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +5 -6
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/telemetry.js +1 -1
- package/dist/core/telemetry.js.map +1 -1
- package/dist/core/theme/theme.d.ts.map +1 -1
- package/dist/core/theme/theme.js +5 -1
- package/dist/core/theme/theme.js.map +1 -1
- package/dist/core/tools/bash.d.ts +2 -2
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +35 -5
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +23 -14
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +182 -41
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts +3 -3
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +10 -11
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +2 -2
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +82 -36
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +7 -5
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +87 -75
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts +2 -2
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +2 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/powershell.d.ts.map +1 -1
- package/dist/core/tools/powershell.js +15 -2
- package/dist/core/tools/powershell.js.map +1 -1
- package/dist/core/tools/read.d.ts +10 -2
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +141 -25
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts +11 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/tools/truncate.d.ts +4 -14
- package/dist/core/tools/truncate.d.ts.map +1 -1
- package/dist/core/tools/truncate.js +23 -29
- package/dist/core/tools/truncate.js.map +1 -1
- package/dist/core/tools/write.d.ts +2 -2
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +14 -8
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/core/usage-totals.d.ts.map +1 -1
- package/dist/core/usage-totals.js +2 -0
- package/dist/core/usage-totals.js.map +1 -1
- package/dist/extensions/codemode/execute.js +4 -4
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/codemode/tool.d.ts +2 -1
- package/dist/extensions/codemode/tool.d.ts.map +1 -1
- package/dist/extensions/codemode/tool.js +59 -12
- package/dist/extensions/codemode/tool.js.map +1 -1
- package/dist/extensions/llama/client.d.ts +2 -0
- package/dist/extensions/llama/client.d.ts.map +1 -1
- package/dist/extensions/llama/client.js +23 -2
- package/dist/extensions/llama/client.js.map +1 -1
- package/dist/extensions/llama/index.d.ts.map +1 -1
- package/dist/extensions/llama/index.js +1 -1
- package/dist/extensions/llama/index.js.map +1 -1
- package/dist/extensions/mcp/cli.d.ts +2 -0
- package/dist/extensions/mcp/cli.d.ts.map +1 -1
- package/dist/extensions/mcp/cli.js +83 -22
- package/dist/extensions/mcp/cli.js.map +1 -1
- package/dist/extensions/mcp/config.d.ts.map +1 -1
- package/dist/extensions/mcp/config.js +4 -7
- package/dist/extensions/mcp/config.js.map +1 -1
- package/dist/extensions/mcp/index.d.ts.map +1 -1
- package/dist/extensions/mcp/index.js +5 -4
- package/dist/extensions/mcp/index.js.map +1 -1
- package/dist/extensions/mcp/oauth.d.ts +11 -49
- package/dist/extensions/mcp/oauth.d.ts.map +1 -1
- package/dist/extensions/mcp/oauth.js +56 -296
- package/dist/extensions/mcp/oauth.js.map +1 -1
- package/dist/extensions/mcp/resources.d.ts +1 -1
- package/dist/extensions/mcp/resources.d.ts.map +1 -1
- package/dist/extensions/mcp/resources.js +4 -3
- package/dist/extensions/mcp/resources.js.map +1 -1
- package/dist/extensions/mcp/runtime.d.ts +4 -3
- package/dist/extensions/mcp/runtime.d.ts.map +1 -1
- package/dist/extensions/mcp/runtime.js +7 -5
- package/dist/extensions/mcp/runtime.js.map +1 -1
- package/dist/extensions/mcp/tools.d.ts +2 -23
- package/dist/extensions/mcp/tools.d.ts.map +1 -1
- package/dist/extensions/mcp/tools.js +6 -58
- package/dist/extensions/mcp/tools.js.map +1 -1
- package/dist/extensions/punch/index.d.ts.map +1 -1
- package/dist/extensions/punch/index.js +1 -1
- package/dist/extensions/punch/index.js.map +1 -1
- package/dist/extensions/punch/todos.js +1 -1
- package/dist/extensions/punch/todos.js.map +1 -1
- package/dist/extensions/subagent/index.d.ts.map +1 -1
- package/dist/extensions/subagent/index.js +278 -129
- package/dist/extensions/subagent/index.js.map +1 -1
- package/dist/extensions/tool-search/tool.d.ts +21 -6
- package/dist/extensions/tool-search/tool.d.ts.map +1 -1
- package/dist/extensions/tool-search/tool.js +122 -42
- package/dist/extensions/tool-search/tool.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +106 -14
- package/dist/main.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +19 -10
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +53 -23
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +94 -12
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/ansi.d.ts.map +1 -1
- package/dist/utils/ansi.js +5 -2
- package/dist/utils/ansi.js.map +1 -1
- package/dist/utils/changelog.d.ts +2 -2
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/changelog.js +12 -9
- package/dist/utils/changelog.js.map +1 -1
- package/dist/utils/clipboard-command.d.ts.map +1 -1
- package/dist/utils/clipboard-command.js +4 -0
- package/dist/utils/clipboard-command.js.map +1 -1
- package/dist/utils/fuzzy.d.ts.map +1 -1
- package/dist/utils/fuzzy.js +59 -44
- package/dist/utils/fuzzy.js.map +1 -1
- package/dist/utils/git.d.ts +11 -1
- package/dist/utils/git.d.ts.map +1 -1
- package/dist/utils/git.js +44 -0
- package/dist/utils/git.js.map +1 -1
- package/dist/utils/image-resize-core.d.ts.map +1 -1
- package/dist/utils/image-resize-core.js +5 -3
- package/dist/utils/image-resize-core.js.map +1 -1
- package/dist/utils/image-resize.d.ts.map +1 -1
- package/dist/utils/image-resize.js +3 -1
- package/dist/utils/image-resize.js.map +1 -1
- package/dist/utils/open-browser.d.ts.map +1 -1
- package/dist/utils/open-browser.js +4 -1
- package/dist/utils/open-browser.js.map +1 -1
- package/dist/utils/paths.d.ts +17 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +42 -1
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +14 -0
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/terminal-question.d.ts +8 -0
- package/dist/utils/terminal-question.d.ts.map +1 -0
- package/dist/utils/terminal-question.js +24 -0
- package/dist/utils/terminal-question.js.map +1 -0
- package/dist/utils/text.d.ts +2 -0
- package/dist/utils/text.d.ts.map +1 -1
- package/dist/utils/text.js +5 -0
- package/dist/utils/text.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +30 -35
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/web-url.d.ts +12 -0
- package/dist/utils/web-url.d.ts.map +1 -0
- package/dist/utils/web-url.js +20 -0
- package/dist/utils/web-url.js.map +1 -0
- package/docs/cli-integration.md +3 -5
- package/docs/cli.md +45 -26
- package/docs/compaction.md +9 -9
- package/docs/configuration.md +1 -2
- package/docs/containerization.md +16 -14
- package/docs/custom-provider.md +5 -3
- package/docs/docs.json +9 -9
- package/docs/environment-variables.md +5 -12
- package/docs/extensions.md +683 -757
- package/docs/how-pi-works.md +5 -5
- package/docs/index.md +5 -5
- package/docs/llama-cpp.md +41 -39
- package/docs/mcp.md +12 -10
- package/docs/message-types.md +1 -1
- package/docs/models-configuration.md +6 -1
- package/docs/models.md +18 -19
- package/docs/nvidia-rtx-llama-cpp.md +1 -1
- package/docs/packages.md +21 -1
- package/docs/prompt-templates.md +11 -9
- package/docs/providers.md +8 -8
- package/docs/quickstart.md +28 -52
- package/docs/rpc-commands.md +2 -2
- package/docs/rpc-extension-ui.md +5 -7
- package/docs/rpc.md +4 -2
- package/docs/sdk.md +1 -1
- package/docs/security.md +9 -5
- package/docs/session-format.md +7 -9
- package/docs/sessions.md +26 -26
- package/docs/settings.md +36 -67
- package/docs/shell-aliases.md +7 -7
- package/docs/skills.md +4 -4
- package/docs/slash-commands.md +50 -58
- package/docs/termux.md +8 -9
- package/docs/themes.md +21 -41
- package/docs/usage.md +59 -177
- package/docs/virtual-models.md +4 -4
- package/docs/windows.md +8 -10
- package/examples/extensions/README.md +3 -2
- package/examples/extensions/custom-provider-anthropic/index.ts +27 -31
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +19 -29
- package/examples/extensions/gondolin/package.json +2 -2
- package/examples/extensions/reload-runtime.ts +17 -5
- package/examples/extensions/rpc-demo.ts +2 -2
- package/examples/extensions/subagent/README.md +14 -11
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/tsconfig.json +208 -0
- package/npm-shrinkwrap.json +58 -53
- package/package.json +15 -17
- package/schemas/models.schema.json +65 -36
- package/schemas/settings.schema.json +17 -243
- package/dist/bundle/chunks/anthropic-messages-WCANLUXE.js +0 -6
- package/dist/bundle/chunks/azure-openai-responses-46GRAI5B.js +0 -2
- package/dist/bundle/chunks/chunk-37OLNCAX.js +0 -16
- package/dist/bundle/chunks/chunk-3V45WARH.js +0 -7
- package/dist/bundle/chunks/chunk-4LBJE4YM.js +0 -14
- package/dist/bundle/chunks/chunk-4NE64BTO.js +0 -82
- package/dist/bundle/chunks/chunk-5NXXRYVM.js +0 -2
- package/dist/bundle/chunks/chunk-7BOHO7TR.js +0 -1190
- package/dist/bundle/chunks/chunk-7XECPCHN.js +0 -2
- package/dist/bundle/chunks/chunk-NJK3U3WK.js +0 -8
- package/dist/bundle/chunks/chunk-PLK2QSUR.js +0 -2
- package/dist/bundle/chunks/chunk-TEPMHNKQ.js +0 -2
- package/dist/bundle/chunks/chunk-UE7JCDFW.js +0 -2
- package/dist/bundle/chunks/chunk-UKVNB6C4.js +0 -2
- package/dist/bundle/chunks/chunk-USJZMAIR.js +0 -2
- package/dist/bundle/chunks/chunk-WZONBDPY.js +0 -11
- package/dist/bundle/chunks/cli-W5KJM7YB.js +0 -51
- package/dist/bundle/chunks/mistral-conversations-D6VQXE7C.js +0 -5
- package/dist/bundle/chunks/openai-codex-responses-QSNSWBYG.js +0 -10
- package/dist/bundle/chunks/openai-completions-72VXSFHQ.js +0 -7
- package/dist/bundle/chunks/openai-responses-PMTL72CY.js +0 -4
- package/dist/bundle/chunks/pi-messages-WVCFUCBL.js +0 -8
- package/dist/bundle/chunks/virtual-modules-7Y5QW4VK.js +0 -2
- package/dist/core/bug-report-upload.d.ts +0 -12
- package/dist/core/bug-report-upload.d.ts.map +0 -1
- package/dist/core/bug-report-upload.js +0 -22
- package/dist/core/bug-report-upload.js.map +0 -1
- package/dist/core/bug-report.d.ts +0 -184
- package/dist/core/bug-report.d.ts.map +0 -1
- package/dist/core/bug-report.js +0 -292
- package/dist/core/bug-report.js.map +0 -1
- package/dist/core/crash-log.d.ts +0 -27
- package/dist/core/crash-log.d.ts.map +0 -1
- package/dist/core/crash-log.js +0 -140
- package/dist/core/crash-log.js.map +0 -1
- package/dist/core/footer-data-provider.d.ts +0 -64
- package/dist/core/footer-data-provider.d.ts.map +0 -1
- package/dist/core/footer-data-provider.js +0 -338
- package/dist/core/footer-data-provider.js.map +0 -1
- package/dist/utils/zip.d.ts +0 -7
- package/dist/utils/zip.d.ts.map +0 -1
- package/dist/utils/zip.js +0 -60
- package/dist/utils/zip.js.map +0 -1
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/keybindings.md +0 -194
- package/docs/terminal-setup.md +0 -17
- package/docs/tmux.md +0 -55
- package/docs/tui.md +0 -125
- package/examples/extensions/sandbox/index.ts +0 -321
- package/examples/extensions/sandbox/package-lock.json +0 -92
- package/examples/extensions/sandbox/package.json +0 -19
|
@@ -30,15 +30,12 @@
|
|
|
30
30
|
*/
|
|
31
31
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
32
32
|
import { dirname, join } from "node:path";
|
|
33
|
+
import { isMcpServerOverride, mcpNamespace } from "@punch-bot/mcp";
|
|
33
34
|
import { CONFIG_DIR_NAME } from "../../config.js";
|
|
34
|
-
import {
|
|
35
|
+
import { validateMcpServerConfig } from "../../core/mcp-servers.js";
|
|
35
36
|
import { stripBom } from "../../utils/text.js";
|
|
36
37
|
export { getMcpToolExposure } from "../../core/mcp-servers.js";
|
|
37
38
|
const OVERRIDE_KEYS = ["enabled", "exposure", "toolExposure"];
|
|
38
|
-
/** Whether an entry overrides a server defined elsewhere instead of defining one. */
|
|
39
|
-
function isOverride(value) {
|
|
40
|
-
return value.command === undefined && value.url === undefined && value.type === undefined;
|
|
41
|
-
}
|
|
42
39
|
function isRecord(value) {
|
|
43
40
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
44
41
|
}
|
|
@@ -63,7 +60,7 @@ function readConfigFile(path, scope, state) {
|
|
|
63
60
|
else if (parsed.autoEnableCodemode !== undefined)
|
|
64
61
|
errors.push(`${path}: autoEnableCodemode must be a boolean`);
|
|
65
62
|
for (const [name, value] of Object.entries(parsed.mcpServers ?? {})) {
|
|
66
|
-
if (scope === "project" && isRecord(value) &&
|
|
63
|
+
if (scope === "project" && isRecord(value) && isMcpServerOverride(value)) {
|
|
67
64
|
const base = servers.get(name);
|
|
68
65
|
const extra = Object.keys(value).filter((key) => !OVERRIDE_KEYS.includes(key));
|
|
69
66
|
if (!base) {
|
|
@@ -130,7 +127,7 @@ export function updateMcpServerConfig(path, name, patch, options = {}) {
|
|
|
130
127
|
}
|
|
131
128
|
if (!isRecord(server))
|
|
132
129
|
throw new Error(`${path} does not define MCP server "${name}"`);
|
|
133
|
-
const keepDefaults =
|
|
130
|
+
const keepDefaults = isMcpServerOverride(server);
|
|
134
131
|
if (patch.enabled !== undefined) {
|
|
135
132
|
if (patch.enabled && !keepDefaults)
|
|
136
133
|
delete server.enabled;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/extensions/mcp/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAGN,YAAY,EACZ,uBAAuB,GACvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAS/C,OAAO,EAAE,kBAAkB,EAAE,M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,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3D,aAAa,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AACnF,CAAC","sourcesContent":["/**\n * MCP server configuration.\n *\n * Servers are read from `mcp.json` in the agent directory and, for trusted projects, from\n * `<project>/.pi/mcp.json`. Both use the `mcpServers` shape shared by other MCP clients, so\n * existing configurations can be copied over. Project entries replace global entries with the\n * same name.\n *\n * A project entry without `command`, `url`, or `type` overrides only `enabled`, `exposure`, and\n * `toolExposure` of the global server with the same name, for example to turn it off in one project:\n * `{ \"mcpServers\": { \"internal-tools\": { \"enabled\": false } } }`. The rest of the global entry is kept,\n * including credentials the project could not set itself.\n *\n * ```json\n * {\n * \"mcpServers\": {\n * \"filesystem\": { \"command\": \"npx\", \"args\": [\"-y\", \"@modelcontextprotocol/server-filesystem\", \".\"] },\n * \"docs\": { \"url\": \"https://example.com/mcp\", \"headers\": { \"Authorization\": \"Bearer ${DOCS_TOKEN}\" } },\n * \"sentry\": { \"url\": \"https://mcp.sentry.dev/mcp\" }\n * }\n * }\n * ```\n *\n * HTTP servers without an `Authorization` header use OAuth when they answer 401 (sign in with `/mcp`).\n * `\"auth\": { \"provider\": \"<provider>\" }` sends the token of a `/login` provider instead. Project files\n * cannot use it, so a repository cannot pick where the credential goes.\n *\n * The top-level `autoEnableCodemode` (default true) activates the codemode tool when a server\n * with `codemode` exposure connects. A project value overrides the global one.\n */\n\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { CONFIG_DIR_NAME } from \"../../config.ts\";\nimport {\n\ttype McpExposure,\n\ttype McpServerConfig,\n\tmcpNamespace,\n\tvalidateMcpServerConfig,\n} from \"../../core/mcp-servers.ts\";\nimport { stripBom } from \"../../utils/text.ts\";\n\nexport type {\n\tMcpExposure,\n\tMcpHttpServerConfig,\n\tMcpOAuthConfig,\n\tMcpServerConfig,\n\tMcpStdioServerConfig,\n} from \"../../core/mcp-servers.ts\";\nexport { getMcpToolExposure } from \"../../core/mcp-servers.ts\";\n\nexport interface McpServerEntry {\n\tname: string;\n\tconfig: McpServerConfig;\n\t/** Config file that defined the entry, or the path of the extension that registered it. */\n\tsource: string;\n\t/**\n\t * The global or the project `mcp.json`, or `extension` for servers registered with\n\t * `pi.registerMcpServer()`. Changes to extension servers are not saved.\n\t */\n\tscope?: \"global\" | \"project\" | \"extension\";\n\t/** Project `mcp.json` with an override of this global server's `enabled`, `exposure`, or `toolExposure`. */\n\toverride?: string;\n}\n\nexport interface LoadedMcpConfig {\n\tservers: McpServerEntry[];\n\t/** Activate the codemode tool when `codemode` servers connect. Default: true. */\n\tautoEnableCodemode?: boolean;\n\terrors: string[];\n\t/** The project `mcp.json` when the project is trusted, where `/mcp` saves project overrides. */\n\tprojectConfig?: string;\n}\n\nconst OVERRIDE_KEYS = [\"enabled\", \"exposure\", \"toolExposure\"];\n\n/** Whether an entry overrides a server defined elsewhere instead of defining one. */\nfunction isOverride(value: Record<string, unknown>): boolean {\n\treturn value.command === undefined && value.url === undefined && value.type === undefined;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\ninterface McpConfigState {\n\tservers: Map<string, McpServerEntry>;\n\tautoEnableCodemode?: boolean;\n\terrors: string[];\n}\n\nfunction readConfigFile(path: string, scope: \"global\" | \"project\", state: McpConfigState): void {\n\tconst { servers, errors } = state;\n\tif (!existsSync(path)) return;\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(stripBom(readFileSync(path, \"utf8\")));\n\t} catch (error) {\n\t\terrors.push(`${path}: ${error instanceof Error ? error.message : String(error)}`);\n\t\treturn;\n\t}\n\tif (!isRecord(parsed) || (parsed.mcpServers !== undefined && !isRecord(parsed.mcpServers))) {\n\t\terrors.push(`${path}: expected an object with an \"mcpServers\" object`);\n\t\treturn;\n\t}\n\tif (typeof parsed.autoEnableCodemode === \"boolean\") state.autoEnableCodemode = parsed.autoEnableCodemode;\n\telse if (parsed.autoEnableCodemode !== undefined) errors.push(`${path}: autoEnableCodemode must be a boolean`);\n\tfor (const [name, value] of Object.entries(parsed.mcpServers ?? {})) {\n\t\tif (scope === \"project\" && isRecord(value) && isOverride(value)) {\n\t\t\tconst base = servers.get(name);\n\t\t\tconst extra = Object.keys(value).filter((key) => !OVERRIDE_KEYS.includes(key));\n\t\t\tif (!base) {\n\t\t\t\terrors.push(`${path}: server \"${name}\" needs \"command\" or \"url\", or a global server to override`);\n\t\t\t} else if (extra.length > 0) {\n\t\t\t\terrors.push(`${path}: server \"${name}\": an override can only set ${OVERRIDE_KEYS.join(\", \")}`);\n\t\t\t} else {\n\t\t\t\tconst config = validateMcpServerConfig(name, { ...base.config, ...value });\n\t\t\t\tif (typeof config === \"string\") errors.push(`${path}: ${config}`);\n\t\t\t\telse servers.set(name, { ...base, config, override: path });\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst config = validateMcpServerConfig(name, value);\n\t\tif (typeof config === \"string\") {\n\t\t\terrors.push(`${path}: ${config}`);\n\t\t\tcontinue;\n\t\t}\n\t\t// Names that differ only in `-` and `_` would share a namespace.\n\t\tconst clash = [...servers.keys()].find((other) => other !== name && mcpNamespace(other) === mcpNamespace(name));\n\t\tif (clash) {\n\t\t\terrors.push(`${path}: server \"${name}\" conflicts with \"${clash}\"`);\n\t\t\tcontinue;\n\t\t}\n\t\tif (scope === \"project\" && \"url\" in config && config.auth) {\n\t\t\terrors.push(`${path}: server \"${name}\": auth is only allowed in the global mcp.json`);\n\t\t\tcontinue;\n\t\t}\n\t\tservers.set(name, { name, config, source: path, scope });\n\t}\n}\n\n/**\n * Load global and (when trusted) project MCP configuration. Disabled servers are included with\n * `enabled: false`, so they can be enabled again.\n */\nexport function loadMcpConfig(options: { agentDir: string; cwd: string; projectTrusted: boolean }): LoadedMcpConfig {\n\tconst state: McpConfigState = { servers: new Map(), errors: [] };\n\treadConfigFile(join(options.agentDir, \"mcp.json\"), \"global\", state);\n\tconst projectConfig = options.projectTrusted ? join(options.cwd, CONFIG_DIR_NAME, \"mcp.json\") : undefined;\n\tif (projectConfig) readConfigFile(projectConfig, \"project\", state);\n\treturn {\n\t\tservers: [...state.servers.values()],\n\t\t...(state.autoEnableCodemode === undefined ? {} : { autoEnableCodemode: state.autoEnableCodemode }),\n\t\terrors: state.errors,\n\t\t...(projectConfig ? { projectConfig } : {}),\n\t};\n}\n\n/** Settings `/mcp` changes. `enabled: true` and `exposure: \"codemode\"` are the defaults and remove the key. */\nexport interface McpServerConfigPatch {\n\tenabled?: boolean;\n\texposure?: McpExposure;\n}\n\n/**\n * Change one server's settings in the `mcp.json` that defines or overrides it. With `override`, a\n * missing entry is added as an override. Overrides keep default values, since they replace the global\n * server's. Other content is kept; the file is rewritten with its indentation.\n */\nexport function updateMcpServerConfig(\n\tpath: string,\n\tname: string,\n\tpatch: McpServerConfigPatch,\n\toptions: { override?: boolean } = {},\n): void {\n\teditMcpServers(path, (servers, parsed) => {\n\t\tlet server = servers?.[name];\n\t\tif (server === undefined && options.override) {\n\t\t\tserver = {};\n\t\t\tparsed.mcpServers = { ...servers, [name]: server };\n\t\t}\n\t\tif (!isRecord(server)) throw new Error(`${path} does not define MCP server \"${name}\"`);\n\t\tconst keepDefaults = isOverride(server);\n\t\tif (patch.enabled !== undefined) {\n\t\t\tif (patch.enabled && !keepDefaults) delete server.enabled;\n\t\t\telse server.enabled = patch.enabled;\n\t\t}\n\t\tif (patch.exposure !== undefined) {\n\t\t\tif (patch.exposure === \"codemode\" && !keepDefaults) delete server.exposure;\n\t\t\telse server.exposure = patch.exposure;\n\t\t}\n\t\treturn true;\n\t});\n}\n\n/**\n * Add a server to an `mcp.json`, creating the file when missing. An existing entry with the same\n * name is replaced. Returns true when an entry was replaced.\n */\nexport function addMcpServerConfig(path: string, name: string, config: McpServerConfig): boolean {\n\tlet replaced = false;\n\teditMcpServers(path, (servers, parsed) => {\n\t\tconst target = servers ?? {};\n\t\treplaced = target[name] !== undefined;\n\t\ttarget[name] = config;\n\t\tparsed.mcpServers = target;\n\t\treturn true;\n\t});\n\treturn replaced;\n}\n\n/** Remove a server from an `mcp.json`. Returns false when the file does not define it. */\nexport function removeMcpServerConfig(path: string, name: string): boolean {\n\tif (!existsSync(path)) return false;\n\tlet removed = false;\n\teditMcpServers(path, (servers) => {\n\t\tif (!servers || servers[name] === undefined) return false;\n\t\tdelete servers[name];\n\t\tremoved = true;\n\t\treturn true;\n\t});\n\treturn removed;\n}\n\n/**\n * Read an `mcp.json` (an empty config when missing), let `edit` change its `mcpServers`, and write\n * it back with its indentation when `edit` returns true. Other content is kept.\n */\nfunction editMcpServers(\n\tpath: string,\n\tedit: (servers: Record<string, unknown> | undefined, parsed: Record<string, unknown>) => boolean,\n): void {\n\tconst text = existsSync(path) ? stripBom(readFileSync(path, \"utf8\")) : undefined;\n\tconst parsed: unknown = text === undefined ? {} : JSON.parse(text);\n\tif (!isRecord(parsed) || (parsed.mcpServers !== undefined && !isRecord(parsed.mcpServers))) {\n\t\tthrow new Error(`${path}: expected an object with an \"mcpServers\" object`);\n\t}\n\tconst servers = isRecord(parsed.mcpServers) ? parsed.mcpServers : undefined;\n\tif (!edit(servers, parsed)) return;\n\tconst indent = (text && /^([ \\t]+)\\S/m.exec(text)?.[1]) || \" \";\n\t// mcp.json can hold literal credentials. The modes apply only to a newly created directory or file, so existing\n\t// permissions are kept.\n\tmkdirSync(dirname(path), { recursive: true, mode: 0o700 });\n\twriteFileSync(path, `${JSON.stringify(parsed, null, indent)}\\n`, { mode: 0o600 });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/extensions/mcp/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,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GAAG,CAAC,IAAI,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IAChE,gHAAgH;IAChH,wBAAwB;IACxB,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3D,aAAa,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AACnF,CAAC","sourcesContent":["/**\n * MCP server configuration.\n *\n * Servers are read from `mcp.json` in the agent directory and, for trusted projects, from\n * `<project>/.pi/mcp.json`. Both use the `mcpServers` shape shared by other MCP clients, so\n * existing configurations can be copied over. Project entries replace global entries with the\n * same name.\n *\n * A project entry without `command`, `url`, or `type` overrides only `enabled`, `exposure`, and\n * `toolExposure` of the global server with the same name, for example to turn it off in one project:\n * `{ \"mcpServers\": { \"internal-tools\": { \"enabled\": false } } }`. The rest of the global entry is kept,\n * including credentials the project could not set itself.\n *\n * ```json\n * {\n * \"mcpServers\": {\n * \"filesystem\": { \"command\": \"npx\", \"args\": [\"-y\", \"@modelcontextprotocol/server-filesystem\", \".\"] },\n * \"docs\": { \"url\": \"https://example.com/mcp\", \"headers\": { \"Authorization\": \"Bearer ${DOCS_TOKEN}\" } },\n * \"sentry\": { \"url\": \"https://mcp.sentry.dev/mcp\" }\n * }\n * }\n * ```\n *\n * HTTP servers without an `Authorization` header use OAuth when they answer 401 (sign in with `/mcp`).\n * `\"auth\": { \"provider\": \"<provider>\" }` sends the token of a `/login` provider instead. Project files\n * cannot use it, so a repository cannot pick where the credential goes.\n *\n * The top-level `autoEnableCodemode` (default true) activates the codemode tool when a server\n * with `codemode` exposure connects. A project value overrides the global one.\n */\n\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { isMcpServerOverride, mcpNamespace } from \"@punch-bot/mcp\";\nimport { CONFIG_DIR_NAME } from \"../../config.ts\";\nimport { type McpExposure, type McpServerConfig, validateMcpServerConfig } from \"../../core/mcp-servers.ts\";\nimport { stripBom } from \"../../utils/text.ts\";\n\nexport type {\n\tMcpExposure,\n\tMcpHttpServerConfig,\n\tMcpOAuthConfig,\n\tMcpServerConfig,\n\tMcpStdioServerConfig,\n} from \"../../core/mcp-servers.ts\";\nexport { getMcpToolExposure } from \"../../core/mcp-servers.ts\";\n\nexport interface McpServerEntry {\n\tname: string;\n\tconfig: McpServerConfig;\n\t/** Config file that defined the entry, or the path of the extension that registered it. */\n\tsource: string;\n\t/**\n\t * The global or the project `mcp.json`, or `extension` for servers registered with\n\t * `pi.registerMcpServer()`. Changes to extension servers are not saved.\n\t */\n\tscope?: \"global\" | \"project\" | \"extension\";\n\t/** Project `mcp.json` with an override of this global server's `enabled`, `exposure`, or `toolExposure`. */\n\toverride?: string;\n}\n\nexport interface LoadedMcpConfig {\n\tservers: McpServerEntry[];\n\t/** Activate the codemode tool when `codemode` servers connect. Default: true. */\n\tautoEnableCodemode?: boolean;\n\terrors: string[];\n\t/** The project `mcp.json` when the project is trusted, where `/mcp` saves project overrides. */\n\tprojectConfig?: string;\n}\n\nconst OVERRIDE_KEYS = [\"enabled\", \"exposure\", \"toolExposure\"];\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\ninterface McpConfigState {\n\tservers: Map<string, McpServerEntry>;\n\tautoEnableCodemode?: boolean;\n\terrors: string[];\n}\n\nfunction readConfigFile(path: string, scope: \"global\" | \"project\", state: McpConfigState): void {\n\tconst { servers, errors } = state;\n\tif (!existsSync(path)) return;\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(stripBom(readFileSync(path, \"utf8\")));\n\t} catch (error) {\n\t\terrors.push(`${path}: ${error instanceof Error ? error.message : String(error)}`);\n\t\treturn;\n\t}\n\tif (!isRecord(parsed) || (parsed.mcpServers !== undefined && !isRecord(parsed.mcpServers))) {\n\t\terrors.push(`${path}: expected an object with an \"mcpServers\" object`);\n\t\treturn;\n\t}\n\tif (typeof parsed.autoEnableCodemode === \"boolean\") state.autoEnableCodemode = parsed.autoEnableCodemode;\n\telse if (parsed.autoEnableCodemode !== undefined) errors.push(`${path}: autoEnableCodemode must be a boolean`);\n\tfor (const [name, value] of Object.entries(parsed.mcpServers ?? {})) {\n\t\tif (scope === \"project\" && isRecord(value) && isMcpServerOverride(value)) {\n\t\t\tconst base = servers.get(name);\n\t\t\tconst extra = Object.keys(value).filter((key) => !OVERRIDE_KEYS.includes(key));\n\t\t\tif (!base) {\n\t\t\t\terrors.push(`${path}: server \"${name}\" needs \"command\" or \"url\", or a global server to override`);\n\t\t\t} else if (extra.length > 0) {\n\t\t\t\terrors.push(`${path}: server \"${name}\": an override can only set ${OVERRIDE_KEYS.join(\", \")}`);\n\t\t\t} else {\n\t\t\t\tconst config = validateMcpServerConfig(name, { ...base.config, ...value });\n\t\t\t\tif (typeof config === \"string\") errors.push(`${path}: ${config}`);\n\t\t\t\telse servers.set(name, { ...base, config, override: path });\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst config = validateMcpServerConfig(name, value);\n\t\tif (typeof config === \"string\") {\n\t\t\terrors.push(`${path}: ${config}`);\n\t\t\tcontinue;\n\t\t}\n\t\t// Names that differ only in `-` and `_` would share a namespace.\n\t\tconst clash = [...servers.keys()].find((other) => other !== name && mcpNamespace(other) === mcpNamespace(name));\n\t\tif (clash) {\n\t\t\terrors.push(`${path}: server \"${name}\" conflicts with \"${clash}\"`);\n\t\t\tcontinue;\n\t\t}\n\t\tif (scope === \"project\" && \"url\" in config && config.auth) {\n\t\t\terrors.push(`${path}: server \"${name}\": auth is only allowed in the global mcp.json`);\n\t\t\tcontinue;\n\t\t}\n\t\tservers.set(name, { name, config, source: path, scope });\n\t}\n}\n\n/**\n * Load global and (when trusted) project MCP configuration. Disabled servers are included with\n * `enabled: false`, so they can be enabled again.\n */\nexport function loadMcpConfig(options: { agentDir: string; cwd: string; projectTrusted: boolean }): LoadedMcpConfig {\n\tconst state: McpConfigState = { servers: new Map(), errors: [] };\n\treadConfigFile(join(options.agentDir, \"mcp.json\"), \"global\", state);\n\tconst projectConfig = options.projectTrusted ? join(options.cwd, CONFIG_DIR_NAME, \"mcp.json\") : undefined;\n\tif (projectConfig) readConfigFile(projectConfig, \"project\", state);\n\treturn {\n\t\tservers: [...state.servers.values()],\n\t\t...(state.autoEnableCodemode === undefined ? {} : { autoEnableCodemode: state.autoEnableCodemode }),\n\t\terrors: state.errors,\n\t\t...(projectConfig ? { projectConfig } : {}),\n\t};\n}\n\n/** Settings `/mcp` changes. `enabled: true` and `exposure: \"codemode\"` are the defaults and remove the key. */\nexport interface McpServerConfigPatch {\n\tenabled?: boolean;\n\texposure?: McpExposure;\n}\n\n/**\n * Change one server's settings in the `mcp.json` that defines or overrides it. With `override`, a\n * missing entry is added as an override. Overrides keep default values, since they replace the global\n * server's. Other content is kept; the file is rewritten with its indentation.\n */\nexport function updateMcpServerConfig(\n\tpath: string,\n\tname: string,\n\tpatch: McpServerConfigPatch,\n\toptions: { override?: boolean } = {},\n): void {\n\teditMcpServers(path, (servers, parsed) => {\n\t\tlet server = servers?.[name];\n\t\tif (server === undefined && options.override) {\n\t\t\tserver = {};\n\t\t\tparsed.mcpServers = { ...servers, [name]: server };\n\t\t}\n\t\tif (!isRecord(server)) throw new Error(`${path} does not define MCP server \"${name}\"`);\n\t\tconst keepDefaults = isMcpServerOverride(server);\n\t\tif (patch.enabled !== undefined) {\n\t\t\tif (patch.enabled && !keepDefaults) delete server.enabled;\n\t\t\telse server.enabled = patch.enabled;\n\t\t}\n\t\tif (patch.exposure !== undefined) {\n\t\t\tif (patch.exposure === \"codemode\" && !keepDefaults) delete server.exposure;\n\t\t\telse server.exposure = patch.exposure;\n\t\t}\n\t\treturn true;\n\t});\n}\n\n/**\n * Add a server to an `mcp.json`, creating the file when missing. An existing entry with the same\n * name is replaced. Returns true when an entry was replaced.\n */\nexport function addMcpServerConfig(path: string, name: string, config: McpServerConfig): boolean {\n\tlet replaced = false;\n\teditMcpServers(path, (servers, parsed) => {\n\t\tconst target = servers ?? {};\n\t\treplaced = target[name] !== undefined;\n\t\ttarget[name] = config;\n\t\tparsed.mcpServers = target;\n\t\treturn true;\n\t});\n\treturn replaced;\n}\n\n/** Remove a server from an `mcp.json`. Returns false when the file does not define it. */\nexport function removeMcpServerConfig(path: string, name: string): boolean {\n\tif (!existsSync(path)) return false;\n\tlet removed = false;\n\teditMcpServers(path, (servers) => {\n\t\tif (!servers || servers[name] === undefined) return false;\n\t\tdelete servers[name];\n\t\tremoved = true;\n\t\treturn true;\n\t});\n\treturn removed;\n}\n\n/**\n * Read an `mcp.json` (an empty config when missing), let `edit` change its `mcpServers`, and write\n * it back with its indentation when `edit` returns true. Other content is kept.\n */\nfunction editMcpServers(\n\tpath: string,\n\tedit: (servers: Record<string, unknown> | undefined, parsed: Record<string, unknown>) => boolean,\n): void {\n\tconst text = existsSync(path) ? stripBom(readFileSync(path, \"utf8\")) : undefined;\n\tconst parsed: unknown = text === undefined ? {} : JSON.parse(text);\n\tif (!isRecord(parsed) || (parsed.mcpServers !== undefined && !isRecord(parsed.mcpServers))) {\n\t\tthrow new Error(`${path}: expected an object with an \"mcpServers\" object`);\n\t}\n\tconst servers = isRecord(parsed.mcpServers) ? parsed.mcpServers : undefined;\n\tif (!edit(servers, parsed)) return;\n\tconst indent = (text && /^([ \\t]+)\\S/m.exec(text)?.[1]) || \" \";\n\t// mcp.json can hold literal credentials. The modes apply only to a newly created directory or file, so existing\n\t// permissions are kept.\n\tmkdirSync(dirname(path), { recursive: true, mode: 0o700 });\n\twriteFileSync(path, `${JSON.stringify(parsed, null, indent)}\\n`, { mode: 0o600 });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAMH,OAAO,KAAK,EAGX,gBAAgB,EAChB,gBAAgB,EAEhB,MAAM,gCAAgC,CAAC;AAMxC,OAAO,EAEN,KAAK,eAAe,EAGpB,KAAK,cAAc,EACnB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,uBAAuB,EAAmB,MAAM,YAAY,CAAC;AAS3E,OAAO,KAAK,EAAqC,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAG3F,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExD,MAAM,WAAW,mBAAmB;IACnC,uFAAuF;IACvF,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,eAAe,CAAC;IACxD,qFAAqF;IACrF,eAAe,CAAC,EAAE,mBAAmB,CAAC;IACtC,0DAA0D;IAC1D,WAAW,CAAC,EAAE,uBAAuB,CAAC;IACtC,8FAA8F;IAC9F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB;AAsDD,6FAA6F;AAC7F,eAAO,MAAM,mBAAmB,gBAAgB,CAAC;AAGjD;;;GAGG;AACH,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAe9C,wDAAwD;AACxD,MAAM,WAAW,gBAAgB;IAChC,KAAK,EAAE,cAAc,CAAC;IACtB,UAAU,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACvC;AAQD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,GAAG,MAAM,GAAG,SAAS,CA0B7F;AAmCD,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,mBAAwB,GAAG,gBAAgB,CAmtBtF"}
|
|
@@ -24,15 +24,16 @@
|
|
|
24
24
|
* reported once. `/mcp` shows status; its subcommands sign in, sign out, and reconnect servers.
|
|
25
25
|
*/
|
|
26
26
|
import { join, resolve } from "node:path";
|
|
27
|
+
import { createMcpToolName, mcpNamespace } from "@punch-bot/mcp";
|
|
27
28
|
import { getAgentDir } from "../../config.js";
|
|
28
|
-
import {
|
|
29
|
+
import { sliceHead } from "../../core/tools/truncate.js";
|
|
29
30
|
import { openBrowser } from "../../utils/open-browser.js";
|
|
30
31
|
import { CODEMODE_TOOL_NAME } from "../codemode/tool.js";
|
|
31
32
|
import { TOOL_SEARCH_TOOL_NAME } from "../tool-search/tool.js";
|
|
32
33
|
import { getMcpToolExposure, loadMcpConfig, } from "./config.js";
|
|
33
34
|
import { createMcpResourceToolDefinitions, LIST_MCP_RESOURCE_TEMPLATES_TOOL, LIST_MCP_RESOURCES_TOOL, READ_MCP_RESOURCE_TOOL, } from "./resources.js";
|
|
34
35
|
import { loadMcpRuntime } from "./runtime.lazy.js";
|
|
35
|
-
import { createMcpToolDefinition
|
|
36
|
+
import { createMcpToolDefinition } from "./tools.js";
|
|
36
37
|
const DEFAULT_STARTUP_WAIT_MS = 10_000;
|
|
37
38
|
const RESOURCE_TOOL_NAMES = new Set([
|
|
38
39
|
LIST_MCP_RESOURCES_TOOL,
|
|
@@ -85,7 +86,7 @@ function serversSectionIntro(reaches) {
|
|
|
85
86
|
function truncate(text, max) {
|
|
86
87
|
if (text.length <= max)
|
|
87
88
|
return text;
|
|
88
|
-
return max <= 1 ? "" : `${text
|
|
89
|
+
return max <= 1 ? "" : `${sliceHead(text, max - 1).trimEnd()}…`;
|
|
89
90
|
}
|
|
90
91
|
/** First line of the configured description, or of the server instructions once connected. */
|
|
91
92
|
function serverSummary(server) {
|
|
@@ -773,7 +774,7 @@ export function createMcpExtension(options = {}) {
|
|
|
773
774
|
await Promise.all([...backgroundActions, ...closing.map((connection) => connection.close())]);
|
|
774
775
|
});
|
|
775
776
|
pi.registerCommand("mcp", {
|
|
776
|
-
description: "
|
|
777
|
+
description: "Show MCP server status, sign in or out, or reconnect",
|
|
777
778
|
getArgumentCompletions: (prefix) => {
|
|
778
779
|
const [action, server, ...rest] = prefix.trimStart().split(/\s+/);
|
|
779
780
|
if (rest.length > 0)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAQ9C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EACN,kBAAkB,EAElB,aAAa,GAGb,MAAM,aAAa,CAAC;AAErB,OAAO,EACN,gCAAgC,EAChC,gCAAgC,EAChC,uBAAuB,EACvB,sBAAsB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAuB,MAAM,YAAY,CAAC;AAuB7F,MAAM,uBAAuB,GAAG,MAAM,CAAC;AAEvC,MAAM,mBAAmB,GAAwB,IAAI,GAAG,CAAC;IACxD,uBAAuB;IACvB,gCAAgC;IAChC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AC;wBACD,OAAO;oBACR,CAAC;oBACD;wBACC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;gBACtC,CAAC;YACF,CAAC;SACD,CAAC,CAAC;IACJ,CAAC,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAqB;IAC/C,OAAO,aAAa,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE,GAAG,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;AACzG,CAAC;AAED,eAAe,kBAAkB,EAAE,CAAC","sourcesContent":["/**\n * Built-in MCP integration.\n *\n * Connects the servers from `mcp.json` and the servers extensions register with\n * `pi.registerMcpServer()` when a session starts, and servers registered later right away. A server\n * in `mcp.json` takes precedence over a registered server of the same name. Connections run in the\n * background: the first prompt waits only for servers with `direct` tools, and codemode scripts,\n * `tool_search`, and the resource tools wait for the servers they need when they run. Tools are\n * registered as `mcp__<server>__<tool>`. By default (`\"exposure\": \"codemode\"`) the tools are only\n * callable from codemode scripts, which keeps MCP tools out of the model's tool declarations and\n * the codemode description: scripts find the tools with `searchTools()` and the server instructions\n * with `describeNamespace()`. The codemode tool is activated for that unless `autoEnableCodemode` is\n * false. `\"deferred\"` declares the tools to the model once the `tool_search` tool loads them, and\n * activates `tool_search` instead of codemode.\n * `\"exposure\": \"direct\"` declares them to the model right away, and `\"hidden\"` makes them\n * unreachable. `toolExposure` overrides the exposure of single tools. Servers with resources are\n * reached through Codex's `list_mcp_resources`, `list_mcp_resource_templates`, and\n * `read_mcp_resource` tools (resources.ts).\n *\n * Every call runs through pi's tool pipeline, so `tool_call`/`tool_result` hooks and permission\n * extensions apply to MCP tools the same way they do to built-in tools.\n *\n * Problems found at startup (config errors, failed connections, servers that need a sign-in) are\n * reported once. `/mcp` shows status; its subcommands sign in, sign out, and reconnect servers.\n */\n\nimport { join, resolve } from \"node:path\";\nimport type { TSchema } from \"typebox\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type {\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n\tExtensionFactory,\n\tToolDefinition,\n} from \"../../core/extensions/types.ts\";\nimport { mcpNamespace } from \"../../core/mcp-servers.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport { openBrowser } from \"../../utils/open-browser.ts\";\nimport { CODEMODE_TOOL_NAME } from \"../codemode/tool.ts\";\nimport { TOOL_SEARCH_TOOL_NAME } from \"../tool-search/tool.ts\";\nimport {\n\tgetMcpToolExposure,\n\ttype LoadedMcpConfig,\n\tloadMcpConfig,\n\ttype McpExposure,\n\ttype McpServerEntry,\n} from \"./config.ts\";\nimport type { McpOAuthCredentialStore, McpSignInPrompt } from \"./oauth.ts\";\nimport {\n\tcreateMcpResourceToolDefinitions,\n\tLIST_MCP_RESOURCE_TEMPLATES_TOOL,\n\tLIST_MCP_RESOURCES_TOOL,\n\tREAD_MCP_RESOURCE_TOOL,\n} from \"./resources.ts\";\nimport { loadMcpRuntime } from \"./runtime.lazy.ts\";\nimport type * as McpRuntime from \"./runtime.ts\";\nimport type { McpServerConnection, McpServerLog, McpTransportFactory } from \"./runtime.ts\";\nimport { createMcpToolDefinition, createMcpToolName, type McpToolDetails } from \"./tools.ts\";\n\nexport type { McpTransportFactory } from \"./runtime.ts\";\n\nexport interface McpExtensionOptions {\n\t/** Defaults to reading `mcp.json` from the agent directory and the trusted project. */\n\tloadConfig?: (ctx: ExtensionContext) => LoadedMcpConfig;\n\t/** Defaults to stdio and streamable HTTP transports built from the server config. */\n\tcreateTransport?: McpTransportFactory;\n\t/** Defaults to `mcp-auth.json` in the agent directory. */\n\tcredentials?: McpOAuthCredentialStore;\n\t/** File server log messages are appended to. Defaults to `mcp.log` in the agent directory. */\n\tlogPath?: string;\n\t/** Opens the OAuth authorization URL. Defaults to the platform browser. */\n\topenUrl?: (url: string) => void;\n\t/**\n\t * How long the first prompt waits for servers with `direct` tools that are still connecting at\n\t * startup, in milliseconds. Their tools become available when they connect. Other servers are\n\t * waited for when a script or search needs them. Default: 10000.\n\t */\n\tstartupWaitMs?: number;\n}\n\nconst DEFAULT_STARTUP_WAIT_MS = 10_000;\n\nconst RESOURCE_TOOL_NAMES: ReadonlySet<string> = new Set([\n\tLIST_MCP_RESOURCES_TOOL,\n\tLIST_MCP_RESOURCE_TEMPLATES_TOOL,\n\tREAD_MCP_RESOURCE_TOOL,\n]);\n\n/** A configured server. Disabled servers have no connection. */\ninterface McpServer {\n\tentry: McpServerEntry;\n\tconnection?: McpServerConnection;\n\t/** For servers extensions registered: the config as registered, to detect re-registrations. */\n\tregisteredConfig?: string;\n\t/** Identifies the current connection attempt; disabling or replacing it invalidates earlier work. */\n\tattempt?: symbol;\n\t/** Settles when the connection started for the server connected or failed. */\n\tready?: Promise<void>;\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction firstLine(text: string): string {\n\treturn text.split(\"\\n\", 1)[0] ?? \"\";\n}\n\nfunction isEnabled(server: Pick<McpServer, \"entry\">): boolean {\n\treturn server.entry.config.enabled !== false;\n}\n\nfunction exposureOf(entry: McpServerEntry): McpExposure {\n\treturn entry.config.exposure ?? \"codemode\";\n}\n\n/** Exposures the server's tools can have, known from its config before it connects. */\nfunction configuredExposures(entry: McpServerEntry): Set<McpExposure> {\n\treturn new Set([exposureOf(entry), ...Object.values(entry.config.toolExposure ?? {})]);\n}\n\n/** Whether some of the server's tools are declared to the model, so the first prompt waits for them. */\nfunction hasDirectTools(entry: McpServerEntry): boolean {\n\treturn configuredExposures(entry).has(\"direct\");\n}\n\n/** Whether some of the server's tools are reached through codemode or tool_search. */\nfunction hasIndirectTools(entry: McpServerEntry): boolean {\n\tconst exposures = configuredExposures(entry);\n\treturn exposures.has(\"codemode\") || exposures.has(\"deferred\");\n}\n\n/** Name of the system prompt section that lists the servers whose tools are not declared. */\nexport const MCP_SERVERS_SECTION = \"mcp_servers\";\n/** Characters of a server description in the section, as Codex allows for deferred namespaces. */\nconst MAX_SERVER_DESCRIPTION_CHARS = 250;\n/**\n * Characters of the whole section. Descriptions shrink to fit; when the server lines alone do not\n * fit, the last servers are left out and counted in a closing line.\n */\nexport const MAX_SERVERS_SECTION_CHARS = 4096;\n\n/** The section's first line. It explains only the ways of reaching tools that the listed servers use. */\nfunction serversSectionIntro(reaches: ReadonlySet<string>): string {\n\tlet intro = \"MCP servers whose tools are not declared to you.\";\n\tif (reaches.has(\"codemode\")) intro += \" Call the tools of `codemode` servers from codemode scripts.\";\n\tif (reaches.has(\"tool_search\")) intro += \" Load the tools of `tool_search` servers with `tool_search`.\";\n\treturn intro;\n}\n\nfunction truncate(text: string, max: number): string {\n\tif (text.length <= max) return text;\n\treturn max <= 1 ? \"\" : `${text.slice(0, max - 1).trimEnd()}…`;\n}\n\n/** What the `mcp_servers` section needs of a server. */\nexport interface McpServerListing {\n\tentry: McpServerEntry;\n\tconnection?: { instructions?: string };\n}\n\n/** First line of the configured description, or of the server instructions once connected. */\nfunction serverSummary(server: McpServerListing): string {\n\tconst text = server.entry.config.description?.trim() || server.connection?.instructions || \"\";\n\treturn (text.split(\"\\n\", 1)[0] ?? \"\").trim();\n}\n\n/**\n * The `mcp_servers` section: every enabled server with codemode or deferred tools, with how its\n * tools are reached and a one-line summary. The model learns of the servers from it, since neither\n * codemode nor tool_search lists them. Undefined when there are no such servers.\n */\nexport function renderServersSection(servers: readonly McpServerListing[]): string | undefined {\n\tconst listed = servers\n\t\t.filter((server) => isEnabled(server) && hasIndirectTools(server.entry))\n\t\t.sort((a, b) => a.entry.name.localeCompare(b.entry.name));\n\tif (listed.length === 0) return undefined;\n\tconst reaches = listed.map((server) =>\n\t\tconfiguredExposures(server.entry).has(\"codemode\") ? \"codemode\" : \"tool_search\",\n\t);\n\tconst intro = serversSectionIntro(new Set(reaches));\n\tconst heads = listed.map((server, index) => `- ${mcpNamespace(server.entry.name)} (${reaches[index]})`);\n\tconst omitted = (count: number) =>\n\t\tcount > 0 ? [`- … ${count} more server${count === 1 ? \"\" : \"s\"}; find their tools with searchTools()`] : [];\n\t// Characters of the intro, the first `kept` server lines without descriptions, and the omission line.\n\tconst size = (kept: number) => [intro, ...heads.slice(0, kept), ...omitted(listed.length - kept)].join(\"\\n\").length;\n\tlet kept = listed.length;\n\twhile (kept > 0 && size(kept) > MAX_SERVERS_SECTION_CHARS) kept--;\n\t// Each description also takes a \": \" separator.\n\tconst perServer =\n\t\tkept === 0\n\t\t\t? 0\n\t\t\t: Math.min(MAX_SERVER_DESCRIPTION_CHARS, Math.floor((MAX_SERVERS_SECTION_CHARS - size(kept)) / kept) - 2);\n\tconst lines = listed.slice(0, kept).map((server, index) => {\n\t\tconst summary = perServer > 0 ? truncate(serverSummary(server), perServer) : \"\";\n\t\treturn summary ? `${heads[index]}: ${summary}` : heads[index];\n\t});\n\treturn [intro, ...lines, ...omitted(listed.length - kept)].join(\"\\n\");\n}\n\n/**\n * Whether a call that reaches `reach` (see `ToolDefinition.reachesTools`) needs the server: it\n * reaches every tool, or one of its words contains the server's namespace.\n */\nfunction reachesServer(reach: \"all\" | readonly string[], server: string): boolean {\n\tif (reach === \"all\") return true;\n\tconst namespace = mcpNamespace(server);\n\treturn reach.some((word) => word.includes(namespace));\n}\n\n/** Short state for lists and the startup report. `withError` appends the first line of a failure. */\nfunction describeState(server: McpServer, withError = true): string {\n\tif (!isEnabled(server)) return \"disabled\";\n\tconst connection = server.connection;\n\tif (!connection) return \"starting\";\n\tswitch (connection.state) {\n\t\tcase \"needs-auth\":\n\t\t\treturn \"needs sign-in\";\n\t\tcase \"failed\":\n\t\t\treturn withError ? `failed: ${firstLine(connection.error ?? \"unknown error\")}` : \"failed\";\n\t\tcase \"connected\": {\n\t\t\tconst { tools, hasResources } = connection;\n\t\t\treturn `connected · ${tools.length} tool${tools.length === 1 ? \"\" : \"s\"}${hasResources ? \" · resources\" : \"\"}`;\n\t\t}\n\t\tcase \"connecting\":\n\t\t\treturn \"connecting…\";\n\t\tdefault:\n\t\t\treturn connection.state;\n\t}\n}\n\nconst MCP_USAGE = \"Usage: /mcp, /mcp login [server], /mcp logout [server], /mcp reconnect [server]\";\n\nexport function createMcpExtension(options: McpExtensionOptions = {}): ExtensionFactory {\n\treturn (pi: ExtensionAPI) => {\n\t\tlet servers: McpServer[] = [];\n\t\t/** Servers from `mcp.json`, which take precedence over registered servers of the same name. */\n\t\tlet configuredEntries: McpServerEntry[] = [];\n\t\tlet configErrors: string[] = [];\n\t\t/** Registered servers that `mcp.json` overrides, shown in `/mcp`. */\n\t\tlet overridden: string[] = [];\n\t\tlet autoEnableCodemode = true;\n\t\t/** Whether the \"codemode tools unreachable\" warning was shown since the session started. */\n\t\tlet warnedUnreachable = false;\n\t\tlet pending: Promise<unknown> | undefined;\n\t\t/** Whether a prompt already waited for the startup connections since the session started. */\n\t\tlet waitedForStartup = false;\n\t\tconst startupWaitMs = options.startupWaitMs ?? DEFAULT_STARTUP_WAIT_MS;\n\t\t/** Working directory of the session, for stdio servers. */\n\t\tlet sessionCwd = process.cwd();\n\t\tlet credentials = options.credentials;\n\t\t/** The session's model registry, which resolves `auth.provider` tokens. */\n\t\tlet modelRegistry: ModelRegistry | undefined;\n\t\tlet serverLog: McpServerLog | undefined;\n\t\tconst openUrl = options.openUrl ?? openBrowser;\n\n\t\t/**\n\t\t * Lifetime of the current session: aborted on session_shutdown, and before the first session_start\n\t\t * (registrations before that are read on session_start). Work captures `session.signal` when it\n\t\t * starts and drops late results once it aborted, for example a runtime load that resolves after\n\t\t * shutdown. Work that outlives the command that started it also stops on the signal and is\n\t\t * registered with `track`, so shutdown can wait for its cleanup.\n\t\t */\n\t\tlet session = new AbortController();\n\t\tsession.abort();\n\t\t/** Work registered with `track`: sign-ins, which shutdown waits for. */\n\t\tconst backgroundActions = new Set<Promise<void>>();\n\t\tconst track = <T>(work: Promise<T>): Promise<T> => {\n\t\t\tconst task = work.then(\n\t\t\t\t() => undefined,\n\t\t\t\t() => undefined,\n\t\t\t);\n\t\t\tbackgroundActions.add(task);\n\t\t\tvoid task.finally(() => backgroundActions.delete(task));\n\t\t\treturn work;\n\t\t};\n\n\t\tconst connections = () => servers.flatMap((server) => (server.connection ? [server.connection] : []));\n\t\tconst findServer = (name: string) => servers.find((server) => server.entry.name === name);\n\n\t\t/** Servers extensions registered, except names `mcp.json` defines, which take precedence. */\n\t\tconst registeredServers = (): { servers: McpServer[]; overridden: string[] } => {\n\t\t\tconst registered: McpServer[] = [];\n\t\t\tconst overriddenNames: string[] = [];\n\t\t\tfor (const { name, config, extensionPath } of pi.getMcpServers()) {\n\t\t\t\tconst configured = configuredEntries.find((entry) => mcpNamespace(entry.name) === mcpNamespace(name));\n\t\t\t\tif (configured) {\n\t\t\t\t\toverriddenNames.push(\n\t\t\t\t\t\t`\"${name}\" registered by ${extensionPath} is overridden by \"${configured.name}\" in ${configured.source}`,\n\t\t\t\t\t);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tregistered.push({\n\t\t\t\t\tentry: { name, config, source: extensionPath, scope: \"extension\" },\n\t\t\t\t\tregisteredConfig: JSON.stringify(config),\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn { servers: registered, overridden: overriddenNames };\n\t\t};\n\n\t\tconst getCredentials = (runtime: typeof McpRuntime): McpOAuthCredentialStore => {\n\t\t\tcredentials ??= new runtime.McpOAuthCredentialStore();\n\t\t\treturn credentials;\n\t\t};\n\n\t\tconst getServerLog = (runtime: typeof McpRuntime): McpServerLog => {\n\t\t\tserverLog ??= new runtime.McpServerLog(options.logPath ?? join(getAgentDir(), \"mcp.log\"));\n\t\t\treturn serverLog;\n\t\t};\n\n\t\t/** pi tool name to the `<server>\\0<tool>` it was assigned to, so names stay unique and stable. */\n\t\tconst toolOwners = new Map<string, string>();\n\t\t/** Tool names currently offered by each server. */\n\t\tconst serverTools = new Map<string, Set<string>>();\n\t\t/** Last definition registered under each tool name, to re-register withdrawn tools as hidden. */\n\t\tconst definitions = new Map<string, ToolDefinition<TSchema, McpToolDetails>>();\n\n\t\tconst registerTools = (connection: McpServerConnection) => {\n\t\t\tconst server = connection.entry.name;\n\t\t\tconst entry = findServer(server)?.entry ?? connection.entry;\n\t\t\tconst description = entry.config.description?.trim();\n\t\t\tconst namespace = {\n\t\t\t\tname: mcpNamespace(server),\n\t\t\t\t// `describeNamespace(\"docs\")` finds `mcp__docs`.\n\t\t\t\taliases: [server],\n\t\t\t\t...(description ? { description } : {}),\n\t\t\t\t...(connection.instructions ? { instructions: connection.instructions } : {}),\n\t\t\t};\n\t\t\tconst previous = serverTools.get(server) ?? new Set<string>();\n\t\t\tconst current = new Set<string>();\n\t\t\t// Like Codex, all tools whose names sanitize to the same name get the hash suffix, so which\n\t\t\t// one would keep the plain name does not depend on the order of the list.\n\t\t\tconst plain = [...new Set(connection.tools.map((tool) => tool.name))].map((tool) =>\n\t\t\t\tcreateMcpToolName(server, tool),\n\t\t\t);\n\t\t\tconst assignName = (tool: string, owner: string) => {\n\t\t\t\tconst name = createMcpToolName(server, tool, (candidate) => {\n\t\t\t\t\tconst existing = toolOwners.get(candidate);\n\t\t\t\t\treturn (\n\t\t\t\t\t\t(existing !== undefined && existing !== owner) ||\n\t\t\t\t\t\tcurrent.has(candidate) ||\n\t\t\t\t\t\tplain.indexOf(candidate) !== plain.lastIndexOf(candidate)\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t\ttoolOwners.set(name, owner);\n\t\t\t\tcurrent.add(name);\n\t\t\t\treturn name;\n\t\t\t};\n\t\t\tfor (const tool of connection.tools) {\n\t\t\t\tconst definition = createMcpToolDefinition({\n\t\t\t\t\tserver,\n\t\t\t\t\ttool,\n\t\t\t\t\tname: assignName(tool.name, `${server}\\0${tool.name}`),\n\t\t\t\t\texposure: getMcpToolExposure(entry.config, tool.name),\n\t\t\t\t\tnamespace,\n\t\t\t\t\ttimeoutMs: connection.timeoutMs,\n\t\t\t\t\tgetClient: async () => {\n\t\t\t\t\t\t// A prepared call can outlive this definition's connection while the readiness\n\t\t\t\t\t\t// hook waits for a disable/re-enable. Resolve the replacement at execution time.\n\t\t\t\t\t\tconst current = findServer(server);\n\t\t\t\t\t\tif (!current || !isEnabled(current)) throw new Error(`MCP server \"${server}\" is disabled.`);\n\t\t\t\t\t\tconst client = current.connection;\n\t\t\t\t\t\tif (!client) throw new Error(`MCP server \"${server}\" is still starting.`);\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tgetMcpToolExposure(current.entry.config, tool.name) === \"hidden\" ||\n\t\t\t\t\t\t\t(client.state === \"connected\" && !client.tools.some((offered) => offered.name === tool.name))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthrow new Error(`MCP tool \"${server}/${tool.name}\" is no longer available.`);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn client;\n\t\t\t\t\t},\n\t\t\t\t\treadableResources: () => resourceServers().some((current) => current.name === server),\n\t\t\t\t});\n\t\t\t\tdefinitions.set(definition.name, definition);\n\t\t\t\tpi.registerTool(definition);\n\t\t\t}\n\t\t\tserverTools.set(server, current);\n\t\t\t// Tools cannot be unregistered, so tools the server dropped are re-registered as hidden. When\n\t\t\t// the server offers them again they are registered with their configured exposure above.\n\t\t\tfor (const name of previous) {\n\t\t\t\tconst definition = definitions.get(name);\n\t\t\t\tif (!current.has(name) && definition) pi.registerTool({ ...definition, exposure: \"hidden\" });\n\t\t\t}\n\t\t\tsyncResourceTools();\n\t\t};\n\n\t\t/** Make a disabled server's tools unreachable. */\n\t\tconst hideTools = (server: string) => {\n\t\t\tfor (const name of serverTools.get(server) ?? []) {\n\t\t\t\tconst definition = definitions.get(name);\n\t\t\t\tif (definition) pi.registerTool({ ...definition, exposure: \"hidden\" });\n\t\t\t}\n\t\t\tserverTools.set(server, new Set());\n\t\t\tsyncResourceTools();\n\t\t};\n\n\t\t/** Enabled servers with resources whose exposure is not `hidden`, which the resource tools reach. */\n\t\tconst serversWithResources = (): McpServer[] =>\n\t\t\tservers.filter(\n\t\t\t\t(server) => server.connection?.hasResources && isEnabled(server) && exposureOf(server.entry) !== \"hidden\",\n\t\t\t);\n\t\tconst resourceServers = (): McpServerConnection[] =>\n\t\t\tserversWithResources().flatMap((server) => (server.connection ? [server.connection] : []));\n\n\t\t/** Exposure the resource tools were last registered with; undefined until a server has resources. */\n\t\tlet resourceToolsExposure: McpExposure | undefined;\n\t\t/**\n\t\t * Register the resource tools with the widest exposure of the servers they reach: `direct` when\n\t\t * one of them is direct, and so on. They are hidden when no server has resources.\n\t\t */\n\t\tconst syncResourceTools = () => {\n\t\t\tconst exposures = new Set(serversWithResources().map((server) => exposureOf(server.entry)));\n\t\t\tconst exposure = ([\"direct\", \"codemode\", \"deferred\"] as const).find((candidate) => exposures.has(candidate));\n\t\t\tconst next = exposure ?? \"hidden\";\n\t\t\tif (next === resourceToolsExposure || (resourceToolsExposure === undefined && next === \"hidden\")) return;\n\t\t\tconst wasDirect = resourceToolsExposure === \"direct\";\n\t\t\tresourceToolsExposure = next;\n\t\t\tconst resourceDefinitions = createMcpResourceToolDefinitions({ exposure: next, servers: resourceServers });\n\t\t\tfor (const definition of resourceDefinitions) pi.registerTool(definition);\n\t\t\tif (wasDirect) {\n\t\t\t\tconst names = new Set(resourceDefinitions.map((definition) => definition.name));\n\t\t\t\tpi.setActiveTools(pi.getActiveTools().filter((name) => !names.has(name)));\n\t\t\t}\n\t\t};\n\n\t\t/**\n\t\t * Tools that are not declared to the model are reached through the codemode tool (scripts call\n\t\t * them) or the tool_search tool (it declares them). Either reaches every such tool. Activate the\n\t\t * one the tools' exposure asks for: codemode for `codemode` unless `autoEnableCodemode` is false,\n\t\t * tool_search for `deferred`.\n\t\t */\n\t\tconst ensureDiscoveryActive = (ctx: ExtensionContext) => {\n\t\t\t// From the config, so the tool is active before the servers connect. Resource tools share\n\t\t\t// their server's exposure.\n\t\t\tconst exposures = new Set<McpExposure>();\n\t\t\tfor (const server of servers) {\n\t\t\t\tif (isEnabled(server)) for (const exposure of configuredExposures(server.entry)) exposures.add(exposure);\n\t\t\t}\n\t\t\tconst needsCodemode = exposures.has(\"codemode\");\n\t\t\tconst needsToolSearch = exposures.has(\"deferred\");\n\t\t\tif (!needsCodemode && !needsToolSearch) return;\n\t\t\t// Only a tool of these names that declares `reachesTools` can reach MCP tools; another\n\t\t\t// extension's tool of the same name without it is never activated.\n\t\t\tconst tools = pi.getAllTools();\n\t\t\tconst hasReachingTool = (name: string) => tools.some((tool) => tool.name === name && tool.reachesTools);\n\t\t\tconst hasCodemode = hasReachingTool(CODEMODE_TOOL_NAME);\n\t\t\tconst hasToolSearch = hasReachingTool(TOOL_SEARCH_TOOL_NAME);\n\t\t\tconst active = pi.getActiveTools();\n\t\t\tconst activate: string[] = [];\n\t\t\tif (needsCodemode && hasCodemode && autoEnableCodemode && !active.includes(CODEMODE_TOOL_NAME)) {\n\t\t\t\tactivate.push(CODEMODE_TOOL_NAME);\n\t\t\t}\n\t\t\tif (needsToolSearch && hasToolSearch && !active.includes(TOOL_SEARCH_TOOL_NAME)) {\n\t\t\t\tactivate.push(TOOL_SEARCH_TOOL_NAME);\n\t\t\t}\n\t\t\tif (activate.length > 0) pi.setActiveTools([...active, ...activate]);\n\t\t\tconst reachable = [...active, ...activate];\n\t\t\tif (hasCodemode && reachable.includes(CODEMODE_TOOL_NAME)) return;\n\t\t\tif (hasToolSearch && reachable.includes(TOOL_SEARCH_TOOL_NAME)) return;\n\t\t\tif (warnedUnreachable) return;\n\t\t\twarnedUnreachable = true;\n\t\t\tconst reason = needsCodemode && hasCodemode && !autoEnableCodemode ? \" (autoEnableCodemode is false)\" : \"\";\n\t\t\tctx.ui.notify(\n\t\t\t\t`MCP tools are only reachable from the codemode or tool_search tool, but neither is active${reason}; they cannot be called.`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t};\n\n\t\t/**\n\t\t * Stored tokens of servers waiting for a sign-in, as they were when the sign-in was needed.\n\t\t * `pi mcp login` in another process (for example run by the agent) changes them.\n\t\t */\n\t\tconst tokensAtSignIn = new Map<McpServerConnection, string>();\n\t\tconst storedTokens = (connection: McpServerConnection): string => {\n\t\t\tconst url = connection.oauthUrl;\n\t\t\treturn url && credentials ? JSON.stringify(credentials.tokens(connection.name, url) ?? null) : \"null\";\n\t\t};\n\t\tconst onConnectionChange = (connection: McpServerConnection) => {\n\t\t\tif (connection.state !== \"needs-auth\") tokensAtSignIn.delete(connection);\n\t\t\telse if (!tokensAtSignIn.has(connection)) tokensAtSignIn.set(connection, storedTokens(connection));\n\t\t};\n\t\t/** Reconnect servers that need a sign-in when their credentials were stored since. */\n\t\tconst reconnectSignedIn = async (ctx: ExtensionContext) => {\n\t\t\tconst signedIn = [...tokensAtSignIn].filter(([connection, tokens]) => storedTokens(connection) !== tokens);\n\t\t\tif (signedIn.length === 0) return;\n\t\t\tfor (const [connection] of signedIn) tokensAtSignIn.delete(connection);\n\t\t\tawait Promise.allSettled(signedIn.map(([connection]) => connection.reconnect()));\n\t\t\tensureDiscoveryActive(ctx);\n\t\t};\n\n\t\t/** Create the server's connection, loading the MCP runtime on first use. */\n\t\tconst createConnection = async (\n\t\t\tserver: McpServer,\n\t\t\tisCurrent: () => boolean,\n\t\t): Promise<McpServerConnection | undefined> => {\n\t\t\tconst runtime = await loadMcpRuntime();\n\t\t\tif (!isCurrent()) return undefined;\n\t\t\tconst connection = new runtime.McpServerConnection({\n\t\t\t\tentry: server.entry,\n\t\t\t\tcwd: sessionCwd,\n\t\t\t\tcreateTransport: options.createTransport ?? runtime.createDefaultTransport,\n\t\t\t\tcredentials: getCredentials(runtime),\n\t\t\t\tproviderToken: async (provider) => modelRegistry?.getApiKeyForProvider(provider),\n\t\t\t\tlog: getServerLog(runtime),\n\t\t\t\tonTools: (connection) => {\n\t\t\t\t\tif (isCurrent()) registerTools(connection);\n\t\t\t\t},\n\t\t\t\tonChange: (connection) => {\n\t\t\t\t\tif (isCurrent()) onConnectionChange(connection);\n\t\t\t\t\telse tokensAtSignIn.delete(connection);\n\t\t\t\t},\n\t\t\t});\n\t\t\tserver.connection = connection;\n\t\t\treturn connection;\n\t\t};\n\n\t\t/**\n\t\t * Connect the server in the background. `server.ready` settles when it connected or failed;\n\t\t * failures show in its state. It starts after `after`, unless disabled, replaced, or shut down\n\t\t * meanwhile. The returned promise rejects when the MCP runtime cannot be loaded.\n\t\t */\n\t\tconst startConnection = (server: McpServer, after?: Promise<unknown>): Promise<void> => {\n\t\t\tconst { signal } = session;\n\t\t\tconst attempt = Symbol();\n\t\t\tserver.attempt = attempt;\n\t\t\tconst isCurrent = () =>\n\t\t\t\t!signal.aborted && server.attempt === attempt && isEnabled(server) && servers.includes(server);\n\t\t\tconst ready = (async () => {\n\t\t\t\tawait after;\n\t\t\t\tif (!isCurrent()) return;\n\t\t\t\tconst connection = await createConnection(server, isCurrent);\n\t\t\t\tif (!connection || !isCurrent()) return;\n\t\t\t\tawait connection.getClient().catch(() => undefined);\n\t\t\t})();\n\t\t\tserver.ready = ready.catch(() => undefined);\n\t\t\treturn ready;\n\t\t};\n\n\t\t/** Wait for the latest connection attempts, including ones queued while waiting, or an abort. */\n\t\tconst waitForServers = async (waiting: readonly McpServer[], signal: AbortSignal | undefined) => {\n\t\t\tfor (;;) {\n\t\t\t\tconst ready = waiting.flatMap((server) =>\n\t\t\t\t\tisEnabled(server) && servers.includes(server) && server.ready ? [{ server, ready: server.ready }] : [],\n\t\t\t\t);\n\t\t\t\tif (ready.length === 0 || signal?.aborted) return;\n\t\t\t\tlet onAbort: (() => void) | undefined;\n\t\t\t\tawait Promise.race([\n\t\t\t\t\tPromise.all(ready.map((attempt) => attempt.ready)),\n\t\t\t\t\tnew Promise<void>((resolve) => {\n\t\t\t\t\t\tonAbort = () => resolve();\n\t\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t\t}),\n\t\t\t\t]);\n\t\t\t\tif (onAbort) signal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\tif (\n\t\t\t\t\tsignal?.aborted ||\n\t\t\t\t\tready.every(\n\t\t\t\t\t\t(attempt) =>\n\t\t\t\t\t\t\t!isEnabled(attempt.server) ||\n\t\t\t\t\t\t\t!servers.includes(attempt.server) ||\n\t\t\t\t\t\t\tattempt.ready === attempt.server.ready,\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\treturn;\n\t\t\t}\n\t\t};\n\n\t\t/**\n\t\t * One message for everything that needs the user after startup, or only for `only`, servers\n\t\t * that connected later.\n\t\t */\n\t\tconst reportProblems = (ctx: ExtensionContext, only?: readonly McpServer[]) => {\n\t\t\tconst lines = only ? [] : configErrors.map((error) => `config: ${error}`);\n\t\t\tfor (const server of only ?? servers) {\n\t\t\t\tconst state = server.connection?.state;\n\t\t\t\tif (state === \"needs-auth\" || state === \"failed\")\n\t\t\t\t\tlines.push(`${server.entry.name}: ${describeState(server)}`);\n\t\t\t}\n\t\t\tif (lines.length === 0) return;\n\t\t\tctx.ui.notify(\n\t\t\t\t`MCP servers need attention:\\n${lines.map((line) => ` ${line}`).join(\"\\n\")}\\nRun /mcp to fix.`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t};\n\n\t\t/** Sign in, then reconnect. Returns an error message on failure. The session's end stops the sign-in. */\n\t\tconst signIn = async (server: McpServer, prompt: McpSignInPrompt): Promise<string | undefined> => {\n\t\t\tconst connection = server.connection;\n\t\t\tconst url = connection?.oauthUrl;\n\t\t\tif (!connection || !url) return `MCP server \"${server.entry.name}\" does not use OAuth.`;\n\t\t\tconst runtime = await loadMcpRuntime();\n\t\t\ttry {\n\t\t\t\tawait track(\n\t\t\t\t\truntime.signInMcpServer({\n\t\t\t\t\t\tserverUrl: url,\n\t\t\t\t\t\tstore: getCredentials(runtime).forServer(server.entry.name, url),\n\t\t\t\t\t\tsettings: connection.oauthSettings(),\n\t\t\t\t\t\tchallenge: connection.challenge,\n\t\t\t\t\t\tprompt,\n\t\t\t\t\t\tsignal: session.signal,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof runtime.McpSignInCancelledError) return \"Sign-in cancelled.\";\n\t\t\t\treturn `Sign-in failed: ${errorMessage(error)}`;\n\t\t\t}\n\t\t\t// The challenge that asked for this sign-in (for example for more scope) is answered.\n\t\t\tconnection.challenge = undefined;\n\t\t\ttry {\n\t\t\t\tawait connection.reconnect();\n\t\t\t} catch (error) {\n\t\t\t\treturn `Signed in, but ${errorMessage(error)}`;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t};\n\n\t\tconst signOut = async (server: McpServer): Promise<boolean> => {\n\t\t\tconst connection = server.connection;\n\t\t\tconst url = connection?.oauthUrl;\n\t\t\tif (!connection || !url) return false;\n\t\t\tconst removed = getCredentials(await loadMcpRuntime()).remove(server.entry.name, url);\n\t\t\tawait connection.signOut();\n\t\t\treturn removed;\n\t\t};\n\n\t\tconst reconnect = async (server: McpServer): Promise<string | undefined> => {\n\t\t\tconst connection = server.connection;\n\t\t\tif (!connection) return `MCP server \"${server.entry.name}\" is disabled.`;\n\t\t\tconst previous = server.ready;\n\t\t\tconst ready = (async () => {\n\t\t\t\tawait previous;\n\t\t\t\tawait connection.reconnect();\n\t\t\t})();\n\t\t\tserver.ready = ready.catch(() => undefined);\n\t\t\ttry {\n\t\t\t\tawait ready;\n\t\t\t\treturn undefined;\n\t\t\t} catch (error) {\n\t\t\t\treturn errorMessage(error);\n\t\t\t}\n\t\t};\n\n\t\t// ---------------------------------------------------------------------------------------\n\t\t// Subcommands and plain status (no TUI)\n\t\t// ---------------------------------------------------------------------------------------\n\n\t\tconst formatStatus = (): string => {\n\t\t\tif (servers.length === 0 && configErrors.length === 0 && overridden.length === 0) {\n\t\t\t\treturn `No MCP servers configured. Add them to ${resolve(getAgentDir(), \"mcp.json\")} or .pi/mcp.json.`;\n\t\t\t}\n\t\t\tconst lines = servers.map((server) => {\n\t\t\t\tconst { name } = server.entry;\n\t\t\t\tconst exposure = exposureOf(server.entry);\n\t\t\t\tconst connection = server.connection;\n\t\t\t\tif (connection?.state === \"needs-auth\")\n\t\t\t\t\treturn `${name}: needs sign-in, run /mcp login ${name} (${exposure})`;\n\t\t\t\tconst tools = connection?.state === \"connected\" ? `, ${connection.tools.length} tools` : \"\";\n\t\t\t\tconst state = !isEnabled(server)\n\t\t\t\t\t? \"disabled\"\n\t\t\t\t\t: connection?.state === \"disconnected\"\n\t\t\t\t\t\t? \"disconnected, reconnects on next call\"\n\t\t\t\t\t\t: (connection?.state ?? \"starting\");\n\t\t\t\tconst error =\n\t\t\t\t\tconnection?.error && connection.state !== \"connected\"\n\t\t\t\t\t\t? `\\n ${connection.error.split(\"\\n\").join(\"\\n \")}`\n\t\t\t\t\t\t: \"\";\n\t\t\t\treturn `${name}: ${state}${tools} (${exposure})${error}`;\n\t\t\t});\n\t\t\tfor (const error of configErrors) lines.push(`config error: ${error}`);\n\t\t\tfor (const line of overridden) lines.push(`overridden: ${line}`);\n\t\t\treturn lines.join(\"\\n\");\n\t\t};\n\n\t\t/** Resolve the server for a subcommand, asking when the name is omitted and ambiguous. */\n\t\tconst pickServer = async (\n\t\t\tname: string | undefined,\n\t\t\tctx: ExtensionCommandContext,\n\t\t\toptions: { eligible: (server: McpServer) => boolean; preferred: (server: McpServer) => boolean; none: string },\n\t\t): Promise<McpServer | undefined> => {\n\t\t\tif (name) {\n\t\t\t\tconst server = findServer(name);\n\t\t\t\tif (!server) ctx.ui.notify(`No MCP server named \"${name}\".`, \"error\");\n\t\t\t\telse if (!options.eligible(server)) ctx.ui.notify(options.none, \"error\");\n\t\t\t\treturn server && options.eligible(server) ? server : undefined;\n\t\t\t}\n\t\t\tconst candidates = servers.filter(options.eligible);\n\t\t\tif (candidates.length === 0) {\n\t\t\t\tctx.ui.notify(options.none, \"info\");\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tconst preferred = candidates.filter(options.preferred);\n\t\t\tif (candidates.length === 1) return candidates[0];\n\t\t\tif (preferred.length === 1) return preferred[0];\n\t\t\tconst choice = await ctx.ui.select(\n\t\t\t\t\"MCP server\",\n\t\t\t\tcandidates.map((server) => server.entry.name),\n\t\t\t);\n\t\t\treturn candidates.find((server) => server.entry.name === choice);\n\t\t};\n\n\t\tconst usesOAuth = (server: McpServer) => server.connection?.oauthUrl !== undefined;\n\t\tconst oauthPick = {\n\t\t\teligible: usesOAuth,\n\t\t\tpreferred: (server: McpServer) => server.connection?.state === \"needs-auth\",\n\t\t\tnone: \"No enabled MCP server uses OAuth. Only HTTP servers without an Authorization header do.\",\n\t\t};\n\n\t\tconst loginCommand = async (server: McpServer, ctx: ExtensionCommandContext) => {\n\t\t\tconst { name } = server.entry;\n\t\t\tif (!ctx.hasUI) {\n\t\t\t\tctx.ui.notify(`Signing in to MCP server \"${name}\" requires an interactive RPC client.`, \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst { signal } = session;\n\t\t\tconst failure = await signIn(server, {\n\t\t\t\tshowAuthorizationUrl: (url) => {\n\t\t\t\t\tctx.ui.notify(`Sign in to MCP server \"${name}\" in your browser:\\n${url.href}`, \"info\");\n\t\t\t\t\topenUrl(url.href);\n\t\t\t\t},\n\t\t\t\tpromptForRedirectUrl: (signal) =>\n\t\t\t\t\tctx.ui.input(\n\t\t\t\t\t\t`Waiting for sign-in to \"${name}\". If the browser cannot reach this machine, paste the URL it was redirected to.`,\n\t\t\t\t\t\t\"http://127.0.0.1:.../callback?code=...\",\n\t\t\t\t\t\t{ signal },\n\t\t\t\t\t),\n\t\t\t});\n\t\t\t// The session ended meanwhile, which cancelled the sign-in and made ctx stale.\n\t\t\tif (signal.aborted) return;\n\t\t\tif (failure) {\n\t\t\t\tctx.ui.notify(failure, failure === \"Sign-in cancelled.\" ? \"info\" : \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tensureDiscoveryActive(ctx);\n\t\t\tctx.ui.notify(`Signed in to MCP server \"${name}\" (${server.connection?.tools.length ?? 0} tools).`, \"info\");\n\t\t};\n\n\t\tpi.on(\"session_start\", (_event, ctx) => {\n\t\t\tconst loaded = (options.loadConfig ?? defaultLoadConfig)(ctx);\n\t\t\tconfigErrors = loaded.errors;\n\t\t\tautoEnableCodemode = loaded.autoEnableCodemode ?? true;\n\t\t\twarnedUnreachable = false;\n\t\t\twaitedForStartup = false;\n\t\t\tsessionCwd = ctx.cwd;\n\t\t\tmodelRegistry = ctx.modelRegistry;\n\t\t\tsession = new AbortController();\n\t\t\tconst { signal } = session;\n\t\t\tconfiguredEntries = loaded.servers;\n\t\t\tconst registered = registeredServers();\n\t\t\toverridden = registered.overridden;\n\t\t\tservers = [...loaded.servers.map((entry) => ({ entry })), ...registered.servers];\n\t\t\t// Codemode or tool_search is activated from the config: the first prompt does not wait for\n\t\t\t// servers whose tools are not declared to the model, and scripts or searches wait for them.\n\t\t\tensureDiscoveryActive(ctx);\n\t\t\tconst enabled = servers.filter(isEnabled);\n\t\t\tif (enabled.length === 0) {\n\t\t\t\treportProblems(ctx);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// The MCP client loads only now, so sessions without servers never pay for it. Waiting one\n\t\t\t// event loop turn lets the first render happen before loading and connecting.\n\t\t\tconst runtime = new Promise((resolve) => setImmediate(resolve)).then(() => loadMcpRuntime());\n\t\t\tpending = Promise.all(enabled.map((server) => startConnection(server, runtime)))\n\t\t\t\t.then(() => {\n\t\t\t\t\tif (!signal.aborted) reportProblems(ctx);\n\t\t\t\t})\n\t\t\t\t.catch((error: unknown) => {\n\t\t\t\t\t// The session may have been disposed meanwhile, which makes ctx stale.\n\t\t\t\t\ttry {\n\t\t\t\t\t\tctx.ui.notify(`MCP failed to load: ${errorMessage(error)}`, \"error\");\n\t\t\t\t\t} catch {}\n\t\t\t\t});\n\t\t});\n\n\t\t// The first prompt waits for servers whose tools are declared to the model, so they are declared\n\t\t// in its first request, but not indefinitely: a slow or hanging server must not hold up the\n\t\t// prompt. Other servers are waited for when a script or search needs them (below).\n\t\tconst waitForDirectServers = async (ctx: ExtensionContext) => {\n\t\t\tif (waitedForStartup) return;\n\t\t\twaitedForStartup = true;\n\t\t\tconst ready = servers.flatMap((server) =>\n\t\t\t\tisEnabled(server) && hasDirectTools(server.entry) && server.ready ? [server.ready] : [],\n\t\t\t);\n\t\t\tif (ready.length === 0) return;\n\t\t\tlet timer: NodeJS.Timeout | undefined;\n\t\t\tconst finished = await Promise.race([\n\t\t\t\tPromise.all(ready).then(() => true),\n\t\t\t\tnew Promise<boolean>((resolve) => {\n\t\t\t\t\ttimer = setTimeout(() => resolve(false), startupWaitMs);\n\t\t\t\t}),\n\t\t\t]);\n\t\t\tclearTimeout(timer);\n\t\t\tif (!finished) {\n\t\t\t\tctx.ui.notify(\"MCP servers are still connecting; their tools become available once connected.\", \"info\");\n\t\t\t}\n\t\t};\n\n\t\t// Every prompt lists the servers in the `mcp_servers` section as they are when it starts. Pi\n\t\t// appends the section to the conversation when it changed, for example after a server connected.\n\t\tpi.on(\"before_agent_start\", async (event, ctx) => {\n\t\t\tawait waitForDirectServers(ctx);\n\t\t\tconst { sections } = event.systemPromptOptions;\n\t\t\tconst section = renderServersSection(servers);\n\t\t\tif (section) sections[MCP_SERVERS_SECTION] = section;\n\t\t\telse delete sections[MCP_SERVERS_SECTION];\n\t\t});\n\n\t\t// A tool that reaches other tools (`reachesTools`) waits for the servers it may reach, so their\n\t\t// tools are registered before it runs: a codemode script for the servers it names, or for every\n\t\t// server when it searches or enumerates tools, and tool_search for every server. The resource\n\t\t// tools reach every server, so they wait for all of them. Direct MCP calls wait only for their\n\t\t// own server, including a reconnect still closing its old transport.\n\t\tpi.on(\"tool_call\", async (event, ctx) => {\n\t\t\tconst tool = pi.getAllTools().find((candidate) => candidate.name === event.toolName);\n\t\t\tif (!tool) return;\n\t\t\t// Readiness can be pending while the display state is still connected: reconnect first\n\t\t\t// closes the old transport, then opens a new one. Settled promises return immediately.\n\t\t\tconst readyServers = servers.filter((server) => isEnabled(server) && server.ready);\n\t\t\tif (readyServers.length === 0) return;\n\t\t\tlet waiting: McpServer[] = [];\n\t\t\tconst reach = tool.reachesTools?.(event.input);\n\t\t\tif (reach !== undefined) {\n\t\t\t\twaiting = readyServers.filter((server) => reachesServer(reach, server.entry.name));\n\t\t\t} else if (RESOURCE_TOOL_NAMES.has(tool.name)) {\n\t\t\t\twaiting = readyServers;\n\t\t\t} else {\n\t\t\t\tconst owner = toolOwners.get(event.toolName)?.split(\"\\0\", 1)[0];\n\t\t\t\twaiting = readyServers.filter((server) => server.entry.name === owner);\n\t\t\t}\n\t\t\tawait waitForServers(waiting, ctx.signal);\n\t\t});\n\n\t\t// Pick up sign-ins done outside the session, such as `pi mcp login` run by the agent.\n\t\tpi.on(\"turn_start\", async (_event, ctx) => {\n\t\t\tif (tokensAtSignIn.size > 0) await reconnectSignedIn(ctx);\n\t\t});\n\n\t\t// Servers registered or unregistered during the session connect or disconnect right away.\n\t\tpi.on(\"mcp_servers_change\", async (_event, ctx) => {\n\t\t\tconst { signal } = session;\n\t\t\tif (signal.aborted) return;\n\t\t\tconst registered = registeredServers();\n\t\t\toverridden = registered.overridden;\n\t\t\tconst next = new Map(registered.servers.map((server) => [server.entry.name, server]));\n\t\t\t// Unregistered servers and re-registered ones with a new config are dropped; the latter come back below.\n\t\t\tconst removed = servers.filter(\n\t\t\t\t(server) =>\n\t\t\t\t\tserver.entry.scope === \"extension\" &&\n\t\t\t\t\tnext.get(server.entry.name)?.registeredConfig !== server.registeredConfig,\n\t\t\t);\n\t\t\tservers = servers.filter((server) => !removed.includes(server));\n\t\t\tfor (const server of removed) hideTools(server.entry.name);\n\t\t\tconst added = registered.servers.filter((server) => !findServer(server.entry.name));\n\t\t\tservers.push(...added);\n\t\t\tensureDiscoveryActive(ctx);\n\t\t\tawait Promise.all(removed.map((server) => server.connection?.close()));\n\t\t\tconst connecting = added.filter(isEnabled);\n\t\t\tif (signal.aborted || connecting.length === 0) return;\n\t\t\ttry {\n\t\t\t\tawait Promise.all(connecting.map((server) => startConnection(server)));\n\t\t\t\tif (signal.aborted) {\n\t\t\t\t\tawait Promise.all(connecting.map((server) => server.connection?.close()));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tctx.ui.notify(`MCP failed to load: ${errorMessage(error)}`, \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (signal.aborted) return;\n\t\t\treportProblems(ctx, connecting);\n\t\t});\n\n\t\tpi.on(\"session_shutdown\", async () => {\n\t\t\tsession.abort();\n\t\t\tconst closing = connections();\n\t\t\tservers = [];\n\t\t\tawait Promise.all([...backgroundActions, ...closing.map((connection) => connection.close())]);\n\t\t});\n\n\t\tpi.registerCommand(\"mcp\", {\n\t\t\tdescription: \"Manage MCP servers: sign in, reconnect, enable or disable, and change exposure\",\n\t\t\tgetArgumentCompletions: (prefix) => {\n\t\t\t\tconst [action, server, ...rest] = prefix.trimStart().split(/\\s+/);\n\t\t\t\tif (rest.length > 0) return null;\n\t\t\t\tif (server === undefined) {\n\t\t\t\t\treturn [\"login\", \"logout\", \"reconnect\"]\n\t\t\t\t\t\t.filter((item) => item.startsWith(action ?? \"\"))\n\t\t\t\t\t\t.map((item) => ({ value: `${item} `, label: item }));\n\t\t\t\t}\n\t\t\t\tif (action !== \"login\" && action !== \"logout\" && action !== \"reconnect\") return null;\n\t\t\t\tconst items = servers\n\t\t\t\t\t.filter((candidate) =>\n\t\t\t\t\t\taction === \"reconnect\" ? candidate.connection !== undefined : usesOAuth(candidate),\n\t\t\t\t\t)\n\t\t\t\t\t.filter((candidate) => candidate.entry.name.startsWith(server))\n\t\t\t\t\t.map((candidate) => ({\n\t\t\t\t\t\tvalue: `${action} ${candidate.entry.name}`,\n\t\t\t\t\t\tlabel: candidate.entry.name,\n\t\t\t\t\t\tdescription: describeState(candidate),\n\t\t\t\t\t}));\n\t\t\t\treturn items.length > 0 ? items : null;\n\t\t\t},\n\t\t\thandler: async (args, ctx) => {\n\t\t\t\tconst [action, name, ...extra] = args.trim().split(/\\s+/).filter(Boolean);\n\t\t\t\tif (action === undefined) {\n\t\t\t\t\tawait pending;\n\t\t\t\t\tctx.ui.notify(formatStatus(), \"info\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (extra.length > 0) {\n\t\t\t\t\tctx.ui.notify(MCP_USAGE, \"warning\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tawait pending;\n\t\t\t\tswitch (action) {\n\t\t\t\t\tcase \"login\": {\n\t\t\t\t\t\tconst server = await pickServer(name, ctx, oauthPick);\n\t\t\t\t\t\tif (server) await loginCommand(server, ctx);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"logout\": {\n\t\t\t\t\t\tconst server = await pickServer(name, ctx, oauthPick);\n\t\t\t\t\t\tif (!server) return;\n\t\t\t\t\t\tconst removed = await signOut(server);\n\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\tremoved\n\t\t\t\t\t\t\t\t? `Signed out of MCP server \"${server.entry.name}\".`\n\t\t\t\t\t\t\t\t: `No stored credentials for MCP server \"${server.entry.name}\".`,\n\t\t\t\t\t\t\t\"info\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"reconnect\": {\n\t\t\t\t\t\tconst server = await pickServer(name, ctx, {\n\t\t\t\t\t\t\teligible: (candidate) => candidate.connection !== undefined,\n\t\t\t\t\t\t\tpreferred: (candidate) =>\n\t\t\t\t\t\t\t\tcandidate.connection?.state === \"failed\" || candidate.connection?.state === \"disconnected\",\n\t\t\t\t\t\t\tnone: \"No enabled MCP server to reconnect.\",\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (!server) return;\n\t\t\t\t\t\tconst failure = await reconnect(server);\n\t\t\t\t\t\tif (failure) ctx.ui.notify(failure, \"error\");\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tensureDiscoveryActive(ctx);\n\t\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\t\t`Reconnected to MCP server \"${server.entry.name}\" (${describeState(server)}).`,\n\t\t\t\t\t\t\t\t\"info\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tctx.ui.notify(MCP_USAGE, \"warning\");\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t};\n}\n\nfunction defaultLoadConfig(ctx: ExtensionContext): LoadedMcpConfig {\n\treturn loadMcpConfig({ agentDir: getAgentDir(), cwd: ctx.cwd, projectTrusted: ctx.isProjectTrusted() });\n}\n\nexport default createMcpExtension();\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAS9C,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EACN,kBAAkB,EAElB,aAAa,GAGb,MAAM,aAAa,CAAC;AAErB,OAAO,EACN,gCAAgC,EAChC,gCAAgC,EAChC,uBAAuB,EACvB,sBAAsB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD,OAAO,EAAE,uBAAuB,EAAuB,MAAM,YAAY,CAAC;AAuB1E,MAAM,uBAAuB,GAAG,MAAM,CAAC;AAEvC,MAAM,mBAAmB,GAAwB,IAAI,GAAG,CAAC;IACxD,uBAAuB;IACv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AAC;wBACD,OAAO;oBACR,CAAC;oBACD;wBACC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;gBACtC,CAAC;YACF,CAAC;SACD,CAAC,CAAC;IACJ,CAAC,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAqB;IAC/C,OAAO,aAAa,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE,GAAG,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;AACzG,CAAC;AAED,eAAe,kBAAkB,EAAE,CAAC","sourcesContent":["/**\n * Built-in MCP integration.\n *\n * Connects the servers from `mcp.json` and the servers extensions register with\n * `pi.registerMcpServer()` when a session starts, and servers registered later right away. A server\n * in `mcp.json` takes precedence over a registered server of the same name. Connections run in the\n * background: the first prompt waits only for servers with `direct` tools, and codemode scripts,\n * `tool_search`, and the resource tools wait for the servers they need when they run. Tools are\n * registered as `mcp__<server>__<tool>`. By default (`\"exposure\": \"codemode\"`) the tools are only\n * callable from codemode scripts, which keeps MCP tools out of the model's tool declarations and\n * the codemode description: scripts find the tools with `searchTools()` and the server instructions\n * with `describeNamespace()`. The codemode tool is activated for that unless `autoEnableCodemode` is\n * false. `\"deferred\"` declares the tools to the model once the `tool_search` tool loads them, and\n * activates `tool_search` instead of codemode.\n * `\"exposure\": \"direct\"` declares them to the model right away, and `\"hidden\"` makes them\n * unreachable. `toolExposure` overrides the exposure of single tools. Servers with resources are\n * reached through Codex's `list_mcp_resources`, `list_mcp_resource_templates`, and\n * `read_mcp_resource` tools (resources.ts).\n *\n * Every call runs through pi's tool pipeline, so `tool_call`/`tool_result` hooks and permission\n * extensions apply to MCP tools the same way they do to built-in tools.\n *\n * Problems found at startup (config errors, failed connections, servers that need a sign-in) are\n * reported once. `/mcp` shows status; its subcommands sign in, sign out, and reconnect servers.\n */\n\nimport { join, resolve } from \"node:path\";\nimport { createMcpToolName, mcpNamespace } from \"@punch-bot/mcp\";\nimport type { TSchema } from \"typebox\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type {\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n\tExtensionFactory,\n\tToolDefinition,\n} from \"../../core/extensions/types.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport { sliceHead } from \"../../core/tools/truncate.ts\";\nimport { openBrowser } from \"../../utils/open-browser.ts\";\nimport { CODEMODE_TOOL_NAME } from \"../codemode/tool.ts\";\nimport { TOOL_SEARCH_TOOL_NAME } from \"../tool-search/tool.ts\";\nimport {\n\tgetMcpToolExposure,\n\ttype LoadedMcpConfig,\n\tloadMcpConfig,\n\ttype McpExposure,\n\ttype McpServerEntry,\n} from \"./config.ts\";\nimport type { McpOAuthCredentialStore, McpSignInPrompt } from \"./oauth.ts\";\nimport {\n\tcreateMcpResourceToolDefinitions,\n\tLIST_MCP_RESOURCE_TEMPLATES_TOOL,\n\tLIST_MCP_RESOURCES_TOOL,\n\tREAD_MCP_RESOURCE_TOOL,\n} from \"./resources.ts\";\nimport { loadMcpRuntime } from \"./runtime.lazy.ts\";\nimport type * as McpRuntime from \"./runtime.ts\";\nimport type { McpServerConnection, McpServerLog, McpTransportFactory } from \"./runtime.ts\";\nimport { createMcpToolDefinition, type McpToolDetails } from \"./tools.ts\";\n\nexport type { McpTransportFactory } from \"./runtime.ts\";\n\nexport interface McpExtensionOptions {\n\t/** Defaults to reading `mcp.json` from the agent directory and the trusted project. */\n\tloadConfig?: (ctx: ExtensionContext) => LoadedMcpConfig;\n\t/** Defaults to stdio and streamable HTTP transports built from the server config. */\n\tcreateTransport?: McpTransportFactory;\n\t/** Defaults to `mcp-auth.json` in the agent directory. */\n\tcredentials?: McpOAuthCredentialStore;\n\t/** File server log messages are appended to. Defaults to `mcp.log` in the agent directory. */\n\tlogPath?: string;\n\t/** Opens the OAuth authorization URL. Defaults to the platform browser. */\n\topenUrl?: (url: string) => void;\n\t/**\n\t * How long the first prompt waits for servers with `direct` tools that are still connecting at\n\t * startup, in milliseconds. Their tools become available when they connect. Other servers are\n\t * waited for when a script or search needs them. Default: 10000.\n\t */\n\tstartupWaitMs?: number;\n}\n\nconst DEFAULT_STARTUP_WAIT_MS = 10_000;\n\nconst RESOURCE_TOOL_NAMES: ReadonlySet<string> = new Set([\n\tLIST_MCP_RESOURCES_TOOL,\n\tLIST_MCP_RESOURCE_TEMPLATES_TOOL,\n\tREAD_MCP_RESOURCE_TOOL,\n]);\n\n/** A configured server. Disabled servers have no connection. */\ninterface McpServer {\n\tentry: McpServerEntry;\n\tconnection?: McpServerConnection;\n\t/** For servers extensions registered: the config as registered, to detect re-registrations. */\n\tregisteredConfig?: string;\n\t/** Identifies the current connection attempt; disabling or replacing it invalidates earlier work. */\n\tattempt?: symbol;\n\t/** Settles when the connection started for the server connected or failed. */\n\tready?: Promise<void>;\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction firstLine(text: string): string {\n\treturn text.split(\"\\n\", 1)[0] ?? \"\";\n}\n\nfunction isEnabled(server: Pick<McpServer, \"entry\">): boolean {\n\treturn server.entry.config.enabled !== false;\n}\n\nfunction exposureOf(entry: McpServerEntry): McpExposure {\n\treturn entry.config.exposure ?? \"codemode\";\n}\n\n/** Exposures the server's tools can have, known from its config before it connects. */\nfunction configuredExposures(entry: McpServerEntry): Set<McpExposure> {\n\treturn new Set([exposureOf(entry), ...Object.values(entry.config.toolExposure ?? {})]);\n}\n\n/** Whether some of the server's tools are declared to the model, so the first prompt waits for them. */\nfunction hasDirectTools(entry: McpServerEntry): boolean {\n\treturn configuredExposures(entry).has(\"direct\");\n}\n\n/** Whether some of the server's tools are reached through codemode or tool_search. */\nfunction hasIndirectTools(entry: McpServerEntry): boolean {\n\tconst exposures = configuredExposures(entry);\n\treturn exposures.has(\"codemode\") || exposures.has(\"deferred\");\n}\n\n/** Name of the system prompt section that lists the servers whose tools are not declared. */\nexport const MCP_SERVERS_SECTION = \"mcp_servers\";\n/** Characters of a server description in the section, as Codex allows for deferred namespaces. */\nconst MAX_SERVER_DESCRIPTION_CHARS = 250;\n/**\n * Characters of the whole section. Descriptions shrink to fit; when the server lines alone do not\n * fit, the last servers are left out and counted in a closing line.\n */\nexport const MAX_SERVERS_SECTION_CHARS = 4096;\n\n/** The section's first line. It explains only the ways of reaching tools that the listed servers use. */\nfunction serversSectionIntro(reaches: ReadonlySet<string>): string {\n\tlet intro = \"MCP servers whose tools are not declared to you.\";\n\tif (reaches.has(\"codemode\")) intro += \" Call the tools of `codemode` servers from codemode scripts.\";\n\tif (reaches.has(\"tool_search\")) intro += \" Load the tools of `tool_search` servers with `tool_search`.\";\n\treturn intro;\n}\n\nfunction truncate(text: string, max: number): string {\n\tif (text.length <= max) return text;\n\treturn max <= 1 ? \"\" : `${sliceHead(text, max - 1).trimEnd()}…`;\n}\n\n/** What the `mcp_servers` section needs of a server. */\nexport interface McpServerListing {\n\tentry: McpServerEntry;\n\tconnection?: { instructions?: string };\n}\n\n/** First line of the configured description, or of the server instructions once connected. */\nfunction serverSummary(server: McpServerListing): string {\n\tconst text = server.entry.config.description?.trim() || server.connection?.instructions || \"\";\n\treturn (text.split(\"\\n\", 1)[0] ?? \"\").trim();\n}\n\n/**\n * The `mcp_servers` section: every enabled server with codemode or deferred tools, with how its\n * tools are reached and a one-line summary. The model learns of the servers from it, since neither\n * codemode nor tool_search lists them. Undefined when there are no such servers.\n */\nexport function renderServersSection(servers: readonly McpServerListing[]): string | undefined {\n\tconst listed = servers\n\t\t.filter((server) => isEnabled(server) && hasIndirectTools(server.entry))\n\t\t.sort((a, b) => a.entry.name.localeCompare(b.entry.name));\n\tif (listed.length === 0) return undefined;\n\tconst reaches = listed.map((server) =>\n\t\tconfiguredExposures(server.entry).has(\"codemode\") ? \"codemode\" : \"tool_search\",\n\t);\n\tconst intro = serversSectionIntro(new Set(reaches));\n\tconst heads = listed.map((server, index) => `- ${mcpNamespace(server.entry.name)} (${reaches[index]})`);\n\tconst omitted = (count: number) =>\n\t\tcount > 0 ? [`- … ${count} more server${count === 1 ? \"\" : \"s\"}; find their tools with searchTools()`] : [];\n\t// Characters of the intro, the first `kept` server lines without descriptions, and the omission line.\n\tconst size = (kept: number) => [intro, ...heads.slice(0, kept), ...omitted(listed.length - kept)].join(\"\\n\").length;\n\tlet kept = listed.length;\n\twhile (kept > 0 && size(kept) > MAX_SERVERS_SECTION_CHARS) kept--;\n\t// Each description also takes a \": \" separator.\n\tconst perServer =\n\t\tkept === 0\n\t\t\t? 0\n\t\t\t: Math.min(MAX_SERVER_DESCRIPTION_CHARS, Math.floor((MAX_SERVERS_SECTION_CHARS - size(kept)) / kept) - 2);\n\tconst lines = listed.slice(0, kept).map((server, index) => {\n\t\tconst summary = perServer > 0 ? truncate(serverSummary(server), perServer) : \"\";\n\t\treturn summary ? `${heads[index]}: ${summary}` : heads[index];\n\t});\n\treturn [intro, ...lines, ...omitted(listed.length - kept)].join(\"\\n\");\n}\n\n/**\n * Whether a call that reaches `reach` (see `ToolDefinition.reachesTools`) needs the server: it\n * reaches every tool, or one of its words contains the server's namespace.\n */\nfunction reachesServer(reach: \"all\" | readonly string[], server: string): boolean {\n\tif (reach === \"all\") return true;\n\tconst namespace = mcpNamespace(server);\n\treturn reach.some((word) => word.includes(namespace));\n}\n\n/** Short state for lists and the startup report. `withError` appends the first line of a failure. */\nfunction describeState(server: McpServer, withError = true): string {\n\tif (!isEnabled(server)) return \"disabled\";\n\tconst connection = server.connection;\n\tif (!connection) return \"starting\";\n\tswitch (connection.state) {\n\t\tcase \"needs-auth\":\n\t\t\treturn \"needs sign-in\";\n\t\tcase \"failed\":\n\t\t\treturn withError ? `failed: ${firstLine(connection.error ?? \"unknown error\")}` : \"failed\";\n\t\tcase \"connected\": {\n\t\t\tconst { tools, hasResources } = connection;\n\t\t\treturn `connected · ${tools.length} tool${tools.length === 1 ? \"\" : \"s\"}${hasResources ? \" · resources\" : \"\"}`;\n\t\t}\n\t\tcase \"connecting\":\n\t\t\treturn \"connecting…\";\n\t\tdefault:\n\t\t\treturn connection.state;\n\t}\n}\n\nconst MCP_USAGE = \"Usage: /mcp, /mcp login [server], /mcp logout [server], /mcp reconnect [server]\";\n\nexport function createMcpExtension(options: McpExtensionOptions = {}): ExtensionFactory {\n\treturn (pi: ExtensionAPI) => {\n\t\tlet servers: McpServer[] = [];\n\t\t/** Servers from `mcp.json`, which take precedence over registered servers of the same name. */\n\t\tlet configuredEntries: McpServerEntry[] = [];\n\t\tlet configErrors: string[] = [];\n\t\t/** Registered servers that `mcp.json` overrides, shown in `/mcp`. */\n\t\tlet overridden: string[] = [];\n\t\tlet autoEnableCodemode = true;\n\t\t/** Whether the \"codemode tools unreachable\" warning was shown since the session started. */\n\t\tlet warnedUnreachable = false;\n\t\tlet pending: Promise<unknown> | undefined;\n\t\t/** Whether a prompt already waited for the startup connections since the session started. */\n\t\tlet waitedForStartup = false;\n\t\tconst startupWaitMs = options.startupWaitMs ?? DEFAULT_STARTUP_WAIT_MS;\n\t\t/** Working directory of the session, for stdio servers. */\n\t\tlet sessionCwd = process.cwd();\n\t\tlet credentials = options.credentials;\n\t\t/** The session's model registry, which resolves `auth.provider` tokens. */\n\t\tlet modelRegistry: ModelRegistry | undefined;\n\t\tlet serverLog: McpServerLog | undefined;\n\t\tconst openUrl = options.openUrl ?? openBrowser;\n\n\t\t/**\n\t\t * Lifetime of the current session: aborted on session_shutdown, and before the first session_start\n\t\t * (registrations before that are read on session_start). Work captures `session.signal` when it\n\t\t * starts and drops late results once it aborted, for example a runtime load that resolves after\n\t\t * shutdown. Work that outlives the command that started it also stops on the signal and is\n\t\t * registered with `track`, so shutdown can wait for its cleanup.\n\t\t */\n\t\tlet session = new AbortController();\n\t\tsession.abort();\n\t\t/** Work registered with `track`: sign-ins, which shutdown waits for. */\n\t\tconst backgroundActions = new Set<Promise<void>>();\n\t\tconst track = <T>(work: Promise<T>): Promise<T> => {\n\t\t\tconst task = work.then(\n\t\t\t\t() => undefined,\n\t\t\t\t() => undefined,\n\t\t\t);\n\t\t\tbackgroundActions.add(task);\n\t\t\tvoid task.finally(() => backgroundActions.delete(task));\n\t\t\treturn work;\n\t\t};\n\n\t\tconst connections = () => servers.flatMap((server) => (server.connection ? [server.connection] : []));\n\t\tconst findServer = (name: string) => servers.find((server) => server.entry.name === name);\n\n\t\t/** Servers extensions registered, except names `mcp.json` defines, which take precedence. */\n\t\tconst registeredServers = (): { servers: McpServer[]; overridden: string[] } => {\n\t\t\tconst registered: McpServer[] = [];\n\t\t\tconst overriddenNames: string[] = [];\n\t\t\tfor (const { name, config, extensionPath } of pi.getMcpServers()) {\n\t\t\t\tconst configured = configuredEntries.find((entry) => mcpNamespace(entry.name) === mcpNamespace(name));\n\t\t\t\tif (configured) {\n\t\t\t\t\toverriddenNames.push(\n\t\t\t\t\t\t`\"${name}\" registered by ${extensionPath} is overridden by \"${configured.name}\" in ${configured.source}`,\n\t\t\t\t\t);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tregistered.push({\n\t\t\t\t\tentry: { name, config, source: extensionPath, scope: \"extension\" },\n\t\t\t\t\tregisteredConfig: JSON.stringify(config),\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn { servers: registered, overridden: overriddenNames };\n\t\t};\n\n\t\tconst getCredentials = (runtime: typeof McpRuntime): McpOAuthCredentialStore => {\n\t\t\tcredentials ??= new runtime.McpOAuthCredentialStore();\n\t\t\treturn credentials;\n\t\t};\n\n\t\tconst getServerLog = (runtime: typeof McpRuntime): McpServerLog => {\n\t\t\tserverLog ??= new runtime.McpServerLog(options.logPath ?? join(getAgentDir(), \"mcp.log\"));\n\t\t\treturn serverLog;\n\t\t};\n\n\t\t/** pi tool name to the `<server>\\0<tool>` it was assigned to, so names stay unique and stable. */\n\t\tconst toolOwners = new Map<string, string>();\n\t\t/** Tool names currently offered by each server. */\n\t\tconst serverTools = new Map<string, Set<string>>();\n\t\t/** Last definition registered under each tool name, to re-register withdrawn tools as hidden. */\n\t\tconst definitions = new Map<string, ToolDefinition<TSchema, McpToolDetails>>();\n\n\t\tconst registerTools = (connection: McpServerConnection) => {\n\t\t\tconst server = connection.entry.name;\n\t\t\tconst entry = findServer(server)?.entry ?? connection.entry;\n\t\t\tconst description = entry.config.description?.trim();\n\t\t\tconst namespace = {\n\t\t\t\tname: mcpNamespace(server),\n\t\t\t\t// `describeNamespace(\"docs\")` finds `mcp__docs`.\n\t\t\t\taliases: [server],\n\t\t\t\t...(description ? { description } : {}),\n\t\t\t\t...(connection.instructions ? { instructions: connection.instructions } : {}),\n\t\t\t};\n\t\t\tconst previous = serverTools.get(server) ?? new Set<string>();\n\t\t\tconst current = new Set<string>();\n\t\t\t// Like Codex, all tools whose names sanitize to the same name get the hash suffix, so which\n\t\t\t// one would keep the plain name does not depend on the order of the list.\n\t\t\tconst plain = [...new Set(connection.tools.map((tool) => tool.name))].map((tool) =>\n\t\t\t\tcreateMcpToolName(server, tool),\n\t\t\t);\n\t\t\tconst assignName = (tool: string, owner: string) => {\n\t\t\t\tconst name = createMcpToolName(server, tool, (candidate) => {\n\t\t\t\t\tconst existing = toolOwners.get(candidate);\n\t\t\t\t\treturn (\n\t\t\t\t\t\t(existing !== undefined && existing !== owner) ||\n\t\t\t\t\t\tcurrent.has(candidate) ||\n\t\t\t\t\t\tplain.indexOf(candidate) !== plain.lastIndexOf(candidate)\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t\ttoolOwners.set(name, owner);\n\t\t\t\tcurrent.add(name);\n\t\t\t\treturn name;\n\t\t\t};\n\t\t\tfor (const tool of connection.tools) {\n\t\t\t\tconst definition = createMcpToolDefinition({\n\t\t\t\t\tserver,\n\t\t\t\t\ttool,\n\t\t\t\t\tname: assignName(tool.name, `${server}\\0${tool.name}`),\n\t\t\t\t\texposure: getMcpToolExposure(entry.config, tool.name),\n\t\t\t\t\tnamespace,\n\t\t\t\t\ttimeoutMs: connection.timeoutMs,\n\t\t\t\t\tgetClient: async () => {\n\t\t\t\t\t\t// A prepared call can outlive this definition's connection while the readiness\n\t\t\t\t\t\t// hook waits for a disable/re-enable. Resolve the replacement at execution time.\n\t\t\t\t\t\tconst current = findServer(server);\n\t\t\t\t\t\tif (!current || !isEnabled(current)) throw new Error(`MCP server \"${server}\" is disabled.`);\n\t\t\t\t\t\tconst client = current.connection;\n\t\t\t\t\t\tif (!client) throw new Error(`MCP server \"${server}\" is still starting.`);\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tgetMcpToolExposure(current.entry.config, tool.name) === \"hidden\" ||\n\t\t\t\t\t\t\t(client.state === \"connected\" && !client.tools.some((offered) => offered.name === tool.name))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthrow new Error(`MCP tool \"${server}/${tool.name}\" is no longer available.`);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn client;\n\t\t\t\t\t},\n\t\t\t\t\treadableResources: () => resourceServers().some((current) => current.name === server),\n\t\t\t\t});\n\t\t\t\tdefinitions.set(definition.name, definition);\n\t\t\t\tpi.registerTool(definition);\n\t\t\t}\n\t\t\tserverTools.set(server, current);\n\t\t\t// Tools cannot be unregistered, so tools the server dropped are re-registered as hidden. When\n\t\t\t// the server offers them again they are registered with their configured exposure above.\n\t\t\tfor (const name of previous) {\n\t\t\t\tconst definition = definitions.get(name);\n\t\t\t\tif (!current.has(name) && definition) pi.registerTool({ ...definition, exposure: \"hidden\" });\n\t\t\t}\n\t\t\tsyncResourceTools();\n\t\t};\n\n\t\t/** Make a disabled server's tools unreachable. */\n\t\tconst hideTools = (server: string) => {\n\t\t\tfor (const name of serverTools.get(server) ?? []) {\n\t\t\t\tconst definition = definitions.get(name);\n\t\t\t\tif (definition) pi.registerTool({ ...definition, exposure: \"hidden\" });\n\t\t\t}\n\t\t\tserverTools.set(server, new Set());\n\t\t\tsyncResourceTools();\n\t\t};\n\n\t\t/** Enabled servers with resources whose exposure is not `hidden`, which the resource tools reach. */\n\t\tconst serversWithResources = (): McpServer[] =>\n\t\t\tservers.filter(\n\t\t\t\t(server) => server.connection?.hasResources && isEnabled(server) && exposureOf(server.entry) !== \"hidden\",\n\t\t\t);\n\t\tconst resourceServers = (): McpServerConnection[] =>\n\t\t\tserversWithResources().flatMap((server) => (server.connection ? [server.connection] : []));\n\n\t\t/** Exposure the resource tools were last registered with; undefined until a server has resources. */\n\t\tlet resourceToolsExposure: McpExposure | undefined;\n\t\t/**\n\t\t * Register the resource tools with the widest exposure of the servers they reach: `direct` when\n\t\t * one of them is direct, and so on. They are hidden when no server has resources.\n\t\t */\n\t\tconst syncResourceTools = () => {\n\t\t\tconst exposures = new Set(serversWithResources().map((server) => exposureOf(server.entry)));\n\t\t\tconst exposure = ([\"direct\", \"codemode\", \"deferred\"] as const).find((candidate) => exposures.has(candidate));\n\t\t\tconst next = exposure ?? \"hidden\";\n\t\t\tif (next === resourceToolsExposure || (resourceToolsExposure === undefined && next === \"hidden\")) return;\n\t\t\tconst wasDirect = resourceToolsExposure === \"direct\";\n\t\t\tresourceToolsExposure = next;\n\t\t\tconst resourceDefinitions = createMcpResourceToolDefinitions({ exposure: next, servers: resourceServers });\n\t\t\tfor (const definition of resourceDefinitions) pi.registerTool(definition);\n\t\t\tif (wasDirect) {\n\t\t\t\tconst names = new Set(resourceDefinitions.map((definition) => definition.name));\n\t\t\t\tpi.setActiveTools(pi.getActiveTools().filter((name) => !names.has(name)));\n\t\t\t}\n\t\t};\n\n\t\t/**\n\t\t * Tools that are not declared to the model are reached through the codemode tool (scripts call\n\t\t * them) or the tool_search tool (it declares them). Either reaches every such tool. Activate the\n\t\t * one the tools' exposure asks for: codemode for `codemode` unless `autoEnableCodemode` is false,\n\t\t * tool_search for `deferred`.\n\t\t */\n\t\tconst ensureDiscoveryActive = (ctx: ExtensionContext) => {\n\t\t\t// From the config, so the tool is active before the servers connect. Resource tools share\n\t\t\t// their server's exposure.\n\t\t\tconst exposures = new Set<McpExposure>();\n\t\t\tfor (const server of servers) {\n\t\t\t\tif (isEnabled(server)) for (const exposure of configuredExposures(server.entry)) exposures.add(exposure);\n\t\t\t}\n\t\t\tconst needsCodemode = exposures.has(\"codemode\");\n\t\t\tconst needsToolSearch = exposures.has(\"deferred\");\n\t\t\tif (!needsCodemode && !needsToolSearch) return;\n\t\t\t// Only a tool of these names that declares `reachesTools` can reach MCP tools; another\n\t\t\t// extension's tool of the same name without it is never activated.\n\t\t\tconst tools = pi.getAllTools();\n\t\t\tconst hasReachingTool = (name: string) => tools.some((tool) => tool.name === name && tool.reachesTools);\n\t\t\tconst hasCodemode = hasReachingTool(CODEMODE_TOOL_NAME);\n\t\t\tconst hasToolSearch = hasReachingTool(TOOL_SEARCH_TOOL_NAME);\n\t\t\tconst active = pi.getActiveTools();\n\t\t\tconst activate: string[] = [];\n\t\t\tif (needsCodemode && hasCodemode && autoEnableCodemode && !active.includes(CODEMODE_TOOL_NAME)) {\n\t\t\t\tactivate.push(CODEMODE_TOOL_NAME);\n\t\t\t}\n\t\t\tif (needsToolSearch && hasToolSearch && !active.includes(TOOL_SEARCH_TOOL_NAME)) {\n\t\t\t\tactivate.push(TOOL_SEARCH_TOOL_NAME);\n\t\t\t}\n\t\t\tif (activate.length > 0) pi.setActiveTools([...active, ...activate]);\n\t\t\tconst reachable = [...active, ...activate];\n\t\t\tif (hasCodemode && reachable.includes(CODEMODE_TOOL_NAME)) return;\n\t\t\tif (hasToolSearch && reachable.includes(TOOL_SEARCH_TOOL_NAME)) return;\n\t\t\tif (warnedUnreachable) return;\n\t\t\twarnedUnreachable = true;\n\t\t\tconst reason = needsCodemode && hasCodemode && !autoEnableCodemode ? \" (autoEnableCodemode is false)\" : \"\";\n\t\t\tctx.ui.notify(\n\t\t\t\t`MCP tools are only reachable from the codemode or tool_search tool, but neither is active${reason}; they cannot be called.`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t};\n\n\t\t/**\n\t\t * Stored tokens of servers waiting for a sign-in, as they were when the sign-in was needed.\n\t\t * `pi mcp login` in another process (for example run by the agent) changes them.\n\t\t */\n\t\tconst tokensAtSignIn = new Map<McpServerConnection, string>();\n\t\tconst storedTokens = (connection: McpServerConnection): string => {\n\t\t\tconst url = connection.oauthUrl;\n\t\t\treturn url && credentials ? JSON.stringify(credentials.tokens(connection.name, url) ?? null) : \"null\";\n\t\t};\n\t\tconst onConnectionChange = (connection: McpServerConnection) => {\n\t\t\tif (connection.state !== \"needs-auth\") tokensAtSignIn.delete(connection);\n\t\t\telse if (!tokensAtSignIn.has(connection)) tokensAtSignIn.set(connection, storedTokens(connection));\n\t\t};\n\t\t/** Reconnect servers that need a sign-in when their credentials were stored since. */\n\t\tconst reconnectSignedIn = async (ctx: ExtensionContext) => {\n\t\t\tconst signedIn = [...tokensAtSignIn].filter(([connection, tokens]) => storedTokens(connection) !== tokens);\n\t\t\tif (signedIn.length === 0) return;\n\t\t\tfor (const [connection] of signedIn) tokensAtSignIn.delete(connection);\n\t\t\tawait Promise.allSettled(signedIn.map(([connection]) => connection.reconnect()));\n\t\t\tensureDiscoveryActive(ctx);\n\t\t};\n\n\t\t/** Create the server's connection, loading the MCP runtime on first use. */\n\t\tconst createConnection = async (\n\t\t\tserver: McpServer,\n\t\t\tisCurrent: () => boolean,\n\t\t): Promise<McpServerConnection | undefined> => {\n\t\t\tconst runtime = await loadMcpRuntime();\n\t\t\tif (!isCurrent()) return undefined;\n\t\t\tconst connection = new runtime.McpServerConnection({\n\t\t\t\tentry: server.entry,\n\t\t\t\tcwd: sessionCwd,\n\t\t\t\tcreateTransport: options.createTransport ?? runtime.createDefaultTransport,\n\t\t\t\tcredentials: getCredentials(runtime),\n\t\t\t\tproviderToken: async (provider) => modelRegistry?.getApiKeyForProvider(provider),\n\t\t\t\tlog: getServerLog(runtime),\n\t\t\t\tonTools: (connection) => {\n\t\t\t\t\tif (isCurrent()) registerTools(connection);\n\t\t\t\t},\n\t\t\t\tonChange: (connection) => {\n\t\t\t\t\tif (isCurrent()) onConnectionChange(connection);\n\t\t\t\t\telse tokensAtSignIn.delete(connection);\n\t\t\t\t},\n\t\t\t});\n\t\t\tserver.connection = connection;\n\t\t\treturn connection;\n\t\t};\n\n\t\t/**\n\t\t * Connect the server in the background. `server.ready` settles when it connected or failed;\n\t\t * failures show in its state. It starts after `after`, unless disabled, replaced, or shut down\n\t\t * meanwhile. The returned promise rejects when the MCP runtime cannot be loaded.\n\t\t */\n\t\tconst startConnection = (server: McpServer, after?: Promise<unknown>): Promise<void> => {\n\t\t\tconst { signal } = session;\n\t\t\tconst attempt = Symbol();\n\t\t\tserver.attempt = attempt;\n\t\t\tconst isCurrent = () =>\n\t\t\t\t!signal.aborted && server.attempt === attempt && isEnabled(server) && servers.includes(server);\n\t\t\tconst ready = (async () => {\n\t\t\t\tawait after;\n\t\t\t\tif (!isCurrent()) return;\n\t\t\t\tconst connection = await createConnection(server, isCurrent);\n\t\t\t\tif (!connection || !isCurrent()) return;\n\t\t\t\tawait connection.getClient().catch(() => undefined);\n\t\t\t})();\n\t\t\tserver.ready = ready.catch(() => undefined);\n\t\t\treturn ready;\n\t\t};\n\n\t\t/** Wait for the latest connection attempts, including ones queued while waiting, or an abort. */\n\t\tconst waitForServers = async (waiting: readonly McpServer[], signal: AbortSignal | undefined) => {\n\t\t\tfor (;;) {\n\t\t\t\tconst ready = waiting.flatMap((server) =>\n\t\t\t\t\tisEnabled(server) && servers.includes(server) && server.ready ? [{ server, ready: server.ready }] : [],\n\t\t\t\t);\n\t\t\t\tif (ready.length === 0 || signal?.aborted) return;\n\t\t\t\tlet onAbort: (() => void) | undefined;\n\t\t\t\tawait Promise.race([\n\t\t\t\t\tPromise.all(ready.map((attempt) => attempt.ready)),\n\t\t\t\t\tnew Promise<void>((resolve) => {\n\t\t\t\t\t\tonAbort = () => resolve();\n\t\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t\t}),\n\t\t\t\t]);\n\t\t\t\tif (onAbort) signal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\tif (\n\t\t\t\t\tsignal?.aborted ||\n\t\t\t\t\tready.every(\n\t\t\t\t\t\t(attempt) =>\n\t\t\t\t\t\t\t!isEnabled(attempt.server) ||\n\t\t\t\t\t\t\t!servers.includes(attempt.server) ||\n\t\t\t\t\t\t\tattempt.ready === attempt.server.ready,\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\treturn;\n\t\t\t}\n\t\t};\n\n\t\t/**\n\t\t * One message for everything that needs the user after startup, or only for `only`, servers\n\t\t * that connected later.\n\t\t */\n\t\tconst reportProblems = (ctx: ExtensionContext, only?: readonly McpServer[]) => {\n\t\t\tconst lines = only ? [] : configErrors.map((error) => `config: ${error}`);\n\t\t\tfor (const server of only ?? servers) {\n\t\t\t\tconst state = server.connection?.state;\n\t\t\t\tif (state === \"needs-auth\" || state === \"failed\")\n\t\t\t\t\tlines.push(`${server.entry.name}: ${describeState(server)}`);\n\t\t\t}\n\t\t\tif (lines.length === 0) return;\n\t\t\tctx.ui.notify(\n\t\t\t\t`MCP servers need attention:\\n${lines.map((line) => ` ${line}`).join(\"\\n\")}\\nRun /mcp to fix.`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t};\n\n\t\t/** Sign in, then reconnect. Returns an error message on failure. The session's end stops the sign-in. */\n\t\tconst signIn = async (server: McpServer, prompt: McpSignInPrompt): Promise<string | undefined> => {\n\t\t\tconst connection = server.connection;\n\t\t\tconst url = connection?.oauthUrl;\n\t\t\tif (!connection || !url) return `MCP server \"${server.entry.name}\" does not use OAuth.`;\n\t\t\tconst runtime = await loadMcpRuntime();\n\t\t\ttry {\n\t\t\t\tawait track(\n\t\t\t\t\truntime.signInMcpServer({\n\t\t\t\t\t\tserverUrl: url,\n\t\t\t\t\t\tstore: getCredentials(runtime).forServer(server.entry.name, url),\n\t\t\t\t\t\tsettings: connection.oauthSettings(),\n\t\t\t\t\t\tchallenge: connection.challenge,\n\t\t\t\t\t\tprompt,\n\t\t\t\t\t\tsignal: session.signal,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof runtime.McpSignInCancelledError) return \"Sign-in cancelled.\";\n\t\t\t\treturn `Sign-in failed: ${errorMessage(error)}`;\n\t\t\t}\n\t\t\t// The challenge that asked for this sign-in (for example for more scope) is answered.\n\t\t\tconnection.challenge = undefined;\n\t\t\ttry {\n\t\t\t\tawait connection.reconnect();\n\t\t\t} catch (error) {\n\t\t\t\treturn `Signed in, but ${errorMessage(error)}`;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t};\n\n\t\tconst signOut = async (server: McpServer): Promise<boolean> => {\n\t\t\tconst connection = server.connection;\n\t\t\tconst url = connection?.oauthUrl;\n\t\t\tif (!connection || !url) return false;\n\t\t\tconst removed = getCredentials(await loadMcpRuntime()).remove(server.entry.name, url);\n\t\t\tawait connection.signOut();\n\t\t\treturn removed;\n\t\t};\n\n\t\tconst reconnect = async (server: McpServer): Promise<string | undefined> => {\n\t\t\tconst connection = server.connection;\n\t\t\tif (!connection) return `MCP server \"${server.entry.name}\" is disabled.`;\n\t\t\tconst previous = server.ready;\n\t\t\tconst ready = (async () => {\n\t\t\t\tawait previous;\n\t\t\t\tawait connection.reconnect();\n\t\t\t})();\n\t\t\tserver.ready = ready.catch(() => undefined);\n\t\t\ttry {\n\t\t\t\tawait ready;\n\t\t\t\treturn undefined;\n\t\t\t} catch (error) {\n\t\t\t\treturn errorMessage(error);\n\t\t\t}\n\t\t};\n\n\t\t// ---------------------------------------------------------------------------------------\n\t\t// Subcommands and plain status (no TUI)\n\t\t// ---------------------------------------------------------------------------------------\n\n\t\tconst formatStatus = (): string => {\n\t\t\tif (servers.length === 0 && configErrors.length === 0 && overridden.length === 0) {\n\t\t\t\treturn `No MCP servers configured. Add them to ${resolve(getAgentDir(), \"mcp.json\")} or .pi/mcp.json.`;\n\t\t\t}\n\t\t\tconst lines = servers.map((server) => {\n\t\t\t\tconst { name } = server.entry;\n\t\t\t\tconst exposure = exposureOf(server.entry);\n\t\t\t\tconst connection = server.connection;\n\t\t\t\tif (connection?.state === \"needs-auth\")\n\t\t\t\t\treturn `${name}: needs sign-in, run /mcp login ${name} (${exposure})`;\n\t\t\t\tconst tools = connection?.state === \"connected\" ? `, ${connection.tools.length} tools` : \"\";\n\t\t\t\tconst state = !isEnabled(server)\n\t\t\t\t\t? \"disabled\"\n\t\t\t\t\t: connection?.state === \"disconnected\"\n\t\t\t\t\t\t? \"disconnected, reconnects on next call\"\n\t\t\t\t\t\t: (connection?.state ?? \"starting\");\n\t\t\t\tconst error =\n\t\t\t\t\tconnection?.error && connection.state !== \"connected\"\n\t\t\t\t\t\t? `\\n ${connection.error.split(\"\\n\").join(\"\\n \")}`\n\t\t\t\t\t\t: \"\";\n\t\t\t\treturn `${name}: ${state}${tools} (${exposure})${error}`;\n\t\t\t});\n\t\t\tfor (const error of configErrors) lines.push(`config error: ${error}`);\n\t\t\tfor (const line of overridden) lines.push(`overridden: ${line}`);\n\t\t\treturn lines.join(\"\\n\");\n\t\t};\n\n\t\t/** Resolve the server for a subcommand, asking when the name is omitted and ambiguous. */\n\t\tconst pickServer = async (\n\t\t\tname: string | undefined,\n\t\t\tctx: ExtensionCommandContext,\n\t\t\toptions: { eligible: (server: McpServer) => boolean; preferred: (server: McpServer) => boolean; none: string },\n\t\t): Promise<McpServer | undefined> => {\n\t\t\tif (name) {\n\t\t\t\tconst server = findServer(name);\n\t\t\t\tif (!server) ctx.ui.notify(`No MCP server named \"${name}\".`, \"error\");\n\t\t\t\telse if (!options.eligible(server)) ctx.ui.notify(options.none, \"error\");\n\t\t\t\treturn server && options.eligible(server) ? server : undefined;\n\t\t\t}\n\t\t\tconst candidates = servers.filter(options.eligible);\n\t\t\tif (candidates.length === 0) {\n\t\t\t\tctx.ui.notify(options.none, \"info\");\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tconst preferred = candidates.filter(options.preferred);\n\t\t\tif (candidates.length === 1) return candidates[0];\n\t\t\tif (preferred.length === 1) return preferred[0];\n\t\t\tconst choice = await ctx.ui.select(\n\t\t\t\t\"MCP server\",\n\t\t\t\tcandidates.map((server) => server.entry.name),\n\t\t\t);\n\t\t\treturn candidates.find((server) => server.entry.name === choice);\n\t\t};\n\n\t\tconst usesOAuth = (server: McpServer) => server.connection?.oauthUrl !== undefined;\n\t\tconst oauthPick = {\n\t\t\teligible: usesOAuth,\n\t\t\tpreferred: (server: McpServer) => server.connection?.state === \"needs-auth\",\n\t\t\tnone: \"No enabled MCP server uses OAuth. Only HTTP servers without an Authorization header do.\",\n\t\t};\n\n\t\tconst loginCommand = async (server: McpServer, ctx: ExtensionCommandContext) => {\n\t\t\tconst { name } = server.entry;\n\t\t\tif (!ctx.hasUI) {\n\t\t\t\tctx.ui.notify(`Signing in to MCP server \"${name}\" requires an interactive RPC client.`, \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst { signal } = session;\n\t\t\tconst failure = await signIn(server, {\n\t\t\t\tshowAuthorizationUrl: (url) => {\n\t\t\t\t\tctx.ui.notify(`Sign in to MCP server \"${name}\" in your browser:\\n${url.href}`, \"info\");\n\t\t\t\t\topenUrl(url.href);\n\t\t\t\t},\n\t\t\t\tpromptForRedirectUrl: (signal) =>\n\t\t\t\t\tctx.ui.input(\n\t\t\t\t\t\t`Waiting for sign-in to \"${name}\". If the browser cannot reach this machine, paste the URL it was redirected to.`,\n\t\t\t\t\t\t\"http://127.0.0.1:.../callback?code=...\",\n\t\t\t\t\t\t{ signal },\n\t\t\t\t\t),\n\t\t\t});\n\t\t\t// The session ended meanwhile, which cancelled the sign-in and made ctx stale.\n\t\t\tif (signal.aborted) return;\n\t\t\tif (failure) {\n\t\t\t\tctx.ui.notify(failure, failure === \"Sign-in cancelled.\" ? \"info\" : \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tensureDiscoveryActive(ctx);\n\t\t\tctx.ui.notify(`Signed in to MCP server \"${name}\" (${server.connection?.tools.length ?? 0} tools).`, \"info\");\n\t\t};\n\n\t\tpi.on(\"session_start\", (_event, ctx) => {\n\t\t\tconst loaded = (options.loadConfig ?? defaultLoadConfig)(ctx);\n\t\t\tconfigErrors = loaded.errors;\n\t\t\tautoEnableCodemode = loaded.autoEnableCodemode ?? true;\n\t\t\twarnedUnreachable = false;\n\t\t\twaitedForStartup = false;\n\t\t\tsessionCwd = ctx.cwd;\n\t\t\tmodelRegistry = ctx.modelRegistry;\n\t\t\tsession = new AbortController();\n\t\t\tconst { signal } = session;\n\t\t\tconfiguredEntries = loaded.servers;\n\t\t\tconst registered = registeredServers();\n\t\t\toverridden = registered.overridden;\n\t\t\tservers = [...loaded.servers.map((entry) => ({ entry })), ...registered.servers];\n\t\t\t// Codemode or tool_search is activated from the config: the first prompt does not wait for\n\t\t\t// servers whose tools are not declared to the model, and scripts or searches wait for them.\n\t\t\tensureDiscoveryActive(ctx);\n\t\t\tconst enabled = servers.filter(isEnabled);\n\t\t\tif (enabled.length === 0) {\n\t\t\t\treportProblems(ctx);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// The MCP client loads only now, so sessions without servers never pay for it. Waiting one\n\t\t\t// event loop turn lets the first render happen before loading and connecting.\n\t\t\tconst runtime = new Promise((resolve) => setImmediate(resolve)).then(() => loadMcpRuntime());\n\t\t\tpending = Promise.all(enabled.map((server) => startConnection(server, runtime)))\n\t\t\t\t.then(() => {\n\t\t\t\t\tif (!signal.aborted) reportProblems(ctx);\n\t\t\t\t})\n\t\t\t\t.catch((error: unknown) => {\n\t\t\t\t\t// The session may have been disposed meanwhile, which makes ctx stale.\n\t\t\t\t\ttry {\n\t\t\t\t\t\tctx.ui.notify(`MCP failed to load: ${errorMessage(error)}`, \"error\");\n\t\t\t\t\t} catch {}\n\t\t\t\t});\n\t\t});\n\n\t\t// The first prompt waits for servers whose tools are declared to the model, so they are declared\n\t\t// in its first request, but not indefinitely: a slow or hanging server must not hold up the\n\t\t// prompt. Other servers are waited for when a script or search needs them (below).\n\t\tconst waitForDirectServers = async (ctx: ExtensionContext) => {\n\t\t\tif (waitedForStartup) return;\n\t\t\twaitedForStartup = true;\n\t\t\tconst ready = servers.flatMap((server) =>\n\t\t\t\tisEnabled(server) && hasDirectTools(server.entry) && server.ready ? [server.ready] : [],\n\t\t\t);\n\t\t\tif (ready.length === 0) return;\n\t\t\tlet timer: NodeJS.Timeout | undefined;\n\t\t\tconst finished = await Promise.race([\n\t\t\t\tPromise.all(ready).then(() => true),\n\t\t\t\tnew Promise<boolean>((resolve) => {\n\t\t\t\t\ttimer = setTimeout(() => resolve(false), startupWaitMs);\n\t\t\t\t}),\n\t\t\t]);\n\t\t\tclearTimeout(timer);\n\t\t\tif (!finished) {\n\t\t\t\tctx.ui.notify(\"MCP servers are still connecting; their tools become available once connected.\", \"info\");\n\t\t\t}\n\t\t};\n\n\t\t// Every prompt lists the servers in the `mcp_servers` section as they are when it starts. Pi\n\t\t// appends the section to the conversation when it changed, for example after a server connected.\n\t\tpi.on(\"before_agent_start\", async (event, ctx) => {\n\t\t\tawait waitForDirectServers(ctx);\n\t\t\tconst { sections } = event.systemPromptOptions;\n\t\t\tconst section = renderServersSection(servers);\n\t\t\tif (section) sections[MCP_SERVERS_SECTION] = section;\n\t\t\telse delete sections[MCP_SERVERS_SECTION];\n\t\t});\n\n\t\t// A tool that reaches other tools (`reachesTools`) waits for the servers it may reach, so their\n\t\t// tools are registered before it runs: a codemode script for the servers it names, or for every\n\t\t// server when it searches or enumerates tools, and tool_search for every server. The resource\n\t\t// tools reach every server, so they wait for all of them. Direct MCP calls wait only for their\n\t\t// own server, including a reconnect still closing its old transport.\n\t\tpi.on(\"tool_call\", async (event, ctx) => {\n\t\t\tconst tool = pi.getAllTools().find((candidate) => candidate.name === event.toolName);\n\t\t\tif (!tool) return;\n\t\t\t// Readiness can be pending while the display state is still connected: reconnect first\n\t\t\t// closes the old transport, then opens a new one. Settled promises return immediately.\n\t\t\tconst readyServers = servers.filter((server) => isEnabled(server) && server.ready);\n\t\t\tif (readyServers.length === 0) return;\n\t\t\tlet waiting: McpServer[] = [];\n\t\t\tconst reach = tool.reachesTools?.(event.input);\n\t\t\tif (reach !== undefined) {\n\t\t\t\twaiting = readyServers.filter((server) => reachesServer(reach, server.entry.name));\n\t\t\t} else if (RESOURCE_TOOL_NAMES.has(tool.name)) {\n\t\t\t\twaiting = readyServers;\n\t\t\t} else {\n\t\t\t\tconst owner = toolOwners.get(event.toolName)?.split(\"\\0\", 1)[0];\n\t\t\t\twaiting = readyServers.filter((server) => server.entry.name === owner);\n\t\t\t}\n\t\t\tawait waitForServers(waiting, ctx.signal);\n\t\t});\n\n\t\t// Pick up sign-ins done outside the session, such as `pi mcp login` run by the agent.\n\t\tpi.on(\"turn_start\", async (_event, ctx) => {\n\t\t\tif (tokensAtSignIn.size > 0) await reconnectSignedIn(ctx);\n\t\t});\n\n\t\t// Servers registered or unregistered during the session connect or disconnect right away.\n\t\tpi.on(\"mcp_servers_change\", async (_event, ctx) => {\n\t\t\tconst { signal } = session;\n\t\t\tif (signal.aborted) return;\n\t\t\tconst registered = registeredServers();\n\t\t\toverridden = registered.overridden;\n\t\t\tconst next = new Map(registered.servers.map((server) => [server.entry.name, server]));\n\t\t\t// Unregistered servers and re-registered ones with a new config are dropped; the latter come back below.\n\t\t\tconst removed = servers.filter(\n\t\t\t\t(server) =>\n\t\t\t\t\tserver.entry.scope === \"extension\" &&\n\t\t\t\t\tnext.get(server.entry.name)?.registeredConfig !== server.registeredConfig,\n\t\t\t);\n\t\t\tservers = servers.filter((server) => !removed.includes(server));\n\t\t\tfor (const server of removed) hideTools(server.entry.name);\n\t\t\tconst added = registered.servers.filter((server) => !findServer(server.entry.name));\n\t\t\tservers.push(...added);\n\t\t\tensureDiscoveryActive(ctx);\n\t\t\tawait Promise.all(removed.map((server) => server.connection?.close()));\n\t\t\tconst connecting = added.filter(isEnabled);\n\t\t\tif (signal.aborted || connecting.length === 0) return;\n\t\t\ttry {\n\t\t\t\tawait Promise.all(connecting.map((server) => startConnection(server)));\n\t\t\t\tif (signal.aborted) {\n\t\t\t\t\tawait Promise.all(connecting.map((server) => server.connection?.close()));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tctx.ui.notify(`MCP failed to load: ${errorMessage(error)}`, \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (signal.aborted) return;\n\t\t\treportProblems(ctx, connecting);\n\t\t});\n\n\t\tpi.on(\"session_shutdown\", async () => {\n\t\t\tsession.abort();\n\t\t\tconst closing = connections();\n\t\t\tservers = [];\n\t\t\tawait Promise.all([...backgroundActions, ...closing.map((connection) => connection.close())]);\n\t\t});\n\n\t\tpi.registerCommand(\"mcp\", {\n\t\t\tdescription: \"Show MCP server status, sign in or out, or reconnect\",\n\t\t\tgetArgumentCompletions: (prefix) => {\n\t\t\t\tconst [action, server, ...rest] = prefix.trimStart().split(/\\s+/);\n\t\t\t\tif (rest.length > 0) return null;\n\t\t\t\tif (server === undefined) {\n\t\t\t\t\treturn [\"login\", \"logout\", \"reconnect\"]\n\t\t\t\t\t\t.filter((item) => item.startsWith(action ?? \"\"))\n\t\t\t\t\t\t.map((item) => ({ value: `${item} `, label: item }));\n\t\t\t\t}\n\t\t\t\tif (action !== \"login\" && action !== \"logout\" && action !== \"reconnect\") return null;\n\t\t\t\tconst items = servers\n\t\t\t\t\t.filter((candidate) =>\n\t\t\t\t\t\taction === \"reconnect\" ? candidate.connection !== undefined : usesOAuth(candidate),\n\t\t\t\t\t)\n\t\t\t\t\t.filter((candidate) => candidate.entry.name.startsWith(server))\n\t\t\t\t\t.map((candidate) => ({\n\t\t\t\t\t\tvalue: `${action} ${candidate.entry.name}`,\n\t\t\t\t\t\tlabel: candidate.entry.name,\n\t\t\t\t\t\tdescription: describeState(candidate),\n\t\t\t\t\t}));\n\t\t\t\treturn items.length > 0 ? items : null;\n\t\t\t},\n\t\t\thandler: async (args, ctx) => {\n\t\t\t\tconst [action, name, ...extra] = args.trim().split(/\\s+/).filter(Boolean);\n\t\t\t\tif (action === undefined) {\n\t\t\t\t\tawait pending;\n\t\t\t\t\tctx.ui.notify(formatStatus(), \"info\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (extra.length > 0) {\n\t\t\t\t\tctx.ui.notify(MCP_USAGE, \"warning\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tawait pending;\n\t\t\t\tswitch (action) {\n\t\t\t\t\tcase \"login\": {\n\t\t\t\t\t\tconst server = await pickServer(name, ctx, oauthPick);\n\t\t\t\t\t\tif (server) await loginCommand(server, ctx);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"logout\": {\n\t\t\t\t\t\tconst server = await pickServer(name, ctx, oauthPick);\n\t\t\t\t\t\tif (!server) return;\n\t\t\t\t\t\tconst removed = await signOut(server);\n\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\tremoved\n\t\t\t\t\t\t\t\t? `Signed out of MCP server \"${server.entry.name}\".`\n\t\t\t\t\t\t\t\t: `No stored credentials for MCP server \"${server.entry.name}\".`,\n\t\t\t\t\t\t\t\"info\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"reconnect\": {\n\t\t\t\t\t\tconst server = await pickServer(name, ctx, {\n\t\t\t\t\t\t\teligible: (candidate) => candidate.connection !== undefined,\n\t\t\t\t\t\t\tpreferred: (candidate) =>\n\t\t\t\t\t\t\t\tcandidate.connection?.state === \"failed\" || candidate.connection?.state === \"disconnected\",\n\t\t\t\t\t\t\tnone: \"No enabled MCP server to reconnect.\",\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (!server) return;\n\t\t\t\t\t\tconst failure = await reconnect(server);\n\t\t\t\t\t\tif (failure) ctx.ui.notify(failure, \"error\");\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tensureDiscoveryActive(ctx);\n\t\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\t\t`Reconnected to MCP server \"${server.entry.name}\" (${describeState(server)}).`,\n\t\t\t\t\t\t\t\t\"info\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tctx.ui.notify(MCP_USAGE, \"warning\");\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t};\n}\n\nfunction defaultLoadConfig(ctx: ExtensionContext): LoadedMcpConfig {\n\treturn loadMcpConfig({ agentDir: getAgentDir(), cwd: ctx.cwd, projectTrusted: ctx.isProjectTrusted() });\n}\n\nexport default createMcpExtension();\n"]}
|