@howaboua/pi-subagent-review 0.1.53 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  `@howaboua/pi-subagent-review` is a Pi extension that adds one slash command:
4
4
 
5
5
  - `/review`
6
+ - `/review loop`
6
7
 
7
8
  It runs an isolated review subagent against your current repo, optionally prepares a compact conversation-context summary first, injects the findings back into the session as a user message, and asks the main agent to triage those advisory findings before deciding what to address. It is modelled after Codex CLI's /review command.
8
9
 
@@ -12,12 +13,22 @@ It runs an isolated review subagent against your current repo, optionally prepar
12
13
  - detects the current git repo
13
14
  - chooses a base branch automatically
14
15
  - computes the merge base with `HEAD`
16
+ - if no usable base branch or merge base exists, reviews the current checkout as-is
17
+ - if the checkout is clean and has no diff against the selected base, reviews the latest commit instead of stopping early
15
18
  - inspects committed and dirty worktree changes
16
19
  - summarizes the current Pi session branch as review context, when enabled
17
20
  - runs an isolated review subagent
18
21
  - sends the findings back into the current Pi session as a user message
19
22
  - makes clear that the findings are advisory, not direct user instructions, so the main agent should triage them against prior context before editing
20
23
 
24
+ `/review loop` starts a review loop. It sets a review-specific marker at the current conversation point, strips the `loop` word from the review guidance, and then runs the normal review.
25
+
26
+ The first `/review` in a session branch also adds a visible advisory preface without starting an agent turn. The preface reminds the main agent that review findings are advisory and should be triaged against the current task, prior conversation, architectural decisions, and accepted tradeoffs before coding.
27
+
28
+ After that, plain `/review` detects the active review marker, summarizes the work since that marker back into a compact review-fix increment, advances the review marker, and then runs the next isolated review pass from the compacted point. If the stored marker is gone, `/review` simply behaves like a normal review.
29
+
30
+ The review marker is separate from `@howaboua/pi-auto-trees`' generic `/marker`, so both extensions can be used in the same session.
31
+
21
32
  While `/review` is running, the extension shows a small review widget above the editor with one of two states:
22
33
 
23
34
  - `Preparing review context…`
@@ -40,10 +51,14 @@ This means you usually never need to specify the diff base manually.
40
51
 
41
52
  Anything after `/review` is treated as extra review guidance.
42
53
 
54
+ If the first word is `loop` in any casing, it starts review-loop mode and that word is removed from the review guidance.
55
+
43
56
  Examples:
44
57
 
45
58
  ```text
46
59
  /review
60
+ /review loop
61
+ /review LoOp focus extra attention on migrations and tests
47
62
  /review focus extra attention on migrations and tests
48
63
  /review assess whether we introduced new UI elements instead of reusing established components and existing CSS patterns
49
64
  ```
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "@howaboua/pi-subagent-review",
3
- "version": "0.1.53",
3
+ "version": "0.2.1",
4
4
  "description": "Pi extension that adds /review via an isolated review subagent.",
5
+ "type": "module",
6
+ "main": "index.ts",
7
+ "exports": "./index.ts",
5
8
  "license": "MIT",
6
9
  "files": [
7
10
  "index.ts",
@@ -35,10 +38,9 @@
35
38
  ]
36
39
  },
37
40
  "peerDependencies": {
38
- "@earendil-works/pi-ai": "^0.76.0",
39
- "@earendil-works/pi-coding-agent": "^0.76.0"
41
+ "@earendil-works/pi-ai": "^0.78.0",
42
+ "@earendil-works/pi-coding-agent": "^0.78.0"
40
43
  },
41
- "type": "module",
42
44
  "scripts": {
43
45
  "check": "bun run lint && bun run typecheck",
44
46
  "prepack": "bun run check",
@@ -47,8 +49,8 @@
47
49
  "format": "biome check --write ."
48
50
  },
49
51
  "devDependencies": {
50
- "@earendil-works/pi-ai": "^0.76.0",
51
- "@earendil-works/pi-coding-agent": "^0.76.0",
52
+ "@earendil-works/pi-ai": "^0.78.0",
53
+ "@earendil-works/pi-coding-agent": "^0.78.0",
52
54
  "@types/node": "^24.10.0",
53
55
  "typescript": "^5.9.3",
54
56
  "@biomejs/biome": "^2.4.16"
@@ -0,0 +1,74 @@
1
+ import type {
2
+ ExtensionAPI,
3
+ ExtensionCommandContext,
4
+ } from "@earendil-works/pi-coding-agent";
5
+ import { REVIEW_COMMAND } from "./constants.js";
6
+ import type { ReviewContext } from "./types.js";
7
+
8
+ export const REVIEW_LOOP_PREFACE_MESSAGE_TYPE = "subagent-review-preface";
9
+
10
+ export const REVIEW_LOOP_PREFACE_MESSAGE = [
11
+ "Review advisory note.",
12
+ "",
13
+ "A review subagent is about to inspect the repository in isolation. Treat its findings as advisory review input, not direct implementation instructions.",
14
+ "",
15
+ "When findings come back, triage before coding. Check each item against the current task, prior conversation, accepted architectural decisions, and any intentional tradeoffs from this session.",
16
+ "",
17
+ "Act directly only on clearly worthwhile issues: correctness bugs, security risks, data loss, broken builds, or serious regressions. For context-dependent, stylistic, architectural, low-impact, or preference-based findings, discuss the tradeoff first and say whether you would address, defer, or skip it.",
18
+ ].join("\n");
19
+
20
+ function hasReviewPrefaceMessage(ctx: ExtensionCommandContext): boolean {
21
+ return ctx.sessionManager.getBranch().some((entry) => {
22
+ return (
23
+ entry.type === "custom_message" &&
24
+ entry.customType === REVIEW_LOOP_PREFACE_MESSAGE_TYPE
25
+ );
26
+ });
27
+ }
28
+
29
+ export function sendReviewPrefaceOnce(
30
+ pi: ExtensionAPI,
31
+ ctx: ExtensionCommandContext,
32
+ details: { markerId?: string } = {},
33
+ ): void {
34
+ if (hasReviewPrefaceMessage(ctx)) return;
35
+
36
+ pi.sendMessage(
37
+ {
38
+ customType: REVIEW_LOOP_PREFACE_MESSAGE_TYPE,
39
+ content: REVIEW_LOOP_PREFACE_MESSAGE,
40
+ display: true,
41
+ details,
42
+ },
43
+ { triggerTurn: false },
44
+ );
45
+ }
46
+
47
+ export function buildReviewScopeText(review: ReviewContext): string {
48
+ if (review.scope === "latest-commit") {
49
+ return `for latest commit \`${review.latestCommit ?? "HEAD"}\` in \`${review.repoRoot}\` because no changes were found against the selected base`;
50
+ }
51
+
52
+ if (review.baseBranch && review.mergeBase) {
53
+ return `against local base branch \`${review.baseBranch}\` in \`${review.repoRoot}\` (merge base \`${review.mergeBase.slice(0, 12)}\`)`;
54
+ }
55
+
56
+ return `for current repository state in \`${review.repoRoot}\` with no usable base branch or merge base`;
57
+ }
58
+
59
+ export function buildReviewUserMessage(
60
+ review: ReviewContext,
61
+ findings: string,
62
+ ): string {
63
+ return [
64
+ `Review findings from /${REVIEW_COMMAND} ${buildReviewScopeText(review)}:`,
65
+ "",
66
+ findings.trim() || "No actionable issues found.",
67
+ "",
68
+ "These findings are advisory output from an isolated review subagent.",
69
+ "",
70
+ "Triage before coding. Weigh each item against the current task, prior conversation, accepted architectural decisions, and intentional tradeoffs from this session.",
71
+ "",
72
+ "If you address, skip, or defer findings, briefly say why.",
73
+ ].join("\n");
74
+ }
@@ -6,11 +6,15 @@ import {
6
6
  } from "./config.js";
7
7
  import { REVIEW_COMMAND } from "./constants.js";
8
8
  import { buildReviewConversationSummary } from "./conversation-summary.js";
9
+ import { buildReviewUserMessage, sendReviewPrefaceOnce } from "./messages.js";
10
+ import { buildReviewTask, detectReviewContext } from "./review.js";
9
11
  import {
10
- buildReviewTask,
11
- buildReviewUserMessage,
12
- detectReviewContext,
13
- } from "./review.js";
12
+ applyReviewLoopMarker,
13
+ getSemanticLeafId,
14
+ parseReviewArgs,
15
+ readReviewLoopState,
16
+ summarizeReviewLoopIncrement,
17
+ } from "./review-loop.js";
14
18
  import { getFinalOutput, runReviewSubagent } from "./subagent.js";
15
19
 
16
20
  export function registerReviewCommand(pi: ExtensionAPI) {
@@ -18,6 +22,8 @@ export function registerReviewCommand(pi: ExtensionAPI) {
18
22
  description:
19
23
  "Run an isolated code-review subagent against the current repo and send the findings back as a user message",
20
24
  handler: async (args, ctx) => {
25
+ const parsedArgs = parseReviewArgs(args);
26
+ const reviewPrefaceDetails: { markerId?: string } = {};
21
27
  const setReviewWidget = (message?: string) => {
22
28
  ctx.ui.setWidget(
23
29
  REVIEW_COMMAND,
@@ -40,6 +46,21 @@ export function registerReviewCommand(pi: ExtensionAPI) {
40
46
  await ctx.waitForIdle();
41
47
  }
42
48
 
49
+ if (!parsedArgs.startLoop) {
50
+ const markerId = readReviewLoopState(ctx)?.markerId;
51
+ if (markerId) {
52
+ const loopResult = await summarizeReviewLoopIncrement(
53
+ pi,
54
+ ctx,
55
+ markerId,
56
+ );
57
+ if (loopResult === "cancelled") {
58
+ ctx.ui.notify("/review cancelled", "warning");
59
+ return;
60
+ }
61
+ }
62
+ }
63
+
43
64
  let review;
44
65
  try {
45
66
  review = await detectReviewContext(pi, ctx.cwd);
@@ -51,6 +72,21 @@ export function registerReviewCommand(pi: ExtensionAPI) {
51
72
  return;
52
73
  }
53
74
 
75
+ if (parsedArgs.startLoop) {
76
+ const targetId = getSemanticLeafId(ctx);
77
+ if (targetId) {
78
+ reviewPrefaceDetails.markerId = targetId;
79
+ applyReviewLoopMarker(
80
+ pi,
81
+ ctx,
82
+ targetId,
83
+ readReviewLoopState(ctx)?.markerId,
84
+ );
85
+ ctx.ui.notify("Review loop marker set", "info");
86
+ }
87
+ }
88
+ sendReviewPrefaceOnce(pi, ctx, reviewPrefaceDetails);
89
+
54
90
  if (!review.hasAnyChanges) {
55
91
  pi.sendUserMessage(
56
92
  buildReviewUserMessage(
@@ -90,7 +126,11 @@ export function registerReviewCommand(pi: ExtensionAPI) {
90
126
  );
91
127
  }
92
128
 
93
- const task = buildReviewTask(review, args, conversationSummary);
129
+ const task = buildReviewTask(
130
+ review,
131
+ parsedArgs.focus,
132
+ conversationSummary,
133
+ );
94
134
  details = createChildRunDetails(task, review.repoRoot, reviewConfig);
95
135
  if (reviewConfig.source === "current") {
96
136
  ctx.ui.notify(
@@ -0,0 +1,152 @@
1
+ import type {
2
+ ExtensionAPI,
3
+ ExtensionCommandContext,
4
+ } from "@earendil-works/pi-coding-agent";
5
+
6
+ export const REVIEW_LOOP_STATE_ENTRY = "subagent-review-loop-state";
7
+ export const REVIEW_LOOP_MARKER_LABEL = "review";
8
+ export const REVIEW_LOOP_WIDGET = "subagent-review-loop";
9
+ export const REVIEW_LOOP_SUMMARY_PROMPT = [
10
+ "Treat this as a completed review-fix increment that should become durable context before the next isolated review pass.",
11
+ "Focus on the final accepted outcome, not dead ends or step-by-step implementation noise.",
12
+ "Capture which review findings were addressed, which were intentionally skipped or deferred, concrete files changed, key decisions, tests/checks run, and any remaining risks that matter for the next review.",
13
+ "Mention relevant commands, commits, PR outcomes, or review feedback only when they change future work.",
14
+ "Omit temporary debugging details, abandoned attempts, incidental churn, and repetitive review transcript noise.",
15
+ "Write the summary so the main agent can continue from this compacted review-loop point and immediately run the next review pass.",
16
+ ].join("\n");
17
+
18
+ interface ReviewLoopState {
19
+ version: 1;
20
+ markerId: string;
21
+ }
22
+
23
+ export interface ParsedReviewArgs {
24
+ startLoop: boolean;
25
+ focus: string;
26
+ }
27
+
28
+ function isReviewLoopState(value: unknown): value is ReviewLoopState {
29
+ if (typeof value !== "object" || value === null) return false;
30
+ const candidate = value as { version?: unknown; markerId?: unknown };
31
+ return candidate.version === 1 && typeof candidate.markerId === "string";
32
+ }
33
+
34
+ export function parseReviewArgs(args: string): ParsedReviewArgs {
35
+ const trimmed = args.trim();
36
+ if (!trimmed) return { startLoop: false, focus: "" };
37
+
38
+ const match = /^(\S+)(?:\s+([\s\S]*))?$/.exec(trimmed);
39
+ const firstWord = match?.[1] ?? "";
40
+ if (firstWord.toLowerCase() !== "loop") {
41
+ return { startLoop: false, focus: trimmed };
42
+ }
43
+
44
+ return { startLoop: true, focus: (match?.[2] ?? "").trim() };
45
+ }
46
+
47
+ export function readReviewLoopState(
48
+ ctx: ExtensionCommandContext,
49
+ ): ReviewLoopState | undefined {
50
+ let state: ReviewLoopState | undefined;
51
+
52
+ for (const entry of ctx.sessionManager.getBranch()) {
53
+ if (entry.type !== "custom" || entry.customType !== REVIEW_LOOP_STATE_ENTRY)
54
+ continue;
55
+ if (isReviewLoopState(entry.data)) state = entry.data;
56
+ }
57
+
58
+ return state;
59
+ }
60
+
61
+ export function getSemanticLeafId(
62
+ ctx: ExtensionCommandContext,
63
+ ): string | undefined {
64
+ let currentId = ctx.sessionManager.getLeafId();
65
+
66
+ while (currentId) {
67
+ const entry = ctx.sessionManager.getEntry(currentId);
68
+ if (!entry) return undefined;
69
+
70
+ if (entry.type === "custom" || entry.type === "label") {
71
+ currentId = entry.parentId;
72
+ continue;
73
+ }
74
+
75
+ return currentId;
76
+ }
77
+
78
+ return undefined;
79
+ }
80
+
81
+ export function applyReviewLoopMarker(
82
+ pi: ExtensionAPI,
83
+ ctx: ExtensionCommandContext,
84
+ nextMarkerId: string,
85
+ previousMarkerId?: string,
86
+ ): void {
87
+ if (
88
+ previousMarkerId &&
89
+ previousMarkerId !== nextMarkerId &&
90
+ ctx.sessionManager.getLabel(previousMarkerId) === REVIEW_LOOP_MARKER_LABEL
91
+ ) {
92
+ pi.setLabel(previousMarkerId, undefined);
93
+ }
94
+
95
+ const existingLabel = ctx.sessionManager.getLabel(nextMarkerId);
96
+ if (
97
+ existingLabel === undefined ||
98
+ existingLabel === REVIEW_LOOP_MARKER_LABEL
99
+ ) {
100
+ pi.setLabel(nextMarkerId, REVIEW_LOOP_MARKER_LABEL);
101
+ }
102
+
103
+ pi.appendEntry(REVIEW_LOOP_STATE_ENTRY, {
104
+ version: 1,
105
+ markerId: nextMarkerId,
106
+ } satisfies ReviewLoopState);
107
+ }
108
+
109
+ export async function summarizeReviewLoopIncrement(
110
+ pi: ExtensionAPI,
111
+ ctx: ExtensionCommandContext,
112
+ markerId: string,
113
+ ): Promise<"summarized" | "skipped" | "cancelled"> {
114
+ if (!ctx.sessionManager.getEntry(markerId)) return "skipped";
115
+
116
+ const currentSemanticLeafId = getSemanticLeafId(ctx);
117
+ if (!currentSemanticLeafId || currentSemanticLeafId === markerId) {
118
+ return "skipped";
119
+ }
120
+
121
+ const clearLoopFeedback = () => {
122
+ if (ctx.hasUI) ctx.ui.setWidget(REVIEW_LOOP_WIDGET, undefined);
123
+ ctx.ui.setWorkingMessage();
124
+ };
125
+
126
+ ctx.ui.setWorkingMessage(ctx.ui.theme.fg("dim", "Summarizing review loop…"));
127
+ if (ctx.hasUI) {
128
+ ctx.ui.setWidget(
129
+ REVIEW_LOOP_WIDGET,
130
+ [ctx.ui.theme.fg("dim", "Summarizing review loop increment...")],
131
+ { placement: "aboveEditor" },
132
+ );
133
+ }
134
+
135
+ let result: Awaited<ReturnType<typeof ctx.navigateTree>>;
136
+ try {
137
+ result = await ctx.navigateTree(markerId, {
138
+ summarize: true,
139
+ customInstructions: REVIEW_LOOP_SUMMARY_PROMPT,
140
+ replaceInstructions: false,
141
+ });
142
+ } finally {
143
+ clearLoopFeedback();
144
+ }
145
+
146
+ if (result.cancelled) return "cancelled";
147
+
148
+ const nextMarkerId = getSemanticLeafId(ctx);
149
+ if (!nextMarkerId) return "skipped";
150
+ applyReviewLoopMarker(pi, ctx, nextMarkerId, markerId);
151
+ return "summarized";
152
+ }
package/src/review.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import { REVIEW_COMMAND } from "./constants.js";
3
2
  import type { ReviewContext } from "./types.js";
4
3
 
5
4
  async function runGit(
@@ -32,28 +31,31 @@ async function gitString(
32
31
  async function hasLocalBranch(
33
32
  pi: ExtensionAPI,
34
33
  cwd: string,
35
- branch: "main" | "master",
34
+ branch: "main" | "master" | "dev",
36
35
  ): Promise<boolean> {
37
- const result = await runGit(pi, cwd, [
38
- "show-ref",
36
+ const refResult = await runGit(pi, cwd, [
37
+ "rev-parse",
39
38
  "--verify",
40
39
  "--quiet",
41
40
  `refs/heads/${branch}`,
42
41
  ]);
43
- return result.code === 0;
42
+ if (refResult.code !== 0) return false;
43
+
44
+ const objectName = refResult.stdout.trim();
45
+ if (!objectName) return false;
46
+ const commitResult = await runGit(pi, cwd, [
47
+ "cat-file",
48
+ "-e",
49
+ `${objectName}^{commit}`,
50
+ ]);
51
+ return commitResult.code === 0;
44
52
  }
45
53
 
46
54
  async function hasLocalDevBranch(
47
55
  pi: ExtensionAPI,
48
56
  cwd: string,
49
57
  ): Promise<boolean> {
50
- const result = await runGit(pi, cwd, [
51
- "show-ref",
52
- "--verify",
53
- "--quiet",
54
- "refs/heads/dev",
55
- ]);
56
- return result.code === 0;
58
+ return hasLocalBranch(pi, cwd, "dev");
57
59
  }
58
60
 
59
61
  async function hasTrackedChangesAgainst(
@@ -70,6 +72,17 @@ async function hasTrackedChangesAgainst(
70
72
  );
71
73
  }
72
74
 
75
+ async function gitStringOrUndefined(
76
+ pi: ExtensionAPI,
77
+ cwd: string,
78
+ args: string[],
79
+ timeout = 10_000,
80
+ ): Promise<string | undefined> {
81
+ const result = await runGit(pi, cwd, args, timeout);
82
+ if (result.code !== 0) return undefined;
83
+ return result.stdout.trim();
84
+ }
85
+
73
86
  export async function detectReviewContext(
74
87
  pi: ExtensionAPI,
75
88
  cwd: string,
@@ -100,42 +113,56 @@ export async function detectReviewContext(
100
113
  else baseBranch = currentBranch as "main" | "master";
101
114
  }
102
115
 
103
- if (!baseBranch) {
104
- const branches = await gitString(pi, repoRoot, [
105
- "for-each-ref",
106
- "--format=%(refname:short)",
107
- "refs/heads",
108
- ]);
109
- throw new Error(
110
- `Could not determine an automatic review base branch. Local branches: ${branches || "(none)"}`,
111
- );
112
- }
113
-
114
116
  const currentRef =
115
117
  currentBranch ||
116
118
  (await gitString(pi, repoRoot, ["rev-parse", "--short", "HEAD"]));
117
- const mergeBase = await gitString(pi, repoRoot, [
119
+ const status = await gitString(pi, repoRoot, [
120
+ "status",
121
+ "--short",
122
+ "--untracked-files=all",
123
+ ]);
124
+
125
+ if (!baseBranch) {
126
+ return {
127
+ repoRoot,
128
+ currentRef,
129
+ scope: "current-state",
130
+ status,
131
+ hasTrackedChanges: false,
132
+ hasAnyChanges: true,
133
+ };
134
+ }
135
+
136
+ const baseBranchRef = `refs/heads/${baseBranch}`;
137
+ const mergeBase = await gitStringOrUndefined(pi, repoRoot, [
118
138
  "merge-base",
119
- baseBranch,
139
+ baseBranchRef,
120
140
  "HEAD",
121
141
  ]);
122
- const baseTip = await gitString(pi, repoRoot, [
142
+ if (!mergeBase) {
143
+ return {
144
+ repoRoot,
145
+ currentRef,
146
+ scope: "current-state",
147
+ baseBranch,
148
+ status,
149
+ hasTrackedChanges: false,
150
+ hasAnyChanges: true,
151
+ };
152
+ }
153
+
154
+ const baseTip = await gitStringOrUndefined(pi, repoRoot, [
123
155
  "rev-parse",
124
156
  "--short",
125
- baseBranch,
157
+ baseBranchRef,
126
158
  ]);
127
- const recentBaseCommits = await gitString(pi, repoRoot, [
159
+ const recentBaseCommits = await gitStringOrUndefined(pi, repoRoot, [
128
160
  "log",
129
161
  "--oneline",
130
162
  "--decorate",
131
163
  "-n",
132
164
  "8",
133
- baseBranch,
134
- ]);
135
- const status = await gitString(pi, repoRoot, [
136
- "status",
137
- "--short",
138
- "--untracked-files=all",
165
+ baseBranchRef,
139
166
  ]);
140
167
  const hasTrackedChanges = await hasTrackedChangesAgainst(
141
168
  pi,
@@ -143,17 +170,25 @@ export async function detectReviewContext(
143
170
  mergeBase,
144
171
  );
145
172
  const hasAnyChanges = hasTrackedChanges || status.length > 0;
173
+ const latestCommit = await gitStringOrUndefined(pi, repoRoot, [
174
+ "rev-parse",
175
+ "--short",
176
+ "HEAD",
177
+ ]);
178
+ const scope = hasAnyChanges ? "base-diff" : "latest-commit";
146
179
 
147
180
  return {
148
181
  repoRoot,
149
182
  currentRef,
183
+ scope,
150
184
  baseBranch,
151
185
  mergeBase,
152
186
  baseTip,
187
+ latestCommit,
153
188
  status,
154
189
  recentBaseCommits,
155
190
  hasTrackedChanges,
156
- hasAnyChanges,
191
+ hasAnyChanges: hasAnyChanges || Boolean(latestCommit),
157
192
  };
158
193
  }
159
194
 
@@ -172,13 +207,25 @@ export function buildReviewTask(
172
207
  const sections = [
173
208
  `Repository root: ${review.repoRoot}`,
174
209
  `Current ref: ${review.currentRef}`,
175
- `Chosen local base branch: ${review.baseBranch}`,
176
- `Base branch tip (short SHA): ${review.baseTip}`,
177
- `Merge base (${review.baseBranch}, HEAD): ${review.mergeBase}`,
178
- "",
179
- `Recent commits on ${review.baseBranch}:`,
180
- review.recentBaseCommits || "(none)",
210
+ `Review scope: ${review.scope}`,
211
+ ...(review.baseBranch && review.mergeBase
212
+ ? [
213
+ `Chosen local base branch: ${review.baseBranch}`,
214
+ `Base branch tip (short SHA): ${review.baseTip ?? "unknown"}`,
215
+ `Merge base (${review.baseBranch}, HEAD): ${review.mergeBase}`,
216
+ ]
217
+ : [
218
+ "Chosen local base branch: none",
219
+ "Merge base: none; review the repository checkout as it currently exists.",
220
+ ]),
181
221
  "",
222
+ ...(review.baseBranch && review.recentBaseCommits !== undefined
223
+ ? [
224
+ `Recent commits on ${review.baseBranch}:`,
225
+ review.recentBaseCommits || "(none)",
226
+ "",
227
+ ]
228
+ : []),
182
229
  "Current status (`git status --short --untracked-files=all`):",
183
230
  review.status || "(clean)",
184
231
  "",
@@ -193,15 +240,39 @@ export function buildReviewTask(
193
240
  "",
194
241
  ]
195
242
  : []),
196
- "Review the current checkout against the merge base so uncommitted changes are included while base-only commits are excluded.",
197
- "Required inspection steps:",
198
- `1. Run \`git diff --stat ${review.mergeBase}\``,
199
- `2. Run \`git diff ${review.mergeBase}\``,
200
- `3. Run \`git diff --stat ${review.baseBranch}...HEAD\``,
201
- `4. Run \`git diff ${review.baseBranch}...HEAD\``,
202
- "5. Use targeted file diffs or reads where needed.",
203
243
  ];
204
244
 
245
+ if (review.scope === "latest-commit") {
246
+ sections.push(
247
+ "No changes were found between the current checkout and the selected base/merge-base. Review the latest committed state instead of returning no findings.",
248
+ "Required inspection steps:",
249
+ "1. Run `git status --short --untracked-files=all`",
250
+ "2. Run `git show --stat --root HEAD`",
251
+ "3. Run `git show --root HEAD`",
252
+ "4. Read relevant source files directly where needed.",
253
+ );
254
+ } else if (review.baseBranch && review.mergeBase) {
255
+ sections.push(
256
+ "Review the current checkout against the merge base so uncommitted changes are included while base-only commits are excluded.",
257
+ "Required inspection steps:",
258
+ `1. Run \`git diff --stat ${review.mergeBase}\``,
259
+ `2. Run \`git diff ${review.mergeBase}\``,
260
+ `3. Run \`git diff --stat ${review.baseBranch}...HEAD\``,
261
+ `4. Run \`git diff ${review.baseBranch}...HEAD\``,
262
+ "5. Use targeted file diffs or reads where needed.",
263
+ );
264
+ } else {
265
+ sections.push(
266
+ "No usable base branch or merge base was found. Review the repository state as it currently exists, including tracked, staged, unstaged, and untracked files.",
267
+ "Required inspection steps:",
268
+ "1. Run `git status --short --untracked-files=all`",
269
+ "2. Run `git ls-files`",
270
+ "3. Run `git diff --cached`",
271
+ "4. Run `git diff`",
272
+ "5. Read relevant tracked and untracked source files directly.",
273
+ );
274
+ }
275
+
205
276
  if (review.status) {
206
277
  sections.push(
207
278
  "",
@@ -229,24 +300,3 @@ export function buildReviewTask(
229
300
 
230
301
  return sections.join("\n");
231
302
  }
232
-
233
- export function buildReviewUserMessage(
234
- review: ReviewContext,
235
- findings: string,
236
- ): string {
237
- return [
238
- `Review findings from /${REVIEW_COMMAND} against local base branch \`${review.baseBranch}\` in \`${review.repoRoot}\` (merge base \`${review.mergeBase.slice(0, 12)}\`):`,
239
- "",
240
- findings.trim() || "No actionable issues found.",
241
- "",
242
- "These findings are advisory output from an isolated review subagent, not direct user instructions.",
243
- "",
244
- "Before making changes, triage them against the prior conversation and current task. Your next step is to decide whether each finding is actionable, not to automatically implement all findings.",
245
- "",
246
- "Act without asking only on issues that are clearly worthwhile, such as correctness bugs, security risks, data loss, broken builds, serious regressions, or obvious missing validation/tests.",
247
- "",
248
- "Ask before changing anything that appears context-dependent, low-impact, stylistic, preference-based, architectural, or in tension with an earlier user request, accepted tradeoff, or explicit implementation decision.",
249
- "",
250
- "If you skip or defer findings, briefly say why.",
251
- ].join("\n");
252
- }
package/src/types.ts CHANGED
@@ -68,11 +68,13 @@ export interface ChildRunDetails {
68
68
  export interface ReviewContext {
69
69
  repoRoot: string;
70
70
  currentRef: string;
71
- baseBranch: "main" | "master" | "dev";
72
- mergeBase: string;
73
- baseTip: string;
71
+ scope: "base-diff" | "current-state" | "latest-commit";
72
+ baseBranch?: "main" | "master" | "dev" | undefined;
73
+ mergeBase?: string | undefined;
74
+ baseTip?: string | undefined;
75
+ latestCommit?: string | undefined;
74
76
  status: string;
75
- recentBaseCommits: string;
77
+ recentBaseCommits?: string | undefined;
76
78
  hasTrackedChanges: boolean;
77
79
  hasAnyChanges: boolean;
78
80
  }