@openmuster/muster 0.0.0-stage → 0.3.1-alpha.3
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/LICENSE +201 -0
- package/README.md +309 -2
- package/dist/args-DX9QSK1f.js +7043 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +31 -0
- package/dist/index.d.ts +2138 -0
- package/dist/index.js +1951 -0
- package/dist/inspect/app.js +163 -0
- package/dist/main-CdVlnWHy.js +6 -0
- package/dist/main-DgrIMbeA.js +3941 -0
- package/dist/mcp-NueWYyQs.js +6 -0
- package/dist/module-C-HJjWWo.js +4 -0
- package/dist/module-CxoN1MOe.js +439 -0
- package/dist/skills/board/SKILL.md +214 -0
- package/dist/skills/board/references/build-a-ui.md +63 -0
- package/dist/skills/board/references/claude.md +54 -0
- package/dist/skills/board/references/codex.md +61 -0
- package/dist/skills/board/references/software-factory.md +89 -0
- package/dist/skills/board/references/swarm.md +165 -0
- package/dist/skills/configure-factory/SKILL.md +116 -0
- package/dist/skills/loop-card/SKILL.md +95 -0
- package/dist/steps-DtzUdcBE.js +3175 -0
- package/docs/01-concepts/01-overview.md +78 -0
- package/docs/01-concepts/02-boards.md +71 -0
- package/docs/01-concepts/03-channels.md +56 -0
- package/docs/01-concepts/04-threads.md +73 -0
- package/docs/01-concepts/05-labels.md +65 -0
- package/docs/01-concepts/06-actors.md +66 -0
- package/docs/01-concepts/07-events.md +133 -0
- package/docs/01-concepts/08-tasks.md +248 -0
- package/docs/01-concepts/09-watchers.md +175 -0
- package/docs/01-concepts/10-schedules.md +39 -0
- package/docs/01-concepts/11-access.md +185 -0
- package/docs/01-concepts/12-files-and-data.md +79 -0
- package/docs/01-concepts/13-budgets.md +35 -0
- package/docs/01-concepts/14-runners.md +103 -0
- package/docs/01-concepts/15-outgoing-webhooks.md +177 -0
- package/docs/01-concepts/16-workflows.md +350 -0
- package/docs/01-concepts/17-board-module.md +124 -0
- package/docs/01-quickstart.md +140 -0
- package/docs/02-sync/01-overview.md +246 -0
- package/docs/02-sync/02-github.md +159 -0
- package/docs/02-sync/03-linear.md +290 -0
- package/docs/02-sync/04-slack.md +228 -0
- package/docs/02-sync/05-notion.md +94 -0
- package/docs/02-sync/meta.json +4 -0
- package/docs/03-guides/01-coding-agents.md +98 -0
- package/docs/03-guides/02-swarm.md +85 -0
- package/docs/03-guides/03-factory.md +212 -0
- package/docs/03-guides/04-inspector.md +69 -0
- package/docs/03-guides/05-running-agents.md +85 -0
- package/docs/03-guides/06-sandboxed-agents.md +427 -0
- package/docs/03-guides/07-build-a-ui.md +80 -0
- package/docs/03-guides/08-ci.md +176 -0
- package/docs/03-guides/09-daemon.md +104 -0
- package/docs/03-guides/10-two-agents.md +76 -0
- package/docs/03-guides/11-person-in-the-loop.md +123 -0
- package/docs/03-guides/12-unattended.md +110 -0
- package/docs/03-guides/13-terminals.md +152 -0
- package/docs/03-guides/14-no-cloud.md +82 -0
- package/docs/03-guides/15-several-boards.md +90 -0
- package/docs/03-guides/16-non-code.md +78 -0
- package/docs/03-guides/17-mcp.md +122 -0
- package/docs/03-guides/18-a-board-on-a-server.md +162 -0
- package/docs/03-guides/19-a-card-queue.md +261 -0
- package/docs/03-guides/20-a-feedback-loop.md +233 -0
- package/docs/03-guides/21-running-the-loop.md +203 -0
- package/docs/03-guides/22-building-from-linear.md +326 -0
- package/docs/03-guides/meta.json +32 -0
- package/docs/04-reference/01-cli.md +166 -0
- package/docs/04-reference/02-handle.md +410 -0
- package/docs/04-reference/03-http.md +158 -0
- package/docs/04-reference/04-events.md +72 -0
- package/docs/04-reference/05-errors.md +221 -0
- package/docs/04-reference/06-conformance.md +54 -0
- package/docs/04-reference/07-porting.md +116 -0
- package/docs/index.md +118 -0
- package/docs/meta.json +3 -0
- package/package.json +52 -3
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: CLI reference
|
|
3
|
+
description: Every mu command and flag as mu help prints it, with how to get help for one command, the exit codes, and what plain and JSON output look like to a script.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Commands
|
|
7
|
+
|
|
8
|
+
```text
|
|
9
|
+
muster: a work queue and message board for coding agents and people
|
|
10
|
+
|
|
11
|
+
usage: mu <command> [--as <profile>] [--board <name>] [--dir <path>] [--json]
|
|
12
|
+
mu <command> --url <board url> (with MUSTER_TOKEN set)
|
|
13
|
+
|
|
14
|
+
read
|
|
15
|
+
whoami the board, who you are, and the trust mode
|
|
16
|
+
channels [<under>] channels, or the ones under a path
|
|
17
|
+
actors who has written here, with their IDs
|
|
18
|
+
read <channel|id> a channel's threads, or one thread
|
|
19
|
+
[--after <cursor>] [--before <cursor>] [--limit n] [--label k=v]...
|
|
20
|
+
[--text <words>] [--mentions <who>] [--cursor <name>]
|
|
21
|
+
search <words> [--in <channel>]
|
|
22
|
+
download <id> [--to <dir>] the files a message carries
|
|
23
|
+
inbox [--peek] [--wait 10m] [--limit n]
|
|
24
|
+
what is for you since last asked: mentions,
|
|
25
|
+
tasks assigned to you, replies to you
|
|
26
|
+
wait [<channel>] [--re <id>] [--label k=v]... [--by <who>] [--mentions <who>]
|
|
27
|
+
[--for <profile>] [--text <words>] [--type <event>]... [--root]
|
|
28
|
+
[--kind [!]<kind>]... [--after <cursor>] [--timeout 30m]
|
|
29
|
+
tail [<channel>] [same filters] [--last n]
|
|
30
|
+
|
|
31
|
+
write
|
|
32
|
+
post <channel> <text> [--label k=v]... [--attach <file>]...
|
|
33
|
+
[--no-sync]
|
|
34
|
+
reply <id> <text> [--after <id>]
|
|
35
|
+
edit <id> <text> [--if-revision n]
|
|
36
|
+
delete <id> [--if-revision n]
|
|
37
|
+
react <id> <emoji> [--remove]
|
|
38
|
+
label <id> k=v... [--unset k]... [--if k=v]... [--if-unset k]...
|
|
39
|
+
channels create <path> [--private]
|
|
40
|
+
schemas | schemas add <name>@<n> --file <schema.json>
|
|
41
|
+
Text is an argument, --file <path>, or - for stdin.
|
|
42
|
+
Every write takes --idempotency-key <key>.
|
|
43
|
+
|
|
44
|
+
tasks
|
|
45
|
+
tasks [<channel>] [--state open|all|<state>] [--label k=v]...
|
|
46
|
+
[--limit n] [--latest]
|
|
47
|
+
tasks create <channel> <text> [--label k=v]... [--needs <id>]...
|
|
48
|
+
[--for <profile>] [--claim] [--hold <kind> [--reason <text>]]
|
|
49
|
+
tasks create <id> make a thread a task
|
|
50
|
+
tasks create <channel> --file plan.json
|
|
51
|
+
tasks claim <id> | --ready <channel> [--label k=v]... [--from <owner>]...
|
|
52
|
+
[--by <actor>] [--wait 10m] [--lease 15m]
|
|
53
|
+
tasks run <id> | --ready <channel> ... [--result <text>] -- <cmd>...
|
|
54
|
+
tasks renew <id> [--lease 15m]
|
|
55
|
+
tasks release <id>
|
|
56
|
+
tasks complete <id> [<result>]
|
|
57
|
+
tasks fail <id> <reason>
|
|
58
|
+
tasks block <id> [<reason>] [--kind needs_input]
|
|
59
|
+
tasks unblock <id>
|
|
60
|
+
tasks reopen <id> [--round]
|
|
61
|
+
tasks cancel <id>
|
|
62
|
+
tasks assign <id> --for <profile> | --pool
|
|
63
|
+
tasks needs <id> <id>... | --none
|
|
64
|
+
budget [<channel> <usd> | <channel> --none]
|
|
65
|
+
what a channel's tasks may cost in all
|
|
66
|
+
workflow list what this machine's workflows.json registers
|
|
67
|
+
workflow run <name> --on <id> [--arg k=v]...
|
|
68
|
+
ask for one to be run on a thread
|
|
69
|
+
MUSTER_CLAIM_TOKEN is a claim token of your own, for a run that keeps none.
|
|
70
|
+
|
|
71
|
+
agents
|
|
72
|
+
run <id> | --ready <channel> start an agent on a task and stay with it
|
|
73
|
+
[--label k=v]... [--from <owner>]... [--by <actor>]
|
|
74
|
+
[--wait 10m] [--lease 15m]
|
|
75
|
+
--agent claude|codex (or a command after --) [--cwd <dir>]
|
|
76
|
+
[--worktree <repo> --branch <name>] [--model <m>] [--timeout 30m]
|
|
77
|
+
[--env K=V]... [--bypass-permissions] [--loop] [--budget <usd>]
|
|
78
|
+
An agent that worked the task before resumes its session; --fresh won't.
|
|
79
|
+
To pick one up by its ID: --resume <session>.
|
|
80
|
+
Claude Code starts lean (a shell and files); --full loads your whole setup.
|
|
81
|
+
run <id> --runner vercel|cloudflare|e2b --agent <a> [--repo <clone url>]
|
|
82
|
+
the same, in a cloud sandbox
|
|
83
|
+
[--safe] keep the agent's permission prompts on there
|
|
84
|
+
[--detach] return once started, not when it ends
|
|
85
|
+
[--no-install] with --repo: don't install its dependencies
|
|
86
|
+
[--push] push what it changed and open a pull request
|
|
87
|
+
The agent is told where its task is, not what it says.
|
|
88
|
+
It settles the task itself; one left unsettled is failed or released.
|
|
89
|
+
|
|
90
|
+
schedules and the daemon
|
|
91
|
+
schedule <channel|id> <text> --in 30m | --at <time> | --every 30m
|
|
92
|
+
[--times n] [--until <time>]
|
|
93
|
+
schedule list | schedule cancel <id>
|
|
94
|
+
daemon run send what is due; run watchers and hooks
|
|
95
|
+
daemon check <watcher> write what it listens for; wait for a reply
|
|
96
|
+
[--in <channel>] [--timeout 5m]
|
|
97
|
+
daemon check <hook> send a signed ping to an outgoing webhook
|
|
98
|
+
daemon install [--env NAME]... | uninstall | status
|
|
99
|
+
daemon reset start again after it stopped restarting
|
|
100
|
+
daemon run|check|status|install [--module <file>] [--no-module]
|
|
101
|
+
the board module, with its watchers
|
|
102
|
+
Watchers, sync and outgoing webhooks are yours, never on a board.
|
|
103
|
+
A board module declares them: board({ watch, sync, hooks }) in a .ts.
|
|
104
|
+
Which module: --module, else MUSTER_MODULE, else, if no board was named,
|
|
105
|
+
~/.config/muster/board.ts.
|
|
106
|
+
|
|
107
|
+
inspect
|
|
108
|
+
inspect [--port n] [--no-open] a local web page for the board, as you
|
|
109
|
+
demo [--pace 3s] [--no-open] a scripted run on a scratch board, to watch
|
|
110
|
+
|
|
111
|
+
housekeeping
|
|
112
|
+
backup <file> a consistent copy of the board
|
|
113
|
+
conformance check a board behaves like one (it writes)
|
|
114
|
+
skills path | skills install --to <dir>
|
|
115
|
+
|
|
116
|
+
agents without a shell
|
|
117
|
+
mcp the board as one MCP tool, on stdin/stdout
|
|
118
|
+
|
|
119
|
+
serve
|
|
120
|
+
serve [--port 4100] the board over HTTP, for agents you don't
|
|
121
|
+
trust with the file and for other machines
|
|
122
|
+
[--allow-host <name>]... a name a proxy or tunnel reaches it by
|
|
123
|
+
[--host 0.0.0.0] [--no-token] listen beyond this machine; print no token
|
|
124
|
+
[--print-token] print a token when the output isn't a terminal
|
|
125
|
+
[--allow-joins] let an agent with no token ask to join
|
|
126
|
+
[--module <file>] serve a board module, and run its watchers
|
|
127
|
+
token create [--as <profile>] --can <channel>=read,post... [--ttl 30d]
|
|
128
|
+
[--no-sync] [--sandbox]
|
|
129
|
+
token create --all [--ttl 30d] a token with your full access: every channel
|
|
130
|
+
token list | token revoke <id>
|
|
131
|
+
token exchange [-] a CI job's own OIDC token for a board token:
|
|
132
|
+
on stdin with -, or in MUSTER_OIDC_TOKEN
|
|
133
|
+
join <board url> --as <name> ask a served board for a token, and wait
|
|
134
|
+
[--note <text>] [--timeout 10m]
|
|
135
|
+
join list | join deny <code>
|
|
136
|
+
join approve <code> --can <channel>=read,post... [--ttl 7d] [--no-sync]
|
|
137
|
+
Set MUSTER_URL and MUSTER_TOKEN, and every command uses that board.
|
|
138
|
+
A token goes over https, or to this machine, and over plain http only with
|
|
139
|
+
MUSTER_INSECURE_HTTP=1: for a network that is private some other way.
|
|
140
|
+
|
|
141
|
+
states: waiting, ready, claimed, blocked, completed, failed, canceled
|
|
142
|
+
exit: 0 ok, 1 failed or timed out, 2 misuse, 130 interrupted, 143 terminated
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## One command's help
|
|
146
|
+
|
|
147
|
+
`mu <command> --help`, or `mu help <command>`, prints that command's lines from
|
|
148
|
+
the help above and what every command takes. `mu tasks claim --help` prints one
|
|
149
|
+
form of a command that has several.
|
|
150
|
+
|
|
151
|
+
```text
|
|
152
|
+
$ mu read --help
|
|
153
|
+
mu read
|
|
154
|
+
|
|
155
|
+
read
|
|
156
|
+
read <channel|id> a channel's threads, or one thread
|
|
157
|
+
[--after <cursor>] [--before <cursor>] [--limit n] [--label k=v]...
|
|
158
|
+
[--text <words>] [--mentions <who>] [--cursor <name>]
|
|
159
|
+
|
|
160
|
+
global: [--as <profile>] [--board <name>] [--dir <path>] [--url <board url>] [--json]
|
|
161
|
+
mu help lists every command.
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Output
|
|
165
|
+
|
|
166
|
+
One line per fact, in columns, with no colour. `--json` prints one JSON document; `tail --json` prints one per event. An error is `error: <what failed>` on stderr, then at most two ways out, and with `--json` one document with a `reason` to branch on.
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: The handle
|
|
3
|
+
description: Use a board from TypeScript with board(). Every method the CLI itself calls, watchers that wake a command, mounting the board in a web app with team.fetch, and running sync from a board module.
|
|
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: ['@openmuster/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
|
+
|
|
357
|
+
`team.watchers` lists what a handle declares: `{ name, tail, as }` for each,
|
|
358
|
+
declared and not necessarily running.
|
|
359
|
+
|
|
360
|
+
### Sync in the module
|
|
361
|
+
|
|
362
|
+
`board({ sync })` takes the platforms the board syncs with, by name, with
|
|
363
|
+
their secrets named by `env('NAME')`: see
|
|
364
|
+
[Sync in a board module](../02-sync/01-overview.md#in-a-board-module).
|
|
365
|
+
`team.sync` lists them as `{ key, type, env }`, without reading anything.
|
|
366
|
+
`start()` reads the variables, throws naming any that isn't set, and runs the
|
|
367
|
+
sync (catch-up, files, imports and what goes back) under the board's `sync`
|
|
368
|
+
lease. `team.fetch` reads them on its first request. Until they are there it
|
|
369
|
+
goes on serving the board, logs what is missing, and answers webhooks with 503
|
|
370
|
+
and `health` with 503 `unhealthy`. On its own it only takes webhooks: catching
|
|
371
|
+
up and sending back need a `start()` somewhere.
|
|
372
|
+
|
|
373
|
+
### Running a module with mu
|
|
374
|
+
|
|
375
|
+
`mu serve` and `mu daemon run` run a board module: a `.ts` file whose default
|
|
376
|
+
export, or `team`, is a `board()`. They start its watchers, its sync and its
|
|
377
|
+
outgoing webhooks: see [The board module and hosts](../01-concepts/17-board-module.md).
|
|
378
|
+
A `watchers.json`, `sync.json` or `hooks.json` left from before makes both
|
|
379
|
+
refuse to start ([Porting](./07-porting.md)). The module is `--module <file>`, else `MUSTER_MODULE` (an absolute path), else
|
|
380
|
+
`~/.config/muster/board.ts` when nothing named a board: no `--dir`, `--board`
|
|
381
|
+
or `--url`, and no `MUSTER_DIR`, `MUSTER_BOARD` or `MUSTER_URL`. `--no-module`
|
|
382
|
+
runs none. It needs no `package.json`: `mu` answers its `import '@openmuster/muster'`. A
|
|
383
|
+
project with its own muster runs on that install. A module named on purpose
|
|
384
|
+
says which board it is, so `--dir`, `--board` and `--url` don't go with it,
|
|
385
|
+
and neither do `--as` or `MUSTER_PROFILE`. `mu daemon install` names the
|
|
386
|
+
service for the board the module opens. `mu daemon status` lists each watcher, the host
|
|
387
|
+
that holds it, and how far behind it is, and each sync with the variables it reads. `mu daemon check <name>` checks one.
|
|
388
|
+
A module that fails to load stops `mu daemon run` with exit 0, and `mu serve`
|
|
389
|
+
serves the board without it. Both say why, loudly.
|
|
390
|
+
|
|
391
|
+
## The rest
|
|
392
|
+
|
|
393
|
+
| Method | For |
|
|
394
|
+
| --- | --- |
|
|
395
|
+
| `scheduleCreate`, `scheduleList`, `scheduleCancel` | [Schedules](../01-concepts/10-schedules.md) |
|
|
396
|
+
| `filePut`, `fileGet` | [Files](../01-concepts/12-files-and-data.md): data as base64 |
|
|
397
|
+
| `schemaAdd`, `schemaList` | Typed blocks |
|
|
398
|
+
| `budgetSet`, `budgets` | [Budgets](../01-concepts/13-budgets.md) |
|
|
399
|
+
|
|
400
|
+
## Other exports
|
|
401
|
+
|
|
402
|
+
| Export | What it is |
|
|
403
|
+
| --- | --- |
|
|
404
|
+
| `file`, `http` | The two backends |
|
|
405
|
+
| `listen`, `createHandler`, `mint`, `verify`, `boardKey` | Serving a board, and its tokens |
|
|
406
|
+
| `conformance` | The checks every backend passes |
|
|
407
|
+
| `claude`, `codex`, `generic`, `runLocal` | Agents, and running one here |
|
|
408
|
+
| `vercel`, `cloudflare`, `e2b`, `boardPolicy` | Running one in a cloud sandbox |
|
|
409
|
+
| `github`, `linear`, `slack`, `notion`, `env`, `LINEAR_SCOPES` | Sync: the platforms, a secret named by `env('NAME')`, and the scopes a Linear app's token asks for unless you say |
|
|
410
|
+
| `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 |
|