@openmuster/muster 0.3.1-alpha.3 → 0.3.1-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +16 -10
  2. package/dist/{args-DX9QSK1f.js → args-CaFBa2IP.js} +305 -23
  3. package/dist/cli.js +3 -3
  4. package/dist/index.d.ts +67 -18
  5. package/dist/index.js +106 -41
  6. package/dist/inspect/app.js +79 -51
  7. package/dist/{main-DgrIMbeA.js → main-BeEB08iI.js} +397 -26
  8. package/dist/main-CLzQkYeG.js +6 -0
  9. package/dist/mcp-CAAZRJgv.js +6 -0
  10. package/dist/{module-C-HJjWWo.js → module-BX2IjSiv.js} +2 -2
  11. package/dist/{module-CxoN1MOe.js → module-D9KdbEpS.js} +1 -1
  12. package/dist/skills/board/SKILL.md +5 -0
  13. package/dist/{steps-DtzUdcBE.js → steps-FNDWY1P_.js} +16 -4
  14. package/docs/01-concepts/09-watchers.md +4 -32
  15. package/docs/01-concepts/10-schedules.md +1 -1
  16. package/docs/01-concepts/11-access.md +19 -3
  17. package/docs/01-concepts/13-budgets.md +66 -3
  18. package/docs/01-concepts/15-outgoing-webhooks.md +6 -19
  19. package/docs/01-concepts/16-workflows.md +22 -2
  20. package/docs/01-quickstart.md +74 -42
  21. package/docs/02-sync/01-overview.md +34 -2
  22. package/docs/02-sync/02-github.md +40 -19
  23. package/docs/02-sync/03-linear.md +103 -85
  24. package/docs/02-sync/04-slack.md +116 -111
  25. package/docs/02-sync/05-notion.md +46 -25
  26. package/docs/03-guides/01-coding-agents.md +51 -33
  27. package/docs/03-guides/02-swarm.md +30 -15
  28. package/docs/03-guides/03-factory.md +193 -80
  29. package/docs/03-guides/04-inspector.md +79 -29
  30. package/docs/03-guides/05-running-agents.md +62 -35
  31. package/docs/03-guides/06-sandboxed-agents.md +488 -305
  32. package/docs/03-guides/07-build-a-ui.md +86 -31
  33. package/docs/03-guides/08-ci.md +59 -36
  34. package/docs/03-guides/09-daemon.md +121 -53
  35. package/docs/03-guides/10-two-agents.md +31 -22
  36. package/docs/03-guides/11-person-in-the-loop.md +47 -34
  37. package/docs/03-guides/12-unattended.md +46 -27
  38. package/docs/03-guides/13-terminals.md +51 -39
  39. package/docs/03-guides/14-no-cloud.md +31 -19
  40. package/docs/03-guides/15-several-boards.md +61 -27
  41. package/docs/03-guides/16-non-code.md +29 -18
  42. package/docs/03-guides/17-mcp.md +37 -30
  43. package/docs/03-guides/18-a-board-on-a-server.md +66 -43
  44. package/docs/03-guides/19-a-card-queue.md +210 -121
  45. package/docs/03-guides/20-a-feedback-loop.md +298 -134
  46. package/docs/03-guides/21-running-the-loop.md +94 -64
  47. package/docs/03-guides/22-building-from-linear.md +81 -57
  48. package/docs/04-reference/01-cli.md +8 -0
  49. package/docs/04-reference/02-handle.md +10 -15
  50. package/docs/04-reference/03-http.md +1 -1
  51. package/docs/04-reference/04-events.md +2 -1
  52. package/docs/04-reference/05-errors.md +3 -0
  53. package/docs/04-reference/08-files.md +49 -0
  54. package/docs/index.md +22 -0
  55. package/package.json +1 -1
  56. package/dist/main-CdVlnWHy.js +0 -6
  57. package/dist/mcp-NueWYyQs.js +0 -6
package/dist/index.d.ts CHANGED
@@ -1,17 +1,6 @@
1
1
  import { DatabaseSync } from "node:sqlite";
2
2
  import { IncomingMessage, Server, ServerResponse } from "node:http";
3
3
 
4
- //#region src/store/sqlite.d.ts
5
-
6
- /** An open board file. */
7
- type Db = {
8
- readonly raw: DatabaseSync;
9
- readonly path: string;
10
- /** Runs `fn` in one write transaction. Only BEGIN and COMMIT are retried when busy: `fn` runs once. */
11
- write<T$1>(fn: () => T$1): T$1;
12
- close(): void;
13
- };
14
- //#endregion
15
4
  //#region src/model.d.ts
16
5
  /** Who a request is from, as the policy verified it. A request body never says. */
17
6
  type Caller = {
@@ -75,6 +64,16 @@ type BoardEvent = {
75
64
  data: Record<string, unknown>;
76
65
  };
77
66
  //#endregion
67
+ //#region src/store/sqlite.d.ts
68
+ /** An open board file. */
69
+ type Db = {
70
+ readonly raw: DatabaseSync;
71
+ readonly path: string;
72
+ /** Runs `fn` in one write transaction. Only BEGIN and COMMIT are retried when busy: `fn` runs once. */
73
+ write<T$1>(fn: () => T$1): T$1;
74
+ close(): void;
75
+ };
76
+ //#endregion
78
77
  //#region src/core/context.d.ts
79
78
  /** What every operation gets: the open file, the clock, and a way to check whether a process lives. */
80
79
  type Context = {
@@ -203,7 +202,16 @@ type Provider = ProviderExtras & {
203
202
  deliver(message: Message, target: {
204
203
  place: string;
205
204
  threadExternal: string | null;
206
- }, fetcher: typeof fetch, read: ReadFile): Promise<Delivery$1>;
205
+ }, fetcher: typeof fetch, read: ReadFile, marker?: string): Promise<Delivery$1>;
206
+ /**
207
+ * Looks on the platform for a message an earlier try may have posted, by the `marker` `deliver` was given, and
208
+ * says what it is there, or null when it isn't. A platform without this never has a message sent twice: one
209
+ * whose try went unanswered is recorded as `unconfirmed` instead.
210
+ */
211
+ find?(marker: string, message: Message, target: {
212
+ place: string;
213
+ threadExternal: string | null;
214
+ }, fetcher: typeof fetch): Promise<Delivery$1 | null>;
207
215
  };
208
216
  /** What a provider may also do. Each is optional: a platform that can't simply doesn't. */
209
217
  type ProviderExtras = {
@@ -279,14 +287,10 @@ type Claims = {
279
287
  /** It was made for an agent in a sandbox: it calls the routes a sandbox may, and no others. */
280
288
  sandbox?: true;
281
289
  };
282
- /**
283
- * The key a board's tokens are signed with. It is made once and kept, so a restart of `mu serve`
284
- * doesn't strand every client holding a token.
285
- */
286
290
  declare function boardKey(where: string, dir?: string): Buffer;
287
291
  declare function mint(key: Buffer, claims: Claims): string;
288
292
  /** The claims of a token this board signed and that hasn't run out. Anything else is refused the same way. */
289
- declare function verify(key: Buffer, token: string | undefined, now: number): Claims;
293
+ declare function verify(key: Buffer | readonly Buffer[], token: string | undefined, now: number): Claims;
290
294
  //#endregion
291
295
  //#region src/serve/tokens.d.ts
292
296
  /** What the board remembers of a token it made: enough to list it and to stop it, never the token itself. */
@@ -824,6 +828,42 @@ declare function search(ctx: Context, caller: Caller, request: {
824
828
  messages: Message[];
825
829
  };
826
830
  //#endregion
831
+ //#region src/core/report.d.ts
832
+ /**
833
+ * How one group of tasks went. `rounds` is the average number of rounds, a task sent back with
834
+ * `reopen --round` counting one more each time; `firstRound` is how many completed without being sent
835
+ * back. `cost` sums the `cost` labels whoever ran an agent wrote, and `perTask` divides it by the
836
+ * `costed` tasks that have one: an agent that reports no cost (Codex) adds to neither.
837
+ */
838
+ type ReportRow = {
839
+ key: string | null;
840
+ tasks: number;
841
+ firstRound: number;
842
+ rounds: number;
843
+ failed: number;
844
+ failing: number;
845
+ needsInput: number;
846
+ cost: number;
847
+ costed: number;
848
+ perTask: number | null;
849
+ };
850
+ type Report = {
851
+ channel: string | null;
852
+ since: string;
853
+ agents: ReportRow[];
854
+ workflows: ReportRow[];
855
+ };
856
+ /**
857
+ * How the tasks under a channel went since a time: grouped by the agent that ran them (the `agent` label
858
+ * `mu run` writes) and by workflow (the `workflow` label a run's tasks are made with). A task counts when
859
+ * its latest change is at or after `since`. Read only, from the tables and the log; the caller sees only
860
+ * the tasks it may read.
861
+ */
862
+ declare function report(ctx: Context, caller: Caller, request: {
863
+ channel?: string;
864
+ since: string;
865
+ }): Report;
866
+ //#endregion
827
867
  //#region src/core/schedules.d.ts
828
868
  type Schedule = {
829
869
  id: number;
@@ -903,6 +943,8 @@ type Backend = {
903
943
  registry?: () => Registry;
904
944
  /** The key this board's tokens are signed with, where it keeps one: the one `mu serve` and `team.fetch` check tokens with. */
905
945
  signingKey?: () => Buffer;
946
+ /** Keys the board signed with before, whose tokens are still good: see `mu token rotate-key`. */
947
+ retiredKeys?: () => Buffer[];
906
948
  /** The board's tokens: making one, listing them, stopping one. For the owner, or a token as wide as the owner's. */
907
949
  tokens: {
908
950
  create(request: MintRequest): Promise<{
@@ -1038,6 +1080,7 @@ type Backend = {
1038
1080
  taskNeeds: Op<typeof setNeeds>;
1039
1081
  taskList: Read<typeof list$1>;
1040
1082
  task(caller: Caller, id: number): Promise<Task | null>;
1083
+ taskReport: Op<typeof report>;
1041
1084
  budgetSet: Op<typeof setBudget>;
1042
1085
  budgets(caller: Caller): Promise<ReturnType<typeof budgets>>;
1043
1086
  filePut: Op<typeof filePut>;
@@ -1190,7 +1233,7 @@ declare class Failure extends Error {
1190
1233
  //#region src/watch/watch.d.ts
1191
1234
  type MessageType = 'message.posted' | 'message.edited' | 'message.deleted';
1192
1235
  type TaskType = 'task.created' | 'task.ready' | 'task.claimed' | 'task.renewed' | 'task.released' | 'task.expired' | 'task.blocked' | 'task.completed' | 'task.failed' | 'task.canceled' | 'task.reopened' | 'task.assigned' | 'task.needs_changed' | 'task.waiting' | 'task.extended';
1193
- type OtherType = 'channel.created' | 'labels.changed' | 'reaction.added' | 'reaction.removed' | 'schedule.created' | 'schedule.canceled' | 'schedule.skipped' | 'schema.registered' | 'budget.set' | 'sync.delivered';
1236
+ type OtherType = 'channel.created' | 'labels.changed' | 'reaction.added' | 'reaction.removed' | 'schedule.created' | 'schedule.canceled' | 'schedule.skipped' | 'schema.registered' | 'budget.set' | 'sync.delivered' | 'sync.failed' | 'sync.dropped';
1194
1237
  /**
1195
1238
  * An event as a watcher gets it: exactly what `mu tail --json` prints for it, narrowed by `type`. A
1196
1239
  * message event carries its message as it is now (a tombstone once deleted), a task event its task.
@@ -1431,6 +1474,8 @@ declare const SANDBOX_ROUTES: readonly ["post", "reply", "edit", "remove", "labe
1431
1474
  type ServeOptions = {
1432
1475
  backend: Backend;
1433
1476
  key: Buffer;
1477
+ /** Keys the board signed with before `key`, whose tokens are still good. */
1478
+ retired?: readonly Buffer[];
1434
1479
  now?: () => number;
1435
1480
  /** The board's list of tokens it made. Default: the backend's own. */
1436
1481
  tokens?: Registry;
@@ -2091,7 +2136,10 @@ type Workers = {
2091
2136
  push?: boolean;
2092
2137
  cwd?: string;
2093
2138
  timeout?: string;
2139
+ template?: string;
2140
+ model?: string;
2094
2141
  };
2142
+ /** `suggest`: the daemon says on the thread what it would start, and starts nothing. Left out, or `run`, it starts the run. */
2095
2143
  type Workflow = {
2096
2144
  name: string;
2097
2145
  description: string;
@@ -2100,6 +2148,7 @@ type Workflow = {
2100
2148
  steps: WorkflowStep[];
2101
2149
  workers: Workers;
2102
2150
  timeout?: string;
2151
+ mode?: 'run' | 'suggest';
2103
2152
  };
2104
2153
  declare const workflowsPath: () => string;
2105
2154
  /**
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { A as file, B as fetchFile, G as SEND_MS, H as refused, M as mint, N as verify, Q as channelPath, R as declared, S as listen, U as sizeOf, V as noteOut, W as withLines, b as createHandler, d as board, it as misuse, j as boardKey, k as boardPath, rt as Failure, w as SANDBOX_ROUTES, z as env } from "./args-DX9QSK1f.js";
2
- import { A as claude, C as boardPolicy, D as agentEnv, F as conformance, M as generic, O as runLocal, P as http, S as applyPolicy, T as installationToken, a as workflowResult, d as workflowsPath, f as e2b, h as vercel, j as codex, k as AGENTS, m as cloudflare, o as fenced, u as loadWorkflows, w as githubApp } from "./steps-DtzUdcBE.js";
1
+ import { A as boardPath, C as listen, G as noteOut, H as declared, J as withLines, K as refused, L as verify, M as boardKey, P as mint, T as SANDBOX_ROUTES, U as env, W as fetchFile, Y as SEND_MS, f as board, j as file, lt as misuse, nt as channelPath, q as sizeOf, st as Failure, x as createHandler } from "./args-CaFBa2IP.js";
2
+ import { A as claude, C as boardPolicy, D as agentEnv, F as conformance, M as generic, O as runLocal, P as http, S as applyPolicy, T as installationToken, a as workflowResult, d as workflowsPath, f as e2b, h as vercel, j as codex, k as AGENTS, m as cloudflare, o as fenced, u as loadWorkflows, w as githubApp } from "./steps-FNDWY1P_.js";
3
3
  import { mkdirSync, writeFileSync } from "node:fs";
4
4
  import { homedir } from "node:os";
5
5
  import { basename, dirname, join } from "node:path";
@@ -194,6 +194,10 @@ async function send(fetcher, url, init) {
194
194
  if (!response.ok) throw new Failure(`platform_${response.status}`, `The platform answered ${response.status}.`);
195
195
  return body;
196
196
  }
197
+ /** How a GitHub issue or comment the board posted carries its marker: a comment GitHub doesn't show. */
198
+ const githubMarker = (marker) => `<!-- muster:${marker} -->`;
199
+ /** The metadata type a Slack message the board posted carries its marker under. */
200
+ const SLACK_MARKER = "muster_message";
197
201
  /** GitHub catch-up reads at most this many pages of 100 of each list per repo. */
198
202
  const GITHUB_CATCHUP_PAGES = 10;
199
203
  /** Past a catch-up's page cap, how many more pages it reads while all of it changed at one time. */
@@ -281,6 +285,21 @@ function githubWith(options) {
281
285
  if (Date.parse(token.expiresAt) - now < APP_TOKEN_MARGIN_MS) token = await (tokens.get(repo) === held ? mint$1(repo, fetcher, now) : tokens.get(repo));
282
286
  return `Bearer ${token.token}`;
283
287
  };
288
+ const headersFor = async (repo, fetcher) => ({
289
+ authorization: await bearer(repo, fetcher),
290
+ accept: "application/vnd.github+json",
291
+ "content-type": "application/json",
292
+ "user-agent": "muster"
293
+ });
294
+ const openedIssue = (repo, number) => ({
295
+ external: `${repo}#${number}`,
296
+ thread: `${repo}#${number}`,
297
+ labels: {
298
+ kind: "issue",
299
+ state: "open",
300
+ ref: `${repo}#${number}`
301
+ }
302
+ });
284
303
  const named = (message, text) => withLines(text, message.attachments.map((file$1) => noteOut(`${file$1.name} (${sizeOf(file$1.size)})`, "GitHub takes no uploads, it is on the board")));
285
304
  /**
286
305
  * An issue's or a pull request's labels and assignees, as GitHub lists them now. Every event about one
@@ -570,41 +589,43 @@ function githubWith(options) {
570
589
  const { to } = mapping(place);
571
590
  return typeof to === "object" && to.mirror === true && (options.token !== void 0 || app !== void 0);
572
591
  },
573
- async deliver(message, target, fetcher) {
574
- const headersFor = async (repo$1) => ({
575
- authorization: await bearer(repo$1, fetcher),
576
- accept: "application/vnd.github+json",
577
- "content-type": "application/json",
578
- "user-agent": "muster"
579
- });
592
+ async deliver(message, target, fetcher, _read, marker) {
593
+ const marked = (text) => marker ? `${text}\n\n${githubMarker(marker)}` : text;
580
594
  if (target.threadExternal === null) {
581
595
  const repo$1 = target.place.split("|")[0];
582
- const headers = await headersFor(repo$1);
596
+ const headers = await headersFor(repo$1, fetcher);
583
597
  const [title, ...rest] = message.text.split("\n");
584
- const made = await send(fetcher, `${api}/repos/${repo$1}/issues`, {
598
+ return openedIssue(repo$1, (await send(fetcher, `${api}/repos/${repo$1}/issues`, {
585
599
  method: "POST",
586
600
  headers,
587
601
  body: JSON.stringify({
588
602
  title: title.slice(0, 250),
589
- body: named(message, rest.join("\n").trim())
603
+ body: marked(named(message, rest.join("\n").trim()))
590
604
  })
591
- });
592
- return {
593
- external: `${repo$1}#${made.number}`,
594
- thread: `${repo$1}#${made.number}`,
595
- labels: {
596
- kind: "issue",
597
- state: "open",
598
- ref: `${repo$1}#${made.number}`
599
- }
600
- };
605
+ })).number);
601
606
  }
602
607
  const [repo, number] = target.threadExternal.split("#");
603
608
  return { external: `comment:${(await send(fetcher, `${api}/repos/${repo}/issues/${number}/comments`, {
604
609
  method: "POST",
605
- headers: await headersFor(repo),
606
- body: JSON.stringify({ body: named(message, message.text) })
610
+ headers: await headersFor(repo, fetcher),
611
+ body: JSON.stringify({ body: marked(named(message, message.text)) })
607
612
  })).id}` };
613
+ },
614
+ async find(marker, message, target, fetcher) {
615
+ const since = (/* @__PURE__ */ new Date(Date.parse(message.at) - 6e5)).toISOString();
616
+ if (options.bot === void 0 && app === void 0) throw new Failure("unconfirmed", "The sync names no bot, so the board cannot tell its own posts on GitHub.");
617
+ const mine = (item) => options.bot !== void 0 && item?.user?.login === options.bot || app !== void 0 && String(item?.performed_via_github_app?.id ?? "") === app.id;
618
+ const has = (item) => typeof item?.body === "string" && item.body.includes(githubMarker(marker)) && mine(item);
619
+ if (target.threadExternal === null) {
620
+ const repo$1 = target.place.split("|")[0];
621
+ const issues = await send(fetcher, `${api}/repos/${repo$1}/issues?state=all&sort=created&direction=desc&per_page=100&since=${since}`, { headers: await headersFor(repo$1, fetcher) });
622
+ const made$1 = Array.isArray(issues) ? issues.filter(has).sort((a, b) => Number(a.number) - Number(b.number))[0] : void 0;
623
+ return made$1 ? openedIssue(repo$1, made$1.number) : null;
624
+ }
625
+ const [repo, number] = target.threadExternal.split("#");
626
+ const comments = await send(fetcher, `${api}/repos/${repo}/issues/${number}/comments?per_page=100&since=${since}`, { headers: await headersFor(repo, fetcher) });
627
+ const made = Array.isArray(comments) ? comments.find(has) : void 0;
628
+ return made ? { external: `comment:${made.id}` } : null;
608
629
  }
609
630
  };
610
631
  }
@@ -731,6 +752,19 @@ function linearWith(options) {
731
752
  const once = found.filter((file$1, index) => found.findIndex((other) => other.url === file$1.url) === index);
732
753
  return once.length ? once : void 0;
733
754
  };
755
+ /** A new issue's thread, as `deliver` makes it, from what Linear says of it. */
756
+ const linearIssue = (created) => {
757
+ const labels = {
758
+ kind: "issue",
759
+ ...created.identifier ? { ref: String(created.identifier) } : {},
760
+ ...created.state?.name ? { state: slug(String(created.state.name)) } : {}
761
+ };
762
+ return {
763
+ external: `issue:${created.id}`,
764
+ thread: `issue:${created.id}`,
765
+ labels
766
+ };
767
+ };
734
768
  const postAs = async (query, variables, fetcher) => {
735
769
  const ask = async () => send(fetcher, api, {
736
770
  method: "POST",
@@ -1075,7 +1109,7 @@ function linearWith(options) {
1075
1109
  ...soonest(cuts)
1076
1110
  } : out;
1077
1111
  },
1078
- async deliver(message, target, fetcher, read) {
1112
+ async deliver(message, target, fetcher, read, marker) {
1079
1113
  const post = (query, variables) => postAs(query, variables, fetcher);
1080
1114
  const lines = [];
1081
1115
  for (const file$1 of message.attachments) {
@@ -1117,27 +1151,31 @@ function linearWith(options) {
1117
1151
  const created = (await post("mutation($input: IssueCreateInput!) { issueCreate(input: $input) { success issue { id identifier state { name } } } }", { input: {
1118
1152
  teamId,
1119
1153
  title: title.slice(0, 250),
1120
- description: withLines(rest.join("\n").trim(), lines)
1154
+ description: withLines(rest.join("\n").trim(), lines),
1155
+ ...marker ? { id: marker } : {}
1121
1156
  } }))?.data?.issueCreate?.issue;
1122
- const issue = created?.id;
1123
- if (!issue) throw new Failure("platform_refused", "Linear did not make the issue.");
1124
- const labels = {
1125
- kind: "issue",
1126
- ...created.identifier ? { ref: String(created.identifier) } : {},
1127
- ...created.state?.name ? { state: slug(String(created.state.name)) } : {}
1128
- };
1129
- return {
1130
- external: `issue:${issue}`,
1131
- thread: `issue:${issue}`,
1132
- labels
1133
- };
1157
+ if (!created?.id) throw new Failure("platform_refused", "Linear did not make the issue.");
1158
+ return linearIssue(created);
1134
1159
  }
1135
1160
  const id = (await post("mutation($input: CommentCreateInput!) { commentCreate(input: $input) { success comment { id } } }", { input: {
1136
1161
  issueId: target.threadExternal.replace(/^issue:/, ""),
1137
- body: withLines(message.text, lines)
1162
+ body: withLines(message.text, lines),
1163
+ ...marker ? { id: marker } : {}
1138
1164
  } }))?.data?.commentCreate?.comment?.id;
1139
1165
  if (!id) throw new Failure("platform_refused", "Linear did not make the comment.");
1140
1166
  return { external: `comment:${id}` };
1167
+ },
1168
+ async find(marker, _message, target, fetcher) {
1169
+ if (options.bot === void 0 && appUser === void 0) throw new Failure("unconfirmed", "The sync names no bot, so the board cannot tell its own posts on Linear.");
1170
+ const root = target.threadExternal === null;
1171
+ const got = await postAs(root ? "query($id: String!) { issue(id: $id) { id identifier state { name } creator { id } } }" : "query($id: String!) { comment(id: $id) { id user { id } } }", { id: marker }, fetcher);
1172
+ const found = root ? got?.data?.issue : got?.data?.comment;
1173
+ const author = root ? found?.creator?.id : found?.user?.id;
1174
+ if (found?.id && author !== void 0 && !own(String(author))) throw new Failure("platform_refused", "Linear has the ID the board chose, on something it did not write.");
1175
+ if (found?.id) return root ? linearIssue(found) : { external: `comment:${found.id}` };
1176
+ if (Array.isArray(got?.errors) && got.errors.some((error) => /not found/i.test(String(error?.message ?? "")) || error?.extensions?.code === "ENTITY_NOT_FOUND" || error?.extensions?.type === "invalid input")) return null;
1177
+ if (got?.data && (got.data.issue === null || got.data.comment === null)) return null;
1178
+ throw new Failure("platform_refused", "Linear did not say whether it has the message.");
1141
1179
  }
1142
1180
  };
1143
1181
  }
@@ -1467,7 +1505,7 @@ function slackWith(options) {
1467
1505
  if (file$1.size !== void 0 && got.bytes.length !== file$1.size) throw refused(`Slack sent ${sizeOf(got.bytes.length)}, not the ${sizeOf(file$1.size)} it named`);
1468
1506
  return got;
1469
1507
  },
1470
- async deliver(message, target, fetcher, read) {
1508
+ async deliver(message, target, fetcher, read, marker) {
1471
1509
  const [channel, ts] = (target.threadExternal ?? target.place).split(":");
1472
1510
  const auth = { authorization: `Bearer ${options.token}` };
1473
1511
  const uploaded = [];
@@ -1518,7 +1556,11 @@ function slackWith(options) {
1518
1556
  body: JSON.stringify({
1519
1557
  channel,
1520
1558
  thread_ts: ts,
1521
- text
1559
+ text,
1560
+ ...marker ? { metadata: {
1561
+ event_type: SLACK_MARKER,
1562
+ event_payload: { marker }
1563
+ } } : {}
1522
1564
  })
1523
1565
  });
1524
1566
  if (made.ok !== true) throw new Failure(`slack_${made.error ?? "error"}`, `Slack refused the message: ${made.error ?? "unknown"}.`);
@@ -1556,6 +1598,29 @@ function slackWith(options) {
1556
1598
  ...target.threadExternal === null ? { thread: `${channel}:${made.ts}` } : {},
1557
1599
  ...uploaded.length ? { files: uploaded.map((file$1) => file$1.id) } : {}
1558
1600
  };
1601
+ },
1602
+ async find(marker, message, target, fetcher) {
1603
+ const [channel, ts] = (target.threadExternal ?? target.place).split(":");
1604
+ const oldest = toTs((Date.parse(message.at) - 6e5) * 1e3);
1605
+ const got = ts === void 0 ? await api(fetcher, "conversations.history", {
1606
+ channel,
1607
+ oldest,
1608
+ limit: "200",
1609
+ include_all_metadata: "true"
1610
+ }) : await api(fetcher, "conversations.replies", {
1611
+ channel,
1612
+ ts,
1613
+ oldest,
1614
+ limit: "200",
1615
+ include_all_metadata: "true"
1616
+ });
1617
+ if (options.bot === void 0) throw new Failure("unconfirmed", "The sync names no bot, so the board cannot tell its own messages on Slack.");
1618
+ const made = (got.messages ?? []).find((each) => isSelf(each) && each?.metadata?.event_type === SLACK_MARKER && each.metadata.event_payload?.marker === marker);
1619
+ if (!made) return null;
1620
+ return {
1621
+ external: `${channel}:${made.ts}`,
1622
+ ...ts === void 0 ? { thread: `${channel}:${made.ts}` } : {}
1623
+ };
1559
1624
  }
1560
1625
  };
1561
1626
  }