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

@primp9053/pi-subagent

v0.2.8

Published

Concurrent sub-agents for pi. /sub <task> opens a fork-point selector so you can pick any user message as the sub's inherited context (Enter = latest); /subn <task> spawns from latest without the selector; status line shows main/sub1/sub2; alt+s cycles su

Readme

pi-subagent

Concurrent sub-agents for pi. Fork a background agent from your current session that runs without blocking the main agent — keep working in the main thread while subs run in parallel.

Why

pi's built-in /fork and /clone tear down the current session and switch to the new one — the main agent stops. If you want to spawn an agent to handle a side task while the main agent keeps working, there is no native path. This extension adds one.

Verified by a concurrency PoC: two independent AgentSession instances created via the public createAgentSession API run interleaved in a single process (event timestamps overlap, both use tools, both complete, no provider conflicts). The agent loop is per-instance and the provider registry is a shared read-only route table — so multiple concurrent agents are safe.

Commands

/sub <task>                Spawn a sub-agent. Pops a fork-point selector listing all
                           your user messages (latest first) so you can choose how much
                           history the sub inherits — pick any user message as the
                           sub's context. Enter = latest (full history, the default);
                           Esc cancels the spawn. Optional "name:<word> " prefix.
/subn <task>               Fast path: spawn from the current latest state WITHOUT the
                           picker (the pre-picker behavior). Full current history.
/sub list                  Show all sub-agents and their status.
/sub view <id|name>        Show a sub-agent's captured output (event log + last message).
                           While the main agent is streaming, the output appears IMMEDIATELY as a
                           widget above the editor (pi has no API to inject a chat block
                           mid-stream); the full chat block is queued and appears after the
                           current main turn ends (deliverAs: followUp). When idle, the block
                           appears in chat immediately.
/sub send <id|name> <msg>  Continue interacting with an existing sub-agent. If the sub is still
                           running, the message is QUEUED (deliverAs: followUp) and processed
                           after the current turn ends — not rejected. The sub's AgentSession
                           accumulates messages, so it retains its prior conversation context
                           and continues on it (the model remembers the history).
/sub cancel <id|name|all>   Abort + dispose a sub-agent (or all).

The fork-point selector is a flat list of your user messages (pi's tree view is an internal TUI component not exposed to extensions; the flat list is the extension-accessible equivalent and matches what pi's own /fork shows).

Folding sub output

Two ways to fold a sub's output block:

  • alt+g (pi-subagent, in-place) — folds/unfolds ONLY the currently-viewed sub-output block. This is the fast path: it toggles just that one component and repaints the screen via a no-op setToolsExpanded(currentValue) (which skips every message's rebuild because the value is unchanged, then calls ui.requestRender()). Use /sub view <id> first so the block is on screen.
  • Ctrl+O (pi global) — folds/unfolds ALL expandable messages at once. On long sessions this re-parses Markdown for every tool/custom block, which can look like "the whole TUI reloaded". Prefer alt+g to fold just the sub block without touching the rest.

The terminal pi TUI does not support mouse-click on UI components, so folding is keyboard-driven, not click-to-fold.

Status line

While subs exist, ctx.ui.setStatus("pi-subagent", ...) renders a line like:

main · sub1▶3t · sub2✓

( running with tool count, done, error, cancelled.)

Keyboard

alt+s — cycle which sub's output is shown (replays its log into the main chat as a custom message). No subs → notifies "no sub-agents".

How it works

  • input event hook intercepts /sub ... and returns { action: "handled" } so the command never reaches the main agent.
  • Spawning: createAgentSession({ cwd, modelRegistry: ctx.modelRegistry (reused), model, sessionManager: branchedSession, tools }). The branched session file is built from the main session's current leaf via createBranchedSession(leafId) (same mechanism as /clone), so the sub inherits the full current history.
  • Background run: sub.session.prompt(task) is fired without awaiting, so the main session's loop continues uninterrupted. Sub events are captured via sub.session.subscribe(...) to an in-memory log.
  • Status: ctx.ui.setStatus updates the footer.
  • Cancel: sub.session.abort() + dispose().
  • Cleanup: on session_shutdown, all subs are aborted + disposed.

Known limitations (honest)

  1. Sub live streaming output is not in the main chat's streaming slot. The main TUI chat is bound to the main session. Sub output is captured to an event log and replayed on demand (or on completion) as a custom message (customType: "pi-subagent-output") via pi.sendMessage(display:true) + a registered message renderer.
  2. Keyboard "switching" switches which sub's log is shown, not the native chat view. The main chat always reflects the main session.
  3. A sub shares the main session's cwd, model, and a fixed tool set (read, bash, edit, write). It writes its own session file under ~/.pi/agent/sessions/<encoded-cwd>/ and is later resumable via pi's normal /resume.
  4. Sub-agents are in-memory only for this extension's tracking (the underlying session file persists, but the live subs Map does not survive a pi restart).

Install

pi install npm:@primp9053/pi-subagent

Project-local: pi install ./pi-subagent -l. Restart pi to load (ESM static imports bind at process start; /reload does not reload extension code).

Compatibility

pi 0.80.x. Requires @earendil-works/pi-coding-agent and @earendil-works/pi-ai as peer dependencies (present in any pi install).

License

MIT