oc-flight-deck 0.8.1 → 0.9.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
@@ -5,7 +5,7 @@
5
5
  **Live session telemetry for your OpenCode terminal.**
6
6
  *The numbers where you're already looking — because your agent is spending money right now.*
7
7
 
8
- ![npm](https://img.shields.io/npm/v/oc-flight-deck) ![license](https://img.shields.io/badge/license-MIT-blue) ![opencode](https://img.shields.io/badge/opencode-V2-compatible-8A2BE2) ![node](https://img.shields.io/badge/node-%E2%89%A522-green)
8
+ ![npm](https://img.shields.io/npm/v/oc-flight-deck) ![license](https://img.shields.io/badge/license-MIT-blue) ![node](https://img.shields.io/badge/node-%E2%89%A522-green) ![downloads](https://img.shields.io/npm/dm/oc-flight-deck) ![check](https://img.shields.io/github/actions/workflow/status/nathwn12/oc-flight-deck/check.yml)
9
9
 
10
10
  </div>
11
11
 
@@ -36,7 +36,7 @@ tokens 533k in · 91k out
36
36
  cache 98% hit · 32M read
37
37
  context ██░░░░░░░░ 18%
38
38
  elapsed 2h 14m 37s
39
- tps 18 tok/s
39
+ tps 18.0 tok/s
40
40
  ```
41
41
 
42
42
  Every row is read from the open session at render time — except `caution`, which watches a clock rather than events (a hang emits none); `elapsed`, which is seeded once from the session's own recorded assistant turn spans and then accumulates the busy windows this run observes, rather than a value the session reports; and the opt-in `guard` row, which is polled from the local guard RPC.
@@ -58,7 +58,7 @@ The panel's only fixed text — `▸ FLIGHT DECK` over a separator — is **opt-
58
58
  | `context` | A gauge of how full the window is |
59
59
  | `perms` | What is waiting for approval, not just how many |
60
60
  | `elapsed` | Active time — the clock runs only while this session, a subagent in its tree, or one of its shells is working, and freezes when everything settles. It is seeded once from the assistant turn spans the host already recorded for that session, so it survives a restart instead of resetting to `—`; work observed live after that keeps counting in memory. It measures active time, not wall-clock since the session began |
61
- | `tps` | Average speed **while working**: output tokens divided by the time the assistant's turns actually ran, subagents included. Idle time between turns is never counted, so the figure freezes when everything settles instead of decaying or hiding; a turn still in flight counts up to now. On a host that exposes no per-message timestamps it falls back to the lifetime average, which includes idle and can therefore sag. Not configurable |
61
+ | `tps` | Average speed **while streaming**: output **plus reasoning** tokens divided by the time the provider was actively streaming (`streamed - created`), subagents included. Idle time between turns and the tool settlement after a turn are never counted, so the figure freezes when everything settles instead of decaying or hiding; a turn still in flight counts up to now. On a host that exposes no per-message timestamps it falls back to the lifetime average, which includes idle and can therefore sag. Not configurable |
62
62
  | `spark` | Recent turn sizes as a shape · **off by default** |
63
63
  | `reasoning` | Reasoning tokens, when the model emits them · **off by default** |
64
64
  | `turns` | How many prompts you've sent this session · **off by default** |
@@ -104,13 +104,14 @@
104
104
  // assistant turn spans the host already recorded, so it
105
105
  // survives a restart instead of resetting; work observed live
106
106
  // after that keeps counting in memory
107
- // tps average speed while working: output tokens divided by the
108
- // time the assistant's turns actually ran, subagents included.
109
- // Idle between turns is never counted, so the figure freezes
110
- // when everything settles rather than decaying or hiding; a
111
- // turn still in flight counts up to now. On a host with no
112
- // per-message timestamps it falls back to the lifetime
113
- // average, which includes idle and can sag
107
+ // tps average speed while streaming: output plus reasoning tokens
108
+ // divided by the time the provider was actively streaming
109
+ // (streamed minus created), subagents included. Idle between
110
+ // turns and the tool settlement after one are never counted,
111
+ // so the figure freezes when everything settles rather than
112
+ // decaying or hiding; a turn still in flight counts up to now.
113
+ // On a host with no per-message timestamps it falls back to
114
+ // the lifetime average, which includes idle and can sag
114
115
  // spark recent turn sizes as a sparkline
115
116
  // reasoning reasoning tokens, when the model emits them
116
117
  // turns how many prompts you have sent this session
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oc-flight-deck",
3
- "version": "0.8.1",
3
+ "version": "0.9.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",
package/src/tui/rows.ts CHANGED
@@ -357,7 +357,9 @@ export function statLine(
357
357
  case "tps": {
358
358
  const tps = asCount(source.tps);
359
359
  if (tps === undefined || tps === 0) return undefined;
360
- return row("tps", `${Math.round(tps)} tok/s`);
360
+ // One decimal, exactly as the official TUI renders it: rounding to a
361
+ // whole number would overstate a slow turn by up to half a token/second.
362
+ return row("tps", `${tps.toFixed(1)} tok/s`);
361
363
  }
362
364
  case "spark": {
363
365
  const values = Array.isArray(source.spark) ? source.spark.map((value) => asCount(value) ?? 0) : [];
@@ -253,7 +253,9 @@ export function createSessionReads(context: Plugin.Context, maxBankedMs?: number
253
253
  const created = asCount(stamp?.["created"]);
254
254
  const completed = asCount(stamp?.["completed"]);
255
255
  const streamed = asCount(stamp?.["streamed"]);
256
- const span = turnSpan(created, completed, streamed, now);
256
+ // `elapsed` ends a settled turn at `completed`: the clock stays busy
257
+ // through the turn's tool settlement, which `streamed` would drop.
258
+ const span = turnSpan(created, completed, streamed, now, "completed");
257
259
  if (span === undefined) continue;
258
260
  const output = asRecord(message["tokens"])?.["output"];
259
261
  spans.push({ key: turnKey(message["id"], created, completed, output), ...span });
@@ -1,9 +1,10 @@
1
1
  // Session throughput, measured from the host's own message timestamps and never
2
2
  // from a clock this process keeps. A host that stamps its assistant turns gets
3
- // an active-work average: output tokens divided by the union of the turns' own
4
- // spans, so idle between turns is not in the denominator and the figure freezes
5
- // once everything settles. A host proven to expose no message timestamps uses
6
- // the lifetime average instead.
3
+ // an active-work average: output plus reasoning tokens divided by the union of
4
+ // the turns' own streaming spans (`streamed - created`, fallbacks in
5
+ // ./throughput.js), so idle between turns and the tool settlement after one are
6
+ // not in the denominator and the figure freezes once everything settles. A host
7
+ // proven to expose no message timestamps uses the lifetime average instead.
7
8
  //
8
9
  // The capability is learned once and remembered for the process. `undefined`
9
10
  // means "not yet known": a read that failed, or carried no assistant turns,
@@ -76,10 +77,18 @@ export function createTpsReader(
76
77
  if (created === undefined && completed === undefined && streamed === undefined) continue;
77
78
  stamped += 1;
78
79
  // Without `created` there is no start; the turn is skipped, not guessed.
79
- const span = turnSpan(created, completed, streamed, now);
80
+ // `tps` ends a turn at `streamed`: decoding stopped is the numerator clock.
81
+ const span = turnSpan(created, completed, streamed, now, "streamed");
80
82
  if (span === undefined) continue;
81
- const output = asRecord(message["tokens"])?.["output"];
82
- spans.push({ key: turnKey(message["id"], created, completed, output), tokens: output, ...span });
83
+ const tokens = asRecord(message["tokens"]);
84
+ // The numerator the TUI divides: output plus reasoning. Both are carried
85
+ // so the union can add them without losing either rung.
86
+ spans.push({
87
+ key: turnKey(message["id"], created, completed, tokens?.["output"]),
88
+ tokens: tokens?.["output"],
89
+ reasoning: tokens?.["reasoning"],
90
+ ...span,
91
+ });
83
92
  }
84
93
  return { ok: true, assistant, stamped, spans };
85
94
  };
@@ -87,7 +96,10 @@ export function createTpsReader(
87
96
  // The lifetime average, the metric of last resort for a host that exposes no
88
97
  // per-message timestamps. Measured from the session's own clock
89
98
  // (`time.updated`, falling back to now) so a finished session settles on a
90
- // stable figure instead of decaying as it sits on screen.
99
+ // stable figure instead of decaying as it sits on screen. The numerator is
100
+ // the session record's `output` plus its `reasoning`, the same pair the
101
+ // stamped path divides: `tokens` is a `TokenUsage.Info`, so the reasoning
102
+ // rung is present and counting output alone would under-report.
91
103
  const lifetimeTps = (
92
104
  sessionID: string,
93
105
  session: SessionLike | undefined,
@@ -99,8 +111,13 @@ export function createTpsReader(
99
111
  const elapsed = end - created;
100
112
  if (elapsed <= 0) return undefined;
101
113
 
102
- const own = asCount(asRecord(session?.tokens)?.["output"]);
103
- let output = own;
114
+ const tokensOf = (source: SessionLike | undefined): number | undefined => {
115
+ const tokens = asRecord(source?.tokens);
116
+ if (tokens === undefined) return undefined;
117
+ return (asCount(tokens["output"]) ?? 0) + (asCount(tokens["reasoning"]) ?? 0);
118
+ };
119
+
120
+ let output = tokensOf(session);
104
121
  // Only a family root owns the tree beneath it; a child asking `family()`
105
122
  // gets its ancestors and siblings too, so it keeps its own figure.
106
123
  if (isFamilyRoot(sessionID)) {
@@ -111,9 +128,9 @@ export function createTpsReader(
111
128
  let sawOne = false;
112
129
  for (const id of ids) {
113
130
  const member = context.data.session.get(id) as SessionLike | undefined;
114
- const out = asCount(asRecord(member?.tokens)?.["output"]);
115
- if (out === undefined) continue;
116
- total += out;
131
+ const memberTokens = tokensOf(member);
132
+ if (memberTokens === undefined) continue;
133
+ total += memberTokens;
117
134
  sawOne = true;
118
135
  }
119
136
  if (sawOne) output = total;
@@ -138,9 +155,10 @@ export function createTpsReader(
138
155
  // instant and the union cannot be skewed by the scans drifting apart.
139
156
  const now = Date.now();
140
157
 
141
- // Timestamped assistant output this session has produced, plus — only from
142
- // a family root — every subagent session's. A child asking `family()` gets
143
- // its ancestors and siblings back, so it keeps its own spans.
158
+ // Timestamped assistant tokens (output + reasoning) this session has
159
+ // produced, plus — only from a family root — every subagent session's. A
160
+ // child asking `family()` gets its ancestors and siblings back, so it keeps
161
+ // its own spans.
144
162
  const scans: TpsScan[] = [scanMessages(sessionID, now)];
145
163
  if (isFamilyRoot(sessionID)) {
146
164
  try {
@@ -31,11 +31,12 @@ export interface StatSource {
31
31
  readonly perms?: unknown;
32
32
  /**
33
33
  * Session throughput. On a host that stamps its messages this is an
34
- * active-work average: output tokens divided by the union of the assistant
35
- * turns' own spans, subagents summed in, so idle between turns is not
36
- * counted and the figure freezes when work stops. On a host without message
37
- * timestamps it falls back to the lifetime average, which can still sag.
38
- * Either way it is derived from state the host already holds.
34
+ * active-work average: output plus reasoning tokens divided by the union of
35
+ * the assistant turns' provider-active spans (`streamed - created`), with
36
+ * idle between turns and the tool settlement after one excluded, subagents
37
+ * summed in, so the figure freezes when work stops. On a host without
38
+ * message timestamps it falls back to the lifetime average, which can still
39
+ * sag. Either way it is derived from state the host already holds.
39
40
  */
40
41
  readonly tps?: unknown;
41
42
  readonly elapsedMs?: unknown;
package/src/tui/stats.ts CHANGED
@@ -23,4 +23,4 @@ export {
23
23
  unionSpanThroughput,
24
24
  unionSpanTotals,
25
25
  } from "./throughput.js";
26
- export type { SpanTotals, ThroughputSpan } from "./throughput.js";
26
+ export type { SpanEndPreference, SpanTotals, ThroughputSpan } from "./throughput.js";
@@ -1,65 +1,93 @@
1
- // Session throughput: output tokens per second, measured over the active work
2
- // the host actually recorded rather than over the wall clock.
1
+ // Session throughput: output and reasoning tokens per second, measured over the
2
+ // provider-active time the host actually recorded rather than over the wall
3
+ // clock.
3
4
  //
4
5
  // Pure: no clock, no I/O, no rendering. Untrusted sample fields are coerced
5
6
  // through ./coerce.js so a garbage value is skipped rather than guessed at.
6
7
  //
7
8
  // Two rates live here. `sessionThroughput` is the whole-lifetime average, kept
8
9
  // as the metric of last resort for a host that exposes no per-message
9
- // timestamps. `unionSpanThroughput` is the active-work average: output tokens
10
- // divided by the union of the assistant turns' own spans, so idle between turns
11
- // is never in the denominator and the figure freezes once everything settles.
10
+ // timestamps. `unionSpanThroughput` is the active-work average: output plus
11
+ // reasoning tokens divided by the union of the assistant turns' own streaming
12
+ // spans, so idle and tool-settlement time is never in the denominator and the
13
+ // figure freezes once everything settles.
12
14
 
13
15
  import { asCount, asText } from "./coerce.js";
14
16
 
15
17
  /**
16
- * Overall session throughput: output tokens over the session's lifetime.
18
+ * Overall session throughput: output plus reasoning tokens over the session's
19
+ * lifetime.
20
+ *
21
+ * `tokens` is the same numerator the active-work average divides — a session
22
+ * record's `tokens` is a `TokenUsage.Info`, so its `reasoning` rung is present
23
+ * and belongs on this path too. Counting output alone would under-report a
24
+ * thinking-heavy model and disagree with the row's stated definition.
17
25
  *
18
26
  * Unlike the active-work average, this is the whole conversation's average, so
19
27
  * it includes every subagent and every pause. A just-started session is floored
20
28
  * at one second so it cannot divide by a sliver of time and flash an absurd
21
29
  * rate. Returns `undefined` when there is nothing to divide.
22
30
  */
23
- export function sessionThroughput(outputTokens: unknown, elapsedMs: unknown): number | undefined {
24
- const output = asCount(outputTokens);
31
+ export function sessionThroughput(tokens: unknown, elapsedMs: unknown): number | undefined {
32
+ const total = asCount(tokens);
25
33
  const elapsed = asCount(elapsedMs);
26
- if (output === undefined || output <= 0) return undefined;
34
+ if (total === undefined || total <= 0) return undefined;
27
35
  if (elapsed === undefined || elapsed <= 0) return undefined;
28
- return output / (Math.max(elapsed, 1_000) / 1_000);
36
+ return total / (Math.max(elapsed, 1_000) / 1_000);
29
37
  }
30
38
 
31
39
  /**
32
40
  * One assistant turn's contribution to the active-work average.
33
41
  *
34
- * `key` is the turn's identity (see `turnKey`); `tokens` is its output count;
35
- * `start` and `end` are its span on the host's epoch clock. Every field is
36
- * untrusted and coerced before use.
42
+ * `key` is the turn's identity (see `turnKey`); `tokens` is its output count and
43
+ * `reasoning` its reasoning count, which the numerator adds together; `start`
44
+ * and `end` are its span on the host's epoch clock. Every field is untrusted and
45
+ * coerced before use.
37
46
  */
38
47
  export interface ThroughputSpan {
39
48
  readonly key?: unknown;
40
49
  readonly tokens?: unknown;
50
+ readonly reasoning?: unknown;
41
51
  readonly start?: unknown;
42
52
  readonly end?: unknown;
43
53
  }
44
54
 
55
+ /**
56
+ * Which recorded stamp ends an assistant turn's span when more than one is
57
+ * present. The choice is the caller's, not the helper's: the two consumers want
58
+ * different clocks off the same record.
59
+ *
60
+ * `"streamed"` ends at `time.streamed`, the moment the provider stopped
61
+ * decoding - the official TUI's numerator clock, used by `tps`.
62
+ * `"completed"` ends at `time.completed`, once the turn's tools have settled -
63
+ * the busy clock, used by the `elapsed` seed.
64
+ */
65
+ export type SpanEndPreference = "streamed" | "completed";
66
+
45
67
  /**
46
68
  * Resolve one assistant turn's span from its timestamp rungs.
47
69
  *
48
- * `start` is `time.created`. `end` is `time.completed`, else `time.streamed`,
49
- * else the caller's `nowMs` for a turn still in flight. A clock that steps
50
- * backwards is clamped to a zero-length span rather than a negative one, so
51
- * skew can never subtract time from the union. Returns `undefined` when there
52
- * is no usable start — the turn is skipped, never guessed at.
70
+ * `start` is `time.created`. `end` is the stamp `preference` names first when
71
+ * both are recorded, else the other rung, else the caller's `nowMs` for a turn
72
+ * still in flight. So `"streamed"` reads `streamed`, then `completed`;
73
+ * `"completed"` reads `completed`, then `streamed`. A clock that steps backwards
74
+ * is clamped to a zero-length span rather than a negative one, so skew can never
75
+ * subtract time from the union. Returns `undefined` when there is no usable
76
+ * start - the turn is skipped, never guessed at.
53
77
  */
54
78
  export function turnSpan(
55
79
  created: unknown,
56
80
  completed: unknown,
57
81
  streamed: unknown,
58
82
  nowMs: unknown,
83
+ preference: SpanEndPreference,
59
84
  ): { readonly start: number; readonly end: number } | undefined {
60
85
  const start = asCount(created);
61
86
  if (start === undefined) return undefined;
62
- const ended = asCount(completed) ?? asCount(streamed) ?? asCount(nowMs);
87
+ const ended =
88
+ preference === "streamed"
89
+ ? asCount(streamed) ?? asCount(completed) ?? asCount(nowMs)
90
+ : asCount(completed) ?? asCount(streamed) ?? asCount(nowMs);
63
91
  if (ended === undefined) return undefined;
64
92
  return { start, end: Math.max(start, ended) };
65
93
  }
@@ -76,7 +104,7 @@ export function turnKey(id: unknown, created: unknown, completed: unknown, outpu
76
104
  return `t:${asCount(created) ?? "?"}:${asCount(completed) ?? "?"}:${asCount(output) ?? "?"}`;
77
105
  }
78
106
 
79
- /** Output tokens and wall time the accepted turns actually cover. */
107
+ /** Output + reasoning tokens and wall time the accepted turns actually cover. */
80
108
  export interface SpanTotals {
81
109
  readonly tokens: number;
82
110
  readonly unionMs: number;
@@ -124,8 +152,14 @@ function mergedSpanMs(accepted: Array<{ start: number; end: number }>): number {
124
152
  * enters the union once — a dropped duplicate drops both sides together.
125
153
  * Spans are clamped (`end >= start`), then sorted and merged so overlapping
126
154
  * and touching turns count once and input order cannot change the result. A
127
- * turn with no usable token count contributes to neither side: the numerator
128
- * and the denominator always cover exactly the same turns.
155
+ * turn's numerator is its output plus its reasoning count, the same pair the
156
+ * official TUI divides.
157
+ *
158
+ * Every turn with a usable span counts in the denominator, including one that
159
+ * produced no tokens: a stamped step that streamed for two seconds still took
160
+ * two seconds, and dropping its span would inflate the rate above the official
161
+ * figure. The caller decides there is no rate at all when the total numerator
162
+ * or the total duration is not positive.
129
163
  */
130
164
  export function unionSpanTotals(spans: readonly ThroughputSpan[]): SpanTotals {
131
165
  const seen = new Set<string>();
@@ -138,27 +172,25 @@ export function unionSpanTotals(spans: readonly ThroughputSpan[]): SpanTotals {
138
172
 
139
173
  const start = asCount(span.start);
140
174
  const end = asCount(span.end);
141
- const output = asCount(span.tokens);
142
175
  if (start === undefined || end === undefined) continue;
143
- if (output === undefined || output <= 0) continue;
176
+ const output = asCount(span.tokens);
177
+ const reasoning = asCount(span.reasoning);
144
178
 
145
179
  seen.add(key);
146
180
  accepted.push({ start, end: Math.max(start, end) });
147
- tokens += output;
181
+ tokens += (output ?? 0) + (reasoning ?? 0);
148
182
  }
149
183
 
150
184
  return { tokens, unionMs: mergedSpanMs(accepted) };
151
185
  }
152
186
 
153
187
  /**
154
- * The union length of distinct turn spans, with tokens ignored entirely.
188
+ * The union length of distinct turn spans, returned without the token sum.
155
189
  *
156
- * The same identity rule, clamp, pre-sort and merge as `unionSpanTotals`, but
157
- * a turn's output count never enters the decision: a zero-output turn still
158
- * took wall time and still contributes its span. This is what seeds `elapsed`,
159
- * which must not undercount real work the way a token-gated union would.
160
- * A missing key is skipped; the first-seen key wins; a span without a usable
161
- * start and end is skipped; `0` when nothing is usable.
190
+ * The same identity rule, clamp, pre-sort and merge as `unionSpanTotals`:
191
+ * `elapsed` needs only the wall time, so the numerator never enters the
192
+ * decision. A missing key is skipped; the first-seen key wins; a span without
193
+ * a usable start and end is skipped; `0` when nothing is usable.
162
194
  */
163
195
  export function unionSpanMs(spans: readonly ThroughputSpan[]): number {
164
196
  const seen = new Set<string>();
@@ -180,15 +212,15 @@ export function unionSpanMs(spans: readonly ThroughputSpan[]): number {
180
212
  }
181
213
 
182
214
  /**
183
- * Active-work throughput: output tokens of the scope divided by the union of
184
- * its active turn spans. Idle time between turns is not in the denominator, so
185
- * the figure stops moving once everything settles instead of decaying or
186
- * hiding. A turn still in flight ends at the caller's `now`, so the value keeps
187
- * climbing while work happens.
215
+ * Active-work throughput: output and reasoning tokens of the scope divided by
216
+ * the union of its streaming turn spans. Idle time between turns and the
217
+ * settlement after a turn are not in the denominator, so the figure stops moving
218
+ * once everything settles instead of decaying or hiding. A turn still in flight
219
+ * ends at the caller's `now`, so the value keeps climbing while work happens.
188
220
  *
189
221
  * Floored at one second, the same floor the lifetime average uses, so a sliver
190
222
  * of time cannot flash an absurd rate. Returns `undefined` when there is
191
- * nothing to divide — no positive output, or no span with positive length.
223
+ * nothing to divide — no positive tokens, or no span with positive length.
192
224
  */
193
225
  export function unionSpanThroughput(spans: readonly ThroughputSpan[]): number | undefined {
194
226
  const { tokens, unionMs } = unionSpanTotals(spans);