paseo-follow-up 2.0.1 → 2.0.2-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.
Files changed (46) hide show
  1. package/CHANGELOG.md +8 -43
  2. package/client/brief.tsx +9 -4
  3. package/client/home.tsx +11 -3
  4. package/client/linked.tsx +1 -1
  5. package/client/live-copies.ts +19 -1
  6. package/client/live.tsx +16 -12
  7. package/client/merge-button.tsx +1 -1
  8. package/client/needs-you.tsx +1 -1
  9. package/client/pill.tsx +13 -9
  10. package/client/questions.tsx +8 -7
  11. package/client/spec.tsx +1 -1
  12. package/client/workspace-data.ts +36 -19
  13. package/package.json +2 -1
  14. package/server/cow.ts +62 -13
  15. package/server/daemon.ts +18 -33
  16. package/server/deployments.ts +55 -20
  17. package/server/directory.ts +29 -10
  18. package/server/feeds.ts +3 -2
  19. package/server/inbox.ts +37 -18
  20. package/server/list-cache.ts +21 -10
  21. package/server/pr-workflow.ts +14 -1
  22. package/shared/activity.ts +1 -1
  23. package/shared/attention.ts +8 -7
  24. package/shared/brief.ts +5 -5
  25. package/shared/contracts.ts +3 -2
  26. package/shared/follow-up.ts +2 -2
  27. package/shared/home.ts +4 -3
  28. package/shared/inbox.ts +11 -2
  29. package/shared/list.ts +86 -0
  30. package/shared/merge-click.ts +1 -1
  31. package/shared/model.ts +8 -7
  32. package/shared/overseer.ts +3 -3
  33. package/shared/poll.ts +1 -1
  34. package/shared/pr-actions.ts +7 -6
  35. package/shared/presentation.ts +6 -5
  36. package/shared/questions.ts +9 -7
  37. package/shared/reviewers.ts +1 -1
  38. package/shared/row-menu.ts +1 -1
  39. package/shared/search.ts +3 -3
  40. package/shared/send-decision.ts +2 -1
  41. package/shared/sending.ts +1 -1
  42. package/shared/status-invariants.ts +1 -1
  43. package/shared/status.ts +1 -1
  44. package/shared/task-rows.ts +4 -2
  45. package/shared/task-status.ts +2 -1
  46. package/shared/task-trigger.ts +1 -1
@@ -1,10 +1,15 @@
1
1
  import type { State, Workspace } from "../shared/model";
2
+ import { listEntry, type ListEntry } from "../shared/list";
2
3
 
3
4
  /**
4
5
  * Diffed answers for follow.list (1.3.0-beta.4). Clients send the revision they hold and get back only the
5
6
  * workspaces that changed since then, plus the ids that left the list, instead of every tracked workspace's full
6
7
  * state on every poll. Work is done once per saved-state change (the store hands out the same object until a
7
8
  * mutation), not once per client or poll.
9
+ *
10
+ * Each workspace goes out in its list form (shared/list.ts, a-list-carries-only-what-lists-draw). The store keeps an
11
+ * unchanged workspace's saved object across mutations (a-mutation-copies-only-what-it-changes), so the list form and
12
+ * its JSON are computed once per changed workspace, not for every workspace on every change.
8
13
  */
9
14
  export class ListCache {
10
15
  private state: State | null = null;
@@ -15,36 +20,42 @@ export class ListCache {
15
20
  private objects = new Map<string, Workspace>();
16
21
  private changedAt = new Map<string, number>();
17
22
  private removedAt = new Map<string, number>();
18
- private current: Workspace[] = [];
23
+ private current: ListEntry[] = [];
24
+ /** Each listed workspace's list form, as last projected from `objects`. */
25
+ private entries = new Map<string, ListEntry>();
19
26
  /** The oldest revision a diff can be computed from; older clients get the full list. */
20
27
  private floor = this.revision;
21
28
  constructor(private select: (state: State) => Workspace[] = state => state.workspaces.filter(w => w.enable_tracking)) {}
22
29
  private update(state: State): void {
23
30
  if (state === this.state) return;
24
31
  this.state = state;
25
- const next = this.select(state);
32
+ const next: ListEntry[] = [];
26
33
  const seen = new Set<string>();
27
34
  let changed = false;
28
35
  const revision = this.revision + 1;
29
- for (const w of next) {
36
+ for (const w of this.select(state)) {
30
37
  seen.add(w.id);
31
38
  // a-list-answer-serializes-only-what-changed: the store keeps an unchanged workspace's frozen object
32
- // (a-mutation-copies-only-what-it-changes), so the same object is the same workspace and isn't serialised again.
33
- // 2026-11-13 (run W, live copy under live load): every state change stringified every tracked workspace (1.4 MB)
34
- // to find the one a turn touched, 23 MB of garbage every 5 minutes.
35
- if (this.objects.get(w.id) === w && Object.isFrozen(w)) continue;
39
+ // (a-mutation-copies-only-what-it-changes), so the same object is the same workspace and isn't projected or
40
+ // serialised again. 2026-11-13 (run W, live copy under live load): every state change stringified every tracked
41
+ // workspace (1.4 MB) to find the one a turn touched, 23 MB of garbage every 5 minutes.
42
+ const held = this.entries.get(w.id);
43
+ if (held && this.objects.get(w.id) === w && Object.isFrozen(w)) { next.push(held); continue; }
36
44
  this.objects.set(w.id, w);
37
- const text = JSON.stringify(w);
45
+ const entry = listEntry(w);
46
+ const text = JSON.stringify(entry);
47
+ this.entries.set(w.id, entry);
48
+ next.push(entry);
38
49
  if (this.json.get(w.id) !== text) { this.json.set(w.id, text); this.changedAt.set(w.id, revision); this.removedAt.delete(w.id); changed = true; }
39
50
  }
40
- for (const id of [...this.json.keys()]) if (!seen.has(id)) { this.json.delete(id); this.objects.delete(id); this.changedAt.delete(id); this.removedAt.set(id, revision); changed = true; }
51
+ for (const id of [...this.json.keys()]) if (!seen.has(id)) { this.json.delete(id); this.objects.delete(id); this.entries.delete(id); this.changedAt.delete(id); this.removedAt.set(id, revision); changed = true; }
41
52
  // Removal records are kept for a while so slow clients still learn about them; past that they resync fully.
42
53
  if (this.removedAt.size > 500) { const cut = [...this.removedAt.values()].sort((a, b) => a - b)[this.removedAt.size - 500]; for (const [id, at] of this.removedAt) if (at < cut) this.removedAt.delete(id); this.floor = cut; }
43
54
  this.current = next;
44
55
  if (changed) this.revision = revision;
45
56
  }
46
57
  /** Everything when `since` is absent, unknown or too old; otherwise only what changed after it. */
47
- answer(state: State, since?: number): { revision: number; full: boolean; workspaces: Workspace[]; removed: string[] } {
58
+ answer(state: State, since?: number): { revision: number; full: boolean; workspaces: ListEntry[]; removed: string[] } {
48
59
  this.update(state);
49
60
  if (since === undefined || since > this.revision || since < this.floor) return { revision: this.revision, full: true, workspaces: this.current, removed: [] };
50
61
  return {
@@ -55,6 +55,8 @@ export async function hasFixPr(claudeHome = process.env.CLAUDE_CONFIG_DIR ?? joi
55
55
  }
56
56
 
57
57
  type Detected = { at: number; workflow: PrWorkflow; reason: string; path: string | null };
58
+ /** How long one detect pass's checkout map is reused: a pass over every repository takes well under this. */
59
+ export const PATHS_PASS_MS = 30_000;
58
60
  export class PrWorkflowStore {
59
61
  private tail: Promise<unknown> = Promise.resolve();
60
62
  private cached: PrWorkflowConfig | null = null;
@@ -65,6 +67,17 @@ export class PrWorkflowStore {
65
67
  * working directories of tracked workspaces with PRs there (a repository often has no project registered). Set by the server.
66
68
  */
67
69
  paths: () => Promise<Map<string, string[]>> = async () => new Map();
70
+ /**
71
+ * One `paths()` per detect pass: repositories detected together (an observe loop, `warm`) share one map, so the
72
+ * pass reads Paseo's project list once (concurrent-readers-share-one-request). Kept briefly after it settles.
73
+ */
74
+ private pathsRead: { at: number; value: Promise<Map<string, string[]>> } | null = null;
75
+ private passPaths(): Promise<Map<string, string[]>> {
76
+ if (this.pathsRead && this.now() - this.pathsRead.at < PATHS_PASS_MS) return this.pathsRead.value;
77
+ const value = this.paths(); this.pathsRead = { at: this.now(), value };
78
+ void value.catch(() => { if (this.pathsRead?.value === value) this.pathsRead = null; });
79
+ return value;
80
+ }
68
81
  /** Called after every save, so derived files (scopes.json) can be rewritten. */
69
82
  onChanged: () => void = () => undefined;
70
83
  constructor(readonly directory: string, private probe: Probe = fsProbe(), private now = Date.now, private ttl = 600_000) {}
@@ -127,7 +140,7 @@ export class PrWorkflowStore {
127
140
  const hit = this.detected.get(key);
128
141
  if (!fresh && hit && this.now() - hit.at < this.ttl) return hit;
129
142
  const machine = await this.machineState(freshMachine);
130
- const candidates = [...new Set((await this.paths()).get(key) ?? [])];
143
+ const candidates = [...new Set((await this.passPaths()).get(key) ?? [])];
131
144
  let path = candidates[0] ?? null;
132
145
  const detection: Detection = { gtInstalled: machine.gtInstalled, signedIn: machine.signedIn, path, initialised: false };
133
146
  // File reads only, stopping at the first checkout set up for Graphite.
@@ -1,4 +1,4 @@
1
- import type { Workspace } from "./model";
1
+ import type { ListWorkspace as Workspace } from "./list";
2
2
  import { recoveryBatch } from "./follow-up";
3
3
  import { shortRefs } from "./attention";
4
4
  import { isGithubFlow } from "./pr-actions";
@@ -1,5 +1,6 @@
1
1
  import { batchView, FINISH_LINE, perSnapshot, stuckLine, unconfirmedRefs } from "./status";
2
- import { blockedOnDeveloper, completionCheck, liveWorkingTask, statusKnown, summary, type Batch, type Pr, type Task, type Workspace, type Status } from "./model";
2
+ import { blockedOnDeveloper, completionCheck, liveWorkingTask, statusKnown, summary, type Task, type Status } from "./model";
3
+ import type { ListBatch as Batch, ListPr as Pr, ListWorkspace as Workspace } from "./list";
3
4
  import { IDLE_REASON, NO_PROGRESS_CAP } from "./send-decision";
4
5
  import { workingLine } from "./task-status";
5
6
  import { followUpObligations, recoveryBatch } from "./follow-up";
@@ -17,8 +18,8 @@ export function prTone(pr: Pr): PrTone {
17
18
  if (!s?.complete) return "unknown";
18
19
  if (s.state === "MERGED") return "merged";
19
20
  if (s.state === "CLOSED") return "closed";
20
- if (s.conflict || s.failedChecks.length) return "danger";
21
- if (s.threads.length || s.reviewDecision === "CHANGES_REQUESTED" || s.otherFailedChecks?.length) return "warning";
21
+ if (s.conflict || s.failedChecks?.length) return "danger";
22
+ if (s.threads?.length || s.reviewDecision === "CHANGES_REQUESTED" || s.otherFailedChecks?.length) return "warning";
22
23
  if (s.draft) return "draft";
23
24
  return s.reviewDecision === "APPROVED" ? "approved" : "pending";
24
25
  }
@@ -26,7 +27,7 @@ export function prTone(pr: Pr): PrTone {
26
27
  /** PRs that still need repairs from the agent: conflicts, required checks or review feedback. */
27
28
  export function needsRepair(pr: Pr): boolean {
28
29
  const s = pr.snapshot;
29
- return !pr.error && !!s?.complete && s.state === "OPEN" && !s.draft && (s.conflict || s.failedChecks.length > 0 || s.threads.length > 0 || s.reviewDecision === "CHANGES_REQUESTED");
30
+ return !pr.error && !!s?.complete && s.state === "OPEN" && !s.draft && (s.conflict || !!s.failedChecks?.length || !!s.threads?.length || s.reviewDecision === "CHANGES_REQUESTED");
30
31
  }
31
32
 
32
33
  /**
@@ -84,7 +85,7 @@ export function mergeReady(pr: Pr, w: Pick<Workspace, "prActions">, now = Date.n
84
85
  const recentlySubmitted = w.prActions.some(a => a.kind === "merge" && a.state === "submitted" && a.heads[pr.key] === s?.head && now - Date.parse(a.createdAt) < 30_000);
85
86
  // GitHub mode: the same verdict Needs you and the merge plan use, so the sheet never offers Merge on a draft, conflict or red check.
86
87
  if (isGithubFlow(s)) return mergeBlockers(pr).length === 0 && !recentlySubmitted;
87
- return !pr.error && !!s?.complete && s.state === "OPEN" && s.reviewDecision === "APPROVED" && !s.draft && !s.conflict && !s.failedChecks.length && !s.checksPending && !queued && !recentlySubmitted;
88
+ return !pr.error && !!s?.complete && s.state === "OPEN" && s.reviewDecision === "APPROVED" && !s.draft && !s.conflict && !s.failedChecks?.length && !s.checksPending && !queued && !recentlySubmitted;
88
89
  }
89
90
  export const mergeQueued = (pr: Pr) => isGithubFlow(pr.snapshot) ? !!pr.snapshot?.inMergeQueue : QUEUED.includes(pr.snapshot?.graphiteMergeStatus ?? "");
90
91
  /** Whether the workflow that ships this PR says it can merge now: Graphite's readiness, or GitHub's own verdict. */
@@ -242,10 +243,10 @@ function holdReason(p: Pr): string {
242
243
  const s = p.snapshot;
243
244
  if (!s?.complete || p.error) return "status unknown";
244
245
  if (s.conflict) return "conflicts";
245
- if (s.failedChecks.length) return "checks failing";
246
+ if (s.failedChecks?.length) return "checks failing";
246
247
  if (s.checksPending) return "checks running";
247
248
  if (s.draft) return "a draft";
248
- if (s.threads.length) return "open threads";
249
+ if (s.threads?.length) return "open threads";
249
250
  if (s.reviewDecision !== "APPROVED") return "not approved yet";
250
251
  return isGithubFlow(s) ? "GitHub can't merge it yet" : "Graphite can't merge it yet";
251
252
  }
package/shared/brief.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { prLink } from "./presentation";
2
2
  import { z } from "zod";
3
- import type { Pr, Workspace } from "./model";
3
+ import type { ListPr as Pr, ListWorkspace as Workspace } from "./list";
4
4
  import { agentMergesKey } from "./pr-workflow";
5
5
  import { reviewersAsk } from "./reviewers";
6
6
  import { ANSWER_PREFIX, OTHER_LABEL, answerLabel, answerTitle, isOther, type Question } from "./questions";
@@ -348,15 +348,15 @@ export function prStates(w: Pick<Workspace, "prs"> | null | undefined): PrState[
348
348
  function prFactsOf(pr: Pr, event: string | null): PrState {
349
349
  const s = pr.snapshot!;
350
350
  const facts: BriefFact[] = [];
351
- if (s.failedChecks.length) facts.push({ icon: "CircleX", label: `Checks failed · ${s.failedChecks.slice(0, 2).join(", ")}`, tone: "bad" });
351
+ if (s.failedChecks?.length) facts.push({ icon: "CircleX", label: `Checks failed · ${s.failedChecks.slice(0, 2).join(", ")}`, tone: "bad" });
352
352
  else if (s.checksPending) facts.push({ icon: "Clock", label: "Checks running", tone: "muted" });
353
353
  else facts.push({ icon: "CircleCheck", label: "Required checks pass", tone: "ok" });
354
354
  const approved = s.reviewDecision === "APPROVED";
355
355
  facts.push(s.conflict ? { icon: "TriangleAlert", label: "Conflicts with its base", tone: "warn" }
356
- : s.threads.length ? { icon: "MessageSquare", label: `${s.threads.length} open thread${s.threads.length === 1 ? "" : "s"}`, tone: "warn" }
356
+ : s.threads?.length ? { icon: "MessageSquare", label: `${s.threads?.length} open thread${s.threads?.length === 1 ? "" : "s"}`, tone: "warn" }
357
357
  : { icon: approved ? "UserCheck" : "User", label: approved ? "Approved · no conflicts" : "Review required", tone: approved ? "ok" : "muted" });
358
358
  if (s.draft) facts.push({ icon: "FilePen", label: "Draft", tone: "muted" });
359
- const mergeable = !s.draft && !s.conflict && !s.failedChecks.length && !s.checksPending && approved && !s.threads.length;
359
+ const mergeable = !s.draft && !s.conflict && !s.failedChecks?.length && !s.checksPending && approved && !s.threads?.length;
360
360
  return { key: pr.key, number: pr.number, url: prLink(pr).url, title: s.title, facts, mergeable, event };
361
361
  }
362
362
 
@@ -557,7 +557,7 @@ export const undeliveredReason = (error: string | null | undefined): string => {
557
557
  * - every question it points at is answered: answered, even if the stored brief hasn't caught up.
558
558
  * Decisions backed by a stored question show that question's live, full text and its recorded answer.
559
559
  */
560
- export function shownBrief(row: Brief, live: { brief: Brief | null } | undefined, questions: readonly Question[] = []): { brief: Brief; actionable: boolean } {
560
+ export function shownBrief(row: Brief, live: { brief: Brief | null } | undefined, questions: readonly Pick<Question, "id" | "question" | "options" | "answer">[] = []): { brief: Brief; actionable: boolean } {
561
561
  const mine = live?.brief?.id === row.id ? live.brief! : row;
562
562
  const byId = new Map(questions.map(q => [q.id, q]));
563
563
  const decisions = mine.decisions.map(d => {
@@ -13,6 +13,7 @@ import { z } from "zod";
13
13
  import { inboxRowSchema } from "./inbox";
14
14
  import { briefSchema } from "./brief";
15
15
  import { idSchema, textSchema, workspaceSchema } from "./model";
16
+ import { listEntrySchema } from "./list";
16
17
  import { communicationSchema } from "./communication";
17
18
  import { taskTriggerSchema } from "./task-trigger";
18
19
  import { QUESTION_MODES, questionSchema } from "./questions";
@@ -32,7 +33,7 @@ const agentCommunicationSchema = z.strictObject({
32
33
  * Tracked workspaces. 1.3.0-beta.4: pass the `revision` you hold as `since` to get only what changed (`full` false,
33
34
  * plus `removed` ids). Without it, or when it's too old, the answer is the full list.
34
35
  */
35
- export const listRpc = defineRpc({ name: "follow.list", input: z.object({ since: z.number().optional() }), output: z.object({ workspaces: z.array(workspaceSchema), error: z.string().nullable(), revision: z.number().optional(), full: z.boolean().optional(), removed: z.array(z.string()).optional() }) });
36
+ export const listRpc = defineRpc({ name: "follow.list", input: z.object({ since: z.number().optional() }), output: z.object({ workspaces: z.array(listEntrySchema), error: z.string().nullable(), revision: z.number().optional(), full: z.boolean().optional(), removed: z.array(z.string()).optional() }) });
36
37
  export const getRpc = defineRpc({ name: "follow.get", input: z.object({ workspaceId: idSchema }), output: z.object({ workspace: workspaceSchema.nullable(), error: z.string().nullable() }) });
37
38
  /** `prWorkflow` (1.4.0-beta.14): how this workspace ships PRs (graphite | github) and its review-fix command (null: built-in steps). */
38
39
  export const agentStatusRpc = defineRpc({ name: "follow.agent-status", input: z.strictObject({ agentId: idSchema, detail: z.enum(["summary", "full"]).optional() }), output: workspaceSchema.extend({ prWorkflow: z.object({ mode: z.enum(["graphite", "github"]), reviewFix: z.string().nullable() }).optional(), /** The next message: recipient, tasks, exact text, and when and why it goes (Preview's agent form). */ nextMessageInfo: z.object({ to: z.string(), tasks: z.array(z.string()), text: z.string(), reason: z.string(), eta: z.string().nullable() }).nullable().optional(),
@@ -281,7 +282,7 @@ export const createdItemsRpc = defineRpc({ name: "follow.created-items",
281
282
  */
282
283
  const subscription = <I extends z.ZodType, E extends z.ZodType>(name: string, input: I, event: E): PluginSubscriptionContract<I, E> => ({ name, input, event });
283
284
  export const workspacesFeed = subscription("follow.workspaces-feed", z.object({ since: z.number().optional() }),
284
- z.object({ revision: z.number(), full: z.boolean(), workspaces: z.array(workspaceSchema), removed: z.array(z.string()), error: z.string().nullable() }));
285
+ z.object({ revision: z.number(), full: z.boolean(), workspaces: z.array(listEntrySchema), removed: z.array(z.string()), error: z.string().nullable() }));
285
286
  export const inboxFeed = subscription("follow.inbox-feed", z.object({}), inboxListRpc.output);
286
287
  /** Home's extras: priorities, the ranker, the Overseer and the usage meters (without the worker's live resources). */
287
288
  export const homeFeed = subscription("follow.home-feed", z.object({}), z.object({
@@ -1,4 +1,4 @@
1
- import type { Obligation, Pr, Workspace, Batch } from "./model";
1
+ import type { ListObligation as Obligation, ListPr as Pr, ListWorkspace as Workspace, ListBatch as Batch } from "./list";
2
2
 
3
3
  export const recoveryBatch = (batch: Pick<Batch, "tasks">): boolean => batch.tasks.length > 0 && batch.tasks.every(t => t.kind === "inventory");
4
4
 
@@ -7,7 +7,7 @@ export function lifecycleOnly(o: Pick<Obligation, "title" | "afterPrs" | "catego
7
7
  if (!o.afterPrs.length || /\b(verify|confirm|check|test|run|decide|decision|monitor|resolve|reconcile)\b/i.test(o.title)) return false;
8
8
  return /^(merge|approve|publish|land|deploy)\b/i.test(o.title) || /^#\d+.*\bneeds?\b.*\b(approval|merge)\b/i.test(o.title);
9
9
  }
10
- export const followUpObligations = (w: Workspace): Obligation[] => w.obligations.filter(o => !lifecycleOnly(o));
10
+ export const followUpObligations = <W extends Workspace>(w: W): W["obligations"] => w.obligations.filter(o => !lifecycleOnly(o));
11
11
  /**
12
12
  * Where a merged PR stands against its deploy target.
13
13
  * - deployed: Follow-up saw its merge commit serving. Latched by deploymentAnchor: a probe error or an old
package/shared/home.ts CHANGED
@@ -4,7 +4,8 @@ import { activity, type Activity } from "./activity";
4
4
  import { followUpObligations, recoveryBatch } from "./follow-up";
5
5
  import { sayNew, flagHeadline, HEADLINE_ICON, HEADLINE_TONE, HEADLINE_WORD, workspaceHeadline, withoutBriefQuestions, type Headline, type HeadlineKey, type HeadlineTone } from "./headline";
6
6
  import { rowTitle, sectionOf, type InboxRow } from "./inbox";
7
- import { settled, summary, type Pr, type Workspace } from "./model";
7
+ import { settled, summary } from "./model";
8
+ import type { ListPr as Pr, ListWorkspace as Workspace } from "./list";
8
9
  import { isOpen as questionOpen } from "./questions";
9
10
  import { taskSchedule } from "./task-trigger";
10
11
  import { freshPriorities, priorityRow, type Priority, type PrioritySourceKind } from "./priorities";
@@ -114,10 +115,10 @@ export function prChip(w: Workspace | undefined): PrChip | null {
114
115
  const checks = !s?.complete ? null
115
116
  : s.state === "MERGED" ? { text: "merged", tone: "merged" as const }
116
117
  : s.state === "CLOSED" ? { text: "closed", tone: "muted" as const }
117
- : s.failedChecks.length ? { text: `✗ ${s.failedChecks.length}`, tone: "danger" as const }
118
+ : s.failedChecks?.length ? { text: `✗ ${s.failedChecks?.length}`, tone: "danger" as const }
118
119
  : s.checksPending ? { text: "running", tone: "muted" as const }
119
120
  : s.draft ? { text: "draft", tone: "muted" as const }
120
- : s.threads.length ? { text: plural(s.threads.length, "thread"), tone: "warning" as const }
121
+ : s.threads?.length ? { text: plural(s.threads?.length, "thread"), tone: "warning" as const }
121
122
  : { text: "✓", tone: "success" as const };
122
123
  return { label: `#${pr.number}${more > 0 ? `+${more}` : ""}`, tone: prTone(pr), checks, url: s?.url ?? null };
123
124
  }
package/shared/inbox.ts CHANGED
@@ -67,6 +67,9 @@ export const outboxSchema = z.object({
67
67
  attempts: z.number().int().default(0), state: z.enum(["sending", "failed"]).default("sending"), error: z.string().nullable().default(null),
68
68
  });
69
69
  export type OutboxEntry = z.infer<typeof outboxSchema>;
70
+ /** The newest flagged briefs' origins kept (InboxState.briefOrigins). */
71
+ export const BRIEF_ORIGINS_MAX = 500;
72
+ export const briefOriginSchema = z.object({ at: isoSchema, origin: z.enum(["tool", "structured", "extraction", "fallback"]) });
70
73
  export const inboxStateSchema = z.object({
71
74
  version: z.literal(1),
72
75
  entries: z.record(z.string(), entrySchema).default({}),
@@ -98,9 +101,15 @@ export const inboxStateSchema = z.object({
98
101
  /** One-time repairs applied to this store (additive; `version` stays 1 so older builds still read it). */
99
102
  revision: z.number().int().default(0),
100
103
  /** Where each flagged turn's brief came from, newest last, for the adoption share (R2). Capped. */
101
- briefOrigins: z.array(z.object({ at: isoSchema, origin: z.enum(["tool", "structured", "extraction", "fallback"]) })).default([]),
104
+ /**
105
+ * Where each flagged brief's content came from, newest last, for the brief share (briefShare). Only ever read whole and
106
+ * replaced whole (InboxStore drafts it as cow kind "frozen"), so it is readonly: a reader never changes it in place.
107
+ */
108
+ briefOrigins: z.array(briefOriginSchema).max(BRIEF_ORIGINS_MAX).default([]),
102
109
  });
103
- export type InboxState = z.infer<typeof inboxStateSchema>;
110
+ export type BriefOrigin = z.infer<typeof briefOriginSchema>;
111
+ /** briefOrigins is readonly for every reader (the store deep-freezes it; see its schema). */
112
+ export type InboxState = Omit<z.infer<typeof inboxStateSchema>, "briefOrigins"> & { briefOrigins: readonly BriefOrigin[] };
104
113
  export const emptyInbox = (): InboxState => inboxStateSchema.parse({ version: 1 });
105
114
 
106
115
  export type InboxEvent =
package/shared/list.ts ADDED
@@ -0,0 +1,86 @@
1
+ import { z } from "zod";
2
+ import { batchSchema, deploymentSchema, obligationSchema, prObjectSchema, snapshotSchema, workspaceSchema, type Workspace } from "./model";
3
+ import { isOpen, questionSchema } from "./questions";
4
+
5
+ /**
6
+ * What follow.list and the workspaces feed carry: each followed workspace as the list views draw it (Home, the pill,
7
+ * the sidebar count, header dots, search), never its detail. Invariant a-list-carries-only-what-lists-draw.
8
+ *
9
+ * 2026-11-13 (live 2.0.1-beta.4, 139 followed workspaces): a full follow.list answer was 1.41 MB, and a burst of them
10
+ * stepped the worker's RSS 204 → 236 MB. Most of it was detail only the panel, the PR sheet and agent tools read:
11
+ * deployment evidence, inventory, task evidence, question background, settled batch results, and archived
12
+ * workspaces in full although search only reads their title and PRs. The detail stays one follow.get away
13
+ * (client/workspace-data.ts useWorkspace), and agent tools read the stored workspace on the worker.
14
+ *
15
+ * Each schema below is the stored one minus named fields, so a new stored field reaches the lists by default and
16
+ * the budget test (tests/list-reply-budget.test.ts) says when the list outgrows LIST_REPLY_BUDGET_KB. The types
17
+ * are the enforcement: a list view takes a ListWorkspace, so reading a dropped field there doesn't compile.
18
+ */
19
+ const DEPLOYMENT_DETAIL = { evidence: true, commits: true } as const;
20
+ // repoMerge stays: Home's Merge button reads it to say "Add to merge queue" (shared/merge-click.ts mergeScope).
21
+ const SNAPSHOT_DETAIL = { base: true, trunk: true, headBranch: true } as const;
22
+ const PR_DETAIL = { discoveredFromSubmission: true } as const;
23
+ const OBLIGATION_DETAIL = { evidence: true, previousTitles: true } as const;
24
+ const BATCH_DETAIL = { contextPath: true, recoveryHandoffs: true, acknowledgmentError: true } as const;
25
+ const QUESTION_DETAIL = { background: true, links: true } as const;
26
+ const WORKSPACE_DETAIL = { inventory: true, excludedStacks: true, nextMessage: true } as const;
27
+
28
+ /**
29
+ * What only an open PR's line reads. A merged PR is terminal: its list form keeps identity, title, url, when it merged
30
+ * and its deploy state (stack bars, "N merged below", deploy waits, search), never its checks, threads or reviewers.
31
+ * Optional in the list type, so a list view that reads one must handle a merged PR without it.
32
+ */
33
+ const OPEN_ONLY = { head: true, draft: true, graphiteMergeStatus: true, conflict: true, reviewDecision: true, reviewers: true, mergeWhenReady: true, threads: true, failedChecks: true, otherFailedChecks: true, checksPending: true, checksRunning: true, mergeStateStatus: true, inMergeQueue: true } as const;
34
+ export const listSnapshotSchema = snapshotSchema.omit(SNAPSHOT_DETAIL).partial(OPEN_ONLY).extend({
35
+ deployment: deploymentSchema.omit(DEPLOYMENT_DETAIL).nullable().optional(),
36
+ // Defaulted in the stored schema; a merged PR's list form leaves them out, so parsing mustn't put them back.
37
+ graphiteMergeStatus: z.string().nullable().optional(), mergeWhenReady: z.enum(["on", "off", "unknown"]).optional(),
38
+ });
39
+ export const listPrSchema = prObjectSchema.omit(PR_DETAIL).extend({ snapshot: listSnapshotSchema.nullable() });
40
+ export const listBatchSchema = batchSchema.omit(BATCH_DETAIL).extend({});
41
+ // An open question keeps its background and links: Needs you shows it inline (client/questions.tsx QuestionBody).
42
+ export const listQuestionSchema = questionSchema.omit(QUESTION_DETAIL).extend({ background: questionSchema.shape.background.unwrap().optional(), links: questionSchema.shape.links.unwrap().optional() });
43
+ export const listWorkspaceSchema = workspaceSchema.omit(WORKSPACE_DETAIL).extend({
44
+ // A task's evidence goes out only while it's blocked: the list line reads "Blocked · waits for Q1" from it (shared/task-status.ts blockedLine).
45
+ prs: z.array(listPrSchema), obligations: z.array(obligationSchema.omit(OBLIGATION_DETAIL).extend({ evidence: obligationSchema.shape.evidence.optional() })), batches: z.array(listBatchSchema),
46
+ questions: z.array(listQuestionSchema).default([]),
47
+ });
48
+ /** An archived workspace, only for search ("Archived" at the bottom of results): its name and its PRs' numbers, titles and stacks. */
49
+ export const archivedListWorkspaceSchema = z.object({
50
+ id: workspaceSchema.shape.id, title: workspaceSchema.shape.title, updatedAt: z.string(), archived: z.literal(true), enable_tracking: z.boolean(),
51
+ prs: z.array(z.object({ key: z.string(), number: z.number(), stack: z.string(), snapshot: z.object({ title: z.string() }).nullable() })),
52
+ });
53
+ export const listEntrySchema = z.union([listWorkspaceSchema, archivedListWorkspaceSchema]);
54
+
55
+ export type ListWorkspace = z.infer<typeof listWorkspaceSchema>;
56
+ export type ArchivedListWorkspace = z.infer<typeof archivedListWorkspaceSchema>;
57
+ export type ListEntry = ListWorkspace | ArchivedListWorkspace;
58
+ export const isArchivedEntry = (w: ListEntry): w is ArchivedListWorkspace => w.archived;
59
+
60
+ const drop = <T extends object, K extends string>(value: T, keys: Readonly<Record<K, true>>): Omit<T, K> => {
61
+ const out = { ...value } as Record<string, unknown>;
62
+ for (const k of Object.keys(keys)) delete out[k];
63
+ return out as Omit<T, K>;
64
+ };
65
+
66
+ /** The list form of one stored workspace. Pure; ListCache keeps one per saved workspace object, so an unchanged workspace isn't projected again. */
67
+ export function listEntry(w: Workspace): ListEntry {
68
+ if (w.archived) return { id: w.id, title: w.title, updatedAt: w.updatedAt, archived: true, enable_tracking: w.enable_tracking,
69
+ prs: w.prs.map(p => ({ key: p.key, number: p.number, stack: p.stack, snapshot: p.snapshot ? { title: p.snapshot.title } : null })) };
70
+ return {
71
+ ...drop(w, WORKSPACE_DETAIL),
72
+ prs: w.prs.map(p => ({ ...drop(p, PR_DETAIL), snapshot: p.snapshot && {
73
+ ...drop(p.snapshot.state === "MERGED" && p.snapshot.complete ? drop(p.snapshot, OPEN_ONLY) : p.snapshot, SNAPSHOT_DETAIL),
74
+ ...(p.snapshot.deployment !== undefined ? { deployment: p.snapshot.deployment && drop(p.snapshot.deployment, DEPLOYMENT_DETAIL) } : {}),
75
+ } })),
76
+ obligations: w.obligations.map(o => o.status === "blocked" ? { ...drop(o, OBLIGATION_DETAIL), evidence: o.evidence } : drop(o, OBLIGATION_DETAIL)),
77
+ batches: w.batches.map(b => drop(b, BATCH_DETAIL)),
78
+ questions: w.questions.map(q => isOpen(q) ? q : drop(q, QUESTION_DETAIL)),
79
+ };
80
+ }
81
+
82
+ export type ListPr = ListWorkspace["prs"][number];
83
+ export type ListSnapshot = NonNullable<ListPr["snapshot"]>;
84
+ export type ListObligation = ListWorkspace["obligations"][number];
85
+ export type ListBatch = ListWorkspace["batches"][number];
86
+ export type ListQuestion = ListWorkspace["questions"][number];
@@ -1,5 +1,5 @@
1
1
  import { downstack, isGithubFlow, type ActionPlan, type MergeStage } from "./pr-actions";
2
- import type { Pr, Workspace } from "./model";
2
+ import type { ListPr as Pr, ListWorkspace as Workspace } from "./list";
3
3
 
4
4
  /**
5
5
  * a-click-on-merge-merges (2026-11-13): Merge on a Needs-you row opened the PR sheet, which ran a read-only check and
package/shared/model.ts CHANGED
@@ -5,6 +5,7 @@ import { communicationSchema, replyRecorded } from "./communication";
5
5
  import { taskTriggerSchema } from "./task-trigger";
6
6
  import { isOpen as questionOpen, questionSchema } from "./questions";
7
7
  import { artifactSchema, specSchema } from "./spec";
8
+ import type { ListPr, ListWorkspace } from "./list";
8
9
 
9
10
  /** Why a main-agent turn ended canceled (shared/status.ts cancelCause). */
10
11
  export const CANCEL_CAUSES = ["stop", "replaced", "compaction", "reload", "closed"] as const;
@@ -41,7 +42,7 @@ export const snapshotSchema = z.object({
41
42
  /** What the repository allows, read with the PR (no extra request): merge methods, auto-merge and a merge queue. */
42
43
  repoMerge: z.object({ methods: z.array(z.enum(["squash", "merge", "rebase"])), preferred: z.enum(["squash", "merge", "rebase"]).nullable(), autoMerge: z.boolean(), mergeQueue: z.boolean() }).optional(),
43
44
  });
44
- const prObjectSchema = z.object({
45
+ export const prObjectSchema = z.object({
45
46
  key: idSchema, repo: z.string().regex(/^[\w.-]+\/[\w.-]+$/), number: z.number().int().positive(),
46
47
  stack: textSchema, parent: idSchema.nullable(), disposition: z.string().nullable(),
47
48
  snapshot: snapshotSchema.nullable(), error: z.string().nullable(),
@@ -186,7 +187,7 @@ export type Batch = z.infer<typeof batchSchema>;
186
187
  export type Workspace = z.infer<typeof workspaceSchema>;
187
188
  export type State = z.infer<typeof stateSchema>;
188
189
 
189
- export function settled(pr: Pr): boolean {
190
+ export function settled(pr: ListPr): boolean {
190
191
  return pr.snapshot?.state === "MERGED" || (pr.snapshot?.state === "CLOSED" && !!pr.disposition);
191
192
  }
192
193
  /**
@@ -202,7 +203,7 @@ export type Blocker = { text: string; owner: BlockerOwner; contrary?: true };
202
203
  export type CompletionGate = { blockers: Blocker[]; unconfirmed: string[] };
203
204
  /** A completion check is the nudge to declare Done; it never blocks Done itself. */
204
205
  export const completionCheck = (b: Pick<Batch, "tasks">): boolean => b.tasks.length > 0 && b.tasks.every(t => t.kind === "completion");
205
- export function completionGate(w: Workspace, now = Date.now()): CompletionGate {
206
+ export function completionGate(w: ListWorkspace, now = Date.now()): CompletionGate {
206
207
  const blockers: Blocker[] = [];
207
208
  const unconfirmed: string[] = [];
208
209
  const add = (owner: BlockerOwner, text: string, contrary?: true) => blockers.push(contrary ? { owner, text, contrary } : { owner, text });
@@ -233,19 +234,19 @@ export function completionGate(w: Workspace, now = Date.now()): CompletionGate {
233
234
  if (w.runtimeReason) add("wait", w.runtimeReason);
234
235
  return { blockers, unconfirmed };
235
236
  }
236
- export function completionBlockers(w: Workspace, now = Date.now()): string[] {
237
+ export function completionBlockers(w: ListWorkspace, now = Date.now()): string[] {
237
238
  return completionGate(w, now).blockers.map(b => b.text);
238
239
  }
239
240
  /** Only new work or contrary evidence takes a Done back; waiting and observation gaps never do. */
240
- export function revokesDone(w: Workspace, now = Date.now()): boolean {
241
+ export function revokesDone(w: ListWorkspace, now = Date.now()): boolean {
241
242
  return completionGate(w, now).blockers.some(b => b.owner !== "wait" || b.contrary);
242
243
  }
243
244
  export type Status = "active" | "handling" | "waiting" | "needs-you" | "done";
244
245
  /** The first working task whose recorded agent is running right now (invariant `a-task-only-says-working-when-its-agent-is`). */
245
- export function liveWorkingTask(w: Workspace): Obligation | undefined {
246
+ export function liveWorkingTask<W extends ListWorkspace>(w: W): W["obligations"][number] | undefined {
246
247
  return followUpObligations(w).find(o => o.status === "working" && !!o.workingAgentId && w.taskAgents?.[o.workingAgentId]?.state === "working");
247
248
  }
248
- export function summary(w: Workspace, now = Date.now()): { status: Status; label: string; reason: string } {
249
+ export function summary(w: ListWorkspace, now = Date.now()): { status: Status; label: string; reason: string } {
249
250
  const obligations = followUpObligations(w);
250
251
  if (w.hold) return { status: "needs-you", label: "Needs you", reason: w.hold };
251
252
  const blocked = w.batches.find(b => !recoveryBatch(b) && ["blocked", "uncertain"].includes(b.state) && !(w.completion && completionCheck(b)));
@@ -3,7 +3,7 @@ import { parseAnswersMessage } from "./questions";
3
3
  import { z } from "zod";
4
4
  import { HOME_GROUPS, buildHome, type HomeGroupId, type PaseoWorkspaceLite, type Workstream } from "./home";
5
5
  import type { InboxRow } from "./inbox";
6
- import type { Workspace } from "./model";
6
+ import type { ListWorkspace as Workspace } from "./list";
7
7
  import type { Priority } from "./priorities";
8
8
 
9
9
  /**
@@ -84,7 +84,7 @@ export const linearKeys = (...texts: (string | null | undefined)[]): string[] =>
84
84
  const prChecks = (p: Workspace["prs"][number]): WorkstreamPr["checks"] => {
85
85
  const s = p.snapshot;
86
86
  if (!s?.complete) return "unknown";
87
- return s.failedChecks.length ? "failed" : s.checksPending ? "pending" : "passed";
87
+ return s.failedChecks?.length ? "failed" : s.checksPending ? "pending" : "passed";
88
88
  };
89
89
 
90
90
  /**
@@ -129,7 +129,7 @@ function resting(r: WorkstreamRow, w: Workspace | undefined, now: number, window
129
129
  }
130
130
 
131
131
  function rowOf(s: Workstream, w: Workspace | undefined, p: PaseoWorkspaceLite | undefined, status: string | null): WorkstreamRow {
132
- const prs = (w?.prs ?? []).map(pr => ({ key: pr.key, number: pr.number, state: pr.snapshot?.state ?? "unknown", checks: prChecks(pr), threads: pr.snapshot?.threads.length ?? 0, url: pr.snapshot?.url ?? null }));
132
+ const prs = (w?.prs ?? []).map(pr => ({ key: pr.key, number: pr.number, state: pr.snapshot?.state ?? "unknown", checks: prChecks(pr), threads: pr.snapshot?.threads?.length ?? 0, url: pr.snapshot?.url ?? null }));
133
133
  const needs = s.group === "needs";
134
134
  return {
135
135
  workspaceId: s.workspaceId!, key: s.key, title: s.title, project: s.project, branch: p?.branch ?? null, group: s.group,
package/shared/poll.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Snapshot } from "./model";
1
+ import type { ListSnapshot as Snapshot } from "./list";
2
2
 
3
3
  /**
4
4
  * PR polling cadence. The engine ticks every TICK_MS. A repository whose PRs are all settled is read at most every
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
- import { idSchema, textSchema, type Pr, type Snapshot, type Workspace } from "./model";
2
+ import { idSchema, textSchema } from "./model";
3
+ import type { ListPr as Pr, ListSnapshot as Snapshot, ListWorkspace as Workspace } from "./list";
3
4
 
4
5
  export const prActionKind = z.enum(["merge", "enable_mwr", "disable_mwr"]);
5
6
  export const actionPrSchema = z.object({ key: idSchema, repo: z.string(), number: z.number(), title: z.string(), head: z.string(), parent: idSchema.nullable(), base: z.string(), trunk: z.string(), blockers: z.array(z.string()) });
@@ -24,8 +25,8 @@ export const mergeStageSchema = z.enum(["merged", "queued", "requested"]);
24
25
  export type MergeStage = z.infer<typeof mergeStageSchema>;
25
26
  export const actionResultSchema = z.object({ state: z.enum(["submitted", "failed", "uncertain"]), result: textSchema, merge: mergeStageSchema.optional() });
26
27
 
27
- export function downstack(prs: Pr[], target: string): Pr[] {
28
- const selected: Pr[] = []; const seen = new Set<string>();
28
+ export function downstack<P extends Pr>(prs: P[], target: string): P[] {
29
+ const selected: P[] = []; const seen = new Set<string>();
29
30
  let key: string | null = target; let repo: string | null = null;
30
31
  while (key) {
31
32
  if (seen.has(key)) throw new Error("This stack has a parent cycle. Reconcile its tracking before merging.");
@@ -59,8 +60,8 @@ export function githubBlocker(s: Snapshot): string | null {
59
60
  if (state === "DIRTY" || state === "DRAFT") return null; // Reported as Merge conflicts / Draft already.
60
61
  if (state === "BEHIND") return "Behind its base branch (update the branch)";
61
62
  if (state === "BLOCKED") {
62
- if (s.threads.length) return `${s.threads.length} unresolved review thread${s.threads.length === 1 ? "" : "s"}`;
63
- if (s.failedChecks.length || s.checksPending || !githubApproved(s)) return null; // Already named.
63
+ if (s.threads?.length) return `${s.threads?.length} unresolved review thread${s.threads?.length === 1 ? "" : "s"}`;
64
+ if (s.failedChecks?.length || s.checksPending || !githubApproved(s)) return null; // Already named.
64
65
  return "A branch protection rule or ruleset";
65
66
  }
66
67
  return "GitHub’s mergeability check";
@@ -74,7 +75,7 @@ export function mergeBlockers(pr: Pr): string[] {
74
75
  if (s.draft) blockers.push("Draft");
75
76
  if (github ? !githubApproved(s) : s.reviewDecision !== "APPROVED") blockers.push(github && s.reviewDecision === "CHANGES_REQUESTED" ? "Changes requested" : "Awaiting approval");
76
77
  if (s.conflict) blockers.push("Merge conflicts");
77
- if (s.failedChecks.length) blockers.push("Required checks failed");
78
+ if (s.failedChecks?.length) blockers.push("Required checks failed");
78
79
  if (s.checksPending) blockers.push("Required checks pending");
79
80
  if (github) { if (s.inMergeQueue) blockers.push("Already in the merge queue"); const g = githubBlocker(s); if (g) blockers.push(g); }
80
81
  else if (!graphiteReady(s.graphiteMergeStatus)) blockers.push(graphiteBlocker(s.graphiteMergeStatus));
@@ -1,4 +1,5 @@
1
- import { settled, statusKnown, type Pr } from "./model";
1
+ import { settled, statusKnown } from "./model";
2
+ import type { ListPr as Pr } from "./list";
2
3
  import { deployed } from "./follow-up";
3
4
 
4
5
  export const graphitePrUrl = (pr: Pick<Pr, "repo" | "number">): string => `https://app.graphite.com/github/pr/${pr.repo}/${pr.number}`;
@@ -36,8 +37,8 @@ export function prPresentation(pr: Pr): { label: string; tone: "merged" | "appro
36
37
  if (s.state === "MERGED") return { label: "Merged", tone: "merged" };
37
38
  if (s.state === "CLOSED") return { label: "Closed", tone: "neutral" };
38
39
  if (s.conflict) return { label: "Conflicts", tone: "warning" };
39
- if (s.threads.length) return { label: `${s.threads.length} review thread${s.threads.length === 1 ? "" : "s"}`, tone: "warning" };
40
- if (s.failedChecks.length) return { label: "Checks failed", tone: "warning" };
40
+ if (s.threads?.length) return { label: `${s.threads?.length} review thread${s.threads?.length === 1 ? "" : "s"}`, tone: "warning" };
41
+ if (s.failedChecks?.length) return { label: "Checks failed", tone: "warning" };
41
42
  if (s.otherFailedChecks?.length) return { label: s.otherFailedChecks.length === 1 ? "Optional check failed" : "Optional checks failed", tone: "warning" };
42
43
  if (s.draft) return { label: "Draft", tone: "neutral" };
43
44
  if (s.checksPending) return { label: "Checks running", tone: "neutral" };
@@ -55,8 +56,8 @@ export function compactPrStatus(pr: Pr): ReturnType<typeof prPresentation> {
55
56
  if (status.label !== "Merged" || !pr.snapshot?.deployment) return { ...status, label: status.label.replace("Status unavailable", "Unknown").replace(/review thread/, "thread").replace("Checks running", "Checking") };
56
57
  return { label: deployed(pr) ? "Deployed" : "Merged", tone: "merged" };
57
58
  }
58
- export function orderedStacks(prs: Pr[]): { name: string; prs: Pr[] }[] {
59
- const groups = new Map<string, Pr[]>();
59
+ export function orderedStacks<P extends Pr>(prs: P[]): { name: string; prs: P[] }[] {
60
+ const groups = new Map<string, P[]>();
60
61
  for (const pr of prs) { const rows = groups.get(pr.stack) ?? []; rows.push(pr); groups.set(pr.stack, rows); }
61
62
  const priority = (rows: Pr[]) => rows.every(settledForDisplay) ? 2 : rows.some(p => prPresentation(p).tone === "warning" || !statusKnown(p) || p.snapshot.state === "CLOSED" && !settled(p)) ? 0 : 1;
62
63
  return [...groups].map(([name, prs]) => ({ name, prs })).sort((a, b) => priority(a.prs) - priority(b.prs));
@@ -91,7 +91,7 @@ export type Question = z.infer<typeof questionSchema>;
91
91
  export type QuestionOption = z.infer<typeof questionOptionSchema>;
92
92
  export type Answer = z.infer<typeof answerSchema>;
93
93
 
94
- export const isOpen = (q: Question) => !q.answer && !q.closed;
94
+ export const isOpen = (q: Pick<Question, "answer" | "closed">) => !q.answer && !q.closed;
95
95
 
96
96
  /** Q1, Q2…: unique for the life of the workspace, never reused after a question closes. */
97
97
  export function nextQuestionId(questions: Pick<Question, "id">[]): string {
@@ -140,7 +140,7 @@ export const answerTitle = (text: string) => text.replace(/\)/g, "").replace(/[(
140
140
  /** The lines Follow-up adds after an answer: the answer and the developer's note run until one of these. */
141
141
  const ANSWER_TRAILER = /^(?:The developer added: |None of your options|You were building |Continue|Answered by .+ for the developer\.$)/;
142
142
  /** The message sent to the asking agent. It starts with ANSWER_PREFIX so chat rows and history scans recognise it. */
143
- export function answerMessage(q: Question, choice: string, words?: string): string {
143
+ export function answerMessage(q: Pick<Question, "id" | "title" | "mode" | "big" | "recommend" | "taskId" | "answer"> & { options: readonly { letter: string; label: string }[] }, choice: string, words?: string): string {
144
144
  const lines = [`${ANSWER_PREFIX} ${q.id} (${answerTitle(q.title)}): ${answerHead(q, choice, words)}`];
145
145
  if (isOther(choice)) lines.push("None of your options: the developer's own answer is in the quotes.");
146
146
  else if (words?.trim()) lines.push(`The developer added: ${words.trim()}`);
@@ -280,8 +280,10 @@ const nearIdentical = (a: QuestionShape, b: QuestionShape) => textSimilarity(a,
280
280
  * open needs_you decisions; another agent's question only when near-identical. Blocked-task questions keep their own
281
281
  * identity (the task and its revision) and never match.
282
282
  */
283
- export function findOpenMatch(questions: readonly Question[], input: QuestionShape, askedBy: string | null): { question: Question; verdict: "same" | "changed" } | null {
284
- let best: { question: Question; verdict: "same" | "changed"; score: number } | null = null;
283
+ /** Matching reads only what list views carry (ListQuestion), so Home's invariant checks run on the list form too. */
284
+ type Matchable = QuestionShape & Pick<Question, "id" | "answer" | "closed" | "taskRevision" | "askedBy" | "via">;
285
+ export function findOpenMatch<Q extends Matchable>(questions: readonly Q[], input: QuestionShape, askedBy: string | null): { question: Q; verdict: "same" | "changed" } | null {
286
+ let best: { question: Q; verdict: "same" | "changed"; score: number } | null = null;
285
287
  for (const q of questions) {
286
288
  if (!isOpen(q) || q.taskRevision !== null) continue;
287
289
  const own = q.askedBy === askedBy || q.via === "needs_you";
@@ -294,9 +296,9 @@ export function findOpenMatch(questions: readonly Question[], input: QuestionSha
294
296
  }
295
297
 
296
298
  /** Open questions that repeat an older open one in the same workspace: [duplicate, original] pairs. The invariant. */
297
- export function duplicateOpenQuestions(questions: readonly Question[]): { duplicate: Question; of: Question }[] {
298
- const out: { duplicate: Question; of: Question }[] = [];
299
- const kept: Question[] = [];
299
+ export function duplicateOpenQuestions<Q extends Matchable>(questions: readonly Q[]): { duplicate: Q; of: Q }[] {
300
+ const out: { duplicate: Q; of: Q }[] = [];
301
+ const kept: Q[] = [];
300
302
  for (const q of questions) {
301
303
  if (!isOpen(q)) continue;
302
304
  const match = q.taskRevision === null ? findOpenMatch(kept, q, q.askedBy) : null;
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import type { Pr } from "./model";
2
+ import type { ListPr as Pr } from "./list";
3
3
 
4
4
  /**
5
5
  * Who "Add reviewers" asks, per repository, set by the developer in Settings → Reviewers or remembered from the