co-maintainer 0.6.13 → 0.7.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/package.json +1 -1
- package/dist/src/ai/anthropic.js +2 -0
- package/dist/src/ai/batch.d.ts +3 -1
- package/dist/src/ai/batch.js +23 -2
- package/dist/src/ai/mermaid_loop.js +1 -1
- package/dist/src/ai/oauth/sign-in-with-chatgpt.js +8 -10
- package/dist/src/ai/openai.js +2 -0
- package/dist/src/ai/openrouter.js +2 -0
- package/dist/src/cli/args.js +47 -0
- package/dist/src/cli/command_json.d.ts +20 -1
- package/dist/src/cli/command_json.js +4 -0
- package/dist/src/cli/commands/config.d.ts +1 -1
- package/dist/src/cli/commands/config.js +1 -0
- package/dist/src/cli/commands/registry.js +226 -1
- package/dist/src/cli/commands/review.js +50 -9
- package/dist/src/cli/commands/serve.js +5 -0
- package/dist/src/cli/commands/set.js +70 -2
- package/dist/src/cli/commands/view.js +46 -5
- package/dist/src/cli/commands/view_sources.d.ts +11 -0
- package/dist/src/cli/commands/view_sources.js +40 -0
- package/dist/src/cli/main.js +5 -0
- package/dist/src/cli/pr_carry.d.ts +25 -0
- package/dist/src/cli/pr_carry.js +128 -0
- package/dist/src/cli/prompt.js +26 -1
- package/dist/src/cli/review_args.d.ts +8 -0
- package/dist/src/cli/review_args.js +18 -0
- package/dist/src/cli/review_carry.d.ts +32 -0
- package/dist/src/cli/review_carry.js +60 -0
- package/dist/src/cli/review_github.d.ts +16 -2
- package/dist/src/cli/review_github.js +49 -12
- package/dist/src/cli/review_intent.d.ts +25 -0
- package/dist/src/cli/review_intent.js +87 -0
- package/dist/src/cli/review_result.d.ts +53 -2
- package/dist/src/cli/review_result.js +90 -23
- package/dist/src/config.d.ts +27 -0
- package/dist/src/config.js +20 -12
- package/dist/src/extensions/command.d.ts +1 -0
- package/dist/src/extensions/command.js +355 -0
- package/dist/src/extensions/contexts.d.ts +65 -0
- package/dist/src/extensions/contexts.js +134 -0
- package/dist/src/extensions/cost.d.ts +8 -0
- package/dist/src/extensions/cost.js +6 -0
- package/dist/src/extensions/local_tracking.d.ts +7 -0
- package/dist/src/extensions/local_tracking.js +29 -0
- package/dist/src/extensions/mock.d.ts +29 -0
- package/dist/src/extensions/mock.js +67 -0
- package/dist/src/extensions/process.d.ts +43 -0
- package/dist/src/extensions/process.js +244 -0
- package/dist/src/extensions/registry.d.ts +79 -0
- package/dist/src/extensions/registry.js +240 -0
- package/dist/src/extensions/render_actions.d.ts +6 -0
- package/dist/src/extensions/render_actions.js +50 -0
- package/dist/src/extensions/render_cli.d.ts +18 -0
- package/dist/src/extensions/render_cli.js +88 -0
- package/dist/src/extensions/render_json.d.ts +51 -0
- package/dist/src/extensions/render_json.js +144 -0
- package/dist/src/extensions/render_markdown.d.ts +22 -0
- package/dist/src/extensions/render_markdown.js +96 -0
- package/dist/src/extensions/render_review.d.ts +44 -0
- package/dist/src/extensions/render_review.js +167 -0
- package/dist/src/extensions/report.d.ts +57 -0
- package/dist/src/extensions/report.js +97 -0
- package/dist/src/extensions/review_result.d.ts +2 -0
- package/dist/src/extensions/review_result.js +14 -0
- package/dist/src/extensions/run_folder.d.ts +74 -0
- package/dist/src/extensions/run_folder.js +172 -0
- package/dist/src/extensions/runner.d.ts +66 -0
- package/dist/src/extensions/runner.js +251 -0
- package/dist/src/extensions/schema.d.ts +103 -0
- package/dist/src/extensions/schema.js +539 -0
- package/dist/src/extensions/session.d.ts +56 -0
- package/dist/src/extensions/session.js +173 -0
- package/dist/src/github/collect.d.ts +7 -2
- package/dist/src/github/collect.js +66 -6
- package/dist/src/github/gh.d.ts +7 -0
- package/dist/src/github/gh.js +24 -29
- package/dist/src/knowledge/guide.js +3 -2
- package/dist/src/knowledge/instruction_files.d.ts +45 -0
- package/dist/src/knowledge/instruction_files.js +91 -0
- package/dist/src/knowledge/instructions.d.ts +78 -0
- package/dist/src/knowledge/instructions.js +280 -0
- package/dist/src/knowledge/rule_changes.d.ts +39 -0
- package/dist/src/knowledge/rule_changes.js +90 -0
- package/dist/src/knowledge/rules.d.ts +44 -0
- package/dist/src/knowledge/rules.js +82 -0
- package/dist/src/knowledge/synthesis.d.ts +1 -0
- package/dist/src/knowledge/synthesis.js +12 -5
- package/dist/src/knowledge/types.d.ts +4 -0
- package/dist/src/local/carry_over_store.d.ts +10 -0
- package/dist/src/local/carry_over_store.js +17 -0
- package/dist/src/local/review_local.js +100 -62
- package/dist/src/local/review_lock.js +15 -4
- package/dist/src/pr/diff_plan.d.ts +110 -0
- package/dist/src/pr/diff_plan.js +429 -0
- package/dist/src/pr/diff_summary.d.ts +17 -1
- package/dist/src/pr/diff_summary.js +87 -13
- package/dist/src/pr/review_diff.d.ts +47 -0
- package/dist/src/pr/review_diff.js +112 -0
- package/dist/src/pr/reviewer.d.ts +44 -19
- package/dist/src/pr/reviewer.js +114 -142
- package/dist/src/remote/client.js +67 -8
- package/dist/src/remote/http.d.ts +12 -0
- package/dist/src/remote/http.js +31 -0
- package/dist/src/remote/push_client.js +14 -3
- package/dist/src/remote/server/guides.js +12 -1
- package/dist/src/remote/server/routes.js +4 -2
- package/dist/src/remote/server/sessions.js +4 -1
- package/dist/src/remote/validate.js +11 -0
- package/dist/src/review/carry_over.d.ts +6 -1
- package/dist/src/review/carry_over.js +10 -2
- package/dist/src/review/coverage.d.ts +57 -0
- package/dist/src/review/coverage.js +186 -0
- package/dist/src/review/diagram.d.ts +73 -0
- package/dist/src/review/diagram.js +309 -0
- package/dist/src/review/engine.d.ts +2 -6
- package/dist/src/review/engine.js +1 -1
- package/dist/src/review/guides.d.ts +6 -0
- package/dist/src/review/guides.js +8 -1
- package/dist/src/review/intent.d.ts +24 -0
- package/dist/src/review/intent.js +28 -0
- package/dist/src/review/not_initialized.d.ts +13 -0
- package/dist/src/review/not_initialized.js +18 -0
- package/dist/src/review/system_prompt.d.ts +6 -0
- package/dist/src/review/system_prompt.js +13 -0
- package/dist/src/review/visible_paths.d.ts +22 -0
- package/dist/src/review/visible_paths.js +41 -0
- package/dist/src/server/pages/extensions.d.ts +5 -0
- package/dist/src/server/pages/extensions.js +72 -0
- package/dist/src/server/pages/pr.js +3 -2
- package/dist/src/services/dashboard.d.ts +8 -0
- package/dist/src/services/dashboard.js +8 -0
- package/dist/src/services/push_review.js +14 -5
- package/dist/src/services/remote_review.js +81 -26
- package/dist/src/services/replies.js +15 -8
- package/dist/src/services/review.d.ts +9 -3
- package/dist/src/services/review.js +109 -28
- package/dist/src/services/rules_build.d.ts +46 -0
- package/dist/src/services/rules_build.js +155 -0
- package/dist/src/services/setup.d.ts +31 -0
- package/dist/src/services/setup.js +120 -25
- package/dist/src/services/watch_comments.js +2 -0
- package/dist/src/store/cache_db.js +3 -0
- package/dist/src/store/extensions.d.ts +51 -0
- package/dist/src/store/extensions.js +132 -0
- package/dist/src/store/migrations.js +40 -0
- package/dist/src/types.d.ts +22 -1
- package/dist/src/util/atomic.d.ts +15 -1
- package/dist/src/util/atomic.js +59 -29
- package/dist/src/util/interrupt.d.ts +6 -0
- package/dist/src/util/interrupt.js +27 -0
- package/dist/src/util/runtime.d.ts +3 -1
- package/dist/src/util/runtime.js +2 -2
- package/dist/src/util/test_location_guard.d.ts +6 -0
- package/dist/src/util/test_location_guard.js +47 -0
- package/package.json +1 -1
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { parseArgs } from "../cli/args.js";
|
|
2
2
|
import { filterReviewConfigArgs, loadReviewSystemPromptFlags, reviewSystemPromptLimitFor, } from "../cli/review_args.js";
|
|
3
|
-
import { buildLocalReviewJson, formatHumanLocalReview, humanFindingsFromResolved,
|
|
3
|
+
import { buildLocalReviewJson, formatHumanLocalReview, humanFindingsFromResolved, reviewExitCodeFromResolved, } from "../cli/review_result.js";
|
|
4
4
|
import { addAiMetrics, emptyAiMetrics, recordAiCost, runInitOrRemake, } from "../services/setup.js";
|
|
5
5
|
import { aiFor } from "../services/review.js";
|
|
6
6
|
import { loadGuides } from "../review/guides.js";
|
|
7
|
-
import {
|
|
7
|
+
import { hasGuides, notInitializedError } from "../review/not_initialized.js";
|
|
8
|
+
import { guideRebuiltSince } from "../review/carry_over.js";
|
|
9
|
+
import { finishCarryRun, startCarryRun, storedFindings, } from "../cli/review_carry.js";
|
|
8
10
|
import { revisionHash } from "../review/revision.js";
|
|
9
|
-
import {
|
|
11
|
+
import { intentRecord, loadIntentFlag } from "../cli/review_intent.js";
|
|
10
12
|
import { reviewWorkspaceRevision } from "../pr/reviewer.js";
|
|
11
13
|
import { runCommand } from "../pr/checkout.js";
|
|
12
14
|
import { log, startHeartbeat, timed, withCliLogsToStderr, } from "../util/log.js";
|
|
@@ -18,24 +20,15 @@ import { canPrompt } from "../tools/codegraph.js";
|
|
|
18
20
|
import { acquireLocalReviewLock } from "./review_lock.js";
|
|
19
21
|
import { assertGitQuiet, currentBranch, detectRemoteRepo, gitRoot, headSha, ReviewCliError, } from "./git_ops.js";
|
|
20
22
|
import { EXIT_RUNTIME, exitWith } from "../cli/error.js";
|
|
23
|
+
import { armInterrupt, disarmInterrupt, interrupted, } from "../util/interrupt.js";
|
|
21
24
|
import { buildLocalRevision, mergeBase, resolveBaseRef, } from "./git_revision.js";
|
|
22
25
|
import { clearLocalCarry, localSubjectId, saveLocalCarry, tryLoadLocalCarry, } from "./carry_over_store.js";
|
|
23
26
|
import { costUsage } from "../util/cost.js";
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
path: row.path,
|
|
30
|
-
lineFrom: row.lineFrom,
|
|
31
|
-
lineTo: row.lineTo,
|
|
32
|
-
title: row.title,
|
|
33
|
-
bodyMd: row.bodyMd,
|
|
34
|
-
anchorText: row.anchorText,
|
|
35
|
-
severity: row.severity,
|
|
36
|
-
firstSeenReviewId: row.firstSeenReviewId,
|
|
37
|
-
}));
|
|
38
|
-
}
|
|
27
|
+
import { withExtensions } from "../extensions/session.js";
|
|
28
|
+
import { localContext } from "../extensions/contexts.js";
|
|
29
|
+
import { reviewResultJson } from "../extensions/review_result.js";
|
|
30
|
+
import { exitCodeWithExtensions, } from "../extensions/report.js";
|
|
31
|
+
import { runSummaryWithExtensions } from "../extensions/render_json.js";
|
|
39
32
|
function fail(error, json) {
|
|
40
33
|
if (json) {
|
|
41
34
|
console.log(JSON.stringify({
|
|
@@ -54,8 +47,26 @@ function fail(error, json) {
|
|
|
54
47
|
// Windows whenever a fetch pool is open.
|
|
55
48
|
exitWith(error.exitCode);
|
|
56
49
|
}
|
|
50
|
+
/** Ctrl-C stops the review: the lock is released, `--json` gets the one
|
|
51
|
+
* "aborted" document, the exit code is 3, and the armed interrupt aborts the
|
|
52
|
+
* model call in flight so the event loop drains and the process ends. The
|
|
53
|
+
* review checks `interrupted()` before it prints or saves anything, so no
|
|
54
|
+
* second output follows. A second Ctrl-C meets Node's default and ends the
|
|
55
|
+
* process at once, as it does for `review --remote`. */
|
|
57
56
|
function installInterruptCleanup(releaseSync, json) {
|
|
57
|
+
const controller = armInterrupt();
|
|
58
|
+
const remove = () => {
|
|
59
|
+
for (const signal of ["SIGINT", "SIGTERM"]) {
|
|
60
|
+
try {
|
|
61
|
+
process.removeListener(signal, onSignal);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// ignore
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
58
68
|
const onSignal = () => {
|
|
69
|
+
remove();
|
|
59
70
|
releaseSync()?.();
|
|
60
71
|
if (json) {
|
|
61
72
|
console.log(JSON.stringify({
|
|
@@ -69,6 +80,7 @@ function installInterruptCleanup(releaseSync, json) {
|
|
|
69
80
|
}));
|
|
70
81
|
}
|
|
71
82
|
exitWith(EXIT_RUNTIME);
|
|
83
|
+
controller.abort();
|
|
72
84
|
};
|
|
73
85
|
for (const signal of ["SIGINT", "SIGTERM"]) {
|
|
74
86
|
try {
|
|
@@ -79,14 +91,8 @@ function installInterruptCleanup(releaseSync, json) {
|
|
|
79
91
|
}
|
|
80
92
|
}
|
|
81
93
|
return () => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
process.removeListener(signal, onSignal);
|
|
85
|
-
}
|
|
86
|
-
catch {
|
|
87
|
-
// ignore
|
|
88
|
-
}
|
|
89
|
-
}
|
|
94
|
+
remove();
|
|
95
|
+
disarmInterrupt();
|
|
90
96
|
};
|
|
91
97
|
}
|
|
92
98
|
export async function runLocalReview(cli) {
|
|
@@ -110,15 +116,21 @@ export async function runLocalReview(cli) {
|
|
|
110
116
|
const promptFlags = await loadReviewSystemPromptFlags(cli, reviewSystemPromptLimitFor(repo));
|
|
111
117
|
options.reviewSystemPromptAdd = promptFlags.add;
|
|
112
118
|
options.reviewSystemPromptOverride = promptFlags.override;
|
|
119
|
+
const intentLoad = await loadIntentFlag(cli.intentFile, reviewSystemPromptLimitFor(repo));
|
|
113
120
|
const guides = await loadGuides(repo);
|
|
114
|
-
if (!guides
|
|
115
|
-
|
|
121
|
+
if (!hasGuides(guides)) {
|
|
122
|
+
// A `ReviewCliError`, so `fail()` below prints it the way local review
|
|
123
|
+
// always has, without the `[error] ` prefix the top level adds.
|
|
124
|
+
const missing = notInitializedError(repo);
|
|
125
|
+
throw new ReviewCliError(missing.code, missing.message, missing.hint, missing.exitCode);
|
|
116
126
|
}
|
|
117
127
|
if (cli.remakeBeforeReview) {
|
|
118
128
|
if (options.auth !== "gh") {
|
|
119
129
|
throw new ReviewCliError("usage", "Sync before review requires GitHub CLI authentication (`--auth=gh`).");
|
|
120
130
|
}
|
|
121
131
|
await runInitOrRemake({ ...options, command: "remake" });
|
|
132
|
+
if (interrupted())
|
|
133
|
+
return;
|
|
122
134
|
}
|
|
123
135
|
const remotes = await runCommand("git", ["remote"], root);
|
|
124
136
|
const remoteName = ["upstream", "origin"].find((n) => remotes.stdout
|
|
@@ -133,10 +145,17 @@ export async function runLocalReview(cli) {
|
|
|
133
145
|
const baseSha = await mergeBase(root, base.ref, remoteName, runCommand);
|
|
134
146
|
const built = await buildLocalRevision(root, baseSha, base.label, runCommand);
|
|
135
147
|
let revision = built.revision;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
148
|
+
// The intent rides in the revision's description, which a local
|
|
149
|
+
// revision leaves empty, and the prompt's WORKSPACE block carries it.
|
|
150
|
+
if (intentLoad.intent) {
|
|
151
|
+
revision = { ...revision, description: intentLoad.intent.text };
|
|
152
|
+
}
|
|
153
|
+
const warnings = [
|
|
154
|
+
...built.warnings.map((w) => ({ code: w.code, message: w.message })),
|
|
155
|
+
...intentLoad.warnings,
|
|
156
|
+
];
|
|
157
|
+
if (interrupted())
|
|
158
|
+
return;
|
|
140
159
|
if (revision.files.length === 0) {
|
|
141
160
|
if (json) {
|
|
142
161
|
console.log(JSON.stringify({
|
|
@@ -149,7 +168,10 @@ export async function runLocalReview(cli) {
|
|
|
149
168
|
else {
|
|
150
169
|
console.log("No changes to review.");
|
|
151
170
|
}
|
|
171
|
+
// `exitWith` only sets the code. Without the return the review went
|
|
172
|
+
// on with an empty diff, called the model and printed a second report.
|
|
152
173
|
exitWith(0);
|
|
174
|
+
return;
|
|
153
175
|
}
|
|
154
176
|
const subjectId = localSubjectId(repo, root, branch);
|
|
155
177
|
if (cli.fresh)
|
|
@@ -171,21 +193,10 @@ export async function runLocalReview(cli) {
|
|
|
171
193
|
await clearLocalCarry(repo, root, branch).catch(() => { });
|
|
172
194
|
previous = null;
|
|
173
195
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
carryPrevious = {
|
|
179
|
-
files: previous.files,
|
|
180
|
-
visiblePaths: new Set(previous.visiblePaths),
|
|
181
|
-
findings: previous.findings,
|
|
182
|
-
guideBuiltAt: previous.guideBuiltAt,
|
|
183
|
-
};
|
|
184
|
-
const { unchanged } = incrementalDiffPaths(revision, previous.files);
|
|
185
|
-
extras.unchangedPaths = unchanged;
|
|
186
|
-
carryItems = classifyCarryItems(carryPrevious, revision, carryPrevious.visiblePaths, guides.guideBuiltAt);
|
|
187
|
-
extras.carryPrompt = buildCarryPromptSection(carryItems, revision);
|
|
188
|
-
}
|
|
196
|
+
const carryRun = startCarryRun(previous, revision, guides.guideBuiltAt);
|
|
197
|
+
// Local carry-over leaves out what the last run saw, so a file this
|
|
198
|
+
// run drops is sent by the next one.
|
|
199
|
+
const extras = { ...carryRun.extras, catchesUp: true };
|
|
189
200
|
const sha = await headSha(root);
|
|
190
201
|
const revisionHashBefore = await revisionHash(revision);
|
|
191
202
|
lock = await acquireLocalReviewLock(root);
|
|
@@ -197,16 +208,29 @@ export async function runLocalReview(cli) {
|
|
|
197
208
|
// `canPrompt` adds the TTY and CI checks.
|
|
198
209
|
interactive: !json && canPrompt(),
|
|
199
210
|
});
|
|
211
|
+
// Ctrl-C at the install prompt or during the index: stop before the
|
|
212
|
+
// model call. The handler has released the lock.
|
|
213
|
+
if (interrupted())
|
|
214
|
+
return;
|
|
200
215
|
extras.prepareCodegraphTools = () => Promise.resolve(codegraphPrep.tools);
|
|
201
216
|
const stopHeartbeat = startHeartbeat("reviewing local changes");
|
|
202
217
|
const started = performance.now();
|
|
203
218
|
const aiMetrics = emptyAiMetrics();
|
|
204
219
|
let response;
|
|
220
|
+
let extensions;
|
|
205
221
|
try {
|
|
206
|
-
|
|
222
|
+
({ review: response, extensions } = await withExtensions(localContext({
|
|
223
|
+
repo,
|
|
224
|
+
branch,
|
|
225
|
+
root,
|
|
226
|
+
headSha: sha,
|
|
227
|
+
baseSha,
|
|
228
|
+
revision,
|
|
229
|
+
fresh: cli.fresh,
|
|
230
|
+
}), () => timed("local review AI", options.logTime, () => reviewWorkspaceRevision(revision, options, sha, async (usage) => {
|
|
207
231
|
addAiMetrics(aiMetrics, usage);
|
|
208
232
|
await recordAiCost(repo, "review_local", usage);
|
|
209
|
-
}, aiFor(options), (message) => log("review", message), extras));
|
|
233
|
+
}, aiFor(options), (message) => log("review", message), extras)), (result) => reviewResultJson(result.text, options.reviewBlocking)));
|
|
210
234
|
}
|
|
211
235
|
finally {
|
|
212
236
|
// Stopping the heartbeat on the error path too, otherwise the interval
|
|
@@ -215,19 +239,18 @@ export async function runLocalReview(cli) {
|
|
|
215
239
|
await lock?.release();
|
|
216
240
|
lock = null;
|
|
217
241
|
}
|
|
242
|
+
// Ctrl-C during the model call: the handler has printed the one output
|
|
243
|
+
// and set the exit code, so nothing is saved or printed after it.
|
|
244
|
+
if (interrupted())
|
|
245
|
+
return;
|
|
218
246
|
const codegraphState = codegraphPrep.state;
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
carryItems = classifyCarryItems(carryPrevious, revision, visiblePaths, response.guideBuiltAt);
|
|
222
|
-
}
|
|
223
|
-
const parsed = parseFindings(response.text);
|
|
224
|
-
const filesByPath = new Map(revision.files.map((f) => [f.path, f]));
|
|
225
|
-
const allResolved = carryPrevious
|
|
226
|
-
? resolveCarryOutcomes(carryItems, revision, visiblePaths, parsePreviousVerdicts(response.text), parsed)
|
|
227
|
-
: resolvedFromFirstReview(parsed, filesByPath);
|
|
247
|
+
warnings.push(...response.warnings);
|
|
248
|
+
const { resolved: allResolved, visiblePaths } = finishCarryRun(carryRun, revision, response);
|
|
228
249
|
const findingsToStore = storedFindings(allResolved);
|
|
229
250
|
const afterBuilt = await buildLocalRevision(root, baseSha, base.label, runCommand);
|
|
230
251
|
const revisionHashAfter = await revisionHash(afterBuilt.revision);
|
|
252
|
+
if (interrupted())
|
|
253
|
+
return;
|
|
231
254
|
if (revisionHashAfter !== revisionHashBefore) {
|
|
232
255
|
warnings.push({
|
|
233
256
|
code: "working_tree_changed",
|
|
@@ -249,6 +272,8 @@ export async function runLocalReview(cli) {
|
|
|
249
272
|
message: "Could not save local carry-over state for the next review.",
|
|
250
273
|
});
|
|
251
274
|
}
|
|
275
|
+
if (interrupted())
|
|
276
|
+
return;
|
|
252
277
|
const header = `co-maintainer review · ${repo} · ${branch} → ${base.label}`;
|
|
253
278
|
const durationMs = Math.round(performance.now() - started);
|
|
254
279
|
const usage = {
|
|
@@ -256,6 +281,7 @@ export async function runLocalReview(cli) {
|
|
|
256
281
|
tokensOut: aiMetrics.tokensOut,
|
|
257
282
|
...costUsage(aiMetrics),
|
|
258
283
|
};
|
|
284
|
+
const run = runSummaryWithExtensions(summaryFromMetrics(aiMetrics, performance.now() - started), extensions);
|
|
259
285
|
if (json) {
|
|
260
286
|
console.log(buildLocalReviewJson({
|
|
261
287
|
repo,
|
|
@@ -270,24 +296,36 @@ export async function runLocalReview(cli) {
|
|
|
270
296
|
usage,
|
|
271
297
|
durationMs,
|
|
272
298
|
reviewBlocking: options.reviewBlocking,
|
|
299
|
+
coverage: response.coverage,
|
|
300
|
+
extensions,
|
|
301
|
+
includeExtensionMarkdowns: cli.includeExtensionMarkdowns,
|
|
302
|
+
intent: intentRecord(intentLoad.intent),
|
|
273
303
|
}));
|
|
274
304
|
}
|
|
275
305
|
else if (cli.output === "github") {
|
|
276
306
|
emitGithubOutput({
|
|
277
307
|
title: header,
|
|
278
308
|
findings: humanFindingsFromResolved(allResolved, options.reviewBlocking),
|
|
279
|
-
run
|
|
309
|
+
run,
|
|
310
|
+
coverage: response.coverage,
|
|
311
|
+
catchesUp: true,
|
|
312
|
+
extensions,
|
|
313
|
+
intent: Boolean(intentLoad.intent),
|
|
280
314
|
});
|
|
281
315
|
}
|
|
282
316
|
else {
|
|
283
317
|
console.log("\n" +
|
|
284
|
-
formatHumanLocalReview(header, revision, response.guideBuiltAt, codegraphState, allResolved, warnings, options.reviewBlocking) +
|
|
318
|
+
formatHumanLocalReview(header, revision, response.guideBuiltAt, codegraphState, allResolved, warnings, options.reviewBlocking, response.coverage, extensions, Boolean(intentLoad.intent)) +
|
|
285
319
|
"\n");
|
|
286
|
-
printRunSummary(
|
|
320
|
+
printRunSummary(run);
|
|
287
321
|
}
|
|
288
|
-
exitWith(reviewExitCodeFromResolved(allResolved, options.reviewBlocking));
|
|
322
|
+
exitWith(exitCodeWithExtensions(reviewExitCodeFromResolved(allResolved, options.reviewBlocking), extensions));
|
|
289
323
|
}
|
|
290
324
|
catch (error) {
|
|
325
|
+
// After Ctrl-C the aborted model call or sync throws. The handler has
|
|
326
|
+
// already printed the one output and set the exit code.
|
|
327
|
+
if (interrupted())
|
|
328
|
+
return;
|
|
291
329
|
if (error instanceof ReviewCliError) {
|
|
292
330
|
fail(error, json);
|
|
293
331
|
return;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { locksDir } from "../config.js";
|
|
2
2
|
import { ReviewCliError } from "./git_ops.js";
|
|
3
|
-
import { isNotFound, isProcessAlive, mkdir, readTextFile, remove, removeSync, writeTextFile, } from "../util/runtime.js";
|
|
3
|
+
import { isNotFound, isProcessAlive, mkdir, readTextFile, readTextFileSync, remove, removeSync, writeTextFile, } from "../util/runtime.js";
|
|
4
4
|
async function lockPath(gitRoot) {
|
|
5
5
|
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(gitRoot));
|
|
6
6
|
const hex = [...new Uint8Array(digest)]
|
|
@@ -27,10 +27,15 @@ export async function acquireLocalReviewLock(gitRoot) {
|
|
|
27
27
|
isProcessAlive(existingPid)) {
|
|
28
28
|
throw new ReviewCliError("usage", `Another co-maintainer review is running in this repository (PID ${existingPid}).`);
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
const pid = String(process.pid);
|
|
31
|
+
await writeTextFile(path, pid);
|
|
32
|
+
// Ctrl-C releases the lock while this process may still be finishing. A
|
|
33
|
+
// review started in that window writes its own PID here, so a release only
|
|
34
|
+
// removes a lock that still names this process.
|
|
31
35
|
const releaseSync = () => {
|
|
32
36
|
try {
|
|
33
|
-
|
|
37
|
+
if (readTextFileSync(path).trim() === pid)
|
|
38
|
+
removeSync(path);
|
|
34
39
|
}
|
|
35
40
|
catch {
|
|
36
41
|
// already removed
|
|
@@ -38,7 +43,13 @@ export async function acquireLocalReviewLock(gitRoot) {
|
|
|
38
43
|
};
|
|
39
44
|
return {
|
|
40
45
|
release: async () => {
|
|
41
|
-
|
|
46
|
+
try {
|
|
47
|
+
if ((await readTextFile(path)).trim() === pid)
|
|
48
|
+
await remove(path);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// already removed
|
|
52
|
+
}
|
|
42
53
|
},
|
|
43
54
|
releaseSync,
|
|
44
55
|
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** The diff plan: which state each changed file reaches the model in, decided
|
|
2
|
+
* before any model call so nothing is cut blindly. Every file ends in exactly
|
|
3
|
+
* one state, and the joined DIFF section fits in `MAX_REVIEW_DIFF_CHARS`.
|
|
4
|
+
*
|
|
5
|
+
* - `full`: the whole patch.
|
|
6
|
+
* - `partial`: the first `MAX_FILE_PATCH_CHARS` characters, cut at a line.
|
|
7
|
+
* - `summarized`: a low-model summary.
|
|
8
|
+
* - `dropped`: only its path and counts, under NOT SHOWN.
|
|
9
|
+
* - `withheld`: GitHub sent no patch, so there is nothing to show.
|
|
10
|
+
*
|
|
11
|
+
* This file is pure. The model calls live in `review_diff.ts`. */
|
|
12
|
+
import type { Json } from "../types.ts";
|
|
13
|
+
import type { RevisionFile, Revision } from "../review/revision.ts";
|
|
14
|
+
import type { Coverage } from "../review/coverage.ts";
|
|
15
|
+
/** A longer patch is shown up to here and marked `partial`. */
|
|
16
|
+
export declare const MAX_FILE_PATCH_CHARS = 12000;
|
|
17
|
+
/** The whole DIFF section never grows past this. */
|
|
18
|
+
export declare const MAX_REVIEW_DIFF_CHARS = 240000;
|
|
19
|
+
/** What the plan counts for one summary before the summary exists. The real
|
|
20
|
+
* length is checked again once the summaries come back. */
|
|
21
|
+
export declare const PLANNED_SUMMARY_CHARS = 700;
|
|
22
|
+
/** Only a patch longer than this is summarized. A shorter one saves too little
|
|
23
|
+
* room to be worth a model call and the loss of its code, so it is shown in
|
|
24
|
+
* full or dropped. */
|
|
25
|
+
export declare const SUMMARY_MIN_PATCH_CHARS = 4000;
|
|
26
|
+
/** At most this many summaries per review, largest files first. Each is one
|
|
27
|
+
* low-model call, and a review made of summaries has no code to judge. */
|
|
28
|
+
export declare const MAX_SUMMARIES = 40;
|
|
29
|
+
export type FileState = "full" | "partial" | "summarized" | "dropped" | "withheld";
|
|
30
|
+
/** Why a file has no patch text. Only `withheld` hides a change from the
|
|
31
|
+
* model. The others are complete as a one-line label. */
|
|
32
|
+
export type EmptyPatch = "withheld" | "binary" | "renamed" | "no_changes";
|
|
33
|
+
export type DiffFile = {
|
|
34
|
+
path: string;
|
|
35
|
+
previousPath: string | null;
|
|
36
|
+
status: string;
|
|
37
|
+
additions: number;
|
|
38
|
+
deletions: number;
|
|
39
|
+
changes: number;
|
|
40
|
+
patch: string;
|
|
41
|
+
/** Set exactly when `patch` is empty. */
|
|
42
|
+
empty?: EmptyPatch;
|
|
43
|
+
};
|
|
44
|
+
export type PlannedFile = DiffFile & {
|
|
45
|
+
state: FileState;
|
|
46
|
+
/** A file with no patch text shown only as one line of the NO DIFF TEXT
|
|
47
|
+
* list instead of its own block, which happens when the diff is over
|
|
48
|
+
* budget. Its state does not change. */
|
|
49
|
+
listed?: boolean;
|
|
50
|
+
};
|
|
51
|
+
/** A file from GitHub's pull request or compare API. GitHub leaves `patch`
|
|
52
|
+
* out for a file it considers too large or binary and gives no reason, so an
|
|
53
|
+
* empty patch is `withheld`. The one exception is a pure rename, which has
|
|
54
|
+
* nothing to withhold. */
|
|
55
|
+
export declare function diffFileFromGithub(file: Json): DiffFile;
|
|
56
|
+
/** A file from a `Revision`. A revision built from git knows why a patch is
|
|
57
|
+
* empty, so a binary file or a pure rename is labeled as what it is instead
|
|
58
|
+
* of being described as withheld. */
|
|
59
|
+
export declare function diffFileFromRevision(file: RevisionFile, producer: Revision["producer"]): DiffFile;
|
|
60
|
+
/** The patch cut to at most `max` characters at a line end, so a partial file
|
|
61
|
+
* never shows half a line and its next line has a clean offset. */
|
|
62
|
+
export declare function cutAtLine(patch: string, max?: number): string;
|
|
63
|
+
export type RenderOptions = {
|
|
64
|
+
/** Whether the model can call `read-full-diff`. Without tool support the
|
|
65
|
+
* markers say the rest cannot be read, rather than pointing at a tool the
|
|
66
|
+
* model does not have. */
|
|
67
|
+
tools: boolean;
|
|
68
|
+
/** The file's summary, for a `summarized` file. */
|
|
69
|
+
summary?: string;
|
|
70
|
+
};
|
|
71
|
+
/** The NO DIFF TEXT list, or `""` when no file is listed. */
|
|
72
|
+
export declare function noDiffBlock(files: PlannedFile[]): string;
|
|
73
|
+
/** One file's block in the DIFF section, or `""` for a dropped file, which
|
|
74
|
+
* is listed under NOT SHOWN instead, and for a listed file, which is one line
|
|
75
|
+
* of NO DIFF TEXT. */
|
|
76
|
+
export declare function renderSection(file: PlannedFile, options: RenderOptions): string;
|
|
77
|
+
/** A list of file names in the prompt names at most this many, then says how
|
|
78
|
+
* many more there are. A local review of a moved or vendored tree has no
|
|
79
|
+
* file limit, and an unbounded list could outgrow the model's context. */
|
|
80
|
+
export declare const MAX_LISTED_FILES = 200;
|
|
81
|
+
/** The NOT SHOWN list for dropped files, or `""` when none was dropped. */
|
|
82
|
+
export declare function notShownBlock(files: PlannedFile[], options: Pick<RenderOptions, "tools">): string;
|
|
83
|
+
/** Plain code-point order. `localeCompare` follows the process locale, so a
|
|
84
|
+
* server and a laptop could drop different files from the same diff. */
|
|
85
|
+
export declare function byPath(a: string, b: string): number;
|
|
86
|
+
/** Drops files from the end of path order until the DIFF section fits. Both
|
|
87
|
+
* the plan and the pass after the real summaries use it. Only a file with a
|
|
88
|
+
* patch is dropped: files without one are listed first. Mutates `files`. */
|
|
89
|
+
export declare function dropUntilFits(files: PlannedFile[], size: (file: PlannedFile) => number, max?: number): void;
|
|
90
|
+
/** After the drop pass the budget can have room left, because a large file
|
|
91
|
+
* went where several small ones would have fit. Dropped files that fit come
|
|
92
|
+
* back, smallest first, without a summary. Mutates `files`. */
|
|
93
|
+
export declare function restoreIntoRoom(files: PlannedFile[], size: (file: PlannedFile) => number, max?: number): void;
|
|
94
|
+
/** The plan. Files keep their input order, and only dropping looks at path
|
|
95
|
+
* order. Preference is always full, then partial or summarized, then
|
|
96
|
+
* dropped.
|
|
97
|
+
*
|
|
98
|
+
* 1. A file over `DIFF_SUMMARY_THRESHOLD` changed lines is summarized.
|
|
99
|
+
* 2. A patch over `MAX_FILE_PATCH_CHARS` is partial.
|
|
100
|
+
* 3. While the total is over `MAX_REVIEW_DIFF_CHARS`, the largest full or
|
|
101
|
+
* partial file is summarized.
|
|
102
|
+
* 4. If that is not enough, files are dropped from the end of path order.
|
|
103
|
+
* 5. Dropped files that fit in the room left come back, smallest first.
|
|
104
|
+
*
|
|
105
|
+
* Only a patch over `SUMMARY_MIN_PATCH_CHARS` is ever summarized, by rule 1
|
|
106
|
+
* or 3, and at most `MAX_SUMMARIES` per review, largest first. */
|
|
107
|
+
export declare function planDiff(files: DiffFile[], max?: number): PlannedFile[];
|
|
108
|
+
/** The coverage block for a planned round. A file carried over unchanged from
|
|
109
|
+
* an earlier round counts as full: it needs no new review. */
|
|
110
|
+
export declare function coverageFromPlan(planned: PlannedFile[], unchangedPaths?: string[]): Coverage;
|