co-maintainer 0.7.2 → 0.7.4
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/cli/command_json.d.ts +3 -1
- package/dist/src/cli/command_json.js +1 -0
- package/dist/src/cli/commands/review.js +2 -0
- package/dist/src/cli/commands/set.js +19 -2
- package/dist/src/cli/pr_carry.d.ts +2 -0
- package/dist/src/cli/pr_carry.js +2 -2
- package/dist/src/cli/review_carry.d.ts +3 -1
- package/dist/src/cli/review_carry.js +5 -3
- package/dist/src/cli/review_result.d.ts +10 -1
- package/dist/src/cli/review_result.js +14 -1
- package/dist/src/config.d.ts +9 -0
- package/dist/src/github/collect.d.ts +7 -1
- package/dist/src/github/collect.js +41 -16
- package/dist/src/knowledge/guide.d.ts +24 -1
- package/dist/src/knowledge/guide.js +39 -9
- package/dist/src/knowledge/guide_ids.d.ts +9 -0
- package/dist/src/knowledge/guide_ids.js +26 -7
- package/dist/src/knowledge/rule_changes.d.ts +18 -0
- package/dist/src/knowledge/rule_changes.js +41 -0
- package/dist/src/knowledge/rules.d.ts +11 -0
- package/dist/src/knowledge/rules.js +10 -1
- package/dist/src/knowledge/stable_ids.d.ts +34 -0
- package/dist/src/knowledge/stable_ids.js +124 -0
- package/dist/src/knowledge/synthesis.d.ts +13 -1
- package/dist/src/knowledge/synthesis.js +89 -21
- package/dist/src/knowledge/types.d.ts +16 -0
- package/dist/src/local/review_local.js +3 -2
- package/dist/src/pr/findings.d.ts +3 -0
- package/dist/src/pr/findings.js +21 -1
- package/dist/src/pr/findings_json.d.ts +1 -1
- package/dist/src/pr/findings_json.js +14 -1
- package/dist/src/pr/reviewer.d.ts +4 -0
- package/dist/src/pr/reviewer.js +2 -0
- package/dist/src/remote/client.js +1 -0
- package/dist/src/review/carry_over.d.ts +8 -0
- package/dist/src/review/carry_over.js +8 -0
- package/dist/src/review/references.d.ts +68 -0
- package/dist/src/review/references.js +176 -0
- package/dist/src/server/pages/pr.js +2 -0
- package/dist/src/server/pages/references.d.ts +2 -0
- package/dist/src/server/pages/references.js +55 -0
- package/dist/src/server/pages/repo.js +26 -0
- package/dist/src/services/dashboard.d.ts +2 -0
- package/dist/src/services/dashboard.js +2 -0
- package/dist/src/services/push_review.js +4 -1
- package/dist/src/services/remote_review.js +5 -2
- package/dist/src/services/review.js +35 -8
- package/dist/src/services/rules_build.d.ts +20 -1
- package/dist/src/services/rules_build.js +88 -6
- package/dist/src/services/setup.js +27 -2
- package/dist/src/store/findings.d.ts +2 -0
- package/dist/src/store/findings.js +3 -3
- package/dist/src/store/migrations.js +17 -0
- package/dist/src/store/rows.d.ts +2 -0
- package/dist/src/store/rule_events.d.ts +15 -0
- package/dist/src/store/rule_events.js +20 -0
- package/dist/src/types.d.ts +4 -0
- package/package.json +1 -1
package/dist/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { Estimate } from "../ai/estimate.ts";
|
|
9
9
|
import type { RunSummary } from "../util/run_summary.ts";
|
|
10
|
-
import type { RuleChanges } from "../knowledge/rule_changes.ts";
|
|
10
|
+
import type { Contradiction, RuleChanges } from "../knowledge/rule_changes.ts";
|
|
11
11
|
export type ProbeJsonInput = {
|
|
12
12
|
repo: string;
|
|
13
13
|
recommended: string;
|
|
@@ -66,6 +66,8 @@ export type SetupJsonInput = {
|
|
|
66
66
|
guide: RuleChanges;
|
|
67
67
|
instructions: RuleChanges;
|
|
68
68
|
} | null;
|
|
69
|
+
/** Old guide rules a new rule goes against. Left out when there are none. */
|
|
70
|
+
contradicted?: Contradiction[];
|
|
69
71
|
summary: RunSummary;
|
|
70
72
|
};
|
|
71
73
|
export declare function buildSetupJson(input: SetupJsonInput): string;
|
|
@@ -39,6 +39,7 @@ export function buildSetupJson(input) {
|
|
|
39
39
|
...(input.ruleChanges !== undefined
|
|
40
40
|
? { ruleChanges: input.ruleChanges }
|
|
41
41
|
: {}),
|
|
42
|
+
...(input.contradicted?.length ? { contradicted: input.contradicted } : {}),
|
|
42
43
|
usage: {
|
|
43
44
|
tokensIn: summary.tokensIn,
|
|
44
45
|
tokensOut: summary.tokensOut,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parseReviewArgs } from "../review_args.js";
|
|
2
|
+
import { readConfig } from "../../config.js";
|
|
2
3
|
import { setCliInteractive } from "../args.js";
|
|
3
4
|
import { addAiMetrics, emptyAiMetrics, recordAiCost, } from "../../services/setup.js";
|
|
4
5
|
import { costUsage } from "../../util/cost.js";
|
|
@@ -134,6 +135,7 @@ async function runReviewPr(options, cli) {
|
|
|
134
135
|
coverage: result.coverage,
|
|
135
136
|
extensions,
|
|
136
137
|
intent: intent !== null,
|
|
138
|
+
showReferences: readConfig().repos?.[options.repo]?.reviewReferences === true,
|
|
137
139
|
}) +
|
|
138
140
|
"\n");
|
|
139
141
|
printRunSummary(runSummaryWithExtensions(summaryFromMetrics(aiMetrics, performance.now() - operationStarted), extensions));
|
|
@@ -76,6 +76,7 @@ export async function runSet(args) {
|
|
|
76
76
|
"review-policy",
|
|
77
77
|
"review-policy-file",
|
|
78
78
|
"review-blocking",
|
|
79
|
+
"review-references",
|
|
79
80
|
"codegraph-version",
|
|
80
81
|
"gh-concurrent",
|
|
81
82
|
"ai-concurrent",
|
|
@@ -104,7 +105,7 @@ export async function runSet(args) {
|
|
|
104
105
|
await runSetRepo(repoArg, args);
|
|
105
106
|
return;
|
|
106
107
|
}
|
|
107
|
-
for (const name of DIAGRAM_FLAGS) {
|
|
108
|
+
for (const name of [...DIAGRAM_FLAGS, "review-references"]) {
|
|
108
109
|
if (text(args, name) !== undefined)
|
|
109
110
|
die(`--${name} needs --repo`);
|
|
110
111
|
}
|
|
@@ -399,6 +400,7 @@ const REPO_SCOPED_FLAGS = new Set([
|
|
|
399
400
|
"review-system-prompt-max-chars",
|
|
400
401
|
...DIAGRAM_FLAGS,
|
|
401
402
|
"review-read-diff-max-chars",
|
|
403
|
+
"review-references",
|
|
402
404
|
"gh-concurrent",
|
|
403
405
|
"ai-concurrent",
|
|
404
406
|
"unset",
|
|
@@ -420,6 +422,8 @@ const REPO_SCOPED_UNSET = new Set([
|
|
|
420
422
|
"ghConcurrent",
|
|
421
423
|
"ai-concurrent",
|
|
422
424
|
"aiConcurrent",
|
|
425
|
+
"review-references",
|
|
426
|
+
"reviewReferences",
|
|
423
427
|
]);
|
|
424
428
|
/** `set --repo=owner/repo [--review-system-prompt=... | --review-system-prompt-max-chars=N | --review-read-diff-max-chars=N | --unset=name]`
|
|
425
429
|
* writes the repository-scoped settings to `repos[owner/repo]` in config.json
|
|
@@ -520,12 +524,25 @@ async function runSetRepo(typed, args) {
|
|
|
520
524
|
patch.reviewReadDiffMaxChars = value;
|
|
521
525
|
}
|
|
522
526
|
}
|
|
527
|
+
if (unset.has("review-references") || unset.has("reviewReferences")) {
|
|
528
|
+
patch.reviewReferences = undefined;
|
|
529
|
+
}
|
|
530
|
+
const references = text(args, "review-references");
|
|
531
|
+
if (references !== undefined) {
|
|
532
|
+
if (!["on", "off"].includes(references)) {
|
|
533
|
+
die("--review-references must be on or off");
|
|
534
|
+
}
|
|
535
|
+
patch.reviewReferences = references === "on";
|
|
536
|
+
if (references === "on" && !existing.referencesBackfilledAt) {
|
|
537
|
+
console.log("[set] the next sync reads every pull request again once, so guide rules get links to the review comments they came from");
|
|
538
|
+
}
|
|
539
|
+
}
|
|
523
540
|
const prompt = text(args, "review-system-prompt");
|
|
524
541
|
if (prompt !== undefined) {
|
|
525
542
|
patch.reviewSystemPrompt = prompt.trim() === "" ? undefined : prompt;
|
|
526
543
|
}
|
|
527
544
|
if (Object.keys(patch).length === 0) {
|
|
528
|
-
die("Nothing to set. Pass --review-system-prompt=, --review-system-prompt-max-chars=N, --diagram-runtime=, --plantuml-server=, --plantuml-output-format=, --review-read-diff-max-chars=N, or --unset=name with --repo.");
|
|
545
|
+
die("Nothing to set. Pass --review-system-prompt=, --review-system-prompt-max-chars=N, --diagram-runtime=, --plantuml-server=, --plantuml-output-format=, --review-read-diff-max-chars=N, --review-references=on|off, or --unset=name with --repo.");
|
|
529
546
|
}
|
|
530
547
|
// The values after this write are the ones given here, or the stored ones.
|
|
531
548
|
// Lowering the cap re-checks the stored prompt too, so it cannot end up over
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { GitHubClient, Options } from "../types.ts";
|
|
2
|
+
import type { ReferenceContext } from "../review/references.ts";
|
|
2
3
|
import { type ResolvedFinding } from "../review/carry_over.ts";
|
|
3
4
|
import type { ReviewExtras } from "../pr/reviewer.ts";
|
|
4
5
|
import type { ReviewWarning } from "./review_result.ts";
|
|
@@ -6,6 +7,7 @@ type EngineAnswer = {
|
|
|
6
7
|
text: string;
|
|
7
8
|
visiblePaths: string[];
|
|
8
9
|
guideBuiltAt: string | null;
|
|
10
|
+
referenceContext?: ReferenceContext;
|
|
9
11
|
};
|
|
10
12
|
/** What a CLI pull request review needs around the engine call. `extras` goes
|
|
11
13
|
* to `reviewPullRequest` as it is, `finish` turns its answer into findings and
|
package/dist/src/cli/pr_carry.js
CHANGED
|
@@ -74,7 +74,7 @@ export async function startPrCarry(client, options, fresh, log = () => { }) {
|
|
|
74
74
|
description: "",
|
|
75
75
|
baseLabel: "",
|
|
76
76
|
producer: "github",
|
|
77
|
-
}, response).resolved,
|
|
77
|
+
}, response, repo).resolved,
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
const guides = await loadGuides(repo);
|
|
@@ -105,7 +105,7 @@ export async function startPrCarry(client, options, fresh, log = () => { }) {
|
|
|
105
105
|
extras: { ...run.extras, prefetched },
|
|
106
106
|
warnings,
|
|
107
107
|
finish: async (response) => {
|
|
108
|
-
const { resolved, visiblePaths } = finishCarryRun(run, current, response);
|
|
108
|
+
const { resolved, visiblePaths } = finishCarryRun(run, current, response, repo);
|
|
109
109
|
try {
|
|
110
110
|
await savePrCarry({
|
|
111
111
|
subjectId: prSubjectId(repo, prNumber),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type CarryItem, type CarryPrevious, type ResolvedFinding, type StoredFinding } from "../review/carry_over.ts";
|
|
2
2
|
import type { Revision, RevisionFile } from "../review/revision.ts";
|
|
3
|
+
import { type ReferenceContext } from "../review/references.ts";
|
|
3
4
|
/** What a CLI run keeps for the next one: the findings that are still live. */
|
|
4
5
|
export declare function storedFindings(resolved: ResolvedFinding[]): StoredFinding[];
|
|
5
6
|
export type PreviousRun = {
|
|
@@ -26,7 +27,8 @@ export declare function finishCarryRun(run: CarryRun, revision: Revision, respon
|
|
|
26
27
|
text: string;
|
|
27
28
|
visiblePaths: string[];
|
|
28
29
|
guideBuiltAt: string | null;
|
|
29
|
-
|
|
30
|
+
referenceContext?: ReferenceContext;
|
|
31
|
+
}, repo?: string): {
|
|
30
32
|
resolved: ResolvedFinding[];
|
|
31
33
|
visiblePaths: Set<string>;
|
|
32
34
|
};
|
|
@@ -2,6 +2,7 @@ import { buildCarryPromptSection, classifyCarryItems, incrementalDiffPaths, pars
|
|
|
2
2
|
import { visiblePathsToSave } from "../review/visible_paths.js";
|
|
3
3
|
import { parseFindings } from "../pr/findings.js";
|
|
4
4
|
import { resolvedFromFirstReview } from "./review_result.js";
|
|
5
|
+
import { withResolvedReferences, } from "../review/references.js";
|
|
5
6
|
/** What a CLI run keeps for the next one: the findings that are still live. */
|
|
6
7
|
export function storedFindings(resolved) {
|
|
7
8
|
return resolved
|
|
@@ -16,6 +17,7 @@ export function storedFindings(resolved) {
|
|
|
16
17
|
anchorText: row.anchorText,
|
|
17
18
|
severity: row.severity,
|
|
18
19
|
firstSeenReviewId: row.firstSeenReviewId,
|
|
20
|
+
...(row.references ? { references: row.references } : {}),
|
|
19
21
|
}));
|
|
20
22
|
}
|
|
21
23
|
/** `previous` is null on a first or fresh run, and then nothing is carried. */
|
|
@@ -42,19 +44,19 @@ export function startCarryRun(previous, revision, currentGuideBuiltAt) {
|
|
|
42
44
|
/** Turns the engine's answer into `new`, `open` and `closed` rows. Without a
|
|
43
45
|
* previous run every parsed finding is `new`. `visiblePaths` is what to save
|
|
44
46
|
* for the next run, decided by `visiblePathsToSave`. */
|
|
45
|
-
export function finishCarryRun(run, revision, response) {
|
|
47
|
+
export function finishCarryRun(run, revision, response, repo = "") {
|
|
46
48
|
const visiblePaths = new Set(response.visiblePaths);
|
|
47
49
|
const parsed = parseFindings(response.text);
|
|
48
50
|
if (!run.previous) {
|
|
49
51
|
const filesByPath = new Map(revision.files.map((f) => [f.path, f]));
|
|
50
52
|
return {
|
|
51
|
-
resolved: resolvedFromFirstReview(parsed, filesByPath),
|
|
53
|
+
resolved: withResolvedReferences(resolvedFromFirstReview(parsed, filesByPath), repo, response.referenceContext),
|
|
52
54
|
visiblePaths: visiblePathsToSave(null, run.extras.unchangedPaths, visiblePaths),
|
|
53
55
|
};
|
|
54
56
|
}
|
|
55
57
|
const items = classifyCarryItems(run.previous, revision, visiblePaths, response.guideBuiltAt);
|
|
56
58
|
return {
|
|
57
|
-
resolved: resolveCarryOutcomes(items, revision, visiblePaths, parsePreviousVerdicts(response.text), parsed),
|
|
59
|
+
resolved: withResolvedReferences(resolveCarryOutcomes(items, revision, visiblePaths, parsePreviousVerdicts(response.text), parsed), repo, response.referenceContext),
|
|
58
60
|
visiblePaths: visiblePathsToSave(run.previous.visiblePaths, run.extras.unchangedPaths, visiblePaths),
|
|
59
61
|
};
|
|
60
62
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ResolvedReference } from "../review/references.ts";
|
|
1
2
|
import { type ParsedFinding } from "../pr/findings.ts";
|
|
2
3
|
import { type ResolvedFinding } from "../review/carry_over.ts";
|
|
3
4
|
import { type ReviewBlocking } from "../review/blocking.ts";
|
|
@@ -29,6 +30,9 @@ export type JsonReviewFinding = {
|
|
|
29
30
|
lineTo: number;
|
|
30
31
|
text: string;
|
|
31
32
|
} | null;
|
|
33
|
+
/** What the finding rests on. Always present, shown in a comment only when
|
|
34
|
+
* the repository turns references on. */
|
|
35
|
+
references: ResolvedReference[];
|
|
32
36
|
};
|
|
33
37
|
export declare function isBlockingFinding(title: string, severity: string, mode?: ReviewBlocking): boolean;
|
|
34
38
|
export declare function resolvedFromFirstReview(parsed: ParsedFinding[], filesByPath: Map<string, {
|
|
@@ -85,6 +89,8 @@ export type HumanFinding = {
|
|
|
85
89
|
} | null;
|
|
86
90
|
/** An extension finding's `[P2 · blocking] · extension: name`. */
|
|
87
91
|
label?: string;
|
|
92
|
+
/** What the finding rests on, printed only with `showReferences`. */
|
|
93
|
+
references?: ResolvedReference[];
|
|
88
94
|
};
|
|
89
95
|
/** Local and PR findings: blocking is decided here from the configured rule,
|
|
90
96
|
* exactly as the exit code decides it. */
|
|
@@ -117,6 +123,9 @@ export type HumanReviewInput = {
|
|
|
117
123
|
coverage?: Coverage;
|
|
118
124
|
/** The extensions' results. Absent or empty prints nothing extra. */
|
|
119
125
|
extensions?: ExtensionReport;
|
|
126
|
+
/** Print each finding's references. On only when the repository turned
|
|
127
|
+
* references on. */
|
|
128
|
+
showReferences?: boolean;
|
|
120
129
|
/** An intent file was given. The line says so and never shows the text. */
|
|
121
130
|
intent?: boolean;
|
|
122
131
|
};
|
|
@@ -129,7 +138,7 @@ export type HumanReviewInput = {
|
|
|
129
138
|
* stay in the GitHub comment, which is a different reader. */
|
|
130
139
|
export declare function formatHumanReview(input: HumanReviewInput): string;
|
|
131
140
|
/** Local review output: the shared format plus the working-tree file stats. */
|
|
132
|
-
export declare function formatHumanLocalReview(header: string, revision: Revision, guideBuiltAt: string | null, codegraphState: "used" | "disabled" | "unavailable", findings: ResolvedFinding[], warnings: ReviewWarning[], mode?: ReviewBlocking, coverage?: Coverage, extensions?: ExtensionReport, intent?: boolean): string;
|
|
141
|
+
export declare function formatHumanLocalReview(header: string, revision: Revision, guideBuiltAt: string | null, codegraphState: "used" | "disabled" | "unavailable", findings: ResolvedFinding[], warnings: ReviewWarning[], mode?: ReviewBlocking, coverage?: Coverage, extensions?: ExtensionReport, intent?: boolean, showReferences?: boolean): string;
|
|
133
142
|
/** The exit code for a remote review. The server already decided
|
|
134
143
|
* each finding's `blocking` under its own configured rule, so the client
|
|
135
144
|
* trusts that field instead of re-deriving the rule from a title: the client
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { referenceLine } from "../review/references.js";
|
|
1
2
|
import { parseFindings } from "../pr/findings.js";
|
|
2
3
|
import { readSuggestion, stripSuggestion } from "../pr/suggestion.js";
|
|
3
4
|
import { stripControlChars } from "../util/sanitize.js";
|
|
@@ -37,6 +38,7 @@ export function resolvedFromFirstReview(parsed, filesByPath) {
|
|
|
37
38
|
severity: finding.severity ?? "P2",
|
|
38
39
|
carriedFromId: null,
|
|
39
40
|
firstSeenReviewId: null,
|
|
41
|
+
referenceIds: finding.references ?? [],
|
|
40
42
|
};
|
|
41
43
|
});
|
|
42
44
|
}
|
|
@@ -78,6 +80,7 @@ export function toJsonFinding(row, mode = DEFAULT_REVIEW_BLOCKING) {
|
|
|
78
80
|
text: suggestion.code,
|
|
79
81
|
}
|
|
80
82
|
: null,
|
|
83
|
+
references: row.references ?? [],
|
|
81
84
|
};
|
|
82
85
|
}
|
|
83
86
|
function statsOf(revision) {
|
|
@@ -149,6 +152,7 @@ export function humanFindingsFromResolved(findings, mode = DEFAULT_REVIEW_BLOCKI
|
|
|
149
152
|
text: suggestion.code,
|
|
150
153
|
}
|
|
151
154
|
: null,
|
|
155
|
+
...(row.references ? { references: row.references } : {}),
|
|
152
156
|
};
|
|
153
157
|
});
|
|
154
158
|
}
|
|
@@ -166,6 +170,8 @@ export function humanFindingsFromJson(findings) {
|
|
|
166
170
|
title: row.title,
|
|
167
171
|
body: row.body.trim(),
|
|
168
172
|
suggestion: row.suggestion,
|
|
173
|
+
// A server older than references sends none.
|
|
174
|
+
...(Array.isArray(row.references) ? { references: row.references } : {}),
|
|
169
175
|
}));
|
|
170
176
|
}
|
|
171
177
|
function humanLocation(row) {
|
|
@@ -261,6 +267,12 @@ export function formatHumanReview(input) {
|
|
|
261
267
|
lines.push(` ${stripControlChars(part)}`);
|
|
262
268
|
lines.push(" ```");
|
|
263
269
|
}
|
|
270
|
+
if (input.showReferences && row.references?.length) {
|
|
271
|
+
lines.push(` References (${row.references.length})`);
|
|
272
|
+
for (const reference of row.references) {
|
|
273
|
+
lines.push(` - ${stripControlChars(referenceLine(reference, false))}`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
264
276
|
}
|
|
265
277
|
lines.push("");
|
|
266
278
|
}
|
|
@@ -304,7 +316,7 @@ export function formatHumanReview(input) {
|
|
|
304
316
|
return lines.join("\n");
|
|
305
317
|
}
|
|
306
318
|
/** Local review output: the shared format plus the working-tree file stats. */
|
|
307
|
-
export function formatHumanLocalReview(header, revision, guideBuiltAt, codegraphState, findings, warnings, mode = DEFAULT_REVIEW_BLOCKING, coverage, extensions, intent) {
|
|
319
|
+
export function formatHumanLocalReview(header, revision, guideBuiltAt, codegraphState, findings, warnings, mode = DEFAULT_REVIEW_BLOCKING, coverage, extensions, intent, showReferences) {
|
|
308
320
|
const stats = revisionStats(revision);
|
|
309
321
|
return formatHumanReview({
|
|
310
322
|
title: header,
|
|
@@ -316,6 +328,7 @@ export function formatHumanLocalReview(header, revision, guideBuiltAt, codegraph
|
|
|
316
328
|
coverage,
|
|
317
329
|
extensions,
|
|
318
330
|
intent,
|
|
331
|
+
showReferences,
|
|
319
332
|
});
|
|
320
333
|
}
|
|
321
334
|
/** The exit code for a remote review. The server already decided
|
package/dist/src/config.d.ts
CHANGED
|
@@ -38,6 +38,15 @@ export type RepoConfig = {
|
|
|
38
38
|
/** How a review decides a blocking finding for this repository. Unset
|
|
39
39
|
* follows the server default. */
|
|
40
40
|
reviewBlocking?: "model" | "severity";
|
|
41
|
+
/** Show each finding's references (the guide rules, instructions,
|
|
42
|
+
* codebase conventions or review instructions it rests on) in the review
|
|
43
|
+
* comment. Unset or false keeps them out of the comment. They are stored
|
|
44
|
+
* and shown on the dashboard either way. */
|
|
45
|
+
reviewReferences?: boolean;
|
|
46
|
+
/** When the first sync after `reviewReferences` was turned on re-read
|
|
47
|
+
* every pull request so its rules get comment links. Set once, so turning
|
|
48
|
+
* the setting off and on again never re-reads them a second time. */
|
|
49
|
+
referencesBackfilledAt?: string;
|
|
41
50
|
/** A repository's own review instructions, appended to the built-in
|
|
42
51
|
* reviewer prompt as a `CUSTOM REVIEW INSTRUCTIONS` section. Unset or blank
|
|
43
52
|
* means none. */
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import type { GitHubClient, Options } from "../types.ts";
|
|
1
|
+
import type { GitHubClient, Json, Options } from "../types.ts";
|
|
2
2
|
import type { Source, State } from "../knowledge/types.ts";
|
|
3
|
+
/** The non-empty texts and the GitHub link of each, kept at the same index so
|
|
4
|
+
* a fact can later name a comment and code can find its link. */
|
|
5
|
+
export declare function textsWithLinks(items: Json[], text: (item: Json) => string, max?: number): {
|
|
6
|
+
texts: string[];
|
|
7
|
+
urls: string[];
|
|
8
|
+
};
|
|
3
9
|
/** What the codebase fetch saves while it runs. `instructionFiles` is always
|
|
4
10
|
* named, even when missing: the blob SHAs it is checked against are saved in
|
|
5
11
|
* the same write, so a checkpoint never pairs new SHAs with old contents. */
|
|
@@ -14,8 +14,26 @@ function percent(done, total) {
|
|
|
14
14
|
function changesRequested(reviews) {
|
|
15
15
|
return reviews.some((review) => review.state === "CHANGES_REQUESTED");
|
|
16
16
|
}
|
|
17
|
+
/** The non-empty texts and the GitHub link of each, kept at the same index so
|
|
18
|
+
* a fact can later name a comment and code can find its link. */
|
|
19
|
+
export function textsWithLinks(items, text, max = Infinity) {
|
|
20
|
+
const kept = items
|
|
21
|
+
.map((item) => ({ text: text(item), url: String(item.html_url ?? "") }))
|
|
22
|
+
.filter((item) => item.text)
|
|
23
|
+
.slice(0, max);
|
|
24
|
+
return {
|
|
25
|
+
texts: kept.map((item) => item.text),
|
|
26
|
+
urls: kept.map((item) => item.url),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
17
29
|
function reviewBodies(reviews) {
|
|
18
|
-
return reviews
|
|
30
|
+
return textsWithLinks(reviews, (review) => String(review.body ?? ""));
|
|
31
|
+
}
|
|
32
|
+
function reviewCommentText(comment) {
|
|
33
|
+
const path = String(comment.path ?? "");
|
|
34
|
+
const line = String(comment.line ?? comment.original_line ?? "");
|
|
35
|
+
const body = String(comment.body ?? "");
|
|
36
|
+
return path ? `${path}:${line} ${body}` : body;
|
|
19
37
|
}
|
|
20
38
|
function withinPrWindow(updatedAt, months) {
|
|
21
39
|
if (months === undefined || months === 0)
|
|
@@ -396,6 +414,11 @@ async function pullRequests(client, options, previous, phase) {
|
|
|
396
414
|
comments: cached?.comments ?? [],
|
|
397
415
|
reviewComments: cached?.reviewComments ?? [],
|
|
398
416
|
reviews: cached?.reviews ?? [],
|
|
417
|
+
...(cached?.commentUrls ? { commentUrls: cached.commentUrls } : {}),
|
|
418
|
+
...(cached?.reviewCommentUrls
|
|
419
|
+
? { reviewCommentUrls: cached.reviewCommentUrls }
|
|
420
|
+
: {}),
|
|
421
|
+
...(cached?.reviewUrls ? { reviewUrls: cached.reviewUrls } : {}),
|
|
399
422
|
changedFiles: cached?.changedFiles ?? [],
|
|
400
423
|
diff: cached?.diff ?? "",
|
|
401
424
|
};
|
|
@@ -403,7 +426,14 @@ async function pullRequests(client, options, previous, phase) {
|
|
|
403
426
|
current.changesRequested = cached.changesRequested;
|
|
404
427
|
}
|
|
405
428
|
const only = options.onlyRequestChangedPr;
|
|
406
|
-
|
|
429
|
+
// A row cached before comment links were kept is read again once, after
|
|
430
|
+
// the repository turned references on, so its rules get links.
|
|
431
|
+
const missingLinks = options.refreshCommentLinks === true &&
|
|
432
|
+
cached !== undefined &&
|
|
433
|
+
cached.commentUrls === undefined &&
|
|
434
|
+
cached.reviewCommentUrls === undefined &&
|
|
435
|
+
cached.reviewUrls === undefined;
|
|
436
|
+
const discussionUnchanged = cached?.updatedAt === current.updatedAt && !missingLinks;
|
|
407
437
|
const decisionKnown = typeof cached?.changesRequested === "boolean";
|
|
408
438
|
const diffUnchanged = cached?.headSha === current.headSha && Boolean(cached?.diff);
|
|
409
439
|
let droppedFromCache = only &&
|
|
@@ -412,28 +442,23 @@ async function pullRequests(client, options, previous, phase) {
|
|
|
412
442
|
let dropped = droppedFromCache;
|
|
413
443
|
const loadComments = async () => {
|
|
414
444
|
const comments = await client.pages(`repos/${options.repo}/issues/${number}/comments`);
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
.slice(0, options.maxComments);
|
|
445
|
+
const kept = textsWithLinks(comments, (comment) => String(comment.body ?? ""), options.maxComments);
|
|
446
|
+
current.comments = kept.texts;
|
|
447
|
+
current.commentUrls = kept.urls;
|
|
419
448
|
};
|
|
420
449
|
// Inline review comments carry most of the substantive feedback, and the
|
|
421
450
|
// reviewer only sees them if they are read here.
|
|
422
451
|
const loadReviewComments = async () => {
|
|
423
452
|
const comments = await client.pages(`repos/${options.repo}/pulls/${number}/comments`);
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
const line = String(comment.line ?? comment.original_line ?? "");
|
|
428
|
-
const body = String(comment.body ?? "");
|
|
429
|
-
return path ? `${path}:${line} ${body}` : body;
|
|
430
|
-
})
|
|
431
|
-
.filter(Boolean)
|
|
432
|
-
.slice(0, options.maxComments);
|
|
453
|
+
const kept = textsWithLinks(comments, reviewCommentText, options.maxComments);
|
|
454
|
+
current.reviewComments = kept.texts;
|
|
455
|
+
current.reviewCommentUrls = kept.urls;
|
|
433
456
|
};
|
|
434
457
|
const loadReviews = async () => {
|
|
435
458
|
const reviews = await client.pages(`repos/${options.repo}/pulls/${number}/reviews`);
|
|
436
|
-
|
|
459
|
+
const kept = reviewBodies(reviews);
|
|
460
|
+
current.reviews = kept.texts;
|
|
461
|
+
current.reviewUrls = kept.urls;
|
|
437
462
|
current.changesRequested = changesRequested(reviews);
|
|
438
463
|
};
|
|
439
464
|
if (!dropped && only && (!discussionUnchanged || !decisionKnown)) {
|
|
@@ -8,6 +8,12 @@ export type ReviewDocuments = {
|
|
|
8
8
|
* findings it merges. */
|
|
9
9
|
rules?: (GuideRule & {
|
|
10
10
|
pullRequests: number[];
|
|
11
|
+
/** The review comment links of the merged findings, when they were
|
|
12
|
+
* kept. A pull request with no link here shows as plain text. */
|
|
13
|
+
links?: {
|
|
14
|
+
pr: number;
|
|
15
|
+
url: string;
|
|
16
|
+
}[];
|
|
11
17
|
})[];
|
|
12
18
|
/** Check lines and how many of them got an id, per file. */
|
|
13
19
|
counts?: GuideFileCount[];
|
|
@@ -33,8 +39,25 @@ export declare function validateGuide(text: string, options?: {
|
|
|
33
39
|
/** The pull requests behind each finding in `guideMaterial`, by position, so
|
|
34
40
|
* finding `n` is `[n - 1]`. A review finding's evidence is `PR #12`. */
|
|
35
41
|
export declare function findingPullRequests(facts: Fact[]): number[][];
|
|
42
|
+
/** The review comment links behind each finding in `guideMaterial`, by
|
|
43
|
+
* position like `findingPullRequests`. Never sent to the model. */
|
|
44
|
+
export declare function findingLinks(facts: Fact[]): {
|
|
45
|
+
pr: number;
|
|
46
|
+
url: string;
|
|
47
|
+
}[][];
|
|
48
|
+
/** The last build's guide rules as the guide prompt sees them: id and text,
|
|
49
|
+
* never a pull request or a date. Empty when there were none, so a first
|
|
50
|
+
* build sends the same prompt as before. */
|
|
51
|
+
export declare function previousRulesMaterial(previous: Record<string, {
|
|
52
|
+
text: string;
|
|
53
|
+
}> | undefined): string;
|
|
36
54
|
/** Builds the review method with the high model. Returns `undefined` below the
|
|
37
55
|
* signal threshold, which is a data condition, not an AI failure. There is no
|
|
38
56
|
* deterministic fallback: a failed or unusable generation fails the run. */
|
|
39
|
-
export declare function synthesizeReviewGuides(provider: AiProvider, repo: string, ai: Options["ai"], model: string, concurrency: number, facts: Fact[], usage?: UsageSink
|
|
57
|
+
export declare function synthesizeReviewGuides(provider: AiProvider, repo: string, ai: Options["ai"], model: string, concurrency: number, facts: Fact[], usage?: UsageSink,
|
|
58
|
+
/** The last build's `RULES.json` rules, so the AI can say which old rule a
|
|
59
|
+
* new line goes against. */
|
|
60
|
+
previousRules?: Record<string, {
|
|
61
|
+
text: string;
|
|
62
|
+
}>): Promise<ReviewDocuments | undefined>;
|
|
40
63
|
export {};
|
|
@@ -160,6 +160,13 @@ export function findingPullRequests(facts) {
|
|
|
160
160
|
})),
|
|
161
161
|
]);
|
|
162
162
|
}
|
|
163
|
+
/** The review comment links behind each finding in `guideMaterial`, by
|
|
164
|
+
* position like `findingPullRequests`. Never sent to the model. */
|
|
165
|
+
export function findingLinks(facts) {
|
|
166
|
+
return guideFindings(facts)
|
|
167
|
+
.slice(0, MAX_FINDINGS)
|
|
168
|
+
.map((item) => item.links ?? []);
|
|
169
|
+
}
|
|
163
170
|
const GUIDE_SYSTEM = `You write a code-review method for an unfamiliar open-source repository.
|
|
164
171
|
Ground every check in the supplied findings. Never invent a file, path, command, or policy. Never write a pull-request number, a commit id, a reviewer name, a mention, a quoted comment, or an attribution. Never add a priority tag. Never tell the reader to run a command.`;
|
|
165
172
|
const CONSOLIDATE = `- Consolidate the findings into a small set of coherent passes: group related findings, merge near-duplicates, and use between 3 and 12 passes. Represent every finding. Never drop one to hit the pass count.
|
|
@@ -172,7 +179,23 @@ const CHECK_SHAPE = `- Under each pass, write each rule as one general invariant
|
|
|
172
179
|
- End each pass with \`**Exit check:**\` followed by its obligations, one per line, so a reviewer who sees only a diff can apply the rule:
|
|
173
180
|
- \`<trigger: a path, glob, or symbol>\` → <what must also change or be verified>
|
|
174
181
|
- Order passes and rules by how often the findings recur, most first. Prefer the general rule over a one-off, and keep the one-off as the example under it.`;
|
|
175
|
-
|
|
182
|
+
/** The last build's guide rules as the guide prompt sees them: id and text,
|
|
183
|
+
* never a pull request or a date. Empty when there were none, so a first
|
|
184
|
+
* build sends the same prompt as before. */
|
|
185
|
+
export function previousRulesMaterial(previous) {
|
|
186
|
+
const rules = Object.entries(previous ?? {})
|
|
187
|
+
.filter(([id]) => /^R[1-9]\d*$/.test(id))
|
|
188
|
+
.sort(([a], [b]) => Number(a.slice(1)) - Number(b.slice(1)))
|
|
189
|
+
.map(([id, entry]) => ({ id, rule: entry.text }));
|
|
190
|
+
return rules.length ? JSON.stringify(rules, null, 2) : "";
|
|
191
|
+
}
|
|
192
|
+
function fullGuideRequest(material, previous = "") {
|
|
193
|
+
const overturns = previous
|
|
194
|
+
? `
|
|
195
|
+
- PREVIOUS RULES lists the rules of the last build by id. When a rule line you write requires the opposite of a previous rule, put \`(overturns R4)\` with that id right before the line's bracket. Name only a previous rule the line clearly contradicts, never one it only rewords or extends.`
|
|
196
|
+
: "";
|
|
197
|
+
// Before FINDINGS, so the findings stay the last block of the prompt.
|
|
198
|
+
const previousBlock = previous ? `PREVIOUS RULES:\n${previous}\n\n` : "";
|
|
176
199
|
return {
|
|
177
200
|
job: "synth_guide",
|
|
178
201
|
maxTokens: 16_000,
|
|
@@ -182,10 +205,10 @@ function fullGuideRequest(material) {
|
|
|
182
205
|
- Start with one \`#\` title, one sentence of purpose, and one line on how to use the method.
|
|
183
206
|
${CONSOLIDATE}
|
|
184
207
|
${CHECK_SHAPE}
|
|
185
|
-
- End every rule line with the numbers of the findings it merges, in square brackets, for example [3, 17]. Each finding has a "number". Put these brackets on no other line
|
|
208
|
+
- End every rule line with the numbers of the findings it merges, in square brackets, for example [3, 17]. Each finding has a "number". Put these brackets on no other line.${overturns}
|
|
186
209
|
- No priority tags. No commands. No code fences. Return only the Markdown.
|
|
187
210
|
|
|
188
|
-
FINDINGS:
|
|
211
|
+
${previousBlock}FINDINGS:
|
|
189
212
|
${material}`,
|
|
190
213
|
};
|
|
191
214
|
}
|
|
@@ -220,7 +243,10 @@ function withTrailingNewline(text) {
|
|
|
220
243
|
/** Builds the review method with the high model. Returns `undefined` below the
|
|
221
244
|
* signal threshold, which is a data condition, not an AI failure. There is no
|
|
222
245
|
* deterministic fallback: a failed or unusable generation fails the run. */
|
|
223
|
-
export async function synthesizeReviewGuides(provider, repo, ai, model, concurrency, facts, usage
|
|
246
|
+
export async function synthesizeReviewGuides(provider, repo, ai, model, concurrency, facts, usage,
|
|
247
|
+
/** The last build's `RULES.json` rules, so the AI can say which old rule a
|
|
248
|
+
* new line goes against. */
|
|
249
|
+
previousRules) {
|
|
224
250
|
const findings = guideFindings(facts);
|
|
225
251
|
if (findings.length <= 2)
|
|
226
252
|
return undefined;
|
|
@@ -228,7 +254,7 @@ export async function synthesizeReviewGuides(provider, repo, ai, model, concurre
|
|
|
228
254
|
// No validator: the guide is kept as written. Losing the run over format is
|
|
229
255
|
// not worth it, and a later `sync` reuses the cached text.
|
|
230
256
|
const queue = new AiBatch(provider, repo, Math.max(1, concurrency), `${ai}:v3:${model}:guide`);
|
|
231
|
-
const [fullResponse] = await queue.run([fullGuideRequest(material)], usage);
|
|
257
|
+
const [fullResponse] = await queue.run([fullGuideRequest(material, previousRulesMaterial(previousRules))], usage);
|
|
232
258
|
const full = cleanGuide(fullResponse?.text ?? "");
|
|
233
259
|
if (!full) {
|
|
234
260
|
// Not a failure: SKILL.md and CODEBASE.md are written anyway.
|
|
@@ -236,21 +262,22 @@ export async function synthesizeReviewGuides(provider, repo, ai, model, concurre
|
|
|
236
262
|
return undefined;
|
|
237
263
|
}
|
|
238
264
|
const sources = findingPullRequests(facts);
|
|
265
|
+
const links = findingLinks(facts);
|
|
239
266
|
const fullLines = full.split("\n").length;
|
|
240
267
|
if (fullLines <= DETAIL_THRESHOLD_LINES) {
|
|
241
|
-
return withRuleIds(withTrailingNewline(full), undefined, sources);
|
|
268
|
+
return withRuleIds(withTrailingNewline(full), undefined, sources, links);
|
|
242
269
|
}
|
|
243
270
|
// The short guide is asked from the full method with its finding brackets
|
|
244
271
|
// still on, so it can carry them over to the lines it summarizes.
|
|
245
272
|
const [shortResponse] = await queue.run([shortGuideRequest(material, full)], usage);
|
|
246
273
|
const short = cleanGuide(shortResponse?.text ?? "");
|
|
247
274
|
if (!short)
|
|
248
|
-
return withRuleIds(withTrailingNewline(full), undefined, sources);
|
|
249
|
-
return withRuleIds(withTrailingNewline(short), full, sources);
|
|
275
|
+
return withRuleIds(withTrailingNewline(full), undefined, sources, links);
|
|
276
|
+
return withRuleIds(withTrailingNewline(short), full, sources, links);
|
|
250
277
|
}
|
|
251
278
|
/** Replaces the finding brackets with `R` ids and attaches each id's pull
|
|
252
279
|
* requests. */
|
|
253
|
-
function withRuleIds(guide, detailed, sources) {
|
|
280
|
+
function withRuleIds(guide, detailed, sources, links = []) {
|
|
254
281
|
const assigned = assignGuideIds(guide, detailed, sources.length);
|
|
255
282
|
return {
|
|
256
283
|
guide: assigned.guide,
|
|
@@ -260,6 +287,9 @@ function withRuleIds(guide, detailed, sources) {
|
|
|
260
287
|
pullRequests: [
|
|
261
288
|
...new Set(rule.findings.flatMap((n) => sources[n - 1] ?? [])),
|
|
262
289
|
].sort((a, b) => a - b),
|
|
290
|
+
links: rule.findings
|
|
291
|
+
.flatMap((n) => links[n - 1] ?? [])
|
|
292
|
+
.filter((link, index, all) => all.findIndex((other) => other.url === link.url) === index),
|
|
263
293
|
})),
|
|
264
294
|
counts: assigned.counts,
|
|
265
295
|
};
|
|
@@ -5,12 +5,21 @@ export type GuideRule = {
|
|
|
5
5
|
text: string;
|
|
6
6
|
/** 1-based numbers of the findings the line merges, sorted. */
|
|
7
7
|
findings: number[];
|
|
8
|
+
/** Previous rule ids the guide AI said this line goes against, from an
|
|
9
|
+
* `(overturns R4)` note before the bracket. The note is removed from the
|
|
10
|
+
* line. Code checks the ids exist and the new rule is newer. */
|
|
11
|
+
overturns?: string[];
|
|
8
12
|
};
|
|
9
13
|
export type GuideFileCount = {
|
|
10
14
|
file: string;
|
|
11
15
|
rules: number;
|
|
12
16
|
withIds: number;
|
|
13
17
|
};
|
|
18
|
+
/** The line without its overturns note, and the ids it named. */
|
|
19
|
+
export declare function takeOverturns(line: string): {
|
|
20
|
+
line: string;
|
|
21
|
+
ids: string[];
|
|
22
|
+
};
|
|
14
23
|
/** Gives every check line that ends in a usable source list an `R` id,
|
|
15
24
|
* numbered in file order. With a detailed guide, its lines are numbered first
|
|
16
25
|
* and a short-guide line with the same finding set shares that id. A line with
|