foldrun 26.3.2 → 26.3.4
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/docs/browser.md +1 -1
- package/package.json +2 -2
- package/src/browser.mjs +35 -5
package/docs/browser.md
CHANGED
|
@@ -66,7 +66,7 @@ data centre. Clicks move the pointer the way a person's does.
|
|
|
66
66
|
| `browser_open` | open a page (the current tab or a new one) and read it |
|
|
67
67
|
| `browser_read` | read the current page again: the accessibility tree with a `[ref=eN]` on everything that can be acted on, or its text, markdown, links, tables, head |
|
|
68
68
|
| `browser_act` | steps in order — click, fill, type, press, choose, scroll, wait, go back, switch tabs, upload, download, read a value — then read the page; an element is named by its ref (`@e13`), a CSS selector or `text=…` |
|
|
69
|
-
| `browser_screenshot` | a picture of the page or one element |
|
|
69
|
+
| `browser_screenshot` | a picture of what is in view, the whole page (`full_page`) or one element; one too big to send (a very long page) is refused with what to take instead |
|
|
70
70
|
| `browser_wait_for_person` | hand the page to you; returns when the address changes, or the condition given (`until_url_contains`, `until_gone`, `until_visible`) |
|
|
71
71
|
| `browser_close` | close the window; the sign-ins stay |
|
|
72
72
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foldrun",
|
|
3
|
-
"version": "26.3.
|
|
3
|
+
"version": "26.3.4",
|
|
4
4
|
"description": "Agents are just folders. Write them, check them, run them — on your machine.",
|
|
5
5
|
"license": "FSL-1.1-ALv2",
|
|
6
6
|
"type": "module",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"node": ">=22"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@foldrun/core": "^24.2.
|
|
14
|
+
"@foldrun/core": "^24.2.2"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"bin",
|
package/src/browser.mjs
CHANGED
|
@@ -123,6 +123,20 @@ function liveRecord(paths) {
|
|
|
123
123
|
}
|
|
124
124
|
const pidAlive = (pid) => { if (!pid) return false; try { process.kill(pid, 0); return true; } catch { return false; } };
|
|
125
125
|
|
|
126
|
+
/** Whether the foldrun window is open: its Chrome running AND showing a page.
|
|
127
|
+
* On macOS, closing the last window leaves Chrome running with none, and a
|
|
128
|
+
* call would start a new window in front of the person who just closed it. */
|
|
129
|
+
export async function windowOpen(paths, fetcher = fetch) {
|
|
130
|
+
const live = liveRecord(paths);
|
|
131
|
+
if (!live?.alive) return false;
|
|
132
|
+
try {
|
|
133
|
+
const list = await (await fetcher(`${live.endpoint}/json/list`, { signal: AbortSignal.timeout(2_000) })).json();
|
|
134
|
+
return Array.isArray(list) && list.some((t) => t?.type === "page");
|
|
135
|
+
} catch {
|
|
136
|
+
return true; // not answering is no proof it is closed: the call says what happened
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
126
140
|
/** Whether a running process is the foldrun window's Chrome — its command line
|
|
127
141
|
* names this profile — false when it is something else (a pid in an old
|
|
128
142
|
* live.json may since be anything's), null when that cannot be told. */
|
|
@@ -260,7 +274,7 @@ export const TOOLS = [
|
|
|
260
274
|
inputSchema: {
|
|
261
275
|
type: "object",
|
|
262
276
|
properties: {
|
|
263
|
-
full_page: { type: "boolean", description: "the whole scrolling page,
|
|
277
|
+
full_page: { type: "boolean", description: "the whole scrolling page; without it, only what is in view. A long page can be too big to send" },
|
|
264
278
|
selector: { type: "string", description: "only this element" },
|
|
265
279
|
},
|
|
266
280
|
additionalProperties: false,
|
|
@@ -325,10 +339,18 @@ export async function callTool(ctx, name, args = {}, { sleep = (ms) => new Promi
|
|
|
325
339
|
}
|
|
326
340
|
case "browser_screenshot": {
|
|
327
341
|
const file = `outputs/screenshot-${Date.now()}.png`;
|
|
328
|
-
|
|
342
|
+
// The program photographs the whole page unless told otherwise; say
|
|
343
|
+
// which, every time. A long page (a 450-comment thread) made a 23 MB
|
|
344
|
+
// picture that closed the app's MCP connection.
|
|
345
|
+
const step = { screenshot: file, full: args.full_page === true, ...(typeof args.selector === "string" && args.selector ? { selector: args.selector } : {}) };
|
|
329
346
|
const r = await runBrowse(ctx, [...live, "--actions", JSON.stringify([step, { get: "url" }])]);
|
|
330
347
|
const abs = path.join(ctx.paths.work, file);
|
|
331
348
|
if (r.code !== 0 || !fs.existsSync(abs)) return textResult(shapeOutput(r), true);
|
|
349
|
+
const bytes = fs.statSync(abs).size;
|
|
350
|
+
if (bytes > MAX_SHOT_BYTES) {
|
|
351
|
+
fs.rmSync(abs, { force: true });
|
|
352
|
+
return textResult(`the picture is ${(bytes / 1e6).toFixed(1)} MB, too big to send (limit ${(MAX_SHOT_BYTES / 1e6).toFixed(1)} MB). Take what is in view (no full_page), one element (selector), or read the page as text with browser_read.`, true);
|
|
353
|
+
}
|
|
332
354
|
const data = fs.readFileSync(abs).toString("base64");
|
|
333
355
|
fs.rmSync(abs, { force: true });
|
|
334
356
|
const url = /"value":\s*"([^"]+)"/.exec(r.stdout)?.[1];
|
|
@@ -345,6 +367,11 @@ export async function callTool(ctx, name, args = {}, { sleep = (ms) => new Promi
|
|
|
345
367
|
}
|
|
346
368
|
}
|
|
347
369
|
|
|
370
|
+
/** The largest picture browser_screenshot sends: model APIs refuse an image
|
|
371
|
+
* over 5 MB as base64 (about 3.7 MB of file), and a bigger MCP message can
|
|
372
|
+
* close the app's connection. */
|
|
373
|
+
export const MAX_SHOT_BYTES = 3_700_000;
|
|
374
|
+
|
|
348
375
|
/** Ask the page where it is, without changing it. */
|
|
349
376
|
async function probe(ctx, args) {
|
|
350
377
|
const steps = [{ get: "url" }];
|
|
@@ -359,8 +386,11 @@ async function probe(ctx, args) {
|
|
|
359
386
|
}
|
|
360
387
|
}
|
|
361
388
|
|
|
389
|
+
const CLOSED = "the person closed the Chrome window — ask them whether they finished, then browser_open the page again (logins they made are kept)";
|
|
390
|
+
|
|
362
391
|
async function waitForPerson(ctx, args, { sleep, now }) {
|
|
363
392
|
const timeout = Math.min(900, Math.max(15, Number(args.timeout_seconds) || 300)) * 1000;
|
|
393
|
+
if (!(await windowOpen(ctx.paths))) return textResult("the Chrome window is not open — browser_open the page to hand over first", true);
|
|
364
394
|
const first = await probe(ctx, args);
|
|
365
395
|
if (!first) return textResult("could not read the page to watch it — is the window open? browser_open a page first", true);
|
|
366
396
|
const start = first.url;
|
|
@@ -376,8 +406,7 @@ async function waitForPerson(ctx, args, { sleep, now }) {
|
|
|
376
406
|
const deadline = now() + timeout;
|
|
377
407
|
while (now() < deadline) {
|
|
378
408
|
await sleep(3_000);
|
|
379
|
-
|
|
380
|
-
if (live && !live.alive) return textResult("the person closed the Chrome window — ask them whether they finished, then browser_open the page again (logins they made are kept)", true);
|
|
409
|
+
if (!(await windowOpen(ctx.paths))) return textResult(CLOSED, true);
|
|
381
410
|
const p = await probe(ctx, args);
|
|
382
411
|
if (p && done(p)) return finish(ctx, `the person is done (${args.reason ?? "their part"}) — now on ${p.url}`);
|
|
383
412
|
}
|
|
@@ -588,7 +617,8 @@ export async function browserCmd(positional, flags, deps) {
|
|
|
588
617
|
console.log(` ${ok(p.browse)} browser program ${p.browse ? `${new URL(/** @type {string} */ (p.url)).host} ${c.dim(p.browse)}` : (p.note ?? "not fetched — foldrun browser setup")}`);
|
|
589
618
|
console.log(` ${ok(have && have === want)} Playwright ${have ?? "not installed"}${want && have !== want ? c.amber(` (the program wants ${want} — foldrun browser setup)`) : ""}`);
|
|
590
619
|
console.log(` ${c.dim("·")} profile ${live?.root ?? paths.chrome}${live && live.root !== paths.chrome ? c.amber(" (temp folder: this platform's browser program predates a fixed profile)") : ""}`);
|
|
591
|
-
|
|
620
|
+
const open = await windowOpen(paths);
|
|
621
|
+
console.log(` ${c.dim("·")} window ${open ? `open ${c.dim(`(pid ${live?.pid})`)}` : live?.alive ? `closed ${c.dim("(Chrome still running with no window; the next call opens one)")}` : "closed"}`);
|
|
592
622
|
console.log(`\n ${c.dim("verbs: setup, open [url], close, reset, mcp — `foldrun browser --help`")}\n`);
|
|
593
623
|
return chrome && p.browse && have === want ? 0 : 1;
|
|
594
624
|
}
|