spur-board 0.52.0 → 0.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- import { $ as configSchema, d as buildCatalogSnapshot, et as plainHttpAllowed, p as OPERATIONS } from "./src-Dy1XbpPP.mjs";
2
- import { o as CliError, t as fetchCatalogVersion } from "./client-BTgz-Fib.mjs";
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";
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";
@@ -0,0 +1,10 @@
1
+ //#region ../contracts/src/urls.ts
2
+ /**
3
+ * The base of an HTTP API at `url`, with one trailing slash, so `new URL('path', base)` keeps a
4
+ * path prefix such as `/api`.
5
+ */
6
+ function apiBaseUrl(url) {
7
+ return new URL(`${url.replace(/\/$/, "")}/`);
8
+ }
9
+ //#endregion
10
+ export { apiBaseUrl as t };
@@ -142,6 +142,14 @@ const ACTORS = [
142
142
  "agent",
143
143
  "system"
144
144
  ];
145
+ /** The stored state of an operator token. */
146
+ const TOKEN_STATUSES = [
147
+ "pending",
148
+ "approved",
149
+ "denied",
150
+ "expired",
151
+ "revoked"
152
+ ];
145
153
  /** Bot OAuth scopes required by the generated Slack manifest and checked by doctor. */
146
154
  const SLACK_BOT_SCOPES = [
147
155
  "chat:write",
@@ -884,28 +892,31 @@ function err(error) {
884
892
  //#region ../contracts/src/ids.ts
885
893
  /**
886
894
  * Number in an ID or a task key: at most 15 digits, so it always converts to a safe integer
887
- * and two different IDs never share one number. A longer number is `usage`.
895
+ * and two different IDs never share one number. A longer number is `usage`. It is the shared
896
+ * grammar for every Jira key pattern.
888
897
  */
889
- const N$1 = "[1-9]\\d{0,14}";
898
+ const REF_NUMBER = "[1-9]\\d{0,14}";
899
+ /** Regex source of a Jira project key prefix, as in `PROJ-12`, in either letter case. */
900
+ const JIRA_PROJECT_KEY = "[A-Za-z][A-Za-z0-9_]*";
890
901
  const TASK_FORMS = [
891
902
  {
892
903
  form: "jira",
893
- source: `[A-Za-z][A-Za-z0-9_]*-${N$1}`
904
+ source: `${JIRA_PROJECT_KEY}-${REF_NUMBER}`
894
905
  },
895
906
  {
896
907
  form: "github",
897
- source: `[A-Za-z0-9-]+\\/[A-Za-z0-9._-]+#${N$1}`
908
+ source: `[A-Za-z0-9-]+\\/[A-Za-z0-9._-]+#${REF_NUMBER}`
898
909
  },
899
910
  {
900
911
  form: "github-short",
901
- source: `[A-Za-z0-9._-]+#${N$1}`
912
+ source: `[A-Za-z0-9._-]+#${REF_NUMBER}`
902
913
  }
903
914
  ];
904
915
  const PATTERNS = {
905
- block: `^B${N$1}$`,
906
- comment: `^C${N$1}$`,
907
- item: `^I${N$1}$`,
908
- turn: `^T${N$1}$`,
916
+ block: `^B${REF_NUMBER}$`,
917
+ comment: `^C${REF_NUMBER}$`,
918
+ item: `^I${REF_NUMBER}$`,
919
+ turn: `^T${REF_NUMBER}$`,
909
920
  task: `^(?:${TASK_FORMS.map((t) => t.source).join("|")})$`
910
921
  };
911
922
  const NUMBERED_KINDS = [
@@ -2235,13 +2246,7 @@ const linkOutput = z.strictObject({
2235
2246
  });
2236
2247
  const operatorOrProjectAgent = [{ grant: "operator" }, { grant: "project-agent" }];
2237
2248
  const operatorOnly = [{ grant: "operator" }];
2238
- const tokenStatus = z.enum([
2239
- "pending",
2240
- "approved",
2241
- "denied",
2242
- "expired",
2243
- "revoked"
2244
- ]).describe("Current token state.");
2249
+ const tokenStatus = z.enum(TOKEN_STATUSES).describe("Current token state.");
2245
2250
  const tokenName = z.string().min(1).describe("Unique name of the operator token.");
2246
2251
  /** The M1 operations. CLI, MCP and the daemon route are generated from this list. */
2247
2252
  const OPERATIONS = [
@@ -3648,6 +3653,17 @@ const batchSchema = z.strictObject({
3648
3653
  });
3649
3654
  });
3650
3655
  }).describe("The result of one poll.");
3656
+ /** Source id of the PR poll of one project repo: `github:<project>:<repo lowercased>`. */
3657
+ function prSourceId(projectId, repo) {
3658
+ return `github:${projectId}:${repo.toLowerCase()}`;
3659
+ }
3660
+ /**
3661
+ * Source id of a project's tracker poll: `jira:<project>`, or
3662
+ * `github-issues:<project>:<tracker repo lowercased>`.
3663
+ */
3664
+ function trackerSourceId(project) {
3665
+ return project.tracker.type === "jira" ? `jira:${project.id}` : `github-issues:${project.id}:${project.tracker.repo.toLowerCase()}`;
3666
+ }
3651
3667
  /** A whole-poll failure (A6). `retryAt` is when the source allows the next attempt. */
3652
3668
  var AdapterError = class extends Error {
3653
3669
  kind;
@@ -3696,6 +3712,14 @@ const tokenRequestSchema = z.strictObject({
3696
3712
  host: z.string().min(1).max(TOKEN_REQUEST_LIMITS.host).regex(PLAIN_TEXT),
3697
3713
  hash: z.string().regex(/^[0-9a-f]{64}$/)
3698
3714
  });
3715
+ /** The value `POST /v1/tokens/requests` answers with: the request waits for the operator. */
3716
+ const tokenRequestResultSchema = z.strictObject({
3717
+ name: z.string(),
3718
+ status: z.literal("pending"),
3719
+ expiresAt: z.iso.datetime()
3720
+ });
3721
+ /** The value `POST /v1/tokens/status` answers with; `unknown` is a hash the board never saw. */
3722
+ const tokenRequestStatusSchema = z.strictObject({ status: z.enum([...TOKEN_STATUSES, "unknown"]) });
3699
3723
  /**
3700
3724
  * The short request hash the approval prompt and `board token create` both show, so the
3701
3725
  * operator can match the request they approve to the one they made.
@@ -3703,6 +3727,34 @@ const tokenRequestSchema = z.strictObject({
3703
3727
  function requestHashOf(hash) {
3704
3728
  return hash.slice(0, 10);
3705
3729
  }
3730
+ const checkShape = {
3731
+ id: z.string(),
3732
+ status: z.enum([
3733
+ "pass",
3734
+ "fail",
3735
+ "warning"
3736
+ ]),
3737
+ blocking: z.boolean(),
3738
+ fix: z.string().nullable()
3739
+ };
3740
+ /** The body of `GET /v1/doctor`, as the daemon sends it; core parses every outgoing report. */
3741
+ const doctorReportSchema = z.strictObject({
3742
+ version: z.string().min(1).max(50),
3743
+ checks: z.array(z.strictObject({
3744
+ ...checkShape,
3745
+ id: checkShape.id.regex(/^[a-z][a-z._]+$/).max(60),
3746
+ fix: z.string().max(300).nullable()
3747
+ })).max(30)
3748
+ });
3749
+ /**
3750
+ * The daemon report as the CLI reads it: a newer daemon may add check ids, longer text or keys,
3751
+ * so this has no bounds and drops unknown keys. A new status value is still rejected, so adding
3752
+ * one breaks every older CLI that reads the report.
3753
+ */
3754
+ const remoteDoctorReportSchema = z.object({
3755
+ version: z.string(),
3756
+ checks: z.array(z.object(checkShape))
3757
+ });
3706
3758
  //#endregion
3707
3759
  //#region ../contracts/src/index.ts
3708
3760
  /** Exhaustiveness check: call it in the `default` branch of a switch over a union. */
@@ -3710,4 +3762,4 @@ function assertNever(value) {
3710
3762
  throw new Error(`Unexpected value: ${JSON.stringify(value)}`);
3711
3763
  }
3712
3764
  //#endregion
3713
- export { configSchema as $, parseRingMarker as A, parseRef as B, userIdSchema as C, SESSION_HEALTH_STATES as D, REVIEW_STATES as E, ticketFactsSchema as F, errorEnvelopeSchema as G, ERRORS as H, actorIdSchema as I, DEFAULT_HTTP_PORT as J, ok as K, encodeActorId as L, prRefSchema as M, ringMarker as N, SESSION_STATUSES as O, sessionFactsSchema as P, RESERVED_PROJECT as Q, errorCodeOf as R, messageRefSchema as S, eventPayloadSchemas as T, err as U, taskKeySchema as V, errorContextSchema as W, DEFAULT_SLACK_APP_NAME as X, DEFAULT_LINK as Y, DEFAULT_SLACK_COMMAND as Z, renderMcpError as _, BOARD_TICK_MS as a, inboundEventSchema as b, batchSchema as c, buildCatalogSnapshot as d, plainHttpAllowed as et, roleCanUseOperation as f, renderJsonError as g, renderHttpProblem as h, tokenRequestSchema as i, SLACK_BOT_SCOPES as it, prFactsSchema as j, isExternalAuthor as k, entityRefSchema as l, turnHandedSchema as m, TOKEN_REQUEST_LIMITS as n, COLUMN_IDS as nt, SYSTEMD_SERVICE_SETTINGS as o, OPERATIONS as p, successEnvelopeSchema as q, requestHashOf as r, DISPATCHER_MODES as rt, AdapterError as s, assertNever as t, requiredSecretKeys as tt, sourceCursorSchema as u, SPACE_IDS as v, EVENT_KINDS as w, interactionRefSchema as x, conversationRefSchema as y, parseActorId as z };
3765
+ export { errorEnvelopeSchema as $, EVENT_KINDS as A, sessionFactsSchema as B, renderMcpError as C, interactionRefSchema as D, inboundEventSchema as E, isExternalAuthor as F, encodeActorId as G, JIRA_PROJECT_KEY as H, parseRingMarker as I, parseRef as J, errorCodeOf as K, prFactsSchema as L, REVIEW_STATES as M, SESSION_HEALTH_STATES as N, messageRefSchema as O, SESSION_STATUSES as P, errorContextSchema as Q, prRefSchema as R, renderJsonError as S, conversationRefSchema as T, REF_NUMBER as U, ticketFactsSchema as V, actorIdSchema as W, ERRORS as X, taskKeySchema as Y, err as Z, buildCatalogSnapshot as _, requestHashOf as a, DEFAULT_SLACK_COMMAND as at, turnHandedSchema as b, tokenRequestStatusSchema as c, plainHttpAllowed as ct, AdapterError as d, DISPATCHER_MODES as dt, ok as et, batchSchema as f, SLACK_BOT_SCOPES as ft, trackerSourceId as g, sourceCursorSchema as h, TOKEN_REQUEST_LIMITS as i, DEFAULT_SLACK_APP_NAME as it, eventPayloadSchemas as j, userIdSchema as k, BOARD_TICK_MS as l, requiredSecretKeys as lt, prSourceId as m, doctorReportSchema as n, DEFAULT_HTTP_PORT as nt, tokenRequestResultSchema as o, RESERVED_PROJECT as ot, entityRefSchema as p, parseActorId as q, remoteDoctorReportSchema as r, DEFAULT_LINK as rt, tokenRequestSchema as s, configSchema as st, assertNever as t, successEnvelopeSchema as tt, SYSTEMD_SERVICE_SETTINGS as u, COLUMN_IDS as ut, roleCanUseOperation as v, SPACE_IDS as w, renderHttpProblem as x, OPERATIONS as y, ringMarker as z };
@@ -1,4 +1,4 @@
1
- import { G as errorEnvelopeSchema, H as ERRORS, W as errorContextSchema, g as renderJsonError, q as successEnvelopeSchema } from "./src-Dy1XbpPP.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-DyHtyPom.mjs";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { z } from "zod";
4
4
  import { request } from "node:http";
@@ -195,11 +195,6 @@ function fetchCatalogVersion(config) {
195
195
  }
196
196
  });
197
197
  }
198
- const enrollmentOutput = z.strictObject({
199
- name: z.string(),
200
- status: z.literal("pending"),
201
- expiresAt: z.iso.datetime()
202
- });
203
198
  /** Bootstrap sends a hash and no authorization header. */
204
199
  function requestTokenEnrollment(input, config) {
205
200
  return send({
@@ -208,17 +203,9 @@ function requestTokenEnrollment(input, config) {
208
203
  body: input,
209
204
  config,
210
205
  anonymous: true,
211
- decode: (response, raw) => decodeResponse(enrollmentOutput, response, raw)
206
+ decode: (response, raw) => decodeResponse(tokenRequestResultSchema, response, raw)
212
207
  });
213
208
  }
214
- const tokenStatusOutput = z.strictObject({ status: z.enum([
215
- "pending",
216
- "approved",
217
- "denied",
218
- "expired",
219
- "revoked",
220
- "unknown"
221
- ]) });
222
209
  /** The daemon's state for a token hash; sends no authorization header. */
223
210
  function fetchTokenStatus(hash, config) {
224
211
  return send({
@@ -227,7 +214,7 @@ function fetchTokenStatus(hash, config) {
227
214
  body: { hash },
228
215
  config,
229
216
  anonymous: true,
230
- decode: (response, raw) => decodeResponse(tokenStatusOutput, response, raw)
217
+ decode: (response, raw) => decodeResponse(tokenRequestStatusSchema, response, raw)
231
218
  });
232
219
  }
233
220
  const skillReloadOutput = z.strictObject({
package/dist/cli.mjs CHANGED
@@ -1,6 +1,7 @@
1
- import { $ as configSchema, H as ERRORS, I as actorIdSchema, f as roleCanUseOperation, it as SLACK_BOT_SCOPES, o as SYSTEMD_SERVICE_SETTINGS, p as OPERATIONS, q as successEnvelopeSchema, r as requestHashOf, tt as requiredSecretKeys } from "./src-Dy1XbpPP.mjs";
2
- 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 "./client-BTgz-Fib.mjs";
3
- 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 "./config-DbMBAXe3.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-DyHtyPom.mjs";
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";
4
5
  import { createHash, randomBytes, randomUUID } from "node:crypto";
5
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";
6
7
  import { homedir, hostname, userInfo } from "node:os";
@@ -328,40 +329,23 @@ const remoteSlackIds = [
328
329
  "slack.feed_member",
329
330
  "slack.command"
330
331
  ];
331
- const remoteIds = [
332
- ...remoteBaseIds,
333
- ...remoteSlackIds,
334
- "slack.configured"
335
- ];
336
332
  function remoteIdSet(slackConfigured) {
337
333
  return [...remoteBaseIds, ...slackConfigured ? remoteSlackIds : ["slack.configured"]];
338
334
  }
339
- function remoteChecks(value) {
340
- if (!value || typeof value !== "object" || !("version" in value) || !("checks" in value)) return null;
341
- if (typeof value.version !== "string" || !Array.isArray(value.checks)) return null;
342
- const checks = [];
343
- for (const entry of value.checks) {
344
- if (entry === null || typeof entry !== "object" || !("id" in entry) || !("status" in entry) || !("blocking" in entry) || !("fix" in entry) || typeof entry.id !== "string" || !remoteIds.some((id) => id === entry.id) || typeof entry.status !== "string" || ![
345
- "pass",
346
- "fail",
347
- "warning"
348
- ].includes(entry.status) || typeof entry.blocking !== "boolean" || entry.fix !== null && typeof entry.fix !== "string") return null;
349
- checks.push({
350
- id: entry.id,
351
- status: entry.status,
352
- blocking: entry.blocking,
353
- fix: entry.fix
354
- });
355
- }
356
- const ids = new Set(checks.map((entry) => entry.id));
357
- if (![true, false].some((slackConfigured) => {
358
- const expected = remoteIdSet(slackConfigured);
359
- return checks.length === expected.length && expected.every((id) => ids.has(id));
360
- })) return null;
361
- return {
362
- version: value.version,
363
- checks
364
- };
335
+ const unreportedFix = "The daemon did not report this check. Restart the user service so the daemon runs the installed version, then rerun board doctor.";
336
+ /**
337
+ * The daemon's checks to show: any id it sends, except one the CLI checks itself or sent twice,
338
+ * plus a warning for each check this version expects but the daemon left out.
339
+ */
340
+ function remoteMerge(remote, localIds, slackConfigured) {
341
+ const reported = new Set(remote.map((check) => check.id));
342
+ const slack = reported.has("slack.configured") ? false : remoteSlackIds.some((id) => reported.has(id)) || slackConfigured;
343
+ const seen = new Set(localIds);
344
+ return [...remote.filter((check) => {
345
+ if (seen.has(check.id)) return false;
346
+ seen.add(check.id);
347
+ return true;
348
+ }), ...remoteIdSet(slack).filter((id) => id !== "secrets" && !reported.has(id)).map((id) => warning(id, unreportedFix))];
365
349
  }
366
350
  function safeIds(values) {
367
351
  return values.filter((id) => /^[a-zA-Z0-9_-]+$/.test(id)).slice(0, 10);
@@ -424,7 +408,7 @@ const spurProjectConfig = z.object({
424
408
  /** Spur's own project list is the only source of each project's main checkout path. */
425
409
  async function spurProjectPaths(baseUrl, ports) {
426
410
  try {
427
- const response = await ports.fetcher(new URL("projects", `${baseUrl.replace(/\/$/, "")}/`), { signal: AbortSignal.timeout(5e3) });
411
+ const response = await ports.fetcher(new URL("projects", apiBaseUrl(baseUrl)), { signal: AbortSignal.timeout(5e3) });
428
412
  if (!response.ok) return null;
429
413
  const parsed = spurProjectList.safeParse(await response.json());
430
414
  return parsed.success ? new Map(parsed.data.map((project) => [project.id, project.path])) : null;
@@ -557,7 +541,10 @@ async function runDoctor(options = {}) {
557
541
  try {
558
542
  const address = resolveDaemonAddress(env, home, config.http.port);
559
543
  const response = await ports.fetcher(new URL("/v1/doctor", address), { signal: AbortSignal.timeout(8e3) });
560
- if (response.ok) remote = remoteChecks(await response.json());
544
+ if (response.ok) {
545
+ const parsed = remoteDoctorReportSchema.safeParse(await response.json());
546
+ if (parsed.success) remote = parsed.data;
547
+ }
561
548
  } catch {}
562
549
  checks.push(result("daemon.available", remote !== null, "Start or restart the user service."));
563
550
  const secrets = localSecrets(config, join(dirname(configFile(env, home)), "secrets.env"), ports);
@@ -568,8 +555,12 @@ async function runDoctor(options = {}) {
568
555
  blocking: true,
569
556
  fix: daemonSecrets.fix ?? "Add the missing required keys to secrets.env and restart the daemon."
570
557
  } : secrets);
571
- if (remote === null) checks.push(...remoteIdSet(Boolean(config.slack.channels.feed || config.slack.channels.orchestrators)).filter((id) => id !== "secrets").map((id) => warning(id, id === "slack.configured" ? "Slack is not configured: questions addressed to you are only visible through board inbox. Run the spur-board-setup skill to configure slack.channels." : "Start the daemon, then rerun board doctor to complete this check.")));
572
- else checks.push(...remote.checks.filter((check) => check.id !== "secrets"));
558
+ const slackConfigured = Boolean(config.slack.channels.feed || config.slack.channels.orchestrators);
559
+ if (remote === null) checks.push(...remoteIdSet(slackConfigured).filter((id) => id !== "secrets").map((id) => warning(id, id === "slack.configured" ? "Slack is not configured: questions addressed to you are only visible through board inbox. Run the spur-board-setup skill to configure slack.channels." : "Start the daemon, then rerun board doctor to complete this check.")));
560
+ else {
561
+ const localIds = /* @__PURE__ */ new Set([...checks.map((check) => check.id), "versions"]);
562
+ checks.push(...remoteMerge(remote.checks, localIds, slackConfigured));
563
+ }
573
564
  const availableVersions = [
574
565
  ...currentBoard.exitCode === 0 ? [currentBoard.stdout.trim()] : [],
575
566
  ...spurBoard?.exitCode === 0 ? [spurBoard.stdout.trim()] : [],
@@ -583,7 +574,8 @@ function renderDoctor(checks, json) {
583
574
  if (json) return JSON.stringify(checks);
584
575
  return checks.map((check) => {
585
576
  const present = check.present === void 0 ? "" : ` (present: ${check.present.join(", ") || "none"})`;
586
- return `${check.status.toUpperCase()} ${check.id}${present}${check.fix === null ? "" : `: ${check.fix}`}`;
577
+ const fix = check.fix === null ? "" : `: ${check.fix}`;
578
+ return escapeTerminalControls(`${check.status.toUpperCase()} ${check.id}${present}${fix}`);
587
579
  }).join("\n");
588
580
  }
589
581
  //#endregion
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 "./client-BTgz-Fib.mjs";
1
+ import { a as requestTokenEnrollment, i as requestSkillReload, n as fetchTokenStatus, r as requestOperation, t as fetchCatalogVersion } from "./chunk-Z9DFhl-U.mjs";
2
2
  export { fetchCatalogVersion, fetchTokenStatus, requestOperation, requestSkillReload, requestTokenEnrollment };