@useavalon/caelence-agent 0.3.0 → 0.5.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 (49) hide show
  1. package/README.md +46 -8
  2. package/desktop/src/api.ts +1 -0
  3. package/desktop/src/desktop-turn.ts +7 -0
  4. package/desktop/src/stream.ts +1 -0
  5. package/desktop/src/thought.test.ts +16 -0
  6. package/desktop/src/thought.ts +15 -4
  7. package/desktop/src/turn-verbs.ts +14 -0
  8. package/package.json +12 -4
  9. package/src/browser/browser-use.test.ts +54 -2
  10. package/src/browser/browser-use.ts +75 -3
  11. package/src/browser/own-chrome.test.ts +593 -0
  12. package/src/browser/own-chrome.ts +542 -0
  13. package/src/cli/tui-progress.ts +15 -3
  14. package/src/cli/tui.tsx +7 -0
  15. package/src/config.ts +31 -2
  16. package/src/core/approval.test.ts +126 -0
  17. package/src/core/approval.ts +17 -0
  18. package/src/core/events.ts +12 -1
  19. package/src/core/host-extensions.test.ts +605 -0
  20. package/src/core/mcp.ts +7 -0
  21. package/src/core/mode.ts +5 -0
  22. package/src/core/run-turn.test.ts +85 -0
  23. package/src/core/run-turn.ts +145 -28
  24. package/src/core/strands.test.ts +89 -0
  25. package/src/core/strands.ts +3 -1
  26. package/src/decisions/shortcuts.ts +5 -0
  27. package/src/desktop/bridge.ts +66 -12
  28. package/src/desktop/host.test.ts +244 -0
  29. package/src/desktop/host.ts +59 -0
  30. package/src/index.ts +122 -4
  31. package/src/memory/brief.ts +62 -0
  32. package/src/memory/embeddings.ts +104 -0
  33. package/src/memory/extract.ts +9 -8
  34. package/src/memory/layered.test.ts +202 -0
  35. package/src/memory/layered.ts +125 -0
  36. package/src/memory/memory-store.test.ts +299 -0
  37. package/src/memory/memory-store.ts +295 -0
  38. package/src/memory/store.ts +70 -20
  39. package/src/observability/langfuse.ts +9 -2
  40. package/src/observability/types.ts +5 -0
  41. package/src/runtime.ts +253 -53
  42. package/src/status/categories.ts +64 -0
  43. package/src/status/default-verbs.ts +190 -0
  44. package/src/status/status-verb-categories.json +6167 -0
  45. package/src/status/status-verbs.test.ts +209 -0
  46. package/src/status/status-verbs.ts +62 -0
  47. package/src/tools/background.test.ts +304 -0
  48. package/src/tools/background.ts +432 -0
  49. package/src/tools/memory.ts +94 -0
package/README.md CHANGED
@@ -198,14 +198,12 @@ The model is pinned because probabilities shift between releases. If you change
198
198
 
199
199
  ## Browser
200
200
 
201
- The agent can drive a real Chrome window through [browser-use](https://docs.browser-use.com/open-source/introduction). It is off until you ask for it. Put `@browser` in a message and the browser tools are available for the rest of that chat, for example `@browser find the pricing page on example.com`.
201
+ The agent can drive Chrome. It is off until you ask for it. Put `@browser` in a message and the browser tools are available for the rest of that chat, for example `@browser find the pricing page on example.com`. It only runs in `agent` mode.
202
202
 
203
- It needs [`uv`](https://docs.astral.sh/uv/) on your `PATH`. The first use downloads browser-use (about 100 Python packages) and can take a minute. Later starts take a few seconds, and the server only starts when you first use it.
204
-
205
- To change the default, set `browser` in `harness.config.ts`:
203
+ There are two ways to run it. Set `browser` in `harness.config.ts`:
206
204
 
207
205
  ```ts
208
- browser: { enabled: true, headless: false },
206
+ browser: { enabled: true, backend: "separate" },
209
207
  ```
210
208
 
211
209
  | Setting | Effect |
@@ -213,16 +211,56 @@ browser: { enabled: true, headless: false },
213
211
  | `enabled` unset | On for chats where a message contains `@browser` |
214
212
  | `enabled: true` | Always available, no mention needed |
215
213
  | `enabled: false` | Never available, `@browser` is ignored |
216
- | `headless: true` | Run Chrome without a window. Default is a visible window |
214
+ | `backend: "separate"` | The default. Its own signed-out Chrome, through browser-use |
215
+ | `backend: "chrome"` | Your own Chrome, where you are already signed in, through Playwright MCP |
216
+ | `headless: true` | Separate backend only. Run Chrome without a window |
217
+
218
+ ### Separate Chrome (default)
219
+
220
+ Runs [browser-use](https://docs.browser-use.com/open-source/introduction). It needs [`uv`](https://docs.astral.sh/uv/). The first use downloads browser-use (about 100 Python packages) and can take a minute, and later starts take a few seconds. It starts when you first use it, and finds `uv` even when the app was launched from the Dock.
221
+
222
+ It uses its own Chrome profile in `~/.config/browseruse/profiles/default`, so it does not see your everyday sign-ins. Sign in once in that window and it stays. Telemetry and cloud sync are switched off. `browser_extract_content`, `browser_screenshot`, and browser-use's own sub-agent are not exposed, because they need a separate OpenAI key or return images. The tools are not gated by an approval prompt, so the agent is only told to ask before buying, sending, posting, or deleting.
223
+
224
+ ### Your own Chrome
225
+
226
+ Attaches to the Chrome you have open, with your logins, through [Playwright MCP](https://playwright.dev/mcp/configuration/browser-extension). It needs Node.js. Chrome has not allowed attaching to your normal profile through a debug port since version 136, so you turn on the supported switch once: open `chrome://inspect/#remote-debugging` in Chrome, tick **Allow remote debugging for this browser instance**, and approve the permission Chrome shows. Until you do, the agent gets those steps and passes them on.
227
+
228
+ Because the agent acts as you on every site you are signed in to, this backend is stricter:
229
+
230
+ - It attaches to the browser named by `browser.app`: `chrome` (default), `edge`, `arc`, `brave`, or `chromium`. It never falls back to a different one, so it cannot end up in a browser you did not choose. If that browser is not set up, the agent is told to say so, and the next turn tries again.
231
+ - It gets 13 page tools. JavaScript execution, file upload, and network inspection are not offered.
232
+ - It works only in a tab it opens itself. Closing and switching your tabs is refused, and so is navigating before it has its own tab, because navigation replaces the tab you are looking at.
233
+ - You are asked before it opens a site you did not name, clicks a button that commits something (post, send, buy, delete, and the Danish equivalents), accepts a dialog, or clicks any button after typing. The last one does not depend on the button's wording. An approval covers one action, and "always allow" and a host's auto-approve mode do not skip it.
234
+
235
+ These checks stand in front of a model. They are not a security boundary, and a page can still try to talk the agent into something. Playwright is pinned to 0.0.83.
217
236
 
218
- The tools are `browser_navigate`, `browser_get_state`, `browser_click`, `browser_type`, `browser_scroll`, `browser_get_html`, `browser_go_back`, and tab and session management. The agent reads the page as a list of numbered elements and clicks by number. They only run in `agent` mode.
237
+ ## Background agents
219
238
 
220
- browser-use uses its own Chrome profile in `~/.config/browseruse/profiles/default`, so it does not see your everyday Chrome sign-ins. Sign in once in that window and it stays. Telemetry and cloud sync are switched off. `browser_extract_content`, `browser_screenshot`, and browser-use's own sub-agent are not exposed, because they need a separate OpenAI key or return images. The agent is told to ask before buying, sending, posting, or deleting, but browser tool calls are not gated by an approval prompt the way `exec` is.
239
+ The agent can start subagents that run while it keeps working. `spawn_agent` returns an id at once, `await_agents` collects the reports, and `cancel_agent` stops one. Explore agents get only the tools that declare themselves read-only, and are the default; in ask and plan mode they are the only kind. An agent never outlives the turn that started it.
240
+
241
+ ```ts
242
+ export default {
243
+ subagents: {
244
+ exploreModel: "z-ai/glm-5.2", // a small fast model for search; defaults to the chat model
245
+ maxConcurrent: 4,
246
+ maxPerTurn: 12,
247
+ // background: false turns spawn_agent off and keeps the blocking `task` tool
248
+ },
249
+ };
250
+ ```
251
+
252
+ `HARNESS_EXPLORE_MODEL` and `HARNESS_SUBAGENT_MODEL` override the models. A host that calls `runTurn` itself builds the same tools with `createBackgroundAgents`.
221
253
 
222
254
  ## Memory
223
255
 
224
256
  Turn it on from the Memory tab or `/memory on` if you want later chats to keep prefs and project decisions. After a turn the model adds a few of those to `~/.harness/memory` and `.harness/memory`, and the next session only sees the ones that fit what you asked. `/memory` lists them, `/memory delete 1` removes a line, and `/memory pin 1` copies it into `AGENTS.md`.
225
257
 
258
+ Recall matches on words by default. Set `memory.embeddings.enabled` (or `HARNESS_MEMORY_EMBEDDINGS=<model>`) to also match on meaning; fact text is then sent to the embeddings endpoint of your OpenRouter base URL, and the vectors are kept in `vectors.json` beside the facts. When memory is on the agent also gets `memory_search` and `memory_save`.
259
+
260
+ A host keeps memory in its own database by passing a `MemoryStore` to `createHarness`, or by implementing `MemoryBackend` (load, insert, remove, and optionally a vector index) and wrapping it with `createMemoryStore`.
261
+
262
+ For shared context across a team, `createLayeredMemoryStore` reads several stores as one, narrowest first (a project, then its workspace). The agent writes to the narrowest layer only; `promote` moves a fact wider, which a host does when a person asks. `synthesizeMemoryBrief` turns a scope's facts into a short brief to put in the prompt.
263
+
226
264
  ## Library
227
265
 
228
266
  The desktop, the terminal UI, and `caelence chat -m` all call `createHarness`, so you can drive the same runtime from a bot, a script, or another host UI.
@@ -87,6 +87,7 @@ export type AgentEvent =
87
87
  }
88
88
  | { kind: "approval_request"; callId: string; toolName: string; input: Record<string, unknown> }
89
89
  | { kind: "session_meta"; sessionId: string; title: string }
90
+ | { kind: "status"; verbs: string[] }
90
91
  | {
91
92
  kind: "usage";
92
93
  promptTokens: number;
@@ -23,6 +23,7 @@ import {
23
23
  type StreamLine,
24
24
  truncateAfterUserTurn,
25
25
  } from "./stream";
26
+ import { setTurnVerbs } from "./turn-verbs";
26
27
 
27
28
  export function applyDesktopTurnEvent(
28
29
  event: AgentEvent,
@@ -42,6 +43,12 @@ export function applyDesktopTurnEvent(
42
43
  });
43
44
  setStatus("approval");
44
45
  }
46
+ if (event.kind === "status") {
47
+ setTurnVerbs(event.verbs);
48
+ // A new array so the thinking label renders again with the verbs.
49
+ setLines((prev) => [...prev]);
50
+ return false;
51
+ }
45
52
  setLines((prev) => applyEvent(prev, event));
46
53
  return event.kind === "completion" || event.kind === "error";
47
54
  }
@@ -152,6 +152,7 @@ export function applyEvent(lines: StreamLine[], event: AgentEvent): StreamLine[]
152
152
  case "usage":
153
153
  case "completion":
154
154
  case "approval_request":
155
+ case "status":
155
156
  return lines;
156
157
  }
157
158
  }
@@ -140,4 +140,20 @@ describe("thought fold", () => {
140
140
  expect(blocks[1].entries[0]).toEqual({ type: "note", text: "I should look this up." });
141
141
  expect(blocks[1].entries[1]?.type).toBe("tool");
142
142
  });
143
+
144
+ test("the turn's verbs replace the plain phrases", () => {
145
+ const verbs = ["Brewing", "Baking", "Kneading"];
146
+ expect(liveStatusPhrases([], true, verbs)).toEqual(verbs);
147
+ const reading = liveStatusPhrases(
148
+ [
149
+ { key: "t", type: "tool", name: "read_file", label: "Reading a.ts", status: "running" },
150
+ ] as never,
151
+ false,
152
+ verbs,
153
+ );
154
+ expect(reading[0]).toBe("Reading a.ts");
155
+ expect(reading).toContain("Brewing");
156
+ expect(reading).toContain("Baking");
157
+ expect(reading).not.toContain("Thinking");
158
+ });
143
159
  });
@@ -2,6 +2,7 @@ import { pipelineProgress } from "./pipeline";
2
2
  import { isPlatformTool } from "./platform";
3
3
  import type { StreamLine } from "./stream";
4
4
  import { eventCountSuffix } from "./tool-label";
5
+ import { turnVerbs } from "./turn-verbs";
5
6
 
6
7
  export type ToolLine = Extract<StreamLine, { type: "tool" }>;
7
8
 
@@ -66,8 +67,16 @@ export function warmupHeadline(seed: number): string {
66
67
  return WARMUP_PHRASES[Math.abs(seed) % WARMUP_PHRASES.length] ?? "Thinking";
67
68
  }
68
69
 
69
- export function liveStatusPhrases(tools: ToolLine[], warmup = false): string[] {
70
- if (warmup || tools.length === 0) return [...WARMUP_PHRASES];
70
+ /**
71
+ * The phrases the thinking label rotates through. `verbs` are the turn's verbs from its `status`
72
+ * event; without them the plain phrases are used.
73
+ */
74
+ export function liveStatusPhrases(
75
+ tools: ToolLine[],
76
+ warmup = false,
77
+ verbs: readonly string[] = turnVerbs(),
78
+ ): string[] {
79
+ if (warmup || tools.length === 0) return verbs.length > 0 ? [...verbs] : [...WARMUP_PHRASES];
71
80
  const pipe = pipelineProgress(tools);
72
81
  const out: string[] = [];
73
82
  if (pipe) {
@@ -86,8 +95,10 @@ export function liveStatusPhrases(tools: ToolLine[], warmup = false): string[] {
86
95
  }
87
96
  if (isWriteTool(current)) pushPhrase(out, "Editing");
88
97
  }
89
- pushPhrase(out, "Thinking");
90
- pushPhrase(out, "Looking this over");
98
+ // The tool label stays first; a couple of verbs fill the pauses between steps.
99
+ const [first, second] = verbs;
100
+ pushPhrase(out, first ?? "Thinking");
101
+ pushPhrase(out, second ?? "Looking this over");
91
102
  return out;
92
103
  }
93
104
 
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The verbs the current turn's `status` event carried. The thinking label reads them while it
3
+ * renders. They live outside React state because the label sits several layers below the place
4
+ * events arrive, and they change once per turn.
5
+ */
6
+ let verbs: readonly string[] = [];
7
+
8
+ export function setTurnVerbs(next: readonly string[]): void {
9
+ verbs = next.filter((verb) => verb.trim().length > 0);
10
+ }
11
+
12
+ export function turnVerbs(): readonly string[] {
13
+ return verbs;
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useavalon/caelence-agent",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Caelence agent: Strands turn loop, local tools, skills, evals, and a themable terminal UI.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -26,7 +26,8 @@
26
26
  "exports": {
27
27
  ".": "./src/index.ts",
28
28
  "./cli": "./src/cli/main.ts",
29
- "./observability": "./src/observability/index.ts"
29
+ "./observability": "./src/observability/index.ts",
30
+ "./status-verbs": "./src/status/status-verbs.ts"
30
31
  },
31
32
  "files": [
32
33
  "bin",
@@ -38,12 +39,15 @@
38
39
  ],
39
40
  "scripts": {
40
41
  "start": "bun bin/harness.ts",
41
- "test": "bun test src/browser src/decisions src/core src/tools src/skills src/evals src/cli src/observability src/desktop src/integrations src/media src/memory src/init.test.ts src/runtime.test.ts desktop/src/rich-text.test.ts desktop/src/stream.test.ts desktop/src/dictation.test.ts desktop/src/thought.test.ts desktop/src/queue.test.ts desktop/src/composer-files.test.ts desktop/src/tool-label.test.ts desktop/src/reply-sources.test.ts desktop/src/pipeline.test.ts desktop/src/preview-render.test.ts desktop/src/session-search.test.ts desktop/src/session-select.test.ts",
42
+ "test": "bun test src/status src/browser src/decisions src/core src/tools src/skills src/evals src/cli src/observability src/desktop src/integrations src/media src/memory src/init.test.ts src/runtime.test.ts desktop/src/rich-text.test.ts desktop/src/stream.test.ts desktop/src/dictation.test.ts desktop/src/thought.test.ts desktop/src/queue.test.ts desktop/src/composer-files.test.ts desktop/src/tool-label.test.ts desktop/src/reply-sources.test.ts desktop/src/pipeline.test.ts desktop/src/preview-render.test.ts desktop/src/session-search.test.ts desktop/src/session-select.test.ts",
42
43
  "typecheck": "bunx tsc --noEmit -p tsconfig.json",
43
44
  "lint": "biome ci .",
44
45
  "format": "biome format --write .",
45
46
  "check": "biome check --write .",
46
47
  "check:exports": "node scripts/check-exports.mjs",
48
+ "changeset": "changeset",
49
+ "version": "changeset version && bun install",
50
+ "release": "node scripts/release.mjs",
47
51
  "prepare": "[ -d .git ] && husky || true",
48
52
  "prepublishOnly": "bun run typecheck && bun run test && bun run check:exports",
49
53
  "desktop": "bun src/cli/main.ts desktop"
@@ -63,10 +67,14 @@
63
67
  "@langfuse/client": "^5.11.1",
64
68
  "@langfuse/otel": "^5.11.1",
65
69
  "@langfuse/tracing": "^5.11.1",
66
- "@opentelemetry/sdk-node": "^0.223.0"
70
+ "@opentelemetry/exporter-trace-otlp-http": ">=0.202.0 <0.300.0",
71
+ "@opentelemetry/otlp-exporter-base": ">=0.202.0 <0.300.0",
72
+ "@opentelemetry/sdk-node": ">=0.202.0 <0.300.0"
67
73
  },
68
74
  "devDependencies": {
69
75
  "@biomejs/biome": "^2.5.2",
76
+ "@changesets/changelog-github": "^1.0.1",
77
+ "@changesets/cli": "^3.0.3",
70
78
  "@types/bun": "^1.3.14",
71
79
  "@types/react": "^18.3.18",
72
80
  "husky": "^9.1.7",
@@ -3,11 +3,14 @@ import type { McpToolDefinition } from "../core/mcp.ts";
3
3
  import { READ_ONLY_ANNOTATIONS, textResult, UNKNOWN_TOOL_ANNOTATIONS } from "../core/mcp.ts";
4
4
  import {
5
5
  adaptBrowserTools,
6
+ BROWSER_USE_PYTHON,
6
7
  BROWSER_USE_SPEC,
7
8
  browserAccess,
8
9
  browserServerOptions,
9
10
  browserSetupHint,
10
11
  mentionsBrowser,
12
+ resolveUvx,
13
+ uvSearchDirs,
11
14
  } from "./browser-use.ts";
12
15
 
13
16
  function tool(name: string, reply = "ok", isError = false): McpToolDefinition {
@@ -52,9 +55,16 @@ describe("browserAccess", () => {
52
55
 
53
56
  describe("browserServerOptions", () => {
54
57
  test("pins browser-use and turns telemetry off", () => {
55
- const opts = browserServerOptions(undefined, "/tmp/x");
58
+ const opts = browserServerOptions(undefined, "/tmp/x", "uvx");
56
59
  expect(opts.command).toBe("uvx");
57
- expect(opts.args).toEqual(["--from", BROWSER_USE_SPEC, "browser-use", "--mcp"]);
60
+ expect(opts.args).toEqual([
61
+ "--python",
62
+ BROWSER_USE_PYTHON,
63
+ "--from",
64
+ BROWSER_USE_SPEC,
65
+ "browser-use",
66
+ "--mcp",
67
+ ]);
58
68
  expect(opts.env?.ANONYMIZED_TELEMETRY).toBe("false");
59
69
  expect(opts.env?.BROWSER_USE_CLOUD_SYNC).toBe("false");
60
70
  expect(opts.env).not.toHaveProperty("BROWSER_USE_HEADLESS");
@@ -129,3 +139,45 @@ describe("browserSetupHint", () => {
129
139
  expect(hint.split("\n")).toHaveLength(6);
130
140
  });
131
141
  });
142
+
143
+ describe("resolveUvx", () => {
144
+ const home = "/Users/someone";
145
+
146
+ test("uses uvx from PATH when it is there", () => {
147
+ const exists = (path: string) => path === "/opt/tools/uvx";
148
+ expect(resolveUvx({ PATH: "/usr/bin:/opt/tools" }, exists, home)).toBe("/opt/tools/uvx");
149
+ });
150
+
151
+ test("finds uvx in the folders uv installs to when PATH is the minimal GUI one", () => {
152
+ const exists = (path: string) => path === `${home}/.local/bin/uvx`;
153
+ expect(resolveUvx({ PATH: "/usr/bin:/bin:/usr/sbin:/sbin" }, exists, home)).toBe(
154
+ `${home}/.local/bin/uvx`,
155
+ );
156
+ });
157
+
158
+ test("PATH wins over the fallback folders", () => {
159
+ const exists = (path: string) => path === "/custom/uvx" || path === `${home}/.local/bin/uvx`;
160
+ expect(resolveUvx({ PATH: "/custom" }, exists, home)).toBe("/custom/uvx");
161
+ });
162
+
163
+ test("works with no PATH at all", () => {
164
+ const exists = (path: string) => path === "/opt/homebrew/bin/uvx";
165
+ expect(resolveUvx({}, exists, home)).toBe("/opt/homebrew/bin/uvx");
166
+ });
167
+
168
+ test("falls back to the bare name when uv is not installed, so the error says so", () => {
169
+ expect(resolveUvx({ PATH: "/usr/bin" }, () => false, home)).toBe("uvx");
170
+ expect(browserSetupHint(new Error('Executable not found in $PATH: "uvx"'))).toContain(
171
+ "docs.astral.sh/uv",
172
+ );
173
+ });
174
+
175
+ test("searches the usual install folders", () => {
176
+ expect(uvSearchDirs(home)).toEqual([
177
+ `${home}/.local/bin`,
178
+ `${home}/.cargo/bin`,
179
+ "/opt/homebrew/bin",
180
+ "/usr/local/bin",
181
+ ]);
182
+ });
183
+ });
@@ -1,3 +1,6 @@
1
+ import { accessSync, constants } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { delimiter, join } from "node:path";
1
4
  import { type McpToolDefinition, READ_ONLY_ANNOTATIONS, toolResultText } from "../core/mcp.ts";
2
5
  import { loadStdioMcpTools, type StdioMcpClientOptions } from "../core/stdio-mcp.ts";
3
6
 
@@ -10,13 +13,35 @@ import { loadStdioMcpTools, type StdioMcpClientOptions } from "../core/stdio-mcp
10
13
  export interface BrowserConfig {
11
14
  /** undefined: on only when a message has @browser. true: always on. false: never. */
12
15
  enabled?: boolean;
13
- /** Run Chrome without a window. Default is a visible window. */
16
+ /** Run Chrome without a window. Default is a visible window. Only for the separate browser. */
14
17
  headless?: boolean;
18
+ /**
19
+ * Which Chrome to drive. `separate` (default) starts its own signed-out Chrome with browser-use.
20
+ * `chrome` attaches to the Chrome the user is running, where they are already signed in. That
21
+ * needs the switch at chrome://inspect/#remote-debugging turned on once.
22
+ */
23
+ backend?: "separate" | "chrome";
24
+ /**
25
+ * Which browser the `chrome` backend attaches to. `chrome` is the default. `arc` reads Arc's
26
+ * debugging port. Any other Chromium browser can be named by its user-data folder in
27
+ * `userDataDir`.
28
+ */
29
+ app?: "chrome" | "arc" | "brave" | "edge" | "chromium";
30
+ /** User-data folder of the browser to attach to, when `app` is not enough. */
31
+ userDataDir?: string;
32
+ /** Where to attach for the `chrome` backend. Wins over `app`. Mostly for tests. */
33
+ chromeEndpoint?: string;
15
34
  }
16
35
 
17
36
  /** Pinned to the line with `--mcp`. Unpinned `uvx` would follow upstream CLI rewrites. */
18
37
  export const BROWSER_USE_SPEC = "browser-use[cli]>=0.13,<0.14";
19
38
 
39
+ /**
40
+ * Ask uv for its own Python instead of whatever the environment exposes. A GUI app's minimal PATH
41
+ * finds Apple's Python 3.9, which browser-use rejects. uv downloads a matching one if needed.
42
+ */
43
+ export const BROWSER_USE_PYTHON = ">=3.11,<3.14";
44
+
20
45
  /** First start downloads about 100 Python packages, so give it far longer than a warm start. */
21
46
  export const BROWSER_INIT_TIMEOUT_MS = 180_000;
22
47
 
@@ -46,13 +71,51 @@ export function browserAccess(config: BrowserConfig | undefined): "off" | "menti
46
71
  return config?.enabled === true ? "always" : "mention";
47
72
  }
48
73
 
74
+ /** Where `uv` installs itself, for apps started from the Dock or Finder with a bare PATH. */
75
+ export function uvSearchDirs(home = homedir()): string[] {
76
+ return [
77
+ join(home, ".local", "bin"),
78
+ join(home, ".cargo", "bin"),
79
+ "/opt/homebrew/bin",
80
+ "/usr/local/bin",
81
+ ];
82
+ }
83
+
84
+ function isExecutable(path: string): boolean {
85
+ try {
86
+ accessSync(path, constants.X_OK);
87
+ return true;
88
+ } catch {
89
+ return false;
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Find `uvx`. A GUI app inherits a minimal PATH that leaves out the folders `uv` installs into,
95
+ * so look on PATH first and then in those folders. Falls back to the bare name, which fails with
96
+ * a clear "uv is not installed" message.
97
+ */
98
+ export function resolveUvx(
99
+ env: Record<string, string | undefined> = process.env,
100
+ exists: (path: string) => boolean = isExecutable,
101
+ home = homedir(),
102
+ ): string {
103
+ const dirs = [...(env.PATH ?? "").split(delimiter).filter(Boolean), ...uvSearchDirs(home)];
104
+ for (const dir of dirs) {
105
+ const candidate = join(dir, "uvx");
106
+ if (exists(candidate)) return candidate;
107
+ }
108
+ return "uvx";
109
+ }
110
+
49
111
  export function browserServerOptions(
50
112
  config: BrowserConfig | undefined,
51
113
  cwd: string,
114
+ uvx: string = resolveUvx(),
52
115
  ): StdioMcpClientOptions {
53
116
  return {
54
- command: "uvx",
55
- args: ["--from", BROWSER_USE_SPEC, "browser-use", "--mcp"],
117
+ command: uvx,
118
+ args: ["--python", BROWSER_USE_PYTHON, "--from", BROWSER_USE_SPEC, "browser-use", "--mcp"],
56
119
  cwd,
57
120
  namePrefix: "browser",
58
121
  initTimeoutMs: BROWSER_INIT_TIMEOUT_MS,
@@ -112,6 +175,15 @@ export function browserSetupHint(error: unknown): string {
112
175
  export interface BrowserSession {
113
176
  tools: McpToolDefinition[];
114
177
  close(): void;
178
+ /** Sites the user named, which the agent may open without asking. Own-Chrome backend only. */
179
+ trust?(hosts: readonly string[]): void;
180
+ /** Forget per-chat state, such as the agent's own tab. Own-Chrome backend only. */
181
+ reset?(): void;
182
+ /**
183
+ * True when the browser could not be reached. The server is fixed to the address it started
184
+ * with, so the runtime starts a new one on the next turn, after the user has set the browser up.
185
+ */
186
+ stale?(): boolean;
115
187
  }
116
188
 
117
189
  export async function startBrowserTools(