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,122 @@
|
|
|
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
|
+
/** What the panel may ask for. */
|
|
18
|
+
export type BridgeAction = 'install' | 'uninstall'
|
|
19
|
+
|
|
20
|
+
/** Everything this module touches from outside, so a test can drive it without spawning. */
|
|
21
|
+
export interface BridgeActionDeps {
|
|
22
|
+
/** Runs the installer; resolves with an exit code and the tail of its output. */
|
|
23
|
+
readonly run: (command: string, argv: readonly string[]) => Promise<{ readonly code: number | null; readonly output: string }>
|
|
24
|
+
/** Absolute path of the packaged installer. */
|
|
25
|
+
readonly installer: () => string
|
|
26
|
+
/** Node executable used to run it (the host's own, so no PATH surprises). */
|
|
27
|
+
readonly node: () => string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** What the panel is told. */
|
|
31
|
+
export interface BridgeActionResult {
|
|
32
|
+
/** Whether the installer exited 0. */
|
|
33
|
+
readonly ok: boolean
|
|
34
|
+
/** Its exit code, or null when it was killed. */
|
|
35
|
+
readonly code: number | null
|
|
36
|
+
/** The tail of its output, for the one line the panel shows. */
|
|
37
|
+
readonly output: string
|
|
38
|
+
/** The exact command line, so a failure can be reproduced by hand. */
|
|
39
|
+
readonly command: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The argv the installer expects, in one place so the panel and a human run the same thing.
|
|
44
|
+
*
|
|
45
|
+
* `--restart --yes` is not a convenience: the shell holds `app.asar` open, so an install with the
|
|
46
|
+
* app running fails with EBUSY, and a prompt would block an unattended click.
|
|
47
|
+
* @param action - install/repair, or restore the pre-bridge state.
|
|
48
|
+
* @param installRoot - the desktop install directory that was discovered.
|
|
49
|
+
* @returns argv for the installer.
|
|
50
|
+
*/
|
|
51
|
+
export function bridgeActionArgv(action: BridgeAction, installRoot: string): string[] {
|
|
52
|
+
const argv = [installRoot]
|
|
53
|
+
if (action === 'uninstall') argv.push('--revert')
|
|
54
|
+
argv.push('--restart', '--yes')
|
|
55
|
+
return argv
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The packaged installer, resolved from this module rather than from a build-time path. */
|
|
59
|
+
export function defaultInstallerPath(): string {
|
|
60
|
+
return fileURLToPath(new URL('../../desktop-bridge/install.mjs', import.meta.url))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** One line from a long output: the tail is what names the failure. */
|
|
64
|
+
function tail(text: string, limit = 600): string {
|
|
65
|
+
const trimmed = text.trim()
|
|
66
|
+
return trimmed.length > limit ? '…' + trimmed.slice(-limit) : trimmed
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Default runner: the host's own node, a bounded wait, and no shell (so a path with spaces is data). */
|
|
70
|
+
function defaultRun(command: string, argv: readonly string[]): Promise<{ code: number | null; output: string }> {
|
|
71
|
+
return new Promise(resolve => {
|
|
72
|
+
const child = spawn(command, [...argv], { stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true })
|
|
73
|
+
let output = ''
|
|
74
|
+
const collect = (chunk: unknown): void => { output += String(chunk); if (output.length > 20_000) output = output.slice(-20_000) }
|
|
75
|
+
child.stdout?.on('data', collect)
|
|
76
|
+
child.stderr?.on('data', collect)
|
|
77
|
+
const timer = setTimeout(() => { try { child.kill() } catch { /* already gone */ } }, 180_000)
|
|
78
|
+
child.on('error', error => { clearTimeout(timer); resolve({ code: null, output: `${output}\nfailed to start: ${String(error)}` }) })
|
|
79
|
+
child.on('exit', code => { clearTimeout(timer); resolve({ code, output }) })
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Run one bridge action.
|
|
85
|
+
*
|
|
86
|
+
* Never throws for an installer failure: the panel needs the exit code and the line that explains it,
|
|
87
|
+
* and an exception would lose both.
|
|
88
|
+
* @param action - install/repair or uninstall.
|
|
89
|
+
* @param installRoot - the desktop install directory.
|
|
90
|
+
* @param deps - effects; defaulted to this process's.
|
|
91
|
+
* @returns the outcome, with the command line for reproduction.
|
|
92
|
+
*/
|
|
93
|
+
export async function runBridgeAction(
|
|
94
|
+
action: BridgeAction,
|
|
95
|
+
installRoot: string,
|
|
96
|
+
deps: BridgeActionDeps = { run: defaultRun, installer: defaultInstallerPath, node: () => process.execPath },
|
|
97
|
+
): Promise<BridgeActionResult> {
|
|
98
|
+
const command = deps.node()
|
|
99
|
+
const argv = [deps.installer(), ...bridgeActionArgv(action, installRoot)]
|
|
100
|
+
const printable = [command, ...argv].map(part => (/\s/.test(part) ? `"${part}"` : part)).join(' ')
|
|
101
|
+
try {
|
|
102
|
+
// Ask the installer to check identity FIRST, without touching anything. It is the same preflight
|
|
103
|
+
// a human can run, and it turns "the button did nothing" into a named reason.
|
|
104
|
+
const preflight = await deps.run(command, [argv[0] as string, installRoot, '--preflight'])
|
|
105
|
+
const verdict = (() => {
|
|
106
|
+
try { return JSON.parse(preflight.output.trim().split('\n').at(-1) ?? '{}') as { ok?: boolean; reason?: string } }
|
|
107
|
+
catch { return {} as { ok?: boolean; reason?: string } }
|
|
108
|
+
})()
|
|
109
|
+
if (preflight.code !== 0 || verdict.ok !== true) {
|
|
110
|
+
return {
|
|
111
|
+
ok: false,
|
|
112
|
+
code: preflight.code,
|
|
113
|
+
output: tail(String(verdict.reason ?? preflight.output)),
|
|
114
|
+
command: printable,
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const result = await deps.run(command, argv)
|
|
118
|
+
return { ok: result.code === 0, code: result.code, output: tail(result.output), command: printable }
|
|
119
|
+
} catch (error) {
|
|
120
|
+
return { ok: false, code: null, output: tail(String(error)), command: printable }
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -36,7 +36,12 @@ import { readDesktopIdentity } from './desktop-identity.js'
|
|
|
36
36
|
export function findDesktopInstall(localAppData = process.env.LOCALAPPDATA ?? ''): string | undefined {
|
|
37
37
|
if (localAppData === '') return undefined
|
|
38
38
|
const programs = join(localAppData, 'Programs')
|
|
39
|
-
|
|
39
|
+
// An archive-only layout is still a DSH Desktop install: a desktop update repacks `resources/app`
|
|
40
|
+
// into `resources/app.asar`, and the identity rule (which reads the unpacked main entry) then has
|
|
41
|
+
// nothing to read. Treating that as "no desktop here" hid the repair command exactly when it was
|
|
42
|
+
// needed most — measured on this machine after an update.
|
|
43
|
+
const isDesktop = (candidate: string): boolean =>
|
|
44
|
+
readDesktopIdentity(candidate).ok || safeExists(join(candidate, 'resources', 'app.asar'))
|
|
40
45
|
for (const named of ['DSH Desktop', 'DeepSeek Harness']) {
|
|
41
46
|
const candidate = join(programs, named)
|
|
42
47
|
if (isDesktop(candidate)) return candidate
|
|
@@ -136,11 +141,26 @@ export function readBridgeStatus(installRoot: string): BridgeStatus {
|
|
|
136
141
|
// aimed at an application that merely looked like Electron.
|
|
137
142
|
const identity = readDesktopIdentity(installRoot)
|
|
138
143
|
if (!identity.ok) {
|
|
144
|
+
// The identity rule reads the unpacked main entry. When the archive is what exists, the tree it
|
|
145
|
+
// wants is gone — the signature of a desktop update that restored app.asar and took the bridge
|
|
146
|
+
// with it. Reporting `absent` there was wrong twice over: the desktop is installed, and the
|
|
147
|
+
// user needs the repair command.
|
|
148
|
+
if (safeExists(archivePath)) {
|
|
149
|
+
return {
|
|
150
|
+
state: 'stale',
|
|
151
|
+
present: true,
|
|
152
|
+
installRoot,
|
|
153
|
+
archivePresent: true,
|
|
154
|
+
command: repairCommand(installRoot),
|
|
155
|
+
detail: 'the desktop is packed (resources/app.asar) and the unpacked tree the bridge lives in '
|
|
156
|
+
+ 'is gone — most likely a desktop update restored the archive: re-run the installer to repair',
|
|
157
|
+
}
|
|
158
|
+
}
|
|
139
159
|
return {
|
|
140
160
|
state: 'missing',
|
|
141
161
|
present: false,
|
|
142
162
|
installRoot,
|
|
143
|
-
archivePresent:
|
|
163
|
+
archivePresent: false,
|
|
144
164
|
detail: `not a DSH Desktop install: ${identity.reason}`,
|
|
145
165
|
}
|
|
146
166
|
}
|
|
@@ -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
|
|
@@ -46,9 +46,10 @@ export function bridgeEndpointPath(): string {
|
|
|
46
46
|
* A display state, not a dead carrier. It must never reach `reportLost`, and it must never be
|
|
47
47
|
* retried as though a guest had vanished: retrying cannot attach a webview the shell has not
|
|
48
48
|
* rendered, and treating it as loss swapped the surface to a fresh self-hosted window whose page was
|
|
49
|
-
* blank
|
|
49
|
+
* blank — losing the page the user had open.
|
|
50
50
|
*/
|
|
51
51
|
const PANEL_NOT_DISPLAYED = 'panel-not-displayed'
|
|
52
|
+
const PANEL_INITIALIZING = 'panel-initializing'
|
|
52
53
|
|
|
53
54
|
/**
|
|
54
55
|
* How many times a display-state refusal is retried, and how long each retry waits.
|
|
@@ -67,23 +68,24 @@ const PANEL_DISPLAY_RETRY_MS = 400
|
|
|
67
68
|
*
|
|
68
69
|
* Thrown instead of a plain Error so callers can distinguish "the panel did not render" from "the
|
|
69
70
|
* browser broke", which is exactly the distinction issue #37 says was missing. The plugin no longer
|
|
70
|
-
* waits for a human to show the conversation
|
|
71
|
-
* this host retries while it renders
|
|
71
|
+
* waits for a human to show the conversation — the client half asks the shell to (`openSession`) and
|
|
72
|
+
* this host retries while it renders — so reaching here means the shell did not render it at all.
|
|
72
73
|
*/
|
|
73
74
|
export class BrowserPanelNotDisplayedError extends Error {
|
|
74
|
-
readonly code
|
|
75
|
+
readonly code: string
|
|
75
76
|
|
|
76
77
|
/**
|
|
77
78
|
* @param detail - the bridge's own explanation, appended so the message says why.
|
|
78
79
|
*/
|
|
79
|
-
constructor(detail: string) {
|
|
80
|
+
constructor(detail: string, code = PANEL_NOT_DISPLAYED) {
|
|
80
81
|
super(
|
|
81
|
-
'dsh-builtin-browser: this conversation\'s sidebar page did not attach
|
|
82
|
+
'dsh-builtin-browser: this conversation\'s sidebar page did not attach — the shell was asked to '
|
|
82
83
|
+ 'show this conversation and its panel still did not render. Nothing was lost, and the page '
|
|
83
84
|
+ 'appears as soon as the panel mounts. '
|
|
84
85
|
+ `(${detail})`,
|
|
85
86
|
)
|
|
86
87
|
this.name = 'BrowserPanelNotDisplayedError'
|
|
88
|
+
this.code = code
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
|
|
@@ -99,7 +101,7 @@ function isGuestGone(error: unknown): boolean {
|
|
|
99
101
|
if (error instanceof BrowserPanelNotDisplayedError) return false
|
|
100
102
|
const message = error instanceof Error ? error.message : String(error)
|
|
101
103
|
// The panel path reports its own failure when the renderer never produced a page, and that is the
|
|
102
|
-
// same class as a vanished guest
|
|
104
|
+
// same class as a vanished guest — worth one retry on a fresh panel — so it is listed here too.
|
|
103
105
|
return /guest \d+ is not available|sidebar unavailable|produced no page/i.test(message)
|
|
104
106
|
}
|
|
105
107
|
|
|
@@ -108,7 +110,7 @@ function isGuestGone(error: unknown): boolean {
|
|
|
108
110
|
*
|
|
109
111
|
* One sidebar exists per shell window, so every view this host hands out refers
|
|
110
112
|
* to the same guest: the provider keeps its tab bookkeeping, and the tabs simply
|
|
111
|
-
* share the visible page. That is the intended behaviour for this carrier
|
|
113
|
+
* share the visible page. That is the intended behaviour for this carrier — the
|
|
112
114
|
* point is a single page both parties can see.
|
|
113
115
|
*/
|
|
114
116
|
export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
@@ -117,7 +119,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
117
119
|
* One entry per view this host handed out: the conversation it serves, and the guest backing it.
|
|
118
120
|
*
|
|
119
121
|
* The conversation belongs to the ENTRY, not to this host. A single plugin process serves every
|
|
120
|
-
* conversation
|
|
122
|
+
* conversation — DSH runs them all through one host instance — so an owner held on the host
|
|
121
123
|
* would be one conversation's id applied to all of them, and a page could still land in
|
|
122
124
|
* another's sidebar however carefully the bridge checked it.
|
|
123
125
|
*/
|
|
@@ -127,7 +129,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
127
129
|
*
|
|
128
130
|
* Every DSH session is its own plugin process, and the sidebar is one surface they all share.
|
|
129
131
|
* A session can only see its own `views` map, so before the bridge kept a ledger it adopted
|
|
130
|
-
* whichever tab it found
|
|
132
|
+
* whichever tab it found — including one another session had opened, which is how a URL from
|
|
131
133
|
* one session appeared in another's sidebar. The id is per process, so two sessions never
|
|
132
134
|
* collide and one session's tabs are never handed to another; it is deliberately not the DSH
|
|
133
135
|
* session id, which this layer has no access to and does not need.
|
|
@@ -135,17 +137,17 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
135
137
|
* The whole ledger rests on that premise, so it was measured rather than assumed: with two
|
|
136
138
|
* sessions running, the desktop had TWO host processes (plus one main, two renderers and a
|
|
137
139
|
* gpu/utility pair). If sessions ever shared a process, every owner check in the bridge would
|
|
138
|
-
* compare equal and the bleed would return in a new shape
|
|
140
|
+
* compare equal and the bleed would return in a new shape — so a change to how DSH spawns
|
|
139
141
|
* sessions invalidates this file, not just this comment.
|
|
140
142
|
*
|
|
141
143
|
* It is now the CONVERSATION id rather than an invented uuid, read from the plugin's ctx by the
|
|
142
144
|
* same path DSH's own desktop host uses. That matters because the shell keeps one sidebar per
|
|
143
145
|
* conversation and writes its session id onto each sidebar container (on the React fiber,
|
|
144
|
-
* measured on the running app)
|
|
146
|
+
* measured on the running app) — so the bridge can only answer "is this sidebar mine" if it has
|
|
145
147
|
* a comparable id. With an invented uuid it never could, which is how a command came to be typed
|
|
146
148
|
* into another conversation's address bar.
|
|
147
149
|
*
|
|
148
|
-
* Falls back to a random uuid when the host cannot supply one
|
|
150
|
+
* Falls back to a random uuid when the host cannot supply one — an older DSH, or a non-desktop
|
|
149
151
|
* composition. That is no worse than before: the bridge then knows only "this process", and it
|
|
150
152
|
* refuses to operate on a sidebar it cannot prove is its own.
|
|
151
153
|
*/
|
|
@@ -155,7 +157,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
155
157
|
* conversation each belongs to.
|
|
156
158
|
*
|
|
157
159
|
* The provider destroys its view handles before it asks for a release, so the mapping is dropped
|
|
158
|
-
* by then
|
|
160
|
+
* by then — keeping the guest ids here is what lets us close only our own tabs when several
|
|
159
161
|
* conversations are running (requirements 搂4: each session gets its own page). The owner rides
|
|
160
162
|
* along for the same reason it does in {@link views}: a release names one conversation.
|
|
161
163
|
*/
|
|
@@ -168,7 +170,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
168
170
|
* handler is stored anyway so the interface contract holds (a caller may register
|
|
169
171
|
* one and must not be surprised) and so a future bridge operation can deliver it
|
|
170
172
|
* without changing the provider. Consequently no user-action event is emitted while
|
|
171
|
-
* the desktop sidebar is the carrier
|
|
173
|
+
* the desktop sidebar is the carrier — by design, not by omission.
|
|
172
174
|
*/
|
|
173
175
|
private userActionHandler: ((action: BrowserUserAction) => void) | undefined
|
|
174
176
|
/** Told when the shell behind this bridge exits; see `onLost`. */
|
|
@@ -177,7 +179,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
177
179
|
/**
|
|
178
180
|
* @param endpoint - the shell's published bridge endpoint.
|
|
179
181
|
*/
|
|
180
|
-
private constructor(endpoint: BridgeEndpoint, sessionId?: string) {
|
|
182
|
+
private constructor(endpoint: BridgeEndpoint, sessionId?: string, private readonly isQuiet: () => boolean = () => false) {
|
|
181
183
|
this.owner = sessionId !== undefined && sessionId !== String.fromCharCode(39,39) ? sessionId : randomUUID()
|
|
182
184
|
// The transport reaches this only by concluding the shell stopped refreshing its endpoint, which
|
|
183
185
|
// is `shell-exited`.
|
|
@@ -212,7 +214,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
212
214
|
* caller falls back to self-hosting, which always works.
|
|
213
215
|
* @returns the host, or undefined when no bridge is available.
|
|
214
216
|
*/
|
|
215
|
-
static async discover(sessionId?: string): Promise<DesktopBridgeViewHost | undefined> {
|
|
217
|
+
static async discover(sessionId?: string, isQuiet?: () => boolean): Promise<DesktopBridgeViewHost | undefined> {
|
|
216
218
|
let endpoint: BridgeEndpoint
|
|
217
219
|
try {
|
|
218
220
|
const raw = JSON.parse(readFileSync(bridgeEndpointPath(), 'utf8')) as Partial<BridgeEndpoint>
|
|
@@ -232,7 +234,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
232
234
|
//
|
|
233
235
|
// The sidebar browser renders as a <webview> only where the shell exposes
|
|
234
236
|
// `dshDesktop.browser` and enables `webviewTag`. Where it renders as an <iframe> there is
|
|
235
|
-
// no webContents, no `getWebContentsId()` and no CDP endpoint
|
|
237
|
+
// no webContents, no `getWebContentsId()` and no CDP endpoint — and every tool here is
|
|
236
238
|
// built on CDP, so adopting it means failing every call, with no path back to a carrier
|
|
237
239
|
// that works. Reported on DSH Desktop 2.0.17 with both conditions measured.
|
|
238
240
|
//
|
|
@@ -246,7 +248,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
246
248
|
DesktopBridgeViewHost.refuseIframe = true
|
|
247
249
|
return undefined
|
|
248
250
|
}
|
|
249
|
-
return new DesktopBridgeViewHost(endpoint, sessionId)
|
|
251
|
+
return new DesktopBridgeViewHost(endpoint, sessionId, isQuiet)
|
|
250
252
|
} finally {
|
|
251
253
|
probe.close()
|
|
252
254
|
}
|
|
@@ -279,8 +281,8 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
279
281
|
* Every page this conversation's sidebar panel currently holds.
|
|
280
282
|
*
|
|
281
283
|
* The shell owns page creation inside the panel: a link the user or the agent clicks may open a
|
|
282
|
-
* new page, and nothing tells the provider. Those pages are real
|
|
283
|
-
*
|
|
284
|
+
* new page, and nothing tells the provider. Those pages are real — they are what the human sees
|
|
285
|
+
* — but without this the tab model reports only the ones the provider created, so the rest are
|
|
284
286
|
* invisible to `dsh_browser_list_tabs` and unclosable through `dsh_browser_close_tab`.
|
|
285
287
|
*
|
|
286
288
|
* The bridge's `list` already answers with the sidebar guests, which is the same information, so
|
|
@@ -291,14 +293,14 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
291
293
|
* Every sidebar page this conversation holds that THIS HOST did not open.
|
|
292
294
|
*
|
|
293
295
|
* The shell owns page creation inside the panel: a link the user or the agent clicks may open a
|
|
294
|
-
* new page, and nothing tells the provider. Those pages are real
|
|
295
|
-
*
|
|
296
|
+
* new page, and nothing tells the provider. Those pages are real — they are what the human sees
|
|
297
|
+
* — but without this the tab model reports only the ones the provider created, so the rest are
|
|
296
298
|
* invisible to `dsh_browser_list_tabs` and unclosable through `dsh_browser_close_tab`.
|
|
297
299
|
*
|
|
298
300
|
* Pages this host opened are EXCLUDED here rather than deduplicated by the caller, because the
|
|
299
301
|
* caller cannot do it: the provider knows a tab by its own id and the carrier knows a page by the
|
|
300
302
|
* guest id, and the two never match. The first version returned everything and relied on the
|
|
301
|
-
* caller to filter, which reported the same page twice
|
|
303
|
+
* caller to filter, which reported the same page twice — the mapping that makes the match
|
|
302
304
|
* possible exists only here.
|
|
303
305
|
* @returns the panel's pages that are not ours, or an empty list when the bridge cannot answer.
|
|
304
306
|
*/
|
|
@@ -322,7 +324,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
322
324
|
/**
|
|
323
325
|
* Close one sidebar page by the id {@link listPages} reported.
|
|
324
326
|
*
|
|
325
|
-
* The bridge closes sidebar pages by TITLE, and only the ones the caller owns
|
|
327
|
+
* The bridge closes sidebar pages by TITLE, and only the ones the caller owns — that is what
|
|
326
328
|
* stopped one conversation's teardown from destroying another's page. So the title is looked up
|
|
327
329
|
* through the same listing, and a page that no longer appears is treated as already gone rather
|
|
328
330
|
* than as an error: the caller asked for it to be closed, and it is.
|
|
@@ -340,8 +342,8 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
340
342
|
/**
|
|
341
343
|
* The guest backing a view, materialized on first use.
|
|
342
344
|
*
|
|
343
|
-
* The conversation that called owns exactly one sidebar page on this carrier
|
|
344
|
-
* agent look at the same page
|
|
345
|
+
* The conversation that called owns exactly one sidebar page on this carrier — a human and the
|
|
346
|
+
* agent look at the same page — so every view resolves to that conversation's own guest, and the
|
|
345
347
|
* page does not multiply behind the provider's own tab bookkeeping.
|
|
346
348
|
*
|
|
347
349
|
* A cached guest is used as-is: probing it first cost a round-trip on every command, so liveness
|
|
@@ -356,8 +358,11 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
356
358
|
// command. A guest that has gone away is detected by the command itself failing,
|
|
357
359
|
// and `createView`'s sendCommand then discards the cache and calls back in here.
|
|
358
360
|
if (entry?.guest !== undefined) return entry.guest
|
|
361
|
+
if (options?.initialize === false) {
|
|
362
|
+
throw new BrowserPanelNotDisplayedError('this view has no attached guest yet', PANEL_INITIALIZING)
|
|
363
|
+
}
|
|
359
364
|
|
|
360
|
-
// The conversation THIS VIEW serves
|
|
365
|
+
// The conversation THIS VIEW serves — read from the view, never from the process.
|
|
361
366
|
//
|
|
362
367
|
// The difference is the whole bug. This host is one instance shared by every conversation, so
|
|
363
368
|
// `this.owner` alone can only be "whichever conversation this process happens to name", and
|
|
@@ -370,10 +375,11 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
370
375
|
// shortcut or clicking its card, both of which the shell delivers to whatever it displays.
|
|
371
376
|
const owner = entry?.owner ?? this.owner
|
|
372
377
|
// A command that must not present anything (issue #46: the live preview) takes a read-only path.
|
|
373
|
-
// It asks the bridge what this conversation ALREADY has and never enters the retry loop below
|
|
378
|
+
// 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
|
|
374
379
|
// and wrong for "let me look at it". A page that is not on screen therefore reports as a display
|
|
375
380
|
// state, and the preview route turns that into the panel's paused state.
|
|
376
|
-
|
|
381
|
+
const quiet = this.isQuiet()
|
|
382
|
+
if (options?.present === false || quiet) {
|
|
377
383
|
// `list` and NOT `ensureSidebar`. This is deliberate and it is the whole fix: every version of
|
|
378
384
|
// `ensureSidebar` can drive the shell — the current one asks the renderer to display the
|
|
379
385
|
// conversation, and the pre-#37 one literally pressed the sidebar shortcut and typed into the
|
|
@@ -385,14 +391,17 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
385
391
|
? listed.sidebar.filter(page => page !== null && typeof page === 'object' && page.type === 'webview')
|
|
386
392
|
: []
|
|
387
393
|
const wanted = url !== undefined && url !== '' ? url : undefined
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
|
|
394
|
+
const matchedUrl = pages.find(page => wanted !== undefined && page.url === wanted)
|
|
395
|
+
const match = quiet && wanted !== undefined
|
|
396
|
+
? matchedUrl
|
|
397
|
+
: pages.find(page => wanted !== undefined && typeof page.url === 'string' && page.url.startsWith(wanted)) ?? pages[0]
|
|
391
398
|
const id = match !== undefined ? Number(match.id) : Number.NaN
|
|
392
399
|
if (!Number.isFinite(id) || id <= 0) {
|
|
393
400
|
throw new BrowserPanelNotDisplayedError(
|
|
394
|
-
|
|
395
|
-
|
|
401
|
+
quiet
|
|
402
|
+
? 'quiet mode will not open a sidebar or switch conversations; open this URL in the sidebar yourself or select the bundled browser for background work'
|
|
403
|
+
: 'the preview asked for this conversation\'s page without presenting it, and no page is attached '
|
|
404
|
+
+ `(the shell holds ${pages.length})`,
|
|
396
405
|
)
|
|
397
406
|
}
|
|
398
407
|
this.views.set(viewId, { guest: id, owner })
|
|
@@ -410,14 +419,14 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
410
419
|
// panel-not-displayed - the conversation exists but is not the one on screen;
|
|
411
420
|
// "is not mounted" - its surface store was not minted when the tab was placed.
|
|
412
421
|
// Both are gone one render later. Measured, this is the whole difference between "the sidebar
|
|
413
|
-
// works once I click over to that conversation" and "it works"
|
|
422
|
+
// works once I click over to that conversation" and "it works" — the page is real either way,
|
|
414
423
|
// and failing the call while the shell is already switching away from it just reported a
|
|
415
424
|
// problem the plugin had already fixed.
|
|
416
425
|
const displayRefusal = (value: Record<string, unknown>): boolean =>
|
|
417
426
|
value.ok !== true
|
|
418
427
|
&& (String(value.code ?? '') === PANEL_NOT_DISPLAYED
|
|
419
428
|
|| String(value.error ?? '').includes('not mounted')
|
|
420
|
-
// Bridges installed before issue #37 send the same refusal with NO code
|
|
429
|
+
// Bridges installed before issue #37 send the same refusal with NO code — the installed copy
|
|
421
430
|
// on this machine is one of them (`panel-not-displayed` appears nowhere in it). Reading only
|
|
422
431
|
// the code therefore turned a retryable display state into a hard failure for exactly the
|
|
423
432
|
// users who had the old bridge, which is the majority until it is reinstalled. The wording
|
|
@@ -428,16 +437,19 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
428
437
|
answer = await ask()
|
|
429
438
|
}
|
|
430
439
|
if (answer.ok !== true) {
|
|
431
|
-
// Reachable only after the retries above have run out, and the code still decides
|
|
440
|
+
// Reachable only after the retries above have run out, and the code still decides — not the
|
|
432
441
|
// wording:
|
|
433
442
|
// panel-not-displayed -> the shell was asked to show the conversation (client half's
|
|
434
443
|
// `openSession`) and did not render it in ~1.6 s: no loss, no swap.
|
|
435
|
-
//
|
|
436
|
-
//
|
|
444
|
+
// A missing guest within a time budget is still initialization, including on old bridges
|
|
445
|
+
// that only returned text. It is not evidence that this shell uses an undrivable iframe.
|
|
437
446
|
const code = String(answer.code ?? '')
|
|
438
447
|
const detail = String(answer.error)
|
|
439
448
|
if (code === PANEL_NOT_DISPLAYED) throw new BrowserPanelNotDisplayedError(detail)
|
|
440
|
-
if (detail.includes('produced no page'))
|
|
449
|
+
if (code === PANEL_INITIALIZING || (code === '' && detail.includes('produced no page'))) {
|
|
450
|
+
throw new BrowserPanelNotDisplayedError(detail, PANEL_INITIALIZING)
|
|
451
|
+
}
|
|
452
|
+
if (code === 'panel-unusable') this.reportLost('panel-unusable')
|
|
441
453
|
throw new Error(`dsh-builtin-browser: sidebar unavailable (${detail})`)
|
|
442
454
|
}
|
|
443
455
|
const id = Number(answer.id)
|
|
@@ -507,16 +519,22 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
507
519
|
* This used to be empty, on the reasoning that the sidebar is already on screen so there is
|
|
508
520
|
* nothing to show. That confused "the sidebar is visible" with "this page is the one being
|
|
509
521
|
* looked at": opening a page left it behind whatever the human had in front, which is issue
|
|
510
|
-
* #23. The other two carriers both do this
|
|
511
|
-
* system browser calls `Page.bringToFront`
|
|
522
|
+
* #23. The other two carriers both do this — the self-hosted window re-adds the view and the
|
|
523
|
+
* system browser calls `Page.bringToFront` — so this carrier was the odd one out.
|
|
512
524
|
*
|
|
513
525
|
* Best-effort by design: the tab strip belongs to the shell's renderer, and failing to raise
|
|
514
526
|
* it must not fail the navigation that has already happened.
|
|
515
527
|
* @param handle - the view to bring forward.
|
|
516
528
|
*/
|
|
517
|
-
showView(handle: ElectronViewHandle): void {
|
|
529
|
+
showView(handle: ElectronViewHandle, _label?: string, options?: { readonly quiet?: boolean }): void {
|
|
530
|
+
// Quiet mode (`ui.quiet`) means "do not take my screen". On this carrier showing a page means
|
|
531
|
+
// asking the shell to switch the displayed conversation — precisely the takeover the switch
|
|
532
|
+
// forbids. So honour it by asking for nothing: a page that is already displayed keeps working,
|
|
533
|
+
// and one that is not fails with the documented display-state error instead of moving the
|
|
534
|
+
// user's view. Measured before this: the setting was on and every call still switched.
|
|
535
|
+
if (options?.quiet === true) return
|
|
518
536
|
// `owner` is required: the bridge refuses to bring forward a guest held by another session.
|
|
519
|
-
// It comes from the view, not the process
|
|
537
|
+
// It comes from the view, not the process — with several conversations live, a process-wide
|
|
520
538
|
// owner would raise the wrong conversation's tab.
|
|
521
539
|
const owner = this.views.get(handle.id)?.owner ?? this.owner
|
|
522
540
|
const guest = this.views.get(handle.id)?.guest
|
|
@@ -539,7 +557,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
539
557
|
*
|
|
540
558
|
* Destroying our own view handles is not enough on this carrier: the sidebar
|
|
541
559
|
* belongs to the shell and would happily keep the page (and its renderer) alive.
|
|
542
|
-
* Closing the tabs is what actually ends the page
|
|
560
|
+
* Closing the tabs is what actually ends the page — and only the page: cookies
|
|
543
561
|
* live in the partition, history on disk, so both survive.
|
|
544
562
|
* @param owner - the conversation whose pages to close. Omit to close every conversation's,
|
|
545
563
|
* which is only correct from a teardown that is itself global.
|
|
@@ -547,7 +565,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
547
565
|
*/
|
|
548
566
|
async releasePage(owner?: string): Promise<void> {
|
|
549
567
|
// Only this conversation's tabs. The host is ONE instance shared by every conversation, so a
|
|
550
|
-
// release that named none would close pages other conversations are still driving
|
|
568
|
+
// release that named none would close pages other conversations are still driving — "every
|
|
551
569
|
// webview currently visible" is precisely what must never be used here.
|
|
552
570
|
const mine: number[] = []
|
|
553
571
|
for (const [viewId, entry] of [...this.views]) {
|
|
@@ -569,7 +587,7 @@ export class DesktopBridgeViewHost implements ElectronBrowserViewHost {
|
|
|
569
587
|
// `owner` is REQUIRED here now that the bridge filters `list` by it. Without it the bridge
|
|
570
588
|
// falls back to a different owner, so the guests this session holds are filtered out of the
|
|
571
589
|
// answer, `mine.includes(...)` matches nothing, the title list comes back empty and this
|
|
572
|
-
// returns without closing anything
|
|
590
|
+
// returns without closing anything — the page stayed open and the human had to close it by
|
|
573
591
|
// hand. Adding the ledger to the bridge without updating this call site is exactly the kind
|
|
574
592
|
// of half-change that made the ownership work take four rounds.
|
|
575
593
|
const answer = await this.connection.call({ op: 'list', owner: owner ?? this.owner }, 5_000)
|