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-agent-flow

v1.1.0

Published

Flow-state delegation extension for Pi coding agent.

Readme


Quickstart

Installing Pi Agent Flow

Install via the Pi CLI from npm:

pi install npm:pi-agent-flow

Or add it to your Pi settings:

# ~/.pi/agent/settings.json
{
  "packages": [
    "npm:pi-agent-flow"
  ]
}

Then start Pi and delegate tasks using flow states.

# Install from a local clone
git clone https://github.com/your-org/pi-agent-flow.git
cd pi-agent-flow
pi install .

Features

  • Isolated context — flows always receive your current session snapshot (or start clean when configured)
  • Parallel execution — batch independent flows into one call
  • Structured reports — every flow returns [Summary], [Done], [Not Done], [Next Steps]
  • Depth guards — configurable max delegation depth (default: 3)
  • Cycle prevention — blocks recursive delegation chains
  • Flow discovery — reads definitions from ~/.pi/agent/agents/ and .pi/agents/
  • TUI rendering — rich collapsed/expanded display in interactive mode
  • Post-flow hooks — automatic advisory messages after successful flows (e.g., code → review)
  • Smooth streaming metrics — context token counters increment tick-by-tick during active streaming instead of jumping at boundaries

Why Flow Style?

Flow-style delegation is designed for context efficiency. Instead of launching every sub-agent with the full, ever-growing conversation history, each flow receives only what it needs: your intent and (when appropriate) a session snapshot.

This approach delivers four concrete benefits:

  1. Avoid duplicate tool calls — every sub-agent launch no longer re-runs the same read, grep, or bash probes that the parent already performed.
  2. Prevent context bloat — long transcripts with repeated file listings and command outputs are kept out of the main conversation thread.
  3. Eliminate unnecessary noise — the parent agent sees only structured results ([Summary], [Done], [Not Done], [Next Steps]) instead of pages of intermediate reasoning.
  4. Preserve focus — each flow stays locked on its intent because it isn't distracted by unrelated earlier messages.

The result is faster, cheaper, and cleaner delegation: the main agent remains uncluttered while specialized flows do the heavy lifting in isolated contexts.


Flow Definitions

Create .md files in ~/.pi/agent/agents/ or .pi/agents/:

---
name: explore
description: Discover files, trace code paths, map architecture
tools: batch, bash
---

During this explore flow — your mission is discovery. Stay focused on your intent at all times.

When accomplished, end your response with:

flow [explore] accomplished

[Summary] what was investigated

[Done]
- completed items

[Not Done]
- incomplete items

[Next Steps]
- recommended follow-up

Bundled Flows

| Flow | Purpose | |------|---------| | [explore] | Discover files, trace code paths, map architecture | | [debug] | Investigate logs, errors, stack traces, root causes | | [code] | Implement features, fix bugs, write tests | | [architect] | Plan structure, break down requirements, design solutions | | [review] | Audit security, quality, correctness | | [brainstorm] | Generate ideas and explore possibilities with a clean slate |

Note: Some flows — like [brainstorm] — start with a clean slate and do not inherit the current session context. They receive only the intent, making them ideal for unbiased, creative thinking.


Post-Flow Hooks

When certain flows complete successfully, the system can inject advisory messages suggesting follow-up flows. This keeps the agent on the optimal path without requiring the user to manually chain flows.

Built-in Hooks

| Hook | Trigger | Advice | |------|---------|--------| | code → review | A [code] flow succeeds | "Consider running a [review] flow to audit the changes…" | | debug → code | A [debug] flow succeeds | "The root cause has been identified. Consider running a [code] flow to implement the fix." |

Hooks are smart: if the agent already included the suggested flow in the same batch, the advisory is suppressed to avoid redundancy.

Extending

Hooks are registered via registerHook() in hooks.ts. Each hook defines a trigger (flow type + success requirement) and an action that returns advisory text. The hook system mirrors the flow discovery pattern, making it easy to add domain-specific hints.

Example — a custom explore → architect hook:

registerHook({
  name: "my/explore-to-architect",
  trigger: { flowTypes: ["explore"], onlyOnSuccess: true },
  action: (ctx) => ({
    content: "Consider running an [architect] flow to design a solution.",
    priority: 10,
  }),
});

Usage

Single flow

{ "flow": [{ "type": "explore", "intent": "Find all authentication-related code", "aim": "Find auth code" }] }

Batch multiple flows

{
  "flow": [
    { "type": "explore", "intent": "Find auth code" },
    { "type": "review", "intent": "Audit auth module" }
  ]
}

Configuration

Flags (passed to parent pi process)

| Flag | Description | Default | |------|-------------|---------| | --flow-max-depth [n] | Maximum delegation depth | 3 | | --flow-prevent-cycles | Block cyclic delegation | true | | --no-flow-prevent-cycles | Disable cycle prevention | — | | --flow-lite-model [model] | Model for lite-tier flows (explore, debug) | — | | --flow-flash-model [model] | Model for flash-tier flows (code, review) | — | | --flow-full-model [model] | Model for full-tier flows (brainstorm, architect) | — |

Environment variables (propagated to child processes)

| Variable | Description | |----------|-------------| | PI_FLOW_DEPTH | Current depth | | PI_FLOW_MAX_DEPTH | Max allowed depth | | PI_FLOW_STACK | JSON array of ancestor flow names | | PI_FLOW_PREVENT_CYCLES | "1" or "0" |


Docs

This repository is licensed under the MIT License.