@mu-crew/mu 1.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.
@@ -0,0 +1,369 @@
1
+ ---
2
+ name: mu
3
+ description: Manage AI agents in terminal-multiplexer panes (tmux or herdr) — from a single off-the-cuff helper to a persistent crew coordinated through a built-in task graph. Use when the user asks to "create/spin up a subagent to X", "run X in the background", "do this in parallel", "use one subagent per X to do Y", "kick off a helper to watch/investigate/draft X", or to spawn, send work to, observe, or coordinate one or many agents — especially work you'll keep talking to, long-lived agents, background tasks, or anything that benefits from a dependency graph and parallel-track detection. For zero-ceremony single helpers use the reserved `scratch` workstream; for one-shot "fire and get a result back" prefer pi-subagents.
4
+ ---
5
+
6
+ # mu — Multi-agent orchestration
7
+
8
+ `mu` manages long-lived AI agents in multiplexer panes (tmux or
9
+ herdr), coordinated by a SQLite task DAG at
10
+ `<XDG_STATE_HOME or ~/.local/state>/mu/mu.db`.
11
+
12
+ **Trust `mu --help` / `mu <verb> --help` over this skill.** Verbs
13
+ not in `--help` do not exist.
14
+
15
+ ## Output + JSON shapes
16
+
17
+ Default output: textual card on stdout plus a `Next:` block. Read
18
+ both. `--json` exists on every verb:
19
+ - Success: one stdout object.
20
+ - Collection reads (`task list`, `workspace commits`, ...): `{items: T[], count: number}`.
21
+ - Singletons keep named fields.
22
+ - `mu sql --json`: bare array rows.
23
+ - `mu log --tail`: NDJSON (one object per line).
24
+ - Errors: `{error,message,nextSteps,exitCode}` on stderr.
25
+ - Validation errors also include structured `usage`.
26
+ - **`nextSteps` survives in JSON.**
27
+
28
+ ## Vocabulary
29
+
30
+ - **workstream** — unit of organization; one **mux session** named
31
+ `mu-<name>` (a tmux session, or a herdr workspace).
32
+ - **agent** — named worker in a pane (you may be one).
33
+ - **mux** — the multiplexer mu drives: tmux, or herdr. One per
34
+ invocation. `mu doctor` names the active one; `MU_MUX` forces it.
35
+ Spawn, send, read, and status detection work on both; `mu agent
36
+ kick` is herdr's remaining gap (Linux-only there).
37
+ - **task** — DAG node with mandatory `impact` (1–100) and
38
+ `effort_days`. Status: `OPEN`, `IN_PROGRESS`, `CLOSED`
39
+ (satisfies `--blocked-by`). Record postponed/wont-do rationale as
40
+ task notes; close the task to satisfy blockers.
41
+ - **claim / release** — atomic take/clear of `tasks.owner`.
42
+ - **note** — append-only task context; survives sessions.
43
+ - **track** — independent DAG subtree; don't spawn more agents than
44
+ ready tracks.
45
+ - **workspace** — per-agent VCS copy under
46
+ `<state-dir>/workspaces/<workstream>/<agent>/`.
47
+
48
+ ## When to use mu
49
+
50
+ Use mu for persistent helpers, parallel work, dependencies, gated review, or
51
+ work that must survive context compaction. Use `pi-subagents` for one focused
52
+ answer and no follow-up; stay in one context for tiny edits or inspection.
53
+
54
+ ### Off-the-cuff helpers (`scratch`)
55
+
56
+ Use the reserved `scratch` workstream for a helper you will keep driving but
57
+ that needs no task DAG. It auto-creates on spawn.
58
+
59
+ - For task-less work, `mu agent wait <name> --first` waits for busy → idle;
60
+ exit 0 means met, 5 timeout, 6 pane died.
61
+ - For a watcher, persist last-seen state in a log ledger: write `mu log -w
62
+ scratch --kind pr-state 'pr=1234 sha=abc ci=red'`, then read `mu log -w
63
+ scratch --kind pr-state -n 1 --json`. Act only on change; chat context is not
64
+ durable.
65
+ - Use one agent per independent unit and `--workspace` for any helper that may
66
+ edit, build, or test the shared repo.
67
+
68
+ A helper stuck at `needs_input` immediately after spawn likely hit pi's project
69
+ trust prompt. Add `--approve` to the existing `MU_<CLI>_COMMAND`; use
70
+ `--command` only to replace that configured command deliberately.
71
+
72
+ Move off `scratch` when work gains dependencies or review gates.
73
+
74
+ ## Mental model
75
+
76
+ ### Workstreams, DAGs, tracks
77
+
78
+ One workstream is one mux session and DB partition. Its task DAG has one edge:
79
+ `mu task block A --by B` means **B blocks A**. Parallel tracks sharing a
80
+ prerequisite collapse, preventing two agents from taking the same dependency.
81
+
82
+ ### Workspaces prevent trampling
83
+
84
+ If an agent may edit/build/test while another agent is active in the
85
+ same repo, spawn with `--workspace`. Keep the main checkout for
86
+ orchestration: two builds in one checkout corrupt each other.
87
+
88
+ Workspaces auto-detect jj/sl/git; non-VCS uses `cp -a`. They are
89
+ auto-freed on `mu agent close` **iff clean**: no uncommitted changes
90
+ and no commits since fork. Non-clean close fails with
91
+ `WorkspacePreservedError`; then use `mu workspace free <agent>` or
92
+ `mu agent close <agent> --discard-workspace` (lossy).
93
+
94
+ Between waves, `mu workspace refresh <agent>` rebases onto fresh main without
95
+ killing LLM context. Claim/send warn at ≥10 commits behind; scripts can make
96
+ that a refusal with `--strict-staleness`.
97
+
98
+ ### Remote agents
99
+
100
+ Agents can run on another machine: the PANE is local, the PROCESS is
101
+ remote (`--command 'ssh <host> -t "..."'`), so `send`, `read`, status
102
+ detection and the reaper all keep working unchanged. **One orchestrator
103
+ DB; panes may be remote** — never run a second mu on the host, since
104
+ `tasks.owner_id` is an FK into the machine-local `agents` table and a
105
+ remote mu could not claim your tasks anyway. You create the remote
106
+ workspace yourself (`--workspace` is local-only).
107
+
108
+ **Read [REMOTE_WORKERS.md](REMOTE_WORKERS.md) before spawning your first
109
+ remote agent, and again before waiting on one; poll once per turn and run
110
+ the claim's one-shot `Next:` command.** These are the other three traps
111
+ that cost real time when learned late:
112
+ - **On a session-capped host, route long commands and silent-failure
113
+ polls through [mule](https://github.com/mu-crew/mule).** A refused
114
+ bare `rev-parse` can return an empty sha that looks like progress;
115
+ batch all workers in one `--max-secs`-bounded mule job.
116
+ - **`mule` exit 3 is a HANDBACK** — no ssh master, and opening one can
117
+ need a human to touch a hardware key. Ask the operator; never retry,
118
+ never run `ssh -MNf` yourself, never fall back to `ssh <host> <cmd>`.
119
+ - **Exit 4 and 6 mean wait again; 5 means never.** Neither says the work
120
+ failed.
121
+
122
+ ### Agent names
123
+
124
+ Use roles: `worker-1`, `worker-2`, `reviewer-1`, `scout-1`,
125
+ `auditor-1`, `planner-1`. Smallest unused suffix. Avoid human names.
126
+
127
+ ### Task note contract
128
+
129
+ End every delegated task with a note containing the applicable
130
+ fields:
131
+
132
+ ```text
133
+ FILES: paths inspected/changed (line ranges if precise)
134
+ COMMANDS: commands run + exit codes
135
+ FINDINGS: what you observed
136
+ DECISION: what you chose, and why
137
+ NEXT: follow-on tasks
138
+ VERIFIED: tests/checks/output
139
+ ODDITIES: weird things not acted on
140
+ ```
141
+
142
+ Then close with grounding:
143
+
144
+ ```bash
145
+ mu task close <id> -w <ws> --evidence "tests pass: cargo test exit 0"
146
+ ```
147
+
148
+ Future agents can reconstruct context via `mu task notes <id>`.
149
+
150
+ ## Orchestrator loop
151
+
152
+ Every turn:
153
+
154
+ 1. `mu state -w <ws>` — read agents, IN_PROGRESS, ready tasks,
155
+ parallel tracks.
156
+ 2. Spawn at most one agent per independent ready track.
157
+ 3. **Claim before sending — even one-shot reviewers/scouts.**
158
+ `mu task claim <id> -w <ws> --for <agent> --evidence "..."`.
159
+ If no task exists, `mu task add` first; include initial context with
160
+ `--note 'REPRO: ...\nSCOPE: ...'` when the title alone is not
161
+ enough. Agent status is noisy; task ownership is durable and
162
+ waitable.
163
+ 4. Send terse instructions: task id, files/notes to read, workspace
164
+ path, validation command, scope guards, task note contract.
165
+ 5. End with a loud final-action block:
166
+
167
+ ```text
168
+ ⚠️ FINAL ACTION
169
+ git commit -am '...' THEN
170
+ mu task close <id> -w <ws> --evidence '...'
171
+ ```
172
+
173
+ 6. `mu task wait ... --first --on-stall exit --json`.
174
+ 7. Cherry-pick the closed worker's **new** commit(s), verify the MERGE
175
+ (see below), return control. Do not barrier or loop in shell.
176
+ 8. Repeat from `mu state`.
177
+
178
+ ## Dispatch rules that prevent real failures
179
+
180
+ - **Pipeline; don't barrier.** Wait for one task, cherry-pick only its new
181
+ commits onto main, verify the combined tree, then return control. Waiting on an
182
+ umbrella task hides partial progress; merging stale branches can restore
183
+ reverted code.
184
+ - **Verify the merge, not the worker's rerun.** The worker tested against its
185
+ fork point; only the combination with moved main is new. This found three
186
+ integration breaks where rerunning worker suites found none. For remote work,
187
+ run the merged gate on the host with warm dependencies: 500s × 30 integrations
188
+ is four laptop-hours. Keep platform-sensitive checks and the final release gate
189
+ local; macOS `ps` once exposed a bug Linux could not.
190
+ - **Push only from a green gate.** Script the gate so `git push` is its last
191
+ line under `set -e`; a chain that printed a failure and pushed anyway put a red
192
+ commit on main. Check the gate runs what it claims: a randomized test gated on
193
+ an env var passed with zero cases.
194
+ - **Dispatch from current main.** Reset the worker's worktree to main before each
195
+ task. Stale bases caused four merges that conflicted or broke tests after
196
+ passing in the worker.
197
+ - **Accept evidence, not close notes.** Re-run the key measurement from a clean
198
+ checkout. Close notes have claimed unpushed commits and reported numbers from
199
+ a half-edited clone.
200
+ - **Freeze only what conflicts.** While one task owns shared files, give idle
201
+ workers tasks that avoid them; a blanket freeze idled four of five workers for
202
+ a day.
203
+ - **Fix done before a long run.** Put the completion criterion in the task note
204
+ first: which checks, how many agreeing runs, what may differ. Without it the
205
+ target moves with every run.
206
+ - **Split long proofs into independent units**, sharded and in parallel, so a
207
+ unit that passes stays passed and one flake restarts only its own unit.
208
+ Workers poll background jobs every few minutes, not hourly.
209
+ - Bucket waves by file cluster, not severity; two agents editing one file
210
+ conflict. Refresh workspaces between waves.
211
+ - Cross-workstream wait/claim uses qualified refs. The owner stays in its own
212
+ workstream; only task ownership crosses.
213
+ - For an idle worker, inspect scrollback, then send a retry or release its task.
214
+ `MU_IDLE_THRESHOLD_MS` defaults to 5m.
215
+ - `mu agent kick` targets a wedged foreground subprocess. It refuses to signal
216
+ the wrapping CLI; close the agent if that is what must stop.
217
+ - Use `mu agent send`, not raw mux input: mu preserves literal text and confirms
218
+ submission. Single-quote prompts containing shell expansions, or use a quoted
219
+ heredoc.
220
+
221
+ ## CLI gotchas
222
+
223
+ - **`workstream teardown`** is dry-run by default; `--yes` commits. It writes
224
+ TOMBSTONE ops, so history survives and `mu undo <group> --yes` reverses the
225
+ deletions — do NOT `mu db backup` first, the log IS the backup.
226
+ `workstream list --torn-down` replays past teardowns with the group id to
227
+ undo, newest first, marking ones already recreated.
228
+ - **`agent wait <names...> --first`** blocks until an agent stops working
229
+ (busy → anything else) — the task-less counterpart to `mu task wait`, for
230
+ helpers that own no task. Use it instead of a `sleep` loop. Exit 0 met,
231
+ 5 timeout, 6 pane died.
232
+ - **`task close --if-ready`** no-ops until every blocker is CLOSED; bare
233
+ `task release` reopens IN_PROGRESS.
234
+ - **For waits use `task wait`, not `log --tail`.** `--kind` is the operator's
235
+ log-ledger channel; `--intent` is what mu recorded.
236
+ - **`mu undo`** bare lists undoable actions with group ids; `<group>` previews;
237
+ `<group> --yes` applies. It emits INVERSE ops for that one group, so it
238
+ touches nothing else, and the undo is itself an op — REDO is
239
+ `mu undo <that group> --yes`. Refuses with exit 4 if a later action changed
240
+ the same fields (`--force` discards that newer work). Rows only: killed panes
241
+ and freed workspace dirs do not come back. No snapshots, no `--to`.
242
+ - **`mu rebuild <file>`** writes a NEW DB from the ops log. Agents and
243
+ workspaces are absent because they have no captured ops; re-spawn after swap.
244
+ - **`mu sql`** alone skips ambient sync, preserving no-surprise mutations.
245
+ - **`mu db backup`** is a convenient copy; real recovery is `mu rebuild`.
246
+ - **Sync (laptop ↔ devserver):** `export MU_SYNC_DIR=$HOME/Sync/mu` on each
247
+ machine pointing at a shared folder (Syncthing recommended). Every command
248
+ then flushes your ops and ingests peers' — ambient, no daemon — so a bare
249
+ `mu task list` on the other box already shows what you added here. Merge is
250
+ per-FIELD, so two machines editing different fields of one task both keep
251
+ their edit. `mu sync` bare reports peer status plus a copy-pasteable rsync
252
+ line; mu never runs ssh/scp/rsync itself. `--from <peer-mu.db>` reads a
253
+ peer's ops directly; `--repair <peer>` re-reads from zero and is always safe
254
+ (ingest is idempotent).
255
+ **NEVER put `MU_DB_PATH` inside `MU_SYNC_DIR`** — it corrupts the DB and
256
+ `mu doctor` hard-fails. Agent/workspace state and task OWNERSHIP are
257
+ machine-local and never travel.
258
+ - **`mu doctor`** runs fast checks; `--deep` rebuilds the log into a temp DB and
259
+ diffs it field-by-field. DRIFT means the log and the tables disagree, which
260
+ breaks undo and sync at once (exit 5, naming table, key and field). It is a
261
+ capture bug, not operator error: back up and report it, do NOT reflexively
262
+ rebuild — if capture missed a mutation, the live rows hold the real work.
263
+ The `disk` section reconciles state-dir against DB both ways and is
264
+ **report-only**: `ws-rows` is a row whose directory is gone (nothing else
265
+ reports it), `ws-dirs` blocks the next `--workspace` spawn, and an orphan dir
266
+ may hold the only copy of uncommitted work — which is why mu prints the
267
+ cleanup command and runs none of them. `--disk` adds per-checkout byte usage.
268
+
269
+ ## `mu task wait`
270
+
271
+ Use `--first --on-stall exit`: `--first` populates `.firing`, and
272
+ `--on-stall exit` prevents unattended waits from polling forever when a worker
273
+ needs attention. Exit 6 means a dead pane; exit 7 means the owner sat in
274
+ `needs_input`. Read that pane (`mu agent read <owner>`) before acting: the
275
+ worker may be waiting on an answer from you, not merely forgetting to close.
276
+ Answer it — questions are cheaper than rework. For remote workers, see
277
+ [REMOTE_WORKERS.md](REMOTE_WORKERS.md) before choosing timeout or stall
278
+ handling.
279
+
280
+ ## Models and thinking effort
281
+
282
+ mu doesn't reason about models; pi does. Controls:
283
+
284
+ ```bash
285
+ mu agent spawn r --command "pi --model opus:high"
286
+ export MU_PI_COMMAND="pi --model sonnet:medium"
287
+ mu agent spawn a --cli pi_big # uses $MU_PI_BIG_COMMAND
288
+ ```
289
+
290
+ Convention: `pi_mini` / `pi` / `pi_big`. Use mini for probing,
291
+ modest for build/edit/refactor, big for design/review/incidents.
292
+ Discover model strings with `pi --list-models [fuzzy-search]`.
293
+
294
+ ## Reaper and status limits
295
+
296
+ If an agent pane dies, or `mu agent close` kills it mid-task, owned
297
+ IN_PROGRESS tasks revert to OPEN with a `[reaper]` note and `task
298
+ reap` op. No manual release after crashes.
299
+
300
+ Status detection is heuristic and can lag behind custom `--command`
301
+ wrappers. It is weakest for a remote worker, where the scrollback is a
302
+ nested tmux rendered over ssh.
303
+
304
+ **[murmur](https://github.com/mu-crew/murmur), if installed, is
305
+ authoritative there** — its extension pushes state from inside the agent
306
+ on the host rather than scraping a pane, and it answers across machines.
307
+ Optional and strictly additive: nothing here needs it, and the seam is
308
+ the env vars `mu agent spawn` already injects (`MU_MANAGED_AGENT`,
309
+ `MU_AGENT_NAME`, `MU_WORKSTREAM`), which murmur reads to mark a pane as
310
+ crew. **mu owns the work; murmur owns what an agent is doing.** See
311
+ [REMOTE_WORKERS.md](REMOTE_WORKERS.md) § mu and murmur.
312
+
313
+ For high-stakes decisions:
314
+
315
+ ```bash
316
+ mu agent read worker-1 -n 100
317
+ mu log -w <ws> --tail
318
+ mu task notes <id>
319
+ ```
320
+
321
+ ## In-pane worker loop
322
+
323
+ `$MU_AGENT_NAME`, injected at spawn, resolves identity; the pane title
324
+ is the fallback that adopted panes need. Env-first means this loop is
325
+ identical whichever multiplexer you are in — you never need to know.
326
+
327
+ - Worker pane: spawned/adopted by mu; bare `mu task claim <id>` works.
328
+ - Orchestrator pane: not registered; bare `claim` errors with next
329
+ steps: `--self`, `--for <worker>`, or `mu agent adopt <pane>`.
330
+
331
+ ```bash
332
+ mu me
333
+ mu me next
334
+ mu task show <id>; mu task notes <id>
335
+ mu task claim <id> --evidence "starting; read notes"
336
+ mu task note <id> "FILES: ...\nDECISION: ...\nVERIFIED: ..."
337
+ mu task close <id> --evidence "tests pass: ..." # LAST action
338
+ ```
339
+
340
+ Skipping close makes the orchestrator's wait hang.
341
+
342
+ ## Follow-on prompts
343
+
344
+ A new `mu agent send` appends to prior LLM context. For unrelated
345
+ work, clear first (`/new` for pi/claude-code; `/clear` for codex):
346
+
347
+ ```bash
348
+ mu agent send worker-1 '/new'
349
+ mu agent send worker-1 'Claim and work on task_x. Read notes first...'
350
+ ```
351
+
352
+ No `sleep` needed. `mu agent send` waits for the pane to finish any
353
+ re-initialisation before pasting, and re-submits if the TUI swallowed
354
+ the Enter. If a send cannot be confirmed it prints a `warning:` to
355
+ stderr naming the pane; exit 0 with no warning means submitted.
356
+
357
+ Budget is `MU_SEND_READINESS_MS` (default 15000; 0 = fire-and-forget).
358
+ Sending to a BUSY agent is not delayed — that input queues normally.
359
+
360
+ ## Guardrails
361
+
362
+ Task ownership outranks scraped status. Coordinate through task notes and the
363
+ activity log. Keep edges within one workstream, role-name agents, and reserve
364
+ the `mu_` task-id prefix. Give workers bounded paths and commands; use `mu
365
+ agent kick` if a subprocess wedges.
366
+
367
+ ## See also
368
+
369
+ - `mu --help`, `mu <verb> --help` — canonical CLI reference.