@jc4649/pi-context-collapse

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

Packages

Package details

extension

Install @jc4649/pi-context-collapse from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:@jc4649/pi-context-collapse
Package
@jc4649/pi-context-collapse
Version
0.1.0
Published
Jun 26, 2026
Downloads
90/mo · 7/wk
Author
jimmyc4649
License
MIT
Types
extension
Size
23.3 KB
Dependencies
1 dependency · 0 peers
Pi manifest JSON
{
  "extensions": [
    "./index.ts"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

@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