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,8 +1,10 @@
1
- import { mkdirSync, readFileSync, realpathSync, renameSync, writeFileSync } from "node:fs";
1
+ import { chmodSync, readFileSync, renameSync, writeFileSync } from "node:fs";
2
2
  import { dirname, resolve, sep } from "node:path";
3
3
  import { parse, stringify } from "smol-toml";
4
4
  import { ConfigError, isValidProfileName } from "../core/config.js";
5
- import { expandHome, paths, tildify } from "../core/paths.js";
5
+ import { PRIVATE_FILE_MODE, ensurePrivateDir, expandHome, paths, tildify } from "../core/paths.js";
6
+ import { CONFIRM_POLICIES, isConfirmPolicy, patternCovers } from "./policy.js";
7
+ import { realOr } from "../core/fsutil.js";
6
8
  const ACCOUNT_ID = /^([a-z0-9][a-z0-9_-]*):([A-Za-z0-9][A-Za-z0-9_.@-]*)$/;
7
9
  const SERVICE = /^[a-z0-9][a-z0-9_-]*$/;
8
10
  /** Split and validate an account id (`service:label`); undefined when malformed. */
@@ -27,6 +29,16 @@ function optStr(v, file, key) {
27
29
  throw new ConfigError(file, `${key} must be a string`);
28
30
  return v;
29
31
  }
32
+ function toolList(v, file, key) {
33
+ if (!Array.isArray(v) || v.length === 0)
34
+ throw new ConfigError(file, `${key} must be a non-empty array of tool patterns`);
35
+ for (const t of v) {
36
+ if (typeof t !== "string" || !t.trim() || /\s/.test(t)) {
37
+ throw new ConfigError(file, `${key}: invalid tool pattern ${JSON.stringify(t)}`);
38
+ }
39
+ }
40
+ return [...v];
41
+ }
30
42
  /** Validate one account definition; shared by the parser and `turno accounts add`. */
31
43
  export function makeAccount(id, fields, file = "accounts.toml") {
32
44
  const key = `account."${id}"`;
@@ -41,20 +53,27 @@ export function makeAccount(id, fields, file = "accounts.toml") {
41
53
  throw new ConfigError(file, `${key} needs profile`);
42
54
  if (!isValidProfileName(fields.profile))
43
55
  throw new ConfigError(file, `${key}.profile: invalid profile name "${fields.profile}"`);
44
- const tools = fields.tools;
45
- if (!Array.isArray(tools) || tools.length === 0)
46
- throw new ConfigError(file, `${key}.tools must be a non-empty array of tool patterns`);
47
- for (const t of tools) {
48
- if (typeof t !== "string" || !t.trim() || /\s/.test(t)) {
49
- throw new ConfigError(file, `${key}.tools: invalid tool pattern ${JSON.stringify(t)}`);
56
+ const tools = toolList(fields.tools, file, `${key}.tools`);
57
+ let readTools;
58
+ if (fields.readTools !== undefined) {
59
+ readTools = toolList(fields.readTools, file, `${key}.read_tools`);
60
+ for (const r of readTools) {
61
+ if (!tools.some((t) => patternCovers(t, r))) {
62
+ throw new ConfigError(file, `${key}.read_tools: "${r}" is not covered by the account's tools (${tools.join(", ")})`);
63
+ }
50
64
  }
51
65
  }
66
+ if (fields.confirm !== undefined && !isConfirmPolicy(fields.confirm)) {
67
+ throw new ConfigError(file, `${key}.confirm must be ${CONFIRM_POLICIES.map((c) => `"${c}"`).join(", ").replace(/, ([^,]*)$/, " or $1")}`);
68
+ }
52
69
  return {
53
70
  id,
54
71
  service,
55
72
  label: parsed.label,
56
73
  profile: fields.profile,
57
- tools: [...tools],
74
+ tools,
75
+ ...(readTools ? { readTools } : {}),
76
+ ...(fields.confirm !== undefined ? { confirm: fields.confirm } : {}),
58
77
  ...(fields.description ? { description: fields.description } : {}),
59
78
  };
60
79
  }
@@ -76,6 +95,8 @@ export function parseRegistry(text, file = "accounts.toml", env = process.env) {
76
95
  ...(service !== undefined ? { service } : {}),
77
96
  ...(profile !== undefined ? { profile } : {}),
78
97
  tools: v.tools,
98
+ ...(v.read_tools !== undefined ? { readTools: v.read_tools } : {}),
99
+ ...(v.confirm !== undefined ? { confirm: v.confirm } : {}),
79
100
  ...(description !== undefined ? { description } : {}),
80
101
  }, file);
81
102
  }
@@ -127,6 +148,8 @@ export function formatRegistry(reg, env = process.env) {
127
148
  service: a.service,
128
149
  profile: a.profile,
129
150
  tools: a.tools,
151
+ ...(a.readTools ? { read_tools: a.readTools } : {}),
152
+ ...(a.confirm ? { confirm: a.confirm } : {}),
130
153
  ...(a.description ? { description: a.description } : {}),
131
154
  };
132
155
  }
@@ -145,9 +168,10 @@ export function saveRegistry(reg, env = process.env, journal) {
145
168
  journal.write(file, formatRegistry(reg, env));
146
169
  return file;
147
170
  }
148
- mkdirSync(dirname(file), { recursive: true });
171
+ ensurePrivateDir(dirname(file), env);
149
172
  const tmp = `${file}.${process.pid}.tmp`;
150
- writeFileSync(tmp, formatRegistry(reg, env));
173
+ writeFileSync(tmp, formatRegistry(reg, env), { mode: PRIVATE_FILE_MODE });
174
+ chmodSync(tmp, PRIVATE_FILE_MODE);
151
175
  renameSync(tmp, file);
152
176
  return file;
153
177
  }
@@ -155,14 +179,6 @@ function normalize(p) {
155
179
  const r = resolve(p);
156
180
  return r.length > 1 && r.endsWith(sep) ? r.slice(0, -1) : r;
157
181
  }
158
- function real(p) {
159
- try {
160
- return realpathSync(p);
161
- }
162
- catch {
163
- return p;
164
- }
165
- }
166
182
  function within(dir, root) {
167
183
  return dir === root || root === sep || dir.startsWith(root + sep);
168
184
  }
@@ -171,10 +187,10 @@ function within(dir, root) {
171
187
  * matching path wins. Both the folder and the rule paths are also compared through symlinks.
172
188
  */
173
189
  export function preferredFor(reg, cwd) {
174
- const dirs = [...new Set([normalize(cwd), normalize(real(cwd))])];
190
+ const dirs = [...new Set([normalize(cwd), normalize(realOr(cwd))])];
175
191
  const best = {};
176
192
  for (const rule of reg.prefer) {
177
- const roots = [...new Set([rule.path, normalize(real(rule.path))])];
193
+ const roots = [...new Set([rule.path, normalize(realOr(rule.path))])];
178
194
  const match = roots.filter((r) => dirs.some((d) => within(d, r))).map((r) => r.length);
179
195
  if (!match.length)
180
196
  continue;
@@ -0,0 +1,7 @@
1
+ export const JSON_MCP_SERVERS = { format: "json", key: "mcpServers" };
2
+ export const TOML_MCP_SERVERS = { format: "toml", key: "mcp_servers" };
3
+ /** The gateway URL of one server, the same for every agent. */
4
+ export function gatewayUrl(name, port) {
5
+ return `http://127.0.0.1:${port}/mcp/${encodeURIComponent(name)}`;
6
+ }
7
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1,195 @@
1
+ import { chmodSync, copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { paths, tildify } from "../core/paths.js";
4
+ import { plural } from "../cli/io.js";
5
+ import { JSON_MCP_SERVERS, gatewayUrl } from "./adapter.js";
6
+ import { isObject, readJsonFile } from "../core/fsutil.js";
7
+ /**
8
+ * Hub folders shared by every Claude Code profile. Launchers recreate them, so a cleanup that
9
+ * removed an empty hub folder never leaves a profile with a dangling symlink.
10
+ */
11
+ export const SHARED_DIRS = [
12
+ "projects",
13
+ "file-history",
14
+ "plans",
15
+ "tasks",
16
+ "paste-cache",
17
+ "session-env",
18
+ "uploads",
19
+ "dev-mods",
20
+ "sessions",
21
+ "skills",
22
+ "commands",
23
+ "agents",
24
+ "hooks",
25
+ "plugins",
26
+ "output-styles",
27
+ "workflows",
28
+ "agent-memory",
29
+ "rules",
30
+ "themes",
31
+ "state",
32
+ "usage-data",
33
+ "cache",
34
+ ];
35
+ /** Hub files shared by every profile (linked only when they exist in the hub). */
36
+ const SHARED_FILES = ["CLAUDE.md", "settings.json", "keybindings.json", "statusline-command.sh", ".mcp.json"];
37
+ /**
38
+ * Owned by each account and never linked. history.jsonl cannot be a symlink: Claude Code
39
+ * ignores it unless it is a regular file with a single link.
40
+ */
41
+ const PER_ACCOUNT = [
42
+ ".claude.json",
43
+ ".credentials.json",
44
+ "history.jsonl",
45
+ "backups",
46
+ "daemon",
47
+ "daemon.log",
48
+ "daemon-auth-cooldown",
49
+ "daemon-auth-status.json",
50
+ "daemon.lock",
51
+ "daemon.status.json",
52
+ "feedback",
53
+ "jobs",
54
+ "policy-limits.json",
55
+ "policy-limits.json.stamp.json",
56
+ "policy-limits.json.signature.json",
57
+ "remote-settings.json",
58
+ "remote-settings.json.signature.json",
59
+ "remote-settings.json.synced-at",
60
+ "mcp-needs-auth-cache.json",
61
+ "stats-cache.json",
62
+ "telemetry",
63
+ "shell-snapshots",
64
+ "debug",
65
+ ".last-cleanup",
66
+ ".last-update-result.json",
67
+ "computer-use.lock",
68
+ ];
69
+ /**
70
+ * Headers every Claude Code gateway entry carries. The PID and folder are expanded by Claude
71
+ * Code from the launcher's environment. The folder travels base64url-encoded: a raw path outside
72
+ * Latin-1 (accents in NFD form, CJK, emoji) is an invalid header value and the client would
73
+ * refuse to connect. Without the variable (a plain `claude`), mcpd reads the folder of the
74
+ * client process.
75
+ */
76
+ export function gatewayEntry(name, port, token, profile) {
77
+ return {
78
+ type: "http",
79
+ url: gatewayUrl(name, port),
80
+ headers: {
81
+ Authorization: `Bearer ${token}`,
82
+ "X-Turno-Profile": profile,
83
+ "X-Turno-Pid": "${TURNO_SESSION_PID:-0}",
84
+ "X-Turno-Cwd-B64": "${TURNO_SESSION_CWD_B64:-}",
85
+ },
86
+ };
87
+ }
88
+ const SEED_KEYS = ["mcpServers", "projects", "hasCompletedOnboarding", "lastOnboardingVersion", "theme"];
89
+ /** First .claude.json of a profile: user MCP servers and per-project state, never the account. */
90
+ function seedGlobalConfig(s) {
91
+ const dst = join(s.dir, ".claude.json");
92
+ if (existsSync(dst)) {
93
+ s.out(" = .claude.json already exists (turno mcp sync brings in new MCP servers)");
94
+ return;
95
+ }
96
+ const src = paths(s.env).hubConfig;
97
+ const hub = readJsonFile(src);
98
+ if (!isObject(hub))
99
+ return;
100
+ const seed = {};
101
+ for (const k of SEED_KEYS)
102
+ if (k in hub)
103
+ seed[k] = hub[k];
104
+ s.writeOwn(dst, `${JSON.stringify(seed, null, 2)}\n`);
105
+ const count = (v) => (v && typeof v === "object" ? Object.keys(v).length : 0);
106
+ s.out(` + .claude.json with ${plural(count(seed.mcpServers), "MCP server")} and ${plural(count(seed.projects), "project")} from the hub`);
107
+ }
108
+ /** The ↑ history starts as a copy of the hub's: it cannot be shared (see PER_ACCOUNT). */
109
+ function copyHistory(s) {
110
+ const history = join(s.dir, "history.jsonl");
111
+ const hubHistory = join(s.hub, "history.jsonl");
112
+ if (existsSync(history) || !isFile(hubHistory))
113
+ return;
114
+ s.journal.save(history);
115
+ copyFileSync(hubHistory, history);
116
+ chmodSync(history, 0o600);
117
+ s.journal.settle(history);
118
+ s.out(" + history.jsonl (initial copy; the ↑ history cannot be shared)");
119
+ }
120
+ function isFile(path) {
121
+ try {
122
+ return lstatSync(path).isFile();
123
+ }
124
+ catch {
125
+ return false;
126
+ }
127
+ }
128
+ function isSymlink(path) {
129
+ try {
130
+ return lstatSync(path).isSymbolicLink();
131
+ }
132
+ catch {
133
+ return false;
134
+ }
135
+ }
136
+ /** The `projects` of a Claude Code config: per-folder state, MCP servers among it. */
137
+ function projectsOf(file) {
138
+ try {
139
+ const v = JSON.parse(readFileSync(file, "utf8"));
140
+ return v.projects && typeof v.projects === "object" && !Array.isArray(v.projects) ? Object.keys(v.projects) : [];
141
+ }
142
+ catch {
143
+ return [];
144
+ }
145
+ }
146
+ export const claude = {
147
+ id: "claude",
148
+ label: "Claude Code",
149
+ command: "claude",
150
+ homeEnv: "CLAUDE_CONFIG_DIR",
151
+ dirPrefix: ".claude-",
152
+ launcherPrefix: "claude-",
153
+ install: "https://docs.claude.com/claude-code",
154
+ hub: (env) => paths(env).hub,
155
+ homeMarkers: [".claude.json", ".credentials.json", "settings.json", "projects", "history.jsonl"],
156
+ sharedDirs: SHARED_DIRS,
157
+ sharedFiles: SHARED_FILES,
158
+ perAccount: { items: PER_ACCOUNT, ignore: /^(\.aside-|\.aparte-|\.claude\.json\.|history\.jsonl\.)/ },
159
+ launcherEnv: {},
160
+ classicLauncher: true,
161
+ tokenFromEnv: false,
162
+ accountDetails: true,
163
+ mcp: {
164
+ store: JSON_MCP_SERVERS,
165
+ file: (dir) => join(dir, ".claude.json"),
166
+ shared: false,
167
+ hubFile: (env) => paths(env).hubConfig,
168
+ folderFile: ".mcp.json",
169
+ projectServers: (config) => Object.entries(config.projects ?? {}).map(([dir, proj]) => [dir, proj?.mcpServers]),
170
+ foldersUsed: projectsOf,
171
+ directRemote: true,
172
+ gatewayEntry,
173
+ },
174
+ setup: {
175
+ before(s) {
176
+ if (existsSync(s.hub))
177
+ return;
178
+ // Claude Code creates it on first run; profiles need it now to link the shared folders.
179
+ mkdirSync(s.hub, { recursive: true, mode: 0o700 });
180
+ s.out(` + created ${tildify(s.hub, s.env)} (the folder every Claude Code profile shares)`);
181
+ },
182
+ hold(item, s) {
183
+ // Claude Code keeps live session files there: replacing the folder under an open session loses them.
184
+ if (item === "sessions" && !isSymlink(join(s.dir, item)) && s.busy()) {
185
+ return "sessions: this profile has open sessions; close them and run turno profile repair again";
186
+ }
187
+ return undefined;
188
+ },
189
+ after(s) {
190
+ seedGlobalConfig(s);
191
+ copyHistory(s);
192
+ },
193
+ },
194
+ };
195
+ //# sourceMappingURL=claude.js.map
@@ -0,0 +1,98 @@
1
+ import { chmodSync, existsSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { parse as parseToml } from "smol-toml";
4
+ import { paths } from "../core/paths.js";
5
+ import { setValue } from "../core/toml-edit.js";
6
+ import { TOML_MCP_SERVERS, gatewayUrl } from "./adapter.js";
7
+ /** A Codex `[mcp_servers.<name>]` table in Claude Code's shape. */
8
+ function fromCodex(e) {
9
+ if (typeof e.command === "string") {
10
+ const env = { ...(e.env ?? {}) };
11
+ for (const v of e.env_vars ?? [])
12
+ if (typeof v === "string")
13
+ env[v] = `\${${v}}`;
14
+ return {
15
+ type: "stdio",
16
+ command: e.command,
17
+ args: e.args ?? [],
18
+ ...(Object.keys(env).length ? { env } : {}),
19
+ ...(typeof e.cwd === "string" ? { cwd: e.cwd } : {}),
20
+ };
21
+ }
22
+ const headers = { ...(e.http_headers ?? {}) };
23
+ for (const [h, v] of Object.entries(e.env_http_headers ?? {}))
24
+ headers[h] = `\${${v}}`;
25
+ if (typeof e.bearer_token_env_var === "string")
26
+ headers.Authorization = `Bearer \${${e.bearer_token_env_var}}`;
27
+ return { type: "http", url: e.url, ...(Object.keys(headers).length ? { headers } : {}) };
28
+ }
29
+ /**
30
+ * Codex profiles: seed config.toml from the hub once, and always store the login in the
31
+ * profile (`cli_auth_credentials_store = "file"`), so each CODEX_HOME has its own account.
32
+ */
33
+ function prepareConfig(s) {
34
+ const file = join(s.dir, "config.toml");
35
+ let text = "";
36
+ if (existsSync(file))
37
+ text = readFileSync(file, "utf8");
38
+ else {
39
+ const hubFile = join(s.hub, "config.toml");
40
+ if (existsSync(hubFile)) {
41
+ text = readFileSync(hubFile, "utf8");
42
+ s.out(" + config.toml from ~/.codex (the login is not copied)");
43
+ }
44
+ }
45
+ const next = setValue(text, undefined, "cli_auth_credentials_store", "file");
46
+ if (next !== text || !existsSync(file)) {
47
+ s.writeOwn(file, next);
48
+ s.out(' + cli_auth_credentials_store = "file" (the login stays in this profile)');
49
+ }
50
+ chmodSync(file, 0o600);
51
+ }
52
+ export const codex = {
53
+ id: "codex",
54
+ label: "Codex CLI",
55
+ command: "codex",
56
+ homeEnv: "CODEX_HOME",
57
+ dirPrefix: ".codex-",
58
+ launcherPrefix: "codex-",
59
+ install: "npm install --global @openai/codex",
60
+ loginSubcommand: "login",
61
+ hub: (env) => join(paths(env).home, ".codex"),
62
+ homeMarkers: ["config.toml", "auth.json", "sessions", "history.jsonl"],
63
+ // Rollouts in sessions/ let `codex resume <id>` continue a session with another account
64
+ // (not verified across ChatGPT accounts yet; ADR 0013).
65
+ sharedDirs: ["sessions", "prompts", "skills"],
66
+ sharedFiles: ["AGENTS.md"],
67
+ launcherEnv: {},
68
+ classicLauncher: false,
69
+ tokenFromEnv: true,
70
+ accountDetails: false,
71
+ mcp: {
72
+ store: TOML_MCP_SERVERS,
73
+ file: (dir) => join(dir, "config.toml"),
74
+ shared: false,
75
+ hubFile: (env) => join(codex.hub(env), "config.toml"),
76
+ toImport: fromCodex,
77
+ directRemote: false,
78
+ // The token and the session PID come from the launcher's environment, never the file.
79
+ gatewayEntry: (name, port, _token, profile) => ({
80
+ url: gatewayUrl(name, port),
81
+ bearer_token_env_var: "TURNO_MCPD_TOKEN",
82
+ http_headers: { "X-Turno-Profile": profile },
83
+ env_http_headers: { "X-Turno-Pid": "TURNO_SESSION_PID", "X-Turno-Cwd-B64": "TURNO_SESSION_CWD_B64" },
84
+ }),
85
+ },
86
+ setup: { after: prepareConfig },
87
+ doctorWarnings(dir) {
88
+ let store;
89
+ try {
90
+ store = parseToml(readFileSync(join(dir, "config.toml"), "utf8")).cli_auth_credentials_store;
91
+ }
92
+ catch {
93
+ store = undefined;
94
+ }
95
+ return store === "file" ? [] : ['Codex may keep the login in the shared Keychain (cli_auth_credentials_store is not "file")'];
96
+ },
97
+ };
98
+ //# sourceMappingURL=codex.js.map
@@ -0,0 +1,39 @@
1
+ import { join } from "node:path";
2
+ import { paths } from "../core/paths.js";
3
+ import { JSON_MCP_SERVERS, gatewayUrl } from "./adapter.js";
4
+ export const copilot = {
5
+ id: "copilot",
6
+ label: "GitHub Copilot CLI",
7
+ command: "copilot",
8
+ homeEnv: "COPILOT_HOME",
9
+ dirPrefix: ".copilot-",
10
+ launcherPrefix: "copilot-",
11
+ install: "npm install --global @github/copilot",
12
+ hub: (env) => join(paths(env).home, ".copilot"),
13
+ homeMarkers: ["config.json", "mcp-config.json", "session-state"],
14
+ sharedDirs: ["session-state"],
15
+ sharedFiles: [],
16
+ launcherEnv: {},
17
+ classicLauncher: false,
18
+ tokenFromEnv: true,
19
+ accountDetails: false,
20
+ mcp: {
21
+ store: JSON_MCP_SERVERS,
22
+ file: (dir) => join(dir, "mcp-config.json"),
23
+ shared: false,
24
+ hubFile: (env) => join(copilot.hub(env), "mcp-config.json"),
25
+ directRemote: false,
26
+ // `${VAR}` expansion in Copilot's headers is from its documentation, not verified (ADR 0013).
27
+ gatewayEntry: (name, port, _token, profile) => ({
28
+ type: "http",
29
+ url: gatewayUrl(name, port),
30
+ headers: {
31
+ Authorization: "Bearer ${TURNO_MCPD_TOKEN}",
32
+ "X-Turno-Profile": profile,
33
+ "X-Turno-Pid": "${TURNO_SESSION_PID}",
34
+ },
35
+ tools: ["*"],
36
+ }),
37
+ },
38
+ };
39
+ //# sourceMappingURL=copilot.js.map
@@ -0,0 +1,41 @@
1
+ import { join } from "node:path";
2
+ import { paths } from "../core/paths.js";
3
+ import { JSON_MCP_SERVERS, gatewayUrl } from "./adapter.js";
4
+ export const cursor = {
5
+ id: "cursor",
6
+ label: "Cursor CLI",
7
+ command: "cursor-agent",
8
+ homeEnv: "CURSOR_CONFIG_DIR",
9
+ dirPrefix: ".cursor-",
10
+ launcherPrefix: "cursor-agent-",
11
+ install: "curl https://cursor.com/install -fsS | bash",
12
+ loginSubcommand: "login",
13
+ hub: (env) => join(paths(env).home, ".cursor"),
14
+ homeMarkers: ["cli-config.json", "mcp.json"],
15
+ sharedDirs: [],
16
+ sharedFiles: [],
17
+ // Without it every config dir shares the Keychain login (verified 2026-11-13, undocumented).
18
+ launcherEnv: { AGENT_CLI_CREDENTIAL_STORE: "file" },
19
+ classicLauncher: false,
20
+ tokenFromEnv: true,
21
+ accountDetails: false,
22
+ mcp: {
23
+ store: JSON_MCP_SERVERS,
24
+ // CURSOR_CONFIG_DIR does not move mcp.json: every profile shares the hub's.
25
+ file: (_dir, env) => join(cursor.hub(env), "mcp.json"),
26
+ shared: true,
27
+ hubFile: (env) => join(cursor.hub(env), "mcp.json"),
28
+ directRemote: false,
29
+ // One file for every profile, so even the profile comes from the launcher's environment.
30
+ gatewayEntry: (name, port) => ({
31
+ url: gatewayUrl(name, port),
32
+ headers: {
33
+ Authorization: "Bearer ${env:TURNO_MCPD_TOKEN}",
34
+ "X-Turno-Profile": "${env:TURNO_PROFILE}",
35
+ "X-Turno-Pid": "${env:TURNO_SESSION_PID}",
36
+ },
37
+ }),
38
+ afterSync: (added) => ` Cursor asks to approve new servers once: cursor-agent mcp enable <name> (${added.join(", ")})`,
39
+ },
40
+ };
41
+ //# sourceMappingURL=cursor.js.map
@@ -1,101 +1,41 @@
1
1
  import { join } from "node:path";
2
2
  import { paths } from "../core/paths.js";
3
- /** The coding agents turno manages profiles for (ADR 0013). */
3
+ import { claude } from "./claude.js";
4
+ import { codex } from "./codex.js";
5
+ import { copilot } from "./copilot.js";
6
+ import { cursor } from "./cursor.js";
7
+ /**
8
+ * The registry of coding agents turno manages profiles for (ADR 0013, ADR 0032). Adding an
9
+ * agent is one adapter file next to this one plus its entries here.
10
+ */
4
11
  export const AGENT_IDS = ["claude", "codex", "copilot", "cursor"];
12
+ const ADAPTERS = { claude, codex, copilot, cursor };
13
+ /**
14
+ * The agent of a profile without `agent =`. It also owns the top-level `default`, `fallback`
15
+ * and `system` of config.toml, and messages leave its name out.
16
+ */
17
+ export const DEFAULT_AGENT = "claude";
18
+ /**
19
+ * The order turno reads agent configs in: `turno mcp import` (the first source wins a name) and
20
+ * `turno doctor --security`.
21
+ */
22
+ export const SCAN_ORDER = ["claude", "codex", "cursor", "copilot"];
5
23
  export function isAgentId(v) {
6
24
  return typeof v === "string" && AGENT_IDS.includes(v);
7
25
  }
8
- const CLAUDE = {
9
- id: "claude",
10
- label: "Claude Code",
11
- command: "claude",
12
- homeEnv: "CLAUDE_CONFIG_DIR",
13
- dirPrefix: ".claude-",
14
- launcherPrefix: "claude-",
15
- // The Claude Code lists live in cli/launchers.ts (SHARED_DIRS) and setup.ts (SHARED_FILES).
16
- sharedDirs: [],
17
- sharedFiles: [],
18
- launcherEnv: [],
19
- tokenFromEnv: false,
20
- mcp: "claude",
21
- sharedMcpFile: false,
22
- install: "https://docs.claude.com/claude-code",
23
- };
24
- const CODEX = {
25
- id: "codex",
26
- label: "Codex CLI",
27
- command: "codex",
28
- homeEnv: "CODEX_HOME",
29
- dirPrefix: ".codex-",
30
- launcherPrefix: "codex-",
31
- // Rollouts in sessions/ let `codex resume <id>` continue a session with another account
32
- // (not verified across ChatGPT accounts yet; ADR 0013).
33
- sharedDirs: ["sessions", "prompts", "skills"],
34
- sharedFiles: ["AGENTS.md"],
35
- launcherEnv: [],
36
- tokenFromEnv: true,
37
- mcp: "codex",
38
- sharedMcpFile: false,
39
- install: "npm install --global @openai/codex",
40
- };
41
- const COPILOT = {
42
- id: "copilot",
43
- label: "GitHub Copilot CLI",
44
- command: "copilot",
45
- homeEnv: "COPILOT_HOME",
46
- dirPrefix: ".copilot-",
47
- launcherPrefix: "copilot-",
48
- sharedDirs: ["session-state"],
49
- sharedFiles: [],
50
- launcherEnv: [],
51
- tokenFromEnv: true,
52
- mcp: "copilot",
53
- sharedMcpFile: false,
54
- install: "npm install --global @github/copilot",
55
- };
56
- const CURSOR = {
57
- id: "cursor",
58
- label: "Cursor CLI",
59
- command: "cursor-agent",
60
- homeEnv: "CURSOR_CONFIG_DIR",
61
- dirPrefix: ".cursor-",
62
- launcherPrefix: "cursor-agent-",
63
- sharedDirs: [],
64
- sharedFiles: [],
65
- // Without it every config dir shares the Keychain login (verified 2026-11-13, undocumented).
66
- launcherEnv: ["export AGENT_CLI_CREDENTIAL_STORE=file"],
67
- tokenFromEnv: true,
68
- mcp: "cursor",
69
- sharedMcpFile: true,
70
- install: "curl https://cursor.com/install -fsS | bash",
71
- };
72
- const ADAPTERS = { claude: CLAUDE, codex: CODEX, copilot: COPILOT, cursor: CURSOR };
73
- export function adapter(id = "claude") {
26
+ export function adapter(id = DEFAULT_AGENT) {
74
27
  return ADAPTERS[id];
75
28
  }
76
29
  /** The agent's own home, shared by every profile of that agent: ~/.claude, ~/.codex, ... */
77
- export function agentHub(id, env = process.env) {
78
- const p = paths(env);
79
- if (id === "claude")
80
- return p.hub;
81
- return join(p.home, `.${id}`);
30
+ export function agentHub(id, env) {
31
+ return ADAPTERS[id].hub(env);
82
32
  }
83
33
  /** The profile's home: ~/.claude-<name>, ~/.codex-<name>, ... */
84
- export function agentProfileDir(name, id, env = process.env) {
85
- return join(paths(env).home, `${adapter(id).dirPrefix}${name}`);
34
+ export function agentProfileDir(name, id, env) {
35
+ return join(paths(env).home, `${ADAPTERS[id].dirPrefix}${name}`);
86
36
  }
87
37
  /** The file that holds a profile's MCP entries, or the shared one for Cursor. */
88
- export function mcpFileFor(name, id, env = process.env) {
89
- const dir = agentProfileDir(name, id, env);
90
- switch (adapter(id).mcp) {
91
- case "claude":
92
- return join(dir, ".claude.json");
93
- case "codex":
94
- return join(dir, "config.toml");
95
- case "copilot":
96
- return join(dir, "mcp-config.json");
97
- case "cursor":
98
- return join(agentHub("cursor", env), "mcp.json");
99
- }
38
+ export function mcpFileFor(name, id, env) {
39
+ return ADAPTERS[id].mcp.file(agentProfileDir(name, id, env), env);
100
40
  }
101
41
  //# sourceMappingURL=index.js.map
@@ -1,3 +1,4 @@
1
+ import { gatewayUrl } from "./adapter.js";
1
2
  /**
2
3
  * Config snippets that point agents turno does not manage at the MCP gateway (ADR 0013).
3
4
  * turno prints them; the user pastes them. The token is never printed: each snippet reads it
@@ -7,15 +8,17 @@ export const SNIPPET_AGENTS = ["opencode", "gemini", "goose", "crush", "droid",
7
8
  export function isSnippetAgent(v) {
8
9
  return SNIPPET_AGENTS.includes(v);
9
10
  }
10
- const url = (port, name) => `http://127.0.0.1:${port}/mcp/${encodeURIComponent(name)}`;
11
- const TOKEN_ENV = 'Start the agent with TURNO_MCPD_TOKEN set, e.g. in your shell profile: export TURNO_MCPD_TOKEN="$(cat ~/.local/state/turno/mcpd.token)"';
11
+ const url = (port, name) => gatewayUrl(name, port);
12
+ /** How the profile's own token (ADR 0023) reaches an agent that expands variables. */
13
+ const tokenEnv = (file) => `Start the agent with TURNO_MCPD_TOKEN set to this profile's token, e.g. in your shell profile: export TURNO_MCPD_TOKEN="$(cat ${file})"`;
12
14
  function headers(profile, token) {
13
15
  return { Authorization: `Bearer ${token}`, "X-Turno-Profile": profile };
14
16
  }
15
17
  function json(v) {
16
18
  return `${JSON.stringify(v, null, 2)}\n`;
17
19
  }
18
- export function gatewaySnippet(agent, servers, port, profile) {
20
+ export function gatewaySnippet(agent, servers, port, profile, tokenFile = `~/.local/state/turno/mcpd-tokens/${profile}.token`) {
21
+ const TOKEN_ENV = tokenEnv(tokenFile);
19
22
  const each = (f) => Object.fromEntries(servers.map((n) => [n, f(n)]));
20
23
  switch (agent) {
21
24
  case "opencode":
@@ -33,7 +36,7 @@ export function gatewaySnippet(agent, servers, port, profile) {
33
36
  case "goose": {
34
37
  const lines = ["extensions:"];
35
38
  for (const n of servers) {
36
- lines.push(` ${n}:`, ` name: ${n}`, " type: streamable_http", ` uri: ${url(port, n)}`, " enabled: true", " timeout: 300", " headers:", ' Authorization: "Bearer <paste the token from ~/.local/state/turno/mcpd.token>"', ` X-Turno-Profile: ${profile}`);
39
+ lines.push(` ${n}:`, ` name: ${n}`, " type: streamable_http", ` uri: ${url(port, n)}`, " enabled: true", " timeout: 300", " headers:", ` Authorization: "Bearer <paste the token from ${tokenFile}>"`, ` X-Turno-Profile: ${profile}`);
37
40
  }
38
41
  return {
39
42
  file: "~/.config/goose/config.yaml",