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-doc-injector

v0.3.1

Published

Auto-inject relevant project documentation into Pi's LLM context based on keyword matching

Readme

Pi Doc Injector

A Pi extension that automatically injects relevant project documentation into the LLM system prompt by monitoring streaming output for keyword matches.

Installation

Via npm (recommended)

pi install npm:pi-doc-injector

Via git

pi install git:github.com/lmn451/pi-doc-injector

Manual

Copy this repository into your project's .pi/extensions/doc-injector/ folder, or clone directly:

git clone https://github.com/yourname/pi-doc-injector.git .pi/extensions/doc-injector

Quick Start

  1. Create a docs/ folder in your project root.
  2. Add markdown files with YAML frontmatter:
---
title: "Testing Workflow"
keywords: [test, testing, jest, vitest]
---

# Testing Workflow

Your documentation here...

Keywords can also be specified in block format:

---
title: "Testing Workflow"
keywords:
  - test
  - testing
  - jest
  - vitest
---
  1. Start Pi. The extension scans docs/ on session start.
  2. When the user mentions a keyword, the matching doc is injected into the system prompt before the assistant responds — no one-turn delay.
  3. If the assistant mentions a NEW keyword mid-response, generation is automatically aborted and restarted with the doc injected immediately.

Configuration

Create .pi/doc-injector.json in your project root to customize behavior:

{
  "docsPath": "./docs",
  "matchThreshold": 1,
  "contextThreshold": 80,
  "recursive": true
}

| Option | Default | Description | | ------------------ | ---------- | -------------------------------------------------------- | | docsPath | "./docs" | Path to docs folder (relative to project root) | | matchThreshold | 1 | Minimum keyword matches required to inject a doc | | contextThreshold | 80 | Skip injection when context usage exceeds this % (0–100) | | recursive | true | Scan docs subdirectories recursively |

Keyword Matching

Matching is case-insensitive and respects word boundaries by default. Once a document is injected, it won't re-match until you run /doc-inject reset.

Injection is also skipped if the current context usage exceeds 80% of the token budget.

Commands

| Command | Description | | -------------------- | ---------------------------------------------------- | | /doc-inject on | Enable doc injection | | /doc-inject off | Disable doc injection | | /doc-inject toggle | Toggle doc injection on/off | | /doc-inject list | List all registered docs and their injection status | | /doc-inject reset | Reset all injected flags (docs become re-injectable) | | /doc-inject status | Show current injection status and config | | /doc-reload | Re-scan docs folder and rebuild registry |

Injection Lifecycle

The extension uses a per-session injection model:

  • On session_start, the registry scans docs/ and indexes all valid documents.
  • Within a session, once a document is injected, it won't be re-injected automatically.
  • Use /doc-inject reset to manually reset all flags and allow docs to be injected again.
  • Use /doc-inject list to see which docs have been injected (✅) and which are pending (⬜).

Injection Timing

  • User messages: matched via the input event, injected before the assistant responds — same turn, no delay.
  • Assistant streaming: if the assistant mentions a NEW keyword mid-response, generation is aborted and restarted with the doc injected immediately.

System Prompt Lifecycle

Pi reconstructs the system prompt from source files each turn (verified against pi v0.70.6).

When before_agent_start fires, the systemPrompt passed to the extension is a freshly rebuilt prompt from AGENTS.md, SYSTEM.md, skills, and tool snippets. It is not accumulated from previous turns.

This means:

  • Injections apply to the current turn only and do not persist in subsequent turns.
  • There is no risk of duplicate injection sections stacking up over time.
  • The injected flag alone is sufficient to prevent re-injection — no additional deduplication or marker-based stripping is needed.

For the full source-level verification, see the JSDoc block in index.ts.

Development

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

License

MIT