dsh-builtin-browser 1.0.0 → 1.0.3
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 +61 -0
- package/README.md +1 -1
- package/assets/browser-panel-locales.mjs +37 -5
- package/assets/browser-policy.d.mts +29 -0
- package/assets/browser-policy.mjs +40 -0
- package/desktop-bridge/desktop-discovery.d.mts +1 -1
- package/desktop-bridge/desktop-discovery.mjs +59 -9
- package/desktop-bridge/desktop-identity.json +12 -0
- package/desktop-bridge/install.mjs +14 -7
- package/desktop-bridge/plugin-browser-bridge.js +19 -7
- package/docs/acceptance-2026-11-27.md +67 -0
- package/docs/architecture.md +1 -1
- package/docs/development.md +33 -4
- package/docs/dsh-0.2.3-host-patch-task.md +34 -0
- package/docs/hardcoding-audit.md +28 -8
- package/docs/known-issues.md +26 -0
- package/docs/limitations.md +6 -2
- package/docs/pr64-maintenance.md +1 -1
- package/docs/tool-reference.md +1 -1
- package/docs/user-guide.md +1 -1
- package/docs/v1.1.0-bu-data-batching-task.md +66 -0
- package/docs/v1.1.0-compat-hardcoding-task.md +85 -0
- package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
- package/dsh-builtin-browser-1.0.3.tgz +0 -0
- package/dsh-host-patch/README.md +4 -0
- package/dsh-host-patch/apply.mjs +61 -13
- package/dsh-host-patch/rc3-revision9.json.gz +0 -0
- package/dsh-host-patch/rc5-revision9.json.gz +0 -0
- package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/manifest.json +218 -0
- package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/series.json +260 -0
- package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
- package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
- package/dsh-host-patch/tauri-revision1.json +39 -0
- package/dsh-host-patch/tauri.json +43 -0
- package/dsh-host-patch/v023-alpha2.json +153 -0
- package/lib/browser/anti-bot.js +215 -0
- package/lib/browser/deep-dom.js +39 -0
- package/lib/browser/runtime.js +15 -0
- package/lib/browser/takeover-target.js +13 -6
- package/lib/browser/types.js +30 -1
- package/lib/browser-electron/authenticated-route.js +16 -2
- package/lib/browser-electron/automatic-maintenance.js +16 -10
- package/lib/browser-electron/bridge-connection.js +3 -8
- package/lib/browser-electron/bridge-install.js +2 -1
- package/lib/browser-electron/bridge-status.js +55 -26
- package/lib/browser-electron/desktop-bridge-host.js +7 -6
- package/lib/browser-electron/desktop-identity.js +28 -5
- package/lib/browser-electron/desktop-shell.js +64 -0
- package/lib/browser-electron/electron-provision.js +105 -18
- package/lib/browser-electron/entry.js +129 -46
- package/lib/browser-electron/extension-browser.js +4 -4
- package/lib/browser-electron/foreground-watch.js +134 -0
- package/lib/browser-electron/guest-cookie-jar.js +13 -13
- package/lib/browser-electron/guest-route.js +181 -32
- package/lib/browser-electron/guest-runtime.js +61 -10
- package/lib/browser-electron/guest-storage.js +2 -2
- package/lib/browser-electron/history-store.js +1 -5
- package/lib/browser-electron/host-main.js +8 -4
- package/lib/browser-electron/host-patch-maintenance.js +14 -8
- package/lib/browser-electron/maintenance-route.js +2 -1
- package/lib/browser-electron/missing-system-browser.js +5 -9
- package/lib/browser-electron/preferred-browser.js +7 -3
- package/lib/browser-electron/preview-route.js +9 -13
- package/lib/browser-electron/process-ownership.js +1 -1
- package/lib/browser-electron/profile-command.js +2 -1
- package/lib/browser-electron/profile-extension.js +5 -0
- package/lib/browser-electron/profile-lease.js +152 -47
- package/lib/browser-electron/provider-core.js +527 -0
- package/lib/browser-electron/provider-interaction.js +963 -0
- package/lib/browser-electron/provider-media.js +518 -0
- package/lib/browser-electron/provider-navigation.js +301 -0
- package/lib/browser-electron/provider-observation.js +623 -0
- package/lib/browser-electron/provider-tabs.js +372 -0
- package/lib/browser-electron/provider.js +150 -3301
- package/lib/browser-electron/reference-route.js +9 -18
- package/lib/browser-electron/remote-host.js +79 -34
- package/lib/browser-electron/runtime-status.js +56 -6
- package/lib/browser-electron/settings-store.js +3 -6
- package/lib/browser-electron/sidebar-only-host.js +1 -1
- package/lib/browser-electron/system-browser.js +539 -172
- package/lib/browser-electron/tauri-host.js +208 -0
- package/lib/browser-electron/virtual-cursor.js +23 -13
- package/lib/browser-reference/service.js +22 -4
- package/lib/browser-reference/web-sources.js +1 -1
- package/lib/client.js +43409 -0
- package/lib/compat/host-features.js +75 -0
- package/lib/reference-source.js +1 -1
- package/lib/reference-text.js +23 -1
- package/lib/takeover-protocol.js +1 -1
- package/lib/tool-browser/block-recovery.js +69 -0
- package/lib/tool-browser/code-tool.js +170 -19
- package/lib/tool-browser/code-worker.js +115 -20
- package/lib/tool-browser/errors.js +34 -0
- package/lib/tool-browser/index.js +66 -3593
- package/lib/tool-browser/page-probe.js +227 -28
- package/lib/tool-browser/panel-page.js +2 -1
- package/lib/tool-browser/probe-client.js +157 -0
- package/lib/tool-browser/screenshot-annotations.js +108 -0
- package/lib/tool-browser/state.js +337 -0
- package/lib/tool-browser/takeover.js +1 -1
- package/lib/tool-browser/tools-debug.js +862 -0
- package/lib/tool-browser/tools-interaction.js +993 -0
- package/lib/tool-browser/tools-navigation.js +807 -0
- package/lib/tool-browser/tools-observation.js +461 -0
- package/lib/tool-browser/tools-reference.js +293 -0
- package/lib/web-guest.js +1 -0
- package/package.json +16 -54
- package/README.en.md +0 -89
- package/browser-extension/constants.mjs +0 -20
- package/browser-extension/controller.mjs +0 -293
- package/browser-extension/locales.mjs +0 -15
- package/browser-extension/manifest.json +0 -12
- package/browser-extension/options.html +0 -14
- package/browser-extension/options.mjs +0 -9
- package/browser-extension/permission-guard.mjs +0 -13
- package/browser-extension/worker.mjs +0 -74
- package/dist/client.cjs +0 -43167
- package/lib/browser-electron/package-removal.js +0 -5
- package/lib/browser-reference/submission-receipts.js +0 -139
- package/scripts/build.mjs +0 -66
- package/scripts/bundle-host.mjs +0 -28
- package/scripts/fix-exports.mjs +0 -50
- package/scripts/install-electron.mjs +0 -51
- package/scripts/verify-exports.mjs +0 -47
- package/scripts/verify-preview-sdk.mjs +0 -93
- package/skills/dsh-builtin-browser/SKILL.md +0 -73
- package/skills/dsh-builtin-browser/references/batch.md +0 -53
- package/skills/dsh-builtin-browser/references/deliver.md +0 -31
- package/skills/dsh-builtin-browser/references/locate.md +0 -11
- package/skills/dsh-builtin-browser/references/recover.md +0 -11
- package/skills/dsh-builtin-browser/references/verify.md +0 -13
- package/skills/dsh-debug-host/SKILL.md +0 -56
- package/skills/dsh-debug-self/SKILL.md +0 -50
- package/src/bridge-compatibility.ts +0 -39
- package/src/browser/handles.ts +0 -89
- package/src/browser/runtime.ts +0 -560
- package/src/browser/takeover-target.ts +0 -36
- package/src/browser/types.ts +0 -817
- package/src/browser-electron/authenticated-route.ts +0 -84
- package/src/browser-electron/automatic-maintenance.ts +0 -726
- package/src/browser-electron/bridge-auto.ts +0 -159
- package/src/browser-electron/bridge-connection.ts +0 -385
- package/src/browser-electron/bridge-endpoint.ts +0 -129
- package/src/browser-electron/bridge-install.ts +0 -289
- package/src/browser-electron/bridge-maintenance.ts +0 -189
- package/src/browser-electron/bridge-status.ts +0 -347
- package/src/browser-electron/desktop-bridge-host.ts +0 -251
- package/src/browser-electron/desktop-identity.ts +0 -320
- package/src/browser-electron/document-readiness.ts +0 -45
- package/src/browser-electron/electron-provision.ts +0 -261
- package/src/browser-electron/entry.ts +0 -1301
- package/src/browser-electron/ephemeral-profile.ts +0 -189
- package/src/browser-electron/extension-browser.ts +0 -223
- package/src/browser-electron/extension-setup.ts +0 -67
- package/src/browser-electron/file-write.ts +0 -31
- package/src/browser-electron/guest-cookie-jar.ts +0 -176
- package/src/browser-electron/guest-cookie-store.ts +0 -59
- package/src/browser-electron/guest-css-runtime.ts +0 -76
- package/src/browser-electron/guest-css.ts +0 -68
- package/src/browser-electron/guest-route.ts +0 -568
- package/src/browser-electron/guest-runtime.ts +0 -357
- package/src/browser-electron/guest-storage-runtime.ts +0 -54
- package/src/browser-electron/guest-storage.ts +0 -117
- package/src/browser-electron/history-store.ts +0 -227
- package/src/browser-electron/host-main.ts +0 -1381
- package/src/browser-electron/host-patch-maintenance.ts +0 -112
- package/src/browser-electron/http-body.ts +0 -65
- package/src/browser-electron/json-reply.ts +0 -47
- package/src/browser-electron/maintenance-broker.ts +0 -166
- package/src/browser-electron/maintenance-lifecycle.ts +0 -91
- package/src/browser-electron/maintenance-route.ts +0 -67
- package/src/browser-electron/missing-system-browser.ts +0 -113
- package/src/browser-electron/open-slot.ts +0 -49
- package/src/browser-electron/package-removal.ts +0 -4
- package/src/browser-electron/paths.ts +0 -25
- package/src/browser-electron/preferred-browser.ts +0 -120
- package/src/browser-electron/preview-route.ts +0 -218
- package/src/browser-electron/process-ownership.ts +0 -168
- package/src/browser-electron/process.ts +0 -23
- package/src/browser-electron/profile-checkpoint.ts +0 -187
- package/src/browser-electron/profile-command.ts +0 -46
- package/src/browser-electron/profile-extension.ts +0 -124
- package/src/browser-electron/profile-lease.ts +0 -115
- package/src/browser-electron/profile-residue.ts +0 -49
- package/src/browser-electron/provider.ts +0 -4571
- package/src/browser-electron/reference-route.ts +0 -608
- package/src/browser-electron/remote-host.ts +0 -1462
- package/src/browser-electron/rpc-input.ts +0 -13
- package/src/browser-electron/rpc-ops.ts +0 -41
- package/src/browser-electron/runtime-diagnostics.ts +0 -38
- package/src/browser-electron/runtime-route.ts +0 -105
- package/src/browser-electron/runtime-status.ts +0 -242
- package/src/browser-electron/settings-route.ts +0 -64
- package/src/browser-electron/settings-store.ts +0 -589
- package/src/browser-electron/shortcuts-route.ts +0 -112
- package/src/browser-electron/sidebar-only-host.ts +0 -298
- package/src/browser-electron/startpage-shortcuts.ts +0 -213
- package/src/browser-electron/system-browser.ts +0 -1497
- package/src/browser-electron/timing.ts +0 -16
- package/src/browser-electron/virtual-cursor.ts +0 -152
- package/src/browser-electron/windows-system.ts +0 -24
- package/src/browser-reference/delivery.ts +0 -384
- package/src/browser-reference/entry.ts +0 -631
- package/src/browser-reference/export.ts +0 -339
- package/src/browser-reference/import.ts +0 -303
- package/src/browser-reference/page-script.ts +0 -1537
- package/src/browser-reference/service.ts +0 -1315
- package/src/browser-reference/store.ts +0 -172
- package/src/browser-reference/submission-receipts.ts +0 -122
- package/src/browser-reference/text-quote.ts +0 -219
- package/src/browser-reference/types.ts +0 -195
- package/src/browser-reference/visible.ts +0 -367
- package/src/browser-reference/web-sources.ts +0 -103
- package/src/client/browser/BrowserController.ts +0 -693
- package/src/client/browser/BrowserFrame.ts +0 -78
- package/src/client/browser/BrowserNavigation.ts +0 -169
- package/src/client/browser/BrowserPage.ts +0 -23
- package/src/client/browser/BrowserPersistence.ts +0 -44
- package/src/client/browser/IframeImpl.ts +0 -176
- package/src/client/browser/child-tabs.ts +0 -14
- package/src/client/browser/iframe-reference.ts +0 -67
- package/src/client/browser/initialization.ts +0 -262
- package/src/client/browser/omnibox.ts +0 -243
- package/src/client/browser/store.ts +0 -38
- package/src/client/browser/takeover-channel.ts +0 -72
- package/src/client/browser/url.ts +0 -46
- package/src/client/browser/web-reference-source.ts +0 -52
- package/src/client/css-modules.d.ts +0 -4
- package/src/client/definition.tsx +0 -30
- package/src/client/electron/ElectronWebViewImpl.ts +0 -364
- package/src/client/electron/ElectronWebviewPresentation.ts +0 -138
- package/src/client/electron/NativeChildPresentation.ts +0 -45
- package/src/client/electron/NativeViewPage.ts +0 -251
- package/src/client/electron/pages.ts +0 -23
- package/src/client/electron/reference-overlay.ts +0 -53
- package/src/client/electron/workspace.ts +0 -33
- package/src/client/index.ts +0 -293
- package/src/client/locales.ts +0 -857
- package/src/client/pages.ts +0 -28
- package/src/client/reference/client/BrowserRefLink.tsx +0 -142
- package/src/client/reference/client/draft-reference.ts +0 -167
- package/src/client/reference/client/index.ts +0 -7
- package/src/client/reference/client/ordered-submission.ts +0 -108
- package/src/client/reference/client/pending-delivery.ts +0 -216
- package/src/client/reference/client/plugin.ts +0 -189
- package/src/client/reference/client/production/ReferenceCapsules.tsx +0 -345
- package/src/client/reference/client/production/ReferenceDock.module.css +0 -193
- package/src/client/reference/client/production/ReferenceDock.tsx +0 -6
- package/src/client/reference/client/production/ReferenceFeedback.tsx +0 -15
- package/src/client/reference/client/production/ReferenceMath.tsx +0 -44
- package/src/client/reference/client/production/ReferenceText.tsx +0 -36
- package/src/client/reference/client/production/assembly.ts +0 -471
- package/src/client/reference/client/production/asset-store.ts +0 -144
- package/src/client/reference/client/production/availability.ts +0 -74
- package/src/client/reference/client/production/bytes.ts +0 -36
- package/src/client/reference/client/production/delivery-client.ts +0 -211
- package/src/client/reference/client/production/draft-adapter.ts +0 -508
- package/src/client/reference/client/production/http-transport.ts +0 -217
- package/src/client/reference/client/production/production-submission.ts +0 -310
- package/src/client/reference/client/production/protocol.ts +0 -231
- package/src/client/reference/client/production/reference-card.ts +0 -240
- package/src/client/reference/client/production/reference-labels.ts +0 -29
- package/src/client/reference/client/production/reply-link-bridge.ts +0 -222
- package/src/client/reference/client/production/reveal.ts +0 -215
- package/src/client/reference/client/production/runtime.ts +0 -1101
- package/src/client/reference/client/production/snapshot-adapter.ts +0 -154
- package/src/client/reference/client/production/source-marker.ts +0 -63
- package/src/client/reference/client/production/source-opener.ts +0 -55
- package/src/client/reference/client/production/styles.ts +0 -104
- package/src/client/reference/client/production/user-text-rule.ts +0 -58
- package/src/client/reference/client/reveal.ts +0 -107
- package/src/client/reference/client/scheme.ts +0 -114
- package/src/client/reference/client/types.ts +0 -168
- package/src/client/reference/css-modules.d.ts +0 -4
- package/src/client/reference/index.ts +0 -11
- package/src/client/reference-capture-owner.ts +0 -162
- package/src/client/reference-intents.ts +0 -36
- package/src/client/settings/index.ts +0 -34
- package/src/client/settings/panel.ts +0 -2657
- package/src/client/shortcut-open.ts +0 -30
- package/src/client/startpage/binding.ts +0 -99
- package/src/client/startpage/controller.ts +0 -303
- package/src/client/startpage/model.ts +0 -279
- package/src/client/view/Browser.module.css +0 -751
- package/src/client/view/BrowserBody.tsx +0 -314
- package/src/client/view/BrowserPresentation.ts +0 -9
- package/src/client/view/BrowserTitle.tsx +0 -17
- package/src/client/view/IframePresentation.ts +0 -344
- package/src/client/view/StartPage.tsx +0 -597
- package/src/client/view/TakeoverBanner.tsx +0 -21
- package/src/index.ts +0 -110
- package/src/reference-owner.ts +0 -5
- package/src/reference-page.ts +0 -9
- package/src/reference-source.ts +0 -3
- package/src/reference-text.ts +0 -197
- package/src/startpage-settings.ts +0 -103
- package/src/startpage.ts +0 -71
- package/src/takeover-protocol.ts +0 -19
- package/src/tool-browser/code-tool.ts +0 -401
- package/src/tool-browser/code-worker.ts +0 -639
- package/src/tool-browser/element-fields.ts +0 -167
- package/src/tool-browser/index.ts +0 -3733
- package/src/tool-browser/page-probe.ts +0 -474
- package/src/tool-browser/panel-page.ts +0 -124
- package/src/tool-browser/screenshot-image.ts +0 -49
- package/src/tool-browser/takeover.ts +0 -198
- package/src/types/electron-shim.d.ts +0 -144
- package/src/types.ts +0 -85
- package/src/web-guest.ts +0 -34
- package/tools/accept-desktop.mjs +0 -148
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { copyFile, lstat, mkdir, readdir, readFile, readlink, rename, rm, rmdir, stat, symlink, writeFile } from 'node:fs/promises'
|
|
2
|
-
import { dirname, join, resolve } from 'node:path'
|
|
3
|
-
import { installedProfileExtension, MAIN_EXTENSION_NAME } from './profile-extension.ts'
|
|
4
|
-
import { MaintenanceRecoveryError } from './maintenance-lifecycle.ts'
|
|
5
|
-
import { runProfileCommand } from './profile-command.ts'
|
|
6
|
-
|
|
7
|
-
type Entry = { path: string } & (
|
|
8
|
-
| { kind: 'missing' | 'directory' | 'file' }
|
|
9
|
-
| { kind: 'link'; target: string; type: 'directory' | 'file' }
|
|
10
|
-
)
|
|
11
|
-
interface CheckpointIO {
|
|
12
|
-
readonly copyFile: typeof copyFile
|
|
13
|
-
readonly symlink: typeof symlink
|
|
14
|
-
readonly readdir: typeof readdir
|
|
15
|
-
readonly reconcile: () => Promise<void>
|
|
16
|
-
}
|
|
17
|
-
const pluginPath = join('node_modules', MAIN_EXTENSION_NAME)
|
|
18
|
-
const manifestPaths = ['package.json', 'pnpm-lock.yaml', join('node_modules', '.modules.yaml')]
|
|
19
|
-
|
|
20
|
-
async function describe(profile: string, path: string, packageEntry = false): Promise<Entry> {
|
|
21
|
-
const source = join(profile, path)
|
|
22
|
-
let info
|
|
23
|
-
try { info = await lstat(source) } catch (error) {
|
|
24
|
-
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return { path, kind: 'missing' }
|
|
25
|
-
throw error
|
|
26
|
-
}
|
|
27
|
-
if (info.isSymbolicLink()) {
|
|
28
|
-
const target = await readlink(source)
|
|
29
|
-
let type: 'directory' | 'file' = 'directory'
|
|
30
|
-
if (!packageEntry) {
|
|
31
|
-
try { type = (await stat(source)).isDirectory() ? 'directory' : 'file' } catch (error) {
|
|
32
|
-
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return { path, kind: 'link', target, type }
|
|
36
|
-
}
|
|
37
|
-
return { path, kind: info.isDirectory() ? 'directory' : 'file' }
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async function inventory(profile: string, io: CheckpointIO): Promise<Entry[]> {
|
|
41
|
-
const entries: Entry[] = []
|
|
42
|
-
for (const name of (await io.readdir(join(profile, 'node_modules'))).sort()) {
|
|
43
|
-
const path = join('node_modules', name), entry = await describe(profile, path, true)
|
|
44
|
-
entries.push(entry)
|
|
45
|
-
if (name.startsWith('@') && entry.kind === 'directory') {
|
|
46
|
-
for (const child of (await io.readdir(join(profile, path))).sort()) entries.push(await describe(profile, join(path, child), true))
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return entries
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async function saveProfile(profile: string, before: string, io: CheckpointIO): Promise<{ entries: Entry[]; modules: Entry[] }> {
|
|
53
|
-
const entries: Entry[] = []
|
|
54
|
-
const visit = async (path: string, packageEntry = false): Promise<void> => {
|
|
55
|
-
const entry = await describe(profile, path, packageEntry)
|
|
56
|
-
entries.push(entry)
|
|
57
|
-
const destination = join(before, 'files', path)
|
|
58
|
-
if (entry.kind === 'directory') {
|
|
59
|
-
await mkdir(destination, { recursive: true })
|
|
60
|
-
for (const name of (await io.readdir(join(profile, path))).sort()) await visit(join(path, name))
|
|
61
|
-
} else if (entry.kind === 'file') {
|
|
62
|
-
await mkdir(dirname(destination), { recursive: true })
|
|
63
|
-
await io.copyFile(join(profile, path), destination)
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if ((await lstat(join(profile, 'node_modules'))).isSymbolicLink()) throw new Error('REINSTALL_CHECKPOINT_LINKED_MODULES: node_modules must be a real directory')
|
|
67
|
-
const modules = await inventory(profile, io)
|
|
68
|
-
for (const path of manifestPaths) await visit(path)
|
|
69
|
-
await visit(pluginPath, true)
|
|
70
|
-
await writeFile(join(before, 'metadata.json'), JSON.stringify({ version: 2, entries, modules }))
|
|
71
|
-
return { entries, modules }
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async function restoreLink(profile: string, entry: Extract<Entry, { kind: 'link' }>, io: CheckpointIO): Promise<void> {
|
|
75
|
-
const destination = join(profile, entry.path)
|
|
76
|
-
await mkdir(dirname(destination), { recursive: true })
|
|
77
|
-
try {
|
|
78
|
-
await io.symlink(entry.type === 'directory' && process.platform === 'win32' ? resolve(dirname(destination), entry.target) : entry.target,
|
|
79
|
-
destination, entry.type === 'directory' ? 'junction' : 'file')
|
|
80
|
-
} catch (error) { throw new Error(`REINSTALL_LINK_RESTORE_FAILED: ${entry.type} link ${entry.path}: ${String(error)}`) }
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async function restoreFiles(profile: string, before: string, entries: readonly Entry[], io: CheckpointIO): Promise<void> {
|
|
84
|
-
const errors: string[] = []
|
|
85
|
-
for (const path of [...manifestPaths, pluginPath]) {
|
|
86
|
-
try { await rm(join(profile, path), { recursive: true, force: true }) } catch (error) { errors.push(`${path}: ${String(error)}`) }
|
|
87
|
-
}
|
|
88
|
-
for (const entry of entries) {
|
|
89
|
-
try {
|
|
90
|
-
const destination = join(profile, entry.path)
|
|
91
|
-
if (entry.kind === 'directory') await mkdir(destination, { recursive: true })
|
|
92
|
-
else if (entry.kind === 'file') {
|
|
93
|
-
await mkdir(dirname(destination), { recursive: true })
|
|
94
|
-
await io.copyFile(join(before, 'files', entry.path), destination)
|
|
95
|
-
} else if (entry.kind === 'link') await restoreLink(profile, entry, io)
|
|
96
|
-
} catch (error) { errors.push(`${entry.path}: ${String(error)}`) }
|
|
97
|
-
}
|
|
98
|
-
if (errors.length > 0) throw new Error(errors.join('; '))
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function unrelated(entries: readonly Entry[]): string {
|
|
102
|
-
return JSON.stringify(entries.filter(entry => entry.path !== pluginPath && !manifestPaths.includes(entry.path) && entry.path !== join('node_modules', '.ignored')))
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async function recoverModules(profile: string, modules: readonly Entry[], io: CheckpointIO): Promise<void> {
|
|
106
|
-
const ignored = join('node_modules', '.ignored')
|
|
107
|
-
const recover = async (entry: Entry): Promise<void> => {
|
|
108
|
-
if (entry.path === pluginPath || manifestPaths.includes(entry.path) || entry.path === ignored) return
|
|
109
|
-
const current = await describe(profile, entry.path, true)
|
|
110
|
-
if (JSON.stringify(current) === JSON.stringify(entry)) return
|
|
111
|
-
if (current.kind !== 'missing') throw new Error(`REINSTALL_UNRELATED_PACKAGE_CHANGED: ${entry.path}`)
|
|
112
|
-
if (entry.kind === 'link') await restoreLink(profile, entry, io)
|
|
113
|
-
else {
|
|
114
|
-
const relative = entry.path.slice('node_modules'.length + 1), parts = relative.split(/[\\/]/)
|
|
115
|
-
for (let i = 0; i < parts.length; i++) {
|
|
116
|
-
const parent = await describe(profile, join(ignored, ...parts.slice(0, i)), true)
|
|
117
|
-
if (parent.kind !== 'directory') throw new Error(`REINSTALL_ORPHAN_RECOVERY_FAILED: unsafe or missing .ignored path for ${entry.path}`)
|
|
118
|
-
}
|
|
119
|
-
await mkdir(dirname(join(profile, entry.path)), { recursive: true })
|
|
120
|
-
await rename(join(profile, ignored, relative), join(profile, entry.path))
|
|
121
|
-
for (let i = parts.length - 1; i >= 0; i--) {
|
|
122
|
-
if (i === 0 && modules.some(entry => entry.path === ignored)) break
|
|
123
|
-
try { await rmdir(join(profile, ignored, ...parts.slice(0, i))) } catch (error) {
|
|
124
|
-
if (!['ENOENT', 'ENOTEMPTY'].includes((error as NodeJS.ErrnoException).code ?? '')) throw error
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
const errors: string[] = []
|
|
130
|
-
for (const entry of modules) {
|
|
131
|
-
try { await recover(entry) } catch (error) { errors.push(String(error)) }
|
|
132
|
-
}
|
|
133
|
-
if (errors.length > 0) throw new Error(errors.join('; '))
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
async function verifyProfile(home: string): Promise<void> {
|
|
137
|
-
await installedProfileExtension(home)
|
|
138
|
-
const script = `const {createRequire} = await import('node:module'); const {readFile} = await import('node:fs/promises'); await readFile(createRequire(process.argv[1]).resolve(${JSON.stringify(MAIN_EXTENSION_NAME)}));`
|
|
139
|
-
const isElectron = process.versions.electron !== undefined
|
|
140
|
-
const argv = [...(isElectron ? ['--expose-internals'] : []), '--input-type=module', '--eval', script, '--', join(home, 'profiles', 'desktop', 'package.json')]
|
|
141
|
-
const env: NodeJS.ProcessEnv = { ...process.env, ...(isElectron ? { ELECTRON_RUN_AS_NODE: '1', ELECTRON_NO_ASAR: '1' } : {}) }
|
|
142
|
-
const result = await runProfileCommand(process.execPath, argv, env, 10_000)
|
|
143
|
-
if (result.code !== 0) throw new Error(`REINSTALL_PROFILE_RESOLUTION_FAILED: ${result.output}`)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/** The checkpoint lives beside the staged worker, never inside the removable profile. */
|
|
147
|
-
export async function withProfileCheckpoint<T>(home: string, directory: string, operation: () => Promise<T>, options: Pick<CheckpointIO, 'reconcile'> & Partial<CheckpointIO>): Promise<T> {
|
|
148
|
-
const profile = join(home, 'profiles', 'desktop'), before = join(directory, 'profile-before')
|
|
149
|
-
const io = { copyFile, symlink, readdir, ...options }
|
|
150
|
-
let saved: { entries: Entry[]; modules: Entry[] }
|
|
151
|
-
let created = false
|
|
152
|
-
try {
|
|
153
|
-
await verifyProfile(home)
|
|
154
|
-
await mkdir(before)
|
|
155
|
-
created = true
|
|
156
|
-
saved = await saveProfile(profile, before, io)
|
|
157
|
-
} catch (error) {
|
|
158
|
-
if (created) await rm(before, { recursive: true, force: true })
|
|
159
|
-
throw new Error(`REINSTALL_CHECKPOINT_FAILED: profile unchanged: ${String(error)}`)
|
|
160
|
-
}
|
|
161
|
-
try {
|
|
162
|
-
const result = await operation()
|
|
163
|
-
if (unrelated(await inventory(profile, io)) !== unrelated(saved.modules)) throw new Error('REINSTALL_UNRELATED_PACKAGES_CHANGED: package manager changed unrelated entries; restoring the profile')
|
|
164
|
-
await verifyProfile(home)
|
|
165
|
-
return result
|
|
166
|
-
} catch (failure) {
|
|
167
|
-
const attempt = async (restore: () => Promise<void>): Promise<string | undefined> => {
|
|
168
|
-
try { await restore(); return undefined } catch (error) { return String(error) }
|
|
169
|
-
}
|
|
170
|
-
let filesError = await attempt(() => restoreFiles(profile, before, saved.entries, io))
|
|
171
|
-
let modulesError = await attempt(() => recoverModules(profile, saved.modules, io))
|
|
172
|
-
let resolutionError = await attempt(() => verifyProfile(home))
|
|
173
|
-
let reconcileError: string | undefined
|
|
174
|
-
if (filesError === undefined && (modulesError !== undefined || resolutionError !== undefined)) {
|
|
175
|
-
reconcileError = await attempt(() => io.reconcile())
|
|
176
|
-
filesError = await attempt(() => restoreFiles(profile, before, saved.entries, io))
|
|
177
|
-
modulesError = await attempt(() => recoverModules(profile, saved.modules, io))
|
|
178
|
-
resolutionError = await attempt(() => verifyProfile(home))
|
|
179
|
-
}
|
|
180
|
-
const restored = filesError === undefined && resolutionError === undefined
|
|
181
|
-
? 'REINSTALL_PROFILE_RESTORED: profile manifests and plugin restored directly and plugin resolution verified'
|
|
182
|
-
: 'Profile restoration could not be fully verified'
|
|
183
|
-
const errors = [filesError, modulesError, resolutionError, reconcileError].filter(error => error !== undefined)
|
|
184
|
-
if (errors.length > 0) throw new MaintenanceRecoveryError(`REINSTALL_ROLLBACK_FAILED: ${errors.join('; ')}; ${restored}; original failure: ${String(failure)}; checkpoint: ${before}`)
|
|
185
|
-
throw new Error(`${String(failure)}; ${restored}`)
|
|
186
|
-
}
|
|
187
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { execFile, spawn } from 'node:child_process'
|
|
2
|
-
import { dirname, join } from 'node:path'
|
|
3
|
-
import { windowsPowerShellPath } from './windows-system.ts'
|
|
4
|
-
import { MaintenanceRecoveryError } from './maintenance-lifecycle.ts'
|
|
5
|
-
|
|
6
|
-
/** Terminate the complete package-manager tree before allowing a profile rollback. */
|
|
7
|
-
export async function runProfileCommand(command: string, args: readonly string[], environment: NodeJS.ProcessEnv, timeoutMs = 60_000): Promise<{ code: number; output: string }> {
|
|
8
|
-
const taskkill = process.platform === 'win32' ? join(dirname(dirname(dirname(windowsPowerShellPath(environment)))), 'taskkill.exe') : undefined
|
|
9
|
-
return await new Promise((resolve, reject) => {
|
|
10
|
-
const child = spawn(command, [...args], { env: environment, windowsHide: true, shell: false, detached: process.platform !== 'win32', stdio: ['ignore', 'pipe', 'pipe'] })
|
|
11
|
-
let output = '', timedOut = false
|
|
12
|
-
let termination: Promise<void> | undefined
|
|
13
|
-
const append = (data: Buffer): void => { output = (output + data.toString()).slice(-1_048_576) }
|
|
14
|
-
child.stdout.on('data', append)
|
|
15
|
-
child.stderr.on('data', append)
|
|
16
|
-
const timer = setTimeout(() => {
|
|
17
|
-
timedOut = true
|
|
18
|
-
if (child.pid === undefined) return
|
|
19
|
-
const pid = child.pid
|
|
20
|
-
termination = new Promise((done, reject) => {
|
|
21
|
-
if (taskkill !== undefined) {
|
|
22
|
-
execFile(taskkill, ['/PID', String(pid), '/T', '/F'], { windowsHide: true, timeout: 10_000 }, error => { if (error) reject(error); else done() })
|
|
23
|
-
} else {
|
|
24
|
-
try { process.kill(-pid, 'SIGKILL'); done() } catch (error) {
|
|
25
|
-
if ((error as NodeJS.ErrnoException).code === 'ESRCH') done()
|
|
26
|
-
else reject(error)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
void termination.catch(error => {
|
|
31
|
-
child.unref()
|
|
32
|
-
child.stdout.destroy()
|
|
33
|
-
child.stderr.destroy()
|
|
34
|
-
reject(new MaintenanceRecoveryError(`${output}\nREINSTALL_ROLLBACK_FAILED: cannot confirm package-manager termination: ${String(error)}`))
|
|
35
|
-
})
|
|
36
|
-
}, timeoutMs)
|
|
37
|
-
child.once('error', error => { clearTimeout(timer); resolve({ code: 1, output: `REINSTALL_COMMAND_START_FAILED: ${error.message}` }) })
|
|
38
|
-
child.once('close', async (code, signal) => {
|
|
39
|
-
clearTimeout(timer)
|
|
40
|
-
try { await termination } catch (error) {
|
|
41
|
-
reject(new MaintenanceRecoveryError(`${output}\nREINSTALL_ROLLBACK_FAILED: cannot confirm package-manager termination: ${String(error)}`)); return
|
|
42
|
-
}
|
|
43
|
-
resolve({ code: timedOut ? 1 : code ?? 1, output: `${output}${timedOut ? `\nREINSTALL_COMMAND_TIMEOUT: exceeded ${timeoutMs}ms; package-manager tree terminated` : signal === null ? '' : `\nREINSTALL_COMMAND_SIGNAL: ${signal}`}`.trim() })
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/** Profile-only extension maintenance through the installation's supported dsh plugin command. */
|
|
2
|
-
import { createHash } from 'node:crypto'
|
|
3
|
-
import { constants } from 'node:fs'
|
|
4
|
-
import { readFile, access, stat } from 'node:fs/promises'
|
|
5
|
-
import { join, resolve, isAbsolute } from 'node:path'
|
|
6
|
-
import type { BridgeAction, BridgeActionResult } from './bridge-install.ts'
|
|
7
|
-
import { BridgeConnection } from './bridge-connection.ts'
|
|
8
|
-
import { desktopPaths, readAsarFile } from './desktop-identity.ts'
|
|
9
|
-
import { runProfileCommand } from './profile-command.ts'
|
|
10
|
-
|
|
11
|
-
export const MAIN_EXTENSION_UNSUPPORTED = 'DESKTOP_MAIN_EXTENSION_UNSUPPORTED'
|
|
12
|
-
export const MAIN_EXTENSION_NAME = 'dsh-builtin-browser'
|
|
13
|
-
export interface MainExtensionStatus {
|
|
14
|
-
readonly state: 'not-installed' | 'pending-restart' | 'loaded' | 'failed'
|
|
15
|
-
readonly version?: string
|
|
16
|
-
readonly loadedAt?: string
|
|
17
|
-
readonly code?: string
|
|
18
|
-
}
|
|
19
|
-
export interface InstalledExtension { readonly version: string; readonly build: string }
|
|
20
|
-
|
|
21
|
-
export async function readHostExtensionStatus(home: string): Promise<MainExtensionStatus | undefined> {
|
|
22
|
-
let connection: BridgeConnection | undefined
|
|
23
|
-
try {
|
|
24
|
-
const endpoint = JSON.parse(await readFile(join(home, 'dsh-builtin-browser-bridge.json'), 'utf8')) as { port: number; token: string; pid: number }
|
|
25
|
-
if (!Number.isSafeInteger(endpoint.pid) || endpoint.pid <= 0 || !Number.isInteger(endpoint.port) || endpoint.port <= 0 || endpoint.port > 65535
|
|
26
|
-
|| typeof endpoint.token !== 'string' || endpoint.token === '') return undefined
|
|
27
|
-
process.kill(endpoint.pid, 0)
|
|
28
|
-
connection = new BridgeConnection(endpoint)
|
|
29
|
-
const answer = await connection.call({ op: 'version' }, 1_000)
|
|
30
|
-
const status = answer.mainExtension as MainExtensionStatus | undefined
|
|
31
|
-
if (answer.ok !== true || answer.homeId !== extensionHomeId(home) || status === null || typeof status !== 'object'
|
|
32
|
-
|| !['not-installed', 'pending-restart', 'loaded', 'failed'].includes(status.state)) return undefined
|
|
33
|
-
return { state: status.state, ...typeof status.version === 'string' ? { version: status.version } : {},
|
|
34
|
-
...typeof status.loadedAt === 'string' ? { loadedAt: status.loadedAt } : {}, ...typeof status.code === 'string' ? { code: status.code } : {} }
|
|
35
|
-
} catch { return undefined } finally { connection?.close() }
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function extensionHomeId(home: string): string {
|
|
39
|
-
const path = resolve(home)
|
|
40
|
-
return createHash('sha256').update(process.platform === 'win32' ? path.toLowerCase() : path).digest('hex')
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export async function installedProfileExtension(home: string): Promise<InstalledExtension> {
|
|
44
|
-
const directory = join(home, 'profiles', 'desktop', 'node_modules', MAIN_EXTENSION_NAME)
|
|
45
|
-
const pkg = JSON.parse(await readFile(join(directory, 'package.json'), 'utf8')) as { name?: unknown; version?: unknown; dsh?: { desktop?: { main?: unknown } } }
|
|
46
|
-
if (pkg.name !== MAIN_EXTENSION_NAME || typeof pkg.version !== 'string' || pkg.dsh?.desktop?.main !== './desktop-bridge/main.mjs') {
|
|
47
|
-
throw new Error('EXTENSION_ENTRY_INVALID')
|
|
48
|
-
}
|
|
49
|
-
const build = createHash('sha256').update(await readFile(join(directory, 'desktop-bridge/plugin-browser-bridge.js'))).digest('hex')
|
|
50
|
-
return { version: pkg.version, build }
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function profileDependencySpec(home: string): Promise<string> {
|
|
54
|
-
const manifest = JSON.parse(await readFile(join(home, 'profiles', 'desktop', 'package.json'), 'utf8')) as { dependencies?: Record<string, unknown> }
|
|
55
|
-
const dependency = manifest.dependencies?.[MAIN_EXTENSION_NAME]
|
|
56
|
-
if (typeof dependency !== 'string' || dependency.trim() === '') throw Object.assign(new Error('The Desktop profile has no dsh-builtin-browser dependency to reinstall.'), { code: 'REINSTALL_DEPENDENCY_MISSING' })
|
|
57
|
-
return dependency
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export async function profileRuntimeDirectory(root: string): Promise<string> {
|
|
61
|
-
const directory = join(desktopPaths(root).resources, 'runtime')
|
|
62
|
-
const pnpm = join(directory, 'primary-runtime', 'dependencies', 'pnpm', 'bin', 'pnpm.mjs')
|
|
63
|
-
try {
|
|
64
|
-
await access(pnpm, constants.R_OK)
|
|
65
|
-
if (!(await stat(pnpm)).isFile()) throw new Error('Not a regular file')
|
|
66
|
-
} catch {
|
|
67
|
-
throw Object.assign(new Error(`The Desktop bundled package manager is missing or unreadable: ${pnpm}`), { code: 'REINSTALL_RUNTIME_MISSING' })
|
|
68
|
-
}
|
|
69
|
-
return directory
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export async function profileExtensionCommand(action: BridgeAction, root: string, home: string, capturedSpec?: string): Promise<readonly string[]> {
|
|
73
|
-
if (!isAbsolute(root) || !isAbsolute(home)) throw new Error('invalid Desktop profile location')
|
|
74
|
-
const profile = join(home, 'profiles', 'desktop')
|
|
75
|
-
const dependency = action === 'install' ? capturedSpec ?? await profileDependencySpec(home) : undefined
|
|
76
|
-
if (action === 'install' && (typeof dependency !== 'string' || dependency.trim() === '')) throw new Error('REINSTALL_DEPENDENCY_MISSING')
|
|
77
|
-
const resources = desktopPaths(root).resources
|
|
78
|
-
const entry = 'dsh/node_modules/@deepseek-ai/dsh-desktop-host/lib/cli.js'
|
|
79
|
-
const archive = join(resources, 'app.asar')
|
|
80
|
-
let cli = join(archive, entry)
|
|
81
|
-
if (readAsarFile(archive, entry) === undefined) {
|
|
82
|
-
try { await access(cli) } catch { cli = join(resources, 'app', entry); await access(cli) }
|
|
83
|
-
}
|
|
84
|
-
const args = [cli, 'plugin', '--profile', 'desktop']
|
|
85
|
-
if (action === 'uninstall') return [...args, 'remove', MAIN_EXTENSION_NAME]
|
|
86
|
-
let spec = String(dependency)
|
|
87
|
-
if (/^(?:file|link):/.test(spec)) {
|
|
88
|
-
const colon = spec.indexOf(':')
|
|
89
|
-
spec = spec.slice(0, colon + 1) + resolve(profile, spec.slice(colon + 1))
|
|
90
|
-
}
|
|
91
|
-
return [...args, 'add', /^(?:file|link):/.test(spec) ? spec : `${MAIN_EXTENSION_NAME}@${spec}`]
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export async function repairProfileExtension(action: BridgeAction, root: string, home: string, run: (
|
|
95
|
-
command: string, argv: readonly string[], environment: NodeJS.ProcessEnv, timeout?: number,
|
|
96
|
-
) => Promise<{ code: number; output: string }>, capturedSpec?: string): Promise<BridgeActionResult> {
|
|
97
|
-
const support = await profileRuntimeDirectory(root)
|
|
98
|
-
const invocation = await profileExtensionCommand(action, root, home, capturedSpec)
|
|
99
|
-
const packedCli = invocation[0].replaceAll('\\', '/').includes('/app.asar/')
|
|
100
|
-
const script = `process.env.ELECTRON_NO_ASAR = '1'; import { dirname, resolve } from 'node:path'; import { pathToFileURL } from 'node:url'; const { runDesktopCli } = await import(pathToFileURL(process.argv[1]).href); const support = ${JSON.stringify(support)}; await (runDesktopCli.length >= 2 ? runDesktopCli(resolve(dirname(process.argv[1]), '../../../..'), support) : runDesktopCli(support));`
|
|
101
|
-
const argv = ['--expose-internals', '--input-type=module', '--eval', script, '--', ...invocation]
|
|
102
|
-
const command = desktopPaths(root).executable
|
|
103
|
-
const environment = profileEnvironment(home, packedCli)
|
|
104
|
-
const result = await run(command, argv, environment, 300_000)
|
|
105
|
-
return { ok: result.code === 0, code: result.code, output: result.output.slice(-20_000), command: [command, ...argv].map(value => JSON.stringify(value)).join(' '), restarted: false }
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function profileEnvironment(home: string, packedCli = false): NodeJS.ProcessEnv {
|
|
109
|
-
const env: NodeJS.ProcessEnv = { ...process.env }
|
|
110
|
-
for (const key of Object.keys(env)) {
|
|
111
|
-
if (key.toUpperCase() === 'ELECTRON_NO_ASAR') delete env[key]
|
|
112
|
-
}
|
|
113
|
-
return { ...env, DSH_HOME: home, ELECTRON_RUN_AS_NODE: '1', ...(packedCli ? {} : { ELECTRON_NO_ASAR: '1' }),
|
|
114
|
-
npm_config_ignore_scripts: 'true', npm_config_auto_install_peers: 'false',
|
|
115
|
-
PNPM_CONFIG_IGNORE_SCRIPTS: 'true', PNPM_CONFIG_AUTO_INSTALL_PEERS: 'false' }
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** Best-effort reconciliation after the checkpoint has restored the profile files and plugin. */
|
|
119
|
-
export async function reconcileProfile(root: string, home: string, run: typeof runProfileCommand = runProfileCommand): Promise<void> {
|
|
120
|
-
const runtime = await profileRuntimeDirectory(root)
|
|
121
|
-
const result = await run(desktopPaths(root).executable, ['--expose-internals', join(runtime, 'primary-runtime', 'dependencies', 'pnpm', 'bin', 'pnpm.mjs'),
|
|
122
|
-
'--dir', join(home, 'profiles', 'desktop'), 'install', '--frozen-lockfile', '--ignore-scripts', '--config.auto-install-peers=false'], profileEnvironment(home), 300_000)
|
|
123
|
-
if (result.code !== 0) throw new Error(`REINSTALL_RECONCILE_FAILED: ${result.output}`)
|
|
124
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { closeSync, mkdirSync, openSync, readFileSync, realpathSync, rmdirSync, statSync, unlinkSync, writeFileSync } from 'node:fs'
|
|
2
|
-
import { randomUUID } from 'node:crypto'
|
|
3
|
-
import { basename, dirname, join } from 'node:path'
|
|
4
|
-
|
|
5
|
-
const STALE_GUARD_MS = 10_000
|
|
6
|
-
|
|
7
|
-
export interface ProfileLease {
|
|
8
|
-
release(cleanup?: () => void): Promise<void>
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function isStaleGuard(guardPath: string, leasePath: string): boolean {
|
|
12
|
-
try {
|
|
13
|
-
const ownerPath = statSync(guardPath).isDirectory() ? leasePath : guardPath
|
|
14
|
-
const raw = JSON.parse(readFileSync(ownerPath, 'utf8')) as { pid?: unknown } | null
|
|
15
|
-
if (raw && Number.isSafeInteger(raw.pid) && Number(raw.pid) > 0) {
|
|
16
|
-
try { process.kill(Number(raw.pid), 0) }
|
|
17
|
-
catch (error) {
|
|
18
|
-
if ((error as NodeJS.ErrnoException).code === 'ESRCH') return true
|
|
19
|
-
}
|
|
20
|
-
return false
|
|
21
|
-
}
|
|
22
|
-
} catch { /* fall through to mtime check */ }
|
|
23
|
-
try {
|
|
24
|
-
return Date.now() - statSync(guardPath).mtimeMs > STALE_GUARD_MS
|
|
25
|
-
} catch (error) {
|
|
26
|
-
return (error as NodeJS.ErrnoException).code === 'ENOENT'
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Exclusive ownership of the plugin profile, including launch and shutdown. */
|
|
31
|
-
export function acquireProfileLease(directory: string): ProfileLease {
|
|
32
|
-
mkdirSync(directory, { recursive: true })
|
|
33
|
-
const root = realpathSync(directory)
|
|
34
|
-
const file = join(root, '.dsh-browser-lease.json')
|
|
35
|
-
const guard = join(dirname(root), `.${basename(root)}.dsh-browser-lease.guard`)
|
|
36
|
-
const token = randomUUID()
|
|
37
|
-
const busy = (): Error => new Error(`dsh-builtin-browser: browser profile is leased or its ownership cannot be verified: ${root}`)
|
|
38
|
-
const guarded = <T>(operation: () => T): T => {
|
|
39
|
-
let acquired = false
|
|
40
|
-
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
41
|
-
let fd: number | undefined
|
|
42
|
-
try {
|
|
43
|
-
fd = openSync(guard, 'wx', 0o600)
|
|
44
|
-
writeFileSync(fd, JSON.stringify({ pid: process.pid, at: Date.now() }))
|
|
45
|
-
acquired = true
|
|
46
|
-
break
|
|
47
|
-
} catch (error) {
|
|
48
|
-
if ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw busy()
|
|
49
|
-
if (attempt === 0 && isStaleGuard(guard, file)) {
|
|
50
|
-
try {
|
|
51
|
-
if (statSync(guard).isDirectory()) rmdirSync(guard)
|
|
52
|
-
else unlinkSync(guard)
|
|
53
|
-
} catch { /* raced with another cleaner */ }
|
|
54
|
-
continue
|
|
55
|
-
}
|
|
56
|
-
throw busy()
|
|
57
|
-
} finally {
|
|
58
|
-
if (fd !== undefined) { try { closeSync(fd) } catch {} }
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (!acquired) throw busy()
|
|
62
|
-
try { return operation() } finally {
|
|
63
|
-
try { unlinkSync(guard) } catch (error) {
|
|
64
|
-
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
guarded(() => {
|
|
69
|
-
let previous: unknown
|
|
70
|
-
try { previous = JSON.parse(readFileSync(file, 'utf8')) }
|
|
71
|
-
catch (error) {
|
|
72
|
-
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw busy()
|
|
73
|
-
previous = undefined
|
|
74
|
-
}
|
|
75
|
-
if (previous !== undefined) {
|
|
76
|
-
const owner = previous as { pid?: unknown; token?: unknown } | null
|
|
77
|
-
if (!owner || !Number.isSafeInteger(owner.pid) || Number(owner.pid) <= 0 || typeof owner.token !== 'string') throw busy()
|
|
78
|
-
try { process.kill(Number(owner.pid), 0); throw busy() }
|
|
79
|
-
catch (error) {
|
|
80
|
-
if ((error as NodeJS.ErrnoException).code !== 'ESRCH') throw busy()
|
|
81
|
-
}
|
|
82
|
-
unlinkSync(file)
|
|
83
|
-
}
|
|
84
|
-
const fd = openSync(file, 'wx', 0o600)
|
|
85
|
-
try { writeFileSync(fd, JSON.stringify({ pid: process.pid, token })) }
|
|
86
|
-
finally { closeSync(fd) }
|
|
87
|
-
})
|
|
88
|
-
let released = false
|
|
89
|
-
return {
|
|
90
|
-
async release(cleanup) {
|
|
91
|
-
if (released) return
|
|
92
|
-
const deadline = Date.now() + 1000
|
|
93
|
-
for (;;) {
|
|
94
|
-
try {
|
|
95
|
-
guarded(() => {
|
|
96
|
-
let owner: { token?: unknown }
|
|
97
|
-
try { owner = JSON.parse(readFileSync(file, 'utf8')) as { token?: unknown } }
|
|
98
|
-
catch (error) { if ((error as NodeJS.ErrnoException).code === 'ENOENT') return; throw error }
|
|
99
|
-
if (owner.token === token) {
|
|
100
|
-
cleanup?.()
|
|
101
|
-
try { unlinkSync(file) } catch (error) {
|
|
102
|
-
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
})
|
|
106
|
-
released = true
|
|
107
|
-
return
|
|
108
|
-
} catch (error) {
|
|
109
|
-
if (Date.now() >= deadline) throw error
|
|
110
|
-
await new Promise(resolve => setTimeout(resolve, 20))
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
}
|
|
115
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { lstat, readdir, readFile, realpath } from 'node:fs/promises'
|
|
2
|
-
import { isAbsolute, join, relative } from 'node:path'
|
|
3
|
-
import { MAIN_EXTENSION_NAME } from './profile-extension.ts'
|
|
4
|
-
import { runProfileCommand } from './profile-command.ts'
|
|
5
|
-
|
|
6
|
-
export async function inspectProfileResidue(home: string): Promise<readonly string[]> {
|
|
7
|
-
const profile = join(home, 'profiles', 'desktop')
|
|
8
|
-
const plugin = join(profile, 'node_modules', MAIN_EXTENSION_NAME)
|
|
9
|
-
let directory: string
|
|
10
|
-
try { directory = await realpath(plugin) } catch (error) {
|
|
11
|
-
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return []
|
|
12
|
-
throw error
|
|
13
|
-
}
|
|
14
|
-
const path = relative(await realpath(profile), directory)
|
|
15
|
-
if (path === '..' || path.startsWith('../') || path.startsWith('..\\') || isAbsolute(path)) return []
|
|
16
|
-
const modules = join(directory, 'node_modules')
|
|
17
|
-
let info
|
|
18
|
-
try { info = await lstat(modules) } catch (error) {
|
|
19
|
-
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return []
|
|
20
|
-
throw error
|
|
21
|
-
}
|
|
22
|
-
if (info.isSymbolicLink()) return ['node_modules (external link)']
|
|
23
|
-
const pkg = JSON.parse(await readFile(join(directory, 'package.json'), 'utf8')) as {
|
|
24
|
-
dependencies?: Record<string, string>; optionalDependencies?: Record<string, string>; peerDependencies?: Record<string, string>
|
|
25
|
-
}
|
|
26
|
-
const declared = new Set(Object.keys({ ...pkg.dependencies, ...pkg.optionalDependencies, ...pkg.peerDependencies }))
|
|
27
|
-
const names: string[] = []
|
|
28
|
-
for (const name of await readdir(modules)) {
|
|
29
|
-
if (name === '.bin' || name === '.modules.yaml') continue
|
|
30
|
-
if (name.startsWith('@') && !(await lstat(join(modules, name))).isSymbolicLink()) {
|
|
31
|
-
for (const child of await readdir(join(modules, name))) names.push(`${name}/${child}`)
|
|
32
|
-
} else names.push(name)
|
|
33
|
-
}
|
|
34
|
-
return names.filter(name => !declared.has(name)).sort()
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Only contaminated, profile-owned nested dependencies are removed; external link checkouts are untouched. */
|
|
38
|
-
export async function cleanProfileResidue(home: string): Promise<string> {
|
|
39
|
-
const residue = await inspectProfileResidue(home)
|
|
40
|
-
if (residue.length === 0) return ''
|
|
41
|
-
const path = join(home, 'profiles', 'desktop', 'node_modules', MAIN_EXTENSION_NAME, 'node_modules')
|
|
42
|
-
const script = `process.noAsar = true; const { rm } = await import('node:fs/promises'); await rm(process.argv[1], {recursive:true, force:true, maxRetries:3, retryDelay:100});`
|
|
43
|
-
const isElectron = process.versions.electron !== undefined
|
|
44
|
-
const argv = [...(isElectron ? ['--expose-internals'] : []), '--input-type=module', '--eval', script, '--', path]
|
|
45
|
-
const env: NodeJS.ProcessEnv = { ...process.env, ...(isElectron ? { ELECTRON_RUN_AS_NODE: '1', ELECTRON_NO_ASAR: '1' } : {}) }
|
|
46
|
-
const result = await runProfileCommand(process.execPath, argv, env)
|
|
47
|
-
if (result.code !== 0) throw new Error(`REINSTALL_RESIDUE_REMOVE_FAILED: ${result.output}`)
|
|
48
|
-
return `Removed pre-existing undeclared nested dependency residue before pnpm: ${residue.join(', ')}`
|
|
49
|
-
}
|