"""HTML views for the workflow policy and guardrail inventory (#646).""" from __future__ import annotations import html import json from webui.policy_inventory import PolicyEntry, PolicyInventorySnapshot def _source_pointer(source) -> str: path = source.path if source.anchor: path = f"{path}#{source.anchor}" return ( f"
{html.escape(path)} "
f"({html.escape(source.kind)})Active value unavailable: " f"{html.escape(entry.error)}
" ) if not entry.active: return "No live projection for this guardrail.
" pretty = json.dumps(entry.active, indent=2, sort_keys=True, default=str) return f"{html.escape(pretty)}"
def _diff_block(entry: PolicyEntry) -> str:
if entry.diff is None:
if entry.documented_default is None:
return "Diff vs documented default: not feasible (no declared default).
" return "Diff vs documented default: unavailable.
" status = entry.diff.get("status", "unknown") badge = "badge-claimed" if status == "matches_documented_default" else "badge-blocked" rows = [] for key, cell in (entry.diff.get("checked") or {}).items(): marker = "✓" if cell.get("matches") else "✗" rows.append( "{html.escape(str(key))}{html.escape(str(cell.get('expected')))}{html.escape(str(cell.get('observed')))}| Key | Documented | Active | Match | " "
|---|
{html.escape(entry.summary)}
" "" f"Some guardrails could not be built:" f"
{html.escape(snapshot.note)}
" f"" f"{build_errors}" f"{cards}" "This page is read-only. It reports enforced policy " "and never edits or weakens a gate. Secret values are redacted.
" )