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-context-map

v0.7.6

Published

Professional context profiler for Pi that visualizes the session context window, token distribution, and integrates with Nexus packages for actionable insights.

Readme

pi-context-map

A visual context window mapping extension for Pi that transforms your abstract token window into a concrete, actionable dashboard.

Pi Package License: MIT npm version

Features

  • Visual Context Budget: Real-time breakdown of tokens used by System, Tools, History, Files, and Summaries.
  • Accurate Token Count: Uses Pi's actual token count from ctx.getContextUsage(), not heuristic estimation — matches the terminal display.
  • Working Set Analysis: Categorizes files as Active, Stale, or Legacy based on position in the conversation.
  • Token Weighting: Identifies "token hogs" by calculating the approximate size of each file in the window.
  • Operation Tracking: Marks files with their last operation (Read, Write, Edit).
  • Compaction Detection: Tracks compaction summaries and branch summaries as a separate slice.
  • Auto-Open Browser: Report automatically opens in your default browser on first invocation.
  • Dark Mode: Toggle between light and dark themes. Preference persists across sessions via localStorage.
  • Live Server: SSE-powered localhost server with auto-refresh after each assistant message.

Installation

pi install npm:pi-context-map

Quick Start

Run the mapping command to generate your session dashboard:

/context-map

The extension will analyze the session and create an interactive HTML report at: ~/.pi/context-map/report.html

Context Statuses

Files are categorized by their position in the conversation (more reliable than turn-based calculation):

| Status | Position in Messages | Action | |--------|---------------------|--------| | Active | Last 30% of messages | Keep in context | | Stale | Middle 40% of messages | Monitor for removal | | Legacy | First 30% of messages | Prime candidate for compaction |

How It Works

  1. Scanning: The analyzer iterates through session messages, detecting toolCall blocks, toolResult messages, compactionSummary entries, and image attachments.
  2. Weighting: It calculates token counts for each message type using a code-aware heuristic (multipliers for code blocks, strings, etc.).
  3. Accuracy: When available, Pi's actual token count from ctx.getContextUsage() overrides the heuristic for the usage percentage.
  4. Categorization: Files are classified by their position in the message array (last 30% = active, middle 40% = stale, first 30% = legacy).
  5. Visualization: Generates a self-contained HTML dashboard with stacked composition bar, file cards with search/filter, dark mode toggle, and interactive insights.

Live Localhost Server

When the extension loads, it automatically starts a local HTTP server on 127.0.0.1 (a random free port). The server:

  • Serves the current report at http://127.0.0.1:<port>/.
  • Pushes live updates via Server-Sent Events at /events?token=<sessionToken>.
  • Authenticates the SSE connection with a per-session token (injected into the HTML as a <meta> tag).
  • Auto-refreshes after each assistant message, so the browser view stays in sync.

Commands:

  • /context-map — Generate a fresh report and broadcast it to the browser.
  • /context-map stop — Stop the live server.

Endpoints:

  • GET / or /report.html — The current report HTML.
  • GET /events?token=... — Server-Sent Events stream of updates.
  • GET /health — Returns { "status": "ok", "port": <number> }.
  • POST /stop — Gracefully stops the server.

Design

The report uses the Linear design system (canvas #010102, accent #5e6ad2) with shadcn/ui card patterns. See docs/design.md for the full specification. The output is a single self-contained HTML file with no external dependencies.

Compatibility

  • ✅ Works with any Pi session regardless of model.
  • ✅ Compatible with pi-ultra-compact (use together for a "Scan $\to$ Compress" workflow).
  • ✅ Compatible with gentle-engram and gentle-pi.

Audit Report

This package has been audited by the pi-audit-master extension for code quality, security, and reliability. The full audit report is available in AUDIT-REPORT-UPDATED.md.

Audit Summary

| Category | Issues Found | Issues Fixed | |----------|--------------|--------------| | 🔴 Critical | 2 | 2 ✅ | | 🟠 High | 4 | 4 ✅ | | 🟡 Medium | 4 | 4 ✅ | | 🟢 Low | 2 | 2 ✅ | | Total | 12 | 12 ✅ |

Key Improvements

  • Security: Fixed dangerous signal listener removal, added XSS protection
  • Reliability: Added error logging, fixed heartbeat cleanup
  • Performance: Optimized file writes, no regression detected
  • Maintainability: Removed dead code, extracted constants, improved documentation

Performance Metrics

| Metric | Result | |--------|--------| | Token Counter | 0.0005ms/call | | Context Analyzer | 0.08ms/analysis | | Report Generator | 0.10ms/report | | Live Server | 0.14ms/update |

For detailed findings and recommendations, see the full audit report.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Pi - The AI coding agent