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.
Files changed (159) hide show
  1. package/README.md +1 -1
  2. package/dist/package.json +1 -1
  3. package/dist/src/ai/anthropic.js +2 -0
  4. package/dist/src/ai/batch.d.ts +3 -1
  5. package/dist/src/ai/batch.js +23 -2
  6. package/dist/src/ai/mermaid_loop.js +1 -1
  7. package/dist/src/ai/oauth/sign-in-with-chatgpt.js +8 -10
  8. package/dist/src/ai/openai.js +2 -0
  9. package/dist/src/ai/openrouter.js +2 -0
  10. package/dist/src/cli/args.js +47 -0
  11. package/dist/src/cli/command_json.d.ts +20 -1
  12. package/dist/src/cli/command_json.js +4 -0
  13. package/dist/src/cli/commands/config.d.ts +1 -1
  14. package/dist/src/cli/commands/config.js +1 -0
  15. package/dist/src/cli/commands/registry.js +226 -1
  16. package/dist/src/cli/commands/review.js +50 -9
  17. package/dist/src/cli/commands/serve.js +5 -0
  18. package/dist/src/cli/commands/set.js +75 -17
  19. package/dist/src/cli/commands/view.js +46 -5
  20. package/dist/src/cli/commands/view_sources.d.ts +11 -0
  21. package/dist/src/cli/commands/view_sources.js +40 -0
  22. package/dist/src/cli/main.js +5 -0
  23. package/dist/src/cli/pr_carry.d.ts +25 -0
  24. package/dist/src/cli/pr_carry.js +128 -0
  25. package/dist/src/cli/prompt.js +26 -1
  26. package/dist/src/cli/review_args.d.ts +8 -0
  27. package/dist/src/cli/review_args.js +18 -0
  28. package/dist/src/cli/review_carry.d.ts +32 -0
  29. package/dist/src/cli/review_carry.js +60 -0
  30. package/dist/src/cli/review_github.d.ts +16 -2
  31. package/dist/src/cli/review_github.js +49 -12
  32. package/dist/src/cli/review_intent.d.ts +25 -0
  33. package/dist/src/cli/review_intent.js +87 -0
  34. package/dist/src/cli/review_result.d.ts +53 -2
  35. package/dist/src/cli/review_result.js +90 -23
  36. package/dist/src/config.d.ts +30 -0
  37. package/dist/src/config.js +20 -12
  38. package/dist/src/extensions/command.d.ts +1 -0
  39. package/dist/src/extensions/command.js +355 -0
  40. package/dist/src/extensions/contexts.d.ts +65 -0
  41. package/dist/src/extensions/contexts.js +134 -0
  42. package/dist/src/extensions/cost.d.ts +8 -0
  43. package/dist/src/extensions/cost.js +6 -0
  44. package/dist/src/extensions/local_tracking.d.ts +7 -0
  45. package/dist/src/extensions/local_tracking.js +29 -0
  46. package/dist/src/extensions/mock.d.ts +29 -0
  47. package/dist/src/extensions/mock.js +67 -0
  48. package/dist/src/extensions/process.d.ts +43 -0
  49. package/dist/src/extensions/process.js +244 -0
  50. package/dist/src/extensions/registry.d.ts +79 -0
  51. package/dist/src/extensions/registry.js +240 -0
  52. package/dist/src/extensions/render_actions.d.ts +6 -0
  53. package/dist/src/extensions/render_actions.js +50 -0
  54. package/dist/src/extensions/render_cli.d.ts +18 -0
  55. package/dist/src/extensions/render_cli.js +88 -0
  56. package/dist/src/extensions/render_json.d.ts +51 -0
  57. package/dist/src/extensions/render_json.js +144 -0
  58. package/dist/src/extensions/render_markdown.d.ts +22 -0
  59. package/dist/src/extensions/render_markdown.js +96 -0
  60. package/dist/src/extensions/render_review.d.ts +44 -0
  61. package/dist/src/extensions/render_review.js +167 -0
  62. package/dist/src/extensions/report.d.ts +57 -0
  63. package/dist/src/extensions/report.js +97 -0
  64. package/dist/src/extensions/review_result.d.ts +2 -0
  65. package/dist/src/extensions/review_result.js +14 -0
  66. package/dist/src/extensions/run_folder.d.ts +74 -0
  67. package/dist/src/extensions/run_folder.js +172 -0
  68. package/dist/src/extensions/runner.d.ts +66 -0
  69. package/dist/src/extensions/runner.js +251 -0
  70. package/dist/src/extensions/schema.d.ts +103 -0
  71. package/dist/src/extensions/schema.js +539 -0
  72. package/dist/src/extensions/session.d.ts +56 -0
  73. package/dist/src/extensions/session.js +173 -0
  74. package/dist/src/github/collect.d.ts +7 -2
  75. package/dist/src/github/collect.js +66 -6
  76. package/dist/src/github/gh.d.ts +7 -0
  77. package/dist/src/github/gh.js +24 -29
  78. package/dist/src/knowledge/guide.js +3 -2
  79. package/dist/src/knowledge/instruction_files.d.ts +45 -0
  80. package/dist/src/knowledge/instruction_files.js +91 -0
  81. package/dist/src/knowledge/instructions.d.ts +78 -0
  82. package/dist/src/knowledge/instructions.js +280 -0
  83. package/dist/src/knowledge/rule_changes.d.ts +39 -0
  84. package/dist/src/knowledge/rule_changes.js +90 -0
  85. package/dist/src/knowledge/rules.d.ts +44 -0
  86. package/dist/src/knowledge/rules.js +82 -0
  87. package/dist/src/knowledge/synthesis.d.ts +1 -0
  88. package/dist/src/knowledge/synthesis.js +12 -5
  89. package/dist/src/knowledge/types.d.ts +4 -0
  90. package/dist/src/local/carry_over_store.d.ts +10 -0
  91. package/dist/src/local/carry_over_store.js +17 -0
  92. package/dist/src/local/review_local.js +100 -62
  93. package/dist/src/local/review_lock.js +15 -4
  94. package/dist/src/pr/diff_plan.d.ts +110 -0
  95. package/dist/src/pr/diff_plan.js +429 -0
  96. package/dist/src/pr/diff_summary.d.ts +17 -1
  97. package/dist/src/pr/diff_summary.js +87 -13
  98. package/dist/src/pr/review_diff.d.ts +47 -0
  99. package/dist/src/pr/review_diff.js +112 -0
  100. package/dist/src/pr/reviewer.d.ts +44 -19
  101. package/dist/src/pr/reviewer.js +114 -142
  102. package/dist/src/remote/client.js +67 -8
  103. package/dist/src/remote/http.d.ts +12 -0
  104. package/dist/src/remote/http.js +31 -0
  105. package/dist/src/remote/push_client.js +14 -3
  106. package/dist/src/remote/server/guides.js +12 -1
  107. package/dist/src/remote/server/routes.js +4 -2
  108. package/dist/src/remote/server/sessions.js +4 -1
  109. package/dist/src/remote/validate.js +11 -0
  110. package/dist/src/review/carry_over.d.ts +6 -1
  111. package/dist/src/review/carry_over.js +10 -2
  112. package/dist/src/review/coverage.d.ts +57 -0
  113. package/dist/src/review/coverage.js +186 -0
  114. package/dist/src/review/diagram.d.ts +73 -0
  115. package/dist/src/review/diagram.js +309 -0
  116. package/dist/src/review/engine.d.ts +2 -6
  117. package/dist/src/review/engine.js +1 -1
  118. package/dist/src/review/guides.d.ts +6 -0
  119. package/dist/src/review/guides.js +8 -1
  120. package/dist/src/review/intent.d.ts +24 -0
  121. package/dist/src/review/intent.js +28 -0
  122. package/dist/src/review/not_initialized.d.ts +13 -0
  123. package/dist/src/review/not_initialized.js +18 -0
  124. package/dist/src/review/system_prompt.d.ts +6 -0
  125. package/dist/src/review/system_prompt.js +13 -0
  126. package/dist/src/review/visible_paths.d.ts +22 -0
  127. package/dist/src/review/visible_paths.js +41 -0
  128. package/dist/src/server/auth.js +8 -1
  129. package/dist/src/server/pages/extensions.d.ts +5 -0
  130. package/dist/src/server/pages/extensions.js +72 -0
  131. package/dist/src/server/pages/pr.js +3 -2
  132. package/dist/src/services/dashboard.d.ts +8 -0
  133. package/dist/src/services/dashboard.js +8 -0
  134. package/dist/src/services/push_review.js +14 -5
  135. package/dist/src/services/remote_review.js +81 -26
  136. package/dist/src/services/replies.js +15 -8
  137. package/dist/src/services/review.d.ts +9 -3
  138. package/dist/src/services/review.js +109 -28
  139. package/dist/src/services/rules_build.d.ts +46 -0
  140. package/dist/src/services/rules_build.js +155 -0
  141. package/dist/src/services/setup.d.ts +31 -0
  142. package/dist/src/services/setup.js +120 -25
  143. package/dist/src/services/watch_comments.js +2 -0
  144. package/dist/src/store/app_db.d.ts +3 -1
  145. package/dist/src/store/app_db.js +7 -2
  146. package/dist/src/store/cache_db.js +3 -0
  147. package/dist/src/store/extensions.d.ts +51 -0
  148. package/dist/src/store/extensions.js +132 -0
  149. package/dist/src/store/migrations.js +40 -0
  150. package/dist/src/types.d.ts +22 -1
  151. package/dist/src/util/atomic.d.ts +15 -1
  152. package/dist/src/util/atomic.js +59 -29
  153. package/dist/src/util/interrupt.d.ts +6 -0
  154. package/dist/src/util/interrupt.js +27 -0
  155. package/dist/src/util/runtime.d.ts +3 -1
  156. package/dist/src/util/runtime.js +2 -2
  157. package/dist/src/util/test_location_guard.d.ts +6 -0
  158. package/dist/src/util/test_location_guard.js +47 -0
  159. 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 { humanShortTitle, sortHumanFindings, } from "./review_result.js";
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(short ? `${row.severity}: ${short}` : `${row.severity} finding`)}`);
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
- export function githubAnnotations(findings) {
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 rows = active(input.findings);
82
- const closed = input.findings.filter((row) => row.state === "closed").length;
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("No actionable findings.");
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 = humanShortTitle(row);
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
- for (const line of githubAnnotations(input.findings))
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 declare function revisionStats(revision: Revision): {
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
- export function revisionStats(revision) {
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
- files: revision.files.length,
86
- additions,
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
- if (!any) {
246
- lines.push("No actionable findings.");
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
- for (const w of input.warnings)
259
- lines.push(` - ${w.message}`);
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 = resolvedFromFirstReview(parseFindings(input.markdown), new Map());
337
+ const findings = input.findings ??
338
+ resolvedFromFirstReview(parseFindings(input.markdown), new Map());
285
339
  const sorted = sortResolvedFindings(findings);
286
- return JSON.stringify({
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: { repo: input.repo, branch: null, prNumber: input.prNumber },
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
- return JSON.stringify({
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: { repo: input.repo, branch: input.branch, prNumber: null },
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: revisionStats(input.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: input.warnings,
387
+ warnings,
321
388
  usage: input.usage,
322
389
  durationMs: input.durationMs,
323
390
  });
@@ -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