spur-board 0.105.3 → 0.106.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.
@@ -1,4 +1,4 @@
1
- import { _ as renderJsonError, at as successEnvelopeSchema, c as tokenRequestStatusSchema, et as ERRORS, nt as errorContextSchema, o as tokenRequestResultSchema, rt as errorEnvelopeSchema } from "./chunk-IDeN7dOW.mjs";
1
+ import { _ as renderJsonError, at as successEnvelopeSchema, c as tokenRequestStatusSchema, et as ERRORS, nt as errorContextSchema, o as tokenRequestResultSchema, rt as errorEnvelopeSchema } from "./chunk-BzwnMm9i.mjs";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { z } from "zod";
4
4
  import { request } from "node:http";
@@ -3064,7 +3064,7 @@ const taskHistoryEventSchema = z.strictObject({
3064
3064
  }).describe("One journal event.");
3065
3065
  const taskHistoryOutputSchema = z.strictObject({
3066
3066
  task: taskViewSchema,
3067
- events: z.array(taskHistoryEventSchema).describe("Journal events of the task, oldest first.")
3067
+ events: z.array(taskHistoryEventSchema).describe("Journal events of the task, oldest first by time; facts events with nothing new to name, such as an update time alone, are left out.")
3068
3068
  });
3069
3069
  taskHistoryOutputSchema.extend({ events: z.array(taskHistoryEventSchema.extend({
3070
3070
  kind: z.string().min(1),
@@ -1,5 +1,5 @@
1
- import { d as buildCatalogSnapshot, gt as plainHttpAllowed, mt as configSchema, p as OPERATIONS } from "./chunk-IDeN7dOW.mjs";
2
- import { o as CliError, t as fetchCatalogVersion } from "./chunk-D-1P5oeK.mjs";
1
+ import { d as buildCatalogSnapshot, gt as plainHttpAllowed, mt as configSchema, p as OPERATIONS } from "./chunk-BzwnMm9i.mjs";
2
+ import { o as CliError, t as fetchCatalogVersion } from "./chunk-BM_rDrEG.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 { St as SLACK_BOT_SCOPES, Y as actorIdSchema, _t as requiredSecretKeys, a as requestHashOf, at as successEnvelopeSchema, et as ERRORS, f as roleCanUseOperation, mt as configSchema, p as OPERATIONS, r as remoteDoctorReportSchema, u as SYSTEMD_SERVICE_SETTINGS, ut as DEFAULT_STAND_PORT_RANGE, vt as resolveWebOrigin } from "./chunk-IDeN7dOW.mjs";
1
+ import { St as SLACK_BOT_SCOPES, Y as actorIdSchema, _t as requiredSecretKeys, a as requestHashOf, at as successEnvelopeSchema, et as ERRORS, f as roleCanUseOperation, mt as configSchema, p as OPERATIONS, r as remoteDoctorReportSchema, u as SYSTEMD_SERVICE_SETTINGS, ut as DEFAULT_STAND_PORT_RANGE, vt as resolveWebOrigin } from "./chunk-BzwnMm9i.mjs";
2
2
  import { t as apiBaseUrl } from "./chunk-Bzb7aI8R.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-D-1P5oeK.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-gi-XmApc.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-BM_rDrEG.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-CZ4l7_un.mjs";
5
5
  import { createHash, randomBytes, randomUUID } from "node:crypto";
6
6
  import { accessSync, chmodSync, closeSync, constants, cpSync, existsSync, ftruncateSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
7
7
  import { homedir, hostname, tmpdir, userInfo } from "node:os";
package/dist/client.mjs CHANGED
@@ -1 +1 @@
1
- export { t as fetchCatalogVersion, n as fetchTokenStatus, r as requestOperation, i as requestSkillReload, a as requestTokenEnrollment } from "./chunk-D-1P5oeK.mjs";
1
+ export { t as fetchCatalogVersion, n as fetchTokenStatus, r as requestOperation, i as requestSkillReload, a as requestTokenEnrollment } from "./chunk-BM_rDrEG.mjs";
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-IDeN7dOW.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-BzwnMm9i.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";
@@ -13825,7 +13825,7 @@ function prIdentity(url) {
13825
13825
  number
13826
13826
  };
13827
13827
  }
13828
- function ref(input) {
13828
+ function ref$1(input) {
13829
13829
  if (input.mode === "pr") {
13830
13830
  const pr = prIdentity(input.pr);
13831
13831
  return `${pr.repo}#${String(pr.number)}`;
@@ -13881,7 +13881,7 @@ async function run(trx, input, ctx, config, remove) {
13881
13881
  if (task === void 0) throw new CommandError("not_found", "Check the task key.");
13882
13882
  if (task.membership === "archived") throw new CommandError("task_archived", "Task is archived.");
13883
13883
  const ticket = input.mode === "ticket" ? ticketIdentity(config, input.ticket) : null;
13884
- const target = ticket ?? ref(input);
13884
+ const target = ticket ?? ref$1(input);
13885
13885
  const current = await existingLink(trx, task.id, input, ticket);
13886
13886
  const pr = input.mode === "pr" ? prIdentity(input.pr) : null;
13887
13887
  const facts = pr === null ? null : await snapshot(trx, pr.repo, pr.number);
@@ -17032,6 +17032,293 @@ function turnSummary(kind, payloadText) {
17032
17032
  return null;
17033
17033
  }
17034
17034
  }
17035
+ // ../core/src/app/history.ts
17036
+ /** The text of a row whose payload does not parse, or of a kind without a payload summary. */
17037
+ const EVENT_SUMMARIES = {
17038
+ head_moved: "Pull request head moved",
17039
+ pr_facts_changed: "Pull request facts changed",
17040
+ checks_changed: "Checks changed",
17041
+ review_submitted: "Review submitted",
17042
+ mergeable_changed: "Mergeability changed",
17043
+ pr_state_changed: "Pull request state changed",
17044
+ ticket_status_changed: "Ticket status changed",
17045
+ ticket_facts_changed: "Ticket facts changed",
17046
+ session_state_changed: "Session state changed",
17047
+ session_facts_changed: "Session facts changed",
17048
+ spur_unknown_state: "Unknown session state observed",
17049
+ link_added: "Link added",
17050
+ link_removed: "Link removed",
17051
+ task_added: "Task added",
17052
+ task_archived: "Task archived",
17053
+ task_submitted: "Turn submitted",
17054
+ task_moved: "Task moved",
17055
+ task_shadow_moved: "Shadow move",
17056
+ task_corrected: "Column corrected by the operator",
17057
+ dispatcher_mode_changed: "Dispatcher mode changed",
17058
+ turn_opened: "Turn opened",
17059
+ turn_taken: "Turn taken",
17060
+ turn_closed: "Turn closed",
17061
+ block_opened: "Block opened",
17062
+ block_escalated: "Block escalated",
17063
+ block_unblocked: "Block unblocked",
17064
+ comment_added: "Comment added",
17065
+ comment_edited: "Comment edited",
17066
+ comment_deleted: "Comment deleted",
17067
+ comment_acked: "Comment acknowledged",
17068
+ doorbell_rung: "Doorbell rung",
17069
+ doorbell_read: "Doorbell read",
17070
+ doorbell_undelivered: "Doorbell delivery exhausted",
17071
+ inbound_failed: "Inbound message failed",
17072
+ inbound_skipped: "Inbound message skipped",
17073
+ from_you_raised: "Operator item raised",
17074
+ from_you_cleared: "Operator item cleared",
17075
+ flag_raised: "Flag raised",
17076
+ flag_cleared: "Flag cleared",
17077
+ operation_denied: "Operation denied",
17078
+ token_requested: "Token requested",
17079
+ token_approved: "Token approved",
17080
+ token_denied: "Token denied",
17081
+ token_expired: "Token expired",
17082
+ token_revoked: "Token revoked"
17083
+ };
17084
+ /** How many changes a facts row names before `+N more`. */
17085
+ const NAMED_CHANGES = 3;
17086
+ /**
17087
+ * Fields a facts row never names, per kind: heartbeats (`updatedAt`, `lastActivityAt`), and
17088
+ * fields an own event row already says (`head_moved`, `checks_changed`, `ticket_status_changed`
17089
+ * and the rest), or that only time one (`healthSince`).
17090
+ */
17091
+ const UNNAMED = {
17092
+ pr: /* @__PURE__ */ new Set([
17093
+ "updatedAt",
17094
+ "headSha",
17095
+ "checks",
17096
+ "requiredChecks",
17097
+ "state",
17098
+ "mergeable",
17099
+ "reviews",
17100
+ "mergedAt",
17101
+ "closedAt"
17102
+ ]),
17103
+ session: /* @__PURE__ */ new Set(["lastActivityAt", "healthSince"]),
17104
+ ticket: /* @__PURE__ */ new Set(["updatedAt", "status"])
17105
+ };
17106
+ const FIELDS = {
17107
+ pr: prFactsSchema.keyof().options,
17108
+ session: sessionFactsSchema.keyof().options,
17109
+ ticket: ticketFactsSchema.keyof().options
17110
+ };
17111
+ const checksSchema = z.tuple([prFactsSchema.shape.checks, prFactsSchema.shape.requiredChecks]);
17112
+ function payloadOf(kind, payloadText) {
17113
+ const payload = eventPayloadSchemas[kind].safeParse(parsedJson(payloadText));
17114
+ return payload.success ? payload.data : null;
17115
+ }
17116
+ function parsedJson(text) {
17117
+ try {
17118
+ return JSON.parse(text);
17119
+ } catch {
17120
+ return;
17121
+ }
17122
+ }
17123
+ /** ` +N more` for the items past the first `NAMED_CHANGES` of `count`. */
17124
+ const more = (count) => count > NAMED_CHANGES ? ` +${String(count - NAMED_CHANGES)} more` : "";
17125
+ const ref = (repo, pr) => `${repo}#${String(pr)}`;
17126
+ const from = (value, to) => value === null || value === to ? to : `${value} → ${to}`;
17127
+ const label = (field) => field.replace(/[A-Z]/g, (letter) => ` ${letter.toLowerCase()}`);
17128
+ const shown = (value) => value === null || value === void 0 ? "none" : typeof value === "string" ? value : JSON.stringify(value);
17129
+ const endWords = (reason) => {
17130
+ const value = sessionFactsSchema.shape.endReason.safeParse(reason);
17131
+ return value.success && value.data !== null ? END_WORDS[value.data] : null;
17132
+ };
17133
+ function prEntity(facts) {
17134
+ return {
17135
+ kind: "pr",
17136
+ key: `pr:${facts.repo.toLowerCase()}#${String(facts.number)}`,
17137
+ prefix: `PR ${ref(facts.repo, facts.number)}`,
17138
+ facts
17139
+ };
17140
+ }
17141
+ function sessionEntity(facts) {
17142
+ return {
17143
+ kind: "session",
17144
+ key: `session:${facts.id}`,
17145
+ prefix: `Session ${facts.id}`,
17146
+ facts
17147
+ };
17148
+ }
17149
+ /** The entity a facts row or a link with facts carries, or null for any other row. */
17150
+ function factsEntity(kind, payloadText) {
17151
+ if (kind === "pr_facts_changed") {
17152
+ const payload = payloadOf(kind, payloadText);
17153
+ return payload === null ? null : prEntity(payload.facts);
17154
+ }
17155
+ if (kind === "session_facts_changed") {
17156
+ const payload = payloadOf(kind, payloadText);
17157
+ return payload === null ? null : sessionEntity(payload.facts);
17158
+ }
17159
+ if (kind === "ticket_facts_changed") {
17160
+ const payload = payloadOf(kind, payloadText);
17161
+ if (payload === null) return null;
17162
+ const { facts } = payload;
17163
+ return {
17164
+ kind: "ticket",
17165
+ key: `ticket:${facts.trackerId}:${facts.id}`,
17166
+ prefix: `Ticket ${facts.key}`,
17167
+ facts
17168
+ };
17169
+ }
17170
+ if (kind === "link_added") {
17171
+ const payload = payloadOf(kind, payloadText);
17172
+ if (payload?.entity === "pr" && payload.facts !== void 0) return prEntity(payload.facts);
17173
+ if (payload?.entity === "session" && payload.facts !== void 0) return sessionEntity(payload.facts);
17174
+ }
17175
+ return null;
17176
+ }
17177
+ /** One changed field in the words of a history row. */
17178
+ function changeText(field, before, after) {
17179
+ const name = label(field);
17180
+ switch (field) {
17181
+ case "draft": return after === true ? "ready → draft" : "draft → ready";
17182
+ case "feedbackComplete": return after === true ? "feedback complete" : "feedback incomplete";
17183
+ case "inFilter": return after === true ? "in filter" : "out of filter";
17184
+ case "endReason": {
17185
+ const words = endWords(after);
17186
+ return words === null ? "end cleared" : `ended (${words})`;
17187
+ }
17188
+ case "reviewThreads": {
17189
+ const unresolved = (value) => {
17190
+ const threads = prFactsSchema.shape.reviewThreads.safeParse(value);
17191
+ return threads.success ? threads.data.filter((thread) => !thread.resolved).length : 0;
17192
+ };
17193
+ const [a, b] = [unresolved(before), unresolved(after)];
17194
+ return a === b ? "threads changed" : `unresolved threads ${String(a)} → ${String(b)}`;
17195
+ }
17196
+ case "pr": {
17197
+ const pr = (value) => {
17198
+ const linked = sessionFactsSchema.shape.pr.safeParse(value);
17199
+ return linked.success && linked.data !== null ? ref(linked.data.repo, linked.data.number) : "none";
17200
+ };
17201
+ return `PR ${pr(before)} → ${pr(after)}`;
17202
+ }
17203
+ case "title":
17204
+ case "url": return `${name} changed`;
17205
+ }
17206
+ if (Array.isArray(before) || Array.isArray(after)) {
17207
+ const length = (value) => Array.isArray(value) ? String(value.length) : "none";
17208
+ return length(before) === length(after) ? `${name} changed` : `${name} ${length(before)} → ${length(after)}`;
17209
+ }
17210
+ const object = (value) => typeof value === "object" && value !== null;
17211
+ if (object(before) || object(after)) return `${name} changed`;
17212
+ return `${name} ${shown(before)} → ${shown(after)}`;
17213
+ }
17214
+ /**
17215
+ * The summary of a facts row against the entity's previous facts on this task, or null when it
17216
+ * changes nothing a row names.
17217
+ */
17218
+ function factsSummary(entity, previous) {
17219
+ if (previous === void 0) return `${entity.prefix}: first observed`;
17220
+ const unnamed = UNNAMED[entity.kind];
17221
+ const changed = FIELDS[entity.kind].filter((field) => !unnamed.has(field) && JSON.stringify(previous[field]) !== JSON.stringify(entity.facts[field]));
17222
+ const named = changed.includes("endReason") ? changed.filter((field) => field !== "endedAt") : changed;
17223
+ if (named.length === 0) return null;
17224
+ const texts = named.slice(0, NAMED_CHANGES).map((field) => changeText(field, previous[field], entity.facts[field]));
17225
+ return `${entity.prefix}: ${texts.join(", ")}${more(named.length)}`;
17226
+ }
17227
+ /** `Checks on <ref>:` with the failed names, or the green and pending counts. */
17228
+ function checksSummary(payload) {
17229
+ const lists = checksSchema.safeParse(parsedJson(payload.to));
17230
+ if (!lists.success) return null;
17231
+ const [checks, requiredChecks] = lists.data;
17232
+ const list = requiredChecks.length > 0 ? requiredChecks : checks.filter((check) => check.state !== "skipped");
17233
+ const head = `Checks on ${ref(payload.repo, payload.pr)}`;
17234
+ if (list.length === 0) return `${head}: none`;
17235
+ const failed = list.filter((check) => VERDICT[check.state] === "red").map(({ name }) => name);
17236
+ if (failed.length > 0) return `${head}: ${String(failed.length)} failed: ${failed.slice(0, NAMED_CHANGES).join(", ")}${more(failed.length)}`;
17237
+ const green = list.filter((check) => VERDICT[check.state] === "green").length;
17238
+ const pending = list.length - green;
17239
+ return `${head}: ${String(green)}/${String(list.length)} green${pending > 0 ? `, ${String(pending)} pending` : ""}`;
17240
+ }
17241
+ const gates = (gate) => gate === void 0 || gate.length === 0 ? "" : ` (${gate.join(", ")})`;
17242
+ const optional = (prefix, value) => value === void 0 ? "" : `${prefix}${value}`;
17243
+ /** Summaries built from a row's payload; null falls back to the fixed text. */
17244
+ const SUMMARIES = {
17245
+ session_state_changed: (p) => `Session ${p.session}: ${from(p.from, p.to)}${optional(", ended (", p.endReason === void 0 ? void 0 : `${END_WORDS[p.endReason]})`)}`,
17246
+ checks_changed: checksSummary,
17247
+ head_moved: (p) => `New head ${p.to.slice(0, 7)} on ${ref(p.repo, p.pr)}`,
17248
+ mergeable_changed: (p) => `Mergeable on ${ref(p.repo, p.pr)}: ${from(p.from, p.to)}`,
17249
+ pr_state_changed: (p) => `PR ${ref(p.repo, p.pr)}: ${from(p.from, p.to)}`,
17250
+ ticket_status_changed: (p) => `Ticket status: ${from(p.from, p.to)}`,
17251
+ review_submitted: (p) => `Review by ${p.reviewer} on ${ref(p.repo, p.pr)}: ${p.state}`,
17252
+ task_moved: (p) => `Moved ${p.from} → ${p.to}${optional(": ", p.reason)}${gates(p.gate)}`,
17253
+ task_shadow_moved: (p) => `Would move ${p.from} → ${p.to} (shadow mode): ${p.reason}${gates(p.gate)}${p.courseCheck === true ? ", with a course check" : ""}`,
17254
+ block_opened: (p) => `Block ${p.block} opened: ${p.type} for ${p.addressee}`,
17255
+ block_escalated: (p) => `Block ${p.block} escalated from ${p.from} to ${p.to}${optional(": ", p.reason)}`,
17256
+ block_unblocked: (p) => `Block ${p.block} unblocked: ${p.outcome}${optional(", ", p.reason)}`,
17257
+ comment_added: (p) => `Comment ${p.comment} for ${p.addressee}${optional(", forwarded from ", p.forwardedFrom)}`,
17258
+ comment_edited: (p) => `Comment ${p.comment} edited, revision ${String(p.revision)}${p.clarification ? ", clarification" : ""}`,
17259
+ comment_deleted: (p) => `Comment ${p.comment} deleted`,
17260
+ comment_acked: (p) => `Comment ${p.comment} acknowledged`,
17261
+ doorbell_rung: (p) => `Doorbell rung: ${p.doorbell} for ${p.addressee}, attempt ${String(p.attempt)}`,
17262
+ doorbell_read: (p) => `Doorbell read: ${p.doorbell}`,
17263
+ doorbell_undelivered: (p) => `Doorbell delivery exhausted: ${p.doorbell}, ${p.reason}`,
17264
+ link_added: (p) => linkSummary("Link added", p),
17265
+ link_removed: (p) => linkSummary("Link removed", p),
17266
+ task_submitted: (p) => {
17267
+ if (p.supersededByMerge !== void 0) return `Submit of ${p.sha.slice(0, 7)} superseded: PR merged at ${p.supersededByMerge.slice(0, 7)}`;
17268
+ if (p.pending === true) return "Turn submitted, pending confirmation";
17269
+ return p.confirmedByPoll === true ? "Turn submitted on the head of the last poll" : null;
17270
+ }
17271
+ };
17272
+ function linkSummary(verb, p) {
17273
+ const target = p.entity === "pr" ? ref(p.repo, p.pr) : p.entity === "session" ? p.session : p.ticket;
17274
+ return `${verb}: ${p.entity} ${target}${optional(" — ", p.reason)}`;
17275
+ }
17276
+ function summaryOf(kind) {
17277
+ return SUMMARIES[kind];
17278
+ }
17279
+ /** The summary built from a row's payload, or null to fall back to the fixed text. */
17280
+ function payloadSummary(kind, payloadText) {
17281
+ const summarize = summaryOf(kind);
17282
+ if (summarize === void 0) return turnSummary(kind, payloadText);
17283
+ const payload = payloadOf(kind, payloadText);
17284
+ return payload === null ? null : summarize(payload);
17285
+ }
17286
+ /**
17287
+ * The rows `task.history` shows for a task's events, read in journal order: each with a summary of
17288
+ * what changed, facts rows diffed against the entity's previous facts on the task. A facts row with
17289
+ * nothing to name is left out but still moves the baseline. Rows come back by time, then journal
17290
+ * order.
17291
+ */
17292
+ function historyEvents(rows) {
17293
+ const previous = /* @__PURE__ */ new Map();
17294
+ return rows.flatMap((row) => {
17295
+ const kind = EVENT_KINDS.find((candidate) => candidate === row.kind);
17296
+ if (kind === void 0) return [];
17297
+ const entity = factsEntity(kind, row.payload);
17298
+ let summary;
17299
+ if (entity !== null && kind !== "link_added") {
17300
+ const text = factsSummary(entity, previous.get(entity.key));
17301
+ previous.set(entity.key, entity.facts);
17302
+ if (text === null) return [];
17303
+ summary = text;
17304
+ } else {
17305
+ if (entity !== null) previous.set(entity.key, entity.facts);
17306
+ summary = payloadSummary(kind, row.payload);
17307
+ }
17308
+ const via = VIAS.find((value) => value === row.via);
17309
+ return [{
17310
+ id: row.id,
17311
+ time: Date.parse(row.at),
17312
+ event: {
17313
+ at: row.at,
17314
+ kind,
17315
+ actor: eventActor(row),
17316
+ ...via === void 0 ? {} : { via },
17317
+ summary: (summary ?? EVENT_SUMMARIES[kind]).replace(/\s+/g, " ").trim()
17318
+ }
17319
+ }];
17320
+ }).sort((left, right) => left.time - right.time || left.id - right.id).map(({ event }) => event);
17321
+ }
17035
17322
  // ../core/src/app/task-sessions.ts
17036
17323
  /** Current facts of the effective session links that task.get exposes. */
17037
17324
  async function taskSessions(trx, taskId) {
@@ -17096,96 +17383,6 @@ const WAITING_FOR = {
17096
17383
  mergeable_unknown: "waiting for GitHub to compute mergeability",
17097
17384
  comment_history_incomplete: "waiting for the board to read the full PR comment history"
17098
17385
  };
17099
- const EVENT_SUMMARIES = {
17100
- head_moved: "Pull request head moved",
17101
- pr_facts_changed: "Pull request facts changed",
17102
- checks_changed: "Checks changed",
17103
- review_submitted: "Review submitted",
17104
- mergeable_changed: "Mergeability changed",
17105
- pr_state_changed: "Pull request state changed",
17106
- ticket_status_changed: "Ticket status changed",
17107
- ticket_facts_changed: "Ticket facts changed",
17108
- session_state_changed: "Session state changed",
17109
- session_facts_changed: "Session facts changed",
17110
- spur_unknown_state: "Unknown session state observed",
17111
- link_added: "Link added",
17112
- link_removed: "Link removed",
17113
- task_added: "Task added",
17114
- task_archived: "Task archived",
17115
- task_submitted: "Turn submitted",
17116
- task_moved: "Task moved",
17117
- task_shadow_moved: "Shadow move",
17118
- task_corrected: "Column corrected by the operator",
17119
- dispatcher_mode_changed: "Dispatcher mode changed",
17120
- turn_opened: "Turn opened",
17121
- turn_taken: "Turn taken",
17122
- turn_closed: "Turn closed",
17123
- block_opened: "Block opened",
17124
- block_escalated: "Block escalated",
17125
- block_unblocked: "Block unblocked",
17126
- comment_added: "Comment added",
17127
- comment_edited: "Comment edited",
17128
- comment_deleted: "Comment deleted",
17129
- comment_acked: "Comment acknowledged",
17130
- doorbell_rung: "Doorbell rung",
17131
- doorbell_read: "Doorbell read",
17132
- doorbell_undelivered: "Doorbell delivery exhausted",
17133
- inbound_failed: "Inbound message failed",
17134
- inbound_skipped: "Inbound message skipped",
17135
- from_you_raised: "Operator item raised",
17136
- from_you_cleared: "Operator item cleared",
17137
- flag_raised: "Flag raised",
17138
- flag_cleared: "Flag cleared",
17139
- operation_denied: "Operation denied",
17140
- token_requested: "Token requested",
17141
- token_approved: "Token approved",
17142
- token_denied: "Token denied",
17143
- token_expired: "Token expired",
17144
- token_revoked: "Token revoked"
17145
- };
17146
- function linkOrEscalationSummary(kind, payloadText) {
17147
- if (kind !== "link_added" && kind !== "link_removed" && kind !== "block_escalated") return null;
17148
- try {
17149
- if (kind === "block_escalated") {
17150
- const payload = eventPayloadSchemas[kind].safeParse(JSON.parse(payloadText));
17151
- if (!payload.success || payload.data.reason !== "asker_is_addressee") return null;
17152
- return `Block ${payload.data.block} escalated from ${payload.data.from} to ${payload.data.to}: ${payload.data.reason}`;
17153
- }
17154
- const payload = eventPayloadSchemas[kind].safeParse(JSON.parse(payloadText));
17155
- if (!payload.success) return null;
17156
- const target = payload.data.entity === "pr" ? `${payload.data.repo}#${String(payload.data.pr)}` : payload.data.entity === "session" ? payload.data.session : payload.data.ticket;
17157
- return `${kind === "link_added" ? "Link added" : "Link removed"}: ${payload.data.entity} ${target}${payload.data.reason === void 0 ? "" : ` — ${payload.data.reason}`}`;
17158
- } catch {
17159
- return null;
17160
- }
17161
- }
17162
- /** The summary of a shadow move that reached its column's course check. */
17163
- function shadowSummary(kind, payloadText) {
17164
- if (kind !== "task_shadow_moved") return null;
17165
- try {
17166
- const payload = eventPayloadSchemas[kind].safeParse(JSON.parse(payloadText));
17167
- return payload.success && payload.data.courseCheck === true ? "Shadow move with a course check" : null;
17168
- } catch {
17169
- return null;
17170
- }
17171
- }
17172
- /**
17173
- * The summary of a submit whose head the board's newest poll confirmed, that waits for one, or
17174
- * that a merge at another head superseded.
17175
- */
17176
- function submitSummary(kind, payloadText) {
17177
- if (kind !== "task_submitted") return null;
17178
- try {
17179
- const payload = eventPayloadSchemas[kind].safeParse(JSON.parse(payloadText));
17180
- if (!payload.success) return null;
17181
- const merged = payload.data.supersededByMerge;
17182
- if (merged !== void 0) return `Submit of ${payload.data.sha.slice(0, 7)} superseded: PR merged at ${merged.slice(0, 7)}`;
17183
- if (payload.data.pending === true) return "Turn submitted, pending confirmation";
17184
- return payload.data.confirmedByPoll === true ? "Turn submitted on the head of the last poll" : null;
17185
- } catch {
17186
- return null;
17187
- }
17188
- }
17189
17386
  function visibleProjects(config, actor) {
17190
17387
  return new Set(config.projects.filter((project) => authorize([{ grant: "operator" }, { grant: "project-agent" }], actor, {
17191
17388
  config,
@@ -17319,21 +17516,10 @@ function createTaskQueries(deps) {
17319
17516
  resolveTargets: (trx, input) => taskTarget(trx, taskKey(input.task)),
17320
17517
  async run(trx, input) {
17321
17518
  const task = await taskByKey(trx, taskKey(input.task));
17322
- const events = (await trx.selectFrom("event").selectAll().where("task_id", "=", task.id).orderBy("id").execute()).flatMap((row) => {
17323
- const kind = EVENT_KINDS.find((candidate) => candidate === row.kind);
17324
- if (kind === void 0) return [];
17325
- const via = VIAS.find((value) => value === row.via);
17326
- return [{
17327
- at: row.at,
17328
- kind,
17329
- actor: eventActor(row),
17330
- ...via === void 0 ? {} : { via },
17331
- summary: linkOrEscalationSummary(kind, row.payload) ?? shadowSummary(kind, row.payload) ?? submitSummary(kind, row.payload) ?? turnSummary(kind, row.payload) ?? EVENT_SUMMARIES[kind]
17332
- }];
17333
- });
17519
+ const rows = await trx.selectFrom("event").selectAll().where("task_id", "=", task.id).orderBy("id").execute();
17334
17520
  return {
17335
17521
  task: taskView(task),
17336
- events
17522
+ events: historyEvents(rows)
17337
17523
  };
17338
17524
  }
17339
17525
  };
@@ -18272,21 +18458,21 @@ async function ticket(trx, config, fact, at, source) {
18272
18458
  }).where("id", "=", task.id).execute();
18273
18459
  const previous = await trx.selectFrom("ticket_snapshot").selectAll().where("task_id", "=", task.id).executeTakeFirst();
18274
18460
  const previousFact = previous === void 0 ? null : parseJson(ticketFactsSchema, previous.detail);
18275
- if (previousFact === null || JSON.stringify(previousFact) !== JSON.stringify(fact)) {
18276
- await trx.insertInto("ticket_snapshot").values({
18277
- task_id: task.id,
18278
- status: fact.status,
18279
- assignee: fact.assignee,
18280
- detail: toJson(ticketFactsSchema, fact),
18281
- source,
18282
- observed_at: at
18283
- }).onConflict((oc) => oc.column("task_id").doUpdateSet({
18284
- status: fact.status,
18285
- assignee: fact.assignee,
18286
- detail: toJson(ticketFactsSchema, fact),
18287
- source,
18288
- observed_at: at
18289
- })).execute();
18461
+ await trx.insertInto("ticket_snapshot").values({
18462
+ task_id: task.id,
18463
+ status: fact.status,
18464
+ assignee: fact.assignee,
18465
+ detail: toJson(ticketFactsSchema, fact),
18466
+ source,
18467
+ observed_at: at
18468
+ }).onConflict((oc) => oc.column("task_id").doUpdateSet({
18469
+ status: fact.status,
18470
+ assignee: fact.assignee,
18471
+ detail: toJson(ticketFactsSchema, fact),
18472
+ source,
18473
+ observed_at: at
18474
+ })).execute();
18475
+ if (previousFact === null || comparableFacts(previousFact, "updatedAt") !== comparableFacts(fact, "updatedAt")) {
18290
18476
  if (previousFact?.status !== fact.status) {
18291
18477
  await emit(trx, "ticket_status_changed", project.id, task.id, at, {
18292
18478
  from: previousFact?.status ?? null,
@@ -18296,7 +18482,7 @@ async function ticket(trx, config, fact, at, source) {
18296
18482
  }
18297
18483
  await emit(trx, "ticket_facts_changed", project.id, task.id, at, { facts: fact });
18298
18484
  await trx.updateTable("task").set({ last_change_at: at }).where("id", "=", task.id).execute();
18299
- } else await trx.updateTable("ticket_snapshot").set({ observed_at: at }).where("task_id", "=", task.id).execute();
18485
+ }
18300
18486
  if (fact.inFilter && (task.membership === "out_of_filter" || task.archive_reason === "out_of_filter")) {
18301
18487
  await trx.updateTable("task").set({
18302
18488
  membership: "active",
@@ -18307,6 +18493,10 @@ async function ticket(trx, config, fact, at, source) {
18307
18493
  }
18308
18494
  if (previousKey !== fact.key || previousMembership === "archived") await reconcileTaskPrs(trx, config, task.id, at);
18309
18495
  }
18496
+ /** Only these top-level refresh timestamps are immaterial to the journal. */
18497
+ function comparableFacts(facts, timestamp) {
18498
+ return JSON.stringify(Object.fromEntries(Object.entries(facts).filter(([key]) => key !== timestamp)));
18499
+ }
18310
18500
  async function pr(trx, config, fact, at, source) {
18311
18501
  await trx.deleteFrom("source_miss").where("source", "=", source).where("ref_key", "=", refKey({
18312
18502
  kind: "pr",
@@ -18318,7 +18508,7 @@ async function pr(trx, config, fact, at, source) {
18318
18508
  const recheckAt = fact.state === "closed" ? new Date(Date.parse(at) + 216e5).toISOString() : null;
18319
18509
  if (old !== void 0 && previous !== null && old.source !== source) await savePrPolling(trx, old.source, previous, old.closed_recheck_at, true);
18320
18510
  await savePrPolling(trx, source, fact, recheckAt);
18321
- const changed = previous === null || JSON.stringify(previous) !== JSON.stringify(fact);
18511
+ const changed = previous === null || comparableFacts(previous, "updatedAt") !== comparableFacts(fact, "updatedAt");
18322
18512
  await trx.insertInto("pr_snapshot").values({
18323
18513
  repo: old?.repo ?? fact.repo,
18324
18514
  number: fact.number,
@@ -18478,7 +18668,7 @@ async function sessionTransition(trx, config, edge) {
18478
18668
  async function session(trx, config, fact, at, source, ambiguousBranches, feedEnabled) {
18479
18669
  const old = await trx.selectFrom("session_snapshot").selectAll().where("id", "=", fact.id).executeTakeFirst();
18480
18670
  const previous = old === void 0 ? null : parseJson(sessionFactsSchema, old.detail);
18481
- const changed = previous === null || JSON.stringify(previous) !== JSON.stringify(fact);
18671
+ const changed = previous === null || comparableFacts(previous, "lastActivityAt") !== comparableFacts(fact, "lastActivityAt");
18482
18672
  await trx.insertInto("session_snapshot").values({
18483
18673
  id: fact.id,
18484
18674
  spur_project: fact.spurProject,
@@ -18833,9 +19023,8 @@ function createObservationCore(deps) {
18833
19023
  if (entity.ref.kind !== "session" || entity.status !== "not_found") continue;
18834
19024
  const old = await trx.selectFrom("session_snapshot").selectAll().where("id", "=", entity.ref.id).executeTakeFirst();
18835
19025
  if (old === void 0 || old.ended_at !== null) continue;
18836
- const fact = parseJson(sessionFactsSchema, old.detail);
18837
19026
  const ended = {
18838
- ...fact,
19027
+ ...parseJson(sessionFactsSchema, old.detail),
18839
19028
  endedAt: batch.observedAt,
18840
19029
  endReason: "vanished"
18841
19030
  };
@@ -18848,12 +19037,6 @@ function createObservationCore(deps) {
18848
19037
  const links = await trx.selectFrom("link").select(["task_id"]).where("entity", "=", "session").where("session_id", "=", old.id).execute();
18849
19038
  for (const link of links) {
18850
19039
  const task = await trx.selectFrom("task").selectAll().where("id", "=", link.task_id).executeTakeFirstOrThrow();
18851
- await emit(trx, "session_state_changed", task.project, task.id, batch.observedAt, {
18852
- session: old.id,
18853
- from: fact.lifecycle,
18854
- to: fact.lifecycle,
18855
- endReason: "vanished"
18856
- });
18857
19040
  await emit(trx, "session_facts_changed", task.project, task.id, batch.observedAt, { facts: ended });
18858
19041
  }
18859
19042
  }
package/dist/mcp.mjs CHANGED
@@ -1,6 +1,6 @@
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";
1
+ import { et as ERRORS, p as OPERATIONS, v as renderMcpError } from "./chunk-BzwnMm9i.mjs";
2
+ import { o as CliError, r as requestOperation } from "./chunk-BM_rDrEG.mjs";
3
+ import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./chunk-CZ4l7_un.mjs";
4
4
  import { randomUUID } from "node:crypto";
5
5
  import { readFileSync } from "node:fs";
6
6
  import { z } from "zod";