@mrclrchtr/supi-review 2.8.0 → 3.0.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.
Files changed (44) hide show
  1. package/README.md +71 -180
  2. package/node_modules/@mrclrchtr/supi-core/package.json +2 -1
  3. package/node_modules/@mrclrchtr/supi-core/src/api.ts +2 -0
  4. package/node_modules/@mrclrchtr/supi-core/src/evidence-badge.ts +40 -0
  5. package/package.json +3 -3
  6. package/src/config.ts +30 -21
  7. package/src/git-command.ts +78 -0
  8. package/src/git.ts +306 -505
  9. package/src/history/collect.ts +43 -120
  10. package/src/model.ts +3 -1
  11. package/src/review-path.ts +85 -0
  12. package/src/review-result.ts +43 -92
  13. package/src/review.ts +154 -290
  14. package/src/session/review-plan-store.ts +20 -51
  15. package/src/target/packet.ts +46 -369
  16. package/src/tool/agent-review-schemas.ts +101 -104
  17. package/src/tool/agent-review-tools.ts +268 -309
  18. package/src/tool/child-failure-diagnostics.ts +1 -1
  19. package/src/tool/child-resource-loader.ts +37 -0
  20. package/src/tool/child-session-runner.ts +83 -0
  21. package/src/tool/output-page.ts +47 -0
  22. package/src/tool/planner-runner.ts +69 -0
  23. package/src/tool/review-runner.ts +42 -257
  24. package/src/tool/review-system-prompt.ts +12 -110
  25. package/src/tool/review-tools.ts +119 -0
  26. package/src/tool/review-workflow.ts +309 -0
  27. package/src/tool/runner-helpers.ts +3 -8
  28. package/src/tool/schemas.ts +75 -62
  29. package/src/tui/common.ts +175 -0
  30. package/src/tui/prepare.ts +132 -0
  31. package/src/tui/run.ts +160 -0
  32. package/src/types.ts +153 -275
  33. package/src/history/synthesize.ts +0 -121
  34. package/src/tool/agent-review-workflow.ts +0 -398
  35. package/src/tool/brief-runner.ts +0 -180
  36. package/src/tool/guidance.ts +0 -21
  37. package/src/tool/review-handlers.ts +0 -314
  38. package/src/tool/snapshot-tools.ts +0 -117
  39. package/src/ui/flow.ts +0 -189
  40. package/src/ui/format-content.ts +0 -143
  41. package/src/ui/renderer.ts +0 -274
  42. package/src/ui/review-plan-inspector.ts +0 -391
  43. package/src/ui/review-tool-format.ts +0 -138
  44. package/src/ui/review-tool-renderer.ts +0 -234
package/src/review.ts CHANGED
@@ -1,319 +1,183 @@
1
1
  import { buildSessionContext, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import type { WidgetProgress } from "@mrclrchtr/supi-core/progress-widget";
3
- import { runWithProgressWidget } from "@mrclrchtr/supi-core/tool-framework";
4
- import { registerReviewSettings } from "./config.ts";
5
- import { resolveBranchSnapshot, resolveCommitSnapshot, resolveWorkingTreeSnapshot } from "./git.ts";
6
- import { serializeSessionContext } from "./history/collect.ts";
7
- import { synthesizeReviewBrief } from "./history/synthesize.ts";
8
- import { normalizeReviewResult } from "./review-result.ts";
9
- import { buildReviewPacket } from "./target/packet.ts";
10
- import { registerAgentReviewTools } from "./tool/agent-review-tools.ts";
11
- import { createUnobservedChildFailureDiagnostics } from "./tool/child-failure-diagnostics.ts";
12
- import { runReviewer } from "./tool/review-runner.ts";
13
- import type {
14
- BriefSynthesisRunResult,
15
- RawReviewResult,
16
- ReviewPlan,
17
- ReviewResult,
18
- ReviewSnapshot,
19
- ReviewTargetSpec,
20
- } from "./types.ts";
21
- import { collectReviewNote, previewReviewPlan, selectModel, selectTarget } from "./ui/flow.ts";
22
- import {
23
- formatBriefSynthesisFailureContent,
24
- formatBriefSynthesisFailureCopy,
25
- formatReviewContent,
26
- } from "./ui/format-content.ts";
27
- import { registerReviewRenderer } from "./ui/renderer.ts";
2
+ import { Box } from "@earendil-works/pi-tui";
3
+ import { Value } from "typebox/value";
4
+ import { loadReviewConfig, registerReviewSettings } from "./config.ts";
5
+ import { listLocalBranches, listRecentCommits } from "./git.ts";
6
+ import { collectPlannerContext } from "./history/collect.ts";
7
+ import { getSelectableReviewModels, resolveAgentReviewModel } from "./model.ts";
8
+ import { ReviewPlanStore } from "./session/review-plan-store.ts";
9
+ import { formatReviewBatch, registerAgentReviewTools } from "./tool/agent-review-tools.ts";
10
+ import { pageText } from "./tool/output-page.ts";
11
+ import { normalizeReviewInput, prepareReview, runReview } from "./tool/review-workflow.ts";
12
+ import { reviewInputSchema } from "./tool/schemas.ts";
13
+ import { renderRunResult } from "./tui/run.ts";
14
+ import type { ReviewInput, ReviewModelSelection, ReviewTargetSpec } from "./types.ts";
28
15
 
29
16
  type CommandContext = Parameters<Parameters<ExtensionAPI["registerCommand"]>[1]["handler"]>[1];
30
17
 
31
- export default function reviewExtension(pi: ExtensionAPI) {
32
- registerReviewRenderer(pi);
33
- registerReviewSettings(pi);
34
- registerAgentReviewTools(pi);
35
-
36
- pi.registerCommand("supi-review", {
37
- description: "Run a structured code review informed by the current session history",
38
- handler: async (_args, ctx) => {
39
- await handleInteractive(ctx, pi);
18
+ const DEFAULT_REVIEW: ReviewInput = {
19
+ tasks: [
20
+ {
21
+ id: "general",
22
+ instructions: "Review for concrete regressions introduced by this change.",
40
23
  },
41
- });
24
+ ],
25
+ };
26
+
27
+ async function selectTarget(ctx: CommandContext): Promise<ReviewTargetSpec | undefined> {
28
+ const kind = await ctx.ui.select("Review target", [
29
+ "Working tree",
30
+ "Comparison against a base commit",
31
+ "Single commit",
32
+ ]);
33
+ if (!kind) return undefined;
34
+ if (kind === "Working tree") return { kind: "working-tree" };
35
+ const choices =
36
+ kind === "Single commit" ? await listRecentCommits(ctx.cwd) : await listLocalBranches(ctx.cwd);
37
+ const label = await ctx.ui.select(
38
+ kind === "Single commit" ? "Commit" : "Base branch",
39
+ choices.map((choice) => choice.label),
40
+ );
41
+ const choice = choices.find((candidate) => candidate.label === label);
42
+ if (!choice) return undefined;
43
+ return kind === "Single commit"
44
+ ? { kind: "commit", commit: choice.commit }
45
+ : { kind: "comparison", baseCommit: choice.commit };
42
46
  }
43
47
 
44
- async function handleInteractive(ctx: CommandContext, pi: ExtensionAPI): Promise<void> {
45
- if (!ctx.hasUI) {
46
- return;
48
+ async function selectReviewerModel(ctx: CommandContext): Promise<ReviewModelSelection | undefined> {
49
+ const models = getSelectableReviewModels(ctx);
50
+ if (models.length === 0) {
51
+ ctx.ui.notify("No scoped reviewer models are available.", "error");
52
+ return undefined;
47
53
  }
48
-
49
- const target = await selectTarget(ctx);
50
- if (!target) return;
51
-
52
- const model = await selectModel(ctx);
53
- if (!model) return;
54
-
55
- const note = await collectReviewNote(ctx);
56
- if (note === undefined) return;
57
- const normalizedNote = note.trim() || undefined;
58
-
59
- const snapshot = await resolveReviewSnapshot(target, ctx);
60
- if (!snapshot) return;
61
-
62
- const sessionContext = buildSessionContext(
63
- ctx.sessionManager.getEntries(),
64
- ctx.sessionManager.getLeafId(),
65
- );
66
- const serializedContext = serializeSessionContext(sessionContext.messages);
67
- const synthesis = await runWithProgressWidget(
68
- pi,
69
- ctx,
70
- "Synthesizing review brief…",
71
- (signal: AbortSignal, onProgress: (p: WidgetProgress) => void) =>
72
- synthesizeReviewBrief({
73
- model,
74
- cwd: ctx.cwd,
75
- snapshot,
76
- serializedContext,
77
- note: normalizedNote,
78
- signal,
79
- onProgress,
80
- }),
54
+ const id = await ctx.ui.select(
55
+ "Reviewer model",
56
+ models.map((model) => model.canonicalId),
81
57
  );
58
+ return models.find((model) => model.canonicalId === id);
59
+ }
82
60
 
83
- if (!synthesis) {
84
- const failure: BriefSynthesisRunResult = {
85
- kind: "failed",
86
- failureCode: "unexpected-runner-failure",
87
- diagnostics: createUnobservedChildFailureDiagnostics(),
88
- };
89
- notifyBriefDone(pi, failure, snapshot, model.canonicalId);
90
- injectBriefSynthesisFailureMessage(pi, failure, snapshot, model.canonicalId);
91
- ctx.ui.notify(formatBriefSynthesisFailureCopy(failure), "warning");
92
- return;
61
+ /** Parse editor JSON through the same structural and semantic contract as agent input. */
62
+ export async function editReview(
63
+ ctx: CommandContext,
64
+ review: ReviewInput,
65
+ ): Promise<ReviewInput | undefined> {
66
+ const text = await ctx.ui.editor("Edit review tasks (JSON)", JSON.stringify(review, null, 2));
67
+ if (text === undefined) return undefined;
68
+ try {
69
+ const parsed: unknown = JSON.parse(text);
70
+ if (!Value.Check(reviewInputSchema, parsed)) {
71
+ ctx.ui.notify("Review tasks do not match the required review schema.", "error");
72
+ return undefined;
73
+ }
74
+ return normalizeReviewInput(parsed);
75
+ } catch (error) {
76
+ const message = error instanceof Error ? error.message : "Review tasks must be valid JSON.";
77
+ ctx.ui.notify(message, "error");
78
+ return undefined;
93
79
  }
80
+ }
94
81
 
95
- notifyBriefDone(pi, synthesis, snapshot, model.canonicalId);
96
-
97
- if (synthesis.kind !== "success") {
98
- injectBriefSynthesisFailureMessage(pi, synthesis, snapshot, model.canonicalId);
99
- notifySynthesisFailure(synthesis, ctx);
100
- return;
82
+ async function runCommand(
83
+ ctx: CommandContext,
84
+ pi: ExtensionAPI,
85
+ planStore: ReviewPlanStore,
86
+ ): Promise<void> {
87
+ if (!ctx.hasUI) return;
88
+ const target = await selectTarget(ctx);
89
+ if (!target) return;
90
+ const reviewerModel = await selectReviewerModel(ctx);
91
+ if (!reviewerModel) return;
92
+ const planning = await ctx.ui.select("Review planning", ["Write tasks", "Suggest tasks"]);
93
+ if (!planning) return;
94
+
95
+ let review = DEFAULT_REVIEW;
96
+ let planId: string | undefined;
97
+ if (planning === "Suggest tasks") {
98
+ const config = loadReviewConfig(ctx.cwd);
99
+ const plannerModel = resolveAgentReviewModel(ctx, config.plannerModel);
100
+ if (!plannerModel) {
101
+ ctx.ui.notify(`Configured Planner model "${config.plannerModel}" is unavailable.`, "error");
102
+ return;
103
+ }
104
+ const session = buildSessionContext(
105
+ ctx.sessionManager.getEntries(),
106
+ ctx.sessionManager.getLeafId(),
107
+ );
108
+ const outcome = await prepareReview({
109
+ cwd: ctx.cwd,
110
+ target,
111
+ planning: "suggest",
112
+ plannerContext: collectPlannerContext(session.messages),
113
+ reviewerModel,
114
+ plannerModel,
115
+ planStore,
116
+ });
117
+ if (outcome.kind !== "prepared" || !outcome.plan.plannerDraft) {
118
+ ctx.ui.notify("Planner did not produce a draft.", "error");
119
+ return;
120
+ }
121
+ review = outcome.plan.plannerDraft;
122
+ planId = outcome.plan.id;
101
123
  }
102
124
 
103
- const brief = {
104
- ...synthesis.brief,
105
- note: normalizedNote,
106
- };
107
-
108
- const packet = buildReviewPacket(snapshot, brief, model);
109
- const plan: ReviewPlan = { model, snapshot, brief, packet };
110
-
111
- const approved = await previewReviewPlan(ctx, plan);
125
+ const edited = await editReview(ctx, review);
126
+ if (!edited) return;
127
+ const approved = await ctx.ui.confirm(
128
+ "Run review?",
129
+ `${edited.tasks.length} task(s) using ${reviewerModel.canonicalId}`,
130
+ );
112
131
  if (!approved) return;
113
132
 
114
- const rawResult = await runWithProgressWidget(
115
- pi,
116
- ctx,
117
- "Running code review…",
118
- (signal: AbortSignal, onProgress: (p: WidgetProgress) => void) =>
119
- runReviewer({
120
- prompt: plan.packet.prompt,
121
- model: plan.model,
133
+ const outcome = planId
134
+ ? await runReview({
135
+ mode: "prepared",
122
136
  cwd: ctx.cwd,
123
- signal,
124
- snapshot: plan.snapshot,
125
- brief: plan.brief,
126
- onProgress,
127
- }),
128
- );
129
-
130
- if (!rawResult) {
131
- const failure: ReviewResult = {
132
- kind: "failed",
133
- failureCode: "unexpected-runner-failure",
134
- diagnostics: createUnobservedChildFailureDiagnostics(),
135
- snapshot,
136
- brief,
137
- modelId: model.canonicalId,
138
- };
139
- notifyReviewDone(pi, failure);
140
- injectReviewMessage(pi, failure);
141
- ctx.ui.notify("Reviewer ended unexpectedly.", "warning");
137
+ planId,
138
+ decision: { kind: "use-review", review: edited },
139
+ planStore,
140
+ })
141
+ : await runReview({
142
+ mode: "direct",
143
+ cwd: ctx.cwd,
144
+ target,
145
+ review: edited,
146
+ reviewerModel,
147
+ });
148
+ if (outcome.kind !== "completed") {
149
+ ctx.ui.notify(outcome.reason, "error");
142
150
  return;
143
151
  }
144
-
145
- const result = normalizeReviewResult(rawResult as RawReviewResult);
146
- notifyReviewDone(pi, result);
147
- injectReviewMessage(pi, result);
148
- }
149
-
150
- async function resolveReviewSnapshot(
151
- target: ReviewTargetSpec,
152
- ctx: CommandContext,
153
- ): Promise<ReviewSnapshot | undefined> {
154
- const snapshot =
155
- target.kind === "working-tree"
156
- ? await resolveWorkingTreeSnapshot(ctx.cwd)
157
- : target.kind === "branch"
158
- ? await resolveBranchSnapshot(ctx.cwd, target.base)
159
- : await resolveCommitSnapshot(ctx.cwd, target.sha);
160
-
161
- if (snapshot) {
162
- return snapshot;
163
- }
164
-
165
- switch (target.kind) {
166
- case "working-tree":
167
- ctx.ui.notify("No working tree changes found", "warning");
168
- break;
169
- case "branch":
170
- ctx.ui.notify(`No reviewable changes found against ${target.base}`, "warning");
171
- break;
172
- case "commit":
173
- ctx.ui.notify(`Unable to resolve commit ${target.sha}`, "error");
174
- break;
175
- }
176
-
177
- return undefined;
178
- }
179
-
180
- function notifySynthesisFailure(
181
- result: Exclude<BriefSynthesisRunResult, { kind: "success" }>,
182
- ctx: CommandContext,
183
- ): void {
184
- ctx.ui.notify(
185
- formatBriefSynthesisFailureCopy(result),
186
- result.kind === "failed" ? "error" : "warning",
187
- );
188
- }
189
-
190
- /** Persist a brief-synthesis failure so bounded diagnostics remain inspectable in parent history. */
191
- function injectBriefSynthesisFailureMessage(
192
- pi: ExtensionAPI,
193
- result: Exclude<BriefSynthesisRunResult, { kind: "success" }>,
194
- snapshot: ReviewSnapshot,
195
- modelId: string,
196
- ): void {
197
152
  pi.sendMessage({
198
153
  customType: "supi-review",
199
- content: formatBriefSynthesisFailureContent(result),
154
+ content: pageText(formatReviewBatch(outcome.details)).text,
200
155
  display: true,
201
- details: {
202
- briefSynthesisFailure: { result, snapshot, modelId },
203
- },
204
- });
205
- }
206
-
207
- /** Ring the terminal bell so the user knows to check back. */
208
- function ringBell(): void {
209
- process.stdout.write("\x07");
210
- }
211
-
212
- /**
213
- * Emit a `supi:review:brief-done` event and ring the terminal bell after
214
- * brief synthesis completes (success, failure, cancel, or timeout).
215
- */
216
- function notifyBriefDone(
217
- pi: ExtensionAPI,
218
- result: BriefSynthesisRunResult,
219
- snapshot: ReviewSnapshot,
220
- modelId: string,
221
- ): void {
222
- pi.events.emit("supi:review:brief-done", {
223
- kind: result.kind,
224
- snapshot: snapshot.title,
225
- modelId,
226
- brief: result.kind === "success" ? result.brief : undefined,
156
+ details: outcome.details,
227
157
  });
228
- ringBell();
229
158
  }
230
159
 
231
- /**
232
- * Emit a `supi:review:review-done` event and ring the terminal bell after
233
- * the review child session completes.
234
- */
235
- function notifyReviewDone(pi: ExtensionAPI, result: ReviewResult): void {
236
- pi.events.emit("supi:review:review-done", {
237
- kind: result.kind,
238
- snapshot: result.snapshot.title,
239
- modelId: result.modelId,
240
- itemCount: result.kind === "success" ? result.output.items.length : 0,
160
+ export default function reviewExtension(pi: ExtensionAPI): void {
161
+ const planStore = new ReviewPlanStore();
162
+ registerReviewSettings(pi);
163
+ registerAgentReviewTools(pi, planStore);
164
+
165
+ // Message renderer for the /supi-review slash command output.
166
+ // Adapts the sendMessage shape into the shape renderRunResult expects.
167
+ pi.registerMessageRenderer("supi-review", (message, options, theme) => {
168
+ const adapted = {
169
+ content: [{ type: "text" as const, text: message.content as string }],
170
+ details: message.details,
171
+ isError: false,
172
+ };
173
+ const result = renderRunResult(adapted, { ...options, isPartial: false }, theme);
174
+ const box = new Box(options.outputPad, 0, undefined);
175
+ box.addChild(result);
176
+ return box;
241
177
  });
242
- ringBell();
243
- }
244
178
 
245
- function injectReviewMessage(pi: ExtensionAPI, result: ReviewResult): void {
246
- pi.sendMessage({
247
- customType: "supi-review",
248
- content: formatReviewContent(result),
249
- display: true,
250
- details: { result },
179
+ pi.registerCommand("supi-review", {
180
+ description: "Run one or more caller-defined read-only review tasks",
181
+ handler: async (_args, ctx) => runCommand(ctx, pi, planStore),
251
182
  });
252
-
253
- maybeQueueReviewFollowUp(pi, result);
254
- }
255
-
256
- function maybeQueueReviewFollowUp(pi: ExtensionAPI, result: ReviewResult): void {
257
- if (result.kind !== "success" || result.output.items.length === 0) {
258
- return;
259
- }
260
-
261
- pi.sendMessage(
262
- {
263
- customType: "supi-review-followup",
264
- content: buildReviewFollowUpInstruction(result),
265
- display: false,
266
- details: {
267
- itemCount: result.output.items.length,
268
- actionSummary: result.output.summary.actions,
269
- items: result.output.items.map((item, index) => ({
270
- number: index + 1,
271
- title: item.title,
272
- recommended_action: item.recommended_action,
273
- })),
274
- },
275
- },
276
- { triggerTurn: true },
277
- );
278
- }
279
-
280
- function buildReviewFollowUpInstruction(
281
- result: Extract<ReviewResult, { kind: "success" }>,
282
- ): string {
283
- const { items, summary } = result.output;
284
- const itemList = items.map(
285
- (item, index) => `- #${index + 1}: ${item.title} (${item.recommended_action})`,
286
- );
287
-
288
- const header =
289
- "A code review just completed and the result is available in the preceding `supi-review` message.";
290
- const noFixing = "Do not start fixing code immediately.";
291
- const useAskUser = "If the `ask_user` tool is available, use it for this decision.";
292
-
293
- const lines: string[] = [header];
294
- lines.push(
295
- `Action summary: ${summary.actions.mustFix} must-fix, ${summary.actions.shouldFix} should-fix, ${summary.actions.consider} consider.`,
296
- );
297
-
298
- if (summary.actions.mustFix > 0) {
299
- lines.push(`${summary.actions.mustFix} must-fix item(s) — fix before merging.`);
300
- } else if (summary.actions.shouldFix > 0) {
301
- lines.push(
302
- `${summary.actions.shouldFix} should-fix item(s) — review carefully before proceeding.`,
303
- );
304
- } else if (summary.actions.consider > 0) {
305
- lines.push(`${summary.actions.consider} consider item(s) — optional follow-ups to review.`);
306
- }
307
-
308
- lines.push(noFixing, useAskUser);
309
- lines.push("Offer these options: Fix all, Fix selected, Verify findings, Skip.");
310
- lines.push(
311
- "If the user chooses Fix selected, ask a follow-up question listing the review items by number/title.",
312
- );
313
- lines.push(
314
- "If the user chooses Verify findings, re-read the relevant files and diffs to independently confirm or refute each review item, then present the verified results and ask again.",
315
- );
316
- lines.push("", "Current review items:", ...itemList);
317
-
318
- return lines.join("\n");
319
183
  }
@@ -1,69 +1,38 @@
1
- import { createHash } from "node:crypto";
2
- import type { ReviewModelSelection, ReviewSnapshot, SynthesizedReviewBrief } from "../types.ts";
1
+ import { randomUUID } from "node:crypto";
2
+ import type { PlannerDraft, ReviewModelSelection, ReviewSnapshot } from "../types.ts";
3
3
 
4
- /** Session-scoped state retained between review preparation and execution. */
5
- export interface StoredAgentReviewPlan {
4
+ /** Session-local resolved target and model choices awaiting one execution decision. */
5
+ export interface StoredReviewPlan {
6
6
  id: string;
7
7
  snapshot: ReviewSnapshot;
8
- snapshotFingerprint: string;
9
- generatedBrief: SynthesizedReviewBrief;
10
- model: ReviewModelSelection;
11
- briefPromptVersion: string;
12
- createdAt: number;
8
+ reviewerModel: ReviewModelSelection;
9
+ plannerDraft?: PlannerDraft;
10
+ plannerModelId?: string;
11
+ plannerPromptVersion?: string;
13
12
  }
14
13
 
15
- /** Inputs retained when creating a session-scoped review plan. */
16
- export interface CreateAgentReviewPlanInput {
17
- snapshot: ReviewSnapshot;
18
- snapshotFingerprint: string;
19
- generatedBrief: SynthesizedReviewBrief;
20
- model: ReviewModelSelection;
21
- briefPromptVersion: string;
22
- }
23
-
24
- /**
25
- * Owns prepared review plans for one PI extension session.
26
- *
27
- * Plans are claimed atomically before reviewer child sessions start, preventing
28
- * duplicate runs from concurrent sibling tool calls.
29
- */
14
+ /** In-memory one-shot store; `take` atomically removes a plan before validation/execution. */
30
15
  export class ReviewPlanStore {
31
- readonly #plans = new Map<string, StoredAgentReviewPlan>();
32
- #sequence = 0;
16
+ readonly #plans = new Map<string, StoredReviewPlan>();
33
17
 
34
- /** Create and retain one prepared review plan. */
35
- create(input: CreateAgentReviewPlanInput): StoredAgentReviewPlan {
36
- const createdAt = Date.now();
37
- const id = this.createPlanId(input.snapshotFingerprint, createdAt);
38
- const plan: StoredAgentReviewPlan = { id, createdAt, ...input };
39
- this.#plans.set(id, plan);
18
+ create(input: Omit<StoredReviewPlan, "id">): StoredReviewPlan {
19
+ const plan = { id: `review-plan-${randomUUID()}`, ...input };
20
+ this.#plans.set(plan.id, plan);
40
21
  return plan;
41
22
  }
42
23
 
43
- /** Read a plan without consuming it. */
44
- get(id: string): StoredAgentReviewPlan | undefined {
45
- return this.#plans.get(id);
46
- }
47
-
48
- /** Atomically consume a plan so it can run at most once. */
49
- take(id: string): StoredAgentReviewPlan | undefined {
24
+ take(id: string): StoredReviewPlan | undefined {
50
25
  const plan = this.#plans.get(id);
51
- if (!plan) return undefined;
52
- this.#plans.delete(id);
26
+ if (plan) this.#plans.delete(id);
53
27
  return plan;
54
28
  }
55
29
 
56
- /** Remove all plans when PI replaces or reloads the session. */
57
- clear(): void {
58
- this.#plans.clear();
30
+ /** Read a plan without consuming it, for pre-execution task count display. */
31
+ peek(id: string): StoredReviewPlan | undefined {
32
+ return this.#plans.get(id);
59
33
  }
60
34
 
61
- private createPlanId(snapshotFingerprint: string, createdAt: number): string {
62
- this.#sequence++;
63
- const hash = createHash("sha256")
64
- .update(`${snapshotFingerprint}:${createdAt}:${this.#sequence}`)
65
- .digest("hex")
66
- .slice(0, 12);
67
- return `review-plan-${hash}`;
35
+ clear(): void {
36
+ this.#plans.clear();
68
37
  }
69
38
  }