@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
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The proxy is served from a different loopback origin than the trusted host.
|
|
3
|
+
* `allow-same-origin` is safe here because this document never contains the
|
|
4
|
+
* host's session capability; provider HTML is loaded into the nested frame.
|
|
5
|
+
*/
|
|
6
|
+
export const SANDBOX_PROXY_SANDBOX =
|
|
7
|
+
"allow-scripts allow-forms allow-modals allow-popups allow-downloads allow-same-origin";
|
|
8
|
+
export const SANDBOX_INNER_SANDBOX = SANDBOX_PROXY_SANDBOX;
|
|
9
|
+
export const SANDBOX_PROXY_PATH = "/sandbox";
|
|
10
|
+
|
|
11
|
+
export interface SandboxProxyTemplateInput {
|
|
12
|
+
parentOrigin: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Build the static document used by the trusted, second-origin sandbox proxy.
|
|
17
|
+
* The only per-session value is the exact origin of the parent host.
|
|
18
|
+
*/
|
|
19
|
+
export function buildSandboxProxyHtml(input: SandboxProxyTemplateInput): string {
|
|
20
|
+
const parentOrigin = safeInlineJSON(input.parentOrigin);
|
|
21
|
+
|
|
22
|
+
return `<!doctype html>
|
|
23
|
+
<html lang="en">
|
|
24
|
+
<head>
|
|
25
|
+
<meta charset="utf-8" />
|
|
26
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
27
|
+
<title>MCP App Sandbox</title>
|
|
28
|
+
<style>
|
|
29
|
+
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: transparent; }
|
|
30
|
+
iframe { display: block; width: 100%; height: 100%; border: 0; }
|
|
31
|
+
</style>
|
|
32
|
+
</head>
|
|
33
|
+
<body>
|
|
34
|
+
<iframe id="mcp-app" title="MCP App" sandbox="${SANDBOX_INNER_SANDBOX}" referrerpolicy="no-referrer"></iframe>
|
|
35
|
+
<script>
|
|
36
|
+
const EXPECTED_PARENT_ORIGIN = ${parentOrigin};
|
|
37
|
+
const SANDBOX_PROXY_READY_METHOD = "ui/notifications/sandbox-proxy-ready";
|
|
38
|
+
const SANDBOX_RESOURCE_READY_METHOD = "ui/notifications/sandbox-resource-ready";
|
|
39
|
+
const INNER_SANDBOX = ${safeInlineJSON(SANDBOX_INNER_SANDBOX)};
|
|
40
|
+
const MAX_PENDING_MESSAGES = 64;
|
|
41
|
+
const innerFrame = document.getElementById("mcp-app");
|
|
42
|
+
const pendingToInner = [];
|
|
43
|
+
let innerReady = false;
|
|
44
|
+
|
|
45
|
+
const isObject = (value) => value !== null && typeof value === "object";
|
|
46
|
+
const isMessageFromParent = (event) =>
|
|
47
|
+
event.source === window.parent && event.origin === EXPECTED_PARENT_ORIGIN;
|
|
48
|
+
const isMessageFromInner = (event) =>
|
|
49
|
+
event.source === innerFrame.contentWindow && event.origin === window.location.origin;
|
|
50
|
+
|
|
51
|
+
const postToParent = (data) => {
|
|
52
|
+
window.parent.postMessage(data, EXPECTED_PARENT_ORIGIN);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const postToInner = (data) => {
|
|
56
|
+
if (!innerReady || !innerFrame.contentWindow) {
|
|
57
|
+
if (pendingToInner.length < MAX_PENDING_MESSAGES) pendingToInner.push(data);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
innerFrame.contentWindow.postMessage(data, window.location.origin);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const flushPendingMessages = () => {
|
|
64
|
+
if (!innerFrame.contentWindow) return;
|
|
65
|
+
innerReady = true;
|
|
66
|
+
for (const data of pendingToInner.splice(0)) {
|
|
67
|
+
innerFrame.contentWindow.postMessage(data, window.location.origin);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const sanitizeDomains = (domains) => {
|
|
72
|
+
if (!Array.isArray(domains)) return [];
|
|
73
|
+
return [...new Set(domains.filter((domain) =>
|
|
74
|
+
typeof domain === "string" &&
|
|
75
|
+
domain.length > 0 &&
|
|
76
|
+
/^[\\x21-\\x7E]+$/.test(domain) &&
|
|
77
|
+
!/[;'\"]/.test(domain),
|
|
78
|
+
))];
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const toDirective = (name, trustedSources, domains) =>
|
|
82
|
+
name + " " + [...new Set([...trustedSources, ...domains])].join(" ");
|
|
83
|
+
|
|
84
|
+
const buildResourceCsp = (csp) => {
|
|
85
|
+
const resourceDomains = sanitizeDomains(csp?.resourceDomains);
|
|
86
|
+
const connectDomains = sanitizeDomains(csp?.connectDomains);
|
|
87
|
+
const frameDomains = sanitizeDomains(csp?.frameDomains);
|
|
88
|
+
const baseUriDomains = sanitizeDomains(csp?.baseUriDomains);
|
|
89
|
+
return [
|
|
90
|
+
"default-src 'none'",
|
|
91
|
+
"sandbox " + INNER_SANDBOX,
|
|
92
|
+
toDirective("script-src", ["'self'", "'unsafe-inline'"], resourceDomains),
|
|
93
|
+
toDirective("style-src", ["'self'", "'unsafe-inline'"], resourceDomains),
|
|
94
|
+
toDirective("font-src", ["'self'"], resourceDomains),
|
|
95
|
+
toDirective("img-src", ["'self'", "data:"], resourceDomains),
|
|
96
|
+
toDirective("media-src", ["'self'", "data:"], resourceDomains),
|
|
97
|
+
connectDomains.length > 0 ? "connect-src " + connectDomains.join(" ") : "connect-src 'none'",
|
|
98
|
+
frameDomains.length > 0 ? "frame-src " + frameDomains.join(" ") : "frame-src 'none'",
|
|
99
|
+
"worker-src 'none'",
|
|
100
|
+
"object-src 'none'",
|
|
101
|
+
baseUriDomains.length > 0 ? "base-uri " + baseUriDomains.join(" ") : "base-uri 'self'",
|
|
102
|
+
].join("; ");
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const escapeAttribute = (value) => value
|
|
106
|
+
.replace(/&/g, "&")
|
|
107
|
+
.replace(/\"/g, """)
|
|
108
|
+
.replace(/</g, "<")
|
|
109
|
+
.replace(/>/g, ">");
|
|
110
|
+
|
|
111
|
+
const injectCsp = (html, csp) => {
|
|
112
|
+
const meta = '<meta http-equiv="Content-Security-Policy" content="' + escapeAttribute(csp) + '">';
|
|
113
|
+
const head = html.match(/<head(?:\\s[^>]*)?>/i);
|
|
114
|
+
if (head && head.index !== undefined) {
|
|
115
|
+
const end = head.index + head[0].length;
|
|
116
|
+
return html.slice(0, end) + meta + html.slice(end);
|
|
117
|
+
}
|
|
118
|
+
return meta + html;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const safeSandbox = (requested) => {
|
|
122
|
+
const requestedTokens = typeof requested === "string" ? requested.split(/\\s+/) : [];
|
|
123
|
+
const allowedTokens = new Set(INNER_SANDBOX.split(" "));
|
|
124
|
+
const tokens = requestedTokens.filter((token) => allowedTokens.has(token));
|
|
125
|
+
// Provider HTML needs both script execution and a real proxy-origin
|
|
126
|
+
// storage context. Never accept popup escape or top-navigation tokens.
|
|
127
|
+
return [...new Set([
|
|
128
|
+
"allow-scripts",
|
|
129
|
+
"allow-same-origin",
|
|
130
|
+
...tokens,
|
|
131
|
+
])].filter((token) => allowedTokens.has(token)).join(" ");
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const buildAllowAttribute = (permissions) => {
|
|
135
|
+
if (!isObject(permissions) || Array.isArray(permissions)) return "";
|
|
136
|
+
const allowed = [];
|
|
137
|
+
if (permissions.camera) allowed.push("camera");
|
|
138
|
+
if (permissions.microphone) allowed.push("microphone");
|
|
139
|
+
if (permissions.geolocation) allowed.push("geolocation");
|
|
140
|
+
if (permissions.clipboardWrite) allowed.push("clipboard-write");
|
|
141
|
+
return allowed.join("; ");
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const loadResource = (params) => {
|
|
145
|
+
if (!isObject(params) || typeof params.html !== "string" || !innerFrame.contentDocument) return;
|
|
146
|
+
innerFrame.setAttribute("sandbox", safeSandbox(params.sandbox));
|
|
147
|
+
const allow = buildAllowAttribute(params.permissions);
|
|
148
|
+
if (allow) innerFrame.setAttribute("allow", allow);
|
|
149
|
+
else innerFrame.removeAttribute("allow");
|
|
150
|
+
innerReady = false;
|
|
151
|
+
const document = innerFrame.contentDocument;
|
|
152
|
+
document.open();
|
|
153
|
+
document.write(injectCsp(params.html, buildResourceCsp(params.csp)));
|
|
154
|
+
document.close();
|
|
155
|
+
flushPendingMessages();
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
window.addEventListener("message", (event) => {
|
|
159
|
+
if (isMessageFromParent(event)) {
|
|
160
|
+
const data = event.data;
|
|
161
|
+
if (!isObject(data)) return;
|
|
162
|
+
if (data.method === SANDBOX_RESOURCE_READY_METHOD) {
|
|
163
|
+
loadResource(data.params);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (data.method === SANDBOX_PROXY_READY_METHOD) return;
|
|
167
|
+
if (typeof data.method === "string" && data.method.startsWith("ui/notifications/sandbox-")) return;
|
|
168
|
+
postToInner(data);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (!isMessageFromInner(event)) return;
|
|
173
|
+
const data = event.data;
|
|
174
|
+
if (!isObject(data)) return;
|
|
175
|
+
if (typeof data.method === "string" && data.method.startsWith("ui/notifications/sandbox-")) return;
|
|
176
|
+
postToParent(data);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
postToParent({
|
|
180
|
+
jsonrpc: "2.0",
|
|
181
|
+
method: SANDBOX_PROXY_READY_METHOD,
|
|
182
|
+
params: {},
|
|
183
|
+
});
|
|
184
|
+
</script>
|
|
185
|
+
</body>
|
|
186
|
+
</html>`;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* CSP for the proxy document itself. It contains only the inline relay script
|
|
191
|
+
* and a nested about:blank frame; provider policy is applied separately after
|
|
192
|
+
* the host sends the resource-ready notification.
|
|
193
|
+
*/
|
|
194
|
+
export function buildSandboxProxyCsp(): string {
|
|
195
|
+
return [
|
|
196
|
+
"default-src 'none'",
|
|
197
|
+
"script-src 'unsafe-inline'",
|
|
198
|
+
"style-src 'unsafe-inline'",
|
|
199
|
+
"frame-src 'self'",
|
|
200
|
+
"connect-src 'none'",
|
|
201
|
+
"worker-src 'none'",
|
|
202
|
+
"object-src 'none'",
|
|
203
|
+
"base-uri 'none'",
|
|
204
|
+
`sandbox ${SANDBOX_PROXY_SANDBOX}`,
|
|
205
|
+
].join("; ");
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function safeInlineJSON(value: unknown): string {
|
|
209
|
+
const json = JSON.stringify(value);
|
|
210
|
+
if (json === undefined) return "undefined";
|
|
211
|
+
return json
|
|
212
|
+
.replace(/</g, "\\u003c")
|
|
213
|
+
.replace(/>/g, "\\u003e")
|
|
214
|
+
.replace(/&/g, "\\u0026")
|
|
215
|
+
.replace(/\u2028/g, "\\u2028")
|
|
216
|
+
.replace(/\u2029/g, "\\u2029");
|
|
217
|
+
}
|