co-maintainer 0.6.1 → 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/oauth.d.ts +1 -0
- package/dist/src/cli/commands/oauth.js +73 -0
- package/dist/src/cli/commands/registry.js +41 -0
- package/dist/src/cli/main.js +5 -0
- package/dist/src/cli/review_args.js +5 -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/reviewer.js +5 -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/types.d.ts +5 -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,
|
|
@@ -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.",
|
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) {
|
|
@@ -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 = {
|
package/dist/src/pr/reviewer.js
CHANGED
|
@@ -9,11 +9,12 @@ 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";
|
|
12
13
|
/** One line naming the provider and the two models a review will call, printed
|
|
13
14
|
* before any AI request so the operator can see what is running. The low model
|
|
14
15
|
* summarizes large diffs, the high model writes the review. */
|
|
15
16
|
export function modelSummary(options) {
|
|
16
|
-
return (`models · provider=${options
|
|
17
|
+
return (`models · provider=${aiProviderName(options)} · low=${options.lowModel ?? "unset"} · ` +
|
|
17
18
|
`high=${options.highModel ?? "unset"}`);
|
|
18
19
|
}
|
|
19
20
|
/** A model id is never guessed here. Models go stale, and a build already
|
|
@@ -402,7 +403,7 @@ ${diff}`;
|
|
|
402
403
|
console.log(`\n----- INITIAL REVIEW -----\n${response.text}\n`);
|
|
403
404
|
}
|
|
404
405
|
if (!response.text.trim()) {
|
|
405
|
-
throw new Error(`${options
|
|
406
|
+
throw new Error(`${aiProviderName(options)} returned an empty review. The reasoning budget may have been exhausted`);
|
|
406
407
|
}
|
|
407
408
|
// The model returns JSON; we render the Markdown. A reply
|
|
408
409
|
// that is not usable JSON is retried once and then falls back to the legacy
|
|
@@ -434,7 +435,7 @@ ${reviewText}`,
|
|
|
434
435
|
report(`AI improvement response · input=${response.tokensIn} tokens · ` +
|
|
435
436
|
`output=${response.tokensOut} tokens`);
|
|
436
437
|
if (!response.text.trim()) {
|
|
437
|
-
throw new Error(`${options
|
|
438
|
+
throw new Error(`${aiProviderName(options)} returned an empty review improvement at pass ${pass - 1}`);
|
|
438
439
|
}
|
|
439
440
|
reviewText = await normalizeReviewResponse(provider, improvementRequest, response, extraTools, maxToolRounds, usage, report, options);
|
|
440
441
|
if (options.debug) {
|
|
@@ -557,7 +558,7 @@ ${ownDiff}${unchangedListing}`;
|
|
|
557
558
|
if (usage)
|
|
558
559
|
await usage(response);
|
|
559
560
|
if (!response.text.trim()) {
|
|
560
|
-
throw new Error(`${options
|
|
561
|
+
throw new Error(`${aiProviderName(options)} returned an empty review`);
|
|
561
562
|
}
|
|
562
563
|
let reviewText = await normalizeReviewResponse(provider, request, response, extraTools, maxToolRounds, usage, report, options);
|
|
563
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
|
|
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 (
|
|
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` });
|
package/dist/src/types.d.ts
CHANGED
|
@@ -30,6 +30,10 @@ export type Options = {
|
|
|
30
30
|
githubPat?: string;
|
|
31
31
|
ai: "none" | "openrouter" | "openai" | "anthropic" | "opencode-zen" | "opencode-go";
|
|
32
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;
|
|
33
37
|
lowModel?: string;
|
|
34
38
|
highModel?: string;
|
|
35
39
|
synthesisVersion: number;
|
|
@@ -117,7 +121,7 @@ export type AiResponse = {
|
|
|
117
121
|
unknown: number;
|
|
118
122
|
};
|
|
119
123
|
model: string;
|
|
120
|
-
provider: "openrouter" | "openai" | "anthropic" | "opencode-zen" | "opencode-go";
|
|
124
|
+
provider: "openrouter" | "openai" | "anthropic" | "opencode-zen" | "opencode-go" | "sign-in-with-chatgpt";
|
|
121
125
|
};
|
|
122
126
|
export type AiProvider = {
|
|
123
127
|
supportsTools?: boolean;
|