co-maintainer 0.7.5 → 0.7.6-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/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.1",
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,4 @@
1
+ import { parseStoredReferences, referenceLine } from "../review/references.js";
1
2
  import { FakeAiProvider } from "../ai/fake.js";
2
3
  import { completeWithMermaidTools, } from "../ai/mermaid_loop.js";
3
4
  import { MERMAID_GUIDANCE, NO_DIAGRAM_RULES } from "../pr/reviewer.js";
@@ -35,6 +36,26 @@ async function githubFor(job, client) {
35
36
  }
36
37
  return clientFor(installationId);
37
38
  }
39
+ /** What a finding rested on when it was found, for the reply: each reference
40
+ * as the review printed it, with its pull request or file links, and a rule's
41
+ * text from `RULES.json` when the id is still there. Rule ids stay the same
42
+ * across syncs, so the text is the rule the finding cited. */
43
+ export function findingRules(referencesJson, rules) {
44
+ // Capped, so a long rule list never crowds out the question.
45
+ return parseStoredReferences(referencesJson)
46
+ .slice(0, MAX_FINDING_RULES)
47
+ .map((reference) => {
48
+ const text = reference.kind === "rule" || reference.kind === "instruction"
49
+ ? rules?.rules[reference.id]?.text
50
+ : undefined;
51
+ return {
52
+ reference: clip(referenceLine(reference), MAX_RULE_CHARS),
53
+ ...(text ? { text: clip(text, MAX_RULE_CHARS) } : {}),
54
+ };
55
+ });
56
+ }
57
+ const MAX_FINDING_RULES = 10;
58
+ const MAX_RULE_CHARS = 600;
38
59
  async function replyContext(client, request) {
39
60
  const [pr, issueComments, reviewComments, reviews, files, guides] = await Promise.all([
40
61
  client.request(`repos/${request.repo}/pulls/${request.pr_number}`),
@@ -106,6 +127,7 @@ async function replyContext(client, request) {
106
127
  severity: finding.severity,
107
128
  title: finding.title,
108
129
  body: finding.body_md,
130
+ restsOn: findingRules(finding.references_json, guides.rules),
109
131
  })
110
132
  : "None.",
111
133
  fileHint,
@@ -194,6 +216,7 @@ async function runReplyJobCore(job, log, client, ai, signal) {
194
216
  "Return only the answer in concise Markdown. Do not add a findings heading. " +
195
217
  "Keep the reply concise unless the user asks for detailed reasoning. " +
196
218
  `${WITHDRAW_RULE} ` +
219
+ "When asked why a finding was raised or which rule it follows, name the rules in RELATED FINDING restsOn with their links. " +
197
220
  (diagrams
198
221
  ? (plantumlReplyRules(options) ??
199
222
  "Use zero Mermaid diagrams when prose is clearer. For a detailed " +
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.1",
4
4
  "description": "An imitator of yours, A PR review tool like co-maintainer.",
5
5
  "keywords": [
6
6
  "ai",