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.
- package/dist/package.json +1 -1
- package/dist/src/ai/oauth/ids.d.ts +10 -0
- package/dist/src/ai/oauth/ids.js +10 -0
- package/dist/src/ai/oauth/registry.d.ts +33 -0
- package/dist/src/ai/oauth/registry.js +40 -0
- package/dist/src/ai/oauth/sign-in-with-chatgpt.d.ts +56 -0
- package/dist/src/ai/oauth/sign-in-with-chatgpt.js +552 -0
- package/dist/src/ai/openai.d.ts +18 -1
- package/dist/src/ai/openai.js +68 -5
- package/dist/src/ai/provider.d.ts +3 -0
- package/dist/src/ai/provider.js +11 -2
- package/dist/src/cli/args.js +40 -18
- package/dist/src/cli/commands/config.d.ts +1 -1
- package/dist/src/cli/commands/config.js +2 -0
- package/dist/src/cli/commands/oauth.d.ts +1 -0
- package/dist/src/cli/commands/oauth.js +73 -0
- package/dist/src/cli/commands/registry.js +46 -0
- package/dist/src/cli/commands/review.js +2 -1
- package/dist/src/cli/commands/set.js +14 -1
- package/dist/src/cli/main.js +5 -0
- package/dist/src/cli/review_args.js +6 -0
- package/dist/src/config.d.ts +4 -0
- package/dist/src/github/collect.d.ts +2 -2
- package/dist/src/github/collect.js +60 -23
- package/dist/src/knowledge/types.d.ts +3 -4
- 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 +16 -4
- package/dist/src/server/pages/settings.js +2 -2
- package/dist/src/services/clear.js +2 -0
- package/dist/src/services/setup.js +3 -12
- package/dist/src/store/cache_db.js +1 -1
- package/dist/src/tools/codegraph.d.ts +15 -0
- package/dist/src/tools/codegraph.js +59 -24
- package/dist/src/types.d.ts +9 -1
- package/package.json +1 -1
|
@@ -6,6 +6,9 @@ export declare const AI_PROVIDERS: readonly ["none", "openrouter", "openai", "an
|
|
|
6
6
|
export { providerKeyEnv } from "../config.ts";
|
|
7
7
|
/** Hetzner was dropped in 0.5.1. Naming it beats a generic "must be one of". */
|
|
8
8
|
export declare function rejectRetiredProvider(value: string | undefined): void;
|
|
9
|
+
/** The provider a run actually calls. `--experimental-siwc` overrides the
|
|
10
|
+
* configured `ai` for the run, so logs and error labels name what ran. */
|
|
11
|
+
export declare function aiProviderName(options: Options): string;
|
|
9
12
|
export declare function createAiProvider(options: Options, model: string): AiProvider | undefined;
|
|
10
13
|
/** A 400 that names one optional part of the request earns one retry without
|
|
11
14
|
* it: the JSON schema, which the prompt asks for anyway, or "thinking off",
|
package/dist/src/ai/provider.js
CHANGED
|
@@ -2,6 +2,7 @@ import { OpenRouterProvider } from "./openrouter.js";
|
|
|
2
2
|
import { OpenAiProvider } from "./openai.js";
|
|
3
3
|
import { AnthropicProvider } from "./anthropic.js";
|
|
4
4
|
import { openCodeHost } from "./opencode.js";
|
|
5
|
+
import { EXPERIMENTAL_OAUTH_PROVIDER, oauthOps } from "./oauth/registry.js";
|
|
5
6
|
import { die } from "../cli/error.js";
|
|
6
7
|
/** The one list of accepted `--ai` values, so a new or retired provider is
|
|
7
8
|
* added or removed in a single place instead of the half dozen copies
|
|
@@ -21,9 +22,17 @@ export function rejectRetiredProvider(value) {
|
|
|
21
22
|
die("Hetzner is no longer supported. Use openrouter or none.");
|
|
22
23
|
}
|
|
23
24
|
}
|
|
25
|
+
/** The provider a run actually calls. `--experimental-siwc` overrides the
|
|
26
|
+
* configured `ai` for the run, so logs and error labels name what ran. */
|
|
27
|
+
export function aiProviderName(options) {
|
|
28
|
+
return options.experimentalSiwc ? EXPERIMENTAL_OAUTH_PROVIDER : options.ai;
|
|
29
|
+
}
|
|
24
30
|
export function createAiProvider(options, model) {
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
// `--experimental-siwc` wins over `--ai` for the run; `parseArgs` refuses
|
|
32
|
+
// the two together, so this only sees one of them set.
|
|
33
|
+
if (options.experimentalSiwc) {
|
|
34
|
+
return oauthOps(EXPERIMENTAL_OAUTH_PROVIDER).createProvider(model);
|
|
35
|
+
}
|
|
27
36
|
if (options.ai === "openrouter") {
|
|
28
37
|
return new OpenRouterProvider(options.aiToken ?? "", model);
|
|
29
38
|
}
|
package/dist/src/cli/args.js
CHANGED
|
@@ -3,6 +3,7 @@ import { getEnv } from "../util/runtime.js";
|
|
|
3
3
|
import { askLine } from "./prompt.js";
|
|
4
4
|
import { die } from "./error.js";
|
|
5
5
|
import { AI_PROVIDERS, providerKeyEnv, rejectRetiredProvider, } from "../ai/provider.js";
|
|
6
|
+
import { availableModelSlugs } from "../ai/oauth/sign-in-with-chatgpt.js";
|
|
6
7
|
import { detectRemoteRepo } from "../local/git_ops.js";
|
|
7
8
|
import { reviewBlockingFrom } from "../review/blocking.js";
|
|
8
9
|
import { renderCommandHelp, renderGlobalHelp, unknownCommandMessage, unknownOptionMessage, } from "./commands/registry.js";
|
|
@@ -160,12 +161,17 @@ export async function parseArgs(args) {
|
|
|
160
161
|
arg === "--review-upstream" ||
|
|
161
162
|
arg === "--disable-codegraph" ||
|
|
162
163
|
arg === "--run" ||
|
|
163
|
-
arg === "--only-request-changed-pr"
|
|
164
|
+
arg === "--only-request-changed-pr" ||
|
|
165
|
+
arg === "--experimental-siwc")
|
|
164
166
|
continue;
|
|
165
167
|
if (arg.startsWith("--") && !known)
|
|
166
168
|
die(unknownOptionMessage(arg, command));
|
|
167
169
|
}
|
|
168
170
|
const explicitAi = rest.some((arg) => arg.startsWith("--ai="));
|
|
171
|
+
const experimentalSiwc = rest.includes("--experimental-siwc");
|
|
172
|
+
if (experimentalSiwc && explicitAi) {
|
|
173
|
+
die("--experimental-siwc cannot be combined with --ai");
|
|
174
|
+
}
|
|
169
175
|
const configuredAiRaw = env("CO_MAINTAINER_AI") ?? repoConfig.ai ?? config.ai;
|
|
170
176
|
rejectRetiredProvider(configuredAiRaw);
|
|
171
177
|
if (configuredAiRaw &&
|
|
@@ -189,24 +195,26 @@ export async function parseArgs(args) {
|
|
|
189
195
|
}
|
|
190
196
|
rejectRetiredProvider(text("ai"));
|
|
191
197
|
let ai = choice("ai", AI_PROVIDERS, configuredAi ?? "none");
|
|
192
|
-
if (
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if (
|
|
198
|
-
|
|
198
|
+
if (!experimentalSiwc) {
|
|
199
|
+
if (command === "review") {
|
|
200
|
+
// Review was pinned to OpenRouter only so Hetzner never wrote one.
|
|
201
|
+
// Hetzner is gone, so review follows the configured provider. With none
|
|
202
|
+
// set it stays on OpenRouter, which every review before this one used.
|
|
203
|
+
if (ai === "none") {
|
|
204
|
+
if (explicitAi) {
|
|
205
|
+
die(`review needs an AI provider. Pass --ai=${AI_PROVIDERS.filter((p) => p !== "none").join("|")}`);
|
|
206
|
+
}
|
|
207
|
+
ai = "openrouter";
|
|
199
208
|
}
|
|
200
|
-
ai = "openrouter";
|
|
201
209
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
210
|
+
else if (!explicitAi && !configuredAi && command !== "probe") {
|
|
211
|
+
const selected = await ask(`AI provider (${AI_PROVIDERS.filter((p) => p !== "none").join("|")})`, "openrouter");
|
|
212
|
+
rejectRetiredProvider(selected);
|
|
213
|
+
if (!AI_PROVIDERS.includes(selected)) {
|
|
214
|
+
die(`AI provider must be one of: ${AI_PROVIDERS.join(", ")}`);
|
|
215
|
+
}
|
|
216
|
+
ai = selected;
|
|
208
217
|
}
|
|
209
|
-
ai = selected;
|
|
210
218
|
}
|
|
211
219
|
let aiToken = text("token") ??
|
|
212
220
|
env("CO_MAINTAINER_TOKEN") ??
|
|
@@ -225,7 +233,19 @@ export async function parseArgs(args) {
|
|
|
225
233
|
env("HIGH_MODEL") ??
|
|
226
234
|
repoConfig.highModel ??
|
|
227
235
|
config.highModel;
|
|
228
|
-
if (
|
|
236
|
+
if (experimentalSiwc) {
|
|
237
|
+
// No API key: the OAuth credentials cover the run. The models still come
|
|
238
|
+
// from the user, but the account's own list is shown first so the value
|
|
239
|
+
// is easy to pick, and it is shown again on a bad model.
|
|
240
|
+
if (command !== "probe" && (!lowModel || !highModel)) {
|
|
241
|
+
const slugs = await availableModelSlugs().catch(() => []);
|
|
242
|
+
if (slugs.length)
|
|
243
|
+
console.log(`ChatGPT models: ${slugs.join(", ")}`);
|
|
244
|
+
}
|
|
245
|
+
lowModel ??= await ask("low model", undefined, true);
|
|
246
|
+
highModel ??= await ask("high model", undefined, true);
|
|
247
|
+
}
|
|
248
|
+
else if (command === "review") {
|
|
229
249
|
aiToken ??= await ask(`${ai} API key`, undefined, true);
|
|
230
250
|
// Review summarizes large files with the low model, so it needs one just
|
|
231
251
|
// as init and sync do. Without a default to fall back on, ask here too.
|
|
@@ -240,7 +260,8 @@ export async function parseArgs(args) {
|
|
|
240
260
|
lowModel ??= await ask("low model", undefined, true);
|
|
241
261
|
highModel ??= await ask("high model", undefined, true);
|
|
242
262
|
}
|
|
243
|
-
if (
|
|
263
|
+
if (!experimentalSiwc &&
|
|
264
|
+
command !== "review" &&
|
|
244
265
|
ai !== "none" &&
|
|
245
266
|
(!lowModel || !highModel || !aiToken)) {
|
|
246
267
|
die("--token, --low-model, and --high-model are required when AI is enabled");
|
|
@@ -262,6 +283,7 @@ export async function parseArgs(args) {
|
|
|
262
283
|
githubPat,
|
|
263
284
|
ai,
|
|
264
285
|
aiToken,
|
|
286
|
+
...(experimentalSiwc ? { experimentalSiwc: true } : {}),
|
|
265
287
|
lowModel,
|
|
266
288
|
highModel,
|
|
267
289
|
synthesisVersion: 17,
|
|
@@ -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",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runOAuth(args: string[]): Promise<void>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** `co-maintainer oauth login|logout|refresh|ping|list-models --provider=...`
|
|
2
|
+
*
|
|
3
|
+
* The credential side of the experimental Sign in with ChatGPT support. Only
|
|
4
|
+
* `login` starts a browser flow; the rest operate on an existing login and
|
|
5
|
+
* fail clearly when there is none. See `docs/docs/providers.md`. */
|
|
6
|
+
import { die } from "../error.js";
|
|
7
|
+
import { oauthOps, oauthUnknownProvider, resolveOAuthProvider, } from "../../ai/oauth/registry.js";
|
|
8
|
+
import { renderCommandHelp, renderGlobalHelp } from "./registry.js";
|
|
9
|
+
const SUBCOMMANDS = [
|
|
10
|
+
"login",
|
|
11
|
+
"logout",
|
|
12
|
+
"refresh",
|
|
13
|
+
"ping",
|
|
14
|
+
"list-models",
|
|
15
|
+
];
|
|
16
|
+
function text(args, name) {
|
|
17
|
+
return args
|
|
18
|
+
.find((arg) => arg.startsWith(`--${name}=`))
|
|
19
|
+
?.slice(name.length + 3);
|
|
20
|
+
}
|
|
21
|
+
export async function runOAuth(args) {
|
|
22
|
+
const sub = args[0];
|
|
23
|
+
if (!sub || sub === "--help" || sub === "-h" || sub === "help") {
|
|
24
|
+
console.log(renderCommandHelp("oauth") ?? renderGlobalHelp());
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!SUBCOMMANDS.includes(sub)) {
|
|
28
|
+
die(`oauth must be one of: ${SUBCOMMANDS.join(", ")}`);
|
|
29
|
+
}
|
|
30
|
+
for (const arg of args.slice(1)) {
|
|
31
|
+
if (!arg.startsWith("--provider=")) {
|
|
32
|
+
die(`Unknown option: ${arg}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const provider = resolveOAuthProvider(text(args, "provider"));
|
|
36
|
+
if (!provider)
|
|
37
|
+
throw oauthUnknownProvider(text(args, "provider"));
|
|
38
|
+
const ops = oauthOps(provider);
|
|
39
|
+
const printModels = (models) => {
|
|
40
|
+
if (models.length === 0) {
|
|
41
|
+
console.log("No models are available to this account.");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
console.log("Available models:");
|
|
45
|
+
for (const model of models) {
|
|
46
|
+
console.log(` ${model.slug} (${model.displayName})`);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
if (sub === "login") {
|
|
50
|
+
const creds = await ops.login();
|
|
51
|
+
console.log(`Signed in${creds.email ? ` as ${creds.email}` : ""}. Saved to ${ops.credentialsPath()}`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (sub === "logout") {
|
|
55
|
+
const removed = await ops.logout();
|
|
56
|
+
console.log(removed
|
|
57
|
+
? "Signed out. The saved ChatGPT credentials were removed."
|
|
58
|
+
: "Nothing to sign out.");
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (sub === "refresh") {
|
|
62
|
+
const creds = await ops.refresh();
|
|
63
|
+
console.log(`Refreshed. New expiry: ${new Date(creds.expires_at).toISOString()}`);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (sub === "ping") {
|
|
67
|
+
const { credentials, models } = await ops.ping();
|
|
68
|
+
console.log(`Signed in${credentials.email ? ` as ${credentials.email}` : ""}.`);
|
|
69
|
+
printModels(models);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
printModels(await ops.listModels());
|
|
73
|
+
}
|
|
@@ -73,6 +73,17 @@ const AI_FLAGS_REQUIRED = {
|
|
|
73
73
|
...AI_KEY_FLAGS,
|
|
74
74
|
],
|
|
75
75
|
};
|
|
76
|
+
/** `--experimental-siwc`: run on a ChatGPT plan through Sign in with ChatGPT
|
|
77
|
+
* instead of an API key. Its own group so it reads as not yet settled. */
|
|
78
|
+
const EXPERIMENTAL_FLAGS = {
|
|
79
|
+
title: "Experimental",
|
|
80
|
+
flags: [
|
|
81
|
+
{
|
|
82
|
+
name: "experimental-siwc",
|
|
83
|
+
description: "Run on your ChatGPT plan through Sign in with ChatGPT instead of an API key. Cannot be combined with --ai. Set up with co-maintainer oauth.",
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
};
|
|
76
87
|
const GITHUB_FLAGS = {
|
|
77
88
|
title: "GitHub access",
|
|
78
89
|
flags: [
|
|
@@ -203,6 +214,7 @@ export const COMMANDS = [
|
|
|
203
214
|
],
|
|
204
215
|
},
|
|
205
216
|
AI_FLAGS_REQUIRED,
|
|
217
|
+
EXPERIMENTAL_FLAGS,
|
|
206
218
|
GITHUB_FLAGS,
|
|
207
219
|
OUTPUT_FLAGS,
|
|
208
220
|
{
|
|
@@ -290,6 +302,7 @@ export const COMMANDS = [
|
|
|
290
302
|
],
|
|
291
303
|
},
|
|
292
304
|
AI_FLAGS_REQUIRED,
|
|
305
|
+
EXPERIMENTAL_FLAGS,
|
|
293
306
|
GITHUB_FLAGS,
|
|
294
307
|
OUTPUT_FLAGS,
|
|
295
308
|
],
|
|
@@ -387,6 +400,7 @@ export const COMMANDS = [
|
|
|
387
400
|
],
|
|
388
401
|
},
|
|
389
402
|
AI_FLAGS,
|
|
403
|
+
EXPERIMENTAL_FLAGS,
|
|
390
404
|
GITHUB_FLAGS,
|
|
391
405
|
REVIEW_OUTPUT_FLAGS,
|
|
392
406
|
],
|
|
@@ -505,6 +519,33 @@ export const COMMANDS = [
|
|
|
505
519
|
],
|
|
506
520
|
examples: ["co-maintainer uninstall", "co-maintainer uninstall --yes"],
|
|
507
521
|
},
|
|
522
|
+
{
|
|
523
|
+
name: "oauth",
|
|
524
|
+
summary: "Sign in to an OAuth AI provider (experimental).",
|
|
525
|
+
usage: [
|
|
526
|
+
"co-maintainer oauth login --provider=sign-in-with-chatgpt",
|
|
527
|
+
"co-maintainer oauth logout --provider=sign-in-with-chatgpt",
|
|
528
|
+
"co-maintainer oauth refresh --provider=sign-in-with-chatgpt",
|
|
529
|
+
"co-maintainer oauth ping --provider=sign-in-with-chatgpt",
|
|
530
|
+
"co-maintainer oauth list-models --provider=sign-in-with-chatgpt",
|
|
531
|
+
],
|
|
532
|
+
groups: [
|
|
533
|
+
{
|
|
534
|
+
title: "OAuth",
|
|
535
|
+
flags: [
|
|
536
|
+
{
|
|
537
|
+
name: "provider",
|
|
538
|
+
value: "sign-in-with-chatgpt",
|
|
539
|
+
description: "Which provider to sign in to. `siwc` is accepted as a short alias.",
|
|
540
|
+
},
|
|
541
|
+
],
|
|
542
|
+
},
|
|
543
|
+
],
|
|
544
|
+
examples: [
|
|
545
|
+
"co-maintainer oauth login --provider=sign-in-with-chatgpt",
|
|
546
|
+
"co-maintainer oauth list-models --provider=siwc",
|
|
547
|
+
],
|
|
548
|
+
},
|
|
508
549
|
{
|
|
509
550
|
name: "set",
|
|
510
551
|
summary: "Persist defaults and secrets to the user config file.",
|
|
@@ -613,6 +654,11 @@ export const COMMANDS = [
|
|
|
613
654
|
default: "model",
|
|
614
655
|
description: "How a review decides a blocking finding.",
|
|
615
656
|
},
|
|
657
|
+
{
|
|
658
|
+
name: "codegraph-version",
|
|
659
|
+
value: "SEMVER",
|
|
660
|
+
description: "The pinned codegraph version, overriding the built-in one. For a security fix without a release.",
|
|
661
|
+
},
|
|
616
662
|
{
|
|
617
663
|
name: "password",
|
|
618
664
|
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
|
package/dist/src/cli/main.js
CHANGED
|
@@ -4,6 +4,7 @@ import { parseArgs } from "./args.js";
|
|
|
4
4
|
import { runServe } from "./commands/serve.js";
|
|
5
5
|
import { runRollback } from "./commands/rollback.js";
|
|
6
6
|
import { runSet } from "./commands/set.js";
|
|
7
|
+
import { runOAuth } from "./commands/oauth.js";
|
|
7
8
|
import { runConfig } from "./commands/config.js";
|
|
8
9
|
import { runView } from "./commands/view.js";
|
|
9
10
|
import { runClear } from "./commands/clear.js";
|
|
@@ -62,6 +63,10 @@ export async function run(args) {
|
|
|
62
63
|
await runSet(args.slice(1));
|
|
63
64
|
return;
|
|
64
65
|
}
|
|
66
|
+
if (args[0] === "oauth") {
|
|
67
|
+
await runOAuth(args.slice(1));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
65
70
|
if (args[0] === "config") {
|
|
66
71
|
await runConfig(args.slice(1));
|
|
67
72
|
return;
|
|
@@ -109,6 +109,11 @@ export async function loadReviewSystemPromptFlags(cli, limit) {
|
|
|
109
109
|
export async function parseReviewArgs(args) {
|
|
110
110
|
const positional = args.filter((a) => !a.startsWith("--"));
|
|
111
111
|
const flags = reviewFlags(args);
|
|
112
|
+
// Remote review runs on the server's provider, so the experimental local
|
|
113
|
+
// provider has nothing to attach to.
|
|
114
|
+
if (flags.remote && args.includes("--experimental-siwc")) {
|
|
115
|
+
die("--experimental-siwc cannot be used with --remote");
|
|
116
|
+
}
|
|
112
117
|
// `--remote-host` / `--remote-token` only mean something together with
|
|
113
118
|
// `--remote`; silently dropping them is exactly the kind of surprise to avoid.
|
|
114
119
|
if ((flags.remoteHost || flags.remoteToken) && !flags.remote) {
|
|
@@ -148,6 +153,7 @@ export async function parseReviewArgs(args) {
|
|
|
148
153
|
options: {
|
|
149
154
|
...options,
|
|
150
155
|
useCodegraph: flags.disableCodegraph ? false : true,
|
|
156
|
+
allowToolInstall: flags.allowToolInstall,
|
|
151
157
|
reviewSystemPromptAdd: promptFlags.add,
|
|
152
158
|
reviewSystemPromptOverride: promptFlags.override,
|
|
153
159
|
},
|
package/dist/src/config.d.ts
CHANGED
|
@@ -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`. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GitHubClient, Options } from "../types.ts";
|
|
2
|
-
import type {
|
|
3
|
-
export declare function collectSource(client: GitHubClient, options: Options, previous?: State,
|
|
2
|
+
import type { Source, State } from "../knowledge/types.ts";
|
|
3
|
+
export declare function collectSource(client: GitHubClient, options: Options, previous?: State, codebaseProgress?: (data: {
|
|
4
4
|
tree: string[];
|
|
5
5
|
treeSha: Record<string, string>;
|
|
6
6
|
files: Record<string, string>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { log, startHeartbeat } from "../util/log.js";
|
|
2
|
-
import { cacheGet, cacheSet } from "../store/cache_db.js";
|
|
2
|
+
import { cacheGet, cacheSet, cacheValues } from "../store/cache_db.js";
|
|
3
3
|
function decodeBase64(value) {
|
|
4
4
|
const binary = atob(value.replaceAll("\n", ""));
|
|
5
5
|
const bytes = Uint8Array.from(binary, (character) => character.charCodeAt(0));
|
|
@@ -244,24 +244,62 @@ async function codebase(client, repo, meta, concurrency, previous, phase, progre
|
|
|
244
244
|
});
|
|
245
245
|
return { tree, treeSha, files };
|
|
246
246
|
}
|
|
247
|
-
|
|
247
|
+
/** One pull request's cached evidence, keyed by number. `cacheValues` returns
|
|
248
|
+
* the newest rows first, so a later row for the same number wins. Legacy
|
|
249
|
+
* entries still in the state blob are merged in when their row is missing, so
|
|
250
|
+
* a migration interrupted after the first row resumes instead of treating the
|
|
251
|
+
* rows it wrote as proof that every pull request moved. */
|
|
252
|
+
async function loadPrCache(repo, previous) {
|
|
253
|
+
const cache = new Map();
|
|
254
|
+
for (const raw of await cacheValues("pr", `${repo}:`)) {
|
|
255
|
+
try {
|
|
256
|
+
const pr = JSON.parse(raw);
|
|
257
|
+
if (typeof pr?.number === "number")
|
|
258
|
+
cache.set(pr.number, pr);
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
// A corrupt row is skipped rather than losing every other row.
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
for (const pr of legacyPrCache(previous)) {
|
|
265
|
+
if (cache.has(pr.number))
|
|
266
|
+
continue;
|
|
267
|
+
cache.set(pr.number, pr);
|
|
268
|
+
await savePr(repo, pr);
|
|
269
|
+
}
|
|
270
|
+
return cache;
|
|
271
|
+
}
|
|
272
|
+
/** The single state blob used to hold every decided pull request before they
|
|
273
|
+
* moved to one row per pull request. Read once, then rewritten as rows. */
|
|
274
|
+
function legacyPrCache(previous) {
|
|
275
|
+
const source = previous?.source;
|
|
276
|
+
const byNumber = new Map();
|
|
277
|
+
for (const pr of [
|
|
278
|
+
...(source?.pullRequestCache ?? []),
|
|
279
|
+
...(source?.pullRequests ?? []),
|
|
280
|
+
]) {
|
|
281
|
+
if (!byNumber.has(pr.number))
|
|
282
|
+
byNumber.set(pr.number, pr);
|
|
283
|
+
}
|
|
284
|
+
return [...byNumber.values()];
|
|
285
|
+
}
|
|
286
|
+
async function savePr(repo, pr) {
|
|
287
|
+
await cacheSet("pr", `${repo}:${pr.number}`, JSON.stringify(pr));
|
|
288
|
+
}
|
|
289
|
+
async function pullRequests(client, options, previous, phase) {
|
|
248
290
|
if (phase)
|
|
249
291
|
phase.text = "listing pull requests · page 0 · fetched 0";
|
|
250
292
|
const selected = await listPullRequestPages(client, options, phase);
|
|
251
|
-
const
|
|
252
|
-
const cacheByNumber = new Map((previous?.source.pullRequestCache ?? []).map((pr) => [pr.number, pr]));
|
|
293
|
+
const prCache = await loadPrCache(options.repo, previous);
|
|
253
294
|
const result = new Array(selected.length);
|
|
254
|
-
const cache = new Array(selected.length);
|
|
255
295
|
let completed = 0;
|
|
256
|
-
let save = Promise.resolve();
|
|
257
296
|
if (phase) {
|
|
258
297
|
phase.text = `pull requests 0/${selected.length} · 0% · concurrency=${options.ghConcurrent}`;
|
|
259
298
|
}
|
|
260
299
|
log("fetch", `${selected.length} pull requests · concurrency=${options.ghConcurrent}`);
|
|
261
300
|
await mapPool(selected, options.ghConcurrent, async (pr, index) => {
|
|
262
301
|
const number = Number(pr.number);
|
|
263
|
-
const
|
|
264
|
-
const cached = full ?? cacheByNumber.get(number);
|
|
302
|
+
const cached = prCache.get(number);
|
|
265
303
|
const listedAdditions = Number(pr.additions);
|
|
266
304
|
const listedDeletions = Number(pr.deletions);
|
|
267
305
|
const listedStatsAvailable = Number.isFinite(listedAdditions) &&
|
|
@@ -312,9 +350,9 @@ async function pullRequests(client, options, previous, phase, progress) {
|
|
|
312
350
|
current.changesRequested = cached.changesRequested;
|
|
313
351
|
}
|
|
314
352
|
const only = options.onlyRequestChangedPr;
|
|
315
|
-
const discussionUnchanged =
|
|
353
|
+
const discussionUnchanged = cached?.updatedAt === current.updatedAt;
|
|
316
354
|
const decisionKnown = typeof cached?.changesRequested === "boolean";
|
|
317
|
-
const diffUnchanged =
|
|
355
|
+
const diffUnchanged = cached?.headSha === current.headSha && Boolean(cached?.diff);
|
|
318
356
|
let droppedFromCache = only &&
|
|
319
357
|
cached?.updatedAt === current.updatedAt &&
|
|
320
358
|
cached.changesRequested === false;
|
|
@@ -406,7 +444,12 @@ async function pullRequests(client, options, previous, phase, progress) {
|
|
|
406
444
|
current.diff = "";
|
|
407
445
|
}
|
|
408
446
|
}
|
|
409
|
-
|
|
447
|
+
const shouldSave = !cached ||
|
|
448
|
+
!discussionUnchanged ||
|
|
449
|
+
!diffUnchanged ||
|
|
450
|
+
(!decisionKnown && typeof current.changesRequested === "boolean");
|
|
451
|
+
if (shouldSave)
|
|
452
|
+
await savePr(options.repo, current);
|
|
410
453
|
if (!dropped)
|
|
411
454
|
result[index] = current;
|
|
412
455
|
completed++;
|
|
@@ -414,17 +457,12 @@ async function pullRequests(client, options, previous, phase, progress) {
|
|
|
414
457
|
phase.text = `pull requests ${completed}/${selected.length} · ${percent(completed, selected.length)}`;
|
|
415
458
|
}
|
|
416
459
|
log("fetch", `PR ${completed}/${selected.length} · ${percent(completed, selected.length)} #${number} · ${discussionStatus} · ${diffStatus}`);
|
|
417
|
-
if (progress) {
|
|
418
|
-
save = save.then(() => progress(result.filter((item) => !!item), cache.filter((item) => !!item)));
|
|
419
|
-
await save;
|
|
420
|
-
}
|
|
421
460
|
});
|
|
422
461
|
const kept = result.filter((item) => !!item);
|
|
423
|
-
const decided = cache.filter((item) => !!item);
|
|
424
462
|
if (options.onlyRequestChangedPr) {
|
|
425
463
|
log("fetch", `only request-changed pr · kept ${kept.length} · dropped ${selected.length - kept.length}`);
|
|
426
464
|
}
|
|
427
|
-
return
|
|
465
|
+
return kept;
|
|
428
466
|
}
|
|
429
467
|
function commitLimit(maxCommits) {
|
|
430
468
|
return maxCommits && maxCommits > 0 ? maxCommits : undefined;
|
|
@@ -492,7 +530,7 @@ async function commits(client, options, meta, previous, phase) {
|
|
|
492
530
|
}
|
|
493
531
|
return selected;
|
|
494
532
|
}
|
|
495
|
-
export async function collectSource(client, options, previous,
|
|
533
|
+
export async function collectSource(client, options, previous, codebaseProgress) {
|
|
496
534
|
const phase = { text: "reading repository metadata" };
|
|
497
535
|
const stopHeartbeat = startHeartbeat(() => phase.text);
|
|
498
536
|
try {
|
|
@@ -501,9 +539,9 @@ export async function collectSource(client, options, previous, progress, codebas
|
|
|
501
539
|
const files = includeCodebase
|
|
502
540
|
? await codebase(client, options.repo, repo, options.ghConcurrent, previous?.source, phase, codebaseProgress)
|
|
503
541
|
: { tree: [], treeSha: {}, files: {} };
|
|
504
|
-
const
|
|
505
|
-
? await pullRequests(client, options, previous, phase
|
|
506
|
-
:
|
|
542
|
+
const selectedPullRequests = options.includePullRequests
|
|
543
|
+
? await pullRequests(client, options, previous, phase)
|
|
544
|
+
: [];
|
|
507
545
|
const commitData = options.includeCommitHistory
|
|
508
546
|
? await commits(client, options, repo, previous, phase)
|
|
509
547
|
: [];
|
|
@@ -512,8 +550,7 @@ export async function collectSource(client, options, previous, progress, codebas
|
|
|
512
550
|
tree: files.tree,
|
|
513
551
|
treeSha: files.treeSha,
|
|
514
552
|
files: files.files,
|
|
515
|
-
pullRequests:
|
|
516
|
-
pullRequestCache: pullRequestData.cache,
|
|
553
|
+
pullRequests: selectedPullRequests,
|
|
517
554
|
commits: commitData,
|
|
518
555
|
};
|
|
519
556
|
}
|
|
@@ -27,11 +27,10 @@ export type Source = {
|
|
|
27
27
|
tree: string[];
|
|
28
28
|
treeSha: Record<string, string>;
|
|
29
29
|
files: Record<string, string>;
|
|
30
|
-
/** Pull requests selected for facts and the skill.
|
|
30
|
+
/** Pull requests selected for facts and the skill. Every decided pull
|
|
31
|
+
* request, including ones left out of the skill, is kept per pull request in
|
|
32
|
+
* cache.db, so a `changesRequested: false` result is not downloaded again. */
|
|
31
33
|
pullRequests: PullRequest[];
|
|
32
|
-
/** Every pull request already decided, including ones left out of the skill.
|
|
33
|
-
* The next fetch reads this so a `changesRequested: false` result is not downloaded again. */
|
|
34
|
-
pullRequestCache?: PullRequest[];
|
|
35
34
|
commits: Json[];
|
|
36
35
|
};
|
|
37
36
|
export type Fact = {
|