← Catalog

pi-live-compaction

Live streaming compaction for Pi — structured summaries with preset routing, Liquid templates, files-touched manifests, and a full TUI settings panel.

Extension

Install

Install with PiG

pig install npm:pi-live-compaction

Install with Pi

pi install npm:pi-live-compaction
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "image": "https://raw.githubusercontent.com/victor-software-house/pi-live-compaction/main/assets/thumbs/final/pi-live-compaction-og.png",
  "extensions": [
    "./dist/index.mjs"
  ],
  "description": "Live streaming compaction with preset routing, Liquid templates, 11 continuity sections, and a TUI settings panel."
}

README

Written by the package's publisher, shown as published in version 0.1.7 (README.md). PiG does not review it.

pi-live-compaction

pi-live-compaction

Live streaming compaction for Pi — structured summaries with preset routing, Liquid templates, files-touched manifests, task-state continuity, and a full TUI settings panel.

Highlights

  • 11 continuity sections instead of 5 — intent trail, dead ends, task state, file manifests, mandatory reading
  • Live streaming — watch the summary form as it compacts; partial recovery if the stream breaks
  • Preset routing — route compaction to any model with per-preset thinking levels and fallback chains
  • Liquid templates — fully customizable prompts with layout inheritance, partials, frontmatter knobs
  • Focus directive — /compact <focus> preserves the exact operator goal through compaction
  • TUI settings panel — scope switching, preset editor, prompt editor, runtime status

Install

pi install npm:pi-live-compaction

Or try without installing:

pi -e npm:pi-live-compaction

How it works

Compaction pipeline

The extension hooks into Pi's session:beforeCompact and session:beforeTree events:

  1. Resolves the summarizer — picks a model from presets, inherits the session model, or falls back to a configured default
  2. Renders the prompt — Liquid template engine composes the request from partials with all context blocks
  3. Streams the summary — calls the summarizer with live streaming, showing progress in the chat flow
  4. Recovers on failure — if the stream breaks mid-summary, recovers whatever was streamed
  5. Logs diagnostics — writes attempt entries with SHA-256 hashes, token counts, and transport info

What the summary preserves

11 continuity sections

Every compaction summary captures what happened, where things stand, and what to do next — so the next agent (or the same session after compaction) opens the right files and doesn't repeat failed approaches.

Preset routing

Preset routing

Route compaction to different models with different thinking levels. Use /compact --preset deep for thorough compaction or let the default kick in automatically. If the selected preset's model auth fails, the fallback chain tries cheaper models before falling back to the session model.

{
  "defaultPreset": "default",
  "fallbackPreset": "cheap",
  "presets": {
    "fast": { "model": "openai-codex/gpt-5.4-mini", "thinkingLevel": "medium" },
    "cheap": { "model": "anthropic/claude-haiku-4-5", "thinkingLevel": "low" },
    "default": { "model": "anthropic/claude-sonnet-4-6", "thinkingLevel": "medium" },
    "deep": { "model": "anthropic/claude-sonnet-4-6", "thinkingLevel": "high" },
    "thorough": { "model": "anthropic/claude-opus-4-8", "thinkingLevel": "xhigh" }
  }
}

Template engine

Prompts are LiquidJS templates powered by pi-template-kit:

  • Layout inheritance — {% layout '_base' %} + {% block content %}
  • Partials — {% include '_blocks' %} from the sibling templates/ directory
  • Frontmatter — preset:, thinking_level:, model:, description: override runtime behavior per template
  • Custom filters — present, quote, tokens, text, last_user_text
  • XML tags — {% xml "tag-name" %}...{% endxml %} emits <tag-name>...</tag-name> or nothing when empty

Context blocks

VariableContent
previous_summaryPrior compaction summary (if any)
discardedSerialized discarded conversation being replaced
kept_tailSerialized kept-tail messages that remain raw after compaction
task_stateLive task-tracking snapshot at compaction time
files_touchedFiles-touched manifest with operation badges
focusOperator's /compact <focus> directive
last_user_messageMost recent user message text

Configuration

All configuration lives in config.json files. Prompts are Liquid templates (.md). Both support a two-level scope cascade:

ScopePath
Project.pi/extensions/live-compaction/
Global~/.pi/agent/extensions/live-compaction/

Resolution order: project → global → built-in defaults. Project overrides win. The TUI panel (/live-compaction) lets you switch between scopes when editing.

Each scope directory can contain:

config.json                  # preset routing, feature toggles
compaction-prompt.md         # main compaction template (Liquid)
branch-summary-prompt.md     # branch summary template (Liquid)

Custom templates

Drop a compaction-prompt.md or branch-summary-prompt.md in the project or global scope directory. Templates are LiquidJS with frontmatter knobs:

---
preset: deep
thinking_level: high
---
{% include '_blocks' %}
{%- if last_user_message | present %}
<latest-user-ask>
{{ last_user_message | truncate: 800 }}
</latest-user-ask>
{% endif %}
{% include '_contract' %}

Settings panel

Run /live-compaction to open the interactive settings panel:

  • Switch between global and project scope
  • Edit default preset and manage preset collection
  • Edit compaction and branch-summary prompts
  • Toggle session-model inheritance
  • Toggle files-touched manifests
  • Verify runtime status

Examples

The examples/ directory contains 9 declarative golden-file examples covering the full feature set:

#ExampleWhat it demonstrates
01minimalSmallest possible composition
02full-blocksEvery block populated with {% xml %} auto-omit
03helpers-tourAll shipped filters/tags + Liquid built-ins
04tool-callsTool-call/tool-result loop with sibling partial
05pipeline-shapingDeclarative data shaping — where/slice/size/truncate
06layout-inheritance{% layout %} + {% block %} inheritance
07files-touched-manyMulti-file manifest with every operation badge combo
08no-kept-tailEmpty kept-tail edge case
09task-continuityTask-state snapshot and continuity guidance

Run pnpm test to verify all examples render to their golden expected output. See examples/AGENTS.md for full details.

Built-in vs pi-live-compaction — full comparison
(blank)Pi Built-inpi-live-compaction
Summary modelSession model onlyPreset routing — any model, per-preset thinking level
PromptHardcoded 5-section formatLiquid templates — fully customizable with layout inheritance and partials
StreamingNo streamingLive streaming with partial recovery on stream failure
Output sections5 (Goal, Constraints, Progress, Decisions, Next Steps)11 (Brief, User intent trail, Constraints, Errors/dead ends, Key decisions, Status, Task continuity, Open issues, Next steps, Mandatory reading)
User intentNot preservedFull chronological trail with quote fidelity
Task stateNot included<task-state> snapshot injected and reconciled
Files touchedBasic read/modified listsOperation-badge manifest (R/W/E/M/D) with display paths
Focus directiveNot supported/compact <focus> preserves exact operator goal
Branch summary5 fixed sections10 sections — verbatim user messages, reusable vs branch-local split, dead ends
SettingsNoneFull TUI panel with scope switching, preset editor, prompt editor
ConfigNoneGlobal/project scope cascade with JSON config + prompt overrides
  • pi-template-kit — shared LiquidJS template engine, filters, and {% xml %} tag used by this package
  • pi-prompt-composer — build multi-option slash commands from plain prompts with variable expansion and interactive selectors

Development

pnpm install
pnpm run typecheck     # tsc --noEmit
pnpm test              # vitest (50 tests)
pnpm run preview       # render a compaction prompt to stdout
pnpm run examples:update  # regenerate golden expected files

Roadmap

  • Per-preset fallback chains — each preset declares its own fallback model, enabling retry chains before falling back to the session model
  • Per-preset prompt routing — map preset tiers to prompt template variants so stronger models get richer contracts
  • Context-aware model selection — auto-select presets based on session length, available models, cost budget, and provider health
  • Reusable TUI components — adopt shared SettingsPanel / editor components for the settings panel

Inspiration

The architecture was informed by pi-grounded-compaction — an early prototype that explored preset routing, template-driven prompts, and streaming compaction — and Pi's official custom-compaction.ts example for hooking into session:beforeCompact.

The compaction prompt contract, streaming engine, template system integration, TUI settings panel, files-touched manifest, task-state continuity, and branch-summary prompt are original work.

License

MIT