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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LOOPBACK_IPV4 } from '../../assets/browser-policy.mjs';
|
|
1
2
|
import { readFileSync } from 'node:fs';
|
|
2
3
|
/**
|
|
3
4
|
* Transport for the desktop shell's browser bridge: one long-lived connection to a
|
|
@@ -19,6 +20,7 @@ import { readFileSync } from 'node:fs';
|
|
|
19
20
|
* @module dsh-browser/browser-electron/bridge-connection
|
|
20
21
|
*/
|
|
21
22
|
import { connect } from 'node:net';
|
|
23
|
+
import { bridgePackageError } from '../bridge-compatibility.js';
|
|
22
24
|
/**
|
|
23
25
|
* Safety cap on one un-answered reply line. CDP answers from the sidebar (a screenshot's
|
|
24
26
|
* base64 is the big one) cross this socket, so the cap is generous; what it exists for is a
|
|
@@ -229,7 +231,7 @@ export class BridgeConnection {
|
|
|
229
231
|
ensureSocket() {
|
|
230
232
|
if (this.socket !== undefined)
|
|
231
233
|
return this.socket;
|
|
232
|
-
const socket = connect({ host:
|
|
234
|
+
const socket = connect({ host: LOOPBACK_IPV4, port: this.endpoint.port });
|
|
233
235
|
socket.setEncoding('utf8');
|
|
234
236
|
socket.on('data', chunk => this.onData(String(chunk)));
|
|
235
237
|
// Both handlers pass the socket they belong to, so a late event from a socket that was
|
|
@@ -289,6 +291,11 @@ export class BridgeConnection {
|
|
|
289
291
|
}
|
|
290
292
|
try {
|
|
291
293
|
const answer = JSON.parse(line);
|
|
294
|
+
const packageError = bridgePackageError(answer);
|
|
295
|
+
if (packageError !== undefined) {
|
|
296
|
+
entry.reject(packageError);
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
292
299
|
// A rejected token means the shell restarted with a new one, so this socket
|
|
293
300
|
// can never succeed again: answer (the caller needs the error) and drop it,
|
|
294
301
|
// so the next call dials afresh instead of retrying a doomed credential.
|
|
@@ -13,6 +13,18 @@ import { join } from 'node:path';
|
|
|
13
13
|
import { fileURLToPath } from 'node:url';
|
|
14
14
|
import { BridgeConnection } from './bridge-connection.js';
|
|
15
15
|
import { bridgeEndpointPath } from './paths.js';
|
|
16
|
+
import { extensionHomeId } from './profile-extension.js';
|
|
17
|
+
export async function runBridgeReinstall(deps) {
|
|
18
|
+
const removed = deps.absent() ? undefined : await deps.run('uninstall');
|
|
19
|
+
if (removed && !removed.ok)
|
|
20
|
+
throw new Error(`REINSTALL_REMOVE_FAILED: ${removed.output}`);
|
|
21
|
+
if (!deps.absent())
|
|
22
|
+
throw new Error('REINSTALL_REMOVE_FAILED: bridge remains installed');
|
|
23
|
+
const installed = await deps.run('install');
|
|
24
|
+
if (!installed.ok)
|
|
25
|
+
throw new Error(`REINSTALL_ADD_FAILED: ${installed.output}`);
|
|
26
|
+
return { ...installed, output: [removed?.output, installed.output].filter(Boolean).join('\n').slice(-20_000) };
|
|
27
|
+
}
|
|
16
28
|
/**
|
|
17
29
|
* Verify that the restarted process published a working authenticated bridge.
|
|
18
30
|
* A previous shell's endpoint, a listening socket, or an authentication refusal is insufficient.
|
|
@@ -32,8 +44,16 @@ export async function waitForRestartedBridge(pid, options = {}) {
|
|
|
32
44
|
break;
|
|
33
45
|
const connection = new BridgeConnection({ port: Number(endpoint.port), token: endpoint.token, pid });
|
|
34
46
|
try {
|
|
47
|
+
if (options.extension !== undefined) {
|
|
48
|
+
const version = await connection.call({ op: 'version' }, Math.min(1_000, remaining));
|
|
49
|
+
const status = version.mainExtension;
|
|
50
|
+
if (version.ok !== true || version.bridgeVersion !== options.extension.version || version.bridgeBuild !== options.extension.build
|
|
51
|
+
|| version.homeId !== extensionHomeId(options.home ?? '') || status?.state !== 'loaded'
|
|
52
|
+
|| status.version !== options.extension.version || typeof status.loadedAt !== 'string' || !Number.isFinite(Date.parse(status.loadedAt)))
|
|
53
|
+
throw new Error('EXTENSION_RESTART_REQUIRED');
|
|
54
|
+
}
|
|
35
55
|
const answer = await connection.call({ op: 'list' }, Math.min(1_000, remaining));
|
|
36
|
-
if (answer.ok === true &&
|
|
56
|
+
if (answer.ok === true && Number(answer.protocol) >= 4)
|
|
37
57
|
return;
|
|
38
58
|
}
|
|
39
59
|
finally {
|
|
@@ -80,6 +100,10 @@ export async function waitForBridgeActionCompletion(path, action, timeoutMs = 18
|
|
|
80
100
|
|| typeof record.completedAt !== 'string' || !Number.isFinite(Date.parse(record.completedAt))
|
|
81
101
|
|| record.pid !== undefined
|
|
82
102
|
|| (record.error !== undefined && typeof record.error !== 'string')
|
|
103
|
+
|| (record.hostPatch !== undefined && (record.hostPatch === null || typeof record.hostPatch !== 'object'
|
|
104
|
+
|| !['absent', 'applied', 'unsupported version', 'anchors mismatch'].includes(record.hostPatch.status)
|
|
105
|
+
|| (record.hostPatch.reason !== undefined && typeof record.hostPatch.reason !== 'string')
|
|
106
|
+
|| (record.hostPatch.changed !== undefined && typeof record.hostPatch.changed !== 'boolean')))
|
|
83
107
|
|| (record.ok !== (record.code === 0))) {
|
|
84
108
|
throw new Error('the bridge installer wrote an invalid completion record');
|
|
85
109
|
}
|
|
@@ -201,7 +225,8 @@ export async function runBridgeAction(action, installRoot, deps = {
|
|
|
201
225
|
const final = await waitForBridgeActionCompletion(resultFile, action, Math.max(0, deadline - Date.now()), deps.resultPollMs);
|
|
202
226
|
const output = [installerOutput, await recordedOutput(), final.error].filter(Boolean).join('\n');
|
|
203
227
|
return { ok: final.ok, code: final.code, output: tail(output), command: printable, resultFile, logFile,
|
|
204
|
-
restarted: final.restarted, ...final.pid === undefined ? {} : { pid: final.pid }
|
|
228
|
+
restarted: final.restarted, ...final.pid === undefined ? {} : { pid: final.pid },
|
|
229
|
+
...final.hostPatch === undefined ? {} : { hostPatch: final.hostPatch } };
|
|
205
230
|
}
|
|
206
231
|
catch (error) {
|
|
207
232
|
return { ok: false, code: null,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { BROWSER_PROFILE_DIR } from '../../assets/browser-policy.mjs';
|
|
1
2
|
/**
|
|
2
|
-
* Prepare
|
|
3
|
+
* Prepare bridge maintenance (Windows `.cmd`, macOS `.command`) for the user to run after exiting DSH Desktop.
|
|
3
4
|
* Preparation writes a private launcher and plan; it never starts a process or changes Desktop.
|
|
4
5
|
* The current packaged installer performs identity and running-process checks at execution time.
|
|
5
6
|
* @module dsh-browser/browser-electron/bridge-maintenance
|
|
@@ -8,7 +9,7 @@ import { existsSync, realpathSync, statSync } from 'node:fs';
|
|
|
8
9
|
import { mkdir, mkdtemp, writeFile } from 'node:fs/promises';
|
|
9
10
|
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
10
11
|
import { fileURLToPath } from 'node:url';
|
|
11
|
-
import { readDesktopIdentity } from './desktop-identity.js';
|
|
12
|
+
import { desktopLayout, desktopPaths, readDesktopIdentity } from './desktop-identity.js';
|
|
12
13
|
import { dshHome as dshHomePath } from './paths.js';
|
|
13
14
|
/** Batch literals cannot contain these characters; other path content stays in JSON arguments. */
|
|
14
15
|
function checkedPath(value, label) {
|
|
@@ -37,6 +38,27 @@ function prospectiveRealPath(path) {
|
|
|
37
38
|
}
|
|
38
39
|
return resolve(realpathSync(ancestor), ...missing);
|
|
39
40
|
}
|
|
41
|
+
/** Case-insensitive on Windows; elsewhere both sides are already on-disk spellings (`realpathSync.native`). */
|
|
42
|
+
function samePath(a, b) {
|
|
43
|
+
return process.platform === 'win32' ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
44
|
+
}
|
|
45
|
+
/** One POSIX shell word: single-quoted, with embedded quotes closed and escaped. */
|
|
46
|
+
function shellLiteral(value) {
|
|
47
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
48
|
+
}
|
|
49
|
+
/** The macOS launcher: a `.command` file Finder opens in Terminal; paths stay single-quoted literals. */
|
|
50
|
+
function posixLauncher(nodePath, electronNode) {
|
|
51
|
+
return [
|
|
52
|
+
'#!/bin/sh',
|
|
53
|
+
'echo "Quit DSH Desktop normally before running bridge maintenance."',
|
|
54
|
+
'cd "$(dirname "$0")" || exit 1',
|
|
55
|
+
`${electronNode ? 'ELECTRON_RUN_AS_NODE=1 ' : 'ELECTRON_RUN_AS_NODE= '}${shellLiteral(nodePath)}${electronNode ? ' --expose-internals' : ''} ./run-maintenance.mjs`,
|
|
56
|
+
'code=$?',
|
|
57
|
+
'if [ "$code" -eq 0 ]; then echo "Bridge maintenance completed. You can now open DSH Desktop."; else echo "Bridge maintenance failed. Read the reason above, then prepare maintenance again if needed."; fi',
|
|
58
|
+
'exit "$code"',
|
|
59
|
+
'',
|
|
60
|
+
].join('\n');
|
|
61
|
+
}
|
|
40
62
|
/** This runner is deliberately data-driven: paths and actions are never evaluated as shell text. */
|
|
41
63
|
const RUNNER = `import { readFileSync, existsSync } from 'node:fs';
|
|
42
64
|
import { isAbsolute } from 'node:path';
|
|
@@ -73,14 +95,14 @@ export async function prepareBridgeMaintenance(action, installRoot, options = {}
|
|
|
73
95
|
const installerPath = fileURLToPath(new URL('../../desktop-bridge/install.mjs', import.meta.url));
|
|
74
96
|
if (!existsSync(installerPath))
|
|
75
97
|
throw new Error('the packaged bridge installer is missing');
|
|
98
|
+
const desktopRuntime = desktopPaths(target).executable;
|
|
76
99
|
const currentIsNode = /^(?:node|node\.exe)$/i.test(basename(process.execPath));
|
|
77
|
-
const selected = options.nodePath ?? (currentIsNode ? process.execPath :
|
|
100
|
+
const selected = options.nodePath ?? (currentIsNode ? process.execPath : desktopRuntime);
|
|
78
101
|
const nodePath = checkedPath(selected, 'Maintenance runtime');
|
|
79
102
|
if (!existsSync(nodePath) || !statSync(nodePath).isFile())
|
|
80
103
|
throw new Error('the maintenance runtime does not exist');
|
|
81
104
|
const electronNode = !/^(?:node|node\.exe)$/i.test(basename(nodePath));
|
|
82
|
-
|
|
83
|
-
if (electronNode && (!existsSync(desktopRuntime) || realpathSync(nodePath).toLowerCase() !== realpathSync(desktopRuntime).toLowerCase())) {
|
|
105
|
+
if (electronNode && (!existsSync(desktopRuntime) || !samePath(realpathSync.native(nodePath), realpathSync.native(desktopRuntime)))) {
|
|
84
106
|
throw new Error('the Electron maintenance runtime must belong to the verified Desktop installation');
|
|
85
107
|
}
|
|
86
108
|
const dshHome = checkedPath(dshHomePath(), 'DSH home');
|
|
@@ -88,7 +110,7 @@ export async function prepareBridgeMaintenance(action, installRoot, options = {}
|
|
|
88
110
|
if (testContext && options.directory === undefined && process.env.DSH_BRIDGE_TEST_ROOT === undefined) {
|
|
89
111
|
throw new Error('test preparation requires an explicit private maintenance directory');
|
|
90
112
|
}
|
|
91
|
-
const directory = checkedPath(options.directory ?? join(dshHome,
|
|
113
|
+
const directory = checkedPath(options.directory ?? join(dshHome, BROWSER_PROFILE_DIR, 'maintenance'), 'Maintenance directory');
|
|
92
114
|
if (withinOrEqual(target, directory) || withinOrEqual(target, prospectiveRealPath(directory))) {
|
|
93
115
|
throw new Error('maintenance launchers must be stored outside the Desktop installation');
|
|
94
116
|
}
|
|
@@ -98,9 +120,10 @@ export async function prepareBridgeMaintenance(action, installRoot, options = {}
|
|
|
98
120
|
const output = await mkdtemp(join(directory, `${action}-`));
|
|
99
121
|
const runnerPath = join(output, 'run-maintenance.mjs');
|
|
100
122
|
const planPath = join(output, 'maintenance.json');
|
|
101
|
-
const
|
|
123
|
+
const bundle = desktopLayout(target).name === 'macos-bundle';
|
|
124
|
+
const path = join(output, `${action === 'uninstall' ? 'uninstall' : 'install'}-bridge.${bundle ? 'command' : 'cmd'}`);
|
|
102
125
|
const plan = { version: 1, action, installRoot: target, installerPath, nodePath, electronNode, dshHome };
|
|
103
|
-
const command = [
|
|
126
|
+
const command = bundle ? posixLauncher(nodePath, electronNode) : [
|
|
104
127
|
'@echo off',
|
|
105
128
|
'setlocal DisableDelayedExpansion',
|
|
106
129
|
'chcp 65001 >nul',
|
|
@@ -120,6 +143,8 @@ export async function prepareBridgeMaintenance(action, installRoot, options = {}
|
|
|
120
143
|
].join('\r\n');
|
|
121
144
|
await writeFile(planPath, JSON.stringify(plan, null, 2) + '\n', { flag: 'wx', mode: 0o600 });
|
|
122
145
|
await writeFile(runnerPath, RUNNER, { flag: 'wx', mode: 0o600 });
|
|
123
|
-
await writeFile(path, command, { flag: 'wx', mode: 0o600 });
|
|
124
|
-
return
|
|
146
|
+
await writeFile(path, command, { flag: 'wx', mode: bundle ? 0o700 : 0o600 });
|
|
147
|
+
return bundle
|
|
148
|
+
? { ok: true, prepared: true, action, path, command: shellLiteral(path), commandShell: 'sh', directory: output, runnerPath, planPath }
|
|
149
|
+
: { ok: true, prepared: true, action, path, command: `& '${path.replace(/'/g, "''")}'`, commandShell: 'powershell', directory: output, runnerPath, planPath };
|
|
125
150
|
}
|
|
@@ -14,11 +14,15 @@
|
|
|
14
14
|
* - `stale` — the archive is back, or the deployed bridge module is missing or outdated.
|
|
15
15
|
* @module dsh-browser/browser-electron/bridge-status
|
|
16
16
|
*/
|
|
17
|
-
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
18
|
-
import {
|
|
17
|
+
import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from 'node:fs';
|
|
18
|
+
import { homedir } from 'node:os';
|
|
19
|
+
import { isAbsolute, join, relative } from 'node:path';
|
|
19
20
|
import { fileURLToPath } from 'node:url';
|
|
20
21
|
import { createRequire } from 'node:module';
|
|
21
|
-
import { readDesktopIdentity } from './desktop-identity.js';
|
|
22
|
+
import { desktopPaths, readDesktopIdentity } from './desktop-identity.js';
|
|
23
|
+
import { MAIN_EXTENSION_UNSUPPORTED } from './profile-extension.js';
|
|
24
|
+
import { BRIDGE_VERSION_MESSAGE } from '../bridge-compatibility.js';
|
|
25
|
+
import { conventionalInstallRoots, registeredInstallLocations } from '../../desktop-bridge/desktop-discovery.mjs';
|
|
22
26
|
// A normal Electron existsSync(app.asar) caches the archive and keeps it locked on Windows.
|
|
23
27
|
// Status inspection must leave maintenance free to rename it after Desktop exits.
|
|
24
28
|
const rawExistsSync = (() => {
|
|
@@ -40,35 +44,32 @@ const rawExistsSync = (() => {
|
|
|
40
44
|
* @param localAppData - the base directory; defaults to the environment's.
|
|
41
45
|
* @returns the install directory, or undefined when nothing matches.
|
|
42
46
|
*/
|
|
43
|
-
export function findDesktopInstall(localAppData) {
|
|
47
|
+
export function findDesktopInstall(localAppData, registry = registeredInstallLocations, conventions = conventionalInstallRoots) {
|
|
44
48
|
// Not every install lives in %LOCALAPPDATA%\\Programs: people put the app on another drive, under
|
|
45
49
|
// Program Files, or in their own folder. DSH_DESKTOP_PATH names one explicitly, and the usual roots
|
|
46
50
|
// are all probed. A test or a caller that passes a base directory gets exactly that base, so the
|
|
47
51
|
// behaviour stays pinnable.
|
|
48
52
|
const isDesktop = (candidate) => readDesktopIdentity(candidate).ok;
|
|
49
|
-
const explicit
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
for (const explicit of [process.env.DSH_DESKTOP_PATH, process.env.DSH_DESKTOP_APP]) {
|
|
54
|
+
if (explicit !== undefined && explicit !== '') {
|
|
55
|
+
const named = explicit;
|
|
56
|
+
if (isDesktop(named))
|
|
57
|
+
return named;
|
|
58
|
+
// A parent directory is a reasonable thing to point at too: look one level down.
|
|
59
|
+
try {
|
|
60
|
+
for (const entry of readdirSync(named, { withFileTypes: true })) {
|
|
61
|
+
if (entry.isDirectory() && isDesktop(join(named, entry.name)))
|
|
62
|
+
return join(named, entry.name);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// Not a directory: fall through to the usual roots.
|
|
59
67
|
}
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
// Not a directory: fall through to the usual roots.
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
|
-
const roots = localAppData === undefined
|
|
66
|
-
? [process.env.LOCALAPPDATA ?? '', process.env['ProgramFiles'] ?? '', process.env['ProgramFiles(x86)'] ?? '', process.env.APPDATA ?? '', process.env.ProgramData ?? '']
|
|
67
|
-
.filter(base => base !== '')
|
|
68
|
-
.map(base => (base === process.env.LOCALAPPDATA ? join(base, 'Programs') : base))
|
|
69
|
-
: [join(localAppData, 'Programs')];
|
|
70
|
+
const roots = localAppData === undefined ? desktopInstallRoots() : [join(localAppData, 'Programs')];
|
|
70
71
|
for (const base of roots) {
|
|
71
|
-
for (const named of
|
|
72
|
+
for (const named of DESKTOP_INSTALL_NAMES) {
|
|
72
73
|
const candidate = join(base, named);
|
|
73
74
|
if (isDesktop(candidate))
|
|
74
75
|
return candidate;
|
|
@@ -86,8 +87,31 @@ export function findDesktopInstall(localAppData) {
|
|
|
86
87
|
// A root that does not exist is a state, not an error.
|
|
87
88
|
}
|
|
88
89
|
}
|
|
90
|
+
for (const source of [registry, conventions]) {
|
|
91
|
+
try {
|
|
92
|
+
for (const candidate of source()) {
|
|
93
|
+
if (isDesktop(candidate))
|
|
94
|
+
return candidate;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch { }
|
|
98
|
+
}
|
|
89
99
|
return undefined;
|
|
90
100
|
}
|
|
101
|
+
/** Directory names an install is given: a plain directory on Windows, an `.app` bundle on macOS. */
|
|
102
|
+
const DESKTOP_INSTALL_NAMES = ['DSH Desktop', 'DeepSeek Harness', 'DSH Desktop.app', 'DeepSeek Harness.app'];
|
|
103
|
+
/**
|
|
104
|
+
* Where this OS keeps installed applications, most specific first.
|
|
105
|
+
* @returns the existing-or-not base directories to probe.
|
|
106
|
+
*/
|
|
107
|
+
function desktopInstallRoots() {
|
|
108
|
+
const windows = [process.env.LOCALAPPDATA ?? '', process.env['ProgramFiles'] ?? '', process.env['ProgramFiles(x86)'] ?? '', process.env.APPDATA ?? '', process.env.ProgramData ?? '']
|
|
109
|
+
.filter(base => base !== '')
|
|
110
|
+
.map(base => (base === process.env.LOCALAPPDATA ? join(base, 'Programs') : base));
|
|
111
|
+
// The machine-wide macOS roots cannot be redirected, so a test process never reads them.
|
|
112
|
+
const testing = process.env.DSH_BROWSER_TEST === '1' || process.env.NODE_TEST_CONTEXT !== undefined;
|
|
113
|
+
return process.platform === 'darwin' && !testing ? [...windows, '/Applications', join(homedir(), 'Applications')] : windows;
|
|
114
|
+
}
|
|
91
115
|
/** The marker the installer inserts into the shell's main.js. */
|
|
92
116
|
const MARKER = '// dsh-builtin-browser: hand the plugin a way to drive the sidebar';
|
|
93
117
|
/**
|
|
@@ -134,8 +158,22 @@ function repairCommand(installRoot) {
|
|
|
134
158
|
* @param installRoot - the desktop install directory.
|
|
135
159
|
* @returns the current state.
|
|
136
160
|
*/
|
|
137
|
-
export function readBridgeStatus(installRoot) {
|
|
138
|
-
const
|
|
161
|
+
export function readBridgeStatus(installRoot, mainExtension) {
|
|
162
|
+
const disk = readBridgeInstallStatus(installRoot);
|
|
163
|
+
if (mainExtension === undefined)
|
|
164
|
+
return { ...disk, code: disk.code ?? MAIN_EXTENSION_UNSUPPORTED };
|
|
165
|
+
return { ...disk, mainExtension, command: undefined, detail: `desktop main extension: ${mainExtension.state}`,
|
|
166
|
+
state: mainExtension.state === 'loaded' ? 'installed' : mainExtension.state === 'not-installed' ? 'missing' : 'stale',
|
|
167
|
+
code: mainExtension.code };
|
|
168
|
+
}
|
|
169
|
+
function readBridgeInstallStatus(installRoot) {
|
|
170
|
+
let resources;
|
|
171
|
+
try {
|
|
172
|
+
resources = desktopPaths(installRoot).resources;
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
return { state: 'missing', present: false, installRoot, archivePresent: false, detail: `not a DSH Desktop install: ${String(error)}` };
|
|
176
|
+
}
|
|
139
177
|
const appDir = join(resources, 'app');
|
|
140
178
|
const mainPath = join(appDir, 'lib', 'main.js');
|
|
141
179
|
const archivePath = join(resources, 'app.asar');
|
|
@@ -169,6 +207,16 @@ export function readBridgeStatus(installRoot) {
|
|
|
169
207
|
detail: 'not a DSH Desktop install: no resources/app/lib/main.js and no resources/app.asar',
|
|
170
208
|
};
|
|
171
209
|
}
|
|
210
|
+
if (!rawExistsSync(archivePath)
|
|
211
|
+
&& safeIncludes(mainPath, '//#region lib/types/main-extensions.js')
|
|
212
|
+
&& safeExists(fileURLToPath(new URL('../../desktop-bridge/main.mjs', import.meta.url)))) {
|
|
213
|
+
return {
|
|
214
|
+
state: 'installed', present: true, installRoot, archivePresent: false,
|
|
215
|
+
detail: 'DSH Desktop main extension loads the bridge from the installed profile plugin',
|
|
216
|
+
...identity.version === undefined ? {} : { version: identity.version },
|
|
217
|
+
command: repairCommand(installRoot),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
172
220
|
let backupAt;
|
|
173
221
|
try {
|
|
174
222
|
if (existsSync(backupPath))
|
|
@@ -218,17 +266,40 @@ export function readBridgeStatus(installRoot) {
|
|
|
218
266
|
}
|
|
219
267
|
const bridgePath = join(appDir, 'lib', 'plugin-browser-bridge.js');
|
|
220
268
|
let bridgeDetail;
|
|
269
|
+
let bridgeCode;
|
|
221
270
|
try {
|
|
222
271
|
const deployed = readFileSync(bridgePath);
|
|
223
272
|
const shipped = readFileSync(new URL('../../desktop-bridge/plugin-browser-bridge.js', import.meta.url));
|
|
224
|
-
|
|
225
|
-
|
|
273
|
+
const loader = readFileSync(new URL('../../desktop-bridge/profile-loader.mjs', import.meta.url));
|
|
274
|
+
if (deployed.equals(loader)) {
|
|
275
|
+
try {
|
|
276
|
+
const profile = join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'profiles', 'desktop');
|
|
277
|
+
const manifest = JSON.parse(readFileSync(join(profile, 'package.json'), 'utf8'));
|
|
278
|
+
if (!Object.hasOwn(manifest.dependencies ?? {}, 'dsh-builtin-browser'))
|
|
279
|
+
throw new Error('not a direct profile dependency');
|
|
280
|
+
const directory = realpathSync(join(profile, 'node_modules', 'dsh-builtin-browser'));
|
|
281
|
+
const entry = realpathSync(join(directory, 'desktop-bridge', 'plugin-browser-bridge.js'));
|
|
282
|
+
const child = relative(directory, entry);
|
|
283
|
+
if (!child || isAbsolute(child) || child === '..' || child.startsWith('../') || child.startsWith('..\\')) {
|
|
284
|
+
throw new Error('bridge entry resolves outside its package');
|
|
285
|
+
}
|
|
286
|
+
if (!readFileSync(entry).equals(shipped))
|
|
287
|
+
bridgeDetail = BRIDGE_VERSION_MESSAGE;
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
bridgeCode = 'DSH_BRIDGE_PACKAGE_UNAVAILABLE';
|
|
291
|
+
bridgeDetail = `${bridgeCode}: the profile loader's package bridge is missing, unreadable or outside its package`;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
else if (!deployed.equals(shipped))
|
|
295
|
+
bridgeDetail = BRIDGE_VERSION_MESSAGE;
|
|
226
296
|
}
|
|
227
297
|
catch {
|
|
228
298
|
bridgeDetail = 'the bridge module is missing or cannot be verified; reinstall the bridge to restore it';
|
|
229
299
|
}
|
|
230
300
|
return {
|
|
231
301
|
state: bridgeDetail === undefined ? 'installed' : 'stale',
|
|
302
|
+
...bridgeCode === undefined ? {} : { code: bridgeCode },
|
|
232
303
|
present: true,
|
|
233
304
|
installRoot,
|
|
234
305
|
archivePresent,
|