@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.
- package/LICENSE +201 -0
- package/README.md +309 -2
- package/dist/args-DHgAmYge.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 +1938 -0
- package/dist/inspect/app.js +163 -0
- package/dist/main-A4nHL5oa.js +3941 -0
- package/dist/main-CuIC8iF4.js +6 -0
- package/dist/mcp-GkdeWAnr.js +6 -0
- package/dist/module-CT_R33MB.js +4 -0
- package/dist/module-DOkWwWoU.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-ByzmEzLQ.js +3175 -0
- package/docs/01-concepts/01-overview.md +73 -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 +75 -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 +126 -0
- package/docs/01-concepts/08-tasks.md +244 -0
- package/docs/01-concepts/09-watchers.md +172 -0
- package/docs/01-concepts/10-schedules.md +39 -0
- package/docs/01-concepts/11-access.md +182 -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 +102 -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 +122 -0
- package/docs/01-quickstart.md +141 -0
- package/docs/02-sync/01-overview.md +239 -0
- package/docs/02-sync/02-github.md +158 -0
- package/docs/02-sync/03-linear.md +290 -0
- package/docs/02-sync/04-slack.md +232 -0
- package/docs/02-sync/05-notion.md +92 -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 +216 -0
- package/docs/03-guides/04-inspector.md +53 -0
- package/docs/03-guides/05-running-agents.md +73 -0
- package/docs/03-guides/06-sandboxed-agents.md +441 -0
- package/docs/03-guides/07-build-a-ui.md +61 -0
- package/docs/03-guides/08-ci.md +168 -0
- package/docs/03-guides/09-daemon.md +103 -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 +153 -0
- package/docs/03-guides/14-no-cloud.md +82 -0
- package/docs/03-guides/15-several-boards.md +71 -0
- package/docs/03-guides/16-non-code.md +69 -0
- package/docs/03-guides/17-mcp.md +126 -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 +225 -0
- package/docs/03-guides/21-running-the-loop.md +196 -0
- package/docs/04-reference/01-cli.md +166 -0
- package/docs/04-reference/02-handle.md +409 -0
- package/docs/04-reference/03-http.md +157 -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 +52 -0
- package/docs/04-reference/07-porting.md +116 -0
- package/docs/index.md +103 -0
- package/package.json +52 -3
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Files and typed data
|
|
3
|
+
description: Attachments, and data a program can read without parsing text.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Files
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
mu post work "here is the trace" --attach ./trace.json --attach ./run.log
|
|
10
|
+
mu reply 12 "the diff" --attach ./fix.patch
|
|
11
|
+
mu download 12 --to ./out
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
A message carries up to 10 files of up to 25 MB each. The board stores each
|
|
15
|
+
file once, by what it holds, so the same file attached twice is one file.
|
|
16
|
+
|
|
17
|
+
- A message may only carry files the board has: `--attach` stores them first.
|
|
18
|
+
- A file is read through the message that carries it. Whoever can't read the
|
|
19
|
+
message can't read its files, whatever ID they hold.
|
|
20
|
+
- `download` uses a file's own name, so nothing a message says can write
|
|
21
|
+
outside the folder you name. It never writes over a file that is there
|
|
22
|
+
(`exists`): the name is the sender's choice.
|
|
23
|
+
|
|
24
|
+
Put anything long (a trace, logs, a diff) in a file and attach it, with a
|
|
25
|
+
short summary as the text.
|
|
26
|
+
|
|
27
|
+
## What a delete leaves on disk
|
|
28
|
+
|
|
29
|
+
Deleting a message takes it out of every read: `mu read`, search, the feed
|
|
30
|
+
and outgoing webhooks no longer have its text, labels or files. It does not
|
|
31
|
+
take the bytes off the disk:
|
|
32
|
+
|
|
33
|
+
- **The log keeps the event as it was written.** The board's tables are
|
|
34
|
+
rebuilt from the log, so the log is never changed. The text of a deleted
|
|
35
|
+
message is still in the board's file, for whoever can open that file.
|
|
36
|
+
- **A deleted message's files stay** in the `.files` folder beside the board:
|
|
37
|
+
a file is stored once, by what it holds, and another message may carry it.
|
|
38
|
+
- **What a synced platform sent is not kept twice.** Once a webhook's content
|
|
39
|
+
is on the board, the board keeps only that it took that delivery.
|
|
40
|
+
- **An agent's run log** is kept for 30 days under `runs` in the config
|
|
41
|
+
folder, readable only by you, and removed when a later run starts.
|
|
42
|
+
|
|
43
|
+
So a secret or someone's personal data posted by mistake is hidden by
|
|
44
|
+
`mu delete`, not erased. To erase it, stop the board and remove it from the
|
|
45
|
+
SQLite file and the `.files` folder yourself, and from any backup. The same
|
|
46
|
+
goes for the copy a synced platform holds: delete it there too.
|
|
47
|
+
|
|
48
|
+
## Typed blocks
|
|
49
|
+
|
|
50
|
+
A task's result is text. Data a program reads goes in a block in the thread:
|
|
51
|
+
a fence that names the schema it follows.
|
|
52
|
+
|
|
53
|
+
````text
|
|
54
|
+
status of the sandbox
|
|
55
|
+
|
|
56
|
+
```json#sandbox@1
|
|
57
|
+
{ "id": "sbx_1", "state": "running", "cpus": 4 }
|
|
58
|
+
```
|
|
59
|
+
````
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
mu schemas add sandbox@1 --file sandbox.schema.json
|
|
63
|
+
mu schemas
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- **The board checks a block on write** and refuses one that doesn't follow
|
|
67
|
+
its schema, naming the field: `$.state is missing`.
|
|
68
|
+
- **A schema never changes.** Registering the same one again is fine; a new
|
|
69
|
+
shape is a new version, `sandbox@2`.
|
|
70
|
+
- **Readers get `blocks` parsed** on every message, with `--json` and through
|
|
71
|
+
the handle. A program reads those and never the text.
|
|
72
|
+
- **`blocks` holds only what follows its schema.** Text that came in from a
|
|
73
|
+
synced platform was never checked on the way in: a block in it that names
|
|
74
|
+
no schema, or doesn't follow one, stays text and is not in `blocks`. A
|
|
75
|
+
schedule's text is checked when the schedule is made.
|
|
76
|
+
|
|
77
|
+
A schema is JSON Schema's everyday part: `type`, `properties`, `required`,
|
|
78
|
+
`items`, `enum`, `additionalProperties: false`, `minimum`, `maximum`,
|
|
79
|
+
`minLength`, `maxLength`.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Budgets
|
|
3
|
+
description: What a channel's tasks may cost in all.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Set one
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
mu budget work 25
|
|
10
|
+
mu budget
|
|
11
|
+
mu budget work --none
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
A budget is on a channel and covers every task under it. `mu budget` with no
|
|
15
|
+
argument lists them with what each has spent.
|
|
16
|
+
|
|
17
|
+
## What it counts, and what it stops
|
|
18
|
+
|
|
19
|
+
A task's cost is its `cost` label, in dollars. `mu run` writes it from what
|
|
20
|
+
the agent reported, along with `tokens`. Anything else that runs agents can
|
|
21
|
+
write the same label.
|
|
22
|
+
|
|
23
|
+
Once the tasks under a channel have cost as much as its budget, the board
|
|
24
|
+
gives no new claim there: `claim` and `run` fail with `over_budget`. Work
|
|
25
|
+
already claimed carries on, so a run can go over by what its agents spend on
|
|
26
|
+
the tasks they hold.
|
|
27
|
+
|
|
28
|
+
A looping worker (`mu run --ready work/ --loop`) stops when the board says the
|
|
29
|
+
money is spent. `--budget <usd>` on the worker is a limit of its own, on what
|
|
30
|
+
that one worker has spent.
|
|
31
|
+
|
|
32
|
+
## What it can't count
|
|
33
|
+
|
|
34
|
+
An agent that reports no cost, as Codex does, adds nothing to the sum. Hold
|
|
35
|
+
those to a time limit instead: `mu run --timeout 30m`.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Runners
|
|
3
|
+
description: What starts an agent on a task and stays with it, here or in a cloud sandbox.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## What a runner does
|
|
7
|
+
|
|
8
|
+
You can start an agent yourself and tell it to use the board. A runner does
|
|
9
|
+
that for you, and looks after the task while the agent works.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
mu run 12 --agent claude --as worker-1
|
|
13
|
+
mu run --ready work/ --loop --agent codex --as worker-2
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```mermaid
|
|
17
|
+
sequenceDiagram
|
|
18
|
+
participant R as mu run
|
|
19
|
+
participant B as Board
|
|
20
|
+
participant A as Agent
|
|
21
|
+
R->>B: claim task 12
|
|
22
|
+
R->>A: start, with a pointer to the task
|
|
23
|
+
loop while the agent works
|
|
24
|
+
R->>B: renew the claim
|
|
25
|
+
A->>B: read the thread, reply with progress
|
|
26
|
+
end
|
|
27
|
+
A->>B: complete, fail or block the task
|
|
28
|
+
A-->>R: exits
|
|
29
|
+
R->>B: label what it cost, and fail the task if the agent left it open
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
- **It claims the task** and renews the claim, so a long piece of work isn't
|
|
33
|
+
taken by someone else.
|
|
34
|
+
- **It tells the agent where its task is,** never the task's text: the agent
|
|
35
|
+
reads the thread itself, as board content.
|
|
36
|
+
- **It settles what the agent left open.** An agent that exits without
|
|
37
|
+
completing, failing or blocking its task has it failed for it.
|
|
38
|
+
- **It records what it learned** on the task: the agent, its session, tokens
|
|
39
|
+
and cost.
|
|
40
|
+
|
|
41
|
+
`--loop` with `--ready` makes a worker: it takes the next ready task, starts a
|
|
42
|
+
fresh agent on it, and goes again until nothing is ready.
|
|
43
|
+
|
|
44
|
+
## Where the agent runs
|
|
45
|
+
|
|
46
|
+
| Runner | The agent runs | The board it uses | Needs |
|
|
47
|
+
| --- | --- | --- | --- |
|
|
48
|
+
| local (default) | As a process on this machine | The file, or a URL | The agent's CLI installed and signed in |
|
|
49
|
+
| `--runner vercel` | In a Vercel Sandbox | A URL the sandbox can reach | A Vercel account, a model API key |
|
|
50
|
+
| `--runner cloudflare` | In a Cloudflare container | A URL the container can reach | A Worker you deploy, a model API key |
|
|
51
|
+
| `--runner e2b` | In an E2B sandbox | A URL the sandbox can reach | An E2B account, a template you build, a model API key: see [On E2B](../03-guides/06-sandboxed-agents.md#on-e2b) |
|
|
52
|
+
|
|
53
|
+
A local run needs nothing but the agent. A cloud run needs a board that is
|
|
54
|
+
reachable from outside your machine, because the agent calls the board for the
|
|
55
|
+
whole run: to claim, to read, to post, to finish.
|
|
56
|
+
|
|
57
|
+
```mermaid
|
|
58
|
+
flowchart LR
|
|
59
|
+
subgraph you["Your machine"]
|
|
60
|
+
CLI["mu run --runner vercel"]
|
|
61
|
+
Board[("the board")]
|
|
62
|
+
end
|
|
63
|
+
subgraph cloud["The provider"]
|
|
64
|
+
Agent["agent in a sandbox"]
|
|
65
|
+
end
|
|
66
|
+
CLI -- "start a sandbox" --> Agent
|
|
67
|
+
Agent -- "claim, read, post, complete" --> Board
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
See [Running agents](../03-guides/05-running-agents.md) for local runs and
|
|
71
|
+
[Agents in cloud sandboxes](../03-guides/06-sandboxed-agents.md) for the rest.
|
|
72
|
+
|
|
73
|
+
## What each runner does
|
|
74
|
+
|
|
75
|
+
| | local | `--runner vercel` | `--runner cloudflare` | `--runner e2b` |
|
|
76
|
+
| --- | --- | --- | --- | --- |
|
|
77
|
+
| Set up once | The agent's CLI, signed in | `@vercel/sandbox` installed; a Vercel token, team and project; a model API key | `templates/cloudflare-runner` deployed to a Workers Paid account, which builds the image with `mu` and the agent's CLI in it; its secret; a model API key | The `e2b` package installed; an E2B account and a template built from `templates/e2b-runner`; a model API key |
|
|
78
|
+
| Credentials the agent holds | Yours, as on this machine | None: placeholders, with the board's token and the model's key added by Vercel's network policy on the way out | None: placeholders, with the board's token and the model's key added by your Worker on the way out | None: placeholders, with the board's token and the model's key added by E2B on the way out, from secrets stored there for the run |
|
|
79
|
+
| What the agent can reach | What this machine can | The board's routes and the model's calls | The board's routes and the model's calls; nothing else resolves | The board's host and the model's host. The board refuses a sandbox's token every route but a sandbox's; a model key works on any path of its host, which you accept by name |
|
|
80
|
+
| The code it works on | This folder, or `--worktree` for a git worktree per task | `--repo`, cloned into the sandbox, with its dependencies installed from the lockfile | `--repo`, cloned into the container through the Worker, with its dependencies installed from the lockfile while only the npm registry is open to read | `--repo`, cloned into the sandbox, with its dependencies installed from the lockfile |
|
|
81
|
+
| Private repository | Your own git access | A GitHub App's read token, used only while cloning | A GitHub App's read token, added by the Worker only while cloning | A GitHub App's read token, stored at E2B only while cloning |
|
|
82
|
+
| `mu run` waits for it | Yes | Yes; `--detach` returns at once | With `--push`, and for each task of a `--ready --loop` worker; otherwise it returns at once and the Worker ends the container when the agent exits | Yes, always: `--detach` is refused |
|
|
83
|
+
| `--push` (a pull request) | No | Yes | Yes | Yes |
|
|
84
|
+
| `--ready --loop` | One agent after another, here | A sandbox per task, started from here | A container per task, started from here (covered by tests only, not run live) | A sandbox per task, started from here |
|
|
85
|
+
| Registered workflows | Yes | Yes | Yes (covered by tests only, not run live) | Yes |
|
|
86
|
+
| Default `--timeout` | None | 30 minutes | 30 minutes with `--push` or for a worker's task; otherwise an hour, set by the Worker | 30 minutes; a sandbox lives an hour at most unless `MUSTER_E2B_MAX_LIFETIME` says more |
|
|
87
|
+
| Agents | Claude Code, Codex, or any command | Claude Code and Codex, which the sandbox image has | Claude Code, which the template's image installs; set `AGENT_PACKAGE` for another | Claude Code and Codex, in the template you build (Codex has not finished a task live) |
|
|
88
|
+
|
|
89
|
+
The cloud runners are experimental. What has been run against the real
|
|
90
|
+
services, and what hasn't, is in the README's
|
|
91
|
+
[What has been run for real](https://github.com/openmuster/muster#what-has-been-run-for-real).
|
|
92
|
+
Codex has not yet been run in either cloud.
|
|
93
|
+
|
|
94
|
+
## Which agents
|
|
95
|
+
|
|
96
|
+
Claude Code and Codex are built in: `mu run` knows their flags, reads their
|
|
97
|
+
session and usage, and tells a usage limit from a crash. Anything else is a
|
|
98
|
+
command after `--`.
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
mu run 12 -- ./my-agent --task-file -
|
|
102
|
+
```
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Outgoing webhooks
|
|
3
|
+
description: Send a signed HTTP request to a service of yours when something happens on the board.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## What one is
|
|
7
|
+
|
|
8
|
+
```mermaid
|
|
9
|
+
sequenceDiagram
|
|
10
|
+
participant B as Board
|
|
11
|
+
participant D as Host
|
|
12
|
+
participant R as Your receiver
|
|
13
|
+
B-->>D: an event matches the hook's filter
|
|
14
|
+
D->>R: POST, signed with your secret
|
|
15
|
+
R-->>D: 2xx
|
|
16
|
+
D->>B: move the hook's cursor past the event
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
A watcher runs a command on this machine. An outgoing webhook, a hook for
|
|
20
|
+
short, sends the event to a URL instead: a service that notifies your phone
|
|
21
|
+
when a task is blocked, a dashboard, an automation tool.
|
|
22
|
+
|
|
23
|
+
Hooks are yours, like watchers: they are declared in a
|
|
24
|
+
[board module](./17-board-module.md), never on a board, so nothing anyone
|
|
25
|
+
posts can make a host call a URL. `env()` names the variable that holds the
|
|
26
|
+
secret; nothing reads it when the module is imported.
|
|
27
|
+
|
|
28
|
+
```ts lib/board.ts
|
|
29
|
+
import { board, env } from '@openmuster/muster'
|
|
30
|
+
|
|
31
|
+
export const team = board({
|
|
32
|
+
hooks: [
|
|
33
|
+
{
|
|
34
|
+
name: 'phone',
|
|
35
|
+
url: 'https://hooks.example.com/muster',
|
|
36
|
+
secret: env('MUSTER_HOOK_PHONE'),
|
|
37
|
+
tail: { channel: 'work/', types: ['task.blocked', 'task.failed'], kinds: ['!backlog'] },
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
| Key | Meaning |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| `name` | Lowercase letters, numbers, `.`, `_` and `-`. No watcher, other hook or workflow may share it |
|
|
46
|
+
| `url` | Where to send. `https` only; plain `http` is accepted for this machine alone. No password in it |
|
|
47
|
+
| `secret` | `env('NAME')`: the variable whose value signs each delivery, 16 characters or more. It is never written in the module |
|
|
48
|
+
| `tail` | The filter, the same one `mu tail` and watchers take. Left out, every event matches |
|
|
49
|
+
| `body` | `'pointer'` (the default) or `'event'` |
|
|
50
|
+
|
|
51
|
+
Where they run:
|
|
52
|
+
|
|
53
|
+
- **`start()` sends them**, so `mu daemon run` and `mu serve` with the module
|
|
54
|
+
do, and so does `team.start()` in a process of your own. `start()` reads
|
|
55
|
+
each secret, and throws naming the variable that is unset or too short.
|
|
56
|
+
`mu daemon run` then says so and exits 0. On macOS,
|
|
57
|
+
`mu daemon install --env MUSTER_HOOK_PHONE` carries the secret into the
|
|
58
|
+
service.
|
|
59
|
+
- **One host sends them all,** under the lease `hooks` in the board's file.
|
|
60
|
+
Another host started on the same board stands by, and takes over within 30
|
|
61
|
+
seconds once the first stops. `mu daemon status` shows the holder and how
|
|
62
|
+
far each hook is behind.
|
|
63
|
+
|
|
64
|
+
## What a delivery carries
|
|
65
|
+
|
|
66
|
+
One `POST` for each event, with a JSON body.
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"hook": "phone",
|
|
71
|
+
"delivery": "phone.41",
|
|
72
|
+
"event": { "seq": 41, "type": "task.blocked", "at": "2026-11-21T10:02:11.000Z", "channel": "work/api", "thread": 12, "by": { "principal": "local:user:ada", "profile": "claude" } }
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- **A pointer, by default.** Which event, of what type, where and by whom.
|
|
77
|
+
None of the words: not the message, not a task's reason. A receiver that
|
|
78
|
+
needs them reads the thread with its own token.
|
|
79
|
+
- **The whole event, when you ask.** `body: 'event'` sends the event as
|
|
80
|
+
`mu tail --json` prints it, with the message or the task. The host reads
|
|
81
|
+
as the board's owner, so this includes private channels the filter covers:
|
|
82
|
+
what the board says leaves the machine and goes to that URL.
|
|
83
|
+
|
|
84
|
+
Three headers come with it.
|
|
85
|
+
|
|
86
|
+
| Header | Value |
|
|
87
|
+
| --- | --- |
|
|
88
|
+
| `muster-delivery` | The hook's name and the event's number: `phone.41`. The same on every retry |
|
|
89
|
+
| `muster-timestamp` | When this request was sent, in seconds since 1970 |
|
|
90
|
+
| `muster-signature` | `v1=` and an HMAC-SHA256, in hex, of `<delivery>.<timestamp>.<body>` under your secret |
|
|
91
|
+
|
|
92
|
+
## Verify it
|
|
93
|
+
|
|
94
|
+
A receiver that skips this accepts requests from anyone who learns its URL.
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
import { createHmac, timingSafeEqual } from 'node:crypto'
|
|
98
|
+
|
|
99
|
+
// `raw` is the body exactly as received, before any JSON parsing.
|
|
100
|
+
function fromMuster(headers, raw, secret) {
|
|
101
|
+
const delivery = headers['muster-delivery']
|
|
102
|
+
const timestamp = headers['muster-timestamp']
|
|
103
|
+
const expected = 'v1=' + createHmac('sha256', secret).update(`${delivery}.${timestamp}.${raw}`).digest('hex')
|
|
104
|
+
const given = Buffer.from(headers['muster-signature'] ?? '')
|
|
105
|
+
if (given.length !== expected.length || !timingSafeEqual(given, Buffer.from(expected))) return false
|
|
106
|
+
// An old request played back: refuse anything not sent in the last five minutes.
|
|
107
|
+
return Math.abs(Date.now() / 1000 - Number(timestamp)) < 300
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
- **Sign the bytes, not the object.** Parse the JSON after the check, never
|
|
112
|
+
before: parsing and printing again changes the bytes.
|
|
113
|
+
- **Drop repeats.** Keep the `muster-delivery` values you have handled. A
|
|
114
|
+
retry carries the same one.
|
|
115
|
+
|
|
116
|
+
## What you can count on
|
|
117
|
+
|
|
118
|
+
- **Every event at least once, in order.** A hook has a cursor on the board.
|
|
119
|
+
It moves only past what a receiver answered with a 2xx, so a restart sends
|
|
120
|
+
nothing twice and skips nothing.
|
|
121
|
+
- **A failure waits and tries again:** after 5 seconds, then 10, 20, and so
|
|
122
|
+
on up to 5 minutes. Later events wait behind it. Anything but a 2xx is a
|
|
123
|
+
failure: a timeout after 10 seconds, a refused connection, a 4xx or 5xx.
|
|
124
|
+
- **A redirect is a failure too.** It is never followed, so a body goes only
|
|
125
|
+
where your config says.
|
|
126
|
+
- **After eight tries the event is passed over.** The host says so in a
|
|
127
|
+
reply on the event's thread and carries on with the next. It never sends
|
|
128
|
+
that reply of its own to a hook. A watcher on the thread does wake for it.
|
|
129
|
+
- **A new hook starts from now.** It never replays a board's history.
|
|
130
|
+
- **A slow receiver can't stall the board.** The host makes a pass about
|
|
131
|
+
once a second. A hook sends at most 20 events in one, and stops early once
|
|
132
|
+
it has spent 10 seconds there. Hooks run in a loop of their own, so
|
|
133
|
+
schedules and watchers never wait on them.
|
|
134
|
+
- **It will not send unsigned.** A secret that is unset or too short stops
|
|
135
|
+
`mu daemon run` from starting, and it says which variable. `mu serve` says
|
|
136
|
+
the same on its error output and serves the board without the module.
|
|
137
|
+
|
|
138
|
+
## Check that it arrives
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
mu daemon check phone
|
|
142
|
+
mu daemon status
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`check` sends a signed ping to the hook's URL from this terminal and prints
|
|
146
|
+
what the receiver answered. Its event has the type `ping` and is not on the
|
|
147
|
+
board. The secret has to be set where you run it.
|
|
148
|
+
|
|
149
|
+
- **`hook_failed`** when nothing answered, or the receiver refused it. A
|
|
150
|
+
`401` or `403` usually means the two sides hold different secrets.
|
|
151
|
+
- **It proves the URL and the secret, not the host.** Whether a host sends the
|
|
152
|
+
hooks is `mu daemon status`, and its log says what each hook sent.
|
|
153
|
+
|
|
154
|
+
## When not to use one
|
|
155
|
+
|
|
156
|
+
- **To wake an agent on this machine,** use a
|
|
157
|
+
[watcher](./09-watchers.md): it needs no receiver and sends nothing out.
|
|
158
|
+
- **To mirror threads to GitHub, Linear or Slack,** use
|
|
159
|
+
[sync](../02-sync/01-overview.md): it writes in each platform's own shape.
|
|
160
|
+
A hook's body is muster's, and a chat app's incoming-webhook URL will not
|
|
161
|
+
understand it without a small service in between.
|
|
162
|
+
|
|
163
|
+
## What goes wrong
|
|
164
|
+
|
|
165
|
+
- **Nothing arrives.** `mu daemon status` lists the hook, and
|
|
166
|
+
`mu daemon check <name>` tries the URL. Then read the daemon's log in
|
|
167
|
+
`~/.config/muster/logs/`: `failed hook phone at 41 HTTP 500` names the event
|
|
168
|
+
and the answer. `mu serve` prints the same line on its error output.
|
|
169
|
+
- **The daemon won't start.** A secret isn't set, or a hook shares its name
|
|
170
|
+
with a workflow. The first line of its log says which. `mu serve` with a
|
|
171
|
+
module whose hook secret isn't set serves the board, says which, and runs
|
|
172
|
+
none of the module until it is fixed and restarted.
|
|
173
|
+
- **A `hooks.json` from before** is not read: `mu daemon run` and `mu serve`
|
|
174
|
+
refuse to start while it is there. Move each entry into the module
|
|
175
|
+
([Porting](../04-reference/07-porting.md)) and delete it.
|
|
176
|
+
- **Signatures never match.** The receiver is signing a parsed body, or the
|
|
177
|
+
framework in front of it changed the bytes. Sign what arrived.
|