spur-board 0.76.0 → 0.78.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 CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as err, A as prSourceId, B as prFactsSchema, C as userIdSchema, D as AdapterError, E as eventPayloadSchemas, F as REVIEW_STATES, G as JIRA_PROJECT_KEY, H as ringMarker, I as SESSION_HEALTH_STATES, J as encodeActorId, K as REF_NUMBER, L as SESSION_STATUSES, M as sourceCursorSchema, N as trackerSourceId, O as batchSchema, P as PR_STATES, Q as ERRORS, R as isExternalAuthor, S as messageRefSchema, T as GATE_REASONS, U as sessionFactsSchema, V as prRefSchema, W as ticketFactsSchema, X as parseActorId, Y as errorCodeOf, Z as parseRef$1, _t as COLUMN_IDS, a as requestHashOf, at as DEFAULT_LINK, b as inboundEventSchema, bt as TASK_HOLDS, c as tokenRequestStatusSchema, d as buildCatalogSnapshot, dt as configBindings, f as roleCanUseOperation, ft as configSchema, gt as resolveWebOrigin, h as renderHttpProblem, ht as requiredSecretKeys, i as TOKEN_REQUEST_LIMITS, j as sessionTransitionSchema, k as entityRefSchema, l as BOARD_TICK_MS, lt as RESERVED_PROJECT, m as turnHandedSchema, mt as plainHttpAllowed, n as doctorReportSchema, nt as ok, o as tokenRequestResultSchema, p as OPERATIONS, pt as defaultAddressee, q as actorIdSchema, rt as successEnvelopeSchema, s as tokenRequestSchema, st as DEFAULT_SLACK_COMMAND, t as assertNever, ut as boardWideSpurProject, v as SPACE_IDS, vt as DISPATCHER_MODES, w as EVENT_KINDS, x as interactionRefSchema, xt as VIAS, y as conversationRefSchema, yt as SLACK_BOT_SCOPES, z as parseRingMarker } from "./chunk-BEExLWBt.mjs";
1
+ import { $ as err, A as prSourceId, B as prFactsSchema, C as userIdSchema, D as AdapterError, E as eventPayloadSchemas, F as REVIEW_STATES, G as JIRA_PROJECT_KEY, H as ringMarker, I as SESSION_HEALTH_STATES, J as encodeActorId, K as REF_NUMBER, L as SESSION_STATUSES, M as sourceCursorSchema, N as trackerSourceId, O as batchSchema, P as PR_STATES, Q as ERRORS, R as isExternalAuthor, S as messageRefSchema, St as VIAS, T as GATE_REASONS, U as sessionFactsSchema, V as prRefSchema, W as ticketFactsSchema, X as parseActorId, Y as errorCodeOf, Z as parseRef$1, _t as COLUMN_IDS, a as requestHashOf, at as DEFAULT_LINK, b as inboundEventSchema, bt as SLACK_BOT_SCOPES, c as tokenRequestStatusSchema, d as buildCatalogSnapshot, dt as configBindings, f as roleCanUseOperation, ft as configSchema, gt as resolveWebOrigin, h as renderHttpProblem, ht as requiredSecretKeys, i as TOKEN_REQUEST_LIMITS, j as sessionTransitionSchema, k as entityRefSchema, l as BOARD_TICK_MS, lt as RESERVED_PROJECT, m as turnHandedSchema, mt as plainHttpAllowed, n as doctorReportSchema, nt as ok, o as tokenRequestResultSchema, p as OPERATIONS, pt as defaultAddressee, q as actorIdSchema, rt as successEnvelopeSchema, s as tokenRequestSchema, st as DEFAULT_SLACK_COMMAND, t as assertNever, ut as boardWideSpurProject, v as SPACE_IDS, vt as DISPATCHER_MODES, w as EVENT_KINDS, x as interactionRefSchema, xt as TASK_HOLDS, y as conversationRefSchema, yt as ITEM_KINDS, z as parseRingMarker } from "./chunk-7XUx0JWq.mjs";
2
2
  import { t as apiBaseUrl } from "./chunk-DAMwWWmT.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import { createHash, randomUUID } from "node:crypto";
@@ -8587,25 +8587,6 @@ async function blockSubject(trx, block) {
8587
8587
  }
8588
8588
  //#endregion
8589
8589
  //#region ../core/src/domain/fromYou.ts
8590
- /** Every operator item kind; `ITEM_POLICY` must give each one a policy. */
8591
- const ITEM_KINDS = [
8592
- "token_request",
8593
- "post_blocked",
8594
- "post_failed",
8595
- "transport_health",
8596
- "answer_undelivered",
8597
- "worker_not_reading",
8598
- "answer_author_unavailable",
8599
- "inbound_failure",
8600
- "inbound_gap",
8601
- "board_observation",
8602
- "worker_ended",
8603
- "turn",
8604
- "anomaly",
8605
- "cycle_limit",
8606
- "course_check",
8607
- "conversation_waiting"
8608
- ];
8609
8590
  const ITEM_POLICY = {
8610
8591
  token_request: {
8611
8592
  retry: "none",
@@ -8613,7 +8594,8 @@ const ITEM_POLICY = {
8613
8594
  priority: 4,
8614
8595
  buttons: "approve_deny",
8615
8596
  reconciled: false,
8616
- block: false
8597
+ block: false,
8598
+ severity: "attention"
8617
8599
  },
8618
8600
  post_blocked: {
8619
8601
  retry: "never_sent",
@@ -8621,7 +8603,8 @@ const ITEM_POLICY = {
8621
8603
  priority: 4,
8622
8604
  buttons: "item",
8623
8605
  reconciled: false,
8624
- block: false
8606
+ block: false,
8607
+ severity: "attention"
8625
8608
  },
8626
8609
  post_failed: {
8627
8610
  retry: "requeue_post",
@@ -8629,7 +8612,8 @@ const ITEM_POLICY = {
8629
8612
  priority: 1,
8630
8613
  buttons: "item",
8631
8614
  reconciled: true,
8632
- block: false
8615
+ block: false,
8616
+ severity: "failure"
8633
8617
  },
8634
8618
  transport_health: {
8635
8619
  retry: "probe_transport",
@@ -8637,7 +8621,8 @@ const ITEM_POLICY = {
8637
8621
  priority: 1,
8638
8622
  buttons: "item",
8639
8623
  reconciled: false,
8640
- block: false
8624
+ block: false,
8625
+ severity: "failure"
8641
8626
  },
8642
8627
  answer_undelivered: {
8643
8628
  retry: "restart_ring",
@@ -8645,7 +8630,8 @@ const ITEM_POLICY = {
8645
8630
  priority: 4,
8646
8631
  buttons: "item",
8647
8632
  reconciled: false,
8648
- block: false
8633
+ block: false,
8634
+ severity: "failure"
8649
8635
  },
8650
8636
  worker_not_reading: {
8651
8637
  retry: "restart_ring",
@@ -8653,7 +8639,8 @@ const ITEM_POLICY = {
8653
8639
  priority: 4,
8654
8640
  buttons: "item",
8655
8641
  reconciled: false,
8656
- block: false
8642
+ block: false,
8643
+ severity: "failure"
8657
8644
  },
8658
8645
  answer_author_unavailable: {
8659
8646
  retry: "none",
@@ -8661,7 +8648,8 @@ const ITEM_POLICY = {
8661
8648
  priority: 4,
8662
8649
  buttons: "item",
8663
8650
  reconciled: false,
8664
- block: false
8651
+ block: false,
8652
+ severity: "attention"
8665
8653
  },
8666
8654
  inbound_failure: {
8667
8655
  retry: "reapply_inbound",
@@ -8669,7 +8657,8 @@ const ITEM_POLICY = {
8669
8657
  priority: 4,
8670
8658
  buttons: "item",
8671
8659
  reconciled: false,
8672
- block: false
8660
+ block: false,
8661
+ severity: "failure"
8673
8662
  },
8674
8663
  inbound_gap: {
8675
8664
  retry: "none",
@@ -8677,7 +8666,8 @@ const ITEM_POLICY = {
8677
8666
  priority: 4,
8678
8667
  buttons: "item",
8679
8668
  reconciled: false,
8680
- block: false
8669
+ block: false,
8670
+ severity: "failure"
8681
8671
  },
8682
8672
  board_observation: {
8683
8673
  retry: "none",
@@ -8685,7 +8675,8 @@ const ITEM_POLICY = {
8685
8675
  priority: 4,
8686
8676
  buttons: "item",
8687
8677
  reconciled: true,
8688
- block: false
8678
+ block: false,
8679
+ severity: "attention"
8689
8680
  },
8690
8681
  worker_ended: {
8691
8682
  retry: "none",
@@ -8693,7 +8684,8 @@ const ITEM_POLICY = {
8693
8684
  priority: 4,
8694
8685
  buttons: "item",
8695
8686
  reconciled: true,
8696
- block: false
8687
+ block: false,
8688
+ severity: "attention"
8697
8689
  },
8698
8690
  /** A turn whose executor is the operator; `closeTurns` clears it. */
8699
8691
  turn: {
@@ -8702,7 +8694,8 @@ const ITEM_POLICY = {
8702
8694
  priority: 4,
8703
8695
  buttons: "item",
8704
8696
  reconciled: false,
8705
- block: false
8697
+ block: false,
8698
+ severity: "attention"
8706
8699
  },
8707
8700
  /** A task-scoped condition only the operator can fix; `reconcileItems` owns its block. */
8708
8701
  anomaly: {
@@ -8711,7 +8704,8 @@ const ITEM_POLICY = {
8711
8704
  priority: 4,
8712
8705
  buttons: "item",
8713
8706
  reconciled: true,
8714
- block: true
8707
+ block: true,
8708
+ severity: "attention"
8715
8709
  },
8716
8710
  /** A task that reached its column's cycle limit; the operator's close resets it. */
8717
8711
  cycle_limit: {
@@ -8720,7 +8714,8 @@ const ITEM_POLICY = {
8720
8714
  priority: 4,
8721
8715
  buttons: "item",
8722
8716
  reconciled: false,
8723
- block: true
8717
+ block: true,
8718
+ severity: "attention"
8724
8719
  },
8725
8720
  /**
8726
8721
  * A task whose returns from a column reached its course check; the answer to its block, sent to
@@ -8732,7 +8727,8 @@ const ITEM_POLICY = {
8732
8727
  priority: 4,
8733
8728
  buttons: "item",
8734
8729
  reconciled: false,
8735
- block: true
8730
+ block: true,
8731
+ severity: "attention"
8736
8732
  },
8737
8733
  /** An operator conversation whose ring waits for a live session of its Spur project. */
8738
8734
  conversation_waiting: {
@@ -8741,9 +8737,32 @@ const ITEM_POLICY = {
8741
8737
  priority: 4,
8742
8738
  buttons: "item",
8743
8739
  reconciled: true,
8744
- block: false
8740
+ block: false,
8741
+ severity: "attention"
8745
8742
  }
8746
8743
  };
8744
+ /** The `inbox.operator` severity of an item; a blind source's item is a failure. */
8745
+ function itemSeverity(kind, key) {
8746
+ return key.startsWith("source:") ? "failure" : ITEM_POLICY[kind].severity;
8747
+ }
8748
+ /** Key prefixes of the items `reconcileItems` raises about a source or a block. */
8749
+ const SOURCE_KEY = "source:";
8750
+ const OPERATOR_BLOCK_KEY = "operator-block:";
8751
+ const BLOCK_KEY = "block:";
8752
+ const CONVERSATION_KEY = "conversation:";
8753
+ /** The block an item is about: its ledger block, else the block its key names. */
8754
+ function itemBlockRef(item) {
8755
+ if (item.block_id !== null) return item.block_id;
8756
+ for (const prefix of [
8757
+ OPERATOR_BLOCK_KEY,
8758
+ BLOCK_KEY,
8759
+ CONVERSATION_KEY
8760
+ ]) {
8761
+ if (!item.item_key.startsWith(prefix)) continue;
8762
+ const id = Number(item.item_key.slice(prefix.length));
8763
+ return Number.isSafeInteger(id) && id > 0 ? id : void 0;
8764
+ }
8765
+ }
8747
8766
  /** Guards a stored kind: the column is free text and old or hand-written rows may hold others. */
8748
8767
  function isItemKind(kind) {
8749
8768
  return Object.hasOwn(ITEM_POLICY, kind);
@@ -10545,13 +10564,18 @@ async function ringStillCurrent(trx, notificationId, sessionId, config) {
10545
10564
  if (await trx.selectFrom("notification").select("id").where("id", "=", n.id).where(courseHold).executeTakeFirst() !== void 0) return "defer";
10546
10565
  return recipientBusy(session) && !await spurBlind$1(trx) ? "defer" : "send";
10547
10566
  }
10567
+ /** The comment of an inbound author ring, named in its `doorbell:comment:<id>:` key. */
10568
+ function ringCommentId(dedupeKey) {
10569
+ const id = /^doorbell:comment:(\d+):/.exec(dedupeKey)?.[1];
10570
+ return id === void 0 ? void 0 : Number(id);
10571
+ }
10548
10572
  /**
10549
10573
  * The task of a ring: through its notification, or for an inbound author ring (no notification)
10550
10574
  * through the comment in its `doorbell:comment:<id>:` key. Archive kills only unclaimed rings;
10551
10575
  * the sender drops a claimed one of an archived task before its send starts.
10552
10576
  */
10553
10577
  async function ringTask(trx, notificationId, dedupeKey) {
10554
- const commentId = /^doorbell:comment:(\d+):/.exec(dedupeKey)?.[1];
10578
+ const commentId = ringCommentId(dedupeKey);
10555
10579
  if (notificationId === void 0 && commentId === void 0) return void 0;
10556
10580
  const owner = notificationId !== void 0 ? trx.selectFrom("notification").select("task_id").where("id", "=", notificationId) : trx.selectFrom("comment").select("task_id").where("id", "=", Number(commentId));
10557
10581
  return trx.selectFrom("task").selectAll().where("id", "in", owner).executeTakeFirst();
@@ -11857,6 +11881,30 @@ function blockView(block, subject) {
11857
11881
  unblockedAt: block.unblocked_at
11858
11882
  };
11859
11883
  }
11884
+ /** A task's blocks, oldest first, each with the `via` of its closing write. */
11885
+ async function taskBlockViews(trx, task) {
11886
+ const subject = taskSubject(task);
11887
+ return (await trx.selectFrom("block").selectAll().select(answeredViaColumn).where("task_id", "=", task.id).orderBy("id").execute()).map(({ answered_via, ...block }) => ({
11888
+ ...blockView(block, subject),
11889
+ answeredVia: answeredVia(answered_via)
11890
+ }));
11891
+ }
11892
+ /**
11893
+ * The `via` of the `block_unblocked` event that closed the `block` row in scope: `closeOpenBlock`
11894
+ * journals it at the block's `unblocked_at`, so the `event_at` index finds it. Select it from a
11895
+ * query over `block` and read the value with `answeredVia`.
11896
+ */
11897
+ const answeredViaColumn = sql`(
11898
+ select event.via from event
11899
+ where event.kind = 'block_unblocked'
11900
+ and event.at = block.unblocked_at
11901
+ and json_extract(event.payload, '$.block') = 'B' || block.id
11902
+ order by event.id desc limit 1
11903
+ )`.as("answered_via");
11904
+ /** The `via` of a block's closing write; null while open or when it came another way. */
11905
+ function answeredVia(value) {
11906
+ return VIAS.find((via) => via === value) ?? null;
11907
+ }
11860
11908
  function commentView(comment, subject) {
11861
11909
  return {
11862
11910
  id: commentId(comment.id),
@@ -13597,19 +13645,63 @@ const deliveryPayloadSchema = z.object({
13597
13645
  taskId: z.unknown().optional(),
13598
13646
  notificationId: z.unknown().optional()
13599
13647
  });
13600
- /** The task a `delivery:<outbox id>` item's row belongs to; the item itself has no task. */
13601
- async function deliveryTask(trx, item) {
13602
- if (item.kind !== "post_failed") return void 0;
13603
- const row = await trx.selectFrom("outbox").select([
13648
+ /** The outbox row of a `delivery:<outbox id>` item; the item itself has no task. */
13649
+ function deliveryId(item) {
13650
+ return item.kind === "post_failed" && item.task_id === null ? Number(item.item_key.slice(9)) : void 0;
13651
+ }
13652
+ /**
13653
+ * The task each failed delivery item's outbox row belongs to: the payload's task, else for a
13654
+ * doorbell its ring's (`ringTask`). Reads at most four statements, whatever the item count.
13655
+ */
13656
+ async function deliveryOwners(trx, items) {
13657
+ const owners = /* @__PURE__ */ new Map();
13658
+ const outboxIds = items.flatMap((item) => deliveryId(item) ?? []);
13659
+ if (outboxIds.length === 0) return owners;
13660
+ const rows = await trx.selectFrom("outbox").select([
13661
+ "id",
13604
13662
  "kind",
13605
13663
  "dedupe_key",
13606
13664
  "payload"
13607
- ]).where("id", "=", Number(item.item_key.slice(9))).executeTakeFirst();
13608
- if (row === void 0) return void 0;
13609
- const payload = parseJson(deliveryPayloadSchema, row.payload);
13610
- if (typeof payload.taskId === "number") return trx.selectFrom("task").selectAll().where("id", "=", payload.taskId).executeTakeFirst();
13611
- if (row.kind !== "doorbell") return void 0;
13612
- return ringTask(trx, typeof payload.notificationId === "number" ? payload.notificationId : void 0, row.dedupe_key);
13665
+ ]).where("id", "in", outboxIds).execute();
13666
+ const refs = /* @__PURE__ */ new Map();
13667
+ for (const row of rows) {
13668
+ const payload = parseJson(deliveryPayloadSchema, row.payload);
13669
+ if (typeof payload.taskId === "number") refs.set(row.id, { task: payload.taskId });
13670
+ else if (row.kind !== "doorbell") continue;
13671
+ else if (typeof payload.notificationId === "number") refs.set(row.id, { notification: payload.notificationId });
13672
+ else {
13673
+ const comment = ringCommentId(row.dedupe_key);
13674
+ if (comment !== void 0) refs.set(row.id, { comment });
13675
+ }
13676
+ }
13677
+ const ids = (pick) => [...refs.values()].flatMap((ref) => ref[pick] ?? []);
13678
+ const [notifications, comments] = await Promise.all(["notification", "comment"].map((table) => {
13679
+ const wanted = ids(table);
13680
+ return wanted.length === 0 ? Promise.resolve([]) : trx.selectFrom(table).select(["id", "task_id"]).where("id", "in", wanted).execute();
13681
+ }));
13682
+ const taskOf = {
13683
+ notification: new Map(notifications?.map((row) => [row.id, row.task_id])),
13684
+ comment: new Map(comments?.map((row) => [row.id, row.task_id]))
13685
+ };
13686
+ const taskIds = /* @__PURE__ */ new Map();
13687
+ for (const [outboxId, ref] of refs) {
13688
+ const taskId = ref.task ?? (ref.notification === void 0 ? void 0 : taskOf.notification.get(ref.notification)) ?? (ref.comment === void 0 ? void 0 : taskOf.comment.get(ref.comment));
13689
+ if (typeof taskId === "number") taskIds.set(outboxId, taskId);
13690
+ }
13691
+ if (taskIds.size === 0) return owners;
13692
+ const tasks = await trx.selectFrom("task").selectAll().where("id", "in", [...new Set(taskIds.values())]).execute();
13693
+ const taskById = new Map(tasks.map((task) => [task.id, task]));
13694
+ for (const item of items) {
13695
+ const outboxId = deliveryId(item);
13696
+ const taskId = outboxId === void 0 ? void 0 : taskIds.get(outboxId);
13697
+ const task = taskId === void 0 ? void 0 : taskById.get(taskId);
13698
+ if (task !== void 0) owners.set(item.id, task);
13699
+ }
13700
+ return owners;
13701
+ }
13702
+ /** The task a `delivery:<outbox id>` item's row belongs to; the item itself has no task. */
13703
+ async function deliveryTask(trx, item) {
13704
+ return (await deliveryOwners(trx, [item])).get(item.id);
13613
13705
  }
13614
13706
  /** The task an item belongs to: its own, else its delivery's; undefined for a board item. */
13615
13707
  async function itemOwner(trx, item) {
@@ -13956,6 +14048,199 @@ function createLinkMutations(config, deps = {}) {
13956
14048
  };
13957
14049
  }
13958
14050
  //#endregion
14051
+ //#region ../core/src/app/operator-inbox.ts
14052
+ /** How far back `handled` reaches, and how many entries it keeps. */
14053
+ const HANDLED_WINDOW_MS = 1440 * 60 * 1e3;
14054
+ const HANDLED_MAX = 20;
14055
+ /** What a failure item asks the operator to check; a `source:` item gets its own text. */
14056
+ const CHECK_HINTS = {
14057
+ transport_health: (item) => `the ${capitalized(item.item_key.slice(10))} app tokens`,
14058
+ post_failed: () => "the chat gateway, then retry the item",
14059
+ inbound_failure: () => "the daemon log, then retry the item",
14060
+ inbound_gap: () => "the conversation for missed messages",
14061
+ answer_undelivered: () => "the asking session, then retry the item",
14062
+ worker_not_reading: () => "the worker session, then retry the item"
14063
+ };
14064
+ const PROBLEMS = {
14065
+ auth: "auth failed",
14066
+ config: "config rejected",
14067
+ stale: "unreachable"
14068
+ };
14069
+ function capitalized(text) {
14070
+ return text.charAt(0).toUpperCase() + text.slice(1);
14071
+ }
14072
+ function serviceOf(source) {
14073
+ if (source === "spur") return "Spur";
14074
+ if (source.startsWith("github:") || source.startsWith("github-issues:")) return "GitHub";
14075
+ return source.startsWith("jira:") ? "Jira" : void 0;
14076
+ }
14077
+ /**
14078
+ * The text of a source item: built from the source's state while it is open and blind; a cleared
14079
+ * or unknown one keeps its stored text, which names the failure it had.
14080
+ */
14081
+ function sourceText(item, state) {
14082
+ const source = item.item_key.slice(7);
14083
+ const stored = `${item.text}: check the ${source} source`;
14084
+ const reason = state?.blind_reason ?? null;
14085
+ const service = serviceOf(source);
14086
+ if (item.cleared_at !== null || reason === null || service === void 0) return stored;
14087
+ const problem = PROBLEMS[reason];
14088
+ const thing = reason === "auth" ? `the ${service} token` : reason === "config" ? `the ${source} settings in the board config` : reason === "stale" && source === "spur" ? "the Spur daemon" : void 0;
14089
+ if (problem === void 0 || thing === void 0) return stored;
14090
+ const message = state?.blind_message ?? null;
14091
+ return `${service} ${problem}${message === null ? "" : ` (${message})`}: check ${thing}`;
14092
+ }
14093
+ /** Newest first by `at`, ties by id as text. */
14094
+ function newestFirst(at) {
14095
+ return (left, right) => at(right).localeCompare(at(left)) || (left.id < right.id ? -1 : left.id > right.id ? 1 : 0);
14096
+ }
14097
+ function owner(row) {
14098
+ return row.task_key === null || row.task_project === null || row.task_membership === null ? null : {
14099
+ key: row.task_key,
14100
+ project: row.task_project,
14101
+ membership: row.task_membership
14102
+ };
14103
+ }
14104
+ const taskColumns = [
14105
+ "task.key as task_key",
14106
+ "task.project as task_project",
14107
+ "task.membership as task_membership"
14108
+ ];
14109
+ /**
14110
+ * The operator's inbox across every project the caller is operator of: open operator items,
14111
+ * blocks addressed to the operator and operator turns, and what of them was handled in the last
14112
+ * day. A block or turn is listed once, without the items that mirror it.
14113
+ */
14114
+ function createOperatorInbox(deps) {
14115
+ const { config, clock } = deps;
14116
+ const configured = new Set(config.projects.map((project) => project.id));
14117
+ /** A project-level block's project, or `_board` once the project has left the config. */
14118
+ const blockProject = (project) => project !== null && configured.has(project) ? project : RESERVED_PROJECT;
14119
+ return {
14120
+ id: "inbox.operator",
14121
+ resolveTargets(_trx, _input, actor) {
14122
+ return Promise.resolve(config.projects.filter((project) => isOperator(actor, config, project.id)).map((project) => projectTarget(project.id)));
14123
+ },
14124
+ async run(trx, _input, actor) {
14125
+ const since = (/* @__PURE__ */ new Date(clock.now() - HANDLED_WINDOW_MS)).toISOString();
14126
+ const boardScope = authorize([{ grant: "operator" }], actor, {
14127
+ config,
14128
+ target: { kind: "missing" }
14129
+ }).status === "allowed";
14130
+ const operatorProjects = new Set(config.projects.filter((project) => isOperator(actor, config, project.id)).map((project) => project.id));
14131
+ const visible = (entry) => entry.project === "_board" ? boardScope : operatorProjects.has(entry.project);
14132
+ const [openItems, clearedItems, openBlocks, closedBlocks, openTurns, closedTurns] = await Promise.all([
14133
+ itemRows(trx).where("operator_item.cleared_at", "is", null).execute(),
14134
+ itemRows(trx).where("operator_item.cleared_at", ">=", since).orderBy("operator_item.cleared_at").orderBy("operator_item.id").execute(),
14135
+ blockRows(trx).where("block.state", "=", "open").execute(),
14136
+ blockRows(trx).select(answeredViaColumn).where("block.state", "=", "unblocked").where("block.unblocked_at", ">=", since).execute(),
14137
+ turnRows(trx).where("turn.closed_at", "is", null).execute(),
14138
+ turnRows(trx).where("turn.closed_at", ">=", since).execute()
14139
+ ]);
14140
+ const openKeys = new Set(openItems.map((item) => item.item_key));
14141
+ const lastCleared = /* @__PURE__ */ new Map();
14142
+ for (const item of clearedItems) {
14143
+ if (openKeys.has(item.item_key)) continue;
14144
+ lastCleared.set(item.item_key, item);
14145
+ }
14146
+ const items = [...openItems, ...lastCleared.values()];
14147
+ const blockIds = [...new Set(items.flatMap((item) => itemBlockRef(item) ?? []))];
14148
+ const sourceIds = items.flatMap((item) => item.item_key.startsWith("source:") ? [item.item_key.slice(7)] : []);
14149
+ const [referenced, owners, sources] = await Promise.all([
14150
+ blockIds.length === 0 ? Promise.resolve([]) : trx.selectFrom("block").leftJoin("task", "task.id", "block.task_id").select([
14151
+ "block.id",
14152
+ "block.addressee_role",
14153
+ "block.project",
14154
+ ...taskColumns
14155
+ ]).where("block.id", "in", blockIds).execute(),
14156
+ deliveryOwners(trx, items),
14157
+ sourceIds.length === 0 ? Promise.resolve([]) : trx.selectFrom("source_state").select([
14158
+ "source",
14159
+ "blind_reason",
14160
+ "blind_message"
14161
+ ]).where("source", "in", sourceIds).execute()
14162
+ ]);
14163
+ const blockById = new Map(referenced.map((block) => [block.id, block]));
14164
+ const sourceById = new Map(sources.map((state) => [state.source, state]));
14165
+ const itemEntry = (item) => {
14166
+ const kind = item.kind;
14167
+ if (!isItemKind(kind) || kind === "turn") return void 0;
14168
+ const ref = itemBlockRef(item);
14169
+ const block = ref === void 0 ? void 0 : blockById.get(ref);
14170
+ if (block?.addressee_role === "operator" && (ITEM_POLICY[kind].block || item.item_key.startsWith("operator-block:") || item.item_key.startsWith("block:"))) return void 0;
14171
+ const task = owner(item) ?? owners.get(item.id) ?? (block === void 0 ? null : owner(block));
14172
+ if (task?.membership === "archived") return void 0;
14173
+ const hint = CHECK_HINTS[kind];
14174
+ return {
14175
+ id: `I${String(item.id)}`,
14176
+ project: task?.project ?? (block === void 0 ? "_board" : blockProject(block.project)),
14177
+ kind,
14178
+ severity: itemSeverity(kind, item.item_key),
14179
+ text: item.item_key.startsWith("source:") ? sourceText(item, sourceById.get(item.item_key.slice(7))) : hint === void 0 ? item.text : `${item.text}: check ${hint(item)}`,
14180
+ at: item.raised_at,
14181
+ task: task?.key ?? null,
14182
+ ...item.cleared_at === null ? {} : { handledAt: item.cleared_at }
14183
+ };
14184
+ };
14185
+ const blockEntry = (block, via) => {
14186
+ const task = owner(block);
14187
+ if (task?.membership === "archived") return void 0;
14188
+ return {
14189
+ id: `B${String(block.id)}`,
14190
+ project: task?.project ?? blockProject(block.project),
14191
+ kind: "block",
14192
+ severity: "attention",
14193
+ text: block.reason,
14194
+ at: block.created_at,
14195
+ task: task?.key ?? null,
14196
+ answeredVia: via,
14197
+ ...block.unblocked_at === null || block.state === "open" ? {} : { handledAt: block.unblocked_at }
14198
+ };
14199
+ };
14200
+ const turnEntry = (turn) => {
14201
+ const task = owner(turn);
14202
+ if (task === null || task.membership === "archived") return void 0;
14203
+ return {
14204
+ id: `T${String(turn.id)}`,
14205
+ project: task.project,
14206
+ kind: "turn",
14207
+ severity: "attention",
14208
+ text: `Your turn T${String(turn.id)}: ${turn.reason}`,
14209
+ at: turn.created_at,
14210
+ task: task.key,
14211
+ column: turn.column,
14212
+ ...turn.closed_at === null ? {} : { handledAt: turn.closed_at }
14213
+ };
14214
+ };
14215
+ const listed = (entries) => entries.filter((entry) => entry !== void 0 && visible(entry));
14216
+ return {
14217
+ items: listed([
14218
+ ...openItems.map(itemEntry),
14219
+ ...openBlocks.map((block) => blockEntry(block, null)),
14220
+ ...openTurns.map(turnEntry)
14221
+ ]).sort(newestFirst((entry) => entry.at)),
14222
+ handled: listed([
14223
+ ...[...lastCleared.values()].map(itemEntry),
14224
+ ...closedBlocks.map(({ answered_via, ...block }) => blockEntry(block, answeredVia(answered_via))),
14225
+ ...closedTurns.map(turnEntry)
14226
+ ]).sort(newestFirst((entry) => entry.handledAt ?? entry.at)).slice(0, HANDLED_MAX).map(({ handledAt, ...entry }) => ({
14227
+ ...entry,
14228
+ handledAt: handledAt ?? entry.at
14229
+ }))
14230
+ };
14231
+ }
14232
+ };
14233
+ }
14234
+ function itemRows(trx) {
14235
+ return trx.selectFrom("operator_item").leftJoin("task", "task.id", "operator_item.task_id").selectAll("operator_item").select(taskColumns);
14236
+ }
14237
+ function blockRows(trx) {
14238
+ return trx.selectFrom("block").leftJoin("task", "task.id", "block.task_id").selectAll("block").select(taskColumns).where("block.addressee_role", "=", "operator");
14239
+ }
14240
+ function turnRows(trx) {
14241
+ return trx.selectFrom("turn").innerJoin("task", "task.id", "turn.task_id").selectAll("turn").select(taskColumns).where("turn.role", "=", "operator");
14242
+ }
14243
+ //#endregion
13959
14244
  //#region ../core/src/app/status-views.ts
13960
14245
  /** Factual PR rollup; the caller owns snapshot freshness and all reads. */
13961
14246
  function summarizePr(fact, factAt, unconfirmed) {
@@ -15072,7 +15357,7 @@ async function conversationWaiting(trx, config, block, subject) {
15072
15357
  if (await trx.selectFrom("notification").select("id").where("block_id", "=", block.id).where("kind", "in", ["block", "answer"]).where("acked_at", "is", null).where("exhausted_at", "is", null).executeTakeFirst() === void 0 || await bestProjectSession(trx, spur) !== void 0) return void 0;
15073
15358
  const shortName = config.projects.flatMap((project) => project.spurProjects).find((entry) => entry.name === spur)?.shortName ?? spur;
15074
15359
  return {
15075
- key: `conversation:${String(block.id)}`,
15360
+ key: `${CONVERSATION_KEY}${String(block.id)}`,
15076
15361
  kind: "conversation_waiting",
15077
15362
  taskId: subject.task?.id ?? null,
15078
15363
  summary: `${subject.key}: message to @${shortName} waits for a live ${spur} session`,
@@ -15090,7 +15375,7 @@ async function reconcileItems(trx, config, now, spurComplete, warnSkipped, spurC
15090
15375
  if (source.blind_reason === null) continue;
15091
15376
  if (source.blind_reason === "stale" && source.source !== "spur") continue;
15092
15377
  candidates.push({
15093
- key: `source:${source.source}`,
15378
+ key: `${SOURCE_KEY}${source.source}`,
15094
15379
  kind: "board_observation",
15095
15380
  taskId: null,
15096
15381
  summary: `${source.source}: ${source.blind_message ?? source.blind_reason}`,
@@ -15155,7 +15440,7 @@ async function reconcileItems(trx, config, now, spurComplete, warnSkipped, spurC
15155
15440
  if (subject === void 0 || ledgerIds.has(block.id)) continue;
15156
15441
  const taskId = subject.task?.id ?? null;
15157
15442
  if (block.addressee_role === "operator" && block.author !== "operator" && !blockedIds.has(block.id)) candidates.push({
15158
- key: `operator-block:${String(block.id)}`,
15443
+ key: `${OPERATOR_BLOCK_KEY}${String(block.id)}`,
15159
15444
  kind: "board_observation",
15160
15445
  taskId,
15161
15446
  summary: `${subject.key}: ${block.reason}`,
@@ -15168,7 +15453,7 @@ async function reconcileItems(trx, config, now, spurComplete, warnSkipped, spurC
15168
15453
  if (waiting !== void 0) candidates.push(waiting);
15169
15454
  }
15170
15455
  if (now - Date.parse(block.created_at) >= config.thresholds.blockOpenMs) candidates.push({
15171
- key: `block:${String(block.id)}`,
15456
+ key: `${BLOCK_KEY}${String(block.id)}`,
15172
15457
  kind: "board_observation",
15173
15458
  taskId,
15174
15459
  summary: `${subject.key}: block has been open for more than a day`,
@@ -16675,7 +16960,7 @@ function createTaskQueries(deps) {
16675
16960
  async run(trx, input) {
16676
16961
  const task = await taskByKey(trx, taskKey(input.task));
16677
16962
  const [blocks, comments, links] = await Promise.all([
16678
- trx.selectFrom("block").selectAll().where("task_id", "=", task.id).orderBy("id").execute(),
16963
+ taskBlockViews(trx, task),
16679
16964
  trx.selectFrom("comment").selectAll().where("task_id", "=", task.id).orderBy("id").execute(),
16680
16965
  trx.selectFrom("link").leftJoin("pr_snapshot", (join) => join.on(sql`lower(pr_snapshot.repo) = lower(link.repo)`).onRef("pr_snapshot.number", "=", "link.number")).selectAll("link").select("pr_snapshot.state").where("link.task_id", "=", task.id).where("link.banned", "=", 0).orderBy("link.id").execute()
16681
16966
  ]);
@@ -16691,7 +16976,7 @@ function createTaskQueries(deps) {
16691
16976
  ...observed === void 0 ? {} : { state: observed }
16692
16977
  };
16693
16978
  }),
16694
- blocks: blocks.map((block) => blockView(block, subject)),
16979
+ blocks,
16695
16980
  comments: comments.map((comment) => commentView(comment, subject)),
16696
16981
  ...input.why === true ? { why: await why(trx, task) } : {}
16697
16982
  };
@@ -17272,6 +17557,10 @@ function createOperationRegistry(deps) {
17272
17557
  "task.get": taskQueries.get,
17273
17558
  "task.history": taskQueries.history,
17274
17559
  "inbox.get": taskQueries.inbox,
17560
+ "inbox.operator": createOperatorInbox({
17561
+ config,
17562
+ clock
17563
+ }),
17275
17564
  "token.list": tokenListQuery(clock),
17276
17565
  "token.revoke": tokenRevokeMutation,
17277
17566
  "task.add": membership.add,
package/dist/mcp.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { Q as ERRORS, _ as renderMcpError, p as OPERATIONS } from "./chunk-BEExLWBt.mjs";
2
- import { o as CliError, r as requestOperation } from "./chunk-BSs9OrJD.mjs";
3
- import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./chunk-CFvX6Mf9.mjs";
1
+ import { Q as ERRORS, _ as renderMcpError, p as OPERATIONS } from "./chunk-7XUx0JWq.mjs";
2
+ import { o as CliError, r as requestOperation } from "./chunk-C06XgrL3.mjs";
3
+ import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./chunk-Ck64u-eo.mjs";
4
4
  import { randomUUID } from "node:crypto";
5
5
  import { readFileSync } from "node:fs";
6
6
  import { z } from "zod";