npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@capyup/pi-auto-compact

v0.2.4

Published

Pre-turn auto-compaction for pi

Readme

pi-auto-compact

Pre-turn auto-compaction extension for pi. Proactively manages context window usage to prevent overflow errors.

The Problem

Pi's default auto-compaction only checks after agent_end. This means context can overflow during long multi-tool turns before compaction triggers.

Strategy

This extension checks tokens at three points:

  1. Pre-turn: Before sending any request to the LLM (turn_start)
  2. Mid-turn: After tool execution, before follow-up LLM calls (turn_end)
  3. Emergency: Synchronous truncation in the context event as a last resort

It also handles the session resume case: when an existing session is reopened above the threshold, compaction kicks off as soon as the session starts.

Continuing After Auto-Compaction

ctx.compact() aborts the running agent internally, so without a nudge the session would sit idle once the summary is written. After every auto-triggered compaction this extension sends a short English follow-up user message to make pi resume the in-flight task. The exact wording depends on which check fired (pre-turn, mid-turn, emergency, or session-resume).

The follow-up is suppressed in two cases:

  • The user ran /compact manually — the callback path used here only fires for compactions this extension started, so manual compaction is never touched.
  • The agent is no longer idle when the summary finishes, e.g. the user already typed something or another extension started a turn while summarising. Their input acts as the kickoff and we stay quiet.

Compaction Strategies

| Strategy | Description | |----------|-------------| | keep-recent | Keep only the most recent messages (default) | | keep-bookends | Keep oldest + newest messages, compact the middle | | summarize-all | Remove everything except the last user message |

Configuration

Use /auto-compact to open the interactive settings menu:

/auto-compact              # Open settings menu
/auto-compact status       # Show current status
/auto-compact reset        # Reset to defaults

Settings

| Setting | Default | Options | |---------|---------|---------| | Auto-compact threshold | 90% | 80%, 85%, 90%, 95% | | Keep recent budget | 15% | 5%, 10%, 15%, 20% | | Strategy | keep-recent | keep-recent, keep-bookends, summarize-all | | Debug logging | off | on/off |

Example

For a 200K context window model:

  • Compact at 180K tokens (90%)
  • Keep 30K recent tokens (15%)

Install

As a pi package:

pi install npm:@capyup/pi-auto-compact

Or via git:

pi install git:github.com/capyup/pi-auto-compact

Or run directly:

pi -e ./extensions/auto-compact.ts

How It Differs from Pi's Default

| Aspect | Pi Default | This Extension | |--------|-----------|----------------| | Check timing | After agent_end only | Before requests + after tools | | Overflow protection | None | Emergency truncation | | Mid-turn handling | None | Checks after each tool batch | | Auto-continue | No | Yes — sends an English follow-up nudge after auto-compaction |

License

MIT