@openmuster/muster 0.3.1-alpha.4 → 0.3.1-alpha.6
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/README.md +11 -7
- package/dist/{args-9ZZDcPxa.js → args-CaFBa2IP.js} +305 -23
- package/dist/cli.js +3 -3
- package/dist/index.d.ts +98 -19
- package/dist/index.js +107 -42
- package/dist/inspect/app.js +49 -26
- package/dist/{main-Doit2DDY.js → main-3kE64MlN.js} +195 -12
- package/dist/main-o4m_lGDG.js +6 -0
- package/dist/mcp-D6Xt2ixk.js +6 -0
- package/dist/{module-DjDMSEKu.js → module-BX2IjSiv.js} +2 -2
- package/dist/{module-D8qcE3e7.js → module-D9KdbEpS.js} +1 -1
- package/dist/skills/board/SKILL.md +5 -0
- package/dist/skills/loop-card/SKILL.md +22 -3
- package/dist/{steps-BUPRIOe3.js → steps-cnWo2Wvx.js} +299 -12
- package/docs/01-concepts/09-watchers.md +4 -32
- package/docs/01-concepts/10-schedules.md +1 -1
- package/docs/01-concepts/11-access.md +19 -3
- package/docs/01-concepts/13-budgets.md +66 -3
- package/docs/01-concepts/15-outgoing-webhooks.md +6 -19
- package/docs/01-concepts/16-workflows.md +42 -2
- package/docs/01-quickstart.md +74 -45
- package/docs/02-sync/01-overview.md +34 -2
- package/docs/02-sync/02-github.md +40 -19
- package/docs/02-sync/03-linear.md +103 -85
- package/docs/02-sync/04-slack.md +116 -111
- package/docs/02-sync/05-notion.md +46 -25
- package/docs/03-guides/01-coding-agents.md +51 -33
- package/docs/03-guides/02-swarm.md +30 -15
- package/docs/03-guides/03-factory.md +193 -80
- package/docs/03-guides/04-inspector.md +73 -42
- package/docs/03-guides/05-running-agents.md +62 -35
- package/docs/03-guides/06-sandboxed-agents.md +535 -305
- package/docs/03-guides/07-build-a-ui.md +86 -31
- package/docs/03-guides/08-ci.md +59 -36
- package/docs/03-guides/09-daemon.md +121 -53
- package/docs/03-guides/10-two-agents.md +31 -22
- package/docs/03-guides/11-person-in-the-loop.md +47 -34
- package/docs/03-guides/12-unattended.md +46 -27
- package/docs/03-guides/13-terminals.md +51 -39
- package/docs/03-guides/14-no-cloud.md +31 -19
- package/docs/03-guides/15-several-boards.md +61 -27
- package/docs/03-guides/16-non-code.md +29 -18
- package/docs/03-guides/17-mcp.md +37 -30
- package/docs/03-guides/18-a-board-on-a-server.md +66 -43
- package/docs/03-guides/19-a-card-queue.md +210 -121
- package/docs/03-guides/20-a-feedback-loop.md +412 -135
- package/docs/03-guides/21-running-the-loop.md +94 -64
- package/docs/03-guides/22-building-from-linear.md +100 -63
- package/docs/04-reference/01-cli.md +7 -0
- package/docs/04-reference/02-handle.md +11 -15
- package/docs/04-reference/03-http.md +1 -1
- package/docs/04-reference/04-events.md +2 -1
- package/docs/04-reference/05-errors.md +6 -0
- package/docs/04-reference/08-files.md +49 -0
- package/docs/index.md +1 -0
- package/package.json +1 -1
- package/dist/main-D5aX7Jaj.js +0 -6
- package/dist/mcp-Cm96TIb3.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;
|
|
@@ -2081,6 +2126,7 @@ type WorkflowStep = {
|
|
|
2081
2126
|
labels?: Record<string, string>;
|
|
2082
2127
|
push?: boolean;
|
|
2083
2128
|
title?: string;
|
|
2129
|
+
refs?: string;
|
|
2084
2130
|
};
|
|
2085
2131
|
type Workers = {
|
|
2086
2132
|
count: number;
|
|
@@ -2091,7 +2137,10 @@ type Workers = {
|
|
|
2091
2137
|
push?: boolean;
|
|
2092
2138
|
cwd?: string;
|
|
2093
2139
|
timeout?: string;
|
|
2140
|
+
template?: string;
|
|
2141
|
+
model?: string;
|
|
2094
2142
|
};
|
|
2143
|
+
/** `suggest`: the daemon says on the thread what it would start, and starts nothing. Left out, or `run`, it starts the run. */
|
|
2095
2144
|
type Workflow = {
|
|
2096
2145
|
name: string;
|
|
2097
2146
|
description: string;
|
|
@@ -2100,6 +2149,7 @@ type Workflow = {
|
|
|
2100
2149
|
steps: WorkflowStep[];
|
|
2101
2150
|
workers: Workers;
|
|
2102
2151
|
timeout?: string;
|
|
2152
|
+
mode?: 'run' | 'suggest';
|
|
2103
2153
|
};
|
|
2104
2154
|
declare const workflowsPath: () => string;
|
|
2105
2155
|
/**
|
|
@@ -2135,4 +2185,33 @@ declare function workflowResult(team: Board, id: number, owner: string): Promise
|
|
|
2135
2185
|
*/
|
|
2136
2186
|
declare function fenced(whose: string, text: string): string;
|
|
2137
2187
|
//#endregion
|
|
2138
|
-
|
|
2188
|
+
//#region src/runner/github.d.ts
|
|
2189
|
+
/** A pull request as `pullRequests` reads it. */
|
|
2190
|
+
type PullRequest = {
|
|
2191
|
+
number: number;
|
|
2192
|
+
state: 'open' | 'closed';
|
|
2193
|
+
merged: boolean;
|
|
2194
|
+
mergedAt: string | null;
|
|
2195
|
+
base: string;
|
|
2196
|
+
createdAt: string;
|
|
2197
|
+
url: string;
|
|
2198
|
+
};
|
|
2199
|
+
/**
|
|
2200
|
+
* The pull requests opened from `head` on a GitHub repository, newest first, and the repository's default branch.
|
|
2201
|
+
* It reads and writes nothing else. With `token`, it reads with that; without, with a token it asks the GitHub
|
|
2202
|
+
* App in `env` (GITHUB_APP_ID, and GITHUB_APP_KEY_FILE or GITHUB_APP_PRIVATE_KEY) for, that may only read pull
|
|
2203
|
+
* requests on this one repository. `repo` is its HTTPS clone address, as a workflow's `workers.repo` gives it.
|
|
2204
|
+
*/
|
|
2205
|
+
declare function pullRequests(options: {
|
|
2206
|
+
repo: string;
|
|
2207
|
+
head: string;
|
|
2208
|
+
token?: string;
|
|
2209
|
+
env?: NodeJS.ProcessEnv;
|
|
2210
|
+
api?: string;
|
|
2211
|
+
fetch?: typeof fetch;
|
|
2212
|
+
}): Promise<{
|
|
2213
|
+
defaultBranch: string;
|
|
2214
|
+
pulls: PullRequest[];
|
|
2215
|
+
}>;
|
|
2216
|
+
//#endregion
|
|
2217
|
+
export { AGENTS, type Agent, type Argv, type Attachment, type Backend, type Block, type Board, type BoardEvent, type BoardOptions, type By, type Caller, type Check, type Claims, type CloudRequest, type CloudRunner, type CommandOptions, type DeclaredHook, type DeclaredSync, type DeclaredWatcher, type Delivered, type Duration, type E2bSdk, type Env, type ExitKind, Failure, type FeedEvent, type FileOptions, type Filter, type GitHubOptions, type HookOptions, type Host, type HttpOptions, type Inbound, LINEAR_SCOPES, type LinearOptions, type Message, type NetworkPolicy, type NotionOptions, type Permission, type PlanTask, type Provider, type PullRequest, type RunRequest, type RunResult, SANDBOX_ROUTES, type Secret, type SlackOptions, type StartOptions, type SyncOptions, type Task, type TaskListing, type TaskState, type ThreadSummary, type Watch, type WatchContext, type WatchEvent, type Workers, type Workflow, type WorkflowStep, agentEnv, applyPolicy, board, boardKey, boardPath, boardPolicy, claude, cloudflare, codex, command, conformance, createHandler, e2b, env, fenced, file, generic, github, http, linear, listen, loadWorkflows, mint, notion, pullRequests, runLocal, slack, vercel, verify, workflowResult, workflowsPath };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { A as
|
|
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 boardPolicy, D as pullRequests, F as runLocal, H as conformance, I as AGENTS, L as claude, M as installationToken, P as agentEnv, R as codex, V as http, _ as e2b, b as vercel, d as fenced, g as workflowsPath, h as loadWorkflows, j as githubApp, k as applyPolicy, u as workflowResult, y as cloudflare, z as generic } from "./steps-cnWo2Wvx.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
|
|
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
|
-
|
|
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
|
-
|
|
1123
|
-
|
|
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
|
}
|
|
@@ -1948,4 +2013,4 @@ function notionWith(options) {
|
|
|
1948
2013
|
}
|
|
1949
2014
|
|
|
1950
2015
|
//#endregion
|
|
1951
|
-
export { AGENTS, Failure, LINEAR_SCOPES, SANDBOX_ROUTES, agentEnv, applyPolicy, board, boardKey, boardPath, boardPolicy, claude, cloudflare, codex, command, conformance, createHandler, e2b, env, fenced, file, generic, github, http, linear, listen, loadWorkflows, mint, notion, runLocal, slack, vercel, verify, workflowResult, workflowsPath };
|
|
2016
|
+
export { AGENTS, Failure, LINEAR_SCOPES, SANDBOX_ROUTES, agentEnv, applyPolicy, board, boardKey, boardPath, boardPolicy, claude, cloudflare, codex, command, conformance, createHandler, e2b, env, fenced, file, generic, github, http, linear, listen, loadWorkflows, mint, notion, pullRequests, runLocal, slack, vercel, verify, workflowResult, workflowsPath };
|