spur-board 0.122.0 → 0.124.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.
@@ -455,8 +455,11 @@ const columnConfig = z.strictObject({
455
455
  cycleLimit: z.int().min(1).default(DEFAULT_CYCLE_LIMIT).describe("How many times a task may return to Dev from this column before the board stops it for the operator. Returns by the column executor, for external comments and for unresolved review threads count, a changes-requested review included (it is an external comment, not a separate return); a conflict, red CI and a draft do not."),
456
456
  courseCheck: z.int().min(0).default(DEFAULT_COURSE_CHECK).describe("How many returns to Dev from this column, counted as for cycleLimit, before the board holds the task and asks courseCheckTo (by default the curator, or the operator when the project has no curator) to check its course. The answer resets the count and reaches the worker as a task comment. 0 turns the check off; cycleLimit is checked first."),
457
457
  courseCheckTo: nonEmpty.optional().describe("Who answers this column's course check: operator, the curator's name, or the name of a column orchestrator listed in this project's spurProjects; a board-wide orchestrator is refused. Without it, the curator, or the operator when the project has no curator. When the addressee has no live session the question moves to the operator; a conductor that is rung and does not answer keeps it, and the operator gets an item."),
458
- requireResolvedThreads: z.boolean().optional().describe("true: a task leaves this column, and every column right of it, only when its PR has no unresolved review thread; an unresolved one sends it back to Dev, and the worker's Dev turn lists each thread. Outdated threads count; a thread counts until someone resolves it, whoever wrote it. Defaults to true on ready-to-merge and false elsewhere; allowed on dev through ready-to-merge.")
458
+ requireResolvedThreads: z.boolean().optional().describe("true: a task leaves this column, and every column right of it, only when its PR has no unresolved review thread; an unresolved one sends it back to Dev, and the worker's Dev turn lists each thread. Outdated threads count; a thread counts until someone resolves it, whoever wrote it. Defaults to true on ready-to-merge and false elsewhere; allowed on dev through ready-to-merge."),
459
+ quietTurnAfterMs: z.int().min(1).optional().describe("How long the orchestrator session holding a turn of this column may sit quiet at its prompt before the board reminds it, then raises a stuck-turn anomaly, in milliseconds. Defaults to health.idleInDevAfterMs. Named orchestrator only: allowed on an enabled column whose orchestrator is a Spur project, set here or filled board-wide; a worker or operator turn left in the column keeps health.idleInDevAfterMs."),
460
+ noRecipientAfterMs: z.int().min(1).optional().describe("How long an untaken turn of this column may wait with no live session to ring before the board raises one operator item for the project and column, in milliseconds. The time runs from the later of the turn ring's creation and the moment the last session that could take it stopped being a recipient: the first of its end, leaving Spur's list or reaching a finished state (stopped, killed, errored or completed), so later changes in the same gap do not move it. Sessions that could take it are those of the column's Spur project and the task's linked orchestrator. Defaults to 600000 (10 minutes). Named orchestrator only: allowed on an enabled column whose orchestrator is a Spur project, set here or filled board-wide.")
459
461
  });
462
+ const TURN_TIMING_KEYS = ["quietTurnAfterMs", "noRecipientAfterMs"];
460
463
  /** Columns a task never leaves through the Dev gate, so they cannot require resolved threads. */
461
464
  const NO_THREAD_GATE = /* @__PURE__ */ new Set([...TODO_GROUP_COLUMN_IDS, "done"]);
462
465
  /**
@@ -792,7 +795,7 @@ const configObject = z.strictObject({
792
795
  turnStallAfterMs: durationMs(6e5, "How long an unhealthy open-turn executor waits before a curator or operator block"),
793
796
  errorAfterMs: durationMs(9e4, "How long a session stays in error before it is flagged"),
794
797
  needsInputAfterMs: durationMs(12e4, "How long a session waits for input before it is flagged"),
795
- idleInDevAfterMs: durationMs(18e5, "How long a worker session without an open PR, or the executor of a taken turn, waits at its prompt before it is flagged"),
798
+ idleInDevAfterMs: durationMs(18e5, "How long a worker session without an open PR, or the executor of a taken turn, waits at its prompt before it is flagged; an orchestrator turn uses its column quietTurnAfterMs when set"),
796
799
  flipSmoothingMs: durationMs(3e4, "How long a new session health value must hold before it is reported"),
797
800
  hostLoad: z.strictObject({
798
801
  sessions: z.int().min(1).default(3).describe("Sessions entering error within the window that start an episode."),
@@ -908,12 +911,41 @@ function checkBoardWideAgainstProjects(config, ctx) {
908
911
  shortNames.add(shortName);
909
912
  });
910
913
  }
914
+ /** Whether a column, before board-wide expansion, is enabled and taken by a named Spur project. */
915
+ function namedOrchestratorColumn(config, column) {
916
+ if (!column.enabled || column.orchestrator === "operator") return false;
917
+ if (column.orchestrator !== "none") return true;
918
+ return config.spurProjects.some((entry) => entry.role !== "operator" && fills(entry, column));
919
+ }
920
+ /** `quietTurnAfterMs` and `noRecipientAfterMs` only on enabled named-orchestrator columns. */
921
+ function checkTurnTimings(config, ctx) {
922
+ config.projects.forEach((project, i) => {
923
+ const allowed = project.columns.filter((column) => namedOrchestratorColumn(config, column)).map((column) => column.id);
924
+ project.columns.forEach((column, j) => {
925
+ if (namedOrchestratorColumn(config, column)) return;
926
+ for (const key of TURN_TIMING_KEYS) {
927
+ if (column[key] === void 0) continue;
928
+ ctx.addIssue({
929
+ code: "custom",
930
+ path: [
931
+ "projects",
932
+ i,
933
+ "columns",
934
+ j,
935
+ key
936
+ ],
937
+ message: `${key} is allowed only on an enabled column with a named orchestrator: ${allowed.length === 0 ? `project ${project.id} has none` : `in project ${project.id} use one of ${allowed.join(", ")}`}`
938
+ });
939
+ }
940
+ });
941
+ });
942
+ }
911
943
  /**
912
944
  * The board config file. Every object rejects unknown keys; no key holds a secret. The parsed
913
945
  * value has top-level `spurProjects` applied to every board project's columns and
914
946
  * `spurProjects` (`expandBoardWide`), so readers of `projects[]` see the effective bindings.
915
947
  */
916
- const configSchema = configObject.superRefine(checkBoardWideAgainstProjects).superRefine((config, ctx) => {
948
+ const configSchema = configObject.superRefine(checkBoardWideAgainstProjects).superRefine(checkTurnTimings).superRefine((config, ctx) => {
917
949
  const { web } = config;
918
950
  if (web.publicOrigin !== void 0 && !validOrigin(web.publicOrigin, web.port)) ctx.addIssue({
919
951
  code: "custom",
@@ -972,6 +1004,19 @@ function boardWideSpurProject(config, name) {
972
1004
  return config.spurProjects.find((entry) => entry.name === name);
973
1005
  }
974
1006
  /**
1007
+ * The effective turn timings of a project column, defaults applied; null when the column is
1008
+ * missing, disabled or not taken by a named Spur project.
1009
+ */
1010
+ function columnTurnTimings(config, projectId, column) {
1011
+ const entry = config.projects.find((project) => project.id === projectId)?.columns.find((candidate) => candidate.id === column);
1012
+ if (entry === void 0 || !entry.enabled || entry.orchestrator === "none" || entry.orchestrator === "operator") return null;
1013
+ return {
1014
+ orchestrator: entry.orchestrator,
1015
+ quietTurnAfterMs: entry.quietTurnAfterMs ?? config.health.idleInDevAfterMs,
1016
+ noRecipientAfterMs: entry.noRecipientAfterMs ?? 6e5
1017
+ };
1018
+ }
1019
+ /**
975
1020
  * `slack.defaultAddressee`; else the board-wide operator; else, once any shortName is set, the
976
1021
  * operator of the first board project that lists one; else null.
977
1022
  */
@@ -3009,7 +3054,9 @@ const configViewSchema = z.strictObject({
3009
3054
  ]).describe("Configured executor; worker falls back to operator without a live worker."),
3010
3055
  name: z.string().nullable().describe("Named Spur project, or null for automatic routing.")
3011
3056
  }).describe("Effective column executor."),
3012
- group: z.enum(COLUMN_GROUPS).optional().describe("Column group; present only on Todo-group columns.")
3057
+ group: z.enum(COLUMN_GROUPS).optional().describe("Column group; present only on Todo-group columns."),
3058
+ quietTurnAfterMs: z.int().min(1).optional().describe("Effective quiet time of an orchestrator turn before its reminder, in milliseconds; present only on columns with a named orchestrator."),
3059
+ noRecipientAfterMs: z.int().min(1).optional().describe("Effective wait of an untaken turn with no live session before the operator item, in milliseconds; present only on columns with a named orchestrator.")
3013
3060
  })).describe("Enabled board columns."),
3014
3061
  dispatcher: z.strictObject({ mode: z.enum(DISPATCHER_MODES).describe("Effective dispatcher mode.") }).describe("Dispatcher configuration."),
3015
3062
  spurProjects: z.array(z.strictObject({
@@ -5205,4 +5252,4 @@ const remoteDoctorReportSchema = z.object({
5205
5252
  function assertNever(value) {
5206
5253
  throw new Error(`Unexpected value: ${JSON.stringify(value)}`);
5207
5254
  }
5208
- export { encodeActorId as $, eventPayloadSchemas as A, isTodoGroupColumn as At, REVIEW_STATES as B, messageRefSchema as C, COLUMN_GROUPS as Ct, sortSkillFiles as D, SLACK_BOT_SCOPES as Dt, skillReloadFilesSchema as E, ITEM_KINDS as Et, prSourceId as F, prFactsSchema as G, SESSION_STATUSES as H, sessionTransitionSchema as I, sessionFactsSchema as J, prRefSchema as K, sourceCursorSchema as L, batchSchema as M, defaultBranchFactSchema as N, EVENT_KINDS as O, TASK_HOLDS as Ot, entityRefSchema as P, actorIdSchema as Q, trackerSourceId as R, interactionRefSchema as S, COLUMNS as St, skillReloadFileSchema as T, DISPATCHER_MODES as Tt, isExternalAuthor as U, SESSION_HEALTH_STATES as V, parseRingMarker as W, JIRA_PROJECT_KEY as X, ticketFactsSchema as Y, REF_NUMBER as Z, renderJsonError as _, configSchema as _t, requestHashOf as a, errorContextSchema as at, conversationRefSchema as b, requiredSecretKeys as bt, tokenRequestStatusSchema as c, successEnvelopeSchema as ct, buildCatalogSnapshot as d, DEFAULT_SLACK_APP_NAME as dt, errorCodeOf as et, roleCanUseOperation as f, DEFAULT_SLACK_COMMAND as ft, renderHttpProblem as g, configBindings as gt, turnHandedSchema as h, boardWideSpurProject as ht, TOKEN_REQUEST_LIMITS as i, err as it, AdapterError as j, GATE_REASONS as k, VIAS as kt, BOARD_TICK_MS as l, DEFAULT_HTTP_PORT as lt, defaultBranchViewSchema as m, RESERVED_PROJECT as mt, doctorReportSchema as n, parseRef as nt, tokenRequestResultSchema as o, errorEnvelopeSchema as ot, OPERATIONS as p, DEFAULT_STAND_PORT_RANGE as pt, ringMarker as q, remoteDoctorReportSchema as r, ERRORS as rt, tokenRequestSchema as s, ok as st, assertNever as t, parseActorId as tt, SYSTEMD_SERVICE_SETTINGS as u, DEFAULT_LINK as ut, renderMcpError as v, defaultAddressee as vt, userIdSchema as w, COLUMN_IDS as wt, inboundEventSchema as x, resolveWebOrigin as xt, SPACE_IDS as y, plainHttpAllowed as yt, PR_STATES as z };
5255
+ export { encodeActorId as $, eventPayloadSchemas as A, VIAS as At, REVIEW_STATES as B, messageRefSchema as C, COLUMNS as Ct, sortSkillFiles as D, ITEM_KINDS as Dt, skillReloadFilesSchema as E, DISPATCHER_MODES as Et, prSourceId as F, prFactsSchema as G, SESSION_STATUSES as H, sessionTransitionSchema as I, sessionFactsSchema as J, prRefSchema as K, sourceCursorSchema as L, batchSchema as M, defaultBranchFactSchema as N, EVENT_KINDS as O, SLACK_BOT_SCOPES as Ot, entityRefSchema as P, actorIdSchema as Q, trackerSourceId as R, interactionRefSchema as S, resolveWebOrigin as St, skillReloadFileSchema as T, COLUMN_IDS as Tt, isExternalAuthor as U, SESSION_HEALTH_STATES as V, parseRingMarker as W, JIRA_PROJECT_KEY as X, ticketFactsSchema as Y, REF_NUMBER as Z, renderJsonError as _, configBindings as _t, requestHashOf as a, errorContextSchema as at, conversationRefSchema as b, plainHttpAllowed as bt, tokenRequestStatusSchema as c, successEnvelopeSchema as ct, buildCatalogSnapshot as d, DEFAULT_SLACK_APP_NAME as dt, errorCodeOf as et, roleCanUseOperation as f, DEFAULT_SLACK_COMMAND as ft, renderHttpProblem as g, columnTurnTimings as gt, turnHandedSchema as h, boardWideSpurProject as ht, TOKEN_REQUEST_LIMITS as i, err as it, AdapterError as j, isTodoGroupColumn as jt, GATE_REASONS as k, TASK_HOLDS as kt, BOARD_TICK_MS as l, DEFAULT_HTTP_PORT as lt, defaultBranchViewSchema as m, RESERVED_PROJECT as mt, doctorReportSchema as n, parseRef as nt, tokenRequestResultSchema as o, errorEnvelopeSchema as ot, OPERATIONS as p, DEFAULT_STAND_PORT_RANGE as pt, ringMarker as q, remoteDoctorReportSchema as r, ERRORS as rt, tokenRequestSchema as s, ok as st, assertNever as t, parseActorId as tt, SYSTEMD_SERVICE_SETTINGS as u, DEFAULT_LINK as ut, renderMcpError as v, configSchema as vt, userIdSchema as w, COLUMN_GROUPS as wt, inboundEventSchema as x, requiredSecretKeys as xt, SPACE_IDS as y, defaultAddressee as yt, PR_STATES as z };
@@ -1,5 +1,5 @@
1
- import { _t as configSchema, d as buildCatalogSnapshot, p as OPERATIONS, yt as plainHttpAllowed } from "./chunk-w6KrYs3j.mjs";
2
- import { o as CliError, t as fetchCatalogVersion } from "./chunk-DS95rV33.mjs";
1
+ import { bt as plainHttpAllowed, d as buildCatalogSnapshot, p as OPERATIONS, vt as configSchema } from "./chunk-Bdi5PEuV.mjs";
2
+ import { o as CliError, t as fetchCatalogVersion } from "./chunk-MSHt4j9s.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";
@@ -1,4 +1,4 @@
1
- import { _ as renderJsonError, at as errorContextSchema, c as tokenRequestStatusSchema, ct as successEnvelopeSchema, o as tokenRequestResultSchema, ot as errorEnvelopeSchema, rt as ERRORS } from "./chunk-w6KrYs3j.mjs";
1
+ import { _ as renderJsonError, at as errorContextSchema, c as tokenRequestStatusSchema, ct as successEnvelopeSchema, o as tokenRequestResultSchema, ot as errorEnvelopeSchema, rt as ERRORS } from "./chunk-Bdi5PEuV.mjs";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { z } from "zod";
4
4
  import { request } from "node:http";
package/dist/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { D as sortSkillFiles, Dt as SLACK_BOT_SCOPES, Q as actorIdSchema, T as skillReloadFileSchema, _t as configSchema, a as requestHashOf, bt as requiredSecretKeys, ct as successEnvelopeSchema, f as roleCanUseOperation, p as OPERATIONS, pt as DEFAULT_STAND_PORT_RANGE, r as remoteDoctorReportSchema, rt as ERRORS, u as SYSTEMD_SERVICE_SETTINGS, xt as resolveWebOrigin } from "./chunk-w6KrYs3j.mjs";
1
+ import { D as sortSkillFiles, Ot as SLACK_BOT_SCOPES, Q as actorIdSchema, St as resolveWebOrigin, T as skillReloadFileSchema, a as requestHashOf, ct as successEnvelopeSchema, f as roleCanUseOperation, p as OPERATIONS, pt as DEFAULT_STAND_PORT_RANGE, r as remoteDoctorReportSchema, rt as ERRORS, u as SYSTEMD_SERVICE_SETTINGS, vt as configSchema, xt as requiredSecretKeys } from "./chunk-Bdi5PEuV.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-DS95rV33.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-DywuekMO.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-MSHt4j9s.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-D9XJdrky.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-DS95rV33.mjs";
1
+ export { t as fetchCatalogVersion, n as fetchTokenStatus, r as requestOperation, i as requestSkillReload, a as requestTokenEnrollment } from "./chunk-MSHt4j9s.mjs";
package/dist/daemon.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as encodeActorId, A as eventPayloadSchemas, At as isTodoGroupColumn, B as REVIEW_STATES, C as messageRefSchema, Ct as COLUMN_GROUPS, D as sortSkillFiles, Dt as SLACK_BOT_SCOPES, E as skillReloadFilesSchema, Et as ITEM_KINDS, F as prSourceId, G as prFactsSchema, H as SESSION_STATUSES, I as sessionTransitionSchema, J as sessionFactsSchema, K as prRefSchema, L as sourceCursorSchema, M as batchSchema, N as defaultBranchFactSchema, O as EVENT_KINDS, Ot as TASK_HOLDS, P as entityRefSchema, Q as actorIdSchema, R as trackerSourceId, S as interactionRefSchema, St as COLUMNS, Tt as DISPATCHER_MODES, U as isExternalAuthor, V as SESSION_HEALTH_STATES, W as parseRingMarker, X as JIRA_PROJECT_KEY, Y as ticketFactsSchema, Z as REF_NUMBER, _t as configSchema, a as requestHashOf, b as conversationRefSchema, bt as requiredSecretKeys, c as tokenRequestStatusSchema, ct as successEnvelopeSchema, d as buildCatalogSnapshot, et as errorCodeOf, f as roleCanUseOperation, ft as DEFAULT_SLACK_COMMAND, g as renderHttpProblem, gt as configBindings, h as turnHandedSchema, ht as boardWideSpurProject, i as TOKEN_REQUEST_LIMITS, it as err, j as AdapterError, k as GATE_REASONS, kt as VIAS, l as BOARD_TICK_MS, m as defaultBranchViewSchema, mt as RESERVED_PROJECT, n as doctorReportSchema, nt as parseRef$1, o as tokenRequestResultSchema, p as OPERATIONS, q as ringMarker, rt as ERRORS, s as tokenRequestSchema, st as ok, t as assertNever, tt as parseActorId, ut as DEFAULT_LINK, vt as defaultAddressee, w as userIdSchema, wt as COLUMN_IDS, x as inboundEventSchema, xt as resolveWebOrigin, y as SPACE_IDS, yt as plainHttpAllowed, z as PR_STATES } from "./chunk-w6KrYs3j.mjs";
1
+ import { $ as encodeActorId, A as eventPayloadSchemas, At as VIAS, B as REVIEW_STATES, C as messageRefSchema, Ct as COLUMNS, D as sortSkillFiles, Dt as ITEM_KINDS, E as skillReloadFilesSchema, Et as DISPATCHER_MODES, F as prSourceId, G as prFactsSchema, H as SESSION_STATUSES, I as sessionTransitionSchema, J as sessionFactsSchema, K as prRefSchema, L as sourceCursorSchema, M as batchSchema, N as defaultBranchFactSchema, O as EVENT_KINDS, Ot as SLACK_BOT_SCOPES, P as entityRefSchema, Q as actorIdSchema, R as trackerSourceId, S as interactionRefSchema, St as resolveWebOrigin, Tt as COLUMN_IDS, U as isExternalAuthor, V as SESSION_HEALTH_STATES, W as parseRingMarker, X as JIRA_PROJECT_KEY, Y as ticketFactsSchema, Z as REF_NUMBER, _t as configBindings, a as requestHashOf, b as conversationRefSchema, bt as plainHttpAllowed, c as tokenRequestStatusSchema, ct as successEnvelopeSchema, d as buildCatalogSnapshot, et as errorCodeOf, f as roleCanUseOperation, ft as DEFAULT_SLACK_COMMAND, g as renderHttpProblem, gt as columnTurnTimings, h as turnHandedSchema, ht as boardWideSpurProject, i as TOKEN_REQUEST_LIMITS, it as err, j as AdapterError, jt as isTodoGroupColumn, k as GATE_REASONS, kt as TASK_HOLDS, l as BOARD_TICK_MS, m as defaultBranchViewSchema, mt as RESERVED_PROJECT, n as doctorReportSchema, nt as parseRef$1, o as tokenRequestResultSchema, p as OPERATIONS, q as ringMarker, rt as ERRORS, s as tokenRequestSchema, st as ok, t as assertNever, tt as parseActorId, ut as DEFAULT_LINK, vt as configSchema, w as userIdSchema, wt as COLUMN_GROUPS, x as inboundEventSchema, xt as requiredSecretKeys, y as SPACE_IDS, yt as defaultAddressee, z as PR_STATES } from "./chunk-Bdi5PEuV.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";
@@ -8761,6 +8761,8 @@ const DEFAULT_BRANCH_KEY = "default-branch:";
8761
8761
  const OPERATOR_BLOCK_KEY = "operator-block:";
8762
8762
  const BLOCK_KEY = "block:";
8763
8763
  const CONVERSATION_KEY = "conversation:";
8764
+ /** The item of a named-orchestrator column whose untaken turns have no live session to ring. */
8765
+ const NO_SESSION_KEY = "no-session:";
8764
8766
  /** The block an item is about: its ledger block, else the block its key names. */
8765
8767
  function itemBlockRef(item) {
8766
8768
  if (item.block_id !== null) return item.block_id;
@@ -10189,8 +10191,10 @@ async function sessionById(trx, id) {
10189
10191
  }
10190
10192
  async function liveSession(trx, id) {
10191
10193
  const row = await sessionById(trx, id);
10192
- return row?.ended_at === null && row.state !== "killed" && row.state !== "stopped" ? row : void 0;
10194
+ return row?.ended_at === null && !LINKED_FINISHED_STATES.includes(row.state) ? row : void 0;
10193
10195
  }
10196
+ /** Spur lifecycle states of a linked session that can no longer read a ring. */
10197
+ const LINKED_FINISHED_STATES = ["killed", "stopped"];
10194
10198
  /** Spur lifecycle states of a session that can no longer read a ring. */
10195
10199
  const FINISHED_STATES = [
10196
10200
  "killed",
@@ -10216,6 +10220,19 @@ function instant(value) {
10216
10220
  const ms = Date.parse(value);
10217
10221
  return Number.isNaN(ms) ? null : ms;
10218
10222
  }
10223
+ /** The earliest readable stored time among `values`, or undefined for none. */
10224
+ function earliestTime(values) {
10225
+ let earliest;
10226
+ for (const value of values) {
10227
+ if (typeof value !== "string") continue;
10228
+ const ms = Date.parse(value);
10229
+ if (!Number.isNaN(ms) && (earliest === void 0 || ms < earliest.ms)) earliest = {
10230
+ value,
10231
+ ms
10232
+ };
10233
+ }
10234
+ return earliest?.value;
10235
+ }
10219
10236
  /** Orders later times first and missing times last. Compared, never subtracted. */
10220
10237
  function laterFirst(left, right) {
10221
10238
  const a = left ?? -Infinity;
@@ -11627,9 +11644,13 @@ async function rerouteDemotedWorkerTurn(trx, input) {
11627
11644
  });
11628
11645
  return true;
11629
11646
  }
11630
- /** How long the holder of a taken turn may sit quiet before it is reminded, then flagged. */
11631
- function stuckTurnAfterMs(config) {
11632
- return config.health.idleInDevAfterMs;
11647
+ /**
11648
+ * How long the holder of a taken turn may sit quiet before it is reminded, then flagged: the column
11649
+ * `quietTurnAfterMs` for its named orchestrator's turn (by role: a worker turn can stay in a column
11650
+ * a config change named), else `health.idleInDevAfterMs`.
11651
+ */
11652
+ function stuckTurnAfterMs(config, projectId, turn) {
11653
+ return (turn.role === `orchestrator:${turn.column}` ? columnTurnTimings(config, projectId, turn.column) : null)?.quietTurnAfterMs ?? config.health.idleInDevAfterMs;
11633
11654
  }
11634
11655
  /**
11635
11656
  * Since when a holder session sits idle: from its end, or from when it began `waiting` at its
@@ -11709,7 +11730,8 @@ async function remindStuckTurns(trx, config, at) {
11709
11730
  if (await spurBlind(trx)) return;
11710
11731
  for (const { turn, sessionId, ended, quietSince, reminder } of await quietTurns(trx)) {
11711
11732
  if (ended || quietSince === null || reminder !== void 0) continue;
11712
- if (at.getTime() < Date.parse(quietSince) + stuckTurnAfterMs(config)) continue;
11733
+ const threshold = stuckTurnAfterMs(config, await taskProject(trx, turn.task_id), turn);
11734
+ if (at.getTime() < Date.parse(quietSince) + threshold) continue;
11713
11735
  await registerTurnReminder(trx, turn, sessionId, at);
11714
11736
  }
11715
11737
  }
@@ -11724,7 +11746,9 @@ async function ringDue(trx, notificationId, config, at) {
11724
11746
  if ((await trx.selectFrom("notification").select("kind").where("id", "=", notificationId).executeTakeFirst())?.kind !== "turn_reminder") return true;
11725
11747
  if (await spurBlind(trx)) return false;
11726
11748
  const quiet = (await quietTurns(trx)).find((entry) => entry.reminder?.id === notificationId);
11727
- return quiet !== void 0 && !quiet.ended && quiet.quietSince !== null && at.getTime() >= Date.parse(quiet.quietSince) + stuckTurnAfterMs(config);
11749
+ if (quiet === void 0 || quiet.ended || quiet.quietSince === null) return false;
11750
+ const project = await taskProject(trx, quiet.turn.task_id);
11751
+ return at.getTime() >= Date.parse(quiet.quietSince) + stuckTurnAfterMs(config, project, quiet.turn);
11728
11752
  }
11729
11753
  /** Close reasons of a turn whose untaken feedback goes back to a later turn. */
11730
11754
  const recalled = /* @__PURE__ */ new Set(["corrected", "rerouted"]);
@@ -14283,6 +14307,50 @@ function sourceText(item, state) {
14283
14307
  action: `check ${thing}`
14284
14308
  };
14285
14309
  }
14310
+ /** The board project and column a `no-session:<project>:<column>` key names. */
14311
+ function noSessionColumn(key) {
14312
+ const rest = key.slice(11);
14313
+ const last = rest.lastIndexOf(":");
14314
+ return {
14315
+ project: rest.slice(0, last),
14316
+ column: rest.slice(last + 1)
14317
+ };
14318
+ }
14319
+ /**
14320
+ * Untaken orchestrator turns of non-archived tasks with a ringing turn notification, as the
14321
+ * reconcile counts them, by `<project>:<column>`: one batched read, run only when an open
14322
+ * `no-session:` item is listed.
14323
+ */
14324
+ async function waitingTurns(trx, items) {
14325
+ if (!items.some((item) => item.item_key.startsWith("no-session:"))) return /* @__PURE__ */ new Map();
14326
+ const rows = await trx.selectFrom("turn").innerJoin("task", "task.id", "turn.task_id").select([
14327
+ "task.project",
14328
+ "turn.column",
14329
+ (eb) => eb.fn.count("turn.id").as("waiting")
14330
+ ]).where("task.membership", "!=", "archived").where("turn.closed_at", "is", null).where("turn.acked_at", "is", null).where(sql`turn.role = 'orchestrator:' || turn."column"`).where((eb) => eb.exists(eb.selectFrom("notification").select("notification.id").whereRef("notification.turn_id", "=", "turn.id").where("notification.kind", "=", "turn").where("notification.acked_at", "is", null).where("notification.exhausted_at", "is", null))).groupBy(["task.project", "turn.column"]).execute();
14331
+ return new Map(rows.map((row) => [`${row.project}:${row.column}`, row.waiting]));
14332
+ }
14333
+ /**
14334
+ * The text of a `no-session:` item: while open, its stored text with the waiting turns and the
14335
+ * whole minutes since `fact_at` read now; a cleared one keeps its stored text. The action names
14336
+ * the column's Spur project.
14337
+ */
14338
+ function noSessionText(item, config, waiting, now) {
14339
+ const { project, column } = noSessionColumn(item.item_key);
14340
+ const spur = columnTurnTimings(config, project, column)?.orchestrator;
14341
+ const action = `start a session in ${spur === void 0 ? "its Spur project" : `Spur project ${spur}`}, or take over its turns with board inbox ack`;
14342
+ const since = item.fact_at === null ? NaN : Date.parse(item.fact_at);
14343
+ if (item.cleared_at !== null || Number.isNaN(since)) return {
14344
+ condition: item.text,
14345
+ action
14346
+ };
14347
+ const minutes = Math.max(0, Math.floor((now - since) / 6e4));
14348
+ const count = waiting.get(`${project}:${column}`) ?? 0;
14349
+ return {
14350
+ condition: `${item.text}; ${String(count)} waiting, no live session for ${String(minutes)} min`,
14351
+ action
14352
+ };
14353
+ }
14286
14354
  /** Newest first by `at`, ties by id as text. */
14287
14355
  function newestFirst(at) {
14288
14356
  return (left, right) => at(right).localeCompare(at(left)) || (left.id < right.id ? -1 : left.id > right.id ? 1 : 0);
@@ -14339,7 +14407,7 @@ function createOperatorInbox(deps) {
14339
14407
  const items = [...openItems, ...lastCleared.values()];
14340
14408
  const blockIds = [...new Set(items.flatMap((item) => itemBlockRef(item) ?? []))];
14341
14409
  const sourceIds = items.flatMap((item) => item.item_key.startsWith("source:") ? [item.item_key.slice(7)] : []);
14342
- const [referenced, owners, sources, deliveries] = await Promise.all([
14410
+ const [referenced, owners, sources, deliveries, waiting] = await Promise.all([
14343
14411
  blockIds.length === 0 ? Promise.resolve([]) : trx.selectFrom("block").leftJoin("task", "task.id", "block.task_id").select([
14344
14412
  "block.id",
14345
14413
  "block.addressee_role",
@@ -14353,7 +14421,8 @@ function createOperatorInbox(deps) {
14353
14421
  "blind_reason",
14354
14422
  "blind_message"
14355
14423
  ]).where("source", "in", sourceIds).execute(),
14356
- deliveryUrls(trx, items)
14424
+ deliveryUrls(trx, items),
14425
+ waitingTurns(trx, openItems)
14357
14426
  ]);
14358
14427
  const blockById = new Map(referenced.map((block) => [block.id, block]));
14359
14428
  const sourceById = new Map(sources.map((state) => [state.source, state]));
@@ -14365,7 +14434,7 @@ function createOperatorInbox(deps) {
14365
14434
  if (block?.addressee_role === "operator" && (ITEM_POLICY[kind].block || item.item_key.startsWith("operator-block:") || item.item_key.startsWith("block:"))) return void 0;
14366
14435
  const task = owner(item) ?? owners.get(item.id) ?? (block === void 0 ? null : owner(block));
14367
14436
  if (task?.membership === "archived") return void 0;
14368
- const { condition, action } = item.item_key.startsWith("source:") ? sourceText(item, sourceById.get(item.item_key.slice(7))) : {
14437
+ const { condition, action } = item.item_key.startsWith("source:") ? sourceText(item, sourceById.get(item.item_key.slice(7))) : kind === "board_observation" && item.item_key.startsWith("no-session:") ? noSessionText(item, config, waiting, clock.now()) : {
14369
14438
  condition: item.text,
14370
14439
  action: ACTIONS[kind](item, {
14371
14440
  block,
@@ -15968,6 +16037,109 @@ async function conversationWaiting(trx, config, block, subject) {
15968
16037
  };
15969
16038
  }
15970
16039
  /**
16040
+ * When the last of `rows` stopped being a session a ring could reach, in milliseconds; -Infinity
16041
+ * for none. A row stopped at the earliest of its stored end, absence and finish, so later
16042
+ * timestamps of the same gap do not move it. A linked orchestrator stays a recipient while absent
16043
+ * or errored or completed, so only its end or a linked finished state counts. A row that stopped
16044
+ * when first seen never was a recipient and counts for nothing.
16045
+ */
16046
+ function lastLoss(rows, linked) {
16047
+ let last = -Infinity;
16048
+ for (const row of rows) {
16049
+ const loss = earliestTime(linked ? [row.ended_at, LINKED_FINISHED_STATES.includes(row.state) ? row.finished_at : null] : [
16050
+ row.ended_at,
16051
+ row.absent_since,
16052
+ row.finished_at
16053
+ ]);
16054
+ const ms = loss === void 0 ? NaN : Date.parse(loss);
16055
+ if (ms > Date.parse(row.first_seen) && ms > last) last = ms;
16056
+ }
16057
+ return last;
16058
+ }
16059
+ /**
16060
+ * One `no-session:<project>:<column>` item per named-orchestrator column whose untaken turns
16061
+ * have rung with no live session to take them for `noRecipientAfterMs`. A ring's wait runs from
16062
+ * the later of its creation and the moment the last session that could take it stopped being a
16063
+ * recipient (`lastLoss`): one of the column's Spur project, or one linked to the task as
16064
+ * orchestrator. The
16065
+ * column's earliest wait start is the item's `factAt`; the summary carries no count or age, so a
16066
+ * new waiting turn or a later reconcile raises nothing again.
16067
+ */
16068
+ async function turnsWithoutSession(trx, config, now, taskById) {
16069
+ const dated = (await trx.selectFrom("notification").innerJoin("turn", "turn.id", "notification.turn_id").select([
16070
+ "notification.id",
16071
+ "notification.kind",
16072
+ "notification.task_id",
16073
+ "notification.block_id",
16074
+ "notification.role",
16075
+ "notification.author_session",
16076
+ "notification.created_at",
16077
+ "turn.id as turn_id",
16078
+ "turn.task_id as turn_task_id",
16079
+ "turn.column"
16080
+ ]).where("notification.kind", "=", "turn").where("notification.acked_at", "is", null).where("notification.exhausted_at", "is", null).where("turn.closed_at", "is", null).where("turn.acked_at", "is", null).where(sql`turn.role = 'orchestrator:' || turn."column"`).execute()).map((ring) => ({
16081
+ ring,
16082
+ at: Date.parse(ring.created_at)
16083
+ })).filter(({ at }) => !Number.isNaN(at)).sort((left, right) => left.at - right.at || left.ring.turn_id - right.ring.turn_id);
16084
+ const spurGone = /* @__PURE__ */ new Map();
16085
+ const linkedGone = /* @__PURE__ */ new Map();
16086
+ const columns = /* @__PURE__ */ new Map();
16087
+ for (const { ring, at } of dated) {
16088
+ const task = taskById.get(ring.turn_task_id);
16089
+ if (task === void 0) continue;
16090
+ const timings = columnTurnTimings(config, task.project, ring.column);
16091
+ if (timings === null) continue;
16092
+ if (await selectNotificationRecipient(trx, ring, config) !== void 0) continue;
16093
+ const spur = timings.orchestrator;
16094
+ let gone = spurGone.get(spur);
16095
+ if (gone === void 0) {
16096
+ gone = lastLoss(await trx.selectFrom("session_snapshot").select([
16097
+ "ended_at",
16098
+ "absent_since",
16099
+ "finished_at",
16100
+ "first_seen",
16101
+ "state"
16102
+ ]).where("spur_project", "=", spur).where((eb) => eb.or([
16103
+ eb("ended_at", "is not", null),
16104
+ eb("absent_since", "is not", null),
16105
+ eb("finished_at", "is not", null)
16106
+ ])).execute(), false);
16107
+ spurGone.set(spur, gone);
16108
+ }
16109
+ let linked = linkedGone.get(task.id);
16110
+ if (linked === void 0) {
16111
+ linked = lastLoss(await trx.selectFrom("link").innerJoin("session_snapshot", "session_snapshot.id", "link.session_id").select([
16112
+ "session_snapshot.ended_at",
16113
+ "session_snapshot.absent_since",
16114
+ "session_snapshot.finished_at",
16115
+ "session_snapshot.first_seen",
16116
+ "session_snapshot.state"
16117
+ ]).where("link.task_id", "=", task.id).where("link.entity", "=", "session").where("link.role", "=", "orchestrator").where("link.banned", "=", 0).execute(), true);
16118
+ linkedGone.set(task.id, linked);
16119
+ }
16120
+ const since = Math.max(at, gone, linked);
16121
+ const key = `${NO_SESSION_KEY}${task.project}:${ring.column}`;
16122
+ const group = columns.get(key);
16123
+ if (group === void 0) columns.set(key, {
16124
+ task,
16125
+ spur,
16126
+ afterMs: timings.noRecipientAfterMs,
16127
+ earliest: since,
16128
+ oldest: ring
16129
+ });
16130
+ else group.earliest = Math.min(group.earliest, since);
16131
+ }
16132
+ return [...columns].flatMap(([key, { task, spur, afterMs, earliest, oldest }]) => now - earliest < afterMs ? [] : [{
16133
+ key,
16134
+ kind: "board_observation",
16135
+ taskId: task.id,
16136
+ summary: `${task.project} ${oldest.column}: turns wait for a live session of Spur project ${spur}; oldest T${String(oldest.turn_id)} since ${oldest.created_at}`,
16137
+ factAt: new Date(earliest).toISOString(),
16138
+ source: null,
16139
+ priority: 4
16140
+ }]);
16141
+ }
16142
+ /**
15971
16143
  * Reconciles every item in the caller's observation or tick transaction. It first closes each
15972
16144
  * Done wrap-up turn whose holder session ended (`closeEndedDoneTurns`), so no stall item is
15973
16145
  * raised for it.
@@ -16382,10 +16554,10 @@ async function reconcileItems(trx, config, now, spurComplete, warnSkipped, spurC
16382
16554
  }
16383
16555
  if (!spurBlind) {
16384
16556
  const flagged = new Set([...health.flags, ...health.held].filter((flag) => ANOMALY_FLAGS.has(flag.kind)).map((flag) => flag.sessionId));
16385
- const threshold = stuckTurnAfterMs(config);
16386
16557
  for (const { turn, sessionId, ended, quietSince, reminder, delivered } of await quietTurns(trx)) {
16387
16558
  const task = taskById.get(turn.task_id);
16388
16559
  if (ended || task === void 0 || quietSince === null || flagged.has(sessionId)) continue;
16560
+ const threshold = stuckTurnAfterMs(config, task.project, turn);
16389
16561
  const quiet = Date.parse(quietSince);
16390
16562
  const reminded = reminder !== void 0 && delivered && reminder.acked_at !== null && now >= Math.max(Date.parse(reminder.acked_at), quiet) + threshold;
16391
16563
  const unreached = reminder !== void 0 && reminder.exhausted_at !== null && now >= quiet + threshold;
@@ -16402,6 +16574,10 @@ async function reconcileItems(trx, config, now, spurComplete, warnSkipped, spurC
16402
16574
  });
16403
16575
  }
16404
16576
  }
16577
+ if (spurBlind || !spurComplete || spurExpired) {
16578
+ const held = await trx.selectFrom("operator_item").select("item_key").where("item_key", "like", `${NO_SESSION_KEY}%`).where("cleared_at", "is", null).execute();
16579
+ heldKeys.push(...held.map((item) => item.item_key));
16580
+ } else candidates.push(...await turnsWithoutSession(trx, config, now, taskById));
16405
16581
  const ordered = orderItems(candidates);
16406
16582
  const seen = /* @__PURE__ */ new Set([...ordered.map((item) => item.key), ...heldKeys]);
16407
16583
  for (const flag of health.held) {
@@ -18462,13 +18638,18 @@ function createOperationRegistry(deps) {
18462
18638
  columns: project.columns.filter((column) => column.enabled).map((column) => {
18463
18639
  const named = column.orchestrator === "none" || column.orchestrator === "operator" ? void 0 : project.spurProjects.find((spur) => spur.name === column.orchestrator);
18464
18640
  const group = COLUMNS.find((c) => c.id === column.id)?.group ?? null;
18641
+ const timings = columnTurnTimings(config, project.id, column.id);
18465
18642
  return {
18466
18643
  id: column.id,
18467
18644
  executor: {
18468
18645
  kind: column.orchestrator === "operator" ? "operator" : named?.role === "curator" ? "curator" : named !== void 0 ? "orchestrator" : column.id === "external-review" ? "dispatcher" : "worker",
18469
18646
  name: named?.name ?? null
18470
18647
  },
18471
- ...group === null ? {} : { group }
18648
+ ...group === null ? {} : { group },
18649
+ ...timings === null ? {} : {
18650
+ quietTurnAfterMs: timings.quietTurnAfterMs,
18651
+ noRecipientAfterMs: timings.noRecipientAfterMs
18652
+ }
18472
18653
  };
18473
18654
  }),
18474
18655
  dispatcher: { mode: project.dispatcher.mode },
@@ -19059,6 +19240,11 @@ async function session(trx, config, fact, at, source, ambiguousBranches, feedEna
19059
19240
  const old = await trx.selectFrom("session_snapshot").selectAll().where("id", "=", fact.id).executeTakeFirst();
19060
19241
  const previous = old === void 0 ? null : parseJson(sessionFactsSchema, old.detail);
19061
19242
  const changed = previous === null || comparableFacts(previous, "lastActivityAt") !== comparableFacts(fact, "lastActivityAt");
19243
+ const finishedAt = FINISHED_STATES.includes(fact.lifecycle) ? earliestTime([
19244
+ old?.finished_at,
19245
+ old?.ended_at,
19246
+ old?.absent_since
19247
+ ]) ?? at : null;
19062
19248
  await trx.insertInto("session_snapshot").values({
19063
19249
  id: fact.id,
19064
19250
  spur_project: fact.spurProject,
@@ -19073,7 +19259,8 @@ async function session(trx, config, fact, at, source, ambiguousBranches, feedEna
19073
19259
  detail: toJson(sessionFactsSchema, fact),
19074
19260
  source,
19075
19261
  observed_at: at,
19076
- absent_since: null
19262
+ absent_since: null,
19263
+ finished_at: finishedAt
19077
19264
  }).onConflict((oc) => oc.column("id").doUpdateSet({
19078
19265
  branch: fact.branch,
19079
19266
  pr: fact.pr === null ? null : `${fact.pr.repo}#${String(fact.pr.number)}`,
@@ -19085,7 +19272,8 @@ async function session(trx, config, fact, at, source, ambiguousBranches, feedEna
19085
19272
  detail: toJson(sessionFactsSchema, fact),
19086
19273
  source,
19087
19274
  observed_at: at,
19088
- absent_since: null
19275
+ absent_since: null,
19276
+ finished_at: finishedAt
19089
19277
  })).execute();
19090
19278
  const orchestrator = config.projects.some((project) => project.spurProjects.some((spur) => spur.name === fact.spurProject && spur.role === "orchestrator"));
19091
19279
  if (orchestrator) {
package/dist/mcp.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { p as OPERATIONS, rt as ERRORS, v as renderMcpError } from "./chunk-w6KrYs3j.mjs";
2
- import { o as CliError, r as requestOperation } from "./chunk-DS95rV33.mjs";
3
- import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./chunk-DywuekMO.mjs";
1
+ import { p as OPERATIONS, rt as ERRORS, v as renderMcpError } from "./chunk-Bdi5PEuV.mjs";
2
+ import { o as CliError, r as requestOperation } from "./chunk-MSHt4j9s.mjs";
3
+ import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./chunk-D9XJdrky.mjs";
4
4
  import { randomUUID } from "node:crypto";
5
5
  import { readFileSync } from "node:fs";
6
6
  import { z } from "zod";
@@ -0,0 +1,7 @@
1
+ -- When the board first saw a session in a finished lifecycle state (FINISHED_STATES in
2
+ -- doorbells.ts: killed, stopped, errored, completed); null while it is in any other state. Spur
3
+ -- keeps listing finished sessions with no end time, so this is the moment one stopped being a
4
+ -- recipient. Rows already finished take their last observation: no earlier time is stored.
5
+ ALTER TABLE session_snapshot ADD COLUMN finished_at TEXT;
6
+ UPDATE session_snapshot SET finished_at = observed_at
7
+ WHERE state IN ('killed', 'stopped', 'errored', 'completed');