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

pi-early-compact

v0.1.0

Published

Pi extension that auto-compacts large-context models (1M-class) at a 400k effective limit before quality degrades

Readme

pi-early-compact

A Pi extension that compacts large-context models before they get dumb.

Many models advertise 1M-token context windows, but output quality often degrades well before that — in practice around 400k tokens. Pi's built-in auto-compaction only kicks in when the context nearly fills the window (contextWindow - 16k), so a 1M-window model keeps running past the point where it stops being useful.

This extension watches context usage after every agent run and triggers compaction early:

  • Large-window models (contextWindow > 400k, e.g. 1M-class): compact at 350k tokens — the 400k effective limit minus a 50k headroom, so the next run cannot push the context past the limit where quality drops.
  • Small-window models (contextWindow ≤ 400k, e.g. 200k-class): left untouched; Pi's built-in threshold compaction already handles them closer to the window.

Compaction fires on agent_settled — only when the agent has fully finished and no retry, queued continuation, or built-in compaction is pending — so it never interrupts work in progress. It shows a single info notification when it triggers, and Pi's built-in overflow recovery remains as a safety net.

While a large-window model is active, the extension also adds a footer status slot like early 352k/400k (88%) — context usage measured against the effective limit instead of the advertised window, so you can see how close an early compaction is. Small-window models get no slot; Pi's own footer percentage already covers them.

Install

pi install npm:pi-early-compact

Then restart Pi (or run /reload). No configuration needed.

How it works

| Setting | Value | | --- | --- | | Effective context limit | 400,000 tokens | | Headroom for the next run | 50,000 tokens | | Compaction trigger | ≥ 350,000 tokens, window > 400k | | Trigger point | after each settled agent run |

  1. After every settled run, the extension reads ctx.getContextUsage().
  2. If the estimated context is at or above 350k on a model whose window exceeds 400k, it calls ctx.compact() — Pi's own native compaction pipeline and summary prompt, identical to a manual /compact — and notifies the user.
  3. Small-window models and fresh post-compaction contexts (unknown token count) are ignored.

Development

npm install
npm run check   # tsc --noEmit
npm test        # node --test

Requires Node.js ≥ 22.18 (Pi runs extensions with TypeScript support built in — there is no build step).

License

MIT