turno-browser 0.6.0 → 0.8.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +13 -5
  3. package/dist/act.js +4 -29
  4. package/dist/agent-cursor-overlay.d.ts +95 -0
  5. package/dist/agent-cursor-overlay.js +358 -0
  6. package/dist/agent-cursor.d.ts +191 -0
  7. package/dist/agent-cursor.js +494 -0
  8. package/dist/api.d.ts +8 -3
  9. package/dist/api.js +6 -3
  10. package/dist/argv.d.ts +2 -1
  11. package/dist/argv.js +7 -1
  12. package/dist/bin/mcp.js +5 -0
  13. package/dist/cli/commands.js +12 -3
  14. package/dist/cli/completion.js +3 -0
  15. package/dist/cli/context.d.ts +2 -0
  16. package/dist/cli/context.js +8 -4
  17. package/dist/cli/do-background.d.ts +2 -0
  18. package/dist/cli/do-background.js +15 -0
  19. package/dist/cli/do.d.ts +4 -0
  20. package/dist/cli/do.js +17 -1
  21. package/dist/cli/flows.js +3 -0
  22. package/dist/cli/identity.d.ts +2 -0
  23. package/dist/cli/identity.js +67 -11
  24. package/dist/cli/init.d.ts +12 -0
  25. package/dist/cli/init.js +219 -0
  26. package/dist/cli/login-summary.d.ts +6 -0
  27. package/dist/cli/login-summary.js +11 -0
  28. package/dist/cli/main.js +3 -0
  29. package/dist/cli/setup.d.ts +32 -0
  30. package/dist/cli/setup.js +32 -23
  31. package/dist/doctor.js +18 -2
  32. package/dist/engine-camoufox.js +1 -0
  33. package/dist/engine-lightpanda.js +1 -0
  34. package/dist/host.d.ts +7 -0
  35. package/dist/host.js +330 -68
  36. package/dist/human-input.d.ts +5 -0
  37. package/dist/human-input.js +1 -1
  38. package/dist/human-step-overlay.d.ts +73 -0
  39. package/dist/human-step-overlay.js +285 -0
  40. package/dist/human-step.d.ts +128 -0
  41. package/dist/human-step.js +521 -0
  42. package/dist/index.d.ts +2 -2
  43. package/dist/index.js +2 -2
  44. package/dist/live-server.d.ts +7 -3
  45. package/dist/live-server.js +13 -15
  46. package/dist/live.d.ts +20 -1
  47. package/dist/live.js +52 -10
  48. package/dist/login.d.ts +22 -2
  49. package/dist/login.js +95 -7
  50. package/dist/network-redact.d.ts +28 -0
  51. package/dist/network-redact.js +202 -0
  52. package/dist/recorder.d.ts +0 -21
  53. package/dist/recorder.js +1 -41
  54. package/dist/recordings.d.ts +5 -0
  55. package/dist/recordings.js +4 -2
  56. package/dist/redact.d.ts +7 -0
  57. package/dist/redact.js +32 -1
  58. package/dist/replay.d.ts +2 -0
  59. package/dist/replay.js +33 -14
  60. package/dist/reputation.d.ts +5 -0
  61. package/dist/reputation.js +12 -7
  62. package/dist/sensitive.d.ts +79 -0
  63. package/dist/sensitive.js +275 -0
  64. package/dist/session.d.ts +12 -0
  65. package/dist/session.js +24 -0
  66. package/dist/settings.d.ts +12 -2
  67. package/dist/settings.js +14 -2
  68. package/dist/tools.d.ts +5 -0
  69. package/dist/tools.js +9 -1
  70. package/dist/tuning.d.ts +4 -1
  71. package/dist/tuning.js +1 -0
  72. package/dist/upstream.d.ts +5 -0
  73. package/dist/watch.d.ts +60 -0
  74. package/dist/watch.js +114 -0
  75. package/npm-shrinkwrap.json +2 -2
  76. package/package.json +1 -1
@@ -0,0 +1,219 @@
1
+ import { spawn } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { bool, fail, needsAnswer, paint, parseFlags, str } from "turno-core/cli";
5
+ import { findOnPath, tildify } from "turno-core/paths";
6
+ import { loginSummary } from "./login-summary.js";
7
+ import { AGENT_NAMES, SETUP_AGENTS, mcpCommand, setupConfig, setupLines, unknownAgent, } from "./setup.js";
8
+ /**
9
+ * `turno-browser init`: the first setup, step by step. It does what the three commands of the
10
+ * docs do (`add`, `login`, `setup`) and asks before each step that opens a window or changes an
11
+ * agent's config:
12
+ *
13
+ * 1. the identity: a name, created, or the existing one reused;
14
+ * 2. the sign-in: Chrome opens on the identity's profile, on a first site when given;
15
+ * 3. the agent: the agents found on this machine, and its `mcp add` command, run only on a yes
16
+ * (an agent without one gets the block to paste).
17
+ *
18
+ * Without a person to answer (`--no-input`, a pipe, an agent session) it needs `--identity` and
19
+ * `--agent`, skips the sign-in (only a person can sign in) and runs nothing: it prints.
20
+ */
21
+ const INIT_FLAGS = {
22
+ identity: { type: "string" },
23
+ agent: { type: "string" },
24
+ url: { type: "string" },
25
+ "no-login": { type: "boolean" },
26
+ yes: { type: "boolean", short: "y" },
27
+ "dry-run": { type: "boolean" },
28
+ };
29
+ export const INIT_SYNOPSIS = "[--identity <id>] [--agent <claude-code|codex|cursor|copilot|gemini|json|none>] [--url <url>] [--no-login] [--yes] [--dry-run]";
30
+ export const INIT_DETAILS = `Sets up a browser identity and gives it to your agent, asking at each step:
31
+ 1. the identity's name (a new one is created; an existing one is used as it is)
32
+ 2. signing in by hand: Chrome opens on the identity's profile (--url opens a first site)
33
+ 3. the agent: the agents found on this machine; its mcp add command runs only if you say yes,
34
+ and an agent without one (cursor, json) gets the block to paste
35
+
36
+ --yes answers yes to every step, --no-login skips the sign-in, --agent none skips the agent.
37
+ Without a terminal (--no-input, a pipe or an agent session) it needs --identity and --agent,
38
+ skips the sign-in and prints the agent's command instead of running it.`;
39
+ const runCommand = (command, args, io) => new Promise((resolve) => {
40
+ const child = spawn(command, [...args], { stdio: "inherit", env: io.env });
41
+ child.on("error", () => resolve(127));
42
+ child.on("exit", (code) => resolve(code ?? 1));
43
+ });
44
+ /** The program each agent's own `mcp add` runs as: the one to look for on the PATH. */
45
+ const AGENT_PROGRAMS = {
46
+ "claude-code": "claude",
47
+ codex: "codex",
48
+ copilot: "copilot",
49
+ gemini: "gemini",
50
+ };
51
+ /** The agents installed here, in the order the question lists them. */
52
+ export function detectAgents(env) {
53
+ const home = env.HOME ?? "";
54
+ return SETUP_AGENTS.filter((a) => {
55
+ if (a === "json")
56
+ return false;
57
+ if (a === "cursor")
58
+ return Boolean(findOnPath("cursor-agent", env)) || (home !== "" && existsSync(join(home, ".cursor")));
59
+ const program = AGENT_PROGRAMS[a];
60
+ return program !== undefined && Boolean(findOnPath(program, env));
61
+ });
62
+ }
63
+ /** Split a printed shell line back into words: setup only quotes with single quotes. */
64
+ export function shellWords(line) {
65
+ const words = [];
66
+ const re = /'((?:[^']|'\\'')*)'|(\S+)/g;
67
+ for (let m = re.exec(line); m; m = re.exec(line))
68
+ words.push(m[1] !== undefined ? m[1].replace(/'\\''/g, "'") : m[2]);
69
+ return words;
70
+ }
71
+ async function askYes(io, question, yes) {
72
+ if (yes)
73
+ return true;
74
+ const answer = (await io.ask(`${question} [Y/n] `)).trim().toLowerCase();
75
+ return answer === "" || answer === "y" || answer === "yes";
76
+ }
77
+ async function askText(io, question, fallback) {
78
+ const answer = (await io.ask(fallback ? `${question} [${fallback}]: ` : `${question}: `)).trim();
79
+ return answer || fallback;
80
+ }
81
+ export async function init(c, args, io, run = runCommand) {
82
+ const p = parseFlags(args, INIT_FLAGS, 0);
83
+ const b = c.names.browser;
84
+ const api = c.api;
85
+ const yes = bool(p, "yes");
86
+ const dry = bool(p, "dry-run");
87
+ const interactive = c.deps.interactive(io) && !dry;
88
+ const step = (n, title) => io.out(`\n${paint(io, `Step ${n} of 3`, "2")} ${paint(io, title, "1")}`);
89
+ const url = str(p, "url");
90
+ if (url !== undefined && !/^https?:\/\//.test(url))
91
+ return fail(`--url must start with http:// or https://: ${url}`);
92
+ const agentFlag = str(p, "agent");
93
+ if (agentFlag !== undefined && agentFlag !== "none" && !SETUP_AGENTS.includes(agentFlag))
94
+ return fail(unknownAgent(agentFlag));
95
+ if (!interactive && !dry && (str(p, "identity") === undefined || agentFlag === undefined)) {
96
+ return needsAnswer(`${b} init`, "--identity and --agent");
97
+ }
98
+ io.out(`Set up ${b}: a browser identity, signed in once, given to your agent.`);
99
+ io.out(paint(io, "Ctrl-C stops at any step; each step that is done stays done.", "2"));
100
+ // 1. The identity.
101
+ step(1, "the identity");
102
+ const existing = api.listIdentities(io.env).map((i) => i.id);
103
+ if (existing.length)
104
+ io.out(`Identities here: ${existing.join(", ")}`);
105
+ io.out("An identity is one Chrome profile your agent uses, with your sign-ins. Name it after what it is for.");
106
+ let id = str(p, "identity");
107
+ while (id === undefined) {
108
+ const answer = await askText(io, "Name", existing.length === 1 ? existing[0] : "personal");
109
+ try {
110
+ api.assertIdentityId(answer);
111
+ id = answer;
112
+ }
113
+ catch (err) {
114
+ io.err(err.message);
115
+ }
116
+ }
117
+ try {
118
+ api.assertIdentityId(id);
119
+ }
120
+ catch (err) {
121
+ return fail(err.message);
122
+ }
123
+ if (api.identityExists(id, io.env))
124
+ io.out(`Using the identity "${id}" that is already here.`);
125
+ else if (dry)
126
+ io.out(`(dry run) would create the identity "${id}"`);
127
+ else {
128
+ const info = api.addIdentity(id, io.env);
129
+ io.out(`Created "${id}" at ${tildify(info.dir, io.env)}`);
130
+ }
131
+ // 2. The sign-in.
132
+ step(2, "sign in by hand once");
133
+ let firstSite = url;
134
+ if (bool(p, "no-login"))
135
+ io.out(`Skipped. Sign in later with ${b} login ${id}.`);
136
+ else if (dry)
137
+ io.out(`(dry run) would open Chrome for "${id}"${url ? ` on ${url}` : ""} so you sign in`);
138
+ else if (!interactive)
139
+ io.out(`Skipped: only a person can sign in. Run ${b} login ${id} on a terminal.`);
140
+ else if (api.isInUse(id, io.env))
141
+ io.out(`Skipped: "${id}" is in use right now. Sign in later with ${b} login ${id}.`);
142
+ else {
143
+ io.out("Chrome opens on this identity's profile. Sign in to the sites your agent needs, then close the window.");
144
+ if (firstSite === undefined && !yes) {
145
+ const answer = await askText(io, "First site to open (Enter for none)", "");
146
+ if (answer)
147
+ firstSite = /^https?:\/\//.test(answer) ? answer : `https://${answer}`;
148
+ }
149
+ if (await askYes(io, "Open Chrome now?", yes)) {
150
+ const result = await api.loginIdentity(id, { env: io.env, ...(firstSite ? { url: firstSite } : {}) });
151
+ io.out(loginSummary(c, id, result?.sites ?? []));
152
+ }
153
+ else
154
+ io.out(`Skipped. Sign in later with ${b} login ${id}.`);
155
+ }
156
+ // 3. The agent.
157
+ step(3, "give it to your agent");
158
+ const found = detectAgents(io.env);
159
+ let agent = agentFlag;
160
+ if (agent === undefined) {
161
+ io.out(found.length
162
+ ? `Agents found here: ${found.map((a) => `${a} (${AGENT_NAMES[a]})`).join(", ")}`
163
+ : "No agent found on the PATH.");
164
+ io.out(`Agents: ${SETUP_AGENTS.join(", ")}, or none.`);
165
+ while (agent === undefined) {
166
+ const answer = (await askText(io, "Agent", found[0] ?? "json")).toLowerCase();
167
+ if (answer === "none" || SETUP_AGENTS.includes(answer))
168
+ agent = answer;
169
+ else
170
+ io.err(unknownAgent(answer));
171
+ }
172
+ }
173
+ let connected = false;
174
+ if (agent === "none")
175
+ io.out(`Skipped. ${b} setup <agent> --identity ${id} prints it later.`);
176
+ else {
177
+ const { command, onPath } = mcpCommand(io.env);
178
+ const cfg = setupConfig(agent, id, command);
179
+ if (!onPath)
180
+ cfg.notes.push("turno-browser-mcp is not on the PATH here, so this names it by its full path.");
181
+ const program = AGENT_PROGRAMS[agent];
182
+ const runnable = cfg.shell !== null && program !== undefined && Boolean(findOnPath(program, io.env));
183
+ if (runnable && interactive && !dry) {
184
+ io.out(`This adds the browser to ${AGENT_NAMES[agent]}:`);
185
+ io.out(` ${cfg.shell}`);
186
+ if (await askYes(io, "Run it now?", yes)) {
187
+ const [bin, ...rest] = shellWords(cfg.shell);
188
+ const code = await run(bin, rest, io);
189
+ if (code === 0) {
190
+ connected = true;
191
+ io.out(`Done: ${AGENT_NAMES[agent]} has the browser "${id}".`);
192
+ }
193
+ else
194
+ io.err(`That command ended with code ${code}; run it yourself, or ${b} setup ${agent} --identity ${id}.`);
195
+ }
196
+ else
197
+ for (const l of setupLines(cfg))
198
+ io.out(l);
199
+ }
200
+ else {
201
+ if (dry && runnable)
202
+ io.out(`(dry run) would ask to run: ${cfg.shell}`);
203
+ else
204
+ for (const l of setupLines(cfg))
205
+ io.out(l);
206
+ }
207
+ }
208
+ // What is left.
209
+ io.out(`\n${paint(io, "Next", "1")}`);
210
+ if (agent !== "none") {
211
+ // "json" names no agent ("any MCP client"), so it reads as "your MCP client".
212
+ const who = agent === undefined ? "your agent" : agent === "json" ? "your MCP client" : AGENT_NAMES[agent];
213
+ const session = agent === "json" ? `a new session of ${who}` : `a new ${who} session`;
214
+ io.out(`${connected ? "Start" : "Once it is added, start"} ${session} and ask it to open ${firstSite ?? "a site you signed in to"}.`);
215
+ }
216
+ io.out(`${b} doctor checks Chrome and the identity; ${b} show ${id} shows its settings.`);
217
+ return 0;
218
+ }
219
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1,6 @@
1
+ import type { Ctx } from "./context.js";
2
+ /**
3
+ * What a login saved, in words: the sites the person opened (the agent starts with their
4
+ * cookies), or that nothing was opened, so nothing new was signed in.
5
+ */
6
+ export declare function loginSummary(c: Ctx, id: string, sites: readonly string[]): string;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * What a login saved, in words: the sites the person opened (the agent starts with their
3
+ * cookies), or that nothing was opened, so nothing new was signed in.
4
+ */
5
+ export function loginSummary(c, id, sites) {
6
+ if (!sites.length)
7
+ return `Closed. No site was opened, so no new sign-in was saved. Open one directly with ${c.names.identity("login", id)} --url https://mail.example.com`;
8
+ const shown = sites.length > 4 ? `${sites.slice(0, 4).join(", ")} and ${sites.length - 4} more` : sites.join(", ");
9
+ return `Saved. Sites you opened: ${shown}. The agent starts with the same cookies on them.`;
10
+ }
11
+ //# sourceMappingURL=login-summary.js.map
package/dist/cli/main.js CHANGED
@@ -14,6 +14,7 @@ import { COMPLETION_USAGE, complete, completionScript } from "./completion.js";
14
14
  const PROGRAM = "turno-browser";
15
15
  /** The sections of `turno-browser --help`, in order. */
16
16
  const SECTIONS = [
17
+ { title: "Start here", commands: ["init"] },
17
18
  { title: "Identities", commands: ["list", "add", "show", "set", "login", "remove"] },
18
19
  { title: "Connect an agent", commands: ["setup"] },
19
20
  { title: "Sign-ins and sessions", commands: ["vault", "secret", "export", "import"] },
@@ -36,6 +37,8 @@ export function renderHelp(io, cli) {
36
37
  out.push(s.color ? `${s.bold(s.accent(PROGRAM))}${s.bold(first[0].slice(PROGRAM.length))}` : first[0]);
37
38
  for (const l of first.slice(1))
38
39
  out.push(s.bold(l));
40
+ if (cli.subs.init)
41
+ out.push("", `New here? ${s.accent(`${PROGRAM} init`)} sets it up step by step: an identity, a sign-in, your agent.`);
39
42
  out.push("", s.header("Usage"));
40
43
  out.push(columns([
41
44
  [`${PROGRAM} <command> [flags]`, "manage identities: persistent Chrome profiles your agents sign in with"],
@@ -6,8 +6,40 @@ import type { Ctx } from "./context.js";
6
6
  * agent's config is the person's (inside turno, `turno mcp sync` writes it from mcp.toml).
7
7
  */
8
8
  export declare const SETUP_AGENTS: readonly ["claude-code", "codex", "cursor", "copilot", "gemini", "json"];
9
+ export type SetupAgent = (typeof SETUP_AGENTS)[number];
9
10
  /** `setup --json`: one object. */
10
11
  export declare const SETUP_JSON: import("turno-core/cli").JsonOutput;
12
+ /** What `setup` prints for one agent. */
13
+ export interface SetupConfig {
14
+ agent: SetupAgent;
15
+ identity: string;
16
+ /** The server's name in the agent's config: `browser-<id>`. */
17
+ server: string;
18
+ command: string;
19
+ args: string[];
20
+ /** The file the config block goes in, when the agent reads one. */
21
+ file: string | null;
22
+ /** A command that adds the server, when the agent has one. */
23
+ shell: string | null;
24
+ /** The block to paste into `file`. */
25
+ config: string | null;
26
+ notes: string[];
27
+ }
28
+ /**
29
+ * The command an agent runs: `turno-browser-mcp` when it is on the PATH, else this install's
30
+ * full path (a `pnpm add` or a local checkout puts it nowhere on the PATH).
31
+ */
32
+ export declare function mcpCommand(env: NodeJS.ProcessEnv): {
33
+ command: string;
34
+ onPath: boolean;
35
+ };
36
+ /** The config of `agent` for identity `id`, run as `command`. */
37
+ export declare function setupConfig(agent: SetupAgent, id: string, command: string): SetupConfig;
38
+ export declare const AGENT_NAMES: Record<SetupAgent, string>;
11
39
  export declare const SETUP_DETAILS = "Prints how a coding agent gets one identity's browser: the command to run, or the block to\npaste into its config file. It writes nothing; run or paste it yourself.\n\nAgents:\n claude-code a claude mcp add command\n codex a [mcp_servers] block for ~/.codex/config.toml, and the codex mcp add command\n cursor an mcpServers entry for ~/.cursor/mcp.json\n copilot an mcpServers entry for ~/.copilot/mcp-config.json, and the copilot mcp add command\n gemini an mcpServers entry for ~/.gemini/settings.json, and the gemini mcp add command\n json the generic mcpServers entry other MCP clients read\n\nWithout --identity it uses the only identity there is. The agent then starts turno-browser-mcp\nfor the identity when it needs the browser.";
40
+ /** "unknown agent", with the agent the person most likely meant: claude for claude-code, cursr for cursor. */
41
+ export declare function unknownAgent(agent: string): string;
42
+ /** What `setup` prints for one config, before the closing line. */
43
+ export declare function setupLines(cfg: SetupConfig): string[];
12
44
  /** `<browser> setup <agent> [--identity <id>] [--json]`. */
13
45
  export declare function setup(c: Ctx, args: string[], io: Io): number;
package/dist/cli/setup.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { fileURLToPath } from "node:url";
2
- import { JSON_FLAG, bool, emit, fail, jsonOutput, parseFlags, str } from "turno-core/cli";
2
+ import { JSON_FLAG, bool, closest, emit, fail, jsonOutput, parseFlags, str, } from "turno-core/cli";
3
3
  import { findOnPath } from "turno-core/paths";
4
4
  /**
5
5
  * `turno-browser setup <agent> [--identity <id>]`: the MCP config that gives a coding agent one
@@ -34,13 +34,13 @@ function json(v) {
34
34
  * The command an agent runs: `turno-browser-mcp` when it is on the PATH, else this install's
35
35
  * full path (a `pnpm add` or a local checkout puts it nowhere on the PATH).
36
36
  */
37
- function mcpCommand(env) {
37
+ export function mcpCommand(env) {
38
38
  if (findOnPath("turno-browser-mcp", env))
39
39
  return { command: "turno-browser-mcp", onPath: true };
40
40
  return { command: fileURLToPath(new URL("../bin/mcp.js", import.meta.url)), onPath: false };
41
41
  }
42
42
  /** The config of `agent` for identity `id`, run as `command`. */
43
- function setupConfig(agent, id, command) {
43
+ export function setupConfig(agent, id, command) {
44
44
  const server = `browser-${id}`;
45
45
  const args = ["--identity", id];
46
46
  const base = { agent, identity: id, server, command, args };
@@ -96,7 +96,7 @@ function setupConfig(agent, id, command) {
96
96
  };
97
97
  }
98
98
  }
99
- const AGENT_NAMES = {
99
+ export const AGENT_NAMES = {
100
100
  "claude-code": "Claude Code",
101
101
  codex: "Codex",
102
102
  cursor: "Cursor",
@@ -117,6 +117,12 @@ Agents:
117
117
 
118
118
  Without --identity it uses the only identity there is. The agent then starts turno-browser-mcp
119
119
  for the identity when it needs the browser.`;
120
+ /** "unknown agent", with the agent the person most likely meant: claude for claude-code, cursr for cursor. */
121
+ export function unknownAgent(agent) {
122
+ const prefix = SETUP_AGENTS.find((a) => a.startsWith(agent.toLowerCase()) && agent.length >= 3);
123
+ const guess = prefix ?? closest(agent.toLowerCase(), SETUP_AGENTS);
124
+ return `unknown agent "${agent}"${guess ? `; did you mean ${guess}?` : ""} (agents: ${SETUP_AGENTS.join(", ")})`;
125
+ }
120
126
  /** The identity `setup` is for: --identity, or the only one there is. */
121
127
  function pickIdentity(c, flag, io) {
122
128
  const b = c.names.browser;
@@ -138,6 +144,25 @@ function pickIdentity(c, flag, io) {
138
144
  return fail(`no identity yet: create one with ${b} add <id>, then ${b} setup <agent> --identity <id>`);
139
145
  return fail(`pick an identity with --identity: ${ids.join(", ")}`);
140
146
  }
147
+ /** What `setup` prints for one config, before the closing line. */
148
+ export function setupLines(cfg) {
149
+ const name = AGENT_NAMES[cfg.agent];
150
+ const id = cfg.identity;
151
+ const out = [];
152
+ if (cfg.agent === "claude-code") {
153
+ out.push(`Run this once to give ${name} the browser identity "${id}":`, "", cfg.shell);
154
+ }
155
+ else if (cfg.file) {
156
+ out.push(`Add this to ${cfg.file} to give ${name} the browser identity "${id}":`, "", cfg.config);
157
+ if (cfg.shell)
158
+ out.push("", `Or run: ${cfg.shell}`);
159
+ }
160
+ else {
161
+ out.push(`The browser identity "${id}" for ${name}:`, "", cfg.config);
162
+ }
163
+ out.push("", ...cfg.notes);
164
+ return out;
165
+ }
141
166
  /** `<browser> setup <agent> [--identity <id>] [--json]`. */
142
167
  export function setup(c, args, io) {
143
168
  const p = parseFlags(args, SETUP_FLAGS, 1);
@@ -146,7 +171,7 @@ export function setup(c, args, io) {
146
171
  if (!agent)
147
172
  return fail(`setup needs an agent: ${b} setup <${SETUP_AGENTS.join("|")}> [--identity <id>]`);
148
173
  if (!SETUP_AGENTS.includes(agent))
149
- return fail(`unknown agent "${agent}" (agents: ${SETUP_AGENTS.join(", ")})`);
174
+ return fail(unknownAgent(agent));
150
175
  const id = pickIdentity(c, str(p, "identity"), io);
151
176
  const { command, onPath } = mcpCommand(io.env);
152
177
  const cfg = setupConfig(agent, id, command);
@@ -156,24 +181,8 @@ export function setup(c, args, io) {
156
181
  emit(io, p, SETUP_JSON, cfg);
157
182
  return 0;
158
183
  }
159
- const name = AGENT_NAMES[cfg.agent];
160
- if (cfg.agent === "claude-code") {
161
- io.out(`Run this once to give ${name} the browser identity "${id}":\n`);
162
- io.out(cfg.shell);
163
- }
164
- else if (cfg.file) {
165
- io.out(`Add this to ${cfg.file} to give ${name} the browser identity "${id}":\n`);
166
- io.out(cfg.config);
167
- if (cfg.shell)
168
- io.out(`\nOr run: ${cfg.shell}`);
169
- }
170
- else {
171
- io.out(`The browser identity "${id}" for ${name}:\n`);
172
- io.out(cfg.config);
173
- }
174
- io.out("");
175
- for (const n of cfg.notes)
176
- io.out(n);
184
+ for (const l of setupLines(cfg))
185
+ io.out(l);
177
186
  io.out(`Start a new agent session to load it. Sign in to your sites once with ${b} login ${id}.`);
178
187
  return 0;
179
188
  }
package/dist/doctor.js CHANGED
@@ -6,6 +6,7 @@ import { browserPaths as paths } from "turno-core/paths";
6
6
  import { readProcTable, signalProcess } from "turno-core/process";
7
7
  import { secretStore } from "turno-core/secrets";
8
8
  import { backgroundAlive, readBackgroundState } from "./background-state.js";
9
+ import { profileHasCookies, readLoginRecord } from "./login.js";
9
10
  import { readHealth } from "./health.js";
10
11
  import { identityDir, isValidIdentityId } from "./ids.js";
11
12
  import { defaultChromeUserDataDir, parseAttachTarget, resolveAttachEndpoint } from "./engine-attach.js";
@@ -121,7 +122,13 @@ function describeSettings(s) {
121
122
  parts.push(`languages ${langs.join(", ")}`);
122
123
  if (s.region)
123
124
  parts.push(`region ${s.region}`);
124
- return parts.length ? parts.join(", ") : "no fixed time zone or languages";
125
+ const base = parts.length ? parts.join(", ") : "no fixed time zone or languages";
126
+ // The agent cursor is on when the browser can be seen (auto): say so only when set otherwise.
127
+ if (s.cursor === "on")
128
+ return `${base}; agent cursor always shown`;
129
+ if (s.cursor === "off")
130
+ return `${base}; agent cursor off`;
131
+ return base;
125
132
  }
126
133
  /** The `turno identity set` flag that replaces the value a problem is about. */
127
134
  function settingsFix(id, problem) {
@@ -131,6 +138,7 @@ function settingsFix(id, problem) {
131
138
  ["languages", "--languages <tag,...>"],
132
139
  ["region", "--region <CC>"],
133
140
  ["health", "--health-url <url> --health-text <text>"],
141
+ ["cursor", "--cursor auto|on|off"],
134
142
  ].find(([key]) => problem.startsWith(key))?.[1];
135
143
  return flag ? `turno identity set browser:${id} ${flag}` : undefined;
136
144
  }
@@ -220,7 +228,7 @@ function identityChecks(id, env, now, servers = []) {
220
228
  });
221
229
  }
222
230
  else {
223
- add({ level: "ok", text: "free: no process holds it" });
231
+ add({ level: "ok", text: "not in use: no process holds it" });
224
232
  }
225
233
  // The background server `turno-browser do` starts: while it runs, an agent's server of this
226
234
  // identity refuses to launch the browser, so say it runs and how to stop it.
@@ -233,6 +241,14 @@ function identityChecks(id, env, now, servers = []) {
233
241
  fix: `turno-browser background stop ${id}`,
234
242
  });
235
243
  }
244
+ // A profile nobody signed in to by hand starts signed out everywhere: say so before an agent finds out.
245
+ if (!readLoginRecord(id, env) && !profileHasCookies(id, env)) {
246
+ add({
247
+ level: "info",
248
+ text: "never signed in by hand here: the agent starts signed out on every site",
249
+ fix: `turno browser login ${id}`,
250
+ });
251
+ }
236
252
  const check = settings?.health;
237
253
  const health = readHealth(id, env);
238
254
  if (!check) {
@@ -41,6 +41,7 @@ import { names } from "./names.js";
41
41
  const NOT_IN_CAMOUFOX = {
42
42
  browser_run_code_unsafe: "it runs Playwright code against the patchright-core API, and Camoufox runs on stock Playwright",
43
43
  browser_solve_captcha: "it sets the token from Patchright's isolated script world and calls the widget's callback in the page's own, and Camoufox runs on stock Playwright",
44
+ browser_request_human: "its banner runs in Patchright's isolated script world, out of the page scripts' reach, and Camoufox runs on stock Playwright",
44
45
  };
45
46
  /** Why the Camoufox engine refuses this tool, or undefined when it runs it. */
46
47
  export function camoufoxRefusal(tool) {
@@ -70,6 +70,7 @@ const NOT_IN_READ_MODE = {
70
70
  browser_run_code_unsafe: "read mode runs only the reading tools",
71
71
  browser_login: "read mode keeps no vault sign-ins; it is meant for public pages",
72
72
  browser_solve_captcha: "read mode runs no captcha widget to solve",
73
+ browser_request_human: "Lightpanda shows no window and no picture, so the person has no page to act on",
73
74
  };
74
75
  /** Why read mode refuses this tool, or undefined when it runs it. */
75
76
  export function readModeRefusal(tool) {
package/dist/host.d.ts CHANGED
@@ -4,6 +4,7 @@ import type { SecretStore } from "turno-core/secrets";
4
4
  import { type Engine, type EngineFlags, type IdentityRef } from "./engine.js";
5
5
  import { type LiveFlags } from "./live.js";
6
6
  import { LiveServer } from "./live-server.js";
7
+ import { type ChallengeEvent } from "./reputation.js";
7
8
  import { type TabLockPolicy } from "./tab-locks.js";
8
9
  import { type Providers, type TurnoTool } from "./tools.js";
9
10
  import { type Tuning, type TuningFlags } from "./tuning.js";
@@ -47,6 +48,8 @@ export interface Host {
47
48
  }
48
49
  /** Upstream joins the text parts of a result into one (`mergeTextParts`). */
49
50
  export declare function mergeTextParts(result: ToolResult): ToolResult;
51
+ /** What the agent reads when the page it ended on is a challenge (`reputation.ts`). */
52
+ export declare function challengeNote(event: Omit<ChallengeEvent, "ts">): string;
50
53
  /**
51
54
  * One MCP session. Implements upstream's server backend contract, so upstream's HTTP server
52
55
  * can serve it as well as turno's stdio server.
@@ -114,3 +117,7 @@ export declare function runHost(args: string[], options?: {
114
117
  */
115
118
  serve?: (host: Host) => Promise<void>;
116
119
  }): Promise<void>;
120
+ /** Why the person cannot see a headless Chrome now, or undefined when the live view shows it. */
121
+ export declare function unseenReason(live: {
122
+ viewerCount: number;
123
+ } | undefined, id: string | undefined): string | undefined;