turno-cli 0.1.0 → 0.2.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 (105) hide show
  1. package/CHANGELOG.md +293 -0
  2. package/README.md +143 -75
  3. package/dist/accounts/audit.js +137 -7
  4. package/dist/accounts/builtin.js +68 -21
  5. package/dist/accounts/delegate.js +176 -35
  6. package/dist/accounts/policy.js +77 -0
  7. package/dist/accounts/registry.js +37 -21
  8. package/dist/agents/adapter.js +7 -0
  9. package/dist/agents/claude.js +195 -0
  10. package/dist/agents/codex.js +98 -0
  11. package/dist/agents/copilot.js +39 -0
  12. package/dist/agents/cursor.js +41 -0
  13. package/dist/agents/index.js +26 -86
  14. package/dist/agents/snippets.js +7 -4
  15. package/dist/cli/args.js +19 -4
  16. package/dist/cli/commands/accounts.js +96 -51
  17. package/dist/cli/commands/auto.js +82 -32
  18. package/dist/cli/commands/browser.js +216 -135
  19. package/dist/cli/commands/complete.js +2 -1
  20. package/dist/cli/commands/completion.js +4 -2
  21. package/dist/cli/commands/config.js +103 -18
  22. package/dist/cli/commands/demo.js +292 -0
  23. package/dist/cli/commands/doctor.js +387 -119
  24. package/dist/cli/commands/handoff.js +33 -22
  25. package/dist/cli/commands/identity.js +101 -50
  26. package/dist/cli/commands/init.js +616 -0
  27. package/dist/cli/commands/limit.js +25 -13
  28. package/dist/cli/commands/mcp-oauth.js +194 -0
  29. package/dist/cli/commands/mcp-observe.js +434 -0
  30. package/dist/cli/commands/mcp.js +653 -185
  31. package/dist/cli/commands/mcpd.js +323 -75
  32. package/dist/cli/commands/migrate.js +6 -4
  33. package/dist/cli/commands/open.js +92 -27
  34. package/dist/cli/commands/profile.js +205 -69
  35. package/dist/cli/commands/resolve.js +6 -2
  36. package/dist/cli/commands/run.js +15 -5
  37. package/dist/cli/commands/secret.js +61 -42
  38. package/dist/cli/commands/session.js +2 -2
  39. package/dist/cli/commands/sessions.js +42 -12
  40. package/dist/cli/commands/setup.js +136 -158
  41. package/dist/cli/commands/status.js +172 -41
  42. package/dist/cli/commands/statusline.js +305 -113
  43. package/dist/cli/commands/ui.js +64 -66
  44. package/dist/cli/commands/undo.js +161 -18
  45. package/dist/cli/commands/uninstall.js +462 -0
  46. package/dist/cli/commands/upgrade.js +75 -19
  47. package/dist/cli/commands/usage.js +117 -44
  48. package/dist/cli/commands/version.js +7 -5
  49. package/dist/cli/commands/which.js +7 -24
  50. package/dist/cli/compile-cache.js +32 -0
  51. package/dist/cli/group.js +10 -10
  52. package/dist/cli/help.js +57 -0
  53. package/dist/cli/highlight.js +236 -0
  54. package/dist/cli/io.js +170 -1
  55. package/dist/cli/launch.js +21 -37
  56. package/dist/cli/launchers.js +145 -94
  57. package/dist/cli/main.js +163 -27
  58. package/dist/cli/picker.js +447 -0
  59. package/dist/cli/registry.js +42 -5
  60. package/dist/cli/security.js +539 -0
  61. package/dist/cli/style.js +281 -0
  62. package/dist/core/config.js +145 -23
  63. package/dist/core/exhausted.js +6 -8
  64. package/dist/core/fsutil.js +47 -0
  65. package/dist/core/journal.js +281 -11
  66. package/dist/core/manifest.js +126 -6
  67. package/dist/core/paths.js +114 -7
  68. package/dist/core/profiles.js +139 -9
  69. package/dist/core/resolve.js +129 -23
  70. package/dist/core/secrets.js +215 -20
  71. package/dist/core/sessions.js +13 -20
  72. package/dist/core/update.js +18 -8
  73. package/dist/core/version.js +6 -0
  74. package/dist/demo/server.js +34 -0
  75. package/dist/mcpd/cache.js +18 -4
  76. package/dist/mcpd/calllog.js +253 -0
  77. package/dist/mcpd/client-names.js +51 -0
  78. package/dist/mcpd/connectors.js +148 -17
  79. package/dist/mcpd/daemon.js +452 -116
  80. package/dist/mcpd/folder-sets.js +39 -0
  81. package/dist/mcpd/gateway.js +441 -47
  82. package/dist/mcpd/health.js +269 -0
  83. package/dist/mcpd/importer.js +356 -36
  84. package/dist/mcpd/instances.js +425 -65
  85. package/dist/mcpd/jsonrpc.js +8 -0
  86. package/dist/mcpd/launchd.js +65 -48
  87. package/dist/mcpd/modern.js +648 -0
  88. package/dist/mcpd/oauth.js +791 -0
  89. package/dist/mcpd/peerpid.js +122 -6
  90. package/dist/mcpd/pressure.js +85 -0
  91. package/dist/mcpd/rss.js +151 -0
  92. package/dist/mcpd/service.js +167 -0
  93. package/dist/mcpd/state.js +183 -0
  94. package/dist/mcpd/sync.js +55 -80
  95. package/dist/mcpd/systemd.js +80 -0
  96. package/dist/mcpd/tokens.js +89 -0
  97. package/dist/mcpd/upstream.js +154 -44
  98. package/dist/statusline/cost.js +154 -44
  99. package/dist/statusline/input.js +66 -0
  100. package/dist/statusline/render.js +9 -3
  101. package/dist/ui/fonts.js +8 -3
  102. package/dist/ui/settings.js +27 -15
  103. package/npm-shrinkwrap.json +1093 -0
  104. package/package.json +9 -9
  105. package/dist/cli/commands/available.js +0 -18
package/dist/cli/args.js CHANGED
@@ -1,11 +1,19 @@
1
1
  import { parseArgs } from "node:util";
2
- import { fail } from "./io.js";
2
+ import { highlightJson } from "./highlight.js";
3
+ import { colors, fail } from "./io.js";
3
4
  /** Flags shared by every command, so the same words mean the same thing everywhere. */
4
5
  export const JSON_FLAG = { json: { type: "boolean" } };
5
6
  export const DRY_RUN = { "dry-run": { type: "boolean" } };
6
7
  export const FORCE = { force: { type: "boolean" } };
7
8
  export const TAIL = { tail: { type: "string", short: "n" } };
8
9
  export const WATCH = { watch: { type: "boolean" } };
10
+ /**
11
+ * Completion flags of a spec (`--name` for each long flag), so the parser and the shell
12
+ * completion never disagree. Use it as `flags: flagsOf(SPEC)` next to `parseFlags(args, SPEC)`.
13
+ */
14
+ export function flagsOf(...specs) {
15
+ return specs.flatMap((s) => Object.keys(s)).map((k) => `--${k}`);
16
+ }
9
17
  /**
10
18
  * Parse `args` against `spec` (long flags, `--flag=value`, short aliases). Unknown flags and
11
19
  * positionals beyond `max` are usage errors with a plain message.
@@ -40,8 +48,15 @@ export function count(p, name, fallback) {
40
48
  fail(`--${name} must be a positive integer`);
41
49
  return n;
42
50
  }
43
- /** Print a value as indented JSON. */
44
- export function printJson(out, value) {
45
- out(JSON.stringify(value, null, 2));
51
+ /**
52
+ * Print a value as indented JSON, colored on a terminal without NO_COLOR (never in a pipe,
53
+ * even with FORCE_COLOR, since programs read it).
54
+ * Given only an output function it prints plain JSON.
55
+ */
56
+ export function printJson(io, value) {
57
+ const text = JSON.stringify(value, null, 2);
58
+ const out = typeof io === "function" ? io : io.out;
59
+ // Only on a real terminal: --json is read by programs, so FORCE_COLOR never colors a pipe here.
60
+ out(text !== undefined && typeof io !== "function" && io.isTty && colors(io) ? highlightJson(text) : text);
46
61
  }
47
62
  //# sourceMappingURL=args.js.map
@@ -1,48 +1,65 @@
1
1
  import { resolve } from "node:path";
2
- import { readAudit } from "../../accounts/audit.js";
2
+ import { readAudit, verifyAudit } from "../../accounts/audit.js";
3
3
  import { launcherExists } from "../../accounts/delegate.js";
4
+ import { effectivePolicy } from "../../accounts/policy.js";
4
5
  import { isValidService, loadRegistry, makeAccount, parseAccountId, saveRegistry } from "../../accounts/registry.js";
5
6
  import { Journal } from "../../core/journal.js";
6
7
  import { expandHome, paths, tildify } from "../../core/paths.js";
8
+ import { DRY_RUN, JSON_FLAG, bool, count, parseFlags, printJson, str } from "../args.js";
7
9
  import { fail, paint } from "../io.js";
8
10
  const USAGE = `Usage:
9
11
  turno accounts list accounts, owners and folder preferences
10
12
  turno accounts add <service:label> --profile <p> --tools <pattern>[,<pattern>]
13
+ [--read-tools <pattern>[,<pattern>]] [--confirm always|writes|never]
11
14
  [--service <s>] [--description <d>]
12
15
  turno accounts remove <service:label>
13
16
  turno accounts prefer <path> <service>=<account> (empty account removes the preference)
14
- turno accounts log [-n N] recent calls to the accounts bridge
17
+ turno accounts log [-n N] [--verify] [--json]
18
+ recent calls to the accounts bridge; --verify
19
+ checks the log's hash chain (exit 1 if broken)
15
20
 
16
21
  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;
22
+ the file (it is managed: comments in it are not preserved) and accept --dry-run.
23
+
24
+ A delegated read gets only --read-tools; an account without them has every call confirmed.
25
+ --confirm defaults to "always" for mail and messaging services and "writes" elsewhere.`;
26
+ /** Flags of each subcommand, shared with completion through flagsOf. */
27
+ const ADD_SPEC = {
28
+ profile: { type: "string" },
29
+ tools: { type: "string" },
30
+ "read-tools": { type: "string" },
31
+ confirm: { type: "string" },
32
+ service: { type: "string" },
33
+ description: { type: "string" },
34
+ ...DRY_RUN,
35
+ };
36
+ export const LOG_SPEC = { tail: { type: "string", short: "n" }, verify: { type: "boolean" }, ...JSON_FLAG };
37
+ /**
38
+ * `log --verify`: check the hash chain of audit.jsonl (ADR 0018). It shows accidents and naive
39
+ * edits (a changed, inserted, removed or reordered line), not a determined attacker who can
40
+ * rewrite the whole file, and it cannot see lines cut from the end.
41
+ */
42
+ function verifyLog(io, json) {
43
+ const v = verifyAudit(io.env);
44
+ const file = tildify(paths(io.env).auditLog, io.env);
45
+ if (json) {
46
+ printJson(io, { file, ...v, line: v.line ?? null, reason: v.reason ?? null });
47
+ return v.ok ? 0 : 1;
48
+ }
49
+ if (!v.ok) {
50
+ io.out(`${paint(io, "broken", "31")} ${file}: line ${v.line}: ${v.reason}`);
51
+ io.out("The audit log was changed after it was written, or two writers raced. Keep a copy before you edit it.");
52
+ return 1;
53
+ }
54
+ if (v.lines === 0)
55
+ io.out(`No delegations recorded yet (${file}).`);
56
+ else {
57
+ const legacy = v.legacy ? `; ${v.legacy} older line${v.legacy === 1 ? "" : "s"} predate the chain` : "";
58
+ io.out(`${paint(io, "ok", "32")} ${file}: ${v.lines} line${v.lines === 1 ? "" : "s"}, hash chain intact${legacy}`);
42
59
  }
43
- return { pos, flags };
60
+ return 0;
44
61
  }
45
- export function list(io) {
62
+ function list(io) {
46
63
  const reg = loadRegistry(io.env);
47
64
  const accounts = Object.values(reg.accounts).sort((a, b) => a.id.localeCompare(b.id));
48
65
  if (!accounts.length) {
@@ -54,6 +71,7 @@ export function list(io) {
54
71
  for (const a of accounts) {
55
72
  const missing = launcherExists(a.profile, io.env) ? "" : paint(io, " (no launcher)", "33");
56
73
  io.out(`${paint(io, a.id.padEnd(width), "1")} ${a.profile.padEnd(12)} ${a.tools.join(", ")}${missing}`);
74
+ io.out(`${" ".repeat(width)} ${paint(io, policyLine(a), "2")}`);
57
75
  if (a.description)
58
76
  io.out(`${" ".repeat(width)} ${paint(io, a.description, "2")}`);
59
77
  }
@@ -66,27 +84,44 @@ export function list(io) {
66
84
  }
67
85
  return 0;
68
86
  }
87
+ /** How the bridge treats an account: its confirm policy and what a read may call. */
88
+ export function policyLine(a) {
89
+ const policy = `confirm ${effectivePolicy(a)}${a.confirm ? "" : " (default)"}`;
90
+ if (a.readTools)
91
+ return `${policy}; reads: ${a.readTools.join(", ")}`;
92
+ return `${policy}; no read_tools: ${effectivePolicy(a) === "never" ? "reads get every tool" : "every call is confirmed"}`;
93
+ }
94
+ const list_ = (v) => v
95
+ ?.split(",")
96
+ .map((t) => t.trim())
97
+ .filter(Boolean);
69
98
  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;
99
+ const p = parseFlags(rawArgs, ADD_SPEC);
100
+ const dry = bool(p, "dry-run");
101
+ const [id, extra] = p.positionals;
75
102
  if (!id || extra !== undefined)
76
- fail("usage: turno accounts add <service:label> --profile <p> --tools <pattern>[,<pattern>]");
103
+ fail("usage: turno identity add <service:label> --profile <p> --tools <pattern>[,<pattern>] [--read-tools <pattern>[,...]] [--confirm always|writes|never]");
104
+ const journal = new Journal(io.env, `accounts add ${id}`, dry);
105
+ const flags = {
106
+ profile: str(p, "profile"),
107
+ tools: str(p, "tools"),
108
+ readTools: str(p, "read-tools"),
109
+ confirm: str(p, "confirm"),
110
+ service: str(p, "service"),
111
+ description: str(p, "description"),
112
+ };
77
113
  if (!flags.profile)
78
114
  fail("--profile is required");
79
115
  if (!flags.tools)
80
116
  fail("--tools is required");
81
- const tools = flags.tools
82
- .split(",")
83
- .map((t) => t.trim())
84
- .filter(Boolean);
117
+ const tools = list_(flags.tools);
85
118
  const reg = loadRegistry(io.env);
86
119
  const existed = Boolean(reg.accounts[id]);
87
120
  reg.accounts[id] = makeAccount(id, {
88
121
  profile: flags.profile,
89
122
  tools,
123
+ ...(flags.readTools !== undefined ? { readTools: list_(flags.readTools) } : {}),
124
+ ...(flags.confirm !== undefined ? { confirm: flags.confirm } : {}),
90
125
  ...(flags.service ? { service: flags.service } : {}),
91
126
  ...(flags.description ? { description: flags.description } : {}),
92
127
  });
@@ -99,12 +134,13 @@ export function add(rawArgs, io) {
99
134
  return 0;
100
135
  }
101
136
  export function remove(rawArgs, io) {
102
- const dry = rawArgs.includes("--dry-run");
103
- const args = rawArgs.filter((a) => a !== "--dry-run");
137
+ const p = parseFlags(rawArgs, DRY_RUN);
138
+ const dry = bool(p, "dry-run");
139
+ const args = p.positionals;
104
140
  const journal = new Journal(io.env, `accounts remove ${args.join(" ")}`, dry);
105
141
  const [id, extra] = args;
106
142
  if (!id || extra !== undefined)
107
- fail("usage: turno accounts remove <service:label>");
143
+ fail("usage: turno identity remove <service:label>");
108
144
  const reg = loadRegistry(io.env);
109
145
  if (!reg.accounts[id])
110
146
  fail(`unknown account "${id}"`);
@@ -125,12 +161,13 @@ function dropPreferences(reg, id) {
125
161
  reg.prefer = reg.prefer.filter((r) => Object.keys(r.accounts).length > 0);
126
162
  }
127
163
  export function prefer(rawArgs, io) {
128
- const dry = rawArgs.includes("--dry-run");
129
- const args = rawArgs.filter((a) => a !== "--dry-run");
164
+ const p = parseFlags(rawArgs, DRY_RUN);
165
+ const dry = bool(p, "dry-run");
166
+ const args = p.positionals;
130
167
  const journal = new Journal(io.env, `accounts prefer ${args.join(" ")}`, dry);
131
168
  const [rawPath, pair, extra] = args;
132
169
  if (!rawPath || !pair || extra !== undefined)
133
- fail("usage: turno accounts prefer <path> <service>=<account>");
170
+ fail("usage: turno identity prefer <path> <service>=<account>");
134
171
  const eq = pair.indexOf("=");
135
172
  if (eq <= 0)
136
173
  fail("expected <service>=<account>, like linear=linear:work");
@@ -166,13 +203,15 @@ export function prefer(rawArgs, io) {
166
203
  return 0;
167
204
  }
168
205
  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");
206
+ const p = parseFlags(args, LOG_SPEC, 0);
207
+ if (bool(p, "verify"))
208
+ return verifyLog(io, bool(p, "json"));
209
+ const n = count(p, "tail", 20);
175
210
  const entries = readAudit(n, io.env);
211
+ if (bool(p, "json")) {
212
+ printJson(io, entries);
213
+ return 0;
214
+ }
176
215
  if (!entries.length) {
177
216
  io.out("No delegations recorded yet.");
178
217
  return 0;
@@ -185,6 +224,12 @@ export function log(args, io) {
185
224
  const task = e.task.replace(/\s+/g, " ");
186
225
  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
226
  io.out(` ${task.length > 120 ? `${task.slice(0, 117)}...` : task}`);
227
+ if (e.decision) {
228
+ const d = e.decision;
229
+ const asked = d.asked ? (d.confirmed ? "confirmed" : "not confirmed") : "not asked";
230
+ const blocked = d.denied?.length ? `; blocked: ${d.denied.join(", ")}` : "";
231
+ io.out(` ${paint(io, `${d.toolset === "read" ? "read tools" : "all tools"}, ${asked}${d.mcp ? `, ${d.mcp} MCP` : ""}${blocked}`, "2")}`);
232
+ }
188
233
  if (e.outcome !== "ok" && e.detail)
189
234
  io.out(` ${paint(io, e.detail.replace(/\s+/g, " ").slice(0, 160), "2")}`);
190
235
  }
@@ -1,44 +1,94 @@
1
- import { adapter, isAgentId } from "../../agents/index.js";
1
+ import { join } from "node:path";
2
+ import { AGENT_IDS, DEFAULT_AGENT, adapter, agentHub, isAgentId } from "../../agents/index.js";
2
3
  import { loadConfig } from "../../core/config.js";
4
+ import { paths, tildify } from "../../core/paths.js";
5
+ import { listProfiles } from "../../core/profiles.js";
3
6
  import { resolveProfile } from "../../core/resolve.js";
4
- import { fail } from "../io.js";
5
- import { execCommand, execLauncher, launcherPath } from "../launch.js";
7
+ import { CliError, fail } from "../io.js";
8
+ import { execLauncher, findOnPath, launcherPath } from "../launch.js";
9
+ import { launcherName } from "../launchers.js";
10
+ /**
11
+ * Decide what `turno auto` runs in `cwd`. It never falls back to another account in silence:
12
+ * a chosen profile without its launcher, a rule naming a missing profile, or a broken
13
+ * config.toml are errors (TURNO_ALLOW_PLAIN=1 runs the plain agent despite a broken config).
14
+ */
15
+ export function planAuto(argv, io, cwd = process.cwd()) {
16
+ let agent = DEFAULT_AGENT;
17
+ let args = argv;
18
+ if (argv[0] === "--agent" || argv[0]?.startsWith("--agent=")) {
19
+ const v = argv[0] === "--agent" ? argv[1] : argv[0].slice("--agent=".length);
20
+ if (!isAgentId(v))
21
+ return fail(`--agent must be ${AGENT_IDS.slice(0, -1).join(", ")} or ${AGENT_IDS.at(-1)}`);
22
+ agent = v;
23
+ args = argv.slice(argv[0] === "--agent" ? 2 : 1);
24
+ }
25
+ const env = io.env;
26
+ const a = adapter(agent);
27
+ const hub = tildify(agentHub(agent, env), env);
28
+ const plain = () => {
29
+ const file = findOnPath(a.command, env);
30
+ if (!file)
31
+ throw new CliError(`${a.command} is not installed (${a.install})`, 127);
32
+ return file;
33
+ };
34
+ let config;
35
+ try {
36
+ config = loadConfig(env);
37
+ }
38
+ catch (err) {
39
+ const msg = err.message;
40
+ if (env.TURNO_ALLOW_PLAIN === "1")
41
+ return { file: plain(), args, notice: `turno: ${msg}; running plain ${a.command} (TURNO_ALLOW_PLAIN=1)`, always: true };
42
+ throw new CliError(`${msg}\nturno auto does not guess an account while config.toml is broken. Fix it (turno config edit), or run plain ${a.command} once with TURNO_ALLOW_PLAIN=1.`);
43
+ }
44
+ const where = tildify(cwd, env);
45
+ const r = resolveProfile(cwd, config, env, undefined, agent);
46
+ if (r.chosen) {
47
+ const launcher = launcherPath(r.chosen, env, agent);
48
+ if (!launcher) {
49
+ if (!listProfiles(config, env).includes(r.chosen)) {
50
+ const add = `turno profile add ${r.chosen}${agent === DEFAULT_AGENT ? "" : ` --agent ${agent}`}`;
51
+ throw new CliError(`${where} uses the ${r.chosen} profile (${r.reason}), but there is no such profile. Run: ${add}, or change the rule (turno profile which)`);
52
+ }
53
+ const missing = tildify(join(paths(env).bin, launcherName(r.chosen, agent)), env);
54
+ throw new CliError(`${where} uses the ${r.chosen} profile, but its launcher ${missing} is missing. Run: turno profile repair ${r.chosen}`);
55
+ }
56
+ return {
57
+ file: launcher,
58
+ args,
59
+ notice: r.note ? `turno: ${r.assigned} ${r.note} → using ${r.chosen} (${r.reason})` : `turno: account ${r.chosen} (${r.reason})`,
60
+ };
61
+ }
62
+ if (config.system === "") {
63
+ throw new CliError(`${where} has no rule and no default profile, and system = "" says there is no default account. Assign one: turno profile assign ${where} <profile>`);
64
+ }
65
+ if (agent !== DEFAULT_AGENT && listProfiles(config, env, agent).length === 0) {
66
+ return { file: plain(), args, notice: `turno: no ${a.label} profile yet, so this runs plain ${a.command} with ${hub} (turno profile add <name> --agent ${agent})`, always: true };
67
+ }
68
+ return { file: plain(), args, notice: `turno: no rule or default for ${where}; running plain ${a.command} with ${hub}` };
69
+ }
6
70
  export const command = {
7
71
  summary: "open the agent with the account assigned to this folder (turno-auto)",
8
72
  usage: [
9
73
  "Usage: turno auto [--agent claude|codex|copilot|cursor] [agent args]",
10
74
  "",
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).",
75
+ "Resolves the profile of that agent (Claude Code by default) for the current",
76
+ "folder (a git worktree counts as its main repository), switches to the fallback",
77
+ "when one is set and the assigned profile is exhausted, and execs its launcher.",
78
+ "Without a rule or a default, runs the agent's own command (claude, codex,",
79
+ "copilot, cursor-agent).",
80
+ "",
81
+ "It never switches accounts in silence: when the chosen profile or its launcher",
82
+ "is missing, or config.toml does not parse, it exits 1 and says how to fix it.",
83
+ "TURNO_ALLOW_PLAIN=1 runs the plain agent despite a broken config.toml;",
84
+ 'system = "" in config.toml makes folders without a rule an error too.',
15
85
  ].join("\n"),
16
86
  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);
87
+ const plan = planAuto(argv, io);
88
+ const quiet = plan.args[0] === "--version" || plan.args[0] === "-v";
89
+ if (plan.notice && (plan.always || (process.stderr.isTTY && !quiet)))
90
+ io.err(plan.notice);
91
+ return execLauncher(plan.file, plan.args, io.env);
42
92
  },
43
93
  };
44
94
  //# sourceMappingURL=auto.js.map