co-maintainer 0.5.4 → 0.6.1
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/dist/package.json +1 -1
- package/dist/src/ai/batch.d.ts +19 -16
- package/dist/src/ai/batch.js +68 -46
- package/dist/src/cli/args.js +2 -2
- package/dist/src/cli/commands/config.d.ts +1 -1
- package/dist/src/cli/commands/config.js +2 -0
- package/dist/src/cli/commands/registry.js +38 -17
- package/dist/src/cli/commands/review.js +2 -1
- package/dist/src/cli/commands/set.js +14 -1
- package/dist/src/cli/review_args.js +1 -0
- package/dist/src/config.d.ts +4 -0
- package/dist/src/github/collect.js +19 -1
- package/dist/src/knowledge/guide.d.ts +19 -4
- package/dist/src/knowledge/guide.js +222 -87
- package/dist/src/knowledge/skill.d.ts +4 -5
- package/dist/src/knowledge/skill.js +27 -35
- package/dist/src/knowledge/synthesis.d.ts +0 -13
- package/dist/src/knowledge/synthesis.js +176 -84
- package/dist/src/knowledge/types.d.ts +22 -0
- package/dist/src/pr/codegraph_tools.d.ts +13 -3
- package/dist/src/pr/codegraph_tools.js +26 -7
- package/dist/src/pr/reviewer.d.ts +4 -0
- package/dist/src/pr/reviewer.js +12 -1
- package/dist/src/services/remote_review.js +1 -1
- package/dist/src/services/review.js +1 -1
- package/dist/src/services/setup.js +63 -53
- package/dist/src/tools/codegraph.d.ts +15 -0
- package/dist/src/tools/codegraph.js +59 -24
- package/dist/src/types.d.ts +4 -0
- package/package.json +1 -1
|
@@ -19,40 +19,95 @@ function slug(value) {
|
|
|
19
19
|
function promptText(value, limit = 6_000) {
|
|
20
20
|
return value.length > limit ? `${value.slice(0, limit)}\n[truncated]` : value;
|
|
21
21
|
}
|
|
22
|
+
function tryParse(value) {
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(value);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** Every balanced top-level `[...]` in the text, string-aware so a `[` inside a
|
|
31
|
+
* string does not shift the depth. */
|
|
32
|
+
function balancedArrays(text) {
|
|
33
|
+
const out = [];
|
|
34
|
+
let depth = 0;
|
|
35
|
+
let start = -1;
|
|
36
|
+
let inString = false;
|
|
37
|
+
let escape = false;
|
|
38
|
+
for (let index = 0; index < text.length; index++) {
|
|
39
|
+
const char = text[index];
|
|
40
|
+
if (inString) {
|
|
41
|
+
if (escape)
|
|
42
|
+
escape = false;
|
|
43
|
+
else if (char === "\\")
|
|
44
|
+
escape = true;
|
|
45
|
+
else if (char === '"')
|
|
46
|
+
inString = false;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (char === '"')
|
|
50
|
+
inString = true;
|
|
51
|
+
else if (char === "[") {
|
|
52
|
+
if (depth === 0)
|
|
53
|
+
start = index;
|
|
54
|
+
depth++;
|
|
55
|
+
}
|
|
56
|
+
else if (char === "]" && depth > 0) {
|
|
57
|
+
depth--;
|
|
58
|
+
if (depth === 0 && start >= 0) {
|
|
59
|
+
out.push(text.slice(start, index + 1));
|
|
60
|
+
start = -1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
22
66
|
function parseJson(text) {
|
|
23
67
|
const cleaned = text
|
|
24
68
|
.trim()
|
|
25
69
|
.replace(/^```(?:json)?\s*/i, "")
|
|
26
70
|
.replace(/\s*```$/, "");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
71
|
+
const direct = tryParse(cleaned);
|
|
72
|
+
if (direct !== undefined)
|
|
73
|
+
return direct;
|
|
74
|
+
// The model sometimes appends a second array (for example `[]` then the real
|
|
75
|
+
// one), so the first-to-last-bracket slice is wrong. Read every balanced
|
|
76
|
+
// top-level array and prefer the first non-empty one.
|
|
77
|
+
const parsed = balancedArrays(cleaned)
|
|
78
|
+
.map((chunk) => tryParse(chunk))
|
|
79
|
+
.filter((value) => Array.isArray(value));
|
|
80
|
+
const nonEmpty = parsed.find((value) => value.length > 0);
|
|
81
|
+
if (nonEmpty)
|
|
82
|
+
return nonEmpty;
|
|
83
|
+
if (parsed.length)
|
|
84
|
+
return parsed[0];
|
|
85
|
+
// Last resort: repair an array whose final bracket was truncated.
|
|
86
|
+
// Nothing usable: return an empty list rather than throw. A format deviation
|
|
87
|
+
// must not cost the whole run.
|
|
88
|
+
const start = cleaned.indexOf("[");
|
|
89
|
+
if (start < 0)
|
|
90
|
+
return [];
|
|
91
|
+
const lastObject = cleaned.lastIndexOf("}");
|
|
92
|
+
if (lastObject > start) {
|
|
93
|
+
const repaired = tryParse(`${cleaned.slice(start, lastObject + 1)}]`);
|
|
94
|
+
if (repaired !== undefined)
|
|
95
|
+
return repaired;
|
|
42
96
|
}
|
|
97
|
+
return [];
|
|
43
98
|
}
|
|
44
99
|
function factsFromResponse(text, evidence, defaultScope, origin) {
|
|
45
100
|
const parsed = parseJson(text);
|
|
46
|
-
if (!Array.isArray(parsed))
|
|
47
|
-
|
|
48
|
-
}
|
|
101
|
+
if (!Array.isArray(parsed))
|
|
102
|
+
return [];
|
|
49
103
|
return parsed.flatMap((item) => {
|
|
50
104
|
if (!item || typeof item !== "object")
|
|
51
105
|
return [];
|
|
52
106
|
const value = item;
|
|
53
107
|
const claim = String(value.claim ?? "").trim();
|
|
54
108
|
const sectionKey = String(value.sectionKey ?? "").trim();
|
|
55
|
-
|
|
109
|
+
const isReview = sectionKey === "review";
|
|
110
|
+
if (!claim || (!isReview && !allowedSections.has(sectionKey)))
|
|
56
111
|
return [];
|
|
57
112
|
const scope = value.scope === "current" ||
|
|
58
113
|
value.scope === "repeated-history" ||
|
|
@@ -64,6 +119,14 @@ function factsFromResponse(text, evidence, defaultScope, origin) {
|
|
|
64
119
|
value.confidence === "low"
|
|
65
120
|
? value.confidence
|
|
66
121
|
: "medium";
|
|
122
|
+
// A review finding without an impact and an action is the generic advice
|
|
123
|
+
// that made the old guide hollow, so it is dropped rather than stored.
|
|
124
|
+
const impact = String(value.impact ?? "").trim();
|
|
125
|
+
const action = String(value.action ?? "").trim();
|
|
126
|
+
const location = String(value.location ?? "").trim();
|
|
127
|
+
const trigger = String(value.trigger ?? "").trim();
|
|
128
|
+
if (isReview && (!impact || !action))
|
|
129
|
+
return [];
|
|
67
130
|
return [
|
|
68
131
|
{
|
|
69
132
|
id: `${sectionKey}:${slug(claim)}`,
|
|
@@ -75,6 +138,15 @@ function factsFromResponse(text, evidence, defaultScope, origin) {
|
|
|
75
138
|
confidence,
|
|
76
139
|
status: "active",
|
|
77
140
|
origin,
|
|
141
|
+
...(isReview
|
|
142
|
+
? {
|
|
143
|
+
class: String(value.class ?? "general").trim() || "general",
|
|
144
|
+
...(location ? { location } : {}),
|
|
145
|
+
...(trigger ? { trigger } : {}),
|
|
146
|
+
impact,
|
|
147
|
+
action,
|
|
148
|
+
}
|
|
149
|
+
: {}),
|
|
78
150
|
},
|
|
79
151
|
];
|
|
80
152
|
});
|
|
@@ -121,18 +193,34 @@ function pullRequestUnit(pr) {
|
|
|
121
193
|
body: promptText(pr.body),
|
|
122
194
|
labels: pr.labels,
|
|
123
195
|
comments: pr.comments.map((comment) => promptText(comment, 2_000)),
|
|
196
|
+
reviewComments: pr.reviewComments.map((comment) => promptText(comment, 2_000)),
|
|
124
197
|
reviews: pr.reviews.map((review) => promptText(review, 2_000)),
|
|
125
198
|
changedFiles: pr.changedFiles,
|
|
126
199
|
diff: promptText(pr.diff, 8_000),
|
|
127
200
|
});
|
|
128
201
|
}
|
|
129
202
|
function queueFor(provider, repo, ai, model, concurrency, validate) {
|
|
130
|
-
return new AiBatch(provider, repo, Math.max(1, concurrency), `${ai}:
|
|
203
|
+
return new AiBatch(provider, repo, Math.max(1, concurrency), `${ai}:v3:${model}`, validate);
|
|
131
204
|
}
|
|
132
205
|
/** `factsFromResponse` as a validator: `null` when the text parses into facts,
|
|
133
206
|
* otherwise the parse error's message. Used so an unparseable response is never
|
|
134
207
|
* cached. */
|
|
208
|
+
/** Whether the response contains a parseable JSON array at all. `parseJson`
|
|
209
|
+
* returns `[]` for anything it cannot read, so this is the only way to tell an
|
|
210
|
+
* empty-but-valid answer from garbage that must not be cached as a result. */
|
|
211
|
+
function hasJsonArray(text) {
|
|
212
|
+
const cleaned = text
|
|
213
|
+
.trim()
|
|
214
|
+
.replace(/^```(?:json)?\s*/i, "")
|
|
215
|
+
.replace(/\s*```$/, "");
|
|
216
|
+
if (Array.isArray(tryParse(cleaned)))
|
|
217
|
+
return true;
|
|
218
|
+
return balancedArrays(cleaned).some((chunk) => Array.isArray(tryParse(chunk)));
|
|
219
|
+
}
|
|
135
220
|
function validateFacts(response, evidence, defaultScope) {
|
|
221
|
+
if (!hasJsonArray(response.text)) {
|
|
222
|
+
return `${evidence}: AI fact output is not a JSON array`;
|
|
223
|
+
}
|
|
136
224
|
try {
|
|
137
225
|
factsFromResponse(response.text, evidence, defaultScope, "repository");
|
|
138
226
|
return null;
|
|
@@ -142,40 +230,29 @@ function validateFacts(response, evidence, defaultScope) {
|
|
|
142
230
|
return `${evidence}: ${message}`;
|
|
143
231
|
}
|
|
144
232
|
}
|
|
145
|
-
/** `validSection` as a validator: `null` when the section body is usable,
|
|
146
|
-
* otherwise a short reason. A section that is empty or malformed is retried
|
|
147
|
-
* once and then left uncached, so a later `sync` does not replay it. */
|
|
148
|
-
function validateSection(response, key) {
|
|
149
|
-
const section = cleanSection(response.text, key);
|
|
150
|
-
if (!validSection(section, key)) {
|
|
151
|
-
return "synthesis output is not a valid section";
|
|
152
|
-
}
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
233
|
function extractRequest(prompt, maxTokens) {
|
|
156
234
|
return {
|
|
157
235
|
job: "extract_unit",
|
|
158
236
|
prompt,
|
|
159
237
|
maxTokens,
|
|
160
|
-
//
|
|
161
|
-
// the
|
|
162
|
-
|
|
163
|
-
|
|
238
|
+
// Reading a discussion into structured findings is multi-step work: with no
|
|
239
|
+
// thinking the model returned an empty array for most pull requests, so a
|
|
240
|
+
// little reasoning is allowed (the answer still fits the token budget).
|
|
241
|
+
reasoningEffort: "low",
|
|
242
|
+
system: 'Extract only repository-specific facts and review findings. Never invent files, commands, or process. Never write a pull-request number, a commit id, a reviewer name, or quoted comment text in a claim. A review finding (sectionKey "review") states a concrete rule with an impact and an action.',
|
|
164
243
|
};
|
|
165
244
|
}
|
|
166
245
|
function cleanSection(text, key) {
|
|
167
|
-
const clean = text
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
function validSection(text, key) {
|
|
246
|
+
const clean = text
|
|
247
|
+
.replace(/^\s*```[a-zA-Z0-9_-]*\s*$/gm, "")
|
|
248
|
+
.replace(/```/g, "")
|
|
249
|
+
.trim();
|
|
172
250
|
const heading = `## ${sectionTitles[key] ?? key}`;
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
!/\b(?:TODO|TBD)\b/i.test(text));
|
|
251
|
+
// Guarantee the heading the skill assembler keys on, and keep whatever body
|
|
252
|
+
// the model produced rather than rejecting it.
|
|
253
|
+
if (/^##\s+.+$/m.test(clean))
|
|
254
|
+
return clean.replace(/^##\s+.+$/m, heading);
|
|
255
|
+
return clean ? `${heading}\n\n${clean}` : heading;
|
|
179
256
|
}
|
|
180
257
|
function sectionGoal(key) {
|
|
181
258
|
const goals = {
|
|
@@ -210,22 +287,26 @@ function synthesisFacts(facts, key) {
|
|
|
210
287
|
.slice(0, 20));
|
|
211
288
|
}
|
|
212
289
|
export async function extractAiFacts(provider, repo, source, options, usage) {
|
|
213
|
-
return (await extractAiFactsWithReport(provider, repo, source, options, usage)).facts;
|
|
214
|
-
}
|
|
215
|
-
export async function extractAiFactsWithReport(provider, repo, source, options, usage) {
|
|
216
290
|
const requests = [];
|
|
217
291
|
const evidence = [];
|
|
218
292
|
const scopes = [];
|
|
219
293
|
const prs = options.includePullRequests ? source.pullRequests : [];
|
|
220
294
|
for (const pr of prs) {
|
|
221
|
-
requests.push(extractRequest(`Analyze this pull request and return only a JSON array of
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
295
|
+
requests.push(extractRequest(`Analyze this pull request's reviews, comments, code and diff, and return only a JSON array of review findings.
|
|
296
|
+
Each item must have exactly:
|
|
297
|
+
{"sectionKey":"review","class":"a short area name","claim":"the invariant a reviewer would enforce, imperative and general","location":"path or path:line the finding is about, or empty when none","trigger":"the diff surface that should trigger this rule: a path, glob, or symbol, or empty when none","impact":"why this matters here, from the review's reasoning","action":"what to change or verify","scope":"historical-example","confidence":"medium"}
|
|
298
|
+
Rules:
|
|
299
|
+
- Include only substantive findings: a reviewer identifies something to fix, change, verify or decide.
|
|
300
|
+
- Never write an approval, a merge, "LGTM", thanks, a reviewer name, a pull-request number, a commit id, or quoted comment text.
|
|
301
|
+
- The claim is a general invariant, not one past fix: "When X changes, Y must also change", or "Every Z uses W", never "change this one line".
|
|
302
|
+
- trigger is what a reviewer can see in a diff: a path, a glob, or a symbol. It is how the rule applies to a future change, so a rule with no trigger is a one-off and is not useful.
|
|
303
|
+
- impact and action are mandatory and concrete. Paraphrase the reviewer's reasoning for impact; never quote it.
|
|
304
|
+
- class is a short area label chosen from a small, consistent set; reuse the same label for findings of the same kind so related findings can be grouped.
|
|
305
|
+
- location is a repository path when the review names one, otherwise leave it empty.
|
|
306
|
+
- Return every distinct finding the reviews support, not a summary. Do not explain the answer.
|
|
226
307
|
|
|
227
308
|
PULL REQUEST:
|
|
228
|
-
${pullRequestUnit(pr)}`,
|
|
309
|
+
${pullRequestUnit(pr)}`, 2_400));
|
|
229
310
|
evidence.push(`PR #${pr.number}`);
|
|
230
311
|
scopes.push("historical-example");
|
|
231
312
|
}
|
|
@@ -267,29 +348,33 @@ ${files}`, 2_200));
|
|
|
267
348
|
const response = responses[index];
|
|
268
349
|
if (!response)
|
|
269
350
|
continue;
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
351
|
+
facts.push(...factsFromResponse(response.text, evidence[index], scopes[index] ?? "historical-example", evidence[index] === "repository files" ? "repository" : "pull-request").filter((item) => {
|
|
352
|
+
if (hasUnsupportedIdentifier(item.claim, source) ||
|
|
353
|
+
hasUnsupportedPath(item.claim, source)) {
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
if (evidence[index] === "repository files" &&
|
|
357
|
+
!allowsContributionSections(source) &&
|
|
358
|
+
["title-body", "labels", "review-bar", "process"].includes(item.sectionKey)) {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
// An invented path is worse than no path: keep the finding and drop
|
|
362
|
+
// the location when it does not exist in the repository. The location
|
|
363
|
+
// may carry a line (`path:12` or `path:12-20`), which is stripped
|
|
364
|
+
// before the path is checked so a real path with a line survives.
|
|
365
|
+
if (item.sectionKey === "review" && item.location) {
|
|
366
|
+
const locationPath = item.location.replace(/:\d+(?:-\d+)?$/, "");
|
|
367
|
+
if (hasUnsupportedPath(locationPath, source)) {
|
|
368
|
+
item.location = undefined;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return true;
|
|
372
|
+
}));
|
|
282
373
|
if (index % 10 === 0 || index === responses.length - 1) {
|
|
283
374
|
console.log(`[ai] extract units ${index + 1}/${responses.length}`);
|
|
284
375
|
}
|
|
285
376
|
}
|
|
286
|
-
return
|
|
287
|
-
}
|
|
288
|
-
/** Same as {@link extractAiFacts}, but also reports what the batch skipped so
|
|
289
|
-
* the caller can put it in the final `[done]` line. */
|
|
290
|
-
export async function enrichFactsWithReport(provider, repo, base, source, options, usage) {
|
|
291
|
-
const { facts, skipped } = await extractAiFactsWithReport(provider, repo, source, options, usage);
|
|
292
|
-
return { facts: mergeFacts(base, facts), skipped };
|
|
377
|
+
return facts;
|
|
293
378
|
}
|
|
294
379
|
function mergeFacts(base, extra) {
|
|
295
380
|
const merged = new Map(base.map((item) => [item.id, { ...item, evidence: [...item.evidence] }]));
|
|
@@ -313,18 +398,21 @@ export async function synthesizeSections(provider, repo, facts, _previousMarkdow
|
|
|
313
398
|
const requests = [];
|
|
314
399
|
const keys = [];
|
|
315
400
|
for (const key of [...new Set(facts.map((item) => item.sectionKey))]) {
|
|
401
|
+
// Review findings are the guide's material, not a prose section.
|
|
402
|
+
if (!sectionTitles[key])
|
|
403
|
+
continue;
|
|
316
404
|
if (onlySections && !onlySections.has(key))
|
|
317
405
|
continue;
|
|
318
406
|
const relevant = synthesisFacts(facts, key);
|
|
319
407
|
// A section whose only facts came from a single pull request has no
|
|
320
|
-
// repository policy to synthesize, so it is
|
|
321
|
-
//
|
|
408
|
+
// repository policy to synthesize, so it is skipped instead of asking the
|
|
409
|
+
// model for an empty answer.
|
|
322
410
|
if (!relevant.length)
|
|
323
411
|
continue;
|
|
324
412
|
keys.push(key);
|
|
325
413
|
requests.push({
|
|
326
414
|
job: "synth_section",
|
|
327
|
-
maxTokens:
|
|
415
|
+
maxTokens: 4_000,
|
|
328
416
|
reasoningEffort: "high",
|
|
329
417
|
system: `You synthesize contribution guidance for an unfamiliar open-source repository.
|
|
330
418
|
Help developers make correct implementation, testing, review, debugging, and release
|
|
@@ -357,17 +445,21 @@ FACTS:
|
|
|
357
445
|
${JSON.stringify(relevant)}`,
|
|
358
446
|
});
|
|
359
447
|
}
|
|
360
|
-
|
|
448
|
+
// No validator: a section that does not match the ideal shape is normalized
|
|
449
|
+
// by `cleanSection` and kept, not rejected. Losing the whole run over a
|
|
450
|
+
// section's format is not worth it.
|
|
451
|
+
const queue = queueFor(provider, repo, ai, model, concurrency);
|
|
361
452
|
const responses = await queue.run(requests, usage);
|
|
362
|
-
// A
|
|
363
|
-
//
|
|
364
|
-
//
|
|
365
|
-
// (an empty string is a *present* override and would blank the section).
|
|
453
|
+
// A heading with no bullets is the model saying "no durable guidance", so the
|
|
454
|
+
// section is omitted rather than written empty. Anything with a bullet is
|
|
455
|
+
// kept as the model wrote it.
|
|
366
456
|
const overrides = {};
|
|
367
457
|
responses.forEach((response, index) => {
|
|
368
|
-
|
|
369
|
-
|
|
458
|
+
if (!response)
|
|
459
|
+
return;
|
|
460
|
+
const section = cleanSection(response.text, keys[index]);
|
|
461
|
+
if (/^- /m.test(section))
|
|
370
462
|
overrides[keys[index]] = section;
|
|
371
463
|
});
|
|
372
|
-
return { overrides
|
|
464
|
+
return { overrides };
|
|
373
465
|
}
|
|
@@ -11,6 +11,10 @@ export type PullRequest = {
|
|
|
11
11
|
additions: number;
|
|
12
12
|
deletions: number;
|
|
13
13
|
comments: string[];
|
|
14
|
+
/** Inline review comments (`pulls/{n}/comments`), as `path:line body`. These
|
|
15
|
+
* carry most of the substantive review feedback, and the reviewer never sees
|
|
16
|
+
* them otherwise. */
|
|
17
|
+
reviewComments: string[];
|
|
14
18
|
reviews: string[];
|
|
15
19
|
/** Set once reviews have been read. Missing means an older checkpoint
|
|
16
20
|
* never stored the review state. */
|
|
@@ -44,6 +48,24 @@ export type Fact = {
|
|
|
44
48
|
* repository-wide rule. Missing means `repository`, which
|
|
45
49
|
* keeps facts written before this field existed. */
|
|
46
50
|
origin?: "repository" | "pull-request";
|
|
51
|
+
/** Review findings only (`sectionKey === "review"`): the free-form area the
|
|
52
|
+
* finding belongs to, so the guide can group findings into passes without a
|
|
53
|
+
* fixed taxonomy. */
|
|
54
|
+
class?: string;
|
|
55
|
+
/** A repository-relative path or `path:line` the finding is about, when the
|
|
56
|
+
* review named one. Kept because it is the difference between a concrete
|
|
57
|
+
* rule and generic advice. */
|
|
58
|
+
location?: string;
|
|
59
|
+
/** Review findings only: why the finding matters here, in one or two
|
|
60
|
+
* sentences of the review's own reasoning (never a verbatim quote). */
|
|
61
|
+
impact?: string;
|
|
62
|
+
/** Review findings only: what to change or verify. */
|
|
63
|
+
action?: string;
|
|
64
|
+
/** Review findings only: the diff surface that should trigger this rule: a
|
|
65
|
+
* path, a glob, or a symbol. The guide turns these into the "when X changes,
|
|
66
|
+
* also do Y" obligations listed under a pass's exit check, so a reviewer that
|
|
67
|
+
* only sees a diff can still apply the rule. */
|
|
68
|
+
trigger?: string;
|
|
47
69
|
};
|
|
48
70
|
export type State = {
|
|
49
71
|
version: 1;
|
|
@@ -3,12 +3,22 @@ import { type Run } from "./checkout.ts";
|
|
|
3
3
|
import { type Presence } from "../tools/codegraph.ts";
|
|
4
4
|
import { type CodegraphRunner } from "../tools/codegraph_exec.ts";
|
|
5
5
|
export declare function ensureCodegraphIndex(binary: string, worktree: string, runner: CodegraphRunner, indexDir?: string): Promise<void>;
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* setup step
|
|
6
|
+
/** Resolves the codegraph binary for a review. `detect` is the default and
|
|
7
|
+
* never installs: the exiting `ensureCodegraph` is for a one-time
|
|
8
|
+
* `init`/`remake`/`serve` setup step, not for a single review that happens to
|
|
9
|
+
* want this tool. With `allowInstall` (`--allow-tool-install`) a missing or
|
|
10
|
+
* mismatched install is resolved through `ensureCodegraphForReview`, which
|
|
11
|
+
* installs without prompting and returns a reason instead of exiting. */
|
|
9
12
|
export declare function prepareCodegraphTools(repo: string, pr: number, commit: string, options?: {
|
|
10
13
|
run?: Run;
|
|
11
14
|
detect?: () => Promise<Presence>;
|
|
15
|
+
allowInstall?: boolean;
|
|
16
|
+
/** Overrides the install step, for tests. */
|
|
17
|
+
ensure?: () => Promise<{
|
|
18
|
+
path: string;
|
|
19
|
+
} | {
|
|
20
|
+
reason: string;
|
|
21
|
+
}>;
|
|
12
22
|
}): Promise<ToolHandler[]>;
|
|
13
23
|
/** Tool schemas for the remote bridge (runs are proxied to the CLI). */
|
|
14
24
|
export declare function codegraphToolHandlersForBridge(): ToolHandler[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ensureWorktree, pathExists, runCommand, } from "./checkout.js";
|
|
2
|
-
import { detect } from "../tools/codegraph.js";
|
|
2
|
+
import { detect, ensureCodegraphForReview, } from "../tools/codegraph.js";
|
|
3
3
|
import { createCodegraphRunner, LOCAL_CODEGRAPH_DIR, runCodegraphTool, SERVER_CODEGRAPH_DIR, } from "../tools/codegraph_exec.js";
|
|
4
4
|
import { log } from "../util/log.js";
|
|
5
5
|
import { guardToolArgs, rejectEscapingPath, rejectFlagLike, } from "./codegraph_tool_args.js";
|
|
@@ -42,22 +42,41 @@ export async function ensureCodegraphIndex(binary, worktree, runner, indexDir =
|
|
|
42
42
|
log("codegraph", `${fresh ? "init" : "sync"} · ${indexed} files · ${((performance.now() - started) /
|
|
43
43
|
1000).toFixed(1)}s`);
|
|
44
44
|
}
|
|
45
|
-
/**
|
|
46
|
-
*
|
|
47
|
-
* setup step
|
|
45
|
+
/** Resolves the codegraph binary for a review. `detect` is the default and
|
|
46
|
+
* never installs: the exiting `ensureCodegraph` is for a one-time
|
|
47
|
+
* `init`/`remake`/`serve` setup step, not for a single review that happens to
|
|
48
|
+
* want this tool. With `allowInstall` (`--allow-tool-install`) a missing or
|
|
49
|
+
* mismatched install is resolved through `ensureCodegraphForReview`, which
|
|
50
|
+
* installs without prompting and returns a reason instead of exiting. */
|
|
48
51
|
export async function prepareCodegraphTools(repo, pr, commit, options = {}) {
|
|
49
52
|
const runner = options.run ?? runCommand;
|
|
50
53
|
const detectPresence = options.detect ?? detect;
|
|
54
|
+
const ensure = options.ensure ??
|
|
55
|
+
(() => ensureCodegraphForReview({
|
|
56
|
+
allowInstall: options.allowInstall,
|
|
57
|
+
interactive: false,
|
|
58
|
+
}));
|
|
51
59
|
try {
|
|
52
60
|
const presence = await detectPresence();
|
|
53
|
-
|
|
61
|
+
let binary = presence.state === "ok" ? presence.path : null;
|
|
62
|
+
if (binary === null && options.allowInstall) {
|
|
63
|
+
const resolved = await ensure();
|
|
64
|
+
if ("path" in resolved) {
|
|
65
|
+
binary = resolved.path;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
log("codegraph", `tools unavailable · ${resolved.reason}`);
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (binary === null) {
|
|
54
73
|
log("codegraph", `tools unavailable · codegraph is ${presence.state}`);
|
|
55
74
|
return [];
|
|
56
75
|
}
|
|
57
76
|
const worktree = await ensureWorktree(repo, pr, commit, runner);
|
|
58
77
|
const cgRun = createCodegraphRunner(SERVER_CODEGRAPH_DIR);
|
|
59
|
-
await ensureCodegraphIndex(
|
|
60
|
-
return codegraphTools(
|
|
78
|
+
await ensureCodegraphIndex(binary, worktree, cgRun);
|
|
79
|
+
return codegraphTools(binary, worktree, cgRun);
|
|
61
80
|
}
|
|
62
81
|
catch (error) {
|
|
63
82
|
log("codegraph", `tools unavailable · ${String(error)}`);
|
|
@@ -4,6 +4,10 @@ import type { Snapshot } from "./snapshot.ts";
|
|
|
4
4
|
import type { AiProvider, AiResponse, GitHubClient, Json, Options } from "../types.ts";
|
|
5
5
|
type UsageSink = (response: AiResponse) => Promise<void>;
|
|
6
6
|
type ProgressSink = (message: string) => void;
|
|
7
|
+
/** One line naming the provider and the two models a review will call, printed
|
|
8
|
+
* before any AI request so the operator can see what is running. The low model
|
|
9
|
+
* summarizes large diffs, the high model writes the review. */
|
|
10
|
+
export declare function modelSummary(options: Options): string;
|
|
7
11
|
export type ReviewExtras = {
|
|
8
12
|
carryPrompt?: string;
|
|
9
13
|
unchangedPaths?: string[];
|
package/dist/src/pr/reviewer.js
CHANGED
|
@@ -9,6 +9,13 @@ import { reviewSystemPromptBlock } from "../review/system_prompt.js";
|
|
|
9
9
|
import { needsSummary, READ_FULL_DIFF_TOOL, readFullDiff, summarizeDiff, } from "./diff_summary.js";
|
|
10
10
|
import { numberPatch } from "./hunks.js";
|
|
11
11
|
import { FINDINGS_JSON_INSTRUCTIONS, FINDINGS_JSON_SCHEMA, findingsMarkdownFromJson, } from "./findings_json.js";
|
|
12
|
+
/** One line naming the provider and the two models a review will call, printed
|
|
13
|
+
* before any AI request so the operator can see what is running. The low model
|
|
14
|
+
* summarizes large diffs, the high model writes the review. */
|
|
15
|
+
export function modelSummary(options) {
|
|
16
|
+
return (`models · provider=${options.ai} · low=${options.lowModel ?? "unset"} · ` +
|
|
17
|
+
`high=${options.highModel ?? "unset"}`);
|
|
18
|
+
}
|
|
12
19
|
/** A model id is never guessed here. Models go stale, and a build already
|
|
13
20
|
* installed cannot fetch a fresher one, so the id to run comes from config
|
|
14
21
|
* or a flag, set at least once by whoever runs it (Murat, 2026-09-28). */
|
|
@@ -196,6 +203,7 @@ export async function reviewPullRequest(client, options, usage, snapshot, ai, pr
|
|
|
196
203
|
throw new Error("review requires a PR number");
|
|
197
204
|
const number = options.prNumber;
|
|
198
205
|
const report = progress ?? (() => { });
|
|
206
|
+
report(modelSummary(options));
|
|
199
207
|
report(`loading PR context for ${options.repo}#${number}`);
|
|
200
208
|
const [pr, allComments, allReviews, guides] = await Promise.all([
|
|
201
209
|
client.request(`repos/${options.repo}/pulls/${number}`),
|
|
@@ -274,7 +282,9 @@ export async function reviewPullRequest(client, options, usage, snapshot, ai, pr
|
|
|
274
282
|
`enough]\n${description}`);
|
|
275
283
|
})),
|
|
276
284
|
options.useCodegraph && headSha
|
|
277
|
-
? prepareCodegraphTools(options.repo, number, headSha
|
|
285
|
+
? prepareCodegraphTools(options.repo, number, headSha, {
|
|
286
|
+
allowInstall: options.allowToolInstall,
|
|
287
|
+
})
|
|
278
288
|
: Promise.resolve([]),
|
|
279
289
|
]);
|
|
280
290
|
if (options.useCodegraph) {
|
|
@@ -459,6 +469,7 @@ function revisionToGithubFiles(revision) {
|
|
|
459
469
|
/** Local workspace review — same prompt loop as PR review without GitHub. */
|
|
460
470
|
export async function reviewWorkspaceRevision(revision, options, headSha, usage, ai, progress, extras) {
|
|
461
471
|
const report = progress ?? (() => { });
|
|
472
|
+
report(modelSummary(options));
|
|
462
473
|
const guides = await loadGuides(options.repo);
|
|
463
474
|
const { shortGuide, detailed, codebase, skill } = guides;
|
|
464
475
|
const guide = shortGuide || skill;
|
|
@@ -70,7 +70,7 @@ function reviewOptionsForRepo(repo, useCodegraph, aiToken) {
|
|
|
70
70
|
aiToken: aiToken ?? resolvedAiToken(config, config.ai ?? "openrouter"),
|
|
71
71
|
lowModel: config.lowModel,
|
|
72
72
|
highModel: config.highModel,
|
|
73
|
-
synthesisVersion:
|
|
73
|
+
synthesisVersion: 17,
|
|
74
74
|
includeCodebase: true,
|
|
75
75
|
includePullRequests: true,
|
|
76
76
|
includePullRequestChanges: true,
|
|
@@ -147,7 +147,7 @@ export function reviewOptions(repo, prNumber) {
|
|
|
147
147
|
aiToken: resolvedAiToken(config, config.ai && config.ai !== "none" ? config.ai : "openrouter"),
|
|
148
148
|
highModel: config.highModel,
|
|
149
149
|
lowModel: config.lowModel,
|
|
150
|
-
synthesisVersion:
|
|
150
|
+
synthesisVersion: 17,
|
|
151
151
|
includeCodebase: true,
|
|
152
152
|
includePullRequests: true,
|
|
153
153
|
includePullRequestChanges: true,
|