@waq666/pneuma 0.0.0-stage → 0.7.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/LICENSE +21 -0
- package/README.md +144 -2
- package/bin/dsc.js +91 -0
- package/bin/headless.cjs +40 -0
- package/lib/adapter/core-runtime.d.ts +11 -0
- package/lib/adapter/core-runtime.js +259 -0
- package/lib/adapter/host.d.ts +18 -0
- package/lib/adapter/host.js +14 -0
- package/lib/adapter/runtime.d.ts +15 -0
- package/lib/adapter/runtime.js +290 -0
- package/lib/adapter/transcript.d.ts +184 -0
- package/lib/adapter/transcript.js +605 -0
- package/lib/app/AgentsOverlay.d.ts +18 -0
- package/lib/app/AgentsOverlay.js +63 -0
- package/lib/app/App.d.ts +13 -0
- package/lib/app/App.js +1498 -0
- package/lib/app/ApprovalCard.d.ts +12 -0
- package/lib/app/ApprovalCard.js +76 -0
- package/lib/app/AskCard.d.ts +20 -0
- package/lib/app/AskCard.js +45 -0
- package/lib/app/ChatView.d.ts +32 -0
- package/lib/app/ChatView.js +198 -0
- package/lib/app/Composer.d.ts +50 -0
- package/lib/app/Composer.js +282 -0
- package/lib/app/DiffBlock.d.ts +6 -0
- package/lib/app/DiffBlock.js +37 -0
- package/lib/app/MarkdownView.d.ts +6 -0
- package/lib/app/MarkdownView.js +99 -0
- package/lib/app/ModelPicker.d.ts +7 -0
- package/lib/app/ModelPicker.js +18 -0
- package/lib/app/PlanReviewCard.d.ts +13 -0
- package/lib/app/PlanReviewCard.js +54 -0
- package/lib/app/PresetPicker.d.ts +11 -0
- package/lib/app/PresetPicker.js +19 -0
- package/lib/app/PreviewOverlay.d.ts +14 -0
- package/lib/app/PreviewOverlay.js +22 -0
- package/lib/app/SessionPicker.d.ts +43 -0
- package/lib/app/SessionPicker.js +56 -0
- package/lib/app/SettingsOverlay.d.ts +32 -0
- package/lib/app/SettingsOverlay.js +157 -0
- package/lib/app/SkillsPicker.d.ts +7 -0
- package/lib/app/SkillsPicker.js +19 -0
- package/lib/app/StatusBar.d.ts +22 -0
- package/lib/app/StatusBar.js +272 -0
- package/lib/app/TaskStrips.d.ts +13 -0
- package/lib/app/TaskStrips.js +40 -0
- package/lib/app/ToolCard.d.ts +5 -0
- package/lib/app/ToolCard.js +40 -0
- package/lib/app/TranscriptOverlay.d.ts +12 -0
- package/lib/app/TranscriptOverlay.js +17 -0
- package/lib/app/Welcome.d.ts +6 -0
- package/lib/app/Welcome.js +66 -0
- package/lib/app/attach.d.ts +16 -0
- package/lib/app/attach.js +58 -0
- package/lib/app/click.d.ts +27 -0
- package/lib/app/click.js +89 -0
- package/lib/app/clipboard-image.d.ts +11 -0
- package/lib/app/clipboard-image.js +66 -0
- package/lib/app/cursor.d.ts +4 -0
- package/lib/app/cursor.js +24 -0
- package/lib/app/hello.d.ts +11 -0
- package/lib/app/hello.js +8 -0
- package/lib/app/history-store.d.ts +4 -0
- package/lib/app/history-store.js +41 -0
- package/lib/app/image-blocks.d.ts +12 -0
- package/lib/app/image-blocks.js +125 -0
- package/lib/app/markdown.d.ts +54 -0
- package/lib/app/markdown.js +189 -0
- package/lib/app/settings-model.d.ts +69 -0
- package/lib/app/settings-model.js +114 -0
- package/lib/app/theme.d.ts +166 -0
- package/lib/app/theme.js +141 -0
- package/lib/boot.d.ts +1 -0
- package/lib/boot.js +34 -0
- package/lib/commands.d.ts +49 -0
- package/lib/commands.js +115 -0
- package/lib/contract.d.ts +1973 -0
- package/lib/contract.js +36 -0
- package/lib/core/agent-roles.d.ts +52 -0
- package/lib/core/agent-roles.js +274 -0
- package/lib/core/approval-floor.d.ts +183 -0
- package/lib/core/approval-floor.js +679 -0
- package/lib/core/approval.d.ts +42 -0
- package/lib/core/approval.js +8 -0
- package/lib/core/audit.d.ts +61 -0
- package/lib/core/audit.js +59 -0
- package/lib/core/boot-notices.d.ts +6 -0
- package/lib/core/boot-notices.js +61 -0
- package/lib/core/cdp/actions.d.ts +182 -0
- package/lib/core/cdp/actions.js +649 -0
- package/lib/core/cdp/launch.d.ts +192 -0
- package/lib/core/cdp/launch.js +491 -0
- package/lib/core/cdp/snapshot.d.ts +139 -0
- package/lib/core/cdp/snapshot.js +316 -0
- package/lib/core/cdp/transport.d.ts +160 -0
- package/lib/core/cdp/transport.js +359 -0
- package/lib/core/command-policy.d.ts +108 -0
- package/lib/core/command-policy.js +580 -0
- package/lib/core/commands-completion.d.ts +78 -0
- package/lib/core/commands-completion.js +167 -0
- package/lib/core/compact-anchors.d.ts +76 -0
- package/lib/core/compact-anchors.js +284 -0
- package/lib/core/compact.d.ts +110 -0
- package/lib/core/compact.js +210 -0
- package/lib/core/config-store.d.ts +38 -0
- package/lib/core/config-store.js +307 -0
- package/lib/core/config.d.ts +36 -0
- package/lib/core/config.js +124 -0
- package/lib/core/connection-test.d.ts +60 -0
- package/lib/core/connection-test.js +84 -0
- package/lib/core/desktop-control.d.ts +298 -0
- package/lib/core/desktop-control.js +1311 -0
- package/lib/core/diff-text.d.ts +74 -0
- package/lib/core/diff-text.js +257 -0
- package/lib/core/dock-browser.d.ts +137 -0
- package/lib/core/dock-browser.js +146 -0
- package/lib/core/dock-ops.d.ts +59 -0
- package/lib/core/dock-ops.js +104 -0
- package/lib/core/dock-session.d.ts +39 -0
- package/lib/core/dock-session.js +28 -0
- package/lib/core/dsh-compat/hook.d.ts +18 -0
- package/lib/core/dsh-compat/hook.js +52 -0
- package/lib/core/dsh-compat/resolve-hook.d.ts +5 -0
- package/lib/core/dsh-compat/resolve-hook.js +59 -0
- package/lib/core/dsh-compat/tools-facade.d.ts +47 -0
- package/lib/core/dsh-compat/tools-facade.js +108 -0
- package/lib/core/err-text.d.ts +13 -0
- package/lib/core/err-text.js +15 -0
- package/lib/core/events.d.ts +149 -0
- package/lib/core/events.js +1 -0
- package/lib/core/git-exec.d.ts +23 -0
- package/lib/core/git-exec.js +72 -0
- package/lib/core/git-info.d.ts +47 -0
- package/lib/core/git-info.js +157 -0
- package/lib/core/goal.d.ts +89 -0
- package/lib/core/goal.js +189 -0
- package/lib/core/hooks.d.ts +272 -0
- package/lib/core/hooks.js +818 -0
- package/lib/core/host-browser-link.d.ts +59 -0
- package/lib/core/host-browser-link.js +9 -0
- package/lib/core/host-methods.d.ts +25 -0
- package/lib/core/host-methods.js +103 -0
- package/lib/core/image-diet.d.ts +77 -0
- package/lib/core/image-diet.js +127 -0
- package/lib/core/learnings/ledger.d.ts +73 -0
- package/lib/core/learnings/ledger.js +273 -0
- package/lib/core/learnings/skill-write.d.ts +250 -0
- package/lib/core/learnings/skill-write.js +854 -0
- package/lib/core/learnings/store.d.ts +102 -0
- package/lib/core/learnings/store.js +266 -0
- package/lib/core/lifecycle-hooks.d.ts +189 -0
- package/lib/core/lifecycle-hooks.js +576 -0
- package/lib/core/llm.d.ts +272 -0
- package/lib/core/llm.js +548 -0
- package/lib/core/lockfile.d.ts +17 -0
- package/lib/core/lockfile.js +110 -0
- package/lib/core/loop.d.ts +185 -0
- package/lib/core/loop.js +587 -0
- package/lib/core/lsp/client.d.ts +189 -0
- package/lib/core/lsp/client.js +690 -0
- package/lib/core/lsp/framing.d.ts +84 -0
- package/lib/core/lsp/framing.js +181 -0
- package/lib/core/lsp/line-shift.d.ts +28 -0
- package/lib/core/lsp/line-shift.js +127 -0
- package/lib/core/lsp/manager.d.ts +93 -0
- package/lib/core/lsp/manager.js +418 -0
- package/lib/core/lsp/normalize.d.ts +32 -0
- package/lib/core/lsp/normalize.js +139 -0
- package/lib/core/lsp/servers.d.ts +106 -0
- package/lib/core/lsp/servers.js +352 -0
- package/lib/core/lsp/uri.d.ts +76 -0
- package/lib/core/lsp/uri.js +179 -0
- package/lib/core/market.d.ts +51 -0
- package/lib/core/market.js +358 -0
- package/lib/core/mcp.d.ts +201 -0
- package/lib/core/mcp.js +836 -0
- package/lib/core/memory-eval.d.ts +158 -0
- package/lib/core/memory-eval.js +215 -0
- package/lib/core/memory.d.ts +266 -0
- package/lib/core/memory.js +703 -0
- package/lib/core/mention.d.ts +57 -0
- package/lib/core/mention.js +129 -0
- package/lib/core/microcompact.d.ts +48 -0
- package/lib/core/microcompact.js +79 -0
- package/lib/core/migrate.d.ts +56 -0
- package/lib/core/migrate.js +134 -0
- package/lib/core/model-caps.d.ts +83 -0
- package/lib/core/model-caps.js +150 -0
- package/lib/core/model-discovery.d.ts +19 -0
- package/lib/core/model-discovery.js +69 -0
- package/lib/core/modes.d.ts +72 -0
- package/lib/core/modes.js +152 -0
- package/lib/core/native-bridge.d.ts +135 -0
- package/lib/core/native-bridge.js +563 -0
- package/lib/core/path-policy.d.ts +32 -0
- package/lib/core/path-policy.js +248 -0
- package/lib/core/permission-presets.d.ts +67 -0
- package/lib/core/permission-presets.js +75 -0
- package/lib/core/plugin-loader.d.ts +36 -0
- package/lib/core/plugin-loader.js +294 -0
- package/lib/core/plugin-registry.d.ts +113 -0
- package/lib/core/plugin-registry.js +256 -0
- package/lib/core/prefs.d.ts +82 -0
- package/lib/core/prefs.js +372 -0
- package/lib/core/presets.d.ts +80 -0
- package/lib/core/presets.js +373 -0
- package/lib/core/pricing.d.ts +90 -0
- package/lib/core/pricing.js +126 -0
- package/lib/core/prompt.d.ts +92 -0
- package/lib/core/prompt.js +339 -0
- package/lib/core/ptc.d.ts +66 -0
- package/lib/core/ptc.js +70 -0
- package/lib/core/remote/frames.d.ts +91 -0
- package/lib/core/remote/frames.js +174 -0
- package/lib/core/remote/notify.d.ts +54 -0
- package/lib/core/remote/notify.js +77 -0
- package/lib/core/remote/owner.d.ts +32 -0
- package/lib/core/remote/owner.js +75 -0
- package/lib/core/remote/pairing.d.ts +104 -0
- package/lib/core/remote/pairing.js +261 -0
- package/lib/core/remote/push.d.ts +80 -0
- package/lib/core/remote/push.js +222 -0
- package/lib/core/remote/store.d.ts +18 -0
- package/lib/core/remote/store.js +59 -0
- package/lib/core/remote/tickets.d.ts +20 -0
- package/lib/core/remote/tickets.js +49 -0
- package/lib/core/remote/uploads.d.ts +63 -0
- package/lib/core/remote/uploads.js +161 -0
- package/lib/core/request-attribution.d.ts +26 -0
- package/lib/core/request-attribution.js +86 -0
- package/lib/core/request-invariant.d.ts +61 -0
- package/lib/core/request-invariant.js +199 -0
- package/lib/core/sandbox/backends.d.ts +64 -0
- package/lib/core/sandbox/backends.js +194 -0
- package/lib/core/sandbox/execpolicy.d.ts +93 -0
- package/lib/core/sandbox/execpolicy.js +452 -0
- package/lib/core/sandbox/net-proxy.d.ts +31 -0
- package/lib/core/sandbox/net-proxy.js +162 -0
- package/lib/core/sandbox/policy.d.ts +211 -0
- package/lib/core/sandbox/policy.js +559 -0
- package/lib/core/sandbox/win/abi.d.ts +161 -0
- package/lib/core/sandbox/win/abi.js +169 -0
- package/lib/core/sandbox/win/account.d.ts +71 -0
- package/lib/core/sandbox/win/account.js +206 -0
- package/lib/core/sandbox/win/acl.d.ts +54 -0
- package/lib/core/sandbox/win/acl.js +339 -0
- package/lib/core/sandbox/win/backend.d.ts +61 -0
- package/lib/core/sandbox/win/backend.js +249 -0
- package/lib/core/sandbox/win/doctor.d.ts +24 -0
- package/lib/core/sandbox/win/doctor.js +272 -0
- package/lib/core/sandbox/win/ffi.d.ts +107 -0
- package/lib/core/sandbox/win/ffi.js +166 -0
- package/lib/core/sandbox/win/net-abi.d.ts +154 -0
- package/lib/core/sandbox/win/net-abi.js +316 -0
- package/lib/core/sandbox/win/runner-entry.d.ts +35 -0
- package/lib/core/sandbox/win/runner-entry.js +391 -0
- package/lib/core/sandbox/win/setup.d.ts +60 -0
- package/lib/core/sandbox/win/setup.js +986 -0
- package/lib/core/sandbox/win/token.d.ts +35 -0
- package/lib/core/sandbox/win/token.js +238 -0
- package/lib/core/sandbox/win/wfp.d.ts +41 -0
- package/lib/core/sandbox/win/wfp.js +200 -0
- package/lib/core/sandbox/win/workspace-sid.d.ts +9 -0
- package/lib/core/sandbox/win/workspace-sid.js +45 -0
- package/lib/core/schedule/rule.d.ts +184 -0
- package/lib/core/schedule/rule.js +745 -0
- package/lib/core/schedule/runner.d.ts +185 -0
- package/lib/core/schedule/runner.js +678 -0
- package/lib/core/schedule/store.d.ts +182 -0
- package/lib/core/schedule/store.js +455 -0
- package/lib/core/secrets.d.ts +41 -0
- package/lib/core/secrets.js +150 -0
- package/lib/core/session-export.d.ts +18 -0
- package/lib/core/session-export.js +73 -0
- package/lib/core/session-index.d.ts +159 -0
- package/lib/core/session-index.js +683 -0
- package/lib/core/session-meta.d.ts +41 -0
- package/lib/core/session-meta.js +97 -0
- package/lib/core/session.d.ts +356 -0
- package/lib/core/session.js +998 -0
- package/lib/core/skills.d.ts +60 -0
- package/lib/core/skills.js +171 -0
- package/lib/core/spill.d.ts +159 -0
- package/lib/core/spill.js +329 -0
- package/lib/core/surface-registry.d.ts +45 -0
- package/lib/core/surface-registry.js +67 -0
- package/lib/core/team-board.d.ts +95 -0
- package/lib/core/team-board.js +316 -0
- package/lib/core/throughput.d.ts +46 -0
- package/lib/core/throughput.js +40 -0
- package/lib/core/todo-reminder.d.ts +44 -0
- package/lib/core/todo-reminder.js +55 -0
- package/lib/core/todo.d.ts +81 -0
- package/lib/core/todo.js +222 -0
- package/lib/core/token-estimate.d.ts +55 -0
- package/lib/core/token-estimate.js +82 -0
- package/lib/core/tool-guards.d.ts +103 -0
- package/lib/core/tool-guards.js +77 -0
- package/lib/core/tool-search.d.ts +152 -0
- package/lib/core/tool-search.js +311 -0
- package/lib/core/tools/bash.d.ts +281 -0
- package/lib/core/tools/bash.js +871 -0
- package/lib/core/tools/command-runner.d.ts +84 -0
- package/lib/core/tools/command-runner.js +68 -0
- package/lib/core/tools/fs-tools.d.ts +23 -0
- package/lib/core/tools/fs-tools.js +247 -0
- package/lib/core/tools/index.d.ts +8 -0
- package/lib/core/tools/index.js +4 -0
- package/lib/core/tools/sandbox-args.d.ts +51 -0
- package/lib/core/tools/sandbox-args.js +90 -0
- package/lib/core/tools/search-tools.d.ts +3 -0
- package/lib/core/tools/search-tools.js +153 -0
- package/lib/core/tools.d.ts +96 -0
- package/lib/core/tools.js +53 -0
- package/lib/core/ui-boot-source.d.ts +71 -0
- package/lib/core/ui-boot-source.js +121 -0
- package/lib/core/ui-bundles.d.ts +249 -0
- package/lib/core/ui-bundles.js +830 -0
- package/lib/core/ui-combo.d.ts +49 -0
- package/lib/core/ui-combo.js +55 -0
- package/lib/core/ui-events.d.ts +81 -0
- package/lib/core/ui-events.js +364 -0
- package/lib/core/ui-hmr.d.ts +36 -0
- package/lib/core/ui-hmr.js +128 -0
- package/lib/core/ui-methods.d.ts +69 -0
- package/lib/core/ui-methods.js +341 -0
- package/lib/core/ui-route.d.ts +69 -0
- package/lib/core/ui-route.js +122 -0
- package/lib/core/ui-server.d.ts +75 -0
- package/lib/core/ui-server.js +369 -0
- package/lib/core/ui-trust.d.ts +47 -0
- package/lib/core/ui-trust.js +164 -0
- package/lib/core/untrusted.d.ts +30 -0
- package/lib/core/untrusted.js +48 -0
- package/lib/core/update-check.d.ts +81 -0
- package/lib/core/update-check.js +177 -0
- package/lib/core/usage-log.d.ts +82 -0
- package/lib/core/usage-log.js +306 -0
- package/lib/core/version.d.ts +1 -0
- package/lib/core/version.js +37 -0
- package/lib/core/web-http.d.ts +57 -0
- package/lib/core/web-http.js +137 -0
- package/lib/core/web-static.d.ts +31 -0
- package/lib/core/web-static.js +75 -0
- package/lib/headless.d.ts +1 -0
- package/lib/headless.js +31 -0
- package/lib/host/kernel.d.ts +33 -0
- package/lib/host/kernel.js +451 -0
- package/lib/index.d.ts +41 -0
- package/lib/index.js +35 -0
- package/lib/plugins/agent.d.ts +2 -0
- package/lib/plugins/agent.js +274 -0
- package/lib/plugins/approval-floor.d.ts +2 -0
- package/lib/plugins/approval-floor.js +223 -0
- package/lib/plugins/approval.d.ts +16 -0
- package/lib/plugins/approval.js +674 -0
- package/lib/plugins/ask.d.ts +2 -0
- package/lib/plugins/ask.js +245 -0
- package/lib/plugins/browser.d.ts +68 -0
- package/lib/plugins/browser.js +1341 -0
- package/lib/plugins/commands.d.ts +23 -0
- package/lib/plugins/commands.js +498 -0
- package/lib/plugins/compact.d.ts +21 -0
- package/lib/plugins/compact.js +274 -0
- package/lib/plugins/computer-use.d.ts +47 -0
- package/lib/plugins/computer-use.js +539 -0
- package/lib/plugins/desktop-dock.d.ts +2 -0
- package/lib/plugins/desktop-dock.js +626 -0
- package/lib/plugins/dock-browser.d.ts +34 -0
- package/lib/plugins/dock-browser.js +765 -0
- package/lib/plugins/dsh-compat.d.ts +25 -0
- package/lib/plugins/dsh-compat.js +37 -0
- package/lib/plugins/file-review.d.ts +108 -0
- package/lib/plugins/file-review.js +393 -0
- package/lib/plugins/git.d.ts +26 -0
- package/lib/plugins/git.js +132 -0
- package/lib/plugins/goal.d.ts +20 -0
- package/lib/plugins/goal.js +245 -0
- package/lib/plugins/guards.d.ts +14 -0
- package/lib/plugins/guards.js +18 -0
- package/lib/plugins/hooks.d.ts +19 -0
- package/lib/plugins/hooks.js +583 -0
- package/lib/plugins/host-stdio.d.ts +88 -0
- package/lib/plugins/host-stdio.js +317 -0
- package/lib/plugins/image-diet.d.ts +17 -0
- package/lib/plugins/image-diet.js +85 -0
- package/lib/plugins/lifecycle-hooks.d.ts +26 -0
- package/lib/plugins/lifecycle-hooks.js +338 -0
- package/lib/plugins/llm.d.ts +13 -0
- package/lib/plugins/llm.js +215 -0
- package/lib/plugins/lsp.d.ts +54 -0
- package/lib/plugins/lsp.js +608 -0
- package/lib/plugins/mcp.d.ts +16 -0
- package/lib/plugins/mcp.js +673 -0
- package/lib/plugins/memory.d.ts +17 -0
- package/lib/plugins/memory.js +858 -0
- package/lib/plugins/microcompact.d.ts +18 -0
- package/lib/plugins/microcompact.js +119 -0
- package/lib/plugins/mode.d.ts +18 -0
- package/lib/plugins/mode.js +115 -0
- package/lib/plugins/permission-presets.d.ts +18 -0
- package/lib/plugins/permission-presets.js +135 -0
- package/lib/plugins/plan.d.ts +2 -0
- package/lib/plugins/plan.js +192 -0
- package/lib/plugins/plugin-manager.d.ts +2 -0
- package/lib/plugins/plugin-manager.js +165 -0
- package/lib/plugins/presets.d.ts +2 -0
- package/lib/plugins/presets.js +182 -0
- package/lib/plugins/prompt.d.ts +2 -0
- package/lib/plugins/prompt.js +264 -0
- package/lib/plugins/ptc.d.ts +2 -0
- package/lib/plugins/ptc.js +272 -0
- package/lib/plugins/remote/http.d.ts +11 -0
- package/lib/plugins/remote/http.js +11 -0
- package/lib/plugins/remote/routes.d.ts +24 -0
- package/lib/plugins/remote/routes.js +384 -0
- package/lib/plugins/remote/types.d.ts +135 -0
- package/lib/plugins/remote/types.js +87 -0
- package/lib/plugins/remote.d.ts +17 -0
- package/lib/plugins/remote.js +1028 -0
- package/lib/plugins/runtime-api.d.ts +16 -0
- package/lib/plugins/runtime-api.js +99 -0
- package/lib/plugins/runtime.d.ts +10 -0
- package/lib/plugins/runtime.js +451 -0
- package/lib/plugins/sandbox.d.ts +2 -0
- package/lib/plugins/sandbox.js +761 -0
- package/lib/plugins/schedule.d.ts +26 -0
- package/lib/plugins/schedule.js +538 -0
- package/lib/plugins/self-improve.d.ts +61 -0
- package/lib/plugins/self-improve.js +953 -0
- package/lib/plugins/session-search.d.ts +16 -0
- package/lib/plugins/session-search.js +308 -0
- package/lib/plugins/session-title.d.ts +19 -0
- package/lib/plugins/session-title.js +109 -0
- package/lib/plugins/session.d.ts +7 -0
- package/lib/plugins/session.js +296 -0
- package/lib/plugins/settings.d.ts +3 -0
- package/lib/plugins/settings.js +705 -0
- package/lib/plugins/skills.d.ts +2 -0
- package/lib/plugins/skills.js +360 -0
- package/lib/plugins/spill.d.ts +16 -0
- package/lib/plugins/spill.js +200 -0
- package/lib/plugins/subagent.d.ts +2 -0
- package/lib/plugins/subagent.js +862 -0
- package/lib/plugins/surfaces.d.ts +11 -0
- package/lib/plugins/surfaces.js +20 -0
- package/lib/plugins/team.d.ts +16 -0
- package/lib/plugins/team.js +149 -0
- package/lib/plugins/todo.d.ts +19 -0
- package/lib/plugins/todo.js +188 -0
- package/lib/plugins/tool-search.d.ts +2 -0
- package/lib/plugins/tool-search.js +425 -0
- package/lib/plugins/tools-default.d.ts +12 -0
- package/lib/plugins/tools-default.js +275 -0
- package/lib/plugins/tools.d.ts +16 -0
- package/lib/plugins/tools.js +62 -0
- package/lib/plugins/transcript.d.ts +15 -0
- package/lib/plugins/transcript.js +311 -0
- package/lib/plugins/tui.d.ts +2 -0
- package/lib/plugins/tui.js +98 -0
- package/lib/plugins/waiting.d.ts +12 -0
- package/lib/plugins/waiting.js +34 -0
- package/lib/plugins/web-search.d.ts +14 -0
- package/lib/plugins/web-search.js +263 -0
- package/lib/plugins/webserver.d.ts +48 -0
- package/lib/plugins/webserver.js +228 -0
- package/lib/remote/assets/app-DAcUCOEn.js +14 -0
- package/lib/remote/assets/icon-192.png +0 -0
- package/lib/remote/assets/icon-512.png +0 -0
- package/lib/remote/assets/index.html +34 -0
- package/lib/remote/assets/manifest.json +27 -0
- package/lib/remote/assets/style-DIB6729x.css +1 -0
- package/lib/remote/assets/sw.js +66 -0
- package/lib/services/types.d.ts +1228 -0
- package/lib/services/types.js +1 -0
- package/lib/tools/config-cli.d.ts +1 -0
- package/lib/tools/config-cli.js +89 -0
- package/lib/ui/arrival.d.ts +72 -0
- package/lib/ui/arrival.js +105 -0
- package/lib/ui/assets/app-B70nVIKd.js +69 -0
- package/lib/ui/assets/chunk-2UxHyX5q.js +1 -0
- package/lib/ui/assets/chunk-B1dDrJ26.js +1 -0
- package/lib/ui/assets/chunk-B6aJPvgy.js +1 -0
- package/lib/ui/assets/chunk-BEwlwnbL.js +1 -0
- package/lib/ui/assets/chunk-BGcgwlCI.js +12 -0
- package/lib/ui/assets/chunk-BIGW1oBm.js +1 -0
- package/lib/ui/assets/chunk-BPQ3VLAy.js +1 -0
- package/lib/ui/assets/chunk-BRH0KZbk.js +141 -0
- package/lib/ui/assets/chunk-BX6H_ySx.js +1 -0
- package/lib/ui/assets/chunk-B_P3UbPa.js +1 -0
- package/lib/ui/assets/chunk-B_TYUkTI.js +1 -0
- package/lib/ui/assets/chunk-B_vNuMnf.js +1 -0
- package/lib/ui/assets/chunk-BajyYBss.js +10 -0
- package/lib/ui/assets/chunk-BdnUsdx6.js +1 -0
- package/lib/ui/assets/chunk-Buea-lGh.js +1 -0
- package/lib/ui/assets/chunk-C0PvZCCE.js +1 -0
- package/lib/ui/assets/chunk-C0m74zRD.js +1 -0
- package/lib/ui/assets/chunk-C27-OAKa.js +1 -0
- package/lib/ui/assets/chunk-C2oV4EkX.js +1 -0
- package/lib/ui/assets/chunk-C7zT0LnQ.js +1 -0
- package/lib/ui/assets/chunk-C9GSunVT.js +1 -0
- package/lib/ui/assets/chunk-C9tS-k6U.js +1 -0
- package/lib/ui/assets/chunk-CHLpvVh8.js +1 -0
- package/lib/ui/assets/chunk-CLxacb5B.js +1 -0
- package/lib/ui/assets/chunk-COt5Ahok.js +1 -0
- package/lib/ui/assets/chunk-CPTIWCL2.js +1 -0
- package/lib/ui/assets/chunk-CQLl-L-p.js +1 -0
- package/lib/ui/assets/chunk-CUWRgxuq.js +55 -0
- package/lib/ui/assets/chunk-CWanVSXC.js +1 -0
- package/lib/ui/assets/chunk-Cf5RLm7j.js +1 -0
- package/lib/ui/assets/chunk-CickPsom.js +1 -0
- package/lib/ui/assets/chunk-Cj5Yp3dK.js +1 -0
- package/lib/ui/assets/chunk-Cmh6b_Ma.js +1 -0
- package/lib/ui/assets/chunk-Cp-IABpG.js +1 -0
- package/lib/ui/assets/chunk-CqE71os6.js +1 -0
- package/lib/ui/assets/chunk-CtKP3W-j.js +1 -0
- package/lib/ui/assets/chunk-Cvjx9yec.js +1 -0
- package/lib/ui/assets/chunk-CxGP3dtY.js +1 -0
- package/lib/ui/assets/chunk-CylS5w8V.js +1 -0
- package/lib/ui/assets/chunk-D38fbIBN.js +1 -0
- package/lib/ui/assets/chunk-D97Zzqfu.js +1 -0
- package/lib/ui/assets/chunk-DAi9KRSo.js +1 -0
- package/lib/ui/assets/chunk-DHK4yRfg.js +1 -0
- package/lib/ui/assets/chunk-DJeabLx-.js +1 -0
- package/lib/ui/assets/chunk-DNRxmY5a.js +1 -0
- package/lib/ui/assets/chunk-DNSN1z5r.js +1 -0
- package/lib/ui/assets/chunk-DNasK_ZG.js +1 -0
- package/lib/ui/assets/chunk-DPvrY3IQ.js +1 -0
- package/lib/ui/assets/chunk-DXmwc3jG.js +1 -0
- package/lib/ui/assets/chunk-Dd0kTxKP.js +1 -0
- package/lib/ui/assets/chunk-De0Btta0.js +1 -0
- package/lib/ui/assets/chunk-Des-eS-w.js +1 -0
- package/lib/ui/assets/chunk-Df6bDoY_.js +1 -0
- package/lib/ui/assets/chunk-DijEV5ha.js +1 -0
- package/lib/ui/assets/chunk-DkvoVjww.js +1 -0
- package/lib/ui/assets/chunk-DlC-OlHO.js +1 -0
- package/lib/ui/assets/chunk-DnzrXTVv.js +1 -0
- package/lib/ui/assets/chunk-Dualf0xi.js +1 -0
- package/lib/ui/assets/chunk-EXT84bkm.js +1 -0
- package/lib/ui/assets/chunk-GwR3hkPK.js +1 -0
- package/lib/ui/assets/chunk-P80f7IUj.js +1 -0
- package/lib/ui/assets/chunk-VOosw3JB.js +1 -0
- package/lib/ui/assets/chunk-YQ4lDkt_.js +140 -0
- package/lib/ui/assets/chunk-Yzrsuije.js +1 -0
- package/lib/ui/assets/chunk-Z72CF80r.js +1 -0
- package/lib/ui/assets/chunk-g9-lgVsj.js +1 -0
- package/lib/ui/assets/chunk-vGWfd6FD.js +1 -0
- package/lib/ui/assets/chunk-wDzz0qaB.js +1 -0
- package/lib/ui/assets/chunk-ySF7HWmS.js +1 -0
- package/lib/ui/assets/icon.png +0 -0
- package/lib/ui/assets/index.html +14 -0
- package/lib/ui/assets/pdf.worker.min-CjEcRF4W.mjs +28 -0
- package/lib/ui/assets/style-Bq01xH_b.css +1 -0
- package/lib/ui/frames.d.ts +67 -0
- package/lib/ui/frames.js +146 -0
- package/lib/ui/index.d.ts +59 -0
- package/lib/ui/index.js +50 -0
- package/lib/ui/manifest.d.ts +172 -0
- package/lib/ui/manifest.js +158 -0
- package/lib/ui/plugin.d.ts +161 -0
- package/lib/ui/plugin.js +7 -0
- package/lib/ui/plugins/browser/client.js +290 -0
- package/lib/ui/plugins/browser/icon.png +0 -0
- package/lib/ui/plugins/composer/client.js +1843 -0
- package/lib/ui/plugins/composer/icon.png +0 -0
- package/lib/ui/plugins/files/client.js +646 -0
- package/lib/ui/plugins/files/icon.png +0 -0
- package/lib/ui/plugins/manifest.json +107 -0
- package/lib/ui/plugins/plugins/client.js +682 -0
- package/lib/ui/plugins/plugins/icon.png +0 -0
- package/lib/ui/plugins/preview/client.js +197 -0
- package/lib/ui/plugins/preview/icon.png +0 -0
- package/lib/ui/plugins/prompt/client.js +653 -0
- package/lib/ui/plugins/prompt/icon.png +0 -0
- package/lib/ui/plugins/sessions/client.js +1577 -0
- package/lib/ui/plugins/sessions/icon.png +0 -0
- package/lib/ui/plugins/settings/client.js +5470 -0
- package/lib/ui/plugins/settings/icon.png +0 -0
- package/lib/ui/plugins/skills/client.js +485 -0
- package/lib/ui/plugins/skills/icon.png +0 -0
- package/lib/ui/plugins/status/client.js +1420 -0
- package/lib/ui/plugins/status/icon.png +0 -0
- package/lib/ui/plugins/statusbar/client.js +504 -0
- package/lib/ui/plugins/statusbar/icon.png +0 -0
- package/lib/ui/plugins/tasks/client.js +52 -0
- package/lib/ui/plugins/tasks/icon.png +0 -0
- package/lib/ui/plugins/team/client.js +527 -0
- package/lib/ui/plugins/team/icon.png +0 -0
- package/lib/ui/plugins/terminal/client.js +232 -0
- package/lib/ui/plugins/terminal/icon.png +0 -0
- package/lib/ui/plugins/trace/client.js +1376 -0
- package/lib/ui/plugins/trace/icon.png +0 -0
- package/lib/ui/plugins/transcript/client.js +2661 -0
- package/lib/ui/plugins/transcript/icon.png +0 -0
- package/lib/ui/scoped-slots.d.ts +20 -0
- package/lib/ui/scoped-slots.js +21 -0
- package/lib/ui/sdk/@dsc/ui/index.d.ts +242 -0
- package/lib/ui/sdk/@dsc/ui/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-core/contract.d.ts +1973 -0
- package/lib/ui/sdk/@dsc/ui-core/core/diff-text.d.ts +74 -0
- package/lib/ui/sdk/@dsc/ui-core/core/dock-browser.d.ts +137 -0
- package/lib/ui/sdk/@dsc/ui-core/core/dock-ops.d.ts +59 -0
- package/lib/ui/sdk/@dsc/ui-core/core/model-caps.d.ts +83 -0
- package/lib/ui/sdk/@dsc/ui-core/core/native-bridge.d.ts +135 -0
- package/lib/ui/sdk/@dsc/ui-core/core/token-estimate.d.ts +55 -0
- package/lib/ui/sdk/@dsc/ui-core/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/arrival.d.ts +72 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/frames.d.ts +67 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/index.d.ts +59 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/manifest.d.ts +172 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/plugin.d.ts +161 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/scoped-slots.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/services-react.d.ts +27 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/services.d.ts +63 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/slots-react.d.ts +28 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/slots.d.ts +481 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/store.d.ts +89 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock-model.d.ts +238 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock-state.d.ts +163 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/index.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-layout/app.d.ts +74 -0
- package/lib/ui/sdk/@dsc/ui-layout/appearance.d.ts +70 -0
- package/lib/ui/sdk/@dsc/ui-layout/host-channel.d.ts +112 -0
- package/lib/ui/sdk/@dsc/ui-layout/index.d.ts +34 -0
- package/lib/ui/sdk/@dsc/ui-layout/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-layout/page-state.d.ts +14 -0
- package/lib/ui/sdk/@dsc/ui-layout/review-pane.d.ts +21 -0
- package/lib/ui/sdk/@dsc/ui-layout/runtime-context.d.ts +44 -0
- package/lib/ui/sdk/@dsc/ui-layout/thread-view.d.ts +28 -0
- package/lib/ui/sdk/@dsc/ui-layout/update-button.d.ts +21 -0
- package/lib/ui/sdk/@dsc/ui-primitives/code-file-icon-artwork.d.ts +53 -0
- package/lib/ui/sdk/@dsc/ui-primitives/code-view.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-primitives/compat.d.ts +27 -0
- package/lib/ui/sdk/@dsc/ui-primitives/completion-sound.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-primitives/confirm.d.ts +33 -0
- package/lib/ui/sdk/@dsc/ui-primitives/css.d.ts +47 -0
- package/lib/ui/sdk/@dsc/ui-primitives/diff-rows.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-icons.d.ts +38 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-type-classify.d.ts +66 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-type-icon.d.ts +57 -0
- package/lib/ui/sdk/@dsc/ui-primitives/highlight.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-primitives/hover-delay.d.ts +17 -0
- package/lib/ui/sdk/@dsc/ui-primitives/icons.d.ts +109 -0
- package/lib/ui/sdk/@dsc/ui-primitives/index.d.ts +55 -0
- package/lib/ui/sdk/@dsc/ui-primitives/lang-table.d.ts +10 -0
- package/lib/ui/sdk/@dsc/ui-primitives/markdown.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-primitives/native.d.ts +41 -0
- package/lib/ui/sdk/@dsc/ui-primitives/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-primitives/panels.d.ts +86 -0
- package/lib/ui/sdk/@dsc/ui-primitives/paths.d.ts +11 -0
- package/lib/ui/sdk/@dsc/ui-primitives/pdf-view.d.ts +13 -0
- package/lib/ui/sdk/@dsc/ui-primitives/plugin-text.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-primitives/select.d.ts +35 -0
- package/lib/ui/sdk/@dsc/ui-primitives/table-view.d.ts +23 -0
- package/lib/ui/sdk/@dsc/ui-primitives/thread-resizer.d.ts +22 -0
- package/lib/ui/sdk/@dsc/ui-primitives/time.d.ts +33 -0
- package/lib/ui/sdk/@dsc/ui-primitives/toast.d.ts +16 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tokens.d.ts +14 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tool-args.d.ts +49 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tool-summary.d.ts +64 -0
- package/lib/ui/sdk/@dsc/ui-renderer/boot.d.ts +121 -0
- package/lib/ui/sdk/@dsc/ui-renderer/hmr.d.ts +43 -0
- package/lib/ui/sdk/@dsc/ui-renderer/index.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-renderer/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-slots/index.d.ts +19 -0
- package/lib/ui/sdk/@dsc/ui-slots/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-slots/slots-react.d.ts +48 -0
- package/lib/ui/sdk/@dsc/ui-slots/slots.d.ts +102 -0
- package/lib/ui/services-react.d.ts +27 -0
- package/lib/ui/services-react.js +32 -0
- package/lib/ui/services.d.ts +63 -0
- package/lib/ui/services.js +121 -0
- package/lib/ui/slots-ink.d.ts +26 -0
- package/lib/ui/slots-ink.js +78 -0
- package/lib/ui/slots-react.d.ts +28 -0
- package/lib/ui/slots-react.js +88 -0
- package/lib/ui/slots.d.ts +481 -0
- package/lib/ui/slots.js +550 -0
- package/lib/ui/store.d.ts +89 -0
- package/lib/ui/store.js +62 -0
- package/lib/ui/tui-plugin-api.d.ts +23 -0
- package/lib/ui/tui-plugin-api.js +23 -0
- package/lib/ui/tui-plugins.d.ts +47 -0
- package/lib/ui/tui-plugins.js +220 -0
- package/package.json +58 -6
|
@@ -0,0 +1,1028 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* remote 插件:把这一条会话开给局域网里的手机浏览器(「远程操控」的宿主半边)。
|
|
3
|
+
*
|
|
4
|
+
* 四件事:**谁伺服**、**谁能进来**、**进来之后能干什么**、**不看屏幕也能知道有事发生**。
|
|
5
|
+
*
|
|
6
|
+
* 1. 谁伺服:同一台机器上可能有不止一个 Pneuma 进程(桌面端一个、终端一个),
|
|
7
|
+
* 而一个端口只能被一个进程听,所以先抢 `~/.dsc/remote/.owner.json` 主控位(pid + 启动
|
|
8
|
+
* 指纹,写法与调度锁同款)。抢不到的进程**完全休眠**:不监听、不起服务,每 30 秒回头
|
|
9
|
+
* 看一眼主控位空出来没有。
|
|
10
|
+
*
|
|
11
|
+
* 2. 谁能进来:配对码(8 位、半小时、错 5 次锁 1 小时)换设备 token,token 换一次性 WS
|
|
12
|
+
* 票据,票据换连接。明文码与 token 都不落盘(只落 sha256),码也绝不进 transcript——
|
|
13
|
+
* 会话 jsonl 是会被翻出来的。所有路由都查 Host 头(必须是 IP 字面量或 localhost 且端口
|
|
14
|
+
* 对得上),挡 DNS rebinding:恶意网页把自己的域名解析到 127.0.0.1 也照打不进来。
|
|
15
|
+
*
|
|
16
|
+
* 3. 能干什么:只开一份白名单(见 REMOTE_METHODS),凭据类与宿主生命周期相关的操作
|
|
17
|
+
* (saveProvider / setProviderKey / setSettingValue / runSettingAction / dock / exit……)
|
|
18
|
+
* 一律不开放。派发与 host-stdio 同一套反射惯例,走 ctx.ui(DscRuntime)。
|
|
19
|
+
*
|
|
20
|
+
* 4. 不看屏幕也能知道:审批卡从无到有、一轮跑完 → Web Push + 通知 Webhook 同时发
|
|
21
|
+
* (设置里的 `remote.push` 与 `remote.notifyWebhook`)。推送全挂在插件已有的
|
|
22
|
+
* 订阅与事件上,内核一条新事件都不用加。
|
|
23
|
+
*
|
|
24
|
+
* **帧协议 v3**(批 B 的手机界面按这一份认版本):
|
|
25
|
+
*
|
|
26
|
+
* - seq 是**宿主级全局单调递增**的(跨连接、跨重连连续),不再每条连接各自从 1 数;
|
|
27
|
+
* - 快照不再每帧全量:与上一帧相比按条目 `id` 做 diff,只发 `added` / `updated` /
|
|
28
|
+
* `removedIds`,其余字段打成 `meta` 每帧全量带(规则与锚帧见 core/remote/frames.ts);
|
|
29
|
+
* - 最近 120 帧进环形缓冲(**原样存 JSON 字符串**,重发不重算)。客户端在升级 URL 上带
|
|
30
|
+
* `&lastSeq=N`:N 落在缓冲窗口内就照原样补发 N 之后的所有帧再转实时(补发不节流),
|
|
31
|
+
* 否则 `hello` + 一帧全量;
|
|
32
|
+
* - 上行(invoke)与静态资源一如既往;上传与推送订阅走 HTTP,不进 invoke 白名单。
|
|
33
|
+
*
|
|
34
|
+
* 静态资源目录是 `lib/remote/assets`(批 B 的 vite 产物落点,见 remote-web/vite.config.ts);
|
|
35
|
+
* 目录不存在(还没构建界面)时 `/` 返回一张「资产未构建」的占位页。
|
|
36
|
+
*
|
|
37
|
+
* **手机端切壳(对齐计划 8c)**:默认伺服的界面是**同一份插件壳**(`lib/ui/assets`,
|
|
38
|
+
* 与桌面同源)——静态产物、启动图(`/boot.js`)、数据通道(`/api/events` + `/api/invoke`,
|
|
39
|
+
* 方法面是 `REMOTE_SHELL_METHODS` 子集)三件都从这一侧出;未配对的浏览器先落在配对页
|
|
40
|
+
* (`POST /api/pair` 换 HttpOnly 设备 Cookie,EventSource 带不了自定义头,只能靠它)。
|
|
41
|
+
* 经典档(remote-web 自己的移动端应用)保留在 `DSC_REMOTE_UI=classic` 或插件配置
|
|
42
|
+
* `ui: 'classic'` 后面,也作为壳产物缺失时的回落。
|
|
43
|
+
*
|
|
44
|
+
* @module dsc/plugins/remote
|
|
45
|
+
*/
|
|
46
|
+
import { createServer } from 'node:http';
|
|
47
|
+
import { existsSync } from 'node:fs';
|
|
48
|
+
import { networkInterfaces } from 'node:os';
|
|
49
|
+
import { dirname, join, resolve } from 'node:path';
|
|
50
|
+
import { fileURLToPath } from 'node:url';
|
|
51
|
+
import { WebSocket, WebSocketServer } from 'ws';
|
|
52
|
+
import { bootNoticeOnce } from '../core/boot-notices.js';
|
|
53
|
+
import { errText } from '../core/err-text.js';
|
|
54
|
+
import { REMOTE_PORT_MAX, REMOTE_PORT_MIN } from '../core/prefs.js';
|
|
55
|
+
import { resolvePluginConfig } from '../core/plugin-registry.js';
|
|
56
|
+
import { RemoteFrameHub } from '../core/remote/frames.js';
|
|
57
|
+
import { isHttpUrl, sendWebhook, webhookHasPlaceholder } from '../core/remote/notify.js';
|
|
58
|
+
import { RemoteOwnerLock } from '../core/remote/owner.js';
|
|
59
|
+
import { RemotePairing } from '../core/remote/pairing.js';
|
|
60
|
+
import { RemotePush } from '../core/remote/push.js';
|
|
61
|
+
import { TicketStore } from '../core/remote/tickets.js';
|
|
62
|
+
import { RemoteUploads } from '../core/remote/uploads.js';
|
|
63
|
+
import { uiAssetsDir, uiPluginsDir } from '../core/ui-bundles.js';
|
|
64
|
+
import { createUiBootSource } from '../core/ui-boot-source.js';
|
|
65
|
+
import { createUiEvents } from '../core/ui-events.js';
|
|
66
|
+
import { validateUiArgs } from '../core/ui-methods.js';
|
|
67
|
+
import { DSC_VERSION } from '../core/version.js';
|
|
68
|
+
import { readCookie } from '../core/web-http.js';
|
|
69
|
+
import { bearerToken, hostHeaderAllowed, isRecord, readLastSeq, sendJson } from './remote/http.js';
|
|
70
|
+
import { createRequestHandler } from './remote/routes.js';
|
|
71
|
+
import { REMOTE_COOKIE, REMOTE_METHODS, REMOTE_PROTOCOL_VERSION, REMOTE_SET, REMOTE_SHELL_METHODS, REMOTE_SHELL_SET, } from './remote/types.js';
|
|
72
|
+
import { UI_EVENTS_PROTOCOL_VERSION } from './webserver.js';
|
|
73
|
+
/** 配置键(`~/.dsc/plugins.json` 条目树里 `file` 等于这个名字那一项的 `config`)。 */
|
|
74
|
+
const CONFIG_KEY = 'remote';
|
|
75
|
+
/** 快照推送节流间隔的缺省值(与 host-stdio 同一个口径)。 */
|
|
76
|
+
const DEFAULT_SNAPSHOT_THROTTLE_MS = 80;
|
|
77
|
+
/** 休眠时回头看一眼主控位的间隔。 */
|
|
78
|
+
const OWNER_RETRY_MS = 30_000;
|
|
79
|
+
/** 同类推送的节流窗口:审批卡连着弹、轮结束连着来的时候,手机上别炸一串。 */
|
|
80
|
+
const NOTIFY_THROTTLE_MS = 10_000;
|
|
81
|
+
/** T45:同一张卡挂了这么久还没人理,就升级再提醒一声(别让推送石沉大海)。 */
|
|
82
|
+
const ESCALATE_WAIT_MS = 120_000;
|
|
83
|
+
/** T45:升级提醒最多几声(别变成骚扰)。 */
|
|
84
|
+
const ESCALATE_MAX = 3;
|
|
85
|
+
/** 多短的一轮不值得通报(用过 15 秒以上,或者这一轮出现过审批卡,才发「轮完成」)。 */
|
|
86
|
+
const TURN_NOTIFY_MIN_MS = 15_000;
|
|
87
|
+
/**
|
|
88
|
+
* 取快照推送节流间隔:夹在 16 毫秒到 1 秒之间(与 host-stdio 同一条理由:再小是白烧 CPU,
|
|
89
|
+
* 再大是点完按钮半天没反应)。
|
|
90
|
+
*/
|
|
91
|
+
function readThrottle(passed) {
|
|
92
|
+
const raw = resolvePluginConfig(CONFIG_KEY, passed);
|
|
93
|
+
const num = Number(raw.snapshotThrottleMs);
|
|
94
|
+
if (!Number.isFinite(num))
|
|
95
|
+
return DEFAULT_SNAPSHOT_THROTTLE_MS;
|
|
96
|
+
return Math.min(Math.max(Math.round(num), 16), 1_000);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 静态资源目录:编译产物是 `lib/plugins/remote.js`,界面产物在 `lib/remote/assets`
|
|
100
|
+
* (由 remote-web 的 vite 配置直接写进去)。
|
|
101
|
+
*/
|
|
102
|
+
export function remoteAssetsDir() {
|
|
103
|
+
return resolve(dirname(fileURLToPath(import.meta.url)), '..', 'remote', 'assets');
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 取静态资源目录:默认就是 {@link remoteAssetsDir},
|
|
107
|
+
* 插件配置里的 `assetsDir` 可以指到别处(自检脚本用它验「目录不存在」的兜底页)。
|
|
108
|
+
*/
|
|
109
|
+
function readAssetsDir(passed) {
|
|
110
|
+
const raw = resolvePluginConfig(CONFIG_KEY, passed);
|
|
111
|
+
const dir = raw.assetsDir;
|
|
112
|
+
return typeof dir === 'string' && dir.trim() !== '' ? resolve(dir) : remoteAssetsDir();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* 手机端伺服哪份界面:`'shell'` = 插件壳产物(默认,切壳后的形态);
|
|
116
|
+
* `'classic'` = remote-web 自己的移动端应用(回落档)。
|
|
117
|
+
* 环境变量优先(自检与回退用,不必改用户配置);壳产物缺失时由调用方再降级。
|
|
118
|
+
*/
|
|
119
|
+
function readUiMode(passed) {
|
|
120
|
+
const env = process.env['DSC_REMOTE_UI'];
|
|
121
|
+
if (env === 'classic' || env === 'shell')
|
|
122
|
+
return env;
|
|
123
|
+
const raw = resolvePluginConfig(CONFIG_KEY, passed).ui;
|
|
124
|
+
return raw === 'classic' ? 'classic' : 'shell';
|
|
125
|
+
}
|
|
126
|
+
/** 本机的局域网 IPv4(设置页显示「手机该输哪个地址」;找不到给 null)。 */
|
|
127
|
+
function lanAddress() {
|
|
128
|
+
for (const list of Object.values(networkInterfaces())) {
|
|
129
|
+
for (const entry of list ?? []) {
|
|
130
|
+
if (entry.family === 'IPv4' && !entry.internal)
|
|
131
|
+
return entry.address;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
/** 拒绝一次 WS 升级:状态行必须是 ASCII,中文说明放 body 里。 */
|
|
137
|
+
function rejectUpgrade(socket, status, reason, error) {
|
|
138
|
+
try {
|
|
139
|
+
const body = JSON.stringify({ ok: false, error });
|
|
140
|
+
socket.write(`HTTP/1.1 ${String(status)} ${reason}\r\n` +
|
|
141
|
+
'content-type: application/json; charset=utf-8\r\n' +
|
|
142
|
+
`content-length: ${String(Buffer.byteLength(body))}\r\n` +
|
|
143
|
+
'connection: close\r\n\r\n' +
|
|
144
|
+
body);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
// 对端可能已经走了
|
|
148
|
+
}
|
|
149
|
+
socket.destroy();
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* 起一个 HTTP + WebSocket 服务。返回的是句柄而不是 Promise:listen 是异步的,
|
|
153
|
+
* 调用方在 `ready` 上收结果,句柄本身立刻可用(`close` 随时能收)。
|
|
154
|
+
*
|
|
155
|
+
* 帧流是**宿主级一份**:一个节流定时器 + 一个 {@link RemoteFrameHub},所有连接收同一串帧。
|
|
156
|
+
* HTTP 业务路由在 `remote/routes.ts`(`createRequestHandler`),这里只剩帧流、
|
|
157
|
+
* WS 会话与生命周期。
|
|
158
|
+
*/
|
|
159
|
+
export function createRemoteServer(deps) {
|
|
160
|
+
const sockets = new Set();
|
|
161
|
+
const wss = new WebSocketServer({ noServer: true });
|
|
162
|
+
/** 每条连接的收尾(退订 + 清定时器)。 */
|
|
163
|
+
const cleanups = new Map();
|
|
164
|
+
/** 每条连接是哪台设备的(吊销设备时要按这个把人踢下线)。 */
|
|
165
|
+
const sessionDevice = new Map();
|
|
166
|
+
/** 全局帧流:seq 跨连接连续,最近 120 帧进环形缓冲。 */
|
|
167
|
+
const hub = new RemoteFrameHub();
|
|
168
|
+
let frameTimer = null;
|
|
169
|
+
let framePending = false;
|
|
170
|
+
/**
|
|
171
|
+
* 一条连接都没有的时候发生的会话变化:帧流那时不前进(没人看,白算),
|
|
172
|
+
* 所以下一条连接补完缓冲里的帧之后,必须再补一帧全量把这段时间的变化对上。
|
|
173
|
+
*/
|
|
174
|
+
let missedWhileIdle = false;
|
|
175
|
+
/** 断开连接:只断指定设备,或全断。返回断了几条。 */
|
|
176
|
+
function closeDevices(deviceId) {
|
|
177
|
+
let count = 0;
|
|
178
|
+
for (const ws of [...sockets]) {
|
|
179
|
+
if (deviceId !== undefined && sessionDevice.get(ws) !== deviceId)
|
|
180
|
+
continue;
|
|
181
|
+
count += 1;
|
|
182
|
+
cleanups.get(ws)?.();
|
|
183
|
+
try {
|
|
184
|
+
ws.close(1008, '设备已被吊销');
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
// 已经断了
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return count;
|
|
191
|
+
}
|
|
192
|
+
const sendText = (ws, text) => {
|
|
193
|
+
if (ws.readyState === WebSocket.OPEN)
|
|
194
|
+
ws.send(text);
|
|
195
|
+
};
|
|
196
|
+
/** 造下一帧、进环形缓冲、发给所有连接。 */
|
|
197
|
+
const emitFrame = (forceFull) => {
|
|
198
|
+
const frame = hub.build(deps.snapshot(), forceFull);
|
|
199
|
+
for (const ws of sockets)
|
|
200
|
+
sendText(ws, frame.text);
|
|
201
|
+
missedWhileIdle = false;
|
|
202
|
+
return frame;
|
|
203
|
+
};
|
|
204
|
+
/** 会话流有变化:攒到下一次节流到点,合成一帧。 */
|
|
205
|
+
const scheduleFrame = () => {
|
|
206
|
+
if (sockets.size === 0) {
|
|
207
|
+
// 没人连着:不造帧(造了也没人收),但要记住「这段时间变过」
|
|
208
|
+
missedWhileIdle = true;
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
framePending = true;
|
|
212
|
+
if (frameTimer !== null)
|
|
213
|
+
return;
|
|
214
|
+
frameTimer = setTimeout(() => {
|
|
215
|
+
frameTimer = null;
|
|
216
|
+
if (!framePending)
|
|
217
|
+
return;
|
|
218
|
+
framePending = false;
|
|
219
|
+
if (sockets.size === 0) {
|
|
220
|
+
missedWhileIdle = true;
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
emitFrame(false);
|
|
224
|
+
}, deps.throttleMs);
|
|
225
|
+
};
|
|
226
|
+
const stopFrames = () => {
|
|
227
|
+
if (frameTimer !== null)
|
|
228
|
+
clearTimeout(frameTimer);
|
|
229
|
+
frameTimer = null;
|
|
230
|
+
framePending = false;
|
|
231
|
+
};
|
|
232
|
+
/** 宿主级订阅:帧流是共享的,所以只订一次(不是每条连接一份)。 */
|
|
233
|
+
const unsubscribeStream = deps.subscribe(scheduleFrame);
|
|
234
|
+
const handleRequest = createRequestHandler({ deps, closeDevices });
|
|
235
|
+
const server = createServer((req, res) => {
|
|
236
|
+
handleRequest(req, res).catch((error) => {
|
|
237
|
+
try {
|
|
238
|
+
sendJson(res, 500, { ok: false, error: errText(error) });
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
// 响应可能已经发出去了
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
// 全生命周期兜底:listen 之后的 socket 级错误不发 'error' 监听器会把进程带崩
|
|
246
|
+
server.on('error', (error) => {
|
|
247
|
+
deps.notice(`远程控制服务出错:${errText(error)}`);
|
|
248
|
+
});
|
|
249
|
+
/** 一条连接的握手与消息循环。 */
|
|
250
|
+
const openSession = (ws, deviceId, lastSeq) => {
|
|
251
|
+
sockets.add(ws);
|
|
252
|
+
sessionDevice.set(ws, deviceId);
|
|
253
|
+
const send = (message) => {
|
|
254
|
+
sendText(ws, JSON.stringify(message));
|
|
255
|
+
};
|
|
256
|
+
// 握手:hello 先报身份(协议版本、端口、开放方法、VAPID 公钥),再按 lastSeq 决定补帧还是全量
|
|
257
|
+
const snapshot = deps.snapshot();
|
|
258
|
+
send({
|
|
259
|
+
type: 'hello',
|
|
260
|
+
protocolVersion: REMOTE_PROTOCOL_VERSION,
|
|
261
|
+
app: 'pneuma',
|
|
262
|
+
version: DSC_VERSION,
|
|
263
|
+
port: deps.port,
|
|
264
|
+
lan: deps.lan,
|
|
265
|
+
sessionId: snapshot.sessionId,
|
|
266
|
+
cwd: snapshot.cwd,
|
|
267
|
+
methods: [...REMOTE_METHODS],
|
|
268
|
+
pushPublicKey: deps.pushPublicKey(),
|
|
269
|
+
});
|
|
270
|
+
const replay = hub.resume(lastSeq);
|
|
271
|
+
if (replay === null) {
|
|
272
|
+
// 接不上(没带 lastSeq、缓冲是空的、或者客户端的号在窗口外):hello + 一帧全量
|
|
273
|
+
emitFrame(true);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
// 补发不节流:缓冲里存的就是原样的 JSON 字符串,直接照发
|
|
277
|
+
for (const text of replay)
|
|
278
|
+
sendText(ws, text);
|
|
279
|
+
// 断线期间一条连接都没有、那时发生的变化没进帧流:补一帧全量把它对上
|
|
280
|
+
if (missedWhileIdle)
|
|
281
|
+
emitFrame(true);
|
|
282
|
+
}
|
|
283
|
+
const handleMessage = async (data) => {
|
|
284
|
+
const raw = typeof data === 'string' ? data : Buffer.isBuffer(data) ? data.toString('utf8') : String(data);
|
|
285
|
+
let parsed = null;
|
|
286
|
+
try {
|
|
287
|
+
parsed = JSON.parse(raw);
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
send({ type: 'result', id: null, ok: false, error: '上行消息不是 JSON' });
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (!isRecord(parsed) || parsed['type'] !== 'invoke')
|
|
294
|
+
return;
|
|
295
|
+
const id = parsed['id'] ?? null;
|
|
296
|
+
const method = typeof parsed['method'] === 'string' ? parsed['method'] : '';
|
|
297
|
+
// 实参表:正常是数组(批 B 的 encodeArgs)。它还有一份「单个值」的备用编码
|
|
298
|
+
// (wire.ts 的 asSingleValue),这里一并认下——两种编码送进来都能跑通。
|
|
299
|
+
const argsField = parsed['args'];
|
|
300
|
+
const args = Array.isArray(argsField) ? argsField : argsField === undefined ? [] : [argsField];
|
|
301
|
+
if (!REMOTE_SET.has(method)) {
|
|
302
|
+
send({ type: 'result', id, ok: false, error: `远程不开放这个方法:${method}` });
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
try {
|
|
306
|
+
const value = await deps.invoke(method, args);
|
|
307
|
+
send({ type: 'result', id, ok: true, result: value ?? null });
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
send({ type: 'result', id, ok: false, error: errText(error) });
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
const cleanup = () => {
|
|
314
|
+
cleanups.delete(ws);
|
|
315
|
+
sessionDevice.delete(ws);
|
|
316
|
+
sockets.delete(ws);
|
|
317
|
+
};
|
|
318
|
+
cleanups.set(ws, cleanup);
|
|
319
|
+
ws.on('message', (data) => {
|
|
320
|
+
void handleMessage(data);
|
|
321
|
+
});
|
|
322
|
+
ws.on('close', cleanup);
|
|
323
|
+
ws.on('error', cleanup);
|
|
324
|
+
};
|
|
325
|
+
server.on('upgrade', (req, socket, head) => {
|
|
326
|
+
// 升级请求也要过 Host 检查:DNS rebinding 挡在握手之前
|
|
327
|
+
if (!hostHeaderAllowed(req.headers.host, deps.port)) {
|
|
328
|
+
rejectUpgrade(socket, 403, 'Forbidden', 'Host 头不是本机地址,拒绝升级');
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const url = new URL(req.url ?? '/', `http://127.0.0.1:${String(deps.port)}`);
|
|
332
|
+
if (url.pathname !== '/ws') {
|
|
333
|
+
rejectUpgrade(socket, 404, 'Not Found', 'WS 升级路径只有 /ws');
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
// 票据一次性:取走即焚,用过一次或过了 30 秒都算无效;票据里带着是哪台设备换的
|
|
337
|
+
const grant = deps.tickets.redeem(url.searchParams.get('ticket') ?? '');
|
|
338
|
+
if (grant === null) {
|
|
339
|
+
rejectUpgrade(socket, 401, 'Unauthorized', '票据无效或已用过,请重新取一张');
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
const lastSeq = readLastSeq(url.searchParams.get('lastSeq'));
|
|
343
|
+
wss.handleUpgrade(req, socket, head, (ws) => {
|
|
344
|
+
openSession(ws, grant.deviceId, lastSeq);
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
const ready = new Promise((resolveReady, rejectReady) => {
|
|
348
|
+
server.once('error', rejectReady);
|
|
349
|
+
server.listen(deps.port, deps.lan ? '0.0.0.0' : '127.0.0.1', () => {
|
|
350
|
+
resolveReady();
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
return {
|
|
354
|
+
port: deps.port,
|
|
355
|
+
lan: deps.lan,
|
|
356
|
+
ready,
|
|
357
|
+
close() {
|
|
358
|
+
unsubscribeStream();
|
|
359
|
+
stopFrames();
|
|
360
|
+
for (const ws of [...sockets]) {
|
|
361
|
+
cleanups.get(ws)?.();
|
|
362
|
+
try {
|
|
363
|
+
ws.close(1001, '服务已停');
|
|
364
|
+
}
|
|
365
|
+
catch {
|
|
366
|
+
// 已经断了
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
sockets.clear();
|
|
370
|
+
sessionDevice.clear();
|
|
371
|
+
wss.close();
|
|
372
|
+
server.closeAllConnections?.();
|
|
373
|
+
server.close();
|
|
374
|
+
},
|
|
375
|
+
broadcast(message) {
|
|
376
|
+
const text = JSON.stringify(message);
|
|
377
|
+
for (const ws of sockets)
|
|
378
|
+
sendText(ws, text);
|
|
379
|
+
},
|
|
380
|
+
closeDevices,
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
/** 审批卡在快照里能给的那点标题信息:参数摘要最好用,退而求其次用工具名。 */
|
|
384
|
+
function approvalHeadline(approval) {
|
|
385
|
+
if (approval === null)
|
|
386
|
+
return '打开手机确认';
|
|
387
|
+
const summary = approval.argsSummary.trim();
|
|
388
|
+
if (summary !== '')
|
|
389
|
+
return summary;
|
|
390
|
+
const tool = approval.toolName.trim();
|
|
391
|
+
return tool === '' ? '打开手机确认' : tool;
|
|
392
|
+
}
|
|
393
|
+
// ── 插件 ──────────────────────────────────────────────────────────────────────
|
|
394
|
+
export const remotePlugin = {
|
|
395
|
+
name: 'remote',
|
|
396
|
+
// 这四个服务是「得先就绪」的意思:ui 是方法派发入口,transcript 供快照与变更订阅,
|
|
397
|
+
// session 给会话 id 与工作目录,settings 用来注册设置分区并监听开关变化。
|
|
398
|
+
inject: ['session', 'transcript', 'agent', 'ui', 'approval', 'settings'],
|
|
399
|
+
apply(ctx, passed) {
|
|
400
|
+
const runtime = ctx.ui;
|
|
401
|
+
const throttleMs = readThrottle(passed);
|
|
402
|
+
const pairing = new RemotePairing();
|
|
403
|
+
const owner = new RemoteOwnerLock();
|
|
404
|
+
const tickets = new TicketStore();
|
|
405
|
+
/** 上传落盘与浏览器推送:数据文件都在 `~/.dsc/remote`(自检换 HOME 就整体隔离)。 */
|
|
406
|
+
const uploads = new RemoteUploads();
|
|
407
|
+
const pushStore = new RemotePush();
|
|
408
|
+
let server = null;
|
|
409
|
+
let retryTimer = null;
|
|
410
|
+
let lastProblem = null;
|
|
411
|
+
/** 推送密钥取不到时只提醒一次(每次连接都提醒会刷屏)。 */
|
|
412
|
+
let pushProblem = null;
|
|
413
|
+
/** 「退出主控」按过之后不再自动抢回来(重新开关一次「开启远程控制」才解除)。 */
|
|
414
|
+
let yielded = false;
|
|
415
|
+
/** 只在问题变了的时候说一次:30 秒一轮的重试不该每轮都往对话流里写一行。 */
|
|
416
|
+
const reportProblem = (text) => {
|
|
417
|
+
if (text === lastProblem)
|
|
418
|
+
return;
|
|
419
|
+
lastProblem = text;
|
|
420
|
+
ctx.emit('dsc/notice', text);
|
|
421
|
+
};
|
|
422
|
+
const armRetry = () => {
|
|
423
|
+
if (retryTimer !== null)
|
|
424
|
+
return;
|
|
425
|
+
retryTimer = setTimeout(() => {
|
|
426
|
+
retryTimer = null;
|
|
427
|
+
applyPrefs();
|
|
428
|
+
}, OWNER_RETRY_MS);
|
|
429
|
+
// 只剩它一个定时器时别挡住进程退出
|
|
430
|
+
retryTimer.unref?.();
|
|
431
|
+
};
|
|
432
|
+
const clearRetry = () => {
|
|
433
|
+
if (retryTimer !== null)
|
|
434
|
+
clearTimeout(retryTimer);
|
|
435
|
+
retryTimer = null;
|
|
436
|
+
};
|
|
437
|
+
const addressText = () => {
|
|
438
|
+
const prefs = ctx.settings.prefs().remote;
|
|
439
|
+
const port = server?.port ?? prefs.port;
|
|
440
|
+
const ip = prefs.lan ? lanAddress() : null;
|
|
441
|
+
return `http://${ip ?? '127.0.0.1'}:${String(port)}/`;
|
|
442
|
+
};
|
|
443
|
+
/** 派发:审批答案带来源;其余方法照 host-stdio 的反射惯例展开实参。 */
|
|
444
|
+
const invoke = async (method, args) => {
|
|
445
|
+
if (method === 'answerApproval') {
|
|
446
|
+
// 手机点的那一下要在审计里认得出(source='web',见 core/audit.ts)
|
|
447
|
+
return await Reflect.apply(runtime.answerApproval, runtime, [args[0], 'web']);
|
|
448
|
+
}
|
|
449
|
+
const fn = runtime[method];
|
|
450
|
+
if (typeof fn !== 'function')
|
|
451
|
+
throw new Error(`运行时没有这个方法:${method}`);
|
|
452
|
+
return await Reflect.apply(fn, runtime, args);
|
|
453
|
+
};
|
|
454
|
+
/** 批 B 契约的快照:会话身份放顶层,直播尾按负 id 拆出来单独给。 */
|
|
455
|
+
const snapshot = () => {
|
|
456
|
+
const base = runtime.getSnapshot();
|
|
457
|
+
const current = ctx.session.current();
|
|
458
|
+
return {
|
|
459
|
+
...base,
|
|
460
|
+
sessionId: current.meta.id,
|
|
461
|
+
cwd: current.meta.cwd,
|
|
462
|
+
entries: base.entries.filter((entry) => entry.id > 0),
|
|
463
|
+
liveEntries: base.entries.filter((entry) => entry.id < 0),
|
|
464
|
+
};
|
|
465
|
+
};
|
|
466
|
+
/** 把 VAPID 公钥给出去(关着时 null)。取不到只提醒一次,然后一直报 null。 */
|
|
467
|
+
const pushPublicKey = () => {
|
|
468
|
+
if (!ctx.settings.prefs().remote.push)
|
|
469
|
+
return null;
|
|
470
|
+
const key = pushStore.publicKey();
|
|
471
|
+
if (key === null && pushProblem === null) {
|
|
472
|
+
pushProblem = '浏览器推送的 VAPID 密钥读不出来(也不能生成),推送先按不可用处理';
|
|
473
|
+
ctx.emit('dsc/notice', pushProblem);
|
|
474
|
+
}
|
|
475
|
+
return key;
|
|
476
|
+
};
|
|
477
|
+
// ── 壳档(手机端切壳):静态产物 + 启动图 + 数据通道 ───────────────────────
|
|
478
|
+
/**
|
|
479
|
+
* 壳档的伺服面:第一次真起服务时造一次(没开远程就不造);经典档、或壳产物还
|
|
480
|
+
* 没构建时给 null(路由层退回经典资产)。数据通道的方法面是
|
|
481
|
+
* {@link REMOTE_SHELL_METHODS},实参过 `validateUiArgs`(与本地界面通道同一份规格)。
|
|
482
|
+
*/
|
|
483
|
+
let shellUiBuilt = undefined;
|
|
484
|
+
const shellUiOf = () => {
|
|
485
|
+
if (shellUiBuilt !== undefined)
|
|
486
|
+
return shellUiBuilt;
|
|
487
|
+
if (readUiMode(passed) === 'classic') {
|
|
488
|
+
shellUiBuilt = null;
|
|
489
|
+
return shellUiBuilt;
|
|
490
|
+
}
|
|
491
|
+
const assetsDir = uiAssetsDir();
|
|
492
|
+
if (!existsSync(join(assetsDir, 'index.html'))) {
|
|
493
|
+
ctx.emit('dsc/notice', `远程壳产物不存在(${join(assetsDir, 'index.html')}):手机端先按远程经典界面伺服;构建 ui-shell 后重启宿主即可切回`);
|
|
494
|
+
shellUiBuilt = null;
|
|
495
|
+
return shellUiBuilt;
|
|
496
|
+
}
|
|
497
|
+
const events = createUiEvents({
|
|
498
|
+
snapshot: () => ({ ...snapshot() }),
|
|
499
|
+
invoke: async (method, args) => {
|
|
500
|
+
if (!REMOTE_SHELL_SET.has(method))
|
|
501
|
+
throw new Error(`远程壳不开放这个方法:${method}`);
|
|
502
|
+
const checked = validateUiArgs(method, args);
|
|
503
|
+
if (!checked.ok)
|
|
504
|
+
throw new Error(checked.error);
|
|
505
|
+
return (await invoke(method, checked.args)) ?? null;
|
|
506
|
+
},
|
|
507
|
+
methods: REMOTE_SHELL_METHODS,
|
|
508
|
+
hello: () => ({
|
|
509
|
+
protocolVersion: UI_EVENTS_PROTOCOL_VERSION,
|
|
510
|
+
methods: [...REMOTE_SHELL_METHODS],
|
|
511
|
+
host: { name: 'Pneuma', version: DSC_VERSION },
|
|
512
|
+
}),
|
|
513
|
+
subscribe: (listener) => ctx.transcript.subscribe(listener),
|
|
514
|
+
log: (line) => ctx.logger.warn(line),
|
|
515
|
+
});
|
|
516
|
+
// 与本地界面服务同一份当前代快照(图 + 批 combo 一起换代);手机壳取的
|
|
517
|
+
// `/plugins/??…` 因此与图里的批地址严格同代。
|
|
518
|
+
//
|
|
519
|
+
// 远程这一侧**每次取向都强制重收**:手机端没有 HMR 推帧(SSE 只服务本地壳),
|
|
520
|
+
// 而「宿主重建插件后手机刷新能看到新界面」是壳档的既有承诺;带内容摘要的 rev
|
|
521
|
+
// 让强制重收也不会误换代(字节没变 combo/上一代都原地不动)。
|
|
522
|
+
const bootSource = createUiBootSource({
|
|
523
|
+
host: { name: 'Pneuma', version: DSC_VERSION },
|
|
524
|
+
builtinDir: uiPluginsDir(),
|
|
525
|
+
});
|
|
526
|
+
const freshGraph = () => {
|
|
527
|
+
bootSource.refresh();
|
|
528
|
+
return bootSource.graph();
|
|
529
|
+
};
|
|
530
|
+
shellUiBuilt = {
|
|
531
|
+
assetsDir,
|
|
532
|
+
boot: freshGraph,
|
|
533
|
+
combos: () => bootSource.combos(),
|
|
534
|
+
events,
|
|
535
|
+
authenticated: (req) => {
|
|
536
|
+
const token = bearerToken(req.headers.authorization) ?? readCookie(req.headers.cookie, REMOTE_COOKIE);
|
|
537
|
+
return token !== null && pairing.verifyToken(token) !== null;
|
|
538
|
+
},
|
|
539
|
+
};
|
|
540
|
+
return shellUiBuilt;
|
|
541
|
+
};
|
|
542
|
+
// 插件卸载时把通道停掉(SSE 连接断开、退订会话流)。
|
|
543
|
+
ctx.effect(() => () => {
|
|
544
|
+
shellUiBuilt?.events.stop();
|
|
545
|
+
}, 'remote: 停掉壳档数据通道');
|
|
546
|
+
// ── 推送:Web Push 与通知 Webhook 同一触发点同时发,互不影响 ─────────────
|
|
547
|
+
/** 同类推送 10 秒节流(键是触发类别:approval / turn-end)。 */
|
|
548
|
+
const lastNotifyAt = {};
|
|
549
|
+
/**
|
|
550
|
+
* 发一条通知(两条腿:浏览器推送 + Webhook)。
|
|
551
|
+
*
|
|
552
|
+
* 任何一条腿失败都只写一条 notice,绝不抛——推送发不出去不该影响宿主干活;
|
|
553
|
+
* 两条腿互相独立,Web Push 没开不影响 Webhook 照发,反之亦然。
|
|
554
|
+
*/
|
|
555
|
+
const notify = async (kind, message, throttle) => {
|
|
556
|
+
const outcome = { push: null, pushSkipped: null, webhook: null, webhookSkipped: null };
|
|
557
|
+
const prefs = ctx.settings.prefs().remote;
|
|
558
|
+
if (throttle) {
|
|
559
|
+
const now = Date.now();
|
|
560
|
+
const last = lastNotifyAt[kind] ?? 0;
|
|
561
|
+
if (now - last < NOTIFY_THROTTLE_MS) {
|
|
562
|
+
outcome.pushSkipped = '10 秒内已经发过同类推送';
|
|
563
|
+
outcome.webhookSkipped = outcome.pushSkipped;
|
|
564
|
+
return outcome;
|
|
565
|
+
}
|
|
566
|
+
lastNotifyAt[kind] = now;
|
|
567
|
+
}
|
|
568
|
+
if (prefs.push) {
|
|
569
|
+
try {
|
|
570
|
+
const result = await pushStore.send({ title: message.title, body: message.body, url: message.url });
|
|
571
|
+
outcome.push = result;
|
|
572
|
+
if (result.attempted > result.sent) {
|
|
573
|
+
const why = result.errors[0] ?? '订阅已失效,已从库里清掉';
|
|
574
|
+
ctx.emit('dsc/notice', `浏览器推送:${String(result.sent)}/${String(result.attempted)} 台成功,没发出去的原因:${why}`);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
catch (error) {
|
|
578
|
+
outcome.pushSkipped = errText(error);
|
|
579
|
+
ctx.emit('dsc/notice', `浏览器推送失败:${outcome.pushSkipped}`);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
outcome.pushSkipped = '浏览器推送没开';
|
|
584
|
+
}
|
|
585
|
+
const webhook = prefs.notifyWebhook.trim();
|
|
586
|
+
if (webhook !== '') {
|
|
587
|
+
const result = await sendWebhook(webhook, message);
|
|
588
|
+
outcome.webhook = result;
|
|
589
|
+
if (!result.ok)
|
|
590
|
+
ctx.emit('dsc/notice', `通知 Webhook 没发出去:${result.error}`);
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
outcome.webhookSkipped = '没配通知 Webhook';
|
|
594
|
+
}
|
|
595
|
+
return outcome;
|
|
596
|
+
};
|
|
597
|
+
// ── 推送触发:全在现有订阅与事件里,内核一条新事件都不用加 ───────────────
|
|
598
|
+
/** 上一帧「等人的卡」的键(判「从无到有 / 换了一张」;键 = 卡种:卡标识)。 */
|
|
599
|
+
let prevCardKey = null;
|
|
600
|
+
/** 上一帧的回合状态(判「一轮开始了」)。 */
|
|
601
|
+
let prevTurnState = 'idle';
|
|
602
|
+
/** 这一轮什么时候开始的(推送里要报「用时 Xs」,宿主没有 turn-start 事件,插件自己记)。 */
|
|
603
|
+
let turnStartedAt = 0;
|
|
604
|
+
/** 这一轮里出现过「等人」的卡没有(短轮也值得通报的第二条条件)。 */
|
|
605
|
+
let turnHadWaitingCard = false;
|
|
606
|
+
/** T45:升级提醒的计时器与计数(同一张卡挂久了再喊几声)。 */
|
|
607
|
+
let escalateTimer = null;
|
|
608
|
+
let escalateCount = 0;
|
|
609
|
+
/** 当前快照里「等人的卡」(审批 → 计划评审 → 模型提问,同一时刻至多一张在前面挡着)。 */
|
|
610
|
+
function waitingCardOf(current) {
|
|
611
|
+
const approval = current.surfaces.pendingApproval;
|
|
612
|
+
if (approval !== null)
|
|
613
|
+
return { key: `approval:${approval.id}`, title: 'Pneuma 等待审批', headline: approvalHeadline(approval) };
|
|
614
|
+
const plan = current.surfaces.pendingPlan;
|
|
615
|
+
if (plan !== null)
|
|
616
|
+
return { key: `plan:${plan.file}`, title: 'Pneuma 等待计划评审', headline: plan.title };
|
|
617
|
+
const question = current.surfaces.pendingQuestion;
|
|
618
|
+
if (question !== null) {
|
|
619
|
+
return { key: `ask:${question.id}`, title: 'Pneuma 在向你提问', headline: question.header ?? question.question };
|
|
620
|
+
}
|
|
621
|
+
return null;
|
|
622
|
+
}
|
|
623
|
+
const clearEscalation = () => {
|
|
624
|
+
if (escalateTimer !== null)
|
|
625
|
+
clearTimeout(escalateTimer);
|
|
626
|
+
escalateTimer = null;
|
|
627
|
+
escalateCount = 0;
|
|
628
|
+
};
|
|
629
|
+
/** T45:升级再提醒——2 分钟第一声,之后每 2 分钟一声,最多 {@link ESCALATE_MAX} 声。 */
|
|
630
|
+
function armEscalation(key, headline) {
|
|
631
|
+
clearEscalation();
|
|
632
|
+
escalateTimer = setTimeout(() => {
|
|
633
|
+
escalateCount += 1;
|
|
634
|
+
const still = waitingCardOf(runtime.getSnapshot());
|
|
635
|
+
if (still === null || still.key !== key || escalateCount > ESCALATE_MAX)
|
|
636
|
+
return;
|
|
637
|
+
void notify(`escalate:${key}`, { title: 'Pneuma 还在等人', body: `已等 ${String(Math.round((ESCALATE_WAIT_MS * escalateCount) / 1000))} 秒:${headline}`, url: addressText() }, false);
|
|
638
|
+
armEscalation(key, headline);
|
|
639
|
+
}, ESCALATE_WAIT_MS);
|
|
640
|
+
escalateTimer.unref();
|
|
641
|
+
}
|
|
642
|
+
/** 会话流一变就看一眼快照:等人的卡从无到有(或换了一张)→ 推送 + 挂升级提醒;回合从 idle 起来 → 记开始时刻。 */
|
|
643
|
+
const watchTransitions = () => {
|
|
644
|
+
const current = runtime.getSnapshot();
|
|
645
|
+
const state = current.status.turnState;
|
|
646
|
+
if (state !== 'idle' && prevTurnState === 'idle') {
|
|
647
|
+
turnStartedAt = Date.now();
|
|
648
|
+
turnHadWaitingCard = false;
|
|
649
|
+
}
|
|
650
|
+
prevTurnState = state;
|
|
651
|
+
const card = waitingCardOf(current);
|
|
652
|
+
if (card !== null && card.key !== prevCardKey) {
|
|
653
|
+
turnHadWaitingCard = true;
|
|
654
|
+
// T45:节流键带上卡片标识——10 秒内连来两张审批卡时,第二张不再被同一把
|
|
655
|
+
// 「approval」节流吞掉;同一条卡重复的快照刷新仍然只推一声。
|
|
656
|
+
void notify(card.key, { title: card.title, body: card.headline, url: addressText() }, true);
|
|
657
|
+
armEscalation(card.key, card.headline);
|
|
658
|
+
}
|
|
659
|
+
else if (card === null && prevCardKey !== null) {
|
|
660
|
+
clearEscalation();
|
|
661
|
+
}
|
|
662
|
+
prevCardKey = card?.key ?? null;
|
|
663
|
+
};
|
|
664
|
+
const offTransitions = ctx.transcript.subscribe(watchTransitions);
|
|
665
|
+
/** 一轮结束:用过 15 秒以上、或者这一轮出现过等人的卡,才值得推一条。 */
|
|
666
|
+
const onTurnEnd = () => {
|
|
667
|
+
const elapsedMs = turnStartedAt === 0 ? 0 : Date.now() - turnStartedAt;
|
|
668
|
+
const hadWaitingCard = turnHadWaitingCard;
|
|
669
|
+
turnStartedAt = 0;
|
|
670
|
+
turnHadWaitingCard = false;
|
|
671
|
+
if (elapsedMs < TURN_NOTIFY_MIN_MS && !hadWaitingCard)
|
|
672
|
+
return;
|
|
673
|
+
const seconds = Math.max(0, Math.round(elapsedMs / 1000));
|
|
674
|
+
void notify('turn-end', { title: 'Pneuma 轮完成', body: `用时 ${String(seconds)}s`, url: addressText() }, true);
|
|
675
|
+
};
|
|
676
|
+
ctx.on('dsc/turn-end', onTurnEnd);
|
|
677
|
+
const stopServer = () => {
|
|
678
|
+
const instance = server;
|
|
679
|
+
server = null;
|
|
680
|
+
instance?.close();
|
|
681
|
+
};
|
|
682
|
+
const startServer = (prefs) => {
|
|
683
|
+
if (!owner.tryAcquire(prefs.port)) {
|
|
684
|
+
const info = owner.peek();
|
|
685
|
+
// 启动提示只展示一次(0.6.64):接管方 pid 没变就不重复说(重试周期里
|
|
686
|
+
// reportProblem 自己的 lastProblem 节流也只覆盖本进程)。
|
|
687
|
+
const standby = `远程控制由另一个 Pneuma 进程(pid ${String(info?.pid ?? 0)})接管,本进程待命`;
|
|
688
|
+
if (bootNoticeOnce('remote.standby', standby))
|
|
689
|
+
reportProblem(standby);
|
|
690
|
+
armRetry();
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
const instance = createRemoteServer({
|
|
694
|
+
port: prefs.port,
|
|
695
|
+
lan: prefs.lan,
|
|
696
|
+
throttleMs,
|
|
697
|
+
assetsDir: readAssetsDir(passed),
|
|
698
|
+
pairing,
|
|
699
|
+
tickets,
|
|
700
|
+
uploads,
|
|
701
|
+
invoke,
|
|
702
|
+
snapshot,
|
|
703
|
+
subscribe: (listener) => ctx.transcript.subscribe(listener),
|
|
704
|
+
notice: (text) => ctx.emit('dsc/notice', text),
|
|
705
|
+
pushEnabled: () => ctx.settings.prefs().remote.push,
|
|
706
|
+
pushPublicKey,
|
|
707
|
+
pushSubscribe: (payload, deviceId) => pushStore.add(payload, deviceId),
|
|
708
|
+
pushUnsubscribe: (endpoint) => pushStore.remove(endpoint),
|
|
709
|
+
shellUi: shellUiOf(),
|
|
710
|
+
});
|
|
711
|
+
server = instance;
|
|
712
|
+
instance.ready.then(() => {
|
|
713
|
+
lastProblem = null;
|
|
714
|
+
}, (error) => {
|
|
715
|
+
if (server === instance)
|
|
716
|
+
server = null;
|
|
717
|
+
instance.close();
|
|
718
|
+
owner.release();
|
|
719
|
+
reportProblem(`远程控制起不来(端口 ${String(prefs.port)}):${errText(error)};${String(OWNER_RETRY_MS / 1000)} 秒后重试`);
|
|
720
|
+
armRetry();
|
|
721
|
+
});
|
|
722
|
+
};
|
|
723
|
+
/**
|
|
724
|
+
* 按当前偏好把服务调到该有的样子。三条路都会走到这里:插件挂载、偏好写盘(设置页改了
|
|
725
|
+
* 开关/端口/绑定)、30 秒重试到点。它是幂等的:该停的停、该起的起、配置没变就什么都不做。
|
|
726
|
+
*/
|
|
727
|
+
function applyPrefs() {
|
|
728
|
+
const prefs = ctx.settings.prefs().remote;
|
|
729
|
+
if (!prefs.enabled) {
|
|
730
|
+
if (server !== null) {
|
|
731
|
+
stopServer();
|
|
732
|
+
ctx.emit('dsc/notice', '远程控制已关闭,已连接的设备已断开');
|
|
733
|
+
}
|
|
734
|
+
// 主控位无条件让出:服务没起来但锁已经抢到过(端口被别的程序占着之类),
|
|
735
|
+
// 关开关时也该把这个位子交出去;release 只删自己那份文件,别人的不碰。
|
|
736
|
+
owner.release();
|
|
737
|
+
clearRetry();
|
|
738
|
+
lastProblem = null;
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
if (server !== null) {
|
|
742
|
+
if (server.port === prefs.port && server.lan === prefs.lan)
|
|
743
|
+
return;
|
|
744
|
+
// 端口或绑定范围改了:停掉旧的,下面按新配置重起(主控位里的端口也跟着刷新)
|
|
745
|
+
stopServer();
|
|
746
|
+
}
|
|
747
|
+
if (yielded)
|
|
748
|
+
return;
|
|
749
|
+
startServer(prefs);
|
|
750
|
+
}
|
|
751
|
+
// ── 设置分区 ──────────────────────────────────────────────────────────────
|
|
752
|
+
const statusText = () => {
|
|
753
|
+
const prefs = ctx.settings.prefs().remote;
|
|
754
|
+
if (!prefs.enabled)
|
|
755
|
+
return '已关闭';
|
|
756
|
+
if (server !== null) {
|
|
757
|
+
return `运行中 · ${server.lan ? '0.0.0.0' : '127.0.0.1'}:${String(server.port)}`;
|
|
758
|
+
}
|
|
759
|
+
const info = owner.peek();
|
|
760
|
+
if (info !== null && info.pid !== process.pid) {
|
|
761
|
+
return `由另一个 Pneuma 进程(pid ${String(info.pid)})接管`;
|
|
762
|
+
}
|
|
763
|
+
return yielded ? '已让出主控位,重新开关「开启远程控制」拿回' : '等待主控位空出(每 30 秒重试)';
|
|
764
|
+
};
|
|
765
|
+
/** 时间戳给设置页看的样子;0(没记过)说「未知」。 */
|
|
766
|
+
const timeText = (at) => (at > 0 ? new Date(at).toLocaleString('zh-CN') : '未知');
|
|
767
|
+
const pushStatusText = () => {
|
|
768
|
+
const prefs = ctx.settings.prefs().remote;
|
|
769
|
+
if (!prefs.push)
|
|
770
|
+
return '没开';
|
|
771
|
+
const key = pushPublicKey();
|
|
772
|
+
return key === null ? '开着,但 VAPID 密钥不可用' : `开着,已订阅 ${String(pushStore.count())} 台`;
|
|
773
|
+
};
|
|
774
|
+
const webhookStatusText = () => {
|
|
775
|
+
const raw = ctx.settings.prefs().remote.notifyWebhook.trim();
|
|
776
|
+
if (raw === '')
|
|
777
|
+
return '没配';
|
|
778
|
+
return raw.includes('{') && webhookHasPlaceholder(raw) ? `${raw}(GET)` : `${raw}(POST JSON)`;
|
|
779
|
+
};
|
|
780
|
+
const section = {
|
|
781
|
+
id: 'remote',
|
|
782
|
+
title: '远程控制',
|
|
783
|
+
subtitle: '把会话开给同一局域网里的手机浏览器',
|
|
784
|
+
order: 40,
|
|
785
|
+
fields() {
|
|
786
|
+
const prefs = ctx.settings.prefs().remote;
|
|
787
|
+
const devices = pairing.devices();
|
|
788
|
+
const rows = [
|
|
789
|
+
{
|
|
790
|
+
type: 'switch',
|
|
791
|
+
key: 'enabled',
|
|
792
|
+
label: '开启远程控制',
|
|
793
|
+
help: '打开后监听端口等待手机接入;关闭立即断开所有连接',
|
|
794
|
+
},
|
|
795
|
+
{
|
|
796
|
+
type: 'number',
|
|
797
|
+
key: 'port',
|
|
798
|
+
label: '监听端口',
|
|
799
|
+
min: REMOTE_PORT_MIN,
|
|
800
|
+
max: REMOTE_PORT_MAX,
|
|
801
|
+
help: '改端口会重启监听,已配对的设备不受影响',
|
|
802
|
+
},
|
|
803
|
+
{
|
|
804
|
+
type: 'switch',
|
|
805
|
+
key: 'lan',
|
|
806
|
+
label: '允许局域网访问',
|
|
807
|
+
help: '打开后同一 Wi-Fi 下的手机可以连入;关闭仅本机可用',
|
|
808
|
+
},
|
|
809
|
+
{ type: 'info', label: '运行状态', text: statusText() },
|
|
810
|
+
{ type: 'info', label: '访问地址', text: addressText(), mono: true, copyable: true },
|
|
811
|
+
{
|
|
812
|
+
type: 'switch',
|
|
813
|
+
key: 'push',
|
|
814
|
+
label: '浏览器推送(Web Push)',
|
|
815
|
+
help: '手机先把本页「添加到主屏幕」,才能收到系统通知;关闭时不订阅、不推送',
|
|
816
|
+
},
|
|
817
|
+
{ type: 'info', label: '推送状态', text: pushStatusText() },
|
|
818
|
+
{
|
|
819
|
+
type: 'text',
|
|
820
|
+
key: 'notifyWebhook',
|
|
821
|
+
label: '通知 Webhook',
|
|
822
|
+
placeholder: 'https://api.day.app/你的KEY/{title}/{body}',
|
|
823
|
+
help: '留空 = 关。带 {title}/{body}/{url} 占位符的地址按 GET 发(Bark),不带的按 POST JSON 发(ntfy)',
|
|
824
|
+
},
|
|
825
|
+
{ type: 'info', label: 'Webhook 状态', text: webhookStatusText(), mono: true },
|
|
826
|
+
{
|
|
827
|
+
type: 'button',
|
|
828
|
+
action: 'test-push',
|
|
829
|
+
label: '发送测试推送',
|
|
830
|
+
style: 'primary',
|
|
831
|
+
help: '浏览器推送与 Webhook 各发一条,结果以右下角通知弹出',
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
type: 'info',
|
|
835
|
+
label: '已配对设备',
|
|
836
|
+
text: devices.length === 0 ? '还没有设备' : `${String(devices.length)} 台:${devices.map((item) => item.name).join('、')}`,
|
|
837
|
+
},
|
|
838
|
+
];
|
|
839
|
+
// 每台设备两行:一行身份(名字 + 最近活跃 + 创建时间),一行「吊销」按钮。
|
|
840
|
+
// fields() 是每次刷新都重新调的,所以吊销完下一刷就少一台,不用自己再通知界面。
|
|
841
|
+
for (const device of devices) {
|
|
842
|
+
rows.push({
|
|
843
|
+
type: 'info',
|
|
844
|
+
label: device.name,
|
|
845
|
+
text: `最近活跃 ${timeText(device.lastSeenAt)}`,
|
|
846
|
+
});
|
|
847
|
+
rows.push({
|
|
848
|
+
type: 'button',
|
|
849
|
+
action: `revoke-device:${device.deviceId}`,
|
|
850
|
+
label: '吊销',
|
|
851
|
+
style: 'ghost',
|
|
852
|
+
help: `断开「${device.name}」的连接并作废它的凭据,重新配对后才能连回`,
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
rows.push({
|
|
856
|
+
type: 'button',
|
|
857
|
+
action: 'regenerate-code',
|
|
858
|
+
label: '连接手机',
|
|
859
|
+
style: 'primary',
|
|
860
|
+
help: '打开连接弹窗,手机扫码或输码即可配对;配对码半小时内有效',
|
|
861
|
+
}, { type: 'button', action: 'revoke-all', label: '吊销全部设备', style: 'ghost', help: '所有手机立刻失效,需要重新配对' }, {
|
|
862
|
+
type: 'button',
|
|
863
|
+
action: 'release-owner',
|
|
864
|
+
label: '退出主控',
|
|
865
|
+
style: 'ghost',
|
|
866
|
+
help: '多开时把监听让给别的 Pneuma 进程,重新开关远程控制可拿回来',
|
|
867
|
+
});
|
|
868
|
+
return rows;
|
|
869
|
+
},
|
|
870
|
+
values() {
|
|
871
|
+
const prefs = ctx.settings.prefs().remote;
|
|
872
|
+
return {
|
|
873
|
+
enabled: prefs.enabled,
|
|
874
|
+
port: prefs.port,
|
|
875
|
+
lan: prefs.lan,
|
|
876
|
+
push: prefs.push,
|
|
877
|
+
notifyWebhook: prefs.notifyWebhook,
|
|
878
|
+
};
|
|
879
|
+
},
|
|
880
|
+
save(key, value) {
|
|
881
|
+
const prefs = ctx.settings.prefs().remote;
|
|
882
|
+
if (key === 'enabled') {
|
|
883
|
+
// 重新打开 = 明确要抢回主控位,「退出主控」那道抑制就此解除
|
|
884
|
+
if (value === true)
|
|
885
|
+
yielded = false;
|
|
886
|
+
ctx.settings.setPrefs({ remote: { ...prefs, enabled: value === true } });
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
if (key === 'port') {
|
|
890
|
+
const port = Math.round(Number(value));
|
|
891
|
+
if (!Number.isFinite(port) || port < REMOTE_PORT_MIN || port > REMOTE_PORT_MAX) {
|
|
892
|
+
throw new Error(`端口要填 ${String(REMOTE_PORT_MIN)} 到 ${String(REMOTE_PORT_MAX)} 之间的数字`);
|
|
893
|
+
}
|
|
894
|
+
ctx.settings.setPrefs({ remote: { ...prefs, port } });
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
if (key === 'lan') {
|
|
898
|
+
ctx.settings.setPrefs({ remote: { ...prefs, lan: value === true } });
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
if (key === 'push') {
|
|
902
|
+
ctx.settings.setPrefs({ remote: { ...prefs, push: value === true } });
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
if (key === 'notifyWebhook') {
|
|
906
|
+
const raw = String(value ?? '').trim();
|
|
907
|
+
if (raw !== '' && !isHttpUrl(raw)) {
|
|
908
|
+
throw new Error('通知 Webhook 要填 http:// 或 https:// 开头的地址;留空 = 关掉');
|
|
909
|
+
}
|
|
910
|
+
ctx.settings.setPrefs({ remote: { ...prefs, notifyWebhook: raw } });
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
throw new Error(`未知的设置项 ${key}`);
|
|
914
|
+
},
|
|
915
|
+
async action(name) {
|
|
916
|
+
if (name === 'regenerate-code') {
|
|
917
|
+
// replace:每次点「连接手机」(以及弹窗里的「重新生成」)都换一张新码,旧码当场作废。
|
|
918
|
+
// 为什么要作废而不是复用:明文码不落盘,旧码的明文只在上一张弹窗上,宿主重画不出来;
|
|
919
|
+
// 而这张弹窗本来就该「一直看得见一张有效码」,所以只能换新的(界面上的 help 写明了这点)。
|
|
920
|
+
const issued = pairing.issueCode({ replace: true });
|
|
921
|
+
if (issued === null) {
|
|
922
|
+
// 理论到不了这里(replace 一定发得出来),留着当兜底
|
|
923
|
+
return '配对码签发失败,请稍后重试';
|
|
924
|
+
}
|
|
925
|
+
// 码只从这里出去(桌面的「连接手机」弹窗):绝不写进 transcript,会话 jsonl 是会被翻出来的。
|
|
926
|
+
// 所以 notice 只说「生成了、半小时内有效」,码本体与可扫地址放 data,由界面画在弹窗里。
|
|
927
|
+
// addressText() 已经给的是带协议的完整地址(末尾一个斜杠),直接接查询串即可。
|
|
928
|
+
return {
|
|
929
|
+
notice: '配对码已生成(半小时内有效)',
|
|
930
|
+
data: {
|
|
931
|
+
kind: 'pair-code',
|
|
932
|
+
code: issued.code,
|
|
933
|
+
url: `${addressText()}?code=${issued.code}`,
|
|
934
|
+
expiresAt: issued.expiresAt,
|
|
935
|
+
},
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
if (name === 'revoke-all') {
|
|
939
|
+
const count = pairing.revokeAll();
|
|
940
|
+
// 已经在线的手机当场断线,不是等它们下次重连才发现凭据没了
|
|
941
|
+
server?.closeDevices();
|
|
942
|
+
return count === 0 ? '本来就没有已经配对的设备' : `已吊销 ${String(count)} 台设备,手机需要重新配对`;
|
|
943
|
+
}
|
|
944
|
+
if (name.startsWith('revoke-device:')) {
|
|
945
|
+
const deviceId = name.slice('revoke-device:'.length);
|
|
946
|
+
const revoked = pairing.revokeDevice(deviceId);
|
|
947
|
+
if (revoked === null)
|
|
948
|
+
return '这台设备已经不在了(可能刚被别的地方吊销掉)';
|
|
949
|
+
const closed = server?.closeDevices(deviceId) ?? 0;
|
|
950
|
+
return `已吊销「${revoked.name}」${closed > 0 ? `,断开 ${String(closed)} 条连接` : ''}`;
|
|
951
|
+
}
|
|
952
|
+
if (name === 'test-push') {
|
|
953
|
+
const prefs = ctx.settings.prefs().remote;
|
|
954
|
+
const message = {
|
|
955
|
+
title: 'Pneuma 测试推送',
|
|
956
|
+
body: '这条消息来自电脑上「设置 → 远程控制」的测试按钮',
|
|
957
|
+
url: addressText(),
|
|
958
|
+
};
|
|
959
|
+
const lines = [];
|
|
960
|
+
if (prefs.push) {
|
|
961
|
+
try {
|
|
962
|
+
const result = await pushStore.send({ ...message });
|
|
963
|
+
if (result.attempted === 0)
|
|
964
|
+
lines.push('浏览器推送:库里还没有订阅的设备(手机要先把页面加到主屏幕)');
|
|
965
|
+
else {
|
|
966
|
+
lines.push(`浏览器推送:${String(result.sent)}/${String(result.attempted)} 台成功` +
|
|
967
|
+
(result.dropped > 0 ? `,${String(result.dropped)} 台订阅已失效(已清理)` : '') +
|
|
968
|
+
(result.errors.length > 0 ? `,失败原因:${result.errors.join(';')}` : ''));
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
catch (error) {
|
|
972
|
+
lines.push(`浏览器推送:失败(${errText(error)})`);
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
else {
|
|
976
|
+
lines.push('浏览器推送:没开(开关关着,一条都没发)');
|
|
977
|
+
}
|
|
978
|
+
const webhook = prefs.notifyWebhook.trim();
|
|
979
|
+
if (webhook === '') {
|
|
980
|
+
lines.push('通知 Webhook:没配(留空 = 关)');
|
|
981
|
+
}
|
|
982
|
+
else {
|
|
983
|
+
const result = await sendWebhook(webhook, message);
|
|
984
|
+
lines.push(result.ok
|
|
985
|
+
? `通知 Webhook:已发送(${result.mode === 'get' ? 'GET' : 'POST JSON'})`
|
|
986
|
+
: `通知 Webhook:失败(${result.error})`);
|
|
987
|
+
}
|
|
988
|
+
return lines.join(';');
|
|
989
|
+
}
|
|
990
|
+
if (name === 'release-owner') {
|
|
991
|
+
yielded = true;
|
|
992
|
+
clearRetry();
|
|
993
|
+
stopServer();
|
|
994
|
+
owner.release();
|
|
995
|
+
return '已让出主控位;重新开关「开启远程控制」可拿回来';
|
|
996
|
+
}
|
|
997
|
+
throw new Error(`这个分区没有动作 ${name}`);
|
|
998
|
+
},
|
|
999
|
+
};
|
|
1000
|
+
// 远程控制是内核级功能:桌面端设置页只列 builtin 分区,这里声明 inSettings
|
|
1001
|
+
// 让它进设置页(插件中心那张卡照旧不放它,避免同一处配置两个入口)。
|
|
1002
|
+
const offSection = ctx.settings.registerSection(section, { inSettings: true });
|
|
1003
|
+
// 设置页改开关 / 改端口都走 settings.setPrefs,写盘那一刻就会回调到这里
|
|
1004
|
+
const offPrefs = ctx.settings.watchPrefs(() => {
|
|
1005
|
+
applyPrefs();
|
|
1006
|
+
});
|
|
1007
|
+
// 宿主请求打开会话选择面板:转给手机上那张界面(批 B 会切到会话列表页)
|
|
1008
|
+
ctx.on('dsc/open-picker', () => {
|
|
1009
|
+
server?.broadcast({ type: 'ui', method: 'open-picker' });
|
|
1010
|
+
});
|
|
1011
|
+
// 进程退出钩子尽力而为:exit 里只能跑同步代码,release 正好是同步的(unlink 一下)
|
|
1012
|
+
const onProcessExit = () => {
|
|
1013
|
+
owner.release();
|
|
1014
|
+
};
|
|
1015
|
+
process.once('exit', onProcessExit);
|
|
1016
|
+
ctx.on('dsc/exit', () => {
|
|
1017
|
+
process.removeListener('exit', onProcessExit);
|
|
1018
|
+
offSection();
|
|
1019
|
+
offPrefs();
|
|
1020
|
+
offTransitions();
|
|
1021
|
+
clearEscalation();
|
|
1022
|
+
clearRetry();
|
|
1023
|
+
stopServer();
|
|
1024
|
+
owner.release();
|
|
1025
|
+
});
|
|
1026
|
+
applyPrefs();
|
|
1027
|
+
},
|
|
1028
|
+
};
|