spur-board 0.104.2 → 0.105.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 parseRef$1, A as defaultBranchFactSchema, B as isExternalAuthor, C as messageRefSchema, Ct as TASK_HOLDS, D as eventPayloadSchemas, E as GATE_REASONS, F as trackerSourceId, G as sessionFactsSchema, H as prFactsSchema, I as PR_STATES, J as REF_NUMBER, K as ticketFactsSchema, L as REVIEW_STATES, M as prSourceId, N as sessionTransitionSchema, O as AdapterError, P as sourceCursorSchema, Q as parseActorId, R as SESSION_HEALTH_STATES, S as interactionRefSchema, St as SLACK_BOT_SCOPES, T as EVENT_KINDS, U as prRefSchema, V as parseRingMarker, W as ringMarker, X as encodeActorId, Y as actorIdSchema, Z as errorCodeOf, _t as requiredSecretKeys, a as requestHashOf, at as successEnvelopeSchema, b as conversationRefSchema, bt as DISPATCHER_MODES, c as tokenRequestStatusSchema, d as buildCatalogSnapshot, dt as RESERVED_PROJECT, et as ERRORS, f as roleCanUseOperation, ft as boardWideSpurProject, g as renderHttpProblem, gt as plainHttpAllowed, h as turnHandedSchema, ht as defaultAddressee, i as TOKEN_REQUEST_LIMITS, it as ok, j as entityRefSchema, k as batchSchema, l as BOARD_TICK_MS, lt as DEFAULT_SLACK_COMMAND, m as defaultBranchViewSchema, mt as configSchema, n as doctorReportSchema, o as tokenRequestResultSchema, p as OPERATIONS, pt as configBindings, q as JIRA_PROJECT_KEY, s as tokenRequestSchema, st as DEFAULT_LINK, t as assertNever, tt as err, vt as resolveWebOrigin, w as userIdSchema, wt as VIAS, x as inboundEventSchema, xt as ITEM_KINDS, y as SPACE_IDS, yt as COLUMN_IDS, z as SESSION_STATUSES } from "./chunk-DGsDK61k.mjs";
1
+ import { $ as parseRef$1, A as defaultBranchFactSchema, B as isExternalAuthor, C as messageRefSchema, Ct as TASK_HOLDS, D as eventPayloadSchemas, E as GATE_REASONS, F as trackerSourceId, G as sessionFactsSchema, H as prFactsSchema, I as PR_STATES, J as REF_NUMBER, K as ticketFactsSchema, L as REVIEW_STATES, M as prSourceId, N as sessionTransitionSchema, O as AdapterError, P as sourceCursorSchema, Q as parseActorId, R as SESSION_HEALTH_STATES, S as interactionRefSchema, St as SLACK_BOT_SCOPES, T as EVENT_KINDS, U as prRefSchema, V as parseRingMarker, W as ringMarker, X as encodeActorId, Y as actorIdSchema, Z as errorCodeOf, _t as requiredSecretKeys, a as requestHashOf, at as successEnvelopeSchema, b as conversationRefSchema, bt as DISPATCHER_MODES, c as tokenRequestStatusSchema, d as buildCatalogSnapshot, dt as RESERVED_PROJECT, et as ERRORS, f as roleCanUseOperation, ft as boardWideSpurProject, g as renderHttpProblem, gt as plainHttpAllowed, h as turnHandedSchema, ht as defaultAddressee, i as TOKEN_REQUEST_LIMITS, it as ok, j as entityRefSchema, k as batchSchema, l as BOARD_TICK_MS, lt as DEFAULT_SLACK_COMMAND, m as defaultBranchViewSchema, mt as configSchema, n as doctorReportSchema, o as tokenRequestResultSchema, p as OPERATIONS, pt as configBindings, q as JIRA_PROJECT_KEY, s as tokenRequestSchema, st as DEFAULT_LINK, t as assertNever, tt as err, vt as resolveWebOrigin, w as userIdSchema, wt as VIAS, x as inboundEventSchema, xt as ITEM_KINDS, y as SPACE_IDS, yt as COLUMN_IDS, z as SESSION_STATUSES } from "./chunk-IDeN7dOW.mjs";
2
2
  import { t as apiBaseUrl } from "./chunk-Bzb7aI8R.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import { createHash, randomUUID } from "node:crypto";
@@ -13634,7 +13634,7 @@ const deliveryPayloadSchema = z.object({
13634
13634
  notificationId: z.unknown().optional()
13635
13635
  });
13636
13636
  /** The outbox row of a `delivery:<outbox id>` item; the item itself has no task. */
13637
- function deliveryId(item) {
13637
+ function deliveryId$1(item) {
13638
13638
  return item.kind === "post_failed" && item.task_id === null ? Number(item.item_key.slice(9)) : void 0;
13639
13639
  }
13640
13640
  /**
@@ -13643,7 +13643,7 @@ function deliveryId(item) {
13643
13643
  */
13644
13644
  async function deliveryOwners(trx, items) {
13645
13645
  const owners = /* @__PURE__ */ new Map();
13646
- const outboxIds = items.flatMap((item) => deliveryId(item) ?? []);
13646
+ const outboxIds = items.flatMap((item) => deliveryId$1(item) ?? []);
13647
13647
  if (outboxIds.length === 0) return owners;
13648
13648
  const rows = await trx.selectFrom("outbox").select([
13649
13649
  "id",
@@ -13680,7 +13680,7 @@ async function deliveryOwners(trx, items) {
13680
13680
  const tasks = await trx.selectFrom("task").selectAll().where("id", "in", [...new Set(taskIds.values())]).execute();
13681
13681
  const taskById = new Map(tasks.map((task) => [task.id, task]));
13682
13682
  for (const item of items) {
13683
- const outboxId = deliveryId(item);
13683
+ const outboxId = deliveryId$1(item);
13684
13684
  const taskId = outboxId === void 0 ? void 0 : taskIds.get(outboxId);
13685
13685
  const task = taskId === void 0 ? void 0 : taskById.get(taskId);
13686
13686
  if (task !== void 0) owners.set(item.id, task);
@@ -14098,6 +14098,52 @@ function serviceOf(source) {
14098
14098
  if (source.startsWith("github:") || source.startsWith("github-issues:")) return "GitHub";
14099
14099
  return source.startsWith("jira:") ? "Jira" : void 0;
14100
14100
  }
14101
+ const externalUrlSchema = z.url({ protocol: /^https?$/ });
14102
+ /** Only structured destinations count; the task-less feed placeholder is never navigation. */
14103
+ function meaningfulUrl(value) {
14104
+ if (!externalUrlSchema.safeParse(value).success) return void 0;
14105
+ const url = new URL(value);
14106
+ if (url.origin === "https://github.com" && url.pathname === "/") return void 0;
14107
+ return url.href;
14108
+ }
14109
+ function deliveredUrl(value) {
14110
+ if (value === null) return void 0;
14111
+ let decoded;
14112
+ try {
14113
+ decoded = JSON.parse(value);
14114
+ } catch (error) {
14115
+ if (!(error instanceof SyntaxError)) throw error;
14116
+ return;
14117
+ }
14118
+ const ref = deliveredRefSchema.safeParse(decoded);
14119
+ return ref.success ? meaningfulUrl(ref.data.permalink) : void 0;
14120
+ }
14121
+ function deliveryId(item) {
14122
+ if (item.kind !== "post_failed" || !/^delivery:[1-9]\d*$/.test(item.item_key)) return void 0;
14123
+ const id = Number(item.item_key.slice(9));
14124
+ return Number.isSafeInteger(id) ? id : void 0;
14125
+ }
14126
+ /** One batched join, including only the immediate parent of each failed delivery. */
14127
+ async function deliveryUrls(trx, items) {
14128
+ const ids = items.flatMap((item) => deliveryId(item) ?? []);
14129
+ if (ids.length === 0) return /* @__PURE__ */ new Map();
14130
+ const rows = await trx.selectFrom("outbox").leftJoin("outbox as parent", "parent.id", "outbox.parent_outbox_id").select([
14131
+ "outbox.id",
14132
+ "outbox.external_ref",
14133
+ "parent.external_ref as parent_ref"
14134
+ ]).where("outbox.id", "in", ids).execute();
14135
+ return new Map(rows.map((row) => [row.id, deliveredUrl(row.external_ref) ?? deliveredUrl(row.parent_ref)]));
14136
+ }
14137
+ function itemUrl(item, deliveries) {
14138
+ if (item.item_key.startsWith("source:")) {
14139
+ const service = serviceOf(item.item_key.slice(7));
14140
+ if (service === "GitHub") return "https://docs.github.com/en/rest/using-the-rest-api/troubleshooting-the-rest-api";
14141
+ if (service === "Jira") return "https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro";
14142
+ return;
14143
+ }
14144
+ const id = deliveryId(item);
14145
+ return id === void 0 ? meaningfulUrl(item.url) : deliveries.get(id);
14146
+ }
14101
14147
  /**
14102
14148
  * The text of a source item: built from the source's state while it is open and blind; a cleared
14103
14149
  * or unknown one keeps its stored text, which names the failure it had.
@@ -14176,7 +14222,7 @@ function createOperatorInbox(deps) {
14176
14222
  const items = [...openItems, ...lastCleared.values()];
14177
14223
  const blockIds = [...new Set(items.flatMap((item) => itemBlockRef(item) ?? []))];
14178
14224
  const sourceIds = items.flatMap((item) => item.item_key.startsWith("source:") ? [item.item_key.slice(7)] : []);
14179
- const [referenced, owners, sources] = await Promise.all([
14225
+ const [referenced, owners, sources, deliveries] = await Promise.all([
14180
14226
  blockIds.length === 0 ? Promise.resolve([]) : trx.selectFrom("block").leftJoin("task", "task.id", "block.task_id").select([
14181
14227
  "block.id",
14182
14228
  "block.addressee_role",
@@ -14189,7 +14235,8 @@ function createOperatorInbox(deps) {
14189
14235
  "source",
14190
14236
  "blind_reason",
14191
14237
  "blind_message"
14192
- ]).where("source", "in", sourceIds).execute()
14238
+ ]).where("source", "in", sourceIds).execute(),
14239
+ deliveryUrls(trx, items)
14193
14240
  ]);
14194
14241
  const blockById = new Map(referenced.map((block) => [block.id, block]));
14195
14242
  const sourceById = new Map(sources.map((state) => [state.source, state]));
@@ -14208,6 +14255,7 @@ function createOperatorInbox(deps) {
14208
14255
  task
14209
14256
  })
14210
14257
  };
14258
+ const url = itemUrl(item, deliveries);
14211
14259
  return {
14212
14260
  id: `I${String(item.id)}`,
14213
14261
  project: task?.project ?? (block === void 0 ? "_board" : blockProject(block.project)),
@@ -14217,6 +14265,7 @@ function createOperatorInbox(deps) {
14217
14265
  action,
14218
14266
  at: item.raised_at,
14219
14267
  task: task?.key ?? null,
14268
+ ...url === void 0 ? {} : { url },
14220
14269
  ...item.cleared_at === null ? {} : { handledAt: item.cleared_at }
14221
14270
  };
14222
14271
  };
@@ -15262,7 +15311,7 @@ const uncounted = (reason) => reason === "ticket_reopened" || reason === "mode_c
15262
15311
  const indexOf$1 = (column) => COLUMN_IDS.indexOf(column);
15263
15312
  const isColumn = (text) => COLUMN_IDS.includes(text);
15264
15313
  /** A left move as a return with its causes, or null when it is no counted return. */
15265
- function counted$1(move, blocked) {
15314
+ function counted$2(move, blocked) {
15266
15315
  if (indexOf$1(move.to) >= indexOf$1(move.from) || uncounted(move.reason)) return null;
15267
15316
  const [first, ...rest] = returnCauses(move.gate ?? [], blocked);
15268
15317
  return first === void 0 ? null : {
@@ -15304,7 +15353,7 @@ async function returnCounts(trx, taskId, column) {
15304
15353
  continue;
15305
15354
  }
15306
15355
  const moved = eventPayloadSchemas.task_moved.safeParse(JSON.parse(row.payload));
15307
- const event = moved.success ? counted$1(moved.data, moved.data.block !== void 0) : null;
15356
+ const event = moved.success ? counted$2(moved.data, moved.data.block !== void 0) : null;
15308
15357
  if (event === null) continue;
15309
15358
  events.cycle.push(event);
15310
15359
  events.course.push(event);
@@ -15421,13 +15470,13 @@ async function openFindings(trx, taskId) {
15421
15470
  */
15422
15471
  async function shadowCourseCheck(trx, taskId, move, project) {
15423
15472
  const every = project.columns.find((column) => column.id === move.from)?.courseCheck ?? 0;
15424
- const current = counted$1(move, false);
15473
+ const current = counted$2(move, false);
15425
15474
  if (every <= 0 || current === null) return false;
15426
15475
  const rows = await trx.selectFrom("event").select("payload").where("task_id", "=", taskId).where("kind", "=", "task_shadow_moved").orderBy("id").execute();
15427
15476
  const past = [];
15428
15477
  for (const row of rows) {
15429
15478
  const moved = eventPayloadSchemas.task_shadow_moved.safeParse(JSON.parse(row.payload));
15430
- const event = moved.success ? counted$1(moved.data, false) : null;
15479
+ const event = moved.success ? counted$2(moved.data, false) : null;
15431
15480
  if (event !== null) past.push(event);
15432
15481
  }
15433
15482
  const before = countCycles(past, move.from, every).count;
@@ -20839,7 +20888,7 @@ const CLOSING_FIELDS = "nodes { number repository { nameWithOwner } } pageInfo {
20839
20888
  const prFields = (number, closing = false) => `id number url title updatedAt mergedAt closedAt state isDraft mergeable mergeStateStatus
20840
20889
  author { login } headRefName headRefOid
20841
20890
  statusCheckRollup { contexts(first: 100) { nodes {
20842
- ... on CheckRun { __typename name status conclusion startedAt completedAt checkSuite { createdAt } isRequired(pullRequestNumber: ${String(number)}) }
20891
+ ... on CheckRun { __typename name status conclusion startedAt completedAt checkSuite { createdAt workflowRun { workflow { id } } app { id } } isRequired(pullRequestNumber: ${String(number)}) }
20843
20892
  ... on StatusContext { __typename context state createdAt isRequired(pullRequestNumber: ${String(number)}) }
20844
20893
  } pageInfo { hasNextPage endCursor } } }
20845
20894
  reviews(first: 100) { nodes { ${REVIEW_FIELDS} } pageInfo { hasNextPage endCursor } }
@@ -20868,7 +20917,7 @@ function detailQuery(numbers, closing = false) {
20868
20917
  function pageQuery(connection, bootstrap = false) {
20869
20918
  if (connection === "comments") return `query PrPage($owner: String!, $repo: String!, $number: Int!, $before: String!) { rateLimit { cost limit remaining resetAt } repository(owner: $owner, name: $repo) { pullRequest(number: $number) { comments(last: 100, before: $before) { ${COMMENT_FIELDS} } } } }`;
20870
20919
  if (connection === "pullRequests") return `query DiscoveryPage($owner: String!, $repo: String!, $after: String!) { rateLimit { cost limit remaining resetAt } repository(owner: $owner, name: $repo) { pullRequests(first: 100, after: $after, states: [${discoveryStates(bootstrap)}], orderBy: {field: UPDATED_AT, direction: DESC}) { ${DISCOVERY_FIELDS} } } }`;
20871
- return `query PrPage($owner: String!, $repo: String!, $number: Int!, $after: String!) { rateLimit { cost limit 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" ? THREAD_FIELDS : REVIEWER_FIELDS} } pageInfo { hasNextPage endCursor } }`} } } }`;
20920
+ return `query PrPage($owner: String!, $repo: String!, $number: Int!, $after: String!) { rateLimit { cost limit 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 workflowRun { workflow { id } } app { id } } 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" ? THREAD_FIELDS : REVIEWER_FIELDS} } pageInfo { hasNextPage endCursor } }`} } } }`;
20872
20921
  }
20873
20922
  /**
20874
20923
  * The failure that GraphQL `errors` mean for the whole request, in rule order: a rate limit is
@@ -20957,6 +21006,217 @@ var GithubClient = class {
20957
21006
  };
20958
21007
  }
20959
21008
  };
21009
+ // ../adapters/src/github/checks.ts
21010
+ const checkRunWire = z.object({
21011
+ __typename: z.literal("CheckRun"),
21012
+ name: z.string(),
21013
+ status: z.string(),
21014
+ conclusion: z.string().nullable(),
21015
+ startedAt: z.string().nullish(),
21016
+ completedAt: z.string().nullable(),
21017
+ checkSuite: z.object({
21018
+ createdAt: z.string(),
21019
+ workflowRun: z.object({ workflow: z.object({ id: z.string().min(1) }) }).nullish(),
21020
+ app: z.object({ id: z.string().min(1) }).nullish()
21021
+ }).nullish(),
21022
+ isRequired: z.boolean().nullish()
21023
+ }).refine((run) => run.status !== "COMPLETED" || run.conclusion !== null, { path: ["conclusion"] });
21024
+ const statusContextWire = z.object({
21025
+ __typename: z.literal("StatusContext"),
21026
+ context: z.string(),
21027
+ state: z.string(),
21028
+ createdAt: z.string(),
21029
+ isRequired: z.boolean().nullish()
21030
+ });
21031
+ const contextWire = z.discriminatedUnion("__typename", [checkRunWire, statusContextWire]);
21032
+ /** The contracts check state of a check run or commit status. */
21033
+ function checkState(node) {
21034
+ if (node.__typename === "StatusContext") {
21035
+ const state = node.state.toLowerCase();
21036
+ return state === "success" ? "success" : state === "pending" ? "pending" : state === "expected" ? "expected" : "failure";
21037
+ }
21038
+ if (node.status !== "COMPLETED") return "pending";
21039
+ const value = node.conclusion?.toLowerCase();
21040
+ return [
21041
+ "success",
21042
+ "neutral",
21043
+ "skipped",
21044
+ "failure",
21045
+ "cancelled",
21046
+ "timed_out",
21047
+ "action_required",
21048
+ "stale"
21049
+ ].find((state) => state === value) ?? "error";
21050
+ }
21051
+ /** When a context ran, to keep the latest of each check; an empty string sorts first. */
21052
+ function contextAt(node) {
21053
+ return node.__typename === "StatusContext" ? node.createdAt : node.startedAt ?? node.checkSuite?.createdAt ?? node.completedAt ?? "";
21054
+ }
21055
+ /** The display name of a check run or commit status. */
21056
+ function contextName(node) {
21057
+ return node.__typename === "StatusContext" ? node.context : node.name;
21058
+ }
21059
+ /**
21060
+ * Only reruns of one check replace each other: a commit status by its context, an Actions check
21061
+ * run by its workflow and job name, another check run by its app and name. A check run with
21062
+ * neither, as in the older recordings, falls back to its name.
21063
+ */
21064
+ function checkKey(node) {
21065
+ if (node.__typename === "StatusContext") return `status:${node.context}`;
21066
+ const workflow = node.checkSuite?.workflowRun?.workflow.id;
21067
+ if (workflow !== void 0) return `check:${workflow}:${node.name}`;
21068
+ const app = node.checkSuite?.app?.id;
21069
+ return app === void 0 ? `name:${node.name}` : `app:${app}:${node.name}`;
21070
+ }
21071
+ /**
21072
+ * The latest node of each check (see `checkKey`), sorted by display name, then key. Of two runs
21073
+ * with one time the later node wins.
21074
+ */
21075
+ function latestContexts(nodes) {
21076
+ const latest = /* @__PURE__ */ new Map();
21077
+ for (const node of nodes) {
21078
+ const key = checkKey(node);
21079
+ const old = latest.get(key);
21080
+ if (old !== void 0 && contextAt(old) > contextAt(node)) continue;
21081
+ latest.set(key, node);
21082
+ }
21083
+ return [...latest.entries()].sort(([a, x], [b, y]) => contextName(x).localeCompare(contextName(y)) || a.localeCompare(b)).map(([, node]) => node);
21084
+ }
21085
+ // ../adapters/src/github/discovery.ts
21086
+ const timestamp$1 = z.string().min(1).refine((value) => !Number.isNaN(Date.parse(value)));
21087
+ const discoveryNodeWire = z.object({
21088
+ number: z.int().positive(),
21089
+ state: z.string().optional(),
21090
+ updatedAt: timestamp$1,
21091
+ author: z.object({ login: z.string() }).nullable()
21092
+ });
21093
+ const baselineNodeWire = z.object({ updatedAt: timestamp$1 });
21094
+ function latestUpdatedAt(nodes, previous) {
21095
+ let high = previous;
21096
+ for (const node of nodes) {
21097
+ const updated = sourceCursorSchema.parse(node.updatedAt);
21098
+ if (high === void 0 || Date.parse(updated) > Date.parse(high)) high = updated;
21099
+ }
21100
+ return high;
21101
+ }
21102
+ /** The high-water cursor is an ISO timestamp. Equal timestamps are revisited. */
21103
+ function discover(nodes, previous, login) {
21104
+ let high = previous;
21105
+ const numbers = /* @__PURE__ */ new Set();
21106
+ const states = /* @__PURE__ */ new Map();
21107
+ for (const node of nodes) {
21108
+ const updated = sourceCursorSchema.parse(node.updatedAt);
21109
+ const updatedMs = Date.parse(updated);
21110
+ if (high === void 0 || updatedMs > Date.parse(high)) high = updated;
21111
+ if (previous !== void 0 && updatedMs < Date.parse(previous)) continue;
21112
+ states.set(node.number, node.state);
21113
+ if (node.author?.login.toLowerCase() !== login.toLowerCase()) continue;
21114
+ numbers.add(node.number);
21115
+ }
21116
+ return {
21117
+ numbers: [...numbers],
21118
+ states,
21119
+ ...high === void 0 ? {} : { cursor: high }
21120
+ };
21121
+ }
21122
+ /** Pages are sorted newest first; older nodes end the scan, while ties must be revisited. */
21123
+ function pastCursor(nodes, previous) {
21124
+ const oldest = nodes.at(-1);
21125
+ if (previous === void 0 || oldest === void 0) return false;
21126
+ return Date.parse(oldest.updatedAt) < Date.parse(previous);
21127
+ }
21128
+ function nextPage(connection) {
21129
+ const { hasNextPage, endCursor } = connection.pageInfo;
21130
+ if (!hasNextPage) return void 0;
21131
+ if (!endCursor) throw new Error("Malformed GitHub pagination");
21132
+ return endCursor;
21133
+ }
21134
+ const branchCheckRunWire = z.object({
21135
+ __typename: z.literal("CheckRun"),
21136
+ name: z.string(),
21137
+ status: z.string(),
21138
+ conclusion: z.string().nullable(),
21139
+ startedAt: z.string().nullish(),
21140
+ completedAt: z.string().nullable(),
21141
+ detailsUrl: z.string().nullish(),
21142
+ checkSuite: z.object({
21143
+ createdAt: z.string(),
21144
+ workflowRun: z.object({
21145
+ event: z.string(),
21146
+ workflow: z.object({ id: z.string().min(1) })
21147
+ }).nullish()
21148
+ }).nullish()
21149
+ });
21150
+ const branchStatusWire = z.object({
21151
+ __typename: z.literal("StatusContext"),
21152
+ context: z.string(),
21153
+ state: z.string(),
21154
+ createdAt: z.string(),
21155
+ targetUrl: z.string().nullish()
21156
+ });
21157
+ const branchContextWire = z.discriminatedUnion("__typename", [branchCheckRunWire, branchStatusWire]);
21158
+ const defaultBranchWire = z.object({ defaultBranchRef: z.object({
21159
+ name: z.string(),
21160
+ target: z.object({
21161
+ __typename: z.literal("Commit"),
21162
+ oid: z.string(),
21163
+ statusCheckRollup: z.object({ contexts: z.object({
21164
+ nodes: z.array(branchContextWire),
21165
+ pageInfo: z.object({ hasNextPage: z.boolean() })
21166
+ }) })
21167
+ })
21168
+ }) });
21169
+ function counted$1(node) {
21170
+ return node.__typename === "StatusContext" || node.checkSuite?.workflowRun?.event === "push";
21171
+ }
21172
+ const PASSED = /* @__PURE__ */ new Set([
21173
+ "success",
21174
+ "neutral",
21175
+ "skipped"
21176
+ ]);
21177
+ const RUNNING = /* @__PURE__ */ new Set(["pending", "expected"]);
21178
+ /**
21179
+ * The colour of the default-branch head in a discovery response's `repository`, or undefined
21180
+ * when it is unknown: an unexpected shape, a running head, no counted check, or a truncated page
21181
+ * with no failure in it. Only check runs of push-triggered workflows and commit statuses count;
21182
+ * the latest run of each check decides (see `latestContexts`). A run URL that is not http(s)
21183
+ * becomes null.
21184
+ */
21185
+ function defaultBranchFact(repository) {
21186
+ const parsed = defaultBranchWire.safeParse(repository);
21187
+ if (!parsed.success) return void 0;
21188
+ const { name: branch, target } = parsed.data.defaultBranchRef;
21189
+ const { nodes, pageInfo } = target.statusCheckRollup.contexts;
21190
+ const kept = latestContexts(nodes.filter(counted$1)).map((node) => ({
21191
+ check: contextName(node),
21192
+ node,
21193
+ state: checkState(node)
21194
+ }));
21195
+ const failing = kept.find(({ state }) => !PASSED.has(state) && !RUNNING.has(state));
21196
+ if (failing !== void 0) {
21197
+ const { check, node } = failing;
21198
+ const url = (node.__typename === "StatusContext" ? node.targetUrl : node.detailsUrl) ?? null;
21199
+ const red = {
21200
+ state: "red",
21201
+ branch,
21202
+ sha: target.oid,
21203
+ check,
21204
+ url
21205
+ };
21206
+ const fact = defaultBranchFactSchema.safeParse(red);
21207
+ if (fact.success) return fact.data;
21208
+ return url === null ? void 0 : defaultBranchFactSchema.safeParse({
21209
+ ...red,
21210
+ url: null
21211
+ }).data;
21212
+ }
21213
+ if (kept.length === 0 || pageInfo.hasNextPage || kept.some(({ state }) => !PASSED.has(state))) return void 0;
21214
+ return defaultBranchFactSchema.safeParse({
21215
+ state: "green",
21216
+ branch,
21217
+ sha: target.oid
21218
+ }).data;
21219
+ }
20960
21220
  // ../adapters/src/github/feedbackLinks.ts
20961
21221
  const threadCommentWire = z.object({
20962
21222
  id: z.string().min(1),
@@ -21008,24 +21268,6 @@ const typedActor = z.object({
21008
21268
  __typename: z.string(),
21009
21269
  login: z.string().min(1)
21010
21270
  }).nullable();
21011
- const checkRunWire = z.object({
21012
- __typename: z.literal("CheckRun"),
21013
- name: z.string(),
21014
- status: z.string(),
21015
- conclusion: z.string().nullable(),
21016
- startedAt: z.string().nullish(),
21017
- completedAt: z.string().nullable(),
21018
- checkSuite: z.object({ createdAt: z.string() }).nullish(),
21019
- isRequired: z.boolean().nullish()
21020
- }).refine((run) => run.status !== "COMPLETED" || run.conclusion !== null, { path: ["conclusion"] });
21021
- const statusContextWire = z.object({
21022
- __typename: z.literal("StatusContext"),
21023
- context: z.string(),
21024
- state: z.string(),
21025
- createdAt: z.string(),
21026
- isRequired: z.boolean().nullish()
21027
- });
21028
- const contextWire = z.discriminatedUnion("__typename", [checkRunWire, statusContextWire]);
21029
21271
  const reviewWire = z.object({
21030
21272
  id: z.string().min(1),
21031
21273
  author: typedActor,
@@ -21134,49 +21376,15 @@ function closingRefs(wire) {
21134
21376
  number: node.number
21135
21377
  }] : []);
21136
21378
  }
21137
- /** The contracts check state of a check run or commit status. */
21138
- function checkState(node) {
21139
- if (node.__typename === "StatusContext") {
21140
- const state = node.state.toLowerCase();
21141
- return state === "success" ? "success" : state === "pending" ? "pending" : state === "expected" ? "expected" : "failure";
21142
- }
21143
- if (node.status !== "COMPLETED") return "pending";
21144
- const value = node.conclusion?.toLowerCase();
21145
- return [
21146
- "success",
21147
- "neutral",
21148
- "skipped",
21149
- "failure",
21150
- "cancelled",
21151
- "timed_out",
21152
- "action_required",
21153
- "stale"
21154
- ].find((state) => state === value) ?? "error";
21155
- }
21156
- /** When a context ran, to keep the latest per name; an empty string sorts first. */
21157
- function contextAt(node) {
21158
- return node.__typename === "StatusContext" ? node.createdAt : node.startedAt ?? node.checkSuite?.createdAt ?? node.completedAt ?? "";
21159
- }
21160
21379
  function latestChecks(nodes) {
21161
- const latest = /* @__PURE__ */ new Map();
21162
- for (const node of nodes) {
21163
- const status = node.__typename === "StatusContext";
21164
- const name = status ? node.context : node.name;
21165
- const completedAt = status ? null : node.completedAt;
21166
- const at = contextAt(node);
21167
- const old = latest.get(name);
21168
- if (old !== void 0 && old.at > at) continue;
21169
- latest.set(name, {
21170
- check: {
21171
- name,
21172
- state: checkState(node),
21173
- completedAt
21174
- },
21175
- required: node.isRequired === true,
21176
- at
21177
- });
21178
- }
21179
- const values = [...latest.values()].sort((a, b) => a.check.name.localeCompare(b.check.name));
21380
+ const values = latestContexts(nodes).map((node) => ({
21381
+ check: {
21382
+ name: contextName(node),
21383
+ state: checkState(node),
21384
+ completedAt: node.__typename === "StatusContext" ? null : node.completedAt
21385
+ },
21386
+ required: node.isRequired === true
21387
+ }));
21180
21388
  return {
21181
21389
  checks: values.map((v) => v.check),
21182
21390
  requiredChecks: values.filter((v) => v.required).map((v) => v.check)
@@ -21389,158 +21597,6 @@ function normalizePr(repo, value, rule, feedbackComplete, held = []) {
21389
21597
  if (!parsed.success) throw new AdapterError("transient", "Malformed GitHub PR facts", { cause: parsed.error });
21390
21598
  return parsed.data;
21391
21599
  }
21392
- // ../adapters/src/github/discovery.ts
21393
- const timestamp$1 = z.string().min(1).refine((value) => !Number.isNaN(Date.parse(value)));
21394
- const discoveryNodeWire = z.object({
21395
- number: z.int().positive(),
21396
- state: z.string().optional(),
21397
- updatedAt: timestamp$1,
21398
- author: z.object({ login: z.string() }).nullable()
21399
- });
21400
- const baselineNodeWire = z.object({ updatedAt: timestamp$1 });
21401
- function latestUpdatedAt(nodes, previous) {
21402
- let high = previous;
21403
- for (const node of nodes) {
21404
- const updated = sourceCursorSchema.parse(node.updatedAt);
21405
- if (high === void 0 || Date.parse(updated) > Date.parse(high)) high = updated;
21406
- }
21407
- return high;
21408
- }
21409
- /** The high-water cursor is an ISO timestamp. Equal timestamps are revisited. */
21410
- function discover(nodes, previous, login) {
21411
- let high = previous;
21412
- const numbers = /* @__PURE__ */ new Set();
21413
- const states = /* @__PURE__ */ new Map();
21414
- for (const node of nodes) {
21415
- const updated = sourceCursorSchema.parse(node.updatedAt);
21416
- const updatedMs = Date.parse(updated);
21417
- if (high === void 0 || updatedMs > Date.parse(high)) high = updated;
21418
- if (previous !== void 0 && updatedMs < Date.parse(previous)) continue;
21419
- states.set(node.number, node.state);
21420
- if (node.author?.login.toLowerCase() !== login.toLowerCase()) continue;
21421
- numbers.add(node.number);
21422
- }
21423
- return {
21424
- numbers: [...numbers],
21425
- states,
21426
- ...high === void 0 ? {} : { cursor: high }
21427
- };
21428
- }
21429
- /** Pages are sorted newest first; older nodes end the scan, while ties must be revisited. */
21430
- function pastCursor(nodes, previous) {
21431
- const oldest = nodes.at(-1);
21432
- if (previous === void 0 || oldest === void 0) return false;
21433
- return Date.parse(oldest.updatedAt) < Date.parse(previous);
21434
- }
21435
- function nextPage(connection) {
21436
- const { hasNextPage, endCursor } = connection.pageInfo;
21437
- if (!hasNextPage) return void 0;
21438
- if (!endCursor) throw new Error("Malformed GitHub pagination");
21439
- return endCursor;
21440
- }
21441
- const branchCheckRunWire = z.object({
21442
- __typename: z.literal("CheckRun"),
21443
- name: z.string(),
21444
- status: z.string(),
21445
- conclusion: z.string().nullable(),
21446
- startedAt: z.string().nullish(),
21447
- completedAt: z.string().nullable(),
21448
- detailsUrl: z.string().nullish(),
21449
- checkSuite: z.object({
21450
- createdAt: z.string(),
21451
- workflowRun: z.object({
21452
- event: z.string(),
21453
- workflow: z.object({ id: z.string().min(1) })
21454
- }).nullish()
21455
- }).nullish()
21456
- });
21457
- const branchStatusWire = z.object({
21458
- __typename: z.literal("StatusContext"),
21459
- context: z.string(),
21460
- state: z.string(),
21461
- createdAt: z.string(),
21462
- targetUrl: z.string().nullish()
21463
- });
21464
- const branchContextWire = z.discriminatedUnion("__typename", [branchCheckRunWire, branchStatusWire]);
21465
- const defaultBranchWire = z.object({ defaultBranchRef: z.object({
21466
- name: z.string(),
21467
- target: z.object({
21468
- __typename: z.literal("Commit"),
21469
- oid: z.string(),
21470
- statusCheckRollup: z.object({ contexts: z.object({
21471
- nodes: z.array(branchContextWire),
21472
- pageInfo: z.object({ hasNextPage: z.boolean() })
21473
- }) })
21474
- })
21475
- }) });
21476
- /**
21477
- * Only reruns of one check replace each other: a commit status by its context, a check run by
21478
- * its workflow and job name. A check run outside a push-triggered workflow has no key.
21479
- */
21480
- function checkKey(node) {
21481
- if (node.__typename === "StatusContext") return `status:${node.context}`;
21482
- const run = node.checkSuite?.workflowRun;
21483
- if (run?.event !== "push") return void 0;
21484
- return `check:${run.workflow.id}:${node.name}`;
21485
- }
21486
- const PASSED = /* @__PURE__ */ new Set([
21487
- "success",
21488
- "neutral",
21489
- "skipped"
21490
- ]);
21491
- const RUNNING = /* @__PURE__ */ new Set(["pending", "expected"]);
21492
- /**
21493
- * The colour of the default-branch head in a discovery response's `repository`, or undefined
21494
- * when it is unknown: an unexpected shape, a running head, no counted check, or a truncated page
21495
- * with no failure in it. Only check runs of push-triggered workflows and commit statuses count;
21496
- * the latest run of each check decides (see `checkKey`). A run URL that is not http(s) becomes null.
21497
- */
21498
- function defaultBranchFact(repository) {
21499
- const parsed = defaultBranchWire.safeParse(repository);
21500
- if (!parsed.success) return void 0;
21501
- const { name: branch, target } = parsed.data.defaultBranchRef;
21502
- const { nodes, pageInfo } = target.statusCheckRollup.contexts;
21503
- const latest = /* @__PURE__ */ new Map();
21504
- for (const node of nodes) {
21505
- const key = checkKey(node);
21506
- if (key === void 0) continue;
21507
- const old = latest.get(key);
21508
- if (old !== void 0 && contextAt(old.node) > contextAt(node)) continue;
21509
- latest.set(key, {
21510
- check: node.__typename === "StatusContext" ? node.context : node.name,
21511
- node
21512
- });
21513
- }
21514
- const kept = [...latest.entries()].sort(([a, x], [b, y]) => x.check.localeCompare(y.check) || a.localeCompare(b)).map(([, { check, node }]) => ({
21515
- check,
21516
- node,
21517
- state: checkState(node)
21518
- }));
21519
- const failing = kept.find(({ state }) => !PASSED.has(state) && !RUNNING.has(state));
21520
- if (failing !== void 0) {
21521
- const { check, node } = failing;
21522
- const url = (node.__typename === "StatusContext" ? node.targetUrl : node.detailsUrl) ?? null;
21523
- const red = {
21524
- state: "red",
21525
- branch,
21526
- sha: target.oid,
21527
- check,
21528
- url
21529
- };
21530
- const fact = defaultBranchFactSchema.safeParse(red);
21531
- if (fact.success) return fact.data;
21532
- return url === null ? void 0 : defaultBranchFactSchema.safeParse({
21533
- ...red,
21534
- url: null
21535
- }).data;
21536
- }
21537
- if (kept.length === 0 || pageInfo.hasNextPage || kept.some(({ state }) => !PASSED.has(state))) return void 0;
21538
- return defaultBranchFactSchema.safeParse({
21539
- state: "green",
21540
- branch,
21541
- sha: target.oid
21542
- }).data;
21543
- }
21544
21600
  const counted = (node) => z.object({
21545
21601
  totalCount: z.int().nonnegative(),
21546
21602
  nodes: z.array(node)
package/dist/mcp.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { et as ERRORS, p as OPERATIONS, v as renderMcpError } from "./chunk-DGsDK61k.mjs";
2
- import { o as CliError, r as requestOperation } from "./chunk-2UOGIWN_.mjs";
3
- import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./chunk-BTkdnlO3.mjs";
1
+ import { et as ERRORS, p as OPERATIONS, v as renderMcpError } from "./chunk-IDeN7dOW.mjs";
2
+ import { o as CliError, r as requestOperation } from "./chunk-D-1P5oeK.mjs";
3
+ import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./chunk-gi-XmApc.mjs";
4
4
  import { randomUUID } from "node:crypto";
5
5
  import { readFileSync } from "node:fs";
6
6
  import { z } from "zod";