pi-web-ui 0.116.0 → 0.118.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +83 -3
- package/README.md +69 -138
- package/README.zh-CN.md +70 -179
- package/README.zh-TW.md +3 -1
- package/bin/device-hub-cli.mjs +163 -36
- package/bin/frp-manager.mjs +4 -80
- package/bin/hub-upgrade.mjs +561 -0
- package/bin/pi-device-hub.mjs +0 -1
- package/bin/pi-web-ui.mjs +184 -504
- package/deploy/nginx-subpath.conf +0 -33
- package/deploy/pi-web-ui.service +0 -20
- package/dist/server/agent-formatters.js +4 -38
- package/dist/server/agent-service-daemon.js +203 -371
- package/dist/server/agent-service.js +1281 -3030
- package/dist/server/approval-audit.js +2 -23
- package/dist/server/approval-default-rules.js +0 -6
- package/dist/server/approval-rules.js +7 -105
- package/dist/server/ask-user-question-tool.js +1 -12
- package/dist/server/atomic-file.js +33 -5
- package/dist/server/attachment-store.js +0 -36
- package/dist/server/attachments.js +3 -112
- package/dist/server/auth-cookie.js +0 -21
- package/dist/server/bash-tool.js +1 -32
- package/dist/server/bg-servers.js +0 -96
- package/dist/server/browser-page-tool.js +11 -62
- package/dist/server/builtin-modules.js +7 -0
- package/dist/server/canvas/canvas-agent-tool.js +58 -47
- package/dist/server/canvas/canvas-cards.js +0 -14
- package/dist/server/canvas/canvas-dispatch.js +7 -4
- package/dist/server/canvas/canvas-orchestrator.js +167 -181
- package/dist/server/canvas/canvas-runtime-messages.js +30 -0
- package/dist/server/canvas/canvas-scheduled-task.js +0 -3
- package/dist/server/canvas/canvas-scheduler.js +5 -7
- package/dist/server/canvas/canvas-store.js +24 -35
- package/dist/server/canvas/canvas-validation.js +17 -14
- package/dist/server/canvas/canvas-workspace.js +42 -114
- package/dist/server/canvas/pstack-skills-data.js +0 -5
- package/dist/server/claim-files-tool.js +1 -15
- package/dist/server/claim-store.js +5 -49
- package/dist/server/client-id-utils.js +0 -16
- package/dist/server/client-state.js +36 -214
- package/dist/server/communicate-tool.js +0 -3
- package/dist/server/compact-context-tool.js +0 -30
- package/dist/server/compacted-history.js +0 -35
- package/dist/server/compaction-instructions.js +0 -13
- package/dist/server/compaction-markers.js +38 -92
- package/dist/server/compaction-state.js +0 -21
- package/dist/server/composer-drafts.js +0 -34
- package/dist/server/context-budget-runner.js +0 -11
- package/dist/server/context-budget.js +1 -70
- package/dist/server/context-evidence.js +0 -14
- package/dist/server/context-usage.js +0 -12
- package/dist/server/control-socket.js +4 -48
- package/dist/server/conversation-communication.js +0 -10
- package/dist/server/conversation-identity.js +0 -1
- package/dist/server/conversation-read-tool.js +0 -58
- package/dist/server/conversation-tool-names.js +0 -1
- package/dist/server/conversation-tool.js +0 -1
- package/dist/server/conversation-touches.js +4 -75
- package/dist/server/dangling-tools.js +142 -68
- package/dist/server/delegate-mode.js +0 -36
- package/dist/server/delegate-task.js +2 -28
- package/dist/server/device-center/approval-summary.js +0 -1
- package/dist/server/device-center/bot-catalog.js +0 -3
- package/dist/server/device-center/bot-execution.js +48 -9
- package/dist/server/device-center/bot-presets.js +0 -1
- package/dist/server/device-center/bots.js +0 -1
- package/dist/server/device-center/collab-service.js +27 -11
- package/dist/server/device-center/collab-tool.js +393 -27
- package/dist/server/device-center/connector.js +128 -48
- package/dist/server/device-center/delivery-authority.js +95 -0
- package/dist/server/device-center/delivery-subject.js +29 -0
- package/dist/server/device-center/desktop-linux.js +3 -15
- package/dist/server/device-center/desktop-native.js +1 -10
- package/dist/server/device-center/desktop-page.js +2 -3
- package/dist/server/device-center/desktop-setup.js +1 -3
- package/dist/server/device-center/desktop.js +1 -7
- package/dist/server/device-center/device-integration.js +452 -208
- package/dist/server/device-center/device-lan-access.js +403 -0
- package/dist/server/device-center/device-lan.js +484 -0
- package/dist/server/device-center/device-portals.js +0 -3
- package/dist/server/device-center/execution-failure.js +0 -2
- package/dist/server/device-center/execution-guides.js +15 -6
- package/dist/server/device-center/execution-instructions.js +0 -1
- package/dist/server/device-center/execution-settings.js +0 -1
- package/dist/server/device-center/execution-system-prompt.js +0 -3
- package/dist/server/device-center/execution-workspace.js +1 -4
- package/dist/server/device-center/executor.js +46 -31
- package/dist/server/device-center/file-sync-paths.js +0 -5
- package/dist/server/device-center/file-sync.js +0 -10
- package/dist/server/device-center/group-context-delta.js +0 -8
- package/dist/server/device-center/group-context-message.js +0 -14
- package/dist/server/device-center/group-context.js +0 -19
- package/dist/server/device-center/group-events.js +0 -2
- package/dist/server/device-center/group-plan-guard.js +1 -35
- package/dist/server/device-center/group-router-runtime.js +182 -0
- package/dist/server/device-center/group-router-worker.js +178 -0
- package/dist/server/device-center/group-router.js +359 -0
- package/dist/server/device-center/hub-auth.js +24 -2
- package/dist/server/device-center/hub-conversations.js +13 -15
- package/dist/server/device-center/hub-deliveries.js +119 -15
- package/dist/server/device-center/hub-integration.js +647 -334
- package/dist/server/device-center/hub-locks.js +1 -5
- package/dist/server/device-center/hub-mobile.js +147 -0
- package/dist/server/device-center/hub-orchestration.js +400 -0
- package/dist/server/device-center/hub-page.js +28 -9
- package/dist/server/device-center/hub-setup.js +23 -7
- package/dist/server/device-center/hub-transaction-log.js +175 -0
- package/dist/server/device-center/hub-upgrade.js +162 -0
- package/dist/server/device-center/hub-webhooks.js +1 -3
- package/dist/server/device-center/hub.js +946 -404
- package/dist/server/device-center/human-interaction.js +1 -4
- package/dist/server/device-center/integration-errors.js +0 -2
- package/dist/server/device-center/integration-verification.js +111 -0
- package/dist/server/device-center/local-hub.js +6 -4
- package/dist/server/device-center/local-publication.js +416 -0
- package/dist/server/device-center/local-verification-job.js +95 -0
- package/dist/server/device-center/local-verification.js +273 -0
- package/dist/server/device-center/local.js +341 -18
- package/dist/server/device-center/main.js +18 -2
- package/dist/server/device-center/mobile-notification-forwarder.js +292 -0
- package/dist/server/device-center/native-desktop/macos.js +0 -1
- package/dist/server/device-center/native-desktop/windows.js +0 -1
- package/dist/server/device-center/partition-log.js +52 -46
- package/dist/server/device-center/path-portal.js +42 -12
- package/dist/server/device-center/publication-journal.js +305 -0
- package/dist/server/device-center/publish-intent.js +374 -0
- package/dist/server/device-center/relay.js +217 -52
- package/dist/server/device-center/report-upload.js +0 -1
- package/dist/server/device-center/runtime.js +419 -52
- package/dist/server/device-center/store.js +223 -65
- package/dist/server/device-center/task-context-budget.js +0 -3
- package/dist/server/device-center/task-error.js +0 -1
- package/dist/server/device-center/task-journal.js +6 -23
- package/dist/server/device-center/task-outcome.js +68 -0
- package/dist/server/device-center/task-plan.js +0 -1
- package/dist/server/device-center/task-progress.js +0 -16
- package/dist/server/device-center/task-recovery.js +569 -227
- package/dist/server/device-center/task-report-outbox.js +0 -4
- package/dist/server/device-center/task-report.js +2 -10
- package/dist/server/device-center/task-scheduler.js +1 -35
- package/dist/server/device-center/task-settlement.js +335 -0
- package/dist/server/device-center/task-state.js +0 -12
- package/dist/server/device-center/task-workspace.js +393 -0
- package/dist/server/device-center/transfer-stream.js +5 -45
- package/dist/server/device-center/transfers.js +2 -10
- package/dist/server/device-center/verification-limits.js +9 -0
- package/dist/server/device-center/work-contract.js +923 -0
- package/dist/server/device-center/work-items.js +317 -0
- package/dist/server/device-center/workspaces.js +0 -1
- package/dist/server/dispatch-domain-handlers.js +202 -29
- package/dist/server/dispatch-plugin-handlers.js +2 -19
- package/dist/server/dsh/dsh-agent-service.js +78 -601
- package/dist/server/dsh/dsh-client.js +7 -111
- package/dist/server/dsh/dsh-market-service.js +4 -25
- package/dist/server/dsh/dsh-serialize.js +0 -49
- package/dist/server/dsh/dsh-sessions.js +0 -37
- package/dist/server/dsh/dsh-usage.js +0 -37
- package/dist/server/dsh/preset-clones.js +1 -65
- package/dist/server/dsh/runtime/custom-prompt.mjs +0 -14
- package/dist/server/dsh/runtime/goal-rpc.mjs +7 -176
- package/dist/server/dsh/runtime/launcher.mjs +2 -53
- package/dist/server/dsh/runtime/override.patch.yml +0 -29
- package/dist/server/dsh/runtime/runtime-root.mjs +0 -54
- package/dist/server/durable/durable-agent-service.js +5 -23
- package/dist/server/durable/durable-driver.js +12 -73
- package/dist/server/durable/durable-event-projector.js +1 -50
- package/dist/server/durable/durable-loader.js +0 -12
- package/dist/server/durable/durable-models.js +11 -80
- package/dist/server/durable/durable-storage.js +1 -17
- package/dist/server/durable/durable-tools.js +2 -20
- package/dist/server/durable/index.js +0 -3
- package/dist/server/edit-soft-tool.js +2 -81
- package/dist/server/engine-capabilities.js +0 -13
- package/dist/server/engine-catalog.js +74 -0
- package/dist/server/engine-cli.js +89 -0
- package/dist/server/engine-probe.js +35 -217
- package/dist/server/ensure-bash.js +2 -28
- package/dist/server/eval-tool.js +1 -50
- package/dist/server/evidence-tool-hooks.js +0 -2
- package/dist/server/file-archives.js +0 -10
- package/dist/server/file-save.js +1 -12
- package/dist/server/file-transfer-routes.js +0 -11
- package/dist/server/files-service.js +18 -271
- package/dist/server/global-loader.js +9 -89
- package/dist/server/goal-evidence.js +1 -35
- package/dist/server/goal-review-gate.js +0 -58
- package/dist/server/goal-service.js +19 -422
- package/dist/server/hashline-engine.js +8 -112
- package/dist/server/host-guard.js +0 -24
- package/dist/server/host-metrics.js +0 -6
- package/dist/server/http-proxy.js +1 -7
- package/dist/server/i18n.js +5 -72
- package/dist/server/icon-svg.js +0 -15
- package/dist/server/index.js +199 -677
- package/dist/server/json-utils.js +0 -12
- package/dist/server/launch-origin.js +0 -44
- package/dist/server/left-panel-running.js +0 -9
- package/dist/server/load-timing.js +1 -4
- package/dist/server/load-tools-tool.js +0 -20
- package/dist/server/locales.js +1 -46
- package/dist/server/lsp-tool.js +13 -126
- package/dist/server/managed.js +0 -48
- package/dist/server/marker-service.js +1 -22
- package/dist/server/markers/builtins/action.js +0 -19
- package/dist/server/markers/builtins/notify.js +1 -9
- package/dist/server/markers/builtins/rename.js +0 -13
- package/dist/server/markers/index.js +0 -3
- package/dist/server/markers/marker.js +0 -13
- package/dist/server/markers/registry.js +0 -3
- package/dist/server/markers/store.js +1 -12
- package/dist/server/market-service.js +7 -43
- package/dist/server/mcp-agent-tool.js +0 -10
- package/dist/server/mcp-bridge.js +6 -138
- package/dist/server/mcp-hot-reload.js +0 -25
- package/dist/server/mcp-manager.js +2 -44
- package/dist/server/mcp-oauth-login.js +0 -2
- package/dist/server/mcp-oauth-ui.js +1 -4
- package/dist/server/mcp-oauth.js +5 -79
- package/dist/server/mcp-project-runtime.js +0 -4
- package/dist/server/message-deletion.js +0 -2
- package/dist/server/message-entry-resolver.js +0 -8
- package/dist/server/message-window.js +0 -71
- package/dist/server/mobile-notification-events.js +16 -0
- package/dist/server/mobile-origin.js +79 -0
- package/dist/server/mobile-push.js +523 -0
- package/dist/server/model-admin.js +19 -358
- package/dist/server/model-enrich.js +0 -19
- package/dist/server/model-resolver.js +2 -61
- package/dist/server/native-cli-discovery.js +115 -0
- package/dist/server/native-cli-model.js +71 -0
- package/dist/server/native-cli-references.js +214 -0
- package/dist/server/native-cli-remote-cleanup.js +58 -0
- package/dist/server/native-cli-remote-files.js +282 -0
- package/dist/server/native-cli-routes.js +68 -0
- package/dist/server/native-cli-runtime.js +1 -0
- package/dist/server/native-cli-session-hooks.js +170 -0
- package/dist/server/native-cli-session.js +585 -0
- package/dist/server/native-cli-state.js +82 -0
- package/dist/server/native-cli.js +210 -0
- package/dist/server/net-guard.js +9 -71
- package/dist/server/office-parse.js +0 -50
- package/dist/server/orphan-manager.js +0 -18
- package/dist/server/patch-bash-process.js +0 -4
- package/dist/server/patch-executable-lookup.js +0 -77
- package/dist/server/patch-node-pty.js +6 -45
- package/dist/server/patch-remote-catalog.js +4 -34
- package/dist/server/patch-tool.js +0 -15
- package/dist/server/payload-limits.js +0 -5
- package/dist/server/pending-question.js +0 -5
- package/dist/server/permission-preset.js +4 -33
- package/dist/server/persona-chain.js +0 -26
- package/dist/server/pkg-info.js +1 -17
- package/dist/server/plan-manager.js +2 -49
- package/dist/server/plan-mode.js +0 -97
- package/dist/server/plan-update-tool.js +1 -15
- package/dist/server/plugin-api-catalog.js +6 -4
- package/dist/server/plugin-assets.js +1 -35
- package/dist/server/plugin-bundled.js +68 -0
- package/dist/server/plugin-catalog-sync.js +0 -37
- package/dist/server/plugin-catalog.js +13 -67
- package/dist/server/plugin-chat-attachments.js +0 -1
- package/dist/server/plugin-conversation-view.js +0 -20
- package/dist/server/plugin-dom.js +1 -23
- package/dist/server/plugin-facilities.js +4 -115
- package/dist/server/plugin-grants.js +2 -90
- package/dist/server/plugin-install-spec.js +0 -43
- package/dist/server/plugin-installer.js +34 -75
- package/dist/server/plugin-llm.js +4 -38
- package/dist/server/plugin-manifest-validate.js +0 -31
- package/dist/server/plugin-permissions.js +1 -24
- package/dist/server/plugin-project.js +7 -129
- package/dist/server/plugin-removal.js +1 -8
- package/dist/server/plugin-schedule.js +1 -38
- package/dist/server/plugin-secrets.js +3 -16
- package/dist/server/plugin-tool-guard.js +1 -28
- package/dist/server/plugin-ui-slots.js +0 -4
- package/dist/server/plugin-updater.js +15 -90
- package/dist/server/plugins.js +71 -619
- package/dist/server/present-files-tool.js +0 -57
- package/dist/server/preset-fields.js +24 -61
- package/dist/server/preset-plugin-dependencies.js +0 -2
- package/dist/server/preset-share.js +4 -172
- package/dist/server/process-utils.js +4 -80
- package/dist/server/prompt-assembler.js +2 -30
- package/dist/server/prompt-base-store.js +0 -47
- package/dist/server/prompt-composer.js +21 -98
- package/dist/server/prompt-templates.js +0 -2
- package/dist/server/protocol-version.js +1 -11
- package/dist/server/protocol.js +0 -5
- package/dist/server/queue-modes.js +0 -3
- package/dist/server/queue-utils.js +0 -40
- package/dist/server/quick-ask-context.js +384 -0
- package/dist/server/quick-ask-settings.js +61 -0
- package/dist/server/quick-ask.js +260 -0
- package/dist/server/read-tool.js +0 -65
- package/dist/server/reasoning-registry.js +1 -29
- package/dist/server/remote-cli-persistence.js +373 -0
- package/dist/server/remote-native-cli.js +78 -0
- package/dist/server/remote-ssh-service.js +481 -190
- package/dist/server/request-context.js +0 -9
- package/dist/server/resolve-global-sdk.js +55 -31
- package/dist/server/sandbox-data.js +0 -1
- package/dist/server/sandbox-engines.js +0 -1
- package/dist/server/sandbox-runtime-gate.js +0 -3
- package/dist/server/sandbox-service.js +0 -41
- package/dist/server/sandbox-tool.js +0 -20
- package/dist/server/schedule-agent-tool.js +2 -31
- package/dist/server/scheduler-tasks.js +32 -56
- package/dist/server/scm-commitmsg.js +0 -53
- package/dist/server/scm.js +3 -48
- package/dist/server/sdk-builtin-extensions.js +2 -29
- package/dist/server/sdk-origin.js +0 -45
- package/dist/server/serialize.js +2 -92
- package/dist/server/server-config.js +0 -11
- package/dist/server/session-branch.js +1 -87
- package/dist/server/session-list-scan.js +215 -0
- package/dist/server/session-open.js +69 -0
- package/dist/server/session-parser.js +4 -54
- package/dist/server/session-scan.js +81 -45
- package/dist/server/session-search.js +0 -56
- package/dist/server/settings-service.js +19 -126
- package/dist/server/setup-config.js +0 -2
- package/dist/server/setup-page.js +0 -9
- package/dist/server/skill-content-filler.js +0 -17
- package/dist/server/skill-discovery.js +5 -92
- package/dist/server/skill-maintenance.js +1 -28
- package/dist/server/skill-tool.js +0 -30
- package/dist/server/slash-commands.js +5 -50
- package/dist/server/soft-cap.js +3 -40
- package/dist/server/startup-banner.js +0 -8
- package/dist/server/subagent-handoff.js +0 -11
- package/dist/server/subagent-helpers.js +2 -17
- package/dist/server/subagent-notify.js +0 -19
- package/dist/server/subagent-security-gate.js +0 -50
- package/dist/server/subagent-task.js +0 -9
- package/dist/server/subagent-templates-hant.js +0 -10
- package/dist/server/subagent-templates.js +3 -103
- package/dist/server/subagents.js +1 -87
- package/dist/server/system-screenshot-windows.js +259 -0
- package/dist/server/system-screenshot.js +77 -0
- package/dist/server/tabs.js +3 -48
- package/dist/server/terminals.js +559 -586
- package/dist/server/text-quote.js +0 -12
- package/dist/server/text-sniff.js +2 -52
- package/dist/server/themes.js +2 -41
- package/dist/server/tool-approval.js +0 -47
- package/dist/server/tool-guards.js +0 -90
- package/dist/server/tool-host-factories.js +1 -16
- package/dist/server/tool-info.js +0 -13
- package/dist/server/tool-manager.js +1 -229
- package/dist/server/tool-overrides.js +1 -46
- package/dist/server/tool-prompt-overrides.js +1 -30
- package/dist/server/tool-prompts.js +0 -14
- package/dist/server/tool-signature.js +0 -25
- package/dist/server/transcript-prepare.js +55 -0
- package/dist/server/tts-routes.js +58 -0
- package/dist/server/tts-service.js +106 -0
- package/dist/server/tts-system.js +160 -0
- package/dist/server/turn-timing.js +0 -1
- package/dist/server/unauthorized-page.js +0 -8
- package/dist/server/universal/driver-base.js +2 -31
- package/dist/server/universal/drivers/claude-code.js +98 -194
- package/dist/server/universal/drivers/codex.js +12 -35
- package/dist/server/universal/drivers/mock-driver.js +1 -11
- package/dist/server/universal/index.js +0 -3
- package/dist/server/universal/session-store.js +4 -21
- package/dist/server/universal/universal-attachments.js +2 -36
- package/dist/server/universal/universal-service.js +5 -24
- package/dist/server/universal/universal-session.js +30 -148
- package/dist/server/universal/universal-types.js +0 -3
- package/dist/server/update-check.js +6 -182
- package/dist/server/uploads.js +4 -43
- package/dist/server/virtual-tui.js +2 -27
- package/dist/server/vision-bridge.js +0 -27
- package/dist/server/wait-subscription-scan.js +13 -115
- package/dist/server/webui-context.js +2 -87
- package/dist/server/workspace-handle.js +373 -0
- package/dist/server/workspace-snapshot.js +7 -113
- package/dist/server/worktree-service.js +2 -53
- package/dist/server/worktree-tool.js +0 -11
- package/dist/server/ws-client-id.js +0 -18
- package/dist/server/ws-pending-queue.js +0 -7
- package/dist/server/ws-unknown-types.js +0 -17
- package/docs/README.md +24 -17
- package/docs/architecture-plugins.md +55 -6
- package/docs/device-center.md +57 -23
- package/docs/device-desktop.md +3 -3
- package/docs/group-orchestration.md +142 -0
- package/docs/hub-upgrade-release-testing.md +46 -0
- package/extensions/webui.ts +3 -74
- package/package.json +9 -6
- package/plugin-sdk/README.md +22 -8
- package/plugin-sdk/client-utils.mjs +0 -7
- package/plugin-sdk/client.d.ts +26 -0
- package/plugin-sdk/client.mjs +52 -0
- package/plugin-sdk/import-check.mjs +4 -51
- package/plugin-sdk/index.d.ts +128 -117
- package/plugin-sdk/index.mjs +2 -687
- package/plugin-sdk/package.json +15 -4
- package/plugin-sdk/ssh-host-trust.mjs +0 -12
- package/plugin-sdk/testing.d.ts +9 -0
- package/plugin-sdk/testing.mjs +511 -0
- package/plugins/catalog.json +52 -4
- package/plugins/superagent/README.md +110 -0
- package/plugins/superagent/client/entry.mjs +21 -0
- package/plugins/superagent/index.mjs +8 -0
- package/plugins/superagent/main.mjs +218 -0
- package/plugins/superagent/manifest.json +15 -0
- package/plugins/superagent/server.mjs +572 -0
- package/plugins/superagent/style.css +167 -0
- package/themes/aetheris.css +1 -31
- package/themes/ayu-light.css +0 -1
- package/themes/bases/flow-base.css +2 -83
- package/themes/bases/obsidian-base.css +2 -37
- package/themes/bases/statusbar-flat-base.css +0 -1
- package/themes/bases/zhujian-base.css +0 -63
- package/themes/bases/zhupi-base.css +0 -64
- package/themes/catppuccin-latte.css +0 -1
- package/themes/catppuccin.css +0 -1
- package/themes/claude-code-dark.css +0 -1
- package/themes/codex.css +0 -1
- package/themes/dark-teal.css +22 -54
- package/themes/everforest-light.css +0 -1
- package/themes/flow-cristallo.css +160 -0
- package/themes/flow-ink.css +160 -0
- package/themes/flow-light.css +1 -10
- package/themes/flow-obsidian.css +160 -0
- package/themes/flow-zurich.css +160 -0
- package/themes/flow.css +1 -9
- package/themes/geist.css +0 -1
- package/themes/gruvbox-light.css +0 -1
- package/themes/kanagawa-lotus.css +0 -1
- package/themes/md-preview.css +1 -2
- package/themes/mist.css +0 -1
- package/themes/nord.css +0 -1
- package/themes/one-dark.css +0 -1
- package/themes/paper.css +0 -1
- package/themes/rose-pine-dawn.css +0 -1
- package/themes/sakura.css +0 -1
- package/themes/solarized-light.css +0 -1
- package/themes/tokyo-night.css +0 -1
- package/themes/translucent.css +4 -35
- package/themes/transparent.css +4 -41
- package/themes/vs-code-dark.css +0 -1
- package/themes/wallpaper-flow.css +3 -17
- package/themes/wallpaper-obsidian.css +1 -4
- package/themes/white.css +0 -1
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/{BgTasksModal-BDoOpj-F.js → BgTasksModal-D-x7kA63.js} +1 -1
- package/web/dist/assets/CanvasStudio-CAWcs9tm.js +1579 -0
- package/web/dist/assets/DeviceCenter-Dc0whRcu.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-BoX7-0h7.js +1 -0
- package/web/dist/assets/DeviceGroups-C_fZMNeK.js +1 -0
- package/web/dist/assets/{Dropdown-C4LIhshN.js → Dropdown-CTgVLUbp.js} +1 -1
- package/web/dist/assets/FilePreview-C6W0PvaK.js +2 -0
- package/web/dist/assets/GlobalSearchModal-HR9LSspC.js +1 -0
- package/web/dist/assets/GroupConversation-C81YjF2C.js +61 -0
- package/web/dist/assets/GroupWorkItems-BIvZtr10.js +1 -0
- package/web/dist/assets/{HintTip-c6d0TJoh.js → HintTip-Da6qc566.js} +1 -1
- package/web/dist/assets/ModelConfigModal-DhSyuIuV.js +2 -0
- package/web/dist/assets/NativeCliPanel-CU1rZmyu.js +5 -0
- package/web/dist/assets/{PiSetupModal-BmMrrgB9.js → PiSetupModal-DZKY5Wiw.js} +1 -1
- package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +1 -0
- package/web/dist/assets/SCMPanel-CuEgzAlO.js +2 -0
- package/web/dist/assets/SettingsModal-Cdu5h29p.js +33 -0
- package/web/dist/assets/TermXterm-Bt5WKAxP.js +3 -0
- package/web/dist/assets/TerminalPanel-BCIBV8se.js +1 -0
- package/web/dist/assets/TuiOverlayModal-3NDd9T97.js +1 -0
- package/web/dist/assets/app-globals-CZjFtI4F.js +129 -0
- package/web/dist/assets/canvas-client-WkhM55mR.js +1 -0
- package/web/dist/assets/composer-bridge-CImnjDHq.js +1 -0
- package/web/dist/assets/desktop-B8NZ3KW-.js +1 -0
- package/web/dist/assets/index-CQc3VrWa.css +1 -0
- package/web/dist/assets/index-D_AGu4Zv.js +404 -0
- package/web/dist/assets/plugin-host-uqZGpvCs.js +1 -0
- package/web/dist/assets/{remote-ssh-client-CfYSMEZg.js → remote-ssh-client-Cdf-cTUe.js} +1 -1
- package/web/dist/assets/theme-DGL7hLUs.js +1 -0
- package/web/dist/index.html +12 -11
- package/web/dist/sw.js +15 -61
- package/web/public/sw.js +14 -60
- package/dist/gh-comment-781.md +0 -5
- package/dist/server/device-center/local-page.js +0 -17
- package/dist/server/device-center/smoke-preview.js +0 -3
- package/dist/server/durable/durable-capabilities.js +0 -11
- package/dist/server/markers/builtins/services.js +0 -123
- package/dist/server/markers/builtins/todo.js +0 -189
- package/dist/server/markers-list-tool.js +0 -34
- package/dist/server/orchestrator.js +0 -109
- package/dist/server/patch-turn-end-boundary.js +0 -77
- package/dist/server/system-prompt-soul.js +0 -41
- package/dist/server/univer-service.js +0 -448
- package/dist/server/universal/drivers/dsh-driver.js +0 -379
- package/dist/test-artifact.md +0 -9
- package/dist/test-preview-modal.md +0 -11
- package/dist/test-report.html +0 -20
- package/web/dist/assets/BgTasksModal-C0i3O1FT.js +0 -1
- package/web/dist/assets/CanvasStudio-B8thymBN.js +0 -1579
- package/web/dist/assets/CanvasStudio-zSxyIx1R.js +0 -1579
- package/web/dist/assets/DeviceCenter-DfAHKcid.js +0 -3
- package/web/dist/assets/DeviceCenter-ydvOTlzE.js +0 -3
- package/web/dist/assets/DeviceExecutionSettings-q5Ik8oXg.js +0 -1
- package/web/dist/assets/DeviceGroups-CI14_SRb.js +0 -1
- package/web/dist/assets/DeviceGroups-DvsB5IEU.js +0 -1
- package/web/dist/assets/FilePreview-BgGongmv.js +0 -2
- package/web/dist/assets/FilePreview-D4NrhF-U.js +0 -2
- package/web/dist/assets/GlobalSearchModal-BWgU8yPd.js +0 -1
- package/web/dist/assets/GlobalSearchModal-F7fNimKk.js +0 -1
- package/web/dist/assets/GroupConversation-Dh71Pdb-.js +0 -17
- package/web/dist/assets/GroupConversation-ZK3nRmNm.js +0 -17
- package/web/dist/assets/ModelConfigModal-YVEgyy34.js +0 -2
- package/web/dist/assets/ModelConfigModal-vWtg3srp.js +0 -2
- package/web/dist/assets/ProviderOAuthControls-BGSBIKD7.js +0 -1
- package/web/dist/assets/SCMPanel-B8_EDxNr.js +0 -2
- package/web/dist/assets/SCMPanel-BU58qk3T.js +0 -2
- package/web/dist/assets/SettingsModal-CMUybq3J.js +0 -32
- package/web/dist/assets/SettingsModal-OBmGTh-5.js +0 -32
- package/web/dist/assets/TerminalPanel-0CYvD72B.js +0 -3
- package/web/dist/assets/TerminalPanel-DDavKvFr.js +0 -3
- package/web/dist/assets/TuiOverlayModal-BsA-QTvN.js +0 -1
- package/web/dist/assets/TuiOverlayModal-DzoVQBuG.js +0 -1
- package/web/dist/assets/app-globals-CZxzGvIo.js +0 -123
- package/web/dist/assets/canvas-client-CUnXlQYX.js +0 -1
- package/web/dist/assets/desktop-aAKpvKJV.js +0 -1
- package/web/dist/assets/index-C6DwztqE.css +0 -1
- package/web/dist/assets/index-CuN802Sj.js +0 -93
- package/web/dist/assets/index-EH5Fw9fa.js +0 -93
- package/web/dist/assets/plugin-host-BRWib9DF.js +0 -1
- package/web/dist/assets/theme-D2l_mLNo.js +0 -1
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import {
|
|
4
|
+
existsSync,
|
|
5
|
+
readFileSync,
|
|
6
|
+
appendFileSync,
|
|
7
|
+
writeFileSync,
|
|
8
|
+
renameSync,
|
|
9
|
+
mkdirSync,
|
|
10
|
+
rmSync,
|
|
11
|
+
openSync,
|
|
12
|
+
closeSync,
|
|
13
|
+
readdirSync,
|
|
14
|
+
} from "node:fs";
|
|
15
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
16
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
17
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
18
|
+
import { acquireHubLock, hubServicePlan, runManager, probeHub, windowsArg } from "./device-hub-cli.mjs";
|
|
19
|
+
|
|
20
|
+
const SELF = fileURLToPath(import.meta.url);
|
|
21
|
+
const PACKAGE = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
22
|
+
export const UPGRADE_TIMEOUT_MS = 30 * 60_000;
|
|
23
|
+
export const jobPathFor = (dataDir) => join(resolve(dataDir), "hub-upgrade.json");
|
|
24
|
+
export function readUpgradeJob(path) {
|
|
25
|
+
if (!existsSync(path)) return undefined;
|
|
26
|
+
const job = JSON.parse(readFileSync(path, "utf8"));
|
|
27
|
+
if (
|
|
28
|
+
job.schemaVersion !== 1 ||
|
|
29
|
+
typeof job.id !== "string" ||
|
|
30
|
+
!/^[a-f0-9-]{36}$/.test(job.id) ||
|
|
31
|
+
!["queued", "running", "succeeded", "failed"].includes(job.state)
|
|
32
|
+
)
|
|
33
|
+
throw new Error("Invalid Hub upgrade job");
|
|
34
|
+
return job;
|
|
35
|
+
}
|
|
36
|
+
export function writeUpgradeJob(path, job) {
|
|
37
|
+
const temp = `${path}.${randomUUID()}.tmp`;
|
|
38
|
+
try {
|
|
39
|
+
writeFileSync(temp, `${JSON.stringify(job, null, 2)}\n`, { flag: "wx", mode: 0o600 });
|
|
40
|
+
renameSync(temp, path);
|
|
41
|
+
} finally {
|
|
42
|
+
rmSync(temp, { force: true });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function planForJob(job) {
|
|
46
|
+
const env = { ...process.env, PI_DEVICE_HUB_SERVICE_NAME: job.serviceName ?? "pi-device-hub" };
|
|
47
|
+
if (job.serviceConfigPath === undefined) return hubServicePlan({ env });
|
|
48
|
+
if (typeof job.serviceConfigPath !== "string" || !isAbsolute(job.serviceConfigPath))
|
|
49
|
+
throw new Error("Invalid Hub service configuration path in upgrade job");
|
|
50
|
+
const config = resolve(job.serviceConfigPath);
|
|
51
|
+
const root = dirname(config);
|
|
52
|
+
// Native workers inherit the service manager's environment, not the submitting CLI's HOME/APPDATA.
|
|
53
|
+
const plan = hubServicePlan(
|
|
54
|
+
process.platform === "win32" ? { env: { ...env, APPDATA: dirname(root) } } : { env, home: dirname(dirname(root)) },
|
|
55
|
+
);
|
|
56
|
+
if (resolve(plan.config) !== config) throw new Error("Upgrade job configuration is not a Hub service path");
|
|
57
|
+
return plan;
|
|
58
|
+
}
|
|
59
|
+
function installedSettings(plan, job) {
|
|
60
|
+
if (!existsSync(plan.config)) throw new Error("Hub service is not installed; install it before updating");
|
|
61
|
+
const settings = JSON.parse(readFileSync(plan.config, "utf8"));
|
|
62
|
+
if (
|
|
63
|
+
job &&
|
|
64
|
+
(settings.PI_DEVICE_HUB_INSTANCE_ID !== job.instanceId ||
|
|
65
|
+
(settings.PI_DEVICE_HUB_SERVICE_NAME ?? "pi-device-hub") !== (job.serviceName ?? "pi-device-hub") ||
|
|
66
|
+
resolve(settings.PI_DEVICE_HUB_DATA_DIR) !== dirname(resolve(job.path)))
|
|
67
|
+
)
|
|
68
|
+
throw new Error("Upgrade job does not belong to this installed Hub");
|
|
69
|
+
return settings;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function execute(file, args, { timeout = 10 * 60_000, logPath, env = process.env, signal } = {}) {
|
|
73
|
+
return new Promise((resolveCommand, reject) => {
|
|
74
|
+
let output = "";
|
|
75
|
+
const fd = logPath ? openSync(logPath, "a", 0o600) : undefined;
|
|
76
|
+
let child;
|
|
77
|
+
try {
|
|
78
|
+
child = spawn(file, args, { env, signal, windowsHide: true, stdio: ["ignore", fd ?? "pipe", fd ?? "pipe"] });
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (fd !== undefined) closeSync(fd);
|
|
81
|
+
return reject(error);
|
|
82
|
+
}
|
|
83
|
+
if (fd !== undefined) closeSync(fd);
|
|
84
|
+
for (const stream of [child.stdout, child.stderr])
|
|
85
|
+
stream?.on("data", (chunk) => {
|
|
86
|
+
output = (output + chunk).slice(-8192);
|
|
87
|
+
});
|
|
88
|
+
const timer = setTimeout(() => {
|
|
89
|
+
child.kill();
|
|
90
|
+
reject(new Error("Hub upgrade command timed out"));
|
|
91
|
+
}, timeout);
|
|
92
|
+
child.once("error", (error) => {
|
|
93
|
+
clearTimeout(timer);
|
|
94
|
+
reject(error);
|
|
95
|
+
});
|
|
96
|
+
child.once("exit", (code, signal) => {
|
|
97
|
+
clearTimeout(timer);
|
|
98
|
+
if (code === 0) resolveCommand(output.trim());
|
|
99
|
+
else
|
|
100
|
+
reject(
|
|
101
|
+
new Error(
|
|
102
|
+
`Hub upgrade command failed (${code ?? signal})${logPath ? `; see ${logPath}` : `: ${output.trim()}`}`,
|
|
103
|
+
),
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
export function independentWorkerPlan(
|
|
109
|
+
jobPath,
|
|
110
|
+
{
|
|
111
|
+
platform = process.platform,
|
|
112
|
+
node = process.execPath,
|
|
113
|
+
worker = SELF,
|
|
114
|
+
id = randomUUID(),
|
|
115
|
+
uid = process.getuid?.() ?? 0,
|
|
116
|
+
} = {},
|
|
117
|
+
) {
|
|
118
|
+
if (!/^[a-f0-9-]{36}$/.test(id)) throw new Error("Invalid Hub upgrade worker id");
|
|
119
|
+
const args = [worker, "--run", resolve(jobPath)];
|
|
120
|
+
if (platform === "linux")
|
|
121
|
+
return {
|
|
122
|
+
file: "systemd-run",
|
|
123
|
+
args: ["--user", "--collect", `--unit=pi-device-hub-update-${id}`, "--property=Type=exec", node, ...args],
|
|
124
|
+
};
|
|
125
|
+
if (platform === "darwin") {
|
|
126
|
+
if (!Number.isSafeInteger(uid) || uid < 0) throw new Error("Invalid Hub upgrade worker uid");
|
|
127
|
+
const label = `com.xingshuyin.pi-device-hub-update-${id}`;
|
|
128
|
+
const plist = join(dirname(resolve(jobPath)), `${label}.plist`);
|
|
129
|
+
const log = join(dirname(resolve(jobPath)), "hub-upgrade-worker.log");
|
|
130
|
+
const xml = (value) =>
|
|
131
|
+
String(value).replace(
|
|
132
|
+
/[<>&"']/g,
|
|
133
|
+
(c) => ({ "<": "<", ">": ">", "&": "&", '"': """, "'": "'" })[c],
|
|
134
|
+
);
|
|
135
|
+
return {
|
|
136
|
+
file: "launchctl",
|
|
137
|
+
args: ["bootstrap", `gui/${uid}`, plist],
|
|
138
|
+
target: `gui/${uid}/${label}`,
|
|
139
|
+
definition: {
|
|
140
|
+
path: plist,
|
|
141
|
+
content: `<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0"><dict><key>Label</key><string>${xml(label)}</string><key>ProgramArguments</key><array>${[node, ...args].map((arg) => `<string>${xml(arg)}</string>`).join("")}</array><key>RunAtLoad</key><true/><key>KeepAlive</key><false/><key>LaunchOnlyOnce</key><true/><key>StandardOutPath</key><string>${xml(log)}</string><key>StandardErrorPath</key><string>${xml(log)}</string></dict></plist>\n`,
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if (platform === "win32") {
|
|
146
|
+
const task = `pi-device-hub-update-${id}`;
|
|
147
|
+
const quote = (s) => `'${s.replace(/'/g, "''")}'`;
|
|
148
|
+
const winArg = (s) => `"${s.replace(/(\\*)"/g, '$1$1\\"').replace(/(\\+)$/g, "$1$1")}"`;
|
|
149
|
+
const script = `$ErrorActionPreference='Stop'; $a=New-ScheduledTaskAction -Execute ${quote(node)} -Argument ${quote(args.map(winArg).join(" "))}; $s=New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Minutes 30) -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries; $u=[System.Security.Principal.WindowsIdentity]::GetCurrent().Name; Register-ScheduledTask -TaskName ${quote(task)} -Action $a -Settings $s -User $u -RunLevel Limited -Force | Out-Null; Start-ScheduledTask -TaskName ${quote(task)};`;
|
|
150
|
+
return { file: "powershell.exe", args: ["-NoProfile", "-NonInteractive", "-Command", script], task };
|
|
151
|
+
}
|
|
152
|
+
throw new Error(`Hub updates are unsupported on ${platform}`);
|
|
153
|
+
}
|
|
154
|
+
export async function launchUpgradeJob(
|
|
155
|
+
path,
|
|
156
|
+
{ plan, run = execute, probe = probeHub, sleep = delay, ...options } = {},
|
|
157
|
+
) {
|
|
158
|
+
const job = readUpgradeJob(path);
|
|
159
|
+
if (!job || job.state !== "queued") throw new Error("Hub upgrade job is not queued");
|
|
160
|
+
plan ??= planForJob(job);
|
|
161
|
+
const settings = installedSettings(plan, { ...job, path });
|
|
162
|
+
const health = await probe(settings);
|
|
163
|
+
if (!health || health.instanceId !== job.instanceId || health.bootId !== job.fromBootId)
|
|
164
|
+
throw new Error("Hub process changed before upgrade submission");
|
|
165
|
+
const launch = independentWorkerPlan(path, { ...options, id: job.id });
|
|
166
|
+
let definitionCreated = false;
|
|
167
|
+
let submissionAttempted = false;
|
|
168
|
+
try {
|
|
169
|
+
if (launch.definition) {
|
|
170
|
+
writeFileSync(launch.definition.path, launch.definition.content, { flag: "wx", mode: 0o600 });
|
|
171
|
+
definitionCreated = true;
|
|
172
|
+
}
|
|
173
|
+
submissionAttempted = true;
|
|
174
|
+
await run(launch.file, launch.args, { timeout: 30_000 });
|
|
175
|
+
const deadline = Date.now() + 10_000;
|
|
176
|
+
while (Date.now() < deadline) {
|
|
177
|
+
const current = readUpgradeJob(path);
|
|
178
|
+
if (current?.id !== job.id) throw new Error("Hub upgrade job changed during submission");
|
|
179
|
+
if (current.state === "failed") throw new Error(current.error || "Hub upgrade worker failed to start");
|
|
180
|
+
if (current.state !== "queued") return;
|
|
181
|
+
await sleep(100);
|
|
182
|
+
}
|
|
183
|
+
throw new Error("Hub upgrade worker did not start; inspect the system service manager");
|
|
184
|
+
} catch (error) {
|
|
185
|
+
if (submissionAttempted && launch.target) {
|
|
186
|
+
try {
|
|
187
|
+
await run(launch.file, ["bootout", launch.target], { timeout: 30_000 });
|
|
188
|
+
} catch {}
|
|
189
|
+
}
|
|
190
|
+
throw error;
|
|
191
|
+
} finally {
|
|
192
|
+
if (definitionCreated) rmSync(launch.definition.path, { force: true });
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function npmCli(node = process.execPath) {
|
|
196
|
+
const candidates = [
|
|
197
|
+
join(dirname(node), "node_modules/npm/bin/npm-cli.js"),
|
|
198
|
+
join(dirname(node), "../lib/node_modules/npm/bin/npm-cli.js"),
|
|
199
|
+
];
|
|
200
|
+
const path = candidates.find(existsSync);
|
|
201
|
+
if (!path) throw new Error("npm is required beside Node to update the Hub; install Node with npm and retry");
|
|
202
|
+
return path;
|
|
203
|
+
}
|
|
204
|
+
async function installRelease(
|
|
205
|
+
root,
|
|
206
|
+
{ source = `${PACKAGE.name}@latest`, executeCommand = execute, env = process.env, logPath } = {},
|
|
207
|
+
) {
|
|
208
|
+
const release = join(root, "releases", randomUUID());
|
|
209
|
+
mkdirSync(release, { recursive: true, mode: 0o700 });
|
|
210
|
+
try {
|
|
211
|
+
await executeCommand(
|
|
212
|
+
process.execPath,
|
|
213
|
+
[
|
|
214
|
+
npmCli(),
|
|
215
|
+
"install",
|
|
216
|
+
"--prefix",
|
|
217
|
+
release,
|
|
218
|
+
"--omit=dev",
|
|
219
|
+
"--omit=optional",
|
|
220
|
+
"--ignore-scripts",
|
|
221
|
+
"--no-audit",
|
|
222
|
+
"--no-fund",
|
|
223
|
+
"--package-lock=false",
|
|
224
|
+
source,
|
|
225
|
+
],
|
|
226
|
+
{ env, logPath },
|
|
227
|
+
);
|
|
228
|
+
const rootPath = join(release, "node_modules", PACKAGE.name);
|
|
229
|
+
const pkg = JSON.parse(readFileSync(join(rootPath, "package.json"), "utf8"));
|
|
230
|
+
if (pkg.name !== PACKAGE.name || typeof pkg.version !== "string")
|
|
231
|
+
throw new Error("Installed Hub package identity does not match");
|
|
232
|
+
const entry = join(rootPath, "bin/pi-device-hub.mjs");
|
|
233
|
+
if (!existsSync(entry) || !existsSync(join(rootPath, "dist/server/device-center/main.js")))
|
|
234
|
+
throw new Error("Installed package is missing the standalone Hub build");
|
|
235
|
+
await executeCommand(
|
|
236
|
+
process.execPath,
|
|
237
|
+
[
|
|
238
|
+
"--input-type=module",
|
|
239
|
+
"-e",
|
|
240
|
+
`await import(${JSON.stringify(pathToFileURL(join(rootPath, "dist/server/device-center/main.js")).href)})`,
|
|
241
|
+
],
|
|
242
|
+
{ env, logPath, timeout: 30_000 },
|
|
243
|
+
);
|
|
244
|
+
return { root: release, entry, version: pkg.version };
|
|
245
|
+
} catch (error) {
|
|
246
|
+
rmSync(release, { recursive: true, force: true });
|
|
247
|
+
throw error;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
export async function waitForRelease(
|
|
251
|
+
settings,
|
|
252
|
+
{ version, fromBootId, legacy = false, probe = probeHub, timeout = 30_000, sleep = delay } = {},
|
|
253
|
+
) {
|
|
254
|
+
const deadline = Date.now() + timeout;
|
|
255
|
+
let observed = "unreachable";
|
|
256
|
+
while (Date.now() < deadline) {
|
|
257
|
+
const health = await probe(settings);
|
|
258
|
+
observed = health
|
|
259
|
+
? `instance=${health.instanceId === settings.PI_DEVICE_HUB_INSTANCE_ID ? "expected" : "other"}, registration=${health.allowRegistration === (settings.PI_DEVICE_HUB_ALLOW_REGISTRATION === "1") ? "expected" : "other"}, version=${typeof health.version === "string" && /^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/.test(health.version) && health.version.length <= 80 ? health.version : "missing/invalid"}, boot=${typeof health.bootId !== "string" ? "missing" : health.bootId === fromBootId ? "unchanged" : "changed"}`
|
|
260
|
+
: "unreachable";
|
|
261
|
+
if (
|
|
262
|
+
health &&
|
|
263
|
+
health.instanceId === settings.PI_DEVICE_HUB_INSTANCE_ID &&
|
|
264
|
+
health.allowRegistration === (settings.PI_DEVICE_HUB_ALLOW_REGISTRATION === "1") &&
|
|
265
|
+
(legacy || (health.version === version && typeof health.bootId === "string" && health.bootId !== fromBootId))
|
|
266
|
+
)
|
|
267
|
+
return health;
|
|
268
|
+
await sleep(250);
|
|
269
|
+
}
|
|
270
|
+
throw new Error(
|
|
271
|
+
`Updated Hub did not start with expected version ${version}; old healthy processes do not count as a successful upgrade; last health: ${observed}`,
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
export async function queryWindowsHubTcp(settings, { run = execute, timeout = 10_000, signal } = {}) {
|
|
275
|
+
const port = Number(settings.PI_DEVICE_HUB_PORT);
|
|
276
|
+
const host = settings.PI_DEVICE_HUB_HOST;
|
|
277
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535 || typeof host !== "string" || !host)
|
|
278
|
+
throw new Error("Invalid Windows Hub TCP endpoint");
|
|
279
|
+
const quote = (s) => `'${s.replace(/'/g, "''")}'`;
|
|
280
|
+
try {
|
|
281
|
+
if (signal?.aborted) throw new Error("Cancelled");
|
|
282
|
+
// CIM returns an empty array for no matches and throws on provider/query failures.
|
|
283
|
+
const output = await run(
|
|
284
|
+
"powershell.exe",
|
|
285
|
+
[
|
|
286
|
+
"-NoProfile",
|
|
287
|
+
"-NonInteractive",
|
|
288
|
+
"-Command",
|
|
289
|
+
`$ErrorActionPreference='Stop'; $ProgressPreference='SilentlyContinue'; $literal=$null; if ([Net.IPAddress]::TryParse(${quote(host)}, [ref]$literal)) { $addresses=@($literal) } else { $addresses=@([Net.Dns]::GetHostAddresses(${quote(host)})) }; if ($addresses.Count -eq 0) { throw 'Hub host has no addresses' }; $keys=@($addresses | ForEach-Object { if ($_.IsIPv4MappedToIPv6) { $_.MapToIPv4().ToString() } else { $_.ToString() } }); $has4=@($keys | Where-Object { $_ -notmatch ':' }).Count -gt 0; $any4=$keys -contains '0.0.0.0'; $any6=$keys -contains '::'; $rows=@(Get-CimInstance -Namespace root/StandardCimv2 -ClassName MSFT_NetTCPConnection -Filter 'LocalPort = ${port}' -ErrorAction Stop | Where-Object { $ip=[Net.IPAddress]::Parse($_.LocalAddress); if ($ip.IsIPv4MappedToIPv6) { $ip=$ip.MapToIPv4() }; $key=$ip.ToString(); $any6 -or ($any4 -and $ip.AddressFamily -eq [Net.Sockets.AddressFamily]::InterNetwork) -or ($keys -contains $key) -or $key -eq '::' -or ($has4 -and $key -eq '0.0.0.0') } | Select-Object -First 32 | ForEach-Object { if ($null -eq $_.State -or $null -eq $_.OwningProcess) { throw 'Invalid TCP resource' }; [pscustomobject]@{state=[int]$_.State;pid=[long]$_.OwningProcess} }); ConvertTo-Json -InputObject $rows -Compress`,
|
|
290
|
+
],
|
|
291
|
+
{ timeout, signal },
|
|
292
|
+
);
|
|
293
|
+
if (signal?.aborted) throw new Error("Cancelled");
|
|
294
|
+
const rows = JSON.parse(output);
|
|
295
|
+
if (
|
|
296
|
+
!Array.isArray(rows) ||
|
|
297
|
+
rows.some(
|
|
298
|
+
(row) =>
|
|
299
|
+
!row || !Number.isSafeInteger(row.state) || row.state < 1 || !Number.isSafeInteger(row.pid) || row.pid < 0,
|
|
300
|
+
)
|
|
301
|
+
)
|
|
302
|
+
throw new Error("Invalid TCP resource result");
|
|
303
|
+
return rows.map(({ state, pid }) => ({ state, pid }));
|
|
304
|
+
} catch {
|
|
305
|
+
throw new Error(
|
|
306
|
+
signal?.aborted ? "Windows Hub TCP handoff cancelled" : "Could not query Windows Hub TCP resources",
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
export async function waitForWindowsHubPort(
|
|
311
|
+
settings,
|
|
312
|
+
{ query = queryWindowsHubTcp, now = () => performance.now(), sleep = delay, signal, onState = () => {} } = {},
|
|
313
|
+
) {
|
|
314
|
+
const deadline = now() + 4 * 60_000;
|
|
315
|
+
let rows = [];
|
|
316
|
+
let previousState;
|
|
317
|
+
while (now() < deadline) {
|
|
318
|
+
if (signal?.aborted) throw new Error("Windows Hub TCP handoff cancelled");
|
|
319
|
+
const remaining = deadline - now();
|
|
320
|
+
if (remaining <= 0) break;
|
|
321
|
+
rows = await query(settings, { timeout: Math.min(10_000, remaining), signal });
|
|
322
|
+
if (signal?.aborted) throw new Error("Windows Hub TCP handoff cancelled");
|
|
323
|
+
if (now() >= deadline) break;
|
|
324
|
+
const snapshot = JSON.stringify([...rows].sort((a, b) => a.state - b.state || a.pid - b.pid));
|
|
325
|
+
if (snapshot !== previousState) {
|
|
326
|
+
try {
|
|
327
|
+
onState(rows);
|
|
328
|
+
} catch {}
|
|
329
|
+
previousState = snapshot;
|
|
330
|
+
}
|
|
331
|
+
if (rows.length === 0) return;
|
|
332
|
+
const remainingSleep = deadline - now();
|
|
333
|
+
if (remainingSleep <= 0) break;
|
|
334
|
+
await sleep(Math.min(1000, remainingSleep), undefined, { signal });
|
|
335
|
+
}
|
|
336
|
+
throw new Error(
|
|
337
|
+
`Windows Hub TCP resources did not drain within 4 minutes; state/pid=${JSON.stringify(rows.slice(0, 32))}`,
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
function recordWindowsServiceFailure(plan, candidate, logPath, run) {
|
|
341
|
+
if (plan.manager !== "schtasks.exe") return;
|
|
342
|
+
try {
|
|
343
|
+
const quote = (s) => `'${String(s).replace(/'/g, "''")}'`;
|
|
344
|
+
const statusArgs = plan.commands.status[0];
|
|
345
|
+
const taskIndex = statusArgs.indexOf("/TN");
|
|
346
|
+
if (taskIndex < 0 || typeof statusArgs[taskIndex + 1] !== "string") throw new Error("Missing Hub task name");
|
|
347
|
+
const task = statusArgs[taskIndex + 1];
|
|
348
|
+
const expectedArgs = [candidate.entry, "--service-config", plan.config].map(windowsArg).join(" ");
|
|
349
|
+
const output = run("powershell.exe", [
|
|
350
|
+
"-NoProfile",
|
|
351
|
+
"-NonInteractive",
|
|
352
|
+
"-Command",
|
|
353
|
+
`$ErrorActionPreference='Stop'; $s=New-Object -ComObject Schedule.Service; $s.Connect(); $t=$s.GetFolder('\\').GetTask(${quote(task)}); $a=$t.Definition.Actions.Item(1); [pscustomobject]@{state=[int]$t.State; instances=[int]$t.GetInstances(0).Count; lastTaskResult=[long]$t.LastTaskResult; expectedNode=($a.Path -eq ${quote(plan.serviceOptions?.node ?? process.execPath)}); expectedArguments=($a.Arguments -eq ${quote(expectedArgs)})} | ConvertTo-Json -Compress`,
|
|
354
|
+
]);
|
|
355
|
+
const status = JSON.parse(output);
|
|
356
|
+
const record = { event: "windows-task-before-rollback" };
|
|
357
|
+
for (const key of ["state", "instances", "lastTaskResult"])
|
|
358
|
+
if (Number.isSafeInteger(status[key])) record[key] = status[key];
|
|
359
|
+
for (const key of ["expectedNode", "expectedArguments"])
|
|
360
|
+
if (typeof status[key] === "boolean") record[key] = status[key];
|
|
361
|
+
appendFileSync(logPath, `${JSON.stringify(record)}\n`, { mode: 0o600 });
|
|
362
|
+
} catch {
|
|
363
|
+
try {
|
|
364
|
+
appendFileSync(logPath, '{"event":"windows-task-before-rollback","available":false}\n', { mode: 0o600 });
|
|
365
|
+
} catch {}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
function retainWorkingReleases(plan, candidate, previousFile) {
|
|
369
|
+
const releases = join(plan.root, "releases");
|
|
370
|
+
if (resolve(dirname(candidate.root)) !== resolve(releases)) return;
|
|
371
|
+
const activePath = join(plan.root, "active-release.json");
|
|
372
|
+
let previous;
|
|
373
|
+
try {
|
|
374
|
+
previous = JSON.parse(readFileSync(activePath, "utf8")).current;
|
|
375
|
+
} catch {}
|
|
376
|
+
const previousText = previousFile.toString(process.platform === "win32" ? "utf16le" : "utf8");
|
|
377
|
+
const knownPrevious =
|
|
378
|
+
typeof previous === "string" && resolve(dirname(previous)) === resolve(releases) && previousText.includes(previous);
|
|
379
|
+
writeUpgradeJob(activePath, { current: candidate.root, ...(knownPrevious ? { previous } : {}) });
|
|
380
|
+
if (!knownPrevious) return;
|
|
381
|
+
for (const entry of readdirSync(releases, { withFileTypes: true })) {
|
|
382
|
+
if (!entry.isDirectory() || !/^[a-f0-9-]{36}$/.test(entry.name)) continue;
|
|
383
|
+
const path = join(releases, entry.name);
|
|
384
|
+
if (path !== candidate.root && path !== previous) rmSync(path, { recursive: true, force: true });
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
export async function runUpgradeJob(
|
|
388
|
+
path,
|
|
389
|
+
{
|
|
390
|
+
plan,
|
|
391
|
+
install = installRelease,
|
|
392
|
+
run = runManager,
|
|
393
|
+
probe = probeHub,
|
|
394
|
+
wait = waitForRelease,
|
|
395
|
+
portQuery = queryWindowsHubTcp,
|
|
396
|
+
now = () => performance.now(),
|
|
397
|
+
sleep = delay,
|
|
398
|
+
signal,
|
|
399
|
+
source = process.env.PI_DEVICE_HUB_UPDATE_SOURCE,
|
|
400
|
+
log = console.log,
|
|
401
|
+
} = {},
|
|
402
|
+
) {
|
|
403
|
+
let job = readUpgradeJob(path);
|
|
404
|
+
if (!job || job.state !== "queued") throw new Error("Hub upgrade job is not queued");
|
|
405
|
+
plan ??= planForJob(job);
|
|
406
|
+
const update = (patch) => {
|
|
407
|
+
const current = readUpgradeJob(path);
|
|
408
|
+
if (current?.id !== job.id) throw new Error("Hub upgrade job was replaced");
|
|
409
|
+
job = { ...job, ...patch, updatedAt: Date.now() };
|
|
410
|
+
writeUpgradeJob(path, job);
|
|
411
|
+
};
|
|
412
|
+
let releaseLock;
|
|
413
|
+
let previousFile;
|
|
414
|
+
let changed = false;
|
|
415
|
+
let candidate;
|
|
416
|
+
const logPath = join(dirname(path), "hub-upgrade.log");
|
|
417
|
+
const restart = async (settings, signal) => {
|
|
418
|
+
for (const args of plan.commands.update) {
|
|
419
|
+
await run(plan.manager, args);
|
|
420
|
+
if (plan.manager === "schtasks.exe" && args[0] === "/End")
|
|
421
|
+
await waitForWindowsHubPort(settings, {
|
|
422
|
+
query: portQuery,
|
|
423
|
+
now,
|
|
424
|
+
sleep,
|
|
425
|
+
signal,
|
|
426
|
+
onState: (rows) =>
|
|
427
|
+
appendFileSync(
|
|
428
|
+
logPath,
|
|
429
|
+
`[tcp-handoff] ${new Date().toISOString()} port=${Number(settings.PI_DEVICE_HUB_PORT)} state/pid=${JSON.stringify(rows.slice(0, 32))}\n`,
|
|
430
|
+
),
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
try {
|
|
435
|
+
const settings = installedSettings(plan, { ...job, path });
|
|
436
|
+
releaseLock = acquireHubLock(plan.root);
|
|
437
|
+
update({ state: "running", phase: "installing" });
|
|
438
|
+
const before = await probe(settings);
|
|
439
|
+
if (!before || before.instanceId !== job.instanceId || (before.bootId ?? "legacy") !== job.fromBootId)
|
|
440
|
+
throw new Error("Hub ownership or process changed before upgrade");
|
|
441
|
+
previousFile = readFileSync(plan.file);
|
|
442
|
+
writeFileSync(join(plan.root, "service.previous"), previousFile, { mode: 0o600 });
|
|
443
|
+
writeFileSync(logPath, `Hub upgrade ${job.id}\n`, { mode: 0o600 });
|
|
444
|
+
candidate = await install(plan.root, { source: settings.PI_DEVICE_HUB_UPDATE_SOURCE ?? source, logPath });
|
|
445
|
+
if (plan.manager === "schtasks.exe") {
|
|
446
|
+
const rows = await portQuery(settings, { timeout: 10_000, signal });
|
|
447
|
+
appendFileSync(
|
|
448
|
+
logPath,
|
|
449
|
+
`[tcp-preflight] ${new Date().toISOString()} port=${Number(settings.PI_DEVICE_HUB_PORT)} state/pid=${JSON.stringify(rows.slice(0, 32))}\n`,
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
update({ phase: "restarting", targetVersion: candidate.version });
|
|
453
|
+
const next = hubServicePlan({ ...plan.serviceOptions, entry: candidate.entry });
|
|
454
|
+
const temp = `${plan.file}.${job.id}.tmp`;
|
|
455
|
+
writeFileSync(temp, process.platform === "win32" ? Buffer.from(`\uFEFF${next.content}`, "utf16le") : next.content, {
|
|
456
|
+
mode: 0o600,
|
|
457
|
+
});
|
|
458
|
+
renameSync(temp, plan.file);
|
|
459
|
+
changed = true;
|
|
460
|
+
await restart(settings, signal);
|
|
461
|
+
const health = await wait(settings, { version: candidate.version, fromBootId: job.fromBootId, probe });
|
|
462
|
+
try {
|
|
463
|
+
retainWorkingReleases(plan, candidate, previousFile);
|
|
464
|
+
} catch (error) {
|
|
465
|
+
log(`Hub release cleanup deferred: ${error.message}`);
|
|
466
|
+
}
|
|
467
|
+
update({ state: "succeeded", phase: "completed", version: health.version, bootId: health.bootId });
|
|
468
|
+
log(`Hub upgraded to ${health.version}`);
|
|
469
|
+
return job;
|
|
470
|
+
} catch (error) {
|
|
471
|
+
let reason = error instanceof Error ? error.message : String(error);
|
|
472
|
+
if (changed && previousFile) {
|
|
473
|
+
recordWindowsServiceFailure(plan, candidate, logPath, run);
|
|
474
|
+
try {
|
|
475
|
+
update({ phase: "rolling-back" });
|
|
476
|
+
const restore = `${plan.file}.${job.id}.rollback`;
|
|
477
|
+
writeFileSync(restore, previousFile, { mode: 0o600 });
|
|
478
|
+
renameSync(restore, plan.file);
|
|
479
|
+
const settings = installedSettings(plan, { ...job, path });
|
|
480
|
+
await restart(settings);
|
|
481
|
+
await wait(settings, {
|
|
482
|
+
version: job.fromVersion,
|
|
483
|
+
fromBootId: job.fromBootId,
|
|
484
|
+
legacy: job.fromVersion === "legacy",
|
|
485
|
+
probe,
|
|
486
|
+
});
|
|
487
|
+
reason += "; previous Hub service restored";
|
|
488
|
+
} catch (rollbackError) {
|
|
489
|
+
reason += `; rollback failed: ${rollbackError.message}. Inspect hub status --json and hub-upgrade.log`;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
update({ state: "failed", phase: "failed", error: reason.slice(0, 4096) });
|
|
493
|
+
throw new Error(job.error);
|
|
494
|
+
} finally {
|
|
495
|
+
releaseLock?.();
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
export async function updateInstalledHub({ plan = hubServicePlan(), log = console.log, ...options } = {}) {
|
|
499
|
+
const settings = installedSettings(plan);
|
|
500
|
+
const lockRoot = join(settings.PI_DEVICE_HUB_DATA_DIR, "hub-upgrade-submission");
|
|
501
|
+
mkdirSync(lockRoot, { recursive: true, mode: 0o700 });
|
|
502
|
+
const releaseSubmission = acquireHubLock(lockRoot);
|
|
503
|
+
try {
|
|
504
|
+
const health = await (options.probe ?? probeHub)(settings);
|
|
505
|
+
if (!health || health.instanceId !== settings.PI_DEVICE_HUB_INSTANCE_ID)
|
|
506
|
+
throw new Error("A running Hub owned by the installed service is required before updating");
|
|
507
|
+
const path = jobPathFor(settings.PI_DEVICE_HUB_DATA_DIR);
|
|
508
|
+
const current = readUpgradeJob(path);
|
|
509
|
+
if (current && ["queued", "running"].includes(current.state) && Date.now() - current.createdAt < UPGRADE_TIMEOUT_MS)
|
|
510
|
+
throw new Error("Hub upgrade is already in progress");
|
|
511
|
+
const now = Date.now();
|
|
512
|
+
writeUpgradeJob(path, {
|
|
513
|
+
schemaVersion: 1,
|
|
514
|
+
id: randomUUID(),
|
|
515
|
+
state: "queued",
|
|
516
|
+
phase: "queued",
|
|
517
|
+
createdAt: now,
|
|
518
|
+
updatedAt: now,
|
|
519
|
+
instanceId: health.instanceId,
|
|
520
|
+
fromVersion: health.version ?? "legacy",
|
|
521
|
+
fromBootId: health.bootId ?? "legacy",
|
|
522
|
+
requestedBy: "local-cli",
|
|
523
|
+
serviceConfigPath: resolve(plan.config),
|
|
524
|
+
...(settings.PI_DEVICE_HUB_SERVICE_NAME ? { serviceName: settings.PI_DEVICE_HUB_SERVICE_NAME } : {}),
|
|
525
|
+
});
|
|
526
|
+
return await runUpgradeJob(path, { ...options, plan, log });
|
|
527
|
+
} finally {
|
|
528
|
+
releaseSubmission();
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export async function cleanupUpgradeWorker(path, { platform = process.platform, run = execute, ...options } = {}) {
|
|
533
|
+
const job = readUpgradeJob(path);
|
|
534
|
+
if (!job) return;
|
|
535
|
+
if (platform === "darwin") {
|
|
536
|
+
const launch = independentWorkerPlan(path, { ...options, platform, id: job.id });
|
|
537
|
+
rmSync(launch.definition.path, { force: true });
|
|
538
|
+
await run(launch.file, ["bootout", launch.target], { timeout: 10_000 });
|
|
539
|
+
} else if (platform === "win32") {
|
|
540
|
+
await run("schtasks.exe", ["/Delete", "/TN", `pi-device-hub-update-${job.id}`, "/F"], { timeout: 10_000 });
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
if (process.argv[1] && resolve(process.argv[1]) === SELF) {
|
|
545
|
+
const [mode, path, ...extra] = process.argv.slice(2);
|
|
546
|
+
try {
|
|
547
|
+
if (!["--launch", "--run"].includes(mode) || !path || extra.length)
|
|
548
|
+
throw new Error("Invalid Hub upgrade worker arguments");
|
|
549
|
+
if (mode === "--launch") await launchUpgradeJob(resolve(path));
|
|
550
|
+
else await runUpgradeJob(resolve(path));
|
|
551
|
+
} catch (error) {
|
|
552
|
+
console.error(`[hub-upgrade] ${error.message}`);
|
|
553
|
+
process.exitCode = 1;
|
|
554
|
+
} finally {
|
|
555
|
+
if (mode === "--run") {
|
|
556
|
+
try {
|
|
557
|
+
await cleanupUpgradeWorker(path);
|
|
558
|
+
} catch {}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|