paseo-turn-speed 0.0.0-stage → 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bogdan Yanysh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/OVERVIEW.md ADDED
@@ -0,0 +1,21 @@
1
+ # turn-speed
2
+
3
+ A composer pill on every agent that shows how fast the model is decoding: live
4
+ tok/s while a turn runs, final tok/s and token totals after it, and a popover
5
+ with the breakdown — prefill/TTFT, in/cached/out tokens, model-call steps, tool
6
+ wait time, and context occupancy.
7
+
8
+ Speed is measured over decode windows only: tool waits, long pauses, and prompt
9
+ prefill are separated out, so the number reflects generation speed rather than
10
+ turn latency. When the provider reports real usage (for OpenCode/MLX models
11
+ enable `options.includeUsage: true` in the provider config), numbers are exact.
12
+ Without usage the plugin estimates tokens from streamed characters, marks them
13
+ with `≈`, and auto-calibrates a per-model chars/token ratio from every step that
14
+ does report usage.
15
+
16
+ Options live under Settings → Plugins → Turn speed: what the pill leads with
17
+ (live estimate, decode-window average, or whole-turn rate, switchable from the
18
+ 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.
20
+ Turns are observed live; history from before a plugin reload is not
21
+ reconstructed, and subagents get their own pills instead of parent totals.
package/README.md CHANGED
@@ -1,3 +1,146 @@
1
- # Temporary Holding Version
1
+ # turn-speed — live token-rate meter for Paseo agents
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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 `≈`.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ paseo plugin add github:Drenalol/paseo-turn-speed
13
+ # or, from npm:
14
+ paseo plugin add npm:paseo-turn-speed
15
+ ```
16
+
17
+ Then open Settings → Plugins → Turn speed to tune it. See
18
+ [Requirements](#requirements) for the one provider setting that makes the
19
+ numbers exact.
20
+
21
+ ## Screenshots
22
+
23
+ Desktop — the composer pill while a turn decodes, and the paused variant
24
+ (the model is waiting for your answer):
25
+
26
+ <img src="images/desktop-pill-live.png" alt="Live pill: 74.4 tok/s" width="200"> <img src="images/desktop-pill-waiting.png" alt="Waiting pill: 43.6 tok/s" width="200">
27
+
28
+ The popover behind the pill — decode and whole-turn rates, prefill/TTFT,
29
+ token totals, steps, tool wait and context occupancy:
30
+
31
+ <img src="images/desktop-popover.png" alt="Turn breakdown popover" width="420">
32
+
33
+ The same popover on mobile, with the `pill shows` basis chips:
34
+
35
+ <img src="images/mobile-popover.png" alt="Mobile popover" width="300">
36
+
37
+ ## Requirements
38
+
39
+ - Paseo **0.11.0+** (daemon and app).
40
+ - Node.js with npm on the daemon host (for the one-time `npm install` here; Paseo itself
41
+ needs no npm to run the plugin).
42
+
43
+ ## Make it work
44
+
45
+ ```bash
46
+ cd /path/to/paseo-turn-speed
47
+ npm install # dev dependencies for typechecking only
48
+ npm run typecheck
49
+ paseo plugin install "$(pwd)"
50
+ paseo plugin reload turn-speed # after every source edit
51
+ paseo plugin logs turn-speed
52
+ ```
53
+
54
+ Then open the Paseo app: every agent with a workspace gets a pill in the composer
55
+ track (next to Tasks/Subagents). Settings → Plugins → Turn speed holds the options.
56
+
57
+ ### The one setting that decides accuracy: `includeUsage`
58
+
59
+ The plugin reads real token counts from the `usage` the provider reports. For
60
+ OpenCode-backed models (including local MLX servers) the provider only forwards
61
+ usage when it is enabled in the OpenCode config, e.g. in `opencode.json`:
62
+
63
+ ```json
64
+ {
65
+ "provider": {
66
+ "mlx": {
67
+ "options": { "includeUsage": true }
68
+ }
69
+ }
70
+ }
71
+ ```
72
+
73
+ Without it the plugin still works: every number is estimated from streamed
74
+ characters (`≈`) and the popover shows a hint about this setting.
75
+
76
+ Also useful: a `limit.context` value for the model (the model catalog or the
77
+ provider config) — it feeds the `context 34k / 131k` line in the popover.
78
+
79
+ ## How the numbers are computed
80
+
81
+ - **TTFT / prefill** — from turn start to the first streamed character. Reported
82
+ separately, never mixed into tok/s.
83
+ - **decode tok/s** — output tokens from usage deltas divided by decode windows
84
+ only. Tool waits, thinking pauses longer than 2 s, and the prefill of the next
85
+ model call are excluded. This is why the pill shows ~139 tok/s on short
86
+ answers instead of 6.
87
+ - **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.
89
+ - **Waiting for you** — when the model asks a question or waits for a permission
90
+ or plan approval it is asleep until you answer. Those intervals are taken from
91
+ the provider's permission/question requests (and restored from agent snapshots
92
+ after reloads and reconnects), and are removed from decode windows, tool-wait
93
+ time and the whole-turn rate. `turn time` stays wall-clock; the popover shows a
94
+ separate `waiting for you` row and the pill switches to a ⏸ icon meanwhile.
95
+ - **Live number inside a model call** — real tokens only arrive at the end of a
96
+ call, so the live value estimates tokens from characters over a 1/2/5 s
97
+ smoothing window and is marked `≈` until the call's usage lands.
98
+ - **Implausible rates are dropped** — a step implying a decode faster than the
99
+ configured limit (default 400 tok/s) cannot have happened on your hardware;
100
+ it is almost always the previous (interrupted) message's usage arriving late.
101
+ Such deltas are absorbed into the baseline instead of inflating the rate, and
102
+ a note lands in the app log (`turn-speed: step dropped as implausible`).
103
+ - **Auto-calibration** — at every step end the observed `chars/token` ratio for
104
+ 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.
107
+
108
+ ## Settings (Settings → Plugins → Turn speed)
109
+
110
+ | Option | Default | Effect |
111
+ | --- | --- | --- |
112
+ | Show pills for idle agents | off | otherwise pills appear only around observed turns |
113
+ | Speed basis | Live decode | what the pill shows: live estimate, decode-window average, or whole-turn rate |
114
+ | Token format | 1.2k | compact or grouped digits |
115
+ | Live smoothing window | 2 s | averaging window of the live tok/s |
116
+ | 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 |
118
+
119
+ ## Development
120
+
121
+ ```bash
122
+ npm run verify # typecheck + unit tests + client-bundle check
123
+ paseo plugin reload turn-speed
124
+ paseo plugin ls # status of every installed plugin
125
+ ```
126
+
127
+ `npm run check:client` compiles the client entry with the same options Paseo's
128
+ compiler uses and rejects output the mobile app's JS engine (Hermes) cannot
129
+ parse — notably anonymous class expressions, which is exactly what a `class`
130
+ becomes after bundling. Client code therefore uses closure factories instead of
131
+ classes. With a `hermes` binary available, `HERMES_BIN=/path/to/hermes npm run
132
+ check:client` runs the real Hermes syntax check too.
133
+
134
+ ## Known limitations
135
+
136
+ - Usage arrives via agent snapshots, so step boundaries are as fine as the
137
+ provider's per-call usage updates. Providers without usage at all stay `≈`.
138
+ - The plugin only counts what it watches live: after a reload or a reconnect the
139
+ 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.
141
+ - Usage that arrives late from a previous turn (typically after an interrupted
142
+ message) is dropped by the plausibility guard, so that turn's token totals can
143
+ be slightly low; rates stay honest.
144
+ - Every closed and dropped step is logged to the app log
145
+ (`~/Library/Logs/Paseo/main.log`, prefix `turn-speed:`) if you want to audit
146
+ where a number came from.
Binary file
@@ -0,0 +1,185 @@
1
+ import type { ComponentType } from "react";
2
+ import { useMemo } from "react";
3
+ import { Pressable, Text, View } from "react-native";
4
+ import { useSyncExternalStore } from "react";
5
+ import type { PluginButtonContentProps } from "@getpaseo/plugin/client";
6
+ import { useSettings } from "@getpaseo/plugin/client";
7
+ import { approx, fmtDuration, fmtRate, fmtTokPerSec, fmtTokens } from "./format";
8
+ import type { AgentSpeedStore } from "./store";
9
+ import { preferences, type Preferences } from "../shared/preferences";
10
+
11
+ type Styles = ReturnType<typeof buildStyles>;
12
+
13
+ function buildStyles(theme: PluginButtonContentProps["theme"], compact: boolean) {
14
+ return {
15
+ wrap: { gap: compact ? 6 : 8, padding: 2, minWidth: compact ? 220 : 280 },
16
+ header: {
17
+ flexDirection: "row" as const,
18
+ justifyContent: "space-between" as const,
19
+ alignItems: "center" as const,
20
+ gap: 12,
21
+ },
22
+ title: { color: theme.colors.foreground, fontSize: 13, fontWeight: "600" as const },
23
+ model: { color: theme.colors.foregroundMuted, fontSize: 11, flexShrink: 1 },
24
+ row: { flexDirection: "row" as const, justifyContent: "space-between" as const, gap: 12 },
25
+ label: { color: theme.colors.foregroundMuted, fontSize: 12 },
26
+ value: { color: theme.colors.foreground, fontSize: 12, fontVariant: ["tabular-nums" as const] },
27
+ hint: { color: theme.colors.statusWarning, fontSize: 11, marginTop: 2 },
28
+ basis: { flexDirection: "row" as const, justifyContent: "space-between" as const, alignItems: "center" as const, gap: 8 },
29
+ chips: { flexDirection: "row" as const, gap: 4 },
30
+ chip: {
31
+ borderRadius: 6,
32
+ borderWidth: 1,
33
+ borderColor: theme.colors.border,
34
+ paddingHorizontal: 8,
35
+ paddingVertical: 3,
36
+ },
37
+ chipOn: {
38
+ borderRadius: 6,
39
+ borderWidth: 1,
40
+ borderColor: theme.colors.accent,
41
+ backgroundColor: theme.colors.accent,
42
+ paddingHorizontal: 8,
43
+ paddingVertical: 3,
44
+ },
45
+ chipText: { color: theme.colors.foregroundMuted, fontSize: 11 },
46
+ chipTextOn: { color: theme.colors.accentForeground, fontSize: 11, fontWeight: "600" as const },
47
+ };
48
+ }
49
+
50
+ function Row({ styles, label, value }: { styles: Styles; label: string; value: string }) {
51
+ return (
52
+ <View style={styles.row}>
53
+ <Text style={styles.label}>{label}</Text>
54
+ <Text style={styles.value}>{value}</Text>
55
+ </View>
56
+ );
57
+ }
58
+
59
+ /**
60
+ * Builds the popover body for one agent's pill. The returned component is a
61
+ * stable identity so updating the pill never closes an open popover.
62
+ */
63
+ export function makeSpeedDetails(
64
+ store: AgentSpeedStore,
65
+ getPrefs: () => Preferences,
66
+ charsPerToken: () => number,
67
+ onPrefsSaved: () => void,
68
+ ): ComponentType<PluginButtonContentProps> {
69
+ return function SpeedDetails({ theme, layout }: PluginButtonContentProps) {
70
+ useSyncExternalStore(store.subscribe, store.getSnapshot);
71
+ const settings = useSettings(preferences);
72
+ const styles = useMemo(() => buildStyles(theme, layout.compact), [theme, layout.compact]);
73
+ const prefs = getPrefs();
74
+ const now = Date.now();
75
+ const state = store.state;
76
+ const summary = store.summary(now);
77
+ const cpt = charsPerToken();
78
+ const running = state.phase === "running";
79
+ const live = running ? store.liveTokPerSec(prefs.liveWindowSec) : null;
80
+ const basis = settings.status === "ready" ? settings.values.numerator : null;
81
+ const setBasis = (value: "live" | "decode" | "turn") => {
82
+ if (settings.status !== "ready" || settings.values.numerator === value) return;
83
+ void settings
84
+ .save({ ...settings.values, numerator: value }, settings.revision)
85
+ .then((ok) => {
86
+ if (ok) onPrefsSaved();
87
+ });
88
+ };
89
+ const prefillRate =
90
+ summary.firstStepPromptTokens !== null && summary.prefillMs !== null && summary.prefillMs > 0
91
+ ? summary.firstStepPromptTokens / (summary.prefillMs / 1000)
92
+ : null;
93
+ const noUsage = !state.sawUsage && state.phase !== "idle";
94
+
95
+ const model = store.model ?? store.provider ?? "";
96
+ return (
97
+ <View style={styles.wrap}>
98
+ <View style={styles.header}>
99
+ <Text style={styles.title}>
100
+ {running ? (state.pausedAt !== null ? "\u23f8 " : "\u26a1 ") : ""}
101
+ {fmtTokPerSec(summary.tokPerSecDecode, summary.approx)} decode
102
+ </Text>
103
+ {model ? (
104
+ <Text style={styles.model} numberOfLines={1} ellipsizeMode="middle">
105
+ {model}
106
+ </Text>
107
+ ) : null}
108
+ </View>
109
+ {basis !== null ? (
110
+ <View style={styles.basis}>
111
+ <Text style={styles.label}>pill shows</Text>
112
+ <View style={styles.chips}>
113
+ {(["live", "decode", "whole"] as const).map((label) => {
114
+ const value = label === "whole" ? "turn" : label;
115
+ const on = basis === value;
116
+ return (
117
+ <Pressable
118
+ key={label}
119
+ onPress={() => setBasis(value)}
120
+ style={on ? styles.chipOn : styles.chip}
121
+ >
122
+ <Text style={on ? styles.chipTextOn : styles.chipText}>{label}</Text>
123
+ </Pressable>
124
+ );
125
+ })}
126
+ </View>
127
+ </View>
128
+ ) : null}
129
+ {running && live !== null ? (
130
+ <Row styles={styles} label={`live (${prefs.liveWindowSec}s)`} value={fmtTokPerSec(live, summary.approx)} />
131
+ ) : null}
132
+ <Row
133
+ styles={styles}
134
+ label="whole turn"
135
+ value={fmtTokPerSec(summary.tokPerSecTurn, summary.approx)}
136
+ />
137
+ {summary.prefillMs !== null ? (
138
+ <Row
139
+ styles={styles}
140
+ label="prefill / TTFT"
141
+ value={`${prefillRate !== null ? `${fmtRate(prefillRate)} tok/s · ` : ""}${fmtDuration(summary.prefillMs)}`}
142
+ />
143
+ ) : null}
144
+ <Row
145
+ styles={styles}
146
+ label="tokens"
147
+ value={`in ${fmtTokens(summary.inputTokens, prefs.tokenFormat)} · cached ${fmtTokens(
148
+ summary.cachedTokens,
149
+ prefs.tokenFormat,
150
+ )} · out ${approx(fmtTokens(summary.estTokens, prefs.tokenFormat), summary.approx)}`}
151
+ />
152
+ {state.ctxUsed !== null && state.ctxMax !== null ? (
153
+ <Row
154
+ styles={styles}
155
+ label="context"
156
+ value={`${fmtTokens(state.ctxUsed, prefs.tokenFormat)} / ${fmtTokens(state.ctxMax, prefs.tokenFormat)}`}
157
+ />
158
+ ) : null}
159
+ <Row
160
+ styles={styles}
161
+ label="steps"
162
+ value={`${summary.steps}${summary.waitMs > 0 ? ` \u00b7 tools waited ${fmtDuration(summary.waitMs)}` : ""}`}
163
+ />
164
+ {summary.userWaitMs > 0 || summary.waiting ? (
165
+ <Row
166
+ styles={styles}
167
+ label={summary.waiting ? "waiting for you" : "user wait"}
168
+ value={fmtDuration(summary.userWaitMs)}
169
+ />
170
+ ) : null}
171
+ {summary.totalMs !== null ? (
172
+ <Row styles={styles} label="turn time" value={fmtDuration(summary.totalMs)} />
173
+ ) : null}
174
+ <Row styles={styles} label="calibration" value={`${cpt.toFixed(1)} chars/tok`} />
175
+ {noUsage ? (
176
+ <Text style={styles.hint}>
177
+ {store.everSawUsage
178
+ ? "\u2248 estimated from characters: the current model call reports its usage when it finishes."
179
+ : "\u2248 estimated from characters: no usage events from the provider. For exact tokens enable options.includeUsage: true for this model."}
180
+ </Text>
181
+ ) : null}
182
+ </View>
183
+ );
184
+ };
185
+ }
@@ -0,0 +1,43 @@
1
+ /** Pure display formatting, shared by the pill and the popover. */
2
+
3
+ /** 139, 12.4, 1.87 — always 3 significant characters worth of precision. */
4
+ export function fmtRate(rate: number | null): string {
5
+ if (rate === null || !Number.isFinite(rate) || rate <= 0) return "—";
6
+ if (rate >= 100) return String(Math.round(rate));
7
+ if (rate >= 10) return rate.toFixed(1);
8
+ return rate.toFixed(2);
9
+ }
10
+
11
+ /** 823 / 1.2k / 12.4k / 128k, or plain grouped digits. */
12
+ export function fmtTokens(n: number, format: "compact" | "plain" = "compact"): string {
13
+ if (!Number.isFinite(n) || n < 0) return "—";
14
+ if (format === "plain") return fmtGrouped(Math.round(n));
15
+ if (n < 1000) return String(Math.round(n));
16
+ if (n < 10_000) return `${(n / 1000).toFixed(1)}k`;
17
+ if (n < 100_000) return `${Math.round(n / 1000)}k`;
18
+ return `${Math.round(n / 1000)}k`;
19
+ }
20
+
21
+ function fmtGrouped(n: number): string {
22
+ return String(n).replace(/\B(?=(\d{3})+(?!\d))/g, "\u2009");
23
+ }
24
+
25
+ /** 640ms / 12.3s / 2m05s */
26
+ export function fmtDuration(ms: number | null): string {
27
+ if (ms === null || !Number.isFinite(ms) || ms < 0) return "—";
28
+ if (ms < 1000) return `${Math.round(ms)}ms`;
29
+ if (ms < 60_000) return `${(ms / 1000).toFixed(1)}s`;
30
+ const m = Math.floor(ms / 60_000);
31
+ const s = Math.round((ms % 60_000) / 1000);
32
+ return `${m}m${String(s).padStart(2, "0")}s`;
33
+ }
34
+
35
+ /** Prefix an estimated number. */
36
+ export function approx(value: string, isApprox: boolean): string {
37
+ return isApprox ? `\u2248${value}` : value;
38
+ }
39
+
40
+ export function fmtTokPerSec(rate: number | null, isApprox: boolean): string {
41
+ const text = fmtRate(rate);
42
+ return text === "—" ? text : `${approx("", isApprox)}${text} tok/s`;
43
+ }