spur-board 0.55.0 → 0.55.1

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.
@@ -1,4 +1,4 @@
1
- import { $ as errorEnvelopeSchema, Q as errorContextSchema, S as renderJsonError, X as ERRORS, c as tokenRequestStatusSchema, o as tokenRequestResultSchema, tt as successEnvelopeSchema } from "./chunk-DdX2rQDT.mjs";
1
+ import { $ as errorContextSchema, S as renderJsonError, Z as ERRORS, c as tokenRequestStatusSchema, et as errorEnvelopeSchema, nt as successEnvelopeSchema, o as tokenRequestResultSchema } from "./chunk-DsCpUW6q.mjs";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { z } from "zod";
4
4
  import { request } from "node:http";
@@ -148,6 +148,7 @@ const TASK_HOLDS = [
148
148
  "pr_snapshot_missing",
149
149
  "github_blind",
150
150
  "spur_blind",
151
+ "ticket_unconfirmed",
151
152
  "cycle_limit",
152
153
  "work_not_started"
153
154
  ];
@@ -1182,6 +1183,7 @@ const prFactsSchema = z.strictObject({
1182
1183
  ticketKeys: z.array(taskKeySchema).describe("Ticket keys found in the head branch name and the title."),
1183
1184
  updatedAt: at$2.describe("When the pull request last changed."),
1184
1185
  mergedAt: at$2.optional().describe("When the pull request merged; absent while it is not merged and in facts stored by an earlier version."),
1186
+ closedAt: at$2.optional().describe("When the pull request closed without merge; absent while it is not closed and in facts stored by an earlier version."),
1185
1187
  feedback: z.array(feedbackSchema).optional().describe("Comments and submitted reviews on the pull request, oldest first, without their text."),
1186
1188
  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.")
1187
1189
  }).describe("Facts about one pull request.");
@@ -1979,7 +1981,8 @@ const linkViewSchema = z.strictObject({
1979
1981
  "worker",
1980
1982
  "other",
1981
1983
  "orchestrator"
1982
- ]).nullable().describe("Session role; null for a pull request or ticket.")
1984
+ ]).nullable().describe("Session role; null for a pull request or ticket."),
1985
+ state: z.enum(PR_STATES).optional().describe("Pull request state as last observed; absent for a session or ticket and for a pull request not observed yet. Only task.get sets it.")
1983
1986
  }).describe("An effective link to a task.");
1984
1987
  const detailOnly = "Present only with detail.";
1985
1988
  const count = (what) => z.int().min(0).describe(what);
@@ -3875,4 +3878,4 @@ function assertNever(value) {
3875
3878
  throw new Error(`Unexpected value: ${JSON.stringify(value)}`);
3876
3879
  }
3877
3880
  //#endregion
3878
- export { errorEnvelopeSchema as $, EVENT_KINDS as A, sessionFactsSchema as B, renderMcpError as C, interactionRefSchema as D, inboundEventSchema as E, isExternalAuthor as F, encodeActorId as G, JIRA_PROJECT_KEY as H, parseRingMarker as I, parseRef as J, errorCodeOf as K, prFactsSchema as L, REVIEW_STATES as M, SESSION_HEALTH_STATES as N, messageRefSchema as O, SESSION_STATUSES as P, errorContextSchema as Q, prRefSchema as R, renderJsonError as S, conversationRefSchema as T, REF_NUMBER as U, ticketFactsSchema as V, actorIdSchema as W, ERRORS as X, taskKeySchema as Y, err as Z, buildCatalogSnapshot as _, requestHashOf as a, DEFAULT_SLACK_COMMAND as at, turnHandedSchema as b, tokenRequestStatusSchema as c, plainHttpAllowed as ct, AdapterError as d, DISPATCHER_MODES as dt, ok as et, batchSchema as f, SLACK_BOT_SCOPES as ft, trackerSourceId as g, sourceCursorSchema as h, TOKEN_REQUEST_LIMITS as i, DEFAULT_SLACK_APP_NAME as it, eventPayloadSchemas as j, userIdSchema as k, BOARD_TICK_MS as l, requiredSecretKeys as lt, prSourceId as m, doctorReportSchema as n, DEFAULT_HTTP_PORT as nt, tokenRequestResultSchema as o, RESERVED_PROJECT as ot, entityRefSchema as p, parseActorId as q, remoteDoctorReportSchema as r, DEFAULT_LINK as rt, tokenRequestSchema as s, configSchema as st, assertNever as t, successEnvelopeSchema as tt, SYSTEMD_SERVICE_SETTINGS as u, COLUMN_IDS as ut, roleCanUseOperation as v, SPACE_IDS as w, renderHttpProblem as x, OPERATIONS as y, ringMarker as z };
3881
+ export { errorContextSchema as $, EVENT_KINDS as A, ringMarker as B, renderMcpError as C, interactionRefSchema as D, inboundEventSchema as E, SESSION_STATUSES as F, actorIdSchema as G, ticketFactsSchema as H, isExternalAuthor as I, parseActorId as J, encodeActorId as K, parseRingMarker as L, PR_STATES as M, REVIEW_STATES as N, messageRefSchema as O, SESSION_HEALTH_STATES as P, err as Q, prFactsSchema as R, renderJsonError as S, conversationRefSchema as T, JIRA_PROJECT_KEY as U, sessionFactsSchema as V, REF_NUMBER as W, taskKeySchema as X, parseRef as Y, ERRORS as Z, buildCatalogSnapshot as _, requestHashOf as a, DEFAULT_SLACK_APP_NAME as at, turnHandedSchema as b, tokenRequestStatusSchema as c, configSchema as ct, AdapterError as d, COLUMN_IDS as dt, errorEnvelopeSchema as et, batchSchema as f, DISPATCHER_MODES as ft, trackerSourceId as g, sourceCursorSchema as h, TOKEN_REQUEST_LIMITS as i, DEFAULT_LINK as it, eventPayloadSchemas as j, userIdSchema as k, BOARD_TICK_MS as l, plainHttpAllowed as lt, prSourceId as m, TASK_HOLDS as mt, doctorReportSchema as n, successEnvelopeSchema as nt, tokenRequestResultSchema as o, DEFAULT_SLACK_COMMAND as ot, entityRefSchema as p, SLACK_BOT_SCOPES as pt, errorCodeOf as q, remoteDoctorReportSchema as r, DEFAULT_HTTP_PORT as rt, tokenRequestSchema as s, RESERVED_PROJECT as st, assertNever as t, ok as tt, SYSTEMD_SERVICE_SETTINGS as u, requiredSecretKeys as ut, roleCanUseOperation as v, SPACE_IDS as w, renderHttpProblem as x, OPERATIONS as y, prRefSchema as z };
@@ -1,5 +1,5 @@
1
- import { _ as buildCatalogSnapshot, ct as plainHttpAllowed, st as configSchema, y as OPERATIONS } from "./chunk-DdX2rQDT.mjs";
2
- import { o as CliError, t as fetchCatalogVersion } from "./chunk-3DiqeT6s.mjs";
1
+ import { _ as buildCatalogSnapshot, ct as configSchema, lt as plainHttpAllowed, y as OPERATIONS } from "./chunk-DsCpUW6q.mjs";
2
+ import { o as CliError, t as fetchCatalogVersion } from "./chunk-B2jz795d.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/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { W as actorIdSchema, X as ERRORS, a as requestHashOf, ft as SLACK_BOT_SCOPES, lt as requiredSecretKeys, r as remoteDoctorReportSchema, st as configSchema, tt as successEnvelopeSchema, u as SYSTEMD_SERVICE_SETTINGS, v as roleCanUseOperation, y as OPERATIONS } from "./chunk-DdX2rQDT.mjs";
1
+ import { G as actorIdSchema, Z as ERRORS, a as requestHashOf, ct as configSchema, nt as successEnvelopeSchema, pt as SLACK_BOT_SCOPES, r as remoteDoctorReportSchema, u as SYSTEMD_SERVICE_SETTINGS, ut as requiredSecretKeys, v as roleCanUseOperation, y as OPERATIONS } from "./chunk-DsCpUW6q.mjs";
2
2
  import { t as apiBaseUrl } from "./chunk-DAMwWWmT.mjs";
3
- import { a as requestTokenEnrollment, c as renderCliError, i as requestSkillReload, l as escapeTerminalControls, n as fetchTokenStatus, o as CliError, r as requestOperation, s as errorExitCode } from "./chunk-3DiqeT6s.mjs";
4
- import { a as memoryVerdictCache, c as loadClientConfig, d as resolveDaemonAddress, f as tokenInFolder, i as fileVerdictCache, l as loadEnrollmentConfig, n as cliPackageVersion, o as configFile, s as dataDirectory, t as checkCatalog, u as readConfiguredPort } from "./chunk-COsEkoTY.mjs";
3
+ import { a as requestTokenEnrollment, c as renderCliError, i as requestSkillReload, l as escapeTerminalControls, n as fetchTokenStatus, o as CliError, r as requestOperation, s as errorExitCode } from "./chunk-B2jz795d.mjs";
4
+ import { a as memoryVerdictCache, c as loadClientConfig, d as resolveDaemonAddress, f as tokenInFolder, i as fileVerdictCache, l as loadEnrollmentConfig, n as cliPackageVersion, o as configFile, s as dataDirectory, t as checkCatalog, u as readConfiguredPort } from "./chunk-hS9wN0vI.mjs";
5
5
  import { createHash, randomBytes, randomUUID } from "node:crypto";
6
6
  import { accessSync, chmodSync, closeSync, constants, cpSync, existsSync, ftruncateSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
7
7
  import { homedir, hostname, userInfo } from "node:os";
package/dist/client.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { a as requestTokenEnrollment, i as requestSkillReload, n as fetchTokenStatus, r as requestOperation, t as fetchCatalogVersion } from "./chunk-3DiqeT6s.mjs";
1
+ import { a as requestTokenEnrollment, i as requestSkillReload, n as fetchTokenStatus, r as requestOperation, t as fetchCatalogVersion } from "./chunk-B2jz795d.mjs";
2
2
  export { fetchCatalogVersion, fetchTokenStatus, requestOperation, requestSkillReload, requestTokenEnrollment };
package/dist/daemon.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { A as EVENT_KINDS, B as sessionFactsSchema, D as interactionRefSchema, E as inboundEventSchema, F as isExternalAuthor, G as encodeActorId, H as JIRA_PROJECT_KEY, I as parseRingMarker, J as parseRef$1, K as errorCodeOf, L as prFactsSchema, M as REVIEW_STATES, N as SESSION_HEALTH_STATES, O as messageRefSchema, P as SESSION_STATUSES, R as prRefSchema, T as conversationRefSchema, U as REF_NUMBER, V as ticketFactsSchema, W as actorIdSchema, X as ERRORS, Y as taskKeySchema, Z as err, _ as buildCatalogSnapshot, a as requestHashOf, at as DEFAULT_SLACK_COMMAND, b as turnHandedSchema, c as tokenRequestStatusSchema, ct as plainHttpAllowed, d as AdapterError, dt as DISPATCHER_MODES, et as ok, f as batchSchema, ft as SLACK_BOT_SCOPES, g as trackerSourceId, h as sourceCursorSchema, i as TOKEN_REQUEST_LIMITS, j as eventPayloadSchemas, k as userIdSchema, l as BOARD_TICK_MS, lt as requiredSecretKeys, m as prSourceId, n as doctorReportSchema, o as tokenRequestResultSchema, ot as RESERVED_PROJECT, p as entityRefSchema, q as parseActorId, rt as DEFAULT_LINK, s as tokenRequestSchema, st as configSchema, t as assertNever, tt as successEnvelopeSchema, ut as COLUMN_IDS, v as roleCanUseOperation, w as SPACE_IDS, x as renderHttpProblem, y as OPERATIONS, z as ringMarker } from "./chunk-DdX2rQDT.mjs";
1
+ import { A as EVENT_KINDS, B as ringMarker, D as interactionRefSchema, E as inboundEventSchema, F as SESSION_STATUSES, G as actorIdSchema, H as ticketFactsSchema, I as isExternalAuthor, J as parseActorId, K as encodeActorId, L as parseRingMarker, M as PR_STATES, N as REVIEW_STATES, O as messageRefSchema, P as SESSION_HEALTH_STATES, Q as err, R as prFactsSchema, T as conversationRefSchema, U as JIRA_PROJECT_KEY, V as sessionFactsSchema, W as REF_NUMBER, X as taskKeySchema, Y as parseRef$1, Z as ERRORS, _ as buildCatalogSnapshot, a as requestHashOf, b as turnHandedSchema, c as tokenRequestStatusSchema, ct as configSchema, d as AdapterError, dt as COLUMN_IDS, f as batchSchema, ft as DISPATCHER_MODES, g as trackerSourceId, h as sourceCursorSchema, i as TOKEN_REQUEST_LIMITS, it as DEFAULT_LINK, j as eventPayloadSchemas, k as userIdSchema, l as BOARD_TICK_MS, lt as plainHttpAllowed, m as prSourceId, mt as TASK_HOLDS, n as doctorReportSchema, nt as successEnvelopeSchema, o as tokenRequestResultSchema, ot as DEFAULT_SLACK_COMMAND, p as entityRefSchema, pt as SLACK_BOT_SCOPES, q as errorCodeOf, s as tokenRequestSchema, st as RESERVED_PROJECT, t as assertNever, tt as ok, ut as requiredSecretKeys, v as roleCanUseOperation, w as SPACE_IDS, x as renderHttpProblem, y as OPERATIONS, z as prRefSchema } from "./chunk-DsCpUW6q.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";
@@ -7994,6 +7994,26 @@ function ticketDone(project, status) {
7994
7994
  return project.tracker.type === "jira" ? project.tracker.doneStatuses.includes(status) : status === "closed";
7995
7995
  }
7996
7996
  /**
7997
+ * How the ticket of a task stands after its PR merged at `mergedAt`: `done`; `open` once the
7998
+ * tracker saw it open at least one tracker interval after the merge, in the filter or fetched by
7999
+ * key for a hand-added task; else `unconfirmed`, since the close a merge triggers may not be
8000
+ * polled yet and a ticket dropped from the filter keeps a stale status.
8001
+ */
8002
+ function mergedTicket(project, config, ticket, manualInclude, mergedAt) {
8003
+ if (ticket === void 0) return "unconfirmed";
8004
+ if (ticketDone(project, ticket.status)) return "done";
8005
+ let inFilter;
8006
+ try {
8007
+ const parsed = ticketFactsSchema.safeParse(JSON.parse(ticket.detail));
8008
+ if (!parsed.success) return "unconfirmed";
8009
+ inFilter = parsed.data.inFilter;
8010
+ } catch {
8011
+ return "unconfirmed";
8012
+ }
8013
+ const { intervalMs } = project.tracker.type === "jira" ? config.adapters.jira : config.adapters.githubIssues;
8014
+ return (inFilter || manualInclude) && Date.parse(ticket.observed_at) >= Date.parse(mergedAt) + intervalMs ? "open" : "unconfirmed";
8015
+ }
8016
+ /**
7997
8017
  * Whether a PR link counts past the task's reopen floor: an open link, or a link not hidden by a
7998
8018
  * reopen. For a query over `link`. Written so a link without a marker counts: the negated form
7999
8019
  * is NULL there and would drop it.
@@ -8015,6 +8035,17 @@ async function taskPr(db, taskId) {
8015
8035
  open: link.pr_open === 1
8016
8036
  };
8017
8037
  }
8038
+ /**
8039
+ * The task's newest merged PR: the newest active unbanned link past the reopen floor whose PR is
8040
+ * seen merged. Completes a task whose follow-up PR closed unmerged after an earlier merge.
8041
+ */
8042
+ async function taskMergedPr(db, taskId) {
8043
+ const link = await db.selectFrom("link").innerJoin("pr_snapshot", (join) => join.on(sql`lower(pr_snapshot.repo) = lower(link.repo)`).onRef("pr_snapshot.number", "=", "link.number")).select(["link.repo", "link.number"]).where("link.task_id", "=", taskId).where("link.entity", "=", "pr").where("link.pr_state", "=", "active").where("link.banned", "=", 0).where("pr_snapshot.state", "=", "merged").where(pastReopenFloor).orderBy("link.id", "desc").executeTakeFirst();
8044
+ return link?.repo == null || link.number === null ? null : {
8045
+ repo: link.repo,
8046
+ number: link.number
8047
+ };
8048
+ }
8018
8049
  /** A PR snapshot's facts, or null when the detail is missing or unreadable. */
8019
8050
  function parsePr(detail) {
8020
8051
  if (detail === void 0) return null;
@@ -12977,7 +13008,7 @@ async function existingLink(trx, taskId, input, ticket) {
12977
13008
  async function sessionRole(trx, taskId) {
12978
13009
  return await trx.selectFrom("link").select("id").where("task_id", "=", taskId).where("entity", "=", "session").where("role", "=", "worker").where("banned", "=", 0).executeTakeFirst() === void 0 ? "worker" : "other";
12979
13010
  }
12980
- async function prConflict(trx, taskId, repo, number, open) {
13011
+ async function prConflict(trx, taskId, repo, number, open, doneTicket) {
12981
13012
  const links = await trx.selectFrom("link").leftJoin("pr_snapshot", (join) => join.on(sql`lower(pr_snapshot.repo) = lower(link.repo)`).onRef("pr_snapshot.number", "=", "link.number")).select([
12982
13013
  "link.repo",
12983
13014
  "link.number",
@@ -12988,7 +13019,7 @@ async function prConflict(trx, taskId, repo, number, open) {
12988
13019
  for (const link of links) {
12989
13020
  if (link.repo?.toLowerCase() === repo && link.number === number) continue;
12990
13021
  const blocking = `${link.repo ?? ""}#${String(link.number ?? "")}`;
12991
- if (link.state === "merged") throw new CommandError("link_conflict", `${blocking} is merged; manual PR replacement is not allowed.`);
13022
+ if (link.state === "merged" && doneTicket) throw new CommandError("link_conflict", `${blocking} is merged; manual PR replacement is not allowed.`);
12992
13023
  if (open && link.pr_state === "active" && link.pr_open === 1) throw new CommandError("link_conflict", `${blocking} is already the open PR for this task.`);
12993
13024
  }
12994
13025
  }
@@ -13003,7 +13034,12 @@ async function run(trx, input, ctx, config, remove) {
13003
13034
  const pr = input.mode === "pr" ? prIdentity(input.pr) : null;
13004
13035
  const facts = pr === null ? null : await snapshot(trx, pr.repo, pr.number);
13005
13036
  const open = facts?.state !== "closed" && facts?.state !== "merged";
13006
- if (!remove && pr !== null) await prConflict(trx, task.id, pr.repo, pr.number, open);
13037
+ if (!remove && pr !== null) {
13038
+ const project = config.projects.find((entry) => entry.id === task.project);
13039
+ const status = await trx.selectFrom("ticket_snapshot").select("status").where("task_id", "=", task.id).executeTakeFirst();
13040
+ const doneTicket = project !== void 0 && status !== void 0 && ticketDone(project, status.status);
13041
+ await prConflict(trx, task.id, pr.repo, pr.number, open, doneTicket);
13042
+ }
13007
13043
  if (remove) {
13008
13044
  if (current?.banned === 1) return {
13009
13045
  task: key,
@@ -14172,11 +14208,30 @@ async function reconcileItems(trx, config, now, spurComplete, warnSkipped) {
14172
14208
  prCompleteAt: prCompleteAt(config.projects.find((entry) => entry.id === task.project), sourceById),
14173
14209
  turnSessions: []
14174
14210
  };
14211
+ const tickets = await trx.selectFrom("ticket_snapshot").select([
14212
+ "task_id",
14213
+ "status",
14214
+ "detail",
14215
+ "source",
14216
+ "observed_at"
14217
+ ]).execute();
14218
+ const mergedAt = /* @__PURE__ */ new Map();
14175
14219
  for (const pr of prs) {
14176
14220
  const state = taskPrs[String(pr.task_id)];
14177
14221
  if (state === void 0) continue;
14178
14222
  if (pr.state === "open") state.hasOpenPr = true;
14179
- if (pr.state === "merged") state.hasMergedPr = true;
14223
+ if (pr.state !== "merged") continue;
14224
+ const facts = parsePr(pr.detail ?? void 0);
14225
+ const at = facts === null ? null : facts.mergedAt ?? facts.updatedAt;
14226
+ const newest = mergedAt.get(pr.task_id) ?? null;
14227
+ if (newest === null || at !== null && Date.parse(at) >= Date.parse(newest)) mergedAt.set(pr.task_id, at);
14228
+ }
14229
+ for (const [taskId, at] of mergedAt) {
14230
+ const state = taskPrs[String(taskId)];
14231
+ const task = taskById.get(taskId);
14232
+ if (state === void 0 || task === void 0) continue;
14233
+ const project = config.projects.find((entry) => entry.id === task.project);
14234
+ state.hasMergedPr = at === null || project === void 0 || mergedTicket(project, config, tickets.find((entry) => entry.task_id === taskId), task.manual_include === 1, at) !== "open";
14180
14235
  }
14181
14236
  const workerTurns = await trx.selectFrom("turn").select(["task_id", "acked_by"]).where("role", "=", "worker").where("closed_at", "is", null).where("acked_at", "is not", null).execute();
14182
14237
  for (const turn of workerTurns) {
@@ -14187,13 +14242,18 @@ async function reconcileItems(trx, config, now, spurComplete, warnSkipped) {
14187
14242
  for (const task of tasks) {
14188
14243
  const state = taskPrs[String(task.id)];
14189
14244
  if (state === void 0 || state.hasOpenPr || state.hasMergedPr) continue;
14190
- const closed = prs.filter((pr) => pr.task_id === task.id && pr.state === "closed").map((pr) => ({
14191
- ...pr,
14192
- ref: `${pr.repo ?? ""}#${String(pr.number)}`
14193
- })).sort((left, right) => left.ref.localeCompare(right.ref));
14245
+ const mergedSince = Date.parse(mergedAt.get(task.id) ?? "");
14246
+ const closed = prs.filter((pr) => pr.task_id === task.id && pr.state === "closed").map((pr) => {
14247
+ const facts = pr.detail === null ? null : parseJson(prFactsSchema, pr.detail);
14248
+ return {
14249
+ ...pr,
14250
+ ref: `${pr.repo ?? ""}#${String(pr.number)}`,
14251
+ closedAt: facts === null ? NaN : Date.parse(facts.closedAt ?? facts.updatedAt)
14252
+ };
14253
+ }).filter((pr) => !(pr.closedAt < mergedSince)).sort((left, right) => left.ref.localeCompare(right.ref));
14194
14254
  const first = closed[0];
14195
14255
  if (first === void 0) continue;
14196
- const closedAt = Math.max(...closed.map((pr) => pr.detail === null ? NaN : Date.parse(parseJson(prFactsSchema, pr.detail).updatedAt)));
14256
+ const closedAt = Math.max(...closed.map((pr) => pr.closedAt));
14197
14257
  const key = `pr-closed:${String(task.id)}`;
14198
14258
  if (state.prCompleteAt === null || !(state.prCompleteAt >= closedAt)) {
14199
14259
  heldKeys.push(key);
@@ -14211,12 +14271,6 @@ async function reconcileItems(trx, config, now, spurComplete, warnSkipped) {
14211
14271
  revision: refs.join(",")
14212
14272
  });
14213
14273
  }
14214
- const tickets = await trx.selectFrom("ticket_snapshot").select([
14215
- "task_id",
14216
- "status",
14217
- "detail",
14218
- "source"
14219
- ]).execute();
14220
14274
  for (const task of tasks) {
14221
14275
  const state = taskPrs[String(task.id)];
14222
14276
  const project = config.projects.find((entry) => entry.id === task.project);
@@ -14739,13 +14793,40 @@ function handedOf(pr, entry) {
14739
14793
  * The dispatcher input of one task, or null when a stored snapshot is missing or unreadable. It
14740
14794
  * only reads.
14741
14795
  */
14742
- async function readInput(trx, task, project, mode, blind) {
14796
+ async function readInput(trx, task, project, mode, blind, config) {
14797
+ const readPr = async (ref) => parsePr((await trx.selectFrom("pr_snapshot").select("detail").where(sql`lower(repo) = ${ref.repo.toLowerCase()}`).where("number", "=", ref.number).executeTakeFirst())?.detail);
14743
14798
  const link = await taskPr(trx, task.id);
14744
14799
  let pr = null;
14745
14800
  if (link !== null) {
14746
- pr = parsePr((await trx.selectFrom("pr_snapshot").select("detail").where(sql`lower(repo) = ${link.repo.toLowerCase()}`).where("number", "=", link.number).executeTakeFirst())?.detail);
14801
+ pr = await readPr(link);
14747
14802
  if (pr === null) return null;
14748
14803
  }
14804
+ const readTicket = () => trx.selectFrom("ticket_snapshot").select([
14805
+ "status",
14806
+ "detail",
14807
+ "observed_at"
14808
+ ]).where("task_id", "=", task.id).executeTakeFirst();
14809
+ if (pr !== null && pr.state !== "merged") {
14810
+ const merged = await taskMergedPr(trx, task.id);
14811
+ if (merged !== null) {
14812
+ const ticket = await readTicket();
14813
+ if (pr.state === "closed" && link?.open !== true || ticket !== void 0 && ticketDone(project, ticket.status)) {
14814
+ pr = await readPr(merged);
14815
+ if (pr === null) return null;
14816
+ }
14817
+ }
14818
+ }
14819
+ let mergedOpen;
14820
+ let ticketUnconfirmed = false;
14821
+ if (pr?.state === "merged") {
14822
+ const judged = mergedTicket(project, config, await readTicket(), task.manual_include === 1, pr.mergedAt ?? pr.updatedAt);
14823
+ if (judged === "open") mergedOpen = {
14824
+ repo: pr.repo,
14825
+ number: pr.number
14826
+ };
14827
+ ticketUnconfirmed = judged === "unconfirmed";
14828
+ }
14829
+ if (mergedOpen !== void 0) pr = null;
14749
14830
  const githubBlind = (pr === null ? project.repos : [pr.repo]).some((repo) => blind(prSourceId(project.id, repo)));
14750
14831
  const marks = (await trx.selectFrom("submission").select(["column", "commit_sha"]).where("task_id", "=", task.id).where("voided_at", "is", null).orderBy("id").execute()).map((row) => {
14751
14832
  const headSha = row.commit_sha.toLowerCase();
@@ -14779,7 +14860,7 @@ async function readInput(trx, task, project, mode, blind) {
14779
14860
  unhandledExternalComments: unhandled.length,
14780
14861
  marks
14781
14862
  },
14782
- reopened: await trx.selectFrom("link").select("id").where("task_id", "=", task.id).where("reopen_hidden_at", "is not", null).executeTakeFirst() !== void 0,
14863
+ reopened: mergedOpen === void 0 && await trx.selectFrom("link").select("id").where("task_id", "=", task.id).where("reopen_hidden_at", "is not", null).executeTakeFirst() !== void 0,
14783
14864
  openPr: link?.open === true,
14784
14865
  githubBlind,
14785
14866
  spurBlind: blind("spur"),
@@ -14792,7 +14873,9 @@ async function readInput(trx, task, project, mode, blind) {
14792
14873
  }
14793
14874
  },
14794
14875
  handed,
14795
- unclosed
14876
+ unclosed,
14877
+ mergedOpen,
14878
+ ticketUnconfirmed
14796
14879
  };
14797
14880
  }
14798
14881
  async function applyShadow(trx, task, project, result, at) {
@@ -14857,7 +14940,7 @@ async function applyOn(trx, task, read, result, ctx) {
14857
14940
  const handed = [...carried, ...read.handed.filter((entry) => !carried.some((old) => sameHanded(old, entry)))];
14858
14941
  await openTurn(trx, {
14859
14942
  task: current,
14860
- reason: turnReason(turn, replaced?.reason),
14943
+ reason: read.mergedOpen === void 0 || turn.kind === "reroute" ? turnReason(turn, replaced?.reason) : `${turnReason(turn)} (PR ${read.mergedOpen.repo}#${String(read.mergedOpen.number)} merged, ticket still open)`,
14861
14944
  handed: current.column === "dev" ? handed : [],
14862
14945
  at,
14863
14946
  config
@@ -14877,8 +14960,8 @@ async function dispatchTasks(trx, taskIds, ctx) {
14877
14960
  const project = ctx.config.projects.find((entry) => entry.id === task.project);
14878
14961
  if (project === void 0) continue;
14879
14962
  const mode = project.dispatcher.mode;
14880
- const read = await readInput(trx, task, project, mode, blind);
14881
- if (read === null) continue;
14963
+ const read = await readInput(trx, task, project, mode, blind, ctx.config);
14964
+ if (read === null || read.ticketUnconfirmed) continue;
14882
14965
  const result = dispatch(read.input);
14883
14966
  if (mode === "shadow") await applyShadow(trx, task, project, result, ctx.at);
14884
14967
  else await applyOn(trx, task, read, result, ctx);
@@ -14911,6 +14994,16 @@ async function dispatchSource(trx, source, ctx) {
14911
14994
  if (projects.length === 0) return;
14912
14995
  await dispatchTasks(trx, (await trx.selectFrom("task").select("id").where("project", "in", projects).where("membership", "!=", "archived").execute()).map((task) => task.id), ctx);
14913
14996
  }
14997
+ /**
14998
+ * Evaluates the tasks of a tracker source's project that are out of Done and whose PR merged:
14999
+ * a poll that only refreshes an unchanged open ticket journals nothing, yet can confirm it open
15000
+ * past the merge.
15001
+ */
15002
+ async function dispatchMergedTickets(trx, source, ctx) {
15003
+ const project = ctx.config.projects.find((entry) => trackerSourceId(entry) === source);
15004
+ if (project === void 0) return;
15005
+ await dispatchTasks(trx, (await trx.selectFrom("task").innerJoin("link", "link.task_id", "task.id").innerJoin("pr_snapshot", (join) => join.on(sql`lower(pr_snapshot.repo) = lower(link.repo)`).onRef("pr_snapshot.number", "=", "link.number")).select("task.id").distinct().where("task.project", "=", project.id).where("task.membership", "!=", "archived").where((eb) => eb.or([eb("task.column", "!=", "done"), eb("task.shadow_column", "!=", "done")])).where("link.entity", "=", "pr").where("link.pr_state", "=", "active").where("link.banned", "=", 0).where("pr_snapshot.state", "=", "merged").execute()).map((task) => task.id), ctx);
15006
+ }
14914
15007
  //#endregion
14915
15008
  //#region ../core/src/app/task-turns.ts
14916
15009
  /** How many closed turns `task.get --detail` shows. */
@@ -15098,7 +15191,7 @@ function createTaskQueries(deps) {
15098
15191
  const read = await readInput(trx, {
15099
15192
  ...task,
15100
15193
  column
15101
- }, project, mode, await blindSources(trx, completeSince));
15194
+ }, project, mode, await blindSources(trx, completeSince), config);
15102
15195
  if (read === null) return {
15103
15196
  ...shared,
15104
15197
  dispatcher: mode,
@@ -15107,7 +15200,7 @@ function createTaskQueries(deps) {
15107
15200
  checksWaivedBy: null
15108
15201
  };
15109
15202
  const { gates, checksWaivedBy } = explainGates(read.input.facts, read.input.project);
15110
- const holds = dispatchHolds(read.input);
15203
+ const holds = [...dispatchHolds(read.input), ...read.ticketUnconfirmed ? ["ticket_unconfirmed"] : []].sort((left, right) => TASK_HOLDS.indexOf(left) - TASK_HOLDS.indexOf(right));
15111
15204
  const heldBy = holds.includes("cycle_limit") ? await holdBlocks(trx, task.id) : [];
15112
15205
  return {
15113
15206
  ...shared,
@@ -15130,12 +15223,18 @@ function createTaskQueries(deps) {
15130
15223
  const [blocks, comments, links] = await Promise.all([
15131
15224
  trx.selectFrom("block").selectAll().where("task_id", "=", task.id).orderBy("id").execute(),
15132
15225
  trx.selectFrom("comment").selectAll().where("task_id", "=", task.id).orderBy("id").execute(),
15133
- trx.selectFrom("link").selectAll().where("task_id", "=", task.id).where("banned", "=", 0).orderBy("id").execute()
15226
+ 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()
15134
15227
  ]);
15135
15228
  return {
15136
15229
  task: taskView(task),
15137
15230
  ...await taskTurns(trx, task, input.detail === true),
15138
- links: links.map(linkView),
15231
+ links: links.map(({ state, ...link }) => {
15232
+ const observed = PR_STATES.find((value) => value === state);
15233
+ return {
15234
+ ...linkView(link),
15235
+ ...observed === void 0 ? {} : { state: observed }
15236
+ };
15237
+ }),
15139
15238
  blocks: blocks.map((block) => blockView(block, task)),
15140
15239
  comments: comments.map((comment) => commentView(comment, task)),
15141
15240
  ...input.why === true ? { why: await why(trx, task) } : {}
@@ -15552,7 +15651,7 @@ function createTurnMutations(deps) {
15552
15651
  if (!project.columns.some((column) => column.id === input.column && column.enabled)) throw new CommandError("move_not_allowed", `Column ${input.column} is not enabled in project ${project.id}; pick one of ${project.columns.filter((column) => column.enabled && column.id !== "done").map((column) => column.id).join(", ")}.`);
15553
15652
  const pr = await taskPr(trx, task.id);
15554
15653
  if (pr !== null) {
15555
- if ((await trx.selectFrom("pr_snapshot").select("state").where(sql`lower(repo) = ${pr.repo.toLowerCase()}`).where("number", "=", pr.number).executeTakeFirst())?.state === "merged") throw new CommandError("move_not_allowed", `Merged pull request ${`${pr.repo}#${String(pr.number)}`} keeps the task in Done; unlink it first with \`board unlink ${task.key} --pr https://github.com/${pr.repo}/pull/${String(pr.number)} --reason <text>\`.`);
15654
+ if ((await trx.selectFrom("pr_snapshot").select("state").where(sql`lower(repo) = ${pr.repo.toLowerCase()}`).where("number", "=", pr.number).executeTakeFirst())?.state === "merged") throw new CommandError("move_not_allowed", `Merged pull request ${`${pr.repo}#${String(pr.number)}`} sets the task's column: Done once its ticket is done, Dev while it stays open; unlink it first with \`board unlink ${task.key} --pr https://github.com/${pr.repo}/pull/${String(pr.number)} --reason <text>\`.`);
15556
15655
  }
15557
15656
  const corrected = await correctColumn(trx, {
15558
15657
  taskId: task.id,
@@ -15798,7 +15897,7 @@ async function updateTerminal(trx, config, taskId, at, completeSince, blind) {
15798
15897
  const complete = completeSince.get(source);
15799
15898
  return !blind.has(source) && complete !== void 0 && complete > (task.last_change_at ?? task.created_at);
15800
15899
  });
15801
- const terminal = !hasOpen && (merged || doneTicket && githubComplete);
15900
+ const terminal = !hasOpen && doneTicket && (merged || githubComplete);
15802
15901
  await trx.updateTable("task").set({ terminal_at: terminal ? task.terminal_at ?? (merged ? at : task.last_change_at ?? at) : null }).where("id", "=", taskId).execute();
15803
15902
  }
15804
15903
  async function blindReason(trx, source) {
@@ -16467,6 +16566,7 @@ function createObservationCore(deps) {
16467
16566
  };
16468
16567
  const recovered = wasBlind !== null && observation.state.blind === void 0;
16469
16568
  if (observation.effectiveComplete && !completeSince.has(source) || recovered) await dispatchSource(trx, source, dispatchContext);
16569
+ await dispatchMergedTickets(trx, source, dispatchContext);
16470
16570
  await dispatchJournaled(trx, dispatchContext);
16471
16571
  await reconcileItems(trx, config, now, currentComplete.has("spur"), warnSkipped);
16472
16572
  if (deps.productVersion !== void 0) await enqueueLiveAfterFirstPoll(trx, {
@@ -16682,6 +16782,7 @@ function commandReply(id, value, input) {
16682
16782
  body: [
16683
16783
  line(`Task ${result.task.key}: ${result.task.column} (${result.task.membership})`),
16684
16784
  turnLine(result.turn),
16785
+ ...result.links.flatMap((link) => link.kind === "pr" ? [line(`Pull request ${link.ref}: ${link.state ?? "not observed yet"}`)] : []),
16685
16786
  ...result.blocks.flatMap((block) => [line(`Block ${block.id} (${block.state}, ${block.type}):`), quote(block.reason)]),
16686
16787
  ...result.comments.flatMap((comment) => [line(`Comment ${comment.id} by ${comment.author}:`), quote(comment.text)])
16687
16788
  ]
@@ -17950,7 +18051,7 @@ const REVIEWER_FIELDS = "requestedReviewer { __typename ... on Bot { login } ...
17950
18051
  const REVIEW_FIELDS = "id author { __typename login } state commit { oid } submittedAt";
17951
18052
  const COMMENT_FIELDS = "nodes { id author { __typename login } createdAt } pageInfo { hasPreviousPage startCursor }";
17952
18053
  const CLOSING_FIELDS = "nodes { number repository { nameWithOwner } } pageInfo { hasNextPage endCursor }";
17953
- const prFields = (number, closing = false) => `id number url title updatedAt mergedAt state isDraft mergeable mergeStateStatus
18054
+ const prFields = (number, closing = false) => `id number url title updatedAt mergedAt closedAt state isDraft mergeable mergeStateStatus
17954
18055
  author { login } headRefName headRefOid
17955
18056
  statusCheckRollup { contexts(first: 100) { nodes {
17956
18057
  ... on CheckRun { __typename name status conclusion startedAt completedAt checkSuite { createdAt } isRequired(pullRequestNumber: ${String(number)}) }
@@ -18169,6 +18270,7 @@ const prWire = z.object({
18169
18270
  title: z.string(),
18170
18271
  updatedAt: z.string(),
18171
18272
  mergedAt: z.string().nullable(),
18273
+ closedAt: z.string().nullable(),
18172
18274
  state: z.string(),
18173
18275
  isDraft: z.boolean(),
18174
18276
  mergeable: z.string(),
@@ -18449,6 +18551,7 @@ function normalizePr(repo, value, rule, feedbackComplete, held = []) {
18449
18551
  ticketKeys: prKeys(rule, title, headBranch, closingRefs(wire.closingIssuesReferences)),
18450
18552
  updatedAt: wire.updatedAt,
18451
18553
  ...state === "merged" && wire.mergedAt !== null ? { mergedAt: wire.mergedAt } : {},
18554
+ ...state === "closed" && wire.closedAt !== null ? { closedAt: wire.closedAt } : {},
18452
18555
  feedback: feedbackOf(wire.reviews.nodes, wire.comments.nodes, held),
18453
18556
  feedbackComplete
18454
18557
  };
package/dist/mcp.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { C as renderMcpError, X as ERRORS, y as OPERATIONS } from "./chunk-DdX2rQDT.mjs";
2
- import { o as CliError, r as requestOperation } from "./chunk-3DiqeT6s.mjs";
3
- import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./chunk-COsEkoTY.mjs";
1
+ import { C as renderMcpError, Z as ERRORS, y as OPERATIONS } from "./chunk-DsCpUW6q.mjs";
2
+ import { o as CliError, r as requestOperation } from "./chunk-B2jz795d.mjs";
3
+ import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./chunk-hS9wN0vI.mjs";
4
4
  import { randomUUID } from "node:crypto";
5
5
  import { readFileSync } from "node:fs";
6
6
  import { z } from "zod";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spur-board",
3
- "version": "0.55.0",
3
+ "version": "0.55.1",
4
4
  "license": "MIT",
5
5
  "engines": {
6
6
  "node": "^24.12.0 || ^26.0.0"