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
@@ -6,11 +6,14 @@ import { Journal } from "../../core/journal.js";
6
6
  import { paths, writePrivateFile } from "../../core/paths.js";
7
7
  import { listProfiles } from "../../core/profiles.js";
8
8
  import { fetchLatest, isSemver, updateChecksOff } from "../../core/update.js";
9
- import { compareVersions, detectInstall, packageInfo, upgradeCommand } from "../../core/version.js";
10
- import { DRY_RUN, JSON_FLAG, bool, parseFlags, printJson, str } from "../args.js";
9
+ import { ONE_OFF_RUNNERS, compareVersions, detectInstall, isOneOff, packageInfo, upgradeCommand, } from "../../core/version.js";
10
+ import { DRY_RUN, JSON_FLAG, bool, parseFlags, str } from "../args.js";
11
+ import { emit, jsonOutput } from "../output.js";
11
12
  import { confirm, fail } from "../io.js";
12
13
  import { findOnPath, launcherPath } from "../launch.js";
13
14
  import { turnoCommand, isGenerated, writeHelperLaunchers, writeLauncher } from "../launchers.js";
15
+ /** `turno upgrade --check --json`. */
16
+ const CHECK_JSON = jsonOutput(["current", "latest", "channel", "method", "updateAvailable", "error", "note"]);
14
17
  const USAGE = `Usage:
15
18
  turno upgrade [--channel latest|next] [--to <version>] [--dry-run] [--yes]
16
19
  install the newest release with the tool that installed turno
@@ -20,9 +23,16 @@ const USAGE = `Usage:
20
23
  When agent configs need a new gateway token, --finish offers to run turno mcp sync (in a
21
24
  terminal it asks; --yes runs it without asking).
22
25
 
23
- turno knows how it was installed (npm, pnpm, yarn, bun, volta, or a git checkout) and runs the
24
- matching command. Once a day interactive commands look for a new release in the background and
25
- mention it once; set update_check = false in config.toml or TURNO_NO_UPDATE_CHECK=1 to stop that.`;
26
+ turno knows how it was installed (npm, pnpm, yarn, bun, volta, Homebrew, or a git checkout) and
27
+ runs the matching command. A copy that npx, pnpm dlx or bunx runs once has nothing to upgrade:
28
+ the next run of that runner with @latest gets the newest release. Once a day interactive commands look for a new release in the background and
29
+ mention it once; set update_check = false in config.toml or TURNO_NO_UPDATE_CHECK=1 to stop that.
30
+
31
+ Examples:
32
+ $ turno upgrade --check
33
+ $ turno upgrade
34
+ $ turno upgrade --dry-run --to 1.2.3
35
+ $ turno upgrade --finish`;
26
36
  function versionFile(env) {
27
37
  return join(paths(env).state, "version");
28
38
  }
@@ -87,7 +97,7 @@ export async function finishUpgrade(io, opts = {}) {
87
97
  const hint = journal.hint();
88
98
  if (hint)
89
99
  io.out(hint);
90
- // Configs synced before per-profile gateway tokens (ADR 0023) send the master token, which
100
+ // Configs synced before per-profile gateway tokens send the master token, which
91
101
  // mcpd refuses for MCP sessions: say so here instead of leaving it to the first failed call.
92
102
  const tokens = (await import("../../mcpd/health.js")).tokenSyncCheck(env);
93
103
  if (tokens) {
@@ -139,80 +149,107 @@ export const command = {
139
149
  summary: "update turno to the newest release (or check for one)",
140
150
  usage: USAGE,
141
151
  flags: ["--check", "--channel", "--to", "--dry-run", "--json", "--finish", "--yes"],
142
- async run(args, io) {
143
- const p = parseFlags(args, { check: { type: "boolean" }, finish: { type: "boolean" }, yes: { type: "boolean", short: "y" }, channel: { type: "string" }, to: { type: "string" }, ...DRY_RUN, ...JSON_FLAG }, 0);
144
- const yes = bool(p, "yes");
145
- if (bool(p, "finish"))
146
- return finishUpgrade(io, { sync: yes ? "yes" : "ask" });
147
- const to = str(p, "to");
148
- if (to !== undefined && !isSemver(to))
149
- fail(`--to needs a version like 1.2.3 (got "${to}")`);
150
- if (!/^[a-z][a-z0-9-]{0,63}$/.test(str(p, "channel") ?? "latest"))
151
- fail("--channel needs a dist-tag such as latest or next");
152
- const pkg = packageInfo();
153
- const install = detectInstall();
154
- const channel = str(p, "channel") ?? "latest";
155
- const off = updateChecksOff(io.env);
156
- const fromRegistry = install.method !== "source" && install.method !== "unknown";
157
- if (bool(p, "check")) {
158
- if (pkg.private || !fromRegistry) {
159
- const why = pkg.private ? "this copy is not published to a registry" : `installed from ${install.method}`;
160
- if (bool(p, "json"))
161
- printJson(io, { current: pkg.version, latest: null, method: install.method, note: why });
162
- else
163
- io.out(`turno ${pkg.version} (${why}; turno upgrade pulls the source)`);
164
- return 0;
165
- }
166
- const s = await fetchLatest(io.env, channel);
167
- const newer = s.latest && compareVersions(s.latest, pkg.version) > 0;
152
+ json: CHECK_JSON,
153
+ run: (args, io) => runUpgrade(args, io),
154
+ };
155
+ /** `turno upgrade`; `deps.install` stands for how this turno was installed, for tests. */
156
+ export async function runUpgrade(args, io, deps = {}) {
157
+ const p = parseFlags(args, {
158
+ check: { type: "boolean" },
159
+ finish: { type: "boolean" },
160
+ yes: { type: "boolean", short: "y" },
161
+ channel: { type: "string" },
162
+ to: { type: "string" },
163
+ ...DRY_RUN,
164
+ ...JSON_FLAG,
165
+ }, 0);
166
+ const yes = bool(p, "yes");
167
+ if (bool(p, "finish"))
168
+ return finishUpgrade(io, { sync: yes ? "yes" : "ask" });
169
+ const to = str(p, "to");
170
+ if (to !== undefined && !isSemver(to))
171
+ fail(`--to needs a version like 1.2.3 (got "${to}")`);
172
+ if (!/^[a-z][a-z0-9-]{0,63}$/.test(str(p, "channel") ?? "latest"))
173
+ fail("--channel needs a dist-tag such as latest or next");
174
+ const pkg = packageInfo();
175
+ const install = deps.install ?? detectInstall();
176
+ const channel = str(p, "channel") ?? "latest";
177
+ const off = updateChecksOff(io.env);
178
+ const fromRegistry = install.method !== "source" && install.method !== "unknown";
179
+ if (bool(p, "check")) {
180
+ if (pkg.private || !fromRegistry) {
181
+ const why = pkg.private ? "this copy is not published to a registry" : `installed from ${install.method}`;
168
182
  if (bool(p, "json"))
169
- printJson(io, { current: pkg.version, latest: s.latest ?? null, channel, method: install.method, updateAvailable: Boolean(newer), error: s.error ?? null });
170
- else if (s.error)
171
- io.out(`could not reach the registry: ${s.error}`);
183
+ emit(io, p, CHECK_JSON, { current: pkg.version, latest: null, method: install.method, note: why });
172
184
  else
173
- io.out(newer ? `turno ${s.latest} is available (you have ${pkg.version}): turno upgrade` : `turno ${pkg.version} is the newest on ${channel}`);
174
- return s.error ? 1 : 0;
175
- }
176
- if (fromRegistry && off === "this copy is not published to a registry")
177
- fail("this copy is not published to a registry");
178
- let spec = str(p, "to") ?? channel;
179
- if (fromRegistry && !str(p, "to")) {
180
- const s = await fetchLatest(io.env, channel);
181
- if (s.error)
182
- fail(`could not reach the registry: ${s.error}`);
183
- if (s.latest && compareVersions(s.latest, pkg.version) <= 0) {
184
- io.out(`turno ${pkg.version} is already the newest on ${channel}`);
185
- return 0;
186
- }
187
- spec = s.latest ?? channel;
185
+ io.out(`turno ${pkg.version} (${why}; turno upgrade pulls the source)`);
186
+ return 0;
188
187
  }
189
- // Whatever reaches the package manager is a plain version or a dist-tag, never a URL or range.
190
- if (!isSemver(spec) && !/^[a-z][a-z0-9-]{0,63}$/.test(spec))
191
- fail(`refusing to install "${spec}": not a version`);
192
- const steps = upgradeCommand(install, pkg.name, spec);
193
- if (!steps)
194
- return fail(`cannot tell how turno was installed (${install.root}); reinstall it with your package manager`);
195
- for (const step of steps) {
196
- io.out(`$ ${step.join(" ")}`);
197
- if (bool(p, "dry-run"))
198
- continue;
199
- const r = spawnSync(step[0], step.slice(1), { stdio: "inherit", env: io.env });
200
- if (r.status !== 0) {
201
- io.err(`turno: ${step[0]} failed (exit ${r.status ?? r.signal}); nothing else was changed`);
202
- return 1;
203
- }
188
+ const s = await fetchLatest(io.env, channel);
189
+ const newer = s.latest && compareVersions(s.latest, pkg.version) > 0;
190
+ if (bool(p, "json"))
191
+ emit(io, p, CHECK_JSON, {
192
+ current: pkg.version,
193
+ latest: s.latest ?? null,
194
+ channel,
195
+ method: install.method,
196
+ updateAvailable: Boolean(newer),
197
+ error: s.error ?? null,
198
+ });
199
+ else if (s.error)
200
+ io.out(`could not reach the registry: ${s.error}`);
201
+ else
202
+ io.out(newer
203
+ ? `turno ${s.latest} is available (you have ${pkg.version}): turno upgrade`
204
+ : `turno ${pkg.version} is the newest on ${channel}`);
205
+ return s.error ? 1 : 0;
206
+ }
207
+ if (isOneOff(install.method)) {
208
+ // A copy in npx's (pnpm dlx's, bunx's) cache: nothing to replace, the runner fetches releases.
209
+ const once = ONE_OFF_RUNNERS[install.method];
210
+ io.out(`turno runs from ${once.runner}'s cache for this run: \`${once.latest}\` runs the newest release.`);
211
+ io.out(`To keep turno, install it: ${once.install}`);
212
+ return 0;
213
+ }
214
+ if (fromRegistry && off === "this copy is not published to a registry")
215
+ fail("this copy is not published to a registry");
216
+ let spec = str(p, "to") ?? channel;
217
+ if (fromRegistry && !str(p, "to")) {
218
+ const s = await fetchLatest(io.env, channel);
219
+ if (s.error)
220
+ fail(`could not reach the registry: ${s.error}`);
221
+ if (s.latest && compareVersions(s.latest, pkg.version) <= 0) {
222
+ io.out(`turno ${pkg.version} is already the newest on ${channel}`);
223
+ return 0;
204
224
  }
225
+ spec = s.latest ?? channel;
226
+ }
227
+ // Whatever reaches the package manager is a plain version or a dist-tag, never a URL or range.
228
+ if (!isSemver(spec) && !/^[a-z][a-z0-9-]{0,63}$/.test(spec))
229
+ fail(`refusing to install "${spec}": not a version`);
230
+ const steps = upgradeCommand(install, pkg.name, spec);
231
+ if (!steps)
232
+ return fail(`cannot tell how turno was installed (${install.root}); reinstall it with your package manager`);
233
+ for (const step of steps) {
234
+ io.out(`$ ${step.join(" ")}`);
205
235
  if (bool(p, "dry-run"))
206
- return 0;
207
- // The new files are in place: let the new version finish its own upgrade.
208
- const self = install.method === "source" ? process.argv[1] : findOnPath("turno", io.env);
209
- if (!self) {
210
- io.out("upgraded; run `turno upgrade --finish` to rewrite the launchers");
211
- return 0;
236
+ continue;
237
+ const r = spawnSync(step[0], step.slice(1), { stdio: "inherit", env: io.env });
238
+ if (r.status !== 0) {
239
+ io.err(`turno: ${step[0]} failed (exit ${r.status ?? r.signal}); nothing else was changed`);
240
+ return 1;
212
241
  }
213
- const finish = ["upgrade", "--finish", ...(yes ? ["--yes"] : [])];
214
- const r = spawnSync(install.method === "source" ? process.execPath : self, install.method === "source" ? [self, ...finish] : finish, { stdio: "inherit", env: io.env });
215
- return r.status ?? 1;
216
- },
217
- };
242
+ }
243
+ if (bool(p, "dry-run"))
244
+ return 0;
245
+ // The new files are in place: let the new version finish its own upgrade.
246
+ const self = install.method === "source" ? process.argv[1] : findOnPath("turno", io.env);
247
+ if (!self) {
248
+ io.out("upgraded; run `turno upgrade --finish` to rewrite the launchers");
249
+ return 0;
250
+ }
251
+ const finish = ["upgrade", "--finish", ...(yes ? ["--yes"] : [])];
252
+ const r = spawnSync(install.method === "source" ? process.execPath : self, install.method === "source" ? [self, ...finish] : finish, { stdio: "inherit", env: io.env });
253
+ return r.status ?? 1;
254
+ }
218
255
  //# sourceMappingURL=upgrade.js.map
@@ -1,5 +1,5 @@
1
1
  import { execFile } from "node:child_process";
2
- import { readFileSync, statSync } from "node:fs";
2
+ import { statSync } from "node:fs";
3
3
  import { join } from "node:path";
4
4
  import { loadConfig } from "../../core/config.js";
5
5
  import { exhaustedUntil } from "../../core/exhausted.js";
@@ -7,6 +7,7 @@ import { isObject, readJsonFile } from "../../core/fsutil.js";
7
7
  import { paths, profileDir, writePrivateFile } from "../../core/paths.js";
8
8
  import { listProfiles } from "../../core/profiles.js";
9
9
  import { profileColor, style } from "../style.js";
10
+ import { isRecord, readState } from "../../core/state-file.js";
10
11
  /** Why `claude auth status` gave no answer, in a few words for the account column. */
11
12
  function authFailure(err, stdout, stderr) {
12
13
  if (err?.code === "ENOENT")
@@ -101,14 +102,10 @@ function authStatusResult(profile, env = process.env) {
101
102
  export async function authStatus(profile, env = process.env) {
102
103
  return (await authStatusResult(profile, env)).status;
103
104
  }
105
+ /** The status line's usage snapshot: its windows are read field by field, so the shape check is light. */
106
+ const isSnapshot = (v) => isRecord(v) && (v.rate_limits === undefined || isRecord(v.rate_limits));
104
107
  function readSnapshot(file) {
105
- try {
106
- const v = JSON.parse(readFileSync(file, "utf8"));
107
- return v && typeof v === "object" ? v : undefined;
108
- }
109
- catch {
110
- return undefined;
111
- }
108
+ return readState(file, isSnapshot);
112
109
  }
113
110
  /** The newer of the snapshot in the state dir and the one the bash tool's status line wrote. */
114
111
  export function usageSnapshot(profile, env = process.env) {
@@ -190,14 +187,18 @@ export function renderUsage(profiles, accounts, io, opts = {}) {
190
187
  if (reset && reset < now)
191
188
  pct = 0;
192
189
  const when = reset ? resetText(reset, now) : "";
193
- out.push(s.wrap(` ${s.muted(label.padEnd(7))} ${s.bar(pct, BAR_CELLS)} `, pct >= 100 ? s.err(`used up, ${when}`) : s.muted(when)).trimEnd());
190
+ out.push(s
191
+ .wrap(` ${s.muted(label.padEnd(7))} ${s.bar(pct, BAR_CELLS)} `, pct >= 100 ? s.err(`used up, ${when}`) : s.muted(when))
192
+ .trimEnd());
194
193
  }
195
194
  const exhausted = exhaustedUntil(p, io.env);
196
195
  if (exhausted !== undefined && exhausted > now) {
197
196
  out.push(s.note("err", `${s.err(`exhausted until ${shortTime(exhausted)}`)}${s.muted(": its projects open with the fallback, if one is set")}`));
198
197
  }
199
198
  if (!hasLimits) {
200
- const why = plan === "team" ? "the Team plan does not report these limits" : "shows up once a session of this account gets a response";
199
+ const why = plan === "team"
200
+ ? "the Team plan does not report these limits"
201
+ : "shows up once a session of this account gets a response";
201
202
  out.push(s.muted(` no usage data yet: ${why}`));
202
203
  }
203
204
  if (hasLimits && typeof data.updated_at === "number")
@@ -1,25 +1,37 @@
1
1
  import { tildify } from "../../core/paths.js";
2
2
  import { availableUpdate } from "../../core/update.js";
3
- import { detectInstall, packageInfo } from "../../core/version.js";
4
- import { JSON_FLAG, bool, flagsOf, parseFlags, printJson } from "../args.js";
3
+ import { ONE_OFF_RUNNERS, detectInstall, isOneOff, packageInfo } from "../../core/version.js";
4
+ import { JSON_FLAG, bool, flagsOf, parseFlags } from "../args.js";
5
+ import { emit, jsonOutput } from "../output.js";
6
+ const JSON_OUT = jsonOutput(["name", "version", "node", "method", "path", "latest"]);
5
7
  export const command = {
6
8
  summary: "the turno version, how it was installed, and whether a newer one is known",
7
- usage: "Usage: turno version [--json]\n\nturno --version prints only the number.",
9
+ usage: "Usage: turno version [--json]\n\nturno --version prints only the number.\n\nExamples:\n $ turno version\n $ turno version --json",
8
10
  flags: flagsOf(JSON_FLAG),
11
+ json: JSON_OUT,
9
12
  async run(args, io) {
10
13
  const p = parseFlags(args, JSON_FLAG, 0);
11
14
  const pkg = packageInfo();
12
15
  const install = detectInstall();
13
16
  const latest = availableUpdate(io.env);
14
- // npx runs a temporary copy from its cache: upgrade and launchers must not rely on it.
15
- const npx = install.root.includes("/_npx/");
16
- const data = { name: pkg.name, version: pkg.version, node: process.versions.node, method: npx ? "npx" : install.method, path: tildify(install.root, io.env), latest: latest ?? null };
17
+ // npx, pnpm dlx and bunx run a temporary copy from their cache: upgrade and launchers must not rely on it.
18
+ const once = isOneOff(install.method) ? ONE_OFF_RUNNERS[install.method] : undefined;
19
+ const data = {
20
+ name: pkg.name,
21
+ version: pkg.version,
22
+ node: process.versions.node,
23
+ method: install.method,
24
+ path: tildify(install.root, io.env),
25
+ latest: latest ?? null,
26
+ };
17
27
  if (bool(p, "json")) {
18
- printJson(io, data);
28
+ emit(io, p, JSON_OUT, data);
19
29
  return 0;
20
30
  }
21
31
  io.out(`turno ${pkg.version}`);
22
- io.out(npx ? ` a temporary copy in npx's cache (${data.path}); install it with: npm install --global turno-cli` : ` installed with ${install.method} at ${data.path}`);
32
+ io.out(once
33
+ ? ` a temporary copy in ${once.runner}'s cache (${data.path}); install it with: ${once.install}`
34
+ : ` installed with ${install.method} at ${data.path}`);
23
35
  io.out(` node ${data.node}`);
24
36
  if (latest)
25
37
  io.out(` ${latest} is available: turno upgrade`);
@@ -1,11 +1,13 @@
1
- import { whichCommand } from "./profile.js";
1
+ import { flagsOf } from "../args.js";
2
+ import { WHICH_JSON, WHICH_SPEC, whichCommand } from "./profile.js";
2
3
  /** The 0.1 `turno which`; `which` is now an alias of `turno profile which`, which this runs. */
3
4
  export const command = {
4
5
  summary: "which account auto would use in a folder, and why",
5
- usage: "Usage: turno profile which [dir] [--json]\n\nExplains the profile resolution for a folder (default: the current one), for each agent.",
6
+ usage: "Usage: turno profile which [dir] [--json] [--check]\n\nExplains the profile resolution for a folder (default: the current one), for each agent.",
6
7
  hidden: true,
7
8
  args: ["dir"],
8
- flags: ["--json"],
9
+ flags: flagsOf(WHICH_SPEC),
10
+ json: WHICH_JSON,
9
11
  run: whichCommand,
10
12
  };
11
13
  //# sourceMappingURL=which.js.map
@@ -0,0 +1,184 @@
1
+ /**
2
+ * What `turno config path --all` and `turno doctor --report` show: every path turno uses, and a
3
+ * Markdown block for an issue with versions, agents, paths, mcpd and the doctor findings. Nothing
4
+ * here prints a token, a secret value or a variable's value: paths are shown with `~`, and the
5
+ * doctor findings already name secrets only by key.
6
+ */
7
+ import { execFile } from "node:child_process";
8
+ import { existsSync } from "node:fs";
9
+ import { arch, release } from "node:os";
10
+ import { join } from "node:path";
11
+ import { AGENT_IDS, adapter, agentHub, agentProfileDir } from "../agents/index.js";
12
+ import { loadConfig } from "../core/config.js";
13
+ import { paths, tildify } from "../core/paths.js";
14
+ import { agentOf, listProfiles } from "../core/profiles.js";
15
+ import { detectInstall, packageInfo } from "../core/version.js";
16
+ import { plistPath } from "../mcpd/launchd.js";
17
+ import { daemonFiles } from "../mcpd/state.js";
18
+ import { unitPath } from "../mcpd/systemd.js";
19
+ import { userFontDir } from "../ui/fonts.js";
20
+ import { compileCacheDir } from "./compile-cache.js";
21
+ import { findOnPath, launcherName } from "./launchers.js";
22
+ function configOrNone(env) {
23
+ try {
24
+ return loadConfig(env);
25
+ }
26
+ catch {
27
+ return undefined;
28
+ }
29
+ }
30
+ /**
31
+ * Every path turno uses on this machine, in a stable order: its own config, state and data, the
32
+ * launchers and the service file, each agent's hub, and each profile's folder and launcher.
33
+ */
34
+ export function allPaths(env, platform = process.platform) {
35
+ const p = paths(env);
36
+ const d = daemonFiles(env);
37
+ const out = [
38
+ { name: "config dir", path: p.config, about: "turno's configuration (TURNO_CONFIG_DIR)" },
39
+ { name: "config", path: p.configFile, about: "profiles, folder rules, defaults" },
40
+ { name: "mcp", path: p.mcpFile, about: "MCP servers behind mcpd" },
41
+ { name: "accounts", path: p.accountsFile, about: "service accounts (turno identity)" },
42
+ { name: "state dir", path: p.state, about: "state, logs and backups (TURNO_STATE_DIR)" },
43
+ { name: "backups", path: p.backupsDir, about: "the journal turno undo reads" },
44
+ { name: "logs", path: p.logsDir, about: "mcpd.log and calls.jsonl" },
45
+ { name: "mcpd log", path: d.log, about: "what mcpd did" },
46
+ { name: "call log", path: d.calls, about: "tool calls mcpd relayed (turno mcp log)" },
47
+ { name: "mcpd token", path: p.mcpdToken, about: "the gateway's master token (mode 600)" },
48
+ { name: "mcpd port", path: p.mcpdPort, about: "the port mcpd listens on" },
49
+ { name: "mcpd lock", path: d.lock, about: "the running mcpd's pid" },
50
+ {
51
+ name: "profile tokens",
52
+ path: join(p.state, "mcpd-tokens"),
53
+ about: "each profile's gateway token, for launchers",
54
+ },
55
+ { name: "managed entries", path: p.mcpdManaged, about: "agent config entries turno mcp sync wrote" },
56
+ { name: "run records", path: p.runDir, about: "which profile each launcher started" },
57
+ { name: "usage", path: p.usageDir, about: "usage snapshots for the status line" },
58
+ { name: "exhausted", path: p.exhaustedDir, about: "exhausted marks (turno limit)" },
59
+ { name: "audit log", path: p.auditLog, about: "accounts bridge audit log" },
60
+ { name: "data dir", path: p.data, about: "installed servers and browser data (TURNO_DATA_DIR)" },
61
+ { name: "servers", path: p.serversDir, about: "packages turno mcp install installed" },
62
+ { name: "descriptions", path: p.mcpdCacheDir, about: "cached tool lists of each server" },
63
+ { name: "browser", path: p.browserDir, about: "browser identities" },
64
+ {
65
+ name: "chrome profiles",
66
+ path: configOrNone(env)?.open.chromeDir ?? p.chromeProfilesDir,
67
+ about: "Chrome profiles of turno open",
68
+ },
69
+ { name: "compile cache", path: compileCacheDir(env), about: "Node's compiled code of turno" },
70
+ { name: "launchers", path: p.bin, about: "claude-<p>, codex-<p>, turno-auto, turno-open (TURNO_BIN)" },
71
+ ];
72
+ if (platform === "darwin")
73
+ out.push({ name: "service", path: plistPath(env), about: "the LaunchAgent that keeps mcpd running" });
74
+ if (platform === "linux")
75
+ out.push({ name: "service", path: unitPath(env), about: "the systemd user unit that keeps mcpd running" });
76
+ const fonts = userFontDir(env, platform);
77
+ if (fonts)
78
+ out.push({ name: "fonts", path: fonts, about: "the status line font (turno ui install)" });
79
+ out.push({ name: "claude config", path: p.hubConfig, about: "plain claude's .claude.json (TURNO_HUB_CONFIG)" });
80
+ for (const id of AGENT_IDS)
81
+ out.push({
82
+ name: `${id} hub`,
83
+ path: agentHub(id, env),
84
+ about: `${adapter(id).label}'s own folder, shared by its profiles`,
85
+ });
86
+ const config = configOrNone(env);
87
+ if (config) {
88
+ for (const name of listProfiles(config, env)) {
89
+ const agent = agentOf(name, config);
90
+ out.push({
91
+ name: `profile ${name}`,
92
+ path: agentProfileDir(name, agent, env),
93
+ about: `${adapter(agent).label} profile folder`,
94
+ });
95
+ out.push({ name: `launcher ${name}`, path: join(p.bin, launcherName(name, agent)), about: `opens ${name}` });
96
+ }
97
+ }
98
+ if (existsSync(p.legacyConfig))
99
+ out.push({
100
+ name: "legacy config",
101
+ path: p.legacyConfig,
102
+ about: "the bash claudio config (turno migrate reads it)",
103
+ });
104
+ return out;
105
+ }
106
+ /** `<command> --version`, first line, or undefined when it does not answer within 3 s. */
107
+ function versionOf(file, env) {
108
+ return new Promise((resolve) => {
109
+ execFile(file, ["--version"], { env, timeout: 3000, encoding: "utf8" }, (err, stdout) => {
110
+ const line = String(stdout ?? "")
111
+ .trim()
112
+ .split("\n")[0]
113
+ ?.trim();
114
+ resolve(err || !line ? undefined : line.slice(0, 80));
115
+ });
116
+ });
117
+ }
118
+ /** Markdown text in a table cell: no pipes or line breaks. */
119
+ const cell = (s) => s.replace(/\|/g, "\\|").replace(/\s*\n\s*/g, " ");
120
+ /**
121
+ * The `turno doctor --report` block: Markdown to paste in an issue. Profile and server names
122
+ * appear (they say which check is which); tokens, secret values and variable values never do.
123
+ */
124
+ export async function reportMarkdown(env, input, platform = process.platform) {
125
+ const t = (s) => tildify(s, env);
126
+ const pkg = packageInfo();
127
+ const install = detectInstall();
128
+ const config = configOrNone(env);
129
+ const profiles = config ? listProfiles(config, env) : [];
130
+ const byAgent = new Map();
131
+ for (const n of profiles)
132
+ byAgent.set(agentOf(n, config), (byAgent.get(agentOf(n, config)) ?? 0) + 1);
133
+ const agents = await Promise.all(AGENT_IDS.map(async (id) => {
134
+ const a = adapter(id);
135
+ const at = findOnPath(a.command, env);
136
+ return { id, label: a.label, command: a.command, at, version: at ? await versionOf(at, env) : undefined };
137
+ }));
138
+ const shell = env.SHELL ? env.SHELL.split("/").pop() : undefined;
139
+ const terminal = env.TERM_PROGRAM
140
+ ? `${env.TERM_PROGRAM}${env.TERM_PROGRAM_VERSION ? ` ${env.TERM_PROGRAM_VERSION}` : ""}`
141
+ : env.TERM;
142
+ const out = [
143
+ `### turno doctor${input.security ? " --security" : ""} --report`,
144
+ "",
145
+ "| | |",
146
+ "|---|---|",
147
+ `| turno | ${pkg.version} (${install.method}) |`,
148
+ `| node | ${process.versions.node} |`,
149
+ `| os | ${platform} ${release()} ${arch()} |`,
150
+ ...(shell ? [`| shell | ${cell(shell)} |`] : []),
151
+ ...(terminal ? [`| terminal | ${cell(terminal)} |`] : []),
152
+ `| config.toml | ${existsSync(paths(env).configFile) ? (config ? "parses" : "does not parse") : "none"} |`,
153
+ `| profiles | ${profiles.length ? [...byAgent].map(([id, n]) => `${n} ${id}`).join(", ") : "none"} |`,
154
+ "",
155
+ "**Agents**",
156
+ "",
157
+ "| agent | command | version | profiles |",
158
+ "|---|---|---|---|",
159
+ ...agents.map((a) => `| ${a.label} | ${a.at ? cell(t(a.at)) : `${a.command} (not found)`} | ${a.version ? cell(a.version) : "-"} | ${byAgent.get(a.id) ?? 0} |`),
160
+ "",
161
+ "**mcpd**",
162
+ "",
163
+ ];
164
+ const s = input.status;
165
+ if (input.mcpd.running && s) {
166
+ const instances = Array.isArray(s.instances) ? s.instances.length : 0;
167
+ const parts = [
168
+ `running on port ${input.mcpd.port}`,
169
+ typeof s.version === "string" ? `version ${s.version}` : "",
170
+ typeof s.startedAt === "string" ? `since ${s.startedAt}` : "",
171
+ `${typeof s.sessions === "number" ? s.sessions : 0} sessions`,
172
+ `${instances} server processes`,
173
+ ].filter(Boolean);
174
+ out.push(`- ${parts.join(", ")}`);
175
+ }
176
+ else
177
+ out.push(`- ${cell(input.mcpd.text)}`);
178
+ const c = input.counts;
179
+ out.push("", "**Doctor**", "", `- ${c.ok} ok, ${c.warn} warnings, ${c.fail} failures, ${c.skip} skipped`, ...input.checks
180
+ .filter((x) => x.status === "warn" || x.status === "fail")
181
+ .map((x) => `- ${x.status}: ${cell(x.text)}${x.fix ? ` (fix: \`${cell(x.fix)}\`)` : ""}`), "", "<details><summary>Paths</summary>", "", "| name | path | exists |", "|---|---|---|", ...allPaths(env, platform).map((e) => `| ${cell(e.name)} | ${cell(t(e.path))} | ${existsSync(e.path) ? "yes" : "no"} |`), "", "</details>");
182
+ return out;
183
+ }
184
+ //# sourceMappingURL=diagnostics.js.map
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The exit codes turno promises, for scripts, hooks and status lines. Keep this file
3
+ * free of imports: io.ts and every command load it.
4
+ */
5
+ export const Exit = {
6
+ /** Done. */
7
+ ok: 0,
8
+ /** It did not work: the message says why. */
9
+ failure: 1,
10
+ /** The command line was wrong (unknown command or flag, missing argument, a question nobody can answer). */
11
+ usage: 2,
12
+ /** No profile for the folder: no rule and no default, or a rule naming a profile that does not exist. */
13
+ noProfile: 3,
14
+ /** The profile exists but its account is not signed in. */
15
+ notSignedIn: 4,
16
+ /** The gateway (mcpd) does not answer. */
17
+ gatewayDown: 5,
18
+ /** The agent's own command is not installed (the shell's "command not found"). */
19
+ notInstalled: 127,
20
+ /** Cancelled by the person (Ctrl-C or Esc in a picker), as shells report SIGINT. */
21
+ cancelled: 130,
22
+ };
23
+ /** The stable name of each code, as `--json` errors carry it (`"code": "no_profile"`). */
24
+ const NAMES = {
25
+ 0: "ok",
26
+ 1: "failure",
27
+ 2: "usage",
28
+ 3: "no_profile",
29
+ 4: "not_signed_in",
30
+ 5: "gateway_down",
31
+ 127: "not_installed",
32
+ 130: "cancelled",
33
+ };
34
+ /** The name of an exit code; "failure" for a code outside the contract. */
35
+ export function exitName(code) {
36
+ return NAMES[code] ?? "failure";
37
+ }
38
+ /** One row per code for `turno help exit-codes`: code, name, meaning. */
39
+ export const EXIT_ROWS = [
40
+ [Exit.ok, "ok", "done"],
41
+ [Exit.failure, "failure", "it did not work; the message on stderr says why"],
42
+ [
43
+ Exit.usage,
44
+ "usage",
45
+ "the command line was wrong: an unknown command or flag, a missing argument, or a question nobody can answer (no terminal, --no-input)",
46
+ ],
47
+ [
48
+ Exit.noProfile,
49
+ "no_profile",
50
+ "no profile for this folder: no rule and no default, or a rule naming a profile that does not exist (turno auto, turno profile which --check)",
51
+ ],
52
+ [
53
+ Exit.notSignedIn,
54
+ "not_signed_in",
55
+ "the folder's profile exists but its account is not signed in (turno profile which --check)",
56
+ ],
57
+ [
58
+ Exit.gatewayDown,
59
+ "gateway_down",
60
+ "the gateway (mcpd) does not answer (turno mcp daemon status, turno mcp top, turno mcp savings)",
61
+ ],
62
+ [Exit.notInstalled, "not_installed", "the agent's own command is not installed (turno auto with no profile to open)"],
63
+ [Exit.cancelled, "cancelled", "cancelled by you: Ctrl-C, or Esc in a profile list"],
64
+ ];
65
+ //# sourceMappingURL=exit.js.map