@howaboua/pi-subagent-review 0.1.5 → 0.1.52

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
@@ -4,7 +4,7 @@
4
4
 
5
5
  - `/review`
6
6
 
7
- It runs an isolated review subagent against your current repo, injects the findings back into the session as a user message, and asks the main agent to consider those findings in light of the prior conversation before deciding what to address. It is modelled after Codex CLI's /review command.
7
+ 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
8
 
9
9
  ## What it does
10
10
 
@@ -13,20 +13,31 @@ It runs an isolated review subagent against your current repo, injects the findi
13
13
  - chooses a base branch automatically
14
14
  - computes the merge base with `HEAD`
15
15
  - inspects committed and dirty worktree changes
16
+ - summarizes the current Pi session branch as review context, when enabled
16
17
  - runs an isolated review subagent
17
18
  - sends the findings back into the current Pi session as a user message
18
- - as a result, the main agent reviews the findings against the prior conversation and addresses only clearly worthwhile issues
19
+ - makes clear that the findings are advisory, not direct user instructions, so the main agent should triage them against prior context before editing
20
+
21
+ While `/review` is running, the extension shows a small review widget above the editor with one of two states:
22
+
23
+ - `Preparing review context…`
24
+ - `Reviewing changes…`
25
+
26
+ The widget is UI-only and is cleared when the command finishes, fails, or is cancelled.
19
27
 
20
28
  ## Automatic base branch selection
21
29
 
22
30
  The command chooses the base branch automatically:
23
31
 
32
+ - if the current branch has a configured local parent/upstream branch, it reviews against that branch
33
+ - if the current branch reflog says it was created from another local branch, it reviews against that branch
34
+ - if the branch was created from `HEAD`, it tries to infer the parent from the branch creation commit
24
35
  - if you are on a branch other than `main`, `master`, or `dev`, it reviews against `dev`
25
36
  - if no local `dev` exists, it falls back to `main`, then `master`
26
37
  - if you are on `dev`, it reviews against `main`, then `master`
27
38
  - if you are on `main` or `master`, it prefers `dev` when available
28
39
 
29
- This means you usually never need to specify the diff base manually.
40
+ This makes `/review` work better in git worktrees: a worktree branch created from another local branch is reviewed against that parent branch instead of blindly falling back to `dev`/`main`/`master`. If no parent can be detected, the old fallback rules still apply.
30
41
 
31
42
  ## User arguments
32
43
 
@@ -64,6 +75,20 @@ Edit that file to change the default review model or thinking level, and the mod
64
75
 
65
76
  The summary model uses the same `provider/model` string format as the reviewer model. The generated summary is injected into the isolated review task as branch-style context; raw conversation turns are not sent to the review subagent. If the configured review or summary model is not available for the user, `/review` falls back to the current session model automatically. If conversation summarization still fails, `/review` continues with a diff-only review.
66
77
 
78
+ Existing config files from older versions are migrated on load. If a config has `model` and `thinking` but no `summary` block, the extension adds one using the same model and low thinking:
79
+
80
+ ```json
81
+ {
82
+ "summary": {
83
+ "enabled": true,
84
+ "model": "<existing review model>",
85
+ "thinking": "low"
86
+ }
87
+ }
88
+ ```
89
+
90
+ If a `summary` block already exists, it is left unchanged.
91
+
67
92
  ## Install
68
93
 
69
94
  Installation methods:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howaboua/pi-subagent-review",
3
- "version": "0.1.5",
3
+ "version": "0.1.52",
4
4
  "description": "Pi extension that adds /review via an isolated review subagent.",
5
5
  "license": "MIT",
6
6
  "files": [
package/src/review.ts CHANGED
@@ -16,16 +16,11 @@ async function gitString(pi: ExtensionAPI, cwd: string, args: string[], timeout
16
16
  return result.stdout.trim();
17
17
  }
18
18
 
19
- async function hasLocalBranch(pi: ExtensionAPI, cwd: string, branch: "main" | "master"): Promise<boolean> {
19
+ async function hasLocalBranch(pi: ExtensionAPI, cwd: string, branch: string): Promise<boolean> {
20
20
  const result = await runGit(pi, cwd, ["show-ref", "--verify", "--quiet", `refs/heads/${branch}`]);
21
21
  return result.code === 0;
22
22
  }
23
23
 
24
- async function hasLocalDevBranch(pi: ExtensionAPI, cwd: string): Promise<boolean> {
25
- const result = await runGit(pi, cwd, ["show-ref", "--verify", "--quiet", "refs/heads/dev"]);
26
- return result.code === 0;
27
- }
28
-
29
24
  async function hasTrackedChangesAgainst(pi: ExtensionAPI, cwd: string, revision: string): Promise<boolean> {
30
25
  const result = await runGit(pi, cwd, ["diff", "--quiet", revision]);
31
26
  if (result.code === 0) return false;
@@ -33,29 +28,97 @@ async function hasTrackedChangesAgainst(pi: ExtensionAPI, cwd: string, revision:
33
28
  throw new Error(result.stderr.trim() || `git diff --quiet ${revision} failed with exit code ${result.code}`);
34
29
  }
35
30
 
31
+ async function firstExistingBranch(pi: ExtensionAPI, cwd: string, branches: string[]): Promise<string | undefined> {
32
+ for (const branch of branches) {
33
+ if (await hasLocalBranch(pi, cwd, branch)) return branch;
34
+ }
35
+ return undefined;
36
+ }
37
+
38
+ function normalizeLocalBranchRef(ref: string): string | undefined {
39
+ const trimmed = ref.trim();
40
+ if (!trimmed || trimmed === "HEAD") return undefined;
41
+ if (trimmed.startsWith("refs/heads/")) return trimmed.slice("refs/heads/".length);
42
+ if (trimmed.startsWith("heads/")) return trimmed.slice("heads/".length);
43
+ return trimmed.replace(/^\/+/, "");
44
+ }
45
+
46
+ async function getConfiguredParentBranch(pi: ExtensionAPI, cwd: string, currentBranch: string): Promise<string | undefined> {
47
+ const remote = await runGit(pi, cwd, ["config", "--get", `branch.${currentBranch}.remote`]);
48
+ if (remote.code === 0 && remote.stdout.trim() && remote.stdout.trim() !== ".") return undefined;
49
+
50
+ const merge = await runGit(pi, cwd, ["config", "--get", `branch.${currentBranch}.merge`]);
51
+ if (merge.code !== 0) return undefined;
52
+ const branch = normalizeLocalBranchRef(merge.stdout.trim());
53
+ if (!branch || branch === currentBranch) return undefined;
54
+ return (await hasLocalBranch(pi, cwd, branch)) ? branch : undefined;
55
+ }
56
+
57
+ async function inferParentBranchFromCreationCommit(pi: ExtensionAPI, cwd: string, currentBranch: string, commit: string): Promise<string | undefined> {
58
+ const result = await runGit(pi, cwd, ["for-each-ref", "--contains", commit, "--format=%(refname:short)%00%(objectname)", "refs/heads"]);
59
+ if (result.code !== 0) return undefined;
60
+
61
+ const candidates = result.stdout
62
+ .split("\n")
63
+ .map((line) => {
64
+ const [branch, tip] = line.split("\0");
65
+ return { branch: branch ?? "", tip: tip ?? "" };
66
+ })
67
+ .filter((candidate) => candidate.branch && candidate.branch !== currentBranch && candidate.tip === commit);
68
+
69
+ return candidates.length === 1 ? candidates[0]?.branch : undefined;
70
+ }
71
+
72
+ async function getReflogParentBranch(pi: ExtensionAPI, cwd: string, currentBranch: string): Promise<string | undefined> {
73
+ const result = await runGit(pi, cwd, ["reflog", "show", "--format=%H%x00%gs", `refs/heads/${currentBranch}`]);
74
+ if (result.code !== 0) return undefined;
75
+
76
+ for (const line of result.stdout.split("\n")) {
77
+ const [commit, subject] = line.split("\0");
78
+ const copyMatch = (subject ?? "").match(/^Branch: copied refs\/heads\/(.+) to refs\/heads\/.+$/);
79
+ if (copyMatch) {
80
+ const candidate = normalizeLocalBranchRef(copyMatch[1] ?? "");
81
+ if (candidate && candidate !== currentBranch && await hasLocalBranch(pi, cwd, candidate)) return candidate;
82
+ continue;
83
+ }
84
+
85
+ const match = (subject ?? "").match(/^branch: Created from (.+)$/);
86
+ if (!match) continue;
87
+
88
+ const createdFrom = match[1] ?? "";
89
+ const candidate = normalizeLocalBranchRef(createdFrom);
90
+ if (candidate && candidate !== currentBranch && await hasLocalBranch(pi, cwd, candidate)) return candidate;
91
+ if (/^HEAD(?:[~^].*)?$/.test(createdFrom.trim()) && commit) return inferParentBranchFromCreationCommit(pi, cwd, currentBranch, commit);
92
+ }
93
+
94
+ return undefined;
95
+ }
96
+
97
+ async function detectParentBranch(pi: ExtensionAPI, cwd: string, currentBranch: string): Promise<string | undefined> {
98
+ if (!currentBranch) return undefined;
99
+ return (await getConfiguredParentBranch(pi, cwd, currentBranch)) ?? (await getReflogParentBranch(pi, cwd, currentBranch));
100
+ }
101
+
102
+ async function detectFallbackBaseBranch(pi: ExtensionAPI, cwd: string, currentBranch: string): Promise<string | undefined> {
103
+ const hasDev = await hasLocalBranch(pi, cwd, "dev");
104
+ const hasMain = await hasLocalBranch(pi, cwd, "main");
105
+ const hasMaster = await hasLocalBranch(pi, cwd, "master");
106
+
107
+ if (currentBranch === "dev") return (await firstExistingBranch(pi, cwd, ["main", "master"]));
108
+ if (currentBranch !== "main" && currentBranch !== "master") return (await firstExistingBranch(pi, cwd, ["dev", "main", "master"]));
109
+ if (hasDev) return "dev";
110
+ if (currentBranch === "main" && hasMaster) return "master";
111
+ if (currentBranch === "master" && hasMain) return "main";
112
+ return currentBranch || undefined;
113
+ }
114
+
36
115
  export async function detectReviewContext(pi: ExtensionAPI, cwd: string): Promise<ReviewContext> {
37
116
  const repoRoot = await gitString(pi, cwd, ["rev-parse", "--show-toplevel"]);
38
117
  const currentBranch = await gitString(pi, repoRoot, ["branch", "--show-current"]);
39
- const [hasDev, hasMain, hasMaster] = await Promise.all([
40
- hasLocalDevBranch(pi, repoRoot),
41
- hasLocalBranch(pi, repoRoot, "main"),
42
- hasLocalBranch(pi, repoRoot, "master"),
43
- ]);
44
-
45
- let baseBranch: "main" | "master" | "dev" | undefined;
46
- if (currentBranch === "dev") {
47
- if (hasMain) baseBranch = "main";
48
- else if (hasMaster) baseBranch = "master";
49
- } else if (currentBranch !== "main" && currentBranch !== "master") {
50
- if (hasDev) baseBranch = "dev";
51
- else if (hasMain) baseBranch = "main";
52
- else if (hasMaster) baseBranch = "master";
53
- } else {
54
- if (hasDev) baseBranch = "dev";
55
- else if (currentBranch === "main" && hasMaster) baseBranch = "master";
56
- else if (currentBranch === "master" && hasMain) baseBranch = "main";
57
- else baseBranch = currentBranch as "main" | "master";
58
- }
118
+
119
+ const parentBranch = await detectParentBranch(pi, repoRoot, currentBranch);
120
+ const baseBranch = parentBranch ?? (await detectFallbackBaseBranch(pi, repoRoot, currentBranch));
121
+ const baseSource = parentBranch ? "parent" : "fallback";
59
122
 
60
123
  if (!baseBranch) {
61
124
  const branches = await gitString(pi, repoRoot, ["for-each-ref", "--format=%(refname:short)", "refs/heads"]);
@@ -74,6 +137,7 @@ export async function detectReviewContext(pi: ExtensionAPI, cwd: string): Promis
74
137
  repoRoot,
75
138
  currentRef,
76
139
  baseBranch,
140
+ baseSource,
77
141
  mergeBase,
78
142
  baseTip,
79
143
  status,
@@ -94,7 +158,7 @@ export function buildReviewTask(review: ReviewContext, extraFocus: string, conve
94
158
  const sections = [
95
159
  `Repository root: ${review.repoRoot}`,
96
160
  `Current ref: ${review.currentRef}`,
97
- `Chosen local base branch: ${review.baseBranch}`,
161
+ `Chosen local base branch: ${review.baseBranch} (${review.baseSource === "parent" ? "detected parent branch" : "fallback branch"})`,
98
162
  `Base branch tip (short SHA): ${review.baseTip}`,
99
163
  `Merge base (${review.baseBranch}, HEAD): ${review.mergeBase}`,
100
164
  "",
@@ -152,9 +216,16 @@ export function buildReviewTask(review: ReviewContext, extraFocus: string, conve
152
216
  return sections.join("\n");
153
217
  }
154
218
 
219
+ function markdownCodeSpan(value: string): string {
220
+ const longestBacktickRun = Math.max(0, ...Array.from(value.matchAll(/`+/g), (match) => match[0].length));
221
+ const delimiter = "`".repeat(longestBacktickRun + 1);
222
+ const padding = value.startsWith("`") || value.endsWith("`") ? " " : "";
223
+ return `${delimiter}${padding}${value}${padding}${delimiter}`;
224
+ }
225
+
155
226
  export function buildReviewUserMessage(review: ReviewContext, findings: string): string {
156
227
  return [
157
- `Review findings from /${REVIEW_COMMAND} against local base branch \`${review.baseBranch}\` in \`${review.repoRoot}\` (merge base \`${review.mergeBase.slice(0, 12)}\`):`,
228
+ `Review findings from /${REVIEW_COMMAND} against local base branch ${markdownCodeSpan(review.baseBranch)} (${review.baseSource === "parent" ? "detected parent branch" : "fallback branch"}) in ${markdownCodeSpan(review.repoRoot)} (merge base ${markdownCodeSpan(review.mergeBase.slice(0, 12))}):`,
158
229
  "",
159
230
  findings.trim() || "No actionable issues found.",
160
231
  "",
package/src/types.ts CHANGED
@@ -60,7 +60,8 @@ export interface ChildRunDetails {
60
60
  export interface ReviewContext {
61
61
  repoRoot: string;
62
62
  currentRef: string;
63
- baseBranch: "main" | "master" | "dev";
63
+ baseBranch: string;
64
+ baseSource: "parent" | "fallback";
64
65
  mergeBase: string;
65
66
  baseTip: string;
66
67
  status: string;