oc-flight-deck 0.2.3 → 0.3.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.
package/README.md CHANGED
@@ -123,6 +123,26 @@ wraps costs more than a row that says less.
123
123
  A 98% hit rate is why millions of tokens can cost cents. The moment that number
124
124
  drops, your bill doesn't.
125
125
 
126
+ ### Every selected row stays on the rail
127
+
128
+ Each field named in `sidebar.rows` renders exactly one row, in order. When the
129
+ host has nothing to show yet, the row shows the `sidebar.placeholder` value
130
+ (default `"—"`) in the same label column as a live row — so `cache` is visible
131
+ before the first cache hit, and the rail keeps a stable shape instead of
132
+ growing rows as the session produces data.
133
+
134
+ ```jsonc
135
+ {
136
+ "sidebar": {
137
+ "persist": true, // the default: stable rows with a placeholder
138
+ "placeholder": "—"
139
+ }
140
+ }
141
+ ```
142
+
143
+ Set `"persist": false` to restore omission: rows with no data are then left out
144
+ entirely, which is also how a narrow rail stays shortest.
145
+
126
146
  ## Configuration
127
147
 
128
148
  **You don't need any.** Install it and the panel works. But every knob is
@@ -207,7 +227,9 @@ bun run check
207
227
  `bun run check` typechecks and runs the suite, including headless OpenTUI render
208
228
  tests that mount the panel in a real renderer and assert the exact characters
209
229
  that come out. A guard test parses the shipped example config and asserts it
210
- still matches the real defaults, so the documentation can't drift from the code.
230
+ still matches the real defaults, and a schema test validates that parsed
231
+ example against the shipped schema — defaults, types, and allowed values —
232
+ so the documentation can't drift from the code on either side.
211
233
 
212
234
  To load the plugin **from this checkout** while working on it, add it to the
213
235
  `opencode.jsonc` of the project you run OpenCode in. A `plugins` entry is a
@@ -230,8 +252,7 @@ Built on the official
230
252
 
231
253
  ## Compatibility
232
254
 
233
- The OpenCode plugin API is still in beta. This release targets
234
- `@opencode/plugin` beta `0.0.0-beta-19425`; pin a host version you've tested.
255
+ Built against `@opencode/plugin` `2.0.2`; pin a host version you've tested.
235
256
 
236
257
  Requires OpenCode V2 (`opencode2`). Building from source needs Bun 1.4+ or
237
258
  Node 22+.
@@ -73,9 +73,10 @@
73
73
  // reasoning reasoning tokens, when the model emits them
74
74
  // turns how many prompts you have sent this session
75
75
  //
76
- // A row appears only once the host has data for it — nothing is drawn as a
77
- // placeholder. The fixed lines and the live rows together are capped at 24,
78
- // and anything past that is dropped.
76
+ // Every named row renders persistently, so the rail keeps a stable shape:
77
+ // a row with no data yet shows the placeholder below, in the same label
78
+ // column as a live row. The fixed lines and the live rows together are
79
+ // capped at 24, and anything past that is dropped.
79
80
  "rows": [
80
81
  "caution",
81
82
  "status",
@@ -90,7 +91,15 @@
90
91
  "perms",
91
92
  "elapsed",
92
93
  "tps"
93
- ]
94
+ ],
95
+
96
+ // Every named row renders persistently: with no data yet it shows the
97
+ // placeholder below, in the same label column as a live row. Set to false
98
+ // to omit rows with no data instead.
99
+ "persist": true,
100
+
101
+ // Value shown for a persistent row with no data yet. Any non-empty string.
102
+ "placeholder": "—"
94
103
  },
95
104
 
96
105
  // ── Footer ───────────────────────────────────────────────────────────────
@@ -41,7 +41,18 @@
41
41
  "items": { "enum": ["caution", "status", "agent", "model", "branch", "cost", "total", "project", "tokens", "cache", "context", "perms", "elapsed", "tps", "spark", "reasoning", "turns"] },
42
42
  "default": ["caution", "status", "agent", "model", "branch", "cost", "project", "tokens", "cache", "context", "perms", "elapsed", "tps"],
43
43
  "maxItems": 24,
44
- "description": "Which live fields to draw, top to bottom. Any subset, any order — this is the single most useful thing to change. Rows with no data are omitted entirely, so a narrow rail grows rows as a session produces them rather than showing placeholders. Counted together with `sidebar.lines` against a 24-line cap on the whole rail."
44
+ "description": "Which live fields to draw, top to bottom. Any subset, any order — this is the single most useful thing to change. With `sidebar.persist` (the default) every named row always renders, using `sidebar.placeholder` until the host has data; with `persist: false` rows with no data are omitted entirely. Counted together with `sidebar.lines` against a 24-line cap on the whole rail."
45
+ },
46
+ "persist": {
47
+ "type": "boolean",
48
+ "default": true,
49
+ "description": "Render every field named in `sidebar.rows` as a persistent row, using `sidebar.placeholder` when the host has no data yet. True keeps the rail a stable shape that fills in as the session produces data; false restores the old behavior of omitting rows with no data."
50
+ },
51
+ "placeholder": {
52
+ "type": "string",
53
+ "minLength": 1,
54
+ "default": "—",
55
+ "description": "Value shown for a persistent row with no data yet. Used only when `sidebar.persist` is true. Must be a non-empty string; anything else falls back to the default em dash."
45
56
  }
46
57
  }
47
58
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oc-flight-deck",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "Live OpenCode V2 session telemetry — agent, model, branch, cost, tokens, cache hit rate and context usage in your sidebar.",
5
5
  "keywords": [
6
6
  "opencode",
@@ -53,7 +53,7 @@
53
53
  "access": "public"
54
54
  },
55
55
  "dependencies": {
56
- "@opencode/plugin": "0.0.0-beta-19425"
56
+ "@opencode/plugin": "2.0.2"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@opentui/core": "0.5.10",
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 { isStatField, STAT_FIELDS } from "./stats.js";
11
+ import { DEFAULT_PLACEHOLDER, isStatField, STAT_FIELDS } from "./stats.js";
12
12
  import type { CautionThresholds } from "./caution.js";
13
13
 
14
14
  export interface SidebarConfig {
@@ -18,6 +18,13 @@ export interface SidebarConfig {
18
18
  readonly lines: readonly string[];
19
19
  /** Live session fields to render, top to bottom. Default `DEFAULT_SIDEBAR_ROWS`. */
20
20
  readonly rows: readonly string[];
21
+ /**
22
+ * Render every named row even when the host has no data for it, using
23
+ * `placeholder` as the value. Default `true`; `false` restores omission.
24
+ */
25
+ readonly persist: boolean;
26
+ /** Value shown for a row with no data when `persist` is on. Default `"—"`. */
27
+ readonly placeholder: string;
21
28
  }
22
29
 
23
30
  export interface FooterConfig {
@@ -208,7 +215,13 @@ export const MIN_REFRESH_MS = 16;
208
215
  export const DEFAULT_FOOTER_TEXT = "Flight Deck";
209
216
 
210
217
  export const DEFAULT_CONFIG: FlightDeckConfig = {
211
- sidebar: { enabled: true, lines: DEFAULT_SIDEBAR_LINES, rows: DEFAULT_SIDEBAR_ROWS },
218
+ sidebar: {
219
+ enabled: true,
220
+ lines: DEFAULT_SIDEBAR_LINES,
221
+ rows: DEFAULT_SIDEBAR_ROWS,
222
+ persist: true,
223
+ placeholder: DEFAULT_PLACEHOLDER,
224
+ },
212
225
  footer: { enabled: false, text: DEFAULT_FOOTER_TEXT },
213
226
  caution: DEFAULT_CAUTION,
214
227
  layout: DEFAULT_LAYOUT,
@@ -324,7 +337,13 @@ function readRows(value: unknown, issues: string[]): readonly string[] {
324
337
  issues.push(`${path} must be a string; skipping it`);
325
338
  return;
326
339
  }
327
- const name = entry.trim().toLowerCase();
340
+ // Control characters are normalized before matching, like every other
341
+ // config string: `cache\n` is the `cache` row, not an unknown field.
342
+ const name = normalizeText(entry, path, issues).toLowerCase();
343
+ if (name.length === 0) {
344
+ issues.push(`${path} is empty; skipping it`);
345
+ return;
346
+ }
328
347
  if (!isStatField(name)) {
329
348
  issues.push(`${path} is not a known field (${STAT_FIELDS.join(", ")}); skipping it`);
330
349
  return;
@@ -614,6 +633,13 @@ export function resolveConfig(options: unknown): ConfigResolution {
614
633
  enabled: readBoolean(sidebar.enabled, DEFAULT_CONFIG.sidebar.enabled, "sidebar.enabled", issues),
615
634
  lines,
616
635
  rows,
636
+ persist: readBoolean(sidebar.persist, DEFAULT_CONFIG.sidebar.persist, "sidebar.persist", issues),
637
+ placeholder: readText(
638
+ sidebar.placeholder,
639
+ DEFAULT_CONFIG.sidebar.placeholder,
640
+ "sidebar.placeholder",
641
+ issues,
642
+ ),
617
643
  },
618
644
  footer: {
619
645
  enabled: readBoolean(footer.enabled, footerConfigured, "footer.enabled", issues),
@@ -13,12 +13,14 @@ import { statRows, type StatSource } from "./stats.js";
13
13
  * Sidebar lines to render, or an empty list when the sidebar rail is disabled.
14
14
  *
15
15
  * Configured `lines` render first (branding, separators, any fixed text), then
16
- * the live rows named by `sidebar.rows`, each included only once the host has
17
- * data for it.
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.
18
19
  */
19
20
  export function sidebarLines(config: FlightDeckConfig, source: StatSource = {}): readonly string[] {
20
21
  if (!config.sidebar.enabled) return [];
21
- return [...config.sidebar.lines, ...statRows(config.sidebar.rows, source, config.layout)].slice(0, MAX_LINES);
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);
22
24
  }
23
25
 
24
26
  /** Footer text to render, or `undefined` when the footer rail is disabled. */
package/src/tui/stats.ts CHANGED
@@ -120,8 +120,20 @@ export interface LayoutHint {
120
120
  * a property of `sidebar.rows`, not a separate setting to find.
121
121
  */
122
122
  readonly hasTotalRow?: boolean;
123
+ /**
124
+ * When true, `statRows` renders one row per named field even when the host
125
+ * has no data for it, using `placeholder` as the value. Default off when
126
+ * calling `statRows` directly; `sidebarLines` turns it on from
127
+ * `config.sidebar.persist`.
128
+ */
129
+ readonly persist?: boolean;
130
+ /** Value shown for a row with no data when `persist` is on. Default `"—"`. */
131
+ readonly placeholder?: string;
123
132
  }
124
133
 
134
+ /** Placeholder value for a persistent row with no data yet. */
135
+ export const DEFAULT_PLACEHOLDER = "—";
136
+
125
137
  const DEFAULT_LABEL_WIDTH = 10;
126
138
  const DEFAULT_BAR_WIDTH = 10;
127
139
  const DEFAULT_SPARK_WIDTH = 12;
@@ -215,6 +227,15 @@ function plain(value: string): string {
215
227
  return value.replace(CONTROL_CHARS, " ");
216
228
  }
217
229
 
230
+ /**
231
+ * One padded rail row: the label in its column, at least one space, then the
232
+ * flattened value. Shared by live rows and persistent placeholders so both
233
+ * keep the same column.
234
+ */
235
+ function formatRow(label: string, value: string, labelWidth: number): string {
236
+ return `${label.padEnd(labelWidth)}${label.length >= labelWidth ? " " : ""}${plain(value)}`;
237
+ }
238
+
218
239
  /**
219
240
  * Recent turn sizes as a shape.
220
241
  *
@@ -256,8 +277,7 @@ export function statLine(
256
277
  // column, so a label longer than `labelWidth` was glued straight onto its
257
278
  // value: at labelWidth 8 the `reasoning` row rendered as "reasoning153k".
258
279
  // The label is nine characters, which made this reachable from a config file.
259
- const row = (label: string, value: string): string =>
260
- `${label.padEnd(labelWidth)}${label.length >= labelWidth ? " " : ""}${plain(value)}`;
280
+ const row = (label: string, value: string): string => formatRow(label, value, labelWidth);
261
281
 
262
282
  switch (field) {
263
283
  case "caution": {
@@ -430,7 +450,13 @@ export function statLine(
430
450
  }
431
451
  }
432
452
 
433
- /** Render every named field that currently has data, in the given order. */
453
+ /** Render every named field, in the given order.
454
+ *
455
+ * By default only fields with data render; with `layout.persist` every known
456
+ * field renders exactly one row, using `layout.placeholder` (default `"—"`)
457
+ * for the value when the host has nothing to show yet. `statLine` keeps
458
+ * returning `string | undefined` — persistence lives here, not there.
459
+ */
434
460
  export function statRows(
435
461
  fields: readonly string[],
436
462
  source: StatSource,
@@ -440,10 +466,20 @@ export function statRows(
440
466
  // Passing that down means the choice lives in `sidebar.rows`, where someone
441
467
  // is already deciding what the rail shows.
442
468
  const hint: LayoutHint = { ...layout, hasTotalRow: fields.includes("total") };
469
+ const persist = hint.persist === true;
470
+ const placeholder = hint.placeholder ?? DEFAULT_PLACEHOLDER;
471
+ const labelWidth = hint.labelWidth ?? DEFAULT_LABEL_WIDTH;
443
472
  const rows: string[] = [];
444
473
  for (const field of fields) {
445
474
  const line = statLine(field, source, hint);
446
- if (line !== undefined) rows.push(line);
475
+ if (line !== undefined) {
476
+ rows.push(line);
477
+ continue;
478
+ }
479
+ // Unknown names stay skipped even when persistent: a typo must stay a
480
+ // reported-and-skipped row, not a placeholder that looks intentional.
481
+ if (!persist || !isStatField(field)) continue;
482
+ rows.push(formatRow(field, placeholder, labelWidth));
447
483
  }
448
484
  return rows;
449
485
  }