@howaboua/pi-subagent-review 0.2.0 → 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 +8 -6
- package/src/messages.ts +39 -7
- package/src/review-command.ts +13 -14
- package/src/review-loop.ts +11 -0
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howaboua/pi-subagent-review",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
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.
|
|
39
|
-
"@earendil-works/pi-coding-agent": "^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.
|
|
51
|
-
"@earendil-works/pi-coding-agent": "^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"
|
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
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
):
|
|
34
|
-
|
|
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
|
+
}
|
package/src/review-command.ts
CHANGED
|
@@ -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 {
|
|
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
|
|
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 =
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
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",
|
package/src/review-loop.ts
CHANGED
|
@@ -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,
|