spur-board 0.11.3 → 0.12.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,15 +1,17 @@
1
- import { H as requiredSecretKeys, N as ERRORS, U as SLACK_BOT_SCOPES, V as configSchema, c as roleCanUseOperation, l as OPERATIONS, n as SYSTEMD_SERVICE_SETTINGS } from "./src-CjlXSUX-.mjs";
2
- import { a as errorExitCode, i as CliError, n as requestOperation, o as renderCliError, r as requestTokenEnrollment, s as escapeTerminalControls } from "./client-B3aIcQ5T.mjs";
3
- import { a as memoryVerdictCache, c as loadEnrollmentConfig, i as fileVerdictCache, l as resolveDaemonAddress, n as cliPackageVersion, o as configFile, s as loadClientConfig, t as checkCatalog } from "./config-DWp8J6RP.mjs";
1
+ import { H as requiredSecretKeys, N as ERRORS, U as SLACK_BOT_SCOPES, V as configSchema, c as roleCanUseOperation, l as OPERATIONS, n as SYSTEMD_SERVICE_SETTINGS } from "./src-4YeTky_x.mjs";
2
+ import { a as errorExitCode, i as CliError, n as requestOperation, o as renderCliError, r as requestTokenEnrollment, s as escapeTerminalControls } from "./client-BxeRGI6U.mjs";
3
+ import { a as memoryVerdictCache, c as loadEnrollmentConfig, i as fileVerdictCache, l as readConfiguredPort, n as cliPackageVersion, o as configFile, s as loadClientConfig, t as checkCatalog, u as resolveDaemonAddress } from "./config-BkpjmVZh.mjs";
4
4
  import { createHash, randomBytes, randomUUID } from "node:crypto";
5
5
  import { chmodSync, closeSync, constants, existsSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync, statSync, unlinkSync, writeFileSync } from "node:fs";
6
6
  import { homedir, hostname, userInfo } from "node:os";
7
7
  import { basename, dirname, isAbsolute, join, resolve } from "node:path";
8
8
  import { Command, CommanderError } from "@commander-js/extra-typings";
9
9
  import { z } from "zod";
10
+ import { get } from "node:http";
10
11
  import YAML from "yaml";
11
12
  import { spawn, spawnSync } from "node:child_process";
12
13
  import { parseEnv } from "node:util";
14
+ import { createServer } from "node:net";
13
15
  import { access, cp, lstat, mkdir, readFile, readdir, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
14
16
  import { fileURLToPath } from "node:url";
15
17
  //#region src/manifest.ts
@@ -62,6 +64,70 @@ function renderSlackManifest(options = {}) {
62
64
  }, { lineWidth: 0 });
63
65
  }
64
66
  //#endregion
67
+ //#region src/port.ts
68
+ /** A private copy of the client's check: client.ts is the published entry, so it exports nothing new. */
69
+ const instanceHeader = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
70
+ /** Bind 127.0.0.1:port as the daemon would and close at once; returns the error code, or null when free. */
71
+ function bindLoopback(port) {
72
+ return new Promise((resolve) => {
73
+ const server = createServer();
74
+ server.once("error", (error) => {
75
+ resolve(error.code ?? "unknown error");
76
+ });
77
+ server.listen({
78
+ port,
79
+ host: "127.0.0.1"
80
+ }, () => {
81
+ server.close(() => {
82
+ resolve(null);
83
+ });
84
+ });
85
+ });
86
+ }
87
+ /**
88
+ * Ask the holder for its board instance header over node:http, the client's transport. fetch would
89
+ * refuse ports on its bad-port list (6000, 6667, ...) that the config allows, and would follow a
90
+ * redirect to a daemon on another port; node:http does neither. The deadline is absolute: a socket
91
+ * timeout would reset on every byte a trickling holder sends.
92
+ */
93
+ function isBoardDaemon(port) {
94
+ return new Promise((resolve) => {
95
+ get({
96
+ host: "127.0.0.1",
97
+ port,
98
+ path: "/v1/schema",
99
+ agent: false,
100
+ signal: AbortSignal.timeout(2e3)
101
+ }, (response) => {
102
+ const value = response.headers["x-board-instance"];
103
+ response.destroy();
104
+ resolve(typeof value === "string" && instanceHeader.test(value));
105
+ }).once("error", () => {
106
+ resolve(false);
107
+ });
108
+ });
109
+ }
110
+ async function holderOf(port, probe) {
111
+ let listed = "";
112
+ try {
113
+ const result = await probe.run("ss", ["-ltnp", `sport = :${String(port)}`]);
114
+ if (result.exitCode === 0) listed = result.stdout;
115
+ } catch {}
116
+ const match = /users:\(\("([^"]*)",pid=(\d+)/.exec(listed);
117
+ if (match?.[1] === void 0 || match[2] === void 0) return "a process not visible to this user";
118
+ return `${escapeTerminalControls(match[1])} (pid ${match[2]})`;
119
+ }
120
+ /** The fix when the daemon could not listen on http.port, or null when it is 0, free or held by a board daemon. */
121
+ async function checkHttpPort(port, probe) {
122
+ if (port === 0) return null;
123
+ const code = await probe.bind(port);
124
+ if (code === null) return null;
125
+ const label = `Port ${String(port)} (http.port)`;
126
+ if (code !== "EADDRINUSE") return `${label} cannot be bound on 127.0.0.1 (${escapeTerminalControls(code)}). Set http.port in config.yaml to a free unprivileged port.`;
127
+ if (await isBoardDaemon(port)) return null;
128
+ return `${label} is held by ${await holderOf(port, probe)}. Stop that process or set http.port in config.yaml to a free port, then start the service again.`;
129
+ }
130
+ //#endregion
65
131
  //#region src/doctor.ts
66
132
  function systemRun(command, args, env) {
67
133
  const result = spawnSync(command, [...args], {
@@ -139,7 +205,8 @@ const defaultPorts = {
139
205
  const value = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
140
206
  if (value && typeof value === "object" && "version" in value && typeof value.version === "string") return value.version;
141
207
  throw new Error("Invalid package version");
142
- }
208
+ },
209
+ bind: bindLoopback
143
210
  };
144
211
  function result(id, ok, fix) {
145
212
  return {
@@ -339,6 +406,11 @@ async function runDoctor(options = {}) {
339
406
  const unknownStarts = sessions.some((session) => session.startAt === void 0);
340
407
  const staleIds = stale.map((session) => session.id).filter((id) => /^[a-zA-Z0-9_-]+$/.test(id)).slice(0, 10);
341
408
  checks.push(stale.length > 0 || unknownStarts ? warning("sessions.stale", `Restart sessions started before the last skill install${staleIds.length ? `: ${staleIds.join(", ")}` : ""}; verify sessions whose start time is unavailable.`) : result("sessions.stale", true, "Restart older sessions."));
409
+ const portFix = await checkHttpPort(config.http.port, {
410
+ bind: ports.bind,
411
+ run: (command, args) => Promise.resolve(ports.run(command, args))
412
+ });
413
+ checks.push(result("http.port", portFix === null, portFix ?? ""));
342
414
  let remote = null;
343
415
  try {
344
416
  const address = resolveDaemonAddress(env, home, config.http.port);
@@ -481,6 +553,11 @@ async function installService(options = {}) {
481
553
  const paths = servicePaths(options);
482
554
  await preflight(paths);
483
555
  const runner = options.runner ?? runCommand;
556
+ const fix = await checkHttpPort(readConfiguredPort(options.env ?? process.env, resolve(options.home ?? homedir())), {
557
+ bind: options.bind ?? bindLoopback,
558
+ run: runner
559
+ });
560
+ if (fix !== null) throw new Error(fix);
484
561
  const unit = renderUserUnit(paths);
485
562
  const previousUnit = await existingUnit(paths.unitFile);
486
563
  const changed = previousUnit !== unit;
@@ -1,4 +1,4 @@
1
- import { F as errorEnvelopeSchema, I as successEnvelopeSchema, N as ERRORS, P as errorContextSchema, d as renderJsonError } from "./src-CjlXSUX-.mjs";
1
+ import { F as errorEnvelopeSchema, I as successEnvelopeSchema, N as ERRORS, P as errorContextSchema, d as renderJsonError } from "./src-4YeTky_x.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-B3aIcQ5T.mjs";
1
+ import { n as requestOperation, r as requestTokenEnrollment, t as fetchCatalogVersion } from "./client-BxeRGI6U.mjs";
2
2
  export { fetchCatalogVersion, requestOperation, requestTokenEnrollment };
@@ -1,5 +1,5 @@
1
- import { V as configSchema, l as OPERATIONS, s as buildCatalogSnapshot } from "./src-CjlXSUX-.mjs";
2
- import { i as CliError, t as fetchCatalogVersion } from "./client-B3aIcQ5T.mjs";
1
+ import { L as DEFAULT_HTTP_PORT, V as configSchema, l as OPERATIONS, s as buildCatalogSnapshot } from "./src-4YeTky_x.mjs";
2
+ import { i as CliError, t as fetchCatalogVersion } from "./client-BxeRGI6U.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";
@@ -15,17 +15,21 @@ function configFile(env, home) {
15
15
  const xdg = env["XDG_CONFIG_HOME"];
16
16
  return join(xdg && isAbsolute(xdg) ? xdg : join(home, ".config"), "spur-board", "config.yaml");
17
17
  }
18
+ /** The http.port in config.yaml, or the default when the file is missing or invalid. */
19
+ function readConfiguredPort(env, home) {
20
+ try {
21
+ const parsed = YAML.parseDocument(readFileSync(configFile(env, home), "utf8"));
22
+ if (parsed.errors.length === 0) {
23
+ const config = configSchema.safeParse(parsed.toJS());
24
+ if (config.success) return config.data.http.port;
25
+ }
26
+ } catch {}
27
+ return DEFAULT_HTTP_PORT;
28
+ }
18
29
  function resolveDaemonAddress(env = process.env, home = homedir(), configuredPort) {
19
30
  const rawAddress = env["BOARD_DAEMON_URL"];
20
31
  if (rawAddress === void 0) {
21
- let port = configuredPort ?? 4311;
22
- if (configuredPort === void 0) try {
23
- const parsed = YAML.parseDocument(readFileSync(configFile(env, home), "utf8"));
24
- if (parsed.errors.length === 0) {
25
- const config = configSchema.safeParse(parsed.toJS());
26
- if (config.success) port = config.data.http.port;
27
- }
28
- } catch {}
32
+ const port = configuredPort ?? readConfiguredPort(env, home);
29
33
  if (port === 0) throw new CliError("config", void 0, void 0, "http.port: 0 assigns a runtime port that clients cannot discover. Set BOARD_DAEMON_URL to the daemon listening address.");
30
34
  return new URL(`http://127.0.0.1:${String(port)}`);
31
35
  }
@@ -229,4 +233,4 @@ function fileVerdictCache(path, cliVersion) {
229
233
  } };
230
234
  }
231
235
  //#endregion
232
- export { memoryVerdictCache as a, loadEnrollmentConfig as c, fileVerdictCache as i, resolveDaemonAddress as l, cliPackageVersion as n, configFile as o, compareCatalogs as r, loadClientConfig as s, checkCatalog as t };
236
+ export { memoryVerdictCache as a, loadEnrollmentConfig as c, fileVerdictCache as i, readConfiguredPort as l, cliPackageVersion as n, configFile as o, compareCatalogs as r, loadClientConfig as s, checkCatalog as t, resolveDaemonAddress as u };
package/dist/daemon.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { A as parseActorId, B as RESERVED_PROJECT, C as prFactsSchema, D as actorIdSchema, E as ticketFactsSchema, H as requiredSecretKeys, I as successEnvelopeSchema, M as taskKeySchema, N as ERRORS, O as encodeActorId, S as SESSION_STATUSES, T as sessionFactsSchema, U as SLACK_BOT_SCOPES, V as configSchema, _ as messageRefSchema, a as entityRefSchema, b as eventPayloadSchemas, c as roleCanUseOperation, g as interactionRefSchema, h as inboundEventSchema, i as batchSchema, j as parseRef$1, k as errorCodeOf, l as OPERATIONS, m as conversationRefSchema, o as sourceCursorSchema, p as SPACE_IDS, r as AdapterError, s as buildCatalogSnapshot, t as BOARD_TICK_MS, u as renderHttpProblem, v as userIdSchema, w as prRefSchema, x as SESSION_HEALTH_STATES, y as EVENT_KINDS, z as DEFAULT_SLACK_COMMAND } from "./src-CjlXSUX-.mjs";
1
+ import { A as parseActorId, B as RESERVED_PROJECT, C as prFactsSchema, D as actorIdSchema, E as ticketFactsSchema, H as requiredSecretKeys, I as successEnvelopeSchema, M as taskKeySchema, N as ERRORS, O as encodeActorId, S as SESSION_STATUSES, T as sessionFactsSchema, U as SLACK_BOT_SCOPES, V as configSchema, _ as messageRefSchema, a as entityRefSchema, b as eventPayloadSchemas, c as roleCanUseOperation, g as interactionRefSchema, h as inboundEventSchema, i as batchSchema, j as parseRef$1, k as errorCodeOf, l as OPERATIONS, m as conversationRefSchema, o as sourceCursorSchema, p as SPACE_IDS, r as AdapterError, s as buildCatalogSnapshot, t as BOARD_TICK_MS, u as renderHttpProblem, v as userIdSchema, w as prRefSchema, x as SESSION_HEALTH_STATES, y as EVENT_KINDS, z as DEFAULT_SLACK_COMMAND } from "./src-4YeTky_x.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import { createHash, randomUUID } from "node:crypto";
4
4
  import { closeSync, existsSync, fstatSync, ftruncateSync, mkdirSync, openSync, readFileSync, readdirSync, writeSync } from "node:fs";
@@ -13816,6 +13816,8 @@ const milestoneWire = z.object({
13816
13816
  title: z.string(),
13817
13817
  number: z.int().positive()
13818
13818
  });
13819
+ const repositoryWire = z.object({ id: z.int().positive() });
13820
+ const PAGINATION = "Malformed GitHub issue pagination";
13819
13821
  function issueNumber(ref, repo) {
13820
13822
  const match = /^(.+)#([1-9]\d*)$/.exec(ref.key);
13821
13823
  if (match?.[1]?.toLowerCase() !== repo.toLowerCase()) throw new AdapterError("config", "Requested issue is outside its configured repository");
@@ -13878,22 +13880,32 @@ function createGithubIssuesAdapter(options) {
13878
13880
  throw new AdapterError("transient", "Malformed GitHub issue response");
13879
13881
  }
13880
13882
  const next = response.headers.get("link")?.match(/<([^>]+)>;\s*rel="next"/)?.[1];
13881
- if (next !== void 0) {
13882
- let pageUrl;
13883
- try {
13884
- pageUrl = new URL(next);
13885
- } catch {
13886
- throw new AdapterError("transient", "Malformed GitHub issue pagination");
13887
- }
13888
- const issuePath = new URL(root).pathname + "/issues";
13889
- const milestonePath = new URL(root).pathname + "/milestones";
13890
- if (pageUrl.origin !== "https://api.github.com" || pageUrl.pathname !== issuePath && pageUrl.pathname !== milestonePath) throw new AdapterError("transient", "Malformed GitHub issue pagination");
13891
- }
13892
13883
  return {
13893
13884
  value,
13894
13885
  ...next === void 0 ? {} : { next }
13895
13886
  };
13896
13887
  }
13888
+ let repositoryId;
13889
+ /** Rejects a next link outside this repository before any request goes to it. */
13890
+ async function checkNext(next, signal) {
13891
+ let pageUrl;
13892
+ try {
13893
+ pageUrl = new URL(next);
13894
+ } catch {
13895
+ throw new AdapterError("transient", PAGINATION);
13896
+ }
13897
+ const base = new URL(root);
13898
+ if (pageUrl.origin !== base.origin) throw new AdapterError("transient", PAGINATION);
13899
+ if (pageUrl.pathname === base.pathname + "/issues") return;
13900
+ if (pageUrl.pathname === base.pathname + "/milestones") return;
13901
+ const match = /^\/repositories\/([1-9]\d*)\/(?:issues|milestones)$/.exec(pageUrl.pathname);
13902
+ if (match === null) throw new AdapterError("transient", PAGINATION);
13903
+ repositoryId ??= parseWire(repositoryWire, (await request(root, signal)).value, MALFORMED).id;
13904
+ if (Number(match[1]) !== repositoryId) {
13905
+ repositoryId = void 0;
13906
+ throw new AdapterError("transient", PAGINATION);
13907
+ }
13908
+ }
13897
13909
  async function pages(url, signal, allowPartial = false) {
13898
13910
  const results = [];
13899
13911
  const seen = /* @__PURE__ */ new Set();
@@ -13912,6 +13924,15 @@ function createGithubIssuesAdapter(options) {
13912
13924
  throw error;
13913
13925
  }
13914
13926
  results.push(...parseWire(z.array(z.unknown()), page.value, "Malformed GitHub issue listing"));
13927
+ if (page.next !== void 0) try {
13928
+ await checkNext(page.next, signal);
13929
+ } catch (error) {
13930
+ if (allowPartial && error instanceof AdapterError && error.kind === "transient") return {
13931
+ values: results,
13932
+ complete: false
13933
+ };
13934
+ throw error;
13935
+ }
13915
13936
  next = page.next;
13916
13937
  }
13917
13938
  return {
package/dist/mcp.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { N as ERRORS, f as renderMcpError, l as OPERATIONS } from "./src-CjlXSUX-.mjs";
2
- import { i as CliError, n as requestOperation } from "./client-B3aIcQ5T.mjs";
3
- import { a as memoryVerdictCache, r as compareCatalogs, s as loadClientConfig, t as checkCatalog } from "./config-DWp8J6RP.mjs";
1
+ import { N as ERRORS, f as renderMcpError, l as OPERATIONS } from "./src-4YeTky_x.mjs";
2
+ import { i as CliError, n as requestOperation } from "./client-BxeRGI6U.mjs";
3
+ import { a as memoryVerdictCache, r as compareCatalogs, s as loadClientConfig, t as checkCatalog } from "./config-BkpjmVZh.mjs";
4
4
  import { randomUUID } from "node:crypto";
5
5
  import { readFileSync } from "node:fs";
6
6
  import { z } from "zod";
@@ -110,7 +110,13 @@ const SLACK_BOT_SCOPES = [
110
110
  ];
111
111
  //#endregion
112
112
  //#region ../contracts/src/config.ts
113
- const DEFAULT_HTTP_PORT = 4311;
113
+ /**
114
+ * The daemon's default loopback port. It sits above 4310-4399, a margin the board keeps for
115
+ * Spur's server port 4310 and the ports from 4311 upward that Spur's MCP port takes. It also
116
+ * avoids Spur's web UI port 5555, its Playwright sidecars 8730-8799 and the Linux ephemeral
117
+ * range 32768-60999.
118
+ */
119
+ const DEFAULT_HTTP_PORT = 4777;
114
120
  const DEFAULT_SLACK_APP_NAME = "spur-board";
115
121
  const DEFAULT_SLACK_COMMAND = "/board";
116
122
  /**
@@ -289,7 +295,7 @@ const configSchema = z.strictObject({
289
295
  message: "Final unanswered pause must exceed the second retry pause"
290
296
  });
291
297
  }).prefault({}),
292
- http: z.strictObject({ port: z.int().min(0).max(65535).default(DEFAULT_HTTP_PORT).describe("Local HTTP API port (0 assigns a free port).") }).prefault({}),
298
+ http: z.strictObject({ port: z.int().min(0).max(65535).default(DEFAULT_HTTP_PORT).describe("Local HTTP API port (0 assigns a free port). The default 4777 is above 4310-4399, a margin kept for Spur's server port 4310 and the ports from 4311 upward that its MCP port takes, and avoids Spur's ports 5555 and 8730-8799 and the Linux ephemeral range 32768-60999.") }).prefault({}),
293
299
  adapters: z.strictObject({
294
300
  spur: spurAdapterSection,
295
301
  github: adapterSection(6e4),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spur-board",
3
- "version": "0.11.3",
3
+ "version": "0.12.0",
4
4
  "license": "MIT",
5
5
  "engines": {
6
6
  "node": "^24.12.0 || ^26.0.0"