spur-board 0.18.0 → 0.19.0
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/dist/daemon.mjs +133 -20
- package/package.json +1 -1
package/dist/daemon.mjs
CHANGED
|
@@ -7590,7 +7590,8 @@ function visibleInline(value) {
|
|
|
7590
7590
|
switch (value.kind) {
|
|
7591
7591
|
case "text":
|
|
7592
7592
|
case "emphasis":
|
|
7593
|
-
case "code":
|
|
7593
|
+
case "code":
|
|
7594
|
+
case "strike": return value.text;
|
|
7594
7595
|
case "link": return `${value.text} (${value.url})`;
|
|
7595
7596
|
case "mention": return `<@${value.user}>`;
|
|
7596
7597
|
}
|
|
@@ -8137,7 +8138,16 @@ const feedLineEditPayload = z.strictObject({
|
|
|
8137
8138
|
itemKey: z.string().min(1),
|
|
8138
8139
|
taskId: id.optional()
|
|
8139
8140
|
});
|
|
8140
|
-
const
|
|
8141
|
+
const feedLinePayload = feedLineEditPayload.extend({ title: z.string().min(1) });
|
|
8142
|
+
/** `text` is the line's summary; a row without `resolved` predates the resolved rendering. */
|
|
8143
|
+
const feedEditPayload = feedLineEditPayload.extend({
|
|
8144
|
+
url: z.url().optional(),
|
|
8145
|
+
resolved: z.strictObject({
|
|
8146
|
+
by: actorIdSchema,
|
|
8147
|
+
at: z.iso.datetime()
|
|
8148
|
+
}).optional()
|
|
8149
|
+
});
|
|
8150
|
+
const feedLineWithLinkPayload = feedLinePayload.extend({
|
|
8141
8151
|
itemId: id.optional(),
|
|
8142
8152
|
url: z.url().optional(),
|
|
8143
8153
|
actions: z.array(z.strictObject({
|
|
@@ -8171,7 +8181,7 @@ const outboxBodySchema = z.discriminatedUnion("kind", [
|
|
|
8171
8181
|
}),
|
|
8172
8182
|
z.strictObject({
|
|
8173
8183
|
kind: z.literal("feed.line.edit"),
|
|
8174
|
-
payload:
|
|
8184
|
+
payload: feedEditPayload
|
|
8175
8185
|
}),
|
|
8176
8186
|
z.strictObject({
|
|
8177
8187
|
kind: z.literal("doorbell"),
|
|
@@ -8271,13 +8281,18 @@ async function enqueueFeedEdit(trx, input) {
|
|
|
8271
8281
|
dedupeKey: `feed.line.edit:${input.itemKey}:${String(input.raise)}`,
|
|
8272
8282
|
payload: {
|
|
8273
8283
|
key: input.key,
|
|
8274
|
-
text:
|
|
8284
|
+
text: input.summary,
|
|
8275
8285
|
persona: {
|
|
8276
8286
|
name: "board",
|
|
8277
8287
|
role: "board"
|
|
8278
8288
|
},
|
|
8279
8289
|
itemKey: input.itemKey,
|
|
8280
|
-
taskId: input.taskId ?? void 0
|
|
8290
|
+
taskId: input.taskId ?? void 0,
|
|
8291
|
+
...input.url === "" ? {} : { url: input.url },
|
|
8292
|
+
resolved: {
|
|
8293
|
+
by: input.by,
|
|
8294
|
+
at: input.at.toISOString()
|
|
8295
|
+
}
|
|
8281
8296
|
},
|
|
8282
8297
|
parent: input.lineId,
|
|
8283
8298
|
at: input.at
|
|
@@ -8513,6 +8528,13 @@ async function enqueueInboundDoorbell(trx, input) {
|
|
|
8513
8528
|
}
|
|
8514
8529
|
//#endregion
|
|
8515
8530
|
//#region ../core/src/app/feed.ts
|
|
8531
|
+
/** The struck summary is capped so the edit stays one message part. */
|
|
8532
|
+
const MAX_SUMMARY = 500;
|
|
8533
|
+
/** Counts code points, so the cut never splits a surrogate pair. */
|
|
8534
|
+
function capSummary(text) {
|
|
8535
|
+
const points = Array.from(text);
|
|
8536
|
+
return points.length <= MAX_SUMMARY ? text : `${points.slice(0, MAX_SUMMARY - 1).join("")}…`;
|
|
8537
|
+
}
|
|
8516
8538
|
/** Raise one item generation. A repeated raise of an active key is idempotent. */
|
|
8517
8539
|
async function raiseItem(trx, input) {
|
|
8518
8540
|
return raiseItemWith(trx, input, enqueueFeedLine);
|
|
@@ -8533,9 +8555,70 @@ async function clearItem(trx, itemId, at, actor = "system") {
|
|
|
8533
8555
|
lineId: item.line_outbox_id,
|
|
8534
8556
|
key: task?.key ?? "spur-board",
|
|
8535
8557
|
taskId: item.task_id,
|
|
8558
|
+
summary: capSummary(item.text),
|
|
8559
|
+
url: item.url,
|
|
8560
|
+
by: actor,
|
|
8536
8561
|
at
|
|
8537
8562
|
});
|
|
8538
8563
|
}
|
|
8564
|
+
function resolvedLine(by, at, config) {
|
|
8565
|
+
const parsed = parseActorId(by);
|
|
8566
|
+
if (parsed === null || parsed.actor === "system") return [{
|
|
8567
|
+
kind: "text",
|
|
8568
|
+
text: "✓ Resolved: condition ended"
|
|
8569
|
+
}];
|
|
8570
|
+
const time = new Intl.DateTimeFormat("en-GB", {
|
|
8571
|
+
timeZone: config.digest.tz,
|
|
8572
|
+
hour: "2-digit",
|
|
8573
|
+
minute: "2-digit",
|
|
8574
|
+
hourCycle: "h23"
|
|
8575
|
+
}).format(new Date(at));
|
|
8576
|
+
return [
|
|
8577
|
+
{
|
|
8578
|
+
kind: "text",
|
|
8579
|
+
text: "✓ Resolved by "
|
|
8580
|
+
},
|
|
8581
|
+
parsed.actor === "agent" ? {
|
|
8582
|
+
kind: "text",
|
|
8583
|
+
text: `${parsed.actorRef.project}/${parsed.actorRef.session}`
|
|
8584
|
+
} : {
|
|
8585
|
+
kind: "mention",
|
|
8586
|
+
user: userIdSchema.parse(config.operator.slack)
|
|
8587
|
+
},
|
|
8588
|
+
{
|
|
8589
|
+
kind: "text",
|
|
8590
|
+
text: ` at ${time}`
|
|
8591
|
+
}
|
|
8592
|
+
];
|
|
8593
|
+
}
|
|
8594
|
+
/** A cleared line: its key line, the struck summary and who resolved it when; no actions. */
|
|
8595
|
+
function resolvedFeedBody(payload, config) {
|
|
8596
|
+
const { key, url, text, resolved } = payload;
|
|
8597
|
+
return [
|
|
8598
|
+
{
|
|
8599
|
+
kind: "paragraph",
|
|
8600
|
+
children: [url === void 0 ? {
|
|
8601
|
+
kind: "text",
|
|
8602
|
+
text: key
|
|
8603
|
+
} : {
|
|
8604
|
+
kind: "link",
|
|
8605
|
+
url,
|
|
8606
|
+
text: key
|
|
8607
|
+
}]
|
|
8608
|
+
},
|
|
8609
|
+
{
|
|
8610
|
+
kind: "quote",
|
|
8611
|
+
children: [{
|
|
8612
|
+
kind: "strike",
|
|
8613
|
+
text
|
|
8614
|
+
}]
|
|
8615
|
+
},
|
|
8616
|
+
{
|
|
8617
|
+
kind: "paragraph",
|
|
8618
|
+
children: resolvedLine(resolved.by, resolved.at, config)
|
|
8619
|
+
}
|
|
8620
|
+
];
|
|
8621
|
+
}
|
|
8539
8622
|
//#endregion
|
|
8540
8623
|
//#region ../core/src/app/tokens.ts
|
|
8541
8624
|
const REQUEST_LIFETIME_MS = 900 * 1e3;
|
|
@@ -8625,7 +8708,7 @@ async function decideTokenInTransaction(trx, itemId, decision, at) {
|
|
|
8625
8708
|
decided_at: at.toISOString()
|
|
8626
8709
|
}).where("id", "=", row.id).execute();
|
|
8627
8710
|
await journalToken(trx, decision === "approve" ? "token_approved" : "token_denied", row.name, at);
|
|
8628
|
-
await clearItem(trx, row.item_id, at);
|
|
8711
|
+
await clearItem(trx, row.item_id, at, "operator");
|
|
8629
8712
|
return {
|
|
8630
8713
|
name: row.name,
|
|
8631
8714
|
status: next
|
|
@@ -8679,7 +8762,7 @@ const tokenRevokeMutation = {
|
|
|
8679
8762
|
decided_at: ctx.at
|
|
8680
8763
|
}).where("id", "=", row.id).execute();
|
|
8681
8764
|
await journalToken(trx, "token_revoked", row.name, at);
|
|
8682
|
-
await clearItem(trx, row.item_id, at);
|
|
8765
|
+
await clearItem(trx, row.item_id, at, ctx.actor);
|
|
8683
8766
|
}
|
|
8684
8767
|
return {
|
|
8685
8768
|
name: row.name,
|
|
@@ -10302,13 +10385,17 @@ function createSender(options) {
|
|
|
10302
10385
|
if (gateway === void 0) throw new Error("gateway is not configured");
|
|
10303
10386
|
const to = target(c);
|
|
10304
10387
|
if (to === null) throw new Error("a dependent row without its parent ref");
|
|
10388
|
+
const { body } = c;
|
|
10305
10389
|
const request = {
|
|
10306
10390
|
key: c.key,
|
|
10307
10391
|
maybeSent: c.maybeSent,
|
|
10308
10392
|
...firstDeliveryAt === null ? {} : { firstAttemptAt: new Date(firstDeliveryAt) },
|
|
10309
10393
|
target: to,
|
|
10310
10394
|
persona: c.body.payload.persona,
|
|
10311
|
-
body:
|
|
10395
|
+
body: body.kind === "feed.line.edit" && body.payload.resolved !== void 0 ? resolvedFeedBody({
|
|
10396
|
+
...body.payload,
|
|
10397
|
+
resolved: body.payload.resolved
|
|
10398
|
+
}, options.config) : c.body.kind === "feed.line" && c.body.payload.url !== void 0 ? [{
|
|
10312
10399
|
kind: "paragraph",
|
|
10313
10400
|
children: [{
|
|
10314
10401
|
kind: "link",
|
|
@@ -11403,6 +11490,7 @@ function evaluateSessionHealth(input) {
|
|
|
11403
11490
|
const previousEpisode = input.episode ?? null;
|
|
11404
11491
|
if (spur.blind) return {
|
|
11405
11492
|
flags: [],
|
|
11493
|
+
held: [],
|
|
11406
11494
|
statuses: [],
|
|
11407
11495
|
hostLoad: null,
|
|
11408
11496
|
episode: previousEpisode
|
|
@@ -11429,6 +11517,7 @@ function evaluateSessionHealth(input) {
|
|
|
11429
11517
|
}
|
|
11430
11518
|
}
|
|
11431
11519
|
const flags = [];
|
|
11520
|
+
const held = [];
|
|
11432
11521
|
const statuses = [];
|
|
11433
11522
|
const seen = /* @__PURE__ */ new Set();
|
|
11434
11523
|
for (const session of sessions) {
|
|
@@ -11437,11 +11526,14 @@ function evaluateSessionHealth(input) {
|
|
|
11437
11526
|
seen.add(identity);
|
|
11438
11527
|
const task = tasks[session.taskId];
|
|
11439
11528
|
if (session.endedAt !== null) {
|
|
11440
|
-
if (session.role === "worker" &&
|
|
11441
|
-
|
|
11442
|
-
|
|
11443
|
-
|
|
11444
|
-
|
|
11529
|
+
if (session.role === "worker" && (session.endReason === "complete" || session.endReason === "kill" || session.endReason === "vanished") && task !== void 0 && !task.hasOpenPr && !task.hasMergedPr && !liveWorkerTasks.has(session.taskId)) {
|
|
11530
|
+
const flag = {
|
|
11531
|
+
taskId: session.taskId,
|
|
11532
|
+
sessionId: session.id,
|
|
11533
|
+
kind: "worker_vanished"
|
|
11534
|
+
};
|
|
11535
|
+
(spur.observationComplete ? flags : held).push(flag);
|
|
11536
|
+
}
|
|
11445
11537
|
continue;
|
|
11446
11538
|
}
|
|
11447
11539
|
if (session.health === "rate_limited") {
|
|
@@ -11466,6 +11558,7 @@ function evaluateSessionHealth(input) {
|
|
|
11466
11558
|
}
|
|
11467
11559
|
return {
|
|
11468
11560
|
flags,
|
|
11561
|
+
held,
|
|
11469
11562
|
statuses,
|
|
11470
11563
|
hostLoad: episode === null ? null : { kind: "host_under_load" },
|
|
11471
11564
|
episode
|
|
@@ -11620,7 +11713,7 @@ async function reconcileItems(trx, config, now, spurComplete) {
|
|
|
11620
11713
|
if (task === void 0) continue;
|
|
11621
11714
|
const fact = subjects.find((subject) => subject.taskId === flag.taskId && subject.id === flag.sessionId);
|
|
11622
11715
|
candidates.push({
|
|
11623
|
-
key:
|
|
11716
|
+
key: healthKey(task.id, flag),
|
|
11624
11717
|
taskId: task.id,
|
|
11625
11718
|
summary: `${task.key}: ${flag.kind.replaceAll("_", " ")} (${flag.sessionId})`,
|
|
11626
11719
|
factAt: fact?.healthSince ?? null,
|
|
@@ -11631,6 +11724,10 @@ async function reconcileItems(trx, config, now, spurComplete) {
|
|
|
11631
11724
|
}
|
|
11632
11725
|
const ordered = orderItems(candidates);
|
|
11633
11726
|
const seen = new Set(ordered.map((item) => item.key));
|
|
11727
|
+
for (const flag of health.held) {
|
|
11728
|
+
const task = taskById.get(Number(flag.taskId));
|
|
11729
|
+
if (task !== void 0) seen.add(healthKey(task.id, flag));
|
|
11730
|
+
}
|
|
11634
11731
|
const existing = await trx.selectFrom("operator_item").selectAll().where("kind", "=", "board_observation").where("cleared_at", "is", null).execute();
|
|
11635
11732
|
for (const item of existing) if (!seen.has(item.item_key)) await clearItem(trx, item.id, new Date(now));
|
|
11636
11733
|
for (const candidate of ordered) {
|
|
@@ -11663,6 +11760,9 @@ async function reconcileItems(trx, config, now, spurComplete) {
|
|
|
11663
11760
|
});
|
|
11664
11761
|
}
|
|
11665
11762
|
}
|
|
11763
|
+
function healthKey(taskId, flag) {
|
|
11764
|
+
return `health:${String(taskId)}:${flag.sessionId}:${flag.kind}`;
|
|
11765
|
+
}
|
|
11666
11766
|
//#endregion
|
|
11667
11767
|
//#region ../core/src/app/observe.ts
|
|
11668
11768
|
function refKey(ref) {
|
|
@@ -12804,6 +12904,7 @@ function createInbound(input) {
|
|
|
12804
12904
|
function interactionOperation(event) {
|
|
12805
12905
|
let id;
|
|
12806
12906
|
let operationInput;
|
|
12907
|
+
let item;
|
|
12807
12908
|
if (event.kind === "command") {
|
|
12808
12909
|
const command = event.command;
|
|
12809
12910
|
if (command?.kind === "query") {
|
|
@@ -12820,15 +12921,18 @@ function createInbound(input) {
|
|
|
12820
12921
|
const parts = event.actionId.split(":");
|
|
12821
12922
|
if (parts.length === 2 && /^I[1-9]\d*$/.test(parts[1] ?? "")) {
|
|
12822
12923
|
id = parts[0] === "item.close" || parts[0] === "item.retry" ? parts[0] : void 0;
|
|
12823
|
-
|
|
12924
|
+
item = parts[1];
|
|
12925
|
+
operationInput = { item };
|
|
12824
12926
|
} else if (parts.length === 3 && parts[0] === "item" && /^[1-9]\d*$/.test(parts[1] ?? "")) {
|
|
12825
12927
|
id = parts[2] === "close" ? "item.close" : parts[2] === "retry" ? "item.retry" : void 0;
|
|
12826
|
-
|
|
12928
|
+
item = `I${parts[1] ?? ""}`;
|
|
12929
|
+
operationInput = { item };
|
|
12827
12930
|
}
|
|
12828
12931
|
}
|
|
12829
12932
|
return {
|
|
12830
12933
|
id,
|
|
12831
|
-
operationInput
|
|
12934
|
+
operationInput,
|
|
12935
|
+
...item === void 0 ? {} : { item }
|
|
12832
12936
|
};
|
|
12833
12937
|
}
|
|
12834
12938
|
function tokenAction(event) {
|
|
@@ -12901,7 +13005,7 @@ function createInbound(input) {
|
|
|
12901
13005
|
} catch {}
|
|
12902
13006
|
return;
|
|
12903
13007
|
}
|
|
12904
|
-
const { id, operationInput } = interactionOperation(event);
|
|
13008
|
+
const { id, operationInput, item } = interactionOperation(event);
|
|
12905
13009
|
let response;
|
|
12906
13010
|
let cliHint;
|
|
12907
13011
|
if (event.kind === "command" && event.command?.kind === "usage") response = plain(event.command.text);
|
|
@@ -12917,7 +13021,7 @@ function createInbound(input) {
|
|
|
12917
13021
|
const reply = commandReply(id, value, operationInput);
|
|
12918
13022
|
response = reply.body;
|
|
12919
13023
|
cliHint = reply.cliHint;
|
|
12920
|
-
} else response = plain(
|
|
13024
|
+
} else response = plain(id === "item.close" ? `Closed ${item ?? ""}.` : `Retry started for ${item ?? ""}.`);
|
|
12921
13025
|
} catch (error) {
|
|
12922
13026
|
if (!(error instanceof CommandError)) await recordFailure(event, error, new Date(clock.now()).toISOString());
|
|
12923
13027
|
response = plain(error instanceof CommandError && error.code !== "not_implemented" ? event.kind === "command" ? `${ERRORS[error.code].message} ${ERRORS[error.code].hint}` : error.hint : "not available yet");
|
|
@@ -15642,11 +15746,19 @@ function originKeyFromBlocks(blocks) {
|
|
|
15642
15746
|
function escapeText(value) {
|
|
15643
15747
|
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
15644
15748
|
}
|
|
15749
|
+
/** Slack strikes only within one line and not across edge spaces or a `~` inside. */
|
|
15750
|
+
function strike(text) {
|
|
15751
|
+
return text.split("\n").map((line) => {
|
|
15752
|
+
const value = line.trim().replaceAll("~", "∼");
|
|
15753
|
+
return value.length === 0 ? "" : `~${escapeText(value)}~`;
|
|
15754
|
+
}).join("\n");
|
|
15755
|
+
}
|
|
15645
15756
|
function inline(value) {
|
|
15646
15757
|
switch (value.kind) {
|
|
15647
15758
|
case "text": return escapeText(value.text);
|
|
15648
15759
|
case "emphasis": return `*${escapeText(value.text)}*`;
|
|
15649
15760
|
case "code": return `\`${value.text.replaceAll("`", "´")}\``;
|
|
15761
|
+
case "strike": return strike(value.text);
|
|
15650
15762
|
case "link": return `<${value.url.replace(/[<>|]/g, "")}|${escapeText(value.text).replaceAll("|", "¦")}>`;
|
|
15651
15763
|
case "mention": return `<@${value.user}>`;
|
|
15652
15764
|
}
|
|
@@ -15662,7 +15774,8 @@ function literal(value) {
|
|
|
15662
15774
|
switch (value.kind) {
|
|
15663
15775
|
case "text":
|
|
15664
15776
|
case "emphasis":
|
|
15665
|
-
case "code":
|
|
15777
|
+
case "code":
|
|
15778
|
+
case "strike": return value.text;
|
|
15666
15779
|
case "link": return `${value.text} (${value.url})`;
|
|
15667
15780
|
case "mention": return `<@${value.user}>`;
|
|
15668
15781
|
}
|