spur-board 0.29.0 → 0.31.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/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { G as configSchema, K as requiredSecretKeys, P as ERRORS, l as roleCanUseOperation, q as SLACK_BOT_SCOPES, r as SYSTEMD_SERVICE_SETTINGS, u as OPERATIONS } from "./src-XNs3RhSm.mjs";
2
- import { a as errorExitCode, i as CliError, n as requestOperation, o as renderCliError, r as requestTokenEnrollment, s as escapeTerminalControls } from "./client-BHnD83EW.mjs";
3
- import { a as memoryVerdictCache, c as loadClientConfig, d as resolveDaemonAddress, i as fileVerdictCache, l as loadEnrollmentConfig, n as cliPackageVersion, o as configFile, s as dataDirectory, t as checkCatalog, u as readConfiguredPort } from "./config-CoUN_LCM.mjs";
1
+ import { G as configSchema, K as requiredSecretKeys, P as ERRORS, l as roleCanUseOperation, q as SLACK_BOT_SCOPES, r as SYSTEMD_SERVICE_SETTINGS, u as OPERATIONS } from "./src-B63VaSzU.mjs";
2
+ import { a as errorExitCode, i as CliError, n as requestOperation, o as renderCliError, r as requestTokenEnrollment, s as escapeTerminalControls } from "./client-DtDNMMO-.mjs";
3
+ import { a as memoryVerdictCache, c as loadClientConfig, d as resolveDaemonAddress, i as fileVerdictCache, l as loadEnrollmentConfig, n as cliPackageVersion, o as configFile, s as dataDirectory, t as checkCatalog, u as readConfiguredPort } from "./config-D3ltZ-MU.mjs";
4
4
  import { createHash, randomBytes, randomUUID } from "node:crypto";
5
5
  import { accessSync, chmodSync, closeSync, constants, cpSync, existsSync, ftruncateSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
6
6
  import { homedir, hostname, userInfo } from "node:os";
@@ -1,4 +1,4 @@
1
- import { I as errorContextSchema, L as errorEnvelopeSchema, P as ERRORS, f as renderJsonError, z as successEnvelopeSchema } from "./src-XNs3RhSm.mjs";
1
+ import { I as errorContextSchema, L as errorEnvelopeSchema, P as ERRORS, f as renderJsonError, z as successEnvelopeSchema } from "./src-B63VaSzU.mjs";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { z } from "zod";
4
4
  import { request } from "node:http";
package/dist/client.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as requestOperation, r as requestTokenEnrollment, t as fetchCatalogVersion } from "./client-BHnD83EW.mjs";
1
+ import { n as requestOperation, r as requestTokenEnrollment, t as fetchCatalogVersion } from "./client-DtDNMMO-.mjs";
2
2
  export { fetchCatalogVersion, requestOperation, requestTokenEnrollment };
@@ -1,5 +1,5 @@
1
- import { G as configSchema, c as buildCatalogSnapshot, u as OPERATIONS } from "./src-XNs3RhSm.mjs";
2
- import { i as CliError, t as fetchCatalogVersion } from "./client-BHnD83EW.mjs";
1
+ import { G as configSchema, c as buildCatalogSnapshot, u as OPERATIONS } from "./src-B63VaSzU.mjs";
2
+ import { i as CliError, t as fetchCatalogVersion } from "./client-DtDNMMO-.mjs";
3
3
  import { randomUUID } from "node:crypto";
4
4
  import { closeSync, constants, fstatSync, lstatSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
5
5
  import { homedir } from "node:os";
package/dist/daemon.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { A as errorCodeOf, C as SESSION_STATUSES, D as ticketFactsSchema, E as sessionFactsSchema, F as err, G as configSchema, K as requiredSecretKeys, M as parseRef$1, N as taskKeySchema, O as actorIdSchema, P as ERRORS, R as ok, S as SESSION_HEALTH_STATES, T as prRefSchema, U as DEFAULT_SLACK_COMMAND, V as DEFAULT_LINK, W as RESERVED_PROJECT, _ as interactionRefSchema, a as batchSchema, b as EVENT_KINDS, c as buildCatalogSnapshot, d as renderHttpProblem, g as inboundEventSchema, h as conversationRefSchema, i as AdapterError, j as parseActorId, k as encodeActorId, l as roleCanUseOperation, m as SPACE_IDS, n as BOARD_TICK_MS, o as entityRefSchema, q as SLACK_BOT_SCOPES, s as sourceCursorSchema, t as assertNever, u as OPERATIONS, v as messageRefSchema, w as prFactsSchema, x as eventPayloadSchemas, y as userIdSchema, z as successEnvelopeSchema } from "./src-XNs3RhSm.mjs";
1
+ import { A as errorCodeOf, C as SESSION_STATUSES, D as ticketFactsSchema, E as sessionFactsSchema, F as err, G as configSchema, K as requiredSecretKeys, M as parseRef$1, N as taskKeySchema, O as actorIdSchema, P as ERRORS, R as ok, S as SESSION_HEALTH_STATES, T as prRefSchema, U as DEFAULT_SLACK_COMMAND, V as DEFAULT_LINK, W as RESERVED_PROJECT, _ as interactionRefSchema, a as batchSchema, b as EVENT_KINDS, c as buildCatalogSnapshot, d as renderHttpProblem, g as inboundEventSchema, h as conversationRefSchema, i as AdapterError, j as parseActorId, k as encodeActorId, l as roleCanUseOperation, m as SPACE_IDS, n as BOARD_TICK_MS, o as entityRefSchema, q as SLACK_BOT_SCOPES, s as sourceCursorSchema, t as assertNever, u as OPERATIONS, v as messageRefSchema, w as prFactsSchema, x as eventPayloadSchemas, y as userIdSchema, z as successEnvelopeSchema } from "./src-B63VaSzU.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import { createHash, randomUUID } from "node:crypto";
4
4
  import { closeSync, existsSync, fstatSync, fsyncSync, ftruncateSync, linkSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeSync } from "node:fs";
@@ -8191,32 +8191,137 @@ async function dispatchOperation(deps, id, input, actor, key) {
8191
8191
  return operation.kind === "query" ? createQuery(deps)(handler, input, actor) : createApply(deps)(handler, input, actor, key);
8192
8192
  }
8193
8193
  //#endregion
8194
- //#region ../core/src/app/item-raise.ts
8195
- const NO_FEED = /* @__PURE__ */ new Set([
8194
+ //#region ../core/src/domain/fromYou.ts
8195
+ /** Every operator item kind; `ITEM_POLICY` must give each one a policy. */
8196
+ const ITEM_KINDS = [
8197
+ "token_request",
8198
+ "post_blocked",
8196
8199
  "post_failed",
8200
+ "transport_health",
8197
8201
  "answer_undelivered",
8198
- "transport_health"
8199
- ]);
8202
+ "worker_not_reading",
8203
+ "answer_author_unavailable",
8204
+ "inbound_failure",
8205
+ "inbound_gap",
8206
+ "board_observation",
8207
+ "worker_ended"
8208
+ ];
8209
+ const ITEM_POLICY = {
8210
+ token_request: {
8211
+ retry: "none",
8212
+ feed: true,
8213
+ priority: 4,
8214
+ buttons: "approve_deny",
8215
+ reconciled: false
8216
+ },
8217
+ post_blocked: {
8218
+ retry: "never_sent",
8219
+ feed: true,
8220
+ priority: 4,
8221
+ buttons: "item",
8222
+ reconciled: false
8223
+ },
8224
+ post_failed: {
8225
+ retry: "requeue_post",
8226
+ feed: false,
8227
+ priority: 1,
8228
+ buttons: "item",
8229
+ reconciled: true
8230
+ },
8231
+ transport_health: {
8232
+ retry: "probe_transport",
8233
+ feed: false,
8234
+ priority: 1,
8235
+ buttons: "item",
8236
+ reconciled: false
8237
+ },
8238
+ answer_undelivered: {
8239
+ retry: "restart_ring",
8240
+ feed: false,
8241
+ priority: 4,
8242
+ buttons: "item",
8243
+ reconciled: false
8244
+ },
8245
+ worker_not_reading: {
8246
+ retry: "restart_ring",
8247
+ feed: true,
8248
+ priority: 4,
8249
+ buttons: "item",
8250
+ reconciled: false
8251
+ },
8252
+ answer_author_unavailable: {
8253
+ retry: "none",
8254
+ feed: true,
8255
+ priority: 4,
8256
+ buttons: "item",
8257
+ reconciled: false
8258
+ },
8259
+ inbound_failure: {
8260
+ retry: "reapply_inbound",
8261
+ feed: true,
8262
+ priority: 4,
8263
+ buttons: "item",
8264
+ reconciled: false
8265
+ },
8266
+ inbound_gap: {
8267
+ retry: "none",
8268
+ feed: true,
8269
+ priority: 4,
8270
+ buttons: "item",
8271
+ reconciled: false
8272
+ },
8273
+ board_observation: {
8274
+ retry: "none",
8275
+ feed: true,
8276
+ priority: 4,
8277
+ buttons: "item",
8278
+ reconciled: true
8279
+ },
8280
+ worker_ended: {
8281
+ retry: "none",
8282
+ feed: false,
8283
+ priority: 4,
8284
+ buttons: "item",
8285
+ reconciled: true
8286
+ }
8287
+ };
8288
+ /** Guards a stored kind: the column is free text and old or hand-written rows may hold others. */
8289
+ function isItemKind(kind) {
8290
+ return Object.hasOwn(ITEM_POLICY, kind);
8291
+ }
8292
+ /** Whether the kind's feed line and status entry offer Retry. */
8293
+ function hasRetryButton(kind) {
8294
+ const retry = ITEM_POLICY[kind].retry;
8295
+ return retry === "requeue_post" || retry === "restart_ring" || retry === "reapply_inbound" || retry === "probe_transport";
8296
+ }
8297
+ /** The kinds `reconcileItems` owns: it clears an active one whose candidate is gone. */
8298
+ const RECONCILED_KINDS = ITEM_KINDS.filter((kind) => ITEM_POLICY[kind].reconciled);
8299
+ function fingerprint(candidate) {
8300
+ return createHash("sha256").update(JSON.stringify([
8301
+ candidate.key,
8302
+ candidate.summary,
8303
+ candidate.source,
8304
+ candidate.revision ?? null
8305
+ ])).digest("hex");
8306
+ }
8307
+ /** Stable ordering within priority, then by item identity. */
8308
+ function orderItems(items) {
8309
+ return [...items].sort((left, right) => left.priority - right.priority || left.key.localeCompare(right.key));
8310
+ }
8200
8311
  async function journal$3(trx, item, kind, at, rule, actor = "system") {
8201
8312
  await emit(trx, kind, (item.task_id === null ? void 0 : await trx.selectFrom("task").select(["project"]).where("id", "=", item.task_id).executeTakeFirstOrThrow())?.project ?? "_board", item.task_id, at.toISOString(), {
8202
8313
  item: `I${String(item.id)}`,
8203
8314
  ...kind === "from_you_raised" && rule !== void 0 ? { rule } : {}
8204
8315
  }, actor);
8205
8316
  }
8206
- /** Kinds whose item has a retry action besides `delivery:<id>` (see `items.ts`). */
8207
- const RETRY_KINDS = /* @__PURE__ */ new Set([
8208
- "answer_undelivered",
8209
- "worker_not_reading",
8210
- "inbound_failure"
8211
- ]);
8212
8317
  /** Every item line gets Close, after Retry when its kind has a retry action. */
8213
- function itemActions(item) {
8214
- const id = String(item.id);
8318
+ function itemActions(itemId, kind) {
8319
+ const id = String(itemId);
8215
8320
  const close = {
8216
8321
  id: `item:${id}:close`,
8217
8322
  label: "Close"
8218
8323
  };
8219
- if (item.kind === "token_request") return [
8324
+ if (ITEM_POLICY[kind].buttons === "approve_deny") return [
8220
8325
  {
8221
8326
  id: `token:${id}:approve`,
8222
8327
  label: "Approve"
@@ -8227,7 +8332,7 @@ function itemActions(item) {
8227
8332
  },
8228
8333
  close
8229
8334
  ];
8230
- return item.item_key.startsWith("delivery:") || RETRY_KINDS.has(item.kind) ? [{
8335
+ return hasRetryButton(kind) ? [{
8231
8336
  id: `item:${id}:retry`,
8232
8337
  label: "Retry"
8233
8338
  }, close] : [close];
@@ -8254,11 +8359,11 @@ async function raiseItemWith(trx, input, writeLine) {
8254
8359
  fingerprint: input.fingerprint ?? null,
8255
8360
  fact_at: input.factAt ?? null,
8256
8361
  source: input.source ?? null,
8257
- priority: input.priority ?? null,
8362
+ priority: input.priority ?? ITEM_POLICY[input.kind].priority,
8258
8363
  inbound_event_json: null
8259
8364
  }).returningAll().executeTakeFirstOrThrow();
8260
8365
  await journal$3(trx, item, "from_you_raised", input.at, input.rule);
8261
- if (!NO_FEED.has(item.kind) && !input.suppressFeed) {
8366
+ if (ITEM_POLICY[input.kind].feed) {
8262
8367
  const key = (item.task_id === null ? null : await trx.selectFrom("task").select("key").where("id", "=", item.task_id).executeTakeFirstOrThrow())?.key ?? "spur-board";
8263
8368
  const line = await writeLine(trx, {
8264
8369
  itemId: item.id,
@@ -8269,7 +8374,7 @@ async function raiseItemWith(trx, input, writeLine) {
8269
8374
  title: `${key}: ${item.text}`,
8270
8375
  url: item.url,
8271
8376
  taskId: item.task_id,
8272
- actions: itemActions(item),
8377
+ actions: itemActions(item.id, input.kind),
8273
8378
  at: input.at
8274
8379
  });
8275
8380
  if (line !== null) item = await trx.updateTable("operator_item").set({ line_outbox_id: line }).where("id", "=", item.id).returningAll().executeTakeFirstOrThrow();
@@ -8466,6 +8571,36 @@ async function enqueueLiveFeedLine(trx, input) {
8466
8571
  at: input.at
8467
8572
  })).id;
8468
8573
  }
8574
+ const QUESTION_CHARS = 120;
8575
+ const ANSWER_CHARS = 200;
8576
+ /** Collapses whitespace and cuts by code points to `limit`, ending a cut text with `…`. */
8577
+ function shorten(text, limit) {
8578
+ const points = Array.from(text.replace(/\s+/g, " ").trim());
8579
+ return points.length <= limit ? points.join("") : `${points.slice(0, limit - 1).join("")}…`;
8580
+ }
8581
+ /** One line per curator answer; the key names the answer comment, so a retry adds none. */
8582
+ async function enqueueCuratorAnswerLine(trx, input) {
8583
+ const block = `B${String(input.blockId)}`;
8584
+ const itemKey = `curator-answer:comment:${String(input.commentId)}`;
8585
+ await insertOutbox(trx, {
8586
+ kind: "feed.line",
8587
+ dedupeKey: `feed.line:${itemKey}`,
8588
+ payload: {
8589
+ key: input.key,
8590
+ text: `${block} · ${input.asker} asked: ${shorten(input.question, QUESTION_CHARS)} → curator answered: ${shorten(input.answer, ANSWER_CHARS)}`,
8591
+ title: `${input.key} ${block} answered by curator`,
8592
+ persona: {
8593
+ name: input.curator,
8594
+ role: "curator"
8595
+ },
8596
+ itemKey,
8597
+ taskId: input.taskId,
8598
+ ...input.url === "" ? {} : { url: input.url }
8599
+ },
8600
+ parent: null,
8601
+ at: input.at
8602
+ });
8603
+ }
8469
8604
  async function enqueueFeedEdit(trx, input) {
8470
8605
  return (await insertOutbox(trx, {
8471
8606
  kind: "feed.line.edit",
@@ -9179,7 +9314,7 @@ function personaRole(role) {
9179
9314
  switch (addressee.kind) {
9180
9315
  case "operator": return "board";
9181
9316
  case "worker": return "worker";
9182
- case "curator":
9317
+ case "curator": return "curator";
9183
9318
  case "orchestrator": return "orchestrator";
9184
9319
  default: return assertNever(addressee);
9185
9320
  }
@@ -9980,6 +10115,27 @@ async function editInboundComment(trx, input) {
9980
10115
  }
9981
10116
  return updated;
9982
10117
  }
10118
+ /** Posts a curator's answer to the feed; an operator answer is already on the board. */
10119
+ async function queueCuratorAnswerLine(trx, task, block, answer, ctx, config) {
10120
+ if (parseAddressee(block.addressee_role).kind !== "curator") return;
10121
+ if (authorRole(config, task, ctx.actor) === "operator") return;
10122
+ const curator = parseActorId(ctx.actor);
10123
+ if (curator?.actor !== "agent") return;
10124
+ const asker = parseActorId(block.author);
10125
+ const question = await trx.selectFrom("comment").select("text").where("block_id", "=", block.id).where("id", "<", answer.id).orderBy("id").executeTakeFirst();
10126
+ await enqueueCuratorAnswerLine(trx, {
10127
+ taskId: task.id,
10128
+ key: task.key,
10129
+ url: taskUrl(task, config),
10130
+ blockId: block.id,
10131
+ commentId: answer.id,
10132
+ asker: asker?.actor === "agent" ? `${asker.actorRef.project}/${asker.actorRef.session}` : block.author,
10133
+ question: question?.text ?? block.reason,
10134
+ answer: answer.text,
10135
+ curator: curator.actorRef.project,
10136
+ at: new Date(ctx.at)
10137
+ });
10138
+ }
9983
10139
  /** Concrete block and comment mutations for the generic apply boundary. */
9984
10140
  function createBlockMutations(config) {
9985
10141
  return {
@@ -10066,8 +10222,10 @@ function createBlockMutations(config) {
10066
10222
  answerBlock(current(block));
10067
10223
  });
10068
10224
  const comment = await addComment(trx, task, block, input.text, ctx, authorRole(config, task, block.author), config);
10225
+ const updated = await closeOpenBlock(trx, task, block, ctx, "done", null);
10226
+ await queueCuratorAnswerLine(trx, task, block, comment, ctx, config);
10069
10227
  return {
10070
- block: blockView(await closeOpenBlock(trx, task, block, ctx, "done", null), task),
10228
+ block: blockView(updated, task),
10071
10229
  comment: commentView(comment, task)
10072
10230
  };
10073
10231
  }
@@ -10194,7 +10352,7 @@ async function archiveTask(trx, input) {
10194
10352
  };
10195
10353
  const blocks = await trx.selectFrom("block").selectAll().where("task_id", "=", task.id).where("state", "=", "open").orderBy("id").execute();
10196
10354
  for (const block of blocks) await closeOpenBlock(trx, task, block, ctx, "archived", null);
10197
- const items = await trx.selectFrom("operator_item").select("id").where("kind", "=", "board_observation").where("task_id", "=", task.id).where("cleared_at", "is", null).orderBy("id").execute();
10355
+ const items = await trx.selectFrom("operator_item").select("id").where("kind", "in", RECONCILED_KINDS).where("task_id", "=", task.id).where("cleared_at", "is", null).orderBy("id").execute();
10198
10356
  for (const item of items) await clearItem(trx, item.id, new Date(at), actor);
10199
10357
  const comments = await trx.selectFrom("comment").select("id").where("task_id", "=", task.id).execute();
10200
10358
  await trx.updateTable("outbox").set({
@@ -10310,20 +10468,6 @@ function createMembershipMutations(config) {
10310
10468
  };
10311
10469
  }
10312
10470
  //#endregion
10313
- //#region ../core/src/domain/fromYou.ts
10314
- function fingerprint(candidate) {
10315
- return createHash("sha256").update(JSON.stringify([
10316
- candidate.key,
10317
- candidate.summary,
10318
- candidate.source,
10319
- candidate.revision ?? null
10320
- ])).digest("hex");
10321
- }
10322
- /** Stable ordering within priority, then by item identity. */
10323
- function orderItems(items) {
10324
- return [...items].sort((left, right) => left.priority - right.priority || left.key.localeCompare(right.key));
10325
- }
10326
- //#endregion
10327
10471
  //#region ../core/src/app/sender.ts
10328
10472
  /**
10329
10473
  * Spur refused a doorbell for good (a permanent 4xx): the sender stops ringing and ends the ring
@@ -10384,8 +10528,6 @@ async function syncTransportItem(trx, gateway, at) {
10384
10528
  url: "",
10385
10529
  taskId: null,
10386
10530
  blockId: null,
10387
- priority: 1,
10388
- suppressFeed: true,
10389
10531
  at
10390
10532
  });
10391
10533
  if (item.text !== text) await trx.updateTable("operator_item").set({ text }).where("id", "=", item.id).execute();
@@ -10977,7 +11119,6 @@ function createSender(options) {
10977
11119
  }
10978
11120
  //#endregion
10979
11121
  //#region ../core/src/app/items.ts
10980
- const DOORBELL_ITEM = /^(?:answer_undelivered|worker_not_reading):(.+)$/;
10981
11122
  async function loadItem(trx, id) {
10982
11123
  const item = await trx.selectFrom("operator_item").selectAll().where("id", "=", Number(id.slice(1))).executeTakeFirst();
10983
11124
  if (item === void 0) throw new CommandError("not_found", "Check the item ID.");
@@ -10988,7 +11129,7 @@ async function loadItem(trx, id) {
10988
11129
  }
10989
11130
  /** The task a `delivery:<outbox id>` item's row belongs to; the item itself has no task. */
10990
11131
  async function deliveryTask(trx, item) {
10991
- if (!item.item_key.startsWith("delivery:")) return void 0;
11132
+ if (item.kind !== "post_failed") return void 0;
10992
11133
  const row = await trx.selectFrom("outbox").select([
10993
11134
  "kind",
10994
11135
  "dedupe_key",
@@ -11016,25 +11157,34 @@ function notApplicable(hint) {
11016
11157
  * except a retry on a transport item, which the sender clears when the transport is back.
11017
11158
  */
11018
11159
  function createItemMutations(deps) {
11160
+ /** Runs the retry behind the item's kind; false when the item must stay raised. */
11019
11161
  async function retryAction(trx, item, at) {
11020
11162
  const closeHint = `close it with \`board item close I${String(item.id)}\`.`;
11021
- if (item.item_key.startsWith("delivery:")) {
11022
- if (await requeuePostFailed(trx, [Number(item.item_key.slice(9))], at) === 0) throw notApplicable("The delivery is no longer failed.");
11023
- return;
11024
- }
11025
- const doorbell = DOORBELL_ITEM.exec(item.item_key);
11026
- if (doorbell?.[1] !== void 0) {
11027
- await restartNotification(trx, doorbell[1], new Date(at));
11028
- return;
11029
- }
11030
- if (item.kind === "inbound_failure") {
11031
- const reapply = deps.reapplyInbound?.();
11032
- if (reapply === void 0) throw notApplicable("Slack inbound is not running; close the item instead.");
11033
- await reapply(trx, item.id, at);
11034
- return;
11163
+ const noAction = notApplicable(`This item has no retry action; ${closeHint}`);
11164
+ const action = isItemKind(item.kind) ? ITEM_POLICY[item.kind].retry : "none";
11165
+ switch (action) {
11166
+ case "requeue_post":
11167
+ if (await requeuePostFailed(trx, [Number(item.item_key.slice(9))], at) === 0) throw notApplicable("The delivery is no longer failed.");
11168
+ return true;
11169
+ case "restart_ring": {
11170
+ const prefix = `${item.kind}:`;
11171
+ if (!item.item_key.startsWith(prefix) || item.item_key.length === prefix.length) throw noAction;
11172
+ await restartNotification(trx, item.item_key.slice(prefix.length), new Date(at));
11173
+ return true;
11174
+ }
11175
+ case "reapply_inbound": {
11176
+ const reapply = deps.reapplyInbound?.();
11177
+ if (reapply === void 0) throw notApplicable("Slack inbound is not running; close the item instead.");
11178
+ await reapply(trx, item.id, at);
11179
+ return true;
11180
+ }
11181
+ case "probe_transport":
11182
+ if (await retryTransport(trx, item.item_key.slice(10), at) === 0) throw notApplicable("No transport outage is recorded; the item clears on its own.");
11183
+ return false;
11184
+ case "never_sent": throw notApplicable(`The blocked text is never sent; ${closeHint}`);
11185
+ case "none": throw noAction;
11186
+ default: return assertNever(action);
11035
11187
  }
11036
- if (item.kind === "post_blocked") throw notApplicable(`The blocked text is never sent; ${closeHint}`);
11037
- throw notApplicable(`This item has no retry action; ${closeHint}`);
11038
11188
  }
11039
11189
  return {
11040
11190
  retry: {
@@ -11044,12 +11194,7 @@ function createItemMutations(deps) {
11044
11194
  const { item, task } = await loadItem(trx, input.item);
11045
11195
  if ((task ?? await deliveryTask(trx, item))?.membership === "archived") throw new CommandError("task_archived", "Add the task again before retrying its item.");
11046
11196
  if (item.cleared_at !== null) throw notApplicable("The item is already cleared.");
11047
- if (item.kind === "transport_health") {
11048
- if (await retryTransport(trx, item.item_key.slice(10), ctx.at) === 0) throw notApplicable("No transport outage is recorded; the item clears on its own.");
11049
- return view(item, task);
11050
- }
11051
- await retryAction(trx, item, ctx.at);
11052
- await clearItem(trx, item.id, new Date(ctx.at), ctx.actor);
11197
+ if (await retryAction(trx, item, ctx.at)) await clearItem(trx, item.id, new Date(ctx.at), ctx.actor);
11053
11198
  return view(item, task);
11054
11199
  }
11055
11200
  },
@@ -11061,11 +11206,8 @@ function createItemMutations(deps) {
11061
11206
  if (item.cleared_at === null) {
11062
11207
  const hash = item.fingerprint ?? fingerprint({
11063
11208
  key: item.item_key,
11064
- taskId: item.task_id,
11065
11209
  summary: item.text,
11066
- factAt: item.fact_at,
11067
11210
  source: item.source,
11068
- priority: item.priority ?? 0,
11069
11211
  revision: null
11070
11212
  });
11071
11213
  await trx.insertInto("dismissal").values({
@@ -11078,7 +11220,7 @@ function createItemMutations(deps) {
11078
11220
  dismissed_by: ctx.actor,
11079
11221
  dismissed_at: ctx.at
11080
11222
  })).execute();
11081
- if (item.item_key.startsWith("delivery:")) await trx.updateTable("outbox").set({
11223
+ if (item.kind === "post_failed") await trx.updateTable("outbox").set({
11082
11224
  state: "dead",
11083
11225
  last_error: `closed by ${ctx.actor} (I${String(item.id)})`
11084
11226
  }).where("id", "=", Number(item.item_key.slice(9))).where("state", "=", "post_failed").execute();
@@ -11966,8 +12108,10 @@ async function reconcileItems(trx, config, now, spurComplete) {
11966
12108
  const sourceById = new Map(sources.map((state) => [state.source, state]));
11967
12109
  for (const source of sources) {
11968
12110
  if (source.blind_reason === null) continue;
12111
+ if (source.blind_reason === "stale" && source.source !== "spur") continue;
11969
12112
  candidates.push({
11970
12113
  key: `source:${source.source}`,
12114
+ kind: "board_observation",
11971
12115
  taskId: null,
11972
12116
  summary: `${source.source}: ${source.blind_message ?? source.blind_reason}`,
11973
12117
  factAt: source.observed_at,
@@ -11979,7 +12123,7 @@ async function reconcileItems(trx, config, now, spurComplete) {
11979
12123
  const taskById = new Map(tasks.map((task) => [task.id, task]));
11980
12124
  const misses = await trx.selectFrom("source_miss").selectAll().execute();
11981
12125
  for (const miss of misses) {
11982
- if (miss.outcome !== "not_found" && miss.outcome !== "no_access" && miss.gone !== 1) continue;
12126
+ if (miss.gone !== 1) continue;
11983
12127
  const ref = JSON.parse(miss.ref);
11984
12128
  if (ref.kind === "pr" && ref.repo !== void 0 && ref.number !== void 0) {
11985
12129
  const links = await trx.selectFrom("link").select("task_id").where("entity", "=", "pr").where(sql`lower(repo) = ${ref.repo.toLowerCase()}`).where("number", "=", ref.number).execute();
@@ -11988,6 +12132,7 @@ async function reconcileItems(trx, config, now, spurComplete) {
11988
12132
  if (task === void 0) continue;
11989
12133
  candidates.push({
11990
12134
  key: `pr-outcome:${String(task.id)}:${ref.repo}#${String(ref.number)}`,
12135
+ kind: "board_observation",
11991
12136
  taskId: task.id,
11992
12137
  summary: `${task.key}: linked pull request ${miss.outcome ?? "gone"}`,
11993
12138
  factAt: sourceById.get(miss.source)?.observed_at ?? null,
@@ -11998,10 +12143,11 @@ async function reconcileItems(trx, config, now, spurComplete) {
11998
12143
  continue;
11999
12144
  }
12000
12145
  if (ref.kind !== "ticket") continue;
12001
- const task = tasks.find((entry) => entry.key === ref.key && (entry.manual_include === 1 || miss.outcome === "no_access" || miss.gone === 1));
12146
+ const task = tasks.find((entry) => entry.key === ref.key);
12002
12147
  if (task === void 0) continue;
12003
12148
  candidates.push({
12004
12149
  key: `lookup:${String(task.id)}`,
12150
+ kind: "board_observation",
12005
12151
  taskId: task.id,
12006
12152
  summary: `${task.key}: tracker returned ${miss.outcome ?? "gone"}`,
12007
12153
  factAt: sourceById.get(miss.source)?.observed_at ?? null,
@@ -12011,6 +12157,7 @@ async function reconcileItems(trx, config, now, spurComplete) {
12011
12157
  }
12012
12158
  for (const task of tasks) if (task.membership === "out_of_filter") candidates.push({
12013
12159
  key: `filter:${String(task.id)}`,
12160
+ kind: "board_observation",
12014
12161
  taskId: task.id,
12015
12162
  summary: `${task.key} left the tracker filter while work is still linked`,
12016
12163
  factAt: task.last_change_at,
@@ -12025,6 +12172,7 @@ async function reconcileItems(trx, config, now, spurComplete) {
12025
12172
  if (task === void 0) continue;
12026
12173
  if (block.addressee_role === "operator" && block.author !== "operator" && !blockedIds.has(block.id)) candidates.push({
12027
12174
  key: `operator-block:${String(block.id)}`,
12175
+ kind: "board_observation",
12028
12176
  taskId: task.id,
12029
12177
  summary: `${task.key}: ${block.reason}`,
12030
12178
  factAt: block.created_at,
@@ -12033,6 +12181,7 @@ async function reconcileItems(trx, config, now, spurComplete) {
12033
12181
  });
12034
12182
  if (now - Date.parse(block.created_at) >= config.thresholds.blockOpenMs) candidates.push({
12035
12183
  key: `block:${String(block.id)}`,
12184
+ kind: "board_observation",
12036
12185
  taskId: task.id,
12037
12186
  summary: `${task.key}: block has been open for more than a day`,
12038
12187
  factAt: block.created_at,
@@ -12043,12 +12192,12 @@ async function reconcileItems(trx, config, now, spurComplete) {
12043
12192
  const failedDeliveries = await trx.selectFrom("outbox").select(["id", "kind"]).where("state", "=", "post_failed").execute();
12044
12193
  for (const delivery of failedDeliveries) candidates.push({
12045
12194
  key: `delivery:${String(delivery.id)}`,
12195
+ kind: "post_failed",
12046
12196
  taskId: null,
12047
12197
  summary: `Delivery failed: ${delivery.kind}`,
12048
12198
  factAt: null,
12049
12199
  source: null,
12050
- priority: 1,
12051
- suppressFeed: delivery.kind === "feed.line" || delivery.kind === "feed.line.edit"
12200
+ priority: ITEM_POLICY.post_failed.priority
12052
12201
  });
12053
12202
  const subjects = (await trx.selectFrom("link").innerJoin("session_snapshot", "session_snapshot.id", "link.session_id").select([
12054
12203
  "link.task_id",
@@ -12091,15 +12240,6 @@ async function reconcileItems(trx, config, now, spurComplete) {
12091
12240
  key: "host_load_episode",
12092
12241
  value: toJson(episodeSchema, health.episode)
12093
12242
  }).onConflict((oc) => oc.column("key").doUpdateSet({ value: toJson(episodeSchema, health.episode) })).execute();
12094
- if (health.hostLoad !== null) candidates.push({
12095
- key: "host-load",
12096
- taskId: null,
12097
- summary: "Host under load",
12098
- factAt: health.episode === null ? null : new Date(health.episode.startedAt).toISOString(),
12099
- source: "spur",
12100
- priority: 4,
12101
- revision: health.episode === null ? null : String(health.episode.startedAt)
12102
- });
12103
12243
  for (const flag of health.flags) {
12104
12244
  const task = taskById.get(Number(flag.taskId));
12105
12245
  if (task === void 0) continue;
@@ -12107,13 +12247,13 @@ async function reconcileItems(trx, config, now, spurComplete) {
12107
12247
  const endedLabel = ENDED_WORKER_LABELS[flag.kind];
12108
12248
  candidates.push({
12109
12249
  key: healthKey(task.id, flag),
12250
+ kind: flag.kind === "worker_completed" || flag.kind === "worker_killed" ? "worker_ended" : "board_observation",
12110
12251
  taskId: task.id,
12111
12252
  summary: `${task.key}: ${endedLabel ?? flag.kind.replaceAll("_", " ")} (${flag.sessionId})`,
12112
12253
  factAt: fact?.healthSince ?? null,
12113
12254
  source: "spur",
12114
12255
  priority: 4,
12115
- revision: endedLabel === void 0 ? fact?.healthSince ?? null : fact?.endedAt ?? null,
12116
- suppressFeed: flag.kind === "worker_completed" || flag.kind === "worker_killed"
12256
+ revision: endedLabel === void 0 ? fact?.healthSince ?? null : fact?.endedAt ?? null
12117
12257
  });
12118
12258
  }
12119
12259
  const ordered = orderItems(candidates);
@@ -12122,15 +12262,16 @@ async function reconcileItems(trx, config, now, spurComplete) {
12122
12262
  const task = taskById.get(Number(flag.taskId));
12123
12263
  if (task !== void 0) seen.add(healthKey(task.id, flag));
12124
12264
  }
12125
- const existing = await trx.selectFrom("operator_item").selectAll().where("kind", "=", "board_observation").where("cleared_at", "is", null).execute();
12265
+ const existing = await trx.selectFrom("operator_item").selectAll().where("kind", "in", RECONCILED_KINDS).where("cleared_at", "is", null).execute();
12126
12266
  for (const item of existing) if (!seen.has(item.item_key)) await clearItem(trx, item.id, new Date(now));
12127
12267
  for (const candidate of ordered) {
12128
12268
  const hash = fingerprint(candidate);
12129
12269
  const old = existing.find((item) => item.item_key === candidate.key);
12130
12270
  const dismissal = await trx.selectFrom("dismissal").select("fingerprint").where("item_key", "=", candidate.key).executeTakeFirst();
12131
- if (old !== void 0 && (dismissal?.fingerprint === hash || old.fingerprint !== hash)) await clearItem(trx, old.id, new Date(now));
12271
+ const kept = old !== void 0 && old.fingerprint === hash && old.kind === candidate.kind;
12272
+ if (old !== void 0 && (dismissal?.fingerprint === hash || !kept)) await clearItem(trx, old.id, new Date(now));
12132
12273
  if (dismissal?.fingerprint === hash) continue;
12133
- if (old !== void 0 && old.fingerprint === hash) {
12274
+ if (kept) {
12134
12275
  if (old.fact_at !== candidate.factAt || old.source !== candidate.source) await trx.updateTable("operator_item").set({
12135
12276
  fact_at: candidate.factAt,
12136
12277
  source: candidate.source
@@ -12140,7 +12281,7 @@ async function reconcileItems(trx, config, now, spurComplete) {
12140
12281
  const task = candidate.taskId === null ? null : taskById.get(candidate.taskId);
12141
12282
  await raiseItem(trx, {
12142
12283
  itemKey: candidate.key,
12143
- kind: "board_observation",
12284
+ kind: candidate.kind,
12144
12285
  text: candidate.summary,
12145
12286
  url: task === null || task === void 0 ? "https://github.com" : taskUrl(task, config),
12146
12287
  taskId: candidate.taskId,
@@ -12149,8 +12290,7 @@ async function reconcileItems(trx, config, now, spurComplete) {
12149
12290
  fingerprint: hash,
12150
12291
  factAt: candidate.factAt,
12151
12292
  source: candidate.source,
12152
- priority: candidate.priority,
12153
- suppressFeed: candidate.suppressFeed ?? false
12293
+ priority: candidate.priority
12154
12294
  });
12155
12295
  }
12156
12296
  }
@@ -13980,6 +14120,8 @@ function teamScopeDenied(error, query) {
13980
14120
  return /\b(?:slug|name)\b/i.test(error.message) && /\bread:(?:org|discussion)\b/i.test(error.message);
13981
14121
  }
13982
14122
  const REVIEWER_FIELDS = "requestedReviewer { __typename ... on Bot { login } ... on Mannequin { login } ... on User { login } ... on Team { slug } ... on EnterpriseTeam { slug } } asCodeOwner";
14123
+ const REVIEW_FIELDS = "id author { __typename login } state commit { oid } submittedAt";
14124
+ const COMMENT_FIELDS = "nodes { id author { __typename login } createdAt } pageInfo { hasPreviousPage startCursor }";
13983
14125
  const CLOSING_FIELDS = "nodes { number repository { nameWithOwner } } pageInfo { hasNextPage endCursor }";
13984
14126
  const prFields = (number, closing = false) => `id number url title updatedAt state isDraft mergeable mergeStateStatus
13985
14127
  author { login } headRefName headRefOid
@@ -13987,7 +14129,8 @@ const prFields = (number, closing = false) => `id number url title updatedAt sta
13987
14129
  ... on CheckRun { __typename name status conclusion startedAt completedAt checkSuite { createdAt } isRequired(pullRequestNumber: ${String(number)}) }
13988
14130
  ... on StatusContext { __typename context state createdAt isRequired(pullRequestNumber: ${String(number)}) }
13989
14131
  } pageInfo { hasNextPage endCursor } } }
13990
- reviews(first: 100) { nodes { author { login } state commit { oid } submittedAt } pageInfo { hasNextPage endCursor } }
14132
+ reviews(first: 100) { nodes { ${REVIEW_FIELDS} } pageInfo { hasNextPage endCursor } }
14133
+ comments(last: 100) { ${COMMENT_FIELDS} }
13991
14134
  reviewThreads(first: 100) { nodes { isResolved } pageInfo { hasNextPage endCursor } }
13992
14135
  reviewRequests(first: 100) { nodes { ${REVIEWER_FIELDS} } pageInfo { hasNextPage endCursor } }${closing ? `\n closingIssuesReferences(first: 100) { ${CLOSING_FIELDS} }` : ""}`;
13993
14136
  const DISCOVERY_FIELDS = `nodes { number updatedAt author { login } state } pageInfo { hasNextPage endCursor }`;
@@ -14001,8 +14144,9 @@ function detailQuery(numbers, closing = false) {
14001
14144
  return `query PrDetails($owner: String!, $repo: String!) { rateLimit { remaining resetAt } ${aliases(numbers, closing)} }`;
14002
14145
  }
14003
14146
  function pageQuery(connection, bootstrap = false) {
14147
+ if (connection === "comments") return `query PrPage($owner: String!, $repo: String!, $number: Int!, $before: String!) { rateLimit { remaining resetAt } repository(owner: $owner, name: $repo) { pullRequest(number: $number) { comments(last: 100, before: $before) { ${COMMENT_FIELDS} } } } }`;
14004
14148
  if (connection === "pullRequests") return `query DiscoveryPage($owner: String!, $repo: String!, $after: String!) { rateLimit { remaining resetAt } repository(owner: $owner, name: $repo) { pullRequests(first: 100, after: $after, states: [${bootstrap ? "OPEN" : "OPEN, MERGED"}], orderBy: {field: UPDATED_AT, direction: DESC}) { ${DISCOVERY_FIELDS} } } }`;
14005
- return `query PrPage($owner: String!, $repo: String!, $number: Int!, $after: String!) { rateLimit { remaining resetAt } repository(owner: $owner, name: $repo) { pullRequest(number: $number) { ${connection === "closingIssuesReferences" ? `closingIssuesReferences(first: 100, after: $after) { ${CLOSING_FIELDS} }` : connection === "contexts" ? `statusCheckRollup { contexts(first: 100, after: $after) { nodes { ... on CheckRun { __typename name status conclusion startedAt completedAt checkSuite { createdAt } isRequired(pullRequestNumber: $number) } ... on StatusContext { __typename context state createdAt isRequired(pullRequestNumber: $number) } } pageInfo { hasNextPage endCursor } } }` : `${connection}(first: 100, after: $after) { nodes { ${connection === "reviews" ? "author { login } state commit { oid } submittedAt" : connection === "reviewThreads" ? "isResolved" : REVIEWER_FIELDS} } pageInfo { hasNextPage endCursor } }`} } } }`;
14149
+ return `query PrPage($owner: String!, $repo: String!, $number: Int!, $after: String!) { rateLimit { remaining resetAt } repository(owner: $owner, name: $repo) { pullRequest(number: $number) { ${connection === "closingIssuesReferences" ? `closingIssuesReferences(first: 100, after: $after) { ${CLOSING_FIELDS} }` : connection === "contexts" ? `statusCheckRollup { contexts(first: 100, after: $after) { nodes { ... on CheckRun { __typename name status conclusion startedAt completedAt checkSuite { createdAt } isRequired(pullRequestNumber: $number) } ... on StatusContext { __typename context state createdAt isRequired(pullRequestNumber: $number) } } pageInfo { hasNextPage endCursor } } }` : `${connection}(first: 100, after: $after) { nodes { ${connection === "reviews" ? REVIEW_FIELDS : connection === "reviewThreads" ? "isResolved" : REVIEWER_FIELDS} } pageInfo { hasNextPage endCursor } }`} } } }`;
14006
14150
  }
14007
14151
  var GithubClient = class {
14008
14152
  token;
@@ -14114,6 +14258,10 @@ const KEPT_REVIEWS = [
14114
14258
  "dismissed"
14115
14259
  ];
14116
14260
  const actor = z.object({ login: z.string().optional() }).nullish();
14261
+ const typedActor = z.object({
14262
+ __typename: z.string(),
14263
+ login: z.string().min(1)
14264
+ }).nullable();
14117
14265
  const checkRunWire = z.object({
14118
14266
  __typename: z.literal("CheckRun"),
14119
14267
  name: z.string(),
@@ -14133,12 +14281,18 @@ const statusContextWire = z.object({
14133
14281
  });
14134
14282
  const contextWire = z.discriminatedUnion("__typename", [checkRunWire, statusContextWire]);
14135
14283
  const reviewWire = z.object({
14136
- author: actor,
14284
+ id: z.string().min(1),
14285
+ author: typedActor,
14137
14286
  state: z.string(),
14138
14287
  commit: z.object({ oid: z.string() }).nullable(),
14139
14288
  submittedAt: z.string().nullish()
14140
14289
  }).refine((review) => review.commit !== null || !review.author?.login || review.submittedAt == null || !KEPT_REVIEWS.includes(review.state.toLowerCase()), { path: ["commit"] });
14141
14290
  const nodes = (node) => z.object({ nodes: z.array(node) });
14291
+ const commentWire = z.object({
14292
+ id: z.string().min(1),
14293
+ author: typedActor,
14294
+ createdAt: z.iso.datetime()
14295
+ });
14142
14296
  const loginReviewer = (type) => z.object({
14143
14297
  __typename: z.literal(type),
14144
14298
  login: z.string()
@@ -14172,6 +14326,7 @@ const prWire = z.object({
14172
14326
  headRefOid: z.string(),
14173
14327
  statusCheckRollup: z.object({ contexts: nodes(contextWire) }).nullish(),
14174
14328
  reviews: nodes(reviewWire),
14329
+ comments: nodes(commentWire),
14175
14330
  reviewThreads: nodes(z.object({ isResolved: z.boolean() })),
14176
14331
  reviewRequests: nodes(z.object({
14177
14332
  requestedReviewer: reviewerWire,
@@ -14287,6 +14442,35 @@ function latestReviews(nodes) {
14287
14442
  }
14288
14443
  return [...latest.values()].sort((a, b) => a.reviewer.localeCompare(b.reviewer));
14289
14444
  }
14445
+ function feedbackAuthor(wire) {
14446
+ return wire === null ? null : {
14447
+ login: wire.login,
14448
+ type: wire.__typename === "Bot" ? "bot" : "user"
14449
+ };
14450
+ }
14451
+ function feedbackOf(reviews, comments) {
14452
+ const entries = /* @__PURE__ */ new Map();
14453
+ const add = (entry) => {
14454
+ entries.set(`${entry.kind}:${entry.id}`, entry);
14455
+ };
14456
+ for (const node of comments) add({
14457
+ kind: "comment",
14458
+ id: node.id,
14459
+ author: feedbackAuthor(node.author),
14460
+ postedAt: node.createdAt
14461
+ });
14462
+ for (const node of reviews) {
14463
+ if (node.submittedAt == null) continue;
14464
+ add({
14465
+ kind: "review",
14466
+ id: node.id,
14467
+ author: feedbackAuthor(node.author),
14468
+ postedAt: node.submittedAt
14469
+ });
14470
+ }
14471
+ const tie = (entry) => `${entry.id}\u0000${entry.kind}`;
14472
+ return [...entries.values()].sort((a, b) => Date.parse(a.postedAt) - Date.parse(b.postedAt) || (tie(a) < tie(b) ? -1 : tie(a) > tie(b) ? 1 : 0));
14473
+ }
14290
14474
  function ticketKeys(title, branch, prefixes) {
14291
14475
  return scanKeys(`${title} ${branch}`, prefixes);
14292
14476
  }
@@ -14366,7 +14550,8 @@ function reviewer(wire) {
14366
14550
  default: return assertNever(wire);
14367
14551
  }
14368
14552
  }
14369
- function normalizePr(repo, value, rule) {
14553
+ /** `feedbackComplete` says whether the comments in `value` reach back to the cursor or start. */
14554
+ function normalizePr(repo, value, rule, feedbackComplete) {
14370
14555
  const wire = parseWire(prWire, value, "Malformed GitHub PR response");
14371
14556
  const checks = latestChecks(wire.statusCheckRollup?.contexts.nodes ?? []);
14372
14557
  const state = wire.state === "MERGED" ? "merged" : wire.state === "CLOSED" ? "closed" : "open";
@@ -14403,7 +14588,9 @@ function normalizePr(repo, value, rule) {
14403
14588
  asCodeOwner
14404
14589
  }]),
14405
14590
  ticketKeys: prKeys(rule, title, headBranch, closingRefs(wire.closingIssuesReferences)),
14406
- updatedAt: wire.updatedAt
14591
+ updatedAt: wire.updatedAt,
14592
+ feedback: feedbackOf(wire.reviews.nodes, wire.comments.nodes),
14593
+ feedbackComplete
14407
14594
  };
14408
14595
  const parsed = prFactsSchema.safeParse(facts);
14409
14596
  if (!parsed.success) throw new AdapterError("transient", "Malformed GitHub PR facts", { cause: parsed.error });
@@ -14415,8 +14602,16 @@ const MALFORMED$2 = "Malformed GitHub response";
14415
14602
  const discoveryRootWire = z.object({ pullRequests: connectionWire(discoveryNodeWire) });
14416
14603
  const baselineRootWire = z.object({ mergedBaseline: z.object({ nodes: z.array(baselineNodeWire) }) });
14417
14604
  const pagingWire = connectionWire(z.unknown());
14605
+ const backPagingWire = z.object({
14606
+ nodes: z.array(commentWire),
14607
+ pageInfo: z.object({
14608
+ hasPreviousPage: z.boolean(),
14609
+ startCursor: z.string().nullable()
14610
+ })
14611
+ });
14418
14612
  const prPagingWire = z.looseObject({
14419
14613
  reviews: pagingWire,
14614
+ comments: backPagingWire,
14420
14615
  reviewThreads: pagingWire,
14421
14616
  reviewRequests: pagingWire,
14422
14617
  statusCheckRollup: z.object({ contexts: pagingWire }).nullish(),
@@ -14424,6 +14619,8 @@ const prPagingWire = z.looseObject({
14424
14619
  });
14425
14620
  const aliasWire = z.object({ pullRequest: prPagingWire.nullish() }).nullish();
14426
14621
  const pageRootWire = z.object({ pullRequest: prPagingWire.partial() });
14622
+ const commentsRootWire = z.object({ pullRequest: z.object({ comments: backPagingWire }) });
14623
+ const FEEDBACK_PAGES = 3;
14427
14624
  function sourceId(project, repo) {
14428
14625
  return `github:${project}:${repo.toLowerCase()}`;
14429
14626
  }
@@ -14567,6 +14764,56 @@ async function fullPr(client, first, owner, name, number, signal, budget) {
14567
14764
  pr
14568
14765
  };
14569
14766
  }
14767
+ function reachesCursor(nodes, cursor) {
14768
+ if (cursor === void 0) return false;
14769
+ const postedAt = Date.parse(cursor.postedAt);
14770
+ return nodes.some((node) => node.id === cursor.id || Date.parse(node.createdAt) < postedAt);
14771
+ }
14772
+ /**
14773
+ * Reads comments back from `first` to `cursor`, or to the start of the PR, within
14774
+ * `FEEDBACK_PAGES`. A transient failure keeps the comments read so far as incomplete; every
14775
+ * other failure, and any failure after an abort, rejects the poll.
14776
+ */
14777
+ async function readFeedback(client, first, owner, name, number, cursor, signal, budget) {
14778
+ let nodes = first.nodes;
14779
+ let page = first;
14780
+ const seen = /* @__PURE__ */ new Set();
14781
+ try {
14782
+ for (let pages = 1; page.pageInfo.hasPreviousPage && !reachesCursor(page.nodes, cursor); pages += 1) {
14783
+ const before = page.pageInfo.startCursor;
14784
+ if (!before || seen.has(before) || pages >= FEEDBACK_PAGES) return {
14785
+ nodes,
14786
+ complete: false
14787
+ };
14788
+ seen.add(before);
14789
+ const response = await client.query(pageQuery("comments"), {
14790
+ owner,
14791
+ repo: name,
14792
+ number,
14793
+ before
14794
+ }, signal);
14795
+ budget(response.budget);
14796
+ rejectUnscoped(response.errors, ["repository"]);
14797
+ if (response.errors.length > 0) return {
14798
+ nodes,
14799
+ complete: false
14800
+ };
14801
+ page = parseWire(commentsRootWire, response.data.repository, MALFORMED$2, ["data", "repository"]).pullRequest.comments;
14802
+ nodes = [...page.nodes, ...nodes];
14803
+ }
14804
+ return {
14805
+ nodes,
14806
+ complete: true
14807
+ };
14808
+ } catch (error) {
14809
+ if (signal.aborted) throw error;
14810
+ if (error instanceof AdapterError && error.kind === "transient") return {
14811
+ nodes,
14812
+ complete: false
14813
+ };
14814
+ throw error;
14815
+ }
14816
+ }
14570
14817
  function accumulator(complete, budget) {
14571
14818
  return {
14572
14819
  complete,
@@ -14613,9 +14860,10 @@ async function processPr(scope, acc, number, alias, data, scopedErrors, ref) {
14613
14860
  else acc.complete = false;
14614
14861
  return false;
14615
14862
  }
14616
- const full = await fullPr(scope.client, wire, scope.owner, scope.name, number, scope.signal, (next) => {
14863
+ const report = (next) => {
14617
14864
  acc.budget = next;
14618
- });
14865
+ };
14866
+ const full = await fullPr(scope.client, wire, scope.owner, scope.name, number, scope.signal, report);
14619
14867
  if (full.status === "denied") {
14620
14868
  acc.complete = false;
14621
14869
  if (ref) acc.entities.push({
@@ -14625,7 +14873,16 @@ async function processPr(scope, acc, number, alias, data, scopedErrors, ref) {
14625
14873
  return false;
14626
14874
  }
14627
14875
  if (full.status === "malformed") return malformed(acc, full.error, ref);
14628
- const facts = content(() => normalizePr(ref?.repo ?? scope.repo, full.pr, scope.keys));
14876
+ const cursor = scope.feedbackCursors?.find((entry) => entry.ref.number === number && entry.ref.repo.toLowerCase() === scope.repo.toLowerCase());
14877
+ const feedback = await readFeedback(scope.client, full.pr.comments, scope.owner, scope.name, number, cursor, scope.signal, report);
14878
+ const pr = {
14879
+ ...full.pr,
14880
+ comments: {
14881
+ ...full.pr.comments,
14882
+ nodes: feedback.nodes
14883
+ }
14884
+ };
14885
+ const facts = content(() => normalizePr(ref?.repo ?? scope.repo, pr, scope.keys, feedback.complete));
14629
14886
  if (facts instanceof AdapterError) return malformed(acc, facts, ref);
14630
14887
  acc.items.push({
14631
14888
  kind: "pr",
@@ -14691,7 +14948,8 @@ async function pollRepository({ id, repo, login, keys, client, now, ctx }) {
14691
14948
  owner,
14692
14949
  name,
14693
14950
  keys,
14694
- signal: ctx.signal
14951
+ signal: ctx.signal,
14952
+ ...ctx.feedbackCursors === void 0 ? {} : { feedbackCursors: ctx.feedbackCursors }
14695
14953
  };
14696
14954
  let discoveredOk = true;
14697
14955
  for (const [i, number] of numbers.entries()) {
package/dist/mcp.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { P as ERRORS, p as renderMcpError, u as OPERATIONS } from "./src-XNs3RhSm.mjs";
2
- import { i as CliError, n as requestOperation } from "./client-BHnD83EW.mjs";
3
- import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./config-CoUN_LCM.mjs";
1
+ import { P as ERRORS, p as renderMcpError, u as OPERATIONS } from "./src-B63VaSzU.mjs";
2
+ import { i as CliError, n as requestOperation } from "./client-DtDNMMO-.mjs";
3
+ import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./config-D3ltZ-MU.mjs";
4
4
  import { randomUUID } from "node:crypto";
5
5
  import { readFileSync } from "node:fs";
6
6
  import { z } from "zod";
@@ -222,10 +222,12 @@ const spurProject = z.strictObject({
222
222
  "curator"
223
223
  ]).describe("worker: sessions of this Spur project may link to this project's tasks through their PR or branch. operator: sessions act as the operator. curator: sessions answer the questions no column orchestrator takes and escalate the rest to the operator; a board project has at most one.")
224
224
  });
225
+ const DEFAULT_CYCLE_LIMIT = 10;
225
226
  const columnConfig = z.strictObject({
226
227
  id: z.enum(COLUMN_IDS, { error: (issue) => typeof issue.input === "string" ? `Unknown column ${JSON.stringify(issue.input)}: custom columns arrive with custom matchers and are not supported yet. Built-in columns: ${COLUMN_IDS.join(", ")}` : void 0 }),
227
228
  enabled: z.boolean().default(true),
228
- orchestrator: nonEmpty.default("none")
229
+ orchestrator: nonEmpty.default("none"),
230
+ cycleLimit: z.int().min(1).default(DEFAULT_CYCLE_LIMIT).describe("How many times a task may return to Dev from this column before the board stops it for the operator. Returns by the column executor, changes requested and external comments count; a conflict, red CI and a draft do not.")
229
231
  });
230
232
  /** The board rules: required columns present and enabled, built-ins in canonical order. */
231
233
  function checkBoard(items, ctx) {
@@ -291,7 +293,8 @@ const projectSchema = z.strictObject({
291
293
  columns: z.array(columnConfig).superRefine(checkBoard).default(() => COLUMN_IDS.map((id) => ({
292
294
  id,
293
295
  enabled: true,
294
- orchestrator: "none"
296
+ orchestrator: "none",
297
+ cycleLimit: DEFAULT_CYCLE_LIMIT
295
298
  })))
296
299
  }).superRefine((project, ctx) => {
297
300
  const spurNames = new Set(project.spurProjects.map((p) => p.name));
@@ -915,6 +918,8 @@ const REVIEWER_KINDS = [
915
918
  "team",
916
919
  "bot"
917
920
  ];
921
+ const FEEDBACK_KINDS = ["comment", "review"];
922
+ const AUTHOR_TYPES = ["user", "bot"];
918
923
  /** Spur session lifecycle values known today. */
919
924
  const SESSION_STATUSES = [
920
925
  "spawning",
@@ -951,6 +956,15 @@ const checkSchema = z.strictObject({
951
956
  state: z.enum(CHECK_STATES).describe("State of the latest run of this check on the head commit."),
952
957
  completedAt: at$2.nullable().describe("When the latest run finished; null while it runs.")
953
958
  });
959
+ const feedbackSchema = z.strictObject({
960
+ kind: z.enum(FEEDBACK_KINDS).describe("Whether this is a comment or a submitted review."),
961
+ id: z.string().min(1).describe("Stable id of the comment or review in the source."),
962
+ author: z.strictObject({
963
+ login: login.describe("Login of the author."),
964
+ type: z.enum(AUTHOR_TYPES).describe("Whether the author is a user or a bot.")
965
+ }).nullable().describe("Who posted it; null for a deleted account."),
966
+ postedAt: at$2.describe("When the comment was posted or the review submitted.")
967
+ });
954
968
  const prFactsSchema = z.strictObject({
955
969
  repo: repoSlugSchema.describe("Repository as owner/name."),
956
970
  number: z.int().min(1).describe("Pull request number in the repository."),
@@ -984,7 +998,9 @@ const prFactsSchema = z.strictObject({
984
998
  });
985
999
  })).describe("Pending review requests."),
986
1000
  ticketKeys: z.array(taskKeySchema).describe("Ticket keys found in the head branch name and the title."),
987
- updatedAt: at$2.describe("When the pull request last changed.")
1001
+ updatedAt: at$2.describe("When the pull request last changed."),
1002
+ feedback: z.array(feedbackSchema).optional().describe("Comments and submitted reviews on the pull request, oldest first, without their text."),
1003
+ feedbackComplete: z.boolean().optional().describe("Whether feedback holds every comment back to the last one handed over, or to the start of the pull request; missing reads as incomplete.")
988
1004
  }).describe("Facts about one pull request.");
989
1005
  /** A tracker ticket; tracker-neutral, so a Jira issue and a GitHub issue both fit. */
990
1006
  const ticketFactsSchema = z.strictObject({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spur-board",
3
- "version": "0.29.0",
3
+ "version": "0.31.0",
4
4
  "license": "MIT",
5
5
  "engines": {
6
6
  "node": "^24.12.0 || ^26.0.0"