pi-muse-compact
Standalone spark-compact for pi — fixes OpenAI compaction (tool_choice auto only) on FreeBSD/Linux
Package details
Install pi-muse-compact from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:pi-muse-compact- Package
pi-muse-compact- Version
1.0.0- Published
- Aug 26, 2026
- Downloads
- 142/mo · 142/wk
- Author
- muswawir
- License
- unknown
- Types
- extension
- Size
- 12 KB
- Dependencies
- 0 dependencies · 0 peers
Pi manifest JSON
{
"extensions": [
"./extensions"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
pi-muse-compact — WORKAROUND for failing pi compaction
This is a workaround, not a fix upstream. Pi's built-in compaction is broken on your setup (OpenAI-compatible proxy that only supports
tool_choice:"auto"). This package works around it so/compactand auto-compaction don't crash.
Root cause: pi hardcodes toolChoice:"none" in completeSummarization (chunk-E5KXRMZK.js: requestOptions={...,toolChoice:"none"}) → your proxy returns 400 only "auto" is supported for tool_choice. The workaround intercepts session_before_compact and re-does summarization with no tools so the request stays "auto".
Upstream fix would be pi/pi-ai defaulting to "auto" when no tools are needed, or making compaction configurable. Until then, use this.
Install
pi install ~/pi-muse-compact
# or test without installing:
pi -e ~/pi-muse-compact/extensions
Use
Auto: just use pi normally — /compact and auto-compaction (overflow) are intercepted and re-run with auto.
Manual standalone:
/spark-compact
/spark-compact focus on auth changes
# tool for Spark:
# spark_compact(instructions="focus on ...")
How the workaround works
session_before_compact→ serializesmessagesToSummarizeviaserializeConversation(convertToLlm(...)), callsctx.modelRegistry.complete(model, {messages}, {cacheRetention:"none", sessionId:uuidv7()})with notools→ staystool_choice:"auto".- Prefers a non-OpenAI model for summarization (
google/gemini-2.5-flash) when available; else uses current model. - Handles
text+thinkingcontent; if LLM still fails/empty (e.g.Insufficient Balance), falls back to a deterministic summary frompreparation.fileOps+ tail messages so compaction never falls back to pi's brokentool_choice:"none"path. - Returns
{compaction:{summary, firstKeptEntryId, tokensBefore, usage}}sopiskips its default compaction. - Also registers tool
spark_compact+ command/spark-compactas standalone entry points that callctx.compact().
Limitations
Workaround only — if the summary is LLM-generated you get a real summary; if the provider is down/billing fails you get a minimal deterministic fallback (still compacts, but lossier). Remove this package once upstream pi fixes the toolChoice:"none" default.
Layout
~/pi-muse-compact/
package.json # pi package manifest (extensions: ["./extensions"])
extensions/index.ts # the extension
README.md
Uninstall: pi remove ~/pi-muse-compact or pi remove pi-muse-compact