oc-flight-deck 0.24.0 → 0.25.1

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.
package/src/tui/config.ts CHANGED
@@ -9,6 +9,7 @@
9
9
  // defaults below, so the rail always renders and a typo can never break the TUI.
10
10
 
11
11
  import { DEFAULT_PLACEHOLDER, canonicalField, isStatField, STAT_FIELDS } from "./stats.js";
12
+ import { defaultLifetimeTotalsPath } from "./lifetime-totals.js";
12
13
  import type { CautionThresholds } from "./caution.js";
13
14
  import type { DurationStyle, TimestampDateStyle, TimestampTimeStyle } from "./format.js";
14
15
  import {
@@ -33,7 +34,7 @@ interface SidebarConfig {
33
34
  readonly footer: SidebarFooterConfig;
34
35
  /** Live session fields to render, top to bottom. Default `DEFAULT_SIDEBAR_ROWS`. */
35
36
  readonly rows: readonly string[];
36
- /** Which sessions the `tps` row paces, and which figure it draws. Default `{ scope: DEFAULT_TPS_SCOPE, display: DEFAULT_TPS_DISPLAY }`. */
37
+ /** Which sessions the `tps` row paces, which figure it draws, its single-figure suffix, and whether TTFT may show. Default `{ scope: DEFAULT_TPS_SCOPE, display: DEFAULT_TPS_DISPLAY, label: DEFAULT_TPS_LABEL, ttft: DEFAULT_TPS_TTFT }`. */
37
38
  readonly tps: TpsConfig;
38
39
  /**
39
40
  * Render every named row even when the host has no data for it, using
@@ -157,11 +158,28 @@ export const DEFAULT_TPS_SCOPE: TpsScope = "family";
157
158
  */
158
159
  export const DEFAULT_TPS_DISPLAY: TpsDisplay = "rt";
159
160
 
161
+ /**
162
+ * The shipped `tps` TTFT switch: `true`, so the observed time to first token
163
+ * keeps its place beside the figures until the owner turns it off.
164
+ */
165
+ export const DEFAULT_TPS_TTFT = true;
166
+
167
+ /**
168
+ * The shipped `tps` single-figure suffix: `"tok/s"`, so a new user sees the
169
+ * same line as before. `display: "both"` names its halves itself and ignores
170
+ * this key.
171
+ */
172
+ export const DEFAULT_TPS_LABEL = "tok/s";
173
+
160
174
  interface TpsConfig {
161
175
  /** Which sessions the `tps` row paces. Default `DEFAULT_TPS_SCOPE`. */
162
176
  readonly scope: TpsScope;
163
177
  /** Which figure the `tps` row draws. Default `DEFAULT_TPS_DISPLAY`. */
164
178
  readonly display: TpsDisplay;
179
+ /** Suffix on the single-figure rows (`rt`, `avg`). Default `DEFAULT_TPS_LABEL`. */
180
+ readonly label: string;
181
+ /** Whether the observed time to first token may render. Default `DEFAULT_TPS_TTFT`. */
182
+ readonly ttft: boolean;
165
183
  }
166
184
 
167
185
  interface SidebarFooterConfig {
@@ -272,6 +290,12 @@ export interface FlightDeckConfig {
272
290
  * it needs a tick. `0` turns the ticker off, leaving every row event-driven.
273
291
  */
274
292
  readonly refresh: number;
293
+ /**
294
+ * Path to the durable lifetime-totals ledger. Ships as
295
+ * `~/.local/share/opencode/flight-deck/totals.json`; a host config can point
296
+ * it at another file, which is also the test seam.
297
+ */
298
+ readonly lifetimeTotalsPath: string;
275
299
  }
276
300
 
277
301
  /** The millisecond view the rules in ./caution.ts operate on. */
@@ -309,18 +333,20 @@ interface LayoutConfig {
309
333
  }
310
334
 
311
335
  /**
312
- * The annunciator's glyphs: one mark per severity.
336
+ * The rail's status marks: one per annunciator severity, plus the status row's
337
+ * paused mark.
313
338
  *
314
- * All three are single-cell marks — `▲` watch, `●` caution, `○` clear — so the
315
- * annunciator row lines up with every other row on the rail regardless of how
316
- * the terminal classifies their East Asian width. Configurable because this is
317
- * the one row that has to read at a glance, and a terminal that draws one of
318
- * these badly can be given a substitute without a rebuild.
339
+ * All four are single-cell marks — `▲` watch, `●` caution, `○` clear, `‖`
340
+ * paused — so the rail lines up regardless of how the terminal classifies
341
+ * their East Asian width. Configurable because these have to read at a glance,
342
+ * and a terminal that draws one badly can be given a substitute without a
343
+ * rebuild.
319
344
  */
320
345
  interface GlyphConfig {
321
346
  readonly watch: string;
322
347
  readonly caution: string;
323
348
  readonly clear: string;
349
+ readonly paused: string;
324
350
  }
325
351
 
326
352
  /**
@@ -382,6 +408,7 @@ const DEFAULT_GLYPHS: GlyphConfig = {
382
408
  watch: "▲",
383
409
  caution: "●",
384
410
  clear: "○",
411
+ paused: "‖",
385
412
  };
386
413
 
387
414
  /**
@@ -464,7 +491,7 @@ export const DEFAULT_SIDEBAR_ROWS: readonly string[] = [
464
491
  "status",
465
492
  "agent",
466
493
  "model",
467
- "cost",
494
+ "spend",
468
495
  "project",
469
496
  "tokens",
470
497
  "cache",
@@ -510,7 +537,12 @@ export const DEFAULT_CONFIG: FlightDeckConfig = {
510
537
  lines: DEFAULT_SIDEBAR_LINES,
511
538
  footer: { lines: DEFAULT_SIDEBAR_FOOTER_LINES, go: false },
512
539
  rows: DEFAULT_SIDEBAR_ROWS,
513
- tps: { scope: DEFAULT_TPS_SCOPE, display: DEFAULT_TPS_DISPLAY },
540
+ tps: {
541
+ scope: DEFAULT_TPS_SCOPE,
542
+ display: DEFAULT_TPS_DISPLAY,
543
+ label: DEFAULT_TPS_LABEL,
544
+ ttft: DEFAULT_TPS_TTFT,
545
+ },
514
546
  persist: true,
515
547
  placeholder: DEFAULT_PLACEHOLDER,
516
548
  maxLines: MAX_LINES,
@@ -523,6 +555,7 @@ export const DEFAULT_CONFIG: FlightDeckConfig = {
523
555
  glyphs: DEFAULT_GLYPHS,
524
556
  style: DEFAULT_STYLE,
525
557
  refresh: DEFAULT_REFRESH_MS,
558
+ lifetimeTotalsPath: defaultLifetimeTotalsPath(),
526
559
  };
527
560
 
528
561
  /** Layout guards: keep a hand-edited config from producing an unusable rail. */
@@ -780,7 +813,20 @@ function readRows(value: unknown, issues: string[], maxLines: number): readonly
780
813
  issues.push(`${path} is not a known field (${STAT_FIELDS.join(", ")}); skipping it`);
781
814
  return;
782
815
  }
783
- rows.push(canonicalField(name));
816
+ // An alias and its key name one row. Keep the first spelling (so an old
817
+ // config keeps its old label) and report the second rather than drawing
818
+ // the same figure twice.
819
+ const canonical = canonicalField(name);
820
+ const duplicateOf = rows.find((entry) => canonicalField(entry) === canonical);
821
+ if (duplicateOf !== undefined) {
822
+ issues.push(`${path} duplicates ${duplicateOf}; rendering the row once`);
823
+ return;
824
+ }
825
+ // `session` keeps folding to `ses`; `cost` and `total` keep their spelling
826
+ // so old configs render byte-for-byte as they did before the rename.
827
+ // The guard above narrows to the canonical union, but the original string
828
+ // may still be an accepted alias; read it as a plain string here.
829
+ rows.push((name as string) === "session" ? "ses" : name);
784
830
  });
785
831
 
786
832
  if (rows.length === 0) {
@@ -818,6 +864,45 @@ function readTpsDisplay(value: unknown, issues: string[]): TpsDisplay {
818
864
  return DEFAULT_TPS_DISPLAY;
819
865
  }
820
866
 
867
+ /**
868
+ * Whether the `tps` row may draw the observed time to first token.
869
+ *
870
+ * A boolean knob: `false` suppresses the TTFT segment in every display mode,
871
+ * including the realtime fallback row that otherwise appears when no rate can
872
+ * be drawn. A non-boolean falls back to the shipped default and is reported.
873
+ */
874
+ function readTpsTtft(value: unknown, issues: string[]): boolean {
875
+ return readBoolean(value, DEFAULT_TPS_TTFT, "sidebar.tps.ttft", issues);
876
+ }
877
+
878
+ /** Longest suffix the single-figure `tps` rows accept before the rail gets silly. */
879
+ const TPS_LABEL_MAX_LENGTH = 16;
880
+
881
+ /**
882
+ * The suffix the single-figure `tps` rows print after the number.
883
+ *
884
+ * A short string, trimmed like the other text values. Blank means no label to
885
+ * draw, so the default comes back and the key is named; a non-string and an
886
+ * overlong value fall back the same way. `display: "both"` ignores it.
887
+ */
888
+ function readTpsLabel(value: unknown, issues: string[]): string {
889
+ if (value === undefined) return DEFAULT_TPS_LABEL;
890
+ if (typeof value !== "string") {
891
+ issues.push("sidebar.tps.label must be a string; using the default");
892
+ return DEFAULT_TPS_LABEL;
893
+ }
894
+ const text = normalizeText(value, "sidebar.tps.label", issues);
895
+ if (text.length === 0) {
896
+ issues.push("sidebar.tps.label must not be empty; using the default");
897
+ return DEFAULT_TPS_LABEL;
898
+ }
899
+ if (text.length > TPS_LABEL_MAX_LENGTH) {
900
+ issues.push(`sidebar.tps.label was longer than ${TPS_LABEL_MAX_LENGTH} characters; using the default`);
901
+ return DEFAULT_TPS_LABEL;
902
+ }
903
+ return text;
904
+ }
905
+
821
906
  /**
822
907
  * Which sessions the `tps` row paces.
823
908
  *
@@ -829,10 +914,20 @@ function readTps(section: Record<string, unknown>, issues: string[]): TpsConfig
829
914
  const raw = section["tps"];
830
915
  if (raw !== undefined && !isRecord(raw)) {
831
916
  issues.push("sidebar.tps must be an object; using defaults");
832
- return { scope: DEFAULT_TPS_SCOPE, display: DEFAULT_TPS_DISPLAY };
917
+ return {
918
+ scope: DEFAULT_TPS_SCOPE,
919
+ display: DEFAULT_TPS_DISPLAY,
920
+ label: DEFAULT_TPS_LABEL,
921
+ ttft: DEFAULT_TPS_TTFT,
922
+ };
833
923
  }
834
924
  const tps = isRecord(raw) ? raw : {};
835
- return { scope: readTpsScope(tps["scope"], issues), display: readTpsDisplay(tps["display"], issues) };
925
+ return {
926
+ scope: readTpsScope(tps["scope"], issues),
927
+ display: readTpsDisplay(tps["display"], issues),
928
+ label: readTpsLabel(tps["label"], issues),
929
+ ttft: readTpsTtft(tps["ttft"], issues),
930
+ };
836
931
  }
837
932
 
838
933
  /**
@@ -853,6 +948,22 @@ function sectionOf(options: Record<string, unknown>, key: SectionKey): Record<st
853
948
  return isRecord(value) ? value : {};
854
949
  }
855
950
 
951
+ /**
952
+ * Optional override for the durable lifetime-totals file.
953
+ *
954
+ * A non-empty string is used as given; an absent key leaves the module's
955
+ * shipped path alone. A malformed key is reported and ignored, like every
956
+ * other option.
957
+ */
958
+ function readLifetimeTotalsPath(value: unknown, issues: string[]): string {
959
+ if (value === undefined) return DEFAULT_CONFIG.lifetimeTotalsPath;
960
+ if (typeof value !== "string" || value.trim().length === 0) {
961
+ issues.push("lifetimeTotalsPath must be a non-empty string; using the default path");
962
+ return DEFAULT_CONFIG.lifetimeTotalsPath;
963
+ }
964
+ return value.trim();
965
+ }
966
+
856
967
  /**
857
968
  * Read the ticker cadence.
858
969
  *
@@ -1210,6 +1321,7 @@ function readGlyphs(section: Record<string, unknown>, issues: string[]): GlyphCo
1210
1321
  watch: readGlyph(section["watch"], DEFAULT_GLYPHS.watch, "glyphs.watch", issues),
1211
1322
  caution: readGlyph(section["caution"], DEFAULT_GLYPHS.caution, "glyphs.caution", issues),
1212
1323
  clear: readGlyph(section["clear"], DEFAULT_GLYPHS.clear, "glyphs.clear", issues),
1324
+ paused: readGlyph(section["paused"], DEFAULT_GLYPHS.paused, "glyphs.paused", issues),
1213
1325
  };
1214
1326
  }
1215
1327
 
@@ -1523,6 +1635,7 @@ export function resolveConfig(options: unknown): ConfigResolution {
1523
1635
  glyphs: readGlyphs(glyphs, issues),
1524
1636
  style: readStyle(style, issues),
1525
1637
  refresh: readRefresh(options.refresh, issues),
1638
+ lifetimeTotalsPath: readLifetimeTotalsPath(options.lifetimeTotalsPath, issues),
1526
1639
  },
1527
1640
  issues,
1528
1641
  };
@@ -30,7 +30,9 @@ import { formatRemaining as formatCompactRemaining, goTone, type GoUsage, type G
30
30
  export { formatRemaining as formatCompactRemaining } from "./go-usage.js";
31
31
  import type { RailLine } from "./presentation.js";
32
32
  import type { StatSegment } from "./rows.js";
33
- import { DEFAULT_PLACEHOLDER } from "./stat-fields.js";
33
+ // The panel's "no reading" mark is its own, not the sidebar row placeholder:
34
+ // changing `sidebar.placeholder` must never rewrite the Go dials.
35
+ const NO_READING = "\u2014";
34
36
  import type { StyleColor } from "./style.js";
35
37
 
36
38
  /** The panel's three windows, in canonical 5h -> 1w -> 1m order. Labels live in the look. */
@@ -482,7 +484,7 @@ function restingLine(
482
484
  }
483
485
  const tail =
484
486
  CELL.repeat(trackCells) +
485
- (look.showPercent ? ` ${alignCell(DEFAULT_PLACEHOLDER, PANEL_PERCENT_WIDTH, look.align)}` : "");
487
+ (look.showPercent ? ` ${alignCell(NO_READING, PANEL_PERCENT_WIDTH, look.align)}` : "");
486
488
  segments.push({ text: tail, tone: "subdued" });
487
489
  return { field: "go", text: segments.map((segment) => segment.text).join(""), segments };
488
490
  }
@@ -535,7 +537,7 @@ function valueLine(
535
537
  appendRun(runs, CELL, "subdued");
536
538
  }
537
539
  if (look.showPercent) {
538
- const percent = ratio === undefined ? DEFAULT_PLACEHOLDER : `${Math.round(ratio * 100)}%`;
540
+ const percent = ratio === undefined ? NO_READING : `${Math.round(ratio * 100)}%`;
539
541
  // The percent joins the meter's trailing run so a uniform meter stays one
540
542
  // span; the countdown is its own dim run (relief, not severity).
541
543
  appendRun(runs, ` ${alignCell(percent, PANEL_PERCENT_WIDTH, look.align)}`, tone);
package/src/tui/index.tsx CHANGED
@@ -15,13 +15,14 @@ import { loadConfigFile } from "./file-config.js";
15
15
  import { createGoLookReader } from "./go-look.js";
16
16
  import { footerLine, railLineSpans, railLines, railLineStyle, type RailLine } from "./presentation.js";
17
17
  import { goPanelLines } from "./go-panel.js";
18
- import { ANIMATED_FIELDS, type StatSource } from "./stats.js";
18
+ import { ANIMATED_FIELDS, canonicalField, type StatSource } from "./stats.js";
19
19
  import { attributeMask, themeColor } from "./style.js";
20
20
  import { startGuardBridge } from "./guard.js";
21
21
  import { startGoBridge } from "./go.js";
22
22
  import { startCodexQuota } from "./codex-quota.js";
23
23
  import { startTicker } from "./ticker.js";
24
24
  import { asCount, asRecord, type SessionLike } from "./coerce.js";
25
+ import { createLifetimeTotals } from "./lifetime-totals.js";
25
26
  import { createProjectTotals } from "./project-totals.js";
26
27
  import { createRealtimeTps } from "./realtime-tps.js";
27
28
  import { createSessionReads, locationOf } from "./session-reads.js";
@@ -54,7 +55,12 @@ export default Plugin.define({
54
55
  // Only the rows actually on the rail are worth deriving: the rail re-runs on
55
56
  // every tick, and a figure nobody asked to see should not cost a walk of the
56
57
  // session database or the model catalog.
57
- const rows = config.sidebar.enabled ? new Set(config.sidebar.rows) : new Set<string>();
58
+ // Canonical keys for the "is this row on screen" checks: `cost` and
59
+ // `total` are accepted aliases of `spend` and `lifetime`, and every one of
60
+ // them must ask for the same underlying read.
61
+ const rows = config.sidebar.enabled
62
+ ? new Set(config.sidebar.rows.map(canonicalField))
63
+ : new Set<string>();
58
64
  const wants = (name: string): boolean => rows.has(name);
59
65
 
60
66
  if (file.issue !== undefined && file.source !== undefined) {
@@ -170,11 +176,17 @@ export default Plugin.define({
170
176
  shellsOf,
171
177
  lastActivity,
172
178
  permsOf,
179
+ openTurnOf,
180
+ pausedOf,
173
181
  busy,
174
182
  } = reads;
175
183
 
176
184
  const { projectTotals } = createProjectTotals(context);
177
185
 
186
+ // The lifetime figure is a high-water mark, not just the host's current
187
+ // family roll-up. This ledger is the only durable state the rail keeps.
188
+ const lifetimeTotals = createLifetimeTotals({ path: config.lifetimeTotalsPath });
189
+
178
190
  const cautionThreshold = cautionThresholds(config.caution);
179
191
 
180
192
  const cautionsOf = (sessionID: string, now: number): Caution[] =>
@@ -183,6 +195,9 @@ export default Plugin.define({
183
195
  shells: shellsOf(sessionID),
184
196
  now,
185
197
  sessionRunning: statusOf(sessionID) === "running",
198
+ // The host flag alone can go stale; only an open turn may drive the
199
+ // silent clock.
200
+ openTurn: openTurnOf(sessionID),
186
201
  lastMessageAt: lastActivity(sessionID),
187
202
  thresholds: cautionThreshold,
188
203
  });
@@ -291,9 +306,10 @@ export default Plugin.define({
291
306
  const location = locationOf(context);
292
307
  const session = context.data.session.get(sessionID) as SessionLike | undefined;
293
308
  const isBusy = busy(sessionID);
294
- // The fast tick exists for the spinner, and the spinner is only drawn while
295
- // something is moving. Everything else on the rail reads in seconds.
296
- spinnerNeeded = wants("status") && isBusy === true;
309
+ const paused = wants("status") ? pausedOf(sessionID) : false;
310
+ // The fast tick exists for the spinner, and the spinner is only drawn
311
+ // while something is moving and nobody is being asked a question.
312
+ spinnerNeeded = wants("status") && isBusy === true && !paused;
297
313
 
298
314
  // A "turn" is one prompt and the work it caused. The host's message list
299
315
  // also carries system, shell and switch records, so counting records
@@ -311,10 +327,34 @@ export default Plugin.define({
311
327
  // roll-up. Neither reads the other's source, so no hand-off can make the
312
328
  // lifetime figure inherit a per-model one.
313
329
  const wantsUsage =
314
- wants("cost") || wants("total") || wants("tokens") || wants("cache") || wants("reasoning");
330
+ wants("spend") || wants("lifetime") || wants("tokens") || wants("cache") || wants("reasoning");
315
331
  const ownCost = wantsUsage ? sessionCost(sessionID, session as SessionLike | undefined) : undefined;
316
332
  const tree = wantsUsage ? treeTotals(sessionID) : undefined;
317
333
 
334
+ // The lifetime figure is a high-water mark. Resolve the family root the
335
+ // same way treeTotals does, read what earlier ticks recorded, and raise
336
+ // the stored figure when the host currently reports more. Only `lifetime`
337
+ // carries the raised number: `tree` stays the live roll-up so the cost
338
+ // row keeps naming the current model's spend alone.
339
+ let lifetime: { cost: number; count: number; kind: string } | undefined;
340
+ if (wantsUsage) {
341
+ let root = sessionID;
342
+ try {
343
+ root = context.data.session.root(sessionID) ?? sessionID;
344
+ } catch {
345
+ root = sessionID;
346
+ }
347
+ const stored = lifetimeTotals.read(root);
348
+ const live = tree?.cost;
349
+ if (live !== undefined && (stored === undefined || live > stored)) {
350
+ lifetimeTotals.record(root, live);
351
+ }
352
+ const high = Math.max(live ?? 0, stored ?? 0);
353
+ if (live !== undefined || stored !== undefined) {
354
+ lifetime = { cost: high, count: tree?.count ?? 0, kind: tree?.kind ?? "bounded" };
355
+ }
356
+ }
357
+
318
358
  return {
319
359
  ...session,
320
360
  cost: ownCost?.cost,
@@ -323,10 +363,12 @@ export default Plugin.define({
323
363
  caution: wants("caution") ? announce(sessionID) : undefined,
324
364
  branch: wants("branch") ? branchOf(location) : undefined,
325
365
  tree,
366
+ lifetime,
326
367
  context: wants("context") ? contextUsage(sessionID, session?.model) : undefined,
327
368
  project: wants("project") ? projectTotals(sessionID) : undefined,
328
369
  status: wants("status") ? statusOf(sessionID) : undefined,
329
370
  busy: isBusy,
371
+ paused,
330
372
  perms: wants("perms") ? permsOf(sessionID) : undefined,
331
373
  tps: wants("tps") ? sessionTps(sessionID, session) : undefined,
332
374
  spark: wants("spark") ? sparkValues(sessionID) : undefined,
@@ -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,13 @@ 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
+ pausedGlyph: config.glyphs.paused,
62
+ // Decided from the whole row list, the way `statRows` decides it: `spend`
63
+ // folds the subagent total into itself only when no `lifetime` row (or its
64
+ // `total` alias) was asked for, even if the cap later drops that row.
65
+ hasLifetimeRow: config.sidebar.rows.some((field) => canonicalField(field) === "lifetime"),
59
66
  };
60
67
 
61
68
  const lines: RailLine[] = config.sidebar.lines.map((text) => ({ text }));