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
@@ -18,7 +18,7 @@ export function sessionsData(env) {
18
18
  async function list(args, io) {
19
19
  const p = parseFlags(args, JSON_FLAG, 0);
20
20
  if (bool(p, "json")) {
21
- printJson(io.out, sessionsData(io.env).map((s) => ({ ...s, cwd: tildify(s.cwd, io.env) })));
21
+ printJson(io, sessionsData(io.env).map((s) => ({ ...s, cwd: tildify(s.cwd, io.env) })));
22
22
  return 0;
23
23
  }
24
24
  return sessions.run([], io);
@@ -27,7 +27,7 @@ export const command = group("session", "live Claude Code sessions, and moving o
27
27
  list: { summary: "live sessions and the account of each", synopsis: "[--json]", flags: ["--json"], run: list },
28
28
  handoff: {
29
29
  summary: "print the command that continues or forks this session under another profile",
30
- synopsis: "<profile|auto> [--fork] [--copy]",
30
+ synopsis: "[profile|auto] [--fork] [--copy]",
31
31
  args: ["profile-or-auto"],
32
32
  flags: ["--fork", "--copy"],
33
33
  run: (args, io) => handoff.run(args, io),
@@ -1,26 +1,56 @@
1
1
  import { loadConfig } from "../../core/config.js";
2
2
  import { tildify } from "../../core/paths.js";
3
- import { displayName, liveSessions } from "../../core/sessions.js";
3
+ import { displayName, liveSessions, parseProcStart } from "../../core/sessions.js";
4
+ import { parseFlags } from "../args.js";
5
+ import { profileColor, style } from "../style.js";
6
+ /** "45s", "12m", "3h05m", "2d 4h": how long a session has been running. */
7
+ function age(ms) {
8
+ const s = Math.max(0, Math.floor(ms / 1000));
9
+ if (s < 60)
10
+ return `${s}s`;
11
+ const m = Math.floor(s / 60);
12
+ if (m < 60)
13
+ return `${m}m`;
14
+ const h = Math.floor(m / 60);
15
+ if (h < 24)
16
+ return `${h}h${String(m % 60).padStart(2, "0")}m`;
17
+ return `${Math.floor(h / 24)}d ${h % 24}h`;
18
+ }
4
19
  export const command = {
5
20
  summary: "list live sessions and the account of each",
6
21
  usage: "Usage: turno sessions",
7
- async run(_args, io) {
22
+ async run(args, io) {
23
+ parseFlags(args, {}, 0);
8
24
  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) };
25
+ const s = style(io);
26
+ const pill = (name) => s.profile(name, profileColor(config.profiles, name));
27
+ const now = Date.now();
28
+ const rows = liveSessions(io.env, config).map((x) => {
29
+ const account = x.source === "desktop"
30
+ ? s.muted("Claude Desktop (its own account)")
31
+ : x.source === "record"
32
+ ? pill(x.profile)
33
+ : s.color
34
+ ? `${s.muted("plain claude")}${config.system ? ` ${pill(config.system)}` : ""}`
35
+ : `plain claude (~/.claude${config.system ? ` = ${config.system}` : ""})`;
36
+ const start = parseProcStart(x.procStart ?? "");
37
+ // Claude Code writes procStart in UTC; a reading in the future means it is local time.
38
+ const began = start ? (start.utc <= now + 60_000 ? start.utc : start.local) : undefined;
39
+ const status = x.status === "busy" ? s.warn(x.status) : x.status === "idle" ? s.ok(x.status) : x.status;
40
+ return [s.bold(displayName(x)), account, status, s.muted(began !== undefined ? age(now - began) : "?"), s.muted(tildify(x.cwd, io.env))];
16
41
  });
17
42
  if (rows.length === 0) {
18
43
  io.out("No live sessions.");
19
44
  return 0;
20
45
  }
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}`);
46
+ if (!s.color) {
47
+ for (const line of s.table(rows, { indent: 0 }))
48
+ io.out(line);
49
+ return 0;
50
+ }
51
+ io.out(s.header("Sessions"));
52
+ for (const line of s.table(rows, { columns: [{}, {}, {}, { align: "right", drop: 1 }, {}] }))
53
+ io.out(line);
24
54
  return 0;
25
55
  },
26
56
  };
@@ -1,48 +1,14 @@
1
- import { chmodSync, copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, renameSync, rmSync, rmdirSync, symlinkSync, writeFileSync } from "node:fs";
1
+ import { chmodSync, existsSync, lstatSync, mkdirSync, readdirSync, readlinkSync, writeFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import { adapter, agentHub, agentProfileDir } from "../../agents/index.js";
3
+ import { DEFAULT_AGENT, adapter, agentHub, agentProfileDir } from "../../agents/index.js";
4
4
  import { isValidProfileName, loadConfig } from "../../core/config.js";
5
- import { setValue } from "../../core/toml-edit.js";
6
- import { paths, profileDir, tildify } from "../../core/paths.js";
5
+ import { Journal, stamp } from "../../core/journal.js";
6
+ import { tildify } from "../../core/paths.js";
7
7
  import { agentOf } from "../../core/profiles.js";
8
8
  import { profileBusy } from "../../core/sessions.js";
9
- import { fail } from "../io.js";
10
- import { SHARED_DIRS, launcherName, turnoCommand, writeHelperLaunchers, writeLauncher } from "../launchers.js";
11
- export { SHARED_DIRS };
12
- /** Hub files shared by every profile (linked only when they exist in the hub). */
13
- export const SHARED_FILES = ["CLAUDE.md", "settings.json", "keybindings.json", "statusline-command.sh", ".mcp.json"];
14
- /**
15
- * Owned by each account and never linked. history.jsonl cannot be a symlink: Claude Code
16
- * ignores it unless it is a regular file with a single link.
17
- */
18
- export const PER_ACCOUNT = [
19
- ".claude.json",
20
- ".credentials.json",
21
- "history.jsonl",
22
- "backups",
23
- "daemon",
24
- "daemon.log",
25
- "daemon-auth-cooldown",
26
- "daemon-auth-status.json",
27
- "daemon.lock",
28
- "daemon.status.json",
29
- "feedback",
30
- "jobs",
31
- "policy-limits.json",
32
- "policy-limits.json.stamp.json",
33
- "policy-limits.json.signature.json",
34
- "remote-settings.json",
35
- "remote-settings.json.signature.json",
36
- "remote-settings.json.synced-at",
37
- "mcp-needs-auth-cache.json",
38
- "stats-cache.json",
39
- "telemetry",
40
- "shell-snapshots",
41
- "debug",
42
- ".last-cleanup",
43
- ".last-update-result.json",
44
- "computer-use.lock",
45
- ];
9
+ import { fail, plural } from "../io.js";
10
+ import { style } from "../style.js";
11
+ import { launcherName, refuseNpx, resolveTurnoCommand, writeHelperLaunchers, writeLauncher } from "../launchers.js";
46
12
  /** Names a profile cannot take: every command, alias and legacy word. */
47
13
  export const RESERVED = new Set([
48
14
  "auto", "which", "resolve", "sessions", "usage", "exhausted", "available", "hook", "setup", "status",
@@ -50,6 +16,7 @@ export const RESERVED = new Set([
50
16
  "cuenta", "resolver", "sesiones", "uso", "agotada", "disponible", "limite", "abrir", "sync-mcp",
51
17
  "profile", "navegador",
52
18
  "run", "limit", "session", "identity", "config", "undo", "upgrade", "completion", "__complete", "__update-check",
19
+ "uninstall", "init", "demo",
53
20
  ]);
54
21
  export function checkName(name) {
55
22
  if (!isValidProfileName(name))
@@ -57,8 +24,6 @@ export function checkName(name) {
57
24
  if (RESERVED.has(name))
58
25
  fail(`'${name}' is reserved`);
59
26
  }
60
- export { stamp } from "../../core/journal.js";
61
- import { stamp } from "../../core/journal.js";
62
27
  function lstat(path) {
63
28
  try {
64
29
  return lstatSync(path);
@@ -67,150 +32,163 @@ function lstat(path) {
67
32
  return undefined;
68
33
  }
69
34
  }
70
- /** Make <dir>/<item> a symlink to the hub, moving a local copy aside. */
71
- function linkItem(dir, item, aside, io, hub = paths(io.env).hub) {
35
+ /** True when `path` holds the person's own data: a file, or a folder that is not empty. */
36
+ function ownCopy(path) {
37
+ const st = lstat(path);
38
+ if (!st || st.isSymbolicLink())
39
+ return false;
40
+ if (st.isDirectory())
41
+ return readdirSync(path).length > 0;
42
+ return true;
43
+ }
44
+ /**
45
+ * Make <dir>/<item> a symlink to the hub, moving a local copy aside. Every step goes through
46
+ * the journal, so `turno undo` removes the link and moves the copy back (ADR 0025).
47
+ */
48
+ function linkItem(dir, item, aside, journal, hub) {
72
49
  const target = join(hub, item);
73
50
  const path = join(dir, item);
74
51
  const st = lstat(path);
52
+ let result = "linked";
75
53
  if (st?.isSymbolicLink()) {
76
54
  if (readlinkSync(path) === target)
77
- return;
78
- rmSync(path);
55
+ return "same";
56
+ journal.unlink(path);
79
57
  }
80
58
  else if (st?.isDirectory() && readdirSync(path).length === 0) {
81
- rmdirSync(path);
59
+ journal.rmdir(path);
82
60
  }
83
61
  else if (st) {
84
- mkdirSync(aside, { recursive: true });
85
- renameSync(path, join(aside, item));
86
- io.out(` ! ${item} was a local copy: moved to ${tildify(aside, io.env)}/ (merge it by hand if useful)`);
62
+ journal.mkdir(aside);
63
+ journal.move(path, join(aside, item));
64
+ result = "aside";
87
65
  }
88
- symlinkSync(target, path);
89
- io.out(` ↔ ${item}`);
90
- }
91
- const SEED_KEYS = ["mcpServers", "projects", "hasCompletedOnboarding", "lastOnboardingVersion", "theme"];
92
- /** First .claude.json of a profile: user MCP servers and per-project state, never the account. */
93
- function seedGlobalConfig(dir, io) {
94
- const dst = join(dir, ".claude.json");
95
- if (existsSync(dst)) {
96
- io.out(" = .claude.json already exists (turno mcp sync brings in new MCP servers)");
97
- return;
98
- }
99
- const src = paths(io.env).hubConfig;
100
- let hub;
101
- try {
102
- hub = JSON.parse(readFileSync(src, "utf8"));
103
- }
104
- catch {
105
- return;
106
- }
107
- const seed = {};
108
- for (const k of SEED_KEYS)
109
- if (k in hub)
110
- seed[k] = hub[k];
111
- writeFileSync(dst, `${JSON.stringify(seed, null, 2)}\n`, { mode: 0o600 });
112
- chmodSync(dst, 0o600);
113
- const count = (v) => (v && typeof v === "object" ? Object.keys(v).length : 0);
114
- io.out(` + .claude.json with ${count(seed.mcpServers)} MCP servers and ${count(seed.projects)} projects from the hub`);
66
+ journal.symlink(target, path);
67
+ return result;
115
68
  }
116
69
  /**
117
- * Codex profiles: seed config.toml from the hub once, and always store the login in the
118
- * profile (`cli_auth_credentials_store = "file"`), so each CODEX_HOME has its own account.
70
+ * Create a profile folder (0700) through the journal, so undo removes it while it is empty, or
71
+ * narrow an existing one to 0700, so undo puts its old mode back.
119
72
  */
120
- function prepareCodex(dir, io) {
121
- const file = join(dir, "config.toml");
122
- let text = "";
123
- if (existsSync(file))
124
- text = readFileSync(file, "utf8");
125
- else {
126
- const hubFile = join(agentHub("codex", io.env), "config.toml");
127
- if (existsSync(hubFile)) {
128
- text = readFileSync(hubFile, "utf8");
129
- io.out(" + config.toml from ~/.codex (the login is not copied)");
130
- }
131
- }
132
- const next = setValue(text, undefined, "cli_auth_credentials_store", "file");
133
- if (next !== text || !existsSync(file)) {
134
- writeFileSync(file, next, { mode: 0o600 });
135
- io.out(' + cli_auth_credentials_store = "file" (the login stays in this profile)');
136
- }
73
+ function profileFolder(dir, journal) {
74
+ journal.mkdir(dir, 0o700);
75
+ journal.chmod(dir, 0o700);
76
+ }
77
+ /** Write a file the setup creates or changes (seeds, agent config) through the journal. */
78
+ function writeOwn(file, text, journal) {
79
+ journal.save(file);
80
+ writeFileSync(file, text, { mode: 0o600 });
137
81
  chmodSync(file, 0o600);
82
+ journal.settle(file);
138
83
  }
139
- /** Profile of an agent other than Claude Code: its directory, hub links, config, launcher. */
140
- function setupAgentProfile(name, agent, io) {
84
+ /** Shared items of a profile: its folder, the agent's hub, and the items linked from it (files only when they exist). */
85
+ function sharedItems(name, agent, env) {
141
86
  const a = adapter(agent);
142
- const hub = agentHub(agent, io.env);
143
- const dir = agentProfileDir(name, agent, io.env);
144
- const aside = join(dir, `.aside-${stamp()}`);
145
- io.out(`▸ ${name} (${a.label}) → ${tildify(dir, io.env)}`);
146
- mkdirSync(dir, { recursive: true });
147
- chmodSync(dir, 0o700);
148
- for (const item of a.sharedDirs) {
149
- mkdirSync(join(hub, item), { recursive: true });
150
- linkItem(dir, item, aside, io, hub);
87
+ const hub = agentHub(agent, env);
88
+ return { dir: agentProfileDir(name, agent, env), hub, dirs: [...a.sharedDirs], files: a.sharedFiles.filter((f) => existsSync(join(hub, f))) };
89
+ }
90
+ /**
91
+ * The person's own files that setting up `names` would move to .aside-<stamp>/, so a command
92
+ * can ask before it moves anything. `config` is the one the setup will run with (turno init
93
+ * passes the config it is about to write, so a profile it declares has its own agent).
94
+ */
95
+ export function localCopies(names, env, config = loadConfig(env)) {
96
+ return names.map((name) => {
97
+ const s = sharedItems(name, agentOf(name, config), env);
98
+ return { name, dir: s.dir, items: [...s.dirs, ...s.files].filter((item) => ownCopy(join(s.dir, item))) };
99
+ });
100
+ }
101
+ /** Print what linking did: one line, or every item with `verbose`. */
102
+ function reportLinks(name, label, dir, hub, results, aside, io, verbose, brief = false) {
103
+ const env = io.env;
104
+ const dirs = results.length;
105
+ const st = style(io);
106
+ const more = verbose || !dirs ? "" : st.muted(" (-v lists them)");
107
+ io.out(st.wrap(`${st.accent("▸")} `, `${st.bold(name)}${label} → ${tildify(dir, env)}: shares ${plural(dirs, "item")} with ${tildify(hub, env)}${more}`));
108
+ if (verbose)
109
+ for (const [item, r] of results)
110
+ io.out(` ${r === "same" ? st.muted("=") : st.accent("↔")} ${item}`);
111
+ const moved = results.filter(([, r]) => r === "aside").map(([item]) => item);
112
+ if (moved.length) {
113
+ const it = moved.length === 1 ? "it" : "them";
114
+ const text = brief
115
+ ? `moved ${moved.join(", ")} aside ${st.muted(`(turno undo puts ${it} back)`)}`
116
+ : `moved your own ${moved.join(", ")} to ${tildify(aside, env)}/ ${st.muted("(merge by hand if useful; turno undo puts them back)")}`;
117
+ io.out(st.wrap(` ${st.warn("!")} `, text));
151
118
  }
152
- for (const item of a.sharedFiles) {
153
- if (existsSync(join(hub, item)))
154
- linkItem(dir, item, aside, io, hub);
119
+ }
120
+ /**
121
+ * Set up one profile: its folder (0700), the hub links, the agent's own steps (ADR 0032) and
122
+ * its launcher. Local copies of shared items move to .aside-<stamp>/.
123
+ */
124
+ function setupProfile(name, agent, io, verbose, journal, config, brief = false) {
125
+ const a = adapter(agent);
126
+ const step = {
127
+ name,
128
+ dir: agentProfileDir(name, agent, io.env),
129
+ hub: agentHub(agent, io.env),
130
+ env: io.env,
131
+ journal,
132
+ out: (line) => io.out(line),
133
+ writeOwn: (file, text) => writeOwn(file, text, journal),
134
+ busy: () => profileBusy(name, io.env, config),
135
+ };
136
+ a.setup?.before?.(step);
137
+ const s = sharedItems(name, agent, io.env);
138
+ const aside = join(s.dir, `.aside-${stamp()}`);
139
+ profileFolder(s.dir, journal);
140
+ const results = [];
141
+ const held = [];
142
+ for (const item of s.dirs) {
143
+ const why = a.setup?.hold?.(item, step);
144
+ if (why) {
145
+ held.push(why);
146
+ continue;
147
+ }
148
+ mkdirSync(join(s.hub, item), { recursive: true });
149
+ results.push([item, linkItem(s.dir, item, aside, journal, s.hub)]);
155
150
  }
156
- if (agent === "codex")
157
- prepareCodex(dir, io);
158
- writeLauncher(name, io.env, agent);
159
- io.out(` + command ${launcherName(name, agent)}`);
151
+ for (const item of s.files)
152
+ results.push([item, linkItem(s.dir, item, aside, journal, s.hub)]);
153
+ reportLinks(name, agent === DEFAULT_AGENT ? "" : ` (${a.label})`, s.dir, s.hub, results, aside, io, verbose, brief);
154
+ const st = style(io);
155
+ for (const why of held)
156
+ io.out(st.wrap(` ${st.warn("!")} `, why));
157
+ a.setup?.after?.(step);
158
+ writeLauncher(name, io.env, agent, journal);
159
+ io.out(` ${st.ok("+")} command ${st.bold(launcherName(name, agent))}`);
160
160
  }
161
161
  export function setupProfiles(names, io, opts = {}) {
162
162
  if (names.length === 0)
163
- fail("usage: turno setup <profile>...");
163
+ fail("usage: turno profile repair <profile>...");
164
164
  for (const name of names)
165
165
  checkName(name);
166
- const p = paths(io.env);
166
+ // Launchers keep the path of this turno; a path into npx's cache disappears.
167
+ if (opts.turno === undefined)
168
+ refuseNpx();
169
+ const turno = opts.turno !== undefined ? { words: opts.turno } : resolveTurnoCommand(io.env);
170
+ const verbose = Boolean(opts.verbose);
167
171
  const config = loadConfig(io.env);
168
- for (const name of names) {
169
- const agent = agentOf(name, config);
170
- if (agent !== "claude") {
171
- setupAgentProfile(name, agent, io);
172
- continue;
173
- }
174
- if (!existsSync(p.hub)) {
175
- // Claude Code creates it on first run; profiles need it now to link the shared folders.
176
- mkdirSync(p.hub, { recursive: true, mode: 0o700 });
177
- io.out(` + created ${tildify(p.hub, io.env)} (the folder every Claude Code profile shares)`);
178
- }
179
- const dir = profileDir(name, io.env);
180
- const aside = join(dir, `.aside-${stamp()}`);
181
- io.out(`▸ ${name} → ${tildify(dir, io.env)}`);
182
- mkdirSync(dir, { recursive: true });
183
- chmodSync(dir, 0o700);
184
- for (const item of SHARED_DIRS) {
185
- if (item === "sessions" && !lstat(join(dir, item))?.isSymbolicLink() && profileBusy(name, io.env, config)) {
186
- io.out(" ! sessions: this profile has open sessions; close them and run setup again");
187
- continue;
188
- }
189
- mkdirSync(join(p.hub, item), { recursive: true });
190
- linkItem(dir, item, aside, io);
191
- }
192
- for (const item of SHARED_FILES) {
193
- if (existsSync(join(p.hub, item)))
194
- linkItem(dir, item, aside, io);
195
- }
196
- seedGlobalConfig(dir, io);
197
- const history = join(dir, "history.jsonl");
198
- const hubHistory = join(p.hub, "history.jsonl");
199
- if (!existsSync(history) && lstat(hubHistory)?.isFile()) {
200
- copyFileSync(hubHistory, history);
201
- chmodSync(history, 0o600);
202
- io.out(" + history.jsonl (initial copy; the ↑ history cannot be shared)");
203
- }
204
- writeLauncher(name, io.env, "claude");
205
- io.out(` + command claude-${name}`);
172
+ const journal = opts.journal ?? new Journal(io.env, `profile repair ${names.join(" ")}`);
173
+ for (const name of names)
174
+ setupProfile(name, agentOf(name, config), io, verbose, journal, config, Boolean(opts.brief));
175
+ const written = writeHelperLaunchers(io.env, turno.words, journal);
176
+ if (verbose)
177
+ for (const w of written)
178
+ io.out(`+ command ${w}`);
179
+ if (turno.warning)
180
+ io.out(`! turno-auto and turno-open: ${turno.warning}`);
181
+ if (!opts.journal) {
182
+ const hint = journal.hint();
183
+ if (hint)
184
+ io.out(hint);
206
185
  }
207
- for (const written of writeHelperLaunchers(io.env, opts.turno ?? turnoCommand()))
208
- io.out(`+ command ${written}`);
209
186
  }
210
187
  export const command = {
211
188
  summary: "create or repair ~/.claude-<profile> and its claude-<profile> command",
189
+ hidden: true,
212
190
  usage: [
213
- "Usage: turno setup <profile>...",
191
+ "Usage: turno profile repair <profile>...",
214
192
  "",
215
193
  "Links the shared hub folders and files into the profile (local copies are moved",
216
194
  "to .aside-<timestamp>/), seeds .claude.json and history.jsonl, and writes the",