oc-flight-deck 0.24.0 → 0.25.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 +15 -0
- package/README.md +42 -24
- package/dist/tui/index.js +285 -115
- package/docs/GUIDE.md +12 -8
- package/flight-deck.example.jsonc +49 -31
- package/flight-deck.schema.json +35 -11
- package/package.json +6 -6
- package/src/tui/caution.ts +15 -6
- package/src/tui/config.ts +125 -12
- package/src/tui/go-panel.ts +5 -3
- package/src/tui/index.tsx +48 -6
- package/src/tui/lifetime-totals.ts +92 -0
- package/src/tui/presentation.ts +12 -5
- package/src/tui/rows.ts +84 -76
- package/src/tui/session-reads.ts +55 -12
- package/src/tui/stat-fields.ts +59 -22
package/src/tui/rows.ts
CHANGED
|
@@ -311,15 +311,21 @@ export function statLine(
|
|
|
311
311
|
}
|
|
312
312
|
case "status": {
|
|
313
313
|
const status = asText(source.status);
|
|
314
|
-
|
|
314
|
+
const paused = source.paused === true;
|
|
315
|
+
if (status === undefined && source.busy === undefined && !paused) return undefined;
|
|
316
|
+
// A person being asked something outranks the spinner: the session may
|
|
317
|
+
// still be busy underneath, but nothing moves until they answer.
|
|
318
|
+
if (paused) return row("status", `${layout.pausedGlyph ?? "‖"} paused`);
|
|
315
319
|
// The spinner lives here rather than in a row of its own: an animated
|
|
316
320
|
// glyph beside "running" says the same thing without spending a line.
|
|
317
321
|
//
|
|
318
322
|
// `busy` folds in work the session's own status misses — a subagent
|
|
319
|
-
// running in its own session,
|
|
320
|
-
// glyph only stops when there is
|
|
321
|
-
//
|
|
322
|
-
if (source.busy !== true && status !== "running")
|
|
323
|
+
// running in its own session, a shell command still going, a live tool,
|
|
324
|
+
// or an open turn — so the glyph only stops when there is real evidence
|
|
325
|
+
// of work. A stale host `running` with none of that reads idle.
|
|
326
|
+
if (source.busy === false || (source.busy !== true && status !== "running")) {
|
|
327
|
+
return row("status", "○ idle");
|
|
328
|
+
}
|
|
323
329
|
// Floored at the boundary: a fractional frame would index the frame list
|
|
324
330
|
// with a non-integer and render `undefined`.
|
|
325
331
|
const frame = Math.floor(asCount(source.frame) ?? 0);
|
|
@@ -340,7 +346,7 @@ export function statLine(
|
|
|
340
346
|
const branch = asText(source.branch);
|
|
341
347
|
return branch === undefined ? undefined : row("branch", branch);
|
|
342
348
|
}
|
|
343
|
-
case "
|
|
349
|
+
case "spend": {
|
|
344
350
|
const cost = asCount(source.cost);
|
|
345
351
|
const tree = asRecord(source.tree);
|
|
346
352
|
const treeCost = asCount(tree?.cost);
|
|
@@ -348,53 +354,53 @@ export function statLine(
|
|
|
348
354
|
const family = count !== undefined && count > 0 ? count : 0;
|
|
349
355
|
|
|
350
356
|
// Merge only when subagents actually ran, and only when the rail is not
|
|
351
|
-
// already showing a `
|
|
352
|
-
// superset was the thing worth fixing; a
|
|
353
|
-
// would just be that duplication
|
|
357
|
+
// already showing a `lifetime` row (or its `total` alias). Two rows
|
|
358
|
+
// holding a number and its own superset was the thing worth fixing; a
|
|
359
|
+
// setting to choose between them would just be that duplication.
|
|
354
360
|
const merge =
|
|
355
|
-
layout.
|
|
361
|
+
layout.hasLifetimeRow !== true &&
|
|
356
362
|
cost !== undefined &&
|
|
357
363
|
treeCost !== undefined &&
|
|
358
364
|
family > 0 &&
|
|
359
365
|
treeCost > cost;
|
|
360
366
|
|
|
361
367
|
if (!merge) {
|
|
362
|
-
// `
|
|
363
|
-
//
|
|
364
|
-
//
|
|
365
|
-
|
|
366
|
-
|
|
368
|
+
// `spend` is the current model's spend and nothing else. With no spend
|
|
369
|
+
// on that model the row draws a sane zero, never a dash or a hole, and
|
|
370
|
+
// it still never borrows the family figure under a one-model label.
|
|
371
|
+
// `field` keeps the caller's spelling, so the `cost` alias still draws
|
|
372
|
+
// its old label.
|
|
373
|
+
return row(field, `${feeMark(source.costKind)}${formatCost(cost ?? 0)}`);
|
|
367
374
|
}
|
|
368
375
|
|
|
369
376
|
// The delta (`+$0.020`) used to be here and pushed the row to 40 columns,
|
|
370
377
|
// wide enough to wrap in a normal sidebar. It was real information that
|
|
371
378
|
// did not earn its width: the count already explains why the figure is
|
|
372
|
-
// higher, and this form is the same width as the
|
|
379
|
+
// higher, and this form is the same width as the lifetime row.
|
|
373
380
|
const plural = family === 1 ? "subagent" : "subagents";
|
|
374
|
-
return row(
|
|
375
|
-
"cost",
|
|
376
|
-
`${feeMark(tree?.kind)}${formatCost(treeCost as number)} · ${family} ${plural}`,
|
|
377
|
-
);
|
|
381
|
+
return row(field, `${feeMark(tree?.kind)}${formatCost(treeCost as number)} · ${family} ${plural}`);
|
|
378
382
|
}
|
|
379
|
-
case "
|
|
383
|
+
case "lifetime": {
|
|
380
384
|
// The family figure: this session plus its subagent sessions. Since 0.20.0
|
|
381
385
|
// it is drawn even when no subagent has run — the true family total is then
|
|
382
386
|
// the session's own cost, and the row reads `$0.000 · 0 subagents` rather
|
|
383
387
|
// than blanking, because the row the owner renames to `lifetime` must never
|
|
384
|
-
// have a hole in it.
|
|
385
|
-
//
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
|
|
388
|
+
// have a hole in it. With no family record at all it still draws the
|
|
389
|
+
// honest zero: this is a numeric row, so it never blanks or falls back
|
|
390
|
+
// to the placeholder.
|
|
391
|
+
const live = asRecord(source.tree);
|
|
392
|
+
const durable = asRecord(source.lifetime);
|
|
393
|
+
// The durable high-water wins over the host's current roll-up so the
|
|
394
|
+
// lifetime never shrinks. The cost row keeps reading `tree` alone, so
|
|
395
|
+
// raising this figure cannot change the current model's spend.
|
|
396
|
+
const cost = asCount(durable?.cost) ?? asCount(live?.cost) ?? 0;
|
|
397
|
+
const count = asCount(live?.count) ?? 0;
|
|
391
398
|
const plural = count === 1 ? "subagent" : "subagents";
|
|
392
|
-
return row(
|
|
399
|
+
return row(field, `${feeMark(durable?.kind ?? live?.kind)}${formatCost(cost)} · ${count} ${plural}`);
|
|
393
400
|
}
|
|
394
401
|
case "project": {
|
|
395
402
|
const project = asRecord(source.project);
|
|
396
|
-
const cost = asCount(project?.cost);
|
|
397
|
-
if (cost === undefined) return undefined;
|
|
403
|
+
const cost = asCount(project?.cost) ?? 0;
|
|
398
404
|
const count = asCount(project?.count);
|
|
399
405
|
return row("project", `${formatCost(cost)}${count !== undefined && count > 1 ? ` · ${count} sessions` : ""}`);
|
|
400
406
|
}
|
|
@@ -402,15 +408,16 @@ export function statLine(
|
|
|
402
408
|
const tokens = asRecord(source.tokens);
|
|
403
409
|
const input = asCount(tokens?.input);
|
|
404
410
|
const output = asCount(tokens?.output);
|
|
405
|
-
|
|
411
|
+
// No token record is a measured zero, not missing data: the row always
|
|
412
|
+
// draws its honest `0 in · 0 out`.
|
|
406
413
|
return row("tokens", `${formatCount(input ?? 0)} in · ${formatCount(output ?? 0)} out`);
|
|
407
414
|
}
|
|
408
415
|
case "cache": {
|
|
409
416
|
const tokens = asRecord(source.tokens);
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
417
|
+
const cache = asRecord(tokens?.cache);
|
|
418
|
+
// An absent token record draws `0 read` rather than blanking: a numeric
|
|
419
|
+
// row always has an honest zero to show.
|
|
420
|
+
const read = asCount(cache?.read) ?? 0;
|
|
414
421
|
const input = asCount(tokens?.input);
|
|
415
422
|
// Hit ratio is the whole point: it explains a cheap bill on a huge token
|
|
416
423
|
// count, and it is the first thing to break when caching stops working.
|
|
@@ -437,8 +444,10 @@ export function statLine(
|
|
|
437
444
|
case "context": {
|
|
438
445
|
const context = asRecord(source.context);
|
|
439
446
|
const used = asCount(context?.used);
|
|
440
|
-
if (used === undefined || used === 0) return undefined;
|
|
441
447
|
const limit = asCount(context?.limit);
|
|
448
|
+
// No occupancy yet is a measured zero, drawn as `~0 used` with the same
|
|
449
|
+
// estimate mark as the populated row. A numeric row never blanks.
|
|
450
|
+
if (used === undefined || used === 0) return row("context", "~0 used");
|
|
442
451
|
// `used` is an occupancy PROXY (last request's input + cache read +
|
|
443
452
|
// cache write), not a host-reported figure, so both shapes below carry
|
|
444
453
|
// a `~`: the row reads as the estimate it is, never as an exact count.
|
|
@@ -467,8 +476,9 @@ export function statLine(
|
|
|
467
476
|
return row("perms", resource === undefined ? action : `${action} · ${clip(resource, 18)}`);
|
|
468
477
|
}
|
|
469
478
|
case "elapsed": {
|
|
470
|
-
|
|
471
|
-
|
|
479
|
+
// A session with no recorded turn time has spent zero active seconds.
|
|
480
|
+
// Draw that zero instead of hiding the numeric row.
|
|
481
|
+
const ms = asCount(source.elapsedMs) ?? 0;
|
|
472
482
|
return row("elapsed", formatDuration(ms, layout.durationStyle));
|
|
473
483
|
}
|
|
474
484
|
case "updated": {
|
|
@@ -491,44 +501,37 @@ export function statLine(
|
|
|
491
501
|
// boundary, so all re-coerced like every other field. Which one draws
|
|
492
502
|
// is `layout.tpsDisplay` (the row's view of `sidebar.tps.display`,
|
|
493
503
|
// default `"rt"`); presentation.ts feeds it from the resolved config.
|
|
504
|
+
// `layout.tpsTtft` is `sidebar.tps.ttft`: off, `ttft` never draws in any
|
|
505
|
+
// mode. `layout.tpsLabel` is `sidebar.tps.label`: the suffix on the two
|
|
506
|
+
// single-figure modes ("tok/s" shipped); "both" names its own halves.
|
|
494
507
|
const pair = asRecord(source.tps);
|
|
495
508
|
const rt = asCount(pair?.["rt"]);
|
|
496
509
|
const avg = asCount(pair?.["avg"]);
|
|
497
510
|
const ttft = asCount(pair?.["ttft"]);
|
|
511
|
+
const shownTtft = (layout.tpsTtft ?? true) ? ttft : undefined;
|
|
498
512
|
const display = layout.tpsDisplay ?? "rt";
|
|
513
|
+
const label = layout.tpsLabel ?? "tok/s";
|
|
514
|
+
// A numeric row never blanks. An absent or sub-half rate is a measured
|
|
515
|
+
// zero, so it draws `0 <label>` — never a placeholder and never a
|
|
516
|
+
// ttft-only fallback. Figures are whole tokens/second: the value is an
|
|
517
|
+
// EWMA over estimated delta samples, so a decimal would fake precision.
|
|
518
|
+
const rounded = (value: number | undefined): number => {
|
|
519
|
+
const value_ = value === undefined ? 0 : Math.round(value);
|
|
520
|
+
return value_ > 0 ? value_ : 0;
|
|
521
|
+
};
|
|
522
|
+
const current = rounded(rt);
|
|
523
|
+
const settled = rounded(avg);
|
|
524
|
+
const suffix = shownTtft === undefined ? "" : ` · ${shownTtft.toFixed(1)}s ttft`;
|
|
499
525
|
if (display === "rt") {
|
|
500
|
-
|
|
501
|
-
// EWMA over estimated delta samples, so a decimal would fake a
|
|
502
|
-
// precision the samples never had. Anything below half a
|
|
503
|
-
// token/second hides rather than printing "0 tok/s".
|
|
504
|
-
const rounded = rt === undefined ? undefined : Math.round(rt);
|
|
505
|
-
if (rounded === undefined || rounded <= 0) {
|
|
506
|
-
return ttft === undefined ? undefined : row("tps", `${ttft.toFixed(1)}s ttft`);
|
|
507
|
-
}
|
|
508
|
-
const rate = `${rounded} tok/s`;
|
|
509
|
-
return row("tps", ttft === undefined ? rate : `${rate} · ${ttft.toFixed(1)}s ttft`);
|
|
526
|
+
return row("tps", current > 0 ? `${current} ${label}${suffix}` : `0 ${label}`);
|
|
510
527
|
}
|
|
511
528
|
if (display === "both") {
|
|
512
|
-
// Both
|
|
513
|
-
//
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
// The realtime-alone degrade is only for a missing average; a present
|
|
517
|
-
// average that rounds to zero hides the whole row, like the avg
|
|
518
|
-
// mode's own hide rule. Without either figure there is no row.
|
|
519
|
-
if (avg !== undefined) {
|
|
520
|
-
if (Math.round(avg) <= 0) return undefined;
|
|
521
|
-
const head = `${rt === undefined ? 0 : Math.round(rt)} rt · ${Math.round(avg)} avg`;
|
|
522
|
-
return ttft === undefined ? row("tps", head) : row("tps", `${head} · ${ttft.toFixed(1)}s ttft`);
|
|
523
|
-
}
|
|
524
|
-
if (rt !== undefined && Math.round(rt) > 0) return row("tps", `${Math.round(rt)} rt`);
|
|
525
|
-
return undefined;
|
|
529
|
+
// Both halves keep their structural names, whatever `label` says.
|
|
530
|
+
// TTFT rides only when a rate stands; a zero rate never borrows it.
|
|
531
|
+
const head = `${current} rt · ${settled} avg`;
|
|
532
|
+
return row("tps", settled > 0 ? head + suffix : head);
|
|
526
533
|
}
|
|
527
|
-
|
|
528
|
-
// rounded. The hide rule is the realtime row's own: at or below half a
|
|
529
|
-
// token/second it hides rather than printing "0 tok/s".
|
|
530
|
-
if (avg === undefined || Math.round(avg) <= 0) return undefined;
|
|
531
|
-
return row("tps", `${Math.round(avg)} tok/s`);
|
|
534
|
+
return row("tps", `${settled} ${label}`);
|
|
532
535
|
}
|
|
533
536
|
case "spark": {
|
|
534
537
|
const values = Array.isArray(source.spark) ? source.spark.map((value) => asCount(value) ?? 0) : [];
|
|
@@ -539,8 +542,9 @@ export function statLine(
|
|
|
539
542
|
return row("spark", sparkline(windowed));
|
|
540
543
|
}
|
|
541
544
|
case "reasoning": {
|
|
542
|
-
|
|
543
|
-
|
|
545
|
+
// A model that emits no reasoning tokens still reads `0` on the row;
|
|
546
|
+
// the count keeps the same unit as a populated figure.
|
|
547
|
+
const reasoning = asCount(asRecord(source.tokens)?.reasoning) ?? 0;
|
|
544
548
|
return row("reasoning", formatCount(reasoning));
|
|
545
549
|
}
|
|
546
550
|
case "turns": {
|
|
@@ -641,18 +645,22 @@ export function statRows(
|
|
|
641
645
|
source: StatSource,
|
|
642
646
|
layout: LayoutHint = {},
|
|
643
647
|
): readonly string[] {
|
|
644
|
-
// The rows list decides whether `
|
|
645
|
-
//
|
|
646
|
-
//
|
|
647
|
-
const hint: LayoutHint = {
|
|
648
|
+
// The rows list decides whether `spend` merges the subagent total into
|
|
649
|
+
// itself. Both `lifetime` and its `total` alias count, so an old config keeps
|
|
650
|
+
// its one-money-row-per-figure shape.
|
|
651
|
+
const hint: LayoutHint = {
|
|
652
|
+
...layout,
|
|
653
|
+
hasLifetimeRow: fields.some((field) => canonicalField(field) === "lifetime"),
|
|
654
|
+
};
|
|
648
655
|
const persist = hint.persist === true;
|
|
649
656
|
const placeholder = hint.placeholder ?? DEFAULT_PLACEHOLDER;
|
|
650
657
|
const labelWidth = hint.labelWidth ?? DEFAULT_LABEL_WIDTH;
|
|
651
658
|
const rows: string[] = [];
|
|
652
659
|
for (const field of fields) {
|
|
653
|
-
//
|
|
660
|
+
// The renderer canonicalizes internally; the original spelling is kept so
|
|
661
|
+
// an alias still draws its old label byte-for-byte.
|
|
654
662
|
const name = canonicalField(field);
|
|
655
|
-
const line = statLine(
|
|
663
|
+
const line = statLine(field, source, hint);
|
|
656
664
|
if (line !== undefined) {
|
|
657
665
|
rows.push(line);
|
|
658
666
|
continue;
|
package/src/tui/session-reads.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// Coercion of untrusted values happens through ./coerce.js.
|
|
9
9
|
|
|
10
10
|
import type { Plugin } from "@opencode/plugin/tui";
|
|
11
|
+
import { SETTLED_TOOL, readToolCall } from "./caution.js";
|
|
11
12
|
import { createActiveTime } from "./session-elapsed.js";
|
|
12
13
|
import { asCount, asRecord, asText, type SessionLike } from "./coerce.js";
|
|
13
14
|
import { turnKey, type ThroughputSpan } from "./stats.js";
|
|
@@ -487,13 +488,57 @@ export function createSessionReads(context: Plugin.Context) {
|
|
|
487
488
|
}
|
|
488
489
|
};
|
|
489
490
|
|
|
490
|
-
//
|
|
491
|
-
//
|
|
492
|
-
//
|
|
493
|
-
//
|
|
491
|
+
// A turn is open while a user prompt is waiting for its reply, or while the
|
|
492
|
+
// newest assistant message has not recorded a completion. This is the only
|
|
493
|
+
// honest clock for the silent-turn rule: the host's `running` flag can go
|
|
494
|
+
// stale, but an open turn cannot be mistaken for a closed one.
|
|
495
|
+
const openTurnOf = (sessionID: string): boolean => {
|
|
496
|
+
const messages = messagesOf(sessionID);
|
|
497
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
498
|
+
const message = asRecord(messages[index]);
|
|
499
|
+
const type = asText(message?.["type"]);
|
|
500
|
+
// System, shell and switch records are not turns; walk past them.
|
|
501
|
+
if (type !== "user" && type !== "assistant") continue;
|
|
502
|
+
if (type === "user") return true;
|
|
503
|
+
return asCount(asRecord(message?.["time"])?.["completed"]) === undefined;
|
|
504
|
+
}
|
|
505
|
+
return false;
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
// A person is being asked something: a pending permission request, or a live
|
|
509
|
+
// `question` tool. Both outrank the spinner — the session cannot move until
|
|
510
|
+
// someone answers.
|
|
511
|
+
const pausedOf = (sessionID: string): boolean => {
|
|
512
|
+
if (permsOf(sessionID) !== undefined) return true;
|
|
513
|
+
for (const part of recentParts(sessionID)) {
|
|
514
|
+
const call = readToolCall(part);
|
|
515
|
+
if (call !== undefined && call.name === "question" && !SETTLED_TOOL.has(call.status)) return true;
|
|
516
|
+
}
|
|
517
|
+
return false;
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
// Real evidence of work: a live tool, a running shell, a running child, or an
|
|
521
|
+
// open turn. A `running` status on its own is not evidence — that flag goes
|
|
522
|
+
// stale when a turn closes without the host clearing it, and reading it as
|
|
523
|
+
// work kept the caution clock running on an idle session. Returns
|
|
524
|
+
// `undefined` only when the host said nothing at all and no evidence exists.
|
|
494
525
|
const busy = (sessionID: string): boolean | undefined => {
|
|
495
526
|
const status = statusOf(sessionID);
|
|
496
|
-
|
|
527
|
+
|
|
528
|
+
try {
|
|
529
|
+
for (const part of recentParts(sessionID)) {
|
|
530
|
+
const call = readToolCall(part);
|
|
531
|
+
if (call !== undefined && !SETTLED_TOOL.has(call.status)) return true;
|
|
532
|
+
}
|
|
533
|
+
} catch {
|
|
534
|
+
// Unreadable parts just mean no tool evidence.
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
try {
|
|
538
|
+
if (shellsOf(sessionID).some((entry) => asRecord(entry)?.["status"] === "running")) return true;
|
|
539
|
+
} catch {
|
|
540
|
+
// Unreadable shells just mean no shell signal.
|
|
541
|
+
}
|
|
497
542
|
|
|
498
543
|
try {
|
|
499
544
|
for (const id of context.data.session.family(sessionID) ?? []) {
|
|
@@ -505,15 +550,11 @@ export function createSessionReads(context: Plugin.Context) {
|
|
|
505
550
|
}
|
|
506
551
|
}
|
|
507
552
|
} catch {
|
|
508
|
-
// No subagent status on this host; the
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
try {
|
|
512
|
-
if (shellsOf(sessionID).some((entry) => asRecord(entry)?.["status"] === "running")) return true;
|
|
513
|
-
} catch {
|
|
514
|
-
// Unreadable shells just mean no shell signal.
|
|
553
|
+
// No subagent status on this host; the other signals still apply.
|
|
515
554
|
}
|
|
516
555
|
|
|
556
|
+
if (openTurnOf(sessionID)) return true;
|
|
557
|
+
// A stale `running` with no evidence reads idle, not busy.
|
|
517
558
|
return status === undefined ? undefined : false;
|
|
518
559
|
};
|
|
519
560
|
|
|
@@ -608,6 +649,8 @@ export function createSessionReads(context: Plugin.Context) {
|
|
|
608
649
|
shellsOf,
|
|
609
650
|
lastActivity,
|
|
610
651
|
permsOf,
|
|
652
|
+
openTurnOf,
|
|
653
|
+
pausedOf,
|
|
611
654
|
busy,
|
|
612
655
|
};
|
|
613
656
|
}
|
package/src/tui/stat-fields.ts
CHANGED
|
@@ -40,11 +40,18 @@ export interface StatSource {
|
|
|
40
40
|
*/
|
|
41
41
|
readonly sessionId?: unknown;
|
|
42
42
|
readonly tree?: unknown;
|
|
43
|
+
/**
|
|
44
|
+
* The durable high-water family figure for the lifetime row, when the host's
|
|
45
|
+
* current `tree` has shrunk. Untrusted like every other field.
|
|
46
|
+
*/
|
|
47
|
+
readonly lifetime?: unknown;
|
|
43
48
|
readonly context?: unknown;
|
|
44
49
|
readonly project?: unknown;
|
|
45
50
|
readonly status?: unknown;
|
|
46
51
|
/** True when anything is working: this session, a subagent, or a shell. */
|
|
47
52
|
readonly busy?: unknown;
|
|
53
|
+
/** True when a permission or a question tool is waiting on the person. */
|
|
54
|
+
readonly paused?: unknown;
|
|
48
55
|
readonly perms?: unknown;
|
|
49
56
|
/**
|
|
50
57
|
* Session generation speed: the figures the reader hands over.
|
|
@@ -90,8 +97,8 @@ export const STAT_FIELDS = [
|
|
|
90
97
|
"agent",
|
|
91
98
|
"model",
|
|
92
99
|
"branch",
|
|
93
|
-
"
|
|
94
|
-
"
|
|
100
|
+
"spend",
|
|
101
|
+
"lifetime",
|
|
95
102
|
"project",
|
|
96
103
|
"tokens",
|
|
97
104
|
"cache",
|
|
@@ -128,23 +135,32 @@ type StatField = (typeof STAT_FIELDS)[number];
|
|
|
128
135
|
export const ANIMATED_FIELDS = ["caution", "status", "elapsed", "tps"] as const;
|
|
129
136
|
|
|
130
137
|
export function isStatField(value: string): value is StatField {
|
|
131
|
-
// `session`
|
|
138
|
+
// `session`, `cost` and `total` are accepted aliases, folded back by
|
|
132
139
|
// `canonicalField`, but kept out of `STAT_FIELDS` on purpose — that array is
|
|
133
|
-
// the config vocabulary echoed in config error messages
|
|
134
|
-
//
|
|
135
|
-
return
|
|
140
|
+
// the canonical config vocabulary echoed in config error messages. The
|
|
141
|
+
// aliases stay accepted forever so no existing config breaks.
|
|
142
|
+
return (
|
|
143
|
+
value === "session" ||
|
|
144
|
+
value === "cost" ||
|
|
145
|
+
value === "total" ||
|
|
146
|
+
STAT_FIELDS.some((field) => field === value)
|
|
147
|
+
);
|
|
136
148
|
}
|
|
137
149
|
|
|
138
150
|
/**
|
|
139
151
|
* The canonical config key for a field name.
|
|
140
152
|
*
|
|
141
|
-
* `session`
|
|
142
|
-
* other name is returned unchanged. The renderers canonicalize their
|
|
143
|
-
* argument at entry, so
|
|
144
|
-
*
|
|
153
|
+
* `session` folds to `ses`, `cost` to `spend`, and `total` to `lifetime`.
|
|
154
|
+
* Every other name is returned unchanged. The renderers canonicalize their
|
|
155
|
+
* field argument at entry, so an alias and its key take the same behavioural
|
|
156
|
+
* path; the caller's original spelling is kept for the label, so an old config
|
|
157
|
+
* still draws the same bytes.
|
|
145
158
|
*/
|
|
146
159
|
export function canonicalField(name: string): string {
|
|
147
|
-
|
|
160
|
+
if (name === "session") return "ses";
|
|
161
|
+
if (name === "cost") return "spend";
|
|
162
|
+
if (name === "total") return "lifetime";
|
|
163
|
+
return name;
|
|
148
164
|
}
|
|
149
165
|
|
|
150
166
|
/**
|
|
@@ -189,13 +205,13 @@ export interface LayoutHint {
|
|
|
189
205
|
*/
|
|
190
206
|
readonly timestamp?: TimestampFormat;
|
|
191
207
|
/**
|
|
192
|
-
* True when the rail already draws a `total`
|
|
208
|
+
* True when the rail already draws a `lifetime` row (or its `total` alias).
|
|
193
209
|
*
|
|
194
|
-
* The `
|
|
195
|
-
* on the rail already shows it — which makes "
|
|
196
|
-
*
|
|
210
|
+
* The `spend` row merges the subagent total into itself only when nothing
|
|
211
|
+
* else on the rail already shows it — which makes "one money row or two" a
|
|
212
|
+
* property of `sidebar.rows`, not a separate setting to find.
|
|
197
213
|
*/
|
|
198
|
-
readonly
|
|
214
|
+
readonly hasLifetimeRow?: boolean;
|
|
199
215
|
/**
|
|
200
216
|
* Per-row label overrides, keyed by the canonical row name (`ses`, not
|
|
201
217
|
* `session`). Carried here rather than read from config directly so both
|
|
@@ -215,6 +231,23 @@ export interface LayoutHint {
|
|
|
215
231
|
* imports this one.
|
|
216
232
|
*/
|
|
217
233
|
readonly tpsDisplay?: "avg" | "rt" | "both";
|
|
234
|
+
/**
|
|
235
|
+
* Suffix printed after the number on the single-figure `tps` rows (`rt`
|
|
236
|
+
* and `avg`), from `sidebar.tps.label`. Default `"tok/s"`. `both` names
|
|
237
|
+
* its halves itself and ignores this. Structurally typed, never the
|
|
238
|
+
* config's own type: this module must not import config.
|
|
239
|
+
*/
|
|
240
|
+
readonly tpsLabel?: string;
|
|
241
|
+
/** The status row's paused mark, from `glyphs.paused`. Default `‖`. */
|
|
242
|
+
readonly pausedGlyph?: string;
|
|
243
|
+
/**
|
|
244
|
+
* Whether the `tps` row may draw the observed mean time to first token
|
|
245
|
+
* (`1.2s ttft`). Off suppresses that segment in every display mode,
|
|
246
|
+
* including the realtime fallback row shown when no rate can be drawn.
|
|
247
|
+
* Default true. Carried here as the config's boolean, never its own type:
|
|
248
|
+
* like the other hints, this module must not import config.
|
|
249
|
+
*/
|
|
250
|
+
readonly tpsTtft?: boolean;
|
|
218
251
|
/**
|
|
219
252
|
* When true, `statRows` renders one row per named field even when the host
|
|
220
253
|
* has no data for it, using `skeletonValue` (a live-shaped zero) and falling
|
|
@@ -236,7 +269,7 @@ export interface LayoutHint {
|
|
|
236
269
|
}
|
|
237
270
|
|
|
238
271
|
/** Fallback placeholder for a persistent row with no data and no skeleton. */
|
|
239
|
-
export const DEFAULT_PLACEHOLDER = "
|
|
272
|
+
export const DEFAULT_PLACEHOLDER = "0";
|
|
240
273
|
|
|
241
274
|
export const DEFAULT_LABEL_WIDTH = 10;
|
|
242
275
|
export const DEFAULT_SPARK_WIDTH = 12;
|
|
@@ -256,8 +289,8 @@ export const DEFAULT_SPARK_WIDTH = 12;
|
|
|
256
289
|
*/
|
|
257
290
|
export function skeletonValue(field: string, layout: LayoutHint): string | undefined {
|
|
258
291
|
switch (canonicalField(field)) {
|
|
259
|
-
case "
|
|
260
|
-
case "
|
|
292
|
+
case "spend":
|
|
293
|
+
case "lifetime":
|
|
261
294
|
case "project":
|
|
262
295
|
return formatCost(0);
|
|
263
296
|
case "tokens":
|
|
@@ -270,9 +303,13 @@ export function skeletonValue(field: string, layout: LayoutHint): string | undef
|
|
|
270
303
|
return "0 waiting";
|
|
271
304
|
case "elapsed":
|
|
272
305
|
return formatDuration(0, layout.durationStyle);
|
|
273
|
-
case "tps":
|
|
274
|
-
//
|
|
275
|
-
|
|
306
|
+
case "tps": {
|
|
307
|
+
// Same zero the row itself draws: an absent rate is a measured zero,
|
|
308
|
+
// never a placeholder. Kept here for callers that ask for a skeleton
|
|
309
|
+
// directly, even though the row now always renders one.
|
|
310
|
+
const label = layout.tpsLabel ?? "tok/s";
|
|
311
|
+
return layout.tpsDisplay === "both" ? `0 rt · 0 avg` : `0 ${label}`;
|
|
312
|
+
}
|
|
276
313
|
case "spark":
|
|
277
314
|
return "▁".repeat(Math.max(0, Math.floor(layout.sparkWidth ?? DEFAULT_SPARK_WIDTH)));
|
|
278
315
|
case "reasoning":
|