paseo-turn-speed 1.0.1 → 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 CHANGED
@@ -11,11 +11,21 @@ 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
18
23
  popover), smoothing window for the live number, token format, idle-pill
19
- visibility, and a manual chars/token override. Requires Paseo 0.11 or later.
24
+ visibility, and a manual chars/token override. Requires Paseo 0.11 or later;
25
+ see the README for installing from GitHub or npm.
20
26
  Turns are observed live; history from before a plugin reload is not
21
- reconstructed, and subagents get their own pills instead of parent totals.
27
+ reconstructed. Subagents keep their own pills, but the parent also knows about
28
+ them: time delegated to running subagents is excluded from the parent's
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
@@ -1,10 +1,16 @@
1
1
  # turn-speed — live token-rate meter for Paseo agents
2
2
 
3
3
  A composer pill per agent that shows how fast the model is actually decoding:
4
- `⚡ 138 tok/s · 0.8k` while a turn runs, `139 tok/s · 1.2k tok` after it ends,
5
- with a popover breakdown (prefill/TTFT, in/cached/out tokens, steps, tool wait,
6
- context occupancy). Numbers measured from real provider usage are exact;
7
- before the first usage event they are character estimates marked with `≈`.
4
+ `⚡ 138 tok/s` while a turn runs, `⏸ 43 tok/s` while it waits for your answer,
5
+ `12.4 tok/s · 2 sub` while subagents do the heavy lifting, and the final rate
6
+ once the turn ends — with a popover breakdown (prefill/TTFT, in/cached/out
7
+ tokens, steps, tool wait, user wait, per-subagent rates, context occupancy).
8
+ Numbers measured from real provider usage are exact; before the first usage
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.
8
14
 
9
15
  ## Install
10
16
 
@@ -85,13 +91,27 @@ provider config) — it feeds the `context 34k / 131k` line in the popover.
85
91
  model call are excluded. This is why the pill shows ~139 tok/s on short
86
92
  answers instead of 6.
87
93
  - **Whole-turn tok/s** — optional alternative basis in settings; it includes
88
- tool time and is always lower. Time spent waiting for you is excluded.
94
+ tool time and is always lower. Time spent waiting for you and time delegated
95
+ to subagents are excluded.
89
96
  - **Waiting for you** — when the model asks a question or waits for a permission
90
97
  or plan approval it is asleep until you answer. Those intervals are taken from
91
98
  the provider's permission/question requests (and restored from agent snapshots
92
99
  after reloads and reconnects), and are removed from decode windows, tool-wait
93
100
  time and the whole-turn rate. `turn time` stays wall-clock; the popover shows a
94
101
  separate `waiting for you` row and the pill switches to a ⏸ icon meanwhile.
102
+ - **Delegation to subagents** — while the agent's work runs in subagents, the
103
+ parent's own model produces nothing, so that stretch is removed from its
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
108
+ normalized `subagent` tool calls Paseo emits for provider subagents such as
109
+ OpenCode's Task) and from linked Paseo child agents. The parent's pill grows
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.
95
115
  - **Live number inside a model call** — real tokens only arrive at the end of a
96
116
  call, so the live value estimates tokens from characters over a 1/2/5 s
97
117
  smoothing window and is marked `≈` until the call's usage lands.
@@ -102,8 +122,27 @@ provider config) — it feeds the `context 34k / 131k` line in the popover.
102
122
  a note lands in the app log (`turn-speed: step dropped as implausible`).
103
123
  - **Auto-calibration** — at every step end the observed `chars/token` ratio for
104
124
  the model is blended into a stored per-model calibration (EMA 0.7/0.3, clamped
105
- to 2..8, persisted in plugin settings). After 2–3 steps the live estimate
106
- tracks the real one closely. Settings → Turn speed shows and can override it.
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.
107
146
 
108
147
  ## Settings (Settings → Plugins → Turn speed)
109
148
 
@@ -114,7 +153,7 @@ provider config) — it feeds the `context 34k / 131k` line in the popover.
114
153
  | Token format | 1.2k | compact or grouped digits |
115
154
  | Live smoothing window | 2 s | averaging window of the live tok/s |
116
155
  | Manual chars per token | off (auto-calibrated) | override the live character estimate |
117
- | 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 |
118
157
 
119
158
  ## Development
120
159
 
@@ -124,6 +163,9 @@ paseo plugin reload turn-speed
124
163
  paseo plugin ls # status of every installed plugin
125
164
  ```
126
165
 
166
+ Releasing a new version (npm + registry flow, with the gotchas): see
167
+ [RELEASE.md](RELEASE.md).
168
+
127
169
  `npm run check:client` compiles the client entry with the same options Paseo's
128
170
  compiler uses and rejects output the mobile app's JS engine (Hermes) cannot
129
171
  parse — notably anonymous class expressions, which is exactly what a `class`
@@ -137,7 +179,15 @@ check:client` runs the real Hermes syntax check too.
137
179
  provider's per-call usage updates. Providers without usage at all stay `≈`.
138
180
  - The plugin only counts what it watches live: after a reload or a reconnect the
139
181
  interrupted turn is not reconstructed (final `lastUsage` still gives totals).
140
- - Subagent turns get their own pills and are never added to the parent's numbers.
182
+ - Subagent turns get their own pills; the parent's numbers stay its own and
183
+ subagent *tokens* are never added to them — delegation time is excluded and
184
+ team rates are shown alongside, not merged. Paseo-native (delegated) agents
185
+ are linked through their `paseo.parent-agent-id` label, so they get the full
186
+ per-child breakdown. Provider subagents (e.g. OpenCode Task calls) do not
187
+ appear as Paseo agents and their token stream is not reachable from the
188
+ plugin API, so for them the badge, the `delegated` time and the rate
189
+ correction work, but the per-child token breakdown stays empty
190
+ (verified on Paseo 0.12 + OpenCode).
141
191
  - Usage that arrives late from a previous turn (typically after an interrupted
142
192
  message) is dropped by the plausibility guard, so that turn's token totals can
143
193
  be slightly low; rates stay honest.
@@ -1,11 +1,11 @@
1
1
  import type { ComponentType } from "react";
2
- import { useMemo } from "react";
2
+ import { useEffect, useMemo, useReducer, useSyncExternalStore } from "react";
3
3
  import { Pressable, Text, View } from "react-native";
4
- import { useSyncExternalStore } from "react";
5
4
  import type { PluginButtonContentProps } from "@getpaseo/plugin/client";
6
5
  import { useSettings } from "@getpaseo/plugin/client";
7
6
  import { approx, fmtDuration, fmtRate, fmtTokPerSec, fmtTokens } from "./format";
8
7
  import type { AgentSpeedStore } from "./store";
8
+ import { EMPTY_TEAM, type TeamView } from "./team";
9
9
  import { preferences, type Preferences } from "../shared/preferences";
10
10
 
11
11
  type Styles = ReturnType<typeof buildStyles>;
@@ -65,6 +65,7 @@ export function makeSpeedDetails(
65
65
  getPrefs: () => Preferences,
66
66
  charsPerToken: () => number,
67
67
  onPrefsSaved: () => void,
68
+ getTeamView: () => TeamView | null = () => null,
68
69
  ): ComponentType<PluginButtonContentProps> {
69
70
  return function SpeedDetails({ theme, layout }: PluginButtonContentProps) {
70
71
  useSyncExternalStore(store.subscribe, store.getSnapshot);
@@ -74,9 +75,19 @@ export function makeSpeedDetails(
74
75
  const now = Date.now();
75
76
  const state = store.state;
76
77
  const summary = store.summary(now);
78
+ const team = getTeamView() ?? EMPTY_TEAM;
79
+ // Children emit on their own stores; while any runs, a slow tick keeps
80
+ // their numbers moving between the parent's own repaints.
81
+ const [, tick] = useReducer((n: number) => n + 1, 0);
82
+ const teamActive = team.running > 0;
83
+ useEffect(() => {
84
+ if (!teamActive) return undefined;
85
+ const timer = setInterval(() => tick(), 500);
86
+ return () => clearInterval(timer);
87
+ }, [teamActive]);
77
88
  const cpt = charsPerToken();
78
89
  const running = state.phase === "running";
79
- const live = running ? store.liveTokPerSec(prefs.liveWindowSec) : null;
90
+ const live = running ? store.liveTokPerSec(prefs.liveWindowSec, prefs.maxPlausibleTokPerSec) : null;
80
91
  const basis = settings.status === "ready" ? settings.values.numerator : null;
81
92
  const setBasis = (value: "live" | "decode" | "turn") => {
82
93
  if (settings.status !== "ready" || settings.values.numerator === value) return;
@@ -90,6 +101,23 @@ export function makeSpeedDetails(
90
101
  summary.firstStepPromptTokens !== null && summary.prefillMs !== null && summary.prefillMs > 0
91
102
  ? summary.firstStepPromptTokens / (summary.prefillMs / 1000)
92
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);
93
121
  const noUsage = !state.sawUsage && state.phase !== "idle";
94
122
 
95
123
  const model = store.model ?? store.provider ?? "";
@@ -135,20 +163,23 @@ export function makeSpeedDetails(
135
163
  value={fmtTokPerSec(summary.tokPerSecTurn, summary.approx)}
136
164
  />
137
165
  {summary.prefillMs !== null ? (
138
- <Row
139
- styles={styles}
140
- label="prefill / TTFT"
141
- value={`${prefillRate !== null ? `${fmtRate(prefillRate)} tok/s · ` : ""}${fmtDuration(summary.prefillMs)}`}
142
- />
166
+ <Row styles={styles} label="prefill / TTFT" value={prefillValue ?? "\u2014"} />
143
167
  ) : null}
144
168
  <Row
145
169
  styles={styles}
146
170
  label="tokens"
147
- value={`in ${fmtTokens(summary.inputTokens, prefs.tokenFormat)} · cached ${fmtTokens(
171
+ value={`in ${fmtTokens(summary.inputTokens, prefs.tokenFormat)} \u00b7 cached ${fmtTokens(
148
172
  summary.cachedTokens,
149
173
  prefs.tokenFormat,
150
- )} · out ${approx(fmtTokens(summary.estTokens, prefs.tokenFormat), summary.approx)}`}
174
+ )} \u00b7 out ${approx(fmtTokens(summary.estTokens, prefs.tokenFormat), summary.approx)}`}
151
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}
152
183
  {state.ctxUsed !== null && state.ctxMax !== null ? (
153
184
  <Row
154
185
  styles={styles}
@@ -168,6 +199,38 @@ export function makeSpeedDetails(
168
199
  value={fmtDuration(summary.userWaitMs)}
169
200
  />
170
201
  ) : null}
202
+ {team.members.length > 0 || summary.delegated || summary.delegatedMs > 0 ? (
203
+ <Row
204
+ styles={styles}
205
+ label={summary.delegated ? "subagents" : "delegated"}
206
+ value={
207
+ team.running > 0
208
+ ? `${team.running} running \u00b7 ${fmtDuration(summary.delegatedMs)}`
209
+ : fmtDuration(summary.delegatedMs)
210
+ }
211
+ />
212
+ ) : null}
213
+ {team.members.slice(0, 5).map((member) => (
214
+ <Row
215
+ key={member.id}
216
+ styles={styles}
217
+ label={member.title ?? member.id.slice(0, 8)}
218
+ value={`${member.running ? fmtTokPerSec(member.liveTokPerSec, member.approx) : "\u2713"} \u00b7 ${approx(
219
+ fmtTokens(member.estTokens, prefs.tokenFormat),
220
+ member.approx,
221
+ )} tok`}
222
+ />
223
+ ))}
224
+ {team.running > 0 && (team.liveTokPerSec !== null || team.estTokens > 0) ? (
225
+ <Row
226
+ styles={styles}
227
+ label="team"
228
+ value={`${fmtTokPerSec(team.liveTokPerSec, team.approx)} \u00b7 ${approx(
229
+ fmtTokens(team.estTokens, prefs.tokenFormat),
230
+ team.approx,
231
+ )} tok`}
232
+ />
233
+ ) : null}
171
234
  {summary.totalMs !== null ? (
172
235
  <Row styles={styles} label="turn time" value={fmtDuration(summary.totalMs)} />
173
236
  ) : null}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Parent linkage for delegated (subagent) agents. Pure, unit-testable.
3
+ *
4
+ * Paseo marks delegated agents with the `paseo.parent-agent-id` label (the
5
+ * same mechanism the app's Subagents popover uses); a dedicated snapshot
6
+ * field is not delivered on the wire, so the label is the primary source and
7
+ * the field only a defensive fallback.
8
+ */
9
+
10
+ export const PARENT_AGENT_ID_LABEL = "paseo.parent-agent-id";
11
+
12
+ export function parentAgentIdOf(agent: {
13
+ labels?: Record<string, string> | null;
14
+ parentAgentId?: string | null;
15
+ }): string | null {
16
+ const labeled = agent.labels?.[PARENT_AGENT_ID_LABEL];
17
+ if (typeof labeled === "string" && labeled.trim() !== "") return labeled.trim();
18
+ const field = agent.parentAgentId;
19
+ return typeof field === "string" && field.trim() !== "" ? field.trim() : null;
20
+ }