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,5 @@
|
|
|
1
|
+
import { hostMessages } from '../../assets/browser-messages.mjs';
|
|
2
|
+
import { LOOPBACK_IPV4, BROWSER_PROFILE_DIR } from '../../assets/browser-policy.mjs';
|
|
1
3
|
/**
|
|
2
4
|
* Self-hosted Electron browser host (child side): the Electron main process
|
|
3
5
|
* spawned by {@link RemoteElectronViewHost}. Owns one `BrowserWindow` PER
|
|
@@ -23,7 +25,9 @@
|
|
|
23
25
|
* The parent never parses stderr, so diagnostics may go there freely.
|
|
24
26
|
* @module dsh-browser/browser-electron/host-main
|
|
25
27
|
*/
|
|
26
|
-
import { app, BrowserWindow, WebContentsView } from 'electron';
|
|
28
|
+
import { app, BrowserWindow, Menu, session, WebContentsView } from 'electron';
|
|
29
|
+
import { overlayScript, overlayDisposeScript, referenceMenuTemplate, standaloneScript, REFERENCE_INTENT_CHANNEL, MAX_REFERENCE_COMMENT, MAX_REFERENCE_TEXT, } from '../browser-reference/entry.js';
|
|
30
|
+
import { validateFrozenCapture } from '../browser-reference/page-script.js';
|
|
27
31
|
import { createInterface } from 'node:readline';
|
|
28
32
|
import { createConnection } from 'node:net';
|
|
29
33
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
@@ -33,6 +37,7 @@ import { createRpcLineReader } from './rpc-input.js';
|
|
|
33
37
|
import { tmpdir } from 'node:os';
|
|
34
38
|
import { join } from 'node:path';
|
|
35
39
|
import { withTimeoutShared } from './timing.js';
|
|
40
|
+
import { dshHome } from './paths.js';
|
|
36
41
|
// Report the binary actually running this child, even when ELECTRON_PATH
|
|
37
42
|
// intentionally selects a different version from the plugin's dependency.
|
|
38
43
|
// The parent mirrors stderr to the host log; discovery stays filesystem-only.
|
|
@@ -50,8 +55,8 @@ for (const line of electronRuntimeDiagnosticLines(process.versions)) {
|
|
|
50
55
|
// (capturePage then fails). A dedicated userData also persists cookies across
|
|
51
56
|
// host restarts (on top of dsh_browser_auth). Must run before app is ready.
|
|
52
57
|
try {
|
|
53
|
-
const base =
|
|
54
|
-
app.setPath('userData', join(base,
|
|
58
|
+
const base = dshHome();
|
|
59
|
+
app.setPath('userData', join(base, BROWSER_PROFILE_DIR));
|
|
55
60
|
}
|
|
56
61
|
catch (error) {
|
|
57
62
|
process.stderr.write(`[dsh-browser host] userData setup failed: ${String(error)}\n`);
|
|
@@ -364,6 +369,7 @@ function windowFor(windowId) {
|
|
|
364
369
|
// (measured: the setting was on and the window still popped up). The first presentation decides:
|
|
365
370
|
// quiet shows it inactive, a normal call shows it normally.
|
|
366
371
|
const w = new BrowserWindow({ width: 1400, height: 900, show: false, title: 'dsh-browser' });
|
|
372
|
+
w.webContents.setWindowOpenHandler(() => ({ action: 'deny' }));
|
|
367
373
|
w.on('closed', () => {
|
|
368
374
|
const closing = windows.get(key);
|
|
369
375
|
windows.delete(key);
|
|
@@ -707,9 +713,7 @@ async function handle(op, msg) {
|
|
|
707
713
|
}
|
|
708
714
|
return { action: 'deny' };
|
|
709
715
|
}
|
|
710
|
-
|
|
711
|
-
// allow the native window so OAuth flows and deep links work.
|
|
712
|
-
return { action: 'allow' };
|
|
716
|
+
return { action: 'deny' };
|
|
713
717
|
});
|
|
714
718
|
// Attach the debugger BEFORE the view can be seen: an attach failure
|
|
715
719
|
// then leaves nothing in the window (no visible ghost view).
|
|
@@ -1188,6 +1192,142 @@ function keepWindowsNonOccluding() {
|
|
|
1188
1192
|
app.commandLine.appendSwitch('disable-features', features.join(','));
|
|
1189
1193
|
}
|
|
1190
1194
|
keepWindowsNonOccluding();
|
|
1195
|
+
// ---------------------------------------------------------------------------
|
|
1196
|
+
// Human reference entries (design §3.1 / §11.3): ONE owner per page.
|
|
1197
|
+
// A typed preload gives the page a narrow intent channel; the page-side
|
|
1198
|
+
// overlay is low-trust and never receives activeTab/screenshot authority.
|
|
1199
|
+
// ---------------------------------------------------------------------------
|
|
1200
|
+
const REFERENCE_PRELOAD = `const { contextBridge, ipcRenderer } = require('electron')
|
|
1201
|
+
try {
|
|
1202
|
+
contextBridge.exposeInMainWorld('__dshRef', {
|
|
1203
|
+
intent: payload => ipcRenderer.send('dsh-reference-intent', payload),
|
|
1204
|
+
})
|
|
1205
|
+
} catch (error) { /* another preload already owns this name */ }
|
|
1206
|
+
`;
|
|
1207
|
+
const REFERENCE_PRELOAD_PATH = join(TOOLBAR_DIR, 'reference-preload.js');
|
|
1208
|
+
function isToolbarContents(contents) {
|
|
1209
|
+
try {
|
|
1210
|
+
return contents.getURL().endsWith('/toolbar.html');
|
|
1211
|
+
}
|
|
1212
|
+
catch {
|
|
1213
|
+
return false;
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
/** Find the session/window id whose view owns these webContents. */
|
|
1217
|
+
function windowIdForContents(contents) {
|
|
1218
|
+
for (const [key, win] of windows) {
|
|
1219
|
+
for (const entry of win.views.values()) {
|
|
1220
|
+
try {
|
|
1221
|
+
if (entry.webContentsView.webContents === contents)
|
|
1222
|
+
return key;
|
|
1223
|
+
}
|
|
1224
|
+
catch { /* view was destroyed mid-iteration */ }
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
return undefined;
|
|
1228
|
+
}
|
|
1229
|
+
/** Install the single merged context menu and the resident selection entry. */
|
|
1230
|
+
function attachReferenceEntry(contents) {
|
|
1231
|
+
if (isToolbarContents(contents))
|
|
1232
|
+
return;
|
|
1233
|
+
contents.on('context-menu', (_event, params) => {
|
|
1234
|
+
const windowId = windowIdForContents(contents);
|
|
1235
|
+
if (windowId === undefined)
|
|
1236
|
+
return;
|
|
1237
|
+
// The browser's ordinary edit items are kept in the SAME menu, so no second
|
|
1238
|
+
// adapter can pop another one over it (design §3.1:59). The real params
|
|
1239
|
+
// decide which reference actions exist, and the target travels with the
|
|
1240
|
+
// action so a collapsed selection cannot change what was clicked (§3.2/§3.3).
|
|
1241
|
+
const hasSelection = typeof params.selectionText === 'string' && params.selectionText.trim() !== '';
|
|
1242
|
+
const mediaType = typeof params.mediaType === 'string' ? params.mediaType : undefined;
|
|
1243
|
+
const template = referenceMenuTemplate({
|
|
1244
|
+
hasSelection,
|
|
1245
|
+
...mediaType !== undefined ? { mediaType } : {},
|
|
1246
|
+
}).map(item => {
|
|
1247
|
+
if (item.kind === 'separator')
|
|
1248
|
+
return { type: 'separator' };
|
|
1249
|
+
if (item.kind === 'role') {
|
|
1250
|
+
if (item.role === undefined)
|
|
1251
|
+
return { type: 'separator' };
|
|
1252
|
+
return { role: item.role, label: item.label };
|
|
1253
|
+
}
|
|
1254
|
+
const target = item.target === undefined ? undefined : {
|
|
1255
|
+
kind: item.target,
|
|
1256
|
+
...item.target === 'image' && typeof params.srcURL === 'string' && params.srcURL !== ''
|
|
1257
|
+
? { srcUrl: params.srcURL } : {},
|
|
1258
|
+
...Number.isFinite(params.x) ? { x: params.x } : {},
|
|
1259
|
+
...Number.isFinite(params.y) ? { y: params.y } : {},
|
|
1260
|
+
};
|
|
1261
|
+
return {
|
|
1262
|
+
id: item.id,
|
|
1263
|
+
label: item.label,
|
|
1264
|
+
click: () => sendUserAction({
|
|
1265
|
+
type: 'capture-reference', windowId, entry: 'native-menu',
|
|
1266
|
+
...target !== undefined ? { target } : {},
|
|
1267
|
+
}),
|
|
1268
|
+
};
|
|
1269
|
+
});
|
|
1270
|
+
try {
|
|
1271
|
+
Menu.buildFromTemplate(template).popup();
|
|
1272
|
+
}
|
|
1273
|
+
catch (error) {
|
|
1274
|
+
process.stderr.write(`[dsh-browser host] reference menu failed: ${String(error)}\n`);
|
|
1275
|
+
}
|
|
1276
|
+
});
|
|
1277
|
+
contents.on('ipc-message', (_event, channel, ...args) => {
|
|
1278
|
+
if (channel !== 'dsh-reference-intent')
|
|
1279
|
+
return;
|
|
1280
|
+
const intent = args[0];
|
|
1281
|
+
if (intent === undefined || intent.type !== REFERENCE_INTENT_CHANNEL)
|
|
1282
|
+
return;
|
|
1283
|
+
// isTrusted is deliberately NOT read: a page overlay is a low-trust entry.
|
|
1284
|
+
const windowId = windowIdForContents(contents);
|
|
1285
|
+
if (windowId === undefined)
|
|
1286
|
+
return;
|
|
1287
|
+
// The page trims its own note; the host re-bounds it because a page is
|
|
1288
|
+
// low-trust, and ignores anything that is not a string.
|
|
1289
|
+
const rawComment = typeof intent.comment === 'string' ? intent.comment.trim() : '';
|
|
1290
|
+
const comment = rawComment.slice(0, MAX_REFERENCE_COMMENT);
|
|
1291
|
+
// The bar freezes the selection text before the comment field takes focus
|
|
1292
|
+
// (focusing it collapses the page selection). Re-bound here: a page is
|
|
1293
|
+
// low-trust, and this string becomes the locator when the live selection is
|
|
1294
|
+
// already gone.
|
|
1295
|
+
const rawSelection = typeof intent.selectionText === 'string' ? intent.selectionText : '';
|
|
1296
|
+
const selectionText = rawSelection.trim().slice(0, MAX_REFERENCE_TEXT);
|
|
1297
|
+
// The bar freezes the complete ordered capture before its comment field
|
|
1298
|
+
// takes focus. Bound and shape-check it here: a page is low-trust.
|
|
1299
|
+
const capture = validateFrozenCapture(intent.capture);
|
|
1300
|
+
sendUserAction({
|
|
1301
|
+
type: 'capture-reference', windowId, entry: 'page-overlay',
|
|
1302
|
+
...comment !== '' ? { comment } : {},
|
|
1303
|
+
...selectionText !== '' ? { selectionText } : {},
|
|
1304
|
+
...capture !== undefined ? { capture } : {},
|
|
1305
|
+
});
|
|
1306
|
+
});
|
|
1307
|
+
contents.on('dom-ready', () => {
|
|
1308
|
+
if (isToolbarContents(contents))
|
|
1309
|
+
return;
|
|
1310
|
+
void contents.executeJavaScript(standaloneScript(overlayScript(), { label: hostMessages.zh.referenceLabel }))
|
|
1311
|
+
.catch(() => { });
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
app.on('web-contents-created', (_event, contents) => {
|
|
1315
|
+
try {
|
|
1316
|
+
attachReferenceEntry(contents);
|
|
1317
|
+
}
|
|
1318
|
+
catch (error) {
|
|
1319
|
+
process.stderr.write(`[dsh-browser host] reference entry failed: ${String(error)}\n`);
|
|
1320
|
+
}
|
|
1321
|
+
});
|
|
1322
|
+
/** Remove the overlay on plugin shutdown; the disposer clears every listener. */
|
|
1323
|
+
export function disposeReferenceEntries(views) {
|
|
1324
|
+
for (const contents of views) {
|
|
1325
|
+
try {
|
|
1326
|
+
void contents.executeJavaScript(standaloneScript(overlayDisposeScript()));
|
|
1327
|
+
}
|
|
1328
|
+
catch { /* gone */ }
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1191
1331
|
/**
|
|
1192
1332
|
* Electron entry: connect back to the parent's RPC server (port from
|
|
1193
1333
|
* `--rpc-port`) and serve line-delimited JSON-RPC. `ELECTRON_RUN_AS_NODE` is
|
|
@@ -1195,6 +1335,21 @@ keepWindowsNonOccluding();
|
|
|
1195
1335
|
* the app entry so `app` is available immediately.
|
|
1196
1336
|
*/
|
|
1197
1337
|
void app.whenReady().then(() => {
|
|
1338
|
+
// One narrow preload for every webContents in this session. It only exposes
|
|
1339
|
+
// an intent sender; no file, command or CDP capability crosses the boundary.
|
|
1340
|
+
try {
|
|
1341
|
+
mkdirSync(TOOLBAR_DIR, { recursive: true });
|
|
1342
|
+
writeFileSync(REFERENCE_PRELOAD_PATH, REFERENCE_PRELOAD);
|
|
1343
|
+
// APPEND, never replace: another part of the shell may already own a
|
|
1344
|
+
// preload, and `setPreloads` takes the whole list.
|
|
1345
|
+
const existing = session.defaultSession.getPreloads();
|
|
1346
|
+
if (!existing.includes(REFERENCE_PRELOAD_PATH)) {
|
|
1347
|
+
session.defaultSession.setPreloads([...existing, REFERENCE_PRELOAD_PATH]);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
catch (error) {
|
|
1351
|
+
process.stderr.write(`[dsh-browser host] reference preload unavailable: ${String(error)}\n`);
|
|
1352
|
+
}
|
|
1198
1353
|
const portArg = process.argv.indexOf('--rpc-port');
|
|
1199
1354
|
const port = portArg >= 0 ? Number(process.argv[portArg + 1]) : NaN;
|
|
1200
1355
|
if (!Number.isFinite(port)) {
|
|
@@ -1202,7 +1357,7 @@ void app.whenReady().then(() => {
|
|
|
1202
1357
|
app.exit(1);
|
|
1203
1358
|
return;
|
|
1204
1359
|
}
|
|
1205
|
-
const socket = createConnection({ host:
|
|
1360
|
+
const socket = createConnection({ host: LOOPBACK_IPV4, port });
|
|
1206
1361
|
rpcSocket = socket;
|
|
1207
1362
|
socket.setEncoding('utf8');
|
|
1208
1363
|
// Prove we know the parent's spawn token before anything else; the parent
|
|
@@ -0,0 +1,141 @@
|
|
|
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
|
+
/** Explicit Web maintenance for the sidebar bundle selected by DSH's client module registry. */
|
|
19
|
+
import { accessSync, constants, existsSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
20
|
+
import { dirname, join } from 'node:path';
|
|
21
|
+
import { sameOrigin } from './settings-route.js';
|
|
22
|
+
import { isDirectLoopback } from './authenticated-route.js';
|
|
23
|
+
import { readJsonBody } from './http-body.js';
|
|
24
|
+
import { replyJson } from './json-reply.js';
|
|
25
|
+
export const HOST_PATCH_ROUTE = '/dsh-builtin-browser/host-patch-maintenance';
|
|
26
|
+
const sidebar = '@deepseek-ai/dsh-client-ui-sidebar-right';
|
|
27
|
+
/** Bind to the live optional service, never resolve a second copy relative to the plugin. */
|
|
28
|
+
export function servedClientModules(value) {
|
|
29
|
+
if (value !== null && typeof value === 'object' && 'clientPath' in value && typeof value.clientPath === 'function') {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
/** Locate only the package whose lib/client.js the running registry actually advertises. */
|
|
35
|
+
export function servedSidebarPackage(modules) {
|
|
36
|
+
const path = modules?.clientPath(sidebar);
|
|
37
|
+
if (path === undefined)
|
|
38
|
+
throw new Error('The running DSH client registry has no sidebar bundle; host patch maintenance is unavailable.');
|
|
39
|
+
const file = realpathSync(path);
|
|
40
|
+
const directory = dirname(dirname(file));
|
|
41
|
+
const manifest = JSON.parse(readFileSync(join(directory, 'package.json'), 'utf8'));
|
|
42
|
+
if (manifest.name !== sidebar || realpathSync(join(directory, 'lib/client.js')) !== file) {
|
|
43
|
+
throw new Error('The served sidebar bundle is not the supported package lib/client.js.');
|
|
44
|
+
}
|
|
45
|
+
return directory;
|
|
46
|
+
}
|
|
47
|
+
/** Same authenticated, same-origin, local-only maintenance admission as Desktop settings. */
|
|
48
|
+
export function createHostPatchMaintenance(deps) {
|
|
49
|
+
let running = false;
|
|
50
|
+
return async (request, response) => {
|
|
51
|
+
if (request.method !== 'GET' && request.method !== 'POST') {
|
|
52
|
+
replyJson(response, 405, { ok: false, error: 'method-not-allowed' });
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (!sameOrigin(request, request.method === 'POST') || !isDirectLoopback(request)) {
|
|
56
|
+
replyJson(response, 403, { ok: false, error: 'same-origin-local-request-required' });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (deps.desktop()) {
|
|
60
|
+
replyJson(response, request.method === 'GET' ? 200 : 409, { ok: request.method === 'GET', hostPatch: { surface: 'desktop', status: 'absent', canInstall: false, canRestore: false,
|
|
61
|
+
restartRequired: false, reason: 'Use Desktop bridge maintenance to change host files after Desktop exits.' } });
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
let directory;
|
|
65
|
+
const modules = deps.modules();
|
|
66
|
+
try {
|
|
67
|
+
directory = servedSidebarPackage(modules);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
replyJson(response, request.method === 'GET' ? 200 : 409, { ok: request.method === 'GET', hostPatch: {
|
|
71
|
+
surface: 'web', status: 'anchors mismatch', canInstall: false, canRestore: false, restartRequired: false, reason: String(error),
|
|
72
|
+
} });
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const patcher = await import(__rewriteRelativeImportExtension(new URL('../../dsh-host-patch/apply.mjs', import.meta.url).href));
|
|
76
|
+
const read = () => {
|
|
77
|
+
const result = patcher.hostPatchStatus(directory);
|
|
78
|
+
let writable = true;
|
|
79
|
+
let reason = result.reason;
|
|
80
|
+
try {
|
|
81
|
+
for (const path of [join(directory, 'lib'), join(directory, 'lib/client.js')]) {
|
|
82
|
+
if ((statSync(path).mode & 0o222) === 0)
|
|
83
|
+
throw new Error('read-only permissions');
|
|
84
|
+
accessSync(path, constants.W_OK);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
writable = false;
|
|
89
|
+
reason = 'The served sidebar package is not writable: ' + String(error);
|
|
90
|
+
}
|
|
91
|
+
return { ...result, ...(reason === undefined ? {} : { reason }), surface: 'web',
|
|
92
|
+
canInstall: writable && result.status === 'absent',
|
|
93
|
+
canRestore: writable && result.status === 'applied' && existsSync(join(directory, 'lib/client.js.before-dsh-host-patch')),
|
|
94
|
+
restartRequired: false };
|
|
95
|
+
};
|
|
96
|
+
if (request.method === 'GET') {
|
|
97
|
+
replyJson(response, 200, { ok: true, hostPatch: read() });
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (running) {
|
|
101
|
+
replyJson(response, 409, { ok: false, error: 'host patch maintenance is already running' });
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
let action;
|
|
105
|
+
try {
|
|
106
|
+
const input = await readJsonBody(request, 4096);
|
|
107
|
+
if (input?.action !== 'install' && input?.action !== 'restore')
|
|
108
|
+
throw new Error('action must be install or restore');
|
|
109
|
+
action = input.action;
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
replyJson(response, 400, { ok: false, error: String(error) });
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const before = read();
|
|
116
|
+
if (action === 'install' ? !before.canInstall : !before.canRestore) {
|
|
117
|
+
replyJson(response, 409, { ok: false, hostPatch: before, error: before.reason ?? 'This action is not available for the served sidebar package.' });
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
running = true;
|
|
121
|
+
try {
|
|
122
|
+
const result = action === 'install' ? patcher.applyHostPatch(directory) : patcher.restoreHostPatch(directory);
|
|
123
|
+
const ok = result.status === (action === 'install' ? 'applied' : 'absent');
|
|
124
|
+
let restartRequired = ok && result.changed === true;
|
|
125
|
+
let reason = result.reason;
|
|
126
|
+
if (restartRequired && typeof modules?.rebuilt === 'function') {
|
|
127
|
+
try {
|
|
128
|
+
modules.rebuilt(sidebar);
|
|
129
|
+
restartRequired = false;
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
reason = 'Files changed, but DSH could not refresh its bundle cache: ' + String(error);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
replyJson(response, ok ? 200 : 409, { ok, hostPatch: { ...read(), ...result, ...(reason === undefined ? {} : { reason }), restartRequired } });
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
running = false;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
@@ -20,6 +20,28 @@ export async function readTextBody(request, limit = 64 * 1024) {
|
|
|
20
20
|
}
|
|
21
21
|
return Buffer.concat(chunks).toString('utf8');
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Read a bounded binary body. The reference-import route takes ZIP bytes directly instead of a
|
|
25
|
+
* base64 JSON wrapper: a wrapper would inflate the limit by a third and add a decoding step that
|
|
26
|
+
* can hide an oversize body until after it has been allocated.
|
|
27
|
+
* @param request - the incoming request.
|
|
28
|
+
* @param limit - maximum accepted bytes.
|
|
29
|
+
* @returns the raw body.
|
|
30
|
+
*/
|
|
31
|
+
export async function readBinaryBody(request, limit = 32 * 1024 * 1024) {
|
|
32
|
+
const chunks = [];
|
|
33
|
+
let size = 0;
|
|
34
|
+
for await (const chunk of request) {
|
|
35
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
|
|
36
|
+
size += buffer.length;
|
|
37
|
+
if (size > limit) {
|
|
38
|
+
request.destroy();
|
|
39
|
+
throw new Error(`request body exceeds ${limit} bytes`);
|
|
40
|
+
}
|
|
41
|
+
chunks.push(buffer);
|
|
42
|
+
}
|
|
43
|
+
return Buffer.concat(chunks);
|
|
44
|
+
}
|
|
23
45
|
/**
|
|
24
46
|
* Read and parse a JSON body. An empty body is an empty object, matching the settings route's
|
|
25
47
|
* long-standing behaviour.
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Start a local
|
|
2
|
+
* Start a local maintenance coordinator outside the requesting app's tree: through WMI on Windows,
|
|
3
|
+
* as a detached session leader on macOS (which survives the app quitting).
|
|
3
4
|
* This primitive only creates the requested process; its caller owns maintenance authorization,
|
|
4
5
|
* the coordinator's plan, readiness handshake and normal application shutdown.
|
|
5
6
|
* @module dsh-browser/browser-electron/maintenance-broker
|
|
6
7
|
*/
|
|
7
|
-
import { execFile } from 'node:child_process';
|
|
8
|
+
import { execFile, spawn } from 'node:child_process';
|
|
8
9
|
import { statSync } from 'node:fs';
|
|
9
|
-
import { win32 } from 'node:path';
|
|
10
|
+
import { isAbsolute, posix, win32 } from 'node:path';
|
|
10
11
|
import { encodePowerShellScript, windowsPowerShellPath } from './windows-system.js';
|
|
11
12
|
/** Quote one argument using the Windows C runtime's command-line decoding rules. */
|
|
12
13
|
export function quoteWin32Argument(value) {
|
|
@@ -52,6 +53,32 @@ const defaultExecutor = (file, args, options) => new Promise((resolve, reject) =
|
|
|
52
53
|
resolve({ stdout, stderr });
|
|
53
54
|
});
|
|
54
55
|
});
|
|
56
|
+
/** macOS: a new session (setsid) with no inherited stdio, so the coordinator outlives Desktop. */
|
|
57
|
+
async function launchDetached(options, environment) {
|
|
58
|
+
for (const [label, value] of [['runtimePath', options.runtimePath], ['cwd', options.cwd]]) {
|
|
59
|
+
if (typeof value !== 'string' || value.includes('\0') || !isAbsolute(value))
|
|
60
|
+
throw new Error(`${label} must be an absolute path without NUL`);
|
|
61
|
+
}
|
|
62
|
+
const runtimePath = posix.normalize(options.runtimePath);
|
|
63
|
+
const cwd = posix.normalize(options.cwd);
|
|
64
|
+
if (!statSync(runtimePath).isFile())
|
|
65
|
+
throw new Error('the maintenance runtime is not a file');
|
|
66
|
+
if (!statSync(cwd).isDirectory())
|
|
67
|
+
throw new Error('the maintenance working directory is not a directory');
|
|
68
|
+
if (!Array.isArray(options.args))
|
|
69
|
+
throw new Error('maintenance arguments must be an array');
|
|
70
|
+
return await new Promise((resolve, reject) => {
|
|
71
|
+
const child = spawn(runtimePath, [...options.args], { cwd, env: environment, detached: true, stdio: 'ignore', shell: false });
|
|
72
|
+
child.once('error', error => { reject(new Error(`maintenance broker failed: ${String(error)}`)); });
|
|
73
|
+
child.once('spawn', () => {
|
|
74
|
+
child.unref();
|
|
75
|
+
if (!Number.isSafeInteger(child.pid) || Number(child.pid) <= 0)
|
|
76
|
+
reject(new Error('the maintenance broker returned no valid process id'));
|
|
77
|
+
else
|
|
78
|
+
resolve({ pid: Number(child.pid) });
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
55
82
|
/**
|
|
56
83
|
* Create a hidden, independent local process. No shell evaluates runtime paths or arguments.
|
|
57
84
|
* WMI receives an explicit environment copied from this process, including any plan overrides;
|
|
@@ -62,8 +89,11 @@ export async function launchMaintenanceBroker(options, deps = {}) {
|
|
|
62
89
|
if (deps.execFile === undefined && (underTest(process.env) || underTest(environment))) {
|
|
63
90
|
throw new Error('the real Windows maintenance broker is disabled in tests; inject a fake executor');
|
|
64
91
|
}
|
|
65
|
-
|
|
66
|
-
|
|
92
|
+
const platform = deps.platform ?? process.platform;
|
|
93
|
+
if (platform === 'darwin')
|
|
94
|
+
return await launchDetached(options, environment);
|
|
95
|
+
if (platform !== 'win32')
|
|
96
|
+
throw new Error('the maintenance broker requires Windows or macOS');
|
|
67
97
|
const runtimePath = absolutePath(options.runtimePath, 'runtimePath');
|
|
68
98
|
const cwd = absolutePath(options.cwd, 'cwd');
|
|
69
99
|
if (!statSync(runtimePath).isFile())
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export class MaintenanceRecoveryError extends Error {
|
|
2
|
+
}
|
|
1
3
|
/**
|
|
2
4
|
* A cancelled/failed quit never reaches the installer. After a confirmed exit, reopen Desktop even
|
|
3
5
|
* when maintenance fails, and retain that failure instead of reporting a successful installation.
|
|
@@ -19,8 +21,9 @@ export async function runMaintenanceLifecycle(action, deps) {
|
|
|
19
21
|
if (phase === 'armed')
|
|
20
22
|
throw error;
|
|
21
23
|
publicationFailure ??= error;
|
|
24
|
+
console.error(`[dsh-browser maintenance] cannot publish ${phase} progress: ${String(error)}`);
|
|
22
25
|
}
|
|
23
|
-
return state;
|
|
26
|
+
return publicationFailure === undefined ? state : { ...state, progressError: String(publicationFailure) };
|
|
24
27
|
};
|
|
25
28
|
await publish('armed');
|
|
26
29
|
try {
|
|
@@ -57,10 +60,9 @@ export async function runMaintenanceLifecycle(action, deps) {
|
|
|
57
60
|
catch (error) {
|
|
58
61
|
failure = failure === undefined ? error : new Error(`${String(failure)}; Desktop recovery: ${String(error)}`);
|
|
59
62
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const details = { restarted, ...pid === undefined ? {} : { pid }, ...outcome?.output ? { output: outcome.output } : {} };
|
|
63
|
+
const details = { restarted, ...pid === undefined ? {} : { pid }, ...outcome?.output ? { output: outcome.output } : {},
|
|
64
|
+
...publicationFailure === undefined ? {} : { progressError: String(publicationFailure) },
|
|
65
|
+
...outcome?.hostPatch === undefined ? {} : { hostPatch: outcome.hostPatch } };
|
|
64
66
|
return failure === undefined
|
|
65
67
|
? await publish('completed', { ...details, ok: true })
|
|
66
68
|
: await publish('failed', { ...details, ok: false, error: String(failure) });
|
|
@@ -25,15 +25,17 @@ export function createAutomaticMaintenanceHandler(deps) {
|
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
if (!deps.supported()) {
|
|
28
|
-
replyJson(response, 409, { ok: false, error: 'automatic bridge maintenance requires Windows
|
|
28
|
+
replyJson(response, 409, { ok: false, error: 'automatic bridge maintenance requires DSH Desktop on Windows or macOS' });
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
let action;
|
|
32
32
|
let locale;
|
|
33
33
|
try {
|
|
34
34
|
const value = await readJsonBody(request, 4096);
|
|
35
|
-
if (value?.action !== '
|
|
36
|
-
throw new Error('action must be
|
|
35
|
+
if (value?.action !== 'reinstall')
|
|
36
|
+
throw new Error('action must be reinstall');
|
|
37
|
+
if (value.mode !== undefined || value.hostStatus !== undefined)
|
|
38
|
+
throw new Error('mode and hostStatus are no longer supported');
|
|
37
39
|
if (value.locale !== undefined && value.locale !== 'zh' && value.locale !== 'en')
|
|
38
40
|
throw new Error('locale must be zh or en');
|
|
39
41
|
action = value.action;
|
|
@@ -49,7 +51,8 @@ export function createAutomaticMaintenanceHandler(deps) {
|
|
|
49
51
|
}
|
|
50
52
|
starting = true;
|
|
51
53
|
try {
|
|
52
|
-
const
|
|
54
|
+
const options = { ...locale === undefined ? {} : { locale } };
|
|
55
|
+
const job = await deps.start(action, Object.keys(options).length === 0 ? undefined : options);
|
|
53
56
|
if (deps.commit !== undefined) {
|
|
54
57
|
let fired = false;
|
|
55
58
|
const commitOnce = () => {
|
|
@@ -63,10 +66,10 @@ export function createAutomaticMaintenanceHandler(deps) {
|
|
|
63
66
|
response.once('finish', commitOnce);
|
|
64
67
|
response.once('close', commitOnce);
|
|
65
68
|
}
|
|
66
|
-
replyJson(response, 202, { ok: true, accepted: true, protocol: 1, job });
|
|
69
|
+
replyJson(response, 202, { ok: true, accepted: true, protocol: 1, quit: deps.quit?.() ?? 'menu', job });
|
|
67
70
|
}
|
|
68
71
|
catch (error) {
|
|
69
|
-
replyJson(response, 409, { ok: false, error: String(error) });
|
|
72
|
+
replyJson(response, 409, { ok: false, error: String(error), ...(error instanceof Error && 'code' in error ? { code: error.code } : {}) });
|
|
70
73
|
}
|
|
71
74
|
finally {
|
|
72
75
|
starting = false;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The last page a tool opened, shared by the provider and the HTTP surface.
|
|
3
|
+
*
|
|
4
|
+
* The provider instance that runs a tool and the one that answers routes are not guaranteed to be the
|
|
5
|
+
* same object (a surface can be built per context), so an instance field read back `null`. A module-level
|
|
6
|
+
* slot is what both sides can see — and it is what lets the Web sidebar place a tool-opened page with one
|
|
7
|
+
* call instead of a manual address-bar dance.
|
|
8
|
+
* @module dsh-builtin-browser/browser-electron/open-slot
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The slot lives on \`globalThis\`: the plugin's lib can be imported by more than one module instance in the
|
|
12
|
+
* same process (tools and the HTTP surface), and module-level state is per instance — which read back as
|
|
13
|
+
* \`null\` even after an open.
|
|
14
|
+
*/
|
|
15
|
+
const SLOT = '__dshBuiltinBrowserLastOpen';
|
|
16
|
+
/**
|
|
17
|
+
* Record an open request.
|
|
18
|
+
* @param url - the page a tool asked to open.
|
|
19
|
+
* @param at - arrival time in epoch milliseconds.
|
|
20
|
+
*/
|
|
21
|
+
export function setLastOpen(url, at, owner) {
|
|
22
|
+
globalThis[SLOT] = { url, at, ...owner === undefined ? {} : { owner } };
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Read the most recent open request.
|
|
26
|
+
* @returns the request, or undefined when nothing was opened since start.
|
|
27
|
+
*/
|
|
28
|
+
export function getLastOpen() {
|
|
29
|
+
return globalThis[SLOT];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 清空 open 记录(客户端摆放完侧栏标签后回执)。
|
|
33
|
+
*
|
|
34
|
+
* 「最后一次 open」如果一直留着,刷新页面或换一个标签页打开 DSH 时就会被重放,把用户已经关掉的
|
|
35
|
+
* 侧栏与网页重新拉起来。拿到回执即清空,这条记录就变成一次性事件。
|
|
36
|
+
* @param at - 只有记录的到达时间与之一致时才清空;省略则无条件清空。
|
|
37
|
+
* @returns 是否真的清掉了。
|
|
38
|
+
*/
|
|
39
|
+
export function clearLastOpen(at) {
|
|
40
|
+
const current = getLastOpen();
|
|
41
|
+
if (current === undefined)
|
|
42
|
+
return false;
|
|
43
|
+
if (at !== undefined && current.at !== at)
|
|
44
|
+
return false;
|
|
45
|
+
delete globalThis[SLOT];
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
@@ -11,7 +11,10 @@ import { homedir } from 'node:os';
|
|
|
11
11
|
import { join } from 'node:path';
|
|
12
12
|
/** Absolute path of the DSH home directory; DSH_HOME overrides the per-user default. */
|
|
13
13
|
export function dshHome() {
|
|
14
|
-
return process.env.DSH_HOME
|
|
14
|
+
return process.env.DSH_HOME || join(homedir(), '.dsh');
|
|
15
|
+
}
|
|
16
|
+
export function browserHostLogPath() {
|
|
17
|
+
return join(dshHome(), 'logs', 'dsh-builtin-browser-host.log');
|
|
15
18
|
}
|
|
16
19
|
/** Absolute path of the endpoint file the running desktop shell publishes. */
|
|
17
20
|
export function bridgeEndpointPath() {
|