dsh-builtin-browser 1.0.3 → 1.1.0
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 +16 -1
- package/README.en.md +89 -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/desktop-bridge/desktop-identity.json +10 -2
- package/desktop-bridge/install.mjs +28 -2
- package/docs/issue-replies-2026-11-28.md +141 -0
- package/dsh-host-patch/apply.mjs +1 -1
- package/dsh-host-patch/rc3.json +4 -4
- package/dsh-host-patch/rc5.json +4 -4
- package/dsh-host-patch/v023-alpha2.json +2 -2
- package/lib/browser-electron/bridge-status.js +24 -1
- package/lib/browser-electron/desktop-identity.js +47 -8
- package/lib/client.js +2 -1
- package/native-host/install.mjs +5 -0
- package/package.json +20 -2
- package/scripts/build-client.mjs +305 -0
- package/scripts/build.mjs +69 -0
- package/scripts/bundle-host.mjs +28 -0
- package/scripts/fix-exports.mjs +40 -0
- package/scripts/install-electron.mjs +101 -0
- package/scripts/pack.mjs +99 -0
- package/scripts/publish-manifest.mjs +56 -0
- package/scripts/verify-exports.mjs +58 -0
- package/scripts/verify-preview-sdk.mjs +93 -0
- package/skills/dsh-builtin-browser/SKILL.md +98 -0
- package/skills/dsh-builtin-browser/references/batch.md +68 -0
- package/skills/dsh-builtin-browser/references/deliver.md +31 -0
- package/skills/dsh-builtin-browser/references/locate.md +11 -0
- package/skills/dsh-builtin-browser/references/recover.md +11 -0
- package/skills/dsh-builtin-browser/references/verify.md +13 -0
- 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/anti-bot.ts +251 -0
- package/src/browser/deep-dom.ts +40 -0
- package/src/browser/handles.ts +89 -0
- package/src/browser/runtime.ts +578 -0
- package/src/browser/takeover-target.ts +45 -0
- package/src/browser/types.ts +870 -0
- package/src/browser-electron/authenticated-route.ts +109 -0
- package/src/browser-electron/automatic-maintenance.ts +736 -0
- package/src/browser-electron/bridge-auto.ts +159 -0
- package/src/browser-electron/bridge-connection.ts +386 -0
- package/src/browser-electron/bridge-endpoint.ts +129 -0
- package/src/browser-electron/bridge-install.ts +290 -0
- package/src/browser-electron/bridge-maintenance.ts +189 -0
- package/src/browser-electron/bridge-status.ts +412 -0
- package/src/browser-electron/desktop-bridge-host.ts +253 -0
- package/src/browser-electron/desktop-identity.ts +400 -0
- package/src/browser-electron/desktop-shell.ts +100 -0
- package/src/browser-electron/document-readiness.ts +45 -0
- package/src/browser-electron/electron-provision.ts +347 -0
- package/src/browser-electron/entry.ts +1378 -0
- package/src/browser-electron/ephemeral-profile.ts +189 -0
- package/src/browser-electron/extension-browser.ts +230 -0
- package/src/browser-electron/extension-setup.ts +67 -0
- package/src/browser-electron/file-write.ts +31 -0
- package/src/browser-electron/foreground-watch.ts +142 -0
- package/src/browser-electron/guest-cookie-jar.ts +177 -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 +716 -0
- package/src/browser-electron/guest-runtime.ts +408 -0
- package/src/browser-electron/guest-storage-runtime.ts +54 -0
- package/src/browser-electron/guest-storage.ts +120 -0
- package/src/browser-electron/history-store.ts +224 -0
- package/src/browser-electron/host-main.ts +1385 -0
- package/src/browser-electron/host-patch-maintenance.ts +121 -0
- package/src/browser-electron/http-body.ts +65 -0
- package/src/browser-electron/json-reply.ts +47 -0
- package/src/browser-electron/maintenance-broker.ts +166 -0
- package/src/browser-electron/maintenance-lifecycle.ts +91 -0
- package/src/browser-electron/maintenance-route.ts +68 -0
- package/src/browser-electron/missing-system-browser.ts +114 -0
- package/src/browser-electron/open-slot.ts +49 -0
- package/src/browser-electron/paths.ts +25 -0
- package/src/browser-electron/preferred-browser.ts +130 -0
- package/src/browser-electron/preview-route.ts +215 -0
- package/src/browser-electron/process-ownership.ts +174 -0
- package/src/browser-electron/process.ts +23 -0
- package/src/browser-electron/profile-checkpoint.ts +187 -0
- package/src/browser-electron/profile-command.ts +47 -0
- package/src/browser-electron/profile-extension.ts +129 -0
- package/src/browser-electron/profile-lease.ts +211 -0
- package/src/browser-electron/profile-residue.ts +49 -0
- package/src/browser-electron/provider-core.ts +1107 -0
- package/src/browser-electron/provider-interaction.ts +1034 -0
- package/src/browser-electron/provider-media.ts +589 -0
- package/src/browser-electron/provider-navigation.ts +323 -0
- package/src/browser-electron/provider-observation.ts +664 -0
- package/src/browser-electron/provider-tabs.ts +372 -0
- package/src/browser-electron/provider.ts +666 -0
- package/src/browser-electron/reference-route.ts +598 -0
- package/src/browser-electron/remote-host.ts +1538 -0
- package/src/browser-electron/rpc-input.ts +13 -0
- package/src/browser-electron/rpc-ops.ts +41 -0
- package/src/browser-electron/runtime-diagnostics.ts +38 -0
- package/src/browser-electron/runtime-route.ts +105 -0
- package/src/browser-electron/runtime-status.ts +309 -0
- package/src/browser-electron/settings-route.ts +64 -0
- package/src/browser-electron/settings-store.ts +593 -0
- package/src/browser-electron/shortcuts-route.ts +112 -0
- package/src/browser-electron/sidebar-only-host.ts +300 -0
- package/src/browser-electron/startpage-shortcuts.ts +213 -0
- package/src/browser-electron/system-browser.ts +1850 -0
- package/src/browser-electron/tauri-host.ts +194 -0
- package/src/browser-electron/timing.ts +16 -0
- package/src/browser-electron/virtual-cursor.ts +162 -0
- package/src/browser-electron/windows-system.ts +24 -0
- 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 +1346 -0
- package/src/browser-reference/store.ts +172 -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 +106 -0
- package/src/client/apply-guard.ts +22 -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 +182 -0
- package/src/client/browser/child-tabs.ts +14 -0
- package/src/client/browser/frame-history.ts +125 -0
- package/src/client/browser/frame-state.ts +27 -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 +56 -0
- package/src/client/css-modules.d.ts +4 -0
- package/src/client/definition.tsx +36 -0
- package/src/client/electron/ElectronWebViewImpl.ts +371 -0
- package/src/client/electron/ElectronWebviewPresentation.ts +140 -0
- package/src/client/electron/NativeChildPresentation.ts +53 -0
- package/src/client/electron/NativeViewPage.ts +265 -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 +333 -0
- package/src/client/locales.ts +860 -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 +208 -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 +447 -0
- package/src/client/reference/client/production/asset-store.ts +144 -0
- package/src/client/reference/client/production/availability.ts +72 -0
- package/src/client/reference/client/production/bytes.ts +36 -0
- package/src/client/reference/client/production/composer-attachments.ts +44 -0
- package/src/client/reference/client/production/delivery-client.ts +211 -0
- package/src/client/reference/client/production/draft-adapter.ts +512 -0
- package/src/client/reference/client/production/http-transport.ts +212 -0
- package/src/client/reference/client/production/production-submission.ts +70 -0
- package/src/client/reference/client/production/protocol.ts +234 -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 +1056 -0
- package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
- package/src/client/reference/client/production/source-marker.ts +99 -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 +67 -0
- package/src/client/reference/client/reveal.ts +109 -0
- package/src/client/reference/client/scheme.ts +114 -0
- package/src/client/reference/client/session-schedule.ts +36 -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 +42 -0
- package/src/client/settings/mount-guard.ts +31 -0
- package/src/client/settings/panel.ts +2773 -0
- package/src/client/shortcut-open.ts +30 -0
- package/src/client/startpage/binding.ts +99 -0
- package/src/client/startpage/controller.ts +300 -0
- package/src/client/startpage/model.ts +279 -0
- package/src/client/view/Browser.module.css +751 -0
- package/src/client/view/BrowserBody.tsx +315 -0
- package/src/client/view/BrowserPresentation.ts +9 -0
- package/src/client/view/BrowserTitle.tsx +17 -0
- package/src/client/view/IframePresentation.ts +365 -0
- package/src/client/view/StartPage.tsx +598 -0
- package/src/client/view/TakeoverBanner.tsx +21 -0
- package/src/compat/host-features.ts +92 -0
- package/src/index.ts +110 -0
- 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 +219 -0
- package/src/startpage-settings.ts +103 -0
- package/src/startpage.ts +71 -0
- package/src/takeover-protocol.ts +28 -0
- package/src/tool-browser/block-recovery.ts +85 -0
- package/src/tool-browser/code-tool.ts +555 -0
- package/src/tool-browser/code-worker.ts +725 -0
- package/src/tool-browser/element-fields.ts +167 -0
- package/src/tool-browser/errors.ts +40 -0
- package/src/tool-browser/index.ts +265 -0
- package/src/tool-browser/page-probe.ts +675 -0
- package/src/tool-browser/panel-page.ts +126 -0
- package/src/tool-browser/probe-client.ts +183 -0
- package/src/tool-browser/screenshot-annotations.ts +131 -0
- package/src/tool-browser/screenshot-image.ts +49 -0
- package/src/tool-browser/state.ts +375 -0
- package/src/tool-browser/takeover.ts +199 -0
- package/src/tool-browser/tools-debug.ts +806 -0
- package/src/tool-browser/tools-interaction.ts +956 -0
- package/src/tool-browser/tools-navigation.ts +786 -0
- package/src/tool-browser/tools-observation.ts +474 -0
- package/src/tool-browser/tools-reference.ts +294 -0
- package/src/types/electron-shim.d.ts +144 -0
- package/src/types.ts +85 -0
- package/src/web-guest.ts +35 -0
- package/tools/accept-desktop.mjs +148 -0
- package/dist/client.d.cts +0 -516
- package/dist/client.d.mts +0 -516
- package/dist/index.cjs +0 -92
- package/dist/index.d.mts +0 -2960
- package/dist/index.mjs +0 -24
- 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/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 +0 -218
- 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 +0 -260
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSH Tauri (dsh-tauri/deepseek-harness-desktop) as a sidebar host.
|
|
3
|
+
*
|
|
4
|
+
* DSH Tauri does not run DeepSeek Harness Desktop's `lib/main.js`: its Electron main process is
|
|
5
|
+
* electron-rs, staged in `runtime/<platform>-<arch>` beside an `electron-rs.json` whose identifier
|
|
6
|
+
* names the app. Its sidebar guests get an in-memory partition, so the sidebar host patch
|
|
7
|
+
* (`dsh-host-patch/tauri.json`) targets `runtime/browser.cjs` there. The plugin's own Node process
|
|
8
|
+
* is that same Electron binary in Node mode, so a running Tauri is recognised from `process.execPath`.
|
|
9
|
+
* @module dsh-browser/browser-electron/tauri-host
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
|
|
12
|
+
import { basename, dirname, join } from 'node:path'
|
|
13
|
+
import { fileURLToPath } from 'node:url'
|
|
14
|
+
import { dshHome } from './paths.ts'
|
|
15
|
+
import { registeredInstallLocations } from '../../desktop-bridge/desktop-discovery.mjs'
|
|
16
|
+
|
|
17
|
+
const { hostPatchStatus }: { hostPatchStatus: (directory: string) => TauriHostPatch } = await import(new URL('../../dsh-host-patch/apply.mjs', import.meta.url).href)
|
|
18
|
+
|
|
19
|
+
interface TauriRule {
|
|
20
|
+
readonly identifiers: readonly string[]
|
|
21
|
+
readonly metadata: string
|
|
22
|
+
readonly runtimeRoots: readonly string[]
|
|
23
|
+
readonly installNames: readonly string[]
|
|
24
|
+
readonly registryName: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** One DSH Tauri electron-rs runtime directory. */
|
|
28
|
+
export interface TauriRuntime {
|
|
29
|
+
/** The install root, when the runtime sits at one of the rule's runtime roots. */
|
|
30
|
+
readonly root?: string
|
|
31
|
+
/** `runtime/<platform>-<arch>`: the directory the host patch is applied to. */
|
|
32
|
+
readonly runtime: string
|
|
33
|
+
readonly identifier: string
|
|
34
|
+
readonly appName?: string
|
|
35
|
+
readonly running: boolean
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Host patch state of a Tauri runtime, as `dsh-host-patch/apply.mjs` reports it. */
|
|
39
|
+
export interface TauriHostPatch {
|
|
40
|
+
readonly status: string
|
|
41
|
+
readonly reason?: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Read the Tauri part of the shared identity rule.
|
|
46
|
+
* @returns the rule, or undefined when it cannot be read.
|
|
47
|
+
*/
|
|
48
|
+
export function readTauriRule(): TauriRule | undefined {
|
|
49
|
+
try {
|
|
50
|
+
const rule = (JSON.parse(readFileSync(new URL('../../desktop-bridge/desktop-identity.json', import.meta.url), 'utf8')) as { tauri?: TauriRule }).tauri
|
|
51
|
+
const strings = (value: unknown): value is readonly string[] => Array.isArray(value) && value.length > 0 && value.every(item => typeof item === 'string' && item !== '')
|
|
52
|
+
if (rule === undefined || !strings(rule.identifiers) || !strings(rule.runtimeRoots) || !strings(rule.installNames)
|
|
53
|
+
|| typeof rule.metadata !== 'string' || typeof rule.registryName !== 'string') return undefined
|
|
54
|
+
return rule
|
|
55
|
+
} catch {
|
|
56
|
+
return undefined
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function metadataOf(directory: string, rule: TauriRule): { identifier: string; appName?: string; target?: string; arch?: string } | undefined {
|
|
61
|
+
try {
|
|
62
|
+
const value = JSON.parse(readFileSync(join(directory, rule.metadata), 'utf8')) as Record<string, unknown>
|
|
63
|
+
if (typeof value.identifier !== 'string' || !rule.identifiers.includes(value.identifier)) return undefined
|
|
64
|
+
return {
|
|
65
|
+
identifier: value.identifier,
|
|
66
|
+
...typeof value.appName === 'string' ? { appName: value.appName } : {},
|
|
67
|
+
...typeof value.target === 'string' ? { target: value.target } : {},
|
|
68
|
+
...typeof value.arch === 'string' ? { arch: value.arch } : {},
|
|
69
|
+
}
|
|
70
|
+
} catch {
|
|
71
|
+
return undefined
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function rootOf(runtime: string, rule: TauriRule): string | undefined {
|
|
76
|
+
for (const base of [...rule.runtimeRoots].sort((a, b) => b.split('/').length - a.split('/').length)) {
|
|
77
|
+
const parts = base.split('/')
|
|
78
|
+
let directory = dirname(runtime)
|
|
79
|
+
let matches = true
|
|
80
|
+
for (const part of [...parts].reverse()) {
|
|
81
|
+
if (basename(directory) !== part) { matches = false; break }
|
|
82
|
+
directory = dirname(directory)
|
|
83
|
+
}
|
|
84
|
+
if (matches) return directory
|
|
85
|
+
}
|
|
86
|
+
return undefined
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The Tauri runtime this process runs from, when the plugin is hosted by DSH Tauri. On macOS the
|
|
91
|
+
* Electron binary sits in `<runtime>/<name>.app/Contents/MacOS/`, beside which electron-rs keeps
|
|
92
|
+
* `electron-rs.json` and `runtime/`, so the directory holding the `.app` is the runtime.
|
|
93
|
+
* @param execPath - the running executable.
|
|
94
|
+
* @returns the runtime, or undefined outside DSH Tauri.
|
|
95
|
+
*/
|
|
96
|
+
export function runningTauriRuntime(execPath: string = process.execPath): TauriRuntime | undefined {
|
|
97
|
+
const rule = readTauriRule()
|
|
98
|
+
if (rule === undefined) return undefined
|
|
99
|
+
const binary = dirname(execPath)
|
|
100
|
+
const bundle = basename(binary) === 'MacOS' && basename(dirname(binary)) === 'Contents' && dirname(dirname(binary)).endsWith('.app')
|
|
101
|
+
? dirname(dirname(dirname(binary))) : undefined
|
|
102
|
+
const runtime = [binary, bundle].find(directory => directory !== undefined && metadataOf(directory, rule) !== undefined)
|
|
103
|
+
if (runtime === undefined) return undefined
|
|
104
|
+
const metadata = metadataOf(runtime, rule)!
|
|
105
|
+
const root = rootOf(runtime, rule)
|
|
106
|
+
return { ...root === undefined ? {} : { root }, runtime, identifier: metadata.identifier, ...metadata.appName === undefined ? {} : { appName: metadata.appName }, running: true }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The runtime of a DSH Tauri install root that matches this machine.
|
|
111
|
+
* @param root - a candidate install directory.
|
|
112
|
+
* @param platform - the platform the runtime must target.
|
|
113
|
+
* @param arch - the architecture the runtime must target.
|
|
114
|
+
* @returns the runtime, or undefined when the directory is not DSH Tauri.
|
|
115
|
+
*/
|
|
116
|
+
export function tauriRuntimeOf(root: string, platform: string = process.platform, arch: string = process.arch): TauriRuntime | undefined {
|
|
117
|
+
const rule = readTauriRule()
|
|
118
|
+
if (rule === undefined) return undefined
|
|
119
|
+
for (const base of rule.runtimeRoots) {
|
|
120
|
+
const directory = join(root, ...base.split('/'))
|
|
121
|
+
let entries: string[] = []
|
|
122
|
+
try { entries = readdirSync(directory, { withFileTypes: true }).filter(entry => entry.isDirectory()).map(entry => entry.name) } catch { continue }
|
|
123
|
+
for (const name of entries) {
|
|
124
|
+
const runtime = join(directory, name)
|
|
125
|
+
const metadata = metadataOf(runtime, rule)
|
|
126
|
+
if (metadata === undefined) continue
|
|
127
|
+
if ((metadata.target !== undefined && metadata.target !== platform) || (metadata.arch !== undefined && metadata.arch !== arch)) continue
|
|
128
|
+
return { root, runtime, identifier: metadata.identifier, ...metadata.appName === undefined ? {} : { appName: metadata.appName }, running: false }
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return undefined
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Find DSH Tauri: the running host first, then the usual install locations.
|
|
136
|
+
* @param options - discovery overrides for tests.
|
|
137
|
+
* @returns the runtime, or undefined when no DSH Tauri is found.
|
|
138
|
+
*/
|
|
139
|
+
export function findTauriRuntime(options: {
|
|
140
|
+
readonly execPath?: string
|
|
141
|
+
readonly localAppData?: string
|
|
142
|
+
readonly registry?: () => readonly string[]
|
|
143
|
+
} = {}): TauriRuntime | undefined {
|
|
144
|
+
const running = runningTauriRuntime(options.execPath)
|
|
145
|
+
if (running !== undefined) return running
|
|
146
|
+
const rule = readTauriRule()
|
|
147
|
+
if (rule === undefined) return undefined
|
|
148
|
+
const bases = options.localAppData !== undefined ? [options.localAppData]
|
|
149
|
+
: [process.env.LOCALAPPDATA, join(process.env.LOCALAPPDATA ?? '', 'Programs'), process.env.ProgramFiles, process.env['ProgramFiles(x86)']]
|
|
150
|
+
.filter((base): base is string => typeof base === 'string' && base !== '' && base !== 'Programs')
|
|
151
|
+
const candidates = [
|
|
152
|
+
...[process.env.DSH_DESKTOP_PATH, process.env.DSH_DESKTOP_APP].filter((path): path is string => typeof path === 'string' && path !== ''),
|
|
153
|
+
...bases.flatMap(base => rule.installNames.map(name => join(base, name))),
|
|
154
|
+
]
|
|
155
|
+
for (const candidate of candidates) {
|
|
156
|
+
if (!existsSync(candidate)) continue
|
|
157
|
+
const found = tauriRuntimeOf(candidate)
|
|
158
|
+
if (found !== undefined) return found
|
|
159
|
+
}
|
|
160
|
+
let registered: readonly string[] = []
|
|
161
|
+
try { registered = (options.registry ?? (() => registeredInstallLocations(process.platform, undefined, rule.registryName)))() } catch {}
|
|
162
|
+
for (const candidate of registered) {
|
|
163
|
+
const found = tauriRuntimeOf(candidate)
|
|
164
|
+
if (found !== undefined) return found
|
|
165
|
+
}
|
|
166
|
+
return undefined
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Read the sidebar host patch state of a Tauri runtime without writing.
|
|
171
|
+
* @param runtime - the runtime directory.
|
|
172
|
+
* @returns the patch status.
|
|
173
|
+
*/
|
|
174
|
+
export function tauriHostPatchStatus(runtime: string): TauriHostPatch {
|
|
175
|
+
try { return hostPatchStatus(runtime) } catch (error) { return { status: 'anchors mismatch', reason: String(error) } }
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Name this plugin's package to the Tauri host patch, which starts its `dsh.desktop.main` (the sidebar
|
|
180
|
+
* bridge) inside electron-rs: Tauri has no Desktop main-extension loader to find it in the profile.
|
|
181
|
+
* @param home - the DSH home the host patch reads.
|
|
182
|
+
* @param root - this plugin's package directory.
|
|
183
|
+
* @returns the pointer file path.
|
|
184
|
+
*/
|
|
185
|
+
export function publishTauriDesktopMain(home: string = dshHome(), root: string = fileURLToPath(new URL('../../', import.meta.url))): string {
|
|
186
|
+
const file = join(home, 'dsh-builtin-browser-desktop-main.json')
|
|
187
|
+
const text = JSON.stringify({ root }) + '\n'
|
|
188
|
+
try { if (readFileSync(file, 'utf8') === text) return file } catch { /* absent */ }
|
|
189
|
+
const temporary = `${file}.${process.pid}.tmp`
|
|
190
|
+
mkdirSync(home, { recursive: true })
|
|
191
|
+
writeFileSync(temporary, text, { mode: 0o600 })
|
|
192
|
+
renameSync(temporary, file)
|
|
193
|
+
return file
|
|
194
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bound an await with a timeout, without dictating the caller's error wording.
|
|
3
|
+
*
|
|
4
|
+
* The two hosts phrase their timeout errors differently and those strings reach the panel, so
|
|
5
|
+
* the shared primitive takes a factory instead of a message.
|
|
6
|
+
* @module dsh-browser/browser-electron/timing
|
|
7
|
+
*/
|
|
8
|
+
export function withTimeoutShared<T>(promise: Promise<T>, ms: number, timedOut: () => Error): Promise<T> {
|
|
9
|
+
return new Promise<T>((resolve, reject) => {
|
|
10
|
+
const timer = setTimeout(() => { reject(timedOut()) }, ms)
|
|
11
|
+
promise.then(
|
|
12
|
+
(value) => { clearTimeout(timer); resolve(value) },
|
|
13
|
+
(error) => { clearTimeout(timer); reject(error) },
|
|
14
|
+
)
|
|
15
|
+
})
|
|
16
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synthetic pointer feedback for a human watching the tab: an overlay drawn
|
|
3
|
+
* INSIDE the page, never the real system pointer. Its presence is the "the agent
|
|
4
|
+
* has taken over this tab" signal, so it also covers DOM-level operations that
|
|
5
|
+
* move no pointer at all.
|
|
6
|
+
*
|
|
7
|
+
* Implementation notes that matter:
|
|
8
|
+
* - The overlay is `position: fixed` and positioned from viewport coordinates,
|
|
9
|
+
* which is exactly what the element locator already computes and what
|
|
10
|
+
* `Input.dispatchMouseEvent` consumes.
|
|
11
|
+
* - All styling is inline and the ripple uses the Web Animations API: a
|
|
12
|
+
* `<style>` element would be subject to the page's `style-src` CSP, an
|
|
13
|
+
* injected script is not. Injected page feedback must never be silently
|
|
14
|
+
* dropped by a strict CSP.
|
|
15
|
+
* - The overlay mounts inside a closed shadow root (keyed via a Symbol on the
|
|
16
|
+
* host node) and translates an inner stage wrapper so neither `innerText`,
|
|
17
|
+
* deep-DOM shadow-root walkers (`content(markdown)`, `findText`, `anti-bot`),
|
|
18
|
+
* nor top-document attribute `MutationObserver`s (`wait_idle`) observe it.
|
|
19
|
+
* - Every call is best-effort: feedback is never allowed to fail an operation.
|
|
20
|
+
* @module dsh-browser/browser-electron/virtual-cursor
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/** What the pointer is doing at the reported point. */
|
|
24
|
+
export type CursorAction = 'move' | 'click'
|
|
25
|
+
|
|
26
|
+
/** Element id of the overlay root, stable so repeat calls update one node. */
|
|
27
|
+
export const CURSOR_ID = '__dsh_agent_cursor__'
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Where the overlay was last placed, so an unchanged position is not repainted.
|
|
31
|
+
*
|
|
32
|
+
* A single tool call issues several CDP commands (locate, click, cursor), and the
|
|
33
|
+
* cursor is repainted for each one that moves it. Repainting to the same pixel is a
|
|
34
|
+
* wasted round-trip *and* a visible flicker: the transition restarts from the same
|
|
35
|
+
* place, which reads as a stutter rather than as movement.
|
|
36
|
+
*/
|
|
37
|
+
const lastPlaced = new WeakMap<object, { x: number; y: number; action: CursorAction }>()
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Whether a paint at this position would change anything on screen.
|
|
41
|
+
* @param handle - the view the overlay belongs to.
|
|
42
|
+
* @param x - viewport x in CSS pixels.
|
|
43
|
+
* @param y - viewport y in CSS pixels.
|
|
44
|
+
* @param action - the action being reported.
|
|
45
|
+
* @param force - paint even when unchanged (a click ripple must always fire).
|
|
46
|
+
* @returns true when the overlay should be painted.
|
|
47
|
+
*/
|
|
48
|
+
export function cursorNeedsPaint<TView>(handle: TView, x: number, y: number, action: CursorAction, force = false): boolean {
|
|
49
|
+
if (force) return true
|
|
50
|
+
const key = handle as unknown as object
|
|
51
|
+
if (key === null || typeof key !== 'object') return true
|
|
52
|
+
const previous = lastPlaced.get(key)
|
|
53
|
+
return previous === undefined || previous.x !== x || previous.y !== y || previous.action !== action
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The in-page expression that materializes or moves the overlay. Idempotent: the
|
|
58
|
+
* first call creates the nodes, later calls only move them (and pulse).
|
|
59
|
+
* @param x - viewport x in CSS pixels.
|
|
60
|
+
* @param y - viewport y in CSS pixels.
|
|
61
|
+
* @param action - whether to pulse a click ripple at the point.
|
|
62
|
+
* @param label - optional short description of the operation, shown beside the
|
|
63
|
+
* pointer. The overlay is the only "the agent has taken over this tab" signal, so
|
|
64
|
+
* saying *what* it is doing is what turns it from a decoration into an account of
|
|
65
|
+
* the agent's actions that a human can follow without reading the tool log.
|
|
66
|
+
* @returns a self-contained expression that evaluates to `true`.
|
|
67
|
+
*/
|
|
68
|
+
export function cursorScript(x: number, y: number, action: CursorAction, label?: string): string {
|
|
69
|
+
return `(() => {
|
|
70
|
+
const id = ${JSON.stringify(CURSOR_ID)}
|
|
71
|
+
const key = Symbol.for('__dsh_agent_cursor_shadow__')
|
|
72
|
+
let root = document.getElementById(id)
|
|
73
|
+
if (!root) {
|
|
74
|
+
root = document.createElement('div')
|
|
75
|
+
root.id = id
|
|
76
|
+
root.setAttribute('aria-hidden', 'true')
|
|
77
|
+
root.style.cssText = 'position:fixed;left:0;top:0;width:0;height:0;z-index:2147483647;pointer-events:none'
|
|
78
|
+
const svg = '<svg width="22" height="22" viewBox="0 0 22 22" style="position:absolute;left:-2px;top:-2px;filter:drop-shadow(0 1px 2px rgba(0,0,0,.45))">'
|
|
79
|
+
+ '<path d="M4 2 L4 18 L8.4 13.8 L11.2 19.6 L13.8 18.4 L11 12.8 L17 12.6 Z" fill="#ffffff" stroke="#111111" stroke-width="1.4" stroke-linejoin="round"/></svg>'
|
|
80
|
+
const ripple = '<span data-dsh-role="ripple" style="position:absolute;left:0;top:0;width:34px;height:34px;margin:-17px 0 0 -17px;border-radius:50%;border:2px solid rgba(64,160,255,.9);opacity:0"></span>'
|
|
81
|
+
// The bubble sits below-right of the pointer tip and is capped in width so a long
|
|
82
|
+
// label cannot cover the page it is describing.
|
|
83
|
+
const bubble = '<span data-dsh-role="bubble" style="position:absolute;left:18px;top:16px;max-width:280px;padding:3px 8px;border-radius:5px;background:rgba(17,17,17,.92);color:#fff;font:12px/1.45 -apple-system,Segoe UI,Roboto,sans-serif;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;opacity:0;box-shadow:0 1px 3px rgba(0,0,0,.4)"></span>'
|
|
84
|
+
const stage = '<div data-dsh-role="stage" style="position:fixed;left:0;top:0;width:0;height:0;pointer-events:none;transition:transform 190ms cubic-bezier(.22,.85,.24,1);will-change:transform">' + svg + ripple + bubble + '</div>'
|
|
85
|
+
const parts = typeof root.attachShadow === 'function' ? root.attachShadow({ mode: 'closed' }) : root
|
|
86
|
+
parts.innerHTML = stage
|
|
87
|
+
root[key] = parts
|
|
88
|
+
;(document.body || document.documentElement).appendChild(root)
|
|
89
|
+
}
|
|
90
|
+
const parts = root[key] || root
|
|
91
|
+
const stage = parts.querySelector('[data-dsh-role="stage"]') || root
|
|
92
|
+
stage.style.transform = 'translate(${x}px, ${y}px)'
|
|
93
|
+
${action === 'click' ? `const ripple = parts.querySelector('[data-dsh-role="ripple"]')
|
|
94
|
+
if (ripple && typeof ripple.animate === 'function') {
|
|
95
|
+
ripple.animate(
|
|
96
|
+
[{ transform: 'scale(.25)', opacity: 0.95 }, { transform: 'scale(1.6)', opacity: 0 }],
|
|
97
|
+
{ duration: 550, easing: 'ease-out' },
|
|
98
|
+
)
|
|
99
|
+
}` : ''}
|
|
100
|
+
${label !== undefined && label !== '' ? `const bubble = parts.querySelector('[data-dsh-role="bubble"]')
|
|
101
|
+
if (bubble) {
|
|
102
|
+
bubble.textContent = ${JSON.stringify(label)}
|
|
103
|
+
if (typeof bubble.animate === 'function') {
|
|
104
|
+
// Fade in, hold, fade out: the label is a narration of the action, not a
|
|
105
|
+
// permanent caption, so a stale one never lingers over later work.
|
|
106
|
+
bubble.animate(
|
|
107
|
+
[{ opacity: 0, transform: 'translateY(-3px)' }, { opacity: 1, transform: 'translateY(0)' }, { opacity: 1, offset: 0.6 }, { opacity: 0 }],
|
|
108
|
+
{ duration: 2200, easing: 'ease-out', fill: 'forwards' },
|
|
109
|
+
)
|
|
110
|
+
} else {
|
|
111
|
+
bubble.style.opacity = '1'
|
|
112
|
+
}
|
|
113
|
+
}` : ''}
|
|
114
|
+
return true
|
|
115
|
+
})()`
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Forget the remembered position for a view.
|
|
120
|
+
*
|
|
121
|
+
* Called when the document is replaced: the overlay lived in the old document and
|
|
122
|
+
* went with it, so the cache would otherwise claim the pointer is already where it
|
|
123
|
+
* needs to be and skip every later paint — the pointer would simply never return
|
|
124
|
+
* after a navigation.
|
|
125
|
+
* @param handle - the view whose cache should be dropped.
|
|
126
|
+
*/
|
|
127
|
+
export function forgetCursor<TView>(handle: TView): void {
|
|
128
|
+
const key = handle as unknown as object
|
|
129
|
+
if (key !== null && typeof key === 'object') lastPlaced.delete(key)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Draw (or move) the pointer overlay on one view's page.
|
|
134
|
+
*
|
|
135
|
+
* Best-effort: a page that is mid-navigation, cross-origin-blocked, or otherwise
|
|
136
|
+
* unable to answer must not turn a successful operation into a failure. Returns
|
|
137
|
+
* a settled promise so callers like click() can optionally wait briefly for the
|
|
138
|
+
* paint before dispatching mouse events without racing the press/release pair.
|
|
139
|
+
* @param handle - the view to paint into.
|
|
140
|
+
* @param x - viewport x in CSS pixels.
|
|
141
|
+
* @param y - viewport y in CSS pixels.
|
|
142
|
+
* @param action - whether to pulse a click ripple.
|
|
143
|
+
* @param evaluate - the provider's evaluate bridge (keeps the CDP coupling in one place).
|
|
144
|
+
* @param label - optional short description of the operation, shown beside the pointer.
|
|
145
|
+
*/
|
|
146
|
+
export function paintCursor<TView>(
|
|
147
|
+
handle: TView,
|
|
148
|
+
x: number,
|
|
149
|
+
y: number,
|
|
150
|
+
action: CursorAction,
|
|
151
|
+
evaluate: (handle: TView, expression: string) => Promise<unknown>,
|
|
152
|
+
label?: string,
|
|
153
|
+
force = false,
|
|
154
|
+
): Promise<void> {
|
|
155
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) return Promise.resolve()
|
|
156
|
+
const roundedX = Math.round(x)
|
|
157
|
+
const roundedY = Math.round(y)
|
|
158
|
+
if (!cursorNeedsPaint(handle, roundedX, roundedY, action, force)) return Promise.resolve()
|
|
159
|
+
const key = handle as unknown as object
|
|
160
|
+
if (key !== null && typeof key === 'object') lastPlaced.set(key, { x: roundedX, y: roundedY, action })
|
|
161
|
+
return Promise.resolve(evaluate(handle, cursorScript(roundedX, roundedY, action, label))).then(() => undefined, () => undefined)
|
|
162
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { WINDOWS_TOOLS } from '../../assets/browser-products.mjs'
|
|
2
|
+
/** Locate Windows system tools from the running system rather than an assumed system drive. */
|
|
3
|
+
import { existsSync } from 'node:fs'
|
|
4
|
+
import { win32 } from 'node:path'
|
|
5
|
+
|
|
6
|
+
/** PowerShell's `-EncodedCommand` expects a UTF-16LE script encoded as base64. */
|
|
7
|
+
export function encodePowerShellScript(script: string): string {
|
|
8
|
+
return Buffer.from(script, 'utf16le').toString('base64')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function windowsPowerShellPath(
|
|
12
|
+
environment: NodeJS.ProcessEnv = process.env,
|
|
13
|
+
exists: (path: string) => boolean = existsSync,
|
|
14
|
+
): string {
|
|
15
|
+
const read = (name: string): string | undefined => Object.entries(environment)
|
|
16
|
+
.find(([key]) => key.toUpperCase() === name)?.[1]
|
|
17
|
+
const root = read('SYSTEMROOT') || read('WINDIR')
|
|
18
|
+
if (root === undefined || !/^(?:[A-Za-z]:[\\/]|\\\\[^\\/]+[\\/][^\\/]+)/.test(root)) {
|
|
19
|
+
throw new Error('Windows system directory is unavailable; SystemRoot or WINDIR must identify the current system')
|
|
20
|
+
}
|
|
21
|
+
const path = win32.join(root, 'System32', 'WindowsPowerShell', 'v1.0', WINDOWS_TOOLS.powershell)
|
|
22
|
+
if (!exists(path)) throw new Error('Windows PowerShell is unavailable in the detected system directory')
|
|
23
|
+
return path
|
|
24
|
+
}
|