oc-flight-deck 0.12.0 → 0.19.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/CHANGELOG.md +70 -0
- package/LICENSE +1 -1
- package/README.md +63 -173
- package/dist/index.js +10 -0
- package/dist/tui/index.js +3814 -0
- package/flight-deck.example.jsonc +114 -38
- package/flight-deck.schema.json +122 -10
- package/package.json +11 -9
- package/src/tui/clipboard.ts +44 -15
- package/src/tui/config.ts +358 -22
- package/src/tui/file-config.ts +4 -1
- package/src/tui/format.ts +1 -1
- package/src/tui/go-look.ts +118 -0
- package/src/tui/go-panel.ts +637 -0
- package/src/tui/go-usage.ts +8 -1
- package/src/tui/go.ts +663 -27
- package/src/tui/guard.ts +15 -7
- package/src/tui/host-clipboard.ts +21 -4
- package/src/tui/index.tsx +96 -24
- package/src/tui/rows.ts +71 -24
- package/src/tui/session-elapsed.ts +122 -0
- package/src/tui/session-reads.ts +97 -65
- package/src/tui/session-tps.ts +145 -105
- package/src/tui/stat-fields.ts +99 -5
- package/src/tui/stats.ts +8 -9
- package/src/tui/style.ts +24 -5
- package/src/tui/throughput.ts +38 -137
- package/src/tui/active-elapsed.ts +0 -141
package/src/tui/config.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// Everything is optional. Missing or invalid values fall back to the sane
|
|
9
9
|
// defaults below, so the rail always renders and a typo can never break the TUI.
|
|
10
10
|
|
|
11
|
-
import { DEFAULT_PLACEHOLDER, isStatField, STAT_FIELDS } from "./stats.js";
|
|
11
|
+
import { DEFAULT_PLACEHOLDER, canonicalField, isStatField, STAT_FIELDS } from "./stats.js";
|
|
12
12
|
import type { CautionThresholds } from "./caution.js";
|
|
13
13
|
import type { DurationStyle } from "./format.js";
|
|
14
14
|
import {
|
|
@@ -33,6 +33,8 @@ interface SidebarConfig {
|
|
|
33
33
|
readonly footer: SidebarFooterConfig;
|
|
34
34
|
/** Live session fields to render, top to bottom. Default `DEFAULT_SIDEBAR_ROWS`. */
|
|
35
35
|
readonly rows: readonly string[];
|
|
36
|
+
/** Which sessions the `tps` row paces. Default `{ scope: DEFAULT_TPS_SCOPE }`. */
|
|
37
|
+
readonly tps: TpsConfig;
|
|
36
38
|
/**
|
|
37
39
|
* Render every named row even when the host has no data for it, using
|
|
38
40
|
* `placeholder` as the value. Default `true`; `false` restores omission.
|
|
@@ -48,16 +50,128 @@ interface SidebarConfig {
|
|
|
48
50
|
readonly maxLines: number;
|
|
49
51
|
}
|
|
50
52
|
|
|
53
|
+
/**
|
|
54
|
+
* The live Go panel's look, when `sidebar.footer.go` is an object.
|
|
55
|
+
*
|
|
56
|
+
* An object enables the panel exactly like `true`, with these knobs replacing
|
|
57
|
+
* the defaults. Absent keys fall back to the defaults below; a malformed value
|
|
58
|
+
* is reported and ignored, never a crash.
|
|
59
|
+
*/
|
|
60
|
+
export interface GoPanelLook {
|
|
61
|
+
/** Draw the dim `◈ OPENCODE GO` header above the three meters. Default `false`. */
|
|
62
|
+
readonly header: boolean;
|
|
63
|
+
/** Cells in the panel meter. Default `10`. */
|
|
64
|
+
readonly barWidth: number;
|
|
65
|
+
/**
|
|
66
|
+
* Minimum width of the panel label column. Default `6`.
|
|
67
|
+
*
|
|
68
|
+
* A minimum, not a fixed width: the panel auto-widens past it to hold the
|
|
69
|
+
* longest rendered rename, so a rename can never overflow or wrap.
|
|
70
|
+
*/
|
|
71
|
+
readonly labelWidth: number;
|
|
72
|
+
/** Draw the right-aligned percent column. Default `true`. */
|
|
73
|
+
readonly percent: boolean;
|
|
74
|
+
/** Draw the right-aligned reset countdown column. Default `true`. */
|
|
75
|
+
readonly reset: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Where a value sits inside its own fixed-width trailing cell.
|
|
78
|
+
* Default `"right"`.
|
|
79
|
+
*
|
|
80
|
+
* The percent (4) and reset (6) cell widths stay fixed; this moves the
|
|
81
|
+
* value within them. `"right"` pins the value to the cell's right edge, so
|
|
82
|
+
* the digits stay put as values change length; `"left"` hugs the bar and
|
|
83
|
+
* `"center"` splits the padding. Both trailing cells use the same setting.
|
|
84
|
+
*/
|
|
85
|
+
readonly align: "left" | "right" | "center";
|
|
86
|
+
/**
|
|
87
|
+
* Let a bright cell sweep the fill while the ticker runs. Default `false`:
|
|
88
|
+
* the bar is static and changes only when the percentage itself changes.
|
|
89
|
+
*/
|
|
90
|
+
readonly sweep: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* The three meter labels by window: `rolling` (5h), `weekly` (1w),
|
|
93
|
+
* `monthly` (1m). Default the lowercase wire names.
|
|
94
|
+
*/
|
|
95
|
+
readonly labels: {
|
|
96
|
+
readonly rolling: string;
|
|
97
|
+
readonly weekly: string;
|
|
98
|
+
readonly monthly: string;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Draw the slow breathing mark at the start of the first meter line.
|
|
102
|
+
* Default `true`: only the mark breathes, the meter stays static.
|
|
103
|
+
*/
|
|
104
|
+
readonly blink: boolean;
|
|
105
|
+
/** Milliseconds per breath step. Default `700`, honoured from 200 to 5000. */
|
|
106
|
+
readonly blinkMs: number;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The panel look `true` enables: no header, static meter, both columns on. */
|
|
110
|
+
export const DEFAULT_GO_PANEL_LOOK: GoPanelLook = {
|
|
111
|
+
header: false,
|
|
112
|
+
barWidth: 10,
|
|
113
|
+
labelWidth: 6,
|
|
114
|
+
percent: true,
|
|
115
|
+
reset: true,
|
|
116
|
+
align: "right",
|
|
117
|
+
sweep: false,
|
|
118
|
+
labels: { rolling: "rolling", weekly: "weekly", monthly: "monthly" },
|
|
119
|
+
blink: true,
|
|
120
|
+
blinkMs: 700,
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Which sessions the `tps` row paces.
|
|
125
|
+
*
|
|
126
|
+
* `"family"` sums generation tokens across the displayed session and its
|
|
127
|
+
* subagent sessions, over the union of all their streaming spans.
|
|
128
|
+
* `"session"` paces the displayed session alone: its own tokens over its own
|
|
129
|
+
* spans.
|
|
130
|
+
*/
|
|
131
|
+
export type TpsScope = "family" | "session";
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The shipped `tps` scope: `"family"`.
|
|
135
|
+
*
|
|
136
|
+
* The one default for this knob, so flipping the shipped behaviour is one
|
|
137
|
+
* line here. Family ships because the visible work in a delegation-heavy
|
|
138
|
+
* session happens in its subagents: a root that has gone idle while its child
|
|
139
|
+
* is still decoding must still read live, the way `cost` already rolls the
|
|
140
|
+
* tree up. Set it to `"session"` for the previous per-session figure.
|
|
141
|
+
*/
|
|
142
|
+
export const DEFAULT_TPS_SCOPE: TpsScope = "family";
|
|
143
|
+
|
|
144
|
+
interface TpsConfig {
|
|
145
|
+
/** Which sessions the `tps` row paces. Default `DEFAULT_TPS_SCOPE`. */
|
|
146
|
+
readonly scope: TpsScope;
|
|
147
|
+
}
|
|
148
|
+
|
|
51
149
|
interface SidebarFooterConfig {
|
|
52
150
|
/**
|
|
53
151
|
* The footer's fixed lines. Empty by default since 0.8.1.
|
|
54
152
|
*
|
|
55
|
-
* An explicitly empty list
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
153
|
+
* An explicitly empty list removes the fixed lines; `go` can still claim the
|
|
154
|
+
* slot on its own. Set the documented two-line `▸ FLIGHT DECK` branding pair
|
|
155
|
+
* back here to re-enable it. The two lists are independent, and the footer
|
|
156
|
+
* draws outside the rail's `maxLines` budget.
|
|
59
157
|
*/
|
|
60
158
|
readonly lines: readonly string[];
|
|
159
|
+
/**
|
|
160
|
+
* The live Go usage panel: three fixed-width lines - rolling (5h),
|
|
161
|
+
* weekly (1w), monthly (1m) - each with a bar, a right-aligned percent, and
|
|
162
|
+
* a right-aligned reset countdown. Off by default.
|
|
163
|
+
*
|
|
164
|
+
* `true` enables it with the default look (no header, static meter, both
|
|
165
|
+
* columns); an object enables it with a custom look (`header`, `barWidth`,
|
|
166
|
+
* `labelWidth`, `percent`, `reset`, `align`, `sweep`, `labels`, `blink`, `blinkMs`,
|
|
167
|
+
* each falling back to its default). Independent of `lines`, and it claims
|
|
168
|
+
* the footer slot on its own so the panel can sit under the rail with no
|
|
169
|
+
* fixed text. Turning it on starts the same account-wide poll the `go` row
|
|
170
|
+
* uses (one key, one quota), reads the active `opencode-go` credential from
|
|
171
|
+
* OpenCode's own credential store, and draws a resting placeholder until the
|
|
172
|
+
* first poll lands - never a blank slot.
|
|
173
|
+
*/
|
|
174
|
+
readonly go: boolean | GoPanelLook;
|
|
61
175
|
}
|
|
62
176
|
|
|
63
177
|
interface FooterConfig {
|
|
@@ -114,7 +228,7 @@ export interface FlightDeckConfig {
|
|
|
114
228
|
* it is opt-in, so an install that never asks for it spends no timer on it.
|
|
115
229
|
*/
|
|
116
230
|
readonly caution: CautionConfig;
|
|
117
|
-
/** Geometry of a row. Every value has a sane default. */
|
|
231
|
+
/** Geometry and wording of a row. Every value has a sane default. */
|
|
118
232
|
readonly layout: LayoutConfig;
|
|
119
233
|
/** How values are written on the rail, e.g. the `elapsed` duration style. */
|
|
120
234
|
readonly format: FormatConfig;
|
|
@@ -148,7 +262,7 @@ export function cautionThresholds(config: CautionConfig): CautionThresholds {
|
|
|
148
262
|
};
|
|
149
263
|
}
|
|
150
264
|
|
|
151
|
-
/** Pure cosmetics: the geometry of a row. */
|
|
265
|
+
/** Pure cosmetics: the geometry and wording of a row. */
|
|
152
266
|
interface LayoutConfig {
|
|
153
267
|
/** Width of the row label column. Default `10`. */
|
|
154
268
|
readonly labelWidth: number;
|
|
@@ -156,6 +270,18 @@ interface LayoutConfig {
|
|
|
156
270
|
readonly barWidth: number;
|
|
157
271
|
/** Samples drawn in the sparkline. Default `12`. */
|
|
158
272
|
readonly sparkWidth: number;
|
|
273
|
+
/**
|
|
274
|
+
* Rename any rail row, keyed by the canonical row name (`ses`, not the
|
|
275
|
+
* `session` alias).
|
|
276
|
+
*
|
|
277
|
+
* `{ "cost": "session", "total": "lifetime" }` draws those two rows under the
|
|
278
|
+
* new labels; every row left out keeps its built-in label, so an absent key
|
|
279
|
+
* changes nothing and the shipped rail is byte-identical without this key.
|
|
280
|
+
* The label is only ever the label column — a row's value, and which figure it
|
|
281
|
+
* carries, is unchanged. An unknown row name, a non-string value, or an empty
|
|
282
|
+
* label is reported by path and that row falls back to the default label.
|
|
283
|
+
*/
|
|
284
|
+
readonly labels?: Readonly<Record<string, string>>;
|
|
159
285
|
}
|
|
160
286
|
|
|
161
287
|
/**
|
|
@@ -234,11 +360,11 @@ export const DEFAULT_SIDEBAR_LINES: readonly string[] = [];
|
|
|
234
360
|
* The sidebar footer's default fixed lines.
|
|
235
361
|
*
|
|
236
362
|
* Empty since 0.8.1: a fresh install renders no footer text at all, so the
|
|
237
|
-
* rail is the live rows and nothing else. The `▸ FLIGHT DECK`
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
363
|
+
* rail is the live rows and nothing else. The `▸ FLIGHT DECK` pair is a
|
|
364
|
+
* documented opt-in - set `sidebar.footer.lines` to the pair to re-enable it
|
|
365
|
+
* (see the README's Configure section). An explicitly empty
|
|
366
|
+
* `sidebar.footer.lines` from a config file removes the slot's fixed lines;
|
|
367
|
+
* `sidebar.footer.go` can still claim the slot on its own.
|
|
242
368
|
*/
|
|
243
369
|
export const DEFAULT_SIDEBAR_FOOTER_LINES: readonly string[] = [];
|
|
244
370
|
|
|
@@ -298,8 +424,9 @@ export const DEFAULT_CONFIG: FlightDeckConfig = {
|
|
|
298
424
|
sidebar: {
|
|
299
425
|
enabled: true,
|
|
300
426
|
lines: DEFAULT_SIDEBAR_LINES,
|
|
301
|
-
footer: { lines: DEFAULT_SIDEBAR_FOOTER_LINES },
|
|
427
|
+
footer: { lines: DEFAULT_SIDEBAR_FOOTER_LINES, go: false },
|
|
302
428
|
rows: DEFAULT_SIDEBAR_ROWS,
|
|
429
|
+
tps: { scope: DEFAULT_TPS_SCOPE },
|
|
303
430
|
persist: true,
|
|
304
431
|
placeholder: DEFAULT_PLACEHOLDER,
|
|
305
432
|
maxLines: MAX_LINES,
|
|
@@ -420,22 +547,128 @@ function readLines(value: unknown, issues: string[], maxLines: number): readonly
|
|
|
420
547
|
}
|
|
421
548
|
|
|
422
549
|
/**
|
|
423
|
-
* The sidebar footer's fixed lines
|
|
550
|
+
* The sidebar footer's fixed lines - empty by default since 0.8.1.
|
|
424
551
|
*
|
|
425
552
|
* Unlike the top rail, an explicitly empty list is meaningful: it removes the
|
|
426
|
-
* footer
|
|
427
|
-
* the
|
|
428
|
-
*
|
|
553
|
+
* footer's fixed lines (the live Go panel, `sidebar.footer.go`, can still claim
|
|
554
|
+
* the slot). A non-empty list with no usable entries falls back to the (empty)
|
|
555
|
+
* default, reported like every other bad value, and a runaway footer is capped
|
|
556
|
+
* at `MAX_LINES` the way the top rail is.
|
|
429
557
|
*/
|
|
430
558
|
function readSidebarFooterLines(value: unknown, issues: string[]): readonly string[] {
|
|
431
559
|
return readLineList(value, issues, MAX_LINES, DEFAULT_SIDEBAR_FOOTER_LINES, "sidebar.footer.lines");
|
|
432
560
|
}
|
|
433
561
|
|
|
562
|
+
/**
|
|
563
|
+
* The sidebar footer Go panel: `true`/`false` or a look object.
|
|
564
|
+
*
|
|
565
|
+
* A boolean keeps working exactly as before (`true` enables with the default
|
|
566
|
+
* look). An object enables with a custom look: absent keys fall back to
|
|
567
|
+
* {@link DEFAULT_GO_PANEL_LOOK}, a malformed value is reported and ignored,
|
|
568
|
+
* and unknown keys are ignored forward-compatibly. Anything else falls back
|
|
569
|
+
* to `false`, loudly, like every other bad option. Never throws.
|
|
570
|
+
*/
|
|
571
|
+
/** Longest rename the panel honours per label; longer would eat the sidebar. */
|
|
572
|
+
const GO_LABEL_MAX_LENGTH = 24;
|
|
573
|
+
|
|
574
|
+
/** One rename: a non-empty string within the sidebar's label budget. */
|
|
575
|
+
function readGoLabel(value: unknown, fallback: string, path: string, issues: string[]): string {
|
|
576
|
+
if (value === undefined) return fallback;
|
|
577
|
+
if (typeof value !== "string") {
|
|
578
|
+
issues.push(`${path} must be a string; using the default`);
|
|
579
|
+
return fallback;
|
|
580
|
+
}
|
|
581
|
+
const text = value.trim();
|
|
582
|
+
if (text.length === 0) {
|
|
583
|
+
issues.push(`${path} must not be empty; using the default`);
|
|
584
|
+
return fallback;
|
|
585
|
+
}
|
|
586
|
+
if (text.length > GO_LABEL_MAX_LENGTH) {
|
|
587
|
+
issues.push(`${path} was longer than ${GO_LABEL_MAX_LENGTH} characters; using the default`);
|
|
588
|
+
return fallback;
|
|
589
|
+
}
|
|
590
|
+
return text;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/** The three renames: each key optional, each falling back per-key. */
|
|
594
|
+
function readGoLabels(value: unknown, issues: string[]): GoPanelLook["labels"] {
|
|
595
|
+
if (value === undefined) return DEFAULT_GO_PANEL_LOOK.labels;
|
|
596
|
+
if (!isRecord(value)) {
|
|
597
|
+
issues.push("sidebar.footer.go.labels must be an object; using the defaults");
|
|
598
|
+
return DEFAULT_GO_PANEL_LOOK.labels;
|
|
599
|
+
}
|
|
600
|
+
return {
|
|
601
|
+
rolling: readGoLabel(value["rolling"], DEFAULT_GO_PANEL_LOOK.labels.rolling, "sidebar.footer.go.labels.rolling", issues),
|
|
602
|
+
weekly: readGoLabel(value["weekly"], DEFAULT_GO_PANEL_LOOK.labels.weekly, "sidebar.footer.go.labels.weekly", issues),
|
|
603
|
+
monthly: readGoLabel(value["monthly"], DEFAULT_GO_PANEL_LOOK.labels.monthly, "sidebar.footer.go.labels.monthly", issues),
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Where a trailing value sits inside its fixed-width cell.
|
|
609
|
+
*
|
|
610
|
+
* Only the three exact strings count: anything else present is malformed, so
|
|
611
|
+
* the default comes back loudly. An absent key falls back silently, like
|
|
612
|
+
* every other optional knob.
|
|
613
|
+
*/
|
|
614
|
+
function readGoAlign(value: unknown, issues: string[]): GoPanelLook["align"] {
|
|
615
|
+
if (value === undefined) return DEFAULT_GO_PANEL_LOOK.align;
|
|
616
|
+
if (value === "left" || value === "right" || value === "center") return value;
|
|
617
|
+
issues.push('sidebar.footer.go.align must be "left", "right" or "center"; using "right"');
|
|
618
|
+
return DEFAULT_GO_PANEL_LOOK.align;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
function readFooterGo(value: unknown, issues: string[]): boolean | GoPanelLook {
|
|
622
|
+
if (value === undefined) return DEFAULT_CONFIG.sidebar.footer.go;
|
|
623
|
+
if (typeof value === "boolean") return value;
|
|
624
|
+
if (!isRecord(value)) {
|
|
625
|
+
issues.push("sidebar.footer.go must be true, false or an object; using false");
|
|
626
|
+
return false;
|
|
627
|
+
}
|
|
628
|
+
return {
|
|
629
|
+
header: readBoolean(value["header"], DEFAULT_GO_PANEL_LOOK.header, "sidebar.footer.go.header", issues),
|
|
630
|
+
barWidth: readNumber(
|
|
631
|
+
value["barWidth"],
|
|
632
|
+
DEFAULT_GO_PANEL_LOOK.barWidth,
|
|
633
|
+
"sidebar.footer.go.barWidth",
|
|
634
|
+
issues,
|
|
635
|
+
1,
|
|
636
|
+
40,
|
|
637
|
+
),
|
|
638
|
+
labelWidth: readNumber(
|
|
639
|
+
value["labelWidth"],
|
|
640
|
+
DEFAULT_GO_PANEL_LOOK.labelWidth,
|
|
641
|
+
"sidebar.footer.go.labelWidth",
|
|
642
|
+
issues,
|
|
643
|
+
5,
|
|
644
|
+
24,
|
|
645
|
+
),
|
|
646
|
+
percent: readBoolean(value["percent"], DEFAULT_GO_PANEL_LOOK.percent, "sidebar.footer.go.percent", issues),
|
|
647
|
+
reset: readBoolean(value["reset"], DEFAULT_GO_PANEL_LOOK.reset, "sidebar.footer.go.reset", issues),
|
|
648
|
+
align: readGoAlign(value["align"], issues),
|
|
649
|
+
sweep: readBoolean(value["sweep"], DEFAULT_GO_PANEL_LOOK.sweep, "sidebar.footer.go.sweep", issues),
|
|
650
|
+
labels: readGoLabels(value["labels"], issues),
|
|
651
|
+
blink: readBoolean(value["blink"], DEFAULT_GO_PANEL_LOOK.blink, "sidebar.footer.go.blink", issues),
|
|
652
|
+
blinkMs: readNumber(
|
|
653
|
+
value["blinkMs"],
|
|
654
|
+
DEFAULT_GO_PANEL_LOOK.blinkMs,
|
|
655
|
+
"sidebar.footer.go.blinkMs",
|
|
656
|
+
issues,
|
|
657
|
+
200,
|
|
658
|
+
5000,
|
|
659
|
+
),
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
|
|
434
663
|
/**
|
|
435
664
|
* Read the list of live fields to render.
|
|
436
665
|
*
|
|
437
666
|
* An unknown name is reported rather than silently dropped: otherwise a typo in
|
|
438
667
|
* `sidebar.rows` looks identical to the host simply not having the data yet.
|
|
668
|
+
* The `session` alias folds back to its canonical key `ses` silently, so the
|
|
669
|
+
* list never carries two spellings of one row and every downstream consumer
|
|
670
|
+
* (the `wants()` set, `railLines`' `field`, the `ses` click-copy and wrap mode)
|
|
671
|
+
* keeps working unchanged.
|
|
439
672
|
*/
|
|
440
673
|
function readRows(value: unknown, issues: string[], maxLines: number): readonly string[] {
|
|
441
674
|
if (value === undefined) return DEFAULT_SIDEBAR_ROWS;
|
|
@@ -462,7 +695,7 @@ function readRows(value: unknown, issues: string[], maxLines: number): readonly
|
|
|
462
695
|
issues.push(`${path} is not a known field (${STAT_FIELDS.join(", ")}); skipping it`);
|
|
463
696
|
return;
|
|
464
697
|
}
|
|
465
|
-
rows.push(name);
|
|
698
|
+
rows.push(canonicalField(name));
|
|
466
699
|
});
|
|
467
700
|
|
|
468
701
|
if (rows.length === 0) {
|
|
@@ -472,6 +705,37 @@ function readRows(value: unknown, issues: string[], maxLines: number): readonly
|
|
|
472
705
|
return rows.slice(0, maxLines);
|
|
473
706
|
}
|
|
474
707
|
|
|
708
|
+
/**
|
|
709
|
+
* The `tps` row's scope, as one of a fixed pair of strings.
|
|
710
|
+
*
|
|
711
|
+
* Unlike a free-text value there is no sensible repair for a misspelled
|
|
712
|
+
* scope: the default comes back and the key is named, like every other
|
|
713
|
+
* invalid option. An absent key falls back silently.
|
|
714
|
+
*/
|
|
715
|
+
function readTpsScope(value: unknown, issues: string[]): TpsScope {
|
|
716
|
+
if (value === undefined) return DEFAULT_TPS_SCOPE;
|
|
717
|
+
if (value === "family" || value === "session") return value;
|
|
718
|
+
issues.push(`sidebar.tps.scope must be "family" or "session"; using "${DEFAULT_TPS_SCOPE}"`);
|
|
719
|
+
return DEFAULT_TPS_SCOPE;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Which sessions the `tps` row paces.
|
|
724
|
+
*
|
|
725
|
+
* A malformed section falls back whole and is reported, like
|
|
726
|
+
* `sidebar.footer`: a string where an object belongs must not silently
|
|
727
|
+
* become a scope.
|
|
728
|
+
*/
|
|
729
|
+
function readTps(section: Record<string, unknown>, issues: string[]): TpsConfig {
|
|
730
|
+
const raw = section["tps"];
|
|
731
|
+
if (raw !== undefined && !isRecord(raw)) {
|
|
732
|
+
issues.push("sidebar.tps must be an object; using defaults");
|
|
733
|
+
return { scope: DEFAULT_TPS_SCOPE };
|
|
734
|
+
}
|
|
735
|
+
const tps = isRecord(raw) ? raw : {};
|
|
736
|
+
return { scope: readTpsScope(tps["scope"], issues) };
|
|
737
|
+
}
|
|
738
|
+
|
|
475
739
|
/**
|
|
476
740
|
* The cap on the whole rail, as a whole number of lines.
|
|
477
741
|
*
|
|
@@ -526,7 +790,26 @@ function mergeSection(
|
|
|
526
790
|
// silently preferring the valid side.
|
|
527
791
|
if (hostValue !== undefined && !isRecord(hostValue)) return hostValue;
|
|
528
792
|
if (fileValue !== undefined && !isRecord(fileValue) && hostValue === undefined) return fileValue;
|
|
529
|
-
|
|
793
|
+
const merged: Record<string, unknown> = { ...sectionOf(file, key), ...sectionOf(host, key) };
|
|
794
|
+
// A nested `sidebar.footer` / `sidebar.tps` object from the host replaces
|
|
795
|
+
// only the leaf keys it names: a host `{ footer: { lines } }` must not drop
|
|
796
|
+
// a file `{ footer: { go } }`, and vice versa. Either side malformed (or
|
|
797
|
+
// absent) keeps the shallow winner above so resolveConfig still reports it.
|
|
798
|
+
if (key === "sidebar") {
|
|
799
|
+
const fileSidebar = sectionOf(file, key);
|
|
800
|
+
const hostSidebar = sectionOf(host, key);
|
|
801
|
+
const fileFooter = fileSidebar["footer"];
|
|
802
|
+
const hostFooter = hostSidebar["footer"];
|
|
803
|
+
if (isRecord(fileFooter) && isRecord(hostFooter)) {
|
|
804
|
+
merged["footer"] = { ...fileFooter, ...hostFooter };
|
|
805
|
+
}
|
|
806
|
+
const fileTps = fileSidebar["tps"];
|
|
807
|
+
const hostTps = hostSidebar["tps"];
|
|
808
|
+
if (isRecord(fileTps) && isRecord(hostTps)) {
|
|
809
|
+
merged["tps"] = { ...fileTps, ...hostTps };
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
return merged;
|
|
530
813
|
}
|
|
531
814
|
|
|
532
815
|
/**
|
|
@@ -578,6 +861,48 @@ function readNumber(
|
|
|
578
861
|
return Math.floor(value);
|
|
579
862
|
}
|
|
580
863
|
|
|
864
|
+
/**
|
|
865
|
+
* The per-row label overrides: `layout.labels`.
|
|
866
|
+
*
|
|
867
|
+
* Keyed by the canonical row name, so `session` and `ses` both land on the
|
|
868
|
+
* `ses` row exactly as `sidebar.rows` folds them. Absent means "no renames" and
|
|
869
|
+
* returns `undefined` rather than an empty map, so nothing downstream has to
|
|
870
|
+
* tell "no overrides" apart from "an empty object of overrides". An unknown
|
|
871
|
+
* name, a non-string value, or an empty label is reported by path and dropped,
|
|
872
|
+
* which leaves that row on its default label.
|
|
873
|
+
*/
|
|
874
|
+
function readLabels(value: unknown, issues: string[]): Readonly<Record<string, string>> | undefined {
|
|
875
|
+
if (value === undefined) return undefined;
|
|
876
|
+
if (!isRecord(value)) {
|
|
877
|
+
issues.push("layout.labels must be an object of row names to labels; using the default labels");
|
|
878
|
+
return undefined;
|
|
879
|
+
}
|
|
880
|
+
const labels: Record<string, string> = {};
|
|
881
|
+
for (const [rawName, rawLabel] of Object.entries(value)) {
|
|
882
|
+
const path = `layout.labels.${rawName}`;
|
|
883
|
+
const key = normalizeText(rawName, path, issues).trim().toLowerCase();
|
|
884
|
+
if (key.length === 0) {
|
|
885
|
+
issues.push(`${path} is empty; using the default label`);
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
888
|
+
if (!isStatField(key)) {
|
|
889
|
+
issues.push(`${path} is not a known row (${STAT_FIELDS.join(", ")}); using the default label`);
|
|
890
|
+
continue;
|
|
891
|
+
}
|
|
892
|
+
if (typeof rawLabel !== "string") {
|
|
893
|
+
issues.push(`${path} must be a string; using the default label`);
|
|
894
|
+
continue;
|
|
895
|
+
}
|
|
896
|
+
const label = normalizeText(rawLabel, path, issues).trim();
|
|
897
|
+
if (label.length === 0) {
|
|
898
|
+
issues.push(`${path} must not be empty; using the default label`);
|
|
899
|
+
continue;
|
|
900
|
+
}
|
|
901
|
+
labels[canonicalField(key)] = label;
|
|
902
|
+
}
|
|
903
|
+
return Object.keys(labels).length === 0 ? undefined : labels;
|
|
904
|
+
}
|
|
905
|
+
|
|
581
906
|
function readLayout(section: Record<string, unknown>, issues: string[]): LayoutConfig {
|
|
582
907
|
return {
|
|
583
908
|
// The label column has to fit "caution" plus a space, and must not eat the
|
|
@@ -585,6 +910,7 @@ function readLayout(section: Record<string, unknown>, issues: string[]): LayoutC
|
|
|
585
910
|
labelWidth: readNumber(section["labelWidth"], DEFAULT_LAYOUT.labelWidth, "layout.labelWidth", issues, 6, 24),
|
|
586
911
|
barWidth: readNumber(section["barWidth"], DEFAULT_LAYOUT.barWidth, "layout.barWidth", issues, 1, 40),
|
|
587
912
|
sparkWidth: readNumber(section["sparkWidth"], DEFAULT_LAYOUT.sparkWidth, "layout.sparkWidth", issues, 2, 64),
|
|
913
|
+
labels: readLabels(section["labels"], issues),
|
|
588
914
|
};
|
|
589
915
|
}
|
|
590
916
|
|
|
@@ -707,7 +1033,8 @@ function readLineStyle(value: unknown, fallback: LineStyle, path: string, issues
|
|
|
707
1033
|
*
|
|
708
1034
|
* A per-row key must name a known field. That check is what keeps a typo
|
|
709
1035
|
* (`style.rows.costly`) from silently styling nothing: unknown names are
|
|
710
|
-
* reported and skipped, exactly like `sidebar.rows`.
|
|
1036
|
+
* reported and skipped, exactly like `sidebar.rows`. The `session` alias
|
|
1037
|
+
* folds back to `ses`, so `style.rows.session` styles the `ses` row.
|
|
711
1038
|
*/
|
|
712
1039
|
function readStyle(section: Record<string, unknown>, issues: string[]): StyleConfig {
|
|
713
1040
|
const rawRows = section["rows"];
|
|
@@ -734,7 +1061,7 @@ function readStyle(section: Record<string, unknown>, issues: string[]): StyleCon
|
|
|
734
1061
|
issues.push(`${path} is not a known field (${STAT_FIELDS.join(", ")}); skipping it`);
|
|
735
1062
|
continue;
|
|
736
1063
|
}
|
|
737
|
-
overrides[name] = readLineStyle(entry, wildcard, path, issues);
|
|
1064
|
+
overrides[canonicalField(name)] = readLineStyle(entry, wildcard, path, issues);
|
|
738
1065
|
}
|
|
739
1066
|
|
|
740
1067
|
return { lines, rows: { wildcard, overrides } };
|
|
@@ -896,8 +1223,17 @@ export function resolveConfig(options: unknown): ConfigResolution {
|
|
|
896
1223
|
sidebar: {
|
|
897
1224
|
enabled: readBoolean(sidebar.enabled, DEFAULT_CONFIG.sidebar.enabled, "sidebar.enabled", issues),
|
|
898
1225
|
lines,
|
|
899
|
-
footer: {
|
|
1226
|
+
footer: {
|
|
1227
|
+
lines: footerLines,
|
|
1228
|
+
// Independent of `lines`, and off by default like the other opt-in
|
|
1229
|
+
// machinery (`caution`, and the `go` row): the panel claims the slot
|
|
1230
|
+
// on its own, so `lines: []` no longer means "no footer at all".
|
|
1231
|
+
// `true` enables with the default look; an object enables with a
|
|
1232
|
+
// custom one.
|
|
1233
|
+
go: readFooterGo(sidebarFooter.go, issues),
|
|
1234
|
+
},
|
|
900
1235
|
rows,
|
|
1236
|
+
tps: readTps(sidebar, issues),
|
|
901
1237
|
persist: readBoolean(sidebar.persist, DEFAULT_CONFIG.sidebar.persist, "sidebar.persist", issues),
|
|
902
1238
|
placeholder: readText(
|
|
903
1239
|
sidebar.placeholder,
|
package/src/tui/file-config.ts
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
// The host's `context.options` is the official configuration channel, but not
|
|
4
4
|
// every host build forwards it (and `cli.json` may not allow comments). So the
|
|
5
5
|
// plugin also reads a small global JSONC file, which guarantees inline comments
|
|
6
|
-
// work everywhere. `context.options` still wins when present
|
|
6
|
+
// work everywhere. `context.options` still wins when present: it is the
|
|
7
|
+
// authoritative channel and takes precedence key by key at the `mergeOptions`
|
|
8
|
+
// site (`config.ts:821-834`). The file fallback also covers the documented
|
|
9
|
+
// bare-string install (`README.md:32-35`), which forwards no `options` at all.
|
|
7
10
|
//
|
|
8
11
|
// There is exactly one config file, in the user's config directory. There is no
|
|
9
12
|
// per-project channel: what the rail shows cannot change with the directory the
|
package/src/tui/format.ts
CHANGED
|
@@ -40,7 +40,7 @@ export type DurationStyle = "compact" | "spaced";
|
|
|
40
40
|
* `format.duration` (spaced).
|
|
41
41
|
*/
|
|
42
42
|
export function formatDuration(ms: number, style: DurationStyle = "compact"): string {
|
|
43
|
-
const total = Math.floor(ms / 1_000);
|
|
43
|
+
const total = Math.max(0, Math.floor(ms / 1_000));
|
|
44
44
|
const seconds = total % 60;
|
|
45
45
|
const minutes = Math.floor(total / 60) % 60;
|
|
46
46
|
const hours = Math.floor(total / 3_600);
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// The footer Go panel's live look.
|
|
2
|
+
//
|
|
3
|
+
// `sidebar.footer.go` used to be resolved once at setup, which froze the
|
|
4
|
+
// panel's look until the next client restart: editing `flight-deck.jsonc`
|
|
5
|
+
// never re-ran setup, so the running panel kept its old look. This reader
|
|
6
|
+
// re-resolves the look from the file at render time, without reading or
|
|
7
|
+
// parsing per frame: each render cheap-stats the file (mtime + size) and
|
|
8
|
+
// re-reads + re-parses only when either moved. The last good look is cached,
|
|
9
|
+
// so a missing, unreadable, or malformed file keeps the panel exactly as it
|
|
10
|
+
// was and never throws out of a render.
|
|
11
|
+
//
|
|
12
|
+
// No host subscription: the plugin API (`context.data.on`) does offer a
|
|
13
|
+
// `config.updated` event, but that fires for the host's own config documents,
|
|
14
|
+
// never for this plugin's file — and the event stream is volatile by
|
|
15
|
+
// contract (a slow consumer misses events). The footer already repaints on
|
|
16
|
+
// the ticker, so one stat rides a render that happens anyway: no extra timer,
|
|
17
|
+
// no missed change. Host-supplied options keep their setup precedence by
|
|
18
|
+
// construction — every re-read merges through the same
|
|
19
|
+
// `mergeOptions(file, host)` + `resolveConfig` path setup uses.
|
|
20
|
+
|
|
21
|
+
import { existsSync, statSync } from "node:fs";
|
|
22
|
+
import { join } from "node:path";
|
|
23
|
+
import { mergeOptions, resolveConfig } from "./config.js";
|
|
24
|
+
import { CONFIG_FILE_CANDIDATES, globalConfigDirectory, loadConfigFile } from "./file-config.js";
|
|
25
|
+
|
|
26
|
+
export interface GoLookReader {
|
|
27
|
+
/** The current look for `goPanelLines`' `layout`: `undefined` or a `GoPanelLook`. Never throws. */
|
|
28
|
+
readonly current: () => unknown;
|
|
29
|
+
/** Times the file was re-read + re-parsed since creation. Exposed for tests. */
|
|
30
|
+
readonly reads: () => number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** First config candidate that exists in `directory`, mirroring `loadConfigFile`. */
|
|
34
|
+
function findCandidate(directory: string): string | undefined {
|
|
35
|
+
for (const candidate of CONFIG_FILE_CANDIDATES) {
|
|
36
|
+
const path = join(directory, candidate);
|
|
37
|
+
if (existsSync(path)) return path;
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The cheap per-render probe: mtime + size, or `undefined` when unstatable. */
|
|
43
|
+
function snapshotOf(path: string): { mtimeMs: number; size: number } | undefined {
|
|
44
|
+
try {
|
|
45
|
+
const stats = statSync(path);
|
|
46
|
+
if (!stats.isFile()) return undefined;
|
|
47
|
+
return { mtimeMs: stats.mtimeMs, size: stats.size };
|
|
48
|
+
} catch {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The `layout` shape `goPanelLines` takes: `true` means its own defaults. */
|
|
54
|
+
function layoutOf(go: unknown): unknown {
|
|
55
|
+
return go === true ? undefined : typeof go === "object" && go !== null ? go : undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Watch `sidebar.footer.go` in `directory` (default the global config
|
|
60
|
+
* directory), starting from the setup-resolved `initial` look.
|
|
61
|
+
*
|
|
62
|
+
* `hostOptions` is the setup `context.options`, merged on every re-read so
|
|
63
|
+
* host-forwarded options keep precedence exactly as at setup. Only a file the
|
|
64
|
+
* loader accepts (present, regular, sized, parseable as an object) replaces
|
|
65
|
+
* the cached look; anything else keeps it.
|
|
66
|
+
*/
|
|
67
|
+
export function createGoLookReader(input: {
|
|
68
|
+
readonly directory?: string;
|
|
69
|
+
readonly hostOptions?: unknown;
|
|
70
|
+
readonly initial: unknown;
|
|
71
|
+
}): GoLookReader {
|
|
72
|
+
const directory = input.directory ?? globalConfigDirectory();
|
|
73
|
+
const hostOptions = input.hostOptions;
|
|
74
|
+
let look: unknown = input.initial;
|
|
75
|
+
let reads = 0;
|
|
76
|
+
|
|
77
|
+
// Primed so the first render takes the cheap path when nothing changed.
|
|
78
|
+
// Neither probe throws (`existsSync` returns false on error; `snapshotOf`
|
|
79
|
+
// catches), so creation is as safe as a render.
|
|
80
|
+
let seenPath: string | undefined = findCandidate(directory);
|
|
81
|
+
let seen: { mtimeMs: number; size: number } | undefined =
|
|
82
|
+
seenPath === undefined ? undefined : snapshotOf(seenPath);
|
|
83
|
+
|
|
84
|
+
const current = (): unknown => {
|
|
85
|
+
try {
|
|
86
|
+
const path = findCandidate(directory);
|
|
87
|
+
if (path === undefined) {
|
|
88
|
+
seenPath = undefined;
|
|
89
|
+
seen = undefined;
|
|
90
|
+
return look;
|
|
91
|
+
}
|
|
92
|
+
const snap = snapshotOf(path);
|
|
93
|
+
if (snap === undefined) {
|
|
94
|
+
// Gone or unstatable between the scan and the stat: keep the look.
|
|
95
|
+
seenPath = undefined;
|
|
96
|
+
seen = undefined;
|
|
97
|
+
return look;
|
|
98
|
+
}
|
|
99
|
+
if (seenPath === path && seen !== undefined && snap.mtimeMs === seen.mtimeMs && snap.size === seen.size) {
|
|
100
|
+
return look;
|
|
101
|
+
}
|
|
102
|
+
// The file moved: re-read + re-parse, then re-stat so a write landing
|
|
103
|
+
// mid-parse is itself a change the next render picks up.
|
|
104
|
+
const loaded = loadConfigFile(directory);
|
|
105
|
+
reads += 1;
|
|
106
|
+
seenPath = path;
|
|
107
|
+
seen = snapshotOf(path) ?? snap;
|
|
108
|
+
if (loaded.options === undefined) return look;
|
|
109
|
+
const { config } = resolveConfig(mergeOptions(loaded.options, hostOptions));
|
|
110
|
+
look = layoutOf(config.sidebar.footer.go);
|
|
111
|
+
return look;
|
|
112
|
+
} catch {
|
|
113
|
+
return look;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
return { current, reads: () => reads };
|
|
118
|
+
}
|