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/attention.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { IDLE_REASON, MAIN_WAIT, NO_PROGRESS_CAP, QUIET_WAIT, mainWait } from ".
|
|
|
7
7
|
import { workingLine } from "./task-status";
|
|
8
8
|
import { followUpObligations, recoveryBatch } from "./follow-up";
|
|
9
9
|
import { orderedStacks, prLink, settledForDisplay, type PrLink } from "./presentation";
|
|
10
|
-
import {
|
|
10
|
+
import { downstackScan, githubApproved, graphiteReady, isGithubFlow, mergeBlockers, prActionBlocks } from "./pr-actions";
|
|
11
11
|
import { configuredReviewers, noReviewers, reviewersAsk, suggestedReviewers } from "./reviewers";
|
|
12
12
|
import { agentMerges } from "./pr-workflow";
|
|
13
13
|
import { awaitingSend, isOpen as questionOpen, questionState, type QuestionState } from "./questions";
|
|
@@ -76,6 +76,61 @@ export function stackBar(w: Pick<Workspace, "prs">): { segments: Segment[]; merg
|
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/** The most marks the stack bar draws: at the panel's ~370 px that is about 7 px each, still readable and clickable. */
|
|
80
|
+
export const STACK_BAR_BUDGET = 40;
|
|
81
|
+
/** How loud a tone is in the stack bar: what needs fixing first, settled work last. */
|
|
82
|
+
const BAR_RANK: Record<PrTone, number> = { danger: 0, warning: 1, unknown: 2, draft: 3, pending: 4, approved: 5, closed: 6, merged: 7 };
|
|
83
|
+
/** One mark on the stack bar: `count` PRs in stack order from #`from` to #`to`, painted `tone`; it opens `key`. */
|
|
84
|
+
export type BarMark = { key: string; number: number; tone: PrTone; count: number; from: number; to: number };
|
|
85
|
+
/**
|
|
86
|
+
* The stack bar's marks (`stack-bar-reads-at-any-size`): one per PR up to STACK_BAR_BUDGET; past it, runs of
|
|
87
|
+
* neighbouring PRs in the same state, each as wide as its share of the stack; and when even the runs are too many, the
|
|
88
|
+
* stack in equal slices, each painted its loudest PR's tone. The order is kept, a failing PR is never averaged away,
|
|
89
|
+
* and a mark opens its loudest PR. 2026-11-22: a 126-PR workspace drew 126 segments about 1 px wide, a dotted hairline.
|
|
90
|
+
*/
|
|
91
|
+
export function barMarks(segments: readonly Segment[], budget = STACK_BAR_BUDGET): BarMark[] {
|
|
92
|
+
const one = (s: Segment): BarMark => ({ key: s.key, number: s.number, tone: s.tone, count: 1, from: s.number, to: s.number });
|
|
93
|
+
if (segments.length <= budget) return segments.map(one);
|
|
94
|
+
const merge = (group: readonly Segment[]): BarMark => {
|
|
95
|
+
const loud = group.reduce((a, b) => BAR_RANK[b.tone] < BAR_RANK[a.tone] ? b : a);
|
|
96
|
+
return { key: loud.key, number: loud.number, tone: loud.tone, count: group.length, from: group[0]!.number, to: group.at(-1)!.number };
|
|
97
|
+
};
|
|
98
|
+
const runs: Segment[][] = [];
|
|
99
|
+
for (const s of segments) { const last = runs.at(-1); if (last && last[0]!.tone === s.tone) last.push(s); else runs.push([s]); }
|
|
100
|
+
if (runs.length <= budget) return runs.map(merge);
|
|
101
|
+
const size = Math.ceil(segments.length / budget);
|
|
102
|
+
const slices: Segment[][] = [];
|
|
103
|
+
for (let i = 0; i < segments.length; i += size) slices.push(segments.slice(i, i + size));
|
|
104
|
+
return slices.map(merge);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** A stack longer than this folds its quiet runs in the Pull requests card. */
|
|
108
|
+
export const QUIET_FOLD_FROM = 20;
|
|
109
|
+
/** The shortest run of quiet PRs worth a fold: shorter ones show as they are. */
|
|
110
|
+
export const QUIET_FOLD_MIN = 4;
|
|
111
|
+
export type StackItem<P> = { kind: "pr"; pr: P } | { kind: "quiet"; key: string; prs: P[] };
|
|
112
|
+
/**
|
|
113
|
+
* The Pull requests card's rows for one stack (`a-long-stack-shows-its-problems`): past QUIET_FOLD_FROM PRs, each run
|
|
114
|
+
* of at least QUIET_FOLD_MIN neighbouring PRs that are only in review (pending: nothing failing, no threads, not
|
|
115
|
+
* approved, not a draft) folds into one "+N in review" row that `isOpen(key)` expands in place. Everything else (a
|
|
116
|
+
* failure, a thread, an approval, a draft, an unknown status) keeps its own row, in stack order, so problems are on
|
|
117
|
+
* screen without scrolling past the quiet ones. 2026-11-22: a 120-PR stack drew every row, about 8000 px, and its
|
|
118
|
+
* seven PRs to fix were scattered through it.
|
|
119
|
+
*/
|
|
120
|
+
export function quietFold<P extends Pr>(prs: readonly P[], isOpen: (key: string) => boolean, from = QUIET_FOLD_FROM, min = QUIET_FOLD_MIN): StackItem<P>[] {
|
|
121
|
+
if (prs.length <= from) return prs.map(pr => ({ kind: "pr", pr }));
|
|
122
|
+
const out: StackItem<P>[] = [];
|
|
123
|
+
let run: P[] = [];
|
|
124
|
+
const flush = () => {
|
|
125
|
+
if (run.length >= min) { const key = `quiet:${run[0]!.key}`; out.push({ kind: "quiet", key, prs: run }); if (isOpen(key)) out.push(...run.map(pr => ({ kind: "pr" as const, pr }))); }
|
|
126
|
+
else out.push(...run.map(pr => ({ kind: "pr" as const, pr })));
|
|
127
|
+
run = [];
|
|
128
|
+
};
|
|
129
|
+
for (const pr of prs) { if (prTone(pr) === "pending") run.push(pr); else { flush(); out.push({ kind: "pr", pr }); } }
|
|
130
|
+
flush();
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
|
|
79
134
|
const pendingSends = (w: Workspace) => w.batches.filter(b => !recoveryBatch(b) && b.state === "pending");
|
|
80
135
|
const openBatches = (w: Workspace) => w.batches.filter(b => !recoveryBatch(b) && ["sending", "sent", "blocked", "uncertain"].includes(b.state));
|
|
81
136
|
const QUEUED = ["QUEUED_TO_MERGE", "WAITING_TO_MERGE", "REBASING", "HANDED_OFF_TO_EXTERNAL_MERGE_QUEUE"];
|
|
@@ -281,8 +336,9 @@ function computeAllNeeds(w: Workspace, now: number): NeedItem[] {
|
|
|
281
336
|
detail: inChat ? "It's in the agent's chat. Send it there, or from here." : "You copied it. Paste it into the agent's chat, or send it from here." });
|
|
282
337
|
}
|
|
283
338
|
for (const q of open.filter(q => questionState(q) !== "stopped")) items.push({ kind: "question", key: `question:${q.id}`, questionId: q.id, title: `${q.id} · ${q.title}`, detail: q.question, state: questionState(q), big: q.big });
|
|
284
|
-
// A blocked task is a question once the server mirrors it
|
|
285
|
-
|
|
339
|
+
// A blocked task is a question once the server mirrors it, or the question that covers it (one-decision-one-card);
|
|
340
|
+
// until then it still shows as a decision.
|
|
341
|
+
for (const o of followUpObligations(w).filter(o => blockedOnDeveloper(o) && !o.coveredBy && !questions.some(q => q.taskId === o.id && q.taskRevision !== null)))
|
|
286
342
|
items.push({ kind: "decision", key: `decision:${o.id}`, obligationId: o.id, title: o.title, detail: o.ask! });
|
|
287
343
|
// Repairs Auto won't send (an idle agent Follow-up doesn't wake) wait on you just like hand-sent ones (shared/status.ts).
|
|
288
344
|
const view = batchView(w, now);
|
|
@@ -297,14 +353,18 @@ function computeAllNeeds(w: Workspace, now: number): NeedItem[] {
|
|
|
297
353
|
const blocking = (pr: Pr) => w.prActions.some(a => prActionBlocks(a, [pr.key]));
|
|
298
354
|
// One click merges the PR and its unmerged downstack (a-click-on-merge-merges), so Merge is offered only when every
|
|
299
355
|
// PR it would merge can merge: never a button the plan will refuse. A stack it can't read keeps the PR's own verdict.
|
|
300
|
-
|
|
301
|
-
|
|
356
|
+
// Each PR's own verdict once: every PR's stack check reads the PRs under it, so recomputing made a long stack's
|
|
357
|
+
// check cubic (invariant a-check-costs-linear-in-its-workspace; tests/pr-scale.test.ts).
|
|
358
|
+
const own = new Map<string, boolean>();
|
|
359
|
+
const canMerge = (p: Pr) => { let v = own.get(p.key); if (v === undefined) own.set(p.key, v = mergeReady(p, w, now) && workflowReady(p) && !blocking(p)); return v; };
|
|
360
|
+
const holding = downstackScan(w.prs, canMerge);
|
|
361
|
+
const stackReady = (pr: Pr) => { const by = holding(pr.key); return by === "unreadable" || by === null; };
|
|
302
362
|
for (const pr of stackOrder(w.prs)) {
|
|
303
363
|
// Only offer Merge here when the PR's workflow (Graphite, or GitHub itself) agrees; otherwise the PR sheet explains what is missing.
|
|
304
364
|
// A PR the agent merges itself (its own register_pr answer, else a No review repository) is the agent's work in
|
|
305
365
|
// flight, never the developer's merge or review. Invariant a-no-review-repo-never-asks-for-review-or-merge.
|
|
306
366
|
if (agentMerges(pr)) continue;
|
|
307
|
-
if (
|
|
367
|
+
if (canMerge(pr) && stackReady(pr)) items.push({ kind: "merge", key: `merge:${pr.key}`, prKey: pr.key, number: pr.number, pr: prLink(pr), title: isGithubFlow(pr.snapshot) && pr.snapshot!.reviewDecision !== "APPROVED" ? `#${pr.number} is ready to merge` : `#${pr.number} is approved`, detail: pr.snapshot!.title });
|
|
308
368
|
// One ask per PR (one-reviewers-ask-per-pr): it names whom Follow-up suggests, so Follow-up's own reviewers brief
|
|
309
369
|
// folds into it (shared/needs-block.ts) instead of drawing a second ask for the same PR.
|
|
310
370
|
else if (asksForReviewers(pr, w)) { const suggested = suggestedReviewers(pr.repo, pr.snapshot!.reviewers?.author); items.push({ kind: "reviewers", key: `reviewers:${pr.key}`, prKey: pr.key, number: pr.number, pr: prLink(pr), suggested, title: reviewersAsk(pr.number, suggested, `#${pr.number} has no reviewers`), detail: pr.snapshot!.title }); }
|
|
@@ -312,16 +372,23 @@ function computeAllNeeds(w: Workspace, now: number): NeedItem[] {
|
|
|
312
372
|
// One Merge per stack: the topmost ready PR's Merge names and merges the PRs under it ("Merge 3 PRs"), so a ready PR
|
|
313
373
|
// under it isn't a second ask for the same decision. Merging only a lower one stays in its PR sheet.
|
|
314
374
|
const merges = items.filter((i): i is Extract<NeedItem, { kind: "merge" }> => i.kind === "merge");
|
|
315
|
-
|
|
375
|
+
// Walk each Merge's parents only until a PR another Merge already covers: everything under it is covered too, so
|
|
376
|
+
// the whole pass reads each PR once (a downstack per Merge was quadratic on a long, all-ready stack).
|
|
377
|
+
const covered = new Set<string>();
|
|
378
|
+
const parentOf = merges.length > 1 ? new Map(w.prs.map(p => [p.key, p.parent] as const)) : new Map<string, string | null>();
|
|
379
|
+
if (merges.length > 1) for (const m of merges) {
|
|
380
|
+
if (holding(m.prKey) === "unreadable") continue;
|
|
381
|
+
for (let k = parentOf.get(m.prKey) ?? null; k !== null && !covered.has(k); k = parentOf.get(k) ?? null) covered.add(k);
|
|
382
|
+
}
|
|
316
383
|
return items.filter(i => i.kind !== "merge" || !covered.has(i.prKey));
|
|
317
384
|
}
|
|
318
385
|
|
|
319
|
-
/** Why a downstack PR holds a merge, in a few words ("checks
|
|
386
|
+
/** Why a downstack PR holds a merge, in a few words, in the rows' words ("checks failed"). */
|
|
320
387
|
function holdReason(p: Pr): string {
|
|
321
388
|
const s = p.snapshot;
|
|
322
389
|
if (!s?.complete || p.error) return "status unknown";
|
|
323
390
|
if (s.conflict) return "conflicts";
|
|
324
|
-
if (s.failedChecks?.length) return "checks
|
|
391
|
+
if (s.failedChecks?.length) return "checks failed";
|
|
325
392
|
if (s.checksPending) return "checks running";
|
|
326
393
|
if (s.draft) return "a draft";
|
|
327
394
|
if (s.threads?.length) return "open threads";
|
|
@@ -331,18 +398,20 @@ function holdReason(p: Pr): string {
|
|
|
331
398
|
/**
|
|
332
399
|
* Approved PRs that Merge isn't offered on because a PR under them can't merge yet (a-click-on-merge-merges: a Merge
|
|
333
400
|
* row merges its whole downstack). Needs you leaves them out (the PR below is the agent's repair), so the panel's
|
|
334
|
-
* Pull requests card and Home's detail pane say it: "#143 approved · waits on #142 (checks
|
|
401
|
+
* Pull requests card and Home's detail pane say it: "#143 approved · waits on #142 (checks failed)". An approved PR
|
|
335
402
|
* never goes quiet.
|
|
336
403
|
*/
|
|
337
404
|
export function heldMerges(w: Workspace, now = Date.now()): { pr: Pr; by: Pr; line: string }[] {
|
|
338
405
|
if (!w.enable_tracking || w.archived) return [];
|
|
339
406
|
const blocking = (pr: Pr) => w.prActions.some(a => prActionBlocks(a, [pr.key]));
|
|
407
|
+
const own = new Map<string, boolean>();
|
|
408
|
+
const canMerge = (p: Pr) => { let v = own.get(p.key); if (v === undefined) own.set(p.key, v = mergeReady(p, w, now) && workflowReady(p) && !blocking(p)); return v; };
|
|
409
|
+
const holding = downstackScan(w.prs, canMerge);
|
|
340
410
|
const out: { pr: Pr; by: Pr; line: string }[] = [];
|
|
341
411
|
for (const pr of stackOrder(w.prs)) {
|
|
342
|
-
if (agentMerges(pr) || !
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
if (by) out.push({ pr, by, line: `#${pr.number} ${isGithubFlow(pr.snapshot) && pr.snapshot!.reviewDecision !== "APPROVED" ? "is ready" : "approved"} · waits on #${by.number} (${holdReason(by)})` });
|
|
412
|
+
if (agentMerges(pr) || !canMerge(pr)) continue;
|
|
413
|
+
const by = holding(pr.key);
|
|
414
|
+
if (by && by !== "unreadable") out.push({ pr, by, line: `#${pr.number} ${isGithubFlow(pr.snapshot) && pr.snapshot!.reviewDecision !== "APPROVED" ? "is ready" : "approved"} · waits on #${by.number} (${holdReason(by)})` });
|
|
346
415
|
}
|
|
347
416
|
return out;
|
|
348
417
|
}
|
|
@@ -370,7 +439,7 @@ export function headline(w: Workspace, now = Date.now()): HeadlinePart[] {
|
|
|
370
439
|
return parts;
|
|
371
440
|
}
|
|
372
441
|
|
|
373
|
-
export type LiveIcon = "spinner" | "sent" | "done" | "paused" | "waiting" | "alert" | "idle";
|
|
442
|
+
export type LiveIcon = "spinner" | "sent" | "done" | "paused" | "waiting" | "alert" | "failing" | "idle";
|
|
374
443
|
/** What is happening right now, in one line, with the time it started when known. */
|
|
375
444
|
/**
|
|
376
445
|
* The panel header's live line. Say it once (Q49): while a message is queued, the Tasks strip right below carries when
|
|
@@ -411,6 +480,10 @@ export function liveLine(w: Workspace, now = Date.now()): { icon: LiveIcon; text
|
|
|
411
480
|
const waiting = followUpObligations(w).find(o => o.status === "waiting");
|
|
412
481
|
if (waiting) return { icon: "waiting", text: waiting.title, since: null };
|
|
413
482
|
if (w.prs.some(p => !statusKnown(p))) return { icon: "alert", text: "Some PR status is unavailable · retrying", since: null };
|
|
483
|
+
// The worst open PR first (a-pr-summary-says-the-worst): failing checks before running ones, never the reverse.
|
|
484
|
+
const failing = w.prs.filter(p => p.snapshot?.state === "OPEN" && p.snapshot.failedChecks?.length);
|
|
485
|
+
// Red, in the rows' words ("Checks failed"): a failed check is a repair, not something waiting on the developer.
|
|
486
|
+
if (failing.length) return { icon: "failing", text: failing.length === 1 ? `Checks failed on #${failing[0]!.number}` : `Checks failed on ${failing.length} PRs`, since: null };
|
|
414
487
|
if (w.prs.some(p => p.snapshot?.state === "OPEN" && p.snapshot.checksPending)) return { icon: "waiting", text: "Checks are running", since: null };
|
|
415
488
|
if (w.prs.some(p => p.snapshot?.state === "OPEN")) return { icon: "waiting", text: "Waiting on review and merges", since: null };
|
|
416
489
|
return { icon: "idle", text: "Waiting for the main agent to declare Done", since: null };
|
package/shared/brief.ts
CHANGED
|
@@ -668,6 +668,22 @@ export function briefCardShown<B extends Pick<Brief, "state" | "kind" | "source"
|
|
|
668
668
|
return !!b && (briefAsks(b, row) || drawnNeeds === 0);
|
|
669
669
|
}
|
|
670
670
|
|
|
671
|
+
/**
|
|
672
|
+
* What a brief card says, on every surface that draws one (the chat's card included): the brief's ask when
|
|
673
|
+
* `briefCardShown` lets it draw, else what Needs you holds, so "No ask stated" or "Nothing needed" never sits beside
|
|
674
|
+
* an ask (a-brief-without-an-ask-never-sits-beside-needs-you). Only an open brief points away; an answered or
|
|
675
|
+
* closed one keeps its own words as history. 2026-11-22: the chat's card read "Finished · No ask stated" beside a
|
|
676
|
+
* Needs you of "Send 7 tasks" and "Merge 3 PRs"; it checked only for open questions, on its own.
|
|
677
|
+
*/
|
|
678
|
+
export function briefCardAsk<B extends Pick<Brief, "state" | "kind" | "source" | "ask">>(brief: B, row: { needs?: unknown } | null | undefined, drawn: readonly { kind: string; title: string; questionId?: string }[]): string {
|
|
679
|
+
if (!liveBrief(brief) || briefCardShown(brief, row, drawn.length)) return brief.ask;
|
|
680
|
+
const questions = drawn.flatMap(i => i.kind === "question" && i.questionId ? [i.questionId] : []);
|
|
681
|
+
if (questions.length === drawn.length) return `Waiting on your answer to ${questions.join(", ")}`;
|
|
682
|
+
// "and N more" in words, unbreakable: "+1 more" after a title with its own " · " read as part of its last clause, and
|
|
683
|
+
// wrapped "more" alone onto a phone's second line.
|
|
684
|
+
return `Needs you: ${drawn[0]!.title}${drawn.length > 1 ? `, and\u00a0${drawn.length - 1}\u00a0more` : ""}`;
|
|
685
|
+
}
|
|
686
|
+
|
|
671
687
|
/** The PR an add-reviewers brief asks about: its Add reviewers move's PR. Null for every other kind. */
|
|
672
688
|
export function reviewersBriefPr(b: { kind: string; moves?: readonly { kind: string; prKey?: string | null }[]; prKey?: string }): string | null {
|
|
673
689
|
if (b.kind !== "reviewers") return null;
|
package/shared/chat.ts
CHANGED
|
@@ -145,7 +145,7 @@ export const TOOL_PRESENTATION: Record<string, "routine" | "moment"> = {
|
|
|
145
145
|
follow_settings: "routine", set_follow_settings: "routine", project_settings: "routine", set_project_tracking: "routine", pr_workflow: "routine",
|
|
146
146
|
set_pr_workflow: "routine", reviewer_settings: "routine", reviewer_suggestions: "routine", save_reviewers: "routine", set_agent_setting: "routine",
|
|
147
147
|
set_wait_for_jobs: "routine", onboarding_status: "routine", onboarding_checks: "routine", set_onboarding: "routine", rank_status: "routine",
|
|
148
|
-
rerank_priorities: "routine", overseer_status: "routine", overseer_start: "routine", overseer_restart: "routine", overseer_ask: "routine", catch_up_deck: "routine", context_requests: "routine", ask_context: "routine", context_reply: "routine",
|
|
148
|
+
rerank_priorities: "routine", overseer_status: "routine", overseer_start: "routine", overseer_restart: "routine", overseer_ask: "routine", catch_up_deck: "routine", context_requests: "routine", ask_context: "routine", context_reply: "routine", wait_for_checks: "routine",
|
|
149
149
|
inbox_brief: "routine", brief_action: "routine", queue_list: "routine", queue_action: "routine", inbox_act: "routine", answer_question: "routine", dismiss_question: "routine", dismiss_item: "routine", run_recovery: "routine",
|
|
150
150
|
set_workspace_spec: "routine", link_item: "routine", unlink_item: "routine", link_items: "routine", set_linked_items: "routine", set_task_trigger: "routine", pr_controls: "routine", browser_status: "routine", trust_bypass_status: "routine",
|
|
151
151
|
release_notes: "routine", updates_status: "routine", check_updates: "routine", set_updates: "routine", install_update: "routine", retry_move: "routine", report_issue: "routine", report_send: "routine", make_main_agent: "routine", wait_prepare_job: "routine", wait_for_job: "routine", wait_get_job: "routine",
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { SCALE } from "./scale";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Wait for checks (docs/wait-for-checks.md): an agent asks Follow-up to tell it when a PR's checks finish, ends its
|
|
6
|
+
* turn, and gets one message afterwards. Follow-up answers from the reads it already makes of every tracked PR (a
|
|
7
|
+
* watched PR reads at the running-checks cadence, inside the backoff and the reserve), so waiting adds no GitHub
|
|
8
|
+
* read of its own (waiting-for-checks-adds-no-github-read). Pure: the server keeps the watches (server/check-watches.ts).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** How long a watch lasts when the agent doesn't say (like Wait's job limit). */
|
|
12
|
+
export const WATCH_DEFAULT_MS = 3 * 60 * 60_000;
|
|
13
|
+
export const WATCH_MAX_MS = 12 * 60 * 60_000;
|
|
14
|
+
/**
|
|
15
|
+
* "All passed" needs the head to have been quiet this long, or checks seen running on it: right after a push GitHub
|
|
16
|
+
* can list a head with no check suites yet, which reads as "nothing running" for a few seconds.
|
|
17
|
+
*/
|
|
18
|
+
export const WATCH_SETTLE_MS = 60_000;
|
|
19
|
+
/** At most this many open watches per agent: a watch per PR of the biggest stack fits (pr-scale-lists-batch-not-throw); this only stops a runaway loop. */
|
|
20
|
+
export const WATCHES_PER_AGENT = SCALE.perWorkspace;
|
|
21
|
+
|
|
22
|
+
export const checkWatchSchema = z.object({
|
|
23
|
+
id: z.string().min(1).max(200),
|
|
24
|
+
agentId: z.string().min(1).max(200),
|
|
25
|
+
workspaceId: z.string().min(1).max(200),
|
|
26
|
+
/** owner/repo#number */
|
|
27
|
+
prKey: z.string().min(1).max(300),
|
|
28
|
+
url: z.string().max(2000),
|
|
29
|
+
createdAt: z.string(),
|
|
30
|
+
until: z.string(),
|
|
31
|
+
/** Set while the tool call that made it is still answering: that call reports the verdict itself, never a message too. */
|
|
32
|
+
answering: z.boolean().default(false),
|
|
33
|
+
/** A head on which checks were seen running: they finished on that head, so "all passed" needs no settle wait. */
|
|
34
|
+
runningHead: z.string().nullable().default(null),
|
|
35
|
+
});
|
|
36
|
+
export type CheckWatch = z.infer<typeof checkWatchSchema>;
|
|
37
|
+
export const checkWatchFileSchema = z.object({ version: z.literal(1), watches: z.array(checkWatchSchema).default([]) });
|
|
38
|
+
export type CheckWatchFile = z.infer<typeof checkWatchFileSchema>;
|
|
39
|
+
|
|
40
|
+
export type WatchedPr = {
|
|
41
|
+
key: string; repo: string; number: number; error: string | null;
|
|
42
|
+
snapshot: {
|
|
43
|
+
url: string; state: "OPEN" | "MERGED" | "CLOSED"; head: string; conflict: boolean; complete: boolean; observedAt: string;
|
|
44
|
+
failedChecks: string[]; otherFailedChecks?: string[]; checksPending: boolean; checksRunning?: boolean;
|
|
45
|
+
} | null;
|
|
46
|
+
};
|
|
47
|
+
export type VerdictKind = "passed" | "failed" | "merged" | "closed" | "conflict" | "expired" | "gone";
|
|
48
|
+
export type Verdict = { kind: VerdictKind; prKey: string; head: string | null; failed: string[]; text: string };
|
|
49
|
+
|
|
50
|
+
const short = (sha: string | null | undefined) => sha ? sha.slice(0, 7) : "unknown";
|
|
51
|
+
const checksUrl = (pr: WatchedPr) => pr.snapshot?.url ? `${pr.snapshot.url.replace(/\/$/, "")}/checks` : null;
|
|
52
|
+
export const WATCH_HEADER = "Follow-up checks";
|
|
53
|
+
|
|
54
|
+
/** The message (or the tool's immediate answer) for a verdict: one header line, then what happened and what to do. */
|
|
55
|
+
export function verdictText(kind: VerdictKind, pr: WatchedPr, extra: { failed?: string[]; pending?: boolean; running?: boolean } = {}): string {
|
|
56
|
+
const name = `${pr.repo}#${pr.number}`;
|
|
57
|
+
const head = short(pr.snapshot?.head);
|
|
58
|
+
const link = checksUrl(pr);
|
|
59
|
+
switch (kind) {
|
|
60
|
+
case "passed": return `${WATCH_HEADER} ${name}: all checks passed on ${head}.${extra.pending ? " A required check hasn't reported yet, so GitHub may still block the merge." : ""}`;
|
|
61
|
+
case "failed": {
|
|
62
|
+
const failed = extra.failed ?? [];
|
|
63
|
+
return `${WATCH_HEADER} ${name}: ${failed.length} check${failed.length === 1 ? "" : "s"} failed on ${head}: ${failed.join(", ")}.${extra.running ? " Others are still running." : ""}${link ? ` Details: ${link}` : ""}`;
|
|
64
|
+
}
|
|
65
|
+
case "merged": return `${WATCH_HEADER} ${name}: merged.`;
|
|
66
|
+
case "closed": return `${WATCH_HEADER} ${name}: closed without merging.`;
|
|
67
|
+
case "conflict": return `${WATCH_HEADER} ${name}: it has a merge conflict with its base on ${head}; checks may not run until it's resolved.`;
|
|
68
|
+
case "expired": return `${WATCH_HEADER} ${name}: stopped waiting after the time limit; the last read showed checks still running on ${head}. Call wait_for_checks again if you still need the result.`;
|
|
69
|
+
case "gone": return `${WATCH_HEADER} ${name}: Follow-up no longer follows this PR, so it stopped waiting.`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* One watch against the PR as Follow-up last read it. `fire`: the watch ends with this verdict. `next`: the watch,
|
|
75
|
+
* possibly updated (runningHead), when it keeps waiting. Only a read made after the watch began decides anything:
|
|
76
|
+
* an older read may predate the agent's push. Never throws.
|
|
77
|
+
*
|
|
78
|
+
* - merged, closed, a merge conflict: at once.
|
|
79
|
+
* - a required check failed: at once (the agent has to fix it whatever else runs); other failures once nothing runs.
|
|
80
|
+
* - all finished and none failed: "passed", once checks were seen running on this head or the head has been quiet
|
|
81
|
+
* WATCH_SETTLE_MS (`quietSince`: when the PR's content last changed, or null when unknown).
|
|
82
|
+
*/
|
|
83
|
+
export function watchVerdict(watch: CheckWatch, pr: WatchedPr | undefined, now: number, quietSince: number | null = null): { fire: Verdict | null; next: CheckWatch } {
|
|
84
|
+
const keep = (next: CheckWatch = watch) => ({ fire: null, next });
|
|
85
|
+
const end = (kind: VerdictKind, p: WatchedPr, extra: Parameters<typeof verdictText>[2] = {}) =>
|
|
86
|
+
({ fire: { kind, prKey: watch.prKey, head: p.snapshot?.head ?? null, failed: extra.failed ?? [], text: verdictText(kind, p, extra) }, next: watch });
|
|
87
|
+
if (!pr) return { fire: { kind: "gone", prKey: watch.prKey, head: null, failed: [], text: verdictText("gone", { key: watch.prKey, ...splitKey(watch.prKey), error: null, snapshot: null }) }, next: watch };
|
|
88
|
+
const s = pr.snapshot;
|
|
89
|
+
if (now >= Date.parse(watch.until)) return end("expired", pr);
|
|
90
|
+
if (!s || pr.error || !s.complete) return keep();
|
|
91
|
+
if (Date.parse(s.observedAt) < Date.parse(watch.createdAt)) return keep();
|
|
92
|
+
if (s.state === "MERGED") return end("merged", pr);
|
|
93
|
+
if (s.state === "CLOSED") return end("closed", pr);
|
|
94
|
+
if (s.conflict) return end("conflict", pr);
|
|
95
|
+
const running = s.checksRunning ?? s.checksPending;
|
|
96
|
+
if (s.failedChecks.length) return end("failed", pr, { failed: [...s.failedChecks, ...(s.otherFailedChecks ?? [])], running });
|
|
97
|
+
if (running) return watch.runningHead === s.head ? keep() : keep({ ...watch, runningHead: s.head });
|
|
98
|
+
const others = s.otherFailedChecks ?? [];
|
|
99
|
+
if (others.length) return end("failed", pr, { failed: others });
|
|
100
|
+
const settled = watch.runningHead === s.head || quietSince !== null && now - quietSince >= WATCH_SETTLE_MS;
|
|
101
|
+
return settled ? end("passed", pr, { pending: s.checksPending }) : keep();
|
|
102
|
+
}
|
|
103
|
+
export function splitKey(key: string): { repo: string; number: number } {
|
|
104
|
+
const at = key.lastIndexOf("#");
|
|
105
|
+
return { repo: key.slice(0, at), number: Number(key.slice(at + 1)) || 0 };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* a-waited-for-failure-is-sent-once: a failure the agent waits for that a repair message will carry anyway (the agent
|
|
110
|
+
* is the workspace's main agent, Auto-send is on, and a repair batch with this PR's checks task is queued, going out or
|
|
111
|
+
* out) ends the watch quietly: the repair is the one message. Anything else (Auto-send off, a contributor waiting) gets
|
|
112
|
+
* the watch's message.
|
|
113
|
+
*/
|
|
114
|
+
export function coveredByRepair(w: { mainAgentId: string; enable_auto_sends: boolean; batches: readonly { state: string; tasks: readonly { kind: string; target: string }[] }[] }, agentId: string, prKey: string): boolean {
|
|
115
|
+
if (w.mainAgentId !== agentId || !w.enable_auto_sends) return false;
|
|
116
|
+
return w.batches.some(b => ["pending", "sending", "sent", "uncertain"].includes(b.state) && !b.tasks.every(t => t.kind === "inventory") && b.tasks.some(t => t.kind === "checks" && t.target === prKey));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** A PR reference from the tool: a URL, owner/repo#N, or a bare number (in the agent's own workspace). */
|
|
120
|
+
export function parsePrRef(ref: string): { repo: string | null; number: number; forge: "github" | "other" } | null {
|
|
121
|
+
const text = ref.trim();
|
|
122
|
+
const url = /^https?:\/\/([^/]+)\/([\w.-]+)\/([\w.-]+)\/(?:pull|pulls|merge_requests|-\/merge_requests)\/(\d+)/i.exec(text);
|
|
123
|
+
if (url) return { repo: `${url[2]}/${url[3]}`, number: Number(url[4]), forge: /(^|\.)github\.com$/i.test(url[1]) ? "github" : "other" };
|
|
124
|
+
const key = /^([\w.-]+\/[\w.-]+)#(\d+)$/.exec(text);
|
|
125
|
+
if (key) return { repo: key[1], number: Number(key[2]), forge: "github" };
|
|
126
|
+
const bare = /^#?(\d+)$/.exec(text);
|
|
127
|
+
if (bare) return { repo: null, number: Number(bare[1]), forge: "github" };
|
|
128
|
+
return null;
|
|
129
|
+
}
|
package/shared/contracts.ts
CHANGED
|
@@ -24,6 +24,7 @@ import { HOME_GROUPS } from "./home";
|
|
|
24
24
|
import { prWorkflowViewSchema, setPrWorkflowInputSchema } from "./pr-workflow";
|
|
25
25
|
import { setUpdatesInputSchema, updatesViewSchema } from "./updates";
|
|
26
26
|
import { releaseNotesViewSchema } from "./changelog";
|
|
27
|
+
import { SCALE } from "./scale";
|
|
27
28
|
import { actionPlanSchema, actionResultSchema, browserCommandSchema, browserExchangeSchema, browserPrSchema, browserStatusSchema, prActionKind } from "./pr-actions";
|
|
28
29
|
|
|
29
30
|
const agentCommunicationSchema = z.strictObject({
|
|
@@ -44,7 +45,7 @@ export const agentStatusRpc = defineRpc({ name: "follow.agent-status", input: z.
|
|
|
44
45
|
export const syncWorkspaceRpc = defineRpc({ name: "follow.sync", input: z.strictObject({ agentId: idSchema, summary: z.string().trim().min(1).max(1000) }), output: z.object({ workspaceId: idSchema, synced: z.literal(true) }) });
|
|
45
46
|
export const enrollRpc = defineRpc({ name: "follow.enroll", input: z.strictObject({ workspaceId: idSchema.optional(), agentId: idSchema, goal: textSchema }), output: workspaceSchema });
|
|
46
47
|
export const registerPrRpc = defineRpc({ name: "follow.register-pr", input: z.strictObject({ agentId: idSchema, repo: z.string().regex(/^[\w.-]+\/[\w.-]+$/), number: z.number().int().positive(), stack: textSchema, parentNumber: z.number().int().positive().nullable().optional(), disposition: z.string().max(2000).optional(), agentMerges: z.boolean().optional() }), output: workspaceSchema });
|
|
47
|
-
export const obligationRpc = defineRpc({ name: "follow.obligation", input: z.strictObject({ agentId: idSchema, workingAgentId: idSchema.optional(), id: idSchema.optional(), title: textSchema, status: z.enum(["pending", "waiting", "working", "blocked", "done", "waived"]), afterPrs: z.array(idSchema).optional(), dependencyStage: z.enum(["merged", "deployed"]).optional(), evidence: z.string().max(4000).optional(), ask: z.string().trim().min(1).max(1000).optional(), enable_follow_up: z.boolean().optional(), communication: agentCommunicationSchema.optional(), trigger: taskTriggerSchema.strict().nullable().optional() }), output: workspaceSchema.extend({ updatedObligationId: idSchema }) });
|
|
48
|
+
export const obligationRpc = defineRpc({ name: "follow.obligation", input: z.strictObject({ agentId: idSchema, workingAgentId: idSchema.optional(), id: idSchema.optional(), title: textSchema, status: z.enum(["pending", "waiting", "working", "blocked", "done", "waived"]), afterPrs: z.array(idSchema).optional(), dependencyStage: z.enum(["merged", "deployed"]).optional(), evidence: z.string().max(4000).optional(), ask: z.string().trim().min(1).max(1000).optional(), question: z.string().regex(/^Q\d+$/).optional(), enable_follow_up: z.boolean().optional(), communication: agentCommunicationSchema.optional(), trigger: taskTriggerSchema.strict().nullable().optional() }), output: workspaceSchema.extend({ updatedObligationId: idSchema, note: z.string().optional() }) });
|
|
48
49
|
export const declareDoneRpc = defineRpc({ name: "follow.done", input: z.strictObject({ agentId: idSchema, summary: textSchema }), output: z.object({ workspace: workspaceSchema, blockers: z.array(z.string()), unconfirmed: z.array(z.string()).default([]), alreadyDone: z.boolean().default(false), next: z.string().default("") }) });
|
|
49
50
|
export const acknowledgeRpc = defineRpc({ name: "follow.acknowledge", input: z.strictObject({ agentId: idSchema, batchId: idSchema, outcome: z.enum(["completed", "blocked"]), result: textSchema, /** With blocked: only a person can move what is still open (Batch.humanOnly). */ humanOnly: z.boolean().optional() }), output: workspaceSchema });
|
|
50
51
|
export const controlRpc = defineRpc({ name: "follow.control", input: z.object({ workspaceId: idSchema, enable_auto_sends: z.boolean().optional(), clearHold: z.boolean().optional(), retryBatchId: idSchema.optional(), /** Retry one capped task (Q49): its key. */ retryTask: z.string().max(400).optional(), /** Auto per task: a task key and whether Follow-up sends it. */ taskAuto: z.object({ key: z.string().max(400), auto: z.boolean() }).optional(), /** The developer's "Make main agent": one of the workspace's other root agents. */ mainAgentId: idSchema.optional(),
|
|
@@ -100,14 +101,14 @@ export const renameWorkspaceRpc = defineRpc({ name: "follow.rename-workspace", i
|
|
|
100
101
|
export const usageRpc = defineRpc({ name: "follow.usage", input: z.object({}), output: usageSchema });
|
|
101
102
|
// Trust bypass agents: how many permission prompts were approved today, and the newest few (tool and a short summary).
|
|
102
103
|
export const trustBypassRpc = defineRpc({ name: "follow.trust-bypass", input: z.object({}), output: z.object({ today: z.number().int().nonnegative(), recent: z.array(z.object({ at: z.string(), agentId: z.string(), tool: z.string(), summary: z.string(), mode: z.string() })).max(20) }) });
|
|
103
|
-
export const refineTasksRpc = defineRpc({ name: "follow.refine-tasks", input: z.object({ workspaceId: idSchema, tasks: z.array(z.object({ id: idSchema, title: textSchema, afterPrs: z.array(idSchema), dependencyStage: z.enum(["merged", "deployed"]), enable_follow_up: z.boolean(), communication: communicationSchema.optional(), trigger: taskTriggerSchema.nullable().optional() })).max(
|
|
104
|
+
export const refineTasksRpc = defineRpc({ name: "follow.refine-tasks", input: z.object({ workspaceId: idSchema, tasks: z.array(z.object({ id: idSchema, title: textSchema, afterPrs: z.array(idSchema), dependencyStage: z.enum(["merged", "deployed"]), enable_follow_up: z.boolean(), communication: communicationSchema.optional(), trigger: taskTriggerSchema.nullable().optional() })).max(SCALE.perWorkspace) }), output: workspaceSchema });
|
|
104
105
|
export const taskTriggerRpc = defineRpc({ name: "follow.set-task-trigger", input: z.object({ workspaceId: idSchema, obligationId: idSchema, expectedRevision: z.number().int().nonnegative(), trigger: taskTriggerSchema.nullable(), afterPrs: z.array(idSchema) }), output: workspaceSchema });
|
|
105
106
|
|
|
106
107
|
// Narrow integration: no inventory, messages, paths, or credentials cross this RPC.
|
|
107
108
|
export const prOwnerRpc = defineRpc({ name: "follow.pr-owner", input: z.strictObject({ repo: z.string().regex(/^[\w.-]+\/[\w.-]+$/), number: z.number().int().positive() }), output: z.object({ owner: z.object({ workspaceId: idSchema, agentId: idSchema }).nullable() }) });
|
|
108
109
|
// Read-only browser view of who owns a PR: titles, ids, agent status and Follow-up's one line. Nothing else.
|
|
109
110
|
// `tracked: false` means the repository is outside the scope Follow-up advertises to the browser, so nothing is returned.
|
|
110
|
-
export const prWorkspacesRpc = defineRpc({ name: "follow.pr-workspaces", input: z.strictObject({ repo: z.string().regex(/^[\w.-]+\/[\w.-]+$/), number: z.number().int().positive() }), output: z.object({ tracked: z.boolean(), more: z.number().int().nonnegative(), workspaces: z.array(z.object({ workspaceId: idSchema, agentId: idSchema, title: z.string().max(200), agentStatus: z.string().max(40), group: z.enum(HOME_GROUPS), state: z.string().max(200) })).max(3) }) });
|
|
111
|
+
export const prWorkspacesRpc = defineRpc({ name: "follow.pr-workspaces", input: z.strictObject({ repo: z.string().regex(/^[\w.-]+\/[\w.-]+$/), number: z.number().int().positive() }), output: z.object({ tracked: z.boolean(), more: z.number().int().nonnegative(), workspaces: z.array(z.object({ workspaceId: idSchema, agentId: idSchema, title: z.string().max(200), agentStatus: z.string().max(40), group: z.enum(HOME_GROUPS), state: z.string().max(200), tone: z.enum(["attention", "danger", "success", "accent", "muted"]) })).max(3) }) });
|
|
111
112
|
|
|
112
113
|
// Questions. Agents ask, record an answer given in chat, or withdraw; the developer answers from the UI.
|
|
113
114
|
const optionInput = z.strictObject({ letter: z.string().regex(/^[A-Z]$/), label: z.string().trim().min(1).max(200), consequence: z.string().trim().max(600).optional() });
|
|
@@ -229,6 +230,12 @@ export const contextListRpc = defineRpc({ name: "follow.context-list", input: z.
|
|
|
229
230
|
export const catchUpDeckRpc = defineRpc({ name: "follow.catch-up-deck", input: z.strictObject({}), output: z.object({
|
|
230
231
|
cards: z.array(z.object({ key: z.string(), kind: z.string(), workspaceId: z.string().nullable(), agentId: z.string().nullable(), title: z.string(), line: z.string(),
|
|
231
232
|
questionId: z.string().nullable(), item: z.string().nullable(), context: contextRequestSchema.pick({ id: true, state: true, target: true }).nullable() })) }) });
|
|
233
|
+
/**
|
|
234
|
+
* Wait for checks (docs/wait-for-checks.md): the caller's PRs whose checks it waits on. `prs`: URLs, owner/repo#N or
|
|
235
|
+
* numbers; none means every open PR of the caller's workspace. `cancel` stops waiting. One message comes after the turn.
|
|
236
|
+
*/
|
|
237
|
+
export const waitForChecksRpc = defineRpc({ name: "follow.wait-for-checks", input: z.strictObject({ agentId: z.string().min(1).max(200), prs: z.array(z.string().trim().min(1).max(2000)).max(SCALE.perWorkspace).optional(), minutes: z.number().int().min(1).max(720).optional(), cancel: z.boolean().optional() }),
|
|
238
|
+
output: z.object({ text: z.string(), waiting: z.array(z.string()), done: z.array(z.object({ pr: z.string(), result: z.string(), text: z.string() })), notFollowed: z.array(z.string()) }) });
|
|
232
239
|
export const contextReplyRpc = defineRpc({ name: "follow.context-reply", input: z.strictObject({ agentId: z.string().min(1).max(200), requestId: z.string().min(1).max(80), text: z.string().trim().min(1).max(CONTEXT_ANSWER_MAX) }), output: z.object({ ok: z.boolean() }) });
|
|
233
240
|
export const rankStatusSchema = z.object({ enabled: z.boolean(), running: z.boolean(), lastRunAt: z.string().nullable(), healthLine: z.string(), error: z.string().nullable(), costUsd: z.number().nullable(), notStarted: z.number().int(),
|
|
234
241
|
last: z.object({ ok: z.boolean(), skipped: z.string().nullable(), top: z.string().nullable(), provider: z.string().nullable(), inputTokens: z.number().nullable(), outputTokens: z.number().nullable() }).nullable() });
|
package/shared/errors.ts
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
|
+
type Issue = { code?: unknown; path?: unknown; message?: unknown; maximum?: unknown; minimum?: unknown; origin?: unknown };
|
|
2
|
+
/** A zod error's issues, or those in its message (a JSON array with `code` and `path`) after it crossed an RPC as text. */
|
|
3
|
+
function schemaIssues(error: unknown): Issue[] | null {
|
|
4
|
+
if (error && typeof error === "object" && (error as { name?: unknown }).name === "ZodError" && Array.isArray((error as { issues?: unknown }).issues)) return (error as { issues: Issue[] }).issues;
|
|
5
|
+
const raw = (error instanceof Error ? error.message : typeof error === "string" ? error : "").replace(/^Request failed:\s*/i, "").replace(/\s*requestType=\S+.*$/s, "").trim();
|
|
6
|
+
if (!/^\[\s*\{/.test(raw) || !/"code"\s*:/.test(raw) || !/"path"\s*:/.test(raw)) return null;
|
|
7
|
+
try { const parsed: unknown = JSON.parse(raw); return Array.isArray(parsed) ? parsed as Issue[] : null; } catch { return []; }
|
|
8
|
+
}
|
|
9
|
+
export const isSchemaError = (error: unknown): boolean => schemaIssues(error) !== null;
|
|
10
|
+
function issueText(i: Issue): string {
|
|
11
|
+
const where = Array.isArray(i.path) && i.path.length ? i.path.map(String).join(".") : "the request";
|
|
12
|
+
const list = i.origin === "array", str = i.origin === "string";
|
|
13
|
+
if (i.code === "too_big" && typeof i.maximum === "number") return list ? `${where} has more than ${i.maximum} items` : str ? `${where} is longer than ${i.maximum} characters` : `${where} is above ${i.maximum}`;
|
|
14
|
+
if (i.code === "too_small" && typeof i.minimum === "number") return list ? `${where} needs at least ${i.minimum} item${i.minimum === 1 ? "" : "s"}` : str ? `${where} is too short` : `${where} is below ${i.minimum}`;
|
|
15
|
+
if (i.code === "invalid_type") return `${where} is missing or the wrong type`;
|
|
16
|
+
return `${where} isn't valid`;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A schema validator's issue list as one plain sentence (invariant pr-scale-lists-batch-not-throw): what didn't fit,
|
|
20
|
+
* never the JSON. The full issues go to the plugin log (`plainError`), not onto a card, a pill or a tool result.
|
|
21
|
+
*/
|
|
22
|
+
export function schemaErrorText(error: unknown): string {
|
|
23
|
+
const issues = schemaIssues(error) ?? [];
|
|
24
|
+
const parts = [...new Set(issues.slice(0, 3).map(issueText))];
|
|
25
|
+
return parts.length ? `Follow-up couldn't finish this: ${parts.join("; ")}${issues.length > 3 ? `; +${issues.length - 3} more` : ""}. The details are in the plugin log.` : "Follow-up couldn't finish this: some data didn't fit what it expects. The details are in the plugin log.";
|
|
26
|
+
}
|
|
27
|
+
/** The error to throw to a person or an agent: a schema error becomes one plain sentence (its issues logged); others pass. */
|
|
28
|
+
export function plainError(error: unknown, log: (detail: string) => void = d => console.error(d)): unknown {
|
|
29
|
+
if (!isSchemaError(error)) return error;
|
|
30
|
+
log(`[follow-up] schema error: ${error instanceof Error ? error.message : String(error)}`.slice(0, 4000));
|
|
31
|
+
return new Error(schemaErrorText(error));
|
|
32
|
+
}
|
|
33
|
+
|
|
1
34
|
/** RPC errors arrive as "Request failed: <reason> requestType=… code=…"; people only need the reason. */
|
|
2
35
|
export function errorText(error: unknown): string {
|
|
36
|
+
if (isSchemaError(error)) return schemaErrorText(error);
|
|
3
37
|
const raw = error instanceof Error ? error.message : String(error ?? "");
|
|
4
38
|
return raw.replace(/^Request failed:\s*/i, "").replace(/\s*requestType=\S+.*$/s, "").trim() || "Something went wrong. Try again.";
|
|
5
39
|
}
|
package/shared/home.ts
CHANGED
|
@@ -43,7 +43,8 @@ export function recentMainChange(w: Pick<Workspace, "mainHistory" | "mainAgentId
|
|
|
43
43
|
const last = w.mainHistory?.at(-1);
|
|
44
44
|
return last && last.by !== "developer" && last.to === w.mainAgentId && now - Date.parse(last.at) < 24 * 60 * 60_000 ? last : null;
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
/** `checks.spoken`: what a screen reader says for `text` when the glyph alone would be ambiguous ("4 PRs with failed checks"). */
|
|
47
|
+
export type PrChip = { label: string; tone: PrTone; checks: { text: string; tone: BadgeTone; spoken?: string } | null; url: string | null };
|
|
47
48
|
/** A Paseo workspace as Home needs it. Untracked workspaces still get a row, in Quiet. */
|
|
48
49
|
export type PaseoWorkspaceLite = {
|
|
49
50
|
id: string; name: string; project: string | null; activityAt: string | null;
|
|
@@ -104,23 +105,60 @@ const plural = (n: number, one: string, many = `${one}s`) => `${n} ${n === 1 ? o
|
|
|
104
105
|
/** In flight: the send glyph. Queued to go out on its own: the clock family, never Running's spinner (Q51). */
|
|
105
106
|
const sendingIcon = (s: Sending) => s.state === "sent" ? "Send" : "ClockArrowUp";
|
|
106
107
|
|
|
107
|
-
|
|
108
|
+
type ChipChecks = NonNullable<PrChip["checks"]>;
|
|
109
|
+
/** One PR's checks as the chip says them. Null: its status isn't known (unknown is not ✓). */
|
|
110
|
+
function prChecks(s: Pr["snapshot"]): ChipChecks | null {
|
|
111
|
+
return !s?.complete ? null
|
|
112
|
+
: s.state === "MERGED" ? { text: "merged", tone: "merged" }
|
|
113
|
+
: s.state === "CLOSED" ? { text: "closed", tone: "muted" }
|
|
114
|
+
: s.failedChecks?.length ? { text: `✗ ${s.failedChecks.length}`, tone: "danger", spoken: plural(s.failedChecks.length, "failed check") }
|
|
115
|
+
: s.checksPending ? { text: "running", tone: "muted" }
|
|
116
|
+
: s.draft ? { text: "draft", tone: "muted" }
|
|
117
|
+
: s.threads?.length ? { text: plural(s.threads.length, "thread"), tone: "warning" }
|
|
118
|
+
: { text: "✓", tone: "success", spoken: "checks passed" };
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The PR chip as a screen reader says it, the same on every surface that draws it (a Home row's label, the detail
|
|
122
|
+
* pane's chip, the phone's meta line): "Pull request #1029 and 125 more, 4 PRs with failed checks". The glyph alone
|
|
123
|
+
* is ambiguous: "✗ 4" counts PRs on a chip for many open PRs and checks on a chip for one.
|
|
124
|
+
*/
|
|
125
|
+
export function prChipSpoken(pr: PrChip): string {
|
|
126
|
+
const [, number, more] = /^(#\d+)(?:\+(\d+))?$/.exec(pr.label) ?? [, pr.label, undefined];
|
|
127
|
+
const name = `Pull request ${number}${more ? ` and ${more} more` : ""}`;
|
|
128
|
+
return pr.checks ? `${name}, ${pr.checks.spoken ?? pr.checks.text}` : name;
|
|
129
|
+
}
|
|
130
|
+
/** How bad an open PR's checks are, worst first: failing, open threads, unknown, running, draft, clear. */
|
|
131
|
+
function chipRank(s: Pr["snapshot"]): number {
|
|
132
|
+
if (!s?.complete) return 2;
|
|
133
|
+
return s.failedChecks?.length ? 0 : s.threads?.length ? 1 : s.checksPending ? 3 : s.draft ? 4 : 5;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The PR chip (`a-pr-summary-says-the-worst`): the workspace's PRs in one chip, so it says the worst of its open PRs,
|
|
137
|
+
* never the first one's. It names the first open PR in stack order with the worst state ("#1058+125"), else the first
|
|
138
|
+
* that hasn't settled, else the last; "+n" counts the rest. At failing checks it counts the PRs failing ("✗ 4", spoken
|
|
139
|
+
* "4 PRs with failed checks"), the same number as the panel's "Checks failed on 4 PRs"; at open threads it adds up the
|
|
140
|
+
* threads. An open PR whose status isn't known keeps it from saying ✓. 2026-11-22: a
|
|
141
|
+
* 126-PR workspace with four PRs failing checks read "#1001+125 ✓", the first PR's state.
|
|
142
|
+
*/
|
|
108
143
|
export function prChip(w: Workspace | undefined): PrChip | null {
|
|
109
144
|
if (!w?.prs.length) return null;
|
|
110
145
|
const ordered = stackOrder(w.prs);
|
|
111
146
|
const open = ordered.filter(p => !settled(p));
|
|
112
|
-
const pr: Pr = open[0] ?? ordered.at(-1)!;
|
|
113
147
|
const more = (open.length || ordered.length) - 1;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
:
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
148
|
+
if (open.length <= 1) {
|
|
149
|
+
const pr: Pr = open[0] ?? ordered.at(-1)!;
|
|
150
|
+
return { label: `#${pr.number}${more > 0 ? `+${more}` : ""}`, tone: prTone(pr), checks: prChecks(pr.snapshot), url: pr.snapshot?.url ?? null };
|
|
151
|
+
}
|
|
152
|
+
const ranks = open.map(p => chipRank(p.snapshot));
|
|
153
|
+
const worst = Math.min(...ranks);
|
|
154
|
+
const at = open.filter((_, i) => ranks[i] === worst);
|
|
155
|
+
const pr = worst < 5 ? at[0]! : open[0]!;
|
|
156
|
+
const sum = (f: (s: NonNullable<Pr["snapshot"]>) => number) => at.reduce((n, p) => n + f(p.snapshot!), 0);
|
|
157
|
+
const checks: ChipChecks | null = worst === 0 ? { text: `✗ ${at.length}`, tone: "danger", spoken: `${plural(at.length, "PR")} with failed checks` }
|
|
158
|
+
: worst === 1 ? { text: plural(sum(s => s.threads?.length ?? 0), "thread"), tone: "warning" }
|
|
159
|
+
: worst === 2 ? null
|
|
160
|
+
: prChecks(pr.snapshot);
|
|
161
|
+
return { label: `#${pr.number}${more > 0 ? `+${more}` : ""}`, tone: prTone(pr), checks, url: pr.snapshot?.url ?? null };
|
|
124
162
|
}
|
|
125
163
|
|
|
126
164
|
/** One trailing chip on a desktop row: a semantic badge or the PR chip. */
|
package/shared/model.ts
CHANGED
|
@@ -67,6 +67,12 @@ export const obligationSchema = z.object({
|
|
|
67
67
|
afterPrs: z.array(idSchema), evidence: z.string().max(4000),
|
|
68
68
|
/** While blocked: the question the developer must answer. Without one, a blocked task waits on nothing of theirs. */
|
|
69
69
|
ask: z.string().max(1000).optional(),
|
|
70
|
+
/**
|
|
71
|
+
* While blocked on the developer: the question that already asks this decision (one-decision-one-card), so the task
|
|
72
|
+
* makes no card of its own. Set by syncTaskQuestions, kept while the ask is unchanged (an answered one still covers it:
|
|
73
|
+
* the agent has the answer), dropped when the ask changes or the task leaves blocked.
|
|
74
|
+
*/
|
|
75
|
+
coveredBy: z.string().regex(/^Q\d+$/).optional(),
|
|
70
76
|
enable_follow_up: z.boolean().default(false), revision: z.number().int().nonnegative(),
|
|
71
77
|
dependencyStage: z.enum(["merged", "deployed"]).optional(), category: z.enum(["follow_up", "pr_lifecycle"]).optional(),
|
|
72
78
|
previousTitles: z.array(z.string()).optional(),
|
|
@@ -84,6 +90,15 @@ export const obligationSchema = z.object({
|
|
|
84
90
|
* Invariant a-question-always-asks-the-developer-something.
|
|
85
91
|
*/
|
|
86
92
|
export const blockedOnDeveloper = (o: { status: string; ask?: string }): boolean => o.status === "blocked" && !!o.ask?.trim();
|
|
93
|
+
/**
|
|
94
|
+
* Still the developer's move: blocked on them, and not on a question they already answered or dismissed
|
|
95
|
+
* (one-decision-one-card: the agent has that answer and moves the task).
|
|
96
|
+
*/
|
|
97
|
+
export const waitsOnDeveloper = (o: { status: string; ask?: string; coveredBy?: string }, questions: readonly { id: string; answer: unknown; closed: unknown }[]): boolean => {
|
|
98
|
+
if (!blockedOnDeveloper(o)) return false;
|
|
99
|
+
const cover = o.coveredBy ? questions.find(q => q.id === o.coveredBy) : undefined;
|
|
100
|
+
return !cover || (!cover.answer && !cover.closed);
|
|
101
|
+
};
|
|
87
102
|
export const taskSchema = z.object({
|
|
88
103
|
key: idSchema, kind: z.enum(["conflict", "review", "checks", "restack", "obligation", "inventory", "completion"]),
|
|
89
104
|
target: idSchema, title: z.string(), fingerprint: z.string(),
|
|
@@ -253,7 +268,7 @@ export function completionGate(w: ListWorkspace, now = Date.now()): CompletionGa
|
|
|
253
268
|
if (pr.snapshot.state === "CLOSED") add("agent", `Settle ${ref} with a disposition`);
|
|
254
269
|
else add("developer", `Settle ${ref}`);
|
|
255
270
|
}
|
|
256
|
-
for (const o of followUpObligations(w).filter(o => !["done", "waived"].includes(o.status))) add(
|
|
271
|
+
for (const o of followUpObligations(w).filter(o => !["done", "waived"].includes(o.status))) add(waitsOnDeveloper(o, w.questions ?? []) ? "developer" : "agent", o.title);
|
|
257
272
|
for (const o of followUpObligations(w).filter(o => o.status === "done" && o.communication && !replyRecorded(o.communication))) add("agent", `Record the sent reply for ${o.title}`);
|
|
258
273
|
const open = w.batches.filter(b => !recoveryBatch(b) && !completionCheck(b));
|
|
259
274
|
if (open.some(b => ["sending", "sent"].includes(b.state))) add("agent", "Acknowledge the open follow-up batch");
|
|
@@ -286,7 +301,7 @@ export function summary(w: ListWorkspace, now = Date.now()): { status: Status; l
|
|
|
286
301
|
if (blocked) return { status: "needs-you", label: "Needs you", reason: blocked.result || "Follow-up needs a decision" };
|
|
287
302
|
const question = (w.questions ?? []).find(questionOpen);
|
|
288
303
|
if (question) return { status: "needs-you", label: "Needs you", reason: `${question.id}: ${question.title}` };
|
|
289
|
-
const obligation = obligations.find(
|
|
304
|
+
const obligation = obligations.find(o => waitsOnDeveloper(o, w.questions ?? []));
|
|
290
305
|
if (obligation) return { status: "needs-you", label: "Needs you", reason: obligation.title };
|
|
291
306
|
if (w.completion && completionBlockers(w, now).length === 0) return { status: "done", label: "Done", reason: w.completion.summary };
|
|
292
307
|
if (w.runtimeReason) return { status: "waiting", label: "Waiting", reason: w.runtimeReason };
|
package/shared/poll.ts
CHANGED
|
@@ -59,6 +59,9 @@ export function cadence(s: Snapshot | null | undefined, error: string | null | u
|
|
|
59
59
|
return reasons.length ? "checks" : "idle";
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
/** A watched PR (an agent waits for its checks) is read at least at the running-checks cadence. */
|
|
63
|
+
export const watchedCadence = (c: Cadence, watched: boolean): Cadence => watched && c === "idle" ? "checks" : c;
|
|
64
|
+
|
|
62
65
|
/** A merged PR is final: nothing on it feeds repairs, and its deploy state is probed separately every tick. */
|
|
63
66
|
export const MERGED_POLL_MS = 30 * 60_000;
|
|
64
67
|
/**
|
|
@@ -112,9 +115,13 @@ export function budgetTier(b: Budget | null | undefined, now: number): Tier {
|
|
|
112
115
|
* only checks are running (unless the budget is critical).
|
|
113
116
|
* Settled open PRs: every POLL_IDLE_MS. Merged (and closed): every MERGED_POLL_MS; server/github.ts skips final ones.
|
|
114
117
|
*/
|
|
115
|
-
export function dueForRead(i: { snapshot: Snapshot | null | undefined; error: string | null | undefined; changedAt: number | null; readAt: number; now: number; tier: Tier; repoUrgent: boolean; since?: number | null }): boolean {
|
|
118
|
+
export function dueForRead(i: { snapshot: Snapshot | null | undefined; error: string | null | undefined; changedAt: number | null; readAt: number; now: number; tier: Tier; repoUrgent: boolean; since?: number | null; watchedSince?: number | null }): boolean {
|
|
116
119
|
if (i.tier === "critical" || i.tier === "reserve") return false;
|
|
117
|
-
const
|
|
120
|
+
const open = i.snapshot?.state !== "MERGED" && i.snapshot?.state !== "CLOSED";
|
|
121
|
+
// An agent waits for this PR's checks (shared/check-watch.ts): one read after the wait began, then the running-checks
|
|
122
|
+
// cadence, even when it looks settled. Never past the reserve (above), and a long run still slows to 2 minutes.
|
|
123
|
+
if (i.watchedSince != null && open && i.readAt < i.watchedSince) return true;
|
|
124
|
+
const c = watchedCadence(cadence(i.snapshot, i.error, i.changedAt, i.now), i.watchedSince != null && open);
|
|
118
125
|
if (c === "tick") return true;
|
|
119
126
|
const age = i.now - i.readAt;
|
|
120
127
|
// Half a tick of slack: ticks drift a little, and 29.9 s must not wait for the next tick.
|