@herbertgao/pi-extensions 2026.8.14 → 2026.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -13
- package/THIRD_PARTY_NOTICES.md +26 -1
- package/node_modules/@czottmann/pi-automode/CHANGELOG.md +8 -1
- package/node_modules/@czottmann/pi-automode/README.md +4 -0
- package/node_modules/@czottmann/pi-automode/extensions/auto-mode/classifier.ts +71 -9
- package/node_modules/@czottmann/pi-automode/package.json +1 -1
- package/node_modules/@herbertgao/pi-bark/LICENSE +21 -0
- package/node_modules/@herbertgao/pi-bark/README.md +44 -0
- package/node_modules/@herbertgao/pi-bark/assets/pi-icon.png +0 -0
- package/node_modules/@herbertgao/pi-bark/package.json +53 -0
- package/node_modules/@herbertgao/pi-bark/src/index.ts +178 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/config.ts +20 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +46 -3
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/interaction.ts +55 -17
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/packets.ts +6 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/scroll.ts +5 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/result.ts +34 -30
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +3 -3
- package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +2 -2
- package/node_modules/@narumitw/pi-btw/README.md +129 -88
- package/node_modules/@narumitw/pi-btw/dist/index.ts +283 -59
- package/node_modules/@narumitw/pi-btw/dist/index.ts.map +3 -3
- package/node_modules/@narumitw/pi-btw/package.json +5 -8
- package/node_modules/@narumitw/pi-btw/src/btw.ts +31 -26
- package/node_modules/@narumitw/pi-btw/src/fullscreen-ui.ts +264 -24
- package/node_modules/@narumitw/pi-btw/src/menu.ts +34 -2
- package/node_modules/@narumitw/pi-btw/src/settings.ts +16 -0
- package/node_modules/@narumitw/pi-btw/src/text.ts +18 -0
- package/node_modules/@narumitw/pi-btw/src/transcript-pager.ts +5 -16
- package/node_modules/@narumitw/pi-caffeinate/LICENSE +21 -0
- package/node_modules/@narumitw/pi-caffeinate/README.md +224 -0
- package/node_modules/@narumitw/pi-caffeinate/dist/index.ts +1112 -0
- package/node_modules/@narumitw/pi-caffeinate/dist/index.ts.map +7 -0
- package/node_modules/@narumitw/pi-caffeinate/package.json +53 -0
- package/node_modules/@narumitw/pi-caffeinate/src/caffeinate.ts +811 -0
- package/node_modules/@narumitw/pi-caffeinate/src/dbus-inhibit.ts +153 -0
- package/node_modules/@narumitw/pi-caffeinate/src/index.ts +1 -0
- package/node_modules/@narumitw/pi-caffeinate/src/inhibitor-process.ts +43 -0
- package/node_modules/@narumitw/pi-caffeinate/src/inhibitors.ts +167 -0
- package/node_modules/@narumitw/pi-caffeinate/src/settings.ts +202 -0
- package/node_modules/@tifan/pi-handoff/README.md +39 -13
- package/node_modules/@tifan/pi-handoff/package.json +2 -2
- package/node_modules/@tifan/pi-handoff/src/index.ts +166 -5
- package/node_modules/@tifan/pi-recap/README.md +1 -1
- package/node_modules/@tifan/pi-recap/package.json +2 -2
- package/node_modules/@tifan/pi-recap/src/index.ts +15 -0
- package/node_modules/@tifan/pi-rename/README.md +42 -21
- package/node_modules/@tifan/pi-rename/package.json +1 -1
- package/node_modules/@tifan/pi-rename/src/index.ts +62 -11
- package/node_modules/@tifan/pi-rename/src/language.ts +18 -0
- package/node_modules/@tifan/pi-rename/src/models.ts +69 -13
- package/node_modules/@tifan/pi-rename/src/naming.ts +36 -7
- package/node_modules/@tifan/pi-rename/src/sanitize.ts +22 -14
- package/node_modules/pi-lens/CHANGELOG.md +320 -0
- package/node_modules/pi-lens/config/dependency-cruiser-eager-allowlist.json +79 -0
- package/node_modules/pi-lens/dist/clients/actionable-warnings-logger.js +16 -1
- package/node_modules/pi-lens/dist/clients/ast-grep-client.js +13 -6
- package/node_modules/pi-lens/dist/clients/availability-probe-flight.js +12 -0
- package/node_modules/pi-lens/dist/clients/biome-client.js +7 -0
- package/node_modules/pi-lens/dist/clients/blocker-freshness.js +20 -0
- package/node_modules/pi-lens/dist/clients/bounded-telemetry.js +56 -19
- package/node_modules/pi-lens/dist/clients/build-identity.js +95 -0
- package/node_modules/pi-lens/dist/clients/bus-publish.js +3 -0
- package/node_modules/pi-lens/dist/clients/cache/rule-cache.js +2 -1
- package/node_modules/pi-lens/dist/clients/cache-observability.js +2 -1
- package/node_modules/pi-lens/dist/clients/cascade-logger.js +15 -1
- package/node_modules/pi-lens/dist/clients/dead-code-client.js +14 -11
- package/node_modules/pi-lens/dist/clients/degradation-ledger.js +56 -4
- package/node_modules/pi-lens/dist/clients/demoted-finding-render.js +14 -0
- package/node_modules/pi-lens/dist/clients/dependency-checker.js +20 -3
- package/node_modules/pi-lens/dist/clients/deps/minimatch.js +1 -1
- package/node_modules/pi-lens/dist/clients/dispatch/collect-later-tier.js +39 -0
- package/node_modules/pi-lens/dist/clients/dispatch/dispatcher.js +150 -9
- package/node_modules/pi-lens/dist/clients/dispatch/fact-store.js +231 -9
- package/node_modules/pi-lens/dist/clients/dispatch/integration.js +205 -100
- package/node_modules/pi-lens/dist/clients/dispatch/pending-runner-findings.js +87 -0
- package/node_modules/pi-lens/dist/clients/dispatch/plan.js +21 -5
- package/node_modules/pi-lens/dist/clients/dispatch/runners/ast-grep-napi.js +174 -55
- package/node_modules/pi-lens/dist/clients/dispatch/runners/eslint.js +5 -1
- package/node_modules/pi-lens/dist/clients/dispatch/runners/helm-lint.js +16 -3
- package/node_modules/pi-lens/dist/clients/dispatch/runners/helm-render.js +54 -9
- package/node_modules/pi-lens/dist/clients/dispatch/runners/index.js +1 -3
- package/node_modules/pi-lens/dist/clients/dispatch/runners/lsp.js +37 -1
- package/node_modules/pi-lens/dist/clients/dispatch/runners/markdownlint.js +4 -1
- package/node_modules/pi-lens/dist/clients/dispatch/runners/oxlint.js +11 -4
- package/node_modules/pi-lens/dist/clients/dispatch/runners/psscriptanalyzer.js +4 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/rust-clippy.js +8 -3
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/runner-helpers.js +76 -25
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/spawn-outcome.js +4 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/tool-failure.js +19 -7
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/toolchain-availability.js +7 -13
- package/node_modules/pi-lens/dist/clients/dispatch/runners/yaml-rule-parser.js +51 -17
- package/node_modules/pi-lens/dist/clients/event-loop-monitor.js +66 -1
- package/node_modules/pi-lens/dist/clients/file-utils.js +157 -7
- package/node_modules/pi-lens/dist/clients/finding-delivery-gate.js +5 -0
- package/node_modules/pi-lens/dist/clients/formatters.js +28 -3
- package/node_modules/pi-lens/dist/clients/git-guard.js +197 -47
- package/node_modules/pi-lens/dist/clients/git-tracked-ignore.js +32 -1
- package/node_modules/pi-lens/dist/clients/govulncheck-client.js +5 -1
- package/node_modules/pi-lens/dist/clients/gzip-stage-write.js +7 -0
- package/node_modules/pi-lens/dist/clients/installer/index.js +131 -34
- package/node_modules/pi-lens/dist/clients/installer/managed-tool-refresh.js +3 -1
- package/node_modules/pi-lens/dist/clients/instance-reaper.js +4 -13
- package/node_modules/pi-lens/dist/clients/instance-registry-lock.js +145 -0
- package/node_modules/pi-lens/dist/clients/instance-registry.js +432 -122
- package/node_modules/pi-lens/dist/clients/jscpd-client.js +6 -1
- package/node_modules/pi-lens/dist/clients/language-profile.js +4 -2
- package/node_modules/pi-lens/dist/clients/latency-logger.js +19 -1
- package/node_modules/pi-lens/dist/clients/lens-flag-registry.js +8 -0
- package/node_modules/pi-lens/dist/clients/lens-map.js +3 -1
- package/node_modules/pi-lens/dist/clients/lsp/cascade-tier.js +4 -0
- package/node_modules/pi-lens/dist/clients/lsp/client.js +516 -31
- package/node_modules/pi-lens/dist/clients/lsp/config.js +25 -2
- package/node_modules/pi-lens/dist/clients/lsp/diagnostic-binding.js +9 -4
- package/node_modules/pi-lens/dist/clients/lsp/index.js +509 -182
- package/node_modules/pi-lens/dist/clients/lsp/jvm-runtime.js +5 -0
- package/node_modules/pi-lens/dist/clients/lsp/launch.js +36 -8
- package/node_modules/pi-lens/dist/clients/lsp/pending-aux-coverage.js +116 -4
- package/node_modules/pi-lens/dist/clients/lsp/server.js +142 -13
- package/node_modules/pi-lens/dist/clients/lsp/session-roots.js +99 -0
- package/node_modules/pi-lens/dist/clients/lsp/workspace-diagnostics-cache.js +16 -6
- package/node_modules/pi-lens/dist/clients/lsp/workspace-sweep-hold.js +32 -23
- package/node_modules/pi-lens/dist/clients/lsp-mutation.js +16 -2
- package/node_modules/pi-lens/dist/clients/mcp/analyze.js +12 -6
- package/node_modules/pi-lens/dist/clients/mcp/session.js +14 -1
- package/node_modules/pi-lens/dist/clients/memory-sampler.js +23 -1
- package/node_modules/pi-lens/dist/clients/message-end-attribution.js +30 -0
- package/node_modules/pi-lens/dist/clients/metrics-history.js +21 -4
- package/node_modules/pi-lens/dist/clients/opaque-mutation-scan.js +232 -18
- package/node_modules/pi-lens/dist/clients/package-manager.js +6 -18
- package/node_modules/pi-lens/dist/clients/path-keyed-map.js +14 -1
- package/node_modules/pi-lens/dist/clients/path-utils.js +32 -0
- package/node_modules/pi-lens/dist/clients/pipeline.js +0 -8
- package/node_modules/pi-lens/dist/clients/process-singletons.js +210 -0
- package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/madge.js +2 -1
- package/node_modules/pi-lens/dist/clients/project-diagnostics/scanner.js +10 -4
- package/node_modules/pi-lens/dist/clients/project-snapshot.js +33 -11
- package/node_modules/pi-lens/dist/clients/read-guard-logger.js +24 -2
- package/node_modules/pi-lens/dist/clients/read-guard.js +74 -7
- package/node_modules/pi-lens/dist/clients/recent-touches.js +17 -5
- package/node_modules/pi-lens/dist/clients/review-graph/builder.js +639 -62
- package/node_modules/pi-lens/dist/clients/review-graph/tsconfig-paths.js +5 -1
- package/node_modules/pi-lens/dist/clients/review-graph-logger.js +21 -1
- package/node_modules/pi-lens/dist/clients/runtime-coordinator.js +68 -0
- package/node_modules/pi-lens/dist/clients/runtime-session.js +30 -12
- package/node_modules/pi-lens/dist/clients/runtime-tool-call.js +15 -0
- package/node_modules/pi-lens/dist/clients/runtime-tool-result.js +106 -7
- package/node_modules/pi-lens/dist/clients/runtime-turn.js +242 -27
- package/node_modules/pi-lens/dist/clients/safe-spawn.js +158 -18
- package/node_modules/pi-lens/dist/clients/security-scan-client.js +48 -17
- package/node_modules/pi-lens/dist/clients/session-lifecycle.js +238 -42
- package/node_modules/pi-lens/dist/clients/sg-runner.js +27 -15
- package/node_modules/pi-lens/dist/clients/shared-checkout-guard.js +338 -0
- package/node_modules/pi-lens/dist/clients/spawn-output-cap.js +37 -0
- package/node_modules/pi-lens/dist/clients/spawn-timeout-cooldown.js +15 -1
- package/node_modules/pi-lens/dist/clients/startup-scan.js +6 -7
- package/node_modules/pi-lens/dist/clients/startup-timing.js +69 -4
- package/node_modules/pi-lens/dist/clients/string-utils.js +20 -0
- package/node_modules/pi-lens/dist/clients/test-runner-client.js +419 -88
- package/node_modules/pi-lens/dist/clients/tool-policy.js +1 -1
- package/node_modules/pi-lens/dist/clients/tree-sitter-client.js +11 -5
- package/node_modules/pi-lens/dist/clients/tree-sitter-logger.js +17 -1
- package/node_modules/pi-lens/dist/clients/warm-attach.js +8 -10
- package/node_modules/pi-lens/dist/clients/word-index-logger.js +13 -1
- package/node_modules/pi-lens/dist/clients/word-index-store.js +448 -0
- package/node_modules/pi-lens/dist/clients/word-index.js +582 -104
- package/node_modules/pi-lens/dist/clients/workspace-topology.js +17 -0
- package/node_modules/pi-lens/dist/clients/zizmor-config.js +26 -6
- package/node_modules/pi-lens/dist/index.js +11243 -6651
- package/node_modules/pi-lens/dist/mcp/build-staleness.js +8 -7
- package/node_modules/pi-lens/dist/mcp/cli.js +3 -1
- package/node_modules/pi-lens/dist/mcp/server.js +6 -1
- package/node_modules/pi-lens/dist/tools/lens-diagnostics.js +4 -0
- package/node_modules/pi-lens/dist/tools/lsp-diagnostics.js +14 -5
- package/node_modules/pi-lens/dist/tools/lsp-navigation.js +3 -1
- package/node_modules/pi-lens/docs/agent-guide.md +4 -2
- package/node_modules/pi-lens/docs/ast-grep_rules_catalog.md +41 -10
- package/node_modules/pi-lens/docs/astplayground.md +26 -17
- package/node_modules/pi-lens/package.json +5 -1
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/c-no-malloc-free-test.yml +20 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/cpp-no-malloc-free-test.yml +25 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/cpp-no-printf-test.yml +19 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/go-no-fmt-println-test.yml +19 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/go-no-panic-in-lib-test.yml +17 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/go-no-underscore-func-name-test.yml +18 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/go-prefer-errors-is-test.yml +15 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/go-prefer-string-builder-test.yml +21 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/hyphenated-svg-attribute-test.yml +11 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-no-lateinit-test.yml +17 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-no-nullable-boolean-test.yml +15 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-no-println-test.yml +19 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-no-unnecessary-let-test.yml +7 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-no-unsafe-cast-test.yml +7 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-no-var-test.yml +7 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-prefer-data-class-test.yml +25 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-prefer-is-empty-test.yml +11 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-important-test.yml +21 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-raw-types-test.yml +30 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-string-concat-in-loop-test.yml +100 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-system-out-println-test.yml +7 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/prefer-string-is-empty-test.yml +7 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/python-optional-type-test.yml +9 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/reducible-list-comprehension-test.yml +11 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/ruby-symbol-to-proc-candidate-test.yml +10 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/rust-no-chars-enumerate-test.yml +7 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/c-no-malloc-free.yml +39 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/cpp-no-malloc-free.yml +45 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/cpp-no-printf.yml +41 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/go-no-fmt-println.yml +43 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/go-no-panic-in-lib.yml +41 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/go-no-underscore-func-name.yml +35 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/go-prefer-errors-is.yml +40 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/go-prefer-string-builder.yml +43 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/hyphenated-svg-attribute.yml +32 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-no-lateinit.yml +37 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-no-nullable-boolean.yml +33 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-no-println.yml +42 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-no-unnecessary-let.yml +28 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-no-unsafe-cast.yml +28 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-no-var.yml +35 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-prefer-data-class.yml +66 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-prefer-is-empty.yml +35 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-important.yml +21 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-raw-types.yml +33 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-string-concat-in-loop.yml +90 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-system-out-println.yml +16 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/prefer-string-is-empty.yml +11 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/python-optional-type.yml +22 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/reducible-list-comprehension.yml +29 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/ruby-symbol-to-proc-candidate.yml +25 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/rust-no-chars-enumerate.yml +19 -0
- package/node_modules/pi-mcp-adapter/CHANGELOG.md +42 -0
- package/node_modules/pi-mcp-adapter/README.md +15 -15
- package/node_modules/pi-mcp-adapter/commands.ts +59 -22
- package/node_modules/pi-mcp-adapter/config.ts +18 -4
- package/node_modules/pi-mcp-adapter/direct-tools.ts +26 -6
- package/node_modules/pi-mcp-adapter/dist/config.d.ts +4 -0
- package/node_modules/pi-mcp-adapter/dist/config.js +13 -4
- package/node_modules/pi-mcp-adapter/dist/config.js.map +1 -1
- package/node_modules/pi-mcp-adapter/dist/types.d.ts +12 -4
- package/node_modules/pi-mcp-adapter/dist/types.js.map +1 -1
- package/node_modules/pi-mcp-adapter/error-signal.ts +15 -4
- package/node_modules/pi-mcp-adapter/errors.ts +141 -0
- package/node_modules/pi-mcp-adapter/host-html-template.ts +58 -5
- package/node_modules/pi-mcp-adapter/index.ts +2 -3
- package/node_modules/pi-mcp-adapter/init.ts +5 -0
- package/node_modules/pi-mcp-adapter/mcp-auth-flow.ts +105 -32
- package/node_modules/pi-mcp-adapter/mcp-panel.ts +30 -9
- package/node_modules/pi-mcp-adapter/mcp-setup-panel.ts +66 -28
- package/node_modules/pi-mcp-adapter/mcp-status.ts +2 -0
- package/node_modules/pi-mcp-adapter/package.json +2 -1
- package/node_modules/pi-mcp-adapter/proxy-modes.ts +88 -25
- package/node_modules/pi-mcp-adapter/sandbox-proxy-template.ts +217 -0
- package/node_modules/pi-mcp-adapter/server-manager.ts +343 -6
- package/node_modules/pi-mcp-adapter/skills/mcp-scripting/SKILL.md +1 -0
- package/node_modules/pi-mcp-adapter/types.ts +19 -4
- package/node_modules/pi-mcp-adapter/ui-resource-handler.ts +18 -2
- package/node_modules/pi-mcp-adapter/ui-server.ts +179 -54
- package/node_modules/pi-mcp-adapter/ui-session.ts +28 -8
- package/node_modules/pi-web-access/CHANGELOG.md +20 -0
- package/node_modules/pi-web-access/README.md +15 -2
- package/node_modules/pi-web-access/extract.ts +57 -12
- package/node_modules/pi-web-access/github-extract.ts +47 -3
- package/node_modules/pi-web-access/index.ts +1 -1
- package/node_modules/pi-web-access/package.json +1 -1
- package/node_modules/pi-web-access/page-query.ts +61 -8
- package/package.json +21 -17
- package/node_modules/@tifan/pi-titlebar-spinner/README.md +0 -24
- package/node_modules/@tifan/pi-titlebar-spinner/package.json +0 -39
- package/node_modules/@tifan/pi-titlebar-spinner/src/index.ts +0 -49
|
@@ -3,6 +3,8 @@ import type { UiHostContext, UiResourceContent, UiResourceCsp } from "./types.ts
|
|
|
3
3
|
// Use locally bundled AppBridge to avoid CDN Zod bundling issues
|
|
4
4
|
const DEFAULT_APP_BRIDGE_MODULE_URL = "/app-bridge.bundle.js";
|
|
5
5
|
const APP_SANDBOX = "allow-scripts allow-forms allow-modals allow-popups allow-downloads";
|
|
6
|
+
const APP_PROXY_SANDBOX = `${APP_SANDBOX} allow-same-origin`;
|
|
7
|
+
const APP_INNER_SANDBOX = APP_PROXY_SANDBOX;
|
|
6
8
|
|
|
7
9
|
export interface HostHtmlTemplateInput {
|
|
8
10
|
sessionToken: string;
|
|
@@ -16,6 +18,7 @@ export interface HostHtmlTemplateInput {
|
|
|
16
18
|
cacheToolConsent: boolean;
|
|
17
19
|
hostContext?: UiHostContext;
|
|
18
20
|
appBridgeModuleUrl?: string;
|
|
21
|
+
sandboxProxyUrl: string;
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
export function buildHostHtmlTemplate(input: HostHtmlTemplateInput): string {
|
|
@@ -31,6 +34,9 @@ export function buildHostHtmlTemplate(input: HostHtmlTemplateInput): string {
|
|
|
31
34
|
const requireToolConsent = safeInlineJSON(input.requireToolConsent);
|
|
32
35
|
const cacheToolConsent = safeInlineJSON(input.cacheToolConsent);
|
|
33
36
|
const moduleUrl = safeInlineJSON(input.appBridgeModuleUrl ?? DEFAULT_APP_BRIDGE_MODULE_URL);
|
|
37
|
+
const sandboxProxyUrl = safeInlineJSON(input.sandboxProxyUrl);
|
|
38
|
+
const resourceCsp = safeInlineJSON(input.resource.meta.csp);
|
|
39
|
+
const resourcePermissions = safeInlineJSON(input.resource.meta.permissions);
|
|
34
40
|
|
|
35
41
|
return `<!doctype html>
|
|
36
42
|
<html lang="en">
|
|
@@ -112,7 +118,7 @@ export function buildHostHtmlTemplate(input: HostHtmlTemplateInput): string {
|
|
|
112
118
|
</div>
|
|
113
119
|
</header>
|
|
114
120
|
<main>
|
|
115
|
-
<iframe id="mcp-app" sandbox="${
|
|
121
|
+
<iframe id="mcp-app" sandbox="${APP_PROXY_SANDBOX}" referrerpolicy="no-referrer"></iframe>
|
|
116
122
|
</main>
|
|
117
123
|
<div class="overlay" id="error-overlay">
|
|
118
124
|
<div class="panel">
|
|
@@ -138,6 +144,10 @@ export function buildHostHtmlTemplate(input: HostHtmlTemplateInput): string {
|
|
|
138
144
|
const ALLOW_ATTRIBUTE = ${allowAttribute};
|
|
139
145
|
const REQUIRE_TOOL_CONSENT = ${requireToolConsent};
|
|
140
146
|
const CACHE_TOOL_CONSENT = ${cacheToolConsent};
|
|
147
|
+
const SANDBOX_PROXY_URL = ${sandboxProxyUrl};
|
|
148
|
+
const RESOURCE_CSP = ${resourceCsp};
|
|
149
|
+
const RESOURCE_PERMISSIONS = ${resourcePermissions};
|
|
150
|
+
const INNER_SANDBOX = ${safeInlineJSON(APP_INNER_SANDBOX)};
|
|
141
151
|
const STREAM_CONTEXT_KEY = "pi-mcp-adapter/stream";
|
|
142
152
|
const STREAM_PATCH_METHOD = "notifications/pi-mcp-adapter/ui-result-patch";
|
|
143
153
|
|
|
@@ -148,6 +158,7 @@ export function buildHostHtmlTemplate(input: HostHtmlTemplateInput): string {
|
|
|
148
158
|
const errorOverlay = document.getElementById("error-overlay");
|
|
149
159
|
const completionOverlay = document.getElementById("completion-overlay");
|
|
150
160
|
const errorMessage = document.getElementById("error-message");
|
|
161
|
+
const sandboxProxyOrigin = new URL(SANDBOX_PROXY_URL).origin;
|
|
151
162
|
|
|
152
163
|
document.getElementById("server-name").textContent = SERVER_NAME;
|
|
153
164
|
document.getElementById("tool-name").textContent = TOOL_NAME;
|
|
@@ -205,10 +216,41 @@ export function buildHostHtmlTemplate(input: HostHtmlTemplateInput): string {
|
|
|
205
216
|
const bridge = new AppBridge(
|
|
206
217
|
null,
|
|
207
218
|
{ name: "pi", version: "1.0.0" },
|
|
208
|
-
{
|
|
219
|
+
{
|
|
220
|
+
serverTools: {},
|
|
221
|
+
openLinks: {},
|
|
222
|
+
logging: {},
|
|
223
|
+
updateModelContext: {},
|
|
224
|
+
message: {},
|
|
225
|
+
sandbox: {
|
|
226
|
+
...(RESOURCE_CSP ? { csp: RESOURCE_CSP } : {}),
|
|
227
|
+
...(RESOURCE_PERMISSIONS ? { permissions: RESOURCE_PERMISSIONS } : {}),
|
|
228
|
+
},
|
|
229
|
+
},
|
|
209
230
|
{ hostContext: HOST_CONTEXT }
|
|
210
231
|
);
|
|
211
232
|
|
|
233
|
+
let sandboxResourceSent = false;
|
|
234
|
+
bridge.onsandboxready = async () => {
|
|
235
|
+
if (sandboxResourceSent) return;
|
|
236
|
+
sandboxResourceSent = true;
|
|
237
|
+
try {
|
|
238
|
+
const response = await fetch("/ui-app?resource=" + encodeURIComponent(UI_RESOURCE_TOKEN), {
|
|
239
|
+
headers: { Accept: "text/html" },
|
|
240
|
+
});
|
|
241
|
+
if (!response.ok) throw new Error("UI resource request failed: HTTP " + response.status);
|
|
242
|
+
const html = await response.text();
|
|
243
|
+
await bridge.sendSandboxResourceReady({
|
|
244
|
+
html,
|
|
245
|
+
sandbox: INNER_SANDBOX,
|
|
246
|
+
...(RESOURCE_CSP ? { csp: RESOURCE_CSP } : {}),
|
|
247
|
+
...(RESOURCE_PERMISSIONS ? { permissions: RESOURCE_PERMISSIONS } : {}),
|
|
248
|
+
});
|
|
249
|
+
} catch (error) {
|
|
250
|
+
showError("Failed to load MCP App resource: " + String(error));
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
|
|
212
254
|
bridge.oncalltool = async (params) => {
|
|
213
255
|
if (!consentGranted) {
|
|
214
256
|
const accepted = window.confirm("Allow this UI to call server tools for this session?");
|
|
@@ -240,7 +282,7 @@ export function buildHostHtmlTemplate(input: HostHtmlTemplateInput): string {
|
|
|
240
282
|
// Also listen for raw postMessage events with custom types (notify, prompt, intent, etc.)
|
|
241
283
|
// These bypass the AppBridge protocol but are used by some MCP UI implementations
|
|
242
284
|
window.addEventListener("message", async (event) => {
|
|
243
|
-
if (event.source !== iframe.contentWindow) return;
|
|
285
|
+
if (event.source !== iframe.contentWindow || event.origin !== sandboxProxyOrigin) return;
|
|
244
286
|
const data = event.data;
|
|
245
287
|
if (!data || typeof data !== "object") return;
|
|
246
288
|
|
|
@@ -304,6 +346,12 @@ export function buildHostHtmlTemplate(input: HostHtmlTemplateInput): string {
|
|
|
304
346
|
}
|
|
305
347
|
|
|
306
348
|
// Connect bridge BEFORE loading iframe to ensure we're listening when the app sends ui/initialize
|
|
349
|
+
const sandboxMessageGuard = (event) => {
|
|
350
|
+
if (event.source === iframe.contentWindow && event.origin !== sandboxProxyOrigin) {
|
|
351
|
+
event.stopImmediatePropagation();
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
window.addEventListener("message", sandboxMessageGuard, true);
|
|
307
355
|
try {
|
|
308
356
|
const transport = new PostMessageTransport(iframe.contentWindow, iframe.contentWindow);
|
|
309
357
|
await bridge.connect(transport);
|
|
@@ -315,7 +363,7 @@ export function buildHostHtmlTemplate(input: HostHtmlTemplateInput): string {
|
|
|
315
363
|
const iframeLoaded = new Promise((resolve) => {
|
|
316
364
|
iframe.onload = resolve;
|
|
317
365
|
});
|
|
318
|
-
iframe.src =
|
|
366
|
+
iframe.src = SANDBOX_PROXY_URL;
|
|
319
367
|
await iframeLoaded;
|
|
320
368
|
|
|
321
369
|
const eventSource = new EventSource("/events?session=" + encodeURIComponent(SESSION_TOKEN));
|
|
@@ -340,6 +388,9 @@ export function buildHostHtmlTemplate(input: HostHtmlTemplateInput): string {
|
|
|
340
388
|
showError("Failed to forward cancellation: " + String(error));
|
|
341
389
|
}
|
|
342
390
|
});
|
|
391
|
+
eventSource.addEventListener("resource-updated", () => {
|
|
392
|
+
setStatus("Resource updated on the server. Reopen this UI to load the latest version.");
|
|
393
|
+
});
|
|
343
394
|
eventSource.addEventListener("result-patch", async (event) => {
|
|
344
395
|
try {
|
|
345
396
|
await bridge.notification({
|
|
@@ -443,7 +494,9 @@ function sanitizeCspDomains(domains: unknown): string[] {
|
|
|
443
494
|
}
|
|
444
495
|
|
|
445
496
|
function safeInlineJSON(value: unknown): string {
|
|
446
|
-
|
|
497
|
+
const json = JSON.stringify(value);
|
|
498
|
+
if (json === undefined) return "undefined";
|
|
499
|
+
return json
|
|
447
500
|
.replace(/</g, "\\u003c")
|
|
448
501
|
.replace(/>/g, "\\u003e")
|
|
449
502
|
.replace(/&/g, "\\u0026")
|
|
@@ -590,7 +590,7 @@ function installMcpAdapter(pi: ExtensionAPI, options: McpAdapterOptions) {
|
|
|
590
590
|
initPromise = null;
|
|
591
591
|
if (earlyConfig.settings?.freezeDirectTools === true) {
|
|
592
592
|
directToolsFrozen = true;
|
|
593
|
-
logger.info("MCP: direct tools frozen after initial sync —
|
|
593
|
+
logger.info("MCP: direct tools frozen after initial sync — metadata can refresh without rebuilding the active tool surface");
|
|
594
594
|
}
|
|
595
595
|
}).catch(async err => {
|
|
596
596
|
if (!owner.isActive() || generation !== lifecycleGeneration) {
|
|
@@ -817,7 +817,6 @@ function installMcpAdapter(pi: ExtensionAPI, options: McpAdapterOptions) {
|
|
|
817
817
|
case "reconnect":
|
|
818
818
|
commandOwner?.throwIfInactive();
|
|
819
819
|
await reconnectServers(state, commandCtx, targetServer);
|
|
820
|
-
if (directToolsFrozen) syncToolSurface(commandCtx);
|
|
821
820
|
break;
|
|
822
821
|
case "tools":
|
|
823
822
|
await showTools(state, commandCtx);
|
|
@@ -1168,7 +1167,7 @@ function installMcpAdapter(pi: ExtensionAPI, options: McpAdapterOptions) {
|
|
|
1168
1167
|
}
|
|
1169
1168
|
if (params.connect) {
|
|
1170
1169
|
const result = await executeConnect(state, params.connect, signal);
|
|
1171
|
-
syncToolSurface(_ctx as ExtensionContext);
|
|
1170
|
+
if (!directToolsFrozen) syncToolSurface(_ctx as ExtensionContext);
|
|
1172
1171
|
return result;
|
|
1173
1172
|
}
|
|
1174
1173
|
if (params.describe) {
|
|
@@ -215,6 +215,10 @@ export async function initializeMcp(
|
|
|
215
215
|
notifyToolMetadataUpdated(state, serverName, reason);
|
|
216
216
|
updateStatusBar(state);
|
|
217
217
|
});
|
|
218
|
+
manager.setListenStateChangedListener?.(() => {
|
|
219
|
+
if (!owner.isActive()) return;
|
|
220
|
+
updateStatusBar(state);
|
|
221
|
+
});
|
|
218
222
|
owner.addCleanup(() => lifecycle.gracefulShutdown());
|
|
219
223
|
owner.addCleanup(() => {
|
|
220
224
|
if (state.uiServer) {
|
|
@@ -641,6 +645,7 @@ export async function lazyConnect(state: McpExtensionState, serverName: string,
|
|
|
641
645
|
return false;
|
|
642
646
|
}
|
|
643
647
|
if (connection?.status === "connected") {
|
|
648
|
+
await state.manager.ensureListen?.(serverName, connection);
|
|
644
649
|
updateServerMetadata(state, serverName);
|
|
645
650
|
markKeepAliveAfterConnect(state, serverName);
|
|
646
651
|
return true;
|
|
@@ -75,6 +75,8 @@ type PendingAuth = {
|
|
|
75
75
|
authProvider: McpOAuthProvider
|
|
76
76
|
serverUrl: string
|
|
77
77
|
authorizationUrl: string
|
|
78
|
+
manualRedirect: boolean
|
|
79
|
+
manualCompletionController?: AbortController
|
|
78
80
|
discovery: AuthDiscovery
|
|
79
81
|
authStorageOptions: AuthStorageOptions
|
|
80
82
|
}
|
|
@@ -307,7 +309,11 @@ async function probeAuthDiscovery(serverUrl: string, definition?: ServerEntry, s
|
|
|
307
309
|
}
|
|
308
310
|
}
|
|
309
311
|
|
|
310
|
-
|
|
312
|
+
type OAuthRedirectTarget =
|
|
313
|
+
| { mode: "local"; port: number; callbackHost: string; callbackPath: string }
|
|
314
|
+
| { mode: "manual" }
|
|
315
|
+
|
|
316
|
+
function parseOAuthRedirectUri(redirectUri: string): OAuthRedirectTarget {
|
|
311
317
|
let url: URL
|
|
312
318
|
try {
|
|
313
319
|
url = new URL(redirectUri)
|
|
@@ -315,12 +321,6 @@ function parseOAuthRedirectUri(redirectUri: string): { port: number; callbackHos
|
|
|
315
321
|
throw new Error(`Invalid OAuth redirectUri: ${redirectUri}`, { cause: error })
|
|
316
322
|
}
|
|
317
323
|
|
|
318
|
-
const hostname = url.hostname.toLowerCase()
|
|
319
|
-
const isLocalhost = hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || hostname === "::1"
|
|
320
|
-
if (url.protocol !== "http:" || !isLocalhost) {
|
|
321
|
-
throw new Error("OAuth redirectUri must be an http:// localhost or loopback URI")
|
|
322
|
-
}
|
|
323
|
-
|
|
324
324
|
if (url.username || url.password) {
|
|
325
325
|
throw new Error("OAuth redirectUri must not include username or password")
|
|
326
326
|
}
|
|
@@ -329,17 +329,32 @@ function parseOAuthRedirectUri(redirectUri: string): { port: number; callbackHos
|
|
|
329
329
|
throw new Error("OAuth redirectUri must not include a fragment")
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
+
const hostname = url.hostname.toLowerCase()
|
|
333
|
+
const isLocalhost = hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || hostname === "::1"
|
|
334
|
+
if (url.port) {
|
|
335
|
+
const parsedPort = Number.parseInt(url.port, 10)
|
|
336
|
+
if (!Number.isInteger(parsedPort) || parsedPort <= 0 || parsedPort > 65535) {
|
|
337
|
+
throw new Error("OAuth redirectUri port must be a positive numeric port")
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if (url.protocol === "https:" && !isLocalhost) {
|
|
341
|
+
return { mode: "manual" }
|
|
342
|
+
}
|
|
343
|
+
if (url.protocol !== "http:" || !isLocalhost) {
|
|
344
|
+
throw new Error("OAuth redirectUri must be an https:// URI or an http:// localhost or loopback URI")
|
|
345
|
+
}
|
|
346
|
+
|
|
332
347
|
if (!url.port) {
|
|
333
|
-
throw new Error("OAuth redirectUri must include an explicit numeric port")
|
|
348
|
+
throw new Error("OAuth localhost redirectUri must include an explicit numeric port")
|
|
334
349
|
}
|
|
335
350
|
|
|
336
351
|
const port = Number.parseInt(url.port, 10)
|
|
337
352
|
if (!Number.isInteger(port) || port <= 0 || port > 65535) {
|
|
338
|
-
throw new Error("OAuth redirectUri must include an explicit numeric port")
|
|
353
|
+
throw new Error("OAuth localhost redirectUri must include an explicit numeric port")
|
|
339
354
|
}
|
|
340
355
|
|
|
341
356
|
const callbackHost = hostname === "[::1]" ? "::1" : hostname
|
|
342
|
-
return { port, callbackHost, callbackPath: url.pathname }
|
|
357
|
+
return { mode: "local", port, callbackHost, callbackPath: url.pathname }
|
|
343
358
|
}
|
|
344
359
|
|
|
345
360
|
/**
|
|
@@ -393,25 +408,30 @@ export async function startAuth(
|
|
|
393
408
|
return { authorizationUrl: existingPendingAuth.authorizationUrl }
|
|
394
409
|
}
|
|
395
410
|
|
|
396
|
-
const
|
|
411
|
+
const redirectTarget = config.redirectUri !== undefined ? parseOAuthRedirectUri(config.redirectUri) : undefined
|
|
412
|
+
const manualRedirect = redirectTarget?.mode === "manual"
|
|
397
413
|
const oauthState = generateState()
|
|
398
414
|
|
|
399
|
-
|
|
400
|
-
await ensureCallbackServer({
|
|
401
|
-
strictPort: Boolean(config.clientId) || config.redirectUri !== undefined,
|
|
402
|
-
oauthState,
|
|
403
|
-
reserveState: true,
|
|
404
|
-
...(redirectCallback ? { port: redirectCallback.port, callbackHost: redirectCallback.callbackHost, callbackPath: redirectCallback.callbackPath } : {}),
|
|
405
|
-
})
|
|
406
|
-
throwIfAborted(signal)
|
|
407
|
-
} catch (error) {
|
|
408
|
-
releaseCallbackServer(oauthState)
|
|
415
|
+
if (!manualRedirect) {
|
|
409
416
|
try {
|
|
410
|
-
await
|
|
411
|
-
|
|
412
|
-
|
|
417
|
+
await ensureCallbackServer({
|
|
418
|
+
strictPort: Boolean(config.clientId) || config.redirectUri !== undefined,
|
|
419
|
+
oauthState,
|
|
420
|
+
reserveState: true,
|
|
421
|
+
...(redirectTarget?.mode === "local"
|
|
422
|
+
? { port: redirectTarget.port, callbackHost: redirectTarget.callbackHost, callbackPath: redirectTarget.callbackPath }
|
|
423
|
+
: {}),
|
|
424
|
+
})
|
|
425
|
+
throwIfAborted(signal)
|
|
426
|
+
} catch (error) {
|
|
427
|
+
releaseCallbackServer(oauthState)
|
|
428
|
+
try {
|
|
429
|
+
await cleanupAndReleaseCallbackServerIfIdle(() => clearOAuthState(serverName, authStorageOptions))
|
|
430
|
+
} catch (cleanupError) {
|
|
431
|
+
throw new AggregateError([error, cleanupError], "OAuth startup cleanup failed")
|
|
432
|
+
}
|
|
433
|
+
throw error
|
|
413
434
|
}
|
|
414
|
-
throw error
|
|
415
435
|
}
|
|
416
436
|
|
|
417
437
|
let capturedUrl: URL | undefined
|
|
@@ -455,7 +475,16 @@ export async function startAuth(
|
|
|
455
475
|
if (!capturedUrl) {
|
|
456
476
|
throw new UnauthorizedError("OAuth authorization URL was not provided")
|
|
457
477
|
}
|
|
458
|
-
await setPendingAuth(runtime, serverName, {
|
|
478
|
+
await setPendingAuth(runtime, serverName, {
|
|
479
|
+
serverName,
|
|
480
|
+
authProvider,
|
|
481
|
+
serverUrl,
|
|
482
|
+
authorizationUrl: capturedUrl.toString(),
|
|
483
|
+
manualRedirect,
|
|
484
|
+
...(manualRedirect ? { manualCompletionController: new AbortController() } : {}),
|
|
485
|
+
discovery,
|
|
486
|
+
authStorageOptions,
|
|
487
|
+
}, oauthState, signal, generation)
|
|
459
488
|
return { authorizationUrl: capturedUrl.toString() }
|
|
460
489
|
} catch (error) {
|
|
461
490
|
authProvider.deactivate()
|
|
@@ -484,7 +513,13 @@ async function setPendingAuth(
|
|
|
484
513
|
state.pendingAuths.set(key, pendingAuth)
|
|
485
514
|
state.pendingAuthStates.set(key, oauthState)
|
|
486
515
|
const cleanupTimer = setTimeout(() => {
|
|
487
|
-
void clearPendingAuthAndReleaseIfIdle(
|
|
516
|
+
void clearPendingAuthAndReleaseIfIdle(
|
|
517
|
+
runtime,
|
|
518
|
+
serverName,
|
|
519
|
+
oauthState,
|
|
520
|
+
pendingAuth.authStorageOptions,
|
|
521
|
+
new Error("OAuth authorization timeout - authorization took too long"),
|
|
522
|
+
).catch(error => {
|
|
488
523
|
console.error(`MCP Auth: Timed-out flow cleanup failed: ${formatTerminalError(error)}`)
|
|
489
524
|
})
|
|
490
525
|
}, MANUAL_AUTH_TIMEOUT_MS)
|
|
@@ -492,7 +527,13 @@ async function setPendingAuth(
|
|
|
492
527
|
state.pendingAuthCleanupTimers.set(key, cleanupTimer)
|
|
493
528
|
}
|
|
494
529
|
|
|
495
|
-
async function clearPendingAuth(
|
|
530
|
+
async function clearPendingAuth(
|
|
531
|
+
runtime: McpOAuthRuntime,
|
|
532
|
+
serverName: string,
|
|
533
|
+
oauthState?: string,
|
|
534
|
+
fallbackStorageOptions: AuthStorageOptions = {},
|
|
535
|
+
reason: Error = new Error("Authorization cancelled"),
|
|
536
|
+
): Promise<void> {
|
|
496
537
|
const state = getRuntimeState(runtime)
|
|
497
538
|
const key = getPendingAuthKey(serverName, fallbackStorageOptions)
|
|
498
539
|
const pendingAuth = state.pendingAuths.get(key)
|
|
@@ -506,6 +547,7 @@ async function clearPendingAuth(runtime: McpOAuthRuntime, serverName: string, oa
|
|
|
506
547
|
state.pendingAuthCleanupTimers.delete(key)
|
|
507
548
|
}
|
|
508
549
|
|
|
550
|
+
pendingAuth?.manualCompletionController?.abort(reason)
|
|
509
551
|
pendingAuth?.authProvider.deactivate()
|
|
510
552
|
state.pendingAuths.delete(key)
|
|
511
553
|
state.pendingAuthStates.delete(key)
|
|
@@ -524,9 +566,10 @@ async function clearPendingAuthAndReleaseIfIdle(
|
|
|
524
566
|
serverName: string,
|
|
525
567
|
oauthState: string | undefined,
|
|
526
568
|
fallbackStorageOptions: AuthStorageOptions = {},
|
|
569
|
+
reason?: Error,
|
|
527
570
|
): Promise<void> {
|
|
528
571
|
await cleanupAndReleaseCallbackServerIfIdle(
|
|
529
|
-
() => clearPendingAuth(runtime, serverName, oauthState, fallbackStorageOptions),
|
|
572
|
+
() => clearPendingAuth(runtime, serverName, oauthState, fallbackStorageOptions, reason),
|
|
530
573
|
)
|
|
531
574
|
}
|
|
532
575
|
|
|
@@ -629,6 +672,19 @@ type AuthorizationResponse = {
|
|
|
629
672
|
source: "callback" | "manual"
|
|
630
673
|
}
|
|
631
674
|
|
|
675
|
+
function waitForManualCompletionCancellation(signal: AbortSignal): Promise<AuthorizationCodeInput> {
|
|
676
|
+
return new Promise((_, reject) => {
|
|
677
|
+
const rejectFromSignal = () => {
|
|
678
|
+
reject(signal.reason instanceof Error ? signal.reason : new Error("Authorization cancelled"))
|
|
679
|
+
}
|
|
680
|
+
if (signal.aborted) {
|
|
681
|
+
rejectFromSignal()
|
|
682
|
+
return
|
|
683
|
+
}
|
|
684
|
+
signal.addEventListener("abort", rejectFromSignal, { once: true })
|
|
685
|
+
})
|
|
686
|
+
}
|
|
687
|
+
|
|
632
688
|
/**
|
|
633
689
|
* Wait for either the localhost callback or a manually pasted redirect URL.
|
|
634
690
|
* The manual input prompt is dismissed as soon as either path finishes.
|
|
@@ -686,7 +742,11 @@ export async function completeAuthFromInput(
|
|
|
686
742
|
throwIfAborted(signal)
|
|
687
743
|
const key = getPendingAuthKey(serverName, fallbackAuthStorageOptions)
|
|
688
744
|
const oauthState = runtimeState.pendingAuthStates.get(key)
|
|
745
|
+
const pendingAuth = runtimeState.pendingAuths.get(key)
|
|
689
746
|
throwIfAborted(signal)
|
|
747
|
+
if (pendingAuth?.manualRedirect && !getSearchParamsFromInput(input.trim())) {
|
|
748
|
+
throw new Error("Paste the full OAuth callback URL, including its code and state parameters")
|
|
749
|
+
}
|
|
690
750
|
const parsed = parseAuthorizationRedirectInput(input, oauthState)
|
|
691
751
|
return completeAuth(serverName, parsed, options)
|
|
692
752
|
}
|
|
@@ -805,15 +865,28 @@ export async function authenticate(
|
|
|
805
865
|
try {
|
|
806
866
|
// Get the state that was already generated and stored in startAuth().
|
|
807
867
|
// Keep this lookup and its abort check inside the cleanup boundary because
|
|
808
|
-
// startAuth
|
|
868
|
+
// startAuth already owns the pending flow at this point.
|
|
809
869
|
oauthState = runtimeState.pendingAuthStates.get(getPendingAuthKey(serverName, authStorageOptions))
|
|
810
870
|
throwIfAborted(signal)
|
|
811
871
|
if (!oauthState) {
|
|
812
872
|
throw new Error("OAuth state not found - this should not happen")
|
|
813
873
|
}
|
|
814
874
|
|
|
815
|
-
|
|
816
|
-
|
|
875
|
+
const pendingAuth = runtimeState.pendingAuths.get(getPendingAuthKey(serverName, authStorageOptions))
|
|
876
|
+
if (!pendingAuth) {
|
|
877
|
+
throw new Error(`No pending OAuth flow for server: ${serverName}`)
|
|
878
|
+
}
|
|
879
|
+
if (pendingAuth.manualRedirect && !options.onAuthorizationInput) {
|
|
880
|
+
throw new Error(
|
|
881
|
+
`OAuth for ${serverName} uses a remote redirect URI. Complete it with auth-start/auth-complete or /mcp-auth.`,
|
|
882
|
+
)
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
// Register the localhost callback before opening the browser. Remote
|
|
886
|
+
// pre-registered callbacks are completed by pasting their full URL.
|
|
887
|
+
const callbackPromise: Promise<AuthorizationCodeInput> = pendingAuth.manualRedirect
|
|
888
|
+
? waitForManualCompletionCancellation(pendingAuth.manualCompletionController!.signal)
|
|
889
|
+
: waitForCallback(oauthState)
|
|
817
890
|
void callbackPromise.catch(() => {})
|
|
818
891
|
|
|
819
892
|
// Open browser. Always surface the URL first so remote/headless users can copy it
|
|
@@ -134,6 +134,8 @@ interface ServerState {
|
|
|
134
134
|
includeTools?: string[];
|
|
135
135
|
excludeTools?: string[];
|
|
136
136
|
exposeResources: boolean;
|
|
137
|
+
disabled: boolean;
|
|
138
|
+
wasDisabled: boolean;
|
|
137
139
|
connectionStatus: ConnectionStatus;
|
|
138
140
|
failureMessage?: string | null;
|
|
139
141
|
tools: ToolState[];
|
|
@@ -243,6 +245,7 @@ class McpPanel {
|
|
|
243
245
|
|
|
244
246
|
const status = callbacks.getConnectionStatus(serverName);
|
|
245
247
|
const failureMessage = callbacks.getFailureMessage?.(serverName) ?? null;
|
|
248
|
+
const serverDisabled = isServerDisabled(definition);
|
|
246
249
|
let directCount = 0;
|
|
247
250
|
let directTokens = 0;
|
|
248
251
|
for (const tool of tools) {
|
|
@@ -258,6 +261,8 @@ class McpPanel {
|
|
|
258
261
|
...(definition.includeTools !== undefined ? { includeTools: definition.includeTools } : {}),
|
|
259
262
|
...(definition.excludeTools !== undefined ? { excludeTools: definition.excludeTools } : {}),
|
|
260
263
|
exposeResources: definition.exposeResources !== false,
|
|
264
|
+
disabled: serverDisabled,
|
|
265
|
+
wasDisabled: serverDisabled,
|
|
261
266
|
connectionStatus: status,
|
|
262
267
|
failureMessage,
|
|
263
268
|
tools,
|
|
@@ -275,7 +280,7 @@ class McpPanel {
|
|
|
275
280
|
if (this.inactivityTimeout) clearTimeout(this.inactivityTimeout);
|
|
276
281
|
this.inactivityTimeout = setTimeout(() => {
|
|
277
282
|
this.cleanup();
|
|
278
|
-
this.done({ cancelled: true, changes: new Map() });
|
|
283
|
+
this.done({ cancelled: true, changes: new Map(), disabledChanges: new Map() });
|
|
279
284
|
}, McpPanel.INACTIVITY_MS);
|
|
280
285
|
}
|
|
281
286
|
|
|
@@ -334,12 +339,16 @@ class McpPanel {
|
|
|
334
339
|
}
|
|
335
340
|
|
|
336
341
|
private updateDirty(): void {
|
|
337
|
-
this.dirty = this.servers.some((s) => s.tools.some((t) => t.isDirect !== t.wasDirect));
|
|
342
|
+
this.dirty = this.servers.some((s) => s.disabled !== s.wasDisabled || s.tools.some((t) => t.isDirect !== t.wasDirect));
|
|
338
343
|
}
|
|
339
344
|
|
|
340
345
|
private buildResult(): McpPanelResult {
|
|
341
346
|
const changes = new Map<string, true | string[] | false>();
|
|
347
|
+
const disabledChanges = new Map<string, boolean>();
|
|
342
348
|
for (const server of this.servers) {
|
|
349
|
+
if (server.disabled !== server.wasDisabled) {
|
|
350
|
+
disabledChanges.set(server.name, server.disabled);
|
|
351
|
+
}
|
|
343
352
|
const changed = server.tools.some((t) => t.isDirect !== t.wasDirect);
|
|
344
353
|
if (!changed) continue;
|
|
345
354
|
const directTools = server.tools.filter((t) => t.isDirect);
|
|
@@ -351,7 +360,7 @@ class McpPanel {
|
|
|
351
360
|
changes.set(server.name, directTools.map((t) => t.name));
|
|
352
361
|
}
|
|
353
362
|
}
|
|
354
|
-
return { changes, cancelled: false };
|
|
363
|
+
return { changes, disabledChanges, cancelled: false };
|
|
355
364
|
}
|
|
356
365
|
|
|
357
366
|
handleInput(data: string): void {
|
|
@@ -367,7 +376,7 @@ class McpPanel {
|
|
|
367
376
|
// Global shortcuts — always work, even during desc search
|
|
368
377
|
if (matchesKey(data, "ctrl+c")) {
|
|
369
378
|
this.cleanup();
|
|
370
|
-
this.done({ cancelled: true, changes: new Map() });
|
|
379
|
+
this.done({ cancelled: true, changes: new Map(), disabledChanges: new Map() });
|
|
371
380
|
return;
|
|
372
381
|
}
|
|
373
382
|
|
|
@@ -424,7 +433,7 @@ class McpPanel {
|
|
|
424
433
|
return;
|
|
425
434
|
}
|
|
426
435
|
this.cleanup();
|
|
427
|
-
this.done({ cancelled: true, changes: new Map() });
|
|
436
|
+
this.done({ cancelled: true, changes: new Map(), disabledChanges: new Map() });
|
|
428
437
|
return;
|
|
429
438
|
}
|
|
430
439
|
|
|
@@ -477,6 +486,17 @@ class McpPanel {
|
|
|
477
486
|
return;
|
|
478
487
|
}
|
|
479
488
|
|
|
489
|
+
if (matchesKey(data, "ctrl+d")) {
|
|
490
|
+
const item = this.visibleItems[this.cursorIndex];
|
|
491
|
+
if (!item || item.type !== "server" || this.authOnly) return;
|
|
492
|
+
const server = this.servers[item.serverIndex];
|
|
493
|
+
if (!server) return;
|
|
494
|
+
server.disabled = !server.disabled;
|
|
495
|
+
this.updateDirty();
|
|
496
|
+
this.tui.requestRender();
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
|
|
480
500
|
if (matchesKey(data, "ctrl+y")) {
|
|
481
501
|
const item = this.visibleItems[this.cursorIndex];
|
|
482
502
|
if (!item) return;
|
|
@@ -632,7 +652,7 @@ class McpPanel {
|
|
|
632
652
|
private handleDiscardInput(data: string): void {
|
|
633
653
|
if (matchesKey(data, "ctrl+c")) {
|
|
634
654
|
this.cleanup();
|
|
635
|
-
this.done({ cancelled: true, changes: new Map() });
|
|
655
|
+
this.done({ cancelled: true, changes: new Map(), disabledChanges: new Map() });
|
|
636
656
|
return;
|
|
637
657
|
}
|
|
638
658
|
if (matchesKey(data, "escape") || data === "n" || data === "N") {
|
|
@@ -642,7 +662,7 @@ class McpPanel {
|
|
|
642
662
|
if (this.keys.selectConfirm(data)) {
|
|
643
663
|
this.cleanup();
|
|
644
664
|
if (this.discardSelected === 0) {
|
|
645
|
-
this.done({ cancelled: true, changes: new Map() });
|
|
665
|
+
this.done({ cancelled: true, changes: new Map(), disabledChanges: new Map() });
|
|
646
666
|
} else {
|
|
647
667
|
this.done(this.buildResult());
|
|
648
668
|
}
|
|
@@ -650,7 +670,7 @@ class McpPanel {
|
|
|
650
670
|
}
|
|
651
671
|
if (data === "y" || data === "Y") {
|
|
652
672
|
this.cleanup();
|
|
653
|
-
this.done({ cancelled: true, changes: new Map() });
|
|
673
|
+
this.done({ cancelled: true, changes: new Map(), disabledChanges: new Map() });
|
|
654
674
|
return;
|
|
655
675
|
}
|
|
656
676
|
if (matchesKey(data, "left") || matchesKey(data, "right") || matchesKey(data, "tab")) {
|
|
@@ -883,6 +903,7 @@ class McpPanel {
|
|
|
883
903
|
italic("⏎") + " expand/auth",
|
|
884
904
|
italic("ctrl+a") + " auth",
|
|
885
905
|
italic("ctrl+r") + " reconnect",
|
|
906
|
+
italic("ctrl+d") + " disable/enable",
|
|
886
907
|
...(this.selectedServerHasFailureMessage() ? [italic("ctrl+y") + " copy error"] : []),
|
|
887
908
|
italic("?") + " desc search",
|
|
888
909
|
...(saveLabel ? [italic(saveLabel) + " save"] : []),
|
|
@@ -995,7 +1016,7 @@ class McpPanel {
|
|
|
995
1016
|
private renderConnectionStatus(server: ServerState): string {
|
|
996
1017
|
const t = this.t;
|
|
997
1018
|
if (this.authInFlight === server.name) return ` ${fg(t.needsAuth, "authenticating")}`;
|
|
998
|
-
if (server.
|
|
1019
|
+
if (server.disabled) return ` ${fg(t.description, "disabled")}`;
|
|
999
1020
|
if (server.connectionStatus === "needs-auth") return ` ${fg(t.needsAuth, "needs auth")}`;
|
|
1000
1021
|
if (server.connectionStatus === "connecting") return ` ${fg(t.needsAuth, "connecting")}`;
|
|
1001
1022
|
if (server.connectionStatus === "failed") return ` ${fg(t.cancel, "failed")}`;
|