dsh-builtin-browser 0.5.8 → 1.0.1
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 +410 -1
- package/README.en.md +16 -64
- package/README.md +33 -64
- package/assets/browser-carriers.svg +20 -0
- package/assets/browser-extension-identity.d.mts +2 -0
- package/assets/browser-extension-identity.mjs +2 -0
- package/assets/browser-messages.d.mts +5 -0
- package/assets/browser-messages.mjs +64 -0
- package/assets/browser-panel-locales.d.mts +2 -0
- package/assets/browser-panel-locales.mjs +380 -0
- package/assets/browser-policy.d.mts +37 -0
- package/assets/browser-policy.mjs +37 -0
- package/assets/browser-products.d.mts +6 -0
- package/assets/browser-products.mjs +76 -0
- package/assets/screenshots/1-main.png +0 -0
- package/assets/screenshots/2-form-fill.png +0 -0
- package/assets/screenshots/3-challenge.png +0 -0
- package/browser-extension/constants.mjs +20 -0
- package/browser-extension/controller.mjs +293 -0
- package/browser-extension/locales.mjs +15 -0
- package/browser-extension/manifest.json +12 -0
- package/browser-extension/options.html +14 -0
- package/browser-extension/options.mjs +9 -0
- package/browser-extension/permission-guard.mjs +13 -0
- package/browser-extension/worker.mjs +74 -0
- package/cordis.patch.yml +23 -48
- package/desktop-bridge/desktop-discovery.d.mts +2 -0
- package/desktop-bridge/desktop-discovery.mjs +36 -0
- package/desktop-bridge/desktop-identity.json +17 -1
- package/desktop-bridge/desktop-processes.d.mts +1 -0
- package/desktop-bridge/desktop-processes.mjs +15 -0
- package/desktop-bridge/guest-proxy.mjs +109 -0
- package/desktop-bridge/install.mjs +197 -74
- package/desktop-bridge/main.mjs +11 -0
- package/desktop-bridge/maintenance-files.d.mts +8 -0
- package/desktop-bridge/maintenance-files.mjs +28 -0
- package/desktop-bridge/maintenance-progress.ps1 +2 -2
- package/desktop-bridge/native-guests.mjs +41 -0
- package/desktop-bridge/plugin-browser-bridge.js +618 -370
- package/desktop-bridge/profile-loader.mjs +26 -0
- package/dist/client.cjs +43167 -0
- package/dist/client.d.cts +516 -0
- package/dist/client.d.mts +516 -0
- package/dist/index.cjs +92 -0
- package/dist/index.d.mts +2960 -0
- package/dist/index.mjs +24 -0
- package/docs/HANDOVER-2026-11-15.md +178 -0
- package/docs/README.md +10 -19
- package/docs/architecture.md +17 -145
- package/docs/child-tabs.md +13 -0
- package/docs/desktop-acceptance.md +9 -0
- package/docs/development.md +88 -18
- package/docs/extension-browser.md +44 -0
- package/docs/hardcoding-audit.md +64 -0
- package/docs/limitations.md +23 -73
- package/docs/pr64-extension-status.md +46 -0
- package/docs/pr64-maintenance.md +25 -0
- package/docs/pr64-native-children.md +52 -0
- package/docs/pr64-native-views.md +60 -0
- package/docs/tool-reference.md +87 -11
- package/docs/user-guide.md +47 -255
- package/docs/why-browser.md +6 -39
- package/dsh-host-patch/README.md +60 -0
- package/dsh-host-patch/apply.mjs +194 -0
- package/dsh-host-patch/legacy-bridge.mjs +53 -0
- package/dsh-host-patch/rc3-revision1.json +90 -0
- package/dsh-host-patch/rc3-revision2.json +112 -0
- package/dsh-host-patch/rc3-revision3.json.gz +0 -0
- package/dsh-host-patch/rc3-revision4.json.gz +0 -0
- package/dsh-host-patch/rc3-revision5.json.gz +0 -0
- package/dsh-host-patch/rc3-revision6.json.gz +0 -0
- package/dsh-host-patch/rc3-revision7.json.gz +0 -0
- package/dsh-host-patch/rc3-revision8.json.gz +0 -0
- package/dsh-host-patch/rc3.json +148 -0
- package/dsh-host-patch/rc5-revision1.json +90 -0
- package/dsh-host-patch/rc5-revision2.json +112 -0
- package/dsh-host-patch/rc5-revision3.json.gz +0 -0
- package/dsh-host-patch/rc5-revision4.json.gz +0 -0
- package/dsh-host-patch/rc5-revision5.json.gz +0 -0
- package/dsh-host-patch/rc5-revision6.json.gz +0 -0
- package/dsh-host-patch/rc5-revision7.json.gz +0 -0
- package/dsh-host-patch/rc5-revision8.json.gz +0 -0
- package/dsh-host-patch/rc5.json +148 -0
- package/lib/bridge-compatibility.js +38 -0
- package/lib/browser/handles.js +78 -0
- package/lib/browser/runtime.js +155 -43
- package/lib/browser/takeover-target.js +24 -0
- package/lib/browser-electron/authenticated-route.js +23 -0
- package/lib/browser-electron/automatic-maintenance.js +394 -51
- package/lib/browser-electron/bridge-auto.js +2 -1
- package/lib/browser-electron/bridge-connection.js +8 -1
- package/lib/browser-electron/bridge-install.js +27 -2
- package/lib/browser-electron/bridge-maintenance.js +35 -10
- package/lib/browser-electron/bridge-status.js +98 -27
- package/lib/browser-electron/desktop-bridge-host.js +193 -560
- package/lib/browser-electron/desktop-identity.js +40 -2
- package/lib/browser-electron/document-readiness.js +34 -0
- package/lib/browser-electron/electron-provision.js +14 -44
- package/lib/browser-electron/entry.js +659 -252
- package/lib/browser-electron/extension-browser.js +234 -0
- package/lib/browser-electron/extension-setup.js +69 -0
- package/lib/browser-electron/guest-cookie-jar.LICENSE.txt +32 -0
- package/lib/browser-electron/guest-cookie-jar.js +10559 -0
- package/lib/browser-electron/guest-cookie-store.js +74 -0
- package/lib/browser-electron/guest-css-runtime.js +75 -0
- package/lib/browser-electron/guest-css.js +106 -0
- package/lib/browser-electron/guest-route.js +603 -0
- package/lib/browser-electron/guest-runtime.js +356 -0
- package/lib/browser-electron/guest-storage-runtime.js +52 -0
- package/lib/browser-electron/guest-storage.js +163 -0
- package/lib/browser-electron/history-store.js +2 -1
- package/lib/browser-electron/host-main.js +162 -7
- package/lib/browser-electron/host-patch-maintenance.js +141 -0
- package/lib/browser-electron/http-body.js +22 -0
- package/lib/browser-electron/maintenance-broker.js +35 -5
- package/lib/browser-electron/maintenance-lifecycle.js +7 -5
- package/lib/browser-electron/maintenance-route.js +9 -6
- package/lib/browser-electron/open-slot.js +47 -0
- package/lib/browser-electron/paths.js +4 -1
- package/lib/browser-electron/preferred-browser.js +144 -0
- package/lib/browser-electron/preview-route.js +11 -8
- package/lib/browser-electron/process-ownership.js +198 -0
- package/lib/browser-electron/profile-checkpoint.js +222 -0
- package/lib/browser-electron/profile-command.js +60 -0
- package/lib/browser-electron/profile-extension.js +126 -0
- package/lib/browser-electron/profile-lease.js +157 -0
- package/lib/browser-electron/profile-residue.js +61 -0
- package/lib/browser-electron/provider.js +719 -262
- package/lib/browser-electron/reference-route.js +635 -0
- package/lib/browser-electron/remote-host.js +12 -13
- package/lib/browser-electron/runtime-route.js +6 -5
- package/lib/browser-electron/runtime-status.js +30 -29
- package/lib/browser-electron/settings-store.js +10 -5
- package/lib/browser-electron/shortcuts-route.js +108 -0
- package/lib/browser-electron/sidebar-only-host.js +119 -18
- package/lib/browser-electron/startpage-shortcuts.js +172 -0
- package/lib/browser-electron/system-browser.js +352 -371
- package/lib/browser-electron/windows-system.js +2 -1
- package/lib/browser-reference/delivery.js +326 -0
- package/lib/browser-reference/entry.js +597 -0
- package/lib/browser-reference/export.js +298 -0
- package/lib/browser-reference/import.js +295 -0
- package/lib/browser-reference/page-script.js +1406 -0
- package/lib/browser-reference/service.js +1062 -0
- package/lib/browser-reference/store.js +177 -0
- package/lib/browser-reference/submission-receipts.js +139 -0
- package/lib/browser-reference/text-quote.js +167 -0
- package/lib/browser-reference/types.js +11 -0
- package/lib/browser-reference/visible.js +311 -0
- package/lib/browser-reference/web-sources.js +97 -0
- package/lib/index.js +10 -3
- package/lib/reference-owner.js +5 -0
- package/lib/reference-page.js +12 -0
- package/lib/reference-source.js +2 -0
- package/lib/reference-text.js +188 -0
- package/lib/startpage-settings.js +63 -0
- package/lib/startpage.js +44 -0
- package/lib/takeover-protocol.js +2 -0
- package/lib/tool-browser/code-tool.js +416 -0
- package/lib/tool-browser/code-worker.js +872 -0
- package/lib/tool-browser/index.js +940 -76
- package/lib/tool-browser/page-probe.js +3 -3
- package/lib/tool-browser/panel-page.js +95 -0
- package/lib/tool-browser/screenshot-image.js +51 -0
- package/lib/tool-browser/takeover.js +205 -0
- package/lib/types.js +1 -0
- package/lib/web-guest.js +26 -0
- package/native-host/client.d.mts +17 -0
- package/native-host/client.mjs +100 -0
- package/native-host/host.mjs +150 -0
- package/native-host/identity.d.mts +2 -0
- package/native-host/identity.mjs +1 -0
- package/native-host/install.mjs +168 -0
- package/native-host/protocol.mjs +75 -0
- package/package.json +80 -92
- package/scripts/build.mjs +66 -0
- package/scripts/bundle-host.mjs +28 -0
- package/scripts/fix-exports.mjs +50 -0
- package/scripts/install-electron.mjs +11 -26
- package/scripts/verify-exports.mjs +47 -0
- package/scripts/verify-preview-sdk.mjs +93 -0
- package/skills/dsh-builtin-browser/SKILL.md +56 -47
- package/skills/dsh-builtin-browser/references/batch.md +31 -1
- package/skills/dsh-debug-host/SKILL.md +56 -0
- package/skills/dsh-debug-self/SKILL.md +50 -0
- package/src/bridge-compatibility.ts +39 -0
- package/src/browser/handles.ts +89 -0
- package/src/browser/runtime.ts +146 -50
- package/src/browser/takeover-target.ts +36 -0
- package/src/browser/types.ts +19 -7
- package/src/browser-electron/authenticated-route.ts +29 -1
- package/src/browser-electron/automatic-maintenance.ts +368 -56
- package/src/browser-electron/bridge-auto.ts +5 -4
- package/src/browser-electron/bridge-connection.ts +20 -2
- package/src/browser-electron/bridge-endpoint.ts +3 -3
- package/src/browser-electron/bridge-install.ts +40 -4
- package/src/browser-electron/bridge-maintenance.ts +42 -14
- package/src/browser-electron/bridge-status.ts +94 -23
- package/src/browser-electron/desktop-bridge-host.ts +185 -585
- package/src/browser-electron/desktop-identity.ts +53 -2
- package/src/browser-electron/document-readiness.ts +45 -0
- package/src/browser-electron/electron-provision.ts +12 -45
- package/src/browser-electron/entry.ts +1299 -882
- package/src/browser-electron/ephemeral-profile.ts +1 -1
- package/src/browser-electron/extension-browser.ts +223 -0
- package/src/browser-electron/extension-setup.ts +67 -0
- package/src/browser-electron/guest-cookie-jar.ts +176 -0
- package/src/browser-electron/guest-cookie-store.ts +59 -0
- package/src/browser-electron/guest-css-runtime.ts +76 -0
- package/src/browser-electron/guest-css.ts +68 -0
- package/src/browser-electron/guest-route.ts +568 -0
- package/src/browser-electron/guest-runtime.ts +357 -0
- package/src/browser-electron/guest-storage-runtime.ts +54 -0
- package/src/browser-electron/guest-storage.ts +117 -0
- package/src/browser-electron/history-store.ts +5 -4
- package/src/browser-electron/host-main.ts +156 -11
- package/src/browser-electron/host-patch-maintenance.ts +112 -0
- package/src/browser-electron/http-body.ts +23 -0
- package/src/browser-electron/maintenance-broker.ts +29 -5
- package/src/browser-electron/maintenance-lifecycle.ts +14 -9
- package/src/browser-electron/maintenance-route.ts +17 -14
- package/src/browser-electron/missing-system-browser.ts +2 -2
- package/src/browser-electron/open-slot.ts +49 -0
- package/src/browser-electron/paths.ts +5 -1
- package/src/browser-electron/preferred-browser.ts +120 -0
- package/src/browser-electron/preview-route.ts +18 -11
- package/src/browser-electron/process-ownership.ts +168 -0
- package/src/browser-electron/profile-checkpoint.ts +187 -0
- package/src/browser-electron/profile-command.ts +46 -0
- package/src/browser-electron/profile-extension.ts +124 -0
- package/src/browser-electron/profile-lease.ts +115 -0
- package/src/browser-electron/profile-residue.ts +49 -0
- package/src/browser-electron/provider.ts +771 -289
- package/src/browser-electron/reference-route.ts +608 -0
- package/src/browser-electron/remote-host.ts +15 -15
- package/src/browser-electron/runtime-route.ts +11 -10
- package/src/browser-electron/runtime-status.ts +51 -32
- package/src/browser-electron/settings-store.ts +27 -7
- package/src/browser-electron/shortcuts-route.ts +112 -0
- package/src/browser-electron/sidebar-only-host.ts +118 -19
- package/src/browser-electron/startpage-shortcuts.ts +213 -0
- package/src/browser-electron/system-browser.ts +309 -338
- package/src/browser-electron/windows-system.ts +2 -1
- package/src/browser-reference/delivery.ts +384 -0
- package/src/browser-reference/entry.ts +631 -0
- package/src/browser-reference/export.ts +339 -0
- package/src/browser-reference/import.ts +303 -0
- package/src/browser-reference/page-script.ts +1537 -0
- package/src/browser-reference/service.ts +1315 -0
- package/src/browser-reference/store.ts +172 -0
- package/src/browser-reference/submission-receipts.ts +122 -0
- package/src/browser-reference/text-quote.ts +219 -0
- package/src/browser-reference/types.ts +195 -0
- package/src/browser-reference/visible.ts +367 -0
- package/src/browser-reference/web-sources.ts +103 -0
- package/src/client/browser/BrowserController.ts +693 -0
- package/src/client/browser/BrowserFrame.ts +78 -0
- package/src/client/browser/BrowserNavigation.ts +169 -0
- package/src/client/browser/BrowserPage.ts +23 -0
- package/src/client/browser/BrowserPersistence.ts +44 -0
- package/src/client/browser/IframeImpl.ts +176 -0
- package/src/client/browser/child-tabs.ts +14 -0
- package/src/client/browser/iframe-reference.ts +67 -0
- package/src/client/browser/initialization.ts +262 -0
- package/src/client/browser/omnibox.ts +243 -0
- package/src/client/browser/store.ts +38 -0
- package/src/client/browser/takeover-channel.ts +72 -0
- package/src/client/browser/url.ts +46 -0
- package/src/client/browser/web-reference-source.ts +52 -0
- package/src/client/css-modules.d.ts +4 -0
- package/src/client/definition.tsx +30 -0
- package/src/client/electron/ElectronWebViewImpl.ts +364 -0
- package/src/client/electron/ElectronWebviewPresentation.ts +138 -0
- package/src/client/electron/NativeChildPresentation.ts +45 -0
- package/src/client/electron/NativeViewPage.ts +251 -0
- package/src/client/electron/pages.ts +23 -0
- package/src/client/electron/reference-overlay.ts +53 -0
- package/src/client/electron/workspace.ts +33 -0
- package/src/client/index.ts +293 -0
- package/src/client/locales.ts +857 -0
- package/src/client/pages.ts +28 -0
- package/src/client/reference/client/BrowserRefLink.tsx +142 -0
- package/src/client/reference/client/draft-reference.ts +167 -0
- package/src/client/reference/client/index.ts +7 -0
- package/src/client/reference/client/ordered-submission.ts +108 -0
- package/src/client/reference/client/pending-delivery.ts +216 -0
- package/src/client/reference/client/plugin.ts +189 -0
- package/src/client/reference/client/production/ReferenceCapsules.tsx +345 -0
- package/src/client/reference/client/production/ReferenceDock.module.css +193 -0
- package/src/client/reference/client/production/ReferenceDock.tsx +6 -0
- package/src/client/reference/client/production/ReferenceFeedback.tsx +15 -0
- package/src/client/reference/client/production/ReferenceMath.tsx +44 -0
- package/src/client/reference/client/production/ReferenceText.tsx +36 -0
- package/src/client/reference/client/production/assembly.ts +471 -0
- package/src/client/reference/client/production/asset-store.ts +144 -0
- package/src/client/reference/client/production/availability.ts +74 -0
- package/src/client/reference/client/production/bytes.ts +36 -0
- package/src/client/reference/client/production/delivery-client.ts +211 -0
- package/src/client/reference/client/production/draft-adapter.ts +508 -0
- package/src/client/reference/client/production/http-transport.ts +217 -0
- package/src/client/reference/client/production/production-submission.ts +310 -0
- package/src/client/reference/client/production/protocol.ts +231 -0
- package/src/client/reference/client/production/reference-card.ts +240 -0
- package/src/client/reference/client/production/reference-labels.ts +29 -0
- package/src/client/reference/client/production/reply-link-bridge.ts +222 -0
- package/src/client/reference/client/production/reveal.ts +215 -0
- package/src/client/reference/client/production/runtime.ts +1101 -0
- package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
- package/src/client/reference/client/production/source-marker.ts +63 -0
- package/src/client/reference/client/production/source-opener.ts +55 -0
- package/src/client/reference/client/production/styles.ts +104 -0
- package/src/client/reference/client/production/user-text-rule.ts +58 -0
- package/src/client/reference/client/reveal.ts +107 -0
- package/src/client/reference/client/scheme.ts +114 -0
- package/src/client/reference/client/types.ts +168 -0
- package/src/client/reference/css-modules.d.ts +4 -0
- package/src/client/reference/index.ts +11 -0
- package/src/client/reference-capture-owner.ts +162 -0
- package/src/client/reference-intents.ts +36 -0
- package/src/client/settings/index.ts +34 -0
- package/{client.js → src/client/settings/panel.ts} +2657 -2231
- package/src/client/shortcut-open.ts +30 -0
- package/src/client/startpage/binding.ts +99 -0
- package/src/client/startpage/controller.ts +303 -0
- package/src/client/startpage/model.ts +279 -0
- package/src/client/view/Browser.module.css +751 -0
- package/src/client/view/BrowserBody.tsx +314 -0
- package/src/client/view/BrowserPresentation.ts +9 -0
- package/src/client/view/BrowserTitle.tsx +17 -0
- package/src/client/view/IframePresentation.ts +344 -0
- package/src/client/view/StartPage.tsx +597 -0
- package/src/client/view/TakeoverBanner.tsx +21 -0
- package/src/index.ts +110 -73
- package/src/reference-owner.ts +5 -0
- package/src/reference-page.ts +9 -0
- package/src/reference-source.ts +3 -0
- package/src/reference-text.ts +197 -0
- package/src/startpage-settings.ts +103 -0
- package/src/startpage.ts +71 -0
- package/src/takeover-protocol.ts +19 -0
- package/src/tool-browser/code-tool.ts +401 -0
- package/src/tool-browser/code-worker.ts +639 -0
- package/src/tool-browser/index.ts +908 -77
- package/src/tool-browser/page-probe.ts +4 -4
- package/src/tool-browser/panel-page.ts +124 -0
- package/src/tool-browser/screenshot-image.ts +49 -0
- package/src/tool-browser/takeover.ts +198 -0
- package/src/types/electron-shim.d.ts +20 -0
- package/src/types.ts +85 -0
- package/src/web-guest.ts +34 -0
- package/tools/accept-desktop.mjs +148 -0
- package/lib/browser/runtime.d.ts +0 -175
- package/lib/browser/types.d.ts +0 -797
- package/lib/browser-electron/authenticated-route.d.ts +0 -27
- package/lib/browser-electron/automatic-maintenance.d.ts +0 -41
- package/lib/browser-electron/bridge-auto.d.ts +0 -93
- package/lib/browser-electron/bridge-connection.d.ts +0 -93
- package/lib/browser-electron/bridge-endpoint.d.ts +0 -30
- package/lib/browser-electron/bridge-install.d.ts +0 -85
- package/lib/browser-electron/bridge-maintenance.d.ts +0 -24
- package/lib/browser-electron/bridge-status.d.ts +0 -50
- package/lib/browser-electron/desktop-bridge-host.d.ts +0 -248
- package/lib/browser-electron/desktop-identity.d.ts +0 -58
- package/lib/browser-electron/electron-provision.d.ts +0 -92
- package/lib/browser-electron/entry.d.ts +0 -64
- package/lib/browser-electron/ephemeral-profile.d.ts +0 -37
- package/lib/browser-electron/file-write.d.ts +0 -2
- package/lib/browser-electron/history-store.d.ts +0 -98
- package/lib/browser-electron/host-main.d.ts +0 -26
- package/lib/browser-electron/http-body.d.ts +0 -24
- package/lib/browser-electron/json-reply.d.ts +0 -33
- package/lib/browser-electron/maintenance-broker.d.ts +0 -35
- package/lib/browser-electron/maintenance-lifecycle.d.ts +0 -32
- package/lib/browser-electron/maintenance-route.d.ts +0 -18
- package/lib/browser-electron/missing-system-browser.d.ts +0 -54
- package/lib/browser-electron/paths.d.ts +0 -4
- package/lib/browser-electron/preview-route.d.ts +0 -89
- package/lib/browser-electron/process.d.ts +0 -14
- package/lib/browser-electron/provider.d.ts +0 -959
- package/lib/browser-electron/remote-host.d.ts +0 -256
- package/lib/browser-electron/rpc-input.d.ts +0 -4
- package/lib/browser-electron/rpc-ops.d.ts +0 -18
- package/lib/browser-electron/runtime-diagnostics.d.ts +0 -12
- package/lib/browser-electron/runtime-route.d.ts +0 -55
- package/lib/browser-electron/runtime-status.d.ts +0 -116
- package/lib/browser-electron/settings-route.d.ts +0 -15
- package/lib/browser-electron/settings-store.d.ts +0 -224
- package/lib/browser-electron/sidebar-only-host.d.ts +0 -36
- package/lib/browser-electron/system-browser.d.ts +0 -367
- package/lib/browser-electron/timing.d.ts +0 -8
- package/lib/browser-electron/virtual-cursor.d.ts +0 -67
- package/lib/browser-electron/windows-system.d.ts +0 -3
- package/lib/index.d.ts +0 -30
- package/lib/tool-browser/element-fields.d.ts +0 -145
- package/lib/tool-browser/index.d.ts +0 -53
- package/lib/tool-browser/page-probe.d.ts +0 -86
- package/scripts/consumer-install-check.mjs +0 -72
- package/scripts/run-tests.mjs +0 -32
- package/scripts/verify-host-compat.mjs +0 -195
- package/scripts/verify-preview-route.mjs +0 -168
- package/scripts/verify-runtime-status.mjs +0 -179
|
@@ -4,13 +4,17 @@
|
|
|
4
4
|
* @module dsh-browser/browser-electron/authenticated-route
|
|
5
5
|
*/
|
|
6
6
|
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
7
|
-
import { replyJson } from './json-reply.
|
|
7
|
+
import { replyJson } from './json-reply.ts'
|
|
8
8
|
|
|
9
9
|
/** The host authentication method shared with its application and inspector routes. */
|
|
10
10
|
export interface BrowserConnection {
|
|
11
11
|
authorizeIndex(request: IncomingMessage, response: ServerResponse): boolean
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
export interface BrowserPairingConnection {
|
|
15
|
+
requestRejection(request: IncomingMessage): 401 | 403 | undefined
|
|
16
|
+
}
|
|
17
|
+
|
|
14
18
|
/** An exact HTTP route registered with the DSH web server. */
|
|
15
19
|
export type BrowserHttpHandler = (request: IncomingMessage, response: ServerResponse) => void | Promise<void>
|
|
16
20
|
|
|
@@ -42,6 +46,30 @@ export function authenticatedRoute(
|
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
48
|
|
|
49
|
+
/** Admit passive previews through the same live-Peer and Host fence as DSH's API. */
|
|
50
|
+
export function pairedRoute(
|
|
51
|
+
connection: () => BrowserPairingConnection | undefined,
|
|
52
|
+
handler: BrowserHttpHandler,
|
|
53
|
+
): BrowserHttpHandler {
|
|
54
|
+
return (request, response) => {
|
|
55
|
+
let rejection: 401 | 403 | undefined
|
|
56
|
+
try {
|
|
57
|
+
const host = connection()
|
|
58
|
+
if (typeof host?.requestRejection !== 'function') throw new Error('pairing unavailable')
|
|
59
|
+
rejection = host.requestRejection(request)
|
|
60
|
+
if (rejection !== undefined && rejection !== 401 && rejection !== 403) throw new Error('invalid admission')
|
|
61
|
+
} catch {
|
|
62
|
+
replyJson(response, 503, { error: 'browser-pairing-unavailable' })
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
if (rejection !== undefined) {
|
|
66
|
+
replyJson(response, rejection, { error: rejection === 401 ? 'unauthorized' : 'forbidden' })
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
return handler(request, response)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
45
73
|
/**
|
|
46
74
|
* Admit machine-wide installation changes from a direct loopback connection.
|
|
47
75
|
* Forwarded requests belong to their remote operator even when the last hop is loopback.
|
|
@@ -1,24 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
import { BROWSER_PROFILE_DIR } from '../../assets/browser-policy.mjs'
|
|
2
|
+
/** User-requested Desktop maintenance (Windows and macOS), coordinated outside the Desktop process tree. */
|
|
2
3
|
import { execFile, spawn } from 'node:child_process'
|
|
4
|
+
import * as fs from 'node:fs'
|
|
3
5
|
import { existsSync, readFileSync } from 'node:fs'
|
|
4
|
-
import { mkdir, open, readFile,
|
|
6
|
+
import { cp, mkdir, open, readFile, stat as statAsync, unlink, writeFile } from 'node:fs/promises'
|
|
5
7
|
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path'
|
|
6
8
|
import { fileURLToPath } from 'node:url'
|
|
7
|
-
import { prepareBridgeMaintenance } from './bridge-maintenance.
|
|
8
|
-
import { launchMaintenanceBroker, type MaintenanceBrokerOptions, type MaintenanceBrokerResult } from './maintenance-broker.
|
|
9
|
-
import { runMaintenanceLifecycle, type MaintenanceState } from './maintenance-lifecycle.
|
|
10
|
-
import { defaultInstallerPath, runBridgeAction, waitForRestartedBridge, type
|
|
11
|
-
import { readDesktopIdentity } from './desktop-identity.
|
|
12
|
-
import { dshHome } from './paths.
|
|
13
|
-
import { encodePowerShellScript, windowsPowerShellPath } from './windows-system.
|
|
9
|
+
import { prepareBridgeMaintenance } from './bridge-maintenance.ts'
|
|
10
|
+
import { launchMaintenanceBroker, type MaintenanceBrokerOptions, type MaintenanceBrokerResult } from './maintenance-broker.ts'
|
|
11
|
+
import { runMaintenanceLifecycle, type MaintenanceState } from './maintenance-lifecycle.ts'
|
|
12
|
+
import { defaultInstallerPath, runBridgeAction, waitForRestartedBridge, type BridgeActionResult, type HostPatchResult } from './bridge-install.ts'
|
|
13
|
+
import { desktopLayout, desktopPaths, readAsarFile, readDesktopIdentity } from './desktop-identity.ts'
|
|
14
|
+
import { dshHome } from './paths.ts'
|
|
15
|
+
import { encodePowerShellScript, windowsPowerShellPath } from './windows-system.ts'
|
|
16
|
+
import { renameMaintenanceFile } from '../../desktop-bridge/maintenance-files.mjs'
|
|
17
|
+
import { isDesktopExecutable } from '../../desktop-bridge/desktop-processes.mjs'
|
|
18
|
+
import { installedProfileExtension, repairProfileExtension, reconcileProfile, profileDependencySpec, profileRuntimeDirectory, MAIN_EXTENSION_NAME, type InstalledExtension } from './profile-extension.ts'
|
|
19
|
+
import { withProfileCheckpoint } from './profile-checkpoint.ts'
|
|
20
|
+
import { runProfileCommand } from './profile-command.ts'
|
|
21
|
+
import { cleanProfileResidue, inspectProfileResidue } from './profile-residue.ts'
|
|
22
|
+
|
|
23
|
+
const { hostPatchStatus }: { hostPatchStatus: (packages: readonly string[], options?: { fs: object }) => HostPatchResult } = await import(new URL('../../dsh-host-patch/apply.mjs', import.meta.url).href)
|
|
24
|
+
const { stripLegacyBridge }: { stripLegacyBridge: (text: string) => string | undefined } = await import(new URL('../../dsh-host-patch/legacy-bridge.mjs', import.meta.url).href)
|
|
14
25
|
|
|
15
26
|
interface DesktopProcess { readonly pid: number; readonly path: string; readonly command: string; readonly started: string }
|
|
16
27
|
export interface AutomaticMaintenanceJob extends MaintenanceState { readonly id: string; readonly workerPid?: number; readonly startedAt?: string }
|
|
17
|
-
export interface AutomaticMaintenanceOptions {
|
|
28
|
+
export interface AutomaticMaintenanceOptions {
|
|
29
|
+
readonly locale?: 'zh' | 'en'
|
|
30
|
+
}
|
|
18
31
|
interface AutomaticPlan {
|
|
19
32
|
readonly version: 1
|
|
20
33
|
readonly id: string
|
|
21
|
-
readonly action:
|
|
34
|
+
readonly action: 'reinstall'
|
|
22
35
|
readonly root: string
|
|
23
36
|
readonly nodePath: string
|
|
24
37
|
readonly electronNode: boolean
|
|
@@ -27,6 +40,177 @@ interface AutomaticPlan {
|
|
|
27
40
|
readonly target: DesktopProcess
|
|
28
41
|
readonly createdAt: string
|
|
29
42
|
readonly locale?: 'zh' | 'en'
|
|
43
|
+
readonly dependency: string
|
|
44
|
+
readonly nestedResidue?: readonly string[]
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class ReinstallPreflightError extends Error {
|
|
48
|
+
constructor(readonly code: string, message: string) { super(message) }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function archiveExists(path: string): boolean {
|
|
52
|
+
const runtime = process as NodeJS.Process & { noAsar?: boolean }
|
|
53
|
+
const previous = runtime.noAsar
|
|
54
|
+
runtime.noAsar = true
|
|
55
|
+
try { return existsSync(path) } finally { runtime.noAsar = previous }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function patchDirectories(root: string): string[] {
|
|
59
|
+
const app = join(desktopPaths(root).resources, 'app')
|
|
60
|
+
return [app, join(app, 'dsh', 'node_modules', '@deepseek-ai', 'dsh-client-ui-sidebar-right')]
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function validateCliBackup(path: string, kind: 'host' | 'shim'): void {
|
|
64
|
+
const backup = path + '.before-bridge'
|
|
65
|
+
if (!existsSync(backup)) return
|
|
66
|
+
if (![path, backup].every(file => fs.lstatSync(file).isFile() && !fs.lstatSync(file).isSymbolicLink())) {
|
|
67
|
+
throw new ReinstallPreflightError('REINSTALL_BACKUP_CONFLICT', 'A CLI restore baseline is not a regular file.')
|
|
68
|
+
}
|
|
69
|
+
const original = readFileSync(backup, 'utf8'), current = readFileSync(path, 'utf8')
|
|
70
|
+
if (current === original) return
|
|
71
|
+
const eol = original.includes('\r\n') ? '\r\n' : '\n'
|
|
72
|
+
let expected: string
|
|
73
|
+
if (kind === 'host') {
|
|
74
|
+
const call = /^(\t)await runDesktopCli\(((?:runtimeDir, )?)join\(dirname\(runtimeArchivePath\(runtimeDir\) \?\? runtimeDir\), "runtime"\)\);$/m.exec(original)
|
|
75
|
+
if (call === null) throw new ReinstallPreflightError('REINSTALL_BACKUP_CONFLICT', 'The CLI differs from its recognized restore baseline.')
|
|
76
|
+
expected = original.replace(call[0], () => [
|
|
77
|
+
'\t// dsh-builtin-browser: recognize an unpacked `app` directory as the app root,',
|
|
78
|
+
'\t// so an installation whose app.asar was moved aside still finds its runtime.',
|
|
79
|
+
'\tconst cliOwnerDir = dirname(runtimeDir);',
|
|
80
|
+
'\tconst cliSupportRoot = basename(cliOwnerDir) === "app" || basename(cliOwnerDir) === "app.asar" ? dirname(cliOwnerDir) : cliOwnerDir;',
|
|
81
|
+
`\tawait runDesktopCli(${call[2]}join(cliSupportRoot, "runtime"));`,
|
|
82
|
+
].join(eol))
|
|
83
|
+
} else {
|
|
84
|
+
const injection = [
|
|
85
|
+
'rem dsh-builtin-browser: resolve the app directory (resources\\app when the bridge is installed,',
|
|
86
|
+
'rem resources\\app.asar on a stock installation).',
|
|
87
|
+
'set "DSH_APP=%~dp0..\\..\\..\\app"',
|
|
88
|
+
'if not exist "%DSH_APP%\\dsh\\node_modules\\@deepseek-ai\\dsh-desktop-host\\lib\\cli.js" set "DSH_APP=%~dp0..\\..\\..\\app.asar"',
|
|
89
|
+
].join(eol)
|
|
90
|
+
const setLocal = /^.*setlocal.*$/m.exec(original)
|
|
91
|
+
expected = (setLocal === null ? injection + eol + original : original.replace(setLocal[0], () => setLocal[0] + eol + injection))
|
|
92
|
+
.replace(/%~dp0(?:\.\.\\)+app\.asar\\dsh\\/, () => '%DSH_APP%\\dsh\\')
|
|
93
|
+
}
|
|
94
|
+
if (current !== expected) throw new ReinstallPreflightError('REINSTALL_BACKUP_CONFLICT', 'The CLI differs from its recognized restore baseline.')
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Inspect the archive Electron will load, never a leftover extraction beside it. */
|
|
98
|
+
export function inspectReinstallHost(root: string): ReturnType<typeof hostPatchStatus> {
|
|
99
|
+
const identity = readDesktopIdentity(root)
|
|
100
|
+
if (!identity.ok) throw new ReinstallPreflightError('REINSTALL_DESKTOP_INVALID', identity.reason)
|
|
101
|
+
const archive = join(desktopPaths(root).resources, 'app.asar')
|
|
102
|
+
if (archiveExists(archive) && existsSync(archive + '.before-bridge')) {
|
|
103
|
+
throw new ReinstallPreflightError('REINSTALL_BACKUP_CONFLICT', 'Both the Desktop archive and its restore baseline exist.')
|
|
104
|
+
}
|
|
105
|
+
if (identity.layout === 'unpacked') return hostPatchStatus(patchDirectories(root))
|
|
106
|
+
const app = patchDirectories(root)[0]!
|
|
107
|
+
const archiveFile = (path: fs.PathLike): Buffer | undefined => readAsarFile(archive, relative(app, String(path)).split('\\').join('/'))
|
|
108
|
+
const snapshot = {
|
|
109
|
+
...fs,
|
|
110
|
+
realpathSync: (path: fs.PathLike) => resolve(String(path)),
|
|
111
|
+
readFileSync: (path: fs.PathLike) => {
|
|
112
|
+
const content = archiveFile(path)
|
|
113
|
+
if (content === undefined) throw new Error(`Missing or unreadable archive entry: ${relative(app, String(path))}`)
|
|
114
|
+
return content.toString('utf8')
|
|
115
|
+
},
|
|
116
|
+
existsSync: (path: fs.PathLike) => archiveFile(path) !== undefined,
|
|
117
|
+
lstatSync: () => ({ isFile: () => true, isSymbolicLink: () => false }),
|
|
118
|
+
statSync: () => ({ mode: 0o644 }),
|
|
119
|
+
}
|
|
120
|
+
return hostPatchStatus(patchDirectories(root), { fs: snapshot })
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Entirely read-only: a missing dependency never creates a lock, plan or replacement source. */
|
|
124
|
+
export async function preflightReinstall(root: string, home: string): Promise<string> {
|
|
125
|
+
let dependency: string
|
|
126
|
+
try { dependency = await profileDependencySpec(home) } catch (error) {
|
|
127
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') throw new ReinstallPreflightError('REINSTALL_DEPENDENCY_MISSING', 'The Desktop profile has no dependency specification to reinstall.')
|
|
128
|
+
throw error
|
|
129
|
+
}
|
|
130
|
+
if (/^(?:file|link):/.test(dependency)) {
|
|
131
|
+
const path = resolve(home, 'profiles', 'desktop', dependency.slice(dependency.indexOf(':') + 1))
|
|
132
|
+
try { fs.accessSync(path, fs.constants.R_OK) } catch {
|
|
133
|
+
throw new ReinstallPreflightError('REINSTALL_DEPENDENCY_UNAVAILABLE', 'The captured local dependency source is not readable.')
|
|
134
|
+
}
|
|
135
|
+
const installed = join(home, 'profiles', 'desktop', 'node_modules', MAIN_EXTENSION_NAME)
|
|
136
|
+
if (existsSync(installed)) {
|
|
137
|
+
const source = fs.realpathSync(path)
|
|
138
|
+
const owner = fs.lstatSync(installed).isSymbolicLink() ? resolve(home, 'profiles', 'desktop', 'node_modules') : fs.realpathSync(installed)
|
|
139
|
+
if (source === owner || inside(owner, source)) throw new ReinstallPreflightError('REINSTALL_DEPENDENCY_UNSAFE', 'The captured dependency source would be deleted by plugin removal.')
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
await inspectProfileResidue(home)
|
|
143
|
+
const status = inspectReinstallHost(root)
|
|
144
|
+
if (status.status !== 'absent' && status.status !== 'applied') throw new ReinstallPreflightError('REINSTALL_HOST_CONFLICT', status.reason ?? status.status)
|
|
145
|
+
const cli = 'dsh/node_modules/@deepseek-ai/dsh-desktop-host/lib/cli.js'
|
|
146
|
+
const archive = join(desktopPaths(root).resources, 'app.asar')
|
|
147
|
+
if (status.status === 'applied' && (archiveExists(archive) || ![
|
|
148
|
+
join(desktopPaths(root).resources, 'app', 'lib', 'main.js'), join(desktopPaths(root).resources, 'app', 'lib', 'preload-app.cjs'),
|
|
149
|
+
join(patchDirectories(root)[1]!, 'lib', 'client.js'),
|
|
150
|
+
].every(path => existsSync(path + '.before-dsh-host-patch')))) {
|
|
151
|
+
throw new ReinstallPreflightError('REINSTALL_BACKUP_CONFLICT', 'An applied host patch has no usable external restore baseline.')
|
|
152
|
+
}
|
|
153
|
+
if (archiveExists(archive) ? readAsarFile(archive, cli) === undefined : !existsSync(join(desktopPaths(root).resources, 'app', cli))) {
|
|
154
|
+
throw new ReinstallPreflightError('REINSTALL_CLI_MISSING', 'The authoritative Desktop CLI is missing or unreadable.')
|
|
155
|
+
}
|
|
156
|
+
validateCliBackup(join(desktopPaths(root).resources, 'runtime', 'cli', 'bin', 'dsh.cmd'), 'shim')
|
|
157
|
+
if (!archiveExists(archive)) validateCliBackup(join(desktopPaths(root).resources, 'app', cli), 'host')
|
|
158
|
+
const main = join(desktopPaths(root).resources, 'app', 'lib', 'main.js')
|
|
159
|
+
if (!archiveExists(join(desktopPaths(root).resources, 'app.asar')) && existsSync(main + '.before-bridge')) {
|
|
160
|
+
const original = readFileSync(main + '.before-bridge', 'utf8')
|
|
161
|
+
const current = readFileSync(existsSync(main + '.before-dsh-host-patch') ? main + '.before-dsh-host-patch' : main, 'utf8')
|
|
162
|
+
if ((stripLegacyBridge(current) ?? current) !== original) {
|
|
163
|
+
throw new ReinstallPreflightError('REINSTALL_BACKUP_CONFLICT', 'The legacy bridge differs from its restore baseline.')
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (!archiveExists(archive) && existsSync(archive + '.before-bridge')) {
|
|
167
|
+
const preserved = readAsarFile(archive + '.before-bridge', 'lib/main.js')
|
|
168
|
+
const current = readFileSync(existsSync(main + '.before-dsh-host-patch') ? main + '.before-dsh-host-patch' : main, 'utf8')
|
|
169
|
+
if (preserved === undefined || preserved.toString('utf8') !== (stripLegacyBridge(current) ?? current)) {
|
|
170
|
+
throw new ReinstallPreflightError('REINSTALL_BACKUP_CONFLICT', 'The preserved archive belongs to different Desktop bytes.')
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
await profileRuntimeDirectory(root)
|
|
174
|
+
return dependency
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Copy only shipped runtime files; the running worker and installer survive profile removal. */
|
|
178
|
+
export async function stageReinstallRuntime(directory: string, source = fileURLToPath(new URL('../../', import.meta.url))): Promise<string> {
|
|
179
|
+
const destination = join(directory, 'runtime')
|
|
180
|
+
const packageDirectory = fs.realpathSync(source)
|
|
181
|
+
const parent = fs.realpathSync(directory)
|
|
182
|
+
if (parent === packageDirectory || inside(packageDirectory, parent)) throw new Error('Reinstall runtime must be staged outside the removed package')
|
|
183
|
+
await mkdir(destination, { mode: 0o700 })
|
|
184
|
+
for (const name of ['lib', 'assets', 'desktop-bridge', 'dsh-host-patch', 'package.json']) {
|
|
185
|
+
await cp(join(packageDirectory, name), join(destination, name), { recursive: true, dereference: true, errorOnExist: true, force: false })
|
|
186
|
+
}
|
|
187
|
+
return join(destination, 'lib', 'browser-electron', 'automatic-maintenance.js')
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export interface ReinstallSteps {
|
|
191
|
+
readonly remove: () => Promise<BridgeActionResult>
|
|
192
|
+
readonly absent: () => Promise<boolean>
|
|
193
|
+
readonly revert: () => Promise<BridgeActionResult>
|
|
194
|
+
readonly hostAbsent: () => boolean
|
|
195
|
+
readonly apply: () => Promise<BridgeActionResult>
|
|
196
|
+
readonly add: () => Promise<BridgeActionResult>
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Called under the automatic job lock, only after the closed-process barrier. */
|
|
200
|
+
export async function runReinstallTransaction(steps: ReinstallSteps): Promise<BridgeActionResult> {
|
|
201
|
+
const removed = await steps.absent() ? undefined : await steps.remove()
|
|
202
|
+
if (removed && !removed.ok) throw new Error(`REINSTALL_REMOVE_FAILED: ${removed.output}`)
|
|
203
|
+
if (!await steps.absent()) throw new Error('REINSTALL_REMOVE_FAILED: profile dependency remains installed')
|
|
204
|
+
const wasAbsent = steps.hostAbsent()
|
|
205
|
+
const reverted = await steps.revert()
|
|
206
|
+
if (!reverted.ok && !(wasAbsent && steps.hostAbsent() && reverted.code === 1 && /^nothing to revert in /m.test(reverted.output)
|
|
207
|
+
&& !/error|refus|incomplete|EACCES|EPERM/i.test(reverted.output))) throw new Error(`REINSTALL_REVERT_FAILED: ${reverted.output}`)
|
|
208
|
+
if (!steps.hostAbsent()) throw new Error('REINSTALL_REVERT_FAILED: host patch is still present')
|
|
209
|
+
const applied = await steps.apply()
|
|
210
|
+
if (!applied.ok || applied.hostPatch?.status !== 'applied') throw new Error(`REINSTALL_APPLY_FAILED: ${applied.output}`)
|
|
211
|
+
const added = await steps.add()
|
|
212
|
+
if (!added.ok) throw new Error(`REINSTALL_ADD_FAILED: ${added.output}`)
|
|
213
|
+
return { ...added, hostPatch: applied.hostPatch, output: [removed?.output, reverted.output, applied.output, added.output].filter(Boolean).join('\n').slice(-20_000) }
|
|
30
214
|
}
|
|
31
215
|
|
|
32
216
|
const terminal = new Set(['completed', 'failed', 'cancelled'])
|
|
@@ -41,13 +225,21 @@ function reportMaintenanceFailure(label: string, error: unknown): void {
|
|
|
41
225
|
}
|
|
42
226
|
|
|
43
227
|
function homePath(): string { return resolve(dshHome()) }
|
|
44
|
-
function basePath(home = homePath()): string { return join(home,
|
|
228
|
+
function basePath(home = homePath()): string { return join(home, BROWSER_PROFILE_DIR, 'maintenance') }
|
|
45
229
|
function inside(base: string, path: string): boolean {
|
|
46
230
|
const part = relative(base, path)
|
|
47
231
|
return part !== '' && !isAbsolute(part) && part !== '..' && !part.startsWith('..\\') && !part.startsWith('../')
|
|
48
232
|
}
|
|
49
|
-
|
|
50
|
-
|
|
233
|
+
/** Platforms whose Desktop can be quit, patched and reopened by the independent worker. */
|
|
234
|
+
export function automaticMaintenanceSupported(platform: NodeJS.Platform = process.platform): boolean {
|
|
235
|
+
return platform === 'win32' || platform === 'darwin'
|
|
236
|
+
}
|
|
237
|
+
/** Same-path comparison: case-insensitive on Windows, by on-disk spelling elsewhere (APFS may be either). */
|
|
238
|
+
function samePath(a: string, b: string): boolean {
|
|
239
|
+
return isDesktopExecutable(a, b)
|
|
240
|
+
}
|
|
241
|
+
function requireLiveDesktop(): void {
|
|
242
|
+
if (!automaticMaintenanceSupported()) throw new Error('automatic bridge maintenance requires DSH Desktop on Windows or macOS')
|
|
51
243
|
if (process.env.DSH_BROWSER_TEST === '1' || process.env.NODE_TEST_CONTEXT !== undefined) {
|
|
52
244
|
throw new Error('automatic Desktop maintenance is forbidden in a test process')
|
|
53
245
|
}
|
|
@@ -60,25 +252,95 @@ async function execute(command: string, args: readonly string[], timeout = 15_00
|
|
|
60
252
|
})
|
|
61
253
|
})
|
|
62
254
|
}
|
|
63
|
-
|
|
255
|
+
/** The Desktop GUI process on macOS: `ps` gives pid, start time, executable path and argv. */
|
|
256
|
+
async function posixDesktopProcesses(root: string, includeBundleHelpers = false): Promise<DesktopProcess[]> {
|
|
257
|
+
const psEnv: NodeJS.ProcessEnv = { ...process.env, LC_ALL: 'C', LANG: 'C' }
|
|
258
|
+
const [started, commands] = await Promise.all([
|
|
259
|
+
execute('ps', ['-axww', '-o', 'pid=,lstart=,comm='], 15_000, psEnv),
|
|
260
|
+
execute('ps', ['-axww', '-o', 'pid=,args='], 15_000, psEnv),
|
|
261
|
+
])
|
|
262
|
+
if (started.code !== 0 || commands.code !== 0) throw new Error('cannot inspect running DSH Desktop processes')
|
|
263
|
+
const argv = new Map<number, string>()
|
|
264
|
+
for (const line of commands.stdout.split('\n')) {
|
|
265
|
+
const match = /^\s*(\d+)\s(.*)$/.exec(line)
|
|
266
|
+
if (match !== null) argv.set(Number(match[1]), match[2] as string)
|
|
267
|
+
}
|
|
268
|
+
const expected = desktopPaths(root).executable
|
|
269
|
+
const layout = desktopLayout(root)
|
|
270
|
+
const bundleRoot = includeBundleHelpers && !('error' in layout) && layout.name === 'macos-bundle'
|
|
271
|
+
? root
|
|
272
|
+
: undefined
|
|
273
|
+
const rows: DesktopProcess[] = []
|
|
274
|
+
for (const line of started.stdout.split('\n')) {
|
|
275
|
+
// lstart is always five fields under C locale: "Fri Nov 20 04:10:00 2026".
|
|
276
|
+
const match = /^\s*(\d+)\s+(\S+\s+\S+\s+\d+\s+[\d:]+\s+\d{4})\s+(.+)$/.exec(line)
|
|
277
|
+
if (match === null) continue
|
|
278
|
+
const path = (match[3] as string).trim()
|
|
279
|
+
if (!isAbsolute(path)) continue
|
|
280
|
+
const matched = isDesktopExecutable(path, expected, bundleRoot)
|
|
281
|
+
if (!matched) continue
|
|
282
|
+
const at = Date.parse(match[2] as string)
|
|
283
|
+
if (!Number.isFinite(at)) throw new Error('cannot identify a running DSH Desktop process')
|
|
284
|
+
rows.push({ pid: Number(match[1]), path, command: argv.get(Number(match[1])) ?? '', started: new Date(at).toISOString() })
|
|
285
|
+
}
|
|
286
|
+
return rows.filter(p => !NODE_MODE.test(p.command))
|
|
287
|
+
}
|
|
288
|
+
// The Desktop also ships a Node-mode CLI under its executable; it is not a GUI to close.
|
|
289
|
+
const NODE_MODE = /(?:^|\s)--expose-internals(?:\s|$)|\.[cm]?js(?:"|\s|$)|(?:^|\s)(?:--eval|--print|--input-type)(?:=|\s|$)|(?:^|\s)-(?:e|p)(?:\s|$)/i
|
|
290
|
+
async function desktopProcesses(root: string, includeBundleHelpers = false): Promise<DesktopProcess[]> {
|
|
291
|
+
if (process.platform !== 'win32') return await posixDesktopProcesses(root, includeBundleHelpers)
|
|
64
292
|
const script = "$ProgressPreference='SilentlyContinue'; $ErrorActionPreference='Stop'; [Console]::OutputEncoding=[System.Text.UTF8Encoding]::new($false); $rows = @((Get-CimInstance Win32_Process -Filter \"Name='DeepSeek Harness.exe'\" -ErrorAction Stop) | ForEach-Object { @{pid=[int]$_.ProcessId;path=$_.ExecutablePath;command=$_.CommandLine;started=$_.CreationDate.ToUniversalTime().ToString('o')} }); ConvertTo-Json -InputObject $rows -Compress"
|
|
65
293
|
const r = await execute(windowsPowerShellPath(), ['-NoProfile', '-NonInteractive', '-EncodedCommand', encodePowerShellScript(script)])
|
|
66
294
|
if (r.code !== 0) throw new Error('cannot inspect running DSH Desktop processes')
|
|
67
295
|
let value: unknown
|
|
68
296
|
try { value = JSON.parse(r.stdout.replace(/^\uFEFF/, '').trim()) } catch { throw new Error('Desktop process inspection returned invalid data') }
|
|
297
|
+
return identifyDesktopProcesses(root, value)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
class DesktopProcessIdentityUnavailable extends Error {}
|
|
301
|
+
|
|
302
|
+
/** Validate a CIM snapshot without treating an incomplete process identity as an exited process. */
|
|
303
|
+
export function identifyDesktopProcesses(root: string, value: unknown): DesktopProcess[] {
|
|
69
304
|
const rows = Array.isArray(value) ? value : value === null ? [] : [value]
|
|
70
|
-
const expected =
|
|
305
|
+
const expected = desktopPaths(root).executable
|
|
71
306
|
return rows.filter((row): row is DesktopProcess => {
|
|
72
307
|
if (row === null || typeof row !== 'object') throw new Error('Desktop process inspection was incomplete')
|
|
73
308
|
const p = row as Partial<DesktopProcess>
|
|
74
309
|
if (typeof p.path !== 'string' || p.path === '' || typeof p.command !== 'string' || !Number.isSafeInteger(p.pid) || typeof p.started !== 'string') {
|
|
75
|
-
throw new
|
|
310
|
+
throw new DesktopProcessIdentityUnavailable('cannot identify a running DSH Desktop process')
|
|
76
311
|
}
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
return !/(?:^|\s)--expose-internals(?:\s|$)|\.[cm]?js(?:"|\s|$)|(?:^|\s)(?:--eval|--print|--input-type)(?:=|\s|$)|(?:^|\s)-(?:e|p)(?:\s|$)/i.test(p.command)
|
|
312
|
+
if (!isDesktopExecutable(p.path, expected, undefined, 'win32')) return false
|
|
313
|
+
return !NODE_MODE.test(p.command)
|
|
80
314
|
})
|
|
81
315
|
}
|
|
316
|
+
|
|
317
|
+
/** Wait through incomplete shutdown snapshots, but require a complete empty snapshot before writing. */
|
|
318
|
+
export async function waitForDesktopExit(deps: {
|
|
319
|
+
readonly inspect: () => Promise<readonly DesktopProcess[]>
|
|
320
|
+
readonly checkCancelled: () => void
|
|
321
|
+
readonly pause?: () => Promise<void>
|
|
322
|
+
readonly now?: () => number
|
|
323
|
+
}): Promise<void> {
|
|
324
|
+
const now = deps.now ?? Date.now
|
|
325
|
+
const deadline = now() + 60_000
|
|
326
|
+
let incomplete = false
|
|
327
|
+
while (now() < deadline) {
|
|
328
|
+
deps.checkCancelled()
|
|
329
|
+
try {
|
|
330
|
+
const rows = await deps.inspect()
|
|
331
|
+
deps.checkCancelled()
|
|
332
|
+
if (rows.length === 0) return
|
|
333
|
+
incomplete = false
|
|
334
|
+
} catch (error) {
|
|
335
|
+
if (!(error instanceof DesktopProcessIdentityUnavailable)) throw error
|
|
336
|
+
incomplete = true
|
|
337
|
+
}
|
|
338
|
+
await (deps.pause ?? (() => delay(1_000)))()
|
|
339
|
+
}
|
|
340
|
+
throw new Error(incomplete
|
|
341
|
+
? 'cannot verify that DSH Desktop exited: process identity remains unavailable; maintenance was cancelled'
|
|
342
|
+
: 'Desktop did not exit; maintenance was cancelled. Any running-task confirmation remains under your control.')
|
|
343
|
+
}
|
|
82
344
|
async function atomicJson(path: string, value: unknown, exclusive = false): Promise<void> {
|
|
83
345
|
if (exclusive && existsSync(path)) {
|
|
84
346
|
const error: NodeJS.ErrnoException = new Error(`EEXIST: ${path} already exists`)
|
|
@@ -87,7 +349,11 @@ async function atomicJson(path: string, value: unknown, exclusive = false): Prom
|
|
|
87
349
|
}
|
|
88
350
|
const temp = `${path}.${String(process.pid)}.tmp`
|
|
89
351
|
await writeFile(temp, JSON.stringify(value, null, 2) + '\n', { mode: 0o600 })
|
|
90
|
-
await
|
|
352
|
+
try { await renameMaintenanceFile(temp, path) } finally {
|
|
353
|
+
await unlink(temp).catch(error => {
|
|
354
|
+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') reportMaintenanceFailure('cannot remove maintenance temporary file', error)
|
|
355
|
+
})
|
|
356
|
+
}
|
|
91
357
|
}
|
|
92
358
|
|
|
93
359
|
export interface MaintenanceProgressOptions {
|
|
@@ -115,7 +381,7 @@ export function maintenanceProgressLaunchOptions(
|
|
|
115
381
|
locale: 'zh' | 'en' = 'zh',
|
|
116
382
|
powershellPath = windowsPowerShellPath(),
|
|
117
383
|
): MaintenanceBrokerOptions {
|
|
118
|
-
if (typeof jobId !== 'string' || !/^(?:install|uninstall)-[A-Za-z0-9]+$/.test(jobId)
|
|
384
|
+
if (typeof jobId !== 'string' || !/^(?:install|uninstall|reinstall)-[A-Za-z0-9]+$/.test(jobId)
|
|
119
385
|
|| typeof directory !== 'string' || !isAbsolute(directory) || basename(directory) !== jobId
|
|
120
386
|
|| !['zh', 'en'].includes(locale)) throw new Error('invalid maintenance progress request')
|
|
121
387
|
return {
|
|
@@ -169,7 +435,7 @@ export function readAutomaticMaintenance(home = homePath()): AutomaticMaintenanc
|
|
|
169
435
|
|| basename(pointer.directory) !== pointer.id) return undefined
|
|
170
436
|
const state = JSON.parse(readFileSync(join(pointer.directory, 'state.json'), 'utf8')) as AutomaticMaintenanceJob
|
|
171
437
|
if (state.id !== pointer.id || !['armed', 'closing', 'installing', 'restarting', 'verifying', ...terminal].includes(state.phase)
|
|
172
|
-
|| !['install', 'uninstall'].includes(state.action) || !Number.isFinite(Date.parse(state.at))) return undefined
|
|
438
|
+
|| !['install', 'uninstall', 'reinstall'].includes(state.action) || !Number.isFinite(Date.parse(state.at))) return undefined
|
|
173
439
|
return state
|
|
174
440
|
} catch { return undefined }
|
|
175
441
|
}
|
|
@@ -180,7 +446,7 @@ async function clearStaleLock(lockPath: string, home: string): Promise<boolean>
|
|
|
180
446
|
// Never touch a lock another request may still be preparing (concurrent start window).
|
|
181
447
|
if (Date.now() - info.mtimeMs < 5 * 60_000) return false
|
|
182
448
|
const id = (await readFile(lockPath, 'utf8')).trim()
|
|
183
|
-
if (!/^(?:install|uninstall)-[A-Za-z0-9]+$/.test(id)) return false
|
|
449
|
+
if (!/^(?:install|uninstall|reinstall)-[A-Za-z0-9]+$/.test(id)) return false
|
|
184
450
|
const prior = readAutomaticMaintenance(home)
|
|
185
451
|
if (prior === undefined || prior.id !== id) return true
|
|
186
452
|
if (terminal.has(prior.phase)) return true
|
|
@@ -207,8 +473,9 @@ function validatePlan(value: unknown, path: string, now = Date.now()): Automatic
|
|
|
207
473
|
if (value === null || typeof value !== 'object') throw new Error('invalid automatic maintenance plan')
|
|
208
474
|
const plan = value as Partial<AutomaticPlan>
|
|
209
475
|
const created = typeof plan.createdAt === 'string' ? Date.parse(plan.createdAt) : NaN
|
|
210
|
-
if (plan.version !== 1 ||
|
|
211
|
-
|| typeof plan.
|
|
476
|
+
if (plan.version !== 1 || plan.action !== 'reinstall'
|
|
477
|
+
|| typeof plan.dependency !== 'string' || plan.dependency.trim() === ''
|
|
478
|
+
|| typeof plan.id !== 'string' || !/^reinstall-[A-Za-z0-9]+$/.test(plan.id)
|
|
212
479
|
|| ![plan.root, plan.home, plan.nodePath, plan.directory].every(p => typeof p === 'string' && isAbsolute(p))
|
|
213
480
|
|| typeof plan.electronNode !== 'boolean' || !Number.isFinite(created) || created > now || now - created > 30_000
|
|
214
481
|
|| (plan.locale !== undefined && !['zh', 'en'].includes(plan.locale))) {
|
|
@@ -222,7 +489,7 @@ function validatePlan(value: unknown, path: string, now = Date.now()): Automatic
|
|
|
222
489
|
}
|
|
223
490
|
const target = checked.target
|
|
224
491
|
if (target === null || typeof target !== 'object' || !Number.isSafeInteger(target.pid) || target.pid <= 0
|
|
225
|
-
|| typeof target.path !== 'string' ||
|
|
492
|
+
|| typeof target.path !== 'string' || !samePath(target.path, desktopPaths(checked.root).executable)
|
|
226
493
|
|| typeof target.command !== 'string' || /(?:^|\s)--type(?:=|\s)/i.test(target.command)
|
|
227
494
|
|| typeof target.started !== 'string' || !Number.isFinite(Date.parse(target.started)) || Date.parse(target.started) > now) {
|
|
228
495
|
throw new Error('invalid automatic maintenance target process')
|
|
@@ -232,7 +499,7 @@ function validatePlan(value: unknown, path: string, now = Date.now()): Automatic
|
|
|
232
499
|
|
|
233
500
|
/** Commit only the armed job after its accepted HTTP response has finished writing. */
|
|
234
501
|
export async function commitAutomaticMaintenance(jobId: string, home = homePath()): Promise<void> {
|
|
235
|
-
if (typeof jobId !== 'string' || !/^
|
|
502
|
+
if (typeof jobId !== 'string' || !/^reinstall-[A-Za-z0-9]+$/.test(jobId)) throw new Error('invalid bridge maintenance job id')
|
|
236
503
|
const state = readAutomaticMaintenance(home)
|
|
237
504
|
if (state?.id !== jobId || state.phase !== 'armed' || !Number.isSafeInteger(state.workerPid) || Number(state.workerPid) <= 0) {
|
|
238
505
|
throw new Error('the bridge maintenance job is no longer armed')
|
|
@@ -257,12 +524,13 @@ export async function commitAutomaticMaintenance(jobId: string, home = homePath(
|
|
|
257
524
|
}
|
|
258
525
|
|
|
259
526
|
/** Only the new, authenticated explicit-click endpoint calls this function. */
|
|
260
|
-
export async function startAutomaticMaintenance(action:
|
|
261
|
-
|
|
262
|
-
if (
|
|
527
|
+
export async function startAutomaticMaintenance(action: 'reinstall', root: string, options: AutomaticMaintenanceOptions = {}): Promise<AutomaticMaintenanceJob> {
|
|
528
|
+
requireLiveDesktop()
|
|
529
|
+
if (action !== 'reinstall') throw new Error('invalid bridge maintenance action')
|
|
263
530
|
if (options.locale !== undefined && !['zh', 'en'].includes(options.locale)) throw new Error('invalid bridge maintenance locale')
|
|
531
|
+
const dependency = await preflightReinstall(root, homePath())
|
|
264
532
|
if (!readDesktopIdentity(root).ok) throw new Error('the maintenance target is not a verified DSH Desktop installation')
|
|
265
|
-
if (!existsSync(quitPath)) throw new Error('the packaged Desktop quit helper is missing')
|
|
533
|
+
if (process.platform === 'win32' && !existsSync(quitPath)) throw new Error('the packaged Desktop quit helper is missing')
|
|
266
534
|
const processes = await desktopProcesses(root)
|
|
267
535
|
const mains = processes.filter(p => !/(?:^|\s)--type(?:=|\s)/i.test(p.command))
|
|
268
536
|
if (mains.length !== 1) throw new Error('automatic maintenance requires one running DSH Desktop window')
|
|
@@ -279,20 +547,23 @@ export async function startAutomaticMaintenance(action: BridgeAction, root: stri
|
|
|
279
547
|
}
|
|
280
548
|
let plan: AutomaticPlan | undefined
|
|
281
549
|
try {
|
|
282
|
-
const prepared = await prepareBridgeMaintenance(
|
|
550
|
+
const prepared = await prepareBridgeMaintenance('install', root, { directory: base })
|
|
283
551
|
const original = JSON.parse(await readFile(prepared.planPath, 'utf8')) as { nodePath: string; electronNode: boolean }
|
|
284
|
-
const id = basename(prepared.directory)
|
|
552
|
+
const id = basename(prepared.directory).replace(/^install-/, 'reinstall-')
|
|
553
|
+
const directory = join(base, id)
|
|
554
|
+
await renameMaintenanceFile(prepared.directory, directory)
|
|
555
|
+
const stagedWorker = await stageReinstallRuntime(directory)
|
|
285
556
|
await lock.writeFile(id + '\n')
|
|
286
557
|
await lock.close()
|
|
287
|
-
plan = { version: 1, id, action, root: resolve(root), nodePath: original.nodePath, electronNode: original.electronNode,
|
|
288
|
-
home, directory
|
|
558
|
+
plan = { version: 1, id, action, dependency, nestedResidue: await inspectProfileResidue(home), root: resolve(root), nodePath: original.nodePath, electronNode: original.electronNode,
|
|
559
|
+
home, directory, target: mains[0] as DesktopProcess, createdAt: new Date().toISOString(),
|
|
289
560
|
...options.locale === undefined ? {} : { locale: options.locale } }
|
|
290
|
-
const path = join(
|
|
561
|
+
const path = join(directory, 'automatic.json')
|
|
291
562
|
await writeFile(path, JSON.stringify(plan, null, 2) + '\n', { flag: 'wx', mode: 0o600 })
|
|
292
|
-
await atomicJson(join(base, 'latest.json'), { id, directory
|
|
563
|
+
await atomicJson(join(base, 'latest.json'), { id, directory })
|
|
293
564
|
const launched = await launchMaintenanceBroker({ runtimePath: plan.nodePath,
|
|
294
|
-
args: [...plan.electronNode ? ['--expose-internals'] : [],
|
|
295
|
-
environment: { DSH_HOME: home, ELECTRON_RUN_AS_NODE: plan.electronNode ? '1' : undefined } })
|
|
565
|
+
args: [...plan.electronNode ? ['--expose-internals'] : [], stagedWorker, '--automatic-maintenance', path], cwd: directory,
|
|
566
|
+
environment: { DSH_HOME: home, ELECTRON_RUN_AS_NODE: plan.electronNode ? '1' : undefined, ELECTRON_NO_ASAR: '1' } })
|
|
296
567
|
// WMI's return code proves creation only. The worker must actually load and publish its arm.
|
|
297
568
|
const deadline = Date.now() + 12_000
|
|
298
569
|
while (Date.now() < deadline) {
|
|
@@ -318,9 +589,24 @@ export async function startAutomaticMaintenance(action: BridgeAction, root: stri
|
|
|
318
589
|
}
|
|
319
590
|
}
|
|
320
591
|
|
|
592
|
+
/**
|
|
593
|
+
* Ask the verified macOS Desktop to quit through its own Quit command (Apple event), exactly as
|
|
594
|
+
* Cmd-Q does: any running-task confirmation stays with the user. The pid and start time are
|
|
595
|
+
* re-read first, so a reused pid or a second copy of the app is never asked.
|
|
596
|
+
*/
|
|
597
|
+
async function requestPosixQuit(plan: AutomaticPlan): Promise<void> {
|
|
598
|
+
const current = (await desktopProcesses(plan.root)).filter(p => !/(?:^|\s)--type(?:=|\s)/i.test(p.command))
|
|
599
|
+
if (current.length !== 1 || current[0]?.pid !== plan.target.pid || current[0].started !== plan.target.started) {
|
|
600
|
+
throw new Error('the running Desktop is not the one maintenance was requested from; no quit was sent')
|
|
601
|
+
}
|
|
602
|
+
const result = await execute('osascript', ['-e', 'on run argv', '-e', 'tell application (item 1 of argv) to quit', '-e', 'end run', plan.root], 25_000)
|
|
603
|
+
if (result.code !== 0) throw new Error(result.output || 'the Desktop Quit command was not accepted')
|
|
604
|
+
}
|
|
605
|
+
|
|
321
606
|
async function runWorker(path: string): Promise<void> {
|
|
322
|
-
|
|
607
|
+
requireLiveDesktop()
|
|
323
608
|
const plan = validatePlan(JSON.parse(await readFile(path, 'utf8')), path)
|
|
609
|
+
let extension: InstalledExtension | undefined
|
|
324
610
|
const checkCancelled = (): void => {
|
|
325
611
|
if (existsSync(join(plan.directory, 'cancel.json'))) throw new Error('bridge maintenance was cancelled before Desktop exited')
|
|
326
612
|
}
|
|
@@ -359,6 +645,10 @@ async function runWorker(path: string): Promise<void> {
|
|
|
359
645
|
if (!committed) throw new Error('the maintenance request was not committed; Desktop remains open')
|
|
360
646
|
checkCancelled()
|
|
361
647
|
await publish({ phase: 'closing', action: plan.action, at: new Date().toISOString() })
|
|
648
|
+
if (process.platform !== 'win32') {
|
|
649
|
+
await requestPosixQuit(plan)
|
|
650
|
+
return
|
|
651
|
+
}
|
|
362
652
|
await startMaintenanceProgressNotification({ jobId: plan.id, directory: plan.directory, locale: plan.locale ?? 'zh' })
|
|
363
653
|
const result = await execute(windowsPowerShellPath(), ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-File', quitPath,
|
|
364
654
|
'-TargetPid', String(plan.target.pid), '-ExpectedExecutable', plan.target.path,
|
|
@@ -367,37 +657,59 @@ async function runWorker(path: string): Promise<void> {
|
|
|
367
657
|
if (result.code !== 0) throw new Error(result.output || 'the official Desktop Quit menu was not available')
|
|
368
658
|
},
|
|
369
659
|
waitUntilClosed: async () => {
|
|
370
|
-
|
|
371
|
-
while (Date.now() < deadline) {
|
|
372
|
-
checkCancelled()
|
|
373
|
-
if ((await desktopProcesses(plan.root)).length === 0) return
|
|
374
|
-
await delay(1_000)
|
|
375
|
-
}
|
|
376
|
-
throw new Error('Desktop did not exit; maintenance was cancelled. Any running-task confirmation remains under your control.')
|
|
660
|
+
await waitForDesktopExit({ inspect: async () => await desktopProcesses(plan.root, true), checkCancelled })
|
|
377
661
|
},
|
|
378
662
|
maintain: async () => {
|
|
379
663
|
checkCancelled()
|
|
380
|
-
if ((await desktopProcesses(plan.root)).length > 0) throw new Error('DSH Desktop was reopened during maintenance; refusing to modify its files')
|
|
381
|
-
|
|
664
|
+
if ((await desktopProcesses(plan.root, true)).length > 0) throw new Error('DSH Desktop was reopened during maintenance; refusing to modify its files')
|
|
665
|
+
if (await preflightReinstall(plan.root, plan.home) !== plan.dependency) throw new Error('REINSTALL_DEPENDENCY_CHANGED')
|
|
666
|
+
const bridge = async (action: 'install' | 'uninstall'): Promise<BridgeActionResult> => await runBridgeAction(action, plan.root, {
|
|
382
667
|
node: () => plan.nodePath, installer: defaultInstallerPath, trackResult: true,
|
|
383
668
|
run: async (cmd, args, extra) => await execute(cmd, [...plan.electronNode ? ['--expose-internals'] : [], ...args], 180_000,
|
|
384
|
-
{ ...process.env, ...extra, ELECTRON_RUN_AS_NODE: plan.electronNode ? '1' : undefined }),
|
|
669
|
+
{ ...process.env, ...extra, ELECTRON_RUN_AS_NODE: plan.electronNode ? '1' : undefined, ELECTRON_NO_ASAR: '1' }),
|
|
385
670
|
})
|
|
671
|
+
const profile = async (action: 'install' | 'uninstall'): Promise<BridgeActionResult> => await repairProfileExtension(action, plan.root, plan.home,
|
|
672
|
+
runProfileCommand, plan.dependency)
|
|
673
|
+
return await withProfileCheckpoint(plan.home, plan.directory, async () => {
|
|
674
|
+
const residue = await cleanProfileResidue(plan.home)
|
|
675
|
+
const result = await runReinstallTransaction({
|
|
676
|
+
remove: () => profile('uninstall'),
|
|
677
|
+
absent: async () => {
|
|
678
|
+
const manifest = JSON.parse(await readFile(join(plan.home, 'profiles', 'desktop', 'package.json'), 'utf8')) as { dependencies?: Record<string, unknown> }
|
|
679
|
+
return manifest.dependencies?.[MAIN_EXTENSION_NAME] === undefined && !existsSync(join(plan.home, 'profiles', 'desktop', 'node_modules', MAIN_EXTENSION_NAME))
|
|
680
|
+
},
|
|
681
|
+
revert: () => bridge('uninstall'),
|
|
682
|
+
hostAbsent: () => inspectReinstallHost(plan.root).status === 'absent',
|
|
683
|
+
apply: () => bridge('install'), add: () => profile('install'),
|
|
684
|
+
})
|
|
685
|
+
extension = await installedProfileExtension(plan.home)
|
|
686
|
+
return { ...result, output: [residue, result.output].filter(Boolean).join('\n') }
|
|
687
|
+
}, { reconcile: () => reconcileProfile(plan.root, plan.home) })
|
|
386
688
|
},
|
|
387
689
|
restart: async () => {
|
|
388
|
-
if ((await desktopProcesses(plan.root)).length > 0) throw new Error('DSH Desktop is already running; not opening a second instance')
|
|
690
|
+
if ((await desktopProcesses(plan.root, true)).length > 0) throw new Error('DSH Desktop is already running; not opening a second instance')
|
|
389
691
|
const identity = readDesktopIdentity(plan.root)
|
|
390
692
|
if (!identity.ok) throw new Error(`Desktop cannot be safely reopened: ${identity.reason}`)
|
|
391
|
-
const environment = { ...process.env }
|
|
392
|
-
for (const key of Object.keys(environment))
|
|
693
|
+
const environment: NodeJS.ProcessEnv = { ...process.env, DSH_HOME: plan.home }
|
|
694
|
+
for (const key of Object.keys(environment)) {
|
|
695
|
+
const upper = key.toUpperCase()
|
|
696
|
+
if (upper === 'ELECTRON_RUN_AS_NODE' || upper === 'ELECTRON_NO_ASAR' || upper.startsWith('DSH_BRIDGE_')) {
|
|
697
|
+
delete environment[key]
|
|
698
|
+
}
|
|
699
|
+
}
|
|
393
700
|
return await new Promise<number>((resolve, reject) => {
|
|
394
|
-
const child = spawn(
|
|
701
|
+
const child = spawn(desktopPaths(plan.root).executable, [], { cwd: plan.root, env: environment, stdio: 'ignore', windowsHide: true, detached: true })
|
|
395
702
|
child.once('error', reject)
|
|
396
703
|
child.once('spawn', () => { child.unref(); resolve(child.pid as number) })
|
|
397
704
|
})
|
|
398
705
|
},
|
|
399
706
|
verify: async (pid, action) => {
|
|
400
|
-
if (action === '
|
|
707
|
+
if (action === 'reinstall') {
|
|
708
|
+
if (inspectReinstallHost(plan.root).status !== 'applied') throw new Error('REINSTALL_HOST_VERIFY_FAILED')
|
|
709
|
+
await waitForRestartedBridge(pid, { timeoutMs: 45_000, endpointPath: join(plan.home, 'dsh-builtin-browser-bridge.json'),
|
|
710
|
+
...(extension === undefined ? {} : { extension, home: plan.home }) })
|
|
711
|
+
return
|
|
712
|
+
}
|
|
401
713
|
await delay(1_500)
|
|
402
714
|
if (!(await desktopProcesses(plan.root)).some(p => p.pid === pid)) throw new Error('the reopened Desktop did not remain running')
|
|
403
715
|
},
|