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-extension-observational-memory

v0.1.3

Published

Observational-memory compaction strategy for pi with observer/reflector token thresholds

Downloads

418

Readme

Observational Memory Extension

Extension-only custom compaction for pi, inspired by observational-memory systems.

See DESIGN.md for architecture notes and next milestones.

This implementation follows pi's extension style:

  • directory extension with index.ts
  • top-level JSDoc usage/behavior comments
  • explicit command registration
  • fallback-safe hooks (default compaction remains available)

What it does now

On session_before_compact:

  1. Uses pi's prepared compaction input (messagesToSummarize, turnPrefixMessages, previousSummary)
  2. Uses the current active model (same model as your session)
  3. Generates a structured summary with sections:
    • ## Observations
    • ## Open Threads
    • ## Next Action Bias
  4. Runs reflector GC when observation block token estimate crosses threshold (default: 40k) or when forced via command
  5. Preserves pi's kept-tail behavior by reusing preparation.firstKeptEntryId
  6. Appends cumulative <read-files> and <modified-files> tags (merged with prior checkpoint tags)
  7. Stores extension metadata in compaction.details

On session_before_tree:

  • Replaces default branch summary with the same observational format.

On agent_end (buffered mode):

  • Estimates raw-tail tokens (messages since latest compaction) and triggers observer compaction at threshold (default: 30k + 8k retain buffer).

Observer modes:

  • buffered (default): auto observer checks in background after agent turns.
  • blocking: background observer trigger is disabled; regular/manual compaction still works.

If generation fails or API key/model is unavailable, it returns nothing so pi falls back to default compaction/tree summarization.

Commands

  • /obs-memory-status — show latest compaction + branch summary metadata and OM token block estimates
  • /obs-auto-compact [on|off] [mode] [observerTokens] [reflectorTokens] [retainTokens] — show/set thresholds and mode
    • keyed form: /obs-auto-compact mode=buffered observer=30k reflector=40k retain=8k
  • /obs-mode [buffered|blocking] — show/set observer auto-compaction mode
  • /obs-view [obs] [raw] [maxLines] — inspect latest observation summary quickly in-terminal
  • /obs-reflect [extra focus] — force aggressive reflection on next compaction and trigger compaction now

Optional startup flags:

  • --obs-auto-compact=true|false
  • --obs-mode=buffered|blocking
  • --obs-observer-threshold=30000 (or 30k)
  • --obs-reflector-threshold=40000 (or 40k)
  • --obs-retain-raw-tail=8000 (or 8k, 0 to disable retain buffer)

Install

From npm (recommended):

pi install npm:pi-extension-observational-memory

Or add to settings directly:

{
  "packages": ["npm:pi-extension-observational-memory"]
}

For local development, you can still load from disk:

  • global: ~/.pi/agent/extensions/observational-memory/index.ts
  • project: .pi/extensions/observational-memory/index.ts

Or run one-off:

pi -e ./index.ts

Linting / formatting

This folder includes a local package.json + biome.json so it can be checked independently.

cd path/to/pi-extension-observational-memory
npm install
npm run lint
npm run format

Current scope vs target design

Implemented now:

  • Observer-style compaction summary override
  • Prior-summary carry forward
  • Reflector/GC pass (threshold + forced mode)
  • Branch-aware observational summaries via session_before_tree
  • Extension-managed two-threshold OM flow: observer trigger (default 30k) + reflector trigger (default 40k)
  • Buffered/background observer mode by default, with optional blocking mode
  • Partial activation support via raw-tail retain buffer (default 8k)
  • Commands: /obs-memory-status, /obs-auto-compact, /obs-mode, /obs-view, /obs-reflect

Planned next:

  • Additional maintenance commands (/obs-rebuild, /obs-dump)

Notes

  • This extension intentionally does not change pi core internals.
  • It composes with pi's existing session tree and compaction lifecycle.
  • Model choice is currently the active session model; can be changed later if desired.