'
for v, l, c in [
(final, "Final Score", tc),
(s1, "S1 Intent", _C["teal"]),
(s2, "S2 Repo", _C["purple"]),
(s3, "S3 Code/Bio", _C["slate"]),
(s4, "S4 Replication", _C["green"]),
]
)
risks = result.get("notable_risks", [])[:5]
positives = result.get("notable_positive_evidence", [])[:4]
stage2_focus = _select_focus_rows(result.get("stage_2r_rubric", {}), negatives_first=True, limit=3)
stage3_focus = _select_focus_rows(result.get("stage_3_rubric", {}), negatives_first=False, limit=3)
if t0:
alert = (
f'
'
f'Tier Lock [T0-FLOOR]: Direct clinical framing without an explicit boundary declaration. '
f'Score ceiling at 39. Resolving this condition is required before any tier advancement.'
f'
'
)
elif score_cap is not None:
alert = (
f'
'
f'Tier Lock [CA-CAP]: Clinical-adjacent surface detected without explicit non-clinical boundary. '
f'Score ceiling at {score_cap} (T2 maximum). '
f'Adding a non-diagnostic disclaimer resolves this lock.'
f'
'
)
else:
alert = ""
risk_list = "".join(f'
{xt(str(r))}
' for r in risks) or "
No notable risks surfaced.
"
positive_list = "".join(f'
{xt(str(p))}
' for p in positives) or "
No notable positive evidence surfaced.
"
return (
f''
f'
Executive Summary
'
f'{alert}'
f'
{stats}
'
f'
'
f''
f'
TL;DR
'
f'
Decision memo
'
f'
This repository lands at {xt(str(score.get("formal_tier", "")))} '
f'with a final score of {final}/100. The result is driven more by '
f'boundary, workflow-support, and governance weaknesses than by classic code-pattern failures.
{xt(calibration_note) if calibration_note else "Authoritative scoring and surfaced policy metadata are aligned in this release line."}
'
f'
Classification applied: '
f'ca_severity={xt(ca_severity)} | '
f'score_cap={xt(str(score_cap)) if score_cap is not None else "none"} | '
f't0_floor={"active" if t0 else "clear"}
'
f''
f'
'
f''
)
def _stage_card(title: str, value: int, color: str, tip: str, focus_rows: list[dict[str, Any]], summary: str) -> str:
bar_color = _C["red"] if value < 40 else (_C["amber"] if value < 65 else color)
return (
f''
f'
'
f'
{title} {tip_icon(tip)}
'
f'
{value}
'
f'
'
f'{svg_hbar(value, 100, bar_color)}'
f'
{xt(summary)}
'
f'
{_rubric_focus_list(focus_rows)}
'
f''
)
def _config_pattern_card() -> str:
return (
f'
'
f'
'
f'
Configured, Not Rewritten
'
f'
Changing review posture does not require touching the score core
'
f'
Use stem policy simulate with a governed profile file when you want to preview a different review posture. '
f'The authoritative score path stays deterministic; the profile is surfaced as metadata and preview-only interpretation.
'
f'
If you only need the default posture, you do not need a profile file at all.
'
)
def _section2(result: dict[str, Any], s1: int, s2: int, s3: int, s4: int) -> str:
stage1_focus = _select_focus_rows(result.get("stage_1_rubric", {}), negatives_first=True, limit=4)
stage2_focus = _select_focus_rows(result.get("stage_2r_rubric", {}), negatives_first=True, limit=4)
stage3_focus = _select_focus_rows(result.get("stage_3_rubric", {}), negatives_first=False, limit=4)
stage4_focus = _select_focus_rows(result.get("stage_4_rubric", {}), negatives_first=False, limit=4)
_s3r = result.get("stage_3_rubric", {}).get("stage_3_raw_total", {})
_s3_formula = f" (raw: {_s3r['score']}/{_s3r['max']})" if _s3r.get("score") is not None and _s3r.get("max") else ""
cards = "".join([
_stage_card(
"Stage 1 — README Intent",
s1,
_C["teal"],
_STAGE_TIPS[0],
stage1_focus,
"Claim language, limitation posture, and clinical boundary wording.",
),
_stage_card(
"Stage 2R — Repo Consistency",
s2,
_C["purple"],
_STAGE_TIPS[1],
stage2_focus,
"Internal contradictions between README, workflow claims, and support surfaces.",
),
_stage_card(
"Stage 3 — Code / Bio Responsibility",
s3,
_C["slate"],
_STAGE_TIPS[2],
stage3_focus,
f"Engineering accountability, provenance, and reviewable responsibility surfaces.{_s3_formula}",
),
_stage_card(
"Stage 4 — Replication",
s4,
_C["green"],
_STAGE_TIPS[3],
stage4_focus,
"Reproducibility evidence is reported separately and does not alter the formal tier.",
),
])
return (
f''
f'
Decision Path {tip_icon("This section explains where the score came from, with rubric-level movement and detector-linked rationale where available.")}
'
f'
'
f'
Final = 0.4 × S1 + 0.2 × S2R + 0.4 × S3 − C1_penalty | Stage 4 remains a separate replication lane.
'
f'{_config_pattern_card()}'
f'
{cards}
'
f'
'
)
def _section3(integrity: dict, cc: dict) -> str:
combined: dict[str, Any] = {**integrity}
for k, v in cc.items():
if isinstance(v, dict):
combined[k] = {
"status": v.get("status", "PASS"),
"evidence": [f"count={v.get('count', 0)}"],
}
warn_pairs, pass_pairs = _code_integrity_summary(combined)
warning_cards = "".join(integrity_card(k, v) for k, v in warn_pairs)
pass_cards = "".join(integrity_card(k, v) for k, v in pass_pairs)
warning_fallback = '
No WARN/FAIL lanes surfaced.
'
hint = tip_icon(
"C1-C6: static code and governance checks. CC1-CC3: Layer 2 AST contract detectors. "
"PASS means no mapped trigger was detected in the current rule scope, not that the whole repository is mature."
)
faq = (
f'
'
f'Why can Code Integrity contain PASS while the overall score is still low?'
f'
Because Code Integrity is a narrow detector family. The formal score is still driven mainly by Stage 1, Stage 2R, and Stage 3 evidence posture.
'
f'What changed in the C4 / C5 / C6 split?'
f'
C4 is now reserved for executable fail-open exception behavior, C5 for unsupported compliance or boundary integrity claims, and C6 for mock-auth or no-auth trust-boundary signals.
'
f'
'
)
return (
f''
f'
Code Integrity & Contract {hint}
'
f'
'
f'
'
f'
Warnings First
'
f'
Mapped risk lanes that fired
'
f'
{warning_cards or warning_fallback}
'
f'
'
f'
'
f'
Clear Lanes
'
f'
What stayed quiet in the current rule scope
'
f'
{pass_cards}
'
f'{faq}'
f'
'
f'
'
)
def _section4(airi: dict) -> str:
if not airi or "covered_risks" not in airi:
return ""
pct = float(airi.get("coverage_rate", 0))
covered_n = int(airi.get("covered_count", 0))
total_n = int(airi.get("total_risks_in_detector_scope", 0))
gaps = airi.get("known_gaps", [])
all_risks = airi.get("covered_risks", [])
donut = svg_donut(pct, _C["green"], 98)
covered_counts: dict[int, int] = {d: 0 for d in range(1, 8)}
gap_counts: dict[int, int] = {d: 0 for d in range(1, 8)}
for r in all_risks:
try:
d = int(str(r.get("subdomain_id", "0")).split(".")[0])
if d in covered_counts:
covered_counts[d] += 1
except (ValueError, IndexError):
continue
for g in gaps:
try:
d = int(str(g.get("subdomain_id", "0")).split(".")[0])
if d in gap_counts:
gap_counts[d] += 1
except (ValueError, IndexError):
continue
domain_boxes = domain_card(0, covered_n, len(gaps))
domain_boxes += "".join(domain_card(d, covered_counts[d], gap_counts[d]) for d in range(1, 8))
c_rows = "".join(airi_row(r, "covered") for r in all_risks[:24])
g_rows = "".join(airi_row(g, "gap") for g in gaps)
toggle = (
f'
'
f'
'
f''
f''
f'
'
f'Click a domain card to filter. Counts are shown as covered / gaps.'
f'
'
)
table = (
f'
'
f'
ID
Risk
Domain
Covered by / Note
'
f'{c_rows}{g_rows}
'
)
src = xt(airi.get("airi_version", ""))
bundle_scope = xt(airi.get("airi_bundle_scope", ""))
snapshot = xt(airi.get("airi_upstream_snapshot_date", ""))
license_name = xt(airi.get("airi_upstream_license", ""))
attribution = xt(airi.get("airi_attribution_note", ""))
hint = tip_icon(
"Coverage counts only risks reached through local detector mappings. "
"Coverage is not a safety verdict, and unmapped review concerns remain outside the numerator."
)
faq = (
f'
'
f'What does 7 / 32 mean?'
f'
It means seven AIRI risk IDs are currently reached by active local detector mappings, out of thirty-two AIRI risk IDs in the current detector scope.
'
f'What does “why mapped” mean?'
f'
Each covered AIRI row carries a bounded explanation built from the triggered detector, the local mapping justification, and the trigger reason surfaced by the scan.
'
f'What does AIRI not prove here?'
f'
AIRI does not independently verify harm, causality, clinical failure, or legal noncompliance. It is a risk-vocabulary layer around local findings.
'
f'
'
)
mapping_pattern = (
f'
'
f'
'
f'
Mapped, Not Guessed
'
f'
AIRI rows light up through active detector mappings
'
f'
The report does not infer AIRI coverage from prose alone. '
f'Coverage appears when a local detector fires and a governed mapping exists in the current AIRI runtime bundle.
MIT AI Risk Repository Coverage {hint}{src} | airisk.mit.edu
'
f'
'
f'
'
f'
Feature Explainer
'
f'
What this section is doing
'
f'
AIRI is used here as a bounded risk-vocabulary layer around deterministic repository findings. '
f'The report uses the curated runtime bundle, not the full upstream AIRI universe.
'
f'
'
f'
{donut}
'
f'
'
f'
{covered_n} / {total_n} risks in detector scope
'
f'
Bundle scope: {bundle_scope}
'
f'
Snapshot: {snapshot} | License: {license_name}
'
f'
{attribution}
'
f'
'
f'{faq}'
f'{mapping_pattern}'
f'
'
f'
'
f'
Coverage Explorer
'
f'
Covered and gap rows
'
f'
{domain_boxes}
'
f'{toggle}{table}'
f'
'
f'
'
)
def _section5(evidence_ledger: list) -> str:
if not evidence_ledger:
return (
f'
Evidence Detail
'
f'
'
f'No evidence entries collected.
'
)
n = len(evidence_ledger)
display_rows = _compress_evidence_for_html(evidence_ledger, limit=200)
shown = len(display_rows)
chips = " ".join(
f'{l}'
for i, (s, l) in enumerate(
[
("all", f"All ({n})"),
("fail", "FAIL"),
("warn", "WARN"),
("pass", "PASS"),
("info", "INFO"),
]
)
)
rows = "".join(evidence_row(ev) for ev in display_rows)
hint = tip_icon(
"Full evidence ledger from all detectors. Filter by severity. Capped at 200 entries in HTML view."
)
compact_note = ""
if shown < min(n, 200):
compact_note = (
f'
'
f'Showing {shown} compact rows from the first {min(n, 200)} evidence entries.'
f'
'
)
th = f'style="padding:8px 5px;font-size:11px;text-align:left;color:{_C["dgray"]}"'
return (
f''
f'