oc-flight-deck 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,34 +1,34 @@
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 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
+ }
package/src/tui/stats.ts CHANGED
@@ -60,6 +60,8 @@ export interface StatSource {
60
60
  readonly spark?: unknown;
61
61
  /** Animation frame counter, advanced by the ticker. */
62
62
  readonly frame?: unknown;
63
+ /** Harness status from oc-harness-guard's RPC, via the guard bridge. Untrusted. */
64
+ readonly guard?: unknown;
63
65
  }
64
66
 
65
67
  /** Fields a user may name in `sidebar.rows`, in the order they are documented. */
@@ -81,6 +83,7 @@ export const STAT_FIELDS = [
81
83
  "spark",
82
84
  "reasoning",
83
85
  "turns",
86
+ "guard",
84
87
  ] as const;
85
88
 
86
89
  export type StatField = (typeof STAT_FIELDS)[number];
@@ -154,6 +157,70 @@ function asCount(value: unknown): number | undefined {
154
157
  return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
155
158
  }
156
159
 
160
+ /**
161
+ * A guard count: a non-negative whole number, or an array counted by length.
162
+ *
163
+ * The RPC aggregates are numbers, but an array (findings, breaches) reads the
164
+ * same way — how many — so both count. Anything else is dropped to `undefined`
165
+ * so the caller can fall back to zero rather than print garbage.
166
+ */
167
+ function asGuardCount(value: unknown): number | undefined {
168
+ if (typeof value === "number" && Number.isFinite(value) && value >= 0) return Math.floor(value);
169
+ if (Array.isArray(value)) return value.length;
170
+ return undefined;
171
+ }
172
+
173
+ function guardCountOrZero(...candidates: readonly unknown[]): number {
174
+ for (const candidate of candidates) {
175
+ const count = asGuardCount(candidate);
176
+ if (count !== undefined) return count;
177
+ }
178
+ return 0;
179
+ }
180
+
181
+ /**
182
+ * Short harness token for the `guard` row, or `undefined` when there is no
183
+ * usable data (the persist layer then renders the placeholder).
184
+ *
185
+ * A section counts as usable only with an explicit boolean `available`: a
186
+ * present section with a missing or garbage flag is dropped, not read as
187
+ * either `ok` or `unknown`. Any usable section reporting `available: false`
188
+ * reads as `unknown` — a failed or disabled source never renders a false `ok`.
189
+ * Otherwise the worst signal wins: breaches, then orphans, then findings.
190
+ * ASCII, short, no padding.
191
+ */
192
+ function guardToken(value: unknown): string | undefined {
193
+ try {
194
+ const top = asRecord(value);
195
+ if (top === undefined) return undefined;
196
+
197
+ const air = asRecord(top.airworthiness);
198
+ const war = asRecord(top.warden);
199
+ const plan = asRecord(top.flightPlan);
200
+
201
+ const airUsable = air !== undefined && (air.available === true || air.available === false);
202
+ const warUsable = war !== undefined && (war.available === true || war.available === false);
203
+ const planUsable = plan !== undefined && (plan.available === true || plan.available === false);
204
+ if (!airUsable && !warUsable && !planUsable) return undefined;
205
+
206
+ if ((airUsable && air.available === false) || (warUsable && war.available === false) || (planUsable && plan.available === false)) {
207
+ return "unknown";
208
+ }
209
+
210
+ const breaches = warUsable ? guardCountOrZero(war.breaches) : 0;
211
+ const orphans = warUsable ? guardCountOrZero(war.orphans) : 0;
212
+ const findings = airUsable ? guardCountOrZero(air.findings, air.counts) : 0;
213
+
214
+ // Abbreviated so a huge count cannot exceed the rail width; stays ASCII.
215
+ if (breaches > 0) return `${formatCount(breaches)} breach`;
216
+ if (orphans > 0) return `${formatCount(orphans)} orphan`;
217
+ if (findings > 0) return `${formatCount(findings)} finding`;
218
+ return "ok";
219
+ } catch {
220
+ return undefined;
221
+ }
222
+ }
223
+
157
224
  /** `518k`, `29.2M`, `32M`, `940` — short enough for a narrow rail, precise enough to read. */
158
225
  export function formatCount(value: number): string {
159
226
  if (value < 1_000) return String(Math.round(value));
@@ -445,6 +512,10 @@ export function statLine(
445
512
  if (turns === undefined || turns === 0) return undefined;
446
513
  return row("turns", String(turns));
447
514
  }
515
+ case "guard": {
516
+ const token = guardToken(source.guard);
517
+ return token === undefined ? undefined : row("guard", token);
518
+ }
448
519
  default:
449
520
  return undefined;
450
521
  }