oc-flight-deck 0.8.0 → 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 +15 -9
- package/flight-deck.example.jsonc +17 -11
- package/flight-deck.schema.json +3 -3
- package/package.json +1 -1
- package/src/tui/config.ts +16 -16
- package/src/tui/index.tsx +6 -5
- package/src/tui/rows.ts +3 -1
- package/src/tui/session-reads.ts +3 -1
- package/src/tui/session-tps.ts +34 -16
- package/src/tui/stat-fields.ts +6 -5
- package/src/tui/stats.ts +1 -1
- package/src/tui/throughput.ts +70 -38
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
|
-
      
|
|
9
9
|
|
|
10
10
|
</div>
|
|
11
11
|
|
|
@@ -36,15 +36,12 @@ 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
|
|
40
|
-
|
|
41
|
-
▸ FLIGHT DECK
|
|
42
|
-
─────────────────
|
|
39
|
+
tps 18.0 tok/s
|
|
43
40
|
```
|
|
44
41
|
|
|
45
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.
|
|
46
43
|
|
|
47
|
-
The panel's only fixed text — `▸ FLIGHT DECK` over a separator — renders in the sidebar footer slot, a separate host region **below** the rows: the top of the rail starts directly with the live rows.
|
|
44
|
+
The panel's only fixed text — `▸ FLIGHT DECK` over a separator — is **opt-in**. It renders in the sidebar footer slot, a separate host region **below** the rows: the top of the rail starts directly with the live rows. Since 0.8.1 the footer is empty by default, so a fresh install draws the live rows and nothing else; set `sidebar.footer.lines` to the pair to re-enable it (see ⚙️ Configure). The footer is independent of `sidebar.rows` and `sidebar.maxLines`.
|
|
48
45
|
|
|
49
46
|
| Row | What it shows |
|
|
50
47
|
|---|---|
|
|
@@ -61,7 +58,7 @@ The panel's only fixed text — `▸ FLIGHT DECK` over a separator — renders i
|
|
|
61
58
|
| `context` | A gauge of how full the window is |
|
|
62
59
|
| `perms` | What is waiting for approval, not just how many |
|
|
63
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 |
|
|
64
|
-
| `tps` | Average speed **while
|
|
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 |
|
|
65
62
|
| `spark` | Recent turn sizes as a shape · **off by default** |
|
|
66
63
|
| `reasoning` | Reasoning tokens, when the model emits them · **off by default** |
|
|
67
64
|
| `turns` | How many prompts you've sent this session · **off by default** |
|
|
@@ -114,11 +111,20 @@ The file is optional, and a missing file is normal and silent: with no file at a
|
|
|
114
111
|
|
|
115
112
|
> **Upgrading from 0.7.0 — the branding moved.** The `▸ FLIGHT DECK` pair now renders in the sidebar footer slot, and `sidebar.lines` defaults to empty, so the top of the rail starts with the live rows. An explicit `sidebar.lines` is kept — it does not suppress the footer default; `sidebar.footer.lines: []` is the way to drop the footer entirely.
|
|
116
113
|
|
|
114
|
+
> **Upgrading from 0.8.0 — the branding is opt-in since 0.8.1.** The footer slot no longer ships the `▸ FLIGHT DECK` pair by default: with `sidebar.footer.lines` empty (the new default) nothing renders below the rows and no footer slot is claimed. Set `sidebar.footer.lines` back to the pair to get the footer exactly as it was.
|
|
115
|
+
|
|
117
116
|
`sidebar.rows` picks the rows and their order; `sidebar.maxLines` caps the whole rail (fixed lines plus rows, default 24, configurable from 1 to 24); `layout.labelWidth` fits your terminal; `format.duration` switches the `elapsed` row between `spaced` (`2h 14m 37s`, the default) and `compact` (`2h14m37s`).
|
|
118
117
|
|
|
119
|
-
`sidebar.footer.lines` sets the fixed lines in the sidebar footer slot —
|
|
118
|
+
`sidebar.footer.lines` sets the fixed lines in the sidebar footer slot — empty by default since 0.8.1, in a region the host draws below the rows. Set it to the documented pair to re-enable the branding:
|
|
119
|
+
|
|
120
|
+
```jsonc
|
|
121
|
+
// inside "sidebar":
|
|
122
|
+
"footer": { "lines": ["▸ FLIGHT DECK", "─────────────────"] }
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
It is independent of `sidebar.lines`: setting your own top lines does not turn the footer on, and an explicitly empty `"lines": []` inside `sidebar.footer` keeps the slot off entirely. The footer never counts against `sidebar.maxLines`.
|
|
120
126
|
|
|
121
|
-
Optional styling lives under `style`: `style.lines` controls the fixed branding/separator lines (the
|
|
127
|
+
Optional styling lives under `style`: `style.lines` controls the fixed branding/separator lines (the opt-in footer pair when you set `sidebar.footer.lines`, or whatever `sidebar.lines` you set), `style.rows."*"` sets every live row, and `style.rows.cost` (or another row name) overrides one field while inheriting omitted values from the wildcard. Colors are theme roles - `default`, `subdued`, `warning`, `error`, `success`, `info` - and attributes are OpenTUI descriptors: `bold`, `dim`, `italic`, `underline`, `blink`, `inverse`, `hidden`, `strikethrough`. Defaults keep the existing theme-native look; no ANSI escapes or raw colors are needed. Invalid colors, attributes, and row names are reported and safely ignored.
|
|
122
128
|
|
|
123
129
|
Everything else lives in the example file, documented inline - a typo is never fatal: the bad value is ignored, the default comes back, and you get a one-time toast naming the key to fix.
|
|
124
130
|
|
|
@@ -67,11 +67,16 @@
|
|
|
67
67
|
"lines": [],
|
|
68
68
|
|
|
69
69
|
// The sidebar footer slot: fixed lines below the rows, in the host's
|
|
70
|
-
// dedicated sidebar-footer area
|
|
71
|
-
//
|
|
72
|
-
//
|
|
70
|
+
// dedicated sidebar-footer area, outside the maxLines budget. EMPTY by
|
|
71
|
+
// default since 0.8.1 — copying this file yields the minimal TUI. The
|
|
72
|
+
// branding pair is the documented opt-in; set it back to re-enable:
|
|
73
|
+
//
|
|
74
|
+
// "lines": ["▸ FLIGHT DECK", "─────────────────"]
|
|
75
|
+
//
|
|
76
|
+
// An explicitly empty list removes the footer slot entirely. Fixed lines
|
|
77
|
+
// use style.lines.
|
|
73
78
|
"footer": {
|
|
74
|
-
"lines": [
|
|
79
|
+
"lines": []
|
|
75
80
|
},
|
|
76
81
|
|
|
77
82
|
// The live rows, top to bottom. Every value is read from the open session,
|
|
@@ -99,13 +104,14 @@
|
|
|
99
104
|
// assistant turn spans the host already recorded, so it
|
|
100
105
|
// survives a restart instead of resetting; work observed live
|
|
101
106
|
// after that keeps counting in memory
|
|
102
|
-
// tps average speed while
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
//
|
|
106
|
-
//
|
|
107
|
-
//
|
|
108
|
-
//
|
|
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
|
|
109
115
|
// spark recent turn sizes as a sparkline
|
|
110
116
|
// reasoning reasoning tokens, when the model emits them
|
|
111
117
|
// turns how many prompts you have sent this session
|
package/flight-deck.schema.json
CHANGED
|
@@ -39,14 +39,14 @@
|
|
|
39
39
|
"footer": {
|
|
40
40
|
"type": "object",
|
|
41
41
|
"additionalProperties": false,
|
|
42
|
-
"description": "Fixed lines rendered in the sidebar footer slot, a separate host region below the rows that draws outside the 24-line rail cap.
|
|
42
|
+
"description": "Fixed lines rendered in the sidebar footer slot, a separate host region below the rows that draws outside the 24-line rail cap. Empty by default since 0.8.1 — set the documented `▸ FLIGHT DECK` / `─────────────────` pair in `lines` to re-enable the branding. An explicitly empty `lines` array removes the slot entirely.",
|
|
43
43
|
"properties": {
|
|
44
44
|
"lines": {
|
|
45
45
|
"type": "array",
|
|
46
46
|
"items": { "type": "string" },
|
|
47
|
-
"default": [
|
|
47
|
+
"default": [],
|
|
48
48
|
"maxItems": 24,
|
|
49
|
-
"description": "The footer's fixed lines, in order.
|
|
49
|
+
"description": "The footer's fixed lines, in order. Empty by default since 0.8.1 — set the documented `▸ FLIGHT DECK` / `─────────────────` pairing here to re-enable it. Independent of `sidebar.lines`, so setting your own top lines does not turn the footer on. An explicit empty array opts the footer slot out (and never registers it)."
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
},
|
package/package.json
CHANGED
package/src/tui/config.ts
CHANGED
|
@@ -50,12 +50,12 @@ interface SidebarConfig {
|
|
|
50
50
|
|
|
51
51
|
interface SidebarFooterConfig {
|
|
52
52
|
/**
|
|
53
|
-
* The footer's fixed lines
|
|
53
|
+
* The footer's fixed lines. Empty by default since 0.8.1.
|
|
54
54
|
*
|
|
55
|
-
* An explicitly empty list opts the footer slot out entirely.
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* `maxLines` budget.
|
|
55
|
+
* An explicitly empty list opts the footer slot out entirely. Only a
|
|
56
|
+
* non-empty list registers the slot: set the documented `▸ FLIGHT DECK` /
|
|
57
|
+
* `─────────────────` branding pair here to re-enable it. The two lists are
|
|
58
|
+
* independent, and the footer draws outside the rail's `maxLines` budget.
|
|
59
59
|
*/
|
|
60
60
|
readonly lines: readonly string[];
|
|
61
61
|
}
|
|
@@ -229,16 +229,16 @@ const DEFAULT_CAUTION: CautionConfig = {
|
|
|
229
229
|
export const DEFAULT_SIDEBAR_LINES: readonly string[] = [];
|
|
230
230
|
|
|
231
231
|
/**
|
|
232
|
-
* The sidebar footer's default fixed lines
|
|
232
|
+
* The sidebar footer's default fixed lines.
|
|
233
233
|
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
234
|
+
* Empty since 0.8.1: a fresh install renders no footer text at all, so the
|
|
235
|
+
* rail is the live rows and nothing else. The `▸ FLIGHT DECK` /
|
|
236
|
+
* `─────────────────` branding pair is a documented opt-in — set
|
|
237
|
+
* `sidebar.footer.lines` to the pair to re-enable it (see the README's
|
|
238
|
+
* ⚙️ Configure section). An explicitly empty `sidebar.footer.lines` from a
|
|
239
|
+
* config file removes the slot entirely.
|
|
237
240
|
*/
|
|
238
|
-
export const DEFAULT_SIDEBAR_FOOTER_LINES: readonly string[] = [
|
|
239
|
-
"▸ FLIGHT DECK",
|
|
240
|
-
"─────────────────",
|
|
241
|
-
];
|
|
241
|
+
export const DEFAULT_SIDEBAR_FOOTER_LINES: readonly string[] = [];
|
|
242
242
|
|
|
243
243
|
/**
|
|
244
244
|
* Live fields shown by default, in reading order.
|
|
@@ -418,11 +418,11 @@ function readLines(value: unknown, issues: string[], maxLines: number): readonly
|
|
|
418
418
|
}
|
|
419
419
|
|
|
420
420
|
/**
|
|
421
|
-
* The sidebar footer's fixed lines —
|
|
421
|
+
* The sidebar footer's fixed lines — empty by default since 0.8.1.
|
|
422
422
|
*
|
|
423
423
|
* Unlike the top rail, an explicitly empty list is meaningful: it removes the
|
|
424
|
-
* footer slot entirely.
|
|
425
|
-
*
|
|
424
|
+
* footer slot entirely. A non-empty list with no usable entries falls back to
|
|
425
|
+
* the (empty) default, reported like every other bad value, and a runaway
|
|
426
426
|
* footer is capped at `MAX_LINES` the way the top rail is.
|
|
427
427
|
*/
|
|
428
428
|
function readSidebarFooterLines(value: unknown, issues: string[]): readonly string[] {
|
package/src/tui/index.tsx
CHANGED
|
@@ -299,11 +299,12 @@ export default Plugin.define({
|
|
|
299
299
|
releases.push(
|
|
300
300
|
context.ui.slot({
|
|
301
301
|
// The sidebar footer: a separate host slot below the rows. The
|
|
302
|
-
//
|
|
303
|
-
//
|
|
304
|
-
//
|
|
305
|
-
// stays when `sidebar.lines` is
|
|
306
|
-
//
|
|
302
|
+
// lines are empty by default since 0.8.1, so this registration is
|
|
303
|
+
// purely opt-in — set `sidebar.footer.lines` (the documented
|
|
304
|
+
// `▸ FLIGHT DECK` pair, or your own) to claim the slot. It draws
|
|
305
|
+
// outside the `maxLines` budget and stays when `sidebar.lines` is
|
|
306
|
+
// customized. The lines are fixed, so nothing here subscribes to
|
|
307
|
+
// the ticker or the session.
|
|
307
308
|
append: "sidebar.footer",
|
|
308
309
|
render: () => (
|
|
309
310
|
<box flexDirection="column">
|
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
|
-
|
|
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) : [];
|
package/src/tui/session-reads.ts
CHANGED
|
@@ -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
|
-
|
|
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 });
|
package/src/tui/session-tps.ts
CHANGED
|
@@ -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
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// the
|
|
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
|
-
|
|
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
|
|
82
|
-
|
|
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
|
|
103
|
-
|
|
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
|
|
115
|
-
if (
|
|
116
|
-
total +=
|
|
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
|
|
142
|
-
// a family root — every subagent session's. A
|
|
143
|
-
// its ancestors and siblings back, so it keeps
|
|
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 {
|
package/src/tui/stat-fields.ts
CHANGED
|
@@ -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
|
|
35
|
-
* turns'
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
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
package/src/tui/throughput.ts
CHANGED
|
@@ -1,65 +1,93 @@
|
|
|
1
|
-
// Session throughput: output tokens per second, measured over the
|
|
2
|
-
// the host actually recorded rather than over the wall
|
|
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
|
|
10
|
-
// divided by the union of the assistant turns' own
|
|
11
|
-
// is never in the denominator and the
|
|
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
|
|
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(
|
|
24
|
-
const
|
|
31
|
+
export function sessionThroughput(tokens: unknown, elapsedMs: unknown): number | undefined {
|
|
32
|
+
const total = asCount(tokens);
|
|
25
33
|
const elapsed = asCount(elapsedMs);
|
|
26
|
-
if (
|
|
34
|
+
if (total === undefined || total <= 0) return undefined;
|
|
27
35
|
if (elapsed === undefined || elapsed <= 0) return undefined;
|
|
28
|
-
return
|
|
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
|
-
* `
|
|
36
|
-
*
|
|
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 `
|
|
49
|
-
* else the caller's `nowMs` for a turn
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* is
|
|
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 =
|
|
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
|
|
128
|
-
*
|
|
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
|
-
|
|
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,
|
|
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
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
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
|
|
184
|
-
* its
|
|
185
|
-
*
|
|
186
|
-
* hiding. A turn still in flight
|
|
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
|
|
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);
|