"""HTML views for the workflow policy and guardrail inventory (#646).""" from __future__ import annotations import html import json from typing import Any from webui import console_redaction from webui.policy_inventory import ( PolicyEntry, PolicyInventorySnapshot, SourcePointer, snapshot_to_dict, ) def _source_pointer(source: dict[str, Any] | SourcePointer) -> str: if isinstance(source, dict): label = str(source.get("label") or "") path = str(source.get("path") or "") anchor = source.get("anchor") kind = str(source.get("kind") or "") else: label = source.label path = source.path anchor = source.anchor kind = source.kind if anchor: path = f"{path}#{anchor}" return ( f"
{html.escape(path)} "
f"({html.escape(kind)})Active value unavailable: " f"{html.escape(error)}
" ) if not active: return "No live projection for this guardrail.
" pretty = json.dumps(active, indent=2, sort_keys=True, default=str) return f"{html.escape(pretty)}"
def _diff_block(entry: dict[str, Any] | PolicyEntry) -> str:
diff = entry.get("diff") if isinstance(entry, dict) else entry.diff
documented_default = entry.get("documented_default") if isinstance(entry, dict) else entry.documented_default
if diff is None:
if documented_default is None:
return "Diff vs documented default: not feasible (no declared default).
" return "Diff vs documented default: unavailable.
" status = str(diff.get("status") if isinstance(diff, dict) else "unknown") badge = "badge-claimed" if status == "matches_documented_default" else "badge-blocked" rows = [] checked = diff.get("checked") if isinstance(diff, dict) else {} if isinstance(checked, dict): for key, cell in checked.items(): cell_dict = cell if isinstance(cell, dict) else {} marker = "✓" if cell_dict.get("matches") else "✗" rows.append( "{html.escape(str(key))}{html.escape(str(cell_dict.get('expected')))}{html.escape(str(cell_dict.get('observed')))}| Key | Documented | Active | Match | " "
|---|
{html.escape(summary)}
" "" f"Some guardrails could not be built:" f"
{html.escape(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.
" )