dsh-builtin-browser 0.5.4 → 0.5.6

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +63 -1
  2. package/README.en.md +5 -3
  3. package/README.md +4 -2
  4. package/client.js +300 -4
  5. package/docs/development.md +10 -0
  6. package/docs/user-guide.md +16 -4
  7. package/lib/browser-electron/bridge-connection.d.ts +8 -0
  8. package/lib/browser-electron/bridge-connection.js +8 -0
  9. package/lib/browser-electron/bridge-endpoint.d.ts +30 -0
  10. package/lib/browser-electron/bridge-endpoint.js +123 -0
  11. package/lib/browser-electron/desktop-bridge-host.d.ts +23 -23
  12. package/lib/browser-electron/desktop-bridge-host.js +35 -35
  13. package/lib/browser-electron/electron-provision.d.ts +34 -1
  14. package/lib/browser-electron/electron-provision.js +52 -9
  15. package/lib/browser-electron/entry.js +62 -1
  16. package/lib/browser-electron/json-reply.d.ts +21 -0
  17. package/lib/browser-electron/json-reply.js +17 -0
  18. package/lib/browser-electron/preview-route.js +1 -12
  19. package/lib/browser-electron/remote-host.js +6 -5
  20. package/lib/browser-electron/runtime-route.d.ts +57 -0
  21. package/lib/browser-electron/runtime-route.js +66 -0
  22. package/lib/browser-electron/runtime-status.d.ts +102 -0
  23. package/lib/browser-electron/runtime-status.js +86 -0
  24. package/package.json +2 -2
  25. package/scripts/consumer-install-check.mjs +72 -0
  26. package/scripts/verify-runtime-status.mjs +165 -0
  27. package/src/browser-electron/bridge-connection.ts +9 -0
  28. package/src/browser-electron/bridge-endpoint.ts +139 -0
  29. package/src/browser-electron/desktop-bridge-host.ts +35 -35
  30. package/src/browser-electron/electron-provision.ts +73 -8
  31. package/src/browser-electron/entry.ts +67 -1
  32. package/src/browser-electron/json-reply.ts +32 -0
  33. package/src/browser-electron/preview-route.ts +1 -12
  34. package/src/browser-electron/remote-host.ts +6 -5
  35. package/src/browser-electron/runtime-route.ts +106 -0
  36. package/src/browser-electron/runtime-status.ts +186 -0
@@ -0,0 +1,123 @@
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
+ }
66
+ catch (error) {
67
+ return {
68
+ present: true,
69
+ alive: false,
70
+ detail: `the published endpoint is unreadable: ${String(error)}`,
71
+ };
72
+ }
73
+ const updatedAt = typeof raw.updatedAt === 'string' ? raw.updatedAt : undefined;
74
+ const pid = typeof raw.pid === 'number' ? raw.pid : undefined;
75
+ // A stamp older than the refresh window is a tombstone, not a slow shell (see
76
+ // ENDPOINT_STALE_AFTER_MS). An ABSENT stamp is not expired on purpose: an older bridge never wrote
77
+ // one, and that shell deserves to be checked by its pid instead of being declared gone.
78
+ if (updatedAt !== undefined) {
79
+ const at = Date.parse(updatedAt);
80
+ if (Number.isFinite(at)) {
81
+ const ageMs = now - at;
82
+ if (ageMs > ENDPOINT_STALE_AFTER_MS) {
83
+ return {
84
+ present: true,
85
+ alive: false,
86
+ updatedAt,
87
+ detail: `the published endpoint has not been refreshed for ${Math.round(ageMs / 1000)}s, `
88
+ + 'so the shell that wrote it has most likely exited',
89
+ };
90
+ }
91
+ }
92
+ }
93
+ if (pid !== undefined && !pidAlive(pid)) {
94
+ return {
95
+ present: true,
96
+ alive: false,
97
+ ...updatedAt === undefined ? {} : { updatedAt },
98
+ detail: `the shell that published the endpoint (pid ${pid}) is not running`,
99
+ };
100
+ }
101
+ return {
102
+ present: true,
103
+ alive: true,
104
+ ...updatedAt === undefined ? {} : { updatedAt },
105
+ detail: 'a desktop shell is running and answering on its published endpoint',
106
+ };
107
+ }
108
+ /**
109
+ * The endpoint file's mtime, for diagnostics that want to say "written at".
110
+ *
111
+ * Separate and optional: the readiness report does not need it, and a caller that does can fail
112
+ * without disturbing anything else.
113
+ * @param path - the endpoint file.
114
+ * @returns the mtime as ISO, or undefined.
115
+ */
116
+ export function bridgeEndpointWrittenAt(path = bridgeEndpointPath()) {
117
+ try {
118
+ return statSync(path).mtime.toISOString();
119
+ }
120
+ catch {
121
+ return undefined;
122
+ }
123
+ }
@@ -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 鈥?which is why it self-hosts a whole browser today. The shell, however, can
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 鈥?a fresh shell has no sidebar guest until something asks
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,8 +32,8 @@ 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 鈥?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.
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
39
  readonly code = "panel-not-displayed";
@@ -47,7 +47,7 @@ export declare class BrowserPanelNotDisplayedError extends Error {
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 鈥?the
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 {
@@ -56,7 +56,7 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
56
56
  * One entry per view this host handed out: the conversation it serves, and the guest backing it.
57
57
  *
58
58
  * The conversation belongs to the ENTRY, not to this host. A single plugin process serves every
59
- * conversation 鈥?DSH runs them all through one host instance 鈥?so an owner held on the host
59
+ * conversation — DSH runs them all through one host instance — so an owner held on the host
60
60
  * would be one conversation's id applied to all of them, and a page could still land in
61
61
  * another's sidebar however carefully the bridge checked it.
62
62
  */
@@ -66,7 +66,7 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
66
66
  *
67
67
  * Every DSH session is its own plugin process, and the sidebar is one surface they all share.
68
68
  * A session can only see its own `views` map, so before the bridge kept a ledger it adopted
69
- * whichever tab it found 鈥?including one another session had opened, which is how a URL from
69
+ * whichever tab it found — including one another session had opened, which is how a URL from
70
70
  * one session appeared in another's sidebar. The id is per process, so two sessions never
71
71
  * collide and one session's tabs are never handed to another; it is deliberately not the DSH
72
72
  * session id, which this layer has no access to and does not need.
@@ -74,17 +74,17 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
74
74
  * The whole ledger rests on that premise, so it was measured rather than assumed: with two
75
75
  * sessions running, the desktop had TWO host processes (plus one main, two renderers and a
76
76
  * 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 鈥?so a change to how DSH spawns
77
+ * compare equal and the bleed would return in a new shape — so a change to how DSH spawns
78
78
  * sessions invalidates this file, not just this comment.
79
79
  *
80
80
  * It is now the CONVERSATION id rather than an invented uuid, read from the plugin's ctx by the
81
81
  * same path DSH's own desktop host uses. That matters because the shell keeps one sidebar per
82
82
  * conversation and writes its session id onto each sidebar container (on the React fiber,
83
- * measured on the running app) 鈥?so the bridge can only answer "is this sidebar mine" if it has
83
+ * measured on the running app) — so the bridge can only answer "is this sidebar mine" if it has
84
84
  * a comparable id. With an invented uuid it never could, which is how a command came to be typed
85
85
  * into another conversation's address bar.
86
86
  *
87
- * Falls back to a random uuid when the host cannot supply one 鈥?an older DSH, or a non-desktop
87
+ * Falls back to a random uuid when the host cannot supply one — an older DSH, or a non-desktop
88
88
  * composition. That is no worse than before: the bridge then knows only "this process", and it
89
89
  * refuses to operate on a sidebar it cannot prove is its own.
90
90
  */
@@ -94,7 +94,7 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
94
94
  * conversation each belongs to.
95
95
  *
96
96
  * The provider destroys its view handles before it asks for a release, so the mapping is dropped
97
- * by then 鈥?keeping the guest ids here is what lets us close only our own tabs when several
97
+ * by then — keeping the guest ids here is what lets us close only our own tabs when several
98
98
  * conversations are running (requirements 搂4: each session gets its own page). The owner rides
99
99
  * along for the same reason it does in {@link views}: a release names one conversation.
100
100
  */
@@ -107,7 +107,7 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
107
107
  * handler is stored anyway so the interface contract holds (a caller may register
108
108
  * one and must not be surprised) and so a future bridge operation can deliver it
109
109
  * without changing the provider. Consequently no user-action event is emitted while
110
- * the desktop sidebar is the carrier 鈥?by design, not by omission.
110
+ * the desktop sidebar is the carrier — by design, not by omission.
111
111
  */
112
112
  private userActionHandler;
113
113
  /** Told when the shell behind this bridge exits; see `onLost`. */
@@ -151,8 +151,8 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
151
151
  * Every page this conversation's sidebar panel currently holds.
152
152
  *
153
153
  * 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 鈥?they are what the human sees
155
- * 鈥?but without this the tab model reports only the ones the provider created, so the rest are
154
+ * new page, and nothing tells the provider. Those pages are real — they are what the human sees
155
+ * — but without this the tab model reports only the ones the provider created, so the rest are
156
156
  * invisible to `dsh_browser_list_tabs` and unclosable through `dsh_browser_close_tab`.
157
157
  *
158
158
  * The bridge's `list` already answers with the sidebar guests, which is the same information, so
@@ -163,14 +163,14 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
163
163
  * Every sidebar page this conversation holds that THIS HOST did not open.
164
164
  *
165
165
  * 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 鈥?they are what the human sees
167
- * 鈥?but without this the tab model reports only the ones the provider created, so the rest are
166
+ * new page, and nothing tells the provider. Those pages are real — they are what the human sees
167
+ * — but without this the tab model reports only the ones the provider created, so the rest are
168
168
  * invisible to `dsh_browser_list_tabs` and unclosable through `dsh_browser_close_tab`.
169
169
  *
170
170
  * Pages this host opened are EXCLUDED here rather than deduplicated by the caller, because the
171
171
  * caller cannot do it: the provider knows a tab by its own id and the carrier knows a page by the
172
172
  * 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 鈥?the mapping that makes the match
173
+ * caller to filter, which reported the same page twice — the mapping that makes the match
174
174
  * possible exists only here.
175
175
  * @returns the panel's pages that are not ours, or an empty list when the bridge cannot answer.
176
176
  */
@@ -178,7 +178,7 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
178
178
  /**
179
179
  * Close one sidebar page by the id {@link listPages} reported.
180
180
  *
181
- * The bridge closes sidebar pages by TITLE, and only the ones the caller owns 鈥?that is what
181
+ * The bridge closes sidebar pages by TITLE, and only the ones the caller owns — that is what
182
182
  * stopped one conversation's teardown from destroying another's page. So the title is looked up
183
183
  * through the same listing, and a page that no longer appears is treated as already gone rather
184
184
  * than as an error: the caller asked for it to be closed, and it is.
@@ -188,8 +188,8 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
188
188
  /**
189
189
  * The guest backing a view, materialized on first use.
190
190
  *
191
- * The conversation that called owns exactly one sidebar page on this carrier 鈥?a human and the
192
- * agent look at the same page 鈥?so every view resolves to that conversation's own guest, and the
191
+ * The conversation that called owns exactly one sidebar page on this carrier — a human and the
192
+ * agent look at the same page — so every view resolves to that conversation's own guest, and the
193
193
  * page does not multiply behind the provider's own tab bookkeeping.
194
194
  *
195
195
  * A cached guest is used as-is: probing it first cost a round-trip on every command, so liveness
@@ -210,8 +210,8 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
210
210
  * This used to be empty, on the reasoning that the sidebar is already on screen so there is
211
211
  * nothing to show. That confused "the sidebar is visible" with "this page is the one being
212
212
  * 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 鈥?the self-hosted window re-adds the view and the
214
- * system browser calls `Page.bringToFront` 鈥?so this carrier was the odd one out.
213
+ * #23. The other two carriers both do this — the self-hosted window re-adds the view and the
214
+ * system browser calls `Page.bringToFront` — so this carrier was the odd one out.
215
215
  *
216
216
  * Best-effort by design: the tab strip belongs to the shell's renderer, and failing to raise
217
217
  * it must not fail the navigation that has already happened.
@@ -224,7 +224,7 @@ export declare class DesktopBridgeViewHost implements ElectronBrowserViewHost {
224
224
  *
225
225
  * Destroying our own view handles is not enough on this carrier: the sidebar
226
226
  * belongs to the shell and would happily keep the page (and its renderer) alive.
227
- * Closing the tabs is what actually ends the page 鈥?and only the page: cookies
227
+ * Closing the tabs is what actually ends the page — and only the page: cookies
228
228
  * live in the partition, history on disk, so both survive.
229
229
  * @param owner - the conversation whose pages to close. Omit to close every conversation's,
230
230
  * which is only correct from a teardown that is itself global.
@@ -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 鈥?which is why it self-hosts a whole browser today. The shell, however, can
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 鈥?a fresh shell has no sidebar guest until something asks
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
@@ -39,7 +39,7 @@ export function bridgeEndpointPath() {
39
39
  * A display state, not a dead carrier. It must never reach `reportLost`, and it must never be
40
40
  * retried as though a guest had vanished: retrying cannot attach a webview the shell has not
41
41
  * rendered, and treating it as loss swapped the surface to a fresh self-hosted window whose page was
42
- * blank 鈥?losing the page the user had open.
42
+ * blank — losing the page the user had open.
43
43
  */
44
44
  const PANEL_NOT_DISPLAYED = 'panel-not-displayed';
45
45
  /**
@@ -58,8 +58,8 @@ const PANEL_DISPLAY_RETRY_MS = 400;
58
58
  *
59
59
  * Thrown instead of a plain Error so callers can distinguish "the panel did not render" from "the
60
60
  * browser broke", which is exactly the distinction issue #37 says was missing. The plugin no longer
61
- * waits for a human to show the conversation 鈥?the client half asks the shell to (`openSession`) and
62
- * this host retries while it renders 鈥?so reaching here means the shell did not render it at all.
61
+ * waits for a human to show the conversation — the client half asks the shell to (`openSession`) and
62
+ * this host retries while it renders — so reaching here means the shell did not render it at all.
63
63
  */
64
64
  export class BrowserPanelNotDisplayedError extends Error {
65
65
  code = PANEL_NOT_DISPLAYED;
@@ -67,7 +67,7 @@ export class BrowserPanelNotDisplayedError extends Error {
67
67
  * @param detail - the bridge's own explanation, appended so the message says why.
68
68
  */
69
69
  constructor(detail) {
70
- super('dsh-builtin-browser: this conversation\'s sidebar page did not attach 鈥?the shell was asked to '
70
+ super('dsh-builtin-browser: this conversation\'s sidebar page did not attach — the shell was asked to '
71
71
  + 'show this conversation and its panel still did not render. Nothing was lost, and the page '
72
72
  + 'appears as soon as the panel mounts. '
73
73
  + `(${detail})`);
@@ -87,7 +87,7 @@ function isGuestGone(error) {
87
87
  return false;
88
88
  const message = error instanceof Error ? error.message : String(error);
89
89
  // The panel path reports its own failure when the renderer never produced a page, and that is the
90
- // same class as a vanished guest 鈥?worth one retry on a fresh panel 鈥?so it is listed here too.
90
+ // same class as a vanished guest — worth one retry on a fresh panel — so it is listed here too.
91
91
  return /guest \d+ is not available|sidebar unavailable|produced no page/i.test(message);
92
92
  }
93
93
  /**
@@ -95,7 +95,7 @@ function isGuestGone(error) {
95
95
  *
96
96
  * One sidebar exists per shell window, so every view this host hands out refers
97
97
  * to the same guest: the provider keeps its tab bookkeeping, and the tabs simply
98
- * share the visible page. That is the intended behaviour for this carrier 鈥?the
98
+ * share the visible page. That is the intended behaviour for this carrier — the
99
99
  * point is a single page both parties can see.
100
100
  */
101
101
  export class DesktopBridgeViewHost {
@@ -104,7 +104,7 @@ export class DesktopBridgeViewHost {
104
104
  * One entry per view this host handed out: the conversation it serves, and the guest backing it.
105
105
  *
106
106
  * The conversation belongs to the ENTRY, not to this host. A single plugin process serves every
107
- * conversation 鈥?DSH runs them all through one host instance 鈥?so an owner held on the host
107
+ * conversation — DSH runs them all through one host instance — so an owner held on the host
108
108
  * would be one conversation's id applied to all of them, and a page could still land in
109
109
  * another's sidebar however carefully the bridge checked it.
110
110
  */
@@ -114,7 +114,7 @@ export class DesktopBridgeViewHost {
114
114
  *
115
115
  * Every DSH session is its own plugin process, and the sidebar is one surface they all share.
116
116
  * A session can only see its own `views` map, so before the bridge kept a ledger it adopted
117
- * whichever tab it found 鈥?including one another session had opened, which is how a URL from
117
+ * whichever tab it found — including one another session had opened, which is how a URL from
118
118
  * one session appeared in another's sidebar. The id is per process, so two sessions never
119
119
  * collide and one session's tabs are never handed to another; it is deliberately not the DSH
120
120
  * session id, which this layer has no access to and does not need.
@@ -122,17 +122,17 @@ export class DesktopBridgeViewHost {
122
122
  * The whole ledger rests on that premise, so it was measured rather than assumed: with two
123
123
  * sessions running, the desktop had TWO host processes (plus one main, two renderers and a
124
124
  * gpu/utility pair). If sessions ever shared a process, every owner check in the bridge would
125
- * compare equal and the bleed would return in a new shape 鈥?so a change to how DSH spawns
125
+ * compare equal and the bleed would return in a new shape — so a change to how DSH spawns
126
126
  * sessions invalidates this file, not just this comment.
127
127
  *
128
128
  * It is now the CONVERSATION id rather than an invented uuid, read from the plugin's ctx by the
129
129
  * same path DSH's own desktop host uses. That matters because the shell keeps one sidebar per
130
130
  * conversation and writes its session id onto each sidebar container (on the React fiber,
131
- * measured on the running app) 鈥?so the bridge can only answer "is this sidebar mine" if it has
131
+ * measured on the running app) — so the bridge can only answer "is this sidebar mine" if it has
132
132
  * a comparable id. With an invented uuid it never could, which is how a command came to be typed
133
133
  * into another conversation's address bar.
134
134
  *
135
- * Falls back to a random uuid when the host cannot supply one 鈥?an older DSH, or a non-desktop
135
+ * Falls back to a random uuid when the host cannot supply one — an older DSH, or a non-desktop
136
136
  * composition. That is no worse than before: the bridge then knows only "this process", and it
137
137
  * refuses to operate on a sidebar it cannot prove is its own.
138
138
  */
@@ -142,7 +142,7 @@ export class DesktopBridgeViewHost {
142
142
  * conversation each belongs to.
143
143
  *
144
144
  * The provider destroys its view handles before it asks for a release, so the mapping is dropped
145
- * by then 鈥?keeping the guest ids here is what lets us close only our own tabs when several
145
+ * by then — keeping the guest ids here is what lets us close only our own tabs when several
146
146
  * conversations are running (requirements 搂4: each session gets its own page). The owner rides
147
147
  * along for the same reason it does in {@link views}: a release names one conversation.
148
148
  */
@@ -155,7 +155,7 @@ export class DesktopBridgeViewHost {
155
155
  * handler is stored anyway so the interface contract holds (a caller may register
156
156
  * one and must not be surprised) and so a future bridge operation can deliver it
157
157
  * without changing the provider. Consequently no user-action event is emitted while
158
- * the desktop sidebar is the carrier 鈥?by design, not by omission.
158
+ * the desktop sidebar is the carrier — by design, not by omission.
159
159
  */
160
160
  userActionHandler;
161
161
  /** Told when the shell behind this bridge exits; see `onLost`. */
@@ -219,7 +219,7 @@ export class DesktopBridgeViewHost {
219
219
  //
220
220
  // The sidebar browser renders as a <webview> only where the shell exposes
221
221
  // `dshDesktop.browser` and enables `webviewTag`. Where it renders as an <iframe> there is
222
- // no webContents, no `getWebContentsId()` and no CDP endpoint 鈥?and every tool here is
222
+ // no webContents, no `getWebContentsId()` and no CDP endpoint — and every tool here is
223
223
  // built on CDP, so adopting it means failing every call, with no path back to a carrier
224
224
  // that works. Reported on DSH Desktop 2.0.17 with both conditions measured.
225
225
  //
@@ -264,8 +264,8 @@ export class DesktopBridgeViewHost {
264
264
  * Every page this conversation's sidebar panel currently holds.
265
265
  *
266
266
  * The shell owns page creation inside the panel: a link the user or the agent clicks may open a
267
- * new page, and nothing tells the provider. Those pages are real 鈥?they are what the human sees
268
- * 鈥?but without this the tab model reports only the ones the provider created, so the rest are
267
+ * new page, and nothing tells the provider. Those pages are real — they are what the human sees
268
+ * — but without this the tab model reports only the ones the provider created, so the rest are
269
269
  * invisible to `dsh_browser_list_tabs` and unclosable through `dsh_browser_close_tab`.
270
270
  *
271
271
  * The bridge's `list` already answers with the sidebar guests, which is the same information, so
@@ -276,14 +276,14 @@ export class DesktopBridgeViewHost {
276
276
  * Every sidebar page this conversation holds that THIS HOST did not open.
277
277
  *
278
278
  * The shell owns page creation inside the panel: a link the user or the agent clicks may open a
279
- * new page, and nothing tells the provider. Those pages are real 鈥?they are what the human sees
280
- * 鈥?but without this the tab model reports only the ones the provider created, so the rest are
279
+ * new page, and nothing tells the provider. Those pages are real — they are what the human sees
280
+ * — but without this the tab model reports only the ones the provider created, so the rest are
281
281
  * invisible to `dsh_browser_list_tabs` and unclosable through `dsh_browser_close_tab`.
282
282
  *
283
283
  * Pages this host opened are EXCLUDED here rather than deduplicated by the caller, because the
284
284
  * caller cannot do it: the provider knows a tab by its own id and the carrier knows a page by the
285
285
  * guest id, and the two never match. The first version returned everything and relied on the
286
- * caller to filter, which reported the same page twice 鈥?the mapping that makes the match
286
+ * caller to filter, which reported the same page twice — the mapping that makes the match
287
287
  * possible exists only here.
288
288
  * @returns the panel's pages that are not ours, or an empty list when the bridge cannot answer.
289
289
  */
@@ -308,7 +308,7 @@ export class DesktopBridgeViewHost {
308
308
  /**
309
309
  * Close one sidebar page by the id {@link listPages} reported.
310
310
  *
311
- * The bridge closes sidebar pages by TITLE, and only the ones the caller owns 鈥?that is what
311
+ * The bridge closes sidebar pages by TITLE, and only the ones the caller owns — that is what
312
312
  * stopped one conversation's teardown from destroying another's page. So the title is looked up
313
313
  * through the same listing, and a page that no longer appears is treated as already gone rather
314
314
  * than as an error: the caller asked for it to be closed, and it is.
@@ -326,8 +326,8 @@ export class DesktopBridgeViewHost {
326
326
  /**
327
327
  * The guest backing a view, materialized on first use.
328
328
  *
329
- * The conversation that called owns exactly one sidebar page on this carrier 鈥?a human and the
330
- * agent look at the same page 鈥?so every view resolves to that conversation's own guest, and the
329
+ * The conversation that called owns exactly one sidebar page on this carrier — a human and the
330
+ * agent look at the same page — so every view resolves to that conversation's own guest, and the
331
331
  * page does not multiply behind the provider's own tab bookkeeping.
332
332
  *
333
333
  * A cached guest is used as-is: probing it first cost a round-trip on every command, so liveness
@@ -342,7 +342,7 @@ export class DesktopBridgeViewHost {
342
342
  // and `createView`'s sendCommand then discards the cache and calls back in here.
343
343
  if (entry?.guest !== undefined)
344
344
  return entry.guest;
345
- // The conversation THIS VIEW serves 鈥?read from the view, never from the process.
345
+ // The conversation THIS VIEW serves — read from the view, never from the process.
346
346
  //
347
347
  // The difference is the whole bug. This host is one instance shared by every conversation, so
348
348
  // `this.owner` alone can only be "whichever conversation this process happens to name", and
@@ -355,7 +355,7 @@ export class DesktopBridgeViewHost {
355
355
  // shortcut or clicking its card, both of which the shell delivers to whatever it displays.
356
356
  const owner = entry?.owner ?? this.owner;
357
357
  // A command that must not present anything (issue #46: the live preview) takes a read-only path.
358
- // 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
358
+ // 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
359
  // and wrong for "let me look at it". A page that is not on screen therefore reports as a display
360
360
  // state, and the preview route turns that into the panel's paused state.
361
361
  if (options?.present === false) {
@@ -393,13 +393,13 @@ export class DesktopBridgeViewHost {
393
393
  // panel-not-displayed - the conversation exists but is not the one on screen;
394
394
  // "is not mounted" - its surface store was not minted when the tab was placed.
395
395
  // Both are gone one render later. Measured, this is the whole difference between "the sidebar
396
- // works once I click over to that conversation" and "it works" 鈥?the page is real either way,
396
+ // works once I click over to that conversation" and "it works" — the page is real either way,
397
397
  // and failing the call while the shell is already switching away from it just reported a
398
398
  // problem the plugin had already fixed.
399
399
  const displayRefusal = (value) => value.ok !== true
400
400
  && (String(value.code ?? '') === PANEL_NOT_DISPLAYED
401
401
  || String(value.error ?? '').includes('not mounted')
402
- // Bridges installed before issue #37 send the same refusal with NO code 鈥?the installed copy
402
+ // Bridges installed before issue #37 send the same refusal with NO code — the installed copy
403
403
  // on this machine is one of them (`panel-not-displayed` appears nowhere in it). Reading only
404
404
  // the code therefore turned a retryable display state into a hard failure for exactly the
405
405
  // users who had the old bridge, which is the majority until it is reinstalled. The wording
@@ -410,7 +410,7 @@ export class DesktopBridgeViewHost {
410
410
  answer = await ask();
411
411
  }
412
412
  if (answer.ok !== true) {
413
- // Reachable only after the retries above have run out, and the code still decides 鈥?not the
413
+ // Reachable only after the retries above have run out, and the code still decides — not the
414
414
  // wording:
415
415
  // panel-not-displayed -> the shell was asked to show the conversation (client half's
416
416
  // `openSession`) and did not render it in ~1.6 s: no loss, no swap.
@@ -492,8 +492,8 @@ export class DesktopBridgeViewHost {
492
492
  * This used to be empty, on the reasoning that the sidebar is already on screen so there is
493
493
  * nothing to show. That confused "the sidebar is visible" with "this page is the one being
494
494
  * looked at": opening a page left it behind whatever the human had in front, which is issue
495
- * #23. The other two carriers both do this 鈥?the self-hosted window re-adds the view and the
496
- * system browser calls `Page.bringToFront` 鈥?so this carrier was the odd one out.
495
+ * #23. The other two carriers both do this — the self-hosted window re-adds the view and the
496
+ * system browser calls `Page.bringToFront` — so this carrier was the odd one out.
497
497
  *
498
498
  * Best-effort by design: the tab strip belongs to the shell's renderer, and failing to raise
499
499
  * it must not fail the navigation that has already happened.
@@ -501,7 +501,7 @@ export class DesktopBridgeViewHost {
501
501
  */
502
502
  showView(handle) {
503
503
  // `owner` is required: the bridge refuses to bring forward a guest held by another session.
504
- // It comes from the view, not the process 鈥?with several conversations live, a process-wide
504
+ // It comes from the view, not the process — with several conversations live, a process-wide
505
505
  // owner would raise the wrong conversation's tab.
506
506
  const owner = this.views.get(handle.id)?.owner ?? this.owner;
507
507
  const guest = this.views.get(handle.id)?.guest;
@@ -519,7 +519,7 @@ export class DesktopBridgeViewHost {
519
519
  *
520
520
  * Destroying our own view handles is not enough on this carrier: the sidebar
521
521
  * belongs to the shell and would happily keep the page (and its renderer) alive.
522
- * Closing the tabs is what actually ends the page 鈥?and only the page: cookies
522
+ * Closing the tabs is what actually ends the page — and only the page: cookies
523
523
  * live in the partition, history on disk, so both survive.
524
524
  * @param owner - the conversation whose pages to close. Omit to close every conversation's,
525
525
  * which is only correct from a teardown that is itself global.
@@ -527,7 +527,7 @@ export class DesktopBridgeViewHost {
527
527
  */
528
528
  async releasePage(owner) {
529
529
  // Only this conversation's tabs. The host is ONE instance shared by every conversation, so a
530
- // release that named none would close pages other conversations are still driving 鈥?"every
530
+ // release that named none would close pages other conversations are still driving — "every
531
531
  // webview currently visible" is precisely what must never be used here.
532
532
  const mine = [];
533
533
  for (const [viewId, entry] of [...this.views]) {
@@ -553,7 +553,7 @@ export class DesktopBridgeViewHost {
553
553
  // `owner` is REQUIRED here now that the bridge filters `list` by it. Without it the bridge
554
554
  // falls back to a different owner, so the guests this session holds are filtered out of the
555
555
  // answer, `mine.includes(...)` matches nothing, the title list comes back empty and this
556
- // returns without closing anything 鈥?the page stayed open and the human had to close it by
556
+ // returns without closing anything — the page stayed open and the human had to close it by
557
557
  // hand. Adding the ledger to the bridge without updating this call site is exactly the kind
558
558
  // of half-change that made the ownership work take four rounds.
559
559
  const answer = await this.connection.call({ op: 'list', owner: owner ?? this.owner }, 5_000);
@@ -7,6 +7,30 @@ export interface ProvisionResult {
7
7
  /** One line for the log; never contains a stack trace a user has to decode. */
8
8
  readonly detail: string;
9
9
  }
10
+ /**
11
+ * The state a settings panel shows, which is one state wider than {@link ProvisionResult}.
12
+ *
13
+ * `idle` and `preparing` are the two a log line never needs and a user always does: "nothing has
14
+ * been asked for yet" and "a ~100 MB download is running right now" are the states in which a first
15
+ * browser call is slow, and until this existed neither was visible anywhere in the product — the
16
+ * only trace was a log line the panel cannot read.
17
+ */
18
+ export interface ProvisionSnapshot {
19
+ /** `idle` and `preparing` are provisional; the rest are terminal for this attempt. */
20
+ readonly state: 'idle' | 'preparing' | 'present' | 'ready' | 'skipped' | 'failed';
21
+ /** One line, already user-facing: never a stack trace. */
22
+ readonly detail: string;
23
+ /** When the state last changed, ISO. */
24
+ readonly at: string;
25
+ }
26
+ /**
27
+ * The current provisioning state, for a readiness report.
28
+ *
29
+ * Deliberately a snapshot rather than a promise: a panel polling this must be able to answer in one
30
+ * synchronous read, without awaiting (and thereby echoing) the download it is reporting on.
31
+ * @returns the last state written, or the idle state before anything ran.
32
+ */
33
+ export declare function provisionSnapshot(): ProvisionSnapshot;
10
34
  /** Everything this module touches from the outside, so a test can drive it without Electron. */
11
35
  export interface ProvisionDeps {
12
36
  /** Whether a spawnable binary already exists. */
@@ -50,10 +74,19 @@ export declare function ensureElectronRuntime(deps?: ProvisionDeps): Promise<Pro
50
74
  *
51
75
  * Returns immediately with the shared promise, so a caller that does not care can ignore it and one
52
76
  * that does can await it — the returned promise never rejects.
77
+ *
78
+ * `force` is the second half of the settings panel's retry button. Without it the memoised attempt
79
+ * made a failed download permanent for the life of the process: the panel could offer a button, the
80
+ * button could call this, and the answer would be the failure it was trying to replace. An attempt
81
+ * still IN FLIGHT is always joined, never restarted — two downloads into one directory is the one
82
+ * outcome worth refusing.
53
83
  * @param log - where the outcome goes.
54
84
  * @param deps - the effects; defaulted to this process's, overridable so a test can drive it.
85
+ * @param options - `force` discards a settled attempt so a new one may start.
55
86
  * @returns the shared attempt.
56
87
  */
57
- export declare function provisionElectronInBackground(log: (message: string) => void, deps?: ProvisionDeps): Promise<ProvisionResult>;
88
+ export declare function provisionElectronInBackground(log: (message: string) => void, deps?: ProvisionDeps, options?: {
89
+ readonly force?: boolean;
90
+ }): Promise<ProvisionResult>;
58
91
  /** Forget the attempt. Tests only: a real process provisions at most once. */
59
92
  export declare function resetProvisionStateForTest(): void;