co-maintainer 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +1 -1
- package/dist/src/ai/batch.d.ts +19 -16
- package/dist/src/ai/batch.js +68 -46
- package/dist/src/cli/args.js +3 -2
- package/dist/src/cli/commands/registry.js +66 -17
- package/dist/src/cli/commands/set.js +102 -1
- package/dist/src/cli/review_args.d.ts +15 -0
- package/dist/src/cli/review_args.js +41 -1
- package/dist/src/config.d.ts +7 -0
- package/dist/src/github/collect.js +19 -1
- package/dist/src/knowledge/guide.d.ts +19 -4
- package/dist/src/knowledge/guide.js +222 -87
- package/dist/src/knowledge/skill.d.ts +4 -5
- package/dist/src/knowledge/skill.js +27 -35
- package/dist/src/knowledge/synthesis.d.ts +0 -13
- package/dist/src/knowledge/synthesis.js +176 -84
- package/dist/src/knowledge/types.d.ts +22 -0
- package/dist/src/local/review_local.js +4 -1
- package/dist/src/pr/reviewer.js +3 -2
- package/dist/src/remote/client.js +14 -1
- package/dist/src/remote/schema.d.ts +3 -0
- package/dist/src/remote/schema.js +3 -0
- package/dist/src/remote/validate.js +12 -1
- package/dist/src/review/system_prompt.d.ts +19 -0
- package/dist/src/review/system_prompt.js +34 -0
- package/dist/src/server/api/repos.js +56 -2
- package/dist/src/server/pages/client.d.ts +1 -1
- package/dist/src/server/pages/client.js +1 -1
- package/dist/src/server/pages/repo_settings.js +31 -0
- package/dist/src/services/remote_review.js +31 -2
- package/dist/src/services/review.js +2 -1
- package/dist/src/services/setup.js +63 -53
- package/dist/src/store/migrations.js +7 -0
- package/dist/src/store/remote_review_inputs.d.ts +2 -0
- package/dist/src/store/remote_review_inputs.js +3 -3
- package/dist/src/store/rows.d.ts +3 -0
- package/dist/src/types.d.ts +11 -0
- package/package.json +1 -1
package/dist/package.json
CHANGED
package/dist/src/ai/batch.d.ts
CHANGED
|
@@ -5,12 +5,20 @@ type UsageSink = (job: string, response: AiResponse) => Promise<void>;
|
|
|
5
5
|
* fine HTTP response can still be unparseable output, and caching that is what
|
|
6
6
|
* poisoned every later `sync`. */
|
|
7
7
|
export type AiValidator = (request: AiRequest, response: AiResponse) => string | null;
|
|
8
|
-
/** A
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
/** A provider call and an unusable response are both retried this many times
|
|
9
|
+
* before the batch gives up and the run fails. */
|
|
10
|
+
export declare const MAX_ATTEMPTS = 3;
|
|
11
|
+
/** A rate-limited unit gets more tries than a broken one. The provider needs a
|
|
12
|
+
* window to recover, and giving up after three fast retries fails a run that
|
|
13
|
+
* would have gone through a minute later. Only `429`/`rate limit` failures use
|
|
14
|
+
* this bound. */
|
|
15
|
+
export declare const MAX_RATE_LIMIT_ATTEMPTS = 6;
|
|
16
|
+
/** True when a failure is the provider throttling, not a broken request. */
|
|
17
|
+
export declare function isRateLimit(reason: string): boolean;
|
|
18
|
+
/** How long to wait before the next attempt. Zero unless the failure is a rate
|
|
19
|
+
* limit, so every other failure retries immediately. Exported so the schedule
|
|
20
|
+
* can be tested without waiting on it. */
|
|
21
|
+
export declare function retryDelayMs(reason: string, attempt: number): number;
|
|
14
22
|
export declare class AiBatch {
|
|
15
23
|
private records;
|
|
16
24
|
private loaded;
|
|
@@ -20,19 +28,14 @@ export declare class AiBatch {
|
|
|
20
28
|
private readonly concurrency;
|
|
21
29
|
private readonly profile;
|
|
22
30
|
private readonly validate?;
|
|
23
|
-
private readonly skipped;
|
|
24
31
|
constructor(provider: AiProvider, repo: string, concurrency: number, profile: string, validate?: AiValidator);
|
|
25
|
-
/** Units whose output did not parse this run (or on re-try), in request order. */
|
|
26
|
-
skippedUnits(): SkippedUnit[];
|
|
27
32
|
run(requests: AiRequest[], usage?: UsageSink): Promise<(AiResponse | undefined)[]>;
|
|
28
|
-
/** Runs one unit,
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
33
|
+
/** Runs one unit, retrying a provider error and a response the validator
|
|
34
|
+
* rejects. It never throws: a provider error that outlives its retries drops
|
|
35
|
+
* the unit, and a response that still does not validate is used anyway. A run
|
|
36
|
+
* that has already paid for extraction must still write what it has; a format
|
|
37
|
+
* deviation is not worth losing the whole run over. */
|
|
32
38
|
private completeUnit;
|
|
33
|
-
/** Records a unit as skipped: no cache write, so it stays retried and its
|
|
34
|
-
* absence is never mistaken for a deliberate empty result. */
|
|
35
|
-
private markSkipped;
|
|
36
39
|
private load;
|
|
37
40
|
private persist;
|
|
38
41
|
}
|
package/dist/src/ai/batch.js
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
import { cacheGet, cacheSet } from "../store/cache_db.js";
|
|
2
2
|
import { isNotFound, readTextFile } from "../util/runtime.js";
|
|
3
3
|
import { formatError } from "../cli/error.js";
|
|
4
|
+
/** A provider call and an unusable response are both retried this many times
|
|
5
|
+
* before the batch gives up and the run fails. */
|
|
6
|
+
export const MAX_ATTEMPTS = 3;
|
|
7
|
+
/** A rate-limited unit gets more tries than a broken one. The provider needs a
|
|
8
|
+
* window to recover, and giving up after three fast retries fails a run that
|
|
9
|
+
* would have gone through a minute later. Only `429`/`rate limit` failures use
|
|
10
|
+
* this bound. */
|
|
11
|
+
export const MAX_RATE_LIMIT_ATTEMPTS = 6;
|
|
12
|
+
const RATE_LIMIT_BACKOFF_MS = [5_000, 15_000, 30_000, 45_000, 60_000];
|
|
13
|
+
/** True when a failure is the provider throttling, not a broken request. */
|
|
14
|
+
export function isRateLimit(reason) {
|
|
15
|
+
return /429|rate limit/i.test(reason);
|
|
16
|
+
}
|
|
17
|
+
/** How long to wait before the next attempt. Zero unless the failure is a rate
|
|
18
|
+
* limit, so every other failure retries immediately. Exported so the schedule
|
|
19
|
+
* can be tested without waiting on it. */
|
|
20
|
+
export function retryDelayMs(reason, attempt) {
|
|
21
|
+
if (!isRateLimit(reason))
|
|
22
|
+
return 0;
|
|
23
|
+
return RATE_LIMIT_BACKOFF_MS[Math.min(attempt - 1, RATE_LIMIT_BACKOFF_MS.length - 1)];
|
|
24
|
+
}
|
|
4
25
|
async function digest(value) {
|
|
5
26
|
const bytes = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(value));
|
|
6
27
|
return [...new Uint8Array(bytes)]
|
|
@@ -16,7 +37,6 @@ export class AiBatch {
|
|
|
16
37
|
concurrency;
|
|
17
38
|
profile;
|
|
18
39
|
validate;
|
|
19
|
-
skipped = [];
|
|
20
40
|
constructor(provider, repo, concurrency, profile, validate) {
|
|
21
41
|
this.provider = provider;
|
|
22
42
|
this.repo = repo;
|
|
@@ -24,10 +44,6 @@ export class AiBatch {
|
|
|
24
44
|
this.profile = profile;
|
|
25
45
|
this.validate = validate;
|
|
26
46
|
}
|
|
27
|
-
/** Units whose output did not parse this run (or on re-try), in request order. */
|
|
28
|
-
skippedUnits() {
|
|
29
|
-
return [...this.skipped];
|
|
30
|
-
}
|
|
31
47
|
async run(requests, usage) {
|
|
32
48
|
await this.load();
|
|
33
49
|
const results = new Array(requests.length);
|
|
@@ -59,7 +75,11 @@ export class AiBatch {
|
|
|
59
75
|
}
|
|
60
76
|
}
|
|
61
77
|
else if (cached?.status === "quarantine") {
|
|
62
|
-
|
|
78
|
+
// A provider error from an earlier run is not a permanent verdict: drop
|
|
79
|
+
// the record and try again rather than skipping it forever.
|
|
80
|
+
delete this.records[id];
|
|
81
|
+
await this.persist();
|
|
82
|
+
pending.push({ index, id, request });
|
|
63
83
|
}
|
|
64
84
|
else {
|
|
65
85
|
pending.push({ index, id, request });
|
|
@@ -88,57 +108,59 @@ export class AiBatch {
|
|
|
88
108
|
await this.saveChain;
|
|
89
109
|
return results;
|
|
90
110
|
}
|
|
91
|
-
/** Runs one unit,
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
111
|
+
/** Runs one unit, retrying a provider error and a response the validator
|
|
112
|
+
* rejects. It never throws: a provider error that outlives its retries drops
|
|
113
|
+
* the unit, and a response that still does not validate is used anyway. A run
|
|
114
|
+
* that has already paid for extraction must still write what it has; a format
|
|
115
|
+
* deviation is not worth losing the whole run over. */
|
|
95
116
|
async completeUnit(item, results, usage, startedAt) {
|
|
96
|
-
for (
|
|
117
|
+
for (let attempt = 1;; attempt++) {
|
|
118
|
+
let response;
|
|
97
119
|
try {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
120
|
+
response = await this.provider.complete(item.request);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
const reason = formatError(error);
|
|
124
|
+
const limit = isRateLimit(reason)
|
|
125
|
+
? MAX_RATE_LIMIT_ATTEMPTS
|
|
126
|
+
: MAX_ATTEMPTS;
|
|
127
|
+
console.log(`[ai] call failed ${attempt}/${limit} ${item.request.job} ${item.id.slice(0, 8)}: ${reason}`);
|
|
128
|
+
if (attempt < limit) {
|
|
129
|
+
const wait = retryDelayMs(reason, attempt);
|
|
130
|
+
if (wait > 0) {
|
|
131
|
+
console.log(`[ai] waiting ${Math.round(wait / 1000)}s before retry (provider is rate limiting)`);
|
|
132
|
+
await new Promise((resolve) => setTimeout(resolve, wait));
|
|
104
133
|
}
|
|
105
|
-
console.log(`[ai] retrying ${item.request.job} ${item.id.slice(0, 8)}: ${reason}`);
|
|
106
134
|
continue;
|
|
107
135
|
}
|
|
108
|
-
|
|
109
|
-
status: "done",
|
|
110
|
-
response,
|
|
111
|
-
updatedAt: new Date().toISOString(),
|
|
112
|
-
};
|
|
113
|
-
results[item.index] = response;
|
|
114
|
-
await this.persist();
|
|
115
|
-
if (usage)
|
|
116
|
-
await usage(item.request.job, response);
|
|
117
|
-
console.log(`[ai] ${attempt === 1 ? "done" : "retried"} ${item.request.job} ${item.id.slice(0, 8)} · ${Math.round((Date.now() - startedAt) / 1000)}s`);
|
|
136
|
+
console.log(`[ai] gave up ${item.request.job} ${item.id.slice(0, 8)} after ${attempt} attempts; continuing without it`);
|
|
118
137
|
return;
|
|
119
138
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
139
|
+
const reason = this.validate?.(item.request, response) ?? null;
|
|
140
|
+
if (reason !== null && attempt < MAX_ATTEMPTS) {
|
|
141
|
+
console.log(`[ai] output rejected ${attempt}/${MAX_ATTEMPTS} ${item.request.job} ${item.id.slice(0, 8)}: ${reason}`);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (reason !== null) {
|
|
145
|
+
// The last attempt still failed its contract. Do not cache it, so a
|
|
146
|
+
// later sync retries instead of replaying the same unusable output, and
|
|
147
|
+
// do not throw: the run keeps its other work.
|
|
148
|
+
console.log(`[ai] dropping ${item.request.job} ${item.id.slice(0, 8)} after ${attempt} attempts: ${reason}`);
|
|
128
149
|
return;
|
|
129
150
|
}
|
|
151
|
+
this.records[item.id] = {
|
|
152
|
+
status: "done",
|
|
153
|
+
response,
|
|
154
|
+
updatedAt: new Date().toISOString(),
|
|
155
|
+
};
|
|
156
|
+
results[item.index] = response;
|
|
157
|
+
await this.persist();
|
|
158
|
+
if (usage)
|
|
159
|
+
await usage(item.request.job, response);
|
|
160
|
+
console.log(`[ai] ${attempt === 1 ? "done" : `retried (${attempt})`} ${item.request.job} ${item.id.slice(0, 8)} · ${Math.round((Date.now() - startedAt) / 1000)}s`);
|
|
161
|
+
return;
|
|
130
162
|
}
|
|
131
163
|
}
|
|
132
|
-
/** Records a unit as skipped: no cache write, so it stays retried and its
|
|
133
|
-
* absence is never mistaken for a deliberate empty result. */
|
|
134
|
-
markSkipped(item, reason) {
|
|
135
|
-
this.skipped.push({
|
|
136
|
-
index: item.index,
|
|
137
|
-
job: item.request.job,
|
|
138
|
-
reason,
|
|
139
|
-
});
|
|
140
|
-
console.log(`[ai] skipped ${item.request.job} ${item.index}: ${reason}`);
|
|
141
|
-
}
|
|
142
164
|
async load() {
|
|
143
165
|
if (this.loaded)
|
|
144
166
|
return;
|
package/dist/src/cli/args.js
CHANGED
|
@@ -201,7 +201,7 @@ export async function parseArgs(args) {
|
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
else if (!explicitAi && !configuredAi && command !== "probe") {
|
|
204
|
-
const selected = await ask(`AI provider (${AI_PROVIDERS.join("|")})`, "openrouter");
|
|
204
|
+
const selected = await ask(`AI provider (${AI_PROVIDERS.filter((p) => p !== "none").join("|")})`, "openrouter");
|
|
205
205
|
rejectRetiredProvider(selected);
|
|
206
206
|
if (!AI_PROVIDERS.includes(selected)) {
|
|
207
207
|
die(`AI provider must be one of: ${AI_PROVIDERS.join(", ")}`);
|
|
@@ -264,7 +264,7 @@ export async function parseArgs(args) {
|
|
|
264
264
|
aiToken,
|
|
265
265
|
lowModel,
|
|
266
266
|
highModel,
|
|
267
|
-
synthesisVersion:
|
|
267
|
+
synthesisVersion: 17,
|
|
268
268
|
includeCodebase: enabled("include-codebase"),
|
|
269
269
|
includePullRequests: enabled("include-pull-requests"),
|
|
270
270
|
includePullRequestChanges: enabled("include-pull-request-changes"),
|
|
@@ -282,5 +282,6 @@ export async function parseArgs(args) {
|
|
|
282
282
|
configDefault.maxPullRequestChangeLines,
|
|
283
283
|
maxComments: value("max-comment") ?? repoConfig.maxComments,
|
|
284
284
|
reviewBlocking,
|
|
285
|
+
reviewSystemPrompt: repoConfig.reviewSystemPrompt,
|
|
285
286
|
};
|
|
286
287
|
}
|
|
@@ -30,6 +30,24 @@ const REVIEW_OUTPUT_FLAGS = {
|
|
|
30
30
|
},
|
|
31
31
|
],
|
|
32
32
|
};
|
|
33
|
+
const AI_KEY_FLAGS = [
|
|
34
|
+
{ name: "token", value: "KEY", description: "The provider API key." },
|
|
35
|
+
{
|
|
36
|
+
name: "ai-key",
|
|
37
|
+
value: "KEY",
|
|
38
|
+
description: "The same key as --token, named for what it is.",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "low-model",
|
|
42
|
+
value: "ID",
|
|
43
|
+
description: "Model for extraction work.",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "high-model",
|
|
47
|
+
value: "ID",
|
|
48
|
+
description: "Model for the review itself.",
|
|
49
|
+
},
|
|
50
|
+
];
|
|
33
51
|
const AI_FLAGS = {
|
|
34
52
|
title: "AI",
|
|
35
53
|
flags: [
|
|
@@ -37,24 +55,22 @@ const AI_FLAGS = {
|
|
|
37
55
|
name: "ai",
|
|
38
56
|
value: AI_PROVIDERS.join("|"),
|
|
39
57
|
default: "none",
|
|
40
|
-
description: "Which provider writes the review.",
|
|
41
|
-
},
|
|
42
|
-
{ name: "token", value: "KEY", description: "The provider API key." },
|
|
43
|
-
{
|
|
44
|
-
name: "ai-key",
|
|
45
|
-
value: "KEY",
|
|
46
|
-
description: "The same key as --token, named for what it is.",
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
name: "low-model",
|
|
50
|
-
value: "ID",
|
|
51
|
-
description: "Model for extraction work.",
|
|
58
|
+
description: "Which provider writes the review. `none` turns AI off.",
|
|
52
59
|
},
|
|
60
|
+
...AI_KEY_FLAGS,
|
|
61
|
+
],
|
|
62
|
+
};
|
|
63
|
+
/** `init` and `sync` author every guide with AI, so no provider is not a
|
|
64
|
+
* choice there. */
|
|
65
|
+
const AI_FLAGS_REQUIRED = {
|
|
66
|
+
title: "AI",
|
|
67
|
+
flags: [
|
|
53
68
|
{
|
|
54
|
-
name: "
|
|
55
|
-
value: "
|
|
56
|
-
description: "
|
|
69
|
+
name: "ai",
|
|
70
|
+
value: AI_PROVIDERS.filter((provider) => provider !== "none").join("|"),
|
|
71
|
+
description: "Which provider writes the guides. Required: init and sync cannot run without one.",
|
|
57
72
|
},
|
|
73
|
+
...AI_KEY_FLAGS,
|
|
58
74
|
],
|
|
59
75
|
};
|
|
60
76
|
const GITHUB_FLAGS = {
|
|
@@ -186,7 +202,7 @@ export const COMMANDS = [
|
|
|
186
202
|
},
|
|
187
203
|
],
|
|
188
204
|
},
|
|
189
|
-
|
|
205
|
+
AI_FLAGS_REQUIRED,
|
|
190
206
|
GITHUB_FLAGS,
|
|
191
207
|
OUTPUT_FLAGS,
|
|
192
208
|
{
|
|
@@ -273,7 +289,7 @@ export const COMMANDS = [
|
|
|
273
289
|
},
|
|
274
290
|
],
|
|
275
291
|
},
|
|
276
|
-
|
|
292
|
+
AI_FLAGS_REQUIRED,
|
|
277
293
|
GITHUB_FLAGS,
|
|
278
294
|
OUTPUT_FLAGS,
|
|
279
295
|
],
|
|
@@ -355,6 +371,21 @@ export const COMMANDS = [
|
|
|
355
371
|
},
|
|
356
372
|
],
|
|
357
373
|
},
|
|
374
|
+
{
|
|
375
|
+
title: "Custom instructions",
|
|
376
|
+
flags: [
|
|
377
|
+
{
|
|
378
|
+
name: "system-prompt-file",
|
|
379
|
+
value: "PATH",
|
|
380
|
+
description: "Append this file's contents to the review instructions for this run only.",
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
name: "system-prompt-override-file",
|
|
384
|
+
value: "PATH",
|
|
385
|
+
description: "Replace the repository's review instructions with this file for this run only. The built-in instructions are kept.",
|
|
386
|
+
},
|
|
387
|
+
],
|
|
388
|
+
},
|
|
358
389
|
AI_FLAGS,
|
|
359
390
|
GITHUB_FLAGS,
|
|
360
391
|
REVIEW_OUTPUT_FLAGS,
|
|
@@ -366,6 +397,8 @@ export const COMMANDS = [
|
|
|
366
397
|
"co-maintainer review --remote --remote-host=https://review.example.com --remote-token=cmr_...",
|
|
367
398
|
"co-maintainer review --remote --remote-byok --json",
|
|
368
399
|
"co-maintainer review --remote --output=github",
|
|
400
|
+
"co-maintainer review owner/repo 42 --system-prompt-file=extra.md",
|
|
401
|
+
"co-maintainer review --system-prompt-override-file=strict.md",
|
|
369
402
|
],
|
|
370
403
|
},
|
|
371
404
|
{
|
|
@@ -559,6 +592,21 @@ export const COMMANDS = [
|
|
|
559
592
|
value: "PATH",
|
|
560
593
|
description: "Read a custom review policy from a JSON file and use it as that default.",
|
|
561
594
|
},
|
|
595
|
+
{
|
|
596
|
+
name: "repo",
|
|
597
|
+
value: "owner/repo",
|
|
598
|
+
description: "Write the repository-scoped settings below to this repository instead of the global config.",
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
name: "review-system-prompt",
|
|
602
|
+
value: "TEXT",
|
|
603
|
+
description: "A repository's own review instructions. Needs --repo. Empty clears it.",
|
|
604
|
+
},
|
|
605
|
+
{
|
|
606
|
+
name: "review-system-prompt-max-chars",
|
|
607
|
+
value: "N",
|
|
608
|
+
description: "Cap the repository's review instructions in characters. Needs --repo. 0 or -1 means no limit.",
|
|
609
|
+
},
|
|
562
610
|
{
|
|
563
611
|
name: "review-blocking",
|
|
564
612
|
value: "model|severity",
|
|
@@ -595,6 +643,7 @@ export const COMMANDS = [
|
|
|
595
643
|
examples: [
|
|
596
644
|
"co-maintainer set --ai=openrouter --ai-key=... --low-model=... --high-model=...",
|
|
597
645
|
"co-maintainer set --remote-host=https://review.example.com --remote-token=...",
|
|
646
|
+
"co-maintainer set --repo=owner/repo --review-system-prompt='Focus on the parser.'",
|
|
598
647
|
"co-maintainer set --unset=token",
|
|
599
648
|
],
|
|
600
649
|
},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { readConfig, configPath, savedKeyProvider, writeUserConfig, } from "../../config.js";
|
|
1
|
+
import { readConfig, configPath, savedKeyProvider, writeRepoConfig, writeUserConfig, } from "../../config.js";
|
|
2
|
+
import { checkReviewSystemPrompt, reviewSystemPromptLimit, } from "../../review/system_prompt.js";
|
|
2
3
|
import { hashPassword, passwordProblem } from "../../util/password.js";
|
|
3
4
|
import { readTextFile } from "../../util/runtime.js";
|
|
4
5
|
import { verifyAnthropic, verifyOpenAi, verifyOpenRouter, } from "../../ai/verify.js";
|
|
@@ -60,6 +61,9 @@ export async function runSet(args) {
|
|
|
60
61
|
"review-policy",
|
|
61
62
|
"review-policy-file",
|
|
62
63
|
"review-blocking",
|
|
64
|
+
"repo",
|
|
65
|
+
"review-system-prompt",
|
|
66
|
+
"review-system-prompt-max-chars",
|
|
63
67
|
"password",
|
|
64
68
|
"unset",
|
|
65
69
|
];
|
|
@@ -72,6 +76,13 @@ export async function runSet(args) {
|
|
|
72
76
|
die(`Unknown option: ${arg}`);
|
|
73
77
|
}
|
|
74
78
|
}
|
|
79
|
+
// `--repo` turns `set` into a write to `repos[owner/repo]` in config.json.
|
|
80
|
+
// Only the repository-scoped settings are accepted alongside it.
|
|
81
|
+
const repoArg = text(args, "repo");
|
|
82
|
+
if (repoArg !== undefined) {
|
|
83
|
+
await runSetRepo(repoArg, args);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
75
86
|
const ai = text(args, "ai");
|
|
76
87
|
rejectRetiredProvider(ai);
|
|
77
88
|
if (ai && !AI_PROVIDERS.includes(ai)) {
|
|
@@ -299,3 +310,93 @@ export async function runSet(args) {
|
|
|
299
310
|
console.log(`[set] updated: ${summary.join(", ")}`);
|
|
300
311
|
console.log(`Saved to ${configPath()}`);
|
|
301
312
|
}
|
|
313
|
+
/** Flag names that make sense together with `--repo`. Anything else is a
|
|
314
|
+
* global setting and is refused rather than silently written to the wrong
|
|
315
|
+
* place. */
|
|
316
|
+
const REPO_SCOPED_FLAGS = new Set([
|
|
317
|
+
"repo",
|
|
318
|
+
"review-system-prompt",
|
|
319
|
+
"review-system-prompt-max-chars",
|
|
320
|
+
"unset",
|
|
321
|
+
"no-verify",
|
|
322
|
+
]);
|
|
323
|
+
/** The `--unset=name` values that address a repository-scoped field. */
|
|
324
|
+
const REPO_SCOPED_UNSET = new Set([
|
|
325
|
+
"review-system-prompt",
|
|
326
|
+
"reviewSystemPrompt",
|
|
327
|
+
"review-system-prompt-max-chars",
|
|
328
|
+
"reviewSystemPromptMaxChars",
|
|
329
|
+
]);
|
|
330
|
+
/** `set --repo=owner/repo [--review-system-prompt=... | --review-system-prompt-max-chars=N | --unset=name]`
|
|
331
|
+
* writes the repository-scoped settings to `repos[owner/repo]` in config.json
|
|
332
|
+
* instead of the global config. */
|
|
333
|
+
async function runSetRepo(repo, args) {
|
|
334
|
+
if (!/^[^/]+\/[^/]+$/.test(repo))
|
|
335
|
+
die("--repo must look like owner/repo");
|
|
336
|
+
for (const arg of args) {
|
|
337
|
+
if (!arg.startsWith("--"))
|
|
338
|
+
continue;
|
|
339
|
+
const name = arg.slice(2).split("=")[0];
|
|
340
|
+
if (!REPO_SCOPED_FLAGS.has(name)) {
|
|
341
|
+
die(`--${name} cannot be used with --repo`);
|
|
342
|
+
}
|
|
343
|
+
if (name === "unset") {
|
|
344
|
+
const value = arg.slice("--unset=".length);
|
|
345
|
+
if (!REPO_SCOPED_UNSET.has(value)) {
|
|
346
|
+
die(`--unset=${value} cannot be used with --repo`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
const unset = new Set(args
|
|
351
|
+
.filter((arg) => arg.startsWith("--unset="))
|
|
352
|
+
.map((arg) => arg.slice("--unset=".length)));
|
|
353
|
+
const existing = readConfig().repos?.[repo] ?? {};
|
|
354
|
+
const patch = {};
|
|
355
|
+
// Unset first, then explicit values win, so `--unset=x --x=...` sets.
|
|
356
|
+
if (unset.has("review-system-prompt") || unset.has("reviewSystemPrompt")) {
|
|
357
|
+
patch.reviewSystemPrompt = undefined;
|
|
358
|
+
}
|
|
359
|
+
if (unset.has("review-system-prompt-max-chars") ||
|
|
360
|
+
unset.has("reviewSystemPromptMaxChars")) {
|
|
361
|
+
patch.reviewSystemPromptMaxChars = undefined;
|
|
362
|
+
}
|
|
363
|
+
const maxRaw = text(args, "review-system-prompt-max-chars");
|
|
364
|
+
if (maxRaw !== undefined) {
|
|
365
|
+
// Blank clears it, the same as an empty value on the dashboard form.
|
|
366
|
+
if (maxRaw.trim() === "") {
|
|
367
|
+
patch.reviewSystemPromptMaxChars = undefined;
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
const value = Number(maxRaw);
|
|
371
|
+
if (!Number.isInteger(value)) {
|
|
372
|
+
die("--review-system-prompt-max-chars must be an integer (0 or -1 for no limit)");
|
|
373
|
+
}
|
|
374
|
+
patch.reviewSystemPromptMaxChars = value;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
const prompt = text(args, "review-system-prompt");
|
|
378
|
+
if (prompt !== undefined) {
|
|
379
|
+
patch.reviewSystemPrompt = prompt.trim() === "" ? undefined : prompt;
|
|
380
|
+
}
|
|
381
|
+
if (Object.keys(patch).length === 0) {
|
|
382
|
+
die("Nothing to set. Pass --review-system-prompt=, --review-system-prompt-max-chars=N, or --unset=name with --repo.");
|
|
383
|
+
}
|
|
384
|
+
// The values after this write are the ones given here, or the stored ones.
|
|
385
|
+
// Lowering the cap re-checks the stored prompt too, so it cannot end up over
|
|
386
|
+
// the cap it is measured against.
|
|
387
|
+
const effectiveMax = "reviewSystemPromptMaxChars" in patch
|
|
388
|
+
? patch.reviewSystemPromptMaxChars
|
|
389
|
+
: existing.reviewSystemPromptMaxChars;
|
|
390
|
+
const effectivePrompt = "reviewSystemPrompt" in patch
|
|
391
|
+
? patch.reviewSystemPrompt
|
|
392
|
+
: existing.reviewSystemPrompt;
|
|
393
|
+
if (effectivePrompt !== undefined) {
|
|
394
|
+
const problem = checkReviewSystemPrompt(effectivePrompt, reviewSystemPromptLimit({ reviewSystemPromptMaxChars: effectiveMax }));
|
|
395
|
+
if (problem)
|
|
396
|
+
die(`--review-system-prompt: ${problem}`);
|
|
397
|
+
}
|
|
398
|
+
await writeRepoConfig(repo, patch);
|
|
399
|
+
const summary = Object.entries(patch).map(([key, value]) => value === undefined ? `${key} (unset)` : `${key}=${value}`);
|
|
400
|
+
console.log(`[set] updated ${repo}: ${summary.join(", ")}`);
|
|
401
|
+
console.log(`Saved to ${configPath()}`);
|
|
402
|
+
}
|
|
@@ -20,6 +20,12 @@ type ReviewFlags = {
|
|
|
20
20
|
/** `--output=github`: workflow commands and a job summary instead of prose.
|
|
21
21
|
*/
|
|
22
22
|
output?: "github";
|
|
23
|
+
/** `--system-prompt-file`: a file whose contents are appended to the
|
|
24
|
+
* custom review section for this run only. */
|
|
25
|
+
systemPromptFile?: string;
|
|
26
|
+
/** `--system-prompt-override-file`: a file whose contents replace the
|
|
27
|
+
* repository's custom review section for this run only. */
|
|
28
|
+
systemPromptOverrideFile?: string;
|
|
23
29
|
};
|
|
24
30
|
export type ReviewCliArgs = ({
|
|
25
31
|
mode: "pr";
|
|
@@ -33,6 +39,15 @@ export type ReviewCliArgs = ({
|
|
|
33
39
|
} & ReviewFlags);
|
|
34
40
|
/** Strip local-only flags before `parseArgs` for PR-style options. */
|
|
35
41
|
export declare function filterReviewConfigArgs(raw: string[]): string[];
|
|
42
|
+
/** The repository's custom-prompt cap, read from config.json. */
|
|
43
|
+
export declare function reviewSystemPromptLimitFor(repo: string): number | null;
|
|
44
|
+
/** Reads the per-run system-prompt files and checks each against the
|
|
45
|
+
* repository's cap. `die`s naming the flag when a file cannot be read or is
|
|
46
|
+
* over the cap. */
|
|
47
|
+
export declare function loadReviewSystemPromptFlags(cli: Pick<ReviewFlags, "systemPromptFile" | "systemPromptOverrideFile">, limit: number | null): Promise<{
|
|
48
|
+
add?: string;
|
|
49
|
+
override?: string;
|
|
50
|
+
}>;
|
|
36
51
|
/** Parses `co-maintainer review` after the `review` token. */
|
|
37
52
|
export declare function parseReviewArgs(args: string[]): Promise<ReviewCliArgs>;
|
|
38
53
|
export {};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { parseArgs, setCliInteractive } from "./args.js";
|
|
2
2
|
import { die } from "./error.js";
|
|
3
|
+
import { readConfig } from "../config.js";
|
|
4
|
+
import { readTextFile } from "../util/runtime.js";
|
|
5
|
+
import { checkReviewSystemPrompt, reviewSystemPromptLimit, } from "../review/system_prompt.js";
|
|
3
6
|
function reviewFlags(rest) {
|
|
4
7
|
const text = (name) => rest.find((item) => item.startsWith(`--${name}=`))?.slice(name.length + 3);
|
|
5
8
|
// `--remake-before-review` is the 0.4.13 spelling; both names mean the same
|
|
@@ -39,6 +42,8 @@ function reviewFlags(rest) {
|
|
|
39
42
|
remoteToken: text("remote-token"),
|
|
40
43
|
remoteByok: remoteByokOn ? true : remoteByokOff ? false : undefined,
|
|
41
44
|
output,
|
|
45
|
+
systemPromptFile: text("system-prompt-file"),
|
|
46
|
+
systemPromptOverrideFile: text("system-prompt-override-file"),
|
|
42
47
|
};
|
|
43
48
|
}
|
|
44
49
|
const LOCAL_ONLY_FLAGS = new Set([
|
|
@@ -62,12 +67,44 @@ export function filterReviewConfigArgs(raw) {
|
|
|
62
67
|
arg.startsWith("--repo=") ||
|
|
63
68
|
arg.startsWith("--remote-host=") ||
|
|
64
69
|
arg.startsWith("--remote-token=") ||
|
|
65
|
-
arg.startsWith("--output=")
|
|
70
|
+
arg.startsWith("--output=") ||
|
|
71
|
+
arg.startsWith("--system-prompt-file=") ||
|
|
72
|
+
arg.startsWith("--system-prompt-override-file=")) {
|
|
66
73
|
return false;
|
|
67
74
|
}
|
|
68
75
|
return true;
|
|
69
76
|
});
|
|
70
77
|
}
|
|
78
|
+
/** The repository's custom-prompt cap, read from config.json. */
|
|
79
|
+
export function reviewSystemPromptLimitFor(repo) {
|
|
80
|
+
return reviewSystemPromptLimit(readConfig().repos?.[repo]);
|
|
81
|
+
}
|
|
82
|
+
/** Reads the per-run system-prompt files and checks each against the
|
|
83
|
+
* repository's cap. `die`s naming the flag when a file cannot be read or is
|
|
84
|
+
* over the cap. */
|
|
85
|
+
export async function loadReviewSystemPromptFlags(cli, limit) {
|
|
86
|
+
const load = async (flag, path) => {
|
|
87
|
+
let text;
|
|
88
|
+
try {
|
|
89
|
+
text = await readTextFile(path);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
die(`${flag}: could not read ${path}: ${String(error)}`);
|
|
93
|
+
}
|
|
94
|
+
const problem = checkReviewSystemPrompt(text, limit);
|
|
95
|
+
if (problem)
|
|
96
|
+
die(`${flag}: ${problem}`);
|
|
97
|
+
return text;
|
|
98
|
+
};
|
|
99
|
+
const result = {};
|
|
100
|
+
if (cli.systemPromptFile) {
|
|
101
|
+
result.add = await load("--system-prompt-file", cli.systemPromptFile);
|
|
102
|
+
}
|
|
103
|
+
if (cli.systemPromptOverrideFile) {
|
|
104
|
+
result.override = await load("--system-prompt-override-file", cli.systemPromptOverrideFile);
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
71
108
|
/** Parses `co-maintainer review` after the `review` token. */
|
|
72
109
|
export async function parseReviewArgs(args) {
|
|
73
110
|
const positional = args.filter((a) => !a.startsWith("--"));
|
|
@@ -105,11 +142,14 @@ export async function parseReviewArgs(args) {
|
|
|
105
142
|
if (flags.remakeBeforeReview) {
|
|
106
143
|
die("--sync-before-review is not supported for PR review");
|
|
107
144
|
}
|
|
145
|
+
const promptFlags = await loadReviewSystemPromptFlags(flags, reviewSystemPromptLimitFor(options.repo));
|
|
108
146
|
return {
|
|
109
147
|
mode: "pr",
|
|
110
148
|
options: {
|
|
111
149
|
...options,
|
|
112
150
|
useCodegraph: flags.disableCodegraph ? false : true,
|
|
151
|
+
reviewSystemPromptAdd: promptFlags.add,
|
|
152
|
+
reviewSystemPromptOverride: promptFlags.override,
|
|
113
153
|
},
|
|
114
154
|
...flags,
|
|
115
155
|
};
|
package/dist/src/config.d.ts
CHANGED
|
@@ -21,6 +21,13 @@ export type RepoConfig = {
|
|
|
21
21
|
prState?: ("open" | "closed" | "merged")[];
|
|
22
22
|
/** Five field cron in UTC, checked by `serve` to queue a remake. */
|
|
23
23
|
remakeCron?: string;
|
|
24
|
+
/** A repository's own review instructions, appended to the built-in
|
|
25
|
+
* reviewer prompt as a `CUSTOM REVIEW INSTRUCTIONS` section. Unset or blank
|
|
26
|
+
* means none. */
|
|
27
|
+
reviewSystemPrompt?: string;
|
|
28
|
+
/** Cap on `reviewSystemPrompt` in characters for this repository. Unset
|
|
29
|
+
* means the default; `0` or a negative number means no limit. */
|
|
30
|
+
reviewSystemPromptMaxChars?: number;
|
|
24
31
|
};
|
|
25
32
|
export type UserConfig = {
|
|
26
33
|
auth?: "gh" | "pat";
|