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/device-hub-cli.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/** Standalone Hub lifecycle. Only Node built-ins; never imports the main CLI or agent SDK. */
|
|
2
1
|
import { spawnSync } from "node:child_process";
|
|
3
2
|
import { randomUUID } from "node:crypto";
|
|
4
3
|
import { createServer } from "node:net";
|
|
5
4
|
import { request } from "node:http";
|
|
6
5
|
import {
|
|
7
6
|
mkdirSync,
|
|
7
|
+
appendFileSync,
|
|
8
8
|
readFileSync,
|
|
9
9
|
writeFileSync,
|
|
10
10
|
renameSync,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
} from "node:fs";
|
|
16
16
|
import { homedir, hostname } from "node:os";
|
|
17
17
|
import { setTimeout as delay, setImmediate as yieldImmediate } from "node:timers/promises";
|
|
18
|
-
import { join, resolve } from "node:path";
|
|
18
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
19
19
|
import { fileURLToPath } from "node:url";
|
|
20
20
|
|
|
21
21
|
export const HUB_HELP = `Usage: pi-web-ui hub [install|start|stop|restart|status|uninstall|update] [options]
|
|
@@ -23,7 +23,8 @@ Without a command, run in the foreground (Ctrl+C to stop).
|
|
|
23
23
|
Options: --host HOST --port PORT --public-url URL --data-dir PATH
|
|
24
24
|
--allow-registration[=true|false] --help
|
|
25
25
|
install saves configuration, enables login autostart and starts the Hub.
|
|
26
|
-
update
|
|
26
|
+
update installs the latest Hub package in a managed release directory, restarts and verifies it.
|
|
27
|
+
If the new release cannot start, the previous service definition is restored.
|
|
27
28
|
Other lifecycle commands use the saved configuration; status accepts --json.
|
|
28
29
|
Close registration after the first account: hub restart --allow-registration=false
|
|
29
30
|
Only that saved setting changes; all other settings are retained.
|
|
@@ -32,11 +33,10 @@ Service: systemd --user (Linux), launchd user agent (macOS), logon scheduled tas
|
|
|
32
33
|
Linux boot without login requires an administrator to enable linger for your user.
|
|
33
34
|
uninstall stops and removes the service; Hub account/device data is retained.`;
|
|
34
35
|
const ENTRY = fileURLToPath(new URL("./pi-device-hub.mjs", import.meta.url));
|
|
35
|
-
const LABEL = "com.xingshuyin.pi-device-hub";
|
|
36
36
|
const TASK = "pi-device-hub";
|
|
37
37
|
const UNIT = "pi-device-hub.service";
|
|
38
38
|
const flags = { "--host": "HOST", "--port": "PORT", "--public-url": "PUBLIC_URL", "--data-dir": "DATA_DIR" };
|
|
39
|
-
const optionalEnv = ["DEVICE_DOMAIN", "PATH_ACCESS", "PORTAL_PORTS"];
|
|
39
|
+
const optionalEnv = ["DEVICE_DOMAIN", "PATH_ACCESS", "PORTAL_PORTS", "UPDATE_SOURCE", "SERVICE_NAME"];
|
|
40
40
|
|
|
41
41
|
export function parseHubArgs(argv, env = process.env) {
|
|
42
42
|
const args = [...argv];
|
|
@@ -71,7 +71,6 @@ export function parseHubArgs(argv, env = process.env) {
|
|
|
71
71
|
settings.PI_DEVICE_HUB_HOST ??= "127.0.0.1";
|
|
72
72
|
settings.PI_DEVICE_HUB_PORT ??= "8790";
|
|
73
73
|
settings.PI_DEVICE_HUB_DATA_DIR = resolve(settings.PI_DEVICE_HUB_DATA_DIR ?? join(homedir(), ".pi-device-hub"));
|
|
74
|
-
// Installing must not inherit an accidentally enabled registration environment variable.
|
|
75
74
|
settings.PI_DEVICE_HUB_ALLOW_REGISTRATION =
|
|
76
75
|
values.ALLOW_REGISTRATION ?? (command === "foreground" && env.PI_DEVICE_HUB_ALLOW_REGISTRATION === "1" ? "1" : "0");
|
|
77
76
|
validateSettings(settings);
|
|
@@ -97,7 +96,6 @@ function validateSettings(settings) {
|
|
|
97
96
|
|
|
98
97
|
const xml = (s) =>
|
|
99
98
|
String(s).replace(/[<>&"']/g, (c) => ({ "<": "<", ">": ">", "&": "&", '"': """, "'": "'" })[c]);
|
|
100
|
-
// CommandLineToArgvW quoting, not shell quoting. Every argument is passed directly to node.exe.
|
|
101
99
|
export const windowsArg = (s) =>
|
|
102
100
|
`"${String(s)
|
|
103
101
|
.replace(/(\\*)"/g, '$1$1\\"')
|
|
@@ -118,16 +116,26 @@ export function hubServicePlan({
|
|
|
118
116
|
uid = process.getuid?.(),
|
|
119
117
|
user = env.USERNAME,
|
|
120
118
|
} = {}) {
|
|
119
|
+
const serviceName = env.PI_DEVICE_HUB_SERVICE_NAME || "pi-device-hub";
|
|
120
|
+
if (!/^pi-device-hub(?:-[a-z0-9-]{1,48})?$/.test(serviceName)) throw new Error("Invalid Hub service name");
|
|
121
|
+
const taskName = serviceName;
|
|
122
|
+
const unitName = `${serviceName}.service`;
|
|
123
|
+
const labelName = `com.xingshuyin.${serviceName}`;
|
|
121
124
|
const root =
|
|
122
125
|
platform === "win32"
|
|
123
|
-
? join(env.APPDATA || join(home, "AppData", "Roaming"),
|
|
124
|
-
: join(home, ".config",
|
|
126
|
+
? join(env.APPDATA || join(home, "AppData", "Roaming"), `${serviceName}-cli`)
|
|
127
|
+
: join(home, ".config", `${serviceName}-cli`);
|
|
125
128
|
const config = join(root, "service.json");
|
|
126
129
|
const args = [entry, "--service-config", config];
|
|
130
|
+
const serviceOptions = { platform, home, env, node, uid, user };
|
|
131
|
+
const UNIT = unitName,
|
|
132
|
+
TASK = taskName,
|
|
133
|
+
LABEL = labelName;
|
|
127
134
|
if (platform === "linux")
|
|
128
135
|
return {
|
|
129
136
|
root,
|
|
130
137
|
config,
|
|
138
|
+
serviceOptions,
|
|
131
139
|
file: join(home, ".config", "systemd", "user", UNIT),
|
|
132
140
|
content: `[Unit]\nDescription=pi device Hub\nAfter=network.target\n\n[Service]\nExecStart=${[node, ...args].map(systemdArg).join(" ")}\nRestart=on-failure\nRestartSec=5\n\n[Install]\nWantedBy=default.target\n`,
|
|
133
141
|
manager: "systemctl",
|
|
@@ -154,6 +162,7 @@ export function hubServicePlan({
|
|
|
154
162
|
root,
|
|
155
163
|
config,
|
|
156
164
|
file,
|
|
165
|
+
serviceOptions,
|
|
157
166
|
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>${LABEL}</string><key>ProgramArguments</key><array>${[node, ...args].map((s) => `<string>${xml(s)}</string>`).join("")}</array><key>RunAtLoad</key><true/><key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict><key>StandardOutPath</key><string>${xml(join(root, "stdout.log"))}</string><key>StandardErrorPath</key><string>${xml(join(root, "stderr.log"))}</string></dict></plist>\n`,
|
|
158
167
|
manager: "launchctl",
|
|
159
168
|
commands: {
|
|
@@ -179,6 +188,7 @@ export function hubServicePlan({
|
|
|
179
188
|
return {
|
|
180
189
|
root,
|
|
181
190
|
config,
|
|
191
|
+
serviceOptions,
|
|
182
192
|
file: join(root, "task.xml"),
|
|
183
193
|
content: `<?xml version="1.0" encoding="UTF-16"?>\n<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"><Triggers><LogonTrigger><Enabled>true</Enabled><UserId>${xml(identity)}</UserId></LogonTrigger></Triggers><Principals><Principal id="Author"><UserId>${xml(identity)}</UserId><LogonType>InteractiveToken</LogonType><RunLevel>LeastPrivilege</RunLevel></Principal></Principals><Settings><MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy><DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries><StopIfGoingOnBatteries>false</StopIfGoingOnBatteries><ExecutionTimeLimit>PT0S</ExecutionTimeLimit><RestartOnFailure><Interval>PT1M</Interval><Count>3</Count></RestartOnFailure></Settings><Actions Context="Author"><Exec><Command>${xml(node)}</Command><Arguments>${xml(args.map(windowsArg).join(" "))}</Arguments></Exec></Actions></Task>`,
|
|
184
194
|
manager: "schtasks.exe",
|
|
@@ -209,8 +219,6 @@ export function hubServicePlan({
|
|
|
209
219
|
throw new Error(`Unsupported Hub service platform: ${platform}`);
|
|
210
220
|
}
|
|
211
221
|
|
|
212
|
-
// One budget per composite native phase, rather than a fresh timeout per subprocess.
|
|
213
|
-
// SIGKILL prevents a timed-out native command from extending the runner's 45s grace.
|
|
214
222
|
function nativePhase(inspect, now) {
|
|
215
223
|
const deadline = now() + 30000;
|
|
216
224
|
return (file, args) => {
|
|
@@ -231,15 +239,16 @@ export function assertServiceAbsent(plan, inspect = spawnSync, now = () => perfo
|
|
|
231
239
|
const result = native(
|
|
232
240
|
plan.manager,
|
|
233
241
|
plan.manager === "systemctl"
|
|
234
|
-
? ["--user", "show", UNIT, "--property=LoadState", "--value"]
|
|
242
|
+
? ["--user", "show", plan.commands.status?.[0]?.[2] ?? UNIT, "--property=LoadState", "--value"]
|
|
235
243
|
: plan.commands.status[0],
|
|
236
244
|
);
|
|
237
245
|
if (result.error) throw result.error;
|
|
238
246
|
if (plan.manager === "systemctl" && result.status === 0 && result.stdout.trim() === "not-found") return;
|
|
239
247
|
if (plan.manager === "launchctl" && result.status !== 0 && /Could not find service/i.test(result.stderr)) return;
|
|
240
248
|
if (plan.manager === "schtasks.exe") {
|
|
241
|
-
|
|
242
|
-
const
|
|
249
|
+
const statusArgs = plan.commands.status?.[0];
|
|
250
|
+
const taskName = (statusArgs ? statusArgs[statusArgs.indexOf("/TN") + 1] : TASK).replace(/'/g, "''");
|
|
251
|
+
const script = `$s=New-Object -ComObject Schedule.Service; $s.Connect(); try { $null=$s.GetFolder('\\').GetTask('${taskName}'); exit 0 } catch { if ($_.Exception.HResult -eq -2147024894) { exit 3 }; exit 4 }`;
|
|
243
252
|
const check = native("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", script]);
|
|
244
253
|
if (!check.error && check.status === 3) return;
|
|
245
254
|
}
|
|
@@ -294,6 +303,21 @@ export function probeHub(settings, signal) {
|
|
|
294
303
|
});
|
|
295
304
|
},
|
|
296
305
|
);
|
|
306
|
+
req.on("socket", (socket) => {
|
|
307
|
+
const rejectSelfConnection = () => {
|
|
308
|
+
// A client ephemeral port can equal the stopped Hub's port (TCP self-connect).
|
|
309
|
+
if (
|
|
310
|
+
socket.localPort &&
|
|
311
|
+
socket.localPort === socket.remotePort &&
|
|
312
|
+
socket.localAddress === socket.remoteAddress
|
|
313
|
+
) {
|
|
314
|
+
socket.once("close", () => done(null));
|
|
315
|
+
socket.resetAndDestroy();
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
if (socket.connecting) socket.once("connect", rejectSelfConnection);
|
|
319
|
+
else rejectSelfConnection();
|
|
320
|
+
});
|
|
297
321
|
req.on("timeout", () => req.destroy());
|
|
298
322
|
req.on("error", () => done(null));
|
|
299
323
|
req.end();
|
|
@@ -319,10 +343,16 @@ async function waitForHub(settings, signal) {
|
|
|
319
343
|
throw new Error("Hub did not become healthy within 15 seconds; service configuration retained for diagnosis");
|
|
320
344
|
}
|
|
321
345
|
|
|
322
|
-
export function runManager(
|
|
346
|
+
export function runManager(
|
|
347
|
+
file,
|
|
348
|
+
args,
|
|
349
|
+
inspect = spawnSync,
|
|
350
|
+
now = () => performance.now(),
|
|
351
|
+
pause = () => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 50),
|
|
352
|
+
) {
|
|
323
353
|
const native = nativePhase(inspect, now);
|
|
324
354
|
if (file === "launchctl" && ["bootout", "bootstrap"].includes(args[0])) {
|
|
325
|
-
const target = args[0] === "bootout" ? args[1] : `${args[1]}/${
|
|
355
|
+
const target = args[0] === "bootout" ? args[1] : `${args[1]}/${basename(args[2], ".plist")}`;
|
|
326
356
|
const state = native(file, ["print", target]);
|
|
327
357
|
if (state.error) throw state.error;
|
|
328
358
|
if (state.status === 0 && args[0] === "bootstrap") return "Hub is already loaded";
|
|
@@ -332,14 +362,15 @@ export function runManager(file, args, inspect = spawnSync, now = () => performa
|
|
|
332
362
|
if (args[0] === "bootout") return "Hub is already stopped";
|
|
333
363
|
}
|
|
334
364
|
}
|
|
335
|
-
// Ending an already stopped task is successful; scheduler errors still propagate.
|
|
336
365
|
if (file === "schtasks.exe" && args[0] === "/End") {
|
|
366
|
+
// Stop must also cancel queued instances; /Run with IgnoreNew can otherwise keep the old action.
|
|
367
|
+
const taskName = args[args.indexOf("/TN") + 1].replace(/'/g, "''");
|
|
337
368
|
file = "powershell.exe";
|
|
338
369
|
args = [
|
|
339
370
|
"-NoProfile",
|
|
340
371
|
"-NonInteractive",
|
|
341
372
|
"-Command",
|
|
342
|
-
`$ErrorActionPreference='Stop'; $s=New-Object -ComObject Schedule.Service; $s.Connect(); $
|
|
373
|
+
`$ErrorActionPreference='Stop'; $s=New-Object -ComObject Schedule.Service; $s.Connect(); $f=$s.GetFolder('\\'); $t=$f.GetTask('${taskName}'); if ($t.State -in @(2,4) -or $t.GetInstances(0).Count -gt 0) { $t.Stop(0) }; $clock=[Diagnostics.Stopwatch]::StartNew(); while ($true) { $t=$f.GetTask('${taskName}'); if ($t.State -in @(1,3) -and $t.GetInstances(0).Count -eq 0) { break }; if ($clock.ElapsedMilliseconds -ge 25000) { throw 'Hub scheduled task did not stop within 25s' }; Start-Sleep -Milliseconds 50 }`,
|
|
343
374
|
];
|
|
344
375
|
}
|
|
345
376
|
const result = native(file, args);
|
|
@@ -347,6 +378,17 @@ export function runManager(file, args, inspect = spawnSync, now = () => performa
|
|
|
347
378
|
throw new Error(
|
|
348
379
|
`${file} ${args.join(" ")}: ${result.error?.message || result.stderr || result.stdout || `exit ${result.status}`}`,
|
|
349
380
|
);
|
|
381
|
+
if (file === "launchctl" && args[0] === "bootout") {
|
|
382
|
+
while (true) {
|
|
383
|
+
const state = native(file, ["print", args[1]]);
|
|
384
|
+
if (state.error) throw state.error;
|
|
385
|
+
if (state.status !== 0) {
|
|
386
|
+
if (/Could not find service/i.test(state.stderr)) break;
|
|
387
|
+
throw new Error(state.stderr || "Could not confirm launchd job removal");
|
|
388
|
+
}
|
|
389
|
+
pause();
|
|
390
|
+
}
|
|
391
|
+
}
|
|
350
392
|
return result.stdout?.trim();
|
|
351
393
|
}
|
|
352
394
|
export function acquireHubLock(
|
|
@@ -384,7 +426,6 @@ export function acquireHubLock(
|
|
|
384
426
|
alive(previous.pid)
|
|
385
427
|
)
|
|
386
428
|
throw new Error(`Hub lifecycle operation is locked by PID ${previous.pid}: ${lock}`);
|
|
387
|
-
// Remove only the observed unique owner file. Competing recovery cannot delete a new owner's file.
|
|
388
429
|
unlinkSync(previousPath);
|
|
389
430
|
rmdirSync(lock);
|
|
390
431
|
mkdirSync(lock);
|
|
@@ -405,14 +446,11 @@ export function acquireHubLock(
|
|
|
405
446
|
};
|
|
406
447
|
}
|
|
407
448
|
|
|
408
|
-
/** Cancel orchestration without killing a native service manager or the installed service. */
|
|
409
449
|
export async function runHubCliEntry(argv = process.argv.slice(2), options = {}) {
|
|
410
450
|
if (!["install", "start", "stop", "restart", "status", "uninstall"].includes(argv[0]))
|
|
411
451
|
return runHubCli(argv, options);
|
|
412
452
|
const controller = new AbortController();
|
|
413
453
|
const abort = () => controller.abort(new Error("Hub CLI cancelled; installed configuration is retained"));
|
|
414
|
-
// The runner uses IPC on Windows, where kill(SIGTERM) terminates the process immediately.
|
|
415
|
-
// A queued message is handled after spawnSync returns and the orchestration yields.
|
|
416
454
|
const onMessage = (message) => {
|
|
417
455
|
if (message && typeof message === "object" && !Array.isArray(message) && message.type === "cancel-hub-operation")
|
|
418
456
|
abort();
|
|
@@ -448,22 +486,95 @@ export async function runHubCli(
|
|
|
448
486
|
inspect = spawnSync,
|
|
449
487
|
log = console.log,
|
|
450
488
|
foreground = runForeground,
|
|
489
|
+
upgrade,
|
|
451
490
|
signal,
|
|
452
491
|
} = {},
|
|
453
492
|
) {
|
|
454
493
|
signal?.throwIfAborted();
|
|
455
|
-
// Internal service entry uses an explicit saved environment, never ambient Hub overrides.
|
|
456
494
|
if (argv[0] === "--service-config") {
|
|
457
495
|
if (argv.length !== 2) throw new Error("Invalid service configuration arguments");
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
496
|
+
let hubPort;
|
|
497
|
+
const record = (event, error) => {
|
|
498
|
+
try {
|
|
499
|
+
const at = new Date().toISOString();
|
|
500
|
+
let tcp;
|
|
501
|
+
if (
|
|
502
|
+
process.platform === "win32" &&
|
|
503
|
+
error?.code === "EADDRINUSE" &&
|
|
504
|
+
Number.isInteger(error.port) &&
|
|
505
|
+
error.port >= 1 &&
|
|
506
|
+
error.port <= 65535
|
|
507
|
+
) {
|
|
508
|
+
try {
|
|
509
|
+
const result = inspect(
|
|
510
|
+
"powershell.exe",
|
|
511
|
+
[
|
|
512
|
+
"-NoProfile",
|
|
513
|
+
"-NonInteractive",
|
|
514
|
+
"-Command",
|
|
515
|
+
`$ErrorActionPreference='Stop'; $rows=@(Get-NetTCPConnection -LocalPort ${error.port} -ErrorAction SilentlyContinue | Select-Object -First 32 | ForEach-Object { [pscustomobject]@{state=[int]$_.State;pid=[int]$_.OwningProcess} }); ConvertTo-Json -InputObject $rows -Compress`,
|
|
516
|
+
],
|
|
517
|
+
{ encoding: "utf8", windowsHide: true, timeout: 5000, maxBuffer: 8192 },
|
|
518
|
+
);
|
|
519
|
+
if (result.status === 0) {
|
|
520
|
+
const rows = JSON.parse(result.stdout);
|
|
521
|
+
if (Array.isArray(rows))
|
|
522
|
+
tcp = rows
|
|
523
|
+
.slice(0, 32)
|
|
524
|
+
.filter(
|
|
525
|
+
(row) =>
|
|
526
|
+
Number.isInteger(row?.state) &&
|
|
527
|
+
row.state >= 1 &&
|
|
528
|
+
row.state <= 12 &&
|
|
529
|
+
Number.isSafeInteger(row?.pid) &&
|
|
530
|
+
row.pid >= 0,
|
|
531
|
+
)
|
|
532
|
+
.map(({ state, pid }) => ({ state, pid }));
|
|
533
|
+
}
|
|
534
|
+
} catch {}
|
|
535
|
+
}
|
|
536
|
+
appendFileSync(
|
|
537
|
+
join(dirname(resolve(argv[1])), "service-runtime.log"),
|
|
538
|
+
`${JSON.stringify({
|
|
539
|
+
at,
|
|
540
|
+
event,
|
|
541
|
+
pid: process.pid,
|
|
542
|
+
version: JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version,
|
|
543
|
+
...(error ? { code: /^[A-Z][A-Z0-9_]{0,63}$/.test(error.code) ? error.code : "STARTUP_FAILED" } : {}),
|
|
544
|
+
...(Number.isInteger(error?.port) && error.port >= 1 && error.port <= 65535 ? { port: error.port } : {}),
|
|
545
|
+
...(hubPort ? { hubPort } : {}),
|
|
546
|
+
...(typeof error?.syscall === "string" && /^[a-z_]{1,32}$/.test(error.syscall)
|
|
547
|
+
? { syscall: error.syscall }
|
|
548
|
+
: {}),
|
|
549
|
+
...(["127.0.0.1", "::1", "0.0.0.0", "::"].includes(error?.address) ? { address: error.address } : {}),
|
|
550
|
+
...(tcp ? { tcp } : {}),
|
|
551
|
+
})}\n`,
|
|
552
|
+
{ mode: 0o600 },
|
|
553
|
+
);
|
|
554
|
+
} catch {}
|
|
555
|
+
};
|
|
556
|
+
record("starting");
|
|
557
|
+
try {
|
|
558
|
+
const settings = JSON.parse(readFileSync(argv[1], "utf8"));
|
|
559
|
+
validateSettings(settings);
|
|
560
|
+
hubPort = Number(settings.PI_DEVICE_HUB_PORT);
|
|
561
|
+
const hub = await foreground({ ...settings, PI_DEVICE_HUB_SERVICE_CONFIG: resolve(argv[1]) });
|
|
562
|
+
record("ready");
|
|
563
|
+
return hub;
|
|
564
|
+
} catch (error) {
|
|
565
|
+
record("failed", error);
|
|
566
|
+
throw error;
|
|
567
|
+
}
|
|
461
568
|
}
|
|
462
569
|
const parsed = parseHubArgs(argv, env);
|
|
463
570
|
if (parsed.help) return log(HUB_HELP);
|
|
464
571
|
if (parsed.command === "foreground") return foreground(parsed.settings);
|
|
465
572
|
const plan = suppliedPlan ?? hubServicePlan({ env });
|
|
466
573
|
const command = parsed.command;
|
|
574
|
+
if (command === "update") {
|
|
575
|
+
const performUpgrade = upgrade ?? (await import("./hub-upgrade.mjs")).updateInstalledHub;
|
|
576
|
+
return performUpgrade({ plan, env, log, signal });
|
|
577
|
+
}
|
|
467
578
|
if (command === "status") {
|
|
468
579
|
const installed = existsSync(plan.config);
|
|
469
580
|
const settings = installed ? JSON.parse(readFileSync(plan.config, "utf8")) : undefined;
|
|
@@ -499,7 +610,6 @@ export async function runHubCli(
|
|
|
499
610
|
throw new Error(
|
|
500
611
|
`Hub service configuration already exists at ${plan.config}. Inspect with 'hub status --json'; recover with 'hub start' or 'hub restart'. To replace configuration, 'hub uninstall' first (data retained).`,
|
|
501
612
|
);
|
|
502
|
-
// A failed query is not proof of absence unless the native manager says so.
|
|
503
613
|
assertServiceAbsent(plan, inspect);
|
|
504
614
|
await yieldForCancellation(signal);
|
|
505
615
|
await assertPortAvailable(parsed.settings);
|
|
@@ -513,15 +623,6 @@ export async function runHubCli(
|
|
|
513
623
|
);
|
|
514
624
|
} else if (!existsSync(plan.config))
|
|
515
625
|
throw new Error("Hub service is not installed. Run pi-web-ui hub install first.");
|
|
516
|
-
if (command === "update") {
|
|
517
|
-
const settings = JSON.parse(readFileSync(plan.config, "utf8"));
|
|
518
|
-
validateSettings(settings);
|
|
519
|
-
mkdirSync(resolve(plan.file, ".."), { recursive: true });
|
|
520
|
-
atomicWrite(
|
|
521
|
-
plan.file,
|
|
522
|
-
process.platform === "win32" ? Buffer.from(`\uFEFF${plan.content}`, "utf16le") : plan.content,
|
|
523
|
-
);
|
|
524
|
-
}
|
|
525
626
|
signal?.throwIfAborted();
|
|
526
627
|
if (parsed.registration !== undefined) {
|
|
527
628
|
const settings = JSON.parse(readFileSync(plan.config, "utf8"));
|
|
@@ -534,17 +635,12 @@ export async function runHubCli(
|
|
|
534
635
|
try {
|
|
535
636
|
assertServiceAbsent(plan, inspect);
|
|
536
637
|
serviceMissing = true;
|
|
537
|
-
} catch {
|
|
538
|
-
/* Native commands must still report failures for an existing or inaccessible service. */
|
|
539
|
-
}
|
|
638
|
+
} catch {}
|
|
540
639
|
}
|
|
541
|
-
// Absence checks are native phases too: drain pending IPC before another phase.
|
|
542
640
|
await yieldForCancellation(signal);
|
|
543
641
|
for (const args of serviceMissing ? [] : plan.commands[command]) {
|
|
544
642
|
signal?.throwIfAborted();
|
|
545
643
|
const output = run(plan.manager, args);
|
|
546
|
-
// Timer callbacks can precede IPC polling. Cross a full poll/check cycle before
|
|
547
|
-
// starting another native command, including when entered outside an I/O callback.
|
|
548
644
|
await yieldForCancellation(signal);
|
|
549
645
|
signal?.throwIfAborted();
|
|
550
646
|
if (output) log(output);
|
|
@@ -570,13 +666,21 @@ export async function runHubCli(
|
|
|
570
666
|
|
|
571
667
|
async function runForeground(settings) {
|
|
572
668
|
const { startDeviceHub } = await import("../dist/server/device-center/main.js");
|
|
573
|
-
const
|
|
669
|
+
const bootId = randomUUID();
|
|
670
|
+
const version = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
671
|
+
const hub = await startDeviceHub({
|
|
672
|
+
...settings,
|
|
673
|
+
PI_DEVICE_HUB_BOOT_ID: bootId,
|
|
674
|
+
PI_DEVICE_HUB_PACKAGE_ROOT: fileURLToPath(new URL("../", import.meta.url)),
|
|
675
|
+
});
|
|
574
676
|
hub.app.get("/health", (_req, res) => {
|
|
575
677
|
res.setHeader("Cache-Control", "no-store");
|
|
576
678
|
res.json({
|
|
577
679
|
schemaVersion: 1,
|
|
578
680
|
service: "pi-device-hub",
|
|
579
681
|
status: "ok",
|
|
682
|
+
version,
|
|
683
|
+
bootId,
|
|
580
684
|
instanceId: settings.PI_DEVICE_HUB_INSTANCE_ID ?? null,
|
|
581
685
|
publicUrl: settings.PI_DEVICE_HUB_PUBLIC_URL,
|
|
582
686
|
port: Number(settings.PI_DEVICE_HUB_PORT),
|