spur-board 0.23.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { G as SLACK_BOT_SCOPES, P as ERRORS, U as configSchema, W as requiredSecretKeys, l as roleCanUseOperation, r as SYSTEMD_SERVICE_SETTINGS, u as OPERATIONS } from "./src-C6fOCG5L.mjs";
2
- import { a as errorExitCode, i as CliError, n as requestOperation, o as renderCliError, r as requestTokenEnrollment, s as escapeTerminalControls } from "./client-B4JXkdZu.mjs";
3
- import { a as memoryVerdictCache, c as loadClientConfig, d as resolveDaemonAddress, i as fileVerdictCache, l as loadEnrollmentConfig, n as cliPackageVersion, o as configFile, s as dataDirectory, t as checkCatalog, u as readConfiguredPort } from "./config-CreYUbFe.mjs";
1
+ import { G as SLACK_BOT_SCOPES, P as ERRORS, U as configSchema, W as requiredSecretKeys, l as roleCanUseOperation, r as SYSTEMD_SERVICE_SETTINGS, u as OPERATIONS } from "./src-lQGgnLLD.mjs";
2
+ import { a as errorExitCode, i as CliError, n as requestOperation, o as renderCliError, r as requestTokenEnrollment, s as escapeTerminalControls } from "./client-B1u-1YVS.mjs";
3
+ import { a as memoryVerdictCache, c as loadClientConfig, d as resolveDaemonAddress, i as fileVerdictCache, l as loadEnrollmentConfig, n as cliPackageVersion, o as configFile, s as dataDirectory, t as checkCatalog, u as readConfiguredPort } from "./config-BuftCWGz.mjs";
4
4
  import { createHash, randomBytes, randomUUID } from "node:crypto";
5
5
  import { accessSync, chmodSync, closeSync, constants, cpSync, existsSync, ftruncateSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
6
6
  import { homedir, hostname, userInfo } from "node:os";
@@ -1,4 +1,4 @@
1
- import { F as errorContextSchema, I as errorEnvelopeSchema, L as successEnvelopeSchema, P as ERRORS, f as renderJsonError } from "./src-C6fOCG5L.mjs";
1
+ import { F as errorContextSchema, I as errorEnvelopeSchema, L as successEnvelopeSchema, P as ERRORS, f as renderJsonError } from "./src-lQGgnLLD.mjs";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { z } from "zod";
4
4
  import { request } from "node:http";
package/dist/client.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as requestOperation, r as requestTokenEnrollment, t as fetchCatalogVersion } from "./client-B4JXkdZu.mjs";
1
+ import { n as requestOperation, r as requestTokenEnrollment, t as fetchCatalogVersion } from "./client-B1u-1YVS.mjs";
2
2
  export { fetchCatalogVersion, requestOperation, requestTokenEnrollment };
@@ -1,5 +1,5 @@
1
- import { U as configSchema, c as buildCatalogSnapshot, u as OPERATIONS } from "./src-C6fOCG5L.mjs";
2
- import { i as CliError, t as fetchCatalogVersion } from "./client-B4JXkdZu.mjs";
1
+ import { U as configSchema, c as buildCatalogSnapshot, u as OPERATIONS } from "./src-lQGgnLLD.mjs";
2
+ import { i as CliError, t as fetchCatalogVersion } from "./client-B1u-1YVS.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/daemon.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { A as errorCodeOf, C as SESSION_STATUSES, D as ticketFactsSchema, E as sessionFactsSchema, G as SLACK_BOT_SCOPES, H as RESERVED_PROJECT, L as successEnvelopeSchema, M as parseRef$1, N as taskKeySchema, O as actorIdSchema, P as ERRORS, S as SESSION_HEALTH_STATES, T as prRefSchema, U as configSchema, V as DEFAULT_SLACK_COMMAND, W as requiredSecretKeys, _ as interactionRefSchema, a as batchSchema, b as EVENT_KINDS, c as buildCatalogSnapshot, d as renderHttpProblem, g as inboundEventSchema, h as conversationRefSchema, i as AdapterError, j as parseActorId, k as encodeActorId, l as roleCanUseOperation, m as SPACE_IDS, n as BOARD_TICK_MS, o as entityRefSchema, s as sourceCursorSchema, t as assertNever, u as OPERATIONS, v as messageRefSchema, w as prFactsSchema, x as eventPayloadSchemas, y as userIdSchema, z as DEFAULT_LINK } from "./src-C6fOCG5L.mjs";
1
+ import { A as errorCodeOf, C as SESSION_STATUSES, D as ticketFactsSchema, E as sessionFactsSchema, G as SLACK_BOT_SCOPES, H as RESERVED_PROJECT, L as successEnvelopeSchema, M as parseRef$1, N as taskKeySchema, O as actorIdSchema, P as ERRORS, S as SESSION_HEALTH_STATES, T as prRefSchema, U as configSchema, V as DEFAULT_SLACK_COMMAND, W as requiredSecretKeys, _ as interactionRefSchema, a as batchSchema, b as EVENT_KINDS, c as buildCatalogSnapshot, d as renderHttpProblem, g as inboundEventSchema, h as conversationRefSchema, i as AdapterError, j as parseActorId, k as encodeActorId, l as roleCanUseOperation, m as SPACE_IDS, n as BOARD_TICK_MS, o as entityRefSchema, s as sourceCursorSchema, t as assertNever, u as OPERATIONS, v as messageRefSchema, w as prFactsSchema, x as eventPayloadSchemas, y as userIdSchema, z as DEFAULT_LINK } from "./src-lQGgnLLD.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import { createHash, randomUUID } from "node:crypto";
4
4
  import { closeSync, existsSync, fstatSync, fsyncSync, ftruncateSync, linkSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeSync } from "node:fs";
@@ -279,12 +279,123 @@ function toJson(schema, value) {
279
279
  return JSON.stringify(schema.parse(value));
280
280
  }
281
281
  //#endregion
282
+ //#region ../core/src/domain/blocks/blocks.ts
283
+ var BlockRuleError = class extends Error {
284
+ code;
285
+ constructor(code, message) {
286
+ super(message);
287
+ this.code = code;
288
+ }
289
+ };
290
+ /** Roles survive a change in the session currently filling them. */
291
+ function blockAddressee(input) {
292
+ const { type, author, authorRole, column, orchestrator, curator = null, hasWorker } = input;
293
+ if (author === "system") return orchestrator !== null ? `orchestrator:${column}` : hasWorker ? "worker" : "operator";
294
+ if (type === "code") return "worker";
295
+ if (type === "dependency" || type === "external") return authorRole;
296
+ const parsed = parseActorId(author);
297
+ const asker = parsed?.actor === "agent" ? parsed.actorRef.project : null;
298
+ if (asker !== null && asker === curator) return "operator";
299
+ if (orchestrator === "operator") return "operator";
300
+ if (orchestrator !== null && asker !== orchestrator) return `orchestrator:${column}`;
301
+ return curator === null ? "operator" : "curator";
302
+ }
303
+ function orchestratorColumn(role) {
304
+ return role.slice(13);
305
+ }
306
+ /** A new role fails typecheck here; a new kind fails at each caller's `assertNever`. */
307
+ function parseAddressee(role) {
308
+ switch (role) {
309
+ case "operator":
310
+ case "curator":
311
+ case "worker": return { kind: role };
312
+ default: return {
313
+ kind: "orchestrator",
314
+ column: orchestratorColumn(role)
315
+ };
316
+ }
317
+ }
318
+ function requireOpen(block) {
319
+ if (block.state === "open") return;
320
+ throw new BlockRuleError("block_not_open", `Block was ${block.outcome ?? "unblocked"} by ${block.unblockedBy ?? "unknown"}.`);
321
+ }
322
+ /** Only a question stops at the curator; every other step goes straight to the operator. */
323
+ function nextAddressee(current, type, hasCurator) {
324
+ const addressee = parseAddressee(current);
325
+ switch (addressee.kind) {
326
+ case "orchestrator": return type === "needs_input" && hasCurator ? "curator" : "operator";
327
+ case "operator":
328
+ case "curator":
329
+ case "worker": return "operator";
330
+ default: return assertNever(addressee);
331
+ }
332
+ }
333
+ /** The steps a block took from `original` to `current`, or none if `current` is not on that path. */
334
+ function priorAddressees(original, current, type, hasCurator) {
335
+ const path = [];
336
+ let step = original;
337
+ while (step !== current) {
338
+ const next = nextAddressee(step, type, hasCurator);
339
+ if (next === step) return [];
340
+ path.push(step);
341
+ step = next;
342
+ }
343
+ return path;
344
+ }
345
+ function escalateBlock(block, hasCurator = false) {
346
+ requireOpen(block);
347
+ const addressee = nextAddressee(block.addressee, block.type, hasCurator);
348
+ return {
349
+ addressee,
350
+ changed: block.addressee !== addressee
351
+ };
352
+ }
353
+ function answerBlock(block) {
354
+ requireOpen(block);
355
+ if (block.type !== "needs_input") throw new BlockRuleError("wrong_block_type", "Only a question block can be answered.");
356
+ }
357
+ function closeBlock(block, input) {
358
+ requireOpen(block);
359
+ if (input.mode === "withdraw") {
360
+ if (block.type !== "needs_input" || block.author !== input.actor) throw new BlockRuleError("forbidden", "Only the question author can withdraw it.");
361
+ return {
362
+ outcome: "withdrawn",
363
+ outcomeReason: null
364
+ };
365
+ }
366
+ if (input.mode === "done") {
367
+ if (block.type !== "code") throw new BlockRuleError("wrong_block_type", "Done applies to a code block.");
368
+ return {
369
+ outcome: "done",
370
+ outcomeReason: input.ref ?? null
371
+ };
372
+ }
373
+ return {
374
+ outcome: "reason",
375
+ outcomeReason: input.reason
376
+ };
377
+ }
378
+ function editComment(revision, ackedRevision) {
379
+ return {
380
+ revision: revision + 1,
381
+ clarification: ackedRevision !== null
382
+ };
383
+ }
384
+ function acknowledgeComment(revision, requested) {
385
+ if (revision !== requested) throw new BlockRuleError("stale_comment_revision", `Comment revision is ${String(revision)}; requested ${String(requested)}.`);
386
+ return requested;
387
+ }
388
+ //#endregion
282
389
  //#region ../core/src/app/authorize.ts
283
390
  function operator(actor, config) {
284
391
  if (actor === "operator") return true;
285
392
  const parsed = parseActorId(actor);
286
393
  return parsed?.actor === "agent" && config.projects.some((project) => project.spurProjects.some((spur) => spur.name === parsed.actorRef.project && spur.role === "operator"));
287
394
  }
395
+ /** The Spur project that curates one board project, or null when it has none. */
396
+ function curatorProject(config, projectId) {
397
+ return config.projects.find((project) => project.id === projectId)?.spurProjects.find((spur) => spur.role === "curator")?.name ?? null;
398
+ }
288
399
  function worker(actor, target) {
289
400
  const parsed = parseActorId(actor);
290
401
  return parsed?.actor === "agent" && target.task !== null && target.workers.some((link) => link.session_id === parsed.actorRef.session && link.role === "worker" && link.banned === 0);
@@ -304,10 +415,14 @@ function matches(rule, actor, target, config) {
304
415
  case "column-orchestrator": return target.task !== null && orchestrator$1(actor, target, config, target.task.column);
305
416
  case "block-addressee": {
306
417
  if (target.block === null) return false;
307
- const role = target.block.addressee_role;
308
- if (role === "operator") return operator(actor, config);
309
- if (role === "worker") return worker(actor, target);
310
- return orchestrator$1(actor, target, config, role.slice(13));
418
+ const addressee = parseAddressee(target.block.addressee_role);
419
+ switch (addressee.kind) {
420
+ case "operator": return operator(actor, config);
421
+ case "curator": return parsed?.actor === "agent" && parsed.actorRef.project === curatorProject(config, target.project);
422
+ case "worker": return worker(actor, target);
423
+ case "orchestrator": return orchestrator$1(actor, target, config, addressee.column);
424
+ default: return assertNever(addressee);
425
+ }
311
426
  }
312
427
  case "block-author": return target.block?.author === actor;
313
428
  }
@@ -7794,6 +7909,18 @@ function taskUrl(task, config) {
7794
7909
  if (project?.tracker.type === "jira") return `${project.tracker.baseUrl.replace(/\/$/, "")}/browse/${task.key}`;
7795
7910
  return `https://github.com/${task.key.replace("#", "/issues/")}`;
7796
7911
  }
7912
+ const commandKeys = new AsyncLocalStorage();
7913
+ /**
7914
+ * Runs fn in the scope of one command: every event `emit` writes inside it carries `key` in
7915
+ * `request_id`. The innermost scope wins. Run only `trx` work inside it. Never trigger a job or
7916
+ * start detached work (timers, unawaited promises) in the scope: async context propagates into
7917
+ * it, and a scheduler job chains its next runs from that context, so a leaked `trigger()` would
7918
+ * stamp this key on every later scheduled run, not just one.
7919
+ */
7920
+ function withCommandKey(key, fn) {
7921
+ return commandKeys.run(key, fn);
7922
+ }
7923
+ /** The only writer of the journal; `request_id` is the key of the enclosing command, or null. */
7797
7924
  async function emit(trx, kind, project, taskId, at, payload, actor = "system") {
7798
7925
  const parsed = parseActorId(actor);
7799
7926
  if (parsed === null) throw new Error("Invalid journal actor");
@@ -7806,7 +7933,7 @@ async function emit(trx, kind, project, taskId, at, payload, actor = "system") {
7806
7933
  actor_ref: parsed.actor === "agent" ? JSON.stringify(parsed.actorRef) : null,
7807
7934
  payload: toJson(eventPayloadSchemas[kind], payload),
7808
7935
  v: 1,
7809
- request_id: null
7936
+ request_id: commandKeys.getStore() ?? null
7810
7937
  }).execute();
7811
7938
  }
7812
7939
  function taskView(task) {
@@ -7826,10 +7953,6 @@ function linkView(link) {
7826
7953
  }
7827
7954
  //#endregion
7828
7955
  //#region ../core/src/app/denied-event.ts
7829
- const actorRefSchema$2 = z.strictObject({
7830
- project: z.string().min(1),
7831
- session: z.string().min(1)
7832
- });
7833
7956
  /**
7834
7957
  * The journal project of a denial with no resolved target, in order: the configured project
7835
7958
  * the input's `task` key or `project` names; else the only configured project listing the agent
@@ -7857,22 +7980,10 @@ function deniedProject(config, actor, input) {
7857
7980
  /** Persist an authorization refusal through the caller's transaction. */
7858
7981
  async function writeDeniedEvent(trx, denial) {
7859
7982
  const { config, actor, operation, input, target, at } = denial;
7860
- const parsed = parseActorId(actor);
7861
- if (parsed === null) throw new Error("Invalid actor");
7862
- await trx.insertInto("event").values({
7863
- at,
7864
- project: target.kind === "found" ? target.value.project : deniedProject(config, actor, input),
7865
- task_id: target.kind === "found" ? target.value.task?.id ?? null : null,
7866
- kind: "operation_denied",
7867
- actor: parsed.actor,
7868
- actor_ref: parsed.actor === "agent" ? toJson(actorRefSchema$2, parsed.actorRef) : null,
7869
- payload: toJson(eventPayloadSchemas.operation_denied, {
7870
- operation,
7871
- reason: "Caller does not match the operation grants."
7872
- }),
7873
- v: 1,
7874
- request_id: null
7875
- }).execute();
7983
+ await emit(trx, "operation_denied", target.kind === "found" ? target.value.project : deniedProject(config, actor, input), target.kind === "found" ? target.value.task?.id ?? null : null, at, {
7984
+ operation,
7985
+ reason: "Caller does not match the operation grants."
7986
+ }, actor);
7876
7987
  }
7877
7988
  //#endregion
7878
7989
  //#region ../core/src/app/commands.ts
@@ -7920,7 +8031,7 @@ async function replayOperation(trx, input) {
7920
8031
  if (row.operation !== input.operation || row.fingerprint !== hash) throw new CommandError("idempotency_key_mismatch", "Use the original input or a new key.");
7921
8032
  return parseJson(input.output, row.result);
7922
8033
  }
7923
- const value = await input.run();
8034
+ const value = await withCommandKey(input.key, input.run);
7924
8035
  if (value === void 0) return void 0;
7925
8036
  const resultText = toJson(input.output, value);
7926
8037
  await trx.insertInto("command").values({
@@ -8068,23 +8179,10 @@ const NO_FEED = /* @__PURE__ */ new Set([
8068
8179
  "transport_health"
8069
8180
  ]);
8070
8181
  async function journal$3(trx, item, kind, at, rule, actor = "system") {
8071
- const parsed = parseActorId(actor);
8072
- if (parsed === null) throw new Error("Invalid journal actor");
8073
- const task = item.task_id === null ? void 0 : await trx.selectFrom("task").select(["project"]).where("id", "=", item.task_id).executeTakeFirstOrThrow();
8074
- await trx.insertInto("event").values({
8075
- at: at.toISOString(),
8076
- project: task?.project ?? "_board",
8077
- task_id: item.task_id,
8078
- kind,
8079
- actor: parsed.actor,
8080
- actor_ref: parsed.actor === "agent" ? JSON.stringify(parsed.actorRef) : null,
8081
- payload: toJson(eventPayloadSchemas[kind], {
8082
- item: `I${String(item.id)}`,
8083
- ...kind === "from_you_raised" && rule !== void 0 ? { rule } : {}
8084
- }),
8085
- v: 1,
8086
- request_id: null
8087
- }).execute();
8182
+ await emit(trx, kind, (item.task_id === null ? void 0 : await trx.selectFrom("task").select(["project"]).where("id", "=", item.task_id).executeTakeFirstOrThrow())?.project ?? "_board", item.task_id, at.toISOString(), {
8183
+ item: `I${String(item.id)}`,
8184
+ ...kind === "from_you_raised" && rule !== void 0 ? { rule } : {}
8185
+ }, actor);
8088
8186
  }
8089
8187
  /** Kinds whose item has a retry action besides `delivery:<id>` (see `items.ts`). */
8090
8188
  const RETRY_KINDS = /* @__PURE__ */ new Set([
@@ -8699,17 +8797,7 @@ function effectiveStatus(row, at) {
8699
8797
  return row.status === "pending" && row.expires_at <= at.toISOString() ? "expired" : row.status;
8700
8798
  }
8701
8799
  async function journalToken(trx, kind, name, at) {
8702
- await trx.insertInto("event").values({
8703
- at: at.toISOString(),
8704
- project: RESERVED_PROJECT,
8705
- task_id: null,
8706
- kind,
8707
- actor: kind === "token_approved" || kind === "token_denied" || kind === "token_revoked" ? "operator" : "system",
8708
- actor_ref: null,
8709
- payload: toJson(eventPayloadSchemas[kind], { name }),
8710
- v: 1,
8711
- request_id: null
8712
- }).execute();
8800
+ await emit(trx, kind, RESERVED_PROJECT, null, at.toISOString(), { name }, kind === "token_approved" || kind === "token_denied" || kind === "token_revoked" ? "operator" : "system");
8713
8801
  }
8714
8802
  /** Lapse one pending request: journal it once and clear its approval item. */
8715
8803
  async function expireToken(trx, row, at) {
@@ -9062,87 +9150,9 @@ function listenApiServer(app, port) {
9062
9150
  });
9063
9151
  }
9064
9152
  //#endregion
9065
- //#region ../core/src/domain/blocks/blocks.ts
9066
- var BlockRuleError = class extends Error {
9067
- code;
9068
- constructor(code, message) {
9069
- super(message);
9070
- this.code = code;
9071
- }
9072
- };
9073
- /** Roles survive a change in the session currently filling them. */
9074
- function blockAddressee(input) {
9075
- const { type, author, authorRole, column, orchestrator, hasWorker } = input;
9076
- if (author === "system") return orchestrator !== null ? `orchestrator:${column}` : hasWorker ? "worker" : "operator";
9077
- if (type === "code") return "worker";
9078
- if (type === "dependency" || type === "external") return authorRole;
9079
- if (orchestrator === null) return "operator";
9080
- if (orchestrator === "operator") return "operator";
9081
- const parsed = parseActorId(author);
9082
- if (parsed?.actor === "agent" && parsed.actorRef.project === orchestrator) return "operator";
9083
- return `orchestrator:${column}`;
9084
- }
9085
- function requireOpen(block) {
9086
- if (block.state === "open") return;
9087
- throw new BlockRuleError("block_not_open", `Block was ${block.outcome ?? "unblocked"} by ${block.unblockedBy ?? "unknown"}.`);
9088
- }
9089
- function escalateBlock(block) {
9090
- requireOpen(block);
9091
- return {
9092
- addressee: "operator",
9093
- changed: block.addressee !== "operator"
9094
- };
9095
- }
9096
- function answerBlock(block) {
9097
- requireOpen(block);
9098
- if (block.type !== "needs_input") throw new BlockRuleError("wrong_block_type", "Only a question block can be answered.");
9099
- }
9100
- function closeBlock(block, input) {
9101
- requireOpen(block);
9102
- if (input.mode === "withdraw") {
9103
- if (block.type !== "needs_input" || block.author !== input.actor) throw new BlockRuleError("forbidden", "Only the question author can withdraw it.");
9104
- return {
9105
- outcome: "withdrawn",
9106
- outcomeReason: null
9107
- };
9108
- }
9109
- if (input.mode === "done") {
9110
- if (block.type !== "code") throw new BlockRuleError("wrong_block_type", "Done applies to a code block.");
9111
- return {
9112
- outcome: "done",
9113
- outcomeReason: input.ref ?? null
9114
- };
9115
- }
9116
- return {
9117
- outcome: "reason",
9118
- outcomeReason: input.reason
9119
- };
9120
- }
9121
- function editComment(revision, ackedRevision) {
9122
- return {
9123
- revision: revision + 1,
9124
- clarification: ackedRevision !== null
9125
- };
9126
- }
9127
- function acknowledgeComment(revision, requested) {
9128
- if (revision !== requested) throw new BlockRuleError("stale_comment_revision", `Comment revision is ${String(revision)}; requested ${String(requested)}.`);
9129
- return requested;
9130
- }
9131
- //#endregion
9132
9153
  //#region ../core/src/app/doorbells.ts
9133
9154
  async function journal$2(trx, notification, kind, payload, at) {
9134
- const task = await trx.selectFrom("task").select("project").where("id", "=", notification.task_id).executeTakeFirstOrThrow();
9135
- await trx.insertInto("event").values({
9136
- at: at.toISOString(),
9137
- project: task.project,
9138
- task_id: notification.task_id,
9139
- kind,
9140
- actor: "system",
9141
- actor_ref: null,
9142
- payload: toJson(eventPayloadSchemas[kind], payload),
9143
- v: 1,
9144
- request_id: null
9145
- }).execute();
9155
+ await emit(trx, kind, (await trx.selectFrom("task").select("project").where("id", "=", notification.task_id).executeTakeFirstOrThrow()).project, notification.task_id, at.toISOString(), payload);
9146
9156
  }
9147
9157
  /** Register a worker-addressed block without manufacturing a comment. */
9148
9158
  async function registerBlockNotification(trx, block, at) {
@@ -9190,13 +9200,26 @@ async function liveSession(trx, id) {
9190
9200
  const row = await trx.selectFrom("session_snapshot").selectAll().where("id", "=", id).executeTakeFirst();
9191
9201
  return row?.ended_at === null && row.state !== "killed" && row.state !== "stopped" ? row : void 0;
9192
9202
  }
9203
+ /** The session link role that receives an addressee's rings; board-wide roles have none. */
9204
+ function recipientLinkRole(role) {
9205
+ const addressee = parseAddressee(role);
9206
+ switch (addressee.kind) {
9207
+ case "worker": return "worker";
9208
+ case "orchestrator": return "orchestrator";
9209
+ case "operator":
9210
+ case "curator": return null;
9211
+ default: return assertNever(addressee);
9212
+ }
9213
+ }
9193
9214
  /** Select the current live recipient for a semantic notification. */
9194
9215
  async function selectNotificationRecipient(trx, n) {
9195
9216
  if (n.author_session !== null) {
9196
9217
  const author = await liveSession(trx, n.author_session);
9197
9218
  if (author !== void 0) return author;
9198
9219
  }
9199
- const links = await trx.selectFrom("link").select("session_id").where("task_id", "=", n.task_id).where("entity", "=", "session").where("role", "=", n.role === "worker" ? "worker" : "orchestrator").where("banned", "=", 0).orderBy("created_at", "desc").execute();
9220
+ const linkRole = recipientLinkRole(n.role);
9221
+ if (linkRole === null) return void 0;
9222
+ const links = await trx.selectFrom("link").select("session_id").where("task_id", "=", n.task_id).where("entity", "=", "session").where("role", "=", linkRole).where("banned", "=", 0).orderBy("created_at", "desc").execute();
9200
9223
  for (const link of links) {
9201
9224
  if (link.session_id === null) continue;
9202
9225
  const session = await liveSession(trx, link.session_id);
@@ -9420,10 +9443,6 @@ async function closeBlockNotification(trx, blockId, at) {
9420
9443
  }
9421
9444
  //#endregion
9422
9445
  //#region ../core/src/app/blocks.ts
9423
- const actorRefSchema$1 = z.strictObject({
9424
- project: z.string().min(1),
9425
- session: z.string().min(1)
9426
- });
9427
9446
  const idNumber = (id) => Number(id.slice(1));
9428
9447
  const blockId$1 = (id) => `B${String(id)}`;
9429
9448
  const commentId = (id) => `C${String(id)}`;
@@ -9532,19 +9551,7 @@ function commentView(comment, task) {
9532
9551
  };
9533
9552
  }
9534
9553
  async function journal$1(trx, task, ctx, kind, payload) {
9535
- const actor = parseActorId(ctx.actor);
9536
- if (actor === null) throw new Error("Invalid actor");
9537
- await trx.insertInto("event").values({
9538
- at: ctx.at,
9539
- project: task.project,
9540
- task_id: task.id,
9541
- kind,
9542
- actor: actor.actor,
9543
- actor_ref: actor.actor === "agent" ? toJson(actorRefSchema$1, actor.actorRef) : null,
9544
- payload: toJson(eventPayloadSchemas[kind], payload),
9545
- v: 1,
9546
- request_id: null
9547
- }).execute();
9554
+ await emit(trx, kind, task.project, task.id, ctx.at, payload, ctx.actor);
9548
9555
  }
9549
9556
  function orchestrator(config, task) {
9550
9557
  const name = config.projects.find((project) => project.id === task.project)?.columns.find((column) => column.id === task.column)?.orchestrator;
@@ -9554,8 +9561,19 @@ function authorRole(config, task, actor) {
9554
9561
  if (actor === "operator") return "operator";
9555
9562
  const parsed = parseActorId(actor);
9556
9563
  if (parsed?.actor === "agent" && config.projects.some((project) => project.spurProjects.some((spur) => spur.name === parsed.actorRef.project && spur.role === "operator"))) return "operator";
9557
- const configured = orchestrator(config, task);
9558
- return parsed?.actor === "agent" && parsed.actorRef.project === configured ? `orchestrator:${task.column}` : "worker";
9564
+ if (parsed?.actor !== "agent") return "worker";
9565
+ if (parsed.actorRef.project === orchestrator(config, task)) return `orchestrator:${task.column}`;
9566
+ return parsed.actorRef.project === curatorProject(config, task.project) ? "curator" : "worker";
9567
+ }
9568
+ function personaRole(role) {
9569
+ const addressee = parseAddressee(role);
9570
+ switch (addressee.kind) {
9571
+ case "operator": return "board";
9572
+ case "worker": return "worker";
9573
+ case "curator":
9574
+ case "orchestrator": return "orchestrator";
9575
+ default: return assertNever(addressee);
9576
+ }
9559
9577
  }
9560
9578
  function personaFor(config, task, actor) {
9561
9579
  if (actor === "system") return {
@@ -9568,10 +9586,9 @@ function personaFor(config, task, actor) {
9568
9586
  };
9569
9587
  const parsed = parseActorId(actor);
9570
9588
  if (parsed?.actor !== "agent") throw new Error("Invalid actor");
9571
- const role = authorRole(config, task, actor);
9572
9589
  return {
9573
9590
  name: parsed.actorRef.project,
9574
- role: role === "operator" ? "board" : role === "worker" ? "worker" : "orchestrator"
9591
+ role: personaRole(authorRole(config, task, actor))
9575
9592
  };
9576
9593
  }
9577
9594
  async function queueBlockOpen(trx, task, block, ctx, config) {
@@ -9592,6 +9609,24 @@ async function queueBlockOpen(trx, task, block, ctx, config) {
9592
9609
  async function hasWorker(trx, task) {
9593
9610
  return await trx.selectFrom("link").select("id").where("task_id", "=", task.id).where("entity", "=", "session").where("role", "=", "worker").where("banned", "=", 0).executeTakeFirst() !== void 0;
9594
9611
  }
9612
+ /** The addressee a block gets from current config and links. */
9613
+ async function routeBlock(trx, task, block, config) {
9614
+ return blockAddressee({
9615
+ type: block.type,
9616
+ author: block.author,
9617
+ authorRole: authorRole(config, task, block.author),
9618
+ column: task.column,
9619
+ orchestrator: orchestrator(config, task),
9620
+ curator: curatorProject(config, task.project),
9621
+ hasWorker: await hasWorker(trx, task)
9622
+ });
9623
+ }
9624
+ function holdsBlock(config, actor, target) {
9625
+ return authorize([{ grant: "block-addressee" }], actor, {
9626
+ config,
9627
+ target
9628
+ }).status === "allowed";
9629
+ }
9595
9630
  async function addComment(trx, task, block, text, ctx, addressee, config, source) {
9596
9631
  const row = await trx.insertInto("comment").values({
9597
9632
  task_id: task.id,
@@ -9624,14 +9659,10 @@ async function addComment(trx, task, block, text, ctx, addressee, config, source
9624
9659
  return row;
9625
9660
  }
9626
9661
  async function openBlock(trx, task, type, reason, ctx, config) {
9627
- const addressee = blockAddressee({
9662
+ const addressee = await routeBlock(trx, task, {
9628
9663
  type,
9629
- author: ctx.actor,
9630
- authorRole: authorRole(config, task, ctx.actor),
9631
- column: task.column,
9632
- orchestrator: orchestrator(config, task),
9633
- hasWorker: await hasWorker(trx, task)
9634
- });
9664
+ author: ctx.actor
9665
+ }, config);
9635
9666
  const row = await trx.insertInto("block").values({
9636
9667
  task_id: task.id,
9637
9668
  type,
@@ -9766,40 +9797,36 @@ function createBlockMutations(config) {
9766
9797
  id: "block.escalate",
9767
9798
  async resolveTargets(trx, input, actor) {
9768
9799
  const block = await blockById(trx, input.block);
9769
- if (block === void 0 || block.addressee_role !== "operator") return blockTarget(trx, input.block);
9800
+ if (block === void 0) return blockTarget(trx, input.block);
9770
9801
  const task = await taskById(trx, block.task_id);
9771
9802
  const target = await authorizationTarget(trx, task, block);
9772
9803
  if (target.kind !== "found" || target.value.block === null) return [target];
9773
- const original = blockAddressee({
9774
- type: block.type,
9775
- author: block.author,
9776
- authorRole: authorRole(config, task, block.author),
9777
- column: task.column,
9778
- orchestrator: orchestrator(config, task),
9779
- hasWorker: block.author === "system" && await hasWorker(trx, task)
9780
- });
9781
- if (original === "operator") return [target];
9782
- const originalTarget = {
9783
- kind: "found",
9784
- value: {
9785
- ...target.value,
9786
- block: {
9787
- ...target.value.block,
9788
- addressee_role: original
9804
+ if (holdsBlock(config, actor, target)) return [target];
9805
+ const priors = priorAddressees(await routeBlock(trx, task, block, config), block.addressee_role, block.type, curatorProject(config, task.project) !== null);
9806
+ for (const addressee_role of priors) {
9807
+ const prior = {
9808
+ kind: "found",
9809
+ value: {
9810
+ ...target.value,
9811
+ block: {
9812
+ ...target.value.block,
9813
+ addressee_role
9814
+ }
9789
9815
  }
9790
- }
9791
- };
9792
- return [authorize([{ grant: "block-addressee" }], actor, {
9793
- config,
9794
- target: originalTarget
9795
- }).status === "allowed" ? originalTarget : target];
9816
+ };
9817
+ if (holdsBlock(config, actor, prior)) return [prior];
9818
+ }
9819
+ return [target];
9796
9820
  },
9797
9821
  async run(trx, input, ctx) {
9798
9822
  const block = found(await blockById(trx, input.block));
9799
9823
  const task = await taskById(trx, block.task_id);
9800
9824
  active(task);
9801
- const next = rule(() => escalateBlock(current(block)));
9825
+ const hasCurator = curatorProject(config, task.project) !== null;
9826
+ const next = rule(() => escalateBlock(current(block), hasCurator));
9802
9827
  if (!next.changed) return { block: blockView(block, task) };
9828
+ const target = await authorizationTarget(trx, task, block);
9829
+ if (!holdsBlock(config, ctx.actor, target)) return { block: blockView(block, task) };
9803
9830
  const updated = await trx.updateTable("block").set({ addressee_role: next.addressee }).where("id", "=", block.id).returningAll().executeTakeFirstOrThrow();
9804
9831
  await journal$1(trx, task, ctx, "block_escalated", {
9805
9832
  block: input.block,
@@ -12701,20 +12728,7 @@ function plain(text) {
12701
12728
  }];
12702
12729
  }
12703
12730
  async function journal(trx, input) {
12704
- const actor = parseActorId(input.actor);
12705
- if (actor === null) throw new Error("Invalid journal actor");
12706
- const schema = eventPayloadSchemas[input.kind];
12707
- await trx.insertInto("event").values({
12708
- at: input.at,
12709
- project: input.project,
12710
- task_id: input.taskId,
12711
- kind: input.kind,
12712
- actor: actor.actor,
12713
- actor_ref: actor.actor === "agent" ? JSON.stringify(actor.actorRef) : null,
12714
- payload: toJson(z.unknown(), schema.parse(input.payload)),
12715
- v: 1,
12716
- request_id: null
12717
- }).execute();
12731
+ await emit(trx, input.kind, input.project, input.taskId, input.at, input.payload, input.actor);
12718
12732
  }
12719
12733
  async function taskContext(trx, event, gateway) {
12720
12734
  if (!("conversation" in event) || event.conversation === void 0) return {
@@ -13114,7 +13128,7 @@ function createInbound(input) {
13114
13128
  });
13115
13129
  }
13116
13130
  async function recordFailure(event, error, at) {
13117
- await scanTransaction(store, config, async (trx) => {
13131
+ await withCommandKey(event.dedupeKey, () => scanTransaction(store, config, async (trx) => {
13118
13132
  const context = await taskContext(trx, event, gateway.kind);
13119
13133
  await journal(trx, {
13120
13134
  kind: "inbound_failed",
@@ -13137,7 +13151,7 @@ function createInbound(input) {
13137
13151
  at,
13138
13152
  retry: true
13139
13153
  });
13140
- });
13154
+ }));
13141
13155
  }
13142
13156
  async function dispatchInteraction(event) {
13143
13157
  const token = event.kind === "action" ? tokenAction(event) : null;
@@ -16924,7 +16938,7 @@ function createSpurPort(options) {
16924
16938
  const { url, init } = spurSendRequest(options.baseUrl, session, text);
16925
16939
  let response;
16926
16940
  try {
16927
- response = await fetch(url, {
16941
+ response = await (options.fetch ?? fetch)(url, {
16928
16942
  ...init,
16929
16943
  signal: AbortSignal.timeout(options.timeoutMs ?? SEND_TIMEOUT_MS)
16930
16944
  });
package/dist/mcp.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { P as ERRORS, p as renderMcpError, u as OPERATIONS } from "./src-C6fOCG5L.mjs";
2
- import { i as CliError, n as requestOperation } from "./client-B4JXkdZu.mjs";
3
- import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./config-CreYUbFe.mjs";
1
+ import { P as ERRORS, p as renderMcpError, u as OPERATIONS } from "./src-lQGgnLLD.mjs";
2
+ import { i as CliError, n as requestOperation } from "./client-B1u-1YVS.mjs";
3
+ import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./config-BuftCWGz.mjs";
4
4
  import { randomUUID } from "node:crypto";
5
5
  import { readFileSync } from "node:fs";
6
6
  import { z } from "zod";
@@ -72,6 +72,7 @@ const BLOCK_OUTCOMES = [
72
72
  ];
73
73
  const ADDRESSEE_ROLES = [
74
74
  "operator",
75
+ "curator",
75
76
  ...COLUMN_IDS.map((id) => `orchestrator:${id}`),
76
77
  "worker"
77
78
  ];
@@ -205,7 +206,11 @@ const githubIssuesTracker = z.strictObject({
205
206
  });
206
207
  const spurProject = z.strictObject({
207
208
  name: nonEmpty,
208
- role: z.enum(["worker", "operator"]).describe("worker: sessions of this Spur project may link to this project's tasks through their PR or branch. operator: sessions act as the operator.")
209
+ role: z.enum([
210
+ "worker",
211
+ "operator",
212
+ "curator"
213
+ ]).describe("worker: sessions of this Spur project may link to this project's tasks through their PR or branch. operator: sessions act as the operator. curator: sessions answer the questions no column orchestrator takes and escalate the rest to the operator; a board project has at most one.")
209
214
  });
210
215
  const columnConfig = z.strictObject({
211
216
  id: z.enum(COLUMN_IDS, { error: (issue) => typeof issue.input === "string" ? `Unknown column ${JSON.stringify(issue.input)}: custom columns arrive with custom matchers and are not supported yet. Built-in columns: ${COLUMN_IDS.join(", ")}` : void 0 }),
@@ -262,6 +267,16 @@ const projectSchema = z.strictObject({
262
267
  operatorGithubLogin: z.string().regex(/^[A-Za-z0-9-]{1,39}$/, "Expected a GitHub login").describe("The GitHub account agents open PRs under. PR discovery in repos keeps only PRs whose author is this login. It is not necessarily the maintainer's own account: when agents push as one account and a maintainer approves as another, set the agents' account, or no PR is discovered."),
263
268
  spurProjects: z.array(spurProject).superRefine((items, ctx) => {
264
269
  rejectDuplicates(items, "name", "spur project name", ctx);
270
+ let curator;
271
+ items.forEach((item, i) => {
272
+ if (item.role !== "curator") return;
273
+ if (curator !== void 0) ctx.addIssue({
274
+ code: "custom",
275
+ path: [i, "role"],
276
+ message: `Second curator ${JSON.stringify(item.name)}: ${JSON.stringify(curator)} is already the curator of this board project`
277
+ });
278
+ curator ??= item.name;
279
+ });
265
280
  }).default([]),
266
281
  columns: z.array(columnConfig).superRefine(checkBoard).default(() => COLUMN_IDS.map((id) => ({
267
282
  id,
@@ -2301,7 +2316,7 @@ const OPERATIONS = [
2301
2316
  defineOperation({
2302
2317
  id: "block.ask",
2303
2318
  kind: "mutation",
2304
- description: "Ask the operator a question; the task is blocked until it is answered.",
2319
+ description: "Ask a blocking question; the Board routes it to the column orchestrator, the curator or the operator.",
2305
2320
  mcp: {
2306
2321
  whenToUse: "Ask a blocking question.",
2307
2322
  whenNotToUse: "Use comment_add for a nonblocking note.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spur-board",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "license": "MIT",
5
5
  "engines": {
6
6
  "node": "^24.12.0 || ^26.0.0"
@@ -83,7 +83,7 @@ Other errors: `wrong_id_kind`, `not_found`, `stale_comment_revision`, `idempoten
83
83
 
84
84
  ### `board ask`
85
85
 
86
- Purpose: Ask the operator a question; the task is blocked until it is answered.
86
+ Purpose: Ask a blocking question; the Board routes it to the column orchestrator, the curator or the operator.
87
87
  Arguments: `<task>`, `<text>`.
88
88
  Flags: `--key <key>`, `--json`.
89
89
  Use when: Ask a blocking question.