co-maintainer 0.7.2 → 0.7.4

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 (59) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/src/cli/command_json.d.ts +3 -1
  3. package/dist/src/cli/command_json.js +1 -0
  4. package/dist/src/cli/commands/review.js +2 -0
  5. package/dist/src/cli/commands/set.js +19 -2
  6. package/dist/src/cli/pr_carry.d.ts +2 -0
  7. package/dist/src/cli/pr_carry.js +2 -2
  8. package/dist/src/cli/review_carry.d.ts +3 -1
  9. package/dist/src/cli/review_carry.js +5 -3
  10. package/dist/src/cli/review_result.d.ts +10 -1
  11. package/dist/src/cli/review_result.js +14 -1
  12. package/dist/src/config.d.ts +9 -0
  13. package/dist/src/github/collect.d.ts +7 -1
  14. package/dist/src/github/collect.js +41 -16
  15. package/dist/src/knowledge/guide.d.ts +24 -1
  16. package/dist/src/knowledge/guide.js +39 -9
  17. package/dist/src/knowledge/guide_ids.d.ts +9 -0
  18. package/dist/src/knowledge/guide_ids.js +26 -7
  19. package/dist/src/knowledge/rule_changes.d.ts +18 -0
  20. package/dist/src/knowledge/rule_changes.js +41 -0
  21. package/dist/src/knowledge/rules.d.ts +11 -0
  22. package/dist/src/knowledge/rules.js +10 -1
  23. package/dist/src/knowledge/stable_ids.d.ts +34 -0
  24. package/dist/src/knowledge/stable_ids.js +124 -0
  25. package/dist/src/knowledge/synthesis.d.ts +13 -1
  26. package/dist/src/knowledge/synthesis.js +89 -21
  27. package/dist/src/knowledge/types.d.ts +16 -0
  28. package/dist/src/local/review_local.js +3 -2
  29. package/dist/src/pr/findings.d.ts +3 -0
  30. package/dist/src/pr/findings.js +21 -1
  31. package/dist/src/pr/findings_json.d.ts +1 -1
  32. package/dist/src/pr/findings_json.js +14 -1
  33. package/dist/src/pr/reviewer.d.ts +4 -0
  34. package/dist/src/pr/reviewer.js +2 -0
  35. package/dist/src/remote/client.js +1 -0
  36. package/dist/src/review/carry_over.d.ts +8 -0
  37. package/dist/src/review/carry_over.js +8 -0
  38. package/dist/src/review/references.d.ts +68 -0
  39. package/dist/src/review/references.js +176 -0
  40. package/dist/src/server/pages/pr.js +2 -0
  41. package/dist/src/server/pages/references.d.ts +2 -0
  42. package/dist/src/server/pages/references.js +55 -0
  43. package/dist/src/server/pages/repo.js +26 -0
  44. package/dist/src/services/dashboard.d.ts +2 -0
  45. package/dist/src/services/dashboard.js +2 -0
  46. package/dist/src/services/push_review.js +4 -1
  47. package/dist/src/services/remote_review.js +5 -2
  48. package/dist/src/services/review.js +35 -8
  49. package/dist/src/services/rules_build.d.ts +20 -1
  50. package/dist/src/services/rules_build.js +88 -6
  51. package/dist/src/services/setup.js +27 -2
  52. package/dist/src/store/findings.d.ts +2 -0
  53. package/dist/src/store/findings.js +3 -3
  54. package/dist/src/store/migrations.js +17 -0
  55. package/dist/src/store/rows.d.ts +2 -0
  56. package/dist/src/store/rule_events.d.ts +15 -0
  57. package/dist/src/store/rule_events.js +20 -0
  58. package/dist/src/types.d.ts +4 -0
  59. package/package.json +1 -1
@@ -32,6 +32,7 @@ import { appPrContext } from "../extensions/contexts.js";
32
32
  import { reviewResultJson } from "../extensions/review_result.js";
33
33
  import { EMPTY_REPORT, hasExtensions, } from "../extensions/report.js";
34
34
  import { reviewBodyWithExtensions, reviewEventWithExtensions, splitExtensionFindings, standingExtensionFindings, } from "../extensions/render_review.js";
35
+ import { parseStoredReferences, referencesBlock, referencesJson, } from "../review/references.js";
35
36
  import { addExtensionCost } from "../extensions/cost.js";
36
37
  const ACCESS_DENIED_BODY = "The App does not have access to review this pull request.";
37
38
  /** The first words of the single note a failed review leaves on the pull
@@ -233,7 +234,20 @@ export function reviewBody(findings, metadata, stillOpen = []) {
233
234
  }
234
235
  return lines.join("\n") + notReviewed + metadataBlock(metadata);
235
236
  }
236
- function inlineCommentBody(finding, suggestion = false) {
237
+ /** The collapsed references block of a stored finding, or `""`. */
238
+ function referencesText(row) {
239
+ return referencesBlock(parseStoredReferences(row.references_json));
240
+ }
241
+ /** Whether this repository shows references in review comments. Off unless
242
+ * `set --repo <repo> --review-references=on` turned it on. */
243
+ function showsReferences(repo) {
244
+ return readConfig().repos?.[repo]?.reviewReferences === true;
245
+ }
246
+ function inlineCommentBody(finding, suggestion = false, references = "") {
247
+ const body = inlineCommentText(finding, suggestion);
248
+ return references ? `${body}\n\n${references}` : body;
249
+ }
250
+ function inlineCommentText(finding, suggestion = false) {
237
251
  const heading = humanCopy(finding.heading);
238
252
  const excerpt = humanCopy(suggestion
239
253
  ? withoutSuggestionLine(finding.excerpt)
@@ -262,8 +276,12 @@ function sameBody(a, b) {
262
276
  * may have gone out with its suggestion block, so both forms count. */
263
277
  function repeatsComment(row, posted) {
264
278
  const finding = rowFinding(row);
265
- return (sameBody(posted, inlineCommentBody(finding)) ||
266
- sameBody(posted, inlineCommentBody(finding, true)));
279
+ // With and without references too, so turning the setting on or off does
280
+ // not post every open finding again.
281
+ const references = referencesText(row);
282
+ return [false, true].some((suggestion) => sameBody(posted, inlineCommentBody(finding, suggestion)) ||
283
+ (references !== "" &&
284
+ sameBody(posted, inlineCommentBody(finding, suggestion, references))));
267
285
  }
268
286
  /** The pull request's review comments by id. An unreadable list comes back
269
287
  * empty, so a repeat is posted again rather than going unsaid. */
@@ -487,15 +505,21 @@ async function publish(client, job, reviewId, headSha, files, log, metadata, mod
487
505
  const freshRows = stored.filter((row) => !repeats.includes(row) && (row.state === "new" || row.thread_comment_id));
488
506
  const fresh = freshRows.map(rowFinding);
489
507
  const { inline } = splitInline(fresh, files);
508
+ const showReferences = showsReferences(job.repo);
509
+ const rowOf = (finding) => freshRows.find((item) => item.path === finding.path &&
510
+ item.line_from === finding.from &&
511
+ item.line_to === finding.to);
512
+ const referencesOf = (finding) => {
513
+ const row = showReferences ? rowOf(finding) : undefined;
514
+ return row ? referencesText(row) : "";
515
+ };
490
516
  const commentByRow = new Map();
491
517
  for (const { finding, anchor, suggestion } of inline) {
492
- const row = freshRows.find((item) => item.path === finding.path &&
493
- item.line_from === finding.from &&
494
- item.line_to === finding.to);
518
+ const row = rowOf(finding);
495
519
  if (row) {
496
520
  commentByRow.set(row.id, {
497
521
  anchor,
498
- body: inlineCommentBody(finding, suggestion),
522
+ body: inlineCommentBody(finding, suggestion, referencesOf(finding)),
499
523
  });
500
524
  }
501
525
  }
@@ -516,7 +540,7 @@ async function publish(client, job, reviewId, headSha, files, log, metadata, mod
516
540
  const body = reviewBodyWithExtensions(reviewBody(summaryFindings, metadata, stillOpen), extensions, extensionSplit.listed, humanCopy);
517
541
  const aiComments = inline.map(({ finding, anchor, suggestion }) => ({
518
542
  path: finding.path,
519
- body: inlineCommentBody(finding, suggestion),
543
+ body: inlineCommentBody(finding, suggestion, referencesOf(finding)),
520
544
  line: anchor.line,
521
545
  side: "RIGHT",
522
546
  ...(anchor.start_line === undefined
@@ -820,6 +844,7 @@ async function runReviewJobCore(job, log, client, ai, signal) {
820
844
  title: row.title,
821
845
  bodyMd: row.body_md,
822
846
  anchorText: row.anchor_text,
847
+ references: parseStoredReferences(row.references_json),
823
848
  severity: row.severity,
824
849
  firstSeenReviewId: row.first_seen_review_id ?? subjectRevision.review_id,
825
850
  replies: replies.get(row.id),
@@ -907,6 +932,7 @@ async function runReviewJobCore(job, log, client, ai, signal) {
907
932
  ? anchorTextFromPatch(patch, row.lineFrom, row.lineTo ?? row.lineFrom)
908
933
  : null),
909
934
  state: row.state,
935
+ referencesJson: referencesJson(row, job.repo, response.referenceContext),
910
936
  carriedFromFindingId: row.carriedFromId,
911
937
  closeReason: row.closeReason ?? undefined,
912
938
  firstSeenReviewId: row.firstSeenReviewId ?? undefined,
@@ -934,6 +960,7 @@ async function runReviewJobCore(job, log, client, ai, signal) {
934
960
  bodyMd: redact(finding.excerpt),
935
961
  anchorText: anchorTextFromPatch(patch, finding.from, finding.to),
936
962
  state: "new",
963
+ referencesJson: referencesJson({ referenceIds: finding.references ?? [] }, job.repo, response.referenceContext),
937
964
  firstSeenReviewId: repeat
938
965
  ? (repeat.first_seen_review_id ?? repeat.review_id)
939
966
  : undefined,
@@ -1,6 +1,6 @@
1
1
  import type { ReviewDocuments } from "../knowledge/guide.ts";
2
2
  import { type InstructionCounts, type InstructionsResult } from "../knowledge/instructions.ts";
3
- import { type RuleChanges } from "../knowledge/rule_changes.ts";
3
+ import { type Contradiction, type RuleChanges } from "../knowledge/rule_changes.ts";
4
4
  import type { Source } from "../knowledge/types.ts";
5
5
  import type { AiProvider, AiResponse, Options } from "../types.ts";
6
6
  export type InstructionsOutcome = InstructionsResult | {
@@ -29,11 +29,25 @@ export type RulesWriteResult = {
29
29
  guide: RuleChanges;
30
30
  instructions: RuleChanges;
31
31
  } | null;
32
+ /** Old guide rules a new rule goes against, checked by date. */
33
+ contradicted: Contradiction[];
32
34
  /** False when nothing happened that the run's output should mention: the
33
35
  * instructions were skipped, no guide rule was built, and there was no
34
36
  * earlier `INSTRUCTIONS.md` or `RULES.json`. */
35
37
  reported: boolean;
36
38
  };
39
+ export declare function readRulesFile(repo: string): Promise<import("../knowledge/rules.ts").RulesFile | null>;
40
+ /** The guides and instructions of this build with their ids mapped onto the
41
+ * last build's, so a rule keeps its id across syncs and a dropped id is never
42
+ * given again. Runs under the knowledge lock, before anything is written. */
43
+ export declare function stabilizeRuleIds(repo: string, documents: ReviewDocuments | undefined, instructions: InstructionsOutcome): Promise<{
44
+ documents: ReviewDocuments | undefined;
45
+ instructions: InstructionsOutcome;
46
+ lastIds: {
47
+ R: number;
48
+ I: number;
49
+ };
50
+ }>;
37
51
  /** Writes or removes `INSTRUCTIONS.md`, writes `RULES.json`, and reports
38
52
  * what changed since the last build. The caller holds the knowledge lock, so
39
53
  * the ids here and the guides just written belong to one build. */
@@ -46,4 +60,9 @@ export declare function writeInstructionsAndRules(input: {
46
60
  signalCount: number;
47
61
  instructions: InstructionsOutcome;
48
62
  source: Source;
63
+ /** From `stabilizeRuleIds`. Missing keeps the highest ids in the file. */
64
+ lastIds?: {
65
+ R: number;
66
+ I: number;
67
+ };
49
68
  }): Promise<RulesWriteResult>;
@@ -7,8 +7,9 @@ import { reposDir } from "../config.js";
7
7
  import { guideWriteLine } from "../knowledge/guide_ids.js";
8
8
  import { agentInstructionsLimit, DEFAULT_AGENT_INSTRUCTIONS, } from "../knowledge/instruction_files.js";
9
9
  import { instructionRuleEntries, instructionsWriteLine, synthesizeInstructions, } from "../knowledge/instructions.js";
10
- import { compareRules, ruleChangeLine, } from "../knowledge/rule_changes.js";
10
+ import { compareRules, contradictionLine, contradictions, ruleChangeLine, } from "../knowledge/rule_changes.js";
11
11
  import { INSTRUCTIONS_FILE, mergedDate, parseRules, RULES_FILE, rulesFileText, rulesOfKind, } from "../knowledge/rules.js";
12
+ import { renameIdsInMarkdown, stableIds } from "../knowledge/stable_ids.js";
12
13
  import { log, timed } from "../util/log.js";
13
14
  import { readTextFile, remove, stat } from "../util/runtime.js";
14
15
  /** Why no instructions are built this run, or `null` when they are. */
@@ -73,7 +74,7 @@ async function exists(path) {
73
74
  return false;
74
75
  }
75
76
  }
76
- async function readRulesFile(repo) {
77
+ export async function readRulesFile(repo) {
77
78
  try {
78
79
  return parseRules(await readTextFile(`${reposDir()}/${repo}/${RULES_FILE}`));
79
80
  }
@@ -96,11 +97,76 @@ function guideEntries(documents, signalCount, previous, source) {
96
97
  text: rule.text,
97
98
  sources: rule.pullRequests.map((pr) => {
98
99
  const date = mergedAt.get(pr);
99
- return date ? { pr, mergedAt: date } : { pr };
100
+ const url = rule.links?.find((link) => link.pr === pr)?.url;
101
+ return {
102
+ pr,
103
+ ...(date ? { mergedAt: date } : {}),
104
+ ...(url ? { url } : {}),
105
+ };
100
106
  }),
101
107
  },
102
108
  ]));
103
109
  }
110
+ /** The guides and instructions of this build with their ids mapped onto the
111
+ * last build's, so a rule keeps its id across syncs and a dropped id is never
112
+ * given again. Runs under the knowledge lock, before anything is written. */
113
+ export async function stabilizeRuleIds(repo, documents, instructions) {
114
+ const previous = await readRulesFile(repo);
115
+ const guide = stableIds("R", (documents?.rules ?? []).map((rule) => ({
116
+ id: rule.id,
117
+ text: rule.text,
118
+ sources: rule.pullRequests.map((pr) => {
119
+ const url = rule.links?.find((link) => link.pr === pr)?.url;
120
+ return url ? { pr, url } : { pr };
121
+ }),
122
+ // A rule never takes the id of the rule it goes against.
123
+ avoid: rule.overturns ?? [],
124
+ })), previous?.rules, previous?.lastIds?.R);
125
+ const fromInstructions = stableIds("I", instructions.status === "written"
126
+ ? instructions.rules.map((rule) => ({
127
+ id: rule.id,
128
+ text: rule.text.replaceAll("`", ""),
129
+ sources: rule.sources,
130
+ }))
131
+ : [], previous?.rules, previous?.lastIds?.I);
132
+ const renamedDocuments = documents && {
133
+ ...documents,
134
+ guide: renameIdsInMarkdown(documents.guide, guide.ids),
135
+ ...(documents.detailed !== undefined
136
+ ? { detailed: renameIdsInMarkdown(documents.detailed, guide.ids) }
137
+ : {}),
138
+ ...(documents.rules
139
+ ? {
140
+ rules: documents.rules.map((rule) => ({
141
+ ...rule,
142
+ id: guide.ids.get(rule.id) ?? rule.id,
143
+ })),
144
+ }
145
+ : {}),
146
+ };
147
+ const renamedInstructions = instructions.status === "written"
148
+ ? {
149
+ ...instructions,
150
+ markdown: renameIdsInMarkdown(instructions.markdown, fromInstructions.ids),
151
+ rules: instructions.rules.map((rule) => ({
152
+ ...rule,
153
+ id: fromInstructions.ids.get(rule.id) ?? rule.id,
154
+ })),
155
+ }
156
+ : instructions;
157
+ return {
158
+ documents: renamedDocuments,
159
+ instructions: renamedInstructions,
160
+ lastIds: { R: guide.lastId, I: fromInstructions.lastId },
161
+ };
162
+ }
163
+ /** Never lower than any id in the file or any id given before. */
164
+ function lastIdsFor(rules, previous, given) {
165
+ const top = (kind) => Math.max(previous?.[kind] ?? 0, given?.[kind] ?? 0, ...Object.keys(rules)
166
+ .filter((id) => id.startsWith(kind))
167
+ .map((id) => Number(id.slice(1)) || 0));
168
+ return { R: top("R"), I: top("I") };
169
+ }
104
170
  function instructionsLine(counts) {
105
171
  const dropped = counts.unsupportedSource + counts.unknownName;
106
172
  return `${INSTRUCTIONS_FILE} skipped: the instruction files hold no rule a reviewer can check · ${dropped} dropped · ${counts.overCap} over the cap`;
@@ -124,7 +190,7 @@ export async function writeInstructionsAndRules(input) {
124
190
  if (input.command === "init") {
125
191
  log("write", `${INSTRUCTIONS_FILE} skipped: ${instructions.reason}`);
126
192
  }
127
- return { rules: 0, changes: null, reported: false };
193
+ return { rules: 0, changes: null, contradicted: [], reported: false };
128
194
  }
129
195
  for (const count of documents?.counts ?? []) {
130
196
  log("write", guideWriteLine(count));
@@ -168,6 +234,7 @@ export async function writeInstructionsAndRules(input) {
168
234
  schemaVersion: 1,
169
235
  builtAt: new Date().toISOString(),
170
236
  rules,
237
+ lastIds: lastIdsFor(rules, previous?.lastIds, input.lastIds),
171
238
  }));
172
239
  }
173
240
  else {
@@ -175,8 +242,16 @@ export async function writeInstructionsAndRules(input) {
175
242
  await remove(`${directory}/${RULES_FILE}`).catch(() => { });
176
243
  }
177
244
  if (!previous) {
178
- return { rules: Object.keys(rules).length, changes: null, reported: true };
245
+ return {
246
+ rules: Object.keys(rules).length,
247
+ changes: null,
248
+ contradicted: [],
249
+ reported: true,
250
+ };
179
251
  }
252
+ const contradicted = contradictions(previous.rules, rules, new Map((documents?.rules ?? [])
253
+ .filter((rule) => rule.overturns?.length)
254
+ .map((rule) => [rule.id, rule.overturns ?? []])));
180
255
  const inWindow = new Set(source.pullRequests.map((pr) => pr.number));
181
256
  const changes = {
182
257
  guide: compareRules(previous.rules, rules, "R", inWindow),
@@ -191,5 +266,12 @@ export async function writeInstructionsAndRules(input) {
191
266
  if (any)
192
267
  log(phase, ruleChangeLine(change));
193
268
  }
194
- return { rules: Object.keys(rules).length, changes, reported: true };
269
+ for (const item of contradicted)
270
+ log("guide", contradictionLine(item));
271
+ return {
272
+ rules: Object.keys(rules).length,
273
+ changes,
274
+ contradicted,
275
+ reported: true,
276
+ };
195
277
  }
@@ -1,6 +1,7 @@
1
1
  /** `init`/`remake` orchestration. The dashboard calls `runInitOrRemake`
2
2
  * directly. It used to re-spawn the CLI as a subprocess, a second
3
3
  * execution path with its own failure modes. */
4
+ import { recordContradictions } from "../store/rule_events.js";
4
5
  import { aiProviderName, createAiProvider } from "../ai/provider.js";
5
6
  import { enrichFacts, synthesizeSections } from "../knowledge/synthesis.js";
6
7
  import { collectSource } from "../github/collect.js";
@@ -27,7 +28,7 @@ import { addResponseCost, emptyTally } from "../util/cost.js";
27
28
  import { costLabel } from "../util/run_summary.js";
28
29
  import { formatError } from "../cli/error.js";
29
30
  import { buildSetupJson } from "../cli/command_json.js";
30
- import { buildInstructions, instructionsJson, writeInstructionsAndRules, } from "./rules_build.js";
31
+ import { buildInstructions, instructionsJson, readRulesFile, stabilizeRuleIds, writeInstructionsAndRules, } from "./rules_build.js";
31
32
  export function emptyAiMetrics() {
32
33
  return { calls: 0, tokensIn: 0, tokensOut: 0, ...emptyTally() };
33
34
  }
@@ -249,6 +250,14 @@ export async function runInitOrRemake(options) {
249
250
  }
250
251
  }
251
252
  async function initOrRemake(options) {
253
+ // Turning review references on re-reads every pull request once, so the
254
+ // guide rules get links to the review comments they came from.
255
+ const repoConfig = readConfig().repos?.[options.repo];
256
+ const backfillLinks = repoConfig?.reviewReferences === true && !repoConfig.referencesBackfilledAt;
257
+ if (backfillLinks) {
258
+ options = { ...options, refreshCommentLinks: true };
259
+ log("fetch", "review references are on: reading every pull request again once for comment links");
260
+ }
252
261
  const operationStarted = performance.now();
253
262
  const aiMetrics = emptyAiMetrics();
254
263
  const previous = await readState(options.repo);
@@ -322,7 +331,11 @@ async function initOrRemake(options) {
322
331
  unchangedSections.add(key);
323
332
  log("ai", `synth_section complete · ${Object.keys(overrides).length} sections`);
324
333
  log("ai", "starting synth_guide jobs");
325
- reviewDocuments = await timed("synth_guide AI", options.logTime, () => synthesizeReviewGuides(highAi, options.repo, options.ai, options.highModel ?? "", options.aiConcurrent, facts, usage));
334
+ // The last build's rules let the guide AI say which old rule a new line
335
+ // goes against. Read outside the lock: it only shapes the prompt, the ids
336
+ // are mapped under the lock below.
337
+ const previousRules = (await readRulesFile(options.repo))?.rules;
338
+ reviewDocuments = await timed("synth_guide AI", options.logTime, () => synthesizeReviewGuides(highAi, options.repo, options.ai, options.highModel ?? "", options.aiConcurrent, facts, usage, previousRules));
326
339
  log("ai", reviewDocuments
327
340
  ? `synth_guide complete · ${reviewDocuments.detailed ? "short + detailed" : "single guide"}`
328
341
  : reviewSignalCount(facts) > 2
@@ -358,6 +371,11 @@ async function initOrRemake(options) {
358
371
  const { withKnowledgeLock } = await import("../review/guides.js");
359
372
  const { writeTextFileAtomic } = await import("../util/atomic.js");
360
373
  await withKnowledgeLock(options.repo, async () => {
374
+ // Ids are mapped onto the last build's before the guides are written,
375
+ // so a review that cited R4 still points at the same rule.
376
+ const stable = await stabilizeRuleIds(options.repo, reviewDocuments, instructions);
377
+ reviewDocuments = stable.documents;
378
+ instructions = stable.instructions;
361
379
  await writeTextFileAtomic(path, result.markdown);
362
380
  await writeCodebaseDocument(options.repo, overrides, unchangedSections);
363
381
  await writeReviewDocuments(options.repo, reviewDocuments, reviewSignalCount(facts));
@@ -371,6 +389,7 @@ async function initOrRemake(options) {
371
389
  signalCount: reviewSignalCount(facts),
372
390
  instructions,
373
391
  source,
392
+ lastIds: stable.lastIds,
374
393
  });
375
394
  const head = source.commits[0];
376
395
  const baseSha = head?.sha ? String(head.sha) : new Date().toISOString();
@@ -378,6 +397,8 @@ async function initOrRemake(options) {
378
397
  // dashboard never sees what it built. A dashboard job already has one.
379
398
  registerCliRepo(options.repo);
380
399
  markKnowledgeBuilt(options.repo, baseSha);
400
+ // The dashboard repo page lists guide rules a newer rule went against.
401
+ recordContradictions(options.repo, rulesResult.contradicted);
381
402
  });
382
403
  await writeState({
383
404
  version: 1,
@@ -413,6 +434,9 @@ async function initOrRemake(options) {
413
434
  prState: options.prState,
414
435
  agentInstructions: options.agentInstructions,
415
436
  agentInstructionsMaxChars: options.agentInstructionsMaxChars,
437
+ ...(backfillLinks
438
+ ? { referencesBackfilledAt: new Date().toISOString() }
439
+ : {}),
416
440
  });
417
441
  });
418
442
  log("write", `${path} · ${result.changed.length
@@ -441,6 +465,7 @@ async function initOrRemake(options) {
441
465
  ? {
442
466
  instructions: instructionsJson(instructions),
443
467
  ruleChanges: rulesResult.changes,
468
+ contradicted: rulesResult.contradicted,
444
469
  }
445
470
  : {}),
446
471
  summary,
@@ -14,6 +14,8 @@ export declare function insertFinding(row: {
14
14
  state?: string;
15
15
  carriedFromFindingId?: string | null;
16
16
  closeReason?: string | null;
17
+ /** `ResolvedReference[]` as JSON. Missing stores `[]`. */
18
+ referencesJson?: string;
17
19
  }): void;
18
20
  export declare function listCarryableFindingsForReview(reviewId: string): FindingRow[];
19
21
  export declare function setFindingPosted(id: string, postedCommentId: string, threadCommentId?: string): void;
@@ -4,9 +4,9 @@ export function insertFinding(row) {
4
4
  .prepare(`INSERT INTO findings
5
5
  (id, review_id, severity, path, line_from, line_to, title, body_md,
6
6
  first_seen_review_id, thread_comment_id, anchor_text, state,
7
- carried_from_finding_id, close_reason)
8
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
9
- .run(row.id, row.reviewId, row.severity, row.path ?? null, row.lineFrom ?? null, row.lineTo ?? null, row.title, row.bodyMd, row.firstSeenReviewId ?? null, row.threadCommentId ?? null, row.anchorText ?? null, row.state ?? "new", row.carriedFromFindingId ?? null, row.closeReason ?? null);
7
+ carried_from_finding_id, close_reason, references_json)
8
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
9
+ .run(row.id, row.reviewId, row.severity, row.path ?? null, row.lineFrom ?? null, row.lineTo ?? null, row.title, row.bodyMd, row.firstSeenReviewId ?? null, row.threadCommentId ?? null, row.anchorText ?? null, row.state ?? "new", row.carriedFromFindingId ?? null, row.closeReason ?? null, row.referencesJson ?? "[]");
10
10
  }
11
11
  export function listCarryableFindingsForReview(reviewId) {
12
12
  return getAppDb()
@@ -392,4 +392,21 @@ export const migrations = [
392
392
  )`,
393
393
  `CREATE INDEX idx_extension_findings_review ON extension_findings(review_id)`,
394
394
  ],
395
+ // 17: what a finding rests on (guide and instruction rules, the codebase
396
+ // conventions, the review instructions), resolved at review time so a later
397
+ // sync never changes what an old review cited. And a log of guide rules a
398
+ // newer rule went against, for the dashboard.
399
+ [
400
+ `ALTER TABLE findings ADD COLUMN references_json TEXT NOT NULL DEFAULT '[]'`,
401
+ `CREATE TABLE rule_events (
402
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
403
+ repo TEXT NOT NULL,
404
+ at TEXT NOT NULL,
405
+ kind TEXT NOT NULL,
406
+ rule_id TEXT NOT NULL,
407
+ by_rule_id TEXT,
408
+ detail_json TEXT NOT NULL DEFAULT '{}'
409
+ )`,
410
+ `CREATE INDEX idx_rule_events_repo ON rule_events(repo, at)`,
411
+ ],
395
412
  ];
@@ -115,6 +115,8 @@ export type FindingRow = {
115
115
  state: string;
116
116
  carried_from_finding_id: string | null;
117
117
  close_reason: string | null;
118
+ /** JSON array of `ResolvedReference`, `[]` for rows before references. */
119
+ references_json: string;
118
120
  };
119
121
  export type SubjectRow = {
120
122
  id: string;
@@ -0,0 +1,15 @@
1
+ /** A log of guide rules a newer rule went against, written by `sync` and read
2
+ * by the dashboard repo page. */
3
+ import type { Contradiction } from "../knowledge/rule_changes.ts";
4
+ export type RuleEventRow = {
5
+ id: number;
6
+ repo: string;
7
+ at: string;
8
+ kind: string;
9
+ rule_id: string;
10
+ by_rule_id: string | null;
11
+ detail_json: string;
12
+ };
13
+ export declare function recordContradictions(repo: string, items: Contradiction[], at?: string): void;
14
+ /** The newest events first. */
15
+ export declare function listRuleEvents(repo: string, limit?: number): RuleEventRow[];
@@ -0,0 +1,20 @@
1
+ import { getAppDb } from "./app_db.js";
2
+ export function recordContradictions(repo, items, at = new Date().toISOString()) {
3
+ if (items.length === 0)
4
+ return;
5
+ const insert = getAppDb().prepare(`INSERT INTO rule_events (repo, at, kind, rule_id, by_rule_id, detail_json)
6
+ VALUES (?, ?, 'contradicted', ?, ?, ?)`);
7
+ for (const item of items) {
8
+ insert.run(repo, at, item.id, item.by, JSON.stringify({
9
+ sources: item.sources,
10
+ newest: item.newest,
11
+ dropped: item.dropped,
12
+ }));
13
+ }
14
+ }
15
+ /** The newest events first. */
16
+ export function listRuleEvents(repo, limit = 20) {
17
+ return getAppDb()
18
+ .prepare(`SELECT * FROM rule_events WHERE repo = ? ORDER BY at DESC, id DESC LIMIT ?`)
19
+ .all(repo, limit);
20
+ }
@@ -45,6 +45,10 @@ export type Options = {
45
45
  /** Keep only pull requests in the window that have at least one
46
46
  * `CHANGES_REQUESTED` review. Off by default, so the window is unchanged. */
47
47
  onlyRequestChangedPr: boolean;
48
+ /** Read the comments of cached pull requests again when they were stored
49
+ * before comment links were kept. Set by `sync` once, after a repository
50
+ * turned review references on. */
51
+ refreshCommentLinks?: boolean;
48
52
  /** Empty or omitted means every state. `closed` is closed and not merged. */
49
53
  prState?: ("open" | "closed" | "merged")[];
50
54
  maxCommits?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "co-maintainer",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "An imitator of yours, A PR review tool like co-maintainer.",
5
5
  "keywords": [
6
6
  "ai",