clud-bug 0.6.34 → 0.7.0-rc.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.
Files changed (110) hide show
  1. package/bin/clud-bug.js +10 -1353
  2. package/dist/cli/agents-md.d.ts +16 -0
  3. package/dist/cli/agents-md.d.ts.map +1 -0
  4. package/dist/cli/agents-md.js +226 -0
  5. package/dist/cli/agents-md.js.map +1 -0
  6. package/dist/cli/audit.d.ts +13 -0
  7. package/dist/cli/audit.d.ts.map +1 -0
  8. package/dist/cli/audit.js +90 -0
  9. package/dist/cli/audit.js.map +1 -0
  10. package/dist/cli/branch-protection.d.ts +57 -0
  11. package/dist/cli/branch-protection.d.ts.map +1 -0
  12. package/dist/cli/branch-protection.js +118 -0
  13. package/dist/cli/branch-protection.js.map +1 -0
  14. package/dist/cli/edit-workflow.d.ts +18 -0
  15. package/dist/cli/edit-workflow.d.ts.map +1 -0
  16. package/dist/cli/edit-workflow.js +43 -0
  17. package/dist/cli/edit-workflow.js.map +1 -0
  18. package/dist/cli/index.d.ts +8 -0
  19. package/dist/cli/index.d.ts.map +1 -0
  20. package/dist/cli/index.js +18 -0
  21. package/dist/cli/index.js.map +1 -0
  22. package/dist/cli/main.d.ts +3 -0
  23. package/dist/cli/main.d.ts.map +1 -0
  24. package/dist/cli/main.js +1336 -0
  25. package/dist/cli/main.js.map +1 -0
  26. package/dist/cli/skill-usage.d.ts +109 -0
  27. package/dist/cli/skill-usage.d.ts.map +1 -0
  28. package/dist/cli/skill-usage.js +380 -0
  29. package/dist/cli/skill-usage.js.map +1 -0
  30. package/dist/cli/skills.d.ts +56 -0
  31. package/dist/cli/skills.d.ts.map +1 -0
  32. package/dist/cli/skills.js +292 -0
  33. package/dist/cli/skills.js.map +1 -0
  34. package/dist/cli/update.d.ts +29 -0
  35. package/dist/cli/update.d.ts.map +1 -0
  36. package/dist/cli/update.js +186 -0
  37. package/dist/cli/update.js.map +1 -0
  38. package/dist/cli/usage.d.ts +142 -0
  39. package/dist/cli/usage.d.ts.map +1 -0
  40. package/dist/cli/usage.js +348 -0
  41. package/dist/cli/usage.js.map +1 -0
  42. package/dist/core/audit.d.ts +8 -0
  43. package/dist/core/audit.d.ts.map +1 -0
  44. package/dist/core/audit.js +47 -0
  45. package/dist/core/audit.js.map +1 -0
  46. package/dist/core/detect.d.ts +77 -0
  47. package/dist/core/detect.d.ts.map +1 -0
  48. package/dist/core/detect.js +262 -0
  49. package/dist/core/detect.js.map +1 -0
  50. package/dist/core/index.d.ts +11 -0
  51. package/dist/core/index.d.ts.map +1 -0
  52. package/dist/core/index.js +31 -0
  53. package/dist/core/index.js.map +1 -0
  54. package/dist/core/prompt-builder.d.ts +164 -0
  55. package/dist/core/prompt-builder.d.ts.map +1 -0
  56. package/dist/core/prompt-builder.js +419 -0
  57. package/dist/core/prompt-builder.js.map +1 -0
  58. package/dist/core/prompts.d.ts +9 -0
  59. package/dist/core/prompts.d.ts.map +1 -0
  60. package/dist/core/prompts.js +401 -0
  61. package/dist/core/prompts.js.map +1 -0
  62. package/dist/core/render-review.d.ts +6 -0
  63. package/dist/core/render-review.d.ts.map +1 -0
  64. package/dist/core/render-review.js +219 -0
  65. package/dist/core/render-review.js.map +1 -0
  66. package/dist/core/render.d.ts +13 -0
  67. package/dist/core/render.d.ts.map +1 -0
  68. package/dist/core/render.js +80 -0
  69. package/dist/core/render.js.map +1 -0
  70. package/dist/core/review-schema-zod.d.ts +240 -0
  71. package/dist/core/review-schema-zod.d.ts.map +1 -0
  72. package/dist/core/review-schema-zod.js +218 -0
  73. package/dist/core/review-schema-zod.js.map +1 -0
  74. package/dist/core/review-schema.d.ts +42 -0
  75. package/dist/core/review-schema.d.ts.map +1 -0
  76. package/dist/core/review-schema.js +156 -0
  77. package/dist/core/review-schema.js.map +1 -0
  78. package/dist/core/review-writeback.d.ts +139 -0
  79. package/dist/core/review-writeback.d.ts.map +1 -0
  80. package/dist/core/review-writeback.js +313 -0
  81. package/dist/core/review-writeback.js.map +1 -0
  82. package/dist/core/skills.d.ts +122 -0
  83. package/dist/core/skills.d.ts.map +1 -0
  84. package/dist/core/skills.js +636 -0
  85. package/dist/core/skills.js.map +1 -0
  86. package/package.json +30 -4
  87. package/{lib/agents-md.js → src/cli/agents-md.ts} +25 -14
  88. package/{lib/audit.js → src/cli/audit.ts} +37 -44
  89. package/{lib/branch-protection.js → src/cli/branch-protection.ts} +75 -11
  90. package/{lib/edit-workflow.js → src/cli/edit-workflow.ts} +32 -11
  91. package/src/cli/index.ts +101 -0
  92. package/src/cli/main.ts +1376 -0
  93. package/{lib/skill-usage.js → src/cli/skill-usage.ts} +168 -94
  94. package/src/cli/skills.ts +386 -0
  95. package/{lib/update.js → src/cli/update.ts} +68 -27
  96. package/{lib/usage.js → src/cli/usage.ts} +167 -76
  97. package/src/core/audit.ts +53 -0
  98. package/{lib/detect.js → src/core/detect.ts} +100 -47
  99. package/src/core/index.ts +155 -0
  100. package/src/core/prompt-builder.ts +561 -0
  101. package/{lib/prompts.js → src/core/prompts.ts} +16 -2
  102. package/{lib/render-review.js → src/core/render-review.ts} +57 -25
  103. package/{lib/render.js → src/core/render.ts} +36 -10
  104. package/src/core/review-schema-zod.ts +262 -0
  105. package/{lib/review-schema.js → src/core/review-schema.ts} +68 -5
  106. package/src/core/review-writeback.ts +446 -0
  107. package/{lib/skills.js → src/core/skills.ts} +339 -342
  108. package/templates/workflow-py.yml.tmpl +2 -2
  109. package/templates/workflow-ts.yml.tmpl +2 -2
  110. package/templates/workflow.yml.tmpl +17 -8
@@ -0,0 +1,446 @@
1
+ // SPEC §1.8.1 doc-file renderer for `docs/reviews/PR-<n>.md`.
2
+ //
3
+ // This is the PURE rendering half of the App's `lib/review-writeback.ts`.
4
+ // The Octokit-side WRITEBACK (branch detection, idempotent rewrite,
5
+ // Contents-API commit) stays App-side — that surface depends on Octokit
6
+ // which we don't want to pull into core.
7
+ //
8
+ // Renamed from the App's `renderReview` to `renderReviewFile` to avoid
9
+ // colliding with the CLI's existing `renderReview` (which renders the
10
+ // summary-PR-comment shape, not the doc-file). Both renderers coexist:
11
+ // - `renderReview` (./render-review.ts) → `## 🐛 Clud Bug review` PR comment
12
+ // - `renderReviewFile` (this module) → `# clud-bug review — PR #N` doc file
13
+ //
14
+ // SPEC pins honored here:
15
+ // - `<!-- protocol-version: 0.1.0 -->` — SPEC version.
16
+ // - `<!-- written-by: clud-bug[bot] -->` — App identity, not Action.
17
+ // - `<!-- review-sha: <40-char-head-sha> -->` — pinned to review-time HEAD.
18
+ // - Severity bucket order: red → yellow → purple.
19
+ // - Empty buckets omitted entirely (no empty headers).
20
+ // - "Resolved this round:" and "Still open:" blocks omitted when empty
21
+ // (D.2.0 always omits — multi-pass is D.2.5).
22
+ // - Trailing `---\n[Link to PR](<url>)` line preserved verbatim.
23
+ // - Emoji codepoints: U+1F534, U+1F7E1, U+1F7E3, NFC-normalized.
24
+
25
+ import {
26
+ deriveSkillsReferenced,
27
+ deriveSummaryCounts,
28
+ flattenFindings,
29
+ type Finding,
30
+ type Review,
31
+ } from './review-schema-zod.js';
32
+
33
+ /** Protocol version this implementation emits. */
34
+ export const PROTOCOL_VERSION = '0.1.0';
35
+
36
+ /** "Written by" tag for the App writeback (SPEC §6.1). */
37
+ export const WRITTEN_BY = 'clud-bug[bot]';
38
+
39
+ // Severity emoji per SPEC §1.8.1. We define them by codepoint so a stray
40
+ // editor that switches encoding can't silently break byte-equality with
41
+ // the Action-runner output. Same constants as render-review.ts but kept
42
+ // local so this module is independent of the CLI renderer.
43
+ export const SEVERITY_EMOJI = {
44
+ critical: '\u{1F534}', // U+1F534 RED CIRCLE
45
+ minor: '\u{1F7E1}', // U+1F7E1 YELLOW CIRCLE
46
+ preexisting: '\u{1F7E3}', // U+1F7E3 PURPLE CIRCLE
47
+ } as const;
48
+
49
+ export interface RenderReviewFileInput {
50
+ review: Review;
51
+ prNumber: number;
52
+ /** 40-char head SHA. Pinned to `<!-- review-sha: ... -->`. */
53
+ headSha: string;
54
+ /** GitHub PR URL — appended verbatim to the trailing rule. */
55
+ prUrl: string;
56
+ }
57
+
58
+ /**
59
+ * Renders the review object to the SPEC §1.8.1 markdown template.
60
+ *
61
+ * Pure: no I/O, no time-of-day, no provider info — fixture-stable.
62
+ *
63
+ * NB: This produces the doc-file shape (`# clud-bug review — PR #N` H1).
64
+ * The CLI's `renderReview` produces the PR-comment shape (`## 🐛 Clud Bug
65
+ * review` H2). Both are valid review outputs; SPEC §6.2 says they share
66
+ * the underlying finding data but differ in container.
67
+ */
68
+ export function renderReviewFile(input: RenderReviewFileInput): string {
69
+ const { review, prNumber, headSha, prUrl } = input;
70
+ // Wire-shape Review carries findings in 3 severity arrays. Flatten to
71
+ // internal `Finding[]` so the renderer's bucketing, count-derivation,
72
+ // and per-skill aggregation can work uniformly.
73
+ const findings = flattenFindings(review);
74
+
75
+ // Always derive these from findings to guarantee they match what we
76
+ // actually render. The model can drift on counts; we don't trust it.
77
+ const counts = deriveSummaryCounts(findings);
78
+ const skillsReferenced = deriveSkillsReferenced(findings);
79
+
80
+ const lines: string[] = [];
81
+
82
+ lines.push(`# clud-bug review — PR #${prNumber}`);
83
+ lines.push(`<!-- protocol-version: ${PROTOCOL_VERSION} -->`);
84
+ lines.push(`<!-- written-by: ${WRITTEN_BY} -->`);
85
+ lines.push(`<!-- review-sha: ${headSha} -->`);
86
+ lines.push('');
87
+
88
+ // Summary line — SPEC §1.8.1 wording.
89
+ lines.push(
90
+ `**Summary:** ${counts.critical} critical · ${counts.minor} minor · ${counts.preexisting} preexisting · ${counts.resolved_from_prior} resolved-from-prior · ${counts.still_open} still-open`,
91
+ );
92
+ lines.push('');
93
+
94
+ // Skills cited block — group findings per skill for citation counts.
95
+ lines.push('**Skills cited:**');
96
+ if (skillsReferenced.length === 0) {
97
+ lines.push('- _(none — see summary above)_');
98
+ } else {
99
+ for (const slug of skillsReferenced) {
100
+ const count = findings.filter((f) => f.skill === slug).length;
101
+ lines.push(`- ${slug} (${count} finding${count === 1 ? '' : 's'})`);
102
+ }
103
+ }
104
+ lines.push('');
105
+
106
+ lines.push('**Findings:**');
107
+ lines.push('');
108
+
109
+ // Severity buckets in SPEC order; empty buckets are omitted entirely.
110
+ const bucketed = bucketBySeverity(findings);
111
+ if (bucketed.critical.length > 0) {
112
+ lines.push(`### ${SEVERITY_EMOJI.critical} Critical`);
113
+ for (const f of bucketed.critical) lines.push(renderFinding(f, true));
114
+ lines.push('');
115
+ }
116
+ if (bucketed.minor.length > 0) {
117
+ lines.push(`### ${SEVERITY_EMOJI.minor} Minor`);
118
+ for (const f of bucketed.minor) lines.push(renderFinding(f, false));
119
+ lines.push('');
120
+ }
121
+ if (bucketed.preexisting.length > 0) {
122
+ lines.push(`### ${SEVERITY_EMOJI.preexisting} Preexisting (informational)`);
123
+ for (const f of bucketed.preexisting) lines.push(renderFinding(f, false));
124
+ lines.push('');
125
+ }
126
+
127
+ // D.2.0 never emits "Resolved this round" / "Still open" — both lists
128
+ // are empty until D.2.5 (multi-pass tracking). SPEC §1.8.1 says these
129
+ // blocks MUST be omitted when empty.
130
+
131
+ lines.push('---');
132
+ lines.push('');
133
+ lines.push(`[Link to PR](${prUrl})`);
134
+
135
+ // Final NFC normalization — guarantees the emoji codepoints stay
136
+ // composed even if a future renderer step decomposes them.
137
+ return lines.join('\n').normalize('NFC') + '\n';
138
+ }
139
+
140
+ function bucketBySeverity(findings: Finding[]): Record<
141
+ 'critical' | 'minor' | 'preexisting',
142
+ Finding[]
143
+ > {
144
+ return {
145
+ critical: findings.filter((f) => f.severity === 'critical'),
146
+ minor: findings.filter((f) => f.severity === 'minor'),
147
+ preexisting: findings.filter((f) => f.severity === 'preexisting'),
148
+ };
149
+ }
150
+
151
+ function renderFinding(f: Finding, includeReasoning: boolean): string {
152
+ // findingItemSchema.file is z.string().optional() — the model is
153
+ // instructed to always provide it, but Zod doesn't enforce. Without
154
+ // the fallback an absent file would emit literal "undefined" in the
155
+ // committed SPEC §1.8.1 doc file. clud-bug-review #158 flagged this.
156
+ const fileLabel = f.file ?? '(unknown file)';
157
+ const location = f.line ? `${fileLabel}:${f.line}` : fileLabel;
158
+ // Per SPEC §1.8.1: "**<file>:<line>** — <skill-name>: <one-line summary>".
159
+ const head = `- **${location}** — ${f.skill}: ${f.summary}`;
160
+ // Reasoning line is documented for the Critical bucket; we follow the
161
+ // SPEC template strictly. For Minor/Preexisting, no reasoning line.
162
+ if (includeReasoning && f.reasoning) {
163
+ return `${head}\n Reasoning: ${f.reasoning}`;
164
+ }
165
+ return head;
166
+ }
167
+
168
+ // ---------------------------------------------------------------------------
169
+ // D.2.5 multi-pass renderer
170
+ // ---------------------------------------------------------------------------
171
+
172
+ /**
173
+ * Provenance label for a single finding's attribution from one pass.
174
+ * Mirrors the App's `PassSource` discriminator.
175
+ *
176
+ * `mode === 'cross-check'`:
177
+ * - 'first' → finding raised by Pass 1
178
+ * - 'agreed' → later pass agreed
179
+ * - 'disagreed' → later pass disagreed
180
+ * - 'independent' → later pass surfaced this finding independently
181
+ *
182
+ * `mode === 'consensus'`:
183
+ * - 'first' → finding tuple unique to Pass 1
184
+ * - 'independent' → finding tuple unique to Pass N (N > 1)
185
+ * - 'agreed' → finding tuple appeared in 2+ passes (consensus)
186
+ */
187
+ export type PassSource = 'first' | 'agreed' | 'disagreed' | 'independent';
188
+
189
+ export interface PassAttribution {
190
+ /** 1-indexed pass number — matches the spec's "[Pass N]" label. */
191
+ passNumber: number;
192
+ /** Role display name, e.g. "Beetle". */
193
+ roleName: string;
194
+ /** Model slug for this pass — used by the renderer for the "· Sonnet 4.6" tail. */
195
+ model: string;
196
+ /** Provenance — see PassSource doc. */
197
+ source: PassSource;
198
+ /** Optional one-line note from the pass, e.g. cross-check rationale. */
199
+ note?: string;
200
+ }
201
+
202
+ export interface UnifiedFinding extends Finding {
203
+ /** One PassAttribution per pass involved with this finding. Order: by passNumber. */
204
+ attributions: PassAttribution[];
205
+ }
206
+
207
+ /** Effective resolution verdict the multi-pass orchestrator emits. */
208
+ export type MultiPassVerdict = 'request_changes' | 'review_only' | 'clean';
209
+
210
+ /** Effective multi-pass mode. */
211
+ export type ReviewPassMode = 'cross-check' | 'consensus' | 'independent';
212
+
213
+ export interface MultiPassReview {
214
+ /** Status header — derived from aggregated findings + mode resolution rules. */
215
+ status_header: Review['status_header'];
216
+ /** Summary counts, derived from the unified findings list. */
217
+ summary_counts: Review['summary_counts'];
218
+ /** Skills cited at least once across any pass. */
219
+ skills_referenced: string[];
220
+ /** Unified findings, with per-pass attribution. */
221
+ findings: UnifiedFinding[];
222
+ /** Effective mode (for the renderer's "(N passes · mode)" header line). */
223
+ mode: ReviewPassMode;
224
+ /** Number of passes that actually ran. */
225
+ passCount: number;
226
+ /** Role labels per pass, parallel to passCount. Used by the renderer. */
227
+ roles: Array<{ passNumber: number; roleName: string; model: string }>;
228
+ /** Resolution verdict — see App's multi-pass-aggregator for derivation. */
229
+ verdict: MultiPassVerdict;
230
+ }
231
+
232
+ export interface RenderMultiPassMarkdownInput {
233
+ review: MultiPassReview;
234
+ prNumber: number;
235
+ /** 40-char head SHA. Pinned to `<!-- review-sha: ... -->`. */
236
+ headSha: string;
237
+ /** GitHub PR URL — appended verbatim to the trailing rule. */
238
+ prUrl: string;
239
+ }
240
+
241
+ /**
242
+ * Renders a multi-pass review with per-pass attribution lines.
243
+ *
244
+ * Output layout (SPEC §1.8.5):
245
+ *
246
+ * # clud-bug review — PR #N (M passes · mode)
247
+ * <!-- protocol-version: ... -->
248
+ * <!-- written-by: clud-bug[bot] -->
249
+ * <!-- review-sha: ... -->
250
+ * <!-- passes: M -->
251
+ * <!-- mode: cross-check|consensus|independent -->
252
+ *
253
+ * **Summary:** ... · **Verdict:** request_changes / review_only / clean
254
+ *
255
+ * **Reviewers:**
256
+ * - Pass 1 — Beetle · anthropic/claude-sonnet-4.6
257
+ * - Pass 2 — Wasp · anthropic/claude-opus-4.7
258
+ *
259
+ * **Skills cited:** ...
260
+ *
261
+ * **Findings:**
262
+ *
263
+ * ### (red) Critical
264
+ * - [Pass 1 — Beetle · Sonnet 4.6] auth.ts:42 — race-conditions: Race condition
265
+ * Reasoning: ...
266
+ * [Pass 2 — Wasp · Opus 4.7]: (check) AGREED — same finding identified independently.
267
+ *
268
+ * ...
269
+ *
270
+ * ---
271
+ * [Link to PR](...)
272
+ *
273
+ * Pure: no I/O, no time-of-day, fixture-stable.
274
+ */
275
+ export function renderMultiPassMarkdown(
276
+ input: RenderMultiPassMarkdownInput,
277
+ ): string {
278
+ const { review, prNumber, headSha, prUrl } = input;
279
+ const lines: string[] = [];
280
+
281
+ lines.push(
282
+ `# clud-bug review — PR #${prNumber} (${review.passCount} ${
283
+ review.passCount === 1 ? 'pass' : 'passes'
284
+ } · ${review.mode})`,
285
+ );
286
+ lines.push(`<!-- protocol-version: ${PROTOCOL_VERSION} -->`);
287
+ lines.push(`<!-- written-by: ${WRITTEN_BY} -->`);
288
+ lines.push(`<!-- review-sha: ${headSha} -->`);
289
+ lines.push(`<!-- passes: ${review.passCount} -->`);
290
+ lines.push(`<!-- mode: ${review.mode} -->`);
291
+ lines.push('');
292
+
293
+ const counts = review.summary_counts;
294
+ lines.push(
295
+ `**Summary:** ${counts.critical} critical · ${counts.minor} minor · ${counts.preexisting} preexisting · ${counts.resolved_from_prior} resolved-from-prior · ${counts.still_open} still-open · **Verdict:** ${review.verdict}`,
296
+ );
297
+ lines.push('');
298
+
299
+ lines.push('**Reviewers:**');
300
+ for (const r of review.roles) {
301
+ lines.push(`- Pass ${r.passNumber} — ${r.roleName} · ${r.model}`);
302
+ }
303
+ lines.push('');
304
+
305
+ lines.push('**Skills cited:**');
306
+ if (review.skills_referenced.length === 0) {
307
+ lines.push('- _(none — see summary above)_');
308
+ } else {
309
+ for (const slug of review.skills_referenced) {
310
+ const count = review.findings.filter((f) => f.skill === slug).length;
311
+ lines.push(`- ${slug} (${count} finding${count === 1 ? '' : 's'})`);
312
+ }
313
+ }
314
+ lines.push('');
315
+
316
+ lines.push('**Findings:**');
317
+ lines.push('');
318
+
319
+ // Severity buckets in SPEC order; empty buckets are omitted entirely.
320
+ const bucketed = bucketUnifiedBySeverity(review.findings);
321
+ if (bucketed.critical.length > 0) {
322
+ lines.push(`### ${SEVERITY_EMOJI.critical} Critical`);
323
+ for (const f of bucketed.critical)
324
+ lines.push(renderUnifiedFinding(f, /* includeReasoning */ true));
325
+ lines.push('');
326
+ }
327
+ if (bucketed.minor.length > 0) {
328
+ lines.push(`### ${SEVERITY_EMOJI.minor} Minor`);
329
+ for (const f of bucketed.minor) lines.push(renderUnifiedFinding(f, false));
330
+ lines.push('');
331
+ }
332
+ if (bucketed.preexisting.length > 0) {
333
+ lines.push(`### ${SEVERITY_EMOJI.preexisting} Preexisting (informational)`);
334
+ for (const f of bucketed.preexisting)
335
+ lines.push(renderUnifiedFinding(f, false));
336
+ lines.push('');
337
+ }
338
+
339
+ lines.push('---');
340
+ lines.push('');
341
+ lines.push(`[Link to PR](${prUrl})`);
342
+
343
+ return lines.join('\n').normalize('NFC') + '\n';
344
+ }
345
+
346
+ function bucketUnifiedBySeverity(findings: UnifiedFinding[]): Record<
347
+ 'critical' | 'minor' | 'preexisting',
348
+ UnifiedFinding[]
349
+ > {
350
+ return {
351
+ critical: findings.filter((f) => f.severity === 'critical'),
352
+ minor: findings.filter((f) => f.severity === 'minor'),
353
+ preexisting: findings.filter((f) => f.severity === 'preexisting'),
354
+ };
355
+ }
356
+
357
+ /**
358
+ * Renders one finding with inline per-pass attribution. The headline carries
359
+ * the FIRST attribution (whichever pass raised the issue); subsequent
360
+ * attributions appear on indented sub-lines:
361
+ *
362
+ * - [Pass 1 — Beetle · sonnet] auth.ts:42 — race: Race condition
363
+ * Reasoning: ...
364
+ * [Pass 2 — Wasp · opus]: (check) AGREED — confirmed by independent review.
365
+ * [Pass 3 — Mantis · opus]: (x) DISAGREED — guarded by the surrounding lock.
366
+ *
367
+ * The headline always tracks the FIRST attribution to preserve the SPEC
368
+ * §1.8.1 grep pattern (`**<file>:<line>** — <skill>: <summary>`).
369
+ */
370
+ function renderUnifiedFinding(
371
+ f: UnifiedFinding,
372
+ includeReasoning: boolean,
373
+ ): string {
374
+ // Same guard as renderFinding — findingItemSchema.file is optional.
375
+ const fileLabel = f.file ?? '(unknown file)';
376
+ const location = f.line ? `${fileLabel}:${f.line}` : fileLabel;
377
+ const head = f.attributions[0];
378
+ if (!head) {
379
+ // Defensive — shouldn't happen; the aggregator guarantees ≥1 attribution.
380
+ return `- **${location}** — ${f.skill}: ${f.summary}`;
381
+ }
382
+ const headLabel = formatAttributionLabel(head);
383
+ const lines: string[] = [];
384
+ lines.push(`- ${headLabel} **${location}** — ${f.skill}: ${f.summary}`);
385
+ if (includeReasoning && f.reasoning) {
386
+ lines.push(` Reasoning: ${f.reasoning}`);
387
+ }
388
+ for (let i = 1; i < f.attributions.length; i++) {
389
+ const a = f.attributions[i];
390
+ if (!a) continue;
391
+ lines.push(` ${formatFollowupAttribution(a)}`);
392
+ }
393
+ return lines.join('\n');
394
+ }
395
+
396
+ /**
397
+ * The leading bracket on the head line. Example:
398
+ *
399
+ * [Pass 1 — Beetle · anthropic/claude-sonnet-4.6]
400
+ * [Pass 2 — Wasp · anthropic/claude-opus-4.7 — found independently]
401
+ *
402
+ * "found independently" only fires when the head attribution is NOT
403
+ * `source: 'first'` — i.e. when a later pass surfaced this finding without
404
+ * Pass 1 raising it.
405
+ */
406
+ function formatAttributionLabel(a: PassAttribution): string {
407
+ const independent =
408
+ a.source === 'independent' && a.passNumber > 1
409
+ ? ' — found independently'
410
+ : '';
411
+ return `[Pass ${a.passNumber} — ${a.roleName} · ${a.model}${independent}]`;
412
+ }
413
+
414
+ /**
415
+ * Subsequent-line attribution. Example:
416
+ *
417
+ * [Pass 2 — Wasp · opus]: ✅ AGREED — confirmed.
418
+ * [Pass 3 — Mantis · opus]: ❌ DISAGREED — guarded by surrounding lock.
419
+ */
420
+ function formatFollowupAttribution(a: PassAttribution): string {
421
+ const verdictSymbol =
422
+ a.source === 'agreed'
423
+ ? '✅ AGREED' // U+2705 WHITE HEAVY CHECK MARK
424
+ : a.source === 'disagreed'
425
+ ? '❌ DISAGREED' // U+274C CROSS MARK
426
+ : a.source === 'independent'
427
+ ? 'INDEPENDENTLY FLAGGED'
428
+ : 'NOTED';
429
+ const note = a.note ? ` — ${a.note}` : '';
430
+ const disputed = a.source === 'disagreed' ? ' (Disputed — human decides.)' : '';
431
+ return `[Pass ${a.passNumber} — ${a.roleName} · ${a.model}]: ${verdictSymbol}${note}${disputed}`;
432
+ }
433
+
434
+ /** SPEC §6.1 / §1.8 path. The App's Octokit writeback uses this. */
435
+ export function reviewFilePath(prNumber: number): string {
436
+ return `docs/reviews/PR-${prNumber}.md`;
437
+ }
438
+
439
+ /**
440
+ * SPEC §6.1 commit message: exactly `[skip-logmind] clud-bug review: PR #<n>`.
441
+ * The `[skip-logmind]` prefix tells `check-decisions.yml` to ignore this
442
+ * commit (SPEC §6.4). The App's Octokit writeback uses this.
443
+ */
444
+ export function reviewCommitMessage(prNumber: number): string {
445
+ return `[skip-logmind] clud-bug review: PR #${prNumber}`;
446
+ }