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-shepherd

v0.1.2

Published

Line count guard and behavior rules extension for pi-coding-agent

Readme

English | 程序中文文档

📖 pi-atelier 实战指南 — 从零教会你使用 pi-atelier 扩展生态,让 AI 编程助手从「会写代码」进化到「会管理项目」

pi-shepherd

源码仓库 | npm

Line count guard and behavior rules extension for pi-coding-agent — rule-driven hooks for tool calls, agent end, and session events.

What It Does

AI agents can go off the rails — generate too much code, forget to commit, ignore coding standards, or produce outputs that are too large. pi-shepherd acts as a guardrail system that monitors and enforces behavioral rules:

  • Tool call interception — Inspect and modify tool calls before execution (e.g., enforce line limits)
  • Tool result inspection — Check tool results after execution (e.g., flag overly large outputs)
  • Agent end hooks — Enforce commit/message rules when the agent finishes
  • Session lifecycle — Reset state between sessions

Installation

pi install git:github.com/catlain/pi-shepherd

How It Works

pi-shepherd uses a rules engine that evaluates configurable patterns against tool calls and results:

Tool Call → Rules Engine → Pass/Block/Modify
Tool Result → Rules Engine → Pass/Flag/Truncate
Agent End → Rules Engine → Enforce (commit, summarize, etc.)

Rules Format

Rules are defined in rules.json (or the shepherd section of settings):

[
  {
    "name": "block-grep-for-code-graph",
    "pattern": "^grep\\s+.*\\b[A-Z][a-zA-Z]+\\(",
    "type": "tool_call",
    "action": "block",
    "message": "Use code-graph search_symbols instead of grep for symbol names"
  },
  {
    "name": "warn-large-edit",
    "pattern": "edit",
    "type": "tool_result",
    "maxLines": 500,
    "action": "warn",
    "message": "Edit result is large, consider breaking into smaller changes"
  }
]

Rule Types

| Type | When Evaluated | Actions | |------|---------------|---------| | tool_call | Before tool execution | pass, block, modify | | tool_result | After tool execution | pass, warn, truncate | | agent_end | When agent finishes | enforce |

Built-in Rules

pi-shepherd ships with default rules for common anti-patterns:

  • Redirect grep to code-graph for symbol searches
  • Warn on overly large tool results
  • Enforce git commit on agent end
  • Block redundant file reads

Configuration

{
  "shepherd": {
    "enabled": true,
    "rulesDir": "~/.pi/agent/shepherd-rules"
  }
}

Use Cases

| Scenario | Rule Type | Action | |----------|-----------|--------| | Enforce coding standards | tool_call | Block tools that don't follow conventions | | Prevent context bloat | tool_result | Truncate large results | | Git discipline | agent_end | Force commit at session end | | Redirect to better tools | tool_call | Block grep, suggest code-graph | | Custom team rules | All types | Project-specific guardrails |

Best Practices

✅ Recommended

  • Start with built-in rules, then add project-specific ones
  • Use warn before block — give the agent a chance to learn
  • Keep rule patterns simple and specific — regex is evaluated on every tool call
  • Put project rules in .pi/shepherd-rules/ for version control

❌ Not Recommended

  • Don't use overly broad patterns — they'll match too many calls and slow things down
  • Don't create contradictory rules (block + allow the same pattern)
  • Don't rely on shepherd for security — it's a guide, not a sandbox

Limitations

| Limitation | Detail | |------------|--------| | Regex only | Patterns use regex, not semantic understanding | | No async rules | Rules must evaluate synchronously | | Agent can bypass | Determined agents can ignore warnings | | No persistence | Rule state resets between sessions |

Architecture

pi-shepherd/
├── index.ts          # Entry: register hooks + rules engine
├── rules-engine.ts   # Pattern matching + action dispatch
├── rules/            # Built-in rule definitions
│   ├── grep.ts       # Redirect grep → code-graph
│   ├── line-limit.ts # Warn on large outputs
│   └── agent-end.ts  # Enforce git commit
├── types.ts          # Rule type definitions
└── package.json

Dependencies:

  • @pi-atelier/shared-utils (bundled) — settings management
  • @earendil-works/pi-coding-agent — ExtensionAPI (peer)

License

MIT