@openmuster/muster 0.3.1-alpha.4 → 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.
- package/README.md +10 -6
- package/dist/{args-9ZZDcPxa.js → args-CaFBa2IP.js} +305 -23
- package/dist/cli.js +3 -3
- package/dist/index.d.ts +67 -18
- package/dist/index.js +106 -41
- package/dist/inspect/app.js +49 -26
- package/dist/{main-Doit2DDY.js → main-BeEB08iI.js} +158 -8
- package/dist/main-CLzQkYeG.js +6 -0
- package/dist/mcp-CAAZRJgv.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/{steps-BUPRIOe3.js → steps-FNDWY1P_.js} +16 -4
- 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 +22 -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 +488 -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 +298 -134
- package/docs/03-guides/21-running-the-loop.md +94 -64
- package/docs/03-guides/22-building-from-linear.md +81 -57
- package/docs/04-reference/01-cli.md +7 -0
- package/docs/04-reference/02-handle.md +10 -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 +3 -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/README.md
CHANGED
|
@@ -26,7 +26,7 @@ mu demo
|
|
|
26
26
|
In a project, `npm i @openmuster/muster` and run it as `npx mu` there. Outside
|
|
27
27
|
one, use `npx @openmuster/muster`: `mu` on npm is not muster.
|
|
28
28
|
|
|
29
|
-
To pin a version, name it: `npm install -g @openmuster/muster@0.3.1-alpha.
|
|
29
|
+
To pin a version, name it: `npm install -g @openmuster/muster@0.3.1-alpha.5`.
|
|
30
30
|
Every release is also a tarball on GitHub, which npm installs from its URL:
|
|
31
31
|
`https://github.com/openmuster/muster/releases/latest/download/muster.tgz`.
|
|
32
32
|
|
|
@@ -165,10 +165,14 @@ on another machine, pass `backend: http({ url, token })`. See
|
|
|
165
165
|
## Give your coding agents the board
|
|
166
166
|
|
|
167
167
|
```bash
|
|
168
|
-
|
|
168
|
+
npx skills add openmuster/muster
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
-
The
|
|
171
|
+
The [skills CLI](https://skills.sh) installs muster's skills for Claude Code,
|
|
172
|
+
Codex, Cursor and other agents. `mu skills install --to ~/.claude/skills`
|
|
173
|
+
does the same from the `mu` you installed, so the skills match its version.
|
|
174
|
+
|
|
175
|
+
The board skill teaches a coding agent to work on a board: find the right channel,
|
|
172
176
|
read a discussion before joining it, reply in threads that exist, attach
|
|
173
177
|
proof, and wait for an answer. An agent names itself with `--as`, and the
|
|
174
178
|
board shows who wrote and as whose user:
|
|
@@ -247,8 +251,8 @@ writing as you. See
|
|
|
247
251
|
`agent` gets a spec, a pull request and a review from agents in Vercel
|
|
248
252
|
sandboxes, and you answer only what they ask. Since 0.3.0
|
|
249
253
|
([A card queue](./packages/muster/docs/03-guides/19-a-card-queue.md)).
|
|
250
|
-
- **Skills** that teach an agent the board: `
|
|
251
|
-
`
|
|
254
|
+
- **Skills** that teach an agent the board: `npx skills add openmuster/muster`,
|
|
255
|
+
or `mu skills install`.
|
|
252
256
|
- **For agents with no shell,** the board as one MCP tool: `mu mcp`, or over
|
|
253
257
|
HTTP from a served board.
|
|
254
258
|
|
|
@@ -301,7 +305,7 @@ been used against the real thing, and what has not.
|
|
|
301
305
|
|
|
302
306
|
```bash
|
|
303
307
|
pnpm install
|
|
304
|
-
pnpm check # build, typecheck and test
|
|
308
|
+
pnpm check # build, typecheck, lint, knip and test
|
|
305
309
|
```
|
|
306
310
|
|
|
307
311
|
See [CONTRIBUTING.md](./CONTRIBUTING.md) and [AGENTS.md](./AGENTS.md).
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { chmodSync, closeSync, copyFileSync, cpSync, existsSync, mkdirSync, openSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { chmodSync, closeSync, copyFileSync, cpSync, existsSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { homedir, hostname, userInfo } from "node:os";
|
|
3
3
|
import { dirname, join, resolve } from "node:path";
|
|
4
4
|
import { createHash, createHmac, createPublicKey, randomBytes, randomInt, timingSafeEqual, verify } from "node:crypto";
|
|
@@ -43,6 +43,11 @@ const misuse = (reason, message, hint) => new Failure(reason, message, {
|
|
|
43
43
|
exit: 2,
|
|
44
44
|
...hint ? { hint } : {}
|
|
45
45
|
});
|
|
46
|
+
/** A cursor past a board's last event: see `mu wait --after`, `mu tail --after` and the live feed. */
|
|
47
|
+
const cursorAhead = (after, head$1) => new Failure("cursor_ahead", `The cursor ${after} is past this board's last event, ${head$1}.`, {
|
|
48
|
+
hint: "Was the board restored from a backup? Read on from its head, or from 0 to read it all again.",
|
|
49
|
+
data: { head: head$1 }
|
|
50
|
+
});
|
|
46
51
|
|
|
47
52
|
//#endregion
|
|
48
53
|
//#region src/model.ts
|
|
@@ -2447,6 +2452,87 @@ function holder(c, name) {
|
|
|
2447
2452
|
};
|
|
2448
2453
|
}
|
|
2449
2454
|
|
|
2455
|
+
//#endregion
|
|
2456
|
+
//#region src/core/report.ts
|
|
2457
|
+
const round = (n, places) => Math.round(n * 10 ** places) / 10 ** places;
|
|
2458
|
+
/**
|
|
2459
|
+
* How the tasks under a channel went since a time: grouped by the agent that ran them (the `agent` label
|
|
2460
|
+
* `mu run` writes) and by workflow (the `workflow` label a run's tasks are made with). A task counts when
|
|
2461
|
+
* its latest change is at or after `since`. Read only, from the tables and the log; the caller sees only
|
|
2462
|
+
* the tasks it may read.
|
|
2463
|
+
*/
|
|
2464
|
+
function report(ctx, caller, request$1) {
|
|
2465
|
+
const since = Date.parse(request$1.since);
|
|
2466
|
+
if (typeof request$1.since !== "string" || !Number.isFinite(since)) throw misuse("invalid_since", `"${String(request$1.since)}" isn't a time.`, "Give an ISO time: 2026-11-01T00:00:00Z.");
|
|
2467
|
+
const scope = request$1.channel === void 0 ? null : {
|
|
2468
|
+
path: channelScope(request$1.channel.replace(/\/$/, "")).path,
|
|
2469
|
+
tree: true
|
|
2470
|
+
};
|
|
2471
|
+
const rows = ctx.db.raw.prepare("select t.id as id, t.state as state, t.rounds as rounds, e.at as at from tasks t join events e on e.seq = t.updated_seq order by t.id").all();
|
|
2472
|
+
const holds$2 = /* @__PURE__ */ new Map();
|
|
2473
|
+
const blocked = ctx.db.raw.prepare("select json_extract(data, '$.id') as id, json_extract(data, '$.kind') as kind from events where type = 'task.blocked'").all();
|
|
2474
|
+
for (const hold of blocked) {
|
|
2475
|
+
const seen = holds$2.get(hold.id) ?? {
|
|
2476
|
+
needsInput: 0,
|
|
2477
|
+
failing: false
|
|
2478
|
+
};
|
|
2479
|
+
if (hold.kind === "needs_input") seen.needsInput += 1;
|
|
2480
|
+
if (hold.kind === "failing") seen.failing = true;
|
|
2481
|
+
holds$2.set(hold.id, seen);
|
|
2482
|
+
}
|
|
2483
|
+
const agents = /* @__PURE__ */ new Map();
|
|
2484
|
+
const workflows = /* @__PURE__ */ new Map();
|
|
2485
|
+
const add = (groups, key, row$1, cost) => {
|
|
2486
|
+
let group = groups.get(key);
|
|
2487
|
+
if (!group) groups.set(key, group = {
|
|
2488
|
+
key,
|
|
2489
|
+
tasks: 0,
|
|
2490
|
+
firstRound: 0,
|
|
2491
|
+
rounds: 0,
|
|
2492
|
+
roundSum: 0,
|
|
2493
|
+
failed: 0,
|
|
2494
|
+
failing: 0,
|
|
2495
|
+
needsInput: 0,
|
|
2496
|
+
cost: 0,
|
|
2497
|
+
costed: 0,
|
|
2498
|
+
perTask: null
|
|
2499
|
+
});
|
|
2500
|
+
const held$1 = holds$2.get(row$1.id);
|
|
2501
|
+
group.tasks += 1;
|
|
2502
|
+
group.roundSum += 1 + row$1.rounds;
|
|
2503
|
+
if (row$1.state === "completed" && row$1.rounds === 0) group.firstRound += 1;
|
|
2504
|
+
if (row$1.state === "failed") group.failed += 1;
|
|
2505
|
+
if (held$1?.failing) group.failing += 1;
|
|
2506
|
+
group.needsInput += held$1?.needsInput ?? 0;
|
|
2507
|
+
if (cost !== null) {
|
|
2508
|
+
group.cost += cost;
|
|
2509
|
+
group.costed += 1;
|
|
2510
|
+
}
|
|
2511
|
+
};
|
|
2512
|
+
for (const row$1 of rows) {
|
|
2513
|
+
if (Date.parse(row$1.at) < since) continue;
|
|
2514
|
+
const root = findMessage(ctx.db, row$1.id);
|
|
2515
|
+
if (!root || !allowed(caller, root.channel, "read")) continue;
|
|
2516
|
+
if (scope && !inScope(root.channel, scope)) continue;
|
|
2517
|
+
const value = Number(root.labels.cost);
|
|
2518
|
+
const cost = root.labels.cost !== void 0 && Number.isFinite(value) && value >= 0 ? value : null;
|
|
2519
|
+
add(agents, root.labels.agent ?? null, row$1, cost);
|
|
2520
|
+
if (root.labels.workflow !== void 0) add(workflows, root.labels.workflow, row$1, cost);
|
|
2521
|
+
}
|
|
2522
|
+
const finish$1 = (groups) => [...groups.values()].map(({ roundSum,...group }) => ({
|
|
2523
|
+
...group,
|
|
2524
|
+
rounds: round(roundSum / group.tasks, 2),
|
|
2525
|
+
cost: round(group.cost, 4),
|
|
2526
|
+
perTask: group.costed ? round(group.cost / group.costed, 4) : null
|
|
2527
|
+
})).sort((x, y) => y.tasks - x.tasks || (x.key === null ? 1 : y.key === null ? -1 : x.key.localeCompare(y.key)));
|
|
2528
|
+
return {
|
|
2529
|
+
channel: scope?.path ?? null,
|
|
2530
|
+
since: new Date(since).toISOString(),
|
|
2531
|
+
agents: finish$1(agents),
|
|
2532
|
+
workflows: finish$1(workflows)
|
|
2533
|
+
};
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2450
2536
|
//#endregion
|
|
2451
2537
|
//#region src/core/schedules.ts
|
|
2452
2538
|
const EVERY_MIN_S = 60;
|
|
@@ -3134,6 +3220,33 @@ const DELIVERY_ATTEMPTS$1 = 5;
|
|
|
3134
3220
|
/** How long a platform has to answer. A delivery out holds that platform's imports, so it can't hang. */
|
|
3135
3221
|
const SEND_MS = 3e4;
|
|
3136
3222
|
const IMPORT_ATTEMPTS = 10;
|
|
3223
|
+
/**
|
|
3224
|
+
* How long a platform may be down before what waits on it is given up: an outage uses none of an event's tries
|
|
3225
|
+
* (`IMPORT_ATTEMPTS`, `DELIVERY_ATTEMPTS`), since it says nothing about the event, so this is what ends a wait.
|
|
3226
|
+
*/
|
|
3227
|
+
const OUTAGE_MS = 24 * 36e5;
|
|
3228
|
+
/** The longest a platform that keeps failing as if down is left alone between tries. */
|
|
3229
|
+
const OUTAGE_PAUSE_MS = 3e5;
|
|
3230
|
+
const SLACK_DOWN = new Set([
|
|
3231
|
+
"slack_ratelimited",
|
|
3232
|
+
"slack_internal_error",
|
|
3233
|
+
"slack_fatal_error",
|
|
3234
|
+
"slack_service_unavailable",
|
|
3235
|
+
"slack_request_timeout"
|
|
3236
|
+
]);
|
|
3237
|
+
/**
|
|
3238
|
+
* Whether an error says the platform is down or busy, rather than anything about what was asked of it: a 5xx, a
|
|
3239
|
+
* 429, Slack's own words for those, no answer at all, or none in time.
|
|
3240
|
+
*/
|
|
3241
|
+
function isOutage(error) {
|
|
3242
|
+
if (error instanceof Failure) {
|
|
3243
|
+
const status = /^platform_(\d+)$/.exec(error.reason);
|
|
3244
|
+
if (status) return Number(status[1]) === 429 || Number(status[1]) >= 500;
|
|
3245
|
+
return SLACK_DOWN.has(error.reason);
|
|
3246
|
+
}
|
|
3247
|
+
if (error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError")) return true;
|
|
3248
|
+
return error instanceof TypeError && error.message === "fetch failed";
|
|
3249
|
+
}
|
|
3137
3250
|
|
|
3138
3251
|
//#endregion
|
|
3139
3252
|
//#region src/sync/files.ts
|
|
@@ -3362,12 +3475,73 @@ function taken(labels) {
|
|
|
3362
3475
|
}
|
|
3363
3476
|
return out;
|
|
3364
3477
|
}
|
|
3478
|
+
/**
|
|
3479
|
+
* Platforms that answered as if down, and when each may be asked again: kept for the process, since an outage
|
|
3480
|
+
* outlives no restart worth remembering. Each outage in a row doubles the pause, up to OUTAGE_PAUSE_MS.
|
|
3481
|
+
*/
|
|
3482
|
+
const down = /* @__PURE__ */ new WeakMap();
|
|
3483
|
+
function isDown(ctx, sync, key) {
|
|
3484
|
+
const state = down.get(sync)?.get(key);
|
|
3485
|
+
return state !== void 0 && ctx.now().getTime() < state.until;
|
|
3486
|
+
}
|
|
3487
|
+
/** Notes how a platform answered: an outage pauses it, anything else ends the pause. */
|
|
3488
|
+
function answered(ctx, sync, key, error) {
|
|
3489
|
+
let states = down.get(sync);
|
|
3490
|
+
if (!error || !isOutage(error)) {
|
|
3491
|
+
states?.delete(key);
|
|
3492
|
+
return;
|
|
3493
|
+
}
|
|
3494
|
+
if (!states) down.set(sync, states = /* @__PURE__ */ new Map());
|
|
3495
|
+
const was = states.get(key);
|
|
3496
|
+
const times = (was?.times ?? 0) + 1;
|
|
3497
|
+
states.set(key, {
|
|
3498
|
+
times,
|
|
3499
|
+
until: ctx.now().getTime() + Math.min(OUTAGE_PAUSE_MS, 1e3 * 2 ** (times - 1)),
|
|
3500
|
+
since: was?.since ?? ctx.now().getTime()
|
|
3501
|
+
});
|
|
3502
|
+
}
|
|
3503
|
+
/**
|
|
3504
|
+
* Whether a platform has been down so long that what waits on it is given up: counted from its first failure in a
|
|
3505
|
+
* row, never from how old the message is, which may have waited for other reasons. A restart counts afresh.
|
|
3506
|
+
*/
|
|
3507
|
+
const tooLong = (ctx, sync, key) => {
|
|
3508
|
+
const state = down.get(sync)?.get(key);
|
|
3509
|
+
return state !== void 0 && ctx.now().getTime() - state.since > OUTAGE_MS;
|
|
3510
|
+
};
|
|
3511
|
+
/** A short, fixed word for why something failed: never the platform's own text, which the log would keep for good. */
|
|
3512
|
+
const failureOf = (error) => error instanceof Failure ? error.reason : error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError") ? "timeout" : error instanceof TypeError && error.message === "fetch failed" ? "unreachable" : "error";
|
|
3513
|
+
/**
|
|
3514
|
+
* Whether a failed send may have reached the platform all the same: no answer in time, a 5xx other than 503, or a
|
|
3515
|
+
* connection that broke once made. A refused connection, an unknown host and any 4xx never sent anything.
|
|
3516
|
+
*/
|
|
3517
|
+
function mayHaveLanded(error) {
|
|
3518
|
+
if (error instanceof Failure) {
|
|
3519
|
+
const status = /^platform_(\d+)$/.exec(error.reason);
|
|
3520
|
+
return status !== null && Number(status[1]) >= 500 && Number(status[1]) !== 503;
|
|
3521
|
+
}
|
|
3522
|
+
if (error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError")) return true;
|
|
3523
|
+
const code = error?.cause?.code ?? "";
|
|
3524
|
+
return error instanceof TypeError && error.message === "fetch failed" && ![
|
|
3525
|
+
"ECONNREFUSED",
|
|
3526
|
+
"ENOTFOUND",
|
|
3527
|
+
"EAI_AGAIN"
|
|
3528
|
+
].includes(code);
|
|
3529
|
+
}
|
|
3530
|
+
/**
|
|
3531
|
+
* What a board message carries to a platform, unseen, so a later try can find it there: the same on every try,
|
|
3532
|
+
* and unlike any other board's, since it hashes when the message was written as well as where it sits in the log.
|
|
3533
|
+
* Shaped as a UUID, which is what Linear takes for an ID chosen by the caller.
|
|
3534
|
+
*/
|
|
3535
|
+
function markerOf(key, event) {
|
|
3536
|
+
const hex = createHash("sha256").update(`${key}:${event.seq}:${event.at}`).digest("hex");
|
|
3537
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-4${hex.slice(13, 16)}-${"89ab"[parseInt(hex[16], 16) % 4]}${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
|
|
3538
|
+
}
|
|
3365
3539
|
/** A delivery older than this is from a process that died mid-send, and no longer holds imports. */
|
|
3366
3540
|
const SENDING_STALE_MS = 2 * SEND_MS;
|
|
3367
3541
|
/** Whether a delivery to this platform is out, from this process or another on the same board. */
|
|
3368
3542
|
function isSending(ctx, key) {
|
|
3369
3543
|
const after = new Date(ctx.now().getTime() - SENDING_STALE_MS).toISOString();
|
|
3370
|
-
return ctx.db.raw.prepare("select 1 from sending where key = ? and since > ?").get(key, after) !== void 0;
|
|
3544
|
+
return ctx.db.raw.prepare("select 1 from sending where key = ? and (since > ? or (since = ? and seq > coalesce((select seq from cursors where name = 'sync:' || ? and profile = ''), 0)))").get(key, after, (/* @__PURE__ */ new Date(0)).toISOString(), key) !== void 0;
|
|
3371
3545
|
}
|
|
3372
3546
|
/**
|
|
3373
3547
|
* Takes a platform's webhook: checks it is the platform's, stores what it carried, and only then
|
|
@@ -3444,11 +3618,14 @@ function importPending(ctx, sync, only) {
|
|
|
3444
3618
|
ctx.db.raw.prepare("update inbox set done = 1, payload = '{}' where key = ? and id = ?").get(row$1.key, row$1.id);
|
|
3445
3619
|
});
|
|
3446
3620
|
imported++;
|
|
3447
|
-
} catch {
|
|
3621
|
+
} catch (error) {
|
|
3448
3622
|
failed$1++;
|
|
3449
3623
|
const attempts = row$1.attempts + 1;
|
|
3450
|
-
|
|
3451
|
-
|
|
3624
|
+
if (attempts >= IMPORT_ATTEMPTS) drop(ctx, sync, row$1, error);
|
|
3625
|
+
else {
|
|
3626
|
+
ctx.db.write(() => ctx.db.raw.prepare("update inbox set attempts = ? where key = ? and id = ?").get(attempts, row$1.key, row$1.id));
|
|
3627
|
+
stuck.add(lane);
|
|
3628
|
+
}
|
|
3452
3629
|
}
|
|
3453
3630
|
}
|
|
3454
3631
|
return {
|
|
@@ -3458,6 +3635,30 @@ function importPending(ctx, sync, only) {
|
|
|
3458
3635
|
};
|
|
3459
3636
|
}
|
|
3460
3637
|
/**
|
|
3638
|
+
* Gives up on a platform event: its row is done and what it carried goes, as an import's would, and the log says
|
|
3639
|
+
* so, so the board's account of what it was sent has no silent gap.
|
|
3640
|
+
*/
|
|
3641
|
+
function drop(ctx, sync, row$1, error) {
|
|
3642
|
+
const event = JSON.parse(row$1.payload);
|
|
3643
|
+
const link = ctx.db.raw.prepare("select message from links where key = ? and external = ?").get(row$1.key, event.thread);
|
|
3644
|
+
const root = link ? findMessage(ctx.db, link.message) : null;
|
|
3645
|
+
const channel = root?.channel ?? sync[row$1.key]?.channelFor(event.place, event.kind) ?? null;
|
|
3646
|
+
ctx.db.write(() => {
|
|
3647
|
+
ctx.db.raw.prepare("update inbox set done = 1, payload = '{}' where key = ? and id = ? and done = 0").get(row$1.key, row$1.id);
|
|
3648
|
+
append(ctx.db, {
|
|
3649
|
+
type: "sync.dropped",
|
|
3650
|
+
by: board$1,
|
|
3651
|
+
channel,
|
|
3652
|
+
thread: root?.thread ?? null,
|
|
3653
|
+
data: {
|
|
3654
|
+
key: row$1.key,
|
|
3655
|
+
id: row$1.id,
|
|
3656
|
+
error: failureOf(error)
|
|
3657
|
+
}
|
|
3658
|
+
}, ctx.now().toISOString());
|
|
3659
|
+
});
|
|
3660
|
+
}
|
|
3661
|
+
/**
|
|
3461
3662
|
* Reads what `unread` events are about from their platforms, on the ticker, before they are imported: each is
|
|
3462
3663
|
* replaced by what its provider read, in its place in the inbox, or dropped when that is nothing. One that can't
|
|
3463
3664
|
* be read now is tried again on a later tick, and given up after IMPORT_ATTEMPTS, as an import is.
|
|
@@ -3467,13 +3668,17 @@ async function readPending(ctx, sync, fetcher) {
|
|
|
3467
3668
|
for (const row$1 of rows) {
|
|
3468
3669
|
const provider = sync[row$1.key];
|
|
3469
3670
|
const event = JSON.parse(row$1.payload);
|
|
3470
|
-
if (!provider?.read || !event.unread) continue;
|
|
3671
|
+
if (!provider?.read || !event.unread || isDown(ctx, sync, row$1.key)) continue;
|
|
3471
3672
|
let read$2;
|
|
3472
3673
|
try {
|
|
3473
3674
|
read$2 = (await provider.read(event, fetcher)).map(({ unread: _,...each }) => each);
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3675
|
+
answered(ctx, sync, row$1.key);
|
|
3676
|
+
} catch (error) {
|
|
3677
|
+
answered(ctx, sync, row$1.key, error);
|
|
3678
|
+
const outage = isOutage(error);
|
|
3679
|
+
const attempts = outage ? row$1.attempts : row$1.attempts + 1;
|
|
3680
|
+
if (attempts >= IMPORT_ATTEMPTS || outage && tooLong(ctx, sync, row$1.key)) drop(ctx, sync, row$1, error);
|
|
3681
|
+
else if (!outage) ctx.db.write(() => ctx.db.raw.prepare("update inbox set attempts = ? where key = ? and id = ? and done = 0").get(attempts, row$1.key, row$1.id));
|
|
3477
3682
|
continue;
|
|
3478
3683
|
}
|
|
3479
3684
|
ctx.db.write(() => {
|
|
@@ -3736,6 +3941,7 @@ async function deliverPending(ctx, sync, fetcher = fetch) {
|
|
|
3736
3941
|
let failed$1 = 0;
|
|
3737
3942
|
const stale = [];
|
|
3738
3943
|
for (const [key, provider] of Object.entries(sync)) {
|
|
3944
|
+
if (isDown(ctx, sync, key)) continue;
|
|
3739
3945
|
const name = `sync:${key}`;
|
|
3740
3946
|
const stored = ctx.db.raw.prepare("select seq from cursors where name = ? and profile = ''").get(name);
|
|
3741
3947
|
let cursor$1 = stored?.seq ?? head(ctx);
|
|
@@ -3746,7 +3952,10 @@ async function deliverPending(ctx, sync, fetcher = fetch) {
|
|
|
3746
3952
|
const data = event.data;
|
|
3747
3953
|
const advance$1 = () => {
|
|
3748
3954
|
cursor$1 = event.seq;
|
|
3749
|
-
ctx.db.write(() =>
|
|
3955
|
+
ctx.db.write(() => {
|
|
3956
|
+
ctx.db.raw.prepare("update cursors set seq = ? where name = ? and profile = ''").get(cursor$1, name);
|
|
3957
|
+
ctx.db.raw.prepare("delete from sending where key = ? and seq = ?").get(key, event.seq);
|
|
3958
|
+
});
|
|
3750
3959
|
};
|
|
3751
3960
|
if (event.type !== "message.posted") {
|
|
3752
3961
|
const copy = ctx.db.raw.prepare("select external, place from links where message = ? and key = ?").get(data.id, key);
|
|
@@ -3781,19 +3990,31 @@ async function deliverPending(ctx, sync, fetcher = fetch) {
|
|
|
3781
3990
|
const held$1 = ctx.db.raw.prepare("select since from sending where key = ? and seq = ?").get(key, event.seq);
|
|
3782
3991
|
if (held$1 && Date.parse(held$1.since) > ctx.now().getTime() - SENDING_STALE_MS) return { held: true };
|
|
3783
3992
|
ctx.db.raw.prepare("insert or replace into sending (key, seq, since) values (?, ?, ?)").get(key, event.seq, ctx.now().toISOString());
|
|
3784
|
-
return {};
|
|
3993
|
+
return held$1 ? { unsure: true } : {};
|
|
3785
3994
|
});
|
|
3786
3995
|
if ("done" in claim$1) {
|
|
3787
3996
|
cursor$1 = claim$1.done;
|
|
3788
3997
|
continue;
|
|
3789
3998
|
}
|
|
3790
3999
|
if ("held" in claim$1) break;
|
|
4000
|
+
const marker = markerOf(key, event);
|
|
4001
|
+
let unsure = "unsure" in claim$1;
|
|
3791
4002
|
try {
|
|
3792
4003
|
const threadExternal = isRoot ? null : rootLink.thread_external ?? rootLink.external;
|
|
3793
|
-
|
|
4004
|
+
let sent = null;
|
|
4005
|
+
if (unsure) {
|
|
4006
|
+
if (!provider.find) throw new Failure("unconfirmed", "The platform never said whether it took the message.");
|
|
4007
|
+
sent = await provider.find(marker, message, {
|
|
4008
|
+
place,
|
|
4009
|
+
threadExternal
|
|
4010
|
+
}, fetcher);
|
|
4011
|
+
unsure = false;
|
|
4012
|
+
}
|
|
4013
|
+
sent ??= await provider.deliver(message, {
|
|
3794
4014
|
place,
|
|
3795
4015
|
threadExternal
|
|
3796
|
-
}, fetcher, (id$1) => fileBytes(ctx, id$1));
|
|
4016
|
+
}, fetcher, (id$1) => fileBytes(ctx, id$1), marker);
|
|
4017
|
+
answered(ctx, sync, key);
|
|
3797
4018
|
ctx.db.write(() => {
|
|
3798
4019
|
ctx.db.raw.prepare("delete from sending where key = ? and seq = ?").get(key, event.seq);
|
|
3799
4020
|
const at = ctx.now().toISOString();
|
|
@@ -3836,14 +4057,19 @@ async function deliverPending(ctx, sync, fetcher = fetch) {
|
|
|
3836
4057
|
cursor$1 = event.seq;
|
|
3837
4058
|
delivered++;
|
|
3838
4059
|
} catch (error) {
|
|
3839
|
-
|
|
4060
|
+
const unconfirmed = error instanceof Failure && error.reason === "unconfirmed";
|
|
4061
|
+
if (!unconfirmed && (unsure || mayHaveLanded(error))) ctx.db.write(() => ctx.db.raw.prepare("update sending set since = ? where key = ? and seq = ?").get((/* @__PURE__ */ new Date(0)).toISOString(), key, event.seq));
|
|
4062
|
+
else ctx.db.write(() => ctx.db.raw.prepare("delete from sending where key = ? and seq = ?").get(key, event.seq));
|
|
3840
4063
|
failed$1++;
|
|
3841
|
-
|
|
4064
|
+
answered(ctx, sync, key, error);
|
|
4065
|
+
if (isOutage(error) && !tooLong(ctx, sync, key)) break;
|
|
4066
|
+
const attempts = isOutage(error) || unconfirmed ? DELIVERY_ATTEMPTS$1 : (ctx.db.raw.prepare("select attempts from outbox_attempts where key = ? and seq = ?").get(key, event.seq)?.attempts ?? 0) + 1;
|
|
3842
4067
|
if (attempts < DELIVERY_ATTEMPTS$1) {
|
|
3843
4068
|
ctx.db.write(() => ctx.db.raw.prepare("insert into outbox_attempts (key, seq, attempts) values (?, ?, ?) on conflict (key, seq) do update set attempts = excluded.attempts").get(key, event.seq, attempts));
|
|
3844
4069
|
break;
|
|
3845
4070
|
}
|
|
3846
4071
|
ctx.db.write(() => {
|
|
4072
|
+
ctx.db.raw.prepare("delete from sending where key = ? and seq = ?").get(key, event.seq);
|
|
3847
4073
|
append(ctx.db, {
|
|
3848
4074
|
type: "sync.failed",
|
|
3849
4075
|
by: board$1,
|
|
@@ -3852,7 +4078,7 @@ async function deliverPending(ctx, sync, fetcher = fetch) {
|
|
|
3852
4078
|
data: {
|
|
3853
4079
|
id: message.id,
|
|
3854
4080
|
key,
|
|
3855
|
-
error:
|
|
4081
|
+
error: failureOf(error)
|
|
3856
4082
|
}
|
|
3857
4083
|
}, ctx.now().toISOString());
|
|
3858
4084
|
ctx.db.raw.prepare("update cursors set seq = ? where name = ? and profile = ''").get(event.seq, name);
|
|
@@ -4296,9 +4522,10 @@ const b64 = (data) => Buffer.from(data).toString("base64url");
|
|
|
4296
4522
|
* The key a board's tokens are signed with. It is made once and kept, so a restart of `mu serve`
|
|
4297
4523
|
* doesn't strand every client holding a token.
|
|
4298
4524
|
*/
|
|
4525
|
+
const keyName = (where) => createHash("sha256").update(where).digest("hex").slice(0, 16);
|
|
4299
4526
|
function boardKey(where, dir = configDir()) {
|
|
4300
4527
|
const folder$1 = join(dir, "keys");
|
|
4301
|
-
const path = join(folder$1,
|
|
4528
|
+
const path = join(folder$1, keyName(where) + ".key");
|
|
4302
4529
|
try {
|
|
4303
4530
|
return Buffer.from(readFileSync(path, "utf8").trim(), "base64url");
|
|
4304
4531
|
} catch {
|
|
@@ -4318,6 +4545,46 @@ function boardKey(where, dir = configDir()) {
|
|
|
4318
4545
|
}
|
|
4319
4546
|
}
|
|
4320
4547
|
}
|
|
4548
|
+
/**
|
|
4549
|
+
* Keys a board signed with before its current one, kept so the tokens they signed stay good until the owner
|
|
4550
|
+
* drops them (`mu token drop-old-keys`). Read when `mu serve` starts.
|
|
4551
|
+
*/
|
|
4552
|
+
function retiredKeys(where, dir = configDir()) {
|
|
4553
|
+
const folder$1 = join(dir, "keys");
|
|
4554
|
+
let names$1;
|
|
4555
|
+
try {
|
|
4556
|
+
names$1 = readdirSync(folder$1);
|
|
4557
|
+
} catch {
|
|
4558
|
+
return [];
|
|
4559
|
+
}
|
|
4560
|
+
const prefix = `${keyName(where)}.`;
|
|
4561
|
+
return names$1.filter((name) => name.startsWith(prefix) && name.endsWith(".retired")).sort().map((name) => Buffer.from(readFileSync(join(folder$1, name), "utf8").trim(), "base64url"));
|
|
4562
|
+
}
|
|
4563
|
+
/**
|
|
4564
|
+
* Puts a new signing key in place of the board's current one, which is kept as retired: tokens it signed still
|
|
4565
|
+
* work, and every token made from now on is signed with the new one. Returns how many keys are retired.
|
|
4566
|
+
*/
|
|
4567
|
+
function rotateKey(where, now, dir = configDir()) {
|
|
4568
|
+
boardKey(where, dir);
|
|
4569
|
+
const folder$1 = join(dir, "keys");
|
|
4570
|
+
renameSync(join(folder$1, `${keyName(where)}.key`), join(folder$1, `${keyName(where)}.${now.toISOString().replace(/[:.]/g, "-")}.retired`));
|
|
4571
|
+
boardKey(where, dir);
|
|
4572
|
+
return { retired: retiredKeys(where, dir).length };
|
|
4573
|
+
}
|
|
4574
|
+
/** Deletes a board's retired keys, which stops every token they signed. Returns how many there were. */
|
|
4575
|
+
function dropRetiredKeys(where, dir = configDir()) {
|
|
4576
|
+
const folder$1 = join(dir, "keys");
|
|
4577
|
+
const prefix = `${keyName(where)}.`;
|
|
4578
|
+
let dropped = 0;
|
|
4579
|
+
try {
|
|
4580
|
+
for (const name of readdirSync(folder$1)) {
|
|
4581
|
+
if (!name.startsWith(prefix) || !name.endsWith(".retired")) continue;
|
|
4582
|
+
rmSync(join(folder$1, name));
|
|
4583
|
+
dropped++;
|
|
4584
|
+
}
|
|
4585
|
+
} catch {}
|
|
4586
|
+
return { dropped };
|
|
4587
|
+
}
|
|
4321
4588
|
const sign$1 = (key, body) => createHmac("sha256", key).update(body).digest();
|
|
4322
4589
|
function mint(key, claims) {
|
|
4323
4590
|
const body = `mu1.${b64(JSON.stringify(claims))}`;
|
|
@@ -4330,8 +4597,12 @@ function verify$1(key, token, now) {
|
|
|
4330
4597
|
const parts = token.split(".");
|
|
4331
4598
|
if (parts.length !== 3 || parts[0] !== "mu1") throw unauthorized("That isn't a token for this board.");
|
|
4332
4599
|
const given = Buffer.from(parts[2], "base64url");
|
|
4333
|
-
|
|
4334
|
-
|
|
4600
|
+
let signed = false;
|
|
4601
|
+
for (const each of Buffer.isBuffer(key) ? [key] : key) {
|
|
4602
|
+
const expected = sign$1(each, `${parts[0]}.${parts[1]}`);
|
|
4603
|
+
if (given.length === expected.length && timingSafeEqual(given, expected)) signed = true;
|
|
4604
|
+
}
|
|
4605
|
+
if (!signed) throw unauthorized("That isn't a token for this board.");
|
|
4335
4606
|
let claims;
|
|
4336
4607
|
try {
|
|
4337
4608
|
claims = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
|
|
@@ -4609,6 +4880,7 @@ function file(options = {}) {
|
|
|
4609
4880
|
});
|
|
4610
4881
|
/** The board's list of the tokens it made: a table in the board itself. */
|
|
4611
4882
|
const signingKey = () => options.key ?? boardKey(where());
|
|
4883
|
+
const oldKeys = () => options.key ? [] : retiredKeys(where());
|
|
4612
4884
|
const registry = () => options.tokens ?? dbRegistry(open(), () => (options.now ?? (() => /* @__PURE__ */ new Date()))().getTime());
|
|
4613
4885
|
const principal = options.principal ?? `local:user:${userInfo().username.toLowerCase().replace(/[^a-z0-9_.-]/g, "-")}`;
|
|
4614
4886
|
const narrowed = (c, caller) => caller.can ? {
|
|
@@ -4632,6 +4904,7 @@ function file(options = {}) {
|
|
|
4632
4904
|
},
|
|
4633
4905
|
registry,
|
|
4634
4906
|
signingKey,
|
|
4907
|
+
retiredKeys: oldKeys,
|
|
4635
4908
|
leases: {
|
|
4636
4909
|
take: async (request$1) => take(ctx(), request$1),
|
|
4637
4910
|
renew: async (request$1) => renew(ctx(), request$1),
|
|
@@ -4728,6 +5001,10 @@ function file(options = {}) {
|
|
|
4728
5001
|
messageFor(c, narrowed(c, caller), id$1);
|
|
4729
5002
|
return findTask(c, id$1);
|
|
4730
5003
|
},
|
|
5004
|
+
taskReport: async (caller, request$1) => {
|
|
5005
|
+
const c = ctx();
|
|
5006
|
+
return report(c, narrowed(c, caller), request$1);
|
|
5007
|
+
},
|
|
4731
5008
|
budgetSet: op(setBudget),
|
|
4732
5009
|
budgets: async (caller) => {
|
|
4733
5010
|
const c = ctx();
|
|
@@ -5154,6 +5431,7 @@ const ROUTES = [
|
|
|
5154
5431
|
"taskNeeds",
|
|
5155
5432
|
"taskList",
|
|
5156
5433
|
"task",
|
|
5434
|
+
"taskReport",
|
|
5157
5435
|
"scheduleCreate",
|
|
5158
5436
|
"scheduleCancel",
|
|
5159
5437
|
"scheduleList",
|
|
@@ -5257,7 +5535,7 @@ function createHandler(options) {
|
|
|
5257
5535
|
const tokens = options.tokens ?? options.backend.registry?.() ?? memoryRegistry();
|
|
5258
5536
|
const claimsOf = (req) => {
|
|
5259
5537
|
const header = req.headers.authorization;
|
|
5260
|
-
const claims = verify$1(options.key, header?.startsWith("Bearer ") ? header.slice(7) : void 0, now());
|
|
5538
|
+
const claims = verify$1([options.key, ...options.retired ?? []], header?.startsWith("Bearer ") ? header.slice(7) : void 0, now());
|
|
5261
5539
|
if (claims.jti && tokens.revoked(claims.jti)) throw new Failure("unauthorized", "That token was revoked.", { hint: "Get a new one from whoever runs the board." });
|
|
5262
5540
|
return claims;
|
|
5263
5541
|
};
|
|
@@ -5336,7 +5614,7 @@ function createHandler(options) {
|
|
|
5336
5614
|
if (bearer?.startsWith("Bearer ") && !(SANDBOX.has(route) && req.method === "POST") && !(route === "whoami" && req.method === "GET")) {
|
|
5337
5615
|
let held$1 = null;
|
|
5338
5616
|
try {
|
|
5339
|
-
held$1 = verify$1(options.key, bearer.slice(7), now());
|
|
5617
|
+
held$1 = verify$1([options.key, ...options.retired ?? []], bearer.slice(7), now());
|
|
5340
5618
|
} catch {}
|
|
5341
5619
|
if (held$1?.sandbox) throw new Failure("forbidden", "A sandbox's token reads and writes the board, and this isn't part of that.", { hint: "Ask whoever runs the board to do it, or use a token that was not made for a sandbox." });
|
|
5342
5620
|
}
|
|
@@ -5478,7 +5756,9 @@ function createHandler(options) {
|
|
|
5478
5756
|
if (url.searchParams.get("root") === "true") filter.root = true;
|
|
5479
5757
|
if (url.searchParams.getAll("kind").length) filter.kinds = url.searchParams.getAll("kind");
|
|
5480
5758
|
const resume = req.headers["last-event-id"] ?? url.searchParams.get("after");
|
|
5481
|
-
|
|
5759
|
+
const last = await options.backend.head(caller);
|
|
5760
|
+
let after = resume !== null && resume !== void 0 && /^\d+$/.test(String(resume)) ? Number(resume) : last;
|
|
5761
|
+
if (after > last) throw cursorAhead(after, last);
|
|
5482
5762
|
await options.backend.events(caller, {
|
|
5483
5763
|
after,
|
|
5484
5764
|
filter,
|
|
@@ -5709,6 +5989,7 @@ function mount(backend, options = {}) {
|
|
|
5709
5989
|
return toFetch(createHandler({
|
|
5710
5990
|
backend,
|
|
5711
5991
|
key,
|
|
5992
|
+
retired: backend.retiredKeys?.() ?? [],
|
|
5712
5993
|
hosts: hosts$1,
|
|
5713
5994
|
log,
|
|
5714
5995
|
...now ? { now: () => now().getTime() } : {}
|
|
@@ -6872,6 +7153,7 @@ const METHODS = [
|
|
|
6872
7153
|
"taskNeeds",
|
|
6873
7154
|
"taskList",
|
|
6874
7155
|
"task",
|
|
7156
|
+
"taskReport",
|
|
6875
7157
|
"scheduleCreate",
|
|
6876
7158
|
"scheduleCancel",
|
|
6877
7159
|
"scheduleList",
|
|
@@ -7040,4 +7322,4 @@ function cursor(input, flag) {
|
|
|
7040
7322
|
}
|
|
7041
7323
|
|
|
7042
7324
|
//#endregion
|
|
7043
|
-
export {
|
|
7325
|
+
export { PROGRESS as $, boardPath as A, heldClaim as B, listen as C, VERSION as D, RELEASE_HOSTS as E, retiredKeys as F, noteOut as G, declared as H, rotateKey as I, withLines as J, refused$2 as K, verify$1 as L, boardKey as M, dropRetiredKeys as N, releaseTarball as O, mint as P, LIMITS as Q, configDir as R, isLoopback as S, SANDBOX_ROUTES as T, env as U, keepClaim as V, fetchFile as W, processStart as X, SEND_MS as Y, OPEN_STATES as Z, ping as _, list as a, labelFilter as at, MOUNT as b, parse as c, cursorAhead as ct, ROOT as d, WORKFLOWS_PROFILE as et, board as f, armHooks as g, HOOKS_LEASE as h, id as i, inScope as it, file as j, loadOidc as k, str as l, misuse as lt, DROPPED as m, cursor as n, channelPath as nt, on as o, profileName as ot, syncLoop as p, sizeOf as q, duration as r, channelScope as rt, pairs as s, Failure as st, GLOBAL as t, actorId as tt, COPY as u, why as v, ROUTES as w, createHandler as x, holdLease as y, dropClaim as z };
|
package/dist/cli.js
CHANGED
|
@@ -9,10 +9,10 @@ process.emitWarning = ((warning, ...rest) => {
|
|
|
9
9
|
if ((typeof warning === "string" ? warning : warning.message).includes("SQLite is an experimental feature")) return;
|
|
10
10
|
return emitWarning.call(process, warning, ...rest);
|
|
11
11
|
});
|
|
12
|
-
await (await import("./module-
|
|
13
|
-
const { main } = await import("./main-
|
|
12
|
+
await (await import("./module-BX2IjSiv.js")).prepare(process.argv.slice(2), process.env);
|
|
13
|
+
const { main } = await import("./main-CLzQkYeG.js");
|
|
14
14
|
if (process.argv[2] === "mcp" && process.argv.length === 3) {
|
|
15
|
-
const { mcp } = await import("./mcp-
|
|
15
|
+
const { mcp } = await import("./mcp-CAAZRJgv.js");
|
|
16
16
|
await mcp(process.stdin, process.stdout, process.env, main);
|
|
17
17
|
process.exit(0);
|
|
18
18
|
}
|