dsh-builtin-browser 0.5.6 → 0.5.8
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 +148 -0
- package/README.en.md +75 -81
- package/README.md +75 -82
- package/client.js +831 -384
- package/desktop-bridge/install-and-start.cmd +4 -5
- package/desktop-bridge/install.mjs +322 -141
- package/desktop-bridge/maintenance-progress.ps1 +166 -0
- package/desktop-bridge/plugin-browser-bridge.js +157 -19
- package/desktop-bridge/request-desktop-quit.ps1 +170 -0
- package/docs/tool-reference.md +20 -1
- package/docs/user-guide.md +28 -4
- package/lib/browser/runtime.d.ts +3 -1
- package/lib/browser/runtime.js +9 -0
- package/lib/browser/types.d.ts +42 -0
- package/lib/browser-electron/authenticated-route.d.ts +27 -0
- package/lib/browser-electron/authenticated-route.js +39 -0
- package/lib/browser-electron/automatic-maintenance.d.ts +41 -0
- package/lib/browser-electron/automatic-maintenance.js +426 -0
- package/lib/browser-electron/bridge-auto.d.ts +93 -0
- package/lib/browser-electron/bridge-auto.js +113 -0
- package/lib/browser-electron/bridge-connection.d.ts +0 -2
- package/lib/browser-electron/bridge-connection.js +2 -4
- package/lib/browser-electron/bridge-endpoint.js +8 -19
- package/lib/browser-electron/bridge-install.d.ts +85 -0
- package/lib/browser-electron/bridge-install.js +211 -0
- package/lib/browser-electron/bridge-maintenance.d.ts +24 -0
- package/lib/browser-electron/bridge-maintenance.js +125 -0
- package/lib/browser-electron/bridge-status.d.ts +10 -3
- package/lib/browser-electron/bridge-status.js +74 -24
- package/lib/browser-electron/desktop-bridge-host.d.ts +11 -5
- package/lib/browser-electron/desktop-bridge-host.js +67 -25
- package/lib/browser-electron/desktop-identity.js +21 -9
- package/lib/browser-electron/electron-provision.d.ts +1 -1
- package/lib/browser-electron/electron-provision.js +36 -13
- package/lib/browser-electron/entry.js +173 -67
- package/lib/browser-electron/ephemeral-profile.js +67 -26
- package/lib/browser-electron/history-store.js +2 -2
- package/lib/browser-electron/host-main.js +48 -38
- package/lib/browser-electron/http-body.d.ts +24 -0
- package/lib/browser-electron/http-body.js +33 -0
- package/lib/browser-electron/json-reply.d.ts +13 -1
- package/lib/browser-electron/json-reply.js +16 -2
- package/lib/browser-electron/maintenance-broker.d.ts +35 -0
- package/lib/browser-electron/maintenance-broker.js +114 -0
- package/lib/browser-electron/maintenance-lifecycle.d.ts +32 -0
- package/lib/browser-electron/maintenance-lifecycle.js +67 -0
- package/lib/browser-electron/maintenance-route.d.ts +18 -0
- package/lib/browser-electron/maintenance-route.js +75 -0
- package/lib/browser-electron/paths.d.ts +4 -0
- package/lib/browser-electron/paths.js +19 -0
- package/lib/browser-electron/process.d.ts +14 -0
- package/lib/browser-electron/process.js +24 -0
- package/lib/browser-electron/provider.d.ts +16 -9
- package/lib/browser-electron/provider.js +87 -18
- package/lib/browser-electron/remote-host.js +22 -20
- package/lib/browser-electron/runtime-route.d.ts +3 -5
- package/lib/browser-electron/runtime-status.d.ts +27 -13
- package/lib/browser-electron/runtime-status.js +28 -6
- package/lib/browser-electron/settings-route.d.ts +5 -18
- package/lib/browser-electron/settings-route.js +4 -14
- package/lib/browser-electron/settings-store.d.ts +28 -0
- package/lib/browser-electron/settings-store.js +32 -2
- package/lib/browser-electron/sidebar-only-host.d.ts +36 -0
- package/lib/browser-electron/sidebar-only-host.js +192 -0
- package/lib/browser-electron/system-browser.d.ts +6 -11
- package/lib/browser-electron/system-browser.js +29 -24
- package/lib/browser-electron/timing.d.ts +8 -0
- package/lib/browser-electron/timing.js +13 -0
- package/lib/browser-electron/windows-system.d.ts +3 -0
- package/lib/browser-electron/windows-system.js +19 -0
- package/lib/tool-browser/index.js +1045 -7
- package/lib/tool-browser/page-probe.d.ts +86 -0
- package/lib/tool-browser/page-probe.js +460 -0
- package/package.json +5 -3
- package/scripts/run-tests.mjs +32 -0
- package/scripts/verify-preview-route.mjs +19 -1
- package/scripts/verify-runtime-status.mjs +14 -0
- package/skills/dsh-builtin-browser/SKILL.md +64 -0
- package/skills/dsh-builtin-browser/references/batch.md +23 -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/src/browser/runtime.ts +11 -0
- package/src/browser/types.ts +19 -0
- package/src/browser-electron/authenticated-route.ts +56 -0
- package/src/browser-electron/automatic-maintenance.ts +414 -0
- package/src/browser-electron/bridge-auto.ts +158 -0
- package/src/browser-electron/bridge-connection.ts +2 -4
- package/src/browser-electron/bridge-endpoint.ts +8 -18
- package/src/browser-electron/bridge-install.ts +253 -0
- package/src/browser-electron/bridge-maintenance.ts +161 -0
- package/src/browser-electron/bridge-status.ts +76 -26
- package/src/browser-electron/desktop-bridge-host.ts +60 -26
- package/src/browser-electron/desktop-identity.ts +18 -9
- package/src/browser-electron/electron-provision.ts +35 -14
- package/src/browser-electron/entry.ts +152 -62
- package/src/browser-electron/ephemeral-profile.ts +65 -28
- package/src/browser-electron/history-store.ts +2 -2
- package/src/browser-electron/host-main.ts +40 -34
- package/src/browser-electron/http-body.ts +42 -0
- package/src/browser-electron/json-reply.ts +18 -3
- package/src/browser-electron/maintenance-broker.ts +142 -0
- package/src/browser-electron/maintenance-lifecycle.ts +86 -0
- package/src/browser-electron/maintenance-route.ts +64 -0
- package/src/browser-electron/paths.ts +21 -0
- package/src/browser-electron/process.ts +23 -0
- package/src/browser-electron/provider.ts +106 -22
- package/src/browser-electron/remote-host.ts +23 -23
- package/src/browser-electron/runtime-route.ts +3 -5
- package/src/browser-electron/runtime-status.ts +56 -19
- package/src/browser-electron/settings-route.ts +9 -32
- package/src/browser-electron/settings-store.ts +59 -3
- package/src/browser-electron/sidebar-only-host.ts +199 -0
- package/src/browser-electron/system-browser.ts +26 -23
- package/src/browser-electron/timing.ts +16 -0
- package/src/browser-electron/windows-system.ts +23 -0
- package/src/tool-browser/index.ts +995 -10
- package/src/tool-browser/page-probe.ts +474 -0
|
@@ -8,18 +8,27 @@
|
|
|
8
8
|
*
|
|
9
9
|
* The states are the three that actually occur:
|
|
10
10
|
*
|
|
11
|
-
* - `installed` — the
|
|
11
|
+
* - `installed` — the loaded main.js carries our marker and its bridge matches this plugin.
|
|
12
12
|
* - `missing` — no marker. Either never installed, or the shell was upgraded (which restores
|
|
13
13
|
* `app.asar` and replaces `lib/main.js`) and the bridge went with it.
|
|
14
|
-
* - `stale` — the
|
|
15
|
-
* update that restored the archive without removing our patch: the shell loads the archive, so the
|
|
16
|
-
* patch inside the unpacked tree has no effect. This is the case that looks installed and is not.
|
|
14
|
+
* - `stale` — the archive is back, or the deployed bridge module is missing or outdated.
|
|
17
15
|
* @module dsh-browser/browser-electron/bridge-status
|
|
18
16
|
*/
|
|
19
17
|
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
20
18
|
import { join } from 'node:path';
|
|
21
19
|
import { fileURLToPath } from 'node:url';
|
|
20
|
+
import { createRequire } from 'node:module';
|
|
22
21
|
import { readDesktopIdentity } from './desktop-identity.js';
|
|
22
|
+
// A normal Electron existsSync(app.asar) caches the archive and keeps it locked on Windows.
|
|
23
|
+
// Status inspection must leave maintenance free to rename it after Desktop exits.
|
|
24
|
+
const rawExistsSync = (() => {
|
|
25
|
+
try {
|
|
26
|
+
return createRequire(import.meta.url)('original-fs').existsSync;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return existsSync;
|
|
30
|
+
}
|
|
31
|
+
})();
|
|
23
32
|
/**
|
|
24
33
|
* Find the desktop install to report on.
|
|
25
34
|
*
|
|
@@ -31,27 +40,51 @@ import { readDesktopIdentity } from './desktop-identity.js';
|
|
|
31
40
|
* @param localAppData - the base directory; defaults to the environment's.
|
|
32
41
|
* @returns the install directory, or undefined when nothing matches.
|
|
33
42
|
*/
|
|
34
|
-
export function findDesktopInstall(localAppData
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
export function findDesktopInstall(localAppData) {
|
|
44
|
+
// Not every install lives in %LOCALAPPDATA%\\Programs: people put the app on another drive, under
|
|
45
|
+
// Program Files, or in their own folder. DSH_DESKTOP_PATH names one explicitly, and the usual roots
|
|
46
|
+
// are all probed. A test or a caller that passes a base directory gets exactly that base, so the
|
|
47
|
+
// behaviour stays pinnable.
|
|
38
48
|
const isDesktop = (candidate) => readDesktopIdentity(candidate).ok;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
const explicit = process.env.DSH_DESKTOP_PATH;
|
|
50
|
+
if (explicit !== undefined && explicit !== '') {
|
|
51
|
+
const named = explicit;
|
|
52
|
+
if (isDesktop(named))
|
|
53
|
+
return named;
|
|
54
|
+
// A parent directory is a reasonable thing to point at too: look one level down.
|
|
55
|
+
try {
|
|
56
|
+
for (const entry of readdirSync(named, { withFileTypes: true })) {
|
|
57
|
+
if (entry.isDirectory() && isDesktop(join(named, entry.name)))
|
|
58
|
+
return join(named, entry.name);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// Not a directory: fall through to the usual roots.
|
|
63
|
+
}
|
|
43
64
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
65
|
+
const roots = localAppData === undefined
|
|
66
|
+
? [process.env.LOCALAPPDATA ?? '', process.env['ProgramFiles'] ?? '', process.env['ProgramFiles(x86)'] ?? '', process.env.APPDATA ?? '', process.env.ProgramData ?? '']
|
|
67
|
+
.filter(base => base !== '')
|
|
68
|
+
.map(base => (base === process.env.LOCALAPPDATA ? join(base, 'Programs') : base))
|
|
69
|
+
: [join(localAppData, 'Programs')];
|
|
70
|
+
for (const base of roots) {
|
|
71
|
+
for (const named of ['DSH Desktop', 'DeepSeek Harness']) {
|
|
72
|
+
const candidate = join(base, named);
|
|
49
73
|
if (isDesktop(candidate))
|
|
50
74
|
return candidate;
|
|
51
75
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
76
|
+
try {
|
|
77
|
+
for (const entry of readdirSync(base, { withFileTypes: true })) {
|
|
78
|
+
if (!entry.isDirectory())
|
|
79
|
+
continue;
|
|
80
|
+
const candidate = join(base, entry.name);
|
|
81
|
+
if (isDesktop(candidate))
|
|
82
|
+
return candidate;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// A root that does not exist is a state, not an error.
|
|
87
|
+
}
|
|
55
88
|
}
|
|
56
89
|
return undefined;
|
|
57
90
|
}
|
|
@@ -91,7 +124,7 @@ function repairCommand(installRoot) {
|
|
|
91
124
|
// No absolute path means the package is laid out in a way this module cannot navigate; the bare
|
|
92
125
|
// relative form is still better than nothing, but it is the fallback, not the default.
|
|
93
126
|
const runner = script === undefined ? 'desktop-bridge/install.mjs' : `"${script}"`;
|
|
94
|
-
return `node ${runner} "${installRoot}"
|
|
127
|
+
return `node ${runner} "${installRoot}"`;
|
|
95
128
|
}
|
|
96
129
|
/**
|
|
97
130
|
* Read the bridge's state from an install directory.
|
|
@@ -122,6 +155,7 @@ export function readBridgeStatus(installRoot) {
|
|
|
122
155
|
};
|
|
123
156
|
}
|
|
124
157
|
const archivePresent = safeExists(archivePath);
|
|
158
|
+
const version = identity.version ?? 'unknown';
|
|
125
159
|
const mainPresent = safeExists(mainPath);
|
|
126
160
|
if (!mainPresent && !archivePresent) {
|
|
127
161
|
// Unreachable once identity has passed (identity requires the loaded main entry), kept as the
|
|
@@ -131,6 +165,7 @@ export function readBridgeStatus(installRoot) {
|
|
|
131
165
|
present: false,
|
|
132
166
|
installRoot,
|
|
133
167
|
archivePresent,
|
|
168
|
+
version,
|
|
134
169
|
detail: 'not a DSH Desktop install: no resources/app/lib/main.js and no resources/app.asar',
|
|
135
170
|
};
|
|
136
171
|
}
|
|
@@ -150,6 +185,7 @@ export function readBridgeStatus(installRoot) {
|
|
|
150
185
|
present: true,
|
|
151
186
|
installRoot,
|
|
152
187
|
archivePresent,
|
|
188
|
+
version,
|
|
153
189
|
...backupAt === undefined ? {} : { backupAt },
|
|
154
190
|
command: repairCommand(installRoot),
|
|
155
191
|
detail: 'packed layout with no bridge in the loaded tree: the bridge is not installed',
|
|
@@ -161,6 +197,7 @@ export function readBridgeStatus(installRoot) {
|
|
|
161
197
|
present: true,
|
|
162
198
|
installRoot,
|
|
163
199
|
archivePresent,
|
|
200
|
+
version,
|
|
164
201
|
...backupAt === undefined ? {} : { backupAt },
|
|
165
202
|
command: repairCommand(installRoot),
|
|
166
203
|
detail: 'the archive is back alongside the patched tree, so the shell loads the archive: '
|
|
@@ -173,25 +210,38 @@ export function readBridgeStatus(installRoot) {
|
|
|
173
210
|
present: true,
|
|
174
211
|
installRoot,
|
|
175
212
|
archivePresent,
|
|
213
|
+
version,
|
|
176
214
|
...backupAt === undefined ? {} : { backupAt },
|
|
177
215
|
command: repairCommand(installRoot),
|
|
178
216
|
detail: 'unpacked layout without the bridge patch: the bridge is not installed',
|
|
179
217
|
};
|
|
180
218
|
}
|
|
219
|
+
const bridgePath = join(appDir, 'lib', 'plugin-browser-bridge.js');
|
|
220
|
+
let bridgeDetail;
|
|
221
|
+
try {
|
|
222
|
+
const deployed = readFileSync(bridgePath);
|
|
223
|
+
const shipped = readFileSync(new URL('../../desktop-bridge/plugin-browser-bridge.js', import.meta.url));
|
|
224
|
+
if (!deployed.equals(shipped))
|
|
225
|
+
bridgeDetail = 'the deployed bridge module differs from this plugin version; reinstall the bridge to refresh it';
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
bridgeDetail = 'the bridge module is missing or cannot be verified; reinstall the bridge to restore it';
|
|
229
|
+
}
|
|
181
230
|
return {
|
|
182
|
-
state: 'installed',
|
|
231
|
+
state: bridgeDetail === undefined ? 'installed' : 'stale',
|
|
183
232
|
present: true,
|
|
184
233
|
installRoot,
|
|
185
234
|
archivePresent,
|
|
235
|
+
version,
|
|
186
236
|
...backupAt === undefined ? {} : { backupAt },
|
|
187
237
|
command: repairCommand(installRoot),
|
|
188
|
-
detail: 'the shell loads the patched tree and
|
|
238
|
+
detail: bridgeDetail ?? 'the shell loads the patched tree and its bridge module matches this plugin version',
|
|
189
239
|
};
|
|
190
240
|
}
|
|
191
241
|
/** Whether a path exists, treating any error as absence. */
|
|
192
242
|
function safeExists(path) {
|
|
193
243
|
try {
|
|
194
|
-
return
|
|
244
|
+
return rawExistsSync(path);
|
|
195
245
|
}
|
|
196
246
|
catch {
|
|
197
247
|
return false;
|
|
@@ -22,11 +22,12 @@
|
|
|
22
22
|
* then keeps the self-hosted Electron it has always used.
|
|
23
23
|
* @module dsh-browser/browser-electron/desktop-bridge-host
|
|
24
24
|
*/
|
|
25
|
+
import { bridgeEndpointPath } from './paths.js';
|
|
25
26
|
import type { ElectronBrowserViewHost, ElectronViewHandle } from './provider.js';
|
|
26
27
|
import type { BrowserUserAction } from './provider.js';
|
|
27
28
|
import type { CarrierPage, CarrierLossReason } from '../browser/types.js';
|
|
28
29
|
/** Absolute path of the endpoint file the shell writes. */
|
|
29
|
-
export
|
|
30
|
+
export { bridgeEndpointPath };
|
|
30
31
|
/**
|
|
31
32
|
* A failure worth showing as-is: the carrier is alive and this is a condition the shell can change.
|
|
32
33
|
*
|
|
@@ -36,11 +37,11 @@ export declare function bridgeEndpointPath(): string;
|
|
|
36
37
|
* this host retries while it renders — so reaching here means the shell did not render it at all.
|
|
37
38
|
*/
|
|
38
39
|
export declare class BrowserPanelNotDisplayedError extends Error {
|
|
39
|
-
readonly code
|
|
40
|
+
readonly code: string;
|
|
40
41
|
/**
|
|
41
42
|
* @param detail - the bridge's own explanation, appended so the message says why.
|
|
42
43
|
*/
|
|
43
|
-
constructor(detail: string);
|
|
44
|
+
constructor(detail: string, code?: string);
|
|
44
45
|
}
|
|
45
46
|
/**
|
|
46
47
|
* The desktop sidebar, presented as a browser view host.
|
|
@@ -51,6 +52,8 @@ export declare class BrowserPanelNotDisplayedError extends Error {
|
|
|
51
52
|
* point is a single page both parties can see.
|
|
52
53
|
*/
|
|
53
54
|
export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
55
|
+
private readonly _isQuiet;
|
|
56
|
+
private readonly protocol;
|
|
54
57
|
private readonly connection;
|
|
55
58
|
/**
|
|
56
59
|
* One entry per view this host handed out: the conversation it serves, and the guest backing it.
|
|
@@ -134,7 +137,7 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
134
137
|
* caller falls back to self-hosting, which always works.
|
|
135
138
|
* @returns the host, or undefined when no bridge is available.
|
|
136
139
|
*/
|
|
137
|
-
static discover(sessionId?: string): Promise<DesktopBridgeViewHost | undefined>;
|
|
140
|
+
static discover(sessionId?: string, isQuiet?: () => boolean): Promise<DesktopBridgeViewHost | undefined>;
|
|
138
141
|
/**
|
|
139
142
|
* Whether the last discovery refused a bridge because its sidebar panel is an iframe.
|
|
140
143
|
*
|
|
@@ -217,7 +220,10 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
217
220
|
* it must not fail the navigation that has already happened.
|
|
218
221
|
* @param handle - the view to bring forward.
|
|
219
222
|
*/
|
|
220
|
-
showView(handle: ElectronViewHandle
|
|
223
|
+
showView(handle: ElectronViewHandle, _label?: string, options?: {
|
|
224
|
+
readonly quiet?: boolean;
|
|
225
|
+
readonly select?: boolean;
|
|
226
|
+
}): void;
|
|
221
227
|
onUserAction(handler: (action: BrowserUserAction) => void): void;
|
|
222
228
|
/**
|
|
223
229
|
* Release the sidebar's browser pages (requirements 搂3, `ui.closeWithSession`).
|
|
@@ -24,14 +24,10 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import { BridgeConnection } from './bridge-connection.js';
|
|
26
26
|
import { readFileSync } from 'node:fs';
|
|
27
|
-
import {
|
|
28
|
-
import { join } from 'node:path';
|
|
27
|
+
import { bridgeEndpointPath } from './paths.js';
|
|
29
28
|
import { randomUUID } from 'node:crypto';
|
|
30
29
|
/** Absolute path of the endpoint file the shell writes. */
|
|
31
|
-
export
|
|
32
|
-
const home = process.env.DSH_HOME ?? join(homedir(), '.dsh');
|
|
33
|
-
return join(home, 'dsh-builtin-browser-bridge.json');
|
|
34
|
-
}
|
|
30
|
+
export { bridgeEndpointPath };
|
|
35
31
|
/**
|
|
36
32
|
* The error code the bridge uses when the conversation's panel exists but the shell is not showing
|
|
37
33
|
* that conversation, so no webview has attached yet (issue #37).
|
|
@@ -42,6 +38,7 @@ export function bridgeEndpointPath() {
|
|
|
42
38
|
* blank — losing the page the user had open.
|
|
43
39
|
*/
|
|
44
40
|
const PANEL_NOT_DISPLAYED = 'panel-not-displayed';
|
|
41
|
+
const PANEL_INITIALIZING = 'panel-initializing';
|
|
45
42
|
/**
|
|
46
43
|
* How many times a display-state refusal is retried, and how long each retry waits.
|
|
47
44
|
*
|
|
@@ -62,16 +59,17 @@ const PANEL_DISPLAY_RETRY_MS = 400;
|
|
|
62
59
|
* this host retries while it renders — so reaching here means the shell did not render it at all.
|
|
63
60
|
*/
|
|
64
61
|
export class BrowserPanelNotDisplayedError extends Error {
|
|
65
|
-
code
|
|
62
|
+
code;
|
|
66
63
|
/**
|
|
67
64
|
* @param detail - the bridge's own explanation, appended so the message says why.
|
|
68
65
|
*/
|
|
69
|
-
constructor(detail) {
|
|
66
|
+
constructor(detail, code = PANEL_NOT_DISPLAYED) {
|
|
70
67
|
super('dsh-builtin-browser: this conversation\'s sidebar page did not attach — the shell was asked to '
|
|
71
68
|
+ 'show this conversation and its panel still did not render. Nothing was lost, and the page '
|
|
72
69
|
+ 'appears as soon as the panel mounts. '
|
|
73
70
|
+ `(${detail})`);
|
|
74
71
|
this.name = 'BrowserPanelNotDisplayedError';
|
|
72
|
+
this.code = code;
|
|
75
73
|
}
|
|
76
74
|
}
|
|
77
75
|
/**
|
|
@@ -99,6 +97,8 @@ function isGuestGone(error) {
|
|
|
99
97
|
* point is a single page both parties can see.
|
|
100
98
|
*/
|
|
101
99
|
export class DesktopBridgeViewHost {
|
|
100
|
+
_isQuiet;
|
|
101
|
+
protocol;
|
|
102
102
|
connection;
|
|
103
103
|
/**
|
|
104
104
|
* One entry per view this host handed out: the conversation it serves, and the guest backing it.
|
|
@@ -163,7 +163,9 @@ export class DesktopBridgeViewHost {
|
|
|
163
163
|
/**
|
|
164
164
|
* @param endpoint - the shell's published bridge endpoint.
|
|
165
165
|
*/
|
|
166
|
-
constructor(endpoint, sessionId) {
|
|
166
|
+
constructor(endpoint, sessionId, _isQuiet = () => false, protocol = 2) {
|
|
167
|
+
this._isQuiet = _isQuiet;
|
|
168
|
+
this.protocol = protocol;
|
|
167
169
|
this.owner = sessionId !== undefined && sessionId !== String.fromCharCode(39, 39) ? sessionId : randomUUID();
|
|
168
170
|
// The transport reaches this only by concluding the shell stopped refreshing its endpoint, which
|
|
169
171
|
// is `shell-exited`.
|
|
@@ -196,7 +198,7 @@ export class DesktopBridgeViewHost {
|
|
|
196
198
|
* caller falls back to self-hosting, which always works.
|
|
197
199
|
* @returns the host, or undefined when no bridge is available.
|
|
198
200
|
*/
|
|
199
|
-
static async discover(sessionId) {
|
|
201
|
+
static async discover(sessionId, isQuiet) {
|
|
200
202
|
let endpoint;
|
|
201
203
|
try {
|
|
202
204
|
const raw = JSON.parse(readFileSync(bridgeEndpointPath(), 'utf8'));
|
|
@@ -233,7 +235,7 @@ export class DesktopBridgeViewHost {
|
|
|
233
235
|
DesktopBridgeViewHost.refuseIframe = true;
|
|
234
236
|
return undefined;
|
|
235
237
|
}
|
|
236
|
-
return new DesktopBridgeViewHost(endpoint, sessionId);
|
|
238
|
+
return new DesktopBridgeViewHost(endpoint, sessionId, isQuiet, Number(answer.protocol ?? 2));
|
|
237
239
|
}
|
|
238
240
|
finally {
|
|
239
241
|
probe.close();
|
|
@@ -337,11 +339,22 @@ export class DesktopBridgeViewHost {
|
|
|
337
339
|
*/
|
|
338
340
|
async guestFor(viewId, url, options) {
|
|
339
341
|
const entry = this.views.get(viewId);
|
|
342
|
+
if (entry === undefined)
|
|
343
|
+
throw new Error('dsh-builtin-browser: sidebar view was released');
|
|
344
|
+
const stillOwned = () => {
|
|
345
|
+
if (this.views.get(viewId) !== entry)
|
|
346
|
+
throw new Error('dsh-builtin-browser: sidebar view was released');
|
|
347
|
+
};
|
|
340
348
|
// No liveness check here: verifying the cached guest cost a round-trip on every
|
|
341
349
|
// command. A guest that has gone away is detected by the command itself failing,
|
|
342
350
|
// and `createView`'s sendCommand then discards the cache and calls back in here.
|
|
343
|
-
|
|
351
|
+
// Explicit navigation also reopens a folded panel. Cached guests are sufficient for reads
|
|
352
|
+
// and input, but not for the user's request to open an address in this conversation's sidebar.
|
|
353
|
+
if (entry?.guest !== undefined && url === undefined)
|
|
344
354
|
return entry.guest;
|
|
355
|
+
if (options?.initialize === false) {
|
|
356
|
+
throw new BrowserPanelNotDisplayedError('this view has no attached guest yet', PANEL_INITIALIZING);
|
|
357
|
+
}
|
|
345
358
|
// The conversation THIS VIEW serves — read from the view, never from the process.
|
|
346
359
|
//
|
|
347
360
|
// The difference is the whole bug. This host is one instance shared by every conversation, so
|
|
@@ -354,11 +367,19 @@ export class DesktopBridgeViewHost {
|
|
|
354
367
|
// conversation's own panel by id through the renderer, rather than by pressing the shell's
|
|
355
368
|
// shortcut or clicking its card, both of which the shell delivers to whatever it displays.
|
|
356
369
|
const owner = entry?.owner ?? this.owner;
|
|
370
|
+
if (url !== undefined && this.protocol < 3
|
|
371
|
+
&& [...this.views.entries()].some(([id, view]) => id !== viewId && view.owner === owner && view.guest !== undefined)) {
|
|
372
|
+
throw new Error('dsh-builtin-browser: this desktop bridge needs an update for separate sidebar tabs; use Repair and restart in Browser settings');
|
|
373
|
+
}
|
|
357
374
|
// A command that must not present anything (issue #46: the live preview) takes a read-only path.
|
|
358
375
|
// It asks the bridge what this conversation ALREADY has and never enters the retry loop below — // that loop is what asks the shell to display the conversation, which is right for a tool call
|
|
359
376
|
// and wrong for "let me look at it". A page that is not on screen therefore reports as a display
|
|
360
377
|
// state, and the preview route turns that into the panel's paused state.
|
|
361
378
|
if (options?.present === false) {
|
|
379
|
+
// A logical view without a binding cannot borrow a neighbouring tab for a preview.
|
|
380
|
+
if (this.protocol >= 3) {
|
|
381
|
+
throw new BrowserPanelNotDisplayedError('this view has no attached guest yet', PANEL_INITIALIZING);
|
|
382
|
+
}
|
|
362
383
|
// `list` and NOT `ensureSidebar`. This is deliberate and it is the whole fix: every version of
|
|
363
384
|
// `ensureSidebar` can drive the shell — the current one asks the renderer to display the
|
|
364
385
|
// conversation, and the pre-#37 one literally pressed the sidebar shortcut and typed into the
|
|
@@ -370,20 +391,22 @@ export class DesktopBridgeViewHost {
|
|
|
370
391
|
? listed.sidebar.filter(page => page !== null && typeof page === 'object' && page.type === 'webview')
|
|
371
392
|
: [];
|
|
372
393
|
const wanted = url !== undefined && url !== '' ? url : undefined;
|
|
373
|
-
const
|
|
374
|
-
|
|
375
|
-
: pages.find(page => typeof page.url === 'string' && (page.url === wanted || page.url.startsWith(wanted))) ?? pages[0];
|
|
394
|
+
const samePage = (url, wanted) => url === wanted || url.startsWith(`${wanted}?`) || url.startsWith(`${wanted}#`);
|
|
395
|
+
const match = pages.find(page => wanted !== undefined && typeof page.url === 'string' && samePage(page.url, wanted)) ?? pages[0];
|
|
376
396
|
const id = match !== undefined ? Number(match.id) : Number.NaN;
|
|
377
397
|
if (!Number.isFinite(id) || id <= 0) {
|
|
378
398
|
throw new BrowserPanelNotDisplayedError('the preview asked for this conversation\'s page without presenting it, and no page is attached '
|
|
379
399
|
+ `(the shell holds ${pages.length})`);
|
|
380
400
|
}
|
|
381
|
-
|
|
401
|
+
stillOwned();
|
|
402
|
+
entry.guest = id;
|
|
382
403
|
return id;
|
|
383
404
|
}
|
|
384
405
|
const ask = () => this.connection.call({
|
|
385
406
|
op: 'ensureSidebar',
|
|
386
407
|
owner,
|
|
408
|
+
viewId,
|
|
409
|
+
...entry?.guest === undefined ? {} : { guestId: entry.guest },
|
|
387
410
|
...url !== undefined && url !== '' ? { url } : {},
|
|
388
411
|
}, 30_000);
|
|
389
412
|
let answer = await ask();
|
|
@@ -407,20 +430,25 @@ export class DesktopBridgeViewHost {
|
|
|
407
430
|
|| String(value.error ?? '').includes('can only attach'));
|
|
408
431
|
for (let attempt = 0; attempt < PANEL_DISPLAY_RETRIES && displayRefusal(answer); attempt += 1) {
|
|
409
432
|
await new Promise(resolve => setTimeout(resolve, PANEL_DISPLAY_RETRY_MS));
|
|
433
|
+
stillOwned();
|
|
410
434
|
answer = await ask();
|
|
411
435
|
}
|
|
436
|
+
stillOwned();
|
|
412
437
|
if (answer.ok !== true) {
|
|
413
438
|
// Reachable only after the retries above have run out, and the code still decides — not the
|
|
414
439
|
// wording:
|
|
415
440
|
// panel-not-displayed -> the shell was asked to show the conversation (client half's
|
|
416
441
|
// `openSession`) and did not render it in ~1.6 s: no loss, no swap.
|
|
417
|
-
//
|
|
418
|
-
//
|
|
442
|
+
// A missing guest within a time budget is still initialization, including on old bridges
|
|
443
|
+
// that only returned text. It is not evidence that this shell uses an undrivable iframe.
|
|
419
444
|
const code = String(answer.code ?? '');
|
|
420
|
-
const detail = String(answer.error);
|
|
445
|
+
const detail = String(answer.error ?? answer.code ?? 'unknown sidebar failure');
|
|
421
446
|
if (code === PANEL_NOT_DISPLAYED)
|
|
422
447
|
throw new BrowserPanelNotDisplayedError(detail);
|
|
423
|
-
if (detail.includes('produced no page'))
|
|
448
|
+
if (code === PANEL_INITIALIZING || (code === '' && detail.includes('produced no page'))) {
|
|
449
|
+
throw new BrowserPanelNotDisplayedError(detail, PANEL_INITIALIZING);
|
|
450
|
+
}
|
|
451
|
+
if (code === 'panel-unusable')
|
|
424
452
|
this.reportLost('panel-unusable');
|
|
425
453
|
throw new Error(`dsh-builtin-browser: sidebar unavailable (${detail})`);
|
|
426
454
|
}
|
|
@@ -428,7 +456,7 @@ export class DesktopBridgeViewHost {
|
|
|
428
456
|
if (!Number.isFinite(id) || id <= 0) {
|
|
429
457
|
throw new Error('dsh-builtin-browser: the sidebar reported no browser page for this conversation');
|
|
430
458
|
}
|
|
431
|
-
|
|
459
|
+
entry.guest = id;
|
|
432
460
|
return id;
|
|
433
461
|
}
|
|
434
462
|
/**
|
|
@@ -440,7 +468,8 @@ export class DesktopBridgeViewHost {
|
|
|
440
468
|
this.views.set(viewId, { owner: owner !== undefined && owner !== '' ? owner : this.owner });
|
|
441
469
|
const navigateUrl = (method, params) => method === 'Page.navigate' ? String(params?.url ?? '') : undefined;
|
|
442
470
|
const run = async (guest, method, params) => {
|
|
443
|
-
const
|
|
471
|
+
const owner = this.views.get(viewId)?.owner ?? this.owner;
|
|
472
|
+
const answer = await this.connection.call({ op: 'cdp', id: guest, method, params, owner });
|
|
444
473
|
if (answer.ok !== true)
|
|
445
474
|
throw new Error(`dsh-builtin-browser: sidebar command failed: ${String(answer.error)}`);
|
|
446
475
|
// The bridge forwards whatever CDP answered; the seam expects an object.
|
|
@@ -448,6 +477,15 @@ export class DesktopBridgeViewHost {
|
|
|
448
477
|
};
|
|
449
478
|
return {
|
|
450
479
|
id: viewId,
|
|
480
|
+
download: async (url, savePath) => {
|
|
481
|
+
if (this.protocol < 3)
|
|
482
|
+
throw new Error('dsh-builtin-browser: repair and restart the desktop bridge for sidebar downloads');
|
|
483
|
+
const guest = await this.guestFor(viewId);
|
|
484
|
+
const owner = this.views.get(viewId)?.owner ?? this.owner;
|
|
485
|
+
const answer = await this.connection.call({ op: 'download', id: guest, owner, url, savePath }, 60_000);
|
|
486
|
+
if (answer.ok !== true)
|
|
487
|
+
throw new Error(`dsh-builtin-browser: sidebar download failed: ${String(answer.error)}`);
|
|
488
|
+
},
|
|
451
489
|
sendCommand: async (method, params, options) => {
|
|
452
490
|
// No liveness probe up front. Checking first cost a whole round-trip on
|
|
453
491
|
// every command; instead the command runs and its failure is what triggers
|
|
@@ -499,7 +537,11 @@ export class DesktopBridgeViewHost {
|
|
|
499
537
|
* it must not fail the navigation that has already happened.
|
|
500
538
|
* @param handle - the view to bring forward.
|
|
501
539
|
*/
|
|
502
|
-
showView(handle) {
|
|
540
|
+
showView(handle, _label, options) {
|
|
541
|
+
// Selecting a sidebar tab only changes the task's pane. The bridge never activates the
|
|
542
|
+
// desktop window, so explicit tab selection works in quiet mode as well.
|
|
543
|
+
if (options?.quiet === true && options.select !== true)
|
|
544
|
+
return;
|
|
503
545
|
// `owner` is required: the bridge refuses to bring forward a guest held by another session.
|
|
504
546
|
// It comes from the view, not the process — with several conversations live, a process-wide
|
|
505
547
|
// owner would raise the wrong conversation's tab.
|
|
@@ -509,7 +551,7 @@ export class DesktopBridgeViewHost {
|
|
|
509
551
|
// present it. Once materialized, only the shell's numeric guest id can name its tab.
|
|
510
552
|
if (guest === undefined)
|
|
511
553
|
return;
|
|
512
|
-
void this.connection.call({ op: 'showTab', viewId: guest, owner }, 5_000).catch(() => undefined);
|
|
554
|
+
void this.connection.call({ op: 'showTab', viewId: guest, logicalViewId: handle.id, owner }, 5_000).catch(() => undefined);
|
|
513
555
|
}
|
|
514
556
|
onUserAction(handler) {
|
|
515
557
|
this.userActionHandler = handler;
|
|
@@ -587,7 +629,7 @@ export class DesktopBridgeViewHost {
|
|
|
587
629
|
*/
|
|
588
630
|
async collapse() {
|
|
589
631
|
try {
|
|
590
|
-
await this.connection.call({ op: 'collapseSidebar' }, 10_000);
|
|
632
|
+
await this.connection.call({ op: 'collapseSidebar', owner: this.owner }, 10_000);
|
|
591
633
|
}
|
|
592
634
|
catch {
|
|
593
635
|
// Presentation only; failing to fold is never worth an error.
|
|
@@ -23,7 +23,18 @@
|
|
|
23
23
|
* @module dsh-browser/browser-electron/desktop-identity
|
|
24
24
|
*/
|
|
25
25
|
import { closeSync, existsSync, openSync, readFileSync, readSync } from 'node:fs';
|
|
26
|
+
import { createRequire } from 'node:module';
|
|
26
27
|
import { join } from 'node:path';
|
|
28
|
+
// Electron's patched fs opens an ASAR as a virtual directory. Identity needs the raw archive
|
|
29
|
+
// header and file offsets, including when this reader runs in the Desktop's Node-mode worker.
|
|
30
|
+
const archiveFs = (() => {
|
|
31
|
+
try {
|
|
32
|
+
return createRequire(import.meta.url)('original-fs');
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return { openSync, readSync, closeSync, existsSync };
|
|
36
|
+
}
|
|
37
|
+
})();
|
|
27
38
|
/**
|
|
28
39
|
* The rule shipped in `desktop-bridge/desktop-identity.json`, used when the file cannot be read.
|
|
29
40
|
*
|
|
@@ -76,15 +87,15 @@ export function readIdentityRule() {
|
|
|
76
87
|
function readAsarHeader(archive) {
|
|
77
88
|
let fd;
|
|
78
89
|
try {
|
|
79
|
-
fd = openSync(archive, 'r');
|
|
90
|
+
fd = archiveFs.openSync(archive, 'r');
|
|
80
91
|
const outer = Buffer.alloc(8);
|
|
81
|
-
if (readSync(fd, outer, 0, 8, 0) !== 8)
|
|
92
|
+
if (archiveFs.readSync(fd, outer, 0, 8, 0) !== 8)
|
|
82
93
|
return { error: 'the archive header is truncated' };
|
|
83
94
|
const headerSize = outer.readUInt32LE(4);
|
|
84
95
|
if (headerSize < 8 || headerSize > 64 * 1024 * 1024)
|
|
85
96
|
return { error: `implausible archive header size (${headerSize})` };
|
|
86
97
|
const header = Buffer.alloc(headerSize);
|
|
87
|
-
if (readSync(fd, header, 0, headerSize, 8) !== headerSize)
|
|
98
|
+
if (archiveFs.readSync(fd, header, 0, headerSize, 8) !== headerSize)
|
|
88
99
|
return { error: 'the archive header is truncated' };
|
|
89
100
|
const jsonLength = header.readUInt32LE(4);
|
|
90
101
|
if (jsonLength <= 0 || jsonLength > headerSize - 8)
|
|
@@ -97,7 +108,7 @@ function readAsarHeader(archive) {
|
|
|
97
108
|
finally {
|
|
98
109
|
if (fd !== undefined) {
|
|
99
110
|
try {
|
|
100
|
-
closeSync(fd);
|
|
111
|
+
archiveFs.closeSync(fd);
|
|
101
112
|
}
|
|
102
113
|
catch { /* already closed */ }
|
|
103
114
|
}
|
|
@@ -139,9 +150,9 @@ export function readAsarFile(archive, path) {
|
|
|
139
150
|
return undefined;
|
|
140
151
|
let fd;
|
|
141
152
|
try {
|
|
142
|
-
fd = openSync(archive, 'r');
|
|
153
|
+
fd = archiveFs.openSync(archive, 'r');
|
|
143
154
|
const buffer = Buffer.alloc(entry.size);
|
|
144
|
-
const read = readSync(fd, buffer, 0, entry.size, parsed.contentBase + Number(entry.offset));
|
|
155
|
+
const read = archiveFs.readSync(fd, buffer, 0, entry.size, parsed.contentBase + Number(entry.offset));
|
|
145
156
|
return read === entry.size ? buffer : undefined;
|
|
146
157
|
}
|
|
147
158
|
catch {
|
|
@@ -150,7 +161,7 @@ export function readAsarFile(archive, path) {
|
|
|
150
161
|
finally {
|
|
151
162
|
if (fd !== undefined) {
|
|
152
163
|
try {
|
|
153
|
-
closeSync(fd);
|
|
164
|
+
archiveFs.closeSync(fd);
|
|
154
165
|
}
|
|
155
166
|
catch { /* already closed */ }
|
|
156
167
|
}
|
|
@@ -173,7 +184,7 @@ export function readDesktopIdentity(installRoot) {
|
|
|
173
184
|
const archive = join(resources, 'app.asar');
|
|
174
185
|
let archivePresent;
|
|
175
186
|
try {
|
|
176
|
-
archivePresent = existsSync(archive);
|
|
187
|
+
archivePresent = archiveFs.existsSync(archive);
|
|
177
188
|
}
|
|
178
189
|
catch {
|
|
179
190
|
return { ok: false, reason: `cannot inspect ${archive}` };
|
|
@@ -201,7 +212,8 @@ export function readDesktopIdentity(installRoot) {
|
|
|
201
212
|
try {
|
|
202
213
|
manifestText = readFileSync(manifestPath, 'utf8');
|
|
203
214
|
}
|
|
204
|
-
catch {
|
|
215
|
+
catch (error) {
|
|
216
|
+
console.error(`[dsh-browser] cannot read the package manifest at ${manifestPath}: ${String(error)}`);
|
|
205
217
|
return { ok: false, reason: `${manifestPath} is missing; a directory without a package manifest is not a DSH Desktop install` };
|
|
206
218
|
}
|
|
207
219
|
mainPresent = existsSync(join(appDir, ...rule.mainEntry.split('/')));
|
|
@@ -38,7 +38,7 @@ export interface ProvisionDeps {
|
|
|
38
38
|
/** The installed electron package's own installer script, or undefined when it is not there. */
|
|
39
39
|
readonly installerScript: () => string | undefined;
|
|
40
40
|
/** Runs the installer; resolves to an exit code, or rejects/returns null on failure. */
|
|
41
|
-
readonly run: (script: string) => Promise<{
|
|
41
|
+
readonly run: (script: string, signal?: AbortSignal) => Promise<{
|
|
42
42
|
code: number | null;
|
|
43
43
|
detail?: string;
|
|
44
44
|
}>;
|