oc-flight-deck 0.11.0 → 0.19.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 +77 -0
- package/LICENSE +1 -1
- package/README.md +63 -173
- package/dist/index.js +10 -0
- package/dist/tui/index.js +3814 -0
- package/flight-deck.example.jsonc +114 -38
- package/flight-deck.schema.json +122 -10
- package/package.json +11 -9
- package/src/tui/clipboard.ts +44 -15
- package/src/tui/config.ts +358 -22
- package/src/tui/file-config.ts +4 -1
- package/src/tui/format.ts +1 -1
- package/src/tui/go-look.ts +118 -0
- package/src/tui/go-panel.ts +637 -0
- package/src/tui/go-usage.ts +8 -1
- package/src/tui/go.ts +663 -27
- package/src/tui/guard.ts +15 -7
- package/src/tui/host-clipboard.ts +21 -4
- package/src/tui/index.tsx +96 -24
- package/src/tui/rows.ts +71 -24
- package/src/tui/session-elapsed.ts +122 -0
- package/src/tui/session-reads.ts +97 -65
- package/src/tui/session-tps.ts +158 -109
- package/src/tui/stat-fields.ts +99 -5
- package/src/tui/stats.ts +9 -9
- package/src/tui/style.ts +24 -5
- package/src/tui/throughput.ts +48 -113
- package/src/tui/active-elapsed.ts +0 -141
package/src/tui/session-reads.ts
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
// Coercion of untrusted values happens through ./coerce.js.
|
|
9
9
|
|
|
10
10
|
import type { Plugin } from "@opencode/plugin/tui";
|
|
11
|
-
import {
|
|
11
|
+
import { createActiveTime } from "./session-elapsed.js";
|
|
12
12
|
import { asCount, asRecord, asText, type SessionLike } from "./coerce.js";
|
|
13
|
-
import { turnKey,
|
|
13
|
+
import { turnKey, type ThroughputSpan } from "./stats.js";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* The location the rail reads shell records and VCS from: the host's current
|
|
@@ -25,7 +25,7 @@ export function locationOf(context: Plugin.Context) {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export function createSessionReads(context: Plugin.Context
|
|
28
|
+
export function createSessionReads(context: Plugin.Context) {
|
|
29
29
|
/** How many trailing messages are inspected for tool parts. */
|
|
30
30
|
const RECENT_MESSAGES = 4;
|
|
31
31
|
|
|
@@ -55,7 +55,14 @@ export function createSessionReads(context: Plugin.Context, maxBankedMs?: number
|
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
// Subagent sessions are separate sessions, and the parent's `cost` does not
|
|
58
|
-
// include them, so a bare `cost` row understates a swarm. Sum the family
|
|
58
|
+
// include them, so a bare `cost` row understates a swarm. Sum the family —
|
|
59
|
+
// and the same scope for `tokens`: the money row already shows the family,
|
|
60
|
+
// so the token rows beside it must share it, or one row's swarm is another
|
|
61
|
+
// row's session. The parent's own tokens come from its session record (its
|
|
62
|
+
// own cost arrives via `ownCost`, already in the caller's hand), every
|
|
63
|
+
// child's from theirs: `input`, `output`, `reasoning`, and both `cache`
|
|
64
|
+
// rungs, so a caller that uses this INSTEAD of the session's own record
|
|
65
|
+
// gets the full family figure.
|
|
59
66
|
const treeTotals = (sessionID: string, ownCost: unknown) => {
|
|
60
67
|
if (!isFamilyRoot(sessionID)) return undefined;
|
|
61
68
|
|
|
@@ -65,7 +72,24 @@ export function createSessionReads(context: Plugin.Context, maxBankedMs?: number
|
|
|
65
72
|
} catch {
|
|
66
73
|
return undefined;
|
|
67
74
|
}
|
|
68
|
-
|
|
75
|
+
|
|
76
|
+
let own: SessionLike | undefined;
|
|
77
|
+
try {
|
|
78
|
+
own = context.data.session.get(sessionID) as SessionLike | undefined;
|
|
79
|
+
} catch {
|
|
80
|
+
own = undefined;
|
|
81
|
+
}
|
|
82
|
+
const tokens = { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } };
|
|
83
|
+
const addTokens = (source: SessionLike | undefined): void => {
|
|
84
|
+
const record = asRecord(source?.tokens);
|
|
85
|
+
tokens.input += asCount(record?.["input"]) ?? 0;
|
|
86
|
+
tokens.output += asCount(record?.["output"]) ?? 0;
|
|
87
|
+
tokens.reasoning += asCount(record?.["reasoning"]) ?? 0;
|
|
88
|
+
const cache = asRecord(record?.["cache"]);
|
|
89
|
+
tokens.cache.read += asCount(cache?.["read"]) ?? 0;
|
|
90
|
+
tokens.cache.write += asCount(cache?.["write"]) ?? 0;
|
|
91
|
+
};
|
|
92
|
+
addTokens(own);
|
|
69
93
|
|
|
70
94
|
let cost = asCount(ownCost) ?? 0;
|
|
71
95
|
let count = 0;
|
|
@@ -81,8 +105,15 @@ export function createSessionReads(context: Plugin.Context, maxBankedMs?: number
|
|
|
81
105
|
if (child === undefined) continue;
|
|
82
106
|
count += 1;
|
|
83
107
|
cost += asCount(child.cost) ?? 0;
|
|
108
|
+
addTokens(child);
|
|
84
109
|
}
|
|
85
|
-
|
|
110
|
+
// The family figure, subagents included. A session that spawned none still
|
|
111
|
+
// records one: its own cost against a count of zero, so the `total` row has
|
|
112
|
+
// a real number to draw instead of blanking at `$0.000`. `undefined` is now
|
|
113
|
+
// reserved for a figure that genuinely cannot be computed — a non-root
|
|
114
|
+
// session (its family is its parent's), or a host read that threw.
|
|
115
|
+
if (ownCost === undefined && count === 0) return undefined;
|
|
116
|
+
return { cost, count, tokens };
|
|
86
117
|
};
|
|
87
118
|
|
|
88
119
|
// A message's own totals are per-request, so the last assistant message's
|
|
@@ -226,53 +257,39 @@ export function createSessionReads(context: Plugin.Context, maxBankedMs?: number
|
|
|
226
257
|
return status === undefined ? undefined : false;
|
|
227
258
|
};
|
|
228
259
|
|
|
229
|
-
//
|
|
230
|
-
//
|
|
231
|
-
//
|
|
232
|
-
//
|
|
233
|
-
//
|
|
234
|
-
//
|
|
235
|
-
//
|
|
236
|
-
//
|
|
237
|
-
//
|
|
238
|
-
//
|
|
239
|
-
//
|
|
240
|
-
//
|
|
241
|
-
//
|
|
242
|
-
//
|
|
243
|
-
//
|
|
244
|
-
const
|
|
245
|
-
const seeds = new Map<string, number>();
|
|
246
|
-
const rememberSeed = (sessionID: string, seed: number): void => {
|
|
247
|
-
if (seeds.has(sessionID)) seeds.delete(sessionID);
|
|
248
|
-
else if (seeds.size >= MAX_SEEDS) {
|
|
249
|
-
for (const oldest of seeds.keys()) {
|
|
250
|
-
seeds.delete(oldest);
|
|
251
|
-
break;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
seeds.set(sessionID, seed);
|
|
255
|
-
};
|
|
256
|
-
const seedElapsed = (sessionID: string): number => {
|
|
257
|
-
const cached = seeds.get(sessionID);
|
|
258
|
-
if (cached !== undefined) {
|
|
259
|
-
seeds.delete(sessionID);
|
|
260
|
-
seeds.set(sessionID, cached);
|
|
261
|
-
return cached;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// One `now` for the whole scan, so every in-flight turn ends at the same
|
|
265
|
-
// instant and the union cannot be skewed by the reads drifting apart.
|
|
266
|
-
const now = Date.now();
|
|
267
|
-
const ids = new Set<string>([sessionID]);
|
|
268
|
-
try {
|
|
269
|
-
for (const id of context.data.session.family(sessionID) ?? []) ids.add(id);
|
|
270
|
-
} catch {
|
|
271
|
-
// No family on this host: the session's own turns still stand.
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
let seed = 0;
|
|
260
|
+
// Active time over the session's whole lifetime, derived from the host's own
|
|
261
|
+
// timestamps rather than accumulated in this process: the figure is the
|
|
262
|
+
// merged union of the assistant turns' spans across exactly the scope
|
|
263
|
+
// `busy()` consults — the displayed session plus every id `family()`
|
|
264
|
+
// returns — with an uncompleted turn ending at `now` while the scope is
|
|
265
|
+
// genuinely working, and collapsing to its last recorded stamp when nothing
|
|
266
|
+
// is working. So a restart recomputes the same figure instead of resetting,
|
|
267
|
+
// a climbing turn keeps climbing while it is in flight, a settled scope
|
|
268
|
+
// freezes, and a stalled or abandoned turn bills no idle time. Tokens are
|
|
269
|
+
// ignored: a zero-output turn still took wall time. One `now` for the whole
|
|
270
|
+
// scan, so every in-flight turn ends at the same instant and the union
|
|
271
|
+
// cannot be skewed by the reads drifting apart. Every read degrades to
|
|
272
|
+
// empty rather than throwing, so an absent family or an unstamped host hides
|
|
273
|
+
// the row instead of breaking the rail. Monotonicity, caching and the
|
|
274
|
+
// per-session bound live in ./session-elapsed.js; this is only the host read.
|
|
275
|
+
const spansOf = (sessionID: string, now: number): readonly ThroughputSpan[] => {
|
|
275
276
|
try {
|
|
277
|
+
// Whether the scope is genuinely working, read once for the whole scan:
|
|
278
|
+
// every uncompleted turn in it shares the same end rule, and the scope
|
|
279
|
+
// is exactly what `busy()` already consults. A read that throws counts
|
|
280
|
+
// as not busy.
|
|
281
|
+
let live = false;
|
|
282
|
+
try {
|
|
283
|
+
live = busy(sessionID) === true;
|
|
284
|
+
} catch {
|
|
285
|
+
live = false;
|
|
286
|
+
}
|
|
287
|
+
const ids = new Set<string>([sessionID]);
|
|
288
|
+
try {
|
|
289
|
+
for (const id of context.data.session.family(sessionID) ?? []) ids.add(id);
|
|
290
|
+
} catch {
|
|
291
|
+
// No family on this host: the session's own turns still stand.
|
|
292
|
+
}
|
|
276
293
|
const spans: ThroughputSpan[] = [];
|
|
277
294
|
for (const id of ids) {
|
|
278
295
|
for (const entry of messagesOf(id)) {
|
|
@@ -280,33 +297,48 @@ export function createSessionReads(context: Plugin.Context, maxBankedMs?: number
|
|
|
280
297
|
if (message?.["type"] !== "assistant") continue;
|
|
281
298
|
const stamp = asRecord(message["time"]);
|
|
282
299
|
const created = asCount(stamp?.["created"]);
|
|
300
|
+
if (created === undefined) continue;
|
|
283
301
|
const completed = asCount(stamp?.["completed"]);
|
|
284
302
|
const streamed = asCount(stamp?.["streamed"]);
|
|
285
|
-
//
|
|
286
|
-
//
|
|
287
|
-
|
|
288
|
-
|
|
303
|
+
// A completed turn ends at `completed`, covering its tool
|
|
304
|
+
// settlement. An uncompleted one ends at `now` while the scope is
|
|
305
|
+
// genuinely working, and collapses to its last recorded stamp
|
|
306
|
+
// (`streamed`, else its own start) when nothing is working — so a
|
|
307
|
+
// host that never writes `completed` cannot bill idle either.
|
|
308
|
+
const end = completed ?? (live ? now : (streamed ?? created));
|
|
309
|
+
if (!Number.isFinite(end)) continue;
|
|
289
310
|
const output = asRecord(message["tokens"])?.["output"];
|
|
290
|
-
spans.push({
|
|
311
|
+
spans.push({
|
|
312
|
+
key: turnKey(message["id"], created, completed, output, streamed),
|
|
313
|
+
start: created,
|
|
314
|
+
end: Math.max(created, end),
|
|
315
|
+
});
|
|
291
316
|
}
|
|
292
317
|
}
|
|
293
|
-
|
|
318
|
+
return spans;
|
|
294
319
|
} catch {
|
|
295
|
-
// A throwing read never reaches the rail: it degrades to
|
|
296
|
-
|
|
320
|
+
// A throwing read never reaches the rail: it degrades to no spans.
|
|
321
|
+
return [];
|
|
297
322
|
}
|
|
323
|
+
};
|
|
298
324
|
|
|
299
|
-
|
|
300
|
-
|
|
325
|
+
// Whether the host still knows a session. The elapsed clock's sweep consults
|
|
326
|
+
// this before dropping an entry, so only a forgotten session loses its
|
|
327
|
+
// high-water mark; a throwing or absent record counts as forgotten.
|
|
328
|
+
const knows = (sessionID: string): boolean => {
|
|
329
|
+
try {
|
|
330
|
+
return context.data.session.get(sessionID) !== undefined;
|
|
331
|
+
} catch {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
301
334
|
};
|
|
302
335
|
|
|
303
|
-
const
|
|
336
|
+
const activeTime = createActiveTime({ spansOf, knows });
|
|
304
337
|
const sessionElapsed = (sessionID: string, now: number = Date.now()): number | undefined =>
|
|
305
|
-
|
|
338
|
+
activeTime(sessionID, now);
|
|
306
339
|
|
|
307
340
|
return {
|
|
308
341
|
messagesOf,
|
|
309
|
-
isFamilyRoot,
|
|
310
342
|
treeTotals,
|
|
311
343
|
contextUsage,
|
|
312
344
|
sessionElapsed,
|
package/src/tui/session-tps.ts
CHANGED
|
@@ -2,42 +2,53 @@
|
|
|
2
2
|
// from a clock this process keeps - as a near-instantaneous output rate, not a
|
|
3
3
|
// lifetime average.
|
|
4
4
|
//
|
|
5
|
-
// Each poll feeds
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// denominator is generating time only: the union of the
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
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
|
|
10
|
+
// tokens - output plus reasoning, which keeps its own row too - and the
|
|
11
|
+
// denominator is generating time only: the union of the streaming spans in
|
|
12
|
+
// scope. The scope is `sidebar.tps.scope` (`./config.js`): `"family"` (the
|
|
13
|
+
// default) paces the displayed session plus its subagent sessions, summing
|
|
14
|
+
// generation tokens across the whole family over the UNION of all their
|
|
15
|
+
// spans, so concurrent decoders share wall clock instead of adding it; a
|
|
16
|
+
// 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.
|
|
16
27
|
//
|
|
17
28
|
// The capability is learned once and remembered for the process. `undefined`
|
|
18
29
|
// means "not yet known": a read that failed, or carried no assistant turns,
|
|
19
30
|
// tells us nothing and must not choose a metric. Once known it is sticky in
|
|
20
31
|
// BOTH directions, so a transient `message.list` failure can never flip a
|
|
21
32
|
// stamped host back to the clock path (nor an unstamped host off it) -
|
|
22
|
-
// a failure just
|
|
33
|
+
// a failure just reads as zero. One value for the whole host, deliberately
|
|
23
34
|
// not keyed by session.
|
|
24
35
|
//
|
|
25
|
-
// The rail re-runs on the fast tick, and walking
|
|
26
|
-
// every
|
|
27
|
-
//
|
|
28
|
-
//
|
|
36
|
+
// 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
|
|
38
|
+
// is held briefly. Zero is cached too: an idle session must not be re-derived
|
|
39
|
+
// on each tick either.
|
|
29
40
|
//
|
|
30
|
-
// One factory closes over the plugin `context
|
|
31
|
-
// ./
|
|
32
|
-
// sums its tree. The math itself lives in ./throughput.js (pure).
|
|
41
|
+
// One factory closes over the plugin `context`. The math itself lives in
|
|
42
|
+
// ./throughput.js (pure).
|
|
33
43
|
|
|
34
44
|
import type { Plugin } from "@opencode/plugin/tui";
|
|
35
45
|
import { asCount, asRecord, type SessionLike } from "./coerce.js";
|
|
46
|
+
import { DEFAULT_TPS_SCOPE, type TpsScope } from "./config.js";
|
|
36
47
|
import {
|
|
37
48
|
createInstantTps,
|
|
38
49
|
turnKey,
|
|
39
50
|
turnSpan,
|
|
40
|
-
|
|
51
|
+
unionGenerationTotals,
|
|
41
52
|
unionSpanMs,
|
|
42
53
|
type ThroughputSpan,
|
|
43
54
|
} from "./stats.js";
|
|
@@ -55,27 +66,22 @@ interface TpsScan {
|
|
|
55
66
|
}
|
|
56
67
|
|
|
57
68
|
/**
|
|
58
|
-
* The live
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
69
|
+
* The live signal the TPS reader borrows rather than re-deriving: the active
|
|
70
|
+
* clock (how much generating time is on record?) is the denominator for a host
|
|
71
|
+
* with no message timestamps — that clock already covers the scope, so it is
|
|
72
|
+
* 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
|
|
74
|
+
* deliberately no busy gate here: idleness is read off the session's own
|
|
75
|
+
* generating-time delta, never off a family-wide flag.
|
|
63
76
|
*/
|
|
64
77
|
export interface TpsLiveReads {
|
|
65
|
-
readonly busyOf?: (sessionID: string) => boolean | undefined;
|
|
66
78
|
readonly elapsedMsOf?: (sessionID: string, now: number) => number | undefined;
|
|
67
79
|
}
|
|
68
80
|
|
|
69
|
-
export function createTpsReader(
|
|
70
|
-
context: Plugin.Context,
|
|
71
|
-
isFamilyRoot: (sessionID: string) => boolean,
|
|
72
|
-
live?: TpsLiveReads,
|
|
73
|
-
) {
|
|
81
|
+
export function createTpsReader(context: Plugin.Context, live?: TpsLiveReads, scope: TpsScope = DEFAULT_TPS_SCOPE) {
|
|
74
82
|
const TPS_CACHE_MS = 1_000;
|
|
75
83
|
let hostStamps: boolean | undefined;
|
|
76
|
-
let tpsCache:
|
|
77
|
-
| { readonly sessionID: string; readonly at: number; readonly value: number | undefined }
|
|
78
|
-
| undefined;
|
|
84
|
+
let tpsCache: { readonly sessionID: string; readonly at: number; readonly value: number } | undefined;
|
|
79
85
|
// One EWMA tracker per displayed session, bounded: without eviction a TUI
|
|
80
86
|
// lifetime of session-hopping grows this map forever. Eviction only drops
|
|
81
87
|
// smoothing - a revisit restarts its baselines, exactly like a first sight.
|
|
@@ -127,130 +133,173 @@ export function createTpsReader(
|
|
|
127
133
|
stamped += 1;
|
|
128
134
|
// Without `created` there is no start; the turn is skipped, not guessed.
|
|
129
135
|
// `tps` ends a turn at `streamed`: decoding stopped is the numerator clock.
|
|
130
|
-
const span = turnSpan(created, completed, streamed, now
|
|
136
|
+
const span = turnSpan(created, completed, streamed, now);
|
|
131
137
|
if (span === undefined) continue;
|
|
132
138
|
const tokens = asRecord(message["tokens"]);
|
|
133
|
-
//
|
|
139
|
+
// Generation: output plus reasoning, which keeps its own row too. A
|
|
140
|
+
// settled id-less turn keys on its final counts, so two settled records
|
|
141
|
+
// sharing a start but differing in reasoning stay distinct.
|
|
142
|
+
const output = tokens?.["output"];
|
|
143
|
+
const reasoning = tokens?.["reasoning"];
|
|
144
|
+
const settled = completed !== undefined || streamed !== undefined;
|
|
145
|
+
const key = turnKey(message["id"], created, completed, output, streamed);
|
|
134
146
|
spans.push({
|
|
135
|
-
key:
|
|
136
|
-
tokens:
|
|
147
|
+
key: settled ? `${key}:${asCount(reasoning) ?? "?"}` : key,
|
|
148
|
+
tokens: output,
|
|
149
|
+
reasoning,
|
|
137
150
|
...span,
|
|
138
151
|
});
|
|
139
152
|
}
|
|
140
153
|
return { ok: true, assistant, stamped, spans };
|
|
141
154
|
};
|
|
142
155
|
|
|
143
|
-
//
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
const tokens = asRecord(source?.tokens);
|
|
150
|
-
return asCount(tokens?.["output"]) ?? 0;
|
|
151
|
-
};
|
|
152
|
-
if (!isFamilyRoot(sessionID)) return outputOf(session);
|
|
156
|
+
// The displayed session plus every id `family()` returns for it — the same
|
|
157
|
+
// traversal `busy()` in ./session-reads.js consults, so the scope is the
|
|
158
|
+
// one the `elapsed` row already covers. A host without `family()` degrades
|
|
159
|
+
// to the session alone rather than failing the row.
|
|
160
|
+
const familyIds = (sessionID: string): readonly string[] => {
|
|
161
|
+
const ids = [sessionID];
|
|
153
162
|
try {
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
for (const id of ids) {
|
|
158
|
-
if (id === sessionID) continue;
|
|
159
|
-
try {
|
|
160
|
-
total += outputOf(context.data.session.get(id) as SessionLike | undefined);
|
|
161
|
-
} catch {
|
|
162
|
-
// One unreadable member must not hide the rest.
|
|
163
|
-
}
|
|
163
|
+
for (const id of context.data.session.family(sessionID) ?? []) {
|
|
164
|
+
if (id === sessionID || ids.includes(id)) continue;
|
|
165
|
+
ids.push(id);
|
|
164
166
|
}
|
|
165
|
-
return outputOf(session) + total;
|
|
166
167
|
} catch {
|
|
167
|
-
// No family on this host: the session's own
|
|
168
|
-
return outputOf(session);
|
|
168
|
+
// No family on this host: the session's own turns still stand.
|
|
169
169
|
}
|
|
170
|
+
return ids;
|
|
170
171
|
};
|
|
171
172
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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.
|
|
177
|
+
const scanScope = (ids: readonly string[], now: number): TpsScan => {
|
|
178
|
+
let ok = true;
|
|
179
|
+
let assistant = 0;
|
|
180
|
+
let stamped = 0;
|
|
181
|
+
const spans: ThroughputSpan[] = [];
|
|
182
|
+
for (const id of ids) {
|
|
183
|
+
const scan = scanMessages(id, now);
|
|
184
|
+
// A refused read is not "this member has no messages": one failure
|
|
185
|
+
// keeps the capability unknown rather than proving anything.
|
|
186
|
+
ok = ok && scan.ok;
|
|
187
|
+
assistant += scan.assistant;
|
|
188
|
+
stamped += scan.stamped;
|
|
189
|
+
for (const span of scan.spans) spans.push({ ...span, key: `${id} ${String(span.key)}` });
|
|
177
190
|
}
|
|
191
|
+
return { ok, assistant, stamped, spans };
|
|
178
192
|
};
|
|
179
193
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const busy = busyOf(sessionID);
|
|
194
|
+
// Generation tokens on record for the session: its own record's `output`
|
|
195
|
+
// and `reasoning` rungs. The `"session"` scope stops here — a root reports
|
|
196
|
+
// only its own rate, and a child keeps its own figure.
|
|
197
|
+
const recordGeneration = (session: SessionLike | undefined): number => {
|
|
198
|
+
const tokens = asRecord(session?.tokens);
|
|
199
|
+
return (asCount(tokens?.["output"]) ?? 0) + (asCount(tokens?.["reasoning"]) ?? 0);
|
|
200
|
+
};
|
|
188
201
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
202
|
+
// Generation tokens on record for the whole family scope: the displayed
|
|
203
|
+
// session's own rungs plus every member's. One unreadable member must not
|
|
204
|
+
// 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.
|
|
207
|
+
const familyGeneration = (
|
|
208
|
+
sessionID: string,
|
|
209
|
+
session: SessionLike | undefined,
|
|
210
|
+
): { readonly ok: boolean; readonly generation: number } => {
|
|
211
|
+
let generation = recordGeneration(session);
|
|
212
|
+
let ok = true;
|
|
213
|
+
for (const id of familyIds(sessionID)) {
|
|
214
|
+
if (id === sessionID) continue;
|
|
194
215
|
try {
|
|
195
|
-
|
|
196
|
-
if (id !== sessionID) scans.push(scanMessages(id, now));
|
|
197
|
-
}
|
|
216
|
+
generation += recordGeneration(context.data.session.get(id) as SessionLike | undefined);
|
|
198
217
|
} catch {
|
|
199
|
-
//
|
|
218
|
+
// One unreadable member must not blank the rest of the tree.
|
|
219
|
+
ok = false;
|
|
200
220
|
}
|
|
201
221
|
}
|
|
222
|
+
return { ok, generation };
|
|
223
|
+
};
|
|
202
224
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
225
|
+
const computeTps = (sessionID: string, session: SessionLike | undefined): number | undefined => {
|
|
226
|
+
const time = asRecord(session?.time);
|
|
227
|
+
const created = asCount(time?.["created"]);
|
|
228
|
+
|
|
229
|
+
const now = Date.now();
|
|
230
|
+
|
|
231
|
+
// Timestamped assistant generation in scope — the whole family under
|
|
232
|
+
// `"family"`, this session's own spans only under `"session"`.
|
|
233
|
+
const scan: TpsScan =
|
|
234
|
+
hostStamps === false
|
|
235
|
+
? { ok: true, assistant: 0, stamped: 0, spans: [] }
|
|
236
|
+
: scope === "family"
|
|
237
|
+
? scanScope(familyIds(sessionID), now)
|
|
238
|
+
: scanMessages(sessionID, now);
|
|
213
239
|
|
|
214
240
|
if (hostStamps === undefined) {
|
|
215
241
|
// A stamped assistant turn proves the host stamps. Assistant turns with
|
|
216
242
|
// no timestamp prove it does not. Neither, and the capability stays
|
|
217
|
-
// unknown so the row
|
|
218
|
-
if (stamped > 0) hostStamps = true;
|
|
219
|
-
else if (
|
|
243
|
+
// unknown so the row reads as zero rather than guessing a metric.
|
|
244
|
+
if (scan.stamped > 0) hostStamps = true;
|
|
245
|
+
else if (scan.ok && scan.assistant > 0) hostStamps = false;
|
|
220
246
|
else return undefined;
|
|
221
247
|
}
|
|
222
248
|
|
|
223
249
|
const tracker = trackerOf(sessionID);
|
|
224
250
|
if (hostStamps === true) {
|
|
225
|
-
//
|
|
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.
|
|
255
|
+
// `"session"` never takes this branch: its single read keeps the
|
|
256
|
+
// 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
|
|
226
259
|
// between turns was never recorded, so it can never enter the rate. An
|
|
227
260
|
// in-flight turn ends at now, so the denominator keeps pace with the
|
|
228
|
-
// decoder while work happens and freezes the instant it settles.
|
|
229
|
-
|
|
230
|
-
const
|
|
231
|
-
|
|
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);
|
|
232
266
|
}
|
|
233
267
|
|
|
234
|
-
// No timestamps on this host: the denominator is the
|
|
235
|
-
//
|
|
236
|
-
// clock there is no honest denominator
|
|
237
|
-
// back to a lifetime average
|
|
238
|
-
|
|
268
|
+
// No timestamps on this host: the denominator is the active clock, which
|
|
269
|
+
// already covers the family scope (it IS the `elapsed` figure), so it is
|
|
270
|
+
// 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.
|
|
273
|
+
const family = scope === "family" ? familyGeneration(sessionID, session) : undefined;
|
|
274
|
+
// 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;
|
|
277
|
+
const generation = family?.generation ?? recordGeneration(session);
|
|
278
|
+
// The creation-time gate is the `"session"` scope's alone: without a
|
|
279
|
+
// stamp there is no clock to borrow. Under `"family"` the displayed
|
|
280
|
+
// session may carry no stamp while a child still paces off the
|
|
281
|
+
// family-wide active clock, so the gate must not silence it.
|
|
282
|
+
if (created === undefined && scope === "session") return tracker(recordGeneration(session), 0);
|
|
239
283
|
let genMs = 0;
|
|
240
284
|
try {
|
|
241
285
|
genMs = live?.elapsedMsOf?.(sessionID, now) ?? 0;
|
|
242
286
|
} catch {
|
|
243
287
|
genMs = 0;
|
|
244
288
|
}
|
|
245
|
-
return tracker(
|
|
289
|
+
return tracker(generation, genMs);
|
|
246
290
|
};
|
|
247
291
|
|
|
248
|
-
|
|
292
|
+
// 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
|
|
296
|
+
// lives in ./rows.js.)
|
|
297
|
+
const sessionTps = (sessionID: string, session: SessionLike | undefined): number => {
|
|
249
298
|
const cached = tpsCache;
|
|
250
299
|
if (cached !== undefined && cached.sessionID === sessionID && Date.now() - cached.at < TPS_CACHE_MS) {
|
|
251
300
|
return cached.value;
|
|
252
301
|
}
|
|
253
|
-
const value = computeTps(sessionID, session);
|
|
302
|
+
const value = computeTps(sessionID, session) ?? 0;
|
|
254
303
|
tpsCache = { sessionID, at: Date.now(), value };
|
|
255
304
|
return value;
|
|
256
305
|
};
|