dsh-builtin-browser 0.1.23 → 0.2.0

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 (37) hide show
  1. package/README.en.md +45 -2
  2. package/README.md +46 -3
  3. package/client.js +298 -0
  4. package/cordis.patch.yml +24 -5
  5. package/docs/README.md +1 -1
  6. package/docs/architecture.md +1 -1
  7. package/docs/tool-reference.md +2 -1
  8. package/lib/browser/runtime.d.ts +18 -1
  9. package/lib/browser/runtime.js +19 -0
  10. package/lib/browser/types.d.ts +33 -0
  11. package/lib/browser-electron/entry.js +115 -0
  12. package/lib/browser-electron/history-store.d.ts +71 -0
  13. package/lib/browser-electron/history-store.js +151 -0
  14. package/lib/browser-electron/host-main.js +28 -1
  15. package/lib/browser-electron/provider.d.ts +80 -0
  16. package/lib/browser-electron/provider.js +142 -2
  17. package/lib/browser-electron/remote-host.d.ts +8 -0
  18. package/lib/browser-electron/remote-host.js +64 -6
  19. package/lib/browser-electron/settings-store.d.ts +87 -0
  20. package/lib/browser-electron/settings-store.js +160 -0
  21. package/lib/browser-electron/virtual-cursor.d.ts +42 -0
  22. package/lib/browser-electron/virtual-cursor.js +71 -0
  23. package/lib/index.d.ts +16 -2
  24. package/lib/index.js +18 -2
  25. package/lib/tool-browser/index.js +72 -2
  26. package/package.json +13 -1
  27. package/src/browser/runtime.ts +22 -0
  28. package/src/browser/types.ts +31 -0
  29. package/src/browser-electron/entry.ts +135 -0
  30. package/src/browser-electron/history-store.ts +162 -0
  31. package/src/browser-electron/host-main.ts +26 -1
  32. package/src/browser-electron/provider.ts +166 -2
  33. package/src/browser-electron/remote-host.ts +67 -5
  34. package/src/browser-electron/settings-store.ts +198 -0
  35. package/src/browser-electron/virtual-cursor.ts +82 -0
  36. package/src/index.ts +20 -2
  37. package/src/tool-browser/index.ts +71 -1
@@ -544,11 +544,44 @@ export interface BrowserProvider {
544
544
  restoreAuth(session: BrowserSessionId, cookies: readonly ExportedCookie[]): Promise<number>;
545
545
  /** Return the session's chronological operation log. */
546
546
  history(session: BrowserSessionId): Promise<readonly BrowserHistoryEntry[]>;
547
+ /**
548
+ * Persisted visits, newest first: what survives the browser process, so a
549
+ * human or an Agent can find a page again after the interface was closed.
550
+ * @param options - result cap and an optional hostname filter.
551
+ * @returns the retained visits (empty when history is disabled).
552
+ */
553
+ visited(options?: {
554
+ readonly limit?: number;
555
+ readonly domain?: string;
556
+ }): readonly VisitedPage[];
557
+ /**
558
+ * Optional: whether a session is still live. A session can end outside the
559
+ * tool layer — the human closed the browser window — so a cached id must be
560
+ * checked before it is reused. Providers that never end a session on their own
561
+ * can omit this, and callers treat absence as "still live".
562
+ * @param session - the session id to test.
563
+ */
564
+ exists?(session: BrowserSessionId): boolean;
547
565
  /** Replay one recorded operation by sequence number. */
548
566
  replay(session: BrowserSessionId, seq: number): Promise<void>;
549
567
  /** Close the session and destroy its backing surface. Idempotent. */
550
568
  close(session: BrowserSessionId): Promise<void>;
551
569
  }
570
+ /**
571
+ * One visited page in the persistent browsing history — the durable record that
572
+ * outlives sessions, unlike {@link BrowserHistoryEntry}, which is a
573
+ * session-scoped operation log (navigate/click/type/…).
574
+ */
575
+ export interface VisitedPage {
576
+ /** Epoch milliseconds when the visit was recorded. */
577
+ readonly at: number;
578
+ /** Absolute URL of the visited document. */
579
+ readonly url: string;
580
+ /** Document title at visit time, when the page exposed one. */
581
+ readonly title?: string;
582
+ /** Session/task label that drove the visit, when the provider knows it. */
583
+ readonly session?: string;
584
+ }
552
585
  /** One recorded browser operation, in chronological order (seq 1, 2, 3…). */
553
586
  export interface BrowserHistoryEntry {
554
587
  /** Monotonic sequence number within the session. */
@@ -12,6 +12,7 @@
12
12
  import z from '@deepseek-ai/schemastery';
13
13
  import { ElectronBrowserProvider } from './provider.js';
14
14
  import { defaultHostMainPath, RemoteElectronViewHost } from './remote-host.js';
15
+ import { SettingsStore } from './settings-store.js';
15
16
  export { ELECTRON_BROWSER_PROVIDER_ID, ElectronBrowserProvider, } from './provider.js';
16
17
  export { RemoteElectronViewHost, defaultHostMainPath } from './remote-host.js';
17
18
  /** Cordis plugin name used by loader diagnostics. */
@@ -31,6 +32,9 @@ export function apply(ctx, config) {
31
32
  // External host (desktop shell) wins; otherwise self-host. The self-hosted
32
33
  // child is disposed with the fiber, mirroring the shell's lifetime.
33
34
  const host = config.viewHost ?? new RemoteElectronViewHost(defaultHostMainPath());
35
+ // One settings document per plugin instance: the settings panel writes it, the
36
+ // provider reads it live, and both ends agree on the same file.
37
+ const settings = new SettingsStore();
34
38
  // Own the disposer on THIS plugin's fiber: registerBrowserProvider's effect
35
39
  // is bound to the seam's own fiber (the browser row), so a reload of this
36
40
  // row would otherwise collide with the still-registered provider
@@ -40,6 +44,7 @@ export function apply(ctx, config) {
40
44
  downloadDir: config.downloadDir,
41
45
  snapshotMaxElements: config.snapshotMaxElements,
42
46
  contentMaxChars: config.contentMaxChars,
47
+ settings: () => settings.get(),
43
48
  }));
44
49
  ctx.effect(() => () => {
45
50
  unregister();
@@ -47,4 +52,114 @@ export function apply(ctx, config) {
47
52
  host.dispose();
48
53
  }
49
54
  });
55
+ installSettingsRoute(ctx, settings);
56
+ }
57
+ /** Route the settings panel reads and writes. */
58
+ const SETTINGS_ROUTE = '/dsh-builtin-browser/settings';
59
+ /**
60
+ * Expose the settings document over the host's web server, which is how the
61
+ * settings panel reads and writes it. A host without that service (headless /
62
+ * CLI surfaces) simply skips this: the panel is then unreachable and the file
63
+ * stays hand-editable — never a plugin-startup failure.
64
+ * @param ctx - the plugin context.
65
+ * @param settings - the settings document to expose.
66
+ */
67
+ function installSettingsRoute(ctx, settings) {
68
+ const inject = ctx.inject;
69
+ if (typeof inject !== 'function')
70
+ return;
71
+ try {
72
+ inject(['webServer'], (host) => {
73
+ host.effect(() => host.webServer.register({
74
+ kind: 'exact',
75
+ path: SETTINGS_ROUTE,
76
+ handler: (request, response) => handleSettingsRequest(request, response, settings),
77
+ }, 'dsh-builtin-browser: settings'));
78
+ });
79
+ }
80
+ catch {
81
+ // No web server on this surface: the settings file remains the interface.
82
+ }
83
+ }
84
+ /**
85
+ * Same-origin guard. Settings are machine-local configuration, so a page loaded
86
+ * elsewhere must not be able to read or rewrite them.
87
+ * @param request - the incoming request.
88
+ * @returns whether the request may touch the settings document.
89
+ */
90
+ function sameOrigin(request) {
91
+ const site = String(request.headers['sec-fetch-site'] ?? '').toLowerCase();
92
+ if (site === 'cross-site')
93
+ return false;
94
+ const origin = String(request.headers.origin ?? '').trim();
95
+ if (origin === 'null')
96
+ return false;
97
+ if (origin === '')
98
+ return true;
99
+ try {
100
+ return new URL(origin).host.toLowerCase() === String(request.headers.host ?? '').trim().toLowerCase();
101
+ }
102
+ catch {
103
+ return false;
104
+ }
105
+ }
106
+ /**
107
+ * One settings round-trip: `GET` reads the document, `PUT`/`POST` merges a
108
+ * partial patch into it.
109
+ * @param request - the incoming request.
110
+ * @param response - the response to write.
111
+ * @param settings - the settings document.
112
+ */
113
+ async function handleSettingsRequest(request, response, settings) {
114
+ const json = (status, body) => {
115
+ response.writeHead(status, {
116
+ 'content-type': 'application/json; charset=utf-8',
117
+ 'cache-control': 'no-store',
118
+ });
119
+ response.end(JSON.stringify(body));
120
+ };
121
+ if (!sameOrigin(request)) {
122
+ json(403, { ok: false, error: 'cross-origin request refused' });
123
+ return;
124
+ }
125
+ const method = request.method ?? 'GET';
126
+ if (method === 'GET') {
127
+ json(200, { ok: true, settings: settings.get(), path: settings.path() });
128
+ return;
129
+ }
130
+ if (method !== 'PUT' && method !== 'POST') {
131
+ response.writeHead(405, { allow: 'GET, PUT' });
132
+ response.end();
133
+ return;
134
+ }
135
+ try {
136
+ const body = await readBody(request);
137
+ const patch = body.trim() === '' ? {} : JSON.parse(body);
138
+ json(200, { ok: true, settings: settings.update(patch) });
139
+ }
140
+ catch (error) {
141
+ json(400, { ok: false, error: `invalid settings patch: ${String(error)}` });
142
+ }
143
+ }
144
+ /**
145
+ * Read a request body with a hard cap (the settings patch is tiny, and an
146
+ * unbounded read would let any same-origin caller exhaust memory).
147
+ * @param request - the incoming request.
148
+ * @param limit - maximum accepted characters.
149
+ * @returns the body text.
150
+ */
151
+ function readBody(request, limit = 64 * 1024) {
152
+ return new Promise((resolve, reject) => {
153
+ let text = '';
154
+ request.setEncoding('utf8');
155
+ request.on('data', chunk => {
156
+ text += String(chunk);
157
+ if (text.length > limit) {
158
+ request.destroy();
159
+ reject(new Error('settings patch too large'));
160
+ }
161
+ });
162
+ request.on('end', () => resolve(text));
163
+ request.on('error', reject);
164
+ });
50
165
  }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Persistent browsing history: which pages the shared browser actually visited,
3
+ * kept independently from any session's operation log (`browser_history`) and
4
+ * from the browser process's lifetime.
5
+ *
6
+ * It lives beside the browser profile (`$DSH_HOME/dsh-builtin-browser-host/
7
+ * history.jsonl`), so it follows the same persistence rules as the login state:
8
+ * closing the interface releases the process, never the record.
9
+ *
10
+ * Format: one JSON object per line, append-only. Appending stays cheap for a
11
+ * long session, and a half-written tail (crash, power loss) is dropped on read
12
+ * instead of poisoning the whole file.
13
+ * @module dsh-browser/browser-electron/history-store
14
+ */
15
+ import type { VisitedPage } from '../browser/types.js';
16
+ export type { VisitedPage };
17
+ /** Retention limits; whichever is hit first starts trimming. */
18
+ export interface HistoryLimits {
19
+ /** Maximum retained entries. Default 5000. */
20
+ readonly maxEntries?: number;
21
+ /** Maximum age in days. Default 90. */
22
+ readonly maxAgeDays?: number;
23
+ }
24
+ /**
25
+ * Absolute path of the browsing-history file, beside the browser profile so the
26
+ * record shares the login state's persistence rules.
27
+ * @returns the history file path.
28
+ */
29
+ export declare function visitedHistoryPath(): string;
30
+ /**
31
+ * Append-only browsing history with bounded retention. Every method tolerates a
32
+ * missing or damaged file: recording a visit must never fail a navigation, and
33
+ * a corrupted line must never hide the rest of the history.
34
+ */
35
+ export declare class HistoryStore {
36
+ private readonly file;
37
+ private readonly maxEntries;
38
+ private readonly maxAgeMs;
39
+ /**
40
+ * @param file - absolute path of the JSONL history file.
41
+ * @param limits - retention overrides (entry count and age).
42
+ */
43
+ constructor(file?: string, limits?: HistoryLimits);
44
+ /** Whether the history file exists yet (diagnostics and tests). */
45
+ exists(): boolean;
46
+ /**
47
+ * Record one visit. Failures are swallowed by design: history is a
48
+ * convenience, and losing an entry must never break the tool call that
49
+ * produced it.
50
+ * @param page - the visited page.
51
+ */
52
+ append(page: VisitedPage): void;
53
+ /**
54
+ * Read visits, newest first. Unparseable lines are skipped; entries older
55
+ * than the age limit are filtered out but left on disk until the next prune.
56
+ * @param options - optional result cap and domain filter.
57
+ * @returns the matching visits, newest first.
58
+ */
59
+ list(options?: {
60
+ readonly limit?: number;
61
+ readonly domain?: string;
62
+ }): VisitedPage[];
63
+ /**
64
+ * Enforce retention: drop entries past the age limit, then the oldest beyond
65
+ * the count cap. Cheap no-op until the file grows past the cap, so callers can
66
+ * run it after every append.
67
+ */
68
+ prune(): void;
69
+ /** Parse the whole file, skipping blank and damaged lines. */
70
+ private readAll;
71
+ }
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Persistent browsing history: which pages the shared browser actually visited,
3
+ * kept independently from any session's operation log (`browser_history`) and
4
+ * from the browser process's lifetime.
5
+ *
6
+ * It lives beside the browser profile (`$DSH_HOME/dsh-builtin-browser-host/
7
+ * history.jsonl`), so it follows the same persistence rules as the login state:
8
+ * closing the interface releases the process, never the record.
9
+ *
10
+ * Format: one JSON object per line, append-only. Appending stays cheap for a
11
+ * long session, and a half-written tail (crash, power loss) is dropped on read
12
+ * instead of poisoning the whole file.
13
+ * @module dsh-browser/browser-electron/history-store
14
+ */
15
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
16
+ import { homedir } from 'node:os';
17
+ import { dirname, join } from 'node:path';
18
+ /** Default entry cap — mirrors the documented retention rule. */
19
+ const DEFAULT_MAX_ENTRIES = 5_000;
20
+ /** Default age cap in days. */
21
+ const DEFAULT_MAX_AGE_DAYS = 90;
22
+ /** Rewrite the file only once it has grown this far past the cap. */
23
+ const PRUNE_SLACK = 500;
24
+ /**
25
+ * Absolute path of the browsing-history file, beside the browser profile so the
26
+ * record shares the login state's persistence rules.
27
+ * @returns the history file path.
28
+ */
29
+ export function visitedHistoryPath() {
30
+ const home = process.env.DSH_HOME ?? join(homedir(), '.dsh');
31
+ return join(home, 'dsh-builtin-browser-host', 'history.jsonl');
32
+ }
33
+ /**
34
+ * Append-only browsing history with bounded retention. Every method tolerates a
35
+ * missing or damaged file: recording a visit must never fail a navigation, and
36
+ * a corrupted line must never hide the rest of the history.
37
+ */
38
+ export class HistoryStore {
39
+ file;
40
+ maxEntries;
41
+ maxAgeMs;
42
+ /**
43
+ * @param file - absolute path of the JSONL history file.
44
+ * @param limits - retention overrides (entry count and age).
45
+ */
46
+ constructor(file = visitedHistoryPath(), limits = {}) {
47
+ this.file = file;
48
+ this.maxEntries = limits.maxEntries ?? DEFAULT_MAX_ENTRIES;
49
+ this.maxAgeMs = (limits.maxAgeDays ?? DEFAULT_MAX_AGE_DAYS) * 24 * 60 * 60 * 1000;
50
+ }
51
+ /** Whether the history file exists yet (diagnostics and tests). */
52
+ exists() {
53
+ return existsSync(this.file);
54
+ }
55
+ /**
56
+ * Record one visit. Failures are swallowed by design: history is a
57
+ * convenience, and losing an entry must never break the tool call that
58
+ * produced it.
59
+ * @param page - the visited page.
60
+ */
61
+ append(page) {
62
+ try {
63
+ mkdirSync(dirname(this.file), { recursive: true });
64
+ appendFileSync(this.file, `${JSON.stringify(page)}\n`);
65
+ }
66
+ catch {
67
+ // Best-effort: history is not worth failing a navigation over.
68
+ }
69
+ }
70
+ /**
71
+ * Read visits, newest first. Unparseable lines are skipped; entries older
72
+ * than the age limit are filtered out but left on disk until the next prune.
73
+ * @param options - optional result cap and domain filter.
74
+ * @returns the matching visits, newest first.
75
+ */
76
+ list(options = {}) {
77
+ const all = this.readAll();
78
+ const cutoff = Date.now() - this.maxAgeMs;
79
+ const domain = options.domain?.toLowerCase();
80
+ const matches = all.filter(page => {
81
+ if (page.at < cutoff)
82
+ return false;
83
+ if (domain === undefined)
84
+ return true;
85
+ try {
86
+ return new URL(page.url).hostname.toLowerCase().includes(domain);
87
+ }
88
+ catch {
89
+ return page.url.toLowerCase().includes(domain);
90
+ }
91
+ });
92
+ matches.reverse();
93
+ return options.limit === undefined ? matches : matches.slice(0, Math.max(0, options.limit));
94
+ }
95
+ /**
96
+ * Enforce retention: drop entries past the age limit, then the oldest beyond
97
+ * the count cap. Cheap no-op until the file grows past the cap, so callers can
98
+ * run it after every append.
99
+ */
100
+ prune() {
101
+ const all = this.readAll();
102
+ const cutoff = Date.now() - this.maxAgeMs;
103
+ const fresh = all.filter(page => page.at >= cutoff);
104
+ const kept = fresh.length > this.maxEntries ? fresh.slice(fresh.length - this.maxEntries) : fresh;
105
+ // Only rewrite when something actually fell off, and only once the excess
106
+ // is worth a full rewrite.
107
+ if (kept.length === all.length)
108
+ return;
109
+ if (all.length - kept.length < PRUNE_SLACK && fresh.length <= this.maxEntries)
110
+ return;
111
+ try {
112
+ const body = kept.map(page => `${JSON.stringify(page)}\n`).join('');
113
+ writeFileSync(this.file, body);
114
+ }
115
+ catch {
116
+ // Best-effort: an unpruned file still reads correctly.
117
+ }
118
+ }
119
+ /** Parse the whole file, skipping blank and damaged lines. */
120
+ readAll() {
121
+ let raw;
122
+ try {
123
+ raw = readFileSync(this.file, 'utf8');
124
+ }
125
+ catch {
126
+ return [];
127
+ }
128
+ const pages = [];
129
+ for (const line of raw.split('\n')) {
130
+ const trimmed = line.trim();
131
+ if (trimmed === '')
132
+ continue;
133
+ try {
134
+ const parsed = JSON.parse(trimmed);
135
+ if (typeof parsed.at !== 'number' || typeof parsed.url !== 'string')
136
+ continue;
137
+ pages.push({
138
+ at: parsed.at,
139
+ url: parsed.url,
140
+ ...typeof parsed.title === 'string' && parsed.title !== '' ? { title: parsed.title } : {},
141
+ ...typeof parsed.session === 'string' && parsed.session !== '' ? { session: parsed.session } : {},
142
+ });
143
+ }
144
+ catch {
145
+ // A damaged line (typically a truncated tail) must not hide the rest.
146
+ continue;
147
+ }
148
+ }
149
+ return pages;
150
+ }
151
+ }
@@ -338,7 +338,34 @@ function windowFor(windowId) {
338
338
  if (existing !== undefined)
339
339
  return existing;
340
340
  const w = new BrowserWindow({ width: 1400, height: 900, show: true, title: 'dsh-browser' });
341
- w.on('closed', () => { windows.delete(key); });
341
+ w.on('closed', () => {
342
+ const closing = windows.get(key);
343
+ windows.delete(key);
344
+ // A BrowserWindow does not destroy its child views: their webContents (the
345
+ // renderer process, its timers and audio) outlive the window unless closed
346
+ // explicitly, so release them here instead of leaking a renderer per window.
347
+ if (closing !== undefined) {
348
+ for (const view of closing.views.values()) {
349
+ try {
350
+ view.webContentsView.webContents.close();
351
+ }
352
+ catch {
353
+ // Already destroyed along with the window.
354
+ }
355
+ }
356
+ closing.views.clear();
357
+ }
358
+ // The interface is gone for good. Report it, so the plugin ends that session
359
+ // instead of holding one whose window the human already closed. Browsing
360
+ // history and login state live on disk, so the next open starts a clean
361
+ // session rather than resurrecting this one.
362
+ try {
363
+ rpcSocket?.write(JSON.stringify({ id: 0, op: 'viewClosed', windowId: key }) + '\n');
364
+ }
365
+ catch {
366
+ // Socket already gone (parent shutting down): nothing left to report to.
367
+ }
368
+ });
342
369
  const win = { windowId: key, window: w, toolbarView: undefined, views: new Map(), visibleViewId: undefined, lastFocusedViewId: undefined, closeTimer: undefined };
343
370
  // Keep every view (and the toolbar) filling the window as the human
344
371
  // resizes it; otherwise pages stay at their original size and break.
@@ -6,6 +6,8 @@
6
6
  * shell that owns the `BrowserWindow`.
7
7
  * @module dsh-browser/browser-electron
8
8
  */
9
+ import { type VisitedPage } from './history-store.js';
10
+ import type { BrowserSettings } from './settings-store.js';
9
11
  import type { BrowserA11yRequest, BrowserA11yResult, BrowserChallenge, BrowserCheckRequest, BrowserClearRequest, BrowserClickRequest, BrowserContentRequest, BrowserContentResult, BrowserElementTarget, BrowserExecuteRequest, BrowserExecuteResult, BrowserFillRequest, BrowserFillResult, BrowserGetValueRequest, BrowserGetValueResult, BrowserHistoryEntry, BrowserOpenRequest, BrowserProvider, BrowserScrapeRequest, BrowserScrapeResult, BrowserScreenshotRequest, BrowserSelectRequest, BrowserSelectResult, BrowserSessionId, BrowserSetValueRequest, BrowserSetValueResult, BrowserSnapshotResult, BrowserTab, BrowserTypeRequest, BrowserWaitRequest, BrowserWaitResult, BrowserScrollRequest, BrowserKeyRequest, ExportedCookie } from '../browser/types.js';
10
12
  /** Stable provider id registered with `ctx.browser`. */
11
13
  export declare const ELECTRON_BROWSER_PROVIDER_ID = "electron";
@@ -78,6 +80,13 @@ export interface ElectronBrowserViewHost {
78
80
  * @param handler - called for every user action; must not throw.
79
81
  */
80
82
  onUserAction?(handler: (action: BrowserUserAction) => void): void;
83
+ /**
84
+ * Optional: receive notice that the human closed a browser window. Closing the
85
+ * interface ends the session it showed — the next call opens a clean one —
86
+ * while browsing history and login state survive on disk.
87
+ * @param handler - called with the group (session) key; must not throw.
88
+ */
89
+ onViewClosed?(handler: (windowId: string) => void): void;
81
90
  }
82
91
  /**
83
92
  * A user-initiated browser action from the host's own UI (toolbar). The
@@ -137,6 +146,28 @@ export interface ElectronViewHandle {
137
146
  export interface ElectronBrowserProviderConfig {
138
147
  /** Allow navigation only to HTTP(S) URLs; reject anything else. Default true. */
139
148
  readonly httpOnly?: boolean;
149
+ /**
150
+ * Persistent browsing history (visited pages), independent of session
151
+ * lifetime. `enabled: false` keeps the browser working but records nothing;
152
+ * the retained limits ride along so a user's choice from the settings panel
153
+ * reaches the store without a second configuration path.
154
+ */
155
+ readonly history?: {
156
+ readonly enabled?: boolean;
157
+ readonly maxEntries?: number;
158
+ readonly maxAgeDays?: number;
159
+ /**
160
+ * Explicit history file path. Default: beside the browser profile
161
+ * (`$DSH_HOME/dsh-builtin-browser-host/history.jsonl`).
162
+ */
163
+ readonly file?: string;
164
+ };
165
+ /**
166
+ * Live settings source (the settings panel's document). When present it wins
167
+ * over the static `history` config, so a switch flipped in the UI takes effect
168
+ * without restarting DSH.
169
+ */
170
+ readonly settings?: () => BrowserSettings;
140
171
  /** Maximum snapshot elements before truncation. Default 60. */
141
172
  readonly snapshotMaxElements?: number;
142
173
  /** Maximum content characters before truncation when no maxChars is given. Default 100_000. */
@@ -208,6 +239,13 @@ export declare class ElectronBrowserProvider implements BrowserProvider {
208
239
  private readonly snapshotMaxElements;
209
240
  private readonly contentMaxChars;
210
241
  private readonly downloadDir;
242
+ /**
243
+ * Persistent browsing history, or `undefined` when the user turned it off.
244
+ * Sessions come and go; this record outlives all of them.
245
+ */
246
+ private readonly historyStore;
247
+ /** Live settings source; absent when nothing owns a settings document. */
248
+ private readonly settingsSource;
211
249
  constructor(host: ElectronBrowserViewHost, config?: ElectronBrowserProviderConfig);
212
250
  /**
213
251
  * Usable when the host says it can back views (the self-hosted host probes
@@ -447,6 +485,34 @@ export declare class ElectronBrowserProvider implements BrowserProvider {
447
485
  private record;
448
486
  /** Return the session's chronological operation log (newest last). */
449
487
  history(session: BrowserSessionId): Promise<readonly BrowserHistoryEntry[]>;
488
+ /**
489
+ * Record one page visit in the persistent browsing history. Fire-and-forget by
490
+ * design: a visit must never delay or fail the navigation that produced it,
491
+ * and the title is only worth reading once the document has settled.
492
+ * @param s - the session that drove the visit.
493
+ * @param handle - the view whose document just loaded.
494
+ */
495
+ private recordVisit;
496
+ /**
497
+ * List persisted visits, newest first — what `browser_visited` reads back.
498
+ * @param options - result cap and an optional hostname filter.
499
+ * @returns the matching visits, or an empty list when history is disabled.
500
+ */
501
+ visited(options?: {
502
+ readonly limit?: number;
503
+ readonly domain?: string;
504
+ }): readonly VisitedPage[];
505
+ /**
506
+ * Show the synthetic pointer on a view, unless the user switched it off. The
507
+ * cursor is the "the agent has taken over this tab" signal, so it is painted
508
+ * for every operation that has a landing point — including DOM-level ones that
509
+ * move no real pointer.
510
+ * @param handle - the view to paint into.
511
+ * @param x - viewport x in CSS pixels.
512
+ * @param y - viewport y in CSS pixels.
513
+ * @param action - click pulses a ripple; move only relocates.
514
+ */
515
+ private showCursor;
450
516
  /**
451
517
  * Replay one recorded operation by sequence number. Navigate/click/type are
452
518
  * re-issued against the current page; execute re-runs its script. The
@@ -465,6 +531,20 @@ export declare class ElectronBrowserProvider implements BrowserProvider {
465
531
  private newTab;
466
532
  /** Find a session's tab by its backing view id (toolbar actions carry view ids). */
467
533
  private tabByViewId;
534
+ /**
535
+ * Whether a session is still live. The human closing a window ends its session
536
+ * (see {@link handleViewClosed}), so callers that cache ids must ask first.
537
+ * @param session - the session id to test.
538
+ */
539
+ exists(session: BrowserSessionId): boolean;
540
+ /**
541
+ * The human closed a browser window: the session that window showed is over.
542
+ * Ending it here is what makes the next call a clean start rather than a
543
+ * resurrection of an invisible window. Browsing history and login state live
544
+ * on disk, so nothing the human cares about is lost with it.
545
+ * @param windowId - the group key the host reported, which is the session id.
546
+ */
547
+ private handleViewClosed;
468
548
  /**
469
549
  * Route a user-initiated action from the host's UI into the session model.
470
550
  * Fire-and-forget by design: a user action failing (e.g. an unreachable