@bismawy/pi-auto-compat
v1.4.0
Published
Auto-fix missing compat flags in Pi's models.json — mirrors pi-cache-optimizer detection so compat warnings never appear. Registry-driven, credential-safe, refreshes in-process.
Maintainers
Readme
pi-auto-compat
A Pi coding agent extension that automatically fixes missing compat flags in models.json — so warnings like 💡 pi-cache-optimizer: ... merged compat lacks ... and the ⚠️ compat footer marker never appear.
Detection mirrors pi-cache-optimizer exactly (same priority chain), and the source of truth is the merged model list from ctx.modelRegistry — not a static file scan. Providers without a models.json entry are patched too (a minimal compat-only entry is created; credentials are never touched).
What it fixes
- Universal long cache retention — every model/provider gets
supportsLongCacheRetention: truewhen not explicitly set (pi already defaults it totrue; declaring it surfaces the "Caching" badge and silences the cache-optimizer warning). Explicitfalseis respected; Pi's built-in llama.cpp is excluded. New models added via/better-customare covered automatically — no per-model injection needed. - Adaptive generation (
anthropic-messages+ Opus/Sonnet ≥ 4.6, Fable ≥ 5, or Kimi Coding K3) →forceAdaptiveThinking: true(+allowEmptySignaturefor K3 empty-signature models) - DeepSeek-like (
openai-completions/openai-responses) →supportsLongCacheRetention,requiresReasoningContentOnAssistantMessages,thinkingFormat: "deepseek"(+sendSessionAffinityHeaderson completions) - Claude-like on OpenAI-compatible proxies
→
cacheControlFormat: "anthropic" - Non-official OpenAI-compatible proxies (
openai-completions) →sendSessionAffinityHeaders: true— only when undefined; explicitfalseis a valid anti-403 opt-out and is never overwritten - Reasoning models without
thinkingLevelMap(static rule) → default{ low, medium, high, xhigh }map
How it works
- Fix placement mirrors pi-cache-optimizer
/fix: channel keys (affinity/retention) go provider-level; model-behavior keys go model-level (models[].compatormodelOverrides) unless every sibling model is compatible. - Extension-owned providers are special-cased: when an extension registers a provider with its own
modelslist (orrefreshModels), Pi applies that list after models.json, so provider-levelcompatandmodels[].compatnever reach the merged model — onlymodelOverridesdo. All fixes for such providers are therefore written tomodelOverrides(detected viactx.modelRegistry.getRegisteredProviderConfig). - After writing, the registry is refreshed in-process (
modelRegistry.refresh({ allowNetwork: false })) — no/reloadneeded. - Triggers:
session_start,model_select, themodels.jsonfile-watcher, and the manual/auto-compatcommand. - A timestamped backup is written before each save (max 3 kept).
Install
pi install npm:@bismawy/pi-auto-compatThen run /reload in Pi (or restart it). Optionally run /auto-compat once to fix everything immediately.
Manual install (from source): copy index.ts into %USERPROFILE%\.pi\agent\extensions\.
Safety
- Never copies, moves, or writes credentials (
apiKey, OAuth) — new provider entries are compat-only. - Never deletes existing values; only fills/repairs the specific compat keys listed above.
- Skips official OpenAI endpoints and Pi's built-in llama.cpp provider.
