oc-flight-deck 0.2.0 → 0.2.2

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
@@ -93,13 +93,21 @@ them. On the session this was built against, the parent reported `$0.2246` while
93
93
  the true spend was `$0.2447` - **9% low on money, and 54% low on input tokens**.
94
94
 
95
95
  Rather than spend two rows on a number and its own superset, `cost` shows the
96
- family total and the delta that produced it:
96
+ family total and the count that explains it:
97
97
 
98
98
  ```
99
- cost $0.245 · +$0.020 · 2 subagents
99
+ cost $0.245 · 2 subagents
100
100
  ```
101
101
 
102
- `total` is still available if you prefer the two figures on separate rows.
102
+ **Add `total` to `sidebar.rows` and `cost` goes back to the session figure
103
+ alone** — the merge only happens when nothing else on the rail already shows it.
104
+ So "one money row or two" is decided by your rows list, not by another setting to
105
+ find.
106
+
107
+ The row is deliberately short. An earlier version also printed the delta
108
+ (`+ $0.020`), which pushed the row to 40 columns and made it **wrap** in a normal
109
+ sidebar. It was true information that did not earn its width, and a row that
110
+ wraps costs more than a row that says less.
103
111
 
104
112
  ### `cache` is the row that surprises people
105
113
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oc-flight-deck",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
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",
package/src/tui/stats.ts CHANGED
@@ -109,6 +109,14 @@ export interface LayoutHint {
109
109
  readonly labelWidth?: number;
110
110
  readonly barWidth?: number;
111
111
  readonly sparkWidth?: number;
112
+ /**
113
+ * True when the rail already draws a `total` row.
114
+ *
115
+ * The `cost` row merges the subagent total into itself only when nothing else
116
+ * on the rail already shows it — which makes "do I want one money row or two"
117
+ * a property of `sidebar.rows`, not a separate setting to find.
118
+ */
119
+ readonly hasTotalRow?: boolean;
112
120
  }
113
121
 
114
122
  const DEFAULT_LABEL_WIDTH = 10;
@@ -213,7 +221,14 @@ export function statLine(
213
221
  const labelWidth = layout.labelWidth ?? DEFAULT_LABEL_WIDTH;
214
222
  const barWidth = layout.barWidth ?? DEFAULT_BAR_WIDTH;
215
223
  const sparkWidth = layout.sparkWidth ?? DEFAULT_SPARK_WIDTH;
216
- const row = (label: string, value: string): string => `${label.padEnd(labelWidth)}${value}`;
224
+ // At least one space, always.
225
+ //
226
+ // `padEnd` returns the label unchanged when it is already wider than the
227
+ // column, so a label longer than `labelWidth` was glued straight onto its
228
+ // value: at labelWidth 8 the `reasoning` row rendered as "reasoning153k".
229
+ // The label is nine characters, which made this reachable from a config file.
230
+ const row = (label: string, value: string): string =>
231
+ `${label.padEnd(labelWidth)}${label.length >= labelWidth ? " " : ""}${value}`;
217
232
 
218
233
  switch (field) {
219
234
  case "caution": {
@@ -260,23 +275,30 @@ export function statLine(
260
275
  const tree = asRecord(source.tree);
261
276
  const treeCost = asCount(tree?.cost);
262
277
  const count = asCount(tree?.count);
278
+ const family = count !== undefined && count > 0 ? count : 0;
263
279
 
264
- // When subagents ran, this session's own cost understates the bill. Show
265
- // the family total and the delta that produced it, rather than spending a
266
- // second row on a number that contains the first. `total` still exists for
267
- // anyone who wants the two figures on separate rows.
268
- if (
280
+ // Merge only when subagents actually ran, and only when the rail is not
281
+ // already showing a `total` row. Two rows holding a number and its own
282
+ // superset was the thing worth fixing; a setting to choose between them
283
+ // would just be that duplication with extra steps.
284
+ const merge =
285
+ layout.hasTotalRow !== true &&
269
286
  cost !== undefined &&
270
287
  treeCost !== undefined &&
271
- count !== undefined &&
272
- count > 0 &&
273
- treeCost > cost
274
- ) {
275
- const plural = count === 1 ? "subagent" : "subagents";
276
- return row("cost", `${formatCost(treeCost)} · +${formatCost(treeCost - cost)} · ${count} ${plural}`);
288
+ family > 0 &&
289
+ treeCost > cost;
290
+
291
+ if (!merge) {
292
+ const value = layout.hasTotalRow === true ? (cost ?? treeCost) : (treeCost ?? cost);
293
+ return value === undefined ? undefined : row("cost", formatCost(value));
277
294
  }
278
- const value = cost ?? treeCost;
279
- return value === undefined ? undefined : row("cost", formatCost(value));
295
+
296
+ // The delta (`+$0.020`) used to be here and pushed the row to 40 columns,
297
+ // wide enough to wrap in a normal sidebar. It was real information that
298
+ // did not earn its width: the count already explains why the figure is
299
+ // higher, and this form is the same width as the old `total` row.
300
+ const plural = family === 1 ? "subagent" : "subagents";
301
+ return row("cost", `${formatCost(treeCost as number)} · ${family} ${plural}`);
280
302
  }
281
303
  case "total": {
282
304
  // Only worth a row once a subagent has actually run: subagent sessions are
@@ -342,7 +364,9 @@ export function statLine(
342
364
  return row("perms", action === undefined ? `${count} waiting` : `${count} waiting · ${action}`);
343
365
  }
344
366
  if (action === undefined) return row("perms", "1 waiting");
345
- return row("perms", resource === undefined ? action : `${action} · ${clip(resource, 22)}`);
367
+ // Clipped hard: a row that wraps costs the reader more than a row that
368
+ // shortens a path, and there is no way to ask the host how wide it is.
369
+ return row("perms", resource === undefined ? action : `${action} · ${clip(resource, 18)}`);
346
370
  }
347
371
  case "elapsed": {
348
372
  const ms = asCount(source.elapsedMs);
@@ -383,9 +407,13 @@ export function statRows(
383
407
  source: StatSource,
384
408
  layout: LayoutHint = {},
385
409
  ): readonly string[] {
410
+ // The rows list decides whether `cost` merges the subagent total into itself.
411
+ // Passing that down means the choice lives in `sidebar.rows`, where someone
412
+ // is already deciding what the rail shows.
413
+ const hint: LayoutHint = { ...layout, hasTotalRow: fields.includes("total") };
386
414
  const rows: string[] = [];
387
415
  for (const field of fields) {
388
- const line = statLine(field, source, layout);
416
+ const line = statLine(field, source, hint);
389
417
  if (line !== undefined) rows.push(line);
390
418
  }
391
419
  return rows;