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

@pinet/model-aware-compaction

v0.2.4

Published

Pi extension for proactive model-aware context compaction thresholds

Readme

@pinet/model-aware-compaction

A Pi extension that triggers proactive compaction at different active-context token limits for different models. It adapts Pi's shipped trigger-compact.ts example to multi-model and subagent workloads.

Install

pi install npm:@pinet/model-aware-compaction

For local development from a clone of this repository, load the source directly:

pi --extension /path/to/extensions/model-aware-compaction/index.ts

Configure

The extension is disabled by default. Add this to project .pi/settings.json or global ~/.pi/agent/settings.json:

{
  "model-aware-compaction": {
    "enabled": true,
    "rules": [
      { "model": "openai/gpt-5-mini", "activeContextTokens": 100000 },
      { "model": "anthropic/claude-sonnet-4-6", "activeContextTokens": 100000 },
      { "model": "example-proxy/*", "activeContextTokens": 136000 }
    ],
    "customInstructions": "Preserve decisions, files changed, validation results, and next steps.",
    "debug": false
  }
}

Rules are evaluated in order. * wildcards are supported, such as example-proxy/*.

Behavior

After each agent_end, the extension reads ctx.getContextUsage() and the active ctx.model. Waiting for agent_end is important: tool-using runs can emit several turn_end events, and Pi's ctx.compact() aborts an active agent operation before compacting. Triggering only after the complete model/tool loop has settled prevents compaction from discarding pending tool work. When usage first exceeds the matching rule's activeContextTokens, the extension calls ctx.compact(). It prevents duplicate calls while compaction is in flight and re-arms after usage drops below the threshold, the model changes, a session starts, or compaction fails.

Run /model-aware-compaction-status to inspect the active model, usage, matched threshold, state, and loaded rules.

Limitation

Pi's extension API makes ctx.compact() fire-and-forget. This package is therefore proactive best effort, not an atomic compact-before-next-provider-request barrier. Debug logs make trigger/completion/failure visible so that race behavior can be measured. Upstream model-specific settings or an awaitable/deferred compaction seam would provide a stronger guarantee.

Development

pnpm --filter @pinet/model-aware-compaction lint
pnpm --filter @pinet/model-aware-compaction typecheck
pnpm --filter @pinet/model-aware-compaction test
pnpm --filter @pinet/model-aware-compaction build