turno-cli 0.1.1 → 0.3.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 (121) hide show
  1. package/CHANGELOG.md +432 -0
  2. package/README.md +228 -73
  3. package/dist/accounts/audit.js +154 -12
  4. package/dist/accounts/builtin.js +100 -25
  5. package/dist/accounts/delegate.js +199 -35
  6. package/dist/accounts/policy.js +79 -0
  7. package/dist/accounts/registry.js +39 -21
  8. package/dist/agents/adapter.js +29 -0
  9. package/dist/agents/claude.js +246 -0
  10. package/dist/agents/codex.js +186 -0
  11. package/dist/agents/copilot.js +56 -0
  12. package/dist/agents/cursor.js +58 -0
  13. package/dist/agents/index.js +26 -86
  14. package/dist/agents/snippets.js +43 -13
  15. package/dist/cli/args.js +38 -6
  16. package/dist/cli/commands/accounts.js +119 -52
  17. package/dist/cli/commands/auto.js +121 -33
  18. package/dist/cli/commands/browser-identity.js +514 -0
  19. package/dist/cli/commands/browser-session.js +102 -0
  20. package/dist/cli/commands/browser-vault.js +193 -0
  21. package/dist/cli/commands/browser.js +319 -138
  22. package/dist/cli/commands/complete.js +14 -3
  23. package/dist/cli/commands/completion.js +8 -2
  24. package/dist/cli/commands/config.js +186 -24
  25. package/dist/cli/commands/demo.js +321 -0
  26. package/dist/cli/commands/doctor.js +525 -123
  27. package/dist/cli/commands/handoff.js +33 -22
  28. package/dist/cli/commands/identity.js +192 -54
  29. package/dist/cli/commands/init.js +648 -0
  30. package/dist/cli/commands/limit.js +84 -16
  31. package/dist/cli/commands/mcp-call.js +240 -0
  32. package/dist/cli/commands/mcp-oauth.js +221 -0
  33. package/dist/cli/commands/mcp-observe.js +539 -0
  34. package/dist/cli/commands/mcp-share.js +201 -0
  35. package/dist/cli/commands/mcp.js +816 -187
  36. package/dist/cli/commands/mcpd.js +388 -76
  37. package/dist/cli/commands/migrate.js +6 -4
  38. package/dist/cli/commands/open.js +115 -27
  39. package/dist/cli/commands/profile.js +396 -78
  40. package/dist/cli/commands/resolve.js +14 -3
  41. package/dist/cli/commands/run.js +36 -6
  42. package/dist/cli/commands/secret.js +80 -76
  43. package/dist/cli/commands/session.js +17 -6
  44. package/dist/cli/commands/sessions.js +48 -12
  45. package/dist/cli/commands/setup.js +214 -164
  46. package/dist/cli/commands/status.js +227 -44
  47. package/dist/cli/commands/statusline.js +311 -114
  48. package/dist/cli/commands/ui.js +78 -68
  49. package/dist/cli/commands/undo.js +193 -18
  50. package/dist/cli/commands/uninstall.js +481 -0
  51. package/dist/cli/commands/upgrade.js +172 -79
  52. package/dist/cli/commands/usage.js +125 -51
  53. package/dist/cli/commands/version.js +21 -7
  54. package/dist/cli/commands/which.js +9 -24
  55. package/dist/cli/compile-cache.js +32 -0
  56. package/dist/cli/diagnostics.js +184 -0
  57. package/dist/cli/exit.js +65 -0
  58. package/dist/cli/group.js +24 -12
  59. package/dist/cli/help.js +62 -0
  60. package/dist/cli/highlight.js +236 -0
  61. package/dist/cli/hints.js +30 -0
  62. package/dist/cli/io.js +186 -1
  63. package/dist/cli/launch.js +52 -39
  64. package/dist/cli/launchers.js +161 -95
  65. package/dist/cli/main.js +201 -31
  66. package/dist/cli/optional.js +144 -0
  67. package/dist/cli/output.js +123 -0
  68. package/dist/cli/picker.js +459 -0
  69. package/dist/cli/registry.js +61 -6
  70. package/dist/cli/safe.js +87 -0
  71. package/dist/cli/secret-input.js +63 -0
  72. package/dist/cli/security.js +561 -0
  73. package/dist/cli/style.js +311 -0
  74. package/dist/cli/topics.js +142 -0
  75. package/dist/core/config.js +181 -23
  76. package/dist/core/exhausted.js +6 -8
  77. package/dist/core/fsutil.js +39 -0
  78. package/dist/core/journal.js +294 -16
  79. package/dist/core/manifest.js +153 -6
  80. package/dist/core/paths.js +14 -13
  81. package/dist/core/profiles.js +160 -10
  82. package/dist/core/resolve.js +139 -23
  83. package/dist/core/secrets.js +68 -23
  84. package/dist/core/sessions.js +13 -20
  85. package/dist/core/state-file.js +107 -0
  86. package/dist/core/update.js +31 -18
  87. package/dist/core/version.js +57 -10
  88. package/dist/demo/server.js +42 -0
  89. package/dist/mcpd/cache.js +23 -10
  90. package/dist/mcpd/calllog.js +254 -0
  91. package/dist/mcpd/client-names.js +46 -0
  92. package/dist/mcpd/connectors.js +188 -18
  93. package/dist/mcpd/daemon.js +472 -115
  94. package/dist/mcpd/folder-sets.js +42 -0
  95. package/dist/mcpd/gateway.js +473 -51
  96. package/dist/mcpd/health.js +313 -0
  97. package/dist/mcpd/importer.js +453 -36
  98. package/dist/mcpd/instances.js +453 -65
  99. package/dist/mcpd/jsonrpc.js +11 -1
  100. package/dist/mcpd/launchd.js +65 -48
  101. package/dist/mcpd/middleware.js +144 -0
  102. package/dist/mcpd/modern.js +686 -0
  103. package/dist/mcpd/oauth.js +845 -0
  104. package/dist/mcpd/peerpid.js +134 -6
  105. package/dist/mcpd/pressure.js +88 -0
  106. package/dist/mcpd/rss.js +166 -0
  107. package/dist/mcpd/service.js +191 -0
  108. package/dist/mcpd/share.js +217 -0
  109. package/dist/mcpd/state.js +183 -0
  110. package/dist/mcpd/sync.js +72 -87
  111. package/dist/mcpd/systemd.js +83 -0
  112. package/dist/mcpd/tokens.js +85 -0
  113. package/dist/mcpd/upstream.js +163 -46
  114. package/dist/statusline/cost.js +167 -44
  115. package/dist/statusline/input.js +78 -0
  116. package/dist/statusline/render.js +9 -3
  117. package/dist/ui/fonts.js +8 -3
  118. package/dist/ui/settings.js +33 -16
  119. package/npm-shrinkwrap.json +1102 -0
  120. package/package.json +10 -9
  121. package/dist/cli/commands/available.js +0 -18
@@ -0,0 +1,246 @@
1
+ import { chmodSync, copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, realpathSync, writeFileSync, } 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, isGatewayEntry, } 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
+ /**
89
+ * Safe mode: `--strict-mcp-config` with a `--mcp-config` holding the profile's own servers (user
90
+ * scope, this folder's project scope and its .mcp.json) minus the gateway entries, and
91
+ * `--settings {"disableAllHooks":true}`, the documented switch that turns off a custom status
92
+ * line (and hooks). The file is private: a server's env may hold a literal secret.
93
+ */
94
+ function safeMode(s) {
95
+ const cfg = readJsonFile(s.file);
96
+ const kept = {};
97
+ const dropped = new Set();
98
+ const keep = (map) => {
99
+ if (!isObject(map))
100
+ return;
101
+ for (const [n, e] of Object.entries(map)) {
102
+ if (isGatewayEntry(e))
103
+ dropped.add(n);
104
+ else if (!(n in kept))
105
+ kept[n] = e;
106
+ }
107
+ };
108
+ let real = s.cwd;
109
+ try {
110
+ real = realpathSync(s.cwd);
111
+ }
112
+ catch {
113
+ /* keep it */
114
+ }
115
+ const projects = isObject(cfg) && isObject(cfg.projects) ? cfg.projects : {};
116
+ const project = projects[s.cwd] ?? projects[real];
117
+ keep(isObject(project) ? project.mcpServers : undefined);
118
+ const folder = readJsonFile(join(s.cwd, ".mcp.json"));
119
+ keep(isObject(folder) ? folder.mcpServers : undefined);
120
+ keep(isObject(cfg) ? cfg.mcpServers : undefined);
121
+ writeFileSync(s.scratch, `${JSON.stringify({ mcpServers: kept }, null, 2)}\n`, { mode: 0o600 });
122
+ chmodSync(s.scratch, 0o600);
123
+ const names = Object.keys(kept).sort();
124
+ return {
125
+ args: ["--strict-mcp-config", "--mcp-config", s.scratch, "--settings", JSON.stringify({ disableAllHooks: true })],
126
+ notes: [
127
+ dropped.size
128
+ ? `left out the gateway entries ${[...dropped].sort().join(", ")}`
129
+ : "no gateway entries to leave out",
130
+ `kept ${names.length ? names.join(", ") : "no other MCP servers"} (${tildify(s.scratch, s.env)}; plugin servers are skipped too)`,
131
+ "no status line and no hooks (disableAllHooks)",
132
+ ],
133
+ };
134
+ }
135
+ const SEED_KEYS = ["mcpServers", "projects", "hasCompletedOnboarding", "lastOnboardingVersion", "theme"];
136
+ /** First .claude.json of a profile: user MCP servers and per-project state, never the account. */
137
+ function seedGlobalConfig(s) {
138
+ const dst = join(s.dir, ".claude.json");
139
+ if (existsSync(dst)) {
140
+ s.out(" = .claude.json already exists (turno mcp sync brings in new MCP servers)");
141
+ return;
142
+ }
143
+ const src = paths(s.env).hubConfig;
144
+ const hub = readJsonFile(src);
145
+ if (!isObject(hub))
146
+ return;
147
+ const seed = {};
148
+ for (const k of SEED_KEYS)
149
+ if (k in hub)
150
+ seed[k] = hub[k];
151
+ s.writeOwn(dst, `${JSON.stringify(seed, null, 2)}\n`);
152
+ const count = (v) => (v && typeof v === "object" ? Object.keys(v).length : 0);
153
+ s.out(` + .claude.json with ${plural(count(seed.mcpServers), "MCP server")} and ${plural(count(seed.projects), "project")} from the hub`);
154
+ }
155
+ /** The ↑ history starts as a copy of the hub's: it cannot be shared (see PER_ACCOUNT). */
156
+ function copyHistory(s) {
157
+ const history = join(s.dir, "history.jsonl");
158
+ const hubHistory = join(s.hub, "history.jsonl");
159
+ if (existsSync(history) || !isFile(hubHistory))
160
+ return;
161
+ s.journal.save(history);
162
+ copyFileSync(hubHistory, history);
163
+ chmodSync(history, 0o600);
164
+ s.journal.settle(history);
165
+ s.out(" + history.jsonl (initial copy; the ↑ history cannot be shared)");
166
+ }
167
+ function isFile(path) {
168
+ try {
169
+ return lstatSync(path).isFile();
170
+ }
171
+ catch {
172
+ return false;
173
+ }
174
+ }
175
+ function isSymlink(path) {
176
+ try {
177
+ return lstatSync(path).isSymbolicLink();
178
+ }
179
+ catch {
180
+ return false;
181
+ }
182
+ }
183
+ /** The `projects` of a Claude Code config: per-folder state, MCP servers among it. */
184
+ function projectsOf(file) {
185
+ try {
186
+ const v = JSON.parse(readFileSync(file, "utf8"));
187
+ return v.projects && typeof v.projects === "object" && !Array.isArray(v.projects) ? Object.keys(v.projects) : [];
188
+ }
189
+ catch {
190
+ return [];
191
+ }
192
+ }
193
+ export const claude = {
194
+ id: "claude",
195
+ label: "Claude Code",
196
+ command: "claude",
197
+ homeEnv: "CLAUDE_CONFIG_DIR",
198
+ dirPrefix: ".claude-",
199
+ launcherPrefix: "claude-",
200
+ install: "https://docs.claude.com/claude-code",
201
+ hub: (env) => paths(env).hub,
202
+ homeMarkers: [".claude.json", ".credentials.json", "settings.json", "projects", "history.jsonl"],
203
+ sharedDirs: SHARED_DIRS,
204
+ sharedFiles: SHARED_FILES,
205
+ perAccount: { items: PER_ACCOUNT, ignore: /^(\.aside-|\.aparte-|\.claude\.json\.|history\.jsonl\.)/ },
206
+ launcherEnv: {},
207
+ classicLauncher: true,
208
+ tokenFromEnv: false,
209
+ accountDetails: true,
210
+ mcp: {
211
+ store: JSON_MCP_SERVERS,
212
+ file: (dir) => join(dir, ".claude.json"),
213
+ shared: false,
214
+ hubFile: (env) => paths(env).hubConfig,
215
+ folderFile: ".mcp.json",
216
+ projectServers: (config) => Object.entries(config.projects ?? {}).map(([dir, proj]) => [
217
+ dir,
218
+ proj?.mcpServers,
219
+ ]),
220
+ foldersUsed: projectsOf,
221
+ directRemote: true,
222
+ gatewayEntry,
223
+ },
224
+ safeMode,
225
+ setup: {
226
+ before(s) {
227
+ if (existsSync(s.hub))
228
+ return;
229
+ // Claude Code creates it on first run; profiles need it now to link the shared folders.
230
+ mkdirSync(s.hub, { recursive: true, mode: 0o700 });
231
+ s.out(` + created ${tildify(s.hub, s.env)} (the folder every Claude Code profile shares)`);
232
+ },
233
+ hold(item, s) {
234
+ // Claude Code keeps live session files there: replacing the folder under an open session loses them.
235
+ if (item === "sessions" && !isSymlink(join(s.dir, item)) && s.busy()) {
236
+ return "sessions: this profile has open sessions; close them and run turno profile repair again";
237
+ }
238
+ return undefined;
239
+ },
240
+ after(s) {
241
+ seedGlobalConfig(s);
242
+ copyHistory(s);
243
+ },
244
+ },
245
+ };
246
+ //# sourceMappingURL=claude.js.map
@@ -0,0 +1,186 @@
1
+ import { chmodSync, existsSync, readFileSync, realpathSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { parse as parseToml } from "smol-toml";
4
+ import { paths, tildify } from "../core/paths.js";
5
+ import { setValue } from "../core/toml-edit.js";
6
+ import { TOML_MCP_SERVERS, gatewayNames, 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
+ /**
53
+ * Codex asks whether to trust a folder the first time it starts there, per CODEX_HOME, so a new
54
+ * profile asks again for folders the person already trusted. turno writes
55
+ * `[projects."<folder>"] trust_level = "trusted"` for each folder whose rule uses the profile,
56
+ * and the real path too when a symlink leads there. Codex matches the exact folder, or the git
57
+ * root of the folder it runs in (the main repository for a worktree); a rule on a parent of
58
+ * several repositories does not trust the repositories inside it. An entry already there,
59
+ * trusted or not, is never changed.
60
+ */
61
+ export function trustFolders(s) {
62
+ const file = join(s.dir, "config.toml");
63
+ if (!s.folders.length || !existsSync(s.dir))
64
+ return;
65
+ const text = existsSync(file) ? readFileSync(file, "utf8") : "";
66
+ let projects = {};
67
+ try {
68
+ const raw = parseToml(text);
69
+ if (raw.projects && typeof raw.projects === "object")
70
+ projects = raw.projects;
71
+ }
72
+ catch {
73
+ s.out(" ! config.toml does not parse; no trust entries written");
74
+ return;
75
+ }
76
+ const wanted = new Set();
77
+ for (const f of s.folders) {
78
+ wanted.add(f);
79
+ try {
80
+ wanted.add(realpathSync(f));
81
+ }
82
+ catch {
83
+ /* not there yet: the rule's path only */
84
+ }
85
+ }
86
+ let next = text;
87
+ const added = [];
88
+ for (const f of wanted) {
89
+ if (f in projects)
90
+ continue;
91
+ next = setValue(next, `projects.${JSON.stringify(f)}`, "trust_level", "trusted");
92
+ added.push(f);
93
+ }
94
+ if (!added.length)
95
+ return;
96
+ try {
97
+ const check = parseToml(next).projects ?? {};
98
+ if (added.some((f) => check[f]?.trust_level !== "trusted"))
99
+ throw new Error("trust entry not readable");
100
+ }
101
+ catch {
102
+ s.out(" ! could not write the Codex trust entries; trust the folders in Codex when it asks");
103
+ return;
104
+ }
105
+ s.writeOwn(file, next);
106
+ for (const f of added)
107
+ s.out(` + trusts ${tildify(f, s.env)} in Codex (its folder rule uses this profile)`);
108
+ }
109
+ /** Safe mode: `-c mcp_servers.<name>.enabled=false` for each gateway entry of config.toml. */
110
+ function safeMode(s) {
111
+ let cfg = {};
112
+ try {
113
+ cfg = parseToml(readFileSync(s.file, "utf8"));
114
+ }
115
+ catch {
116
+ /* no config: nothing to turn off */
117
+ }
118
+ const names = gatewayNames(cfg.mcp_servers);
119
+ // `-c` splits its key at dots, so a name with one cannot be addressed; mcpd refuses it anyway
120
+ // (safe mode leaves the token out).
121
+ const plain = names.filter((n) => /^[A-Za-z0-9_-]+$/.test(n));
122
+ const odd = names.filter((n) => !plain.includes(n));
123
+ return {
124
+ args: plain.flatMap((n) => ["-c", `mcp_servers.${n}.enabled=false`]),
125
+ notes: [
126
+ plain.length
127
+ ? `turned off the gateway entries ${plain.join(", ")} for this run`
128
+ : "no gateway entries to turn off",
129
+ ...(odd.length
130
+ ? [`${odd.join(", ")}: a name with a dot cannot be turned off for one run; without the token mcpd refuses it`]
131
+ : []),
132
+ ],
133
+ };
134
+ }
135
+ export const codex = {
136
+ id: "codex",
137
+ label: "Codex CLI",
138
+ command: "codex",
139
+ homeEnv: "CODEX_HOME",
140
+ dirPrefix: ".codex-",
141
+ launcherPrefix: "codex-",
142
+ install: "npm install --global @openai/codex",
143
+ loginSubcommand: "login",
144
+ hub: (env) => join(paths(env).home, ".codex"),
145
+ homeMarkers: ["config.toml", "auth.json", "sessions", "history.jsonl"],
146
+ // Rollouts in sessions/ let `codex resume <id>` continue a session with another account
147
+ // (not verified across ChatGPT accounts yet).
148
+ sharedDirs: ["sessions", "prompts", "skills"],
149
+ sharedFiles: ["AGENTS.md"],
150
+ launcherEnv: {},
151
+ classicLauncher: false,
152
+ tokenFromEnv: true,
153
+ accountDetails: false,
154
+ mcp: {
155
+ store: TOML_MCP_SERVERS,
156
+ file: (dir) => join(dir, "config.toml"),
157
+ shared: false,
158
+ hubFile: (env) => join(codex.hub(env), "config.toml"),
159
+ toImport: fromCodex,
160
+ directRemote: false,
161
+ // The token and the session PID come from the launcher's environment, never the file.
162
+ gatewayEntry: (name, port, _token, profile) => ({
163
+ url: gatewayUrl(name, port),
164
+ bearer_token_env_var: "TURNO_MCPD_TOKEN",
165
+ http_headers: { "X-Turno-Profile": profile },
166
+ env_http_headers: { "X-Turno-Pid": "TURNO_SESSION_PID", "X-Turno-Cwd-B64": "TURNO_SESSION_CWD_B64" },
167
+ }),
168
+ },
169
+ safeMode,
170
+ ruleFolders: trustFolders,
171
+ setup: { after: prepareConfig },
172
+ doctorWarnings(dir) {
173
+ let store;
174
+ try {
175
+ store = parseToml(readFileSync(join(dir, "config.toml"), "utf8"))
176
+ .cli_auth_credentials_store;
177
+ }
178
+ catch {
179
+ store = undefined;
180
+ }
181
+ return store === "file"
182
+ ? []
183
+ : ['Codex may keep the login in the shared Keychain (cli_auth_credentials_store is not "file")'];
184
+ },
185
+ };
186
+ //# sourceMappingURL=codex.js.map
@@ -0,0 +1,56 @@
1
+ import { join } from "node:path";
2
+ import { paths } from "../core/paths.js";
3
+ import { readJsonFile } from "../core/fsutil.js";
4
+ import { JSON_MCP_SERVERS, gatewayNames, gatewayUrl } from "./adapter.js";
5
+ export const copilot = {
6
+ id: "copilot",
7
+ label: "GitHub Copilot CLI",
8
+ command: "copilot",
9
+ homeEnv: "COPILOT_HOME",
10
+ dirPrefix: ".copilot-",
11
+ launcherPrefix: "copilot-",
12
+ install: "npm install --global @github/copilot",
13
+ hub: (env) => join(paths(env).home, ".copilot"),
14
+ homeMarkers: ["config.json", "mcp-config.json", "session-state"],
15
+ sharedDirs: ["session-state"],
16
+ sharedFiles: [],
17
+ launcherEnv: {},
18
+ classicLauncher: false,
19
+ tokenFromEnv: true,
20
+ accountDetails: false,
21
+ mcp: {
22
+ store: JSON_MCP_SERVERS,
23
+ file: (dir) => join(dir, "mcp-config.json"),
24
+ shared: false,
25
+ hubFile: (env) => join(copilot.hub(env), "mcp-config.json"),
26
+ directRemote: false,
27
+ // Copilot CLI expands `${VAR}` in a remote server's headers ("Supports variable expansion",
28
+ // CLI command reference); not verified against the real CLI yet. The folder is
29
+ // the launcher's, base64url like Claude Code's and Codex's (docs/agents.md).
30
+ gatewayEntry: (name, port, _token, profile) => ({
31
+ type: "http",
32
+ url: gatewayUrl(name, port),
33
+ headers: {
34
+ Authorization: "Bearer ${TURNO_MCPD_TOKEN}",
35
+ "X-Turno-Profile": profile,
36
+ "X-Turno-Pid": "${TURNO_SESSION_PID}",
37
+ "X-Turno-Cwd-B64": "${TURNO_SESSION_CWD_B64}",
38
+ },
39
+ tools: ["*"],
40
+ }),
41
+ },
42
+ // Safe mode: `--disable-mcp-server=<name>` ("can be used multiple times") for each gateway entry.
43
+ safeMode(s) {
44
+ const cfg = readJsonFile(s.file);
45
+ const names = gatewayNames(typeof cfg === "object" && cfg !== null ? cfg.mcpServers : undefined);
46
+ return {
47
+ args: names.map((n) => `--disable-mcp-server=${n}`),
48
+ notes: [
49
+ names.length
50
+ ? `turned off the gateway entries ${names.join(", ")} for this run`
51
+ : "no gateway entries to turn off",
52
+ ],
53
+ };
54
+ },
55
+ };
56
+ //# sourceMappingURL=copilot.js.map
@@ -0,0 +1,58 @@
1
+ import { join } from "node:path";
2
+ import { paths } from "../core/paths.js";
3
+ import { readJsonFile } from "../core/fsutil.js";
4
+ import { JSON_MCP_SERVERS, gatewayNames, gatewayUrl } from "./adapter.js";
5
+ export const cursor = {
6
+ id: "cursor",
7
+ label: "Cursor CLI",
8
+ command: "cursor-agent",
9
+ homeEnv: "CURSOR_CONFIG_DIR",
10
+ dirPrefix: ".cursor-",
11
+ launcherPrefix: "cursor-agent-",
12
+ install: "curl https://cursor.com/install -fsS | bash",
13
+ loginSubcommand: "login",
14
+ hub: (env) => join(paths(env).home, ".cursor"),
15
+ homeMarkers: ["cli-config.json", "mcp.json"],
16
+ sharedDirs: [],
17
+ sharedFiles: [],
18
+ // Without it every config dir shares the Keychain login (verified 2026-11-13, undocumented).
19
+ launcherEnv: { AGENT_CLI_CREDENTIAL_STORE: "file" },
20
+ classicLauncher: false,
21
+ tokenFromEnv: true,
22
+ accountDetails: false,
23
+ mcp: {
24
+ store: JSON_MCP_SERVERS,
25
+ // CURSOR_CONFIG_DIR does not move mcp.json: every profile shares the hub's.
26
+ file: (_dir, env) => join(cursor.hub(env), "mcp.json"),
27
+ shared: true,
28
+ hubFile: (env) => join(cursor.hub(env), "mcp.json"),
29
+ directRemote: false,
30
+ // One file for every profile, so even the profile comes from the launcher's environment;
31
+ // Cursor resolves `${env:NAME}` in url and headers, the CLI too (docs/agents.md).
32
+ gatewayEntry: (name, port) => ({
33
+ url: gatewayUrl(name, port),
34
+ headers: {
35
+ Authorization: "Bearer ${env:TURNO_MCPD_TOKEN}",
36
+ "X-Turno-Profile": "${env:TURNO_PROFILE}",
37
+ "X-Turno-Pid": "${env:TURNO_SESSION_PID}",
38
+ "X-Turno-Cwd-B64": "${env:TURNO_SESSION_CWD_B64}",
39
+ },
40
+ }),
41
+ afterSync: (added) => ` Cursor asks to approve new servers once: cursor-agent mcp enable <name> (${added.join(", ")})`,
42
+ },
43
+ // Safe mode: Cursor CLI has no switch for one run (only `agent mcp disable`, which lasts). Its
44
+ // entries read the token from the environment, which safe mode leaves out, so mcpd refuses them.
45
+ safeMode(s) {
46
+ const cfg = readJsonFile(s.file);
47
+ const names = gatewayNames(typeof cfg === "object" && cfg !== null ? cfg.mcpServers : undefined);
48
+ return {
49
+ args: [],
50
+ notes: [
51
+ names.length
52
+ ? `Cursor cannot turn servers off for one run: ${names.join(", ")} start without the gateway token, so mcpd refuses them and they show as failed`
53
+ : "no gateway entries in the shared mcp.json",
54
+ ],
55
+ };
56
+ },
57
+ };
58
+ //# 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. 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