@loka1/pi-orchestra 0.0.0-stage → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +257 -0
- package/LICENSE +21 -0
- package/README.md +584 -2
- package/assets/preview.html +226 -0
- package/assets/preview.png +0 -0
- package/config/orchestra.json.example +35 -0
- package/config/templates/review-squad.md +11 -0
- package/extensions/lib/agents.ts +110 -0
- package/extensions/lib/chat.ts +171 -0
- package/extensions/lib/commands.ts +115 -0
- package/extensions/lib/config.ts +219 -0
- package/extensions/lib/format.ts +637 -0
- package/extensions/lib/git.ts +99 -0
- package/extensions/lib/log.ts +233 -0
- package/extensions/lib/mail.ts +115 -0
- package/extensions/lib/metrics.ts +365 -0
- package/extensions/lib/providers.ts +355 -0
- package/extensions/lib/redact.ts +57 -0
- package/extensions/lib/retry.ts +61 -0
- package/extensions/lib/state.ts +591 -0
- package/extensions/lib/templates.ts +153 -0
- package/extensions/lib/types.ts +156 -0
- package/extensions/lib/worker.ts +450 -0
- package/extensions/orchestra.ts +2906 -0
- package/extensions/ui/browse.ts +497 -0
- package/extensions/ui/join.ts +289 -0
- package/package.json +56 -4
- package/skills/orchestra/SKILL.md +84 -0
package/README.md
CHANGED
|
@@ -1,3 +1,585 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pi-orchestra
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/loka1?tab=repositories&q=pi-&type=source)
|
|
4
|
+
[](https://www.npmjs.com/package/@loka1/pi-orchestra)
|
|
5
|
+
[](https://github.com/loka1/pi-orchestra/releases)
|
|
6
|
+
[](https://loka1.github.io/pi-orchestra/)
|
|
7
|
+
|
|
8
|
+
A [pi](https://github.com/earendil-works/pi-mono) extension that **lets one pi session orchestrate other pi sessions** — runs, tasks, worker dispatches, wake-ups, questions and gates — with **no external runtime, no daemon and no socket**. Every worker is a real `pi` process with its own context window, tools and model.
|
|
9
|
+
|
|
10
|
+
**Docs:** [docs site](https://loka1.github.io/pi-orchestra/) · [wiki](https://github.com/loka1/pi-orchestra/wiki) · every section below links to its full page.
|
|
11
|
+
|
|
12
|
+
<img src="assets/preview.png" alt="pi-orchestra: the worker widget above the editor and the /orchestra browse list" width="100%">
|
|
13
|
+
|
|
14
|
+
*The always-on widget stays small; `/orchestra browse` is where you search, tail a transcript, stop or retry a worker — and now mark several at once.*
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
you (coordinator) worker (pi --mode rpc)
|
|
18
|
+
│ orchestra action=worker_start ─────────────► fresh session, own context
|
|
19
|
+
│ │
|
|
20
|
+
│ ◄────────── orchestra_ask (blocking question) ──┤
|
|
21
|
+
│ orchestra_answer ─────────────────────────────►│
|
|
22
|
+
│ ◄────────── settle wake-up + report + usage ────┤
|
|
23
|
+
│ orchestra_send ──────────────────────────────► │ follow-up work
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
- **Runs, tasks, dispatches.** Group work into a run, split it into tasks with `deps`, start one worker per task. Task readiness follows its dependencies automatically.
|
|
29
|
+
- **Real isolated workers.** Each worker is `pi --mode rpc` in its own process: own context window, own session log, own tools, own model and thinking level.
|
|
30
|
+
- **Wake-ups instead of polling.** When a worker settles or asks a question, the coordinator is woken with its report and usage — you can end the turn and keep working; `orchestra_wait` blocks instead when nothing else can proceed.
|
|
31
|
+
- **Questions and gates.** A worker calls `orchestra_ask`; the coordinator answers with `orchestra_answer`. The question shows up as a message, and a gate is recorded in state.
|
|
32
|
+
- **Steering and follow-ups.** `orchestra_send` steers a running worker mid-task, hands a settled one new work, or broadcasts one decision to every live worker at once.
|
|
33
|
+
- **Resume and repair.** `worker_resume` reopens a worker's own session (no context lost); `worker_start retryOf=<id>` starts a fresh worker with the failed attempt and its evidence in the brief.
|
|
34
|
+
- **Budgets and a stall watchdog.** Cost and wall-clock ceilings per worker and per run, plus detection of a worker that stopped emitting events — distinct from the hard timeout that kills a long task.
|
|
35
|
+
- **Transcript search and metrics.** `action=search` greps every worker log, `/orchestra grep` does the same from the prompt, and `action=export` writes the run's cost/turn timeline as JSONL.
|
|
36
|
+
- **Joinable.** `/orchestra join <id>` (or `j` in the browser) opens one worker's conversation full-screen: what you asked, what it replied, thinking and tool calls, with a composer that steers a live worker or hands a settled one follow-up work. `esc` returns to the browser, `ctrl+g` to your own session.
|
|
37
|
+
- **Reviewable.** Every dispatch records the git commit it started from, so `D` in the browser (or `action=diff`) shows exactly what that worker changed, and `action=report` writes a markdown run report for a PR.
|
|
38
|
+
- **Self-correcting.** Dependency cycles are refused instead of deadlocking a run, `retries` re-dispatches a failed worker with the failure in the brief, and a coordinator restart tells orphaned processes (still alive) apart from lost ones — and can stop them.
|
|
39
|
+
- **Live status.** A compact, width-aware widget ordered by what needs you (questions → running → failed/timeout → ready → settled), plus `/orchestra browse`: a scrollable, searchable list of tasks, workers and runs with detail, message, stop and follow actions.
|
|
40
|
+
- **Durable, local, private.** One JSON state file, one JSONL log per worker, all under `.pi/orchestra/` (git-ignored by the extension itself). Nothing leaves the machine except the model calls you already make.
|
|
41
|
+
- **Isolated by default.** Workers start with `--no-extensions` plus this extension only: no MCP servers, no interactive permission gates, no recursion into more workers.
|
|
42
|
+
|
|
43
|
+
## Install
|
|
44
|
+
|
|
45
|
+
As a package (npm or git — `git:` always tracks the repository, `npm:` follows
|
|
46
|
+
[the registry](https://www.npmjs.com/package/@loka1/pi-orchestra)):
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pi install git:github.com/loka1/pi-orchestra
|
|
50
|
+
# or, once the version is on npm
|
|
51
|
+
pi install npm:@loka1/pi-orchestra
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Every release also ships a tarball asset, if you would rather pin a file:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
gh release download v0.5.0 --pattern '*.tgz'
|
|
58
|
+
pi install ./loka1-pi-orchestra-0.5.0.tgz
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Try it without installing:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pi -e git:github.com/loka1/pi-orchestra
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Reload an open session with `/reload` after installing.
|
|
68
|
+
|
|
69
|
+
→ [Installation](https://loka1.github.io/pi-orchestra/Installation.html): install and upgrade.
|
|
70
|
+
|
|
71
|
+
## Quick start
|
|
72
|
+
|
|
73
|
+
Give pi one instruction:
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
Create the run goal "add input validation", then three tasks: audit the API handlers,
|
|
77
|
+
write the validators, and update the tests (depending on the audit). Start a worker for
|
|
78
|
+
each ready task, wait for them, and report per task with the evidence.
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Or drive it tool by tool:
|
|
82
|
+
|
|
83
|
+
```text
|
|
84
|
+
orchestra action=run_create name="api-validation" goal="validate every endpoint"
|
|
85
|
+
orchestra action=task_create title="Audit handlers"
|
|
86
|
+
orchestra action=task_create title="Write validators" deps=["<audit task id>"]
|
|
87
|
+
orchestra action=worker_start taskId="<audit task id>"
|
|
88
|
+
orchestra action=worker_start spec="Review src/api for missing validation and report a list."
|
|
89
|
+
orchestra_wait timeoutMs=300000
|
|
90
|
+
cat .pi/orchestra/logs/<dispatch id>.jsonl # or: /orchestra watch <id>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
→ [Commands](https://loka1.github.io/pi-orchestra/Commands.html): every command.
|
|
94
|
+
|
|
95
|
+
## Concepts
|
|
96
|
+
|
|
97
|
+
| Concept | What it is |
|
|
98
|
+
|---|---|
|
|
99
|
+
| **Run** | A named body of work with an optional goal. State and reports are grouped per run. |
|
|
100
|
+
| **Task** | A unit of work inside a run. `deps` make it `ready` only after its dependencies are `done`. |
|
|
101
|
+
| **Dispatch** | One worker process working on a task (or on a free-form spec). |
|
|
102
|
+
| **Gate** | A question a worker is blocked on, answered with `orchestra_answer`. |
|
|
103
|
+
|
|
104
|
+
→ [Workers](https://loka1.github.io/pi-orchestra/Workers.html): worker lifecycle.
|
|
105
|
+
|
|
106
|
+
## Commands
|
|
107
|
+
|
|
108
|
+
Tab completes after `/orchestra`: the subcommand first, then the live argument
|
|
109
|
+
(dispatch, task, run or template ids, matched on id, status and title).
|
|
110
|
+
|
|
111
|
+
```text
|
|
112
|
+
/orchestra browse (interactive, TUI); status text elsewhere
|
|
113
|
+
/orchestra browse [query] browser pre-filtered with `query`
|
|
114
|
+
/orchestra resume <id> [msg] reopen a worker's own session (needs sessionMode: session)
|
|
115
|
+
/orchestra retry <id> [note] repair a failed worker: same spec, failure prepended
|
|
116
|
+
/orchestra broadcast <msg> send one message to every live worker
|
|
117
|
+
/orchestra grep <text> search every worker transcript
|
|
118
|
+
/orchestra metrics cost/turn table, spend timeline and delta vs the previous run
|
|
119
|
+
/orchestra export [json] write the run's metrics to .pi/orchestra/exports/
|
|
120
|
+
/orchestra report markdown run report written to .pi/orchestra/exports/<run>.md
|
|
121
|
+
/orchestra diff <id> what that worker changed since it started (git diff)
|
|
122
|
+
/orchestra budget [usd] show spend / raise the run's cost ceiling
|
|
123
|
+
/orchestra prune [days] delete archived runs and orphaned logs older than N days
|
|
124
|
+
/orchestra archive [keep] move finished runs to .pi/orchestra/archive/
|
|
125
|
+
/orchestra open <id> detail of one task/worker/run (task + transcript)
|
|
126
|
+
/orchestra join <id> joined chat with a worker (type into it; esc back)
|
|
127
|
+
/orchestra chat <id> the same conversation as text (print/RPC modes)
|
|
128
|
+
/orchestra find <query> text search across tasks
|
|
129
|
+
/orchestra status summary of the active run (tasks + workers + usage)
|
|
130
|
+
/orchestra tasks task list with readiness and dispatch ids
|
|
131
|
+
/orchestra workers worker table: status, turns, tools, cost
|
|
132
|
+
/orchestra read <id> compact transcript of a worker (tool calls + replies)
|
|
133
|
+
/orchestra watch <id> live transcript in the widget (tail)
|
|
134
|
+
/orchestra unwatch stop watching
|
|
135
|
+
/orchestra stop <id> abort and stop a worker
|
|
136
|
+
/orchestra runs runs, newest first (→ = active)
|
|
137
|
+
/orchestra use <id> make a run the active one
|
|
138
|
+
/orchestra templates run templates (/orchestra template <name> to start one)
|
|
139
|
+
/orchestra questions pending questions/gates
|
|
140
|
+
/orchestra config state dir, config sources, effective config
|
|
141
|
+
/orchestra back leave a joined chat (inside the composer: /back, /exit)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
→ [Commands](https://loka1.github.io/pi-orchestra/Commands.html): complete command and action reference.
|
|
145
|
+
|
|
146
|
+
## Tools
|
|
147
|
+
|
|
148
|
+
| Tool | Purpose |
|
|
149
|
+
|---|---|
|
|
150
|
+
| `orchestra` | Control plane: `status`, `run_create`, `run_list`, `run_use`, `task_create`, `task_list`, `task_update`, `worker_start`, `worker_resume`, `worker_list`, `worker_show`, `worker_read`, `worker_stop`, `worker_keep_open`, `worker_send`, `wait`, `answer`, `gate_list`, `search`, `chat`, `diff`, `metrics`, `report`, `export`, `budget`, `prune`, `archive`, `templates`, `reset`. |
|
|
151
|
+
| `orchestra_wait` | Block until one dispatch (or every live worker) settles, a question arrives, or the timeout fires. |
|
|
152
|
+
| `orchestra_send` | Steer a running worker, or give a settled worker follow-up work. |
|
|
153
|
+
| `orchestra_answer` | Answer a blocking question (`questionId` comes from a question message or `gate_list`). |
|
|
154
|
+
| `orchestra_ask` | *Worker side only.* Ask the coordinator a question and block until it answers. |
|
|
155
|
+
|
|
156
|
+
→ [Commands](https://loka1.github.io/pi-orchestra/Commands.html): complete command and action reference.
|
|
157
|
+
|
|
158
|
+
## Browsing
|
|
159
|
+
|
|
160
|
+
A widget cannot take keyboard focus, so the interactive surface is `/orchestra`
|
|
161
|
+
(or `/orchestra browse`), which opens a full-screen list in TUI mode. Print and
|
|
162
|
+
RPC modes get the same content as text.
|
|
163
|
+
|
|
164
|
+
| Key | Action |
|
|
165
|
+
| --- | --- |
|
|
166
|
+
| `↑` `↓` | move |
|
|
167
|
+
| `PgUp` `PgDn`, `home` `end`, `g` `G` | page, first/last row (`ctrl+d`/`ctrl+u` = half page) |
|
|
168
|
+
| `/`, then type | fuzzy search over title, id, agent, meta and status |
|
|
169
|
+
| `space` | mark the row (▣) for bulk actions |
|
|
170
|
+
| `D` | diff of what that worker changed since it started |
|
|
171
|
+
| `s` / `t` | sort by cost / by time (default: urgency) |
|
|
172
|
+
| `esc` | clear the search, then close |
|
|
173
|
+
| `tab` | switch scope: tasks → workers → runs |
|
|
174
|
+
| `enter` | detail: metadata, report and transcript tail (scrollable) |
|
|
175
|
+
| `m` | message the worker (opens the editor, prefilled empty) |
|
|
176
|
+
| `x` | stop the worker, or every marked one (asks first) |
|
|
177
|
+
| `r` | retry the worker, or every marked one (`retryOf`) |
|
|
178
|
+
| `c` | put the marked (or current) dispatch ids in the editor |
|
|
179
|
+
| `j` | join the worker's chat (see below) |
|
|
180
|
+
| `d` | full transcript of the worker, tail-following |
|
|
181
|
+
| `f` | follow the worker in the widget |
|
|
182
|
+
| `o` | make the highlighted run active |
|
|
183
|
+
| `q` | close |
|
|
184
|
+
|
|
185
|
+
Search understands fields, not just words: `status:failed`, `agent:reviewer`,
|
|
186
|
+
`kind:worker`, `run:ab12`, `cost:>0.1`, `turns:>=8`, combined with free text
|
|
187
|
+
(`status:failed port backend`). The same syntax works in `task_list`/`worker_list`
|
|
188
|
+
`filter` and in the non-TUI `/orchestra find`.
|
|
189
|
+
|
|
190
|
+
The detail pane scrolls, and its transcript tails live: opening a log pager
|
|
191
|
+
starts at the end and keeps following (`f` toggles, scrolling pins it). Rows are
|
|
192
|
+
sorted by urgency by default, so a worker waiting on a question is always the
|
|
193
|
+
first thing on screen; `s` and `t` re-sort by spend and recency. Status comes from the dispatch whenever one exists: a
|
|
194
|
+
task whose worker settled never shows a failure glyph, and a timeout keeps its
|
|
195
|
+
`⏱ n m` marker.
|
|
196
|
+
|
|
197
|
+
The always-on widget is deliberately small: it renders the top
|
|
198
|
+
`widgetMaxLines` rows plus `+N more · /orchestra browse`, and collapses settled
|
|
199
|
+
tasks into a counter unless `widgetShowSettled` is on.
|
|
200
|
+
|
|
201
|
+
→ [Browsing](https://loka1.github.io/pi-orchestra/Browsing.html): keys, detail view, bulk actions.
|
|
202
|
+
|
|
203
|
+
## Joining a worker
|
|
204
|
+
|
|
205
|
+
`/orchestra join <dispatch>` (or `j` in the browser) replaces the screen with
|
|
206
|
+
that worker's conversation:
|
|
207
|
+
|
|
208
|
+
```text
|
|
209
|
+
⤷ joined 9c4e7a10bd · worker · running
|
|
210
|
+
● running 3m · 4 turns · 12 tools · $0.07 of $2.00
|
|
211
|
+
commandcode/deepseek-v4.1-flash · live
|
|
212
|
+
|
|
213
|
+
▶ you
|
|
214
|
+
Port the JSONL backend, keep the header format.
|
|
215
|
+
◆ worker
|
|
216
|
+
Reading the store first, then the header codec.
|
|
217
|
+
→ read src/store.ts
|
|
218
|
+
export interface Store { … }
|
|
219
|
+
→ bash npm test -- jsonl
|
|
220
|
+
42 passing
|
|
221
|
+
────────────────────────────────────────────────────────────
|
|
222
|
+
message this worker — /help for commands
|
|
223
|
+
enter send · ctrl+e editor · ctrl+t think · ctrl+o tools · ctrl+g main · esc orchestra
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Typing sends to that worker, not to the coordinator: a running worker gets a
|
|
227
|
+
steer (delivered after its current tool call), a settled one with `keepOpen`
|
|
228
|
+
gets a follow-up turn in its own context. Composer commands: `/stop`, `/retry`,
|
|
229
|
+
`/resume`, `/diff`, `/open` and `/back` (return to the list), `/exit` (your own
|
|
230
|
+
session), `/help`; `ctrl+e` opens the full editor for a long message.
|
|
231
|
+
|
|
232
|
+
`esc` clears a draft, then goes back to the browser; `ctrl+g` returns to your own
|
|
233
|
+
session. Joining is a view: it changes nothing about the worker, its task or the
|
|
234
|
+
run, and the budget and stall watchdog keep running.
|
|
235
|
+
|
|
236
|
+
→ [Browsing](https://loka1.github.io/pi-orchestra/Browsing.html): joining, keys, leaving.
|
|
237
|
+
|
|
238
|
+
## Working while workers run
|
|
239
|
+
|
|
240
|
+
Workers are background processes, so the coordinator does not have to sit and wait:
|
|
241
|
+
|
|
242
|
+
```text
|
|
243
|
+
you ▸ port the storage layer with two workers, then review their diffs
|
|
244
|
+
|
|
245
|
+
pi ▸ orchestra action=worker_start spec="…storage interface…"
|
|
246
|
+
▸ orchestra action=worker_start spec="…jsonl backend…"
|
|
247
|
+
Started dispatch_9c4e7a10bd and dispatch_ab12cd34ef.
|
|
248
|
+
End your turn — you will be woken when they settle.
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
After starting, ending the turn is the normal move: the extension wakes the
|
|
252
|
+
coordinator (as a follow-up turn) when a worker settles, and immediately when one
|
|
253
|
+
asks a question. You can chat about something else in the meantime, or work in a
|
|
254
|
+
different session — the run lives in `.pi/orchestra/`, not in the conversation.
|
|
255
|
+
|
|
256
|
+
Use `orchestra_wait timeoutMs=…` only when nothing else can proceed, e.g. before
|
|
257
|
+
a step that needs the result. `wait` also returns when a worker asks a question,
|
|
258
|
+
so one call covers both.
|
|
259
|
+
|
|
260
|
+
For jobs that outlive a normal working session, raise the ceiling instead of the
|
|
261
|
+
model being killed mid-file:
|
|
262
|
+
|
|
263
|
+
```json
|
|
264
|
+
{ "timeoutMs": 21600000, "timeoutMode": "idle", "stallMs": 1800000, "stallAction": "abort" }
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
`timeoutMode: "idle"` restarts the clock on every event: a worker that is reading,
|
|
268
|
+
editing and running commands is never stopped, while silence for `timeoutMs`
|
|
269
|
+
(e.g. 6 h) is. `timeoutMs: 0` removes the wall-clock limit entirely and leaves the
|
|
270
|
+
stall watchdog (`stallMs`) as the only safety net. Both can be set for one
|
|
271
|
+
dispatch: `worker_start spec="…" timeoutMs=0`.
|
|
272
|
+
|
|
273
|
+
### Running overnight
|
|
274
|
+
|
|
275
|
+
The settings that matter when nobody is watching, in `~/.pi/agent/orchestra.json`:
|
|
276
|
+
|
|
277
|
+
```json
|
|
278
|
+
{
|
|
279
|
+
"timeoutMs": 0,
|
|
280
|
+
"timeoutMode": "idle",
|
|
281
|
+
"stallMs": 3600000,
|
|
282
|
+
"stallAction": "notify",
|
|
283
|
+
"budgetUsdPerWorker": 5,
|
|
284
|
+
"budgetUsdPerRun": 40,
|
|
285
|
+
"budgetAction": "ask",
|
|
286
|
+
"retries": 1,
|
|
287
|
+
"keepOpen": true,
|
|
288
|
+
"sessionMode": "session"
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
- `timeoutMs: 0` (or a large idle value) means a long task is never cut in half.
|
|
293
|
+
- `stallMs` is then the safety net: an hour with no event is reported in the
|
|
294
|
+
widget and in `/orchestra status`; `stallAction: "abort"` also stops it.
|
|
295
|
+
- Cost ceilings still apply — `budgetAction: "ask"` pauses new dispatches at the
|
|
296
|
+
run ceiling instead of killing the ones that are running.
|
|
297
|
+
- `sessionMode: "session"` records each worker's pi session, so a crash or a
|
|
298
|
+
killed coordinator can be recovered with `/orchestra resume <id>` instead of
|
|
299
|
+
redoing the task. A live process that outlived the coordinator shows as
|
|
300
|
+
`⚡ orphaned` and can still be stopped or resumed.
|
|
301
|
+
- `retries: 1` repairs a failure automatically before you wake up; the retry
|
|
302
|
+
prompt carries the old error.
|
|
303
|
+
|
|
304
|
+
→ [Workers](https://loka1.github.io/pi-orchestra/Workers.html): background work and long jobs.
|
|
305
|
+
|
|
306
|
+
## Budgets, stalls and repair
|
|
307
|
+
|
|
308
|
+
A worker can be expensive or quiet without being stuck, and neither is caught by
|
|
309
|
+
`timeoutMs` alone.
|
|
310
|
+
|
|
311
|
+
```json
|
|
312
|
+
{
|
|
313
|
+
"budgetUsdPerWorker": 2,
|
|
314
|
+
"budgetUsdPerRun": 10,
|
|
315
|
+
"budgetMsPerWorker": 1200000,
|
|
316
|
+
"budgetGraceMs": 60000,
|
|
317
|
+
"stallMs": 600000,
|
|
318
|
+
"stallAction": "notify"
|
|
319
|
+
}
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
- **Cost budget** is checked on every event a worker emits. Crossing it (or the
|
|
323
|
+
run ceiling) stops the worker, marks it `failed` with a `stopNote`, and refuses
|
|
324
|
+
new workers until the run is archived or the ceiling raised. `run_create
|
|
325
|
+
budgetUsd=` and `worker_start budgetUsd=/budgetMs=` override the defaults.
|
|
326
|
+
- **Wall-clock budget** is not a kill switch: at `budgetMsPerWorker` the worker is
|
|
327
|
+
told to wrap up, and only after `budgetGraceMs` is it stopped.
|
|
328
|
+
- **Stall watchdog** flags any live worker with no events for `stallMs`, shows it
|
|
329
|
+
as `⚠ stalled 12m` in the widget, and sends a message. `stallAction: "abort"`
|
|
330
|
+
stops it instead.
|
|
331
|
+
|
|
332
|
+
`budgetAction: "ask"` turns the ceiling into a checkpoint rather than a kill
|
|
333
|
+
switch: live workers finish their step, nothing new starts, the run shows
|
|
334
|
+
`⏸ budget paused`, and `orchestra action=budget usd=<n>` (or `/orchestra budget`)
|
|
335
|
+
raises it and reopens the gate.
|
|
336
|
+
|
|
337
|
+
`retries` (and `worker_start retries=`) re-dispatch a failed worker on its own,
|
|
338
|
+
with exponential backoff; a repair dispatch keeps `attempt`, so the policy stops
|
|
339
|
+
after the budget and never retries a deliberate kill (`stopped`, budget, stall).
|
|
340
|
+
Processes that survive a coordinator restart become `⚡ orphaned` instead of
|
|
341
|
+
`lost`: their pid can still be stopped with `worker_stop`, and `worker_resume`
|
|
342
|
+
continues from the stored session.
|
|
343
|
+
|
|
344
|
+
When a worker fails, `worker_start retryOf=<dispatch>` starts a repair attempt:
|
|
345
|
+
it reuses the spec, agent, tools and model, and leads the prompt with the
|
|
346
|
+
previous status, error, last tool and report so the new worker checks the tree
|
|
347
|
+
before redoing anything. With `sessionMode: "session"`,
|
|
348
|
+
`worker_resume dispatch=<id>` goes further and reopens the *same* session, so
|
|
349
|
+
nothing the worker learned is lost.
|
|
350
|
+
|
|
351
|
+
→ [Configuration](https://loka1.github.io/pi-orchestra/Configuration.html): every setting and default.
|
|
352
|
+
|
|
353
|
+
## Cycles, retention and limits
|
|
354
|
+
|
|
355
|
+
`task_create deps=` and `task_update deps=` refuse a dependency loop and print
|
|
356
|
+
the path (`A -> C -> B -> A`), so a typo cannot silently deadlock a run; a cycle
|
|
357
|
+
that is already on disk is shown as `⊘ blocked` with that note until the graph is
|
|
358
|
+
fixed. `orchestra action=prune days=<n> dryRun=<bool>` (or `/orchestra prune 30`)
|
|
359
|
+
deletes archived run directories and orphaned logs/prompts/mail/exports older
|
|
360
|
+
than the window — live state is never touched.
|
|
361
|
+
|
|
362
|
+
→ [Configuration](https://loka1.github.io/pi-orchestra/Configuration.html): every setting and default.
|
|
363
|
+
|
|
364
|
+
## Split decisions and search
|
|
365
|
+
|
|
366
|
+
`orchestra_send dispatch="*"` (or `/orchestra broadcast <msg>`) delivers one
|
|
367
|
+
message to every live worker and reports per-worker success — the cheap way to
|
|
368
|
+
land a decision that affects three parallel workers.
|
|
369
|
+
|
|
370
|
+
`orchestra action=search filter=…` greps every `.pi/orchestra/logs/*.jsonl`
|
|
371
|
+
(tokens are ANDed), returning dispatch, line number and redacted text;
|
|
372
|
+
`/orchestra grep <text>` prints the same. Secrets never reach the logs in the
|
|
373
|
+
first place: API keys, tokens, JWTs and `password=`-style assignments are
|
|
374
|
+
redacted before a line is appended.
|
|
375
|
+
|
|
376
|
+
→ [Commands](https://loka1.github.io/pi-orchestra/Commands.html): actions and filters.
|
|
377
|
+
|
|
378
|
+
## Metrics and export
|
|
379
|
+
|
|
380
|
+
`orchestra action=metrics` prints the per-worker table, totals, a spend
|
|
381
|
+
sparkline and — when a run with the same template or name exists — a delta line
|
|
382
|
+
(`vs previous squad: +$0.15 cost · +3 turns …`); the run detail pane in the browser shows the same
|
|
383
|
+
under **Cost & turns**. `orchestra action=export` (or `/orchestra export [json]`)
|
|
384
|
+
writes `.pi/orchestra/exports/<runId>.jsonl`: one `run` header line, one `worker`
|
|
385
|
+
line per dispatch (turns, tools, tokens, cost, duration) and one `point` per
|
|
386
|
+
timeline event with cumulative cost and turns.
|
|
387
|
+
|
|
388
|
+
`orchestra action=report` turns the same numbers into a markdown report —
|
|
389
|
+
goal, task table, each worker's report, failures, diff stats and the cost
|
|
390
|
+
regression — and writes it to `.pi/orchestra/exports/<runId>.md`. That is the
|
|
391
|
+
file to paste into a PR.
|
|
392
|
+
|
|
393
|
+
→ [Commands](https://loka1.github.io/pi-orchestra/Commands.html): metrics, export, report.
|
|
394
|
+
|
|
395
|
+
## Templates
|
|
396
|
+
|
|
397
|
+
A run usually starts with the same shape: implement, then review; or split a
|
|
398
|
+
migration across three workers. Put that shape in
|
|
399
|
+
`.pi/orchestra/templates/<name>.md` (or `~/.pi/agent/orchestra/templates/`) and
|
|
400
|
+
create the whole run in one call.
|
|
401
|
+
|
|
402
|
+
```markdown
|
|
403
|
+
# Review squad
|
|
404
|
+
goal: Land a change, then have an independent reviewer check it.
|
|
405
|
+
agent: worker
|
|
406
|
+
|
|
407
|
+
## Implement the change
|
|
408
|
+
spec: Implement the task, run the project's checks, report files and evidence.
|
|
409
|
+
|
|
410
|
+
## Review the change
|
|
411
|
+
deps: Implement the change
|
|
412
|
+
agent: reviewer
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
```text
|
|
416
|
+
/orchestra template review-squad # or: orchestra action=run_create template=review-squad
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
A `## Heading` is a task title; `spec:`, `agent:`, `model:`, `thinking:` and
|
|
420
|
+
`deps:` come from its first lines (deps name earlier task titles), everything
|
|
421
|
+
else becomes the spec. A template with no tasks is ignored, and a missing
|
|
422
|
+
dependency fails with the task that asked for it. `config/templates/` ships a
|
|
423
|
+
ready-made `review-squad.md`.
|
|
424
|
+
|
|
425
|
+
→ [Configuration](https://loka1.github.io/pi-orchestra/Configuration.html): templates and config.
|
|
426
|
+
|
|
427
|
+
## Configuration
|
|
428
|
+
|
|
429
|
+
Merged from JSON files (project wins over global):
|
|
430
|
+
|
|
431
|
+
| File | Scope |
|
|
432
|
+
| --- | --- |
|
|
433
|
+
| `~/.pi/agent/orchestra.json` | Global |
|
|
434
|
+
| `.pi/orchestra.json` | Project-local |
|
|
435
|
+
|
|
436
|
+
```json
|
|
437
|
+
{
|
|
438
|
+
"maxConcurrency": 4,
|
|
439
|
+
"defaultAgent": "worker",
|
|
440
|
+
"inheritModel": true,
|
|
441
|
+
"timeoutMs": 900000,
|
|
442
|
+
"keepOpen": true,
|
|
443
|
+
"notifyOnSettle": true,
|
|
444
|
+
"workerIsolation": true,
|
|
445
|
+
"widgetMaxLines": 8,
|
|
446
|
+
"widgetShowSettled": false,
|
|
447
|
+
"providerExtensions": [],
|
|
448
|
+
"sessionMode": "no-session",
|
|
449
|
+
"budgetUsdPerWorker": 0,
|
|
450
|
+
"budgetUsdPerRun": 0,
|
|
451
|
+
"budgetMsPerWorker": 0,
|
|
452
|
+
"budgetGraceMs": 60000,
|
|
453
|
+
"budgetAction": "stop",
|
|
454
|
+
"stallMs": 600000,
|
|
455
|
+
"stallAction": "notify",
|
|
456
|
+
"retries": 0,
|
|
457
|
+
"retryBackoffMs": 2000,
|
|
458
|
+
"agents": {
|
|
459
|
+
"reviewer": { "model": "deepseek/deepseek-v4.1-flash", "thinking": "high", "tools": ["read", "grep", "ls"] }
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
| Key | Default | Meaning |
|
|
465
|
+
| --- | --- | --- |
|
|
466
|
+
| `maxConcurrency` | `4` | Maximum simultaneously running workers. |
|
|
467
|
+
| `defaultAgent` | `"worker"` | Agent used when a dispatch names none. |
|
|
468
|
+
| `inheritModel` | `true` | Workers inherit the coordinator's model when the agent names none. |
|
|
469
|
+
| `providerExtensions` | `[]` | Extra extension files (or `npm:`/`git:` specs) an isolated worker should load, typically a provider package. Usually discovered automatically. |
|
|
470
|
+
| `timeoutMs` | `900000` | Hard limit per worker; it is stopped (and marked `timeout`) after this. `0` disables it; overridable per dispatch with `worker_start timeoutMs=`. |
|
|
471
|
+
| `timeoutMode` | `"total"` | How `timeoutMs` is measured. `"idle"` restarts the clock on every worker event, so only silence that long stops it — use it for multi-hour jobs. |
|
|
472
|
+
| `keepOpen` | `true` | Keep a settled worker's process alive so `orchestra_send` can talk to it. Set `false` to reap on settle. |
|
|
473
|
+
| `notifyOnSettle` | `true` | Wake the coordinator when a worker settles or asks a question. |
|
|
474
|
+
| `workerIsolation` | `true` | Start workers with `--no-extensions -e <this extension>` (no MCP, no interactive gates). |
|
|
475
|
+
| `sessionMode` | `"no-session"` | `"session"` keeps worker sessions on disk so `worker_resume` can reopen one. |
|
|
476
|
+
| `budgetUsdPerWorker` | `0` | Cost ceiling per worker in USD (0 = off). Overridable per dispatch. |
|
|
477
|
+
| `budgetUsdPerRun` | `0` | Cost ceiling per run (0 = off). Overridable with `run_create budgetUsd=`. |
|
|
478
|
+
| `budgetMsPerWorker` | `0` | Wall-clock budget per worker; wrap-up first, then stop after `budgetGraceMs`. |
|
|
479
|
+
| `budgetGraceMs` | `60000` | Grace period between "wrap up" and the hard stop. |
|
|
480
|
+
| `stallMs` | `600000` | No-event interval that counts as stalled (0 = off). |
|
|
481
|
+
| `stallAction` | `"notify"` | `"abort"` stops a stalled worker instead of only reporting it. |
|
|
482
|
+
| `budgetAction` | `"stop"` | `"ask"` pauses the run at the ceiling instead of stopping workers; raise it with `action=budget`. |
|
|
483
|
+
| `retries` | `0` | Extra attempts after a failed worker (each one gets the failure in its brief). |
|
|
484
|
+
| `retryBackoffMs` | `2000` | Wait before the first retry; doubles per attempt, capped at 5 minutes. |
|
|
485
|
+
| `workerCommand` | *(auto)* | Override the pi executable used for workers. |
|
|
486
|
+
| `stateDir` | `.pi/orchestra` | Where state, logs and prompts live. |
|
|
487
|
+
| `widgetMaxLines` | `8` | Rows in the always-on widget before `+N more` (hint row excluded). |
|
|
488
|
+
| `widgetShowSettled` | `false` | Show settled rows instead of collapsing them into a counter. |
|
|
489
|
+
| `agents` | `{}` | Per-agent overrides of model/thinking/tools. |
|
|
490
|
+
|
|
491
|
+
### Which model does a worker run?
|
|
492
|
+
|
|
493
|
+
A worker gets an explicit `{provider, id}` pair, never a bare slash id: pi reads
|
|
494
|
+
`provider/id` from `--model`, so `--model deepseek/deepseek-v4.1-flash` looks for
|
|
495
|
+
`deepseek-v4.1-flash` *on the `deepseek` provider* and quietly lands on a different
|
|
496
|
+
model.
|
|
497
|
+
|
|
498
|
+
1. `provider`/`model` given to `worker_start`, else
|
|
499
|
+
2. the agent's frontmatter (`provider:`, `model:`) or its `agents.<name>` override, else
|
|
500
|
+
3. the coordinator's model (`inheritModel`).
|
|
501
|
+
|
|
502
|
+
The provider is resolved from the model id against the coordinator's catalogue
|
|
503
|
+
(preferring the coordinator's own provider when an id exists on several). Because
|
|
504
|
+
`workerIsolation` starts the worker with `--no-extensions`, provider *extensions* have to
|
|
505
|
+
be loaded explicitly: orchestration finds the installed package that registers that
|
|
506
|
+
provider (from your pi `packages`) and passes it with `-e`. Nothing extra needs to be
|
|
507
|
+
installed or configured — `providerExtensions` exists for the cases discovery cannot see.
|
|
508
|
+
|
|
509
|
+
Before spawning, a throwaway `pi … --list-models <provider>/<id>` confirms the worker
|
|
510
|
+
really has that model. If it does not, the worker falls back to the **coordinator's**
|
|
511
|
+
model and `modelNote` says so; if that is unavailable too, the dispatch is marked with a
|
|
512
|
+
warning instead of silently running something else. `worker_start`, `worker_show`,
|
|
513
|
+
`worker_read` and the browser all print `(provider) model`.
|
|
514
|
+
|
|
515
|
+
→ [Configuration](https://loka1.github.io/pi-orchestra/Configuration.html): every setting and default.
|
|
516
|
+
|
|
517
|
+
## Agents
|
|
518
|
+
|
|
519
|
+
Workers use the same agent definitions as pi's bundled subagent example — markdown with YAML frontmatter:
|
|
520
|
+
|
|
521
|
+
```markdown
|
|
522
|
+
---
|
|
523
|
+
name: reviewer
|
|
524
|
+
description: Read-only code review
|
|
525
|
+
tools: read, grep, find, ls, bash
|
|
526
|
+
model: deepseek/deepseek-v4.1-flash
|
|
527
|
+
provider: commandcode
|
|
528
|
+
thinking: high
|
|
529
|
+
---
|
|
530
|
+
You review code and report findings ordered by severity. You do not edit files.
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
Locations: `~/.pi/agent/agents/*.md` (user) and `.pi/agents/*.md` (project, overrides by name). The system prompt is appended to the worker's prompt with `--append-system-prompt`, so workers keep pi's full tool behaviour.
|
|
534
|
+
|
|
535
|
+
→ [Configuration](https://loka1.github.io/pi-orchestra/Configuration.html): agent files and overrides.
|
|
536
|
+
|
|
537
|
+
## How it works
|
|
538
|
+
|
|
539
|
+
1. `worker_start` creates a dispatch in `.pi/orchestra/state.json`, writes the agent prompt to `.pi/orchestra/prompts/<id>.md`, and spawns
|
|
540
|
+
`pi --mode rpc --no-session --no-extensions -e orchestra.ts [--model …] [--thinking …] [--tools …]`.
|
|
541
|
+
2. The worker gets a preamble with its task and the `orchestra_ask` tool. It works autonomously.
|
|
542
|
+
3. Its stdout events are appended to `.pi/orchestra/logs/<id>.jsonl`; the coordinator tracks turns, tool calls, tokens and cost from them.
|
|
543
|
+
4. On `agent_settled` the coordinator records the final text, closes the task, refreshes dependents and wakes you with a report.
|
|
544
|
+
5. Questions travel as files under `.pi/orchestra/mail/<dispatch>/`: the worker blocks on `orchestra_ask`, the coordinator polls once a second, surfaces the question, and `orchestra_answer` writes the answer file that unblocks it.
|
|
545
|
+
6. On session shutdown every worker is aborted and stopped (SIGTERM, then SIGKILL after five seconds).
|
|
546
|
+
|
|
547
|
+
No ports, no daemon, no external state store. The only requirement is a working `pi` on `PATH` (or `workerCommand`).
|
|
548
|
+
|
|
549
|
+
→ [Workers](https://loka1.github.io/pi-orchestra/Workers.html): processes, state and logs.
|
|
550
|
+
|
|
551
|
+
## Safety
|
|
552
|
+
|
|
553
|
+
- Workers share your working directory and filesystem. They can edit what you let their tools edit; use agent `tools` to restrict them.
|
|
554
|
+
- Project agents (`.pi/agents/`) are repo-controlled prompts. Only use them in repositories you trust.
|
|
555
|
+
- `workerIsolation` starts workers with only built-in tools and this extension, which also means provider plugins loaded as extensions are not available inside workers. Set `"workerIsolation": false` if a worker needs your full extension stack.
|
|
556
|
+
- A worker dialog (confirm/select) is auto-cancelled because workers are headless; prefer isolated workers or non-interactive extensions.
|
|
557
|
+
|
|
558
|
+
→ [Workers](https://loka1.github.io/pi-orchestra/Workers.html): isolation and prompts.
|
|
559
|
+
|
|
560
|
+
## Documentation
|
|
561
|
+
|
|
562
|
+
- **Docs site:** <https://loka1.github.io/pi-orchestra/> — every page in `wiki/` is built and deployed on each change (Installation, Configuration, Commands, Browsing, Workers).
|
|
563
|
+
- **GitHub wiki:** the same pages are mirrored there once the wiki exists. GitHub only creates `<repo>.wiki.git` when a page is first saved in the web UI — no API call and no push can do it — so the `Sync wiki` workflow validates the pages and warns until that one-time step is done. The docs site does not have that prerequisite.
|
|
564
|
+
|
|
565
|
+
## Limitations
|
|
566
|
+
|
|
567
|
+
- One coordinator per state directory. Two pi sessions sharing `.pi/orchestra/` would fight over `state.json`.
|
|
568
|
+
- A worker whose process died while the coordinator was down is marked `lost`; a process that outlived the coordinator is `orphaned` — still alive, stoppable and resumable.
|
|
569
|
+
- No git-worktree isolation yet: workers run in the coordinator's cwd.
|
|
570
|
+
- Worker usage is reported in its dispatch, but is not added to the coordinator's own cost totals.
|
|
571
|
+
|
|
572
|
+
## More pi packages
|
|
573
|
+
|
|
574
|
+
Focused, single-purpose extensions from the same author. Each installs on its own:
|
|
575
|
+
|
|
576
|
+
| Package | What it does |
|
|
577
|
+
| --- | --- |
|
|
578
|
+
| **[pi-orchestra](https://github.com/loka1/pi-orchestra)** — this package | Orchestrate worker agents from one session: runs, tasks, dispatches, questions and gates.<br>`pi install npm:@loka1/pi-orchestra` |
|
|
579
|
+
| **[pi-auto-compact](https://github.com/loka1/pi-auto-compact)** | Auto-compact the context at a configurable % used, globally or per model, with a status-bar indicator.<br>`pi install npm:@loka1/pi-auto-compact` |
|
|
580
|
+
|
|
581
|
+
Browse all pi packages: <https://github.com/loka1?tab=repositories&q=pi-&type=source>
|
|
582
|
+
|
|
583
|
+
## License
|
|
584
|
+
|
|
585
|
+
MIT
|