spur-board 0.18.0 → 0.20.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.
Files changed (2) hide show
  1. package/dist/daemon.mjs +147 -22
  2. 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": return value.text;
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 feedLineWithLinkPayload = feedLineEditPayload.extend({ title: z.string().min(1) }).extend({
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: feedLineEditPayload
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: "✓ cleared",
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: c.body.kind === "feed.line" && c.body.payload.url !== void 0 ? [{
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",
@@ -11397,12 +11484,18 @@ async function reconcileMembership(trx, config, completeSince, at) {
11397
11484
  }
11398
11485
  //#endregion
11399
11486
  //#region ../core/src/domain/health.ts
11487
+ const ENDED_WORKER_KINDS = {
11488
+ complete: "worker_completed",
11489
+ kill: "worker_killed",
11490
+ vanished: "worker_vanished"
11491
+ };
11400
11492
  /** Derive actionable health facts without reading the clock or mutating input. */
11401
11493
  function evaluateSessionHealth(input) {
11402
11494
  const { sessions, tasks, spur, config, now } = input;
11403
11495
  const previousEpisode = input.episode ?? null;
11404
11496
  if (spur.blind) return {
11405
11497
  flags: [],
11498
+ held: [],
11406
11499
  statuses: [],
11407
11500
  hostLoad: null,
11408
11501
  episode: previousEpisode
@@ -11429,6 +11522,7 @@ function evaluateSessionHealth(input) {
11429
11522
  }
11430
11523
  }
11431
11524
  const flags = [];
11525
+ const held = [];
11432
11526
  const statuses = [];
11433
11527
  const seen = /* @__PURE__ */ new Set();
11434
11528
  for (const session of sessions) {
@@ -11437,11 +11531,14 @@ function evaluateSessionHealth(input) {
11437
11531
  seen.add(identity);
11438
11532
  const task = tasks[session.taskId];
11439
11533
  if (session.endedAt !== null) {
11440
- if (session.role === "worker" && spur.observationComplete && (session.endReason === "complete" || session.endReason === "kill" || session.endReason === "vanished") && task !== void 0 && !task.hasOpenPr && !task.hasMergedPr && !liveWorkerTasks.has(session.taskId)) flags.push({
11441
- taskId: session.taskId,
11442
- sessionId: session.id,
11443
- kind: "worker_vanished"
11444
- });
11534
+ if (session.role === "worker" && (session.endReason === "complete" || session.endReason === "kill" || session.endReason === "vanished") && task !== void 0 && !task.hasOpenPr && !task.hasMergedPr && !liveWorkerTasks.has(session.taskId)) {
11535
+ const flag = {
11536
+ taskId: session.taskId,
11537
+ sessionId: session.id,
11538
+ kind: ENDED_WORKER_KINDS[session.endReason]
11539
+ };
11540
+ (spur.observationComplete ? flags : held).push(flag);
11541
+ }
11445
11542
  continue;
11446
11543
  }
11447
11544
  if (session.health === "rate_limited") {
@@ -11466,6 +11563,7 @@ function evaluateSessionHealth(input) {
11466
11563
  }
11467
11564
  return {
11468
11565
  flags,
11566
+ held,
11469
11567
  statuses,
11470
11568
  hostLoad: episode === null ? null : { kind: "host_under_load" },
11471
11569
  episode
@@ -11474,6 +11572,11 @@ function evaluateSessionHealth(input) {
11474
11572
  //#endregion
11475
11573
  //#region ../core/src/app/fromYou.ts
11476
11574
  const episodeSchema = z.object({ startedAt: z.number() }).nullable();
11575
+ const ENDED_WORKER_LABELS = {
11576
+ worker_completed: "worker ended (completed), no PR",
11577
+ worker_killed: "worker ended (killed), no PR",
11578
+ worker_vanished: "worker vanished, no PR"
11579
+ };
11477
11580
  /** Reconciles every item in the caller's observation or tick transaction. */
11478
11581
  async function reconcileItems(trx, config, now, spurComplete) {
11479
11582
  const candidates = [];
@@ -11619,18 +11722,24 @@ async function reconcileItems(trx, config, now, spurComplete) {
11619
11722
  const task = taskById.get(Number(flag.taskId));
11620
11723
  if (task === void 0) continue;
11621
11724
  const fact = subjects.find((subject) => subject.taskId === flag.taskId && subject.id === flag.sessionId);
11725
+ const endedLabel = ENDED_WORKER_LABELS[flag.kind];
11622
11726
  candidates.push({
11623
- key: `health:${String(task.id)}:${flag.sessionId}:${flag.kind}`,
11727
+ key: healthKey(task.id, flag),
11624
11728
  taskId: task.id,
11625
- summary: `${task.key}: ${flag.kind.replaceAll("_", " ")} (${flag.sessionId})`,
11729
+ summary: `${task.key}: ${endedLabel ?? flag.kind.replaceAll("_", " ")} (${flag.sessionId})`,
11626
11730
  factAt: fact?.healthSince ?? null,
11627
11731
  source: "spur",
11628
11732
  priority: 4,
11629
- revision: flag.kind === "worker_vanished" ? fact?.endedAt ?? null : fact?.healthSince ?? null
11733
+ revision: endedLabel === void 0 ? fact?.healthSince ?? null : fact?.endedAt ?? null,
11734
+ suppressFeed: flag.kind === "worker_completed" || flag.kind === "worker_killed"
11630
11735
  });
11631
11736
  }
11632
11737
  const ordered = orderItems(candidates);
11633
11738
  const seen = new Set(ordered.map((item) => item.key));
11739
+ for (const flag of health.held) {
11740
+ const task = taskById.get(Number(flag.taskId));
11741
+ if (task !== void 0) seen.add(healthKey(task.id, flag));
11742
+ }
11634
11743
  const existing = await trx.selectFrom("operator_item").selectAll().where("kind", "=", "board_observation").where("cleared_at", "is", null).execute();
11635
11744
  for (const item of existing) if (!seen.has(item.item_key)) await clearItem(trx, item.id, new Date(now));
11636
11745
  for (const candidate of ordered) {
@@ -11663,6 +11772,9 @@ async function reconcileItems(trx, config, now, spurComplete) {
11663
11772
  });
11664
11773
  }
11665
11774
  }
11775
+ function healthKey(taskId, flag) {
11776
+ return `health:${String(taskId)}:${flag.sessionId}:${flag.kind}`;
11777
+ }
11666
11778
  //#endregion
11667
11779
  //#region ../core/src/app/observe.ts
11668
11780
  function refKey(ref) {
@@ -12804,6 +12916,7 @@ function createInbound(input) {
12804
12916
  function interactionOperation(event) {
12805
12917
  let id;
12806
12918
  let operationInput;
12919
+ let item;
12807
12920
  if (event.kind === "command") {
12808
12921
  const command = event.command;
12809
12922
  if (command?.kind === "query") {
@@ -12820,15 +12933,18 @@ function createInbound(input) {
12820
12933
  const parts = event.actionId.split(":");
12821
12934
  if (parts.length === 2 && /^I[1-9]\d*$/.test(parts[1] ?? "")) {
12822
12935
  id = parts[0] === "item.close" || parts[0] === "item.retry" ? parts[0] : void 0;
12823
- operationInput = { item: parts[1] };
12936
+ item = parts[1];
12937
+ operationInput = { item };
12824
12938
  } else if (parts.length === 3 && parts[0] === "item" && /^[1-9]\d*$/.test(parts[1] ?? "")) {
12825
12939
  id = parts[2] === "close" ? "item.close" : parts[2] === "retry" ? "item.retry" : void 0;
12826
- operationInput = { item: `I${parts[1] ?? ""}` };
12940
+ item = `I${parts[1] ?? ""}`;
12941
+ operationInput = { item };
12827
12942
  }
12828
12943
  }
12829
12944
  return {
12830
12945
  id,
12831
- operationInput
12946
+ operationInput,
12947
+ ...item === void 0 ? {} : { item }
12832
12948
  };
12833
12949
  }
12834
12950
  function tokenAction(event) {
@@ -12901,7 +13017,7 @@ function createInbound(input) {
12901
13017
  } catch {}
12902
13018
  return;
12903
13019
  }
12904
- const { id, operationInput } = interactionOperation(event);
13020
+ const { id, operationInput, item } = interactionOperation(event);
12905
13021
  let response;
12906
13022
  let cliHint;
12907
13023
  if (event.kind === "command" && event.command?.kind === "usage") response = plain(event.command.text);
@@ -12917,7 +13033,7 @@ function createInbound(input) {
12917
13033
  const reply = commandReply(id, value, operationInput);
12918
13034
  response = reply.body;
12919
13035
  cliHint = reply.cliHint;
12920
- } else response = plain(JSON.stringify(value));
13036
+ } else response = plain(id === "item.close" ? `Closed ${item ?? ""}.` : `Retry started for ${item ?? ""}.`);
12921
13037
  } catch (error) {
12922
13038
  if (!(error instanceof CommandError)) await recordFailure(event, error, new Date(clock.now()).toISOString());
12923
13039
  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 +15758,19 @@ function originKeyFromBlocks(blocks) {
15642
15758
  function escapeText(value) {
15643
15759
  return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
15644
15760
  }
15761
+ /** Slack strikes only within one line and not across edge spaces or a `~` inside. */
15762
+ function strike(text) {
15763
+ return text.split("\n").map((line) => {
15764
+ const value = line.trim().replaceAll("~", "∼");
15765
+ return value.length === 0 ? "" : `~${escapeText(value)}~`;
15766
+ }).join("\n");
15767
+ }
15645
15768
  function inline(value) {
15646
15769
  switch (value.kind) {
15647
15770
  case "text": return escapeText(value.text);
15648
15771
  case "emphasis": return `*${escapeText(value.text)}*`;
15649
15772
  case "code": return `\`${value.text.replaceAll("`", "´")}\``;
15773
+ case "strike": return strike(value.text);
15650
15774
  case "link": return `<${value.url.replace(/[<>|]/g, "")}|${escapeText(value.text).replaceAll("|", "¦")}>`;
15651
15775
  case "mention": return `<@${value.user}>`;
15652
15776
  }
@@ -15662,7 +15786,8 @@ function literal(value) {
15662
15786
  switch (value.kind) {
15663
15787
  case "text":
15664
15788
  case "emphasis":
15665
- case "code": return value.text;
15789
+ case "code":
15790
+ case "strike": return value.text;
15666
15791
  case "link": return `${value.text} (${value.url})`;
15667
15792
  case "mention": return `<@${value.user}>`;
15668
15793
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spur-board",
3
- "version": "0.18.0",
3
+ "version": "0.20.0",
4
4
  "license": "MIT",
5
5
  "engines": {
6
6
  "node": "^24.12.0 || ^26.0.0"