turno-cli 0.2.0 → 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 (112) hide show
  1. package/CHANGELOG.md +148 -0
  2. package/README.md +127 -39
  3. package/dist/accounts/audit.js +27 -15
  4. package/dist/accounts/builtin.js +35 -7
  5. package/dist/accounts/delegate.js +30 -7
  6. package/dist/accounts/policy.js +4 -2
  7. package/dist/accounts/registry.js +3 -1
  8. package/dist/agents/adapter.js +22 -0
  9. package/dist/agents/claude.js +54 -3
  10. package/dist/agents/codex.js +94 -6
  11. package/dist/agents/copilot.js +19 -2
  12. package/dist/agents/cursor.js +19 -2
  13. package/dist/agents/index.js +1 -1
  14. package/dist/agents/snippets.js +37 -10
  15. package/dist/cli/args.js +32 -15
  16. package/dist/cli/commands/accounts.js +29 -7
  17. package/dist/cli/commands/auto.js +50 -12
  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 +159 -59
  22. package/dist/cli/commands/complete.js +13 -3
  23. package/dist/cli/commands/completion.js +4 -0
  24. package/dist/cli/commands/config.js +90 -13
  25. package/dist/cli/commands/demo.js +36 -7
  26. package/dist/cli/commands/doctor.js +170 -36
  27. package/dist/cli/commands/identity.js +99 -12
  28. package/dist/cli/commands/init.js +42 -10
  29. package/dist/cli/commands/limit.js +65 -9
  30. package/dist/cli/commands/mcp-call.js +240 -0
  31. package/dist/cli/commands/mcp-oauth.js +33 -6
  32. package/dist/cli/commands/mcp-observe.js +128 -23
  33. package/dist/cli/commands/mcp-share.js +201 -0
  34. package/dist/cli/commands/mcp.js +203 -42
  35. package/dist/cli/commands/mcpd.js +76 -12
  36. package/dist/cli/commands/open.js +26 -3
  37. package/dist/cli/commands/profile.js +212 -30
  38. package/dist/cli/commands/resolve.js +8 -1
  39. package/dist/cli/commands/run.js +24 -4
  40. package/dist/cli/commands/secret.js +23 -38
  41. package/dist/cli/commands/session.js +16 -5
  42. package/dist/cli/commands/sessions.js +7 -1
  43. package/dist/cli/commands/setup.js +83 -11
  44. package/dist/cli/commands/status.js +67 -15
  45. package/dist/cli/commands/statusline.js +7 -2
  46. package/dist/cli/commands/ui.js +17 -5
  47. package/dist/cli/commands/undo.js +39 -7
  48. package/dist/cli/commands/uninstall.js +24 -5
  49. package/dist/cli/commands/upgrade.js +113 -76
  50. package/dist/cli/commands/usage.js +11 -10
  51. package/dist/cli/commands/version.js +20 -8
  52. package/dist/cli/commands/which.js +5 -3
  53. package/dist/cli/diagnostics.js +184 -0
  54. package/dist/cli/exit.js +65 -0
  55. package/dist/cli/group.js +20 -8
  56. package/dist/cli/help.js +6 -1
  57. package/dist/cli/hints.js +30 -0
  58. package/dist/cli/io.js +24 -8
  59. package/dist/cli/launch.js +31 -2
  60. package/dist/cli/launchers.js +25 -10
  61. package/dist/cli/main.js +52 -18
  62. package/dist/cli/optional.js +144 -0
  63. package/dist/cli/output.js +123 -0
  64. package/dist/cli/picker.js +17 -5
  65. package/dist/cli/registry.js +20 -2
  66. package/dist/cli/safe.js +87 -0
  67. package/dist/cli/secret-input.js +63 -0
  68. package/dist/cli/security.js +31 -9
  69. package/dist/cli/style.js +35 -5
  70. package/dist/cli/topics.js +142 -0
  71. package/dist/core/config.js +39 -3
  72. package/dist/core/fsutil.js +2 -10
  73. package/dist/core/journal.js +19 -11
  74. package/dist/core/manifest.js +28 -1
  75. package/dist/core/paths.js +6 -112
  76. package/dist/core/profiles.js +28 -8
  77. package/dist/core/resolve.js +13 -3
  78. package/dist/core/secrets.js +4 -154
  79. package/dist/core/state-file.js +107 -0
  80. package/dist/core/update.js +14 -11
  81. package/dist/core/version.js +57 -10
  82. package/dist/demo/server.js +10 -2
  83. package/dist/mcpd/cache.js +6 -7
  84. package/dist/mcpd/calllog.js +10 -9
  85. package/dist/mcpd/client-names.js +8 -13
  86. package/dist/mcpd/connectors.js +42 -3
  87. package/dist/mcpd/daemon.js +29 -8
  88. package/dist/mcpd/folder-sets.js +5 -2
  89. package/dist/mcpd/gateway.js +57 -29
  90. package/dist/mcpd/health.js +69 -25
  91. package/dist/mcpd/importer.js +106 -9
  92. package/dist/mcpd/instances.js +59 -31
  93. package/dist/mcpd/jsonrpc.js +3 -1
  94. package/dist/mcpd/middleware.js +144 -0
  95. package/dist/mcpd/modern.js +57 -19
  96. package/dist/mcpd/oauth.js +71 -17
  97. package/dist/mcpd/peerpid.js +15 -3
  98. package/dist/mcpd/pressure.js +4 -1
  99. package/dist/mcpd/rss.js +34 -19
  100. package/dist/mcpd/service.js +28 -4
  101. package/dist/mcpd/share.js +217 -0
  102. package/dist/mcpd/state.js +16 -16
  103. package/dist/mcpd/sync.js +22 -12
  104. package/dist/mcpd/systemd.js +4 -1
  105. package/dist/mcpd/tokens.js +4 -8
  106. package/dist/mcpd/upstream.js +12 -5
  107. package/dist/statusline/cost.js +17 -4
  108. package/dist/statusline/input.js +15 -3
  109. package/dist/ui/fonts.js +1 -1
  110. package/dist/ui/settings.js +6 -1
  111. package/npm-shrinkwrap.json +12 -3
  112. package/package.json +7 -6
@@ -38,7 +38,7 @@ function delegationPrompt(account, task, write, tools = account.tools) {
38
38
  /**
39
39
  * Environment variables the delegated run keeps (plus every `LC_*`). Everything else in
40
40
  * mcpd's environment is dropped: another profile's `CLAUDE_CONFIG_DIR`, API keys, the session
41
- * variables of whoever started mcpd (ADR 0024).
41
+ * variables of whoever started mcpd.
42
42
  */
43
43
  const ENV_ALLOW = [
44
44
  "HOME",
@@ -98,7 +98,11 @@ export function isolatedMcp(profile, tools, env = process.env) {
98
98
  const wanted = [...new Set(tools.map(mcpServerOf).filter((s) => s !== undefined))];
99
99
  const connector = wanted.find((s) => s.startsWith("claude_ai_"));
100
100
  if (connector)
101
- return { strict: false, servers: {}, why: `${connector} is a claude.ai connector, which --strict-mcp-config would not load` };
101
+ return {
102
+ strict: false,
103
+ servers: {},
104
+ why: `${connector} is a claude.ai connector, which --strict-mcp-config would not load`,
105
+ };
102
106
  const wild = wanted.find((s) => s.includes("*"));
103
107
  if (wild)
104
108
  return { strict: false, servers: {}, why: `the pattern server "${wild}" is not one server` };
@@ -148,7 +152,7 @@ export function prepareRun(profile, tools, env = process.env) {
148
152
  return { cwd, mcpConfig, mcp, cleanup: () => rmSync(dir, { recursive: true, force: true }) };
149
153
  }
150
154
  /**
151
- * The enforced command line (ADR 0004, decision 3; ADR 0024): headless, `dontAsk` so a global
155
+ * The enforced command line: headless, `dontAsk` so a global
152
156
  * `bypassPermissions` default cannot leak in, no settings files (their allow rules, hooks and
153
157
  * plugins would widen the run), no built-in tools, only the decided tools allowed, the bridge
154
158
  * itself disallowed, and only the account's servers when the folder has an MCP config.
@@ -302,16 +306,35 @@ export async function delegate(req, opts = {}) {
302
306
  const json = parseClaudeJson(out.stdout);
303
307
  const costUsd = typeof json?.total_cost_usd === "number" ? json.total_cost_usd : null;
304
308
  const numTurns = typeof json?.num_turns === "number" ? json.num_turns : null;
305
- const base = { costUsd, numTurns, durationMs, denied: deniedTools(json), mcp: run.mcp.strict ? "strict" : "profile" };
309
+ const base = {
310
+ costUsd,
311
+ numTurns,
312
+ durationMs,
313
+ denied: deniedTools(json),
314
+ mcp: run.mcp.strict ? "strict" : "profile",
315
+ };
306
316
  if (out.cancelled || (opts.signal?.aborted && !json)) {
307
- return { ok: false, cancelled: true, text: `Delegation to ${req.account.profile} was cancelled; its process was stopped.`, ...base };
317
+ return {
318
+ ok: false,
319
+ cancelled: true,
320
+ text: `Delegation to ${req.account.profile} was cancelled; its process was stopped.`,
321
+ ...base,
322
+ };
308
323
  }
309
324
  if (out.timedOut) {
310
- return { ok: false, text: `Delegation to ${req.account.profile} timed out after ${Math.round(spec.timeoutMs / 1000)}s.`, ...base };
325
+ return {
326
+ ok: false,
327
+ text: `Delegation to ${req.account.profile} timed out after ${Math.round(spec.timeoutMs / 1000)}s.`,
328
+ ...base,
329
+ };
311
330
  }
312
331
  if (!json) {
313
332
  const why = tail(out.stderr) || tail(out.stdout) || "no output";
314
- return { ok: false, text: `Delegation to ${req.account.profile} failed (exit ${out.code ?? "?"}): ${why}`, ...base };
333
+ return {
334
+ ok: false,
335
+ text: `Delegation to ${req.account.profile} failed (exit ${out.code ?? "?"}): ${why}`,
336
+ ...base,
337
+ };
315
338
  }
316
339
  const result = typeof json.result === "string" ? json.result : "";
317
340
  const isError = json.is_error === true || out.code !== 0;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * What a call to the accounts bridge may do (ADR 0024): whether the user must confirm it, and
2
+ * What a call to the accounts bridge may do: whether the user must confirm it, and
3
3
  * which tools the delegated run gets. The decision depends on the account, never on the
4
4
  * caller's word alone: `write=false` only narrows the tools when the account lists read tools.
5
5
  */
@@ -65,7 +65,9 @@ export function decide(account, write) {
65
65
  reason: policy === "always" ? `read with the read tools; confirm = "always"` : "read with the read tools only",
66
66
  };
67
67
  }
68
- const reason = write ? "write: every tool of the account" : "read, but the account lists no read_tools, so it gets every tool";
68
+ const reason = write
69
+ ? "write: every tool of the account"
70
+ : "read, but the account lists no read_tools, so it gets every tool";
69
71
  return {
70
72
  policy,
71
73
  confirm: policy !== "never",
@@ -64,7 +64,9 @@ export function makeAccount(id, fields, file = "accounts.toml") {
64
64
  }
65
65
  }
66
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")}`);
67
+ throw new ConfigError(file, `${key}.confirm must be ${CONFIRM_POLICIES.map((c) => `"${c}"`)
68
+ .join(", ")
69
+ .replace(/, ([^,]*)$/, " or $1")}`);
68
70
  }
69
71
  return {
70
72
  id,
@@ -4,4 +4,26 @@ export const TOML_MCP_SERVERS = { format: "toml", key: "mcp_servers" };
4
4
  export function gatewayUrl(name, port) {
5
5
  return `http://127.0.0.1:${port}/mcp/${encodeURIComponent(name)}`;
6
6
  }
7
+ /** Whether an MCP entry points at mcpd: written by `turno mcp sync`, or by hand from `turno mcp config`. */
8
+ export function isGatewayEntry(e) {
9
+ if (typeof e !== "object" || e === null || Array.isArray(e))
10
+ return false;
11
+ const o = e;
12
+ const table = (v) => typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
13
+ const headers = { ...table(o.headers), ...table(o.http_headers), ...table(o.env_http_headers) };
14
+ if (Object.keys(headers).some((h) => h.toLowerCase() === "x-turno-profile" || h.toLowerCase() === "x-turno-pid"))
15
+ return true;
16
+ if (o.bearer_token_env_var === "TURNO_MCPD_TOKEN")
17
+ return true;
18
+ return typeof o.url === "string" && /^http:\/\/127\.0\.0\.1:\d+\/mcp\/[^/]+\/?$/.test(o.url);
19
+ }
20
+ /** The names of the gateway entries in one server map, sorted. */
21
+ export function gatewayNames(map) {
22
+ if (typeof map !== "object" || map === null || Array.isArray(map))
23
+ return [];
24
+ return Object.entries(map)
25
+ .filter(([, e]) => isGatewayEntry(e))
26
+ .map(([n]) => n)
27
+ .sort();
28
+ }
7
29
  //# sourceMappingURL=adapter.js.map
@@ -1,8 +1,8 @@
1
- import { chmodSync, copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync } from "node:fs";
1
+ import { chmodSync, copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, realpathSync, writeFileSync, } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { paths, tildify } from "../core/paths.js";
4
4
  import { plural } from "../cli/io.js";
5
- import { JSON_MCP_SERVERS, gatewayUrl } from "./adapter.js";
5
+ import { JSON_MCP_SERVERS, gatewayUrl, isGatewayEntry, } from "./adapter.js";
6
6
  import { isObject, readJsonFile } from "../core/fsutil.js";
7
7
  /**
8
8
  * Hub folders shared by every Claude Code profile. Launchers recreate them, so a cleanup that
@@ -85,6 +85,53 @@ export function gatewayEntry(name, port, token, profile) {
85
85
  },
86
86
  };
87
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
+ }
88
135
  const SEED_KEYS = ["mcpServers", "projects", "hasCompletedOnboarding", "lastOnboardingVersion", "theme"];
89
136
  /** First .claude.json of a profile: user MCP servers and per-project state, never the account. */
90
137
  function seedGlobalConfig(s) {
@@ -166,11 +213,15 @@ export const claude = {
166
213
  shared: false,
167
214
  hubFile: (env) => paths(env).hubConfig,
168
215
  folderFile: ".mcp.json",
169
- projectServers: (config) => Object.entries(config.projects ?? {}).map(([dir, proj]) => [dir, proj?.mcpServers]),
216
+ projectServers: (config) => Object.entries(config.projects ?? {}).map(([dir, proj]) => [
217
+ dir,
218
+ proj?.mcpServers,
219
+ ]),
170
220
  foldersUsed: projectsOf,
171
221
  directRemote: true,
172
222
  gatewayEntry,
173
223
  },
224
+ safeMode,
174
225
  setup: {
175
226
  before(s) {
176
227
  if (existsSync(s.hub))
@@ -1,9 +1,9 @@
1
- import { chmodSync, existsSync, readFileSync } from "node:fs";
1
+ import { chmodSync, existsSync, readFileSync, realpathSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { parse as parseToml } from "smol-toml";
4
- import { paths } from "../core/paths.js";
4
+ import { paths, tildify } from "../core/paths.js";
5
5
  import { setValue } from "../core/toml-edit.js";
6
- import { TOML_MCP_SERVERS, gatewayUrl } from "./adapter.js";
6
+ import { TOML_MCP_SERVERS, gatewayNames, gatewayUrl, } from "./adapter.js";
7
7
  /** A Codex `[mcp_servers.<name>]` table in Claude Code's shape. */
8
8
  function fromCodex(e) {
9
9
  if (typeof e.command === "string") {
@@ -49,6 +49,89 @@ function prepareConfig(s) {
49
49
  }
50
50
  chmodSync(file, 0o600);
51
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
+ }
52
135
  export const codex = {
53
136
  id: "codex",
54
137
  label: "Codex CLI",
@@ -61,7 +144,7 @@ export const codex = {
61
144
  hub: (env) => join(paths(env).home, ".codex"),
62
145
  homeMarkers: ["config.toml", "auth.json", "sessions", "history.jsonl"],
63
146
  // Rollouts in sessions/ let `codex resume <id>` continue a session with another account
64
- // (not verified across ChatGPT accounts yet; ADR 0013).
147
+ // (not verified across ChatGPT accounts yet).
65
148
  sharedDirs: ["sessions", "prompts", "skills"],
66
149
  sharedFiles: ["AGENTS.md"],
67
150
  launcherEnv: {},
@@ -83,16 +166,21 @@ export const codex = {
83
166
  env_http_headers: { "X-Turno-Pid": "TURNO_SESSION_PID", "X-Turno-Cwd-B64": "TURNO_SESSION_CWD_B64" },
84
167
  }),
85
168
  },
169
+ safeMode,
170
+ ruleFolders: trustFolders,
86
171
  setup: { after: prepareConfig },
87
172
  doctorWarnings(dir) {
88
173
  let store;
89
174
  try {
90
- store = parseToml(readFileSync(join(dir, "config.toml"), "utf8")).cli_auth_credentials_store;
175
+ store = parseToml(readFileSync(join(dir, "config.toml"), "utf8"))
176
+ .cli_auth_credentials_store;
91
177
  }
92
178
  catch {
93
179
  store = undefined;
94
180
  }
95
- return store === "file" ? [] : ['Codex may keep the login in the shared Keychain (cli_auth_credentials_store is not "file")'];
181
+ return store === "file"
182
+ ? []
183
+ : ['Codex may keep the login in the shared Keychain (cli_auth_credentials_store is not "file")'];
96
184
  },
97
185
  };
98
186
  //# sourceMappingURL=codex.js.map
@@ -1,6 +1,7 @@
1
1
  import { join } from "node:path";
2
2
  import { paths } from "../core/paths.js";
3
- import { JSON_MCP_SERVERS, gatewayUrl } from "./adapter.js";
3
+ import { readJsonFile } from "../core/fsutil.js";
4
+ import { JSON_MCP_SERVERS, gatewayNames, gatewayUrl } from "./adapter.js";
4
5
  export const copilot = {
5
6
  id: "copilot",
6
7
  label: "GitHub Copilot CLI",
@@ -23,7 +24,9 @@ export const copilot = {
23
24
  shared: false,
24
25
  hubFile: (env) => join(copilot.hub(env), "mcp-config.json"),
25
26
  directRemote: false,
26
- // `${VAR}` expansion in Copilot's headers is from its documentation, not verified (ADR 0013).
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).
27
30
  gatewayEntry: (name, port, _token, profile) => ({
28
31
  type: "http",
29
32
  url: gatewayUrl(name, port),
@@ -31,9 +34,23 @@ export const copilot = {
31
34
  Authorization: "Bearer ${TURNO_MCPD_TOKEN}",
32
35
  "X-Turno-Profile": profile,
33
36
  "X-Turno-Pid": "${TURNO_SESSION_PID}",
37
+ "X-Turno-Cwd-B64": "${TURNO_SESSION_CWD_B64}",
34
38
  },
35
39
  tools: ["*"],
36
40
  }),
37
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
+ },
38
55
  };
39
56
  //# sourceMappingURL=copilot.js.map
@@ -1,6 +1,7 @@
1
1
  import { join } from "node:path";
2
2
  import { paths } from "../core/paths.js";
3
- import { JSON_MCP_SERVERS, gatewayUrl } from "./adapter.js";
3
+ import { readJsonFile } from "../core/fsutil.js";
4
+ import { JSON_MCP_SERVERS, gatewayNames, gatewayUrl } from "./adapter.js";
4
5
  export const cursor = {
5
6
  id: "cursor",
6
7
  label: "Cursor CLI",
@@ -26,16 +27,32 @@ export const cursor = {
26
27
  shared: true,
27
28
  hubFile: (env) => join(cursor.hub(env), "mcp.json"),
28
29
  directRemote: false,
29
- // One file for every profile, so even the profile comes from the launcher's environment.
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).
30
32
  gatewayEntry: (name, port) => ({
31
33
  url: gatewayUrl(name, port),
32
34
  headers: {
33
35
  Authorization: "Bearer ${env:TURNO_MCPD_TOKEN}",
34
36
  "X-Turno-Profile": "${env:TURNO_PROFILE}",
35
37
  "X-Turno-Pid": "${env:TURNO_SESSION_PID}",
38
+ "X-Turno-Cwd-B64": "${env:TURNO_SESSION_CWD_B64}",
36
39
  },
37
40
  }),
38
41
  afterSync: (added) => ` Cursor asks to approve new servers once: cursor-agent mcp enable <name> (${added.join(", ")})`,
39
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
+ },
40
57
  };
41
58
  //# sourceMappingURL=cursor.js.map
@@ -5,7 +5,7 @@ import { codex } from "./codex.js";
5
5
  import { copilot } from "./copilot.js";
6
6
  import { cursor } from "./cursor.js";
7
7
  /**
8
- * The registry of coding agents turno manages profiles for (ADR 0013, ADR 0032). Adding an
8
+ * The registry of coding agents turno manages profiles for. Adding an
9
9
  * agent is one adapter file next to this one plus its entries here.
10
10
  */
11
11
  export const AGENT_IDS = ["claude", "codex", "copilot", "cursor"];
@@ -1,6 +1,6 @@
1
1
  import { gatewayUrl } from "./adapter.js";
2
2
  /**
3
- * Config snippets that point agents turno does not manage at the MCP gateway (ADR 0013).
3
+ * Config snippets that point agents turno does not manage at the MCP gateway.
4
4
  * turno prints them; the user pastes them. The token is never printed: each snippet reads it
5
5
  * from TURNO_MCPD_TOKEN where the agent expands variables, and says so where it does not.
6
6
  */
@@ -9,7 +9,7 @@ export function isSnippetAgent(v) {
9
9
  return SNIPPET_AGENTS.includes(v);
10
10
  }
11
11
  const url = (port, name) => gatewayUrl(name, port);
12
- /** How the profile's own token (ADR 0023) reaches an agent that expands variables. */
12
+ /** How the profile's own token reaches an agent that expands variables. */
13
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})"`;
14
14
  function headers(profile, token) {
15
15
  return { Authorization: `Bearer ${token}`, "X-Turno-Profile": profile };
@@ -24,13 +24,22 @@ export function gatewaySnippet(agent, servers, port, profile, tokenFile = `~/.lo
24
24
  case "opencode":
25
25
  return {
26
26
  file: "opencode.json (project) or ~/.config/opencode/opencode.json",
27
- text: json({ mcp: each((n) => ({ type: "remote", url: url(port, n), headers: headers(profile, "{env:TURNO_MCPD_TOKEN}"), enabled: true })) }),
27
+ text: json({
28
+ mcp: each((n) => ({
29
+ type: "remote",
30
+ url: url(port, n),
31
+ headers: headers(profile, "{env:TURNO_MCPD_TOKEN}"),
32
+ enabled: true,
33
+ })),
34
+ }),
28
35
  notes: [TOKEN_ENV],
29
36
  };
30
37
  case "gemini":
31
38
  return {
32
39
  file: "~/.gemini/settings.json (or .gemini/settings.json in a project)",
33
- text: json({ mcpServers: each((n) => ({ httpUrl: url(port, n), headers: headers(profile, "${TURNO_MCPD_TOKEN}") })) }),
40
+ text: json({
41
+ mcpServers: each((n) => ({ httpUrl: url(port, n), headers: headers(profile, "${TURNO_MCPD_TOKEN}") })),
42
+ }),
34
43
  notes: [TOKEN_ENV],
35
44
  };
36
45
  case "goose": {
@@ -41,26 +50,44 @@ export function gatewaySnippet(agent, servers, port, profile, tokenFile = `~/.lo
41
50
  return {
42
51
  file: "~/.config/goose/config.yaml",
43
52
  text: `${lines.join("\n")}\n`,
44
- notes: ["Goose does not document variable expansion in headers: paste the token by hand and keep the file private (chmod 600)."],
53
+ notes: [
54
+ "Goose does not document variable expansion in headers: paste the token by hand and keep the file private (chmod 600).",
55
+ ],
45
56
  };
46
57
  }
47
58
  case "crush":
48
59
  return {
49
60
  file: "crush.json (project) or ~/.config/crush/crush.json",
50
- text: json({ mcp: each((n) => ({ type: "http", url: url(port, n), headers: headers(profile, "$TURNO_MCPD_TOKEN") })) }),
61
+ text: json({
62
+ mcp: each((n) => ({ type: "http", url: url(port, n), headers: headers(profile, "$TURNO_MCPD_TOKEN") })),
63
+ }),
51
64
  notes: [TOKEN_ENV],
52
65
  };
53
66
  case "droid":
54
67
  return {
55
68
  file: "~/.factory/mcp.json",
56
- text: json({ mcpServers: each((n) => ({ type: "http", url: url(port, n), headers: headers(profile, "${TURNO_MCPD_TOKEN}") })) }),
57
- notes: [TOKEN_ENV, "Variable expansion in Droid headers is not verified: if the gateway answers 401, paste the token instead."],
69
+ text: json({
70
+ mcpServers: each((n) => ({
71
+ type: "http",
72
+ url: url(port, n),
73
+ headers: headers(profile, "${TURNO_MCPD_TOKEN}"),
74
+ })),
75
+ }),
76
+ notes: [
77
+ TOKEN_ENV,
78
+ "Variable expansion in Droid headers is not verified: if the gateway answers 401, paste the token instead.",
79
+ ],
58
80
  };
59
81
  case "kiro":
60
82
  return {
61
83
  file: "~/.kiro/settings/mcp.json",
62
- text: json({ mcpServers: each((n) => ({ url: url(port, n), headers: headers(profile, "${TURNO_MCPD_TOKEN}") })) }),
63
- notes: [TOKEN_ENV, "Variable expansion in Kiro headers is not verified: if the gateway answers 401, paste the token instead."],
84
+ text: json({
85
+ mcpServers: each((n) => ({ url: url(port, n), headers: headers(profile, "${TURNO_MCPD_TOKEN}") })),
86
+ }),
87
+ notes: [
88
+ TOKEN_ENV,
89
+ "Variable expansion in Kiro headers is not verified: if the gateway answers 401, paste the token instead.",
90
+ ],
64
91
  };
65
92
  }
66
93
  }
package/dist/cli/args.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { parseArgs } from "node:util";
2
- import { highlightJson } from "./highlight.js";
3
- import { colors, fail } from "./io.js";
2
+ import { fail } from "./io.js";
4
3
  /** Flags shared by every command, so the same words mean the same thing everywhere. */
5
4
  export const JSON_FLAG = { json: { type: "boolean" } };
6
5
  export const DRY_RUN = { "dry-run": { type: "boolean" } };
@@ -14,17 +13,46 @@ export const WATCH = { watch: { type: "boolean" } };
14
13
  export function flagsOf(...specs) {
15
14
  return specs.flatMap((s) => Object.keys(s)).map((k) => `--${k}`);
16
15
  }
16
+ /**
17
+ * Take `--json=<value>` out of `args` when the spec has a boolean --json: it turns
18
+ * --json on and keeps the value for `emit`. Only a command's own flags count, not those after --.
19
+ */
20
+ function takeJsonValue(args, spec) {
21
+ if (spec.json?.type !== "boolean")
22
+ return { args };
23
+ let json;
24
+ const out = [];
25
+ let i = 0;
26
+ for (; i < args.length && args[i] !== "--"; i++) {
27
+ const a = args[i];
28
+ if (a.startsWith("--json=")) {
29
+ json = a.slice("--json=".length);
30
+ out.push("--json");
31
+ }
32
+ else {
33
+ if (a === "--json")
34
+ json ??= "";
35
+ out.push(a);
36
+ }
37
+ }
38
+ return { args: [...out, ...args.slice(i)], ...(json !== undefined ? { json } : {}) };
39
+ }
17
40
  /**
18
41
  * Parse `args` against `spec` (long flags, `--flag=value`, short aliases). Unknown flags and
19
42
  * positionals beyond `max` are usage errors with a plain message.
20
43
  */
21
- export function parseFlags(args, spec, max = Number.POSITIVE_INFINITY) {
44
+ export function parseFlags(given, spec, max = Number.POSITIVE_INFINITY) {
45
+ const { args, json } = takeJsonValue(given, spec);
22
46
  let parsed;
23
47
  try {
24
48
  parsed = parseArgs({ args, options: spec, allowPositionals: true, strict: true });
49
+ if (json !== undefined)
50
+ parsed.json = json;
25
51
  }
26
52
  catch (err) {
27
- const msg = err.message.replace(/^Unknown option '(.+?)'.*$/s, "unknown option $1").replace(/\. To specify.*$/s, "");
53
+ const msg = err.message
54
+ .replace(/^Unknown option '(.+?)'.*$/s, "unknown option $1")
55
+ .replace(/\. To specify.*$/s, "");
28
56
  return fail(msg.replace(/^Option '(--[\w-]+)(?: <value>)?' argument missing$/, "$1 needs a value"));
29
57
  }
30
58
  if (parsed.positionals.length > max)
@@ -48,15 +76,4 @@ export function count(p, name, fallback) {
48
76
  fail(`--${name} must be a positive integer`);
49
77
  return n;
50
78
  }
51
- /**
52
- * Print a value as indented JSON, colored on a terminal without NO_COLOR (never in a pipe,
53
- * even with FORCE_COLOR, since programs read it).
54
- * Given only an output function it prints plain JSON.
55
- */
56
- export function printJson(io, value) {
57
- const text = JSON.stringify(value, null, 2);
58
- const out = typeof io === "function" ? io : io.out;
59
- // Only on a real terminal: --json is read by programs, so FORCE_COLOR never colors a pipe here.
60
- out(text !== undefined && typeof io !== "function" && io.isTty && colors(io) ? highlightJson(text) : text);
61
- }
62
79
  //# sourceMappingURL=args.js.map