No description
  • TypeScript 74.5%
  • JavaScript 25.5%
Find a file
2026-11-05 19:54:39 +00:00
tests Add per-agent readOnly research mode and contextWindow override 2026-11-05 19:54:39 +00:00
activity.ts Show distinct compacting status for subagents 2026-10-23 09:12:32 +00:00
CHANGELOG.md Add per-agent readOnly research mode and contextWindow override 2026-11-05 19:54:39 +00:00
index.ts Add per-agent readOnly research mode and contextWindow override 2026-11-05 19:54:39 +00:00
package.json Report subagent usage in native Pi session totals 2026-10-17 12:33:56 +00:00
panel.ts Detect and display silent and suspected subagent stalls 2026-10-20 20:02:52 +00:00
README.md Add per-agent readOnly research mode and contextWindow override 2026-11-05 19:54:39 +00:00
render.ts Show distinct compacting status for subagents 2026-10-23 09:12:32 +00:00
spawn.ts Add per-agent readOnly research mode and contextWindow override 2026-11-05 19:54:39 +00:00
stall.ts Detect and display silent and suspected subagent stalls 2026-10-20 20:02:52 +00:00
usage.ts Report subagent usage in native Pi session totals 2026-10-17 12:33:56 +00:00

@pi-spice/minimal-subagents

One tool, spawn_agents: describe sub-agents inline, run them in parallel, block until every one finishes. No predefined agent files, no orchestration, no nesting. Each sub-agent is an isolated pi process with its own context window; the child-process machinery is adapted from pi's official subagent example.

Install

pi install npm:@pi-spice/minimal-subagents

Quick test from this repo: pi -e ./extensions/minimal-subagents

How it works

spawn_agents({ agents: [spec...] }) — a single task is an array of one; up to 10 per call, all 10 able to run concurrently.

Field Required Default
task ✓ —
systemPrompt — child default; role/constraints go here, not the assignment
model — inherit the parent session's model
thinking — inherit the parent session's thinking level (off…max)
tools — child default tools; e.g. ["read","grep","find","ls"] for read-only scouts
readOnly — false (all tools). true limits tools to read, grep, find, ls, bash plus the pi-web-access tools web_search, fetch_content, get_search_content, source_check (active immediately; web_enable is omitted) and prepends a do-not-modify instruction. bash is read-only by instruction only. Ignored when tools is set
contextWindow — the model's own window. A positive integer in tokens, unchecked against the model's real limit; it moves the child's compaction point
name — agent-<index>
  • Context window override - pi has no flag for this, so the child runs with PI_CODING_AGENT_DIR pointing to a temporary dir that symlinks every entry of the real agent dir, plus a copy of models.json with providers.<provider>.modelOverrides.<id>.contextWindow merged in. The dir is removed when the child exits. The model must resolve to a unique provider/id, otherwise that agent fails with an error; models.json must be plain JSON (no comments).
  • Native usage accounting - when the call finishes, its tool result reports the combined input/output/cache tokens and cost of all sub-agents to Pi. Pi includes these in its session statistics and footer totals alongside the main agent's usage. This includes reported nested-tool model usage, successful compactions, and usage already received from failed or cancelled agents. Streaming snapshots are not counted again. The main agent's context-window percentage remains separate. Accounting depends on usage emitted by the child and the provider's pricing; usage not reported before a child is killed cannot be recovered. Requires a Pi host that supports tool-result usage (verified with Pi 1.3.0).
  • Failures don't cancel siblings — every agent runs to completion; each result is a ### [name] completed/failed section with the agent's final output (50 KB cap; full transcripts stay in the tool details). isError only when all fail.
  • Live progress — a one-line call header (spawn_agents (3 agents)), then one block per agent: glyph + name + duration/tools, then the first line of the task (always — so agents stay distinguishable even when names are opaque). Text output and waiting on tools share the same Braille spinner (⠖⠲⢲…, with the top dot row empty); thinking or awaiting the model uses a pulsing star (✶✷✹✺…), including during startup. Animations refresh every 100 ms and elapsed time advances in whole seconds. Activity labels distinguish writing, running tool, thinking and Compacting.... Agents waiting on tools grow a third line with the latest tool call; failed agents put the error on the header. Once every agent has finished, the summary shows combined cost, wall-clock time and tool count, with a separate output/total-token row (including cache), even for single-agent calls; alt+a live details is shown only while something is still running. alt+a opens the live detail panel; Ctrl+O after completion expands to each agent's final output.
  • Final token summary - collapsed and expanded summaries show e.g. Tokens: 20 out · 190 total (incl. cache). Total tokens are uncached input + output + cache reads + cache writes across all agents and turns. Reasoning and 1h cache writes are already included in their parent counts and are not added again. This is display-only; Pi's native accounting is unchanged.
  • Compaction status - child compaction shows Compacting... with the ASCII spinner | / - \ in the transcript summary and alt+a panel. It appears immediately, remains active through compaction retries, and clears when compaction succeeds, fails or is aborted. Pending tools resume their normal status afterwards. It uses the existing 100 ms refresh clock, leaves the thinking star unchanged and does not change parent-session status or usage accounting. Stall warnings and terminal glyphs still take priority.
  • Tool-status smoothing - both views wait 100 ms before displaying tool activity, then keep it visible for at least 500 ms once shown. The glyph, label and temporary tool-call preview change together. Quick calls skip the transient status; full tool history and live response text remain immediate. Compaction, completion, failure and cancellation bypass the hold. This is display-only, driven by the existing refresh clock; tool execution and usage accounting are unchanged.
  • Stall detection - running agents show a red ! and stall detected after 60 seconds without a valid child event, or stall suspected after 5 minutes of raw thinking without useful progress. Thinking updates prove liveness but do not reset the progress clock; text, tool activity (including execution updates), message completion and compaction/retry transitions do. Expanded results and alt+a show the reason and elapsed silence/no-progress time. These are display-only warnings, not proof of a hang: they clear automatically on recovery or completion and never kill or cancel an agent. The existing UI clock drives detection independently of tool-status smoothing.
  • Abort returns partial results - finished agents keep their output and the rest are marked aborted. Cancellation requests SIGTERM, with a SIGKILL fallback after 5 s while the child is still open (process group on POSIX; direct child on Windows). Cancellation handlers are removed when children finish.
  • Child-output warnings - malformed JSONL records produce a visible warning, without discarding a usable answer. A child that exits without a completed assistant response is marked failed. UTF-8 characters split between output chunks are decoded safely.

Details panel (alt+a)

  • One tab per sub-agent (←/→, 1-9, or 0 for agent 10; the tab bar compacts and wraps automatically on narrow panels), labelled with name and live status (animated ⠖ for text/tools, animated ✶ for thinking/model waits, ASCII spinner for compaction, ✓ completed, ✗ failed). The selected agent's elapsed time is shown in the timeline header.
  • Each tab is the agent's full timeline: task, tool calls, labelled tool-result previews (up to 10 source lines and 2,000 characters), assistant output rendered as markdown, usage. Shortened previews are marked; full tool results remain in the tool details.
  • Live responses appear only in this panel, with refreshes limited to once per 100 ms while text streams. Completed messages replace the temporary preview, so text and usage are not counted twice. Private thinking text is never displayed.
  • Terminal-style scrolling: ↑/↓, PgUp/PgDn, Home/g, End/G, mouse wheel — pinned to the bottom while following new output, scrolling up pauses, End resumes. alt+a toggles (same key opens and closes); Esc also closes.
  • Pressing alt+a before any spawn_agents run shows pi's notify message above the input instead of opening an empty panel.
  • Shows the latest call only. Two platform limits: it is an overlay (the transcript is covered, not reflowed), and mouse wheel works only under --tui-mode fullscreen — the only mode where pi enables terminal mouse reporting.

Tests

With Node.js 22.19+:

npm test

Tests use deterministic child processes, not paid model requests. The integration test loads the extension and checks Pi's native session/footer accounting. It runs when the Pi peer package is locally resolvable, or when PI_CODING_AGENT_DIR points to its installed package directory; otherwise it is skipped:

PI_CODING_AGENT_DIR=/path/to/node_modules/@earendil-works/pi-coding-agent npm test

No nesting

Children run with PI_SUBAGENTS_CHILD=1 (the extension skips tool registration when it sees it) and are launched with --exclude-tools spawn_agents as a backstop. This is a guard, not a sandbox: a sub-agent with bash can still start arbitrary processes and work around both layers (e.g. env -u PI_SUBAGENTS_CHILD pi ...) — use tools restrictions or a container for hard isolation. Side effect: exporting PI_SUBAGENTS_CHILD=1 in your own shell hides spawn_agents from your sessions.