dsh-builtin-browser 0.5.5 → 0.5.7
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 +143 -1
- package/README.en.md +67 -97
- package/README.md +67 -98
- package/client.js +618 -263
- package/desktop-bridge/install.mjs +122 -33
- package/desktop-bridge/plugin-browser-bridge.js +9 -4
- package/docs/development.md +10 -0
- package/docs/tool-reference.md +20 -1
- package/docs/user-guide.md +16 -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/bridge-connection.d.ts +8 -0
- package/lib/browser-electron/bridge-connection.js +8 -0
- package/lib/browser-electron/bridge-endpoint.d.ts +30 -0
- package/lib/browser-electron/bridge-endpoint.js +130 -0
- package/lib/browser-electron/bridge-install.d.ts +48 -0
- package/lib/browser-electron/bridge-install.js +98 -0
- package/lib/browser-electron/bridge-status.js +21 -2
- package/lib/browser-electron/desktop-bridge-host.d.ts +30 -27
- package/lib/browser-electron/desktop-bridge-host.js +71 -50
- package/lib/browser-electron/electron-provision.d.ts +35 -2
- package/lib/browser-electron/electron-provision.js +83 -20
- package/lib/browser-electron/entry.js +144 -7
- package/lib/browser-electron/host-main.js +48 -27
- package/lib/browser-electron/json-reply.d.ts +21 -0
- package/lib/browser-electron/json-reply.js +17 -0
- package/lib/browser-electron/preview-route.js +1 -12
- package/lib/browser-electron/provider.d.ts +9 -2
- package/lib/browser-electron/provider.js +76 -6
- package/lib/browser-electron/remote-host.js +10 -9
- package/lib/browser-electron/runtime-route.d.ts +55 -0
- package/lib/browser-electron/runtime-route.js +66 -0
- package/lib/browser-electron/runtime-status.d.ts +102 -0
- package/lib/browser-electron/runtime-status.js +88 -0
- 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 +17 -0
- package/lib/browser-electron/settings-store.js +24 -0
- package/lib/browser-electron/system-browser.d.ts +5 -2
- package/lib/browser-electron/system-browser.js +12 -4
- package/lib/tool-browser/index.js +1041 -4
- 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/consumer-install-check.mjs +72 -0
- package/scripts/verify-runtime-status.mjs +179 -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/bridge-connection.ts +9 -0
- package/src/browser-electron/bridge-endpoint.ts +146 -0
- package/src/browser-electron/bridge-install.ts +122 -0
- package/src/browser-electron/bridge-status.ts +22 -2
- package/src/browser-electron/desktop-bridge-host.ts +68 -50
- package/src/browser-electron/electron-provision.ts +103 -20
- package/src/browser-electron/entry.ts +141 -7
- package/src/browser-electron/host-main.ts +41 -22
- package/src/browser-electron/json-reply.ts +32 -0
- package/src/browser-electron/preview-route.ts +1 -12
- package/src/browser-electron/provider.ts +90 -6
- package/src/browser-electron/remote-host.ts +10 -9
- package/src/browser-electron/runtime-route.ts +104 -0
- package/src/browser-electron/runtime-status.ts +188 -0
- package/src/browser-electron/settings-route.ts +9 -32
- package/src/browser-electron/settings-store.ts +39 -0
- package/src/browser-electron/system-browser.ts +9 -3
- package/src/tool-browser/index.ts +991 -7
- package/src/tool-browser/page-probe.ts +474 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the desktop shell is RUNNING, as opposed to whether its bridge is installed.
|
|
3
|
+
*
|
|
4
|
+
* The two questions are constantly confused, and the confusion is the reason a user on
|
|
5
|
+
* `channel: sidebar` sees "another window opened instead" and cannot tell why:
|
|
6
|
+
*
|
|
7
|
+
* - `bridge-status.ts` reads the INSTALL TREE: does the shell's main entry carry our patch, and is
|
|
8
|
+
* the archive out of the way. It survives a reboot; it says nothing about a process.
|
|
9
|
+
* - This module reads the ENDPOINT the shell publishes while it runs: a port, a token, a pid and a
|
|
10
|
+
* refresh stamp. It says nothing about the install tree.
|
|
11
|
+
*
|
|
12
|
+
* "Installed" plus "not running" is the single most common broken state (the desktop app is simply
|
|
13
|
+
* closed), and a readiness report that stops at the install tree calls it ready — then every call
|
|
14
|
+
* dials a port nobody owns. So both readings are taken, and the sidebar carrier is only ready when
|
|
15
|
+
* BOTH are true.
|
|
16
|
+
*
|
|
17
|
+
* Two independent signals, because each alone has a false-positive:
|
|
18
|
+
* - the refresh stamp (the shell rewrites the file every ~15 s, so a stale stamp means a shell that
|
|
19
|
+
* exited and left its last write behind — a tombstone naming a dead port);
|
|
20
|
+
* - the pid, checked with signal 0 (kills nothing, and works across platforms).
|
|
21
|
+
* @module dsh-browser/browser-electron/bridge-endpoint
|
|
22
|
+
*/
|
|
23
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
24
|
+
import { ENDPOINT_STALE_AFTER_MS } from './bridge-connection.js';
|
|
25
|
+
import { bridgeEndpointPath } from './desktop-bridge-host.js';
|
|
26
|
+
/**
|
|
27
|
+
* Whether a pid is alive, without signalling it.
|
|
28
|
+
*
|
|
29
|
+
* Signal 0 performs the permission and existence checks and delivers nothing. `EPERM` means the
|
|
30
|
+
* process exists and belongs to someone else, which is still "alive" for this purpose.
|
|
31
|
+
* @param pid - the process id from the endpoint file.
|
|
32
|
+
* @returns whether that process exists.
|
|
33
|
+
*/
|
|
34
|
+
function pidAlive(pid) {
|
|
35
|
+
if (!Number.isSafeInteger(pid) || pid <= 0)
|
|
36
|
+
return false;
|
|
37
|
+
try {
|
|
38
|
+
process.kill(pid, 0);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
return error?.code === 'EPERM';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Read the endpoint the shell publishes.
|
|
47
|
+
*
|
|
48
|
+
* Never throws: a settings panel must get an answer even when the file is mid-write, unreadable, or
|
|
49
|
+
* belongs to a shell that exited an hour ago.
|
|
50
|
+
* @param path - the endpoint file; defaults to the one location the shell writes.
|
|
51
|
+
* @param now - the clock, injected so a test can age a stamp without sleeping.
|
|
52
|
+
* @returns what the panel shows.
|
|
53
|
+
*/
|
|
54
|
+
export function readBridgeEndpoint(path = bridgeEndpointPath(), now = Date.now()) {
|
|
55
|
+
if (!existsSync(path)) {
|
|
56
|
+
return {
|
|
57
|
+
present: false,
|
|
58
|
+
alive: false,
|
|
59
|
+
detail: 'no desktop shell has published a bridge endpoint',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
let raw;
|
|
63
|
+
try {
|
|
64
|
+
raw = JSON.parse(readFileSync(path, 'utf8'));
|
|
65
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)
|
|
66
|
+
|| !Number.isInteger(raw.port) || Number(raw.port) < 1 || Number(raw.port) > 65535
|
|
67
|
+
|| typeof raw.token !== 'string' || raw.token.trim() === ''
|
|
68
|
+
|| !Number.isSafeInteger(raw.pid) || Number(raw.pid) <= 0
|
|
69
|
+
|| (raw.updatedAt !== undefined && (typeof raw.updatedAt !== 'string' || !Number.isFinite(Date.parse(raw.updatedAt))))) {
|
|
70
|
+
throw new Error('expected a port, a nonempty token, a positive pid and an optional timestamp');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
return {
|
|
75
|
+
present: true,
|
|
76
|
+
alive: false,
|
|
77
|
+
detail: `the published endpoint is unreadable: ${String(error)}`,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const updatedAt = typeof raw.updatedAt === 'string' ? raw.updatedAt : undefined;
|
|
81
|
+
const pid = typeof raw.pid === 'number' ? raw.pid : undefined;
|
|
82
|
+
// A stamp older than the refresh window is a tombstone, not a slow shell (see
|
|
83
|
+
// ENDPOINT_STALE_AFTER_MS). An ABSENT stamp is not expired on purpose: an older bridge never wrote
|
|
84
|
+
// one, and that shell deserves to be checked by its pid instead of being declared gone.
|
|
85
|
+
if (updatedAt !== undefined) {
|
|
86
|
+
const at = Date.parse(updatedAt);
|
|
87
|
+
if (Number.isFinite(at)) {
|
|
88
|
+
const ageMs = now - at;
|
|
89
|
+
if (ageMs > ENDPOINT_STALE_AFTER_MS) {
|
|
90
|
+
return {
|
|
91
|
+
present: true,
|
|
92
|
+
alive: false,
|
|
93
|
+
updatedAt,
|
|
94
|
+
detail: `the published endpoint has not been refreshed for ${Math.round(ageMs / 1000)}s, `
|
|
95
|
+
+ 'so the shell that wrote it has most likely exited',
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (pid !== undefined && !pidAlive(pid)) {
|
|
101
|
+
return {
|
|
102
|
+
present: true,
|
|
103
|
+
alive: false,
|
|
104
|
+
...updatedAt === undefined ? {} : { updatedAt },
|
|
105
|
+
detail: `the shell that published the endpoint (pid ${pid}) is not running`,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
present: true,
|
|
110
|
+
alive: true,
|
|
111
|
+
...updatedAt === undefined ? {} : { updatedAt },
|
|
112
|
+
detail: 'a desktop shell is running and answering on its published endpoint',
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The endpoint file's mtime, for diagnostics that want to say "written at".
|
|
117
|
+
*
|
|
118
|
+
* Separate and optional: the readiness report does not need it, and a caller that does can fail
|
|
119
|
+
* without disturbing anything else.
|
|
120
|
+
* @param path - the endpoint file.
|
|
121
|
+
* @returns the mtime as ISO, or undefined.
|
|
122
|
+
*/
|
|
123
|
+
export function bridgeEndpointWrittenAt(path = bridgeEndpointPath()) {
|
|
124
|
+
try {
|
|
125
|
+
return statSync(path).mtime.toISOString();
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** What the panel may ask for. */
|
|
2
|
+
export type BridgeAction = 'install' | 'uninstall';
|
|
3
|
+
/** Everything this module touches from outside, so a test can drive it without spawning. */
|
|
4
|
+
export interface BridgeActionDeps {
|
|
5
|
+
/** Runs the installer; resolves with an exit code and the tail of its output. */
|
|
6
|
+
readonly run: (command: string, argv: readonly string[]) => Promise<{
|
|
7
|
+
readonly code: number | null;
|
|
8
|
+
readonly output: string;
|
|
9
|
+
}>;
|
|
10
|
+
/** Absolute path of the packaged installer. */
|
|
11
|
+
readonly installer: () => string;
|
|
12
|
+
/** Node executable used to run it (the host's own, so no PATH surprises). */
|
|
13
|
+
readonly node: () => string;
|
|
14
|
+
}
|
|
15
|
+
/** What the panel is told. */
|
|
16
|
+
export interface BridgeActionResult {
|
|
17
|
+
/** Whether the installer exited 0. */
|
|
18
|
+
readonly ok: boolean;
|
|
19
|
+
/** Its exit code, or null when it was killed. */
|
|
20
|
+
readonly code: number | null;
|
|
21
|
+
/** The tail of its output, for the one line the panel shows. */
|
|
22
|
+
readonly output: string;
|
|
23
|
+
/** The exact command line, so a failure can be reproduced by hand. */
|
|
24
|
+
readonly command: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The argv the installer expects, in one place so the panel and a human run the same thing.
|
|
28
|
+
*
|
|
29
|
+
* `--restart --yes` is not a convenience: the shell holds `app.asar` open, so an install with the
|
|
30
|
+
* app running fails with EBUSY, and a prompt would block an unattended click.
|
|
31
|
+
* @param action - install/repair, or restore the pre-bridge state.
|
|
32
|
+
* @param installRoot - the desktop install directory that was discovered.
|
|
33
|
+
* @returns argv for the installer.
|
|
34
|
+
*/
|
|
35
|
+
export declare function bridgeActionArgv(action: BridgeAction, installRoot: string): string[];
|
|
36
|
+
/** The packaged installer, resolved from this module rather than from a build-time path. */
|
|
37
|
+
export declare function defaultInstallerPath(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Run one bridge action.
|
|
40
|
+
*
|
|
41
|
+
* Never throws for an installer failure: the panel needs the exit code and the line that explains it,
|
|
42
|
+
* and an exception would lose both.
|
|
43
|
+
* @param action - install/repair or uninstall.
|
|
44
|
+
* @param installRoot - the desktop install directory.
|
|
45
|
+
* @param deps - effects; defaulted to this process's.
|
|
46
|
+
* @returns the outcome, with the command line for reproduction.
|
|
47
|
+
*/
|
|
48
|
+
export declare function runBridgeAction(action: BridgeAction, installRoot: string, deps?: BridgeActionDeps): Promise<BridgeActionResult>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Install, repair or remove the desktop bridge from the settings panel.
|
|
3
|
+
*
|
|
4
|
+
* The panel used to print a command and leave the user to copy it into a terminal. That is a defect
|
|
5
|
+
* for this plugin specifically: the command closes and reopens the desktop app, so a half-done manual
|
|
6
|
+
* run (wrong cwd, wrong node, wrong quoting on a path with spaces) leaves the shell in a state the
|
|
7
|
+
* user has to diagnose. The installer already knows how to do the whole dance unattended
|
|
8
|
+
* (`--restart --yes`), so the panel calls it and reports what happened.
|
|
9
|
+
*
|
|
10
|
+
* What this deliberately does NOT do: invent its own patching. Every path, backup and identity check
|
|
11
|
+
* stays inside `desktop-bridge/install.mjs`, which is the same file a human would run.
|
|
12
|
+
* @module dsh-browser/browser-electron/bridge-install
|
|
13
|
+
*/
|
|
14
|
+
import { spawn } from 'node:child_process';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
/**
|
|
17
|
+
* The argv the installer expects, in one place so the panel and a human run the same thing.
|
|
18
|
+
*
|
|
19
|
+
* `--restart --yes` is not a convenience: the shell holds `app.asar` open, so an install with the
|
|
20
|
+
* app running fails with EBUSY, and a prompt would block an unattended click.
|
|
21
|
+
* @param action - install/repair, or restore the pre-bridge state.
|
|
22
|
+
* @param installRoot - the desktop install directory that was discovered.
|
|
23
|
+
* @returns argv for the installer.
|
|
24
|
+
*/
|
|
25
|
+
export function bridgeActionArgv(action, installRoot) {
|
|
26
|
+
const argv = [installRoot];
|
|
27
|
+
if (action === 'uninstall')
|
|
28
|
+
argv.push('--revert');
|
|
29
|
+
argv.push('--restart', '--yes');
|
|
30
|
+
return argv;
|
|
31
|
+
}
|
|
32
|
+
/** The packaged installer, resolved from this module rather than from a build-time path. */
|
|
33
|
+
export function defaultInstallerPath() {
|
|
34
|
+
return fileURLToPath(new URL('../../desktop-bridge/install.mjs', import.meta.url));
|
|
35
|
+
}
|
|
36
|
+
/** One line from a long output: the tail is what names the failure. */
|
|
37
|
+
function tail(text, limit = 600) {
|
|
38
|
+
const trimmed = text.trim();
|
|
39
|
+
return trimmed.length > limit ? '…' + trimmed.slice(-limit) : trimmed;
|
|
40
|
+
}
|
|
41
|
+
/** Default runner: the host's own node, a bounded wait, and no shell (so a path with spaces is data). */
|
|
42
|
+
function defaultRun(command, argv) {
|
|
43
|
+
return new Promise(resolve => {
|
|
44
|
+
const child = spawn(command, [...argv], { stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
|
|
45
|
+
let output = '';
|
|
46
|
+
const collect = (chunk) => { output += String(chunk); if (output.length > 20_000)
|
|
47
|
+
output = output.slice(-20_000); };
|
|
48
|
+
child.stdout?.on('data', collect);
|
|
49
|
+
child.stderr?.on('data', collect);
|
|
50
|
+
const timer = setTimeout(() => { try {
|
|
51
|
+
child.kill();
|
|
52
|
+
}
|
|
53
|
+
catch { /* already gone */ } }, 180_000);
|
|
54
|
+
child.on('error', error => { clearTimeout(timer); resolve({ code: null, output: `${output}\nfailed to start: ${String(error)}` }); });
|
|
55
|
+
child.on('exit', code => { clearTimeout(timer); resolve({ code, output }); });
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Run one bridge action.
|
|
60
|
+
*
|
|
61
|
+
* Never throws for an installer failure: the panel needs the exit code and the line that explains it,
|
|
62
|
+
* and an exception would lose both.
|
|
63
|
+
* @param action - install/repair or uninstall.
|
|
64
|
+
* @param installRoot - the desktop install directory.
|
|
65
|
+
* @param deps - effects; defaulted to this process's.
|
|
66
|
+
* @returns the outcome, with the command line for reproduction.
|
|
67
|
+
*/
|
|
68
|
+
export async function runBridgeAction(action, installRoot, deps = { run: defaultRun, installer: defaultInstallerPath, node: () => process.execPath }) {
|
|
69
|
+
const command = deps.node();
|
|
70
|
+
const argv = [deps.installer(), ...bridgeActionArgv(action, installRoot)];
|
|
71
|
+
const printable = [command, ...argv].map(part => (/\s/.test(part) ? `"${part}"` : part)).join(' ');
|
|
72
|
+
try {
|
|
73
|
+
// Ask the installer to check identity FIRST, without touching anything. It is the same preflight
|
|
74
|
+
// a human can run, and it turns "the button did nothing" into a named reason.
|
|
75
|
+
const preflight = await deps.run(command, [argv[0], installRoot, '--preflight']);
|
|
76
|
+
const verdict = (() => {
|
|
77
|
+
try {
|
|
78
|
+
return JSON.parse(preflight.output.trim().split('\n').at(-1) ?? '{}');
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return {};
|
|
82
|
+
}
|
|
83
|
+
})();
|
|
84
|
+
if (preflight.code !== 0 || verdict.ok !== true) {
|
|
85
|
+
return {
|
|
86
|
+
ok: false,
|
|
87
|
+
code: preflight.code,
|
|
88
|
+
output: tail(String(verdict.reason ?? preflight.output)),
|
|
89
|
+
command: printable,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const result = await deps.run(command, argv);
|
|
93
|
+
return { ok: result.code === 0, code: result.code, output: tail(result.output), command: printable };
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
return { ok: false, code: null, output: tail(String(error)), command: printable };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -35,7 +35,11 @@ export function findDesktopInstall(localAppData = process.env.LOCALAPPDATA ?? ''
|
|
|
35
35
|
if (localAppData === '')
|
|
36
36
|
return undefined;
|
|
37
37
|
const programs = join(localAppData, 'Programs');
|
|
38
|
-
|
|
38
|
+
// An archive-only layout is still a DSH Desktop install: a desktop update repacks `resources/app`
|
|
39
|
+
// into `resources/app.asar`, and the identity rule (which reads the unpacked main entry) then has
|
|
40
|
+
// nothing to read. Treating that as "no desktop here" hid the repair command exactly when it was
|
|
41
|
+
// needed most — measured on this machine after an update.
|
|
42
|
+
const isDesktop = (candidate) => readDesktopIdentity(candidate).ok || safeExists(join(candidate, 'resources', 'app.asar'));
|
|
39
43
|
for (const named of ['DSH Desktop', 'DeepSeek Harness']) {
|
|
40
44
|
const candidate = join(programs, named);
|
|
41
45
|
if (isDesktop(candidate))
|
|
@@ -113,11 +117,26 @@ export function readBridgeStatus(installRoot) {
|
|
|
113
117
|
// aimed at an application that merely looked like Electron.
|
|
114
118
|
const identity = readDesktopIdentity(installRoot);
|
|
115
119
|
if (!identity.ok) {
|
|
120
|
+
// The identity rule reads the unpacked main entry. When the archive is what exists, the tree it
|
|
121
|
+
// wants is gone — the signature of a desktop update that restored app.asar and took the bridge
|
|
122
|
+
// with it. Reporting `absent` there was wrong twice over: the desktop is installed, and the
|
|
123
|
+
// user needs the repair command.
|
|
124
|
+
if (safeExists(archivePath)) {
|
|
125
|
+
return {
|
|
126
|
+
state: 'stale',
|
|
127
|
+
present: true,
|
|
128
|
+
installRoot,
|
|
129
|
+
archivePresent: true,
|
|
130
|
+
command: repairCommand(installRoot),
|
|
131
|
+
detail: 'the desktop is packed (resources/app.asar) and the unpacked tree the bridge lives in '
|
|
132
|
+
+ 'is gone — most likely a desktop update restored the archive: re-run the installer to repair',
|
|
133
|
+
};
|
|
134
|
+
}
|
|
116
135
|
return {
|
|
117
136
|
state: 'missing',
|
|
118
137
|
present: false,
|
|
119
138
|
installRoot,
|
|
120
|
-
archivePresent:
|
|
139
|
+
archivePresent: false,
|
|
121
140
|
detail: `not a DSH Desktop install: ${identity.reason}`,
|
|
122
141
|
};
|
|
123
142
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* WHY
|
|
6
6
|
* The plugin runs inside the desktop's Node-mode host, where there is no Electron
|
|
7
|
-
* API
|
|
7
|
+
* API — which is why it self-hosts a whole browser today. The shell, however, can
|
|
8
8
|
* own views, and its sidebar already displays real web pages. This host borrows
|
|
9
9
|
* that page over the shell's bridge (see apps/desktop/bridge/plugin-browser-bridge.js),
|
|
10
10
|
* so the agent and the human end up on ONE page instead of two.
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* It implements the same `ElectronBrowserViewHost` seam the self-hosted host does,
|
|
14
14
|
* so the provider, the tools, browsing history, the synthetic cursor and the
|
|
15
15
|
* teardown rules are all unchanged: only the carrier differs. Everything is
|
|
16
|
-
* lazily materialized
|
|
16
|
+
* lazily materialized — a fresh shell has no sidebar guest until something asks
|
|
17
17
|
* for a page, and the bridge creates one on demand.
|
|
18
18
|
*
|
|
19
19
|
* FALLBACK
|
|
@@ -32,31 +32,32 @@ export declare function bridgeEndpointPath(): string;
|
|
|
32
32
|
*
|
|
33
33
|
* Thrown instead of a plain Error so callers can distinguish "the panel did not render" from "the
|
|
34
34
|
* browser broke", which is exactly the distinction issue #37 says was missing. The plugin no longer
|
|
35
|
-
* waits for a human to show the conversation
|
|
36
|
-
* this host retries while it renders
|
|
35
|
+
* waits for a human to show the conversation — the client half asks the shell to (`openSession`) and
|
|
36
|
+
* this host retries while it renders — so reaching here means the shell did not render it at all.
|
|
37
37
|
*/
|
|
38
38
|
export declare class BrowserPanelNotDisplayedError extends Error {
|
|
39
|
-
readonly code
|
|
39
|
+
readonly code: string;
|
|
40
40
|
/**
|
|
41
41
|
* @param detail - the bridge's own explanation, appended so the message says why.
|
|
42
42
|
*/
|
|
43
|
-
constructor(detail: string);
|
|
43
|
+
constructor(detail: string, code?: string);
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
46
|
* The desktop sidebar, presented as a browser view host.
|
|
47
47
|
*
|
|
48
48
|
* One sidebar exists per shell window, so every view this host hands out refers
|
|
49
49
|
* to the same guest: the provider keeps its tab bookkeeping, and the tabs simply
|
|
50
|
-
* share the visible page. That is the intended behaviour for this carrier
|
|
50
|
+
* share the visible page. That is the intended behaviour for this carrier — the
|
|
51
51
|
* point is a single page both parties can see.
|
|
52
52
|
*/
|
|
53
53
|
export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
54
|
+
private readonly isQuiet;
|
|
54
55
|
private readonly connection;
|
|
55
56
|
/**
|
|
56
57
|
* One entry per view this host handed out: the conversation it serves, and the guest backing it.
|
|
57
58
|
*
|
|
58
59
|
* The conversation belongs to the ENTRY, not to this host. A single plugin process serves every
|
|
59
|
-
* conversation
|
|
60
|
+
* conversation — DSH runs them all through one host instance — so an owner held on the host
|
|
60
61
|
* would be one conversation's id applied to all of them, and a page could still land in
|
|
61
62
|
* another's sidebar however carefully the bridge checked it.
|
|
62
63
|
*/
|
|
@@ -66,7 +67,7 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
66
67
|
*
|
|
67
68
|
* Every DSH session is its own plugin process, and the sidebar is one surface they all share.
|
|
68
69
|
* A session can only see its own `views` map, so before the bridge kept a ledger it adopted
|
|
69
|
-
* whichever tab it found
|
|
70
|
+
* whichever tab it found — including one another session had opened, which is how a URL from
|
|
70
71
|
* one session appeared in another's sidebar. The id is per process, so two sessions never
|
|
71
72
|
* collide and one session's tabs are never handed to another; it is deliberately not the DSH
|
|
72
73
|
* session id, which this layer has no access to and does not need.
|
|
@@ -74,17 +75,17 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
74
75
|
* The whole ledger rests on that premise, so it was measured rather than assumed: with two
|
|
75
76
|
* sessions running, the desktop had TWO host processes (plus one main, two renderers and a
|
|
76
77
|
* gpu/utility pair). If sessions ever shared a process, every owner check in the bridge would
|
|
77
|
-
* compare equal and the bleed would return in a new shape
|
|
78
|
+
* compare equal and the bleed would return in a new shape — so a change to how DSH spawns
|
|
78
79
|
* sessions invalidates this file, not just this comment.
|
|
79
80
|
*
|
|
80
81
|
* It is now the CONVERSATION id rather than an invented uuid, read from the plugin's ctx by the
|
|
81
82
|
* same path DSH's own desktop host uses. That matters because the shell keeps one sidebar per
|
|
82
83
|
* conversation and writes its session id onto each sidebar container (on the React fiber,
|
|
83
|
-
* measured on the running app)
|
|
84
|
+
* measured on the running app) — so the bridge can only answer "is this sidebar mine" if it has
|
|
84
85
|
* a comparable id. With an invented uuid it never could, which is how a command came to be typed
|
|
85
86
|
* into another conversation's address bar.
|
|
86
87
|
*
|
|
87
|
-
* Falls back to a random uuid when the host cannot supply one
|
|
88
|
+
* Falls back to a random uuid when the host cannot supply one — an older DSH, or a non-desktop
|
|
88
89
|
* composition. That is no worse than before: the bridge then knows only "this process", and it
|
|
89
90
|
* refuses to operate on a sidebar it cannot prove is its own.
|
|
90
91
|
*/
|
|
@@ -94,7 +95,7 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
94
95
|
* conversation each belongs to.
|
|
95
96
|
*
|
|
96
97
|
* The provider destroys its view handles before it asks for a release, so the mapping is dropped
|
|
97
|
-
* by then
|
|
98
|
+
* by then — keeping the guest ids here is what lets us close only our own tabs when several
|
|
98
99
|
* conversations are running (requirements 搂4: each session gets its own page). The owner rides
|
|
99
100
|
* along for the same reason it does in {@link views}: a release names one conversation.
|
|
100
101
|
*/
|
|
@@ -107,7 +108,7 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
107
108
|
* handler is stored anyway so the interface contract holds (a caller may register
|
|
108
109
|
* one and must not be surprised) and so a future bridge operation can deliver it
|
|
109
110
|
* without changing the provider. Consequently no user-action event is emitted while
|
|
110
|
-
* the desktop sidebar is the carrier
|
|
111
|
+
* the desktop sidebar is the carrier — by design, not by omission.
|
|
111
112
|
*/
|
|
112
113
|
private userActionHandler;
|
|
113
114
|
/** Told when the shell behind this bridge exits; see `onLost`. */
|
|
@@ -134,7 +135,7 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
134
135
|
* caller falls back to self-hosting, which always works.
|
|
135
136
|
* @returns the host, or undefined when no bridge is available.
|
|
136
137
|
*/
|
|
137
|
-
static discover(sessionId?: string): Promise<DesktopBridgeViewHost | undefined>;
|
|
138
|
+
static discover(sessionId?: string, isQuiet?: () => boolean): Promise<DesktopBridgeViewHost | undefined>;
|
|
138
139
|
/**
|
|
139
140
|
* Whether the last discovery refused a bridge because its sidebar panel is an iframe.
|
|
140
141
|
*
|
|
@@ -151,8 +152,8 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
151
152
|
* Every page this conversation's sidebar panel currently holds.
|
|
152
153
|
*
|
|
153
154
|
* The shell owns page creation inside the panel: a link the user or the agent clicks may open a
|
|
154
|
-
* new page, and nothing tells the provider. Those pages are real
|
|
155
|
-
*
|
|
155
|
+
* new page, and nothing tells the provider. Those pages are real — they are what the human sees
|
|
156
|
+
* — but without this the tab model reports only the ones the provider created, so the rest are
|
|
156
157
|
* invisible to `dsh_browser_list_tabs` and unclosable through `dsh_browser_close_tab`.
|
|
157
158
|
*
|
|
158
159
|
* The bridge's `list` already answers with the sidebar guests, which is the same information, so
|
|
@@ -163,14 +164,14 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
163
164
|
* Every sidebar page this conversation holds that THIS HOST did not open.
|
|
164
165
|
*
|
|
165
166
|
* The shell owns page creation inside the panel: a link the user or the agent clicks may open a
|
|
166
|
-
* new page, and nothing tells the provider. Those pages are real
|
|
167
|
-
*
|
|
167
|
+
* new page, and nothing tells the provider. Those pages are real — they are what the human sees
|
|
168
|
+
* — but without this the tab model reports only the ones the provider created, so the rest are
|
|
168
169
|
* invisible to `dsh_browser_list_tabs` and unclosable through `dsh_browser_close_tab`.
|
|
169
170
|
*
|
|
170
171
|
* Pages this host opened are EXCLUDED here rather than deduplicated by the caller, because the
|
|
171
172
|
* caller cannot do it: the provider knows a tab by its own id and the carrier knows a page by the
|
|
172
173
|
* guest id, and the two never match. The first version returned everything and relied on the
|
|
173
|
-
* caller to filter, which reported the same page twice
|
|
174
|
+
* caller to filter, which reported the same page twice — the mapping that makes the match
|
|
174
175
|
* possible exists only here.
|
|
175
176
|
* @returns the panel's pages that are not ours, or an empty list when the bridge cannot answer.
|
|
176
177
|
*/
|
|
@@ -178,7 +179,7 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
178
179
|
/**
|
|
179
180
|
* Close one sidebar page by the id {@link listPages} reported.
|
|
180
181
|
*
|
|
181
|
-
* The bridge closes sidebar pages by TITLE, and only the ones the caller owns
|
|
182
|
+
* The bridge closes sidebar pages by TITLE, and only the ones the caller owns — that is what
|
|
182
183
|
* stopped one conversation's teardown from destroying another's page. So the title is looked up
|
|
183
184
|
* through the same listing, and a page that no longer appears is treated as already gone rather
|
|
184
185
|
* than as an error: the caller asked for it to be closed, and it is.
|
|
@@ -188,8 +189,8 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
188
189
|
/**
|
|
189
190
|
* The guest backing a view, materialized on first use.
|
|
190
191
|
*
|
|
191
|
-
* The conversation that called owns exactly one sidebar page on this carrier
|
|
192
|
-
* agent look at the same page
|
|
192
|
+
* The conversation that called owns exactly one sidebar page on this carrier — a human and the
|
|
193
|
+
* agent look at the same page — so every view resolves to that conversation's own guest, and the
|
|
193
194
|
* page does not multiply behind the provider's own tab bookkeeping.
|
|
194
195
|
*
|
|
195
196
|
* A cached guest is used as-is: probing it first cost a round-trip on every command, so liveness
|
|
@@ -210,21 +211,23 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
210
211
|
* This used to be empty, on the reasoning that the sidebar is already on screen so there is
|
|
211
212
|
* nothing to show. That confused "the sidebar is visible" with "this page is the one being
|
|
212
213
|
* looked at": opening a page left it behind whatever the human had in front, which is issue
|
|
213
|
-
* #23. The other two carriers both do this
|
|
214
|
-
* system browser calls `Page.bringToFront`
|
|
214
|
+
* #23. The other two carriers both do this — the self-hosted window re-adds the view and the
|
|
215
|
+
* system browser calls `Page.bringToFront` — so this carrier was the odd one out.
|
|
215
216
|
*
|
|
216
217
|
* Best-effort by design: the tab strip belongs to the shell's renderer, and failing to raise
|
|
217
218
|
* it must not fail the navigation that has already happened.
|
|
218
219
|
* @param handle - the view to bring forward.
|
|
219
220
|
*/
|
|
220
|
-
showView(handle: ElectronViewHandle
|
|
221
|
+
showView(handle: ElectronViewHandle, _label?: string, options?: {
|
|
222
|
+
readonly quiet?: boolean;
|
|
223
|
+
}): void;
|
|
221
224
|
onUserAction(handler: (action: BrowserUserAction) => void): void;
|
|
222
225
|
/**
|
|
223
226
|
* Release the sidebar's browser pages (requirements 搂3, `ui.closeWithSession`).
|
|
224
227
|
*
|
|
225
228
|
* Destroying our own view handles is not enough on this carrier: the sidebar
|
|
226
229
|
* belongs to the shell and would happily keep the page (and its renderer) alive.
|
|
227
|
-
* Closing the tabs is what actually ends the page
|
|
230
|
+
* Closing the tabs is what actually ends the page — and only the page: cookies
|
|
228
231
|
* live in the partition, history on disk, so both survive.
|
|
229
232
|
* @param owner - the conversation whose pages to close. Omit to close every conversation's,
|
|
230
233
|
* which is only correct from a teardown that is itself global.
|