turno-cli 0.0.0-stage → 0.1.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.
Files changed (83) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +18 -0
  4. package/README.md +335 -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 +109 -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,60 @@
1
+ import { spawn } from "node:child_process";
2
+ import { existsSync, mkdirSync } from "node:fs";
3
+ import { loadConfig } from "../../core/config.js";
4
+ import { profileFromConfigDir } from "../../core/profiles.js";
5
+ import { fail } from "../io.js";
6
+ import { checkName } from "./setup.js";
7
+ /** claude.ai and claude.com links (and their subdomains) open with the profile's account. */
8
+ export function isClaudeUrl(url) {
9
+ return /^https:\/\/([A-Za-z0-9-]+\.)*claude\.(ai|com)\//.test(url);
10
+ }
11
+ function chromeApp(env) {
12
+ return env.TURNO_CHROME_APP || "/Applications/Google Chrome.app";
13
+ }
14
+ /** The `open` invocation for a link: argv for /usr/bin/open. */
15
+ export function openArgs(profile, url, env = process.env) {
16
+ if (!isClaudeUrl(url))
17
+ return [url];
18
+ const config = loadConfig(env);
19
+ const name = profile ?? profileFromConfigDir(env.CLAUDE_CONFIG_DIR, config, env) ?? config.system;
20
+ if (!name)
21
+ return [url];
22
+ checkName(name);
23
+ if (config.profiles[name]?.browser === "default")
24
+ return [url];
25
+ if (!existsSync(chromeApp(env)))
26
+ return [url];
27
+ mkdirSync(config.open.chromeDir, { recursive: true });
28
+ return ["-na", "Google Chrome", "--args", `--user-data-dir=${config.open.chromeDir}`, `--profile-directory=${name}`, url];
29
+ }
30
+ export const command = {
31
+ summary: "open a claude.ai link with an account (default: the session's)",
32
+ usage: [
33
+ "Usage: turno open [profile] <url>",
34
+ "",
35
+ "claude.ai and claude.com links open in the profile's isolated Google Chrome profile,",
36
+ 'or in the default browser when profiles.<name>.browser = "default". Other links',
37
+ "always open in the default browser. Claude Code calls this through $BROWSER.",
38
+ ].join("\n"),
39
+ async run(args, io) {
40
+ let profile;
41
+ let rest = args;
42
+ if (rest.length >= 2) {
43
+ profile = rest[0];
44
+ rest = rest.slice(1);
45
+ }
46
+ const url = rest[0];
47
+ if (!url)
48
+ fail("usage: turno open [profile] <url>");
49
+ const argv = openArgs(profile, url, io.env);
50
+ return new Promise((resolve) => {
51
+ const child = spawn("open", argv, { stdio: "inherit", env: io.env });
52
+ child.on("error", (err) => {
53
+ io.err(`turno: open: ${err.message}`);
54
+ resolve(1);
55
+ });
56
+ child.on("exit", (code) => resolve(code ?? 1));
57
+ });
58
+ },
59
+ };
60
+ //# sourceMappingURL=open.js.map
@@ -0,0 +1,259 @@
1
+ import { existsSync, statSync } from "node:fs";
2
+ import { resolve as resolvePath } from "node:path";
3
+ import { adapter, agentProfileDir, isAgentId, AGENT_IDS } from "../../agents/index.js";
4
+ import { editConfig } from "../../core/config-edit.js";
5
+ import { loadConfig } from "../../core/config.js";
6
+ import { exhaustedUntil } from "../../core/exhausted.js";
7
+ import { Journal } from "../../core/journal.js";
8
+ import { expandHome, paths, tildify } from "../../core/paths.js";
9
+ import { agentOf, listProfiles } from "../../core/profiles.js";
10
+ import { resolveProfile } from "../../core/resolve.js";
11
+ import { addArrayTable, ensureTable, removeArrayTables, removeTable, setValue } from "../../core/toml-edit.js";
12
+ import { NAMED_COLORS } from "../../statusline/render.js";
13
+ import { DRY_RUN, JSON_FLAG, bool, parseFlags, printJson, str } from "../args.js";
14
+ import { group } from "../group.js";
15
+ import { fail } from "../io.js";
16
+ import { launcherPath } from "../launch.js";
17
+ import { isGenerated, launcherName } from "../launchers.js";
18
+ import { checkName, setupProfiles } from "./setup.js";
19
+ import { authStatus } from "./usage.js";
20
+ /** A named color, or a 256-color code. */
21
+ export function parseColor(v) {
22
+ if (/^\d+$/.test(v)) {
23
+ const n = Number(v);
24
+ if (n > 255)
25
+ fail(`--color ${v}: a 256-color code goes from 0 to 255`);
26
+ return n;
27
+ }
28
+ if (NAMED_COLORS[v.toLowerCase()] === undefined)
29
+ fail(`--color ${v}: use a number (0-255) or one of ${Object.keys(NAMED_COLORS).join(", ")}`);
30
+ return v.toLowerCase();
31
+ }
32
+ export async function profilesData(env, config, withAccounts = true) {
33
+ const names = listProfiles(config, env);
34
+ // Account details come from `claude auth status`; other agents show whether they are set up.
35
+ const auth = withAccounts ? await Promise.all(names.map((n) => (agentOf(n, config) === "claude" ? authStatus(n, env) : undefined))) : [];
36
+ return names.map((name, i) => {
37
+ const s = auth[i];
38
+ const agent = agentOf(name, config);
39
+ const dir = agentProfileDir(name, agent, env);
40
+ return {
41
+ name,
42
+ agent,
43
+ dir: tildify(dir, env),
44
+ setUp: existsSync(dir) && Boolean(launcherPath(name, env, agent)),
45
+ ...(withAccounts ? { email: s?.loggedIn ? (s.email ?? null) : null, plan: s?.loggedIn ? (s.subscriptionType ?? null) : null } : {}),
46
+ color: config.profiles[name]?.color ?? null,
47
+ browser: config.profiles[name]?.browser ?? "chrome",
48
+ roles: [config.system === name && "system", config.default === name && "default", config.fallback === name && "fallback"].filter(Boolean),
49
+ projects: config.projects.filter((r) => r.profile === name).length,
50
+ exhaustedUntil: exhaustedUntil(name, env) ?? null,
51
+ };
52
+ });
53
+ }
54
+ async function list(args, io) {
55
+ const p = parseFlags(args, JSON_FLAG, 0);
56
+ const config = loadConfig(io.env);
57
+ const rows = await profilesData(io.env, config);
58
+ if (bool(p, "json")) {
59
+ printJson(io.out, rows);
60
+ return 0;
61
+ }
62
+ if (!rows.length) {
63
+ io.out("No profiles yet. Create one with: turno profile add <name>");
64
+ return 0;
65
+ }
66
+ const w = Math.max(...rows.map((r) => r.name.length));
67
+ for (const r of rows) {
68
+ const who = r.setUp
69
+ ? r.agent !== "claude"
70
+ ? `${adapter(r.agent).label} (${launcherName(r.name, r.agent)})`
71
+ : r.email
72
+ ? `${r.email}${r.plan ? ` · ${r.plan}` : ""}`
73
+ : "not logged in"
74
+ : `not set up (turno profile repair ${r.name})`;
75
+ const extra = [r.roles.join(", "), r.projects ? `${r.projects} projects` : "", r.exhaustedUntil ? "exhausted" : ""].filter(Boolean).join(" · ");
76
+ io.out(`${r.name.padEnd(w)} ${who}${extra ? ` (${extra})` : ""}`);
77
+ }
78
+ return 0;
79
+ }
80
+ async function add(args, io) {
81
+ const p = parseFlags(args, { color: { type: "string" }, browser: { type: "string" }, agent: { type: "string" }, ...DRY_RUN }, 1);
82
+ const name = p.positionals[0];
83
+ if (!name)
84
+ return fail("usage: turno profile add <name> [--agent claude|codex|copilot|cursor] [--color <c>] [--browser chrome|default]");
85
+ checkName(name);
86
+ const agent = str(p, "agent") ?? "claude";
87
+ if (!isAgentId(agent))
88
+ fail(`--agent must be one of ${AGENT_IDS.join(", ")}`);
89
+ const color = str(p, "color");
90
+ const browser = str(p, "browser");
91
+ if (browser && browser !== "chrome" && browser !== "default")
92
+ fail("--browser must be chrome or default");
93
+ const dry = bool(p, "dry-run");
94
+ const journal = new Journal(io.env, `profile add ${name}`, dry);
95
+ const table = `profiles.${name}`;
96
+ const { changed } = editConfig(io.env, journal, (t) => {
97
+ let text = ensureTable(t, table);
98
+ if (agent !== "claude")
99
+ text = setValue(text, table, "agent", agent);
100
+ if (color)
101
+ text = setValue(text, table, "color", parseColor(color));
102
+ if (browser)
103
+ text = setValue(text, table, "browser", browser);
104
+ return text;
105
+ });
106
+ io.out(`${changed ? "+" : "="} [${table}] in ${tildify(paths(io.env).configFile, io.env)}${dry ? " (dry run)" : ""}`);
107
+ if (dry) {
108
+ io.out(`(dry run) would set up ${tildify(agentProfileDir(name, agent, io.env), io.env)} and the ${launcherName(name, agent)} command`);
109
+ return 0;
110
+ }
111
+ setupProfiles([name], io);
112
+ io.out("");
113
+ const login = {
114
+ claude: `run claude-${name} and sign in with /login`,
115
+ codex: `run codex-${name} login`,
116
+ copilot: `run copilot-${name} and sign in with /login`,
117
+ cursor: `run cursor-agent-${name} login`,
118
+ };
119
+ io.out(`Next: ${login[agent]}. turno profile list shows the profile.`);
120
+ const hint = journal.hint();
121
+ if (hint)
122
+ io.out(hint);
123
+ return 0;
124
+ }
125
+ async function repair(args, io) {
126
+ const p = parseFlags(args, {});
127
+ const names = p.positionals.length ? p.positionals : listProfiles(loadConfig(io.env), io.env);
128
+ if (!names.length)
129
+ return fail("no profiles to repair (turno profile add <name>)");
130
+ setupProfiles(names, io);
131
+ return 0;
132
+ }
133
+ async function remove(args, io) {
134
+ const p = parseFlags(args, DRY_RUN, 1);
135
+ const name = p.positionals[0];
136
+ if (!name)
137
+ return fail("usage: turno profile remove <name>");
138
+ const config = loadConfig(io.env);
139
+ if (!listProfiles(config, io.env).includes(name))
140
+ fail(`no profile '${name}'`);
141
+ for (const role of ["system", "default", "fallback"]) {
142
+ if (config[role] === name)
143
+ fail(`${name} is the ${role} profile; point ${role} elsewhere first (turno config set ${role} <profile>)`);
144
+ }
145
+ const dry = bool(p, "dry-run");
146
+ const journal = new Journal(io.env, `profile remove ${name}`, dry);
147
+ let rules = 0;
148
+ editConfig(io.env, journal, (t) => {
149
+ const r = removeArrayTables(removeTable(t, `profiles.${name}`), "projects", (e) => e.profile === name);
150
+ rules = r.removed;
151
+ return r.text;
152
+ });
153
+ const agent = agentOf(name, config);
154
+ const launcher = launcherPath(name, io.env, agent);
155
+ if (launcher && isGenerated(launcher))
156
+ journal.remove(launcher);
157
+ const d = dry ? " (dry run)" : "";
158
+ io.out(`- [profiles.${name}] and ${rules} project rules from config.toml${d}`);
159
+ if (launcher)
160
+ io.out(`- ${tildify(launcher, io.env)}${d}`);
161
+ io.out(`${tildify(agentProfileDir(name, agent, io.env), io.env)} stays (sign-in, history); delete it by hand when you no longer need it.`);
162
+ const hint = journal.hint();
163
+ if (hint)
164
+ io.out(hint);
165
+ return 0;
166
+ }
167
+ function folder(arg, io) {
168
+ const dir = resolvePath(expandHome(arg ?? process.cwd(), io.env));
169
+ let ok = false;
170
+ try {
171
+ ok = statSync(dir).isDirectory();
172
+ }
173
+ catch {
174
+ ok = false;
175
+ }
176
+ if (!ok)
177
+ fail(`no such folder: ${arg ?? dir}`);
178
+ return dir;
179
+ }
180
+ async function which(args, io) {
181
+ const p = parseFlags(args, JSON_FLAG, 1);
182
+ const dir = folder(p.positionals[0], io);
183
+ const r = resolveProfile(dir, loadConfig(io.env), io.env);
184
+ if (bool(p, "json")) {
185
+ printJson(io.out, { dir: tildify(dir, io.env), assigned: r.assigned || null, chosen: r.chosen || null, reason: r.reason, note: r.note || null });
186
+ return 0;
187
+ }
188
+ io.out(tildify(dir, io.env));
189
+ io.out(` assigned: ${r.assigned || "none"} (${r.reason})`);
190
+ io.out(r.note ? ` using now: ${r.chosen} (${r.assigned} ${r.note})` : ` using now: ${r.chosen || "plain claude"}`);
191
+ return 0;
192
+ }
193
+ async function assign(args, io) {
194
+ const p = parseFlags(args, DRY_RUN, 2);
195
+ const [dirArg, name] = p.positionals;
196
+ if (!dirArg || !name)
197
+ return fail("usage: turno profile assign <dir> <profile>");
198
+ const dir = folder(dirArg, io);
199
+ const config = loadConfig(io.env);
200
+ if (!listProfiles(config, io.env).includes(name))
201
+ fail(`no profile '${name}' (turno profile list)`);
202
+ const dry = bool(p, "dry-run");
203
+ const journal = new Journal(io.env, `profile assign ${tildify(dir, io.env)} ${name}`, dry);
204
+ const shown = tildify(dir, io.env);
205
+ // One rule per folder and agent: a Codex rule does not replace the folder's Claude Code rule.
206
+ const agent = agentOf(name, config);
207
+ editConfig(io.env, journal, (t) => {
208
+ const r = removeArrayTables(t, "projects", (e) => resolvePath(expandHome(e.path ?? "", io.env)) === dir && agentOf(e.profile ?? "", config) === agent);
209
+ return addArrayTable(r.text, "projects", { path: shown, profile: name });
210
+ });
211
+ io.out(`${shown} -> ${name}${dry ? " (dry run)" : ""}`);
212
+ const hint = journal.hint();
213
+ if (hint)
214
+ io.out(hint);
215
+ return 0;
216
+ }
217
+ async function unassign(args, io) {
218
+ const p = parseFlags(args, DRY_RUN, 1);
219
+ const dir = resolvePath(expandHome(p.positionals[0] ?? process.cwd(), io.env));
220
+ const dry = bool(p, "dry-run");
221
+ const journal = new Journal(io.env, `profile unassign ${tildify(dir, io.env)}`, dry);
222
+ let removed = 0;
223
+ editConfig(io.env, journal, (t) => {
224
+ const r = removeArrayTables(t, "projects", (e) => resolvePath(expandHome(e.path ?? "", io.env)) === dir);
225
+ removed = r.removed;
226
+ return r.text;
227
+ });
228
+ if (!removed) {
229
+ io.out(`${tildify(dir, io.env)} has no rule of its own (turno profile which explains what applies)`);
230
+ return 1;
231
+ }
232
+ io.out(`${tildify(dir, io.env)} unassigned${dry ? " (dry run)" : ""}`);
233
+ const hint = journal.hint();
234
+ if (hint)
235
+ io.out(hint);
236
+ return 0;
237
+ }
238
+ export const command = group("profile", "Claude Code accounts: list, add, repair, remove, and which folders use each", {
239
+ list: { summary: "each profile, its account and roles", synopsis: "[--json]", flags: ["--json"], run: list },
240
+ add: {
241
+ summary: "declare a profile in config.toml and set up its folder and launcher (claude-<name>, codex-<name>, ...)",
242
+ synopsis: "<name> [--agent claude|codex|copilot|cursor] [--color <c>] [--browser chrome|default] [--dry-run]",
243
+ args: ["any"],
244
+ flags: ["--agent", "--color", "--browser", "--dry-run"],
245
+ run: add,
246
+ },
247
+ repair: { summary: "relink shared folders and rewrite launchers (all profiles by default)", synopsis: "[profile...]", args: ["profile"], run: repair },
248
+ remove: {
249
+ summary: "drop a profile from config.toml and its launcher (its folder stays)",
250
+ synopsis: "<name> [--dry-run]",
251
+ args: ["profile"],
252
+ flags: ["--dry-run"],
253
+ run: remove,
254
+ },
255
+ which: { summary: "which profile auto uses in a folder, and why", synopsis: "[dir] [--json]", args: ["dir"], flags: ["--json"], run: which },
256
+ assign: { summary: "make a folder (and everything under it) use a profile", synopsis: "<dir> <profile> [--dry-run]", args: ["dir", "profile"], flags: ["--dry-run"], run: assign },
257
+ unassign: { summary: "remove a folder's own rule", synopsis: "[dir] [--dry-run]", args: ["dir"], flags: ["--dry-run"], run: unassign },
258
+ }, { fallback: "list" });
259
+ //# sourceMappingURL=profile.js.map
@@ -0,0 +1,23 @@
1
+ import { resolve as resolvePath } from "node:path";
2
+ import { loadConfig } from "../../core/config.js";
3
+ import { resolveProfile } from "../../core/resolve.js";
4
+ /** Field separator of the machine output read by status lines. */
5
+ export const SEP = "\x1f";
6
+ export const command = {
7
+ summary: "machine-readable resolution for status lines",
8
+ usage: [
9
+ "Usage: turno resolve [dir] [--json]",
10
+ "",
11
+ "Prints chosen, assigned, reason and note separated by \\x1f on one line,",
12
+ "or a JSON object with --json.",
13
+ ].join("\n"),
14
+ hidden: true,
15
+ async run(args, io) {
16
+ const json = args.includes("--json");
17
+ const dir = args.find((a) => a !== "--json");
18
+ const r = resolveProfile(resolvePath(dir ?? process.cwd()), loadConfig(io.env), io.env);
19
+ io.out(json ? JSON.stringify(r) : [r.chosen, r.assigned, r.reason, r.note].join(SEP));
20
+ return 0;
21
+ },
22
+ };
23
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1,15 @@
1
+ import { fail } from "../io.js";
2
+ import { launchProfile } from "../launch.js";
3
+ import { command as auto } from "./auto.js";
4
+ export const command = {
5
+ summary: "open a profile with its agent (turno <profile> is the short form), or auto",
6
+ usage: "Usage: turno run <profile|auto> [claude args]\n\nEverything after the profile goes to claude, for example: turno run work --resume",
7
+ args: ["profile-or-auto"],
8
+ async run(args, io) {
9
+ const [name, ...rest] = args;
10
+ if (!name)
11
+ return fail("usage: turno run <profile|auto> [claude args]");
12
+ return name === "auto" ? auto.run(rest, io) : launchProfile(name, rest, io);
13
+ },
14
+ };
15
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1,123 @@
1
+ import { execFile } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ import { storeKeychainSecret } from "../../core/secrets.js";
4
+ import { readFileSync } from "node:fs";
5
+ import { paths, tildify } from "../../core/paths.js";
6
+ import { fail } from "../io.js";
7
+ const run = promisify(execFile);
8
+ const USAGE = `Usage:
9
+ turno secret set <service> read a value from stdin and store it in the Keychain
10
+ turno secret has <service> exit 0 when the Keychain item exists
11
+ turno secret rm <service> delete the Keychain item
12
+ turno secret list [--json] every keychain: reference in mcp.toml and whether it is stored
13
+
14
+ Reference it in mcp.toml as "keychain:<service>". Values are never printed.`;
15
+ async function readStdin() {
16
+ if (process.stdin.isTTY) {
17
+ process.stderr.write("value (input hidden, end with Enter): ");
18
+ return new Promise((resolve) => {
19
+ const stdin = process.stdin;
20
+ let value = "";
21
+ stdin.setRawMode(true);
22
+ stdin.resume();
23
+ stdin.setEncoding("utf8");
24
+ const onData = (ch) => {
25
+ if (ch === "\r" || ch === "\n" || ch === "\u0004") {
26
+ stdin.setRawMode(false);
27
+ stdin.pause();
28
+ stdin.off("data", onData);
29
+ process.stderr.write("\n");
30
+ resolve(value);
31
+ }
32
+ else if (ch === "\u0003") {
33
+ process.exit(130);
34
+ }
35
+ else if (ch === "\u007f") {
36
+ value = value.slice(0, -1);
37
+ }
38
+ else {
39
+ value += ch;
40
+ }
41
+ };
42
+ stdin.on("data", onData);
43
+ });
44
+ }
45
+ const chunks = [];
46
+ for await (const c of process.stdin)
47
+ chunks.push(c);
48
+ return Buffer.concat(chunks).toString("utf8").replace(/\r?\n$/, "");
49
+ }
50
+ async function exists(service) {
51
+ try {
52
+ // Without -w: this reads the item's attributes, never its value.
53
+ await run("security", ["find-generic-password", "-s", service], { timeout: 10_000 });
54
+ return true;
55
+ }
56
+ catch {
57
+ return false;
58
+ }
59
+ }
60
+ /** keychain:<service> references in mcp.toml. */
61
+ export function keychainRefs(text) {
62
+ return [...new Set([...text.matchAll(/"keychain:([^"\\]+)"/g)].map((m) => m[1]))].sort();
63
+ }
64
+ async function list(args, io) {
65
+ const json = args.includes("--json");
66
+ let text = "";
67
+ try {
68
+ text = readFileSync(paths(io.env).mcpFile, "utf8");
69
+ }
70
+ catch {
71
+ text = "";
72
+ }
73
+ const refs = keychainRefs(text);
74
+ const found = await Promise.all(refs.map((r) => exists(r)));
75
+ if (json) {
76
+ io.out(JSON.stringify(refs.map((r, i) => ({ service: r, stored: found[i] })), null, 2));
77
+ return 0;
78
+ }
79
+ if (!refs.length)
80
+ io.out(`no keychain: references in ${tildify(paths(io.env).mcpFile, io.env)}`);
81
+ for (const [i, r] of refs.entries())
82
+ io.out(`${found[i] ? "stored " : "MISSING"} keychain:${r}${found[i] ? "" : ` (turno secret set ${r})`}`);
83
+ return found.every(Boolean) ? 0 : 1;
84
+ }
85
+ export const command = {
86
+ summary: "store MCP secrets in the macOS Keychain",
87
+ usage: USAGE,
88
+ subcommands: { set: { args: ["any"] }, has: { args: ["any"] }, rm: { args: ["any"] }, list: { flags: ["--json"] } },
89
+ async run(args, io) {
90
+ const [sub, service] = args;
91
+ if (sub === "list" || sub === undefined)
92
+ return list(args.slice(1), io);
93
+ if (!service)
94
+ return fail(USAGE);
95
+ switch (sub) {
96
+ case "set": {
97
+ const value = await readStdin();
98
+ if (!value)
99
+ return fail("empty value");
100
+ await storeKeychainSecret(service, value);
101
+ io.out(`stored keychain:${service}`);
102
+ return 0;
103
+ }
104
+ case "has":
105
+ try {
106
+ await run("security", ["find-generic-password", "-s", service], { timeout: 10_000 });
107
+ io.out(`keychain:${service} exists`);
108
+ return 0;
109
+ }
110
+ catch {
111
+ io.out(`keychain:${service} not found`);
112
+ return 1;
113
+ }
114
+ case "rm":
115
+ await run("security", ["delete-generic-password", "-s", service], { timeout: 10_000 });
116
+ io.out(`removed keychain:${service}`);
117
+ return 0;
118
+ default:
119
+ return fail(USAGE);
120
+ }
121
+ },
122
+ };
123
+ //# sourceMappingURL=secret.js.map
@@ -0,0 +1,36 @@
1
+ import { loadConfig } from "../../core/config.js";
2
+ import { tildify } from "../../core/paths.js";
3
+ import { displayName, liveSessions } from "../../core/sessions.js";
4
+ import { JSON_FLAG, bool, parseFlags, printJson } from "../args.js";
5
+ import { group } from "../group.js";
6
+ import { command as handoff } from "./handoff.js";
7
+ import { command as sessions } from "./sessions.js";
8
+ export function sessionsData(env) {
9
+ const config = loadConfig(env);
10
+ return liveSessions(env, config).map((s) => ({
11
+ name: displayName(s),
12
+ profile: s.source === "record" ? (s.profile ?? null) : s.source === "desktop" ? null : (config.system ?? null),
13
+ source: s.source,
14
+ status: s.status,
15
+ cwd: s.cwd,
16
+ }));
17
+ }
18
+ async function list(args, io) {
19
+ const p = parseFlags(args, JSON_FLAG, 0);
20
+ if (bool(p, "json")) {
21
+ printJson(io.out, sessionsData(io.env).map((s) => ({ ...s, cwd: tildify(s.cwd, io.env) })));
22
+ return 0;
23
+ }
24
+ return sessions.run([], io);
25
+ }
26
+ export const command = group("session", "live Claude Code sessions, and moving one to another account", {
27
+ list: { summary: "live sessions and the account of each", synopsis: "[--json]", flags: ["--json"], run: list },
28
+ handoff: {
29
+ summary: "print the command that continues or forks this session under another profile",
30
+ synopsis: "<profile|auto> [--fork] [--copy]",
31
+ args: ["profile-or-auto"],
32
+ flags: ["--fork", "--copy"],
33
+ run: (args, io) => handoff.run(args, io),
34
+ },
35
+ }, { fallback: "list" });
36
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1,27 @@
1
+ import { loadConfig } from "../../core/config.js";
2
+ import { tildify } from "../../core/paths.js";
3
+ import { displayName, liveSessions } from "../../core/sessions.js";
4
+ export const command = {
5
+ summary: "list live sessions and the account of each",
6
+ usage: "Usage: turno sessions",
7
+ async run(_args, io) {
8
+ const config = loadConfig(io.env);
9
+ const rows = liveSessions(io.env, config).map((s) => {
10
+ const account = s.source === "desktop"
11
+ ? "Claude Desktop (its own account)"
12
+ : s.source === "record"
13
+ ? s.profile
14
+ : `default (~/.claude = ${config.system ?? "?"})`;
15
+ return { name: displayName(s), account, status: s.status, cwd: tildify(s.cwd, io.env) };
16
+ });
17
+ if (rows.length === 0) {
18
+ io.out("No live sessions.");
19
+ return 0;
20
+ }
21
+ const w = Math.max(6, ...rows.map((r) => r.name.length));
22
+ for (const r of rows)
23
+ io.out(`${r.name.padEnd(w)} ${r.account.padEnd(34)} ${r.status.padEnd(6)} ${r.cwd}`);
24
+ return 0;
25
+ },
26
+ };
27
+ //# sourceMappingURL=sessions.js.map