| 98 | } |
| 99 | |
| 100 | function showCard(id, focus = false) { |
| 101 | if (state.pass === 'summary') activate(riskRules.has(id) ? 'risk' : 'slop'); |
| 102 | const host = $('card-content'); |
| 103 | host.replaceChildren(); |
| 104 | if (!Array.from($('card-picker').options).some(option => option.value === id)) { |
| 105 | const option = el('option', '', id); |
| 106 | option.value = id; |
| 107 | $('card-picker').append(option); |
| 108 | } |
| 109 | $('card-picker').value = id; |
| 110 | const audit = auditCards.get(id), metric = metricCards.get(id), rule = riskRules.get(id); |
| 111 | const heading = el('h2', '', audit?.title || metric?.title || (rule ? 'Change-risk rule' : 'Engineering rule')); |
| 112 | heading.tabIndex = -1; |
| 113 | host.append(el('p', 'card-id', id), heading); |
| 114 | if (audit) { |
| 115 | host.append(el('p', '', audit.question), definition([ |
| 116 | ['Supported patterns', data.patterns[id] || 'See the finding evidence'], |
| 117 | ['Evidence to inspect', audit.evidence], ['Exceptions and limits', audit.exceptions] |
| 118 | ])); |
| 119 | const checks = graph.nodes.filter(node => node.kind === 'check' && node.properties.rule === id); |
| 120 | const count = status => checks.filter(node => node.properties.status === status).length; |
| 121 | host.append(el('p', 'muted', `${count('completed')} completed · ${count('skipped')} skipped · ${count('error')} errors`)); |
| 122 | host.append(detail('Exact check coverage', el('pre', '', checks.map(node => `${node.properties.path}: ${node.properties.status}\n${node.properties.detail}`).join('\n\n')))); |
| 123 | } else if (metric) { |
| 124 | host.append(definition([ |
| 125 | ['Definition', metric.definition], ['Scope and unit', `${metric.scope} · ${metric.unit}`], |
| 126 | ['How to interpret it', metric.interpretation], ['Exceptions', metric.exceptions] |
| 127 | ])); |
| 128 | const nodes = graph.nodes.filter(node => node.kind === 'metric' && metricId(node) === id); |
| 129 | const measured = nodes.filter(node => ['before', 'after'].some(side => node.properties.observation[side].status === 'measured')).length; |
| 130 | host.append(el('p', 'muted', `${nodes.length} observations; ${measured} have a numeric value. These are measurements, not findings.`)); |
| 131 | const conventions = [...new Set(nodes.map(node => node.properties.convention).filter(Boolean))]; |
| 132 | host.append(el('p', 'muted', `Counting convention: ${conventions.join(', ') || 'not reported'}. Unavailable values are never zero baselines.`)); |
| 133 | const samples = nodes.map(node => { |
| 134 | const item = node.properties, sample = item.observation; |
| 135 | const value = side => describeValue(sample[side]) + (sample[side].reason ? ' — ' + sample[side].reason : ''); |
| 136 | const location = side => item[side + '_location'] ? `${item[side + '_location'].start_line}–${item[side + '_location'].end_line}` : 'no recorded range'; |
| 137 | return viewSnapshot ? `${viewSnapshot.view} @ ${viewSnapshot.state} · ${item.path}\n${sample.subject}\nSnapshot (${location('after')}): ${value('after')}` : `${item.change} · ${item.path}\n${sample.subject}\nBefore (${location('before')}): ${value('before')}\nAfter (${location('after')}): ${value('after')}\n${changeText(node)}`; |
| 138 | }); |
| 139 | host.append(detail('All recorded observations', el('pre', '', samples.join('\n\n') || 'No recorded observations for this metric in the selected scope.'))); |
| 140 | } else if (rule) { |
| 141 | host.append(badge(title(rule.level), rule.level), el('p', '', rule.reason)); |
| 142 | host.append(el('p', 'muted', `${risk.model.model}: Atomic review-priority policy, not defect probability or a confirmed bug.`)); |
| 143 | host.append(detail('Expanded threshold profile', el('pre', '', data.profile_json || 'Profile not exported'))); |
| 144 | host.append(detail('Recorded references', el('pre', '', rule.references.join('\n')))); |
| 145 | } else { |
| 146 | const finding = graph.findings.find(item => item.finding.requirement_or_rule.id === id); |
| 147 | host.append(el('p', '', finding?.finding.requirement_or_rule.explanation || 'No definition was supplied for this rule.')); |
| 148 | } |
| 149 | if (focus) heading.focus(); |
| 150 | } |
| 151 | |
| 152 | function findingBlock(number) { |
| 153 | const item = findings.get(number), finding = item.finding; |