spur-board 0.45.0 → 0.46.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 +3 -3
- package/dist/{client-CYAzUkSd.mjs → client-BAwxhgyr.mjs} +1 -1
- package/dist/client.mjs +1 -1
- package/dist/{config-DSySN2QA.mjs → config-C0nYXJX4.mjs} +2 -2
- package/dist/daemon.mjs +234 -90
- package/dist/mcp.mjs +3 -3
- package/dist/migrations/0015_pr_continuation.sql +13 -0
- package/dist/{src-CL9PYpaV.mjs → src-DYURByVi.mjs} +11 -2
- package/package.json +1 -1
- package/skills/spur-board/references/errors.md +1 -0
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Q as requiredSecretKeys, X as configSchema, l as roleCanUseOperation, r as SYSTEMD_SERVICE_SETTINGS, tt as SLACK_BOT_SCOPES, u as OPERATIONS, z as ERRORS } from "./src-
|
|
2
|
-
import { a as CliError, c as escapeTerminalControls, i as requestTokenEnrollment, n as fetchTokenStatus, o as errorExitCode, r as requestOperation, s as renderCliError } from "./client-
|
|
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-
|
|
1
|
+
import { Q as requiredSecretKeys, X as configSchema, l as roleCanUseOperation, r as SYSTEMD_SERVICE_SETTINGS, tt as SLACK_BOT_SCOPES, u as OPERATIONS, z as ERRORS } from "./src-DYURByVi.mjs";
|
|
2
|
+
import { a as CliError, c as escapeTerminalControls, i as requestTokenEnrollment, n as fetchTokenStatus, o as errorExitCode, r as requestOperation, s as renderCliError } from "./client-BAwxhgyr.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-C0nYXJX4.mjs";
|
|
4
4
|
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
5
5
|
import { accessSync, chmodSync, closeSync, constants, cpSync, existsSync, ftruncateSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
|
|
6
6
|
import { homedir, hostname, userInfo } from "node:os";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { H as errorEnvelopeSchema, V as errorContextSchema, W as successEnvelopeSchema, p as renderJsonError, z as ERRORS } from "./src-
|
|
1
|
+
import { H as errorEnvelopeSchema, V as errorContextSchema, W as successEnvelopeSchema, p as renderJsonError, z as ERRORS } from "./src-DYURByVi.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 { i as requestTokenEnrollment, n as fetchTokenStatus, r as requestOperation, t as fetchCatalogVersion } from "./client-
|
|
1
|
+
import { i as requestTokenEnrollment, n as fetchTokenStatus, r as requestOperation, t as fetchCatalogVersion } from "./client-BAwxhgyr.mjs";
|
|
2
2
|
export { fetchCatalogVersion, fetchTokenStatus, requestOperation, requestTokenEnrollment };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { X as configSchema, Z as plainHttpAllowed, c as buildCatalogSnapshot, u as OPERATIONS } from "./src-
|
|
2
|
-
import { a as CliError, t as fetchCatalogVersion } from "./client-
|
|
1
|
+
import { X as configSchema, Z as plainHttpAllowed, c as buildCatalogSnapshot, u as OPERATIONS } from "./src-DYURByVi.mjs";
|
|
2
|
+
import { a as CliError, t as fetchCatalogVersion } from "./client-BAwxhgyr.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 { $ as COLUMN_IDS, A as ringMarker, B as err, C as REVIEW_STATES, D as parseRingMarker, E as isExternalAuthor, F as errorCodeOf, I as parseActorId, J as DEFAULT_SLACK_COMMAND, K as DEFAULT_LINK, L as parseRef$1, M as ticketFactsSchema, N as actorIdSchema, O as prFactsSchema, P as encodeActorId, Q as requiredSecretKeys, R as taskKeySchema, S as eventPayloadSchemas, T as SESSION_STATUSES, U as ok, W as successEnvelopeSchema, X as configSchema, Y as RESERVED_PROJECT, Z as plainHttpAllowed, _ as inboundEventSchema, a as batchSchema, b as userIdSchema, c as buildCatalogSnapshot, d as turnHandedSchema, et as DISPATCHER_MODES, f as renderHttpProblem, g as conversationRefSchema, h as SPACE_IDS, i as AdapterError, j as sessionFactsSchema, k as prRefSchema, l as roleCanUseOperation, n as BOARD_TICK_MS, o as entityRefSchema, s as sourceCursorSchema, t as assertNever, tt as SLACK_BOT_SCOPES, u as OPERATIONS, v as interactionRefSchema, w as SESSION_HEALTH_STATES, x as EVENT_KINDS, y as messageRefSchema, z as ERRORS } from "./src-
|
|
1
|
+
import { $ as COLUMN_IDS, A as ringMarker, B as err, C as REVIEW_STATES, D as parseRingMarker, E as isExternalAuthor, F as errorCodeOf, I as parseActorId, J as DEFAULT_SLACK_COMMAND, K as DEFAULT_LINK, L as parseRef$1, M as ticketFactsSchema, N as actorIdSchema, O as prFactsSchema, P as encodeActorId, Q as requiredSecretKeys, R as taskKeySchema, S as eventPayloadSchemas, T as SESSION_STATUSES, U as ok, W as successEnvelopeSchema, X as configSchema, Y as RESERVED_PROJECT, Z as plainHttpAllowed, _ as inboundEventSchema, a as batchSchema, b as userIdSchema, c as buildCatalogSnapshot, d as turnHandedSchema, et as DISPATCHER_MODES, f as renderHttpProblem, g as conversationRefSchema, h as SPACE_IDS, i as AdapterError, j as sessionFactsSchema, k as prRefSchema, l as roleCanUseOperation, n as BOARD_TICK_MS, o as entityRefSchema, s as sourceCursorSchema, t as assertNever, tt as SLACK_BOT_SCOPES, u as OPERATIONS, v as interactionRefSchema, w as SESSION_HEALTH_STATES, x as EVENT_KINDS, y as messageRefSchema, z as ERRORS } from "./src-DYURByVi.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
4
|
import { chmodSync, closeSync, existsSync, fchmodSync, fstatSync, fsyncSync, ftruncateSync, linkSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeSync } from "node:fs";
|
|
@@ -443,7 +443,8 @@ function acknowledgeComment(revision, requested) {
|
|
|
443
443
|
}
|
|
444
444
|
//#endregion
|
|
445
445
|
//#region ../core/src/app/authorize.ts
|
|
446
|
-
|
|
446
|
+
/** True for the operator token and for a session of a Spur project with the `operator` role. */
|
|
447
|
+
function isOperator(actor, config) {
|
|
447
448
|
if (actor === "operator") return true;
|
|
448
449
|
const parsed = parseActorId(actor);
|
|
449
450
|
return parsed?.actor === "agent" && config.projects.some((project) => project.spurProjects.some((spur) => spur.name === parsed.actorRef.project && spur.role === "operator"));
|
|
@@ -458,7 +459,7 @@ function worker(actor, target) {
|
|
|
458
459
|
}
|
|
459
460
|
function orchestrator$1(actor, target, config, column) {
|
|
460
461
|
const configured = config.projects.find((entry) => entry.id === target.project)?.columns.find((entry) => entry.id === column)?.orchestrator;
|
|
461
|
-
if (configured === "operator") return
|
|
462
|
+
if (configured === "operator") return isOperator(actor, config);
|
|
462
463
|
const parsed = parseActorId(actor);
|
|
463
464
|
return parsed?.actor === "agent" && configured !== "none" && configured === parsed.actorRef.project;
|
|
464
465
|
}
|
|
@@ -483,7 +484,7 @@ function blockAuthor(actor, target, config) {
|
|
|
483
484
|
function matches(rule, actor, target, config) {
|
|
484
485
|
const parsed = parseActorId(actor);
|
|
485
486
|
switch (rule.grant) {
|
|
486
|
-
case "operator": return
|
|
487
|
+
case "operator": return isOperator(actor, config);
|
|
487
488
|
case "project-agent": return parsed?.actor === "agent" && config.projects.find((project) => project.id === target.project)?.spurProjects.some((spur) => spur.name === parsed.actorRef.project) === true;
|
|
488
489
|
case "task-worker": return worker(actor, target);
|
|
489
490
|
case "column-orchestrator": return target.task !== null && orchestrator$1(actor, target, config, target.task.column);
|
|
@@ -491,7 +492,7 @@ function matches(rule, actor, target, config) {
|
|
|
491
492
|
if (target.block === null) return false;
|
|
492
493
|
const addressee = parseAddressee(target.block.addressee_role);
|
|
493
494
|
switch (addressee.kind) {
|
|
494
|
-
case "operator": return
|
|
495
|
+
case "operator": return isOperator(actor, config);
|
|
495
496
|
case "curator": return parsed?.actor === "agent" && parsed.actorRef.project === curatorProject(config, target.project);
|
|
496
497
|
case "worker": return worker(actor, target);
|
|
497
498
|
case "orchestrator": return orchestrator$1(actor, target, config, addressee.column);
|
|
@@ -507,7 +508,7 @@ function authorize(grants, actor, state) {
|
|
|
507
508
|
const rules = grants.filter((rule) => rule.mode === void 0 || rule.mode === state.mode);
|
|
508
509
|
const hint = `Allowed role: ${[...new Set(rules.map((rule) => rule.grant))].join(", ") || "none"}.`;
|
|
509
510
|
if (state.target.kind === "missing") {
|
|
510
|
-
if (rules.some((rule) => rule.grant === "operator" &&
|
|
511
|
+
if (rules.some((rule) => rule.grant === "operator" && isOperator(actor, state.config))) return { status: "allowed" };
|
|
511
512
|
return rules.every((rule) => rule.grant === "operator") ? {
|
|
512
513
|
status: "denied",
|
|
513
514
|
hint
|
|
@@ -9101,7 +9102,7 @@ async function raiseItem(trx, input) {
|
|
|
9101
9102
|
}
|
|
9102
9103
|
/**
|
|
9103
9104
|
* Clear an item once; the edit waits for its line and is cancelled with a stale pending line.
|
|
9104
|
-
* The journal names `actor`, `system` unless an
|
|
9105
|
+
* The journal names `actor`, `system` unless an actor's action cleared it.
|
|
9105
9106
|
*/
|
|
9106
9107
|
async function clearItem(trx, itemId, at, actor = "system") {
|
|
9107
9108
|
if ((await trx.selectFrom("operator_item").selectAll().where("id", "=", itemId).executeTakeFirstOrThrow()).cleared_at !== null) return;
|
|
@@ -9163,7 +9164,7 @@ function resolvedLine(by, at, config) {
|
|
|
9163
9164
|
kind: "text",
|
|
9164
9165
|
text: "✓ Resolved by "
|
|
9165
9166
|
},
|
|
9166
|
-
parsed.actor === "agent" ? {
|
|
9167
|
+
parsed.actor === "agent" && !isOperator(by, config) ? {
|
|
9167
9168
|
kind: "text",
|
|
9168
9169
|
text: `${parsed.actorRef.project}/${parsed.actorRef.session}`
|
|
9169
9170
|
} : {
|
|
@@ -9459,6 +9460,7 @@ async function createApiServer(options) {
|
|
|
9459
9460
|
let doctorInFlight = null;
|
|
9460
9461
|
let doctorCached = null;
|
|
9461
9462
|
let doctorNextProbeAt = 0;
|
|
9463
|
+
const notReady = () => options.stopping?.() === true ? new CommandError("stopping", "Wait until the daemon is running again.") : new CommandError("starting", "Wait until the daemon is ready.");
|
|
9462
9464
|
app.addHook("onRequest", async (request, reply) => {
|
|
9463
9465
|
reply.header("x-request-id", request.id);
|
|
9464
9466
|
reply.header("x-board-instance", instance);
|
|
@@ -9508,11 +9510,11 @@ async function createApiServer(options) {
|
|
|
9508
9510
|
throw new CommandError("not_found", "This API route is not available.");
|
|
9509
9511
|
});
|
|
9510
9512
|
app.get("/v1/schema", async (_request, reply) => {
|
|
9511
|
-
if (!options.ready()) throw
|
|
9513
|
+
if (!options.ready()) throw notReady();
|
|
9512
9514
|
return reply.send(snapshot);
|
|
9513
9515
|
});
|
|
9514
9516
|
app.get("/v1/doctor", async (_request, reply) => {
|
|
9515
|
-
if (!options.ready()) throw
|
|
9517
|
+
if (!options.ready()) throw notReady();
|
|
9516
9518
|
if (options.doctor === void 0) throw new CommandError("not_found", "Doctor is unavailable.");
|
|
9517
9519
|
if (doctorInFlight !== null) return reply.send(await doctorInFlight);
|
|
9518
9520
|
if (options.clock.now() < doctorNextProbeAt) {
|
|
@@ -9529,12 +9531,12 @@ async function createApiServer(options) {
|
|
|
9529
9531
|
}
|
|
9530
9532
|
});
|
|
9531
9533
|
app.get("/v1/health", async (_request, reply) => {
|
|
9532
|
-
if (!options.ready()) throw
|
|
9534
|
+
if (!options.ready()) throw notReady();
|
|
9533
9535
|
if (options.firstPollDone === void 0) throw new CommandError("not_found", "Health is unavailable.");
|
|
9534
9536
|
return reply.send({ firstPollDone: await options.firstPollDone() });
|
|
9535
9537
|
});
|
|
9536
9538
|
app.post("/v1/tokens/requests", async (request, reply) => {
|
|
9537
|
-
if (!options.ready()) throw
|
|
9539
|
+
if (!options.ready()) throw notReady();
|
|
9538
9540
|
const parsed = tokenRequestSchema.safeParse(request.body);
|
|
9539
9541
|
if (!parsed.success) throw new CommandError("usage", "Provide a name, folder, host and token hash.");
|
|
9540
9542
|
const result = await requestToken(options.store, options.config, parsed.data, new Date(options.clock.now()));
|
|
@@ -9546,7 +9548,7 @@ async function createApiServer(options) {
|
|
|
9546
9548
|
});
|
|
9547
9549
|
/** The hash travels in the body because request logs record the URL. */
|
|
9548
9550
|
app.post("/v1/tokens/status", async (request, reply) => {
|
|
9549
|
-
if (!options.ready()) throw
|
|
9551
|
+
if (!options.ready()) throw notReady();
|
|
9550
9552
|
const parsed = tokenStatusSchema.safeParse(request.body);
|
|
9551
9553
|
if (!parsed.success) throw new CommandError("usage", "Provide a SHA-256 token hash.");
|
|
9552
9554
|
const status = await tokenStatusByHash(options.store, parsed.data.hash, new Date(options.clock.now()));
|
|
@@ -9557,7 +9559,7 @@ async function createApiServer(options) {
|
|
|
9557
9559
|
}));
|
|
9558
9560
|
});
|
|
9559
9561
|
app.post("/v1/ops/:id", { onRequest: async (request) => {
|
|
9560
|
-
if (!options.ready()) throw
|
|
9562
|
+
if (!options.ready()) throw notReady();
|
|
9561
9563
|
const sessionHeader = request.headers["x-board-session"];
|
|
9562
9564
|
if (Array.isArray(sessionHeader)) throw new CommandError("forbidden", "Use one session identity header.");
|
|
9563
9565
|
callers.set(request, await identifyCaller(options, {
|
|
@@ -9660,7 +9662,7 @@ async function applyDoorbellPolicy(trx, event, at) {
|
|
|
9660
9662
|
if (!(parseActorId(event.block.author)?.actor === "agent" && event.block.addressee_role === event.authorRole)) await registerBlockNotification(trx, event.block, at);
|
|
9661
9663
|
return;
|
|
9662
9664
|
case "block_escalated":
|
|
9663
|
-
await closeBlockNotification(trx, event.block.id, at);
|
|
9665
|
+
await closeBlockNotification(trx, event.block.id, at, "system");
|
|
9664
9666
|
await registerBlockNotification(trx, event.block, at);
|
|
9665
9667
|
return;
|
|
9666
9668
|
case "answer":
|
|
@@ -10259,21 +10261,22 @@ async function workerNotificationAddressedTo(trx, n, session, config) {
|
|
|
10259
10261
|
if (n.recipient_session === null) return session === n.author_session || await sessionLink(trx, n.task_id, "worker", session) !== void 0;
|
|
10260
10262
|
return await liveSession(trx, n.recipient_session) !== void 0 ? session === n.recipient_session : (await selectNotificationRecipient(trx, n, config))?.id === session;
|
|
10261
10263
|
}
|
|
10262
|
-
|
|
10263
|
-
|
|
10264
|
+
/** Ends a block's ring series; its exhaustion item is cleared by `actor`, who closed the block. */
|
|
10265
|
+
async function closeBlockNotification(trx, blockId, at, actor) {
|
|
10266
|
+
await closeOwnedNotifications(trx, "block", blockId, at, actor);
|
|
10264
10267
|
}
|
|
10265
10268
|
/**
|
|
10266
10269
|
* Ends a turn's ring series and reminders for good: acked, and its exhaustion item cleared by the
|
|
10267
10270
|
* system.
|
|
10268
10271
|
*/
|
|
10269
10272
|
async function closeTurnNotification(trx, turnId, at) {
|
|
10270
|
-
await closeOwnedNotifications(trx, "turn", turnId, at);
|
|
10273
|
+
await closeOwnedNotifications(trx, "turn", turnId, at, "system");
|
|
10271
10274
|
}
|
|
10272
|
-
async function closeOwnedNotifications(trx, kind, ownerId, at) {
|
|
10275
|
+
async function closeOwnedNotifications(trx, kind, ownerId, at, actor) {
|
|
10273
10276
|
const closed = await trx.updateTable("notification").set({ acked_at: at.toISOString() }).where(kind === "block" ? "block_id" : "turn_id", "=", ownerId).where("kind", "in", kind === "block" ? ["block"] : ["turn", "turn_reminder"]).where("acked_at", "is", null).returning(["kind", "source_key"]).execute();
|
|
10274
10277
|
for (const row of closed) {
|
|
10275
10278
|
const item = await trx.selectFrom("operator_item").select("id").where("item_key", "=", exhaustedItemKey(row)).where("cleared_at", "is", null).executeTakeFirst();
|
|
10276
|
-
if (item !== void 0) await clearItem(trx, item.id, at);
|
|
10279
|
+
if (item !== void 0) await clearItem(trx, item.id, at, actor);
|
|
10277
10280
|
}
|
|
10278
10281
|
}
|
|
10279
10282
|
//#endregion
|
|
@@ -10812,9 +10815,9 @@ async function closeOpenBlock(trx, task, block, ctx, outcome, outcomeReason) {
|
|
|
10812
10815
|
actor: ctx.actor,
|
|
10813
10816
|
at: new Date(ctx.at)
|
|
10814
10817
|
});
|
|
10815
|
-
await closeBlockNotification(trx, block.id, new Date(ctx.at));
|
|
10818
|
+
await closeBlockNotification(trx, block.id, new Date(ctx.at), ctx.actor);
|
|
10816
10819
|
const items = await trx.selectFrom("operator_item").selectAll().where("kind", "in", ["post_blocked", ...BLOCK_ITEM_KINDS]).where("block_id", "=", block.id).where("cleared_at", "is", null).execute();
|
|
10817
|
-
for (const item of items) if (item.kind === "post_blocked") await clearItem(trx, item.id, new Date(ctx.at));
|
|
10820
|
+
for (const item of items) if (item.kind === "post_blocked") await clearItem(trx, item.id, new Date(ctx.at), ctx.actor);
|
|
10818
10821
|
else if (ctx.actor !== "system" && outcome !== "archived" && isItemKind(item.kind) && ITEM_POLICY[item.kind].reconciled) await dismissItem(trx, item, ctx.actor, new Date(ctx.at));
|
|
10819
10822
|
else await clearItem(trx, item.id, new Date(ctx.at), ctx.actor);
|
|
10820
10823
|
return updated;
|
|
@@ -12203,7 +12206,21 @@ function sessionView(fact) {
|
|
|
12203
12206
|
function counts(values, order) {
|
|
12204
12207
|
return order.map((value) => [value, values.filter((entry) => entry === value).length]).filter(([, n]) => n > 0).map(([value, n]) => `${String(n)} ${value}`).join(", ");
|
|
12205
12208
|
}
|
|
12206
|
-
/**
|
|
12209
|
+
/** End reasons in the words of the "worker ended" item (`ENDED_WORKER_LABELS`, fromYou.ts). */
|
|
12210
|
+
const END_WORDS = {
|
|
12211
|
+
complete: "completed",
|
|
12212
|
+
kill: "killed",
|
|
12213
|
+
vanished: "vanished",
|
|
12214
|
+
unknown: "unknown"
|
|
12215
|
+
};
|
|
12216
|
+
/** A linked session's label in the task row: `ended (<reason>)` once the board knows it ended. */
|
|
12217
|
+
function sessionLabel(fact, absentSince) {
|
|
12218
|
+
if (fact.endReason !== null) return `ended (${END_WORDS[fact.endReason]})`;
|
|
12219
|
+
if (fact.lifecycle === "killed" || fact.lifecycle === "completed") return `ended (${fact.lifecycle})`;
|
|
12220
|
+
if (absentSince !== null) return "ended (gone)";
|
|
12221
|
+
return fact.health;
|
|
12222
|
+
}
|
|
12223
|
+
/** The one-line task state: ticket status, pull request states, session counts by label. */
|
|
12207
12224
|
function taskState(ticket, prs, sessions) {
|
|
12208
12225
|
const parts = [ticket === null ? "ticket not observed" : `ticket ${ticket.status}`];
|
|
12209
12226
|
if (prs.length > 0) {
|
|
@@ -12216,8 +12233,8 @@ function taskState(ticket, prs, sessions) {
|
|
|
12216
12233
|
])}`);
|
|
12217
12234
|
}
|
|
12218
12235
|
if (sessions.length > 0) {
|
|
12219
|
-
const
|
|
12220
|
-
parts.push(`sessions ${counts(
|
|
12236
|
+
const labels = sessions.map((session) => sessionLabel(session.fact, session.absentSince));
|
|
12237
|
+
parts.push(`sessions ${counts(labels, [...new Set(labels)].sort())}`);
|
|
12221
12238
|
}
|
|
12222
12239
|
return parts.join("; ");
|
|
12223
12240
|
}
|
|
@@ -12252,12 +12269,20 @@ async function getStatus(deps, options = {}) {
|
|
|
12252
12269
|
const links = taskLinks.filter((link) => link.banned === 0);
|
|
12253
12270
|
const prs = [];
|
|
12254
12271
|
const sessions = [];
|
|
12272
|
+
const sessionStates = [];
|
|
12255
12273
|
for (const link of links) if (link.entity === "pr" && link.repo !== null && link.number !== null) {
|
|
12256
12274
|
const snapshot = await store.db.selectFrom("pr_snapshot").select("detail").where(sql`lower(repo) = ${link.repo.toLowerCase()}`).where("number", "=", link.number).executeTakeFirst();
|
|
12257
12275
|
if (snapshot !== void 0) prs.push(parseJson(prFactsSchema, snapshot.detail));
|
|
12258
12276
|
} else if (link.entity === "session" && link.session_id !== null) {
|
|
12259
|
-
const snapshot = await store.db.selectFrom("session_snapshot").select("detail").where("id", "=", link.session_id).executeTakeFirst();
|
|
12260
|
-
if (snapshot !== void 0)
|
|
12277
|
+
const snapshot = await store.db.selectFrom("session_snapshot").select(["detail", "absent_since"]).where("id", "=", link.session_id).executeTakeFirst();
|
|
12278
|
+
if (snapshot !== void 0) {
|
|
12279
|
+
const fact = parseJson(sessionFactsSchema, snapshot.detail);
|
|
12280
|
+
sessions.push(fact);
|
|
12281
|
+
sessionStates.push({
|
|
12282
|
+
fact,
|
|
12283
|
+
absentSince: snapshot.absent_since
|
|
12284
|
+
});
|
|
12285
|
+
}
|
|
12261
12286
|
}
|
|
12262
12287
|
const ticketFacts = ticket === void 0 ? null : parseJson(ticketFactsSchema, ticket.detail);
|
|
12263
12288
|
const project = config.projects.find((entry) => entry.id === task.project);
|
|
@@ -12281,7 +12306,7 @@ async function getStatus(deps, options = {}) {
|
|
|
12281
12306
|
shadowColumn: task.shadow_column ?? task.column,
|
|
12282
12307
|
shadowDiffers: (task.shadow_column ?? task.column) !== task.column
|
|
12283
12308
|
} : {},
|
|
12284
|
-
state: taskState(ticketFacts, prs,
|
|
12309
|
+
state: taskState(ticketFacts, prs, sessionStates),
|
|
12285
12310
|
prCount: links.filter((link) => link.entity === "pr").length,
|
|
12286
12311
|
sessionCount: links.filter((link) => link.entity === "session").length,
|
|
12287
12312
|
openBlocks: openBlocks.get(task.id) ?? 0,
|
|
@@ -15036,6 +15061,60 @@ async function session(trx, config, fact, at, source, ambiguousBranches) {
|
|
|
15036
15061
|
await trx.updateTable("task").set({ last_change_at: at }).where("id", "=", task.id).execute();
|
|
15037
15062
|
}
|
|
15038
15063
|
}
|
|
15064
|
+
/** The PRs of a GitHub source's repo that still have an unbanned link, one per ref key. */
|
|
15065
|
+
async function linkedPrs(db, source) {
|
|
15066
|
+
if (!source.startsWith("github:")) return [];
|
|
15067
|
+
const repo = source.slice(source.lastIndexOf(":") + 1);
|
|
15068
|
+
const prs = (await db.selectFrom("link").select(["repo", "number"]).where("entity", "=", "pr").where(sql`lower(repo) = ${repo.toLowerCase()}`).where("banned", "=", 0).execute()).flatMap((link) => link.repo === null || link.number === null ? [] : [{
|
|
15069
|
+
kind: "pr",
|
|
15070
|
+
repo: link.repo,
|
|
15071
|
+
number: link.number
|
|
15072
|
+
}]);
|
|
15073
|
+
return [...new Map(prs.map((ref) => [refKey(ref), ref])).values()];
|
|
15074
|
+
}
|
|
15075
|
+
const heldFeedbackSchema = prFactsSchema.shape.feedback.unwrap();
|
|
15076
|
+
/** The held comment histories of `prs` (A10); a row that does not parse is skipped. */
|
|
15077
|
+
async function heldContinuations(db, source, prs) {
|
|
15078
|
+
if (prs.length === 0) return [];
|
|
15079
|
+
const byKey = new Map(prs.map((ref) => [refKey(ref), ref]));
|
|
15080
|
+
return (await db.selectFrom("pr_continuation").selectAll().where("source", "=", source).where("ref_key", "in", [...byKey.keys()]).orderBy("ref_key").execute()).flatMap((row) => {
|
|
15081
|
+
const ref = byKey.get(row.ref_key);
|
|
15082
|
+
if (ref === void 0) return [];
|
|
15083
|
+
let feedback;
|
|
15084
|
+
try {
|
|
15085
|
+
feedback = parseJson(heldFeedbackSchema, row.feedback);
|
|
15086
|
+
} catch {
|
|
15087
|
+
return [];
|
|
15088
|
+
}
|
|
15089
|
+
return [{
|
|
15090
|
+
ref,
|
|
15091
|
+
resume: row.resume,
|
|
15092
|
+
feedback
|
|
15093
|
+
}];
|
|
15094
|
+
});
|
|
15095
|
+
}
|
|
15096
|
+
/** Applies a `pr` item's `continuation` (A10): omitted keeps the row, null drops it. */
|
|
15097
|
+
async function holdContinuation(trx, source, item) {
|
|
15098
|
+
if (item.continuation === void 0) return;
|
|
15099
|
+
const key = refKey({
|
|
15100
|
+
kind: "pr",
|
|
15101
|
+
repo: item.facts.repo,
|
|
15102
|
+
number: item.facts.number
|
|
15103
|
+
});
|
|
15104
|
+
if (item.continuation === null) {
|
|
15105
|
+
await trx.deleteFrom("pr_continuation").where("source", "=", source).where("ref_key", "=", key).execute();
|
|
15106
|
+
return;
|
|
15107
|
+
}
|
|
15108
|
+
const held = {
|
|
15109
|
+
resume: item.continuation.resume,
|
|
15110
|
+
feedback: toJson(heldFeedbackSchema, item.facts.feedback ?? [])
|
|
15111
|
+
};
|
|
15112
|
+
await trx.insertInto("pr_continuation").values({
|
|
15113
|
+
source,
|
|
15114
|
+
ref_key: key,
|
|
15115
|
+
...held
|
|
15116
|
+
}).onConflict((oc) => oc.columns(["source", "ref_key"]).doUpdateSet(held)).execute();
|
|
15117
|
+
}
|
|
15039
15118
|
/** Core's adapter-facing port. Every accepted batch and its source state share one transaction. */
|
|
15040
15119
|
function createObservationCore(deps) {
|
|
15041
15120
|
const { store, config, clock } = deps;
|
|
@@ -15061,12 +15140,7 @@ function createObservationCore(deps) {
|
|
|
15061
15140
|
key: task.key
|
|
15062
15141
|
}] : [];
|
|
15063
15142
|
}) : [];
|
|
15064
|
-
const
|
|
15065
|
-
const prs = repo === null ? [] : (await store.db.selectFrom("link").select(["repo", "number"]).where("entity", "=", "pr").where(sql`lower(repo) = ${repo.toLowerCase()}`).where("banned", "=", 0).execute()).flatMap((link) => link.repo === null || link.number === null ? [] : [{
|
|
15066
|
-
kind: "pr",
|
|
15067
|
-
repo: link.repo,
|
|
15068
|
-
number: link.number
|
|
15069
|
-
}]);
|
|
15143
|
+
const requested = await linkedPrs(store.db, source);
|
|
15070
15144
|
const sessions = source === "spur" ? (await store.db.selectFrom("link").innerJoin("session_snapshot", "session_snapshot.id", "link.session_id").select("link.session_id").where("link.entity", "=", "session").where("session_snapshot.ended_at", "is", null).execute()).flatMap((link) => link.session_id === null ? [] : [{
|
|
15071
15145
|
kind: "session",
|
|
15072
15146
|
id: link.session_id
|
|
@@ -15080,8 +15154,8 @@ function createObservationCore(deps) {
|
|
|
15080
15154
|
})));
|
|
15081
15155
|
}
|
|
15082
15156
|
const misses = await store.db.selectFrom("source_miss").selectAll().where("source", "=", source).execute();
|
|
15083
|
-
const requested = [...new Map(prs.map((ref) => [refKey(ref), ref])).values()];
|
|
15084
15157
|
const feedbackCursors = await pollFeedbackCursors(store.db, config, requested);
|
|
15158
|
+
const continuations = await heldContinuations(store.db, source, requested);
|
|
15085
15159
|
return {
|
|
15086
15160
|
observe: {
|
|
15087
15161
|
prs: requested,
|
|
@@ -15096,7 +15170,8 @@ function createObservationCore(deps) {
|
|
|
15096
15170
|
count: row.misses
|
|
15097
15171
|
}];
|
|
15098
15172
|
}),
|
|
15099
|
-
...feedbackCursors.length === 0 ? {} : { feedbackCursors }
|
|
15173
|
+
...feedbackCursors.length === 0 ? {} : { feedbackCursors },
|
|
15174
|
+
...continuations.length === 0 ? {} : { continuations }
|
|
15100
15175
|
};
|
|
15101
15176
|
},
|
|
15102
15177
|
async observe(source, observation) {
|
|
@@ -15128,8 +15203,12 @@ function createObservationCore(deps) {
|
|
|
15128
15203
|
return rank(left) - rank(right);
|
|
15129
15204
|
});
|
|
15130
15205
|
for (const item of orderedItems) if (item.kind === "ticket") await ticket(trx, config, item.facts, batch.observedAt, source);
|
|
15131
|
-
else if (item.kind === "pr")
|
|
15132
|
-
|
|
15206
|
+
else if (item.kind === "pr") {
|
|
15207
|
+
await pr(trx, config, item.facts, batch.observedAt, source);
|
|
15208
|
+
await holdContinuation(trx, source, item);
|
|
15209
|
+
} else await session(trx, config, item.facts, batch.observedAt, source, ambiguous);
|
|
15210
|
+
const linked = (await linkedPrs(trx, source)).map(refKey);
|
|
15211
|
+
await trx.deleteFrom("pr_continuation").where("source", "=", source).$if(linked.length > 0, (query) => query.where("ref_key", "not in", linked)).execute();
|
|
15133
15212
|
for (const entity of batch.entities) {
|
|
15134
15213
|
if (entity.ref.kind !== "session" || entity.status !== "not_found") continue;
|
|
15135
15214
|
const old = await trx.selectFrom("session_snapshot").selectAll().where("id", "=", entity.ref.id).executeTakeFirst();
|
|
@@ -16878,11 +16957,12 @@ function feedbackAuthor(wire) {
|
|
|
16878
16957
|
type: wire.__typename === "Bot" ? "bot" : "user"
|
|
16879
16958
|
};
|
|
16880
16959
|
}
|
|
16881
|
-
function feedbackOf(reviews, comments) {
|
|
16960
|
+
function feedbackOf(reviews, comments, held) {
|
|
16882
16961
|
const entries = /* @__PURE__ */ new Map();
|
|
16883
16962
|
const add = (entry) => {
|
|
16884
16963
|
entries.set(`${entry.kind}:${entry.id}`, entry);
|
|
16885
16964
|
};
|
|
16965
|
+
for (const entry of held) if (entry.kind === "comment") add(entry);
|
|
16886
16966
|
for (const node of comments) add({
|
|
16887
16967
|
kind: "comment",
|
|
16888
16968
|
id: node.id,
|
|
@@ -16982,8 +17062,11 @@ function reviewer(wire) {
|
|
|
16982
17062
|
default: return assertNever(wire);
|
|
16983
17063
|
}
|
|
16984
17064
|
}
|
|
16985
|
-
/**
|
|
16986
|
-
|
|
17065
|
+
/**
|
|
17066
|
+
* `feedbackComplete` says whether the comments in `value`, with the `held` comments an earlier
|
|
17067
|
+
* poll read, reach back to the cursor or start.
|
|
17068
|
+
*/
|
|
17069
|
+
function normalizePr(repo, value, rule, feedbackComplete, held = []) {
|
|
16987
17070
|
const wire = parseWire(prWire, value, "Malformed GitHub PR response");
|
|
16988
17071
|
const checks = latestChecks(wire.statusCheckRollup?.contexts.nodes ?? []);
|
|
16989
17072
|
const state = wire.state === "MERGED" ? "merged" : wire.state === "CLOSED" ? "closed" : "open";
|
|
@@ -17022,7 +17105,7 @@ function normalizePr(repo, value, rule, feedbackComplete) {
|
|
|
17022
17105
|
ticketKeys: prKeys(rule, title, headBranch, closingRefs(wire.closingIssuesReferences)),
|
|
17023
17106
|
updatedAt: wire.updatedAt,
|
|
17024
17107
|
...state === "merged" && wire.mergedAt !== null ? { mergedAt: wire.mergedAt } : {},
|
|
17025
|
-
feedback: feedbackOf(wire.reviews.nodes, wire.comments.nodes),
|
|
17108
|
+
feedback: feedbackOf(wire.reviews.nodes, wire.comments.nodes, held),
|
|
17026
17109
|
feedbackComplete
|
|
17027
17110
|
};
|
|
17028
17111
|
const parsed = prFactsSchema.safeParse(facts);
|
|
@@ -17165,7 +17248,7 @@ function githubSources(config, options) {
|
|
|
17165
17248
|
client,
|
|
17166
17249
|
now: options.now,
|
|
17167
17250
|
ref,
|
|
17168
|
-
|
|
17251
|
+
ctx,
|
|
17169
17252
|
cache
|
|
17170
17253
|
})
|
|
17171
17254
|
}
|
|
@@ -17276,53 +17359,95 @@ async function fullPr(client, first, owner, name, number, signal, budget) {
|
|
|
17276
17359
|
pr
|
|
17277
17360
|
};
|
|
17278
17361
|
}
|
|
17362
|
+
const at = (time) => Date.parse(time);
|
|
17363
|
+
/** Whether `nodes` hold the `cursor` entry or one strictly older than it. */
|
|
17279
17364
|
function reachesCursor(nodes, cursor) {
|
|
17280
17365
|
if (cursor === void 0) return false;
|
|
17281
|
-
const postedAt =
|
|
17282
|
-
return nodes.some((node) => node.id === cursor.id ||
|
|
17366
|
+
const postedAt = at(cursor.postedAt);
|
|
17367
|
+
return nodes.some((node) => node.id === cursor.id || at(node.createdAt) < postedAt);
|
|
17368
|
+
}
|
|
17369
|
+
const asNode = (entry) => ({
|
|
17370
|
+
id: entry.id,
|
|
17371
|
+
createdAt: entry.postedAt
|
|
17372
|
+
});
|
|
17373
|
+
/** The newest of `items` by `time`; the first one on a tie. */
|
|
17374
|
+
function newestOf(items, time) {
|
|
17375
|
+
return items.reduce((found, item) => found === void 0 || at(time(item)) > at(time(found)) ? item : found, void 0);
|
|
17376
|
+
}
|
|
17377
|
+
/** Reads one page of comments before `before`; undefined on a GraphQL error or a bad page. */
|
|
17378
|
+
async function commentPage(scope, number, before, budget) {
|
|
17379
|
+
const response = await scope.client.query(pageQuery("comments"), {
|
|
17380
|
+
owner: scope.owner,
|
|
17381
|
+
repo: scope.name,
|
|
17382
|
+
number,
|
|
17383
|
+
before
|
|
17384
|
+
}, scope.signal);
|
|
17385
|
+
budget(response.budget);
|
|
17386
|
+
rejectUnscoped(response.errors, ["repository"]);
|
|
17387
|
+
if (response.errors.length > 0) return void 0;
|
|
17388
|
+
const page = content(() => parseWire(commentsRootWire, response.data.repository, MALFORMED$2, ["data", "repository"]).pullRequest.comments);
|
|
17389
|
+
return page instanceof AdapterError ? void 0 : page;
|
|
17283
17390
|
}
|
|
17284
17391
|
/**
|
|
17285
17392
|
* Reads comments back from `first` to `cursor`, or to the start of the PR, within
|
|
17286
|
-
* `FEEDBACK_PAGES
|
|
17287
|
-
*
|
|
17393
|
+
* `FEEDBACK_PAGES` for both phases. Phase 1 pages back from the newest comment until it reaches
|
|
17394
|
+
* the cursor or the start, or joins the newest `held` comment; phase 2 then reads further back
|
|
17395
|
+
* from the held `resume`. A transient failure keeps the comments read so far as incomplete;
|
|
17396
|
+
* every other failure, and any failure after an abort, rejects the poll.
|
|
17288
17397
|
*/
|
|
17289
|
-
async function readFeedback(
|
|
17398
|
+
async function readFeedback(scope, number, first, cursor, held, budget) {
|
|
17290
17399
|
let nodes = first.nodes;
|
|
17291
|
-
let
|
|
17292
|
-
const
|
|
17400
|
+
let kept = [];
|
|
17401
|
+
const result = (complete, continuation) => ({
|
|
17402
|
+
nodes,
|
|
17403
|
+
held: kept,
|
|
17404
|
+
complete,
|
|
17405
|
+
continuation: scope.states ? continuation : void 0
|
|
17406
|
+
});
|
|
17407
|
+
const heldComments = held?.feedback.filter((entry) => entry.kind === "comment") ?? [];
|
|
17408
|
+
const newest = newestOf(heldComments, (entry) => entry.postedAt);
|
|
17409
|
+
let pages = 1;
|
|
17293
17410
|
try {
|
|
17294
|
-
|
|
17411
|
+
const seen = /* @__PURE__ */ new Set();
|
|
17412
|
+
for (let page = first;; pages += 1) {
|
|
17413
|
+
if (!page.pageInfo.hasPreviousPage || reachesCursor(page.nodes, cursor)) return result(true, held === void 0 ? void 0 : null);
|
|
17414
|
+
if (reachesCursor(page.nodes, newest)) break;
|
|
17295
17415
|
const before = page.pageInfo.startCursor;
|
|
17296
|
-
if (!before || seen.has(before)
|
|
17297
|
-
|
|
17298
|
-
complete: false
|
|
17299
|
-
};
|
|
17416
|
+
if (!before || seen.has(before)) return result(false);
|
|
17417
|
+
if (pages >= FEEDBACK_PAGES) return result(false, { resume: sourceCursorSchema.parse(before) });
|
|
17300
17418
|
seen.add(before);
|
|
17301
|
-
const
|
|
17302
|
-
|
|
17303
|
-
|
|
17304
|
-
number,
|
|
17305
|
-
before
|
|
17306
|
-
}, signal);
|
|
17307
|
-
budget(response.budget);
|
|
17308
|
-
rejectUnscoped(response.errors, ["repository"]);
|
|
17309
|
-
if (response.errors.length > 0) return {
|
|
17310
|
-
nodes,
|
|
17311
|
-
complete: false
|
|
17312
|
-
};
|
|
17313
|
-
page = parseWire(commentsRootWire, response.data.repository, MALFORMED$2, ["data", "repository"]).pullRequest.comments;
|
|
17419
|
+
const next = await commentPage(scope, number, before, budget);
|
|
17420
|
+
if (next === void 0) return result(false);
|
|
17421
|
+
page = next;
|
|
17314
17422
|
nodes = [...page.nodes, ...nodes];
|
|
17315
17423
|
}
|
|
17316
|
-
return
|
|
17317
|
-
|
|
17318
|
-
|
|
17319
|
-
|
|
17424
|
+
if (held === void 0) return result(false);
|
|
17425
|
+
const listed = new Set(nodes.map((node) => node.id));
|
|
17426
|
+
const oldestRead = Math.min(...nodes.map((node) => at(node.createdAt)));
|
|
17427
|
+
kept = heldComments.filter((entry) => !listed.has(entry.id) && at(entry.postedAt) <= oldestRead);
|
|
17428
|
+
const history = () => [...nodes, ...kept.map(asNode)];
|
|
17429
|
+
const reached = () => reachesCursor(history(), cursor);
|
|
17430
|
+
let resume = held.resume;
|
|
17431
|
+
const resumed = /* @__PURE__ */ new Set();
|
|
17432
|
+
for (; resume !== null && !reached() && pages < FEEDBACK_PAGES; pages += 1) {
|
|
17433
|
+
resumed.add(resume);
|
|
17434
|
+
const page = await commentPage(scope, number, resume, budget);
|
|
17435
|
+
if (page === void 0) return result(false, null);
|
|
17436
|
+
const run = history();
|
|
17437
|
+
const ids = new Set(run.map((node) => node.id));
|
|
17438
|
+
const oldest = Math.min(...run.map((node) => at(node.createdAt)));
|
|
17439
|
+
const latest = newestOf(page.nodes, (node) => node.createdAt);
|
|
17440
|
+
if (latest !== void 0 && !ids.has(latest.id) && at(latest.createdAt) > oldest) return result(false, null);
|
|
17441
|
+
nodes = [...page.nodes, ...nodes];
|
|
17442
|
+
const start = page.pageInfo.startCursor;
|
|
17443
|
+
if (!page.pageInfo.hasPreviousPage) resume = null;
|
|
17444
|
+
else if (!start || resumed.has(start)) return result(false, null);
|
|
17445
|
+
else resume = sourceCursorSchema.parse(start);
|
|
17446
|
+
}
|
|
17447
|
+
return result(resume === null || reached(), { resume });
|
|
17320
17448
|
} catch (error) {
|
|
17321
|
-
if (signal.aborted) throw error;
|
|
17322
|
-
if (error instanceof AdapterError && error.kind === "transient") return
|
|
17323
|
-
nodes,
|
|
17324
|
-
complete: false
|
|
17325
|
-
};
|
|
17449
|
+
if (scope.signal.aborted) throw error;
|
|
17450
|
+
if (error instanceof AdapterError && error.kind === "transient") return result(false);
|
|
17326
17451
|
throw error;
|
|
17327
17452
|
}
|
|
17328
17453
|
}
|
|
@@ -17390,8 +17515,7 @@ async function processPr(scope, acc, number, alias, data, scopedErrors, ref) {
|
|
|
17390
17515
|
malformed(acc, full.error, ref);
|
|
17391
17516
|
return;
|
|
17392
17517
|
}
|
|
17393
|
-
const
|
|
17394
|
-
const feedback = await readFeedback(scope.client, full.pr.comments, scope.owner, scope.name, number, cursor, scope.signal, report);
|
|
17518
|
+
const feedback = await readFeedback(scope, number, full.pr.comments, entryFor(scope.feedbackCursors, scope.repo, number), entryFor(scope.continuations, scope.repo, number), report);
|
|
17395
17519
|
const pr = {
|
|
17396
17520
|
...full.pr,
|
|
17397
17521
|
comments: {
|
|
@@ -17399,14 +17523,16 @@ async function processPr(scope, acc, number, alias, data, scopedErrors, ref) {
|
|
|
17399
17523
|
nodes: feedback.nodes
|
|
17400
17524
|
}
|
|
17401
17525
|
};
|
|
17402
|
-
const facts = content(() => normalizePr(ref?.repo ?? scope.repo, pr, scope.keys, feedback.complete));
|
|
17526
|
+
const facts = content(() => normalizePr(ref?.repo ?? scope.repo, pr, scope.keys, feedback.complete, feedback.held));
|
|
17403
17527
|
if (facts instanceof AdapterError) {
|
|
17404
17528
|
malformed(acc, facts, ref);
|
|
17405
17529
|
return;
|
|
17406
17530
|
}
|
|
17531
|
+
const { continuation } = feedback;
|
|
17407
17532
|
acc.items.push({
|
|
17408
17533
|
kind: "pr",
|
|
17409
|
-
facts
|
|
17534
|
+
facts,
|
|
17535
|
+
...continuation === void 0 ? {} : { continuation }
|
|
17410
17536
|
});
|
|
17411
17537
|
if (ref) acc.entities.push({
|
|
17412
17538
|
ref,
|
|
@@ -17414,8 +17540,9 @@ async function processPr(scope, acc, number, alias, data, scopedErrors, ref) {
|
|
|
17414
17540
|
});
|
|
17415
17541
|
return facts;
|
|
17416
17542
|
}
|
|
17417
|
-
|
|
17418
|
-
|
|
17543
|
+
/** The entry of one PR in a per-PR list of the poll context. */
|
|
17544
|
+
function entryFor(entries, repo, number) {
|
|
17545
|
+
return entries?.find((entry) => entry.ref.number === number && entry.ref.repo.toLowerCase() === repo.toLowerCase());
|
|
17419
17546
|
}
|
|
17420
17547
|
function closingSelected(keys) {
|
|
17421
17548
|
return keys.type === "issues" && keys.sources.includes("closing");
|
|
@@ -17554,7 +17681,7 @@ async function pollRepository({ id, repo, login, keys, client, now, ctx, reserve
|
|
|
17554
17681
|
if (!discovery.ok) acc.complete = false;
|
|
17555
17682
|
const { found } = discovery;
|
|
17556
17683
|
const entries = await readIndex(request, acc, numbers);
|
|
17557
|
-
const cursorKey = (number) => JSON.stringify(
|
|
17684
|
+
const cursorKey = (number) => JSON.stringify([entryFor(ctx.feedbackCursors, repo, number) ?? "none", entryFor(ctx.continuations, repo, number) ?? "none"]);
|
|
17558
17685
|
const changed = [];
|
|
17559
17686
|
for (const number of numbers) {
|
|
17560
17687
|
const facts = reusable(cache.get(number), entries.get(number), cursorKey(number), now());
|
|
@@ -17580,7 +17707,9 @@ async function pollRepository({ id, repo, login, keys, client, now, ctx, reserve
|
|
|
17580
17707
|
name,
|
|
17581
17708
|
keys,
|
|
17582
17709
|
signal: ctx.signal,
|
|
17583
|
-
...ctx.feedbackCursors === void 0 ? {} : { feedbackCursors: ctx.feedbackCursors }
|
|
17710
|
+
...ctx.feedbackCursors === void 0 ? {} : { feedbackCursors: ctx.feedbackCursors },
|
|
17711
|
+
...ctx.continuations === void 0 ? {} : { continuations: ctx.continuations },
|
|
17712
|
+
states: true
|
|
17584
17713
|
};
|
|
17585
17714
|
let discoveredOk = true;
|
|
17586
17715
|
const unread = (chunk) => {
|
|
@@ -17641,7 +17770,8 @@ async function pollRepository({ id, repo, login, keys, client, now, ctx, reserve
|
|
|
17641
17770
|
...acc.budget === void 0 ? {} : { budget: acc.budget }
|
|
17642
17771
|
};
|
|
17643
17772
|
}
|
|
17644
|
-
async function pollOnePr({ id, repo, keys, client, now, ref,
|
|
17773
|
+
async function pollOnePr({ id, repo, keys, client, now, ref, ctx, cache }) {
|
|
17774
|
+
const { signal } = ctx;
|
|
17645
17775
|
const observedAt = new Date(now()).toISOString();
|
|
17646
17776
|
const [owner, name] = repo.split("/");
|
|
17647
17777
|
if (!owner || !name) throw new AdapterError("config", "Invalid repository");
|
|
@@ -17658,7 +17788,10 @@ async function pollOnePr({ id, repo, keys, client, now, ref, signal, cache }) {
|
|
|
17658
17788
|
owner,
|
|
17659
17789
|
name,
|
|
17660
17790
|
keys,
|
|
17661
|
-
signal
|
|
17791
|
+
signal,
|
|
17792
|
+
...ctx.feedbackCursors === void 0 ? {} : { feedbackCursors: ctx.feedbackCursors },
|
|
17793
|
+
...ctx.continuations === void 0 ? {} : { continuations: ctx.continuations },
|
|
17794
|
+
states: false
|
|
17662
17795
|
}, acc, ref.number, "pr0", response.data, scoped(response.errors, "pr0"), ref);
|
|
17663
17796
|
if (signal.aborted) throw new AdapterError("transient", "GitHub poll aborted");
|
|
17664
17797
|
rethrowLoneParseFailure(acc);
|
|
@@ -18644,9 +18777,19 @@ function runSource(entry, options, runnerStartMs) {
|
|
|
18644
18777
|
message: "The source is throttled until retryAt"
|
|
18645
18778
|
});
|
|
18646
18779
|
const aborted = () => abort.signal.aborted;
|
|
18647
|
-
let step = "
|
|
18780
|
+
let step = "context";
|
|
18648
18781
|
try {
|
|
18649
|
-
const
|
|
18782
|
+
const received = await untilAborted(core.context(source), abort.signal);
|
|
18783
|
+
if (aborted() || received === void 0) return err(stoppedError);
|
|
18784
|
+
const own = ({ ref: held }) => held.number === ref.number && held.repo.toLowerCase() === ref.repo.toLowerCase();
|
|
18785
|
+
const feedbackCursors = received.feedbackCursors?.filter(own) ?? [];
|
|
18786
|
+
const continuations = received.continuations?.filter(own) ?? [];
|
|
18787
|
+
step = "poll";
|
|
18788
|
+
const batch = await untilAborted(adapter.pollPr(ref, {
|
|
18789
|
+
signal: abort.signal,
|
|
18790
|
+
...feedbackCursors.length === 0 ? {} : { feedbackCursors },
|
|
18791
|
+
...continuations.length === 0 ? {} : { continuations }
|
|
18792
|
+
}), abort.signal);
|
|
18650
18793
|
if (aborted()) return err(stoppedError);
|
|
18651
18794
|
step = "batch";
|
|
18652
18795
|
const observedAt = iso$1(startMs);
|
|
@@ -18659,7 +18802,7 @@ function runSource(entry, options, runnerStartMs) {
|
|
|
18659
18802
|
prs: [ref],
|
|
18660
18803
|
tickets: [],
|
|
18661
18804
|
sessions: []
|
|
18662
|
-
}, parsed.data.entities) ? "does not answer the request" : parsed.data.complete ? "is marked complete" : parsed.data.cursor !== void 0 ? "carries a cursor" : value === void 0 ? "carries another item" : void 0;
|
|
18805
|
+
}, parsed.data.entities) ? "does not answer the request" : parsed.data.complete ? "is marked complete" : parsed.data.cursor !== void 0 ? "carries a cursor" : parsed.data.items.some((item) => item.kind === "pr" && item.continuation !== void 0) ? "carries a continuation" : value === void 0 ? "carries another item" : void 0;
|
|
18663
18806
|
if (!parsed.success || invalid !== void 0 || value === void 0) {
|
|
18664
18807
|
const error = new AdapterError("transient", `Invalid batch: ${invalid ?? "fails the batch schema"}`);
|
|
18665
18808
|
fail("batch", error, parsed.error?.issues.map((issue) => ({
|
|
@@ -20776,6 +20919,7 @@ function createHttpModule(ctx, options = {}) {
|
|
|
20776
20919
|
config: ctx.config,
|
|
20777
20920
|
port: ctx.config.http.port,
|
|
20778
20921
|
ready: () => ctx.state() === "ready",
|
|
20922
|
+
stopping: () => ctx.state() === "stopping",
|
|
20779
20923
|
clock: ctx.clock,
|
|
20780
20924
|
lookupSession: (id) => ctx.logCall("spur.session.lookup", () => lookupLiveSession(ctx.config.adapters.spur.baseUrl, id, options.fetcher)),
|
|
20781
20925
|
verifyToken: (token) => verifyOperatorToken(ctx.store, token),
|
package/dist/mcp.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { m as renderMcpError, u as OPERATIONS, z as ERRORS } from "./src-
|
|
2
|
-
import { a as CliError, r as requestOperation } from "./client-
|
|
3
|
-
import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./config-
|
|
1
|
+
import { m as renderMcpError, u as OPERATIONS, z as ERRORS } from "./src-DYURByVi.mjs";
|
|
2
|
+
import { a as CliError, r as requestOperation } from "./client-BAwxhgyr.mjs";
|
|
3
|
+
import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./config-C0nYXJX4.mjs";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import { readFileSync } from "node:fs";
|
|
6
6
|
import { z } from "zod";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
-- A PR comment history the GitHub adapter is still reading back, per source and PR. A regular
|
|
2
|
+
-- poll's `pr` item asks core to hold it (`continuation` with an opaque `resume`, NULL once the
|
|
3
|
+
-- read reached the start of the PR) and core passes it back in `PollContext.continuations`.
|
|
4
|
+
-- `ref_key` is the PR's entity ref key; `feedback` is the JSON array of feedback entries read so
|
|
5
|
+
-- far, checked by zod on read. Core never parses `resume`. A row goes when an item states `null`
|
|
6
|
+
-- or when the source no longer has an unbanned link to the PR.
|
|
7
|
+
CREATE TABLE pr_continuation (
|
|
8
|
+
source TEXT NOT NULL REFERENCES source_state (source),
|
|
9
|
+
ref_key TEXT NOT NULL,
|
|
10
|
+
resume TEXT,
|
|
11
|
+
feedback TEXT NOT NULL,
|
|
12
|
+
PRIMARY KEY (source, ref_key)
|
|
13
|
+
) STRICT;
|
|
@@ -728,6 +728,13 @@ const ERRORS = {
|
|
|
728
728
|
hint: "Wait until the daemon is ready, then retry the command with its existing idempotency key if it has one.",
|
|
729
729
|
recovery: retry("Wait until the daemon is ready, then retry the command with its existing idempotency key if it has one.", "After the daemon is ready; wait briefly between retries.")
|
|
730
730
|
}),
|
|
731
|
+
stopping: spec("stopping", {
|
|
732
|
+
status: 503,
|
|
733
|
+
exit: EXIT_CODES.notApplied,
|
|
734
|
+
message: "The daemon is stopping; nothing was applied.",
|
|
735
|
+
hint: "Wait until the daemon is running again, then retry the command with its existing idempotency key if it has one; if it stays stopped, ask in your own session.",
|
|
736
|
+
recovery: retry("Wait until the daemon is running again, then retry the command with its existing idempotency key if it has one; if it stays stopped, ask in your own session.", "After the daemon is running again; wait briefly between retries.")
|
|
737
|
+
}),
|
|
731
738
|
github_unavailable: spec("github_unavailable", {
|
|
732
739
|
status: 503,
|
|
733
740
|
exit: EXIT_CODES.notApplied,
|
|
@@ -1736,6 +1743,7 @@ const COMMON_ERRORS = [
|
|
|
1736
1743
|
"forbidden",
|
|
1737
1744
|
"identity_unavailable",
|
|
1738
1745
|
"starting",
|
|
1746
|
+
"stopping",
|
|
1739
1747
|
"not_implemented"
|
|
1740
1748
|
];
|
|
1741
1749
|
const MUTATION_ERRORS = ["idempotency_key_mismatch"];
|
|
@@ -1899,7 +1907,7 @@ const count = (what) => z.int().min(0).describe(what);
|
|
|
1899
1907
|
const statusTaskSchema = taskViewSchema.extend({
|
|
1900
1908
|
shadowColumn: z.enum(COLUMN_IDS).optional().describe("Column the dispatcher works from in shadow mode: where the board would have the task. Present only while the project dispatcher is in shadow mode."),
|
|
1901
1909
|
shadowDiffers: z.boolean().optional().describe("Whether shadowColumn differs from column. Present only while the project dispatcher is in shadow mode."),
|
|
1902
|
-
state: z.string().min(1).describe("One line: ticket status, pull request states and session health
|
|
1910
|
+
state: z.string().min(1).describe("One line: ticket status, pull request states and session counts by health, an ended session counted as `ended (<reason>)`, joined by \"; \"."),
|
|
1903
1911
|
prCount: count("Number of effective pull request links."),
|
|
1904
1912
|
sessionCount: count("Number of effective session links."),
|
|
1905
1913
|
openBlocks: count("Number of open blocks on the task."),
|
|
@@ -3465,7 +3473,8 @@ const entityRefSchema = z.discriminatedUnion("kind", [
|
|
|
3465
3473
|
const batchItemSchema = z.discriminatedUnion("kind", [
|
|
3466
3474
|
z.strictObject({
|
|
3467
3475
|
kind: z.literal("pr").describe("Pull request facts."),
|
|
3468
|
-
facts: prFactsSchema
|
|
3476
|
+
facts: prFactsSchema,
|
|
3477
|
+
continuation: z.strictObject({ resume: sourceCursorSchema.nullable().describe("Opaque position to read further back from; null at the start of the PR.") }).nullable().optional().describe("Comment history core holds for the next poll (A10): omitted says nothing, null drops it, an object holds facts.feedback with resume.")
|
|
3469
3478
|
}),
|
|
3470
3479
|
z.strictObject({
|
|
3471
3480
|
kind: z.literal("ticket").describe("Ticket facts."),
|
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
- `not_implemented`: Ask the operator to update the daemon to a build with this operation.
|
|
8
8
|
- `identity_unavailable`: Ask in your own session, then retry the same command later with its existing idempotency key if it has one.
|
|
9
9
|
- `starting`: Wait until the daemon is ready, then retry the command with its existing idempotency key if it has one.
|
|
10
|
+
- `stopping`: Wait until the daemon is running again, then retry the command with its existing idempotency key if it has one; if it stays stopped, ask in your own session.
|
|
10
11
|
|
|
11
12
|
## Other error hints
|
|
12
13
|
|