@useavalon/caelence-agent 0.2.5-canary.4 → 0.4.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.
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,11 +211,28 @@ 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:
217
229
 
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.
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.
219
234
 
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.
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.
221
236
 
222
237
  ## Memory
223
238
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useavalon/caelence-agent",
3
- "version": "0.2.5-canary.4",
3
+ "version": "0.4.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",
@@ -44,6 +44,9 @@
44
44
  "format": "biome format --write .",
45
45
  "check": "biome check --write .",
46
46
  "check:exports": "node scripts/check-exports.mjs",
47
+ "changeset": "changeset",
48
+ "version": "changeset version && bun install",
49
+ "release": "node scripts/release.mjs",
47
50
  "prepare": "[ -d .git ] && husky || true",
48
51
  "prepublishOnly": "bun run typecheck && bun run test && bun run check:exports",
49
52
  "desktop": "bun src/cli/main.ts desktop"
@@ -63,10 +66,12 @@
63
66
  "@langfuse/client": "^5.11.1",
64
67
  "@langfuse/otel": "^5.11.1",
65
68
  "@langfuse/tracing": "^5.11.1",
66
- "@opentelemetry/sdk-node": "^0.223.0"
69
+ "@opentelemetry/sdk-node": "^0.300.0"
67
70
  },
68
71
  "devDependencies": {
69
72
  "@biomejs/biome": "^2.5.2",
73
+ "@changesets/changelog-github": "^1.0.1",
74
+ "@changesets/cli": "^3.0.3",
70
75
  "@types/bun": "^1.3.14",
71
76
  "@types/react": "^18.3.18",
72
77
  "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(