@mercuryo-ai/agentbrowse 0.2.57 → 0.2.61

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 (100) hide show
  1. package/README.md +76 -57
  2. package/dist/browser-session-state.d.ts +39 -0
  3. package/dist/browser-session-state.d.ts.map +1 -1
  4. package/dist/browser-session-state.js +63 -1
  5. package/dist/command-name.js +1 -1
  6. package/dist/commands/act.d.ts.map +1 -1
  7. package/dist/commands/act.js +540 -528
  8. package/dist/commands/action-executor-helpers.d.ts.map +1 -1
  9. package/dist/commands/action-executor-helpers.js +10 -8
  10. package/dist/commands/attach.d.ts.map +1 -1
  11. package/dist/commands/attach.js +5 -10
  12. package/dist/commands/browser-connection-failure.d.ts +9 -0
  13. package/dist/commands/browser-connection-failure.d.ts.map +1 -0
  14. package/dist/commands/browser-connection-failure.js +15 -0
  15. package/dist/commands/browser-status.d.ts.map +1 -1
  16. package/dist/commands/browser-status.js +26 -30
  17. package/dist/commands/click-activation-policy.d.ts.map +1 -1
  18. package/dist/commands/click-activation-policy.js +6 -2
  19. package/dist/commands/close.d.ts.map +1 -1
  20. package/dist/commands/close.js +5 -0
  21. package/dist/commands/extract.d.ts.map +1 -1
  22. package/dist/commands/extract.js +147 -144
  23. package/dist/commands/launch.d.ts +0 -1
  24. package/dist/commands/launch.d.ts.map +1 -1
  25. package/dist/commands/launch.js +13 -16
  26. package/dist/commands/navigate.d.ts.map +1 -1
  27. package/dist/commands/navigate.js +79 -73
  28. package/dist/commands/observe-inventory.d.ts +6 -1
  29. package/dist/commands/observe-inventory.d.ts.map +1 -1
  30. package/dist/commands/observe-inventory.js +331 -8
  31. package/dist/commands/observe-persistence.d.ts.map +1 -1
  32. package/dist/commands/observe-persistence.js +2 -0
  33. package/dist/commands/observe-projection.d.ts +3 -2
  34. package/dist/commands/observe-projection.d.ts.map +1 -1
  35. package/dist/commands/observe-projection.js +1 -0
  36. package/dist/commands/observe-protected.d.ts +3 -1
  37. package/dist/commands/observe-protected.d.ts.map +1 -1
  38. package/dist/commands/observe-protected.js +23 -1
  39. package/dist/commands/observe-semantics.d.ts.map +1 -1
  40. package/dist/commands/observe-semantics.js +70 -0
  41. package/dist/commands/observe.d.ts +1 -0
  42. package/dist/commands/observe.d.ts.map +1 -1
  43. package/dist/commands/observe.js +260 -270
  44. package/dist/commands/screenshot.d.ts.map +1 -1
  45. package/dist/commands/screenshot.js +50 -64
  46. package/dist/control-semantics.d.ts.map +1 -1
  47. package/dist/control-semantics.js +5 -0
  48. package/dist/date-value-normalization.d.ts +16 -0
  49. package/dist/date-value-normalization.d.ts.map +1 -0
  50. package/dist/date-value-normalization.js +117 -0
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +5 -24
  53. package/dist/library.d.ts +5 -1
  54. package/dist/library.d.ts.map +1 -1
  55. package/dist/library.js +4 -1
  56. package/dist/protected-fill.d.ts +3 -2
  57. package/dist/protected-fill.d.ts.map +1 -1
  58. package/dist/protected-fill.js +46 -7
  59. package/dist/runtime-protected-state.d.ts.map +1 -1
  60. package/dist/runtime-protected-state.js +8 -1
  61. package/dist/runtime-state.d.ts +11 -0
  62. package/dist/runtime-state.d.ts.map +1 -1
  63. package/dist/secrets/form-matcher.d.ts +1 -2
  64. package/dist/secrets/form-matcher.d.ts.map +1 -1
  65. package/dist/secrets/form-matcher.js +125 -119
  66. package/dist/secrets/matching-helpers.d.ts +13 -0
  67. package/dist/secrets/matching-helpers.d.ts.map +1 -0
  68. package/dist/secrets/matching-helpers.js +147 -0
  69. package/dist/secrets/observed-field-resolution.d.ts +43 -0
  70. package/dist/secrets/observed-field-resolution.d.ts.map +1 -0
  71. package/dist/secrets/observed-field-resolution.js +223 -0
  72. package/dist/secrets/protected-field-semantics.d.ts.map +1 -1
  73. package/dist/secrets/protected-field-semantics.js +3 -2
  74. package/dist/secrets/protected-fill.d.ts +3 -1
  75. package/dist/secrets/protected-fill.d.ts.map +1 -1
  76. package/dist/secrets/protected-fill.js +31 -0
  77. package/dist/secrets/protected-value-adapters.d.ts.map +1 -1
  78. package/dist/secrets/protected-value-adapters.js +14 -22
  79. package/dist/secrets/types.d.ts +3 -0
  80. package/dist/secrets/types.d.ts.map +1 -1
  81. package/dist/sticky-owner-host-entry.d.ts +2 -0
  82. package/dist/sticky-owner-host-entry.d.ts.map +1 -0
  83. package/dist/sticky-owner-host-entry.js +97 -0
  84. package/dist/sticky-owner.d.ts +15 -0
  85. package/dist/sticky-owner.d.ts.map +1 -0
  86. package/dist/sticky-owner.js +431 -0
  87. package/docs/README.md +15 -2
  88. package/docs/api-reference.md +13 -3
  89. package/docs/assistive-runtime.md +63 -7
  90. package/docs/configuration.md +48 -8
  91. package/docs/getting-started.md +42 -9
  92. package/docs/integration-checklist.md +8 -7
  93. package/docs/protected-fill.md +40 -7
  94. package/docs/testing.md +4 -3
  95. package/docs/troubleshooting.md +126 -36
  96. package/examples/README.md +9 -2
  97. package/package.json +8 -3
  98. package/dist/protected-fill-browser.d.ts +0 -22
  99. package/dist/protected-fill-browser.d.ts.map +0 -1
  100. package/dist/protected-fill-browser.js +0 -52
package/README.md CHANGED
@@ -9,24 +9,41 @@ web pages — launch a browser, read what's on screen, interact with it, and
9
9
  extract structured data. Your app keeps full control of orchestration and
10
10
  business logic; AgentBrowse handles the page.
11
11
 
12
- Key capabilities:
13
-
14
- - launch a managed browser or attach to an existing CDP session;
15
- - inspect the page and get stable target references (no raw selectors);
16
- - click, type, select, and fill through those references;
17
- - extract structured data with an optional LLM-backed runtime;
18
- - capture screenshots and check session health.
19
-
20
- A good first way to think about it is:
21
-
22
- 1. launch a browser or attach to one and get a `session`
23
- 2. inspect the page with `observe(...)`
24
- 3. use `act(...)` to interact with what you found
25
- 4. use `extract(...)` when you need structured data instead of an action
26
- 5. close the session when you are done
27
-
28
- This makes AgentBrowse fit naturally into a worker, backend service, CLI, or
29
- agent runtime that already exists.
12
+ Typical workflow:
13
+
14
+ 1. open a browser (or attach to an existing one) and get a `session`;
15
+ 2. ask AgentBrowse what's on the page with `observe(...)`;
16
+ 3. act on what you found with `act(...)`;
17
+ 4. use `extract(...)` when you need structured data instead of an action;
18
+ 5. close the session when you are done.
19
+
20
+ That shape fits naturally into a worker, backend service, CLI, or agent
21
+ runtime you already have.
22
+
23
+ ## Key Terms
24
+
25
+ Three terms come up repeatedly in the API:
26
+
27
+ - **`session`** — the handle AgentBrowse returns from `launch(...)` or
28
+ `attach(...)`. You pass it into every later call. The session carries
29
+ browser identity, runtime state, and sticky-owner metadata so healthy
30
+ commands reuse one browser owner instead of opening a fresh root CDP
31
+ attach for every call. If you persist a session across process runs,
32
+ the next command may repair that owner while the underlying browser is
33
+ still alive; otherwise the session fails closed and you should
34
+ `launch(...)` or `attach(...)` again.
35
+ - **`ref`** (also `targetRef`, `scopeRef`, `fillRef`) — a stable reference
36
+ returned by `observe(...)`. You act on references, never on raw CSS
37
+ selectors. **Refs are valid for the page state that produced them, not
38
+ forever.** Navigation, route changes, or a major DOM re-render
39
+ invalidate them — call `observe(...)` again to get fresh refs.
40
+ - **CDP** — the Chrome DevTools Protocol. Chrome, Chromium, and Playwright
41
+ all speak it. If a browser exposes a CDP WebSocket URL, AgentBrowse can
42
+ attach to it.
43
+
44
+ Optionally, AgentBrowse can call an LLM to understand pages at a higher
45
+ level. That layer is called the *assistive runtime* and is only required
46
+ for `extract(...)` and goal-driven `observe(session, goal)`.
30
47
 
31
48
  ## Install
32
49
 
@@ -34,24 +51,15 @@ agent runtime that already exists.
34
51
  npm i @mercuryo-ai/agentbrowse
35
52
  ```
36
53
 
37
- If you want the operator-facing CLI, install `@mercuryo-ai/agentbrowse-cli`.
54
+ If you want the operator-facing CLI command, install the separate global CLI
55
+ package:
38
56
 
39
- ## The Core Mental Model
40
-
41
- There are four ideas you need to understand before using the library:
57
+ ```bash
58
+ npm i -g @mercuryo-ai/agentbrowse-cli@latest
59
+ ```
42
60
 
43
- - `session`
44
- The handle for a running browser. `launch(...)` or `attach(...)` returns it,
45
- and you pass it into the rest of the API.
46
- - `observe`
47
- Reads the page and tells you what AgentBrowse found: targets, scopes,
48
- signals, and forms.
49
- - `ref`
50
- A stable reference returned by `observe(...)`. You use it with `act(...)`
51
- instead of managing selectors yourself.
52
- - `assistive runtime`
53
- Optional LLM-backed page understanding. You only need it for extraction and
54
- for better quality in some goal-based `observe(session, goal)` calls.
61
+ `@mercuryo-ai/agentbrowse` is the library package for imports. It does not
62
+ install the `agentbrowse` shell command.
55
63
 
56
64
  ## Quick Start
57
65
 
@@ -101,8 +109,8 @@ try {
101
109
  }
102
110
 
103
111
  const statusResult = await status(session);
104
- if (!statusResult.success) {
105
- throw new Error(statusResult.reason ?? statusResult.message);
112
+ if (!statusResult.alive) {
113
+ throw new Error('Browser is no longer reachable.');
106
114
  }
107
115
  } finally {
108
116
  await close(session);
@@ -116,30 +124,24 @@ Runnable examples live in [`examples/`](./examples/README.md):
116
124
  - `npx tsx examples/attach.ts`
117
125
  - `npx tsx examples/extract.ts`
118
126
 
119
- ## Managed Launch Runtime Note
127
+ The library entrypoint does not load `.env` files. Environment loading only
128
+ happens in the CLI entrypoint.
120
129
 
121
- When you use `launch(...)`, the package includes `puppeteer` for the managed
122
- browser connection layer with stealth evasions enabled by default.
123
-
124
- The goal is practical: reduce unnecessary anti-bot friction such as extra
125
- captcha or challenge pages on sensitive sites.
126
-
127
- After the browser is up, the normal live browser interaction flow still runs
128
- over Playwright CDP.
129
-
130
- The library entrypoint does not load `.env` files. Environment loading is only
131
- part of the CLI entrypoint.
130
+ Both `launch(...)` and `attach(...)` bootstrap the same sticky-owner
131
+ lifecycle. That owner may live in-process or in an internal detached host,
132
+ but it is not a user-managed daemon contract.
132
133
 
133
134
  ## Attach To An Existing Browser
134
135
 
135
- If you already have a browser that exposes a CDP websocket, use `attach(...)`
136
- instead of `launch(...)`.
136
+ If you already have a browser that exposes a CDP WebSocket URL, use
137
+ `attach(...)` instead of `launch(...)`.
137
138
 
138
- That works for:
139
+ Common sources of a CDP URL:
139
140
 
140
- - a local Chrome or Chromium process started with remote debugging enabled;
141
- - a cloud browser session that gives you a CDP websocket URL;
142
- - any other browser runtime that Playwright can reach through CDP.
141
+ - a local Chrome or Chromium started with the `--remote-debugging-port` flag;
142
+ - a managed cloud browser (Browserbase, Browserless, and similar) that hands
143
+ you a WebSocket URL;
144
+ - any other browser runtime Playwright can reach through CDP.
143
145
 
144
146
  ```ts
145
147
  import { attach, observe } from '@mercuryo-ai/agentbrowse';
@@ -164,6 +166,11 @@ const attached = await attach(remoteCdpUrl, {
164
166
  });
165
167
  ```
166
168
 
169
+ `attach(...)` is not a separate reconnect mode. It is the second bootstrap
170
+ path into the same sticky-owner execution model as `launch(...)`. After
171
+ attach succeeds, later browser commands reuse or repair that owner instead of
172
+ performing a fresh provider-level root attach on every healthy command.
173
+
167
174
  ## What Each Main API Does
168
175
 
169
176
  | API | Use it when | Typical result |
@@ -198,8 +205,8 @@ In practice, that mainly means:
198
205
  - `extract(...)`
199
206
  - better quality goal-based `observe(session, goal)`
200
207
 
201
- The runtime contract is intentionally small: you provide an object that can
202
- create an OpenAI-compatible chat-completions client.
208
+ The runtime interface is intentionally small: you provide an object that
209
+ can create an OpenAI-compatible chat-completions client.
203
210
 
204
211
  ```ts
205
212
  // Pseudocode shape only. For a runnable fetch-based adapter, see
@@ -246,6 +253,18 @@ store.save(session);
246
253
  const restoredFromCustomRoot = store.load();
247
254
  ```
248
255
 
256
+ Persisted session files contain versioned sticky-owner metadata, not a live
257
+ Playwright connection. `loadBrowserSession()` and custom stores intentionally
258
+ return `null` for incompatible reconnect-era records or incomplete owner
259
+ metadata instead of auto-migrating them. After loading a session, call
260
+ `status(restored)` or let the next browser command verify or repair
261
+ ownership. If the underlying browser is gone, the session fails closed and
262
+ you start fresh with `launch(...)` or `attach(...)`.
263
+
264
+ There is no separate daemon API to supervise. `close(session)` is the public
265
+ lifecycle boundary for shutting down the internal owner host and, when
266
+ applicable, the managed browser itself.
267
+
249
268
  If you want to use a proxy, pass it directly to `launch(...)`:
250
269
 
251
270
  ```ts
@@ -278,7 +297,7 @@ See:
278
297
  ## Testing Wrappers Around AgentBrowse
279
298
 
280
299
  If your package wraps AgentBrowse and you want a stable test helper for the
281
- assistive runtime contract, use the dedicated testing subpath:
300
+ assistive runtime, use the dedicated testing subpath:
282
301
 
283
302
  ```ts
284
303
  import {
@@ -4,6 +4,29 @@ import type { ProxyConfig } from './solver/types.js';
4
4
  export interface BrowserSessionCapabilities {
5
5
  captchaSolve?: boolean;
6
6
  }
7
+ export declare const STICKY_OWNER_SCHEMA_VERSION: 1;
8
+ export type StickyOwnerState = 'bootstrapping' | 'active' | 'recovering' | 'dead';
9
+ export interface StickyOwnerPlaywrightBindTransport {
10
+ type: 'playwright_bind';
11
+ endpoint: string;
12
+ mode: 'pipe' | 'ws';
13
+ }
14
+ export interface StickyOwnerInProcessTransport {
15
+ type: 'in_process';
16
+ }
17
+ export type StickyOwnerTransport = StickyOwnerPlaywrightBindTransport | StickyOwnerInProcessTransport;
18
+ export interface StickyOwnerMetadata {
19
+ version: typeof STICKY_OWNER_SCHEMA_VERSION;
20
+ hostId: string;
21
+ state: StickyOwnerState;
22
+ startedAt: string;
23
+ lastUsedAt?: string;
24
+ ttlMs?: number;
25
+ touchPath?: string;
26
+ browserSessionId: string;
27
+ transport: StickyOwnerTransport;
28
+ pid?: number;
29
+ }
7
30
  /** Persisted browser session state shared across AgentBrowse commands. */
8
31
  export interface BrowserSessionState {
9
32
  cdpUrl: string;
@@ -15,6 +38,7 @@ export interface BrowserSessionState {
15
38
  transport?: BrowseSessionTransport;
16
39
  capabilities?: BrowserSessionCapabilities;
17
40
  runtime?: BrowseRuntimeState;
41
+ stickyOwner?: StickyOwnerMetadata;
18
42
  }
19
43
  /** Browser session state plus transient run-scoped metadata. */
20
44
  export interface BrowserCommandSession extends BrowserSessionState {
@@ -53,6 +77,21 @@ type AttachedBrowserSessionInput = Omit<BrowserSessionState, 'port' | 'identity'
53
77
  browserInstanceRef?: string;
54
78
  provider?: string;
55
79
  };
80
+ export declare function isStickyOwnerMetadata(value: unknown): value is StickyOwnerMetadata;
81
+ export declare function canPersistStickyOwnerMetadata(value: unknown): value is StickyOwnerMetadata & {
82
+ transport: StickyOwnerPlaywrightBindTransport;
83
+ };
84
+ export declare function buildStickyOwnerMetadata(input: {
85
+ hostId: string;
86
+ state: StickyOwnerState;
87
+ startedAt: string;
88
+ lastUsedAt?: string;
89
+ ttlMs?: number;
90
+ touchPath?: string;
91
+ browserSessionId: string;
92
+ transport: StickyOwnerTransport;
93
+ pid?: number;
94
+ }): StickyOwnerMetadata;
56
95
  export declare function parseSessionPort(cdpUrl: string): number | undefined;
57
96
  /** Converts a CDP websocket or HTTP endpoint into the matching DevTools HTTP endpoint. */
58
97
  export declare function buildCdpHttpEndpointUrl(cdpUrl: string, resourcePath?: '/json/version' | '/json/list'): string | null;
@@ -1 +1 @@
1
- {"version":3,"file":"browser-session-state.d.ts","sourceRoot":"","sources":["../src/browser-session-state.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,sEAAsE;AACtE,MAAM,WAAW,0BAA0B;IACzC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,0EAA0E;AAC1E,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,qBAAqB,CAAC;IACjC,SAAS,CAAC,EAAE,sBAAsB,CAAC;IACnC,YAAY,CAAC,EAAE,0BAA0B,CAAC;IAC1C,OAAO,CAAC,EAAE,kBAAkB,CAAC;CAC9B;AAED,gEAAgE;AAChE,MAAM,WAAW,qBAAsB,SAAQ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AAG,IAAI,GAAG,OAAO,CAEjF;AAED,iFAAiF;AACjF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,mBAAmB,GAAG,IAAI,GAAG,SAAS,GAC9C,OAAO,IAAI,mBAAmB,GAAG;IAAE,QAAQ,EAAE,qBAAqB,CAAA;CAAE,CAkBtE;AAED,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,mBAAmB,GAAG,IAAI,GAAG,SAAS,GAC9C,OAAO,IAAI,mBAAmB,GAAG;IAAE,QAAQ,EAAE,qBAAqB,CAAA;CAAE,CAWtE;AAED,4FAA4F;AAC5F,wBAAsB,cAAc,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,CAmBnF"}
@@ -2,6 +2,7 @@ import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, unlinkSync, wr
2
2
  import { homedir } from 'node:os';
3
3
  import { join } from 'node:path';
4
4
  import { scrubProtectedExactValues } from './secrets/protected-exact-value-redaction.js';
5
+ export const STICKY_OWNER_SCHEMA_VERSION = 1;
5
6
  const BLOCKED_SESSION_KEYS = new Set([
6
7
  'rawValue',
7
8
  'rawValues',
@@ -21,6 +22,67 @@ function ensureStateDir(stateDir) {
21
22
  mkdirSync(stateDir, { recursive: true });
22
23
  }
23
24
  }
25
+ function isStickyOwnerTransport(value) {
26
+ if (!value || typeof value !== 'object') {
27
+ return false;
28
+ }
29
+ const candidate = value;
30
+ if (candidate.type === 'in_process') {
31
+ return true;
32
+ }
33
+ if (candidate.type !== 'playwright_bind') {
34
+ return false;
35
+ }
36
+ const endpointCandidate = candidate.endpoint;
37
+ const endpoint = typeof endpointCandidate === 'string' ? endpointCandidate.trim() : '';
38
+ const mode = candidate.mode;
39
+ return endpoint.length > 0 && (mode === 'pipe' || mode === 'ws');
40
+ }
41
+ function isStickyOwnerState(value) {
42
+ return (value === 'bootstrapping' || value === 'active' || value === 'recovering' || value === 'dead');
43
+ }
44
+ export function isStickyOwnerMetadata(value) {
45
+ if (!value || typeof value !== 'object') {
46
+ return false;
47
+ }
48
+ const candidate = value;
49
+ return (candidate.version === STICKY_OWNER_SCHEMA_VERSION &&
50
+ typeof candidate.hostId === 'string' &&
51
+ candidate.hostId.trim().length > 0 &&
52
+ isStickyOwnerState(candidate.state) &&
53
+ typeof candidate.startedAt === 'string' &&
54
+ candidate.startedAt.trim().length > 0 &&
55
+ (candidate.lastUsedAt === undefined ||
56
+ (typeof candidate.lastUsedAt === 'string' && candidate.lastUsedAt.trim().length > 0)) &&
57
+ (candidate.ttlMs === undefined ||
58
+ (typeof candidate.ttlMs === 'number' &&
59
+ Number.isFinite(candidate.ttlMs) &&
60
+ candidate.ttlMs > 0)) &&
61
+ (candidate.touchPath === undefined ||
62
+ (typeof candidate.touchPath === 'string' && candidate.touchPath.trim().length > 0)) &&
63
+ typeof candidate.browserSessionId === 'string' &&
64
+ candidate.browserSessionId.trim().length > 0 &&
65
+ isStickyOwnerTransport(candidate.transport) &&
66
+ (candidate.pid === undefined ||
67
+ (typeof candidate.pid === 'number' && Number.isFinite(candidate.pid) && candidate.pid > 0)));
68
+ }
69
+ export function canPersistStickyOwnerMetadata(value) {
70
+ return isStickyOwnerMetadata(value) && value.transport.type === 'playwright_bind';
71
+ }
72
+ export function buildStickyOwnerMetadata(input) {
73
+ return {
74
+ version: STICKY_OWNER_SCHEMA_VERSION,
75
+ hostId: input.hostId,
76
+ state: input.state,
77
+ startedAt: input.startedAt,
78
+ ...(input.lastUsedAt ? { lastUsedAt: input.lastUsedAt } : {}),
79
+ ...(typeof input.ttlMs === 'number' ? { ttlMs: input.ttlMs } : {}),
80
+ ...(input.touchPath ? { touchPath: input.touchPath } : {}),
81
+ browserSessionId: input.browserSessionId,
82
+ transport: input.transport,
83
+ ...(typeof input.pid === 'number' ? { pid: input.pid } : {}),
84
+ };
85
+ }
24
86
  function atomicWriteJson(path, contents) {
25
87
  const tempPath = `${path}.${process.pid}.tmp`;
26
88
  try {
@@ -136,7 +198,7 @@ export function createBrowserSessionStore(options = {}) {
136
198
  }
137
199
  try {
138
200
  const raw = JSON.parse(readFileSync(sessionPath, 'utf-8'));
139
- if (!raw.cdpUrl) {
201
+ if (!raw.cdpUrl || !canPersistStickyOwnerMetadata(raw.stickyOwner)) {
140
202
  return null;
141
203
  }
142
204
  return raw;
@@ -1,8 +1,8 @@
1
- const DEFAULT_BROWSE_COMMAND = 'agentbrowse';
2
1
  function normalizeCommandName(value, fallback) {
3
2
  const normalized = value?.trim().replace(/\s+/g, ' ');
4
3
  return normalized && normalized.length > 0 ? normalized : fallback;
5
4
  }
5
+ const DEFAULT_BROWSE_COMMAND = 'agentbrowse';
6
6
  export function browseCommandName() {
7
7
  return normalizeCommandName(process.env.AGENTBROWSE_COMMAND, DEFAULT_BROWSE_COMMAND);
8
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"act.d.ts","sourceRoot":"","sources":["../../src/commands/act.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAYzE,OAAO,EAIL,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EAClB,MAAM,cAAc,CAAC;AA6BtB,OAAO,EAAE,cAAc,EAAE,KAAK,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AA4CxF,2DAA2D;AAC3D,eAAO,MAAM,eAAe,oWAgBlB,CAAC;AAEX,uDAAuD;AACvD,eAAO,MAAM,iBAAiB,8FAMpB,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAC5D,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhE,8CAA8C;AAC9C,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG;IAC5C,OAAO,EAAE,IAAI,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,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