co-maintainer 0.6.13 → 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 +70 -2
- 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 +27 -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/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/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
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/** The extensions in Markdown: the `#### Extensions` section of a GitHub review
|
|
2
|
+
* and of a job summary, and the length limits both live under.
|
|
3
|
+
*
|
|
4
|
+
* Only an extension's `markdown` can be dropped for length. The AI review, the
|
|
5
|
+
* verdict, the inline comments and the stored result always stay. The longest
|
|
6
|
+
* `markdown` goes first, then the next longest, until the text fits. */
|
|
7
|
+
import { stripControlChars } from "../util/sanitize.js";
|
|
8
|
+
/** GitHub accepted a 250,000 character review body. */
|
|
9
|
+
export const REVIEW_BODY_MAX_CHARS = 250_000;
|
|
10
|
+
/** The job summary limit reported for one step. Measured in bytes. */
|
|
11
|
+
export const JOB_SUMMARY_MAX_BYTES = 1024 * 1024;
|
|
12
|
+
export const REVIEW_LIMIT_NOTE = "Not added to this comment because of the length limit, see the dashboard.";
|
|
13
|
+
export const JOB_SUMMARY_LIMIT_NOTE = "Not added to the job summary because of the length limit.";
|
|
14
|
+
export function utf8Bytes(text) {
|
|
15
|
+
return Buffer.byteLength(text, "utf8");
|
|
16
|
+
}
|
|
17
|
+
/** Closes a fence left open, so it cannot swallow what follows it. */
|
|
18
|
+
export function closeFences(text) {
|
|
19
|
+
const fences = text
|
|
20
|
+
.split("\n")
|
|
21
|
+
.filter((line) => /^\s*(?:```|~~~)/.test(line));
|
|
22
|
+
return fences.length % 2 === 1 ? `${text.trimEnd()}\n\`\`\`` : text;
|
|
23
|
+
}
|
|
24
|
+
/** A name inside `<summary>`: no tag can open or close there. */
|
|
25
|
+
function summaryName(name) {
|
|
26
|
+
return stripControlChars(name).replace(/[<>&]/g, "");
|
|
27
|
+
}
|
|
28
|
+
/** The titles of the sections a review body is made of. A heading in an
|
|
29
|
+
* extension's `markdown` with one of these names could pass for a
|
|
30
|
+
* co-maintainer section. */
|
|
31
|
+
const SECTION_TITLES = [
|
|
32
|
+
"extensions",
|
|
33
|
+
"extension findings",
|
|
34
|
+
"review summary",
|
|
35
|
+
"metadata",
|
|
36
|
+
"new",
|
|
37
|
+
"still open",
|
|
38
|
+
"closed",
|
|
39
|
+
"not reviewed",
|
|
40
|
+
"coverage",
|
|
41
|
+
];
|
|
42
|
+
/** An extension's `markdown` made unable to leave the `<details>` block
|
|
43
|
+
* co-maintainer puts it in, or to forge a co-maintainer section. What it
|
|
44
|
+
* prints is shaped by a stranger's pull request. Mentions and images stay:
|
|
45
|
+
* they are the extension owner's responsibility. */
|
|
46
|
+
export function containMarkdown(markdown) {
|
|
47
|
+
return closeFences(markdown
|
|
48
|
+
.replace(/<(\/?)(details|summary)\b/gi, "<$1$2")
|
|
49
|
+
.split("\n")
|
|
50
|
+
.map((line) => {
|
|
51
|
+
const heading = line.match(/^(\s{0,3})(#{1,6})(\s+)(.*)$/);
|
|
52
|
+
if (!heading)
|
|
53
|
+
return line;
|
|
54
|
+
const title = heading[4].replace(/[#\s]+$/, "").toLowerCase();
|
|
55
|
+
const own = SECTION_TITLES.some((name) => title === name || title.startsWith(`${name} (`));
|
|
56
|
+
return own
|
|
57
|
+
? `${heading[1]}\\${heading[2]}${heading[3]}${heading[4]}`
|
|
58
|
+
: line;
|
|
59
|
+
})
|
|
60
|
+
.join("\n"));
|
|
61
|
+
}
|
|
62
|
+
/** The `#### Extensions` section from each extension's `markdown`, or "" when
|
|
63
|
+
* no extension sent any. `markdowns` holds what is shown, which the length
|
|
64
|
+
* limit may have replaced. */
|
|
65
|
+
export function extensionsSection(report, markdowns) {
|
|
66
|
+
const blocks = report.results
|
|
67
|
+
.filter((result) => markdowns.has(result.name))
|
|
68
|
+
.map((result) => `<details><summary>${summaryName(result.name)}</summary>\n\n${containMarkdown(markdowns.get(result.name).trim())}\n\n</details>`);
|
|
69
|
+
if (blocks.length === 0)
|
|
70
|
+
return "";
|
|
71
|
+
return `#### Extensions\n\n${blocks.join("\n\n")}`;
|
|
72
|
+
}
|
|
73
|
+
/** Renders with every extension's `markdown`, then replaces the longest one
|
|
74
|
+
* with `note` until `measure` fits `limit`. */
|
|
75
|
+
export function fitMarkdowns(report, render, limit, measure, note) {
|
|
76
|
+
const markdowns = new Map(report.results
|
|
77
|
+
.filter((result) => result.markdown.trim() !== "")
|
|
78
|
+
.map((result) => [result.name, result.markdown]));
|
|
79
|
+
let text = render(markdowns);
|
|
80
|
+
while (measure(text) > limit) {
|
|
81
|
+
let longest;
|
|
82
|
+
for (const [name, markdown] of markdowns) {
|
|
83
|
+
if (markdown === note)
|
|
84
|
+
continue;
|
|
85
|
+
if (longest === undefined ||
|
|
86
|
+
measure(markdown) > measure(markdowns.get(longest))) {
|
|
87
|
+
longest = name;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (longest === undefined)
|
|
91
|
+
break;
|
|
92
|
+
markdowns.set(longest, note);
|
|
93
|
+
text = render(markdowns);
|
|
94
|
+
}
|
|
95
|
+
return text;
|
|
96
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Json } from "../types.ts";
|
|
2
|
+
import { type ExtensionFinding, type ExtensionReport } from "./report.ts";
|
|
3
|
+
/** The copy rule every posted text passes through (`humanCopy`). Passed in so
|
|
4
|
+
* this file does not import the review service that imports it. */
|
|
5
|
+
export type Copy = (text: string) => string;
|
|
6
|
+
export type InlineComment = {
|
|
7
|
+
path: string;
|
|
8
|
+
body: string;
|
|
9
|
+
line: number;
|
|
10
|
+
side: "RIGHT";
|
|
11
|
+
start_line?: number;
|
|
12
|
+
start_side?: "RIGHT";
|
|
13
|
+
};
|
|
14
|
+
/** At most this many extension comments go inline in one review. The rest
|
|
15
|
+
* join the summary list. A linter run over a generated pull request can
|
|
16
|
+
* return thousands, and GitHub refuses a review that size. */
|
|
17
|
+
export declare const MAX_INLINE_EXTENSION_COMMENTS = 50;
|
|
18
|
+
/** At most this many extension findings are listed in the summary, then one
|
|
19
|
+
* "and N more" line points at the dashboard, which keeps every one. */
|
|
20
|
+
export declare const MAX_LISTED_EXTENSION_FINDINGS = 50;
|
|
21
|
+
/** A title is one line in a list: longer ones are cut. */
|
|
22
|
+
export declare const MAX_TITLE_CHARS = 200;
|
|
23
|
+
/** An inline comment's body past this is cut. */
|
|
24
|
+
export declare const MAX_INLINE_BODY_CHARS = 4000;
|
|
25
|
+
/** Text cut to `max` characters, ending in an ellipsis when it was cut. */
|
|
26
|
+
export declare function cut(text: string, max: number): string;
|
|
27
|
+
/** Splits the findings still standing into inline comments and the ones the
|
|
28
|
+
* summary lists. Only a finding new this round goes inline: a still open one
|
|
29
|
+
* was commented on when it was new. */
|
|
30
|
+
export declare function splitExtensionFindings(report: ExtensionReport, files: Json[], copy: Copy): {
|
|
31
|
+
comments: InlineComment[];
|
|
32
|
+
listed: ExtensionFinding[];
|
|
33
|
+
};
|
|
34
|
+
/** The lines Metadata gains. */
|
|
35
|
+
export declare function extensionMetadataLines(report: ExtensionReport): string[];
|
|
36
|
+
/** The review body with the extensions in it. `body` is the AI review's own
|
|
37
|
+
* body, which always ends in its Metadata block. */
|
|
38
|
+
export declare function reviewBodyWithExtensions(body: string, report: ExtensionReport, listed: ExtensionFinding[], copy: Copy): string;
|
|
39
|
+
/** One extension's `request_changes` makes the review Request changes. A
|
|
40
|
+
* review the AI would approve only comments while an extension finding
|
|
41
|
+
* stands. */
|
|
42
|
+
export declare function reviewEventWithExtensions(event: "REQUEST_CHANGES" | "COMMENT" | "APPROVE", report: ExtensionReport): "REQUEST_CHANGES" | "COMMENT" | "APPROVE";
|
|
43
|
+
/** Findings still standing, for the check run's conclusion. */
|
|
44
|
+
export declare function standingExtensionFindings(report: ExtensionReport): number;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/** The extensions in the GitHub review `serve` posts.
|
|
2
|
+
*
|
|
3
|
+
* - A finding on a diff line goes inline, headed with its label.
|
|
4
|
+
* - A finding off the diff, or with no location, goes in the summary list
|
|
5
|
+
* with the same label. It is never an inline comment.
|
|
6
|
+
* - `#### Extensions` follows the review summary, one `<details>` per
|
|
7
|
+
* extension holding its `markdown`.
|
|
8
|
+
* - Metadata names which extensions ran, failed, skipped and requested
|
|
9
|
+
* changes.
|
|
10
|
+
* - A failure does not block. The summary says it failed and points at the
|
|
11
|
+
* dashboard, where the reason and the output are kept.
|
|
12
|
+
*
|
|
13
|
+
* The whole body stays under 250,000 characters by dropping `markdown`,
|
|
14
|
+
* longest first. The AI review is never cut. */
|
|
15
|
+
import { anchorFor } from "../pr/hunks.js";
|
|
16
|
+
import { locationOf } from "./render_cli.js";
|
|
17
|
+
import { extensionLabel, extensionsBlock, namesWith, } from "./report.js";
|
|
18
|
+
import { closeFences, extensionsSection, fitMarkdowns, REVIEW_BODY_MAX_CHARS, REVIEW_LIMIT_NOTE, } from "./render_markdown.js";
|
|
19
|
+
/** At most this many extension comments go inline in one review. The rest
|
|
20
|
+
* join the summary list. A linter run over a generated pull request can
|
|
21
|
+
* return thousands, and GitHub refuses a review that size. */
|
|
22
|
+
export const MAX_INLINE_EXTENSION_COMMENTS = 50;
|
|
23
|
+
/** At most this many extension findings are listed in the summary, then one
|
|
24
|
+
* "and N more" line points at the dashboard, which keeps every one. */
|
|
25
|
+
export const MAX_LISTED_EXTENSION_FINDINGS = 50;
|
|
26
|
+
/** A title is one line in a list: longer ones are cut. */
|
|
27
|
+
export const MAX_TITLE_CHARS = 200;
|
|
28
|
+
/** An inline comment's body past this is cut. */
|
|
29
|
+
export const MAX_INLINE_BODY_CHARS = 4_000;
|
|
30
|
+
/** Text cut to `max` characters, ending in an ellipsis when it was cut. */
|
|
31
|
+
export function cut(text, max) {
|
|
32
|
+
return text.length > max ? `${text.slice(0, max - 1)}…` : text;
|
|
33
|
+
}
|
|
34
|
+
/** A title as one line of a list. A backtick could open a code span or a
|
|
35
|
+
* fence that pairs with one in another part of the body, so none is kept. */
|
|
36
|
+
function titleLine(title) {
|
|
37
|
+
return cut(title.replace(/\s+/g, " ").replace(/`/g, "'").trim(), MAX_TITLE_CHARS);
|
|
38
|
+
}
|
|
39
|
+
function inlineBody(report, finding, copy) {
|
|
40
|
+
const body = closeFences(cut(finding.body, MAX_INLINE_BODY_CHARS)).trim();
|
|
41
|
+
// One pass over the whole comment, which is what `publish` checks.
|
|
42
|
+
return copy(`${extensionLabel(report, finding)}\n\n**${titleLine(finding.title)}**${body ? `\n\n${body}` : ""}`);
|
|
43
|
+
}
|
|
44
|
+
/** Splits the findings still standing into inline comments and the ones the
|
|
45
|
+
* summary lists. Only a finding new this round goes inline: a still open one
|
|
46
|
+
* was commented on when it was new. */
|
|
47
|
+
export function splitExtensionFindings(report, files, copy) {
|
|
48
|
+
const patches = new Map(files.map((file) => [
|
|
49
|
+
String(file.filename ?? ""),
|
|
50
|
+
String(file.patch ?? ""),
|
|
51
|
+
]));
|
|
52
|
+
const comments = [];
|
|
53
|
+
const listed = [];
|
|
54
|
+
for (const finding of report.findings) {
|
|
55
|
+
if (finding.state === "closed")
|
|
56
|
+
continue;
|
|
57
|
+
const patch = finding.path ? patches.get(finding.path) : undefined;
|
|
58
|
+
const anchor = finding.state === "new" && patch !== undefined && finding.lineFrom
|
|
59
|
+
? anchorFor(patch, finding.lineFrom, finding.lineTo ?? finding.lineFrom)
|
|
60
|
+
: undefined;
|
|
61
|
+
if (!anchor ||
|
|
62
|
+
!finding.path ||
|
|
63
|
+
comments.length >= MAX_INLINE_EXTENSION_COMMENTS) {
|
|
64
|
+
listed.push(finding);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
comments.push({
|
|
68
|
+
path: finding.path,
|
|
69
|
+
body: inlineBody(report, finding, copy),
|
|
70
|
+
line: anchor.line,
|
|
71
|
+
side: "RIGHT",
|
|
72
|
+
...(anchor.start_line === undefined
|
|
73
|
+
? {}
|
|
74
|
+
: { start_line: anchor.start_line, start_side: "RIGHT" }),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return { comments, listed };
|
|
78
|
+
}
|
|
79
|
+
function bracket(names) {
|
|
80
|
+
return `[${names.join(", ")}]`;
|
|
81
|
+
}
|
|
82
|
+
/** The lines Metadata gains. */
|
|
83
|
+
export function extensionMetadataLines(report) {
|
|
84
|
+
const failed = namesWith(report, "failed");
|
|
85
|
+
const skipped = namesWith(report, "skipped");
|
|
86
|
+
const requested = report.results
|
|
87
|
+
.filter((result) => result.status === "ok" && result.verdict === "request_changes")
|
|
88
|
+
.map((result) => result.name);
|
|
89
|
+
return [
|
|
90
|
+
`- Extensions: ${bracket(namesWith(report, "ok"))}`,
|
|
91
|
+
...(failed.length ? [`- Failed Extensions: ${bracket(failed)}`] : []),
|
|
92
|
+
...(skipped.length ? [`- Skipped Extensions: ${bracket(skipped)}`] : []),
|
|
93
|
+
...(requested.length ? [`- Requested changes: ${bracket(requested)}`] : []),
|
|
94
|
+
];
|
|
95
|
+
}
|
|
96
|
+
const METADATA_START = "\n\n<details>\n<summary>Metadata</summary>";
|
|
97
|
+
/** The review body with the extensions in it. `body` is the AI review's own
|
|
98
|
+
* body, which always ends in its Metadata block. */
|
|
99
|
+
export function reviewBodyWithExtensions(body, report, listed, copy) {
|
|
100
|
+
if (report.results.length === 0)
|
|
101
|
+
return body;
|
|
102
|
+
const at = body.lastIndexOf(METADATA_START);
|
|
103
|
+
let summary = at === -1 ? body : body.slice(0, at);
|
|
104
|
+
const metadata = at === -1 ? "" : body.slice(at);
|
|
105
|
+
const standing = report.findings.some((row) => row.state !== "closed");
|
|
106
|
+
if (standing && summary.startsWith("No actionable findings.")) {
|
|
107
|
+
summary = summary.replace("No actionable findings.", "The AI review found nothing to fix.");
|
|
108
|
+
}
|
|
109
|
+
const listBlock = (shown) => {
|
|
110
|
+
if (listed.length === 0)
|
|
111
|
+
return "";
|
|
112
|
+
const lines = [
|
|
113
|
+
`Extension findings (${listed.length})`,
|
|
114
|
+
...listed.slice(0, shown).map((row) => {
|
|
115
|
+
const where = locationOf(row);
|
|
116
|
+
return `- ${extensionLabel(report, row)}: ${titleLine(row.title)}${where ? ` (${titleLine(where)})` : ""}${row.state === "open" ? " (still open)" : ""}`;
|
|
117
|
+
}),
|
|
118
|
+
];
|
|
119
|
+
const more = listed.length - shown;
|
|
120
|
+
if (more > 0)
|
|
121
|
+
lines.push(`- and ${more} more, see the dashboard`);
|
|
122
|
+
return lines.join("\n");
|
|
123
|
+
};
|
|
124
|
+
const failures = namesWith(report, "failed")
|
|
125
|
+
.map((name) => `${name} extension failed, you can see details in dashboard`)
|
|
126
|
+
.join("\n");
|
|
127
|
+
const withMetadata = metadata.replace(/\n<\/details>$/, `\n${extensionMetadataLines(report).join("\n")}\n</details>`);
|
|
128
|
+
const render = (shown) => fitMarkdowns(report, (markdowns) => {
|
|
129
|
+
// The extension part passes the copy rule as one text: a fence in one
|
|
130
|
+
// piece pairs with one in another, so piece by piece is not enough.
|
|
131
|
+
const part = [
|
|
132
|
+
listBlock(shown),
|
|
133
|
+
failures,
|
|
134
|
+
extensionsSection(report, markdowns),
|
|
135
|
+
]
|
|
136
|
+
.filter((piece) => piece !== "")
|
|
137
|
+
.join("\n\n");
|
|
138
|
+
return ([summary, part ? copy(part) : ""]
|
|
139
|
+
.filter((piece) => piece !== "")
|
|
140
|
+
.join("\n\n") + withMetadata);
|
|
141
|
+
}, REVIEW_BODY_MAX_CHARS, (text) => text.length, REVIEW_LIMIT_NOTE);
|
|
142
|
+
// Every markdown dropped and still too long: the list gets shorter too,
|
|
143
|
+
// down to its "and N more" line. The AI review is never cut.
|
|
144
|
+
let shown = Math.min(listed.length, MAX_LISTED_EXTENSION_FINDINGS);
|
|
145
|
+
let text = render(shown);
|
|
146
|
+
while (text.length > REVIEW_BODY_MAX_CHARS && shown > 0) {
|
|
147
|
+
shown = Math.floor(shown / 2);
|
|
148
|
+
text = render(shown);
|
|
149
|
+
}
|
|
150
|
+
return text;
|
|
151
|
+
}
|
|
152
|
+
/** One extension's `request_changes` makes the review Request changes. A
|
|
153
|
+
* review the AI would approve only comments while an extension finding
|
|
154
|
+
* stands. */
|
|
155
|
+
export function reviewEventWithExtensions(event, report) {
|
|
156
|
+
if (extensionsBlock(report))
|
|
157
|
+
return "REQUEST_CHANGES";
|
|
158
|
+
if (event === "APPROVE" &&
|
|
159
|
+
report.findings.some((row) => row.state !== "closed")) {
|
|
160
|
+
return "COMMENT";
|
|
161
|
+
}
|
|
162
|
+
return event;
|
|
163
|
+
}
|
|
164
|
+
/** Findings still standing, for the check run's conclusion. */
|
|
165
|
+
export function standingExtensionFindings(report) {
|
|
166
|
+
return report.findings.filter((row) => row.state !== "closed").length;
|
|
167
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** The extensions' part of one finished review, in the shape every output
|
|
2
|
+
* reads: the results as they came back, and their findings with a state.
|
|
3
|
+
*
|
|
4
|
+
* A finding with a `key` is tracked across rounds. Seen again means still
|
|
5
|
+
* open, missing from a run that returned `ok` means closed. A finding with no
|
|
6
|
+
* key gets a fresh id each run and is never closed. The AI review's own
|
|
7
|
+
* carry-over is not touched: its output is not deterministic, so stable keys
|
|
8
|
+
* would not fit it. */
|
|
9
|
+
import type { ExtensionResult } from "./runner.ts";
|
|
10
|
+
import type { Severity } from "./schema.ts";
|
|
11
|
+
export type ExtensionFindingState = "new" | "open" | "closed";
|
|
12
|
+
export type ExtensionFinding = {
|
|
13
|
+
id: string;
|
|
14
|
+
/** The registered name of the extension that reported it. */
|
|
15
|
+
extensionId: string;
|
|
16
|
+
key: string | null;
|
|
17
|
+
state: ExtensionFindingState;
|
|
18
|
+
severity: Severity;
|
|
19
|
+
/** The finding's own flag, as the extension sent it. */
|
|
20
|
+
blocking: boolean;
|
|
21
|
+
title: string;
|
|
22
|
+
body: string;
|
|
23
|
+
path: string | null;
|
|
24
|
+
lineFrom: number | null;
|
|
25
|
+
lineTo: number | null;
|
|
26
|
+
};
|
|
27
|
+
/** A tracked finding from an earlier round, as the stores keep it. */
|
|
28
|
+
export type PreviousExtensionFinding = Omit<ExtensionFinding, "state">;
|
|
29
|
+
export type ExtensionReport = {
|
|
30
|
+
results: ExtensionResult[];
|
|
31
|
+
findings: ExtensionFinding[];
|
|
32
|
+
};
|
|
33
|
+
export declare const EMPTY_REPORT: ExtensionReport;
|
|
34
|
+
export declare function hasExtensions(report: ExtensionReport): boolean;
|
|
35
|
+
/** Joins this round's results with the keyed findings of the last round each
|
|
36
|
+
* extension returned `ok`. An extension that did not return `ok` this time
|
|
37
|
+
* closes nothing: a crash is not evidence that a problem went away. */
|
|
38
|
+
export declare function buildReport(results: ExtensionResult[], previous?: PreviousExtensionFinding[]): ExtensionReport;
|
|
39
|
+
/** What the next round compares against: the keyed findings still standing,
|
|
40
|
+
* per extension that returned `ok`, and the earlier set for one that did not. */
|
|
41
|
+
export declare function nextPrevious(report: ExtensionReport, previous?: PreviousExtensionFinding[]): PreviousExtensionFinding[];
|
|
42
|
+
/** An extension's `request_changes` makes the review Request changes, and a
|
|
43
|
+
* verdict always wins over a finding's own `blocking`: a blocking finding from
|
|
44
|
+
* an extension that says `comment` does not block. */
|
|
45
|
+
export declare function requestsChanges(result: ExtensionResult): boolean;
|
|
46
|
+
export declare function effectiveBlocking(report: ExtensionReport, finding: ExtensionFinding): boolean;
|
|
47
|
+
/** Whether the extensions alone make the review blocking. */
|
|
48
|
+
export declare function extensionsBlock(report: ExtensionReport): boolean;
|
|
49
|
+
/** A review's exit code with the extensions joined in: one extension's
|
|
50
|
+
* `request_changes` makes it blocking (1). A failure never does. */
|
|
51
|
+
export declare function exitCodeWithExtensions(code: number, report: ExtensionReport | undefined): number;
|
|
52
|
+
/** `[P2 · blocking] · extension: secret`, the label every output uses. */
|
|
53
|
+
export declare function extensionLabel(report: ExtensionReport, finding: ExtensionFinding): string;
|
|
54
|
+
export declare function namesWith(report: ExtensionReport, status: ExtensionResult["status"]): string[];
|
|
55
|
+
/** The sum of the costs the extensions reported. Unreported costs count as
|
|
56
|
+
* nothing: a linter that uses no AI costs nothing. */
|
|
57
|
+
export declare function extensionsCostUsd(report: ExtensionReport): number;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export const EMPTY_REPORT = { results: [], findings: [] };
|
|
2
|
+
export function hasExtensions(report) {
|
|
3
|
+
return report.results.length > 0;
|
|
4
|
+
}
|
|
5
|
+
function fromInput(extensionId, input, state, id) {
|
|
6
|
+
return {
|
|
7
|
+
id,
|
|
8
|
+
extensionId,
|
|
9
|
+
key: input.key ?? null,
|
|
10
|
+
state,
|
|
11
|
+
severity: input.severity,
|
|
12
|
+
blocking: input.blocking,
|
|
13
|
+
title: input.title,
|
|
14
|
+
body: input.body,
|
|
15
|
+
path: input.path ?? null,
|
|
16
|
+
lineFrom: input.lineFrom ?? null,
|
|
17
|
+
lineTo: input.lineTo ?? input.lineFrom ?? null,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** Joins this round's results with the keyed findings of the last round each
|
|
21
|
+
* extension returned `ok`. An extension that did not return `ok` this time
|
|
22
|
+
* closes nothing: a crash is not evidence that a problem went away. */
|
|
23
|
+
export function buildReport(results, previous = []) {
|
|
24
|
+
const findings = [];
|
|
25
|
+
for (const result of results) {
|
|
26
|
+
if (result.status !== "ok")
|
|
27
|
+
continue;
|
|
28
|
+
const before = new Map(previous
|
|
29
|
+
.filter((row) => row.extensionId === result.name && row.key)
|
|
30
|
+
.map((row) => [row.key, row]));
|
|
31
|
+
const seen = new Set();
|
|
32
|
+
for (const input of result.findings) {
|
|
33
|
+
if (input.key && !seen.has(input.key)) {
|
|
34
|
+
seen.add(input.key);
|
|
35
|
+
const earlier = before.get(input.key);
|
|
36
|
+
findings.push(fromInput(result.name, input, earlier ? "open" : "new", earlier?.id ?? crypto.randomUUID()));
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
findings.push(fromInput(result.name, input, "new", crypto.randomUUID()));
|
|
40
|
+
}
|
|
41
|
+
for (const [key, row] of before) {
|
|
42
|
+
if (!seen.has(key))
|
|
43
|
+
findings.push({ ...row, state: "closed" });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return { results, findings };
|
|
47
|
+
}
|
|
48
|
+
/** What the next round compares against: the keyed findings still standing,
|
|
49
|
+
* per extension that returned `ok`, and the earlier set for one that did not. */
|
|
50
|
+
export function nextPrevious(report, previous = []) {
|
|
51
|
+
const okNames = new Set(report.results
|
|
52
|
+
.filter((result) => result.status === "ok")
|
|
53
|
+
.map((result) => result.name));
|
|
54
|
+
const kept = previous.filter((row) => !okNames.has(row.extensionId));
|
|
55
|
+
const current = report.findings
|
|
56
|
+
.filter((row) => row.key && row.state !== "closed")
|
|
57
|
+
.map(({ state: _state, ...row }) => row);
|
|
58
|
+
return [...kept, ...current];
|
|
59
|
+
}
|
|
60
|
+
/** An extension's `request_changes` makes the review Request changes, and a
|
|
61
|
+
* verdict always wins over a finding's own `blocking`: a blocking finding from
|
|
62
|
+
* an extension that says `comment` does not block. */
|
|
63
|
+
export function requestsChanges(result) {
|
|
64
|
+
return result.status === "ok" && result.verdict === "request_changes";
|
|
65
|
+
}
|
|
66
|
+
export function effectiveBlocking(report, finding) {
|
|
67
|
+
if (!finding.blocking || finding.state === "closed")
|
|
68
|
+
return false;
|
|
69
|
+
const result = report.results.find((row) => row.name === finding.extensionId);
|
|
70
|
+
return result !== undefined && requestsChanges(result);
|
|
71
|
+
}
|
|
72
|
+
/** Whether the extensions alone make the review blocking. */
|
|
73
|
+
export function extensionsBlock(report) {
|
|
74
|
+
return report.results.some(requestsChanges);
|
|
75
|
+
}
|
|
76
|
+
/** A review's exit code with the extensions joined in: one extension's
|
|
77
|
+
* `request_changes` makes it blocking (1). A failure never does. */
|
|
78
|
+
export function exitCodeWithExtensions(code, report) {
|
|
79
|
+
return code === 0 && report && extensionsBlock(report) ? 1 : code;
|
|
80
|
+
}
|
|
81
|
+
/** `[P2 · blocking] · extension: secret`, the label every output uses. */
|
|
82
|
+
export function extensionLabel(report, finding) {
|
|
83
|
+
const blocking = effectiveBlocking(report, finding)
|
|
84
|
+
? "blocking"
|
|
85
|
+
: "non-blocking";
|
|
86
|
+
return `[${finding.severity} · ${blocking}] · extension: ${finding.extensionId}`;
|
|
87
|
+
}
|
|
88
|
+
export function namesWith(report, status) {
|
|
89
|
+
return report.results
|
|
90
|
+
.filter((result) => result.status === status)
|
|
91
|
+
.map((result) => result.name);
|
|
92
|
+
}
|
|
93
|
+
/** The sum of the costs the extensions reported. Unreported costs count as
|
|
94
|
+
* nothing: a linter that uses no AI costs nothing. */
|
|
95
|
+
export function extensionsCostUsd(report) {
|
|
96
|
+
return report.results.reduce((sum, result) => sum + (result.usage?.costUsd ?? 0), 0);
|
|
97
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** `cm-review.json`: the AI review's findings, for the extensions that run
|
|
2
|
+
* after it. The same finding shape `review --json` prints, so an extension
|
|
3
|
+
* reads one format whatever the review type. It holds what the AI answered
|
|
4
|
+
* this round. Carry-over states are worked out after the extensions finish. */
|
|
5
|
+
import { parseFindings } from "../pr/findings.js";
|
|
6
|
+
import { resolvedFromFirstReview, sortResolvedFindings, summaryCounts, toJsonFinding, } from "../cli/review_result.js";
|
|
7
|
+
export function reviewResultJson(reviewText, mode) {
|
|
8
|
+
const findings = sortResolvedFindings(resolvedFromFirstReview(parseFindings(reviewText), new Map()));
|
|
9
|
+
return {
|
|
10
|
+
schemaVersion: 1,
|
|
11
|
+
summary: summaryCounts(findings, mode),
|
|
12
|
+
findings: findings.map((row) => toJsonFinding(row, mode)),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ReviewType } from "./registry.ts";
|
|
2
|
+
export type RunOwner = "cli" | "serve";
|
|
3
|
+
/** What every extension of one review reads from `details.json`. */
|
|
4
|
+
export type ExtensionDetails = {
|
|
5
|
+
schemaVersion: 1;
|
|
6
|
+
reviewType: ReviewType;
|
|
7
|
+
repo: string;
|
|
8
|
+
prNumber: number | null;
|
|
9
|
+
branch: string | null;
|
|
10
|
+
/** The checkout a local review runs in. Empty for PR and remote reviews,
|
|
11
|
+
* where an extension makes its own checkout if it needs one. */
|
|
12
|
+
workdir: string;
|
|
13
|
+
headSha: string | null;
|
|
14
|
+
baseSha: string | null;
|
|
15
|
+
scope: string;
|
|
16
|
+
sinceCommit: string | null;
|
|
17
|
+
trigger: string;
|
|
18
|
+
round: number;
|
|
19
|
+
/** Empty until the AI review has finished. */
|
|
20
|
+
reviewResultPath: string;
|
|
21
|
+
diffPath: string;
|
|
22
|
+
};
|
|
23
|
+
export type RunFolder = {
|
|
24
|
+
runId: string;
|
|
25
|
+
dir: string;
|
|
26
|
+
detailsPath: string;
|
|
27
|
+
reviewResultPath: string;
|
|
28
|
+
diffPath: string;
|
|
29
|
+
/** The folder was already there: this run is a rerun after a restart. */
|
|
30
|
+
restarted: boolean;
|
|
31
|
+
/** Extensions that had started before the restart. */
|
|
32
|
+
startedBefore: Set<string>;
|
|
33
|
+
/** Extensions that had also finished before it. */
|
|
34
|
+
finishedBefore: Set<string>;
|
|
35
|
+
details: ExtensionDetails;
|
|
36
|
+
};
|
|
37
|
+
/** `<config dir>/co-maintainer/extensions`. A `config.json` moved elsewhere
|
|
38
|
+
* with `CM_CONFIG_PATH` may sit in a folder that holds anything, such as the
|
|
39
|
+
* home folder, so the run folders go under a name of their own there:
|
|
40
|
+
* `co-maintainer-extensions` next to that file. */
|
|
41
|
+
export declare function extensionsRoot(): string;
|
|
42
|
+
export declare function isRunId(value: string | undefined): value is string;
|
|
43
|
+
/** Marks `owner.json` as co-maintainer's own. */
|
|
44
|
+
declare const OWNER_TOOL = "co-maintainer-extension-run";
|
|
45
|
+
type Owner = {
|
|
46
|
+
tool: typeof OWNER_TOOL;
|
|
47
|
+
pid: number;
|
|
48
|
+
kind: RunOwner;
|
|
49
|
+
};
|
|
50
|
+
export declare function openRunFolder(input: {
|
|
51
|
+
runId: string;
|
|
52
|
+
owner: RunOwner;
|
|
53
|
+
details: Omit<ExtensionDetails, "reviewResultPath" | "diffPath">;
|
|
54
|
+
diff: string;
|
|
55
|
+
}): Promise<RunFolder>;
|
|
56
|
+
/** Records that an extension started. A rerun clears its earlier finish. */
|
|
57
|
+
export declare function markStarted(folder: RunFolder, name: string): Promise<void>;
|
|
58
|
+
/** Records that an extension finished, so a restart after it does not count
|
|
59
|
+
* it as cut off. */
|
|
60
|
+
export declare function markFinished(folder: RunFolder, name: string): Promise<void>;
|
|
61
|
+
/** Writes the AI review results and points `details.json` at them. */
|
|
62
|
+
export declare function writeReviewResult(folder: RunFolder, result: unknown): Promise<void>;
|
|
63
|
+
export declare function removeRunFolder(folder: RunFolder): Promise<void>;
|
|
64
|
+
/** Removes the run folders `keep` does not claim. Only a folder named like a
|
|
65
|
+
* run id that holds co-maintainer's own `owner.json` is ever a candidate:
|
|
66
|
+
* anything else under the folder is someone else's and stays. */
|
|
67
|
+
export declare function removeStaleRunFolders(keep: (runId: string, owner: Owner) => boolean): Promise<number>;
|
|
68
|
+
/** `serve`'s cleanup at startup: every folder of a job no longer running, and
|
|
69
|
+
* every CLI run whose process is gone. */
|
|
70
|
+
export declare function removeServeRunFolders(running: Set<string>): Promise<number>;
|
|
71
|
+
/** The CLI's cleanup on its next review: a CLI run whose process is gone.
|
|
72
|
+
* Folders `serve` owns are left to `serve`, which may still rerun them. */
|
|
73
|
+
export declare function removeDeadCliRunFolders(): Promise<number>;
|
|
74
|
+
export {};
|