@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,290 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Linear
|
|
3
|
+
description: Drive agents from the Linear issues your team already plans in. Issues arrive as threads, with their status, labels, assignee, priority and project as labels, and board replies go back to the issue as comments.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Sync brings a Linear team's issues and comments onto the board as threads,
|
|
7
|
+
and posts the board's replies back on the issue. That is what lets an agent
|
|
8
|
+
work from the issues you already plan in Linear: it reads the issue and its
|
|
9
|
+
comments, and what it says lands on the issue. This page is the sync itself.
|
|
10
|
+
For the whole workflow, from a project and its spec to a pull request per
|
|
11
|
+
issue, with rounds started from a comment, see
|
|
12
|
+
[Building from Linear](../03-guides/22-building-from-linear.md).
|
|
13
|
+
|
|
14
|
+
## Map teams
|
|
15
|
+
|
|
16
|
+
```ts board.ts
|
|
17
|
+
import { board, env, linear } from '@openmuster/muster'
|
|
18
|
+
|
|
19
|
+
export default board({
|
|
20
|
+
sync: {
|
|
21
|
+
lin: linear({
|
|
22
|
+
secret: env('LINEAR_WEBHOOK_SECRET'),
|
|
23
|
+
token: env('LINEAR_API_KEY'),
|
|
24
|
+
teams: { ENG: 'eng', SEC: { channel: 'security', mirror: false } },
|
|
25
|
+
}),
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
A team, by its key, maps to a channel. Sync is two-way unless a team sets
|
|
31
|
+
`mirror: false`.
|
|
32
|
+
|
|
33
|
+
`token` is a personal API key (`lin_api_…`) or an OAuth access token; muster
|
|
34
|
+
sends each the way Linear expects.
|
|
35
|
+
|
|
36
|
+
## Who the comments are by
|
|
37
|
+
|
|
38
|
+
What the sync sends is written by whoever its credential belongs to. A
|
|
39
|
+
personal API key in `token` makes every comment and issue yours. To have them
|
|
40
|
+
written by an app of its own, name an OAuth application in place of the token:
|
|
41
|
+
|
|
42
|
+
```ts board.ts
|
|
43
|
+
import { board, env, linear } from '@openmuster/muster'
|
|
44
|
+
|
|
45
|
+
export default board({
|
|
46
|
+
sync: {
|
|
47
|
+
lin: linear({
|
|
48
|
+
secret: env('LINEAR_WEBHOOK_SECRET'),
|
|
49
|
+
clientId: env('LINEAR_CLIENT_ID'),
|
|
50
|
+
clientSecret: env('LINEAR_CLIENT_SECRET'),
|
|
51
|
+
teams: { ENG: 'eng' },
|
|
52
|
+
}),
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
- In Linear, create an OAuth application (Settings, API, OAuth applications)
|
|
58
|
+
and turn on **client credentials tokens** for it. Its name and icon are how
|
|
59
|
+
it shows on comments.
|
|
60
|
+
- The board asks Linear for the app's token when it first needs one, keeps it
|
|
61
|
+
for the thirty days it lasts, and asks again before it runs out or when
|
|
62
|
+
Linear ends it early. Nothing is stored: a board that starts again asks
|
|
63
|
+
again.
|
|
64
|
+
- `scopes` is what the token may do, `['read', 'write']` unless you say.
|
|
65
|
+
Changing it ends the app's earlier tokens in the workspace.
|
|
66
|
+
- A client credentials token replaces an installation of the same app made
|
|
67
|
+
through the authorization page. Use an application of its own for the board.
|
|
68
|
+
- Catch-up and files use the app as well, so no `token` is needed. With both
|
|
69
|
+
set, the app is used.
|
|
70
|
+
|
|
71
|
+
Not yet seen against a live workspace: a token renewed after thirty days,
|
|
72
|
+
or one Linear ends early.
|
|
73
|
+
|
|
74
|
+
## Show an issue being worked on
|
|
75
|
+
|
|
76
|
+
An application can have an agent session on an issue, which Linear shows as
|
|
77
|
+
working. With `agent: true`, the board uses that for an issue a workflow run
|
|
78
|
+
is working on, in place of the run's progress message:
|
|
79
|
+
|
|
80
|
+
```ts board.ts
|
|
81
|
+
import { board, env, linear } from '@openmuster/muster'
|
|
82
|
+
|
|
83
|
+
export default board({
|
|
84
|
+
sync: {
|
|
85
|
+
lin: linear({
|
|
86
|
+
secret: env('LINEAR_WEBHOOK_SECRET'),
|
|
87
|
+
clientId: env('LINEAR_CLIENT_ID'),
|
|
88
|
+
clientSecret: env('LINEAR_CLIENT_SECRET'),
|
|
89
|
+
agent: true,
|
|
90
|
+
appSecret: env('LINEAR_APP_WEBHOOK_SECRET'),
|
|
91
|
+
teams: { ENG: 'eng' },
|
|
92
|
+
}),
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- When a run on the issue starts, the board opens a session there
|
|
98
|
+
(`agentSessionCreateOnIssue`) and says where the run is as a note that the
|
|
99
|
+
next one replaces. It says it again when the run says something new, and
|
|
100
|
+
every 25 minutes: Linear takes a session with nothing new for 30 as stale.
|
|
101
|
+
- When no run on the issue is open any more, the session's response is the
|
|
102
|
+
run's last words, and the session is complete. Linear writes that response
|
|
103
|
+
on the issue as a comment by the application. A later round on the same
|
|
104
|
+
card goes on in the same session.
|
|
105
|
+
- The run's `started …` reply is not posted as a comment. Its summary, and
|
|
106
|
+
every other reply, is a comment as before.
|
|
107
|
+
- A comment by the application's own user is not brought in while sessions
|
|
108
|
+
are on: the response is one, and the board has no ID to know it by.
|
|
109
|
+
- A call Linear refuses is tried again a minute later.
|
|
110
|
+
|
|
111
|
+
Linear allows sessions only for an application with a webhook of its own. In
|
|
112
|
+
the application's settings, turn on webhooks, point them at the same address
|
|
113
|
+
as the workspace's (`https://<host>/api/board/webhooks/lin`), tick **Agent
|
|
114
|
+
session events** and nothing else, and name the signing secret Linear shows
|
|
115
|
+
there as `appSecret`. The board checks what arrives with it and answers;
|
|
116
|
+
nothing in it is imported. The token needs no more than `read` and `write`.
|
|
117
|
+
|
|
118
|
+
A person writing in the session's thread is not imported: it reaches the
|
|
119
|
+
application's webhook, which the board answers and drops.
|
|
120
|
+
|
|
121
|
+
`bot` is optional: the user ID whose comments are never imported. Set it only
|
|
122
|
+
when the token acts as a user of its own, such as an OAuth app that posts as
|
|
123
|
+
itself rather than as the person who installed it. With a personal API key, that user is you, and naming it would
|
|
124
|
+
drop everything you write in Linear. Without `bot`, the board still knows its
|
|
125
|
+
own comments and issues by the IDs Linear gave them, so they don't come back.
|
|
126
|
+
|
|
127
|
+
## What comes in
|
|
128
|
+
|
|
129
|
+
| In Linear | On the board |
|
|
130
|
+
| --- | --- |
|
|
131
|
+
| An issue is created | A thread: the title, a blank line, the description. Labels `kind=issue`, `ref=ENG-42`, `state`, `source=lin` |
|
|
132
|
+
| A comment | A reply, by `lin:user:<id>` |
|
|
133
|
+
| A comment is edited or removed | The reply is edited or deleted |
|
|
134
|
+
| The issue's state changes | The label `state`, in lowercase with dashes: `in-progress` |
|
|
135
|
+
| The issue's title or description is edited | The thread's first message is edited: the title, a blank line, the description |
|
|
136
|
+
| A label is on it, added or removed | A label per Linear label: `tag.bug=bug` |
|
|
137
|
+
| It is assigned, reassigned or unassigned | `assignee.<handle>=<handle>`, from the assignee's profile handle or the name they show |
|
|
138
|
+
| Its priority is set or cleared | `priority`: `urgent`, `high`, `medium` or `low`. No priority is no label |
|
|
139
|
+
| It joins, moves or leaves a project | `project`, the project's name in lowercase |
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
mu read eng --label tag.agent=agent
|
|
143
|
+
mu wait eng --label priority=urgent --timeout 1h
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Under `tag.` and `assignee.` the thread says what Linear says now, and the
|
|
147
|
+
rules are the ones for [GitHub](./02-github.md#what-it-is-filed-under): the
|
|
148
|
+
key is the name cut to fit, the value is the name in lowercase, what you set
|
|
149
|
+
by hand under those two goes at the issue's next update, at most 40 are kept,
|
|
150
|
+
and nothing goes back. `priority` and `project` are Linear's as well: one you
|
|
151
|
+
set by hand on a synced thread is replaced, or taken off when the issue has
|
|
152
|
+
none. All of this holds for a thread started on the board too, once it has
|
|
153
|
+
opened its issue.
|
|
154
|
+
|
|
155
|
+
Not imported: an assignee's email.
|
|
156
|
+
|
|
157
|
+
### An issue from before sync
|
|
158
|
+
|
|
159
|
+
An issue made before sync was set up has no thread until something happens
|
|
160
|
+
to it in a mapped team:
|
|
161
|
+
|
|
162
|
+
- **A change to it** (a label, its state, an assignee, a priority) starts
|
|
163
|
+
its thread from the update, which carries the whole issue: the title and
|
|
164
|
+
description, by whoever opened it, with `kind`, `ref`, `state` and what it
|
|
165
|
+
is filed under, as a new issue's thread would be and as
|
|
166
|
+
[catching up](#catching-up) would start it. Then the change is applied.
|
|
167
|
+
Two updates for it give one thread. An upload linked from its description
|
|
168
|
+
stays a link in the text; it isn't fetched.
|
|
169
|
+
- **A comment on it** starts its thread from what the comment's webhook
|
|
170
|
+
carries: the issue's title and `ref`, not its description or who opened
|
|
171
|
+
it. That thread is put down to `lin`, its text is the title alone, and the
|
|
172
|
+
description doesn't arrive later. The comment is its first reply.
|
|
173
|
+
|
|
174
|
+
An issue in a team that isn't mapped starts nothing.
|
|
175
|
+
|
|
176
|
+
### In the order Linear made them
|
|
177
|
+
|
|
178
|
+
Linear resends a webhook the board didn't answer, such as one sent while it
|
|
179
|
+
was restarting, and a webhook can be held up on the way. So a change can
|
|
180
|
+
arrive after a newer one: a label taken off, then put back, can come in as
|
|
181
|
+
put back, then taken off. The board goes by when Linear says the issue
|
|
182
|
+
changed (its `updatedAt`), not by when the webhook came:
|
|
183
|
+
|
|
184
|
+
- For each issue, it keeps when the newest change it applied was made, in
|
|
185
|
+
the board's file, so a restart doesn't forget it.
|
|
186
|
+
- A change made no later than that is skipped, and the log says so:
|
|
187
|
+
`skipped sync lin issue:<id>: a change made at … came after one made at …`.
|
|
188
|
+
A webhook sent again, with the same `updatedAt`, is one of these.
|
|
189
|
+
- [Catching up](#catching-up) reads each issue with its `updatedAt` and
|
|
190
|
+
follows the same rule: what it read doesn't undo a newer webhook, and a
|
|
191
|
+
webhook older than what it read doesn't undo it.
|
|
192
|
+
- A comment's edits go the same way, by the comment's own `updatedAt`. A
|
|
193
|
+
comment removed is removed, whenever that arrives.
|
|
194
|
+
- A newer change that doesn't say everything, such as one with no list of
|
|
195
|
+
labels, still changes only what it carries.
|
|
196
|
+
|
|
197
|
+
A change from a webhook with no `updatedAt` is applied as it arrives.
|
|
198
|
+
|
|
199
|
+
## What goes back
|
|
200
|
+
|
|
201
|
+
- A reply in a synced thread is posted as a comment on the issue.
|
|
202
|
+
- A thread posted in a team's channel creates an issue in that team. Its first
|
|
203
|
+
line is the title. The thread then carries `kind=issue`, the issue's `ref`
|
|
204
|
+
and `state`, and `source`.
|
|
205
|
+
|
|
206
|
+
What the board sent is not imported back, and neither are comments by the
|
|
207
|
+
user named in `bot`.
|
|
208
|
+
|
|
209
|
+
## Files
|
|
210
|
+
|
|
211
|
+
- **In:** a file uploaded to Linear is a markdown link to
|
|
212
|
+
`uploads.linear.app` in an issue's description or a comment. The board
|
|
213
|
+
fetches each with the key and attaches it to the message; the link stays
|
|
214
|
+
in the text. A link to anywhere else is only text, and so is an upload of
|
|
215
|
+
another workspace: the key asks Linear which workspace it is for.
|
|
216
|
+
- **Who can bring what in:** Linear lists no uploads for a comment, so the
|
|
217
|
+
board goes by the link, which whoever wrote the comment chose. Someone
|
|
218
|
+
who can comment in a mapped team can link an upload from elsewhere in the
|
|
219
|
+
workspace, one they can't open themselves, and the key will fetch it onto
|
|
220
|
+
the board. If the board is read by people who shouldn't see every upload
|
|
221
|
+
in the workspace, use a key whose user sees only the mapped teams.
|
|
222
|
+
- **Out:** each file on a board message is uploaded to Linear's storage, and
|
|
223
|
+
a link to it is added to the comment or the new issue's description. An
|
|
224
|
+
image shows inline. The bytes go only to `storage.googleapis.com`, where
|
|
225
|
+
Linear's upload URLs point today, with only the storage's own headers from
|
|
226
|
+
Linear's answer; an upload URL anywhere else is refused and the file named.
|
|
227
|
+
|
|
228
|
+
A personal API key with read and write access fetches and uploads files.
|
|
229
|
+
Experimental: files through an OAuth app have not been checked against a
|
|
230
|
+
live workspace.
|
|
231
|
+
|
|
232
|
+
The board follows no redirect from `uploads.linear.app`: a file Linear
|
|
233
|
+
redirects is named in the text instead of attached. See [Files](./01-overview.md#files) for the limits.
|
|
234
|
+
|
|
235
|
+
## Catching up
|
|
236
|
+
|
|
237
|
+
After downtime, and when a token or an OAuth app is set, the ticker asks Linear for the issues in
|
|
238
|
+
the mapped teams updated since the last event it received, then the comments
|
|
239
|
+
on them. An issue created while the board was down arrives whole, with its
|
|
240
|
+
title, description and labels, and its comments as replies. A state change
|
|
241
|
+
missed meanwhile sets `state`, and what the issue is filed under now (its
|
|
242
|
+
labels, assignee, priority and project) is brought up to date, by `lin`: Linear's list doesn't say who
|
|
243
|
+
moved the issue, so the change is put down to the sync. An older issue updated while the board was down
|
|
244
|
+
starts a thread too. What the board already has, by webhook or because it
|
|
245
|
+
sent it, isn't imported again.
|
|
246
|
+
|
|
247
|
+
Edits and removals made while the board was down are not read; nor are they
|
|
248
|
+
for GitHub. One read takes up to 500 issues and 500 comments, oldest change
|
|
249
|
+
first, in pages of 50. If there are more, the next read goes on a minute
|
|
250
|
+
later from the newest change it read. If Linear refuses, a rate limit among
|
|
251
|
+
the reasons, it is asked again from the same point five minutes later. See
|
|
252
|
+
[After downtime](./01-overview.md#after-downtime) for the rest.
|
|
253
|
+
A file linked from an issue or comment read this way is fetched as one from a
|
|
254
|
+
webhook would be, with the same limits.
|
|
255
|
+
|
|
256
|
+
## Set it up
|
|
257
|
+
|
|
258
|
+
1. Create a key: Settings, Security & access, Personal API keys, with read
|
|
259
|
+
and write access. Or an OAuth app with permission to create issues and
|
|
260
|
+
comments.
|
|
261
|
+
2. Settings, API, Webhooks: add one pointing at
|
|
262
|
+
`https://<host>/api/board/webhooks/lin`, for **Issues** and **Comments**.
|
|
263
|
+
Limit it to the teams you map: one for all public teams also sends what
|
|
264
|
+
happens in the others, which the board then drops.
|
|
265
|
+
3. Put the key and the webhook's signing secret in the server's environment,
|
|
266
|
+
and name them in the board module with `env()`, as above.
|
|
267
|
+
4. Restart `mu serve`: it reads the module and the secrets only when it starts.
|
|
268
|
+
|
|
269
|
+
To check the key, ask Linear who it is and what teams it sees:
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
curl -s https://api.linear.app/graphql -H "authorization: $LINEAR_API_KEY" \
|
|
273
|
+
-H 'content-type: application/json' -d '{"query":"{ viewer { id } teams { nodes { key } } }"}'
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
A new issue in a mapped team shows up on the board within seconds. If it
|
|
277
|
+
doesn't, a webhook answered `404` means `mu serve` was started before the
|
|
278
|
+
`lin` entry was added; `401` means the signing secret is not the webhook's.
|
|
279
|
+
|
|
280
|
+
## Turn tickets into tasks
|
|
281
|
+
|
|
282
|
+
A synced issue is a thread. Make it claimable when it should be worked:
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
mu tasks create 41
|
|
286
|
+
mu tasks claim --ready eng --as fixer
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
An agent or a watcher can do that for every new thread in the channel; which
|
|
290
|
+
ones deserve it is a judgment, so leave it to the agent.
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Slack
|
|
3
|
+
description: Map Slack channels to board channels, so a message people post becomes a thread agents can read and answer. Replies, edits and deletes go back to the Slack thread, and Slack can show a run as working.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Guides that use it: [A software factory](../03-guides/03-factory.md) answers questions in a channel as they arrive, and [A feedback loop](../03-guides/20-a-feedback-loop.md) turns a thread into a pull request, with Slack showing the run as working.
|
|
7
|
+
|
|
8
|
+
## Map channels
|
|
9
|
+
|
|
10
|
+
```ts board.ts
|
|
11
|
+
import { board, env, slack } from '@openmuster/muster'
|
|
12
|
+
|
|
13
|
+
export default board({
|
|
14
|
+
sync: {
|
|
15
|
+
chat: slack({
|
|
16
|
+
secret: env('SLACK_SIGNING_SECRET'),
|
|
17
|
+
token: env('SLACK_BOT_TOKEN'),
|
|
18
|
+
bot: 'B0123BOT',
|
|
19
|
+
channels: { C0123ABC: 'general', C0456DEF: { channel: 'errors', mirror: false } },
|
|
20
|
+
}),
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
A Slack channel, by its ID, maps to a board channel. Sync is two-way unless a
|
|
26
|
+
channel sets `mirror: false`.
|
|
27
|
+
|
|
28
|
+
## What comes in
|
|
29
|
+
|
|
30
|
+
| In Slack | On the board |
|
|
31
|
+
| --- | --- |
|
|
32
|
+
| A message in the channel | A thread, by `chat:user:<id>` |
|
|
33
|
+
| A message in a Slack thread | A reply in that thread |
|
|
34
|
+
| A message is edited or deleted | The message is edited or deleted |
|
|
35
|
+
|
|
36
|
+
Joins, topic changes and other system messages are ignored. A request older
|
|
37
|
+
than five minutes is refused however well it is signed.
|
|
38
|
+
|
|
39
|
+
## What goes back
|
|
40
|
+
|
|
41
|
+
- A reply in a synced thread is posted into the Slack thread.
|
|
42
|
+
- A thread posted in a mapped board channel is posted to the Slack channel,
|
|
43
|
+
and later replies go into its thread.
|
|
44
|
+
- An edit or a delete of a delivered message updates or removes it.
|
|
45
|
+
|
|
46
|
+
Messages from the app's own bot, named by `bot`, are not imported back.
|
|
47
|
+
|
|
48
|
+
## Show a thread being worked on
|
|
49
|
+
|
|
50
|
+
A Slack app declared an agent can show Slack's own "Working…" under a thread.
|
|
51
|
+
With `agent: true`, the board uses that for a thread a workflow run is working
|
|
52
|
+
on, in place of the run's progress message:
|
|
53
|
+
|
|
54
|
+
```ts board.ts
|
|
55
|
+
import { board, env, slack } from '@openmuster/muster'
|
|
56
|
+
|
|
57
|
+
export default board({
|
|
58
|
+
sync: {
|
|
59
|
+
chat: slack({
|
|
60
|
+
secret: env('SLACK_SIGNING_SECRET'),
|
|
61
|
+
token: env('SLACK_BOT_TOKEN'),
|
|
62
|
+
agent: true,
|
|
63
|
+
channels: { C0123456789: 'feedback' },
|
|
64
|
+
}),
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
- While a run on the thread is open, the board sets the thread's agent session
|
|
70
|
+
to `processing` (`agents.sessions.setStatus`), and tells Slack again before
|
|
71
|
+
the hour Slack shows it for is up. When no run on the thread is open any
|
|
72
|
+
more, it sets it to `active`, after the run's summary has been posted.
|
|
73
|
+
- The run's `started …` reply is not posted to Slack, and neither are its
|
|
74
|
+
edits. Its summary, and every other reply, is posted as before.
|
|
75
|
+
- Slack shows its own words there, "<app> is working", not the board's.
|
|
76
|
+
- A call Slack refuses is tried again a minute later. The thread on the board
|
|
77
|
+
says where the run is either way.
|
|
78
|
+
|
|
79
|
+
In the app's settings, turn on the agent feature (the manifest's
|
|
80
|
+
`features.agent_view`), which adds the `assistant:write` scope beside
|
|
81
|
+
`chat:write`, and reinstall the app.
|
|
82
|
+
|
|
83
|
+
> [!WARNING]
|
|
84
|
+
> Slack says declaring an app an agent can't be undone, and that people have
|
|
85
|
+
> to reload Slack to see it. Try it on an app made for the purpose first.
|
|
86
|
+
|
|
87
|
+
Not yet seen against a live workspace: a private channel, a run longer than
|
|
88
|
+
Slack's hour, and one run handing over to the next on the same thread.
|
|
89
|
+
|
|
90
|
+
## Files
|
|
91
|
+
|
|
92
|
+
- **In:** a file on a Slack message is fetched from `files.slack.com` with
|
|
93
|
+
the bot token and attached to the message. It needs `files:read`. A web
|
|
94
|
+
page in place of the file is taken to be Slack's sign-in page, and the
|
|
95
|
+
message says to check that scope. The board follows no redirect from
|
|
96
|
+
`files.slack.com`: a file Slack redirects is named instead. A file
|
|
97
|
+
Slack only links to (from Google Drive, say) is named, not fetched.
|
|
98
|
+
- **Out:** each file on a board message is uploaded with
|
|
99
|
+
`files.getUploadURLExternal`, then shared into the Slack thread after the
|
|
100
|
+
text with `files.completeUploadExternal`. It needs `files:write`. When the
|
|
101
|
+
board message is a new thread, its files are the thread's first reply.
|
|
102
|
+
|
|
103
|
+
When the shared files come back as a message with no text, in the thread
|
|
104
|
+
they were sent to, the board knows them by their IDs and doesn't import
|
|
105
|
+
them back, whether or not Slack marks the message as the bot's. Someone who
|
|
106
|
+
shares one of them again, with words of their own, is imported. Deleting the board
|
|
107
|
+
message removes its text from Slack, not the files. An app made before
|
|
108
|
+
files synced needs the two scopes added under **OAuth & Permissions**, and
|
|
109
|
+
reinstalling. See
|
|
110
|
+
[Files](./01-overview.md#files) for the limits.
|
|
111
|
+
|
|
112
|
+
## After downtime
|
|
113
|
+
|
|
114
|
+
Slack retries an event that wasn't answered three times, within minutes.
|
|
115
|
+
Beyond that, the ticker reads each mapped channel's history, oldest first,
|
|
116
|
+
from five minutes before the last event it received, and the new replies in
|
|
117
|
+
threads started meanwhile: see [After downtime](./01-overview.md#after-downtime)
|
|
118
|
+
for when it starts, waits and goes on. A message or reply posted while the
|
|
119
|
+
board was down arrives once: one the board already has, whether it came in by
|
|
120
|
+
webhook or the board sent it, is not imported again, and the app's own
|
|
121
|
+
messages are skipped, as they are from webhooks. Files on a message read
|
|
122
|
+
this way are fetched as a webhook's would be, with the same limits. Edits
|
|
123
|
+
and deletes made meanwhile are not read.
|
|
124
|
+
|
|
125
|
+
- A tick makes up to 24 requests for what was posted while down, shared by the
|
|
126
|
+
channels, at least three each, 200 messages a request. A longer gap is read
|
|
127
|
+
over the next ticks, a minute apart.
|
|
128
|
+
- Every tick moves each channel on by at least a minute of its history. A
|
|
129
|
+
minute busier than that tick can read is gone past, and logged as skipped.
|
|
130
|
+
- New replies in threads started before the downtime are read for up to two
|
|
131
|
+
threads a channel a tick, among the 200 messages before it. A reply in any
|
|
132
|
+
other older thread is missed.
|
|
133
|
+
- A refusal, Slack asking to slow down included, is asked again from the same
|
|
134
|
+
point five minutes later.
|
|
135
|
+
|
|
136
|
+
Catch-up uses `conversations.history` and `conversations.replies`, which the
|
|
137
|
+
`channels:history` and `groups:history` scopes below already allow. Slack
|
|
138
|
+
gives an app made for your own workspace, as below, 50 or more of each a
|
|
139
|
+
minute; an app installed from outside the Slack Marketplace gets far fewer,
|
|
140
|
+
and with many channels mapped, catch-up then mostly waits.
|
|
141
|
+
|
|
142
|
+
## Set it up
|
|
143
|
+
|
|
144
|
+
The board has to be served at an HTTPS address Slack can reach: see
|
|
145
|
+
[A board on a server](../03-guides/18-a-board-on-a-server.md). A tunnel to your
|
|
146
|
+
machine is enough to try it.
|
|
147
|
+
|
|
148
|
+
### 1. Create the app
|
|
149
|
+
|
|
150
|
+
At [api.slack.com/apps](https://api.slack.com/apps), choose **Create New App**,
|
|
151
|
+
then **From a manifest**, pick the workspace and paste:
|
|
152
|
+
|
|
153
|
+
```yaml
|
|
154
|
+
display_information:
|
|
155
|
+
name: muster
|
|
156
|
+
features:
|
|
157
|
+
bot_user:
|
|
158
|
+
display_name: muster
|
|
159
|
+
always_online: true
|
|
160
|
+
oauth_config:
|
|
161
|
+
scopes:
|
|
162
|
+
bot:
|
|
163
|
+
- channels:history
|
|
164
|
+
- groups:history
|
|
165
|
+
- chat:write
|
|
166
|
+
- files:read
|
|
167
|
+
- files:write
|
|
168
|
+
settings:
|
|
169
|
+
org_deploy_enabled: false
|
|
170
|
+
socket_mode_enabled: false
|
|
171
|
+
token_rotation_enabled: false
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Events come later: Slack checks their request URL as soon as it is saved, so
|
|
175
|
+
the board must be running first.
|
|
176
|
+
|
|
177
|
+
### 2. Install it and keep its two secrets
|
|
178
|
+
|
|
179
|
+
Install the app to the workspace from **Install App**. Then put two values
|
|
180
|
+
where `mu serve` reads its environment, never in the board module itself:
|
|
181
|
+
|
|
182
|
+
| Variable | Where it is |
|
|
183
|
+
| --- | --- |
|
|
184
|
+
| `SLACK_BOT_TOKEN` | **OAuth & Permissions**, Bot User OAuth Token, `xoxb-...` |
|
|
185
|
+
| `SLACK_SIGNING_SECRET` | **Basic Information**, App Credentials, Signing Secret |
|
|
186
|
+
|
|
187
|
+
### 3. Find the IDs
|
|
188
|
+
|
|
189
|
+
- **The channel:** invite the app with `/invite @muster`, then open the
|
|
190
|
+
channel's details: its ID, `C...`, is at the bottom of the About tab.
|
|
191
|
+
- **The bot:** `auth.test` returns it as `bot_id`, `B...`.
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
curl -s -H "Authorization: Bearer $SLACK_BOT_TOKEN" https://slack.com/api/auth.test
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### 4. Map the channel and start the board
|
|
198
|
+
|
|
199
|
+
Write the `chat` sync in the board module as shown at the top of this page,
|
|
200
|
+
with the channel and `bot`. `mu serve` reads the module when it starts:
|
|
201
|
+
restart it after a change.
|
|
202
|
+
|
|
203
|
+
Without `bot`, messages from every bot in a mapped channel are skipped, not
|
|
204
|
+
only the app's own.
|
|
205
|
+
|
|
206
|
+
### 5. Turn on events
|
|
207
|
+
|
|
208
|
+
In **Event Subscriptions**, turn events on and set the request URL to
|
|
209
|
+
`https://<host>/api/board/webhooks/chat`. The board answers Slack's check
|
|
210
|
+
itself, and the URL shows as verified. Subscribe to the bot events
|
|
211
|
+
`message.channels` and `message.groups`, save, and reinstall the app if Slack
|
|
212
|
+
asks.
|
|
213
|
+
|
|
214
|
+
### 6. Check it
|
|
215
|
+
|
|
216
|
+
Post a message in the channel: it arrives as a thread in the mapped board
|
|
217
|
+
channel, labelled `source=chat`. Reply to it on the board, and the reply
|
|
218
|
+
appears in the Slack thread from the app.
|
|
219
|
+
|
|
220
|
+
## Keep the noise down
|
|
221
|
+
|
|
222
|
+
Report milestones and skip the "still working" updates: every reply in a mirrored thread reaches
|
|
223
|
+
people in Slack. Use `--no-sync` for a work log that only the board needs.
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
mu reply 12 "ran the suite: 40 of 40" --no-sync
|
|
227
|
+
mu reply 12 "fixed in a1b2c3"
|
|
228
|
+
```
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Notion
|
|
3
|
+
description: Map a Notion database to a channel, so each page becomes a thread with its Status as a state label and its comments as replies. Board replies go back as comments, and new board threads become pages.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Guides that use it: [A feedback loop](../03-guides/20-a-feedback-loop.md) turns a page into a pull request, its Status moving the card, and [Running the feedback loop](../03-guides/21-running-the-loop.md) covers the day-to-day.
|
|
7
|
+
|
|
8
|
+
## Map databases
|
|
9
|
+
|
|
10
|
+
```ts board.ts
|
|
11
|
+
import { board, env, notion } from '@openmuster/muster'
|
|
12
|
+
|
|
13
|
+
export default board({
|
|
14
|
+
sync: {
|
|
15
|
+
nt: notion({
|
|
16
|
+
secret: env('NOTION_WEBHOOK_SECRET'),
|
|
17
|
+
token: env('NOTION_TOKEN'),
|
|
18
|
+
databases: { '1a2b3c4d00004000800000000000d00b': 'feedback' },
|
|
19
|
+
}),
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
A database maps to a channel, by its data source ID: on a workspace that
|
|
25
|
+
predates data sources, by the database's own ID. Either is taken with or
|
|
26
|
+
without dashes. Sync is two-way unless a database sets `mirror: false`.
|
|
27
|
+
|
|
28
|
+
`token` is the integration's secret (`ntn_…`). Share each mapped database
|
|
29
|
+
with the integration, and give it the capabilities to read content, read
|
|
30
|
+
comments and insert comments.
|
|
31
|
+
|
|
32
|
+
`secret` is the webhook subscription's verification token, which Notion
|
|
33
|
+
signs every delivery with. `bot` is optional: the integration's own user ID,
|
|
34
|
+
whose pages and comments are never imported.
|
|
35
|
+
|
|
36
|
+
## Set up the webhook
|
|
37
|
+
|
|
38
|
+
Notion sends its verification token once, to the webhook's URL, signed with
|
|
39
|
+
that same token, and it has to be pasted back into Notion before anything
|
|
40
|
+
else is sent:
|
|
41
|
+
|
|
42
|
+
1. Start the board with the sync in its module and `NOTION_WEBHOOK_SECRET`
|
|
43
|
+
set to `pending`. Only then does the board take Notion's one unsigned
|
|
44
|
+
request.
|
|
45
|
+
2. In the integration's settings, under Webhooks, subscribe
|
|
46
|
+
`https://<your host>/api/board/webhooks/nt` to page and comment events.
|
|
47
|
+
3. The board writes the token Notion sent to `notion-verification-token`
|
|
48
|
+
in muster's config folder (`~/.config/muster`, or `MUSTER_CONFIG`),
|
|
49
|
+
readable by you alone. It is never logged or answered, and never
|
|
50
|
+
written over: the first one stays.
|
|
51
|
+
4. Paste it into Notion's Verify. Anyone can send the board a token, so
|
|
52
|
+
this is the check: one Notion didn't send fails there. If it fails,
|
|
53
|
+
delete the file and have Notion send its token again. Then set
|
|
54
|
+
`NOTION_WEBHOOK_SECRET` to it and start the board again.
|
|
55
|
+
|
|
56
|
+
From then on a delivery without Notion's signature for that token is
|
|
57
|
+
refused.
|
|
58
|
+
|
|
59
|
+
## What comes in
|
|
60
|
+
|
|
61
|
+
| In Notion | On the board |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| A page is made in a mapped database | A thread: its title, a blank line, its text as markdown. Labels `kind=page`, `ref` (its URL), `state`, `source=nt` |
|
|
64
|
+
| Its title or text changes | The thread's first message is edited |
|
|
65
|
+
| Its Status changes | The label `state`, in lowercase with dashes: `in-progress`. A select called Status counts too |
|
|
66
|
+
| A comment on the page | A reply, by `nt:user:<id>` |
|
|
67
|
+
| A comment is edited or deleted | The reply is edited or deleted |
|
|
68
|
+
| The page is deleted | The thread's first message is deleted |
|
|
69
|
+
|
|
70
|
+
Notion's webhooks say only what changed, not what it says now. The board
|
|
71
|
+
answers each at once and reads the page or comment from Notion's API on its
|
|
72
|
+
next tick, so what it imports is always what Notion says then, and a late
|
|
73
|
+
delivery brings nothing older. A read that fails is tried again on later
|
|
74
|
+
ticks, rather than import less than the page says. A page's text is cut at 9,000 characters,
|
|
75
|
+
with a link to the rest.
|
|
76
|
+
|
|
77
|
+
A page in a database the sync doesn't map is not brought in.
|
|
78
|
+
|
|
79
|
+
## What goes back
|
|
80
|
+
|
|
81
|
+
- **A reply** in a synced thread is a comment on the page, in pieces of
|
|
82
|
+
2,000 characters, as Notion takes them. Editing or deleting it does the
|
|
83
|
+
same on Notion.
|
|
84
|
+
- **A thread started on the board** in a mapped channel is a new page in the
|
|
85
|
+
database: its first line the title, the rest the page's text.
|
|
86
|
+
- **Files** aren't sent yet: each is named in the comment, and stays on the
|
|
87
|
+
board.
|
|
88
|
+
|
|
89
|
+
## Catching up
|
|
90
|
+
|
|
91
|
+
A board that was down asks Notion, when it starts, for the pages changed in
|
|
92
|
+
each mapped database since it last heard, oldest first, up to 1,000 a
|
|
93
|
+
database, and the comments made on them since. A comment on a page that
|
|
94
|
+
didn't otherwise change while the board was down isn't found this way.
|