pi-quiver 6.16.0 → 6.16.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/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  Format follows sibling pi packages (e.g. [`pi-condense`](https://github.com/jjuraszek/pi-condense/blob/main/CHANGELOG.md)):
4
4
  one entry per `vX.Y.Z` tag, newest first, terse bullets, dated.
5
5
 
6
+ ## v6.16.2 - 2026-11-15
7
+
8
+ - `fast-mode` covers every model in Anthropic's fast-mode availability table: Claude Fable 5.2 and Mythos 5.2 join Opus 5.5, Opus 5, and Opus 4.8. The `fast-mode-2026-02-01` beta header goes only to Opus 5 (research preview) and Opus 4.8 (deprecated), the two models Anthropic still requires it on; Fable 5.2, Mythos 5.2, and Opus 5.5 get `speed: "fast"` alone and keep the `anthropic-beta` header pi built. Opus 5.5 previously got the header through the `claude-opus-5` prefix, which dropped pi's `message-threads-2026-08-12` beta and cost a rejected first attempt on every request. Cost correction stays 2x, checked against the rate card for all five models. (#40)
9
+
10
+ ## v6.16.1 - 2026-11-09
11
+
12
+ - doc_to_md result and option enums share one declaration in `lib/`, so members cannot drift between TypeScript types and tool schemas. (#38)
13
+
6
14
  Published to npm as `pi-quiver` (`pi install npm:pi-quiver`). Pushing a
7
15
  `vX.Y.Z` tag triggers `.github/workflows/release.yml`, which publishes to npm
8
16
  via OIDC trusted publishing. The release helper at
package/README.md CHANGED
@@ -68,7 +68,7 @@ A 300 KB changelog page never touches your context window - you get a preview an
68
68
  | `extensions/doc_to_md.ts` | `doc_to_md` | Convert a local PDF/DOCX/DOC/PPTX/XLSX/XLSM/XLS, MSG/EML, HTML, or image file to a Markdown bundle on disk (`<stem>.md` + `images/`, spreadsheet `sheets/`, optional `pageImages` in `pages/`, and email `attachments/`) and return a handle (paths, page count, outline, diagnostics) - never inline Markdown. `info` inspects PDF/Office inputs; `pages` selects 1-based PDF/Office pages (DOCX: explicit-page-break segments); HTML, image, and email inputs reject both; every selected PDF/PPTX page or DOCX segment when `pageCount > 1` ends with `--- end of page.page_number=N ---`. Tiers: pymupdf4llm -> PyMuPDF text (degraded) -> unpdf worker (no Python only). Excel -> sheet inventory, full CSVs, bounded previews, and optional rendered views. HTML keeps local and `data:` images in the bundle and remote images as links; image inputs keep the original image. Scanned PDF pages keep a page picture on both Python tiers; eligible single full-page images are delivered as their embedded stream, without re-encoding or render DPI; opt-in OCR needs Tesseract language data. DOCX converts directly (mammoth, python-docx fallback); LibreOffice pagination marks the degraded route. The Outline lists `L<line>` and `p<page>` per heading. Settings under `quiver.docToMd`. Every conversion that goes through the Python PDF tiers (PDF, PPTX, `.doc`, DOCX via LibreOffice) writes `<stem>.pages.json` (per-page chars, image count, image coverage; handle line `Page-Stats:`); unpdf writes no stats. `ocrMode: "all"` with `ocr: true` and an explicit `pages` forces OCR on those pages into `ocr/<stem>-pNNN.md` sidecars, leaving the Markdown byte-identical to the same selected-page call without OCR. `words: true` (CLI `--words`, per-call only - no settings key) writes `<stem>.words.json` with every word's bbox per selected PDF/image page (`source` `text` or `ocr`), plus `ocr/<stem>-pNNN.words.json` beside each forced-OCR sidecar; it never triggers OCR. |
69
69
  | `extensions/session-name.ts` | `/session-name` | Manual + opt-in automatic session naming, naming rules and deny list, long-session revisits, and Ghostty/Herdr tab rename. OFF by default. |
70
70
  | `extensions/sword-header.ts` | `/builtin-header` | Themed ASCII startup header replacing pi's default logo. OFF by default. |
71
- | `extensions/fast-mode.ts` | `/fast` | Inject Anthropic fast-mode (`speed: "fast"` + `anthropic-beta: fast-mode-2026-02-01`) into every Claude Opus 4.8 / Opus 5 request, any thinking level. `--fast` flag + `/fast [on\|off\|status]`. OFF by default. |
71
+ | `extensions/fast-mode.ts` | `/fast` | Inject Anthropic fast-mode (`speed: "fast"`, plus `anthropic-beta: fast-mode-2026-02-01` where the model needs it) into every Claude Fable 5.2 / Mythos 5.2 / Opus 5.5 / Opus 5 / Opus 4.8 request, any thinking level. `--fast` flag + `/fast [on\|off\|status]`. OFF by default. |
72
72
  | `extensions/provider-stall-watchdog.ts` | - | Opt-in provider-stall recovery, in two tiers: a pre-first-event deadline (`firstEventMs`, 20s) on every provider request in every mode, and the mid-stream pair (warn at 2 min, recover at 4 min) in TUI runs only. Each stall is aborted; while pi's `retry.enabled` is true and the stall retry budget (`maxStallRetries`, default = `retry.maxRetries`) remains, its aborted attempt is hidden from the model and re-driven by the watchdog after pi's backoff; behavior guide: [doc/provider-stall-watchdog.md](doc/provider-stall-watchdog.md). OFF by default. |
73
73
  | `extensions/slack.ts` | `slack_search`, `slack_thread`, `slack_post`, `slack_update`, `slack_delete`, `slack_pin`, `slack_upload`, `slack_cache_refresh` | Context-safe Slack search/threads/posting with dual `user`/`bot` token identities, Block Kit flattening and optional raw JSON output for threads, a workspace-keyed channel/user name->ID cache, DM targets by `@name` / user ID, fetch-style output size gating, and a transactional headline+detail-thread announce protocol with a documented recovery path. Pi registration is OFF by default. Behavior lives in `lib/slack-core.ts` and `lib/slack-cache.ts`; the [Slack CLI](doc/slack.md#cli) exposes `post`, `reply`, `dm`, and `canvas` without enabling pi registration. |
74
74
  | `prompts/rebase-worktree.md` | `/rebase-worktree [base]` | Prompt template, pi only. Rebases the current worktree onto `origin/<base>` (default `main`), resolves conflicts inline with the authorization stated in the prompt, runs only the tests that cover the resolved files, and reports the resolutions and fix commits. Never pushes; it syncs the branch so a later CI run or `/skill:gatekeep-pr` sees current `main`. |
@@ -210,7 +210,7 @@ survive untouched.
210
210
 
211
211
  `swordHeader` swaps the header at `session_start`, which runs after pi has already drawn its built-in pixel logo, so the logo shows for a moment before the sword replaces it. To skip that flash set pi's own `"quietStartup": true` in `~/.pi/agent/settings.json`: pi then draws an empty header slot at startup and the sword fills it. Quiet startup also drops pi's key-hint lines, which the sword header does not reproduce.
212
212
 
213
- `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. The `anthropic-beta` header is discovered at request time by probing pi's own request assembly (no network), so conditional betas pi adds - e.g. `server-side-fallback-2026-07-01` for models with server-side fallback - are preserved alongside `fast-mode-2026-02-01`. If the probe fails, the header falls back to the static OAuth-identity + fast-mode list. 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.
213
+ `fastMode` only affects `claude-fable-5-2`, `claude-mythos-5-2`, `claude-opus-5-5`, `claude-opus-5`, and `claude-opus-4-8` requests on Anthropic's `anthropic-messages` API - the models in Anthropic's [fast-mode availability table](https://platform.claude.com/docs/en/build-with-claude/fast-mode#feature-availability); 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. Fable 5.2, Mythos 5.2, and Opus 5.5 get `speed: "fast"` alone, and pi's `anthropic-beta` header goes out as pi built it. Opus 5 (research preview) and Opus 4.8 (deprecated by Anthropic, removal date 2026-11-30) also get the `fast-mode-2026-02-01` beta header. That 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. The `anthropic-beta` header is discovered at request time by probing pi's own request assembly (no network), so conditional betas pi adds - e.g. `server-side-fallback-2026-07-01` for models with server-side fallback - are preserved alongside `fast-mode-2026-02-01`. If the probe fails, the header falls back to the static OAuth-identity + fast-mode list. 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.
214
214
 
215
215
  `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.
216
216
 
@@ -1034,6 +1034,8 @@ function formatInfoHandle(i, max) {
1034
1034
 
1035
1035
  // lib/doc-to-md-options.ts
1036
1036
  import { extname as extname2 } from "node:path";
1037
+ var IMAGE_FORMATS = ["png", "jpg"];
1038
+ var OCR_MODES = ["textless", "all"];
1037
1039
  var UsageError = class extends Error {
1038
1040
  };
1039
1041
  var MIN_PYMUPDF4LLM = "1.27.0";
@@ -1048,7 +1050,7 @@ var DOC_TO_MD_OPTIONS = [
1048
1050
  { key: "overwrite", flag: "--overwrite", type: "bool", default: false, settable: false, help: "Replace an existing completed <stem>.md bundle" },
1049
1051
  { key: "pageImages", flag: "--page-images", type: "bool", default: false, settable: false, help: "Also render every selected page to pages/<stem>-pNNN.<imageFormat> at imageDpi (PDF, PPTX, .doc, DOCX via LibreOffice); off by default" },
1050
1052
  { key: "words", toolHelp: "Write word positions to <stem>.words.json, or ocr/<stem>-pNNN.words.json for ocrMode all. Never triggers OCR. PDF and image inputs only.", flag: "--words", type: "bool", default: false, settable: false, help: 'Write word positions: <stem>.words.json beside the Markdown lists every text-layer word of each selected page with its bbox (PDF points, top-left origin, display orientation; image inputs in source pixels) and the words inline OCR recognized, tagged source "text" or "ocr"; under --ocr-mode all the OCR words go to ocr/<stem>-pNNN.words.json beside each sidecar. Never triggers OCR. PDF and image inputs only.' },
1051
- { key: "ocrMode", toolHelp: "textless (default): OCR empty text layers inline. all: OCR selected pages to ocr/ sidecars without changing Markdown; requires ocr and explicit pages (PDF, PPTX, DOC).", flag: "--ocr-mode", type: "enum", default: "textless", settable: false, enumValues: ["textless", "all"], help: "OCR policy: textless (default) OCRs only pages with an empty text layer, inline; all OCRs every selected page and writes the recognized text to ocr/<stem>-pNNN.md sidecars, leaving the Markdown untouched. all requires --ocr and an explicit --pages selection (PDF, PPTX, DOC)." },
1053
+ { key: "ocrMode", toolHelp: "textless (default): OCR empty text layers inline. all: OCR selected pages to ocr/ sidecars without changing Markdown; requires ocr and explicit pages (PDF, PPTX, DOC).", flag: "--ocr-mode", type: "enum", default: "textless", settable: false, enumValues: OCR_MODES, help: "OCR policy: textless (default) OCRs only pages with an empty text layer, inline; all OCRs every selected page and writes the recognized text to ocr/<stem>-pNNN.md sidecars, leaving the Markdown untouched. all requires --ocr and an explicit --pages selection (PDF, PPTX, DOC)." },
1052
1054
  { key: "primaryTimeoutMs", flag: "--primary-timeout", type: "int", default: 6e4, settable: true, env: "PI_DOC_TO_MD_CONVERT_TIMEOUT_MS", help: "pymupdf4llm tier and DOCX child (docx mode); also the unpdf tier" },
1053
1055
  { key: "fallbackTimeoutMs", flag: "--fallback-timeout", type: "int", default: 3e4, settable: true, help: "PyMuPDF get_text tier (including DOCX LibreOffice fallback); also PDF and DOCX info and Excel rendered views" },
1054
1056
  { key: "sofficeTimeoutMs", flag: "--soffice-timeout", type: "int", default: 12e4, settable: true, env: "PI_DOC_TO_MD_SOFFICE_TIMEOUT_MS", help: "DOCX/PPTX -> PDF via LibreOffice; also Excel rendered views" },
@@ -1056,7 +1058,7 @@ var DOC_TO_MD_OPTIONS = [
1056
1058
  { key: "warmTimeoutMs", flag: "--warm-timeout", type: "int", default: 12e4, settable: true, env: "PI_DOC_TO_MD_WARM_TIMEOUT_MS", help: "Absolute backend discovery/bootstrap deadline (first call per process)" },
1057
1059
  { key: "pymupdfVersion", flag: "--pymupdf-version", type: "version", default: "1.27.2.3", settable: true, env: "PI_DOC_TO_MD_PYMUPDF_VERSION", help: "pymupdf4llm pin (>= 1.27.0)" },
1058
1060
  { key: "imageDpi", flag: "--image-dpi", type: "int", default: 150, settable: true, help: "Render DPI for page images and Excel rendered views" },
1059
- { key: "imageFormat", flag: "--image-format", type: "enum", default: "png", settable: true, enumValues: ["png", "jpg"], help: "Rendered image format (embedded images keep their native extension)" },
1061
+ { key: "imageFormat", flag: "--image-format", type: "enum", default: "png", settable: true, enumValues: IMAGE_FORMATS, help: "Rendered image format (embedded images keep their native extension)" },
1060
1062
  { key: "maxOutputBytes", flag: "--max-output-bytes", type: "int", default: 2e7, settable: true, help: "Child stdout cap in bytes" },
1061
1063
  { key: "outlineMaxEntries", flag: "--outline-max-entries", type: "int", default: 40, settable: true, help: "Heading outline / TOC / sheet inventory cap in the handle" },
1062
1064
  { key: "ocr", flag: "--ocr", type: "bool", default: false, settable: true, help: "Run OCR on pages without a text layer and on image inputs when Tesseract language data is installed; off by default (--no-ocr turns a settings-level true off)" },
@@ -14,23 +14,24 @@ import {
14
14
  coerceDocToMdSettings, convertDocument, inspectDocument, resolveOptions,
15
15
  } from "../lib/doc-to-md-core.ts";
16
16
  import { resolve } from "node:path";
17
- import { publicHandle } from "../lib/doc-to-md-handle.ts";
17
+ import { BACKEND_KINDS, ENGINES, OCR_STATUSES, SHEET_KINDS, TIERS, publicHandle } from "../lib/doc-to-md-handle.ts";
18
+ import { INPUT_TYPES, OCR_MODES } from "../lib/doc-to-md-options.ts";
18
19
 
19
20
  const nullable = <T extends TSchema>(schema: T) => Type.Union([schema, Type.Null()]);
20
- const strings = <T extends string>(values: T[]) => Type.Union(values.map((value) => Type.Literal(value)));
21
+ const strings = <T extends string>(values: readonly T[]) => Type.Union(values.map((value) => Type.Literal(value)));
21
22
  const pages = Type.Array(Type.Integer());
22
23
  const pageStrings = Type.Record(Type.String(), Type.String());
23
- const inputType = strings(["pdf", "docx", "doc", "pptx", "xlsx", "xlsm", "xls", "html", "image", "email"]);
24
+ const inputType = strings(INPUT_TYPES);
24
25
  const tocEntry = { level: Type.Integer(), title: Type.String(), page: nullable(Type.Integer()) };
25
26
  const ocrSchema = Type.Object({
26
- status: strings(["off", "unavailable", "skipped", "ran"]), lang: Type.String(),
27
+ status: strings(OCR_STATUSES), lang: Type.String(),
27
28
  textless: pages, pages, noText: pages, ocrFailed: pages, budgetStopped: pages, ceilingStopped: pages,
28
29
  ocrMaxPages: Type.Integer(), reason: nullable(Type.String()), tesseract: nullable(Type.Boolean()),
29
- mode: strings(["textless", "all"]), sidecars: pageStrings, wordSidecars: pageStrings, ocrErrors: pageStrings,
30
+ mode: strings(OCR_MODES), sidecars: pageStrings, wordSidecars: pageStrings, ocrErrors: pageStrings,
30
31
  killed: nullable(Type.Integer()), notAttempted: pages, childError: nullable(Type.String()),
31
32
  });
32
33
  const sheetSchema = Type.Object({
33
- index: Type.Integer(), name: Type.String(), kind: strings(["worksheet", "chartsheet"]), hidden: Type.Boolean(),
34
+ index: Type.Integer(), name: Type.String(), kind: strings(SHEET_KINDS), hidden: Type.Boolean(),
34
35
  rows: nullable(Type.Integer()), cols: nullable(Type.Integer()), hiddenRows: Type.Integer(), hiddenCols: Type.Integer(),
35
36
  charts: Type.Integer(), images: Type.Integer(), rendered: Type.Boolean(), csv: nullable(Type.String()),
36
37
  });
@@ -38,8 +39,8 @@ const outputSchema = Type.Union([
38
39
  Type.Object({
39
40
  savedTo: Type.String(), imagesDir: nullable(Type.String()), sheetsDir: nullable(Type.String()), pagesDir: nullable(Type.String()),
40
41
  type: inputType,
41
- engine: strings(["pymupdf4llm", "pymupdf-text", "unpdf", "openpyxl", "xlrd", "mammoth", "python-docx", "markdownify", "turndown", "copy", "extract-msg", "email"]),
42
- tier: strings(["primary", "fallback", "unpdf", "excel", "docx", "html", "image", "email"]),
42
+ engine: strings(ENGINES),
43
+ tier: strings(TIERS),
43
44
  pageCount: nullable(Type.Integer()), pages: nullable(pages), explicitBreaks: nullable(Type.Integer()),
44
45
  imageCount: Type.Integer(), pageImageCount: Type.Integer(), pageImagesReason: nullable(Type.String()), bytes: Type.Integer(), lines: Type.Integer(),
45
46
  degraded: nullable(Type.String()), fallbackReason: nullable(Type.String()), failedPages: pages, emptyPages: pages,
@@ -53,7 +54,7 @@ const outputSchema = Type.Union([
53
54
  wordsPath: nullable(Type.String()), wordsReason: nullable(Type.String()), wordsErrors: pageStrings,
54
55
  }),
55
56
  Type.Object({
56
- type: inputType, backend: strings(["uv", "python", "venv", "none"]), pageCount: nullable(Type.Integer()),
57
+ type: inputType, backend: strings(BACKEND_KINDS), pageCount: nullable(Type.Integer()),
57
58
  metadata: Type.Record(Type.String(), Type.String()), toc: Type.Array(Type.Object(tocEntry)), tocTotal: Type.Integer(),
58
59
  sheets: nullable(Type.Array(sheetSchema)), sheetsTotal: Type.Integer(),
59
60
  }),
@@ -1,10 +1,13 @@
1
1
  /**
2
- * Fast mode for Claude Opus 4.8 / Opus 5.
2
+ * Fast mode for the Claude models Anthropic serves it on (FAST_MODE_MODELS).
3
3
  *
4
4
  * When enabled, injects Anthropic's fast-mode signals into every qualifying
5
- * Opus 4.8 / Opus 5 request on the anthropic-messages API, regardless of thinking level:
5
+ * request on the anthropic-messages API, regardless of thinking level:
6
6
  * - payload: { ...payload, speed: "fast" } (before_provider_request)
7
7
  * - header: anthropic-beta: ...,fast-mode-2026-02-01 (before_provider_headers)
8
+ * The header goes only to the models that still need the beta (Opus 5,
9
+ * Opus 4.8); on the rest `speed` is the whole contract and pi's own
10
+ * `anthropic-beta` list is left untouched.
8
11
  *
9
12
  * OFF BY DEFAULT. Three control surfaces, lowest precedence first:
10
13
  * 1. settings.json "fastMode": true | { "enabled": true } (default false)
@@ -33,14 +36,27 @@ import { resolveConfig } from "../lib/extension-config.ts";
33
36
 
34
37
  export const FAST_MODE_BETA = "fast-mode-2026-02-01";
35
38
  export const FAST_SPEED = "fast";
36
- // Loose prefixes: match dated snapshots (claude-opus-4-8-*, claude-opus-5-*).
37
- // Opus 4.7 is out of scope (D1); a future model needs a one-line addition here.
38
- export const FAST_MODE_MODEL_PREFIXES = ["claude-opus-4-8", "claude-opus-5"];
39
-
40
- // Anthropic bills Opus 4.8/5 fast mode at exactly 2x standard rates; input,
41
- // output, and cache read/write all scale by the same factor because caching
42
- // multipliers "apply on top of fast mode pricing". Rate card:
43
- // https://docs.claude.com/en/docs/build-with-claude/fast-mode (retrieved 2026-08-04).
39
+ // One row per model in Anthropic's fast-mode availability table:
40
+ // https://platform.claude.com/docs/en/build-with-claude/fast-mode#feature-availability
41
+ // (retrieved 2026-11-13). `beta` marks the models that need the fast-mode beta
42
+ // header - Opus 5 (research preview) and Opus 4.8 (deprecated, removal
43
+ // 2026-11-30); the rest take `speed` alone. A prefix matches the id itself or
44
+ // the id up to a `-`, so a dated claude-fable-5-2026... snapshot is not
45
+ // Fable 5.2. The first match wins, so claude-opus-5-5 must stay ahead of
46
+ // claude-opus-5. A model added to or dropped from that table is a one-row
47
+ // change here.
48
+ export const FAST_MODE_MODELS = [
49
+ { prefix: "claude-fable-5-2", beta: false },
50
+ { prefix: "claude-mythos-5-2", beta: false },
51
+ { prefix: "claude-opus-5-5", beta: false },
52
+ { prefix: "claude-opus-5", beta: true },
53
+ { prefix: "claude-opus-4-8", beta: true },
54
+ ];
55
+
56
+ // Anthropic bills fast mode at exactly 2x standard rates on every model in
57
+ // FAST_MODE_MODELS; input, output, and cache read/write all scale by the same
58
+ // factor because caching multipliers "apply on top of fast mode pricing". Rate card:
59
+ // https://platform.claude.com/docs/en/build-with-claude/fast-mode#pricing (retrieved 2026-11-13).
44
60
  export const FAST_MODE_COST_MULTIPLIER = 2;
45
61
 
46
62
  export function scaleCost(cost: Usage["cost"], multiplier: number): Usage["cost"] {
@@ -81,13 +97,21 @@ export function coerce(raw: unknown): Partial<Config> | undefined {
81
97
 
82
98
  type ModelLike = { id?: string; api?: string; provider?: string } | undefined;
83
99
 
100
+ function fastModeModel(model: ModelLike) {
101
+ const id = model?.id;
102
+ if (typeof id !== "string") return undefined;
103
+ return FAST_MODE_MODELS.find((m) => id === m.prefix || id.startsWith(`${m.prefix}-`));
104
+ }
105
+
84
106
  export function shouldInject(enabled: boolean, model: ModelLike): boolean {
85
107
  if (!enabled || !model) return false;
86
108
  if (model.provider !== "anthropic") return false;
87
109
  if (model.api !== "anthropic-messages") return false;
88
- const id = model.id;
89
- if (typeof id !== "string") return false;
90
- return FAST_MODE_MODEL_PREFIXES.some((p) => id.startsWith(p));
110
+ return fastModeModel(model) !== undefined;
111
+ }
112
+
113
+ export function needsFastModeBeta(model: ModelLike): boolean {
114
+ return fastModeModel(model)?.beta === true;
91
115
  }
92
116
 
93
117
  export function injectSpeed(payload: unknown): unknown {
@@ -185,6 +209,7 @@ export default function (pi: ExtensionAPI) {
185
209
  // requests per session (headers -> request -> message_end, awaited in order).
186
210
  let pendingFastSpeed = false;
187
211
  let pendingFastHeader = false;
212
+ let pendingBetaRequired = false;
188
213
 
189
214
  const readFlag = (): boolean => pi.getFlag("fast") === true;
190
215
 
@@ -221,7 +246,7 @@ export default function (pi: ExtensionAPI) {
221
246
 
222
247
  pi.registerFlag("fast", {
223
248
  type: "boolean",
224
- description: "Enable Anthropic fast mode for Opus 4.8/5 requests this launch",
249
+ description: "Enable Anthropic fast mode for supported Claude models this launch",
225
250
  });
226
251
 
227
252
  pi.on("session_start", async (_event, ctx) => {
@@ -241,11 +266,12 @@ export default function (pi: ExtensionAPI) {
241
266
  const next = injectSpeed(event.payload);
242
267
  pendingFastSpeed =
243
268
  typeof next === "object" && next !== null && (next as Record<string, unknown>).speed === FAST_SPEED;
269
+ pendingBetaRequired = needsFastModeBeta(ctx.model);
244
270
  return next;
245
271
  });
246
272
 
247
273
  pi.on("before_provider_headers", async (event, ctx) => {
248
- if (!shouldInject(enabled, ctx.model) || !event.headers) {
274
+ if (!shouldInject(enabled, ctx.model) || !needsFastModeBeta(ctx.model) || !event.headers) {
249
275
  pendingFastHeader = false;
250
276
  return;
251
277
  }
@@ -267,7 +293,9 @@ export default function (pi: ExtensionAPI) {
267
293
  pi.on("message_end", (event) => {
268
294
  const msg = event.message;
269
295
  if (msg.role !== "assistant") return;
270
- const corrected = pendingFastSpeed && pendingFastHeader && !!msg.usage?.cost;
296
+ // Billed fast: `speed` went out, plus the beta header where the model needs one.
297
+ const billedFast = pendingFastSpeed && (pendingFastHeader || !pendingBetaRequired);
298
+ const corrected = billedFast && !!msg.usage?.cost;
271
299
  pendingFastSpeed = false;
272
300
  pendingFastHeader = false;
273
301
  if (!corrected) return;
@@ -280,7 +308,7 @@ export default function (pi: ExtensionAPI) {
280
308
  });
281
309
 
282
310
  pi.registerCommand("fast", {
283
- description: "Manage Opus 4.8/5 fast mode: /fast [on|off|status]",
311
+ description: "Manage Anthropic fast mode: /fast [on|off|status]",
284
312
  getArgumentCompletions: (prefix) => {
285
313
  const p = prefix.trim().toLowerCase();
286
314
  if (p.includes(" ")) return null;
@@ -13,12 +13,12 @@ import { homedir, tmpdir } from "node:os";
13
13
  import { basename, dirname, extname, isAbsolute, join, resolve } from "node:path";
14
14
  import { fileURLToPath, pathToFileURL } from "node:url";
15
15
  import { type StagedPage, type Bundle, abortBundle, commitBundle, openBundle, publishAttachments, publishSidecars, publishWords, writePageStats, publishPageImages, publishSheetCsvs, publishSheetImages, publishStaged, rewriteLinks, tempBundleRoot, validateImageLinks } from "./doc-to-md-bundle.ts";
16
- import { type NativeImage, type Engine, type HandleData, type InfoData, type OcrInfo, type PageStat, type Tier, formatHandle, formatInfoHandle, scanOutline, type SheetInfo, type TocEntry } from "./doc-to-md-handle.ts";
16
+ import { type BackendKind, type NativeImage, type Engine, type HandleData, type InfoData, type OcrInfo, type PageStat, type Tier, formatHandle, formatInfoHandle, scanOutline, type SheetInfo, type TocEntry } from "./doc-to-md-handle.ts";
17
17
  import { type DocToMdOptions, type InputType, IMAGE_EXTS, TUNABLE_DEFAULTS, UsageError, classifyInput, sanitizeStem } from "./doc-to-md-options.ts";
18
18
 
19
19
  export * from "./doc-to-md-options.ts";
20
20
  export { compactRanges, formatHandle, formatInfoHandle, formatSize, scanOutline } from "./doc-to-md-handle.ts";
21
- export type { Engine, HandleData, InfoData, OutlineEntry, SheetInfo, Tier, TocEntry } from "./doc-to-md-handle.ts";
21
+ export type { BackendKind, Engine, HandleData, InfoData, OutlineEntry, SheetInfo, Tier, TocEntry } from "./doc-to-md-handle.ts";
22
22
 
23
23
  // --- Types ---
24
24
 
@@ -227,7 +227,6 @@ export function probeArgs(): string[] {
227
227
  }
228
228
  export const PYTHON_CANDIDATES = ["python3", "python"] as const;
229
229
 
230
- export type BackendKind = "uv" | "python" | "venv" | "none";
231
230
  export type Backend =
232
231
  | { kind: "uv"; pdf: true; xlsx: true; docx: true; email: true }
233
232
  | { kind: "python"; exe: string; pdf: boolean; xlsx: boolean; docx: boolean; email: boolean }
@@ -1,16 +1,23 @@
1
1
  import type { InputType, OcrMode } from "./doc-to-md-options.ts";
2
2
  import type { DocToMdDetails } from "./doc-to-md-core.ts";
3
3
 
4
- export type Tier = "primary" | "fallback" | "unpdf" | "excel" | "docx" | "html" | "image" | "email";
5
- export type Engine = "pymupdf4llm" | "pymupdf-text" | "unpdf" | "openpyxl" | "xlrd" | "mammoth" | "python-docx" | "markdownify" | "turndown" | "copy" | "extract-msg" | "email";
6
- export type BackendKind = "uv" | "python" | "venv" | "none";
4
+ export const TIERS = ["primary", "fallback", "unpdf", "excel", "docx", "html", "image", "email"] as const;
5
+ export type Tier = (typeof TIERS)[number];
6
+ export const ENGINES = ["pymupdf4llm", "pymupdf-text", "unpdf", "openpyxl", "xlrd", "mammoth", "python-docx", "markdownify", "turndown", "copy", "extract-msg", "email"] as const;
7
+ export type Engine = (typeof ENGINES)[number];
8
+ export const BACKEND_KINDS = ["uv", "python", "venv", "none"] as const;
9
+ export type BackendKind = (typeof BACKEND_KINDS)[number];
10
+ export const SHEET_KINDS = ["worksheet", "chartsheet"] as const;
11
+ export type SheetKind = (typeof SHEET_KINDS)[number];
12
+ export const OCR_STATUSES = ["off", "unavailable", "skipped", "ran"] as const;
13
+ export type OcrStatus = (typeof OCR_STATUSES)[number];
7
14
 
8
15
  export interface OutlineEntry { line: number; level: number; title: string; page: number | null; }
9
16
  export interface TocEntry { level: number; title: string; page: number | null; }
10
17
  export interface SheetInfo {
11
18
  index: number;
12
19
  name: string;
13
- kind: "worksheet" | "chartsheet";
20
+ kind: SheetKind;
14
21
  hidden: boolean;
15
22
  rows: number | null; cols: number | null;
16
23
  hiddenRows: number; hiddenCols: number;
@@ -22,7 +29,7 @@ export interface SheetInfo {
22
29
  export type PageStat = { page: number; chars: number; images: number; imageCoverage: number } | { page: number; error: string };
23
30
 
24
31
  export interface OcrInfo {
25
- status: "off" | "unavailable" | "skipped" | "ran";
32
+ status: OcrStatus;
26
33
  lang: string;
27
34
  textless: number[];
28
35
  pages: number[];
@@ -4,9 +4,12 @@
4
4
  */
5
5
  import { extname } from "node:path";
6
6
 
7
- export type InputType = "pdf" | "docx" | "doc" | "pptx" | "xlsx" | "xlsm" | "xls" | "html" | "image" | "email";
8
- export type ImageFormat = "png" | "jpg";
9
- export type OcrMode = "textless" | "all";
7
+ export const INPUT_TYPES = ["pdf", "docx", "doc", "pptx", "xlsx", "xlsm", "xls", "html", "image", "email"] as const;
8
+ export type InputType = (typeof INPUT_TYPES)[number];
9
+ export const IMAGE_FORMATS = ["png", "jpg"] as const;
10
+ export type ImageFormat = (typeof IMAGE_FORMATS)[number];
11
+ export const OCR_MODES = ["textless", "all"] as const;
12
+ export type OcrMode = (typeof OCR_MODES)[number];
10
13
 
11
14
  export interface Tunables {
12
15
  primaryTimeoutMs: number;
@@ -78,7 +81,7 @@ export const DOC_TO_MD_OPTIONS: readonly OptionDescriptor[] = [
78
81
  { key: "overwrite", flag: "--overwrite", type: "bool", default: false, settable: false, help: "Replace an existing completed <stem>.md bundle" },
79
82
  { key: "pageImages", flag: "--page-images", type: "bool", default: false, settable: false, help: "Also render every selected page to pages/<stem>-pNNN.<imageFormat> at imageDpi (PDF, PPTX, .doc, DOCX via LibreOffice); off by default" },
80
83
  { key: "words", toolHelp: "Write word positions to <stem>.words.json, or ocr/<stem>-pNNN.words.json for ocrMode all. Never triggers OCR. PDF and image inputs only.", flag: "--words", type: "bool", default: false, settable: false, help: "Write word positions: <stem>.words.json beside the Markdown lists every text-layer word of each selected page with its bbox (PDF points, top-left origin, display orientation; image inputs in source pixels) and the words inline OCR recognized, tagged source \"text\" or \"ocr\"; under --ocr-mode all the OCR words go to ocr/<stem>-pNNN.words.json beside each sidecar. Never triggers OCR. PDF and image inputs only." },
81
- { key: "ocrMode", toolHelp: "textless (default): OCR empty text layers inline. all: OCR selected pages to ocr/ sidecars without changing Markdown; requires ocr and explicit pages (PDF, PPTX, DOC).", flag: "--ocr-mode", type: "enum", default: "textless", settable: false, enumValues: ["textless", "all"], help: "OCR policy: textless (default) OCRs only pages with an empty text layer, inline; all OCRs every selected page and writes the recognized text to ocr/<stem>-pNNN.md sidecars, leaving the Markdown untouched. all requires --ocr and an explicit --pages selection (PDF, PPTX, DOC)." },
84
+ { key: "ocrMode", toolHelp: "textless (default): OCR empty text layers inline. all: OCR selected pages to ocr/ sidecars without changing Markdown; requires ocr and explicit pages (PDF, PPTX, DOC).", flag: "--ocr-mode", type: "enum", default: "textless", settable: false, enumValues: OCR_MODES, help: "OCR policy: textless (default) OCRs only pages with an empty text layer, inline; all OCRs every selected page and writes the recognized text to ocr/<stem>-pNNN.md sidecars, leaving the Markdown untouched. all requires --ocr and an explicit --pages selection (PDF, PPTX, DOC)." },
82
85
  { key: "primaryTimeoutMs", flag: "--primary-timeout", type: "int", default: 60000, settable: true, env: "PI_DOC_TO_MD_CONVERT_TIMEOUT_MS", help: "pymupdf4llm tier and DOCX child (docx mode); also the unpdf tier" },
83
86
  { key: "fallbackTimeoutMs", flag: "--fallback-timeout", type: "int", default: 30000, settable: true, help: "PyMuPDF get_text tier (including DOCX LibreOffice fallback); also PDF and DOCX info and Excel rendered views" },
84
87
  { key: "sofficeTimeoutMs", flag: "--soffice-timeout", type: "int", default: 120000, settable: true, env: "PI_DOC_TO_MD_SOFFICE_TIMEOUT_MS", help: "DOCX/PPTX -> PDF via LibreOffice; also Excel rendered views" },
@@ -86,7 +89,7 @@ export const DOC_TO_MD_OPTIONS: readonly OptionDescriptor[] = [
86
89
  { key: "warmTimeoutMs", flag: "--warm-timeout", type: "int", default: 120000, settable: true, env: "PI_DOC_TO_MD_WARM_TIMEOUT_MS", help: "Absolute backend discovery/bootstrap deadline (first call per process)" },
87
90
  { key: "pymupdfVersion", flag: "--pymupdf-version", type: "version", default: "1.27.2.3", settable: true, env: "PI_DOC_TO_MD_PYMUPDF_VERSION", help: "pymupdf4llm pin (>= 1.27.0)" },
88
91
  { key: "imageDpi", flag: "--image-dpi", type: "int", default: 150, settable: true, help: "Render DPI for page images and Excel rendered views" },
89
- { key: "imageFormat", flag: "--image-format", type: "enum", default: "png", settable: true, enumValues: ["png", "jpg"], help: "Rendered image format (embedded images keep their native extension)" },
92
+ { key: "imageFormat", flag: "--image-format", type: "enum", default: "png", settable: true, enumValues: IMAGE_FORMATS, help: "Rendered image format (embedded images keep their native extension)" },
90
93
  { key: "maxOutputBytes", flag: "--max-output-bytes", type: "int", default: 20000000, settable: true, help: "Child stdout cap in bytes" },
91
94
  { key: "outlineMaxEntries", flag: "--outline-max-entries", type: "int", default: 40, settable: true, help: "Heading outline / TOC / sheet inventory cap in the handle" },
92
95
  { key: "ocr", flag: "--ocr", type: "bool", default: false, settable: true, help: "Run OCR on pages without a text layer and on image inputs when Tesseract language data is installed; off by default (--no-ocr turns a settings-level true off)" },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-quiver",
3
- "version": "6.16.0",
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.",
3
+ "version": "6.16.2",
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, Anthropic fast mode, and a provider-stall watchdog.",
5
5
  "author": "Jacek Juraszek",
6
6
  "license": "MIT",
7
7
  "type": "module",