paseo-follow-up 2.3.0 → 2.4.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/brief.tsx +7 -5
- package/client/header.tsx +10 -6
- package/client/stacks.tsx +24 -2
- package/index.client.tsx +1 -1
- package/index.server.ts +10 -3
- package/package.json +1 -1
- package/server/agent-actions.ts +4 -3
- package/server/browser-bridge.ts +20 -2
- package/server/pr-actions.ts +17 -11
- package/server/pr-owner.ts +30 -13
- package/server/ranker.ts +3 -2
- package/shared/activity.ts +2 -2
- package/shared/attention.ts +82 -10
- package/shared/brief.ts +16 -0
- package/shared/contracts.ts +3 -2
- package/shared/errors.ts +34 -0
- package/shared/home.ts +38 -12
- package/shared/pr-actions.ts +61 -3
- package/shared/ranker.ts +3 -2
- package/shared/scale.ts +24 -0
- package/shared/status-invariants.ts +15 -0
package/client/brief.tsx
CHANGED
|
@@ -6,7 +6,8 @@ import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
|
6
6
|
import { openExternalUrl, useRpc, type PluginClientContext, type PluginTimelineItemProps } from "@getpaseo/plugin/client";
|
|
7
7
|
import { deliveryStatus } from "../shared/queue";
|
|
8
8
|
import { Icon, TextInput, copyText, useToast } from "@getpaseo/plugin/client/ui";
|
|
9
|
-
import { BRIEF_KIND, BRIEF_VERSION, askedDecisions, cardPicks, notedCount, pickedCount, briefSchema, collapsedLine, outcomeLabel, extrasFit, hasOriginal, nothingNeededLine, isTight, pastRows, pastTone, selectsFirst, sendBar, shownBrief, pastAsk, liveBrief, newAnswerId, type Brief, type BriefDecision, type BriefMove } from "../shared/brief";
|
|
9
|
+
import { BRIEF_KIND, briefCardAsk, BRIEF_VERSION, askedDecisions, cardPicks, notedCount, pickedCount, briefSchema, collapsedLine, outcomeLabel, extrasFit, hasOriginal, nothingNeededLine, isTight, pastRows, pastTone, selectsFirst, sendBar, shownBrief, pastAsk, liveBrief, newAnswerId, type Brief, type BriefDecision, type BriefMove } from "../shared/brief";
|
|
10
|
+
import { needsYou } from "../shared/attention";
|
|
10
11
|
import { age } from "../shared/inbox";
|
|
11
12
|
import { noReviewReposVersion, onNoReviewRepos } from "../shared/pr-workflow";
|
|
12
13
|
import { briefKey, HEADLINE_WORD } from "../shared/headline";
|
|
@@ -38,6 +39,8 @@ export type BriefDeps = {
|
|
|
38
39
|
openAgent(agentId: string): void;
|
|
39
40
|
/** The workspace's list form (shared/list.ts); the PR sheet reads the full one itself. */
|
|
40
41
|
workspace(id: string): ListWorkspace | undefined;
|
|
42
|
+
/** The agent's Needs-you inbox row, so a card knows whether its brief is an ask (briefAsks). */
|
|
43
|
+
row?(agentId: string): { needs?: unknown } | null;
|
|
41
44
|
/** Opens Follow-up's panel for a workspace whose record this client hasn't loaded yet. */
|
|
42
45
|
openPanel(workspaceId: string): void;
|
|
43
46
|
/** Done's Undo window, so the composer pill says Done (and its Undo cancels the same toast) until it ends. */
|
|
@@ -371,10 +374,9 @@ function BriefCardBody({ item, theme, layout, agentId, deps, embedded = false, s
|
|
|
371
374
|
const unverifiable = live.isError || !agentId;
|
|
372
375
|
const shown = row.state !== "open" ? { brief: row, actionable: false } : unverifiable && checked.brief.state === "open" ? { ...checked, actionable: true } : checked;
|
|
373
376
|
const b = shown.brief;
|
|
374
|
-
//
|
|
375
|
-
//
|
|
376
|
-
const
|
|
377
|
-
const askText = waitingOn.length ? `Waiting on your answer to ${waitingOn.join(", ")}` : b.ask;
|
|
377
|
+
// One predicate decides whether the brief's own words draw (briefCardShown, inside briefCardAsk): beside what Needs you
|
|
378
|
+
// holds, a brief without an ask points at it instead (a-brief-without-an-ask-never-sits-beside-needs-you).
|
|
379
|
+
const askText = briefCardAsk(b, agentId ? deps.row?.(agentId) : null, workspace ? needsYou(workspace, Date.now()) : []);
|
|
378
380
|
// A refusal that means "already answered or replaced" isn't a failure: re-read, and the card shows what happened.
|
|
379
381
|
const reconcile = (e?: unknown) => { if (e !== undefined) notice(mootNote(e), toast); setError(null); void cache.invalidateQueries({ queryKey: liveBriefKey(agentId) }); if (row.workspaceId) void cache.invalidateQueries({ queryKey: workspaceKey(row.workspaceId) }); };
|
|
380
382
|
const now = useNow(60_000);
|
package/client/header.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import { View } from "react-native";
|
|
|
4
4
|
import { Pressable, Text } from "./text";
|
|
5
5
|
import { Icon } from "@getpaseo/plugin/client/ui";
|
|
6
6
|
import type { Workspace } from "../shared/model";
|
|
7
|
-
import { ago, headline, headerLine, stackBar, type LiveIcon } from "../shared/attention";
|
|
7
|
+
import { ago, barMarks, headline, headerLine, stackBar, type LiveIcon } from "../shared/attention";
|
|
8
8
|
import { Button, IconButton, Switch, text, type Theme } from "./kit";
|
|
9
9
|
import { VersionMark } from "./updates";
|
|
10
10
|
import { IconSwap, Spinner } from "./motion";
|
|
@@ -15,21 +15,24 @@ import { SummaryLine } from "./about";
|
|
|
15
15
|
/** PR status older than this means the poll has stopped working; say so instead of looking current. */
|
|
16
16
|
export const STALE_MS = 10 * 60_000;
|
|
17
17
|
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* One mark per PR in stack order, coloured by state; past STACK_BAR_BUDGET PRs, runs or slices of the stack as wide as
|
|
20
|
+
* their share (`barMarks`, stack-bar-reads-at-any-size). The signature of the panel; a mark opens its loudest PR.
|
|
21
|
+
*/
|
|
19
22
|
export function StackBar({ workspace, theme, height = 6, onOpen }: { workspace: Pick<Workspace, "prs">; theme: Theme; height?: number; onOpen?: (key: string) => void }) {
|
|
20
23
|
const bar = stackBar(workspace);
|
|
21
24
|
if (!bar.total) return null;
|
|
22
25
|
return <View accessibilityRole="progressbar" accessibilityLabel={`${bar.merged} of ${bar.total} PRs merged`} accessibilityValue={{ min: 0, max: bar.total, now: bar.merged }}
|
|
23
26
|
style={{ flexDirection: "row", gap: 2, height, borderRadius: height / 2, overflow: onOpen ? "visible" : "hidden" }}>
|
|
24
|
-
{bar.segments.map((s, i) => {
|
|
27
|
+
{barMarks(bar.segments).map((s, i, marks) => {
|
|
25
28
|
const paint = segmentPaint(theme.colors, s.tone);
|
|
26
|
-
const r = height / 2, first = i === 0, last = i ===
|
|
27
|
-
const fill = { flex:
|
|
29
|
+
const r = height / 2, first = i === 0, last = i === marks.length - 1;
|
|
30
|
+
const fill = { flex: s.count, minWidth: 6, justifyContent: "center" as const, alignItems: "center" as const, overflow: "hidden" as const, backgroundColor: paint.fill, borderTopLeftRadius: first ? r : 0, borderBottomLeftRadius: first ? r : 0, borderTopRightRadius: last ? r : 0, borderBottomRightRadius: last ? r : 0 };
|
|
28
31
|
// A short centred dash marks the state without filling the slot, so unmerged work never reads as done.
|
|
29
32
|
const mark = Math.max(2, Math.round(height / 3));
|
|
30
33
|
const line = paint.line ? <View style={{ width: "36%", minWidth: 6, height: mark, borderRadius: mark / 2, backgroundColor: paint.line }} /> : null;
|
|
31
34
|
return onOpen
|
|
32
|
-
? <Pressable key={s.key} accessibilityRole="button" accessibilityLabel={`Open pull request ${s.number}`} hitSlop={{ top: 8, bottom: 8 }} onPress={() => onOpen(s.key)} style={state => [fill, (state as { hovered?: boolean }).hovered ? { opacity: 0.75 } : null]}>{line}</Pressable>
|
|
35
|
+
? <Pressable key={s.key} accessibilityRole="button" accessibilityLabel={s.count === 1 ? `Open pull request ${s.number}` : `${s.count} pull requests, #${s.from} to #${s.to}: open #${s.number}`} hitSlop={{ top: 8, bottom: 8 }} onPress={() => onOpen(s.key)} style={state => [fill, (state as { hovered?: boolean }).hovered ? { opacity: 0.75 } : null]}>{line}</Pressable>
|
|
33
36
|
: <View key={s.key} style={fill}>{line}</View>;
|
|
34
37
|
})}
|
|
35
38
|
</View>;
|
|
@@ -42,6 +45,7 @@ function LiveGlyph({ icon, colors }: { icon: LiveIcon; colors: Colors }) {
|
|
|
42
45
|
case "done": return <Icon name="CircleCheck" size={12} color={colors.statusSuccess} />;
|
|
43
46
|
case "paused": return <Icon name="CirclePause" size={12} color={colors.statusWarning} />;
|
|
44
47
|
case "alert": return <Icon name="TriangleAlert" size={12} color={colors.statusWarning} />;
|
|
48
|
+
case "failing": return <Icon name="CircleX" size={12} color={colors.statusDanger} />;
|
|
45
49
|
case "waiting": return <Icon name="Clock" size={12} color={colors.foregroundMuted} />;
|
|
46
50
|
default: return <Icon name="Circle" size={12} color={colors.foregroundMuted} />;
|
|
47
51
|
}
|
package/client/stacks.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import { Pressable, Text } from "./text";
|
|
|
3
3
|
import { Icon } from "@getpaseo/plugin/client/ui";
|
|
4
4
|
import type { Pr, Workspace } from "../shared/model";
|
|
5
5
|
import { compactPrStatus, githubWaitLine, orderedStacks, settledForDisplay } from "../shared/presentation";
|
|
6
|
-
import { mergeQueued, prTone, stackOrder } from "../shared/attention";
|
|
6
|
+
import { mergeQueued, prTone, quietFold, stackOrder, type StackItem } from "../shared/attention";
|
|
7
7
|
import { reviewersMissing } from "../shared/pr-workflow";
|
|
8
8
|
import { isGithubFlow } from "../shared/pr-actions";
|
|
9
9
|
import { Card, FoldRow, text, type Theme } from "./kit";
|
|
@@ -93,6 +93,8 @@ function StackRows({ name, prs, theme, open, toggle, onOpen, compact, showRepo,
|
|
|
93
93
|
const showDone = settled || open(foldKey);
|
|
94
94
|
const rows = hits ? ordered.filter(p => hits.has(p)) : settled ? ordered : [...active, ...(showDone ? done : [])];
|
|
95
95
|
const fold = !hits && !settled && done.length > 0;
|
|
96
|
+
// A long stack folds its quiet runs (a-long-stack-shows-its-problems); a search shows its hits as they are.
|
|
97
|
+
const items: StackItem<Pr>[] = hits || settled ? rows.map(pr => ({ kind: "pr", pr })) : [...quietFold(active, open), ...(showDone ? done : []).map(pr => ({ kind: "pr" as const, pr }))];
|
|
96
98
|
if (!rows.length) return null;
|
|
97
99
|
const merged = prs.filter(p => p.snapshot?.state === "MERGED").length;
|
|
98
100
|
return <View style={{ borderTopWidth: 1, borderTopColor: c.border }}>
|
|
@@ -100,7 +102,27 @@ function StackRows({ name, prs, theme, open, toggle, onOpen, compact, showRepo,
|
|
|
100
102
|
<Text numberOfLines={1} style={[t.label, { flex: 1, fontSize: 12, lineHeight: 17 }]}>{name}</Text>
|
|
101
103
|
<Text style={[t.small, { fontVariant: ["tabular-nums"] }]}>{settled ? `${prs.length} PR${prs.length === 1 ? "" : "s"}` : `${merged} of ${prs.length} merged`}</Text>
|
|
102
104
|
</View>
|
|
103
|
-
{
|
|
105
|
+
{items.map((item, i) => {
|
|
106
|
+
const first = i === 0, last = i === items.length - 1 && !fold;
|
|
107
|
+
if (item.kind === "pr") return <PrRow key={item.pr.key} pr={item.pr} theme={theme} first={first} last={last} showRepo={showRepo} onOpen={onOpen} compact={compact} wide={wide} hit={hits?.get(item.pr)} />;
|
|
108
|
+
const expanded = open(item.key), n = item.prs.length;
|
|
109
|
+
const range = `#${item.prs[0]!.number} to #${item.prs.at(-1)!.number}`;
|
|
110
|
+
return <Pressable key={item.key} accessibilityRole="button" aria-expanded={expanded} accessibilityState={{ expanded }} accessibilityLabel={`${expanded ? "Hide" : "Show"} ${n} PRs in review, ${range}, in ${name}`} onPress={() => toggle(item.key)}
|
|
111
|
+
style={state => ({ flexDirection: "row", gap: 10, paddingHorizontal: 12, minHeight: compact ? 44 : 32, backgroundColor: state.pressed ? c.surface2 : (state as { hovered?: boolean }).hovered ? c.surface1 : "transparent" })}>
|
|
112
|
+
{/* The node and the words sit on the row's middle (the rail runs through both ends), and the ring and chevron
|
|
113
|
+
take the in-review nodes' muted ink, not the border's, so the fold reads as a row you can open. */}
|
|
114
|
+
<View style={{ width: NODE, alignItems: "center" }}>
|
|
115
|
+
<View style={{ width: 2, flex: 1, minHeight: 4, backgroundColor: first ? "transparent" : c.border }} />
|
|
116
|
+
<View style={{ width: NODE, height: NODE, borderRadius: NODE / 2, alignItems: "center", justifyContent: "center", borderWidth: 1, borderColor: c.foregroundMuted, backgroundColor: c.surface0 }}>
|
|
117
|
+
<Icon name={expanded ? "ChevronUp" : "ChevronsUpDown"} size={12} color={c.foregroundMuted} />
|
|
118
|
+
</View>
|
|
119
|
+
<View style={{ width: 2, flex: 1, minHeight: 4, backgroundColor: last ? "transparent" : c.border }} />
|
|
120
|
+
</View>
|
|
121
|
+
<View style={{ flex: 1, justifyContent: "center", paddingVertical: 4 }}>
|
|
122
|
+
<Text style={[t.meta, { color: c.foreground, fontVariant: ["tabular-nums"] }]}>{expanded ? `Hide ${n} in review` : `+${n} in review`}<Text style={{ color: c.foregroundMuted }}>{` · #${item.prs[0]!.number}–#${item.prs.at(-1)!.number}`}</Text></Text>
|
|
123
|
+
</View>
|
|
124
|
+
</Pressable>;
|
|
125
|
+
})}
|
|
104
126
|
{fold && <Pressable accessibilityRole="button" aria-expanded={showDone} accessibilityState={{ expanded: showDone }} accessibilityLabel={`${showDone ? "Hide" : "Show"} ${done.length} merged PR${done.length === 1 ? "" : "s"} in ${name}`} onPress={() => toggle(foldKey)}
|
|
105
127
|
style={state => ({ flexDirection: "row", gap: 10, paddingHorizontal: 12, minHeight: compact ? 44 : 30, backgroundColor: state.pressed ? c.surface2 : (state as { hovered?: boolean }).hovered ? c.surface1 : "transparent" })}>
|
|
106
128
|
<View style={{ width: NODE, alignItems: "center" }}>
|
package/index.client.tsx
CHANGED
|
@@ -98,7 +98,7 @@ export default function contribute(host: PluginClientContext) {
|
|
|
98
98
|
const briefDeps: BriefDeps = {
|
|
99
99
|
signOff: agentId => void inbox.signOff([agentId]), openNext,
|
|
100
100
|
openAgent: agentId => client.openScreen({ screenId: OVERVIEW, params: { next: String(++nextToken), open: agentId } }),
|
|
101
|
-
workspace: id => store.get(id), openPanel,
|
|
101
|
+
workspace: id => store.get(id), openPanel, row: agentId => inbox.rows().find(r => r.agentId === agentId) ?? null,
|
|
102
102
|
noteDone: (agentId, cancel) => inbox.noteDone(agentId, cancel), endDone: agentId => inbox.endDone(agentId),
|
|
103
103
|
};
|
|
104
104
|
const openItem = (key: string, extra: { question?: string } = {}) => client.openScreen({ screenId: OVERVIEW, params: { item: key, ...(extra.question ? { question: extra.question } : {}) } });
|
package/index.server.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { plainError } from "./shared/errors";
|
|
1
2
|
import { TranscriptTitleLookup, TranscriptTitleStore, trackedTitleTranscripts } from "./server/transcript-titles";
|
|
2
3
|
import { fillLinkedTitles, fillWorkspaceTitles, localTitles, workspaceNeedsTitles, type TitleIndex } from "./shared/local-titles";
|
|
3
4
|
import { stopWorker } from "./server/teardown";
|
|
@@ -162,7 +163,10 @@ export default function contribute(server: PluginServerContext) {
|
|
|
162
163
|
const handle = <I extends ZodType, O extends ZodType>(contract: PluginRpcContract<I, O>, handler: (input: zOutput<I>, context: PluginHandlerContext) => unknown) => {
|
|
163
164
|
// Main-agent work by a successor makes its handover stick (see handBackMainAgent): noted after the call succeeds.
|
|
164
165
|
const run = MAIN_WORK.has(contract.name) ? (async (input: { agentId?: string }, context: PluginHandlerContext) => { const out = await (handler as (i: unknown, c: PluginHandlerContext) => unknown)(input, context); if (input?.agentId) await noteMainWork(input.agentId).catch(() => undefined); return out; }) as typeof handler : handler;
|
|
165
|
-
|
|
166
|
+
// A schema error inside a handler (an internal cap, a stored record that no longer fits) reaches the caller as one
|
|
167
|
+
// plain sentence, its issues logged; never as the validator's JSON (invariant pr-scale-lists-batch-not-throw).
|
|
168
|
+
const plain = async (input: unknown, context: PluginHandlerContext) => { try { return await (run as (i: unknown, c: PluginHandlerContext) => unknown)(input, context); } catch (error) { throw plainError(error); } };
|
|
169
|
+
handlers.set(contract.name, { input: contract.input, run: plain as never }); server.handle(contract, rpcTiming.timed(contract.name, plain) as never);
|
|
166
170
|
};
|
|
167
171
|
// What each subscription feed is made of may have changed (wired to the feeds below, server/feeds.ts). Cheap: a feed
|
|
168
172
|
// with no subscriber does nothing, and an unchanged value pushes nothing.
|
|
@@ -628,10 +632,13 @@ export default function contribute(server: PluginServerContext) {
|
|
|
628
632
|
const state = await store.snapshot();
|
|
629
633
|
if (!browserRepositories(state).includes(repo.toLowerCase())) return { tracked: false, workspaces: [], more: 0 };
|
|
630
634
|
const entries = await Promise.all(prClaims(state, repo, number).map(async workspace => {
|
|
631
|
-
|
|
635
|
+
// A read that fails says nothing about the agent: leave that claim out rather than call its agent closed.
|
|
636
|
+
const read = await paseo.agents.ref(workspace.mainAgentId).refresh().then(r => ({ agent: r?.agent }), () => null);
|
|
637
|
+
if (!read) return null;
|
|
638
|
+
const agent = read.agent;
|
|
632
639
|
return { workspace, agent: agent && !agent.archivedAt && agent.workspaceId === workspace.id ? agent : null };
|
|
633
640
|
}));
|
|
634
|
-
const view = browserWorkspaces(entries);
|
|
641
|
+
const view = browserWorkspaces(entries.filter(e => e !== null));
|
|
635
642
|
return { tracked: true, ...view, workspaces: view.workspaces.map(w => ({ ...w, title: w.title.slice(0, 200), agentStatus: w.agentStatus.slice(0, 40), state: w.state.slice(0, 200) })) };
|
|
636
643
|
});
|
|
637
644
|
handle(rpc.listRpc, async ({ since }) => { if (waiting) return { workspaces: [], full: false, removed: [], error: waiting }; await ready; return { ...listCache.answer(await store.snapshot(), since), error: loadError ?? hookError ?? writeHealth.message() ?? engine.error }; });
|
package/package.json
CHANGED
package/server/agent-actions.ts
CHANGED
|
@@ -26,6 +26,7 @@ import type { RenameStatus } from "../shared/rename";
|
|
|
26
26
|
import { DISPLAY_KEYS, displayPreferences, HOME_DETAIL_DEFAULT, CATCH_UP_RAIL_DEFAULT } from "../shared/display";
|
|
27
27
|
import { DEFAULT_SEARCH_SHORTCUT, SEARCH_SHORTCUTS } from "../shared/search-key";
|
|
28
28
|
import { DEFAULT_SORT, SORT_MODES } from "../shared/sort";
|
|
29
|
+
import { SCALE } from "../shared/scale";
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
32
|
* Agent parity: every action the developer can click in Follow-up has a tool that runs the same server path.
|
|
@@ -155,10 +156,10 @@ const login = reviewerLoginSchema;
|
|
|
155
156
|
const prKey = z.string().trim().regex(/^[\w.-]+\/[\w.-]+#\d+$/, "Use owner/repo#number keys from list_prs.");
|
|
156
157
|
const id = z.string().trim().min(1).max(200);
|
|
157
158
|
const confirm = { planId: id.optional(), confirm: z.boolean().optional() };
|
|
158
|
-
const agentIds = z.array(id).min(1).max(
|
|
159
|
+
const agentIds = z.array(id).min(1).max(SCALE.agents);
|
|
159
160
|
export const TOOL_INPUT = {
|
|
160
161
|
list_prs: z.strictObject({ workspace: id.optional(), needs_reviewers: z.boolean().optional(), ready_to_merge: z.boolean().optional(), include_closed: z.boolean().optional() }),
|
|
161
|
-
add_reviewers: z.strictObject({ prs: z.array(prKey).min(1).max(
|
|
162
|
+
add_reviewers: z.strictObject({ prs: z.array(prKey).min(1).max(SCALE.perWorkspace).optional(), reviewers: z.array(login).min(1).max(15).optional(), ...confirm }),
|
|
162
163
|
merge: z.strictObject({ pr: prKey.optional(), scope: z.enum(["target", "downstack"]).optional(), ...confirm }),
|
|
163
164
|
enable_merge_when_ready: z.strictObject({ pr: prKey.optional(), scope: z.enum(["target", "downstack"]).optional(), ...confirm }),
|
|
164
165
|
disable_merge_when_ready: z.strictObject({ pr: prKey.optional(), scope: z.enum(["target", "downstack"]).optional(), ...confirm }),
|
|
@@ -175,7 +176,7 @@ export const TOOL_INPUT = {
|
|
|
175
176
|
ai_rename: z.strictObject({ workspaceId: id.optional(), title: z.string().trim().min(1).max(300).optional(), undo: z.boolean().optional(), ...confirm }),
|
|
176
177
|
snooze_workspace: z.strictObject({ workspace: id.optional(), until: z.string().trim().min(1).max(200).optional(), bring_back: z.boolean().optional(), ...confirm }),
|
|
177
178
|
set_finish_flags: z.strictObject({ agentIds: agentIds.optional(), value: z.boolean().optional(), ...confirm }),
|
|
178
|
-
set_priorities: z.strictObject({ priorities: z.array(priorityInputSchema).max(
|
|
179
|
+
set_priorities: z.strictObject({ priorities: z.array(priorityInputSchema).max(SCALE.workspaces).optional(), replace: z.boolean().optional(), ...confirm }),
|
|
179
180
|
display_settings: z.strictObject({}),
|
|
180
181
|
make_main_agent: z.strictObject({ agentId: id.optional(), reason: z.string().trim().min(1).max(200).optional(), requested: z.enum(["developer", "self"]).optional(), ...confirm }),
|
|
181
182
|
set_display: z.strictObject({ values: z.record(z.string(), z.union([z.boolean(), z.string(), z.number()])).optional(), ...confirm }),
|
package/server/browser-bridge.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { browserCommandSchema, type BrowserCommand, type BrowserPr, type BrowserResult } from "../shared/pr-actions";
|
|
2
|
+
import { browserBatches, browserCommandSchema, type BrowserCommand, type BrowserPr, type BrowserResult } from "../shared/pr-actions";
|
|
3
3
|
|
|
4
4
|
type Pending = { command: BrowserCommand; clientId: string | null; timer: ReturnType<typeof setTimeout>; resolve: (r: BrowserResult) => void };
|
|
5
5
|
export class BrowserBridge {
|
|
@@ -41,7 +41,25 @@ export class BrowserBridge {
|
|
|
41
41
|
for (const job of jobs) job.clientId = clientId;
|
|
42
42
|
return { jobs: jobs.map(j => j.command), accepted };
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Any number of PRs: a stack longer than BROWSER_BATCH goes as consecutive commands, one at a time, and the results
|
|
46
|
+
* merge into one (invariant pr-scale-lists-batch-not-throw). It stops at the first batch that doesn't complete; a
|
|
47
|
+
* write that already changed earlier batches then reads as uncertain, so the caller checks state before retrying.
|
|
48
|
+
*/
|
|
49
|
+
async request(op: BrowserCommand["op"], repo: string, prs: BrowserCommand["prs"]): Promise<BrowserResult> {
|
|
50
|
+
if (!prs.length) throw new Error("No PRs to send to Graphite.");
|
|
51
|
+
const merged: BrowserResult[] = [];
|
|
52
|
+
for (const batch of browserBatches(prs)) {
|
|
53
|
+
const r = await this.requestOne(op, repo, batch); merged.push(r);
|
|
54
|
+
if (r.outcome !== "completed") break;
|
|
55
|
+
}
|
|
56
|
+
const last = merged.at(-1)!;
|
|
57
|
+
if (merged.length === 1) return last;
|
|
58
|
+
const applied = merged.flatMap(r => r.applied);
|
|
59
|
+
const outcome = last.outcome === "failed" && op !== "read" && applied.length ? "uncertain" : last.outcome;
|
|
60
|
+
return { id: last.id, nonce: last.nonce, outcome, prs: merged.flatMap(r => r.prs), applied, error: last.error };
|
|
61
|
+
}
|
|
62
|
+
private requestOne(op: BrowserCommand["op"], repo: string, prs: BrowserCommand["prs"]): Promise<BrowserResult> {
|
|
45
63
|
if (!this.status(repo).ready) return Promise.reject(new Error(this.status(repo).reason!));
|
|
46
64
|
if (this.pending.size >= 50) return Promise.reject(new Error("Too many browser requests are pending."));
|
|
47
65
|
const budget = op === "read" ? 20_000 : 120_000;
|
package/server/pr-actions.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { STOP_WAIT_MS, settleWithin, type Deadline } from "./teardown";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { downstack, isGithubFlow, mergeBlockers, prActionBlocks, type ActionPlan, type BrowserPr, type MergeStage, type PrActionKind } from "../shared/pr-actions";
|
|
3
|
+
import { downstack, isGithubFlow, prRefs, mergeBlockers, prActionBlocks, type ActionPlan, type BrowserPr, type MergeStage, type PrActionKind } from "../shared/pr-actions";
|
|
4
4
|
import type { MergeMethod } from "../shared/pr-workflow";
|
|
5
5
|
import type { Workspace, Pr } from "../shared/model";
|
|
6
6
|
import { findWorkspace } from "./engine";
|
|
@@ -10,6 +10,7 @@ import { GraphiteWriteError, type Graphite } from "./graphite";
|
|
|
10
10
|
import { BrowserBridge } from "./browser-bridge";
|
|
11
11
|
import { allAssigned, configuredReviewers, noReviewers, reviewerLabel, sameLogin, withoutAuthor, type ReviewerEntry } from "../shared/reviewers";
|
|
12
12
|
import { chooseMethod, GithubWriteError, ReviewRequestError } from "./github";
|
|
13
|
+
import { errorText, plainError } from "../shared/errors";
|
|
13
14
|
|
|
14
15
|
function active(w: Workspace) {
|
|
15
16
|
if (!w.enable_tracking || w.archived) throw new Error("This workspace is not actively tracked.");
|
|
@@ -72,7 +73,7 @@ export class PrActions {
|
|
|
72
73
|
const readKey = `${w.id}:${identity(rows)}`;
|
|
73
74
|
if (!this.reads.has(readKey)) this.reads.set(readKey, this.read(rows).finally(() => this.reads.delete(readKey)));
|
|
74
75
|
try { return { browser, pr: (await this.reads.get(readKey)!).find(row => row.number === p.number) ?? null, error: null }; }
|
|
75
|
-
catch (error) { return { browser: this.browser.status(), pr: null, error: error instanceof Error ? error
|
|
76
|
+
catch (error) { return { browser: this.browser.status(), pr: null, error: error instanceof Error ? errorText(plainError(error)) : "Could not read Graphite state." }; }
|
|
76
77
|
}
|
|
77
78
|
async prepare(workspaceId: string, key: string, kind: PrActionKind): Promise<ActionPlan> {
|
|
78
79
|
const w = await this.fresh(workspaceId);
|
|
@@ -201,13 +202,15 @@ export class PrActions {
|
|
|
201
202
|
} else {
|
|
202
203
|
const reply = await this.browser.request(plan.kind, prs[0].repo, wire(prs));
|
|
203
204
|
state = reply.outcome === "completed" ? "submitted" : reply.outcome;
|
|
204
|
-
const changed = reply.applied
|
|
205
|
+
const changed = prRefs(reply.applied);
|
|
205
206
|
result = reply.outcome === "completed" ? `Merge when ready ${plan.kind === "enable_mwr" ? "enabled" : "disabled"} for ${changed}.` : `${changed ? `Changed ${changed}. ` : ""}${reply.error || "Graphite could not confirm every selected PR."}`;
|
|
206
207
|
}
|
|
207
208
|
} catch (error) {
|
|
208
209
|
state = (error instanceof GraphiteWriteError || error instanceof GithubWriteError) && error.uncertain ? "uncertain" : "failed";
|
|
209
|
-
result = error instanceof Error ? error
|
|
210
|
+
result = error instanceof Error ? errorText(plainError(error)) : `${via(prs)} action failed.`;
|
|
210
211
|
}
|
|
212
|
+
// The result crosses an RPC as textSchema (2000 chars): a long one ends in an ellipsis, it never fails the reply.
|
|
213
|
+
if (result.length > 2000) result = `${result.slice(0, 1999)}…`;
|
|
211
214
|
await this.store.mutate(s => {
|
|
212
215
|
const current = findWorkspace(s, w.id);
|
|
213
216
|
const action = current.prActions.find(a => a.id === id)!; action.state = state; action.result = result; if (state === "submitted" && merge) action.merge = merge;
|
|
@@ -233,15 +236,18 @@ export class PrActions {
|
|
|
233
236
|
private async githubExecute(kind: PrActionKind, prs: Pr[]): Promise<{ state: "submitted" | "failed" | "uncertain"; result: string; merge?: MergeStage }> {
|
|
234
237
|
const gh = this.github;
|
|
235
238
|
if (!gh.merge || !gh.autoMerge || !gh.retarget) throw new Error("GitHub merging isn't available here.");
|
|
236
|
-
|
|
237
|
-
const
|
|
239
|
+
// What happened so far, as numbers: said with prRefs, so a long stack's result stays one short paragraph.
|
|
240
|
+
const retargeted: number[] = [], merged: number[] = [], toggled: number[] = []; let queued: number | null = null;
|
|
241
|
+
const progress = () => [retargeted.length ? `Retargeted ${prRefs(retargeted)} to ${prs[0].snapshot!.trunk}.` : "", merged.length ? `Merged ${prRefs(merged)}.` : "",
|
|
242
|
+
queued !== null ? `Added #${queued} to the merge queue.` : "", toggled.length ? `Auto-merge ${kind === "enable_mwr" ? "on" : "off"} for ${prRefs(toggled)}.` : ""].filter(Boolean).join(" ");
|
|
243
|
+
const partial = (error: unknown) => { const message = error instanceof Error ? error.message : "GitHub action failed."; const done = progress(); return done ? `${done} Then: ${message}` : message; };
|
|
238
244
|
const method = (p: Pr) => chooseMethod(p.snapshot!.repoMerge, this.savedMethod(p.repo));
|
|
239
245
|
try {
|
|
240
246
|
if (kind === "merge") {
|
|
241
247
|
const queue = !!prs[0].snapshot!.repoMerge?.mergeQueue;
|
|
242
248
|
for (const [i, p] of prs.entries()) {
|
|
243
249
|
const s = p.snapshot!;
|
|
244
|
-
if (i > 0 && s.base !== s.trunk) { await gh.retarget(p, s.trunk);
|
|
250
|
+
if (i > 0 && s.base !== s.trunk) { await gh.retarget(p, s.trunk); retargeted.push(p.number); }
|
|
245
251
|
for (let attempt = 0; ; attempt++) {
|
|
246
252
|
try { await gh.merge(p, { method: method(p), head: s.head, mergeQueue: queue }); break; }
|
|
247
253
|
catch (error) {
|
|
@@ -250,16 +256,16 @@ export class PrActions {
|
|
|
250
256
|
await this.settle(3_000);
|
|
251
257
|
}
|
|
252
258
|
}
|
|
253
|
-
|
|
259
|
+
if (queue) queued = p.number; else merged.push(p.number);
|
|
254
260
|
if (queue) break; // The queue merges the rest in order once the first lands; GitHub retargets nothing yet.
|
|
255
261
|
}
|
|
256
|
-
return { state: "submitted", result:
|
|
262
|
+
return { state: "submitted", result: progress(), merge: queue ? "queued" : "merged" };
|
|
257
263
|
}
|
|
258
264
|
for (const p of prs) {
|
|
259
265
|
await gh.autoMerge(p, kind === "enable_mwr" ? { enable: true, method: method(p), head: p.snapshot!.head, mergeQueue: !!p.snapshot!.repoMerge?.mergeQueue } : { enable: false });
|
|
260
|
-
|
|
266
|
+
toggled.push(p.number);
|
|
261
267
|
}
|
|
262
|
-
return { state: "submitted", result:
|
|
268
|
+
return { state: "submitted", result: progress() };
|
|
263
269
|
} catch (error) {
|
|
264
270
|
return { state: error instanceof GithubWriteError && !error.uncertain ? "failed" : "uncertain", result: partial(error) };
|
|
265
271
|
}
|
package/server/pr-owner.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { State, Workspace } from "../shared/model";
|
|
2
|
-
import { buildHome, GROUP_TITLE, HOME_GROUPS, type HomeGroupId } from "../shared/home";
|
|
2
|
+
import { buildHome, GROUP_TITLE, HOME_GROUPS, type BadgeTone, type HomeGroupId, type Workstream } from "../shared/home";
|
|
3
3
|
import { isLive } from "../shared/agent-load";
|
|
4
4
|
|
|
5
5
|
/** Duplicate claims are ambiguous. Never route by recency or by PR title. */
|
|
@@ -20,7 +20,16 @@ export function browserRepositories(state: State): string[] {
|
|
|
20
20
|
|
|
21
21
|
/** The live Paseo facts about a workspace's main agent that the browser view needs. */
|
|
22
22
|
export type BrowserAgent = { status: string; pendingPermissions?: unknown[]; requiresAttention?: boolean; attentionReason?: string | null; backgroundWork?: { count?: unknown } | null };
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* The color of a row's state, so the browser never parses Follow-up's English. It comes from the same tone Home paints
|
|
25
|
+
* the row's first badge (or headline) with: attention (amber), danger (red), success (green), accent (blue: running,
|
|
26
|
+
* sending, finished), muted.
|
|
27
|
+
*/
|
|
28
|
+
export const BROWSER_TONES = ["attention", "danger", "success", "accent", "muted"] as const;
|
|
29
|
+
export type BrowserTone = typeof BROWSER_TONES[number];
|
|
30
|
+
const TONE: Record<BadgeTone | Workstream["tone"], BrowserTone> = { warning: "attention", danger: "danger", success: "success", merged: "success", accent: "accent", running: "accent", muted: "muted" };
|
|
31
|
+
export type BrowserWorkspaceView = { group: HomeGroupId; state: string; tone: BrowserTone };
|
|
32
|
+
export type BrowserWorkspace = { workspaceId: string; agentId: string; title: string; agentStatus: string } & BrowserWorkspaceView;
|
|
24
33
|
export const BROWSER_WORKSPACE_LIMIT = 3;
|
|
25
34
|
|
|
26
35
|
/** Every active tracked workspace that registered this PR. Unlike `prOwner`, several are expected: a stack or a review workspace. */
|
|
@@ -44,25 +53,33 @@ function fixDetail(w: Workspace, fallback: string): string {
|
|
|
44
53
|
* Follow-up's one line for a workspace ("Needs you · Merge ready"), from the same model Home uses, plus the
|
|
45
54
|
* main agent's live Paseo attention, which Home reads from the inbox and the server does not have otherwise.
|
|
46
55
|
*/
|
|
47
|
-
export function browserWorkspaceState(w: Workspace, agent: BrowserAgent, now = Date.now()):
|
|
56
|
+
export function browserWorkspaceState(w: Workspace, agent: BrowserAgent | null, now = Date.now()): BrowserWorkspaceView {
|
|
48
57
|
const row = buildHome({ rows: [], tracked: [w], paseo: [], now }).byKey.get(`ws:${w.id}`);
|
|
49
58
|
const group = row?.group ?? "quiet";
|
|
50
|
-
if (group === "needs") return { group, state: `${GROUP_TITLE.needs} · ${row!.badges[0]?.text ?? row!.word ?? "Action"}
|
|
51
|
-
if (agent
|
|
59
|
+
if (group === "needs") return { group, state: `${GROUP_TITLE.needs} · ${row!.badges[0]?.text ?? row!.word ?? "Action"}`, tone: TONE[row!.badges[0]?.tone ?? row!.tone] };
|
|
60
|
+
if (!agent) {
|
|
61
|
+
// The main agent is closed. Done work has nothing left to do; anything else needs the developer to pick an agent.
|
|
62
|
+
return row?.readyToArchive ? { group, state: "Done · ready to archive", tone: "success" } : { group: "needs", state: `${GROUP_TITLE.needs} · Agent closed`, tone: "attention" };
|
|
63
|
+
}
|
|
64
|
+
if (agent.pendingPermissions?.length || agent.attentionReason === "permission") return { group: "needs", state: `${GROUP_TITLE.needs} · Permission`, tone: TONE.warning };
|
|
52
65
|
// Paseo's attention reason outlives the turn it describes: a running agent's "error" is the last turn's, not now's.
|
|
53
66
|
// 0.16: live background work counts as running too (no "Finished" while a job it started still runs).
|
|
54
67
|
const running = isLive(agent);
|
|
55
|
-
if (agent.status === "error" || agent.attentionReason === "error" && !running) return { group: "needs", state: `${GROUP_TITLE.needs} · Error
|
|
56
|
-
if (group === "sending") return { group, state: `${GROUP_TITLE.sending} · ${fixDetail(w, row!.line)}
|
|
57
|
-
if (group === "running" || running) return { group: "running", state: GROUP_TITLE.running };
|
|
58
|
-
if (agent.requiresAttention) return { group: "needs", state: `${GROUP_TITLE.needs} · Finished
|
|
59
|
-
if (group === "waiting") return { group, state: row!.line ? `${GROUP_TITLE.waiting} · ${row!.line}` : GROUP_TITLE.waiting };
|
|
60
|
-
return { group, state:
|
|
68
|
+
if (agent.status === "error" || agent.attentionReason === "error" && !running) return { group: "needs", state: `${GROUP_TITLE.needs} · Error`, tone: TONE.danger };
|
|
69
|
+
if (group === "sending") return { group, state: `${GROUP_TITLE.sending} · ${fixDetail(w, row!.line)}`, tone: TONE.running };
|
|
70
|
+
if (group === "running" || running) return { group: "running", state: GROUP_TITLE.running, tone: TONE.running };
|
|
71
|
+
if (agent.requiresAttention) return { group: "needs", state: `${GROUP_TITLE.needs} · Finished`, tone: TONE.accent };
|
|
72
|
+
if (group === "waiting") return { group, state: row!.line ? `${GROUP_TITLE.waiting} · ${row!.line}` : GROUP_TITLE.waiting, tone: TONE.muted };
|
|
73
|
+
return row?.readyToArchive ? { group, state: "Done · ready to archive", tone: TONE.success } : { group, state: GROUP_TITLE.quiet, tone: TONE.muted };
|
|
61
74
|
}
|
|
62
75
|
|
|
63
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Most urgent first, then most recently updated. At most three; `more` counts the rest. A claim whose main agent is
|
|
78
|
+
* closed (`agent: null`) stays, as "Needs you · Agent closed" with `agentStatus: "closed"`; the caller leaves out a claim
|
|
79
|
+
* whose agent it couldn't read at all, since an unknown agent is not a closed one.
|
|
80
|
+
*/
|
|
64
81
|
export function browserWorkspaces(entries: { workspace: Workspace; agent: BrowserAgent | null }[], now = Date.now()): { workspaces: BrowserWorkspace[]; more: number } {
|
|
65
|
-
const rows = entries.
|
|
82
|
+
const rows = entries.map(({ workspace: w, agent }) => ({ w, view: { workspaceId: w.id, agentId: w.mainAgentId, title: w.title, agentStatus: !agent ? "closed" : agent.pendingPermissions?.length ? "permission" : agent.status, ...browserWorkspaceState(w, agent, now) } }));
|
|
66
83
|
rows.sort((a, b) => HOME_GROUPS.indexOf(a.view.group) - HOME_GROUPS.indexOf(b.view.group) || b.w.updatedAt.localeCompare(a.w.updatedAt) || a.w.id.localeCompare(b.w.id));
|
|
67
84
|
return { workspaces: rows.slice(0, BROWSER_WORKSPACE_LIMIT).map(r => r.view), more: Math.max(0, rows.length - BROWSER_WORKSPACE_LIMIT) };
|
|
68
85
|
}
|
package/server/ranker.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
} from "../shared/ranker";
|
|
16
16
|
import type { Priority } from "../shared/priorities";
|
|
17
17
|
import type { WorkstreamRow } from "../shared/overseer";
|
|
18
|
+
import { truncated } from "../shared/scale";
|
|
18
19
|
|
|
19
20
|
import { ghAccounts, githubApi, type AccountReads } from "./github-api";
|
|
20
21
|
const exec = promisify(execFile);
|
|
@@ -125,10 +126,10 @@ export function parseReviewRequests(stdout: string): RankReview[] {
|
|
|
125
126
|
export const planReplySchema = z.object({
|
|
126
127
|
title: z.string().trim().max(200).nullable().catch(null).default(null),
|
|
127
128
|
// Items as objects, or plain lines (models sometimes flatten them); anything else is dropped, not fatal.
|
|
128
|
-
items:
|
|
129
|
+
items: truncated(z.union([
|
|
129
130
|
z.object({ level: z.string().trim().min(1).max(30).catch("item"), title: z.string().trim().min(1).max(300), keys: z.array(z.string().trim().max(30)).max(10).catch([]).default([]) }),
|
|
130
131
|
z.string().trim().min(1).max(300).transform(title => ({ level: "item", title, keys: title.match(/\b[A-Z][A-Z0-9]+-\d+\b/g) ?? [] })),
|
|
131
|
-
]).nullable().catch(null)
|
|
132
|
+
]).nullable().catch(null), 120).transform(items => items.filter((i): i is { level: string; title: string; keys: string[] } => !!i).slice(0, 80)),
|
|
132
133
|
});
|
|
133
134
|
export const PLAN_SYSTEM = "You read one Claude artifact with the Artifact tool, action \"read\" only, and summarise its planning content. Never call the Artifact tool with any other action (never publish, update, delete, comment or share). Reply with one JSON object only: {\"title\": string|null, \"items\": [{\"level\": \"initiative|project|milestone|issue\", \"title\": string, \"keys\": [Linear keys like ACME-123]}]}. Focus on this week; at most 60 items. Never include share keys, links or raw HTML.";
|
|
134
135
|
|
package/shared/activity.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ListWorkspace as Workspace } from "./list";
|
|
2
2
|
import { recoveryBatch } from "./follow-up";
|
|
3
3
|
import { shortRefs } from "./attention";
|
|
4
|
-
import { isGithubFlow } from "./pr-actions";
|
|
4
|
+
import { isGithubFlow, prRefs } from "./pr-actions";
|
|
5
5
|
import { answerLabel, answerStatus, closedLine } from "./questions";
|
|
6
6
|
|
|
7
7
|
export type ActivityTone = "merged" | "success" | "warning" | "danger" | "muted";
|
|
@@ -44,7 +44,7 @@ export function activity(w: Workspace): Activity[] {
|
|
|
44
44
|
for (const a of w.prActions) {
|
|
45
45
|
// Say a merge once: when every PR it merged has its own "#N merged" row, the action's "Merged …" row would repeat it.
|
|
46
46
|
if (a.kind === "merge" && a.merge === "merged" && a.prs.every(key => { const s = w.prs.find(p => p.key === key)?.snapshot; return s?.state === "MERGED" && !!s.mergedAt; })) continue;
|
|
47
|
-
const numbers = a.prs.map(key =>
|
|
47
|
+
const numbers = prRefs(a.prs.map(key => key.split("#")[1]));
|
|
48
48
|
const toggle = isGithubFlow(w.prs.find(p => p.key === a.prs[0])?.snapshot) ? "Auto-merge" : "Merge when ready";
|
|
49
49
|
// The same outcome the button and toast said (mergeWords): Merged only when GitHub merged.
|
|
50
50
|
const what = a.kind === "merge" ? a.merge === "merged" ? `Merged ${numbers}` : a.merge === "queued" ? `Queued ${numbers.split(", ")[0]} to merge` : `Merge requested for ${numbers}` : a.kind === "request_reviewers" ? `Reviewers requested on ${numbers}` : a.kind === "enable_mwr" ? `${toggle} on for ${numbers}` : `${toggle} off for ${numbers}`;
|
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"];
|
|
@@ -297,14 +352,18 @@ function computeAllNeeds(w: Workspace, now: number): NeedItem[] {
|
|
|
297
352
|
const blocking = (pr: Pr) => w.prActions.some(a => prActionBlocks(a, [pr.key]));
|
|
298
353
|
// One click merges the PR and its unmerged downstack (a-click-on-merge-merges), so Merge is offered only when every
|
|
299
354
|
// 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
|
-
|
|
355
|
+
// Each PR's own verdict once: every PR's stack check reads the PRs under it, so recomputing made a long stack's
|
|
356
|
+
// check cubic (invariant a-check-costs-linear-in-its-workspace; tests/pr-scale.test.ts).
|
|
357
|
+
const own = new Map<string, boolean>();
|
|
358
|
+
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; };
|
|
359
|
+
const holding = downstackScan(w.prs, canMerge);
|
|
360
|
+
const stackReady = (pr: Pr) => { const by = holding(pr.key); return by === "unreadable" || by === null; };
|
|
302
361
|
for (const pr of stackOrder(w.prs)) {
|
|
303
362
|
// Only offer Merge here when the PR's workflow (Graphite, or GitHub itself) agrees; otherwise the PR sheet explains what is missing.
|
|
304
363
|
// A PR the agent merges itself (its own register_pr answer, else a No review repository) is the agent's work in
|
|
305
364
|
// flight, never the developer's merge or review. Invariant a-no-review-repo-never-asks-for-review-or-merge.
|
|
306
365
|
if (agentMerges(pr)) continue;
|
|
307
|
-
if (
|
|
366
|
+
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
367
|
// One ask per PR (one-reviewers-ask-per-pr): it names whom Follow-up suggests, so Follow-up's own reviewers brief
|
|
309
368
|
// folds into it (shared/needs-block.ts) instead of drawing a second ask for the same PR.
|
|
310
369
|
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,7 +371,14 @@ function computeAllNeeds(w: Workspace, now: number): NeedItem[] {
|
|
|
312
371
|
// 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
372
|
// under it isn't a second ask for the same decision. Merging only a lower one stays in its PR sheet.
|
|
314
373
|
const merges = items.filter((i): i is Extract<NeedItem, { kind: "merge" }> => i.kind === "merge");
|
|
315
|
-
|
|
374
|
+
// Walk each Merge's parents only until a PR another Merge already covers: everything under it is covered too, so
|
|
375
|
+
// the whole pass reads each PR once (a downstack per Merge was quadratic on a long, all-ready stack).
|
|
376
|
+
const covered = new Set<string>();
|
|
377
|
+
const parentOf = merges.length > 1 ? new Map(w.prs.map(p => [p.key, p.parent] as const)) : new Map<string, string | null>();
|
|
378
|
+
if (merges.length > 1) for (const m of merges) {
|
|
379
|
+
if (holding(m.prKey) === "unreadable") continue;
|
|
380
|
+
for (let k = parentOf.get(m.prKey) ?? null; k !== null && !covered.has(k); k = parentOf.get(k) ?? null) covered.add(k);
|
|
381
|
+
}
|
|
316
382
|
return items.filter(i => i.kind !== "merge" || !covered.has(i.prKey));
|
|
317
383
|
}
|
|
318
384
|
|
|
@@ -337,12 +403,14 @@ function holdReason(p: Pr): string {
|
|
|
337
403
|
export function heldMerges(w: Workspace, now = Date.now()): { pr: Pr; by: Pr; line: string }[] {
|
|
338
404
|
if (!w.enable_tracking || w.archived) return [];
|
|
339
405
|
const blocking = (pr: Pr) => w.prActions.some(a => prActionBlocks(a, [pr.key]));
|
|
406
|
+
const own = new Map<string, boolean>();
|
|
407
|
+
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; };
|
|
408
|
+
const holding = downstackScan(w.prs, canMerge);
|
|
340
409
|
const out: { pr: Pr; by: Pr; line: string }[] = [];
|
|
341
410
|
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)})` });
|
|
411
|
+
if (agentMerges(pr) || !canMerge(pr)) continue;
|
|
412
|
+
const by = holding(pr.key);
|
|
413
|
+
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
414
|
}
|
|
347
415
|
return out;
|
|
348
416
|
}
|
|
@@ -370,7 +438,7 @@ export function headline(w: Workspace, now = Date.now()): HeadlinePart[] {
|
|
|
370
438
|
return parts;
|
|
371
439
|
}
|
|
372
440
|
|
|
373
|
-
export type LiveIcon = "spinner" | "sent" | "done" | "paused" | "waiting" | "alert" | "idle";
|
|
441
|
+
export type LiveIcon = "spinner" | "sent" | "done" | "paused" | "waiting" | "alert" | "failing" | "idle";
|
|
374
442
|
/** What is happening right now, in one line, with the time it started when known. */
|
|
375
443
|
/**
|
|
376
444
|
* The panel header's live line. Say it once (Q49): while a message is queued, the Tasks strip right below carries when
|
|
@@ -411,6 +479,10 @@ export function liveLine(w: Workspace, now = Date.now()): { icon: LiveIcon; text
|
|
|
411
479
|
const waiting = followUpObligations(w).find(o => o.status === "waiting");
|
|
412
480
|
if (waiting) return { icon: "waiting", text: waiting.title, since: null };
|
|
413
481
|
if (w.prs.some(p => !statusKnown(p))) return { icon: "alert", text: "Some PR status is unavailable · retrying", since: null };
|
|
482
|
+
// The worst open PR first (a-pr-summary-says-the-worst): failing checks before running ones, never the reverse.
|
|
483
|
+
const failing = w.prs.filter(p => p.snapshot?.state === "OPEN" && p.snapshot.failedChecks?.length);
|
|
484
|
+
// Red, in the rows' words ("Checks failed"): a failed check is a repair, not something waiting on the developer.
|
|
485
|
+
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
486
|
if (w.prs.some(p => p.snapshot?.state === "OPEN" && p.snapshot.checksPending)) return { icon: "waiting", text: "Checks are running", since: null };
|
|
415
487
|
if (w.prs.some(p => p.snapshot?.state === "OPEN")) return { icon: "waiting", text: "Waiting on review and merges", since: null };
|
|
416
488
|
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/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({
|
|
@@ -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() });
|
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
|
@@ -104,23 +104,49 @@ const plural = (n: number, one: string, many = `${one}s`) => `${n} ${n === 1 ? o
|
|
|
104
104
|
/** In flight: the send glyph. Queued to go out on its own: the clock family, never Running's spinner (Q51). */
|
|
105
105
|
const sendingIcon = (s: Sending) => s.state === "sent" ? "Send" : "ClockArrowUp";
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
type ChipChecks = NonNullable<PrChip["checks"]>;
|
|
108
|
+
/** One PR's checks as the chip says them. Null: its status isn't known (unknown is not ✓). */
|
|
109
|
+
function prChecks(s: Pr["snapshot"]): ChipChecks | null {
|
|
110
|
+
return !s?.complete ? null
|
|
111
|
+
: s.state === "MERGED" ? { text: "merged", tone: "merged" }
|
|
112
|
+
: s.state === "CLOSED" ? { text: "closed", tone: "muted" }
|
|
113
|
+
: s.failedChecks?.length ? { text: `✗ ${s.failedChecks.length}`, tone: "danger" }
|
|
114
|
+
: s.checksPending ? { text: "running", tone: "muted" }
|
|
115
|
+
: s.draft ? { text: "draft", tone: "muted" }
|
|
116
|
+
: s.threads?.length ? { text: plural(s.threads.length, "thread"), tone: "warning" }
|
|
117
|
+
: { text: "✓", tone: "success" };
|
|
118
|
+
}
|
|
119
|
+
/** How bad an open PR's checks are, worst first: failing, open threads, unknown, running, draft, clear. */
|
|
120
|
+
function chipRank(s: Pr["snapshot"]): number {
|
|
121
|
+
if (!s?.complete) return 2;
|
|
122
|
+
return s.failedChecks?.length ? 0 : s.threads?.length ? 1 : s.checksPending ? 3 : s.draft ? 4 : 5;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 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,
|
|
126
|
+
* never the first one's. It names the first open PR in stack order with the worst state ("#1058+125"), else the first
|
|
127
|
+
* that hasn't settled, else the last; "+n" counts the rest. Its checks add up across the open PRs at that worst
|
|
128
|
+
* state ("✗ 7": seven failing checks), and an open PR whose status isn't known keeps it from saying ✓. 2026-11-22: a
|
|
129
|
+
* 126-PR workspace with four PRs failing checks read "#1001+125 ✓", the first PR's state.
|
|
130
|
+
*/
|
|
108
131
|
export function prChip(w: Workspace | undefined): PrChip | null {
|
|
109
132
|
if (!w?.prs.length) return null;
|
|
110
133
|
const ordered = stackOrder(w.prs);
|
|
111
134
|
const open = ordered.filter(p => !settled(p));
|
|
112
|
-
const pr: Pr = open[0] ?? ordered.at(-1)!;
|
|
113
135
|
const more = (open.length || ordered.length) - 1;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
:
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
136
|
+
if (open.length <= 1) {
|
|
137
|
+
const pr: Pr = open[0] ?? ordered.at(-1)!;
|
|
138
|
+
return { label: `#${pr.number}${more > 0 ? `+${more}` : ""}`, tone: prTone(pr), checks: prChecks(pr.snapshot), url: pr.snapshot?.url ?? null };
|
|
139
|
+
}
|
|
140
|
+
const ranks = open.map(p => chipRank(p.snapshot));
|
|
141
|
+
const worst = Math.min(...ranks);
|
|
142
|
+
const at = open.filter((_, i) => ranks[i] === worst);
|
|
143
|
+
const pr = worst < 5 ? at[0]! : open[0]!;
|
|
144
|
+
const sum = (f: (s: NonNullable<Pr["snapshot"]>) => number) => at.reduce((n, p) => n + f(p.snapshot!), 0);
|
|
145
|
+
const checks: ChipChecks | null = worst === 0 ? { text: `✗ ${sum(s => s.failedChecks?.length ?? 0)}`, tone: "danger" }
|
|
146
|
+
: worst === 1 ? { text: plural(sum(s => s.threads?.length ?? 0), "thread"), tone: "warning" }
|
|
147
|
+
: worst === 2 ? null
|
|
148
|
+
: prChecks(pr.snapshot);
|
|
149
|
+
return { label: `#${pr.number}${more > 0 ? `+${more}` : ""}`, tone: prTone(pr), checks, url: pr.snapshot?.url ?? null };
|
|
124
150
|
}
|
|
125
151
|
|
|
126
152
|
/** One trailing chip on a desktop row: a semantic badge or the PR chip. */
|
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);
|
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
|
+
}
|
|
@@ -36,6 +36,21 @@ 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.",
|
|
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
|
+
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`;
|
|
51
|
+
return null;
|
|
52
|
+
},
|
|
53
|
+
},
|
|
39
54
|
{
|
|
40
55
|
id: "a-linked-item-uses-every-known-local-title",
|
|
41
56
|
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.",
|