pi-web-ui 0.117.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 +48 -2
- 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 +147 -43
- 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 +56 -444
- 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 +160 -374
- package/dist/server/agent-service.js +875 -2978
- 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 +26 -30
- 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 +6 -213
- 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 +3 -76
- 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 +0 -82
- 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 +0 -8
- 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 +1 -3
- package/dist/server/device-center/collab-tool.js +0 -10
- package/dist/server/device-center/connector.js +21 -11
- package/dist/server/device-center/delivery-authority.js +0 -3
- package/dist/server/device-center/delivery-subject.js +0 -1
- 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 +1 -27
- 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 +0 -1
- 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 +0 -27
- 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 +0 -12
- package/dist/server/device-center/hub-deliveries.js +0 -1
- package/dist/server/device-center/hub-integration.js +0 -8
- 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 +25 -7
- package/dist/server/device-center/hub-setup.js +0 -6
- package/dist/server/device-center/hub-transaction-log.js +0 -22
- 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 +210 -86
- 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 +0 -2
- package/dist/server/device-center/local-hub.js +0 -2
- package/dist/server/device-center/local-publication.js +1 -8
- package/dist/server/device-center/local-verification-job.js +0 -2
- package/dist/server/device-center/local-verification.js +0 -1
- package/dist/server/device-center/local.js +267 -39
- package/dist/server/device-center/main.js +14 -1
- 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 +0 -31
- package/dist/server/device-center/path-portal.js +42 -12
- package/dist/server/device-center/publication-journal.js +0 -7
- package/dist/server/device-center/publish-intent.js +0 -5
- package/dist/server/device-center/relay.js +85 -30
- package/dist/server/device-center/report-upload.js +0 -1
- package/dist/server/device-center/runtime.js +1 -18
- package/dist/server/device-center/store.js +13 -33
- 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 +0 -13
- 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 +5 -88
- 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 +0 -18
- package/dist/server/device-center/task-state.js +0 -12
- package/dist/server/device-center/task-workspace.js +0 -50
- 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 +0 -1
- package/dist/server/device-center/work-contract.js +1 -73
- 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 +190 -32
- package/dist/server/dispatch-plugin-handlers.js +2 -19
- package/dist/server/dsh/dsh-agent-service.js +69 -599
- 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 +177 -680
- 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 +3 -43
- package/dist/server/patch-remote-catalog.js +1 -32
- 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 +9 -62
- package/dist/server/preset-plugin-dependencies.js +0 -2
- package/dist/server/preset-share.js +3 -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 +34 -1
- package/dist/server/quick-ask.js +123 -27
- 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 +0 -26
- 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 +3 -54
- 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 +17 -25
- package/dist/server/session-open.js +2 -26
- package/dist/server/session-parser.js +1 -55
- package/dist/server/session-scan.js +1 -17
- package/dist/server/session-search.js +0 -56
- package/dist/server/settings-service.js +11 -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 +0 -42
- 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 +1 -19
- 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 +12 -172
- 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 +26 -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 +1 -56
- 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 +37 -1
- package/docs/device-center.md +28 -2
- 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 +7 -3
- package/plugin-sdk/README.md +6 -0
- package/plugin-sdk/client-utils.mjs +0 -7
- package/plugin-sdk/client.d.ts +0 -1
- package/plugin-sdk/client.mjs +1 -31
- package/plugin-sdk/import-check.mjs +4 -51
- package/plugin-sdk/index.d.ts +120 -119
- package/plugin-sdk/index.mjs +0 -6
- package/plugin-sdk/ssh-host-trust.mjs +0 -12
- package/plugin-sdk/testing.d.ts +0 -1
- package/plugin-sdk/testing.mjs +31 -86
- 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 +1 -9
- package/themes/flow-ink.css +1 -10
- package/themes/flow-light.css +1 -10
- package/themes/flow-obsidian.css +1 -10
- package/themes/flow-zurich.css +1 -10
- 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-BjNRIUIc.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-CQtstPGv.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-ChTW8o1m.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-BX5rUuoI.js → PiSetupModal-DZKY5Wiw.js} +1 -1
- package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +1 -0
- package/web/dist/assets/{SCMPanel-DPAyY2sW.js → SCMPanel-CuEgzAlO.js} +2 -2
- 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-Dzi-eEyE.js → remote-ssh-client-Cdf-cTUe.js} +1 -1
- package/web/dist/assets/theme-DGL7hLUs.js +1 -0
- package/web/dist/index.html +11 -10
- package/web/dist/sw.js +15 -61
- package/web/public/sw.js +14 -60
- package/web/dist/assets/BgTasksModal-C0zuU8FE.js +0 -1
- package/web/dist/assets/CanvasStudio-BWvdmJ0M.js +0 -1579
- package/web/dist/assets/CanvasStudio-VQFjmTGq.js +0 -1579
- package/web/dist/assets/DeviceCenter-DI9_0aBB.js +0 -3
- package/web/dist/assets/DeviceCenter-DsNtXqzY.js +0 -3
- package/web/dist/assets/DeviceExecutionSettings-BLP1Su5G.js +0 -1
- package/web/dist/assets/DeviceGroups-2Pvk0Cds.js +0 -1
- package/web/dist/assets/DeviceGroups-CP7CcyPD.js +0 -1
- package/web/dist/assets/FilePreview-BMB2tNyT.js +0 -2
- package/web/dist/assets/FilePreview-RGFQUbJo.js +0 -2
- package/web/dist/assets/GlobalSearchModal-BM5wxiqU.js +0 -1
- package/web/dist/assets/GlobalSearchModal-DGv_WINq.js +0 -1
- package/web/dist/assets/GroupConversation-B7SnuXj1.js +0 -61
- package/web/dist/assets/GroupConversation-Dda69q-2.js +0 -61
- package/web/dist/assets/ModelConfigModal-C-0Z4hUZ.js +0 -2
- package/web/dist/assets/ModelConfigModal-yqeadyab.js +0 -2
- package/web/dist/assets/ProviderOAuthControls-DY4SCfXg.js +0 -1
- package/web/dist/assets/SCMPanel-C4KbQvvK.js +0 -2
- package/web/dist/assets/SettingsModal-DxZp6D_g.js +0 -32
- package/web/dist/assets/SettingsModal-WhQzaOPt.js +0 -32
- package/web/dist/assets/TerminalPanel-D4By_RVc.js +0 -3
- package/web/dist/assets/TerminalPanel-lZw8-i3j.js +0 -3
- package/web/dist/assets/TuiOverlayModal-C3pAVuC8.js +0 -1
- package/web/dist/assets/TuiOverlayModal-D7_rEXcJ.js +0 -1
- package/web/dist/assets/app-globals-KqOVtmp1.js +0 -123
- package/web/dist/assets/canvas-client-BY6ojmle.js +0 -1
- package/web/dist/assets/desktop-CV6KKp9R.js +0 -1
- package/web/dist/assets/index-BawF7ZP5.js +0 -397
- package/web/dist/assets/index-BoGCoq5X.js +0 -397
- package/web/dist/assets/index-CVW9FoY2.css +0 -1
- package/web/dist/assets/plugin-host-Dn8Dd6SC.js +0 -1
- package/web/dist/assets/theme-D_bihpdN.js +0 -1
package/bin/pi-web-ui.mjs
CHANGED
|
@@ -1,34 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* pi-web-ui CLI.
|
|
4
|
-
*
|
|
5
|
-
* pi-web-ui 启动生产服务器(前台,Ctrl+C 停止,自动打开浏览器)
|
|
6
|
-
* pi-web-ui --engine dsh --port 9000 --cwd /path 同上,覆盖引擎/端口/工作目录/数据目录
|
|
7
|
-
* pi-web-ui --no-browser 启动但不自动打开浏览器
|
|
8
|
-
* pi-web-ui --version | --help
|
|
9
|
-
* pi-web-ui server install [选项] 安装系统服务(开机自启)并启动
|
|
10
|
-
* pi-web-ui server shortcut [选项] 在桌面创建「一键启动」图标(启动服务并打开浏览器)
|
|
11
|
-
* pi-web-ui server uninstall [选项] 卸载系统服务(同时移除桌面图标)
|
|
12
|
-
* pi-web-ui server start|stop|restart|status [选项]
|
|
13
|
-
* pi-web-ui install <源> [选项] 安装 GitHub 上的界面插件(见下方「界面插件」)
|
|
14
|
-
* pi-web-ui plugins / uninstall <id> 列出 / 卸载界面插件
|
|
15
|
-
*
|
|
16
|
-
* 系统服务:
|
|
17
|
-
* - macOS → launchd 用户代理,label 默认 com.xingshuyin.pi-web-ui
|
|
18
|
-
* (--name 自定义时 com.<name>.server),无需 sudo
|
|
19
|
-
* - Linux → systemd 单元 <name>.service(/etc/systemd/system/,自动 sudo)
|
|
20
|
-
* - Windows → 登录自启 Run 键(HKCU,无需管理员)+ wscript 隐藏启动(无黑窗);
|
|
21
|
-
* PowerShell 启动脚本 / VBS 启动器 / PID 文件生成在
|
|
22
|
-
* %APPDATA%\pi-web-ui\
|
|
23
|
-
*
|
|
24
|
-
* 环境变量(flag 优先,环境变量后备):PI_WEB_PORT / PI_WEB_CWD / PI_WEB_DATA_DIR /
|
|
25
|
-
* PI_WEB_ENGINE / PI_WEB_HOST / PI_CODING_AGENT_DIR;token 仅环境变量,不走命令行。
|
|
26
|
-
*/
|
|
27
2
|
import { spawn, spawnSync } from "node:child_process";
|
|
28
3
|
import { createConnection } from "node:net";
|
|
29
4
|
import { get as httpGet } from "node:http";
|
|
30
5
|
import { createInterface } from "node:readline/promises";
|
|
31
|
-
// Dispatch Hub before loading optional plugin/FRP dependencies or the server build.
|
|
32
6
|
if (process.argv[2] === "hub") {
|
|
33
7
|
try {
|
|
34
8
|
const { runHubCliEntry } = await import("./device-hub-cli.mjs");
|
|
@@ -70,43 +44,32 @@ const {
|
|
|
70
44
|
} = isHubCommand ? {} : await import("../dist/server/plugin-updater.js");
|
|
71
45
|
|
|
72
46
|
const BIN_DIR = dirname(fileURLToPath(import.meta.url));
|
|
73
|
-
/** <pkg>/dist/server/index.js — the actual server entry. */
|
|
74
47
|
const SERVER_ENTRY = join(BIN_DIR, "..", "dist", "server", "index.js");
|
|
75
|
-
/** 「机器上有更新的 pi 副本就跟随它」解析钩子(issue #260;#321 起默认启用)。
|
|
76
|
-
* 必须早于任何 SDK 静态 import 加载 —— 所以每条启动路径都把它当 `--import` 传进去;
|
|
77
|
-
* PI_WEB_SDK=bundled 显式钉死自带副本(见 server/resolve-global-sdk.ts)。 */
|
|
78
48
|
const SDK_HOOK = join(BIN_DIR, "..", "dist", "server", "resolve-global-sdk.js");
|
|
79
|
-
/** dist 可能是旧构建(没有这个钩子文件)—— 只有文件在才注入:`--import <missing>` 会让
|
|
80
|
-
* CLI/服务直接起不来,那比少个开关严重得多。 */
|
|
81
49
|
const HAS_SDK_HOOK = existsSync(SDK_HOOK);
|
|
82
50
|
const NODE = process.execPath;
|
|
83
51
|
let pkg = { version: "0.0.0" };
|
|
84
52
|
try {
|
|
85
53
|
pkg = JSON.parse(readFileSync(join(BIN_DIR, "..", "package.json"), "utf8"));
|
|
86
|
-
} catch {
|
|
87
|
-
// version is best-effort — the server itself doesn't need it
|
|
88
|
-
}
|
|
54
|
+
} catch {}
|
|
89
55
|
|
|
90
|
-
/** Detect if the user prefers Chinese locale: POSIX env vars win, then Intl API fallback. */
|
|
91
56
|
function isZhLang() {
|
|
92
57
|
const env = process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || "";
|
|
93
58
|
if (env.startsWith("zh")) return true;
|
|
94
59
|
if (!env) {
|
|
95
60
|
try {
|
|
96
61
|
return Intl.DateTimeFormat().resolvedOptions().locale.startsWith("zh");
|
|
97
|
-
} catch {
|
|
98
|
-
/* ignore */
|
|
99
|
-
}
|
|
62
|
+
} catch {}
|
|
100
63
|
}
|
|
101
64
|
return false;
|
|
102
65
|
}
|
|
103
66
|
|
|
104
|
-
/** Resolved once: CLI messages below pick zh/en with `ZH ? zh : en` (only the chosen branch is evaluated). */
|
|
105
67
|
const ZH = isZhLang();
|
|
106
68
|
|
|
107
69
|
const HELP_ZH = `pi-web-ui v${pkg.version} — web chat for the pi coding agent
|
|
108
70
|
|
|
109
|
-
|
|
71
|
+
用法(pwu / piwebui / pi-web-ui 等价):
|
|
72
|
+
pwu [目录] 在指定目录启动(如 pwu .);不能与 --cwd 同用
|
|
110
73
|
pi-web-ui 启动服务器(前台,Ctrl+C 停止,自动打开浏览器)
|
|
111
74
|
pi-web-ui --engine dsh --port 9000 --cwd /path 启动并指定引擎 / 端口 / 工作目录 / 数据目录
|
|
112
75
|
pi-web-ui --no-browser 启动但不自动打开浏览器
|
|
@@ -172,7 +135,8 @@ FRP 内网穿透(将本地 pi-web-ui 服务端口通过 FRP 穿透转发到远
|
|
|
172
135
|
|
|
173
136
|
const HELP_EN = `pi-web-ui v${pkg.version} — web chat for the pi coding agent
|
|
174
137
|
|
|
175
|
-
Usage:
|
|
138
|
+
Usage (pwu / piwebui / pi-web-ui are equivalent):
|
|
139
|
+
pwu [directory] Start in a directory (e.g. pwu .); cannot combine with --cwd
|
|
176
140
|
pi-web-ui Start server (foreground, Ctrl+C to stop, auto-opens browser)
|
|
177
141
|
pi-web-ui --engine dsh --port 9000 --cwd /path Start with engine/port/cwd/data-dir overrides
|
|
178
142
|
pi-web-ui --no-browser Start without auto-opening browser
|
|
@@ -240,7 +204,6 @@ Environment variables (flag takes precedence, env var as fallback):
|
|
|
240
204
|
|
|
241
205
|
const HELP = isZhLang() ? HELP_ZH : HELP_EN;
|
|
242
206
|
|
|
243
|
-
/** Minimum Node required by the pi SDK (its dist uses `import … with { type: "json" }`). */
|
|
244
207
|
const NODE_MIN = [22, 19, 0];
|
|
245
208
|
function checkNodeVersion() {
|
|
246
209
|
const v = process.versions.node.split(".").map(Number);
|
|
@@ -267,7 +230,6 @@ function fail(msg) {
|
|
|
267
230
|
process.exit(1);
|
|
268
231
|
}
|
|
269
232
|
|
|
270
|
-
/** Run a command, inheriting stdio; exits on failure unless ignoreError. */
|
|
271
233
|
function run(cmd, args, { ignoreError = false, silent = false } = {}) {
|
|
272
234
|
const res = spawnSync(cmd, args, {
|
|
273
235
|
stdio: silent ? ["inherit", "ignore", "ignore"] : "inherit",
|
|
@@ -276,7 +238,6 @@ function run(cmd, args, { ignoreError = false, silent = false } = {}) {
|
|
|
276
238
|
return res;
|
|
277
239
|
}
|
|
278
240
|
|
|
279
|
-
/** Parse --flag value / --flag=value options; returns { opts, positionals }. */
|
|
280
241
|
function parseFlags(argv) {
|
|
281
242
|
const opts = {
|
|
282
243
|
port: undefined,
|
|
@@ -384,11 +345,6 @@ function parseFlags(argv) {
|
|
|
384
345
|
return { opts, positionals };
|
|
385
346
|
}
|
|
386
347
|
|
|
387
|
-
// ---------------------------------------------------------------------------
|
|
388
|
-
// 前台启动
|
|
389
|
-
// ---------------------------------------------------------------------------
|
|
390
|
-
|
|
391
|
-
/** Open a URL in the OS default browser; failures are ignored (best-effort). */
|
|
392
348
|
function openBrowser(url) {
|
|
393
349
|
let res;
|
|
394
350
|
if (isMac) {
|
|
@@ -398,7 +354,6 @@ function openBrowser(url) {
|
|
|
398
354
|
} else {
|
|
399
355
|
res = spawnSync("xdg-open", [url], { stdio: "ignore" });
|
|
400
356
|
}
|
|
401
|
-
// spawnSync 不抛异常:命令缺失(headless 服务器)时在返回对象里带 error 字段。
|
|
402
357
|
if (res?.error) {
|
|
403
358
|
if (res.error.code === "ENOENT") {
|
|
404
359
|
console.warn(
|
|
@@ -414,13 +369,6 @@ function openBrowser(url) {
|
|
|
414
369
|
}
|
|
415
370
|
}
|
|
416
371
|
|
|
417
|
-
/**
|
|
418
|
-
* Poll `url` until the server answers (or ~15s pass), then open it in the
|
|
419
|
-
* default browser. The foreground server runs in this process, so the first
|
|
420
|
-
* HTTP response is the "listening" signal; if the server crashes meanwhile
|
|
421
|
-
* (e.g. port already taken), the pending timers die with the process and
|
|
422
|
-
* nothing is opened.
|
|
423
|
-
*/
|
|
424
372
|
function openBrowserWhenUp(url) {
|
|
425
373
|
const deadline = Date.now() + 15_000;
|
|
426
374
|
const attempt = () => {
|
|
@@ -449,9 +397,7 @@ function loadStoredFileToken(dataDir) {
|
|
|
449
397
|
const raw = readFileSync(join(dataDir, "server-config.json"), "utf8");
|
|
450
398
|
const parsed = JSON.parse(raw);
|
|
451
399
|
if (typeof parsed?.token === "string" && parsed.token.trim()) return parsed.token.trim();
|
|
452
|
-
} catch {
|
|
453
|
-
/* ignore */
|
|
454
|
-
}
|
|
400
|
+
} catch {}
|
|
455
401
|
return "";
|
|
456
402
|
}
|
|
457
403
|
|
|
@@ -511,10 +457,6 @@ async function startForeground(opts) {
|
|
|
511
457
|
if (!opts.noBrowser) openBrowserWhenUp(url);
|
|
512
458
|
}
|
|
513
459
|
|
|
514
|
-
// ---------------------------------------------------------------------------
|
|
515
|
-
// 系统服务管理
|
|
516
|
-
// ---------------------------------------------------------------------------
|
|
517
|
-
|
|
518
460
|
const isMac = process.platform === "darwin";
|
|
519
461
|
const isLinux = process.platform === "linux";
|
|
520
462
|
const isWin = process.platform === "win32";
|
|
@@ -527,7 +469,6 @@ function uid() {
|
|
|
527
469
|
}
|
|
528
470
|
}
|
|
529
471
|
|
|
530
|
-
/** launchd label / systemd unit name / Windows task name for a service name. */
|
|
531
472
|
function serviceLabel(name) {
|
|
532
473
|
if (isMac) {
|
|
533
474
|
return name === "pi-web-ui" ? "com.xingshuyin.pi-web-ui" : `com.${name}.server`;
|
|
@@ -543,7 +484,6 @@ function systemdUnitPath(name) {
|
|
|
543
484
|
return `/etc/systemd/system/${name}.service`;
|
|
544
485
|
}
|
|
545
486
|
|
|
546
|
-
/** Windows: per-user config dir (%APPDATA%\pi-web-ui) holding the ps1/vbs launchers + pid file. */
|
|
547
487
|
function winServiceDir() {
|
|
548
488
|
return join(process.env.APPDATA ?? join(homedir(), "AppData", "Roaming"), "pi-web-ui");
|
|
549
489
|
}
|
|
@@ -564,22 +504,18 @@ function winTaskXmlPath(name) {
|
|
|
564
504
|
return join(winServiceDir(), `${name}.xml`);
|
|
565
505
|
}
|
|
566
506
|
|
|
567
|
-
/** Windows log file (per service name — multiple services must not share one log). */
|
|
568
507
|
function winLogPath(name) {
|
|
569
508
|
return join(homedir(), name === "pi-web-ui" ? "pi-web-ui.log" : `pi-web-ui-${name}.log`);
|
|
570
509
|
}
|
|
571
510
|
|
|
572
|
-
/** True when a scheduled task with this name exists (schtasks exits 0). */
|
|
573
511
|
function winTaskExists(name) {
|
|
574
512
|
return spawnSync("schtasks", ["/Query", "/TN", name], { stdio: "ignore" }).status === 0;
|
|
575
513
|
}
|
|
576
514
|
|
|
577
|
-
/** Windows: per-user autostart registry key (HKCU — writable without admin). */
|
|
578
515
|
function winRunKeyName() {
|
|
579
516
|
return "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
|
580
517
|
}
|
|
581
518
|
|
|
582
|
-
/** True when the per-user autostart Run key value exists. */
|
|
583
519
|
function winRunKeyInstalled(name) {
|
|
584
520
|
return (
|
|
585
521
|
spawnSync("reg", ["query", `HKCU\\${winRunKeyName()}`, "/v", name], {
|
|
@@ -588,39 +524,26 @@ function winRunKeyInstalled(name) {
|
|
|
588
524
|
);
|
|
589
525
|
}
|
|
590
526
|
|
|
591
|
-
/** Set the per-user autostart Run key value (no admin needed for HKCU). */
|
|
592
527
|
function winRunKeySet(name, value) {
|
|
593
528
|
run("reg", ["add", `HKCU\\${winRunKeyName()}`, "/v", name, "/t", "REG_SZ", "/d", value, "/f"], { silent: true });
|
|
594
529
|
}
|
|
595
530
|
|
|
596
|
-
/** Remove the per-user autostart Run key value (missing key is a no-op). */
|
|
597
531
|
function winRunKeyDelete(name) {
|
|
598
532
|
run("reg", ["delete", `HKCU\\${winRunKeyName()}`, "/v", name, "/f"], { ignoreError: true, silent: true });
|
|
599
533
|
}
|
|
600
534
|
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
const SHORTCUT_LNK_NAME = "pi-web-ui.lnk"; // Windows 桌面快捷方式
|
|
606
|
-
const SHORTCUT_MAC_NAME = "pi-web-ui.command"; // macOS 双击启动器
|
|
607
|
-
const SHORTCUT_LINUX_NAME = "pi-web-ui.desktop"; // Linux 桌面图标
|
|
535
|
+
const SHORTCUT_LNK_NAME = "pi-web-ui.lnk";
|
|
536
|
+
const SHORTCUT_MAC_NAME = "pi-web-ui.command";
|
|
537
|
+
const SHORTCUT_LINUX_NAME = "pi-web-ui.desktop";
|
|
608
538
|
|
|
609
|
-
|
|
610
|
-
const
|
|
611
|
-
const APP_ICO_SOURCE = join(BIN_DIR, "..", "web", "public", "icon.ico"); // 包内品牌图标源文件(10 帧多分辨率,DPI 密度帧保证桌面/任务栏各尺寸颜色不失真)
|
|
612
|
-
/** Branded SVG logo (source of truth: web/public/favicon.svg) — used on Linux. */
|
|
539
|
+
const APP_ICO_NAME = "pi-web-ui-logo.ico";
|
|
540
|
+
const APP_ICO_SOURCE = join(BIN_DIR, "..", "web", "public", "icon.ico");
|
|
613
541
|
const APP_SVG_PACKAGE = join(BIN_DIR, "..", "web", "public", "favicon.svg");
|
|
614
542
|
|
|
615
|
-
/** Windows: per-user copy of the branded .ico (stable path for the .lnk icon). */
|
|
616
543
|
function winIcoPath() {
|
|
617
544
|
return join(winServiceDir(), APP_ICO_NAME);
|
|
618
545
|
}
|
|
619
546
|
|
|
620
|
-
/** Full path to Windows PowerShell. Prefers pwsh.exe (PowerShell 7) when it is
|
|
621
|
-
* resolvable on PATH: some machines ship Windows PowerShell 5.1 as a broken
|
|
622
|
-
* stub whose launch fails silently, so probe for a working shell first and
|
|
623
|
-
* fall back to the built-in path. */
|
|
624
547
|
function winPowershell() {
|
|
625
548
|
const which = spawnSync("where.exe", ["pwsh.exe"], { encoding: "utf8" });
|
|
626
549
|
if (which.status === 0) {
|
|
@@ -630,28 +553,14 @@ function winPowershell() {
|
|
|
630
553
|
return join(process.env.SystemRoot ?? "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
631
554
|
}
|
|
632
555
|
|
|
633
|
-
/** Full path to wscript.exe — a console-free host (no conhost window, so no black
|
|
634
|
-
* console box ever appears in the taskbar on double-click). Used as the .lnk target;
|
|
635
|
-
* it launches the .ps1 hidden via a thin VBS launcher. */
|
|
636
556
|
function winWscript() {
|
|
637
557
|
return join(process.env.SystemRoot ?? "C:\\Windows", "System32", "wscript.exe");
|
|
638
558
|
}
|
|
639
559
|
|
|
640
|
-
/**
|
|
641
|
-
* The node binary the launcher scripts must bake in: the executable this
|
|
642
|
-
* process itself runs on. Under Bun this resolves to bun, so a Bun-hosted
|
|
643
|
-
* install never bakes in pi.exe.
|
|
644
|
-
*/
|
|
645
560
|
function resolveNode() {
|
|
646
561
|
return process.execPath;
|
|
647
562
|
}
|
|
648
563
|
|
|
649
|
-
/**
|
|
650
|
-
* Resolve the real node binary. fnm/volta/nvm shims (e.g. fnm_multishells)
|
|
651
|
-
* point into temp dirs that vanish when the installing shell exits — the
|
|
652
|
-
* baked-in launcher scripts must use the stable real path instead.
|
|
653
|
-
* Also applies resolveNode() so Bun-hosted pi never bakes in pi.exe.
|
|
654
|
-
*/
|
|
655
564
|
function realNode() {
|
|
656
565
|
try {
|
|
657
566
|
return realpathSync(resolveNode());
|
|
@@ -660,22 +569,18 @@ function realNode() {
|
|
|
660
569
|
}
|
|
661
570
|
}
|
|
662
571
|
|
|
663
|
-
/** Windows: launcher ps1 the desktop .lnk runs (hidden). */
|
|
664
572
|
function winShortcutPs1Path(name) {
|
|
665
573
|
return join(winServiceDir(), `${name}-shortcut.ps1`);
|
|
666
574
|
}
|
|
667
575
|
|
|
668
|
-
/** Windows: launcher vbs the desktop .lnk actually runs (wscript.exe, console-free). */
|
|
669
576
|
function winShortcutVbsPath(name) {
|
|
670
577
|
return join(winServiceDir(), `${name}-shortcut.vbs`);
|
|
671
578
|
}
|
|
672
579
|
|
|
673
|
-
/** Windows: PID file of a shortcut-started (no scheduled task) instance. */
|
|
674
580
|
function winPidFilePath(name) {
|
|
675
581
|
return join(winServiceDir(), `${name}.pid`);
|
|
676
582
|
}
|
|
677
583
|
|
|
678
|
-
/** Read the recorded PID of a shortcut-started Windows instance. */
|
|
679
584
|
function winReadPid(name) {
|
|
680
585
|
try {
|
|
681
586
|
const pid = Number(readFileSync(winPidFilePath(name), "utf8").trim());
|
|
@@ -685,7 +590,6 @@ function winReadPid(name) {
|
|
|
685
590
|
}
|
|
686
591
|
}
|
|
687
592
|
|
|
688
|
-
/** True when a PID exists (signal 0; EPERM means exists but not ours). */
|
|
689
593
|
function pidAlive(pid) {
|
|
690
594
|
if (!pid) return false;
|
|
691
595
|
try {
|
|
@@ -696,18 +600,10 @@ function pidAlive(pid) {
|
|
|
696
600
|
}
|
|
697
601
|
}
|
|
698
602
|
|
|
699
|
-
/** Single-quote a string for embedding in a POSIX shell script. */
|
|
700
603
|
function shQuote(s) {
|
|
701
604
|
return "'" + s.replace(/'/g, `'\\''`) + "'";
|
|
702
605
|
}
|
|
703
606
|
|
|
704
|
-
/**
|
|
705
|
-
* Windows shortcut launcher. Double-click the .lnk → this script runs hidden:
|
|
706
|
-
* server already up → just open the browser; autostart service installed
|
|
707
|
-
* (HKCU Run key + wscript/VBS launcher) → start it (manageable via `server
|
|
708
|
-
* stop`); otherwise run the server in the foreground of this hidden window and
|
|
709
|
-
* record its PID so `server stop` / `server uninstall` can terminate it too.
|
|
710
|
-
*/
|
|
711
607
|
function buildWinShortcutPs1(env, cwd, taskName, url, logPath, pidPath) {
|
|
712
608
|
const sets = Object.entries(env)
|
|
713
609
|
.map(([k, v]) => `$env:${k} = ${psQuote(v)}`)
|
|
@@ -764,22 +660,8 @@ function buildWinShortcutPs1(env, cwd, taskName, url, logPath, pidPath) {
|
|
|
764
660
|
].join("\r\n");
|
|
765
661
|
}
|
|
766
662
|
|
|
767
|
-
/**
|
|
768
|
-
* Build the tiny VBS launcher that starts a .ps1 *without* creating any console
|
|
769
|
-
* host: wscript.exe has no console, and WScript.Shell.Run(…, 0, False) launches
|
|
770
|
-
* the child hidden and returns at once (0 = hidden window, False = don't wait).
|
|
771
|
-
* Used by both the desktop .lnk and the logon autostart service. Note:
|
|
772
|
-
* `powershell -WindowStyle Hidden` alone is unreliable when Windows itself
|
|
773
|
-
* spawns the process (Task Scheduler) — the console window can still show;
|
|
774
|
-
* this launcher never creates one at all.
|
|
775
|
-
*/
|
|
776
663
|
function buildWinHiddenVbs(ps1Path) {
|
|
777
|
-
// 可执行文件必须带引号:winPowershell() 常返回 `C:\Program Files\PowerShell\7\pwsh.exe`,
|
|
778
|
-
// 含空格且未加引号时 WScript.Shell.Run 找不到文件,直接报 80070002(系统找不到指定的文件)。
|
|
779
664
|
const cmd = `"${winPowershell()}" -NoProfile -NonInteractive -ExecutionPolicy Bypass -WindowStyle Hidden -File "${ps1Path}"`;
|
|
780
|
-
// VBScript 字符串没有 \" 转义(也没有 \uXXXX),内嵌引号必须写成 "";
|
|
781
|
-
// 不能用 JSON.stringify —— 它输出 \" 会在 VBScript 里提前结束字符串(语句未结束 800A0401),
|
|
782
|
-
// 且会把非 ASCII 路径转成 \uXXXX 字面量(wscript 不识别,中文用户名直接变成乱码路径)。
|
|
783
665
|
const vbsCmd = cmd.replace(/"/g, '""');
|
|
784
666
|
return [
|
|
785
667
|
"Option Explicit",
|
|
@@ -792,18 +674,9 @@ function buildWinHiddenVbs(ps1Path) {
|
|
|
792
674
|
].join("\r\n");
|
|
793
675
|
}
|
|
794
676
|
|
|
795
|
-
/**
|
|
796
|
-
* Create the Windows desktop .lnk via WScript.Shell COM (correct Desktop path
|
|
797
|
-
* even with OneDrive redirection). Target is powershell.exe with
|
|
798
|
-
* -WindowStyle Hidden so nothing flashes on double-click.
|
|
799
|
-
*/
|
|
800
677
|
function installWinShortcut(opts) {
|
|
801
678
|
const { name, port, cwd, dataDir, engine, host, agentDir } = serviceOptions(opts);
|
|
802
679
|
const env = serviceEnv(port, cwd, dataDir, engine, host, agentDir);
|
|
803
|
-
// The server binds 127.0.0.1 by default; PowerShell 7's Invoke-WebRequest
|
|
804
|
-
// resolves `localhost` to ::1 first and hangs until TimeoutSec when nothing
|
|
805
|
-
// listens on IPv6, making the health probe misfire ("server not running").
|
|
806
|
-
// Pin the probe (and the opened URL) to the IPv4 loopback the server uses.
|
|
807
680
|
const url = `http://127.0.0.1:${port}`;
|
|
808
681
|
const ps1Path = winShortcutPs1Path(name);
|
|
809
682
|
const ps1 = buildWinShortcutPs1(env, cwd, name, url, winLogPath(name), winPidFilePath(name));
|
|
@@ -812,11 +685,9 @@ function installWinShortcut(opts) {
|
|
|
812
685
|
return;
|
|
813
686
|
}
|
|
814
687
|
mkdirSync(dirname(ps1Path), { recursive: true });
|
|
815
|
-
writeFileSync(ps1Path, "\uFEFF" + ps1, "utf8");
|
|
816
|
-
// wscript host + VBS launcher: no console window / taskbar black box on double-click.
|
|
688
|
+
writeFileSync(ps1Path, "\uFEFF" + ps1, "utf8");
|
|
817
689
|
const vbsPath = winShortcutVbsPath(name);
|
|
818
|
-
writeFileSync(vbsPath, "\uFEFF" + buildWinHiddenVbs(ps1Path), "utf16le");
|
|
819
|
-
// 把品牌图标准备好:复制到用户目录(.lnk 图标指向稳定路径)
|
|
690
|
+
writeFileSync(vbsPath, "\uFEFF" + buildWinHiddenVbs(ps1Path), "utf16le");
|
|
820
691
|
if (existsSync(APP_ICO_SOURCE)) {
|
|
821
692
|
copyFileSync(APP_ICO_SOURCE, winIcoPath());
|
|
822
693
|
} else {
|
|
@@ -866,7 +737,6 @@ function installWinShortcut(opts) {
|
|
|
866
737
|
console.log(ZH ? ` 目录 : ${cwd}` : ` Directory : ${cwd}`);
|
|
867
738
|
}
|
|
868
739
|
|
|
869
|
-
/** macOS: double-clickable .command launcher (the .lnk equivalent). */
|
|
870
740
|
function buildMacShortcut(label, plist, url, env) {
|
|
871
741
|
const exports = Object.entries(env)
|
|
872
742
|
.map(([k, v]) => `export ${k}=${shQuote(v)}`)
|
|
@@ -943,7 +813,6 @@ function installMacShortcut(opts) {
|
|
|
943
813
|
console.log(ZH ? ` 目录 : ${cwd}` : ` Directory : ${cwd}`);
|
|
944
814
|
}
|
|
945
815
|
|
|
946
|
-
/** Linux: launcher script run by the .desktop icon. */
|
|
947
816
|
function buildLinuxStartScript(unitName, url) {
|
|
948
817
|
const log = join(homedir(), ".local", "share", "pi-web-ui", "pi-web-ui.log");
|
|
949
818
|
const node = realNode();
|
|
@@ -984,7 +853,7 @@ function installLinuxShortcut(opts) {
|
|
|
984
853
|
const scriptDir = join(homedir(), ".local", "share", "pi-web-ui");
|
|
985
854
|
const scriptPath = join(scriptDir, `${name}-start.sh`);
|
|
986
855
|
const desktopPath = join(homedir(), "Desktop", SHORTCUT_LINUX_NAME);
|
|
987
|
-
const icoPath = join(scriptDir, APP_ICO_NAME);
|
|
856
|
+
const icoPath = join(scriptDir, APP_ICO_NAME);
|
|
988
857
|
const svgPath = join(scriptDir, "pi-web-ui.svg");
|
|
989
858
|
const script = buildLinuxStartScript(name, url);
|
|
990
859
|
const desktopIcon = existsSync(APP_SVG_PACKAGE) ? svgPath : APP_ICO_NAME;
|
|
@@ -1004,14 +873,12 @@ Categories=Network;WebBrowser;
|
|
|
1004
873
|
return;
|
|
1005
874
|
}
|
|
1006
875
|
mkdirSync(scriptDir, { recursive: true });
|
|
1007
|
-
// 品牌图标(缺失时跳过,桌面自动回退默认图标)
|
|
1008
876
|
if (existsSync(APP_SVG_PACKAGE)) copyFileSync(APP_SVG_PACKAGE, svgPath);
|
|
1009
877
|
else if (existsSync(APP_ICO_SOURCE)) copyFileSync(APP_ICO_SOURCE, icoPath);
|
|
1010
878
|
writeFileSync(scriptPath, script);
|
|
1011
879
|
chmodSync(scriptPath, 0o755);
|
|
1012
880
|
writeFileSync(desktopPath, desktop);
|
|
1013
881
|
chmodSync(desktopPath, 0o755);
|
|
1014
|
-
// GNOME 需要标记可信才能双击运行
|
|
1015
882
|
run("gio", ["set", desktopPath, "metadata::trusted", "true"], {
|
|
1016
883
|
ignoreError: true,
|
|
1017
884
|
silent: true,
|
|
@@ -1026,7 +893,6 @@ Categories=Network;WebBrowser;
|
|
|
1026
893
|
console.log(ZH ? ` 目录 : ${cwd}` : ` Directory : ${cwd}`);
|
|
1027
894
|
}
|
|
1028
895
|
|
|
1029
|
-
/** Remove desktop shortcut artifacts created by `server shortcut`. */
|
|
1030
896
|
function removeShortcut(name) {
|
|
1031
897
|
if (isWin) {
|
|
1032
898
|
for (const f of [winShortcutPs1Path(name), winShortcutVbsPath(name), winPidFilePath(name), winIcoPath()]) {
|
|
@@ -1057,20 +923,10 @@ function removeShortcut(name) {
|
|
|
1057
923
|
}
|
|
1058
924
|
}
|
|
1059
925
|
|
|
1060
|
-
/** Single-quote a string for embedding in a generated PowerShell script. */
|
|
1061
926
|
function psQuote(s) {
|
|
1062
927
|
return "'" + s.replace(/'/g, "''") + "'";
|
|
1063
928
|
}
|
|
1064
929
|
|
|
1065
|
-
/**
|
|
1066
|
-
* Build the PowerShell launcher the autostart service runs. Windows never sees
|
|
1067
|
-
* a console from it: the HKCU Run key launches wscript.exe → VBS → powershell
|
|
1068
|
-
* (hidden), so no black box can appear. The script sets the env, cd's to the
|
|
1069
|
-
* workspace, records its PID to <name>.pid (for `server stop`), then runs node
|
|
1070
|
-
* inside a watchdog loop — if node exits, it restarts after 10s (same
|
|
1071
|
-
* philosophy as launchd KeepAlive / systemd Restart=always). `server stop`
|
|
1072
|
-
* force-kills the recorded PID tree, which takes the loop down with it.
|
|
1073
|
-
*/
|
|
1074
930
|
function buildWinStartPs1(env, cwd, logPath, pidPath) {
|
|
1075
931
|
const sets = Object.entries(env)
|
|
1076
932
|
.map(([k, v]) => `$env:${k} = ${psQuote(v)}`)
|
|
@@ -1098,7 +954,6 @@ function esc(s) {
|
|
|
1098
954
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1099
955
|
}
|
|
1100
956
|
|
|
1101
|
-
/** Start the autostart service now: wscript runs the VBS hidden and exits at once. */
|
|
1102
957
|
function launchWinService(vbsPath) {
|
|
1103
958
|
const child = spawn(winWscript(), [vbsPath], {
|
|
1104
959
|
detached: true,
|
|
@@ -1108,30 +963,20 @@ function launchWinService(vbsPath) {
|
|
|
1108
963
|
child.unref();
|
|
1109
964
|
}
|
|
1110
965
|
|
|
1111
|
-
/**
|
|
1112
|
-
* PID 文件记录的是看门狗 PowerShell 的 $PID(winPowershell() 可能选 pwsh.exe),
|
|
1113
|
-
* node 是它的子进程 —— 这三者是本服务实例的合理映像名。taskkill /T /F 是树级强杀,
|
|
1114
|
-
* PID 若已退出被系统复用就会误杀无辜进程,所以杀前必须核对映像名。
|
|
1115
|
-
*/
|
|
1116
966
|
const WIN_SERVICE_IMAGE_RE = /^(powershell|pwsh|node)\.exe$/i;
|
|
1117
967
|
|
|
1118
|
-
/** tasklist 查询 PID 对应的进程映像名;查询失败/无此进程返回 null(无法核实)。 */
|
|
1119
968
|
function winPidImageName(pid) {
|
|
1120
969
|
const res = spawnSync("tasklist", ["/FI", `PID eq ${pid}`, "/FO", "CSV", "/NH"], { encoding: "utf8" });
|
|
1121
970
|
if (res.status !== 0) return null;
|
|
1122
971
|
const line = (res.stdout ?? "").split(/\r?\n/).find((l) => l.trim());
|
|
1123
|
-
if (!line) return null;
|
|
972
|
+
if (!line) return null;
|
|
1124
973
|
return (line.match(/^"([^"]+)"/) ?? [])[1] ?? null;
|
|
1125
974
|
}
|
|
1126
975
|
|
|
1127
|
-
/** Kill a running Windows instance via its PID file (whole tree). */
|
|
1128
976
|
function stopWinInstance(name) {
|
|
1129
977
|
const pid = winReadPid(name);
|
|
1130
978
|
if (pid) {
|
|
1131
979
|
if (pidAlive(pid)) {
|
|
1132
|
-
// PID 可能已退出并被系统复用给别的进程:杀前核对映像名,不符则警告并跳过,
|
|
1133
|
-
// 绝不 taskkill /T /F 盲杀。macOS/Linux 无按 PID 杀的路径(launchctl/systemctl
|
|
1134
|
-
// 按服务单元管理),只有 Windows 需要这道核对。
|
|
1135
980
|
const image = winPidImageName(pid);
|
|
1136
981
|
if (image === null) {
|
|
1137
982
|
console.warn(
|
|
@@ -1150,7 +995,6 @@ function stopWinInstance(name) {
|
|
|
1150
995
|
ignoreError: true,
|
|
1151
996
|
silent: true,
|
|
1152
997
|
});
|
|
1153
|
-
// taskkill /F 异步生效:等到进程树真正退出(restart 需要避免端口竞争)
|
|
1154
998
|
const deadline = Date.now() + 5000;
|
|
1155
999
|
while (Date.now() < deadline && pidAlive(pid)) {
|
|
1156
1000
|
spawnSync("ping", ["-n", "2", "127.0.0.1"], { stdio: "ignore" });
|
|
@@ -1161,7 +1005,6 @@ function stopWinInstance(name) {
|
|
|
1161
1005
|
}
|
|
1162
1006
|
}
|
|
1163
1007
|
|
|
1164
|
-
/** Build the launchd plist XML. */
|
|
1165
1008
|
function buildPlist(label, cwd, env) {
|
|
1166
1009
|
const entries = Object.entries(env)
|
|
1167
1010
|
.map(([k, v]) => ` <key>${esc(k)}</key>\n <string>${esc(v)}</string>`)
|
|
@@ -1206,23 +1049,14 @@ ${entries}
|
|
|
1206
1049
|
`;
|
|
1207
1050
|
}
|
|
1208
1051
|
|
|
1209
|
-
/** systemd quoted strings use C-style escapes; %% prevents specifier expansion. */
|
|
1210
1052
|
function systemdQuote(value) {
|
|
1211
1053
|
return JSON.stringify(String(value)).replace(/%/g, "%%");
|
|
1212
1054
|
}
|
|
1213
1055
|
|
|
1214
|
-
/**
|
|
1215
|
-
* systemd paths (WorkingDirectory=) must NOT be quoted: unlike Environment= and
|
|
1216
|
-
* ExecStart=, the path directives do not strip surrounding double quotes, so
|
|
1217
|
-
* WorkingDirectory="/home/me/work" makes systemd fail with "path is not absolute".
|
|
1218
|
-
* The whole (trimmed) value is the path, so inner spaces need no escaping —
|
|
1219
|
-
* only % has to be doubled to survive specifier expansion.
|
|
1220
|
-
*/
|
|
1221
1056
|
function systemdPath(value) {
|
|
1222
1057
|
return String(value).replace(/%/g, "%%");
|
|
1223
1058
|
}
|
|
1224
1059
|
|
|
1225
|
-
/** Build the systemd unit file. */
|
|
1226
1060
|
function buildUnit(cwd, env) {
|
|
1227
1061
|
const envLines = Object.entries(env)
|
|
1228
1062
|
.map(([k, v]) => `Environment=${systemdQuote(`${k}=${v}`)}`)
|
|
@@ -1250,29 +1084,18 @@ WantedBy=multi-user.target
|
|
|
1250
1084
|
`;
|
|
1251
1085
|
}
|
|
1252
1086
|
|
|
1253
|
-
/** If not root on Linux, re-exec the same server command through sudo. */
|
|
1254
1087
|
function ensureRootForSystemctl() {
|
|
1255
1088
|
if (typeof process.getuid === "function" && process.getuid() === 0) return;
|
|
1256
|
-
// process.argv = [node, <bin>, "server", <action>, ...rest] — forward
|
|
1257
|
-
// everything after "server" so flags like --port/--cwd survive.
|
|
1258
1089
|
const res = spawnSync("sudo", [NODE, fileURLToPath(import.meta.url), "server", ...process.argv.slice(3)], {
|
|
1259
1090
|
stdio: "inherit",
|
|
1260
1091
|
});
|
|
1261
1092
|
process.exit(res.status ?? 1);
|
|
1262
1093
|
}
|
|
1263
1094
|
|
|
1264
|
-
/** Resolve the effective HTTP port: --port > $PI_WEB_PORT > 8787. */
|
|
1265
1095
|
function effectivePort(opts) {
|
|
1266
1096
|
return String(opts.port ?? process.env.PI_WEB_PORT ?? "8787");
|
|
1267
1097
|
}
|
|
1268
1098
|
|
|
1269
|
-
/**
|
|
1270
|
-
* 服务名(--name)统一校验。name 会被原样拼进 systemd unit 文件名
|
|
1271
|
-
* (/etc/systemd/system/<name>.service)、Windows 启动脚本/PID 文件路径
|
|
1272
|
-
* (%APPDATA%\pi-web-ui\<name>.ps1) 与 HKCU Run 键值名 —— 不限字符集时,
|
|
1273
|
-
* 路径分隔符/引号/空格都能进这些拼接点(路径穿越或 unit 内容注入)。
|
|
1274
|
-
* 收紧为:字母或数字开头,仅字母/数字/-/_,最长 64 字符。
|
|
1275
|
-
*/
|
|
1276
1099
|
function serviceName(opts) {
|
|
1277
1100
|
const name = opts.name ?? "pi-web-ui";
|
|
1278
1101
|
if (!/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(name))
|
|
@@ -1284,19 +1107,12 @@ function serviceName(opts) {
|
|
|
1284
1107
|
return name;
|
|
1285
1108
|
}
|
|
1286
1109
|
|
|
1287
|
-
/** Shared option normalization for install. */
|
|
1288
1110
|
function serviceOptions(opts) {
|
|
1289
1111
|
const name = serviceName(opts);
|
|
1290
1112
|
const port = effectivePort(opts);
|
|
1291
1113
|
if (!/^\d{1,5}$/.test(port) || Number(port) < 1 || Number(port) > 65535) {
|
|
1292
1114
|
fail(ZH ? `无效端口: ${port}` : `Invalid port: ${port}`);
|
|
1293
1115
|
}
|
|
1294
|
-
// 服务默认工作区(issue #295):安装命令的当前目录不可靠(例如 Windows 提权提示符
|
|
1295
|
-
// 默认在 C:\WINDOWS\system32),且直接拿用户主目录当 agent cwd 会让 SDK 的
|
|
1296
|
-
// resourceLoader.reload 等同步目录扫描落在 $HOME 上 —— 家目录下的 iCloud 占位符、
|
|
1297
|
-
// 外部/网络卷坏挂载会让 scandir/open 在内核里挂起,整个事件循环假死(hello 后永远
|
|
1298
|
-
// 收不到 ready)。默认落到干净的 ~/pi-web-ui 子目录(不存在即建);显式 --cwd /
|
|
1299
|
-
// PI_WEB_CWD 保持原语义(不存在则报错)。前台启动仍默认当前目录。
|
|
1300
1116
|
const explicitCwd = opts.cwd ?? process.env.PI_WEB_CWD;
|
|
1301
1117
|
const cwd = resolve(explicitCwd ?? join(homedir(), "pi-web-ui"));
|
|
1302
1118
|
if (explicitCwd) {
|
|
@@ -1310,7 +1126,6 @@ function serviceOptions(opts) {
|
|
|
1310
1126
|
} else if (process.env.PI_WEB_DATA_DIR) {
|
|
1311
1127
|
dataDir = resolve(process.env.PI_WEB_DATA_DIR);
|
|
1312
1128
|
}
|
|
1313
|
-
// 引擎/监听地址/agent 配置目录:flag 优先,环境变量后备(token 不走命令行,仅环境变量)。
|
|
1314
1129
|
const engine = opts.engine ?? process.env.PI_WEB_ENGINE ?? "pi";
|
|
1315
1130
|
if (!["pi", "dsh", "claude", "codex", "durable"].includes(engine))
|
|
1316
1131
|
fail(
|
|
@@ -1328,16 +1143,10 @@ function serviceEnv(port, cwd, dataDir, engine, host, agentDir, service = {}) {
|
|
|
1328
1143
|
PI_WEB_PORT: port,
|
|
1329
1144
|
PI_WEB_CWD: cwd,
|
|
1330
1145
|
};
|
|
1331
|
-
// 启动来源标记(见 server/launch-origin.ts):只有真正被平台服务管理器托管的
|
|
1332
|
-
// 启动器才写。桌面快捷方式 / .command 在「未安装服务」时是前台跑(退出不回来),
|
|
1333
|
-
// 不能带这个标记,所以它们不传 service。已装好的老服务没有这两个变量,服务端
|
|
1334
|
-
// 仍能靠运行时判据(XPC_SERVICE_NAME / INVOCATION_ID / PID 文件)认出来。
|
|
1335
1146
|
if (service.name) {
|
|
1336
1147
|
env.PI_WEB_LAUNCHED_BY = "service";
|
|
1337
1148
|
env.PI_WEB_SERVICE_NAME = service.name;
|
|
1338
1149
|
}
|
|
1339
|
-
// Interactive Windows tasks inherit the user's PATH; only systemd/launchd
|
|
1340
|
-
// run with a minimal environment that needs an explicit PATH.
|
|
1341
1150
|
if (!isWin) {
|
|
1342
1151
|
const defaultPath =
|
|
1343
1152
|
process.platform === "darwin"
|
|
@@ -1350,14 +1159,10 @@ function serviceEnv(port, cwd, dataDir, engine, host, agentDir, service = {}) {
|
|
|
1350
1159
|
env.PATH = currentPath;
|
|
1351
1160
|
}
|
|
1352
1161
|
}
|
|
1353
|
-
// Same for the locale: launchd/systemd drop LANG/LC_ALL, and a C-locale
|
|
1354
|
-
// shell garbles multibyte input in the terminal (UTF-8 continuation
|
|
1355
|
-
// bytes 0x80–0x9F rendered as C1 control chars). Bake the installing
|
|
1356
|
-
// shell's locale into the service env so spawned terminals are UTF-8.
|
|
1357
1162
|
if (!isWin && process.env.LANG) env.LANG = process.env.LANG;
|
|
1358
1163
|
if (!isWin && process.env.LC_ALL) env.LC_ALL = process.env.LC_ALL;
|
|
1359
1164
|
if (dataDir) env.PI_WEB_DATA_DIR = dataDir;
|
|
1360
|
-
if (engine !== "pi") env.PI_WEB_ENGINE = engine;
|
|
1165
|
+
if (engine !== "pi") env.PI_WEB_ENGINE = engine;
|
|
1361
1166
|
if (host) env.PI_WEB_HOST = host;
|
|
1362
1167
|
if (agentDir) env.PI_CODING_AGENT_DIR = agentDir;
|
|
1363
1168
|
return env;
|
|
@@ -1372,7 +1177,6 @@ function installLaunchd(opts) {
|
|
|
1372
1177
|
console.log(`# ${plist}\n${content}`);
|
|
1373
1178
|
return;
|
|
1374
1179
|
}
|
|
1375
|
-
// Unload any existing instance (ignore "not loaded"), then (re)install.
|
|
1376
1180
|
run("launchctl", ["bootout", `gui/${uid()}/${label}`], {
|
|
1377
1181
|
ignoreError: true,
|
|
1378
1182
|
silent: true,
|
|
@@ -1399,8 +1203,6 @@ function installLaunchd(opts) {
|
|
|
1399
1203
|
);
|
|
1400
1204
|
}
|
|
1401
1205
|
|
|
1402
|
-
/** Elevate only the privileged operation, not the CLI that captures the user's environment.
|
|
1403
|
-
* Unit contents travel through stdin, never argv (which may expose the token via ps). */
|
|
1404
1206
|
function runSystemdRoot(command, args, input) {
|
|
1405
1207
|
const root = typeof process.getuid === "function" && process.getuid() === 0;
|
|
1406
1208
|
const result = spawnSync(root ? command : "sudo", root ? args : ["--", command, ...args], {
|
|
@@ -1422,9 +1224,6 @@ function installSystemd(opts) {
|
|
|
1422
1224
|
console.log(`# ${unitPath}\n${content}`);
|
|
1423
1225
|
return;
|
|
1424
1226
|
}
|
|
1425
|
-
// Generated units can contain credentials. install also corrects an existing unit's mode.
|
|
1426
|
-
// Stage through a temp file: `install /dev/stdin` fails on some hosts (WSL) with
|
|
1427
|
-
// ENXIO when stdin is a pipe rather than a tty.
|
|
1428
1227
|
const staged = join(tmpdir(), `pi-web-ui-${name}-${process.pid}.service`);
|
|
1429
1228
|
writeFileSync(staged, content, { mode: 0o600 });
|
|
1430
1229
|
try {
|
|
@@ -1434,7 +1233,6 @@ function installSystemd(opts) {
|
|
|
1434
1233
|
}
|
|
1435
1234
|
runSystemdRoot("systemctl", ["daemon-reload"]);
|
|
1436
1235
|
runSystemdRoot("systemctl", ["enable", `${name}.service`]);
|
|
1437
|
-
// enable --now does not restart an already-active unit after configuration changes.
|
|
1438
1236
|
runSystemdRoot("systemctl", ["restart", `${name}.service`]);
|
|
1439
1237
|
console.log(
|
|
1440
1238
|
ZH ? `✅ 已安装并启动 systemd 服务 ${name}.service` : `✅ systemd service installed and started ${name}.service`,
|
|
@@ -1498,7 +1296,6 @@ function installWindows(opts) {
|
|
|
1498
1296
|
const pidPath = winPidFilePath(name);
|
|
1499
1297
|
const ps1 = buildWinStartPs1(env, cwd, winLogPath(name), pidPath);
|
|
1500
1298
|
const vbs = buildWinHiddenVbs(ps1Path);
|
|
1501
|
-
// HKCU Run 键值:wscript.exe 以隐藏方式启动 VBS(无控制台,登录后自启)
|
|
1502
1299
|
const runValue = `"${winWscript()}" "${vbsPath}"`;
|
|
1503
1300
|
if (opts.print) {
|
|
1504
1301
|
console.log(`# ${ps1Path}\n${ps1}`);
|
|
@@ -1508,18 +1305,14 @@ function installWindows(opts) {
|
|
|
1508
1305
|
return;
|
|
1509
1306
|
}
|
|
1510
1307
|
mkdirSync(dirname(ps1Path), { recursive: true });
|
|
1511
|
-
// UTF-8 with BOM: Windows PowerShell 5.1 misreads BOM-less UTF-8 as ANSI.
|
|
1512
1308
|
writeFileSync(ps1Path, "\uFEFF" + ps1, "utf8");
|
|
1513
|
-
|
|
1514
|
-
writeFileSync(vbsPath, "\uFEFF" + vbs, "utf16le"); // wscript 只认 UTF-16/ANSI,UTF-8 BOM 会报“无效字符”
|
|
1515
|
-
// 迁移:移除旧版 .cmd 包装与历史计划任务(普通用户下 schtasks 无法创建,改为 Run 键)。
|
|
1309
|
+
writeFileSync(vbsPath, "\uFEFF" + vbs, "utf16le");
|
|
1516
1310
|
if (existsSync(winCmdPath(name))) rmSync(winCmdPath(name));
|
|
1517
1311
|
if (winTaskExists(name)) {
|
|
1518
1312
|
run("schtasks", ["/End", "/TN", name], {
|
|
1519
1313
|
ignoreError: true,
|
|
1520
1314
|
silent: true,
|
|
1521
1315
|
});
|
|
1522
|
-
// /End 异步生效:稍候再删任务,避免新实例与旧实例端口竞争
|
|
1523
1316
|
spawnSync("ping", ["-n", "2", "127.0.0.1"], { stdio: "ignore" });
|
|
1524
1317
|
run("schtasks", ["/Delete", "/TN", name, "/F"], {
|
|
1525
1318
|
ignoreError: true,
|
|
@@ -1557,11 +1350,9 @@ function installWindows(opts) {
|
|
|
1557
1350
|
function uninstallWindows(opts) {
|
|
1558
1351
|
const name = serviceName(opts);
|
|
1559
1352
|
winRunKeyDelete(name);
|
|
1560
|
-
// 历史计划任务(旧版本 install 可能注册过)
|
|
1561
1353
|
if (winTaskExists(name)) {
|
|
1562
1354
|
run("schtasks", ["/Delete", "/TN", name, "/F"], { ignoreError: true });
|
|
1563
1355
|
}
|
|
1564
|
-
// 运行中的实例(服务或快捷方式启动,均记录 PID 文件)
|
|
1565
1356
|
stopWinInstance(name);
|
|
1566
1357
|
for (const f of [winCmdPath(name), winPs1Path(name), winVbsPath(name), winTaskXmlPath(name)]) {
|
|
1567
1358
|
if (existsSync(f)) rmSync(f);
|
|
@@ -1575,15 +1366,6 @@ function uninstallWindows(opts) {
|
|
|
1575
1366
|
console.log(ZH ? `🗑 已移除桌面快捷方式` : `🗑 Desktop shortcut removed`);
|
|
1576
1367
|
}
|
|
1577
1368
|
|
|
1578
|
-
// ---------------------------------------------------------------------------
|
|
1579
|
-
// ---------------------------------------------------------------------------
|
|
1580
|
-
// Local control socket (status / quiesce / unquiesce). The server listens on
|
|
1581
|
-
// a mode-0600 Unix socket (POSIX) or a named pipe (Windows) under its data
|
|
1582
|
-
// dir; same path rules as server/control-socket.ts so the CLI and server
|
|
1583
|
-
// always agree without sharing code.
|
|
1584
|
-
// ---------------------------------------------------------------------------
|
|
1585
|
-
|
|
1586
|
-
/** Resolve the control socket path for the given options. */
|
|
1587
1369
|
function controlPath(opts) {
|
|
1588
1370
|
const dir = opts.dataDir
|
|
1589
1371
|
? resolve(opts.dataDir)
|
|
@@ -1593,7 +1375,6 @@ function controlPath(opts) {
|
|
|
1593
1375
|
return isWin ? `\\\\.\\pipe\\pi-web-ui-${effectivePort(opts)}` : join(dir, "pi-web-ui.sock");
|
|
1594
1376
|
}
|
|
1595
1377
|
|
|
1596
|
-
/** Send one control command to a RUNNING server; resolves null if unreachable. */
|
|
1597
1378
|
function controlCommand(opts, cmd) {
|
|
1598
1379
|
const path = controlPath(opts);
|
|
1599
1380
|
return new Promise((resolvePromise) => {
|
|
@@ -1650,13 +1431,10 @@ function getLocalLanIpv4s() {
|
|
|
1650
1431
|
}
|
|
1651
1432
|
}
|
|
1652
1433
|
}
|
|
1653
|
-
} catch {
|
|
1654
|
-
// best-effort
|
|
1655
|
-
}
|
|
1434
|
+
} catch {}
|
|
1656
1435
|
return ips;
|
|
1657
1436
|
}
|
|
1658
1437
|
|
|
1659
|
-
/** 格式化打印服务的访问链接(包含本机、局域网 IP 与 Token / Setup 入口) */
|
|
1660
1438
|
function printServiceUrls(port, host, token = "") {
|
|
1661
1439
|
const tokenSuffix = token ? `?token=${token}` : "";
|
|
1662
1440
|
const isLoopback = !host || isLocalLoopback(host);
|
|
@@ -1694,7 +1472,6 @@ function printServiceUrls(port, host, token = "") {
|
|
|
1694
1472
|
);
|
|
1695
1473
|
}
|
|
1696
1474
|
|
|
1697
|
-
/** 轮询等待后台服务就绪并打印包含实时 token 的访问信息 */
|
|
1698
1475
|
async function printRunningServiceAccess(opts, host, fallbackToken = "") {
|
|
1699
1476
|
const t0 = Date.now();
|
|
1700
1477
|
let st = null;
|
|
@@ -1707,7 +1484,6 @@ async function printRunningServiceAccess(opts, host, fallbackToken = "") {
|
|
|
1707
1484
|
printServiceUrls(effectivePort(opts), host, token);
|
|
1708
1485
|
}
|
|
1709
1486
|
|
|
1710
|
-
/** Append the live server status (via the control socket) to `server status`. */
|
|
1711
1487
|
async function printLiveStatus(opts) {
|
|
1712
1488
|
const st = await controlCommand(opts, "status");
|
|
1713
1489
|
if (!st || !st.ok) {
|
|
@@ -1725,8 +1501,6 @@ async function printLiveStatus(opts) {
|
|
|
1725
1501
|
}
|
|
1726
1502
|
console.log(ZH ? ` 版本 : ${st.version} · PID ${st.pid}` : ` Version : ${st.version} · PID ${st.pid}`);
|
|
1727
1503
|
console.log(ZH ? ` 目录 : ${st.cwd}` : ` Directory : ${st.cwd}`);
|
|
1728
|
-
// 启动来源(server/launch-origin.ts):有 supervisor = 这个进程退出后会被自动
|
|
1729
|
-
// 拉起(server restart / 更新面板的「重启服务」才有意义)。
|
|
1730
1504
|
console.log(
|
|
1731
1505
|
ZH
|
|
1732
1506
|
? ` 启动 : ${
|
|
@@ -1752,7 +1526,6 @@ async function printLiveStatus(opts) {
|
|
|
1752
1526
|
);
|
|
1753
1527
|
}
|
|
1754
1528
|
|
|
1755
|
-
/** `server quiesce|unquiesce` — toggle the admission gate on a RUNNING server. */
|
|
1756
1529
|
async function setQuiesce(opts, on) {
|
|
1757
1530
|
const st = await controlCommand(opts, on ? "quiesce" : "unquiesce");
|
|
1758
1531
|
if (!st || !st.ok) {
|
|
@@ -1859,7 +1632,7 @@ function controlService(action, opts) {
|
|
|
1859
1632
|
|
|
1860
1633
|
if (isWin) {
|
|
1861
1634
|
const installed = winRunKeyInstalled(name);
|
|
1862
|
-
const legacy = !installed && winTaskExists(name);
|
|
1635
|
+
const legacy = !installed && winTaskExists(name);
|
|
1863
1636
|
|
|
1864
1637
|
if (action === "status") {
|
|
1865
1638
|
const pid = winReadPid(name);
|
|
@@ -1989,11 +1762,6 @@ function controlService(action, opts) {
|
|
|
1989
1762
|
);
|
|
1990
1763
|
}
|
|
1991
1764
|
|
|
1992
|
-
// ---------------------------------------------------------------------------
|
|
1993
|
-
// 界面插件管理(<dataDir>/plugins/,从 GitHub 安装)
|
|
1994
|
-
// ---------------------------------------------------------------------------
|
|
1995
|
-
|
|
1996
|
-
/** 合法插件 id(同 server/plugins.ts 的 ID_RE)。 */
|
|
1997
1765
|
const PLUGIN_ID_RE = /^[A-Za-z0-9_-]+$/;
|
|
1998
1766
|
|
|
1999
1767
|
const PLUGIN_HELP = ZH
|
|
@@ -2092,7 +1860,6 @@ function pluginDataDir(opts) {
|
|
|
2092
1860
|
return resolve(opts.dataDir ?? process.env.PI_WEB_DATA_DIR ?? join(homedir(), ".pi-web"));
|
|
2093
1861
|
}
|
|
2094
1862
|
|
|
2095
|
-
/** 解析安装源为 { owner, repo, ref, subpath, cloneUrl } 或本地路径;非法输入直接退出。 */
|
|
2096
1863
|
function parsePluginSource(rawSpec) {
|
|
2097
1864
|
let spec = rawSpec.trim();
|
|
2098
1865
|
let ref;
|
|
@@ -2107,7 +1874,6 @@ function parsePluginSource(rawSpec) {
|
|
|
2107
1874
|
);
|
|
2108
1875
|
spec = spec.slice(0, hash).replace(/\/+$/, "");
|
|
2109
1876
|
}
|
|
2110
|
-
// ssh 形式转 https 拉取(不要求本机配 ssh key);URL 去掉协议前缀统一按路径段解析
|
|
2111
1877
|
const ssh = spec.match(/^git@([^:]+):(.+?)(?:\.git)?$/);
|
|
2112
1878
|
if (ssh) [, , spec] = ssh;
|
|
2113
1879
|
else {
|
|
@@ -2116,7 +1882,6 @@ function parsePluginSource(rawSpec) {
|
|
|
2116
1882
|
}
|
|
2117
1883
|
const segs = spec.split("/").filter(Boolean);
|
|
2118
1884
|
if (segs.length < 2) {
|
|
2119
|
-
// 单段名称(如 browser-use):若本地随包官方插件或 catalog 存在该 id,自动补齐为官方插件源
|
|
2120
1885
|
if (segs.length === 1 && PLUGIN_ID_RE.test(segs[0])) {
|
|
2121
1886
|
const id = segs[0];
|
|
2122
1887
|
const pkgRoot = resolve(BIN_DIR, "..");
|
|
@@ -2157,12 +1922,11 @@ function parsePluginSource(rawSpec) {
|
|
|
2157
1922
|
if (!ref && segs.length > 3) ref = segs[3];
|
|
2158
1923
|
subpath = segs.slice(4).join("/") || undefined;
|
|
2159
1924
|
} else if (segs.length > 2) {
|
|
2160
|
-
subpath = segs.slice(2).join("/");
|
|
1925
|
+
subpath = segs.slice(2).join("/");
|
|
2161
1926
|
}
|
|
2162
1927
|
return { owner, repo, ref, subpath, cloneUrl: `https://github.com/${owner}/${repo}.git` };
|
|
2163
1928
|
}
|
|
2164
1929
|
|
|
2165
|
-
/** 清理临时目录下残留超过 1 小时的 pi-web-ui-plugin-* 安装目录。 */
|
|
2166
1930
|
function cleanStalePluginTmpDirs() {
|
|
2167
1931
|
try {
|
|
2168
1932
|
const base = tmpdir();
|
|
@@ -2182,13 +1946,6 @@ function cleanStalePluginTmpDirs() {
|
|
|
2182
1946
|
} catch {}
|
|
2183
1947
|
}
|
|
2184
1948
|
|
|
2185
|
-
/**
|
|
2186
|
-
* 尝试定位随包自带的内置官方插件目录。
|
|
2187
|
-
* 命中条件:
|
|
2188
|
-
* 1. 未开启强制远端拉取标志(opts.remote / PI_WEB_PLUGIN_FORCE_REMOTE);
|
|
2189
|
-
* 2. 未显式指定非主干 git ref(除 main/master/HEAD 之外的 ref 说明用户想试特定提交);
|
|
2190
|
-
* 3. 属于官方仓库(xing-shuyin/pi-web-ui)的 plugins/<id> 子路径,且随包目录存在合法 manifest.json。
|
|
2191
|
-
*/
|
|
2192
1949
|
function resolveLocalBuiltinPluginDir(rawSpec, src, opts = {}) {
|
|
2193
1950
|
if (opts.remote === true || process.env.PI_WEB_PLUGIN_FORCE_REMOTE === "1") return null;
|
|
2194
1951
|
if (src?.ref && src.ref !== "main" && src.ref !== "master" && src.ref !== "HEAD") return null;
|
|
@@ -2210,19 +1967,11 @@ function resolveLocalBuiltinPluginDir(rawSpec, src, opts = {}) {
|
|
|
2210
1967
|
return null;
|
|
2211
1968
|
}
|
|
2212
1969
|
|
|
2213
|
-
/**
|
|
2214
|
-
* 把仓库拉到 tmpDir 并返回检出根目录。
|
|
2215
|
-
* 优化策略:
|
|
2216
|
-
* 1. 共享缓存复用:同一批量操作/同源仓库共享检出,增量 sparse-checkout add,杜绝反复 clone;
|
|
2217
|
-
* 2. 稀疏拉取(Sparse Checkout + Blobless filter):只拉取元数据与目标子目录,免除全量下载数十兆整仓;
|
|
2218
|
-
* 3. 健壮降级:稀疏失败平滑降级常规 shallow clone,再失败回退 tarball 直连。
|
|
2219
|
-
*/
|
|
2220
1970
|
async function acquireRepo(src, tmpDir, opts = {}) {
|
|
2221
1971
|
const sharedCache = opts.sharedCache;
|
|
2222
1972
|
const cacheKey = sharedCache ? `${src.cloneUrl}#${src.ref || "HEAD"}` : null;
|
|
2223
1973
|
const normalizedSubpath = src.subpath ? src.subpath.split(/[\\/]/).filter(Boolean).join("/") : null;
|
|
2224
1974
|
|
|
2225
|
-
// 1. 尝试从共享缓存中复用已有检出
|
|
2226
1975
|
if (sharedCache && cacheKey && sharedCache.has(cacheKey)) {
|
|
2227
1976
|
const cached = sharedCache.get(cacheKey);
|
|
2228
1977
|
if (existsSync(cached.dir)) {
|
|
@@ -2260,7 +2009,6 @@ async function acquireRepo(src, tmpDir, opts = {}) {
|
|
|
2260
2009
|
const gitTimeout = Number(process.env.PI_WEB_GIT_TIMEOUT_MS) || 45_000;
|
|
2261
2010
|
const gitEnv = { ...process.env, GIT_TERMINAL_PROMPT: "0", GCM_INTERACTIVE: "never" };
|
|
2262
2011
|
|
|
2263
|
-
// 2. 稀疏拉取:当指定了 subpath 时,优先尝试 --filter=blob:none --sparse
|
|
2264
2012
|
if (normalizedSubpath) {
|
|
2265
2013
|
const sparseArgs = [
|
|
2266
2014
|
"-c",
|
|
@@ -2309,7 +2057,6 @@ async function acquireRepo(src, tmpDir, opts = {}) {
|
|
|
2309
2057
|
}
|
|
2310
2058
|
}
|
|
2311
2059
|
}
|
|
2312
|
-
// 稀疏拉取失败,清理已产生的残骸,准备降级
|
|
2313
2060
|
if (existsSync(dst)) {
|
|
2314
2061
|
try {
|
|
2315
2062
|
rmSync(dst, { recursive: true, force: true });
|
|
@@ -2320,7 +2067,6 @@ async function acquireRepo(src, tmpDir, opts = {}) {
|
|
|
2320
2067
|
);
|
|
2321
2068
|
}
|
|
2322
2069
|
|
|
2323
|
-
// 3. 常规 shallow clone(未指定 subpath 或稀疏拉取失败时的降级通路)
|
|
2324
2070
|
const args = ["-c", "connect.timeout=15", "clone", "--depth", "1", "--single-branch"];
|
|
2325
2071
|
if (src.ref) args.push("--branch", src.ref);
|
|
2326
2072
|
args.push(src.cloneUrl, dst);
|
|
@@ -2350,9 +2096,6 @@ async function acquireRepo(src, tmpDir, opts = {}) {
|
|
|
2350
2096
|
|
|
2351
2097
|
const url = `https://codeload.github.com/${src.owner}/${src.repo}/tar.gz/${src.ref || "HEAD"}`;
|
|
2352
2098
|
console.log(ZH ? `· 下载 ${url}` : `· Downloading ${url}`);
|
|
2353
|
-
// 注意:这里不用 fail()/process.exit —— async 上下文里还有未关闭的 socket 时
|
|
2354
|
-
// 直接退出会触发 Windows libuv "UV_HANDLE_CLOSING" 断言崩溃;改为 throw,
|
|
2355
|
-
// 由 pluginInstallCmd 捕获后设 exitCode 让事件循环自然排空。
|
|
2356
2099
|
let buf;
|
|
2357
2100
|
try {
|
|
2358
2101
|
const res = await fetch(url, { redirect: "follow", signal: AbortSignal.timeout(120_000) });
|
|
@@ -2377,7 +2120,6 @@ async function acquireRepo(src, tmpDir, opts = {}) {
|
|
|
2377
2120
|
writeFileSync(join(tmpDir, "src.tar.gz"), buf);
|
|
2378
2121
|
const extractTo = join(tmpDir, "tar");
|
|
2379
2122
|
mkdirSync(extractTo, { recursive: true });
|
|
2380
|
-
// 相对路径解压:win32 的 GNU tar 会把 "C:\..." 里的 C: 当远程主机(Cannot connect to C:)
|
|
2381
2123
|
const tarRes = spawnSync("tar", ["-xzf", "src.tar.gz", "-C", "tar"], {
|
|
2382
2124
|
cwd: tmpDir,
|
|
2383
2125
|
stdio: "inherit",
|
|
@@ -2398,13 +2140,12 @@ async function acquireRepo(src, tmpDir, opts = {}) {
|
|
|
2398
2140
|
return join(extractTo, entries[0]);
|
|
2399
2141
|
}
|
|
2400
2142
|
|
|
2401
|
-
/** 在检出树里找包含 manifest.json 的目录(深度 ≤3,跳过 .git/node_modules)。 */
|
|
2402
2143
|
function findManifestDirs(root) {
|
|
2403
2144
|
const hits = [];
|
|
2404
2145
|
const walk = (dir, depth) => {
|
|
2405
2146
|
if (existsSync(join(dir, "manifest.json"))) {
|
|
2406
2147
|
hits.push(dir);
|
|
2407
|
-
return;
|
|
2148
|
+
return;
|
|
2408
2149
|
}
|
|
2409
2150
|
if (depth >= 3) return;
|
|
2410
2151
|
for (const ent of readdirSync(dir, { withFileTypes: true })) {
|
|
@@ -2416,7 +2157,6 @@ function findManifestDirs(root) {
|
|
|
2416
2157
|
return hits;
|
|
2417
2158
|
}
|
|
2418
2159
|
|
|
2419
|
-
/** 定位插件根目录:显式子路径 > 根目录 manifest > 全树搜索(唯一命中才继续)。 */
|
|
2420
2160
|
function locatePluginRoot(checkout, subpath, repoLabel) {
|
|
2421
2161
|
if (subpath) {
|
|
2422
2162
|
const dir = join(checkout, ...subpath.split("/"));
|
|
@@ -2447,14 +2187,6 @@ function locatePluginRoot(checkout, subpath, repoLabel) {
|
|
|
2447
2187
|
return hits[0];
|
|
2448
2188
|
}
|
|
2449
2189
|
|
|
2450
|
-
/**
|
|
2451
|
-
* 插件的源码构建声明(--build,issue #150):
|
|
2452
|
-
* manifest.json: { "build": { "install"?: "npm install --ignore-scripts",
|
|
2453
|
-
* "command": "npm run build",
|
|
2454
|
-
* "outputs"?: ["index.mjs", "client/entry.mjs"] } }
|
|
2455
|
-
* 缺 command 时回落到 package.json 的 scripts.build;两者都没有 = 没声明构建方式。
|
|
2456
|
-
* 返回 null 表示该插件没声明构建(--build 会明确报错,而不是猜一个命令出来)。
|
|
2457
|
-
*/
|
|
2458
2190
|
function resolveBuildPlan(pluginRoot, manifest) {
|
|
2459
2191
|
const declared = manifest && typeof manifest.build === "object" && manifest.build ? manifest.build : null;
|
|
2460
2192
|
let command = declared && typeof declared.command === "string" ? declared.command.trim() : "";
|
|
@@ -2462,9 +2194,7 @@ function resolveBuildPlan(pluginRoot, manifest) {
|
|
|
2462
2194
|
try {
|
|
2463
2195
|
const pkg = JSON.parse(readFileSync(join(pluginRoot, "package.json"), "utf8"));
|
|
2464
2196
|
if (pkg?.scripts && typeof pkg.scripts.build === "string" && pkg.scripts.build.trim()) command = "npm run build";
|
|
2465
|
-
} catch {
|
|
2466
|
-
/* 没有 package.json */
|
|
2467
|
-
}
|
|
2197
|
+
} catch {}
|
|
2468
2198
|
}
|
|
2469
2199
|
if (!command) return null;
|
|
2470
2200
|
const install =
|
|
@@ -2478,17 +2208,11 @@ function resolveBuildPlan(pluginRoot, manifest) {
|
|
|
2478
2208
|
return { install, command, outputs };
|
|
2479
2209
|
}
|
|
2480
2210
|
|
|
2481
|
-
/** 拷贝插件树时的过滤:不带 .git / node_modules(与安装同一套)。 */
|
|
2482
2211
|
const PLUGIN_COPY_FILTER = (s) => !/(^|[\\/])(\.git|node_modules)([\\/]|$)/.test(s);
|
|
2483
2212
|
|
|
2484
|
-
/** 插件目录里「属于随包代码」的清单文件:升级时只删清单里的路径,插件自己的
|
|
2485
|
-
* 数据(db-connections.json 之类)不在清单里,因此不会被删(issue #813)。 */
|
|
2486
2213
|
const SHIPPED_LIST = ".pi-files.json";
|
|
2487
|
-
/** 这些顶层目录就地保留:既免重下几百 MB 模型,也规避 Windows 下已加载的
|
|
2488
|
-
* .node/.dll 被 rmSync 触发 EBUSY 导致更新失败。 */
|
|
2489
2214
|
const PRESERVED_DIRS = new Set(["whisper-cache", "node_modules"]);
|
|
2490
2215
|
|
|
2491
|
-
/** 列出将要随包安装的相对路径(与 cpSync 同过滤)。 */
|
|
2492
2216
|
function listShippedFiles(root) {
|
|
2493
2217
|
const out = [];
|
|
2494
2218
|
const walk = (dir, prefix) => {
|
|
@@ -2514,7 +2238,6 @@ function listShippedFiles(root) {
|
|
|
2514
2238
|
return out.sort();
|
|
2515
2239
|
}
|
|
2516
2240
|
|
|
2517
|
-
/** 在给定目录跑一条外部命令(shell 执行,继承 stdio 让用户看到进度)。失败抛错。 */
|
|
2518
2241
|
function runBuildCommand(cmd, cwd, label) {
|
|
2519
2242
|
console.log(`· ${label}: ${cmd}`);
|
|
2520
2243
|
const res = spawnSync(cmd, {
|
|
@@ -2532,13 +2255,6 @@ function runBuildCommand(cmd, cwd, label) {
|
|
|
2532
2255
|
);
|
|
2533
2256
|
}
|
|
2534
2257
|
|
|
2535
|
-
/**
|
|
2536
|
-
* 隔离构建:把插件源码拷进临时目录 → 只在那里安装声明的构建依赖(默认
|
|
2537
|
-
* npm install --ignore-scripts:不执行任意生命周期脚本)→ 执行声明的构建命令 →
|
|
2538
|
-
* 校验产物齐全 → 返回可安装的目录。
|
|
2539
|
-
*
|
|
2540
|
-
* 全程不碰目标目录:构建失败时上一版插件原样还在(替换只在构建成功后才发生)。
|
|
2541
|
-
*/
|
|
2542
2258
|
function buildPluginSource(pluginRoot, tmpDir, manifest) {
|
|
2543
2259
|
const plan = resolveBuildPlan(pluginRoot, manifest);
|
|
2544
2260
|
if (!plan)
|
|
@@ -2567,16 +2283,6 @@ function buildPluginSource(pluginRoot, tmpDir, manifest) {
|
|
|
2567
2283
|
return buildDir;
|
|
2568
2284
|
}
|
|
2569
2285
|
|
|
2570
|
-
/**
|
|
2571
|
-
* 构建决策(issue #165:--build 自动推断)。
|
|
2572
|
-
*
|
|
2573
|
-
* 只有源码、没有产物(index.mjs 与 client/entry.mjs 都缺)且存在可解析的构建声明 =
|
|
2574
|
-
* “不构建这次安装必死”,此前会直接自动构建;但构建命令来自远端 manifest/package.json,
|
|
2575
|
-
* 经 shell:true 执行属于任意命令执行面,非交互环境下静默跑等于替用户放行。
|
|
2576
|
-
* 收紧后(审计修复):mode=auto 只表示“有构建声明且必要”,是否真正执行由
|
|
2577
|
-
* installOnePlugin 二次把关 —— 交互 TTY 且用户输入 y 才跑,否则跳过并警告。
|
|
2578
|
-
* --no-build 保留旧的“装个空目录”行为(脚本化镜像/检查用),并明确打印跳过原因。
|
|
2579
|
-
*/
|
|
2580
2286
|
function decideBuildAction({ pluginRoot, manifest, build, noBuild, isCatalog = false }) {
|
|
2581
2287
|
if (build && noBuild)
|
|
2582
2288
|
throw new Error(
|
|
@@ -2603,10 +2309,6 @@ function decideBuildAction({ pluginRoot, manifest, build, noBuild, isCatalog = f
|
|
|
2603
2309
|
return { mode: "none", plan };
|
|
2604
2310
|
}
|
|
2605
2311
|
|
|
2606
|
-
/**
|
|
2607
|
-
* 交互确认:插件声明的构建命令将经 shell 在本机执行(install + command 都来自
|
|
2608
|
-
* 远端 manifest/package.json),必须用户显式输入 y 才跑。仅 TTY 下会被调用。
|
|
2609
|
-
*/
|
|
2610
2312
|
async function confirmSourceBuild(plan) {
|
|
2611
2313
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
2612
2314
|
try {
|
|
@@ -2622,11 +2324,6 @@ async function confirmSourceBuild(plan) {
|
|
|
2622
2324
|
}
|
|
2623
2325
|
}
|
|
2624
2326
|
|
|
2625
|
-
/**
|
|
2626
|
-
* 装一个插件(单源模式与目录模式共用):拉取/定位 → 读 manifest → 构建决策 →
|
|
2627
|
-
* 覆盖(备份+保留 config.json)→ 落盘 → 记录来源/sha。
|
|
2628
|
-
* 失败抛 Error(目录模式逐条 try/catch 继续下一条,单源模式由调用方转 fail)。
|
|
2629
|
-
*/
|
|
2630
2327
|
async function installOnePlugin({
|
|
2631
2328
|
rawSpec,
|
|
2632
2329
|
name,
|
|
@@ -2652,7 +2349,6 @@ async function installOnePlugin({
|
|
|
2652
2349
|
const isLocal = existsSync(localCandidate);
|
|
2653
2350
|
const src = isLocal ? null : parsePluginSource(rawSpec);
|
|
2654
2351
|
|
|
2655
|
-
// 随包内置插件快速路径:若随包已自带官方插件且满足版本条件,优先走本地快速通路
|
|
2656
2352
|
const localBuiltinDir = isLocal ? null : resolveLocalBuiltinPluginDir(rawSpec, src, { remote });
|
|
2657
2353
|
let fastPathCandidate = null;
|
|
2658
2354
|
if (localBuiltinDir) {
|
|
@@ -2664,15 +2360,12 @@ async function installOnePlugin({
|
|
|
2664
2360
|
const id = name ?? fallbackId;
|
|
2665
2361
|
const target = join(pluginsDir, id);
|
|
2666
2362
|
if (!existsSync(target)) {
|
|
2667
|
-
// 未安装:全新安装直接采用本地随包
|
|
2668
2363
|
fastPathCandidate = localBuiltinDir;
|
|
2669
2364
|
} else if (force) {
|
|
2670
|
-
// 覆盖更新:对比随包版本与已装版本
|
|
2671
2365
|
try {
|
|
2672
2366
|
const tgtM = JSON.parse(readFileSync(join(target, "manifest.json"), "utf8"));
|
|
2673
2367
|
const srcM = JSON.parse(readFileSync(join(localBuiltinDir, "manifest.json"), "utf8"));
|
|
2674
2368
|
if (srcM?.version && tgtM?.version && compareVersions(srcM.version, tgtM.version) > 0) {
|
|
2675
|
-
// 随包版本比已装版本更新(刚升级了主程序),优先直接使用本地随包
|
|
2676
2369
|
fastPathCandidate = localBuiltinDir;
|
|
2677
2370
|
}
|
|
2678
2371
|
} catch {}
|
|
@@ -2695,7 +2388,6 @@ async function installOnePlugin({
|
|
|
2695
2388
|
try {
|
|
2696
2389
|
checkout = await acquireRepo(src, tmp, { sharedCache });
|
|
2697
2390
|
} catch (err) {
|
|
2698
|
-
// 若远端拉取失败,且属于官方插件,优雅回退到本地随包(离线与断网容错保护)
|
|
2699
2391
|
if (localBuiltinDir && existsSync(join(localBuiltinDir, "manifest.json"))) {
|
|
2700
2392
|
console.warn(
|
|
2701
2393
|
ZH
|
|
@@ -2720,8 +2412,6 @@ async function installOnePlugin({
|
|
|
2720
2412
|
: `manifest.json is not valid JSON: ${err?.message ?? err}`,
|
|
2721
2413
|
);
|
|
2722
2414
|
}
|
|
2723
|
-
// 构建决策(issue #150 的 --build + issue #165 的自动推断):构建在临时目录里完成,
|
|
2724
|
-
// 成功后才进入覆盖流程——构建失败 = 目标目录完全没被动过(上一版插件照常可用)。
|
|
2725
2415
|
const decision = decideBuildAction({
|
|
2726
2416
|
pluginRoot,
|
|
2727
2417
|
manifest,
|
|
@@ -2729,9 +2419,6 @@ async function installOnePlugin({
|
|
|
2729
2419
|
noBuild: noBuild === true,
|
|
2730
2420
|
isCatalog,
|
|
2731
2421
|
});
|
|
2732
|
-
// 授权把关(审计修复):--build 显式传参行为不变;mode=auto 的构建命令来自
|
|
2733
|
-
// 远端 manifest/package.json 且经 shell:true 执行 —— 非交互环境绝不自动跑
|
|
2734
|
-
// (跳过并警告),交互 TTY 也要用户显式输入 y 才执行。
|
|
2735
2422
|
let authorized = decision.mode === "explicit";
|
|
2736
2423
|
if (decision.mode === "auto") {
|
|
2737
2424
|
if (!process.stdin.isTTY) {
|
|
@@ -2775,7 +2462,6 @@ async function installOnePlugin({
|
|
|
2775
2462
|
: "· Build skipped: no artifacts in directory, plugin will not load after install (re-install with authorization to build)",
|
|
2776
2463
|
);
|
|
2777
2464
|
}
|
|
2778
|
-
// 默认 id:子目录名 > 仓库名 > 本地目录名
|
|
2779
2465
|
const sourceName = src?.subpath ? src.subpath.split("/").pop() : (src?.repo ?? localCandidate.split(/[\\/]/).pop());
|
|
2780
2466
|
const fallbackId =
|
|
2781
2467
|
String(manifest.id ?? sourceName)
|
|
@@ -2799,32 +2485,20 @@ async function installOnePlugin({
|
|
|
2799
2485
|
? `插件目录已存在:${target}\n 加 --force 覆盖,或用 --name <id> 换个名字。`
|
|
2800
2486
|
: `Plugin directory already exists: ${target}\n Add --force to overwrite, or use --name <id> to choose a different name.`,
|
|
2801
2487
|
);
|
|
2802
|
-
// 更新前备份旧版本(<dataDir>/plugin-backups/<id>-<ts>/,保留最近 3 份),
|
|
2803
|
-
// 失败时自动回滚。备份与安装同 filter:不带 .git/node_modules。
|
|
2804
2488
|
backupTs = ensurePluginBackup(dataDir, id, { source: rawSpec });
|
|
2805
|
-
// 插件凭据/加密机密/私有存储/运行时依赖声明不因升级丢失:先取出,拷完新文件后若新包未自带则原样放回
|
|
2806
2489
|
for (const fname of PRESERVED_FILES) {
|
|
2807
2490
|
try {
|
|
2808
2491
|
preservedData.set(fname, readFileSync(join(target, fname)));
|
|
2809
|
-
} catch {
|
|
2810
|
-
/* 无该文件 */
|
|
2811
|
-
}
|
|
2492
|
+
} catch {}
|
|
2812
2493
|
}
|
|
2813
|
-
// 只删上一版**随包安装**的文件:插件把自己的数据写在插件目录里
|
|
2814
|
-
// (db-client 的 db-connections.json、聊天记录、索引……)时,整目录清空会
|
|
2815
|
-
// 把它们一起删掉(issue #813)。没有清单的老安装不敢猜,宁可少删:
|
|
2816
|
-
// 残留的旧代码文件不会被加载,而删错的数据找不回来。
|
|
2817
2494
|
let previous = null;
|
|
2818
2495
|
try {
|
|
2819
2496
|
const raw = JSON.parse(readFileSync(join(target, SHIPPED_LIST), "utf8"));
|
|
2820
2497
|
if (Array.isArray(raw?.files)) previous = raw.files.filter((f) => typeof f === "string" && f);
|
|
2821
|
-
} catch {
|
|
2822
|
-
/* 老版本安装没留清单 */
|
|
2823
|
-
}
|
|
2498
|
+
} catch {}
|
|
2824
2499
|
if (previous) {
|
|
2825
2500
|
for (const rel of previous) {
|
|
2826
2501
|
const full = resolve(target, rel);
|
|
2827
|
-
// 清单来自磁盘,越界路径一律忽略(不支持插件把文件删到目录外)。
|
|
2828
2502
|
if (!full.startsWith(target + sep)) continue;
|
|
2829
2503
|
if (PRESERVED_DIRS.has(relative(target, full).split(sep)[0])) continue;
|
|
2830
2504
|
rmSync(full, { recursive: true, force: true });
|
|
@@ -2841,7 +2515,6 @@ async function installOnePlugin({
|
|
|
2841
2515
|
try {
|
|
2842
2516
|
cpSync(installRoot, target, { recursive: true, filter: PLUGIN_COPY_FILTER });
|
|
2843
2517
|
} catch (err) {
|
|
2844
|
-
// 拷贝失败 → 有备份则自动回滚,保持旧版本可用
|
|
2845
2518
|
if (backupTs && restorePluginBackup(dataDir, id)) {
|
|
2846
2519
|
throw new Error(
|
|
2847
2520
|
ZH
|
|
@@ -2860,33 +2533,21 @@ async function installOnePlugin({
|
|
|
2860
2533
|
writeFileSync(join(target, fname), buf);
|
|
2861
2534
|
}
|
|
2862
2535
|
}
|
|
2863
|
-
// 记录来源 / 远端 sha / 随包文件清单。清单是下一次升级的删除依据:只删它,
|
|
2864
|
-
// 插件自己写进目录的数据就不会被清空。
|
|
2865
2536
|
try {
|
|
2866
2537
|
writeFileSync(
|
|
2867
2538
|
join(target, SHIPPED_LIST),
|
|
2868
2539
|
JSON.stringify({ files: listShippedFiles(installRoot) }, null, 2) + "\n",
|
|
2869
2540
|
);
|
|
2870
|
-
} catch {
|
|
2871
|
-
/* 尽力而为:没有清单时下次升级退化为「不清理旧文件」 */
|
|
2872
|
-
}
|
|
2873
|
-
// 记录安装来源:设置面板「更新」按钮据此重跑同一条安装命令(--force 覆盖)。
|
|
2541
|
+
} catch {}
|
|
2874
2542
|
try {
|
|
2875
2543
|
writeFileSync(join(target, ".pi-source.json"), JSON.stringify({ source: rawSpec }, null, 2) + "\n");
|
|
2876
|
-
} catch {
|
|
2877
|
-
/* 尽力而为:没有来源信息只是不显示更新按钮 */
|
|
2878
|
-
}
|
|
2879
|
-
// 记录本次安装的远端 sha(git ls-remote HEAD,离线也支持本地 git 源):
|
|
2880
|
-
// 供 `pi-web-ui plugins --check-updates` 对比更新。失败静默(无 sha = 保守可更新)。
|
|
2544
|
+
} catch {}
|
|
2881
2545
|
try {
|
|
2882
2546
|
const sha = await resolveRemoteSha(rawSpec);
|
|
2883
2547
|
if (sha) writeFileSync(join(target, ".pi-git-sha"), sha + "\n");
|
|
2884
|
-
} catch {
|
|
2885
|
-
/* 尽力而为 */
|
|
2886
|
-
}
|
|
2548
|
+
} catch {}
|
|
2887
2549
|
return { id, target, manifest, buildMode: decision.mode };
|
|
2888
2550
|
} finally {
|
|
2889
|
-
// 若当前 tmp 正在被 sharedCache 共享复用,不在此清理,留给批量操作统一释放
|
|
2890
2551
|
let isCached = false;
|
|
2891
2552
|
if (sharedCache) {
|
|
2892
2553
|
for (const c of sharedCache.values()) {
|
|
@@ -2899,29 +2560,16 @@ async function installOnePlugin({
|
|
|
2899
2560
|
if (!isCached) {
|
|
2900
2561
|
try {
|
|
2901
2562
|
rmSync(tmp, { recursive: true, force: true });
|
|
2902
|
-
} catch {
|
|
2903
|
-
/* Windows 等平台杀毒/进程占用可能抛 EBUSY,不应翻转已成功的安装 */
|
|
2904
|
-
}
|
|
2563
|
+
} catch {}
|
|
2905
2564
|
}
|
|
2906
2565
|
}
|
|
2907
2566
|
}
|
|
2908
2567
|
|
|
2909
|
-
/**
|
|
2910
|
-
* 目录文档校验(issue #165 的 CLI --catalog)。
|
|
2911
|
-
*
|
|
2912
|
-
* 规则与 server/plugin-catalog.ts 的 toEntry 对齐(id 字符集、source 形状、字段裁剪),
|
|
2913
|
-
* 仅放宽一条:CLI 跑在使用者的本机信任上下文里,允许已存在的本地目录源(离线开发、
|
|
2914
|
-
* 本地目录同步);服务端 toEntry(网络/插件触发)仍只收远端源。两边规则若漂移,
|
|
2915
|
-
* tests/plugin-catalog-cli-test.mjs 的行为断言会先响(离线全链路)。
|
|
2916
|
-
*/
|
|
2917
2568
|
function isCatalogEntrySource(s) {
|
|
2918
2569
|
if (!s || s.length > 300) return false;
|
|
2919
|
-
// 本地目录:CLI 才放行(存在性检查,file:// 前缀兼容 install 单源写法)
|
|
2920
2570
|
try {
|
|
2921
2571
|
if (existsSync(resolve(s.replace(/^file:\/\//, "")))) return true;
|
|
2922
|
-
} catch {
|
|
2923
|
-
/* 非法路径字符:走下面的远端规则 */
|
|
2924
|
-
}
|
|
2572
|
+
} catch {}
|
|
2925
2573
|
if (/^https?:\/\//.test(s)) return true;
|
|
2926
2574
|
const spec = s.split("#")[0].replace(/\/+$/, "");
|
|
2927
2575
|
const segs = spec.split("/").filter(Boolean);
|
|
@@ -2939,9 +2587,7 @@ function deriveCatalogEntryId(rawId, source) {
|
|
|
2939
2587
|
const cleaned = base.replace(/[^A-Za-z0-9_-]/g, "-").replace(/^-+|-+$/g, "");
|
|
2940
2588
|
return cleaned || "plugin";
|
|
2941
2589
|
}
|
|
2942
|
-
} catch {
|
|
2943
|
-
/* 走远端规则 */
|
|
2944
|
-
}
|
|
2590
|
+
} catch {}
|
|
2945
2591
|
const spec = source.split("#")[0].replace(/\/+$/, "");
|
|
2946
2592
|
const segs = spec.split("/").filter(Boolean);
|
|
2947
2593
|
const last = segs.length >= 2 ? segs[segs.length - 1] : (segs[0] ?? "plugin");
|
|
@@ -2972,7 +2618,6 @@ function catalogEntryFromRaw(raw) {
|
|
|
2972
2618
|
};
|
|
2973
2619
|
}
|
|
2974
2620
|
|
|
2975
|
-
/** 目录文档形状:JSON 数组或 {entries:[...]};非法条目丢弃并计数(与服务端同语义)。 */
|
|
2976
2621
|
function normalizeCatalogEntries(raw) {
|
|
2977
2622
|
const list = Array.isArray(raw)
|
|
2978
2623
|
? raw
|
|
@@ -2995,7 +2640,6 @@ function normalizeCatalogEntries(raw) {
|
|
|
2995
2640
|
return { entries, skipped };
|
|
2996
2641
|
}
|
|
2997
2642
|
|
|
2998
|
-
/** 读目录文档:http(s) 拉取(30s 超时),其余当本地绝对路径(与服务端同口径)。 */
|
|
2999
2643
|
async function readCatalogDocumentText(source) {
|
|
3000
2644
|
const src = String(source ?? "").trim();
|
|
3001
2645
|
if (!src)
|
|
@@ -3037,9 +2681,7 @@ function readCatalogFileEntries(customPath) {
|
|
|
3037
2681
|
try {
|
|
3038
2682
|
const raw = JSON.parse(readFileSync(customPath, "utf8"));
|
|
3039
2683
|
if (raw && typeof raw === "object" && Array.isArray(raw.entries)) return raw.entries;
|
|
3040
|
-
} catch {
|
|
3041
|
-
/* 无文件/坏文件 = 空列表 */
|
|
3042
|
-
}
|
|
2684
|
+
} catch {}
|
|
3043
2685
|
return [];
|
|
3044
2686
|
}
|
|
3045
2687
|
|
|
@@ -3050,7 +2692,6 @@ function writeCatalogFileEntries(customPath, entries) {
|
|
|
3050
2692
|
renameSync(tmp, customPath);
|
|
3051
2693
|
}
|
|
3052
2694
|
|
|
3053
|
-
/** install --catalog <url>:同步可安装列表 + 逐条安装/更新(单条失败不中断整批)。 */
|
|
3054
2695
|
async function installCatalogCmd(opts) {
|
|
3055
2696
|
const dataDir = pluginDataDir(opts);
|
|
3056
2697
|
const customPath = join(dataDir, "plugin-catalog.json");
|
|
@@ -3069,7 +2710,6 @@ async function installCatalogCmd(opts) {
|
|
|
3069
2710
|
} catch (err) {
|
|
3070
2711
|
fail(`${err?.message ?? err}`);
|
|
3071
2712
|
}
|
|
3072
|
-
// 到这里才动磁盘:形状不对的文档绝不覆盖有效列表(与服务端同纪律)。
|
|
3073
2713
|
if (opts.replace) {
|
|
3074
2714
|
writeCatalogFileEntries(customPath, entries);
|
|
3075
2715
|
} else {
|
|
@@ -3124,7 +2764,6 @@ async function installCatalogCmd(opts) {
|
|
|
3124
2764
|
}
|
|
3125
2765
|
}
|
|
3126
2766
|
} finally {
|
|
3127
|
-
// 统一清理同批任务复用的共享缓存检出目录
|
|
3128
2767
|
for (const entry of sharedCache.values()) {
|
|
3129
2768
|
if (entry.tmpDir) {
|
|
3130
2769
|
try {
|
|
@@ -3141,25 +2780,14 @@ async function installCatalogCmd(opts) {
|
|
|
3141
2780
|
if (failCount) process.exitCode = 1;
|
|
3142
2781
|
}
|
|
3143
2782
|
|
|
3144
|
-
// ---------------------------------------------------------------------------
|
|
3145
|
-
// 插件脚手架(plugin create):生成最小可跑骨架
|
|
3146
|
-
// 形态 = <dataDir>/plugins/<id>/(manifest.json + index.mjs + client/entry.mjs),
|
|
3147
|
-
// 与 server/plugins.ts 的加载约定对齐;官方插件(plugins/demo-mailbox 等)可作参考。
|
|
3148
|
-
// ---------------------------------------------------------------------------
|
|
3149
|
-
|
|
3150
|
-
/** 脚手架模板:minimal(零权限)| ui-slot | agent-tool | renderer(view:false)。 */
|
|
3151
2783
|
const PLUGIN_TEMPLATES = ["minimal", "ui-slot", "agent-tool", "renderer"];
|
|
3152
2784
|
|
|
3153
|
-
/** 随包发布的 plugin-sdk 服务端文件:包含总入口、浏览器入口、工具函数与测试 harness。 */
|
|
3154
2785
|
const PLUGIN_SDK_FILES = ["index.mjs", "client.mjs", "client-utils.mjs", "testing.mjs"];
|
|
3155
2786
|
|
|
3156
|
-
/** 拷进 client/sdk/ 的浏览器 SDK 文件清单(绝不含 testing.mjs 或任何 node 依赖)。 */
|
|
3157
2787
|
const PLUGIN_SDK_CLIENT_FILES = ["client.mjs", "client-utils.mjs"];
|
|
3158
2788
|
|
|
3159
|
-
/** 浏览器端 client/sdk/index.mjs 的兼容入口内容(保证已有客户端无需修改)。 */
|
|
3160
2789
|
const CLIENT_SDK_INDEX_COMPAT = `export * from "./client.mjs";\n`;
|
|
3161
2790
|
|
|
3162
|
-
/** 包内 plugin-sdk 文件清单(随包发布,见 package.json files);缺任一 = 包不完整,按「无 SDK」处理。 */
|
|
3163
2791
|
function pluginSdkSources() {
|
|
3164
2792
|
const dir = join(BIN_DIR, "..", "plugin-sdk");
|
|
3165
2793
|
const files = [];
|
|
@@ -3187,14 +2815,11 @@ function copyClientSdkInto(dir, sources) {
|
|
|
3187
2815
|
const src = map.get(name);
|
|
3188
2816
|
if (src && existsSync(src)) copyFileSync(src, join(dir, name));
|
|
3189
2817
|
}
|
|
3190
|
-
// 浏览器端兼容入口:export * from "./client.mjs";
|
|
3191
2818
|
writeFileSync(join(dir, "index.mjs"), CLIENT_SDK_INDEX_COMPAT);
|
|
3192
|
-
// 禁止 testing.mjs 或任何 Node 依赖进 client/sdk/,若有旧残留则清理
|
|
3193
2819
|
const testFile = join(dir, "testing.mjs");
|
|
3194
2820
|
if (existsSync(testFile)) rmSync(testFile, { force: true });
|
|
3195
2821
|
}
|
|
3196
2822
|
|
|
3197
|
-
/** 各模板的 manifest.description(一句话说明骨架来源)。 */
|
|
3198
2823
|
function scaffoldDescription(template) {
|
|
3199
2824
|
switch (template) {
|
|
3200
2825
|
case "ui-slot":
|
|
@@ -3208,17 +2833,12 @@ function scaffoldDescription(template) {
|
|
|
3208
2833
|
}
|
|
3209
2834
|
}
|
|
3210
2835
|
|
|
3211
|
-
/** 模板的客户端是否 import SDK:**除 renderer 外都 import `./sdk/client.mjs`**(renderer 渲染器走裸 ESM)。
|
|
3212
|
-
* 决定 `client/sdk/` 要不要拷、README 怎么写;拷完还用 import-check 复验(模板以后改了也不漏)。 */
|
|
3213
2836
|
function templateClientUsesSdk(template) {
|
|
3214
2837
|
return template !== "renderer";
|
|
3215
2838
|
}
|
|
3216
2839
|
|
|
3217
|
-
/** 拼骨架文件:{ 相对路径: 内容 }。useSdk=false 时走无 SDK 导入的等价写法。
|
|
3218
|
-
* withTest=true(且 useSdk)时多带 index.test.mjs(node --test + createMockHost 最小单测)。 */
|
|
3219
2840
|
function buildPluginScaffold(id, template, useSdk, withTest = false) {
|
|
3220
2841
|
const sdkServer = useSdk ? `import { definePlugin } from "./sdk/index.mjs";\n\n` : "";
|
|
3221
|
-
// 客户端 import 必须落在 client/ 内:宿主只暴露 /plugins/<id>/client/*(见 import-check)。
|
|
3222
2842
|
const sdkClient = useSdk ? `import { defineView, onUiAction } from "./sdk/client.mjs";\n\n` : "";
|
|
3223
2843
|
const wrapServer = (body) =>
|
|
3224
2844
|
useSdk ? `${sdkServer}export default definePlugin({\n${body}\n});\n` : `export default {\n${body}\n};\n`;
|
|
@@ -3234,8 +2854,6 @@ function buildPluginScaffold(id, template, useSdk, withTest = false) {
|
|
|
3234
2854
|
version: "0.1.0",
|
|
3235
2855
|
description: scaffoldDescription(template),
|
|
3236
2856
|
apiVersion: 2,
|
|
3237
|
-
// apiVersion 2 **必须**声明 permissions(缺字段 = 宿主直接拒激活,issue #546 现场顺带发现):
|
|
3238
|
-
// 模板按需覆写(ui-slot → ["ui"]、agent-tool → ["tools"]),零能力的就是空数组。
|
|
3239
2857
|
permissions: [],
|
|
3240
2858
|
};
|
|
3241
2859
|
|
|
@@ -3359,7 +2977,6 @@ function buildPluginScaffold(id, template, useSdk, withTest = false) {
|
|
|
3359
2977
|
`\t\t};\n` +
|
|
3360
2978
|
`\t},`,
|
|
3361
2979
|
);
|
|
3362
|
-
// 渲染器走裸 ESM(命中围栏才懒加载):默认导出 { renderers },不用 defineView。
|
|
3363
2980
|
clientJs =
|
|
3364
2981
|
`/**\n` +
|
|
3365
2982
|
` * ${id} —— fenced-code 渲染器(pi-web-ui plugin create 生成)。\n` +
|
|
@@ -3432,7 +3049,6 @@ function buildPluginScaffold(id, template, useSdk, withTest = false) {
|
|
|
3432
3049
|
"README.md": readme,
|
|
3433
3050
|
};
|
|
3434
3051
|
if (withTest && useSdk) {
|
|
3435
|
-
// 最小单测:四个模板的 activate 都会 host.log("activated"),断言与模板无关。
|
|
3436
3052
|
out["index.test.mjs"] =
|
|
3437
3053
|
`/**\n` +
|
|
3438
3054
|
` * ${id} —— 最小单测(pi-web-ui plugin create --with-test 生成)。\n` +
|
|
@@ -3468,7 +3084,6 @@ function buildPluginScaffold(id, template, useSdk, withTest = false) {
|
|
|
3468
3084
|
return out;
|
|
3469
3085
|
}
|
|
3470
3086
|
|
|
3471
|
-
/** 生成后的 manifest 基础校验(必填/口径);返回 warnings(无则空数组)。 */
|
|
3472
3087
|
function validateScaffoldManifest(manifest, dirName) {
|
|
3473
3088
|
const warnings = [];
|
|
3474
3089
|
for (const k of ["id", "name", "version", "description"]) {
|
|
@@ -3505,8 +3120,6 @@ function validateScaffoldManifest(manifest, dirName) {
|
|
|
3505
3120
|
: `manifest.permissions must be a string array (e.g. ["ui"])`,
|
|
3506
3121
|
);
|
|
3507
3122
|
}
|
|
3508
|
-
// 与宿主同口径(server/plugin-manifest-validate.ts):apiVersion 2 必须有 permissions 字段,
|
|
3509
|
-
// 缺失 = 扫到就报错误、插件被拒(零能力也写 [])—— 骨架曾经漏写,装上去才发现。
|
|
3510
3123
|
if (manifest.apiVersion === 2 && manifest.permissions === undefined)
|
|
3511
3124
|
warnings.push(
|
|
3512
3125
|
ZH
|
|
@@ -3523,7 +3136,6 @@ function validateScaffoldManifest(manifest, dirName) {
|
|
|
3523
3136
|
return warnings;
|
|
3524
3137
|
}
|
|
3525
3138
|
|
|
3526
|
-
/** 已装插件目录或文件里解析 SDK_VERSION(新单源在 client.mjs,兼容旧版在 index.mjs;老拷贝无此常量 → null)。 */
|
|
3527
3139
|
function installedSdkVersion(dirOrFile) {
|
|
3528
3140
|
try {
|
|
3529
3141
|
const isDir = statSync(dirOrFile).isDirectory();
|
|
@@ -3542,7 +3154,6 @@ function installedSdkVersion(dirOrFile) {
|
|
|
3542
3154
|
}
|
|
3543
3155
|
}
|
|
3544
3156
|
|
|
3545
|
-
/** 包内 SDK 版本(新单源:plugin-sdk/client.mjs 的 `export const SDK_VERSION`,兼容旧版 index.mjs)。 */
|
|
3546
3157
|
function packageSdkVersion() {
|
|
3547
3158
|
const sources = pluginSdkSources();
|
|
3548
3159
|
if (!sources) {
|
|
@@ -3567,7 +3178,6 @@ function packageSdkVersion() {
|
|
|
3567
3178
|
);
|
|
3568
3179
|
}
|
|
3569
3180
|
|
|
3570
|
-
/** 静态 import 自检问题的双语文案(create / upgrade-sdk 共用)。 */
|
|
3571
3181
|
function importProblemText(p) {
|
|
3572
3182
|
if (p.kind === "escapes-client")
|
|
3573
3183
|
return ZH
|
|
@@ -3578,7 +3188,6 @@ function importProblemText(p) {
|
|
|
3578
3188
|
: `${p.file}: import "${p.spec}" target does not exist (${p.target}) — typo, or a missing vendored dependency?`;
|
|
3579
3189
|
}
|
|
3580
3190
|
|
|
3581
|
-
/** 懒加载 import-check(随包发布,但裁剪包可能没有 → 跳自检而不是崩)。 */
|
|
3582
3191
|
let importCheckModule;
|
|
3583
3192
|
async function loadImportCheck() {
|
|
3584
3193
|
if (importCheckModule === undefined) {
|
|
@@ -3587,7 +3196,6 @@ async function loadImportCheck() {
|
|
|
3587
3196
|
return importCheckModule;
|
|
3588
3197
|
}
|
|
3589
3198
|
|
|
3590
|
-
/** 刷新已装插件的 SDK 拷贝(服务端 `sdk/` + 客户端 `client/sdk/`,版本/文件对不上才拷)。 */
|
|
3591
3199
|
async function pluginUpgradeSdkCmd(argv) {
|
|
3592
3200
|
const { opts, positionals } = parseFlags(argv);
|
|
3593
3201
|
if (opts.help || positionals.length > 1) {
|
|
@@ -3628,7 +3236,6 @@ async function pluginUpgradeSdkCmd(argv) {
|
|
|
3628
3236
|
const hasServerSdk = existsSync(serverSdkDir);
|
|
3629
3237
|
const hasClientSdk = existsSync(clientSdkDir);
|
|
3630
3238
|
|
|
3631
|
-
// 客户端侧缺失但代码确实 import ./sdk/ → 补建(修好 issue #546 之前生成的插件)。
|
|
3632
3239
|
let wantsClientSdk = false;
|
|
3633
3240
|
if (!hasClientSdk) {
|
|
3634
3241
|
wantsClientSdk =
|
|
@@ -3641,7 +3248,6 @@ async function pluginUpgradeSdkCmd(argv) {
|
|
|
3641
3248
|
continue;
|
|
3642
3249
|
}
|
|
3643
3250
|
|
|
3644
|
-
// 分别检测服务/客户端版本与缺文件
|
|
3645
3251
|
let serverStale = false;
|
|
3646
3252
|
if (hasServerSdk) {
|
|
3647
3253
|
const missingFiles = PLUGIN_SDK_FILES.some((name) => !existsSync(join(serverSdkDir, name)));
|
|
@@ -3719,7 +3325,6 @@ async function pluginUpgradeSdkCmd(argv) {
|
|
|
3719
3325
|
: ` ↳ ${id}: created the missing client/sdk/ (needed by the client-side ./sdk/ import)`,
|
|
3720
3326
|
);
|
|
3721
3327
|
for (const w of broken) console.log(`⚠ ${w}`);
|
|
3722
|
-
// 顺带自检 import 越界/缺失(issue #546:客户端越界会让插件页整页空白,而服务端看不出来)。
|
|
3723
3328
|
if (importCheck) {
|
|
3724
3329
|
for (const id of targets) {
|
|
3725
3330
|
for (const p of importCheck.checkPluginImports(join(parentDir, id)).problems)
|
|
@@ -3769,16 +3374,12 @@ async function pluginCreateCmd(argv) {
|
|
|
3769
3374
|
const files = buildPluginScaffold(id, template, useSdk, wantTest && useSdk);
|
|
3770
3375
|
if (useSdk) copyServerSdkInto(join(target, "sdk"), sdkSources);
|
|
3771
3376
|
for (const [rel, content] of Object.entries(files)) writeFileSync(join(target, rel), content);
|
|
3772
|
-
// 客户端侧的相对依赖必须落在 client/ 内(宿主只暴露 /plugins/<id>/client/*):生成文件里
|
|
3773
|
-
// 引到 client/ 内的 SDK 就把 SDK 也拷进 client/sdk/(renderer 模板客户端不用 SDK,不白拷)。
|
|
3774
3377
|
const importCheck = await loadImportCheck();
|
|
3775
3378
|
if (useSdk) {
|
|
3776
|
-
// 模板按约定先拷(renderer 除外),再用扫描复验一遍 —— 模板以后加了客户端 SDK 引用也不会漏。
|
|
3777
3379
|
const scanned =
|
|
3778
3380
|
importCheck?.scanPluginImports(target).some((r) => r.client && r.target.startsWith("client/sdk/")) ?? false;
|
|
3779
3381
|
if (templateClientUsesSdk(template) || scanned) copyClientSdkInto(join(target, "client", "sdk"), sdkSources);
|
|
3780
3382
|
}
|
|
3781
|
-
// 生成后校验:manifest 基础必填 + 生成文件的 node 语法检查 + 静态 import 自检。
|
|
3782
3383
|
let manifest;
|
|
3783
3384
|
try {
|
|
3784
3385
|
manifest = JSON.parse(readFileSync(join(target, "manifest.json"), "utf8"));
|
|
@@ -3807,8 +3408,6 @@ async function pluginCreateCmd(argv) {
|
|
|
3807
3408
|
: `${rel} failed node --check (please check generated files)`,
|
|
3808
3409
|
);
|
|
3809
3410
|
}
|
|
3810
|
-
// 静态 import 自检(issue #546):客户端越界 / 目标缺失都会让插件在浏览器里整页空白,
|
|
3811
|
-
// 而服务端看不出来 —— 在脚手架阶段就报出来。
|
|
3812
3411
|
if (importCheck) {
|
|
3813
3412
|
const { problems } = importCheck.checkPluginImports(target);
|
|
3814
3413
|
for (const p of problems) warnings.push(importProblemText(p));
|
|
@@ -3848,8 +3447,6 @@ async function pluginInstallCmd(argv) {
|
|
|
3848
3447
|
console.log(PLUGIN_HELP);
|
|
3849
3448
|
return;
|
|
3850
3449
|
}
|
|
3851
|
-
// 目录同步模式(issue #165):install --catalog <url> —— 读目录文档 → 校验 →
|
|
3852
|
-
// 原子写盘 → 逐条安装/更新(与服务端 plugin-catalog-sync 同语义)。
|
|
3853
3450
|
if (opts.catalog !== undefined) {
|
|
3854
3451
|
if (positionals.length !== 0)
|
|
3855
3452
|
fail(
|
|
@@ -3943,7 +3540,6 @@ function pluginListCmd(argv) {
|
|
|
3943
3540
|
return;
|
|
3944
3541
|
}
|
|
3945
3542
|
const dataDir = pluginDataDir(opts);
|
|
3946
|
-
// --rollback <id>:回滚到最近一份更新前备份
|
|
3947
3543
|
if (opts.rollback) {
|
|
3948
3544
|
const id = String(opts.rollback);
|
|
3949
3545
|
if (!PLUGIN_ID_RE.test(id)) fail(ZH ? `非法插件 id: ${id}` : `Invalid plugin id: ${id}`);
|
|
@@ -3968,7 +3564,6 @@ function pluginListCmd(argv) {
|
|
|
3968
3564
|
);
|
|
3969
3565
|
return;
|
|
3970
3566
|
}
|
|
3971
|
-
// --check-updates:对比各插件记录的最后安装 sha 与远端 HEAD(git ls-remote)
|
|
3972
3567
|
if (opts.checkUpdates) {
|
|
3973
3568
|
return checkUpdatesCmd(dataDir).then(() => {});
|
|
3974
3569
|
}
|
|
@@ -3977,9 +3572,7 @@ function pluginListCmd(argv) {
|
|
|
3977
3572
|
let names = [];
|
|
3978
3573
|
try {
|
|
3979
3574
|
names = readdirSync(pluginsDir).sort();
|
|
3980
|
-
} catch {
|
|
3981
|
-
/* 目录不存在 = 未安装任何插件 */
|
|
3982
|
-
}
|
|
3575
|
+
} catch {}
|
|
3983
3576
|
for (const n of names) {
|
|
3984
3577
|
if (!PLUGIN_ID_RE.test(n)) continue;
|
|
3985
3578
|
try {
|
|
@@ -3988,7 +3581,7 @@ function pluginListCmd(argv) {
|
|
|
3988
3581
|
` ${n.padEnd(24)} ${[m.name, m.version ? `v${m.version}` : "", m.description].filter(Boolean).join(" ")}`,
|
|
3989
3582
|
);
|
|
3990
3583
|
} catch {
|
|
3991
|
-
continue;
|
|
3584
|
+
continue;
|
|
3992
3585
|
}
|
|
3993
3586
|
}
|
|
3994
3587
|
if (rows.length === 0) {
|
|
@@ -4211,16 +3804,35 @@ async function main() {
|
|
|
4211
3804
|
pluginListCmd(argv.slice(1));
|
|
4212
3805
|
return;
|
|
4213
3806
|
}
|
|
4214
|
-
// One-shot server with optional --port/--cwd/--data-dir overrides.
|
|
4215
3807
|
const { opts, positionals } = parseFlags(argv);
|
|
4216
3808
|
if (opts.help) {
|
|
4217
3809
|
console.log(HELP);
|
|
4218
3810
|
return;
|
|
4219
3811
|
}
|
|
4220
|
-
if (positionals.length >
|
|
3812
|
+
if (positionals.length > 1)
|
|
4221
3813
|
fail(
|
|
4222
|
-
ZH
|
|
3814
|
+
ZH
|
|
3815
|
+
? `未知命令: ${positionals.join(" ")}(--help 查看用法)`
|
|
3816
|
+
: `Unknown command: ${positionals.join(" ")} (--help for usage)`,
|
|
4223
3817
|
);
|
|
3818
|
+
if (positionals.length === 1) {
|
|
3819
|
+
if (opts.cwd !== undefined) {
|
|
3820
|
+
fail(ZH ? "目录参数不能与 --cwd 同时使用" : "Cannot combine a directory argument with --cwd");
|
|
3821
|
+
}
|
|
3822
|
+
const cwd = resolve(positionals[0]);
|
|
3823
|
+
let isDirectory = false;
|
|
3824
|
+
try {
|
|
3825
|
+
isDirectory = statSync(cwd).isDirectory();
|
|
3826
|
+
} catch {}
|
|
3827
|
+
if (!isDirectory) {
|
|
3828
|
+
fail(
|
|
3829
|
+
ZH
|
|
3830
|
+
? `目录不存在或不可访问: ${positionals[0]}`
|
|
3831
|
+
: `Directory does not exist or is inaccessible: ${positionals[0]}`,
|
|
3832
|
+
);
|
|
3833
|
+
}
|
|
3834
|
+
opts.cwd = cwd;
|
|
3835
|
+
}
|
|
4224
3836
|
await startForeground(opts);
|
|
4225
3837
|
}
|
|
4226
3838
|
|