turno-cli 0.2.0 → 0.3.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 (112) hide show
  1. package/CHANGELOG.md +148 -0
  2. package/README.md +127 -39
  3. package/dist/accounts/audit.js +27 -15
  4. package/dist/accounts/builtin.js +35 -7
  5. package/dist/accounts/delegate.js +30 -7
  6. package/dist/accounts/policy.js +4 -2
  7. package/dist/accounts/registry.js +3 -1
  8. package/dist/agents/adapter.js +22 -0
  9. package/dist/agents/claude.js +54 -3
  10. package/dist/agents/codex.js +94 -6
  11. package/dist/agents/copilot.js +19 -2
  12. package/dist/agents/cursor.js +19 -2
  13. package/dist/agents/index.js +1 -1
  14. package/dist/agents/snippets.js +37 -10
  15. package/dist/cli/args.js +32 -15
  16. package/dist/cli/commands/accounts.js +29 -7
  17. package/dist/cli/commands/auto.js +50 -12
  18. package/dist/cli/commands/browser-identity.js +514 -0
  19. package/dist/cli/commands/browser-session.js +102 -0
  20. package/dist/cli/commands/browser-vault.js +193 -0
  21. package/dist/cli/commands/browser.js +159 -59
  22. package/dist/cli/commands/complete.js +13 -3
  23. package/dist/cli/commands/completion.js +4 -0
  24. package/dist/cli/commands/config.js +90 -13
  25. package/dist/cli/commands/demo.js +36 -7
  26. package/dist/cli/commands/doctor.js +170 -36
  27. package/dist/cli/commands/identity.js +99 -12
  28. package/dist/cli/commands/init.js +42 -10
  29. package/dist/cli/commands/limit.js +65 -9
  30. package/dist/cli/commands/mcp-call.js +240 -0
  31. package/dist/cli/commands/mcp-oauth.js +33 -6
  32. package/dist/cli/commands/mcp-observe.js +128 -23
  33. package/dist/cli/commands/mcp-share.js +201 -0
  34. package/dist/cli/commands/mcp.js +203 -42
  35. package/dist/cli/commands/mcpd.js +76 -12
  36. package/dist/cli/commands/open.js +26 -3
  37. package/dist/cli/commands/profile.js +212 -30
  38. package/dist/cli/commands/resolve.js +8 -1
  39. package/dist/cli/commands/run.js +24 -4
  40. package/dist/cli/commands/secret.js +23 -38
  41. package/dist/cli/commands/session.js +16 -5
  42. package/dist/cli/commands/sessions.js +7 -1
  43. package/dist/cli/commands/setup.js +83 -11
  44. package/dist/cli/commands/status.js +67 -15
  45. package/dist/cli/commands/statusline.js +7 -2
  46. package/dist/cli/commands/ui.js +17 -5
  47. package/dist/cli/commands/undo.js +39 -7
  48. package/dist/cli/commands/uninstall.js +24 -5
  49. package/dist/cli/commands/upgrade.js +113 -76
  50. package/dist/cli/commands/usage.js +11 -10
  51. package/dist/cli/commands/version.js +20 -8
  52. package/dist/cli/commands/which.js +5 -3
  53. package/dist/cli/diagnostics.js +184 -0
  54. package/dist/cli/exit.js +65 -0
  55. package/dist/cli/group.js +20 -8
  56. package/dist/cli/help.js +6 -1
  57. package/dist/cli/hints.js +30 -0
  58. package/dist/cli/io.js +24 -8
  59. package/dist/cli/launch.js +31 -2
  60. package/dist/cli/launchers.js +25 -10
  61. package/dist/cli/main.js +52 -18
  62. package/dist/cli/optional.js +144 -0
  63. package/dist/cli/output.js +123 -0
  64. package/dist/cli/picker.js +17 -5
  65. package/dist/cli/registry.js +20 -2
  66. package/dist/cli/safe.js +87 -0
  67. package/dist/cli/secret-input.js +63 -0
  68. package/dist/cli/security.js +31 -9
  69. package/dist/cli/style.js +35 -5
  70. package/dist/cli/topics.js +142 -0
  71. package/dist/core/config.js +39 -3
  72. package/dist/core/fsutil.js +2 -10
  73. package/dist/core/journal.js +19 -11
  74. package/dist/core/manifest.js +28 -1
  75. package/dist/core/paths.js +6 -112
  76. package/dist/core/profiles.js +28 -8
  77. package/dist/core/resolve.js +13 -3
  78. package/dist/core/secrets.js +4 -154
  79. package/dist/core/state-file.js +107 -0
  80. package/dist/core/update.js +14 -11
  81. package/dist/core/version.js +57 -10
  82. package/dist/demo/server.js +10 -2
  83. package/dist/mcpd/cache.js +6 -7
  84. package/dist/mcpd/calllog.js +10 -9
  85. package/dist/mcpd/client-names.js +8 -13
  86. package/dist/mcpd/connectors.js +42 -3
  87. package/dist/mcpd/daemon.js +29 -8
  88. package/dist/mcpd/folder-sets.js +5 -2
  89. package/dist/mcpd/gateway.js +57 -29
  90. package/dist/mcpd/health.js +69 -25
  91. package/dist/mcpd/importer.js +106 -9
  92. package/dist/mcpd/instances.js +59 -31
  93. package/dist/mcpd/jsonrpc.js +3 -1
  94. package/dist/mcpd/middleware.js +144 -0
  95. package/dist/mcpd/modern.js +57 -19
  96. package/dist/mcpd/oauth.js +71 -17
  97. package/dist/mcpd/peerpid.js +15 -3
  98. package/dist/mcpd/pressure.js +4 -1
  99. package/dist/mcpd/rss.js +34 -19
  100. package/dist/mcpd/service.js +28 -4
  101. package/dist/mcpd/share.js +217 -0
  102. package/dist/mcpd/state.js +16 -16
  103. package/dist/mcpd/sync.js +22 -12
  104. package/dist/mcpd/systemd.js +4 -1
  105. package/dist/mcpd/tokens.js +4 -8
  106. package/dist/mcpd/upstream.js +12 -5
  107. package/dist/statusline/cost.js +17 -4
  108. package/dist/statusline/input.js +15 -3
  109. package/dist/ui/fonts.js +1 -1
  110. package/dist/ui/settings.js +6 -1
  111. package/npm-shrinkwrap.json +12 -3
  112. package/package.json +7 -6
@@ -0,0 +1,193 @@
1
+ import { DRY_RUN, JSON_FLAG, bool, flagsOf, parseFlags, str } from "../args.js";
2
+ import { group } from "../group.js";
3
+ import { nextStep } from "../hints.js";
4
+ import { fail, needsAnswer, noInputReason } from "../io.js";
5
+ import { emit, jsonOutput } from "../output.js";
6
+ import { readHidden, readStdinText, readVisible, stdinIsTty } from "../secret-input.js";
7
+ import { OPTIONAL, notInstalled } from "../optional.js";
8
+ /**
9
+ * `turno browser vault`: the credential vault of a browser identity. Values go
10
+ * from a hidden prompt or stdin straight to turno-browser, which keeps them in the secret store;
11
+ * nothing here prints, logs or passes one as an argument.
12
+ */
13
+ /** `turno browser vault list --json`. */
14
+ const VAULT_JSON = jsonOutput(["identity", "submit", "sites"]);
15
+ export const terminalInput = {
16
+ isTty: stdinIsTty,
17
+ hidden: readHidden,
18
+ visible: readVisible,
19
+ stdin: readStdinText,
20
+ };
21
+ const ADD_FLAGS = {
22
+ url: { type: "string", multiple: true },
23
+ username: { type: "string" },
24
+ totp: { type: "boolean" },
25
+ ...DRY_RUN,
26
+ };
27
+ function ids(mod, io, args, count, usage) {
28
+ const words = args.slice(0, count);
29
+ if (words.length < count || words.some((w) => !w))
30
+ return fail(`usage: turno browser vault ${usage}`);
31
+ try {
32
+ mod.assertIdentityId(words[0]);
33
+ }
34
+ catch (err) {
35
+ return fail(err.message);
36
+ }
37
+ if (!mod.identityExists(words[0], io.env))
38
+ return fail(`browser identity "${words[0]}" does not exist (turno browser add ${words[0]})`);
39
+ return words;
40
+ }
41
+ async function add(mod, args, io, input) {
42
+ const p = parseFlags(args, ADD_FLAGS, 2);
43
+ const [id, site] = ids(mod, io, p.positionals, 2, "add <identity> <site> --url <sign-in page> [--username <name>] [--totp]");
44
+ const urls = p.values.url ?? [];
45
+ if (!urls.length)
46
+ return fail("give the sign-in page with --url (for example --url https://github.com/login)");
47
+ const withTotp = bool(p, "totp");
48
+ if (bool(p, "dry-run")) {
49
+ io.out(`(dry run) would store a username, a password${withTotp ? " and a TOTP secret" : ""} for ${site} in browser identity "${id}"`);
50
+ return 0;
51
+ }
52
+ let username = str(p, "username");
53
+ let password;
54
+ let totp;
55
+ if (input.isTty()) {
56
+ // Hidden prompts wait for a person: never with --no-input or inside an agent session.
57
+ if (noInputReason(io.env))
58
+ needsAnswer("browser vault add", "the password on stdin (and --username)");
59
+ username ??= await input.visible(`Username for ${site}: `);
60
+ password = await input.hidden(`Password for ${site} (input hidden): `);
61
+ if (withTotp)
62
+ totp = await input.hidden("TOTP secret or otpauth:// URI (input hidden): ");
63
+ }
64
+ else {
65
+ if (!username)
66
+ return fail("give --username when the password comes on stdin");
67
+ const lines = (await input.stdin()).split(/\r?\n/);
68
+ password = lines[0] ?? "";
69
+ if (withTotp)
70
+ totp = lines[1]?.trim() || undefined;
71
+ if (withTotp && !totp)
72
+ return fail("--totp reads the TOTP secret from the second line of stdin, and it is empty");
73
+ }
74
+ if (!password)
75
+ return fail("the password is empty; nothing was stored");
76
+ const entry = await mod.vaultAdd(id, site, { urls, username: username ?? "", password, ...(totp ? { totp } : {}) }, { env: io.env });
77
+ io.out(`stored the credentials of ${entry.site} for browser identity "${id}" (username, password${entry.totp ? ", TOTP secret" : ""}) in the secret store`);
78
+ io.out(`origins: ${entry.origins.join(", ")}`);
79
+ nextStep(io, `an agent on browser-${id} signs in with the browser_login tool (site "${entry.site}") on that sign-in page`);
80
+ return 0;
81
+ }
82
+ async function list(mod, args, io) {
83
+ const p = parseFlags(args, JSON_FLAG, 1);
84
+ const [id] = ids(mod, io, p.positionals, 1, "list <identity> [--json]");
85
+ const info = await mod.vaultList(id, { env: io.env });
86
+ if (bool(p, "json")) {
87
+ emit(io, p, VAULT_JSON, info);
88
+ return 0;
89
+ }
90
+ io.out(`browser identity "${id}": ${info.submit === "auto" ? "browser_login submits the form itself" : "browser_login fills, the agent clicks sign in"} (turno browser vault submit ${id} auto|confirm)`);
91
+ if (!info.sites.length) {
92
+ io.out(`No credentials yet. Add some with \`turno browser vault add ${id} <site> --url <sign-in page>\`.`);
93
+ return 0;
94
+ }
95
+ const width = Math.max(...info.sites.map((s) => s.site.length));
96
+ for (const s of info.sites) {
97
+ const state = s.stored ? "" : " MISSING from the secret store";
98
+ io.out(`${s.site.padEnd(width)} ${s.totp ? "password+totp" : "password "} ${s.origins.join(", ")}${state}`);
99
+ }
100
+ return info.sites.every((s) => s.stored) ? 0 : 1;
101
+ }
102
+ async function remove(mod, args, io) {
103
+ const p = parseFlags(args, DRY_RUN, 2);
104
+ const [id, site] = ids(mod, io, p.positionals, 2, "remove <identity> <site> [--dry-run]");
105
+ if (bool(p, "dry-run")) {
106
+ io.out(`(dry run) would delete the credentials of ${site} from browser identity "${id}"`);
107
+ return 0;
108
+ }
109
+ if (!(await mod.vaultRemove(id, site, { env: io.env }))) {
110
+ io.out(`browser identity "${id}" has no credentials for ${site}`);
111
+ return 1;
112
+ }
113
+ io.out(`removed the credentials of ${site} from browser identity "${id}"`);
114
+ return 0;
115
+ }
116
+ function submit(mod, args, io) {
117
+ const p = parseFlags(args, DRY_RUN, 2);
118
+ const [id, mode] = ids(mod, io, p.positionals, 2, "submit <identity> <confirm|auto>");
119
+ if (mode !== "confirm" && mode !== "auto")
120
+ return fail(`submit takes "confirm" (the agent clicks sign in) or "auto" (browser_login submits), not "${mode}"`);
121
+ if (bool(p, "dry-run")) {
122
+ io.out(`(dry run) would set browser_login of "${id}" to ${mode}`);
123
+ return 0;
124
+ }
125
+ mod.vaultSetSubmit(id, mode, { env: io.env });
126
+ io.out(mode === "auto"
127
+ ? `browser_login now submits the sign-in form itself for "${id}"`
128
+ : `browser_login now only fills the form for "${id}"; the agent clicks sign in`);
129
+ return 0;
130
+ }
131
+ const FOOTER = `The vault keeps a username, a password and optionally a TOTP secret per site for one
132
+ browser identity, only in the secret store (the macOS Keychain or the Linux Secret Service).
133
+ The browser_login tool fills them into the site's sign-in page without the agent seeing them,
134
+ and only on the origins given with --url. In a terminal the password and the TOTP secret are
135
+ asked with hidden prompts; from a pipe, the first line of stdin is the password and, with
136
+ --totp, the second line is the TOTP secret (base32, or the otpauth:// URI of the QR code).`;
137
+ /** The `browser vault` group; `load` is the browser group's loader. */
138
+ export function vaultCommand(deps, input = terminalInput) {
139
+ const withModule = (run) => async (args, io) => {
140
+ const mod = await deps.load(io);
141
+ if (!mod)
142
+ return fail(notInstalled(OPTIONAL.browser));
143
+ try {
144
+ return await run(mod, args, io);
145
+ }
146
+ catch (err) {
147
+ const name = err.name;
148
+ if (name === "VaultError" || name === "IdentityError" || name === "TotpError")
149
+ return fail(err.message);
150
+ throw err;
151
+ }
152
+ };
153
+ const subs = {
154
+ add: {
155
+ summary: "store a site's username, password and optional TOTP secret (asked hidden, or on stdin)",
156
+ synopsis: "<identity> <site> --url <sign-in page> [--url <url>]... [--username <name>] [--totp] [--dry-run]",
157
+ flags: flagsOf(ADD_FLAGS),
158
+ run: withModule((mod, args, io) => add(mod, args, io, input)),
159
+ },
160
+ list: {
161
+ summary: "the sites in an identity's vault (never the values)",
162
+ synopsis: "<identity> [--json]",
163
+ flags: ["--json"],
164
+ json: VAULT_JSON,
165
+ run: withModule(list),
166
+ },
167
+ remove: {
168
+ summary: "delete a site's credentials",
169
+ synopsis: "<identity> <site> [--dry-run]",
170
+ flags: ["--dry-run"],
171
+ run: withModule(remove),
172
+ },
173
+ rm: { summary: "same as remove", hidden: true, run: withModule(remove) },
174
+ submit: {
175
+ summary: "let browser_login submit the form (auto) or leave the click to the agent (confirm, default)",
176
+ synopsis: "<identity> <confirm|auto> [--dry-run]",
177
+ flags: ["--dry-run"],
178
+ run: withModule(submit),
179
+ },
180
+ };
181
+ return group("browser vault", "credentials browser_login fills without showing them", subs, {
182
+ footer: FOOTER,
183
+ examples: [
184
+ "turno browser vault add work github --url https://github.com/login --username alice --totp",
185
+ "printf '%s\\n' \"$PASSWORD\" | turno browser vault add work mail --url https://mail.example.com --username alice@example.com",
186
+ "turno browser vault list work",
187
+ "turno browser vault list work --json",
188
+ "turno browser vault submit work auto",
189
+ "turno browser vault remove work github --dry-run",
190
+ ],
191
+ });
192
+ }
193
+ //# sourceMappingURL=browser-vault.js.map
@@ -1,53 +1,40 @@
1
- import { execFileSync } from "node:child_process";
2
- import { createRequire } from "node:module";
3
- import { join } from "node:path";
4
- import { pathToFileURL } from "node:url";
5
1
  import { paths, tildify } from "../../core/paths.js";
6
- import { DRY_RUN, JSON_FLAG, bool, parseFlags, printJson, str } from "../args.js";
2
+ import { DRY_RUN, JSON_FLAG, bool, parseFlags, str } from "../args.js";
7
3
  import { group } from "../group.js";
8
4
  import { fail, needsAnswer, paint } from "../io.js";
9
- export const INSTALL_HINT = "npm install --global turno-browser";
10
- export const NOT_INSTALLED = `turno-browser is not installed: ${INSTALL_HINT}`;
11
- const SPEC = "turno-browser";
12
- function isMissing(err) {
13
- const code = err.code;
14
- return code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED";
15
- }
16
- /** The global npm folder, where `npm install --global turno-browser` puts the package. */
17
- function npmGlobalRoot(env) {
18
- try {
19
- return execFileSync("npm", ["root", "--global"], { env, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5000 }).trim() || undefined;
20
- }
21
- catch {
22
- return undefined;
23
- }
5
+ import { OPTIONAL, loadOptional, notInstalled } from "../optional.js";
6
+ import { emit, jsonOutput } from "../output.js";
7
+ import * as ident from "./browser-identity.js";
8
+ import * as session from "./browser-session.js";
9
+ import { vaultCommand } from "./browser-vault.js";
10
+ /** `turno browser bench --json`: turno-browser's report. */
11
+ const BENCH_JSON = jsonOutput(["version", "startedAt", "finishedAt", "engines", "results", "file"]);
12
+ /** `turno browser identities --json`: one element per identity. */
13
+ const IDENTITIES_JSON = jsonOutput(["id", "inUse", "dir"]);
14
+ /**
15
+ * The API version this turno was built against. Typed by the package's own constant, so a
16
+ * change of its API_VERSION in the workspace fails the typecheck until this line follows.
17
+ */
18
+ export const BROWSER_API = { major: 1, minor: 2 };
19
+ export const INSTALL_HINT = OPTIONAL.browser.install;
20
+ export const NOT_INSTALLED = notInstalled(OPTIONAL.browser);
21
+ /** A turno-browser this command can drive: its API object has the calls every subcommand needs. */
22
+ function isBrowserPackage(mod) {
23
+ const api = mod?.api;
24
+ return (typeof api === "object" &&
25
+ api !== null &&
26
+ Array.isArray(api.ENGINES) &&
27
+ typeof api.listIdentities === "function" &&
28
+ typeof api.runBench === "function");
24
29
  }
25
30
  /**
26
- * Load turno-browser: next to this install first, then (with `global`) from the global npm
27
- * folder, which a Homebrew or npx install of turno cannot see on its own.
31
+ * Load turno-browser's API: next to this install first, then (with `global`) from the global
32
+ * npm folder, which a Homebrew or npx install of turno cannot see on its own (loadOptional). A
33
+ * package whose API_VERSION does not fit is refused with one message that says what to update.
28
34
  */
29
35
  export async function loadBrowser(options = {}) {
30
- try {
31
- return (await import(SPEC));
32
- }
33
- catch (err) {
34
- if (!isMissing(err))
35
- throw err;
36
- }
37
- if (!options.global)
38
- return undefined;
39
- const root = npmGlobalRoot(options.env ?? process.env);
40
- if (!root)
41
- return undefined;
42
- try {
43
- const entry = createRequire(join(root, "noop.js")).resolve(SPEC);
44
- return (await import(pathToFileURL(entry).href));
45
- }
46
- catch (err) {
47
- if (isMissing(err))
48
- return undefined;
49
- throw err;
50
- }
36
+ const mod = await loadOptional(OPTIONAL.browser, { ...options, api: BROWSER_API, guard: isBrowserPackage });
37
+ return mod?.api;
51
38
  }
52
39
  async function askOnTerminal(question) {
53
40
  const { createInterface } = await import("node:readline/promises");
@@ -88,14 +75,16 @@ export const BENCH_PROMPT = "This opens Chrome and visits third-party test pages
88
75
  const URLS_PROMPT = "This opens Chrome and visits the URLs you gave. Continue? [y/N] ";
89
76
  async function bench(mod, args, io, deps) {
90
77
  const p = parseFlags(args, BENCH_FLAGS, 0);
91
- const list = (name) => (p.values[name] ?? []).flatMap((v) => v.split(",")).map((v) => v.trim()).filter(Boolean);
78
+ const list = (name) => (p.values[name] ?? [])
79
+ .flatMap((v) => v.split(","))
80
+ .map((v) => v.trim())
81
+ .filter(Boolean);
92
82
  const given = list("engine");
93
83
  const urls = p.values.url ?? [];
94
84
  const onlyUrls = bool(p, "only-urls") || bool(p, "no-detectors");
95
85
  const engines = [];
96
86
  for (const e of given) {
97
- // An older turno-browser has no engineId: its ENGINES list is the whole truth.
98
- const id = mod.engineId ? mod.engineId(e) : mod.ENGINES.includes(e) ? e : undefined;
87
+ const id = mod.engineId(e);
99
88
  if (!id)
100
89
  return fail(`unknown engine "${e}" (known: ${mod.ENGINES.join(", ")})`);
101
90
  engines.push(id);
@@ -125,7 +114,7 @@ async function bench(mod, args, io, deps) {
125
114
  onProgress: (m) => io.err(paint(io, m, "2")),
126
115
  });
127
116
  if (bool(p, "json")) {
128
- printJson(io, report);
117
+ emit(io, p, BENCH_JSON, report);
129
118
  }
130
119
  else {
131
120
  io.out(mod.formatBenchTable(report));
@@ -138,7 +127,7 @@ function identities(mod, args, io) {
138
127
  const p = parseFlags(args, JSON_FLAG, 0);
139
128
  const list = mod.listIdentities(io.env);
140
129
  if (bool(p, "json")) {
141
- printJson(io, list.map((i) => ({ id: i.id, inUse: i.inUse, dir: tildify(i.dir, io.env) })));
130
+ emit(io, p, IDENTITIES_JSON, list.map((i) => ({ id: i.id, inUse: i.inUse, dir: tildify(i.dir, io.env) })));
142
131
  return 0;
143
132
  }
144
133
  if (!list.length) {
@@ -153,26 +142,34 @@ function identities(mod, args, io) {
153
142
  return 0;
154
143
  }
155
144
  function add(mod, args, io) {
156
- const p = parseFlags(args, DRY_RUN, 1);
145
+ const p = parseFlags(args, { ...DRY_RUN, ...ident.SETTINGS_FLAGS }, 1);
157
146
  const id = checkId(mod, p.positionals[0], "add");
147
+ const settings = ident.settingsPatch(p);
158
148
  if (bool(p, "dry-run")) {
159
149
  io.out(`(dry run) would create browser identity "${id}"`);
160
150
  return 0;
161
151
  }
162
- const info = mod.addIdentity(id, io.env);
152
+ const info = ident.hasSettings(settings) ? mod.addIdentity(id, io.env, settings) : mod.addIdentity(id, io.env);
163
153
  io.out(`identity "${id}" ready at ${tildify(info.dir, io.env)}`);
154
+ io.out(`settings (time zone, languages, health check) in ${tildify(mod.identitySettingsPath(id, io.env), io.env)}`);
164
155
  io.out(`\nAdd this to ${tildify(paths(io.env).mcpFile, io.env)}, then run \`turno mcp sync\`:\n`);
165
156
  io.out(mod.manifestSnippet(id));
166
157
  io.out(`Sign in to your sites once with \`turno identity login browser:${id}\`.`);
167
158
  return 0;
168
159
  }
169
- function remove(mod, args, io) {
160
+ async function remove(mod, args, io) {
170
161
  const p = parseFlags(args, DRY_RUN, 1);
171
162
  const id = checkId(mod, p.positionals[0], "remove");
172
163
  if (bool(p, "dry-run")) {
173
- io.out(`(dry run) would delete browser identity "${id}" and its saved logins`);
164
+ io.out(`(dry run) would delete browser identity "${id}", its saved logins and its vault credentials`);
174
165
  return 0;
175
166
  }
167
+ if (mod.isInUse(id, io.env))
168
+ return fail(`identity "${id}" is in use by a running Chrome; close it first`);
169
+ // The vault's secret store items first: removeIdentity refuses while they exist.
170
+ const cleared = await mod.vaultClear(id, { env: io.env });
171
+ if (cleared)
172
+ io.out(`deleted ${cleared} vault credential${cleared === 1 ? "" : "s"} of "${id}" from the secret store`);
176
173
  mod.removeIdentity(id, io.env);
177
174
  io.out(`removed identity "${id}" and its saved browser data`);
178
175
  io.out(`Remove its [server.browser-${id}] block from ${tildify(paths(io.env).mcpFile, io.env)} if you added one.`);
@@ -184,6 +181,9 @@ async function login(mod, args, io) {
184
181
  const url = str(p, "url");
185
182
  if (url !== undefined && !/^https?:\/\//.test(url))
186
183
  return fail(`--url must start with http:// or https://: ${url}`);
184
+ const holder = mod.inUseBy(id, io.env);
185
+ if (holder)
186
+ return fail(holder);
187
187
  if (mod.isInUse(id, io.env)) {
188
188
  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.`);
189
189
  }
@@ -206,17 +206,30 @@ export async function dispatch(mod, sub, rest, io, deps = defaultDeps) {
206
206
  return add(mod, rest, io);
207
207
  case "remove":
208
208
  case "rm":
209
- return remove(mod, rest, io);
209
+ return await remove(mod, rest, io);
210
210
  case "login":
211
211
  return await login(mod, rest, io);
212
212
  case "bench":
213
213
  return await bench(mod, rest, io, deps);
214
+ case "export":
215
+ return await session.exportSession(mod, rest, io);
216
+ case "import":
217
+ return await session.importSession(mod, rest, io, deps);
218
+ case "show":
219
+ return ident.show(mod, checkId(mod, rest.find((a) => !a.startsWith("-")), "show"), rest, io);
220
+ case "set":
221
+ return ident.set(mod, checkId(mod, rest.find((a) => !a.startsWith("-")), "set"), rest, io);
222
+ case "doctor":
223
+ return await ident.doctor(mod, rest, io);
224
+ case "reputation":
225
+ return ident.reputation(mod, rest, io, (id) => checkId(mod, id, "reputation"));
214
226
  default:
215
227
  return fail(`unknown browser command "${sub}"`);
216
228
  }
217
229
  }
218
230
  catch (err) {
219
- if (err.name === "IdentityError")
231
+ const name = err.name;
232
+ if (name === "IdentityError" || name === "VaultError" || name === "SealError")
220
233
  return fail(err.message);
221
234
  throw err;
222
235
  }
@@ -237,20 +250,107 @@ export function browserCommand(deps = defaultDeps) {
237
250
  return dispatch(mod, sub, args, io, deps);
238
251
  };
239
252
  const subs = {
240
- identities: { summary: "list browser identities and whether they are in use", synopsis: "[--json]", flags: ["--json"], run: withModule("identities") },
253
+ identities: {
254
+ summary: "list browser identities and whether they are in use",
255
+ synopsis: "[--json]",
256
+ flags: ["--json"],
257
+ json: IDENTITIES_JSON,
258
+ run: withModule("identities"),
259
+ },
241
260
  list: { summary: "same as identities", hidden: true, run: withModule("identities") },
242
- add: { summary: "create an identity and print its mcp.toml block", synopsis: "<id> [--dry-run]", flags: ["--dry-run"], run: withModule("add") },
243
- remove: { summary: "delete an identity and its saved logins", synopsis: "<id> [--dry-run]", flags: ["--dry-run"], run: withModule("remove") },
261
+ add: {
262
+ summary: "create an identity (pinned to this time zone) and print its mcp.toml block",
263
+ synopsis: "<id> [--timezone <zone>] [--locale <tag>] [--languages <tag,...>] [--region <CC>] [--health-url <url> --health-text <text>] [--dry-run]",
264
+ flags: ["--dry-run", ...ident.SETTINGS_FLAG_NAMES],
265
+ run: withModule("add"),
266
+ },
267
+ show: {
268
+ summary: "an identity's settings, session health and who holds it",
269
+ synopsis: "<id> [--json]",
270
+ flags: ["--json"],
271
+ json: ident.SHOW_JSON,
272
+ run: withModule("show"),
273
+ },
274
+ set: {
275
+ summary: "change an identity's identity.json (an empty value removes a setting)",
276
+ synopsis: `<id> ${ident.SET_SYNOPSIS}`,
277
+ details: ident.SET_DETAILS,
278
+ flags: ident.SET_FLAG_NAMES,
279
+ json: ident.SET_JSON,
280
+ run: withModule("set"),
281
+ },
282
+ doctor: {
283
+ summary: "check Chrome, a test launch and every identity (settings, lock, sign-in), with fixes",
284
+ synopsis: "[--fix] [--no-launch] [--json]",
285
+ flags: ["--fix", "--no-launch", "--json"],
286
+ json: ident.DOCTOR_JSON,
287
+ run: withModule("doctor"),
288
+ },
289
+ reputation: {
290
+ summary: "challenges each identity met per site (captcha, verify it's you, block) and their trend",
291
+ synopsis: "[<id>] [--json]",
292
+ flags: ["--json"],
293
+ json: ident.REPUTATION_JSON,
294
+ run: withModule("reputation"),
295
+ },
296
+ vault: {
297
+ summary: "credentials browser_login fills without showing them to the agent",
298
+ synopsis: "add|list|remove|submit <id> ...",
299
+ ownHelp: true,
300
+ run: (args, io) => vaultCommand(deps).run(args, io),
301
+ },
302
+ export: {
303
+ summary: "write an identity's cookies and site storage to a file encrypted with a passphrase",
304
+ synopsis: "<id> --out <file> [--expires 7d] [--force]",
305
+ flags: ["--out", "--expires", "--force"],
306
+ run: withModule("export"),
307
+ },
308
+ import: {
309
+ summary: "replace an identity's session with an export (asks first), or create it",
310
+ synopsis: "<file> [--as <id>] [--yes] [--dry-run]",
311
+ flags: ["--as", "--yes", "--dry-run"],
312
+ run: withModule("import"),
313
+ },
314
+ remove: {
315
+ summary: "delete an identity, its saved logins and its vault",
316
+ synopsis: "<id> [--dry-run]",
317
+ flags: ["--dry-run"],
318
+ run: withModule("remove"),
319
+ },
244
320
  rm: { summary: "same as remove", hidden: true, run: withModule("remove") },
245
- login: { summary: "open the identity's Chrome to sign in by hand once", synopsis: "<id> [--url <url>]", flags: ["--url"], run: withModule("login") },
321
+ login: {
322
+ summary: "open the identity's Chrome to sign in by hand once",
323
+ synopsis: "<id> [--url <url>]",
324
+ flags: ["--url"],
325
+ run: withModule("login"),
326
+ },
246
327
  bench: {
247
328
  summary: "check how each browser engine loads reference test pages and your URLs (asks first)",
248
329
  synopsis: "[--engine <name>]... [--url <url>]... [--only-urls] [--yes] [--json]",
249
330
  flags: ["--engine", "--url", "--only-urls", "--yes", "--json"],
331
+ json: BENCH_JSON,
250
332
  run: withModule("bench"),
251
333
  },
252
334
  };
253
- return group("browser", "developer tool: compare browser engines (needs turno-browser)", subs, { footer: FOOTER });
335
+ return group("browser", "developer tool: compare browser engines (needs turno-browser)", subs, {
336
+ footer: FOOTER,
337
+ examples: [
338
+ "turno browser identities",
339
+ "turno browser add school --languages es-MX,es,en",
340
+ "turno browser show school",
341
+ "turno browser set school --health-url https://mail.example.com/ --health-text Inbox",
342
+ "turno browser set school --tabs-max 5 --tabs-popups keep --settle 250ms",
343
+ "turno browser set school --block-trackers true --cache --json",
344
+ "turno browser login school --url https://example.com",
345
+ "turno browser doctor --fix",
346
+ "turno browser reputation school --json",
347
+ "turno browser vault add school mail --url https://mail.example.com --username alice",
348
+ "turno browser export school --out school.session --expires 2d",
349
+ "turno browser import school.session --as school-laptop",
350
+ "turno browser remove school --dry-run",
351
+ "turno browser bench --only-urls --url https://example.com --yes",
352
+ ],
353
+ });
254
354
  }
255
355
  export const command = browserCommand();
256
356
  //# sourceMappingURL=browser.js.map
@@ -48,10 +48,19 @@ async function values(kind, env) {
48
48
  case "server":
49
49
  return safe(() => Object.keys(loadManifest(env).servers), []);
50
50
  case "stamp":
51
- return ["last", ...listJournals(env).filter((j) => j.manifest).map((j) => j.stamp)];
51
+ return [
52
+ "last",
53
+ ...listJournals(env)
54
+ .filter((j) => j.manifest)
55
+ .map((j) => j.stamp),
56
+ ];
52
57
  case "key": {
53
58
  const { CONFIG_KEYS } = await import("./config.js");
54
- return CONFIG_KEYS.flatMap((k) => k.includes("<name>") ? profiles().map((p) => k.replace("<name>", p)) : k.includes("<agent>") ? AGENT_IDS.filter((a) => a !== DEFAULT_AGENT).map((a) => k.replace("<agent>", a)) : [k]);
59
+ return CONFIG_KEYS.flatMap((k) => k.includes("<name>")
60
+ ? profiles().map((p) => k.replace("<name>", p))
61
+ : k.includes("<agent>")
62
+ ? AGENT_IDS.filter((a) => a !== DEFAULT_AGENT).map((a) => k.replace("<agent>", a))
63
+ : [k]);
55
64
  }
56
65
  case "shell":
57
66
  return ["zsh", "bash", "fish"];
@@ -92,7 +101,8 @@ export async function complete(words, env) {
92
101
  return match(comp.flags ?? []);
93
102
  const positionals = args.filter((a, i) => !a.startsWith("-") && !(i > 0 && FLAG_VALUES[args[i - 1]]));
94
103
  const kinds = comp.args ?? [];
95
- const kind = kinds[positionals.length] ?? (kinds[kinds.length - 1] === "profile" && kinds.length === 1 && name === "profile" ? "profile" : undefined);
104
+ const kind = kinds[positionals.length] ??
105
+ (kinds[kinds.length - 1] === "profile" && kinds.length === 1 && name === "profile" ? "profile" : undefined);
96
106
  if (!kind)
97
107
  return [];
98
108
  if (kind === "dir")
@@ -45,6 +45,10 @@ export const command = {
45
45
  " zsh echo 'source <(turno completion zsh)' >> ~/.zshrc",
46
46
  " bash echo 'source <(turno completion bash)' >> ~/.bashrc",
47
47
  " fish turno completion fish > ~/.config/fish/completions/turno.fish",
48
+ "",
49
+ "Examples:",
50
+ " $ turno completion zsh",
51
+ " $ turno completion fish > ~/.config/fish/completions/turno.fish",
48
52
  ].join("\n"),
49
53
  args: ["shell"],
50
54
  async run(args, io) {