co-maintainer 0.7.0-beta.2 → 0.7.0-beta.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/github/gh.js +23 -2
- package/dist/src/local/codegraph_exclude.js +5 -3
- package/dist/src/local/codegraph_prepare.js +3 -1
- package/dist/src/pr/checkout.js +3 -2
- package/dist/src/pr/reviewer.js +12 -1
- package/dist/src/services/remote_review.js +11 -4
- package/package.json +1 -1
package/dist/package.json
CHANGED
package/dist/src/github/gh.js
CHANGED
|
@@ -62,6 +62,25 @@ function ghFailure(method, endpoint, stderr) {
|
|
|
62
62
|
}
|
|
63
63
|
return new CliError("gh_failed", `gh could not read ${endpoint}.`, `gh said: ${stderr}`, EXIT_RUNTIME);
|
|
64
64
|
}
|
|
65
|
+
/** A 404 for a pull request, when the repository itself can be read. gh says
|
|
66
|
+
* the same "Not Found" for both, so one more call tells them apart: without
|
|
67
|
+
* it a wrong number was reported as a repository that does not exist. */
|
|
68
|
+
async function missingPullRequest(endpoint, stderr) {
|
|
69
|
+
if (!/HTTP 404|Not Found/i.test(stderr))
|
|
70
|
+
return undefined;
|
|
71
|
+
const match = endpoint.match(/^(repos\/([^/]+)\/([^/]+))\/pulls\/(\d+)/);
|
|
72
|
+
if (!match)
|
|
73
|
+
return undefined;
|
|
74
|
+
try {
|
|
75
|
+
const repo = await runGh(["api", match[1]]);
|
|
76
|
+
if (!repo.success)
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
return new CliError("pull_request_not_found", `Pull request #${match[4]} was not found in ${match[2]}/${match[3]}.`, "Check the number.", EXIT_USAGE);
|
|
83
|
+
}
|
|
65
84
|
let lastCallAt = 0;
|
|
66
85
|
let pulse;
|
|
67
86
|
function count(value) {
|
|
@@ -190,8 +209,10 @@ export class GhClient {
|
|
|
190
209
|
const limited = bucket
|
|
191
210
|
? bucket.remaining === 0
|
|
192
211
|
: /rate limit/i.test(error);
|
|
193
|
-
if (!limited)
|
|
194
|
-
throw
|
|
212
|
+
if (!limited) {
|
|
213
|
+
throw ((await missingPullRequest(endpoint, error)) ??
|
|
214
|
+
ghFailure(method, endpoint, error));
|
|
215
|
+
}
|
|
195
216
|
const resetAt = bucket?.resetAt ?? new Date(Date.now() + RATE_LIMIT_PROBE_MS);
|
|
196
217
|
const delay = probeDelay(resetAt, Date.now());
|
|
197
218
|
if (delay === 0) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { dirname } from "node:path";
|
|
1
|
+
import { dirname, resolve } from "node:path";
|
|
2
2
|
import { isNotFound, mkdir, readTextFile, writeTextFile, } from "../util/runtime.js";
|
|
3
3
|
const EXCLUDE_LINE = "/.co-maintainer-codegraph/";
|
|
4
4
|
/** Hide the local codegraph index from git status. */
|
|
@@ -6,9 +6,11 @@ export async function ensureCodegraphGitExclude(gitRoot, run) {
|
|
|
6
6
|
const pathResult = await run("git", ["rev-parse", "--git-path", "info/exclude"], gitRoot);
|
|
7
7
|
if (pathResult.code !== 0)
|
|
8
8
|
return;
|
|
9
|
-
const
|
|
10
|
-
if (!
|
|
9
|
+
const gitPath = pathResult.stdout.trim();
|
|
10
|
+
if (!gitPath)
|
|
11
11
|
return;
|
|
12
|
+
// git answers relative to the repository, not to where the command runs.
|
|
13
|
+
const excludePath = resolve(gitRoot, gitPath);
|
|
12
14
|
let text = "";
|
|
13
15
|
try {
|
|
14
16
|
text = await readTextFile(excludePath);
|
|
@@ -9,7 +9,6 @@ export async function prepareLocalCodegraph(input) {
|
|
|
9
9
|
return { state: "disabled", reason: null, tools: [] };
|
|
10
10
|
}
|
|
11
11
|
const run = input.run ?? runCommand;
|
|
12
|
-
await ensureCodegraphGitExclude(input.gitRoot, run);
|
|
13
12
|
const resolved = await ensureCodegraphForReview({
|
|
14
13
|
allowInstall: input.allowInstall,
|
|
15
14
|
// The prompt is safe only when a human can answer it; `canPrompt` checks
|
|
@@ -21,6 +20,9 @@ export async function prepareLocalCodegraph(input) {
|
|
|
21
20
|
log("codegraph", `tools unavailable · ${resolved.reason}`);
|
|
22
21
|
return { state: "unavailable", reason: resolved.reason, tools: [] };
|
|
23
22
|
}
|
|
23
|
+
// Only once an index will be written: a review without codegraph leaves
|
|
24
|
+
// the user's .git/info/exclude alone.
|
|
25
|
+
await ensureCodegraphGitExclude(input.gitRoot, run);
|
|
24
26
|
const binary = resolved.path;
|
|
25
27
|
const cgRun = createCodegraphRunner(LOCAL_CODEGRAPH_DIR);
|
|
26
28
|
try {
|
package/dist/src/pr/checkout.js
CHANGED
|
@@ -50,11 +50,12 @@ async function cloneInto(repo, dir, run) {
|
|
|
50
50
|
]);
|
|
51
51
|
if (result.code !== 0) {
|
|
52
52
|
// One actionable line, not the raw multi-line git transcript: the caller
|
|
53
|
-
// only needs to know the clone failed and what it costs them.
|
|
53
|
+
// only needs to know the clone failed and what it costs them. git opens
|
|
54
|
+
// with "Cloning into '...'", which says nothing about why.
|
|
54
55
|
const firstLine = result.stderr
|
|
55
56
|
.split(/\r?\n/)
|
|
56
57
|
.map((line) => line.trim())
|
|
57
|
-
.find((line) => line.length > 0) ?? "";
|
|
58
|
+
.find((line) => line.length > 0 && !/^Cloning into /.test(line)) ?? "";
|
|
58
59
|
throw new Error(`git clone failed (exit ${result.code}) for ${repo}, so this review has no ` +
|
|
59
60
|
`repository scope and falls back to the diff only` +
|
|
60
61
|
(firstLine ? `: ${firstLine}` : ""));
|
package/dist/src/pr/reviewer.js
CHANGED
|
@@ -208,6 +208,17 @@ export async function readGuide(repo, name) {
|
|
|
208
208
|
return "";
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
|
+
/** `Promise.all`, except that when several fail the error is the first in
|
|
212
|
+
* list order, not the first in time. For a pull request that does not exist
|
|
213
|
+
* every read fails, and only the read of the pull request itself says so:
|
|
214
|
+
* the comments read is an `issues/N` endpoint, which names the repository. */
|
|
215
|
+
async function allInOrder(values) {
|
|
216
|
+
const settled = await Promise.allSettled(values);
|
|
217
|
+
const failed = settled.find((item) => item.status === "rejected");
|
|
218
|
+
if (failed)
|
|
219
|
+
throw failed.reason;
|
|
220
|
+
return settled.map((item) => item.value);
|
|
221
|
+
}
|
|
211
222
|
export async function reviewPullRequest(client, options, usage, snapshot, ai, progress, extras) {
|
|
212
223
|
if (!options.prNumber)
|
|
213
224
|
throw new Error("review requires a PR number");
|
|
@@ -215,7 +226,7 @@ export async function reviewPullRequest(client, options, usage, snapshot, ai, pr
|
|
|
215
226
|
const report = progress ?? (() => { });
|
|
216
227
|
report(modelSummary(options));
|
|
217
228
|
report(`loading PR context for ${options.repo}#${number}`);
|
|
218
|
-
const [pr, allComments, allReviews, guides] = await
|
|
229
|
+
const [pr, allComments, allReviews, guides] = await allInOrder([
|
|
219
230
|
extras?.prefetched?.pull ??
|
|
220
231
|
client.request(`repos/${options.repo}/pulls/${number}`),
|
|
221
232
|
client.pages(`repos/${options.repo}/issues/${number}/comments`),
|
|
@@ -4,7 +4,7 @@ import { resolvedFromFirstReview, reviewCoverageFields, sortResolvedFindings, su
|
|
|
4
4
|
import { parseFindings } from "../pr/findings.js";
|
|
5
5
|
import { codegraphToolHandlersForBridge } from "../pr/codegraph_tools.js";
|
|
6
6
|
import { reviewWorkspaceRevision } from "../pr/reviewer.js";
|
|
7
|
-
import { buildCarryPromptSection, classifyCarryItems, guideRebuiltSince, incrementalDiffPaths, } from "../review/carry_over.js";
|
|
7
|
+
import { buildCarryPromptSection, classifyCarryItems, guideRebuiltSince, incrementalDiffPaths, parsePreviousVerdicts, resolveCarryOutcomes, } from "../review/carry_over.js";
|
|
8
8
|
import { visiblePathsToSave } from "../review/visible_paths.js";
|
|
9
9
|
import { remoteBridgeToolHandlers } from "../remote/tool_bridge.js";
|
|
10
10
|
import { revisionFromSubmitJson } from "../remote/revision_from_submit.js";
|
|
@@ -320,6 +320,7 @@ export function registerRemoteReviewHandler() {
|
|
|
320
320
|
// file this run drops is sent by the next one.
|
|
321
321
|
const extras = { catchesUp: true };
|
|
322
322
|
let previousVisible;
|
|
323
|
+
let previous;
|
|
323
324
|
if (subjectId) {
|
|
324
325
|
const subjectRevision = getSubjectRevision(subjectId);
|
|
325
326
|
// A guide rebuilt after the previous review invalidates its verdicts
|
|
@@ -333,7 +334,7 @@ export function registerRemoteReviewHandler() {
|
|
|
333
334
|
extras.unchangedPaths = unchanged;
|
|
334
335
|
const storedRows = listCarryableFindingsForReview(subjectRevision.review_id);
|
|
335
336
|
previousVisible = parseVisiblePaths(subjectRevision);
|
|
336
|
-
const carryPrevious = {
|
|
337
|
+
const carryPrevious = (previous = {
|
|
337
338
|
files: prevFiles,
|
|
338
339
|
visiblePaths: previousVisible,
|
|
339
340
|
findings: storedRows.map((row) => ({
|
|
@@ -348,7 +349,7 @@ export function registerRemoteReviewHandler() {
|
|
|
348
349
|
firstSeenReviewId: row.first_seen_review_id ?? subjectRevision.review_id,
|
|
349
350
|
})),
|
|
350
351
|
guideBuiltAt: subjectRevision.guide_built_at,
|
|
351
|
-
};
|
|
352
|
+
});
|
|
352
353
|
const carryItems = classifyCarryItems(carryPrevious, revision, carryPrevious.visiblePaths, null);
|
|
353
354
|
extras.carryPrompt = buildCarryPromptSection(carryItems, revision);
|
|
354
355
|
}
|
|
@@ -380,7 +381,13 @@ export function registerRemoteReviewHandler() {
|
|
|
380
381
|
return;
|
|
381
382
|
const parsed = parseFindings(result.text);
|
|
382
383
|
const filesByPath = new Map(revision.files.map((file) => [file.path, { patch: file.patch }]));
|
|
383
|
-
|
|
384
|
+
// A later round also applies the model's verdicts on the earlier
|
|
385
|
+
// findings, as a local review does. Reading only the new ones dropped
|
|
386
|
+
// a finding the model kept open, for good.
|
|
387
|
+
const visible = new Set(result.visiblePaths);
|
|
388
|
+
const findings = sortResolvedFindings(previous
|
|
389
|
+
? resolveCarryOutcomes(classifyCarryItems(previous, revision, visible, result.guideBuiltAt), revision, visible, parsePreviousVerdicts(result.text), parsed)
|
|
390
|
+
: resolvedFromFirstReview(parsed, filesByPath));
|
|
384
391
|
const durationMs = Math.round(performance.now() - started);
|
|
385
392
|
const blockingMode = reviewBlockingFrom(options.reviewBlocking);
|
|
386
393
|
// The plan ran here, on the patches the client submitted, so the
|