oc-flight-deck 0.6.3 → 0.6.6

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
@@ -10,6 +10,16 @@
10
10
 
11
11
  import { DEFAULT_PLACEHOLDER, isStatField, STAT_FIELDS } from "./stats.js";
12
12
  import type { CautionThresholds } from "./caution.js";
13
+ import type { DurationStyle } from "./format.js";
14
+ import {
15
+ DEFAULT_STYLE,
16
+ STYLE_ATTRIBUTES,
17
+ STYLE_COLORS,
18
+ type LineStyle,
19
+ type StyleAttribute,
20
+ type StyleColor,
21
+ type StyleConfig,
22
+ } from "./style.js";
13
23
 
14
24
  interface SidebarConfig {
15
25
  /** Show the sidebar rail. Default `true`. */
@@ -25,6 +35,12 @@ interface SidebarConfig {
25
35
  readonly persist: boolean;
26
36
  /** Value shown for a row with no data when `persist` is on. Default `"—"`. */
27
37
  readonly placeholder: string;
38
+ /**
39
+ * Cap on the whole rail: fixed lines plus live rows. Default `MAX_LINES`
40
+ * (24). The fixed lines and the live rows draw from one budget, so this is
41
+ * the one number that decides how tall the panel may grow.
42
+ */
43
+ readonly maxLines: number;
28
44
  }
29
45
 
30
46
  interface FooterConfig {
@@ -82,8 +98,15 @@ export interface FlightDeckConfig {
82
98
  readonly caution: CautionConfig;
83
99
  /** Geometry of a row. Every value has a sane default. */
84
100
  readonly layout: LayoutConfig;
101
+ /** How values are written on the rail, e.g. the `elapsed` duration style. */
102
+ readonly format: FormatConfig;
85
103
  /** Glyphs for the annunciator, for terminals that render the defaults badly. */
86
104
  readonly glyphs: GlyphConfig;
105
+ /**
106
+ * Per-line appearance: a colour role and text attributes for the fixed lines
107
+ * and the live rows. Absent config leaves the theme-native look untouched.
108
+ */
109
+ readonly style: StyleConfig;
87
110
  /**
88
111
  * Update cadence in milliseconds for time-derived rows.
89
112
  *
@@ -130,12 +153,29 @@ interface GlyphConfig {
130
153
  readonly clear: string;
131
154
  }
132
155
 
156
+ /**
157
+ * How values are written on the rail.
158
+ *
159
+ * Display only: nothing here changes what is measured, only how a number is
160
+ * drawn.
161
+ */
162
+ interface FormatConfig {
163
+ /**
164
+ * How the `elapsed` row joins its segments: `"spaced"` separates the units
165
+ * with one space (`2h 14m 37s`, the default), `"compact"` hugs them
166
+ * (`2h14m37s`). Zero-padding is identical either way.
167
+ */
168
+ readonly duration: DurationStyle;
169
+ }
170
+
133
171
  const DEFAULT_LAYOUT: LayoutConfig = {
134
172
  labelWidth: 10,
135
173
  barWidth: 10,
136
174
  sparkWidth: 12,
137
175
  };
138
176
 
177
+ const DEFAULT_FORMAT: FormatConfig = { duration: "spaced" };
178
+
139
179
  const DEFAULT_GLYPHS: GlyphConfig = {
140
180
  watch: "▲",
141
181
  caution: "⚠",
@@ -193,6 +233,15 @@ export const DEFAULT_SIDEBAR_ROWS: readonly string[] = [
193
233
  "tps",
194
234
  ];
195
235
 
236
+ /**
237
+ * Default cap on the whole rail: fixed lines plus live rows.
238
+ *
239
+ * The rail shares the sidebar with the host's own content, so a config file
240
+ * naming two dozen rows must not silently push the host off screen.
241
+ * `sidebar.maxLines` exposes it; this is the shipped default.
242
+ */
243
+ export const MAX_LINES = 24;
244
+
196
245
  /**
197
246
  * Ten ticks a second: the status spinner has ten frames, so one rotation takes a
198
247
  * second and reads as motion instead of as a stuck glyph. A tick costs one
@@ -221,16 +270,18 @@ export const DEFAULT_CONFIG: FlightDeckConfig = {
221
270
  rows: DEFAULT_SIDEBAR_ROWS,
222
271
  persist: true,
223
272
  placeholder: DEFAULT_PLACEHOLDER,
273
+ maxLines: MAX_LINES,
224
274
  },
225
275
  footer: { enabled: false, text: DEFAULT_FOOTER_TEXT },
226
276
  caution: DEFAULT_CAUTION,
227
277
  layout: DEFAULT_LAYOUT,
278
+ format: DEFAULT_FORMAT,
228
279
  glyphs: DEFAULT_GLYPHS,
280
+ style: DEFAULT_STYLE,
229
281
  refresh: DEFAULT_REFRESH_MS,
230
282
  };
231
283
 
232
284
  /** Layout guards: keep a hand-edited config from producing an unusable rail. */
233
- export const MAX_LINES = 24;
234
285
  const MAX_LINE_LENGTH = 120;
235
286
 
236
287
  // Rails render on a single line, so control characters are replaced with
@@ -279,7 +330,7 @@ function readText(value: unknown, fallback: string, path: string, issues: string
279
330
  return text;
280
331
  }
281
332
 
282
- function readLines(value: unknown, issues: string[]): readonly string[] {
333
+ function readLines(value: unknown, issues: string[], maxLines: number): readonly string[] {
283
334
  if (value === undefined) return DEFAULT_SIDEBAR_LINES;
284
335
  if (!Array.isArray(value) || value.length === 0) {
285
336
  issues.push("sidebar.lines must be a non-empty array of strings; using the default lines");
@@ -310,9 +361,9 @@ function readLines(value: unknown, issues: string[]): readonly string[] {
310
361
  issues.push("sidebar.lines had no usable entries; using the default lines");
311
362
  return DEFAULT_SIDEBAR_LINES;
312
363
  }
313
- if (lines.length > MAX_LINES) {
314
- issues.push(`sidebar.lines has ${lines.length} entries; keeping the first ${MAX_LINES}`);
315
- return lines.slice(0, MAX_LINES);
364
+ if (lines.length > maxLines) {
365
+ issues.push(`sidebar.lines has ${lines.length} entries; keeping the first ${maxLines}`);
366
+ return lines.slice(0, maxLines);
316
367
  }
317
368
  return lines;
318
369
  }
@@ -323,7 +374,7 @@ function readLines(value: unknown, issues: string[]): readonly string[] {
323
374
  * An unknown name is reported rather than silently dropped: otherwise a typo in
324
375
  * `sidebar.rows` looks identical to the host simply not having the data yet.
325
376
  */
326
- function readRows(value: unknown, issues: string[]): readonly string[] {
377
+ function readRows(value: unknown, issues: string[], maxLines: number): readonly string[] {
327
378
  if (value === undefined) return DEFAULT_SIDEBAR_ROWS;
328
379
  if (!Array.isArray(value) || value.length === 0) {
329
380
  issues.push("sidebar.rows must be a non-empty array of field names; using the default rows");
@@ -355,11 +406,21 @@ function readRows(value: unknown, issues: string[]): readonly string[] {
355
406
  issues.push("sidebar.rows had no usable entries; using the default rows");
356
407
  return DEFAULT_SIDEBAR_ROWS;
357
408
  }
358
- return rows.slice(0, MAX_LINES);
409
+ return rows.slice(0, maxLines);
410
+ }
411
+
412
+ /**
413
+ * The cap on the whole rail, as a whole number of lines.
414
+ *
415
+ * `0` would not draw a small rail, it would draw nothing: anything below one
416
+ * is a bad value, so the default comes back and the key is named.
417
+ */
418
+ function readMaxLines(value: unknown, issues: string[]): number {
419
+ return readNumber(value, MAX_LINES, "sidebar.maxLines", issues, 1, MAX_LINES);
359
420
  }
360
421
 
361
422
  /** Every config section that can be set from the file and overridden by the host. */
362
- type SectionKey = "sidebar" | "footer" | "caution" | "layout" | "glyphs";
423
+ type SectionKey = "sidebar" | "footer" | "caution" | "layout" | "format" | "glyphs" | "style";
363
424
 
364
425
  function sectionOf(options: Record<string, unknown>, key: SectionKey): Record<string, unknown> {
365
426
  const value = options[key];
@@ -421,7 +482,9 @@ export function mergeOptions(fileOptions: unknown, hostOptions: unknown): Record
421
482
  footer: mergeSection(file, host, "footer"),
422
483
  caution: mergeSection(file, host, "caution"),
423
484
  layout: mergeSection(file, host, "layout"),
485
+ format: mergeSection(file, host, "format"),
424
486
  glyphs: mergeSection(file, host, "glyphs"),
487
+ style: mergeSection(file, host, "style"),
425
488
  };
426
489
  }
427
490
 
@@ -462,6 +525,24 @@ function readLayout(section: Record<string, unknown>, issues: string[]): LayoutC
462
525
  };
463
526
  }
464
527
 
528
+ /**
529
+ * The duration style, as one of a fixed set of strings.
530
+ *
531
+ * Unlike a free-text value there is no sensible repair for a misspelled style:
532
+ * the default is restored and the key named, like every other invalid option.
533
+ */
534
+ function readDurationStyle(value: unknown, issues: string[]): DurationStyle {
535
+ if (value === undefined) return DEFAULT_FORMAT.duration;
536
+ const text = typeof value === "string" ? value.trim() : "";
537
+ if (text === "compact" || text === "spaced") return text;
538
+ issues.push('format.duration must be "compact" or "spaced"; using the default');
539
+ return DEFAULT_FORMAT.duration;
540
+ }
541
+
542
+ function readFormat(section: Record<string, unknown>, issues: string[]): FormatConfig {
543
+ return { duration: readDurationStyle(section["duration"], issues) };
544
+ }
545
+
465
546
  /**
466
547
  * One glyph, validated for width.
467
548
  *
@@ -495,6 +576,107 @@ function readGlyphs(section: Record<string, unknown>, issues: string[]): GlyphCo
495
576
  };
496
577
  }
497
578
 
579
+ /**
580
+ * One colour role, as named in the config.
581
+ *
582
+ * The vocabulary is fixed (`STYLE_COLORS`): a config names a role like
583
+ * `warning`, never a raw theme token, so the mapping onto the host's actual
584
+ * tokens stays in ./style.ts, where a host renaming its tokens can be absorbed.
585
+ */
586
+ function readStyleColor(value: unknown, fallback: StyleColor, path: string, issues: string[]): StyleColor {
587
+ if (value === undefined) return fallback;
588
+ const text = typeof value === "string" ? value.trim() : "";
589
+ if ((STYLE_COLORS as readonly string[]).includes(text)) return text as StyleColor;
590
+ issues.push(`${path} must be one of ${STYLE_COLORS.join(", ")}; using ${fallback}`);
591
+ return fallback;
592
+ }
593
+
594
+ /** Attribute names, validated one by one: an unknown name is skipped, not fatal. */
595
+ function readStyleAttributes(
596
+ value: unknown,
597
+ fallback: readonly StyleAttribute[],
598
+ path: string,
599
+ issues: string[],
600
+ ): readonly StyleAttribute[] {
601
+ if (value === undefined) return fallback;
602
+ if (!Array.isArray(value)) {
603
+ issues.push(`${path} must be an array of attribute names; using the default`);
604
+ return fallback;
605
+ }
606
+ const attributes: StyleAttribute[] = [];
607
+ value.forEach((entry, index) => {
608
+ const at = `${path}[${index}]`;
609
+ if (typeof entry !== "string") {
610
+ issues.push(`${at} must be a string; skipping it`);
611
+ return;
612
+ }
613
+ const name = entry.trim();
614
+ if (!(STYLE_ATTRIBUTES as readonly string[]).includes(name)) {
615
+ issues.push(`${at} is not a known attribute (${STYLE_ATTRIBUTES.join(", ")}); skipping it`);
616
+ return;
617
+ }
618
+ attributes.push(name as StyleAttribute);
619
+ });
620
+ return attributes;
621
+ }
622
+
623
+ /**
624
+ * One line's look; every field falls back independently.
625
+ *
626
+ * An entry that names only a colour keeps the attributes it inherited (and the
627
+ * other way round), so a per-row override can change one thing about a row.
628
+ */
629
+ function readLineStyle(value: unknown, fallback: LineStyle, path: string, issues: string[]): LineStyle {
630
+ if (value === undefined) return fallback;
631
+ if (!isRecord(value)) {
632
+ issues.push(`${path} must be an object with color and attributes; using the default`);
633
+ return fallback;
634
+ }
635
+ return {
636
+ color: readStyleColor(value["color"], fallback.color, `${path}.color`, issues),
637
+ attributes: readStyleAttributes(value["attributes"], fallback.attributes, `${path}.attributes`, issues),
638
+ };
639
+ }
640
+
641
+ /**
642
+ * The `style` section: the fixed lines, the wildcard every live row inherits,
643
+ * and per-row overrides.
644
+ *
645
+ * A per-row key must name a known field. That check is what keeps a typo
646
+ * (`style.rows.costly`) from silently styling nothing: unknown names are
647
+ * reported and skipped, exactly like `sidebar.rows`.
648
+ */
649
+ function readStyle(section: Record<string, unknown>, issues: string[]): StyleConfig {
650
+ const rawRows = section["rows"];
651
+ if (rawRows !== undefined && !isRecord(rawRows)) {
652
+ issues.push("style.rows must be an object of row names; using the default");
653
+ }
654
+ const rows = isRecord(rawRows) ? rawRows : {};
655
+
656
+ const lines = readLineStyle(section["lines"], DEFAULT_STYLE.lines, "style.lines", issues);
657
+ const wildcard = readLineStyle(rows["*"], DEFAULT_STYLE.rows.wildcard, "style.rows.*", issues);
658
+
659
+ const overrides: Record<string, LineStyle> = {};
660
+ for (const [key, entry] of Object.entries(rows)) {
661
+ if (key === "*") continue;
662
+ const path = `style.rows.${key}`;
663
+ // Keyed like `sidebar.rows`: normalized for control characters and case,
664
+ // so `"Cost"` is the `cost` row.
665
+ const name = normalizeText(key, path, issues).toLowerCase();
666
+ if (name.length === 0) {
667
+ issues.push(`${path} is empty; skipping it`);
668
+ continue;
669
+ }
670
+ if (!isStatField(name)) {
671
+ issues.push(`${path} is not a known field (${STAT_FIELDS.join(", ")}); skipping it`);
672
+ continue;
673
+ }
674
+ overrides[name] = readLineStyle(entry, wildcard, path, issues);
675
+ }
676
+
677
+ return { lines, rows: { wildcard, overrides } };
678
+ }
679
+
498
680
  /** Tool names, matched exactly. A malformed list falls back whole, not partly. */
499
681
  function readToolNames(value: unknown, issues: string[]): readonly string[] {
500
682
  if (value === undefined) return DEFAULT_CAUTION.exemptTools;
@@ -594,6 +776,8 @@ export function resolveConfig(options: unknown): ConfigResolution {
594
776
  const rawSidebar = options.sidebar;
595
777
  const rawFooter = options.footer;
596
778
  const rawCaution = options.caution;
779
+ const rawFormat = options.format;
780
+ const rawStyle = options.style;
597
781
  if (rawSidebar !== undefined && !isRecord(rawSidebar)) {
598
782
  issues.push("sidebar must be an object; using defaults");
599
783
  }
@@ -603,27 +787,36 @@ export function resolveConfig(options: unknown): ConfigResolution {
603
787
  if (rawCaution !== undefined && !isRecord(rawCaution)) {
604
788
  issues.push("caution must be an object; using defaults");
605
789
  }
790
+ if (rawFormat !== undefined && !isRecord(rawFormat)) {
791
+ issues.push("format must be an object; using defaults");
792
+ }
793
+ if (rawStyle !== undefined && !isRecord(rawStyle)) {
794
+ issues.push("style must be an object; using defaults");
795
+ }
606
796
 
607
797
  const sidebar = isRecord(rawSidebar) ? rawSidebar : {};
608
798
  const footer = isRecord(rawFooter) ? rawFooter : {};
609
799
  const caution = isRecord(rawCaution) ? rawCaution : {};
610
800
  const layout = isRecord(options.layout) ? options.layout : {};
801
+ const format = isRecord(rawFormat) ? rawFormat : {};
611
802
  const glyphs = isRecord(options.glyphs) ? options.glyphs : {};
803
+ const style = isRecord(rawStyle) ? rawStyle : {};
612
804
 
613
805
  // Writing any footer setting counts as asking for the footer, so the rail
614
806
  // turns on as soon as you configure it. It is off only when you said nothing
615
807
  // about it, and an explicit `enabled` always wins either way.
616
808
  const footerConfigured = Object.keys(footer).length > 0;
617
809
 
618
- const lines = readLines(sidebar.lines, issues);
619
- const rows = readRows(sidebar.rows, issues);
620
- // `sidebarLines` caps the whole rail at MAX_LINES, so the fixed lines and the
621
- // live rows draw from one budget. `readLines` already reports its own cut;
622
- // this is the other half, which used to be silent — a long `lines` list ate
623
- // live rows off the bottom of the rail without saying so.
624
- if (lines.length + rows.length > MAX_LINES) {
810
+ const maxLines = readMaxLines(sidebar.maxLines, issues);
811
+ const lines = readLines(sidebar.lines, issues, maxLines);
812
+ const rows = readRows(sidebar.rows, issues, maxLines);
813
+ // `railLines` caps the whole rail at `sidebar.maxLines`, so the fixed lines
814
+ // and the live rows draw from one budget. `readLines` already reports its own
815
+ // cut; this is the other half, which used to be silent — a long `lines` list
816
+ // ate live rows off the bottom of the rail without saying so.
817
+ if (lines.length + rows.length > maxLines) {
625
818
  issues.push(
626
- `sidebar.lines and sidebar.rows total ${lines.length + rows.length} lines; the rail draws the first ${MAX_LINES}`,
819
+ `sidebar.lines and sidebar.rows total ${lines.length + rows.length} lines; the rail draws the first ${maxLines}`,
627
820
  );
628
821
  }
629
822
 
@@ -640,6 +833,7 @@ export function resolveConfig(options: unknown): ConfigResolution {
640
833
  "sidebar.placeholder",
641
834
  issues,
642
835
  ),
836
+ maxLines,
643
837
  },
644
838
  footer: {
645
839
  enabled: readBoolean(footer.enabled, footerConfigured, "footer.enabled", issues),
@@ -647,7 +841,9 @@ export function resolveConfig(options: unknown): ConfigResolution {
647
841
  },
648
842
  caution: readCaution(caution, issues),
649
843
  layout: readLayout(layout, issues),
844
+ format: readFormat(format, issues),
650
845
  glyphs: readGlyphs(glyphs, issues),
846
+ style: readStyle(style, issues),
651
847
  refresh: readRefresh(options.refresh, issues),
652
848
  },
653
849
  issues,
package/src/tui/format.ts CHANGED
@@ -23,15 +23,33 @@ export function formatCost(value: number): string {
23
23
  return `$${value.toFixed(value < 1 ? 3 : 2)}`;
24
24
  }
25
25
 
26
- /** `45s`, `14m07s`, `2h14m37s`. Seconds always show, so the row ticks every second. */
27
- export function formatDuration(ms: number): string {
26
+ /**
27
+ * How `formatDuration` joins its segments: `"compact"` hugs the units
28
+ * (`2h14m37s`), `"spaced"` puts one space between them (`2h 14m 37s`).
29
+ */
30
+ export type DurationStyle = "compact" | "spaced";
31
+
32
+ /**
33
+ * `45s`, `14m07s`, `2h14m37s`; with `spaced`, one space between the segments
34
+ * (`14m 07s`, `2h 14m 37s`). Seconds always show, so the row ticks every
35
+ * second. Zero-padding is identical in both styles: minutes pad when hours are
36
+ * present, seconds pad when minutes are present.
37
+ *
38
+ * The parameter default stays `"compact"`: this formatter's own contract is
39
+ * unchanged for direct callers, while the rail's shipped default comes from
40
+ * `format.duration` (spaced).
41
+ */
42
+ export function formatDuration(ms: number, style: DurationStyle = "compact"): string {
28
43
  const total = Math.floor(ms / 1_000);
29
44
  const seconds = total % 60;
30
45
  const minutes = Math.floor(total / 60) % 60;
31
46
  const hours = Math.floor(total / 3_600);
32
47
  const ss = String(seconds).padStart(2, "0");
33
- if (hours > 0) return `${hours}h${String(minutes).padStart(2, "0")}m${ss}s`;
34
- return minutes > 0 ? `${minutes}m${ss}s` : `${seconds}s`;
48
+ // Only the join between segments differs; with `compact` the join is empty,
49
+ // so that style stays byte-identical to what it has always rendered.
50
+ const join = style === "spaced" ? " " : "";
51
+ if (hours > 0) return `${hours}h${join}${String(minutes).padStart(2, "0")}m${join}${ss}s`;
52
+ return minutes > 0 ? `${minutes}m${join}${ss}s` : `${seconds}s`;
35
53
  }
36
54
 
37
55
  /** Fuel-gauge width in cells when the caller does not override it. */
package/src/tui/index.tsx CHANGED
@@ -3,8 +3,9 @@ import { Plugin } from "@opencode/plugin/tui";
3
3
  import { cautionDetail, cautionText, detectCautions, worstCaution, type Caution } from "./caution.js";
4
4
  import { cautionThresholds, mergeOptions, resolveConfig } from "./config.js";
5
5
  import { loadConfigFile } from "./file-config.js";
6
- import { footerLine, liveRowOffset, sidebarLines } from "./presentation.js";
6
+ import { footerLine, railLines, railLineStyle } from "./presentation.js";
7
7
  import { ANIMATED_FIELDS, type StatSource } from "./stats.js";
8
+ import { attributeMask, themeColor } from "./style.js";
8
9
  import { startGuardBridge } from "./guard.js";
9
10
  import { startTicker } from "./ticker.js";
10
11
  import { asCount, asRecord, type SessionLike } from "./coerce.js";
@@ -58,7 +59,10 @@ export default Plugin.define({
58
59
  const footer = footerLine(config);
59
60
  const releases: Array<() => void> = [];
60
61
 
61
- const reads = createSessionReads(context);
62
+ // Bound a bankable window to a few ticks: `min(60s, max(5s, 4 * refreshMs))`,
63
+ // so a suspended process or a sparse-event gap cannot be billed as work.
64
+ const maxBankedMs = Math.min(60_000, Math.max(5_000, 4 * config.refresh));
65
+ const reads = createSessionReads(context, maxBankedMs);
62
66
  const {
63
67
  messagesOf,
64
68
  isFamilyRoot,
@@ -177,7 +181,7 @@ export default Plugin.define({
177
181
  perms: wants("perms") ? permsOf(sessionID) : undefined,
178
182
  tps: wants("tps") ? sessionTps(sessionID, session) : undefined,
179
183
  spark: wants("spark") ? sparkValues(sessionID) : undefined,
180
- elapsedMs: wants("elapsed") ? sessionElapsed(session) : undefined,
184
+ elapsedMs: wants("elapsed") ? sessionElapsed(sessionID) : undefined,
181
185
  turns,
182
186
  guard: bridge?.status,
183
187
  // Read the tick inside the render so the host registers a dependency on
@@ -237,20 +241,34 @@ export default Plugin.define({
237
241
  void bridge?.status;
238
242
 
239
243
  const source = snapshot(sessionID);
240
- const lines = sidebarLines(config, source);
244
+ const lines = railLines(config, source);
241
245
  if (lines.length === 0) return null;
242
- const offset = Math.min(liveRowOffset(config), lines.length);
243
246
 
244
247
  return (
245
248
  // No padding here: the host already lays out and pads the sidebar,
246
249
  // so adding our own would push the rows out of alignment with it.
247
250
  //
248
- // Every live row gets the same token, the annunciator included. It
249
- // is the same panel; only the glyph changes.
251
+ // Each line resolves its own look from `config.style`: the fixed
252
+ // lines use `style.lines`, and every live row its own entry or the
253
+ // wildcard. `themeColor`/`attributeMask` are the only things that
254
+ // know how a role or an attribute name becomes renderer state, and
255
+ // they hand back plain props here — never escapes.
256
+ //
257
+ // `?? 0` keeps a line with no attributes on the renderer's own
258
+ // default instead of assigning `undefined` over it, so the shipped
259
+ // config draws exactly what it always drew.
250
260
  <box flexDirection="column">
251
- {lines.map((line, index) => (
252
- <text fg={index < offset ? context.theme.text.default : context.theme.text.subdued}>{line}</text>
253
- ))}
261
+ {lines.map((line) => {
262
+ const style = railLineStyle(config.style, line);
263
+ return (
264
+ <text
265
+ fg={themeColor(style.color, context.theme) as string | undefined}
266
+ attributes={attributeMask(style.attributes) ?? 0}
267
+ >
268
+ {line.text}
269
+ </text>
270
+ );
271
+ })}
254
272
  </box>
255
273
  );
256
274
  },
@@ -1,34 +1,84 @@
1
- // Plain-string views of the Flight Deck rail.
2
- //
3
- // Keeping the text layer pure makes it trivial to test, and leaves the JSX in
4
- // index.tsx to do nothing but wrap these strings in themed <text> elements.
5
- // The live rows come from ./stats.ts and are read-only: nothing here mutates
6
- // session state, and nothing leaves the process.
7
-
8
- import type { FlightDeckConfig } from "./config.js";
9
- import { MAX_LINES } from "./config.js";
10
- import { statRows, type StatSource } from "./stats.js";
11
-
12
- /**
13
- * Sidebar lines to render, or an empty list when the sidebar rail is disabled.
14
- *
15
- * Configured `lines` render first (branding, separators, any fixed text), then
16
- * the live rows named by `sidebar.rows`. With `sidebar.persist` (the default)
17
- * every named row renders exactly once, using `sidebar.placeholder` when the
18
- * host has no data yet; with `persist: false` rows with no data are omitted.
19
- */
20
- export function sidebarLines(config: FlightDeckConfig, source: StatSource = {}): readonly string[] {
21
- if (!config.sidebar.enabled) return [];
22
- const layout = { ...config.layout, persist: config.sidebar.persist, placeholder: config.sidebar.placeholder };
23
- return [...config.sidebar.lines, ...statRows(config.sidebar.rows, source, layout)].slice(0, MAX_LINES);
24
- }
25
-
26
- /** Footer text to render, or `undefined` when the footer rail is disabled. */
27
- export function footerLine(config: FlightDeckConfig): string | undefined {
28
- return config.footer.enabled ? config.footer.text : undefined;
29
- }
30
-
31
- /** Index of the first live row, so the caller can theme branding apart from data. */
32
- export function liveRowOffset(config: FlightDeckConfig): number {
33
- return config.sidebar.enabled ? config.sidebar.lines.length : 0;
34
- }
1
+ // Plain-string and per-line views of the Flight Deck rail.
2
+ //
3
+ // Keeping the text layer pure makes it trivial to test, and leaves the JSX in
4
+ // index.tsx to do nothing but wrap these lines in themed <text> elements. The
5
+ // live rows come from ./stats.ts and are read-only: nothing here mutates
6
+ // session state, and nothing leaves the process.
7
+
8
+ import type { FlightDeckConfig } from "./config.js";
9
+ import { statLine, statRows, type StatSource } from "./stats.js";
10
+ import { rowStyle, type LineStyle, type StyleConfig } from "./style.js";
11
+
12
+ /**
13
+ * One line of the rail, before it is themed.
14
+ *
15
+ * `field` names the live row (`cost`, `tps`, ...) and is absent on the fixed
16
+ * branding lines. Carrying the name — rather than only "fixed or live" — is
17
+ * what lets the caller resolve the row's style, wildcard fallback included,
18
+ * without re-deriving which fields were drawn.
19
+ */
20
+ export interface RailLine {
21
+ readonly text: string;
22
+ /** The live row's field name; absent on a fixed line. */
23
+ readonly field?: string;
24
+ }
25
+
26
+ /**
27
+ * The rail's lines in render order: the fixed lines first, then the live rows
28
+ * named by `sidebar.rows`, together capped at `sidebar.maxLines`.
29
+ *
30
+ * With `sidebar.persist` (the default) every named row renders exactly once,
31
+ * using `sidebar.placeholder` when the host has no data yet; with
32
+ * `persist: false` rows with no data are omitted.
33
+ */
34
+ export function railLines(config: FlightDeckConfig, source: StatSource = {}): readonly RailLine[] {
35
+ if (!config.sidebar.enabled) return [];
36
+
37
+ // The display side of the config, which the row renderer reads alongside its
38
+ // geometry. `format` is a top-level section, so it is mapped here.
39
+ const layout = {
40
+ ...config.layout,
41
+ persist: config.sidebar.persist,
42
+ placeholder: config.sidebar.placeholder,
43
+ durationStyle: config.format.duration,
44
+ // Decided from the whole row list, the way `statRows` decides it: `cost`
45
+ // folds the subagent total into itself only when no `total` row was asked
46
+ // for, even if the cap later drops that row.
47
+ hasTotalRow: config.sidebar.rows.includes("total"),
48
+ };
49
+
50
+ const lines: RailLine[] = config.sidebar.lines.map((text) => ({ text }));
51
+ for (const field of config.sidebar.rows) {
52
+ // `statLine` is the half that knows the field's name; persistence stays in
53
+ // `statRows`, which turns a data-less known field into the placeholder.
54
+ // For a row that rendered, the fallback is never reached.
55
+ const text = statLine(field, source, layout) ?? statRows([field], source, layout)[0];
56
+ if (text !== undefined) lines.push({ field, text });
57
+ }
58
+
59
+ return lines.slice(0, config.sidebar.maxLines);
60
+ }
61
+
62
+ /** The rail's lines as plain strings, in render order. */
63
+ export function sidebarTextLines(config: FlightDeckConfig, source: StatSource = {}): readonly string[] {
64
+ return railLines(config, source).map((line) => line.text);
65
+ }
66
+
67
+ /**
68
+ * The pre-style-layer name for {@link sidebarTextLines}.
69
+ *
70
+ * Kept as an alias while callers migrate to the rail-line view: the string
71
+ * view is still the right one for tests and for anything that only wants the
72
+ * text.
73
+ */
74
+ export const sidebarLines = sidebarTextLines;
75
+
76
+ /** The resolved style for one line: fixed lines use `style.lines`, rows their own entry. */
77
+ export function railLineStyle(style: StyleConfig, line: RailLine): LineStyle {
78
+ return line.field === undefined ? style.lines : rowStyle(style, line.field);
79
+ }
80
+
81
+ /** Footer text to render, or `undefined` when the footer rail is disabled. */
82
+ export function footerLine(config: FlightDeckConfig): string | undefined {
83
+ return config.footer.enabled ? config.footer.text : undefined;
84
+ }
package/src/tui/rows.ts CHANGED
@@ -212,7 +212,7 @@ export function statLine(
212
212
  case "elapsed": {
213
213
  const ms = asCount(source.elapsedMs);
214
214
  if (ms === undefined || ms <= 0) return undefined;
215
- return row("elapsed", formatDuration(ms));
215
+ return row("elapsed", formatDuration(ms, layout.durationStyle));
216
216
  }
217
217
  case "tps": {
218
218
  const tps = asCount(source.tps);
@@ -8,6 +8,7 @@
8
8
  // Coercion of untrusted values happens through ./coerce.js.
9
9
 
10
10
  import type { Plugin } from "@opencode/plugin/tui";
11
+ import { createActiveElapsed } from "./active-elapsed.js";
11
12
  import { asCount, asRecord, asText, type SessionLike } from "./coerce.js";
12
13
 
13
14
  /**
@@ -23,7 +24,7 @@ export function locationOf(context: Plugin.Context) {
23
24
  }
24
25
  }
25
26
 
26
- export function createSessionReads(context: Plugin.Context) {
27
+ export function createSessionReads(context: Plugin.Context, maxBankedMs?: number) {
27
28
  /** How many trailing messages are inspected for tool parts. */
28
29
  const RECENT_MESSAGES = 4;
29
30
 
@@ -116,15 +117,6 @@ export function createSessionReads(context: Plugin.Context) {
116
117
  return undefined;
117
118
  };
118
119
 
119
- // Measured against the clock rather than the session's last update, so the
120
- // row keeps moving between events instead of freezing between turns.
121
- const sessionElapsed = (session: SessionLike | undefined): number | undefined => {
122
- const created = asCount(asRecord(session?.time)?.created);
123
- if (created === undefined) return undefined;
124
- const elapsed = Date.now() - created;
125
- return elapsed <= 0 ? undefined : elapsed;
126
- };
127
-
128
120
  const statusOf = (sessionID: string): string | undefined => {
129
121
  try {
130
122
  return context.data.session.status(sessionID);
@@ -223,6 +215,13 @@ export function createSessionReads(context: Plugin.Context) {
223
215
  return status === undefined ? undefined : false;
224
216
  };
225
217
 
218
+ // Accumulated active wall time: the clock runs only while `busy()` says the
219
+ // session, its family, or its shells is working, and freezes otherwise. The
220
+ // `now` parameter keeps the transition observation deterministic for tests.
221
+ const activeElapsed = createActiveElapsed(busy, { maxBankedMs });
222
+ const sessionElapsed = (sessionID: string, now: number = Date.now()): number | undefined =>
223
+ activeElapsed(sessionID, now);
224
+
226
225
  return {
227
226
  messagesOf,
228
227
  isFamilyRoot,