turno-cli 0.0.0-stage → 0.1.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 (83) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +18 -0
  4. package/README.md +334 -2
  5. package/dist/accounts/audit.js +54 -0
  6. package/dist/accounts/builtin.js +214 -0
  7. package/dist/accounts/delegate.js +185 -0
  8. package/dist/accounts/registry.js +190 -0
  9. package/dist/agents/index.js +101 -0
  10. package/dist/agents/snippets.js +64 -0
  11. package/dist/cli/args.js +47 -0
  12. package/dist/cli/commands/accounts.js +216 -0
  13. package/dist/cli/commands/auto.js +44 -0
  14. package/dist/cli/commands/available.js +18 -0
  15. package/dist/cli/commands/browser.js +175 -0
  16. package/dist/cli/commands/complete.js +112 -0
  17. package/dist/cli/commands/completion.js +57 -0
  18. package/dist/cli/commands/config.js +168 -0
  19. package/dist/cli/commands/doctor.js +324 -0
  20. package/dist/cli/commands/exhausted.js +40 -0
  21. package/dist/cli/commands/handoff.js +118 -0
  22. package/dist/cli/commands/hook.js +63 -0
  23. package/dist/cli/commands/identity.js +114 -0
  24. package/dist/cli/commands/limit.js +102 -0
  25. package/dist/cli/commands/mcp.js +350 -0
  26. package/dist/cli/commands/mcpd.js +161 -0
  27. package/dist/cli/commands/migrate.js +176 -0
  28. package/dist/cli/commands/open.js +60 -0
  29. package/dist/cli/commands/profile.js +259 -0
  30. package/dist/cli/commands/resolve.js +23 -0
  31. package/dist/cli/commands/run.js +15 -0
  32. package/dist/cli/commands/secret.js +123 -0
  33. package/dist/cli/commands/session.js +36 -0
  34. package/dist/cli/commands/sessions.js +27 -0
  35. package/dist/cli/commands/setup.js +224 -0
  36. package/dist/cli/commands/status.js +101 -0
  37. package/dist/cli/commands/statusline.js +275 -0
  38. package/dist/cli/commands/ui.js +276 -0
  39. package/dist/cli/commands/undo.js +67 -0
  40. package/dist/cli/commands/update-check.js +22 -0
  41. package/dist/cli/commands/upgrade.js +162 -0
  42. package/dist/cli/commands/usage.js +167 -0
  43. package/dist/cli/commands/version.js +27 -0
  44. package/dist/cli/commands/which.js +28 -0
  45. package/dist/cli/group.js +50 -0
  46. package/dist/cli/io.js +22 -0
  47. package/dist/cli/launch.js +98 -0
  48. package/dist/cli/launchers.js +200 -0
  49. package/dist/cli/main.js +94 -0
  50. package/dist/cli/registry.js +77 -0
  51. package/dist/core/config-edit.js +42 -0
  52. package/dist/core/config.js +137 -0
  53. package/dist/core/exhausted.js +30 -0
  54. package/dist/core/journal.js +185 -0
  55. package/dist/core/manifest.js +177 -0
  56. package/dist/core/paths.js +54 -0
  57. package/dist/core/profiles.js +61 -0
  58. package/dist/core/ratelimit.js +39 -0
  59. package/dist/core/resolve.js +78 -0
  60. package/dist/core/secrets.js +44 -0
  61. package/dist/core/sessions.js +173 -0
  62. package/dist/core/toml-edit.js +152 -0
  63. package/dist/core/update.js +102 -0
  64. package/dist/core/version.js +103 -0
  65. package/dist/mcpd/cache.js +41 -0
  66. package/dist/mcpd/connectors.js +63 -0
  67. package/dist/mcpd/daemon.js +163 -0
  68. package/dist/mcpd/gateway.js +308 -0
  69. package/dist/mcpd/importer.js +160 -0
  70. package/dist/mcpd/instances.js +303 -0
  71. package/dist/mcpd/jsonrpc.js +19 -0
  72. package/dist/mcpd/launchd.js +86 -0
  73. package/dist/mcpd/peerpid.js +25 -0
  74. package/dist/mcpd/sync.js +208 -0
  75. package/dist/mcpd/upstream.js +232 -0
  76. package/dist/statusline/cost.js +135 -0
  77. package/dist/statusline/render.js +246 -0
  78. package/dist/ui/cmap.js +57 -0
  79. package/dist/ui/fonts.js +107 -0
  80. package/dist/ui/settings.js +69 -0
  81. package/dist/ui/terminal-id.js +30 -0
  82. package/dist/ui/terminals.js +163 -0
  83. package/package.json +69 -3
@@ -0,0 +1,101 @@
1
+ import { join } from "node:path";
2
+ import { paths } from "../core/paths.js";
3
+ /** The coding agents turno manages profiles for (ADR 0013). */
4
+ export const AGENT_IDS = ["claude", "codex", "copilot", "cursor"];
5
+ export function isAgentId(v) {
6
+ return typeof v === "string" && AGENT_IDS.includes(v);
7
+ }
8
+ const CLAUDE = {
9
+ id: "claude",
10
+ label: "Claude Code",
11
+ command: "claude",
12
+ homeEnv: "CLAUDE_CONFIG_DIR",
13
+ dirPrefix: ".claude-",
14
+ launcherPrefix: "claude-",
15
+ // The Claude Code lists live in cli/launchers.ts (SHARED_DIRS) and setup.ts (SHARED_FILES).
16
+ sharedDirs: [],
17
+ sharedFiles: [],
18
+ launcherEnv: [],
19
+ tokenFromEnv: false,
20
+ mcp: "claude",
21
+ sharedMcpFile: false,
22
+ install: "https://docs.claude.com/claude-code",
23
+ };
24
+ const CODEX = {
25
+ id: "codex",
26
+ label: "Codex CLI",
27
+ command: "codex",
28
+ homeEnv: "CODEX_HOME",
29
+ dirPrefix: ".codex-",
30
+ launcherPrefix: "codex-",
31
+ // Rollouts in sessions/ let `codex resume <id>` continue a session with another account
32
+ // (not verified across ChatGPT accounts yet; ADR 0013).
33
+ sharedDirs: ["sessions", "prompts", "skills"],
34
+ sharedFiles: ["AGENTS.md"],
35
+ launcherEnv: [],
36
+ tokenFromEnv: true,
37
+ mcp: "codex",
38
+ sharedMcpFile: false,
39
+ install: "npm install --global @openai/codex",
40
+ };
41
+ const COPILOT = {
42
+ id: "copilot",
43
+ label: "GitHub Copilot CLI",
44
+ command: "copilot",
45
+ homeEnv: "COPILOT_HOME",
46
+ dirPrefix: ".copilot-",
47
+ launcherPrefix: "copilot-",
48
+ sharedDirs: ["session-state"],
49
+ sharedFiles: [],
50
+ launcherEnv: [],
51
+ tokenFromEnv: true,
52
+ mcp: "copilot",
53
+ sharedMcpFile: false,
54
+ install: "npm install --global @github/copilot",
55
+ };
56
+ const CURSOR = {
57
+ id: "cursor",
58
+ label: "Cursor CLI",
59
+ command: "cursor-agent",
60
+ homeEnv: "CURSOR_CONFIG_DIR",
61
+ dirPrefix: ".cursor-",
62
+ launcherPrefix: "cursor-agent-",
63
+ sharedDirs: [],
64
+ sharedFiles: [],
65
+ // Without it every config dir shares the Keychain login (verified 2026-11-13, undocumented).
66
+ launcherEnv: ["export AGENT_CLI_CREDENTIAL_STORE=file"],
67
+ tokenFromEnv: true,
68
+ mcp: "cursor",
69
+ sharedMcpFile: true,
70
+ install: "curl https://cursor.com/install -fsS | bash",
71
+ };
72
+ const ADAPTERS = { claude: CLAUDE, codex: CODEX, copilot: COPILOT, cursor: CURSOR };
73
+ export function adapter(id = "claude") {
74
+ return ADAPTERS[id];
75
+ }
76
+ /** The agent's own home, shared by every profile of that agent: ~/.claude, ~/.codex, ... */
77
+ export function agentHub(id, env = process.env) {
78
+ const p = paths(env);
79
+ if (id === "claude")
80
+ return p.hub;
81
+ return join(p.home, `.${id}`);
82
+ }
83
+ /** The profile's home: ~/.claude-<name>, ~/.codex-<name>, ... */
84
+ export function agentProfileDir(name, id, env = process.env) {
85
+ return join(paths(env).home, `${adapter(id).dirPrefix}${name}`);
86
+ }
87
+ /** The file that holds a profile's MCP entries, or the shared one for Cursor. */
88
+ export function mcpFileFor(name, id, env = process.env) {
89
+ const dir = agentProfileDir(name, id, env);
90
+ switch (adapter(id).mcp) {
91
+ case "claude":
92
+ return join(dir, ".claude.json");
93
+ case "codex":
94
+ return join(dir, "config.toml");
95
+ case "copilot":
96
+ return join(dir, "mcp-config.json");
97
+ case "cursor":
98
+ return join(agentHub("cursor", env), "mcp.json");
99
+ }
100
+ }
101
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Config snippets that point agents turno does not manage at the MCP gateway (ADR 0013).
3
+ * turno prints them; the user pastes them. The token is never printed: each snippet reads it
4
+ * from TURNO_MCPD_TOKEN where the agent expands variables, and says so where it does not.
5
+ */
6
+ export const SNIPPET_AGENTS = ["opencode", "gemini", "goose", "crush", "droid", "kiro"];
7
+ export function isSnippetAgent(v) {
8
+ return SNIPPET_AGENTS.includes(v);
9
+ }
10
+ const url = (port, name) => `http://127.0.0.1:${port}/mcp/${encodeURIComponent(name)}`;
11
+ const TOKEN_ENV = 'Start the agent with TURNO_MCPD_TOKEN set, e.g. in your shell profile: export TURNO_MCPD_TOKEN="$(cat ~/.local/state/turno/mcpd.token)"';
12
+ function headers(profile, token) {
13
+ return { Authorization: `Bearer ${token}`, "X-Turno-Profile": profile };
14
+ }
15
+ function json(v) {
16
+ return `${JSON.stringify(v, null, 2)}\n`;
17
+ }
18
+ export function gatewaySnippet(agent, servers, port, profile) {
19
+ const each = (f) => Object.fromEntries(servers.map((n) => [n, f(n)]));
20
+ switch (agent) {
21
+ case "opencode":
22
+ return {
23
+ file: "opencode.json (project) or ~/.config/opencode/opencode.json",
24
+ text: json({ mcp: each((n) => ({ type: "remote", url: url(port, n), headers: headers(profile, "{env:TURNO_MCPD_TOKEN}"), enabled: true })) }),
25
+ notes: [TOKEN_ENV],
26
+ };
27
+ case "gemini":
28
+ return {
29
+ file: "~/.gemini/settings.json (or .gemini/settings.json in a project)",
30
+ text: json({ mcpServers: each((n) => ({ httpUrl: url(port, n), headers: headers(profile, "${TURNO_MCPD_TOKEN}") })) }),
31
+ notes: [TOKEN_ENV],
32
+ };
33
+ case "goose": {
34
+ const lines = ["extensions:"];
35
+ for (const n of servers) {
36
+ lines.push(` ${n}:`, ` name: ${n}`, " type: streamable_http", ` uri: ${url(port, n)}`, " enabled: true", " timeout: 300", " headers:", ' Authorization: "Bearer <paste the token from ~/.local/state/turno/mcpd.token>"', ` X-Turno-Profile: ${profile}`);
37
+ }
38
+ return {
39
+ file: "~/.config/goose/config.yaml",
40
+ text: `${lines.join("\n")}\n`,
41
+ notes: ["Goose does not document variable expansion in headers: paste the token by hand and keep the file private (chmod 600)."],
42
+ };
43
+ }
44
+ case "crush":
45
+ return {
46
+ file: "crush.json (project) or ~/.config/crush/crush.json",
47
+ text: json({ mcp: each((n) => ({ type: "http", url: url(port, n), headers: headers(profile, "$TURNO_MCPD_TOKEN") })) }),
48
+ notes: [TOKEN_ENV],
49
+ };
50
+ case "droid":
51
+ return {
52
+ file: "~/.factory/mcp.json",
53
+ text: json({ mcpServers: each((n) => ({ type: "http", url: url(port, n), headers: headers(profile, "${TURNO_MCPD_TOKEN}") })) }),
54
+ notes: [TOKEN_ENV, "Variable expansion in Droid headers is not verified: if the gateway answers 401, paste the token instead."],
55
+ };
56
+ case "kiro":
57
+ return {
58
+ file: "~/.kiro/settings/mcp.json",
59
+ text: json({ mcpServers: each((n) => ({ url: url(port, n), headers: headers(profile, "${TURNO_MCPD_TOKEN}") })) }),
60
+ notes: [TOKEN_ENV, "Variable expansion in Kiro headers is not verified: if the gateway answers 401, paste the token instead."],
61
+ };
62
+ }
63
+ }
64
+ //# sourceMappingURL=snippets.js.map
@@ -0,0 +1,47 @@
1
+ import { parseArgs } from "node:util";
2
+ import { fail } from "./io.js";
3
+ /** Flags shared by every command, so the same words mean the same thing everywhere. */
4
+ export const JSON_FLAG = { json: { type: "boolean" } };
5
+ export const DRY_RUN = { "dry-run": { type: "boolean" } };
6
+ export const FORCE = { force: { type: "boolean" } };
7
+ export const TAIL = { tail: { type: "string", short: "n" } };
8
+ export const WATCH = { watch: { type: "boolean" } };
9
+ /**
10
+ * Parse `args` against `spec` (long flags, `--flag=value`, short aliases). Unknown flags and
11
+ * positionals beyond `max` are usage errors with a plain message.
12
+ */
13
+ export function parseFlags(args, spec, max = Number.POSITIVE_INFINITY) {
14
+ let parsed;
15
+ try {
16
+ parsed = parseArgs({ args, options: spec, allowPositionals: true, strict: true });
17
+ }
18
+ catch (err) {
19
+ const msg = err.message.replace(/^Unknown option '(.+?)'.*$/s, "unknown option $1").replace(/\. To specify.*$/s, "");
20
+ return fail(msg.replace(/^Option '(--[\w-]+)(?: <value>)?' argument missing$/, "$1 needs a value"));
21
+ }
22
+ if (parsed.positionals.length > max)
23
+ fail(`unexpected argument '${parsed.positionals[max]}'`);
24
+ return parsed;
25
+ }
26
+ export function bool(p, name) {
27
+ return p.values[name] === true;
28
+ }
29
+ export function str(p, name) {
30
+ const v = p.values[name];
31
+ return typeof v === "string" ? v : undefined;
32
+ }
33
+ /** A positive integer flag such as --tail. */
34
+ export function count(p, name, fallback) {
35
+ const v = str(p, name);
36
+ if (v === undefined)
37
+ return fallback;
38
+ const n = Number.parseInt(v, 10);
39
+ if (!Number.isInteger(n) || n < 1 || String(n) !== v.trim())
40
+ fail(`--${name} must be a positive integer`);
41
+ return n;
42
+ }
43
+ /** Print a value as indented JSON. */
44
+ export function printJson(out, value) {
45
+ out(JSON.stringify(value, null, 2));
46
+ }
47
+ //# sourceMappingURL=args.js.map
@@ -0,0 +1,216 @@
1
+ import { resolve } from "node:path";
2
+ import { readAudit } from "../../accounts/audit.js";
3
+ import { launcherExists } from "../../accounts/delegate.js";
4
+ import { isValidService, loadRegistry, makeAccount, parseAccountId, saveRegistry } from "../../accounts/registry.js";
5
+ import { Journal } from "../../core/journal.js";
6
+ import { expandHome, paths, tildify } from "../../core/paths.js";
7
+ import { fail, paint } from "../io.js";
8
+ const USAGE = `Usage:
9
+ turno accounts list accounts, owners and folder preferences
10
+ turno accounts add <service:label> --profile <p> --tools <pattern>[,<pattern>]
11
+ [--service <s>] [--description <d>]
12
+ turno accounts remove <service:label>
13
+ turno accounts prefer <path> <service>=<account> (empty account removes the preference)
14
+ turno accounts log [-n N] recent calls to the accounts bridge
15
+
16
+ The registry lives in ~/.config/turno/accounts.toml. add, remove and prefer rewrite
17
+ the file (it is managed: comments in it are not preserved) and accept --dry-run.`;
18
+ /** Split args into positionals and --flag values (also --flag=value). */
19
+ function parseFlags(args, known) {
20
+ const pos = [];
21
+ const flags = {};
22
+ for (let i = 0; i < args.length; i++) {
23
+ const a = args[i];
24
+ if (!a.startsWith("--")) {
25
+ pos.push(a);
26
+ continue;
27
+ }
28
+ const eq = a.indexOf("=");
29
+ const name = eq > 0 ? a.slice(2, eq) : a.slice(2);
30
+ if (!known.includes(name))
31
+ fail(`unknown option --${name}`);
32
+ let value;
33
+ if (eq > 0)
34
+ value = a.slice(eq + 1);
35
+ else {
36
+ value = args[i + 1];
37
+ i += 1;
38
+ }
39
+ if (value === undefined)
40
+ fail(`--${name} needs a value`);
41
+ flags[name] = value;
42
+ }
43
+ return { pos, flags };
44
+ }
45
+ export function list(io) {
46
+ const reg = loadRegistry(io.env);
47
+ const accounts = Object.values(reg.accounts).sort((a, b) => a.id.localeCompare(b.id));
48
+ if (!accounts.length) {
49
+ io.out(`No accounts yet. Add one with: turno accounts add linear:work --profile work --tools 'mcp__linear__*'`);
50
+ io.out(`(${tildify(paths(io.env).accountsFile, io.env)})`);
51
+ return 0;
52
+ }
53
+ const width = Math.max(...accounts.map((a) => a.id.length));
54
+ for (const a of accounts) {
55
+ const missing = launcherExists(a.profile, io.env) ? "" : paint(io, " (no launcher)", "33");
56
+ io.out(`${paint(io, a.id.padEnd(width), "1")} ${a.profile.padEnd(12)} ${a.tools.join(", ")}${missing}`);
57
+ if (a.description)
58
+ io.out(`${" ".repeat(width)} ${paint(io, a.description, "2")}`);
59
+ }
60
+ if (reg.prefer.length) {
61
+ io.out("\nPreferences:");
62
+ for (const r of reg.prefer) {
63
+ const pairs = Object.entries(r.accounts).map(([s, id]) => `${s}=${id}`);
64
+ io.out(` ${tildify(r.path, io.env)} ${pairs.join(" ") || "(none)"}`);
65
+ }
66
+ }
67
+ return 0;
68
+ }
69
+ export function add(rawArgs, io) {
70
+ const dry = rawArgs.includes("--dry-run");
71
+ const args = rawArgs.filter((a) => a !== "--dry-run");
72
+ const journal = new Journal(io.env, `accounts add ${args.join(" ")}`, dry);
73
+ const { pos, flags } = parseFlags(args, ["profile", "tools", "service", "description"]);
74
+ const [id, extra] = pos;
75
+ if (!id || extra !== undefined)
76
+ fail("usage: turno accounts add <service:label> --profile <p> --tools <pattern>[,<pattern>]");
77
+ if (!flags.profile)
78
+ fail("--profile is required");
79
+ if (!flags.tools)
80
+ fail("--tools is required");
81
+ const tools = flags.tools
82
+ .split(",")
83
+ .map((t) => t.trim())
84
+ .filter(Boolean);
85
+ const reg = loadRegistry(io.env);
86
+ const existed = Boolean(reg.accounts[id]);
87
+ reg.accounts[id] = makeAccount(id, {
88
+ profile: flags.profile,
89
+ tools,
90
+ ...(flags.service ? { service: flags.service } : {}),
91
+ ...(flags.description ? { description: flags.description } : {}),
92
+ });
93
+ const file = saveRegistry(reg, io.env, journal);
94
+ io.out(`${existed ? "Updated" : "Added"} ${id} (profile ${flags.profile}) in ${tildify(file, io.env)}${dry ? " (dry run)" : ""}.`);
95
+ if (journal.hint())
96
+ io.out(journal.hint());
97
+ if (!launcherExists(flags.profile, io.env))
98
+ io.err(`warning: no launcher claude-${flags.profile} yet; delegation to it will fail until it exists.`);
99
+ return 0;
100
+ }
101
+ export function remove(rawArgs, io) {
102
+ const dry = rawArgs.includes("--dry-run");
103
+ const args = rawArgs.filter((a) => a !== "--dry-run");
104
+ const journal = new Journal(io.env, `accounts remove ${args.join(" ")}`, dry);
105
+ const [id, extra] = args;
106
+ if (!id || extra !== undefined)
107
+ fail("usage: turno accounts remove <service:label>");
108
+ const reg = loadRegistry(io.env);
109
+ if (!reg.accounts[id])
110
+ fail(`unknown account "${id}"`);
111
+ delete reg.accounts[id];
112
+ dropPreferences(reg, id);
113
+ const file = saveRegistry(reg, io.env, journal);
114
+ io.out(`Removed ${id} from ${tildify(file, io.env)}${dry ? " (dry run)" : ""}.`);
115
+ if (journal.hint())
116
+ io.out(journal.hint());
117
+ return 0;
118
+ }
119
+ function dropPreferences(reg, id) {
120
+ for (const r of reg.prefer) {
121
+ for (const [s, target] of Object.entries(r.accounts))
122
+ if (target === id)
123
+ delete r.accounts[s];
124
+ }
125
+ reg.prefer = reg.prefer.filter((r) => Object.keys(r.accounts).length > 0);
126
+ }
127
+ export function prefer(rawArgs, io) {
128
+ const dry = rawArgs.includes("--dry-run");
129
+ const args = rawArgs.filter((a) => a !== "--dry-run");
130
+ const journal = new Journal(io.env, `accounts prefer ${args.join(" ")}`, dry);
131
+ const [rawPath, pair, extra] = args;
132
+ if (!rawPath || !pair || extra !== undefined)
133
+ fail("usage: turno accounts prefer <path> <service>=<account>");
134
+ const eq = pair.indexOf("=");
135
+ if (eq <= 0)
136
+ fail("expected <service>=<account>, like linear=linear:work");
137
+ const service = pair.slice(0, eq);
138
+ const accountId = pair.slice(eq + 1);
139
+ if (!isValidService(service))
140
+ fail(`invalid service name "${service}"`);
141
+ const reg = loadRegistry(io.env);
142
+ const path = resolve(expandHome(rawPath, io.env));
143
+ let rule = reg.prefer.find((r) => r.path === path);
144
+ if (!accountId) {
145
+ if (rule)
146
+ delete rule.accounts[service];
147
+ reg.prefer = reg.prefer.filter((r) => Object.keys(r.accounts).length > 0);
148
+ saveRegistry(reg, io.env, journal);
149
+ io.out(`No ${service} preference for ${tildify(path, io.env)} now.`);
150
+ return 0;
151
+ }
152
+ const account = reg.accounts[accountId];
153
+ if (!account)
154
+ fail(`unknown account "${accountId}"`);
155
+ if (parseAccountId(accountId)?.service !== service)
156
+ fail(`account "${accountId}" belongs to service "${account.service}", not "${service}"`);
157
+ if (!rule) {
158
+ rule = { path, accounts: {} };
159
+ reg.prefer.push(rule);
160
+ }
161
+ rule.accounts[service] = accountId;
162
+ saveRegistry(reg, io.env, journal);
163
+ io.out(`In ${tildify(path, io.env)}, ${service} prefers ${accountId}${dry ? " (dry run)" : ""}.`);
164
+ if (journal.hint())
165
+ io.out(journal.hint());
166
+ return 0;
167
+ }
168
+ export function log(args, io) {
169
+ const { pos, flags } = parseFlags(args.map((a) => (a === "-n" ? "--tail" : a)), ["tail"]);
170
+ if (pos.length)
171
+ fail("usage: turno accounts log [--tail N]");
172
+ const n = flags.tail === undefined ? 20 : Number.parseInt(flags.tail, 10);
173
+ if (!Number.isInteger(n) || n < 1)
174
+ fail("--tail must be a positive integer");
175
+ const entries = readAudit(n, io.env);
176
+ if (!entries.length) {
177
+ io.out("No delegations recorded yet.");
178
+ return 0;
179
+ }
180
+ for (const e of entries) {
181
+ const when = new Date(e.ts).toLocaleString("en-US", { hour12: false });
182
+ const color = e.outcome === "ok" ? "32" : e.outcome === "refused" ? "33" : "31";
183
+ const who = `${e.caller.profile ?? "?"}${e.caller.pid ? `#${e.caller.pid}` : ""}`;
184
+ const cost = e.costUsd === null ? "" : ` $${e.costUsd.toFixed(4)}`;
185
+ const task = e.task.replace(/\s+/g, " ");
186
+ io.out(`${when} ${paint(io, e.outcome.padEnd(7), color)} ${who} -> ${e.account} (${e.owner ?? "?"}) ${e.write ? "write" : "read"} ${Math.round(e.durationMs / 1000)}s${cost}`);
187
+ io.out(` ${task.length > 120 ? `${task.slice(0, 117)}...` : task}`);
188
+ if (e.outcome !== "ok" && e.detail)
189
+ io.out(` ${paint(io, e.detail.replace(/\s+/g, " ").slice(0, 160), "2")}`);
190
+ }
191
+ return 0;
192
+ }
193
+ export const command = {
194
+ summary: "service accounts registry and the delegation bridge log",
195
+ usage: USAGE,
196
+ async run(args, io) {
197
+ const [sub, ...rest] = args;
198
+ switch (sub) {
199
+ case undefined:
200
+ case "list":
201
+ return list(io);
202
+ case "add":
203
+ return add(rest, io);
204
+ case "remove":
205
+ case "rm":
206
+ return remove(rest, io);
207
+ case "prefer":
208
+ return prefer(rest, io);
209
+ case "log":
210
+ return log(rest, io);
211
+ default:
212
+ return fail(`unknown accounts command "${sub}"\n${USAGE}`);
213
+ }
214
+ },
215
+ };
216
+ //# sourceMappingURL=accounts.js.map
@@ -0,0 +1,44 @@
1
+ import { adapter, isAgentId } from "../../agents/index.js";
2
+ import { loadConfig } from "../../core/config.js";
3
+ import { resolveProfile } from "../../core/resolve.js";
4
+ import { fail } from "../io.js";
5
+ import { execCommand, execLauncher, launcherPath } from "../launch.js";
6
+ export const command = {
7
+ summary: "open the agent with the account assigned to this folder (turno-auto)",
8
+ usage: [
9
+ "Usage: turno auto [--agent claude|codex|copilot|cursor] [agent args]",
10
+ "",
11
+ "Resolves the profile of that agent (Claude Code by default) for the current folder (a",
12
+ "git worktree counts as its main repository), switches to the fallback when one is set and",
13
+ "the assigned profile is exhausted, and execs its launcher. Without a profile, runs the",
14
+ "agent's own command (claude, codex, copilot, cursor-agent).",
15
+ ].join("\n"),
16
+ async run(argv, io) {
17
+ let agent = "claude";
18
+ let args = argv;
19
+ if (argv[0] === "--agent" || argv[0]?.startsWith("--agent=")) {
20
+ const v = argv[0] === "--agent" ? argv[1] : argv[0].slice("--agent=".length);
21
+ if (!isAgentId(v))
22
+ return fail("--agent must be claude, codex, copilot or cursor");
23
+ agent = v;
24
+ args = argv.slice(argv[0] === "--agent" ? 2 : 1);
25
+ }
26
+ let config;
27
+ try {
28
+ config = loadConfig(io.env);
29
+ }
30
+ catch (err) {
31
+ // A broken config must not stop Claude Code from starting.
32
+ io.err(`turno: ${err.message}; running plain ${adapter(agent).command}`);
33
+ }
34
+ const r = config ? resolveProfile(process.cwd(), config, io.env, undefined, agent) : undefined;
35
+ const launcher = r?.chosen ? launcherPath(r.chosen, io.env, agent) : undefined;
36
+ if (!r || !launcher)
37
+ return execCommand(adapter(agent).command, args, io.env);
38
+ if (process.stderr.isTTY && args[0] !== "--version" && args[0] !== "-v") {
39
+ io.err(r.note ? `turno: ${r.assigned} ${r.note} → using ${r.chosen} (${r.reason})` : `turno: account ${r.chosen} (${r.reason})`);
40
+ }
41
+ return execLauncher(launcher, args, io.env);
42
+ },
43
+ };
44
+ //# sourceMappingURL=auto.js.map
@@ -0,0 +1,18 @@
1
+ import { isValidProfileName } from "../../core/config.js";
2
+ import { clearExhausted } from "../../core/exhausted.js";
3
+ import { fail } from "../io.js";
4
+ export const command = {
5
+ summary: "clear a profile's exhausted mark",
6
+ usage: "Usage: turno available <profile>",
7
+ async run(args, io) {
8
+ const name = args[0];
9
+ if (!name)
10
+ fail("usage: turno available <profile>");
11
+ if (!isValidProfileName(name))
12
+ fail(`invalid profile name: '${name}'`);
13
+ clearExhausted(name, io.env);
14
+ io.out(`${name} available again`);
15
+ return 0;
16
+ },
17
+ };
18
+ //# sourceMappingURL=available.js.map
@@ -0,0 +1,175 @@
1
+ import { paths, tildify } from "../../core/paths.js";
2
+ import { fail, paint } from "../io.js";
3
+ const USAGE = `Usage:
4
+ turno browser identities list browser identities and whether they are in use
5
+ turno browser add <id> create an identity and print its mcp.toml block
6
+ turno browser remove <id> delete an identity and its saved logins
7
+ turno browser login <id> [--url <url>] open the identity's Chrome to sign in by hand once
8
+ turno browser bench [--engine <name>]... [--url <url>]... [--no-detectors] [--json]
9
+ compare engines against bot detectors and your URLs
10
+
11
+ Identities are persistent Chrome profiles served by turno-browser-mcp (one session at a
12
+ time through mcpd). Ids use lowercase letters, digits, "-" and "_", for example "school".
13
+ Engines: patchright-chrome-headed, patchright-chrome-headless, playwright-stock, camoufox.`;
14
+ const NOT_INSTALLED = `the browser package (turno-browser) is not installed or not built.
15
+ Install it next to turno (it is an optional dependency) and run its build, then try again.`;
16
+ export async function loadBrowser() {
17
+ const spec = "turno-browser";
18
+ try {
19
+ return (await import(spec));
20
+ }
21
+ catch (err) {
22
+ const code = err.code;
23
+ if (code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED")
24
+ return undefined;
25
+ throw err;
26
+ }
27
+ }
28
+ function requireId(mod, id, sub) {
29
+ if (!id)
30
+ return fail(`browser ${sub} needs an identity id\n\n${USAGE}`);
31
+ try {
32
+ mod.assertIdentityId(id);
33
+ }
34
+ catch (err) {
35
+ return fail(err.message);
36
+ }
37
+ return id;
38
+ }
39
+ /** Values of a repeatable flag; "--flag a,b" and "--flag=a" both work. */
40
+ function takeList(args, flag) {
41
+ const values = [];
42
+ const rest = [];
43
+ for (let i = 0; i < args.length; i++) {
44
+ const a = args[i];
45
+ if (a === flag) {
46
+ const v = args[++i];
47
+ if (v === undefined)
48
+ return fail(`${flag} needs a value`);
49
+ values.push(v);
50
+ }
51
+ else if (a.startsWith(`${flag}=`)) {
52
+ values.push(a.slice(flag.length + 1));
53
+ }
54
+ else {
55
+ rest.push(a);
56
+ }
57
+ }
58
+ return { values, rest };
59
+ }
60
+ async function bench(mod, args, io) {
61
+ const engines = takeList(args, "--engine");
62
+ const urls = takeList(engines.rest, "--url");
63
+ const rest = urls.rest;
64
+ const json = rest.includes("--json");
65
+ const detectors = !rest.includes("--no-detectors");
66
+ const unknown = rest.filter((a) => a !== "--json" && a !== "--no-detectors");
67
+ if (unknown.length)
68
+ return fail(`unknown bench argument: ${unknown[0]}\n\n${USAGE}`);
69
+ const engineNames = engines.values.flatMap((v) => v.split(",")).map((v) => v.trim()).filter(Boolean);
70
+ for (const e of engineNames) {
71
+ if (!mod.ENGINES.includes(e))
72
+ return fail(`unknown engine "${e}" (known: ${mod.ENGINES.join(", ")})`);
73
+ }
74
+ for (const u of urls.values) {
75
+ if (!/^https?:\/\//.test(u))
76
+ return fail(`--url must start with http:// or https://: ${u}`);
77
+ }
78
+ if (!detectors && urls.values.length === 0)
79
+ return fail("--no-detectors needs at least one --url");
80
+ const report = await mod.runBench({
81
+ engines: engineNames,
82
+ urls: urls.values,
83
+ detectors,
84
+ env: io.env,
85
+ onProgress: (m) => io.err(paint(io, m, "2")),
86
+ });
87
+ if (json) {
88
+ io.out(JSON.stringify(report, null, 2));
89
+ }
90
+ else {
91
+ io.out(mod.formatBenchTable(report));
92
+ if (report.file)
93
+ io.out(`\nreport: ${tildify(report.file, io.env)}`);
94
+ }
95
+ return 0;
96
+ }
97
+ export const command = {
98
+ summary: "how automation-fingerprint test pages see each browser engine (identities live in turno identity)",
99
+ usage: USAGE,
100
+ subcommands: { bench: { flags: ["--engine", "--url", "--no-detectors", "--json"] } },
101
+ async run(args, io) {
102
+ const [sub, ...rest] = args;
103
+ if (!sub)
104
+ return fail(USAGE);
105
+ const mod = await loadBrowser();
106
+ if (!mod) {
107
+ io.err(`turno: ${NOT_INSTALLED}`);
108
+ return 1;
109
+ }
110
+ try {
111
+ return await dispatch(mod, sub, rest, io);
112
+ }
113
+ catch (err) {
114
+ if (err.name === "IdentityError")
115
+ return fail(err.message);
116
+ throw err;
117
+ }
118
+ },
119
+ };
120
+ export async function dispatch(mod, sub, rest, io) {
121
+ switch (sub) {
122
+ case "identities":
123
+ case "list": {
124
+ const list = mod.listIdentities(io.env);
125
+ if (!list.length) {
126
+ io.out("No browser identities yet. Create one with `turno browser add <id>`.");
127
+ return 0;
128
+ }
129
+ const width = Math.max(...list.map((i) => i.id.length));
130
+ for (const i of list) {
131
+ const state = i.inUse ? paint(io, "in use", "33") : paint(io, "free ", "32");
132
+ io.out(`${i.id.padEnd(width)} ${state} ${tildify(i.dir, io.env)}`);
133
+ }
134
+ return 0;
135
+ }
136
+ case "add": {
137
+ const id = requireId(mod, rest[0], "add");
138
+ const info = mod.addIdentity(id, io.env);
139
+ io.out(`identity "${id}" ready at ${tildify(info.dir, io.env)}`);
140
+ io.out(`\nAdd this to ${tildify(paths(io.env).mcpFile, io.env)}, then run \`turno mcp sync\`:\n`);
141
+ io.out(mod.manifestSnippet(id));
142
+ io.out(`Sign in to your sites once with \`turno browser login ${id}\`.`);
143
+ return 0;
144
+ }
145
+ case "remove":
146
+ case "rm": {
147
+ const id = requireId(mod, rest[0], "remove");
148
+ mod.removeIdentity(id, io.env);
149
+ io.out(`removed identity "${id}" and its saved browser data`);
150
+ io.out(`Remove its [server.browser-${id}] block from ${tildify(paths(io.env).mcpFile, io.env)} if you added one.`);
151
+ return 0;
152
+ }
153
+ case "login": {
154
+ const id = requireId(mod, rest[0], "login");
155
+ const { values, rest: extra } = takeList(rest.slice(1), "--url");
156
+ if (extra.length)
157
+ return fail(`unknown login argument: ${extra[0]}`);
158
+ if (mod.isInUse(id, io.env)) {
159
+ 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.`);
160
+ }
161
+ io.out(`Opening Chrome for identity "${id}". Sign in to your sites, then close the window to save the session.`);
162
+ const options = { env: io.env };
163
+ if (values[0])
164
+ options.url = values[0];
165
+ await mod.loginIdentity(id, options);
166
+ io.out(`saved. Sessions using browser-${id} now start signed in.`);
167
+ return 0;
168
+ }
169
+ case "bench":
170
+ return bench(mod, rest, io);
171
+ default:
172
+ return fail(`unknown browser command "${sub}"\n\n${USAGE}`);
173
+ }
174
+ }
175
+ //# sourceMappingURL=browser.js.map