pi-quiver 3.4.0 → 3.4.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/CHANGELOG.md CHANGED
@@ -8,6 +8,11 @@ Published to npm as `pi-quiver` (`pi install npm:pi-quiver`). Pushing a
8
8
  via OIDC trusted publishing. The release helper at
9
9
  `.agents/skills/release/scripts/release.sh` cuts the tag; CI publishes.
10
10
 
11
+ ## v3.4.1 - 2026-08-04
12
+
13
+ - **`fast-mode` now corrects reported `usage.cost` to true 2x fast pricing for Opus 4.8/5** (statusline, persisted cost, and pi-cohort `Σ$` per load order) (#6).
14
+ - **Documented Anthropic stall-retry activation.** A session trace confirmed Pi's existing 2/4/8-second exponential backoff was active and that the watchdog retained the retry budget resolved when its extension instance started. Local `retry.maxRetries: 5` now takes effect after a fresh session or explicit reload, with no watchdog cooldown, resubmission path, or runtime code change.
15
+
11
16
  ## v3.4.0 - 2026-07-30
12
17
 
13
18
  - **`provider-stall-watchdog`: new `firstEventMs` tier (default 20s) fast-fails a request that never streams.** A pre-first-event deadline is armed at every provider request and cleared by the first assistant `message_start`; on expiry the request is aborted and converted to a retryable error, cutting recovery for an unresponsive request from ~240s to ~22s (detection + Pi's 2s backoff). Previously only the 240s mid-stream `recoveryMs` timer caught this case.
package/README.md CHANGED
@@ -150,6 +150,8 @@ These extensions are opt-in via `settings.json` (project `.pi/settings.json` ove
150
150
 
151
151
  `sessionAutoName.enabled` makes one extra short LLM call per session (once, after the first turn) to title it; `false` (default) makes no model calls. `fastMode` only affects `claude-opus-4-8` and `claude-opus-5` requests on Anthropic's `anthropic-messages` API; enabling it opts into premium fast-mode pricing. `--fast` forces it on for one launch; `/fast on|off` toggles live. Proxy providers (opencode, cloudflare-ai-gateway) are excluded. `fastMode`'s header injection needs the `before_provider_headers` hook (pi bundling `@earendil-works/pi-coding-agent` >= 0.80.5); on older pi the beta header is silently not sent. See [doc/fetch.md](doc/fetch.md) and [doc/doc-to-md.md](doc/doc-to-md.md) for the ingestion tools' full reference; session-name/sword-header behavior above is complete.
152
152
 
153
+ `pi-ai` prices every fast request at standard rates - it has no `usage.speed` support and no request-level pricing modifier - so `fastMode` corrects the reported cost itself: a `message_end` handler scales all four `usage.cost` components by `FAST_MODE_COST_MULTIPLIER` (2x) and returns the corrected message. Persisted session JSONL and pi's own native cost display are always exact, since they're written from this corrected message. pi-cohort's live `Σ$` reflects the correction only when pi-quiver's `message_end` handler runs before pi-cohort's - best-effort, depending on extension load order - and is reconciled on pi-cohort's next `session_start` regardless. The upstream fix (teaching `pi-ai`'s `Usage`/`calculateCost` about `usage.speed`) is the better long-term path and is tracked separately.
154
+
153
155
  Recommended explicit retry and watchdog settings:
154
156
 
155
157
  ```json
package/fast-mode.ts CHANGED
@@ -22,6 +22,7 @@
22
22
  */
23
23
 
24
24
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
25
+ import type { Usage } from "@earendil-works/pi-ai";
25
26
  import { resolveConfig } from "./extension-config.ts";
26
27
 
27
28
  export const FAST_MODE_BETA = "fast-mode-2026-02-01";
@@ -29,6 +30,21 @@ export const FAST_SPEED = "fast";
29
30
  // Loose prefixes: match dated snapshots (claude-opus-4-8-*, claude-opus-5-*).
30
31
  // Opus 4.7 is out of scope (D1); a future model needs a one-line addition here.
31
32
  export const FAST_MODE_MODEL_PREFIXES = ["claude-opus-4-8", "claude-opus-5"];
33
+
34
+ // Anthropic bills Opus 4.8/5 fast mode at exactly 2x standard rates; input,
35
+ // output, and cache read/write all scale by the same factor because caching
36
+ // multipliers "apply on top of fast mode pricing". Rate card:
37
+ // https://docs.claude.com/en/docs/build-with-claude/fast-mode (retrieved 2026-08-04).
38
+ export const FAST_MODE_COST_MULTIPLIER = 2;
39
+
40
+ export function scaleCost(cost: Usage["cost"], multiplier: number): Usage["cost"] {
41
+ const input = cost.input * multiplier;
42
+ const output = cost.output * multiplier;
43
+ const cacheRead = cost.cacheRead * multiplier;
44
+ const cacheWrite = cost.cacheWrite * multiplier;
45
+ return { input, output, cacheRead, cacheWrite, total: input + output + cacheRead + cacheWrite };
46
+ }
47
+
32
48
  export const OAUTH_IDENTITY_BETAS = ["claude-code-20250219", "oauth-2025-04-20"];
33
49
  const STATUS_KEY = "fast-mode";
34
50
  const BETA_HEADER = "anthropic-beta";
@@ -92,6 +108,10 @@ export function resolveEnabled(s: State): boolean {
92
108
  export default function (pi: ExtensionAPI) {
93
109
  let liveOverride: boolean | null = null;
94
110
  let enabled = false;
111
+ // Per-request snapshot. Safe as plain booleans because pi serializes provider
112
+ // requests per session (headers -> request -> message_end, awaited in order).
113
+ let pendingFastSpeed = false;
114
+ let pendingFastHeader = false;
95
115
 
96
116
  const readFlag = (): boolean => pi.getFlag("fast") === true;
97
117
 
@@ -135,16 +155,43 @@ export default function (pi: ExtensionAPI) {
135
155
  });
136
156
 
137
157
  pi.on("before_provider_request", (event, ctx) => {
138
- if (!shouldInject(enabled, ctx.model)) return;
139
- return injectSpeed(event.payload);
158
+ if (!shouldInject(enabled, ctx.model)) {
159
+ pendingFastSpeed = false;
160
+ return;
161
+ }
162
+ const next = injectSpeed(event.payload);
163
+ pendingFastSpeed =
164
+ typeof next === "object" && next !== null && (next as Record<string, unknown>).speed === FAST_SPEED;
165
+ return next;
140
166
  });
141
167
 
142
168
  pi.on("before_provider_headers", async (event, ctx) => {
143
- if (!shouldInject(enabled, ctx.model)) return;
144
- if (!event.headers) return;
169
+ if (!shouldInject(enabled, ctx.model) || !event.headers) {
170
+ pendingFastHeader = false;
171
+ return;
172
+ }
145
173
  const isOAuth = await detectOAuth(ctx);
146
- if (isOAuth === null) return;
174
+ if (isOAuth === null) {
175
+ pendingFastHeader = false;
176
+ return;
177
+ }
147
178
  event.headers[BETA_HEADER] = buildBetaHeader(event.headers[BETA_HEADER], isOAuth);
179
+ pendingFastHeader = true;
180
+ });
181
+
182
+ pi.on("message_end", (event) => {
183
+ const msg = event.message;
184
+ if (msg.role !== "assistant") return;
185
+ const corrected = pendingFastSpeed && pendingFastHeader && !!msg.usage?.cost;
186
+ pendingFastSpeed = false;
187
+ pendingFastHeader = false;
188
+ if (!corrected) return;
189
+ return {
190
+ message: {
191
+ ...msg,
192
+ usage: { ...msg.usage, cost: scaleCost(msg.usage.cost, FAST_MODE_COST_MULTIPLIER) },
193
+ },
194
+ };
148
195
  });
149
196
 
150
197
  pi.registerCommand("fast", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-quiver",
3
- "version": "3.4.0",
3
+ "version": "3.4.1",
4
4
  "description": "Personal pack of Pi coding-agent extensions: context-safe fetch, doc_to_md PDF/DOCX/PPTX-to-Markdown conversion, session naming, a themed ASCII startup header, Opus 4.8 fast mode, and a provider-stall watchdog.",
5
5
  "author": "Jacek Juraszek",
6
6
  "license": "MIT",