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 { BROWSER_PROFILE_DIR } from '../../assets/browser-policy.mjs'
|
|
1
2
|
/**
|
|
2
3
|
* Compatibility for historical automatic-install settings and explicit bridge-maintenance intent.
|
|
3
4
|
* Runtime automatic installation is disabled. Bridge maintenance requires the user to close DSH
|
|
@@ -8,9 +9,9 @@
|
|
|
8
9
|
import { existsSync, mkdirSync, readFileSync } from 'node:fs'
|
|
9
10
|
import { dirname, join } from 'node:path'
|
|
10
11
|
|
|
11
|
-
import type { BridgeStatus } from './bridge-status.
|
|
12
|
-
import type { BrowserChannel } from './system-browser.
|
|
13
|
-
import { writeFileAtomic } from './settings-store.
|
|
12
|
+
import type { BridgeStatus } from './bridge-status.ts'
|
|
13
|
+
import type { BrowserChannel } from './system-browser.ts'
|
|
14
|
+
import { writeFileAtomic } from './settings-store.ts'
|
|
14
15
|
|
|
15
16
|
/** What the last automatic attempt was, and for which desktop build. */
|
|
16
17
|
export interface AutoInstallMarker {
|
|
@@ -114,7 +115,7 @@ export async function runWithManualBridgePreference<T>(
|
|
|
114
115
|
|
|
115
116
|
/** Where the attempt record lives, beside the settings the plugin already owns. */
|
|
116
117
|
export function autoInstallMarkerPath(dshHome: string): string {
|
|
117
|
-
return join(dshHome,
|
|
118
|
+
return join(dshHome, BROWSER_PROFILE_DIR, 'bridge-auto-install.json')
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
/**
|
|
@@ -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
|
|
@@ -20,6 +21,18 @@ import { readFileSync } from 'node:fs'
|
|
|
20
21
|
*/
|
|
21
22
|
|
|
22
23
|
import { connect, type Socket } from 'node:net'
|
|
24
|
+
import type { BrowserSessionWireId, BrowserTabWireId } from '../browser/handles.ts'
|
|
25
|
+
import { bridgePackageError } from '../bridge-compatibility.ts'
|
|
26
|
+
|
|
27
|
+
export type BridgeRequest =
|
|
28
|
+
| { readonly op: 'version' }
|
|
29
|
+
| { readonly op: 'list'; readonly handle?: BrowserSessionWireId }
|
|
30
|
+
| { readonly op: 'collapseSidebar' | 'releaseSession'; readonly handle: BrowserSessionWireId }
|
|
31
|
+
| { readonly op: 'ensureSidebar'; readonly handle: BrowserTabWireId; readonly deadline: number; readonly transactionId: string; readonly url?: string; readonly attachOnly?: boolean }
|
|
32
|
+
| { readonly op: 'cancelSidebar'; readonly handle: BrowserTabWireId; readonly transactionId: string }
|
|
33
|
+
| { readonly op: 'adoptPage' | 'closePage' | 'showTab' | 'releaseTab'; readonly handle: BrowserTabWireId }
|
|
34
|
+
| { readonly op: 'download'; readonly handle: BrowserTabWireId; readonly url: string; readonly savePath: string }
|
|
35
|
+
| { readonly op: 'cdp'; readonly handle: BrowserTabWireId; readonly method: string; readonly params?: Record<string, unknown> }
|
|
23
36
|
|
|
24
37
|
/** Where the shell publishes its bridge endpoint. */
|
|
25
38
|
export interface BridgeEndpoint {
|
|
@@ -171,7 +184,7 @@ export class BridgeConnection {
|
|
|
171
184
|
* @param timeoutMs - how long to wait for the answer before dropping the socket.
|
|
172
185
|
* @returns the bridge's answer.
|
|
173
186
|
*/
|
|
174
|
-
async call(request:
|
|
187
|
+
async call(request: BridgeRequest, timeoutMs = 20_000): Promise<Record<string, unknown>> {
|
|
175
188
|
// One re-dial, and only for the case this exists for: a socket that has already carried
|
|
176
189
|
// an id-less answer cannot have a second request in flight, because two outstanding
|
|
177
190
|
// requests would be matched by position — the swap this correlation prevents. It is a
|
|
@@ -243,7 +256,7 @@ export class BridgeConnection {
|
|
|
243
256
|
/** The live socket, connecting and authenticating it on first use. */
|
|
244
257
|
private ensureSocket(): Socket {
|
|
245
258
|
if (this.socket !== undefined) return this.socket
|
|
246
|
-
const socket = connect({ host:
|
|
259
|
+
const socket = connect({ host: LOOPBACK_IPV4, port: this.endpoint.port })
|
|
247
260
|
socket.setEncoding('utf8')
|
|
248
261
|
socket.on('data', chunk => this.onData(String(chunk)))
|
|
249
262
|
// Both handlers pass the socket they belong to, so a late event from a socket that was
|
|
@@ -301,6 +314,11 @@ export class BridgeConnection {
|
|
|
301
314
|
}
|
|
302
315
|
try {
|
|
303
316
|
const answer = JSON.parse(line) as Record<string, unknown>
|
|
317
|
+
const packageError = bridgePackageError(answer)
|
|
318
|
+
if (packageError !== undefined) {
|
|
319
|
+
entry.reject(packageError)
|
|
320
|
+
continue
|
|
321
|
+
}
|
|
304
322
|
// A rejected token means the shell restarted with a new one, so this socket
|
|
305
323
|
// can never succeed again: answer (the caller needs the error) and drop it,
|
|
306
324
|
// so the next call dials afresh instead of retrying a doomed credential.
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import { existsSync, readFileSync, statSync } from 'node:fs'
|
|
24
24
|
|
|
25
|
-
import { ENDPOINT_STALE_AFTER_MS } from './bridge-connection.
|
|
26
|
-
import { bridgeEndpointPath } from './desktop-bridge-host.
|
|
27
|
-
import { pidAlive } from './process.
|
|
25
|
+
import { ENDPOINT_STALE_AFTER_MS } from './bridge-connection.ts'
|
|
26
|
+
import { bridgeEndpointPath } from './desktop-bridge-host.ts'
|
|
27
|
+
import { pidAlive } from './process.ts'
|
|
28
28
|
|
|
29
29
|
/** What the panel needs to know about the running shell. */
|
|
30
30
|
export interface BridgeEndpointState {
|
|
@@ -11,12 +11,20 @@ import { mkdtemp, readFile } from 'node:fs/promises'
|
|
|
11
11
|
import { tmpdir } from 'node:os'
|
|
12
12
|
import { join } from 'node:path'
|
|
13
13
|
import { fileURLToPath } from 'node:url'
|
|
14
|
-
import { BridgeConnection } from './bridge-connection.
|
|
15
|
-
import { bridgeEndpointPath } from './paths.
|
|
14
|
+
import { BridgeConnection } from './bridge-connection.ts'
|
|
15
|
+
import { bridgeEndpointPath } from './paths.ts'
|
|
16
|
+
import { extensionHomeId, type InstalledExtension } from './profile-extension.ts'
|
|
16
17
|
|
|
17
18
|
/** What the panel may ask for. */
|
|
18
19
|
export type BridgeAction = 'install' | 'uninstall'
|
|
19
20
|
|
|
21
|
+
/** Independent result of the optional, version-gated DSH host patch. */
|
|
22
|
+
export interface HostPatchResult {
|
|
23
|
+
readonly status: 'absent' | 'applied' | 'unsupported version' | 'anchors mismatch'
|
|
24
|
+
readonly reason?: string
|
|
25
|
+
readonly changed?: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
20
28
|
/** Everything this module touches from outside, so a test can drive it without spawning. */
|
|
21
29
|
export interface BridgeActionDeps {
|
|
22
30
|
/** Runs the installer; resolves with an exit code and the tail of its output. */
|
|
@@ -48,6 +56,19 @@ export interface BridgeActionResult {
|
|
|
48
56
|
readonly logFile?: string
|
|
49
57
|
readonly restarted?: boolean
|
|
50
58
|
readonly pid?: number
|
|
59
|
+
readonly hostPatch?: HostPatchResult
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function runBridgeReinstall(deps: {
|
|
63
|
+
readonly absent: () => boolean
|
|
64
|
+
readonly run: (action: BridgeAction) => Promise<BridgeActionResult>
|
|
65
|
+
}): Promise<BridgeActionResult> {
|
|
66
|
+
const removed = deps.absent() ? undefined : await deps.run('uninstall')
|
|
67
|
+
if (removed && !removed.ok) throw new Error(`REINSTALL_REMOVE_FAILED: ${removed.output}`)
|
|
68
|
+
if (!deps.absent()) throw new Error('REINSTALL_REMOVE_FAILED: bridge remains installed')
|
|
69
|
+
const installed = await deps.run('install')
|
|
70
|
+
if (!installed.ok) throw new Error(`REINSTALL_ADD_FAILED: ${installed.output}`)
|
|
71
|
+
return { ...installed, output: [removed?.output, installed.output].filter(Boolean).join('\n').slice(-20_000) }
|
|
51
72
|
}
|
|
52
73
|
|
|
53
74
|
/** Final record written by the installer that actually performed the operation. */
|
|
@@ -59,6 +80,7 @@ export interface BridgeActionCompletion {
|
|
|
59
80
|
readonly pid?: number
|
|
60
81
|
readonly error?: string
|
|
61
82
|
readonly completedAt: string
|
|
83
|
+
readonly hostPatch?: HostPatchResult
|
|
62
84
|
}
|
|
63
85
|
|
|
64
86
|
/** Read-only startup verification, with a private endpoint path available to isolated tests. */
|
|
@@ -66,6 +88,8 @@ export interface BridgeReadyOptions {
|
|
|
66
88
|
readonly endpointPath?: string
|
|
67
89
|
readonly timeoutMs?: number
|
|
68
90
|
readonly pollMs?: number
|
|
91
|
+
readonly extension?: InstalledExtension
|
|
92
|
+
readonly home?: string
|
|
69
93
|
}
|
|
70
94
|
|
|
71
95
|
/**
|
|
@@ -86,8 +110,15 @@ export async function waitForRestartedBridge(pid: number, options: BridgeReadyOp
|
|
|
86
110
|
if (remaining <= 0) break
|
|
87
111
|
const connection = new BridgeConnection({ port: Number(endpoint.port), token: endpoint.token, pid })
|
|
88
112
|
try {
|
|
113
|
+
if (options.extension !== undefined) {
|
|
114
|
+
const version = await connection.call({ op: 'version' }, Math.min(1_000, remaining))
|
|
115
|
+
const status = version.mainExtension as { state?: unknown; version?: unknown; loadedAt?: unknown } | undefined
|
|
116
|
+
if (version.ok !== true || version.bridgeVersion !== options.extension.version || version.bridgeBuild !== options.extension.build
|
|
117
|
+
|| version.homeId !== extensionHomeId(options.home ?? '') || status?.state !== 'loaded'
|
|
118
|
+
|| status.version !== options.extension.version || typeof status.loadedAt !== 'string' || !Number.isFinite(Date.parse(status.loadedAt))) throw new Error('EXTENSION_RESTART_REQUIRED')
|
|
119
|
+
}
|
|
89
120
|
const answer = await connection.call({ op: 'list' }, Math.min(1_000, remaining))
|
|
90
|
-
if (answer.ok === true &&
|
|
121
|
+
if (answer.ok === true && Number(answer.protocol) >= 4) return
|
|
91
122
|
} finally { connection.close() }
|
|
92
123
|
}
|
|
93
124
|
} catch {
|
|
@@ -127,6 +158,10 @@ export async function waitForBridgeActionCompletion(
|
|
|
127
158
|
|| typeof record.completedAt !== 'string' || !Number.isFinite(Date.parse(record.completedAt))
|
|
128
159
|
|| record.pid !== undefined
|
|
129
160
|
|| (record.error !== undefined && typeof record.error !== 'string')
|
|
161
|
+
|| (record.hostPatch !== undefined && (record.hostPatch === null || typeof record.hostPatch !== 'object'
|
|
162
|
+
|| !['absent', 'applied', 'unsupported version', 'anchors mismatch'].includes(record.hostPatch.status)
|
|
163
|
+
|| (record.hostPatch.reason !== undefined && typeof record.hostPatch.reason !== 'string')
|
|
164
|
+
|| (record.hostPatch.changed !== undefined && typeof record.hostPatch.changed !== 'boolean')))
|
|
130
165
|
|| (record.ok !== (record.code === 0))) {
|
|
131
166
|
throw new Error('the bridge installer wrote an invalid completion record')
|
|
132
167
|
}
|
|
@@ -244,7 +279,8 @@ export async function runBridgeAction(
|
|
|
244
279
|
const final = await waitForBridgeActionCompletion(resultFile, action, Math.max(0, deadline - Date.now()), deps.resultPollMs)
|
|
245
280
|
const output = [installerOutput, await recordedOutput(), final.error].filter(Boolean).join('\n')
|
|
246
281
|
return { ok: final.ok, code: final.code, output: tail(output), command: printable, resultFile, logFile,
|
|
247
|
-
restarted: final.restarted, ...final.pid === undefined ? {} : { pid: final.pid }
|
|
282
|
+
restarted: final.restarted, ...final.pid === undefined ? {} : { pid: final.pid },
|
|
283
|
+
...final.hostPatch === undefined ? {} : { hostPatch: final.hostPatch } }
|
|
248
284
|
} catch (error) {
|
|
249
285
|
return { ok: false, code: null,
|
|
250
286
|
output: tail([installerOutput, await recordedOutput(), String(error)].filter(Boolean).join('\n')),
|
|
@@ -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,9 +9,9 @@ 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.
|
|
12
|
-
import { dshHome as dshHomePath } from './paths.
|
|
13
|
-
import type { BridgeAction } from './bridge-install.
|
|
12
|
+
import { desktopLayout, desktopPaths, readDesktopIdentity } from './desktop-identity.ts'
|
|
13
|
+
import { dshHome as dshHomePath } from './paths.ts'
|
|
14
|
+
import type { BridgeAction } from './bridge-install.ts'
|
|
14
15
|
|
|
15
16
|
export interface BridgeMaintenanceOptions {
|
|
16
17
|
/** Parent of a new, unique maintenance directory; defaults to the user's DSH home. */
|
|
@@ -24,9 +25,9 @@ export interface PreparedBridgeMaintenance {
|
|
|
24
25
|
readonly prepared: true
|
|
25
26
|
readonly action: BridgeAction
|
|
26
27
|
readonly path: string
|
|
27
|
-
/** Literal-path invocation for the user's PowerShell
|
|
28
|
+
/** Literal-path invocation for the user's terminal (PowerShell on Windows, a POSIX shell on macOS). */
|
|
28
29
|
readonly command: string
|
|
29
|
-
readonly commandShell: 'powershell'
|
|
30
|
+
readonly commandShell: 'powershell' | 'sh'
|
|
30
31
|
readonly directory: string
|
|
31
32
|
readonly runnerPath: string
|
|
32
33
|
readonly planPath: string
|
|
@@ -71,6 +72,30 @@ function prospectiveRealPath(path: string): string {
|
|
|
71
72
|
return resolve(realpathSync(ancestor), ...missing)
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
/** Case-insensitive on Windows; elsewhere both sides are already on-disk spellings (`realpathSync.native`). */
|
|
76
|
+
function samePath(a: string, b: string): boolean {
|
|
77
|
+
return process.platform === 'win32' ? a.toLowerCase() === b.toLowerCase() : a === b
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** One POSIX shell word: single-quoted, with embedded quotes closed and escaped. */
|
|
81
|
+
function shellLiteral(value: string): string {
|
|
82
|
+
return `'${value.replace(/'/g, `'\\''`)}'`
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The macOS launcher: a `.command` file Finder opens in Terminal; paths stay single-quoted literals. */
|
|
86
|
+
function posixLauncher(nodePath: string, electronNode: boolean): string {
|
|
87
|
+
return [
|
|
88
|
+
'#!/bin/sh',
|
|
89
|
+
'echo "Quit DSH Desktop normally before running bridge maintenance."',
|
|
90
|
+
'cd "$(dirname "$0")" || exit 1',
|
|
91
|
+
`${electronNode ? 'ELECTRON_RUN_AS_NODE=1 ' : 'ELECTRON_RUN_AS_NODE= '}${shellLiteral(nodePath)}${electronNode ? ' --expose-internals' : ''} ./run-maintenance.mjs`,
|
|
92
|
+
'code=$?',
|
|
93
|
+
'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',
|
|
94
|
+
'exit "$code"',
|
|
95
|
+
'',
|
|
96
|
+
].join('\n')
|
|
97
|
+
}
|
|
98
|
+
|
|
74
99
|
/** This runner is deliberately data-driven: paths and actions are never evaluated as shell text. */
|
|
75
100
|
const RUNNER = `import { readFileSync, existsSync } from 'node:fs';
|
|
76
101
|
import { isAbsolute } from 'node:path';
|
|
@@ -110,13 +135,13 @@ export async function prepareBridgeMaintenance(
|
|
|
110
135
|
const installerPath = fileURLToPath(new URL('../../desktop-bridge/install.mjs', import.meta.url))
|
|
111
136
|
if (!existsSync(installerPath)) throw new Error('the packaged bridge installer is missing')
|
|
112
137
|
|
|
138
|
+
const desktopRuntime = desktopPaths(target).executable
|
|
113
139
|
const currentIsNode = /^(?:node|node\.exe)$/i.test(basename(process.execPath))
|
|
114
|
-
const selected = options.nodePath ?? (currentIsNode ? process.execPath :
|
|
140
|
+
const selected = options.nodePath ?? (currentIsNode ? process.execPath : desktopRuntime)
|
|
115
141
|
const nodePath = checkedPath(selected, 'Maintenance runtime')
|
|
116
142
|
if (!existsSync(nodePath) || !statSync(nodePath).isFile()) throw new Error('the maintenance runtime does not exist')
|
|
117
143
|
const electronNode = !/^(?:node|node\.exe)$/i.test(basename(nodePath))
|
|
118
|
-
|
|
119
|
-
if (electronNode && (!existsSync(desktopRuntime) || realpathSync(nodePath).toLowerCase() !== realpathSync(desktopRuntime).toLowerCase())) {
|
|
144
|
+
if (electronNode && (!existsSync(desktopRuntime) || !samePath(realpathSync.native(nodePath), realpathSync.native(desktopRuntime)))) {
|
|
120
145
|
throw new Error('the Electron maintenance runtime must belong to the verified Desktop installation')
|
|
121
146
|
}
|
|
122
147
|
|
|
@@ -125,7 +150,7 @@ export async function prepareBridgeMaintenance(
|
|
|
125
150
|
if (testContext && options.directory === undefined && process.env.DSH_BRIDGE_TEST_ROOT === undefined) {
|
|
126
151
|
throw new Error('test preparation requires an explicit private maintenance directory')
|
|
127
152
|
}
|
|
128
|
-
const directory = checkedPath(options.directory ?? join(dshHome,
|
|
153
|
+
const directory = checkedPath(options.directory ?? join(dshHome, BROWSER_PROFILE_DIR, 'maintenance'), 'Maintenance directory')
|
|
129
154
|
if (withinOrEqual(target, directory) || withinOrEqual(target, prospectiveRealPath(directory))) {
|
|
130
155
|
throw new Error('maintenance launchers must be stored outside the Desktop installation')
|
|
131
156
|
}
|
|
@@ -134,9 +159,10 @@ export async function prepareBridgeMaintenance(
|
|
|
134
159
|
const output = await mkdtemp(join(directory, `${action}-`))
|
|
135
160
|
const runnerPath = join(output, 'run-maintenance.mjs')
|
|
136
161
|
const planPath = join(output, 'maintenance.json')
|
|
137
|
-
const
|
|
162
|
+
const bundle = (desktopLayout(target) as { name?: string }).name === 'macos-bundle'
|
|
163
|
+
const path = join(output, `${action === 'uninstall' ? 'uninstall' : 'install'}-bridge.${bundle ? 'command' : 'cmd'}`)
|
|
138
164
|
const plan: MaintenancePlan = { version: 1, action, installRoot: target, installerPath, nodePath, electronNode, dshHome }
|
|
139
|
-
const command = [
|
|
165
|
+
const command = bundle ? posixLauncher(nodePath, electronNode) : [
|
|
140
166
|
'@echo off',
|
|
141
167
|
'setlocal DisableDelayedExpansion',
|
|
142
168
|
'chcp 65001 >nul',
|
|
@@ -156,6 +182,8 @@ export async function prepareBridgeMaintenance(
|
|
|
156
182
|
].join('\r\n')
|
|
157
183
|
await writeFile(planPath, JSON.stringify(plan, null, 2) + '\n', { flag: 'wx', mode: 0o600 })
|
|
158
184
|
await writeFile(runnerPath, RUNNER, { flag: 'wx', mode: 0o600 })
|
|
159
|
-
await writeFile(path, command, { flag: 'wx', mode: 0o600 })
|
|
160
|
-
return
|
|
185
|
+
await writeFile(path, command, { flag: 'wx', mode: bundle ? 0o700 : 0o600 })
|
|
186
|
+
return bundle
|
|
187
|
+
? { ok: true, prepared: true, action, path, command: shellLiteral(path), commandShell: 'sh', directory: output, runnerPath, planPath }
|
|
188
|
+
: { ok: true, prepared: true, action, path, command: `& '${path.replace(/'/g, "''")}'`, commandShell: 'powershell', directory: output, runnerPath, planPath }
|
|
161
189
|
}
|
|
@@ -14,12 +14,16 @@
|
|
|
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
22
|
|
|
22
|
-
import { readDesktopIdentity } from './desktop-identity.
|
|
23
|
+
import { desktopPaths, readDesktopIdentity } from './desktop-identity.ts'
|
|
24
|
+
import { MAIN_EXTENSION_UNSUPPORTED, type MainExtensionStatus } from './profile-extension.ts'
|
|
25
|
+
import { BRIDGE_VERSION_MESSAGE } from '../bridge-compatibility.ts'
|
|
26
|
+
import { conventionalInstallRoots, registeredInstallLocations } from '../../desktop-bridge/desktop-discovery.mjs'
|
|
23
27
|
|
|
24
28
|
// A normal Electron existsSync(app.asar) caches the archive and keeps it locked on Windows.
|
|
25
29
|
// Status inspection must leave maintenance free to rename it after Desktop exits.
|
|
@@ -39,32 +43,33 @@ const rawExistsSync: typeof existsSync = (() => {
|
|
|
39
43
|
* @param localAppData - the base directory; defaults to the environment's.
|
|
40
44
|
* @returns the install directory, or undefined when nothing matches.
|
|
41
45
|
*/
|
|
42
|
-
export function findDesktopInstall(
|
|
46
|
+
export function findDesktopInstall(
|
|
47
|
+
localAppData?: string,
|
|
48
|
+
registry: () => readonly string[] = registeredInstallLocations,
|
|
49
|
+
conventions: () => readonly string[] = conventionalInstallRoots,
|
|
50
|
+
): string | undefined {
|
|
43
51
|
// Not every install lives in %LOCALAPPDATA%\\Programs: people put the app on another drive, under
|
|
44
52
|
// Program Files, or in their own folder. DSH_DESKTOP_PATH names one explicitly, and the usual roots
|
|
45
53
|
// are all probed. A test or a caller that passes a base directory gets exactly that base, so the
|
|
46
54
|
// behaviour stays pinnable.
|
|
47
55
|
const isDesktop = (candidate: string): boolean => readDesktopIdentity(candidate).ok
|
|
48
|
-
const explicit
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
for (const explicit of [process.env.DSH_DESKTOP_PATH, process.env.DSH_DESKTOP_APP]) {
|
|
57
|
+
if (explicit !== undefined && explicit !== '') {
|
|
58
|
+
const named = explicit
|
|
59
|
+
if (isDesktop(named)) return named
|
|
60
|
+
// A parent directory is a reasonable thing to point at too: look one level down.
|
|
61
|
+
try {
|
|
62
|
+
for (const entry of readdirSync(named, { withFileTypes: true })) {
|
|
63
|
+
if (entry.isDirectory() && isDesktop(join(named, entry.name))) return join(named, entry.name)
|
|
64
|
+
}
|
|
65
|
+
} catch {
|
|
66
|
+
// Not a directory: fall through to the usual roots.
|
|
56
67
|
}
|
|
57
|
-
} catch {
|
|
58
|
-
// Not a directory: fall through to the usual roots.
|
|
59
68
|
}
|
|
60
69
|
}
|
|
61
|
-
const roots = localAppData === undefined
|
|
62
|
-
? [process.env.LOCALAPPDATA ?? '', process.env['ProgramFiles'] ?? '', process.env['ProgramFiles(x86)'] ?? '', process.env.APPDATA ?? '', process.env.ProgramData ?? '']
|
|
63
|
-
.filter(base => base !== '')
|
|
64
|
-
.map(base => (base === process.env.LOCALAPPDATA ? join(base, 'Programs') : base))
|
|
65
|
-
: [join(localAppData, 'Programs')]
|
|
70
|
+
const roots = localAppData === undefined ? desktopInstallRoots() : [join(localAppData, 'Programs')]
|
|
66
71
|
for (const base of roots) {
|
|
67
|
-
for (const named of
|
|
72
|
+
for (const named of DESKTOP_INSTALL_NAMES) {
|
|
68
73
|
const candidate = join(base, named)
|
|
69
74
|
if (isDesktop(candidate)) return candidate
|
|
70
75
|
}
|
|
@@ -78,14 +83,39 @@ export function findDesktopInstall(localAppData?: string): string | undefined {
|
|
|
78
83
|
// A root that does not exist is a state, not an error.
|
|
79
84
|
}
|
|
80
85
|
}
|
|
86
|
+
for (const source of [registry, conventions]) {
|
|
87
|
+
try {
|
|
88
|
+
for (const candidate of source()) {
|
|
89
|
+
if (isDesktop(candidate)) return candidate
|
|
90
|
+
}
|
|
91
|
+
} catch {}
|
|
92
|
+
}
|
|
81
93
|
return undefined
|
|
82
94
|
}
|
|
83
95
|
|
|
96
|
+
/** Directory names an install is given: a plain directory on Windows, an `.app` bundle on macOS. */
|
|
97
|
+
const DESKTOP_INSTALL_NAMES = ['DSH Desktop', 'DeepSeek Harness', 'DSH Desktop.app', 'DeepSeek Harness.app']
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Where this OS keeps installed applications, most specific first.
|
|
101
|
+
* @returns the existing-or-not base directories to probe.
|
|
102
|
+
*/
|
|
103
|
+
function desktopInstallRoots(): string[] {
|
|
104
|
+
const windows = [process.env.LOCALAPPDATA ?? '', process.env['ProgramFiles'] ?? '', process.env['ProgramFiles(x86)'] ?? '', process.env.APPDATA ?? '', process.env.ProgramData ?? '']
|
|
105
|
+
.filter(base => base !== '')
|
|
106
|
+
.map(base => (base === process.env.LOCALAPPDATA ? join(base, 'Programs') : base))
|
|
107
|
+
// The machine-wide macOS roots cannot be redirected, so a test process never reads them.
|
|
108
|
+
const testing = process.env.DSH_BROWSER_TEST === '1' || process.env.NODE_TEST_CONTEXT !== undefined
|
|
109
|
+
return process.platform === 'darwin' && !testing ? [...windows, '/Applications', join(homedir(), 'Applications')] : windows
|
|
110
|
+
}
|
|
111
|
+
|
|
84
112
|
/** The marker the installer inserts into the shell's main.js. */
|
|
85
113
|
const MARKER = '// dsh-builtin-browser: hand the plugin a way to drive the sidebar'
|
|
86
114
|
|
|
87
115
|
/** One reading of the install tree. */
|
|
88
116
|
export interface BridgeStatus {
|
|
117
|
+
readonly mainExtension?: MainExtensionStatus
|
|
118
|
+
readonly code?: string
|
|
89
119
|
/** `installed`, `missing` or `stale`; see the module comment for what each means. */
|
|
90
120
|
readonly state: 'installed' | 'missing' | 'stale'
|
|
91
121
|
/** Whether the loaded application passed DSH Desktop identity verification. */
|
|
@@ -158,8 +188,20 @@ function repairCommand(installRoot: string | undefined): string | undefined {
|
|
|
158
188
|
* @param installRoot - the desktop install directory.
|
|
159
189
|
* @returns the current state.
|
|
160
190
|
*/
|
|
161
|
-
export function readBridgeStatus(installRoot: string): BridgeStatus {
|
|
162
|
-
const
|
|
191
|
+
export function readBridgeStatus(installRoot: string, mainExtension?: MainExtensionStatus): BridgeStatus {
|
|
192
|
+
const disk = readBridgeInstallStatus(installRoot)
|
|
193
|
+
if (mainExtension === undefined) return { ...disk, code: disk.code ?? MAIN_EXTENSION_UNSUPPORTED }
|
|
194
|
+
return { ...disk, mainExtension, command: undefined, detail: `desktop main extension: ${mainExtension.state}`,
|
|
195
|
+
state: mainExtension.state === 'loaded' ? 'installed' : mainExtension.state === 'not-installed' ? 'missing' : 'stale',
|
|
196
|
+
code: mainExtension.code }
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function readBridgeInstallStatus(installRoot: string): BridgeStatus {
|
|
200
|
+
let resources: string
|
|
201
|
+
try { resources = desktopPaths(installRoot).resources }
|
|
202
|
+
catch (error) {
|
|
203
|
+
return { state: 'missing', present: false, installRoot, archivePresent: false, detail: `not a DSH Desktop install: ${String(error)}` }
|
|
204
|
+
}
|
|
163
205
|
const appDir = join(resources, 'app')
|
|
164
206
|
const mainPath = join(appDir, 'lib', 'main.js')
|
|
165
207
|
const archivePath = join(resources, 'app.asar')
|
|
@@ -195,6 +237,16 @@ export function readBridgeStatus(installRoot: string): BridgeStatus {
|
|
|
195
237
|
detail: 'not a DSH Desktop install: no resources/app/lib/main.js and no resources/app.asar',
|
|
196
238
|
}
|
|
197
239
|
}
|
|
240
|
+
if (!rawExistsSync(archivePath)
|
|
241
|
+
&& safeIncludes(mainPath, '//#region lib/types/main-extensions.js')
|
|
242
|
+
&& safeExists(fileURLToPath(new URL('../../desktop-bridge/main.mjs', import.meta.url)))) {
|
|
243
|
+
return {
|
|
244
|
+
state: 'installed', present: true, installRoot, archivePresent: false,
|
|
245
|
+
detail: 'DSH Desktop main extension loads the bridge from the installed profile plugin',
|
|
246
|
+
...identity.version === undefined ? {} : { version: identity.version },
|
|
247
|
+
command: repairCommand(installRoot),
|
|
248
|
+
}
|
|
249
|
+
}
|
|
198
250
|
let backupAt
|
|
199
251
|
try {
|
|
200
252
|
if (existsSync(backupPath)) backupAt = statSync(backupPath).mtime.toISOString()
|
|
@@ -242,15 +294,34 @@ export function readBridgeStatus(installRoot: string): BridgeStatus {
|
|
|
242
294
|
}
|
|
243
295
|
const bridgePath = join(appDir, 'lib', 'plugin-browser-bridge.js')
|
|
244
296
|
let bridgeDetail: string | undefined
|
|
297
|
+
let bridgeCode: string | undefined
|
|
245
298
|
try {
|
|
246
299
|
const deployed = readFileSync(bridgePath)
|
|
247
300
|
const shipped = readFileSync(new URL('../../desktop-bridge/plugin-browser-bridge.js', import.meta.url))
|
|
248
|
-
|
|
301
|
+
const loader = readFileSync(new URL('../../desktop-bridge/profile-loader.mjs', import.meta.url))
|
|
302
|
+
if (deployed.equals(loader)) {
|
|
303
|
+
try {
|
|
304
|
+
const profile = join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'profiles', 'desktop')
|
|
305
|
+
const manifest = JSON.parse(readFileSync(join(profile, 'package.json'), 'utf8'))
|
|
306
|
+
if (!Object.hasOwn(manifest.dependencies ?? {}, 'dsh-builtin-browser')) throw new Error('not a direct profile dependency')
|
|
307
|
+
const directory = realpathSync(join(profile, 'node_modules', 'dsh-builtin-browser'))
|
|
308
|
+
const entry = realpathSync(join(directory, 'desktop-bridge', 'plugin-browser-bridge.js'))
|
|
309
|
+
const child = relative(directory, entry)
|
|
310
|
+
if (!child || isAbsolute(child) || child === '..' || child.startsWith('../') || child.startsWith('..\\')) {
|
|
311
|
+
throw new Error('bridge entry resolves outside its package')
|
|
312
|
+
}
|
|
313
|
+
if (!readFileSync(entry).equals(shipped)) bridgeDetail = BRIDGE_VERSION_MESSAGE
|
|
314
|
+
} catch {
|
|
315
|
+
bridgeCode = 'DSH_BRIDGE_PACKAGE_UNAVAILABLE'
|
|
316
|
+
bridgeDetail = `${bridgeCode}: the profile loader's package bridge is missing, unreadable or outside its package`
|
|
317
|
+
}
|
|
318
|
+
} else if (!deployed.equals(shipped)) bridgeDetail = BRIDGE_VERSION_MESSAGE
|
|
249
319
|
} catch {
|
|
250
320
|
bridgeDetail = 'the bridge module is missing or cannot be verified; reinstall the bridge to restore it'
|
|
251
321
|
}
|
|
252
322
|
return {
|
|
253
323
|
state: bridgeDetail === undefined ? 'installed' : 'stale',
|
|
324
|
+
...bridgeCode === undefined ? {} : { code: bridgeCode },
|
|
254
325
|
present: true,
|
|
255
326
|
installRoot,
|
|
256
327
|
archivePresent,
|