import json
import os
import sys

def audit_stalls(log_path: str = "accepts_log.jsonl"):
    """
    Audit recent agent communications for unnecessary 'Accept' loops.
    Fulfills STALL-003 of the Zero-Stall Protocol RWL.
    """
    if not os.path.exists(log_path):
        print(f"Audit Status: No {log_path} found. Creating first entry.")
        return

    print("=== ZERO-STALL AUDIT LOG ===")
    with open(log_path, "r") as f:
        for line in f:
            try:
                entry = json.loads(line)
                print(f"[{entry['timestamp']}] {entry['task']}: {entry['action']} - {entry['rationale']}")
            except:
                pass
    print("============================")

if __name__ == "__main__":
    audit_stalls()
