co-maintainer 0.6.0 → 0.6.3

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.
Files changed (37) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/src/ai/oauth/ids.d.ts +10 -0
  3. package/dist/src/ai/oauth/ids.js +10 -0
  4. package/dist/src/ai/oauth/registry.d.ts +33 -0
  5. package/dist/src/ai/oauth/registry.js +40 -0
  6. package/dist/src/ai/oauth/sign-in-with-chatgpt.d.ts +56 -0
  7. package/dist/src/ai/oauth/sign-in-with-chatgpt.js +552 -0
  8. package/dist/src/ai/openai.d.ts +18 -1
  9. package/dist/src/ai/openai.js +68 -5
  10. package/dist/src/ai/provider.d.ts +3 -0
  11. package/dist/src/ai/provider.js +11 -2
  12. package/dist/src/cli/args.js +40 -18
  13. package/dist/src/cli/commands/config.d.ts +1 -1
  14. package/dist/src/cli/commands/config.js +2 -0
  15. package/dist/src/cli/commands/oauth.d.ts +1 -0
  16. package/dist/src/cli/commands/oauth.js +73 -0
  17. package/dist/src/cli/commands/registry.js +46 -0
  18. package/dist/src/cli/commands/review.js +2 -1
  19. package/dist/src/cli/commands/set.js +14 -1
  20. package/dist/src/cli/main.js +5 -0
  21. package/dist/src/cli/review_args.js +6 -0
  22. package/dist/src/config.d.ts +4 -0
  23. package/dist/src/github/collect.d.ts +2 -2
  24. package/dist/src/github/collect.js +60 -23
  25. package/dist/src/knowledge/types.d.ts +3 -4
  26. package/dist/src/pr/codegraph_tools.d.ts +13 -3
  27. package/dist/src/pr/codegraph_tools.js +26 -7
  28. package/dist/src/pr/reviewer.d.ts +4 -0
  29. package/dist/src/pr/reviewer.js +16 -4
  30. package/dist/src/server/pages/settings.js +2 -2
  31. package/dist/src/services/clear.js +2 -0
  32. package/dist/src/services/setup.js +3 -12
  33. package/dist/src/store/cache_db.js +1 -1
  34. package/dist/src/tools/codegraph.d.ts +15 -0
  35. package/dist/src/tools/codegraph.js +59 -24
  36. package/dist/src/types.d.ts +9 -1
  37. package/package.json +1 -1
@@ -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,14 @@ 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
+ import { aiProviderName } from "../ai/provider.js";
13
+ /** One line naming the provider and the two models a review will call, printed
14
+ * before any AI request so the operator can see what is running. The low model
15
+ * summarizes large diffs, the high model writes the review. */
16
+ export function modelSummary(options) {
17
+ return (`models · provider=${aiProviderName(options)} · low=${options.lowModel ?? "unset"} · ` +
18
+ `high=${options.highModel ?? "unset"}`);
19
+ }
12
20
  /** A model id is never guessed here. Models go stale, and a build already
13
21
  * installed cannot fetch a fresher one, so the id to run comes from config
14
22
  * or a flag, set at least once by whoever runs it (Murat, 2026-09-28). */
@@ -196,6 +204,7 @@ export async function reviewPullRequest(client, options, usage, snapshot, ai, pr
196
204
  throw new Error("review requires a PR number");
197
205
  const number = options.prNumber;
198
206
  const report = progress ?? (() => { });
207
+ report(modelSummary(options));
199
208
  report(`loading PR context for ${options.repo}#${number}`);
200
209
  const [pr, allComments, allReviews, guides] = await Promise.all([
201
210
  client.request(`repos/${options.repo}/pulls/${number}`),
@@ -274,7 +283,9 @@ export async function reviewPullRequest(client, options, usage, snapshot, ai, pr
274
283
  `enough]\n${description}`);
275
284
  })),
276
285
  options.useCodegraph && headSha
277
- ? prepareCodegraphTools(options.repo, number, headSha)
286
+ ? prepareCodegraphTools(options.repo, number, headSha, {
287
+ allowInstall: options.allowToolInstall,
288
+ })
278
289
  : Promise.resolve([]),
279
290
  ]);
280
291
  if (options.useCodegraph) {
@@ -392,7 +403,7 @@ ${diff}`;
392
403
  console.log(`\n----- INITIAL REVIEW -----\n${response.text}\n`);
393
404
  }
394
405
  if (!response.text.trim()) {
395
- throw new Error(`${options.ai} returned an empty review. The reasoning budget may have been exhausted`);
406
+ throw new Error(`${aiProviderName(options)} returned an empty review. The reasoning budget may have been exhausted`);
396
407
  }
397
408
  // The model returns JSON; we render the Markdown. A reply
398
409
  // that is not usable JSON is retried once and then falls back to the legacy
@@ -424,7 +435,7 @@ ${reviewText}`,
424
435
  report(`AI improvement response · input=${response.tokensIn} tokens · ` +
425
436
  `output=${response.tokensOut} tokens`);
426
437
  if (!response.text.trim()) {
427
- throw new Error(`${options.ai} returned an empty review improvement at pass ${pass - 1}`);
438
+ throw new Error(`${aiProviderName(options)} returned an empty review improvement at pass ${pass - 1}`);
428
439
  }
429
440
  reviewText = await normalizeReviewResponse(provider, improvementRequest, response, extraTools, maxToolRounds, usage, report, options);
430
441
  if (options.debug) {
@@ -459,6 +470,7 @@ function revisionToGithubFiles(revision) {
459
470
  /** Local workspace review — same prompt loop as PR review without GitHub. */
460
471
  export async function reviewWorkspaceRevision(revision, options, headSha, usage, ai, progress, extras) {
461
472
  const report = progress ?? (() => { });
473
+ report(modelSummary(options));
462
474
  const guides = await loadGuides(options.repo);
463
475
  const { shortGuide, detailed, codebase, skill } = guides;
464
476
  const guide = shortGuide || skill;
@@ -546,7 +558,7 @@ ${ownDiff}${unchangedListing}`;
546
558
  if (usage)
547
559
  await usage(response);
548
560
  if (!response.text.trim()) {
549
- throw new Error(`${options.ai} returned an empty review`);
561
+ throw new Error(`${aiProviderName(options)} returned an empty review`);
550
562
  }
551
563
  let reviewText = await normalizeReviewResponse(provider, request, response, extraTools, maxToolRounds, usage, report, options);
552
564
  for (let pass = 2; pass <= matrix; pass++) {
@@ -54,7 +54,7 @@ export function renderSettings(username, config, webhookUrl, baseUrl) {
54
54
  <span class="st ${aiOk ? "ok" : "warn"}" style="margin-left:auto">${aiOk ? "Configured" : "Not set"}</span></div>
55
55
  <div class="bd">
56
56
  <div class="field"><label>Provider</label>
57
- <select id="ai">
57
+ <select id="ai-provider">
58
58
  <option value="none"${!config.ai || config.ai === "none" ? " selected" : ""}>None</option>
59
59
  <option value="openrouter"${config.ai === "openrouter" ? " selected" : ""}>OpenRouter</option>
60
60
  <option value="openai"${config.ai === "openai" ? " selected" : ""}>OpenAI</option>
@@ -274,7 +274,7 @@ function save(btn, body) {
274
274
  }
275
275
  document.getElementById("save-ai").addEventListener("click", function() {
276
276
  save(this, {
277
- ai: document.getElementById("ai").value,
277
+ ai: document.getElementById("ai-provider").value,
278
278
  token: document.getElementById("token").value,
279
279
  highModel: document.getElementById("high").value,
280
280
  lowModel: document.getElementById("low").value
@@ -12,6 +12,7 @@
12
12
  * built", which the next `init` fixes. */
13
13
  import { cacheDbPath, cloneDir, clonesDir, configPath, getCacheDir, getConfigDir, locksDir, readConfig, removeAllRepoConfig, removeRepoConfig, repoWorktreesDir, reposDir, toolsDir, worktreesDir, } from "../config.js";
14
14
  import { withKnowledgeLock } from "../review/guides.js";
15
+ import { credentialsDir } from "../ai/oauth/sign-in-with-chatgpt.js";
15
16
  import { appDbLockPath, appDbPath, backupPaths, closeAppDb, isAppDbOpen, openAppDb, } from "../store/app_db.js";
16
17
  import { cacheDbExists, cacheDeleteRepoEvidence, cacheDeleteRepoKnowledge, } from "../store/cache_db.js";
17
18
  import { clearRepoKnowledge } from "../store/repos.js";
@@ -280,6 +281,7 @@ function uninstallTargets() {
280
281
  worktreesDir(),
281
282
  locksDir(),
282
283
  toolsDir(),
284
+ credentialsDir(),
283
285
  backupPaths().root,
284
286
  ];
285
287
  }
@@ -1,7 +1,7 @@
1
1
  /** `init`/`remake` orchestration. The dashboard calls `runInitOrRemake`
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
- import { createAiProvider } from "../ai/provider.js";
4
+ import { aiProviderName, createAiProvider } from "../ai/provider.js";
5
5
  import { enrichFacts, synthesizeSections } from "../knowledge/synthesis.js";
6
6
  import { collectSource } from "../github/collect.js";
7
7
  import { GhClient } from "../github/gh.js";
@@ -171,18 +171,9 @@ async function initOrRemake(options) {
171
171
  if (!lowAi || !highAi) {
172
172
  throw new Error("init requires an AI provider. Run: co-maintainer set --ai=openrouter --token=... --low-model=... --high-model=...");
173
173
  }
174
- log("ai", `${options.ai} providers configured · low=${options.lowModel} · high=${options.highModel}`);
174
+ log("ai", `${aiProviderName(options)} providers configured · low=${options.lowModel} · high=${options.highModel}`);
175
175
  log("fetch", `${options.repo} via ${options.auth}`);
176
- const source = await timed("fetch repository data", options.logTime, () => collectSource(client, options, previous, async (pullRequests, cache) => {
177
- checkpoint.source.pullRequests = pullRequests;
178
- checkpoint.source.pullRequestCache = cache;
179
- checkpoint.scanDone = {
180
- ...checkpoint.scanDone,
181
- pullRequests: pullRequests.length,
182
- updatedAt: new Date().toISOString(),
183
- };
184
- await writeState(checkpoint);
185
- }, async (codebase) => {
176
+ const source = await timed("fetch repository data", options.logTime, () => collectSource(client, options, previous, async (codebase) => {
186
177
  checkpoint.source = {
187
178
  ...checkpoint.source,
188
179
  tree: codebase.tree,
@@ -116,7 +116,7 @@ export async function cacheDeleteRepoEvidence(repo) {
116
116
  for (const namespace of ["pr-listing", "probe"]) {
117
117
  removed += deleteRows(db, namespace, { exact: repo });
118
118
  }
119
- for (const namespace of ["ai-jobs", "cost"]) {
119
+ for (const namespace of ["pr", "ai-jobs", "cost"]) {
120
120
  removed += deleteRows(db, namespace, { prefix: `${repo}:` });
121
121
  }
122
122
  removed += deleteRows(db, "local-review", { prefix: `${repo}\0` });
@@ -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;
@@ -26,6 +30,10 @@ export type Options = {
26
30
  githubPat?: string;
27
31
  ai: "none" | "openrouter" | "openai" | "anthropic" | "opencode-zen" | "opencode-go";
28
32
  aiToken?: string;
33
+ /** Experimental: run this command on the user's ChatGPT plan through Sign
34
+ * in with ChatGPT (`--experimental-siwc`), instead of the API-key provider
35
+ * `ai` names. `ai` and `aiToken` are ignored for that run. */
36
+ experimentalSiwc?: boolean;
29
37
  lowModel?: string;
30
38
  highModel?: string;
31
39
  synthesisVersion: number;
@@ -113,7 +121,7 @@ export type AiResponse = {
113
121
  unknown: number;
114
122
  };
115
123
  model: string;
116
- provider: "openrouter" | "openai" | "anthropic" | "opencode-zen" | "opencode-go";
124
+ provider: "openrouter" | "openai" | "anthropic" | "opencode-zen" | "opencode-go" | "sign-in-with-chatgpt";
117
125
  };
118
126
  export type AiProvider = {
119
127
  supportsTools?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "co-maintainer",
3
- "version": "0.6.0",
3
+ "version": "0.6.3",
4
4
  "description": "An imitator of yours, A PR review tool like co-maintainer.",
5
5
  "keywords": [
6
6
  "ai",