⚠️ For vanilla
piusers. Piclaw already includes smart compaction natively. If this package is loaded inside Piclaw it disables itself by default to avoid duplicate compaction handlers.
This is a standalone, code-complete Pi extension package that ports Piclaw's selective smart-compaction behavior into a vanilla pi add-on. It does not import Piclaw runtime internals and does not move or replace Piclaw's built-in implementation.
session_before_compact and returns a custom compaction result.<read-files> and <modified-files> sections.From a local checkout:
pi install /workspace/piclaw-addons/addons/smart-compactionOr run temporarily:
pi -e /workspace/piclaw-addons/addons/smart-compactionThis package is meant for users running upstream/vanilla pi. In Piclaw, the equivalent extension is already built in. To avoid registering two compaction handlers, this add-on checks for Piclaw runtime environment variables and stays inert unless explicitly forced:
PI_SMART_COMPACTION_ALLOW_PICLAW=1 pi -e /path/to/smart-compactionUse that override only for local testing.
Optional environment variables:
| Variable | Purpose |
|---|---|
PI_SMART_COMPACTION_DEBUG=1 |
Log debug details to stderr/console. |
PI_SMART_COMPACTION_SYSTEM_PROMPT_OVERHEAD_TOKENS |
Override estimated non-message prompt/tool overhead. |
PI_SMART_COMPACTION_PROGRESSIVE=1 |
Force progressive chunk/merge compaction. |
PI_SMART_COMPACTION_PROGRESSIVE_PROMPT_CHARS |
Override the single-pass prompt character budget before progressive mode. |
Historical PICLAW_* equivalents are accepted for copied local configurations, but PI_SMART_COMPACTION_* is preferred for vanilla pi.
The extension uses the active session model and public Pi/Pi-AI APIs:
session_before_compactctx.modelRegistry.getApiKeyAndHeaders(model)completeSimpleMessage/file serialization is bundled locally so no Piclaw source imports are required at runtime.