oc-flight-deck 0.19.2 → 0.20.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/src/tui/rows.ts CHANGED
@@ -448,15 +448,47 @@ export function statLine(
448
448
  return row("elapsed", formatDuration(ms, layout.durationStyle));
449
449
  }
450
450
  case "tps": {
451
- const tps = asCount(source.tps);
452
- if (tps === undefined) return undefined;
453
- // Whole tokens/second, honestly rounded: the value is already an EWMA of
454
- // per-poll deltas, so a decimal would fake a precision the samples never
455
- // had. Anything below half a token/second hides rather than printing
456
- // "0 tok/s".
457
- const rounded = Math.round(tps);
458
- if (rounded <= 0) return undefined;
459
- return row("tps", `${rounded} tok/s`);
451
+ // The triple the reader hands over: `rt` the realtime estimate from
452
+ // the host's streaming delta events, `avg` the settled-turn average,
453
+ // `ttft` the mean time to first token in seconds — all unknown at this
454
+ // boundary, so all re-coerced like every other field. Which one draws
455
+ // is `layout.tpsDisplay` (the row's view of `sidebar.tps.display`,
456
+ // default `"avg"`); presentation.ts feeds it from the resolved config.
457
+ const pair = asRecord(source.tps);
458
+ const rt = asCount(pair?.["rt"]);
459
+ const avg = asCount(pair?.["avg"]);
460
+ const ttft = asCount(pair?.["ttft"]);
461
+ const display = layout.tpsDisplay ?? "avg";
462
+ if (display === "rt") {
463
+ // Whole tokens/second, honestly rounded — the value is already an
464
+ // EWMA over estimated delta samples, so a decimal would fake a
465
+ // precision the samples never had. Anything below half a
466
+ // token/second hides rather than printing "0 tok/s".
467
+ const rounded = rt === undefined ? undefined : Math.round(rt);
468
+ if (rounded === undefined || rounded <= 0) return undefined;
469
+ return row("tps", `${rounded} tok/s`);
470
+ }
471
+ if (display === "both") {
472
+ // Both figures on one line when the average stands — the realtime
473
+ // half may round to zero while the average stands (`0 rt · 41 avg`).
474
+ // The mean time to first token rides along only once observed
475
+ // (`83 rt · 38 avg · 1.2s ttft`); unknown is omitted, never zeroed.
476
+ // The realtime-alone degrade is only for a missing average; a present
477
+ // average that rounds to zero hides the whole row, like the avg
478
+ // mode's own hide rule. Without either figure there is no row.
479
+ if (avg !== undefined) {
480
+ if (Math.round(avg) <= 0) return undefined;
481
+ const head = `${rt === undefined ? 0 : Math.round(rt)} rt · ${Math.round(avg)} avg`;
482
+ return ttft === undefined ? row("tps", head) : row("tps", `${head} · ${ttft.toFixed(1)}s ttft`);
483
+ }
484
+ if (rt !== undefined && Math.round(rt) > 0) return row("tps", `${Math.round(rt)} rt`);
485
+ return undefined;
486
+ }
487
+ // The default: the settled-turn average over the scope, honestly
488
+ // rounded. The hide rule is the realtime row's own: at or below half a
489
+ // token/second it hides rather than printing "0 tok/s".
490
+ if (avg === undefined || Math.round(avg) <= 0) return undefined;
491
+ return row("tps", `${Math.round(avg)} tok/s`);
460
492
  }
461
493
  case "spark": {
462
494
  const values = Array.isArray(source.spark) ? source.spark.map((value) => asCount(value) ?? 0) : [];
@@ -1,12 +1,17 @@
1
- // Session throughput, measured from the host's own message timestamps and never
2
- // from a clock this process keeps - as a near-instantaneous output rate, not a
3
- // lifetime average.
1
+ // Session throughput, measured from the host's own streaming events and its
2
+ // own message timestamps — never from a clock this process keeps — as a
3
+ // realtime estimate, and as the settled-turn average that estimate complements.
4
4
  //
5
- // Each poll feeds cumulative generation tokens and cumulative generating
6
- // milliseconds into the EWMA tracker (`./throughput.js`): the rate is the
7
- // DELTA between successive polls, smoothed (alpha 0.3) and repainted only on
8
- // a move of >= 1 tok/s or >= 10%, so the row tracks live decoding instead of
9
- // sagging behind everything ever produced. The numerator is generation
5
+ // `rt` is the realtime figure from ./realtime-tps.js: it estimates tokens from
6
+ // the host's `session.text.delta` / `session.reasoning.delta` events, because
7
+ // a poll of `session.message.list` can only see a turn's tokens after it
8
+ // settles. It reads fresh on every render — no cache here — and 0 while
9
+ // nothing streams. `avg` is the settled-turn average: generation tokens over
10
+ // assistant turns that recorded `streamed`, divided by the union of their
11
+ // `streamed - created` spans — the whole scope's mean decoding speed, which
12
+ // holds steady through idle gaps instead of reading zero between turns. An
13
+ // in-flight turn (no `streamed` yet) enters neither side of the average. The
14
+ // numerator is generation
10
15
  // tokens - output plus reasoning, which keeps its own row too - and the
11
16
  // denominator is generating time only: the union of the streaming spans in
12
17
  // scope. The scope is `sidebar.tps.scope` (`./config.js`): `"family"` (the
@@ -14,16 +19,9 @@
14
19
  // generation tokens across the whole family over the UNION of all their
15
20
  // spans, so concurrent decoders share wall clock instead of adding it; a
16
21
  // root that has gone idle while its child is still decoding still reads
17
- // live. `"session"` restores the per-session figure: the displayed session's
18
- // own tokens over its own spans, reading zero whenever its own generating
19
- // time does not advance, even while a child still runs. The idle test is the
20
- // denominator's delta either way: when the generating time in scope does not
21
- // advance between polls, nothing in scope is generating right now, so the
22
- // reader reports zero — idle means no tokens per second are being produced.
23
- // The first poll for a session only sets the tracker's baselines and reads
24
- // as zero — no rate is known yet, and the cumulative lifetime average never
25
- // seeds the figure, so a session deep into its life must not flash its
26
- // history as if it were live.
22
+ // realtime. `"session"` restores the per-session figure: the displayed
23
+ // session's own samples alone, reading zero whenever it stops streaming, even
24
+ // while a child still runs.
27
25
  //
28
26
  // The capability is learned once and remembered for the process. `undefined`
29
27
  // means "not yet known": a read that failed, or carried no assistant turns,
@@ -34,26 +32,28 @@
34
32
  // not keyed by session.
35
33
  //
36
34
  // The rail re-runs on the fast tick, and walking the session's messages on
37
- // every tick would repeat the same work fifty times a second, so the result
35
+ // every tick would repeat the same work fifty times a second, so the average
38
36
  // is held briefly. Zero is cached too: an idle session must not be re-derived
39
- // on each tick either.
37
+ // on each tick either. The realtime figure takes no part in that cache: it is
38
+ // estimated from events that arrive between renders, so it is read fresh on
39
+ // every render and would go stale behind a 1s hold.
40
40
  //
41
41
  // One factory closes over the plugin `context`. The math itself lives in
42
- // ./throughput.js (pure).
42
+ // ./throughput.js (settled spans, EWMA, hysteresis) and ./realtime-tps.js
43
+ // (delta-event samples).
43
44
 
44
45
  import type { Plugin } from "@opencode/plugin/tui";
45
46
  import { asCount, asRecord, type SessionLike } from "./coerce.js";
46
47
  import { DEFAULT_TPS_SCOPE, type TpsScope } from "./config.js";
48
+ import { createRealtimeTps, type RealtimeTps } from "./realtime-tps.js";
47
49
  import {
48
- createInstantTps,
50
+ settledAverageRate,
49
51
  turnKey,
50
52
  turnSpan,
51
- unionGenerationTotals,
52
- unionSpanMs,
53
53
  type ThroughputSpan,
54
54
  } from "./stats.js";
55
55
 
56
- /** What one session's message list contributes to its instantaneous rate. */
56
+ /** What one session's message list contributes to the settled-turn average. */
57
57
  interface TpsScan {
58
58
  /** False only when the host refused to list the session's messages. */
59
59
  readonly ok: boolean;
@@ -61,8 +61,15 @@ interface TpsScan {
61
61
  readonly assistant: number;
62
62
  /** Assistant turns that carried any usable timestamp, which proves the host stamps. */
63
63
  readonly stamped: number;
64
- /** Spans for turns that carried a usable `created` start. */
65
- readonly spans: readonly ThroughputSpan[];
64
+ /**
65
+ * The settled-turn average's own spans: turns that carried a usable
66
+ * `created` start AND recorded `streamed`. An in-flight turn has no
67
+ * decoding end yet, so it stays out of the numerator and the denominator
68
+ * together — partial work never dilutes or inflates the mean. With
69
+ * `streamed` recorded the span already ends there (clamped), so each entry
70
+ * is the same object the old `spans` list carried; only membership differs.
71
+ */
72
+ readonly settled: readonly ThroughputSpan[];
66
73
  }
67
74
 
68
75
  /**
@@ -70,7 +77,7 @@ interface TpsScan {
70
77
  * clock (how much generating time is on record?) is the denominator for a host
71
78
  * with no message timestamps — that clock already covers the scope, so it is
72
79
  * borrowed as-is. It comes from ./session-reads.js; absent, the stamped path
73
- * still works and the unstamped path reads as zero for lack of time. There is
80
+ * still works and the unstamped path reads as unknown for lack of time. There is
74
81
  * deliberately no busy gate here: idleness is read off the session's own
75
82
  * generating-time delta, never off a family-wide flag.
76
83
  */
@@ -78,35 +85,20 @@ export interface TpsLiveReads {
78
85
  readonly elapsedMsOf?: (sessionID: string, now: number) => number | undefined;
79
86
  }
80
87
 
81
- export function createTpsReader(context: Plugin.Context, live?: TpsLiveReads, scope: TpsScope = DEFAULT_TPS_SCOPE) {
88
+ export function createTpsReader(
89
+ context: Plugin.Context,
90
+ live?: TpsLiveReads,
91
+ scope: TpsScope = DEFAULT_TPS_SCOPE,
92
+ realtime?: RealtimeTps,
93
+ ) {
82
94
  const TPS_CACHE_MS = 1_000;
83
95
  let hostStamps: boolean | undefined;
84
- let tpsCache: { readonly sessionID: string; readonly at: number; readonly value: number } | undefined;
85
- // One EWMA tracker per displayed session, bounded: without eviction a TUI
86
- // lifetime of session-hopping grows this map forever. Eviction only drops
87
- // smoothing - a revisit restarts its baselines, exactly like a first sight.
88
- // Recency refreshes on every poll, so the watched session is always the last
89
- // one evicted.
90
- const MAX_TRACKERS = 50;
91
- const trackers = new Map<string, ReturnType<typeof createInstantTps>>();
92
-
93
- const trackerOf = (sessionID: string): ReturnType<typeof createInstantTps> => {
94
- const known = trackers.get(sessionID);
95
- if (known !== undefined) {
96
- trackers.delete(sessionID);
97
- trackers.set(sessionID, known);
98
- return known;
99
- }
100
- const fresh = createInstantTps();
101
- if (trackers.size >= MAX_TRACKERS) {
102
- for (const oldest of trackers.keys()) {
103
- trackers.delete(oldest);
104
- break;
105
- }
106
- }
107
- trackers.set(sessionID, fresh);
108
- return fresh;
109
- };
96
+ let tpsCache: { readonly sessionID: string; readonly at: number; readonly avg: number | undefined } | undefined;
97
+ // The realtime figure's own subscriptions. A caller that already owns one
98
+ // (the plugin setup, which wires disposal) passes it in; tests that only
99
+ // pin the average get the degraded tracker — no `data.on` on their stub
100
+ // context, so `rt` reads 0 and the average asserts alone.
101
+ const tracker = realtime ?? createRealtimeTps(context);
110
102
 
111
103
  const scanMessages = (id: string, now: number): TpsScan => {
112
104
  let messages: readonly unknown[];
@@ -114,9 +106,9 @@ export function createTpsReader(context: Plugin.Context, live?: TpsLiveReads, sc
114
106
  messages = context.data.session.message.list(id) ?? [];
115
107
  } catch {
116
108
  // A refused read is not "this host has no messages".
117
- return { ok: false, assistant: 0, stamped: 0, spans: [] };
109
+ return { ok: false, assistant: 0, stamped: 0, settled: [] };
118
110
  }
119
- const spans: ThroughputSpan[] = [];
111
+ const settled: ThroughputSpan[] = [];
120
112
  let assistant = 0;
121
113
  let stamped = 0;
122
114
  for (const entry of messages) {
@@ -141,16 +133,21 @@ export function createTpsReader(context: Plugin.Context, live?: TpsLiveReads, sc
141
133
  // sharing a start but differing in reasoning stay distinct.
142
134
  const output = tokens?.["output"];
143
135
  const reasoning = tokens?.["reasoning"];
144
- const settled = completed !== undefined || streamed !== undefined;
136
+ const settledTurn = completed !== undefined || streamed !== undefined;
145
137
  const key = turnKey(message["id"], created, completed, output, streamed);
146
- spans.push({
147
- key: settled ? `${key}:${asCount(reasoning) ?? "?"}` : key,
138
+ const turn: ThroughputSpan = {
139
+ key: settledTurn ? `${key}:${asCount(reasoning) ?? "?"}` : key,
148
140
  tokens: output,
149
141
  reasoning,
150
142
  ...span,
151
- });
143
+ };
144
+ // Only a turn that recorded `streamed` has a decoding end: without it
145
+ // the turn is still in flight (or settled only its tools), and it stays
146
+ // out of the average entirely. The span above already ends at `streamed`
147
+ // when it is recorded, so the same entry serves the average directly.
148
+ if (streamed !== undefined) settled.push(turn);
152
149
  }
153
- return { ok: true, assistant, stamped, spans };
150
+ return { ok: true, assistant, stamped, settled };
154
151
  };
155
152
 
156
153
  // The displayed session plus every id `family()` returns for it — the same
@@ -170,15 +167,15 @@ export function createTpsReader(context: Plugin.Context, live?: TpsLiveReads, sc
170
167
  return ids;
171
168
  };
172
169
 
173
- // Generation spans for the whole family scope: every member's own spans,
174
- // keyed per member so two sessions' id-less turns sharing a start stay
175
- // distinct. The union downstream merges their overlaps — concurrent
176
- // decoders share wall clock, so it is never summed.
170
+ // Settled spans for the whole family scope: every member's own spans, keyed
171
+ // per member so two sessions' id-less turns sharing a start stay distinct.
172
+ // The union downstream merges their overlaps — concurrent decoders share
173
+ // wall clock, so it is never summed.
177
174
  const scanScope = (ids: readonly string[], now: number): TpsScan => {
178
175
  let ok = true;
179
176
  let assistant = 0;
180
177
  let stamped = 0;
181
- const spans: ThroughputSpan[] = [];
178
+ const settled: ThroughputSpan[] = [];
182
179
  for (const id of ids) {
183
180
  const scan = scanMessages(id, now);
184
181
  // A refused read is not "this member has no messages": one failure
@@ -186,9 +183,9 @@ export function createTpsReader(context: Plugin.Context, live?: TpsLiveReads, sc
186
183
  ok = ok && scan.ok;
187
184
  assistant += scan.assistant;
188
185
  stamped += scan.stamped;
189
- for (const span of scan.spans) spans.push({ ...span, key: `${id} ${String(span.key)}` });
186
+ for (const span of scan.settled) settled.push({ ...span, key: `${id} ${String(span.key)}` });
190
187
  }
191
- return { ok, assistant, stamped, spans };
188
+ return { ok, assistant, stamped, settled };
192
189
  };
193
190
 
194
191
  // Generation tokens on record for the session: its own record's `output`
@@ -202,8 +199,8 @@ export function createTpsReader(context: Plugin.Context, live?: TpsLiveReads, sc
202
199
  // Generation tokens on record for the whole family scope: the displayed
203
200
  // session's own rungs plus every member's. One unreadable member must not
204
201
  // blank the rest of the tree — but the total is then incomplete, so the
205
- // walk reports it and the caller holds the tracker's baselines instead of
206
- // feeding the partial figure in.
202
+ // walk reports it and the average stays unknown rather than dividing a
203
+ // partial figure.
207
204
  const familyGeneration = (
208
205
  sessionID: string,
209
206
  session: SessionLike | undefined,
@@ -222,7 +219,25 @@ export function createTpsReader(context: Plugin.Context, live?: TpsLiveReads, sc
222
219
  return { ok, generation };
223
220
  };
224
221
 
225
- const computeTps = (sessionID: string, session: SessionLike | undefined): number | undefined => {
222
+ /**
223
+ * Both figures for one displayed session: the realtime estimate and the
224
+ * settled-turn average.
225
+ *
226
+ * `rt` is the delta-event figure, `0` while nothing streams or on a host
227
+ * with no subscription surface. `avg` is the settled-turn mean over the
228
+ * same scope — generation tokens over turns that recorded `streamed`,
229
+ * divided by the union of their spans — and `undefined` when no settled
230
+ * turn exists, so the row hides rather than inventing a rate. `ttft` is
231
+ * the mean time to first token over the same scope, in seconds, and
232
+ * `undefined` while no step with a first delta is on record.
233
+ */
234
+ interface TpsFigures {
235
+ readonly rt: number;
236
+ readonly avg: number | undefined;
237
+ readonly ttft?: number | undefined;
238
+ }
239
+
240
+ const computeAvg = (sessionID: string, session: SessionLike | undefined): number | undefined => {
226
241
  const time = asRecord(session?.time);
227
242
  const created = asCount(time?.["created"]);
228
243
 
@@ -232,7 +247,7 @@ export function createTpsReader(context: Plugin.Context, live?: TpsLiveReads, sc
232
247
  // `"family"`, this session's own spans only under `"session"`.
233
248
  const scan: TpsScan =
234
249
  hostStamps === false
235
- ? { ok: true, assistant: 0, stamped: 0, spans: [] }
250
+ ? { ok: true, assistant: 0, stamped: 0, settled: [] }
236
251
  : scope === "family"
237
252
  ? scanScope(familyIds(sessionID), now)
238
253
  : scanMessages(sessionID, now);
@@ -246,62 +261,79 @@ export function createTpsReader(context: Plugin.Context, live?: TpsLiveReads, sc
246
261
  else return undefined;
247
262
  }
248
263
 
249
- const tracker = trackerOf(sessionID);
250
264
  if (hostStamps === true) {
251
- // A refused member read leaves an incomplete cumulative total: feeding
252
- // it in would move the baselines, and the member's history would return
253
- // as a spike on recovery. The poll reads as zero with the baselines
254
- // held, so the next healthy poll divides only what is genuinely new.
265
+ // A refused member read leaves an incomplete cumulative total, so the
266
+ // average stays unknown rather than dividing partial spans (which
267
+ // would undercount time and inflate the mean).
255
268
  // `"session"` never takes this branch: its single read keeps the
256
269
  // pre-change behaviour byte-identically.
257
- if (scope === "family" && scan.ok === false) return 0;
258
- // Generating time is the union of the turns' spans in scope: idle
259
- // between turns was never recorded, so it can never enter the rate. An
260
- // in-flight turn ends at now, so the denominator keeps pace with the
261
- // decoder while work happens and freezes the instant it settles. The
262
- // numerator over it is generation: output plus reasoning.
263
- const { tokens } = unionGenerationTotals(scan.spans);
264
- const genMs = unionSpanMs(scan.spans);
265
- return tracker(tokens, genMs);
270
+ if (scope === "family" && scan.ok === false) return undefined;
271
+ // The average over the same scope needs no baselines: settled turns
272
+ // already divide on the first poll. In-flight turns never entered
273
+ // `settled`, so no second filter is needed here.
274
+ return settledAverageRate(scan.settled);
266
275
  }
267
276
 
268
277
  // No timestamps on this host: the denominator is the active clock, which
269
278
  // already covers the family scope (it IS the `elapsed` figure), so it is
270
279
  // borrowed as-is. Without that clock there is no honest denominator
271
- // - the row reads as zero rather than falling back to a lifetime average
272
- // that bills idle as work.
280
+ // - the average stays unknown rather than falling back to a lifetime
281
+ // average that bills idle as work.
273
282
  const family = scope === "family" ? familyGeneration(sessionID, session) : undefined;
274
283
  // As on the stamped path: one unreadable member leaves the total
275
- // incomplete, so the poll reads as zero with the baselines held.
276
- if (family !== undefined && family.ok === false) return 0;
284
+ // incomplete, so the average stays unknown rather than dividing a partial
285
+ // numerator.
286
+ if (family !== undefined && family.ok === false) return undefined;
277
287
  const generation = family?.generation ?? recordGeneration(session);
278
288
  // The creation-time gate is the `"session"` scope's alone: without a
279
289
  // stamp there is no clock to borrow. Under `"family"` the displayed
280
290
  // session may carry no stamp while a child still paces off the
281
291
  // family-wide active clock, so the gate must not silence it.
282
- if (created === undefined && scope === "session") return tracker(recordGeneration(session), 0);
292
+ if (created === undefined && scope === "session") {
293
+ return undefined;
294
+ }
283
295
  let genMs = 0;
284
296
  try {
285
297
  genMs = live?.elapsedMsOf?.(sessionID, now) ?? 0;
286
298
  } catch {
287
299
  genMs = 0;
288
300
  }
289
- return tracker(generation, genMs);
301
+ // No per-turn stamps here, so the average is the generation count over
302
+ // the same borrowed active clock, in seconds — and no clock means no
303
+ // average, never a wall-clock lifetime figure.
304
+ return genMs > 0 ? generation / (genMs / 1_000) : undefined;
290
305
  };
291
306
 
292
307
  // The reader never answers `undefined` for a session it was asked about: a
293
- // session that is not generating reads as zero immediately — its generating
294
- // time is not advancing, so the tracker reports zero — and a session with no
295
- // figure yet reads as zero too. (The row itself hides a zero; that decision
308
+ // session that is not streaming reads zero immediately, and a session with
309
+ // no figure yet reads zero too. The average is the exception that proves
310
+ // the rule: unknown stays unknown, so the row hides rather than drawing a
311
+ // zero it cannot stand behind. (The row itself hides a zero; that decision
296
312
  // lives in ./rows.js.)
297
- const sessionTps = (sessionID: string, session: SessionLike | undefined): number => {
313
+ const sessionTps = (sessionID: string, session: SessionLike | undefined): TpsFigures => {
314
+ // The realtime figures are estimated from events that arrive between
315
+ // renders: they read fresh on every render and take no part in the cache
316
+ // below, which holds the settled-average scan alone.
317
+ const ids = scope === "family" ? familyIds(sessionID) : [sessionID];
318
+ let rt = 0;
319
+ try {
320
+ rt = tracker.rate(sessionID, ids);
321
+ } catch {
322
+ rt = 0;
323
+ }
324
+ let ttft: number | undefined;
325
+ try {
326
+ ttft = tracker.ttft(ids);
327
+ } catch {
328
+ ttft = undefined;
329
+ }
298
330
  const cached = tpsCache;
299
331
  if (cached !== undefined && cached.sessionID === sessionID && Date.now() - cached.at < TPS_CACHE_MS) {
300
- return cached.value;
332
+ return { rt, avg: cached.avg, ttft };
301
333
  }
302
- const value = computeTps(sessionID, session) ?? 0;
303
- tpsCache = { sessionID, at: Date.now(), value };
304
- return value;
334
+ const avg = computeAvg(sessionID, session);
335
+ tpsCache = { sessionID, at: Date.now(), avg };
336
+ return { rt, avg, ttft };
305
337
  };
306
338
 
307
339
  return { sessionTps };
@@ -39,11 +39,15 @@ export interface StatSource {
39
39
  readonly busy?: unknown;
40
40
  readonly perms?: unknown;
41
41
  /**
42
- * Session output rate, drawn whole. A near-instantaneous figure: the delta
43
- * of output tokens between successive polls over the delta of generating
44
- * time (streaming spans, or the busy-gated active clock), smoothed and held
45
- * through noise, frozen while idle, hidden until a minimum sample is on
46
- * record. Derived from state the host already holds.
42
+ * Session generation speed: the figures the reader hands over.
43
+ *
44
+ * `rt` is the realtime estimate from the host's streaming delta events
45
+ * (zero while nothing streams), `avg` the settled-turn average over the
46
+ * same scope (`undefined` when no settled turn exists), `ttft` the mean
47
+ * time to first token in seconds (`undefined` while no step with a first
48
+ * delta is on record). All are unknown at this boundary, so the row
49
+ * re-coerces them like every other field. Which one draws is
50
+ * `LayoutHint.tpsDisplay` (default `"avg"`).
47
51
  */
48
52
  readonly tps?: unknown;
49
53
  readonly elapsedMs?: unknown;
@@ -174,6 +178,18 @@ export interface LayoutHint {
174
178
  * its geometry.
175
179
  */
176
180
  readonly labels?: Readonly<Record<string, string>>;
181
+ /**
182
+ * Which figure the `tps` row draws: the settled-turn average (`"avg"`, the
183
+ * default), the realtime estimate from the host's streaming delta events
184
+ * (`"rt"`), or both on one line (`"both"`). Carried here rather than read
185
+ * from config directly so the row stays a pure function of its inputs,
186
+ * exactly like `labels` above.
187
+ *
188
+ * Structurally typed — a string union, never the config's own type: like
189
+ * every other hint here this must not import the config module, which
190
+ * imports this one.
191
+ */
192
+ readonly tpsDisplay?: "avg" | "rt" | "both";
177
193
  /**
178
194
  * When true, `statRows` renders one row per named field even when the host
179
195
  * has no data for it, using `skeletonValue` (a live-shaped zero) and falling
@@ -227,7 +243,10 @@ export function skeletonValue(field: string, layout: LayoutHint): string | undef
227
243
  case "elapsed":
228
244
  return formatDuration(0, layout.durationStyle);
229
245
  case "tps":
230
- return "0 tok/s";
246
+ // The skeleton follows the display mode: `both` draws both figures on
247
+ // one line, the single-figure modes draw the one shape either would
248
+ // read as a zero.
249
+ return layout.tpsDisplay === "both" ? "0 rt · 0 avg" : "0 tok/s";
231
250
  case "spark":
232
251
  return "▁".repeat(Math.max(0, Math.floor(layout.sparkWidth ?? DEFAULT_SPARK_WIDTH)));
233
252
  case "reasoning":
package/src/tui/stats.ts CHANGED
@@ -20,8 +20,7 @@ export type { StatSegment } from "./rows.js";
20
20
  export { ANIMATED_FIELDS, DEFAULT_PLACEHOLDER, STAT_FIELDS, canonicalField, fieldLabel, isStatField, skeletonValue } from "./stat-fields.js";
21
21
  export type { StatSource } from "./stat-fields.js";
22
22
  export {
23
- createInstantTps,
24
- instantTpsRate,
23
+ settledAverageRate,
25
24
  smoothTpsRate,
26
25
  TPS_EWMA_ALPHA,
27
26
  TPS_REPAINT_ABS,
@@ -29,8 +28,15 @@ export {
29
28
  tpsNeedsRepaint,
30
29
  turnKey,
31
30
  turnSpan,
32
- unionGenerationTotals,
33
31
  unionSpanMs,
34
32
  unionSpanTotals,
35
33
  } from "./throughput.js";
36
34
  export type { SpanTotals, ThroughputSpan } from "./throughput.js";
35
+ export {
36
+ createRealtimeTps,
37
+ estimateDeltaTokens,
38
+ RT_MAX_SESSIONS,
39
+ RT_SAMPLE_WINDOW_MS,
40
+ RT_STALE_MS,
41
+ } from "./realtime-tps.js";
42
+ export type { RealtimeTps } from "./realtime-tps.js";