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 +36 -0
- package/README.md +2 -2
- package/dist/cli/args.js +2 -78
- package/dist/cli/commands/browser-do-session.js +16 -117
- package/dist/cli/commands/browser-do.js +99 -598
- package/dist/cli/commands/browser.js +130 -440
- package/dist/cli/commands/completion.js +3 -37
- package/dist/cli/commands/identity.js +101 -96
- package/dist/cli/commands/mcp-call.js +2 -38
- package/dist/cli/commands/mcpd.js +8 -0
- package/dist/cli/exit.js +2 -64
- package/dist/cli/group.js +2 -61
- package/dist/cli/highlight.js +2 -235
- package/dist/cli/hints.js +5 -12
- package/dist/cli/io.js +2 -206
- package/dist/cli/output.js +2 -122
- package/dist/cli/registry.js +3 -2
- package/dist/cli/secret-input.js +2 -62
- package/dist/cli/style.js +2 -289
- package/dist/cli/topics.js +4 -0
- package/dist/core/paths.js +2 -9
- package/dist/mcpd/daemon.js +13 -0
- package/npm-shrinkwrap.json +5 -5
- package/package.json +3 -3
- package/dist/cli/commands/browser-flows.js +0 -300
- package/dist/cli/commands/browser-identity.js +0 -952
- package/dist/cli/commands/browser-live.js +0 -118
- package/dist/cli/commands/browser-session.js +0 -102
- package/dist/cli/commands/browser-vault.js +0 -193
|
@@ -1,26 +1,18 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
import { loadManifest } from "../../core/manifest.js";
|
|
1
3
|
import { paths, tildify } from "../../core/paths.js";
|
|
2
|
-
import {
|
|
3
|
-
import { group } from "../group.js";
|
|
4
|
-
import { fail, needsAnswer, paint } from "../io.js";
|
|
4
|
+
import { hintsOn } from "../hints.js";
|
|
5
5
|
import { OPTIONAL, loadOptional, notInstalled } from "../optional.js";
|
|
6
|
-
import {
|
|
7
|
-
import { ACTION_NAMES, DO_DETAILS, DO_JSON, DO_FLAG_NAMES, DO_SYNOPSIS, browserDo, defaultDoDeps, } from "./browser-do.js";
|
|
8
|
-
import * as flowCmd from "./browser-flows.js";
|
|
9
|
-
import * as ident from "./browser-identity.js";
|
|
10
|
-
import * as liveCmd from "./browser-live.js";
|
|
11
|
-
import * as session from "./browser-session.js";
|
|
12
|
-
import { vaultCommand } from "./browser-vault.js";
|
|
13
|
-
/** `turno browser bench --json`: turno-browser's report. */
|
|
14
|
-
const BENCH_JSON = jsonOutput(["version", "startedAt", "finishedAt", "engines", "results", "file"]);
|
|
15
|
-
/** `turno browser identities --json`: one element per identity. */
|
|
16
|
-
const IDENTITIES_JSON = jsonOutput(["id", "inUse", "dir"]);
|
|
6
|
+
import { defaultDoDeps, mcpdTransport } from "./browser-do.js";
|
|
17
7
|
/**
|
|
18
8
|
* The API version this turno was built against. Typed by the package's own constant, so a
|
|
19
9
|
* change of its API_VERSION in the workspace fails the typecheck until this line follows.
|
|
20
10
|
*/
|
|
21
|
-
export const BROWSER_API = { major: 1, minor:
|
|
11
|
+
export const BROWSER_API = { major: 1, minor: 12 };
|
|
22
12
|
export const INSTALL_HINT = OPTIONAL.browser.install;
|
|
23
13
|
export const NOT_INSTALLED = notInstalled(OPTIONAL.browser);
|
|
14
|
+
/** The summary in `turno help` (registry.ts HELP_SUMMARY). */
|
|
15
|
+
const SUMMARY = "developer tool: compare browser engines (needs turno-browser)";
|
|
24
16
|
/** A turno-browser this command can drive: its API object has the calls every subcommand needs. */
|
|
25
17
|
function isBrowserPackage(mod) {
|
|
26
18
|
const api = mod?.api;
|
|
@@ -28,7 +20,7 @@ function isBrowserPackage(mod) {
|
|
|
28
20
|
api !== null &&
|
|
29
21
|
Array.isArray(api.ENGINES) &&
|
|
30
22
|
typeof api.listIdentities === "function" &&
|
|
31
|
-
typeof api.
|
|
23
|
+
typeof api.cli === "function");
|
|
32
24
|
}
|
|
33
25
|
/**
|
|
34
26
|
* Load turno-browser's API: next to this install first, then (with `global`) from the global
|
|
@@ -54,203 +46,6 @@ export const defaultDeps = {
|
|
|
54
46
|
interactive: (io) => Boolean(io.ask),
|
|
55
47
|
confirm: (question) => askOnTerminal(question),
|
|
56
48
|
};
|
|
57
|
-
function checkId(mod, id, sub) {
|
|
58
|
-
if (!id)
|
|
59
|
-
return fail(`browser ${sub} needs an identity id (for example: turno browser ${sub} school)`);
|
|
60
|
-
try {
|
|
61
|
-
mod.assertIdentityId(id);
|
|
62
|
-
}
|
|
63
|
-
catch (err) {
|
|
64
|
-
return fail(err.message);
|
|
65
|
-
}
|
|
66
|
-
return id;
|
|
67
|
-
}
|
|
68
|
-
const BENCH_FLAGS = {
|
|
69
|
-
engine: { type: "string", multiple: true },
|
|
70
|
-
url: { type: "string", multiple: true },
|
|
71
|
-
"only-urls": { type: "boolean" },
|
|
72
|
-
// Older name of --only-urls, kept so scripts keep working.
|
|
73
|
-
"no-detectors": { type: "boolean" },
|
|
74
|
-
yes: { type: "boolean", short: "y" },
|
|
75
|
-
...JSON_FLAG,
|
|
76
|
-
};
|
|
77
|
-
export const BENCH_PROMPT = "This opens Chrome and visits third-party test pages. Continue? [y/N] ";
|
|
78
|
-
const URLS_PROMPT = "This opens Chrome and visits the URLs you gave. Continue? [y/N] ";
|
|
79
|
-
async function bench(mod, args, io, deps) {
|
|
80
|
-
const p = parseFlags(args, BENCH_FLAGS, 0);
|
|
81
|
-
const list = (name) => (p.values[name] ?? [])
|
|
82
|
-
.flatMap((v) => v.split(","))
|
|
83
|
-
.map((v) => v.trim())
|
|
84
|
-
.filter(Boolean);
|
|
85
|
-
const given = list("engine");
|
|
86
|
-
const urls = p.values.url ?? [];
|
|
87
|
-
const onlyUrls = bool(p, "only-urls") || bool(p, "no-detectors");
|
|
88
|
-
const engines = [];
|
|
89
|
-
for (const e of given) {
|
|
90
|
-
const id = mod.engineId(e);
|
|
91
|
-
if (!id)
|
|
92
|
-
return fail(`unknown engine "${e}" (known: ${mod.ENGINES.join(", ")})`);
|
|
93
|
-
engines.push(id);
|
|
94
|
-
}
|
|
95
|
-
for (const u of urls) {
|
|
96
|
-
if (!/^https?:\/\//.test(u))
|
|
97
|
-
return fail(`--url must start with http:// or https://: ${u}`);
|
|
98
|
-
}
|
|
99
|
-
if (onlyUrls && urls.length === 0)
|
|
100
|
-
return fail("--only-urls needs at least one --url");
|
|
101
|
-
// Opening a browser on outside pages needs a yes from a person: --json is not consent.
|
|
102
|
-
if (!bool(p, "yes")) {
|
|
103
|
-
if (!deps.interactive(io)) {
|
|
104
|
-
io.err("browser bench opens Chrome and visits third-party test pages.");
|
|
105
|
-
return needsAnswer("browser bench");
|
|
106
|
-
}
|
|
107
|
-
if (!(await deps.confirm(onlyUrls ? URLS_PROMPT : BENCH_PROMPT, io))) {
|
|
108
|
-
io.err("Cancelled; nothing was opened.");
|
|
109
|
-
return 1;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const report = await mod.runBench({
|
|
113
|
-
engines,
|
|
114
|
-
urls,
|
|
115
|
-
detectors: !onlyUrls,
|
|
116
|
-
env: io.env,
|
|
117
|
-
onProgress: (m) => io.err(paint(io, m, "2")),
|
|
118
|
-
});
|
|
119
|
-
if (bool(p, "json")) {
|
|
120
|
-
emit(io, p, BENCH_JSON, report);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
io.out(mod.formatBenchTable(report));
|
|
124
|
-
if (report.file)
|
|
125
|
-
io.out(`\nreport: ${tildify(report.file, io.env)}`);
|
|
126
|
-
}
|
|
127
|
-
return 0;
|
|
128
|
-
}
|
|
129
|
-
function identities(mod, args, io) {
|
|
130
|
-
const p = parseFlags(args, JSON_FLAG, 0);
|
|
131
|
-
const list = mod.listIdentities(io.env);
|
|
132
|
-
if (bool(p, "json")) {
|
|
133
|
-
emit(io, p, IDENTITIES_JSON, list.map((i) => ({ id: i.id, inUse: i.inUse, dir: tildify(i.dir, io.env) })));
|
|
134
|
-
return 0;
|
|
135
|
-
}
|
|
136
|
-
if (!list.length) {
|
|
137
|
-
io.out("No browser identities yet. Create one with `turno identity add browser:<id>`.");
|
|
138
|
-
return 0;
|
|
139
|
-
}
|
|
140
|
-
const width = Math.max(...list.map((i) => i.id.length));
|
|
141
|
-
for (const i of list) {
|
|
142
|
-
const state = i.inUse ? paint(io, "in use", "33") : paint(io, "free ", "32");
|
|
143
|
-
io.out(`${i.id.padEnd(width)} ${state} ${tildify(i.dir, io.env)}`);
|
|
144
|
-
}
|
|
145
|
-
return 0;
|
|
146
|
-
}
|
|
147
|
-
function add(mod, args, io) {
|
|
148
|
-
const p = parseFlags(args, { ...DRY_RUN, ...ident.SETTINGS_FLAGS }, 1);
|
|
149
|
-
const id = checkId(mod, p.positionals[0], "add");
|
|
150
|
-
const settings = ident.settingsPatch(p);
|
|
151
|
-
if (bool(p, "dry-run")) {
|
|
152
|
-
io.out(`(dry run) would create browser identity "${id}"`);
|
|
153
|
-
return 0;
|
|
154
|
-
}
|
|
155
|
-
const info = ident.hasSettings(settings) ? mod.addIdentity(id, io.env, settings) : mod.addIdentity(id, io.env);
|
|
156
|
-
io.out(`identity "${id}" ready at ${tildify(info.dir, io.env)}`);
|
|
157
|
-
io.out(`settings (time zone, languages, health check) in ${tildify(mod.identitySettingsPath(id, io.env), io.env)}`);
|
|
158
|
-
io.out(`\nAdd this to ${tildify(paths(io.env).mcpFile, io.env)}, then run \`turno mcp sync\`:\n`);
|
|
159
|
-
io.out(settings.sharing === "tabs" ? mod.manifestSnippet(id, { sharing: "tabs" }) : mod.manifestSnippet(id));
|
|
160
|
-
io.out(`Sign in to your sites once with \`turno identity login browser:${id}\`.`);
|
|
161
|
-
return 0;
|
|
162
|
-
}
|
|
163
|
-
async function remove(mod, args, io) {
|
|
164
|
-
const p = parseFlags(args, DRY_RUN, 1);
|
|
165
|
-
const id = checkId(mod, p.positionals[0], "remove");
|
|
166
|
-
if (bool(p, "dry-run")) {
|
|
167
|
-
io.out(`(dry run) would delete browser identity "${id}", its saved logins and its vault credentials`);
|
|
168
|
-
return 0;
|
|
169
|
-
}
|
|
170
|
-
if (mod.isInUse(id, io.env))
|
|
171
|
-
return fail(`identity "${id}" is in use by a running Chrome; close it first`);
|
|
172
|
-
// The vault's secret store items first: removeIdentity refuses while they exist.
|
|
173
|
-
const cleared = await mod.vaultClear(id, { env: io.env });
|
|
174
|
-
if (cleared)
|
|
175
|
-
io.out(`deleted ${cleared} vault credential${cleared === 1 ? "" : "s"} of "${id}" from the secret store`);
|
|
176
|
-
mod.removeIdentity(id, io.env);
|
|
177
|
-
io.out(`removed identity "${id}" and its saved browser data`);
|
|
178
|
-
io.out(`Remove its [server.browser-${id}] block from ${tildify(paths(io.env).mcpFile, io.env)} if you added one.`);
|
|
179
|
-
return 0;
|
|
180
|
-
}
|
|
181
|
-
async function login(mod, args, io) {
|
|
182
|
-
const p = parseFlags(args, { url: { type: "string" } }, 1);
|
|
183
|
-
const id = checkId(mod, p.positionals[0], "login");
|
|
184
|
-
const url = str(p, "url");
|
|
185
|
-
if (url !== undefined && !/^https?:\/\//.test(url))
|
|
186
|
-
return fail(`--url must start with http:// or https://: ${url}`);
|
|
187
|
-
const holder = mod.inUseBy(id, io.env);
|
|
188
|
-
if (holder)
|
|
189
|
-
return fail(holder);
|
|
190
|
-
if (mod.isInUse(id, io.env)) {
|
|
191
|
-
return fail(`identity "${id}" is in use by a running Chrome (probably an MCP session through mcpd). Close that session or wait for its lease to end, then retry.`);
|
|
192
|
-
}
|
|
193
|
-
io.out(`Opening Chrome for identity "${id}". Sign in to your sites, then close the window to save the session.`);
|
|
194
|
-
const options = { env: io.env };
|
|
195
|
-
if (url)
|
|
196
|
-
options.url = url;
|
|
197
|
-
await mod.loginIdentity(id, options);
|
|
198
|
-
io.out(`saved. Sessions using browser-${id} now start signed in.`);
|
|
199
|
-
return 0;
|
|
200
|
-
}
|
|
201
|
-
/** Run one browser subcommand with a loaded module. `identity` uses it for browser:<id>. */
|
|
202
|
-
export async function dispatch(mod, sub, rest, io, deps = defaultDeps) {
|
|
203
|
-
try {
|
|
204
|
-
switch (sub) {
|
|
205
|
-
case "identities":
|
|
206
|
-
case "list":
|
|
207
|
-
return identities(mod, rest, io);
|
|
208
|
-
case "add":
|
|
209
|
-
return add(mod, rest, io);
|
|
210
|
-
case "remove":
|
|
211
|
-
case "rm":
|
|
212
|
-
return await remove(mod, rest, io);
|
|
213
|
-
case "login":
|
|
214
|
-
return await login(mod, rest, io);
|
|
215
|
-
case "bench":
|
|
216
|
-
return await bench(mod, rest, io, deps);
|
|
217
|
-
case "export":
|
|
218
|
-
return await session.exportSession(mod, rest, io);
|
|
219
|
-
case "import":
|
|
220
|
-
return await session.importSession(mod, rest, io, deps);
|
|
221
|
-
case "show":
|
|
222
|
-
return ident.show(mod, checkId(mod, rest.find((a) => !a.startsWith("-")), "show"), rest, io);
|
|
223
|
-
case "set":
|
|
224
|
-
return ident.set(mod, checkId(mod, rest.find((a) => !a.startsWith("-")), "set"), rest, io);
|
|
225
|
-
case "doctor":
|
|
226
|
-
return await ident.doctor(mod, rest, io);
|
|
227
|
-
case "reputation":
|
|
228
|
-
return ident.reputation(mod, rest, io, (id) => checkId(mod, id, "reputation"));
|
|
229
|
-
case "flows":
|
|
230
|
-
return flowCmd.flows(mod, rest, io);
|
|
231
|
-
case "replay":
|
|
232
|
-
return await flowCmd.replay(mod, rest, io);
|
|
233
|
-
case "traces":
|
|
234
|
-
return await flowCmd.traces(mod, rest, io);
|
|
235
|
-
case "record":
|
|
236
|
-
return flowCmd.record(mod, rest, io);
|
|
237
|
-
case "live":
|
|
238
|
-
return await liveCmd.live(mod, rest, io, deps.openUrl);
|
|
239
|
-
case "pause":
|
|
240
|
-
return await liveCmd.pause(mod, rest, io);
|
|
241
|
-
case "resume":
|
|
242
|
-
return await liveCmd.resume(mod, rest, io);
|
|
243
|
-
default:
|
|
244
|
-
return fail(`unknown browser command "${sub}"`);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
catch (err) {
|
|
248
|
-
const name = err.name;
|
|
249
|
-
if (["IdentityError", "VaultError", "SealError", "FlowError", "LiveError"].includes(name))
|
|
250
|
-
return fail(err.message);
|
|
251
|
-
throw err;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
49
|
const FOOTER = `A developer diagnostic for browser engine compatibility. It needs the separate
|
|
255
50
|
turno-browser package (${INSTALL_HINT}).
|
|
256
51
|
Identities are persistent Chrome profiles served by turno-browser-mcp, one session at a time
|
|
@@ -258,240 +53,135 @@ through mcpd; turno identity manages them too (browser:<id>). Ids use lowercase
|
|
|
258
53
|
digits, "-" and "_", for example "school".
|
|
259
54
|
turno browser do <id> <action> runs one action (open, snapshot, click, type, read...) on an
|
|
260
55
|
identity's browser through mcpd, for coding agents that prefer shell commands (do --help).`;
|
|
56
|
+
/** The value of `--flag v` or `--flag=v` in a server's args. */
|
|
57
|
+
function flagValue(args, flag) {
|
|
58
|
+
for (let i = 0; i < args.length; i++) {
|
|
59
|
+
if (args[i] === flag)
|
|
60
|
+
return args[i + 1];
|
|
61
|
+
if (args[i].startsWith(`${flag}=`))
|
|
62
|
+
return args[i].slice(flag.length + 1);
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
261
66
|
/**
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
* so a later subcommand can never change what a written command does.
|
|
67
|
+
* The mcp.toml servers that run turno-browser-mcp for an identity, for the doctor's check of
|
|
68
|
+
* `exclusive` against the identity's `sharing`. An unreadable mcp.toml gives none (`turno doctor`
|
|
69
|
+
* reports it).
|
|
266
70
|
*/
|
|
267
|
-
function
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
71
|
+
export function servedIdentities(env) {
|
|
72
|
+
let manifest;
|
|
73
|
+
try {
|
|
74
|
+
manifest = loadManifest(env);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
const out = [];
|
|
80
|
+
for (const [name, server] of Object.entries(manifest.servers)) {
|
|
81
|
+
if (server.kind !== "stdio")
|
|
82
|
+
continue;
|
|
83
|
+
const runs = [server.command, ...server.args].some((a) => basename(a) === "turno-browser-mcp");
|
|
84
|
+
const identity = flagValue(server.args, "--identity");
|
|
85
|
+
if (!runs || !identity)
|
|
86
|
+
continue;
|
|
87
|
+
const sharing = flagValue(server.args, "--sharing");
|
|
88
|
+
out.push({
|
|
89
|
+
name,
|
|
90
|
+
identity: identity.replace(/^browser:/, ""),
|
|
91
|
+
exclusive: server.exclusive,
|
|
92
|
+
scope: server.scope,
|
|
93
|
+
...(sharing ? { sharing } : {}),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
/** turno's host for turno-browser's commands: what only turno has. */
|
|
99
|
+
export function turnoHost(mod, doDeps = defaultDoDeps) {
|
|
100
|
+
const mcpFile = (env) => tildify(paths(env).mcpFile, env);
|
|
101
|
+
return {
|
|
102
|
+
names: {
|
|
103
|
+
program: "turno",
|
|
104
|
+
browser: "turno browser",
|
|
105
|
+
subject: "browser ",
|
|
106
|
+
identity: (sub, id) => `turno identity ${sub} browser:${id}`,
|
|
107
|
+
secretSet: (item) => `turno secret set ${item}`,
|
|
108
|
+
secretStore: "turno secret set",
|
|
109
|
+
},
|
|
110
|
+
footer: FOOTER,
|
|
111
|
+
addSummary: "create an identity (pinned to this time zone) and print its mcp.toml block",
|
|
112
|
+
connect(id, settings, io) {
|
|
113
|
+
io.out(`\nAdd this to ${mcpFile(io.env)}, then run \`turno mcp sync\`:\n`);
|
|
114
|
+
io.out(settings.sharing === "tabs" ? mod.manifestSnippet(id, { sharing: "tabs" }) : mod.manifestSnippet(id));
|
|
115
|
+
io.out(`Sign in to your sites once with \`turno identity login browser:${id}\`.`);
|
|
116
|
+
},
|
|
117
|
+
removed(id, io) {
|
|
118
|
+
io.out(`Remove its [server.browser-${id}] block from ${mcpFile(io.env)} if you added one.`);
|
|
119
|
+
},
|
|
120
|
+
// mcpd decides how many sessions reach the server, so `sharing` needs mcp.toml to follow.
|
|
121
|
+
sharingNote: (id, sharing) => sharing === "tabs"
|
|
122
|
+
? `In mcp.toml, set exclusive = false for [server.browser-${id}] (and drop lease), then run \`turno mcp sync\`: mcpd then lets every session in, and each gets its own tabs.`
|
|
123
|
+
: `In mcp.toml, set exclusive = true for [server.browser-${id}], then run \`turno mcp sync\`: one agent session at a time.`,
|
|
124
|
+
busy: { holder: "probably an MCP session through mcpd", end: "its lease to end" },
|
|
125
|
+
restart: "a new agent session, or turno mcp daemon restart",
|
|
126
|
+
servers: servedIdentities,
|
|
127
|
+
doTransport: mcpdTransport(doDeps),
|
|
128
|
+
hints: hintsOn,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** turno-browser's commands with turno's host, on the functions of `mod`. */
|
|
132
|
+
export function browserCli(mod, deps = defaultDeps, doDeps = defaultDoDeps) {
|
|
133
|
+
return mod.cli(turnoHost(mod, doDeps), {
|
|
134
|
+
api: mod,
|
|
135
|
+
interactive: deps.interactive,
|
|
136
|
+
confirm: deps.confirm,
|
|
137
|
+
...(deps.openUrl ? { openUrl: deps.openUrl } : {}),
|
|
138
|
+
...(doDeps.stdin ? { stdin: doDeps.stdin } : {}),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/** Run one browser subcommand with a loaded module. `identity` uses it for browser:<id>. */
|
|
142
|
+
export function dispatch(mod, sub, rest, io, deps = defaultDeps) {
|
|
143
|
+
return browserCli(mod, deps).run(sub, rest, io);
|
|
274
144
|
}
|
|
275
|
-
/**
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
145
|
+
/** `turno browser` before turno-browser is there: the usage says how to install it. */
|
|
146
|
+
const FALLBACK_USAGE = `Usage:
|
|
147
|
+
turno browser <command> [args]
|
|
148
|
+
|
|
149
|
+
${FOOTER}`;
|
|
150
|
+
/**
|
|
151
|
+
* The `browser` command. `preloaded` is the module the registry loaded to describe the
|
|
152
|
+
* subcommands (help, completion, the docs); null when it is not installed. Without it the
|
|
153
|
+
* command loads the module when it runs, with `deps` (tests inject a fake).
|
|
154
|
+
*/
|
|
155
|
+
export function browserCommand(deps = defaultDeps, doDeps = defaultDoDeps, preloaded) {
|
|
156
|
+
const run = async (args, io) => {
|
|
157
|
+
const mod = preloaded === null ? undefined : (preloaded ?? (await deps.load(io)));
|
|
279
158
|
if (!mod) {
|
|
159
|
+
if (!args.length || args[0] === "--help" || args[0] === "-h" || args[0] === "help" || args.includes("--help")) {
|
|
160
|
+
io.out(FALLBACK_USAGE);
|
|
161
|
+
return 0;
|
|
162
|
+
}
|
|
280
163
|
io.err(`turno: ${NOT_INSTALLED}`);
|
|
281
164
|
return 1;
|
|
282
165
|
}
|
|
283
|
-
return
|
|
284
|
-
};
|
|
285
|
-
const subs = {
|
|
286
|
-
identities: {
|
|
287
|
-
summary: "list browser identities and whether they are in use",
|
|
288
|
-
synopsis: "[--json]",
|
|
289
|
-
flags: ["--json"],
|
|
290
|
-
json: IDENTITIES_JSON,
|
|
291
|
-
run: withModule("identities"),
|
|
292
|
-
},
|
|
293
|
-
list: { summary: "same as identities", hidden: true, run: withModule("identities") },
|
|
294
|
-
add: {
|
|
295
|
-
summary: "create an identity (pinned to this time zone) and print its mcp.toml block",
|
|
296
|
-
synopsis: "<id> [--timezone <zone>] [--locale <tag>] [--languages <tag,...>] [--region <CC>] [--health-url <url> --health-text <text>] [--dry-run]",
|
|
297
|
-
flags: ["--dry-run", ...ident.SETTINGS_FLAG_NAMES],
|
|
298
|
-
run: withModule("add"),
|
|
299
|
-
},
|
|
300
|
-
show: {
|
|
301
|
-
summary: "an identity's settings, session health and who holds it",
|
|
302
|
-
synopsis: "<id> [--json]",
|
|
303
|
-
flags: ["--json"],
|
|
304
|
-
json: ident.SHOW_JSON,
|
|
305
|
-
run: withModule("show"),
|
|
306
|
-
},
|
|
307
|
-
set: {
|
|
308
|
-
summary: "change an identity's identity.json (an empty value removes a setting)",
|
|
309
|
-
synopsis: `<id> ${ident.SET_SYNOPSIS}`,
|
|
310
|
-
details: ident.SET_DETAILS,
|
|
311
|
-
flags: ident.SET_FLAG_NAMES,
|
|
312
|
-
json: ident.SET_JSON,
|
|
313
|
-
run: withModule("set"),
|
|
314
|
-
},
|
|
315
|
-
doctor: {
|
|
316
|
-
summary: "check Chrome, a test launch and every identity (settings, lock, sign-in), with fixes",
|
|
317
|
-
synopsis: "[--fix] [--no-launch] [--json]",
|
|
318
|
-
flags: ["--fix", "--no-launch", "--json"],
|
|
319
|
-
json: ident.DOCTOR_JSON,
|
|
320
|
-
run: withModule("doctor"),
|
|
321
|
-
},
|
|
322
|
-
reputation: {
|
|
323
|
-
summary: "challenges each identity met per site (captcha, verify it's you, block) and their trend",
|
|
324
|
-
synopsis: "[<id>] [--json]",
|
|
325
|
-
flags: ["--json"],
|
|
326
|
-
json: ident.REPUTATION_JSON,
|
|
327
|
-
run: withModule("reputation"),
|
|
328
|
-
},
|
|
329
|
-
vault: {
|
|
330
|
-
summary: "credentials browser_login fills without showing them to the agent",
|
|
331
|
-
synopsis: "add|list|remove|submit <id> ...",
|
|
332
|
-
ownHelp: true,
|
|
333
|
-
run: (args, io) => vaultCommand(deps).run(args, io),
|
|
334
|
-
},
|
|
335
|
-
record: {
|
|
336
|
-
summary: "what an identity records (flows, traces, screenshots); turn it on or off",
|
|
337
|
-
synopsis: "<id> [--flows] [--traces] [--screenshots] [--max-size <size>] [--off] [--dry-run] [--json]",
|
|
338
|
-
details: `With no flag, shows what the identity records and where. --flows, --traces and --screenshots
|
|
339
|
-
turn those on (the next Chrome start uses them), --off turns everything off; turn one off with
|
|
340
|
-
turno browser set <id> --record-traces false. All are off by default.
|
|
341
|
-
|
|
342
|
-
flows every session's actions saved as a flow (auto-<time>, newest 20 kept)
|
|
343
|
-
traces a Playwright trace of each browser session (turno browser traces)
|
|
344
|
-
screenshots a screenshot after each action
|
|
345
|
-
|
|
346
|
-
Vault sign-ins never reach a flow, a trace or a screenshot: the trace stops before a fill and
|
|
347
|
-
starts again after the page navigates, and a password or one-time code is never saved.`,
|
|
348
|
-
flags: ["--flows", "--traces", "--screenshots", "--max-size", "--off", "--dry-run", "--json"],
|
|
349
|
-
json: flowCmd.RECORD_JSON,
|
|
350
|
-
run: withModule("record"),
|
|
351
|
-
},
|
|
352
|
-
flows: {
|
|
353
|
-
summary: "an identity's saved flows; name one to see its steps, --remove to delete it",
|
|
354
|
-
synopsis: "<id> [<flow>] [--remove] [--dry-run] [--json]",
|
|
355
|
-
flags: ["--remove", "--dry-run", "--json"],
|
|
356
|
-
json: flowCmd.FLOWS_JSON,
|
|
357
|
-
run: withModule("flows"),
|
|
358
|
-
},
|
|
359
|
-
replay: {
|
|
360
|
-
summary: "run a saved flow on the identity's Chrome, without an agent",
|
|
361
|
-
synopsis: "<id> <flow> [--param <name=value>]... [--from <step>] [--headless] [--json]",
|
|
362
|
-
details: `Runs the flow through turno-browser-mcp, the same way an agent's browser_replay does. A
|
|
363
|
-
sensitive parameter is never a value on the command line: pass --param <name>=keychain:<item>
|
|
364
|
-
(store it once with turno secret set <item>), or type it at the hidden prompt. When a step fails,
|
|
365
|
-
the report says which locators it tried; --from continues at a later step.`,
|
|
366
|
-
flags: ["--param", "--from", "--headless", "--json"],
|
|
367
|
-
json: flowCmd.REPLAY_JSON,
|
|
368
|
-
run: withModule("replay"),
|
|
369
|
-
},
|
|
370
|
-
traces: {
|
|
371
|
-
summary: "an identity's recordings (traces, screenshots); --open shows a trace in the viewer",
|
|
372
|
-
synopsis: "<id> [<recording>] [--open] [--segment <n>] [--json]",
|
|
373
|
-
details: `--open serves the trace on 127.0.0.1 with the trace viewer patchright-core ships and opens it
|
|
374
|
-
in your default browser; Ctrl-C stops it. A recording has one trace per stretch of activity (a
|
|
375
|
-
vault sign-in or the idle limit ends one): --segment picks one, the last by default.`,
|
|
376
|
-
flags: ["--open", "--segment", "--json"],
|
|
377
|
-
json: flowCmd.TRACES_JSON,
|
|
378
|
-
run: withModule("traces"),
|
|
379
|
-
},
|
|
380
|
-
live: {
|
|
381
|
-
summary: "watch the agent in an identity's browser and take the controls (opens the live view)",
|
|
382
|
-
synopsis: "<id> [--no-open] [--json]",
|
|
383
|
-
details: `Shows what the agent is doing (paused or not, its tabs) and opens the live view in your
|
|
384
|
-
default browser: the agent's tab as a picture, Pause and Resume buttons, and while the agent is
|
|
385
|
-
paused, your clicks, keys and scrolls go to the page. The view is served on 127.0.0.1 only; the
|
|
386
|
-
link it opens works once. Off by default: turn it on with turno browser set <id> --live true
|
|
387
|
-
(it starts with the next turno-browser-mcp for the identity).
|
|
388
|
-
|
|
389
|
-
Read mode (Lightpanda) has no pixels, attach mode is your own Chrome, which you already see, and
|
|
390
|
-
Camoufox (Firefox) has no Chrome screencast: there the view is off, and pause and resume still work. A page that holds a vault or password
|
|
391
|
-
value is never shown until it navigates.`,
|
|
392
|
-
flags: ["--no-open", "--json"],
|
|
393
|
-
json: liveCmd.LIVE_JSON,
|
|
394
|
-
run: withModule("live"),
|
|
395
|
-
},
|
|
396
|
-
pause: {
|
|
397
|
-
summary: "pause the agent in an identity's browser: its next call waits until you resume",
|
|
398
|
-
synopsis: "<id> [--json]",
|
|
399
|
-
details: `A call that is running finishes; the next one waits up to the identity's live wait (2m by
|
|
400
|
-
default), then fails and tells the agent you still have the browser. A batch or replay stops at its
|
|
401
|
-
next step. In a headed Chrome the agent's tab comes to the front. Needs the live view on.`,
|
|
402
|
-
flags: ["--json"],
|
|
403
|
-
json: liveCmd.LIVE_JSON,
|
|
404
|
-
run: withModule("pause"),
|
|
405
|
-
},
|
|
406
|
-
resume: {
|
|
407
|
-
summary: "give the browser back to the agent; each waiting call is told what changed",
|
|
408
|
-
synopsis: "<id> [--json]",
|
|
409
|
-
details: `The waiting calls go on. Each starts with a note: how long the pause lasted and what changed
|
|
410
|
-
(the current tab's URL and title, tabs opened and closed, your input in the view). When something
|
|
411
|
-
changed, a call that does more than read does not run, and the agent gets a fresh snapshot instead.`,
|
|
412
|
-
flags: ["--json"],
|
|
413
|
-
json: liveCmd.LIVE_JSON,
|
|
414
|
-
run: withModule("resume"),
|
|
415
|
-
},
|
|
416
|
-
export: {
|
|
417
|
-
summary: "write an identity's cookies and site storage to a file encrypted with a passphrase",
|
|
418
|
-
synopsis: "<id> --out <file> [--expires 7d] [--force]",
|
|
419
|
-
flags: ["--out", "--expires", "--force"],
|
|
420
|
-
run: withModule("export"),
|
|
421
|
-
},
|
|
422
|
-
import: {
|
|
423
|
-
summary: "replace an identity's session with an export (asks first), or create it",
|
|
424
|
-
synopsis: "<file> [--as <id>] [--yes] [--dry-run]",
|
|
425
|
-
flags: ["--as", "--yes", "--dry-run"],
|
|
426
|
-
run: withModule("import"),
|
|
427
|
-
},
|
|
428
|
-
remove: {
|
|
429
|
-
summary: "delete an identity, its saved logins and its vault",
|
|
430
|
-
synopsis: "<id> [--dry-run]",
|
|
431
|
-
flags: ["--dry-run"],
|
|
432
|
-
run: withModule("remove"),
|
|
433
|
-
},
|
|
434
|
-
rm: { summary: "same as remove", hidden: true, run: withModule("remove") },
|
|
435
|
-
login: {
|
|
436
|
-
summary: "open the identity's Chrome to sign in by hand once",
|
|
437
|
-
synopsis: "<id> [--url <url>]",
|
|
438
|
-
flags: ["--url"],
|
|
439
|
-
run: withModule("login"),
|
|
440
|
-
},
|
|
441
|
-
do: {
|
|
442
|
-
summary: "one action on an identity's browser from the shell: open, snapshot, click, type, read...",
|
|
443
|
-
synopsis: DO_SYNOPSIS,
|
|
444
|
-
details: DO_DETAILS,
|
|
445
|
-
ownHelp: true,
|
|
446
|
-
json: DO_JSON,
|
|
447
|
-
flags: [...DO_FLAG_NAMES],
|
|
448
|
-
run: (args, io) => browserDo(args, io, doDeps),
|
|
449
|
-
},
|
|
450
|
-
bench: {
|
|
451
|
-
summary: "check how each browser engine loads reference test pages and your URLs (asks first)",
|
|
452
|
-
synopsis: "[--engine <name>]... [--url <url>]... [--only-urls] [--yes] [--json]",
|
|
453
|
-
flags: ["--engine", "--url", "--only-urls", "--yes", "--json"],
|
|
454
|
-
json: BENCH_JSON,
|
|
455
|
-
run: withModule("bench"),
|
|
456
|
-
},
|
|
457
|
-
};
|
|
458
|
-
const command = group("browser", "developer tool: compare browser engines (needs turno-browser)", subs, {
|
|
459
|
-
footer: FOOTER,
|
|
460
|
-
examples: [
|
|
461
|
-
"turno browser identities",
|
|
462
|
-
"turno browser add school --languages es-MX,es,en",
|
|
463
|
-
"turno browser show school",
|
|
464
|
-
"turno browser set school --health-url https://mail.example.com/ --health-text Inbox",
|
|
465
|
-
"turno browser set school --tabs-max 5 --tabs-popups keep --settle 250ms",
|
|
466
|
-
"turno browser set school --block-trackers true --cache --json",
|
|
467
|
-
"turno browser set school --humanize light",
|
|
468
|
-
"turno browser set school --sharing tabs",
|
|
469
|
-
"turno browser login school --url https://example.com",
|
|
470
|
-
"turno browser doctor --fix",
|
|
471
|
-
"turno browser reputation school --json",
|
|
472
|
-
"turno browser vault add school mail --url https://mail.example.com --username alice",
|
|
473
|
-
"turno browser record school --flows --traces",
|
|
474
|
-
"turno browser flows school",
|
|
475
|
-
"turno browser replay school submit-timesheet --param password=keychain:school-password",
|
|
476
|
-
"turno browser traces school --open",
|
|
477
|
-
"turno browser set school --live true",
|
|
478
|
-
"turno browser live school",
|
|
479
|
-
"turno browser pause school",
|
|
480
|
-
"turno browser resume school",
|
|
481
|
-
"turno browser export school --out school.session --expires 2d",
|
|
482
|
-
"turno browser import school.session --as school-laptop",
|
|
483
|
-
"turno browser remove school --dry-run",
|
|
484
|
-
"turno browser bench --only-urls --url https://example.com --yes",
|
|
485
|
-
"turno browser do school open https://example.com",
|
|
486
|
-
"turno browser do school snapshot",
|
|
487
|
-
"turno browser do school click e12",
|
|
488
|
-
"turno browser do school end",
|
|
489
|
-
],
|
|
490
|
-
});
|
|
491
|
-
return {
|
|
492
|
-
...command,
|
|
493
|
-
run: (args, io) => (shortDo(args, subs) ? browserDo(args, io, doDeps) : command.run(args, io)),
|
|
166
|
+
return browserCli(mod, deps, doDeps).command.run(args, io);
|
|
494
167
|
};
|
|
168
|
+
if (!preloaded)
|
|
169
|
+
return { summary: SUMMARY, usage: FALLBACK_USAGE, run };
|
|
170
|
+
const described = browserCli(preloaded, deps, doDeps).command;
|
|
171
|
+
return { ...described, summary: SUMMARY, run };
|
|
172
|
+
}
|
|
173
|
+
/** turno-browser when it loads without a word, for the registry: undefined when it does not. */
|
|
174
|
+
export async function preload() {
|
|
175
|
+
try {
|
|
176
|
+
return (await loadBrowser({ global: true, env: process.env })) ?? null;
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
// An API that does not fit: the command loads it again when it runs, and says what to update.
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/** The command as the registry loads it: described by the installed turno-browser. */
|
|
184
|
+
export async function loadCommand() {
|
|
185
|
+
return browserCommand(defaultDeps, defaultDoDeps, await preload());
|
|
495
186
|
}
|
|
496
|
-
export const command = browserCommand();
|
|
497
187
|
//# sourceMappingURL=browser.js.map
|
|
@@ -1,41 +1,7 @@
|
|
|
1
|
+
import { completionScripts } from "turno-core/cli";
|
|
1
2
|
import { parseFlags } from "../args.js";
|
|
2
3
|
import { fail } from "../io.js";
|
|
3
|
-
const
|
|
4
|
-
# turno completion for zsh. Load it with: source <(turno completion zsh)
|
|
5
|
-
_turno() {
|
|
6
|
-
local -a out
|
|
7
|
-
out=("\${(@f)$(turno __complete -- "\${(@)words[2,CURRENT]}" 2>/dev/null)}")
|
|
8
|
-
if [[ "\${out[1]}" == ":dir" ]]; then _files -/; return; fi
|
|
9
|
-
(( \${#out} )) && [[ -n "\${out[1]}" ]] && compadd -- "\${out[@]}"
|
|
10
|
-
}
|
|
11
|
-
compdef _turno turno
|
|
12
|
-
`;
|
|
13
|
-
const BASH = `# turno completion for bash. Load it with: source <(turno completion bash)
|
|
14
|
-
_turno() {
|
|
15
|
-
local IFS=$'\\n'
|
|
16
|
-
local out=($(turno __complete -- "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
17
|
-
if [[ "\${out[0]}" == ":dir" ]]; then
|
|
18
|
-
COMPREPLY=($(compgen -d -- "\${COMP_WORDS[COMP_CWORD]}"))
|
|
19
|
-
return
|
|
20
|
-
fi
|
|
21
|
-
COMPREPLY=("\${out[@]}")
|
|
22
|
-
}
|
|
23
|
-
complete -o default -F _turno turno
|
|
24
|
-
`;
|
|
25
|
-
const FISH = `# turno completion for fish. Load it with: turno completion fish | source
|
|
26
|
-
function __turno_complete
|
|
27
|
-
set -l words (commandline -opc) (commandline -ct)
|
|
28
|
-
set -e words[1]
|
|
29
|
-
set -l out (turno __complete -- $words 2>/dev/null)
|
|
30
|
-
if test "$out[1]" = ":dir"
|
|
31
|
-
__fish_complete_directories (commandline -ct)
|
|
32
|
-
return
|
|
33
|
-
end
|
|
34
|
-
printf '%s\\n' $out
|
|
35
|
-
end
|
|
36
|
-
complete -c turno -f -a '(__turno_complete)'
|
|
37
|
-
`;
|
|
38
|
-
export const SCRIPTS = { zsh: ZSH, bash: BASH, fish: FISH };
|
|
4
|
+
export const SCRIPTS = completionScripts("turno");
|
|
39
5
|
export const command = {
|
|
40
6
|
summary: "shell completion for commands, profiles, identities and config keys",
|
|
41
7
|
usage: [
|
|
@@ -43,7 +9,7 @@ export const command = {
|
|
|
43
9
|
"",
|
|
44
10
|
"Prints the completion script. To load it in every shell:",
|
|
45
11
|
" zsh echo 'source <(turno completion zsh)' >> ~/.zshrc",
|
|
46
|
-
" bash echo '
|
|
12
|
+
" bash echo 'eval \"$(turno completion bash)\"' >> ~/.bashrc",
|
|
47
13
|
" fish turno completion fish > ~/.config/fish/completions/turno.fish",
|
|
48
14
|
"",
|
|
49
15
|
"Examples:",
|