turno-cli 0.4.0 → 0.5.1

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 CHANGED
@@ -1,5 +1,41 @@
1
1
  # turno-cli
2
2
 
3
+ ## 0.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - cd53ee9: - `turno --help | head` and `turno-browser --help | head` end quietly instead of printing an
8
+ EPIPE stack trace when the reader stops early.
9
+ - Bash completion works on the bash 3.2 macOS ships: each word reaches turno on its own, and
10
+ the script loads with `eval "$(turno completion bash)"`, since bash 3.2 cannot source `<(...)`.
11
+ - `turno mcp daemon run` stops by itself when its home folder is removed (a throwaway HOME
12
+ someone deleted), instead of running on with nothing left to serve.
13
+ - Updated dependencies [cd53ee9]
14
+ - Updated dependencies [cd53ee9]
15
+ - turno-core@0.3.0
16
+
17
+ ## 0.5.0
18
+
19
+ ### Minor Changes
20
+
21
+ - df52afc: turno-browser has its own `turno-browser` command: add, list, show, set, login, vault, export, import, flows, replay, record, traces, live, pause, resume, doctor and reputation work without turno, with `--version` and a help grouped by section. `turno-browser add` prints how to connect an agent instead of an `mcp.toml` block, and `turno-browser do` says it needs turno for now. `turno browser ...` and the browser part of `turno identity ...` now run turno-browser's commands through its typed api (API_VERSION 1.12, new member `cli`) with the same flags, output and exit codes, so turno-cli needs turno-browser 1.12 or a later 1.x. turno-core gains `turno-core/cli`, the command line toolkit (arguments, output, styles, exit codes, command groups, hints, hidden input) that both programs share.
22
+
23
+ ### Patch Changes
24
+
25
+ - 44fb809: `turno-browser-mcp --identity <id> --background` serves an identity to the shell without turno: MCP over streamable HTTP on a Unix socket in a private folder of the identity's state (or 127.0.0.1 with a per-server token where a socket cannot be used), one Chrome shared by every connection with the identity's sharing rules, and an exit after 15 minutes without a request (`--background-idle`, `TURNO_BROWSER_BACKGROUND_IDLE`). While it runs it alone drives the identity's browser: a stdio server of the same identity refuses calls that need the browser with a message that names it, and it does not start while another process has the identity's Chrome open. The package exports a client for it (`startBackground`, `backgroundStatus`, `openBackgroundSession`, `stopBackground`), also in the typed api, now version 1.11. turno-cli now asks for turno-browser 1.11 or a later 1.x.
26
+ - e2b1779: `turno-browser do` works without turno: it starts the identity's background server on the first action, keeps one session per agent or shell between commands, and ends it with `end`, `close` or when that process exits. `turno browser do` keeps going through mcpd.
27
+
28
+ New `turno-browser` commands: `setup <claude-code|codex|cursor|copilot|gemini|json> [--identity <id>]` prints the MCP config that gives an agent an identity (it writes nothing; `--json` for scripts), `background status|start|stop` shows and controls the background servers, and `secret set|has|list|remove` stores the `keychain:<item>` secrets identity.json names, in the same store and items as `turno secret`.
29
+
30
+ Hints, errors and doctor fixes name the commands of the program you typed: `turno-browser ...` on its own (the MCP server's messages too), `turno browser ...` and `turno identity ... browser:<id>` inside turno. `turno-browser doctor` lists a running background server, and a stdio server refused by a background server names `turno-browser background stop <id>`.
31
+
32
+ turno-core exports the owner, name and lock of a shell session of browser commands (`turno-core/cli`), shared by `turno browser do` and `turno-browser do`.
33
+
34
+ The npm description, keywords and MCP Registry entry follow the new tagline. Wording: the help no longer labels the off-by-default settings (natural language actions, captcha solving, network and user agent, Camoufox) as "not recommended"; they stay off by default and the help still says what each one sends where.
35
+ - Updated dependencies [df52afc]
36
+ - Updated dependencies [e2b1779]
37
+ - turno-core@0.2.0
38
+
3
39
  ## 0.4.0
4
40
 
5
41
  ### Minor Changes
package/README.md CHANGED
@@ -350,7 +350,7 @@ turno identity login browser:school # sign in by hand once; cookies persist
350
350
  ```
351
351
 
352
352
  `turno-browser` is its own MCP server. It drives the installed Google Chrome, headed, with a
353
- persistent profile per identity and no injected scripts; each identity keeps its time zone,
353
+ persistent profile per identity; each identity keeps its time zone,
354
354
  languages and locale fixed (`turno browser show|set <id>`).
355
355
 
356
356
  - **It cleans up after itself.** At most 8 tabs per session's browser, an unused tab is parked
@@ -371,7 +371,7 @@ languages and locale fixed (`turno browser show|set <id>`).
371
371
  - **Health you can read.** `turno browser doctor [--fix]` checks Chrome and every identity, and
372
372
  `turno browser reputation` shows how often each site challenged it.
373
373
 
374
- More in [Browser identities](https://turno.wimo.dev/docs/concepts/browser-identities) and
374
+ More in [Browser identities](https://turno.wimo.dev/docs/browser/identities) and
375
375
  [`turno browser`](https://turno.wimo.dev/docs/reference/cli/browser).
376
376
 
377
377
  **Acceptable use.** Use it with your own accounts, on sites whose terms allow automated access
package/dist/cli/args.js CHANGED
@@ -1,79 +1,3 @@
1
- import { parseArgs } from "node:util";
2
- import { fail } from "./io.js";
3
- /** Flags shared by every command, so the same words mean the same thing everywhere. */
4
- export const JSON_FLAG = { json: { type: "boolean" } };
5
- export const DRY_RUN = { "dry-run": { type: "boolean" } };
6
- export const FORCE = { force: { type: "boolean" } };
7
- export const TAIL = { tail: { type: "string", short: "n" } };
8
- export const WATCH = { watch: { type: "boolean" } };
9
- /**
10
- * Completion flags of a spec (`--name` for each long flag), so the parser and the shell
11
- * completion never disagree. Use it as `flags: flagsOf(SPEC)` next to `parseFlags(args, SPEC)`.
12
- */
13
- export function flagsOf(...specs) {
14
- return specs.flatMap((s) => Object.keys(s)).map((k) => `--${k}`);
15
- }
16
- /**
17
- * Take `--json=<value>` out of `args` when the spec has a boolean --json: it turns
18
- * --json on and keeps the value for `emit`. Only a command's own flags count, not those after --.
19
- */
20
- function takeJsonValue(args, spec) {
21
- if (spec.json?.type !== "boolean")
22
- return { args };
23
- let json;
24
- const out = [];
25
- let i = 0;
26
- for (; i < args.length && args[i] !== "--"; i++) {
27
- const a = args[i];
28
- if (a.startsWith("--json=")) {
29
- json = a.slice("--json=".length);
30
- out.push("--json");
31
- }
32
- else {
33
- if (a === "--json")
34
- json ??= "";
35
- out.push(a);
36
- }
37
- }
38
- return { args: [...out, ...args.slice(i)], ...(json !== undefined ? { json } : {}) };
39
- }
40
- /**
41
- * Parse `args` against `spec` (long flags, `--flag=value`, short aliases). Unknown flags and
42
- * positionals beyond `max` are usage errors with a plain message.
43
- */
44
- export function parseFlags(given, spec, max = Number.POSITIVE_INFINITY) {
45
- const { args, json } = takeJsonValue(given, spec);
46
- let parsed;
47
- try {
48
- parsed = parseArgs({ args, options: spec, allowPositionals: true, strict: true });
49
- if (json !== undefined)
50
- parsed.json = json;
51
- }
52
- catch (err) {
53
- const msg = err.message
54
- .replace(/^Unknown option '(.+?)'.*$/s, "unknown option $1")
55
- .replace(/\. To specify.*$/s, "");
56
- return fail(msg.replace(/^Option '(--[\w-]+)(?: <value>)?' argument missing$/, "$1 needs a value"));
57
- }
58
- if (parsed.positionals.length > max)
59
- fail(`unexpected argument '${parsed.positionals[max]}'`);
60
- return parsed;
61
- }
62
- export function bool(p, name) {
63
- return p.values[name] === true;
64
- }
65
- export function str(p, name) {
66
- const v = p.values[name];
67
- return typeof v === "string" ? v : undefined;
68
- }
69
- /** A positive integer flag such as --tail. */
70
- export function count(p, name, fallback) {
71
- const v = str(p, name);
72
- if (v === undefined)
73
- return fallback;
74
- const n = Number.parseInt(v, 10);
75
- if (!Number.isInteger(n) || n < 1 || String(n) !== v.trim())
76
- fail(`--${name} must be a positive integer`);
77
- return n;
78
- }
1
+ // Moved to turno-core so turno-browser shares it; re-exported here so commands keep their imports.
2
+ export * from "turno-core/cli/args";
79
3
  //# sourceMappingURL=args.js.map
@@ -1,86 +1,23 @@
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";
1
+ import { readFileSync, readdirSync, rmSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { writePrivateFile } from "turno-core/paths";
4
4
  import { pidAlive } from "turno-core/process";
5
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
6
  /**
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.
7
+ * The session of `turno browser do`. Each command is one call through mcpd, the way an agent's
8
+ * tool call goes, so the identity's browser, its tab locks ("sharing": "tabs") or its one-session
9
+ * lease ("sharing": "session"), humanize and recordings treat it like an agent session.
10
+ *
11
+ * What makes several commands one session is the mcpd session itself: the first command opens
12
+ * one and saves its id in a private file, the next commands reconnect to it instead of opening
13
+ * another, and mcpd keeps giving the browser the same `io.turno/session` id, so the commands keep
14
+ * their tab. mcpd drops a session when the process named by its X-Turno-Pid header exits, so that
15
+ * header names the process the commands belong to (`sessionOwner`): the coding agent that runs
16
+ * them through a shell, or the terminal's shell. `turno browser do <id> end` ends it at once.
42
17
  */
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
- }
18
+ // The owner of a session, its name and the lock moved to turno-core so turno-browser's own `do`
19
+ // shares them; re-exported here so turno's imports stay.
20
+ export { ownerName, passesOn, sessionName, sessionOwner, withLock } from "turno-core/cli";
84
21
  /** Where CLI sessions are saved: <state>/browser-do. */
85
22
  export function sessionsDir(env) {
86
23
  return join(paths(env).state, "browser-do");
@@ -120,44 +57,6 @@ export function sweepSaved(env, alive = pidAlive) {
120
57
  dropSaved(join(sessionsDir(env), n));
121
58
  }
122
59
  }
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
60
  /**
162
61
  * The mcp.toml server that serves identity `id`: a stdio server with `--identity <id>` in its
163
62
  * args (`browser-<id>` first, as `turno browser add` prints it).