No description
| src | fix: support Pi 0.80 compaction API | |
| config.example.json | compaction-aware: fallback to session model for compaction summaries | |
| package-lock.json | fix: support Pi 0.80 compaction API | |
| package.json | fix: support Pi 0.80 compaction API | |
| README.md | compaction-aware: fallback to session model for compaction summaries | |
| tsconfig.json | compaction-aware: fallback to session model for compaction summaries | |
compaction-aware
Pi Coding Agent extension for small compaction tweaks while reusing Pi's own compaction implementation as much as possible.
It changes only:
- summary model: uses a configured model for compaction instead of the active session model;
- trigger point: calls Pi's native
ctx.compact()when context usage crossestriggerPercentof the active model context window; - recent retention: converts
keepRecentPercentinto Pi's nativekeepRecentTokensand then calls Pi's ownprepareCompaction()/compact()from@earendil-works/pi-agent-core.
No custom serializer, custom split algorithm, or token inflation hack.
Install local
# from this repo
cd /home/su3h7am/Projects/pi-compaction-plus
mkdir -p ~/.pi/agent/extensions
ln -sfn /home/su3h7am/Projects/pi-compaction-plus ~/.pi/agent/extensions/compaction-aware
Or run one session with:
pi -e /home/su3h7am/Projects/pi-compaction-plus
Config
The extension reads only this file:
~/.pi/agent/compaction-aware.json
Create it:
mkdir -p ~/.pi/agent
cp /home/su3h7am/Projects/pi-compaction-plus/config.example.json ~/.pi/agent/compaction-aware.json
Example:
{
"enabled": true,
"summaryModel": "google/gemini-2.5-flash",
"triggerPercent": 75,
"keepRecentPercent": 15,
"notify": true,
"cooldownMs": 15000
}
Fields:
summaryModel:provider/model-idused only during compaction summary generation.triggerPercent: after a turn, ifctx.getContextUsage().percentcrosses this value, the extension callsctx.compact().keepRecentPercent: converted tokeepRecentTokens = activeContextWindow * keepRecentPercent / 100before calling Pi's nativeprepareCompaction().notify: show Pi UI notifications.cooldownMs: avoid repeated trigger calls.
Design
Hooks used:
turn_end: checksctx.getContextUsage()and triggersctx.compact()when crossingtriggerPercent.session_before_compact: resolvessummaryModel, adjusts onlykeepRecentTokens, then delegates to Pi SDK:
const preparationResult = prepareCompaction(event.branchEntries, settings);
const compactionResult = await compact(preparation, summaryModel, apiKey, headers, event.customInstructions, event.signal);
Fallback behavior: if the configured model/auth is unavailable, the hook returns undefined, allowing Pi's default compaction path to run.