@howaboua/pi-subagent-review 0.2.1 → 0.2.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howaboua/pi-subagent-review",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
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
@@ -6,6 +6,7 @@ import { REVIEW_COMMAND } from "./constants.js";
6
6
  import type { ReviewContext } from "./types.js";
7
7
 
8
8
  export const REVIEW_LOOP_PREFACE_MESSAGE_TYPE = "subagent-review-preface";
9
+ export const REVIEW_FINDINGS_MESSAGE_TYPE = "subagent-review-findings";
9
10
 
10
11
  export const REVIEW_LOOP_PREFACE_MESSAGE = [
11
12
  "Review advisory note.",
@@ -17,22 +18,30 @@ export const REVIEW_LOOP_PREFACE_MESSAGE = [
17
18
  "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
19
  ].join("\n");
19
20
 
20
- function hasReviewPrefaceMessage(ctx: ExtensionCommandContext): boolean {
21
- return ctx.sessionManager.getBranch().some((entry) => {
22
- return (
21
+ function getReviewPrefaceMessageId(
22
+ ctx: ExtensionCommandContext,
23
+ ): string | undefined {
24
+ let messageId: string | undefined;
25
+ for (const entry of ctx.sessionManager.getBranch()) {
26
+ if (
23
27
  entry.type === "custom_message" &&
24
28
  entry.customType === REVIEW_LOOP_PREFACE_MESSAGE_TYPE
25
- );
26
- });
29
+ ) {
30
+ messageId = entry.id;
31
+ }
32
+ }
33
+ return messageId;
27
34
  }
28
35
 
29
36
  export function sendReviewPrefaceOnce(
30
37
  pi: ExtensionAPI,
31
38
  ctx: ExtensionCommandContext,
32
39
  details: { markerId?: string } = {},
33
- ): void {
34
- if (hasReviewPrefaceMessage(ctx)) return;
40
+ ): { inserted: boolean; entryId?: string } {
41
+ const existingId = getReviewPrefaceMessageId(ctx);
42
+ if (existingId) return { inserted: false, entryId: existingId };
35
43
 
44
+ const previousLeafId = ctx.sessionManager.getLeafId();
36
45
  pi.sendMessage(
37
46
  {
38
47
  customType: REVIEW_LOOP_PREFACE_MESSAGE_TYPE,
@@ -42,6 +51,12 @@ export function sendReviewPrefaceOnce(
42
51
  },
43
52
  { triggerTurn: false },
44
53
  );
54
+
55
+ const nextLeafId = ctx.sessionManager.getLeafId();
56
+ if (nextLeafId && nextLeafId !== previousLeafId) {
57
+ return { inserted: true, entryId: nextLeafId };
58
+ }
59
+ return { inserted: true };
45
60
  }
46
61
 
47
62
  export function buildReviewScopeText(review: ReviewContext): string {
@@ -72,3 +87,20 @@ export function buildReviewUserMessage(
72
87
  "If you address, skip, or defer findings, briefly say why.",
73
88
  ].join("\n");
74
89
  }
90
+
91
+ export function sendReviewFindings(
92
+ pi: ExtensionAPI,
93
+ ctx: ExtensionCommandContext,
94
+ review: ReviewContext,
95
+ findings: string,
96
+ ): void {
97
+ pi.sendMessage(
98
+ {
99
+ customType: REVIEW_FINDINGS_MESSAGE_TYPE,
100
+ content: buildReviewUserMessage(review, findings),
101
+ display: true,
102
+ details: { repoRoot: review.repoRoot, scope: review.scope },
103
+ },
104
+ ctx.isIdle() ? { triggerTurn: true } : { deliverAs: "followUp" },
105
+ );
106
+ }
@@ -6,9 +6,10 @@ 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";
9
+ import { sendReviewFindings, sendReviewPrefaceOnce } from "./messages.js";
10
10
  import { buildReviewTask, detectReviewContext } from "./review.js";
11
11
  import {
12
+ appendReviewLoopBoundary,
12
13
  applyReviewLoopMarker,
13
14
  getSemanticLeafId,
14
15
  parseReviewArgs,
@@ -20,10 +21,9 @@ import { getFinalOutput, runReviewSubagent } from "./subagent.js";
20
21
  export function registerReviewCommand(pi: ExtensionAPI) {
21
22
  pi.registerCommand(REVIEW_COMMAND, {
22
23
  description:
23
- "Run an isolated code-review subagent against the current repo and send the findings back as a user message",
24
+ "Run an isolated code-review subagent against the current repo and send advisory findings back as custom review output",
24
25
  handler: async (args, ctx) => {
25
26
  const parsedArgs = parseReviewArgs(args);
26
- const reviewPrefaceDetails: { markerId?: string } = {};
27
27
  const setReviewWidget = (message?: string) => {
28
28
  ctx.ui.setWidget(
29
29
  REVIEW_COMMAND,
@@ -72,10 +72,12 @@ export function registerReviewCommand(pi: ExtensionAPI) {
72
72
  return;
73
73
  }
74
74
 
75
+ sendReviewPrefaceOnce(pi, ctx);
76
+
75
77
  if (parsedArgs.startLoop) {
76
- const targetId = getSemanticLeafId(ctx);
78
+ const targetId =
79
+ appendReviewLoopBoundary(pi, ctx) ?? getSemanticLeafId(ctx);
77
80
  if (targetId) {
78
- reviewPrefaceDetails.markerId = targetId;
79
81
  applyReviewLoopMarker(
80
82
  pi,
81
83
  ctx,
@@ -85,14 +87,13 @@ export function registerReviewCommand(pi: ExtensionAPI) {
85
87
  ctx.ui.notify("Review loop marker set", "info");
86
88
  }
87
89
  }
88
- sendReviewPrefaceOnce(pi, ctx, reviewPrefaceDetails);
89
90
 
90
91
  if (!review.hasAnyChanges) {
91
- pi.sendUserMessage(
92
- buildReviewUserMessage(
93
- review,
94
- "No changes found relative to the selected base branch.",
95
- ),
92
+ sendReviewFindings(
93
+ pi,
94
+ ctx,
95
+ review,
96
+ "No changes found relative to the selected base branch.",
96
97
  );
97
98
  ctx.ui.notify(
98
99
  `No changes found relative to ${review.baseBranch}; sent summary to the agent.`,
@@ -155,9 +156,7 @@ export function registerReviewCommand(pi: ExtensionAPI) {
155
156
  details.errorMessage || details.stderr || finalOutput,
156
157
  );
157
158
 
158
- const message = buildReviewUserMessage(review, finalOutput);
159
- if (ctx.isIdle()) pi.sendUserMessage(message);
160
- else pi.sendUserMessage(message, { deliverAs: "followUp" });
159
+ sendReviewFindings(pi, ctx, review, finalOutput);
161
160
  ctx.ui.notify(
162
161
  `Review findings sent back to the main agent from /${REVIEW_COMMAND}.`,
163
162
  "info",
@@ -4,6 +4,7 @@ import type {
4
4
  } from "@earendil-works/pi-coding-agent";
5
5
 
6
6
  export const REVIEW_LOOP_STATE_ENTRY = "subagent-review-loop-state";
7
+ export const REVIEW_LOOP_BOUNDARY_ENTRY = "subagent-review-loop-boundary";
7
8
  export const REVIEW_LOOP_MARKER_LABEL = "review";
8
9
  export const REVIEW_LOOP_WIDGET = "subagent-review-loop";
9
10
  export const REVIEW_LOOP_SUMMARY_PROMPT = [
@@ -106,6 +107,16 @@ export function applyReviewLoopMarker(
106
107
  } satisfies ReviewLoopState);
107
108
  }
108
109
 
110
+ export function appendReviewLoopBoundary(
111
+ pi: ExtensionAPI,
112
+ ctx: ExtensionCommandContext,
113
+ ): string | undefined {
114
+ const previousLeafId = ctx.sessionManager.getLeafId();
115
+ pi.appendEntry(REVIEW_LOOP_BOUNDARY_ENTRY, { version: 1 });
116
+ const nextLeafId = ctx.sessionManager.getLeafId();
117
+ return nextLeafId && nextLeafId !== previousLeafId ? nextLeafId : undefined;
118
+ }
119
+
109
120
  export async function summarizeReviewLoopIncrement(
110
121
  pi: ExtensionAPI,
111
122
  ctx: ExtensionCommandContext,