co-maintainer 0.5.3 → 0.5.4
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/cli/args.js +1 -0
- package/dist/src/cli/commands/registry.js +33 -0
- 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/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 +30 -1
- package/dist/src/services/review.js +1 -0
- 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/cli/args.js
CHANGED
|
@@ -355,6 +355,21 @@ export const COMMANDS = [
|
|
|
355
355
|
},
|
|
356
356
|
],
|
|
357
357
|
},
|
|
358
|
+
{
|
|
359
|
+
title: "Custom instructions",
|
|
360
|
+
flags: [
|
|
361
|
+
{
|
|
362
|
+
name: "system-prompt-file",
|
|
363
|
+
value: "PATH",
|
|
364
|
+
description: "Append this file's contents to the review instructions for this run only.",
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
name: "system-prompt-override-file",
|
|
368
|
+
value: "PATH",
|
|
369
|
+
description: "Replace the repository's review instructions with this file for this run only. The built-in instructions are kept.",
|
|
370
|
+
},
|
|
371
|
+
],
|
|
372
|
+
},
|
|
358
373
|
AI_FLAGS,
|
|
359
374
|
GITHUB_FLAGS,
|
|
360
375
|
REVIEW_OUTPUT_FLAGS,
|
|
@@ -366,6 +381,8 @@ export const COMMANDS = [
|
|
|
366
381
|
"co-maintainer review --remote --remote-host=https://review.example.com --remote-token=cmr_...",
|
|
367
382
|
"co-maintainer review --remote --remote-byok --json",
|
|
368
383
|
"co-maintainer review --remote --output=github",
|
|
384
|
+
"co-maintainer review owner/repo 42 --system-prompt-file=extra.md",
|
|
385
|
+
"co-maintainer review --system-prompt-override-file=strict.md",
|
|
369
386
|
],
|
|
370
387
|
},
|
|
371
388
|
{
|
|
@@ -559,6 +576,21 @@ export const COMMANDS = [
|
|
|
559
576
|
value: "PATH",
|
|
560
577
|
description: "Read a custom review policy from a JSON file and use it as that default.",
|
|
561
578
|
},
|
|
579
|
+
{
|
|
580
|
+
name: "repo",
|
|
581
|
+
value: "owner/repo",
|
|
582
|
+
description: "Write the repository-scoped settings below to this repository instead of the global config.",
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
name: "review-system-prompt",
|
|
586
|
+
value: "TEXT",
|
|
587
|
+
description: "A repository's own review instructions. Needs --repo. Empty clears it.",
|
|
588
|
+
},
|
|
589
|
+
{
|
|
590
|
+
name: "review-system-prompt-max-chars",
|
|
591
|
+
value: "N",
|
|
592
|
+
description: "Cap the repository's review instructions in characters. Needs --repo. 0 or -1 means no limit.",
|
|
593
|
+
},
|
|
562
594
|
{
|
|
563
595
|
name: "review-blocking",
|
|
564
596
|
value: "model|severity",
|
|
@@ -595,6 +627,7 @@ export const COMMANDS = [
|
|
|
595
627
|
examples: [
|
|
596
628
|
"co-maintainer set --ai=openrouter --ai-key=... --low-model=... --high-model=...",
|
|
597
629
|
"co-maintainer set --remote-host=https://review.example.com --remote-token=...",
|
|
630
|
+
"co-maintainer set --repo=owner/repo --review-system-prompt='Focus on the parser.'",
|
|
598
631
|
"co-maintainer set --unset=token",
|
|
599
632
|
],
|
|
600
633
|
},
|
|
@@ -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";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseArgs } from "../cli/args.js";
|
|
2
|
-
import { filterReviewConfigArgs, } from "../cli/review_args.js";
|
|
2
|
+
import { filterReviewConfigArgs, loadReviewSystemPromptFlags, reviewSystemPromptLimitFor, } from "../cli/review_args.js";
|
|
3
3
|
import { buildLocalReviewJson, formatHumanLocalReview, humanFindingsFromResolved, resolvedFromFirstReview, reviewExitCodeFromResolved, } from "../cli/review_result.js";
|
|
4
4
|
import { addAiMetrics, emptyAiMetrics, recordAiCost, runInitOrRemake, } from "../services/setup.js";
|
|
5
5
|
import { aiFor } from "../services/review.js";
|
|
@@ -107,6 +107,9 @@ export async function runLocalReview(cli) {
|
|
|
107
107
|
...filterReviewConfigArgs(cli.rawArgs),
|
|
108
108
|
]);
|
|
109
109
|
options.useCodegraph = cli.disableCodegraph ? false : true;
|
|
110
|
+
const promptFlags = await loadReviewSystemPromptFlags(cli, reviewSystemPromptLimitFor(repo));
|
|
111
|
+
options.reviewSystemPromptAdd = promptFlags.add;
|
|
112
|
+
options.reviewSystemPromptOverride = promptFlags.override;
|
|
110
113
|
const guides = await loadGuides(repo);
|
|
111
114
|
if (!guides.shortGuide && !guides.skill) {
|
|
112
115
|
throw new ReviewCliError("not_initialized", `Review guides are missing for ${repo}.`, `co-maintainer init ${repo}`);
|
package/dist/src/pr/reviewer.js
CHANGED
|
@@ -5,6 +5,7 @@ import { loadGuides } from "../review/guides.js";
|
|
|
5
5
|
import { computeScope } from "./scope.js";
|
|
6
6
|
import { prepareCodegraphTools } from "./codegraph_tools.js";
|
|
7
7
|
import { REVIEW_COPY_RULE, severitySection } from "./review_copy.js";
|
|
8
|
+
import { reviewSystemPromptBlock } from "../review/system_prompt.js";
|
|
8
9
|
import { needsSummary, READ_FULL_DIFF_TOOL, readFullDiff, summarizeDiff, } from "./diff_summary.js";
|
|
9
10
|
import { numberPatch } from "./hunks.js";
|
|
10
11
|
import { FINDINGS_JSON_INSTRUCTIONS, FINDINGS_JSON_SCHEMA, findingsMarkdownFromJson, } from "./findings_json.js";
|
|
@@ -370,7 +371,7 @@ ${diff}`;
|
|
|
370
371
|
const matrix = clampImproveMatrix(options.improveMatrix);
|
|
371
372
|
const request = {
|
|
372
373
|
job: "review_pull_request",
|
|
373
|
-
system: `${reviewSystemPrompt(diagrams)}\n\n${reviewGuidesBlock(guide, detailed, codebase)}`,
|
|
374
|
+
system: `${reviewSystemPrompt(diagrams)}\n\n${reviewGuidesBlock(guide, detailed, codebase)}${reviewSystemPromptBlock(options)}`,
|
|
374
375
|
prompt,
|
|
375
376
|
maxTokens: 24_000 * matrix,
|
|
376
377
|
reasoningEffort: "high",
|
|
@@ -534,7 +535,7 @@ ${ownDiff}${unchangedListing}`;
|
|
|
534
535
|
const matrix = clampImproveMatrix(options.improveMatrix);
|
|
535
536
|
const request = {
|
|
536
537
|
job: "review_local",
|
|
537
|
-
system: `${reviewSystemPrompt(diagrams)}\n\n${reviewGuidesBlock(guide, detailed, codebase)}`,
|
|
538
|
+
system: `${reviewSystemPrompt(diagrams)}\n\n${reviewGuidesBlock(guide, detailed, codebase)}${reviewSystemPromptBlock(options)}`,
|
|
538
539
|
prompt,
|
|
539
540
|
maxTokens: 24_000 * matrix,
|
|
540
541
|
reasoningEffort: "high",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { VERSION } from "../version.js";
|
|
2
|
-
import {
|
|
2
|
+
import { loadReviewSystemPromptFlags } from "../cli/review_args.js";
|
|
3
|
+
import { exitWith } from "../cli/error.js";
|
|
3
4
|
import { formatHumanReview, humanFindingsFromJson, reviewExitCodeFromJsonFindings, } from "../cli/review_result.js";
|
|
4
5
|
import { baseUrl, die, readApiError, remoteFetch, remoteFromEnv, } from "./http.js";
|
|
5
6
|
import { readConfig, writeUserConfig } from "../config.js";
|
|
@@ -140,6 +141,10 @@ export async function runRemoteReview(cli) {
|
|
|
140
141
|
.filter((name) => REMOTE_KNOWN_TOOL_NAMES.has(name))
|
|
141
142
|
.map((name) => ({ name }));
|
|
142
143
|
const requestId = crypto.randomUUID();
|
|
144
|
+
// The review runs on the server, so the server's per-repo cap decides. The
|
|
145
|
+
// client only reads the files and sends them, and the server rejects an
|
|
146
|
+
// over-cap value with a 400.
|
|
147
|
+
const promptFlags = await loadReviewSystemPromptFlags(cli, null);
|
|
143
148
|
const submitBody = {
|
|
144
149
|
schemaVersion: REMOTE_SCHEMA_VERSION,
|
|
145
150
|
requestId,
|
|
@@ -157,6 +162,14 @@ export async function runRemoteReview(cli) {
|
|
|
157
162
|
// Only present when this run turned BYOK on; `byokKey` is
|
|
158
163
|
// known to be set here because of the earlier `byokEnabled` guard.
|
|
159
164
|
...(byokEnabled ? { byok: { key: byokKey } } : {}),
|
|
165
|
+
// The client's one-run instructions, when given. The server applies
|
|
166
|
+
// them on top of its own per-repo prompt.
|
|
167
|
+
...(promptFlags.add !== undefined
|
|
168
|
+
? { systemPromptAdd: promptFlags.add }
|
|
169
|
+
: {}),
|
|
170
|
+
...(promptFlags.override !== undefined
|
|
171
|
+
? { systemPromptOverride: promptFlags.override }
|
|
172
|
+
: {}),
|
|
160
173
|
};
|
|
161
174
|
const serialized = JSON.stringify(submitBody);
|
|
162
175
|
if (serialized.length > hs.limits.maxBodyBytes) {
|
|
@@ -6,6 +6,9 @@ export declare const MIN_SERVER_SCHEMA = 1;
|
|
|
6
6
|
export declare const REMOTE_CLI_UPGRADE_COMMAND = "npm install -g co-maintainer@latest";
|
|
7
7
|
export declare const REMOTE_MAX_BODY_BYTES = 52428800;
|
|
8
8
|
export declare const REMOTE_SYNC_INTERVAL_SECONDS = 3;
|
|
9
|
+
/** Absolute ceiling on a client's one-run review instructions, before the
|
|
10
|
+
* repository's own cap is applied on the server. Guards the body size. */
|
|
11
|
+
export declare const REMOTE_MAX_SYSTEM_PROMPT_CHARS = 200000;
|
|
9
12
|
/** SHA-256 of sorted `fixtures/v<N>/*.json` (name + contents, `\r\n` normalized
|
|
10
13
|
* to `\n`); bump with schema version. */
|
|
11
14
|
export declare const REMOTE_FIXTURE_HASH: Record<number, string>;
|
|
@@ -6,6 +6,9 @@ export const MIN_SERVER_SCHEMA = 1;
|
|
|
6
6
|
export const REMOTE_CLI_UPGRADE_COMMAND = "npm install -g co-maintainer@latest";
|
|
7
7
|
export const REMOTE_MAX_BODY_BYTES = 52_428_800;
|
|
8
8
|
export const REMOTE_SYNC_INTERVAL_SECONDS = 3;
|
|
9
|
+
/** Absolute ceiling on a client's one-run review instructions, before the
|
|
10
|
+
* repository's own cap is applied on the server. Guards the body size. */
|
|
11
|
+
export const REMOTE_MAX_SYSTEM_PROMPT_CHARS = 200_000;
|
|
9
12
|
/** SHA-256 of sorted `fixtures/v<N>/*.json` (name + contents, `\r\n` normalized
|
|
10
13
|
* to `\n`); bump with schema version. */
|
|
11
14
|
export const REMOTE_FIXTURE_HASH = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { rejectEscapingPath } from "../pr/codegraph_tool_args.js";
|
|
2
|
-
import { MIN_CLIENT_SCHEMA, REMOTE_KNOWN_TOOL_NAMES, REMOTE_SCHEMA_VERSION, REMOTE_SYNC_STATUSES, } from "./schema.js";
|
|
2
|
+
import { MIN_CLIENT_SCHEMA, REMOTE_KNOWN_TOOL_NAMES, REMOTE_MAX_SYSTEM_PROMPT_CHARS, REMOTE_SCHEMA_VERSION, REMOTE_SYNC_STATUSES, } from "./schema.js";
|
|
3
3
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
4
4
|
const REVISION_STATUSES = new Set([
|
|
5
5
|
"added",
|
|
@@ -188,6 +188,17 @@ export function validateSubmitRequest(body) {
|
|
|
188
188
|
const revisionErr = validateRevisionPayload(body.revision);
|
|
189
189
|
if (revisionErr)
|
|
190
190
|
return revisionErr;
|
|
191
|
+
for (const field of ["systemPromptAdd", "systemPromptOverride"]) {
|
|
192
|
+
const value = body[field];
|
|
193
|
+
if (value === undefined)
|
|
194
|
+
continue;
|
|
195
|
+
if (typeof value !== "string") {
|
|
196
|
+
return bad(field, "must be a string");
|
|
197
|
+
}
|
|
198
|
+
if (value.length > REMOTE_MAX_SYSTEM_PROMPT_CHARS) {
|
|
199
|
+
return bad(field, "too long");
|
|
200
|
+
}
|
|
201
|
+
}
|
|
191
202
|
if (body.capabilities !== undefined) {
|
|
192
203
|
if (!isRecord(body.capabilities)) {
|
|
193
204
|
return bad("capabilities", "must be an object");
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** The per-repository custom review instructions and the cap on them. The
|
|
2
|
+
* block is appended to the built-in reviewer system prompt (role, diagram
|
|
3
|
+
* rules and guide) as a separate section, so the built-in instructions are
|
|
4
|
+
* always kept. */
|
|
5
|
+
import type { Options } from "../types.ts";
|
|
6
|
+
import type { RepoConfig } from "../config.ts";
|
|
7
|
+
/** Default cap on `reviewSystemPrompt`, in characters. */
|
|
8
|
+
export declare const DEFAULT_REVIEW_SYSTEM_PROMPT_MAX_CHARS = 8000;
|
|
9
|
+
/** The repository's cap, or `null` for no limit. Unset takes the default; a
|
|
10
|
+
* non-positive value means unlimited. */
|
|
11
|
+
export declare function reviewSystemPromptLimit(repoConfig: Pick<RepoConfig, "reviewSystemPromptMaxChars"> | undefined): number | null;
|
|
12
|
+
/** The problem with a custom prompt, or `null` when it is fine. Blank text is
|
|
13
|
+
* allowed and means "off". */
|
|
14
|
+
export declare function checkReviewSystemPrompt(text: string, limit: number | null): string | null;
|
|
15
|
+
/** The extra system-prompt section for a review, or `""` when none applies.
|
|
16
|
+
* A per-run override replaces the repository's own section, and a per-run add
|
|
17
|
+
* is appended after it. A blank per-run value counts as absent, so an empty
|
|
18
|
+
* override file keeps the repository's own section rather than dropping it. */
|
|
19
|
+
export declare function reviewSystemPromptBlock(options: Pick<Options, "reviewSystemPrompt" | "reviewSystemPromptAdd" | "reviewSystemPromptOverride">): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Default cap on `reviewSystemPrompt`, in characters. */
|
|
2
|
+
export const DEFAULT_REVIEW_SYSTEM_PROMPT_MAX_CHARS = 8000;
|
|
3
|
+
/** The repository's cap, or `null` for no limit. Unset takes the default; a
|
|
4
|
+
* non-positive value means unlimited. */
|
|
5
|
+
export function reviewSystemPromptLimit(repoConfig) {
|
|
6
|
+
const raw = repoConfig?.reviewSystemPromptMaxChars;
|
|
7
|
+
if (raw === undefined)
|
|
8
|
+
return DEFAULT_REVIEW_SYSTEM_PROMPT_MAX_CHARS;
|
|
9
|
+
if (!Number.isFinite(raw) || raw <= 0)
|
|
10
|
+
return null;
|
|
11
|
+
const floored = Math.floor(raw);
|
|
12
|
+
return floored > 0 ? floored : null;
|
|
13
|
+
}
|
|
14
|
+
/** The problem with a custom prompt, or `null` when it is fine. Blank text is
|
|
15
|
+
* allowed and means "off". */
|
|
16
|
+
export function checkReviewSystemPrompt(text, limit) {
|
|
17
|
+
if (limit !== null && text.length > limit) {
|
|
18
|
+
return `must be at most ${limit} characters (got ${text.length})`;
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
/** The extra system-prompt section for a review, or `""` when none applies.
|
|
23
|
+
* A per-run override replaces the repository's own section, and a per-run add
|
|
24
|
+
* is appended after it. A blank per-run value counts as absent, so an empty
|
|
25
|
+
* override file keeps the repository's own section rather than dropping it. */
|
|
26
|
+
export function reviewSystemPromptBlock(options) {
|
|
27
|
+
const override = options.reviewSystemPromptOverride?.trim();
|
|
28
|
+
const base = override ? override : options.reviewSystemPrompt?.trim();
|
|
29
|
+
const add = options.reviewSystemPromptAdd?.trim();
|
|
30
|
+
const parts = [base, add].filter((part) => Boolean(part));
|
|
31
|
+
if (parts.length === 0)
|
|
32
|
+
return "";
|
|
33
|
+
return `\n\nCUSTOM REVIEW INSTRUCTIONS:\n${parts.join("\n\n")}`;
|
|
34
|
+
}
|
|
@@ -2,6 +2,7 @@ import { errorResponse } from "../errors.js";
|
|
|
2
2
|
import { AppClient, findInstallationForRepo } from "../../github/app.js";
|
|
3
3
|
import { activateRepo, deactivateRepo, getRepo, listActiveRepos, updateRepoSettings, } from "../../store/repos.js";
|
|
4
4
|
import { readConfig, writeRepoConfig } from "../../config.js";
|
|
5
|
+
import { checkReviewSystemPrompt, reviewSystemPromptLimit, } from "../../review/system_prompt.js";
|
|
5
6
|
import { parseRemakeCron } from "../../services/remake_cron.js";
|
|
6
7
|
import { parsePolicy, policyToStore, describePolicy, } from "../../services/review_policy.js";
|
|
7
8
|
import { enqueueSetup } from "../../services/setup.js";
|
|
@@ -198,6 +199,53 @@ export async function handleReposRoute(request, url, githubApp) {
|
|
|
198
199
|
}
|
|
199
200
|
}
|
|
200
201
|
const patch = {};
|
|
202
|
+
// The repository's own review instructions live in config.json, not the
|
|
203
|
+
// database, so they go through writeRepoConfig below.
|
|
204
|
+
const promptPatch = {};
|
|
205
|
+
if ("reviewSystemPromptMaxChars" in body) {
|
|
206
|
+
const raw = body.reviewSystemPromptMaxChars;
|
|
207
|
+
if (raw === null || raw === "") {
|
|
208
|
+
promptPatch.reviewSystemPromptMaxChars = undefined;
|
|
209
|
+
}
|
|
210
|
+
else if (typeof raw === "number" && Number.isInteger(raw)) {
|
|
211
|
+
promptPatch.reviewSystemPromptMaxChars = raw;
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
return errorResponse(422, "invalid_review_system_prompt_limit", "reviewSystemPromptMaxChars must be an integer (0 or -1 for no limit) or null");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if ("reviewSystemPrompt" in body) {
|
|
218
|
+
const raw = body.reviewSystemPrompt;
|
|
219
|
+
if (raw === null || raw === "") {
|
|
220
|
+
promptPatch.reviewSystemPrompt = undefined;
|
|
221
|
+
}
|
|
222
|
+
else if (typeof raw === "string") {
|
|
223
|
+
promptPatch.reviewSystemPrompt = raw.trim() === "" ? undefined : raw;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
return errorResponse(422, "invalid_review_system_prompt", "reviewSystemPrompt must be text or null");
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// The prompt after this write is the one given here, or the stored one.
|
|
230
|
+
// Lowering the cap re-checks the stored prompt too.
|
|
231
|
+
if ("reviewSystemPrompt" in promptPatch ||
|
|
232
|
+
"reviewSystemPromptMaxChars" in promptPatch) {
|
|
233
|
+
const existing = readConfig().repos?.[fullName] ?? {};
|
|
234
|
+
const effectiveMax = "reviewSystemPromptMaxChars" in promptPatch
|
|
235
|
+
? promptPatch.reviewSystemPromptMaxChars
|
|
236
|
+
: existing.reviewSystemPromptMaxChars;
|
|
237
|
+
const effectivePrompt = "reviewSystemPrompt" in promptPatch
|
|
238
|
+
? promptPatch.reviewSystemPrompt
|
|
239
|
+
: existing.reviewSystemPrompt;
|
|
240
|
+
if (effectivePrompt !== undefined) {
|
|
241
|
+
const problem = checkReviewSystemPrompt(effectivePrompt, reviewSystemPromptLimit({
|
|
242
|
+
reviewSystemPromptMaxChars: effectiveMax,
|
|
243
|
+
}));
|
|
244
|
+
if (problem) {
|
|
245
|
+
return errorResponse(422, "invalid_review_system_prompt", `reviewSystemPrompt ${problem}`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
201
249
|
if ("reviewPolicy" in body) {
|
|
202
250
|
const stored = policyToStore(body.reviewPolicy, { allowLegacy: true });
|
|
203
251
|
if (!stored.ok) {
|
|
@@ -248,8 +296,14 @@ export async function handleReposRoute(request, url, githubApp) {
|
|
|
248
296
|
init[key] = body[key];
|
|
249
297
|
}
|
|
250
298
|
}
|
|
251
|
-
if (Object.keys(init).length > 0 ||
|
|
252
|
-
|
|
299
|
+
if (Object.keys(init).length > 0 ||
|
|
300
|
+
"remakeCron" in cronPatch ||
|
|
301
|
+
Object.keys(promptPatch).length > 0) {
|
|
302
|
+
await writeRepoConfig(fullName, {
|
|
303
|
+
...init,
|
|
304
|
+
...cronPatch,
|
|
305
|
+
...promptPatch,
|
|
306
|
+
});
|
|
253
307
|
}
|
|
254
308
|
return Response.json({ ok: true });
|
|
255
309
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Generated from src/server/pages/client.js by scripts/embed_assets.mjs — do not edit. */
|
|
2
|
-
export declare const client = "function toast(message) {\n const host = document.getElementById(\"toasts\");\n if (!host) return;\n const el = document.createElement(\"div\");\n el.className = \"toast\";\n el.setAttribute(\"role\", \"status\");\n el.textContent = message;\n host.appendChild(el);\n setTimeout(function () {\n el.remove();\n }, 5000);\n}\n\nfunction fail(card, message, retry) {\n toast(message);\n if (!card) return;\n let box = card.querySelector(\"[data-fail]\");\n if (!box) {\n box = document.createElement(\"div\");\n box.setAttribute(\"data-fail\", \"1\");\n box.className = \"fail\";\n card.appendChild(box);\n }\n box.replaceChildren();\n const p = document.createElement(\"p\");\n p.textContent = message;\n const btn = document.createElement(\"button\");\n btn.className = \"btn sm\";\n btn.type = \"button\";\n btn.textContent = \"Retry\";\n btn.addEventListener(\"click\", retry);\n box.appendChild(p);\n box.appendChild(btn);\n}\n\nfunction clearFail(card) {\n const box = card && card.querySelector(\"[data-fail]\");\n if (box) box.remove();\n}\n\nfunction skeleton(card, on) {\n if (!card) return;\n card.classList.toggle(\"busy\", on);\n}\n\nasync function api(method, url, body) {\n const res = await fetch(url, {\n method: method,\n headers: {\n \"content-type\": \"application/json\",\n \"x-requested-with\": \"co-maintainer\",\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n });\n if (!res.ok) {\n let message = \"Request failed\";\n let code = \"\";\n let detail;\n try {\n const data = await res.json();\n if (data.error && data.error.message) message = data.error.message;\n if (data.error && data.error.code) code = data.error.code;\n if (data.error) detail = data.error.detail;\n } catch {\n // body was not JSON; keep the generic message\n }\n const error = new Error(message);\n if (code) error.code = code;\n error.detail = detail;\n throw error;\n }\n if (res.status === 204) return null;\n return await res.json();\n}\n\nasync function run(btn, card, fn) {\n if (btn) btn.disabled = true;\n skeleton(card, true);\n clearFail(card);\n try {\n await fn();\n } catch (err) {\n fail(card, err.message, function () {\n run(btn, card, fn);\n });\n } finally {\n if (btn) btn.disabled = false;\n skeleton(card, false);\n }\n}\n\n/** Polls one job until it reaches a terminal status. A running `init`/`remake`\n * ignores the abort signal, so \"wait for the sync\" is the only honest option\n * the clear pages can offer for it. */\nfunction waitForJob(id) {\n return new Promise(function (resolve, reject) {\n let attempts = 0;\n async function tick() {\n attempts++;\n try {\n const res = await fetch(\"/api/jobs/\" + encodeURIComponent(id), {\n headers: { \"x-requested-with\": \"co-maintainer\" },\n });\n if (!res.ok) throw new Error(\"Could not check the running job.\");\n const job = await res.json();\n if (job.status !== \"running\" && job.status !== \"queued\") {\n resolve();\n return;\n }\n if (attempts > 1200) {\n reject(new Error(\"The sync did not finish.\"));\n return;\n }\n setTimeout(tick, 3000);\n } catch (err) {\n reject(err);\n }\n }\n tick();\n });\n}\n\n/** Clears knowledge, asking about pending jobs when the server refuses.\n * Returns false when the user backed out, so the caller does not reload.\n * A running review is abortable and a running setup is not, which is the\n * difference between the two questions. */\nasync function clearKnowledge(url, includeCache) {\n const target = includeCache ? url + \"?includeCache=1\" : url;\n const retry = target.indexOf(\"?\") >= 0 ? \"&\" : \"?\";\n try {\n await api(\"DELETE\", target);\n } catch (err) {\n if (err.code !== \"jobs_running\") throw err;\n const detail = err.detail || { queued: 0, running: [] };\n const running = detail.running || [];\n const setup = running.find(function (job) {\n return job.abortable === false;\n });\n if (setup) {\n if (\n !confirm(\n \"A sync is running and cannot be stopped. Wait for it to finish and then clear?\",\n )\n ) {\n return false;\n }\n await waitForJob(setup.id);\n await api(\"DELETE\", target);\n return;\n }\n const parts = [];\n if (running.length) parts.push(running.length + \" running review(s)\");\n if (detail.queued) parts.push(detail.queued + \" queued job(s)\");\n if (!confirm(\"Stop \" + parts.join(\" and \") + \" and clear?\")) return false;\n try {\n await api(\"DELETE\", target + retry + \"onRunning=abort\");\n } catch (retryError) {\n // A setup job was claimed between the first 409 and this retry. It\n // cannot be aborted, so wait it out like the branch above.\n if (retryError.code !== \"job_not_abortable\") throw retryError;\n const jobId = retryError.detail && retryError.detail.id;\n if (jobId) await waitForJob(jobId);\n await api(\"DELETE\", target);\n }\n }\n}\n\nasync function postAndGo(url, body, next, btn) {\n const card = btn && btn.closest(\"[data-async]\");\n await run(btn, card, async function () {\n await api(\"POST\", url, body);\n location.href = next;\n });\n}\n\n// Called from the inline scripts on the repo list and repo pages, which deno lint\n// cannot see, so it looks unused from inside this file.\n// deno-lint-ignore no-unused-vars\nfunction bindToggle(btn, url, field) {\n btn.addEventListener(\"click\", async function () {\n if (btn.disabled) return;\n const on = !btn.classList.contains(\"on\");\n btn.classList.toggle(\"on\", on);\n btn.setAttribute(\"data-on\", on ? \"1\" : \"0\");\n btn.disabled = true;\n const card = btn.closest(\"[data-async]\");\n try {\n const payload = {};\n payload[field] = on;\n await api(\"PATCH\", url, payload);\n } catch (err) {\n btn.classList.toggle(\"on\", !on);\n btn.setAttribute(\"data-on\", on ? \"0\" : \"1\");\n fail(card, err.message, function () {\n btn.click();\n });\n } finally {\n btn.disabled = false;\n }\n });\n}\n\n// The helper is inlined into `<head>` by `layout.ts`, before any page script\n// runs, so this is the one place that can close over both `toast()` and\n// `bindToggle` without depending on point-in-time globals.\ndocument.addEventListener(\"DOMContentLoaded\", function () {\n // Client errors bubble to `window` from `document`.\n addEventListener(\"error\", function (ev) {\n toast((ev.error && ev.error.message) || \"Something broke\");\n });\n addEventListener(\"unhandledrejection\", function (ev) {\n toast((ev.reason && ev.reason.message) || \"Something broke\");\n });\n\n document.addEventListener(\"click\", function (ev) {\n const btn =\n ev.target && ev.target.closest\n ? ev.target.closest(\"[data-cancel], [data-post]\")\n : null;\n if (!btn) return;\n ev.preventDefault();\n if (btn.hasAttribute(\"data-cancel\")) {\n postAndGo(\n \"/api/jobs/\" + btn.getAttribute(\"data-cancel\") + \"/cancel\",\n {},\n \"/activity\",\n btn,\n );\n return;\n }\n const body = btn.getAttribute(\"data-body\");\n postAndGo(\n btn.getAttribute(\"data-post\"),\n body ? JSON.parse(body) : {},\n \"/activity\",\n btn,\n );\n });\n\n // Reads `activity-root` at call time, so it has to wait for the body even\n // though this file itself is already parsed.\n if (!document.getElementById(\"activity-root\")) return;\n setInterval(async function () {\n if (document.hidden) return;\n if (document.querySelector(\"[data-async].busy\")) return;\n const root = document.getElementById(\"activity-root\");\n if (!root) return;\n try {\n const res = await fetch(location.pathname + location.search, {\n headers: { accept: \"text/html\" },\n });\n if (!res.ok) return;\n const doc = new DOMParser().parseFromString(\n await res.text(),\n \"text/html\",\n );\n const next = doc.getElementById(\"activity-root\");\n if (!next || next.innerHTML === root.innerHTML) return;\n root.replaceWith(next);\n } catch {\n // a failed poll just waits for the next tick\n }\n }, 5000);\n});\n";
|
|
2
|
+
export declare const client = "function toast(message) {\n const host = document.getElementById(\"toasts\");\n if (!host) return;\n const el = document.createElement(\"div\");\n el.className = \"toast\";\n el.setAttribute(\"role\", \"status\");\n el.textContent = message;\n host.appendChild(el);\n setTimeout(function () {\n el.remove();\n }, 5000);\n}\n\nfunction fail(card, message, retry) {\n toast(message);\n if (!card) return;\n let box = card.querySelector(\"[data-fail]\");\n if (!box) {\n box = document.createElement(\"div\");\n box.setAttribute(\"data-fail\", \"1\");\n box.className = \"fail\";\n card.appendChild(box);\n }\n box.replaceChildren();\n const p = document.createElement(\"p\");\n p.textContent = message;\n const btn = document.createElement(\"button\");\n btn.className = \"btn sm\";\n btn.type = \"button\";\n btn.textContent = \"Retry\";\n btn.addEventListener(\"click\", retry);\n box.appendChild(p);\n box.appendChild(btn);\n}\n\nfunction clearFail(card) {\n const box = card && card.querySelector(\"[data-fail]\");\n if (box) box.remove();\n}\n\nfunction skeleton(card, on) {\n if (!card) return;\n card.classList.toggle(\"busy\", on);\n}\n\nasync function api(method, url, body) {\n const res = await fetch(url, {\n method: method,\n headers: {\n \"content-type\": \"application/json\",\n \"x-requested-with\": \"co-maintainer\",\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n });\n if (!res.ok) {\n let message = \"Request failed\";\n let code = \"\";\n let detail;\n try {\n const data = await res.json();\n if (data.error && data.error.message) message = data.error.message;\n if (data.error && data.error.code) code = data.error.code;\n if (data.error) detail = data.error.detail;\n } catch {\n // body was not JSON; keep the generic message\n }\n const error = new Error(message);\n if (code) error.code = code;\n error.detail = detail;\n throw error;\n }\n if (res.status === 204) return null;\n return await res.json();\n}\n\nasync function run(btn, card, fn) {\n if (btn) btn.disabled = true;\n skeleton(card, true);\n clearFail(card);\n try {\n await fn();\n } catch (err) {\n fail(card, err.message, function () {\n run(btn, card, fn);\n });\n } finally {\n if (btn) btn.disabled = false;\n skeleton(card, false);\n }\n}\n\n/** Polls one job until it reaches a terminal status. A running `init`/`remake`\n * ignores the abort signal, so \"wait for the sync\" is the only honest option\n * the clear pages can offer for it. */\nfunction waitForJob(id) {\n return new Promise(function (resolve, reject) {\n let attempts = 0;\n async function tick() {\n attempts++;\n try {\n const res = await fetch(\"/api/jobs/\" + encodeURIComponent(id), {\n headers: { \"x-requested-with\": \"co-maintainer\" },\n });\n if (!res.ok) throw new Error(\"Could not check the running job.\");\n const job = await res.json();\n if (job.status !== \"running\" && job.status !== \"queued\") {\n resolve();\n return;\n }\n if (attempts > 1200) {\n reject(new Error(\"The sync did not finish.\"));\n return;\n }\n setTimeout(tick, 3000);\n } catch (err) {\n reject(err);\n }\n }\n tick();\n });\n}\n\n/** Clears knowledge, asking about pending jobs when the server refuses.\n * Returns false when the user backed out, so the caller does not reload.\n * A running review is abortable and a running setup is not, which is the\n * difference between the two questions. Called from the inline scripts on the\n * knowledge pages, so it looks unused from inside this file. */\n// oxlint-disable-next-line no-unused-vars\nasync function clearKnowledge(url, includeCache) {\n const target = includeCache ? url + \"?includeCache=1\" : url;\n const retry = target.indexOf(\"?\") >= 0 ? \"&\" : \"?\";\n try {\n await api(\"DELETE\", target);\n } catch (err) {\n if (err.code !== \"jobs_running\") throw err;\n const detail = err.detail || { queued: 0, running: [] };\n const running = detail.running || [];\n const setup = running.find(function (job) {\n return job.abortable === false;\n });\n if (setup) {\n if (\n !confirm(\n \"A sync is running and cannot be stopped. Wait for it to finish and then clear?\",\n )\n ) {\n return false;\n }\n await waitForJob(setup.id);\n await api(\"DELETE\", target);\n return;\n }\n const parts = [];\n if (running.length) parts.push(running.length + \" running review(s)\");\n if (detail.queued) parts.push(detail.queued + \" queued job(s)\");\n if (!confirm(\"Stop \" + parts.join(\" and \") + \" and clear?\")) return false;\n try {\n await api(\"DELETE\", target + retry + \"onRunning=abort\");\n } catch (retryError) {\n // A setup job was claimed between the first 409 and this retry. It\n // cannot be aborted, so wait it out like the branch above.\n if (retryError.code !== \"job_not_abortable\") throw retryError;\n const jobId = retryError.detail && retryError.detail.id;\n if (jobId) await waitForJob(jobId);\n await api(\"DELETE\", target);\n }\n }\n}\n\nasync function postAndGo(url, body, next, btn) {\n const card = btn && btn.closest(\"[data-async]\");\n await run(btn, card, async function () {\n await api(\"POST\", url, body);\n location.href = next;\n });\n}\n\n// Called from the inline scripts on the repo list and repo pages, which deno lint\n// cannot see, so it looks unused from inside this file.\n// deno-lint-ignore no-unused-vars\n// oxlint-disable-next-line no-unused-vars\nfunction bindToggle(btn, url, field) {\n btn.addEventListener(\"click\", async function () {\n if (btn.disabled) return;\n const on = !btn.classList.contains(\"on\");\n btn.classList.toggle(\"on\", on);\n btn.setAttribute(\"data-on\", on ? \"1\" : \"0\");\n btn.disabled = true;\n const card = btn.closest(\"[data-async]\");\n try {\n const payload = {};\n payload[field] = on;\n await api(\"PATCH\", url, payload);\n } catch (err) {\n btn.classList.toggle(\"on\", !on);\n btn.setAttribute(\"data-on\", on ? \"0\" : \"1\");\n fail(card, err.message, function () {\n btn.click();\n });\n } finally {\n btn.disabled = false;\n }\n });\n}\n\n// The helper is inlined into `<head>` by `layout.ts`, before any page script\n// runs, so this is the one place that can close over both `toast()` and\n// `bindToggle` without depending on point-in-time globals.\ndocument.addEventListener(\"DOMContentLoaded\", function () {\n // Client errors bubble to `window` from `document`.\n addEventListener(\"error\", function (ev) {\n toast((ev.error && ev.error.message) || \"Something broke\");\n });\n addEventListener(\"unhandledrejection\", function (ev) {\n toast((ev.reason && ev.reason.message) || \"Something broke\");\n });\n\n document.addEventListener(\"click\", function (ev) {\n const btn =\n ev.target && ev.target.closest\n ? ev.target.closest(\"[data-cancel], [data-post]\")\n : null;\n if (!btn) return;\n ev.preventDefault();\n if (btn.hasAttribute(\"data-cancel\")) {\n postAndGo(\n \"/api/jobs/\" + btn.getAttribute(\"data-cancel\") + \"/cancel\",\n {},\n \"/activity\",\n btn,\n );\n return;\n }\n const body = btn.getAttribute(\"data-body\");\n postAndGo(\n btn.getAttribute(\"data-post\"),\n body ? JSON.parse(body) : {},\n \"/activity\",\n btn,\n );\n });\n\n // Reads `activity-root` at call time, so it has to wait for the body even\n // though this file itself is already parsed.\n if (!document.getElementById(\"activity-root\")) return;\n setInterval(async function () {\n if (document.hidden) return;\n if (document.querySelector(\"[data-async].busy\")) return;\n const root = document.getElementById(\"activity-root\");\n if (!root) return;\n try {\n const res = await fetch(location.pathname + location.search, {\n headers: { accept: \"text/html\" },\n });\n if (!res.ok) return;\n const doc = new DOMParser().parseFromString(\n await res.text(),\n \"text/html\",\n );\n const next = doc.getElementById(\"activity-root\");\n if (!next || next.innerHTML === root.innerHTML) return;\n root.replaceWith(next);\n } catch {\n // a failed poll just waits for the next tick\n }\n }, 5000);\n});\n";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Generated from src/server/pages/client.js by scripts/embed_assets.mjs — do not edit. */
|
|
2
|
-
export const client = "function toast(message) {\n const host = document.getElementById(\"toasts\");\n if (!host) return;\n const el = document.createElement(\"div\");\n el.className = \"toast\";\n el.setAttribute(\"role\", \"status\");\n el.textContent = message;\n host.appendChild(el);\n setTimeout(function () {\n el.remove();\n }, 5000);\n}\n\nfunction fail(card, message, retry) {\n toast(message);\n if (!card) return;\n let box = card.querySelector(\"[data-fail]\");\n if (!box) {\n box = document.createElement(\"div\");\n box.setAttribute(\"data-fail\", \"1\");\n box.className = \"fail\";\n card.appendChild(box);\n }\n box.replaceChildren();\n const p = document.createElement(\"p\");\n p.textContent = message;\n const btn = document.createElement(\"button\");\n btn.className = \"btn sm\";\n btn.type = \"button\";\n btn.textContent = \"Retry\";\n btn.addEventListener(\"click\", retry);\n box.appendChild(p);\n box.appendChild(btn);\n}\n\nfunction clearFail(card) {\n const box = card && card.querySelector(\"[data-fail]\");\n if (box) box.remove();\n}\n\nfunction skeleton(card, on) {\n if (!card) return;\n card.classList.toggle(\"busy\", on);\n}\n\nasync function api(method, url, body) {\n const res = await fetch(url, {\n method: method,\n headers: {\n \"content-type\": \"application/json\",\n \"x-requested-with\": \"co-maintainer\",\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n });\n if (!res.ok) {\n let message = \"Request failed\";\n let code = \"\";\n let detail;\n try {\n const data = await res.json();\n if (data.error && data.error.message) message = data.error.message;\n if (data.error && data.error.code) code = data.error.code;\n if (data.error) detail = data.error.detail;\n } catch {\n // body was not JSON; keep the generic message\n }\n const error = new Error(message);\n if (code) error.code = code;\n error.detail = detail;\n throw error;\n }\n if (res.status === 204) return null;\n return await res.json();\n}\n\nasync function run(btn, card, fn) {\n if (btn) btn.disabled = true;\n skeleton(card, true);\n clearFail(card);\n try {\n await fn();\n } catch (err) {\n fail(card, err.message, function () {\n run(btn, card, fn);\n });\n } finally {\n if (btn) btn.disabled = false;\n skeleton(card, false);\n }\n}\n\n/** Polls one job until it reaches a terminal status. A running `init`/`remake`\n * ignores the abort signal, so \"wait for the sync\" is the only honest option\n * the clear pages can offer for it. */\nfunction waitForJob(id) {\n return new Promise(function (resolve, reject) {\n let attempts = 0;\n async function tick() {\n attempts++;\n try {\n const res = await fetch(\"/api/jobs/\" + encodeURIComponent(id), {\n headers: { \"x-requested-with\": \"co-maintainer\" },\n });\n if (!res.ok) throw new Error(\"Could not check the running job.\");\n const job = await res.json();\n if (job.status !== \"running\" && job.status !== \"queued\") {\n resolve();\n return;\n }\n if (attempts > 1200) {\n reject(new Error(\"The sync did not finish.\"));\n return;\n }\n setTimeout(tick, 3000);\n } catch (err) {\n reject(err);\n }\n }\n tick();\n });\n}\n\n/** Clears knowledge, asking about pending jobs when the server refuses.\n * Returns false when the user backed out, so the caller does not reload.\n * A running review is abortable and a running setup is not, which is the\n * difference between the two questions. */\nasync function clearKnowledge(url, includeCache) {\n const target = includeCache ? url + \"?includeCache=1\" : url;\n const retry = target.indexOf(\"?\") >= 0 ? \"&\" : \"?\";\n try {\n await api(\"DELETE\", target);\n } catch (err) {\n if (err.code !== \"jobs_running\") throw err;\n const detail = err.detail || { queued: 0, running: [] };\n const running = detail.running || [];\n const setup = running.find(function (job) {\n return job.abortable === false;\n });\n if (setup) {\n if (\n !confirm(\n \"A sync is running and cannot be stopped. Wait for it to finish and then clear?\",\n )\n ) {\n return false;\n }\n await waitForJob(setup.id);\n await api(\"DELETE\", target);\n return;\n }\n const parts = [];\n if (running.length) parts.push(running.length + \" running review(s)\");\n if (detail.queued) parts.push(detail.queued + \" queued job(s)\");\n if (!confirm(\"Stop \" + parts.join(\" and \") + \" and clear?\")) return false;\n try {\n await api(\"DELETE\", target + retry + \"onRunning=abort\");\n } catch (retryError) {\n // A setup job was claimed between the first 409 and this retry. It\n // cannot be aborted, so wait it out like the branch above.\n if (retryError.code !== \"job_not_abortable\") throw retryError;\n const jobId = retryError.detail && retryError.detail.id;\n if (jobId) await waitForJob(jobId);\n await api(\"DELETE\", target);\n }\n }\n}\n\nasync function postAndGo(url, body, next, btn) {\n const card = btn && btn.closest(\"[data-async]\");\n await run(btn, card, async function () {\n await api(\"POST\", url, body);\n location.href = next;\n });\n}\n\n// Called from the inline scripts on the repo list and repo pages, which deno lint\n// cannot see, so it looks unused from inside this file.\n// deno-lint-ignore no-unused-vars\nfunction bindToggle(btn, url, field) {\n btn.addEventListener(\"click\", async function () {\n if (btn.disabled) return;\n const on = !btn.classList.contains(\"on\");\n btn.classList.toggle(\"on\", on);\n btn.setAttribute(\"data-on\", on ? \"1\" : \"0\");\n btn.disabled = true;\n const card = btn.closest(\"[data-async]\");\n try {\n const payload = {};\n payload[field] = on;\n await api(\"PATCH\", url, payload);\n } catch (err) {\n btn.classList.toggle(\"on\", !on);\n btn.setAttribute(\"data-on\", on ? \"0\" : \"1\");\n fail(card, err.message, function () {\n btn.click();\n });\n } finally {\n btn.disabled = false;\n }\n });\n}\n\n// The helper is inlined into `<head>` by `layout.ts`, before any page script\n// runs, so this is the one place that can close over both `toast()` and\n// `bindToggle` without depending on point-in-time globals.\ndocument.addEventListener(\"DOMContentLoaded\", function () {\n // Client errors bubble to `window` from `document`.\n addEventListener(\"error\", function (ev) {\n toast((ev.error && ev.error.message) || \"Something broke\");\n });\n addEventListener(\"unhandledrejection\", function (ev) {\n toast((ev.reason && ev.reason.message) || \"Something broke\");\n });\n\n document.addEventListener(\"click\", function (ev) {\n const btn =\n ev.target && ev.target.closest\n ? ev.target.closest(\"[data-cancel], [data-post]\")\n : null;\n if (!btn) return;\n ev.preventDefault();\n if (btn.hasAttribute(\"data-cancel\")) {\n postAndGo(\n \"/api/jobs/\" + btn.getAttribute(\"data-cancel\") + \"/cancel\",\n {},\n \"/activity\",\n btn,\n );\n return;\n }\n const body = btn.getAttribute(\"data-body\");\n postAndGo(\n btn.getAttribute(\"data-post\"),\n body ? JSON.parse(body) : {},\n \"/activity\",\n btn,\n );\n });\n\n // Reads `activity-root` at call time, so it has to wait for the body even\n // though this file itself is already parsed.\n if (!document.getElementById(\"activity-root\")) return;\n setInterval(async function () {\n if (document.hidden) return;\n if (document.querySelector(\"[data-async].busy\")) return;\n const root = document.getElementById(\"activity-root\");\n if (!root) return;\n try {\n const res = await fetch(location.pathname + location.search, {\n headers: { accept: \"text/html\" },\n });\n if (!res.ok) return;\n const doc = new DOMParser().parseFromString(\n await res.text(),\n \"text/html\",\n );\n const next = doc.getElementById(\"activity-root\");\n if (!next || next.innerHTML === root.innerHTML) return;\n root.replaceWith(next);\n } catch {\n // a failed poll just waits for the next tick\n }\n }, 5000);\n});\n";
|
|
2
|
+
export const client = "function toast(message) {\n const host = document.getElementById(\"toasts\");\n if (!host) return;\n const el = document.createElement(\"div\");\n el.className = \"toast\";\n el.setAttribute(\"role\", \"status\");\n el.textContent = message;\n host.appendChild(el);\n setTimeout(function () {\n el.remove();\n }, 5000);\n}\n\nfunction fail(card, message, retry) {\n toast(message);\n if (!card) return;\n let box = card.querySelector(\"[data-fail]\");\n if (!box) {\n box = document.createElement(\"div\");\n box.setAttribute(\"data-fail\", \"1\");\n box.className = \"fail\";\n card.appendChild(box);\n }\n box.replaceChildren();\n const p = document.createElement(\"p\");\n p.textContent = message;\n const btn = document.createElement(\"button\");\n btn.className = \"btn sm\";\n btn.type = \"button\";\n btn.textContent = \"Retry\";\n btn.addEventListener(\"click\", retry);\n box.appendChild(p);\n box.appendChild(btn);\n}\n\nfunction clearFail(card) {\n const box = card && card.querySelector(\"[data-fail]\");\n if (box) box.remove();\n}\n\nfunction skeleton(card, on) {\n if (!card) return;\n card.classList.toggle(\"busy\", on);\n}\n\nasync function api(method, url, body) {\n const res = await fetch(url, {\n method: method,\n headers: {\n \"content-type\": \"application/json\",\n \"x-requested-with\": \"co-maintainer\",\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n });\n if (!res.ok) {\n let message = \"Request failed\";\n let code = \"\";\n let detail;\n try {\n const data = await res.json();\n if (data.error && data.error.message) message = data.error.message;\n if (data.error && data.error.code) code = data.error.code;\n if (data.error) detail = data.error.detail;\n } catch {\n // body was not JSON; keep the generic message\n }\n const error = new Error(message);\n if (code) error.code = code;\n error.detail = detail;\n throw error;\n }\n if (res.status === 204) return null;\n return await res.json();\n}\n\nasync function run(btn, card, fn) {\n if (btn) btn.disabled = true;\n skeleton(card, true);\n clearFail(card);\n try {\n await fn();\n } catch (err) {\n fail(card, err.message, function () {\n run(btn, card, fn);\n });\n } finally {\n if (btn) btn.disabled = false;\n skeleton(card, false);\n }\n}\n\n/** Polls one job until it reaches a terminal status. A running `init`/`remake`\n * ignores the abort signal, so \"wait for the sync\" is the only honest option\n * the clear pages can offer for it. */\nfunction waitForJob(id) {\n return new Promise(function (resolve, reject) {\n let attempts = 0;\n async function tick() {\n attempts++;\n try {\n const res = await fetch(\"/api/jobs/\" + encodeURIComponent(id), {\n headers: { \"x-requested-with\": \"co-maintainer\" },\n });\n if (!res.ok) throw new Error(\"Could not check the running job.\");\n const job = await res.json();\n if (job.status !== \"running\" && job.status !== \"queued\") {\n resolve();\n return;\n }\n if (attempts > 1200) {\n reject(new Error(\"The sync did not finish.\"));\n return;\n }\n setTimeout(tick, 3000);\n } catch (err) {\n reject(err);\n }\n }\n tick();\n });\n}\n\n/** Clears knowledge, asking about pending jobs when the server refuses.\n * Returns false when the user backed out, so the caller does not reload.\n * A running review is abortable and a running setup is not, which is the\n * difference between the two questions. Called from the inline scripts on the\n * knowledge pages, so it looks unused from inside this file. */\n// oxlint-disable-next-line no-unused-vars\nasync function clearKnowledge(url, includeCache) {\n const target = includeCache ? url + \"?includeCache=1\" : url;\n const retry = target.indexOf(\"?\") >= 0 ? \"&\" : \"?\";\n try {\n await api(\"DELETE\", target);\n } catch (err) {\n if (err.code !== \"jobs_running\") throw err;\n const detail = err.detail || { queued: 0, running: [] };\n const running = detail.running || [];\n const setup = running.find(function (job) {\n return job.abortable === false;\n });\n if (setup) {\n if (\n !confirm(\n \"A sync is running and cannot be stopped. Wait for it to finish and then clear?\",\n )\n ) {\n return false;\n }\n await waitForJob(setup.id);\n await api(\"DELETE\", target);\n return;\n }\n const parts = [];\n if (running.length) parts.push(running.length + \" running review(s)\");\n if (detail.queued) parts.push(detail.queued + \" queued job(s)\");\n if (!confirm(\"Stop \" + parts.join(\" and \") + \" and clear?\")) return false;\n try {\n await api(\"DELETE\", target + retry + \"onRunning=abort\");\n } catch (retryError) {\n // A setup job was claimed between the first 409 and this retry. It\n // cannot be aborted, so wait it out like the branch above.\n if (retryError.code !== \"job_not_abortable\") throw retryError;\n const jobId = retryError.detail && retryError.detail.id;\n if (jobId) await waitForJob(jobId);\n await api(\"DELETE\", target);\n }\n }\n}\n\nasync function postAndGo(url, body, next, btn) {\n const card = btn && btn.closest(\"[data-async]\");\n await run(btn, card, async function () {\n await api(\"POST\", url, body);\n location.href = next;\n });\n}\n\n// Called from the inline scripts on the repo list and repo pages, which deno lint\n// cannot see, so it looks unused from inside this file.\n// deno-lint-ignore no-unused-vars\n// oxlint-disable-next-line no-unused-vars\nfunction bindToggle(btn, url, field) {\n btn.addEventListener(\"click\", async function () {\n if (btn.disabled) return;\n const on = !btn.classList.contains(\"on\");\n btn.classList.toggle(\"on\", on);\n btn.setAttribute(\"data-on\", on ? \"1\" : \"0\");\n btn.disabled = true;\n const card = btn.closest(\"[data-async]\");\n try {\n const payload = {};\n payload[field] = on;\n await api(\"PATCH\", url, payload);\n } catch (err) {\n btn.classList.toggle(\"on\", !on);\n btn.setAttribute(\"data-on\", on ? \"0\" : \"1\");\n fail(card, err.message, function () {\n btn.click();\n });\n } finally {\n btn.disabled = false;\n }\n });\n}\n\n// The helper is inlined into `<head>` by `layout.ts`, before any page script\n// runs, so this is the one place that can close over both `toast()` and\n// `bindToggle` without depending on point-in-time globals.\ndocument.addEventListener(\"DOMContentLoaded\", function () {\n // Client errors bubble to `window` from `document`.\n addEventListener(\"error\", function (ev) {\n toast((ev.error && ev.error.message) || \"Something broke\");\n });\n addEventListener(\"unhandledrejection\", function (ev) {\n toast((ev.reason && ev.reason.message) || \"Something broke\");\n });\n\n document.addEventListener(\"click\", function (ev) {\n const btn =\n ev.target && ev.target.closest\n ? ev.target.closest(\"[data-cancel], [data-post]\")\n : null;\n if (!btn) return;\n ev.preventDefault();\n if (btn.hasAttribute(\"data-cancel\")) {\n postAndGo(\n \"/api/jobs/\" + btn.getAttribute(\"data-cancel\") + \"/cancel\",\n {},\n \"/activity\",\n btn,\n );\n return;\n }\n const body = btn.getAttribute(\"data-body\");\n postAndGo(\n btn.getAttribute(\"data-post\"),\n body ? JSON.parse(body) : {},\n \"/activity\",\n btn,\n );\n });\n\n // Reads `activity-root` at call time, so it has to wait for the body even\n // though this file itself is already parsed.\n if (!document.getElementById(\"activity-root\")) return;\n setInterval(async function () {\n if (document.hidden) return;\n if (document.querySelector(\"[data-async].busy\")) return;\n const root = document.getElementById(\"activity-root\");\n if (!root) return;\n try {\n const res = await fetch(location.pathname + location.search, {\n headers: { accept: \"text/html\" },\n });\n if (!res.ok) return;\n const doc = new DOMParser().parseFromString(\n await res.text(),\n \"text/html\",\n );\n const next = doc.getElementById(\"activity-root\");\n if (!next || next.innerHTML === root.innerHTML) return;\n root.replaceWith(next);\n } catch {\n // a failed poll just waits for the next tick\n }\n }, 5000);\n});\n";
|
|
@@ -2,6 +2,7 @@ import { html, layout, repoNav, skSlot, text } from "./layout.js";
|
|
|
2
2
|
import { parseRemakeCron } from "../../services/remake_cron.js";
|
|
3
3
|
import { nextCronRun } from "../../util/cron.js";
|
|
4
4
|
import { policySource } from "../../services/webhook.js";
|
|
5
|
+
import { DEFAULT_REVIEW_SYSTEM_PROMPT_MAX_CHARS } from "../../review/system_prompt.js";
|
|
5
6
|
import { ASSOCIATIONS, TEMPLATES, TEMPLATE_INFO, storedPolicyValue, withDefaults, } from "../../services/review_policy.js";
|
|
6
7
|
const ASSOCIATION_LABEL = {
|
|
7
8
|
OWNER: "Owner",
|
|
@@ -157,6 +158,19 @@ export function renderRepoSettings(username, repo, config) {
|
|
|
157
158
|
</div>
|
|
158
159
|
<div class="ft"><button class="primary" id="save-auto">Save</button></div>
|
|
159
160
|
</div>
|
|
161
|
+
<div class="card" data-async>
|
|
162
|
+
${skSlot()}
|
|
163
|
+
<div class="hd"><h2>Custom review instructions</h2></div>
|
|
164
|
+
<div class="bd">
|
|
165
|
+
<p class="muted" style="margin:0 0 18px">Added to the reviewer's built-in instructions for every review of this repository, as a separate section. Leave blank for none.</p>
|
|
166
|
+
<div class="field wide"><label for="system-prompt">Instructions</label>
|
|
167
|
+
<textarea id="system-prompt" rows="8" placeholder="For example: prefer the project's own helpers over new dependencies.">${text(config.reviewSystemPrompt ?? "")}</textarea></div>
|
|
168
|
+
<div class="field"><label for="system-prompt-max">Maximum characters</label>
|
|
169
|
+
<input id="system-prompt-max" placeholder="${DEFAULT_REVIEW_SYSTEM_PROMPT_MAX_CHARS}" value="${text(config.reviewSystemPromptMaxChars ?? "")}">
|
|
170
|
+
<div class="hint">Blank uses ${DEFAULT_REVIEW_SYSTEM_PROMPT_MAX_CHARS}. 0 or -1 means no limit.</div></div>
|
|
171
|
+
</div>
|
|
172
|
+
<div class="ft"><button class="primary" id="save-prompt">Save</button></div>
|
|
173
|
+
</div>
|
|
160
174
|
<div class="card" data-async>
|
|
161
175
|
${skSlot()}
|
|
162
176
|
<div class="hd"><h2>How this repository is analyzed</h2></div>
|
|
@@ -462,6 +476,23 @@ document.getElementById("save-init").addEventListener("click", function() {
|
|
|
462
476
|
document.getElementById("save-cron").addEventListener("click", function() {
|
|
463
477
|
save(this, { remakeCron: document.getElementById("cron").value.trim() });
|
|
464
478
|
});
|
|
479
|
+
document.getElementById("save-prompt").addEventListener("click", function() {
|
|
480
|
+
var maxRaw = document.getElementById("system-prompt-max").value.trim();
|
|
481
|
+
var max;
|
|
482
|
+
if (maxRaw === "") {
|
|
483
|
+
max = null;
|
|
484
|
+
} else {
|
|
485
|
+
max = Number(maxRaw);
|
|
486
|
+
if (!Number.isInteger(max)) {
|
|
487
|
+
toast("Maximum characters must be a whole number, or blank for the default.");
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
save(this, {
|
|
492
|
+
reviewSystemPrompt: document.getElementById("system-prompt").value,
|
|
493
|
+
reviewSystemPromptMaxChars: max
|
|
494
|
+
});
|
|
495
|
+
});
|
|
465
496
|
document.getElementById("remove").addEventListener("click", function() {
|
|
466
497
|
if (!confirm("Stop reviewing this repository?")) return;
|
|
467
498
|
var btn = this;
|
|
@@ -11,6 +11,7 @@ import { closeRemoteSession, openRemoteSession, setRemoteSyncResult, } from "../
|
|
|
11
11
|
import { readConfig, remoteByokPolicy, resolvedAiToken } from "../config.js";
|
|
12
12
|
import { dropByokKey, getByokKey, hasByokKey, registerByokKey, } from "../remote/server/byok_keys.js";
|
|
13
13
|
import { reviewBlockingFrom } from "../review/blocking.js";
|
|
14
|
+
import { checkReviewSystemPrompt, reviewSystemPromptLimit, } from "../review/system_prompt.js";
|
|
14
15
|
import { loadGuides } from "../review/guides.js";
|
|
15
16
|
import { withLogSink } from "../util/log.js";
|
|
16
17
|
import { cancel, registerHandler } from "./jobs.js";
|
|
@@ -77,6 +78,7 @@ function reviewOptionsForRepo(repo, useCodegraph, aiToken) {
|
|
|
77
78
|
includeHowRepoWorks: true,
|
|
78
79
|
onlyRequestChangedPr: false,
|
|
79
80
|
reviewBlocking: reviewBlockingFrom(config.reviewBlocking),
|
|
81
|
+
reviewSystemPrompt: config.repos?.[repo]?.reviewSystemPrompt,
|
|
80
82
|
};
|
|
81
83
|
}
|
|
82
84
|
function supersedeActiveRemoteJobs(queueKey, supersededBy) {
|
|
@@ -159,6 +161,27 @@ export function submitRemoteReview(token, body) {
|
|
|
159
161
|
supersedeActiveRemoteJobs(queueKey, jobId);
|
|
160
162
|
const revision = body.revision ?? {};
|
|
161
163
|
const capabilities = body.capabilities ?? { tools: [] };
|
|
164
|
+
const config = readConfig();
|
|
165
|
+
const promptLimit = reviewSystemPromptLimit(config.repos?.[repoRow.full_name]);
|
|
166
|
+
const systemPromptAdd = typeof body.systemPromptAdd === "string" ? body.systemPromptAdd : undefined;
|
|
167
|
+
const systemPromptOverride = typeof body.systemPromptOverride === "string"
|
|
168
|
+
? body.systemPromptOverride
|
|
169
|
+
: undefined;
|
|
170
|
+
for (const [field, value] of [
|
|
171
|
+
["systemPromptAdd", systemPromptAdd],
|
|
172
|
+
["systemPromptOverride", systemPromptOverride],
|
|
173
|
+
]) {
|
|
174
|
+
if (value === undefined)
|
|
175
|
+
continue;
|
|
176
|
+
const problem = checkReviewSystemPrompt(value, promptLimit);
|
|
177
|
+
if (problem) {
|
|
178
|
+
return {
|
|
179
|
+
error: `${field}: ${problem}`,
|
|
180
|
+
status: 400,
|
|
181
|
+
code: "bad_request",
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
162
185
|
insertRemoteReviewInput({
|
|
163
186
|
jobId,
|
|
164
187
|
revisionJson: JSON.stringify(revision),
|
|
@@ -166,13 +189,14 @@ export function submitRemoteReview(token, body) {
|
|
|
166
189
|
requestId,
|
|
167
190
|
tokenId: token.id,
|
|
168
191
|
billedTo,
|
|
192
|
+
systemPromptAdd,
|
|
193
|
+
systemPromptOverride,
|
|
169
194
|
});
|
|
170
195
|
// The review and job rows go in one transaction so a failure cannot leave a
|
|
171
196
|
// partially written submission behind: no review with no job, and no queued
|
|
172
197
|
// job whose input row points a retry at a job that never really started.
|
|
173
198
|
// The key is registered only after COMMIT, so it never outlives a failed
|
|
174
199
|
// setup.
|
|
175
|
-
const config = readConfig();
|
|
176
200
|
const db = getAppDb();
|
|
177
201
|
db.exec("BEGIN");
|
|
178
202
|
try {
|
|
@@ -250,6 +274,11 @@ export function registerRemoteReviewHandler() {
|
|
|
250
274
|
.filter((name) => typeof name === "string" && name));
|
|
251
275
|
const useCodegraph = allowed.size > 0;
|
|
252
276
|
const options = reviewOptionsForRepo(job.repo, useCodegraph, byokKey);
|
|
277
|
+
// The client's one-run instructions travel with the job, so a retry
|
|
278
|
+
// keeps them. They apply on top of the server's per-repo prompt.
|
|
279
|
+
options.reviewSystemPromptAdd = input.system_prompt_add ?? undefined;
|
|
280
|
+
options.reviewSystemPromptOverride =
|
|
281
|
+
input.system_prompt_override ?? undefined;
|
|
253
282
|
// A BYOK client brings a key but not models, so a server with no
|
|
254
283
|
// models cannot run its review either.
|
|
255
284
|
if (!options.aiToken ||
|
|
@@ -156,6 +156,7 @@ export function reviewOptions(repo, prNumber) {
|
|
|
156
156
|
onlyRequestChangedPr: false,
|
|
157
157
|
useCodegraph: getRepo(repo)?.use_codegraph === 1,
|
|
158
158
|
reviewBlocking: reviewBlockingFrom(config.reviewBlocking),
|
|
159
|
+
reviewSystemPrompt: config.repos?.[repo]?.reviewSystemPrompt,
|
|
159
160
|
};
|
|
160
161
|
}
|
|
161
162
|
export function aiFor(options) {
|
|
@@ -275,4 +275,11 @@ export const migrations = [
|
|
|
275
275
|
`ALTER TABLE repos ADD COLUMN review_policy_json TEXT`,
|
|
276
276
|
`UPDATE repos SET review_policy_json = '"legacy"'`,
|
|
277
277
|
],
|
|
278
|
+
// 12 — a remote client's one-run review instructions travel with the job so
|
|
279
|
+
// a retry keeps them. The per-repo prompt stays in config.json and is read
|
|
280
|
+
// on the server where the review runs.
|
|
281
|
+
[
|
|
282
|
+
`ALTER TABLE remote_review_inputs ADD COLUMN system_prompt_add TEXT`,
|
|
283
|
+
`ALTER TABLE remote_review_inputs ADD COLUMN system_prompt_override TEXT`,
|
|
284
|
+
],
|
|
278
285
|
];
|
|
@@ -8,6 +8,8 @@ export declare function insertRemoteReviewInput(input: {
|
|
|
8
8
|
/** `'byok'` when the client submitted its own key, else `'server'`. The key
|
|
9
9
|
* itself is never written here. */
|
|
10
10
|
billedTo: "server" | "byok";
|
|
11
|
+
systemPromptAdd?: string;
|
|
12
|
+
systemPromptOverride?: string;
|
|
11
13
|
}): void;
|
|
12
14
|
export declare function findRemoteReviewInputByRequest(tokenId: string, requestId: string): RemoteReviewInputRow | undefined;
|
|
13
15
|
export declare function getRemoteReviewInput(jobId: string): RemoteReviewInputRow | undefined;
|
|
@@ -3,9 +3,9 @@ import { nowIso } from "../util/time.js";
|
|
|
3
3
|
export function insertRemoteReviewInput(input) {
|
|
4
4
|
getAppDb()
|
|
5
5
|
.prepare(`INSERT INTO remote_review_inputs
|
|
6
|
-
(job_id, revision_json, capabilities_json, request_id, token_id, created_at, billed_to)
|
|
7
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)`)
|
|
8
|
-
.run(input.jobId, input.revisionJson, input.capabilitiesJson, input.requestId, input.tokenId, nowIso(), input.billedTo);
|
|
6
|
+
(job_id, revision_json, capabilities_json, request_id, token_id, created_at, billed_to, system_prompt_add, system_prompt_override)
|
|
7
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
8
|
+
.run(input.jobId, input.revisionJson, input.capabilitiesJson, input.requestId, input.tokenId, nowIso(), input.billedTo, input.systemPromptAdd ?? null, input.systemPromptOverride ?? null);
|
|
9
9
|
}
|
|
10
10
|
export function findRemoteReviewInputByRequest(tokenId, requestId) {
|
|
11
11
|
return getAppDb()
|
package/dist/src/store/rows.d.ts
CHANGED
|
@@ -186,4 +186,7 @@ export type RemoteReviewInputRow = {
|
|
|
186
186
|
/** `'byok'` when the client's own key paid for the review, `'server'`
|
|
187
187
|
* otherwise. A null (pre-0.5.1 row) is treated as `'server'`. */
|
|
188
188
|
billed_to?: string | null;
|
|
189
|
+
/** The client's one-run review instructions, kept so a retry reuses them. */
|
|
190
|
+
system_prompt_add?: string | null;
|
|
191
|
+
system_prompt_override?: string | null;
|
|
189
192
|
};
|
package/dist/src/types.d.ts
CHANGED
|
@@ -49,6 +49,17 @@ export type Options = {
|
|
|
49
49
|
/** How a review decides a blocking finding. `model` keeps the
|
|
50
50
|
* 0.4.13 behavior, `severity` uses a fixed P0/P1 threshold. */
|
|
51
51
|
reviewBlocking?: "model" | "severity";
|
|
52
|
+
/** The repository's own review instructions (config.json
|
|
53
|
+
* `repos[repo].reviewSystemPrompt`). Appended to the built-in reviewer
|
|
54
|
+
* prompt as a `CUSTOM REVIEW INSTRUCTIONS` section. */
|
|
55
|
+
reviewSystemPrompt?: string;
|
|
56
|
+
/** A one-run addition to the custom section
|
|
57
|
+
* (`review --system-prompt-file`). */
|
|
58
|
+
reviewSystemPromptAdd?: string;
|
|
59
|
+
/** A one-run replacement of the repository's custom section
|
|
60
|
+
* (`review --system-prompt-override-file`). The built-in role, diagram
|
|
61
|
+
* rules and guide block are still kept. */
|
|
62
|
+
reviewSystemPromptOverride?: string;
|
|
52
63
|
};
|
|
53
64
|
export type GitHubClient = {
|
|
54
65
|
request<T>(endpoint: string): Promise<T>;
|