paseo-turn-speed 1.4.0 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -41,6 +41,33 @@ The same popover on mobile, with the `pill shows` basis chips:
41
41
 
42
42
  <img src="images/mobile-popover.png" alt="Mobile popover" width="300">
43
43
 
44
+ ## How this differs from Paseo's own turn stats
45
+
46
+ Paseo [0.17.2](https://paseo.sh/changelog#release-0.17.2) added a stats icon to a
47
+ completed turn's footer ([#10496](https://github.com/getpaseo/paseo/pull/10496)):
48
+ the provider's own rows for that turn, plus session rows in the context-window
49
+ popover. It answers *what did that turn cost*; this plugin answers *what is it
50
+ doing right now*, so both can stay on and neither hides the other.
51
+
52
+ | | Paseo turn stats | turn-speed |
53
+ | --- | --- | --- |
54
+ | When | after the turn ends | while it runs, and after |
55
+ | Source | the daemon re-reading the provider's stored history | the events the client already receives |
56
+ | Rate | one `Response` number: the last reply's stream, prefill excluded, and no row at all when the final step ran a tool | every step of the turn pooled into `decode`, a `live` window over the last seconds, and a whole-turn basis to choose from |
57
+ | Thinking | exact where the provider reports reasoning separately | estimated from the streamed reasoning text and marked `≈`, for providers that subtract it from `output` |
58
+ | Pauses | not tracked | the pill turns ⏸ while a tool runs or the model waits for you; delegation and user waits leave both rates |
59
+ | Subagents | none | `· N sub` on the pill, per-subagent rates and a team total in the popover |
60
+ | Providers | Claude, OpenCode v2, Pi, Oh My Pi; Codex, ACP and plugin providers report a model row only | any provider that streams text, plugin providers included |
61
+
62
+ Where the two measure the same window they agree: on a measured OpenCode turn
63
+ Paseo printed `Whole turn ~33 tok/s` against the pill's `34.0` (theirs uses
64
+ measured tokens, ours character estimates until the first usage event lands, so
65
+ `≈`). Where they disagree they describe different windows, not a different
66
+ model: Paseo's `Response` is the fastest window of the turn (the final reply,
67
+ between its first token and the end of its stream), while our `decode` averages
68
+ every step including tool-argument generation and stalls, so the first is
69
+ usually the higher number.
70
+
44
71
  ## Requirements
45
72
 
46
73
  - Paseo **0.11.0+** (daemon and app).
@@ -136,14 +163,21 @@ provider config) — it feeds the `context 34k / 131k` line in the popover.
136
163
  per model call, summed over the turn. The numerator is the prompt the model
137
164
  did not have to recompute; the denominator is the whole prompt, so cache
138
165
  writes count against the rate — they are tokens the model had to process even
139
- though they missed the cache. Shown in the popover, and in the pill label
140
- when enabled in settings.
141
-
142
- Providers report cache reads in two shapes: OpenAI-compatible ones fold them
143
- into the prompt counter, Anthropic-style ones report cache reads on top of it.
144
- The plugin infers the shape per call (a cache read larger than the prompt can
145
- only mean separate counters) and Settings → Turn speed → Prompt cache can pin
146
- it explicitly.
166
+ though they missed the cache. Providers disagree on whether their prompt
167
+ counter already contains the cache reads, and a single call cannot tell the
168
+ two shapes apart (a large uncached prompt and a small cache read are the same
169
+ pair of numbers), so the shape is inferred once per turn: a call whose cache
170
+ reads exceed its prompt counter is only possible with disjoint counters, and
171
+ it decides for every call of that turn. One shape per turn is also what keeps
172
+ `in + cacheWrite + cached` equal to the reported prompt total; a cache-cold
173
+ call judged on its own pulled its cache reads out of the denominator, which is
174
+ the case `client/meter.test.ts` pins (61% printed as 86%). Settings can force
175
+ either shape. Shown in the popover, and in the pill label when enabled in settings.
176
+
177
+ OpenAI-compatible providers fold cache reads into the prompt counter and
178
+ Anthropic-style ones (Claude, OpenCode) report them on top of it; Settings →
179
+ Turn speed → Prompt cache pins either shape when a provider confuses the
180
+ inference.
147
181
 
148
182
  Paseo's `AgentUsage` exposes only `inputTokens` and `cachedInputTokens`, with
149
183
  no cache-write counter, so the `cacheWrite` term is always `0` today and the
@@ -226,6 +260,11 @@ check:client` runs the real Hermes syntax check too.
226
260
  provider's per-call usage updates. Providers without usage at all stay `≈`.
227
261
  - The plugin only counts what it watches live: after a reload or a reconnect the
228
262
  interrupted turn is not reconstructed (final `lastUsage` still gives totals).
263
+ Such a turn is marked `partial`: its `turn time` stays the real one (the
264
+ daemon's turn boundary), while `steps`, `tokens` and `cache hit` cover only
265
+ the watched stretch, so the popover shows `observed 1m10s of 8m57s` and hides
266
+ `whole turn` and `prefill / TTFT` rather than dividing a partial token count
267
+ by the whole turn.
229
268
  - Subagent turns get their own pills; the parent's numbers stay its own and
230
269
  subagent *tokens* are never added to them — delegation time is excluded and
231
270
  team rates are shown alongside, not merged. Paseo-native (delegated) agents
@@ -157,11 +157,13 @@ export function makeSpeedDetails(
157
157
  {running && live !== null ? (
158
158
  <Row styles={styles} label={`live (${prefs.liveWindowSec}s)`} value={fmtTokPerSec(live, summary.approx)} />
159
159
  ) : null}
160
- <Row
161
- styles={styles}
162
- label="whole turn"
163
- value={fmtTokPerSec(summary.tokPerSecTurn, summary.approx)}
164
- />
160
+ {summary.tokPerSecTurn !== null ? (
161
+ <Row
162
+ styles={styles}
163
+ label="whole turn"
164
+ value={fmtTokPerSec(summary.tokPerSecTurn, summary.approx)}
165
+ />
166
+ ) : null}
165
167
  {summary.prefillMs !== null ? (
166
168
  <Row styles={styles} label="prefill / TTFT" value={prefillValue ?? "\u2014"} />
167
169
  ) : null}
@@ -251,7 +253,20 @@ export function makeSpeedDetails(
251
253
  {summary.totalMs !== null ? (
252
254
  <Row styles={styles} label="turn time" value={fmtDuration(summary.totalMs)} />
253
255
  ) : null}
256
+ {summary.partial && summary.observedMs !== null && summary.totalMs !== null ? (
257
+ <Row
258
+ styles={styles}
259
+ label="observed"
260
+ value={`${fmtDuration(summary.observedMs)} of ${fmtDuration(summary.totalMs)}`}
261
+ />
262
+ ) : null}
254
263
  <Row styles={styles} label="calibration" value={`${cpt.toFixed(1)} chars/tok`} />
264
+ {summary.partial ? (
265
+ <Text style={styles.hint}>
266
+ Discovered while it was running: steps, tokens and cache cover the observed stretch
267
+ only, so no whole-turn rate is claimed.
268
+ </Text>
269
+ ) : null}
255
270
  {noUsage ? (
256
271
  <Text style={styles.hint}>
257
272
  {store.everSawUsage
@@ -53,6 +53,10 @@ function parseTimestamp(value: string | null | undefined): number | null {
53
53
  return Number.isFinite(parsed) ? parsed : null;
54
54
  }
55
55
 
56
+ /** Epoch milliseconds carried by a stream message, or null when it carries none.
57
+ * Exposed so callers can compare the daemon's clock with their own anchor. */
58
+ export const timestampMs = parseTimestamp;
59
+
56
60
  /** Anchor a live `turn_started` to the daemon timestamp carried by the stream
57
61
  * message, clamped so the clock never starts in the future. Events arrive in
58
62
  * order on one subscription, so the timestamp of the latest one is the turn
@@ -109,6 +113,9 @@ export function reconcileSnapshot(
109
113
  t: "turn_started",
110
114
  at: start.at,
111
115
  turnId: snapshot.activeTurn.turnId || null,
116
+ // The turn is only observed from here on: the meter must not turn its
117
+ // real boundary into a denominator for tokens it never saw.
118
+ observedFrom: now,
112
119
  });
113
120
  }
114
121
 
package/client/meter.ts CHANGED
@@ -97,7 +97,7 @@ export interface UsageSnapshot {
97
97
  * process, so it belongs in the cache-hit denominator.
98
98
  *
99
99
  * Paseo's AgentUsage carries no such field today (see the note on
100
- * `PromptTotals`), so the client always sends 0; the slot exists so a
100
+ * `cacheStats`), so the client always sends 0; the slot exists so a
101
101
  * provider that starts reporting it changes one mapper, not the formula.
102
102
  */
103
103
  cacheWrite?: number | null;
@@ -143,6 +143,11 @@ export interface MeterState {
143
143
  phase: TurnPhase;
144
144
  turnId: string | null;
145
145
  startedAt: number | null;
146
+ /** The turn was discovered while it was already running (plugin reload, app
147
+ * reopen, reconnect), so every event before this instant is unobserved while
148
+ * the clock still starts at the turn's real boundary. Null when the turn was
149
+ * seen from its first event. */
150
+ seededFrom: number | null;
146
151
  /** First assistant/reasoning growth of the turn => end of prefill. */
147
152
  firstTextAt: number | null;
148
153
  lastTextAt: number | null;
@@ -222,7 +227,13 @@ export interface MeterState {
222
227
  }
223
228
 
224
229
  export type MeterAction =
225
- | { t: "turn_started"; at: number; turnId: string | null }
230
+ | {
231
+ t: "turn_started";
232
+ at: number;
233
+ turnId: string | null;
234
+ /** When watching began, for a turn discovered mid-flight. */
235
+ observedFrom?: number;
236
+ }
226
237
  | { t: "text"; at: number; key: string; text: string; kind?: "text" | "reasoning" }
227
238
  | { t: "usage"; at: number; usage: UsageSnapshot; maxTokPerSec?: number }
228
239
  | { t: "compaction"; at: number }
@@ -253,6 +264,7 @@ export function initialMeterState(): MeterState {
253
264
  phase: "idle",
254
265
  turnId: null,
255
266
  startedAt: null,
267
+ seededFrom: null,
256
268
  firstTextAt: null,
257
269
  lastTextAt: null,
258
270
  stepFirstTextAt: null,
@@ -652,6 +664,15 @@ export function reduceMeter(state: MeterState, action: MeterAction): MeterState
652
664
  phase: "running",
653
665
  turnId: action.turnId || null,
654
666
  startedAt: action.at,
667
+ // A seed marks the turn as only partly observed. A live `turn_started`
668
+ // for the turn already being tracked (a re-announce after a
669
+ // resubscribe) cannot undo that mark: the events before the seed are
670
+ // still missing.
671
+ seededFrom:
672
+ action.observedFrom ??
673
+ (action.turnId && state.phase === "running" && state.turnId === action.turnId
674
+ ? state.seededFrom
675
+ : null),
655
676
  ctxMax: state.ctxMax,
656
677
  ctxUsed: state.ctxUsed,
657
678
  textLens: state.textLens,
@@ -811,6 +832,12 @@ export interface TurnSummary {
811
832
  promptTokens: number;
812
833
  /** Cached share of `promptTokens` (0..1); null without prompt data. */
813
834
  cacheHitRate: number | null;
835
+ /** Turn time and the token totals cover different stretches: the turn was
836
+ * discovered mid-flight, so no rate over the whole turn is claimed (a partial
837
+ * total is never shown), and `observedMs` says what was actually watched. */
838
+ partial: boolean;
839
+ /** Wall time watched by this plugin; null unless the turn is partial. */
840
+ observedMs: number | null;
814
841
  /** Prompt tokens of the first step, for the prefill rate. */
815
842
  firstStepPromptTokens: number | null;
816
843
  /** Cached prompt tokens of the first step: with a warm cache the prompt
@@ -831,11 +858,34 @@ export interface TurnSummary {
831
858
  * tokens, so the prompt total is `inputTokens`.
832
859
  * - `separate` (Anthropic-style): `inputTokens` is only the uncached part and
833
860
  * cache reads are reported on top, so the total is their sum.
834
- * - `auto`: infer per turn — cache reads larger than the prompt can only mean
835
- * separate counters; otherwise assume the prompt already includes them.
861
+ * - `auto`: infer from this call alone — cache reads larger than the prompt can
862
+ * only mean separate counters; otherwise assume the prompt includes them.
863
+ * Summarizing a turn, decide with `turnReportsSeparateCache` instead and pass
864
+ * an explicit mode, so one call cannot use a different shape from the rest.
836
865
  */
837
866
  export type CacheCountingMode = "auto" | "inclusive" | "separate";
838
867
 
868
+ /**
869
+ * Whether a turn's calls report cache reads outside the prompt counter.
870
+ *
871
+ * One call cannot tell the two shapes apart: a large uncached prompt and a
872
+ * small cache read are the same pair of numbers whichever way the counters are
873
+ * arranged. A whole turn can, because the shapes make different promises — an
874
+ * inclusive provider can never report more cache reads than its prompt, so one
875
+ * call that does proves disjoint counters for every call of the turn.
876
+ *
877
+ * Deciding per call instead lets a cache-cold call (a large prompt, a modest
878
+ * cache read) fall back to the inclusive reading, and that call's cache reads
879
+ * then stay out of the denominator while still counting in the numerator.
880
+ * Measured on a real OpenCode turn: one such call moved 16k cache reads out of
881
+ * the denominator and printed 86% where the prompt was 76% cache reads.
882
+ */
883
+ export function turnReportsSeparateCache(
884
+ steps: readonly { inputTokens: number; cachedTokens: number }[],
885
+ ): boolean {
886
+ return steps.some((step) => step.cachedTokens > 0 && step.cachedTokens > step.inputTokens);
887
+ }
888
+
839
889
  /**
840
890
  * Prompt totals for one model call.
841
891
  *
@@ -949,12 +999,19 @@ export function summarizeTurn(
949
999
  estTokens = wholeEst;
950
1000
  approx = true;
951
1001
  }
1002
+ // A turn discovered mid-flight has no observed prefill: the first text we
1003
+ // saw arrived long after the real one, so the gap measures the attach, not
1004
+ // the model.
952
1005
  const prefillMs =
953
- state.firstTextAt !== null && state.startedAt !== null
1006
+ state.seededFrom === null && state.firstTextAt !== null && state.startedAt !== null
954
1007
  ? Math.max(0, state.firstTextAt - state.startedAt)
955
1008
  : null;
956
1009
  const end = state.endedAt ?? (state.phase === "running" ? now : null);
957
1010
  const totalMs = state.startedAt !== null && end !== null ? Math.max(0, end - state.startedAt) : null;
1011
+ // What this plugin actually watched of a partly observed turn, for the row
1012
+ // that explains why its totals are smaller than the provider's.
1013
+ const observedMs =
1014
+ state.seededFrom !== null && end !== null ? Math.max(0, end - state.seededFrom) : null;
958
1015
  let userWaitMs = 0;
959
1016
  for (const wait of state.userWaits) userWaitMs += Math.max(0, wait.end - wait.start);
960
1017
  if (state.pausedAt !== null && end !== null) userWaitMs += Math.max(0, end - state.pausedAt);
@@ -987,13 +1044,20 @@ export function summarizeTurn(
987
1044
  const tokPerSecDecode =
988
1045
  decodeMs > 0 && decodeTokens > 0 ? decodeTokens / (decodeMs / 1000) : null;
989
1046
  const tokPerSecTurn =
990
- activeMs !== null && activeMs > 0 && estTokens > 0 ? estTokens / (activeMs / 1000) : null;
991
- // Each call is normalised on its own, then summed: a turn can mix providers'
992
- // shapes, and a per-call decision is far more reliable than a merged one.
1047
+ state.seededFrom === null && activeMs !== null && activeMs > 0 && estTokens > 0
1048
+ ? estTokens / (activeMs / 1000)
1049
+ : null;
1050
+ // The counter shape is one property of the turn, not of a call: one cache-cold
1051
+ // call must not have its cache reads read back into the prompt it missed.
1052
+ const cacheMode: CacheCountingMode =
1053
+ cacheCounting === "separate" ||
1054
+ (cacheCounting === "auto" && turnReportsSeparateCache(state.steps))
1055
+ ? "separate"
1056
+ : "inclusive";
993
1057
  let promptTokens = 0;
994
1058
  let hitTokens = 0;
995
1059
  for (const step of state.steps) {
996
- const stepCache = cacheStats(step.inputTokens, step.cachedTokens, cacheCounting, step.cacheWriteTokens);
1060
+ const stepCache = cacheStats(step.inputTokens, step.cachedTokens, cacheMode, step.cacheWriteTokens);
997
1061
  promptTokens += stepCache.promptTokens;
998
1062
  hitTokens += stepCache.cachedTokens;
999
1063
  }
@@ -1002,6 +1066,8 @@ export function summarizeTurn(
1002
1066
  outTokens,
1003
1067
  estTokens,
1004
1068
  approx,
1069
+ partial: state.seededFrom !== null,
1070
+ observedMs,
1005
1071
  decodeMs,
1006
1072
  waitMs,
1007
1073
  prefillMs,
@@ -161,7 +161,7 @@ export function makeSettingsScreen(onSaved: () => void): ComponentType<PluginSur
161
161
  <SettingsCard>
162
162
  <SettingsSelect
163
163
  label="How cache reads are reported"
164
- hint="Auto infers from the numbers (cache reads larger than the prompt can only mean separate counters). Claude reports cache reads on top of the prompt; most OpenAI-compatible providers fold them in."
164
+ hint="Auto infers the shape from the turn: one call whose cache reads exceed its prompt can only mean separate counters, and it decides for every call. Claude and OpenCode report cache reads on top of the prompt; most OpenAI-compatible providers fold them in."
165
165
  value={values.cacheCounting}
166
166
  options={[
167
167
  { label: "Auto (default)", value: "auto" },
package/index.client.tsx CHANGED
@@ -6,6 +6,7 @@ import { makeSpeedDetails } from "./client/details";
6
6
  import { parentAgentIdOf } from "./client/links";
7
7
  import {
8
8
  reconcileSnapshot,
9
+ timestampMs,
9
10
  turnStartFromEvent,
10
11
  } from "./client/lifecycle";
11
12
  import { summarizeTeam, type TeamMemberInput } from "./client/team";
@@ -291,6 +292,15 @@ export default function contribute(client: PluginClientContext) {
291
292
  // snapshot updates on another channel and can still hold the previous
292
293
  // turn's start, which would charge that whole turn to this one.
293
294
  const start = turnStartFromEvent(eventTimestamp, at);
295
+ // Paseo's own turn footer counts from the user's message row. When the
296
+ // daemon announces `turn_started` later than that row, this meter's
297
+ // clock is short by the difference, so log the anchor it chose and how
298
+ // long this message took to arrive.
299
+ console.log(
300
+ `turn-speed: turn started [${agentId.slice(0, 8)}]` +
301
+ ` anchor ${start.source}` +
302
+ ` lead ${((at - start.at) / 1000).toFixed(1)}s`,
303
+ );
294
304
  store.dispatch({
295
305
  t: "turn_started",
296
306
  at: start.at,
@@ -379,6 +389,22 @@ export default function contribute(client: PluginClientContext) {
379
389
  });
380
390
  } else if (item.type === "compaction") {
381
391
  store.dispatch({ t: "compaction", at });
392
+ } else if (item.type === "user_message") {
393
+ // The other half of the comparison: Paseo's turn footer opens the
394
+ // turn at this row, so log how far the row sits from this meter's
395
+ // anchor. `empty` marks the row that opened the turn; without it the
396
+ // row is a steer, which Paseo still counts inside the same turn.
397
+ const sentAt = timestampMs(eventTimestamp);
398
+ const opening = store.state.steps.length === 0 && store.state.totalChars === 0;
399
+ console.log(
400
+ `turn-speed: prompt row [${agentId.slice(0, 8)}]` +
401
+ ` ${
402
+ sentAt === null
403
+ ? "no timestamp"
404
+ : `${((((store.state.startedAt ?? at) - sentAt) / 1000).toFixed(1))}s before the clock`
405
+ }` +
406
+ ` phase ${store.state.phase}${opening ? " empty" : ""}`,
407
+ );
382
408
  } else if (item.type === "tool_call" && isSubAgentCall(item)) {
383
409
  // A subagent call: running/closed drives the parent's delegation
384
410
  // interval, and its child session id (when the provider reports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paseo-turn-speed",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Live decode tok/s, prefill and token breakdown for every agent turn",
5
5
  "license": "MIT",
6
6
  "author": "Bogdan Yanysh <acidlol@live.ru>",
package/paseo-plugin.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "id": "turn-speed",
3
3
  "description": "Live decode tok/s, prefill/TTFT, and a token breakdown for every agent turn, right in the composer.",
4
+ "icon": "assets/icon.png",
4
5
  "requirements": {
5
6
  "paseo": ">=0.11.0"
6
7
  }