oc-flight-deck 0.24.0 → 0.25.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.
@@ -0,0 +1,92 @@
1
+ // A durable high-water ledger for the lifetime family cost.
2
+ //
3
+ // The host's family roll-up is exact while the host holds it, but pruning old
4
+ // messages or restarting can make it shrink. The lifetime row is a high-water
5
+ // mark: it never goes backwards. A single small JSON file under the user's data
6
+ // directory remembers the highest figure seen for each family root. Every fs
7
+ // failure is swallowed — a broken or unwritable ledger must never break the
8
+ // rail — and no entry is ever deleted or expired.
9
+
10
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
11
+ import { homedir } from "node:os";
12
+ import { dirname, join } from "node:path";
13
+
14
+ export interface LifetimeTotals {
15
+ /** Highest figure known for `id`, or `undefined` when none has been seen. */
16
+ readonly read: (id: string) => number | undefined;
17
+ /** Raise `id` to `value` when it is higher than everything already known. */
18
+ readonly record: (id: string, value: number) => void;
19
+ }
20
+
21
+ export interface LifetimeTotalsOptions {
22
+ /**
23
+ * Ledger path. Defaults to
24
+ * `~/.local/share/opencode/flight-deck/totals.json`; tests pass a temp dir.
25
+ */
26
+ readonly path?: string;
27
+ }
28
+
29
+ /** The shipped ledger path, under the user's data directory. */
30
+ export function defaultLifetimeTotalsPath(): string {
31
+ return join(homedir(), ".local", "share", "opencode", "flight-deck", "totals.json");
32
+ }
33
+
34
+ /**
35
+ * Open the ledger. `path` is the only option; an absent or unreadable file is
36
+ * an empty ledger, never an error. The in-process map is a second high-water:
37
+ * a host that drops messages mid-session cannot shrink `read()` either.
38
+ */
39
+ export function createLifetimeTotals(options: LifetimeTotalsOptions = {}): LifetimeTotals {
40
+ const path = options.path ?? defaultLifetimeTotalsPath();
41
+ const held = new Map<string, number>();
42
+
43
+ // Re-read on every call: another OpenCode process may have raised the file
44
+ // since our last tick, and we must not lower our answer to its figure.
45
+ const storedValues = (): Record<string, number> => {
46
+ try {
47
+ if (!existsSync(path)) return {};
48
+ const parsed: unknown = JSON.parse(readFileSync(path, "utf8"));
49
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return {};
50
+ const values: Record<string, number> = {};
51
+ for (const [id, value] of Object.entries(parsed)) {
52
+ if (typeof value === "number" && Number.isFinite(value) && value > 0) values[id] = value;
53
+ }
54
+ return values;
55
+ } catch {
56
+ // A corrupt or unreadable file is treated as empty, never thrown on.
57
+ return {};
58
+ }
59
+ };
60
+
61
+ const writeAll = (values: Record<string, number>): void => {
62
+ try {
63
+ mkdirSync(dirname(path), { recursive: true });
64
+ const temporary = `${path}.${process.pid}.tmp`;
65
+ writeFileSync(temporary, JSON.stringify(values));
66
+ renameSync(temporary, path);
67
+ } catch {
68
+ // Persistence is best-effort: the in-process high-water still holds.
69
+ }
70
+ };
71
+
72
+ return {
73
+ read(id) {
74
+ const stored = storedValues()[id];
75
+ const memory = held.get(id);
76
+ if (stored === undefined && memory === undefined) return undefined;
77
+ return Math.max(stored ?? 0, memory ?? 0);
78
+ },
79
+ record(id, value) {
80
+ // A non-finite or non-positive figure is not a spend and cannot raise a
81
+ // high-water mark.
82
+ if (!Number.isFinite(value) || value <= 0) return;
83
+ const previous = Math.max(held.get(id) ?? 0, storedValues()[id] ?? 0);
84
+ if (value <= previous) return;
85
+ held.set(id, value);
86
+ // Merge into what is on disk: never delete or prune another entry.
87
+ const values = storedValues();
88
+ values[id] = value;
89
+ writeAll(values);
90
+ },
91
+ };
92
+ }
@@ -6,6 +6,7 @@
6
6
  // session state, and nothing leaves the process.
7
7
 
8
8
  import type { FlightDeckConfig } from "./config.js";
9
+ import { canonicalField } from "./stat-fields.js";
9
10
  import { statLine, statRows, statSegments, type StatSource, type StatSegment } from "./stats.js";
10
11
  import { rowStyle, type LineStyle, type StyleColor, type StyleConfig } from "./style.js";
11
12
 
@@ -44,7 +45,10 @@ export function railLines(config: FlightDeckConfig, source: StatSource = {}): re
44
45
  // The display side of the config, which the row renderer reads alongside its
45
46
  // geometry. `format` is a top-level section, so it is mapped here.
46
47
  // `tpsDisplay` is the `tps` row's view of `sidebar.tps.display`: which of
47
- // the pair's figures draws (the settled-turn average by default).
48
+ // the pair's figures draws (the realtime estimate by default). `tpsLabel`
49
+ // is its view of `sidebar.tps.label`: the suffix on the single-figure rows.
50
+ // `tpsTtft` is its view of `sidebar.tps.ttft`: whether the observed time
51
+ // to first token may draw beside or instead of the figures.
48
52
  const layout = {
49
53
  ...config.layout,
50
54
  persist: config.sidebar.persist,
@@ -52,10 +56,12 @@ export function railLines(config: FlightDeckConfig, source: StatSource = {}): re
52
56
  durationStyle: config.format.duration,
53
57
  timestamp: config.format.timestamp,
54
58
  tpsDisplay: config.sidebar.tps.display,
55
- // Decided from the whole row list, the way `statRows` decides it: `cost`
56
- // folds the subagent total into itself only when no `total` row was asked
57
- // for, even if the cap later drops that row.
58
- hasTotalRow: config.sidebar.rows.includes("total"),
59
+ tpsLabel: config.sidebar.tps.label,
60
+ tpsTtft: config.sidebar.tps.ttft,
61
+ // Decided from the whole row list, the way `statRows` decides it: `spend`
62
+ // folds the subagent total into itself only when no `lifetime` row (or its
63
+ // `total` alias) was asked for, even if the cap later drops that row.
64
+ hasLifetimeRow: config.sidebar.rows.some((field) => canonicalField(field) === "lifetime"),
59
65
  };
60
66
 
61
67
  const lines: RailLine[] = config.sidebar.lines.map((text) => ({ text }));
package/src/tui/rows.ts CHANGED
@@ -340,7 +340,7 @@ export function statLine(
340
340
  const branch = asText(source.branch);
341
341
  return branch === undefined ? undefined : row("branch", branch);
342
342
  }
343
- case "cost": {
343
+ case "spend": {
344
344
  const cost = asCount(source.cost);
345
345
  const tree = asRecord(source.tree);
346
346
  const treeCost = asCount(tree?.cost);
@@ -348,53 +348,53 @@ export function statLine(
348
348
  const family = count !== undefined && count > 0 ? count : 0;
349
349
 
350
350
  // Merge only when subagents actually ran, and only when the rail is not
351
- // already showing a `total` row. Two rows holding a number and its own
352
- // superset was the thing worth fixing; a setting to choose between them
353
- // would just be that duplication with extra steps.
351
+ // already showing a `lifetime` row (or its `total` alias). Two rows
352
+ // holding a number and its own superset was the thing worth fixing; a
353
+ // setting to choose between them would just be that duplication.
354
354
  const merge =
355
- layout.hasTotalRow !== true &&
355
+ layout.hasLifetimeRow !== true &&
356
356
  cost !== undefined &&
357
357
  treeCost !== undefined &&
358
358
  family > 0 &&
359
359
  treeCost > cost;
360
360
 
361
361
  if (!merge) {
362
- // `cost` is the current model's spend and nothing else: when it is not
363
- // known the row stays absent rather than borrowing the family figure
364
- // under a label that promises one model.
365
- if (cost === undefined) return undefined;
366
- return row("cost", `${feeMark(source.costKind)}${formatCost(cost)}`);
362
+ // `spend` is the current model's spend and nothing else. With no spend
363
+ // on that model the row draws a sane zero, never a dash or a hole, and
364
+ // it still never borrows the family figure under a one-model label.
365
+ // `field` keeps the caller's spelling, so the `cost` alias still draws
366
+ // its old label.
367
+ return row(field, `${feeMark(source.costKind)}${formatCost(cost ?? 0)}`);
367
368
  }
368
369
 
369
370
  // The delta (`+$0.020`) used to be here and pushed the row to 40 columns,
370
371
  // wide enough to wrap in a normal sidebar. It was real information that
371
372
  // did not earn its width: the count already explains why the figure is
372
- // higher, and this form is the same width as the old `total` row.
373
+ // higher, and this form is the same width as the lifetime row.
373
374
  const plural = family === 1 ? "subagent" : "subagents";
374
- return row(
375
- "cost",
376
- `${feeMark(tree?.kind)}${formatCost(treeCost as number)} · ${family} ${plural}`,
377
- );
375
+ return row(field, `${feeMark(tree?.kind)}${formatCost(treeCost as number)} · ${family} ${plural}`);
378
376
  }
379
- case "total": {
377
+ case "lifetime": {
380
378
  // The family figure: this session plus its subagent sessions. Since 0.20.0
381
379
  // it is drawn even when no subagent has run — the true family total is then
382
380
  // the session's own cost, and the row reads `$0.000 · 0 subagents` rather
383
381
  // than blanking, because the row the owner renames to `lifetime` must never
384
- // have a hole in it. Still `undefined` when there is no family data at all,
385
- // so the persist layer keeps its zero skeleton for a session with no record.
386
- const tree = asRecord(source.tree);
387
- if (tree === undefined) return undefined;
388
- const cost = asCount(tree.cost);
389
- if (cost === undefined) return undefined;
390
- const count = asCount(tree.count) ?? 0;
382
+ // have a hole in it. With no family record at all it still draws the
383
+ // honest zero: this is a numeric row, so it never blanks or falls back
384
+ // to the placeholder.
385
+ const live = asRecord(source.tree);
386
+ const durable = asRecord(source.lifetime);
387
+ // The durable high-water wins over the host's current roll-up so the
388
+ // lifetime never shrinks. The cost row keeps reading `tree` alone, so
389
+ // raising this figure cannot change the current model's spend.
390
+ const cost = asCount(durable?.cost) ?? asCount(live?.cost) ?? 0;
391
+ const count = asCount(live?.count) ?? 0;
391
392
  const plural = count === 1 ? "subagent" : "subagents";
392
- return row("total", `${feeMark(tree.kind)}${formatCost(cost)} · ${count} ${plural}`);
393
+ return row(field, `${feeMark(durable?.kind ?? live?.kind)}${formatCost(cost)} · ${count} ${plural}`);
393
394
  }
394
395
  case "project": {
395
396
  const project = asRecord(source.project);
396
- const cost = asCount(project?.cost);
397
- if (cost === undefined) return undefined;
397
+ const cost = asCount(project?.cost) ?? 0;
398
398
  const count = asCount(project?.count);
399
399
  return row("project", `${formatCost(cost)}${count !== undefined && count > 1 ? ` · ${count} sessions` : ""}`);
400
400
  }
@@ -402,15 +402,16 @@ export function statLine(
402
402
  const tokens = asRecord(source.tokens);
403
403
  const input = asCount(tokens?.input);
404
404
  const output = asCount(tokens?.output);
405
- if (input === undefined && output === undefined) return undefined;
405
+ // No token record is a measured zero, not missing data: the row always
406
+ // draws its honest `0 in · 0 out`.
406
407
  return row("tokens", `${formatCount(input ?? 0)} in · ${formatCount(output ?? 0)} out`);
407
408
  }
408
409
  case "cache": {
409
410
  const tokens = asRecord(source.tokens);
410
- if (tokens === undefined) return undefined;
411
- const cache = asRecord(tokens.cache);
412
- const read = asCount(cache?.read);
413
- if (read === undefined) return undefined;
411
+ const cache = asRecord(tokens?.cache);
412
+ // An absent token record draws `0 read` rather than blanking: a numeric
413
+ // row always has an honest zero to show.
414
+ const read = asCount(cache?.read) ?? 0;
414
415
  const input = asCount(tokens?.input);
415
416
  // Hit ratio is the whole point: it explains a cheap bill on a huge token
416
417
  // count, and it is the first thing to break when caching stops working.
@@ -437,8 +438,10 @@ export function statLine(
437
438
  case "context": {
438
439
  const context = asRecord(source.context);
439
440
  const used = asCount(context?.used);
440
- if (used === undefined || used === 0) return undefined;
441
441
  const limit = asCount(context?.limit);
442
+ // No occupancy yet is a measured zero, drawn as `~0 used` with the same
443
+ // estimate mark as the populated row. A numeric row never blanks.
444
+ if (used === undefined || used === 0) return row("context", "~0 used");
442
445
  // `used` is an occupancy PROXY (last request's input + cache read +
443
446
  // cache write), not a host-reported figure, so both shapes below carry
444
447
  // a `~`: the row reads as the estimate it is, never as an exact count.
@@ -467,8 +470,9 @@ export function statLine(
467
470
  return row("perms", resource === undefined ? action : `${action} · ${clip(resource, 18)}`);
468
471
  }
469
472
  case "elapsed": {
470
- const ms = asCount(source.elapsedMs);
471
- if (ms === undefined || ms <= 0) return undefined;
473
+ // A session with no recorded turn time has spent zero active seconds.
474
+ // Draw that zero instead of hiding the numeric row.
475
+ const ms = asCount(source.elapsedMs) ?? 0;
472
476
  return row("elapsed", formatDuration(ms, layout.durationStyle));
473
477
  }
474
478
  case "updated": {
@@ -491,44 +495,37 @@ export function statLine(
491
495
  // boundary, so all re-coerced like every other field. Which one draws
492
496
  // is `layout.tpsDisplay` (the row's view of `sidebar.tps.display`,
493
497
  // default `"rt"`); presentation.ts feeds it from the resolved config.
498
+ // `layout.tpsTtft` is `sidebar.tps.ttft`: off, `ttft` never draws in any
499
+ // mode. `layout.tpsLabel` is `sidebar.tps.label`: the suffix on the two
500
+ // single-figure modes ("tok/s" shipped); "both" names its own halves.
494
501
  const pair = asRecord(source.tps);
495
502
  const rt = asCount(pair?.["rt"]);
496
503
  const avg = asCount(pair?.["avg"]);
497
504
  const ttft = asCount(pair?.["ttft"]);
505
+ const shownTtft = (layout.tpsTtft ?? true) ? ttft : undefined;
498
506
  const display = layout.tpsDisplay ?? "rt";
507
+ const label = layout.tpsLabel ?? "tok/s";
508
+ // A numeric row never blanks. An absent or sub-half rate is a measured
509
+ // zero, so it draws `0 <label>` — never a placeholder and never a
510
+ // ttft-only fallback. Figures are whole tokens/second: the value is an
511
+ // EWMA over estimated delta samples, so a decimal would fake precision.
512
+ const rounded = (value: number | undefined): number => {
513
+ const value_ = value === undefined ? 0 : Math.round(value);
514
+ return value_ > 0 ? value_ : 0;
515
+ };
516
+ const current = rounded(rt);
517
+ const settled = rounded(avg);
518
+ const suffix = shownTtft === undefined ? "" : ` · ${shownTtft.toFixed(1)}s ttft`;
499
519
  if (display === "rt") {
500
- // Whole tokens/second, honestly rounded — the value is already an
501
- // EWMA over estimated delta samples, so a decimal would fake a
502
- // precision the samples never had. Anything below half a
503
- // token/second hides rather than printing "0 tok/s".
504
- const rounded = rt === undefined ? undefined : Math.round(rt);
505
- if (rounded === undefined || rounded <= 0) {
506
- return ttft === undefined ? undefined : row("tps", `${ttft.toFixed(1)}s ttft`);
507
- }
508
- const rate = `${rounded} tok/s`;
509
- return row("tps", ttft === undefined ? rate : `${rate} · ${ttft.toFixed(1)}s ttft`);
520
+ return row("tps", current > 0 ? `${current} ${label}${suffix}` : `0 ${label}`);
510
521
  }
511
522
  if (display === "both") {
512
- // Both figures on one line when the average stands — the realtime
513
- // half may round to zero while the average stands (`0 rt · 41 avg`).
514
- // The mean time to first token rides along only once observed
515
- // (`83 rt · 38 avg · 1.2s ttft`); unknown is omitted, never zeroed.
516
- // The realtime-alone degrade is only for a missing average; a present
517
- // average that rounds to zero hides the whole row, like the avg
518
- // mode's own hide rule. Without either figure there is no row.
519
- if (avg !== undefined) {
520
- if (Math.round(avg) <= 0) return undefined;
521
- const head = `${rt === undefined ? 0 : Math.round(rt)} rt · ${Math.round(avg)} avg`;
522
- return ttft === undefined ? row("tps", head) : row("tps", `${head} · ${ttft.toFixed(1)}s ttft`);
523
- }
524
- if (rt !== undefined && Math.round(rt) > 0) return row("tps", `${Math.round(rt)} rt`);
525
- return undefined;
523
+ // Both halves keep their structural names, whatever `label` says.
524
+ // TTFT rides only when a rate stands; a zero rate never borrows it.
525
+ const head = `${current} rt · ${settled} avg`;
526
+ return row("tps", settled > 0 ? head + suffix : head);
526
527
  }
527
- // The default: the settled-turn average over the scope, honestly
528
- // rounded. The hide rule is the realtime row's own: at or below half a
529
- // token/second it hides rather than printing "0 tok/s".
530
- if (avg === undefined || Math.round(avg) <= 0) return undefined;
531
- return row("tps", `${Math.round(avg)} tok/s`);
528
+ return row("tps", `${settled} ${label}`);
532
529
  }
533
530
  case "spark": {
534
531
  const values = Array.isArray(source.spark) ? source.spark.map((value) => asCount(value) ?? 0) : [];
@@ -539,8 +536,9 @@ export function statLine(
539
536
  return row("spark", sparkline(windowed));
540
537
  }
541
538
  case "reasoning": {
542
- const reasoning = asCount(asRecord(source.tokens)?.reasoning);
543
- if (reasoning === undefined || reasoning === 0) return undefined;
539
+ // A model that emits no reasoning tokens still reads `0` on the row;
540
+ // the count keeps the same unit as a populated figure.
541
+ const reasoning = asCount(asRecord(source.tokens)?.reasoning) ?? 0;
544
542
  return row("reasoning", formatCount(reasoning));
545
543
  }
546
544
  case "turns": {
@@ -641,18 +639,22 @@ export function statRows(
641
639
  source: StatSource,
642
640
  layout: LayoutHint = {},
643
641
  ): readonly string[] {
644
- // The rows list decides whether `cost` merges the subagent total into itself.
645
- // Passing that down means the choice lives in `sidebar.rows`, where someone
646
- // is already deciding what the rail shows.
647
- const hint: LayoutHint = { ...layout, hasTotalRow: fields.includes("total") };
642
+ // The rows list decides whether `spend` merges the subagent total into
643
+ // itself. Both `lifetime` and its `total` alias count, so an old config keeps
644
+ // its one-money-row-per-figure shape.
645
+ const hint: LayoutHint = {
646
+ ...layout,
647
+ hasLifetimeRow: fields.some((field) => canonicalField(field) === "lifetime"),
648
+ };
648
649
  const persist = hint.persist === true;
649
650
  const placeholder = hint.placeholder ?? DEFAULT_PLACEHOLDER;
650
651
  const labelWidth = hint.labelWidth ?? DEFAULT_LABEL_WIDTH;
651
652
  const rows: string[] = [];
652
653
  for (const field of fields) {
653
- // Canonicalized once, so the alias and the key take the same path below.
654
+ // The renderer canonicalizes internally; the original spelling is kept so
655
+ // an alias still draws its old label byte-for-byte.
654
656
  const name = canonicalField(field);
655
- const line = statLine(name, source, hint);
657
+ const line = statLine(field, source, hint);
656
658
  if (line !== undefined) {
657
659
  rows.push(line);
658
660
  continue;
@@ -40,6 +40,11 @@ export interface StatSource {
40
40
  */
41
41
  readonly sessionId?: unknown;
42
42
  readonly tree?: unknown;
43
+ /**
44
+ * The durable high-water family figure for the lifetime row, when the host's
45
+ * current `tree` has shrunk. Untrusted like every other field.
46
+ */
47
+ readonly lifetime?: unknown;
43
48
  readonly context?: unknown;
44
49
  readonly project?: unknown;
45
50
  readonly status?: unknown;
@@ -90,8 +95,8 @@ export const STAT_FIELDS = [
90
95
  "agent",
91
96
  "model",
92
97
  "branch",
93
- "cost",
94
- "total",
98
+ "spend",
99
+ "lifetime",
95
100
  "project",
96
101
  "tokens",
97
102
  "cache",
@@ -128,23 +133,32 @@ type StatField = (typeof STAT_FIELDS)[number];
128
133
  export const ANIMATED_FIELDS = ["caution", "status", "elapsed", "tps"] as const;
129
134
 
130
135
  export function isStatField(value: string): value is StatField {
131
- // `session` is the display alias for `ses`: accepted here and folded back by
136
+ // `session`, `cost` and `total` are accepted aliases, folded back by
132
137
  // `canonicalField`, but kept out of `STAT_FIELDS` on purpose — that array is
133
- // the config vocabulary echoed in config error messages, and the key stays
134
- // `ses`.
135
- return value === "session" || STAT_FIELDS.some((field) => field === value);
138
+ // the canonical config vocabulary echoed in config error messages. The
139
+ // aliases stay accepted forever so no existing config breaks.
140
+ return (
141
+ value === "session" ||
142
+ value === "cost" ||
143
+ value === "total" ||
144
+ STAT_FIELDS.some((field) => field === value)
145
+ );
136
146
  }
137
147
 
138
148
  /**
139
149
  * The canonical config key for a field name.
140
150
  *
141
- * `session` is accepted as an alias for `ses` and folds back to it; every
142
- * other name is returned unchanged. The renderers canonicalize their field
143
- * argument at entry, so `statLine("session", …)` renders byte-identically to
144
- * `statLine("ses", …)`.
151
+ * `session` folds to `ses`, `cost` to `spend`, and `total` to `lifetime`.
152
+ * Every other name is returned unchanged. The renderers canonicalize their
153
+ * field argument at entry, so an alias and its key take the same behavioural
154
+ * path; the caller's original spelling is kept for the label, so an old config
155
+ * still draws the same bytes.
145
156
  */
146
157
  export function canonicalField(name: string): string {
147
- return name === "session" ? "ses" : name;
158
+ if (name === "session") return "ses";
159
+ if (name === "cost") return "spend";
160
+ if (name === "total") return "lifetime";
161
+ return name;
148
162
  }
149
163
 
150
164
  /**
@@ -189,13 +203,13 @@ export interface LayoutHint {
189
203
  */
190
204
  readonly timestamp?: TimestampFormat;
191
205
  /**
192
- * True when the rail already draws a `total` row.
206
+ * True when the rail already draws a `lifetime` row (or its `total` alias).
193
207
  *
194
- * The `cost` row merges the subagent total into itself only when nothing else
195
- * on the rail already shows it — which makes "do I want one money row or two"
196
- * a property of `sidebar.rows`, not a separate setting to find.
208
+ * The `spend` row merges the subagent total into itself only when nothing
209
+ * else on the rail already shows it — which makes "one money row or two" a
210
+ * property of `sidebar.rows`, not a separate setting to find.
197
211
  */
198
- readonly hasTotalRow?: boolean;
212
+ readonly hasLifetimeRow?: boolean;
199
213
  /**
200
214
  * Per-row label overrides, keyed by the canonical row name (`ses`, not
201
215
  * `session`). Carried here rather than read from config directly so both
@@ -215,6 +229,21 @@ export interface LayoutHint {
215
229
  * imports this one.
216
230
  */
217
231
  readonly tpsDisplay?: "avg" | "rt" | "both";
232
+ /**
233
+ * Suffix printed after the number on the single-figure `tps` rows (`rt`
234
+ * and `avg`), from `sidebar.tps.label`. Default `"tok/s"`. `both` names
235
+ * its halves itself and ignores this. Structurally typed, never the
236
+ * config's own type: this module must not import config.
237
+ */
238
+ readonly tpsLabel?: string;
239
+ /**
240
+ * Whether the `tps` row may draw the observed mean time to first token
241
+ * (`1.2s ttft`). Off suppresses that segment in every display mode,
242
+ * including the realtime fallback row shown when no rate can be drawn.
243
+ * Default true. Carried here as the config's boolean, never its own type:
244
+ * like the other hints, this module must not import config.
245
+ */
246
+ readonly tpsTtft?: boolean;
218
247
  /**
219
248
  * When true, `statRows` renders one row per named field even when the host
220
249
  * has no data for it, using `skeletonValue` (a live-shaped zero) and falling
@@ -236,7 +265,7 @@ export interface LayoutHint {
236
265
  }
237
266
 
238
267
  /** Fallback placeholder for a persistent row with no data and no skeleton. */
239
- export const DEFAULT_PLACEHOLDER = "—";
268
+ export const DEFAULT_PLACEHOLDER = "0";
240
269
 
241
270
  export const DEFAULT_LABEL_WIDTH = 10;
242
271
  export const DEFAULT_SPARK_WIDTH = 12;
@@ -256,8 +285,8 @@ export const DEFAULT_SPARK_WIDTH = 12;
256
285
  */
257
286
  export function skeletonValue(field: string, layout: LayoutHint): string | undefined {
258
287
  switch (canonicalField(field)) {
259
- case "cost":
260
- case "total":
288
+ case "spend":
289
+ case "lifetime":
261
290
  case "project":
262
291
  return formatCost(0);
263
292
  case "tokens":
@@ -270,9 +299,13 @@ export function skeletonValue(field: string, layout: LayoutHint): string | undef
270
299
  return "0 waiting";
271
300
  case "elapsed":
272
301
  return formatDuration(0, layout.durationStyle);
273
- case "tps":
274
- // An absent rate is not a measured zero.
275
- return undefined;
302
+ case "tps": {
303
+ // Same zero the row itself draws: an absent rate is a measured zero,
304
+ // never a placeholder. Kept here for callers that ask for a skeleton
305
+ // directly, even though the row now always renders one.
306
+ const label = layout.tpsLabel ?? "tok/s";
307
+ return layout.tpsDisplay === "both" ? `0 rt · 0 avg` : `0 ${label}`;
308
+ }
276
309
  case "spark":
277
310
  return "▁".repeat(Math.max(0, Math.floor(layout.sparkWidth ?? DEFAULT_SPARK_WIDTH)));
278
311
  case "reasoning":