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,16 +1,229 @@
|
|
|
1
|
-
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx, extraExtensions, ignoreCase) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
if (extraExtensions) {
|
|
4
|
+
for (var extension in extraExtensions) {
|
|
5
|
+
var suffix = path.slice(-extension.length);
|
|
6
|
+
if (suffix === extension || ignoreCase && suffix.toLowerCase() === extension.toLowerCase()) {
|
|
7
|
+
var output = extraExtensions[extension];
|
|
8
|
+
return output === extension ? path : path.slice(0, -extension.length) + output;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
13
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return path;
|
|
17
|
+
};
|
|
18
|
+
import { BROWSER_PROFILE_DIR } from '../../assets/browser-policy.mjs';
|
|
19
|
+
/** User-requested Desktop maintenance (Windows and macOS), coordinated outside the Desktop process tree. */
|
|
2
20
|
import { execFile, spawn } from 'node:child_process';
|
|
21
|
+
import * as fs from 'node:fs';
|
|
3
22
|
import { existsSync, readFileSync } from 'node:fs';
|
|
4
|
-
import { mkdir, open, readFile,
|
|
23
|
+
import { cp, mkdir, open, readFile, stat as statAsync, unlink, writeFile } from 'node:fs/promises';
|
|
5
24
|
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
6
25
|
import { fileURLToPath } from 'node:url';
|
|
7
26
|
import { prepareBridgeMaintenance } from './bridge-maintenance.js';
|
|
8
27
|
import { launchMaintenanceBroker } from './maintenance-broker.js';
|
|
9
28
|
import { runMaintenanceLifecycle } from './maintenance-lifecycle.js';
|
|
10
29
|
import { defaultInstallerPath, runBridgeAction, waitForRestartedBridge } from './bridge-install.js';
|
|
11
|
-
import { readDesktopIdentity } from './desktop-identity.js';
|
|
30
|
+
import { desktopLayout, desktopPaths, readAsarFile, readDesktopIdentity } from './desktop-identity.js';
|
|
12
31
|
import { dshHome } from './paths.js';
|
|
13
32
|
import { encodePowerShellScript, windowsPowerShellPath } from './windows-system.js';
|
|
33
|
+
import { renameMaintenanceFile } from '../../desktop-bridge/maintenance-files.mjs';
|
|
34
|
+
import { isDesktopExecutable } from '../../desktop-bridge/desktop-processes.mjs';
|
|
35
|
+
import { installedProfileExtension, repairProfileExtension, reconcileProfile, profileDependencySpec, profileRuntimeDirectory, MAIN_EXTENSION_NAME } from './profile-extension.js';
|
|
36
|
+
import { withProfileCheckpoint } from './profile-checkpoint.js';
|
|
37
|
+
import { runProfileCommand } from './profile-command.js';
|
|
38
|
+
import { cleanProfileResidue, inspectProfileResidue } from './profile-residue.js';
|
|
39
|
+
const { hostPatchStatus } = await import(__rewriteRelativeImportExtension(new URL('../../dsh-host-patch/apply.mjs', import.meta.url).href));
|
|
40
|
+
const { stripLegacyBridge } = await import(__rewriteRelativeImportExtension(new URL('../../dsh-host-patch/legacy-bridge.mjs', import.meta.url).href));
|
|
41
|
+
export class ReinstallPreflightError extends Error {
|
|
42
|
+
code;
|
|
43
|
+
constructor(code, message) {
|
|
44
|
+
super(message);
|
|
45
|
+
this.code = code;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function archiveExists(path) {
|
|
49
|
+
const runtime = process;
|
|
50
|
+
const previous = runtime.noAsar;
|
|
51
|
+
runtime.noAsar = true;
|
|
52
|
+
try {
|
|
53
|
+
return existsSync(path);
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
runtime.noAsar = previous;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function patchDirectories(root) {
|
|
60
|
+
const app = join(desktopPaths(root).resources, 'app');
|
|
61
|
+
return [app, join(app, 'dsh', 'node_modules', '@deepseek-ai', 'dsh-client-ui-sidebar-right')];
|
|
62
|
+
}
|
|
63
|
+
function validateCliBackup(path, kind) {
|
|
64
|
+
const backup = path + '.before-bridge';
|
|
65
|
+
if (!existsSync(backup))
|
|
66
|
+
return;
|
|
67
|
+
if (![path, backup].every(file => fs.lstatSync(file).isFile() && !fs.lstatSync(file).isSymbolicLink())) {
|
|
68
|
+
throw new ReinstallPreflightError('REINSTALL_BACKUP_CONFLICT', 'A CLI restore baseline is not a regular file.');
|
|
69
|
+
}
|
|
70
|
+
const original = readFileSync(backup, 'utf8'), current = readFileSync(path, 'utf8');
|
|
71
|
+
if (current === original)
|
|
72
|
+
return;
|
|
73
|
+
const eol = original.includes('\r\n') ? '\r\n' : '\n';
|
|
74
|
+
let expected;
|
|
75
|
+
if (kind === 'host') {
|
|
76
|
+
const call = /^(\t)await runDesktopCli\(((?:runtimeDir, )?)join\(dirname\(runtimeArchivePath\(runtimeDir\) \?\? runtimeDir\), "runtime"\)\);$/m.exec(original);
|
|
77
|
+
if (call === null)
|
|
78
|
+
throw new ReinstallPreflightError('REINSTALL_BACKUP_CONFLICT', 'The CLI differs from its recognized restore baseline.');
|
|
79
|
+
expected = original.replace(call[0], () => [
|
|
80
|
+
'\t// dsh-builtin-browser: recognize an unpacked `app` directory as the app root,',
|
|
81
|
+
'\t// so an installation whose app.asar was moved aside still finds its runtime.',
|
|
82
|
+
'\tconst cliOwnerDir = dirname(runtimeDir);',
|
|
83
|
+
'\tconst cliSupportRoot = basename(cliOwnerDir) === "app" || basename(cliOwnerDir) === "app.asar" ? dirname(cliOwnerDir) : cliOwnerDir;',
|
|
84
|
+
`\tawait runDesktopCli(${call[2]}join(cliSupportRoot, "runtime"));`,
|
|
85
|
+
].join(eol));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const injection = [
|
|
89
|
+
'rem dsh-builtin-browser: resolve the app directory (resources\\app when the bridge is installed,',
|
|
90
|
+
'rem resources\\app.asar on a stock installation).',
|
|
91
|
+
'set "DSH_APP=%~dp0..\\..\\..\\app"',
|
|
92
|
+
'if not exist "%DSH_APP%\\dsh\\node_modules\\@deepseek-ai\\dsh-desktop-host\\lib\\cli.js" set "DSH_APP=%~dp0..\\..\\..\\app.asar"',
|
|
93
|
+
].join(eol);
|
|
94
|
+
const setLocal = /^.*setlocal.*$/m.exec(original);
|
|
95
|
+
expected = (setLocal === null ? injection + eol + original : original.replace(setLocal[0], () => setLocal[0] + eol + injection))
|
|
96
|
+
.replace(/%~dp0(?:\.\.\\)+app\.asar\\dsh\\/, () => '%DSH_APP%\\dsh\\');
|
|
97
|
+
}
|
|
98
|
+
if (current !== expected)
|
|
99
|
+
throw new ReinstallPreflightError('REINSTALL_BACKUP_CONFLICT', 'The CLI differs from its recognized restore baseline.');
|
|
100
|
+
}
|
|
101
|
+
/** Inspect the archive Electron will load, never a leftover extraction beside it. */
|
|
102
|
+
export function inspectReinstallHost(root) {
|
|
103
|
+
const identity = readDesktopIdentity(root);
|
|
104
|
+
if (!identity.ok)
|
|
105
|
+
throw new ReinstallPreflightError('REINSTALL_DESKTOP_INVALID', identity.reason);
|
|
106
|
+
const archive = join(desktopPaths(root).resources, 'app.asar');
|
|
107
|
+
if (archiveExists(archive) && existsSync(archive + '.before-bridge')) {
|
|
108
|
+
throw new ReinstallPreflightError('REINSTALL_BACKUP_CONFLICT', 'Both the Desktop archive and its restore baseline exist.');
|
|
109
|
+
}
|
|
110
|
+
if (identity.layout === 'unpacked')
|
|
111
|
+
return hostPatchStatus(patchDirectories(root));
|
|
112
|
+
const app = patchDirectories(root)[0];
|
|
113
|
+
const archiveFile = (path) => readAsarFile(archive, relative(app, String(path)).split('\\').join('/'));
|
|
114
|
+
const snapshot = {
|
|
115
|
+
...fs,
|
|
116
|
+
realpathSync: (path) => resolve(String(path)),
|
|
117
|
+
readFileSync: (path) => {
|
|
118
|
+
const content = archiveFile(path);
|
|
119
|
+
if (content === undefined)
|
|
120
|
+
throw new Error(`Missing or unreadable archive entry: ${relative(app, String(path))}`);
|
|
121
|
+
return content.toString('utf8');
|
|
122
|
+
},
|
|
123
|
+
existsSync: (path) => archiveFile(path) !== undefined,
|
|
124
|
+
lstatSync: () => ({ isFile: () => true, isSymbolicLink: () => false }),
|
|
125
|
+
statSync: () => ({ mode: 0o644 }),
|
|
126
|
+
};
|
|
127
|
+
return hostPatchStatus(patchDirectories(root), { fs: snapshot });
|
|
128
|
+
}
|
|
129
|
+
/** Entirely read-only: a missing dependency never creates a lock, plan or replacement source. */
|
|
130
|
+
export async function preflightReinstall(root, home) {
|
|
131
|
+
let dependency;
|
|
132
|
+
try {
|
|
133
|
+
dependency = await profileDependencySpec(home);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
if (error.code === 'ENOENT')
|
|
137
|
+
throw new ReinstallPreflightError('REINSTALL_DEPENDENCY_MISSING', 'The Desktop profile has no dependency specification to reinstall.');
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
if (/^(?:file|link):/.test(dependency)) {
|
|
141
|
+
const path = resolve(home, 'profiles', 'desktop', dependency.slice(dependency.indexOf(':') + 1));
|
|
142
|
+
try {
|
|
143
|
+
fs.accessSync(path, fs.constants.R_OK);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
throw new ReinstallPreflightError('REINSTALL_DEPENDENCY_UNAVAILABLE', 'The captured local dependency source is not readable.');
|
|
147
|
+
}
|
|
148
|
+
const installed = join(home, 'profiles', 'desktop', 'node_modules', MAIN_EXTENSION_NAME);
|
|
149
|
+
if (existsSync(installed)) {
|
|
150
|
+
const source = fs.realpathSync(path);
|
|
151
|
+
const owner = fs.lstatSync(installed).isSymbolicLink() ? resolve(home, 'profiles', 'desktop', 'node_modules') : fs.realpathSync(installed);
|
|
152
|
+
if (source === owner || inside(owner, source))
|
|
153
|
+
throw new ReinstallPreflightError('REINSTALL_DEPENDENCY_UNSAFE', 'The captured dependency source would be deleted by plugin removal.');
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
await inspectProfileResidue(home);
|
|
157
|
+
const status = inspectReinstallHost(root);
|
|
158
|
+
if (status.status !== 'absent' && status.status !== 'applied')
|
|
159
|
+
throw new ReinstallPreflightError('REINSTALL_HOST_CONFLICT', status.reason ?? status.status);
|
|
160
|
+
const cli = 'dsh/node_modules/@deepseek-ai/dsh-desktop-host/lib/cli.js';
|
|
161
|
+
const archive = join(desktopPaths(root).resources, 'app.asar');
|
|
162
|
+
if (status.status === 'applied' && (archiveExists(archive) || ![
|
|
163
|
+
join(desktopPaths(root).resources, 'app', 'lib', 'main.js'), join(desktopPaths(root).resources, 'app', 'lib', 'preload-app.cjs'),
|
|
164
|
+
join(patchDirectories(root)[1], 'lib', 'client.js'),
|
|
165
|
+
].every(path => existsSync(path + '.before-dsh-host-patch')))) {
|
|
166
|
+
throw new ReinstallPreflightError('REINSTALL_BACKUP_CONFLICT', 'An applied host patch has no usable external restore baseline.');
|
|
167
|
+
}
|
|
168
|
+
if (archiveExists(archive) ? readAsarFile(archive, cli) === undefined : !existsSync(join(desktopPaths(root).resources, 'app', cli))) {
|
|
169
|
+
throw new ReinstallPreflightError('REINSTALL_CLI_MISSING', 'The authoritative Desktop CLI is missing or unreadable.');
|
|
170
|
+
}
|
|
171
|
+
validateCliBackup(join(desktopPaths(root).resources, 'runtime', 'cli', 'bin', 'dsh.cmd'), 'shim');
|
|
172
|
+
if (!archiveExists(archive))
|
|
173
|
+
validateCliBackup(join(desktopPaths(root).resources, 'app', cli), 'host');
|
|
174
|
+
const main = join(desktopPaths(root).resources, 'app', 'lib', 'main.js');
|
|
175
|
+
if (!archiveExists(join(desktopPaths(root).resources, 'app.asar')) && existsSync(main + '.before-bridge')) {
|
|
176
|
+
const original = readFileSync(main + '.before-bridge', 'utf8');
|
|
177
|
+
const current = readFileSync(existsSync(main + '.before-dsh-host-patch') ? main + '.before-dsh-host-patch' : main, 'utf8');
|
|
178
|
+
if ((stripLegacyBridge(current) ?? current) !== original) {
|
|
179
|
+
throw new ReinstallPreflightError('REINSTALL_BACKUP_CONFLICT', 'The legacy bridge differs from its restore baseline.');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (!archiveExists(archive) && existsSync(archive + '.before-bridge')) {
|
|
183
|
+
const preserved = readAsarFile(archive + '.before-bridge', 'lib/main.js');
|
|
184
|
+
const current = readFileSync(existsSync(main + '.before-dsh-host-patch') ? main + '.before-dsh-host-patch' : main, 'utf8');
|
|
185
|
+
if (preserved === undefined || preserved.toString('utf8') !== (stripLegacyBridge(current) ?? current)) {
|
|
186
|
+
throw new ReinstallPreflightError('REINSTALL_BACKUP_CONFLICT', 'The preserved archive belongs to different Desktop bytes.');
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
await profileRuntimeDirectory(root);
|
|
190
|
+
return dependency;
|
|
191
|
+
}
|
|
192
|
+
/** Copy only shipped runtime files; the running worker and installer survive profile removal. */
|
|
193
|
+
export async function stageReinstallRuntime(directory, source = fileURLToPath(new URL('../../', import.meta.url))) {
|
|
194
|
+
const destination = join(directory, 'runtime');
|
|
195
|
+
const packageDirectory = fs.realpathSync(source);
|
|
196
|
+
const parent = fs.realpathSync(directory);
|
|
197
|
+
if (parent === packageDirectory || inside(packageDirectory, parent))
|
|
198
|
+
throw new Error('Reinstall runtime must be staged outside the removed package');
|
|
199
|
+
await mkdir(destination, { mode: 0o700 });
|
|
200
|
+
for (const name of ['lib', 'assets', 'desktop-bridge', 'dsh-host-patch', 'package.json']) {
|
|
201
|
+
await cp(join(packageDirectory, name), join(destination, name), { recursive: true, dereference: true, errorOnExist: true, force: false });
|
|
202
|
+
}
|
|
203
|
+
return join(destination, 'lib', 'browser-electron', 'automatic-maintenance.js');
|
|
204
|
+
}
|
|
205
|
+
/** Called under the automatic job lock, only after the closed-process barrier. */
|
|
206
|
+
export async function runReinstallTransaction(steps) {
|
|
207
|
+
const removed = await steps.absent() ? undefined : await steps.remove();
|
|
208
|
+
if (removed && !removed.ok)
|
|
209
|
+
throw new Error(`REINSTALL_REMOVE_FAILED: ${removed.output}`);
|
|
210
|
+
if (!await steps.absent())
|
|
211
|
+
throw new Error('REINSTALL_REMOVE_FAILED: profile dependency remains installed');
|
|
212
|
+
const wasAbsent = steps.hostAbsent();
|
|
213
|
+
const reverted = await steps.revert();
|
|
214
|
+
if (!reverted.ok && !(wasAbsent && steps.hostAbsent() && reverted.code === 1 && /^nothing to revert in /m.test(reverted.output)
|
|
215
|
+
&& !/error|refus|incomplete|EACCES|EPERM/i.test(reverted.output)))
|
|
216
|
+
throw new Error(`REINSTALL_REVERT_FAILED: ${reverted.output}`);
|
|
217
|
+
if (!steps.hostAbsent())
|
|
218
|
+
throw new Error('REINSTALL_REVERT_FAILED: host patch is still present');
|
|
219
|
+
const applied = await steps.apply();
|
|
220
|
+
if (!applied.ok || applied.hostPatch?.status !== 'applied')
|
|
221
|
+
throw new Error(`REINSTALL_APPLY_FAILED: ${applied.output}`);
|
|
222
|
+
const added = await steps.add();
|
|
223
|
+
if (!added.ok)
|
|
224
|
+
throw new Error(`REINSTALL_ADD_FAILED: ${added.output}`);
|
|
225
|
+
return { ...added, hostPatch: applied.hostPatch, output: [removed?.output, reverted.output, applied.output, added.output].filter(Boolean).join('\n').slice(-20_000) };
|
|
226
|
+
}
|
|
14
227
|
const terminal = new Set(['completed', 'failed', 'cancelled']);
|
|
15
228
|
const workerPath = fileURLToPath(new URL('./automatic-maintenance.js', import.meta.url));
|
|
16
229
|
const quitPath = fileURLToPath(new URL('../../desktop-bridge/request-desktop-quit.ps1', import.meta.url));
|
|
@@ -21,14 +234,22 @@ function reportMaintenanceFailure(label, error) {
|
|
|
21
234
|
console.error(`[dsh-browser maintenance] ${label}: ${String(error)}`);
|
|
22
235
|
}
|
|
23
236
|
function homePath() { return resolve(dshHome()); }
|
|
24
|
-
function basePath(home = homePath()) { return join(home,
|
|
237
|
+
function basePath(home = homePath()) { return join(home, BROWSER_PROFILE_DIR, 'maintenance'); }
|
|
25
238
|
function inside(base, path) {
|
|
26
239
|
const part = relative(base, path);
|
|
27
240
|
return part !== '' && !isAbsolute(part) && part !== '..' && !part.startsWith('..\\') && !part.startsWith('../');
|
|
28
241
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
242
|
+
/** Platforms whose Desktop can be quit, patched and reopened by the independent worker. */
|
|
243
|
+
export function automaticMaintenanceSupported(platform = process.platform) {
|
|
244
|
+
return platform === 'win32' || platform === 'darwin';
|
|
245
|
+
}
|
|
246
|
+
/** Same-path comparison: case-insensitive on Windows, by on-disk spelling elsewhere (APFS may be either). */
|
|
247
|
+
function samePath(a, b) {
|
|
248
|
+
return isDesktopExecutable(a, b);
|
|
249
|
+
}
|
|
250
|
+
function requireLiveDesktop() {
|
|
251
|
+
if (!automaticMaintenanceSupported())
|
|
252
|
+
throw new Error('automatic bridge maintenance requires DSH Desktop on Windows or macOS');
|
|
32
253
|
if (process.env.DSH_BROWSER_TEST === '1' || process.env.NODE_TEST_CONTEXT !== undefined) {
|
|
33
254
|
throw new Error('automatic Desktop maintenance is forbidden in a test process');
|
|
34
255
|
}
|
|
@@ -41,7 +262,50 @@ async function execute(command, args, timeout = 15_000, environment) {
|
|
|
41
262
|
});
|
|
42
263
|
});
|
|
43
264
|
}
|
|
44
|
-
|
|
265
|
+
/** The Desktop GUI process on macOS: `ps` gives pid, start time, executable path and argv. */
|
|
266
|
+
async function posixDesktopProcesses(root, includeBundleHelpers = false) {
|
|
267
|
+
const psEnv = { ...process.env, LC_ALL: 'C', LANG: 'C' };
|
|
268
|
+
const [started, commands] = await Promise.all([
|
|
269
|
+
execute('ps', ['-axww', '-o', 'pid=,lstart=,comm='], 15_000, psEnv),
|
|
270
|
+
execute('ps', ['-axww', '-o', 'pid=,args='], 15_000, psEnv),
|
|
271
|
+
]);
|
|
272
|
+
if (started.code !== 0 || commands.code !== 0)
|
|
273
|
+
throw new Error('cannot inspect running DSH Desktop processes');
|
|
274
|
+
const argv = new Map();
|
|
275
|
+
for (const line of commands.stdout.split('\n')) {
|
|
276
|
+
const match = /^\s*(\d+)\s(.*)$/.exec(line);
|
|
277
|
+
if (match !== null)
|
|
278
|
+
argv.set(Number(match[1]), match[2]);
|
|
279
|
+
}
|
|
280
|
+
const expected = desktopPaths(root).executable;
|
|
281
|
+
const layout = desktopLayout(root);
|
|
282
|
+
const bundleRoot = includeBundleHelpers && !('error' in layout) && layout.name === 'macos-bundle'
|
|
283
|
+
? root
|
|
284
|
+
: undefined;
|
|
285
|
+
const rows = [];
|
|
286
|
+
for (const line of started.stdout.split('\n')) {
|
|
287
|
+
// lstart is always five fields under C locale: "Fri Nov 20 04:10:00 2026".
|
|
288
|
+
const match = /^\s*(\d+)\s+(\S+\s+\S+\s+\d+\s+[\d:]+\s+\d{4})\s+(.+)$/.exec(line);
|
|
289
|
+
if (match === null)
|
|
290
|
+
continue;
|
|
291
|
+
const path = match[3].trim();
|
|
292
|
+
if (!isAbsolute(path))
|
|
293
|
+
continue;
|
|
294
|
+
const matched = isDesktopExecutable(path, expected, bundleRoot);
|
|
295
|
+
if (!matched)
|
|
296
|
+
continue;
|
|
297
|
+
const at = Date.parse(match[2]);
|
|
298
|
+
if (!Number.isFinite(at))
|
|
299
|
+
throw new Error('cannot identify a running DSH Desktop process');
|
|
300
|
+
rows.push({ pid: Number(match[1]), path, command: argv.get(Number(match[1])) ?? '', started: new Date(at).toISOString() });
|
|
301
|
+
}
|
|
302
|
+
return rows.filter(p => !NODE_MODE.test(p.command));
|
|
303
|
+
}
|
|
304
|
+
// The Desktop also ships a Node-mode CLI under its executable; it is not a GUI to close.
|
|
305
|
+
const NODE_MODE = /(?:^|\s)--expose-internals(?:\s|$)|\.[cm]?js(?:"|\s|$)|(?:^|\s)(?:--eval|--print|--input-type)(?:=|\s|$)|(?:^|\s)-(?:e|p)(?:\s|$)/i;
|
|
306
|
+
async function desktopProcesses(root, includeBundleHelpers = false) {
|
|
307
|
+
if (process.platform !== 'win32')
|
|
308
|
+
return await posixDesktopProcesses(root, includeBundleHelpers);
|
|
45
309
|
const script = "$ProgressPreference='SilentlyContinue'; $ErrorActionPreference='Stop'; [Console]::OutputEncoding=[System.Text.UTF8Encoding]::new($false); $rows = @((Get-CimInstance Win32_Process -Filter \"Name='DeepSeek Harness.exe'\" -ErrorAction Stop) | ForEach-Object { @{pid=[int]$_.ProcessId;path=$_.ExecutablePath;command=$_.CommandLine;started=$_.CreationDate.ToUniversalTime().ToString('o')} }); ConvertTo-Json -InputObject $rows -Compress";
|
|
46
310
|
const r = await execute(windowsPowerShellPath(), ['-NoProfile', '-NonInteractive', '-EncodedCommand', encodePowerShellScript(script)]);
|
|
47
311
|
if (r.code !== 0)
|
|
@@ -53,21 +317,51 @@ async function desktopProcesses(root) {
|
|
|
53
317
|
catch {
|
|
54
318
|
throw new Error('Desktop process inspection returned invalid data');
|
|
55
319
|
}
|
|
320
|
+
return identifyDesktopProcesses(root, value);
|
|
321
|
+
}
|
|
322
|
+
class DesktopProcessIdentityUnavailable extends Error {
|
|
323
|
+
}
|
|
324
|
+
/** Validate a CIM snapshot without treating an incomplete process identity as an exited process. */
|
|
325
|
+
export function identifyDesktopProcesses(root, value) {
|
|
56
326
|
const rows = Array.isArray(value) ? value : value === null ? [] : [value];
|
|
57
|
-
const expected =
|
|
327
|
+
const expected = desktopPaths(root).executable;
|
|
58
328
|
return rows.filter((row) => {
|
|
59
329
|
if (row === null || typeof row !== 'object')
|
|
60
330
|
throw new Error('Desktop process inspection was incomplete');
|
|
61
331
|
const p = row;
|
|
62
332
|
if (typeof p.path !== 'string' || p.path === '' || typeof p.command !== 'string' || !Number.isSafeInteger(p.pid) || typeof p.started !== 'string') {
|
|
63
|
-
throw new
|
|
333
|
+
throw new DesktopProcessIdentityUnavailable('cannot identify a running DSH Desktop process');
|
|
64
334
|
}
|
|
65
|
-
if (
|
|
335
|
+
if (!isDesktopExecutable(p.path, expected, undefined, 'win32'))
|
|
66
336
|
return false;
|
|
67
|
-
|
|
68
|
-
return !/(?:^|\s)--expose-internals(?:\s|$)|\.[cm]?js(?:"|\s|$)|(?:^|\s)(?:--eval|--print|--input-type)(?:=|\s|$)|(?:^|\s)-(?:e|p)(?:\s|$)/i.test(p.command);
|
|
337
|
+
return !NODE_MODE.test(p.command);
|
|
69
338
|
});
|
|
70
339
|
}
|
|
340
|
+
/** Wait through incomplete shutdown snapshots, but require a complete empty snapshot before writing. */
|
|
341
|
+
export async function waitForDesktopExit(deps) {
|
|
342
|
+
const now = deps.now ?? Date.now;
|
|
343
|
+
const deadline = now() + 60_000;
|
|
344
|
+
let incomplete = false;
|
|
345
|
+
while (now() < deadline) {
|
|
346
|
+
deps.checkCancelled();
|
|
347
|
+
try {
|
|
348
|
+
const rows = await deps.inspect();
|
|
349
|
+
deps.checkCancelled();
|
|
350
|
+
if (rows.length === 0)
|
|
351
|
+
return;
|
|
352
|
+
incomplete = false;
|
|
353
|
+
}
|
|
354
|
+
catch (error) {
|
|
355
|
+
if (!(error instanceof DesktopProcessIdentityUnavailable))
|
|
356
|
+
throw error;
|
|
357
|
+
incomplete = true;
|
|
358
|
+
}
|
|
359
|
+
await (deps.pause ?? (() => delay(1_000)))();
|
|
360
|
+
}
|
|
361
|
+
throw new Error(incomplete
|
|
362
|
+
? 'cannot verify that DSH Desktop exited: process identity remains unavailable; maintenance was cancelled'
|
|
363
|
+
: 'Desktop did not exit; maintenance was cancelled. Any running-task confirmation remains under your control.');
|
|
364
|
+
}
|
|
71
365
|
async function atomicJson(path, value, exclusive = false) {
|
|
72
366
|
if (exclusive && existsSync(path)) {
|
|
73
367
|
const error = new Error(`EEXIST: ${path} already exists`);
|
|
@@ -76,11 +370,19 @@ async function atomicJson(path, value, exclusive = false) {
|
|
|
76
370
|
}
|
|
77
371
|
const temp = `${path}.${String(process.pid)}.tmp`;
|
|
78
372
|
await writeFile(temp, JSON.stringify(value, null, 2) + '\n', { mode: 0o600 });
|
|
79
|
-
|
|
373
|
+
try {
|
|
374
|
+
await renameMaintenanceFile(temp, path);
|
|
375
|
+
}
|
|
376
|
+
finally {
|
|
377
|
+
await unlink(temp).catch(error => {
|
|
378
|
+
if (error.code !== 'ENOENT')
|
|
379
|
+
reportMaintenanceFailure('cannot remove maintenance temporary file', error);
|
|
380
|
+
});
|
|
381
|
+
}
|
|
80
382
|
}
|
|
81
383
|
/** Data-only argv for the independent, read-only progress window. This function starts nothing. */
|
|
82
384
|
export function maintenanceProgressLaunchOptions(jobId, directory, locale = 'zh', powershellPath = windowsPowerShellPath()) {
|
|
83
|
-
if (typeof jobId !== 'string' || !/^(?:install|uninstall)-[A-Za-z0-9]+$/.test(jobId)
|
|
385
|
+
if (typeof jobId !== 'string' || !/^(?:install|uninstall|reinstall)-[A-Za-z0-9]+$/.test(jobId)
|
|
84
386
|
|| typeof directory !== 'string' || !isAbsolute(directory) || basename(directory) !== jobId
|
|
85
387
|
|| !['zh', 'en'].includes(locale))
|
|
86
388
|
throw new Error('invalid maintenance progress request');
|
|
@@ -135,7 +437,7 @@ export function readAutomaticMaintenance(home = homePath()) {
|
|
|
135
437
|
return undefined;
|
|
136
438
|
const state = JSON.parse(readFileSync(join(pointer.directory, 'state.json'), 'utf8'));
|
|
137
439
|
if (state.id !== pointer.id || !['armed', 'closing', 'installing', 'restarting', 'verifying', ...terminal].includes(state.phase)
|
|
138
|
-
|| !['install', 'uninstall'].includes(state.action) || !Number.isFinite(Date.parse(state.at)))
|
|
440
|
+
|| !['install', 'uninstall', 'reinstall'].includes(state.action) || !Number.isFinite(Date.parse(state.at)))
|
|
139
441
|
return undefined;
|
|
140
442
|
return state;
|
|
141
443
|
}
|
|
@@ -151,7 +453,7 @@ async function clearStaleLock(lockPath, home) {
|
|
|
151
453
|
if (Date.now() - info.mtimeMs < 5 * 60_000)
|
|
152
454
|
return false;
|
|
153
455
|
const id = (await readFile(lockPath, 'utf8')).trim();
|
|
154
|
-
if (!/^(?:install|uninstall)-[A-Za-z0-9]+$/.test(id))
|
|
456
|
+
if (!/^(?:install|uninstall|reinstall)-[A-Za-z0-9]+$/.test(id))
|
|
155
457
|
return false;
|
|
156
458
|
const prior = readAutomaticMaintenance(home);
|
|
157
459
|
if (prior === undefined || prior.id !== id)
|
|
@@ -189,8 +491,9 @@ function validatePlan(value, path, now = Date.now()) {
|
|
|
189
491
|
throw new Error('invalid automatic maintenance plan');
|
|
190
492
|
const plan = value;
|
|
191
493
|
const created = typeof plan.createdAt === 'string' ? Date.parse(plan.createdAt) : NaN;
|
|
192
|
-
if (plan.version !== 1 ||
|
|
193
|
-
|| typeof plan.
|
|
494
|
+
if (plan.version !== 1 || plan.action !== 'reinstall'
|
|
495
|
+
|| typeof plan.dependency !== 'string' || plan.dependency.trim() === ''
|
|
496
|
+
|| typeof plan.id !== 'string' || !/^reinstall-[A-Za-z0-9]+$/.test(plan.id)
|
|
194
497
|
|| ![plan.root, plan.home, plan.nodePath, plan.directory].every(p => typeof p === 'string' && isAbsolute(p))
|
|
195
498
|
|| typeof plan.electronNode !== 'boolean' || !Number.isFinite(created) || created > now || now - created > 30_000
|
|
196
499
|
|| (plan.locale !== undefined && !['zh', 'en'].includes(plan.locale))) {
|
|
@@ -204,7 +507,7 @@ function validatePlan(value, path, now = Date.now()) {
|
|
|
204
507
|
}
|
|
205
508
|
const target = checked.target;
|
|
206
509
|
if (target === null || typeof target !== 'object' || !Number.isSafeInteger(target.pid) || target.pid <= 0
|
|
207
|
-
|| typeof target.path !== 'string' ||
|
|
510
|
+
|| typeof target.path !== 'string' || !samePath(target.path, desktopPaths(checked.root).executable)
|
|
208
511
|
|| typeof target.command !== 'string' || /(?:^|\s)--type(?:=|\s)/i.test(target.command)
|
|
209
512
|
|| typeof target.started !== 'string' || !Number.isFinite(Date.parse(target.started)) || Date.parse(target.started) > now) {
|
|
210
513
|
throw new Error('invalid automatic maintenance target process');
|
|
@@ -213,7 +516,7 @@ function validatePlan(value, path, now = Date.now()) {
|
|
|
213
516
|
}
|
|
214
517
|
/** Commit only the armed job after its accepted HTTP response has finished writing. */
|
|
215
518
|
export async function commitAutomaticMaintenance(jobId, home = homePath()) {
|
|
216
|
-
if (typeof jobId !== 'string' || !/^
|
|
519
|
+
if (typeof jobId !== 'string' || !/^reinstall-[A-Za-z0-9]+$/.test(jobId))
|
|
217
520
|
throw new Error('invalid bridge maintenance job id');
|
|
218
521
|
const state = readAutomaticMaintenance(home);
|
|
219
522
|
if (state?.id !== jobId || state.phase !== 'armed' || !Number.isSafeInteger(state.workerPid) || Number(state.workerPid) <= 0) {
|
|
@@ -240,14 +543,15 @@ export async function commitAutomaticMaintenance(jobId, home = homePath()) {
|
|
|
240
543
|
}
|
|
241
544
|
/** Only the new, authenticated explicit-click endpoint calls this function. */
|
|
242
545
|
export async function startAutomaticMaintenance(action, root, options = {}) {
|
|
243
|
-
|
|
244
|
-
if (
|
|
546
|
+
requireLiveDesktop();
|
|
547
|
+
if (action !== 'reinstall')
|
|
245
548
|
throw new Error('invalid bridge maintenance action');
|
|
246
549
|
if (options.locale !== undefined && !['zh', 'en'].includes(options.locale))
|
|
247
550
|
throw new Error('invalid bridge maintenance locale');
|
|
551
|
+
const dependency = await preflightReinstall(root, homePath());
|
|
248
552
|
if (!readDesktopIdentity(root).ok)
|
|
249
553
|
throw new Error('the maintenance target is not a verified DSH Desktop installation');
|
|
250
|
-
if (!existsSync(quitPath))
|
|
554
|
+
if (process.platform === 'win32' && !existsSync(quitPath))
|
|
251
555
|
throw new Error('the packaged Desktop quit helper is missing');
|
|
252
556
|
const processes = await desktopProcesses(root);
|
|
253
557
|
const mains = processes.filter(p => !/(?:^|\s)--type(?:=|\s)/i.test(p.command));
|
|
@@ -269,20 +573,23 @@ export async function startAutomaticMaintenance(action, root, options = {}) {
|
|
|
269
573
|
}
|
|
270
574
|
let plan;
|
|
271
575
|
try {
|
|
272
|
-
const prepared = await prepareBridgeMaintenance(
|
|
576
|
+
const prepared = await prepareBridgeMaintenance('install', root, { directory: base });
|
|
273
577
|
const original = JSON.parse(await readFile(prepared.planPath, 'utf8'));
|
|
274
|
-
const id = basename(prepared.directory);
|
|
578
|
+
const id = basename(prepared.directory).replace(/^install-/, 'reinstall-');
|
|
579
|
+
const directory = join(base, id);
|
|
580
|
+
await renameMaintenanceFile(prepared.directory, directory);
|
|
581
|
+
const stagedWorker = await stageReinstallRuntime(directory);
|
|
275
582
|
await lock.writeFile(id + '\n');
|
|
276
583
|
await lock.close();
|
|
277
|
-
plan = { version: 1, id, action, root: resolve(root), nodePath: original.nodePath, electronNode: original.electronNode,
|
|
278
|
-
home, directory
|
|
584
|
+
plan = { version: 1, id, action, dependency, nestedResidue: await inspectProfileResidue(home), root: resolve(root), nodePath: original.nodePath, electronNode: original.electronNode,
|
|
585
|
+
home, directory, target: mains[0], createdAt: new Date().toISOString(),
|
|
279
586
|
...options.locale === undefined ? {} : { locale: options.locale } };
|
|
280
|
-
const path = join(
|
|
587
|
+
const path = join(directory, 'automatic.json');
|
|
281
588
|
await writeFile(path, JSON.stringify(plan, null, 2) + '\n', { flag: 'wx', mode: 0o600 });
|
|
282
|
-
await atomicJson(join(base, 'latest.json'), { id, directory
|
|
589
|
+
await atomicJson(join(base, 'latest.json'), { id, directory });
|
|
283
590
|
const launched = await launchMaintenanceBroker({ runtimePath: plan.nodePath,
|
|
284
|
-
args: [...plan.electronNode ? ['--expose-internals'] : [],
|
|
285
|
-
environment: { DSH_HOME: home, ELECTRON_RUN_AS_NODE: plan.electronNode ? '1' : undefined } });
|
|
591
|
+
args: [...plan.electronNode ? ['--expose-internals'] : [], stagedWorker, '--automatic-maintenance', path], cwd: directory,
|
|
592
|
+
environment: { DSH_HOME: home, ELECTRON_RUN_AS_NODE: plan.electronNode ? '1' : undefined, ELECTRON_NO_ASAR: '1' } });
|
|
286
593
|
// WMI's return code proves creation only. The worker must actually load and publish its arm.
|
|
287
594
|
const deadline = Date.now() + 12_000;
|
|
288
595
|
while (Date.now() < deadline) {
|
|
@@ -312,9 +619,24 @@ export async function startAutomaticMaintenance(action, root, options = {}) {
|
|
|
312
619
|
throw error;
|
|
313
620
|
}
|
|
314
621
|
}
|
|
622
|
+
/**
|
|
623
|
+
* Ask the verified macOS Desktop to quit through its own Quit command (Apple event), exactly as
|
|
624
|
+
* Cmd-Q does: any running-task confirmation stays with the user. The pid and start time are
|
|
625
|
+
* re-read first, so a reused pid or a second copy of the app is never asked.
|
|
626
|
+
*/
|
|
627
|
+
async function requestPosixQuit(plan) {
|
|
628
|
+
const current = (await desktopProcesses(plan.root)).filter(p => !/(?:^|\s)--type(?:=|\s)/i.test(p.command));
|
|
629
|
+
if (current.length !== 1 || current[0]?.pid !== plan.target.pid || current[0].started !== plan.target.started) {
|
|
630
|
+
throw new Error('the running Desktop is not the one maintenance was requested from; no quit was sent');
|
|
631
|
+
}
|
|
632
|
+
const result = await execute('osascript', ['-e', 'on run argv', '-e', 'tell application (item 1 of argv) to quit', '-e', 'end run', plan.root], 25_000);
|
|
633
|
+
if (result.code !== 0)
|
|
634
|
+
throw new Error(result.output || 'the Desktop Quit command was not accepted');
|
|
635
|
+
}
|
|
315
636
|
async function runWorker(path) {
|
|
316
|
-
|
|
637
|
+
requireLiveDesktop();
|
|
317
638
|
const plan = validatePlan(JSON.parse(await readFile(path, 'utf8')), path);
|
|
639
|
+
let extension;
|
|
318
640
|
const checkCancelled = () => {
|
|
319
641
|
if (existsSync(join(plan.directory, 'cancel.json')))
|
|
320
642
|
throw new Error('bridge maintenance was cancelled before Desktop exited');
|
|
@@ -358,6 +680,10 @@ async function runWorker(path) {
|
|
|
358
680
|
throw new Error('the maintenance request was not committed; Desktop remains open');
|
|
359
681
|
checkCancelled();
|
|
360
682
|
await publish({ phase: 'closing', action: plan.action, at: new Date().toISOString() });
|
|
683
|
+
if (process.platform !== 'win32') {
|
|
684
|
+
await requestPosixQuit(plan);
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
361
687
|
await startMaintenanceProgressNotification({ jobId: plan.id, directory: plan.directory, locale: plan.locale ?? 'zh' });
|
|
362
688
|
const result = await execute(windowsPowerShellPath(), ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-File', quitPath,
|
|
363
689
|
'-TargetPid', String(plan.target.pid), '-ExpectedExecutable', plan.target.path,
|
|
@@ -367,43 +693,60 @@ async function runWorker(path) {
|
|
|
367
693
|
throw new Error(result.output || 'the official Desktop Quit menu was not available');
|
|
368
694
|
},
|
|
369
695
|
waitUntilClosed: async () => {
|
|
370
|
-
|
|
371
|
-
while (Date.now() < deadline) {
|
|
372
|
-
checkCancelled();
|
|
373
|
-
if ((await desktopProcesses(plan.root)).length === 0)
|
|
374
|
-
return;
|
|
375
|
-
await delay(1_000);
|
|
376
|
-
}
|
|
377
|
-
throw new Error('Desktop did not exit; maintenance was cancelled. Any running-task confirmation remains under your control.');
|
|
696
|
+
await waitForDesktopExit({ inspect: async () => await desktopProcesses(plan.root, true), checkCancelled });
|
|
378
697
|
},
|
|
379
698
|
maintain: async () => {
|
|
380
699
|
checkCancelled();
|
|
381
|
-
if ((await desktopProcesses(plan.root)).length > 0)
|
|
700
|
+
if ((await desktopProcesses(plan.root, true)).length > 0)
|
|
382
701
|
throw new Error('DSH Desktop was reopened during maintenance; refusing to modify its files');
|
|
383
|
-
|
|
702
|
+
if (await preflightReinstall(plan.root, plan.home) !== plan.dependency)
|
|
703
|
+
throw new Error('REINSTALL_DEPENDENCY_CHANGED');
|
|
704
|
+
const bridge = async (action) => await runBridgeAction(action, plan.root, {
|
|
384
705
|
node: () => plan.nodePath, installer: defaultInstallerPath, trackResult: true,
|
|
385
|
-
run: async (cmd, args, extra) => await execute(cmd, [...plan.electronNode ? ['--expose-internals'] : [], ...args], 180_000, { ...process.env, ...extra, ELECTRON_RUN_AS_NODE: plan.electronNode ? '1' : undefined }),
|
|
706
|
+
run: async (cmd, args, extra) => await execute(cmd, [...plan.electronNode ? ['--expose-internals'] : [], ...args], 180_000, { ...process.env, ...extra, ELECTRON_RUN_AS_NODE: plan.electronNode ? '1' : undefined, ELECTRON_NO_ASAR: '1' }),
|
|
386
707
|
});
|
|
708
|
+
const profile = async (action) => await repairProfileExtension(action, plan.root, plan.home, runProfileCommand, plan.dependency);
|
|
709
|
+
return await withProfileCheckpoint(plan.home, plan.directory, async () => {
|
|
710
|
+
const residue = await cleanProfileResidue(plan.home);
|
|
711
|
+
const result = await runReinstallTransaction({
|
|
712
|
+
remove: () => profile('uninstall'),
|
|
713
|
+
absent: async () => {
|
|
714
|
+
const manifest = JSON.parse(await readFile(join(plan.home, 'profiles', 'desktop', 'package.json'), 'utf8'));
|
|
715
|
+
return manifest.dependencies?.[MAIN_EXTENSION_NAME] === undefined && !existsSync(join(plan.home, 'profiles', 'desktop', 'node_modules', MAIN_EXTENSION_NAME));
|
|
716
|
+
},
|
|
717
|
+
revert: () => bridge('uninstall'),
|
|
718
|
+
hostAbsent: () => inspectReinstallHost(plan.root).status === 'absent',
|
|
719
|
+
apply: () => bridge('install'), add: () => profile('install'),
|
|
720
|
+
});
|
|
721
|
+
extension = await installedProfileExtension(plan.home);
|
|
722
|
+
return { ...result, output: [residue, result.output].filter(Boolean).join('\n') };
|
|
723
|
+
}, { reconcile: () => reconcileProfile(plan.root, plan.home) });
|
|
387
724
|
},
|
|
388
725
|
restart: async () => {
|
|
389
|
-
if ((await desktopProcesses(plan.root)).length > 0)
|
|
726
|
+
if ((await desktopProcesses(plan.root, true)).length > 0)
|
|
390
727
|
throw new Error('DSH Desktop is already running; not opening a second instance');
|
|
391
728
|
const identity = readDesktopIdentity(plan.root);
|
|
392
729
|
if (!identity.ok)
|
|
393
730
|
throw new Error(`Desktop cannot be safely reopened: ${identity.reason}`);
|
|
394
|
-
const environment = { ...process.env };
|
|
395
|
-
for (const key of Object.keys(environment))
|
|
396
|
-
|
|
731
|
+
const environment = { ...process.env, DSH_HOME: plan.home };
|
|
732
|
+
for (const key of Object.keys(environment)) {
|
|
733
|
+
const upper = key.toUpperCase();
|
|
734
|
+
if (upper === 'ELECTRON_RUN_AS_NODE' || upper === 'ELECTRON_NO_ASAR' || upper.startsWith('DSH_BRIDGE_')) {
|
|
397
735
|
delete environment[key];
|
|
736
|
+
}
|
|
737
|
+
}
|
|
398
738
|
return await new Promise((resolve, reject) => {
|
|
399
|
-
const child = spawn(
|
|
739
|
+
const child = spawn(desktopPaths(plan.root).executable, [], { cwd: plan.root, env: environment, stdio: 'ignore', windowsHide: true, detached: true });
|
|
400
740
|
child.once('error', reject);
|
|
401
741
|
child.once('spawn', () => { child.unref(); resolve(child.pid); });
|
|
402
742
|
});
|
|
403
743
|
},
|
|
404
744
|
verify: async (pid, action) => {
|
|
405
|
-
if (action === '
|
|
406
|
-
|
|
745
|
+
if (action === 'reinstall') {
|
|
746
|
+
if (inspectReinstallHost(plan.root).status !== 'applied')
|
|
747
|
+
throw new Error('REINSTALL_HOST_VERIFY_FAILED');
|
|
748
|
+
await waitForRestartedBridge(pid, { timeoutMs: 45_000, endpointPath: join(plan.home, 'dsh-builtin-browser-bridge.json'),
|
|
749
|
+
...(extension === undefined ? {} : { extension, home: plan.home }) });
|
|
407
750
|
return;
|
|
408
751
|
}
|
|
409
752
|
await delay(1_500);
|
|
@@ -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
|
|
@@ -67,7 +68,7 @@ export async function runWithManualBridgePreference(action, update, run) {
|
|
|
67
68
|
}
|
|
68
69
|
/** Where the attempt record lives, beside the settings the plugin already owns. */
|
|
69
70
|
export function autoInstallMarkerPath(dshHome) {
|
|
70
|
-
return join(dshHome,
|
|
71
|
+
return join(dshHome, BROWSER_PROFILE_DIR, 'bridge-auto-install.json');
|
|
71
72
|
}
|
|
72
73
|
/**
|
|
73
74
|
* Read the last attempt.
|