turno-cli 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/CHANGELOG.md +432 -0
  2. package/README.md +228 -73
  3. package/dist/accounts/audit.js +154 -12
  4. package/dist/accounts/builtin.js +100 -25
  5. package/dist/accounts/delegate.js +199 -35
  6. package/dist/accounts/policy.js +79 -0
  7. package/dist/accounts/registry.js +39 -21
  8. package/dist/agents/adapter.js +29 -0
  9. package/dist/agents/claude.js +246 -0
  10. package/dist/agents/codex.js +186 -0
  11. package/dist/agents/copilot.js +56 -0
  12. package/dist/agents/cursor.js +58 -0
  13. package/dist/agents/index.js +26 -86
  14. package/dist/agents/snippets.js +43 -13
  15. package/dist/cli/args.js +38 -6
  16. package/dist/cli/commands/accounts.js +119 -52
  17. package/dist/cli/commands/auto.js +121 -33
  18. package/dist/cli/commands/browser-identity.js +514 -0
  19. package/dist/cli/commands/browser-session.js +102 -0
  20. package/dist/cli/commands/browser-vault.js +193 -0
  21. package/dist/cli/commands/browser.js +319 -138
  22. package/dist/cli/commands/complete.js +14 -3
  23. package/dist/cli/commands/completion.js +8 -2
  24. package/dist/cli/commands/config.js +186 -24
  25. package/dist/cli/commands/demo.js +321 -0
  26. package/dist/cli/commands/doctor.js +525 -123
  27. package/dist/cli/commands/handoff.js +33 -22
  28. package/dist/cli/commands/identity.js +192 -54
  29. package/dist/cli/commands/init.js +648 -0
  30. package/dist/cli/commands/limit.js +84 -16
  31. package/dist/cli/commands/mcp-call.js +240 -0
  32. package/dist/cli/commands/mcp-oauth.js +221 -0
  33. package/dist/cli/commands/mcp-observe.js +539 -0
  34. package/dist/cli/commands/mcp-share.js +201 -0
  35. package/dist/cli/commands/mcp.js +816 -187
  36. package/dist/cli/commands/mcpd.js +388 -76
  37. package/dist/cli/commands/migrate.js +6 -4
  38. package/dist/cli/commands/open.js +115 -27
  39. package/dist/cli/commands/profile.js +396 -78
  40. package/dist/cli/commands/resolve.js +14 -3
  41. package/dist/cli/commands/run.js +36 -6
  42. package/dist/cli/commands/secret.js +80 -76
  43. package/dist/cli/commands/session.js +17 -6
  44. package/dist/cli/commands/sessions.js +48 -12
  45. package/dist/cli/commands/setup.js +214 -164
  46. package/dist/cli/commands/status.js +227 -44
  47. package/dist/cli/commands/statusline.js +311 -114
  48. package/dist/cli/commands/ui.js +78 -68
  49. package/dist/cli/commands/undo.js +193 -18
  50. package/dist/cli/commands/uninstall.js +481 -0
  51. package/dist/cli/commands/upgrade.js +172 -79
  52. package/dist/cli/commands/usage.js +125 -51
  53. package/dist/cli/commands/version.js +21 -7
  54. package/dist/cli/commands/which.js +9 -24
  55. package/dist/cli/compile-cache.js +32 -0
  56. package/dist/cli/diagnostics.js +184 -0
  57. package/dist/cli/exit.js +65 -0
  58. package/dist/cli/group.js +24 -12
  59. package/dist/cli/help.js +62 -0
  60. package/dist/cli/highlight.js +236 -0
  61. package/dist/cli/hints.js +30 -0
  62. package/dist/cli/io.js +186 -1
  63. package/dist/cli/launch.js +52 -39
  64. package/dist/cli/launchers.js +161 -95
  65. package/dist/cli/main.js +201 -31
  66. package/dist/cli/optional.js +144 -0
  67. package/dist/cli/output.js +123 -0
  68. package/dist/cli/picker.js +459 -0
  69. package/dist/cli/registry.js +61 -6
  70. package/dist/cli/safe.js +87 -0
  71. package/dist/cli/secret-input.js +63 -0
  72. package/dist/cli/security.js +561 -0
  73. package/dist/cli/style.js +311 -0
  74. package/dist/cli/topics.js +142 -0
  75. package/dist/core/config.js +181 -23
  76. package/dist/core/exhausted.js +6 -8
  77. package/dist/core/fsutil.js +39 -0
  78. package/dist/core/journal.js +294 -16
  79. package/dist/core/manifest.js +153 -6
  80. package/dist/core/paths.js +14 -13
  81. package/dist/core/profiles.js +160 -10
  82. package/dist/core/resolve.js +139 -23
  83. package/dist/core/secrets.js +68 -23
  84. package/dist/core/sessions.js +13 -20
  85. package/dist/core/state-file.js +107 -0
  86. package/dist/core/update.js +31 -18
  87. package/dist/core/version.js +57 -10
  88. package/dist/demo/server.js +42 -0
  89. package/dist/mcpd/cache.js +23 -10
  90. package/dist/mcpd/calllog.js +254 -0
  91. package/dist/mcpd/client-names.js +46 -0
  92. package/dist/mcpd/connectors.js +188 -18
  93. package/dist/mcpd/daemon.js +472 -115
  94. package/dist/mcpd/folder-sets.js +42 -0
  95. package/dist/mcpd/gateway.js +473 -51
  96. package/dist/mcpd/health.js +313 -0
  97. package/dist/mcpd/importer.js +453 -36
  98. package/dist/mcpd/instances.js +453 -65
  99. package/dist/mcpd/jsonrpc.js +11 -1
  100. package/dist/mcpd/launchd.js +65 -48
  101. package/dist/mcpd/middleware.js +144 -0
  102. package/dist/mcpd/modern.js +686 -0
  103. package/dist/mcpd/oauth.js +845 -0
  104. package/dist/mcpd/peerpid.js +134 -6
  105. package/dist/mcpd/pressure.js +88 -0
  106. package/dist/mcpd/rss.js +166 -0
  107. package/dist/mcpd/service.js +191 -0
  108. package/dist/mcpd/share.js +217 -0
  109. package/dist/mcpd/state.js +183 -0
  110. package/dist/mcpd/sync.js +72 -87
  111. package/dist/mcpd/systemd.js +83 -0
  112. package/dist/mcpd/tokens.js +85 -0
  113. package/dist/mcpd/upstream.js +163 -46
  114. package/dist/statusline/cost.js +167 -44
  115. package/dist/statusline/input.js +78 -0
  116. package/dist/statusline/render.js +9 -3
  117. package/dist/ui/fonts.js +8 -3
  118. package/dist/ui/settings.js +33 -16
  119. package/npm-shrinkwrap.json +1102 -0
  120. package/package.json +10 -9
  121. package/dist/cli/commands/available.js +0 -18
@@ -1,6 +1,10 @@
1
1
  import { resolve as resolvePath } from "node:path";
2
2
  import { loadConfig } from "../../core/config.js";
3
3
  import { resolveProfile } from "../../core/resolve.js";
4
+ import { JSON_FLAG, bool, flagsOf, parseFlags } from "../args.js";
5
+ import { emitLine, jsonOutput } from "../output.js";
6
+ /** `turno resolve --json`: one line, read by status lines. */
7
+ const RESOLVE_JSON = jsonOutput(["chosen", "assigned", "reason", "note", "exhaustedUntil"]);
4
8
  /** Field separator of the machine output read by status lines. */
5
9
  export const SEP = "\x1f";
6
10
  export const command = {
@@ -12,11 +16,18 @@ export const command = {
12
16
  "or a JSON object with --json.",
13
17
  ].join("\n"),
14
18
  hidden: true,
19
+ args: ["dir"],
20
+ flags: flagsOf(JSON_FLAG),
21
+ json: RESOLVE_JSON,
15
22
  async run(args, io) {
16
- const json = args.includes("--json");
17
- const dir = args.find((a) => a !== "--json");
23
+ const p = parseFlags(args, JSON_FLAG, 1);
24
+ const json = bool(p, "json");
25
+ const dir = p.positionals[0];
18
26
  const r = resolveProfile(resolvePath(dir ?? process.cwd()), loadConfig(io.env), io.env);
19
- io.out(json ? JSON.stringify(r) : [r.chosen, r.assigned, r.reason, r.note].join(SEP));
27
+ if (json)
28
+ emitLine(io, p, RESOLVE_JSON, r);
29
+ else
30
+ io.out([r.chosen, r.assigned, r.reason, r.note].join(SEP));
20
31
  return 0;
21
32
  },
22
33
  };
@@ -1,14 +1,44 @@
1
- import { fail } from "../io.js";
2
1
  import { launchProfile } from "../launch.js";
3
2
  import { command as auto } from "./auto.js";
4
3
  export const command = {
5
4
  summary: "open a profile with its agent (turno <profile> is the short form), or auto",
6
- usage: "Usage: turno run <profile|auto> [claude args]\n\nEverything after the profile goes to claude, for example: turno run work --resume",
5
+ usage: [
6
+ "Usage: turno run <profile|auto> [--no-gateway] [agent args]",
7
+ "",
8
+ "Everything after the profile goes to its agent, for example:",
9
+ " turno run work --resume",
10
+ "",
11
+ "Without a profile, a terminal shows the profiles to choose from. When this",
12
+ "folder resolves to a profile, auto comes first, named with it: auto (work).",
13
+ "",
14
+ "Safe mode: --no-gateway (or TURNO_SAFE=1) opens the profile with its account",
15
+ "but without turno's gateway: no mcpd entries, no gateway token, and for Claude",
16
+ "Code no status line (and no hooks). If a problem goes away in safe mode, it",
17
+ "comes from turno. Claude Code gets --strict-mcp-config with the profile's other",
18
+ "servers, Codex -c mcp_servers.<name>.enabled=false and Copilot",
19
+ "--disable-mcp-server for each gateway entry; Cursor has no switch for one run,",
20
+ "so its entries start without the token and mcpd refuses them.",
21
+ "",
22
+ "Examples:",
23
+ " $ turno run work",
24
+ " $ turno run work --resume # arguments go to the agent",
25
+ " $ turno run auto",
26
+ " $ turno run work --no-gateway # safe mode",
27
+ " $ TURNO_SAFE=1 turno work",
28
+ ].join("\n"),
7
29
  args: ["profile-or-auto"],
8
- async run(args, io) {
9
- const [name, ...rest] = args;
10
- if (!name)
11
- return fail("usage: turno run <profile|auto> [claude args]");
30
+ flags: ["--no-gateway"],
31
+ async run(given, io) {
32
+ // `turno run --no-gateway work` as well as `turno run work --no-gateway`.
33
+ const lead = given[0] === "--no-gateway";
34
+ let [name, ...rest] = lead ? given.slice(1) : given;
35
+ if (lead)
36
+ rest = ["--no-gateway", ...rest];
37
+ if (!name) {
38
+ const { pickProfile } = await import("../picker.js");
39
+ name = await pickProfile(io, { command: "run", title: "Profile to open", extra: ["auto"], auto: true });
40
+ rest = lead ? ["--no-gateway"] : [];
41
+ }
12
42
  return name === "auto" ? auto.run(rest, io) : launchProfile(name, rest, io);
13
43
  },
14
44
  };
@@ -1,68 +1,47 @@
1
- import { execFile } from "node:child_process";
2
- import { promisify } from "node:util";
3
- import { storeKeychainSecret } from "../../core/secrets.js";
4
1
  import { readFileSync } from "node:fs";
5
2
  import { paths, tildify } from "../../core/paths.js";
6
- import { fail } from "../io.js";
7
- const run = promisify(execFile);
3
+ import { SecretError, requireSecretStore } from "../../core/secrets.js";
4
+ import { JSON_FLAG, bool, flagsOf, parseFlags } from "../args.js";
5
+ import { nextStep } from "../hints.js";
6
+ import { fail, needsAnswer, noInputReason } from "../io.js";
7
+ import { answerFields, emit, jsonOutput } from "../output.js";
8
+ import { readHidden, readStdinText, stdinIsTty } from "../secret-input.js";
8
9
  const USAGE = `Usage:
9
- turno secret set <service> read a value from stdin and store it in the Keychain
10
- turno secret has <service> exit 0 when the Keychain item exists
11
- turno secret rm <service> delete the Keychain item
10
+ turno secret set <service> read a value from stdin and store it
11
+ turno secret has <service> exit 0 when the item exists
12
+ turno secret rm <service> delete the item
12
13
  turno secret list [--json] every keychain: reference in mcp.toml and whether it is stored
13
14
 
14
- Reference it in mcp.toml as "keychain:<service>". Values are never printed.`;
15
+ Reference it in mcp.toml as "keychain:<service>". Values are never printed and never passed
16
+ as a command argument. The store is the login Keychain on macOS and the Secret Service
17
+ (libsecret's secret-tool, attributes service=turno account=<service>) on Linux. Without
18
+ either, use "env:NAME" references.
19
+
20
+ Examples:
21
+ $ printf %s "$TOKEN" | turno secret set github-token
22
+ $ turno secret has github-token
23
+ $ turno secret list --json`;
15
24
  async function readStdin() {
16
- if (process.stdin.isTTY) {
17
- process.stderr.write("value (input hidden, end with Enter): ");
18
- return new Promise((resolve) => {
19
- const stdin = process.stdin;
20
- let value = "";
21
- stdin.setRawMode(true);
22
- stdin.resume();
23
- stdin.setEncoding("utf8");
24
- const onData = (ch) => {
25
- if (ch === "\r" || ch === "\n" || ch === "\u0004") {
26
- stdin.setRawMode(false);
27
- stdin.pause();
28
- stdin.off("data", onData);
29
- process.stderr.write("\n");
30
- resolve(value);
31
- }
32
- else if (ch === "\u0003") {
33
- process.exit(130);
34
- }
35
- else if (ch === "\u007f") {
36
- value = value.slice(0, -1);
37
- }
38
- else {
39
- value += ch;
40
- }
41
- };
42
- stdin.on("data", onData);
43
- });
44
- }
45
- const chunks = [];
46
- for await (const c of process.stdin)
47
- chunks.push(c);
48
- return Buffer.concat(chunks).toString("utf8").replace(/\r?\n$/, "");
25
+ return stdinIsTty() ? readHidden("value (input hidden, end with Enter): ") : readStdinText();
49
26
  }
50
- async function exists(service) {
27
+ /** The store, with its SecretError turned into a one-line usage error. */
28
+ function store(io) {
51
29
  try {
52
- // Without -w: this reads the item's attributes, never its value.
53
- await run("security", ["find-generic-password", "-s", service], { timeout: 10_000 });
54
- return true;
30
+ return requireSecretStore(io.env);
55
31
  }
56
- catch {
57
- return false;
32
+ catch (err) {
33
+ return fail(err.message);
58
34
  }
59
35
  }
60
36
  /** keychain:<service> references in mcp.toml. */
61
37
  export function keychainRefs(text) {
62
38
  return [...new Set([...text.matchAll(/"keychain:([^"\\]+)"/g)].map((m) => m[1]))].sort();
63
39
  }
40
+ /** `turno secret list --json`: one element per keychain: reference in mcp.toml. */
41
+ const LIST_JSON = jsonOutput(["service", "stored"]);
64
42
  async function list(args, io) {
65
- const json = args.includes("--json");
43
+ const p = parseFlags(args, JSON_FLAG, 0);
44
+ const json = bool(p, "json");
66
45
  let text = "";
67
46
  try {
68
47
  text = readFileSync(paths(io.env).mcpFile, "utf8");
@@ -71,9 +50,10 @@ async function list(args, io) {
71
50
  text = "";
72
51
  }
73
52
  const refs = keychainRefs(text);
74
- const found = await Promise.all(refs.map((r) => exists(r)));
53
+ const s = refs.length ? store(io) : undefined;
54
+ const found = s ? await Promise.all(refs.map((r) => s.has(r))) : [];
75
55
  if (json) {
76
- io.out(JSON.stringify(refs.map((r, i) => ({ service: r, stored: found[i] })), null, 2));
56
+ emit(io, p, LIST_JSON, refs.map((r, i) => ({ service: r, stored: found[i] })));
77
57
  return 0;
78
58
  }
79
59
  if (!refs.length)
@@ -83,40 +63,64 @@ async function list(args, io) {
83
63
  return found.every(Boolean) ? 0 : 1;
84
64
  }
85
65
  export const command = {
86
- summary: "store MCP secrets in the macOS Keychain",
66
+ summary: "store MCP secrets in the Keychain (macOS) or the Secret Service (Linux)",
87
67
  usage: USAGE,
88
- subcommands: { set: { args: ["any"] }, has: { args: ["any"] }, rm: { args: ["any"] }, list: { flags: ["--json"] } },
68
+ subcommands: {
69
+ set: { args: ["any"] },
70
+ has: { args: ["any"] },
71
+ rm: { args: ["any"] },
72
+ list: { flags: flagsOf(JSON_FLAG) },
73
+ },
89
74
  async run(args, io) {
90
- const [sub, service] = args;
75
+ const [sub] = args;
76
+ const rest = args.slice(1);
77
+ if (sub === "--help" || sub === "-h" || sub === "help" || rest.includes("--help") || rest.includes("-h")) {
78
+ io.out(USAGE);
79
+ return 0;
80
+ }
91
81
  if (sub === "list" || sub === undefined)
92
- return list(args.slice(1), io);
82
+ return answerFields(rest, LIST_JSON, io) ? 0 : list(rest, io);
83
+ // One service name and no flags: an unknown flag must not become a service name.
84
+ const service = parseFlags(rest, {}, 1).positionals[0];
93
85
  if (!service)
94
86
  return fail(USAGE);
95
- switch (sub) {
96
- case "set": {
97
- const value = await readStdin();
98
- if (!value)
99
- return fail("empty value");
100
- await storeKeychainSecret(service, value);
101
- io.out(`stored keychain:${service}`);
102
- return 0;
103
- }
104
- case "has":
105
- try {
106
- await run("security", ["find-generic-password", "-s", service], { timeout: 10_000 });
107
- io.out(`keychain:${service} exists`);
87
+ try {
88
+ switch (sub) {
89
+ case "set": {
90
+ const s = store(io);
91
+ // The hidden prompt waits for a person: never with --no-input or inside an agent.
92
+ if (process.stdin.isTTY && noInputReason(io.env))
93
+ needsAnswer("secret set", "the value on stdin");
94
+ const value = await readStdin();
95
+ if (!value)
96
+ return fail("empty value");
97
+ await s.set(service, value);
98
+ io.out(`stored keychain:${service}`);
99
+ nextStep(io, `use it in mcp.toml as "keychain:${service}"; turno secret list shows which references are stored`);
108
100
  return 0;
109
101
  }
110
- catch {
102
+ case "has":
103
+ if (await store(io).has(service)) {
104
+ io.out(`keychain:${service} exists`);
105
+ return 0;
106
+ }
111
107
  io.out(`keychain:${service} not found`);
112
108
  return 1;
113
- }
114
- case "rm":
115
- await run("security", ["delete-generic-password", "-s", service], { timeout: 10_000 });
116
- io.out(`removed keychain:${service}`);
117
- return 0;
118
- default:
119
- return fail(USAGE);
109
+ case "rm":
110
+ if (!(await store(io).remove(service))) {
111
+ io.out(`keychain:${service} not found`);
112
+ return 1;
113
+ }
114
+ io.out(`removed keychain:${service}`);
115
+ return 0;
116
+ default:
117
+ return fail(USAGE);
118
+ }
119
+ }
120
+ catch (err) {
121
+ if (err instanceof SecretError)
122
+ return fail(err.message);
123
+ throw err;
120
124
  }
121
125
  },
122
126
  };
@@ -1,7 +1,8 @@
1
1
  import { loadConfig } from "../../core/config.js";
2
2
  import { tildify } from "../../core/paths.js";
3
3
  import { displayName, liveSessions } from "../../core/sessions.js";
4
- import { JSON_FLAG, bool, parseFlags, printJson } from "../args.js";
4
+ import { JSON_FLAG, bool, parseFlags } from "../args.js";
5
+ import { emit, jsonOutput } from "../output.js";
5
6
  import { group } from "../group.js";
6
7
  import { command as handoff } from "./handoff.js";
7
8
  import { command as sessions } from "./sessions.js";
@@ -9,28 +10,38 @@ export function sessionsData(env) {
9
10
  const config = loadConfig(env);
10
11
  return liveSessions(env, config).map((s) => ({
11
12
  name: displayName(s),
12
- profile: s.source === "record" ? (s.profile ?? null) : s.source === "desktop" ? null : (config.system ?? null),
13
+ profile: s.source === "record" ? (s.profile ?? null) : s.source === "desktop" ? null : config.system || null,
13
14
  source: s.source,
14
15
  status: s.status,
15
16
  cwd: s.cwd,
16
17
  }));
17
18
  }
19
+ const LIST_JSON = jsonOutput(["name", "profile", "source", "status", "cwd"]);
18
20
  async function list(args, io) {
19
21
  const p = parseFlags(args, JSON_FLAG, 0);
20
22
  if (bool(p, "json")) {
21
- printJson(io.out, sessionsData(io.env).map((s) => ({ ...s, cwd: tildify(s.cwd, io.env) })));
23
+ emit(io, p, LIST_JSON, sessionsData(io.env).map((s) => ({ ...s, cwd: tildify(s.cwd, io.env) })));
22
24
  return 0;
23
25
  }
24
26
  return sessions.run([], io);
25
27
  }
26
28
  export const command = group("session", "live Claude Code sessions, and moving one to another account", {
27
- list: { summary: "live sessions and the account of each", synopsis: "[--json]", flags: ["--json"], run: list },
29
+ list: {
30
+ summary: "live sessions and the account of each",
31
+ synopsis: "[--json]",
32
+ flags: ["--json"],
33
+ json: LIST_JSON,
34
+ run: list,
35
+ },
28
36
  handoff: {
29
37
  summary: "print the command that continues or forks this session under another profile",
30
- synopsis: "<profile|auto> [--fork] [--copy]",
38
+ synopsis: "[profile|auto] [--fork] [--copy]",
31
39
  args: ["profile-or-auto"],
32
40
  flags: ["--fork", "--copy"],
33
41
  run: (args, io) => handoff.run(args, io),
34
42
  },
35
- }, { fallback: "list" });
43
+ }, {
44
+ fallback: "list",
45
+ examples: ["turno session list", "turno session handoff personal", "turno session handoff work --fork --copy"],
46
+ });
36
47
  //# sourceMappingURL=session.js.map
@@ -1,26 +1,62 @@
1
1
  import { loadConfig } from "../../core/config.js";
2
2
  import { tildify } from "../../core/paths.js";
3
- import { displayName, liveSessions } from "../../core/sessions.js";
3
+ import { displayName, liveSessions, parseProcStart } from "../../core/sessions.js";
4
+ import { parseFlags } from "../args.js";
5
+ import { profileColor, style } from "../style.js";
6
+ /** "45s", "12m", "3h05m", "2d 4h": how long a session has been running. */
7
+ function age(ms) {
8
+ const s = Math.max(0, Math.floor(ms / 1000));
9
+ if (s < 60)
10
+ return `${s}s`;
11
+ const m = Math.floor(s / 60);
12
+ if (m < 60)
13
+ return `${m}m`;
14
+ const h = Math.floor(m / 60);
15
+ if (h < 24)
16
+ return `${h}h${String(m % 60).padStart(2, "0")}m`;
17
+ return `${Math.floor(h / 24)}d ${h % 24}h`;
18
+ }
4
19
  export const command = {
5
20
  summary: "list live sessions and the account of each",
6
21
  usage: "Usage: turno sessions",
7
- async run(_args, io) {
22
+ async run(args, io) {
23
+ parseFlags(args, {}, 0);
8
24
  const config = loadConfig(io.env);
9
- const rows = liveSessions(io.env, config).map((s) => {
10
- const account = s.source === "desktop"
11
- ? "Claude Desktop (its own account)"
12
- : s.source === "record"
13
- ? s.profile
14
- : `default (~/.claude = ${config.system ?? "?"})`;
15
- return { name: displayName(s), account, status: s.status, cwd: tildify(s.cwd, io.env) };
25
+ const s = style(io);
26
+ const pill = (name) => s.profile(name, profileColor(config.profiles, name));
27
+ const now = Date.now();
28
+ const rows = liveSessions(io.env, config).map((x) => {
29
+ const account = x.source === "desktop"
30
+ ? s.muted("Claude Desktop (its own account)")
31
+ : x.source === "record"
32
+ ? pill(x.profile)
33
+ : s.color
34
+ ? `${s.muted("plain claude")}${config.system ? ` ${pill(config.system)}` : ""}`
35
+ : `plain claude (~/.claude${config.system ? ` = ${config.system}` : ""})`;
36
+ const start = parseProcStart(x.procStart ?? "");
37
+ // Claude Code writes procStart in UTC; a reading in the future means it is local time.
38
+ const began = start ? (start.utc <= now + 60_000 ? start.utc : start.local) : undefined;
39
+ const status = x.status === "busy" ? s.warn(x.status) : x.status === "idle" ? s.ok(x.status) : x.status;
40
+ return [
41
+ s.bold(displayName(x)),
42
+ account,
43
+ status,
44
+ s.muted(began !== undefined ? age(now - began) : "?"),
45
+ s.muted(tildify(x.cwd, io.env)),
46
+ ];
16
47
  });
17
48
  if (rows.length === 0) {
18
49
  io.out("No live sessions.");
19
50
  return 0;
20
51
  }
21
- const w = Math.max(6, ...rows.map((r) => r.name.length));
22
- for (const r of rows)
23
- io.out(`${r.name.padEnd(w)} ${r.account.padEnd(34)} ${r.status.padEnd(6)} ${r.cwd}`);
52
+ if (!s.color) {
53
+ for (const line of s.table(rows, { indent: 0 }))
54
+ io.out(line);
55
+ return 0;
56
+ }
57
+ io.out(s.header("Sessions"));
58
+ for (const line of s.table(rows, { columns: [{}, {}, {}, { align: "right", drop: 1 }, {}] }))
59
+ io.out(line);
24
60
  return 0;
25
61
  },
26
62
  };