co-maintainer 0.6.12 → 0.7.0-beta.1
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/README.md +1 -1
- package/dist/package.json +1 -1
- package/dist/src/ai/anthropic.js +2 -0
- package/dist/src/ai/batch.d.ts +3 -1
- package/dist/src/ai/batch.js +23 -2
- package/dist/src/ai/mermaid_loop.js +1 -1
- package/dist/src/ai/oauth/sign-in-with-chatgpt.js +8 -10
- package/dist/src/ai/openai.js +2 -0
- package/dist/src/ai/openrouter.js +2 -0
- package/dist/src/cli/args.js +47 -0
- package/dist/src/cli/command_json.d.ts +20 -1
- package/dist/src/cli/command_json.js +4 -0
- package/dist/src/cli/commands/config.d.ts +1 -1
- package/dist/src/cli/commands/config.js +1 -0
- package/dist/src/cli/commands/registry.js +226 -1
- package/dist/src/cli/commands/review.js +50 -9
- package/dist/src/cli/commands/serve.js +5 -0
- package/dist/src/cli/commands/set.js +75 -17
- package/dist/src/cli/commands/view.js +46 -5
- package/dist/src/cli/commands/view_sources.d.ts +11 -0
- package/dist/src/cli/commands/view_sources.js +40 -0
- package/dist/src/cli/main.js +5 -0
- package/dist/src/cli/pr_carry.d.ts +25 -0
- package/dist/src/cli/pr_carry.js +128 -0
- package/dist/src/cli/prompt.js +26 -1
- package/dist/src/cli/review_args.d.ts +8 -0
- package/dist/src/cli/review_args.js +18 -0
- package/dist/src/cli/review_carry.d.ts +32 -0
- package/dist/src/cli/review_carry.js +60 -0
- package/dist/src/cli/review_github.d.ts +16 -2
- package/dist/src/cli/review_github.js +49 -12
- package/dist/src/cli/review_intent.d.ts +25 -0
- package/dist/src/cli/review_intent.js +87 -0
- package/dist/src/cli/review_result.d.ts +53 -2
- package/dist/src/cli/review_result.js +90 -23
- package/dist/src/config.d.ts +30 -0
- package/dist/src/config.js +20 -12
- package/dist/src/extensions/command.d.ts +1 -0
- package/dist/src/extensions/command.js +355 -0
- package/dist/src/extensions/contexts.d.ts +65 -0
- package/dist/src/extensions/contexts.js +134 -0
- package/dist/src/extensions/cost.d.ts +8 -0
- package/dist/src/extensions/cost.js +6 -0
- package/dist/src/extensions/local_tracking.d.ts +7 -0
- package/dist/src/extensions/local_tracking.js +29 -0
- package/dist/src/extensions/mock.d.ts +29 -0
- package/dist/src/extensions/mock.js +67 -0
- package/dist/src/extensions/process.d.ts +43 -0
- package/dist/src/extensions/process.js +244 -0
- package/dist/src/extensions/registry.d.ts +79 -0
- package/dist/src/extensions/registry.js +240 -0
- package/dist/src/extensions/render_actions.d.ts +6 -0
- package/dist/src/extensions/render_actions.js +50 -0
- package/dist/src/extensions/render_cli.d.ts +18 -0
- package/dist/src/extensions/render_cli.js +88 -0
- package/dist/src/extensions/render_json.d.ts +51 -0
- package/dist/src/extensions/render_json.js +144 -0
- package/dist/src/extensions/render_markdown.d.ts +22 -0
- package/dist/src/extensions/render_markdown.js +96 -0
- package/dist/src/extensions/render_review.d.ts +44 -0
- package/dist/src/extensions/render_review.js +167 -0
- package/dist/src/extensions/report.d.ts +57 -0
- package/dist/src/extensions/report.js +97 -0
- package/dist/src/extensions/review_result.d.ts +2 -0
- package/dist/src/extensions/review_result.js +14 -0
- package/dist/src/extensions/run_folder.d.ts +74 -0
- package/dist/src/extensions/run_folder.js +172 -0
- package/dist/src/extensions/runner.d.ts +66 -0
- package/dist/src/extensions/runner.js +251 -0
- package/dist/src/extensions/schema.d.ts +103 -0
- package/dist/src/extensions/schema.js +539 -0
- package/dist/src/extensions/session.d.ts +56 -0
- package/dist/src/extensions/session.js +173 -0
- package/dist/src/github/collect.d.ts +7 -2
- package/dist/src/github/collect.js +66 -6
- package/dist/src/github/gh.d.ts +7 -0
- package/dist/src/github/gh.js +24 -29
- package/dist/src/knowledge/guide.js +3 -2
- package/dist/src/knowledge/instruction_files.d.ts +45 -0
- package/dist/src/knowledge/instruction_files.js +91 -0
- package/dist/src/knowledge/instructions.d.ts +78 -0
- package/dist/src/knowledge/instructions.js +280 -0
- package/dist/src/knowledge/rule_changes.d.ts +39 -0
- package/dist/src/knowledge/rule_changes.js +90 -0
- package/dist/src/knowledge/rules.d.ts +44 -0
- package/dist/src/knowledge/rules.js +82 -0
- package/dist/src/knowledge/synthesis.d.ts +1 -0
- package/dist/src/knowledge/synthesis.js +12 -5
- package/dist/src/knowledge/types.d.ts +4 -0
- package/dist/src/local/carry_over_store.d.ts +10 -0
- package/dist/src/local/carry_over_store.js +17 -0
- package/dist/src/local/review_local.js +100 -62
- package/dist/src/local/review_lock.js +15 -4
- package/dist/src/pr/diff_plan.d.ts +110 -0
- package/dist/src/pr/diff_plan.js +429 -0
- package/dist/src/pr/diff_summary.d.ts +17 -1
- package/dist/src/pr/diff_summary.js +87 -13
- package/dist/src/pr/review_diff.d.ts +47 -0
- package/dist/src/pr/review_diff.js +112 -0
- package/dist/src/pr/reviewer.d.ts +44 -19
- package/dist/src/pr/reviewer.js +114 -142
- package/dist/src/remote/client.js +67 -8
- package/dist/src/remote/http.d.ts +12 -0
- package/dist/src/remote/http.js +31 -0
- package/dist/src/remote/push_client.js +14 -3
- package/dist/src/remote/server/guides.js +12 -1
- package/dist/src/remote/server/routes.js +4 -2
- package/dist/src/remote/server/sessions.js +4 -1
- package/dist/src/remote/validate.js +11 -0
- package/dist/src/review/carry_over.d.ts +6 -1
- package/dist/src/review/carry_over.js +10 -2
- package/dist/src/review/coverage.d.ts +57 -0
- package/dist/src/review/coverage.js +186 -0
- package/dist/src/review/diagram.d.ts +73 -0
- package/dist/src/review/diagram.js +309 -0
- package/dist/src/review/engine.d.ts +2 -6
- package/dist/src/review/engine.js +1 -1
- package/dist/src/review/guides.d.ts +6 -0
- package/dist/src/review/guides.js +8 -1
- package/dist/src/review/intent.d.ts +24 -0
- package/dist/src/review/intent.js +28 -0
- package/dist/src/review/not_initialized.d.ts +13 -0
- package/dist/src/review/not_initialized.js +18 -0
- package/dist/src/review/system_prompt.d.ts +6 -0
- package/dist/src/review/system_prompt.js +13 -0
- package/dist/src/review/visible_paths.d.ts +22 -0
- package/dist/src/review/visible_paths.js +41 -0
- package/dist/src/server/auth.js +8 -1
- package/dist/src/server/pages/extensions.d.ts +5 -0
- package/dist/src/server/pages/extensions.js +72 -0
- package/dist/src/server/pages/pr.js +3 -2
- package/dist/src/services/dashboard.d.ts +8 -0
- package/dist/src/services/dashboard.js +8 -0
- package/dist/src/services/push_review.js +14 -5
- package/dist/src/services/remote_review.js +81 -26
- package/dist/src/services/replies.js +15 -8
- package/dist/src/services/review.d.ts +9 -3
- package/dist/src/services/review.js +109 -28
- package/dist/src/services/rules_build.d.ts +46 -0
- package/dist/src/services/rules_build.js +155 -0
- package/dist/src/services/setup.d.ts +31 -0
- package/dist/src/services/setup.js +120 -25
- package/dist/src/services/watch_comments.js +2 -0
- package/dist/src/store/app_db.d.ts +3 -1
- package/dist/src/store/app_db.js +7 -2
- package/dist/src/store/cache_db.js +3 -0
- package/dist/src/store/extensions.d.ts +51 -0
- package/dist/src/store/extensions.js +132 -0
- package/dist/src/store/migrations.js +40 -0
- package/dist/src/types.d.ts +22 -1
- package/dist/src/util/atomic.d.ts +15 -1
- package/dist/src/util/atomic.js +59 -29
- package/dist/src/util/interrupt.d.ts +6 -0
- package/dist/src/util/interrupt.js +27 -0
- package/dist/src/util/runtime.d.ts +3 -1
- package/dist/src/util/runtime.js +2 -2
- package/dist/src/util/test_location_guard.d.ts +6 -0
- package/dist/src/util/test_location_guard.js +47 -0
- package/package.json +1 -1
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
import { appendFileSync } from "node:fs";
|
|
13
13
|
import { stripControlChars } from "../util/sanitize.js";
|
|
14
14
|
import { formatRunSummary } from "../util/run_summary.js";
|
|
15
|
-
import {
|
|
15
|
+
import { coverageLine, coverageMissing, notReviewedLines, } from "../review/coverage.js";
|
|
16
|
+
import { INTENT_LINE, humanShortTitle, sortHumanFindings, } from "./review_result.js";
|
|
17
|
+
import { extensionHumanFindings, jobSummaryWithExtensions, } from "../extensions/render_actions.js";
|
|
16
18
|
/** GitHub shows at most this many error and this many warning annotations per
|
|
17
19
|
* step and drops the rest without a word. */
|
|
18
20
|
export const MAX_ANNOTATIONS_PER_LEVEL = 10;
|
|
@@ -38,24 +40,41 @@ function annotation(row) {
|
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
const short = humanShortTitle(row);
|
|
41
|
-
properties.push(`title=${escapeProperty(
|
|
43
|
+
properties.push(`title=${escapeProperty(row.label
|
|
44
|
+
? `${row.label}: ${row.title}`
|
|
45
|
+
: short
|
|
46
|
+
? `${row.severity}: ${short}`
|
|
47
|
+
: `${row.severity} finding`)}`);
|
|
42
48
|
const level = row.blocking ? "error" : "warning";
|
|
43
49
|
return `::${level} ${properties.join(",")}::${escapeData(row.body || row.title)}`;
|
|
44
50
|
}
|
|
45
51
|
function active(findings) {
|
|
46
52
|
return sortHumanFindings(findings).filter((row) => row.state !== "closed");
|
|
47
53
|
}
|
|
54
|
+
/** One warning without a file when the diff plan dropped files, so a pull
|
|
55
|
+
* request shows that part of the change went unreviewed. */
|
|
56
|
+
function droppedAnnotation(coverage) {
|
|
57
|
+
const dropped = coverage?.dropped.length ?? 0;
|
|
58
|
+
if (dropped === 0)
|
|
59
|
+
return null;
|
|
60
|
+
const files = dropped === 1 ? "1 file was" : `${dropped} files were`;
|
|
61
|
+
return `::warning title=co-maintainer::${escapeData(`${files} not reviewed because the diff is too large. The job summary lists them.`)}`;
|
|
62
|
+
}
|
|
48
63
|
/** One workflow command per finding still standing, errors first. A finding
|
|
49
|
-
* that was closed since the last review needs no annotation.
|
|
50
|
-
|
|
64
|
+
* that was closed since the last review needs no annotation. The dropped
|
|
65
|
+
* files warning takes one of the warning slots. */
|
|
66
|
+
export function githubAnnotations(findings, coverage) {
|
|
51
67
|
const rows = active(findings);
|
|
52
68
|
const errors = rows.filter((row) => row.blocking);
|
|
53
69
|
const warnings = rows.filter((row) => !row.blocking);
|
|
70
|
+
const dropped = droppedAnnotation(coverage);
|
|
54
71
|
const shown = [
|
|
55
72
|
...errors.slice(0, MAX_ANNOTATIONS_PER_LEVEL),
|
|
56
|
-
...warnings.slice(0, MAX_ANNOTATIONS_PER_LEVEL),
|
|
73
|
+
...warnings.slice(0, MAX_ANNOTATIONS_PER_LEVEL - (dropped ? 1 : 0)),
|
|
57
74
|
];
|
|
58
75
|
const lines = shown.map(annotation);
|
|
76
|
+
if (dropped)
|
|
77
|
+
lines.push(dropped);
|
|
59
78
|
const left = rows.length - shown.length;
|
|
60
79
|
if (left > 0) {
|
|
61
80
|
lines.push(`::notice title=co-maintainer::${escapeData(`${left} more ${left === 1 ? "finding is" : "findings are"} not annotated, GitHub shows ${MAX_ANNOTATIONS_PER_LEVEL} errors and ${MAX_ANNOTATIONS_PER_LEVEL} warnings per step. The job summary lists all of them.`)}`);
|
|
@@ -78,17 +97,25 @@ function where(row) {
|
|
|
78
97
|
return cell(`${row.path}${span}`, 120);
|
|
79
98
|
}
|
|
80
99
|
export function githubSummary(input) {
|
|
81
|
-
const
|
|
82
|
-
const
|
|
100
|
+
const all = [...input.findings, ...extensionHumanFindings(input.extensions)];
|
|
101
|
+
const rows = active(all);
|
|
102
|
+
const closed = all.filter((row) => row.state === "closed").length;
|
|
83
103
|
const blocking = rows.filter((row) => row.blocking).length;
|
|
84
|
-
const lines = ["## co-maintainer review", "", cell(input.title, 200)
|
|
104
|
+
const lines = ["## co-maintainer review", "", cell(input.title, 200)];
|
|
105
|
+
if (input.intent)
|
|
106
|
+
lines.push("", INTENT_LINE);
|
|
107
|
+
lines.push("");
|
|
85
108
|
if (rows.length === 0) {
|
|
86
|
-
lines.push(
|
|
109
|
+
lines.push(input.coverage && coverageMissing(input.coverage) > 0
|
|
110
|
+
? "No actionable findings in the files reviewed."
|
|
111
|
+
: "No actionable findings.");
|
|
87
112
|
}
|
|
88
113
|
else {
|
|
89
114
|
lines.push("| Severity | State | Where | Finding |", "|---|---|---|---|");
|
|
90
115
|
for (const row of rows) {
|
|
91
|
-
const short =
|
|
116
|
+
const short = row.label
|
|
117
|
+
? `${row.label} ${row.title}`
|
|
118
|
+
: humanShortTitle(row);
|
|
92
119
|
const text = [short, row.body.split("\n")[0] ?? ""]
|
|
93
120
|
.filter(Boolean)
|
|
94
121
|
.join(": ");
|
|
@@ -96,9 +123,15 @@ export function githubSummary(input) {
|
|
|
96
123
|
}
|
|
97
124
|
}
|
|
98
125
|
lines.push("", `**Summary:** ${rows.filter((r) => r.state === "new").length} new · ${rows.filter((r) => r.state === "open").length} open · ${closed} closed · ${blocking} blocking`);
|
|
126
|
+
const coverage = coverageLine(input.coverage);
|
|
127
|
+
if (coverage)
|
|
128
|
+
lines.push("", cell(coverage, 200));
|
|
129
|
+
const notReviewed = notReviewedLines(input.coverage, input.catchesUp ?? false, (path) => cell(path, 200));
|
|
130
|
+
if (notReviewed.length > 0)
|
|
131
|
+
lines.push("", ...notReviewed);
|
|
99
132
|
if (input.run)
|
|
100
133
|
lines.push("", formatRunSummary(input.run));
|
|
101
|
-
return lines.join("\n");
|
|
134
|
+
return jobSummaryWithExtensions(lines.join("\n"), input.extensions);
|
|
102
135
|
}
|
|
103
136
|
/** Appends to `$GITHUB_STEP_SUMMARY` when it is set. A summary that cannot be
|
|
104
137
|
* written is reported on stderr and never fails the review. */
|
|
@@ -114,8 +147,12 @@ export function appendStepSummary(markdown, path = process.env.GITHUB_STEP_SUMMA
|
|
|
114
147
|
}
|
|
115
148
|
/** The whole `--output=github` output of one finished review. */
|
|
116
149
|
export function emitGithubOutput(input) {
|
|
117
|
-
|
|
150
|
+
// Only an extension finding with a location is annotated. The job summary
|
|
151
|
+
// lists the rest.
|
|
152
|
+
const located = extensionHumanFindings(input.extensions).filter((row) => row.path);
|
|
153
|
+
for (const line of githubAnnotations([...input.findings, ...located], input.coverage)) {
|
|
118
154
|
console.log(line);
|
|
155
|
+
}
|
|
119
156
|
appendStepSummary(githubSummary(input));
|
|
120
157
|
}
|
|
121
158
|
/** Progress lines that come from somewhere else (the server's job log) are
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { IntentRecord, IntentSource } from "../review/intent.ts";
|
|
2
|
+
/** The intent a run was given, trimmed. */
|
|
3
|
+
export type LoadedIntent = {
|
|
4
|
+
text: string;
|
|
5
|
+
source: IntentSource;
|
|
6
|
+
};
|
|
7
|
+
export type IntentLoad = {
|
|
8
|
+
/** `null` when the flag was not given, and when the text was empty. */
|
|
9
|
+
intent: LoadedIntent | null;
|
|
10
|
+
warnings: Array<{
|
|
11
|
+
code: string;
|
|
12
|
+
message: string;
|
|
13
|
+
}>;
|
|
14
|
+
};
|
|
15
|
+
/** Where `-` reads from. Standard input, unless a test hands in another. */
|
|
16
|
+
export type IntentInput = AsyncIterable<Buffer | string> & {
|
|
17
|
+
isTTY?: boolean;
|
|
18
|
+
};
|
|
19
|
+
/** What a result records about an intent: how it came in and how long it is,
|
|
20
|
+
* never the text. */
|
|
21
|
+
export declare function intentRecord(intent: LoadedIntent | null): IntentRecord | null;
|
|
22
|
+
/** Reads the flag's value. `die`s with exit 2 when the file cannot be read,
|
|
23
|
+
* when `-` meets a terminal, or when the text is over `limit`. An empty text
|
|
24
|
+
* is no intent and one `intent_empty` warning. */
|
|
25
|
+
export declare function loadIntentFlag(value: string | undefined, limit: number | null, input?: IntentInput): Promise<IntentLoad>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** `review --intent-file`: reads what the change is for, from a file or from
|
|
2
|
+
* standard input, and checks it against the repository's cap. */
|
|
3
|
+
import { createReadStream } from "node:fs";
|
|
4
|
+
import { StringDecoder } from "node:string_decoder";
|
|
5
|
+
import { die } from "./error.js";
|
|
6
|
+
import { checkReviewSystemPrompt } from "../review/system_prompt.js";
|
|
7
|
+
/** What a result records about an intent: how it came in and how long it is,
|
|
8
|
+
* never the text. */
|
|
9
|
+
export function intentRecord(intent) {
|
|
10
|
+
return intent ? { source: intent.source, chars: intent.text.length } : null;
|
|
11
|
+
}
|
|
12
|
+
/** A source that goes this far past the cap is over it for certain. A text a
|
|
13
|
+
* little past the cap is read to its end instead, so the error can say how long
|
|
14
|
+
* it is. Space around the text is dropped, but it still has to end somewhere,
|
|
15
|
+
* so raw text has a larger bound. */
|
|
16
|
+
const TEXT_SLACK = 65_536;
|
|
17
|
+
const RAW_SLACK = 1_000_000;
|
|
18
|
+
/** Reads `source` until it ends, or until the text is known to be over the
|
|
19
|
+
* cap, so a huge file or a device that never ends is a quick error and not an
|
|
20
|
+
* out-of-memory one. `complete` says the whole source was read. */
|
|
21
|
+
async function readBounded(source, limit) {
|
|
22
|
+
const decoder = new StringDecoder("utf8");
|
|
23
|
+
let text = "";
|
|
24
|
+
for await (const chunk of source) {
|
|
25
|
+
text += typeof chunk === "string" ? chunk : decoder.write(chunk);
|
|
26
|
+
if (limit !== null &&
|
|
27
|
+
(text.trim().length > limit + TEXT_SLACK ||
|
|
28
|
+
text.length > limit + RAW_SLACK)) {
|
|
29
|
+
return { text, complete: false };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return { text: text + decoder.end(), complete: true };
|
|
33
|
+
}
|
|
34
|
+
/** Reads the flag's value. `die`s with exit 2 when the file cannot be read,
|
|
35
|
+
* when `-` meets a terminal, or when the text is over `limit`. An empty text
|
|
36
|
+
* is no intent and one `intent_empty` warning. */
|
|
37
|
+
export async function loadIntentFlag(value, limit, input = process.stdin) {
|
|
38
|
+
if (value === undefined)
|
|
39
|
+
return { intent: null, warnings: [] };
|
|
40
|
+
if (value === "") {
|
|
41
|
+
die("--intent-file: give a path, or - to read standard input");
|
|
42
|
+
}
|
|
43
|
+
let read;
|
|
44
|
+
let source;
|
|
45
|
+
if (value === "-") {
|
|
46
|
+
source = "stdin";
|
|
47
|
+
// A terminal never ends its input, so reading it would wait forever.
|
|
48
|
+
if (input.isTTY === true) {
|
|
49
|
+
die("--intent-file=-: nothing on standard input");
|
|
50
|
+
}
|
|
51
|
+
read = await readBounded(input, limit);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
source = "file";
|
|
55
|
+
const stream = createReadStream(value);
|
|
56
|
+
try {
|
|
57
|
+
read = await readBounded(stream, limit);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
die(`--intent-file: could not read ${value}: ${String(error)}`);
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
stream.destroy();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const text = read.text.trim();
|
|
67
|
+
if (!read.complete) {
|
|
68
|
+
// Only the start of the source was read, which is enough to know it is
|
|
69
|
+
// over the cap but not by how much.
|
|
70
|
+
die(`--intent-file: must be at most ${limit} characters (got more than ${limit})`);
|
|
71
|
+
}
|
|
72
|
+
if (text === "") {
|
|
73
|
+
return {
|
|
74
|
+
intent: null,
|
|
75
|
+
warnings: [
|
|
76
|
+
{
|
|
77
|
+
code: "intent_empty",
|
|
78
|
+
message: "The intent is empty, so the review ran without one.",
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const problem = checkReviewSystemPrompt(text, limit);
|
|
84
|
+
if (problem)
|
|
85
|
+
die(`--intent-file: ${problem}`);
|
|
86
|
+
return { intent: { text, source }, warnings: [] };
|
|
87
|
+
}
|
|
@@ -2,11 +2,17 @@ import { type ParsedFinding } from "../pr/findings.ts";
|
|
|
2
2
|
import { type ResolvedFinding } from "../review/carry_over.ts";
|
|
3
3
|
import { type ReviewBlocking } from "../review/blocking.ts";
|
|
4
4
|
import type { Revision } from "../review/revision.ts";
|
|
5
|
+
import type { IntentRecord } from "../review/intent.ts";
|
|
6
|
+
import { type Coverage } from "../review/coverage.ts";
|
|
5
7
|
import type { BilledTo, CostReason, CostStatus } from "../util/cost.ts";
|
|
8
|
+
import type { ExtensionReport } from "../extensions/report.ts";
|
|
6
9
|
export type ReviewWarning = {
|
|
7
10
|
code: string;
|
|
8
11
|
message: string;
|
|
9
12
|
};
|
|
13
|
+
/** The line a review prints, in the terminal and in the job summary, when it
|
|
14
|
+
* was given an intent. */
|
|
15
|
+
export declare const INTENT_LINE = "Intent file: provided";
|
|
10
16
|
export type JsonReviewFinding = {
|
|
11
17
|
id: string;
|
|
12
18
|
state: "new" | "open" | "closed";
|
|
@@ -30,11 +36,28 @@ export declare function resolvedFromFirstReview(parsed: ParsedFinding[], filesBy
|
|
|
30
36
|
}>): ResolvedFinding[];
|
|
31
37
|
export declare function sortResolvedFindings(findings: ResolvedFinding[]): ResolvedFinding[];
|
|
32
38
|
export declare function toJsonFinding(row: ResolvedFinding, mode?: ReviewBlocking): JsonReviewFinding;
|
|
33
|
-
export
|
|
39
|
+
export type RevisionJson = {
|
|
34
40
|
files: number;
|
|
35
41
|
additions: number;
|
|
36
42
|
deletions: number;
|
|
37
43
|
truncated: boolean;
|
|
44
|
+
coverage: Coverage;
|
|
45
|
+
};
|
|
46
|
+
/** File and line counts when there is no `Revision` at hand, as in a pull
|
|
47
|
+
* request review that read GitHub's file list. */
|
|
48
|
+
export type DiffStats = {
|
|
49
|
+
files: number;
|
|
50
|
+
additions: number;
|
|
51
|
+
deletions: number;
|
|
52
|
+
};
|
|
53
|
+
/** The `revision` block. Without a coverage, as when no review ran, every
|
|
54
|
+
* file counts as full. */
|
|
55
|
+
export declare function revisionStats(revision: Revision | DiffStats, coverage?: Coverage): RevisionJson;
|
|
56
|
+
/** The `revision` and `warnings` pair every review result carries: local,
|
|
57
|
+
* CLI PR, remote and push. Warning lists are joined in the order given. */
|
|
58
|
+
export declare function reviewCoverageFields(revision: Revision | DiffStats, coverage: Coverage | undefined, ...warnings: ReviewWarning[][]): {
|
|
59
|
+
revision: RevisionJson;
|
|
60
|
+
warnings: ReviewWarning[];
|
|
38
61
|
};
|
|
39
62
|
export declare function summaryCounts(findings: ResolvedFinding[], mode?: ReviewBlocking): {
|
|
40
63
|
new: number;
|
|
@@ -60,6 +83,8 @@ export type HumanFinding = {
|
|
|
60
83
|
lineTo: number;
|
|
61
84
|
text: string;
|
|
62
85
|
} | null;
|
|
86
|
+
/** An extension finding's `[P2 · blocking] · extension: name`. */
|
|
87
|
+
label?: string;
|
|
63
88
|
};
|
|
64
89
|
/** Local and PR findings: blocking is decided here from the configured rule,
|
|
65
90
|
* exactly as the exit code decides it. */
|
|
@@ -88,6 +113,13 @@ export type HumanReviewInput = {
|
|
|
88
113
|
codegraphState: "used" | "disabled" | "unavailable" | null;
|
|
89
114
|
findings: HumanFinding[];
|
|
90
115
|
warnings?: ReviewWarning[];
|
|
116
|
+
/** What the model received. Left out by a remote server older than this
|
|
117
|
+
* field, and then no coverage line is printed. */
|
|
118
|
+
coverage?: Coverage;
|
|
119
|
+
/** The extensions' results. Absent or empty prints nothing extra. */
|
|
120
|
+
extensions?: ExtensionReport;
|
|
121
|
+
/** An intent file was given. The line says so and never shows the text. */
|
|
122
|
+
intent?: boolean;
|
|
91
123
|
};
|
|
92
124
|
/** The single human-readable review format. Local,
|
|
93
125
|
* PR and remote reviews print this: a header naming the guide build date and
|
|
@@ -98,7 +130,7 @@ export type HumanReviewInput = {
|
|
|
98
130
|
* stay in the GitHub comment, which is a different reader. */
|
|
99
131
|
export declare function formatHumanReview(input: HumanReviewInput): string;
|
|
100
132
|
/** Local review output: the shared format plus the working-tree file stats. */
|
|
101
|
-
export declare function formatHumanLocalReview(header: string, revision: Revision, guideBuiltAt: string | null, codegraphState: "used" | "disabled" | "unavailable", findings: ResolvedFinding[], warnings: ReviewWarning[], mode?: ReviewBlocking): string;
|
|
133
|
+
export declare function formatHumanLocalReview(header: string, revision: Revision, guideBuiltAt: string | null, codegraphState: "used" | "disabled" | "unavailable", findings: ResolvedFinding[], warnings: ReviewWarning[], mode?: ReviewBlocking, coverage?: Coverage, extensions?: ExtensionReport, intent?: boolean): string;
|
|
102
134
|
/** The exit code for a remote review. The server already decided
|
|
103
135
|
* each finding's `blocking` under its own configured rule, so the client
|
|
104
136
|
* trusts that field instead of re-deriving the rule from a title: the client
|
|
@@ -127,17 +159,36 @@ export type LocalReviewJsonInput = {
|
|
|
127
159
|
usage: ReviewUsage;
|
|
128
160
|
durationMs: number;
|
|
129
161
|
reviewBlocking?: ReviewBlocking;
|
|
162
|
+
coverage?: Coverage;
|
|
163
|
+
extensions?: ExtensionReport;
|
|
164
|
+
includeExtensionMarkdowns?: boolean;
|
|
165
|
+
/** `subject.intent`: how the intent came in. Left out of the result when
|
|
166
|
+
* none was given, so a review without the flag prints the result it always
|
|
167
|
+
* printed. */
|
|
168
|
+
intent?: IntentRecord | null;
|
|
130
169
|
};
|
|
131
170
|
export type PrReviewJsonInput = {
|
|
132
171
|
repo: string;
|
|
133
172
|
prNumber: number;
|
|
134
173
|
markdown: string;
|
|
174
|
+
/** The findings with their `new`, `open` and `closed` state. Without them
|
|
175
|
+
* every finding in `markdown` counts as new. */
|
|
176
|
+
findings?: ResolvedFinding[];
|
|
177
|
+
warnings?: ReviewWarning[];
|
|
135
178
|
guideBuiltAt: string | null;
|
|
136
179
|
codegraphState: "used" | "disabled" | "unavailable";
|
|
137
180
|
codegraphReason: string | null;
|
|
138
181
|
usage: ReviewUsage;
|
|
139
182
|
durationMs: number;
|
|
140
183
|
reviewBlocking?: ReviewBlocking;
|
|
184
|
+
diffStats?: DiffStats;
|
|
185
|
+
coverage?: Coverage;
|
|
186
|
+
extensions?: ExtensionReport;
|
|
187
|
+
includeExtensionMarkdowns?: boolean;
|
|
188
|
+
/** `subject.intent`: how the intent came in. Left out of the result when
|
|
189
|
+
* none was given, so a review without the flag prints the result it always
|
|
190
|
+
* printed. */
|
|
191
|
+
intent?: IntentRecord | null;
|
|
141
192
|
};
|
|
142
193
|
export declare function buildPrReviewJson(input: PrReviewJsonInput): string;
|
|
143
194
|
export declare function buildLocalReviewJson(input: LocalReviewJsonInput): string;
|
|
@@ -3,7 +3,13 @@ import { readSuggestion, stripSuggestion } from "../pr/suggestion.js";
|
|
|
3
3
|
import { stripControlChars } from "../util/sanitize.js";
|
|
4
4
|
import { anchorTextFromPatch, } from "../review/carry_over.js";
|
|
5
5
|
import { DEFAULT_REVIEW_BLOCKING, isBlocking, } from "../review/blocking.js";
|
|
6
|
+
import { coverageLine, coverageMissing, coverageTruncated, fullCoverage, } from "../review/coverage.js";
|
|
6
7
|
import { humanCopy } from "../services/review.js";
|
|
8
|
+
import { withExtensionsJson } from "../extensions/render_json.js";
|
|
9
|
+
import { cliExtensionFooter, cliExtensionLines, extensionCounts, } from "../extensions/render_cli.js";
|
|
10
|
+
/** The line a review prints, in the terminal and in the job summary, when it
|
|
11
|
+
* was given an intent. */
|
|
12
|
+
export const INTENT_LINE = "Intent file: provided";
|
|
7
13
|
const SEVERITY_RANK = {
|
|
8
14
|
P0: 0,
|
|
9
15
|
P1: 1,
|
|
@@ -74,18 +80,34 @@ export function toJsonFinding(row, mode = DEFAULT_REVIEW_BLOCKING) {
|
|
|
74
80
|
: null,
|
|
75
81
|
};
|
|
76
82
|
}
|
|
77
|
-
|
|
83
|
+
function statsOf(revision) {
|
|
84
|
+
if (!Array.isArray(revision.files))
|
|
85
|
+
return revision;
|
|
78
86
|
let additions = 0;
|
|
79
87
|
let deletions = 0;
|
|
80
88
|
for (const file of revision.files) {
|
|
81
89
|
additions += file.additions;
|
|
82
90
|
deletions += file.deletions;
|
|
83
91
|
}
|
|
92
|
+
return { files: revision.files.length, additions, deletions };
|
|
93
|
+
}
|
|
94
|
+
/** The `revision` block. Without a coverage, as when no review ran, every
|
|
95
|
+
* file counts as full. */
|
|
96
|
+
export function revisionStats(revision, coverage) {
|
|
97
|
+
const stats = statsOf(revision);
|
|
98
|
+
const covered = coverage ?? fullCoverage(stats.files);
|
|
99
|
+
return {
|
|
100
|
+
...stats,
|
|
101
|
+
truncated: coverageTruncated(covered),
|
|
102
|
+
coverage: covered,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** The `revision` and `warnings` pair every review result carries: local,
|
|
106
|
+
* CLI PR, remote and push. Warning lists are joined in the order given. */
|
|
107
|
+
export function reviewCoverageFields(revision, coverage, ...warnings) {
|
|
84
108
|
return {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
deletions,
|
|
88
|
-
truncated: false,
|
|
109
|
+
revision: revisionStats(revision, coverage),
|
|
110
|
+
warnings: warnings.flat(),
|
|
89
111
|
};
|
|
90
112
|
}
|
|
91
113
|
export function summaryCounts(findings, mode = DEFAULT_REVIEW_BLOCKING) {
|
|
@@ -205,7 +227,10 @@ export function formatHumanReview(input) {
|
|
|
205
227
|
? "codegraph unavailable"
|
|
206
228
|
: "codegraph unknown";
|
|
207
229
|
const meta = [input.stats, guideBit, cgBit].filter(Boolean).join(" · ");
|
|
208
|
-
const lines = [input.title, meta
|
|
230
|
+
const lines = [input.title, meta];
|
|
231
|
+
if (input.intent)
|
|
232
|
+
lines.push(INTENT_LINE);
|
|
233
|
+
lines.push("");
|
|
209
234
|
const sorted = sortHumanFindings(input.findings);
|
|
210
235
|
const groups = [
|
|
211
236
|
{ label: "Closed", state: "closed", bullet: "✓" },
|
|
@@ -242,26 +267,47 @@ export function formatHumanReview(input) {
|
|
|
242
267
|
}
|
|
243
268
|
lines.push("");
|
|
244
269
|
}
|
|
245
|
-
|
|
246
|
-
|
|
270
|
+
const extensionLines = input.extensions
|
|
271
|
+
? cliExtensionLines(input.extensions)
|
|
272
|
+
: [];
|
|
273
|
+
if (!any && (input.extensions?.findings.length ?? 0) === 0) {
|
|
274
|
+
// With files the model never received, "no findings" speaks only for
|
|
275
|
+
// the rest.
|
|
276
|
+
lines.push(input.coverage && coverageMissing(input.coverage) > 0
|
|
277
|
+
? "No actionable findings in the files reviewed."
|
|
278
|
+
: "No actionable findings.");
|
|
247
279
|
lines.push("");
|
|
248
280
|
}
|
|
281
|
+
if (extensionLines.length > 0)
|
|
282
|
+
lines.push(...extensionLines, "");
|
|
283
|
+
const extra = input.extensions
|
|
284
|
+
? extensionCounts(input.extensions)
|
|
285
|
+
: { new: 0, open: 0, closed: 0, blocking: 0 };
|
|
249
286
|
const counts = {
|
|
250
|
-
new: sorted.filter((f) => f.state === "new").length,
|
|
251
|
-
open: sorted.filter((f) => f.state === "open").length,
|
|
252
|
-
closed: sorted.filter((f) => f.state === "closed").length,
|
|
253
|
-
blocking: sorted.filter((f) => (f.state === "new" || f.state === "open") && f.blocking).length,
|
|
287
|
+
new: sorted.filter((f) => f.state === "new").length + extra.new,
|
|
288
|
+
open: sorted.filter((f) => f.state === "open").length + extra.open,
|
|
289
|
+
closed: sorted.filter((f) => f.state === "closed").length + extra.closed,
|
|
290
|
+
blocking: sorted.filter((f) => (f.state === "new" || f.state === "open") && f.blocking).length + extra.blocking,
|
|
254
291
|
};
|
|
255
292
|
lines.push(`Summary: ${counts.new} new · ${counts.open} open · ${counts.closed} closed · ${counts.blocking} blocking`);
|
|
293
|
+
const coverage = coverageLine(input.coverage);
|
|
294
|
+
if (coverage)
|
|
295
|
+
lines.push(coverage);
|
|
296
|
+
if (extensionLines.length > 0) {
|
|
297
|
+
lines.push(cliExtensionFooter(input.extensions));
|
|
298
|
+
}
|
|
256
299
|
if (input.warnings?.length) {
|
|
257
300
|
lines.push("Warnings:");
|
|
258
|
-
|
|
259
|
-
|
|
301
|
+
// A diff warning can name a file, and a pull request's author chooses
|
|
302
|
+
// file names.
|
|
303
|
+
for (const w of input.warnings) {
|
|
304
|
+
lines.push(` - ${stripControlChars(w.message)}`);
|
|
305
|
+
}
|
|
260
306
|
}
|
|
261
307
|
return lines.join("\n");
|
|
262
308
|
}
|
|
263
309
|
/** Local review output: the shared format plus the working-tree file stats. */
|
|
264
|
-
export function formatHumanLocalReview(header, revision, guideBuiltAt, codegraphState, findings, warnings, mode = DEFAULT_REVIEW_BLOCKING) {
|
|
310
|
+
export function formatHumanLocalReview(header, revision, guideBuiltAt, codegraphState, findings, warnings, mode = DEFAULT_REVIEW_BLOCKING, coverage, extensions, intent) {
|
|
265
311
|
const stats = revisionStats(revision);
|
|
266
312
|
return formatHumanReview({
|
|
267
313
|
title: header,
|
|
@@ -270,6 +316,9 @@ export function formatHumanLocalReview(header, revision, guideBuiltAt, codegraph
|
|
|
270
316
|
codegraphState,
|
|
271
317
|
findings: humanFindingsFromResolved(findings, mode),
|
|
272
318
|
warnings,
|
|
319
|
+
coverage,
|
|
320
|
+
extensions,
|
|
321
|
+
intent,
|
|
273
322
|
});
|
|
274
323
|
}
|
|
275
324
|
/** The exit code for a remote review. The server already decided
|
|
@@ -279,15 +328,27 @@ export function formatHumanLocalReview(header, revision, guideBuiltAt, codegraph
|
|
|
279
328
|
export function reviewExitCodeFromJsonFindings(findings) {
|
|
280
329
|
return findings.some((f) => f.blocking) ? 1 : 0;
|
|
281
330
|
}
|
|
331
|
+
/** The review JSON with the extensions joined in, serialised. */
|
|
332
|
+
function jsonWithExtensions(input, doc) {
|
|
333
|
+
return JSON.stringify(withExtensionsJson(doc, input.extensions, input.includeExtensionMarkdowns ?? false));
|
|
334
|
+
}
|
|
282
335
|
export function buildPrReviewJson(input) {
|
|
283
336
|
const mode = input.reviewBlocking ?? DEFAULT_REVIEW_BLOCKING;
|
|
284
|
-
const findings =
|
|
337
|
+
const findings = input.findings ??
|
|
338
|
+
resolvedFromFirstReview(parseFindings(input.markdown), new Map());
|
|
285
339
|
const sorted = sortResolvedFindings(findings);
|
|
286
|
-
|
|
340
|
+
const { revision, warnings } = reviewCoverageFields(input.diffStats ?? { files: 0, additions: 0, deletions: 0 }, input.coverage, input.warnings ?? []);
|
|
341
|
+
return jsonWithExtensions(input, {
|
|
287
342
|
schemaVersion: 1,
|
|
288
343
|
ok: true,
|
|
289
344
|
mode: "pr",
|
|
290
|
-
subject: {
|
|
345
|
+
subject: {
|
|
346
|
+
repo: input.repo,
|
|
347
|
+
branch: null,
|
|
348
|
+
prNumber: input.prNumber,
|
|
349
|
+
...(input.intent ? { intent: input.intent } : {}),
|
|
350
|
+
},
|
|
351
|
+
revision,
|
|
291
352
|
guide: { builtAt: input.guideBuiltAt },
|
|
292
353
|
codegraph: {
|
|
293
354
|
state: input.codegraphState,
|
|
@@ -295,7 +356,7 @@ export function buildPrReviewJson(input) {
|
|
|
295
356
|
},
|
|
296
357
|
summary: summaryCounts(findings, mode),
|
|
297
358
|
findings: sorted.map((row) => toJsonFinding(row, mode)),
|
|
298
|
-
warnings
|
|
359
|
+
warnings,
|
|
299
360
|
usage: input.usage,
|
|
300
361
|
durationMs: input.durationMs,
|
|
301
362
|
});
|
|
@@ -303,13 +364,19 @@ export function buildPrReviewJson(input) {
|
|
|
303
364
|
export function buildLocalReviewJson(input) {
|
|
304
365
|
const mode = input.reviewBlocking ?? DEFAULT_REVIEW_BLOCKING;
|
|
305
366
|
const sorted = sortResolvedFindings(input.findings);
|
|
306
|
-
|
|
367
|
+
const { revision, warnings } = reviewCoverageFields(input.revision, input.coverage, input.warnings);
|
|
368
|
+
return jsonWithExtensions(input, {
|
|
307
369
|
schemaVersion: 1,
|
|
308
370
|
ok: true,
|
|
309
371
|
mode: "local",
|
|
310
|
-
subject: {
|
|
372
|
+
subject: {
|
|
373
|
+
repo: input.repo,
|
|
374
|
+
branch: input.branch,
|
|
375
|
+
prNumber: null,
|
|
376
|
+
...(input.intent ? { intent: input.intent } : {}),
|
|
377
|
+
},
|
|
311
378
|
base: { toBranch: input.baseLabel, label: input.baseLabel },
|
|
312
|
-
revision
|
|
379
|
+
revision,
|
|
313
380
|
guide: { builtAt: input.guideBuiltAt },
|
|
314
381
|
codegraph: {
|
|
315
382
|
state: input.codegraphState,
|
|
@@ -317,7 +384,7 @@ export function buildLocalReviewJson(input) {
|
|
|
317
384
|
},
|
|
318
385
|
summary: summaryCounts(input.findings, mode),
|
|
319
386
|
findings: sorted.map((row) => toJsonFinding(row, mode)),
|
|
320
|
-
warnings
|
|
387
|
+
warnings,
|
|
321
388
|
usage: input.usage,
|
|
322
389
|
durationMs: input.durationMs,
|
|
323
390
|
});
|
package/dist/src/config.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Platform } from "./util/runtime.ts";
|
|
2
|
+
import type { ExtensionRegistration } from "./extensions/registry.ts";
|
|
2
3
|
/** Everything init/remake resolved for one repo, except secrets — an API
|
|
3
4
|
* token is never written to config.json, only ever taken from --token or
|
|
4
5
|
* an env file. Remembering this lets `remake owner/repo` run with no
|
|
@@ -23,6 +24,12 @@ export type RepoConfig = {
|
|
|
23
24
|
includeHowRepoWorks?: boolean;
|
|
24
25
|
onlyRequestChangedPr?: boolean;
|
|
25
26
|
prState?: ("open" | "closed" | "merged")[];
|
|
27
|
+
/** The regex that finds the agent instruction files. Blank turns
|
|
28
|
+
* `INSTRUCTIONS.md` off, unset means the default. */
|
|
29
|
+
agentInstructions?: string;
|
|
30
|
+
/** Cap on `INSTRUCTIONS.md` in characters. Unset means the default, `0` or
|
|
31
|
+
* a negative number means no limit. */
|
|
32
|
+
agentInstructionsMaxChars?: number;
|
|
26
33
|
/** Five field cron in UTC, checked by `serve` to queue a remake. */
|
|
27
34
|
remakeCron?: string;
|
|
28
35
|
/** A rejected custom schedule kept only so the settings form can show what
|
|
@@ -38,6 +45,17 @@ export type RepoConfig = {
|
|
|
38
45
|
/** Cap on `reviewSystemPrompt` in characters for this repository. Unset
|
|
39
46
|
* means the default; `0` or a negative number means no limit. */
|
|
40
47
|
reviewSystemPromptMaxChars?: number;
|
|
48
|
+
/** Which diagram language this repository's reviews use. Unset means
|
|
49
|
+
* `mermaid`. `set --repo` writes it, so App reviews can use it too. */
|
|
50
|
+
diagramRuntime?: "mermaid" | "plantuml" | "plantuml-server";
|
|
51
|
+
/** The PlantUML server `plantuml-server` links to. Unset means the public
|
|
52
|
+
* one. */
|
|
53
|
+
plantumlServer?: string;
|
|
54
|
+
/** `svg` or `png`. Unset means `svg`. */
|
|
55
|
+
plantumlOutputFormat?: "svg" | "png";
|
|
56
|
+
/** Cap on one `read-full-diff` answer in characters for this repository.
|
|
57
|
+
* Unset means the default; `0` or a negative number means no limit. */
|
|
58
|
+
reviewReadDiffMaxChars?: number;
|
|
41
59
|
};
|
|
42
60
|
export type UserConfig = {
|
|
43
61
|
auth?: "gh" | "pat";
|
|
@@ -71,6 +89,9 @@ export type UserConfig = {
|
|
|
71
89
|
githubAuthEnabled?: boolean;
|
|
72
90
|
/** scrypt hash of the dashboard password, never the password itself. */
|
|
73
91
|
dashboardPasswordHash?: string;
|
|
92
|
+
/** When `set` last changed a sign-in credential. Dashboard sessions issued
|
|
93
|
+
* before it are refused. */
|
|
94
|
+
credentialsChangedAt?: string;
|
|
74
95
|
defaults?: {
|
|
75
96
|
maxCommits?: number;
|
|
76
97
|
maxPrMonths?: number;
|
|
@@ -116,6 +137,12 @@ export type UserConfig = {
|
|
|
116
137
|
* `--no-remote-byok` turns it off for one run without unsetting this. */
|
|
117
138
|
remoteByokDefault?: boolean;
|
|
118
139
|
repos?: Record<string, RepoConfig>;
|
|
140
|
+
/** Registered extensions, oldest first. Only `co-maintainer extension`
|
|
141
|
+
* writes it. */
|
|
142
|
+
extensions?: ExtensionRegistration[];
|
|
143
|
+
/** Whether an extension that was running when co-maintainer restarted runs
|
|
144
|
+
* again. Unset means it does. A registration's own value wins. */
|
|
145
|
+
extensionRerunOnRestart?: boolean;
|
|
119
146
|
};
|
|
120
147
|
export type ByokPolicy = "off" | "allow" | "require";
|
|
121
148
|
/** The provider's own key variable. It is read only when that provider runs,
|
|
@@ -178,6 +205,9 @@ export declare function cacheDbPath(): string;
|
|
|
178
205
|
* `uninstall` still takes them: they are co-maintainer data too. */
|
|
179
206
|
export declare function locksDir(): string;
|
|
180
207
|
export declare function loadEnvFile(path: string): void;
|
|
208
|
+
/** No retry on a parse error: every write replaces the file whole, so a file
|
|
209
|
+
* that does not parse is broken, not half written, and reading it again would
|
|
210
|
+
* give the same answer. */
|
|
181
211
|
export declare function readConfig(): UserConfig;
|
|
182
212
|
/** The App private key to sign with. An inline `githubAppPrivateKey` wins,
|
|
183
213
|
* then the file named by `githubAppPrivateKeyPath`. Reading the file here
|