turno-cli 0.2.0 → 0.4.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 (116) hide show
  1. package/CHANGELOG.md +266 -0
  2. package/README.md +134 -42
  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-do-session.js +170 -0
  19. package/dist/cli/commands/browser-do.js +740 -0
  20. package/dist/cli/commands/browser-flows.js +300 -0
  21. package/dist/cli/commands/browser-identity.js +952 -0
  22. package/dist/cli/commands/browser-live.js +118 -0
  23. package/dist/cli/commands/browser-session.js +102 -0
  24. package/dist/cli/commands/browser-vault.js +193 -0
  25. package/dist/cli/commands/browser.js +303 -62
  26. package/dist/cli/commands/complete.js +13 -3
  27. package/dist/cli/commands/completion.js +4 -0
  28. package/dist/cli/commands/config.js +90 -13
  29. package/dist/cli/commands/demo.js +36 -7
  30. package/dist/cli/commands/doctor.js +170 -36
  31. package/dist/cli/commands/identity.js +101 -12
  32. package/dist/cli/commands/init.js +42 -10
  33. package/dist/cli/commands/limit.js +65 -9
  34. package/dist/cli/commands/mcp-call.js +240 -0
  35. package/dist/cli/commands/mcp-oauth.js +33 -6
  36. package/dist/cli/commands/mcp-observe.js +128 -23
  37. package/dist/cli/commands/mcp-share.js +201 -0
  38. package/dist/cli/commands/mcp.js +203 -42
  39. package/dist/cli/commands/mcpd.js +76 -12
  40. package/dist/cli/commands/open.js +26 -3
  41. package/dist/cli/commands/profile.js +212 -30
  42. package/dist/cli/commands/resolve.js +8 -1
  43. package/dist/cli/commands/run.js +24 -4
  44. package/dist/cli/commands/secret.js +23 -38
  45. package/dist/cli/commands/session.js +16 -5
  46. package/dist/cli/commands/sessions.js +7 -1
  47. package/dist/cli/commands/setup.js +83 -11
  48. package/dist/cli/commands/status.js +67 -15
  49. package/dist/cli/commands/statusline.js +7 -2
  50. package/dist/cli/commands/ui.js +17 -5
  51. package/dist/cli/commands/undo.js +39 -7
  52. package/dist/cli/commands/uninstall.js +24 -5
  53. package/dist/cli/commands/upgrade.js +113 -76
  54. package/dist/cli/commands/usage.js +11 -10
  55. package/dist/cli/commands/version.js +20 -8
  56. package/dist/cli/commands/which.js +5 -3
  57. package/dist/cli/diagnostics.js +184 -0
  58. package/dist/cli/exit.js +65 -0
  59. package/dist/cli/group.js +20 -8
  60. package/dist/cli/help.js +6 -1
  61. package/dist/cli/hints.js +30 -0
  62. package/dist/cli/io.js +24 -8
  63. package/dist/cli/launch.js +31 -2
  64. package/dist/cli/launchers.js +25 -10
  65. package/dist/cli/main.js +52 -18
  66. package/dist/cli/optional.js +144 -0
  67. package/dist/cli/output.js +123 -0
  68. package/dist/cli/picker.js +17 -5
  69. package/dist/cli/registry.js +20 -2
  70. package/dist/cli/safe.js +87 -0
  71. package/dist/cli/secret-input.js +63 -0
  72. package/dist/cli/security.js +31 -9
  73. package/dist/cli/style.js +35 -5
  74. package/dist/cli/topics.js +155 -0
  75. package/dist/core/config.js +39 -3
  76. package/dist/core/fsutil.js +2 -10
  77. package/dist/core/journal.js +19 -11
  78. package/dist/core/manifest.js +28 -1
  79. package/dist/core/paths.js +6 -112
  80. package/dist/core/profiles.js +28 -8
  81. package/dist/core/resolve.js +13 -3
  82. package/dist/core/secrets.js +4 -154
  83. package/dist/core/state-file.js +107 -0
  84. package/dist/core/update.js +14 -11
  85. package/dist/core/version.js +57 -10
  86. package/dist/demo/server.js +10 -2
  87. package/dist/mcpd/cache.js +6 -7
  88. package/dist/mcpd/calllog.js +10 -9
  89. package/dist/mcpd/client-names.js +8 -13
  90. package/dist/mcpd/connectors.js +42 -3
  91. package/dist/mcpd/daemon.js +29 -8
  92. package/dist/mcpd/folder-sets.js +5 -2
  93. package/dist/mcpd/gateway.js +57 -29
  94. package/dist/mcpd/health.js +70 -26
  95. package/dist/mcpd/importer.js +106 -9
  96. package/dist/mcpd/instances.js +70 -32
  97. package/dist/mcpd/jsonrpc.js +3 -1
  98. package/dist/mcpd/middleware.js +156 -0
  99. package/dist/mcpd/modern.js +57 -19
  100. package/dist/mcpd/oauth.js +71 -17
  101. package/dist/mcpd/peerpid.js +63 -17
  102. package/dist/mcpd/pressure.js +4 -1
  103. package/dist/mcpd/rss.js +34 -19
  104. package/dist/mcpd/service.js +28 -4
  105. package/dist/mcpd/share.js +217 -0
  106. package/dist/mcpd/state.js +16 -16
  107. package/dist/mcpd/sync.js +22 -12
  108. package/dist/mcpd/systemd.js +4 -1
  109. package/dist/mcpd/tokens.js +4 -8
  110. package/dist/mcpd/upstream.js +12 -5
  111. package/dist/statusline/cost.js +17 -4
  112. package/dist/statusline/input.js +15 -3
  113. package/dist/ui/fonts.js +1 -1
  114. package/dist/ui/settings.js +6 -1
  115. package/npm-shrinkwrap.json +12 -3
  116. package/package.json +7 -6
@@ -0,0 +1,155 @@
1
+ /**
2
+ * `turno help <topic>`: environment, exit-codes and json (like gh's help topics). Static text
3
+ * only, so a topic loads no command module.
4
+ */
5
+ import { EXIT_ROWS } from "./exit.js";
6
+ import { columns, examplesBlock } from "./io.js";
7
+ /** Variables turno reads, by section: name and what it does. */
8
+ const ENVIRONMENT = [
9
+ {
10
+ title: "Where turno keeps things",
11
+ rows: [
12
+ ["TURNO_CONFIG_DIR", "config.toml and mcp.toml (default: $XDG_CONFIG_HOME/turno, else ~/.config/turno)"],
13
+ [
14
+ "TURNO_STATE_DIR",
15
+ "state, logs, caches and backups (default: $XDG_STATE_HOME/turno, else ~/.local/state/turno)",
16
+ ],
17
+ [
18
+ "TURNO_DATA_DIR",
19
+ "installed servers and browser identities (default: $XDG_DATA_HOME/turno, else ~/.local/share/turno)",
20
+ ],
21
+ ["TURNO_BIN", "where the launchers go (default: ~/.local/bin)"],
22
+ ["TURNO_HUB", "Claude Code's shared folder (default: ~/.claude)"],
23
+ ["TURNO_HUB_CONFIG", "Claude Code's shared .claude.json (default: ~/.claude.json)"],
24
+ ["TURNO_FONT_DIR", "where turno ui installs the status line font"],
25
+ ["TURNO_APPS_DIR", "where turno looks for terminal apps on macOS (default: /Applications)"],
26
+ ["TURNO_CHROME_APP", "Google Chrome on macOS, for turno open (default: /Applications/Google Chrome.app)"],
27
+ ["TURNO_CHROME_BIN", "the Chrome program on Linux, for turno open"],
28
+ ],
29
+ },
30
+ {
31
+ title: "How turno behaves",
32
+ rows: [
33
+ [
34
+ "TURNO_NO_INPUT",
35
+ "1: never ask, exit 2 and name the flag instead (same as --no-input); 0: ask even inside an agent session",
36
+ ],
37
+ ["TURNO_COLOR", "always, never or auto (same as --color); see the order below"],
38
+ ["TURNO_ALLOW_PLAIN", "1: turno auto runs the plain agent when config.toml does not parse"],
39
+ [
40
+ "TURNO_SAFE",
41
+ "1: turno run, turno <profile> and turno auto open the agent in safe mode, without the gateway and the status line (same as --no-gateway)",
42
+ ],
43
+ ["TURNO_NO_UPDATE_CHECK", "1: no daily update check and no notice"],
44
+ ["TURNO_NO_UPDATE_NOTIFIER", "1: same as TURNO_NO_UPDATE_CHECK (the name gh uses)"],
45
+ ["TURNO_REGISTRY", "npm registry for update checks (default: npm_config_registry, else registry.npmjs.org)"],
46
+ ["TURNO_BROWSER_IDLE", "turno-browser closes Chrome after this long without a tool call (default: 15m)"],
47
+ ["TURNO_LIGHTPANDA_PATH", "the Lightpanda binary turno-browser's read mode runs (default: lightpanda on PATH)"],
48
+ [
49
+ "TURNO_BROWSER_SESSION",
50
+ "the session name of turno browser do (same as --session; default: default), to keep several apart",
51
+ ],
52
+ [
53
+ "TURNO_CAMOUFOX_PATH",
54
+ "the Camoufox executable turno-browser's camoufox engine runs (default: the newest in Camoufox's cache)",
55
+ ],
56
+ [
57
+ "TURNO_PLAYWRIGHT_CORE",
58
+ "the playwright-core folder the camoufox engine runs on (default: the one next to turno-browser)",
59
+ ],
60
+ ],
61
+ },
62
+ {
63
+ title: "Set by turno for the agents it starts (read them, do not set them)",
64
+ rows: [
65
+ ["TURNO_PROFILE", "the profile a launcher opened"],
66
+ ["TURNO_AGENT", "that profile's agent (codex, copilot, cursor)"],
67
+ ["TURNO_SESSION_PID", "the agent's process id, sent to the gateway"],
68
+ ["TURNO_SESSION_CWD_B64", "the agent's folder (base64url), sent to the gateway"],
69
+ ["TURNO_MCPD_TOKEN", "the profile's gateway token, for agents that read headers from the environment"],
70
+ ["TURNO_MCPD_SERVICE", "set by the mcpd service file (LaunchAgent or systemd unit)"],
71
+ ],
72
+ },
73
+ {
74
+ title: "Standard variables turno honors",
75
+ rows: [
76
+ ["NO_COLOR", "set and not empty: no colors (no-color.org)"],
77
+ ["FORCE_COLOR", "0 or false: no colors; anything else: colors, also in a pipe"],
78
+ ["CLICOLOR_FORCE", "set and not 0: colors, also in a pipe"],
79
+ ["CLICOLOR", "0: no colors"],
80
+ ["TERM", "dumb: no colors"],
81
+ ["COLUMNS", "the width to lay out for (default: the terminal's, else 80)"],
82
+ ["DO_NOT_TRACK", "1: no update check (turno sends nothing else anywhere)"],
83
+ ["CI", "set: no update check"],
84
+ ["NO_UPDATE_NOTIFIER", "1: no update check"],
85
+ [
86
+ "XDG_CONFIG_HOME, XDG_STATE_HOME, XDG_DATA_HOME, XDG_CACHE_HOME",
87
+ "base folders, when the TURNO_* ones are not set",
88
+ ],
89
+ ["VISUAL, EDITOR", "the editor of turno config edit"],
90
+ [
91
+ "NODE_COMPILE_CACHE, NODE_DISABLE_COMPILE_CACHE",
92
+ "Node's compile cache (turno keeps it in $XDG_CACHE_HOME/turno)",
93
+ ],
94
+ ],
95
+ },
96
+ ];
97
+ function environment() {
98
+ const out = ["Environment variables turno reads.", ""];
99
+ for (const s of ENVIRONMENT)
100
+ out.push(`${s.title}:`, columns(s.rows, 2, 26), "");
101
+ out.push("Colors: the first that applies wins: --color, TURNO_COLOR, NO_COLOR, FORCE_COLOR,", "CLICOLOR_FORCE, then CLICOLOR=0 or TERM=dumb, then whether output is a terminal.", "--json output is colored only on a terminal.", "", examplesBlock([
102
+ "NO_COLOR=1 turno status",
103
+ "TURNO_NO_INPUT=1 turno profile remove work # fails fast instead of asking",
104
+ "TURNO_CONFIG_DIR=/tmp/t turno doctor",
105
+ "TURNO_SAFE=1 turno work # without the gateway, to tell whether a problem is turno's",
106
+ ]));
107
+ return out;
108
+ }
109
+ function exitCodes() {
110
+ return [
111
+ "Exit codes. Scripts, hooks and status lines can rely on these.",
112
+ "",
113
+ columns(EXIT_ROWS.map(([code, name, what]) => [`${code} ${name}`, what]), 2, 18),
114
+ "",
115
+ "With --json, an error is one JSON line on stderr with the same code:",
116
+ ' {"schemaVersion":1,"error":{"code":"no_profile","exitCode":3,"message":"..."}}',
117
+ "",
118
+ examplesBlock([
119
+ "turno profile which --check || turno profile assign . work",
120
+ "turno mcp daemon status >/dev/null; [ $? -eq 5 ] && turno mcp daemon start",
121
+ ]),
122
+ ];
123
+ }
124
+ function json() {
125
+ return [
126
+ "JSON output. Read commands take --json:",
127
+ "",
128
+ columns([
129
+ ["--json", "every field, as one indented document"],
130
+ ["--json=fields", "the field names, one per line, and nothing else"],
131
+ ["--json=a,b", "only those fields; an unknown one is a usage error (exit 2) that lists the known ones"],
132
+ [
133
+ "--watch --json",
134
+ "one compact JSON record per line (NDJSON) until Ctrl-C (turno limit show, turno mcp top); turno mcp log --follow --json too",
135
+ ],
136
+ ], 2, 16),
137
+ "",
138
+ "Every object carries schemaVersion, and so does each element of a list. A version",
139
+ "goes up only when a field is removed or renamed or changes meaning (the changelog",
140
+ "says so); new fields keep it. Errors under --json are JSON on stderr (turno help",
141
+ "exit-codes). turno config get prints a config value as it is in config.toml.",
142
+ "",
143
+ examplesBlock([
144
+ "turno status --json=fields",
145
+ "turno profile list --json=name,email",
146
+ "turno limit show --watch --json | jq -c '.fiveHour'",
147
+ ]),
148
+ ];
149
+ }
150
+ export const TOPICS = {
151
+ environment: { summary: "every environment variable turno reads", text: environment },
152
+ "exit-codes": { summary: "what each exit code means", text: exitCodes },
153
+ json: { summary: "the --json contract: fields, schemaVersion, NDJSON, errors", text: json },
154
+ };
155
+ //# sourceMappingURL=topics.js.map
@@ -5,14 +5,39 @@ import { distance } from "../cli/io.js";
5
5
  import { expandHome, paths, tildify } from "./paths.js";
6
6
  /** Every key config.toml may hold, by table ("" is the top level; `*` stands for any name). */
7
7
  const KNOWN_KEYS = {
8
- "": ["system", "default", "fallback", "icons", "nerd_terminals", "update_check", "profiles", "agents", "projects", "open", "mcpd"],
8
+ "": [
9
+ "system",
10
+ "default",
11
+ "fallback",
12
+ "icons",
13
+ "nerd_terminals",
14
+ "update_check",
15
+ "hints",
16
+ "profiles",
17
+ "agents",
18
+ "projects",
19
+ "open",
20
+ "mcpd",
21
+ ],
9
22
  "profiles.*": ["agent", "browser", "color"],
10
23
  "agents.*": ["default", "fallback"],
11
24
  "projects[]": ["path", "profile", "mcp", "mcp_deny"],
12
25
  open: ["chrome_dir"],
13
26
  mcpd: ["port", "call_log", "max_request_body", "idle_under_pressure"],
14
27
  };
15
- const SIZE_UNITS = { "": 1, b: 1, k: 1024, kb: 1000, kib: 1024, m: 1024 ** 2, mb: 1000 ** 2, mib: 1024 ** 2, g: 1024 ** 3, gb: 1000 ** 3, gib: 1024 ** 3 };
28
+ const SIZE_UNITS = {
29
+ "": 1,
30
+ b: 1,
31
+ k: 1024,
32
+ kb: 1000,
33
+ kib: 1024,
34
+ m: 1024 ** 2,
35
+ mb: 1000 ** 2,
36
+ mib: 1024 ** 2,
37
+ g: 1024 ** 3,
38
+ gb: 1000 ** 3,
39
+ gib: 1024 ** 3,
40
+ };
16
41
  /** Bounds of `mcpd.max_request_body`: below 1 MiB ordinary tool calls fail, above 1 GiB a client can exhaust memory. */
17
42
  const MIN_REQUEST_BODY = 1024 ** 2;
18
43
  const MAX_REQUEST_BODY = 1024 ** 3;
@@ -133,6 +158,7 @@ export function parseConfig(text, path = "config.toml", env = process.env) {
133
158
  icons: "auto",
134
159
  nerdTerminals: [],
135
160
  updateCheck: true,
161
+ hints: true,
136
162
  profiles: {},
137
163
  agents: {},
138
164
  projects: [],
@@ -162,6 +188,11 @@ export function parseConfig(text, path = "config.toml", env = process.env) {
162
188
  throw new ConfigError(file, "update_check must be true or false");
163
189
  cfg.updateCheck = raw.update_check;
164
190
  }
191
+ if (raw.hints !== undefined) {
192
+ if (typeof raw.hints !== "boolean")
193
+ throw new ConfigError(file, "hints must be true or false");
194
+ cfg.hints = raw.hints;
195
+ }
165
196
  const profiles = table(raw.profiles, file, "profiles");
166
197
  for (const [name, value] of Object.entries(profiles)) {
167
198
  if (!isValidProfileName(name))
@@ -209,7 +240,12 @@ export function parseConfig(text, path = "config.toml", env = process.env) {
209
240
  const mcpDeny = names(v.mcp_deny, file, `projects[${i}].mcp_deny`);
210
241
  if (!path || (!profile && !mcp && !mcpDeny))
211
242
  throw new ConfigError(file, `projects[${i}] needs path and profile, mcp or mcp_deny`);
212
- cfg.projects.push({ path: expandHome(path, env), ...(profile ? { profile } : {}), ...(mcp ? { mcp } : {}), ...(mcpDeny ? { mcpDeny } : {}) });
243
+ cfg.projects.push({
244
+ path: expandHome(path, env),
245
+ ...(profile ? { profile } : {}),
246
+ ...(mcp ? { mcp } : {}),
247
+ ...(mcpDeny ? { mcpDeny } : {}),
248
+ });
213
249
  }
214
250
  const open = table(raw.open, file, "open");
215
251
  unknownKeys(open, KNOWN_KEYS.open, "open.", warnings);
@@ -34,14 +34,6 @@ export function parseJsonObject(text, file) {
34
34
  throw new CliError(`${file} does not hold a JSON object; fix or remove it`);
35
35
  return v;
36
36
  }
37
- /** Whether a process is alive. EPERM means it exists but belongs to someone else. */
38
- export function pidAlive(pid) {
39
- try {
40
- process.kill(pid, 0);
41
- return true;
42
- }
43
- catch (err) {
44
- return err.code === "EPERM";
45
- }
46
- }
37
+ /** Whether a process is alive; shared with turno-browser. */
38
+ export { pidAlive } from "turno-core/process";
47
39
  //# sourceMappingURL=fsutil.js.map
@@ -1,7 +1,8 @@
1
- import { chmodSync, copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, rmdirSync, statSync, symlinkSync, writeFileSync } from "node:fs";
1
+ import { chmodSync, copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, rmdirSync, statSync, symlinkSync, writeFileSync, } from "node:fs";
2
2
  import { createHash } from "node:crypto";
3
3
  import { basename, dirname, join } from "node:path";
4
4
  import { PRIVATE_FILE_MODE, ensurePrivateDir, isPrivatePath, paths } from "./paths.js";
5
+ import { hasFields, readState } from "./state-file.js";
5
6
  /** Local "YYYYMMDD-HHMMSS". */
6
7
  export function stamp(d = new Date()) {
7
8
  const p = (n) => String(n).padStart(2, "0");
@@ -236,6 +237,8 @@ export class Journal {
236
237
  return this.used ? `undo with: turno undo ${this.stamp}` : undefined;
237
238
  }
238
239
  }
240
+ const isManifest = (v) => hasFields(v, { stamp: "string", command: "string", entries: "array" }) &&
241
+ v.entries.every((e) => hasFields(e, { path: "string" }));
239
242
  /** Backup folders, newest first. */
240
243
  export function listJournals(env) {
241
244
  const root = paths(env).backupsDir;
@@ -252,12 +255,9 @@ export function listJournals(env) {
252
255
  .reverse()
253
256
  .map((n) => {
254
257
  const dir = join(root, n);
255
- try {
256
- return { stamp: n, dir, manifest: JSON.parse(readFileSync(join(dir, MANIFEST), "utf8")) };
257
- }
258
- catch {
259
- return { stamp: n, dir };
260
- }
258
+ // No manifest, or one that cannot be used: the folder is shown as restore-by-hand.
259
+ const manifest = readState(join(dir, MANIFEST), isManifest, 1);
260
+ return manifest ? { stamp: n, dir, manifest } : { stamp: n, dir };
261
261
  });
262
262
  }
263
263
  function isEmptyDir(p) {
@@ -336,18 +336,26 @@ function planTreeEntry(e) {
336
336
  case "symlink":
337
337
  if (!st)
338
338
  return undefined;
339
- return st.isSymbolicLink() && readlinkSync(e.path) === e.target ? { path: e.path, action: "unlink" } : { path: e.path, action: "skip", reason: "no longer the link turno made; left as it is" };
339
+ return st.isSymbolicLink() && readlinkSync(e.path) === e.target
340
+ ? { path: e.path, action: "unlink" }
341
+ : { path: e.path, action: "skip", reason: "no longer the link turno made; left as it is" };
340
342
  case "unlink":
341
- return st ? { path: e.path, action: "skip", reason: `something else is there now; it linked to ${e.target}` } : { path: e.path, action: "link" };
343
+ return st
344
+ ? { path: e.path, action: "skip", reason: `something else is there now; it linked to ${e.target}` }
345
+ : { path: e.path, action: "link" };
342
346
  case "move":
343
347
  if (st)
344
348
  return { path: e.path, action: "skip", reason: `something is there now; the moved copy stays at ${e.to}` };
345
- return lstatOf(e.to) ? { path: e.path, action: "move", from: e.to } : { path: e.path, action: "skip", reason: `${e.to} is gone` };
349
+ return lstatOf(e.to)
350
+ ? { path: e.path, action: "move", from: e.to }
351
+ : { path: e.path, action: "skip", reason: `${e.to} is gone` };
346
352
  case "mkdir":
347
353
  if (!st)
348
354
  return undefined;
349
355
  // In a dry run nothing inside was removed yet: report the folder as removable.
350
- return st.isDirectory() ? { path: e.path, action: "rmdir" } : { path: e.path, action: "keep", reason: "not a folder any more" };
356
+ return st.isDirectory()
357
+ ? { path: e.path, action: "rmdir" }
358
+ : { path: e.path, action: "keep", reason: "not a folder any more" };
351
359
  case "rmdir":
352
360
  return st ? undefined : { path: e.path, action: "mkdir" };
353
361
  case "chmod":
@@ -233,6 +233,12 @@ export function parseManifest(text, file = "mcp.toml") {
233
233
  server.builtin = builtin;
234
234
  if (v.call_timeout !== undefined)
235
235
  server.callTimeout = parseDuration(v.call_timeout, file, `${key}.call_timeout`);
236
+ if (v.stop_grace !== undefined) {
237
+ const grace = parseDuration(v.stop_grace, file, `${key}.stop_grace`);
238
+ if (grace > MAX_STOP_GRACE)
239
+ throw new ConfigError(file, `${key}.stop_grace must be at most ${MAX_STOP_GRACE}s`);
240
+ server.stopGrace = grace;
241
+ }
236
242
  const tools = toolFilterOf(v.tools, file, `${key}.tools`);
237
243
  if (tools)
238
244
  server.tools = tools;
@@ -261,6 +267,24 @@ export function variantKey(server, profile) {
261
267
  return profile && server.variants[profile] ? profile : "default";
262
268
  }
263
269
  /** Effective launch settings for a variant. */
270
+ /** The MCP SDK's fixed wait between closing stdin and SIGTERM, in seconds. */
271
+ const SDK_STOP_GRACE = 2;
272
+ /** turno-browser-mcp closes Chrome within about 2.5 s of stdin closing; 5 s leaves room. */
273
+ const BROWSER_STOP_GRACE = 5;
274
+ const MAX_STOP_GRACE = 60;
275
+ /**
276
+ * Seconds mcpd gives a stdio server between closing its stdin and SIGTERM: its
277
+ * `stop_grace`, else 5 for turno-browser-mcp however it is started (a path, npx), else the
278
+ * SDK's 2.
279
+ */
280
+ export function effectiveStopGrace(server, variant) {
281
+ if (server.stopGrace !== undefined)
282
+ return server.stopGrace;
283
+ const { command, args } = effectiveLaunch(server, variant);
284
+ return [command, ...args].some((a) => a.split(/[\\/]/).pop() === "turno-browser-mcp")
285
+ ? BROWSER_STOP_GRACE
286
+ : SDK_STOP_GRACE;
287
+ }
264
288
  export function effectiveLaunch(server, variant) {
265
289
  const v = server.variants[variant];
266
290
  const out = {
@@ -280,7 +304,10 @@ export function toolFilterFor(server, profile) {
280
304
  return v ? { ...base, ...v } : base;
281
305
  }
282
306
  function globRegExp(pattern) {
283
- const body = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
307
+ const body = pattern
308
+ .replace(/[.+^${}()|[\]\\]/g, "\\$&")
309
+ .replace(/\*/g, ".*")
310
+ .replace(/\?/g, ".");
284
311
  return new RegExp(`^${body}$`);
285
312
  }
286
313
  /** Whether a tool passes a filter. */
@@ -1,11 +1,9 @@
1
- import { accessSync, chmodSync, closeSync, constants, fchmodSync, fstatSync, mkdirSync, openSync, statSync, writeSync } from "node:fs";
2
- import { homedir } from "node:os";
3
- import { delimiter, dirname, isAbsolute, join, normalize, relative, sep } from "node:path";
1
+ import { isAbsolute, join, normalize } from "node:path";
2
+ import { browserPaths, turnoRoots } from "turno-core/paths";
3
+ // The roots, private folders and PATH lookup are shared with turno-browser.
4
+ export { PRIVATE_DIR_MODE, PRIVATE_FILE_MODE, ensurePrivateDir, findOnPath, isPrivatePath, privateRoots, resetPrivateDirCache, writePrivateFile, } from "turno-core/paths";
4
5
  export function paths(env) {
5
- const home = env.HOME || homedir();
6
- const config = env.TURNO_CONFIG_DIR || join(env.XDG_CONFIG_HOME || join(home, ".config"), "turno");
7
- const state = env.TURNO_STATE_DIR || join(env.XDG_STATE_HOME || join(home, ".local", "state"), "turno");
8
- const data = env.TURNO_DATA_DIR || join(env.XDG_DATA_HOME || join(home, ".local", "share"), "turno");
6
+ const { home, config, state, data } = turnoRoots(env);
9
7
  return {
10
8
  home,
11
9
  hub: env.TURNO_HUB || join(home, ".claude"),
@@ -29,7 +27,7 @@ export function paths(env) {
29
27
  mcpdManaged: join(state, "mcp-managed.json"),
30
28
  mcpdCacheDir: join(data, "mcpd", "cache"),
31
29
  serversDir: join(data, "servers"),
32
- browserDir: join(data, "browser"),
30
+ browserDir: browserPaths(env).browserDir,
33
31
  chromeProfilesDir: join(data, "chrome"),
34
32
  legacyConfig: join(home, ".config", "claudio"),
35
33
  };
@@ -54,108 +52,4 @@ export function expandHome(p, env) {
54
52
  return join(home, p.slice(2));
55
53
  return p;
56
54
  }
57
- /** Mode of every directory turno creates under its own config, state and data roots. */
58
- export const PRIVATE_DIR_MODE = 0o700;
59
- /** Mode of every file turno writes under those roots (logs, accounts.toml, audit log, mcpd.port). */
60
- export const PRIVATE_FILE_MODE = 0o600;
61
- /** turno's own roots (config, state, data): what `ensurePrivateDir` locks down. */
62
- export function privateRoots(env) {
63
- const p = paths(env);
64
- return [p.config, p.state, p.data];
65
- }
66
- function within(file, root) {
67
- const rel = relative(root, file);
68
- return rel === "" || (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));
69
- }
70
- /** The turno root (config, state or data) that holds `file`, if any. */
71
- function rootOf(file, env) {
72
- return privateRoots(env).find((root) => within(file, root));
73
- }
74
- /** True when `file` is one of turno's roots or lies inside one. */
75
- export function isPrivatePath(file, env) {
76
- return rootOf(file, env) !== undefined;
77
- }
78
- /** Roots already checked by this process (tests switch HOME, so the key is the path). */
79
- const lockedRoots = new Set();
80
- function lockRoot(root) {
81
- if (lockedRoots.has(root))
82
- return;
83
- // Parents such as ~/.config keep the default mode; only turno's own folder is private.
84
- mkdirSync(dirname(root), { recursive: true });
85
- try {
86
- mkdirSync(root, { mode: PRIVATE_DIR_MODE });
87
- }
88
- catch (err) {
89
- if (err.code !== "EEXIST")
90
- throw err;
91
- }
92
- const st = statSync(root);
93
- if ((st.mode & 0o777) !== PRIVATE_DIR_MODE && st.uid === process.getuid?.())
94
- chmodSync(root, PRIVATE_DIR_MODE);
95
- lockedRoots.add(root);
96
- }
97
- /**
98
- * Create `dir` (and its parents) for turno's own state. Inside turno's config, state and data
99
- * roots every folder is created 0700, and an existing root with a wider mode is narrowed to
100
- * 0700 the first time a process uses it. Other folders are created with the default mode.
101
- * Returns `dir`.
102
- */
103
- export function ensurePrivateDir(dir, env) {
104
- const root = rootOf(dir, env);
105
- if (!root) {
106
- mkdirSync(dir, { recursive: true });
107
- return dir;
108
- }
109
- lockRoot(root);
110
- // Recursive mkdir applies the mode to every folder it creates, the root included if it vanished.
111
- mkdirSync(dir, { recursive: true, mode: PRIVATE_DIR_MODE });
112
- return dir;
113
- }
114
- /**
115
- * Write a small file turno keeps for itself (a mark, a cache, a state file): its folder through
116
- * `ensurePrivateDir`, the file created 0600, and narrowed to 0600 when an older turno left it
117
- * wider. Not atomic; use the journal's `atomicWrite` for files a reader must never see half written.
118
- */
119
- export function writePrivateFile(file, data, env) {
120
- ensurePrivateDir(dirname(file), env);
121
- const fd = openSync(file, "w", PRIVATE_FILE_MODE);
122
- try {
123
- if (fstatSync(fd).mode & 0o077)
124
- fchmodSync(fd, PRIVATE_FILE_MODE);
125
- writeSync(fd, data);
126
- }
127
- finally {
128
- closeSync(fd);
129
- }
130
- }
131
- /** Forget which roots were checked (tests). */
132
- export function resetPrivateDirCache() {
133
- lockedRoots.clear();
134
- }
135
- /** The first executable called `name` on the PATH of `env`, or undefined. */
136
- export function findOnPath(name, env) {
137
- if (name.includes("/")) {
138
- try {
139
- accessSync(name, constants.X_OK);
140
- return name;
141
- }
142
- catch {
143
- return undefined;
144
- }
145
- }
146
- for (const dir of (env.PATH ?? "").split(delimiter)) {
147
- if (!dir)
148
- continue;
149
- const file = join(dir, name);
150
- try {
151
- accessSync(file, constants.X_OK);
152
- if (statSync(file).isFile())
153
- return file;
154
- }
155
- catch {
156
- /* next */
157
- }
158
- }
159
- return undefined;
160
- }
161
55
  //# sourceMappingURL=paths.js.map
@@ -59,7 +59,12 @@ export function configFindings(config, env) {
59
59
  };
60
60
  const out = (config.warnings ?? []).map((text) => {
61
61
  const m = /^unknown key ([^\s;]+)(?: \(did you mean ([^\s?]+)\?\))?/.exec(text);
62
- return { text, ...(m ? edit(m[1], m[2] ? `rename it to ${m[2].slice(m[2].lastIndexOf(".") + 1)}` : "remove it") : { hint: "turno config edit" }) };
62
+ return {
63
+ text,
64
+ ...(m
65
+ ? edit(m[1], m[2] ? `rename it to ${m[2].slice(m[2].lastIndexOf(".") + 1)}` : "remove it")
66
+ : { hint: "turno config edit" }),
67
+ };
63
68
  });
64
69
  const known = new Set(listProfiles(config, env));
65
70
  const missing = (where, name) => {
@@ -76,7 +81,10 @@ export function configFindings(config, env) {
76
81
  const name = roles?.[role];
77
82
  if (name && known.has(name) && agentOf(name, config) !== id) {
78
83
  const label = adapter(id).label;
79
- out.push({ text: `agents.${id}.${role} = "${name}", but ${name} is a ${adapter(agentOf(name, config)).label} profile`, ...edit(`agents.${id}.${role}`, `name a ${label} profile`) });
84
+ out.push({
85
+ text: `agents.${id}.${role} = "${name}", but ${name} is a ${adapter(agentOf(name, config)).label} profile`,
86
+ ...edit(`agents.${id}.${role}`, `name a ${label} profile`),
87
+ });
80
88
  }
81
89
  }
82
90
  }
@@ -84,12 +92,18 @@ export function configFindings(config, env) {
84
92
  const name = config[role];
85
93
  if (name && known.has(name) && agentOf(name, config) !== DEFAULT_AGENT) {
86
94
  const other = agentOf(name, config);
87
- out.push({ text: `${role} = "${name}" is for ${adapter(DEFAULT_AGENT).label}, but ${name} is a ${adapter(other).label} profile`, ...edit(role, `move it to [agents.${other}]`) });
95
+ out.push({
96
+ text: `${role} = "${name}" is for ${adapter(DEFAULT_AGENT).label}, but ${name} is a ${adapter(other).label} profile`,
97
+ ...edit(role, `move it to [agents.${other}]`),
98
+ });
88
99
  }
89
100
  }
90
101
  for (const [i, rule] of config.projects.entries()) {
91
102
  if (rule.profile && !known.has(rule.profile))
92
- out.push({ text: `the rule for ${tildify(rule.path, env)} uses profile ${rule.profile}, which does not exist`, hint: `turno profile add ${rule.profile}` });
103
+ out.push({
104
+ text: `the rule for ${tildify(rule.path, env)} uses profile ${rule.profile}, which does not exist`,
105
+ hint: `turno profile add ${rule.profile}`,
106
+ });
93
107
  out.push(...folderSetFindings(rule, i, env, edit));
94
108
  }
95
109
  return out;
@@ -138,7 +152,7 @@ function keyLine(lines, key) {
138
152
  return undefined;
139
153
  }
140
154
  /**
141
- * Folder server sets (ADR 0031) checked against mcp.toml: names it does not declare, and
155
+ * Folder server sets checked against mcp.toml: names it does not declare, and
142
156
  * remote servers that skip mcpd, which a set cannot hide. Nothing when mcp.toml is missing or
143
157
  * broken (its own check reports that).
144
158
  */
@@ -155,7 +169,10 @@ function folderSetFindings(rule, index, env, edit) {
155
169
  const declared = Object.keys(servers);
156
170
  const out = [];
157
171
  const where = `the rule for ${tildify(rule.path, env)}`;
158
- for (const [key, list] of [["mcp", rule.mcp], ["mcp_deny", rule.mcpDeny]]) {
172
+ for (const [key, list] of [
173
+ ["mcp", rule.mcp],
174
+ ["mcp_deny", rule.mcpDeny],
175
+ ]) {
159
176
  for (const name of list ?? []) {
160
177
  if (servers[name])
161
178
  continue;
@@ -169,7 +186,9 @@ function folderSetFindings(rule, index, env, edit) {
169
186
  for (const [name, def] of Object.entries(servers)) {
170
187
  const hidden = (rule.mcp && !rule.mcp.includes(name)) || rule.mcpDeny?.includes(name);
171
188
  if (hidden && def.kind === "remote" && !def.proxy) {
172
- const fix = rule.mcpDeny?.includes(name) ? edit(`projects[${index}].mcp_deny`, `remove ${name}`) : edit(`projects[${index}].mcp`, `add ${name}`);
189
+ const fix = rule.mcpDeny?.includes(name)
190
+ ? edit(`projects[${index}].mcp_deny`, `remove ${name}`)
191
+ : edit(`projects[${index}].mcp`, `add ${name}`);
173
192
  out.push({ text: `${where} cannot hide ${name}: it is a remote server that does not pass through mcpd`, ...fix });
174
193
  }
175
194
  }
@@ -186,6 +205,7 @@ export function profileFromConfigDir(configDir, config, env) {
186
205
  if (dir !== p.hub)
187
206
  return undefined;
188
207
  }
189
- return config.system;
208
+ // system = "" says the hub is no profile's account.
209
+ return config.system || undefined;
190
210
  }
191
211
  //# sourceMappingURL=profiles.js.map
@@ -33,7 +33,13 @@ function gitCommonDirBySpawn(cwd) {
33
33
  }
34
34
  const UNSURE = Symbol("unsure");
35
35
  /** Variables that change how git finds a repository: with any of them set, git itself decides. */
36
- const GIT_DISCOVERY_VARS = ["GIT_DIR", "GIT_COMMON_DIR", "GIT_WORK_TREE", "GIT_CEILING_DIRECTORIES", "GIT_DISCOVERY_ACROSS_FILESYSTEM"];
36
+ const GIT_DISCOVERY_VARS = [
37
+ "GIT_DIR",
38
+ "GIT_COMMON_DIR",
39
+ "GIT_WORK_TREE",
40
+ "GIT_CEILING_DIRECTORIES",
41
+ "GIT_DISCOVERY_ACROSS_FILESYSTEM",
42
+ ];
37
43
  function stat(p) {
38
44
  try {
39
45
  return statSync(p);
@@ -120,7 +126,7 @@ function covers(root, folder) {
120
126
  return folder === root || folder.startsWith(root + sep);
121
127
  }
122
128
  /**
123
- * The MCP server set of a folder (ADR 0031): among the rules that have `mcp` or `mcp_deny` and
129
+ * The MCP server set of a folder: among the rules that have `mcp` or `mcp_deny` and
124
130
  * cover one of `roots` (the folder, and the main repository of a worktree), the one with the
125
131
  * longest path. On a tie, the rule of `profile`, else the first one in the file. A rule without
126
132
  * a set says nothing about servers, so a nested profile rule does not clear a parent's set.
@@ -134,7 +140,11 @@ export function folderMcpSet(roots, rules, profile) {
134
140
  if (!roots.some((c) => covers(root, c)))
135
141
  continue;
136
142
  const longer = !best || root.length > best.root.length;
137
- const preferred = best && root.length === best.root.length && profile !== undefined && rule.profile === profile && best.rule.profile !== profile;
143
+ const preferred = best &&
144
+ root.length === best.root.length &&
145
+ profile !== undefined &&
146
+ rule.profile === profile &&
147
+ best.rule.profile !== profile;
138
148
  if (longer || preferred)
139
149
  best = { rule, root };
140
150
  }