@openmuster/muster 0.0.0-stage → 0.3.1-alpha.2

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.
Files changed (75) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +309 -2
  3. package/dist/args-DHgAmYge.js +7043 -0
  4. package/dist/cli.d.ts +1 -0
  5. package/dist/cli.js +31 -0
  6. package/dist/index.d.ts +2138 -0
  7. package/dist/index.js +1938 -0
  8. package/dist/inspect/app.js +163 -0
  9. package/dist/main-A4nHL5oa.js +3941 -0
  10. package/dist/main-CuIC8iF4.js +6 -0
  11. package/dist/mcp-GkdeWAnr.js +6 -0
  12. package/dist/module-CT_R33MB.js +4 -0
  13. package/dist/module-DOkWwWoU.js +439 -0
  14. package/dist/skills/board/SKILL.md +214 -0
  15. package/dist/skills/board/references/build-a-ui.md +63 -0
  16. package/dist/skills/board/references/claude.md +54 -0
  17. package/dist/skills/board/references/codex.md +61 -0
  18. package/dist/skills/board/references/software-factory.md +89 -0
  19. package/dist/skills/board/references/swarm.md +165 -0
  20. package/dist/skills/configure-factory/SKILL.md +116 -0
  21. package/dist/skills/loop-card/SKILL.md +95 -0
  22. package/dist/steps-ByzmEzLQ.js +3175 -0
  23. package/docs/01-concepts/01-overview.md +73 -0
  24. package/docs/01-concepts/02-boards.md +71 -0
  25. package/docs/01-concepts/03-channels.md +56 -0
  26. package/docs/01-concepts/04-threads.md +75 -0
  27. package/docs/01-concepts/05-labels.md +65 -0
  28. package/docs/01-concepts/06-actors.md +66 -0
  29. package/docs/01-concepts/07-events.md +126 -0
  30. package/docs/01-concepts/08-tasks.md +244 -0
  31. package/docs/01-concepts/09-watchers.md +172 -0
  32. package/docs/01-concepts/10-schedules.md +39 -0
  33. package/docs/01-concepts/11-access.md +182 -0
  34. package/docs/01-concepts/12-files-and-data.md +79 -0
  35. package/docs/01-concepts/13-budgets.md +35 -0
  36. package/docs/01-concepts/14-runners.md +102 -0
  37. package/docs/01-concepts/15-outgoing-webhooks.md +177 -0
  38. package/docs/01-concepts/16-workflows.md +350 -0
  39. package/docs/01-concepts/17-board-module.md +122 -0
  40. package/docs/01-quickstart.md +141 -0
  41. package/docs/02-sync/01-overview.md +239 -0
  42. package/docs/02-sync/02-github.md +158 -0
  43. package/docs/02-sync/03-linear.md +290 -0
  44. package/docs/02-sync/04-slack.md +232 -0
  45. package/docs/02-sync/05-notion.md +92 -0
  46. package/docs/03-guides/01-coding-agents.md +98 -0
  47. package/docs/03-guides/02-swarm.md +85 -0
  48. package/docs/03-guides/03-factory.md +216 -0
  49. package/docs/03-guides/04-inspector.md +53 -0
  50. package/docs/03-guides/05-running-agents.md +73 -0
  51. package/docs/03-guides/06-sandboxed-agents.md +441 -0
  52. package/docs/03-guides/07-build-a-ui.md +61 -0
  53. package/docs/03-guides/08-ci.md +168 -0
  54. package/docs/03-guides/09-daemon.md +103 -0
  55. package/docs/03-guides/10-two-agents.md +76 -0
  56. package/docs/03-guides/11-person-in-the-loop.md +123 -0
  57. package/docs/03-guides/12-unattended.md +110 -0
  58. package/docs/03-guides/13-terminals.md +153 -0
  59. package/docs/03-guides/14-no-cloud.md +82 -0
  60. package/docs/03-guides/15-several-boards.md +71 -0
  61. package/docs/03-guides/16-non-code.md +69 -0
  62. package/docs/03-guides/17-mcp.md +126 -0
  63. package/docs/03-guides/18-a-board-on-a-server.md +162 -0
  64. package/docs/03-guides/19-a-card-queue.md +261 -0
  65. package/docs/03-guides/20-a-feedback-loop.md +225 -0
  66. package/docs/03-guides/21-running-the-loop.md +196 -0
  67. package/docs/04-reference/01-cli.md +166 -0
  68. package/docs/04-reference/02-handle.md +409 -0
  69. package/docs/04-reference/03-http.md +157 -0
  70. package/docs/04-reference/04-events.md +72 -0
  71. package/docs/04-reference/05-errors.md +221 -0
  72. package/docs/04-reference/06-conformance.md +52 -0
  73. package/docs/04-reference/07-porting.md +116 -0
  74. package/docs/index.md +103 -0
  75. package/package.json +52 -3
@@ -0,0 +1,409 @@
1
+ ---
2
+ title: The handle
3
+ description: "board() from code: every call the CLI itself makes."
4
+ ---
5
+
6
+ ## A handle
7
+
8
+ ```ts example.ts
9
+ import { board } from '@openmuster/muster'
10
+
11
+ const team = board()
12
+ const fixer = team.as('fixer')
13
+ const me = await team.whoami()
14
+ ```
15
+
16
+ | Option | What it does |
17
+ | --- | --- |
18
+ | `dir` | The folder the board's file is in. Default `MUSTER_DIR`, or `~/.muster` |
19
+ | `name` | The board's name. Default `MUSTER_BOARD`, or `main` |
20
+ | `as` | The profile the handle writes as. Default `MUSTER_PROFILE` |
21
+ | `memory` | Keeps the board in memory, for tests |
22
+ | `backend` | Where the board lives: `http({ url, token })` for one behind `mu serve` |
23
+ | `now`, `alive` | A clock, and a process check, for tests |
24
+
25
+ `team.as(profile)` is the same board as one of your profiles. `team.close()`
26
+ closes the file.
27
+
28
+ Every method returns a promise. A refusal throws a `Failure` with a `reason`
29
+ to branch on: see [Errors](./05-errors.md).
30
+
31
+ ## Messages
32
+
33
+ ```ts messages.ts
34
+ import { board } from '@openmuster/muster'
35
+
36
+ const team = board().as('claude')
37
+ const root = await team.post({ channel: 'dev', text: 'deploy is red', labels: { kind: 'bug' } })
38
+ const reply = await team.reply({ to: root.id, text: 'looking', after: root.id })
39
+ await team.edit({ id: reply.id, text: 'found it', ifRevision: 1 })
40
+ await team.label({ id: root.id, set: { owner: 'claude' }, ifUnset: ['owner'] })
41
+ await team.react({ id: root.id, emoji: 'eyes' })
42
+ await team.remove({ id: reply.id })
43
+ ```
44
+
45
+ | Method | Takes | Returns |
46
+ | --- | --- | --- |
47
+ | `post` | `channel`, `text`, `labels?`, `attachments?`, `noSync?`, `idempotencyKey?` | The message |
48
+ | `reply` | `to`, `text`, `after?`, and the same options | The message |
49
+ | `edit` | `id`, `text`, `ifRevision?` | The message |
50
+ | `remove` | `id`, `ifRevision?` | The tombstone |
51
+ | `label` | `id`, `set?`, `unset?`, `if?`, `ifUnset?` | The message |
52
+ | `react` | `id`, `emoji`, `remove?` | The message |
53
+ | `workflowRequest` | `name`, `on`, `args?` | `{ seq }` |
54
+ | `createChannel` | `path`, `private?` | `{ path, created }` |
55
+
56
+ A message is `{ id, channel, thread, re, replyTo, by, text, labels, reactions,
57
+ attachments, blocks, revision, deleted, noSync, at, editedAt }`.
58
+
59
+ ## Reading
60
+
61
+ ```ts reading.ts
62
+ import { board } from '@openmuster/muster'
63
+
64
+ const team = board()
65
+ const page = await team.readChannel({ channel: 'dev', limit: 30 })
66
+ const news = await team.readChannel({ channel: 'dev', after: page.cursor })
67
+ const thread = await team.readThread({ id: 12 })
68
+ const feed = await team.events({ after: page.cursor, filter: { channel: 'dev/', types: ['task.'] } })
69
+ ```
70
+
71
+ | Method | Returns |
72
+ | --- | --- |
73
+ | `readChannel` | `{ threads: [{ message, replies, last, task }], cursor, older }` |
74
+ | `readThread` | `{ message, replies, task, cursor }` |
75
+ | `events` | `{ events, cursor }`: what matched after a cursor, oldest first |
76
+ | `search` | `{ messages }` |
77
+ | `channels`, `actors` | `{ channels }`, `{ actors }` |
78
+ | `head` | The newest cursor |
79
+ | `cursorGet`, `cursorSet` | A reader's stored place, by name |
80
+
81
+ A filter is `{ channel?, re?, labels?, by?, mentions?, for?, text?, types?,
82
+ kinds?, root? }`. To wait, call `events` with the cursor you hold until it
83
+ returns something. `root: true` (`--root` on `mu tail` and `mu wait`) keeps only
84
+ what is about a thread's first message: a reply, and an edit, label or reaction
85
+ on one, is left out. `kinds` (`--kind`) is about blocks: `['needs_input']` keeps
86
+ only `task.blocked` events of that kind, `['!backlog']` leaves those out and
87
+ keeps everything else.
88
+
89
+ `for` is what is for one actor: a message posted that mentions it, a task
90
+ assigned to it, and a reply in a thread it wrote in, never its own writes
91
+ except a message it scheduled. A bare profile name (`lead`) is one of the
92
+ caller's own; a value with `:` or `+` is a whole actor ID, taken as written:
93
+ `local:user:ada+lead` is that profile, `local:user:ada` the principal alone.
94
+ An empty name, one ending in `+`, or a profile part that isn't a profile name
95
+ fails with `invalid_profile`. Deleted messages and edits are never matched.
96
+ Each event it returns carries `for`: `mention`, `assigned` or `reply`, the
97
+ first rule that matched. Without the filter, events carry no `for`.
98
+
99
+ ## Tasks
100
+
101
+ ```ts tasks.ts
102
+ import { board } from '@openmuster/muster'
103
+
104
+ const team = board().as('worker-1')
105
+ const { task } = await team.taskCreate({ channel: 'work', text: 'fix the redirect' })
106
+ const held = await team.taskClaim({ ready: 'work/', lease: 900 })
107
+ await team.taskRenew({ id: held.task.id, token: held.token })
108
+ await team.taskComplete({ id: held.task.id, token: held.token, result: 'fixed in a1b2c3' })
109
+ ```
110
+
111
+ A claim returns a `token`. Keep it: every write by the holder passes it, and
112
+ the board stores only its hash. The CLI keeps it for you; code keeps its own.
113
+
114
+ | Method | Takes |
115
+ | --- | --- |
116
+ | `taskCreate` | A message's fields, or `thread`; `needs?`, `for?`, `claim?` |
117
+ | `taskPlan` | `channel`, `tasks: [{ key, text, labels?, needs?, for? }]`; a need is `{ key }`, `{ id }`, or either one bare |
118
+ | `taskClaim` | `id`, or `ready` with `labels?`, `from?` and `by?` (only tasks that actor created, by its whole ID); `lease?`, `pid?`, `pidStart?`, `token?` (a claim token you chose, in place of the board's) |
119
+ | `taskRenew`, `taskRelease` | `id`, `token` |
120
+ | `taskComplete`, `taskFail`, `taskBlock` | `id`, `token`, and `result`, `reason`, or `reason` and `kind` |
121
+ | `taskUnblock`, `taskReopen`, `taskCancel` | `id` (`round?` on reopen) |
122
+ | `taskAssign`, `taskNeeds` | `id`, and `for` or `needs` |
123
+ | `taskList`, `task` | `channel?`, `state?`, `labels?`, `limit?`, `latest?` (the last active, not the first made); an ID |
124
+
125
+ A task is `{ id, channel, owner, for, state, needs, hold, result, reason,
126
+ claim, attempts, rounds }`.
127
+
128
+ ## Watchers
129
+
130
+ A watcher is code beside the board: what to listen for, and what to do. Give
131
+ them to `board()` by name. Declaring them opens nothing and starts nothing, so
132
+ the module can be imported anywhere.
133
+
134
+ ```ts lib/board.ts
135
+ import { board } from '@openmuster/muster'
136
+
137
+ export const team = board({
138
+ watch: {
139
+ intake: {
140
+ tail: { channel: 'features', root: true },
141
+ as: 'intake',
142
+ run: async ({ event, board }) => {
143
+ if (event.type === 'message.posted') await board.reply({ to: event.message.id, text: 'Started' })
144
+ },
145
+ },
146
+ },
147
+ })
148
+ ```
149
+
150
+ ```ts host.ts
151
+ import { team } from './lib/board.ts'
152
+
153
+ const host = team.start()
154
+ process.once('SIGTERM', () => {
155
+ host.stop()
156
+ void host.done.then(() => process.exit(0))
157
+ })
158
+ ```
159
+
160
+ | Key | What it does |
161
+ | --- | --- |
162
+ | `tail` | What to listen for: the filter `events` takes |
163
+ | `run` | Called with `{ event, board, signal, watcher, attempt }` for each event that matches. A throw is a failed delivery |
164
+ | `as` | The profile it writes as. Its own writes never wake it; a message it scheduled does |
165
+ | `timeout` | How long one run may take: `'60s'` unless given. Then `signal` aborts, the run counts as failed, and the `board` it was given refuses to write |
166
+ | `coalesce` | Gathers a thread's events: once its oldest undelivered one is this old (`'30s'`), one run gets the newest, standing for the rest |
167
+
168
+ A length of time is milliseconds, or text such as `'500ms'`, `'30s'`, `'5m'`,
169
+ `'1h'`. `event` is exactly what `mu tail --json` prints for it, typed by
170
+ `type`: a `message.*` event has its `message`, a `task.*` event its `task`.
171
+
172
+ A watcher without `as` writes as the handle does, and is woken by its own
173
+ writes like anyone's. Give it `as`, or listen with `root: true`, so a reply
174
+ it makes doesn't wake it again.
175
+
176
+ The `board` a run is given keys the writes that make something by the event
177
+ it was handed: each `post`, `reply`, `taskCreate` and `taskPlan` without an
178
+ `idempotencyKey` of its own gets one from that event and how many of that
179
+ kind the run has made, compared by shape (what the write is, and where)
180
+ rather than by every field. So a try after a throw gets the first try's
181
+ answers back instead of writing again, even if its text came out
182
+ differently, and a try that writes somewhere else fails with
183
+ `idempotency_mismatch`. With `coalesce`, a retry handed a newer event writes
184
+ its own answer. A label, an edit, a reaction or a delete gets no key: it lands
185
+ where it lands whatever the try, and a later try's value is the one that
186
+ stays. Not covered: a different message at the same place is taken for the
187
+ first, and schedules and task claims, renewals and settles carry no key. Any
188
+ write takes `idempotencyMatch: 'shape'` with its own key to be compared the
189
+ same way.
190
+
191
+ `start()` runs each watcher in a loop of its own and returns `{ stop, done }`
192
+ at once. **Never await `done`, or anything that waits for it, where a server
193
+ starts up** (Next.js `register()`, a framework's boot hook): it settles only
194
+ when the host stops, so the server would never start. `stop()` cuts the wait
195
+ between looks short and starts no run after it. The run in flight has its
196
+ `signal` aborted (a `command()` is sent SIGTERM), and is waited for at most
197
+ `grace` (5 seconds unless `start({ grace })` says), then recorded; `done`
198
+ settles after that. A second `start()` on the same handle, or on another copy
199
+ of the same module that declares the same watchers (Next.js loads two),
200
+ returns the host already running. One on another handle with other watchers
201
+ for a board this process already runs fails with `watch_started`, naming
202
+ both: declare every watcher on one handle.
203
+
204
+ `board({ hooks })` declares [outgoing webhooks](../01-concepts/15-outgoing-webhooks.md#in-a-board-module)
205
+ the same way, each secret named with `env('NAME')`: `start()` reads the
206
+ secrets and sends them, under one lease, `hooks`.
207
+
208
+ A watcher starts from now: the first time it runs, it takes the board's head
209
+ as its place, and what was posted before wakes nothing. Its place is the
210
+ cursor `watch:<name>`. Each watcher is held by one host at a time, through
211
+ its lease `watch:<name>` in the board's file: another host started on the
212
+ same board stands by, and takes over within the lease (30 seconds) if the
213
+ first one stops. A host that finds at a renewal that another has taken its
214
+ lease aborts the run in flight at once, and records nothing more: what that
215
+ run did is delivered again by the new holder. Watchers run where the board's file is; on a board at a URL
216
+ `start()` fails with `watch_remote`.
217
+
218
+ Events in one thread are delivered in order, and each thread on its own. A
219
+ run that throws is a failed delivery: that event is tried again 10 seconds
220
+ later, then 20, 40 and 80, and the events after it in its thread wait, while
221
+ other threads go on, however many events wait behind it. A pass reads at
222
+ most 5,000 of the board's events, matched or not, and the next pass reads on
223
+ from there, so a long backlog or a busy board never holds a host's event loop
224
+ for long. With `coalesce`, one run stands for at most 500 events; the rest go
225
+ in the next. Tries are counted
226
+ in the board's file before each run,
227
+ so a host that restarts, or dies during a run, carries on where it was and
228
+ never delivers a thread's event twice once it was recorded. After 5 tries the
229
+ watcher gives up on that event and says so in its thread, once, with a reply
230
+ that starts `watcher "<name>" couldn't deliver a wake-up` and never wakes it.
231
+ Backing off is per thread, so a thread that keeps failing never holds up a
232
+ new one. Past five failed runs in a row, across threads, the run itself is
233
+ broken: the watcher's loop waits 2 seconds between passes, then 4, and so on
234
+ up to ten minutes, logs `slowed`, and is back to its pace after one run that
235
+ works.
236
+
237
+ ### Waking a command
238
+
239
+ `command()` is a `run` that starts a command: the way to wake an agent.
240
+
241
+ ```ts lib/board.ts
242
+ import { board, command } from '@openmuster/muster'
243
+
244
+ export const team = board({
245
+ watch: {
246
+ lead: {
247
+ tail: { channel: 'work/', types: ['message.posted'] },
248
+ as: 'lead',
249
+ coalesce: '30s',
250
+ run: command(({ event }) => ['./wake.sh', String(event.thread)], { env: ['ANTHROPIC_API_KEY'] }),
251
+ },
252
+ },
253
+ })
254
+ ```
255
+
256
+ It takes the command as a list of words, or a function of the event that
257
+ returns one; never a string for a shell to split. The command starts with
258
+ nothing of this process's environment but `PATH`, `HOME` and the like, the
259
+ names `env` lists, and a pointer to what happened: `MUSTER_THREAD`,
260
+ `MUSTER_CHANNEL`, `MUSTER_EVENT`, `MUSTER_EVENT_TYPE`, `MUSTER_WATCHER`,
261
+ `MUSTER_ATTEMPT`, `MUSTER_PROFILE` (the watcher's `as`), and `MUSTER_DIR` and
262
+ `MUSTER_BOARD` for the board the handle has; `MUSTER_URL` and
263
+ `MUSTER_INSECURE_HTTP` are dropped, and on a board in memory so are
264
+ `MUSTER_DIR` and `MUSTER_BOARD`, unless `env` names them. Never the text: what
265
+ a stranger wrote reaches the agent only when it reads the thread. Its output
266
+ goes to the host's. Exit 0 is delivered; anything else is a failed try, and
267
+ the note after 5 says its exit code. The run is over when the command exits:
268
+ an agent it started in the background (`agent &`) lives on, in the command's
269
+ process group, and nothing waits for it or kills it. Until the command exits,
270
+ at the watcher's `timeout` or the host's `stop()`, its whole process group is
271
+ sent SIGTERM, then SIGKILL 5 seconds later (`grace`). `gate` runs first: when
272
+ the last line it prints is JSON with `"wake": false`, the command isn't run.
273
+ A gate is read to the end of its output, not only until it exits, so an
274
+ answer printed by a child it left behind is heard.
275
+
276
+ `await team.deliver()` runs each watcher once on what it has not had yet, and
277
+ returns `{ delivered, failed, held }`, for tests. Call it once before the
278
+ writes a test makes, so the watchers have their place.
279
+
280
+ ## Mounting it in a web app
281
+
282
+ `team.fetch` takes a web `Request` and returns a `Response`: what `mu serve`
283
+ serves for this board, from the same code. That covers the routes in
284
+ [the HTTP reference](./03-http.md), the live feed, `health`, and webhooks for
285
+ the handle's `sync`. Every request needs a token, and the key is the one
286
+ `mu serve` uses, so a token from `mu token create` works on both and
287
+ `mu token revoke` stops it on both. That key is kept in muster's config
288
+ folder, so the app must run with the same `HOME` or `MUSTER_CONFIG` as the
289
+ `mu` that made the token. There is no mode without a token.
290
+
291
+ ```ts app/api/board/[...path]/route.ts
292
+ import { team } from '@/lib/board'
293
+
294
+ export const GET = team.fetch, POST = team.fetch
295
+ ```
296
+
297
+ | Option | Default | What it does |
298
+ | --- | --- | --- |
299
+ | `serve.base` | `/api/board` | The path it is mounted at. Anything outside it gets 404, including `/api/board` when the base is another path |
300
+ | `serve.hosts` | `MUSTER_ALLOW_HOSTS` | Host names it answers for besides `127.0.0.1`, `localhost` and `[::1]`, like `mu serve --allow-host`. A request for any other `Host`, or with none, gets 403. List every name the app is reached by, preview domains included |
301
+ | `serve.log` | standard error | Where a request that failed for a reason other than the board's own rules is described, for the owner |
302
+
303
+ ```ts lib/board.ts
304
+ import { board } from '@openmuster/muster'
305
+
306
+ export const team = board({ serve: { base: '/team/board', hosts: ['board.example.com'] } })
307
+ ```
308
+
309
+ It opens nothing until its first request. It serves only a board on this
310
+ machine: on a handle for a board at a URL, every request gets 403. MCP over
311
+ HTTP, `tokenExchange` and requests to join are not served here: those stay
312
+ with `mu serve`. It runs only in Node, never on an edge runtime, because the
313
+ board is a SQLite file. With Next.js, keep `serverExternalPackages: ['muster']`
314
+ in `next.config.ts`, so the process has one copy of muster. If the app has a
315
+ `proxy.ts` (or `middleware.ts`), leave the board's routes out of its
316
+ `matcher`: Next.js reads a body that passes through it into memory and cuts
317
+ it at 10 MB, under the board's limit for a file.
318
+
319
+ ### Running the watchers beside it
320
+
321
+ In production, run the watchers in a process of their own: a `host.ts` that
322
+ imports the same `team` and calls `team.start()`. A board's file is shared
323
+ between processes, so the app and the host each open it.
324
+
325
+ For development only, Next.js can start them in its own process:
326
+
327
+ ```ts instrumentation.ts
328
+ export async function register() {
329
+ // Only in Node. With a static import an edge route builds, then fails on every request.
330
+ if (process.env.NEXT_RUNTIME === 'nodejs') {
331
+ const { team } = await import('./lib/board')
332
+ const host = team.start() // never await host.done here: the server would never start
333
+ for (const [signal, code] of [['SIGTERM', 143], ['SIGINT', 130]] as const) {
334
+ process.once(signal, () => {
335
+ host.stop()
336
+ void host.done.finally(() => process.exit(code))
337
+ })
338
+ }
339
+ }
340
+ }
341
+ ```
342
+
343
+ The caveats, which are why this is for development only:
344
+
345
+ - An edit to a watcher, `lib/board.ts` or `instrumentation.ts` reaches the
346
+ routes but not the running watchers, until the dev server restarts.
347
+ - Watchers run on the same thread as the pages and read the board
348
+ synchronously, so a long catch-up delays requests.
349
+ - Stopping cleanly needs `NEXT_MANUAL_SIG_HANDLE=1 next start`, and never
350
+ happens under `next dev`. Without it a run in flight can be delivered again
351
+ after a restart.
352
+ - Next.js loads `instrumentation.ts` and the routes as separate copies of
353
+ `lib/board.ts`. `start()` keeps what it runs on `globalThis`, so a second
354
+ copy finds the host already running. `team.fetch` keeps nothing between
355
+ requests: its token list is in the board's file, so both copies agree.
356
+ `team.watchers` lists what a handle declares: `{ name, tail, as }` for each,
357
+ declared and not necessarily running.
358
+
359
+ ### Sync in the module
360
+
361
+ `board({ sync })` takes the platforms the board syncs with, by name, with
362
+ their secrets named by `env('NAME')`: see
363
+ [Sync in a board module](../02-sync/01-overview.md#in-a-board-module).
364
+ `team.sync` lists them as `{ key, type, env }`, without reading anything.
365
+ `start()` reads the variables, throws naming any that isn't set, and runs the
366
+ sync (catch-up, files, imports and what goes back) under the board's `sync`
367
+ lease. `team.fetch` reads them on its first request. Until they are there it
368
+ goes on serving the board, logs what is missing, and answers webhooks with 503
369
+ and `health` with 503 `unhealthy`. On its own it only takes webhooks: catching
370
+ up and sending back need a `start()` somewhere.
371
+
372
+ ### Running a module with mu
373
+
374
+ `mu serve` and `mu daemon run` run a board module: a `.ts` file whose default
375
+ export, or `team`, is a `board()`. They start its watchers, its sync and its
376
+ outgoing webhooks: see [The board module and hosts](../01-concepts/17-board-module.md).
377
+ A `watchers.json`, `sync.json` or `hooks.json` left from before makes both
378
+ refuse to start ([Porting](./07-porting.md)). The module is `--module <file>`, else `MUSTER_MODULE` (an absolute path), else
379
+ `~/.config/muster/board.ts` when nothing named a board: no `--dir`, `--board`
380
+ or `--url`, and no `MUSTER_DIR`, `MUSTER_BOARD` or `MUSTER_URL`. `--no-module`
381
+ runs none. It needs no `package.json`: `mu` answers its `import '@openmuster/muster'`. A
382
+ project with its own muster runs on that install. A module named on purpose
383
+ says which board it is, so `--dir`, `--board` and `--url` don't go with it,
384
+ and neither do `--as` or `MUSTER_PROFILE`. `mu daemon install` names the
385
+ service for the board the module opens. `mu daemon status` lists each watcher, the host
386
+ that holds it, and how far behind it is, and each sync with the variables it reads. `mu daemon check <name>` checks one.
387
+ A module that fails to load stops `mu daemon run` with exit 0, and `mu serve`
388
+ serves the board without it. Both say why, loudly.
389
+
390
+ ## The rest
391
+
392
+ | Method | For |
393
+ | --- | --- |
394
+ | `scheduleCreate`, `scheduleList`, `scheduleCancel` | [Schedules](../01-concepts/10-schedules.md) |
395
+ | `filePut`, `fileGet` | [Files](../01-concepts/12-files-and-data.md): data as base64 |
396
+ | `schemaAdd`, `schemaList` | Typed blocks |
397
+ | `budgetSet`, `budgets` | [Budgets](../01-concepts/13-budgets.md) |
398
+
399
+ ## Other exports
400
+
401
+ | Export | What it is |
402
+ | --- | --- |
403
+ | `file`, `http` | The two backends |
404
+ | `listen`, `createHandler`, `mint`, `verify`, `boardKey` | Serving a board, and its tokens |
405
+ | `conformance` | The checks every backend passes |
406
+ | `claude`, `codex`, `generic`, `runLocal` | Agents, and running one here |
407
+ | `vercel`, `cloudflare`, `e2b`, `boardPolicy` | Running one in a cloud sandbox |
408
+ | `github`, `linear`, `slack`, `env`, `loadSync` | Sync |
409
+ | `workflowResult(team, id, owner)` | A workflow step's result, for code that goes on from it: `{ workflow, step, request, thread, on, result }` only when the daemon made the task and the run's own worker completed it, as a result is checked before it is quoted. Null otherwise, whatever the task's labels say |
@@ -0,0 +1,157 @@
1
+ ---
2
+ title: HTTP
3
+ description: "What mu serve answers: board routes, the live feed, and webhooks."
4
+ ---
5
+
6
+ ## The shape
7
+
8
+ Everything is under `/api/board` on the address `mu serve` prints, or
9
+ under the base a web app mounts
10
+ [`team.fetch`](./02-handle.md#mounting-it-in-a-web-app) at. Every
11
+ request but a webhook carries a token:
12
+
13
+ ```text
14
+ Authorization: Bearer mu1...
15
+ x-muster-profile: claude
16
+ ```
17
+
18
+ The profile header names which of the token's agents is writing. A token held
19
+ to a profile ignores it.
20
+
21
+ ## Board routes
22
+
23
+ One route per handle method, all `POST`, with the method's arguments as a JSON
24
+ array:
25
+
26
+ ```text
27
+ POST /api/board/post
28
+ { "args": [{ "channel": "dev", "text": "deploy is red" }] }
29
+
30
+ 200 { "ok": { "id": 12, "channel": "dev", ... } }
31
+ ```
32
+
33
+ The routes are the handle's methods: `post`, `reply`, `edit`, `remove`,
34
+ `label`, `react`, `createChannel`, `workflowRequest`, `readChannel`, `readThread`, `events`,
35
+ `channels`, `search`, `actors`, `head`, `cursorGet`, `cursorSet`, the `task*`
36
+ methods, the `schedule*` methods, `schemaAdd`, `schemaList`, `filePut`,
37
+ `fileGet`, `budgetSet`, `budgets`. See [The handle](./02-handle.md) for what
38
+ each takes.
39
+
40
+ `GET /api/board/whoami` says who the token is: `{ principal, profile, can }`.
41
+
42
+ ## Joining
43
+
44
+ ```text
45
+ POST /api/board/joinAsk { "args": [{ "profile": "reviewer", "note": "..." }] } no token
46
+ 200 { "ok": { "code": "K7Q4-M2XD", "secret": "...", "expires": 1795000000 } }
47
+
48
+ POST /api/board/joinPoll { "args": [{ "code": "K7Q4-M2XD", "secret": "..." }] } no token
49
+ 200 { "ok": { "state": "pending" } } | { "ok": { "state": "approved", "token": "mu1..." } } | { "ok": { "state": "denied" } }
50
+ ```
51
+
52
+ Only when the board was served with `--allow-joins`; otherwise both answer
53
+ `joins_closed`. A body is at most 4 KB. `joinList`, `joinApprove` and
54
+ `joinDeny` take a token as wide as the owner's, like the token routes.
55
+
56
+ ## Signing in as a workload
57
+
58
+ ```text
59
+ POST /api/board/tokenExchange { "args": [{ "token": "<the platform's OIDC token>" }] } no token
60
+ 200 { "ok": { "token": "mu1...", "record": { "id": "...", "profile": "ci", "can": { "ci/": ["read", "post"] }, "exp": 1795000000 }, "trust": "api-main" } }
61
+ ```
62
+
63
+ Only when the board's owner named workloads in `oidc.json`; otherwise it
64
+ answers `exchange_closed`. The token must be signed by an issuer a trust
65
+ names, with RS256 and a key of at least 2048 bits, be made out to that trust's
66
+ audience, have a `sub` the trust matches, and not have run out. Until the
67
+ signature is verified every refusal is the same `unauthorized`. A body is at
68
+ most 16 KB, and a token is taken once. See
69
+ [CI](../03-guides/08-ci.md#sign-in-with-the-jobs-own-token).
70
+
71
+ ## MCP
72
+
73
+ ```text
74
+ POST /api/board/mcp
75
+ Authorization: Bearer mu1...
76
+ { "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "mu", "arguments": { "args": ["read", "general"] } } }
77
+
78
+ 200 { "jsonrpc": "2.0", "id": 1, "result": { "content": [{ "type": "text", "text": "..." }], "isError": false } }
79
+ ```
80
+
81
+ MCP's HTTP transport, one JSON-RPC message per `POST`, answered in the
82
+ response. A notification gets `202` and no body; `GET` gets `405`, since
83
+ there is no stream. The token and the profile header work as on every other
84
+ route, and a request with an `Origin` from a host the board doesn't answer
85
+ for is refused. The tool is the one `mu mcp` offers: see
86
+ [An agent with no shell](../03-guides/17-mcp.md).
87
+
88
+ A request body is at most 36 MB, the room one file needs. A webhook's body,
89
+ which is read before anything can say who sent it, is at most 1 MB.
90
+
91
+ ## Errors
92
+
93
+ ```text
94
+ 409 { "error": { "reason": "claim_lost", "message": "You no longer hold task 12.", "hint": "...", "next": ["mu read 12"] }, "exit": 1 }
95
+ ```
96
+
97
+ | Status | When |
98
+ | --- | --- |
99
+ | 400 | The request is wrong: a bad channel, a missing value, a body that isn't JSON |
100
+ | 401 | No token, a forged or expired one, or one another board signed |
101
+ | 403 | The token may not do that there, or the request came for another host name |
102
+ | 404 | No such message, channel or route. A channel a token can't read is this too |
103
+ | 409 | The board refused: a conflict, a lost claim, a limit |
104
+ | 500 | Something broke |
105
+
106
+ Branch on `reason`, never on the message. See [Errors](./05-errors.md).
107
+
108
+ ## The live feed
109
+
110
+ ```text
111
+ GET /api/board/feed?channel=work/&type=task.completed&type=task.blocked
112
+ Authorization: Bearer mu1...
113
+
114
+ id: 41
115
+ event: task.completed
116
+ data: {"seq":41,"type":"task.completed","thread":12,...}
117
+ ```
118
+
119
+ A stream of server-sent events: every matching event after a cursor, as it
120
+ happens. Each event's `id` is its cursor.
121
+
122
+ | Parameter | What it filters |
123
+ | --- | --- |
124
+ | `after` | Where to start. Default: now |
125
+ | `channel`, `re`, `by`, `mentions`, `text` | As for `mu tail` |
126
+ | `label`, `type` | Repeatable |
127
+
128
+ Reconnecting with `Last-Event-ID` resumes from that cursor, with no event
129
+ missed or repeated. A browser's `EventSource` does this by itself, but can't
130
+ send the token header: have your own server hold the feed and pass it on.
131
+
132
+ ## Webhooks
133
+
134
+ ```text
135
+ POST /api/board/webhooks/<name>
136
+ ```
137
+
138
+ For platforms, with no token: the platform's own signature is what proves the
139
+ request, and the sync named `<name>` checks it. See
140
+ [Sync](../02-sync/01-overview.md).
141
+
142
+ | Answer | Means |
143
+ | --- | --- |
144
+ | 200 | Stored, or a kind of event the board doesn't read |
145
+ | 401 | The signature is wrong or missing |
146
+ | 404 | No sync by that name |
147
+ | 500 | Not stored: send it again |
148
+
149
+ ## What it won't answer
150
+
151
+ `mu serve` listens on 127.0.0.1, or where `--host` says, and refuses a request
152
+ whose `Host` isn't its own or one named with `--allow-host`.
153
+
154
+ `GET /api/board/health` answers `200 { "ok": { "version": "..." } }` with no
155
+ token, for a container's health check or a load balancer. It says nothing
156
+ about the board. Sending schedules, importing sync and
157
+ running watchers are the server's own work: no route asks for them.
@@ -0,0 +1,72 @@
1
+ ---
2
+ title: Events
3
+ description: Every kind of event in a board's log, and what it carries.
4
+ ---
5
+
6
+ ## An event
7
+
8
+ ```json
9
+ { "seq": 41, "at": "2026-11-20T09:15:00.000Z", "type": "task.completed", "by": { "principal": "local:user:ada", "profile": "worker-1" }, "channel": "work", "thread": 12, "data": { "id": 12, "result": "fixed in a1b2c3", "from": "claimed" } }
10
+ ```
11
+
12
+ `seq` is its place in the log and the cursor to read on from. `thread` is the
13
+ root it belongs to. From `tail`, `wait` and `events`, a message event also
14
+ carries the `message` as it is now, and a task event the `task`.
15
+
16
+ Events the board writes itself are by the principal `board`.
17
+
18
+ ## Messages
19
+
20
+ | Type | Data |
21
+ | --- | --- |
22
+ | `channel.created` | `path`, `private` |
23
+ | `message.posted` | `re`, `replyTo`, `text`, `labels`, `attachments`, `noSync`, `mentions`; `schedule` when a schedule sent it; `origin` when sync imported it |
24
+ | `message.edited` | `id`, `text`, `revision`, `mentions` |
25
+ | `message.deleted` | `id` |
26
+ | `labels.changed` | `id`, `set`, `unset`, `before`: the labels as they were |
27
+ | `reaction.added`, `reaction.removed` | `id`, `emoji` |
28
+ | `workflow.requested` | `name`, `on`: the message it was asked on, `args`: text values by name, `profileHeld`: whether the profile in `by` is fixed by the token (or the caller is the board itself, unnarrowed) rather than named by the request, `narrowed`: whether the caller's token is held to channels (a request without it counts as narrowed), `private`: whether the thread's channel is private, so the run is made private too (a request without it counts as private). On the thread of `on`. Changes nothing itself: the daemon that has `name` in its `workflows.json` acts on it |
29
+
30
+ ## Tasks
31
+
32
+ Each carries the task's `id` and, where it moved, the state it came `from`.
33
+
34
+ | Type | Also carries | Means |
35
+ | --- | --- | --- |
36
+ | `task.created` | `state`, `needs`, `for` | A thread became a task |
37
+ | `task.ready`, `task.waiting` | | It moved to that state |
38
+ | `task.claimed` | `epoch`, `until` | Someone holds it |
39
+ | `task.renewed` | `until` | Its holder extended the lease |
40
+ | `task.extended` | `until` | The board extended it: its process is alive, or the machine slept |
41
+ | `task.released` | | Its holder gave it back |
42
+ | `task.expired` | | Its lease ran out |
43
+ | `task.blocked` | `kind`, `reason` | Held for a person, or by the board |
44
+ | `task.completed` | `result` | Done |
45
+ | `task.failed` | `reason`, `counts` | Given up on |
46
+ | `task.canceled` | | Called off |
47
+ | `task.reopened` | `state`, `round` | Back in the queue |
48
+ | `task.assigned` | `for` | Given to a profile, or back to the pool |
49
+ | `task.needs_changed` | `needs` | What it waits for changed |
50
+
51
+ A claim's token never appears in an event a reader gets.
52
+
53
+ ## The rest
54
+
55
+ | Type | Data |
56
+ | --- | --- |
57
+ | `schedule.created` | `thread`, `text`, `first`, `every`, `times`, `until` |
58
+ | `schedule.canceled` | `id` |
59
+ | `schedule.skipped` | `id`, `slot`: a slot too late to send |
60
+ | `sync.delivered` | `id`, `key`, `external`: a message reached a platform. `files`: the platform's IDs for the files sent with it, if any |
61
+ | `sync.failed` | `id`, `key`, `error`: it didn't, after five tries |
62
+ | `schema.registered` | `name`, `version`, `schema` |
63
+ | `budget.set` | `channel`, `usd` |
64
+
65
+ ## Filtering by type
66
+
67
+ ```bash
68
+ mu tail work/ --type task.completed --type task.failed
69
+ mu wait work/ --type task.
70
+ ```
71
+
72
+ A type ending in `.` takes every event under it.