co-maintainer 0.7.5 → 0.7.6-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "co-maintainer",
3
- "version": "0.7.5",
3
+ "version": "0.7.6-beta.2",
4
4
  "description": "An imitator of yours, A PR review tool like co-maintainer.",
5
5
  "keywords": [
6
6
  "ai",
@@ -1,6 +1,15 @@
1
+ import type { RulesFile } from "../knowledge/rules.ts";
1
2
  import type { AiProvider, GitHubClient } from "../types.ts";
2
3
  import { type LogFn } from "./jobs.ts";
3
4
  import type { JobRow } from "../store/rows.ts";
5
+ /** What a finding rested on when it was found, for the reply: each reference
6
+ * as the review printed it, with its pull request or file links, and a rule's
7
+ * text from `RULES.json` when the id is still there. Rule ids stay the same
8
+ * across syncs, so the text is the rule the finding cited. */
9
+ export declare function findingRules(referencesJson: string | null | undefined, rules: RulesFile | null): {
10
+ reference: string;
11
+ text?: string;
12
+ }[];
4
13
  /** The answer without its closing `WITHDRAWN` line, and whether it had one.
5
14
  * The line is for co-maintainer, never posted. */
6
15
  export declare function takeWithdrawLine(answer: string): {
@@ -1,3 +1,5 @@
1
+ import { safeCopy } from "../util/redact.js";
2
+ import { parseStoredReferences, referenceLine } from "../review/references.js";
1
3
  import { FakeAiProvider } from "../ai/fake.js";
2
4
  import { completeWithMermaidTools, } from "../ai/mermaid_loop.js";
3
5
  import { MERMAID_GUIDANCE, NO_DIAGRAM_RULES } from "../pr/reviewer.js";
@@ -35,6 +37,26 @@ async function githubFor(job, client) {
35
37
  }
36
38
  return clientFor(installationId);
37
39
  }
40
+ /** What a finding rested on when it was found, for the reply: each reference
41
+ * as the review printed it, with its pull request or file links, and a rule's
42
+ * text from `RULES.json` when the id is still there. Rule ids stay the same
43
+ * across syncs, so the text is the rule the finding cited. */
44
+ export function findingRules(referencesJson, rules) {
45
+ // Capped, so a long rule list never crowds out the question.
46
+ return parseStoredReferences(referencesJson)
47
+ .slice(0, MAX_FINDING_RULES)
48
+ .map((reference) => {
49
+ const text = reference.kind === "rule" || reference.kind === "instruction"
50
+ ? rules?.rules[reference.id]?.text
51
+ : undefined;
52
+ return {
53
+ reference: clip(referenceLine(reference), MAX_RULE_CHARS),
54
+ ...(text ? { text: clip(text, MAX_RULE_CHARS) } : {}),
55
+ };
56
+ });
57
+ }
58
+ const MAX_FINDING_RULES = 10;
59
+ const MAX_RULE_CHARS = 600;
38
60
  async function replyContext(client, request) {
39
61
  const [pr, issueComments, reviewComments, reviews, files, guides] = await Promise.all([
40
62
  client.request(`repos/${request.repo}/pulls/${request.pr_number}`),
@@ -106,6 +128,7 @@ async function replyContext(client, request) {
106
128
  severity: finding.severity,
107
129
  title: finding.title,
108
130
  body: finding.body_md,
131
+ restsOn: findingRules(finding.references_json, guides.rules),
109
132
  })
110
133
  : "None.",
111
134
  fileHint,
@@ -194,6 +217,7 @@ async function runReplyJobCore(job, log, client, ai, signal) {
194
217
  "Return only the answer in concise Markdown. Do not add a findings heading. " +
195
218
  "Keep the reply concise unless the user asks for detailed reasoning. " +
196
219
  `${WITHDRAW_RULE} ` +
220
+ "When asked why a finding was raised or which rule it follows, name the rules in RELATED FINDING restsOn with their links. " +
197
221
  (diagrams
198
222
  ? (plantumlReplyRules(options) ??
199
223
  "Use zero Mermaid diagrams when prose is clearer. For a detailed " +
@@ -230,7 +254,11 @@ async function runReplyJobCore(job, log, client, ai, signal) {
230
254
  log("info", "stopped before posting the reply, nothing was posted");
231
255
  return;
232
256
  }
233
- const { text, withdrawn } = takeWithdrawLine(answer);
257
+ const taken = takeWithdrawLine(answer);
258
+ // The copy rule is asked of the model, and a model can still break it. A
259
+ // reply's prose loses its em dashes and semicolons here, code keeps them.
260
+ const text = safeCopy(taken.text);
261
+ const withdrawn = taken.withdrawn;
234
262
  const body = `${marker}\n${plainSuggestionFences(text)}`;
235
263
  setReplyStatus(request.id, "posting");
236
264
  const posted = await postReply(github, request, body);
@@ -29,5 +29,5 @@ export function outsideCode(text, clean) {
29
29
  * semicolon. Code keeps its own punctuation or it stops compiling. */
30
30
  export function safeCopy(text) {
31
31
  // punctuation: code, this cleaner must name the semicolon it removes from AI text
32
- return outsideCode(redact(text), (prose) => prose.replaceAll("\u2014", ", ").replaceAll(";", "."));
32
+ return outsideCode(redact(text), (prose) => prose.replace(/\s*\u2014\s*/g, ", ").replaceAll(";", "."));
33
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "co-maintainer",
3
- "version": "0.7.5",
3
+ "version": "0.7.6-beta.2",
4
4
  "description": "An imitator of yours, A PR review tool like co-maintainer.",
5
5
  "keywords": [
6
6
  "ai",