pi-web-ui 0.116.0 → 0.118.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/CHANGELOG.md +83 -3
- package/README.md +69 -138
- package/README.zh-CN.md +70 -179
- package/README.zh-TW.md +3 -1
- package/bin/device-hub-cli.mjs +163 -36
- package/bin/frp-manager.mjs +4 -80
- package/bin/hub-upgrade.mjs +561 -0
- package/bin/pi-device-hub.mjs +0 -1
- package/bin/pi-web-ui.mjs +184 -504
- package/deploy/nginx-subpath.conf +0 -33
- package/deploy/pi-web-ui.service +0 -20
- package/dist/server/agent-formatters.js +4 -38
- package/dist/server/agent-service-daemon.js +203 -371
- package/dist/server/agent-service.js +1281 -3030
- package/dist/server/approval-audit.js +2 -23
- package/dist/server/approval-default-rules.js +0 -6
- package/dist/server/approval-rules.js +7 -105
- package/dist/server/ask-user-question-tool.js +1 -12
- package/dist/server/atomic-file.js +33 -5
- package/dist/server/attachment-store.js +0 -36
- package/dist/server/attachments.js +3 -112
- package/dist/server/auth-cookie.js +0 -21
- package/dist/server/bash-tool.js +1 -32
- package/dist/server/bg-servers.js +0 -96
- package/dist/server/browser-page-tool.js +11 -62
- package/dist/server/builtin-modules.js +7 -0
- package/dist/server/canvas/canvas-agent-tool.js +58 -47
- package/dist/server/canvas/canvas-cards.js +0 -14
- package/dist/server/canvas/canvas-dispatch.js +7 -4
- package/dist/server/canvas/canvas-orchestrator.js +167 -181
- package/dist/server/canvas/canvas-runtime-messages.js +30 -0
- package/dist/server/canvas/canvas-scheduled-task.js +0 -3
- package/dist/server/canvas/canvas-scheduler.js +5 -7
- package/dist/server/canvas/canvas-store.js +24 -35
- package/dist/server/canvas/canvas-validation.js +17 -14
- package/dist/server/canvas/canvas-workspace.js +42 -114
- package/dist/server/canvas/pstack-skills-data.js +0 -5
- package/dist/server/claim-files-tool.js +1 -15
- package/dist/server/claim-store.js +5 -49
- package/dist/server/client-id-utils.js +0 -16
- package/dist/server/client-state.js +36 -214
- package/dist/server/communicate-tool.js +0 -3
- package/dist/server/compact-context-tool.js +0 -30
- package/dist/server/compacted-history.js +0 -35
- package/dist/server/compaction-instructions.js +0 -13
- package/dist/server/compaction-markers.js +38 -92
- package/dist/server/compaction-state.js +0 -21
- package/dist/server/composer-drafts.js +0 -34
- package/dist/server/context-budget-runner.js +0 -11
- package/dist/server/context-budget.js +1 -70
- package/dist/server/context-evidence.js +0 -14
- package/dist/server/context-usage.js +0 -12
- package/dist/server/control-socket.js +4 -48
- package/dist/server/conversation-communication.js +0 -10
- package/dist/server/conversation-identity.js +0 -1
- package/dist/server/conversation-read-tool.js +0 -58
- package/dist/server/conversation-tool-names.js +0 -1
- package/dist/server/conversation-tool.js +0 -1
- package/dist/server/conversation-touches.js +4 -75
- package/dist/server/dangling-tools.js +142 -68
- package/dist/server/delegate-mode.js +0 -36
- package/dist/server/delegate-task.js +2 -28
- package/dist/server/device-center/approval-summary.js +0 -1
- package/dist/server/device-center/bot-catalog.js +0 -3
- package/dist/server/device-center/bot-execution.js +48 -9
- package/dist/server/device-center/bot-presets.js +0 -1
- package/dist/server/device-center/bots.js +0 -1
- package/dist/server/device-center/collab-service.js +27 -11
- package/dist/server/device-center/collab-tool.js +393 -27
- package/dist/server/device-center/connector.js +128 -48
- package/dist/server/device-center/delivery-authority.js +95 -0
- package/dist/server/device-center/delivery-subject.js +29 -0
- package/dist/server/device-center/desktop-linux.js +3 -15
- package/dist/server/device-center/desktop-native.js +1 -10
- package/dist/server/device-center/desktop-page.js +2 -3
- package/dist/server/device-center/desktop-setup.js +1 -3
- package/dist/server/device-center/desktop.js +1 -7
- package/dist/server/device-center/device-integration.js +452 -208
- package/dist/server/device-center/device-lan-access.js +403 -0
- package/dist/server/device-center/device-lan.js +484 -0
- package/dist/server/device-center/device-portals.js +0 -3
- package/dist/server/device-center/execution-failure.js +0 -2
- package/dist/server/device-center/execution-guides.js +15 -6
- package/dist/server/device-center/execution-instructions.js +0 -1
- package/dist/server/device-center/execution-settings.js +0 -1
- package/dist/server/device-center/execution-system-prompt.js +0 -3
- package/dist/server/device-center/execution-workspace.js +1 -4
- package/dist/server/device-center/executor.js +46 -31
- package/dist/server/device-center/file-sync-paths.js +0 -5
- package/dist/server/device-center/file-sync.js +0 -10
- package/dist/server/device-center/group-context-delta.js +0 -8
- package/dist/server/device-center/group-context-message.js +0 -14
- package/dist/server/device-center/group-context.js +0 -19
- package/dist/server/device-center/group-events.js +0 -2
- package/dist/server/device-center/group-plan-guard.js +1 -35
- package/dist/server/device-center/group-router-runtime.js +182 -0
- package/dist/server/device-center/group-router-worker.js +178 -0
- package/dist/server/device-center/group-router.js +359 -0
- package/dist/server/device-center/hub-auth.js +24 -2
- package/dist/server/device-center/hub-conversations.js +13 -15
- package/dist/server/device-center/hub-deliveries.js +119 -15
- package/dist/server/device-center/hub-integration.js +647 -334
- package/dist/server/device-center/hub-locks.js +1 -5
- package/dist/server/device-center/hub-mobile.js +147 -0
- package/dist/server/device-center/hub-orchestration.js +400 -0
- package/dist/server/device-center/hub-page.js +28 -9
- package/dist/server/device-center/hub-setup.js +23 -7
- package/dist/server/device-center/hub-transaction-log.js +175 -0
- package/dist/server/device-center/hub-upgrade.js +162 -0
- package/dist/server/device-center/hub-webhooks.js +1 -3
- package/dist/server/device-center/hub.js +946 -404
- package/dist/server/device-center/human-interaction.js +1 -4
- package/dist/server/device-center/integration-errors.js +0 -2
- package/dist/server/device-center/integration-verification.js +111 -0
- package/dist/server/device-center/local-hub.js +6 -4
- package/dist/server/device-center/local-publication.js +416 -0
- package/dist/server/device-center/local-verification-job.js +95 -0
- package/dist/server/device-center/local-verification.js +273 -0
- package/dist/server/device-center/local.js +341 -18
- package/dist/server/device-center/main.js +18 -2
- package/dist/server/device-center/mobile-notification-forwarder.js +292 -0
- package/dist/server/device-center/native-desktop/macos.js +0 -1
- package/dist/server/device-center/native-desktop/windows.js +0 -1
- package/dist/server/device-center/partition-log.js +52 -46
- package/dist/server/device-center/path-portal.js +42 -12
- package/dist/server/device-center/publication-journal.js +305 -0
- package/dist/server/device-center/publish-intent.js +374 -0
- package/dist/server/device-center/relay.js +217 -52
- package/dist/server/device-center/report-upload.js +0 -1
- package/dist/server/device-center/runtime.js +419 -52
- package/dist/server/device-center/store.js +223 -65
- package/dist/server/device-center/task-context-budget.js +0 -3
- package/dist/server/device-center/task-error.js +0 -1
- package/dist/server/device-center/task-journal.js +6 -23
- package/dist/server/device-center/task-outcome.js +68 -0
- package/dist/server/device-center/task-plan.js +0 -1
- package/dist/server/device-center/task-progress.js +0 -16
- package/dist/server/device-center/task-recovery.js +569 -227
- package/dist/server/device-center/task-report-outbox.js +0 -4
- package/dist/server/device-center/task-report.js +2 -10
- package/dist/server/device-center/task-scheduler.js +1 -35
- package/dist/server/device-center/task-settlement.js +335 -0
- package/dist/server/device-center/task-state.js +0 -12
- package/dist/server/device-center/task-workspace.js +393 -0
- package/dist/server/device-center/transfer-stream.js +5 -45
- package/dist/server/device-center/transfers.js +2 -10
- package/dist/server/device-center/verification-limits.js +9 -0
- package/dist/server/device-center/work-contract.js +923 -0
- package/dist/server/device-center/work-items.js +317 -0
- package/dist/server/device-center/workspaces.js +0 -1
- package/dist/server/dispatch-domain-handlers.js +202 -29
- package/dist/server/dispatch-plugin-handlers.js +2 -19
- package/dist/server/dsh/dsh-agent-service.js +78 -601
- package/dist/server/dsh/dsh-client.js +7 -111
- package/dist/server/dsh/dsh-market-service.js +4 -25
- package/dist/server/dsh/dsh-serialize.js +0 -49
- package/dist/server/dsh/dsh-sessions.js +0 -37
- package/dist/server/dsh/dsh-usage.js +0 -37
- package/dist/server/dsh/preset-clones.js +1 -65
- package/dist/server/dsh/runtime/custom-prompt.mjs +0 -14
- package/dist/server/dsh/runtime/goal-rpc.mjs +7 -176
- package/dist/server/dsh/runtime/launcher.mjs +2 -53
- package/dist/server/dsh/runtime/override.patch.yml +0 -29
- package/dist/server/dsh/runtime/runtime-root.mjs +0 -54
- package/dist/server/durable/durable-agent-service.js +5 -23
- package/dist/server/durable/durable-driver.js +12 -73
- package/dist/server/durable/durable-event-projector.js +1 -50
- package/dist/server/durable/durable-loader.js +0 -12
- package/dist/server/durable/durable-models.js +11 -80
- package/dist/server/durable/durable-storage.js +1 -17
- package/dist/server/durable/durable-tools.js +2 -20
- package/dist/server/durable/index.js +0 -3
- package/dist/server/edit-soft-tool.js +2 -81
- package/dist/server/engine-capabilities.js +0 -13
- package/dist/server/engine-catalog.js +74 -0
- package/dist/server/engine-cli.js +89 -0
- package/dist/server/engine-probe.js +35 -217
- package/dist/server/ensure-bash.js +2 -28
- package/dist/server/eval-tool.js +1 -50
- package/dist/server/evidence-tool-hooks.js +0 -2
- package/dist/server/file-archives.js +0 -10
- package/dist/server/file-save.js +1 -12
- package/dist/server/file-transfer-routes.js +0 -11
- package/dist/server/files-service.js +18 -271
- package/dist/server/global-loader.js +9 -89
- package/dist/server/goal-evidence.js +1 -35
- package/dist/server/goal-review-gate.js +0 -58
- package/dist/server/goal-service.js +19 -422
- package/dist/server/hashline-engine.js +8 -112
- package/dist/server/host-guard.js +0 -24
- package/dist/server/host-metrics.js +0 -6
- package/dist/server/http-proxy.js +1 -7
- package/dist/server/i18n.js +5 -72
- package/dist/server/icon-svg.js +0 -15
- package/dist/server/index.js +199 -677
- package/dist/server/json-utils.js +0 -12
- package/dist/server/launch-origin.js +0 -44
- package/dist/server/left-panel-running.js +0 -9
- package/dist/server/load-timing.js +1 -4
- package/dist/server/load-tools-tool.js +0 -20
- package/dist/server/locales.js +1 -46
- package/dist/server/lsp-tool.js +13 -126
- package/dist/server/managed.js +0 -48
- package/dist/server/marker-service.js +1 -22
- package/dist/server/markers/builtins/action.js +0 -19
- package/dist/server/markers/builtins/notify.js +1 -9
- package/dist/server/markers/builtins/rename.js +0 -13
- package/dist/server/markers/index.js +0 -3
- package/dist/server/markers/marker.js +0 -13
- package/dist/server/markers/registry.js +0 -3
- package/dist/server/markers/store.js +1 -12
- package/dist/server/market-service.js +7 -43
- package/dist/server/mcp-agent-tool.js +0 -10
- package/dist/server/mcp-bridge.js +6 -138
- package/dist/server/mcp-hot-reload.js +0 -25
- package/dist/server/mcp-manager.js +2 -44
- package/dist/server/mcp-oauth-login.js +0 -2
- package/dist/server/mcp-oauth-ui.js +1 -4
- package/dist/server/mcp-oauth.js +5 -79
- package/dist/server/mcp-project-runtime.js +0 -4
- package/dist/server/message-deletion.js +0 -2
- package/dist/server/message-entry-resolver.js +0 -8
- package/dist/server/message-window.js +0 -71
- package/dist/server/mobile-notification-events.js +16 -0
- package/dist/server/mobile-origin.js +79 -0
- package/dist/server/mobile-push.js +523 -0
- package/dist/server/model-admin.js +19 -358
- package/dist/server/model-enrich.js +0 -19
- package/dist/server/model-resolver.js +2 -61
- package/dist/server/native-cli-discovery.js +115 -0
- package/dist/server/native-cli-model.js +71 -0
- package/dist/server/native-cli-references.js +214 -0
- package/dist/server/native-cli-remote-cleanup.js +58 -0
- package/dist/server/native-cli-remote-files.js +282 -0
- package/dist/server/native-cli-routes.js +68 -0
- package/dist/server/native-cli-runtime.js +1 -0
- package/dist/server/native-cli-session-hooks.js +170 -0
- package/dist/server/native-cli-session.js +585 -0
- package/dist/server/native-cli-state.js +82 -0
- package/dist/server/native-cli.js +210 -0
- package/dist/server/net-guard.js +9 -71
- package/dist/server/office-parse.js +0 -50
- package/dist/server/orphan-manager.js +0 -18
- package/dist/server/patch-bash-process.js +0 -4
- package/dist/server/patch-executable-lookup.js +0 -77
- package/dist/server/patch-node-pty.js +6 -45
- package/dist/server/patch-remote-catalog.js +4 -34
- package/dist/server/patch-tool.js +0 -15
- package/dist/server/payload-limits.js +0 -5
- package/dist/server/pending-question.js +0 -5
- package/dist/server/permission-preset.js +4 -33
- package/dist/server/persona-chain.js +0 -26
- package/dist/server/pkg-info.js +1 -17
- package/dist/server/plan-manager.js +2 -49
- package/dist/server/plan-mode.js +0 -97
- package/dist/server/plan-update-tool.js +1 -15
- package/dist/server/plugin-api-catalog.js +6 -4
- package/dist/server/plugin-assets.js +1 -35
- package/dist/server/plugin-bundled.js +68 -0
- package/dist/server/plugin-catalog-sync.js +0 -37
- package/dist/server/plugin-catalog.js +13 -67
- package/dist/server/plugin-chat-attachments.js +0 -1
- package/dist/server/plugin-conversation-view.js +0 -20
- package/dist/server/plugin-dom.js +1 -23
- package/dist/server/plugin-facilities.js +4 -115
- package/dist/server/plugin-grants.js +2 -90
- package/dist/server/plugin-install-spec.js +0 -43
- package/dist/server/plugin-installer.js +34 -75
- package/dist/server/plugin-llm.js +4 -38
- package/dist/server/plugin-manifest-validate.js +0 -31
- package/dist/server/plugin-permissions.js +1 -24
- package/dist/server/plugin-project.js +7 -129
- package/dist/server/plugin-removal.js +1 -8
- package/dist/server/plugin-schedule.js +1 -38
- package/dist/server/plugin-secrets.js +3 -16
- package/dist/server/plugin-tool-guard.js +1 -28
- package/dist/server/plugin-ui-slots.js +0 -4
- package/dist/server/plugin-updater.js +15 -90
- package/dist/server/plugins.js +71 -619
- package/dist/server/present-files-tool.js +0 -57
- package/dist/server/preset-fields.js +24 -61
- package/dist/server/preset-plugin-dependencies.js +0 -2
- package/dist/server/preset-share.js +4 -172
- package/dist/server/process-utils.js +4 -80
- package/dist/server/prompt-assembler.js +2 -30
- package/dist/server/prompt-base-store.js +0 -47
- package/dist/server/prompt-composer.js +21 -98
- package/dist/server/prompt-templates.js +0 -2
- package/dist/server/protocol-version.js +1 -11
- package/dist/server/protocol.js +0 -5
- package/dist/server/queue-modes.js +0 -3
- package/dist/server/queue-utils.js +0 -40
- package/dist/server/quick-ask-context.js +384 -0
- package/dist/server/quick-ask-settings.js +61 -0
- package/dist/server/quick-ask.js +260 -0
- package/dist/server/read-tool.js +0 -65
- package/dist/server/reasoning-registry.js +1 -29
- package/dist/server/remote-cli-persistence.js +373 -0
- package/dist/server/remote-native-cli.js +78 -0
- package/dist/server/remote-ssh-service.js +481 -190
- package/dist/server/request-context.js +0 -9
- package/dist/server/resolve-global-sdk.js +55 -31
- package/dist/server/sandbox-data.js +0 -1
- package/dist/server/sandbox-engines.js +0 -1
- package/dist/server/sandbox-runtime-gate.js +0 -3
- package/dist/server/sandbox-service.js +0 -41
- package/dist/server/sandbox-tool.js +0 -20
- package/dist/server/schedule-agent-tool.js +2 -31
- package/dist/server/scheduler-tasks.js +32 -56
- package/dist/server/scm-commitmsg.js +0 -53
- package/dist/server/scm.js +3 -48
- package/dist/server/sdk-builtin-extensions.js +2 -29
- package/dist/server/sdk-origin.js +0 -45
- package/dist/server/serialize.js +2 -92
- package/dist/server/server-config.js +0 -11
- package/dist/server/session-branch.js +1 -87
- package/dist/server/session-list-scan.js +215 -0
- package/dist/server/session-open.js +69 -0
- package/dist/server/session-parser.js +4 -54
- package/dist/server/session-scan.js +81 -45
- package/dist/server/session-search.js +0 -56
- package/dist/server/settings-service.js +19 -126
- package/dist/server/setup-config.js +0 -2
- package/dist/server/setup-page.js +0 -9
- package/dist/server/skill-content-filler.js +0 -17
- package/dist/server/skill-discovery.js +5 -92
- package/dist/server/skill-maintenance.js +1 -28
- package/dist/server/skill-tool.js +0 -30
- package/dist/server/slash-commands.js +5 -50
- package/dist/server/soft-cap.js +3 -40
- package/dist/server/startup-banner.js +0 -8
- package/dist/server/subagent-handoff.js +0 -11
- package/dist/server/subagent-helpers.js +2 -17
- package/dist/server/subagent-notify.js +0 -19
- package/dist/server/subagent-security-gate.js +0 -50
- package/dist/server/subagent-task.js +0 -9
- package/dist/server/subagent-templates-hant.js +0 -10
- package/dist/server/subagent-templates.js +3 -103
- package/dist/server/subagents.js +1 -87
- package/dist/server/system-screenshot-windows.js +259 -0
- package/dist/server/system-screenshot.js +77 -0
- package/dist/server/tabs.js +3 -48
- package/dist/server/terminals.js +559 -586
- package/dist/server/text-quote.js +0 -12
- package/dist/server/text-sniff.js +2 -52
- package/dist/server/themes.js +2 -41
- package/dist/server/tool-approval.js +0 -47
- package/dist/server/tool-guards.js +0 -90
- package/dist/server/tool-host-factories.js +1 -16
- package/dist/server/tool-info.js +0 -13
- package/dist/server/tool-manager.js +1 -229
- package/dist/server/tool-overrides.js +1 -46
- package/dist/server/tool-prompt-overrides.js +1 -30
- package/dist/server/tool-prompts.js +0 -14
- package/dist/server/tool-signature.js +0 -25
- package/dist/server/transcript-prepare.js +55 -0
- package/dist/server/tts-routes.js +58 -0
- package/dist/server/tts-service.js +106 -0
- package/dist/server/tts-system.js +160 -0
- package/dist/server/turn-timing.js +0 -1
- package/dist/server/unauthorized-page.js +0 -8
- package/dist/server/universal/driver-base.js +2 -31
- package/dist/server/universal/drivers/claude-code.js +98 -194
- package/dist/server/universal/drivers/codex.js +12 -35
- package/dist/server/universal/drivers/mock-driver.js +1 -11
- package/dist/server/universal/index.js +0 -3
- package/dist/server/universal/session-store.js +4 -21
- package/dist/server/universal/universal-attachments.js +2 -36
- package/dist/server/universal/universal-service.js +5 -24
- package/dist/server/universal/universal-session.js +30 -148
- package/dist/server/universal/universal-types.js +0 -3
- package/dist/server/update-check.js +6 -182
- package/dist/server/uploads.js +4 -43
- package/dist/server/virtual-tui.js +2 -27
- package/dist/server/vision-bridge.js +0 -27
- package/dist/server/wait-subscription-scan.js +13 -115
- package/dist/server/webui-context.js +2 -87
- package/dist/server/workspace-handle.js +373 -0
- package/dist/server/workspace-snapshot.js +7 -113
- package/dist/server/worktree-service.js +2 -53
- package/dist/server/worktree-tool.js +0 -11
- package/dist/server/ws-client-id.js +0 -18
- package/dist/server/ws-pending-queue.js +0 -7
- package/dist/server/ws-unknown-types.js +0 -17
- package/docs/README.md +24 -17
- package/docs/architecture-plugins.md +55 -6
- package/docs/device-center.md +57 -23
- package/docs/device-desktop.md +3 -3
- package/docs/group-orchestration.md +142 -0
- package/docs/hub-upgrade-release-testing.md +46 -0
- package/extensions/webui.ts +3 -74
- package/package.json +9 -6
- package/plugin-sdk/README.md +22 -8
- package/plugin-sdk/client-utils.mjs +0 -7
- package/plugin-sdk/client.d.ts +26 -0
- package/plugin-sdk/client.mjs +52 -0
- package/plugin-sdk/import-check.mjs +4 -51
- package/plugin-sdk/index.d.ts +128 -117
- package/plugin-sdk/index.mjs +2 -687
- package/plugin-sdk/package.json +15 -4
- package/plugin-sdk/ssh-host-trust.mjs +0 -12
- package/plugin-sdk/testing.d.ts +9 -0
- package/plugin-sdk/testing.mjs +511 -0
- package/plugins/catalog.json +52 -4
- package/plugins/superagent/README.md +110 -0
- package/plugins/superagent/client/entry.mjs +21 -0
- package/plugins/superagent/index.mjs +8 -0
- package/plugins/superagent/main.mjs +218 -0
- package/plugins/superagent/manifest.json +15 -0
- package/plugins/superagent/server.mjs +572 -0
- package/plugins/superagent/style.css +167 -0
- package/themes/aetheris.css +1 -31
- package/themes/ayu-light.css +0 -1
- package/themes/bases/flow-base.css +2 -83
- package/themes/bases/obsidian-base.css +2 -37
- package/themes/bases/statusbar-flat-base.css +0 -1
- package/themes/bases/zhujian-base.css +0 -63
- package/themes/bases/zhupi-base.css +0 -64
- package/themes/catppuccin-latte.css +0 -1
- package/themes/catppuccin.css +0 -1
- package/themes/claude-code-dark.css +0 -1
- package/themes/codex.css +0 -1
- package/themes/dark-teal.css +22 -54
- package/themes/everforest-light.css +0 -1
- package/themes/flow-cristallo.css +160 -0
- package/themes/flow-ink.css +160 -0
- package/themes/flow-light.css +1 -10
- package/themes/flow-obsidian.css +160 -0
- package/themes/flow-zurich.css +160 -0
- package/themes/flow.css +1 -9
- package/themes/geist.css +0 -1
- package/themes/gruvbox-light.css +0 -1
- package/themes/kanagawa-lotus.css +0 -1
- package/themes/md-preview.css +1 -2
- package/themes/mist.css +0 -1
- package/themes/nord.css +0 -1
- package/themes/one-dark.css +0 -1
- package/themes/paper.css +0 -1
- package/themes/rose-pine-dawn.css +0 -1
- package/themes/sakura.css +0 -1
- package/themes/solarized-light.css +0 -1
- package/themes/tokyo-night.css +0 -1
- package/themes/translucent.css +4 -35
- package/themes/transparent.css +4 -41
- package/themes/vs-code-dark.css +0 -1
- package/themes/wallpaper-flow.css +3 -17
- package/themes/wallpaper-obsidian.css +1 -4
- package/themes/white.css +0 -1
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/{BgTasksModal-BDoOpj-F.js → BgTasksModal-D-x7kA63.js} +1 -1
- package/web/dist/assets/CanvasStudio-CAWcs9tm.js +1579 -0
- package/web/dist/assets/DeviceCenter-Dc0whRcu.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-BoX7-0h7.js +1 -0
- package/web/dist/assets/DeviceGroups-C_fZMNeK.js +1 -0
- package/web/dist/assets/{Dropdown-C4LIhshN.js → Dropdown-CTgVLUbp.js} +1 -1
- package/web/dist/assets/FilePreview-C6W0PvaK.js +2 -0
- package/web/dist/assets/GlobalSearchModal-HR9LSspC.js +1 -0
- package/web/dist/assets/GroupConversation-C81YjF2C.js +61 -0
- package/web/dist/assets/GroupWorkItems-BIvZtr10.js +1 -0
- package/web/dist/assets/{HintTip-c6d0TJoh.js → HintTip-Da6qc566.js} +1 -1
- package/web/dist/assets/ModelConfigModal-DhSyuIuV.js +2 -0
- package/web/dist/assets/NativeCliPanel-CU1rZmyu.js +5 -0
- package/web/dist/assets/{PiSetupModal-BmMrrgB9.js → PiSetupModal-DZKY5Wiw.js} +1 -1
- package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +1 -0
- package/web/dist/assets/SCMPanel-CuEgzAlO.js +2 -0
- package/web/dist/assets/SettingsModal-Cdu5h29p.js +33 -0
- package/web/dist/assets/TermXterm-Bt5WKAxP.js +3 -0
- package/web/dist/assets/TerminalPanel-BCIBV8se.js +1 -0
- package/web/dist/assets/TuiOverlayModal-3NDd9T97.js +1 -0
- package/web/dist/assets/app-globals-CZjFtI4F.js +129 -0
- package/web/dist/assets/canvas-client-WkhM55mR.js +1 -0
- package/web/dist/assets/composer-bridge-CImnjDHq.js +1 -0
- package/web/dist/assets/desktop-B8NZ3KW-.js +1 -0
- package/web/dist/assets/index-CQc3VrWa.css +1 -0
- package/web/dist/assets/index-D_AGu4Zv.js +404 -0
- package/web/dist/assets/plugin-host-uqZGpvCs.js +1 -0
- package/web/dist/assets/{remote-ssh-client-CfYSMEZg.js → remote-ssh-client-Cdf-cTUe.js} +1 -1
- package/web/dist/assets/theme-DGL7hLUs.js +1 -0
- package/web/dist/index.html +12 -11
- package/web/dist/sw.js +15 -61
- package/web/public/sw.js +14 -60
- package/dist/gh-comment-781.md +0 -5
- package/dist/server/device-center/local-page.js +0 -17
- package/dist/server/device-center/smoke-preview.js +0 -3
- package/dist/server/durable/durable-capabilities.js +0 -11
- package/dist/server/markers/builtins/services.js +0 -123
- package/dist/server/markers/builtins/todo.js +0 -189
- package/dist/server/markers-list-tool.js +0 -34
- package/dist/server/orchestrator.js +0 -109
- package/dist/server/patch-turn-end-boundary.js +0 -77
- package/dist/server/system-prompt-soul.js +0 -41
- package/dist/server/univer-service.js +0 -448
- package/dist/server/universal/drivers/dsh-driver.js +0 -379
- package/dist/test-artifact.md +0 -9
- package/dist/test-preview-modal.md +0 -11
- package/dist/test-report.html +0 -20
- package/web/dist/assets/BgTasksModal-C0i3O1FT.js +0 -1
- package/web/dist/assets/CanvasStudio-B8thymBN.js +0 -1579
- package/web/dist/assets/CanvasStudio-zSxyIx1R.js +0 -1579
- package/web/dist/assets/DeviceCenter-DfAHKcid.js +0 -3
- package/web/dist/assets/DeviceCenter-ydvOTlzE.js +0 -3
- package/web/dist/assets/DeviceExecutionSettings-q5Ik8oXg.js +0 -1
- package/web/dist/assets/DeviceGroups-CI14_SRb.js +0 -1
- package/web/dist/assets/DeviceGroups-DvsB5IEU.js +0 -1
- package/web/dist/assets/FilePreview-BgGongmv.js +0 -2
- package/web/dist/assets/FilePreview-D4NrhF-U.js +0 -2
- package/web/dist/assets/GlobalSearchModal-BWgU8yPd.js +0 -1
- package/web/dist/assets/GlobalSearchModal-F7fNimKk.js +0 -1
- package/web/dist/assets/GroupConversation-Dh71Pdb-.js +0 -17
- package/web/dist/assets/GroupConversation-ZK3nRmNm.js +0 -17
- package/web/dist/assets/ModelConfigModal-YVEgyy34.js +0 -2
- package/web/dist/assets/ModelConfigModal-vWtg3srp.js +0 -2
- package/web/dist/assets/ProviderOAuthControls-BGSBIKD7.js +0 -1
- package/web/dist/assets/SCMPanel-B8_EDxNr.js +0 -2
- package/web/dist/assets/SCMPanel-BU58qk3T.js +0 -2
- package/web/dist/assets/SettingsModal-CMUybq3J.js +0 -32
- package/web/dist/assets/SettingsModal-OBmGTh-5.js +0 -32
- package/web/dist/assets/TerminalPanel-0CYvD72B.js +0 -3
- package/web/dist/assets/TerminalPanel-DDavKvFr.js +0 -3
- package/web/dist/assets/TuiOverlayModal-BsA-QTvN.js +0 -1
- package/web/dist/assets/TuiOverlayModal-DzoVQBuG.js +0 -1
- package/web/dist/assets/app-globals-CZxzGvIo.js +0 -123
- package/web/dist/assets/canvas-client-CUnXlQYX.js +0 -1
- package/web/dist/assets/desktop-aAKpvKJV.js +0 -1
- package/web/dist/assets/index-C6DwztqE.css +0 -1
- package/web/dist/assets/index-CuN802Sj.js +0 -93
- package/web/dist/assets/index-EH5Fw9fa.js +0 -93
- package/web/dist/assets/plugin-host-BRWib9DF.js +0 -1
- package/web/dist/assets/theme-D2l_mLNo.js +0 -1
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP 服务器管理服务
|
|
3
|
-
*
|
|
4
|
-
* 负责 Pi 全局 (~/.pi/agent/mcp.json 或兼容 ~/.pi-web/mcp.json)
|
|
5
|
-
* 与工作区项目级 (.pi/mcp.json) MCP 服务器配置的读写、合并与生命周期。
|
|
6
|
-
*/
|
|
7
1
|
import { readFileSync, unlinkSync } from "node:fs";
|
|
8
2
|
import { resolve } from "node:path";
|
|
9
3
|
import { isDeepStrictEqual } from "node:util";
|
|
10
4
|
import { writeAtomicSync } from "./atomic-file.js";
|
|
11
5
|
import { getGlobalMcpPath, getProjectMcpPath, parseMcpConfig, } from "./mcp-bridge.js";
|
|
12
6
|
export { getGlobalMcpPath, getProjectMcpPath };
|
|
13
|
-
/** 读取指定文件的 MCP 服务器配置 */
|
|
14
7
|
export function readMcpConfigFile(filePath) {
|
|
15
8
|
try {
|
|
16
9
|
const raw = readWritableConfig(filePath);
|
|
@@ -29,7 +22,6 @@ export function readMcpConfigFile(filePath) {
|
|
|
29
22
|
};
|
|
30
23
|
}
|
|
31
24
|
}
|
|
32
|
-
/** Only ENOENT is an empty configuration. All other read/shape errors stop mutations. */
|
|
33
25
|
function readWritableConfig(filePath) {
|
|
34
26
|
try {
|
|
35
27
|
const raw = JSON.parse(readFileSync(filePath, "utf8"));
|
|
@@ -50,7 +42,6 @@ function readWritableConfig(filePath) {
|
|
|
50
42
|
throw error;
|
|
51
43
|
}
|
|
52
44
|
}
|
|
53
|
-
/** 写入指定文件的 MCP 服务器配置(保留除服务器清单以外的其它字段) */
|
|
54
45
|
export function writeMcpConfigFile(filePath, servers, preferLegacy = false) {
|
|
55
46
|
const raw = readWritableConfig(filePath) ?? {};
|
|
56
47
|
const legacy = raw.servers !== undefined && raw.mcpServers === undefined ? true : preferLegacy;
|
|
@@ -68,11 +59,9 @@ export function writeMcpConfigFile(filePath, servers, preferLegacy = false) {
|
|
|
68
59
|
function isRecord(value) {
|
|
69
60
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
70
61
|
}
|
|
71
|
-
/** MCP configs and recovery intents may contain credentials. */
|
|
72
62
|
function atomicWrite(filePath, value) {
|
|
73
63
|
writeAtomicSync(filePath, JSON.stringify(value, null, 2) + "\n", { mode: 0o600, fsync: true });
|
|
74
64
|
}
|
|
75
|
-
/** Keep unrecognized server fields intact when editing a different entry. */
|
|
76
65
|
function editableConfig(filePath) {
|
|
77
66
|
const cfg = readMcpConfigFile(filePath);
|
|
78
67
|
if (cfg.error)
|
|
@@ -85,11 +74,9 @@ function editableConfig(filePath) {
|
|
|
85
74
|
function mutationError(error) {
|
|
86
75
|
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
87
76
|
}
|
|
88
|
-
/** 校验 MCP 服务器名称合法性(字母、数字、下划线、短横线) */
|
|
89
77
|
export function isValidMcpServerName(name) {
|
|
90
78
|
return /^[a-zA-Z0-9_-]+$/.test(name.trim());
|
|
91
79
|
}
|
|
92
|
-
/** 汇总查询全局与项目级配置列表,并结合 McpBridge 运行时状态组装 UiMcpServer 数组 */
|
|
93
80
|
export function listAllMcpServers(opts) {
|
|
94
81
|
const globalPath = getGlobalMcpPath(opts.agentDir, opts.dataDir);
|
|
95
82
|
const projectPath = getProjectMcpPath(opts.cwd);
|
|
@@ -103,7 +90,6 @@ export function listAllMcpServers(opts) {
|
|
|
103
90
|
if (cfg.error)
|
|
104
91
|
result.push({ name: path, scope, enabled: false, status: "error", error: cfg.error });
|
|
105
92
|
}
|
|
106
|
-
// 全局服务器
|
|
107
93
|
for (const [name, spec] of Object.entries(globalCfg.servers)) {
|
|
108
94
|
const overridden = Object.hasOwn(projectCfg.servers, name);
|
|
109
95
|
const status = getRuntimeStatus(name, spec, overridden ? undefined : opts.bridge);
|
|
@@ -125,7 +111,6 @@ export function listAllMcpServers(opts) {
|
|
|
125
111
|
...status,
|
|
126
112
|
});
|
|
127
113
|
}
|
|
128
|
-
// 项目级服务器
|
|
129
114
|
for (const [name, spec] of Object.entries(projectCfg.servers)) {
|
|
130
115
|
const status = getRuntimeStatus(name, spec, opts.bridge);
|
|
131
116
|
result.push({
|
|
@@ -156,7 +141,6 @@ function getRuntimeStatus(name, spec, bridge) {
|
|
|
156
141
|
}
|
|
157
142
|
return bridge.getServerStatus(name);
|
|
158
143
|
}
|
|
159
|
-
/** 保存或更新 MCP 服务器 */
|
|
160
144
|
export function saveMcpServer(opts) {
|
|
161
145
|
const name = opts.server.name.trim();
|
|
162
146
|
if (!isValidMcpServerName(name)) {
|
|
@@ -205,10 +189,6 @@ export function saveMcpServer(opts) {
|
|
|
205
189
|
return mutationError(error);
|
|
206
190
|
}
|
|
207
191
|
}
|
|
208
|
-
/** Durable intent distinguishes a partially committed move from a name collision.
|
|
209
|
-
* Retry the same save after restart to finish. Never roll back a committed target,
|
|
210
|
-
* or delete an entry edited since the intent was recorded.
|
|
211
|
-
*/
|
|
212
192
|
function migrateMcpServer(sourcePath, targetPath, sourceName, targetName, spec) {
|
|
213
193
|
const journalPath = `${sourcePath}.migration.json`;
|
|
214
194
|
const source = editableConfig(sourcePath);
|
|
@@ -265,7 +245,6 @@ function migrateMcpServer(sourcePath, targetPath, sourceName, targetName, spec)
|
|
|
265
245
|
unlinkSync(journalPath);
|
|
266
246
|
return { ok: true };
|
|
267
247
|
}
|
|
268
|
-
/** 删除指定作用域下的 MCP 服务器 */
|
|
269
248
|
export function deleteMcpServer(opts) {
|
|
270
249
|
const name = opts.name.trim();
|
|
271
250
|
const globalPath = getGlobalMcpPath(opts.agentDir, opts.dataDir);
|
|
@@ -284,7 +263,6 @@ export function deleteMcpServer(opts) {
|
|
|
284
263
|
return mutationError(error);
|
|
285
264
|
}
|
|
286
265
|
}
|
|
287
|
-
/** 切换指定作用域下的 MCP 服务器启用/停用状态 */
|
|
288
266
|
export function toggleMcpServer(opts) {
|
|
289
267
|
const name = opts.name.trim();
|
|
290
268
|
const globalPath = getGlobalMcpPath(opts.agentDir, opts.dataDir);
|
|
@@ -297,7 +275,6 @@ export function toggleMcpServer(opts) {
|
|
|
297
275
|
writeMcpConfigFile(targetPath, targetCfg.servers, targetCfg.legacy);
|
|
298
276
|
return { ok: true };
|
|
299
277
|
}
|
|
300
|
-
// 若在项目级切换全局服务器的启用状态(项目级覆盖):写入仅带 enabled 的配置项
|
|
301
278
|
if (opts.scope === "project") {
|
|
302
279
|
const globalCfg = editableConfig(globalPath);
|
|
303
280
|
if (globalCfg.servers[name]) {
|
|
@@ -312,28 +289,22 @@ export function toggleMcpServer(opts) {
|
|
|
312
289
|
return mutationError(error);
|
|
313
290
|
}
|
|
314
291
|
}
|
|
315
|
-
/** 从 npm 包名、URL 或命令自动推导合法的 MCP 服务器名称 */
|
|
316
292
|
export function deriveMcpServerName(raw) {
|
|
317
293
|
let s = String(raw ?? "").trim();
|
|
318
294
|
if (!s)
|
|
319
295
|
return "";
|
|
320
|
-
// 如果是 URL,提取 hostname
|
|
321
296
|
if (/^https?:\/\//i.test(s)) {
|
|
322
297
|
try {
|
|
323
298
|
const u = new URL(s);
|
|
324
299
|
s = u.hostname;
|
|
325
300
|
}
|
|
326
|
-
catch {
|
|
327
|
-
/* ignore */
|
|
328
|
-
}
|
|
301
|
+
catch { }
|
|
329
302
|
}
|
|
330
303
|
else {
|
|
331
|
-
// 去掉 npm 版本后缀(如 @scope/pkg@1.2.3 或 pkg@latest)
|
|
332
304
|
const atIdx = s.lastIndexOf("@");
|
|
333
305
|
if (atIdx > 0) {
|
|
334
306
|
s = s.slice(0, atIdx);
|
|
335
307
|
}
|
|
336
|
-
// 若为 @scope/pkg,取斜杠后半段;若后半段只是 "mcp" 或 "server"(如 @playwright/mcp),取 scope
|
|
337
308
|
if (s.startsWith("@") && s.includes("/")) {
|
|
338
309
|
const [scopePart, pkgPart] = s.slice(1).split("/", 2);
|
|
339
310
|
if (pkgPart && !/^(mcp|server|mcp-server)$/i.test(pkgPart)) {
|
|
@@ -343,7 +314,6 @@ export function deriveMcpServerName(raw) {
|
|
|
343
314
|
s = scopePart;
|
|
344
315
|
}
|
|
345
316
|
}
|
|
346
|
-
// 剥离常见前后缀(保留非空主体)
|
|
347
317
|
const stripped = s.replace(/^(mcp-server-|server-|mcp-)/i, "").replace(/(-mcp-server|-server|-mcp)$/i, "");
|
|
348
318
|
if (stripped.trim()) {
|
|
349
319
|
s = stripped.trim();
|
|
@@ -354,9 +324,6 @@ export function deriveMcpServerName(raw) {
|
|
|
354
324
|
.replace(/^-+|-+$/g, "")
|
|
355
325
|
.slice(0, 64);
|
|
356
326
|
}
|
|
357
|
-
/**
|
|
358
|
-
* 检查某个 MCP 服务器是否已安装(支持按服务器名称、npm 包名、命令或 URL 匹配)。
|
|
359
|
-
*/
|
|
360
327
|
export function checkMcpServer(opts) {
|
|
361
328
|
const q = String(opts.query ?? "").trim();
|
|
362
329
|
if (!q) {
|
|
@@ -365,7 +332,6 @@ export function checkMcpServer(opts) {
|
|
|
365
332
|
const qLower = q.toLowerCase();
|
|
366
333
|
const derived = deriveMcpServerName(q).toLowerCase();
|
|
367
334
|
const { servers } = listAllMcpServers(opts);
|
|
368
|
-
// 按匹配度打分:精确名 > 忽略大小写名 > 推导短名相等 > package/args/url/command 包含
|
|
369
335
|
const scored = [];
|
|
370
336
|
for (const srv of servers) {
|
|
371
337
|
const nameLower = srv.name.toLowerCase();
|
|
@@ -392,7 +358,6 @@ export function checkMcpServer(opts) {
|
|
|
392
358
|
score = 50;
|
|
393
359
|
}
|
|
394
360
|
if (score > 0) {
|
|
395
|
-
// 同分时项目级优先、running 优先
|
|
396
361
|
if (srv.scope === "project")
|
|
397
362
|
score += 2;
|
|
398
363
|
if (srv.status === "running")
|
|
@@ -412,9 +377,6 @@ export function checkMcpServer(opts) {
|
|
|
412
377
|
tools: primary?.tools ?? [],
|
|
413
378
|
};
|
|
414
379
|
}
|
|
415
|
-
/**
|
|
416
|
-
* 便捷安装/配置一个 MCP 服务器并立即触发 McpBridge 热加载。
|
|
417
|
-
*/
|
|
418
380
|
export async function installMcpServer(opts) {
|
|
419
381
|
const spec = opts.spec ?? {};
|
|
420
382
|
const pkg = typeof spec.package === "string" ? spec.package.trim() : "";
|
|
@@ -442,8 +404,6 @@ export async function installMcpServer(opts) {
|
|
|
442
404
|
};
|
|
443
405
|
}
|
|
444
406
|
const scope = spec.scope === "global" ? "global" : "project";
|
|
445
|
-
// 重名保护:install 默认拒绝覆盖——promptGuidelines 里的"先 check"只是给模型
|
|
446
|
-
// 的建议,不拦运行时;静默覆盖会吃掉用户手工配置的同名条目(含私有 token env)
|
|
447
407
|
const existing = listAllMcpServers({ agentDir: opts.agentDir, cwd: opts.cwd, dataDir: opts.dataDir }).servers.find((s) => s.name === rawName && s.scope === scope);
|
|
448
408
|
if (existing && spec.overwrite !== true) {
|
|
449
409
|
return {
|
|
@@ -480,9 +440,7 @@ export async function installMcpServer(opts) {
|
|
|
480
440
|
try {
|
|
481
441
|
await opts.bridge.reload();
|
|
482
442
|
}
|
|
483
|
-
catch {
|
|
484
|
-
/* bridge reload 内部已吞异常,兜底防御 */
|
|
485
|
-
}
|
|
443
|
+
catch { }
|
|
486
444
|
}
|
|
487
445
|
const after = listAllMcpServers({
|
|
488
446
|
agentDir: opts.agentDir,
|
|
@@ -4,7 +4,6 @@ import { authorizeMcp, McpOAuthProvider, MemoryOAuthStateStore } from "@earendil
|
|
|
4
4
|
import { getMcpAuthStorePath, mcpAuthStoreKey, readMcpAuthStore, withMcpAuthStoreLock, writeMcpAuthStore, } from "./mcp-oauth.js";
|
|
5
5
|
const LOGIN_TTL_MS = 10 * 60_000;
|
|
6
6
|
const attempts = new Map();
|
|
7
|
-
/** Ephemeral PKCE state stays server-side; only a completed grant enters pi's shared store. */
|
|
8
7
|
export async function startMcpOAuthLogin(options) {
|
|
9
8
|
const url = new URL(options.serverUrl);
|
|
10
9
|
if (url.protocol !== "https:" &&
|
|
@@ -100,7 +99,6 @@ export async function finishMcpOAuthLogin({ id, redirectUrl }) {
|
|
|
100
99
|
return;
|
|
101
100
|
if (attempt.status.status === "error")
|
|
102
101
|
throw new Error(attempt.status.error);
|
|
103
|
-
// Validate before changing state: a stray or forged callback must not consume the real login.
|
|
104
102
|
let callback;
|
|
105
103
|
try {
|
|
106
104
|
callback = new URL(redirectUrl);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as login from "./mcp-oauth-login.js";
|
|
2
|
-
/** One controller per requesting ClientSession; IDs never authorize another client. */
|
|
3
2
|
export class McpOAuthUi {
|
|
4
3
|
service;
|
|
5
4
|
attempts = new Map();
|
|
@@ -111,9 +110,7 @@ export class McpOAuthUi {
|
|
|
111
110
|
try {
|
|
112
111
|
recoverable = !!attempt?.id && this.service.getMcpOAuthLoginStatus(attempt.id).status === "pending";
|
|
113
112
|
}
|
|
114
|
-
catch {
|
|
115
|
-
/* Expired attempts are terminal. */
|
|
116
|
-
}
|
|
113
|
+
catch { }
|
|
117
114
|
if ((msg.type === "mcp_oauth_finish" || msg.type === "mcp_oauth_status") && attempt?.id && recoverable) {
|
|
118
115
|
attempt.finishing = undefined;
|
|
119
116
|
send("pending", { id: attempt.id, error: "Invalid redirect URL. Paste the full callback URL and try again." });
|
package/dist/server/mcp-oauth.js
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OAuth 保护的远端 MCP 服务器的凭据(Issue #786)。
|
|
3
|
-
*
|
|
4
|
-
* pi 的内置 MCP 集成会把登录结果存进 `<agent-dir>/mcp-auth.json`,键为 `mcp__<服务器名>|<url>`
|
|
5
|
-
* (旧版本只写 URL 做键;那种状态这里同样接管)。桥接层与网页登录共用这份凭据。
|
|
6
|
-
*
|
|
7
|
-
* 本模块**复用 pi 的凭据库**,而不是再建一份:
|
|
8
|
-
* - 读出存好的 access token,随请求发 `Authorization: Bearer …`;
|
|
9
|
-
* - 临近过期或收到 401 时,用存好的 refresh token 换新的;
|
|
10
|
-
* - 刷新结果按 pi 的格式写回,并复用 pi 的刷新锁(两个进程不会同时刷新)。
|
|
11
|
-
*
|
|
12
|
-
* 网页登录(授权码 + PKCE + 浏览器回调)由 mcp-oauth-login.ts 处理;CLI 登录仍然兼容。
|
|
13
|
-
*/
|
|
14
1
|
import { createHash } from "node:crypto";
|
|
15
2
|
import { mkdirSync, readFileSync, rmSync, statSync, utimesSync } from "node:fs";
|
|
16
3
|
import { homedir } from "node:os";
|
|
@@ -18,41 +5,28 @@ import { dirname, join } from "node:path";
|
|
|
18
5
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
19
6
|
import { isDeepStrictEqual } from "node:util";
|
|
20
7
|
import { writeAtomicSync } from "./atomic-file.js";
|
|
21
|
-
/** 离过期这么近的 access token 先刷新再发出去(与 pi 同口径)。 */
|
|
22
8
|
export const MCP_REFRESH_SKEW_MS = 30_000;
|
|
23
|
-
/** 刷新锁被持有超过这个时间就视为遗弃(持锁进程被杀),后来者接管。 */
|
|
24
9
|
const REFRESH_LOCK_STALE_MS = 20_000;
|
|
25
|
-
/** 等别的进程刷新的最长时间;比一个过期锁的寿命更长。 */
|
|
26
10
|
const REFRESH_LOCK_WAIT_MS = 25_000;
|
|
27
11
|
const REFRESH_LOCK_RETRY_MS = 100;
|
|
28
|
-
/** 单次授权服务器请求的上限:不响应的服务器不能一直占着锁。 */
|
|
29
12
|
const REFRESH_REQUEST_TIMEOUT_MS = 20_000;
|
|
30
|
-
/** 凭据库锁只在「读-合并-写」这一小段持有;等别的进程的最长时间远小于刷新锁。 */
|
|
31
13
|
const STORE_LOCK_WAIT_MS = 2_000;
|
|
32
|
-
/** pi 的 proper-lockfile 默认把超过 10 s 没续期的锁视为遗弃,这里保持一致。 */
|
|
33
14
|
const STORE_LOCK_STALE_MS = 10_000;
|
|
34
15
|
const STORE_LOCK_RETRY_MS = 20;
|
|
35
|
-
/** 该 OAuth 服务器需要重新登录(没有可用的刷新令牌,或刷新被拒绝)。 */
|
|
36
16
|
export class McpOAuthSignInRequiredError extends Error {
|
|
37
17
|
constructor(message) {
|
|
38
18
|
super(message);
|
|
39
19
|
this.name = "McpOAuthSignInRequiredError";
|
|
40
20
|
}
|
|
41
21
|
}
|
|
42
|
-
/** 缺省 agent 目录,与 `getGlobalMcpPath` 的解析顺序一致。 */
|
|
43
22
|
export function defaultMcpAgentDir() {
|
|
44
23
|
return process.env.PI_CODING_AGENT_DIR || join(homedir(), ".pi", "agent");
|
|
45
24
|
}
|
|
46
|
-
/** pi 的 MCP 凭据库绝对路径。 */
|
|
47
25
|
export function getMcpAuthStorePath(options = {}) {
|
|
48
26
|
if (options.storePath)
|
|
49
27
|
return options.storePath;
|
|
50
28
|
return join(options.agentDir || defaultMcpAgentDir(), "mcp-auth.json");
|
|
51
29
|
}
|
|
52
|
-
/**
|
|
53
|
-
* 凭据库键里用的 URL。pi 走 `new URL()` 归一化:`…/mcp` 与 `…/mcp/` 仍是不同的键,但
|
|
54
|
-
* origin 上缺的斜杠会补成 `/`。
|
|
55
|
-
*/
|
|
56
30
|
function normalizeServerUrl(serverUrl) {
|
|
57
31
|
try {
|
|
58
32
|
return String(new URL(serverUrl));
|
|
@@ -61,38 +35,27 @@ function normalizeServerUrl(serverUrl) {
|
|
|
61
35
|
return serverUrl;
|
|
62
36
|
}
|
|
63
37
|
}
|
|
64
|
-
/** pi 从服务器名推导出的命名空间:连字符换成下划线(`mcp__my_server`)。 */
|
|
65
38
|
function mcpNamespace(name) {
|
|
66
39
|
return `mcp__${name.replace(/-/g, "_")}`;
|
|
67
40
|
}
|
|
68
|
-
/** 一个服务器的存储键:名字 + URL,同一 URL 上的两个账号各存各的。 */
|
|
69
41
|
export function mcpAuthStoreKey(name, serverUrl) {
|
|
70
42
|
return `${mcpNamespace(name)}|${normalizeServerUrl(serverUrl)}`;
|
|
71
43
|
}
|
|
72
|
-
/** 旧版本 pi 写的键(只有 URL);照样读,下一次写入时被替换。 */
|
|
73
44
|
export function mcpAuthLegacyKey(serverUrl) {
|
|
74
45
|
return normalizeServerUrl(serverUrl);
|
|
75
46
|
}
|
|
76
|
-
/** 读整个凭据库;文件缺失或读不出来就当空库,绝不抛错。 */
|
|
77
47
|
export function readMcpAuthStore(options = {}) {
|
|
78
48
|
try {
|
|
79
49
|
const parsed = JSON.parse(readFileSync(getMcpAuthStorePath(options), "utf8"));
|
|
80
50
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
|
|
81
51
|
return parsed;
|
|
82
52
|
}
|
|
83
|
-
catch {
|
|
84
|
-
/* missing or corrupt: behave like pi, an unauthenticated server */
|
|
85
|
-
}
|
|
53
|
+
catch { }
|
|
86
54
|
return {};
|
|
87
55
|
}
|
|
88
|
-
/**
|
|
89
|
-
* 按 pi 的格式写回(2 空格 JSON + 换行,仅本人可读写)—— pi 与本模块共用这一个文件。
|
|
90
|
-
* 新建文件必须显式给 0600:默认的 0666 & umask 在常见 umask 下会写出 0644,凭据就变成可读了。
|
|
91
|
-
*/
|
|
92
56
|
export function writeMcpAuthStore(store, options = {}) {
|
|
93
57
|
writeAtomicSync(getMcpAuthStorePath(options), `${JSON.stringify(store, null, 2)}\n`, { mode: 0o600 });
|
|
94
58
|
}
|
|
95
|
-
/** 单个服务器已存的状态:优先新键,回落旧版 URL 键。 */
|
|
96
59
|
export function loadMcpAuthState(options) {
|
|
97
60
|
const key = mcpAuthStoreKey(options.name, options.serverUrl);
|
|
98
61
|
const legacyKey = mcpAuthLegacyKey(options.serverUrl);
|
|
@@ -109,10 +72,6 @@ function lockPathFor(storePath, key) {
|
|
|
109
72
|
const hash = createHash("sha256").update(key).digest("hex").slice(0, 16);
|
|
110
73
|
return `${storePath.replace(/mcp-auth\.json$/, "")}mcp-auth-refresh-${hash}.lock`;
|
|
111
74
|
}
|
|
112
|
-
/**
|
|
113
|
-
* 用凭据库旁边的锁目录把跨进程刷新串行化 —— 名字与过期窗口都与 pi 的存储一致,因此 pi 与
|
|
114
|
-
* pi-web-ui 的刷新不会同时发生。
|
|
115
|
-
*/
|
|
116
75
|
async function withRefreshLock(storePath, key, fn, signal) {
|
|
117
76
|
const lockPath = lockPathFor(storePath, key);
|
|
118
77
|
mkdirSync(join(lockPath, ".."), { recursive: true, mode: 0o700 });
|
|
@@ -133,22 +92,19 @@ async function withRefreshLock(storePath, key, fn, signal) {
|
|
|
133
92
|
}
|
|
134
93
|
}
|
|
135
94
|
catch {
|
|
136
|
-
continue;
|
|
95
|
+
continue;
|
|
137
96
|
}
|
|
138
97
|
if (Date.now() > deadline)
|
|
139
98
|
throw new Error("Timed out waiting for the MCP refresh lock (another process is refreshing)");
|
|
140
99
|
await sleep(REFRESH_LOCK_RETRY_MS, undefined, { signal });
|
|
141
100
|
}
|
|
142
101
|
}
|
|
143
|
-
// 刷新期间持续续期锁,慢的授权服务器不会被别人当成遗弃锁接管。
|
|
144
102
|
const renewal = setInterval(() => {
|
|
145
103
|
try {
|
|
146
104
|
const now = new Date();
|
|
147
105
|
utimesSync(lockPath, now, now);
|
|
148
106
|
}
|
|
149
|
-
catch {
|
|
150
|
-
/* released under us: nothing to renew */
|
|
151
|
-
}
|
|
107
|
+
catch { }
|
|
152
108
|
}, Math.max(1_000, Math.floor(REFRESH_LOCK_STALE_MS / 4)));
|
|
153
109
|
renewal.unref?.();
|
|
154
110
|
try {
|
|
@@ -160,16 +116,6 @@ async function withRefreshLock(storePath, key, fn, signal) {
|
|
|
160
116
|
rmSync(lockPath, { recursive: true, force: true });
|
|
161
117
|
}
|
|
162
118
|
}
|
|
163
|
-
/**
|
|
164
|
-
* 用 pi 自己的文件锁(`mcp-auth.json.lock`)保护整份凭据库的读-改-写。
|
|
165
|
-
*
|
|
166
|
-
* pi 的 `FileAuthStorageBackend.withLock` 对**每次**读写都用 proper-lockfile 锁住这个路径,
|
|
167
|
-
* 所以我们也用同名目录锁,两边互斥。两条约束:
|
|
168
|
-
* - 锁只覆盖读、合并、写这一小段,**绝不跨网络请求** —— pi 抢锁只重试 10 × 20 ms,
|
|
169
|
-
* 超时就抛错,会把 pi 自己的 MCP 调用拖挂;
|
|
170
|
-
* - mtime 超过 10 s 没续期就按遗弃处理(与 proper-lockfile 的默认 stale 一致),
|
|
171
|
-
* 崩溃留下的空锁目录不会永久堵住 pi。
|
|
172
|
-
*/
|
|
173
119
|
export async function withMcpAuthStoreLock(storePath, fn, signal) {
|
|
174
120
|
const lockPath = `${storePath}.lock`;
|
|
175
121
|
mkdirSync(dirname(storePath), { recursive: true, mode: 0o700 });
|
|
@@ -190,7 +136,7 @@ export async function withMcpAuthStoreLock(storePath, fn, signal) {
|
|
|
190
136
|
}
|
|
191
137
|
}
|
|
192
138
|
catch {
|
|
193
|
-
continue;
|
|
139
|
+
continue;
|
|
194
140
|
}
|
|
195
141
|
if (Date.now() > deadline)
|
|
196
142
|
throw new Error(`Timed out waiting for the MCP credential store lock (${lockPath})`);
|
|
@@ -219,7 +165,6 @@ function parseTokenResponse(value, fallbackRefreshToken) {
|
|
|
219
165
|
}
|
|
220
166
|
return {
|
|
221
167
|
access_token: raw.access_token,
|
|
222
|
-
// Servers that rotate refresh tokens send a new one; otherwise the grant keeps the old.
|
|
223
168
|
refresh_token: typeof raw.refresh_token === "string" && raw.refresh_token ? raw.refresh_token : fallbackRefreshToken,
|
|
224
169
|
token_type: typeof raw.token_type === "string" ? raw.token_type : undefined,
|
|
225
170
|
expires_in: typeof raw.expires_in === "number" ? raw.expires_in : undefined,
|
|
@@ -233,9 +178,6 @@ function selectClientAuthMethod(state) {
|
|
|
233
178
|
return hinted;
|
|
234
179
|
return information.client_secret ? "client_secret_basic" : "none";
|
|
235
180
|
}
|
|
236
|
-
/**
|
|
237
|
-
* 用存好的 refresh token 换新的 access token(RFC 6749 §6),客户端认证方式跟随注册时的选择。
|
|
238
|
-
*/
|
|
239
181
|
async function requestRefreshToken(state, options) {
|
|
240
182
|
const tokenEndpoint = state.discovery?.authorizationServerMetadata?.token_endpoint;
|
|
241
183
|
const clientId = state.clientInformation?.client_id;
|
|
@@ -292,7 +234,6 @@ async function requestRefreshToken(state, options) {
|
|
|
292
234
|
catch {
|
|
293
235
|
parsed = undefined;
|
|
294
236
|
}
|
|
295
|
-
// OAuth servers may report errors with any status, so the body wins over the status code.
|
|
296
237
|
if (parsed && typeof parsed === "object" && typeof parsed.error === "string") {
|
|
297
238
|
return parseTokenResponse(parsed, refreshToken);
|
|
298
239
|
}
|
|
@@ -301,11 +242,6 @@ async function requestRefreshToken(state, options) {
|
|
|
301
242
|
}
|
|
302
243
|
return parseTokenResponse(parsed, refreshToken);
|
|
303
244
|
}
|
|
304
|
-
/**
|
|
305
|
-
* 强制刷新(401 之后,或 token 即将过期)并把结果落盘。返回新的 access token。
|
|
306
|
-
* 带 `staleToken` 时,若库里已被别的进程换掉就直接用那个 token,不再刷第二次 —— 刷新令牌轮换后
|
|
307
|
-
* 第二次尝试会失败。
|
|
308
|
-
*/
|
|
309
245
|
export async function refreshMcpAccessToken(options) {
|
|
310
246
|
const storePath = getMcpAuthStorePath(options);
|
|
311
247
|
const key = mcpAuthStoreKey(options.name, options.serverUrl);
|
|
@@ -322,17 +258,14 @@ export async function refreshMcpAccessToken(options) {
|
|
|
322
258
|
}
|
|
323
259
|
const storedToken = state?.tokens?.access_token;
|
|
324
260
|
if (options.staleToken && storedToken && storedToken !== options.staleToken) {
|
|
325
|
-
return storedToken;
|
|
261
|
+
return storedToken;
|
|
326
262
|
}
|
|
327
263
|
if (!state)
|
|
328
264
|
return null;
|
|
329
|
-
// 网络期间仅持该服务器的刷新锁,不持整库锁;pi 仍可登录、注销或写入其它服务器。
|
|
330
265
|
const tokens = await requestRefreshToken(state, options);
|
|
331
266
|
const nowMs = (options.now ?? Date.now)();
|
|
332
267
|
const expiresAt = typeof tokens.expires_in === "number" ? nowMs + tokens.expires_in * 1000 : undefined;
|
|
333
268
|
return withMcpAuthStoreLock(storePath, () => {
|
|
334
|
-
// Compare the grant read before the network call under the SDK store lock.
|
|
335
|
-
// Logout/re-login/client changes win; never restore a missing entry.
|
|
336
269
|
signal?.throwIfAborted();
|
|
337
270
|
const fresh = readMcpAuthStore(options);
|
|
338
271
|
const currentKey = fresh[key] ? key : legacyKey;
|
|
@@ -344,8 +277,6 @@ export async function refreshMcpAccessToken(options) {
|
|
|
344
277
|
...base,
|
|
345
278
|
tokens: { ...base.tokens, ...trimUndefined(tokens) },
|
|
346
279
|
};
|
|
347
|
-
// 授权服务器没给 `expires_in` 时必须删掉旧的绝对过期时间:否则它一直是「已过期」,
|
|
348
|
-
// 每个请求都会再走一次刷新(pi 的 provider 也是这么处理的)。
|
|
349
280
|
if (expiresAt === undefined)
|
|
350
281
|
delete next.tokensExpireAt;
|
|
351
282
|
else
|
|
@@ -370,10 +301,6 @@ function trimUndefined(tokens) {
|
|
|
370
301
|
}
|
|
371
302
|
return out;
|
|
372
303
|
}
|
|
373
|
-
/**
|
|
374
|
-
* 该发的 access token;这个服务器没有凭据(匿名服务器)时返回 `null`。
|
|
375
|
-
* 即将过期的会先刷新;刷新失败则返回旧 token,交给服务器自己的 401 定论。
|
|
376
|
-
*/
|
|
377
304
|
export async function getMcpAccessToken(options) {
|
|
378
305
|
options.signal?.throwIfAborted();
|
|
379
306
|
const { state } = loadMcpAuthState(options);
|
|
@@ -389,7 +316,6 @@ export async function getMcpAccessToken(options) {
|
|
|
389
316
|
}
|
|
390
317
|
catch {
|
|
391
318
|
options.signal?.throwIfAborted();
|
|
392
|
-
// A failed refresh may race logout/re-login too. Never reuse the captured grant.
|
|
393
319
|
return loadMcpAuthState(options).state?.tokens?.access_token ?? null;
|
|
394
320
|
}
|
|
395
321
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
2
|
import { McpBridge } from "./mcp-bridge.js";
|
|
3
3
|
import { createMcpHotReload } from "./mcp-hot-reload.js";
|
|
4
|
-
/** Bridges never change cwd. Only unreferenced, idle entries may be automatically evicted. */
|
|
5
4
|
export class McpProjectRuntimeRegistry {
|
|
6
5
|
options;
|
|
7
6
|
projects = new Map();
|
|
@@ -29,7 +28,6 @@ export class McpProjectRuntimeRegistry {
|
|
|
29
28
|
now() {
|
|
30
29
|
return this.options.now?.() ?? Date.now();
|
|
31
30
|
}
|
|
32
|
-
/** Operations retain entries across awaits even before a conversation is published. */
|
|
33
31
|
retain(cwd) {
|
|
34
32
|
const entry = this.entry(cwd);
|
|
35
33
|
entry.busy++;
|
|
@@ -63,7 +61,6 @@ export class McpProjectRuntimeRegistry {
|
|
|
63
61
|
await this.disposeProject(entry.cwd);
|
|
64
62
|
}
|
|
65
63
|
}
|
|
66
|
-
/** Read an already active bridge without creating a runtime or starting processes. */
|
|
67
64
|
peekBridge(cwd) {
|
|
68
65
|
return this.projects.get(this.key(cwd))?.bridge;
|
|
69
66
|
}
|
|
@@ -116,7 +113,6 @@ export class McpProjectRuntimeRegistry {
|
|
|
116
113
|
busy: 1,
|
|
117
114
|
};
|
|
118
115
|
this.projects.set(key, entry);
|
|
119
|
-
// Seed before load; apply afterwards catches edits made while servers were starting.
|
|
120
116
|
watcher.start();
|
|
121
117
|
entry.ready = Promise.resolve().then(async () => {
|
|
122
118
|
if (!current())
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isPromptAsideEntry } from "./attachments.js";
|
|
2
|
-
/** Context entries retain tombstones; omit deleted messages before resolving UI IDs. */
|
|
3
2
|
export function undeletedContextEntries(entries) {
|
|
4
3
|
const edits = new Map();
|
|
5
4
|
for (const entry of entries) {
|
|
@@ -8,7 +7,6 @@ export function undeletedContextEntries(entries) {
|
|
|
8
7
|
}
|
|
9
8
|
return entries.filter((entry) => edits.get(entry.id) !== null);
|
|
10
9
|
}
|
|
11
|
-
/** Keep deletion local to the selected message, including its attachment/tool records. */
|
|
12
10
|
export function messageDeletionTargets(entries, targetId) {
|
|
13
11
|
const visible = undeletedContextEntries(entries);
|
|
14
12
|
const index = visible.findIndex((entry) => entry.id === targetId);
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { findEntryByUiId } from "./serialize.js";
|
|
2
|
-
/**
|
|
3
|
-
* 将前端渲染的用户消息 ID(u-<timestamp>-<seq>)解析为底层 SessionEntry 的唯一 ID。
|
|
4
|
-
* seq 用于解决同一毫秒内发出的多条用户消息(例如附件 aside 消息)。
|
|
5
|
-
*/
|
|
6
2
|
export function resolveUserMessageEntryId(contextEntries, messageId) {
|
|
7
3
|
const m = /^u-(\d+)(?:-(\d+))?$/.exec(messageId);
|
|
8
4
|
if (!m)
|
|
@@ -22,10 +18,6 @@ export function resolveUserMessageEntryId(contextEntries, messageId) {
|
|
|
22
18
|
}
|
|
23
19
|
return null;
|
|
24
20
|
}
|
|
25
|
-
/**
|
|
26
|
-
* 将任意渲染的消息 ID 解析为当前会话分支的 SessionEntry 节点。
|
|
27
|
-
* 优先在上下文条目中比对 UI ID,未命中时通过 fallback 查整棵历史树。
|
|
28
|
-
*/
|
|
29
21
|
export function resolveConversationMessageEntry(contextEntries, messageId, seqOf, fallbackGetEntry) {
|
|
30
22
|
const found = findEntryByUiId(contextEntries, messageId, seqOf);
|
|
31
23
|
return found ?? fallbackGetEntry?.(messageId) ?? null;
|