co-maintainer 0.6.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "co-maintainer",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "An imitator of yours, A PR review tool like co-maintainer.",
5
5
  "keywords": [
6
6
  "ai",
@@ -37,7 +37,7 @@ export declare function resolveField(name: string): string;
37
37
  * `defaults` are nested maps, not settings, so they are not listed.
38
38
  * `satisfies` makes this the type's own vocabulary: a name that is not a
39
39
  * `UserConfig` key is a compile error rather than a silently undefined read. */
40
- export declare const KNOWN_FIELDS: readonly ["auth", "ai", "lowModel", "highModel", "token", "githubPat", "githubAppId", "githubAppPrivateKey", "githubAppPrivateKeyPath", "githubWebhookSecret", "webhookUrl", "githubOAuthClientId", "githubOAuthClientSecret", "githubOAuthAllowedUser", "passwordAuthDisabled", "githubAuthEnabled", "dashboardPasswordHash", "maxConcurrentJobs", "reviewBlocking", "remoteHost", "remoteToken", "remoteNoticeShownFor", "remoteSyncTimeoutSeconds", "maxConcurrentRemoteReviewsPerToken", "remoteToolOutputMaxChars", "remoteByok", "remoteByokDefault", "remoteByokPolicy", "reviewPolicy"];
40
+ export declare const KNOWN_FIELDS: readonly ["auth", "ai", "lowModel", "highModel", "token", "githubPat", "githubAppId", "githubAppPrivateKey", "githubAppPrivateKeyPath", "githubWebhookSecret", "webhookUrl", "githubOAuthClientId", "githubOAuthClientSecret", "githubOAuthAllowedUser", "passwordAuthDisabled", "githubAuthEnabled", "dashboardPasswordHash", "maxConcurrentJobs", "reviewBlocking", "codegraphVersion", "remoteHost", "remoteToken", "remoteNoticeShownFor", "remoteSyncTimeoutSeconds", "maxConcurrentRemoteReviewsPerToken", "remoteToolOutputMaxChars", "remoteByok", "remoteByokDefault", "remoteByokPolicy", "reviewPolicy"];
41
41
  /** `co-maintainer config <sub> ...`. `set` is handled by runSet, which this
42
42
  * command delegates to so there is one implementation of the write rules. */
43
43
  export declare function runConfig(args: string[]): Promise<void>;
@@ -50,6 +50,7 @@ export const ENV_BY_FIELD = {
50
50
  remoteToken: ["CM_REMOTE_TOKEN"],
51
51
  reviewBlocking: ["CO_MAINTAINER_REVIEW_BLOCKING"],
52
52
  remoteByokPolicy: ["CM_REMOTE_BYOK_POLICY"],
53
+ codegraphVersion: ["CM_CODEGRAPH_VERSION"],
53
54
  };
54
55
  /** Renders one field for people. A secret is masked; the password hash, which
55
56
  * nobody can use, only reports whether it is set. */
@@ -149,6 +150,7 @@ export const KNOWN_FIELDS = [
149
150
  "dashboardPasswordHash",
150
151
  "maxConcurrentJobs",
151
152
  "reviewBlocking",
153
+ "codegraphVersion",
152
154
  "remoteHost",
153
155
  "remoteToken",
154
156
  "remoteNoticeShownFor",
@@ -613,6 +613,11 @@ export const COMMANDS = [
613
613
  default: "model",
614
614
  description: "How a review decides a blocking finding.",
615
615
  },
616
+ {
617
+ name: "codegraph-version",
618
+ value: "SEMVER",
619
+ description: "The pinned codegraph version, overriding the built-in one. For a security fix without a release.",
620
+ },
616
621
  {
617
622
  name: "password",
618
623
  value: "TEXT",
@@ -3,7 +3,7 @@ import { setCliInteractive } from "../args.js";
3
3
  import { addAiMetrics, emptyAiMetrics, recordAiCost, } from "../../services/setup.js";
4
4
  import { costUsage } from "../../util/cost.js";
5
5
  import { costLabel } from "../../util/run_summary.js";
6
- import { reviewPullRequest } from "../../pr/reviewer.js";
6
+ import { modelSummary, reviewPullRequest } from "../../pr/reviewer.js";
7
7
  import { GhClient } from "../../github/gh.js";
8
8
  import { log, startHeartbeat, timed, withCliLogsToStderr, } from "../../util/log.js";
9
9
  import { runLocalReview } from "../../local/review_local.js";
@@ -47,6 +47,7 @@ async function runReviewPr(options, cli) {
47
47
  throw new Error("review supports gh authentication only");
48
48
  }
49
49
  log("review", `reading PR #${options.prNumber} in ${options.repo} via gh`);
50
+ log("review", modelSummary(options));
50
51
  const result = await timed("review GitHub collection and AI", options.logTime, () => reviewPullRequest(new GhClient(options.debug), options, async (response) => {
51
52
  addAiMetrics(aiMetrics, response);
52
53
  await recordAiCost(options.repo, "review_pull_request", response);
@@ -6,6 +6,7 @@ import { verifyAnthropic, verifyOpenAi, verifyOpenRouter, } from "../../ai/verif
6
6
  import { verifyOpenCode } from "../../ai/opencode.js";
7
7
  import { die } from "../error.js";
8
8
  import { parsePolicy } from "../../services/review_policy.js";
9
+ import { isCodegraphVersion } from "../../tools/codegraph.js";
9
10
  import { AI_PROVIDERS, rejectRetiredProvider } from "../../ai/provider.js";
10
11
  import { renderCommandHelp, renderGlobalHelp } from "./registry.js";
11
12
  function text(args, name) {
@@ -61,6 +62,7 @@ export async function runSet(args) {
61
62
  "review-policy",
62
63
  "review-policy-file",
63
64
  "review-blocking",
65
+ "codegraph-version",
64
66
  "repo",
65
67
  "review-system-prompt",
66
68
  "review-system-prompt-max-chars",
@@ -124,6 +126,7 @@ export async function runSet(args) {
124
126
  "remote-byok-default": "remoteByokDefault",
125
127
  "review-policy": "reviewPolicy",
126
128
  "review-blocking": "reviewBlocking",
129
+ "codegraph-version": "codegraphVersion",
127
130
  password: "dashboardPasswordHash",
128
131
  };
129
132
  const unset = new Set(args
@@ -254,6 +257,16 @@ export async function runSet(args) {
254
257
  }
255
258
  patch.reviewBlocking = reviewBlocking;
256
259
  }
260
+ const rawCodegraphVersion = text(args, "codegraph-version");
261
+ if (rawCodegraphVersion !== undefined && rawCodegraphVersion.trim() !== "") {
262
+ // Match the reader: a leading `v` is accepted and dropped, so `set` and
263
+ // `codegraphVersion()` agree on what a version looks like.
264
+ const normalized = rawCodegraphVersion.trim().replace(/^v/, "");
265
+ if (!isCodegraphVersion(normalized)) {
266
+ die("--codegraph-version must be a version like 1.6.0");
267
+ }
268
+ patch.codegraphVersion = normalized;
269
+ }
257
270
  const password = text(args, "password");
258
271
  if (password) {
259
272
  const problem = passwordProblem(password);
@@ -266,7 +279,7 @@ export async function runSet(args) {
266
279
  "--github-app-id=, --github-app-private-key(-file|-path)=, --github-webhook-secret=, " +
267
280
  "--github-oauth-client-id=, --github-oauth-client-secret=, --github-oauth-allowed-user=, " +
268
281
  "--remote-host=, --remote-token=, --remote-byok-policy=off|allow|require, " +
269
- "--review-blocking=model|severity, " +
282
+ "--review-blocking=model|severity, --codegraph-version=SEMVER, " +
270
283
  "--password=, --disable-auth=password, --enable-auth=github, or --unset=name");
271
284
  }
272
285
  // Verify the key and model before writing, so a typo fails here instead of
@@ -148,6 +148,7 @@ export async function parseReviewArgs(args) {
148
148
  options: {
149
149
  ...options,
150
150
  useCodegraph: flags.disableCodegraph ? false : true,
151
+ allowToolInstall: flags.allowToolInstall,
151
152
  reviewSystemPromptAdd: promptFlags.add,
152
153
  reviewSystemPromptOverride: promptFlags.override,
153
154
  },
@@ -71,6 +71,10 @@ export type UserConfig = {
71
71
  /** What a review uses to decide a blocking finding. `model` lets
72
72
  * the model's own severity decide, `severity` uses a fixed threshold. */
73
73
  reviewBlocking?: "model" | "severity";
74
+ /** The pinned codegraph version to install and detect, replacing the one
75
+ * this build ships. Lets a security fix ship without a new release.
76
+ * `CM_CODEGRAPH_VERSION` overrides it. */
77
+ codegraphVersion?: string;
74
78
  /** Remote review CLI target (`co-maintainer set`). */
75
79
  remoteHost?: string;
76
80
  /** Bearer token for `/api/remote/*`; only written by `set`. */
@@ -3,12 +3,22 @@ import { type Run } from "./checkout.ts";
3
3
  import { type Presence } from "../tools/codegraph.ts";
4
4
  import { type CodegraphRunner } from "../tools/codegraph_exec.ts";
5
5
  export declare function ensureCodegraphIndex(binary: string, worktree: string, runner: CodegraphRunner, indexDir?: string): Promise<void>;
6
- /** Uses `detect`, never `ensureCodegraph`: the latter can call `Deno.exit` on
7
- * a declined or failed install, fine for a one-time `init`/`remake`/`serve`
8
- * setup step but not for a single review that happens to want this tool. */
6
+ /** Resolves the codegraph binary for a review. `detect` is the default and
7
+ * never installs: the exiting `ensureCodegraph` is for a one-time
8
+ * `init`/`remake`/`serve` setup step, not for a single review that happens to
9
+ * want this tool. With `allowInstall` (`--allow-tool-install`) a missing or
10
+ * mismatched install is resolved through `ensureCodegraphForReview`, which
11
+ * installs without prompting and returns a reason instead of exiting. */
9
12
  export declare function prepareCodegraphTools(repo: string, pr: number, commit: string, options?: {
10
13
  run?: Run;
11
14
  detect?: () => Promise<Presence>;
15
+ allowInstall?: boolean;
16
+ /** Overrides the install step, for tests. */
17
+ ensure?: () => Promise<{
18
+ path: string;
19
+ } | {
20
+ reason: string;
21
+ }>;
12
22
  }): Promise<ToolHandler[]>;
13
23
  /** Tool schemas for the remote bridge (runs are proxied to the CLI). */
14
24
  export declare function codegraphToolHandlersForBridge(): ToolHandler[];
@@ -1,5 +1,5 @@
1
1
  import { ensureWorktree, pathExists, runCommand, } from "./checkout.js";
2
- import { detect } from "../tools/codegraph.js";
2
+ import { detect, ensureCodegraphForReview, } from "../tools/codegraph.js";
3
3
  import { createCodegraphRunner, LOCAL_CODEGRAPH_DIR, runCodegraphTool, SERVER_CODEGRAPH_DIR, } from "../tools/codegraph_exec.js";
4
4
  import { log } from "../util/log.js";
5
5
  import { guardToolArgs, rejectEscapingPath, rejectFlagLike, } from "./codegraph_tool_args.js";
@@ -42,22 +42,41 @@ export async function ensureCodegraphIndex(binary, worktree, runner, indexDir =
42
42
  log("codegraph", `${fresh ? "init" : "sync"} · ${indexed} files · ${((performance.now() - started) /
43
43
  1000).toFixed(1)}s`);
44
44
  }
45
- /** Uses `detect`, never `ensureCodegraph`: the latter can call `Deno.exit` on
46
- * a declined or failed install, fine for a one-time `init`/`remake`/`serve`
47
- * setup step but not for a single review that happens to want this tool. */
45
+ /** Resolves the codegraph binary for a review. `detect` is the default and
46
+ * never installs: the exiting `ensureCodegraph` is for a one-time
47
+ * `init`/`remake`/`serve` setup step, not for a single review that happens to
48
+ * want this tool. With `allowInstall` (`--allow-tool-install`) a missing or
49
+ * mismatched install is resolved through `ensureCodegraphForReview`, which
50
+ * installs without prompting and returns a reason instead of exiting. */
48
51
  export async function prepareCodegraphTools(repo, pr, commit, options = {}) {
49
52
  const runner = options.run ?? runCommand;
50
53
  const detectPresence = options.detect ?? detect;
54
+ const ensure = options.ensure ??
55
+ (() => ensureCodegraphForReview({
56
+ allowInstall: options.allowInstall,
57
+ interactive: false,
58
+ }));
51
59
  try {
52
60
  const presence = await detectPresence();
53
- if (presence.state !== "ok") {
61
+ let binary = presence.state === "ok" ? presence.path : null;
62
+ if (binary === null && options.allowInstall) {
63
+ const resolved = await ensure();
64
+ if ("path" in resolved) {
65
+ binary = resolved.path;
66
+ }
67
+ else {
68
+ log("codegraph", `tools unavailable · ${resolved.reason}`);
69
+ return [];
70
+ }
71
+ }
72
+ if (binary === null) {
54
73
  log("codegraph", `tools unavailable · codegraph is ${presence.state}`);
55
74
  return [];
56
75
  }
57
76
  const worktree = await ensureWorktree(repo, pr, commit, runner);
58
77
  const cgRun = createCodegraphRunner(SERVER_CODEGRAPH_DIR);
59
- await ensureCodegraphIndex(presence.path, worktree, cgRun);
60
- return codegraphTools(presence.path, worktree, cgRun);
78
+ await ensureCodegraphIndex(binary, worktree, cgRun);
79
+ return codegraphTools(binary, worktree, cgRun);
61
80
  }
62
81
  catch (error) {
63
82
  log("codegraph", `tools unavailable · ${String(error)}`);
@@ -4,6 +4,10 @@ import type { Snapshot } from "./snapshot.ts";
4
4
  import type { AiProvider, AiResponse, GitHubClient, Json, Options } from "../types.ts";
5
5
  type UsageSink = (response: AiResponse) => Promise<void>;
6
6
  type ProgressSink = (message: string) => void;
7
+ /** One line naming the provider and the two models a review will call, printed
8
+ * before any AI request so the operator can see what is running. The low model
9
+ * summarizes large diffs, the high model writes the review. */
10
+ export declare function modelSummary(options: Options): string;
7
11
  export type ReviewExtras = {
8
12
  carryPrompt?: string;
9
13
  unchangedPaths?: string[];
@@ -9,6 +9,13 @@ import { reviewSystemPromptBlock } from "../review/system_prompt.js";
9
9
  import { needsSummary, READ_FULL_DIFF_TOOL, readFullDiff, summarizeDiff, } from "./diff_summary.js";
10
10
  import { numberPatch } from "./hunks.js";
11
11
  import { FINDINGS_JSON_INSTRUCTIONS, FINDINGS_JSON_SCHEMA, findingsMarkdownFromJson, } from "./findings_json.js";
12
+ /** One line naming the provider and the two models a review will call, printed
13
+ * before any AI request so the operator can see what is running. The low model
14
+ * summarizes large diffs, the high model writes the review. */
15
+ export function modelSummary(options) {
16
+ return (`models · provider=${options.ai} · low=${options.lowModel ?? "unset"} · ` +
17
+ `high=${options.highModel ?? "unset"}`);
18
+ }
12
19
  /** A model id is never guessed here. Models go stale, and a build already
13
20
  * installed cannot fetch a fresher one, so the id to run comes from config
14
21
  * or a flag, set at least once by whoever runs it (Murat, 2026-09-28). */
@@ -196,6 +203,7 @@ export async function reviewPullRequest(client, options, usage, snapshot, ai, pr
196
203
  throw new Error("review requires a PR number");
197
204
  const number = options.prNumber;
198
205
  const report = progress ?? (() => { });
206
+ report(modelSummary(options));
199
207
  report(`loading PR context for ${options.repo}#${number}`);
200
208
  const [pr, allComments, allReviews, guides] = await Promise.all([
201
209
  client.request(`repos/${options.repo}/pulls/${number}`),
@@ -274,7 +282,9 @@ export async function reviewPullRequest(client, options, usage, snapshot, ai, pr
274
282
  `enough]\n${description}`);
275
283
  })),
276
284
  options.useCodegraph && headSha
277
- ? prepareCodegraphTools(options.repo, number, headSha)
285
+ ? prepareCodegraphTools(options.repo, number, headSha, {
286
+ allowInstall: options.allowToolInstall,
287
+ })
278
288
  : Promise.resolve([]),
279
289
  ]);
280
290
  if (options.useCodegraph) {
@@ -459,6 +469,7 @@ function revisionToGithubFiles(revision) {
459
469
  /** Local workspace review — same prompt loop as PR review without GitHub. */
460
470
  export async function reviewWorkspaceRevision(revision, options, headSha, usage, ai, progress, extras) {
461
471
  const report = progress ?? (() => { });
472
+ report(modelSummary(options));
462
473
  const guides = await loadGuides(options.repo);
463
474
  const { shortGuide, detailed, codebase, skill } = guides;
464
475
  const guide = shortGuide || skill;
@@ -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 = CODEGRAPH_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 = CODEGRAPH_VERSION, root = toolsDir(), run = runCommand) {
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 = CODEGRAPH_VERSION, root = toolsDir()) {
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 = CODEGRAPH_VERSION, root = toolsDir()) {
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(CODEGRAPH_VERSION, root, run);
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 ${CODEGRAPH_VERSION} but found ${present.version} ` +
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 ${CODEGRAPH_VERSION} is not installed.\n` +
140
- `Run with --allow-tool-install, or install it yourself:\n ${installHint(CODEGRAPH_VERSION, root)}`);
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(CODEGRAPH_VERSION, root));
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(CODEGRAPH_VERSION, root);
153
- log(`[codegraph] installing ${CODEGRAPH_PACKAGE}@${CODEGRAPH_VERSION}`);
154
- await mkdir(versionDir(CODEGRAPH_VERSION, root), { recursive: true });
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(CODEGRAPH_VERSION, root, run);
194
+ const after = await detect(version, root, run);
161
195
  if (after.state !== "ok") {
162
- log(`[codegraph] install finished but ${binaryPath(CODEGRAPH_VERSION, root)} is still not usable`);
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(CODEGRAPH_VERSION, root, run);
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 ${CODEGRAPH_VERSION} but found ${present.version}; reinstalling`);
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(CODEGRAPH_VERSION, root));
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(CODEGRAPH_VERSION, root);
193
- log(`[codegraph] installing ${CODEGRAPH_PACKAGE}@${CODEGRAPH_VERSION}`);
194
- await mkdir(versionDir(CODEGRAPH_VERSION, root), { recursive: true });
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(CODEGRAPH_VERSION, root, run);
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
  }
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "co-maintainer",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "An imitator of yours, A PR review tool like co-maintainer.",
5
5
  "keywords": [
6
6
  "ai",