spur-board 0.63.1 → 0.63.3
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/daemon.mjs
CHANGED
|
@@ -11735,6 +11735,31 @@ function atAddressee(target, role) {
|
|
|
11735
11735
|
}
|
|
11736
11736
|
};
|
|
11737
11737
|
}
|
|
11738
|
+
/** Advances open questions whose persisted author now holds their stored addressee role. */
|
|
11739
|
+
async function reconcileQuestionAddressees(trx, config, at) {
|
|
11740
|
+
const blocks = await trx.selectFrom("block").selectAll().where("type", "=", "needs_input").where("state", "=", "open").where("task_id", "is not", null).where("addressee_spur_project", "is", null).execute();
|
|
11741
|
+
for (const block of blocks) {
|
|
11742
|
+
if (parseActorId(block.author)?.actor !== "agent" || block.addressee_role !== "curator" && !block.addressee_role.startsWith("orchestrator:")) continue;
|
|
11743
|
+
const subject = await blockSubject(trx, block);
|
|
11744
|
+
const { task } = subject;
|
|
11745
|
+
if (task === null || task.membership === "archived") continue;
|
|
11746
|
+
const target = await subjectTarget(trx, subject, block);
|
|
11747
|
+
if (!holdsBlock(config, block.author, target)) continue;
|
|
11748
|
+
const next = escalateBlock(current$1(block), curatorProject(config, subject.project) !== null, (role) => holdsBlock(config, block.author, atAddressee(target, role)));
|
|
11749
|
+
if (!next.changed) continue;
|
|
11750
|
+
await moveBlockToAddressee(trx, {
|
|
11751
|
+
task,
|
|
11752
|
+
block,
|
|
11753
|
+
to: next.addressee,
|
|
11754
|
+
reason: "asker_is_addressee",
|
|
11755
|
+
ctx: {
|
|
11756
|
+
actor: "system",
|
|
11757
|
+
at
|
|
11758
|
+
},
|
|
11759
|
+
config
|
|
11760
|
+
});
|
|
11761
|
+
}
|
|
11762
|
+
}
|
|
11738
11763
|
function wroteBlock(config, actor, target) {
|
|
11739
11764
|
return authorize([{ grant: "block-author" }], actor, {
|
|
11740
11765
|
config,
|
|
@@ -12422,6 +12447,22 @@ async function savePrPolling(trx, source, fact, recheckAt, preserve = false) {
|
|
|
12422
12447
|
value
|
|
12423
12448
|
}).onConflict((oc) => preserve ? oc.column("key").doNothing() : oc.column("key").doUpdateSet({ value })).execute();
|
|
12424
12449
|
}
|
|
12450
|
+
/**
|
|
12451
|
+
* Replaces the ticket keys `source` last read for a PR in the `pr_ticket_key` candidate index.
|
|
12452
|
+
* `repo` is the snapshot's stored casing. Call it wherever a source writes a snapshot's details
|
|
12453
|
+
* or its polling ticket keys from a fresh read; today that is only pr() in observe.ts.
|
|
12454
|
+
*/
|
|
12455
|
+
async function replacePrTicketKeys(trx, source, repo, number, keys) {
|
|
12456
|
+
await trx.deleteFrom("pr_ticket_key").where("repo", "=", repo).where("number", "=", number).where("source", "=", source).execute();
|
|
12457
|
+
const unique = [...new Set(keys)];
|
|
12458
|
+
if (unique.length === 0) return;
|
|
12459
|
+
await trx.insertInto("pr_ticket_key").values(unique.map((ticket_key) => ({
|
|
12460
|
+
repo,
|
|
12461
|
+
number,
|
|
12462
|
+
source,
|
|
12463
|
+
ticket_key
|
|
12464
|
+
}))).execute();
|
|
12465
|
+
}
|
|
12425
12466
|
/** The PR was merged before the reopen; a tie counts the merge. */
|
|
12426
12467
|
function mergedBefore(fact, reopenedAt) {
|
|
12427
12468
|
return fact.state === "merged" && reopenedAt !== null && Date.parse(fact.mergedAt ?? fact.updatedAt) < Date.parse(reopenedAt);
|
|
@@ -12461,7 +12502,7 @@ async function reconcileTaskPrs(trx, config, taskId, at) {
|
|
|
12461
12502
|
if (task.membership === "archived" || task.manual_exclude === 1) return;
|
|
12462
12503
|
const project = config.projects.find((entry) => entry.id === task.project);
|
|
12463
12504
|
if (project === void 0) return;
|
|
12464
|
-
const snapshots = await trx.selectFrom("pr_snapshot").selectAll().execute();
|
|
12505
|
+
const snapshots = await trx.selectFrom("pr_ticket_key").innerJoin("pr_snapshot", (join) => join.onRef("pr_snapshot.repo", "=", "pr_ticket_key.repo").onRef("pr_snapshot.number", "=", "pr_ticket_key.number")).selectAll("pr_snapshot").distinct().where("pr_ticket_key.ticket_key", "=", task.key).where("pr_ticket_key.source", "in", project.repos.map((repo) => prSourceId(project.id, repo))).orderBy(sql`pr_snapshot.rowid`).execute();
|
|
12465
12506
|
for (const row of snapshots) {
|
|
12466
12507
|
const repo = project.repos.find((repo) => repo.toLowerCase() === row.repo.toLowerCase());
|
|
12467
12508
|
if (repo === void 0) continue;
|
|
@@ -15906,9 +15947,14 @@ const EVENT_SUMMARIES = {
|
|
|
15906
15947
|
token_expired: "Token expired",
|
|
15907
15948
|
token_revoked: "Token revoked"
|
|
15908
15949
|
};
|
|
15909
|
-
function
|
|
15910
|
-
if (kind !== "link_added" && kind !== "link_removed") return null;
|
|
15950
|
+
function linkOrEscalationSummary(kind, payloadText) {
|
|
15951
|
+
if (kind !== "link_added" && kind !== "link_removed" && kind !== "block_escalated") return null;
|
|
15911
15952
|
try {
|
|
15953
|
+
if (kind === "block_escalated") {
|
|
15954
|
+
const payload = eventPayloadSchemas[kind].safeParse(JSON.parse(payloadText));
|
|
15955
|
+
if (!payload.success || payload.data.reason !== "asker_is_addressee") return null;
|
|
15956
|
+
return `Block ${payload.data.block} escalated from ${payload.data.from} to ${payload.data.to}: ${payload.data.reason}`;
|
|
15957
|
+
}
|
|
15912
15958
|
const payload = eventPayloadSchemas[kind].safeParse(JSON.parse(payloadText));
|
|
15913
15959
|
if (!payload.success) return null;
|
|
15914
15960
|
const target = payload.data.entity === "pr" ? `${payload.data.repo}#${String(payload.data.pr)}` : payload.data.entity === "session" ? payload.data.session : payload.data.ticket;
|
|
@@ -16100,7 +16146,7 @@ function createTaskQueries(deps) {
|
|
|
16100
16146
|
at: row.at,
|
|
16101
16147
|
kind,
|
|
16102
16148
|
actor: eventActor(row),
|
|
16103
|
-
summary:
|
|
16149
|
+
summary: linkOrEscalationSummary(kind, row.payload) ?? shadowSummary(kind, row.payload) ?? submitSummary(kind, row.payload) ?? EVENT_SUMMARIES[kind]
|
|
16104
16150
|
}];
|
|
16105
16151
|
});
|
|
16106
16152
|
return {
|
|
@@ -17011,6 +17057,7 @@ async function pr(trx, config, fact, at, source) {
|
|
|
17011
17057
|
source,
|
|
17012
17058
|
observed_at: at
|
|
17013
17059
|
})).execute();
|
|
17060
|
+
await replacePrTicketKeys(trx, source, old?.repo ?? fact.repo, fact.number, fact.ticketKeys);
|
|
17014
17061
|
if (old !== void 0 && old.head_sha.toLowerCase() !== fact.headSha.toLowerCase()) await voidMarksOffHead(trx, {
|
|
17015
17062
|
repo: fact.repo,
|
|
17016
17063
|
number: fact.number,
|
|
@@ -17677,6 +17724,7 @@ async function tickBoard(deps) {
|
|
|
17677
17724
|
at
|
|
17678
17725
|
});
|
|
17679
17726
|
}
|
|
17727
|
+
await reconcileQuestionAddressees(trx, config, at);
|
|
17680
17728
|
await dispatchJournaled(trx, {
|
|
17681
17729
|
config,
|
|
17682
17730
|
at: new Date(now),
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
-- Candidate index of the ticket keys each source last read for a PR, so a task added after its PR
|
|
2
|
+
-- finds the PR without reading every retained snapshot. It may hold stale extras: reconcileTaskPrs
|
|
3
|
+
-- re-checks each candidate against the snapshot and the source's polling state. Only pr() in
|
|
4
|
+
-- observe.ts writes snapshot details and polling keys; a new writer must keep this table current.
|
|
5
|
+
CREATE TABLE pr_ticket_key (
|
|
6
|
+
repo TEXT NOT NULL,
|
|
7
|
+
number INTEGER NOT NULL,
|
|
8
|
+
source TEXT NOT NULL,
|
|
9
|
+
ticket_key TEXT NOT NULL,
|
|
10
|
+
PRIMARY KEY (repo, number, source, ticket_key),
|
|
11
|
+
FOREIGN KEY (repo, number) REFERENCES pr_snapshot (repo, number) ON DELETE CASCADE
|
|
12
|
+
) STRICT;
|
|
13
|
+
CREATE INDEX pr_ticket_key_lookup ON pr_ticket_key (ticket_key, source);
|
|
14
|
+
|
|
15
|
+
-- Each snapshot's keys under the source that wrote it. CASE keeps malformed JSON out of json_each.
|
|
16
|
+
INSERT OR IGNORE INTO pr_ticket_key (repo, number, source, ticket_key)
|
|
17
|
+
SELECT s.repo, s.number, s.source, k.value
|
|
18
|
+
FROM pr_snapshot s,
|
|
19
|
+
json_each(
|
|
20
|
+
CASE WHEN json_valid(s.detail) THEN
|
|
21
|
+
CASE WHEN json_type(s.detail, '$.ticketKeys') = 'array' THEN s.detail END
|
|
22
|
+
END,
|
|
23
|
+
'$.ticketKeys'
|
|
24
|
+
) k
|
|
25
|
+
WHERE k.type = 'text';
|
|
26
|
+
|
|
27
|
+
-- Keys other sources saved in their polling state ('pr-poll:<source>:pr:<lower repo>#<number>').
|
|
28
|
+
-- Each key is parsed once and joined through a temporary index on the lowercased snapshot
|
|
29
|
+
-- identity, so the backfill does not compare every polling key with every snapshot. Repo names
|
|
30
|
+
-- hold no ':' or '#', so the repo is the text after the last ':' and the number follows the '#'.
|
|
31
|
+
CREATE INDEX pr_snapshot_lower_identity ON pr_snapshot (lower(repo), number);
|
|
32
|
+
|
|
33
|
+
INSERT OR IGNORE INTO pr_ticket_key (repo, number, source, ticket_key)
|
|
34
|
+
SELECT s.repo, s.number, p.source, k.value
|
|
35
|
+
FROM (
|
|
36
|
+
SELECT value,
|
|
37
|
+
substr(prefix, 1, length(prefix) - 4) AS source,
|
|
38
|
+
substr(head, length(prefix) + 1, length(head) - length(prefix) - 1) AS repo,
|
|
39
|
+
CAST(digits AS INTEGER) AS number
|
|
40
|
+
FROM (
|
|
41
|
+
SELECT value, head, digits,
|
|
42
|
+
rtrim(head, replace(head, ':', '')) AS prefix
|
|
43
|
+
FROM (
|
|
44
|
+
SELECT value, head, substr(rest, length(head) + 1) AS digits
|
|
45
|
+
FROM (
|
|
46
|
+
SELECT value, rest, rtrim(rest, '0123456789') AS head
|
|
47
|
+
FROM (SELECT value, substr(key, 9) AS rest FROM meta WHERE key GLOB 'pr-poll:*')
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
WHERE head GLOB '*#' AND digits <> '' AND CAST(CAST(digits AS INTEGER) AS TEXT) = digits
|
|
52
|
+
AND prefix GLOB '*:pr:' AND length(prefix) > 4
|
|
53
|
+
) p
|
|
54
|
+
JOIN pr_snapshot s ON lower(s.repo) = p.repo AND s.number = p.number,
|
|
55
|
+
json_each(
|
|
56
|
+
CASE WHEN json_valid(p.value) THEN
|
|
57
|
+
CASE WHEN json_type(p.value, '$.ticketKeys') = 'array' THEN p.value END
|
|
58
|
+
END,
|
|
59
|
+
'$.ticketKeys'
|
|
60
|
+
) k
|
|
61
|
+
WHERE k.type = 'text';
|
|
62
|
+
|
|
63
|
+
DROP INDEX pr_snapshot_lower_identity;
|