spur-board 0.15.2 → 0.16.1
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 +3 -3
- package/dist/{client-FoFGbc11.mjs → client-CwKmG23X.mjs} +1 -1
- package/dist/client.mjs +1 -1
- package/dist/{config-6Nm4MFGe.mjs → config-CXDupHSC.mjs} +2 -2
- package/dist/daemon.mjs +131 -53
- package/dist/mcp.mjs +3 -3
- package/dist/migrations/0011_session_absent_since.sql +2 -0
- package/dist/{src-eVAzSAsk.mjs → src-ep5scuVt.mjs} +30 -9
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as errorExitCode, i as CliError, n as requestOperation, o as renderCliError, r as requestTokenEnrollment, s as escapeTerminalControls } from "./client-
|
|
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-
|
|
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-ep5scuVt.mjs";
|
|
2
|
+
import { a as errorExitCode, i as CliError, n as requestOperation, o as renderCliError, r as requestTokenEnrollment, s as escapeTerminalControls } from "./client-CwKmG23X.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-CXDupHSC.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";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as
|
|
1
|
+
import { F as errorContextSchema, I as errorEnvelopeSchema, L as successEnvelopeSchema, P as ERRORS, f as renderJsonError } from "./src-ep5scuVt.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-
|
|
1
|
+
import { n as requestOperation, r as requestTokenEnrollment, t as fetchCatalogVersion } from "./client-CwKmG23X.mjs";
|
|
2
2
|
export { fetchCatalogVersion, requestOperation, requestTokenEnrollment };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as CliError, t as fetchCatalogVersion } from "./client-
|
|
1
|
+
import { R as DEFAULT_HTTP_PORT, U as configSchema, c as buildCatalogSnapshot, u as OPERATIONS } from "./src-ep5scuVt.mjs";
|
|
2
|
+
import { i as CliError, t as fetchCatalogVersion } from "./client-CwKmG23X.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
|
|
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-ep5scuVt.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";
|
|
@@ -8778,13 +8778,25 @@ async function journalToken(trx, kind, name, at) {
|
|
|
8778
8778
|
request_id: null
|
|
8779
8779
|
}).execute();
|
|
8780
8780
|
}
|
|
8781
|
+
/** Lapse one pending request: journal it once and clear its approval item. */
|
|
8782
|
+
async function expireToken(trx, row, at) {
|
|
8783
|
+
await trx.updateTable("operator_token").set({
|
|
8784
|
+
status: "expired",
|
|
8785
|
+
decided_at: at.toISOString()
|
|
8786
|
+
}).where("id", "=", row.id).execute();
|
|
8787
|
+
await journalToken(trx, "token_expired", row.name, at);
|
|
8788
|
+
await clearItem(trx, row.item_id, at);
|
|
8789
|
+
}
|
|
8781
8790
|
/** Register a hash and its approval item together. The raw file secret never reaches this app. */
|
|
8782
8791
|
async function requestToken(store, input, at) {
|
|
8783
8792
|
if (!/^[0-9a-f]{64}$/.test(input.hash) || input.name.trim() === "" || input.folder.trim() === "") throw new CommandError("usage", "Provide a name, folder and SHA-256 token hash.");
|
|
8784
8793
|
const expiresAt = new Date(at.getTime() + REQUEST_LIFETIME_MS).toISOString();
|
|
8785
8794
|
return scanTransaction(store, async (trx) => {
|
|
8786
|
-
|
|
8795
|
+
const existing = await trx.selectFrom("operator_token").selectAll().where("name", "=", input.name).executeTakeFirst();
|
|
8796
|
+
const status = existing === void 0 ? void 0 : effectiveStatus(existing, at);
|
|
8797
|
+
if (status === "pending" || status === "approved" || status === "revoked") throw new CommandError("usage", `Token name ${input.name} is taken; choose another name (see \`board token list\`).`);
|
|
8787
8798
|
if ((await trx.selectFrom("operator_token").select("id").where("status", "=", "pending").where("expires_at", ">", at.toISOString()).limit(MAX_PENDING_REQUESTS).execute()).length >= MAX_PENDING_REQUESTS) throw new CommandError("usage", "Too many token requests are awaiting approval.");
|
|
8799
|
+
if (existing?.status === "pending") await expireToken(trx, existing, at);
|
|
8788
8800
|
const item = await raiseItem(trx, {
|
|
8789
8801
|
itemKey: `token:${input.name}`,
|
|
8790
8802
|
kind: "token_request",
|
|
@@ -8794,8 +8806,7 @@ async function requestToken(store, input, at) {
|
|
|
8794
8806
|
blockId: null,
|
|
8795
8807
|
at
|
|
8796
8808
|
});
|
|
8797
|
-
|
|
8798
|
-
name: input.name,
|
|
8809
|
+
const values = {
|
|
8799
8810
|
hash: input.hash,
|
|
8800
8811
|
folder: input.folder,
|
|
8801
8812
|
host: input.host,
|
|
@@ -8804,7 +8815,12 @@ async function requestToken(store, input, at) {
|
|
|
8804
8815
|
expires_at: expiresAt,
|
|
8805
8816
|
decided_at: null,
|
|
8806
8817
|
item_id: item.id
|
|
8818
|
+
};
|
|
8819
|
+
if (existing === void 0) await trx.insertInto("operator_token").values({
|
|
8820
|
+
name: input.name,
|
|
8821
|
+
...values
|
|
8807
8822
|
}).execute();
|
|
8823
|
+
else await trx.updateTable("operator_token").set(values).where("id", "=", existing.id).execute();
|
|
8808
8824
|
await journalToken(trx, "token_requested", input.name, at);
|
|
8809
8825
|
return {
|
|
8810
8826
|
name: input.name,
|
|
@@ -8819,14 +8835,7 @@ async function decideTokenInTransaction(trx, itemId, decision, at) {
|
|
|
8819
8835
|
if (row === void 0) throw new CommandError("not_found", "Token request was not found.");
|
|
8820
8836
|
const status = effectiveStatus(row, at);
|
|
8821
8837
|
if (status !== "pending") {
|
|
8822
|
-
if (status === "expired" && row.status === "pending")
|
|
8823
|
-
await trx.updateTable("operator_token").set({
|
|
8824
|
-
status: "expired",
|
|
8825
|
-
decided_at: at.toISOString()
|
|
8826
|
-
}).where("id", "=", row.id).execute();
|
|
8827
|
-
await journalToken(trx, "token_expired", row.name, at);
|
|
8828
|
-
await clearItem(trx, row.item_id, at);
|
|
8829
|
-
}
|
|
8838
|
+
if (status === "expired" && row.status === "pending") await expireToken(trx, row, at);
|
|
8830
8839
|
return {
|
|
8831
8840
|
name: row.name,
|
|
8832
8841
|
status
|
|
@@ -8854,14 +8863,7 @@ async function expirePendingTokens(store, at) {
|
|
|
8854
8863
|
"name",
|
|
8855
8864
|
"item_id"
|
|
8856
8865
|
]).where("status", "=", "pending").where("expires_at", "<=", expiresAt).execute();
|
|
8857
|
-
for (const row of rows)
|
|
8858
|
-
await trx.updateTable("operator_token").set({
|
|
8859
|
-
status: "expired",
|
|
8860
|
-
decided_at: expiresAt
|
|
8861
|
-
}).where("id", "=", row.id).execute();
|
|
8862
|
-
await journalToken(trx, "token_expired", row.name, at);
|
|
8863
|
-
await clearItem(trx, row.item_id, at);
|
|
8864
|
-
}
|
|
8866
|
+
for (const row of rows) await expireToken(trx, row, at);
|
|
8865
8867
|
return rows.length;
|
|
8866
8868
|
});
|
|
8867
8869
|
}
|
|
@@ -10585,6 +10587,10 @@ async function snapshot(trx, repo, number) {
|
|
|
10585
10587
|
const row = await trx.selectFrom("pr_snapshot").select("detail").where(sql`lower(repo) = ${repo.toLowerCase()}`).where("number", "=", number).executeTakeFirst();
|
|
10586
10588
|
return row === void 0 ? null : parseJson(prFactsSchema, row.detail);
|
|
10587
10589
|
}
|
|
10590
|
+
async function sessionSnapshot(trx, id) {
|
|
10591
|
+
const row = await trx.selectFrom("session_snapshot").select("detail").where("id", "=", id).executeTakeFirst();
|
|
10592
|
+
return row === void 0 ? null : parseJson(sessionFactsSchema, row.detail);
|
|
10593
|
+
}
|
|
10588
10594
|
async function existingLink(trx, taskId, input, ticket) {
|
|
10589
10595
|
let query = trx.selectFrom("link").selectAll().where("task_id", "=", taskId);
|
|
10590
10596
|
if (input.mode === "pr") {
|
|
@@ -10668,6 +10674,7 @@ async function run(trx, input, ctx, config, remove) {
|
|
|
10668
10674
|
target
|
|
10669
10675
|
};
|
|
10670
10676
|
const role = input.mode === "session" ? current?.role ?? await sessionRole(trx, task.id) : null;
|
|
10677
|
+
const session = input.mode === "session" ? await sessionSnapshot(trx, input.session) : null;
|
|
10671
10678
|
if (current === void 0) await trx.insertInto("link").values({
|
|
10672
10679
|
task_id: task.id,
|
|
10673
10680
|
entity: input.mode,
|
|
@@ -10696,12 +10703,14 @@ async function run(trx, input, ctx, config, remove) {
|
|
|
10696
10703
|
pr: pr?.number ?? 0,
|
|
10697
10704
|
state: "active",
|
|
10698
10705
|
source: "manual",
|
|
10706
|
+
...facts === null ? {} : { facts },
|
|
10699
10707
|
reason: input.reason
|
|
10700
10708
|
} : input.mode === "session" ? {
|
|
10701
10709
|
entity: "session",
|
|
10702
10710
|
session: input.session,
|
|
10703
10711
|
role: role ?? "other",
|
|
10704
10712
|
source: "manual",
|
|
10713
|
+
...session === null ? {} : { facts: session },
|
|
10705
10714
|
reason: input.reason
|
|
10706
10715
|
} : {
|
|
10707
10716
|
entity: "ticket",
|
|
@@ -10766,6 +10775,8 @@ function taskState(ticket, prs, sessions) {
|
|
|
10766
10775
|
function issuesRepo(project) {
|
|
10767
10776
|
return project?.tracker.type === "github-issues" ? project.tracker.repo.toLowerCase() : null;
|
|
10768
10777
|
}
|
|
10778
|
+
/** Unlinked PRs and sessions finished longer ago than this are counted, not listed. */
|
|
10779
|
+
const UNLINKED_WINDOW_MS = 10080 * 60 * 1e3;
|
|
10769
10780
|
function interval(config, source) {
|
|
10770
10781
|
if (source === "spur") return config.adapters.spur.intervalMs;
|
|
10771
10782
|
if (source.startsWith("jira:")) return config.adapters.jira.intervalMs;
|
|
@@ -10827,6 +10838,7 @@ async function getStatus(deps, options = {}) {
|
|
|
10827
10838
|
} : {}
|
|
10828
10839
|
});
|
|
10829
10840
|
}
|
|
10841
|
+
const pastWindow = (at) => clock.now() - Date.parse(at) > UNLINKED_WINDOW_MS;
|
|
10830
10842
|
const allPrs = await store.db.selectFrom("pr_snapshot").selectAll().execute();
|
|
10831
10843
|
const allSessions = await store.db.selectFrom("session_snapshot").selectAll().execute();
|
|
10832
10844
|
const allLinks = await store.db.selectFrom("link").selectAll().where("banned", "=", 0).execute();
|
|
@@ -10840,8 +10852,12 @@ async function getStatus(deps, options = {}) {
|
|
|
10840
10852
|
if (facts.ticketKeys.length === 0) return "no key in branch or title by the link rules";
|
|
10841
10853
|
return facts.ticketKeys.some((key) => rows.some((task) => task.project === project.id && task.key === key)) ? void 0 : `no task on the board for ${facts.ticketKeys.join(", ")}`;
|
|
10842
10854
|
};
|
|
10843
|
-
const
|
|
10844
|
-
|
|
10855
|
+
const prRows = allPrs.filter((pr) => projects.some((project) => project.repos.some((repo) => repo.toLowerCase() === pr.repo.toLowerCase())) && !allLinks.some((link) => link.entity === "pr" && link.repo?.toLowerCase() === pr.repo.toLowerCase() && link.number === pr.number)).map((pr) => ({
|
|
10856
|
+
pr,
|
|
10857
|
+
facts: parseJson(prFactsSchema, pr.detail)
|
|
10858
|
+
}));
|
|
10859
|
+
const hiddenPr = (facts) => facts.state !== "open" && pastWindow(facts.updatedAt);
|
|
10860
|
+
const unlinkedPrs = prRows.filter(({ facts }) => !hiddenPr(facts)).map(({ pr, facts }) => {
|
|
10845
10861
|
const reason = unlinkedReason(pr.source, facts);
|
|
10846
10862
|
const why = reason === void 0 ? {} : { reason };
|
|
10847
10863
|
if (detail) return {
|
|
@@ -10859,7 +10875,12 @@ async function getStatus(deps, options = {}) {
|
|
|
10859
10875
|
...why
|
|
10860
10876
|
};
|
|
10861
10877
|
});
|
|
10862
|
-
const
|
|
10878
|
+
const sessionRows = allSessions.filter((session) => projects.some((project) => project.spurProjects.some((spur) => spur.name === session.spur_project)) && !allLinks.some((link) => link.entity === "session" && link.session_id === session.id));
|
|
10879
|
+
/** Ended, or omitted by complete Spur polls, for longer than the window. */
|
|
10880
|
+
const hiddenSession = (session) => {
|
|
10881
|
+
return (session.ended_at !== null || session.state === "completed" || session.state === "killed" || session.absent_since !== null) && pastWindow(session.ended_at ?? session.absent_since ?? session.last_seen);
|
|
10882
|
+
};
|
|
10883
|
+
const unlinkedSessions = sessionRows.filter((session) => !hiddenSession(session)).map((session) => {
|
|
10863
10884
|
const facts = parseJson(sessionFactsSchema, session.detail);
|
|
10864
10885
|
if (detail) return sessionView(facts);
|
|
10865
10886
|
const { id, spurProject, branch, lifecycle, health } = facts;
|
|
@@ -10935,7 +10956,9 @@ async function getStatus(deps, options = {}) {
|
|
|
10935
10956
|
sources,
|
|
10936
10957
|
tasks,
|
|
10937
10958
|
unlinkedPrs,
|
|
10938
|
-
unlinkedSessions
|
|
10959
|
+
unlinkedSessions,
|
|
10960
|
+
hiddenUnlinkedPrs: prRows.length - unlinkedPrs.length,
|
|
10961
|
+
hiddenUnlinkedSessions: sessionRows.length - unlinkedSessions.length
|
|
10939
10962
|
};
|
|
10940
10963
|
}
|
|
10941
10964
|
//#endregion
|
|
@@ -11579,7 +11602,7 @@ async function updateTerminal(trx, config, taskId, at, completeSince, blind) {
|
|
|
11579
11602
|
const complete = completeSince.get(source);
|
|
11580
11603
|
return !blind.has(source) && complete !== void 0 && complete > (task.last_change_at ?? task.created_at);
|
|
11581
11604
|
});
|
|
11582
|
-
const terminal = merged || doneTicket &&
|
|
11605
|
+
const terminal = !hasOpen && (merged || doneTicket && githubComplete);
|
|
11583
11606
|
await trx.updateTable("task").set({ terminal_at: terminal ? task.terminal_at ?? (merged ? at : task.last_change_at ?? at) : null }).where("id", "=", taskId).execute();
|
|
11584
11607
|
}
|
|
11585
11608
|
async function sourceState(trx, source, state, observedAt, cursor) {
|
|
@@ -11853,7 +11876,8 @@ async function session(trx, config, fact, at, source, ambiguousBranches) {
|
|
|
11853
11876
|
end_reason: fact.endReason,
|
|
11854
11877
|
detail: toJson(sessionFactsSchema, fact),
|
|
11855
11878
|
source,
|
|
11856
|
-
observed_at: at
|
|
11879
|
+
observed_at: at,
|
|
11880
|
+
absent_since: null
|
|
11857
11881
|
}).onConflict((oc) => oc.column("id").doUpdateSet({
|
|
11858
11882
|
branch: fact.branch,
|
|
11859
11883
|
pr: fact.pr === null ? null : `${fact.pr.repo}#${String(fact.pr.number)}`,
|
|
@@ -11864,7 +11888,8 @@ async function session(trx, config, fact, at, source, ambiguousBranches) {
|
|
|
11864
11888
|
end_reason: fact.endReason,
|
|
11865
11889
|
detail: toJson(sessionFactsSchema, fact),
|
|
11866
11890
|
source,
|
|
11867
|
-
observed_at: at
|
|
11891
|
+
observed_at: at,
|
|
11892
|
+
absent_since: null
|
|
11868
11893
|
})).execute();
|
|
11869
11894
|
let key;
|
|
11870
11895
|
let role;
|
|
@@ -12044,6 +12069,7 @@ function createObservationCore(deps) {
|
|
|
12044
12069
|
await emit(trx, "session_facts_changed", task.project, task.id, batch.observedAt, { facts: ended });
|
|
12045
12070
|
}
|
|
12046
12071
|
}
|
|
12072
|
+
if (observation.effectiveComplete) await trx.updateTable("session_snapshot").set({ absent_since: batch.observedAt }).where("source", "=", source).where("absent_since", "is", null).where("last_seen", "<", batch.observedAt).execute();
|
|
12047
12073
|
if (observation.effectiveComplete) {
|
|
12048
12074
|
const project = config.projects.find((entry) => trackerSource(entry) === source);
|
|
12049
12075
|
if (project !== void 0) {
|
|
@@ -12280,7 +12306,7 @@ function commandReply(id, value, input) {
|
|
|
12280
12306
|
line(`Board status: ${String(status.tasks.length)} tasks, ${String(status.items.length)} items needing attention.`),
|
|
12281
12307
|
...status.tasks.map((task) => line(`${task.key}: ${task.column} (${task.membership})`)),
|
|
12282
12308
|
...status.items.map((item) => line(`${item.key}: ${item.summary}`)),
|
|
12283
|
-
line(`Unlinked: ${String(status.unlinkedPrs.length)} pull requests, ${String(status.unlinkedSessions.length)} sessions.`),
|
|
12309
|
+
line(`Unlinked: ${String(status.unlinkedPrs.length)} pull requests, ${String(status.unlinkedSessions.length)} sessions${status.hiddenUnlinkedPrs + status.hiddenUnlinkedSessions === 0 ? "" : `; ${String(status.hiddenUnlinkedPrs)} pull requests and ${String(status.hiddenUnlinkedSessions)} sessions finished over 7 days ago are hidden`}.`),
|
|
12284
12310
|
...status.sources.map((source) => line(`${source.source}: ${source.blindReason !== null ? `blind (${source.blindReason})` : source.warmingUp ? "warming up" : source.stale ? "stale" : "current"}`)),
|
|
12285
12311
|
...status.warmingUp ? [line("Sources are warming up.")] : [],
|
|
12286
12312
|
...status.spurUnavailable === null ? [] : [line(status.spurUnavailable)],
|
|
@@ -13555,6 +13581,36 @@ function issuesRule(repo, link) {
|
|
|
13555
13581
|
title: new RegExp(link.titlePattern)
|
|
13556
13582
|
};
|
|
13557
13583
|
}
|
|
13584
|
+
function jiraRule(prefixes, link) {
|
|
13585
|
+
const sources = link.sources.length === DEFAULT_LINK.sources.length && link.sources.every((source, i) => source === DEFAULT_LINK.sources[i]);
|
|
13586
|
+
const branch = link.branchPattern === DEFAULT_LINK.branchPattern;
|
|
13587
|
+
const title = link.titlePattern === DEFAULT_LINK.titlePattern;
|
|
13588
|
+
if (sources && branch && title) return {
|
|
13589
|
+
type: "prefixes",
|
|
13590
|
+
prefixes
|
|
13591
|
+
};
|
|
13592
|
+
return {
|
|
13593
|
+
type: "jira",
|
|
13594
|
+
prefixes,
|
|
13595
|
+
sources: link.sources.filter((source) => source !== "closing"),
|
|
13596
|
+
branch: branch ? void 0 : new RegExp(link.branchPattern),
|
|
13597
|
+
title: title ? void 0 : new RegExp(link.titlePattern)
|
|
13598
|
+
};
|
|
13599
|
+
}
|
|
13600
|
+
/**
|
|
13601
|
+
* The key rule of `repo` in a project: the github-issues tracker repo reads issue numbers by
|
|
13602
|
+
* `link`, its other repos link nothing, and a Jira project's repos read `projectKeys` keys.
|
|
13603
|
+
*/
|
|
13604
|
+
function projectKeyRule(tracker, link, repo) {
|
|
13605
|
+
switch (tracker.type) {
|
|
13606
|
+
case "github-issues": return tracker.repo.toLowerCase() === repo.toLowerCase() ? issuesRule(tracker.repo, link) : {
|
|
13607
|
+
type: "prefixes",
|
|
13608
|
+
prefixes: []
|
|
13609
|
+
};
|
|
13610
|
+
case "jira": return jiraRule(tracker.projectKeys, link);
|
|
13611
|
+
default: return assertNever(tracker);
|
|
13612
|
+
}
|
|
13613
|
+
}
|
|
13558
13614
|
/** Drops denied (null) nodes and nodes without a repository. */
|
|
13559
13615
|
function closingRefs(wire) {
|
|
13560
13616
|
return (wire?.nodes ?? []).flatMap((node) => node?.repository ? [{
|
|
@@ -13624,9 +13680,12 @@ function latestReviews(nodes) {
|
|
|
13624
13680
|
return [...latest.values()].sort((a, b) => a.reviewer.localeCompare(b.reviewer));
|
|
13625
13681
|
}
|
|
13626
13682
|
function ticketKeys(title, branch, prefixes) {
|
|
13683
|
+
return scanKeys(`${title} ${branch}`, prefixes);
|
|
13684
|
+
}
|
|
13685
|
+
function scanKeys(text, prefixes) {
|
|
13627
13686
|
const keys = /* @__PURE__ */ new Set();
|
|
13628
13687
|
const allowed = new Set(prefixes);
|
|
13629
|
-
for (const match of
|
|
13688
|
+
for (const match of text.matchAll(/(?<![A-Za-z0-9_])([A-Z][A-Z0-9_]*)-([1-9][0-9]*)(?![A-Za-z0-9_])/gi)) {
|
|
13630
13689
|
const prefix = match[1]?.toUpperCase();
|
|
13631
13690
|
const number = match[2];
|
|
13632
13691
|
if (prefix !== void 0 && number !== void 0 && allowed.has(prefix)) keys.add(`${prefix}-${number}`);
|
|
@@ -13654,6 +13713,32 @@ function issueKeys(title, branch, refs, rule) {
|
|
|
13654
13713
|
}
|
|
13655
13714
|
return [];
|
|
13656
13715
|
}
|
|
13716
|
+
const JIRA_KEY = /^([A-Z][A-Z0-9_]*)-[1-9][0-9]*$/;
|
|
13717
|
+
function matchedKey(text, pattern, prefixes) {
|
|
13718
|
+
if (text.length > MAX_MATCHED_LENGTH) return [];
|
|
13719
|
+
const key = pattern.exec(text)?.[1]?.toUpperCase();
|
|
13720
|
+
if (key === void 0) return [];
|
|
13721
|
+
const prefix = JIRA_KEY.exec(key)?.[1];
|
|
13722
|
+
return prefix !== void 0 && prefixes.includes(prefix) ? [key] : [];
|
|
13723
|
+
}
|
|
13724
|
+
function jiraKeys(title, branch, rule) {
|
|
13725
|
+
for (const source of rule.sources) {
|
|
13726
|
+
const text = source === "branch" ? branch : title;
|
|
13727
|
+
const pattern = rule[source];
|
|
13728
|
+
const keys = pattern === void 0 ? scanKeys(text, rule.prefixes) : matchedKey(text, pattern, rule.prefixes);
|
|
13729
|
+
if (keys.length > 0) return keys;
|
|
13730
|
+
}
|
|
13731
|
+
return [];
|
|
13732
|
+
}
|
|
13733
|
+
/** The task keys `rule` reads from a PR's title, head branch and closing references. */
|
|
13734
|
+
function prKeys(rule, title, branch, refs) {
|
|
13735
|
+
switch (rule.type) {
|
|
13736
|
+
case "prefixes": return ticketKeys(title, branch, rule.prefixes);
|
|
13737
|
+
case "issues": return issueKeys(title, branch, refs, rule);
|
|
13738
|
+
case "jira": return jiraKeys(title, branch, rule);
|
|
13739
|
+
default: return assertNever(rule);
|
|
13740
|
+
}
|
|
13741
|
+
}
|
|
13657
13742
|
function normalizePr(repo, value, rule) {
|
|
13658
13743
|
const wire = parseWire(prWire, value, "Malformed GitHub PR response");
|
|
13659
13744
|
const checks = latestChecks(wire.statusCheckRollup?.contexts.nodes ?? []);
|
|
@@ -13690,7 +13775,7 @@ function normalizePr(repo, value, rule) {
|
|
|
13690
13775
|
reviewer: node.requestedReviewer.login ?? node.requestedReviewer.name,
|
|
13691
13776
|
asCodeOwner: node.asCodeOwner
|
|
13692
13777
|
})),
|
|
13693
|
-
ticketKeys: rule
|
|
13778
|
+
ticketKeys: prKeys(rule, title, headBranch, closingRefs(wire.closingIssuesReferences)),
|
|
13694
13779
|
updatedAt: wire.updatedAt
|
|
13695
13780
|
};
|
|
13696
13781
|
const parsed = prFactsSchema.safeParse(facts);
|
|
@@ -13718,12 +13803,6 @@ function sourceId(project, repo) {
|
|
|
13718
13803
|
function githubSources(config, options) {
|
|
13719
13804
|
const sources = [];
|
|
13720
13805
|
for (const project of config.projects) {
|
|
13721
|
-
const tracker = project.tracker;
|
|
13722
|
-
const issues = tracker.type === "github-issues" ? issuesRule(tracker.repo, project.link) : void 0;
|
|
13723
|
-
const prefixes = {
|
|
13724
|
-
type: "prefixes",
|
|
13725
|
-
prefixes: tracker.type === "jira" ? tracker.projectKeys : []
|
|
13726
|
-
};
|
|
13727
13806
|
const seen = /* @__PURE__ */ new Set();
|
|
13728
13807
|
for (const repo of project.repos) {
|
|
13729
13808
|
const normalized = repo.toLowerCase();
|
|
@@ -13731,7 +13810,7 @@ function githubSources(config, options) {
|
|
|
13731
13810
|
seen.add(normalized);
|
|
13732
13811
|
const id = sourceId(project.id, repo);
|
|
13733
13812
|
const client = new GithubClient(options.token, options.fetch);
|
|
13734
|
-
const keys =
|
|
13813
|
+
const keys = projectKeyRule(project.tracker, project.link, repo);
|
|
13735
13814
|
sources.push({
|
|
13736
13815
|
repo,
|
|
13737
13816
|
reserveRemaining: config.github.reserveRemaining,
|
|
@@ -15070,25 +15149,26 @@ function sampleQuery(closing) {
|
|
|
15070
15149
|
}
|
|
15071
15150
|
/**
|
|
15072
15151
|
* Matches up to 10 of the operator's most recently updated open or merged PRs in `repo` (among
|
|
15073
|
-
* the last 50) against
|
|
15074
|
-
* other GraphQL error rejects with a transient
|
|
15152
|
+
* the last 50) against the key rule `tracker` and `link` give that repo. A denied closing
|
|
15153
|
+
* reference is dropped, as the poller does; any other GraphQL error rejects with a transient
|
|
15154
|
+
* `AdapterError`.
|
|
15075
15155
|
*/
|
|
15076
|
-
async function sampleLinkRules({ repo, login, link }, { token, fetch: fetcher, signal }) {
|
|
15156
|
+
async function sampleLinkRules({ repo, login, tracker, link }, { token, fetch: fetcher, signal }) {
|
|
15077
15157
|
const [owner, name] = repo.split("/");
|
|
15078
15158
|
if (!owner || !name) throw new AdapterError("config", "Invalid repository");
|
|
15079
|
-
const
|
|
15159
|
+
const rule = projectKeyRule(tracker, link, repo);
|
|
15160
|
+
const closing = rule.type === "issues" && rule.sources.includes("closing");
|
|
15080
15161
|
const response = await new GithubClient(token, fetcher).query(sampleQuery(closing), {
|
|
15081
15162
|
owner,
|
|
15082
15163
|
repo: name
|
|
15083
15164
|
}, signal);
|
|
15084
15165
|
if (response.errors.some((error) => !deniedReference(error))) throw new AdapterError("transient", "GitHub link sample failed");
|
|
15085
15166
|
const root = parseWire(sampleRootWire, response.data["repository"], MALFORMED, ["data", "repository"]);
|
|
15086
|
-
const rule = issuesRule(repo, link);
|
|
15087
15167
|
const operator = login.toLowerCase();
|
|
15088
15168
|
const sampled = root.pullRequests.nodes.filter((pr) => pr.author?.login?.toLowerCase() === operator).slice(0, SAMPLED);
|
|
15089
15169
|
return {
|
|
15090
15170
|
sampled: sampled.length,
|
|
15091
|
-
unmatched: sampled.filter((pr) =>
|
|
15171
|
+
unmatched: sampled.filter((pr) => prKeys(rule, pr.title, pr.headRefName, closingRefs(pr.closingIssuesReferences)).length === 0).map((pr) => ({
|
|
15092
15172
|
number: pr.number,
|
|
15093
15173
|
branch: pr.headRefName
|
|
15094
15174
|
}))
|
|
@@ -16409,6 +16489,7 @@ function sampleProject(ctx, fetcher, token, project, repo) {
|
|
|
16409
16489
|
return deadlineCall(ctx, "doctor.link_rules", "GitHub link sample failed", (signal) => sampleLinkRules({
|
|
16410
16490
|
repo,
|
|
16411
16491
|
login: project.operatorGithubLogin,
|
|
16492
|
+
tracker: project.tracker,
|
|
16412
16493
|
link: project.link
|
|
16413
16494
|
}, {
|
|
16414
16495
|
token,
|
|
@@ -16420,8 +16501,11 @@ function sampleLinks(ctx, fetcher, token) {
|
|
|
16420
16501
|
const projects = ctx.config.projects.flatMap((project) => project.tracker.type === "github-issues" ? [{
|
|
16421
16502
|
project,
|
|
16422
16503
|
repo: project.tracker.repo
|
|
16423
|
-
}] :
|
|
16424
|
-
|
|
16504
|
+
}] : project.repos.map((repo) => ({
|
|
16505
|
+
project,
|
|
16506
|
+
repo
|
|
16507
|
+
})));
|
|
16508
|
+
if (token === void 0) return null;
|
|
16425
16509
|
return Promise.all(projects.map(async ({ project, repo }) => {
|
|
16426
16510
|
const polled = project.repos.some((entry) => entry.toLowerCase() === repo.toLowerCase());
|
|
16427
16511
|
return polled ? {
|
|
@@ -16476,14 +16560,8 @@ function fitFix(segments, tail, fallback) {
|
|
|
16476
16560
|
}
|
|
16477
16561
|
return fallback;
|
|
16478
16562
|
}
|
|
16479
|
-
function linkRulesCheck(outcomes
|
|
16563
|
+
function linkRulesCheck(outcomes) {
|
|
16480
16564
|
const id = "link.rules";
|
|
16481
|
-
if (!configured) return {
|
|
16482
|
-
id,
|
|
16483
|
-
status: "pass",
|
|
16484
|
-
blocking: false,
|
|
16485
|
-
fix: null
|
|
16486
|
-
};
|
|
16487
16565
|
if (outcomes === null) return warning(id, LINK_RULES_TOKEN_FIX);
|
|
16488
16566
|
const segments = outcomes.map(linkSegment);
|
|
16489
16567
|
const problems = segments.filter((segment) => segment.problem);
|
|
@@ -16588,7 +16666,7 @@ async function runDaemonDoctor(ctx, productVersion, fetcher = fetch) {
|
|
|
16588
16666
|
return null;
|
|
16589
16667
|
}))).find((failure) => failure !== null) ?? null;
|
|
16590
16668
|
checks.push(check("github.credentials", githubFailure === null, githubFailure ?? GITHUB_FIX));
|
|
16591
|
-
checks.push(linkRulesCheck(await linkSamples
|
|
16669
|
+
checks.push(linkRulesCheck(await linkSamples));
|
|
16592
16670
|
const probe = spurSendRequest(config.adapters.spur.baseUrl, SPUR_PROBE_SESSION, "spur-board doctor probe");
|
|
16593
16671
|
const [spur, spurSend] = await Promise.all([request(ctx, fetcher, "spur", new URL("sessions", `${config.adapters.spur.baseUrl.replace(/\/$/, "")}/`)), request(ctx, fetcher, "spur.send", probe.url, probe.init)]);
|
|
16594
16672
|
checks.push(check("spur.api", spur?.ok === true, "Start or correct the configured Spur API."));
|
package/dist/mcp.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as CliError, n as requestOperation } from "./client-
|
|
3
|
-
import { a as memoryVerdictCache, r as compareCatalogs, s as loadClientConfig, t as checkCatalog } from "./config-
|
|
1
|
+
import { P as ERRORS, p as renderMcpError, u as OPERATIONS } from "./src-ep5scuVt.mjs";
|
|
2
|
+
import { i as CliError, n as requestOperation } from "./client-CwKmG23X.mjs";
|
|
3
|
+
import { a as memoryVerdictCache, r as compareCatalogs, s as loadClientConfig, t as checkCatalog } from "./config-CXDupHSC.mjs";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import { readFileSync } from "node:fs";
|
|
6
6
|
import { z } from "zod";
|
|
@@ -173,6 +173,15 @@ const LINK_SOURCES = [
|
|
|
173
173
|
"branch",
|
|
174
174
|
"title"
|
|
175
175
|
];
|
|
176
|
+
/**
|
|
177
|
+
* The `projects[].link` defaults. A Jira project whose `link` field equals its default here
|
|
178
|
+
* treats it as unset and finds every `tracker.projectKeys` key in that text instead.
|
|
179
|
+
*/
|
|
180
|
+
const DEFAULT_LINK = {
|
|
181
|
+
sources: LINK_SOURCES,
|
|
182
|
+
branchPattern: "^[A-Za-z]+-([1-9][0-9]*)",
|
|
183
|
+
titlePattern: "^[a-z]+(?:\\([^)]*\\))?!?: #([1-9][0-9]*)"
|
|
184
|
+
};
|
|
176
185
|
/** A `link` pattern: compiles, starts with `^` and has exactly one capture group. */
|
|
177
186
|
function linkPattern(fallback, description) {
|
|
178
187
|
return nonEmpty.superRefine((pattern, ctx) => {
|
|
@@ -246,10 +255,10 @@ const projectSchema = z.strictObject({
|
|
|
246
255
|
message: `Duplicate link source: ${JSON.stringify(source)}`
|
|
247
256
|
});
|
|
248
257
|
});
|
|
249
|
-
}).default([...
|
|
250
|
-
branchPattern: linkPattern(
|
|
251
|
-
titlePattern: linkPattern(
|
|
252
|
-
}).prefault({}).describe("How a github-issues project
|
|
258
|
+
}).default([...DEFAULT_LINK.sources]).describe("Where a PR names its task, in priority order; the first source that yields an issue number wins (for a Jira project, an issue key). closing: issues in tracker.repo the PR closes (Closes #12 in the body, or linked in the sidebar), for PRs to the default branch only; a Jira project skips it. branch: branchPattern on the head branch. title: titlePattern on the PR title."),
|
|
259
|
+
branchPattern: linkPattern(DEFAULT_LINK.branchPattern, "Regular expression that starts with ^ and whose one capture group reads the issue number from a PR head branch, such as <agent>-<number>-<slug>. Branches longer than 255 characters are not matched. For a Jira project the capture group reads the issue key, such as PROJ-12, which must use one of tracker.projectKeys in any letter case; left at the default, a Jira project finds every such key in the PR head branch."),
|
|
260
|
+
titlePattern: linkPattern(DEFAULT_LINK.titlePattern, "Regular expression that starts with ^ and whose one capture group reads the issue number from a PR title, such as fix(core): #12 summary. Titles longer than 255 characters are not matched. For a Jira project the capture group reads the issue key, such as PROJ-12, which must use one of tracker.projectKeys in any letter case; left at the default, a Jira project finds every such key in the PR title.")
|
|
261
|
+
}).prefault({}).describe("How a project links a PR to its task. A github-issues project reads an issue number from PRs in tracker.repo; a Jira project reads an issue key with one of tracker.projectKeys from PRs in repos. Left at the defaults, a Jira project links every tracker.projectKeys key (such as PROJ-12, any letter case) in the PR title or head branch. Set the sources and patterns to the branch and PR title naming rules of the repos. The board does not enforce those rules; the repo enforces them through its CI title check and its agents' skills. board doctor compares these rules with recent PRs by operatorGithubLogin."),
|
|
253
262
|
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."),
|
|
254
263
|
spurProjects: z.array(spurProject).superRefine((items, ctx) => {
|
|
255
264
|
rejectDuplicates(items, "name", "spur project name", ctx);
|
|
@@ -1740,8 +1749,10 @@ const OPERATIONS = [
|
|
|
1740
1749
|
}).describe("Transport health of one gateway.")).describe("Transport health of each chat gateway."),
|
|
1741
1750
|
sources: z.array(sourceViewSchema).describe("Freshness and availability of each source."),
|
|
1742
1751
|
tasks: z.array(statusTaskSchema).describe("Tasks on the board with state and counts; facts and links with detail."),
|
|
1743
|
-
unlinkedPrs: z.array(statusUnlinkedPrSchema).describe("Observed pull requests without a task link."),
|
|
1744
|
-
unlinkedSessions: z.array(statusUnlinkedSessionSchema).describe("Observed sessions without a task link.")
|
|
1752
|
+
unlinkedPrs: z.array(statusUnlinkedPrSchema).describe("Observed pull requests without a task link; merged or closed ones with no change for over 7 days are left out."),
|
|
1753
|
+
unlinkedSessions: z.array(statusUnlinkedSessionSchema).describe("Observed sessions without a task link; ones ended, or gone from Spur's session list, for over 7 days are left out."),
|
|
1754
|
+
hiddenUnlinkedPrs: z.int().min(0).describe("Unlinked pull requests not listed: merged or closed, with no change for over 7 days. Counted within the requested projects; detail does not list them."),
|
|
1755
|
+
hiddenUnlinkedSessions: z.int().min(0).describe("Unlinked sessions not listed: ended, or gone from Spur's session list, for over 7 days. Counted within the requested projects; detail does not list them.")
|
|
1745
1756
|
}),
|
|
1746
1757
|
grants: operatorOrProjectAgent,
|
|
1747
1758
|
errors: ["not_found"],
|
|
@@ -1771,7 +1782,9 @@ const OPERATIONS = [
|
|
|
1771
1782
|
openBlocks: 0
|
|
1772
1783
|
}],
|
|
1773
1784
|
unlinkedPrs: [],
|
|
1774
|
-
unlinkedSessions: []
|
|
1785
|
+
unlinkedSessions: [],
|
|
1786
|
+
hiddenUnlinkedPrs: 0,
|
|
1787
|
+
hiddenUnlinkedSessions: 0
|
|
1775
1788
|
}
|
|
1776
1789
|
}, {
|
|
1777
1790
|
summary: "Show the board with full facts and links",
|
|
@@ -1795,7 +1808,9 @@ const OPERATIONS = [
|
|
|
1795
1808
|
links: []
|
|
1796
1809
|
}],
|
|
1797
1810
|
unlinkedPrs: [],
|
|
1798
|
-
unlinkedSessions: []
|
|
1811
|
+
unlinkedSessions: [],
|
|
1812
|
+
hiddenUnlinkedPrs: 0,
|
|
1813
|
+
hiddenUnlinkedSessions: 0
|
|
1799
1814
|
}
|
|
1800
1815
|
}]
|
|
1801
1816
|
}),
|
|
@@ -2846,4 +2861,10 @@ const SYSTEMD_SERVICE_SETTINGS = [
|
|
|
2846
2861
|
"TimeoutStopSec=15s"
|
|
2847
2862
|
];
|
|
2848
2863
|
//#endregion
|
|
2849
|
-
|
|
2864
|
+
//#region ../contracts/src/index.ts
|
|
2865
|
+
/** Exhaustiveness check: call it in the `default` branch of a switch over a union. */
|
|
2866
|
+
function assertNever(value) {
|
|
2867
|
+
throw new Error(`Unexpected value: ${JSON.stringify(value)}`);
|
|
2868
|
+
}
|
|
2869
|
+
//#endregion
|
|
2870
|
+
export { errorCodeOf as A, DEFAULT_SLACK_APP_NAME as B, SESSION_STATUSES as C, ticketFactsSchema as D, sessionFactsSchema as E, errorContextSchema as F, SLACK_BOT_SCOPES as G, RESERVED_PROJECT as H, errorEnvelopeSchema as I, successEnvelopeSchema as L, parseRef as M, taskKeySchema as N, actorIdSchema as O, ERRORS as P, DEFAULT_HTTP_PORT as R, SESSION_HEALTH_STATES as S, prRefSchema as T, configSchema as U, DEFAULT_SLACK_COMMAND as V, requiredSecretKeys as W, interactionRefSchema as _, batchSchema as a, EVENT_KINDS as b, buildCatalogSnapshot as c, renderHttpProblem as d, renderJsonError as f, inboundEventSchema as g, conversationRefSchema as h, AdapterError as i, parseActorId as j, encodeActorId as k, roleCanUseOperation as l, SPACE_IDS as m, BOARD_TICK_MS as n, entityRefSchema as o, renderMcpError as p, SYSTEMD_SERVICE_SETTINGS as r, sourceCursorSchema as s, assertNever as t, OPERATIONS as u, messageRefSchema as v, prFactsSchema as w, eventPayloadSchemas as x, userIdSchema as y, DEFAULT_LINK as z };
|