oc-flight-deck 0.6.2 → 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.
@@ -0,0 +1,98 @@
1
+ // Accumulated active time for one session, measured rather than assumed.
2
+ //
3
+ // Wall-clock since `time.created` reports a session left open overnight as a
4
+ // night's work. This clock only advances while the session — or something in
5
+ // its family, or one of its shells — is actually running, and it freezes the
6
+ // instant everything settles. `busy()` decides that, so the `elapsed` and
7
+ // `status` rows can never disagree about whether work is happening.
8
+ //
9
+ // One session is watched at a time. Reading a different session means the gap
10
+ // on the previous one happened off-watch, so its next read rebaselines and
11
+ // banks nothing. A window is billed only when the session was busy at both
12
+ // ends and the window was observed within the bound — so no single unobserved
13
+ // gap is ever billed beyond the optional `maxBankedMs`, and a longer gap banks
14
+ // nothing at all.
15
+ //
16
+ // State is a per-session accumulator held in this process and keyed by the
17
+ // displayed session, so an unrelated project's session can never contribute.
18
+ // That also means the figure begins at zero when the TUI starts: it measures
19
+ // activity observed this process, not activity the host recorded. A session
20
+ // that is idle when first seen stays at zero, and an unknown busy state
21
+ // (`undefined`) freezes rather than inventing motion.
22
+
23
+ /** How the caller answers "is this session working right now?". */
24
+ export type BusyRead = (sessionID: string) => boolean | undefined;
25
+
26
+ export interface ActiveElapsedOptions {
27
+ /**
28
+ * Longest window that may be banked as work. A longer one was not observed
29
+ * — a suspended process, sparse host events — so it banks nothing.
30
+ *
31
+ * Defaults to 60_000 so the module's own contract holds even when the
32
+ * caller supplies no bound. A production caller still passes its own
33
+ * derived bound.
34
+ */
35
+ readonly maxBankedMs?: number;
36
+ }
37
+
38
+ /** One session's running tally and the last instant it was observed. */
39
+ interface ActiveState {
40
+ accumulated: number;
41
+ lastAt: number;
42
+ running: boolean;
43
+ }
44
+
45
+ /**
46
+ * Build the active clock. One session is watched at a time. A read banks the
47
+ * time since the previous read only when the session was running at BOTH ends
48
+ * of that window — so overlapping activities record one wall-clock window, not
49
+ * one per activity, and a window in which the session settled is treated as
50
+ * idle rather than billed. Reads while the tally is zero return `undefined`,
51
+ * matching the row's own "nothing to show yet" behaviour.
52
+ *
53
+ * The observation boundary is unconditional: a read of a different session than
54
+ * the one before it rebaselines and banks nothing, because the gap happened
55
+ * off-watch. The optional `maxBankedMs` is an independent cap on top of that —
56
+ * any window longer than it was unobserved and banks nothing — not a switch for
57
+ * the boundary. Undercount is acceptable, over-count is not.
58
+ */
59
+ export function createActiveElapsed(isBusy: BusyRead, options: ActiveElapsedOptions = {}) {
60
+ const states = new Map<string, ActiveState>();
61
+ // The module's own contract must hold without the caller opting in; the
62
+ // production caller still passes its own derived bound.
63
+ const maxBankedMs = options.maxBankedMs ?? 60_000;
64
+ let lastRead: string | undefined;
65
+
66
+ return function activeElapsedMs(sessionID: string, now: number): number | undefined {
67
+ if (!Number.isFinite(now)) return undefined;
68
+
69
+ // A throwing or unknown read means "not known to be busy", which freezes.
70
+ let busy = false;
71
+ try {
72
+ busy = isBusy(sessionID) === true;
73
+ } catch {
74
+ busy = false;
75
+ }
76
+
77
+ // Observation boundary: a different session on screen means this one's
78
+ // gap since the last read happened off-watch, so take a fresh baseline.
79
+ const boundary = lastRead !== undefined && lastRead !== sessionID;
80
+ lastRead = sessionID;
81
+
82
+ let state = states.get(sessionID);
83
+ if (state === undefined) {
84
+ state = { accumulated: 0, lastAt: now, running: false };
85
+ states.set(sessionID, state);
86
+ } else if (!boundary && state.running && busy) {
87
+ // Only a window that was busy at BOTH ends and short enough to have been
88
+ // observed is work. A settled gap is idle; a stalled or stepped-back
89
+ // clock must never subtract; an over-long window was not watched.
90
+ const delta = now - state.lastAt;
91
+ if (delta > 0 && delta <= maxBankedMs) state.accumulated += delta;
92
+ }
93
+
94
+ state.running = busy;
95
+ state.lastAt = now;
96
+ return state.accumulated <= 0 ? undefined : state.accumulated;
97
+ };
98
+ }
@@ -30,9 +30,9 @@
30
30
  // caution light that cries wolf is worse than no caution light.
31
31
 
32
32
  /** Flight Deck's rail has one line for this, so only the worst is ever drawn. */
33
- export type CautionSeverity = "watch" | "caution";
33
+ type CautionSeverity = "watch" | "caution";
34
34
 
35
- export type CautionKind = "hung-tool" | "hung-shell" | "repeat-loop" | "failure-loop" | "silent-turn";
35
+ type CautionKind = "hung-tool" | "hung-shell" | "repeat-loop" | "failure-loop" | "silent-turn";
36
36
 
37
37
  export interface CautionThresholds {
38
38
  readonly toolWatchMs: number;
@@ -56,7 +56,7 @@ export interface Caution {
56
56
  readonly key: string;
57
57
  }
58
58
 
59
- export interface CautionInput {
59
+ interface CautionInput {
60
60
  /** The snapshot's tool parts, oldest first. */
61
61
  readonly parts: readonly unknown[];
62
62
  /** Running shells from `context.data.shell`, when the host exposes them. */
@@ -90,7 +90,7 @@ function asText(value: unknown): string | undefined {
90
90
  /** Statuses that mean a tool has stopped. Anything else counts as live. */
91
91
  const SETTLED_TOOL = new Set(["completed", "error", "aborted", "cancelled"]);
92
92
 
93
- export interface ToolCall {
93
+ interface ToolCall {
94
94
  readonly name: string;
95
95
  readonly status: string;
96
96
  /** Canonical form of the input, for comparing one call with the next. */
@@ -340,14 +340,14 @@ export function worstCaution(cautions: readonly Caution[]): Caution | undefined
340
340
 
341
341
  export const WATCH_GLYPH = "▲";
342
342
  export const CAUTION_GLYPH = "⚠";
343
- export const CLEAR_GLYPH = "○";
343
+ const CLEAR_GLYPH = "○";
344
344
 
345
345
  /**
346
346
  * Glyph overrides, for terminals that render the defaults badly.
347
347
  *
348
348
  * Structural, like `LayoutHint`, so this module stays free of imports.
349
349
  */
350
- export interface GlyphHint {
350
+ interface GlyphHint {
351
351
  readonly watch?: string;
352
352
  readonly caution?: string;
353
353
  readonly clear?: string;
@@ -406,13 +406,13 @@ export function cautionDetail(caution: Caution): string {
406
406
  }
407
407
  }
408
408
 
409
- /** `45s`, `14m`, `2h 14m`. */
409
+ /** `45s`, `14m07s`, `2h14m37s`. Seconds always show, so the text ticks every second. */
410
410
  export function formatElapsed(ms: number): string {
411
- const seconds = Math.max(0, Math.floor(ms / 1_000));
412
- if (seconds < 60) return `${seconds}s`;
413
- const minutes = Math.floor(seconds / 60);
414
- if (minutes < 60) return `${minutes}m`;
415
- const hours = Math.floor(minutes / 60);
416
- const rest = minutes % 60;
417
- return rest === 0 ? `${hours}h` : `${hours}h ${rest}m`;
411
+ const total = Math.max(0, Math.floor(ms / 1_000));
412
+ const seconds = total % 60;
413
+ const minutes = Math.floor(total / 60) % 60;
414
+ const hours = Math.floor(total / 3_600);
415
+ const ss = String(seconds).padStart(2, "0");
416
+ if (hours > 0) return `${hours}h${String(minutes).padStart(2, "0")}m${ss}s`;
417
+ return minutes > 0 ? `${minutes}m${ss}s` : `${seconds}s`;
418
418
  }
@@ -0,0 +1,25 @@
1
+ // Coercion guards for untrusted host values.
2
+ //
3
+ // Everything the host hands the rail — session records, message lists, model
4
+ // catalog entries — is `unknown` and read defensively. These four guards are
5
+ // the only place the plugin turns a raw value into something the rail can use;
6
+ // every other module coerces through them rather than re-checking shapes.
7
+ // `SessionLike` is the minimal session shape the reads understand.
8
+
9
+ export type SessionLike = { cost?: unknown; model?: unknown; time?: unknown; tokens?: unknown };
10
+
11
+ export function asCount(value: unknown): number | undefined {
12
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
13
+ }
14
+
15
+ export function asText(value: unknown): string | undefined {
16
+ if (typeof value !== "string") return undefined;
17
+ const text = value.trim();
18
+ return text.length === 0 ? undefined : text;
19
+ }
20
+
21
+ export function asRecord(value: unknown): Record<string, unknown> | undefined {
22
+ return typeof value === "object" && value !== null && !Array.isArray(value)
23
+ ? (value as Record<string, unknown>)
24
+ : undefined;
25
+ }
package/src/tui/config.ts CHANGED
@@ -10,8 +10,18 @@
10
10
 
11
11
  import { DEFAULT_PLACEHOLDER, isStatField, STAT_FIELDS } from "./stats.js";
12
12
  import type { CautionThresholds } from "./caution.js";
13
-
14
- export interface SidebarConfig {
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";
23
+
24
+ interface SidebarConfig {
15
25
  /** Show the sidebar rail. Default `true`. */
16
26
  readonly enabled: boolean;
17
27
  /** Fixed lines rendered above the live rows. Default `DEFAULT_SIDEBAR_LINES`. */
@@ -25,9 +35,15 @@ export 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
- export interface FooterConfig {
46
+ interface FooterConfig {
31
47
  /**
32
48
  * Show the prompt-footer rail. Default `false`.
33
49
  *
@@ -40,7 +56,7 @@ export interface FooterConfig {
40
56
  readonly text: string;
41
57
  }
42
58
 
43
- export interface CautionConfig {
59
+ interface CautionConfig {
44
60
  /** Show the caution annunciator. Default `true`. */
45
61
  readonly enabled: boolean;
46
62
  /** A tool running longer than this is worth noting. Default `180`. */
@@ -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
  *
@@ -108,7 +131,7 @@ export function cautionThresholds(config: CautionConfig): CautionThresholds {
108
131
  }
109
132
 
110
133
  /** Pure cosmetics: the geometry of a row. */
111
- export interface LayoutConfig {
134
+ interface LayoutConfig {
112
135
  /** Width of the row label column. Default `10`. */
113
136
  readonly labelWidth: number;
114
137
  /** Cells in the context gauge. Default `10`. */
@@ -124,25 +147,42 @@ export interface LayoutConfig {
124
147
  * some terminals render `⚠` as a box or the wrong width. Swapping it for `!` is
125
148
  * a worse-looking but working panel, which beats an unreadable one.
126
149
  */
127
- export interface GlyphConfig {
150
+ interface GlyphConfig {
128
151
  readonly watch: string;
129
152
  readonly caution: string;
130
153
  readonly clear: string;
131
154
  }
132
155
 
133
- export const DEFAULT_LAYOUT: LayoutConfig = {
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
+
171
+ const DEFAULT_LAYOUT: LayoutConfig = {
134
172
  labelWidth: 10,
135
173
  barWidth: 10,
136
174
  sparkWidth: 12,
137
175
  };
138
176
 
139
- export const DEFAULT_GLYPHS: GlyphConfig = {
177
+ const DEFAULT_FORMAT: FormatConfig = { duration: "spaced" };
178
+
179
+ const DEFAULT_GLYPHS: GlyphConfig = {
140
180
  watch: "▲",
141
181
  caution: "⚠",
142
182
  clear: "○",
143
183
  };
144
184
 
145
- export const DEFAULT_CAUTION: CautionConfig = {
185
+ const DEFAULT_CAUTION: CautionConfig = {
146
186
  enabled: true,
147
187
  toolWatchSeconds: 180,
148
188
  toolCautionSeconds: 420,
@@ -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
@@ -244,7 +295,7 @@ function normalizeText(value: string, path: string, issues: string[]): string {
244
295
  return value.replace(CONTROL_CHARS, " ").replace(/ {2,}/g, " ").trim();
245
296
  }
246
297
 
247
- export interface ConfigResolution {
298
+ interface ConfigResolution {
248
299
  readonly config: FlightDeckConfig;
249
300
  /** Human-readable problems found in the supplied options; empty when clean. */
250
301
  readonly issues: readonly string[];
@@ -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,
@@ -48,7 +48,7 @@ export interface FileConfig {
48
48
  * Find the first config file that exists in `directory`, which defaults to the
49
49
  * global config directory. A missing directory simply has no candidates.
50
50
  */
51
- export function findConfigFile(directory: string = globalConfigDirectory()): string | undefined {
51
+ function findConfigFile(directory: string = globalConfigDirectory()): string | undefined {
52
52
  for (const candidate of CONFIG_FILE_CANDIDATES) {
53
53
  const path = join(directory, candidate);
54
54
  if (existsSync(path)) return path;