Something went wrong. Try again.
project submission for SunsteadHack
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192#!/usr/bin/env python3"""record_judgment.py
Reads a staged membrane unit JSON and appends a structured YAML-like entryto the agent-escalation-log crossings log. Append-only operation."""
import argparseimport jsonimport sysfrom datetime import datetime, timezonefrom pathlib import Path
def main(): parser = argparse.ArgumentParser(description="Record human judgment on a membrane crossing") parser.add_argument("--input", required=True, help="Path to staged-unit.json") parser.add_argument("--decision", required=True, choices=["modify", "approve", "reject", "escalate"], help="Decision made by judge") parser.add_argument("--pore", required=True, help="Pore used for crossing") parser.add_argument("--rationale", required=True, help="Human rationale for decision") parser.add_argument("--transform", default="none", help="Transform applied if any") parser.add_argument("--judge", required=True, help="Judge agent or human ID") args = parser.parse_args()
input_path = Path(args.input) if not input_path.exists(): print(f"[record_judgment] ERROR: Input file not found: {input_path}", file=sys.stderr) sys.exit(1)
try: unit = json.loads(input_path.read_text(encoding="utf-8")) except json.JSONDecodeError as e: print(f"[record_judgment] ERROR: Failed to parse JSON: {e}", file=sys.stderr) sys.exit(1)
log_path = Path("cells/agent-escalation-log/crossings.yaml") log_path.parent.mkdir(parents=True, exist_ok=True)
timestamp = datetime.now(timezone.utc).isoformat() entry = f"""\- id: "{unit.get('unit_id', 'unknown')}" timestamp: "{timestamp}" actor: "{unit.get('actor', 'unknown')}" judge: "{args.judge}" decision: "{args.decision}" pore: "{args.pore}" rationale: "{args.rationale}" transform: "{args.transform}" unit_type: "{unit.get('unit_type', 'unknown')}" source: "{unit.get('source', 'unknown')}" affected_paths: {json.dumps(unit.get('affected_paths', []))} claim_surface_touched: {str(unit.get('claim_surface_touched', False)).lower()} model_surface_touched: {str(unit.get('model_surface_touched', False)).lower()} suggested_pore: "{unit.get('suggested_pore', 'unknown')}" created_at: "{unit.get('created_at', timestamp)}""""
# Read existing content to check if file has entries (non-comment content) existing = "" if log_path.exists(): existing = log_path.read_text(encoding="utf-8")
# Ensure YAML header/comments exist header = """\# crossings.yaml# ============# Agent escalation log for membrane crossings.# Each entry records a judgment decision on a membrane-crossing probe result.# DO NOT edit this file manually; use scripts/record_judgment.py#""" if existing.strip() and not existing.strip().startswith("#"): # Has actual entries, append log_path.write_text(existing + "\n" + entry, encoding="utf-8") else: # Just comments or empty, prepend header if needed if not existing.startswith("#"): log_path.write_text(header + entry, encoding="utf-8") else: log_path.write_text(existing.rstrip() + "\n" + entry, encoding="utf-8")
print(f"[record_judgment] Appended judgment entry to {log_path}") print(f"[record_judgment] Decision: {args.decision} | Pore: {args.pore} | Judge: {args.judge}") print(f"[record_judgment] Unit ID: {unit.get('unit_id', 'unknown')}") sys.exit(0)
if __name__ == "__main__": main()