Install
Install with PiG
pig install npm:@zhtmike/pi-minimal-dispatchInstall with Pi
pi install npm:@zhtmike/pi-minimal-dispatchPackages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.
Pi manifest JSON
The pi field of package.json.
{
"extensions": [
"./src/index.ts"
]
}README
Written by the package's publisher, shown as published in version 0.6.0 (README.md). PiG does not review it.
pi-minimal-dispatch
Minimal detached lane dispatch with visible state for the pi coding agent.
Lanes are detached pi --mode json processes in their own process groups:
they survive the dispatcher's death, and their live state is derived from
their event streams — never guessed from empty files.
wave 'survey':
docs [glm-4.6 think:high] · running · 2 turns · tok 5703in/90out, $0.0009 · stop:toolUse · last 3.1s ago
review [glm-5.3-flash] · settled · 4 turns · tok 12021in/310out, $0.0041 · stop:stop · last 12s ago
Why
pi ships no sub-agents by design — its README: "install a package that does it your way." Most packages that answer grow an agent cast: persona rosters and per-role system-prompt markdown, concurrency pools and spawn budgets, fleet UIs, hub servers or daemons that must stay alive. pi-minimal-dispatch takes the other end of the trade:
- No personas, no role play — a lane is a brief — inline (
brief) or a file (briefPath) — plus optionalmodel/thinkingpins; the dispatching agent writes each brief, so it keeps the judgment. - The filesystem is the whole protocol — briefs in, JSONL events, one manifest, artifacts out; no server, no in-memory state, re-adoptable by any later session.
- The caller decides scale — no queue, no pool, no cap; external limits are the caller's discipline.
- Zero runtime dependencies — Node builtins and a small host-API surface; CI typechecks the pi 1.4.0 floor and latest pi.
The full design rationale, positioning, and origin story: docs/design.md.
Requirements
- pi ≥ 1.4.0, macOS or Linux (POSIX process groups,
timeout, process start times — Windows is not supported): Linux reads/proc/<pid>/stat; macOS needsps -o lstart= - GNU
timeout: preinstalled on Linux; on macOSbrew install coreutilsor settimeoutBin: "gtimeout"(Configuration)
Install
pi install npm:@zhtmike/pi-minimal-dispatch # official (registry)
pi install git:github.com/zhtmike/pi-minimal-dispatch # tracks main
pi -e ./src/index.ts # try it for one invocation
Quick start
Write one brief per lane — inline (brief) or as a file (briefPath) — the
lane's whole prompt: goal, scope, expected deliverable. Then ask in plain
language:
Dispatch two lanes: docs summarizes the request-handling module, review audits src/auth.
Wait for them to settle and collect the artifacts.
A real session:
> dispatch wave="survey" lanes=[{name:"docs", briefPath:".pi/work/s/<session-id>/survey-docs-brief.md",
model:"zai/glm-5.3-flash"},
{name:"review", briefPath:".pi/work/s/<session-id>/survey-review-brief.md", mcp:true,
tools:"read,grep,find,ls,codemode"}]
wave 'survey' dispatched — 2/2 lanes spawned
docs: pid 99015 (deadline 900s)
review: pid 99016 (deadline 900s)
manifest: /abs/path/to/.pi/work/survey-manifest.json
[next: lanes(wave='survey', action='wait') — blocks until every lane settles or any fails; waitSec caps it; action='status' to peek]
> lanes wave="survey" action="wait"
docs [glm-5.3-flash] · settled · 2 turns · tok 5703in/90out, $0.0009 · stop:stop · last 0.8s ago
review [glm-4.6] · settled · 4 turns · tok 12021in/310out, $0.0041 · stop:stop · last 2.1s ago
[next: lanes(wave='survey', action='collect') — writes each lane's final message to an artifact; release the wave when done]
> lanes wave="survey" action="collect"
collect wave 'survey':
docs: /abs/path/to/.pi/work/survey-docs.md stop:stop
review: /abs/path/to/.pi/work/survey-review.md stop:stop
[next: lanes(wave='survey', action='release') — deletes the wave's files including the artifacts; copy out anything you still need]
The ceremony: write briefs → dispatch → wait (or poll status) →
collect → release. dispatch never blocks; waiting is an explicit,
bounded wait call that returns the status table the moment every lane is
settled or any has failed (surfaced at the poll cadence) — no
sleep-then-poll guessing. In the TUI, a
collect result expands (ctrl+o / click) to render each lane's artifact
in place. release deletes exactly the wave's own files and refuses
unsettled, foreign-owned, and unconsumed waves — collect first, and a
human may always delete by hand (details).
Steering is kill + redispatch: refine the brief, run a new wave
(slugs are single-use). Hang detection: lastEventAgeSec is the
signal — no event growth for ~2× the lane's normal turn latency ⇒
kill and redispatch. Failed lanes: wait wakes at the first failure —
waitMode: "hold" sees the running siblings through, or steer: kill +
redispatch under a new slug.
When to dispatch — a drop-in policy block
The tool schemas deliberately carry no usage policy: when to fan out is
your layer, not the package's, and shipped descriptions are identical for
everyone while policy is per-repo taste. The mechanics (dispatch never
blocks; waiting is the bounded wait call) live in the schemas — the
judgment belongs in your agent instructions. Copy and adapt:
- Dispatch a sub-task when it deserves its own context: read-only
exploration before implementing, parallel investigation lanes. Research
fan-out is the classic pattern; whether implementation dispatches is your
policy — the tools support write-capable lanes the same way.
- One brief per lane — inline (`brief`) or a file (`briefPath`) — is its
entire prompt: goal, scope, expected deliverable and format, what not to
do, and lines stating the addressee is a dispatched leaf with no shared
context and that the lane's final message is its deliverable. Park briefs
under a per-session subdirectory (.pi/work/s/<session-id>/ — your session
id where the harness exposes it, else any unique per-session marker).
- Tier the lane to the job — mechanical recon and investigation on a cheap
fast model (pin `model`, add `thinking`), judgment and verdict work on
the strong model. Shape `tools` to the role: verification lanes take
bash (run tests, edit nothing), implementation lanes take
bash/edit/write, and any lane needing online resources takes
`mcp: true` + `codemode`. Name the covering tests in the brief — a lane
set to run an unscoped full suite eats its own deadline.
Valid `model` ids: `pi --list-models`.
- Consume waves: wait (bounded) → collect → release; never hand-delete
workDir contents while a lane may still be running.
API
Two tools — full parameter, output, and configuration reference in docs/api.md:
dispatch— validate briefs, claim the wave slug, spawn every lane detached in its own process group; returns in under a second.lanes— statelessstatus/wait/kill/collect/releaseover the wave's manifest; any session can re-adopt a wave, including after the dispatcher exited.
Web/MCP reach: the default lane is offline — set mcp: true to connect
MCP servers; connecting grants nothing by themselves, and a lane reaches
their tools only through codemode or tool_search named in its tools.
Rules and examples: MCP and web reach.
Configuration
The lane protocol is fixed; every variable knob — deadlines, kill grace, poll interval, working directory, binaries — is configurable via user or project JSON, merged defaults → user → project → per-call parameters. Invalid files fail loudly. Full table and precedence rules: docs/api.md.
Status bar & /lanes
While any tracked lane runs — or has failed and the wave is not yet released — the footer shows one line:
[lanes: 2 running · 1 failed (deadline) · 1 settled]
[lanes: survey/docs running (turn 3 · bash · last 12s)] ← one lane running
A lane gone quiet badges (1 idle 75s); a lane past its deadline badges
(1 overdue) — signals, not verdicts. /lanes inspects waves without
spending model tokens: bare /lanes lists every wave (with exactly one
readable wave it shows that wave's table directly), /lanes <wave>
prints the full table, /lanes <wave> <lane> shows one lane in detail —
its trace, its artifact, its failure. Failed lanes link their transcript
and .err where the terminal supports it. Full reference:
docs/api.md.
State model
Derived on every call from the event stream, PID liveness, and the
deadline — never stored, never stale. settled means the agent_settled
event was seen — success is collect with suspect: false.
| State | Meaning |
|---|---|
starting | spawned, no session header yet |
running | events flowing (overdue: true once past deadline) |
settled | agent_settled emitted (any stop reason — success is collect with suspect: false) |
failed | cause: spawn (nothing ran) · killed (tombstoned) · deadline (leash fired) · crashed (.err tail attached) |
How lanes are spawned, what the manifest records, and why state is never stored: Mechanics in docs/design.md.
Testing
npm test runs the unit suites (config, derive, format, lane, release).
Contributing · License
CONTRIBUTING.md · agent instructions in AGENTS.md · MIT