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,62 +1,119 @@
1
- import { existsSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, closeSync } from "node:fs";
1
+ import { existsSync, mkdirSync, openSync, readSync, readdirSync, renameSync, rmSync, statSync, writeFileSync, closeSync, } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
- /** $/MTok: input, output, cache write 5 m, cache write 1 h, cache read. Longest prefix wins. */
4
- export const PRICES = {
5
- "claude-fable-5-2": [10, 50, 12.5, 20, 0.25],
3
+ import { PRIVATE_DIR_MODE, PRIVATE_FILE_MODE } from "../core/paths.js";
4
+ import { readJsonFile, realOr } from "../core/fsutil.js";
5
+ /**
6
+ * $/MTok: input, output, cache write 5 m, cache write 1 h, cache read, for Anthropic first-party
7
+ * API rates (Bedrock and Vertex ids map to the same model; their regional prices can differ a
8
+ * little). Ids are matched after `normalizeModel()`, exactly: an unknown id has no price, so the
9
+ * status line can say "$?" instead of a silent $0.00. Retired models stay so old transcripts
10
+ * keep their cost.
11
+ */
12
+ const PRICES = {
13
+ "claude-fable-5-2": [8, 40, 10, 16, 0.2],
14
+ "claude-mythos-5-2": [8, 40, 10, 16, 0.2],
6
15
  "claude-fable-5-1": [10, 50, 12.5, 20, 0.25],
7
16
  "claude-mythos-5-1": [10, 50, 12.5, 20, 0.25],
8
17
  "claude-fable-5": [10, 50, 12.5, 20, 1.0],
18
+ "claude-mythos-5": [10, 50, 12.5, 20, 1.0],
9
19
  "claude-opus-5-5": [4, 20, 5, 8, 0.2],
10
20
  "claude-opus-5": [5, 25, 6.25, 10, 0.5],
11
21
  "claude-opus-4-8": [5, 25, 6.25, 10, 0.5],
12
22
  "claude-opus-4-7": [5, 25, 6.25, 10, 0.5],
13
23
  "claude-opus-4-6": [5, 25, 6.25, 10, 0.5],
14
- "claude-sonnet-5-5": [2, 10, 2.5, 4, 0.2],
24
+ "claude-opus-4-5": [5, 25, 6.25, 10, 0.5],
25
+ "claude-opus-4-1": [15, 75, 18.75, 30, 1.5],
26
+ "claude-opus-4": [15, 75, 18.75, 30, 1.5],
27
+ "claude-3-opus": [15, 75, 18.75, 30, 1.5],
28
+ "claude-sonnet-5-5": [2, 10, 2.5, 4, 0.1],
15
29
  "claude-sonnet-5": [2, 10, 2.5, 4, 0.2],
16
30
  "claude-sonnet-4-6": [3, 15, 3.75, 6, 0.3],
17
- "claude-haiku-5-5": [1, 5, 1.25, 2, 0.1],
31
+ "claude-sonnet-4-5": [3, 15, 3.75, 6, 0.3],
32
+ "claude-sonnet-4": [3, 15, 3.75, 6, 0.3],
33
+ "claude-3-7-sonnet": [3, 15, 3.75, 6, 0.3],
34
+ "claude-3-5-sonnet": [3, 15, 3.75, 6, 0.3],
35
+ "claude-haiku-5-5": [0.1, 0.5, 0.125, 0.2, 0.01],
18
36
  "claude-haiku-4-5": [1, 5, 1.25, 2, 0.1],
37
+ "claude-3-5-haiku": [0.8, 4, 1, 1.6, 0.08],
38
+ "claude-3-haiku": [0.25, 1.25, 0.3, 0.5, 0.03],
19
39
  };
20
- const KEYS = Object.keys(PRICES).sort((a, b) => b.length - a.length);
40
+ /** Models whose price rises once the prompt passes a size: above `over` tokens, `price` applies. */
41
+ const LONG_PROMPT = {
42
+ "claude-haiku-5-5": { over: 100_000, price: [0.5, 2.5, 0.625, 1, 0.05] },
43
+ };
44
+ /**
45
+ * The first-party id of a model as it appears in a transcript: drops the Bedrock prefixes
46
+ * (`us.anthropic.`, ARNs), the Vertex `@date` suffix, Bedrock `-v1:0` suffixes, `[1m]`
47
+ * markers and `-YYYYMMDD` snapshot dates.
48
+ */
49
+ export function normalizeModel(model) {
50
+ let m = model.trim().toLowerCase();
51
+ const at = m.lastIndexOf("claude-");
52
+ if (at > 0)
53
+ m = m.slice(at);
54
+ return m
55
+ .replace(/\[[^\]]*\]$/, "")
56
+ .replace(/@.*$/, "")
57
+ .replace(/-v\d+(:\d+)?$/, "")
58
+ .replace(/-\d{8}$/, "");
59
+ }
21
60
  export function priceFor(model) {
22
- if (!model)
61
+ if (typeof model !== "string" || !model)
23
62
  return undefined;
24
- for (const k of KEYS)
25
- if (model.startsWith(k))
26
- return PRICES[k];
27
- return undefined;
63
+ return PRICES[normalizeModel(model)];
64
+ }
65
+ const num = (v) => (typeof v === "number" && Number.isFinite(v) ? v : 0);
66
+ /** Tokens a usage record bills: zero for Claude Code's synthetic messages. */
67
+ function usageTokens(u) {
68
+ return (num(u.input_tokens) + num(u.output_tokens) + num(u.cache_creation_input_tokens) + num(u.cache_read_input_tokens));
28
69
  }
29
- /** API cost in USD of one assistant usage record. */
70
+ /**
71
+ * API cost in USD of one assistant usage record, or undefined when the model has no price.
72
+ * A record without tokens costs 0 whatever its model.
73
+ */
30
74
  export function usageCost(model, u) {
31
- const p = priceFor(model);
32
- if (!p)
75
+ if (usageTokens(u) === 0)
33
76
  return 0;
34
- const w1h = u.cache_creation?.ephemeral_1h_input_tokens ?? 0;
35
- const w5m = u.cache_creation?.ephemeral_5m_input_tokens ?? Math.max(0, (u.cache_creation_input_tokens ?? 0) - w1h);
36
- const usd = ((u.input_tokens ?? 0) * p[0] + (u.output_tokens ?? 0) * p[1] + w5m * p[2] + w1h * p[3] + (u.cache_read_input_tokens ?? 0) * p[4]) / 1e6;
77
+ let p = priceFor(model);
78
+ if (!p)
79
+ return undefined;
80
+ const long = LONG_PROMPT[normalizeModel(model)];
81
+ if (long && num(u.input_tokens) + num(u.cache_creation_input_tokens) + num(u.cache_read_input_tokens) > long.over)
82
+ p = long.price;
83
+ const w1h = num(u.cache_creation?.ephemeral_1h_input_tokens);
84
+ const w5m = u.cache_creation?.ephemeral_5m_input_tokens !== undefined
85
+ ? num(u.cache_creation.ephemeral_5m_input_tokens)
86
+ : Math.max(0, num(u.cache_creation_input_tokens) - w1h);
87
+ const usd = (num(u.input_tokens) * p[0] +
88
+ num(u.output_tokens) * p[1] +
89
+ w5m * p[2] +
90
+ w1h * p[3] +
91
+ num(u.cache_read_input_tokens) * p[4]) /
92
+ 1e6;
37
93
  return usd * (u.speed === "fast" ? 2 : 1);
38
94
  }
95
+ /** Bumped when an older state would give a wrong total (v2: unknown models are tracked). */
96
+ const STATE_VERSION = 2;
39
97
  function readJson(file) {
40
- try {
41
- return JSON.parse(readFileSync(file, "utf8"));
42
- }
43
- catch {
44
- return undefined;
45
- }
98
+ return readJsonFile(file);
46
99
  }
47
100
  function writeJson(file, data) {
48
- mkdirSync(dirname(file), { recursive: true });
101
+ mkdirSync(dirname(file), { recursive: true, mode: PRIVATE_DIR_MODE });
49
102
  const tmp = `${file}.${process.pid}.tmp`;
50
- writeFileSync(tmp, JSON.stringify(data));
103
+ writeFileSync(tmp, JSON.stringify(data), { mode: PRIVATE_FILE_MODE });
51
104
  renameSync(tmp, file);
52
105
  }
53
- function real(p) {
54
- try {
55
- return realpathSync(p);
56
- }
57
- catch {
58
- return p;
59
- }
106
+ function validState(v) {
107
+ if (!v || typeof v !== "object")
108
+ return false;
109
+ const o = v;
110
+ return o.v === STATE_VERSION && !!o.files && typeof o.files === "object" && !Array.isArray(o.files);
111
+ }
112
+ function validFile(v) {
113
+ if (!v || typeof v !== "object")
114
+ return false;
115
+ const f = v;
116
+ return typeof f.offset === "number" && typeof f.usd === "number" && Array.isArray(f.recent);
60
117
  }
61
118
  /** Read only complete new lines of a transcript and add their cost. */
62
119
  function scan(path, st) {
@@ -68,7 +125,7 @@ function scan(path, st) {
68
125
  return;
69
126
  }
70
127
  if (size < st.offset)
71
- Object.assign(st, { offset: 0, usd: 0, recent: [] });
128
+ Object.assign(st, { offset: 0, usd: 0, recent: [], unknown: [] });
72
129
  if (size === st.offset)
73
130
  return;
74
131
  const fd = openSync(path, "r");
@@ -92,8 +149,8 @@ function scan(path, st) {
92
149
  catch {
93
150
  continue;
94
151
  }
95
- const m = o.message;
96
- if (o.type !== "assistant" || !m?.usage)
152
+ const m = o?.message;
153
+ if (o?.type !== "assistant" || !m?.usage || typeof m.usage !== "object")
97
154
  continue;
98
155
  const key = `${m.id}|${o.requestId}`; // every block of one response repeats its usage
99
156
  if (st.recent.includes(key))
@@ -101,7 +158,15 @@ function scan(path, st) {
101
158
  st.recent.push(key);
102
159
  if (st.recent.length > 64)
103
160
  st.recent.splice(0, st.recent.length - 64);
104
- st.usd += usageCost(m.model, m.usage);
161
+ const usd = usageCost(m.model, m.usage);
162
+ if (usd !== undefined)
163
+ st.usd += usd;
164
+ else {
165
+ const id = typeof m.model === "string" && m.model ? m.model.slice(0, 120) : "(none)";
166
+ st.unknown ??= [];
167
+ if (!st.unknown.includes(id))
168
+ st.unknown.push(id);
169
+ }
105
170
  }
106
171
  }
107
172
  finally {
@@ -111,25 +176,83 @@ function scan(path, st) {
111
176
  /** Incremental cost of a conversation: the main transcript plus its subagents. */
112
177
  export function computeCost(transcript, out, now = Date.now() / 1000) {
113
178
  const prev = readJson(out);
114
- const files = prev?.files ?? {};
115
- const main = real(transcript);
179
+ const files = {};
180
+ if (validState(prev))
181
+ for (const [k, f] of Object.entries(prev.files))
182
+ if (validFile(f))
183
+ files[k] = f;
184
+ const main = realOr(transcript);
116
185
  const stem = main.endsWith(".jsonl") ? main.slice(0, -6) : main;
117
186
  const subDir = join(stem, "subagents");
118
187
  const subs = existsSync(subDir)
119
188
  ? readdirSync(subDir)
120
189
  .filter((f) => f.endsWith(".jsonl"))
121
- .map((f) => real(join(subDir, f)))
190
+ .map((f) => realOr(join(subDir, f)))
122
191
  .sort()
123
192
  : [];
124
193
  for (const p of [main, ...subs]) {
125
- files[p] ??= { offset: 0, usd: 0, recent: [] };
194
+ files[p] ??= { offset: 0, usd: 0, recent: [], unknown: [] };
126
195
  scan(p, files[p]);
127
196
  }
128
197
  const mainUsd = files[main]?.usd ?? 0;
129
198
  const total = Object.values(files).reduce((a, f) => a + f.usd, 0);
130
- const state = { files, main: mainUsd, sub: total - mainUsd, total, updated_at: now };
131
- writeJson(out, state);
132
- rmSync(`${out}.lock`, { force: true });
199
+ const unknown = [...new Set(Object.values(files).flatMap((f) => f.unknown ?? []))];
200
+ const state = {
201
+ v: STATE_VERSION,
202
+ files,
203
+ main: mainUsd,
204
+ sub: total - mainUsd,
205
+ total,
206
+ unknown,
207
+ updated_at: now,
208
+ };
209
+ try {
210
+ writeJson(out, state);
211
+ }
212
+ finally {
213
+ rmSync(`${out}.lock`, { force: true });
214
+ }
133
215
  return state;
134
216
  }
217
+ /** Remove status line cache files not touched for `maxAgeDays`, at most once a day. */
218
+ export function pruneCache(dir, now = Date.now() / 1000, maxAgeDays = 7) {
219
+ const stamp = join(dir, ".pruned");
220
+ try {
221
+ if (now - statSync(stamp).mtimeMs / 1000 < 86_400)
222
+ return 0;
223
+ }
224
+ catch {
225
+ /* never pruned */
226
+ }
227
+ let removed = 0;
228
+ let names;
229
+ try {
230
+ names = readdirSync(dir);
231
+ }
232
+ catch {
233
+ return 0;
234
+ }
235
+ for (const name of names) {
236
+ if (name === ".pruned")
237
+ continue;
238
+ const file = join(dir, name);
239
+ try {
240
+ const st = statSync(file);
241
+ if (st.isFile() && now - st.mtimeMs / 1000 > maxAgeDays * 86_400) {
242
+ rmSync(file, { force: true });
243
+ removed++;
244
+ }
245
+ }
246
+ catch {
247
+ /* raced with another worker */
248
+ }
249
+ }
250
+ try {
251
+ writeFileSync(stamp, "", { mode: PRIVATE_FILE_MODE });
252
+ }
253
+ catch {
254
+ /* read-only: try again next time */
255
+ }
256
+ return removed;
257
+ }
135
258
  //# sourceMappingURL=cost.js.map
@@ -0,0 +1,78 @@
1
+ export const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
2
+ export const num = (v) => (typeof v === "number" && Number.isFinite(v) ? v : undefined);
3
+ const str = (v) => (typeof v === "string" ? v : undefined);
4
+ const bool = (v) => (typeof v === "boolean" ? v : undefined);
5
+ /** Session ids become file names, so only plain ids are accepted. */
6
+ const SESSION_ID = /^[A-Za-z0-9-]{1,128}$/;
7
+ export function sessionId(v) {
8
+ return typeof v === "string" && SESSION_ID.test(v) ? v : undefined;
9
+ }
10
+ /** Copy the keys of `from` whose checked value is defined. */
11
+ function pick(from, checks) {
12
+ const out = {};
13
+ for (const k of Object.keys(checks)) {
14
+ const v = checks[k](from[k]);
15
+ if (v !== undefined)
16
+ out[k] = v;
17
+ }
18
+ return out;
19
+ }
20
+ function window(v) {
21
+ if (!isObj(v))
22
+ return undefined;
23
+ const w = pick(v, { used_percentage: num, resets_at: num });
24
+ return Object.keys(w).length ? w : undefined;
25
+ }
26
+ export function limits(v) {
27
+ if (!isObj(v))
28
+ return {};
29
+ return pick(v, { five_hour: window, seven_day: window });
30
+ }
31
+ const sub = (checks) => (v) => isObj(v) ? pick(v, checks) : undefined;
32
+ /** The stdin payload, with every field checked. Anything that is not an object gives {}. */
33
+ export function sanitize(raw) {
34
+ if (!isObj(raw))
35
+ return {};
36
+ const data = pick(raw, {
37
+ session_id: sessionId,
38
+ prompt_id: str,
39
+ cwd: str,
40
+ transcript_path: str,
41
+ workspace: sub({
42
+ current_dir: str,
43
+ project_dir: str,
44
+ repo: sub({ name: str }),
45
+ git_worktree: (v) => (v === null ? undefined : v),
46
+ }),
47
+ model: sub({ display_name: str }),
48
+ effort: sub({ level: str }),
49
+ cost: sub({
50
+ total_cost_usd: num,
51
+ total_lines_added: num,
52
+ total_lines_removed: num,
53
+ }),
54
+ context_window: sub({
55
+ used_percentage: num,
56
+ total_input_tokens: num,
57
+ context_window_size: num,
58
+ }),
59
+ prompt_cache: sub({
60
+ caching_observed: bool,
61
+ warm: bool,
62
+ expires_at: num,
63
+ recache_tokens_if_cold: num,
64
+ }),
65
+ rate_limits: (v) => (isObj(v) ? limits(v) : undefined),
66
+ });
67
+ return data;
68
+ }
69
+ export function turns(v) {
70
+ if (!Array.isArray(v))
71
+ return [];
72
+ return v.filter((e) => Array.isArray(e) &&
73
+ e.length === 3 &&
74
+ typeof e[0] === "string" &&
75
+ num(e[1]) !== undefined &&
76
+ (e[2] === null || num(e[2]) !== undefined));
77
+ }
78
+ //# sourceMappingURL=input.js.map
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Two-row status line for Claude Code. Pure rendering: everything it shows comes in through
3
3
  * RenderInput, which `collect()` in ../cli/commands/statusline.ts fills from disk and git.
4
+ * It expects data already checked by `sanitize()` in ./input.ts: every field has its type.
4
5
  *
5
6
  * 1. account: profile and plan, 5 h and weekly usage of THAT account, context, cache,
6
7
  * turns left, and a warning when a fallback or the wrong account is in use
@@ -66,7 +67,7 @@ export const NERD = {
66
67
  left: cp(0xe0b6),
67
68
  right: cp(0xe0b4),
68
69
  };
69
- export const UNICODE = {
70
+ const UNICODE = {
70
71
  acct: "◉",
71
72
  h5: "⧗",
72
73
  d7: "▦",
@@ -89,7 +90,7 @@ export const UNICODE = {
89
90
  left: "",
90
91
  right: "",
91
92
  };
92
- export function fg(n, text, bold = false) {
93
+ function fg(n, text, bold = false) {
93
94
  return text ? `\x1b[${bold ? "1;" : ""}38;5;${n}m${text}\x1b[0m` : "";
94
95
  }
95
96
  export function tokens(n) {
@@ -221,9 +222,14 @@ export function render(i) {
221
222
  seg += fg(MUTED, ` (sub $${Math.round(i.cost.sub).toLocaleString("en-US")})`);
222
223
  row2.push(seg);
223
224
  }
224
- else if (c.total_cost_usd !== undefined && c.total_cost_usd !== null) {
225
+ else if (i.costUnknown) {
226
+ row2.push(ic("cost", COST) + fg(COST, "$?", true));
227
+ }
228
+ else if (typeof c.total_cost_usd === "number" && Number.isFinite(c.total_cost_usd)) {
225
229
  row2.push(ic("cost", COST) + fg(COST, `$${c.total_cost_usd.toFixed(2)}`) + fg(MUTED, "…"));
226
230
  }
231
+ if (i.gatewayDown)
232
+ row2.push(ic("ban", BAD) + fg(BAD, "mcpd down"));
227
233
  return `${row1.join(div)}\n${row2.join(div)}\n`;
228
234
  }
229
235
  /** Turns left in the 5 h window, from how much the percentage rose over this session's last turns. */
package/dist/ui/fonts.js CHANGED
@@ -4,7 +4,10 @@ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "
4
4
  import { join } from "node:path";
5
5
  import { findOnPath } from "../cli/launch.js";
6
6
  const NF = "https://raw.githubusercontent.com/ryanoasis/nerd-fonts/v3.4.0/patched-fonts/Meslo/S/";
7
- /** Same values as turno-fonts, for an install without that optional package. */
7
+ /**
8
+ * Same values as turno-fonts. turno-cli does not depend on that package, so a normal
9
+ * install downloads these files and checks each one against its pinned SHA-256.
10
+ */
8
11
  export const FALLBACK = {
9
12
  family: "MesloLGS Nerd Font",
10
13
  version: "3.4.0",
@@ -98,9 +101,11 @@ export async function installFonts(source, opts) {
98
101
  }
99
102
  const wrote = results.some((r) => r.action === "copied" || r.action === "downloaded");
100
103
  if (wrote && !opts.dryRun && (opts.platform ?? process.platform) === "linux") {
101
- const fc = findOnPath("fc-cache", opts.env ?? process.env);
104
+ const env = opts.env ?? process.env;
105
+ const fc = findOnPath("fc-cache", env);
106
+ // The same env as the rest of the install: fontconfig writes its cache under HOME or XDG_CACHE_HOME.
102
107
  if (fc)
103
- execFileSync(fc, ["-f", opts.dir], { stdio: "ignore" });
108
+ execFileSync(fc, ["-f", opts.dir], { stdio: "ignore", env });
104
109
  }
105
110
  return results;
106
111
  }
@@ -1,18 +1,12 @@
1
- import { existsSync, readFileSync, realpathSync } from "node:fs";
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { parseJsonObject, realOr } from "../core/fsutil.js";
3
+ import { tildify } from "../core/paths.js";
2
4
  /** Refresh every 30 s so reset countdowns and the clock-driven parts stay current. */
3
- export const REFRESH_SECONDS = 30;
4
- function real(p) {
5
- try {
6
- return realpathSync(p);
7
- }
8
- catch {
9
- return p;
10
- }
11
- }
5
+ const REFRESH_SECONDS = 30;
12
6
  export function readSettings(file) {
13
7
  if (!existsSync(file))
14
8
  return {};
15
- return JSON.parse(readFileSync(file, "utf8"));
9
+ return parseJsonObject(readFileSync(file, "utf8"), file);
16
10
  }
17
11
  export function currentStatusLine(file) {
18
12
  try {
@@ -23,20 +17,43 @@ export function currentStatusLine(file) {
23
17
  return undefined;
24
18
  }
25
19
  }
26
- /** Whether a status line command runs turno's. */
20
+ /** Whether a status line command runs turno's, with a bare or quoted path (`"/x/turno" statusline`). */
27
21
  export function isTurnoStatusLine(s) {
28
- return Boolean(s && /(^|[\s/])turno statusline(\s|$)/.test(s.command));
22
+ return Boolean(s && /(^|[\s/"'])turno["']?\s+statusline(\s|$)/.test(s.command));
23
+ }
24
+ /**
25
+ * A status line command as one row of doctor or the status screen shows it: "turno statusline"
26
+ * for turno's own, "none" without one, and any other command without quotes, with paths under
27
+ * HOME as ~ and cut to `max` characters.
28
+ */
29
+ export function statusLineLabel(s, env, max = 60) {
30
+ if (!s)
31
+ return "none";
32
+ if (isTurnoStatusLine(s))
33
+ return "turno statusline";
34
+ const text = s.command
35
+ .replace(/["']/g, "")
36
+ .split(/\s+/)
37
+ .filter(Boolean)
38
+ .map((w) => tildify(w, env))
39
+ .join(" ");
40
+ return text.length > max ? `${text.slice(0, max - 3)}...` : text;
29
41
  }
30
42
  /** The entry to write: our command, keeping any other keys the user set (padding, ...). */
31
- export function wantedStatusLine(command, existing) {
32
- return { ...(existing ?? {}), type: "command", command, refreshInterval: existing?.refreshInterval ?? REFRESH_SECONDS };
43
+ function wantedStatusLine(command, existing) {
44
+ return {
45
+ ...(existing ?? {}),
46
+ type: "command",
47
+ command,
48
+ refreshInterval: existing?.refreshInterval ?? REFRESH_SECONDS,
49
+ };
33
50
  }
34
51
  export function setStatusLine(file, command, journal) {
35
52
  const settings = readSettings(file);
36
53
  const before = settings.statusLine;
37
54
  const after = wantedStatusLine(command, before);
38
55
  const changed = JSON.stringify(before) !== JSON.stringify(after);
39
- const result = { file: real(file), changed, after, ...(before ? { before } : {}) };
56
+ const result = { file: realOr(file), changed, after, ...(before ? { before } : {}) };
40
57
  if (changed)
41
58
  journal.write(file, `${JSON.stringify({ ...settings, statusLine: after }, null, 2)}\n`);
42
59
  return result;