paseo-turn-speed 1.1.0 → 1.2.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/OVERVIEW.md +9 -3
- package/README.md +36 -9
- package/client/details.tsx +28 -8
- package/client/meter.ts +250 -14
- package/client/pill.tsx +18 -16
- package/client/store.ts +32 -7
- package/client/team.ts +2 -1
- package/index.client.tsx +21 -3
- package/package.json +1 -1
package/OVERVIEW.md
CHANGED
|
@@ -11,7 +11,12 @@ turn latency. When the provider reports real usage (for OpenCode/MLX models
|
|
|
11
11
|
enable `options.includeUsage: true` in the provider config), numbers are exact.
|
|
12
12
|
Without usage the plugin estimates tokens from streamed characters, marks them
|
|
13
13
|
with `≈`, and auto-calibrates a per-model chars/token ratio from every step that
|
|
14
|
-
does report usage.
|
|
14
|
+
does report usage. Reasoning models whose provider subtracts thinking from the
|
|
15
|
+
reported output are detected automatically; their rates include an estimate of
|
|
16
|
+
the thinking tokens (streamed reasoning characters converted with a measured
|
|
17
|
+
reasoning-specific chars/token ratio), and the popover shows it as a separate
|
|
18
|
+
`thinking ≈` line. The verdict is per model: switching models or a provider
|
|
19
|
+
config that starts including thinking revokes it, so nothing is double-counted.
|
|
15
20
|
|
|
16
21
|
Options live under Settings → Plugins → Turn speed: what the pill leads with
|
|
17
22
|
(live estimate, decode-window average, or whole-turn rate, switchable from the
|
|
@@ -21,5 +26,6 @@ see the README for installing from GitHub or npm.
|
|
|
21
26
|
Turns are observed live; history from before a plugin reload is not
|
|
22
27
|
reconstructed. Subagents keep their own pills, but the parent also knows about
|
|
23
28
|
them: time delegated to running subagents is excluded from the parent's
|
|
24
|
-
whole-turn rate, its pill grows a `· N sub` badge, and
|
|
25
|
-
per-subagent breakdown with a combined team rate.
|
|
29
|
+
whole-turn rate, its pill grows a `· N sub` badge, and for Paseo-native child
|
|
30
|
+
agents the popover adds a per-subagent breakdown with a combined team rate.
|
|
31
|
+
Subagent replies count as the parent's input tokens, never its output.
|
package/README.md
CHANGED
|
@@ -6,7 +6,11 @@ A composer pill per agent that shows how fast the model is actually decoding:
|
|
|
6
6
|
once the turn ends — with a popover breakdown (prefill/TTFT, in/cached/out
|
|
7
7
|
tokens, steps, tool wait, user wait, per-subagent rates, context occupancy).
|
|
8
8
|
Numbers measured from real provider usage are exact; before the first usage
|
|
9
|
-
event they are character estimates marked with `≈`.
|
|
9
|
+
event they are character estimates marked with `≈`. For reasoning models whose
|
|
10
|
+
provider subtracts thinking from the reported output (measured on OpenCode +
|
|
11
|
+
local models via oMLX), the thinking tokens are estimated from the streamed
|
|
12
|
+
reasoning text and shown as a separate `thinking ≈` line, so rates cover all
|
|
13
|
+
generated tokens instead of only the visible answer.
|
|
10
14
|
|
|
11
15
|
## Install
|
|
12
16
|
|
|
@@ -97,13 +101,17 @@ provider config) — it feeds the `context 34k / 131k` line in the popover.
|
|
|
97
101
|
separate `waiting for you` row and the pill switches to a ⏸ icon meanwhile.
|
|
98
102
|
- **Delegation to subagents** — while the agent's work runs in subagents, the
|
|
99
103
|
parent's own model produces nothing, so that stretch is removed from its
|
|
100
|
-
whole-turn rate like a user wait.
|
|
101
|
-
|
|
104
|
+
whole-turn rate like a user wait. A subagent's reply reaching the parent is
|
|
105
|
+
a tool result: it lands in the parent's *input* tokens (`in`/`cached`),
|
|
106
|
+
never in its output. Delegation is detected from the parent's timeline
|
|
107
|
+
(`sub_agent` tool details where the provider reports them, and the
|
|
102
108
|
normalized `subagent` tool calls Paseo emits for provider subagents such as
|
|
103
109
|
OpenCode's Task) and from linked Paseo child agents. The parent's pill grows
|
|
104
|
-
a `· N sub` badge
|
|
105
|
-
|
|
106
|
-
|
|
110
|
+
a `· N sub` badge and its accessible title carries the team rate. For
|
|
111
|
+
linked Paseo children the popover also lists each subagent with its own
|
|
112
|
+
live rate and tokens plus a `team` total; for provider subagents only the
|
|
113
|
+
running count and delegated time are knowable (see Known limitations).
|
|
114
|
+
Each linked subagent still gets its own pill in its own composer.
|
|
107
115
|
- **Live number inside a model call** — real tokens only arrive at the end of a
|
|
108
116
|
call, so the live value estimates tokens from characters over a 1/2/5 s
|
|
109
117
|
smoothing window and is marked `≈` until the call's usage lands.
|
|
@@ -114,8 +122,27 @@ provider config) — it feeds the `context 34k / 131k` line in the popover.
|
|
|
114
122
|
a note lands in the app log (`turn-speed: step dropped as implausible`).
|
|
115
123
|
- **Auto-calibration** — at every step end the observed `chars/token` ratio for
|
|
116
124
|
the model is blended into a stored per-model calibration (EMA 0.7/0.3, clamped
|
|
117
|
-
to 2..8, persisted in plugin settings).
|
|
118
|
-
|
|
125
|
+
to 2..8, persisted in plugin settings). Samples dominated by tool-call arguments
|
|
126
|
+
(far fewer visible chars than the step's output tokens) are rejected, so tool
|
|
127
|
+
runs do not drag the ratio down. After 2–3 steps the live estimate tracks the
|
|
128
|
+
real one closely. Settings → Turn speed shows and can override it.
|
|
129
|
+
- **Thinking estimate has its own ratio** — reasoning prose encodes ~3.7
|
|
130
|
+
characters per token (measured against per-step reasoning-token ground truth),
|
|
131
|
+
so `thinking ≈` divides streamed reasoning characters by that instead of the
|
|
132
|
+
visible-text calibration.
|
|
133
|
+
- **The exclusion verdict belongs to its model** — detecting that a provider
|
|
134
|
+
subtracts thinking from `output` is a property of the model behind the agent.
|
|
135
|
+
Switching models revokes the verdict immediately; a provider config change
|
|
136
|
+
under the same model (thinking suddenly inside `output`) is caught after
|
|
137
|
+
three consecutive contradicting steps, and heavy-thinking evidence re-arms it
|
|
138
|
+
the next step. When the agent's model identity is never reported, the verdict
|
|
139
|
+
is never permanent: each new turn re-derives it from fresh evidence.
|
|
140
|
+
|
|
141
|
+
Caveats: providers that never send usage cannot be judged at all (there is
|
|
142
|
+
nothing to compare the reasoning text against), and for them a reasoning
|
|
143
|
+
block delivered in one bulk after the answer text started is deliberately
|
|
144
|
+
left out of the character estimate — a bulk tells when it arrived, not how
|
|
145
|
+
long it took to generate. Such turns can be undercounted.
|
|
119
146
|
|
|
120
147
|
## Settings (Settings → Plugins → Turn speed)
|
|
121
148
|
|
|
@@ -126,7 +153,7 @@ provider config) — it feeds the `context 34k / 131k` line in the popover.
|
|
|
126
153
|
| Token format | 1.2k | compact or grouped digits |
|
|
127
154
|
| Live smoothing window | 2 s | averaging window of the live tok/s |
|
|
128
155
|
| Manual chars per token | off (auto-calibrated) | override the live character estimate |
|
|
129
|
-
| Implausible rate limit | 400 tok/s | steps implying a faster decode are dropped as misattributed usage |
|
|
156
|
+
| Implausible rate limit | 400 tok/s | steps implying a faster decode are dropped as misattributed usage; no pill ever shows a rate above the limit |
|
|
130
157
|
|
|
131
158
|
## Development
|
|
132
159
|
|
package/client/details.tsx
CHANGED
|
@@ -87,7 +87,7 @@ export function makeSpeedDetails(
|
|
|
87
87
|
}, [teamActive]);
|
|
88
88
|
const cpt = charsPerToken();
|
|
89
89
|
const running = state.phase === "running";
|
|
90
|
-
const live = running ? store.liveTokPerSec(prefs.liveWindowSec) : null;
|
|
90
|
+
const live = running ? store.liveTokPerSec(prefs.liveWindowSec, prefs.maxPlausibleTokPerSec) : null;
|
|
91
91
|
const basis = settings.status === "ready" ? settings.values.numerator : null;
|
|
92
92
|
const setBasis = (value: "live" | "decode" | "turn") => {
|
|
93
93
|
if (settings.status !== "ready" || settings.values.numerator === value) return;
|
|
@@ -101,6 +101,23 @@ export function makeSpeedDetails(
|
|
|
101
101
|
summary.firstStepPromptTokens !== null && summary.prefillMs !== null && summary.prefillMs > 0
|
|
102
102
|
? summary.firstStepPromptTokens / (summary.prefillMs / 1000)
|
|
103
103
|
: null;
|
|
104
|
+
// With a warm prefix cache the model restores the prompt instead of
|
|
105
|
+
// prefilling it: dividing new tokens by TTFT then measures cache load and
|
|
106
|
+
// queueing, not prefill speed, so only the honest pieces are shown.
|
|
107
|
+
const cacheDominant =
|
|
108
|
+
summary.firstStepCachedTokens !== null &&
|
|
109
|
+
(summary.firstStepPromptTokens ?? 0) <= summary.firstStepCachedTokens;
|
|
110
|
+
const prefillValue =
|
|
111
|
+
summary.prefillMs === null
|
|
112
|
+
? null
|
|
113
|
+
: cacheDominant
|
|
114
|
+
? `${fmtTokens(summary.firstStepPromptTokens ?? 0, prefs.tokenFormat)} new + ${fmtTokens(
|
|
115
|
+
summary.firstStepCachedTokens ?? 0,
|
|
116
|
+
prefs.tokenFormat,
|
|
117
|
+
)} cached \u00b7 ${fmtDuration(summary.prefillMs)}`
|
|
118
|
+
: prefillRate !== null
|
|
119
|
+
? `${fmtRate(prefillRate)} tok/s \u00b7 ${fmtDuration(summary.prefillMs)}`
|
|
120
|
+
: fmtDuration(summary.prefillMs);
|
|
104
121
|
const noUsage = !state.sawUsage && state.phase !== "idle";
|
|
105
122
|
|
|
106
123
|
const model = store.model ?? store.provider ?? "";
|
|
@@ -146,20 +163,23 @@ export function makeSpeedDetails(
|
|
|
146
163
|
value={fmtTokPerSec(summary.tokPerSecTurn, summary.approx)}
|
|
147
164
|
/>
|
|
148
165
|
{summary.prefillMs !== null ? (
|
|
149
|
-
<Row
|
|
150
|
-
styles={styles}
|
|
151
|
-
label="prefill / TTFT"
|
|
152
|
-
value={`${prefillRate !== null ? `${fmtRate(prefillRate)} tok/s · ` : ""}${fmtDuration(summary.prefillMs)}`}
|
|
153
|
-
/>
|
|
166
|
+
<Row styles={styles} label="prefill / TTFT" value={prefillValue ?? "\u2014"} />
|
|
154
167
|
) : null}
|
|
155
168
|
<Row
|
|
156
169
|
styles={styles}
|
|
157
170
|
label="tokens"
|
|
158
|
-
value={`in ${fmtTokens(summary.inputTokens, prefs.tokenFormat)}
|
|
171
|
+
value={`in ${fmtTokens(summary.inputTokens, prefs.tokenFormat)} \u00b7 cached ${fmtTokens(
|
|
159
172
|
summary.cachedTokens,
|
|
160
173
|
prefs.tokenFormat,
|
|
161
|
-
)}
|
|
174
|
+
)} \u00b7 out ${approx(fmtTokens(summary.estTokens, prefs.tokenFormat), summary.approx)}`}
|
|
162
175
|
/>
|
|
176
|
+
{summary.thinkingTokens >= 10 ? (
|
|
177
|
+
<Row
|
|
178
|
+
styles={styles}
|
|
179
|
+
label={"thinking \u2248"}
|
|
180
|
+
value={`${approx(fmtTokens(summary.thinkingTokens, prefs.tokenFormat), true)} tok (not in reported out)`}
|
|
181
|
+
/>
|
|
182
|
+
) : null}
|
|
163
183
|
{state.ctxUsed !== null && state.ctxMax !== null ? (
|
|
164
184
|
<Row
|
|
165
185
|
styles={styles}
|
package/client/meter.ts
CHANGED
|
@@ -21,6 +21,24 @@
|
|
|
21
21
|
* whole-turn rate — the subagents' own pills carry their speed — but it stays
|
|
22
22
|
* inside decode/wait windows, because a delegated call is just another tool
|
|
23
23
|
* run between the agent's model calls.
|
|
24
|
+
*
|
|
25
|
+
* Thinking tokens: some providers (measured on OpenCode + local reasoning
|
|
26
|
+
* models) report `output` with the reasoning tokens subtracted while the
|
|
27
|
+
* thinking itself streams as reasoning text and its decode time sits in the
|
|
28
|
+
* step window. Counting only `output` then under-reports rates by the whole
|
|
29
|
+
* thinking share. When a closed step shows far more reasoning characters
|
|
30
|
+
* than its output tokens could pay for, the meter marks the turn as
|
|
31
|
+
* `thinkingExcluded` and credits an estimate of the thinking tokens (reasoning
|
|
32
|
+
* characters divided by the reasoning-specific chars/token ratio, measured
|
|
33
|
+
* well above the visible-text one), marked approximate: reasoning that streamed
|
|
34
|
+
* from the step start covers its own window time and enters the decode rate;
|
|
35
|
+
* reasoning delivered as a late bulk (after the step's visible text began)
|
|
36
|
+
* has no measured time, so it only enters turn totals and the whole-turn
|
|
37
|
+
* rate. Providers that report thinking inside `output` never trigger this.
|
|
38
|
+
*
|
|
39
|
+
* Usage deltas the plausibility guard rejects are not dropped: they land in
|
|
40
|
+
* `unattributedTokens`, counted in token totals and the whole-turn rate
|
|
41
|
+
* without a decode window of their own.
|
|
24
42
|
*/
|
|
25
43
|
|
|
26
44
|
/** A live-window text gap longer than this is treated as a stall. */
|
|
@@ -36,6 +54,32 @@ const MAX_TEXT_KEYS = 32;
|
|
|
36
54
|
export const CAL_MIN = 2;
|
|
37
55
|
export const CAL_MAX = 8;
|
|
38
56
|
export const CAL_MIN_CHARS = 40;
|
|
57
|
+
/** A closed step whose reasoning characters exceed its output tokens by this
|
|
58
|
+
* much cannot be reporting thinking inside `output`: mark the turn as one
|
|
59
|
+
* where the provider excludes reasoning tokens from the reported numbers. */
|
|
60
|
+
export const EXCLUDED_EVIDENCE_RATIO = 8;
|
|
61
|
+
/** Below this many reasoning characters the evidence above is too noisy. */
|
|
62
|
+
export const EXCLUDED_MIN_CHARS = 200;
|
|
63
|
+
/** Reasoning prose encodes more characters per token than visible answers,
|
|
64
|
+
* and the calibrated visible ratio is additionally biased low: usage
|
|
65
|
+
* `output` counts tool-call arguments, which never stream as text. Measured
|
|
66
|
+
* across ~41k reasoning tokens of real OpenCode + local reasoning sessions:
|
|
67
|
+
* streamed reasoning text runs ~3.7 characters per reasoning token, so the
|
|
68
|
+
* thinking estimate uses this dedicated ratio instead of the model's
|
|
69
|
+
* visible-text calibration. */
|
|
70
|
+
export const REASONING_CHARS_PER_TOKEN = 3.7;
|
|
71
|
+
/** A closed step whose reported output tokens already pay for its streamed
|
|
72
|
+
* reasoning characters — at most 1.4× the reasoning ratio, headroom for
|
|
73
|
+
* token-dense prose — says thinking is inside `output`: excluded heavy
|
|
74
|
+
* thinking could not be this cheap to report. Between this and
|
|
75
|
+
* EXCLUDED_EVIDENCE_RATIO sits a neutral band that concludes nothing. A
|
|
76
|
+
* single such step can also be a tool-heavy fluke on an excluding provider,
|
|
77
|
+
* so a streak of them is needed to revoke the verdict — e.g. after the
|
|
78
|
+
* provider config started including usage differently. One excluding-style
|
|
79
|
+
* step re-arms it, so a wrong revocation costs at most a step of
|
|
80
|
+
* undercounting; without revocation a wrong verdict double-counts forever. */
|
|
81
|
+
export const INCLUSION_EVIDENCE_RATIO = REASONING_CHARS_PER_TOKEN * 1.4;
|
|
82
|
+
export const INCLUSION_EVIDENCE_STEPS = 3;
|
|
39
83
|
|
|
40
84
|
export interface UsageSnapshot {
|
|
41
85
|
input?: number | null;
|
|
@@ -56,6 +100,13 @@ export interface StepRecord {
|
|
|
56
100
|
inputTokens: number;
|
|
57
101
|
/** Cached prompt tokens this call reported. */
|
|
58
102
|
cachedTokens: number;
|
|
103
|
+
/** Reasoning characters streamed during this step (thinking estimate). */
|
|
104
|
+
thinkingChars: number;
|
|
105
|
+
/** The subset that arrived late (after the step's visible text started):
|
|
106
|
+
* a bulk delivery of the reasoning block, whose generation time the step
|
|
107
|
+
* window never saw. Their tokens count in turn totals but not in the
|
|
108
|
+
* decode-window rate. */
|
|
109
|
+
thinkingLateChars: number;
|
|
59
110
|
/** Prefill/TTFT measured on the first step only, else 0. */
|
|
60
111
|
prefillMs: number;
|
|
61
112
|
}
|
|
@@ -78,6 +129,11 @@ export interface MeterState {
|
|
|
78
129
|
lastTextAt: number | null;
|
|
79
130
|
/** First text since the last step boundary (null = re-anchored). */
|
|
80
131
|
stepFirstTextAt: number | null;
|
|
132
|
+
/** First visible-text and first reasoning growth since the step boundary.
|
|
133
|
+
* Their order tells streamed thinking (window-covering) from a late bulk
|
|
134
|
+
* delivery of a reasoning block (whose generation time the window misses). */
|
|
135
|
+
stepFirstVisibleAt: number | null;
|
|
136
|
+
stepFirstReasoningAt: number | null;
|
|
81
137
|
/** Usage arrival of the last completed step. */
|
|
82
138
|
prevStepEndAt: number | null;
|
|
83
139
|
/** Per-message observed text length (snapshot vs delta normalised). */
|
|
@@ -99,6 +155,24 @@ export interface MeterState {
|
|
|
99
155
|
liveChars: number;
|
|
100
156
|
/** All characters streamed this turn (fallback estimate). */
|
|
101
157
|
totalChars: number;
|
|
158
|
+
/** Reasoning-only characters since the last step boundary (⊆ liveChars). */
|
|
159
|
+
liveReasoningChars: number;
|
|
160
|
+
/** Reasoning-only characters streamed this turn (⊆ totalChars). */
|
|
161
|
+
totalReasoningChars: number;
|
|
162
|
+
/** Usage tokens the plausibility guard rejected, kept for whole-turn totals. */
|
|
163
|
+
unattributedTokens: number;
|
|
164
|
+
/** Set once a step showed reasoning characters no `output` figure could
|
|
165
|
+
* pay for: this provider excludes thinking from its reported output, so
|
|
166
|
+
* rates add an estimate from the streamed reasoning text. */
|
|
167
|
+
thinkingExcluded: boolean;
|
|
168
|
+
/** Model id (`model_changed`) the verdict belongs to: an exclusion is a
|
|
169
|
+
* provider-model property, so switching to a model that reports thinking
|
|
170
|
+
* inside `output` must not double-count it. Null while the identity was
|
|
171
|
+
* not yet known when the verdict was learned. */
|
|
172
|
+
thinkingExcludedModel: string | null;
|
|
173
|
+
/** Consecutive closed steps whose `output` already paid for the streamed
|
|
174
|
+
* reasoning characters; enough of them revoke a stale verdict. */
|
|
175
|
+
inclusionStreak: number;
|
|
102
176
|
/** Completed user-wait intervals inside this turn. */
|
|
103
177
|
userWaits: readonly UserWaitInterval[];
|
|
104
178
|
/** Start of the open user-wait interval, null when the model is live. */
|
|
@@ -119,7 +193,7 @@ export interface MeterState {
|
|
|
119
193
|
|
|
120
194
|
export type MeterAction =
|
|
121
195
|
| { t: "turn_started"; at: number; turnId: string | null }
|
|
122
|
-
| { t: "text"; at: number; key: string; text: string }
|
|
196
|
+
| { t: "text"; at: number; key: string; text: string; kind?: "text" | "reasoning" }
|
|
123
197
|
| { t: "usage"; at: number; usage: UsageSnapshot; maxTokPerSec?: number }
|
|
124
198
|
| { t: "compaction"; at: number }
|
|
125
199
|
/** The model blocked on the user (question asked, permission pending). */
|
|
@@ -131,6 +205,9 @@ export type MeterAction =
|
|
|
131
205
|
/** All subagents finished: the agent works alone again. */
|
|
132
206
|
| { t: "delegated_ended"; at: number }
|
|
133
207
|
| { t: "turn_ended"; at: number; kind: "completed" | "failed" | "canceled"; usage?: UsageSnapshot; maxTokPerSec?: number; note?: string | null }
|
|
208
|
+
/** The agent switched model (or its identity just became known): a
|
|
209
|
+
* thinking-exclusion verdict learned on another model must not carry. */
|
|
210
|
+
| { t: "model_changed"; model: string | null }
|
|
134
211
|
/** Drop the locally observed turn (epoch replacement, reconnect, reload). */
|
|
135
212
|
| { t: "reset" };
|
|
136
213
|
|
|
@@ -142,6 +219,8 @@ export function initialMeterState(): MeterState {
|
|
|
142
219
|
firstTextAt: null,
|
|
143
220
|
lastTextAt: null,
|
|
144
221
|
stepFirstTextAt: null,
|
|
222
|
+
stepFirstVisibleAt: null,
|
|
223
|
+
stepFirstReasoningAt: null,
|
|
145
224
|
prevStepEndAt: null,
|
|
146
225
|
textLens: {},
|
|
147
226
|
textTails: {},
|
|
@@ -156,6 +235,12 @@ export function initialMeterState(): MeterState {
|
|
|
156
235
|
steps: [],
|
|
157
236
|
liveChars: 0,
|
|
158
237
|
totalChars: 0,
|
|
238
|
+
liveReasoningChars: 0,
|
|
239
|
+
totalReasoningChars: 0,
|
|
240
|
+
unattributedTokens: 0,
|
|
241
|
+
thinkingExcluded: false,
|
|
242
|
+
thinkingExcludedModel: null,
|
|
243
|
+
inclusionStreak: 0,
|
|
159
244
|
userWaits: [],
|
|
160
245
|
pausedAt: null,
|
|
161
246
|
delegatedWaits: [],
|
|
@@ -207,7 +292,13 @@ function growText(
|
|
|
207
292
|
return { lens, tails, growth };
|
|
208
293
|
}
|
|
209
294
|
|
|
210
|
-
function applyText(
|
|
295
|
+
function applyText(
|
|
296
|
+
state: MeterState,
|
|
297
|
+
at: number,
|
|
298
|
+
key: string,
|
|
299
|
+
text: string,
|
|
300
|
+
isReasoning: boolean,
|
|
301
|
+
): MeterState {
|
|
211
302
|
if (state.phase !== "running" || text.length === 0) return state;
|
|
212
303
|
const { lens, tails, growth } = growText(state, key, text);
|
|
213
304
|
if (growth <= 0) return state;
|
|
@@ -217,9 +308,15 @@ function applyText(state: MeterState, at: number, key: string, text: string): Me
|
|
|
217
308
|
textTails: tails,
|
|
218
309
|
firstTextAt: state.firstTextAt === null ? at : state.firstTextAt,
|
|
219
310
|
stepFirstTextAt: state.stepFirstTextAt === null ? at : state.stepFirstTextAt,
|
|
311
|
+
stepFirstVisibleAt:
|
|
312
|
+
!isReasoning && state.stepFirstVisibleAt === null ? at : state.stepFirstVisibleAt,
|
|
313
|
+
stepFirstReasoningAt:
|
|
314
|
+
isReasoning && state.stepFirstReasoningAt === null ? at : state.stepFirstReasoningAt,
|
|
220
315
|
lastTextAt: at,
|
|
221
316
|
liveChars: state.liveChars + growth,
|
|
222
317
|
totalChars: state.totalChars + growth,
|
|
318
|
+
liveReasoningChars: isReasoning ? state.liveReasoningChars + growth : state.liveReasoningChars,
|
|
319
|
+
totalReasoningChars: isReasoning ? state.totalReasoningChars + growth : state.totalReasoningChars,
|
|
223
320
|
};
|
|
224
321
|
}
|
|
225
322
|
|
|
@@ -348,6 +445,9 @@ function applyUsage(
|
|
|
348
445
|
return {
|
|
349
446
|
...withCounters,
|
|
350
447
|
calibInput: null,
|
|
448
|
+
// Real tokens with no trustworthy window of their own: keep them in
|
|
449
|
+
// the turn totals instead of letting them vanish from every rate.
|
|
450
|
+
unattributedTokens: state.unattributedTokens + outDelta.amount,
|
|
351
451
|
stepRejected: { tokens: outDelta.amount, windowMs: stepDecodeMs },
|
|
352
452
|
};
|
|
353
453
|
}
|
|
@@ -355,23 +455,59 @@ function applyUsage(
|
|
|
355
455
|
state.steps.length === 0 && state.firstTextAt !== null && state.startedAt !== null
|
|
356
456
|
? Math.max(0, state.firstTextAt - state.startedAt)
|
|
357
457
|
: 0;
|
|
458
|
+
// Reasoning that showed up only after this step's visible text was already
|
|
459
|
+
// streaming is a bulk delivery of the finished block: the window missed
|
|
460
|
+
// its generation. Reasoning that led (or carried) the window covered it.
|
|
461
|
+
const reasoningLate =
|
|
462
|
+
state.liveReasoningChars > 0 &&
|
|
463
|
+
state.stepFirstVisibleAt !== null &&
|
|
464
|
+
(state.stepFirstReasoningAt === null || state.stepFirstReasoningAt > state.stepFirstVisibleAt);
|
|
358
465
|
const step: StepRecord = {
|
|
359
466
|
outTokens: outDelta.amount,
|
|
360
467
|
decodeMs: stepDecodeMs,
|
|
361
468
|
waitMs: stepWaitMs,
|
|
362
469
|
inputTokens: inDelta.amount,
|
|
363
470
|
cachedTokens: cachedDelta.amount,
|
|
471
|
+
thinkingChars: state.liveReasoningChars,
|
|
472
|
+
thinkingLateChars: reasoningLate ? state.liveReasoningChars : 0,
|
|
364
473
|
prefillMs,
|
|
365
474
|
};
|
|
475
|
+
// More streamed reasoning characters than this step's output tokens could
|
|
476
|
+
// possibly contain: the provider subtracts thinking from `output`.
|
|
477
|
+
const thinkingEvidence =
|
|
478
|
+
state.liveReasoningChars >= EXCLUDED_MIN_CHARS &&
|
|
479
|
+
state.liveReasoningChars > outDelta.amount * EXCLUDED_EVIDENCE_RATIO;
|
|
480
|
+
// The opposite signal: this step streamed meaningful reasoning yet its
|
|
481
|
+
// reported output tokens alone already pay for those characters, meaning
|
|
482
|
+
// the thinking is inside `output`. A single such step can also be a
|
|
483
|
+
// tool-heavy step on an excluding provider, so a streak of them is needed
|
|
484
|
+
// to revoke the verdict; one excluding-style step re-arms it.
|
|
485
|
+
const inclusionEvidence =
|
|
486
|
+
state.thinkingExcluded &&
|
|
487
|
+
!thinkingEvidence &&
|
|
488
|
+
state.liveReasoningChars >= EXCLUDED_MIN_CHARS &&
|
|
489
|
+
state.liveReasoningChars <= outDelta.amount * INCLUSION_EVIDENCE_RATIO;
|
|
490
|
+
const inclusionStreak = inclusionEvidence ? state.inclusionStreak + 1 : 0;
|
|
491
|
+
const revoked = inclusionStreak >= INCLUSION_EVIDENCE_STEPS;
|
|
366
492
|
return {
|
|
367
493
|
...withCounters,
|
|
368
494
|
steps: [...state.steps, step],
|
|
369
495
|
stepFirstTextAt: null,
|
|
496
|
+
stepFirstVisibleAt: null,
|
|
497
|
+
stepFirstReasoningAt: null,
|
|
370
498
|
prevStepEndAt: at,
|
|
371
499
|
liveChars: 0,
|
|
500
|
+
liveReasoningChars: 0,
|
|
372
501
|
sawUsage: true,
|
|
502
|
+
thinkingExcluded: revoked ? false : state.thinkingExcluded || thinkingEvidence,
|
|
503
|
+
inclusionStreak: revoked ? 0 : inclusionStreak,
|
|
373
504
|
stepRejected: null,
|
|
374
|
-
|
|
505
|
+
// Calibration pairs visible characters with visible tokens: reasoning
|
|
506
|
+
// text must not enter it, or the ratio saturates against excluded output.
|
|
507
|
+
calibInput: {
|
|
508
|
+
chars: state.liveChars - state.liveReasoningChars,
|
|
509
|
+
tokens: outDelta.amount,
|
|
510
|
+
},
|
|
375
511
|
};
|
|
376
512
|
}
|
|
377
513
|
|
|
@@ -414,16 +550,34 @@ export function reduceMeter(state: MeterState, action: MeterAction): MeterState
|
|
|
414
550
|
prevUsageOut: state.prevUsageOut,
|
|
415
551
|
prevUsageIn: state.prevUsageIn,
|
|
416
552
|
prevUsageCached: state.prevUsageCached,
|
|
553
|
+
// A provider-level property: survives turns like the usage baseline
|
|
554
|
+
// — but only when it has a known owner. A verdict that never got a
|
|
555
|
+
// model identity cannot tell an unchanged provider from an invisible
|
|
556
|
+
// model switch, so each new turn re-derives it from fresh evidence.
|
|
557
|
+
thinkingExcluded:
|
|
558
|
+
state.thinkingExcludedModel === null ? false : state.thinkingExcluded,
|
|
559
|
+
thinkingExcludedModel: state.thinkingExcludedModel,
|
|
560
|
+
inclusionStreak: state.thinkingExcludedModel === null ? 0 : state.inclusionStreak,
|
|
417
561
|
};
|
|
418
562
|
}
|
|
419
563
|
case "text":
|
|
420
|
-
return applyText(
|
|
564
|
+
return applyText(
|
|
565
|
+
state,
|
|
566
|
+
action.at,
|
|
567
|
+
action.key,
|
|
568
|
+
action.text,
|
|
569
|
+
action.kind === "reasoning" ||
|
|
570
|
+
// Backwards compatibility with callers using the legacy key scheme.
|
|
571
|
+
(action.kind === undefined && action.key.startsWith("reasoning")),
|
|
572
|
+
);
|
|
421
573
|
case "usage":
|
|
422
574
|
return applyUsage(state, action.at, action.usage, action.maxTokPerSec);
|
|
423
575
|
case "compaction":
|
|
424
576
|
// Context was rewritten; streamed chars since the last step no longer
|
|
425
577
|
// map to answer tokens. Drop the live window, keep step history.
|
|
426
|
-
return state.phase === "running"
|
|
578
|
+
return state.phase === "running"
|
|
579
|
+
? { ...state, liveChars: 0, liveReasoningChars: 0 }
|
|
580
|
+
: state;
|
|
427
581
|
case "user_wait_started":
|
|
428
582
|
return state.phase === "running" && state.pausedAt === null
|
|
429
583
|
? { ...state, pausedAt: action.at }
|
|
@@ -451,7 +605,29 @@ export function reduceMeter(state: MeterState, action: MeterAction): MeterState
|
|
|
451
605
|
prevUsageOut: state.prevUsageOut,
|
|
452
606
|
prevUsageIn: state.prevUsageIn,
|
|
453
607
|
prevUsageCached: state.prevUsageCached,
|
|
608
|
+
thinkingExcluded: state.thinkingExcluded,
|
|
609
|
+
thinkingExcludedModel: state.thinkingExcludedModel,
|
|
610
|
+
inclusionStreak: state.inclusionStreak,
|
|
454
611
|
};
|
|
612
|
+
case "model_changed": {
|
|
613
|
+
const model = action.model;
|
|
614
|
+
// An unknown identity must never clear a learned verdict: the model
|
|
615
|
+
// simply is not on record yet.
|
|
616
|
+
if (model === null || model === state.thinkingExcludedModel) return state;
|
|
617
|
+
// A verdict learned before identity was known belongs to it: adopt
|
|
618
|
+
// rather than revoke, the first concrete model is what we observed.
|
|
619
|
+
if (state.thinkingExcluded && state.thinkingExcludedModel === null) {
|
|
620
|
+
return { ...state, thinkingExcludedModel: model };
|
|
621
|
+
}
|
|
622
|
+
// Another model: the exclusion verdict was its property, not this
|
|
623
|
+
// model's. Steps of the current turn stay; only the verdict resets.
|
|
624
|
+
return {
|
|
625
|
+
...state,
|
|
626
|
+
thinkingExcluded: false,
|
|
627
|
+
thinkingExcludedModel: model,
|
|
628
|
+
inclusionStreak: 0,
|
|
629
|
+
};
|
|
630
|
+
}
|
|
455
631
|
default:
|
|
456
632
|
return state;
|
|
457
633
|
}
|
|
@@ -492,6 +668,14 @@ export interface TurnSummary {
|
|
|
492
668
|
cachedTokens: number;
|
|
493
669
|
/** Prompt tokens of the first step, for the prefill rate. */
|
|
494
670
|
firstStepPromptTokens: number | null;
|
|
671
|
+
/** Cached prompt tokens of the first step: with a warm cache the prompt
|
|
672
|
+
* was restored, not prefilled, so the prefill rate is hidden then. */
|
|
673
|
+
firstStepCachedTokens: number | null;
|
|
674
|
+
/** Thinking tokens estimated from streamed reasoning characters (0 when
|
|
675
|
+
* the provider reports thinking inside `output` or none was streamed). */
|
|
676
|
+
thinkingTokens: number;
|
|
677
|
+
/** Tokens from rejected usage bursts, counted in totals without a window. */
|
|
678
|
+
unattributedTokens: number;
|
|
495
679
|
}
|
|
496
680
|
|
|
497
681
|
export function summarizeTurn(state: MeterState, charsPerToken: number, now: number): TurnSummary {
|
|
@@ -499,24 +683,64 @@ export function summarizeTurn(state: MeterState, charsPerToken: number, now: num
|
|
|
499
683
|
const inputTokens = state.steps.reduce((sum, s) => sum + s.inputTokens, 0);
|
|
500
684
|
const cachedTokens = state.steps.reduce((sum, s) => sum + s.cachedTokens, 0);
|
|
501
685
|
const waitMs = state.steps.reduce((sum, s) => sum + s.waitMs, 0);
|
|
686
|
+
const hasReal = state.sawUsage && realOut > 0;
|
|
502
687
|
// Without any usage step there is no anchored window; the span of streamed
|
|
503
688
|
// text stands in for it so estimate-only providers still get a decode rate.
|
|
689
|
+
// While a step is open, its streamed characters already sit in `estTokens`
|
|
690
|
+
// (as the tail estimate), so the running window from its first text counts
|
|
691
|
+
// in the decode denominator too: freezing it at the closed steps would
|
|
692
|
+
// divide a growing token count by stale windows and print a burst rate.
|
|
693
|
+
const openWindowMs =
|
|
694
|
+
state.phase === "running" && state.stepFirstTextAt !== null && state.liveChars > 0
|
|
695
|
+
? Math.max(
|
|
696
|
+
0,
|
|
697
|
+
now - state.stepFirstTextAt - waitOverlap(state, state.stepFirstTextAt, now),
|
|
698
|
+
)
|
|
699
|
+
: 0;
|
|
504
700
|
const decodeMs =
|
|
505
701
|
state.steps.length > 0
|
|
506
|
-
? state.steps.reduce((sum, s) => sum + s.decodeMs, 0)
|
|
702
|
+
? state.steps.reduce((sum, s) => sum + s.decodeMs, 0) + openWindowMs
|
|
507
703
|
: state.firstTextAt !== null && state.lastTextAt !== null
|
|
508
704
|
? Math.max(0, state.lastTextAt - state.firstTextAt)
|
|
509
705
|
: 0;
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
706
|
+
// Thinking estimate for providers detected as excluding reasoning from
|
|
707
|
+
// `output`: reasoning characters converted with the reasoning-specific
|
|
708
|
+
// chars/token ratio (visible-text calibration is biased by tool args).
|
|
709
|
+
// Early thinking (reasoning led the step window) both adds tokens and was
|
|
710
|
+
// paid for by window time; late bulks add tokens only, so they may count
|
|
711
|
+
// in turn totals but never in the decode-window rate.
|
|
712
|
+
const stepThinkingChars = state.steps.reduce((sum, s) => sum + s.thinkingChars, 0);
|
|
713
|
+
const earlyThinking = state.thinkingExcluded
|
|
714
|
+
? state.steps.reduce((sum, s) => sum + (s.thinkingChars - s.thinkingLateChars), 0) /
|
|
715
|
+
REASONING_CHARS_PER_TOKEN
|
|
716
|
+
: 0;
|
|
717
|
+
const lateThinking = state.thinkingExcluded
|
|
718
|
+
? state.steps.reduce((sum, s) => sum + s.thinkingLateChars, 0) / REASONING_CHARS_PER_TOKEN
|
|
719
|
+
: 0;
|
|
720
|
+
// Live reasoning characters enter the tail estimate only while reasoning
|
|
721
|
+
// leads the open step (its arrival was paced with generation). A trailing
|
|
722
|
+
// bulk of a finished reasoning block would fake a token burst.
|
|
723
|
+
const liveReasoningEarly =
|
|
724
|
+
state.stepFirstReasoningAt !== null &&
|
|
725
|
+
(state.stepFirstVisibleAt === null || state.stepFirstReasoningAt <= state.stepFirstVisibleAt);
|
|
726
|
+
const thinkingTokens = state.thinkingExcluded && hasReal
|
|
727
|
+
? (stepThinkingChars + (liveReasoningEarly ? state.liveReasoningChars : 0)) /
|
|
728
|
+
REASONING_CHARS_PER_TOKEN
|
|
729
|
+
: 0;
|
|
730
|
+
const tailEst =
|
|
731
|
+
(state.liveChars - state.liveReasoningChars) / charsPerToken +
|
|
732
|
+
(liveReasoningEarly ? state.liveReasoningChars / REASONING_CHARS_PER_TOKEN : 0);
|
|
733
|
+
const wholeEst =
|
|
734
|
+
(state.totalChars - state.totalReasoningChars) / charsPerToken +
|
|
735
|
+
(state.totalReasoningChars - (liveReasoningEarly ? 0 : state.liveReasoningChars)) /
|
|
736
|
+
REASONING_CHARS_PER_TOKEN;
|
|
513
737
|
let outTokens: number | null = null;
|
|
514
738
|
let estTokens: number;
|
|
515
739
|
let approx: boolean;
|
|
516
740
|
if (hasReal) {
|
|
517
741
|
outTokens = realOut;
|
|
518
|
-
estTokens = realOut + tailEst;
|
|
519
|
-
approx = state.liveChars > 0;
|
|
742
|
+
estTokens = realOut + earlyThinking + lateThinking + tailEst + state.unattributedTokens;
|
|
743
|
+
approx = state.liveChars > 0 || earlyThinking + lateThinking > 0 || state.unattributedTokens > 0;
|
|
520
744
|
} else {
|
|
521
745
|
estTokens = wholeEst;
|
|
522
746
|
approx = true;
|
|
@@ -543,10 +767,14 @@ export function summarizeTurn(state: MeterState, charsPerToken: number, now: num
|
|
|
543
767
|
totalMs !== null && state.startedAt !== null && end !== null
|
|
544
768
|
? Math.max(0, totalMs - unionOverlapMs(asleep, state.startedAt, end))
|
|
545
769
|
: null;
|
|
770
|
+
// Rejected bursts and late thinking bulks have no decode window of their
|
|
771
|
+
// own, so they count in the whole-turn totals but never inflate the
|
|
772
|
+
// decode-window rate.
|
|
773
|
+
const decodeTokens = hasReal ? estTokens - state.unattributedTokens - lateThinking : estTokens;
|
|
546
774
|
const tokPerSecDecode =
|
|
547
|
-
decodeMs > 0 &&
|
|
775
|
+
decodeMs > 0 && decodeTokens > 0 ? decodeTokens / (decodeMs / 1000) : null;
|
|
548
776
|
const tokPerSecTurn =
|
|
549
|
-
activeMs !== null && activeMs > 0 && estTokens > 0 ?
|
|
777
|
+
activeMs !== null && activeMs > 0 && estTokens > 0 ? estTokens / (activeMs / 1000) : null;
|
|
550
778
|
return {
|
|
551
779
|
outTokens,
|
|
552
780
|
estTokens,
|
|
@@ -565,6 +793,9 @@ export function summarizeTurn(state: MeterState, charsPerToken: number, now: num
|
|
|
565
793
|
inputTokens,
|
|
566
794
|
cachedTokens,
|
|
567
795
|
firstStepPromptTokens: state.steps.length > 0 && state.steps[0].inputTokens > 0 ? state.steps[0].inputTokens : null,
|
|
796
|
+
firstStepCachedTokens: state.steps.length > 0 && state.steps[0].cachedTokens > 0 ? state.steps[0].cachedTokens : null,
|
|
797
|
+
thinkingTokens,
|
|
798
|
+
unattributedTokens: state.unattributedTokens,
|
|
568
799
|
};
|
|
569
800
|
}
|
|
570
801
|
|
|
@@ -579,7 +810,12 @@ export function calibrate(
|
|
|
579
810
|
): number | null {
|
|
580
811
|
if (!(tokens > 0) || !(chars >= minChars)) return null;
|
|
581
812
|
const observed = chars / tokens;
|
|
582
|
-
|
|
813
|
+
// Below 1.5 char/token the sample is dominated by tool-call arguments
|
|
814
|
+
// (counted in `output` but never streamed as text), not this model's text
|
|
815
|
+
// ratio; above 12 it is usage bookkeeping noise (misattributed deltas).
|
|
816
|
+
// Either end poisons the EMA toward the clamps (a single 20+ sample used to
|
|
817
|
+
// pin the blend at CAL_MAX).
|
|
818
|
+
if (!Number.isFinite(observed) || observed < 1.5 || observed > 12) return null;
|
|
583
819
|
const base = typeof prev === "number" && Number.isFinite(prev) ? prev : DEFAULT_CHARS_PER_TOKEN;
|
|
584
820
|
const next = 0.7 * base + 0.3 * observed;
|
|
585
821
|
return Math.min(CAL_MAX, Math.max(CAL_MIN, next));
|
package/client/pill.tsx
CHANGED
|
@@ -13,15 +13,20 @@ export interface PillView {
|
|
|
13
13
|
title: string;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
/** Number the pill leads with, per the speed-basis preference.
|
|
16
|
+
/** Number the pill leads with, per the speed-basis preference. Rates above
|
|
17
|
+
* the plausibility limit are bookkeeping artifacts, not speed: show nothing
|
|
18
|
+
* rather than a fabricated burst. */
|
|
17
19
|
function headlineTokPerSec(store: AgentSpeedStore, prefs: Preferences, now: number): number | null {
|
|
18
20
|
const summary = store.summary(now);
|
|
21
|
+
const plausible = (rate: number | null): number | null =>
|
|
22
|
+
rate !== null && rate > prefs.maxPlausibleTokPerSec ? null : rate;
|
|
19
23
|
if (store.isRunning() && prefs.numerator === "live") {
|
|
20
|
-
const live = store.liveTokPerSec(prefs.liveWindowSec);
|
|
24
|
+
const live = store.liveTokPerSec(prefs.liveWindowSec, prefs.maxPlausibleTokPerSec);
|
|
21
25
|
if (live !== null) return live;
|
|
22
26
|
}
|
|
23
|
-
if (prefs.numerator === "turn")
|
|
24
|
-
|
|
27
|
+
if (prefs.numerator === "turn")
|
|
28
|
+
return plausible(summary.tokPerSecTurn ?? summary.tokPerSecDecode);
|
|
29
|
+
return plausible(summary.tokPerSecDecode ?? summary.tokPerSecTurn);
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
export function computePillView(
|
|
@@ -56,19 +61,16 @@ export function computePillView(
|
|
|
56
61
|
if (phase === "failed") labelParts.push("\u00b7 failed");
|
|
57
62
|
if (phase === "canceled") labelParts.push("\u00b7 canceled");
|
|
58
63
|
const titleParts = [`Turn speed ${rateText} decode`];
|
|
59
|
-
if (waiting) titleParts.push("waiting
|
|
64
|
+
if (waiting) titleParts.push("waiting");
|
|
60
65
|
if (teamRunning) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
`${teamLabel}
|
|
68
|
-
|
|
69
|
-
} else {
|
|
70
|
-
titleParts.push(`${teamLabel} working`);
|
|
71
|
-
}
|
|
66
|
+
// Keep the sheet title on one phone line: the short `N sub` form matches
|
|
67
|
+
// the pill label; the full breakdown is in the popover body.
|
|
68
|
+
const teamLabel = `${teamRunning.running} sub`;
|
|
69
|
+
titleParts.push(
|
|
70
|
+
teamRunning.liveTokPerSec === null
|
|
71
|
+
? teamLabel
|
|
72
|
+
: `${teamLabel} @ ${approx(fmtRate(teamRunning.liveTokPerSec), teamRunning.approx)} tok/s`,
|
|
73
|
+
);
|
|
72
74
|
}
|
|
73
75
|
if (summary.estTokens > 0) {
|
|
74
76
|
titleParts.push(`${approx(fmtTokens(summary.estTokens, prefs.tokenFormat), isApprox)} tok`);
|
package/client/store.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
reduceMeter,
|
|
5
5
|
summarizeTurn,
|
|
6
6
|
DEFAULT_CHARS_PER_TOKEN,
|
|
7
|
+
REASONING_CHARS_PER_TOKEN,
|
|
7
8
|
type MeterAction,
|
|
8
9
|
type MeterState,
|
|
9
10
|
type TurnSummary,
|
|
@@ -47,7 +48,7 @@ export interface AgentSpeedStore {
|
|
|
47
48
|
readonly everSawUsage: boolean;
|
|
48
49
|
setIdentity(provider: string | null | undefined, model: string | null | undefined): void;
|
|
49
50
|
dispatch(action: MeterAction): void;
|
|
50
|
-
liveTokPerSec(windowSec: number): number | null;
|
|
51
|
+
liveTokPerSec(windowSec: number, maxTokPerSec?: number): number | null;
|
|
51
52
|
summary(now?: number): TurnSummary;
|
|
52
53
|
isRunning(): boolean;
|
|
53
54
|
}
|
|
@@ -124,8 +125,14 @@ export function createAgentSpeedStore(deps: AgentSpeedStoreDeps): AgentSpeedStor
|
|
|
124
125
|
const resolvedProvider = nextProvider ?? provider;
|
|
125
126
|
const resolvedModel = nextModel ?? model;
|
|
126
127
|
if (resolvedProvider === provider && resolvedModel === model) return;
|
|
128
|
+
const modelChanged = resolvedModel !== null && resolvedModel !== model;
|
|
127
129
|
provider = resolvedProvider;
|
|
128
130
|
model = resolvedModel;
|
|
131
|
+
// The exclusion verdict is a property of the model behind the agent:
|
|
132
|
+
// switching models clears it in the reducer. A not-yet-known identity
|
|
133
|
+
// dispatches nothing, so the first `setIdentity(…, null)` cannot undo
|
|
134
|
+
// a verdict learned earlier.
|
|
135
|
+
if (modelChanged) store.dispatch({ t: "model_changed", model: resolvedModel });
|
|
129
136
|
emit();
|
|
130
137
|
},
|
|
131
138
|
dispatch(action) {
|
|
@@ -134,12 +141,26 @@ export function createAgentSpeedStore(deps: AgentSpeedStoreDeps): AgentSpeedStor
|
|
|
134
141
|
if (action.t === "usage" && action.usage.output != null) everSawUsage = true;
|
|
135
142
|
if (next === state) return;
|
|
136
143
|
state = next;
|
|
144
|
+
if (action.t === "model_changed") {
|
|
145
|
+
console.log(
|
|
146
|
+
`turn-speed: model [${deps.agentId.slice(0, 8)}] now=${action.model ?? "?"}` +
|
|
147
|
+
` thinking-verdict=${next.thinkingExcluded ? "excluded" : "unknown"}` +
|
|
148
|
+
`${next.thinkingExcludedModel ? ` (learned on ${next.thinkingExcludedModel})` : ""}`,
|
|
149
|
+
);
|
|
150
|
+
}
|
|
137
151
|
if (next.steps.length > prev.steps.length) {
|
|
138
152
|
const step = next.steps[next.steps.length - 1];
|
|
139
|
-
const
|
|
153
|
+
const thinking = next.thinkingExcluded
|
|
154
|
+
? (step.thinkingChars - step.thinkingLateChars) / REASONING_CHARS_PER_TOKEN
|
|
155
|
+
: 0;
|
|
156
|
+
const rate =
|
|
157
|
+
step.decodeMs > 0 ? ((step.outTokens + thinking) / (step.decodeMs / 1000)).toFixed(1) : "inf";
|
|
158
|
+
const thinkPart =
|
|
159
|
+
step.thinkingChars > 0 ? ` thinkChars=${step.thinkingChars} think~${Math.round(thinking)}` : "";
|
|
140
160
|
console.log(
|
|
141
|
-
`turn-speed: step ok [${deps.agentId.slice(0, 8)}] out=${step.outTokens} in=${step.inputTokens}` +
|
|
142
|
-
` cached=${step.cachedTokens} decodeMs=${Math.round(step.decodeMs)} waitMs=${Math.round(step.waitMs)}
|
|
161
|
+
`turn-speed: step ok [${deps.agentId.slice(0, 8)}] out=${step.outTokens}${thinkPart} in=${step.inputTokens}` +
|
|
162
|
+
` cached=${step.cachedTokens} decodeMs=${Math.round(step.decodeMs)} waitMs=${Math.round(step.waitMs)}` +
|
|
163
|
+
` rate=${rate} verdict=${next.thinkingExcluded ? "excluded" : "off"}`,
|
|
143
164
|
);
|
|
144
165
|
}
|
|
145
166
|
if (next.stepRejected) {
|
|
@@ -149,7 +170,7 @@ export function createAgentSpeedStore(deps: AgentSpeedStoreDeps): AgentSpeedStor
|
|
|
149
170
|
console.log(
|
|
150
171
|
`turn-speed: step dropped as implausible [${deps.agentId.slice(0, 8)}]` +
|
|
151
172
|
` tokens=${next.stepRejected.tokens} windowMs=${Math.round(next.stepRejected.windowMs)}` +
|
|
152
|
-
" (
|
|
173
|
+
" (late or aggregated usage; kept in the turn totals as unattributed tokens)",
|
|
153
174
|
);
|
|
154
175
|
}
|
|
155
176
|
}
|
|
@@ -165,7 +186,7 @@ export function createAgentSpeedStore(deps: AgentSpeedStoreDeps): AgentSpeedStor
|
|
|
165
186
|
pushSample();
|
|
166
187
|
emit();
|
|
167
188
|
},
|
|
168
|
-
liveTokPerSec(windowSec) {
|
|
189
|
+
liveTokPerSec(windowSec: number, maxTokPerSec?: number) {
|
|
169
190
|
const windowMs = Math.max(0.5, windowSec) * 1000;
|
|
170
191
|
const at = now();
|
|
171
192
|
const cutoff = at - windowMs;
|
|
@@ -186,7 +207,11 @@ export function createAgentSpeedStore(deps: AgentSpeedStoreDeps): AgentSpeedStor
|
|
|
186
207
|
if (spanMs < 250) return null;
|
|
187
208
|
const tokens = last.est - first.est;
|
|
188
209
|
if (tokens <= 0) return null;
|
|
189
|
-
|
|
210
|
+
const rate = tokens / (spanMs / 1000);
|
|
211
|
+
// Beyond the plausibility cap the window holds a bookkeeping jump
|
|
212
|
+
// (aggregated usage, reasoning bulk), not streaming speed: no number.
|
|
213
|
+
if (maxTokPerSec !== undefined && rate > maxTokPerSec) return null;
|
|
214
|
+
return rate;
|
|
190
215
|
},
|
|
191
216
|
summary,
|
|
192
217
|
isRunning() {
|
package/client/team.ts
CHANGED
|
@@ -54,6 +54,7 @@ export function summarizeTeam(
|
|
|
54
54
|
members: readonly TeamMemberInput[],
|
|
55
55
|
windowSec: number,
|
|
56
56
|
now: number,
|
|
57
|
+
maxTokPerSec?: number,
|
|
57
58
|
): TeamView {
|
|
58
59
|
const views: TeamMemberView[] = [];
|
|
59
60
|
let running = 0;
|
|
@@ -63,7 +64,7 @@ export function summarizeTeam(
|
|
|
63
64
|
for (const member of members) {
|
|
64
65
|
const isRunning = member.store.isRunning();
|
|
65
66
|
const summary = member.store.summary(now);
|
|
66
|
-
const liveTokPerSec = isRunning ? member.store.liveTokPerSec(windowSec) : null;
|
|
67
|
+
const liveTokPerSec = isRunning ? member.store.liveTokPerSec(windowSec, maxTokPerSec) : null;
|
|
67
68
|
views.push({
|
|
68
69
|
id: member.id,
|
|
69
70
|
title: member.title,
|
package/index.client.tsx
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
type MeterStateDoc,
|
|
15
15
|
type Preferences,
|
|
16
16
|
} from "./shared/preferences";
|
|
17
|
-
import { DEFAULT_CHARS_PER_TOKEN } from "./client/meter";
|
|
17
|
+
import { DEFAULT_CHARS_PER_TOKEN, CAL_MAX } from "./client/meter";
|
|
18
18
|
|
|
19
19
|
// Structural type derivation keeps `@getpaseo/client` out of the client
|
|
20
20
|
// bundle: only types provided through the plugin context are used.
|
|
@@ -150,8 +150,20 @@ export default function contribute(client: PluginClientContext) {
|
|
|
150
150
|
const parsed = meterState.schema.safeParse(read.values);
|
|
151
151
|
if (parsed.success) {
|
|
152
152
|
calibration.clear();
|
|
153
|
+
const saturated: string[] = [];
|
|
153
154
|
for (const [model, cpt] of Object.entries(parsed.data.calibration)) {
|
|
154
|
-
|
|
155
|
+
// Entries pinned at CAL_MAX were produced by the pre-1.2 bug
|
|
156
|
+
// that charged reasoning characters against reasoning-free
|
|
157
|
+
// output tokens: drop them and let them relearn cleanly.
|
|
158
|
+
if (cpt >= CAL_MAX) saturated.push(model);
|
|
159
|
+
else calibration.set(model, cpt);
|
|
160
|
+
}
|
|
161
|
+
if (saturated.length > 0) {
|
|
162
|
+
void mutateDoc(meterState, (doc) => {
|
|
163
|
+
const next = { ...doc.calibration };
|
|
164
|
+
for (const model of saturated) delete next[model];
|
|
165
|
+
return { calibration: next };
|
|
166
|
+
});
|
|
155
167
|
}
|
|
156
168
|
}
|
|
157
169
|
}
|
|
@@ -295,6 +307,7 @@ export default function contribute(client: PluginClientContext) {
|
|
|
295
307
|
at,
|
|
296
308
|
key: `reasoning:${event.turnId ?? "current"}`,
|
|
297
309
|
text: item.text,
|
|
310
|
+
kind: "reasoning",
|
|
298
311
|
});
|
|
299
312
|
} else if (item.type === "compaction") {
|
|
300
313
|
store.dispatch({ t: "compaction", at });
|
|
@@ -457,7 +470,12 @@ export default function contribute(client: PluginClientContext) {
|
|
|
457
470
|
store.dispatch({ t: should ? "delegated_started" : "delegated_ended", at: Date.now() });
|
|
458
471
|
};
|
|
459
472
|
const team = () => {
|
|
460
|
-
const view = summarizeTeam(
|
|
473
|
+
const view = summarizeTeam(
|
|
474
|
+
teamMembers(agent.id),
|
|
475
|
+
prefs.liveWindowSec,
|
|
476
|
+
Date.now(),
|
|
477
|
+
prefs.maxPlausibleTokPerSec,
|
|
478
|
+
);
|
|
461
479
|
// Open sub_agent tool calls count too: on provider subagents (no
|
|
462
480
|
// linked Paseo child) they are the only running signal.
|
|
463
481
|
const running = Math.max(view.running, subCalls.size);
|