Skip to content
jonascloudPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

pi-sub

A small coordinator for native Pi subagents. Pi owns conversation history, tools, compaction and retries; pi-sub owns subagent model selection, task and process lifetime, and compact presentation.

A task owns a native Pi session. Each execution is a fresh pi --mode json --print process on that session. A reply may be a question, and an execution may fail: a follow-up continues the session either way, and explicit acceptance removes the task. Ready and paused tasks hold no process.

Install

Requires Pi 1.5-compatible host packages and Node.js 22.19 or newer:

pi install git:github.com/jonascloud/pi-sub

Use /reload after installation or source changes.

Settings

Open /sub:settings to configure delegation for your Pi profile:

  • Model — choose the model and thinking level for new tasks. Existing tasks, including queued tasks and follow-ups, keep their original choice. The picker is independent of the parent model and its cycling scope; delegation requires an explicit, available model.
  • Max. parallel tasks — the number of child executions one parent session may run at once (default: 4). Raising it admits waiting work immediately in the current session. Lowering it lets running work finish; no new execution starts until a slot is free.

If the session limit differs from the profile limit, /sub:settings shows both. Opening or cancelling settings does not apply the profile limit; a session picks up changes saved elsewhere on its next successful sub_task call.

Use /sub:settings sonnet to go directly to models matching sonnet. The model and limit are stored independently in the Pi profile (pi-sub-model.json and pi-sub-limit.json); an existing model selection needs no migration.

Parent tools

Tool Contract
sub_task Start bounded work with a prompt and optional description. Returns an ID immediately.
sub_message Send { id, message }. Updates queued input or stops active execution, waits for closure, then continues the same session with the correction. Also answers ready, failed or paused tasks.
sub_result Inspect { ids, wait?, timeout?, finish? } in input order, or page { report, offset?, limit? }. finish accepts the selected tasks as a group.
sub_control Pause, continue or stop ids: [a, b]. Use all: true instead to act on all applicable tasks. Stop removes tasks without undoing their work.

Start with sub_task and carry on with independent work. The reply arrives automatically. If the next step depends on several replies, join just those tasks: sub_result({ ids: [a, b], wait: true }). For a single task, pass [a]. Use distinct IDs. With or without waiting, task results are a list in input order, including for one task. Add finish: true only if every selected task can be closed even on failure; acceptance removes all or none.

Use sub_message for a correction or follow-up in the same session. An unsent follow-up has no answer yet. If the previous execution fails while winding down, the task tells you that the follow-up was not sent. Its report ID points to the previous execution’s error and any partial answer, not an answer to the follow-up.

A wait observes until every selected task is ready or failed, even if some start out queued. A single timeout covers the group (default: 30 seconds). A timeout, any selected task pausing, or user steering returns the current states without stopping work. With finish: true, an incomplete group stays open; requesting immediate acceptance of an incomplete group is an error. An unknown or removed ID is an error, not a missing result to skip. Reading a reply does not accept it, and a delivered reply needs no acknowledgement: the task stays open for follow-up until accepted or stopped. Accepted and stopped tasks cannot resume; cached reports survive task removal until eviction or runtime teardown. If acceptance is the first delivery, it includes the result. Otherwise it confirms only the task ID, accepted status and available report ID. /sub:stop also names any final report IDs without repeating replies. There are no idempotent task receipts.

Replies and failures arrive on their own. At the next safe turn boundary, or once when the parent is idle, pi-sub batches unannounced ones into one message; a complete tool return already counts as delivery. Each completed execution has an immutable report ID. Serialized reports up to 2 KiB are inline; larger ones include a reference, a response preview of at most 512 bytes and an error preview of at most 240 bytes. A result or batch is at most 8 KiB; an oversized batch is cached as a report with a summary and reference.

Page a report with sub_result({ report: "<report-id>", offset: 0, limit: 4096 }). This returns plain text and the next offset without executing a child. Offsets are zero-based UTF-8 byte boundaries; limits are bytes, default 4096, minimum 4 and maximum 4096. The parent runtime has one 16 MiB FIFO cache of UTF-8 report payloads; reads do not refresh it. If FIFO eviction reaches a task’s current report before its first handoff, the cache keeps a temporary disk copy. After handoff or replacement by a follow-up, later writes may evict it. An expired reference returns “Report no longer available”. A single report over 16 MiB spills to a private temporary file until runtime teardown. A batch also spills if caching it would evict a report it references; later FIFO eviction is unchanged. The budget excludes JS heap, native history, pending input and journals. Session switch, fork, reload or shutdown tears down the runtime; preserve relevant findings before leaving.

Pause and continue

Aborting the parent, for example with Escape, stops only the parent. Children keep running; their replies wait and do not wake the parent until your next prompt. To stop children, pause them:

/sub:pause [task-id]
/sub:continue [task-id]
/sub:stop [task-id]

For these slash commands, omitting the ID means all applicable tasks. The model tool sub_control has no implicit target: the whole selection is checked before any task is changed. /sub:pause without an ID stops everything: it pauses every child and aborts the parent. Paused children stay paused until /sub:continue, a sub_control continue or a message. In RPC, send prompt("/sub:pause").

Pausing terminates the process (SIGTERM, then SIGKILL) and continuation restarts it on the same session. It does not undo writes or external effects.

A failed execution leaves its task open. The parent receives the failure like a reply, and a message continues the session, resending instructions that never reached it. Nothing retries on its own. A lost or corrupt journal can prevent continuation.

Queued, paused and ready tasks hold no process. Shutdown, reload and session replacement close all executions and delete the temporary workspace; reopening a saved conversation starts without tasks.

Views and usage

Grouped results show state counts, task names and reply or error previews, whether requested or delivered automatically. Expand a result for requests, full delivered text, IDs, execution and usage. The widget above the editor shows outstanding work: active and paused tasks, and replies or failures the parent has not seen. Delivered ones fold into a count; the summary shows native ↑input ↓output tokens of all subagents.

Usage is read from each child's saved journal after every execution and charged to the parent session with the next subagent tool result, independent of acceptance. Pi offers extensions no other way into session totals, so work confirmed after a session's last subagent tool result is missing from them.

Boundaries

  • Children load normal Pi resources from the same profile and working directory, including AGENTS.md and project context, but not the parent's conversation, runtime-only registrations or tool filters. The delegation tools are excluded to prevent recursion.
  • --approve conveys project trust, not approval of individual tools. Children have no interactive UI: confirm returns false and other dialogs return undefined. The parent model cannot grant human authorization.
  • Separate processes are not a filesystem sandbox. Interruption and replay do not guarantee exactly-once external effects.
  • Process exit is not success: a reply requires a new saved assistant response.

Development

Clone the repository and install its dependencies. To load the local checkout in Pi, run pi install /absolute/path/to/pi-sub.

npm ci --ignore-scripts
npm run check
npm test
npm run format:check

Tests include real parent/child Pi processes with a synthetic local provider and no paid model calls. They do not establish instruction compliance or token savings with real models.

The architectural decisions record the contracts behind this behavior. Code is MIT licensed.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages