← Catalog

@jc4649/pi-context-collapse

Deterministic write-once collapse of bulky tool outputs, with reversible originals cache

Extension

Install

Install with PiG

pig install npm:@jc4649/pi-context-collapse

Install with Pi

pi install npm:@jc4649/pi-context-collapse
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.

{
  "extensions": [
    "./index.ts"
  ]
}

README

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

@jc4649/pi-context-collapse

Deterministic, reversible collapse of bulky tool outputs in a pi coding-agent session, to keep the context window lean without losing information.

What it does

On each LLM call (context hook), it walks the transcript newest→oldest and collapses old, non-error tool results that exceed a token threshold — replacing the bulky body with a compact summary plus an expand handle. A protected recent tail (default ~6000 tokens, PI_COLLAPSE_PROTECT_TOKENS) is always left untouched so the prompt prefix stays byte-stable and prompt-cache-friendly.

Collapsed originals are kept in a local SQLite cache (node:sqlite), so the model can call the registered expand tool to recover any collapsed result verbatim.

Compressors

  • log — strips ANSI, drops progress/step-counter noise, dedupes, caps head/tail.
  • json/paths — structural summarization of large JSON and path lists.
  • useless — elides empty or "no matches" search results.

Configuration

  • PI_COLLAPSE_DIR — artifact dir (default <cwd>/.pi/collapse).
  • PI_COLLAPSE_PROTECT_TOKENS — recent-tail tokens never collapsed (default 6000).

Install

pi install @jc4649/pi-context-collapse

MIT