turno-cli 0.1.1 → 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 (104) hide show
  1. package/CHANGELOG.md +284 -0
  2. package/README.md +120 -53
  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/demo/server.js +34 -0
  74. package/dist/mcpd/cache.js +18 -4
  75. package/dist/mcpd/calllog.js +253 -0
  76. package/dist/mcpd/client-names.js +51 -0
  77. package/dist/mcpd/connectors.js +148 -17
  78. package/dist/mcpd/daemon.js +452 -116
  79. package/dist/mcpd/folder-sets.js +39 -0
  80. package/dist/mcpd/gateway.js +441 -47
  81. package/dist/mcpd/health.js +269 -0
  82. package/dist/mcpd/importer.js +356 -36
  83. package/dist/mcpd/instances.js +425 -65
  84. package/dist/mcpd/jsonrpc.js +8 -0
  85. package/dist/mcpd/launchd.js +65 -48
  86. package/dist/mcpd/modern.js +648 -0
  87. package/dist/mcpd/oauth.js +791 -0
  88. package/dist/mcpd/peerpid.js +122 -6
  89. package/dist/mcpd/pressure.js +85 -0
  90. package/dist/mcpd/rss.js +151 -0
  91. package/dist/mcpd/service.js +167 -0
  92. package/dist/mcpd/state.js +183 -0
  93. package/dist/mcpd/sync.js +55 -80
  94. package/dist/mcpd/systemd.js +80 -0
  95. package/dist/mcpd/tokens.js +89 -0
  96. package/dist/mcpd/upstream.js +154 -44
  97. package/dist/statusline/cost.js +154 -44
  98. package/dist/statusline/input.js +66 -0
  99. package/dist/statusline/render.js +9 -3
  100. package/dist/ui/fonts.js +8 -3
  101. package/dist/ui/settings.js +27 -15
  102. package/npm-shrinkwrap.json +1093 -0
  103. package/package.json +6 -6
  104. package/dist/cli/commands/available.js +0 -18
@@ -1,11 +1,13 @@
1
- import { existsSync, readFileSync, readdirSync, realpathSync } from "node:fs";
1
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { loadConfig } from "../../core/config.js";
4
4
  import { paths, profileDir } from "../../core/paths.js";
5
5
  import { listProfiles, profileFromConfigDir } from "../../core/profiles.js";
6
+ import { bool, flagsOf, parseFlags } from "../args.js";
6
7
  import { fail } from "../io.js";
8
+ import { realOr } from "../../core/fsutil.js";
7
9
  const USAGE = `Usage:
8
- turno handoff <profile|auto> [--fork] [--copy]
10
+ turno session handoff [profile|auto] [--fork] [--copy]
9
11
 
10
12
  Prints the command that continues THIS Claude Code session under another profile:
11
13
  default resume it there (exit this session first)
@@ -14,12 +16,15 @@ Prints the command that continues THIS Claude Code session under another profile
14
16
 
15
17
  Run it from inside a Claude Code session (it reads CLAUDE_CODE_SESSION_ID). The command starts
16
18
  with a cd to the folder the session began in, because claude --resume looks sessions up by
17
- the project folder it is launched from.`;
19
+ the project folder it is launched from.
20
+
21
+ Without a profile, a terminal shows the profiles to choose from; elsewhere it exits with 2
22
+ and lists them.`;
18
23
  function shellQuote(s) {
19
24
  return /^[A-Za-z0-9_./:@%+=-]+$/.test(s) ? s : `'${s.replace(/'/g, "'\\''")}'`;
20
25
  }
21
26
  /** The first `cwd` recorded in a transcript: where the session started. */
22
- export function transcriptCwd(file) {
27
+ function transcriptCwd(file) {
23
28
  const text = readFileSync(file, "utf8");
24
29
  for (const line of text.split("\n")) {
25
30
  if (!line.includes('"cwd"'))
@@ -35,7 +40,7 @@ export function transcriptCwd(file) {
35
40
  }
36
41
  return undefined;
37
42
  }
38
- export function findTranscript(configDir, sessionId) {
43
+ function findTranscript(configDir, sessionId) {
39
44
  const projects = join(configDir, "projects");
40
45
  if (!existsSync(projects))
41
46
  return undefined;
@@ -46,14 +51,6 @@ export function findTranscript(configDir, sessionId) {
46
51
  }
47
52
  return undefined;
48
53
  }
49
- function real(p) {
50
- try {
51
- return realpathSync(p);
52
- }
53
- catch {
54
- return p;
55
- }
56
- }
57
54
  export function buildHandoff(target, fork, env) {
58
55
  const sid = env.CLAUDE_CODE_SESSION_ID;
59
56
  if (!sid)
@@ -74,8 +71,8 @@ export function buildHandoff(target, fork, env) {
74
71
  const current = profileFromConfigDir(env.CLAUDE_CONFIG_DIR, config, env);
75
72
  if (!fork && target === current)
76
73
  warnings.push(`this session already runs as '${target}'`);
77
- if (target !== "auto" && real(join(cfg, "projects")) !== real(join(profileDir(target, env), "projects"))) {
78
- warnings.push(`${target} does not share the projects folder with this profile, so it will not see this session (turno setup ${target})`);
74
+ if (target !== "auto" && realOr(join(cfg, "projects")) !== realOr(join(profileDir(target, env), "projects"))) {
75
+ warnings.push(`${target} does not share the projects folder with this profile, so it will not see this session (turno profile repair ${target})`);
79
76
  }
80
77
  const command = `cd ${shellQuote(cwd)} && turno ${target} --resume ${sid}${fork ? " --fork-session" : ""}`;
81
78
  return { command, warnings };
@@ -94,23 +91,37 @@ async function copy(text) {
94
91
  }
95
92
  });
96
93
  }
94
+ const SPEC = { fork: { type: "boolean" }, copy: { type: "boolean" } };
97
95
  export const command = {
98
96
  summary: "print the command to continue or fork this session under another profile",
99
97
  usage: USAGE,
98
+ args: ["profile-or-auto"],
99
+ flags: flagsOf(SPEC),
100
100
  async run(args, io) {
101
- const target = args.find((a) => !a.startsWith("--"));
101
+ const p = parseFlags(args, SPEC, 1);
102
+ let target = p.positionals[0];
102
103
  if (!target) {
103
104
  const config = loadConfig(io.env);
104
- io.out(`profiles: ${[...listProfiles(config, io.env, "claude"), "auto"].join(" ")}`);
105
- io.out(`current: ${profileFromConfigDir(io.env.CLAUDE_CONFIG_DIR, config, io.env) ?? "(none)"}`);
106
- io.err(USAGE);
107
- return 2;
105
+ const current = profileFromConfigDir(io.env.CLAUDE_CONFIG_DIR, config, io.env);
106
+ if (!io.ask) {
107
+ // Scripts read these two lines; the error names the values and the exit is 2.
108
+ io.out(`profiles: ${[...listProfiles(config, io.env, "claude"), "auto"].join(" ")}`);
109
+ io.out(`current: ${current ?? "(none)"}`);
110
+ }
111
+ const { pickProfile } = await import("../picker.js");
112
+ target = await pickProfile(io, {
113
+ command: "session handoff",
114
+ title: bool(p, "fork") ? "Fork this session under" : "Continue this session under",
115
+ agent: "claude",
116
+ extra: ["auto"],
117
+ ...(current ? { marks: { [current]: "this session" } } : {}),
118
+ });
108
119
  }
109
- const h = buildHandoff(target, args.includes("--fork"), io.env);
120
+ const h = buildHandoff(target, bool(p, "fork"), io.env);
110
121
  for (const w of h.warnings)
111
122
  io.err(`warning: ${w}`);
112
123
  io.out(h.command);
113
- if (args.includes("--copy") && !(await copy(`${h.command}\n`)))
124
+ if (bool(p, "copy") && !(await copy(`${h.command}\n`)))
114
125
  io.err("warning: could not copy to the clipboard");
115
126
  return 0;
116
127
  },
@@ -1,103 +1,149 @@
1
+ import { effectivePolicy } from "../../accounts/policy.js";
1
2
  import { loadRegistry } from "../../accounts/registry.js";
2
3
  import { tildify } from "../../core/paths.js";
3
- import { JSON_FLAG, bool, parseFlags, printJson } from "../args.js";
4
+ import { DRY_RUN, JSON_FLAG, bool, flagsOf, parseFlags, printJson, str } from "../args.js";
4
5
  import { group } from "../group.js";
5
- import { fail, paint } from "../io.js";
6
+ import { launcherExists } from "../../accounts/delegate.js";
7
+ import { loadConfig } from "../../core/config.js";
8
+ import { fail } from "../io.js";
9
+ import { profileColor, style } from "../style.js";
6
10
  import * as accounts from "./accounts.js";
7
- import { dispatch, loadBrowser } from "./browser.js";
11
+ import { policyLine } from "./accounts.js";
12
+ import { NOT_INSTALLED, defaultDeps, dispatch } from "./browser.js";
8
13
  /**
9
14
  * Who acts on an outside service for a session: a service account (`linear:work`, run by a
10
15
  * profile through the accounts bridge) or a browser identity (`browser:school`, a Chrome
11
16
  * profile with saved logins). One command for both; `accounts` and `browser` still work.
12
17
  */
13
18
  const BROWSER = "browser:";
19
+ let deps = defaultDeps;
14
20
  async function browserModule(io) {
15
- const mod = await loadBrowser();
21
+ const mod = await deps.load(io);
16
22
  if (!mod) {
17
- io.err("turno: the browser package (turno-browser) is not installed; browser identities need it");
18
- return fail("browser identities are not available");
23
+ io.err(`turno: ${NOT_INSTALLED}`);
24
+ return fail("browser identities need turno-browser");
19
25
  }
20
26
  return mod;
21
27
  }
22
- async function onBrowser(mod, sub, args, io) {
23
- try {
24
- return await dispatch(mod, sub, args, io);
25
- }
26
- catch (err) {
27
- if (err.name === "IdentityError")
28
- return fail(err.message);
29
- throw err;
30
- }
28
+ /** The first argument that is not a flag or a flag value, without parsing the flags. */
29
+ function firstId(args) {
30
+ return args.find((a) => !a.startsWith("-"));
31
31
  }
32
32
  async function list(args, io) {
33
33
  const p = parseFlags(args, JSON_FLAG, 0);
34
34
  const reg = loadRegistry(io.env);
35
- const mod = await loadBrowser();
35
+ const mod = await deps.load(io);
36
36
  const browsers = mod ? mod.listIdentities(io.env) : [];
37
37
  if (bool(p, "json")) {
38
- printJson(io.out, {
38
+ printJson(io, {
39
39
  services: Object.values(reg.accounts)
40
40
  .sort((a, b) => a.id.localeCompare(b.id))
41
- .map((a) => ({ id: a.id, service: a.service, profile: a.profile, tools: a.tools, description: a.description ?? null })),
41
+ .map((a) => ({
42
+ id: a.id,
43
+ service: a.service,
44
+ profile: a.profile,
45
+ tools: a.tools,
46
+ readTools: a.readTools ?? null,
47
+ confirm: effectivePolicy(a),
48
+ description: a.description ?? null,
49
+ })),
42
50
  browser: browsers.map((b) => ({ id: `${BROWSER}${b.id}`, inUse: b.inUse, dir: tildify(b.dir, io.env) })),
43
51
  preferences: reg.prefer.map((r) => ({ path: tildify(r.path, io.env), accounts: r.accounts })),
44
52
  });
45
53
  return 0;
46
54
  }
47
- io.out(paint(io, "Service accounts", "1"));
48
- accounts.list(io);
55
+ const st = style(io);
56
+ let colors = {};
57
+ try {
58
+ colors = loadConfig(io.env).profiles;
59
+ }
60
+ catch {
61
+ /* pills without their configured colors */
62
+ }
63
+ const pill = (name) => st.profile(name, profileColor(colors, name));
64
+ io.out(st.header("Service accounts"));
65
+ const services = Object.values(reg.accounts).sort((a, b) => a.id.localeCompare(b.id));
66
+ if (!services.length)
67
+ io.out(` none yet ${st.muted("(turno identity add linear:work --profile work --tools 'mcp__linear__*')")}`);
68
+ // Each account: id, profile, tools; under them its confirm policy and description.
69
+ const rows = st.tableRows(services.map((a) => [
70
+ st.bold(a.id),
71
+ pill(a.profile),
72
+ `${a.tools.join(", ")}${launcherExists(a.profile, io.env) ? "" : ` ${st.warn("(no launcher)")}`}`,
73
+ ]));
74
+ // Under the profile name: a pill on a terminal starts with a space of its own.
75
+ const under = " ".repeat(2 + Math.max(0, ...services.map((a) => a.id.length)) + 2 + (st.color ? 1 : 0));
76
+ services.forEach((a, i) => {
77
+ for (const l of rows[i])
78
+ io.out(l);
79
+ io.out(st.wrap(under, st.muted(policyLine(a))));
80
+ if (a.description)
81
+ io.out(st.wrap(under, st.muted(a.description)));
82
+ });
83
+ if (reg.prefer.length) {
84
+ io.out("");
85
+ io.out(st.header("Folder preferences"));
86
+ for (const l of st.table(reg.prefer.map((r) => [tildify(r.path, io.env), Object.entries(r.accounts).map(([sv, id]) => `${sv}=${id}`).join(" ") || st.muted("(none)")])))
87
+ io.out(l);
88
+ }
49
89
  io.out("");
50
- io.out(paint(io, "Browser identities", "1"));
90
+ io.out(st.header("Browser identities"));
51
91
  if (!mod)
52
- io.out(" (the turno-browser package is not installed)");
92
+ io.out(st.note("warn", NOT_INSTALLED));
53
93
  else if (!browsers.length)
54
- io.out(" none yet (turno identity add browser:<id>)");
94
+ io.out(` none yet ${st.muted("(turno identity add browser:<id>)")}`);
55
95
  else {
56
- const w = Math.max(...browsers.map((b) => b.id.length)) + BROWSER.length;
57
- for (const b of browsers) {
58
- const state = b.inUse ? paint(io, "in use", "33") : paint(io, "free ", "32");
59
- io.out(` ${`${BROWSER}${b.id}`.padEnd(w)} ${state} ${tildify(b.dir, io.env)}`);
60
- }
96
+ const rows = browsers.map((b) => [st.bold(`${BROWSER}${b.id}`), b.inUse ? st.lead("on", st.warn("in use")) : st.lead("off", st.ok("free")), st.muted(tildify(b.dir, io.env))]);
97
+ for (const l of st.table(rows))
98
+ io.out(l);
61
99
  }
62
100
  return 0;
63
101
  }
64
102
  async function add(args, io) {
65
- const id = args.find((a) => !a.startsWith("-"));
66
- if (id?.startsWith(BROWSER)) {
67
- if (args.includes("--dry-run")) {
68
- io.out(`(dry run) would create browser identity "${id.slice(BROWSER.length)}"`);
69
- return 0;
70
- }
71
- return onBrowser(await browserModule(io), "add", [id.slice(BROWSER.length)], io);
103
+ if (!firstId(args)?.startsWith(BROWSER))
104
+ return accounts.add(args, io);
105
+ const p = parseFlags(args, DRY_RUN, 1);
106
+ const id = p.positionals[0].slice(BROWSER.length);
107
+ if (bool(p, "dry-run")) {
108
+ io.out(`(dry run) would create browser identity "${id}"`);
109
+ return 0;
72
110
  }
73
- return accounts.add(args, io);
111
+ return dispatch(await browserModule(io), "add", [id], io, deps);
74
112
  }
75
113
  async function remove(args, io) {
76
- const id = args.find((a) => !a.startsWith("-"));
77
- if (id?.startsWith(BROWSER)) {
78
- if (args.includes("--dry-run")) {
79
- io.out(`(dry run) would delete browser identity "${id.slice(BROWSER.length)}" and its saved logins`);
80
- return 0;
81
- }
82
- return onBrowser(await browserModule(io), "remove", [id.slice(BROWSER.length)], io);
114
+ if (!firstId(args)?.startsWith(BROWSER))
115
+ return accounts.remove(args, io);
116
+ const p = parseFlags(args, DRY_RUN, 1);
117
+ const id = p.positionals[0].slice(BROWSER.length);
118
+ if (bool(p, "dry-run")) {
119
+ io.out(`(dry run) would delete browser identity "${id}" and its saved logins`);
120
+ return 0;
83
121
  }
84
- return accounts.remove(args, io);
122
+ return dispatch(await browserModule(io), "remove", [id], io, deps);
85
123
  }
86
124
  async function login(args, io) {
87
- const [id, ...rest] = args;
125
+ const p = parseFlags(args, { url: { type: "string" } }, 1);
126
+ const id = p.positionals[0];
88
127
  if (!id)
89
128
  return fail("usage: turno identity login browser:<id> [--url <url>]");
90
129
  if (!id.startsWith(BROWSER))
91
- fail(`only browser identities sign in by hand; service accounts sign in through their profile (claude-<profile>)`);
92
- return onBrowser(await browserModule(io), "login", [id.slice(BROWSER.length), ...rest], io);
130
+ return fail("only browser identities sign in by hand; service accounts sign in through their profile (claude-<profile>)");
131
+ const url = str(p, "url");
132
+ return dispatch(await browserModule(io), "login", [id.slice(BROWSER.length), ...(url !== undefined ? ["--url", url] : [])], io, deps);
133
+ }
134
+ /** Swap the turno-browser loader and prompt, for tests. Returns the previous ones. */
135
+ export function setBrowserDeps(next) {
136
+ const prev = deps;
137
+ deps = next;
138
+ return prev;
93
139
  }
94
140
  export const command = group("identity", "who acts on outside services: service accounts (linear:work) and browser identities (browser:school)", {
95
141
  list: { summary: "service accounts, browser identities and folder preferences", synopsis: "[--json]", flags: ["--json"], run: list },
96
142
  add: {
97
143
  summary: "add a service account, or create a browser identity (browser:<id>)",
98
- synopsis: "<service:label> --profile <p> --tools <pattern>[,...] | browser:<id> [--dry-run]",
144
+ synopsis: "<service:label> --profile <p> --tools <pattern>[,...] [--read-tools <pattern>[,...]] [--confirm always|writes|never] | browser:<id> [--dry-run]",
99
145
  args: ["any"],
100
- flags: ["--profile", "--tools", "--service", "--description", "--dry-run"],
146
+ flags: ["--profile", "--tools", "--read-tools", "--confirm", "--service", "--description", "--dry-run"],
101
147
  run: add,
102
148
  },
103
149
  remove: { summary: "remove a service account, or delete a browser identity and its logins", synopsis: "<id> [--dry-run]", args: ["identity"], flags: ["--dry-run"], run: remove },
@@ -109,6 +155,11 @@ export const command = group("identity", "who acts on outside services: service
109
155
  flags: ["--dry-run"],
110
156
  run: async (a, io) => accounts.prefer(a, io),
111
157
  },
112
- log: { summary: "recent calls to the accounts bridge", synopsis: "[-n N]", flags: ["--tail"], run: async (a, io) => accounts.log(a, io) },
158
+ log: {
159
+ summary: "recent calls to the accounts bridge; --verify checks the log's hash chain",
160
+ synopsis: "[-n N] [--verify] [--json]",
161
+ flags: flagsOf(accounts.LOG_SPEC),
162
+ run: async (a, io) => accounts.log(a, io),
163
+ },
113
164
  }, { fallback: "list" });
114
165
  //# sourceMappingURL=identity.js.map