@howaboua/pi-subagent-review 0.2.18 → 0.2.19

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @howaboua/pi-subagent-review
2
2
 
3
+ ## 0.2.19
4
+
5
+ ### Changes
6
+
7
+ - [#314](https://github.com/IgorWarzocha/howaboua-pi-stuff/pull/314) [`536910d`](https://github.com/IgorWarzocha/howaboua-pi-stuff/commit/536910d3b0a89f1caaa7a37844bdb80b62c1f844) Thanks [@IgorWarzocha](https://github.com/IgorWarzocha)! - Review a focused JJ revision when its workspace cursor is an empty child commit.
8
+
3
9
  ## 0.2.18
4
10
 
5
11
  ### Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howaboua/pi-subagent-review",
3
- "version": "0.2.18",
3
+ "version": "0.2.19",
4
4
  "description": "Pi extension that adds /review via an isolated review subagent.",
5
5
  "type": "module",
6
6
  "main": "index.ts",
package/src/messages.ts CHANGED
@@ -108,8 +108,17 @@ function buildJjReviewScopeText(
108
108
  : "(root revision)";
109
109
  return [
110
110
  "for JJ workspace " + review.repoRoot,
111
- "active change ID: " + review.changeId,
112
- "active commit ID: " + review.commitId,
111
+ ...(review.workspaceChangeId && review.workspaceCommitId
112
+ ? [
113
+ "active empty workspace change ID: " + review.workspaceChangeId,
114
+ "active empty workspace commit ID: " + review.workspaceCommitId,
115
+ "review parent change ID: " + review.changeId,
116
+ "review parent commit ID: " + review.commitId,
117
+ ]
118
+ : [
119
+ "active change ID: " + review.changeId,
120
+ "active commit ID: " + review.commitId,
121
+ ]),
113
122
  "direct parent change ID" +
114
123
  (review.parentChangeIds.length === 1 ? "" : "s") +
115
124
  ": " +
@@ -100,6 +100,15 @@ export function registerReviewCommand(
100
100
  }
101
101
  }
102
102
 
103
+ if (!review.hasAnyChanges) {
104
+ ctx.ui.notify(
105
+ review.vcs === "jj"
106
+ ? "No changes found in the active JJ revision or its immediate parent."
107
+ : "No changes found relative to the selected base branch.",
108
+ "info",
109
+ );
110
+ return;
111
+ }
103
112
  sendReviewPreface(pi, ctx, { freshLoop: parsedArgs.startLoop });
104
113
 
105
114
  if (parsedArgs.startLoop) {
@@ -116,24 +125,6 @@ export function registerReviewCommand(
116
125
  }
117
126
  }
118
127
 
119
- if (!review.hasAnyChanges) {
120
- sendReviewFindings(
121
- pi,
122
- ctx,
123
- review,
124
- review.vcs === "jj"
125
- ? "No changes found in the active JJ revision."
126
- : "No changes found relative to the selected base branch.",
127
- );
128
- ctx.ui.notify(
129
- review.vcs === "jj"
130
- ? "No changes found in the active JJ revision; sent summary to the agent."
131
- : `No changes found relative to ${review.baseBranch}; sent summary to the agent.`,
132
- "info",
133
- );
134
- return;
135
- }
136
-
137
128
  reviewConfig ??= await resolveReviewConfig(pi, ctx);
138
129
  let conversationSummary: string | undefined;
139
130
  let details = createChildRunDetails("", review.repoRoot, reviewConfig);
@@ -152,74 +152,135 @@ async function resolveSingleJjRevision(
152
152
  return { changeId: lines[0], commitId: lines[1] };
153
153
  }
154
154
 
155
- async function detectJjReviewContext(
155
+ interface JjRevision {
156
+ changeId: string;
157
+ commitId: string;
158
+ parentChangeIds: string[];
159
+ parentCommitIds: string[];
160
+ }
161
+
162
+ async function readJjRevision(
156
163
  pi: ExtensionAPI,
157
- repoRoot: string,
158
- stackBase?: string,
159
- ): Promise<JjReviewContext> {
160
- const active = await jjString(pi, repoRoot, [
164
+ cwd: string,
165
+ revision: string,
166
+ ): Promise<JjRevision> {
167
+ const output = await jjString(pi, cwd, [
161
168
  "log",
162
169
  "-r",
163
- "@",
170
+ revision,
164
171
  "--no-graph",
165
172
  "--template",
166
173
  'change_id ++ "\\n" ++ commit_id ++ "\\n" ++ parents.map(|p| p.change_id()).join(",") ++ "\\n" ++ parents.map(|p| p.commit_id()).join(",") ++ "\\n" ++ if(conflict, "true", "false") ++ "\\n"',
167
174
  ]);
168
175
  const [changeId, commitId, parentChanges = "", parentCommits = "", conflict] =
169
- active.split("\n");
170
- if (!changeId || !commitId || !conflict)
171
- throw new Error("Could not identify the active JJ revision for /review.");
176
+ output.split("\n");
177
+ if (!changeId || !commitId || !conflict) {
178
+ throw new Error("Could not identify the selected JJ revision for /review.");
179
+ }
172
180
  if (conflict === "true") {
173
181
  throw new Error(
174
- `Active JJ revision ${changeId} (${commitId}) has conflicts. Resolve them before running /review.`,
182
+ "JJ revision " +
183
+ changeId +
184
+ " (" +
185
+ commitId +
186
+ ") has conflicts. Resolve them before running /review.",
175
187
  );
176
188
  }
189
+ return {
190
+ changeId,
191
+ commitId,
192
+ parentChangeIds: parentChanges ? parentChanges.split(",") : [],
193
+ parentCommitIds: parentCommits ? parentCommits.split(",") : [],
194
+ };
195
+ }
177
196
 
178
- const parentChangeIds = parentChanges ? parentChanges.split(",") : [];
179
- const parentCommitIds = parentCommits ? parentCommits.split(",") : [];
197
+ async function jjDiffSummary(
198
+ pi: ExtensionAPI,
199
+ cwd: string,
200
+ commitId: string,
201
+ baseCommitId?: string,
202
+ ): Promise<string> {
203
+ return jjString(
204
+ pi,
205
+ cwd,
206
+ baseCommitId
207
+ ? ["diff", "--from", baseCommitId, "--to", commitId, "--summary"]
208
+ : ["diff", "-r", commitId, "--summary"],
209
+ );
210
+ }
211
+
212
+ async function detectJjReviewContext(
213
+ pi: ExtensionAPI,
214
+ repoRoot: string,
215
+ stackBase?: string,
216
+ ): Promise<JjReviewContext> {
217
+ const active = await readJjRevision(pi, repoRoot, "@");
218
+ let target = active;
180
219
  let base:
181
220
  | { revision: string; changeId: string; commitId: string }
182
221
  | undefined;
183
222
  if (stackBase) {
184
223
  const resolved = await resolveSingleJjRevision(pi, repoRoot, stackBase);
185
- if (resolved.commitId === commitId) {
224
+ if (resolved.commitId === active.commitId) {
186
225
  throw new Error(
187
- `JJ review stack base ${JSON.stringify(stackBase)} is the active revision. Choose an ancestor instead.`,
226
+ "JJ review stack base " +
227
+ JSON.stringify(stackBase) +
228
+ " is the active revision. Choose an ancestor instead.",
188
229
  );
189
230
  }
190
231
  const ancestor = await jjString(pi, repoRoot, [
191
232
  "log",
192
233
  "-r",
193
- `ancestors(${commitId}) & ${resolved.commitId}`,
234
+ ["ancestors(", active.commitId, ") & ", resolved.commitId].join(""),
194
235
  "--no-graph",
195
236
  "--template",
196
237
  "commit_id",
197
238
  ]);
198
239
  if (ancestor !== resolved.commitId) {
199
240
  throw new Error(
200
- `JJ review stack base ${JSON.stringify(stackBase)} must be an ancestor of active revision ${changeId}.`,
241
+ "JJ review stack base " +
242
+ JSON.stringify(stackBase) +
243
+ " must be an ancestor of active revision " +
244
+ active.changeId +
245
+ ".",
201
246
  );
202
247
  }
203
248
  base = { revision: stackBase, ...resolved };
204
249
  }
205
250
 
206
- const changedFiles = await jjString(
251
+ let changedFiles = await jjDiffSummary(
207
252
  pi,
208
253
  repoRoot,
209
- base
210
- ? ["diff", "--from", base.commitId, "--to", commitId, "--summary"]
211
- : ["diff", "-r", commitId, "--summary"],
254
+ target.commitId,
255
+ base?.commitId,
212
256
  );
257
+ if (!base && !changedFiles && active.parentCommitIds.length === 1) {
258
+ const parentCommitId = active.parentCommitIds[0];
259
+ if (parentCommitId) {
260
+ const parent = await readJjRevision(pi, repoRoot, parentCommitId);
261
+ const parentChanges = await jjDiffSummary(pi, repoRoot, parent.commitId);
262
+ if (parentChanges) {
263
+ target = parent;
264
+ changedFiles = parentChanges;
265
+ }
266
+ }
267
+ }
213
268
 
214
269
  return {
215
270
  vcs: "jj",
216
271
  repoRoot,
217
- currentRef: changeId,
272
+ currentRef: target.changeId,
218
273
  scope: base ? "jj-base" : "jj-parent",
219
- changeId,
220
- commitId,
221
- parentChangeIds,
222
- parentCommitIds,
274
+ changeId: target.changeId,
275
+ commitId: target.commitId,
276
+ parentChangeIds: target.parentChangeIds,
277
+ parentCommitIds: target.parentCommitIds,
278
+ ...(target.commitId !== active.commitId
279
+ ? {
280
+ workspaceChangeId: active.changeId,
281
+ workspaceCommitId: active.commitId,
282
+ }
283
+ : {}),
223
284
  ...(base
224
285
  ? {
225
286
  baseRevision: base.revision,
@@ -232,7 +293,6 @@ async function detectJjReviewContext(
232
293
  hasAnyChanges: changedFiles.length > 0,
233
294
  };
234
295
  }
235
-
236
296
  async function detectGitReviewContext(
237
297
  pi: ExtensionAPI,
238
298
  cwd: string,
@@ -125,8 +125,17 @@ function buildJjReviewTask(
125
125
  : "(root revision)";
126
126
  const sections = [
127
127
  "JJ workspace root: " + review.repoRoot,
128
- "Active change ID: " + review.changeId,
129
- "Active commit ID: " + review.commitId,
128
+ ...(review.workspaceChangeId && review.workspaceCommitId
129
+ ? [
130
+ "Active empty workspace change ID: " + review.workspaceChangeId,
131
+ "Active empty workspace commit ID: " + review.workspaceCommitId,
132
+ "Review parent change ID: " + review.changeId,
133
+ "Review parent commit ID: " + review.commitId,
134
+ ]
135
+ : [
136
+ "Active change ID: " + review.changeId,
137
+ "Active commit ID: " + review.commitId,
138
+ ]),
130
139
  "Direct parent commit ID" +
131
140
  (review.parentCommitIds.length === 1 ? "" : "s") +
132
141
  ": " +
package/src/types.ts CHANGED
@@ -86,6 +86,8 @@ export interface JjReviewContext {
86
86
  commitId: string;
87
87
  parentChangeIds: string[];
88
88
  parentCommitIds: string[];
89
+ workspaceChangeId?: string;
90
+ workspaceCommitId?: string;
89
91
  baseRevision?: string;
90
92
  baseChangeId?: string;
91
93
  baseCommitId?: string;