@ferris1225/pi-subagents 4.3.22 → 4.3.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,23 @@
3
3
  Release notes for `@ferris1225/pi-subagents`. Only the most recent releases
4
4
  are kept here; every published version is preserved as a GitHub Release.
5
5
 
6
+ ## 4.3.24
7
+
8
+ - Remove the live `tok/s` throughput figure from the per-model cost footer.
9
+ Dividing the message's output tokens by wall-clock stream time could not be
10
+ made trustworthy across providers (reasoning tokens, time-to-first-token,
11
+ and per-chunk usage semantics differ), and no mainstream agent CLI ships a
12
+ comparable live rate. The footer keeps exactly-reported facts only: per-model
13
+ token flow, cost, context share, and thinking level.
14
+
15
+ ## 4.3.23
16
+
17
+ - Track Pi 1.0.3. The extension API, RPC command types, and the child
18
+ `registerProvider` path are unchanged. Pi renamed the Azure provider from
19
+ `azure-openai-responses` to `azure`; a stored agent model override follows
20
+ whichever of those ids the live catalog still lists, and is rewritten to
21
+ `azure/<id>` once that is the one Pi reports.
22
+
6
23
  ## 4.3.22
7
24
 
8
25
  - Use a subagent when the work can run independently in parallel, its boundary
package/README.md CHANGED
@@ -13,6 +13,16 @@ is clear, and delegation will actually reduce cost or improve completion quality
13
13
 
14
14
  ## What's new
15
15
 
16
+ **4.3.24** — the per-model cost footer drops the live `tok/s` throughput
17
+ figure: measured rates could not be trusted across providers, so the footer
18
+ sticks to what pi reports exactly — per-model token flow, cost, context share,
19
+ and thinking level.
20
+
21
+ **4.3.23** — Pi 1.0.3. Development dependencies track that release. A stored
22
+ agent model that still names `azure-openai-responses/<id>` keeps working: it
23
+ follows the live catalog, and is saved as `azure/<id>` once that is the id Pi
24
+ reports.
25
+
16
26
  **4.3.22** — use a subagent when the work can run independently in parallel, its
17
27
  boundary is clear, and delegation will actually reduce cost or improve
18
28
  completion quality. Role choice stays with scout and artisan.
@@ -155,7 +165,7 @@ material assumptions or blockers.
155
165
 
156
166
  Children run the official `pi --mode rpc` server, using Pi's exported command/response
157
167
  types and its own session persistence. There is no separate subagent protocol. The
158
- host transport remains local. Pi 1.0.2's `RpcClient` still spawns its own `node`
168
+ host transport remains local. Pi 1.0.3's `RpcClient` still spawns its own `node`
159
169
  process, signals only that process, and does not provide process-tree shutdown,
160
170
  bounded abort coordination, or cancellation of child extension dialogs.
161
171
 
@@ -398,13 +408,12 @@ capped at ten lines: when many runs are live, extra runs collapse into a
398
408
  In TUI sessions the extension replaces pi's built-in consumption line with a
399
409
  per-model tally of the main window's own spend, directly under the
400
410
  current-project line. Models are never merged: each `provider/model` keeps its
401
- own token flow, cost, and — for the current model — context share, effective
402
- thinking level, and live throughput (`~` marks the streaming estimate; the
403
- exact rate of the last completed message replaces it):
411
+ own token flow, cost, and — for the current model — context share and
412
+ effective thinking level:
404
413
 
405
414
  ```text
406
415
  ~/projs/app (main)
407
- ↑48.1k ↓112.7k R1.9M W302.4k $3.0812 · 41.2%/200.0k · ~58.3 tok/s zhipu/glm-4.7 • high
416
+ ↑48.1k ↓112.7k R1.9M W302.4k $3.0812 · 41.2%/200.0k zhipu/glm-4.7 • high
408
417
  anthropic/claude-sonnet-4 ↑12.0k ↓31.2k R410.0k $0.9104
409
418
  ```
410
419
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ferris1225/pi-subagents",
3
- "version": "4.3.22",
3
+ "version": "4.3.24",
4
4
  "description": "A managed sub-agent team for pi: lightweight scout research and artisan implementation, one-shot runs, read-only status, and Git worktree isolation.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -49,11 +49,11 @@
49
49
  "typebox": "*"
50
50
  },
51
51
  "devDependencies": {
52
- "@earendil-works/pi-agent-core": "^1.0.2",
53
- "@earendil-works/pi-ai": "^1.0.2",
54
- "@earendil-works/pi-coding-agent": "^1.0.2",
55
- "@earendil-works/pi-server": "^1.0.2",
56
- "@earendil-works/pi-tui": "^1.0.2",
52
+ "@earendil-works/pi-agent-core": "^1.0.3",
53
+ "@earendil-works/pi-ai": "^1.0.3",
54
+ "@earendil-works/pi-coding-agent": "^1.0.3",
55
+ "@earendil-works/pi-server": "^1.0.3",
56
+ "@earendil-works/pi-tui": "^1.0.3",
57
57
  "@types/node": "^22.10.0",
58
58
  "typebox": "^1.3.27",
59
59
  "typescript": "^5.9.0"
@@ -54,6 +54,32 @@ function cleanModelRef(ref: string | undefined): string | undefined {
54
54
  return trimmed || undefined;
55
55
  }
56
56
 
57
+ /**
58
+ * Provider ids Pi renamed while keeping the model id. Pi 1.0.3 renamed
59
+ * `azure-openai-responses` to `azure`. The old id stays valid on earlier 1.0
60
+ * hosts, so a stored override follows whichever id the live catalog still has.
61
+ */
62
+ const RENAMED_PROVIDER_IDS: Readonly<Record<string, string>> = {
63
+ "azure-openai-responses": "azure",
64
+ };
65
+
66
+ /** Stored ref plus the renamed provider id, when Pi published one. */
67
+ export function modelRefAliases(ref: string): readonly string[] {
68
+ const normalized = ref.trim();
69
+ const slash = normalized.indexOf("/");
70
+ if (slash <= 0 || slash >= normalized.length - 1) return [normalized];
71
+ const renamed = RENAMED_PROVIDER_IDS[normalized.slice(0, slash)];
72
+ if (!renamed) return [normalized];
73
+ return [normalized, `${renamed}${normalized.slice(slash)}`];
74
+ }
75
+
76
+ /** Prefer the alias that the live catalog actually lists. */
77
+ function resolveLiveModelRef(ref: string, liveRefs: ReadonlySet<string> | undefined): string | undefined {
78
+ const aliases = modelRefAliases(ref);
79
+ if (!liveRefs) return aliases[0];
80
+ return aliases.find((candidate) => liveRefs.has(candidate));
81
+ }
82
+
57
83
  export function modelRef(model: { provider: string; id: string }): string {
58
84
  return `${model.provider}/${model.id}`;
59
85
  }
@@ -82,7 +108,9 @@ export function findModelByRef(
82
108
  ref: string | undefined,
83
109
  ): Model<Api> | undefined {
84
110
  const normalized = cleanModelRef(ref);
85
- return normalized ? models.find((model) => modelRef(model) === normalized) : undefined;
111
+ if (!normalized) return undefined;
112
+ const aliases = new Set(modelRefAliases(normalized));
113
+ return models.find((model) => aliases.has(modelRef(model)));
86
114
  }
87
115
 
88
116
  /** Split persisted agent model overrides into the ones Pi still reports as
@@ -95,7 +123,10 @@ export function filterUnavailableModelOverrides(
95
123
  const kept: Record<string, string> = {};
96
124
  const dropped: Array<{ agent: string; ref: string }> = [];
97
125
  for (const [agent, ref] of Object.entries(agentModels)) {
98
- if (findModelByRef(models, ref)) kept[agent] = ref;
126
+ const model = findModelByRef(models, ref);
127
+ // Persist the id the live catalog uses, so a renamed provider does not
128
+ // stay stored under the id Pi no longer registers.
129
+ if (model) kept[agent] = modelRef(model);
99
130
  else dropped.push({ agent, ref });
100
131
  }
101
132
  return { kept, dropped };
@@ -116,8 +147,9 @@ export function resolveAgentModelRoute(input: AgentModelRouteInput): ResolvedAge
116
147
  const available = input.availableRefs
117
148
  ? new Set(input.availableRefs.map((ref) => ref.trim()).filter(Boolean))
118
149
  : undefined;
119
- const selectedAvailable = !selectedRef || !available || available.has(selectedRef);
120
- const usableSelectedRef = selectedAvailable ? selectedRef : undefined;
150
+ const resolvedSelectedRef = selectedRef ? resolveLiveModelRef(selectedRef, available) : undefined;
151
+ const selectedAvailable = !selectedRef || resolvedSelectedRef !== undefined;
152
+ const usableSelectedRef = selectedAvailable ? resolvedSelectedRef : undefined;
121
153
  const primaryRef = usableSelectedRef ?? mainRef;
122
154
  const ordered = [primaryRef, usableSelectedRef && usableSelectedRef !== mainRef ? mainRef : undefined];
123
155
  const candidateRefs = [...new Set(ordered.filter((ref): ref is string => Boolean(ref)))];
@@ -155,18 +187,21 @@ export function buildModelPickerItems(options: {
155
187
  configuredRef?: string;
156
188
  mainRef?: string;
157
189
  }): ModelPickerItem[] {
158
- const configuredRef = cleanModelRef(options.configuredRef);
159
190
  const mainRef = cleanModelRef(options.mainRef);
160
191
  const byRef = new Map<string, ModelListEntry>();
161
192
  for (const model of options.models) {
162
193
  const ref = modelRef(model);
163
194
  if (!byRef.has(ref)) byRef.set(ref, model);
164
195
  }
196
+ const configuredRef = cleanModelRef(options.configuredRef);
197
+ const liveConfiguredRef = configuredRef
198
+ ? resolveLiveModelRef(configuredRef, new Set(byRef.keys())) ?? configuredRef
199
+ : undefined;
165
200
 
166
201
  const refs = [...byRef.keys()]
167
202
  .sort((left, right) => {
168
- const leftRank = left === configuredRef ? 0 : left === mainRef ? 1 : 2;
169
- const rightRank = right === configuredRef ? 0 : right === mainRef ? 1 : 2;
203
+ const leftRank = left === liveConfiguredRef ? 0 : left === mainRef ? 1 : 2;
204
+ const rightRank = right === liveConfiguredRef ? 0 : right === mainRef ? 1 : 2;
170
205
  return leftRank - rightRank || left.localeCompare(right);
171
206
  });
172
207
 
@@ -178,7 +213,7 @@ export function buildModelPickerItems(options: {
178
213
  const items: ModelPickerItem[] = [dynamic];
179
214
  for (const ref of refs) {
180
215
  const model = byRef.get(ref)!;
181
- const tags = [ref === configuredRef ? "configured" : "", ref === mainRef ? "current main" : ""]
216
+ const tags = [ref === liveConfiguredRef ? "configured" : "", ref === mainRef ? "current main" : ""]
182
217
  .filter(Boolean);
183
218
  const name = model.name.trim() && model.name !== model.id ? model.name.trim() : undefined;
184
219
  items.push({
@@ -20,8 +20,10 @@ async function removeUnavailableAgentModels(
20
20
  const overrides = Object.entries(config.agentModels);
21
21
  if (overrides.length === 0) return;
22
22
  const { kept, dropped } = filterUnavailableModelOverrides(config.agentModels, availableModelsInScope(ctx));
23
- if (dropped.length === 0) return;
23
+ const rewritten = JSON.stringify(kept) !== JSON.stringify(config.agentModels);
24
+ if (!rewritten && dropped.length === 0) return;
24
25
  await saveConfig({ ...config, agentModels: kept }, runtime.configPath);
26
+ if (dropped.length === 0) return;
25
27
  const list = dropped.map(({ agent, ref }) => `${agent}: ${ref}`).join(", ");
26
28
  ctx.ui.notify(
27
29
  `pi-subagents: removed stale agent model overrides that are no longer available (${list}). Those agents now use their role's default model route; run /subagents-setup to re-pick.`,
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Persistent cost footer: replaces pi's built-in consumption line with a
3
3
  * per-model tally of the main window's own spend, so models are never summed
4
- * into one number — each `provider/model` keeps its own token flow, cost,
5
- * context share, and live throughput. The current-project line stays first,
6
- * exactly where pi put it; extension statuses stay last.
4
+ * into one number — each `provider/model` keeps its own token flow, cost, and
5
+ * context share. The current-project line stays first, exactly where pi put
6
+ * it; extension statuses stay last.
7
7
  *
8
8
  * Sub-agent spend is intentionally absent: children report per-run usage with
9
9
  * their model ref when they settle, and injecting it here (or into the parent
@@ -61,11 +61,6 @@ function contextPart(theme: Theme, usage: { percent?: number | null; contextWind
61
61
  return display;
62
62
  }
63
63
 
64
- function speedPart(speed: { tokensPerSecond: number; streaming: boolean } | undefined): string {
65
- if (!speed || speed.tokensPerSecond <= 0) return "";
66
- return `${speed.streaming ? "~" : ""}${speed.tokensPerSecond.toFixed(1)} tok/s`;
67
- }
68
-
69
64
  function spendUsage(spend: ModelSpendRow["spend"]): UsageStats {
70
65
  return { ...spend, contextTokens: 0, turns: 0 };
71
66
  }
@@ -88,11 +83,6 @@ function currentModelLine(
88
83
  const parts = [spendPart(row.spend)];
89
84
  const context = contextPart(theme, ctx.getContextUsage?.());
90
85
  if (context) parts.push(context);
91
- const speed = costLedger.speed();
92
- if (speed && speed.model === row.model) {
93
- const part = speedPart(speed);
94
- if (part) parts.push(part);
95
- }
96
86
  let left = parts.join(" ");
97
87
  if (visibleWidth(left) > width) left = truncateToWidth(left, width, "…");
98
88
 
@@ -124,7 +114,7 @@ function settledModelLine(row: ModelSpendRow, theme: Theme, width: number): stri
124
114
  }
125
115
 
126
116
  /** Render the replacement footer: project line first, one line per model the
127
- * main window spent on (current model with context + throughput), extension
117
+ * main window spent on (current model with context share), extension
128
118
  * statuses last — the same slots the built-in footer used. Settled models are
129
119
  * ranked by spend and capped, so a session that switched through many models
130
120
  * never grows the footer without bound. */
@@ -6,7 +6,7 @@
6
6
  * per-model completion totals), so mixing its live spend into the parent's
7
7
  * footer would just re-create the cross-model sum this ledger exists to
8
8
  * avoid. The ledger covers the main window only — across `/model` switches,
9
- * each model keeps its own tally — plus its live token throughput.
9
+ * each model keeps its own tally.
10
10
  */
11
11
 
12
12
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
@@ -28,23 +28,6 @@ export interface ModelSpendRow {
28
28
  spend: ModelSpend;
29
29
  }
30
30
 
31
- export interface MainStreamSpeed {
32
- model: string;
33
- tokensPerSecond: number;
34
- /** True while the assistant is still streaming (value is an estimate). */
35
- streaming: boolean;
36
- }
37
-
38
- interface StreamState {
39
- model: string;
40
- startedAt: number;
41
- estimatedChars: number;
42
- }
43
-
44
- /** Rough chars-per-token for the live estimate; the exact rate replaces it at
45
- * `message_end`, where real output tokens are known. */
46
- const ESTIMATED_CHARS_PER_TOKEN = 4;
47
-
48
31
  /** pi Usage shape: numeric token buckets plus a cost that is either already a
49
32
  * number (child tallies) or the provider object with a `total`. */
50
33
  interface UsageLike {
@@ -84,8 +67,6 @@ export class CostLedger {
84
67
  /** First-seen order, so row order is stable between notifications. */
85
68
  private order: string[] = [];
86
69
  private currentModel: string | undefined;
87
- private stream: StreamState | undefined;
88
- private lastSpeed: MainStreamSpeed | undefined;
89
70
  private subscribers = new Set<() => void>();
90
71
 
91
72
  record(model: string, spend: UsageLike | undefined): void {
@@ -133,8 +114,6 @@ export class CostLedger {
133
114
  this.rows.clear();
134
115
  this.order = [];
135
116
  this.currentModel = undefined;
136
- this.stream = undefined;
137
- this.lastSpeed = undefined;
138
117
  this.notify();
139
118
  }
140
119
 
@@ -145,46 +124,6 @@ export class CostLedger {
145
124
  };
146
125
  }
147
126
 
148
- noteStreamStart(model: string): void {
149
- this.stream = { model, startedAt: Date.now(), estimatedChars: 0 };
150
- this.lastSpeed = undefined;
151
- this.notify();
152
- }
153
-
154
- noteStreamDelta(chars: number): void {
155
- if (!this.stream || chars <= 0) return;
156
- this.stream.estimatedChars += chars;
157
- this.notify();
158
- }
159
-
160
- isStreaming(): boolean {
161
- return this.stream !== undefined;
162
- }
163
-
164
- noteStreamEnd(model: string, outputTokens: number): void {
165
- const stream = this.stream;
166
- this.stream = undefined;
167
- if (stream && outputTokens > 0) {
168
- const seconds = Math.max(0.001, (Date.now() - stream.startedAt) / 1_000);
169
- this.lastSpeed = { model, tokensPerSecond: outputTokens / seconds, streaming: false };
170
- }
171
- this.notify();
172
- }
173
-
174
- /** Live estimate while streaming, exact rate of the last completed
175
- * assistant message afterwards; undefined before any generation. */
176
- speed(): MainStreamSpeed | undefined {
177
- if (this.stream) {
178
- const seconds = Math.max(0.001, (Date.now() - this.stream.startedAt) / 1_000);
179
- return {
180
- model: this.stream.model,
181
- tokensPerSecond: this.stream.estimatedChars / ESTIMATED_CHARS_PER_TOKEN / seconds,
182
- streaming: true,
183
- };
184
- }
185
- return this.lastSpeed;
186
- }
187
-
188
127
  private notify(): void {
189
128
  for (const cb of this.subscribers) {
190
129
  try {
@@ -202,35 +141,12 @@ export const costLedger = new CostLedger();
202
141
  * carry the serving model and exact usage, model switches re-key the current
203
142
  * row, and compaction calls land on the model that made them. */
204
143
  export function registerMainCostTracking(pi: ExtensionAPI): void {
205
- pi.on("message_start", async (event) => {
206
- const message = (event as { message?: { role?: string } }).message;
207
- if (message?.role !== "assistant") return;
208
- const ref = messageModelRef(message as { provider?: string; model?: string });
209
- if (ref) costLedger.noteStreamStart(ref);
210
- });
211
-
212
- pi.on("message_update", async (event) => {
213
- const delta = (event as { assistantMessageEvent?: { type?: string; delta?: string } }).assistantMessageEvent;
214
- if (delta?.type !== "text_delta" && delta?.type !== "thinking_delta") return;
215
- // `message_start` does not always carry the model yet; the first delta
216
- // of the stream is just as good a clock start.
217
- if (!costLedger.isStreaming()) {
218
- const partial = (event as { message?: { role?: string } }).message;
219
- if (partial?.role === "assistant") {
220
- const ref = messageModelRef(partial as { provider?: string; model?: string });
221
- if (ref) costLedger.noteStreamStart(ref);
222
- }
223
- }
224
- costLedger.noteStreamDelta(delta.delta?.length ?? 0);
225
- });
226
-
227
144
  pi.on("message_end", async (event) => {
228
145
  const message = (event as { message?: { role?: string; provider?: string; model?: string; usage?: UsageLike } }).message;
229
146
  if (message?.role !== "assistant") return;
230
147
  const ref = messageModelRef(message) ?? costLedger.getCurrentModel();
231
148
  if (!ref) return;
232
149
  const usage = finiteUsage(message.usage);
233
- costLedger.noteStreamEnd(ref, usage.output);
234
150
  costLedger.record(ref, usage);
235
151
  });
236
152