@punch-bot/cli 1.5.1 → 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 +162 -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-RROECCMX.js → chunk-LOHGXPCL.js} +2 -2
- package/dist/bundle/chunks/{chunk-CRILLKNU.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-HMPP4ECW.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-JWAAZATQ.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-EHUU7JII.js → google-generative-ai-KA6FZCHM.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-AFMVUS5C.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-YVA2UOJG.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-GNOLFL74.js → openai-decisions-SO57QA6O.js} +1 -1
- package/dist/bundle/chunks/openai-responses-3HV234HB.js +4 -0
- package/dist/bundle/chunks/{openrouter-images-ZTNVFSL2.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-I5AHLF6T.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 +16 -26
- 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 +32 -34
- package/package.json +12 -14
- package/schemas/models.schema.json +65 -36
- package/schemas/settings.schema.json +17 -243
- package/dist/bundle/chunks/anthropic-messages-WAYXCPZL.js +0 -6
- package/dist/bundle/chunks/azure-openai-responses-LUIPKPFC.js +0 -2
- package/dist/bundle/chunks/chunk-275CIYA5.js +0 -16
- package/dist/bundle/chunks/chunk-2W2ATKZM.js +0 -2
- 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-7SFLP7ZK.js +0 -1197
- package/dist/bundle/chunks/chunk-BQU3RKDL.js +0 -2
- package/dist/bundle/chunks/chunk-NJK3U3WK.js +0 -8
- package/dist/bundle/chunks/chunk-NQWQE4BR.js +0 -11
- package/dist/bundle/chunks/chunk-TEPMHNKQ.js +0 -2
- package/dist/bundle/chunks/chunk-TRN3ET6M.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/cli-W5KJM7YB.js +0 -51
- package/dist/bundle/chunks/mistral-conversations-FEBYNTL2.js +0 -5
- package/dist/bundle/chunks/openai-codex-responses-MI7TTP3C.js +0 -10
- package/dist/bundle/chunks/openai-completions-BVORSTAM.js +0 -7
- package/dist/bundle/chunks/openai-responses-TLIV5OQA.js +0 -4
- package/dist/bundle/chunks/pi-messages-4MVQCGGY.js +0 -8
- package/dist/bundle/chunks/virtual-modules-QK7S56IZ.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 -66
- package/examples/extensions/sandbox/package.json +0 -22
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The core only validates and stores registrations. The MCP extension (built in, or another
|
|
5
5
|
* extension that handles `mcp_servers_change`) connects them next to the servers from `mcp.json`.
|
|
6
|
+
* The `mcpServers` shape itself (stdio and HTTP fields, `oauth`, `enabled`, `description`, `timeout`)
|
|
7
|
+
* is pi-mcp's; this file adds pi's fields to it.
|
|
6
8
|
*/
|
|
9
|
+
import { type McpHttpServerConfig as McpHttpServerFields, type McpOAuthConfig as McpOAuthFields, type McpStdioServerConfig as McpStdioServerFields } from "@punch-bot/mcp";
|
|
7
10
|
/** Whether a tool name matches any of the entries, each an exact name or a pattern. */
|
|
8
11
|
export declare function createToolNameMatcher(entries: readonly string[]): (name: string) => boolean;
|
|
9
12
|
/** MCP resource tools, which reach every server with resources. */
|
|
@@ -22,6 +25,10 @@ export declare function isMcpToolName(name: string): boolean;
|
|
|
22
25
|
* - `hidden`: tools are registered but unreachable.
|
|
23
26
|
*/
|
|
24
27
|
export type McpExposure = "codemode" | "deferred" | "direct" | "hidden";
|
|
28
|
+
/**
|
|
29
|
+
* pi's fields of every server entry, beside the shared `mcpServers` fields of pi-mcp. `description`
|
|
30
|
+
* and `timeout` are shared fields, declared again for pi's documentation.
|
|
31
|
+
*/
|
|
25
32
|
interface McpServerConfigBase {
|
|
26
33
|
/** Default: `codemode`. */
|
|
27
34
|
exposure?: McpExposure;
|
|
@@ -37,62 +44,39 @@ interface McpServerConfigBase {
|
|
|
37
44
|
* overrides for a few tools exposes only those.
|
|
38
45
|
*/
|
|
39
46
|
toolExposure?: Record<string, McpExposure>;
|
|
40
|
-
/** Set to false to keep the entry without connecting. Default: true. */
|
|
41
|
-
enabled?: boolean;
|
|
42
47
|
/** Per-request timeout in seconds. Progress notifications from the server reset it. Default: 60. */
|
|
43
48
|
timeout?: number;
|
|
44
49
|
}
|
|
45
|
-
export interface McpStdioServerConfig extends McpServerConfigBase {
|
|
46
|
-
type?: "stdio";
|
|
47
|
-
command: string;
|
|
48
|
-
args?: string[];
|
|
50
|
+
export interface McpStdioServerConfig extends McpStdioServerFields, McpServerConfigBase {
|
|
49
51
|
/** Values may reference environment variables (`${NAME}`) or commands (`!cmd`). */
|
|
50
52
|
env?: Record<string, string>;
|
|
51
53
|
/** Relative paths resolve against the session working directory. */
|
|
52
54
|
cwd?: string;
|
|
53
55
|
}
|
|
54
56
|
/** OAuth client settings for servers that do not support dynamic client registration. */
|
|
55
|
-
export interface McpOAuthConfig {
|
|
56
|
-
/** Pre-registered client id. Without it, pi registers a client with the authorization server. */
|
|
57
|
-
clientId?: string;
|
|
57
|
+
export interface McpOAuthConfig extends McpOAuthFields {
|
|
58
58
|
/** May reference environment variables (`${NAME}`) or commands (`!cmd`). */
|
|
59
59
|
clientSecret?: string;
|
|
60
|
-
/**
|
|
61
|
-
* Port of the loopback callback server, for clients registered with a fixed redirect URI. Without
|
|
62
|
-
* `callbackUrl`, the redirect URI is `http://127.0.0.1:<port>/callback`.
|
|
63
|
-
*/
|
|
64
|
-
callbackPort?: number;
|
|
65
|
-
/**
|
|
66
|
-
* Redirect URI registered for `clientId`, for example `http://localhost:8080/oauth/callback`. It must
|
|
67
|
-
* be an `http` URI on `localhost`, `127.0.0.1`, or `[::1]`. Without a port, the callback server
|
|
68
|
-
* listens on `callbackPort` or a free port, which is added to the URI (RFC 8252).
|
|
69
|
-
*/
|
|
70
|
-
callbackUrl?: string;
|
|
71
|
-
/** Scopes to request, separated by spaces. Default: the scopes the server advertises. */
|
|
72
|
-
scope?: string;
|
|
73
60
|
/**
|
|
74
61
|
* `client_name` sent with dynamic client registration, for servers that only accept known clients.
|
|
75
62
|
* Default: `pi`.
|
|
76
63
|
*/
|
|
77
64
|
clientName?: string;
|
|
78
65
|
/**
|
|
79
|
-
* How pi identifies itself without `clientId`. `
|
|
80
|
-
* pi
|
|
81
|
-
*
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Authorization server metadata document (RFC 8414 or OpenID Connect discovery) to use instead of
|
|
86
|
-
* discovery through the server, for servers that advertise a wrong authorization server or none.
|
|
87
|
-
* The document is trusted as configured. Must use https, except on loopback hosts.
|
|
66
|
+
* How pi identifies itself without `clientId`. `auto` (default): pi's Client ID Metadata Document on
|
|
67
|
+
* pi.dev when the authorization server supports it for public clients, otherwise dynamic client
|
|
68
|
+
* registration; with `clientName` or a `callbackUrl` other than `/callback` on localhost or 127.0.0.1,
|
|
69
|
+
* always dynamic client registration. `cimd`: always the document, and sign-in fails without support.
|
|
70
|
+
* `dcr`: always dynamic client registration.
|
|
88
71
|
*/
|
|
89
|
-
|
|
72
|
+
clientRegistration?: "auto" | "dcr" | "cimd";
|
|
90
73
|
}
|
|
91
|
-
/**
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Whether pi's Client ID Metadata Documents list a redirect URI for the loopback `callbackUrl`: they list
|
|
76
|
+
* `/callback` on localhost and 127.0.0.1, on any port. Without `callbackUrl`, pi uses such a URI.
|
|
77
|
+
*/
|
|
78
|
+
export declare function isClientMetadataDocumentCallback(callbackUrl: string | undefined): boolean;
|
|
79
|
+
export interface McpHttpServerConfig extends McpHttpServerFields, McpServerConfigBase {
|
|
96
80
|
/** Values may reference environment variables (`${NAME}`) or commands (`!cmd`). */
|
|
97
81
|
headers?: Record<string, string>;
|
|
98
82
|
oauth?: McpOAuthConfig;
|
|
@@ -105,13 +89,11 @@ export interface McpHttpServerConfig extends McpServerConfigBase {
|
|
|
105
89
|
};
|
|
106
90
|
}
|
|
107
91
|
export type McpServerConfig = McpStdioServerConfig | McpHttpServerConfig;
|
|
108
|
-
/** Namespace of a server's tools: `mcp__<server>` with `-` replaced by `_`, like the tool names. */
|
|
109
|
-
export declare function mcpNamespace(server: string): string;
|
|
110
92
|
/** Exposure of one tool of a server: its `toolExposure` entry, else the server's `exposure`. */
|
|
111
93
|
export declare function getMcpToolExposure(config: McpServerConfig, toolName: string): McpExposure;
|
|
112
94
|
/**
|
|
113
|
-
* Validate one server entry of the `mcpServers` shape
|
|
114
|
-
* aliases resolved, or an error message.
|
|
95
|
+
* Validate one server entry of the `mcpServers` shape: pi-mcp's shared fields and pi's own. Returns a
|
|
96
|
+
* copy of the config with exposure aliases resolved, or an error message.
|
|
115
97
|
*/
|
|
116
98
|
export declare function validateMcpServerConfig(name: string, raw: unknown): McpServerConfig | string;
|
|
117
99
|
/** A server an extension registered with `pi.registerMcpServer()`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-servers.d.ts","sourceRoot":"","sources":["../../src/core/mcp-servers.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"mcp-servers.d.ts","sourceRoot":"","sources":["../../src/core/mcp-servers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACN,KAAK,mBAAmB,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,iBAAiB,CAAC,QAAQ,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,GAAG,IAAI,CAE1D;CACD"}
|
package/dist/core/mcp-servers.js
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The core only validates and stores registrations. The MCP extension (built in, or another
|
|
5
5
|
* extension that handles `mcp_servers_change`) connects them next to the servers from `mcp.json`.
|
|
6
|
+
* The `mcpServers` shape itself (stdio and HTTP fields, `oauth`, `enabled`, `description`, `timeout`)
|
|
7
|
+
* is pi-mcp's; this file adds pi's fields to it.
|
|
6
8
|
*/
|
|
9
|
+
import { validateMcpServerConfig as validateMcpServerFields, } from "@punch-bot/mcp";
|
|
7
10
|
/**
|
|
8
11
|
* Regular expression for a tool name pattern where `*` matches any characters, as `toolExposure`,
|
|
9
12
|
* `--tools`, and `--exclude-tools` accept them.
|
|
@@ -37,73 +40,19 @@ export function isMcpToolName(name) {
|
|
|
37
40
|
const MCP_EXPOSURES = ["codemode", "deferred", "direct", "hidden"];
|
|
38
41
|
/** Older exposure names, accepted in configs and replaced by their current name when validated. */
|
|
39
42
|
const MCP_EXPOSURE_ALIASES = { "codemode-deferred": "codemode" };
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
/** Namespace of a server's tools: `mcp__<server>` with `-` replaced by `_`, like the tool names. */
|
|
50
|
-
export function mcpNamespace(server) {
|
|
51
|
-
return `mcp__${server.replace(/-/g, "_")}`;
|
|
43
|
+
/**
|
|
44
|
+
* Whether pi's Client ID Metadata Documents list a redirect URI for the loopback `callbackUrl`: they list
|
|
45
|
+
* `/callback` on localhost and 127.0.0.1, on any port. Without `callbackUrl`, pi uses such a URI.
|
|
46
|
+
*/
|
|
47
|
+
export function isClientMetadataDocumentCallback(callbackUrl) {
|
|
48
|
+
if (callbackUrl === undefined)
|
|
49
|
+
return true;
|
|
50
|
+
const url = new URL(callbackUrl);
|
|
51
|
+
return url.hostname !== "[::1]" && url.pathname === "/callback";
|
|
52
52
|
}
|
|
53
53
|
function isRecord(value) {
|
|
54
54
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
55
55
|
}
|
|
56
|
-
function isStringRecord(value) {
|
|
57
|
-
return isRecord(value) && Object.values(value).every((entry) => typeof entry === "string");
|
|
58
|
-
}
|
|
59
|
-
function validateOAuth(value) {
|
|
60
|
-
if (value === undefined)
|
|
61
|
-
return undefined;
|
|
62
|
-
if (!isRecord(value))
|
|
63
|
-
return "oauth must be an object";
|
|
64
|
-
if (value.clientId !== undefined && typeof value.clientId !== "string")
|
|
65
|
-
return "oauth.clientId must be a string";
|
|
66
|
-
if (value.clientSecret !== undefined && typeof value.clientSecret !== "string") {
|
|
67
|
-
return "oauth.clientSecret must be a string";
|
|
68
|
-
}
|
|
69
|
-
const port = value.callbackPort;
|
|
70
|
-
if (port !== undefined && (typeof port !== "number" || !Number.isInteger(port) || port < 1 || port > 65535)) {
|
|
71
|
-
return "oauth.callbackPort must be a port number";
|
|
72
|
-
}
|
|
73
|
-
if (value.callbackUrl !== undefined) {
|
|
74
|
-
if (typeof value.callbackUrl !== "string" || !isLoopbackRedirectUri(value.callbackUrl)) {
|
|
75
|
-
return "oauth.callbackUrl must be an http URI on localhost, 127.0.0.1, or [::1] without query or fragment";
|
|
76
|
-
}
|
|
77
|
-
const urlPort = new URL(value.callbackUrl).port;
|
|
78
|
-
if (urlPort && port !== undefined && Number(urlPort) !== port) {
|
|
79
|
-
return "oauth.callbackUrl and oauth.callbackPort name different ports";
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
if (value.scope !== undefined && typeof value.scope !== "string")
|
|
83
|
-
return "oauth.scope must be a string";
|
|
84
|
-
if (value.clientName !== undefined && (typeof value.clientName !== "string" || !value.clientName.trim())) {
|
|
85
|
-
return "oauth.clientName must be a non-empty string";
|
|
86
|
-
}
|
|
87
|
-
if (value.clientRegistration !== undefined && value.clientRegistration !== "dcr") {
|
|
88
|
-
if (value.clientRegistration !== "cimd")
|
|
89
|
-
return 'oauth.clientRegistration must be "dcr" or "cimd"';
|
|
90
|
-
if (value.clientId !== undefined || value.clientName !== undefined) {
|
|
91
|
-
return 'oauth.clientRegistration "cimd" cannot be combined with oauth.clientId or oauth.clientName';
|
|
92
|
-
}
|
|
93
|
-
const callback = typeof value.callbackUrl === "string" ? new URL(value.callbackUrl) : undefined;
|
|
94
|
-
if (callback && (callback.hostname === "[::1]" || callback.pathname !== "/callback")) {
|
|
95
|
-
return 'oauth.clientRegistration "cimd" requires oauth.callbackUrl on localhost or 127.0.0.1 with path /callback';
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const metadataUrl = value.authServerMetadataUrl;
|
|
99
|
-
if (metadataUrl !== undefined) {
|
|
100
|
-
const url = typeof metadataUrl === "string" && URL.canParse(metadataUrl) ? new URL(metadataUrl) : undefined;
|
|
101
|
-
if (!url || !(url.protocol === "https:" || (url.protocol === "http:" && LOOPBACK_HOSTS.includes(url.hostname)))) {
|
|
102
|
-
return "oauth.authServerMetadataUrl must be an https URL, or http on localhost, 127.0.0.1, or [::1]";
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
107
56
|
function isExposure(value) {
|
|
108
57
|
return typeof value === "string" && MCP_EXPOSURES.includes(value);
|
|
109
58
|
}
|
|
@@ -134,72 +83,54 @@ export function getMcpToolExposure(config, toolName) {
|
|
|
134
83
|
}
|
|
135
84
|
return config.exposure ?? "codemode";
|
|
136
85
|
}
|
|
137
|
-
/**
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
*/
|
|
141
|
-
export function validateMcpServerConfig(name, raw) {
|
|
142
|
-
if (!SERVER_NAME.test(name))
|
|
143
|
-
return `invalid server name "${name}" (use letters, digits, "_" and "-")`;
|
|
144
|
-
if (!isRecord(raw))
|
|
145
|
-
return `server "${name}" must be an object`;
|
|
146
|
-
const value = resolveExposureAliases(raw);
|
|
147
|
-
const { type, exposure, enabled, timeout, toolExposure, description } = value;
|
|
86
|
+
/** Checks `exposure` and `toolExposure`, after aliases were resolved. Returns an error message. */
|
|
87
|
+
function checkExposures(entry) {
|
|
88
|
+
const { exposure, toolExposure } = entry;
|
|
148
89
|
const exposures = MCP_EXPOSURES.map((value) => `"${value}"`).join(", ");
|
|
149
|
-
if (exposure !== undefined && !isExposure(exposure))
|
|
150
|
-
return `
|
|
151
|
-
}
|
|
90
|
+
if (exposure !== undefined && !isExposure(exposure))
|
|
91
|
+
return `exposure must be one of ${exposures}`;
|
|
152
92
|
if (toolExposure !== undefined) {
|
|
153
93
|
if (!isRecord(toolExposure))
|
|
154
|
-
return
|
|
94
|
+
return "toolExposure must map tool names to exposures";
|
|
155
95
|
for (const [tool, value] of Object.entries(toolExposure)) {
|
|
156
96
|
if (!isExposure(value))
|
|
157
|
-
return `
|
|
97
|
+
return `toolExposure "${tool}" must be one of ${exposures}`;
|
|
158
98
|
}
|
|
159
99
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
return
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return `server "${name}": legacy SSE transport is not supported; use the streamable HTTP URL`;
|
|
170
|
-
if (typeof value.url === "string" && (type === undefined || type === "http" || type === "streamable-http")) {
|
|
171
|
-
if (!URL.canParse(value.url) || !/^https?:$/.test(new URL(value.url).protocol)) {
|
|
172
|
-
return `server "${name}": url must be an http or https URL`;
|
|
173
|
-
}
|
|
174
|
-
if (value.headers !== undefined && !isStringRecord(value.headers)) {
|
|
175
|
-
return `server "${name}": headers must map names to strings`;
|
|
176
|
-
}
|
|
177
|
-
const oauthError = validateOAuth(value.oauth);
|
|
178
|
-
if (oauthError)
|
|
179
|
-
return `server "${name}": ${oauthError}`;
|
|
180
|
-
if (value.auth !== undefined) {
|
|
181
|
-
if (!isRecord(value.auth) || typeof value.auth.provider !== "string" || !value.auth.provider) {
|
|
182
|
-
return `server "${name}": auth.provider must be a provider name`;
|
|
183
|
-
}
|
|
184
|
-
const url = new URL(value.url);
|
|
185
|
-
if (url.protocol !== "https:" && !LOOPBACK_HOSTS.includes(url.hostname)) {
|
|
186
|
-
return `server "${name}": auth requires an https URL, or http on localhost, 127.0.0.1, or [::1]`;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return value;
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
const LOOPBACK_HOSTS = ["localhost", "127.0.0.1", "[::1]"];
|
|
103
|
+
/** Checks `auth` of an HTTP server, which sends a provider's credential to `url`. Returns an error message. */
|
|
104
|
+
function checkAuth(auth, url) {
|
|
105
|
+
if (auth === undefined)
|
|
106
|
+
return undefined;
|
|
107
|
+
if (!isRecord(auth) || typeof auth.provider !== "string" || !auth.provider) {
|
|
108
|
+
return "auth.provider must be a provider name";
|
|
190
109
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
return `server "${name}": args must be an array of strings`;
|
|
195
|
-
}
|
|
196
|
-
if (value.env !== undefined && !isStringRecord(value.env))
|
|
197
|
-
return `server "${name}": env must map names to strings`;
|
|
198
|
-
if (value.cwd !== undefined && typeof value.cwd !== "string")
|
|
199
|
-
return `server "${name}": cwd must be a string`;
|
|
200
|
-
return value;
|
|
110
|
+
const parsed = new URL(url);
|
|
111
|
+
if (parsed.protocol !== "https:" && !LOOPBACK_HOSTS.includes(parsed.hostname)) {
|
|
112
|
+
return "auth requires an https URL, or http on localhost, 127.0.0.1, or [::1]";
|
|
201
113
|
}
|
|
202
|
-
return
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Validate one server entry of the `mcpServers` shape: pi-mcp's shared fields and pi's own. Returns a
|
|
118
|
+
* copy of the config with exposure aliases resolved, or an error message.
|
|
119
|
+
*/
|
|
120
|
+
export function validateMcpServerConfig(name, raw) {
|
|
121
|
+
const result = validateMcpServerFields(name, isRecord(raw) ? resolveExposureAliases(raw) : raw, {
|
|
122
|
+
checkMetadataDocumentCallback: (callbackUrl) => isClientMetadataDocumentCallback(callbackUrl)
|
|
123
|
+
? undefined
|
|
124
|
+
: 'oauth.clientRegistration "cimd" requires oauth.callbackUrl on localhost or 127.0.0.1 with path /callback',
|
|
125
|
+
});
|
|
126
|
+
if (result.kind === "invalid")
|
|
127
|
+
return result.error;
|
|
128
|
+
const error = checkExposures(result.config) ??
|
|
129
|
+
(result.kind === "http" ? checkAuth(result.config.auth, result.config.url) : undefined);
|
|
130
|
+
if (error)
|
|
131
|
+
return `server "${name}": ${error}`;
|
|
132
|
+
// The cast holds because pi's fields were checked above, which the types cannot express.
|
|
133
|
+
return result.config;
|
|
203
134
|
}
|
|
204
135
|
/** Servers registered by the extensions of one runtime. */
|
|
205
136
|
export class McpServerRegistry {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-servers.js","sourceRoot":"","sources":["../../src/core/mcp-servers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,SAAS,iBAAiB,CAAC,OAAe;IACzC,MAAM,MAAM,GAAG,OAAO;SACpB,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;SACzD,IAAI,CAAC,IAAI,CAAC,CAAC;IACb,OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC;AAClC,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,qBAAqB,CAAC,OAA0B;IAC/D,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACvE,MAAM,Q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,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,aAAa,KAAK,aAAa;YAAE,OAAO;QACpE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC1B,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,GAAG,CAAC,IAAY;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,+DAA+D;IAC/D,IAAI;QACH,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5G,CAAC;IAED,iGAAiG;IACjG,iBAAiB,CAAC,QAAkC;QACnD,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC;IAChC,CAAC;CACD","sourcesContent":["/**\n * MCP server configuration and the servers extensions register with `pi.registerMcpServer()`.\n *\n * The core only validates and stores registrations. The MCP extension (built in, or another\n * extension that handles `mcp_servers_change`) connects them next to the servers from `mcp.json`.\n */\n\n/**\n * Regular expression for a tool name pattern where `*` matches any characters, as `toolExposure`,\n * `--tools`, and `--exclude-tools` accept them.\n */\nfunction toolPatternRegExp(pattern: string): RegExp {\n\tconst source = pattern\n\t\t.split(\"*\")\n\t\t.map((part) => part.replace(/[.+?^${}()|[\\]\\\\]/g, \"\\\\$&\"))\n\t\t.join(\".*\");\n\treturn new RegExp(`^${source}$`);\n}\n\n/** Whether a tool name matches any of the entries, each an exact name or a pattern. */\nexport function createToolNameMatcher(entries: readonly string[]): (name: string) => boolean {\n\tconst names = new Set(entries.filter((entry) => !entry.includes(\"*\")));\n\tconst patterns = entries.filter((entry) => entry.includes(\"*\")).map(toolPatternRegExp);\n\treturn (name) => names.has(name) || patterns.some((pattern) => pattern.test(name));\n}\n\n/** MCP resource tools, which reach every server with resources. */\nexport const LIST_MCP_RESOURCES_TOOL = \"list_mcp_resources\";\nexport const LIST_MCP_RESOURCE_TEMPLATES_TOOL = \"list_mcp_resource_templates\";\nexport const READ_MCP_RESOURCE_TOOL = \"read_mcp_resource\";\n\nconst MCP_RESOURCE_TOOLS: ReadonlySet<string> = new Set([\n\tLIST_MCP_RESOURCES_TOOL,\n\tLIST_MCP_RESOURCE_TEMPLATES_TOOL,\n\tREAD_MCP_RESOURCE_TOOL,\n]);\n\n/** Whether a tool comes from MCP: a server tool (`mcp__<server>__<tool>`) or a resource tool. */\nexport function isMcpToolName(name: string): boolean {\n\treturn name.startsWith(\"mcp__\") || MCP_RESOURCE_TOOLS.has(name);\n}\n\n/**\n * - `codemode`: tools are callable from codemode scripts but neither declared to the model nor\n * listed in the codemode description, which lists only the server's namespace. Scripts find them\n * with `searchTools()`. `codemode-deferred` is accepted as an alias.\n * - `deferred`: not declared to the model until the `tool_search` tool loads them; the model then\n * calls them directly. Does not need codemode.\n * - `direct`: tools are declared to the model like any other tool (and callable from codemode).\n * - `hidden`: tools are registered but unreachable.\n */\nexport type McpExposure = \"codemode\" | \"deferred\" | \"direct\" | \"hidden\";\n\nconst MCP_EXPOSURES: readonly string[] = [\"codemode\", \"deferred\", \"direct\", \"hidden\"] satisfies McpExposure[];\n\n/** Older exposure names, accepted in configs and replaced by their current name when validated. */\nconst MCP_EXPOSURE_ALIASES: Readonly<Record<string, McpExposure>> = { \"codemode-deferred\": \"codemode\" };\n\ninterface McpServerConfigBase {\n\t/** Default: `codemode`. */\n\texposure?: McpExposure;\n\t/**\n\t * What the server offers, in a sentence. The `mcp_servers` system prompt section lists the server\n\t * with it, tool search ranks the server's tools by it, and codemode's `describeNamespace()` returns it.\n\t */\n\tdescription?: string;\n\t/**\n\t * Exposure of single tools, overriding `exposure`. Keys are tool names as the server offers them,\n\t * or patterns where `*` matches any characters. An exact name wins over patterns; among patterns\n\t * the first match in the object wins. `hidden` removes tools, so `\"exposure\": \"hidden\"` with\n\t * overrides for a few tools exposes only those.\n\t */\n\ttoolExposure?: Record<string, McpExposure>;\n\t/** Set to false to keep the entry without connecting. Default: true. */\n\tenabled?: boolean;\n\t/** Per-request timeout in seconds. Progress notifications from the server reset it. Default: 60. */\n\ttimeout?: number;\n}\n\nexport interface McpStdioServerConfig extends McpServerConfigBase {\n\ttype?: \"stdio\";\n\tcommand: string;\n\targs?: string[];\n\t/** Values may reference environment variables (`${NAME}`) or commands (`!cmd`). */\n\tenv?: Record<string, string>;\n\t/** Relative paths resolve against the session working directory. */\n\tcwd?: string;\n}\n\n/** OAuth client settings for servers that do not support dynamic client registration. */\nexport interface McpOAuthConfig {\n\t/** Pre-registered client id. Without it, pi registers a client with the authorization server. */\n\tclientId?: string;\n\t/** May reference environment variables (`${NAME}`) or commands (`!cmd`). */\n\tclientSecret?: string;\n\t/**\n\t * Port of the loopback callback server, for clients registered with a fixed redirect URI. Without\n\t * `callbackUrl`, the redirect URI is `http://127.0.0.1:<port>/callback`.\n\t */\n\tcallbackPort?: number;\n\t/**\n\t * Redirect URI registered for `clientId`, for example `http://localhost:8080/oauth/callback`. It must\n\t * be an `http` URI on `localhost`, `127.0.0.1`, or `[::1]`. Without a port, the callback server\n\t * listens on `callbackPort` or a free port, which is added to the URI (RFC 8252).\n\t */\n\tcallbackUrl?: string;\n\t/** Scopes to request, separated by spaces. Default: the scopes the server advertises. */\n\tscope?: string;\n\t/**\n\t * `client_name` sent with dynamic client registration, for servers that only accept known clients.\n\t * Default: `pi`.\n\t */\n\tclientName?: string;\n\t/**\n\t * How pi identifies itself without `clientId`. `dcr` (default): dynamic client registration. `cimd`:\n\t * pi's Client ID Metadata Document on pi.dev, for authorization servers that allow pi by that URL. The\n\t * server must support it for public clients, and the callback must use the default path `/callback`.\n\t */\n\tclientRegistration?: \"dcr\" | \"cimd\";\n\t/**\n\t * Authorization server metadata document (RFC 8414 or OpenID Connect discovery) to use instead of\n\t * discovery through the server, for servers that advertise a wrong authorization server or none.\n\t * The document is trusted as configured. Must use https, except on loopback hosts.\n\t */\n\tauthServerMetadataUrl?: string;\n}\n\nconst LOOPBACK_HOSTS = [\"localhost\", \"127.0.0.1\", \"[::1]\"];\n\n/** Whether a redirect URI can be served by pi's loopback callback server. */\nexport function isLoopbackRedirectUri(value: string): boolean {\n\tif (!URL.canParse(value)) return false;\n\tconst url = new URL(value);\n\treturn url.protocol === \"http:\" && LOOPBACK_HOSTS.includes(url.hostname) && url.search === \"\" && url.hash === \"\";\n}\n\nexport interface McpHttpServerConfig extends McpServerConfigBase {\n\ttype?: \"http\";\n\turl: string;\n\t/** Values may reference environment variables (`${NAME}`) or commands (`!cmd`). */\n\theaders?: Record<string, string>;\n\toauth?: McpOAuthConfig;\n\t/**\n\t * Send the token of a pi provider (`/login <provider>`) instead of using OAuth. Not allowed in project\n\t * `mcp.json` files, and requires https except on loopback hosts, since it sends the credential to `url`.\n\t */\n\tauth?: { provider: string };\n}\n\nexport type McpServerConfig = McpStdioServerConfig | McpHttpServerConfig;\n\nconst SERVER_NAME = /^[A-Za-z0-9_-]+$/;\n\n/** Namespace of a server's tools: `mcp__<server>` with `-` replaced by `_`, like the tool names. */\nexport function mcpNamespace(server: string): string {\n\treturn `mcp__${server.replace(/-/g, \"_\")}`;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isStringRecord(value: unknown): value is Record<string, string> {\n\treturn isRecord(value) && Object.values(value).every((entry) => typeof entry === \"string\");\n}\n\nfunction validateOAuth(value: unknown): string | undefined {\n\tif (value === undefined) return undefined;\n\tif (!isRecord(value)) return \"oauth must be an object\";\n\tif (value.clientId !== undefined && typeof value.clientId !== \"string\") return \"oauth.clientId must be a string\";\n\tif (value.clientSecret !== undefined && typeof value.clientSecret !== \"string\") {\n\t\treturn \"oauth.clientSecret must be a string\";\n\t}\n\tconst port = value.callbackPort;\n\tif (port !== undefined && (typeof port !== \"number\" || !Number.isInteger(port) || port < 1 || port > 65535)) {\n\t\treturn \"oauth.callbackPort must be a port number\";\n\t}\n\tif (value.callbackUrl !== undefined) {\n\t\tif (typeof value.callbackUrl !== \"string\" || !isLoopbackRedirectUri(value.callbackUrl)) {\n\t\t\treturn \"oauth.callbackUrl must be an http URI on localhost, 127.0.0.1, or [::1] without query or fragment\";\n\t\t}\n\t\tconst urlPort = new URL(value.callbackUrl).port;\n\t\tif (urlPort && port !== undefined && Number(urlPort) !== port) {\n\t\t\treturn \"oauth.callbackUrl and oauth.callbackPort name different ports\";\n\t\t}\n\t}\n\tif (value.scope !== undefined && typeof value.scope !== \"string\") return \"oauth.scope must be a string\";\n\tif (value.clientName !== undefined && (typeof value.clientName !== \"string\" || !value.clientName.trim())) {\n\t\treturn \"oauth.clientName must be a non-empty string\";\n\t}\n\tif (value.clientRegistration !== undefined && value.clientRegistration !== \"dcr\") {\n\t\tif (value.clientRegistration !== \"cimd\") return 'oauth.clientRegistration must be \"dcr\" or \"cimd\"';\n\t\tif (value.clientId !== undefined || value.clientName !== undefined) {\n\t\t\treturn 'oauth.clientRegistration \"cimd\" cannot be combined with oauth.clientId or oauth.clientName';\n\t\t}\n\t\tconst callback = typeof value.callbackUrl === \"string\" ? new URL(value.callbackUrl) : undefined;\n\t\tif (callback && (callback.hostname === \"[::1]\" || callback.pathname !== \"/callback\")) {\n\t\t\treturn 'oauth.clientRegistration \"cimd\" requires oauth.callbackUrl on localhost or 127.0.0.1 with path /callback';\n\t\t}\n\t}\n\tconst metadataUrl = value.authServerMetadataUrl;\n\tif (metadataUrl !== undefined) {\n\t\tconst url = typeof metadataUrl === \"string\" && URL.canParse(metadataUrl) ? new URL(metadataUrl) : undefined;\n\t\tif (!url || !(url.protocol === \"https:\" || (url.protocol === \"http:\" && LOOPBACK_HOSTS.includes(url.hostname)))) {\n\t\t\treturn \"oauth.authServerMetadataUrl must be an https URL, or http on localhost, 127.0.0.1, or [::1]\";\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction isExposure(value: unknown): value is McpExposure {\n\treturn typeof value === \"string\" && MCP_EXPOSURES.includes(value);\n}\n\n/** The exposure an alias stands for; other values are returned unchanged. */\nfunction resolveExposureAlias(value: unknown): unknown {\n\treturn typeof value === \"string\" ? (MCP_EXPOSURE_ALIASES[value] ?? value) : value;\n}\n\n/** A copy of the server entry with exposure aliases replaced by their current names. */\nfunction resolveExposureAliases(value: Record<string, unknown>): Record<string, unknown> {\n\tconst { exposure, toolExposure } = value;\n\tconst resolved: Record<string, unknown> = { ...value };\n\tif (exposure !== undefined) resolved.exposure = resolveExposureAlias(exposure);\n\tif (isRecord(toolExposure)) {\n\t\tresolved.toolExposure = Object.fromEntries(\n\t\t\tObject.entries(toolExposure).map(([tool, entry]) => [tool, resolveExposureAlias(entry)]),\n\t\t);\n\t}\n\treturn resolved;\n}\n\n/** Exposure of one tool of a server: its `toolExposure` entry, else the server's `exposure`. */\nexport function getMcpToolExposure(config: McpServerConfig, toolName: string): McpExposure {\n\tconst overrides = config.toolExposure ?? {};\n\tconst exact = overrides[toolName];\n\tif (exact !== undefined) return exact;\n\tfor (const [pattern, exposure] of Object.entries(overrides)) {\n\t\tif (pattern.includes(\"*\") && toolPatternRegExp(pattern).test(toolName)) return exposure;\n\t}\n\treturn config.exposure ?? \"codemode\";\n}\n\n/**\n * Validate one server entry of the `mcpServers` shape. Returns a copy of the config with exposure\n * aliases resolved, or an error message.\n */\nexport function validateMcpServerConfig(name: string, raw: unknown): McpServerConfig | string {\n\tif (!SERVER_NAME.test(name)) return `invalid server name \"${name}\" (use letters, digits, \"_\" and \"-\")`;\n\tif (!isRecord(raw)) return `server \"${name}\" must be an object`;\n\tconst value = resolveExposureAliases(raw);\n\tconst { type, exposure, enabled, timeout, toolExposure, description } = value;\n\tconst exposures = MCP_EXPOSURES.map((value) => `\"${value}\"`).join(\", \");\n\tif (exposure !== undefined && !isExposure(exposure)) {\n\t\treturn `server \"${name}\": exposure must be one of ${exposures}`;\n\t}\n\tif (toolExposure !== undefined) {\n\t\tif (!isRecord(toolExposure)) return `server \"${name}\": toolExposure must map tool names to exposures`;\n\t\tfor (const [tool, value] of Object.entries(toolExposure)) {\n\t\t\tif (!isExposure(value)) return `server \"${name}\": toolExposure \"${tool}\" must be one of ${exposures}`;\n\t\t}\n\t}\n\tif (enabled !== undefined && typeof enabled !== \"boolean\") return `server \"${name}\": enabled must be a boolean`;\n\tif (description !== undefined && typeof description !== \"string\") {\n\t\treturn `server \"${name}\": description must be a string`;\n\t}\n\tif (timeout !== undefined && (typeof timeout !== \"number\" || !(timeout > 0))) {\n\t\treturn `server \"${name}\": timeout must be a positive number of seconds`;\n\t}\n\tif (type === \"sse\") return `server \"${name}\": legacy SSE transport is not supported; use the streamable HTTP URL`;\n\n\tif (typeof value.url === \"string\" && (type === undefined || type === \"http\" || type === \"streamable-http\")) {\n\t\tif (!URL.canParse(value.url) || !/^https?:$/.test(new URL(value.url).protocol)) {\n\t\t\treturn `server \"${name}\": url must be an http or https URL`;\n\t\t}\n\t\tif (value.headers !== undefined && !isStringRecord(value.headers)) {\n\t\t\treturn `server \"${name}\": headers must map names to strings`;\n\t\t}\n\t\tconst oauthError = validateOAuth(value.oauth);\n\t\tif (oauthError) return `server \"${name}\": ${oauthError}`;\n\t\tif (value.auth !== undefined) {\n\t\t\tif (!isRecord(value.auth) || typeof value.auth.provider !== \"string\" || !value.auth.provider) {\n\t\t\t\treturn `server \"${name}\": auth.provider must be a provider name`;\n\t\t\t}\n\t\t\tconst url = new URL(value.url);\n\t\t\tif (url.protocol !== \"https:\" && !LOOPBACK_HOSTS.includes(url.hostname)) {\n\t\t\t\treturn `server \"${name}\": auth requires an https URL, or http on localhost, 127.0.0.1, or [::1]`;\n\t\t\t}\n\t\t}\n\t\treturn value as unknown as McpHttpServerConfig;\n\t}\n\tif (typeof value.command === \"string\" && (type === undefined || type === \"stdio\")) {\n\t\tif (\n\t\t\tvalue.args !== undefined &&\n\t\t\t!(Array.isArray(value.args) && value.args.every((arg) => typeof arg === \"string\"))\n\t\t) {\n\t\t\treturn `server \"${name}\": args must be an array of strings`;\n\t\t}\n\t\tif (value.env !== undefined && !isStringRecord(value.env))\n\t\t\treturn `server \"${name}\": env must map names to strings`;\n\t\tif (value.cwd !== undefined && typeof value.cwd !== \"string\") return `server \"${name}\": cwd must be a string`;\n\t\treturn value as unknown as McpStdioServerConfig;\n\t}\n\treturn `server \"${name}\" needs either \"command\" (stdio) or \"url\" (streamable HTTP)`;\n}\n\n/** A server an extension registered with `pi.registerMcpServer()`. */\nexport interface RegisteredMcpServer {\n\tname: string;\n\tconfig: McpServerConfig;\n\t/** Path of the extension that registered the server. */\n\textensionPath: string;\n}\n\n/** Servers registered by the extensions of one runtime. */\nexport class McpServerRegistry {\n\tprivate readonly servers = new Map<string, RegisteredMcpServer>();\n\tprivate changeListener: (() => void) | undefined;\n\n\t/** Register or replace a server. The caller checks ownership. */\n\tregister(server: RegisteredMcpServer): void {\n\t\tthis.servers.set(server.name, server);\n\t\tthis.changeListener?.();\n\t}\n\n\t/** Remove a server registered by `extensionPath`. Servers of other extensions are left alone. */\n\tunregister(name: string, extensionPath: string): void {\n\t\tif (this.servers.get(name)?.extensionPath !== extensionPath) return;\n\t\tthis.servers.delete(name);\n\t\tthis.changeListener?.();\n\t}\n\n\tget(name: string): RegisteredMcpServer | undefined {\n\t\treturn this.servers.get(name);\n\t}\n\n\t/** Copies of the registered servers, in registration order. */\n\tlist(): RegisteredMcpServer[] {\n\t\treturn [...this.servers.values()].map((server) => ({ ...server, config: structuredClone(server.config) }));\n\t}\n\n\t/** Called after every change. The runner sets it when it binds, to emit `mcp_servers_change`. */\n\tsetChangeListener(listener: (() => void) | undefined): void {\n\t\tthis.changeListener = listener;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mcp-servers.js","sourceRoot":"","sources":["../../src/core/mcp-servers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH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C;IAED,GAAG,CAAC,IAAY;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,+DAA+D;IAC/D,IAAI;QACH,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5G,CAAC;IAED,iGAAiG;IACjG,iBAAiB,CAAC,QAAkC;QACnD,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC;IAChC,CAAC;CACD","sourcesContent":["/**\n * MCP server configuration and the servers extensions register with `pi.registerMcpServer()`.\n *\n * The core only validates and stores registrations. The MCP extension (built in, or another\n * extension that handles `mcp_servers_change`) connects them next to the servers from `mcp.json`.\n * The `mcpServers` shape itself (stdio and HTTP fields, `oauth`, `enabled`, `description`, `timeout`)\n * is pi-mcp's; this file adds pi's fields to it.\n */\n\nimport {\n\ttype McpHttpServerConfig as McpHttpServerFields,\n\ttype McpOAuthConfig as McpOAuthFields,\n\ttype McpStdioServerConfig as McpStdioServerFields,\n\tvalidateMcpServerConfig as validateMcpServerFields,\n} from \"@punch-bot/mcp\";\n\n/**\n * Regular expression for a tool name pattern where `*` matches any characters, as `toolExposure`,\n * `--tools`, and `--exclude-tools` accept them.\n */\nfunction toolPatternRegExp(pattern: string): RegExp {\n\tconst source = pattern\n\t\t.split(\"*\")\n\t\t.map((part) => part.replace(/[.+?^${}()|[\\]\\\\]/g, \"\\\\$&\"))\n\t\t.join(\".*\");\n\treturn new RegExp(`^${source}$`);\n}\n\n/** Whether a tool name matches any of the entries, each an exact name or a pattern. */\nexport function createToolNameMatcher(entries: readonly string[]): (name: string) => boolean {\n\tconst names = new Set(entries.filter((entry) => !entry.includes(\"*\")));\n\tconst patterns = entries.filter((entry) => entry.includes(\"*\")).map(toolPatternRegExp);\n\treturn (name) => names.has(name) || patterns.some((pattern) => pattern.test(name));\n}\n\n/** MCP resource tools, which reach every server with resources. */\nexport const LIST_MCP_RESOURCES_TOOL = \"list_mcp_resources\";\nexport const LIST_MCP_RESOURCE_TEMPLATES_TOOL = \"list_mcp_resource_templates\";\nexport const READ_MCP_RESOURCE_TOOL = \"read_mcp_resource\";\n\nconst MCP_RESOURCE_TOOLS: ReadonlySet<string> = new Set([\n\tLIST_MCP_RESOURCES_TOOL,\n\tLIST_MCP_RESOURCE_TEMPLATES_TOOL,\n\tREAD_MCP_RESOURCE_TOOL,\n]);\n\n/** Whether a tool comes from MCP: a server tool (`mcp__<server>__<tool>`) or a resource tool. */\nexport function isMcpToolName(name: string): boolean {\n\treturn name.startsWith(\"mcp__\") || MCP_RESOURCE_TOOLS.has(name);\n}\n\n/**\n * - `codemode`: tools are callable from codemode scripts but neither declared to the model nor\n * listed in the codemode description, which lists only the server's namespace. Scripts find them\n * with `searchTools()`. `codemode-deferred` is accepted as an alias.\n * - `deferred`: not declared to the model until the `tool_search` tool loads them; the model then\n * calls them directly. Does not need codemode.\n * - `direct`: tools are declared to the model like any other tool (and callable from codemode).\n * - `hidden`: tools are registered but unreachable.\n */\nexport type McpExposure = \"codemode\" | \"deferred\" | \"direct\" | \"hidden\";\n\nconst MCP_EXPOSURES: readonly string[] = [\"codemode\", \"deferred\", \"direct\", \"hidden\"] satisfies McpExposure[];\n\n/** Older exposure names, accepted in configs and replaced by their current name when validated. */\nconst MCP_EXPOSURE_ALIASES: Readonly<Record<string, McpExposure>> = { \"codemode-deferred\": \"codemode\" };\n\n/**\n * pi's fields of every server entry, beside the shared `mcpServers` fields of pi-mcp. `description`\n * and `timeout` are shared fields, declared again for pi's documentation.\n */\ninterface McpServerConfigBase {\n\t/** Default: `codemode`. */\n\texposure?: McpExposure;\n\t/**\n\t * What the server offers, in a sentence. The `mcp_servers` system prompt section lists the server\n\t * with it, tool search ranks the server's tools by it, and codemode's `describeNamespace()` returns it.\n\t */\n\tdescription?: string;\n\t/**\n\t * Exposure of single tools, overriding `exposure`. Keys are tool names as the server offers them,\n\t * or patterns where `*` matches any characters. An exact name wins over patterns; among patterns\n\t * the first match in the object wins. `hidden` removes tools, so `\"exposure\": \"hidden\"` with\n\t * overrides for a few tools exposes only those.\n\t */\n\ttoolExposure?: Record<string, McpExposure>;\n\t/** Per-request timeout in seconds. Progress notifications from the server reset it. Default: 60. */\n\ttimeout?: number;\n}\n\nexport interface McpStdioServerConfig extends McpStdioServerFields, McpServerConfigBase {\n\t// Shared fields, declared again for pi's documentation.\n\t/** Values may reference environment variables (`${NAME}`) or commands (`!cmd`). */\n\tenv?: Record<string, string>;\n\t/** Relative paths resolve against the session working directory. */\n\tcwd?: string;\n}\n\n/** OAuth client settings for servers that do not support dynamic client registration. */\nexport interface McpOAuthConfig extends McpOAuthFields {\n\t// Shared fields, declared again for pi's documentation.\n\t/** May reference environment variables (`${NAME}`) or commands (`!cmd`). */\n\tclientSecret?: string;\n\t/**\n\t * `client_name` sent with dynamic client registration, for servers that only accept known clients.\n\t * Default: `pi`.\n\t */\n\tclientName?: string;\n\t/**\n\t * How pi identifies itself without `clientId`. `auto` (default): pi's Client ID Metadata Document on\n\t * pi.dev when the authorization server supports it for public clients, otherwise dynamic client\n\t * registration; with `clientName` or a `callbackUrl` other than `/callback` on localhost or 127.0.0.1,\n\t * always dynamic client registration. `cimd`: always the document, and sign-in fails without support.\n\t * `dcr`: always dynamic client registration.\n\t */\n\tclientRegistration?: \"auto\" | \"dcr\" | \"cimd\";\n}\n\n/**\n * Whether pi's Client ID Metadata Documents list a redirect URI for the loopback `callbackUrl`: they list\n * `/callback` on localhost and 127.0.0.1, on any port. Without `callbackUrl`, pi uses such a URI.\n */\nexport function isClientMetadataDocumentCallback(callbackUrl: string | undefined): boolean {\n\tif (callbackUrl === undefined) return true;\n\tconst url = new URL(callbackUrl);\n\treturn url.hostname !== \"[::1]\" && url.pathname === \"/callback\";\n}\n\nexport interface McpHttpServerConfig extends McpHttpServerFields, McpServerConfigBase {\n\t// `headers` is shared, declared again for pi's documentation; `oauth` narrows to pi's documented type.\n\t/** Values may reference environment variables (`${NAME}`) or commands (`!cmd`). */\n\theaders?: Record<string, string>;\n\toauth?: McpOAuthConfig;\n\t/**\n\t * Send the token of a pi provider (`/login <provider>`) instead of using OAuth. Not allowed in project\n\t * `mcp.json` files, and requires https except on loopback hosts, since it sends the credential to `url`.\n\t */\n\tauth?: { provider: string };\n}\n\nexport type McpServerConfig = McpStdioServerConfig | McpHttpServerConfig;\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isExposure(value: unknown): value is McpExposure {\n\treturn typeof value === \"string\" && MCP_EXPOSURES.includes(value);\n}\n\n/** The exposure an alias stands for; other values are returned unchanged. */\nfunction resolveExposureAlias(value: unknown): unknown {\n\treturn typeof value === \"string\" ? (MCP_EXPOSURE_ALIASES[value] ?? value) : value;\n}\n\n/** A copy of the server entry with exposure aliases replaced by their current names. */\nfunction resolveExposureAliases(value: Record<string, unknown>): Record<string, unknown> {\n\tconst { exposure, toolExposure } = value;\n\tconst resolved: Record<string, unknown> = { ...value };\n\tif (exposure !== undefined) resolved.exposure = resolveExposureAlias(exposure);\n\tif (isRecord(toolExposure)) {\n\t\tresolved.toolExposure = Object.fromEntries(\n\t\t\tObject.entries(toolExposure).map(([tool, entry]) => [tool, resolveExposureAlias(entry)]),\n\t\t);\n\t}\n\treturn resolved;\n}\n\n/** Exposure of one tool of a server: its `toolExposure` entry, else the server's `exposure`. */\nexport function getMcpToolExposure(config: McpServerConfig, toolName: string): McpExposure {\n\tconst overrides = config.toolExposure ?? {};\n\tconst exact = overrides[toolName];\n\tif (exact !== undefined) return exact;\n\tfor (const [pattern, exposure] of Object.entries(overrides)) {\n\t\tif (pattern.includes(\"*\") && toolPatternRegExp(pattern).test(toolName)) return exposure;\n\t}\n\treturn config.exposure ?? \"codemode\";\n}\n\n/** Checks `exposure` and `toolExposure`, after aliases were resolved. Returns an error message. */\nfunction checkExposures(entry: Record<string, unknown>): string | undefined {\n\tconst { exposure, toolExposure } = entry;\n\tconst exposures = MCP_EXPOSURES.map((value) => `\"${value}\"`).join(\", \");\n\tif (exposure !== undefined && !isExposure(exposure)) return `exposure must be one of ${exposures}`;\n\tif (toolExposure !== undefined) {\n\t\tif (!isRecord(toolExposure)) return \"toolExposure must map tool names to exposures\";\n\t\tfor (const [tool, value] of Object.entries(toolExposure)) {\n\t\t\tif (!isExposure(value)) return `toolExposure \"${tool}\" must be one of ${exposures}`;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nconst LOOPBACK_HOSTS = [\"localhost\", \"127.0.0.1\", \"[::1]\"];\n\n/** Checks `auth` of an HTTP server, which sends a provider's credential to `url`. Returns an error message. */\nfunction checkAuth(auth: unknown, url: string): string | undefined {\n\tif (auth === undefined) return undefined;\n\tif (!isRecord(auth) || typeof auth.provider !== \"string\" || !auth.provider) {\n\t\treturn \"auth.provider must be a provider name\";\n\t}\n\tconst parsed = new URL(url);\n\tif (parsed.protocol !== \"https:\" && !LOOPBACK_HOSTS.includes(parsed.hostname)) {\n\t\treturn \"auth requires an https URL, or http on localhost, 127.0.0.1, or [::1]\";\n\t}\n\treturn undefined;\n}\n\n/**\n * Validate one server entry of the `mcpServers` shape: pi-mcp's shared fields and pi's own. Returns a\n * copy of the config with exposure aliases resolved, or an error message.\n */\nexport function validateMcpServerConfig(name: string, raw: unknown): McpServerConfig | string {\n\tconst result = validateMcpServerFields(name, isRecord(raw) ? resolveExposureAliases(raw) : raw, {\n\t\tcheckMetadataDocumentCallback: (callbackUrl) =>\n\t\t\tisClientMetadataDocumentCallback(callbackUrl)\n\t\t\t\t? undefined\n\t\t\t\t: 'oauth.clientRegistration \"cimd\" requires oauth.callbackUrl on localhost or 127.0.0.1 with path /callback',\n\t});\n\tif (result.kind === \"invalid\") return result.error;\n\tconst error =\n\t\tcheckExposures(result.config) ??\n\t\t(result.kind === \"http\" ? checkAuth(result.config.auth, result.config.url) : undefined);\n\tif (error) return `server \"${name}\": ${error}`;\n\t// The cast holds because pi's fields were checked above, which the types cannot express.\n\treturn result.config as McpServerConfig;\n}\n\n/** A server an extension registered with `pi.registerMcpServer()`. */\nexport interface RegisteredMcpServer {\n\tname: string;\n\tconfig: McpServerConfig;\n\t/** Path of the extension that registered the server. */\n\textensionPath: string;\n}\n\n/** Servers registered by the extensions of one runtime. */\nexport class McpServerRegistry {\n\tprivate readonly servers = new Map<string, RegisteredMcpServer>();\n\tprivate changeListener: (() => void) | undefined;\n\n\t/** Register or replace a server. The caller checks ownership. */\n\tregister(server: RegisteredMcpServer): void {\n\t\tthis.servers.set(server.name, server);\n\t\tthis.changeListener?.();\n\t}\n\n\t/** Remove a server registered by `extensionPath`. Servers of other extensions are left alone. */\n\tunregister(name: string, extensionPath: string): void {\n\t\tif (this.servers.get(name)?.extensionPath !== extensionPath) return;\n\t\tthis.servers.delete(name);\n\t\tthis.changeListener?.();\n\t}\n\n\tget(name: string): RegisteredMcpServer | undefined {\n\t\treturn this.servers.get(name);\n\t}\n\n\t/** Copies of the registered servers, in registration order. */\n\tlist(): RegisteredMcpServer[] {\n\t\treturn [...this.servers.values()].map((server) => ({ ...server, config: structuredClone(server.config) }));\n\t}\n\n\t/** Called after every change. The runner sets it when it binds, to emit `mcp_servers_change`. */\n\tsetChangeListener(listener: (() => void) | undefined): void {\n\t\tthis.changeListener = listener;\n\t}\n}\n"]}
|