@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
|
@@ -1,37 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OAuth sign-in for remote MCP servers.
|
|
2
|
+
* OAuth sign-in for remote MCP servers: pi's credential store and its side of the sign-in.
|
|
3
3
|
*
|
|
4
4
|
* Connections never start a browser flow on their own. They send the stored access token and, after
|
|
5
5
|
* a 401, try the stored refresh token. When that is not possible they fail with
|
|
6
|
-
* `McpOAuthAuthorizationRequiredError`, and the user signs in through `/mcp`, which
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* `McpOAuthAuthorizationRequiredError`, and the user signs in through `/mcp` or `pi mcp login`, which
|
|
7
|
+
* run pi-mcp's sign-in (PKCE, pi's Client ID Metadata Document or dynamic client registration) against
|
|
8
|
+
* a loopback callback or a pasted redirect URL.
|
|
9
9
|
*
|
|
10
10
|
* Credentials live in `<agent-dir>/mcp-auth.json`, keyed by server name and URL.
|
|
11
11
|
*/
|
|
12
|
-
import type
|
|
13
|
-
import { type McpOAuthState, type McpOAuthStateStore, type OAuthChallenge } from "@punch-bot/mcp/oauth";
|
|
12
|
+
import { type McpAuthProvider, type McpOAuthServerStore, type McpOAuthSettings, type McpOAuthState, type OAuthChallenge } from "@punch-bot/mcp/oauth";
|
|
14
13
|
import { type AuthStorageBackend } from "../../core/auth-storage.ts";
|
|
15
|
-
export interface McpOAuthSettings {
|
|
16
|
-
clientId?: string;
|
|
17
|
-
/** Already resolved. */
|
|
18
|
-
clientSecret?: string;
|
|
19
|
-
callbackPort?: number;
|
|
20
|
-
/** Loopback redirect URI; see `McpOAuthConfig.callbackUrl`. */
|
|
21
|
-
callbackUrl?: string;
|
|
22
|
-
/** Scopes to request, separated by spaces. */
|
|
23
|
-
scope?: string;
|
|
24
|
-
/** `client_name` for dynamic client registration. Default: `APP_NAME`. */
|
|
25
|
-
clientName?: string;
|
|
26
|
-
/** See `McpOAuthConfig.clientRegistration`. */
|
|
27
|
-
clientRegistration?: "dcr" | "cimd";
|
|
28
|
-
/** See `McpOAuthConfig.authServerMetadataUrl`. */
|
|
29
|
-
authServerMetadataUrl?: URL;
|
|
30
|
-
}
|
|
31
|
-
export interface McpOAuthServerStore extends McpOAuthStateStore {
|
|
32
|
-
/** Run `fn` while no other process refreshes the server's tokens. */
|
|
33
|
-
withRefreshLock<T>(fn: () => Promise<T>): Promise<T>;
|
|
34
|
-
}
|
|
35
14
|
/** Per-server OAuth state (client registration, tokens, pending PKCE verifier) in `mcp-auth.json`. */
|
|
36
15
|
export declare class McpOAuthCredentialStore {
|
|
37
16
|
private readonly backend;
|
|
@@ -42,6 +21,7 @@ export declare class McpOAuthCredentialStore {
|
|
|
42
21
|
/**
|
|
43
22
|
* A lock file per server. When the process exits, proper-lockfile removes the locks it holds; when
|
|
44
23
|
* it is killed, the lock goes stale because it is no longer renewed, and the next process takes it over.
|
|
24
|
+
* Throws `McpRefreshLockBusyError` when another process holds the lock for the whole wait.
|
|
45
25
|
*/
|
|
46
26
|
private withRefreshLock;
|
|
47
27
|
/** The stored tokens of a server, for noticing sign-ins done by another process. Does not take over legacy state. */
|
|
@@ -50,23 +30,7 @@ export declare class McpOAuthCredentialStore {
|
|
|
50
30
|
remove(name: string, serverUrl: string): boolean;
|
|
51
31
|
private write;
|
|
52
32
|
}
|
|
53
|
-
|
|
54
|
-
/** Resolves when no refresh is running, so shutdown does not drop rotated tokens before they are saved. */
|
|
55
|
-
settled(): Promise<void>;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Auth provider for MCP connections: sends the stored access token and refreshes it when it is about
|
|
59
|
-
* to expire or after a 401. Throws `McpOAuthAuthorizationRequiredError` when the user has to sign in,
|
|
60
|
-
* including when the server asks for more scope (`insufficient_scope`). `onChallenge` receives the
|
|
61
|
-
* server's `WWW-Authenticate` challenge so sign-in can use its resource metadata URL and scope.
|
|
62
|
-
* `settings` is only called when a refresh is needed, so a secret that fails to resolve fails the
|
|
63
|
-
* refresh instead of the whole connection setup.
|
|
64
|
-
*
|
|
65
|
-
* Many servers rotate refresh tokens, so two refreshes with the same refresh token lose the grant.
|
|
66
|
-
* Requests in this process share one refresh, and other processes are kept out by the store's
|
|
67
|
-
* refresh lock, held from reading the tokens to saving new ones. Tokens that changed meanwhile
|
|
68
|
-
* (another process refreshed them, or the user signed in) are used without refreshing.
|
|
69
|
-
*/
|
|
33
|
+
/** pi-mcp's `createMcpAuthProvider` with pi's client identity. */
|
|
70
34
|
export declare function createMcpAuthProvider(options: {
|
|
71
35
|
serverUrl: string;
|
|
72
36
|
store: McpOAuthServerStore;
|
|
@@ -83,17 +47,15 @@ export interface McpSignInPrompt {
|
|
|
83
47
|
*/
|
|
84
48
|
promptForRedirectUrl(signal: AbortSignal): Promise<string | undefined>;
|
|
85
49
|
}
|
|
86
|
-
export declare class McpSignInCancelledError extends Error {
|
|
87
|
-
constructor();
|
|
88
|
-
}
|
|
89
50
|
/**
|
|
90
51
|
* Sign in to an MCP server. Uses the stored refresh token when possible; otherwise runs the browser
|
|
91
|
-
* authorization code flow
|
|
92
|
-
* step with `McpSignInCancelledError`; requests to
|
|
52
|
+
* authorization code flow against a loopback callback or a pasted redirect URL. Tokens are saved to
|
|
53
|
+
* `store`. Aborting `signal` stops the sign-in at any step with `McpSignInCancelledError`; requests to
|
|
54
|
+
* the authorization server are also time-limited.
|
|
93
55
|
*/
|
|
94
56
|
export declare function signInMcpServer(options: {
|
|
95
57
|
serverUrl: string;
|
|
96
|
-
store:
|
|
58
|
+
store: McpOAuthServerStore;
|
|
97
59
|
settings: McpOAuthSettings;
|
|
98
60
|
challenge?: OAuthChallenge;
|
|
99
61
|
prompt: McpSignInPrompt;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../src/extensions/mcp/oauth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../src/extensions/mcp/oauth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH,OAAO,EAIN,KAAK,eAAe,EAEpB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAGlB,KAAK,cAAc,EAGnB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,KAAK,kBAAkB,EAA0B,MAAM,4BAA4B,CAAC;AA8B7F,sGAAsG;AACtG,qBAAa,uBAAuB;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,wGAAwG;IACxG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAE7C,YAAY,OAAO,CAAC,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,MAAM,EAGzD;IAED,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,mBAAmB,CAkB9D;IAED;;;;OAIG;YACW,eAAe;IA8B7B,qHAAqH;IACrH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa,CAAC,QAAQ,CAAC,CAI/D;IAED,+GAA+G;IAC/G,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAS/C;IAED,OAAO,CAAC,KAAK;CAOb;AAiBD,kEAAkE;AAClE,wBAAgB,qBAAqB,CAAC,OAAO,EAAE;IAC9C,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,mBAAmB,CAAC;IAC3B,QAAQ,EAAE,MAAM,gBAAgB,CAAC;IACjC,WAAW,EAAE,CAAC,SAAS,EAAE,cAAc,KAAK,IAAI,CAAC;CACjD,GAAG,eAAe,CAElB;AAED,MAAM,WAAW,eAAe;IAC/B,uEAAuE;IACvE,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IACrC;;;;OAIG;IACH,oBAAoB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CACvE;AAQD;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE;IAC9C,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,mBAAmB,CAAC;IAC3B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyBhB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OAuth sign-in for remote MCP servers.
|
|
2
|
+
* OAuth sign-in for remote MCP servers: pi's credential store and its side of the sign-in.
|
|
3
3
|
*
|
|
4
4
|
* Connections never start a browser flow on their own. They send the stored access token and, after
|
|
5
5
|
* a 401, try the stored refresh token. When that is not possible they fail with
|
|
6
|
-
* `McpOAuthAuthorizationRequiredError`, and the user signs in through `/mcp`, which
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* `McpOAuthAuthorizationRequiredError`, and the user signs in through `/mcp` or `pi mcp login`, which
|
|
7
|
+
* run pi-mcp's sign-in (PKCE, pi's Client ID Metadata Document or dynamic client registration) against
|
|
8
|
+
* a loopback callback or a pasted redirect URL.
|
|
9
9
|
*
|
|
10
10
|
* Credentials live in `<agent-dir>/mcp-auth.json`, keyed by server name and URL.
|
|
11
11
|
*/
|
|
@@ -13,55 +13,17 @@ import { createHash } from "node:crypto";
|
|
|
13
13
|
import { mkdirSync } from "node:fs";
|
|
14
14
|
import { join } from "node:path";
|
|
15
15
|
import { oauthErrorHtml, oauthSuccessHtml } from "@punch-bot/ai/utils/oauth-page";
|
|
16
|
-
import {
|
|
16
|
+
import { mcpNamespace } from "@punch-bot/mcp";
|
|
17
|
+
import { completeMcpSignIn, createMcpAuthProvider as createAuthProvider, listenForLoopbackSignIn, McpRefreshLockBusyError, startMcpSignIn, waitForLoopbackSignIn, } from "@punch-bot/mcp/oauth";
|
|
17
18
|
import lockfile from "proper-lockfile";
|
|
18
19
|
import { APP_NAME, getAgentDir } from "../../config.js";
|
|
19
20
|
import { FileAuthStorageBackend } from "../../core/auth-storage.js";
|
|
20
|
-
import {
|
|
21
|
-
const CALLBACK_HOST = "127.0.0.1";
|
|
22
|
-
const CALLBACK_PATH = "/callback";
|
|
23
|
-
/** Where pi.dev serves pi's Client ID Metadata Documents: `client.json` and `<callback ID>/client.json`. */
|
|
24
|
-
const CLIENT_METADATA_BASE_URL = "https://pi.dev/oauth";
|
|
25
|
-
/** Redirect URI for refreshes when none is stored. Refreshing never redirects the user. */
|
|
26
|
-
const FALLBACK_REDIRECT_URL = `http://${CALLBACK_HOST}${CALLBACK_PATH}`;
|
|
27
|
-
/** Access tokens this close to expiry are refreshed before they are sent. */
|
|
28
|
-
const REFRESH_SKEW_MS = 30_000;
|
|
29
|
-
/**
|
|
30
|
-
* Bounds each request to the authorization server, so an unresponsive one cannot hold the refresh lock,
|
|
31
|
-
* delay shutdown, or keep a sign-in waiting for long.
|
|
32
|
-
*/
|
|
33
|
-
const OAUTH_REQUEST_TIMEOUT_MS = 15_000;
|
|
21
|
+
import { isClientMetadataDocumentCallback } from "../../core/mcp-servers.js";
|
|
34
22
|
/** A refresh lock that its holder stopped renewing (the process was killed) is taken over after this. */
|
|
35
23
|
const REFRESH_LOCK_STALE_MS = 20_000;
|
|
36
24
|
/** How long to wait for another process's refresh: longer than a stale lock lives. */
|
|
37
25
|
const REFRESH_LOCK_WAIT_MS = 25_000;
|
|
38
26
|
const REFRESH_LOCK_RETRY_MS = 100;
|
|
39
|
-
function callbackSettings(settings) {
|
|
40
|
-
const url = new URL(settings.callbackUrl ?? `http://${CALLBACK_HOST}${CALLBACK_PATH}`);
|
|
41
|
-
const address = url.hostname.replace(/^\[|\]$/g, "");
|
|
42
|
-
const port = url.port ? Number(url.port) : settings.callbackPort;
|
|
43
|
-
let fixedRedirectUrl;
|
|
44
|
-
// A configured URI with a port is sent exactly as written, since servers compare it as a string.
|
|
45
|
-
if (url.port)
|
|
46
|
-
fixedRedirectUrl = settings.callbackUrl;
|
|
47
|
-
else if (port !== undefined) {
|
|
48
|
-
url.port = String(port);
|
|
49
|
-
fixedRedirectUrl = url.href;
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
// `localhost` is served on 127.0.0.1; browsers fall back to it when ::1 refuses.
|
|
53
|
-
host: address === "localhost" ? CALLBACK_HOST : address,
|
|
54
|
-
redirectHost: address,
|
|
55
|
-
port,
|
|
56
|
-
path: url.pathname,
|
|
57
|
-
fixedRedirectUrl,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
/** Scopes of both lists, each once. */
|
|
61
|
-
function mergeScopes(...scopes) {
|
|
62
|
-
const merged = [...new Set(scopes.flatMap((scope) => scope?.split(/\s+/).filter(Boolean) ?? []))];
|
|
63
|
-
return merged.length > 0 ? merged.join(" ") : undefined;
|
|
64
|
-
}
|
|
65
27
|
function parseStates(content) {
|
|
66
28
|
if (!content?.trim())
|
|
67
29
|
return {};
|
|
@@ -109,13 +71,15 @@ export class McpOAuthCredentialStore {
|
|
|
109
71
|
/**
|
|
110
72
|
* A lock file per server. When the process exits, proper-lockfile removes the locks it holds; when
|
|
111
73
|
* it is killed, the lock goes stale because it is no longer renewed, and the next process takes it over.
|
|
74
|
+
* Throws `McpRefreshLockBusyError` when another process holds the lock for the whole wait.
|
|
112
75
|
*/
|
|
113
76
|
async withRefreshLock(key, fn) {
|
|
114
77
|
if (!this.lockDir)
|
|
115
78
|
return fn();
|
|
116
79
|
mkdirSync(this.lockDir, { recursive: true, mode: 0o700 });
|
|
117
80
|
const hash = createHash("sha256").update(key).digest("hex").slice(0, 16);
|
|
118
|
-
const release = await lockfile
|
|
81
|
+
const release = await lockfile
|
|
82
|
+
.lock(join(this.lockDir, `mcp-auth-refresh-${hash}`), {
|
|
119
83
|
realpath: false,
|
|
120
84
|
stale: REFRESH_LOCK_STALE_MS,
|
|
121
85
|
retries: {
|
|
@@ -126,6 +90,12 @@ export class McpOAuthCredentialStore {
|
|
|
126
90
|
},
|
|
127
91
|
// The default throws from a timer. A lost lock at worst lets two refreshes overlap.
|
|
128
92
|
onCompromised: () => { },
|
|
93
|
+
})
|
|
94
|
+
.catch((error) => {
|
|
95
|
+
// proper-lockfile reports a lock held by another process as `ELOCKED`.
|
|
96
|
+
if (error instanceof Error && "code" in error && error.code === "ELOCKED")
|
|
97
|
+
throw new McpRefreshLockBusyError();
|
|
98
|
+
throw error;
|
|
129
99
|
});
|
|
130
100
|
try {
|
|
131
101
|
return await fn();
|
|
@@ -160,266 +130,56 @@ export class McpOAuthCredentialStore {
|
|
|
160
130
|
});
|
|
161
131
|
}
|
|
162
132
|
}
|
|
163
|
-
/**
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
function callbackId(serverUrl) {
|
|
175
|
-
const url = new URL(serverUrl);
|
|
176
|
-
url.hash = "";
|
|
177
|
-
return createHash("sha256").update(url.href).digest().subarray(0, 9).toString("base64url");
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* pi's Client ID Metadata Document, for `clientRegistration: "cimd"`, chosen like Codex chooses its own.
|
|
181
|
-
* The configuration ensures the default callback path. Without the `iss` parameter in authorization
|
|
182
|
-
* responses (RFC 9207), the redirect URI and the document are specific to the MCP server, so a response
|
|
183
|
-
* cannot be mixed up with one from another authorization server (RFC 9700 section 4.4.2.2).
|
|
184
|
-
*/
|
|
185
|
-
function clientMetadataDocument(serverUrl, redirectUrl, metadata) {
|
|
186
|
-
if (!metadata?.client_id_metadata_document_supported ||
|
|
187
|
-
!metadata.token_endpoint_auth_methods_supported?.includes("none")) {
|
|
188
|
-
throw new Error('The authorization server does not support Client ID Metadata Documents for public clients; remove oauth.clientRegistration "cimd"');
|
|
189
|
-
}
|
|
190
|
-
if (metadata.authorization_response_iss_parameter_supported) {
|
|
191
|
-
return { url: `${CLIENT_METADATA_BASE_URL}/client.json`, redirectUrl };
|
|
192
|
-
}
|
|
193
|
-
const id = callbackId(serverUrl);
|
|
194
|
-
const redirect = new URL(redirectUrl);
|
|
195
|
-
redirect.pathname = `${CALLBACK_PATH}/${id}`;
|
|
196
|
-
return { url: `${CLIENT_METADATA_BASE_URL}/${id}/client.json`, redirectUrl: redirect.href };
|
|
197
|
-
}
|
|
198
|
-
function createProvider(serverUrl, store, settings, redirectUrl, onRedirect) {
|
|
199
|
-
return new McpOAuthProvider({
|
|
200
|
-
serverUrl,
|
|
201
|
-
redirectUrl,
|
|
202
|
-
clientMetadata: { client_name: settings.clientName ?? APP_NAME },
|
|
203
|
-
clientMetadataDocument: settings.clientRegistration === "cimd"
|
|
204
|
-
? (metadata) => clientMetadataDocument(serverUrl, redirectUrl, metadata)
|
|
205
|
-
: undefined,
|
|
206
|
-
clientId: settings.clientId,
|
|
207
|
-
clientSecret: settings.clientSecret,
|
|
208
|
-
store,
|
|
209
|
-
onRedirect,
|
|
210
|
-
});
|
|
133
|
+
/** pi's Client ID Metadata Documents on pi.dev: `client.json` and `<callback ID>/client.json`. */
|
|
134
|
+
const PI_CLIENT_METADATA_DOCUMENTS = {
|
|
135
|
+
baseUrl: "https://pi.dev/oauth",
|
|
136
|
+
listsRedirectUrl: isClientMetadataDocumentCallback,
|
|
137
|
+
};
|
|
138
|
+
/** pi's client identity for sign-in and refresh. */
|
|
139
|
+
const PI_CLIENT = { clientName: APP_NAME, clientMetadataDocuments: PI_CLIENT_METADATA_DOCUMENTS };
|
|
140
|
+
/** `settings` for pi-mcp: a rebranded build would show up as pi with pi's documents, so `auto` registers. */
|
|
141
|
+
function piSettings(settings) {
|
|
142
|
+
const auto = (settings.clientRegistration ?? "auto") === "auto";
|
|
143
|
+
return auto && APP_NAME !== "pi" ? { ...settings, clientRegistration: "dcr" } : settings;
|
|
211
144
|
}
|
|
212
|
-
/**
|
|
213
|
-
* Auth provider for MCP connections: sends the stored access token and refreshes it when it is about
|
|
214
|
-
* to expire or after a 401. Throws `McpOAuthAuthorizationRequiredError` when the user has to sign in,
|
|
215
|
-
* including when the server asks for more scope (`insufficient_scope`). `onChallenge` receives the
|
|
216
|
-
* server's `WWW-Authenticate` challenge so sign-in can use its resource metadata URL and scope.
|
|
217
|
-
* `settings` is only called when a refresh is needed, so a secret that fails to resolve fails the
|
|
218
|
-
* refresh instead of the whole connection setup.
|
|
219
|
-
*
|
|
220
|
-
* Many servers rotate refresh tokens, so two refreshes with the same refresh token lose the grant.
|
|
221
|
-
* Requests in this process share one refresh, and other processes are kept out by the store's
|
|
222
|
-
* refresh lock, held from reading the tokens to saving new ones. Tokens that changed meanwhile
|
|
223
|
-
* (another process refreshed them, or the user signed in) are used without refreshing.
|
|
224
|
-
*/
|
|
145
|
+
/** pi-mcp's `createMcpAuthProvider` with pi's client identity. */
|
|
225
146
|
export function createMcpAuthProvider(options) {
|
|
226
|
-
|
|
227
|
-
let refreshing;
|
|
228
|
-
/** Replace `staleToken`, the access token that expired or was rejected. */
|
|
229
|
-
const refresh = (staleToken, fetch = globalThis.fetch, challenge) => {
|
|
230
|
-
refreshing ??= store
|
|
231
|
-
.withRefreshLock(async () => {
|
|
232
|
-
const state = await store.load();
|
|
233
|
-
if (state?.tokens?.access_token !== staleToken)
|
|
234
|
-
return;
|
|
235
|
-
if (!state?.tokens?.refresh_token)
|
|
236
|
-
throw new McpOAuthAuthorizationRequiredError();
|
|
237
|
-
const settings = options.settings();
|
|
238
|
-
const redirectUrl = callbackSettings(settings).fixedRedirectUrl ??
|
|
239
|
-
registeredRedirectUrls(state.clientInformation)[0] ??
|
|
240
|
-
FALLBACK_REDIRECT_URL;
|
|
241
|
-
const provider = createProvider(serverUrl, store, settings, redirectUrl, () => { });
|
|
242
|
-
// Refreshes the tokens, or reports that a new sign-in is needed. Not cancellable: a refresh the
|
|
243
|
-
// server answered may have rotated the refresh token, so its answer must be saved.
|
|
244
|
-
const result = await authorizeMcp(provider, {
|
|
245
|
-
serverUrl,
|
|
246
|
-
resourceMetadataUrl: challenge?.resourceMetadataUrl,
|
|
247
|
-
authorizationServerMetadataUrl: settings.authServerMetadataUrl,
|
|
248
|
-
scope: challenge?.scope,
|
|
249
|
-
fetch: timedFetch(fetch),
|
|
250
|
-
});
|
|
251
|
-
if (result === "REDIRECT")
|
|
252
|
-
throw new McpOAuthAuthorizationRequiredError();
|
|
253
|
-
})
|
|
254
|
-
.finally(() => {
|
|
255
|
-
refreshing = undefined;
|
|
256
|
-
});
|
|
257
|
-
return refreshing;
|
|
258
|
-
};
|
|
259
|
-
return {
|
|
260
|
-
token: async () => {
|
|
261
|
-
await refreshing?.catch(() => undefined);
|
|
262
|
-
const state = await store.load();
|
|
263
|
-
const token = state?.tokens?.access_token;
|
|
264
|
-
const expired = state?.tokensExpireAt !== undefined && state.tokensExpireAt - REFRESH_SKEW_MS <= Date.now();
|
|
265
|
-
if (!expired || !state?.tokens?.refresh_token)
|
|
266
|
-
return token;
|
|
267
|
-
// Failures fall through: the request goes out with the old token and a 401 decides what happens.
|
|
268
|
-
await refresh(token).catch(() => undefined);
|
|
269
|
-
return (await store.load())?.tokens?.access_token;
|
|
270
|
-
},
|
|
271
|
-
onUnauthorized: async (context) => {
|
|
272
|
-
const challenge = parseWwwAuthenticate(context.response.headers.get("www-authenticate"));
|
|
273
|
-
options.onChallenge(challenge);
|
|
274
|
-
// A refresh keeps the granted scope, so more scope needs a new sign-in.
|
|
275
|
-
if (challenge.error === "insufficient_scope")
|
|
276
|
-
throw new McpOAuthAuthorizationRequiredError();
|
|
277
|
-
await refresh(context.token, context.fetch, challenge);
|
|
278
|
-
},
|
|
279
|
-
settled: async () => {
|
|
280
|
-
await refreshing?.catch(() => undefined);
|
|
281
|
-
},
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
export class McpSignInCancelledError extends Error {
|
|
285
|
-
constructor() {
|
|
286
|
-
super("Sign-in cancelled");
|
|
287
|
-
this.name = "McpSignInCancelledError";
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
function responseFromRedirectUrl(input, state, redirectUrl) {
|
|
291
|
-
let url;
|
|
292
|
-
try {
|
|
293
|
-
url = new URL(input.trim());
|
|
294
|
-
}
|
|
295
|
-
catch {
|
|
296
|
-
throw new Error("Expected the full redirect URL from the browser address bar");
|
|
297
|
-
}
|
|
298
|
-
// A server-specific redirect URI tells authorization servers apart, so it must match exactly.
|
|
299
|
-
if (url.origin !== redirectUrl.origin || url.pathname !== redirectUrl.pathname) {
|
|
300
|
-
throw new Error("The redirect URL does not match this sign-in's redirect URI");
|
|
301
|
-
}
|
|
302
|
-
const error = url.searchParams.get("error");
|
|
303
|
-
if (error)
|
|
304
|
-
throw new Error(url.searchParams.get("error_description") ?? error);
|
|
305
|
-
if (url.searchParams.get("state") !== state)
|
|
306
|
-
throw new Error("The redirect URL belongs to a different sign-in");
|
|
307
|
-
const code = url.searchParams.get("code");
|
|
308
|
-
if (!code)
|
|
309
|
-
throw new Error("The redirect URL does not contain an authorization code");
|
|
310
|
-
return { code, iss: url.searchParams.get("iss") ?? undefined };
|
|
147
|
+
return createAuthProvider({ ...options, ...PI_CLIENT, settings: () => piSettings(options.settings()) });
|
|
311
148
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
async function waitForAuthorizationResponse(callback, state, redirectUrl, prompt, signal) {
|
|
317
|
-
const controller = new AbortController();
|
|
318
|
-
const promptSignal = signal ? AbortSignal.any([controller.signal, signal]) : controller.signal;
|
|
319
|
-
const fromBrowser = callback.waitForCallback(state, redirectUrl.pathname);
|
|
320
|
-
const fromUser = prompt.promptForRedirectUrl(promptSignal).then((input) => {
|
|
321
|
-
if (!input?.trim())
|
|
322
|
-
throw new McpSignInCancelledError();
|
|
323
|
-
return responseFromRedirectUrl(input, state, redirectUrl);
|
|
324
|
-
});
|
|
325
|
-
try {
|
|
326
|
-
return await Promise.race([fromBrowser, fromUser]);
|
|
327
|
-
}
|
|
328
|
-
finally {
|
|
329
|
-
// The losing side rejects once the prompt is aborted or the callback server closes.
|
|
330
|
-
controller.abort();
|
|
331
|
-
fromBrowser.catch(() => undefined);
|
|
332
|
-
fromUser.catch(() => undefined);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
/** Listen on `port`, or on a free port when it is taken and not `required`. */
|
|
336
|
-
async function listenForCallback(settings, extraPaths, port, required) {
|
|
337
|
-
const options = {
|
|
338
|
-
host: settings.host,
|
|
339
|
-
redirectHost: settings.redirectHost,
|
|
340
|
-
path: settings.path,
|
|
341
|
-
extraPaths,
|
|
342
|
-
renderPage: (page) => page.ok
|
|
343
|
-
? oauthSuccessHtml("Signed in to the MCP server. You may now close this page.")
|
|
344
|
-
: oauthErrorHtml(page.message, page.details),
|
|
345
|
-
};
|
|
346
|
-
try {
|
|
347
|
-
return await OAuthCallbackServer.listen({ ...options, port: port ?? 0 });
|
|
348
|
-
}
|
|
349
|
-
catch (error) {
|
|
350
|
-
if (required || port === undefined)
|
|
351
|
-
throw error;
|
|
352
|
-
return OAuthCallbackServer.listen(options);
|
|
353
|
-
}
|
|
149
|
+
function renderCallbackPage(page) {
|
|
150
|
+
return page.ok
|
|
151
|
+
? oauthSuccessHtml("Signed in to the MCP server. You may now close this page.")
|
|
152
|
+
: oauthErrorHtml(page.message, page.details);
|
|
354
153
|
}
|
|
355
154
|
/**
|
|
356
155
|
* Sign in to an MCP server. Uses the stored refresh token when possible; otherwise runs the browser
|
|
357
|
-
* authorization code flow
|
|
358
|
-
* step with `McpSignInCancelledError`; requests to
|
|
156
|
+
* authorization code flow against a loopback callback or a pasted redirect URL. Tokens are saved to
|
|
157
|
+
* `store`. Aborting `signal` stops the sign-in at any step with `McpSignInCancelledError`; requests to
|
|
158
|
+
* the authorization server are also time-limited.
|
|
359
159
|
*/
|
|
360
160
|
export async function signInMcpServer(options) {
|
|
361
|
-
const { serverUrl, store,
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
const cimd = settings.clientRegistration === "cimd";
|
|
371
|
-
const callback = await listenForCallback(callbackOptions,
|
|
372
|
-
// The redirect URI of a server-specific Client ID Metadata Document.
|
|
373
|
-
cimd ? [`${CALLBACK_PATH}/${callbackId(serverUrl)}`] : [], preferredPort, callbackOptions.port !== undefined);
|
|
374
|
-
const redirectUrl = callbackOptions.fixedRedirectUrl ?? callback.redirectUrl;
|
|
161
|
+
const { serverUrl, store, challenge, prompt, signal } = options;
|
|
162
|
+
const settings = piSettings(options.settings);
|
|
163
|
+
const { callback, redirectUrl } = await listenForLoopbackSignIn({
|
|
164
|
+
serverUrl,
|
|
165
|
+
store,
|
|
166
|
+
settings,
|
|
167
|
+
clientMetadataDocuments: PI_CLIENT_METADATA_DOCUMENTS,
|
|
168
|
+
renderPage: renderCallbackPage,
|
|
169
|
+
});
|
|
375
170
|
try {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
delete next.oauthState;
|
|
380
|
-
// A registered client cannot use another redirect URI, and its tokens belong to it. A Client ID
|
|
381
|
-
// Metadata Document is not stored, so with one, a stored client was registered before and is replaced.
|
|
382
|
-
const keepClient = settings.clientId ||
|
|
383
|
-
(cimd ? !stored.clientInformation : registeredRedirectUrls(stored.clientInformation).includes(redirectUrl));
|
|
384
|
-
if (!keepClient) {
|
|
385
|
-
delete next.clientInformation;
|
|
386
|
-
delete next.tokens;
|
|
387
|
-
delete next.tokensExpireAt;
|
|
388
|
-
}
|
|
389
|
-
await store.save(next);
|
|
390
|
-
}
|
|
391
|
-
let authorizationUrl;
|
|
392
|
-
const provider = createProvider(serverUrl, store, settings, redirectUrl, (url) => {
|
|
393
|
-
authorizationUrl = url;
|
|
394
|
-
});
|
|
395
|
-
const flow = {
|
|
396
|
-
serverUrl,
|
|
397
|
-
fetch: timedFetch(),
|
|
398
|
-
signal,
|
|
399
|
-
resourceMetadataUrl: options.challenge?.resourceMetadataUrl,
|
|
400
|
-
authorizationServerMetadataUrl: settings.authServerMetadataUrl,
|
|
401
|
-
// A server asking for more scope gets it on top of the configured scope and, since the challenge
|
|
402
|
-
// may list only the missing scopes, on top of the scope granted so far.
|
|
403
|
-
scope: mergeScopes(settings.scope, stepUp ? stepUpScope(stored?.tokens?.scope, options.challenge?.scope) : options.challenge?.scope),
|
|
404
|
-
};
|
|
405
|
-
// A refresh keeps the granted scope; a server asking for more needs the browser flow.
|
|
406
|
-
const skipRefresh = stepUp;
|
|
407
|
-
if ((await authorizeMcp(provider, { ...flow, skipRefresh })) === "AUTHORIZED")
|
|
171
|
+
const signIn = { serverUrl, store, settings, redirectUrl, challenge, signal, ...PI_CLIENT };
|
|
172
|
+
const authorization = await startMcpSignIn(signIn);
|
|
173
|
+
if (authorization.kind === "authorized")
|
|
408
174
|
return;
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
await
|
|
417
|
-
}
|
|
418
|
-
catch (error) {
|
|
419
|
-
// Aborted requests fail with the signal's reason; report them as the cancellation they are.
|
|
420
|
-
if (signal?.aborted)
|
|
421
|
-
throw new McpSignInCancelledError();
|
|
422
|
-
throw error;
|
|
175
|
+
prompt.showAuthorizationUrl(new URL(authorization.authorizationUrl));
|
|
176
|
+
const response = await waitForLoopbackSignIn({
|
|
177
|
+
callback,
|
|
178
|
+
authorization,
|
|
179
|
+
promptForRedirectUrl: (promptSignal) => prompt.promptForRedirectUrl(promptSignal),
|
|
180
|
+
signal,
|
|
181
|
+
});
|
|
182
|
+
await completeMcpSignIn({ ...signIn, authorization, response });
|
|
423
183
|
}
|
|
424
184
|
finally {
|
|
425
185
|
await callback.close();
|