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
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* directly; it used to re-spawn the CLI as a subprocess, a second
|
|
3
3
|
* execution path with its own failure modes. */
|
|
4
4
|
import { createAiProvider } from "../ai/provider.js";
|
|
5
|
-
import {
|
|
5
|
+
import { enrichFacts, synthesizeSections } from "../knowledge/synthesis.js";
|
|
6
6
|
import { collectSource } from "../github/collect.js";
|
|
7
7
|
import { GhClient } from "../github/gh.js";
|
|
8
8
|
import { PatClient } from "../github/pat.js";
|
|
9
9
|
import { extractFacts } from "../knowledge/facts.js";
|
|
10
|
-
import {
|
|
10
|
+
import { reviewSignalCount, synthesizeReviewGuides, } from "../knowledge/guide.js";
|
|
11
11
|
import { assembleSkill, codebaseBody, factSectionHashes, } from "../knowledge/skill.js";
|
|
12
12
|
import { validateSkill } from "../knowledge/validate.js";
|
|
13
13
|
import { readConfig, reposDir, resolvedAiToken, writeRepoConfig, } from "../config.js";
|
|
@@ -22,6 +22,7 @@ import { nowIso } from "../util/time.js";
|
|
|
22
22
|
import { mkdir, readTextFile, remove } from "../util/runtime.js";
|
|
23
23
|
import { addResponseCost, emptyTally } from "../util/cost.js";
|
|
24
24
|
import { costLabel } from "../util/run_summary.js";
|
|
25
|
+
import { formatError } from "../cli/error.js";
|
|
25
26
|
export function emptyAiMetrics() {
|
|
26
27
|
return { calls: 0, tokensIn: 0, tokensOut: 0, ...emptyTally() };
|
|
27
28
|
}
|
|
@@ -86,13 +87,20 @@ async function skillPath(repo) {
|
|
|
86
87
|
async function writeReviewDocuments(repo, documents, signalCount) {
|
|
87
88
|
const directory = `${reposDir()}/${repo}`;
|
|
88
89
|
if (!documents) {
|
|
89
|
-
//
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
// `undefined` means two different things. Below the signal threshold there
|
|
91
|
+
// is nothing to write, so the files are removed and the reason is one line.
|
|
92
|
+
// When the AI produced no usable guide, the existing files are kept: a
|
|
93
|
+
// provider hiccup must not delete a guide the last run wrote.
|
|
94
|
+
if (signalCount <= 2) {
|
|
95
|
+
log("write", `PR_REVIEW_GUIDE.md skipped: found ${signalCount} review signals, needs at least 3`);
|
|
96
|
+
await Promise.all([
|
|
97
|
+
remove(`${directory}/PR_REVIEW_GUIDE.md`).catch(() => { }),
|
|
98
|
+
remove(`${directory}/PR_REVIEW_DETAILED_GUIDE.md`).catch(() => { }),
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
log("write", "PR_REVIEW_GUIDE.md not regenerated: the AI produced no guide, keeping any existing file");
|
|
103
|
+
}
|
|
96
104
|
return;
|
|
97
105
|
}
|
|
98
106
|
const { writeTextFileAtomic } = await import("../util/atomic.js");
|
|
@@ -104,17 +112,19 @@ async function writeReviewDocuments(repo, documents, signalCount) {
|
|
|
104
112
|
await remove(`${directory}/PR_REVIEW_DETAILED_GUIDE.md`).catch(() => { });
|
|
105
113
|
}
|
|
106
114
|
}
|
|
107
|
-
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
|
|
113
|
-
async function writeCodebaseDocument(repo, facts, overrides = {}) {
|
|
115
|
+
/** Writes the codebase-description sections (layout/style/tests/devloop) to
|
|
116
|
+
* their own file, so `review` can check a pull request against how this
|
|
117
|
+
* repository's code actually looks, not just the review-bar checklist. Every
|
|
118
|
+
* section body is authored by the synthesis job; the skill links to this file
|
|
119
|
+
* rather than repeating it. */
|
|
120
|
+
async function writeCodebaseDocument(repo, overrides = {}) {
|
|
114
121
|
const path = `${reposDir()}/${repo}/CODEBASE.md`;
|
|
115
|
-
const body = codebaseBody(
|
|
122
|
+
const body = codebaseBody(overrides);
|
|
116
123
|
if (!body) {
|
|
117
|
-
|
|
124
|
+
// Keep any existing file: `SKILL.md` links to it, and removing it would
|
|
125
|
+
// leave that link dangling. A guide the last run wrote is better than a
|
|
126
|
+
// broken link.
|
|
127
|
+
log("write", "CODEBASE.md not regenerated: the AI produced no codebase sections, keeping any existing file");
|
|
118
128
|
return;
|
|
119
129
|
}
|
|
120
130
|
const { writeTextFileAtomic } = await import("../util/atomic.js");
|
|
@@ -157,9 +167,11 @@ async function initOrRemake(options) {
|
|
|
157
167
|
const client = clientFor(options);
|
|
158
168
|
const lowAi = createAiProvider(options, options.lowModel ?? "");
|
|
159
169
|
const highAi = createAiProvider(options, options.highModel ?? "");
|
|
160
|
-
|
|
161
|
-
|
|
170
|
+
// Every guide is AI-authored: with no provider there is nothing to build.
|
|
171
|
+
if (!lowAi || !highAi) {
|
|
172
|
+
throw new Error("init requires an AI provider. Run: co-maintainer set --ai=openrouter --token=... --low-model=... --high-model=...");
|
|
162
173
|
}
|
|
174
|
+
log("ai", `${options.ai} providers configured · low=${options.lowModel} · high=${options.highModel}`);
|
|
163
175
|
log("fetch", `${options.repo} via ${options.auth}`);
|
|
164
176
|
const source = await timed("fetch repository data", options.logTime, () => collectSource(client, options, previous, async (pullRequests, cache) => {
|
|
165
177
|
checkpoint.source.pullRequests = pullRequests;
|
|
@@ -193,17 +205,15 @@ async function initOrRemake(options) {
|
|
|
193
205
|
if (options.logTime) {
|
|
194
206
|
log("time", `extract deterministic facts · ${((performance.now() - factsStarted) / 1000).toFixed(2)}s`);
|
|
195
207
|
}
|
|
208
|
+
const usage = async (job, response) => {
|
|
209
|
+
addAiMetrics(aiMetrics, response);
|
|
210
|
+
await recordAiCost(options.repo, job, response);
|
|
211
|
+
};
|
|
196
212
|
let overrides = {};
|
|
197
|
-
|
|
198
|
-
|
|
213
|
+
let reviewDocuments;
|
|
214
|
+
try {
|
|
199
215
|
log("ai", "starting extract_unit jobs");
|
|
200
|
-
|
|
201
|
-
addAiMetrics(aiMetrics, response);
|
|
202
|
-
await recordAiCost(options.repo, job, response);
|
|
203
|
-
};
|
|
204
|
-
const enriched = await timed("extract_unit AI", options.logTime, () => enrichFactsWithReport(lowAi, options.repo, facts, source, options, usage));
|
|
205
|
-
facts = enriched.facts;
|
|
206
|
-
skipped.push(...enriched.skipped);
|
|
216
|
+
facts = await timed("extract_unit AI", options.logTime, () => enrichFacts(lowAi, options.repo, facts, source, options, usage));
|
|
207
217
|
log("ai", `extract_unit complete · ${facts.length} facts`);
|
|
208
218
|
const hashes = await factSectionHashes(facts);
|
|
209
219
|
const synthesisChanged = previous &&
|
|
@@ -217,22 +227,28 @@ async function initOrRemake(options) {
|
|
|
217
227
|
.map(([key]) => key))
|
|
218
228
|
: undefined;
|
|
219
229
|
log("ai", `starting synth_section jobs${dirtySections ? ` · ${dirtySections.size} dirty sections` : ""}`);
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
overrides = synth.overrides;
|
|
223
|
-
skipped.push(...synth.skipped);
|
|
224
|
-
}
|
|
230
|
+
const synth = await timed("synth_section AI", options.logTime, () => synthesizeSections(highAi, options.repo, facts, previousMarkdown, options.ai, options.highModel ?? "", options.aiConcurrent, usage, dirtySections));
|
|
231
|
+
overrides = synth.overrides;
|
|
225
232
|
log("ai", `synth_section complete · ${Object.keys(overrides).length} sections`);
|
|
233
|
+
log("ai", "starting synth_guide jobs");
|
|
234
|
+
reviewDocuments = await timed("synth_guide AI", options.logTime, () => synthesizeReviewGuides(highAi, options.repo, options.ai, options.highModel ?? "", options.aiConcurrent, facts, usage));
|
|
235
|
+
log("ai", reviewDocuments
|
|
236
|
+
? `synth_guide complete · ${reviewDocuments.detailed ? "short + detailed" : "single guide"}`
|
|
237
|
+
: "synth_guide skipped · fewer than 3 review signals");
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
// Nothing is written on an AI failure. Fetching and extraction are cached,
|
|
241
|
+
// so a rerun picks up where this stopped instead of starting over.
|
|
242
|
+
throw new Error(`AI failed to generate the guides: ${formatError(error)}. ` +
|
|
243
|
+
"Fetching and extraction are cached, so rerunning `co-maintainer sync <owner/repo>` continues without re-fetching.");
|
|
226
244
|
}
|
|
227
245
|
let result = await timed("assemble skill", options.logTime, () => assembleSkill(options.repo, facts, previousMarkdown, previous?.sectionHashes ?? {}, overrides));
|
|
228
|
-
const reviewDocuments = buildReviewDocuments(facts);
|
|
229
246
|
result.markdown = addReviewLink(result.markdown, reviewDocuments);
|
|
230
247
|
const validation = await timed("validate skill", options.logTime, () => validateSkill(result.markdown, source));
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
result.markdown = addReviewLink(result.markdown, reviewDocuments);
|
|
248
|
+
// There is no deterministic fallback to reassemble from: a skill the AI could
|
|
249
|
+
// not write correctly is reported rather than rebuilt from facts.
|
|
250
|
+
if (!validation.valid) {
|
|
251
|
+
log("validate", `skill problems kept: ${validation.errors.join("; ")}`);
|
|
236
252
|
}
|
|
237
253
|
const finalValidation = await timed("final skill validation", options.logTime, () => validateSkill(result.markdown, source, "warning"));
|
|
238
254
|
if (finalValidation.warnings.length) {
|
|
@@ -246,7 +262,7 @@ async function initOrRemake(options) {
|
|
|
246
262
|
const { writeTextFileAtomic } = await import("../util/atomic.js");
|
|
247
263
|
await withKnowledgeLock(options.repo, async () => {
|
|
248
264
|
await writeTextFileAtomic(path, result.markdown);
|
|
249
|
-
await writeCodebaseDocument(options.repo,
|
|
265
|
+
await writeCodebaseDocument(options.repo, overrides);
|
|
250
266
|
await writeReviewDocuments(options.repo, reviewDocuments, reviewSignalCount(facts));
|
|
251
267
|
const head = source.commits[0];
|
|
252
268
|
const baseSha = head?.sha ? String(head.sha) : new Date().toISOString();
|
|
@@ -290,16 +306,6 @@ async function initOrRemake(options) {
|
|
|
290
306
|
? `updated ${result.changed.join(", ")}`
|
|
291
307
|
: "already current"}`);
|
|
292
308
|
log("done", `${facts.length} facts · ${source.pullRequests.length} pull requests · ${source.commits.length} commits`);
|
|
293
|
-
if (skipped.length) {
|
|
294
|
-
// A skipped unit used to vanish into a log line and recur as a "cache
|
|
295
|
-
// hit" forever. Say it in the final line instead, in this shape:
|
|
296
|
-
// `1 unit skipped (PR #3: output was not JSON)`.
|
|
297
|
-
const parts = skipped.map((unit) => unit.reason);
|
|
298
|
-
const line = skipped.length === 1
|
|
299
|
-
? `1 unit skipped (${parts[0]})`
|
|
300
|
-
: `${skipped.length} units skipped (${parts.join("; ")})`;
|
|
301
|
-
log("done", line);
|
|
302
|
-
}
|
|
303
309
|
printRunSummary(summaryFromMetrics(aiMetrics, performance.now() - operationStarted));
|
|
304
310
|
if (options.logTime) {
|
|
305
311
|
log("time", `AI total · calls=${aiMetrics.calls} · input=${aiMetrics.tokensIn} tokens · output=${aiMetrics.tokensOut} tokens · cost=${costLabel(aiMetrics)}`);
|
|
@@ -319,7 +325,11 @@ export function optionsFromConfig(repo, command) {
|
|
|
319
325
|
const lowModel = repoConfig.lowModel ?? config.lowModel;
|
|
320
326
|
const highModel = repoConfig.highModel ?? config.highModel;
|
|
321
327
|
const aiToken = resolvedAiToken(config, ai);
|
|
322
|
-
|
|
328
|
+
// Every guide is AI-authored: init and sync cannot run without a provider.
|
|
329
|
+
if (ai === "none") {
|
|
330
|
+
throw new Error("init and sync need an AI provider. Run: co-maintainer set --ai=openrouter --token=... --low-model=... --high-model=...");
|
|
331
|
+
}
|
|
332
|
+
if (!aiToken || !lowModel || !highModel) {
|
|
323
333
|
throw new Error("AI is enabled but token/low-model/high-model are not fully configured. Run: " +
|
|
324
334
|
"co-maintainer set --token=... --low-model=... --high-model=...");
|
|
325
335
|
}
|
|
@@ -337,7 +347,7 @@ export function optionsFromConfig(repo, command) {
|
|
|
337
347
|
aiToken,
|
|
338
348
|
lowModel,
|
|
339
349
|
highModel,
|
|
340
|
-
synthesisVersion:
|
|
350
|
+
synthesisVersion: 17,
|
|
341
351
|
includeCodebase: repoConfig.includeCodebase ?? true,
|
|
342
352
|
includePullRequests: repoConfig.includePullRequests ?? true,
|
|
343
353
|
includePullRequestChanges: repoConfig.includePullRequestChanges ?? true,
|
|
@@ -1,9 +1,21 @@
|
|
|
1
|
+
import { type UserConfig } from "../config.ts";
|
|
1
2
|
/** The version co-maintainer is built against. codegraph's CLI output shape is
|
|
2
3
|
* what the reviewer parses, so this is pinned rather than tracking latest: a
|
|
3
4
|
* format change upstream must be an explicit upgrade here, not a surprise on
|
|
4
5
|
* someone else's machine. Raise it, adjust whatever reads the output, done. */
|
|
5
6
|
export declare const CODEGRAPH_VERSION = "1.6.0";
|
|
6
7
|
export declare const CODEGRAPH_PACKAGE = "@colbymchenry/codegraph";
|
|
8
|
+
/** A version that is safe in a directory name and an npm argument: a bare
|
|
9
|
+
* semver, optionally with a prerelease suffix. Anything else (a path, a
|
|
10
|
+
* leading `-`, whitespace) is refused, so a bad config value can never reach
|
|
11
|
+
* `versionDir` or the npm spec. */
|
|
12
|
+
export declare function isCodegraphVersion(value: string): boolean;
|
|
13
|
+
/** The pinned version to use, in precedence order: `CM_CODEGRAPH_VERSION`,
|
|
14
|
+
* then `config.json codegraphVersion`, then the version this build ships. A
|
|
15
|
+
* layer that is missing or not a plain semver is skipped, so a typo falls back
|
|
16
|
+
* instead of breaking detection. This is what lets a security fix ship as a
|
|
17
|
+
* config or environment change without a new release. */
|
|
18
|
+
export declare function codegraphVersion(env?: (name: string) => string | undefined, config?: () => UserConfig): string;
|
|
7
19
|
export type CommandResult = {
|
|
8
20
|
code: number;
|
|
9
21
|
stdout: string;
|
|
@@ -20,6 +32,9 @@ export type EnsureOptions = {
|
|
|
20
32
|
log?: (message: string) => void;
|
|
21
33
|
/** Overrides `toolsDir()`, for tests. */
|
|
22
34
|
root?: string;
|
|
35
|
+
/** Overrides the pinned version, for tests. Defaults to
|
|
36
|
+
* {@link codegraphVersion}. */
|
|
37
|
+
version?: string;
|
|
23
38
|
/** Overrides `process.exit`, for tests. */
|
|
24
39
|
exit?: (code: number) => never;
|
|
25
40
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { toolsDir } from "../config.js";
|
|
2
|
-
import { commandOutput, isWindows, mkdir, stat } from "../util/runtime.js";
|
|
1
|
+
import { readConfig, toolsDir } from "../config.js";
|
|
2
|
+
import { commandOutput, getEnv, isWindows, mkdir, stat, } from "../util/runtime.js";
|
|
3
3
|
import { askConfirm } from "../cli/prompt.js";
|
|
4
4
|
/** The version co-maintainer is built against. codegraph's CLI output shape is
|
|
5
5
|
* what the reviewer parses, so this is pinned rather than tracking latest: a
|
|
@@ -7,6 +7,39 @@ import { askConfirm } from "../cli/prompt.js";
|
|
|
7
7
|
* someone else's machine. Raise it, adjust whatever reads the output, done. */
|
|
8
8
|
export const CODEGRAPH_VERSION = "1.6.0";
|
|
9
9
|
export const CODEGRAPH_PACKAGE = "@colbymchenry/codegraph";
|
|
10
|
+
/** A version that is safe in a directory name and an npm argument: a bare
|
|
11
|
+
* semver, optionally with a prerelease suffix. Anything else (a path, a
|
|
12
|
+
* leading `-`, whitespace) is refused, so a bad config value can never reach
|
|
13
|
+
* `versionDir` or the npm spec. */
|
|
14
|
+
export function isCodegraphVersion(value) {
|
|
15
|
+
return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.test(value);
|
|
16
|
+
}
|
|
17
|
+
/** Trims and drops a leading `v`, then checks the result is a plain semver.
|
|
18
|
+
* `undefined` for anything that is not, so the caller falls back. */
|
|
19
|
+
function normalizeVersion(raw) {
|
|
20
|
+
const value = raw.trim().replace(/^v/, "");
|
|
21
|
+
return value !== "" && isCodegraphVersion(value) ? value : undefined;
|
|
22
|
+
}
|
|
23
|
+
/** The pinned version to use, in precedence order: `CM_CODEGRAPH_VERSION`,
|
|
24
|
+
* then `config.json codegraphVersion`, then the version this build ships. A
|
|
25
|
+
* layer that is missing or not a plain semver is skipped, so a typo falls back
|
|
26
|
+
* instead of breaking detection. This is what lets a security fix ship as a
|
|
27
|
+
* config or environment change without a new release. */
|
|
28
|
+
export function codegraphVersion(env = getEnv, config = readConfig) {
|
|
29
|
+
const fromEnv = env("CM_CODEGRAPH_VERSION");
|
|
30
|
+
if (fromEnv !== undefined) {
|
|
31
|
+
const value = normalizeVersion(fromEnv);
|
|
32
|
+
if (value)
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
const fromConfig = config().codegraphVersion;
|
|
36
|
+
if (fromConfig !== undefined) {
|
|
37
|
+
const value = normalizeVersion(fromConfig);
|
|
38
|
+
if (value)
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
return CODEGRAPH_VERSION;
|
|
42
|
+
}
|
|
10
43
|
/** codegraph ships a small launcher plus a per-platform binary (an
|
|
11
44
|
* `optionalDependencies` split), so the download a user is about to accept is
|
|
12
45
|
* the platform package, not the tiny launcher. Measured from the npm registry
|
|
@@ -30,7 +63,7 @@ export function canPrompt(streams = {
|
|
|
30
63
|
}
|
|
31
64
|
/** The one line a non-interactive run prints instead of asking. It names
|
|
32
65
|
* the reason and both ways forward, so a CI log explains itself. */
|
|
33
|
-
export function skippedNotice(version =
|
|
66
|
+
export function skippedNotice(version = codegraphVersion()) {
|
|
34
67
|
return (`codegraph ${version} is not installed, reviewing without it. ` +
|
|
35
68
|
"Pass --allow-tool-install to install it, or --disable-codegraph to skip this notice.");
|
|
36
69
|
}
|
|
@@ -76,7 +109,7 @@ export function parseVersion(stdout) {
|
|
|
76
109
|
const match = stdout.match(/(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)/);
|
|
77
110
|
return match?.[1];
|
|
78
111
|
}
|
|
79
|
-
export async function detect(version =
|
|
112
|
+
export async function detect(version = codegraphVersion(), root = toolsDir(), run = runCommand) {
|
|
80
113
|
const path = binaryPath(version, root);
|
|
81
114
|
try {
|
|
82
115
|
await stat(path);
|
|
@@ -92,7 +125,7 @@ export async function detect(version = CODEGRAPH_VERSION, root = toolsDir(), run
|
|
|
92
125
|
? { state: "ok", version: found, path }
|
|
93
126
|
: { state: "mismatch", version: found, path };
|
|
94
127
|
}
|
|
95
|
-
export function installCommand(version =
|
|
128
|
+
export function installCommand(version = codegraphVersion(), root = toolsDir()) {
|
|
96
129
|
return {
|
|
97
130
|
command: "npm",
|
|
98
131
|
args: [
|
|
@@ -105,7 +138,7 @@ export function installCommand(version = CODEGRAPH_VERSION, root = toolsDir()) {
|
|
|
105
138
|
],
|
|
106
139
|
};
|
|
107
140
|
}
|
|
108
|
-
export function installHint(version =
|
|
141
|
+
export function installHint(version = codegraphVersion(), root = toolsDir()) {
|
|
109
142
|
const { command, args } = installCommand(version, root);
|
|
110
143
|
return `${command} ${args.join(" ")}`;
|
|
111
144
|
}
|
|
@@ -117,6 +150,7 @@ async function defaultConfirm(question) {
|
|
|
117
150
|
* declining is a decision not to run this command, not a degraded mode. */
|
|
118
151
|
export async function ensureCodegraph(options = {}) {
|
|
119
152
|
const root = options.root ?? toolsDir();
|
|
153
|
+
const version = options.version ?? codegraphVersion();
|
|
120
154
|
const run = options.run ?? runCommand;
|
|
121
155
|
const log = options.log ?? ((message) => console.log(message));
|
|
122
156
|
// `canPrompt` is the single source of truth for "may we ask": stdin and
|
|
@@ -125,41 +159,41 @@ export async function ensureCodegraph(options = {}) {
|
|
|
125
159
|
// Annotated so TypeScript can see the calls below never return and keeps the
|
|
126
160
|
// `Presence` narrowing intact.
|
|
127
161
|
const exit = options.exit ?? process.exit;
|
|
128
|
-
const present = await detect(
|
|
162
|
+
const present = await detect(version, root, run);
|
|
129
163
|
if (present.state === "ok")
|
|
130
164
|
return present.path;
|
|
131
165
|
if (present.state === "mismatch") {
|
|
132
|
-
log(`[codegraph] expected ${
|
|
166
|
+
log(`[codegraph] expected ${version} but found ${present.version} ` +
|
|
133
167
|
`at ${present.path}; reinstalling the pinned version`);
|
|
134
168
|
}
|
|
135
169
|
if (!options.allowInstall) {
|
|
136
170
|
if (!interactive) {
|
|
137
171
|
// This path exits rather than continuing, so it must not say "reviewing
|
|
138
172
|
// without it"; it says how to proceed.
|
|
139
|
-
log(`[codegraph] codegraph ${
|
|
140
|
-
`Run with --allow-tool-install, or install it yourself:\n ${installHint(
|
|
173
|
+
log(`[codegraph] codegraph ${version} is not installed.\n` +
|
|
174
|
+
`Run with --allow-tool-install, or install it yourself:\n ${installHint(version, root)}`);
|
|
141
175
|
exit(1);
|
|
142
176
|
}
|
|
143
177
|
const confirm = options.confirm ?? defaultConfirm;
|
|
144
178
|
// `defaultConfirm` is async, so an unawaited call is always truthy and the
|
|
145
179
|
// user's "no" was silently ignored. Await it before deciding.
|
|
146
|
-
const approved = await confirm(installPrompt(
|
|
180
|
+
const approved = await confirm(installPrompt(version, root));
|
|
147
181
|
if (!approved) {
|
|
148
182
|
log("[codegraph] declined. Nothing was installed");
|
|
149
183
|
exit(1);
|
|
150
184
|
}
|
|
151
185
|
}
|
|
152
|
-
const { command, args } = installCommand(
|
|
153
|
-
log(`[codegraph] installing ${CODEGRAPH_PACKAGE}@${
|
|
154
|
-
await mkdir(versionDir(
|
|
186
|
+
const { command, args } = installCommand(version, root);
|
|
187
|
+
log(`[codegraph] installing ${CODEGRAPH_PACKAGE}@${version}`);
|
|
188
|
+
await mkdir(versionDir(version, root), { recursive: true });
|
|
155
189
|
const result = await run(command, args);
|
|
156
190
|
if (result.code !== 0) {
|
|
157
191
|
log(`[codegraph] install failed (exit ${result.code}): ${result.stderr.trim() || result.stdout.trim()}`);
|
|
158
192
|
exit(1);
|
|
159
193
|
}
|
|
160
|
-
const after = await detect(
|
|
194
|
+
const after = await detect(version, root, run);
|
|
161
195
|
if (after.state !== "ok") {
|
|
162
|
-
log(`[codegraph] install finished but ${binaryPath(
|
|
196
|
+
log(`[codegraph] install finished but ${binaryPath(version, root)} is still not usable`);
|
|
163
197
|
exit(1);
|
|
164
198
|
}
|
|
165
199
|
log(`[codegraph] ready at ${after.path}`);
|
|
@@ -168,30 +202,31 @@ export async function ensureCodegraph(options = {}) {
|
|
|
168
202
|
/** Review paths must not call `Deno.exit`. */
|
|
169
203
|
export async function ensureCodegraphForReview(options = {}) {
|
|
170
204
|
const root = options.root ?? toolsDir();
|
|
205
|
+
const version = options.version ?? codegraphVersion();
|
|
171
206
|
const run = options.run ?? runCommand;
|
|
172
207
|
const log = options.log ?? ((message) => console.error(message));
|
|
173
208
|
const interactive = options.interactive ?? canPrompt();
|
|
174
|
-
const present = await detect(
|
|
209
|
+
const present = await detect(version, root, run);
|
|
175
210
|
if (present.state === "ok")
|
|
176
211
|
return { path: present.path };
|
|
177
212
|
if (present.state === "mismatch") {
|
|
178
|
-
log(`[codegraph] expected ${
|
|
213
|
+
log(`[codegraph] expected ${version} but found ${present.version}; reinstalling`);
|
|
179
214
|
}
|
|
180
215
|
if (!options.allowInstall) {
|
|
181
216
|
// Non-interactive: do not ask, review without it. The caller logs the
|
|
182
217
|
// reason, so the run continues instead of hanging or exiting.
|
|
183
218
|
if (!interactive) {
|
|
184
|
-
return { reason: skippedNotice() };
|
|
219
|
+
return { reason: skippedNotice(version) };
|
|
185
220
|
}
|
|
186
221
|
const confirm = options.confirm ?? defaultConfirm;
|
|
187
222
|
// Same as `ensureCodegraph`: an unawaited async confirm is always truthy.
|
|
188
|
-
const approved = await confirm(installPrompt(
|
|
223
|
+
const approved = await confirm(installPrompt(version, root));
|
|
189
224
|
if (!approved)
|
|
190
225
|
return { reason: "codegraph install declined" };
|
|
191
226
|
}
|
|
192
|
-
const { command, args } = installCommand(
|
|
193
|
-
log(`[codegraph] installing ${CODEGRAPH_PACKAGE}@${
|
|
194
|
-
await mkdir(versionDir(
|
|
227
|
+
const { command, args } = installCommand(version, root);
|
|
228
|
+
log(`[codegraph] installing ${CODEGRAPH_PACKAGE}@${version}`);
|
|
229
|
+
await mkdir(versionDir(version, root), { recursive: true });
|
|
195
230
|
const result = await run(command, args);
|
|
196
231
|
if (result.code !== 0) {
|
|
197
232
|
return {
|
|
@@ -200,7 +235,7 @@ export async function ensureCodegraphForReview(options = {}) {
|
|
|
200
235
|
`install failed (exit ${result.code})`,
|
|
201
236
|
};
|
|
202
237
|
}
|
|
203
|
-
const after = await detect(
|
|
238
|
+
const after = await detect(version, root, run);
|
|
204
239
|
if (after.state !== "ok") {
|
|
205
240
|
return { reason: "install finished but the binary is still not usable" };
|
|
206
241
|
}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -18,6 +18,10 @@ export type Options = {
|
|
|
18
18
|
* Server jobs still follow per-repo settings. Indexing adds tokens and time;
|
|
19
19
|
* measured PR recall gains were small when this was opt-in only (K25). */
|
|
20
20
|
useCodegraph?: boolean;
|
|
21
|
+
/** PR review installs the pinned codegraph when `--allow-tool-install` is
|
|
22
|
+
* passed, instead of only using an install that is already there. CLI-only,
|
|
23
|
+
* off for server jobs and remote reviews. */
|
|
24
|
+
allowToolInstall?: boolean;
|
|
21
25
|
improveMatrix: number;
|
|
22
26
|
ghConcurrent: number;
|
|
23
27
|
aiConcurrent: number;
|