Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/browser-import-cost-bound.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"turno-browser": patch
---

`turno-browser import` takes only the key derivation parameters `export` writes: scrypt `r` 8 and `p` 1, and `N` at most 2^17, so reading a `.session` file never costs more memory than writing one (about 128 MiB). A header that asks for more is refused as damaged before any key is derived. Every export written so far uses exactly these values and still imports.
5 changes: 5 additions & 0 deletions .changeset/browser-remove-reports-unchecked.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"turno-browser": patch
---

`turno-browser remove` no longer reports a complete removal (exit 0) while it could not check something. What it cannot check goes under `left` with `"unchecked": true` in `--json`, as "could not check" in the plan and "not checked" afterwards, and the exit code is 1: an agent config file it cannot read or parse, a registration `init` recorded in a file Cursor's, GitHub Copilot CLI's or Gemini CLI's own command does not change (now with the step to do by hand), an identity.json or vault index it cannot read (kept, since they name the secret store items, so a later run can find them), a secret another identity's identity.json or turno's mcp.toml may use when that file cannot be read (kept), and a turno-browser-mcp started with the identity's id whose environment cannot be read (with its stop command). Agent config files are read with comments and trailing commas allowed, as Gemini CLI's settings.json allows comments, and a file that does not parse is skipped only when no quoted key in it names the identity's server. An agent file that cannot be read after the agent's `mcp remove` counts as failed, not deleted. Planning and the final check read a path with `lstat`, so a broken link is planned and checked and a path it cannot look at is not taken for gone. The final check keeps a process the plan could not tell apart when the process table cannot be read, and checks failed items again: one that is gone after all is listed as deleted. The help and the reference state the limits: vault credentials are found through the sites the vault index names, and session exports through the record kept since 0.9.0. The `--json` fields are unchanged; `unchecked` is a new field on items.
2 changes: 1 addition & 1 deletion apps/docs/content/docs/browser/moving-a-session.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ turno-browser export school --out school.session --expires 2d
turno-browser import school.session --as school-laptop
```

The export holds the identity's cookies, localStorage and IndexedDB, and its settings (identity.json), encrypted with a passphrase of 12 characters or more that you type (asked twice, and asked again when it is too short or the two differ), or the first line of stdin. It is refused after its expiry (7 days by default, at most 90). It never holds vault credentials. Importing into an identity that exists replaces its session and settings, so turno asks first (or needs `--yes`).
The export holds the identity's cookies, localStorage and IndexedDB, and its settings (identity.json), encrypted with a passphrase of 12 characters or more that you type (asked twice, and asked again when it is too short or the two differ), or the first line of stdin. It is refused after its expiry (7 days by default, at most 90). It never holds vault credentials. Importing into an identity that exists replaces its session and settings, so turno asks first (or needs `--yes`). The file's key derivation settings are part of what is checked: import takes the scrypt parameters export writes (`r` 8, `p` 1, `N` at most 2^17, about 128 MiB of memory) and refuses a file that asks for more before it derives a key.

Import restores the settings (locale, languages, region, time zone, humanize level, resources, sharing and the rest) and keeps the importing identity's own creation date. Before anything changes, it lists each setting it changes with the old and the new value, and what it leaves out and why; `--dry-run` shows the same list. It leaves out what belongs to the machine and keeps this identity's value of each: `browser` (a path, or a browser installed on the other machine), `attach` (a Chrome running there), `keychain` (each machine's secret store), and an `engine` other than `chrome` (the session is a Chrome profile). It also leaves out a setting that uses secret store items (`keychain:<item>` references, such as a proxy password or a model key), since the export never holds them: store them on the new machine, then set it again. A value this release does not accept is left out alone. The identity keeps its own `policy` unless you pass `--take-policy`, and an export without a policy never removes it. A change to `lastClick`, `proxy`, `act`, `live`, `record`, `policy` or `sharing`, or `sidePanel` or `notify` set to `false` or `cursor` to `"off"`, sends data elsewhere, lets the agent do more or shows you less of what it does, so turno shows those values whole, with the same warnings as `set`, and asks first (or needs `--yes`) even for a new identity. An export made by an older release holds no settings; it still imports, and the identity keeps its own. The settings apply from the next start of the identity's server.

Expand Down
8 changes: 8 additions & 0 deletions apps/docs/content/docs/browser/reference/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ Deletes everything turno-browser keeps for the identity, after it shows the list
Afterwards it checks that nothing is left. Exit codes: 0 all gone, 1 something is left (--json
lists it under left, with the step that removes it), 2 no terminal and no --yes.

What it cannot check counts as left, with "unchecked": true under --json: an agent config file
it cannot read or parse, a registration in a file the agent's command does not change, an
unreadable identity.json or vault index (kept, as they name the secret store items), a secret
another identity's identity.json or turno's mcp.toml may use when that file cannot be read
(kept), and a turno-browser-mcp for the id whose environment cannot be read. Its limits: vault credentials are
found by the sites the vault index names (the secret store has no listing by prefix), and
session exports by the record kept since 0.9.0 (one made before, or moved since, is not found).

Examples:
$ turno-browser remove school --dry-run
$ turno-browser remove school --yes --json
Expand Down
8 changes: 8 additions & 0 deletions apps/docs/content/docs/reference/cli/browser.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,14 @@ Deletes everything turno-browser keeps for the identity, after it shows the list
Afterwards it checks that nothing is left. Exit codes: 0 all gone, 1 something is left (--json
lists it under left, with the step that removes it), 2 no terminal and no --yes.

What it cannot check counts as left, with "unchecked": true under --json: an agent config file
it cannot read or parse, a registration in a file the agent's command does not change, an
unreadable identity.json or vault index (kept, as they name the secret store items), a secret
another identity's identity.json or turno's mcp.toml may use when that file cannot be read
(kept), and a turno-browser-mcp for the id whose environment cannot be read. Its limits: vault credentials are
found by the sites the vault index names (the secret store has no listing by prefix), and
session exports by the record kept since 0.9.0 (one made before, or moved since, is not found).

Examples:
$ turno browser remove school --dry-run
$ turno browser remove school --yes --json
Expand Down
46 changes: 42 additions & 4 deletions packages/browser/src/agent-mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,42 @@ function tomlValue(text: string): unknown {
}
}

/**
* JSON with comments and trailing commas taken out, outside strings. Gemini CLI reads its
* settings.json with comments (strip-json-comments); Claude Code, Cursor and GitHub Copilot CLI
* write plain JSON. Reading leniently only finds more of what is in a file, never less.
*/
function parseJsonc(text: string): unknown {
let out = "";
for (let i = 0; i < text.length; i++) {
const ch = text[i]!;
if (ch === '"') {
const from = i;
for (i++; i < text.length && text[i] !== '"'; i++) if (text[i] === "\\") i++;
out += text.slice(from, i + 1);
} else if (ch === "/" && text[i + 1] === "/") {
while (i + 1 < text.length && text[i + 1] !== "\n") i++;
} else if (ch === "/" && text[i + 1] === "*") {
const close = text.indexOf("*/", i + 2);
i = close < 0 ? text.length : close + 1;
out += " ";
} else if (ch === ",") {
// A comma followed only by blanks and comments before } or ] is a trailing one.
let j = i + 1;
for (;;) {
while (j < text.length && /\s/.test(text[j]!)) j++;
if (text.startsWith("//", j)) while (j < text.length && text[j] !== "\n") j++;
else if (text.startsWith("/*", j)) {
const close = text.indexOf("*/", j + 2);
j = close < 0 ? text.length : close + 2;
} else break;
}
if (text[j] !== "}" && text[j] !== "]") out += ch;
} else out += ch;
}
return JSON.parse(out);
}

/** The `[mcp_servers.<name>]` tables of a Codex config.toml, with their command and args. */
function tomlServers(text: string): Map<string, Record<string, unknown>> {
const out = new Map<string, Record<string, unknown>>();
Expand All @@ -164,10 +200,12 @@ function tomlServers(text: string): Map<string, Record<string, unknown>> {
return out;
}

/** Every MCP server in the agent's config file (read only). A missing file has none. */
export function agentServers(agent: McpAgent, env: NodeJS.ProcessEnv): AgentServers {
/**
* Every MCP server in the agent's config file (read only), or in `file` when given (a
* registration recorded in another file). A missing file has none.
*/
export function agentServers(agent: McpAgent, env: NodeJS.ProcessEnv, file = AGENTS[agent].file(env)): AgentServers {
const info = AGENTS[agent];
const file = info.file(env);
let text: string;
try {
text = readFileSync(file, "utf8");
Expand All @@ -191,7 +229,7 @@ export function agentServers(agent: McpAgent, env: NodeJS.ProcessEnv): AgentServ
return { agent, file, entries: [...tomlServers(text)].map(([server, e]) => entry(server, e)) };
let v: unknown;
try {
v = JSON.parse(text);
v = parseJsonc(text);
} catch (err) {
return { agent, file, entries: [], error: `not valid JSON (${(err as Error).message})` };
}
Expand Down
18 changes: 15 additions & 3 deletions packages/browser/src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,15 @@ const REMOVE_DETAILS = `Deletes everything turno-browser keeps for the identity,

--yes deletes without asking; without a terminal it is required. --dry-run shows the list.
Afterwards it checks that nothing is left. Exit codes: 0 all gone, 1 something is left (--json
lists it under left, with the step that removes it), 2 no terminal and no --yes.`;
lists it under left, with the step that removes it), 2 no terminal and no --yes.

What it cannot check counts as left, with "unchecked": true under --json: an agent config file
it cannot read or parse, a registration in a file the agent's command does not change, an
unreadable identity.json or vault index (kept, as they name the secret store items), a secret
another identity's identity.json or turno's mcp.toml may use when that file cannot be read
(kept), and a turno-browser-mcp for the id whose environment cannot be read. Its limits: vault credentials are
found by the sites the vault index names (the secret store has no listing by prefix), and
session exports by the record kept since 0.9.0 (one made before, or moved since, is not found).`;

/** One line about a removal item, for people. */
function describeItem(item: RemovalItem, env: NodeJS.ProcessEnv): string {
Expand Down Expand Up @@ -313,7 +321,11 @@ async function remove(c: Ctx, args: string[], io: Io): Promise<number> {
const out = [`This deletes browser identity "${id}":`];
for (const item of plan.items) out.push(` ${describeItem(item, env)}`);
for (const item of plan.left)
out.push(` ${describeItem(item, env)}: cannot be removed here (${item.reason}); by hand: ${item.command ?? ""}`);
out.push(
item.unchecked
? ` could not check ${describeItem(item, env)}: ${item.reason}; by hand: ${item.command ?? ""}`
: ` ${describeItem(item, env)}: cannot be removed here (${item.reason}); by hand: ${item.command ?? ""}`,
);
for (const item of plan.kept) out.push(` kept: ${describeItem(item, env)}, ${item.reason}`);
return out;
};
Expand Down Expand Up @@ -350,7 +362,7 @@ async function remove(c: Ctx, args: string[], io: Io): Promise<number> {
io.out(
s.note(
"warn",
`left ${describeItem(item, env)}: ${item.reason}${item.command ? `; to remove it: ${item.command}` : ""}`,
`${item.unchecked ? "not checked" : "left"} ${describeItem(item, env)}: ${item.reason}${item.command ? `; to remove it: ${item.command}` : ""}`,
),
);
if (report.complete) io.out(`removed identity "${id}" and its saved browser data`);
Expand Down
Loading
Loading