co-maintainer 0.7.2-beta.1 → 0.7.3

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 (194) hide show
  1. package/dist/package.json +2 -1
  2. package/dist/src/ai/anthropic.d.ts +1 -1
  3. package/dist/src/ai/anthropic.js +1 -1
  4. package/dist/src/ai/batch.d.ts +1 -1
  5. package/dist/src/ai/batch.js +3 -3
  6. package/dist/src/ai/copy_rule.d.ts +7 -0
  7. package/dist/src/ai/copy_rule.js +23 -0
  8. package/dist/src/ai/estimate.js +3 -3
  9. package/dist/src/ai/fake.js +2 -1
  10. package/dist/src/ai/mermaid.js +1 -0
  11. package/dist/src/ai/oauth/registry.d.ts +1 -1
  12. package/dist/src/ai/oauth/sign-in-with-chatgpt.d.ts +4 -4
  13. package/dist/src/ai/oauth/sign-in-with-chatgpt.js +6 -6
  14. package/dist/src/ai/openai.d.ts +3 -3
  15. package/dist/src/ai/openai.js +4 -4
  16. package/dist/src/ai/openrouter.d.ts +1 -1
  17. package/dist/src/ai/openrouter.js +1 -1
  18. package/dist/src/ai/pricing.js +1 -1
  19. package/dist/src/ai/provider.d.ts +2 -0
  20. package/dist/src/ai/provider.js +8 -2
  21. package/dist/src/ai/verify.d.ts +1 -1
  22. package/dist/src/ai/verify.js +1 -1
  23. package/dist/src/cli/args.js +1 -1
  24. package/dist/src/cli/command_json.d.ts +4 -2
  25. package/dist/src/cli/command_json.js +1 -0
  26. package/dist/src/cli/commands/config.d.ts +1 -1
  27. package/dist/src/cli/commands/config.js +1 -1
  28. package/dist/src/cli/commands/oauth.js +1 -1
  29. package/dist/src/cli/commands/probe.js +1 -1
  30. package/dist/src/cli/commands/review.js +2 -0
  31. package/dist/src/cli/commands/serve.d.ts +1 -1
  32. package/dist/src/cli/commands/serve.js +1 -1
  33. package/dist/src/cli/commands/set.d.ts +1 -1
  34. package/dist/src/cli/commands/set.js +23 -6
  35. package/dist/src/cli/commands/view.js +2 -2
  36. package/dist/src/cli/error.d.ts +1 -1
  37. package/dist/src/cli/error.js +1 -1
  38. package/dist/src/cli/pr_carry.d.ts +2 -0
  39. package/dist/src/cli/pr_carry.js +2 -2
  40. package/dist/src/cli/prompt.d.ts +2 -2
  41. package/dist/src/cli/prompt.js +3 -3
  42. package/dist/src/cli/review_args.js +2 -2
  43. package/dist/src/cli/review_carry.d.ts +3 -1
  44. package/dist/src/cli/review_carry.js +5 -3
  45. package/dist/src/cli/review_result.d.ts +13 -5
  46. package/dist/src/cli/review_result.js +19 -9
  47. package/dist/src/config.d.ts +20 -11
  48. package/dist/src/config.js +3 -3
  49. package/dist/src/github/app.d.ts +1 -1
  50. package/dist/src/github/app.js +1 -1
  51. package/dist/src/github/app_manifest.d.ts +1 -1
  52. package/dist/src/github/app_manifest.js +1 -1
  53. package/dist/src/github/client.d.ts +1 -1
  54. package/dist/src/github/client.js +1 -1
  55. package/dist/src/github/collect.d.ts +7 -1
  56. package/dist/src/github/collect.js +41 -16
  57. package/dist/src/github/gh.js +2 -2
  58. package/dist/src/github/jwt.d.ts +1 -1
  59. package/dist/src/github/jwt.js +1 -1
  60. package/dist/src/github/oauth.js +2 -2
  61. package/dist/src/knowledge/facts.js +3 -3
  62. package/dist/src/knowledge/guide.d.ts +24 -1
  63. package/dist/src/knowledge/guide.js +46 -16
  64. package/dist/src/knowledge/guide_ids.d.ts +9 -0
  65. package/dist/src/knowledge/guide_ids.js +26 -7
  66. package/dist/src/knowledge/probe.js +1 -1
  67. package/dist/src/knowledge/rule_changes.d.ts +18 -0
  68. package/dist/src/knowledge/rule_changes.js +41 -0
  69. package/dist/src/knowledge/rules.d.ts +11 -0
  70. package/dist/src/knowledge/rules.js +10 -1
  71. package/dist/src/knowledge/skill.js +1 -1
  72. package/dist/src/knowledge/stable_ids.d.ts +29 -0
  73. package/dist/src/knowledge/stable_ids.js +90 -0
  74. package/dist/src/knowledge/synthesis.d.ts +13 -1
  75. package/dist/src/knowledge/synthesis.js +94 -26
  76. package/dist/src/knowledge/types.d.ts +16 -0
  77. package/dist/src/local/carry_over_store.d.ts +1 -1
  78. package/dist/src/local/carry_over_store.js +1 -1
  79. package/dist/src/local/codegraph_prepare.js +1 -1
  80. package/dist/src/local/git_ops.js +1 -1
  81. package/dist/src/local/review_local.js +6 -5
  82. package/dist/src/local/review_lock.d.ts +1 -1
  83. package/dist/src/pr/checkout.d.ts +3 -3
  84. package/dist/src/pr/checkout.js +7 -7
  85. package/dist/src/pr/codegraph_tool_args.d.ts +1 -1
  86. package/dist/src/pr/codegraph_tool_args.js +1 -1
  87. package/dist/src/pr/findings.d.ts +3 -0
  88. package/dist/src/pr/findings.js +29 -10
  89. package/dist/src/pr/findings_json.d.ts +2 -2
  90. package/dist/src/pr/findings_json.js +15 -2
  91. package/dist/src/pr/github_revision.js +1 -1
  92. package/dist/src/pr/review_copy.d.ts +2 -3
  93. package/dist/src/pr/review_copy.js +2 -3
  94. package/dist/src/pr/reviewer.d.ts +7 -3
  95. package/dist/src/pr/reviewer.js +26 -26
  96. package/dist/src/pr/scope.d.ts +8 -8
  97. package/dist/src/pr/scope.js +4 -4
  98. package/dist/src/pr/snapshot.d.ts +2 -2
  99. package/dist/src/remote/client.js +4 -3
  100. package/dist/src/remote/schema.d.ts +1 -1
  101. package/dist/src/remote/schema.js +1 -1
  102. package/dist/src/remote/server/body.d.ts +1 -1
  103. package/dist/src/remote/server/body.js +1 -1
  104. package/dist/src/remote/server/guides.js +1 -1
  105. package/dist/src/remote/validate.js +1 -1
  106. package/dist/src/review/blocking.d.ts +3 -3
  107. package/dist/src/review/blocking.js +2 -2
  108. package/dist/src/review/carry_over.d.ts +9 -1
  109. package/dist/src/review/carry_over.js +10 -2
  110. package/dist/src/review/diagram.js +7 -6
  111. package/dist/src/review/engine.d.ts +1 -1
  112. package/dist/src/review/guides.js +1 -1
  113. package/dist/src/review/references.d.ts +68 -0
  114. package/dist/src/review/references.js +176 -0
  115. package/dist/src/review/system_prompt.d.ts +1 -1
  116. package/dist/src/review/system_prompt.js +1 -1
  117. package/dist/src/server/api/jobs.js +2 -2
  118. package/dist/src/server/api/repos.js +1 -1
  119. package/dist/src/server/app.js +1 -1
  120. package/dist/src/server/auth.d.ts +3 -3
  121. package/dist/src/server/auth.js +9 -4
  122. package/dist/src/server/http.js +5 -5
  123. package/dist/src/server/pages/activity.js +1 -1
  124. package/dist/src/server/pages/add_repo.js +1 -0
  125. package/dist/src/server/pages/client.d.ts +2 -2
  126. package/dist/src/server/pages/client.js +2 -2
  127. package/dist/src/server/pages/home.d.ts +1 -1
  128. package/dist/src/server/pages/home.js +1 -1
  129. package/dist/src/server/pages/icons.d.ts +1 -1
  130. package/dist/src/server/pages/icons.js +1 -1
  131. package/dist/src/server/pages/layout.d.ts +2 -2
  132. package/dist/src/server/pages/layout.js +3 -3
  133. package/dist/src/server/pages/pr.js +4 -0
  134. package/dist/src/server/pages/rate_limit_waits.js +2 -2
  135. package/dist/src/server/pages/references.d.ts +2 -0
  136. package/dist/src/server/pages/references.js +55 -0
  137. package/dist/src/server/pages/repo.js +26 -0
  138. package/dist/src/server/pages/repo_settings.js +1 -0
  139. package/dist/src/server/pages/router.js +3 -2
  140. package/dist/src/server/pages/styles.d.ts +2 -2
  141. package/dist/src/server/pages/styles.js +2 -2
  142. package/dist/src/server/pages/ui.d.ts +1 -1
  143. package/dist/src/server/pages/ui.js +2 -2
  144. package/dist/src/server/webhook/index.js +1 -1
  145. package/dist/src/services/clear.d.ts +2 -2
  146. package/dist/src/services/clear.js +2 -2
  147. package/dist/src/services/dashboard.d.ts +2 -0
  148. package/dist/src/services/dashboard.js +2 -0
  149. package/dist/src/services/probe.js +1 -1
  150. package/dist/src/services/push_review.js +4 -1
  151. package/dist/src/services/remote_review.js +5 -2
  152. package/dist/src/services/remote_review_abort.d.ts +1 -1
  153. package/dist/src/services/remote_review_abort.js +1 -1
  154. package/dist/src/services/remote_tokens.js +1 -1
  155. package/dist/src/services/replies.js +0 -2
  156. package/dist/src/services/review.d.ts +3 -5
  157. package/dist/src/services/review.js +43 -18
  158. package/dist/src/services/rules_build.d.ts +20 -1
  159. package/dist/src/services/rules_build.js +85 -6
  160. package/dist/src/services/setup.d.ts +2 -2
  161. package/dist/src/services/setup.js +36 -11
  162. package/dist/src/services/watch_comments.js +1 -2
  163. package/dist/src/services/watch_notes.js +1 -3
  164. package/dist/src/store/app_db.d.ts +1 -1
  165. package/dist/src/store/app_db.js +2 -2
  166. package/dist/src/store/findings.d.ts +2 -0
  167. package/dist/src/store/findings.js +3 -3
  168. package/dist/src/store/jobs.d.ts +2 -2
  169. package/dist/src/store/jobs.js +3 -3
  170. package/dist/src/store/migrations.d.ts +2 -2
  171. package/dist/src/store/migrations.js +35 -18
  172. package/dist/src/store/rows.d.ts +4 -2
  173. package/dist/src/store/rows.js +1 -1
  174. package/dist/src/store/rule_events.d.ts +15 -0
  175. package/dist/src/store/rule_events.js +20 -0
  176. package/dist/src/store/sessions.d.ts +1 -1
  177. package/dist/src/store/sessions.js +2 -2
  178. package/dist/src/store/sqlite.js +2 -2
  179. package/dist/src/tools/codegraph.d.ts +1 -1
  180. package/dist/src/tools/codegraph.js +3 -3
  181. package/dist/src/tools/codegraph_exec.d.ts +1 -1
  182. package/dist/src/tools/codegraph_exec.js +1 -1
  183. package/dist/src/types.d.ts +6 -2
  184. package/dist/src/util/keyed_lock.d.ts +1 -1
  185. package/dist/src/util/keyed_lock.js +1 -1
  186. package/dist/src/util/log.js +1 -1
  187. package/dist/src/util/redact.js +2 -1
  188. package/dist/src/util/run_summary.d.ts +3 -3
  189. package/dist/src/util/run_summary.js +3 -3
  190. package/dist/src/util/runtime.d.ts +4 -4
  191. package/dist/src/util/runtime.js +5 -5
  192. package/dist/src/util/time.d.ts +1 -1
  193. package/dist/src/util/time.js +1 -1
  194. package/package.json +2 -1
@@ -97,7 +97,7 @@ function parseJson(text) {
97
97
  }
98
98
  return [];
99
99
  }
100
- function factsFromResponse(text, evidence, defaultScope, origin) {
100
+ function factsFromResponse(text, evidence, defaultScope, origin, pr, ids) {
101
101
  const parsed = parseJson(text);
102
102
  if (!Array.isArray(parsed))
103
103
  return [];
@@ -128,6 +128,7 @@ function factsFromResponse(text, evidence, defaultScope, origin) {
128
128
  const trigger = String(value.trigger ?? "").trim();
129
129
  if (isReview && (!impact || !action))
130
130
  return [];
131
+ const links = isReview ? linksFor(value.sources, pr, ids) : [];
131
132
  return [
132
133
  {
133
134
  id: `${sectionKey}:${slug(claim)}`,
@@ -146,6 +147,7 @@ function factsFromResponse(text, evidence, defaultScope, origin) {
146
147
  ...(trigger ? { trigger } : {}),
147
148
  impact,
148
149
  action,
150
+ ...(links.length ? { links } : {}),
149
151
  }
150
152
  : {}),
151
153
  },
@@ -187,19 +189,88 @@ function hasUnsupportedPath(claim, source) {
187
189
  ![...paths].some((path) => wildcard ? wildcard.test(path) : path.startsWith(`${normalized}/`)));
188
190
  });
189
191
  }
190
- function pullRequestUnit(pr) {
192
+ /** Whether the pull request was read with comment links. A row cached before
193
+ * links were kept has none, and keeps the old extract prompt so its cached
194
+ * answer is still used. */
195
+ export function hasCommentLinks(pr) {
196
+ return (pr.commentUrls !== undefined ||
197
+ pr.reviewCommentUrls !== undefined ||
198
+ pr.reviewUrls !== undefined);
199
+ }
200
+ /** The comment ids of a linked pull request (`c1` issue comment, `r1` inline
201
+ * review comment, `v1` review) and the link behind each. */
202
+ export function commentIds(pr) {
203
+ const ids = new Map();
204
+ const add = (prefix, urls, count) => {
205
+ for (let index = 0; index < count; index++) {
206
+ const url = urls?.[index] ?? "";
207
+ if (url)
208
+ ids.set(`${prefix}${index + 1}`, url);
209
+ }
210
+ };
211
+ add("c", pr.commentUrls, pr.comments.length);
212
+ add("r", pr.reviewCommentUrls, pr.reviewComments.length);
213
+ add("v", pr.reviewUrls, pr.reviews.length);
214
+ return ids;
215
+ }
216
+ function pullRequestUnit(pr, numbered = false) {
217
+ const texts = (prefix, values) => values.map((value, index) => {
218
+ const text = promptText(value, 2_000);
219
+ return numbered ? `[${prefix}${index + 1}] ${text}` : text;
220
+ });
191
221
  return JSON.stringify({
192
222
  number: pr.number,
193
223
  title: pr.title,
194
224
  body: promptText(pr.body),
195
225
  labels: pr.labels,
196
- comments: pr.comments.map((comment) => promptText(comment, 2_000)),
197
- reviewComments: pr.reviewComments.map((comment) => promptText(comment, 2_000)),
198
- reviews: pr.reviews.map((review) => promptText(review, 2_000)),
226
+ comments: texts("c", pr.comments),
227
+ reviewComments: texts("r", pr.reviewComments),
228
+ reviews: texts("v", pr.reviews),
199
229
  changedFiles: pr.changedFiles,
200
230
  diff: promptText(pr.diff, 8_000),
201
231
  });
202
232
  }
233
+ /** The extract prompt for one pull request. A pull request read before
234
+ * comment links were kept gets the exact old text, so its cached answer still
235
+ * hits. A linked one numbers its comments and asks which ones a finding rests
236
+ * on. */
237
+ export function extractPrompt(pr) {
238
+ const numbered = hasCommentLinks(pr);
239
+ const sourcesField = numbered
240
+ ? ',"sources":["the ids of the comments or reviews the finding comes from, such as r2 or v1, empty when it comes from the body or the diff"]'
241
+ : "";
242
+ const sourcesRule = numbered
243
+ ? "\n- Every comment and review starts with its id in square brackets. List in sources only ids that appear in this pull request."
244
+ : "";
245
+ return `Analyze this pull request's reviews, comments, code and diff, and return only a JSON array of review findings.
246
+ Each item must have exactly:
247
+ {"sectionKey":"review","class":"a short area name","claim":"the invariant a reviewer would enforce, imperative and general","location":"path or path:line the finding is about, or empty when none","trigger":"the diff surface that should trigger this rule: a path, glob, or symbol, or empty when none","impact":"why this matters here, from the review's reasoning","action":"what to change or verify","scope":"historical-example","confidence":"medium"${sourcesField}}
248
+ Rules:
249
+ - Include only substantive findings: a reviewer identifies something to fix, change, verify or decide.
250
+ - Never write an approval, a merge, "LGTM", thanks, a reviewer name, a pull-request number, a commit id, or quoted comment text.
251
+ - The claim is a general invariant, not one past fix: "When X changes, Y must also change", or "Every Z uses W", never "change this one line".
252
+ - trigger is what a reviewer can see in a diff: a path, a glob, or a symbol. It is how the rule applies to a future change, so a rule with no trigger is a one-off and is not useful.
253
+ - impact and action are mandatory and concrete. Paraphrase the reviewer's reasoning for impact. Never quote it.
254
+ - class is a short area label chosen from a small, consistent set. Reuse the same label for findings of the same kind so related findings can be grouped.
255
+ - location is a repository path when the review names one, otherwise leave it empty.${sourcesRule}
256
+ - Return every distinct finding the reviews support, not a summary. Do not explain the answer.
257
+
258
+ PULL REQUEST:
259
+ ${pullRequestUnit(pr, numbered)}`;
260
+ }
261
+ /** The links a finding's `sources` name. An id the pull request does not have
262
+ * is dropped, so a made-up id never becomes a link. */
263
+ function linksFor(value, pr, ids) {
264
+ if (pr === undefined || !ids || !Array.isArray(value))
265
+ return [];
266
+ const urls = new Set();
267
+ for (const item of value) {
268
+ const url = ids.get(String(item).trim().toLowerCase());
269
+ if (url)
270
+ urls.add(url);
271
+ }
272
+ return [...urls].map((url) => ({ pr, url }));
273
+ }
203
274
  function queueFor(provider, repo, ai, model, concurrency, validate) {
204
275
  return new AiBatch(provider, repo, Math.max(1, concurrency), `${ai}:v3:${model}`, validate);
205
276
  }
@@ -268,7 +339,7 @@ function sectionGoal(key) {
268
339
  function synthesisFacts(facts, key) {
269
340
  return (facts
270
341
  // A section that states repository policy never learns from a single pull
271
- // request's narrative; only `review-bar` may.
342
+ // request's narrative. Only `review-bar` may.
272
343
  .filter((item) => item.sectionKey === key &&
273
344
  (sectionAllowsPrFacts(key) || !isPullRequestFact(item)))
274
345
  .sort((a, b) => (b.status === "active" ? 1 : 0) - (a.status === "active" ? 1 : 0) ||
@@ -291,23 +362,15 @@ export async function extractAiFacts(provider, repo, source, options, usage) {
291
362
  const requests = [];
292
363
  const evidence = [];
293
364
  const scopes = [];
365
+ // Per request: the comment ids of a linked pull request and its number,
366
+ // `undefined` for the repository files request and unlinked pull requests.
367
+ const linkIds = [];
368
+ const prNumbers = [];
294
369
  const prs = options.includePullRequests ? source.pullRequests : [];
295
370
  for (const pr of prs) {
296
- requests.push(extractRequest(`Analyze this pull request's reviews, comments, code and diff, and return only a JSON array of review findings.
297
- Each item must have exactly:
298
- {"sectionKey":"review","class":"a short area name","claim":"the invariant a reviewer would enforce, imperative and general","location":"path or path:line the finding is about, or empty when none","trigger":"the diff surface that should trigger this rule: a path, glob, or symbol, or empty when none","impact":"why this matters here, from the review's reasoning","action":"what to change or verify","scope":"historical-example","confidence":"medium"}
299
- Rules:
300
- - Include only substantive findings: a reviewer identifies something to fix, change, verify or decide.
301
- - Never write an approval, a merge, "LGTM", thanks, a reviewer name, a pull-request number, a commit id, or quoted comment text.
302
- - The claim is a general invariant, not one past fix: "When X changes, Y must also change", or "Every Z uses W", never "change this one line".
303
- - trigger is what a reviewer can see in a diff: a path, a glob, or a symbol. It is how the rule applies to a future change, so a rule with no trigger is a one-off and is not useful.
304
- - impact and action are mandatory and concrete. Paraphrase the reviewer's reasoning for impact; never quote it.
305
- - class is a short area label chosen from a small, consistent set; reuse the same label for findings of the same kind so related findings can be grouped.
306
- - location is a repository path when the review names one, otherwise leave it empty.
307
- - Return every distinct finding the reviews support, not a summary. Do not explain the answer.
308
-
309
- PULL REQUEST:
310
- ${pullRequestUnit(pr)}`, 2_400));
371
+ requests.push(extractRequest(extractPrompt(pr), 2_400));
372
+ linkIds.push(hasCommentLinks(pr) ? commentIds(pr) : undefined);
373
+ prNumbers.push(pr.number);
311
374
  evidence.push(`PR #${pr.number}`);
312
375
  scopes.push("historical-example");
313
376
  }
@@ -325,14 +388,16 @@ release gates, and conventions that affect a code change. Ignore end-user featur
325
388
  installation walkthroughs, and generic programming advice. For source files, identify
326
389
  what important modules own and how tests exercise them when the files provide evidence.
327
390
  Do not infer PR titles, labels, review rules, or contributor policy unless the input
328
- contains PR or pull-request-template evidence; every claim must be directly supported
329
- by a provided file. Do not report a current version value; preserve the version
391
+ contains PR or pull-request-template evidence. Every claim must be directly supported
392
+ by a provided file. Do not report a current version value. Preserve the version
330
393
  change or release rule instead.
331
394
  Return at most 10 items. Keep each claim under 180 characters. Do not explain the answer.
332
395
 
333
396
  FILES:
334
397
  ${files}`, 2_200));
335
398
  evidence.push("repository files");
399
+ linkIds.push(undefined);
400
+ prNumbers.push(undefined);
336
401
  scopes.push("current");
337
402
  }
338
403
  }
@@ -349,7 +414,7 @@ ${files}`, 2_200));
349
414
  const response = responses[index];
350
415
  if (!response)
351
416
  continue;
352
- facts.push(...factsFromResponse(response.text, evidence[index], scopes[index] ?? "historical-example", evidence[index] === "repository files" ? "repository" : "pull-request").filter((item) => {
417
+ facts.push(...factsFromResponse(response.text, evidence[index], scopes[index] ?? "historical-example", evidence[index] === "repository files" ? "repository" : "pull-request", prNumbers[index], linkIds[index]).filter((item) => {
353
418
  if (hasUnsupportedIdentifier(item.claim, source) ||
354
419
  hasUnsupportedPath(item.claim, source)) {
355
420
  return false;
@@ -388,6 +453,9 @@ function mergeFacts(base, extra) {
388
453
  existing.evidence = [
389
454
  ...new Set([...existing.evidence, ...item.evidence]),
390
455
  ];
456
+ const links = [...(existing.links ?? []), ...(item.links ?? [])].filter((link, index, all) => all.findIndex((other) => other.url === link.url) === index);
457
+ if (links.length)
458
+ existing.links = links;
391
459
  }
392
460
  }
393
461
  return [...merged.values()];
@@ -429,11 +497,11 @@ existing guidance, remove contradictions, deduplicate overlapping facts, and do
429
497
  invent anything. Include the correct human-readable section heading. Use inline
430
498
  backticks instead of fenced code blocks. Do not create examples, placeholder
431
499
  identifiers, or policies that are not present in the facts. Prefer at most
432
- 6 high-value bullets; keep a concrete example only when it changes an agent decision.
500
+ 6 high-value bullets. Keep a concrete example only when it changes an agent decision.
433
501
  Do not preserve a current version value that can become stale. In Shipping,
434
502
  consolidate CI and release facts instead of repeating the same workflow rule.
435
503
  Facts are raw candidates, not all mandatory output. A fact supported by only one PR
436
- is an example, not a repository-wide rule; omit it unless canonical files or repeated
504
+ is an example, not a repository-wide rule. Omit it unless canonical files or repeated
437
505
  evidence support it. Omit conflicting claims rather than guessing. Return only the
438
506
  heading when this section has no durable guidance. Do not preserve bot-specific
439
507
  automation commands, reviewer identities, or one-off historical requests as
@@ -19,6 +19,13 @@ export type PullRequest = {
19
19
  * them otherwise. */
20
20
  reviewComments: string[];
21
21
  reviews: string[];
22
+ /** The GitHub link of each entry in `comments`, `reviewComments` and
23
+ * `reviews`, at the same index. Missing on rows cached before links were
24
+ * kept, and an entry is empty when GitHub gave no link. Never sent to a
25
+ * model: a fact names the numbered comment and code looks the link up. */
26
+ commentUrls?: string[];
27
+ reviewCommentUrls?: string[];
28
+ reviewUrls?: string[];
22
29
  /** Set once reviews have been read. Missing means an older checkpoint
23
30
  * never stored the review state. */
24
31
  changesRequested?: boolean;
@@ -72,6 +79,15 @@ export type Fact = {
72
79
  * also do Y" obligations listed under a pass's exit check, so a reviewer that
73
80
  * only sees a diff can still apply the rule. */
74
81
  trigger?: string;
82
+ /** Review findings only: the GitHub link of each comment or review the
83
+ * finding came from, with its pull request. The model names a numbered
84
+ * comment, code turns it into this link. Missing when the finding came from
85
+ * the body or the diff, or from a pull request cached before links were
86
+ * kept. */
87
+ links?: {
88
+ pr: number;
89
+ url: string;
90
+ }[];
75
91
  };
76
92
  export type State = {
77
93
  version: 1;
@@ -12,7 +12,7 @@ export type LocalCarrySnapshot = {
12
12
  };
13
13
  export declare function localSubjectId(repo: string, root: string, branch: string): string;
14
14
  export declare function loadLocalCarry(repo: string, root: string, branch: string): Promise<LocalCarrySnapshot | null>;
15
- /** Plan E163 — corrupt or locked cache must not abort review. */
15
+ /** Plan E163, corrupt or locked cache must not abort review. */
16
16
  export declare function tryLoadLocalCarry(repo: string, root: string, branch: string): Promise<{
17
17
  data: LocalCarrySnapshot | null;
18
18
  unavailable: boolean;
@@ -13,7 +13,7 @@ export async function loadLocalCarry(repo, root, branch) {
13
13
  }
14
14
  return loaded.data;
15
15
  }
16
- /** Plan E163 — corrupt or locked cache must not abort review. */
16
+ /** Plan E163, corrupt or locked cache must not abort review. */
17
17
  export async function tryLoadLocalCarry(repo, root, branch) {
18
18
  try {
19
19
  const raw = await cacheGet(NS, key(repo, root, branch));
@@ -11,7 +11,7 @@ export async function prepareLocalCodegraph(input) {
11
11
  const run = input.run ?? runCommand;
12
12
  const resolved = await ensureCodegraphForReview({
13
13
  allowInstall: input.allowInstall,
14
- // The prompt is safe only when a human can answer it; `canPrompt` checks
14
+ // The prompt is safe only when a human can answer it, `canPrompt` checks
15
15
  // stdin, stdout and `CI`, so a `</dev/null` or piped run never asks.
16
16
  interactive: input.interactive ?? canPrompt(),
17
17
  log: (message) => log("codegraph", message.replace(/^\[codegraph\]\s*/, "")),
@@ -86,7 +86,7 @@ export async function currentBranch(cwd, override, run = runCommand) {
86
86
  return override;
87
87
  const result = await run("git", ["symbolic-ref", "--short", "-q", "HEAD"], cwd);
88
88
  if (result.code !== 0 || !result.stdout.trim()) {
89
- throw new ReviewCliError("detached_head", "Detached HEAD; pass --branch=<name> to review.");
89
+ throw new ReviewCliError("detached_head", "Detached HEAD. Pass --branch=<name> to review.");
90
90
  }
91
91
  return result.stdout.trim();
92
92
  }
@@ -1,4 +1,5 @@
1
1
  import { parseArgs } from "../cli/args.js";
2
+ import { readConfig } from "../config.js";
2
3
  import { filterReviewConfigArgs, loadReviewSystemPromptFlags, reviewSystemPromptLimitFor, } from "../cli/review_args.js";
3
4
  import { buildLocalReviewJson, formatHumanLocalReview, humanFindingsFromResolved, reviewExitCodeFromResolved, } from "../cli/review_result.js";
4
5
  import { addAiMetrics, emptyAiMetrics, recordAiCost, runInitOrRemake, } from "../services/setup.js";
@@ -43,7 +44,7 @@ function fail(error, json) {
43
44
  if (error.hint)
44
45
  console.error(`Hint: ${error.hint}`);
45
46
  }
46
- // Set the exit code and return; `process.exit` here would assert in libuv on
47
+ // Set the exit code and return, `process.exit` here would assert in libuv on
47
48
  // Windows whenever a fetch pool is open.
48
49
  exitWith(error.exitCode);
49
50
  }
@@ -186,7 +187,7 @@ export async function runLocalReview(cli) {
186
187
  let previous = carryLoad.data;
187
188
  // A guide rebuilt after the last review judged its findings under rules
188
189
  // that no longer exist. Rather than let those stale findings mask new
189
- // ones, start fresh automatically — the same effect as
190
+ // ones, start fresh automatically, the same effect as
190
191
  // `--fresh`, without making the user remember the flag.
191
192
  if (previous &&
192
193
  guideRebuiltSince(previous.guideBuiltAt, guides.guideBuiltAt)) {
@@ -204,7 +205,7 @@ export async function runLocalReview(cli) {
204
205
  gitRoot: root,
205
206
  enabled: options.useCodegraph === true,
206
207
  allowInstall: cli.allowToolInstall,
207
- // `--json` output must stay machine-readable, so never prompt then;
208
+ // `--json` output must stay machine-readable, so never prompt then.
208
209
  // `canPrompt` adds the TTY and CI checks.
209
210
  interactive: !json && canPrompt(),
210
211
  });
@@ -245,7 +246,7 @@ export async function runLocalReview(cli) {
245
246
  return;
246
247
  const codegraphState = codegraphPrep.state;
247
248
  warnings.push(...response.warnings);
248
- const { resolved: allResolved, visiblePaths } = finishCarryRun(carryRun, revision, response);
249
+ const { resolved: allResolved, visiblePaths } = finishCarryRun(carryRun, revision, response, options.repo);
249
250
  const findingsToStore = storedFindings(allResolved);
250
251
  const afterBuilt = await buildLocalRevision(root, baseSha, base.label, runCommand);
251
252
  const revisionHashAfter = await revisionHash(afterBuilt.revision);
@@ -315,7 +316,7 @@ export async function runLocalReview(cli) {
315
316
  }
316
317
  else {
317
318
  console.log("\n" +
318
- formatHumanLocalReview(header, revision, response.guideBuiltAt, codegraphState, allResolved, warnings, options.reviewBlocking, response.coverage, extensions, Boolean(intentLoad.intent)) +
319
+ formatHumanLocalReview(header, revision, response.guideBuiltAt, codegraphState, allResolved, warnings, options.reviewBlocking, response.coverage, extensions, Boolean(intentLoad.intent), readConfig().repos?.[options.repo]?.reviewReferences === true) +
319
320
  "\n");
320
321
  printRunSummary(run);
321
322
  }
@@ -1,6 +1,6 @@
1
1
  export type LocalReviewLock = {
2
2
  release: () => Promise<void>;
3
- /** For signal handlers — must not await before exit. */
3
+ /** For signal handlers, must not await before exit. */
4
4
  releaseSync: () => void;
5
5
  };
6
6
  /** One local review per repo root. */
@@ -1,6 +1,6 @@
1
1
  export declare function withCloneLock<T>(repo: string, fn: () => Promise<T>): Promise<T>;
2
2
  /** Shared git plumbing for anything that needs a real checkout of a
3
- * repository — the codegraph map and the upstream/own-work scope both need
3
+ * repository, the codegraph map and the upstream/own-work scope both need
4
4
  * a clone and a way to resolve a commit that is not necessarily reachable
5
5
  * from any branch (a squash-merged or rebased-away PR head). One
6
6
  * implementation, so the two never manage the same on-disk clone in two
@@ -16,8 +16,8 @@ export declare function pathExists(path: string): Promise<boolean>;
16
16
  /** Like `ensureClone` but assumes the caller already holds `withCloneLock`. */
17
17
  export declare function ensureCloneUnlocked(repo: string, run: Run): Promise<string>;
18
18
  export declare function ensureClone(repo: string, run: Run): Promise<string>;
19
- /** Resolves `revision` — a branch name, a remote-tracking ref, or a commit SHA
20
- * — to a commit SHA, fetching it directly if it is a SHA the clone does not
19
+ /** Resolves `revision`, a branch name, a remote-tracking ref, or a commit SHA,
20
+ * to a commit SHA, fetching it directly if it is a SHA the clone does not
21
21
  * have. A round's boundary commit is often reachable only by SHA once its
22
22
  * branch has moved on or the PR was squash-merged, so no local or
23
23
  * remote-tracking ref points at it any more. */
@@ -60,7 +60,7 @@ async function cloneInto(repo, dir, run) {
60
60
  `repository scope and falls back to the diff only` +
61
61
  (firstLine ? `: ${firstLine}` : ""));
62
62
  }
63
- // A pull request may ship symlinks; without this a codegraph tool could read
63
+ // A pull request may ship symlinks. Without this a codegraph tool could read
64
64
  // through one to a file outside the tree. Persist it in the clone so every
65
65
  // worktree checkout writes symlinks as plain files instead of following them.
66
66
  await run("git", ["config", "core.symlinks", "false"], dir);
@@ -69,14 +69,14 @@ async function cloneInto(repo, dir, run) {
69
69
  }
70
70
  /** In-flight clone per destination directory. A benchmark run reviews several
71
71
  * PRs of the same repo concurrently, and each one's scope/map computation
72
- * calls `ensureClone` independently; without this, the first concurrent burst
72
+ * calls `ensureClone` independently. Without this, the first concurrent burst
73
73
  * has every caller see "not cloned yet" and race `git clone` into the same
74
- * directory — one wins, the rest fail with "already exists" and silently fall
74
+ * directory, one wins, the rest fail with "already exists" and silently fall
75
75
  * back to an unscoped review. Concurrent callers now await the one real clone
76
76
  * instead. The two statements between the `pathExists` check and this map's
77
77
  * `get`/`set` are synchronous (no `await` between them), so whichever caller's
78
78
  * continuation runs first registers the clone before any other caller can
79
- * observe an empty map entry — ordinary JS single-threaded scheduling, not a
79
+ * observe an empty map entry, ordinary JS single-threaded scheduling, not a
80
80
  * lock. */
81
81
  const cloningInFlight = new Map();
82
82
  /** Like `ensureClone` but assumes the caller already holds `withCloneLock`. */
@@ -99,7 +99,7 @@ export async function ensureClone(repo, run) {
99
99
  /** Resolves `candidate` to a commit SHA, or returns undefined. Two plain
100
100
  * commands rather than one `rev-parse <rev>^{commit}`: on Windows this runs
101
101
  * through `cmd /c`, where `^` is the shell's own escape character and would
102
- * silently eat the peel suffix, making a present commit look absent — the
102
+ * silently eat the peel suffix, making a present commit look absent, the
103
103
  * same trap `benchmark/core_v2/runners.ts`'s `requireCommit` avoids for the same
104
104
  * reason. `cat-file -t` after a caret-free `rev-parse` sidesteps it. */
105
105
  async function resolveCommit(clone, candidate, run) {
@@ -112,8 +112,8 @@ async function resolveCommit(clone, candidate, run) {
112
112
  return undefined;
113
113
  return sha;
114
114
  }
115
- /** Resolves `revision` — a branch name, a remote-tracking ref, or a commit SHA
116
- * — to a commit SHA, fetching it directly if it is a SHA the clone does not
115
+ /** Resolves `revision`, a branch name, a remote-tracking ref, or a commit SHA,
116
+ * to a commit SHA, fetching it directly if it is a SHA the clone does not
117
117
  * have. A round's boundary commit is often reachable only by SHA once its
118
118
  * branch has moved on or the PR was squash-merged, so no local or
119
119
  * remote-tracking ref points at it any more. */
@@ -7,7 +7,7 @@ export declare function rejectFlagLike(value: string, label: string): string | n
7
7
  * `>` or `%` can append a second command. None of them have a legitimate place
8
8
  * in a search term, symbol name or repo-relative path, so refuse them. */
9
9
  export declare function rejectShellMetacharacters(value: string, label: string): string | null;
10
- /** Repo-relative path only — no `..`, no absolute paths (plan E103). */
10
+ /** Repo-relative path only, no `..`, no absolute paths (plan E103). */
11
11
  export declare function rejectEscapingPath(file: string): string | null;
12
12
  export declare function guardToolArgs(args: Args, allowed: ReadonlySet<string>): string | null;
13
13
  export {};
@@ -24,7 +24,7 @@ export function rejectShellMetacharacters(value, label) {
24
24
  }
25
25
  return null;
26
26
  }
27
- /** Repo-relative path only — no `..`, no absolute paths (plan E103). */
27
+ /** Repo-relative path only, no `..`, no absolute paths (plan E103). */
28
28
  export function rejectEscapingPath(file) {
29
29
  const flag = rejectFlagLike(file, "file");
30
30
  if (flag)
@@ -10,5 +10,8 @@ export type ParsedFinding = Span & {
10
10
  blocking?: boolean;
11
11
  symbol?: string;
12
12
  summary?: string;
13
+ /** The ids from the finding's `References:` line, as the model wrote them.
14
+ * Missing when the line is absent. */
15
+ references?: string[];
13
16
  };
14
17
  export declare function parseFindings(markdown: string): ParsedFinding[];
@@ -1,12 +1,11 @@
1
1
  const FILE_LINE = /(?<path>(?:[\w.-]+\/)*[\w.-]+\.[A-Za-z0-9]+):(?<from>\d+)(?:-(?<to>\d+))?/g;
2
- /** The finding heading: `[P2 · non-blocking] \`path\` — \`symbol\``. The model
3
- * sometimes writes `:` where the prompt asked for the em dash, and sometimes
4
- * leaves the symbol off. Both are accepted: an unrecognised heading used to
5
- * send every finding down the fallback path, which is what produced the
6
- * truncated and shifted output. The separator may also sit directly
7
- * against the path (`\`src/a.ts\`: \`helper()\``), which is how the model
8
- * usually writes the colon form. */
9
- const NEW_HEADING = /^\[(?<severity>P[0-3])\s*·\s*(?<impact>blocking|non-blocking)\]\s+(?<path>.+?)(?:\s*(?:—|:)\s*(?<symbol>.+))?$/;
2
+ /** The finding heading: `[P2 · non-blocking] \`path\`: \`symbol\``. The model
3
+ * sometimes leaves the symbol off, so the symbol is optional: an unrecognised
4
+ * heading used to send every finding down the fallback path, which is what
5
+ * produced the truncated and shifted output. The separator may also sit
6
+ * directly against the path (`\`src/a.ts\`: \`helper()\``), which is how the
7
+ * model usually writes it. */
8
+ const NEW_HEADING = /^\[(?<severity>P[0-3])\s*·\s*(?<impact>blocking|non-blocking)\]\s+(?<path>.+?)(?:\s*:\s*(?<symbol>.+))?$/;
10
9
  function uncode(value) {
11
10
  return value.trim().replace(/^`|`$/g, "").trim();
12
11
  }
@@ -23,8 +22,24 @@ function location(block) {
23
22
  to: found.groups.to ? Number(found.groups.to) : from,
24
23
  };
25
24
  }
25
+ /** The `References:` line, only right under the Location line where
26
+ * `findingMarkdown` writes it, so a body sentence starting with the same word
27
+ * is never taken. */
28
+ const REFERENCES_LINE = /^(\s*(?:Location|File)\s*:[^\n]*)\n\s*References\s*:\s*([^\n]+?)\s*$/im;
29
+ function references(block) {
30
+ const match = REFERENCES_LINE.exec(block);
31
+ if (!match)
32
+ return undefined;
33
+ return match[2]
34
+ .split(",")
35
+ .map((id) => id.trim())
36
+ .filter(Boolean);
37
+ }
26
38
  function bodyWithoutLocation(block) {
27
- return block.replace(/^\s*(?:Location|File)\s*:\s*`?.+?`?\s*$/im, "").trim();
39
+ return block
40
+ .replace(REFERENCES_LINE, "$1")
41
+ .replace(/^\s*(?:Location|File)\s*:\s*`?.+?`?\s*$/im, "")
42
+ .trim();
28
43
  }
29
44
  function newFinding(header, block) {
30
45
  const meta = NEW_HEADING.exec(header);
@@ -41,7 +56,7 @@ function newFinding(header, block) {
41
56
  const summary = excerpt.split(/\r?\n/).find((line) => line.trim()) ?? "";
42
57
  return {
43
58
  ...at,
44
- // The Location line is authoritative for the path; the heading only names
59
+ // The Location line is authoritative for the path. The heading only names
45
60
  // it, and may omit the symbol entirely.
46
61
  path: at.path || path,
47
62
  heading: symbol
@@ -52,6 +67,10 @@ function newFinding(header, block) {
52
67
  blocking: impact === "blocking",
53
68
  symbol: symbol || undefined,
54
69
  summary,
70
+ ...(() => {
71
+ const ids = references(block);
72
+ return ids ? { references: ids } : {};
73
+ })(),
55
74
  };
56
75
  }
57
76
  export function parseFindings(markdown) {
@@ -4,7 +4,7 @@
4
4
  * wrong offsets, because the model's free-form Markdown was sliced by the
5
5
  * fallback parser. The fix is to have the model return JSON and generate the
6
6
  * Markdown ourselves, so a finding's boundaries can no longer be guessed from
7
- * prose. Markdown stays the internal contract — every downstream consumer
7
+ * prose. Markdown stays the internal contract, every downstream consumer
8
8
  * (`parseFindings`, carry-over, GitHub posting) keeps working unchanged.
9
9
  */
10
10
  import type { Json } from "../types.ts";
@@ -13,7 +13,7 @@ import type { ParsedFinding } from "./findings.ts";
13
13
  * get the prompt's instruction to return a fenced JSON block. */
14
14
  export declare const FINDINGS_JSON_SCHEMA: Json;
15
15
  /** The prompt's contract, kept next to the schema so the two cannot drift. */
16
- export declare const FINDINGS_JSON_INSTRUCTIONS = "Return a single JSON object, and nothing else, with this shape:\n{\"findings\":[{\"severity\":\"P1\",\"blocking\":true,\"path\":\"src/a.ts\",\"lineFrom\":42,\"lineTo\":42,\"symbol\":\"helper()\",\"title\":\"The helper ignores its argument\",\"body\":\"One sentence on what is wrong and its impact, then a short evidence paragraph.\",\"suggestion\":\"the exact replacement lines, or omit this field\"}],\"previousFindings\":[{\"id\":\"F1\",\"state\":\"open\"}]}\n\nRules for the JSON:\n- \"severity\" is exactly one of P0, P1, P2, P3. \"blocking\" is true or false.\n- \"lineFrom\" and \"lineTo\" are numbers in the new file, copied from the DIFF\n column, never counted from the @@ header. \"lineTo\" may equal \"lineFrom\".\n- \"title\" is one sentence naming the defect, without the severity or the path.\n- \"body\" is the explanation. Do not repeat the title, the path, or the location\n line inside it; our code renders those. Do not add a closing sentence asking\n whether to explain more, and do not use the words Mechanism, Symptom,\n Scenario, Verified, Repro, Options, or Scope as labels.\n- \"suggestion\" holds only the replacement source lines, with their original\n indentation, when the fix replaces the exact lines lineFrom-lineTo in one\n hunk of the same file. Omit it otherwise. Never wrap it in a code fence.\n- When a fix needs removed lines, another file, or more than one hunk, omit\n \"suggestion\".\n- Return every independently actionable finding, including none: use\n {\"findings\":[]} when the change is clean. Never invent a finding to fill the\n array.";
16
+ export declare const FINDINGS_JSON_INSTRUCTIONS = "Return a single JSON object, and nothing else, with this shape:\n{\"findings\":[{\"severity\":\"P1\",\"blocking\":true,\"path\":\"src/a.ts\",\"lineFrom\":42,\"lineTo\":42,\"symbol\":\"helper()\",\"title\":\"The helper ignores its argument\",\"body\":\"One sentence on what is wrong and its impact, then a short evidence paragraph.\",\"suggestion\":\"the exact replacement lines, or omit this field\",\"references\":[\"R12\"]}],\"previousFindings\":[{\"id\":\"F1\",\"state\":\"open\"}]}\n\nRules for the JSON:\n- \"severity\" is exactly one of P0, P1, P2, P3. \"blocking\" is true or false.\n- \"lineFrom\" and \"lineTo\" are numbers in the new file, copied from the DIFF\n column, never counted from the @@ header. \"lineTo\" may equal \"lineFrom\".\n- \"title\" is one sentence naming the defect, without the severity or the path.\n- \"body\" is the explanation. Do not repeat the title, the path, or the location\n line inside it. Our code renders those. Do not add a closing sentence asking\n whether to explain more, and do not use the words Mechanism, Symptom,\n Scenario, Verified, Repro, Options, or Scope as labels.\n- \"suggestion\" holds only the replacement source lines, with their original\n indentation, when the fix replaces the exact lines lineFrom-lineTo in one\n hunk of the same file. Omit it otherwise. Never wrap it in a code fence.\n- When a fix needs removed lines, another file, or more than one hunk, omit\n \"suggestion\".\n- \"references\" lists what the finding rests on: the bracketed id at the end\n of a guide or repository instruction line (such as R12 or I3),\n \"codebase:<section title>\" for a CODEBASE CONVENTIONS section, or \"system\"\n when it rests only on these review instructions. Name only ids you used.\n- Return every independently actionable finding, including none: use\n {\"findings\":[]} when the change is clean. Never invent a finding to fill the\n array.";
17
17
  /** Reads the structured output and renders it as Markdown. `undefined` means
18
18
  * the text was not usable JSON, so the caller falls back to the legacy
19
19
  * Markdown parser rather than dropping the review. */
@@ -1,3 +1,4 @@
1
+ import { referenceIds } from "../review/references.js";
1
2
  const SEVERITIES = ["P0", "P1", "P2", "P3"];
2
3
  /** OpenRouter `response_format` for a review. Providers that ignore it still
3
4
  * get the prompt's instruction to return a fenced JSON block. */
@@ -23,6 +24,7 @@ export const FINDINGS_JSON_SCHEMA = {
23
24
  title: { type: "string" },
24
25
  body: { type: "string" },
25
26
  suggestion: { type: "string" },
27
+ references: { type: "array", items: { type: "string" } },
26
28
  },
27
29
  required: ["severity", "path", "lineFrom", "title", "body"],
28
30
  },
@@ -48,7 +50,7 @@ export const FINDINGS_JSON_SCHEMA = {
48
50
  };
49
51
  /** The prompt's contract, kept next to the schema so the two cannot drift. */
50
52
  export const FINDINGS_JSON_INSTRUCTIONS = `Return a single JSON object, and nothing else, with this shape:
51
- {"findings":[{"severity":"P1","blocking":true,"path":"src/a.ts","lineFrom":42,"lineTo":42,"symbol":"helper()","title":"The helper ignores its argument","body":"One sentence on what is wrong and its impact, then a short evidence paragraph.","suggestion":"the exact replacement lines, or omit this field"}],"previousFindings":[{"id":"F1","state":"open"}]}
53
+ {"findings":[{"severity":"P1","blocking":true,"path":"src/a.ts","lineFrom":42,"lineTo":42,"symbol":"helper()","title":"The helper ignores its argument","body":"One sentence on what is wrong and its impact, then a short evidence paragraph.","suggestion":"the exact replacement lines, or omit this field","references":["R12"]}],"previousFindings":[{"id":"F1","state":"open"}]}
52
54
 
53
55
  Rules for the JSON:
54
56
  - "severity" is exactly one of P0, P1, P2, P3. "blocking" is true or false.
@@ -56,7 +58,7 @@ Rules for the JSON:
56
58
  column, never counted from the @@ header. "lineTo" may equal "lineFrom".
57
59
  - "title" is one sentence naming the defect, without the severity or the path.
58
60
  - "body" is the explanation. Do not repeat the title, the path, or the location
59
- line inside it; our code renders those. Do not add a closing sentence asking
61
+ line inside it. Our code renders those. Do not add a closing sentence asking
60
62
  whether to explain more, and do not use the words Mechanism, Symptom,
61
63
  Scenario, Verified, Repro, Options, or Scope as labels.
62
64
  - "suggestion" holds only the replacement source lines, with their original
@@ -64,6 +66,10 @@ Rules for the JSON:
64
66
  hunk of the same file. Omit it otherwise. Never wrap it in a code fence.
65
67
  - When a fix needs removed lines, another file, or more than one hunk, omit
66
68
  "suggestion".
69
+ - "references" lists what the finding rests on: the bracketed id at the end
70
+ of a guide or repository instruction line (such as R12 or I3),
71
+ "codebase:<section title>" for a CODEBASE CONVENTIONS section, or "system"
72
+ when it rests only on these review instructions. Name only ids you used.
67
73
  - Return every independently actionable finding, including none: use
68
74
  {"findings":[]} when the change is clean. Never invent a finding to fill the
69
75
  array.`;
@@ -125,9 +131,16 @@ function findingMarkdown(raw) {
125
131
  const lineTo = asNumber(raw.lineTo) ?? lineFrom;
126
132
  const span = lineTo === lineFrom ? `${lineFrom}` : `${lineFrom}-${lineTo}`;
127
133
  const suggestion = asSource(raw.suggestion);
134
+ const references = referenceIds(raw.references)
135
+ // One line per finding: a comma or a newline in an id would split it.
136
+ .map((id) => id.replace(/[,\r\n]+/g, " ").trim())
137
+ .filter(Boolean);
128
138
  const lines = [
129
139
  `### [${level} · ${impact}] \`${path}\`${symbol ? `: \`${symbol}\`` : ""}`,
130
140
  `Location: \`${path}:${span}\``,
141
+ // Read back by `parseFindings` and never shown as is: code turns the ids
142
+ // into references.
143
+ ...(references.length ? [`References: ${references.join(", ")}`] : []),
131
144
  "",
132
145
  asText(raw.body),
133
146
  ];
@@ -14,7 +14,7 @@ export function githubFileToRevisionFile(file) {
14
14
  const additions = Number(file.additions ?? 0);
15
15
  const deletions = Number(file.deletions ?? 0);
16
16
  const patch = String(file.patch ?? "");
17
- // GitHub omits large text patches; do not treat that as binary.
17
+ // GitHub omits large text patches. Do not treat that as binary.
18
18
  const binary = false;
19
19
  return {
20
20
  path,
@@ -1,10 +1,9 @@
1
1
  /** The severity legend and the review-copy rule.
2
2
  *
3
3
  * Product text avoids the em dash and the semicolon: the docs linter rejects
4
- * them, and the finding parser had to accept both a `—` and a `:` heading
4
+ * them, and the finding parser had to accept both a dash and a `:` heading
5
5
  * separator only because the prompt itself modelled the em dash. The colon is
6
- * the one separator now. The legacy parser still reads an em dash heading so
7
- * comments posted before 0.5.0 stay readable. */
6
+ * the one separator now. */
8
7
  /** `[P2] path: symbol` headings and `Summary: 3 new, 1 open, ...` lines are
9
8
  * built from this legend, so the four levels read the same everywhere. */
10
9
  export declare const SEVERITY_LEGEND: ReadonlyArray<{
@@ -1,10 +1,9 @@
1
1
  /** The severity legend and the review-copy rule.
2
2
  *
3
3
  * Product text avoids the em dash and the semicolon: the docs linter rejects
4
- * them, and the finding parser had to accept both a `—` and a `:` heading
4
+ * them, and the finding parser had to accept both a dash and a `:` heading
5
5
  * separator only because the prompt itself modelled the em dash. The colon is
6
- * the one separator now. The legacy parser still reads an em dash heading so
7
- * comments posted before 0.5.0 stay readable. */
6
+ * the one separator now. */
8
7
  /** `[P2] path: symbol` headings and `Summary: 3 new, 1 open, ...` lines are
9
8
  * built from this legend, so the four levels read the same everywhere. */
10
9
  export const SEVERITY_LEGEND = [