turno-browser 0.3.0 → 0.5.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 (131) hide show
  1. package/CHANGELOG.md +122 -0
  2. package/README.md +95 -123
  3. package/dist/act-model.d.ts +85 -0
  4. package/dist/act-model.js +117 -0
  5. package/dist/act.d.ts +37 -0
  6. package/dist/act.js +600 -0
  7. package/dist/api.d.ts +90 -2
  8. package/dist/api.js +41 -4
  9. package/dist/argv.d.ts +16 -2
  10. package/dist/argv.js +100 -3
  11. package/dist/background-state.d.ts +54 -0
  12. package/dist/background-state.js +97 -0
  13. package/dist/background.d.ts +69 -0
  14. package/dist/background.js +458 -0
  15. package/dist/batch.d.ts +5 -0
  16. package/dist/batch.js +3 -3
  17. package/dist/bin/mcp.js +103 -6
  18. package/dist/captcha.d.ts +77 -0
  19. package/dist/captcha.js +334 -0
  20. package/dist/cdp-relay.d.ts +20 -0
  21. package/dist/cdp-relay.js +101 -0
  22. package/dist/chrome-features.d.ts +23 -0
  23. package/dist/chrome-features.js +44 -0
  24. package/dist/cli/background.d.ts +11 -0
  25. package/dist/cli/background.js +132 -0
  26. package/dist/cli/commands.d.ts +16 -0
  27. package/dist/cli/commands.js +515 -0
  28. package/dist/cli/context.d.ts +75 -0
  29. package/dist/cli/context.js +44 -0
  30. package/dist/cli/do-background.d.ts +27 -0
  31. package/dist/cli/do-background.js +212 -0
  32. package/dist/cli/do.d.ts +85 -0
  33. package/dist/cli/do.js +558 -0
  34. package/dist/cli/flows.d.ts +28 -0
  35. package/dist/cli/flows.js +303 -0
  36. package/dist/cli/identity.d.ts +37 -0
  37. package/dist/cli/identity.js +906 -0
  38. package/dist/cli/live.d.ts +7 -0
  39. package/dist/cli/live.js +99 -0
  40. package/dist/cli/main.d.ts +16 -0
  41. package/dist/cli/main.js +171 -0
  42. package/dist/cli/secret.d.ts +4 -0
  43. package/dist/cli/secret.js +151 -0
  44. package/dist/cli/session.d.ts +6 -0
  45. package/dist/cli/session.js +106 -0
  46. package/dist/cli/setup.d.ts +7 -0
  47. package/dist/cli/setup.js +180 -0
  48. package/dist/cli/vault.d.ts +5 -0
  49. package/dist/cli/vault.js +192 -0
  50. package/dist/client.d.ts +82 -0
  51. package/dist/client.js +303 -0
  52. package/dist/diagnose.d.ts +7 -0
  53. package/dist/diagnose.js +61 -6
  54. package/dist/doctor.d.ts +37 -3
  55. package/dist/doctor.js +264 -6
  56. package/dist/engine-attach.d.ts +27 -0
  57. package/dist/engine-attach.js +165 -0
  58. package/dist/engine-camoufox.d.ts +32 -0
  59. package/dist/engine-camoufox.js +271 -0
  60. package/dist/engine-lightpanda.d.ts +72 -0
  61. package/dist/engine-lightpanda.js +293 -0
  62. package/dist/engine.d.ts +63 -11
  63. package/dist/engine.js +106 -29
  64. package/dist/flows.d.ts +127 -0
  65. package/dist/flows.js +294 -0
  66. package/dist/governor.d.ts +42 -7
  67. package/dist/governor.js +82 -32
  68. package/dist/health.js +2 -1
  69. package/dist/host.d.ts +38 -2
  70. package/dist/host.js +689 -52
  71. package/dist/human-input.d.ts +84 -0
  72. package/dist/human-input.js +448 -0
  73. package/dist/humanize.d.ts +123 -0
  74. package/dist/humanize.js +241 -0
  75. package/dist/identities.js +4 -1
  76. package/dist/idle-timer.d.ts +12 -0
  77. package/dist/idle-timer.js +25 -0
  78. package/dist/index.d.ts +13 -4
  79. package/dist/index.js +7 -1
  80. package/dist/lifecycle.d.ts +11 -1
  81. package/dist/lifecycle.js +11 -2
  82. package/dist/live-client.d.ts +22 -0
  83. package/dist/live-client.js +95 -0
  84. package/dist/live-page.d.ts +4 -0
  85. package/dist/live-page.js +144 -0
  86. package/dist/live-server.d.ts +173 -0
  87. package/dist/live-server.js +643 -0
  88. package/dist/live.d.ts +120 -0
  89. package/dist/live.js +204 -0
  90. package/dist/login-tool.d.ts +13 -0
  91. package/dist/login-tool.js +8 -3
  92. package/dist/login.d.ts +4 -1
  93. package/dist/login.js +12 -2
  94. package/dist/names.d.ts +28 -0
  95. package/dist/names.js +25 -0
  96. package/dist/network-chrome.d.ts +74 -0
  97. package/dist/network-chrome.js +178 -0
  98. package/dist/network.d.ts +125 -0
  99. package/dist/network.js +264 -0
  100. package/dist/opt-in-settings.d.ts +69 -0
  101. package/dist/opt-in-settings.js +152 -0
  102. package/dist/recorder.d.ts +88 -0
  103. package/dist/recorder.js +538 -0
  104. package/dist/recordings.d.ts +116 -0
  105. package/dist/recordings.js +474 -0
  106. package/dist/redact.d.ts +7 -0
  107. package/dist/redact.js +18 -0
  108. package/dist/replay.d.ts +20 -0
  109. package/dist/replay.js +383 -0
  110. package/dist/reputation.d.ts +24 -2
  111. package/dist/reputation.js +63 -17
  112. package/dist/runtime-lock.js +3 -2
  113. package/dist/session-export.js +1 -1
  114. package/dist/session.d.ts +10 -2
  115. package/dist/session.js +10 -2
  116. package/dist/settings.d.ts +104 -2
  117. package/dist/settings.js +204 -6
  118. package/dist/sharing.d.ts +96 -0
  119. package/dist/sharing.js +269 -0
  120. package/dist/snippet.d.ts +8 -2
  121. package/dist/snippet.js +10 -4
  122. package/dist/tab-locks.d.ts +63 -0
  123. package/dist/tab-locks.js +179 -0
  124. package/dist/tools.d.ts +38 -0
  125. package/dist/tools.js +20 -1
  126. package/dist/tuning.d.ts +14 -0
  127. package/dist/tuning.js +9 -0
  128. package/dist/upstream.d.ts +11 -0
  129. package/dist/vault.js +5 -4
  130. package/npm-shrinkwrap.json +6 -5
  131. package/package.json +13 -7
@@ -0,0 +1,7 @@
1
+ import { type Io } from "turno-core/cli";
2
+ import { type Ctx } from "./context.js";
3
+ /** `live|pause|resume <id> --json`. */
4
+ export declare const LIVE_JSON: import("turno-core/cli").JsonOutput;
5
+ export declare function live(c: Ctx, args: string[], io: Io): Promise<number>;
6
+ export declare function pause(c: Ctx, args: string[], io: Io): Promise<number>;
7
+ export declare function resume(c: Ctx, args: string[], io: Io): Promise<number>;
@@ -0,0 +1,99 @@
1
+ import { Exit, JSON_FLAG, bool, emit, fail, jsonOutput, parseFlags, style, } from "turno-core/cli";
2
+ import { openInBrowser } from "./context.js";
3
+ import { needIdentity } from "./flows.js";
4
+ /** `live|pause|resume <id> --json`. */
5
+ export const LIVE_JSON = jsonOutput([
6
+ "identity",
7
+ "pid",
8
+ "port",
9
+ "started",
10
+ "paused",
11
+ "waiting",
12
+ "busy",
13
+ "wait",
14
+ "browser",
15
+ "engine",
16
+ "view",
17
+ "showing",
18
+ "pinned",
19
+ "hidden",
20
+ "viewers",
21
+ "tabs",
22
+ ]);
23
+ /** `120000` as "2m", `90000` as "90s". */
24
+ function seconds(ms) {
25
+ return ms >= 60_000 && ms % 60_000 === 0 ? `${ms / 60_000}m` : `${Math.round(ms / 1000)}s`;
26
+ }
27
+ /** Why there is no live view to talk to: off, or no server running now. */
28
+ function notServing(c, id, io) {
29
+ const on = c.api.checkIdentitySettings(id, io.env).settings?.live?.enabled === true;
30
+ return fail(on
31
+ ? `no turno-browser-mcp serves "${id}" right now. The live view starts with the server (an agent session that uses browser-${id} starts it).`
32
+ : `the live view is off for "${id}" (the default). Turn it on with ${c.names.browser} set ${id} --live true; it starts with the next turno-browser-mcp for this identity.`);
33
+ }
34
+ function describe(status, io) {
35
+ const s = style(io);
36
+ const state = status.paused
37
+ ? `paused for ${seconds(Math.max(0, Date.now() - Date.parse(status.paused.since)))} (${status.paused.by})${status.waiting ? `, ${status.waiting} call${status.waiting === 1 ? "" : "s"} waiting` : ""}`
38
+ : status.busy
39
+ ? "the agent is working"
40
+ : "the agent is idle";
41
+ io.out(`${s.bold(status.identity)} ${state}`);
42
+ io.out(s.muted(` browser ${status.browser ? `running (${status.engine})` : "not running"}; a paused call waits up to ${seconds(status.wait)}`));
43
+ if (!status.view.available && status.view.reason)
44
+ io.out(s.note("info", status.view.reason, 2));
45
+ for (const t of status.tabs)
46
+ io.out(` ${t.id === status.showing ? "*" : " "} ${t.title || "(no title)"} ${s.muted(t.url)}${t.session ? s.muted(` [${t.session}]`) : ""}`);
47
+ }
48
+ const LIVE_FLAGS = { "no-open": { type: "boolean" }, ...JSON_FLAG };
49
+ export async function live(c, args, io) {
50
+ const mod = c.api;
51
+ const open = c.deps.openUrl ?? openInBrowser;
52
+ const p = parseFlags(args, LIVE_FLAGS, 1);
53
+ const id = needIdentity(c, p.positionals[0], "live", io);
54
+ const status = await mod.liveStatus(id, io.env);
55
+ if (!status)
56
+ return notServing(c, id, io);
57
+ if (bool(p, "json")) {
58
+ emit(io, p, LIVE_JSON, status);
59
+ return Exit.ok;
60
+ }
61
+ describe(status, io);
62
+ if (!status.view.available || bool(p, "no-open"))
63
+ return Exit.ok;
64
+ await open(await mod.liveLink(id, io.env), io);
65
+ io.err(style(io).muted(`opened the live view of "${id}" in your browser (the link works once; run this again for a new one)`));
66
+ return Exit.ok;
67
+ }
68
+ export async function pause(c, args, io) {
69
+ const mod = c.api;
70
+ const p = parseFlags(args, JSON_FLAG, 1);
71
+ const id = needIdentity(c, p.positionals[0], "pause", io);
72
+ if (!(await mod.liveStatus(id, io.env)))
73
+ return notServing(c, id, io);
74
+ const status = await mod.livePause(id, io.env);
75
+ if (bool(p, "json")) {
76
+ emit(io, p, LIVE_JSON, status);
77
+ return Exit.ok;
78
+ }
79
+ io.out(`paused "${id}": the agent's next call waits up to ${seconds(status.wait)} for you. Act in the browser${status.view.available ? ` or the live view (${c.names.browser} live ${id})` : ""}, then: ${c.names.browser} resume ${id}`);
80
+ return Exit.ok;
81
+ }
82
+ export async function resume(c, args, io) {
83
+ const mod = c.api;
84
+ const p = parseFlags(args, JSON_FLAG, 1);
85
+ const id = needIdentity(c, p.positionals[0], "resume", io);
86
+ const before = await mod.liveStatus(id, io.env);
87
+ if (!before)
88
+ return notServing(c, id, io);
89
+ const status = await mod.liveResume(id, io.env);
90
+ if (bool(p, "json")) {
91
+ emit(io, p, LIVE_JSON, status);
92
+ return Exit.ok;
93
+ }
94
+ io.out(before?.paused
95
+ ? `resumed "${id}": the agent's waiting calls go on, and each is told what changed.`
96
+ : `"${id}" was not paused.`);
97
+ return Exit.ok;
98
+ }
99
+ //# sourceMappingURL=live.js.map
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ import { type ColorMode, type Io } from "turno-core/cli";
3
+ import { type BrowserCli } from "./commands.js";
4
+ export declare function version(): string;
5
+ /** The main help: every command by section, drawn the way turno draws its own. */
6
+ export declare function renderHelp(io: Io, cli: BrowserCli): string[];
7
+ /**
8
+ * Take the global flags out of argv: `--no-input` and `--color auto|always|never` (or
9
+ * `--color=<mode>`), before the command or among its flags, never after `--`.
10
+ */
11
+ export declare function takeGlobals(argv: readonly string[]): {
12
+ argv: string[];
13
+ noInput: boolean;
14
+ color?: ColorMode;
15
+ };
16
+ export declare function main(args: string[], io?: Io): Promise<number>;
@@ -0,0 +1,171 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync, realpathSync } from "node:fs";
3
+ import { fileURLToPath } from "node:url";
4
+ import { CliError, Exit, UsageError, columns, confirm, defaultIo, exitName, fail, isColorMode, jsonError, noInputReason, style, withoutAsk, wrap, } from "turno-core/cli";
5
+ import { api } from "../api.js";
6
+ import { browserCli } from "./commands.js";
7
+ import { standaloneHost } from "./context.js";
8
+ /**
9
+ * `turno-browser <command>`: the identity commands on their own, without turno-cli. The same
10
+ * commands run inside turno as `turno browser <command>`; only the names in help and hints
11
+ * differ. The MCP server itself is the other program of this package, `turno-browser-mcp`.
12
+ */
13
+ const PROGRAM = "turno-browser";
14
+ /** The sections of `turno-browser --help`, in order. */
15
+ const SECTIONS = [
16
+ { title: "Identities", commands: ["list", "add", "show", "set", "login", "remove"] },
17
+ { title: "Connect an agent", commands: ["setup"] },
18
+ { title: "Sign-ins and sessions", commands: ["vault", "secret", "export", "import"] },
19
+ { title: "Flows and recordings", commands: ["record", "flows", "replay", "traces"] },
20
+ { title: "Watch and take over", commands: ["live", "pause", "resume"] },
21
+ { title: "From the shell", commands: ["do", "background"] },
22
+ { title: "Checks", commands: ["doctor", "reputation", "bench"] },
23
+ ];
24
+ export function version() {
25
+ const pkg = JSON.parse(readFileSync(fileURLToPath(new URL("../../package.json", import.meta.url)), "utf8"));
26
+ return pkg.version;
27
+ }
28
+ /** The main help: every command by section, drawn the way turno draws its own. */
29
+ export function renderHelp(io, cli) {
30
+ const s = style(io);
31
+ const width = Math.min(s.width, 100);
32
+ const out = [];
33
+ const tagline = `${PROGRAM}: a browser your agents use with your accounts. It stays light on your machine, and the model never sees your passwords.`;
34
+ const first = wrap(tagline, width);
35
+ out.push(s.color ? `${s.bold(s.accent(PROGRAM))}${s.bold(first[0].slice(PROGRAM.length))}` : first[0]);
36
+ for (const l of first.slice(1))
37
+ out.push(s.bold(l));
38
+ out.push("", s.header("Usage"));
39
+ out.push(columns([
40
+ [`${PROGRAM} <command> [flags]`, "manage identities: persistent Chrome profiles your agents sign in with"],
41
+ [`${PROGRAM} <command> --help`, "the flags and examples of one command"],
42
+ ["turno-browser-mcp --identity <id>", "the MCP server an agent runs for one identity (--help)"],
43
+ ]));
44
+ const left = Math.max(...SECTIONS.flatMap((x) => x.commands.map((n) => n.length)));
45
+ for (const section of SECTIONS) {
46
+ out.push("", s.header(section.title));
47
+ out.push(columns(section.commands.map((n) => [n, cli.subs[n]?.summary ?? ""]), 2, 32, left));
48
+ }
49
+ out.push("", s.header("Flags of every command"));
50
+ out.push(columns([
51
+ ["--json", "machine output, on commands that read (--json=fields lists the fields)"],
52
+ ["--dry-run", "say what a command that writes would do, and do nothing"],
53
+ ["--no-input", "never ask a question (also TURNO_NO_INPUT=1)"],
54
+ ["--color auto|always|never", "colors in the output (also NO_COLOR, TURNO_COLOR)"],
55
+ ["--version", `the ${PROGRAM} version`],
56
+ ]));
57
+ out.push("", s.muted(`${PROGRAM} help <command> prints the same as ${PROGRAM} <command> --help.`));
58
+ return out;
59
+ }
60
+ function colorValue(v) {
61
+ if (isColorMode(v))
62
+ return v;
63
+ return fail(v === undefined || v.startsWith("-")
64
+ ? "--color needs a value: auto, always or never"
65
+ : `--color ${v}: use auto, always or never`);
66
+ }
67
+ /**
68
+ * Take the global flags out of argv: `--no-input` and `--color auto|always|never` (or
69
+ * `--color=<mode>`), before the command or among its flags, never after `--`.
70
+ */
71
+ export function takeGlobals(argv) {
72
+ const end = argv.indexOf("--");
73
+ const own = end < 0 ? argv : argv.slice(0, end);
74
+ const kept = [];
75
+ let noInput = false;
76
+ let color;
77
+ for (let i = 0; i < own.length; i++) {
78
+ const a = own[i];
79
+ if (a === "--no-input")
80
+ noInput = true;
81
+ else if (a === "--color")
82
+ color = colorValue(own[++i]);
83
+ else if (a.startsWith("--color="))
84
+ color = colorValue(a.slice("--color=".length));
85
+ else
86
+ kept.push(a);
87
+ }
88
+ return { argv: [...kept, ...(end < 0 ? [] : argv.slice(end))], noInput, ...(color ? { color } : {}) };
89
+ }
90
+ /** Whether this run asked for --json: then an error is a JSON line on stderr. */
91
+ function wantsJson(argv) {
92
+ const end = argv.indexOf("--");
93
+ return (end < 0 ? argv : argv.slice(0, end)).some((a) => a === "--json" || a.startsWith("--json="));
94
+ }
95
+ /** Error classes whose message is the whole story: printed without a stack trace. */
96
+ const ONE_LINE_ERRORS = new Set(["SecretError", "IdentityError", "VaultError", "SealError", "FlowError", "LiveError"]);
97
+ function report(err, io, json) {
98
+ const e = err;
99
+ const code = err instanceof UsageError ? Exit.usage : err instanceof CliError ? err.code : Exit.failure;
100
+ const known = err instanceof UsageError || err instanceof CliError || ONE_LINE_ERRORS.has(e?.name);
101
+ if (json) {
102
+ const fields = err.fields;
103
+ io.err(jsonError(e?.message ?? String(err), code, exitName(code), {
104
+ ...(Array.isArray(fields) ? { fields } : {}),
105
+ ...(known ? {} : { stack: e?.stack }),
106
+ }));
107
+ }
108
+ else
109
+ io.err(`${PROGRAM}: ${known ? e.message : (e?.stack ?? e?.message ?? String(err))}`);
110
+ return code;
111
+ }
112
+ export async function main(args, io = defaultIo()) {
113
+ let picked;
114
+ try {
115
+ picked = takeGlobals(args);
116
+ }
117
+ catch (err) {
118
+ io.err(`${PROGRAM}: ${err.message}`);
119
+ return Exit.usage;
120
+ }
121
+ if (picked.color)
122
+ io = { ...io, color: picked.color };
123
+ // --no-input is TURNO_NO_INPUT=1, as in turno.
124
+ if (picked.noInput)
125
+ io = { ...withoutAsk(io), env: { ...io.env, TURNO_NO_INPUT: "1" } };
126
+ else if (io.ask && noInputReason(io.env))
127
+ io = withoutAsk(io);
128
+ const cli = browserCli(standaloneHost(), {
129
+ api,
130
+ interactive: (o) => Boolean(o.ask),
131
+ confirm: (question, o) => confirm(o, question.replace(/ \[y\/N\] $/, "")),
132
+ });
133
+ const [head, ...tail] = picked.argv;
134
+ const json = wantsJson(picked.argv);
135
+ try {
136
+ if (head === undefined || head === "-h" || head === "--help" || (head === "help" && !tail.length)) {
137
+ for (const l of renderHelp(io, cli))
138
+ io.out(l);
139
+ return Exit.ok;
140
+ }
141
+ if (head === "--version" || head === "-v") {
142
+ io.out(`${PROGRAM} ${version()}`);
143
+ return Exit.ok;
144
+ }
145
+ if (head === "help")
146
+ return await cli.command.run([...tail, "--help"], io);
147
+ if (head.startsWith("-"))
148
+ return fail(`unknown option ${head} (${PROGRAM} --help)`);
149
+ return await cli.command.run(picked.argv, io);
150
+ }
151
+ catch (err) {
152
+ return report(err, io, json);
153
+ }
154
+ }
155
+ function isEntry() {
156
+ try {
157
+ return Boolean(process.argv[1]) && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url);
158
+ }
159
+ catch {
160
+ return false;
161
+ }
162
+ }
163
+ if (isEntry()) {
164
+ main(process.argv.slice(2)).then((code) => {
165
+ process.exitCode = code;
166
+ }, (err) => {
167
+ process.stderr.write(`${PROGRAM}: ${err.stack ?? err}\n`);
168
+ process.exitCode = 1;
169
+ });
170
+ }
171
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1,4 @@
1
+ import { type Command } from "turno-core/cli";
2
+ import type { Ctx } from "./context.js";
3
+ /** The `secret` group. */
4
+ export declare function secretCommand(c: Ctx): Command;
@@ -0,0 +1,151 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { JSON_FLAG, bool, emit, fail, group, jsonOutput, needsAnswer, noInputReason, parseFlags, } from "turno-core/cli";
3
+ import { SecretError, requireSecretStore } from "turno-core/secrets";
4
+ import { terminalInput } from "./vault.js";
5
+ /**
6
+ * `turno-browser secret`: the items of the secret store that identity.json and replay
7
+ * parameters name as `keychain:<item>` (a proxy password, an act or captcha API key). The same
8
+ * store and the same items as turno's `turno secret`: the macOS Keychain or the Linux Secret
9
+ * Service. Values come from a hidden prompt or stdin, never from an argument, and are never
10
+ * printed. The vault's sign-in credentials have their own command (`vault`).
11
+ */
12
+ /** `secret list --json`: one element per keychain: reference in identity.json. */
13
+ const SECRET_JSON = jsonOutput(["item", "stored", "identities"]);
14
+ function store(io) {
15
+ try {
16
+ return requireSecretStore(io.env);
17
+ }
18
+ catch (err) {
19
+ return fail(err.message);
20
+ }
21
+ }
22
+ /** The keychain:<item> references in one identity.json. */
23
+ function keychainRefs(text) {
24
+ return [...new Set([...text.matchAll(/"keychain:([^"\\]+)"/g)].map((m) => m[1]))].sort();
25
+ }
26
+ /** One item name and no flags: an unknown flag must not become an item name. */
27
+ function itemOf(c, sub, args) {
28
+ const item = parseFlags(args, {}, 1).positionals[0];
29
+ if (!item)
30
+ return fail(`secret ${sub} needs an item name (for example: ${c.names.browser} secret ${sub} proxy-password)`);
31
+ return item;
32
+ }
33
+ async function set(c, args, io, input) {
34
+ const item = itemOf(c, "set", args);
35
+ const s = store(io);
36
+ let value;
37
+ if (input.isTty()) {
38
+ // The hidden prompt waits for a person: never with --no-input or inside an agent session.
39
+ if (noInputReason(io.env))
40
+ needsAnswer(`${c.names.subject}secret set`, "the value on stdin");
41
+ value = await input.hidden("value (input hidden, end with Enter): ");
42
+ }
43
+ else
44
+ value = await input.stdin(); // without one trailing line break
45
+ if (!value)
46
+ return fail("empty value: nothing stored");
47
+ await s.set(item, value);
48
+ io.out(`stored keychain:${item}`);
49
+ return 0;
50
+ }
51
+ async function has(c, args, io) {
52
+ const item = itemOf(c, "has", args);
53
+ if (await store(io).has(item)) {
54
+ io.out(`keychain:${item} exists`);
55
+ return 0;
56
+ }
57
+ io.out(`keychain:${item} not found`);
58
+ return 1;
59
+ }
60
+ async function remove(c, args, io) {
61
+ const item = itemOf(c, "remove", args);
62
+ if (!(await store(io).remove(item))) {
63
+ io.out(`keychain:${item} not found`);
64
+ return 1;
65
+ }
66
+ io.out(`removed keychain:${item}`);
67
+ return 0;
68
+ }
69
+ async function list(c, args, io) {
70
+ const p = parseFlags(args, JSON_FLAG, 0);
71
+ const users = new Map();
72
+ for (const { id } of c.api.listIdentities(io.env)) {
73
+ let text = "";
74
+ try {
75
+ text = readFileSync(c.api.identitySettingsPath(id, io.env), "utf8");
76
+ }
77
+ catch {
78
+ continue;
79
+ }
80
+ for (const item of keychainRefs(text))
81
+ users.set(item, [...(users.get(item) ?? []), id]);
82
+ }
83
+ const items = [...users.keys()].sort();
84
+ const s = items.length ? store(io) : undefined;
85
+ const found = s ? await Promise.all(items.map((i) => s.has(i))) : [];
86
+ if (bool(p, "json")) {
87
+ emit(io, p, SECRET_JSON, items.map((item, i) => ({ item, stored: found[i], identities: users.get(item) })));
88
+ return found.every(Boolean) ? 0 : 1;
89
+ }
90
+ if (!items.length)
91
+ io.out("no keychain: references in any identity.json");
92
+ for (const [i, item] of items.entries())
93
+ io.out(`${found[i] ? "stored " : "MISSING"} keychain:${item} (${users.get(item).join(", ")})${found[i] ? "" : ` ${c.names.browser} secret set ${item}`}`);
94
+ return found.every(Boolean) ? 0 : 1;
95
+ }
96
+ /** The `secret` group. */
97
+ export function secretCommand(c) {
98
+ const input = c.deps.input ?? terminalInput;
99
+ const b = c.names.browser;
100
+ const guarded = (run) => async (args, io) => {
101
+ try {
102
+ return await run(args, io);
103
+ }
104
+ catch (err) {
105
+ if (err instanceof SecretError)
106
+ return fail(err.message);
107
+ throw err;
108
+ }
109
+ };
110
+ const subs = {
111
+ set: {
112
+ summary: "store a value read from a hidden prompt or stdin",
113
+ synopsis: "<item>",
114
+ run: guarded((args, io) => set(c, args, io, input)),
115
+ },
116
+ has: {
117
+ summary: "exit 0 when the item exists",
118
+ synopsis: "<item>",
119
+ run: guarded((args, io) => has(c, args, io)),
120
+ },
121
+ list: {
122
+ summary: "every keychain: reference in identity.json and whether it is stored",
123
+ synopsis: "[--json]",
124
+ flags: ["--json"],
125
+ json: SECRET_JSON,
126
+ run: guarded((args, io) => list(c, args, io)),
127
+ },
128
+ remove: {
129
+ summary: "delete the item",
130
+ synopsis: "<item>",
131
+ run: guarded((args, io) => remove(c, args, io)),
132
+ },
133
+ rm: { summary: "same as remove", hidden: true, run: guarded((args, io) => remove(c, args, io)) },
134
+ };
135
+ return group(`${c.names.subject}secret`, "items of the secret store identity.json names", subs, {
136
+ fallback: "list",
137
+ footer: `An identity.json names a secret as "keychain:<item>" (proxy.password, act.key, captcha.key), and
138
+ so does a replay parameter (--param password=keychain:<item>). The store is the login Keychain on
139
+ macOS and the Secret Service (libsecret's secret-tool) on Linux, the same items turno secret uses.
140
+ Values are never printed and never passed as an argument. Sign-in credentials live in the vault
141
+ (${b} vault).`,
142
+ prefix: `${b} secret`,
143
+ examples: [
144
+ `printf %s "$PROXY_PASSWORD" | ${b} secret set proxy-password`,
145
+ `${b} secret has proxy-password`,
146
+ `${b} secret list --json`,
147
+ `${b} secret remove proxy-password`,
148
+ ],
149
+ });
150
+ }
151
+ //# sourceMappingURL=secret.js.map
@@ -0,0 +1,6 @@
1
+ import { type Io } from "turno-core/cli";
2
+ import type { Ctx } from "./context.js";
3
+ /** `7d`, `36h`: how long an export can be imported. */
4
+ export declare function parseExpiry(text: string): number;
5
+ export declare function exportSession(c: Ctx, args: string[], io: Io): Promise<number>;
6
+ export declare function importSession(c: Ctx, args: string[], io: Io): Promise<number>;
@@ -0,0 +1,106 @@
1
+ import { readFileSync, writeFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { DRY_RUN, bool, fail, needsAnswer, noInputReason, parseFlags, str } from "turno-core/cli";
4
+ import { tildify } from "turno-core/paths";
5
+ import { terminalInput } from "./vault.js";
6
+ /**
7
+ * `export` and `import`: an identity's signed-in session
8
+ * (cookies, localStorage, IndexedDB) as one file encrypted under a passphrase, with an expiry
9
+ * inside. The passphrase comes from a hidden prompt (asked twice on export) or the first line
10
+ * of stdin, never from a flag.
11
+ */
12
+ const EXPORT_FLAGS = {
13
+ out: { type: "string", short: "o" },
14
+ expires: { type: "string" },
15
+ force: { type: "boolean" },
16
+ };
17
+ const IMPORT_FLAGS = { as: { type: "string" }, yes: { type: "boolean", short: "y" }, ...DRY_RUN };
18
+ const DAY = 24 * 3600_000;
19
+ /** `7d`, `36h`: how long an export can be imported. */
20
+ export function parseExpiry(text) {
21
+ const m = /^(\d+)\s*(d|h)$/.exec(text.trim());
22
+ const ms = m ? Number(m[1]) * (m[2] === "d" ? DAY : 3600_000) : Number.NaN;
23
+ if (!(ms > 0 && ms <= 90 * DAY))
24
+ return fail(`--expires takes hours or days up to 90d, like 7d or 12h, not "${text}"`);
25
+ return ms;
26
+ }
27
+ async function passphrase(io, input, confirm, subject) {
28
+ if (input.isTty()) {
29
+ if (noInputReason(io.env))
30
+ needsAnswer(`${subject}${confirm ? "export" : "import"}`, "the passphrase on stdin");
31
+ const first = await input.hidden("Passphrase (input hidden): ");
32
+ if (confirm && (await input.hidden("Passphrase again: ")) !== first)
33
+ return fail("the passphrases differ; nothing was written");
34
+ return first;
35
+ }
36
+ return (await input.stdin()).split(/\r?\n/)[0] ?? "";
37
+ }
38
+ export async function exportSession(c, args, io) {
39
+ const mod = c.api;
40
+ const input = c.deps.input ?? terminalInput;
41
+ const p = parseFlags(args, EXPORT_FLAGS, 1);
42
+ const id = p.positionals[0];
43
+ if (!id)
44
+ return fail(`usage: ${c.names.browser} export <id> --out <file> [--expires 7d] [--force]`);
45
+ mod.assertIdentityId(id);
46
+ if (!mod.identityExists(id, io.env))
47
+ return fail(`browser identity "${id}" does not exist`);
48
+ const out = str(p, "out");
49
+ if (!out)
50
+ return fail("give the file to write with --out (for example --out school.session)");
51
+ const expiresInMs = parseExpiry(str(p, "expires") ?? "7d");
52
+ const file = resolve(out);
53
+ const secret = await passphrase(io, input, true, c.names.subject);
54
+ const { sealed, summary } = await mod.exportSession(id, { passphrase: secret, expiresInMs, env: io.env });
55
+ try {
56
+ writeFileSync(file, sealed, { mode: 0o600, flag: bool(p, "force") ? "w" : "wx" });
57
+ }
58
+ catch (err) {
59
+ if (err.code === "EEXIST")
60
+ return fail(`${tildify(file, io.env)} exists; pass --force to replace it`);
61
+ throw err;
62
+ }
63
+ io.out(`exported the session of "${id}" (${summary.cookies} cookies, storage of ${summary.origins} sites) to ${tildify(file, io.env)}`);
64
+ io.out(`it can be imported until ${summary.expiresAt}; it holds no vault credentials`);
65
+ return 0;
66
+ }
67
+ export async function importSession(c, args, io) {
68
+ const mod = c.api;
69
+ const deps = c.deps;
70
+ const input = c.deps.input ?? terminalInput;
71
+ const p = parseFlags(args, IMPORT_FLAGS, 1);
72
+ const path = p.positionals[0];
73
+ if (!path)
74
+ return fail(`usage: ${c.names.browser} import <file> [--as <id>] [--yes] [--dry-run]`);
75
+ let text;
76
+ try {
77
+ text = readFileSync(resolve(path), "utf8");
78
+ }
79
+ catch {
80
+ return fail(`cannot read ${path}`);
81
+ }
82
+ const as = str(p, "as");
83
+ if (as)
84
+ mod.assertIdentityId(as);
85
+ const secret = await passphrase(io, input, false, c.names.subject);
86
+ const { summary } = await mod.readSessionExport(text, secret);
87
+ const id = as ?? summary.identity;
88
+ const exists = mod.identityExists(id, io.env);
89
+ const what = `${summary.cookies} cookies and the storage of ${summary.origins} sites, exported from "${summary.identity}" on ${summary.createdAt}`;
90
+ if (bool(p, "dry-run")) {
91
+ io.out(`(dry run) would ${exists ? "replace the session of" : "create"} browser identity "${id}" with ${what}`);
92
+ return 0;
93
+ }
94
+ if (exists && !bool(p, "yes")) {
95
+ if (!deps.interactive(io))
96
+ needsAnswer(`${c.names.subject}import into an existing identity`);
97
+ if (!(await deps.confirm(`Replace the cookies and site storage of "${id}"? Its current sign-ins are lost. [y/N] `, io))) {
98
+ io.out("nothing imported");
99
+ return 1;
100
+ }
101
+ }
102
+ const done = await mod.importSession(text, { passphrase: secret, ...(as ? { as } : {}), env: io.env });
103
+ io.out(`${done.created ? "created" : "replaced the session of"} browser identity "${done.identity}" with ${what}`);
104
+ return 0;
105
+ }
106
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1,7 @@
1
+ import { type Io } from "turno-core/cli";
2
+ import type { Ctx } from "./context.js";
3
+ /** `setup --json`: one object. */
4
+ export declare const SETUP_JSON: import("turno-core/cli").JsonOutput;
5
+ 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.";
6
+ /** `<browser> setup <agent> [--identity <id>] [--json]`. */
7
+ export declare function setup(c: Ctx, args: string[], io: Io): number;