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