paseo-follow-up 2.3.0 → 2.4.0-beta.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/client/brief.tsx +7 -5
- package/client/header.tsx +18 -9
- package/client/home-list.tsx +3 -3
- package/client/home.tsx +3 -2
- package/client/merge-button.tsx +1 -1
- package/client/stacks.tsx +24 -2
- package/index.client.tsx +1 -1
- package/index.server.ts +42 -7
- package/package.json +2 -1
- package/server/agent-actions.ts +4 -3
- package/server/agent-hook.mjs +35 -6
- package/server/browser-bridge.ts +20 -2
- package/server/check-watches.ts +145 -0
- package/server/engine.ts +13 -2
- package/server/github.ts +15 -2
- package/server/hook-source.ts +35 -6
- package/server/mcp-source.ts +8 -5
- package/server/mcp.mjs +8 -5
- package/server/obligations.ts +18 -2
- package/server/pr-actions.ts +17 -11
- package/server/pr-owner.ts +30 -13
- package/server/pr-stats-gate.ts +102 -0
- package/server/pr-stats-store.ts +196 -0
- package/server/pr-stats-sync.ts +228 -0
- package/server/questions.ts +35 -8
- package/server/ranker.ts +3 -2
- package/server/wait-for-checks.ts +108 -0
- package/shared/activity.ts +2 -2
- package/shared/attention.ts +88 -15
- package/shared/brief.ts +16 -0
- package/shared/chat.ts +1 -1
- package/shared/check-watch.ts +129 -0
- package/shared/contracts.ts +10 -3
- package/shared/errors.ts +34 -0
- package/shared/home.ts +51 -13
- package/shared/model.ts +17 -2
- package/shared/poll.ts +9 -2
- package/shared/pr-actions.ts +61 -3
- package/shared/pr-stats-records.ts +169 -0
- package/shared/questions.ts +75 -0
- package/shared/queue.ts +1 -1
- package/shared/ranker.ts +3 -2
- package/shared/scale.ts +24 -0
- package/shared/status-invariants.ts +39 -1
- package/shared/task-status.ts +9 -2
package/shared/pr-actions.ts
CHANGED
|
@@ -11,9 +11,29 @@ export type PrActionKind = z.infer<typeof prActionKind>;
|
|
|
11
11
|
|
|
12
12
|
export const browserPrSchema = z.object({ repo: z.string().regex(/^[\w.-]+\/[\w.-]+$/), number: z.number().int().positive(), head: z.string().min(1), state: z.enum(["OPEN", "MERGED", "CLOSED"]), mergeWhenReady: z.boolean(), merging: z.boolean() });
|
|
13
13
|
export type BrowserPr = z.infer<typeof browserPrSchema>;
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The most PRs one browser exchange command (and its result) carries: a DoS bound on the untrusted browser side, which
|
|
16
|
+
* the Send to Paseo extension enforces too. A longer stack goes as several commands of at most this many
|
|
17
|
+
* (`browserBatches`), never as one that fails the schema (invariant pr-scale-lists-batch-not-throw).
|
|
18
|
+
*/
|
|
19
|
+
export const BROWSER_BATCH = 50;
|
|
20
|
+
/** `items` in order, as consecutive slices of at most `size`. */
|
|
21
|
+
export function browserBatches<T>(items: readonly T[], size = BROWSER_BATCH): T[][] {
|
|
22
|
+
const out: T[][] = [];
|
|
23
|
+
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* PR numbers for a sentence: the first `shown`, then "+N more", so a long stack never grows a result past its text cap
|
|
28
|
+
* (invariant pr-scale-lists-batch-not-throw). `prRefs([1, 2, 3], 2)` is "#1, #2 +1 more".
|
|
29
|
+
*/
|
|
30
|
+
export function prRefs(numbers: readonly (number | string)[], shown = 8): string {
|
|
31
|
+
const head = numbers.slice(0, shown).map(n => `#${n}`).join(", ");
|
|
32
|
+
return numbers.length > shown ? `${head} +${numbers.length - shown} more` : head;
|
|
33
|
+
}
|
|
34
|
+
export const browserCommandSchema = z.object({ id: idSchema, nonce: idSchema, expiresAt: z.string(), op: z.enum(["read", "enable_mwr", "disable_mwr"]), repo: z.string().regex(/^[\w.-]+\/[\w.-]+$/), prs: z.array(z.object({ number: z.number().int().positive(), head: z.string(), trunk: z.string() })).min(1).max(BROWSER_BATCH) });
|
|
15
35
|
export type BrowserCommand = z.infer<typeof browserCommandSchema>;
|
|
16
|
-
export const browserResultSchema = z.object({ id: idSchema, nonce: idSchema, outcome: z.enum(["completed", "failed", "uncertain"]), prs: z.array(browserPrSchema).max(
|
|
36
|
+
export const browserResultSchema = z.object({ id: idSchema, nonce: idSchema, outcome: z.enum(["completed", "failed", "uncertain"]), prs: z.array(browserPrSchema).max(BROWSER_BATCH).default([]), applied: z.array(z.number().int().positive()).max(BROWSER_BATCH).default([]), error: z.string().max(500).default("") });
|
|
17
37
|
export type BrowserResult = z.infer<typeof browserResultSchema>;
|
|
18
38
|
export const browserExchangeSchema = z.object({ clientId: idSchema, ready: z.boolean(), acceptJobs: z.boolean().default(true), results: z.array(browserResultSchema).max(10).default([]), repositories: z.array(browserPrSchema.shape.repo).max(100).default([]) });
|
|
19
39
|
export const browserStatusSchema = z.object({ ready: z.boolean(), reason: z.string().nullable() });
|
|
@@ -25,13 +45,51 @@ export const mergeStageSchema = z.enum(["merged", "queued", "requested"]);
|
|
|
25
45
|
export type MergeStage = z.infer<typeof mergeStageSchema>;
|
|
26
46
|
export const actionResultSchema = z.object({ state: z.enum(["submitted", "failed", "uncertain"]), result: textSchema, merge: mergeStageSchema.optional() });
|
|
27
47
|
|
|
48
|
+
/**
|
|
49
|
+
* For every PR at once: the lowest unmerged PR under it (its downstack, the PRs one click would merge with it) that
|
|
50
|
+
* fails `ok`, null when all pass, or "unreadable" where `downstack` would throw (a cycle, a gap, another repository).
|
|
51
|
+
* One pass over the stack with memoised answers, so asking it of every PR stays linear in the workspace (invariant
|
|
52
|
+
* a-check-costs-linear-in-its-workspace), where calling `downstack` per PR was quadratic and a find per step cubic.
|
|
53
|
+
*/
|
|
54
|
+
export function downstackScan<P extends Pr>(prs: P[], ok: (p: P) => boolean): (key: string) => P | null | "unreadable" {
|
|
55
|
+
const byKey = new Map<string, P>(); for (const p of prs) if (!byKey.has(p.key)) byKey.set(p.key, p);
|
|
56
|
+
const memo = new Map<string, P | null | "unreadable">();
|
|
57
|
+
return (target: string) => {
|
|
58
|
+
if (memo.has(target)) return memo.get(target)!;
|
|
59
|
+
// Walk down to a known answer or the bottom, then fill the answers back up the chain.
|
|
60
|
+
const chain: P[] = []; const onChain = new Set<string>();
|
|
61
|
+
let key: string | null = target; let base: P | null | "unreadable" = null;
|
|
62
|
+
while (key !== null) {
|
|
63
|
+
if (onChain.has(key)) { base = "unreadable"; break; }
|
|
64
|
+
const pr = byKey.get(key);
|
|
65
|
+
if (!pr || chain.length && pr.repo !== chain.at(-1)!.repo) { base = "unreadable"; break; }
|
|
66
|
+
if (memo.has(key)) {
|
|
67
|
+
// A known PR below: its answer, plus the PR itself (the memo holds what is under it, not the PR).
|
|
68
|
+
const known = memo.get(key)!;
|
|
69
|
+
base = known !== null ? known : pr.snapshot?.state !== "MERGED" && !ok(pr) ? pr : null;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
chain.push(pr); onChain.add(key); key = pr.parent;
|
|
73
|
+
}
|
|
74
|
+
// A cycle poisons every PR on it, and so does a gap: downstack throws for each of them.
|
|
75
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
76
|
+
const below = chain[i + 1];
|
|
77
|
+
if (base !== "unreadable" && below && base === null && below.snapshot?.state !== "MERGED" && !ok(below)) base = below;
|
|
78
|
+
memo.set(chain[i]!.key, base);
|
|
79
|
+
}
|
|
80
|
+
return memo.get(target) ?? base;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
28
83
|
export function downstack<P extends Pr>(prs: P[], target: string): P[] {
|
|
29
84
|
const selected: P[] = []; const seen = new Set<string>();
|
|
85
|
+
// One index per call, never a find per step: callers walk every PR's downstack, so a find made a 520-PR stack cubic
|
|
86
|
+
// (2.5 s of one Home build; invariant a-check-costs-linear-in-its-workspace).
|
|
87
|
+
const byKey = new Map<string, P>(); for (const p of prs) if (!byKey.has(p.key)) byKey.set(p.key, p);
|
|
30
88
|
let key: string | null = target; let repo: string | null = null;
|
|
31
89
|
while (key) {
|
|
32
90
|
if (seen.has(key)) throw new Error("This stack has a parent cycle. Reconcile its tracking before merging.");
|
|
33
91
|
seen.add(key);
|
|
34
|
-
const pr =
|
|
92
|
+
const pr = byKey.get(key);
|
|
35
93
|
if (!pr || repo && pr.repo !== repo) throw new Error("A downstack PR is outside this workspace's inventory. Reconcile ownership before merging.");
|
|
36
94
|
repo = pr.repo;
|
|
37
95
|
if (pr.snapshot?.state !== "MERGED") selected.push(pr);
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* PR statistics (docs/pr-stats.md): the compact record kept per PR of an opted-in repository, and how it is parsed
|
|
5
|
+
* from the one GraphQL query the sync reads (`STATS_PAGE_QUERY`, server/pr-stats-sync.ts).
|
|
6
|
+
*
|
|
7
|
+
* What a record holds is the privacy line: numbers, times, logins, branch names and a PR title capped at
|
|
8
|
+
* `TITLE_MAX`. Never a body, a comment's text, a diff or a file list (`stats-records-hold-no-text`,
|
|
9
|
+
* tests/pr-stats-privacy.test.ts). Times are epoch seconds. Bots are dropped at parse time wherever they act on a PR
|
|
10
|
+
* (reviews, comments, requests); a bot's own PR is kept with `ab` so totals can say how many were left out. A
|
|
11
|
+
* repository's ignore list (service accounts that look human) is applied when metrics are computed, so changing it
|
|
12
|
+
* needs no re-read.
|
|
13
|
+
*/
|
|
14
|
+
export const TITLE_MAX = 120;
|
|
15
|
+
/** Review times kept per reviewer per PR: the first response and later re-reviews (review turnaround, M6). */
|
|
16
|
+
export const REVIEW_TIMES_MAX = 10;
|
|
17
|
+
/** The default page size; a 502 or RESOURCE_LIMITS answer halves it for that repository until a page succeeds. */
|
|
18
|
+
export const STATS_PAGE_SIZE = 25;
|
|
19
|
+
export const STATS_PAGE_MIN = 5;
|
|
20
|
+
/** Reviews, comments and timeline events per PR in the page query (design §2.2, measured). */
|
|
21
|
+
export const PAGE_REVIEWS = 20;
|
|
22
|
+
export const PAGE_COMMENTS = 10;
|
|
23
|
+
export const PAGE_TIMELINE = 25;
|
|
24
|
+
|
|
25
|
+
/** Record flags (bits). */
|
|
26
|
+
export const FLAG = {
|
|
27
|
+
/** More reviews than the page read; a follow-up query reads the rest (`REVIEWS_FOLLOW_UP`). Cleared once read. */
|
|
28
|
+
reviewsTruncated: 1,
|
|
29
|
+
/** The first PAGE_COMMENTS comments were all the author's or bots' and there are more: the first response is from reviews only. */
|
|
30
|
+
commentsTruncated: 2,
|
|
31
|
+
/** More draft/ready/request events than the page read: readyAt and askedAt come from the first PAGE_TIMELINE. */
|
|
32
|
+
timelineTruncated: 4,
|
|
33
|
+
} as const;
|
|
34
|
+
|
|
35
|
+
const at = z.number().int().nonnegative();
|
|
36
|
+
const login = z.string().min(1).max(100);
|
|
37
|
+
/**
|
|
38
|
+
* One PR. Short keys: a 50-person team's 90 days are ~3,250 of these (~1 MB on disk).
|
|
39
|
+
* - `n` number, `a` author login (null: a deleted user, "ghost"), `ab` 1 when the author is a bot.
|
|
40
|
+
* - `t` title (≤ TITLE_MAX), `c` createdAt, `u` updatedAt, `r` readyAt (null: still a draft, never ready),
|
|
41
|
+
* `k` askedAt (the first review request at or after readyAt, else readyAt), `m` mergedAt, `x` closedAt.
|
|
42
|
+
* - `s` state O/M/C, `d` draft now, `add`/`del`/`f` lines added/deleted and files changed, `b` base, `h` head.
|
|
43
|
+
* - `rq` review requests `[target, at]` (a user's login, or `@slug` for a team), `rr` requests removed.
|
|
44
|
+
* - `rv` reviews `[login, firstState, ...times]` per non-author person, times ascending (≤ REVIEW_TIMES_MAX);
|
|
45
|
+
* states A approved, C changes requested, M commented, D dismissed.
|
|
46
|
+
* - `fc` first comment `[login, at]` per non-author person, at or after readyAt (all of them while it's a draft).
|
|
47
|
+
*/
|
|
48
|
+
export const statsRecordSchema = z.object({
|
|
49
|
+
n: z.number().int().positive(),
|
|
50
|
+
a: login.nullable(),
|
|
51
|
+
ab: z.literal(1).optional(),
|
|
52
|
+
t: z.string().max(TITLE_MAX),
|
|
53
|
+
c: at, u: at,
|
|
54
|
+
r: at.nullable(), k: at.nullable(),
|
|
55
|
+
m: at.nullable(), x: at.nullable(),
|
|
56
|
+
s: z.enum(["O", "M", "C"]),
|
|
57
|
+
d: z.boolean(),
|
|
58
|
+
add: z.number().int().nonnegative(), del: z.number().int().nonnegative(), f: z.number().int().nonnegative(),
|
|
59
|
+
b: z.string(), h: z.string(),
|
|
60
|
+
rq: z.array(z.tuple([z.string().min(1), at])),
|
|
61
|
+
rr: z.array(z.tuple([z.string().min(1), at])).optional(),
|
|
62
|
+
rv: z.array(z.tuple([login, z.enum(["A", "C", "M", "D"])]).rest(at)),
|
|
63
|
+
fc: z.array(z.tuple([login, at])),
|
|
64
|
+
fl: z.number().int().nonnegative().optional(),
|
|
65
|
+
}).strict();
|
|
66
|
+
export type StatsRecord = z.infer<typeof statsRecordSchema>;
|
|
67
|
+
|
|
68
|
+
type Node = Record<string, any>;
|
|
69
|
+
const seconds = (iso: unknown): number | null => { if (typeof iso !== "string") return null; const ms = Date.parse(iso); return Number.isFinite(ms) ? Math.floor(ms / 1000) : null; };
|
|
70
|
+
/** A bot by GitHub's own type, or a login ending in `[bot]`. The ignore list is applied later (metrics). */
|
|
71
|
+
export function isBotActor(actor: Node | null | undefined): boolean {
|
|
72
|
+
if (!actor) return false;
|
|
73
|
+
return actor.__typename === "Bot" || (typeof actor.login === "string" && /\[bot\]$/i.test(actor.login));
|
|
74
|
+
}
|
|
75
|
+
const STATE = { OPEN: "O", MERGED: "M", CLOSED: "C" } as const;
|
|
76
|
+
const REVIEW = { APPROVED: "A", CHANGES_REQUESTED: "C", COMMENTED: "M", DISMISSED: "D" } as const;
|
|
77
|
+
|
|
78
|
+
/** When the PR stopped being a draft for the first time (design §1.1), or null while it never has. */
|
|
79
|
+
export function readyAtOf(createdAt: number, isDraft: boolean, events: { type: "ready" | "draft"; at: number }[]): number | null {
|
|
80
|
+
const sorted = [...events].sort((p, q) => p.at - q.at);
|
|
81
|
+
const first = sorted[0];
|
|
82
|
+
if (first?.type === "ready") return first.at;
|
|
83
|
+
if (isDraft && !sorted.some(e => e.type === "ready")) return null;
|
|
84
|
+
return createdAt;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Parses one PR node of the page query into a record. Throws on a node without the fields every record needs. */
|
|
88
|
+
export function parseStatsRecord(node: Node): StatsRecord {
|
|
89
|
+
const number = node.number, c = seconds(node.createdAt), u = seconds(node.updatedAt);
|
|
90
|
+
if (!Number.isInteger(number) || number <= 0 || c === null || u === null) throw new Error("A PR in GitHub's answer has no number or times");
|
|
91
|
+
const author: string | null = typeof node.author?.login === "string" ? node.author.login : null;
|
|
92
|
+
const timeline: Node[] = node.timelineItems?.nodes ?? [];
|
|
93
|
+
const draftEvents = timeline.flatMap((e): { type: "ready" | "draft"; at: number }[] => {
|
|
94
|
+
const t = seconds(e?.createdAt);
|
|
95
|
+
if (t === null) return [];
|
|
96
|
+
return e.__typename === "ReadyForReviewEvent" ? [{ type: "ready", at: t }] : e.__typename === "ConvertToDraftEvent" ? [{ type: "draft", at: t }] : [];
|
|
97
|
+
});
|
|
98
|
+
const r = readyAtOf(c, !!node.isDraft, draftEvents);
|
|
99
|
+
const target = (reviewer: Node | null | undefined): string | null => {
|
|
100
|
+
if (!reviewer) return null;
|
|
101
|
+
if (reviewer.__typename === "Team" && typeof reviewer.slug === "string") return `@${reviewer.slug}`;
|
|
102
|
+
if (typeof reviewer.login === "string" && !isBotActor(reviewer)) return reviewer.login;
|
|
103
|
+
return null;
|
|
104
|
+
};
|
|
105
|
+
const requests: [string, number][] = [], removed: [string, number][] = [];
|
|
106
|
+
for (const e of timeline) {
|
|
107
|
+
const t = seconds(e?.createdAt), who = target(e?.requestedReviewer);
|
|
108
|
+
if (t === null || !who) continue;
|
|
109
|
+
if (e.__typename === "ReviewRequestedEvent") requests.push([who, t]);
|
|
110
|
+
else if (e.__typename === "ReviewRequestRemovedEvent") removed.push([who, t]);
|
|
111
|
+
}
|
|
112
|
+
requests.sort((p, q) => p[1] - q[1]); removed.sort((p, q) => p[1] - q[1]);
|
|
113
|
+
// A request made while it was a draft counts from readyAt; none at all: being ready is the ask.
|
|
114
|
+
const k = r === null ? null : requests.length ? Math.max(requests[0]![1], r) : r;
|
|
115
|
+
|
|
116
|
+
const reviews = new Map<string, { state: StatsRecord["rv"][number][1]; times: number[] }>();
|
|
117
|
+
const reviewNodes: Node[] = [...(node.reviews?.nodes ?? [])].sort((p, q) => (seconds(p?.submittedAt) ?? 0) - (seconds(q?.submittedAt) ?? 0));
|
|
118
|
+
for (const review of reviewNodes) addReview(reviews, review, author);
|
|
119
|
+
const comments = new Map<string, number>();
|
|
120
|
+
for (const comment of node.comments?.nodes ?? []) {
|
|
121
|
+
const t = seconds(comment?.createdAt), who = comment?.author?.login;
|
|
122
|
+
if (t === null || typeof who !== "string" || who === author || isBotActor(comment.author)) continue;
|
|
123
|
+
if (r !== null && t < r) continue;
|
|
124
|
+
if (!comments.has(who) || comments.get(who)! > t) comments.set(who, t);
|
|
125
|
+
}
|
|
126
|
+
let fl = 0;
|
|
127
|
+
if ((node.reviews?.totalCount ?? 0) > (node.reviews?.nodes?.length ?? 0)) fl |= FLAG.reviewsTruncated;
|
|
128
|
+
if ((node.comments?.totalCount ?? 0) > (node.comments?.nodes?.length ?? 0) && comments.size === 0) fl |= FLAG.commentsTruncated;
|
|
129
|
+
if (node.timelineItems?.pageInfo?.hasNextPage) fl |= FLAG.timelineTruncated;
|
|
130
|
+
const record: StatsRecord = {
|
|
131
|
+
n: number, a: author, ...(isBotActor(node.author) ? { ab: 1 as const } : {}),
|
|
132
|
+
t: typeof node.title === "string" ? node.title.slice(0, TITLE_MAX) : "",
|
|
133
|
+
c, u, r, k, m: seconds(node.mergedAt), x: seconds(node.closedAt),
|
|
134
|
+
s: STATE[node.state as keyof typeof STATE] ?? "O", d: !!node.isDraft,
|
|
135
|
+
add: count(node.additions), del: count(node.deletions), f: count(node.changedFiles),
|
|
136
|
+
b: typeof node.baseRefName === "string" ? node.baseRefName : "", h: typeof node.headRefName === "string" ? node.headRefName : "",
|
|
137
|
+
rq: requests, ...(removed.length ? { rr: removed } : {}),
|
|
138
|
+
rv: reviewList(reviews),
|
|
139
|
+
fc: [...comments].sort((p, q) => p[1] - q[1]),
|
|
140
|
+
...(fl ? { fl } : {}),
|
|
141
|
+
};
|
|
142
|
+
return record;
|
|
143
|
+
}
|
|
144
|
+
const count = (v: unknown) => Number.isInteger(v) && (v as number) >= 0 ? v as number : 0;
|
|
145
|
+
function addReview(reviews: Map<string, { state: StatsRecord["rv"][number][1]; times: number[] }>, review: Node, author: string | null): void {
|
|
146
|
+
const t = seconds(review?.submittedAt), who = review?.author?.login, state = REVIEW[review?.state as keyof typeof REVIEW];
|
|
147
|
+
// PENDING (an unsubmitted draft review) has no submittedAt and no state here: never a response.
|
|
148
|
+
if (t === null || typeof who !== "string" || !state || who === author || isBotActor(review.author)) return;
|
|
149
|
+
const entry = reviews.get(who);
|
|
150
|
+
if (!entry) { reviews.set(who, { state, times: [t] }); return; }
|
|
151
|
+
if (!entry.times.includes(t)) entry.times.push(t);
|
|
152
|
+
entry.times.sort((p, q) => p - q);
|
|
153
|
+
if (entry.times[0] === t) entry.state = state;
|
|
154
|
+
if (entry.times.length > REVIEW_TIMES_MAX) entry.times.length = REVIEW_TIMES_MAX;
|
|
155
|
+
}
|
|
156
|
+
function reviewList(reviews: Map<string, { state: StatsRecord["rv"][number][1]; times: number[] }>): StatsRecord["rv"] {
|
|
157
|
+
return [...reviews].map(([who, { state, times }]) => [who, state, ...times] as StatsRecord["rv"][number]).sort((p, q) => (p[2] ?? 0) - (q[2] ?? 0));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Merges the reviews a follow-up query read (all of a PR's reviews) into its record and clears the truncation flag. */
|
|
161
|
+
export function withAllReviews(record: StatsRecord, reviewNodes: Node[]): StatsRecord {
|
|
162
|
+
const reviews = new Map<string, { state: StatsRecord["rv"][number][1]; times: number[] }>();
|
|
163
|
+
for (const [who, state, ...times] of record.rv) reviews.set(who, { state, times: [...times] });
|
|
164
|
+
const sorted = [...reviewNodes].sort((p, q) => (seconds(p?.submittedAt) ?? 0) - (seconds(q?.submittedAt) ?? 0));
|
|
165
|
+
for (const review of sorted) addReview(reviews, review, record.a);
|
|
166
|
+
const fl = (record.fl ?? 0) & ~FLAG.reviewsTruncated;
|
|
167
|
+
const { fl: _old, ...rest } = record;
|
|
168
|
+
return { ...rest, rv: reviewList(reviews), ...(fl ? { fl } : {}) };
|
|
169
|
+
}
|
package/shared/questions.ts
CHANGED
|
@@ -404,6 +404,81 @@ export function duplicateOpenQuestions<Q extends Matchable>(questions: readonly
|
|
|
404
404
|
return out;
|
|
405
405
|
}
|
|
406
406
|
|
|
407
|
+
// ---------- one decision, one card (one-decision-one-card) ----------
|
|
408
|
+
//
|
|
409
|
+
// 2026-11-22, the developer: "a lot of the time, 2 questions are created for the same thing". An agent asked Q1 with options
|
|
410
|
+
// (ask_question, often with task set), then marked the task blocked with ask "Q1: may I …?", and Follow-up made a second
|
|
411
|
+
// card from the task (syncTaskQuestions), with no options. Live data: 33 of 96 task-made questions repeated an
|
|
412
|
+
// ask_question question, 19 while it was still open and 13 after the developer had answered it. A task blocked on the
|
|
413
|
+
// developer is covered by the question it points at; it makes a card only when nothing covers it.
|
|
414
|
+
|
|
415
|
+
/** The question ids a text names ("Q1: may I …", "see Q12"), in order. */
|
|
416
|
+
export const questionRefs = (text: string): string[] => [...new Set([...text.matchAll(/\bQ(\d+)\b/g)].map(m => `Q${m[1]}`))];
|
|
417
|
+
const SUPERSEDED = /^(?:Superseded by|Duplicate of|Already asked as|Already answered as) (Q\d+)\./;
|
|
418
|
+
/**
|
|
419
|
+
* Where a decision lives now: the question itself, or the one that replaced it ("Superseded by Q7."). Null when it was
|
|
420
|
+
* withdrawn (it no longer asks anything) or isn't in this workspace. A dismissed question still stands for its decision.
|
|
421
|
+
*/
|
|
422
|
+
export function currentQuestion<Q extends Pick<Question, "id" | "answer" | "closed">>(questions: readonly Q[], id: string): Q | null {
|
|
423
|
+
const seen = new Set<string>();
|
|
424
|
+
let q = questions.find(x => x.id === id) ?? null;
|
|
425
|
+
while (q && q.closed && !q.answer && !q.closed.dismissed) {
|
|
426
|
+
const next = SUPERSEDED.exec(q.closed.reason)?.[1];
|
|
427
|
+
if (!next || seen.has(next)) return null;
|
|
428
|
+
seen.add(q.id);
|
|
429
|
+
q = questions.find(x => x.id === next) ?? null;
|
|
430
|
+
}
|
|
431
|
+
return q;
|
|
432
|
+
}
|
|
433
|
+
/** The ask leads with this question's id: "Q4: …", "Q4 - …", "Q4 (…", "(Q4) …", never "Q40". */
|
|
434
|
+
const leadsWith = (ask: string, id: string) => new RegExp(`^[\\s(\\[]*${id}(?!\\d)`).test(ask);
|
|
435
|
+
/** True when an ask restates `q` (its words, apart from the Q reference, are mostly the question's, title's or options'). */
|
|
436
|
+
function askRepeats(ask: string, q: QuestionShape): boolean {
|
|
437
|
+
const words = tokensOf(wordsOf(ask.replace(/\bQ\d+\b/g, " ")), false);
|
|
438
|
+
if (!words.size) return true;
|
|
439
|
+
const f = featuresOf(q);
|
|
440
|
+
const theirs = new Set([...f.both, ...f.options.flatMap(o => [...o])]);
|
|
441
|
+
return contained(words, theirs) >= 0.5;
|
|
442
|
+
}
|
|
443
|
+
type Coverable = Matchable & Pick<Question, "taskId">;
|
|
444
|
+
/**
|
|
445
|
+
* The question that already asks a blocked task's decision, if any, so the task makes no card of its own. In order:
|
|
446
|
+
* a question the ask names (`Q1: may I …`); one asked with `task` set to it; an open question that reads the same
|
|
447
|
+
* (`findOpenMatch`). Open wins over answered. An answered (or dismissed) one covers only when the ask restates it or
|
|
448
|
+
* leads with its id: the developer already decided, and the agent has the answer. Task-made questions never cover.
|
|
449
|
+
*/
|
|
450
|
+
export function findTaskCover<Q extends Coverable>(o: { id: string; title: string; ask?: string }, questions: readonly Q[], mainAgentId: string | null): Q | null {
|
|
451
|
+
const ask = o.ask?.trim();
|
|
452
|
+
if (!ask) return null;
|
|
453
|
+
const asked = (q: Q | null): q is Q => !!q && q.taskRevision === null;
|
|
454
|
+
let settled: Q | null = null;
|
|
455
|
+
const consider = (q: Q, restated: boolean): Q | null => {
|
|
456
|
+
if (isOpen(q)) return q;
|
|
457
|
+
if (!settled && restated) settled = q;
|
|
458
|
+
return null;
|
|
459
|
+
};
|
|
460
|
+
// A reference links only when the ask leads with the id ("Q1: may I …?", "Q1 - …", "(Q1) …"), restates the question,
|
|
461
|
+
// or the question was asked for this task. A mention in passing ("ship the Q4 report") links nothing: covering the task
|
|
462
|
+
// with an unrelated question would drop its decision, which is worse than a second card.
|
|
463
|
+
for (const id of questionRefs(ask)) {
|
|
464
|
+
const named = questions.find(x => x.id === id);
|
|
465
|
+
const q = currentQuestion(questions, id);
|
|
466
|
+
if (!asked(q)) continue;
|
|
467
|
+
const links = leadsWith(ask, id) || askRepeats(ask, q) || q.taskId === o.id || named?.taskId === o.id;
|
|
468
|
+
if (!links) continue;
|
|
469
|
+
const hit = consider(q, true);
|
|
470
|
+
if (hit) return hit;
|
|
471
|
+
}
|
|
472
|
+
for (let i = questions.length - 1; i >= 0; i--) {
|
|
473
|
+
const q = questions[i];
|
|
474
|
+
if (q.taskId !== o.id || !asked(q) || (q.closed && !q.answer && !q.closed.dismissed)) continue;
|
|
475
|
+
const hit = consider(q, askRepeats(ask, q) || !!compareQuestions({ title: o.title, question: ask, options: [] }, q));
|
|
476
|
+
if (hit) return hit;
|
|
477
|
+
}
|
|
478
|
+
const match = findOpenMatch(questions, { title: o.title, question: ask, options: [] }, mainAgentId);
|
|
479
|
+
return match?.question ?? settled;
|
|
480
|
+
}
|
|
481
|
+
|
|
407
482
|
export const QUESTION_DEDUPE_MIGRATION = "dedupe-open-questions-1";
|
|
408
483
|
/**
|
|
409
484
|
* One-time cleanup (1.4.0-beta.25): open questions that repeat an older open one close as "Duplicate of Qn.". The
|
package/shared/queue.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { BATCH_PREFIXES, RECOVERY_TITLES } from "./legacy";
|
|
|
9
9
|
* runs the prompt (agent-manager recordSubmittedPrompt). So a send that left without a confirmation is never resent
|
|
10
10
|
* blind: the agent's chat is read for it first.
|
|
11
11
|
*/
|
|
12
|
-
export const QUEUE_KINDS = ["answer", "brief", "repair", "recovery", "message"] as const;
|
|
12
|
+
export const QUEUE_KINDS = ["answer", "brief", "repair", "recovery", "message", "checks"] as const;
|
|
13
13
|
export type QueueKind = typeof QUEUE_KINDS[number];
|
|
14
14
|
|
|
15
15
|
/**
|
package/shared/ranker.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { PRIORITY_SOURCES, priorityNote, prioritySourceSchema, type Priority } from "./priorities";
|
|
3
3
|
import type { WorkstreamRow } from "./overseer";
|
|
4
|
+
import { SCALE, truncated } from "./scale";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* The ranker (1.4.0-beta.0, slice 3): one bounded model job that orders Tom's workstreams by what matters today and
|
|
@@ -90,7 +91,7 @@ export function rankPrompt(inputs: RankInputs, today: string, maxChars: number,
|
|
|
90
91
|
|
|
91
92
|
const sourceOut = z.object({ kind: z.enum(PRIORITY_SOURCES), label: z.string().trim().min(1).max(60), url: z.string().url().max(2000).optional().catch(undefined) });
|
|
92
93
|
export const rankReplySchema = z.object({
|
|
93
|
-
priorities:
|
|
94
|
+
priorities: truncated(z.object({ workspace: z.string().trim().min(1).max(200), score: z.number().min(0).max(100), reason: z.string().trim().max(300).catch(""), sources: z.array(sourceOut).max(5).catch([]).default([]) }), SCALE.workspaces),
|
|
94
95
|
notStarted: z.array(z.object({ key: z.string().trim().min(1).max(30), title: z.string().trim().min(1).max(200), url: z.string().url().max(2000).optional().catch(undefined), reason: z.string().trim().max(300).catch("") })).max(20).catch([]).default([]),
|
|
95
96
|
});
|
|
96
97
|
export type RankReply = z.infer<typeof rankReplySchema>;
|
|
@@ -108,7 +109,7 @@ Rules:
|
|
|
108
109
|
- When no outside input names it, use its strongest Paseo fact (its open ask, PR state or checks, "agent stopped") with sources [{"kind":"paseo","label":"Paseo"}].
|
|
109
110
|
- Use only facts in the material. An empty reason is invalid.`;
|
|
110
111
|
export const reasonReplySchema = z.object({
|
|
111
|
-
reasons:
|
|
112
|
+
reasons: truncated(z.object({ workspace: z.string().trim().min(1).max(200), reason: z.string().trim().max(300).catch(""), sources: z.array(sourceOut).max(5).catch([]).default([]) }), SCALE.workspaces),
|
|
112
113
|
});
|
|
113
114
|
export type ReasonReply = z.infer<typeof reasonReplySchema>;
|
|
114
115
|
|
package/shared/scale.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Bounds for lists that grow with a workspace (invariant pr-scale-lists-batch-not-throw). A cap on such a list is a
|
|
5
|
+
* sanity bound far above any real workspace, never a size a busy one reaches: the busiest seen so far carried 65 PRs
|
|
6
|
+
* in one stack, and `tests/pr-scale.test.ts` runs 4x that. Where the far side is untrusted (the browser exchange) the
|
|
7
|
+
* cap stays small and the sender batches to fit instead (`BROWSER_BATCH`).
|
|
8
|
+
*/
|
|
9
|
+
export const SCALE = {
|
|
10
|
+
/** PRs or tasks named in one call about one workspace (add_reviewers, follow.refine-tasks). */
|
|
11
|
+
perWorkspace: 500,
|
|
12
|
+
/** Agents named in one call (sign_off, snooze, set_finish_flags). */
|
|
13
|
+
agents: 500,
|
|
14
|
+
/** Workspaces named in one call or one model reply (set_priorities, the ranker). */
|
|
15
|
+
workspaces: 1000,
|
|
16
|
+
} as const;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* An array a model writes: past `max` items it keeps the first `max` instead of failing the whole reply. For model
|
|
20
|
+
* output only, where a longer list is a model slip, not an attack (the reply is already bounded by its char limit).
|
|
21
|
+
*/
|
|
22
|
+
export function truncated<T extends z.ZodType>(item: T, max: number) {
|
|
23
|
+
return z.preprocess(v => Array.isArray(v) ? v.slice(0, max) : v, z.array(item).max(max));
|
|
24
|
+
}
|
|
@@ -4,7 +4,7 @@ import type { Actor } from "./actor";
|
|
|
4
4
|
import { ANY_HOOK_TEXT_PREFIXES } from "./message-sender";
|
|
5
5
|
import { BATCH_PREFIXES, RECOVERY_TITLES } from "./legacy";
|
|
6
6
|
import type { ListWorkspace as Workspace } from "./list";
|
|
7
|
-
import { answerMessage, awaitingSend, duplicateOpenQuestions, isOther, parseAnswerMessage, parseAnswersMessage } from "./questions";
|
|
7
|
+
import { answerMessage, awaitingSend, duplicateOpenQuestions, findTaskCover, isOpen, isOther, parseAnswerMessage, parseAnswersMessage } from "./questions";
|
|
8
8
|
import { briefAnswer, briefAnswers, briefAsks, briefStep, reviewersBriefPr, shouldReopen, type Brief } from "./brief";
|
|
9
9
|
import { workspaceHeadline, sayNew, repeatsRow, flagHeadline, HEADLINE_WORD } from "./headline";
|
|
10
10
|
import { newEntry, prEndEvent, REASONS, reduce, type InboxRow } from "./inbox";
|
|
@@ -36,6 +36,23 @@ const inFlight = (w: Workspace) => w.batches.some(b => ["sending", "sent"].inclu
|
|
|
36
36
|
const lines = (w: Workspace, now: number) => [liveLine(w, now).text, agentCard(w, now)?.line ?? "", batchView(w, now)?.line ?? "", ...needsYou(w, now).flatMap(i => [i.title, "blocker" in i ? i.blocker ?? "" : ""])];
|
|
37
37
|
|
|
38
38
|
export const INVARIANTS: Invariant[] = [
|
|
39
|
+
{
|
|
40
|
+
id: "a-pr-summary-says-the-worst",
|
|
41
|
+
why: "2026-11-22: a 126-PR workspace with four PRs failing checks read \"#1001+125 ✓\" on Home (the chip took the first open PR's state) and \"Checks are running\" in the panel header (running outranked failing). A line or chip that sums up a workspace's PRs says the worst of its open PRs, and the chip counts failing PRs as the live line does.",
|
|
42
|
+
check(w, now) {
|
|
43
|
+
const open = w.prs.filter(p => p.snapshot?.state === "OPEN");
|
|
44
|
+
const failing = open.filter(p => p.snapshot!.failedChecks?.length);
|
|
45
|
+
// Only a workspace with a problem can read wrong, so only then is the chip built (it orders the stack:
|
|
46
|
+
// a-check-costs-linear-in-its-workspace).
|
|
47
|
+
const problem = open.length > 1 && open.some(p => !p.snapshot!.complete || p.snapshot!.failedChecks?.length || p.snapshot!.threads?.length);
|
|
48
|
+
const chip = problem ? prChip(w) : null;
|
|
49
|
+
if (chip?.checks?.tone === "success") return `the PR chip reads ${chip.checks.text} while an open PR has failing checks, threads or an unknown status`;
|
|
50
|
+
// The chip and the live line count the same thing: PRs with failed checks, not checks.
|
|
51
|
+
if (chip && failing.length && chip.checks?.text !== `✗ ${failing.length}`) return `the PR chip reads ${chip.checks?.text ?? "nothing"} while ${failing.length} PR(s) fail checks`;
|
|
52
|
+
if (failing.length && liveLine(w, now).text === "Checks are running") return `the live line says checks are running while ${failing.length} PR(s) fail checks`;
|
|
53
|
+
return null;
|
|
54
|
+
},
|
|
55
|
+
},
|
|
39
56
|
{
|
|
40
57
|
id: "a-linked-item-uses-every-known-local-title",
|
|
41
58
|
why: "Artifact receipt titles must reach the spec and linked views; explicit names stay chosen. Cross-workspace and linked-store coverage lives in tests/local-titles.test.ts.",
|
|
@@ -419,6 +436,27 @@ export const INVARIANTS: Invariant[] = [
|
|
|
419
436
|
return stray ? `Needs you asks about task ${stray.title}, which isn't blocked on the developer` : null;
|
|
420
437
|
},
|
|
421
438
|
},
|
|
439
|
+
{
|
|
440
|
+
id: "one-decision-one-card",
|
|
441
|
+
why: "2026-11-22, the developer: \"a lot of the time, 2 questions are created for the same thing\". An agent asked Q1 with options and marked its task blocked with ask \"Q1: may I …?\"; Follow-up made Q2 from the task, the same decision with no options (live: 33 of 96 task-made questions). A blocked task covered by a question (it names it, it was asked with task set, or it reads the same) makes no card and no decision item (shared/questions.ts findTaskCover, server/questions.ts syncTaskQuestions).",
|
|
442
|
+
check(w, now) {
|
|
443
|
+
const questions = w.questions ?? [];
|
|
444
|
+
for (const o of w.obligations) {
|
|
445
|
+
if (!blockedOnDeveloper(o)) continue;
|
|
446
|
+
const own = questions.find(q => q.taskId === o.id && q.taskRevision !== null && isOpen(q));
|
|
447
|
+
if (o.coveredBy) {
|
|
448
|
+
if (!questions.some(q => q.id === o.coveredBy)) return `task ${o.title} is covered by ${o.coveredBy}, which isn't in this workspace`;
|
|
449
|
+
if (own) return `${own.id} repeats ${o.coveredBy} for task ${o.title}`;
|
|
450
|
+
}
|
|
451
|
+
if (!own) continue;
|
|
452
|
+
// Uncovered but asked: the same rule the sync uses (findTaskCover), so the check and the fix can't disagree.
|
|
453
|
+
const twin = findTaskCover(o, questions, w.mainAgentId);
|
|
454
|
+
if (twin && isOpen(twin)) return `${own.id} repeats ${twin.id} for task ${o.title}`;
|
|
455
|
+
}
|
|
456
|
+
const decision = needsYou(w, now).find(i => i.kind === "decision" && w.obligations.find(o => o.id === i.obligationId)?.coveredBy);
|
|
457
|
+
return decision && decision.kind === "decision" ? `Needs you asks task ${decision.title}'s decision beside the question that covers it` : null;
|
|
458
|
+
},
|
|
459
|
+
},
|
|
422
460
|
{
|
|
423
461
|
id: "a-github-limit-never-blanks-a-known-pr",
|
|
424
462
|
why: "2026-11-12 live 2.0.1-beta.1: merged PRs with a complete snapshot kept an error from beta.0's RATE_LIMIT failures, the panel let the error win and merged-is-final never re-read them, so they read Unknown for good. A complete snapshot always shows its own status (shared/presentation.ts), and a merged one never stores an error (shared/model.ts prSchema, server/github.ts finalMerged).",
|
package/shared/task-status.ts
CHANGED
|
@@ -32,8 +32,15 @@ export type TaskStatus = {
|
|
|
32
32
|
|
|
33
33
|
export const finishedTask = (o: Obligation) => o.status === "done" || o.status === "waived";
|
|
34
34
|
|
|
35
|
-
/**
|
|
36
|
-
|
|
35
|
+
/**
|
|
36
|
+
* The question a blocked task waits on: the one that covers it (one-decision-one-card: asked once, with ask_question),
|
|
37
|
+
* else the card the server made from it. Answering it shows on the task ("Q1 · answered, waiting on the agent").
|
|
38
|
+
*/
|
|
39
|
+
export const linkedQuestion = (o: Obligation, w: Workspace) => {
|
|
40
|
+
if (o.status !== "blocked") return null;
|
|
41
|
+
const questions = w.questions ?? [];
|
|
42
|
+
return (o.coveredBy ? questions.find(q => q.id === o.coveredBy) : undefined) ?? [...questions].reverse().find(q => q.taskId === o.id && q.taskRevision !== null) ?? null;
|
|
43
|
+
};
|
|
37
44
|
|
|
38
45
|
const name = (live: TaskAgentLive) => live.title?.trim() || "Agent";
|
|
39
46
|
|