spur-board 0.53.1 → 0.53.3

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-DyHtyPom.mjs";
1
+ import { $ as errorEnvelopeSchema, Q as errorContextSchema, S as renderJsonError, X as ERRORS, c as tokenRequestStatusSchema, o as tokenRequestResultSchema, tt as successEnvelopeSchema } from "./chunk-DuSucVv4.mjs";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { z } from "zod";
4
4
  import { request } from "node:http";
@@ -1,5 +1,5 @@
1
- import { _ as buildCatalogSnapshot, ct as plainHttpAllowed, st as configSchema, y as OPERATIONS } from "./chunk-DyHtyPom.mjs";
2
- import { o as CliError, t as fetchCatalogVersion } from "./chunk-Z9DFhl-U.mjs";
1
+ import { _ as buildCatalogSnapshot, ct as plainHttpAllowed, st as configSchema, y as OPERATIONS } from "./chunk-DuSucVv4.mjs";
2
+ import { o as CliError, t as fetchCatalogVersion } from "./chunk-B81O9UQo.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";
@@ -1394,7 +1394,9 @@ const eventPayloadSchemas = {
1394
1394
  task_submitted: z.looseObject({
1395
1395
  turn: S.optional(),
1396
1396
  column: z.enum(COLUMN_IDS),
1397
- sha: S
1397
+ sha: S,
1398
+ /** The head was confirmed by the board's newest poll; GitHub did not answer the submit. */
1399
+ confirmedByPoll: z.literal(true).optional()
1398
1400
  }),
1399
1401
  task_moved: z.looseObject({
1400
1402
  from: z.enum(COLUMN_IDS),
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-DyHtyPom.mjs";
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-DuSucVv4.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-Z9DFhl-U.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-BbwZCNQh.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-B81O9UQo.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-DSGruS1f.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-Z9DFhl-U.mjs";
1
+ import { a as requestTokenEnrollment, i as requestSkillReload, n as fetchTokenStatus, r as requestOperation, t as fetchCatalogVersion } from "./chunk-B81O9UQo.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-DyHtyPom.mjs";
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-DuSucVv4.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";
@@ -9129,7 +9129,7 @@ async function blockPost(trx, row, payload, rule) {
9129
9129
  await raiseItemWith(trx, {
9130
9130
  itemKey: `secret-post:${createHash("sha256").update(row.dedupeKey).digest("hex")}`,
9131
9131
  kind: "post_blocked",
9132
- text: `text on ${safeKey} not sent: looks like a secret (${rule}), read \`board task ${safeKey}\``,
9132
+ text: `text on ${safeKey} not sent: looks like a secret (${rule}), read board task ${safeKey}`,
9133
9133
  url: task === null ? "" : taskUrl(task, scanConfig()),
9134
9134
  taskId,
9135
9135
  blockId,
@@ -10520,7 +10520,7 @@ async function postTokenList(trx, input) {
10520
10520
  }
10521
10521
  const shown = rows.slice(0, lines.length);
10522
10522
  const hidden = rows.length - shown.length;
10523
- if (hidden > 0) lines.push(`${String(hidden)} more: \`board token list\``);
10523
+ if (hidden > 0) lines.push(`${String(hidden)} more: board token list`);
10524
10524
  await enqueueBoardFeedLine(trx, {
10525
10525
  dedupeKey: `feed.line:token-list:${input.key}`,
10526
10526
  itemKey: `token-list:${input.key}`,
@@ -14822,6 +14822,16 @@ function shadowSummary(kind, payloadText) {
14822
14822
  return null;
14823
14823
  }
14824
14824
  }
14825
+ /** The summary of a submit whose head the board's newest poll confirmed. */
14826
+ function submitSummary(kind, payloadText) {
14827
+ if (kind !== "task_submitted") return null;
14828
+ try {
14829
+ const payload = eventPayloadSchemas[kind].safeParse(JSON.parse(payloadText));
14830
+ return payload.success && payload.data.confirmedByPoll === true ? "Turn submitted on the head of the last poll" : null;
14831
+ } catch {
14832
+ return null;
14833
+ }
14834
+ }
14825
14835
  function projectTarget(project) {
14826
14836
  return {
14827
14837
  kind: "found",
@@ -14945,7 +14955,7 @@ function createTaskQueries(deps) {
14945
14955
  at: row.at,
14946
14956
  kind,
14947
14957
  actor: eventActor(row),
14948
- summary: linkSummary(kind, row.payload) ?? shadowSummary(kind, row.payload) ?? EVENT_SUMMARIES[kind]
14958
+ summary: linkSummary(kind, row.payload) ?? shadowSummary(kind, row.payload) ?? submitSummary(kind, row.payload) ?? EVENT_SUMMARIES[kind]
14949
14959
  }];
14950
14960
  });
14951
14961
  return {
@@ -15131,25 +15141,49 @@ async function takenTurn(trx, id, ctx) {
15131
15141
  task
15132
15142
  };
15133
15143
  }
15144
+ /** Ends a hint for a refusal that a later submit cannot fix. */
15145
+ const noRepeat = (step) => `repeating will not help; ask the operator to ${step}.`;
15146
+ /** The next step for an on-demand poll that answered nothing. */
15134
15147
  function pollErrorHint(error, pr) {
15135
15148
  switch (error.kind) {
15136
- case "timeout": return `GitHub did not answer for ${pr} within ${String(SUBMIT_POLL_TIMEOUT_MS / 1e3)} s; wait, then submit again.`;
15137
- case "blind": return `The board cannot read ${pr} (${error.reason}); ask the operator to fix the GitHub access, then submit again.`;
15138
- case "failed": return error.retryAt === void 0 ? `The GitHub poll of ${pr} failed (${error.adapterKind}); wait, then submit again.` : `GitHub is throttled until ${error.retryAt}; submit again after that.`;
15149
+ case "timeout": return `GitHub did not answer for ${pr} within ${String(SUBMIT_POLL_TIMEOUT_MS / 1e3)} s; wait a minute, then submit again.`;
15150
+ case "blind": return error.reason === "stale" ? `The board has no recent complete GitHub poll for ${pr}; submit again in a few minutes, once GitHub answers its polls.` : `The board cannot read ${pr} (${error.reason}); ${noRepeat("fix the GitHub access")}`;
15151
+ case "failed":
15152
+ if (error.adapterKind === "auth" || error.adapterKind === "config") return `The board cannot read ${pr} (${error.adapterKind}); ${noRepeat("fix the GitHub access")}`;
15153
+ return error.retryAt === void 0 ? `The GitHub poll of ${pr} failed (${error.adapterKind}); wait a minute, then submit again.` : `GitHub is throttled until ${error.retryAt}; submit again after that.`;
15139
15154
  case "stopped": return "The GitHub poller is not running; submit again once the daemon is up.";
15140
- case "unknown_source": return `The repo of ${pr} is not in the project's repos; ask the operator to add it to the config.`;
15141
- case "unsupported": return "This daemon cannot poll a pull request on demand; ask the operator to update the daemon.";
15155
+ case "unknown_source": return `The repo of ${pr} is not in the project's repos; ${noRepeat("add it to the config")}`;
15156
+ case "unsupported": return `This daemon cannot poll a pull request on demand; ${noRepeat("update the daemon")}`;
15142
15157
  }
15143
15158
  }
15144
- /** Throws `github_unavailable` unless `prepared` is a successful poll of this PR. */
15145
- function confirmPolled(prepared, pr) {
15159
+ /** True when GitHub gave no answer this call and the last poll may stand in for it. */
15160
+ function pollMayConfirm(error) {
15161
+ return error.kind === "timeout" || error.kind === "failed" && (error.adapterKind === "transient" || error.adapterKind === "unexpected" || error.adapterKind === "throttled");
15162
+ }
15163
+ /**
15164
+ * How the PR head behind a submit is confirmed: `live` by this call's poll, `poll` by the
15165
+ * board's newest poll when GitHub did not answer. Throws `head_mismatch` when the confirmed head
15166
+ * is not `sha`, `github_unavailable` when nothing confirms it.
15167
+ */
15168
+ function confirmHead(input) {
15169
+ const { prepared, pr, sha, snapshot, completeAt } = input;
15146
15170
  const label = `${pr.repo}#${String(pr.number)}`;
15147
15171
  const unavailable = (hint) => new CommandError("github_unavailable", hint);
15148
15172
  if (prepared?.kind !== "polled" || prepared.repo !== pr.repo.toLowerCase() || prepared.number !== pr.number) throw unavailable(`The board did not poll ${label} for this call; submit again.`);
15149
15173
  const { result } = prepared;
15150
- if (result === null) throw unavailable("This daemon runs no GitHub poller; ask the operator to check the daemon.");
15151
- if (!result.ok) throw unavailable(pollErrorHint(result.error, label));
15152
- if (result.value.status !== "ok") throw unavailable(`GitHub answered ${result.value.status} for ${label}; ask the operator to check the board's GitHub access.`);
15174
+ if (result === null) throw unavailable(`This daemon runs no GitHub poller; ${noRepeat("check the daemon")}`);
15175
+ if (!result.ok) {
15176
+ const hint = pollErrorHint(result.error, label);
15177
+ if (!pollMayConfirm(result.error)) throw unavailable(hint);
15178
+ if (completeAt === void 0) throw unavailable(`${hint} The board has had no complete GitHub poll since it started.`);
15179
+ if (snapshot === void 0) throw unavailable(`${hint} The board has not seen the head of ${label} yet.`);
15180
+ if (Date.parse(snapshot.observed_at) < Date.parse(completeAt)) throw unavailable(`${hint} The board last saw head ${snapshot.head_sha} at ${snapshot.observed_at}, before its last complete GitHub poll.`);
15181
+ if (snapshot.head_sha.toLowerCase() !== sha) throw unavailable(`${hint} Its last poll saw head ${snapshot.head_sha}.`);
15182
+ return "poll";
15183
+ }
15184
+ if (result.value.status !== "ok") throw unavailable(`GitHub answered ${result.value.status} for ${label}; ${noRepeat("check the board's GitHub access")}`);
15185
+ if (snapshot?.head_sha.toLowerCase() !== sha) throw new CommandError("head_mismatch", `The head of ${label} is ${snapshot?.head_sha ?? "unknown"}; push the commit, then submit the head.`);
15186
+ return "live";
15153
15187
  }
15154
15188
  /** Polls the task's PR on demand for a submit; `skipped` when the task has none. */
15155
15189
  async function pollTaskPr(db, task, poll) {
@@ -15169,16 +15203,21 @@ async function pollTaskPr(db, task, poll) {
15169
15203
  };
15170
15204
  }
15171
15205
  /**
15172
- * Records the submit of `sha` for the task's `column` visit `epoch`. Throws `head_mismatch` or
15173
- * `github_unavailable` unless `sha` is the freshly polled PR head.
15206
+ * Records the submit of `sha` for the task's `column` visit `epoch` and says how its head was
15207
+ * confirmed (`confirmHead`). Throws `head_mismatch` or `github_unavailable` otherwise.
15174
15208
  */
15175
- async function insertSubmission(trx, input, ctx) {
15209
+ async function insertSubmission(trx, input, ctx, completeSince) {
15176
15210
  const { task, column, epoch, sha } = input;
15177
15211
  const pr = await taskPr(trx, task.id);
15178
15212
  if (pr === null) throw new CommandError("head_mismatch", "The task has no active pull request; ask the operator to link it with `board link`, then submit its head.");
15179
- confirmPolled(ctx.prepared, pr);
15180
- const snapshot = await trx.selectFrom("pr_snapshot").select("head_sha").where(sql`lower(repo) = ${pr.repo.toLowerCase()}`).where("number", "=", pr.number).executeTakeFirst();
15181
- if (snapshot?.head_sha.toLowerCase() !== sha) throw new CommandError("head_mismatch", `The head of ${pr.repo}#${String(pr.number)} is ${snapshot?.head_sha ?? "unknown"}; push the commit, then submit the head.`);
15213
+ const snapshot = await trx.selectFrom("pr_snapshot").select(["head_sha", "observed_at"]).where(sql`lower(repo) = ${pr.repo.toLowerCase()}`).where("number", "=", pr.number).executeTakeFirst();
15214
+ const confirmed = confirmHead({
15215
+ prepared: ctx.prepared,
15216
+ pr,
15217
+ sha,
15218
+ snapshot,
15219
+ completeAt: completeSince.get(prSourceId(task.project, pr.repo))
15220
+ });
15182
15221
  await trx.insertInto("submission").values({
15183
15222
  task_id: task.id,
15184
15223
  column,
@@ -15190,7 +15229,10 @@ async function insertSubmission(trx, input, ctx) {
15190
15229
  pr_repo: pr.repo,
15191
15230
  pr_number: pr.number
15192
15231
  }).execute();
15232
+ return confirmed;
15193
15233
  }
15234
+ /** The `task_submitted` payload mark of a head confirmed by the board's last poll. */
15235
+ const confirmation = (confirmed) => confirmed === "poll" ? { confirmedByPoll: true } : {};
15194
15236
  /**
15195
15237
  * The executor's submit and return of a turn it took, the turnless shadow submit, and the
15196
15238
  * operator's column correction.
@@ -15212,15 +15254,16 @@ function createTurnMutations(deps) {
15212
15254
  if (task.membership === "archived") throw new CommandError("task_archived", "Add the task again before changing it.");
15213
15255
  const column = shadowColumn(task);
15214
15256
  if (!await executesShadowColumn(trx, task, ctx.actor, config)) throw new CommandError("forbidden", `Only the executor of ${column} submits this task while the dispatcher is in shadow mode.`);
15215
- await insertSubmission(trx, {
15257
+ const confirmed = await insertSubmission(trx, {
15216
15258
  task,
15217
15259
  column,
15218
15260
  epoch: task.column_epoch,
15219
15261
  sha: input.sha
15220
- }, ctx);
15262
+ }, ctx, completeSince);
15221
15263
  await emit(trx, "task_submitted", task.project, task.id, ctx.at, {
15222
15264
  column,
15223
- sha: input.sha
15265
+ sha: input.sha,
15266
+ ...confirmation(confirmed)
15224
15267
  }, ctx.actor);
15225
15268
  return {
15226
15269
  task: taskView(await dispatched(trx, task.id, ctx.at)),
@@ -15247,12 +15290,12 @@ function createTurnMutations(deps) {
15247
15290
  async run(trx, input, ctx) {
15248
15291
  if (!isTurnId(input.turn)) return submitShadow(trx, input, ctx);
15249
15292
  const { turn, task } = await takenTurn(trx, input.turn, ctx);
15250
- await insertSubmission(trx, {
15293
+ const confirmed = await insertSubmission(trx, {
15251
15294
  task,
15252
15295
  column: turn.column,
15253
15296
  epoch: turn.epoch,
15254
15297
  sha: input.sha
15255
- }, ctx);
15298
+ }, ctx, completeSince);
15256
15299
  await closeTurns(trx, {
15257
15300
  taskId: task.id,
15258
15301
  reason: "submitted",
@@ -15261,7 +15304,8 @@ function createTurnMutations(deps) {
15261
15304
  await emit(trx, "task_submitted", task.project, task.id, ctx.at, {
15262
15305
  turn: input.turn,
15263
15306
  column: turn.column,
15264
- sha: input.sha
15307
+ sha: input.sha,
15308
+ ...confirmation(confirmed)
15265
15309
  }, ctx.actor);
15266
15310
  return {
15267
15311
  task: taskView(await dispatched(trx, task.id, ctx.at)),
@@ -19602,6 +19646,8 @@ function applyEntityOutcomes(input) {
19602
19646
  //#region ../adapters/src/runner/runner.ts
19603
19647
  /** The setTimeout limit: a longer delay would otherwise fire after 1 ms. */
19604
19648
  const MAX_TIMER_MS = 2147483647;
19649
+ /** Waits before the second and third attempt of an on-demand poll after a transient failure. */
19650
+ const DEMAND_RETRY_WAITS_MS = [1e3, 2e3];
19605
19651
  function startRunner(options) {
19606
19652
  const startedAt = options.now();
19607
19653
  const sources = options.entries.map((entry) => runSource(entry, options, startedAt));
@@ -19843,8 +19889,11 @@ function runSource(entry, options, runnerStartMs) {
19843
19889
  if (!options.oneShot) schedule(delay.delayMs);
19844
19890
  return outcome;
19845
19891
  }
19846
- /** One on-demand request at its turn on the chain; `live` is false once its caller left. */
19847
- async function demandTurn(ref, abort, live, observing) {
19892
+ /**
19893
+ * One on-demand request at its turn on the chain; `live` is false once its caller left.
19894
+ * `retryable` is called before it returns a `transient` failure of the `poll` step.
19895
+ */
19896
+ async function demandTurn(ref, abort, live, observing, retryable) {
19848
19897
  if (stopping) return err(stoppedError);
19849
19898
  if (!live()) return;
19850
19899
  const startMs = now();
@@ -19924,6 +19973,7 @@ function runSource(entry, options, runnerStartMs) {
19924
19973
  } catch (error) {
19925
19974
  if (aborted()) return err(stoppedError);
19926
19975
  fail(step, error);
19976
+ if (step === "poll" && error instanceof AdapterError && error.kind === "transient") retryable();
19927
19977
  const retryAt = throttledRetryAt(error);
19928
19978
  return err({
19929
19979
  kind: "failed",
@@ -19941,12 +19991,17 @@ function runSource(entry, options, runnerStartMs) {
19941
19991
  if (stopping) return Promise.resolve(err(stoppedError));
19942
19992
  return new Promise((resolve) => {
19943
19993
  const abort = new AbortController();
19994
+ const deadlineMs = now() + timeoutMs;
19944
19995
  let settled = false;
19945
19996
  let observing = false;
19997
+ let attempts = 0;
19998
+ let retryTimer;
19946
19999
  const settle = (result) => {
19947
20000
  if (settled) return;
19948
20001
  settled = true;
19949
20002
  clearTimeout(timer);
20003
+ clearTimeout(retryTimer);
20004
+ retryTimer = void 0;
19950
20005
  pending.delete(cancel);
19951
20006
  resolve(result);
19952
20007
  };
@@ -19964,12 +20019,27 @@ function runSource(entry, options, runnerStartMs) {
19964
20019
  }));
19965
20020
  abort.abort();
19966
20021
  }, timeoutMs);
19967
- run(async () => {
20022
+ const attempt = () => run(async () => {
20023
+ let retry = false;
20024
+ const transient = () => retry;
19968
20025
  const result = await demandTurn(ref, abort, () => !settled, () => {
19969
20026
  observing = true;
20027
+ }, () => {
20028
+ retry = true;
19970
20029
  });
19971
- if (result !== void 0) settle(result);
20030
+ if (result === void 0) return;
20031
+ const waitMs = DEMAND_RETRY_WAITS_MS[attempts];
20032
+ attempts += 1;
20033
+ if (transient() && waitMs !== void 0 && !settled && now() + waitMs < deadlineMs) {
20034
+ retryTimer = setTimeout(() => {
20035
+ retryTimer = void 0;
20036
+ attempt();
20037
+ }, waitMs);
20038
+ return;
20039
+ }
20040
+ settle(result);
19972
20041
  });
20042
+ attempt();
19973
20043
  });
19974
20044
  }
19975
20045
  if (!options.oneShot) armDeadline();
@@ -20619,25 +20689,67 @@ function originKeyFromBlocks(blocks) {
20619
20689
  }
20620
20690
  return markerFromBlocks(blocks);
20621
20691
  }
20692
+ /** The single `&<>` escaper: every piece of outside text reaches mrkdwn through it. */
20622
20693
  function escapeText(value) {
20623
20694
  return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
20624
20695
  }
20696
+ /** Board markup: the literal parts are board source, every value is already `Mrkdwn`. */
20697
+ function markup(parts, ...values) {
20698
+ return parts.reduce((out, part, index) => `${out}${values[index - 1] ?? ""}${part}`);
20699
+ }
20700
+ function joined(values, separator) {
20701
+ return values.join(separator);
20702
+ }
20703
+ /** Splitting on a newline never cuts an entity, so each line stays escaped. */
20704
+ function lines(value) {
20705
+ return value.split("\n");
20706
+ }
20707
+ const lookalikes = {
20708
+ "*": "∗",
20709
+ _: "ˍ",
20710
+ "~": "∼",
20711
+ "`": "´"
20712
+ };
20713
+ const urlRun = /https?:\/\/\S+/g;
20714
+ const wordChar = /[\p{L}\p{N}]/u;
20715
+ /**
20716
+ * Swaps a `*`, `_` or `~` in outside text for a lookalike unless a letter or digit sits on both
20717
+ * sides of it (the node's start and end count as boundaries), so Slack cannot format it; `own`
20718
+ * is the span's mark and is always swapped. Marks inside `https?://` runs stay so Slack still
20719
+ * links the URL. Neighbours are read from the original text: `ˍ` is a letter (Lm). A mark at a
20720
+ * word edge changes copied bytes: `__init__` shows `ˍˍinitˍˍ`, `/srv/_config.yml` shows
20721
+ * `/srv/ˍconfig.yml`. Every backtick is swapped, inside words and URLs too: Slack pairs
20722
+ * backticks across words into code, which hides them.
20723
+ */
20724
+ function neutralize(text, own) {
20725
+ const urls = [...text.matchAll(urlRun)].map((match) => [match.index, match.index + match[0].length]);
20726
+ return text.replace(/[*_~`]/g, (found, index) => {
20727
+ if (found === "`") return lookalikes["`"];
20728
+ const mark = found;
20729
+ if (mark === own) return lookalikes[mark];
20730
+ if (urls.some(([start, end]) => start <= index && index < end)) return mark;
20731
+ const before = text[index - 1];
20732
+ const after = text[index + 1];
20733
+ return before !== void 0 && after !== void 0 && wordChar.test(before) && wordChar.test(after) ? mark : lookalikes[mark];
20734
+ });
20735
+ }
20625
20736
  /** Slack applies `~` and `_` only within one line and not across edge spaces. */
20626
- function perLine(text, mark) {
20627
- return text.split("\n").map((line) => {
20737
+ function perLine(text, wrap) {
20738
+ return joined(text.split("\n").map((line) => {
20628
20739
  const value = line.trim();
20629
- return value.length === 0 ? "" : `${mark}${escapeText(value)}${mark}`;
20630
- }).join("\n");
20740
+ return value.length === 0 ? escapeText("") : wrap(escapeText(value));
20741
+ }), "\n");
20631
20742
  }
20743
+ const userId = /^[A-Za-z0-9_]+$/;
20632
20744
  function inline(value) {
20633
20745
  switch (value.kind) {
20634
- case "text": return escapeText(value.text);
20635
- case "emphasis": return `*${escapeText(value.text)}*`;
20636
- case "code": return `\`${value.text.replaceAll("`", "´")}\``;
20637
- case "strike": return perLine(value.text.replaceAll("~", "∼"), "~");
20638
- case "italic": return perLine(value.text.replaceAll("_", "ˍ"), "_");
20639
- case "link": return `<${value.url.replace(/[<>|]/g, "")}|${escapeText(value.text).replaceAll("|", "¦")}>`;
20640
- case "mention": return `<@${value.user}>`;
20746
+ case "text": return escapeText(neutralize(value.text));
20747
+ case "emphasis": return markup`*${escapeText(neutralize(value.text, "*"))}*`;
20748
+ case "code": return markup`\`${escapeText(value.text.replaceAll("`", lookalikes["`"]))}\``;
20749
+ case "strike": return perLine(neutralize(value.text, "~"), (line) => markup`~${line}~`);
20750
+ case "italic": return perLine(neutralize(value.text, "_"), (line) => markup`_${line}_`);
20751
+ case "link": return markup`<${escapeText(value.url.replace(/[<>|]/g, ""))}|${escapeText(neutralize(value.text).replaceAll("|", "¦"))}>`;
20752
+ case "mention": return userId.test(value.user) ? markup`<@${escapeText(value.user)}>` : escapeText(neutralize(`@${value.user}`));
20641
20753
  }
20642
20754
  }
20643
20755
  /**
@@ -20653,8 +20765,8 @@ function splitContext(body) {
20653
20765
  body,
20654
20766
  context: []
20655
20767
  };
20656
- const context = body.slice(end).map((block) => block.kind === "context" ? block.children.map(inline).join("") : "").filter((text) => text.length > 0);
20657
- const bounded = [...context.slice(0, MAX_CONTEXT_ELEMENTS - 1), ...context.length >= MAX_CONTEXT_ELEMENTS ? [context.slice(MAX_CONTEXT_ELEMENTS - 1).join("\n")] : []];
20768
+ const context = body.slice(end).map((block) => block.kind === "context" ? joined(block.children.map(inline), "") : escapeText("")).filter((text) => text.length > 0);
20769
+ const bounded = [...context.slice(0, MAX_CONTEXT_ELEMENTS - 1), ...context.length >= MAX_CONTEXT_ELEMENTS ? [joined(context.slice(MAX_CONTEXT_ELEMENTS - 1), "\n")] : []];
20658
20770
  if (bounded.some((text) => text.length > 2900)) return {
20659
20771
  body,
20660
20772
  context: []
@@ -20665,11 +20777,11 @@ function splitContext(body) {
20665
20777
  };
20666
20778
  }
20667
20779
  function renderText(body) {
20668
- return body.map((block) => {
20669
- if (block.kind === "code_block") return `\`\`\`\n${block.text.replaceAll("```", "'''")}\n\`\`\``;
20670
- const value = block.children.map(inline).join("");
20671
- return block.kind === "quote" ? value.split("\n").map((line) => `> ${line}`).join("\n") : value;
20672
- }).filter((value) => value.length > 0).join("\n\n");
20780
+ return joined(body.map((block) => {
20781
+ if (block.kind === "code_block") return markup`\`\`\`\n${escapeText(block.text.replaceAll("```", "'''"))}\n\`\`\``;
20782
+ const value = joined(block.children.map(inline), "");
20783
+ return block.kind === "quote" ? joined(lines(value).map((line) => markup`> ${line}`), "\n") : value;
20784
+ }).filter((value) => value.length > 0), "\n\n");
20673
20785
  }
20674
20786
  function literal(value) {
20675
20787
  switch (value.kind) {
@@ -20725,13 +20837,13 @@ function renderResponse(body, cliHint) {
20725
20837
  text: pointer
20726
20838
  }]
20727
20839
  });
20728
- const fallback = shown.map((block) => {
20840
+ const escaped = escapeText(shown.map((block) => {
20729
20841
  const value = block.children.map(literal).join("");
20730
20842
  return block.kind === "quote" ? `Quote: ${value}` : value;
20731
- }).join("\n\n");
20843
+ }).join("\n\n"));
20732
20844
  const limit = MAX_PART_TEXT - (truncated ? suffix.length : 0);
20733
20845
  return {
20734
- text: `${fallback.length <= limit ? fallback : splitText(fallback, limit)?.[0] ?? ""}${truncated ? suffix : ""}`,
20846
+ text: `${escaped.length <= limit ? escaped : splitText(escaped, limit)?.[0] ?? ""}${truncated ? suffix : ""}`,
20735
20847
  blocks: [{
20736
20848
  type: "rich_text",
20737
20849
  elements
@@ -20881,7 +20993,8 @@ function createDeliveryGateway(client, channels) {
20881
20993
  const addressed = parseRef(target.message);
20882
20994
  if (addressed === null) return failedMessage("invalid_message_ref");
20883
20995
  const marker = markers[0];
20884
- if (marker === null || marker === void 0 || parts.length !== 1) return failedMessage("edit_too_long");
20996
+ const part = parts[0];
20997
+ if (marker === null || marker === void 0 || part === void 0 || parts.length !== 1) return failedMessage("edit_too_long");
20885
20998
  if (request.maybeSent) {
20886
20999
  const existing = (await readMessages(client, {
20887
21000
  channel: addressed.channel,
@@ -20893,8 +21006,8 @@ function createDeliveryGateway(client, channels) {
20893
21006
  await client.chat.update({
20894
21007
  channel: addressed.channel,
20895
21008
  ts: addressed.ts,
20896
- text: parts[0] ?? "",
20897
- blocks: messageBlocks(parts[0] ?? "", marker, request.actions, void 0, context)
21009
+ text: part,
21010
+ blocks: messageBlocks(part, marker, request.actions, void 0, context)
20898
21011
  });
20899
21012
  confirmed = true;
20900
21013
  }
@@ -20942,10 +21055,11 @@ function createDeliveryGateway(client, channels) {
20942
21055
  for (let i = 0; i < parts.length; i++) {
20943
21056
  const key = keys[i];
20944
21057
  const marker = markers[i];
20945
- if (key === void 0 || marker === null || marker === void 0) return failedMessage("invalid_marker");
21058
+ const part = parts[i];
21059
+ if (key === void 0 || part === void 0 || marker === null || marker === void 0) return failedMessage("invalid_marker");
20946
21060
  const existing = request.maybeSent ? marked(prior, key) : void 0;
20947
21061
  if (i === 0 && firstTs !== void 0) continue;
20948
- const ts = existing ?? await post(channel, threadTs, parts[i] ?? "", marker, request, i === 0, context, target.kind === "open" && i === 0 && parts.length > 1 ? request.key : void 0);
21062
+ const ts = existing ?? await post(channel, threadTs, part, marker, request, i === 0, context, target.kind === "open" && i === 0 && parts.length > 1 ? request.key : void 0);
20949
21063
  confirmed = true;
20950
21064
  if (i === 0) firstTs = ts;
20951
21065
  if (target.kind === "open" && i === 0) threadTs = ts;
package/dist/mcp.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { C as renderMcpError, X as ERRORS, y as OPERATIONS } from "./chunk-DyHtyPom.mjs";
2
- import { o as CliError, r as requestOperation } from "./chunk-Z9DFhl-U.mjs";
3
- import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./chunk-BbwZCNQh.mjs";
1
+ import { C as renderMcpError, X as ERRORS, y as OPERATIONS } from "./chunk-DuSucVv4.mjs";
2
+ import { o as CliError, r as requestOperation } from "./chunk-B81O9UQo.mjs";
3
+ import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./chunk-DSGruS1f.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.53.1",
3
+ "version": "0.53.3",
4
4
  "license": "MIT",
5
5
  "engines": {
6
6
  "node": "^24.12.0 || ^26.0.0"