@howaboua/pi-subagent-review 0.1.52 → 0.2.0
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 +16 -4
- package/biome.json +31 -0
- package/package.json +57 -47
- package/src/config.ts +97 -22
- package/src/constants.ts +13 -3
- package/src/conversation-summary.ts +38 -18
- package/src/messages.ts +74 -0
- package/src/review-command.ts +109 -20
- package/src/review-loop.ts +152 -0
- package/src/review.ts +212 -152
- package/src/subagent.ts +72 -15
- package/src/types.ts +16 -7
- package/tsconfig.json +4 -0
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…`
|
|
@@ -29,24 +40,25 @@ The widget is UI-only and is cleared when the command finishes, fails, or is can
|
|
|
29
40
|
|
|
30
41
|
The command chooses the base branch automatically:
|
|
31
42
|
|
|
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
|
|
35
43
|
- if you are on a branch other than `main`, `master`, or `dev`, it reviews against `dev`
|
|
36
44
|
- if no local `dev` exists, it falls back to `main`, then `master`
|
|
37
45
|
- if you are on `dev`, it reviews against `main`, then `master`
|
|
38
46
|
- if you are on `main` or `master`, it prefers `dev` when available
|
|
39
47
|
|
|
40
|
-
This
|
|
48
|
+
This means you usually never need to specify the diff base manually.
|
|
41
49
|
|
|
42
50
|
## User arguments
|
|
43
51
|
|
|
44
52
|
Anything after `/review` is treated as extra review guidance.
|
|
45
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
|
+
|
|
46
56
|
Examples:
|
|
47
57
|
|
|
48
58
|
```text
|
|
49
59
|
/review
|
|
60
|
+
/review loop
|
|
61
|
+
/review LoOp focus extra attention on migrations and tests
|
|
50
62
|
/review focus extra attention on migrations and tests
|
|
51
63
|
/review assess whether we introduced new UI elements instead of reusing established components and existing CSS patterns
|
|
52
64
|
```
|
package/biome.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.4.16/schema.json",
|
|
3
|
+
"vcs": {
|
|
4
|
+
"enabled": true,
|
|
5
|
+
"clientKind": "git",
|
|
6
|
+
"useIgnoreFile": true
|
|
7
|
+
},
|
|
8
|
+
"files": {
|
|
9
|
+
"includes": [
|
|
10
|
+
"**",
|
|
11
|
+
"!node_modules",
|
|
12
|
+
"!dist",
|
|
13
|
+
"!coverage",
|
|
14
|
+
"!package-lock.json"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"formatter": {
|
|
18
|
+
"enabled": true,
|
|
19
|
+
"indentStyle": "tab"
|
|
20
|
+
},
|
|
21
|
+
"linter": {
|
|
22
|
+
"enabled": false
|
|
23
|
+
},
|
|
24
|
+
"javascript": {
|
|
25
|
+
"formatter": {
|
|
26
|
+
"quoteStyle": "double",
|
|
27
|
+
"semicolons": "always",
|
|
28
|
+
"trailingCommas": "all"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,49 +1,59 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
2
|
+
"name": "@howaboua/pi-subagent-review",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Pi extension that adds /review via an isolated review subagent.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"index.ts",
|
|
8
|
+
"src",
|
|
9
|
+
"review.prompt.md",
|
|
10
|
+
"README.md",
|
|
11
|
+
"tsconfig.json",
|
|
12
|
+
"biome.json"
|
|
13
|
+
],
|
|
14
|
+
"keywords": [
|
|
15
|
+
"pi-package",
|
|
16
|
+
"pi",
|
|
17
|
+
"pi-extension",
|
|
18
|
+
"review",
|
|
19
|
+
"code-review",
|
|
20
|
+
"subagent",
|
|
21
|
+
"agent"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/IgorWarzocha/howaboua-pi-stuff.git",
|
|
26
|
+
"directory": "packages/pi-subagent-review"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/IgorWarzocha/howaboua-pi-stuff/tree/main/packages/pi-subagent-review#readme",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/IgorWarzocha/howaboua-pi-stuff/issues"
|
|
31
|
+
},
|
|
32
|
+
"pi": {
|
|
33
|
+
"extensions": [
|
|
34
|
+
"./index.ts"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@earendil-works/pi-ai": "^0.76.0",
|
|
39
|
+
"@earendil-works/pi-coding-agent": "^0.76.0"
|
|
40
|
+
},
|
|
41
|
+
"type": "module",
|
|
42
|
+
"scripts": {
|
|
43
|
+
"check": "bun run lint && bun run typecheck",
|
|
44
|
+
"prepack": "bun run check",
|
|
45
|
+
"typecheck": "tsgo --noEmit",
|
|
46
|
+
"lint": "biome check .",
|
|
47
|
+
"format": "biome check --write ."
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@earendil-works/pi-ai": "^0.76.0",
|
|
51
|
+
"@earendil-works/pi-coding-agent": "^0.76.0",
|
|
52
|
+
"@types/node": "^24.10.0",
|
|
53
|
+
"typescript": "^5.9.3",
|
|
54
|
+
"@biomejs/biome": "^2.4.16"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
}
|
|
49
59
|
}
|
package/src/config.ts
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import type {
|
|
3
|
+
ExtensionAPI,
|
|
4
|
+
ExtensionCommandContext,
|
|
5
|
+
} from "@earendil-works/pi-coding-agent";
|
|
6
|
+
import {
|
|
7
|
+
ALLOWED_THINKING,
|
|
8
|
+
DEFAULT_CONFIG,
|
|
9
|
+
getAgentDir,
|
|
10
|
+
getConfigPath,
|
|
11
|
+
REVIEW_COMMAND,
|
|
12
|
+
} from "./constants.js";
|
|
13
|
+
import type {
|
|
14
|
+
ChildRunDetails,
|
|
15
|
+
ParsedModelRef,
|
|
16
|
+
ResolvedReviewConfig,
|
|
17
|
+
ReviewConfig,
|
|
18
|
+
ThinkingLevel,
|
|
19
|
+
UsageStats,
|
|
20
|
+
} from "./types.js";
|
|
21
|
+
|
|
22
|
+
function normalizeThinking(
|
|
23
|
+
value: ThinkingLevel | undefined,
|
|
24
|
+
fallback: ThinkingLevel = DEFAULT_CONFIG.thinking,
|
|
25
|
+
): ThinkingLevel {
|
|
7
26
|
return value && ALLOWED_THINKING.has(value) ? value : fallback;
|
|
8
27
|
}
|
|
9
28
|
|
|
@@ -17,7 +36,10 @@ function migrateConfigFile(configPath: string): void {
|
|
|
17
36
|
|
|
18
37
|
if (parsed.summary !== undefined) return;
|
|
19
38
|
|
|
20
|
-
const reviewModel =
|
|
39
|
+
const reviewModel =
|
|
40
|
+
typeof parsed.model === "string" && parsed.model.trim()
|
|
41
|
+
? parsed.model.trim()
|
|
42
|
+
: DEFAULT_CONFIG.model;
|
|
21
43
|
const migrated: ReviewConfig = {
|
|
22
44
|
...parsed,
|
|
23
45
|
summary: {
|
|
@@ -26,7 +48,11 @@ function migrateConfigFile(configPath: string): void {
|
|
|
26
48
|
thinking: DEFAULT_CONFIG.summary.thinking,
|
|
27
49
|
},
|
|
28
50
|
};
|
|
29
|
-
fs.writeFileSync(
|
|
51
|
+
fs.writeFileSync(
|
|
52
|
+
configPath,
|
|
53
|
+
`${JSON.stringify(migrated, null, 2)}\n`,
|
|
54
|
+
"utf8",
|
|
55
|
+
);
|
|
30
56
|
}
|
|
31
57
|
|
|
32
58
|
export function ensureConfigFile(): string {
|
|
@@ -34,7 +60,11 @@ export function ensureConfigFile(): string {
|
|
|
34
60
|
const configPath = getConfigPath();
|
|
35
61
|
fs.mkdirSync(agentDir, { recursive: true });
|
|
36
62
|
if (!fs.existsSync(configPath)) {
|
|
37
|
-
fs.writeFileSync(
|
|
63
|
+
fs.writeFileSync(
|
|
64
|
+
configPath,
|
|
65
|
+
`${JSON.stringify(DEFAULT_CONFIG, null, 2)}\n`,
|
|
66
|
+
"utf8",
|
|
67
|
+
);
|
|
38
68
|
} else {
|
|
39
69
|
migrateConfigFile(configPath);
|
|
40
70
|
}
|
|
@@ -47,34 +77,63 @@ export function readConfig(): Omit<ResolvedReviewConfig, "source"> {
|
|
|
47
77
|
try {
|
|
48
78
|
parsed = JSON.parse(fs.readFileSync(configPath, "utf8")) as ReviewConfig;
|
|
49
79
|
} catch (error) {
|
|
50
|
-
throw new Error(
|
|
80
|
+
throw new Error(
|
|
81
|
+
`Could not parse ${configPath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
82
|
+
);
|
|
51
83
|
}
|
|
52
84
|
|
|
53
|
-
const reviewModel =
|
|
85
|
+
const reviewModel =
|
|
86
|
+
typeof parsed?.model === "string" && parsed.model.trim()
|
|
87
|
+
? parsed.model.trim()
|
|
88
|
+
: DEFAULT_CONFIG.model;
|
|
54
89
|
const summary = parsed?.summary;
|
|
55
|
-
const configuredSummaryModel =
|
|
56
|
-
|
|
57
|
-
|
|
90
|
+
const configuredSummaryModel =
|
|
91
|
+
typeof summary?.model === "string" && summary.model.trim()
|
|
92
|
+
? summary.model.trim()
|
|
93
|
+
: reviewModel;
|
|
94
|
+
const defaultSummaryModelParsed = splitModelRef(
|
|
95
|
+
DEFAULT_CONFIG.summary.model,
|
|
96
|
+
)!;
|
|
97
|
+
const summaryModelParsed =
|
|
98
|
+
splitModelRef(configuredSummaryModel) ?? defaultSummaryModelParsed;
|
|
58
99
|
const summaryModel = `${summaryModelParsed.provider}/${summaryModelParsed.modelId}`;
|
|
59
100
|
|
|
60
101
|
return {
|
|
61
102
|
model: reviewModel,
|
|
62
103
|
thinking: normalizeThinking(parsed?.thinking),
|
|
63
104
|
summary: {
|
|
64
|
-
enabled:
|
|
105
|
+
enabled:
|
|
106
|
+
typeof summary?.enabled === "boolean"
|
|
107
|
+
? summary.enabled
|
|
108
|
+
: DEFAULT_CONFIG.summary.enabled,
|
|
65
109
|
model: summaryModel,
|
|
66
110
|
modelParsed: summaryModelParsed,
|
|
67
|
-
thinking: normalizeThinking(
|
|
111
|
+
thinking: normalizeThinking(
|
|
112
|
+
summary?.thinking,
|
|
113
|
+
DEFAULT_CONFIG.summary.thinking,
|
|
114
|
+
),
|
|
68
115
|
source: "configured",
|
|
69
116
|
},
|
|
70
117
|
};
|
|
71
118
|
}
|
|
72
119
|
|
|
73
120
|
function emptyUsage(): UsageStats {
|
|
74
|
-
return {
|
|
121
|
+
return {
|
|
122
|
+
input: 0,
|
|
123
|
+
output: 0,
|
|
124
|
+
cacheRead: 0,
|
|
125
|
+
cacheWrite: 0,
|
|
126
|
+
cost: 0,
|
|
127
|
+
contextTokens: 0,
|
|
128
|
+
turns: 0,
|
|
129
|
+
};
|
|
75
130
|
}
|
|
76
131
|
|
|
77
|
-
export function createChildRunDetails(
|
|
132
|
+
export function createChildRunDetails(
|
|
133
|
+
task: string,
|
|
134
|
+
cwd: string,
|
|
135
|
+
config = readConfig(),
|
|
136
|
+
): ChildRunDetails {
|
|
78
137
|
return {
|
|
79
138
|
mode: "review",
|
|
80
139
|
toolName: REVIEW_COMMAND,
|
|
@@ -89,8 +148,14 @@ export function createChildRunDetails(task: string, cwd: string, config = readCo
|
|
|
89
148
|
};
|
|
90
149
|
}
|
|
91
150
|
|
|
92
|
-
export function isSubagentFailure(
|
|
93
|
-
|
|
151
|
+
export function isSubagentFailure(
|
|
152
|
+
details: Pick<ChildRunDetails, "exitCode" | "stopReason">,
|
|
153
|
+
): boolean {
|
|
154
|
+
return (
|
|
155
|
+
details.exitCode !== 0 ||
|
|
156
|
+
details.stopReason === "error" ||
|
|
157
|
+
details.stopReason === "aborted"
|
|
158
|
+
);
|
|
94
159
|
}
|
|
95
160
|
|
|
96
161
|
function splitModelRef(modelRef: string): ParsedModelRef | undefined {
|
|
@@ -102,7 +167,10 @@ function splitModelRef(modelRef: string): ParsedModelRef | undefined {
|
|
|
102
167
|
};
|
|
103
168
|
}
|
|
104
169
|
|
|
105
|
-
async function canUseModel(
|
|
170
|
+
async function canUseModel(
|
|
171
|
+
ctx: ExtensionCommandContext,
|
|
172
|
+
modelRef: string,
|
|
173
|
+
): Promise<boolean> {
|
|
106
174
|
const parsed = splitModelRef(modelRef);
|
|
107
175
|
if (!parsed) return false;
|
|
108
176
|
const model = ctx.modelRegistry.find(parsed.provider, parsed.modelId);
|
|
@@ -111,11 +179,18 @@ async function canUseModel(ctx: ExtensionCommandContext, modelRef: string): Prom
|
|
|
111
179
|
return auth.ok;
|
|
112
180
|
}
|
|
113
181
|
|
|
114
|
-
export async function resolveReviewConfig(
|
|
182
|
+
export async function resolveReviewConfig(
|
|
183
|
+
pi: ExtensionAPI,
|
|
184
|
+
ctx: ExtensionCommandContext,
|
|
185
|
+
): Promise<ResolvedReviewConfig> {
|
|
115
186
|
const configured = readConfig();
|
|
116
187
|
let summary = configured.summary;
|
|
117
188
|
|
|
118
|
-
if (
|
|
189
|
+
if (
|
|
190
|
+
summary.enabled &&
|
|
191
|
+
!(await canUseModel(ctx, summary.model)) &&
|
|
192
|
+
ctx.model
|
|
193
|
+
) {
|
|
119
194
|
const auth = await ctx.modelRegistry.getApiKeyAndHeaders(ctx.model);
|
|
120
195
|
if (auth.ok) {
|
|
121
196
|
const currentModel = `${ctx.model.provider}/${ctx.model.id}`;
|
package/src/constants.ts
CHANGED
|
@@ -8,7 +8,10 @@ export const CHILD_ENV = "PI_REVIEW_EXTENSION_CHILD";
|
|
|
8
8
|
export const REVIEW_COMMAND = "review";
|
|
9
9
|
export const REVIEW_LABEL = "Review";
|
|
10
10
|
export const CONFIG_FILENAME = "pi-subagent-review.json";
|
|
11
|
-
export const REVIEW_PROMPT_PATH = path.join(
|
|
11
|
+
export const REVIEW_PROMPT_PATH = path.join(
|
|
12
|
+
path.resolve(__dirname, ".."),
|
|
13
|
+
"review.prompt.md",
|
|
14
|
+
);
|
|
12
15
|
|
|
13
16
|
export const DEFAULT_CONFIG = {
|
|
14
17
|
model: "openai-codex/gpt-5.5",
|
|
@@ -20,14 +23,21 @@ export const DEFAULT_CONFIG = {
|
|
|
20
23
|
},
|
|
21
24
|
} as const;
|
|
22
25
|
|
|
23
|
-
export const ALLOWED_THINKING = new Set([
|
|
26
|
+
export const ALLOWED_THINKING = new Set([
|
|
27
|
+
"off",
|
|
28
|
+
"minimal",
|
|
29
|
+
"low",
|
|
30
|
+
"medium",
|
|
31
|
+
"high",
|
|
32
|
+
"xhigh",
|
|
33
|
+
] as const);
|
|
24
34
|
export const RPC_READY_TIMEOUT_MS = 10_000;
|
|
25
35
|
export const RPC_RESPONSE_TIMEOUT_MS = 30_000;
|
|
26
36
|
export const RPC_POLL_MS = 150;
|
|
27
37
|
export const RPC_QUIESCENCE_MS = 500;
|
|
28
38
|
|
|
29
39
|
export function getAgentDir(): string {
|
|
30
|
-
const configured = process.env
|
|
40
|
+
const configured = process.env["PI_CODING_AGENT_DIR"]?.trim();
|
|
31
41
|
return configured || path.join(os.homedir(), ".pi", "agent");
|
|
32
42
|
}
|
|
33
43
|
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { completeSimple } from "@earendil-works/pi-ai";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
ExtensionCommandContext,
|
|
4
|
+
SessionEntry,
|
|
5
|
+
} from "@earendil-works/pi-coding-agent";
|
|
3
6
|
import type { ResolvedReviewConfig } from "./types.js";
|
|
4
7
|
|
|
5
|
-
|
|
6
8
|
function textFromContent(content: unknown): string {
|
|
7
9
|
if (typeof content === "string") return content;
|
|
8
10
|
if (!Array.isArray(content)) return "";
|
|
9
11
|
return content
|
|
10
12
|
.map((part) => {
|
|
11
|
-
if (
|
|
13
|
+
if (
|
|
14
|
+
part &&
|
|
15
|
+
typeof part === "object" &&
|
|
16
|
+
(part as { type?: unknown }).type === "text"
|
|
17
|
+
) {
|
|
12
18
|
return String((part as { text?: unknown }).text ?? "");
|
|
13
19
|
}
|
|
14
20
|
return "";
|
|
@@ -51,15 +57,19 @@ function buildSummaryInput(entries: SessionEntry[]): string {
|
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
function escapeConversationBlock(conversation: string): string {
|
|
54
|
-
return conversation
|
|
60
|
+
return conversation
|
|
61
|
+
.replaceAll("</conversation>", "</conversation>")
|
|
62
|
+
.replaceAll("<conversation>", "<conversation>");
|
|
55
63
|
}
|
|
56
64
|
|
|
57
65
|
function isNoRelevantContext(summary: string): boolean {
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
return (
|
|
67
|
+
summary
|
|
68
|
+
.trim()
|
|
69
|
+
.toLowerCase()
|
|
70
|
+
.replace(/^#+\s*/, "")
|
|
71
|
+
.replace(/[.!]+$/, "") === "no relevant conversation context"
|
|
72
|
+
);
|
|
63
73
|
}
|
|
64
74
|
|
|
65
75
|
function buildPrompt(conversation: string): string {
|
|
@@ -90,7 +100,10 @@ ${escapeConversationBlock(conversation)}
|
|
|
90
100
|
</conversation>`;
|
|
91
101
|
}
|
|
92
102
|
|
|
93
|
-
export async function buildReviewConversationSummary(
|
|
103
|
+
export async function buildReviewConversationSummary(
|
|
104
|
+
ctx: ExtensionCommandContext,
|
|
105
|
+
config: ResolvedReviewConfig,
|
|
106
|
+
): Promise<string | undefined> {
|
|
94
107
|
if (!config.summary.enabled) return undefined;
|
|
95
108
|
|
|
96
109
|
const conversation = buildSummaryInput(ctx.sessionManager.getBranch());
|
|
@@ -98,10 +111,20 @@ export async function buildReviewConversationSummary(ctx: ExtensionCommandContex
|
|
|
98
111
|
|
|
99
112
|
const parsed = config.summary.modelParsed;
|
|
100
113
|
const model = ctx.modelRegistry.find(parsed.provider, parsed.modelId);
|
|
101
|
-
if (!model)
|
|
114
|
+
if (!model)
|
|
115
|
+
throw new Error(`Summary model not found: ${config.summary.model}`);
|
|
102
116
|
const auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
|
|
103
117
|
if (!auth.ok) throw new Error(`Summary model unavailable: ${auth.error}`);
|
|
104
118
|
|
|
119
|
+
const options = {
|
|
120
|
+
...(auth.apiKey ? { apiKey: auth.apiKey } : {}),
|
|
121
|
+
...(auth.headers ? { headers: auth.headers } : {}),
|
|
122
|
+
...(model.reasoning && config.summary.thinking !== "off"
|
|
123
|
+
? { reasoning: config.summary.thinking }
|
|
124
|
+
: {}),
|
|
125
|
+
...(ctx.signal ? { signal: ctx.signal } : {}),
|
|
126
|
+
};
|
|
127
|
+
|
|
105
128
|
const response = await completeSimple(
|
|
106
129
|
model,
|
|
107
130
|
{
|
|
@@ -113,16 +136,13 @@ export async function buildReviewConversationSummary(ctx: ExtensionCommandContex
|
|
|
113
136
|
},
|
|
114
137
|
],
|
|
115
138
|
},
|
|
116
|
-
|
|
117
|
-
apiKey: auth.apiKey,
|
|
118
|
-
headers: auth.headers,
|
|
119
|
-
reasoning: model.reasoning && config.summary.thinking !== "off" ? config.summary.thinking : undefined,
|
|
120
|
-
signal: ctx.signal,
|
|
121
|
-
},
|
|
139
|
+
options,
|
|
122
140
|
);
|
|
123
141
|
|
|
124
142
|
const summary = response.content
|
|
125
|
-
.filter(
|
|
143
|
+
.filter(
|
|
144
|
+
(part): part is { type: "text"; text: string } => part.type === "text",
|
|
145
|
+
)
|
|
126
146
|
.map((part) => part.text)
|
|
127
147
|
.join("\n")
|
|
128
148
|
.trim();
|
package/src/messages.ts
ADDED
|
@@ -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
|
+
}
|