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.
Files changed (77) hide show
  1. package/CHANGELOG.md +143 -1
  2. package/README.en.md +67 -97
  3. package/README.md +67 -98
  4. package/client.js +618 -263
  5. package/desktop-bridge/install.mjs +122 -33
  6. package/desktop-bridge/plugin-browser-bridge.js +9 -4
  7. package/docs/development.md +10 -0
  8. package/docs/tool-reference.md +20 -1
  9. package/docs/user-guide.md +16 -4
  10. package/lib/browser/runtime.d.ts +3 -1
  11. package/lib/browser/runtime.js +9 -0
  12. package/lib/browser/types.d.ts +42 -0
  13. package/lib/browser-electron/authenticated-route.d.ts +27 -0
  14. package/lib/browser-electron/authenticated-route.js +39 -0
  15. package/lib/browser-electron/bridge-connection.d.ts +8 -0
  16. package/lib/browser-electron/bridge-connection.js +8 -0
  17. package/lib/browser-electron/bridge-endpoint.d.ts +30 -0
  18. package/lib/browser-electron/bridge-endpoint.js +130 -0
  19. package/lib/browser-electron/bridge-install.d.ts +48 -0
  20. package/lib/browser-electron/bridge-install.js +98 -0
  21. package/lib/browser-electron/bridge-status.js +21 -2
  22. package/lib/browser-electron/desktop-bridge-host.d.ts +30 -27
  23. package/lib/browser-electron/desktop-bridge-host.js +71 -50
  24. package/lib/browser-electron/electron-provision.d.ts +35 -2
  25. package/lib/browser-electron/electron-provision.js +83 -20
  26. package/lib/browser-electron/entry.js +144 -7
  27. package/lib/browser-electron/host-main.js +48 -27
  28. package/lib/browser-electron/json-reply.d.ts +21 -0
  29. package/lib/browser-electron/json-reply.js +17 -0
  30. package/lib/browser-electron/preview-route.js +1 -12
  31. package/lib/browser-electron/provider.d.ts +9 -2
  32. package/lib/browser-electron/provider.js +76 -6
  33. package/lib/browser-electron/remote-host.js +10 -9
  34. package/lib/browser-electron/runtime-route.d.ts +55 -0
  35. package/lib/browser-electron/runtime-route.js +66 -0
  36. package/lib/browser-electron/runtime-status.d.ts +102 -0
  37. package/lib/browser-electron/runtime-status.js +88 -0
  38. package/lib/browser-electron/settings-route.d.ts +5 -18
  39. package/lib/browser-electron/settings-route.js +4 -14
  40. package/lib/browser-electron/settings-store.d.ts +17 -0
  41. package/lib/browser-electron/settings-store.js +24 -0
  42. package/lib/browser-electron/system-browser.d.ts +5 -2
  43. package/lib/browser-electron/system-browser.js +12 -4
  44. package/lib/tool-browser/index.js +1041 -4
  45. package/lib/tool-browser/page-probe.d.ts +86 -0
  46. package/lib/tool-browser/page-probe.js +460 -0
  47. package/package.json +5 -3
  48. package/scripts/consumer-install-check.mjs +72 -0
  49. package/scripts/verify-runtime-status.mjs +179 -0
  50. package/skills/dsh-builtin-browser/SKILL.md +64 -0
  51. package/skills/dsh-builtin-browser/references/batch.md +23 -0
  52. package/skills/dsh-builtin-browser/references/deliver.md +31 -0
  53. package/skills/dsh-builtin-browser/references/locate.md +11 -0
  54. package/skills/dsh-builtin-browser/references/recover.md +11 -0
  55. package/skills/dsh-builtin-browser/references/verify.md +13 -0
  56. package/src/browser/runtime.ts +11 -0
  57. package/src/browser/types.ts +19 -0
  58. package/src/browser-electron/authenticated-route.ts +56 -0
  59. package/src/browser-electron/bridge-connection.ts +9 -0
  60. package/src/browser-electron/bridge-endpoint.ts +146 -0
  61. package/src/browser-electron/bridge-install.ts +122 -0
  62. package/src/browser-electron/bridge-status.ts +22 -2
  63. package/src/browser-electron/desktop-bridge-host.ts +68 -50
  64. package/src/browser-electron/electron-provision.ts +103 -20
  65. package/src/browser-electron/entry.ts +141 -7
  66. package/src/browser-electron/host-main.ts +41 -22
  67. package/src/browser-electron/json-reply.ts +32 -0
  68. package/src/browser-electron/preview-route.ts +1 -12
  69. package/src/browser-electron/provider.ts +90 -6
  70. package/src/browser-electron/remote-host.ts +10 -9
  71. package/src/browser-electron/runtime-route.ts +104 -0
  72. package/src/browser-electron/runtime-status.ts +188 -0
  73. package/src/browser-electron/settings-route.ts +9 -32
  74. package/src/browser-electron/settings-store.ts +39 -0
  75. package/src/browser-electron/system-browser.ts +9 -3
  76. package/src/tool-browser/index.ts +991 -7
  77. package/src/tool-browser/page-probe.ts +474 -0
@@ -0,0 +1,55 @@
1
+ /**
2
+ * The readiness endpoints the settings panel reads.
3
+ *
4
+ * The host authenticates both routes with its signed browser-session cookie. The read returns
5
+ * readiness, while a POST starts runtime preparation and also passes the settings write-origin
6
+ * checks.
7
+ *
8
+ * Both answer with the whole report rather than a delta: the panel replaces what it shows with what
9
+ * it is told, so a stale poll can never leave a wrong state on screen.
10
+ * @module dsh-browser/browser-electron/runtime-route
11
+ */
12
+ import type { IncomingMessage, ServerResponse } from 'node:http';
13
+ import type { ProvisionSnapshot } from './electron-provision.js';
14
+ import type { RuntimeStatusReport } from './runtime-status.js';
15
+ /** Where the panel reads readiness. */
16
+ export declare const RUNTIME_STATUS_ROUTE = "/dsh-builtin-browser/runtime-status";
17
+ /**
18
+ * Where the panel asks for the bundled runtime.
19
+ *
20
+ * Non-blocking by design: it starts (or joins) the one background attempt and answers immediately
21
+ * with the state that attempt is in, which is `preparing`. A request that waited for the download
22
+ * would time out in the browser long before a slow network finished, and would hold a connection
23
+ * open for something the panel can poll instead.
24
+ */
25
+ export declare const RUNTIME_PROVISION_ROUTE = "/dsh-builtin-browser/runtime-provision";
26
+ /** What both handlers need. */
27
+ export interface RuntimeRouteDeps {
28
+ /** The current report; a cheap read, never a spawn. */
29
+ readonly report: () => RuntimeStatusReport;
30
+ /**
31
+ * Start (or join) a provision and return the state it is in now.
32
+ *
33
+ * Must not throw: a failure belongs in the report as a 200 with a `failed` state, because a user
34
+ * looking at a panel needs to read the reason, not an HTTP status.
35
+ */
36
+ readonly provision: () => ProvisionSnapshot;
37
+ }
38
+ /**
39
+ * Read readiness: `{ ok, runtime }`.
40
+ * @param request - the incoming request.
41
+ * @param response - the response to write.
42
+ * @param deps - the readers.
43
+ */
44
+ export declare function handleRuntimeStatus(request: IncomingMessage, response: ServerResponse, deps: RuntimeRouteDeps): Promise<void>;
45
+ /**
46
+ * Start (or join) a provision, then answer with the state it is in.
47
+ *
48
+ * Always 200 once admitted, whatever happened: the state carries `failed` with its reason, and a
49
+ * panel that had to distinguish 4xx from 5xx to say "the download failed" would show a network
50
+ * error where the user needs the sentence explaining it.
51
+ * @param request - the incoming request.
52
+ * @param response - the response to write.
53
+ * @param deps - the readers.
54
+ */
55
+ export declare function handleRuntimeProvision(request: IncomingMessage, response: ServerResponse, deps: RuntimeRouteDeps): Promise<void>;
@@ -0,0 +1,66 @@
1
+ import { replyJson } from './json-reply.js';
2
+ import { sameOrigin } from './settings-route.js';
3
+ /** Where the panel reads readiness. */
4
+ export const RUNTIME_STATUS_ROUTE = '/dsh-builtin-browser/runtime-status';
5
+ /**
6
+ * Where the panel asks for the bundled runtime.
7
+ *
8
+ * Non-blocking by design: it starts (or joins) the one background attempt and answers immediately
9
+ * with the state that attempt is in, which is `preparing`. A request that waited for the download
10
+ * would time out in the browser long before a slow network finished, and would hold a connection
11
+ * open for something the panel can poll instead.
12
+ */
13
+ export const RUNTIME_PROVISION_ROUTE = '/dsh-builtin-browser/runtime-provision';
14
+ /**
15
+ * Read readiness: `{ ok, runtime }`.
16
+ * @param request - the incoming request.
17
+ * @param response - the response to write.
18
+ * @param deps - the readers.
19
+ */
20
+ export async function handleRuntimeStatus(request, response, deps) {
21
+ if (request.method !== 'GET') {
22
+ replyJson(response, 405, { error: 'method-not-allowed' });
23
+ return;
24
+ }
25
+ if (!sameOrigin(request)) {
26
+ replyJson(response, 403, { error: 'not-same-origin' });
27
+ return;
28
+ }
29
+ replyJson(response, 200, { ok: true, runtime: deps.report() });
30
+ }
31
+ /**
32
+ * Start (or join) a provision, then answer with the state it is in.
33
+ *
34
+ * Always 200 once admitted, whatever happened: the state carries `failed` with its reason, and a
35
+ * panel that had to distinguish 4xx from 5xx to say "the download failed" would show a network
36
+ * error where the user needs the sentence explaining it.
37
+ * @param request - the incoming request.
38
+ * @param response - the response to write.
39
+ * @param deps - the readers.
40
+ */
41
+ export async function handleRuntimeProvision(request, response, deps) {
42
+ if (request.method !== 'POST') {
43
+ replyJson(response, 405, { error: 'method-not-allowed' });
44
+ return;
45
+ }
46
+ // `true`: starting a download is a write, and is admitted the way a settings write is.
47
+ if (!sameOrigin(request, true)) {
48
+ replyJson(response, 403, { error: 'not-same-origin' });
49
+ return;
50
+ }
51
+ let snapshot;
52
+ try {
53
+ snapshot = deps.provision();
54
+ }
55
+ catch (error) {
56
+ // `provision` is documented not to throw; if a caller breaks that contract the panel still gets
57
+ // an answer it can render, rather than a dropped connection it cannot tell from a hang.
58
+ replyJson(response, 200, {
59
+ ok: true,
60
+ runtime: deps.report(),
61
+ provisionError: String(error),
62
+ });
63
+ return;
64
+ }
65
+ replyJson(response, 200, { ok: true, runtime: deps.report(), provision: snapshot });
66
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * One answer to "can I use the browser right now", assembled from the three things that decide it.
3
+ *
4
+ * WHY THIS EXISTS
5
+ * Installing this plugin made the browser work with no setup, and that property got silently
6
+ * weaker as the carriers were added: the bundled carrier downloads a ~100 MB Electron runtime on
7
+ * first need (issue #41 — the download had to leave `postinstall`), so on a fresh install the first
8
+ * browser call can arrive while that download is still running, and the only trace anywhere in the
9
+ * product was a log line the settings panel cannot read. A user who saw "cannot locate a spawnable
10
+ * Electron binary" had no way to learn that the plugin was already fetching one, and no button to
11
+ * retry it once it failed.
12
+ *
13
+ * So the readiness of each part is computed ONCE here, in a pure function over injectable readers:
14
+ * the settings panel renders it, and a test drives it without touching Electron, a desktop install
15
+ * or the file system.
16
+ *
17
+ * Everything here is a cheap read by construction. `hasBinary` resolves a path (the same probe a
18
+ * launch uses, so the answer can never disagree with a launch), and the bridge reading is the same
19
+ * install-tree inspection the bridge-status route already serves. Nothing spawns anything.
20
+ * @module dsh-browser/browser-electron/runtime-status
21
+ */
22
+ import type { BridgeStatus } from './bridge-status.js';
23
+ import type { BridgeEndpointState } from './bridge-endpoint.js';
24
+ import type { ProvisionSnapshot } from './electron-provision.js';
25
+ import type { BrowserChannel } from './system-browser.js';
26
+ /** The part of the carrier the channel names, in the terms the panel has to explain. */
27
+ export type CarrierKind = 'sidebar' | 'bundled' | 'system' | 'auto';
28
+ /**
29
+ * Whether the readiness question has an answer at all.
30
+ *
31
+ * `unknown` is not a defect: an explicit Chrome / Edge choice is only falsifiable by launching one,
32
+ * and launching a browser to answer a status question is exactly what this report must not do. The
33
+ * panel says so in words instead of guessing a colour.
34
+ */
35
+ export type Readiness = 'ready' | 'blocked' | 'unknown';
36
+ /** The Electron runtime's state, as the panel needs it. */
37
+ export interface ElectronReadiness {
38
+ /** `present` — a launch would find a binary; `preparing` — a download is running now; and so on. */
39
+ readonly state: ProvisionSnapshot['state'];
40
+ /** One line, already user-facing: the provisioning module's own words. */
41
+ readonly detail: string;
42
+ /** When that state was reached, ISO. */
43
+ readonly at: string;
44
+ }
45
+ /** The desktop sidebar bridge, or the honest "there is no desktop here" shape. */
46
+ export interface BridgeReadiness {
47
+ /** Whether a DSH Desktop install was found at all. */
48
+ readonly present: boolean;
49
+ /** `absent` is reported separately from `missing`: nothing to repair versus something to repair. */
50
+ readonly state: BridgeStatus['state'] | 'absent';
51
+ /** The plugin's own words about the install tree. */
52
+ readonly detail: string;
53
+ /**
54
+ * Whether a shell is RUNNING and answering, as opposed to merely installed.
55
+ *
56
+ * Install-tree state survives a reboot and says nothing about a process; the published endpoint is
57
+ * the only thing that does. Reporting "installed" as "ready" is how a panel goes green while every
58
+ * call dials a port nobody owns — the desktop app being closed is the most common broken state
59
+ * there is.
60
+ */
61
+ readonly running: boolean;
62
+ /** The plugin's own words about the running shell (or about why there is none). */
63
+ readonly runningDetail: string;
64
+ /** The command that installs or repairs it, for a human to run. Never run by the plugin. */
65
+ readonly command?: string;
66
+ }
67
+ /** The whole report. */
68
+ export interface RuntimeStatusReport {
69
+ /** What the settings document says, verbatim: the panel shows the switch it is honouring. */
70
+ readonly channel: BrowserChannel;
71
+ /** What that channel resolves to, in panel terms. */
72
+ readonly carrier: CarrierKind;
73
+ /** Whether the browser this channel names can serve a call right now. */
74
+ readonly readiness: Readiness;
75
+ readonly electron: ElectronReadiness;
76
+ readonly bridge: BridgeReadiness;
77
+ /** Whether "Prepare the bundled browser" is worth offering (it is not while one is running). */
78
+ readonly canProvision: boolean;
79
+ }
80
+ /** Everything the report reads, so a test can answer without any of the real machinery. */
81
+ export interface RuntimeStatusDeps {
82
+ /** The stored `browser.channel`. */
83
+ readonly channel: () => BrowserChannel;
84
+ /** Whether a launch would find an Electron binary — the launch path's own probe. */
85
+ readonly hasBinary: () => boolean;
86
+ /** The provisioning state machine's current state. */
87
+ readonly provision: () => ProvisionSnapshot;
88
+ /** The desktop install's bridge state, or undefined when there is no desktop install. */
89
+ readonly bridge: () => BridgeStatus | undefined;
90
+ /** The endpoint the shell publishes while it runs; undefined when nothing published one. */
91
+ readonly endpoint: () => BridgeEndpointState | undefined;
92
+ }
93
+ /**
94
+ * Assemble the report.
95
+ *
96
+ * The `readiness` field is per carrier on purpose: "the browser is ready" is not a property of this
97
+ * plugin, it is a property of the carrier the user chose. A bundled carrier with a finished download
98
+ * is ready; the sidebar carrier with no bridge is not, however healthy the bundled runtime is.
99
+ * @param deps - the readers; every one of them is a cheap, side-effect-free read.
100
+ * @returns the report the panel renders.
101
+ */
102
+ export declare function readRuntimeStatus(deps: RuntimeStatusDeps): RuntimeStatusReport;
@@ -0,0 +1,88 @@
1
+ /** Which carrier a channel names. */
2
+ function carrierOf(channel) {
3
+ if (channel === 'sidebar')
4
+ return 'sidebar';
5
+ if (channel === 'bundled')
6
+ return 'bundled';
7
+ if (channel === 'auto')
8
+ return 'auto';
9
+ return 'system';
10
+ }
11
+ /** Whether a binary being present settles the Electron question. */
12
+ function electronReady(state) {
13
+ return state === 'present' || state === 'ready';
14
+ }
15
+ /**
16
+ * Assemble the report.
17
+ *
18
+ * The `readiness` field is per carrier on purpose: "the browser is ready" is not a property of this
19
+ * plugin, it is a property of the carrier the user chose. A bundled carrier with a finished download
20
+ * is ready; the sidebar carrier with no bridge is not, however healthy the bundled runtime is.
21
+ * @param deps - the readers; every one of them is a cheap, side-effect-free read.
22
+ * @returns the report the panel renders.
23
+ */
24
+ export function readRuntimeStatus(deps) {
25
+ const channel = deps.channel();
26
+ const carrier = carrierOf(channel);
27
+ // The binary check comes first and wins: a runtime that is on disk is ready whatever the
28
+ // provisioning state machine last said, which is also how a runtime installed by hand (or by an
29
+ // earlier process) is reported correctly without a restart. The DETAIL has to follow the same
30
+ // rule, or the panel shows "present" next to "the runtime has not been asked for yet" — measured
31
+ // on a live install, and the kind of contradiction a reader cannot resolve.
32
+ const snapshot = deps.provision();
33
+ const runnable = deps.hasBinary();
34
+ const missingAfterReady = !runnable && (snapshot.state === 'present' || snapshot.state === 'ready');
35
+ const state = runnable ? 'present' : missingAfterReady ? 'failed' : snapshot.state;
36
+ const electron = {
37
+ state,
38
+ detail: runnable ? 'an Electron runtime is already available'
39
+ : missingAfterReady ? 'the previously prepared Electron runtime is missing; prepare it again' : snapshot.detail,
40
+ at: runnable ? new Date().toISOString() : snapshot.at,
41
+ };
42
+ const bridgeStatus = deps.bridge();
43
+ const endpoint = deps.endpoint();
44
+ const bridge = bridgeStatus === undefined
45
+ ? {
46
+ present: false,
47
+ state: 'absent',
48
+ detail: 'no DSH Desktop install was found on this machine',
49
+ running: endpoint?.alive === true,
50
+ runningDetail: endpoint?.detail ?? 'no desktop shell has published a bridge endpoint',
51
+ }
52
+ : {
53
+ present: bridgeStatus.present,
54
+ state: bridgeStatus.state,
55
+ detail: bridgeStatus.detail,
56
+ running: endpoint?.alive === true,
57
+ runningDetail: endpoint?.detail ?? 'no desktop shell has published a bridge endpoint',
58
+ ...bridgeStatus.command === undefined ? {} : { command: bridgeStatus.command },
59
+ };
60
+ // The sidebar needs BOTH halves: our patch inside the shell it will be driven through, and that
61
+ // shell actually running. Either one alone is the false green this report exists to prevent.
62
+ const sidebarReady = bridge.state === 'installed' && bridge.running;
63
+ let readiness;
64
+ if (carrier === 'sidebar') {
65
+ readiness = sidebarReady ? 'ready' : 'blocked';
66
+ }
67
+ else if (carrier === 'bundled') {
68
+ readiness = electronReady(state) ? 'ready' : 'blocked';
69
+ }
70
+ else if (carrier === 'auto') {
71
+ // `auto` is satisfied by either carrier, so a working sidebar covers a missing runtime. An
72
+ // explicit Chrome / Edge install would satisfy it too, but proving that means launching one.
73
+ readiness = electronReady(state) || sidebarReady ? 'ready' : 'unknown';
74
+ }
75
+ else {
76
+ readiness = 'unknown';
77
+ }
78
+ return {
79
+ channel,
80
+ carrier,
81
+ readiness,
82
+ electron,
83
+ bridge,
84
+ // Offering the button while a download runs would be a second download, which is the one thing
85
+ // the shared attempt exists to prevent.
86
+ canProvision: !electronReady(state) && state !== 'preparing',
87
+ };
88
+ }
@@ -1,22 +1,9 @@
1
1
  /**
2
- * Admission for the settings route: who may read the document, and who may write it.
3
- *
4
- * Its own module for a blunt reason — `entry.ts` imports the host's peer packages (cordis, the
5
- * tools registry) and therefore cannot be loaded by the test suite, while this is precisely the
6
- * logic whose failure is invisible in a browser: too strict and the panel silently stops being
7
- * able to save, too loose and any process on the machine can rewrite the operator's switches.
8
- *
9
- * It is NOT authentication, and cannot be. The plugin has no credential to check: DSH hands
10
- * plugin routes the raw request (`packages/host/webserver/src/index.ts` registers handlers with
11
- * no gate of its own), so the strongest same-origin evidence available is what a browser
12
- * reliably sends.
13
- *
14
- * What that buys and what it does not:
15
- * - a plain HTTP client (curl, a script, another process) cannot WRITE, because it sends no
16
- * `user-agent` and no `accept-language`;
17
- * - a page of THIS origin can, because a browser sending a same-origin write looks exactly
18
- * like the panel. That is inherent to exposing an HTTP endpoint at all, and it is why the
19
- * settings panel's own text must not promise a lock that does not exist.
2
+ * Browser-origin checks used after DSH authenticates each plugin HTTP request.
3
+ * Desktop protocol forwarding supplies the host session cookie while Chromium may omit Origin
4
+ * and Referer for the custom application scheme. These checks preserve that request shape and
5
+ * reject browser requests that explicitly name another web origin.
6
+ * @module dsh-browser/browser-electron/settings-route
20
7
  */
21
8
  import type { IncomingMessage } from 'node:http';
22
9
  /**
@@ -29,25 +29,15 @@ export function sameOrigin(request, writing = false) {
29
29
  return true;
30
30
  if (APP_SCHEMES.includes(schemeOf(String(request.headers.referer ?? '')) ?? ''))
31
31
  return true;
32
- // MEASURED on the running desktop, and what three earlier attempts each guessed wrong: a
33
- // request from the shell's own settings panel carries NO origin, NO sec-fetch-site and NO
34
- // referer. It is not "dsh-app://app" and it is not "null" — the headers are simply absent,
35
- // because Chromium attaches no cross-origin metadata to a request leaving a custom scheme.
36
- //
37
- // So the rule for that shape cannot be "a request without an Origin is a script", which is
38
- // what refused every desktop save, and it cannot lean on `Sec-Fetch-Site` either. It has to
39
- // test what a hand-rolled client does not send:
40
- // - a renderer sends a full Mozilla-compatible `user-agent` AND an `accept-language`;
41
- // - curl sends neither unless told to, and a local process that forges both can also read
42
- // the settings document directly — it sits readable on disk, as the panel's own text
43
- // says. This was never the boundary it looked like.
32
+ // Desktop custom-scheme requests can omit browser origin metadata. The route's host-cookie
33
+ // gate has already authenticated them; the renderer headers retain compatibility with older
34
+ // shells that omit Origin while forwarding settings writes.
44
35
  if (origin === '') {
45
36
  const agent = String(request.headers['user-agent'] ?? '');
46
37
  const language = String(request.headers['accept-language'] ?? '');
47
38
  if (/^Mozilla\/5\.0/.test(agent) && language !== '')
48
39
  return true;
49
- // Reads stay open: they return the document the panel is already showing, and refusing them
50
- // would only break hand-inspection of a file that sits readable on disk anyway.
40
+ // A missing Origin is valid for reads after the host-cookie gate has admitted the caller.
51
41
  return !writing;
52
42
  }
53
43
  // `cross-site` is another origin entirely; `same-site` is another origin of the same site
@@ -116,6 +116,23 @@ export interface BrowserSettings {
116
116
  /** Write cookies — importing login state (`dsh_browser_auth` restore). */
117
117
  readonly allowCredentialWrite: boolean;
118
118
  };
119
+ /**
120
+ * Where a downloaded file goes after it lands on disk.
121
+ *
122
+ * An ATTRIBUTE of a download, not a new concept: an empty `tool` means the behaviour is exactly
123
+ * what it was before this existed. The user owns the field, can point it at any MCP tool that
124
+ * takes a path (Feishu drive, Baidu Netdisk), and can empty it again at any time.
125
+ */
126
+ readonly delivery: {
127
+ /** MCP tool that receives the saved file. Empty = save locally and stop there. */
128
+ readonly tool: string;
129
+ /** Flat argument template; {path}, {name} and {size} are substituted into string values. */
130
+ readonly args: Readonly<Record<string, string>>;
131
+ /** `keep-local` reports both outcomes; `stop` reports the handoff failure as the result. */
132
+ readonly onFail: 'keep-local' | 'stop';
133
+ /** Per-site override: page host → tool name. */
134
+ readonly sites: Readonly<Record<string, string>>;
135
+ };
119
136
  }
120
137
  /** Defaults for every switch: the documented out-of-the-box behaviour. */
121
138
  export declare const DEFAULT_SETTINGS: BrowserSettings;
@@ -28,6 +28,9 @@ export const DEFAULT_SETTINGS = {
28
28
  // content, so watching is an explicit decision rather than something a remote client can arrange.
29
29
  remoteView: { enabled: false },
30
30
  actions: { allowExecute: true, allowDownload: true, allowCredentialWrite: true },
31
+ // Local by default: the file lands in downloadDir and nothing leaves the machine until the user
32
+ // names a tool here. {file_path} is the argument name both Feishu's and Netdisk's upload tools use.
33
+ delivery: { tool: '', args: { file_path: '{path}' }, onFail: 'keep-local', sites: {} },
31
34
  };
32
35
  /**
33
36
  * Absolute path of the settings file, beside the browser profile and the
@@ -181,6 +184,19 @@ export function resolveSettings(raw, warn) {
181
184
  const browser = section(source, 'browser');
182
185
  const actions = section(source, 'actions');
183
186
  const remoteView = section(source, 'remoteView');
187
+ // Read defensively: this section is hand-editable, and a bad value must fall back to "local only"
188
+ // rather than fail the whole document.
189
+ const deliverySection = (section(source, 'delivery') ?? {});
190
+ const strings = (value, fallback) => {
191
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
192
+ return { ...fallback };
193
+ const out = {};
194
+ for (const [key, entry] of Object.entries(value)) {
195
+ if (typeof entry === 'string')
196
+ out[key] = entry;
197
+ }
198
+ return Object.keys(out).length === 0 ? { ...fallback } : out;
199
+ };
184
200
  // A section that is present but unreadable refuses its gates rather than defaulting them
185
201
  // open. The rest of a broken section keeps its defaults: refusing history or presentation
186
202
  // would punish the user for a bad file without protecting anything.
@@ -233,6 +249,14 @@ export function resolveSettings(raw, warn) {
233
249
  ? false
234
250
  : gate(remoteView.enabled, false),
235
251
  },
252
+ delivery: {
253
+ tool: typeof deliverySection.tool === 'string' && /^[A-Za-z0-9_.-]+$/.test(deliverySection.tool)
254
+ ? deliverySection.tool
255
+ : '',
256
+ args: strings(deliverySection.args, DEFAULT_SETTINGS.delivery.args),
257
+ onFail: deliverySection.onFail === 'stop' ? 'stop' : 'keep-local',
258
+ sites: strings(deliverySection.sites, {}),
259
+ },
236
260
  };
237
261
  }
238
262
  /**
@@ -85,6 +85,7 @@ export declare class SystemBrowserViewHost implements ElectronBrowserViewHost {
85
85
  * and why a display-less host needs headless at all (issue #32).
86
86
  */
87
87
  private readonly headlessMode;
88
+ private readonly isQuiet;
88
89
  /**
89
90
  * viewId -> the session that view rides, and the client that issued it.
90
91
  *
@@ -156,7 +157,7 @@ export declare class SystemBrowserViewHost implements ElectronBrowserViewHost {
156
157
  * Whether this launch should get a window. See {@link resolveLaunchMode} for how `auto` decides
157
158
  * and why a display-less host needs headless at all (issue #32).
158
159
  */
159
- headlessMode?: HeadlessMode);
160
+ headlessMode?: HeadlessMode, isQuiet?: () => boolean);
160
161
  /** Which product this host would drive (for diagnostics). */
161
162
  get kind(): DetectedBrowser['kind'];
162
163
  /** Whether the browser has actually been started yet (diagnostics and tests). */
@@ -284,7 +285,9 @@ export declare class SystemBrowserViewHost implements ElectronBrowserViewHost {
284
285
  * two, and the order is honoured either way.
285
286
  * @param handle - the view to present.
286
287
  */
287
- presentView(handle: ElectronViewHandle): Promise<void>;
288
+ presentView(handle: ElectronViewHandle, _label?: string, options?: {
289
+ readonly quiet?: boolean;
290
+ }): Promise<void>;
288
291
  /**
289
292
  * Best effort at bringing the browser's window forward.
290
293
  *
@@ -483,6 +483,7 @@ export class SystemBrowserViewHost {
483
483
  ephemeralDir;
484
484
  launcher;
485
485
  headlessMode;
486
+ isQuiet;
486
487
  /**
487
488
  * viewId -> the session that view rides, and the client that issued it.
488
489
  *
@@ -554,13 +555,14 @@ export class SystemBrowserViewHost {
554
555
  * Whether this launch should get a window. See {@link resolveLaunchMode} for how `auto` decides
555
556
  * and why a display-less host needs headless at all (issue #32).
556
557
  */
557
- headlessMode = 'auto') {
558
+ headlessMode = 'auto', isQuiet = () => false) {
558
559
  this.browser = browser;
559
560
  this.profileDir = profileDir;
560
561
  this.extraArgs = extraArgs;
561
562
  this.ephemeralDir = ephemeralDir;
562
563
  this.launcher = launcher;
563
564
  this.headlessMode = headlessMode;
565
+ this.isQuiet = isQuiet;
564
566
  }
565
567
  /** Which product this host would drive (for diagnostics). */
566
568
  get kind() {
@@ -740,7 +742,7 @@ export class SystemBrowserViewHost {
740
742
  const adopted = await this.adoptRunningBrowser('before launch');
741
743
  if (adopted !== undefined)
742
744
  return adopted;
743
- const launch = resolveLaunchMode(this.headlessMode);
745
+ const launch = resolveLaunchMode(this.isQuiet() ? 'headless' : this.headlessMode);
744
746
  const args = [
745
747
  '--remote-debugging-port=0',
746
748
  `--user-data-dir=${this.profileDir}`,
@@ -1102,6 +1104,7 @@ export class SystemBrowserViewHost {
1102
1104
  const ours = new Set(this.sessions.values());
1103
1105
  return (listed?.targetInfos ?? [])
1104
1106
  .filter(entry => entry.type === 'page' && typeof entry.targetId === 'string')
1107
+ .filter(entry => !/^edge:\/\/sync-confirmation-dialog(?:\/|$)/.test(entry.url ?? ''))
1105
1108
  .filter(entry => !ours.has(entry.targetId))
1106
1109
  .map(entry => ({
1107
1110
  id: entry.targetId,
@@ -1259,7 +1262,9 @@ export class SystemBrowserViewHost {
1259
1262
  * two, and the order is honoured either way.
1260
1263
  * @param handle - the view to present.
1261
1264
  */
1262
- async presentView(handle) {
1265
+ async presentView(handle, _label, options) {
1266
+ if (options?.quiet === true || this.isQuiet())
1267
+ return;
1263
1268
  try {
1264
1269
  await handle.sendCommand('Page.bringToFront');
1265
1270
  }
@@ -1479,7 +1484,10 @@ export class SystemBrowserViewHost {
1479
1484
  }
1480
1485
  /** Create one page, refusing to go on without an id. */
1481
1486
  async createTarget(client) {
1482
- const created = await client.send('Target.createTarget', { url: 'about:blank' });
1487
+ const created = await client.send('Target.createTarget', {
1488
+ url: 'about:blank',
1489
+ ...this.isQuiet() ? { background: true } : {},
1490
+ });
1483
1491
  const targetId = created?.targetId;
1484
1492
  if (typeof targetId !== 'string')
1485
1493
  throw new Error('dsh-builtin-browser: the browser did not create a page');