"""Read-only operational-friction summaries derived from governance events.""" from __future__ import annotations from collections import Counter from dataclasses import dataclass from afk_developer.event_store import DurableEventStore, EventProjector @dataclass(frozen=True) class FrictionReport: event_count: int counters: dict[str, int] event_kinds: dict[str, int] pending_effects: dict[str, str] environment_rejection: dict[str, str] awaiting_product_validation: list[str] def build_friction_report(store: DurableEventStore) -> FrictionReport: events = store.read_events() projection = EventProjector().rebuild(store) kinds = Counter(event.kind for event in events) awaiting = [ task_id for task_id, event in projection.latest_run_events.items() if (event.get("data") or {}).get("human_validation") ] return FrictionReport( event_count=len(events), counters=dict(sorted(projection.counters.items())), event_kinds=dict(sorted(kinds.items())), pending_effects=dict(sorted(projection.pending_effects.items())), environment_rejection=dict(projection.environment_rejection), awaiting_product_validation=sorted(awaiting), )