turno-cli 0.3.0 → 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/CHANGELOG.md +118 -0
- package/README.md +7 -3
- package/dist/cli/commands/browser-do-session.js +170 -0
- package/dist/cli/commands/browser-do.js +740 -0
- package/dist/cli/commands/browser-flows.js +300 -0
- package/dist/cli/commands/browser-identity.js +445 -7
- package/dist/cli/commands/browser-live.js +118 -0
- package/dist/cli/commands/browser.js +147 -6
- package/dist/cli/commands/identity.js +2 -0
- package/dist/cli/commands/mcp-call.js +2 -2
- package/dist/cli/topics.js +13 -0
- package/dist/mcpd/health.js +1 -1
- package/dist/mcpd/instances.js +11 -1
- package/dist/mcpd/middleware.js +15 -3
- package/dist/mcpd/peerpid.js +52 -18
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,123 @@
|
|
|
1
1
|
# turno-cli
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 50facc9: Record and replay. `browser_record` saves an agent's actions on an identity as a named flow, each
|
|
8
|
+
element kept four ways (Playwright's locator, role and name, text, CSS path) and typed text as
|
|
9
|
+
parameters; passwords, one-time codes and values marked sensitive are never saved, and a vault
|
|
10
|
+
sign-in is kept as `browser_login` with the site name. `browser_replay` runs a flow with
|
|
11
|
+
parameters (`keychain:<item>` reads one from the secret store) and, when a step no longer fits,
|
|
12
|
+
stops with a report the agent can continue from; `browser_flows` lists them. Opt-in per identity
|
|
13
|
+
(`record` in identity.json, `turno browser record <id>`): every session as a flow, Playwright
|
|
14
|
+
traces and a screenshot per action under a size cap, with the trace stopped around sign-ins.
|
|
15
|
+
New commands `turno browser flows|replay|record|traces`; `traces --open` uses the trace viewer
|
|
16
|
+
bundled with patchright-core.
|
|
17
|
+
With `"sharing": "tabs"` a recording holds only the session that started it and replay runs in
|
|
18
|
+
that session's tabs; traces and screenshots are refused in attach mode and in read mode.
|
|
19
|
+
- e94a153: Natural language actions and captcha solving for browser identities, both not recommended and off by default.
|
|
20
|
+
|
|
21
|
+
- `turno identity set browser:<id> --act` lists `browser_act` (an instruction carried out one stock browser action at a time, every step shown), `browser_extract` (data off the page as JSON) and `browser_observe` (proposed calls, not run). The model is your client's, through MCP sampling, or a chat completions API you name with `--act-provider chat-completions --act-endpoint <url> --act-model <name> --act-key keychain:<item>`. The model sees the instruction and a snapshot of the current tab with vault values and password, one-time code and card fields hidden; it can only click, type, select, press keys, hover, drag, wait and go back on that tab; steps, tokens and time are capped per call (`--act-max-steps`, `--act-max-tokens`, `--act-timeout`). A recorded flow keeps the stock steps it chose, never the instruction or the page.
|
|
22
|
+
- `--captcha-provider task-api --captcha-endpoint <url> --captcha-key keychain:<item>` lists `browser_solve_captcha`, which sends a reCAPTCHA v2, hCaptcha or Turnstile widget and the page address to that solver service and puts the token into the page. The service sees the page, and solving a site's captchas by machine may break its terms: it is meant for your own accounts. Every attempt is a line in the identity's reputation log, and `turno browser reputation` shows a `solved` column once a solver answered. Read mode refuses it.
|
|
23
|
+
- Keys are only `keychain:` references read from the secret store at use time, refused as literal values without being echoed, and hidden from every result.
|
|
24
|
+
- identity.json format 8 (`act`, `captcha`); turno-browser API 1.7, which turno-cli now requires.
|
|
25
|
+
- dcc2b97: Two opt-in engines for browser identities and servers, both off by default.
|
|
26
|
+
|
|
27
|
+
Read mode runs an identity (or one server) on Lightpanda instead of Chrome, for reading pages
|
|
28
|
+
with a fraction of the memory: `turno browser set <id> --engine lightpanda`, or
|
|
29
|
+
`turno-browser-mcp --engine lightpanda`. turno never downloads Lightpanda; it runs the
|
|
30
|
+
`lightpanda` on your PATH (or at `TURNO_LIGHTPANDA_PATH`), on a private Unix socket with
|
|
31
|
+
Lightpanda's telemetry off. The tools that work there run; the others (screenshots, dialogs,
|
|
32
|
+
drag and drop, uploads, `browser_login`) are refused with the reason before they reach the
|
|
33
|
+
browser. An identity in read mode keeps its own cookie jar, apart from its Chrome profile.
|
|
34
|
+
|
|
35
|
+
Attach mode connects to the Chrome you already have open, so the agent works in your signed-in
|
|
36
|
+
browser: `turno browser set <id> --attach auto` (after you turn on remote debugging at
|
|
37
|
+
chrome://inspect/#remote-debugging, Chrome 144 or newer), a Chrome user data folder, or a
|
|
38
|
+
loopback endpoint; `turno-browser-mcp --attach <target>` for one server. Chrome asks you to allow
|
|
39
|
+
each connection. turno works in a tab of its own, closes only the tabs it opened (on
|
|
40
|
+
`browser_close`, at the end of the session and at the idle limit) and never closes Chrome; the
|
|
41
|
+
tab governor leaves your tabs alone, and `browser_run_code_unsafe` is refused.
|
|
42
|
+
|
|
43
|
+
`turno browser doctor` gains an Engines section (Lightpanda found or how to install it, a
|
|
44
|
+
Lightpanda left running, which `--fix` stops) and checks each identity's attach target without
|
|
45
|
+
connecting. identity.json is now format 6 (`engine`, `attach`), and the turno-browser API is 1.5.
|
|
46
|
+
|
|
47
|
+
Read mode works with `"sharing": "tabs"`. Two pairs are refused with the reason, in identity.json
|
|
48
|
+
and from server flags: attach mode with `"sharing": "tabs"` (turno keeps one agent's tabs apart
|
|
49
|
+
from yours in your Chrome, not several sessions apart), and read mode with `humanize` (Lightpanda
|
|
50
|
+
lays out no page, so there is no pointer path to play). Attach mode works with `humanize`.
|
|
51
|
+
- 4814fb8: Human-like input for browser identities, off by default. `turno identity set browser:<id> --humanize light|full|adaptive` (or `turno-browser-mcp --humanize <level>`, which wins) makes the stock click, hover, type, fill form, select, drag, press key and coordinate tools, and `browser_batch`, move the pointer along a curve from where it last was to a point inside the target, hold the button for tens of milliseconds and type short text key by key with per-key delays. `full` adds a move time that follows distance and target size, overshoot and correction, a reading pause on a new page, longer gaps between words and wheel scrolling; `adaptive` is `light`, and `full` on a site where the identity met a challenge page. Tool names, arguments and results do not change. The setting is the `humanize` key of identity.json (format 4, with an optional `seed`), and turno-cli needs turno-browser API 1.3 for it.
|
|
52
|
+
- bf1cafb: `turno browser do <id> <action>` drives a browser identity from the shell, for coding agents that
|
|
53
|
+
prefer commands to MCP tools: `open`, `back`, `snapshot`, `read`, `find`, `click`, `type`,
|
|
54
|
+
`press`, `select`, `hover`, `wait`, `screenshot`, `tabs`, `login` (a vault sign-in), `call` (any
|
|
55
|
+
tool of the server), `close`, `session` and `end`. Each action is one tool call through mcpd to the
|
|
56
|
+
identity's turno-browser-mcp, so the tab locks or the one-session lease, attach mode, read mode's
|
|
57
|
+
refusals, humanize, recordings and the vault apply as they do to an agent. The commands one agent
|
|
58
|
+
or one terminal shell runs are one session and keep their tab: turno keeps the mcpd session open
|
|
59
|
+
between them and ties it to the agent (or the shell), and `end` closes it; `--session <name>` or
|
|
60
|
+
`TURNO_BROWSER_SESSION` keeps several apart. Output is `url:` and `title:` lines and what the
|
|
61
|
+
action returned, errors on stderr with exit 1, or one object with `--json`. `turno browser <id>
|
|
62
|
+
<action>` is the short form when the id is not a subcommand. The Claude Code plugin adds a short
|
|
63
|
+
`browser-identity` skill that teaches the loop and reads the installed help first.
|
|
64
|
+
- 6698608: Live view and take-over for browser identities, off by default. `turno browser set <id> --live true` (or `turno-browser-mcp --live`) serves a view of the agent's tab on 127.0.0.1 with a per-server token; `turno browser live <id>` opens it through a link that works once and is never printed. `turno browser pause <id>` (or Pause in the view) holds the agent's next call, up to `live.wait` (2 minutes by default), while you act in the window or through the view; `turno browser resume <id>` lets it go, and each held call is told what changed (URL, title, tabs, your input) and a call that would act on stale refs is not run: it returns an error with a fresh snapshot. The natural language and captcha tools are held too, and a `browser_act` run stops at its next step. A page that holds a vault value or a password is never shown, including a sign-in typed key by key with humanize. Read mode and attach mode refuse the view and keep pause and resume. turno-browser API 1.9, identity.json format 10.
|
|
65
|
+
- c716051: Opt-in network and user agent settings, and a Camoufox engine, all off by default and not
|
|
66
|
+
recommended for your own accounts. identity.json format 11 adds `userAgent` and `proxy`, and the
|
|
67
|
+
`engine` key takes `"camoufox"` (also format 11); API_VERSION is 1.10 and turno-cli needs it.
|
|
68
|
+
`"userAgent": "coherent"` takes no typed value: a headless Chrome gets the user agent a headed one
|
|
69
|
+
of the same version sends, with its real client hints metadata, and a launch check refuses any
|
|
70
|
+
contradiction between the user agent, client hints, platform, headers, languages and time zone.
|
|
71
|
+
`proxy` sends the identity's traffic (sign-ins included) through an http, https or SOCKS proxy,
|
|
72
|
+
with its password only from the secret store, hidden from every tool result, and WebRTC limited
|
|
73
|
+
to the proxy. `--engine camoufox` runs an identity on an installed Camoufox through stock
|
|
74
|
+
playwright-core, with its own Firefox profile; turno never downloads it, and every stock tool but
|
|
75
|
+
`browser_run_code_unsafe` runs, as do natural language actions, `browser_login` and
|
|
76
|
+
`turno browser do`. Captcha solving is refused with it, and the live view shows no picture there
|
|
77
|
+
(pause and resume work). The act model's prompt and the live view's tab list hide the proxy
|
|
78
|
+
credentials. New flags on `turno identity set` (`--user-agent`,
|
|
79
|
+
`--proxy-server`, `--proxy-username`, `--proxy-password`, `--no-proxy`), doctor checks for
|
|
80
|
+
Camoufox and the proxy credentials, and fingerprint bench checks that compare headers and a
|
|
81
|
+
worker with the page.
|
|
82
|
+
- 4b9556f: Several agent sessions can now share one browser identity, each in its own tabs. Turn it on per identity with `"sharing": "tabs"` in identity.json (`turno identity set browser:<id> --sharing tabs`, or the server's `--sharing tabs`) and serve the identity with `exclusive = false` in mcp.toml; the default stays one session at a time. Each session gets its own current tab and holds the tabs it works on: another session's call on one of them waits up to 10 seconds and then fails with a message that names the holder. A session lets go of its tabs when it ends (mcpd now tells servers that declare the `io.turno/sessions` capability), when a tab closes, or after 5 minutes without a call. `browser_close` closes only the calling session's tabs, tab lists mark the tabs other sessions hold, and the tab governor's cap counts each session's tabs apart. `turno identity add browser:<id> --sharing tabs` prints the matching mcp.toml block. turno-browser's API version is now 1.4.
|
|
83
|
+
- 3bd7bc2: Follow-ups for browser identities.
|
|
84
|
+
|
|
85
|
+
A tool call no longer starts while the tab governor is still closing a popup or a parked tab, so
|
|
86
|
+
the call cannot fail with "Target page, context or browser has been closed". A Chrome that does
|
|
87
|
+
not stop after SIGKILL gets 5 seconds instead of 2 before turno calls it a survivor.
|
|
88
|
+
|
|
89
|
+
A server in read mode stops a Lightpanda that a killed server left running on the same cookie jar
|
|
90
|
+
when it starts, and removes its socket folder.
|
|
91
|
+
|
|
92
|
+
`turno browser doctor` warns when an identity that serves one session at a time
|
|
93
|
+
(`"sharing": "session"`) is served by an mcp.toml server with `exclusive = false`, and says how to
|
|
94
|
+
switch it to `"sharing": "tabs"`.
|
|
95
|
+
|
|
96
|
+
The tab lock wait (10 seconds) and the idle release (5 minutes) of `"sharing": "tabs"` can be set
|
|
97
|
+
per identity: `"tabLocks": { "wait": "30s", "release": "10m" }` in identity.json, or
|
|
98
|
+
`turno browser set <id> --tab-lock-wait 30s --tab-lock-release 10m`. identity.json is now format
|
|
99
|
+
9 and the turno-browser API is 1.8.
|
|
100
|
+
|
|
101
|
+
The `light` humanize level moves the pointer on a visible arc (some 4 to 8% longer than the
|
|
102
|
+
straight line) instead of an almost straight path. With humanize on, `browser_login` clicks into
|
|
103
|
+
each field and types the value key by key; the keys go to Chrome only, never to a result, a
|
|
104
|
+
recording or a log.
|
|
105
|
+
|
|
106
|
+
When another element covers the target of a click, hover, type, select or drag before the call,
|
|
107
|
+
and still covers it 300 ms later, the error names that element at once instead of after the 5
|
|
108
|
+
second action timeout.
|
|
109
|
+
|
|
110
|
+
Chrome keeps its third-party storage partitioning on, as a person's Chrome does: Playwright turns
|
|
111
|
+
it off, and turno now passes Playwright's list of disabled features without it.
|
|
112
|
+
|
|
113
|
+
### Patch Changes
|
|
114
|
+
|
|
115
|
+
- 31a9a36: `turno doctor`, `turno status`, `turno mcp daemon status` and `turno doctor --security` no longer
|
|
116
|
+
wait for lsof to tell who holds mcpd's port. A free port is told by a refused connection, and a
|
|
117
|
+
running mcpd's port is checked against the pid it reports, so lsof's scan of every process (which
|
|
118
|
+
takes seconds on a busy Mac) runs only when another process holds the port. When lsof cannot say
|
|
119
|
+
which process that is, doctor still reports the port as in use.
|
|
120
|
+
|
|
3
121
|
## 0.3.0
|
|
4
122
|
|
|
5
123
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -258,6 +258,7 @@ change, and print the `turno undo <stamp>` that puts them back. `turno mcp impor
|
|
|
258
258
|
| `turno browser identities\|add\|show\|set\|login\|remove` | browser identities and their settings (needs `turno-browser`) |
|
|
259
259
|
| `turno browser vault add\|list\|remove\|submit` | sign-in credentials per site in the OS secret store, filled by the `browser_login` tool |
|
|
260
260
|
| `turno browser export <id> --out <file>`, `turno browser import <file>` | move an identity's session to another machine as one encrypted file |
|
|
261
|
+
| `turno browser flows\|replay <id>`, `turno browser record\|traces <id>` | saved flows and replaying them; opt-in recordings (flows, traces, screenshots) and the trace viewer |
|
|
261
262
|
| `turno browser doctor [--fix]`, `turno browser reputation [<id>]` | check Chrome and every identity; how often each site challenged it |
|
|
262
263
|
| `turno browser bench` | developer diagnostic: browser engine compatibility |
|
|
263
264
|
|
|
@@ -374,8 +375,10 @@ More in [Browser identities](https://turno.wimo.dev/docs/concepts/browser-identi
|
|
|
374
375
|
[`turno browser`](https://turno.wimo.dev/docs/reference/cli/browser).
|
|
375
376
|
|
|
376
377
|
**Acceptable use.** Use it with your own accounts, on sites whose terms allow automated access
|
|
377
|
-
by you, and at a human pace. Do not use it to get around access controls, paywalls
|
|
378
|
-
|
|
378
|
+
by you, and at a human pace. Do not use it to get around access controls, paywalls or rate
|
|
379
|
+
limits, to scrape at scale, or to access accounts that are not yours. Captcha solving and natural
|
|
380
|
+
language actions are off unless you turn them on per identity; both send page content to a third
|
|
381
|
+
party you pick, and captcha solving may break a site's terms.
|
|
379
382
|
|
|
380
383
|
### Accounts bridge
|
|
381
384
|
|
|
@@ -403,7 +406,8 @@ Details: [docs/ui.md](https://github.com/wimo-dev/turno/blob/main/docs/ui.md).
|
|
|
403
406
|
### Claude Code plugin
|
|
404
407
|
|
|
405
408
|
`plugins/turno` adds session handoff and fork skills, a `copy-artifact` skill that copies a
|
|
406
|
-
claude.ai artifact (with its files and assets) from one profile's account to another,
|
|
409
|
+
claude.ai artifact (with its files and assets) from one profile's account to another, a
|
|
410
|
+
`browser-identity` skill that drives a browser identity with `turno browser do`, and a hook
|
|
407
411
|
that records when a profile reaches its usage limit, so `turno status` can show it:
|
|
408
412
|
|
|
409
413
|
```
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { closeSync, openSync, readFileSync, readdirSync, rmSync, statSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, join } from "node:path";
|
|
3
|
+
import { ensurePrivateDir, writePrivateFile } from "turno-core/paths";
|
|
4
|
+
import { pidAlive } from "turno-core/process";
|
|
5
|
+
import { paths } from "../../core/paths.js";
|
|
6
|
+
import { UsageError } from "../io.js";
|
|
7
|
+
const SHELLS = new Set(["sh", "bash", "zsh", "dash", "fish", "ksh", "mksh", "ash", "csh", "tcsh"]);
|
|
8
|
+
const WRAPPERS = new Set(["env", "timeout", "gtimeout", "nice", "nohup", "stdbuf", "time", "xargs"]);
|
|
9
|
+
const RUNNERS = /^(pnpm|pnpx|npm|npx|yarn|bunx|corepack)(\.c?js)?$|^(npm|npx)-cli\.js$/;
|
|
10
|
+
function words(command) {
|
|
11
|
+
return command.trim().split(/\s+/);
|
|
12
|
+
}
|
|
13
|
+
function program(word) {
|
|
14
|
+
return basename(word ?? "").replace(/^-/, "");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* True for a process that only passes a command on: a shell started for one command (`zsh -c`,
|
|
18
|
+
* `bash -lc`, as coding agents run each command), a wrapper (`env`, `timeout`) or a package
|
|
19
|
+
* runner (`pnpm exec`). An interactive or login shell (`-zsh`, `bash`) and a script's shell
|
|
20
|
+
* (`bash script.sh`) are not: a session belongs to them.
|
|
21
|
+
*/
|
|
22
|
+
export function passesOn(command) {
|
|
23
|
+
const [first, ...rest] = words(command);
|
|
24
|
+
const name = program(first);
|
|
25
|
+
if (SHELLS.has(name))
|
|
26
|
+
return rest.some((w) => /^-[a-zA-Z]*c[a-zA-Z]*$/.test(w));
|
|
27
|
+
if (WRAPPERS.has(name))
|
|
28
|
+
return true;
|
|
29
|
+
if (RUNNERS.test(name))
|
|
30
|
+
return true;
|
|
31
|
+
if (name === "node" || name === "bun")
|
|
32
|
+
return RUNNERS.test(program(rest[0]));
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The owner of a CLI session started from `start` (the parent of this process). An agent that a
|
|
37
|
+
* turno launcher started names itself in TURNO_SESSION_PID (`agent`), the pid its own MCP
|
|
38
|
+
* sessions send: when that process is up the tree, it is the owner. Otherwise the first process
|
|
39
|
+
* up the tree that does not only pass a command on: inside Claude Code or Codex that is the
|
|
40
|
+
* agent, so its commands share one session; in a terminal it is the shell. Without a process
|
|
41
|
+
* table (no `ps`), the parent itself.
|
|
42
|
+
*/
|
|
43
|
+
export function sessionOwner(table, start = process.ppid, agent) {
|
|
44
|
+
if (table && agent && agent > 1) {
|
|
45
|
+
for (let pid = start, hops = 0; hops < 32; hops++) {
|
|
46
|
+
const info = table.get(pid);
|
|
47
|
+
if (!info)
|
|
48
|
+
break;
|
|
49
|
+
if (pid === agent)
|
|
50
|
+
return { pid, command: info.command };
|
|
51
|
+
if (info.ppid <= 1 || info.ppid === pid)
|
|
52
|
+
break;
|
|
53
|
+
pid = info.ppid;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
let pid = start;
|
|
57
|
+
for (let hops = 0; table && hops < 16; hops++) {
|
|
58
|
+
const info = table.get(pid);
|
|
59
|
+
if (!info)
|
|
60
|
+
break;
|
|
61
|
+
const parent = table.get(info.ppid);
|
|
62
|
+
if (!passesOn(info.command) || info.ppid <= 1 || !parent)
|
|
63
|
+
return { pid, command: info.command };
|
|
64
|
+
pid = info.ppid;
|
|
65
|
+
}
|
|
66
|
+
return { pid: start, command: table?.get(start)?.command ?? "" };
|
|
67
|
+
}
|
|
68
|
+
/** A short name for the owner in a message: its program (`claude`, `zsh`). */
|
|
69
|
+
export function ownerName(owner) {
|
|
70
|
+
const [first, second] = words(owner.command);
|
|
71
|
+
const name = program(first);
|
|
72
|
+
if ((name === "node" || name === "bun") && second)
|
|
73
|
+
return program(second).replace(/\.c?js$/, "");
|
|
74
|
+
return name || `pid ${owner.pid}`;
|
|
75
|
+
}
|
|
76
|
+
const NAME = /^[a-z0-9][a-z0-9_-]{0,39}$/;
|
|
77
|
+
/** `--session <name>`, else TURNO_BROWSER_SESSION, else "default". */
|
|
78
|
+
export function sessionName(flag, env) {
|
|
79
|
+
const name = flag ?? (env.TURNO_BROWSER_SESSION || "default");
|
|
80
|
+
if (!NAME.test(name))
|
|
81
|
+
throw new UsageError(`session name "${name}" must be 1 to 40 lowercase letters, digits, "-" or "_" (--session or TURNO_BROWSER_SESSION)`);
|
|
82
|
+
return name;
|
|
83
|
+
}
|
|
84
|
+
/** Where CLI sessions are saved: <state>/browser-do. */
|
|
85
|
+
export function sessionsDir(env) {
|
|
86
|
+
return join(paths(env).state, "browser-do");
|
|
87
|
+
}
|
|
88
|
+
export function sessionFile(env, identity, owner, name) {
|
|
89
|
+
return join(sessionsDir(env), `${identity}.${owner}.${name}.json`);
|
|
90
|
+
}
|
|
91
|
+
export function readSaved(file) {
|
|
92
|
+
try {
|
|
93
|
+
const s = JSON.parse(readFileSync(file, "utf8"));
|
|
94
|
+
if (s.v !== 1 || typeof s.sessionId !== "string" || typeof s.port !== "number" || !s.owner)
|
|
95
|
+
return undefined;
|
|
96
|
+
return s;
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export function writeSaved(file, saved, env) {
|
|
103
|
+
writePrivateFile(file, `${JSON.stringify(saved, null, 2)}\n`, env);
|
|
104
|
+
}
|
|
105
|
+
export function dropSaved(file) {
|
|
106
|
+
rmSync(file, { force: true });
|
|
107
|
+
}
|
|
108
|
+
/** Removes the saved sessions whose owner exited (mcpd dropped those sessions already). */
|
|
109
|
+
export function sweepSaved(env, alive = pidAlive) {
|
|
110
|
+
let names;
|
|
111
|
+
try {
|
|
112
|
+
names = readdirSync(sessionsDir(env));
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
for (const n of names) {
|
|
118
|
+
const m = /^[^.]+\.(\d+)\.[^.]+\.json$/.exec(n);
|
|
119
|
+
if (m && !alive(Number(m[1])))
|
|
120
|
+
dropSaved(join(sessionsDir(env), n));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Runs `fn` while holding `<file>.lock`, so two commands of one session started at once open one
|
|
125
|
+
* mcpd session, not two. A lock older than `staleMs` is from a command that died: taken over.
|
|
126
|
+
*/
|
|
127
|
+
export async function withLock(file, env, fn) {
|
|
128
|
+
const lock = `${file}.lock`;
|
|
129
|
+
const staleMs = 30_000;
|
|
130
|
+
const until = Date.now() + 10_000;
|
|
131
|
+
ensurePrivateDir(dirname(file), env);
|
|
132
|
+
for (;;) {
|
|
133
|
+
try {
|
|
134
|
+
closeSync(openSync(lock, "wx", 0o600));
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
if (err.code !== "EEXIST")
|
|
139
|
+
throw err;
|
|
140
|
+
let age = 0;
|
|
141
|
+
try {
|
|
142
|
+
age = Date.now() - statSync(lock).mtimeMs;
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (age > staleMs || Date.now() > until) {
|
|
148
|
+
rmSync(lock, { force: true });
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
return await fn();
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
rmSync(lock, { force: true });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The mcp.toml server that serves identity `id`: a stdio server with `--identity <id>` in its
|
|
163
|
+
* args (`browser-<id>` first, as `turno browser add` prints it).
|
|
164
|
+
*/
|
|
165
|
+
export function identityServer(manifest, id) {
|
|
166
|
+
const serves = (args) => args.some((a, i) => (a === "--identity" && args[i + 1] === id) || a === `--identity=${id}`);
|
|
167
|
+
const found = Object.values(manifest.servers).filter((s) => s.kind === "stdio" && serves(s.args));
|
|
168
|
+
return found.find((s) => s.name === `browser-${id}`) ?? found.sort((a, b) => a.name.localeCompare(b.name))[0];
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=browser-do-session.js.map
|