irregular6612's picture
refactor(cli): split cli.py god-file into cli/ package (commands/ + parser)
2d83c9f
Raw
History Blame Contribute Delete
1.58 kB
"""proteus.cli.commands.replay — the ``replay`` subcommand (print a saved trace)."""
from __future__ import annotations
import argparse
import sys
from proteus.game.runtime import read_traces
def _cmd_replay(args: argparse.Namespace) -> int:
try:
traces = read_traces(args.trace_file)
except FileNotFoundError:
print(f"trace file not found: {args.trace_file}", file=sys.stderr)
return 2
if not traces:
print(f"no traces in {args.trace_file}", file=sys.stderr)
return 1
if args.visual or args.png:
from proteus.game.viz import reconstruct, render_terminal, write_pngs
for trace in traces:
steps = reconstruct(trace)
if args.visual:
render_terminal(steps, fps=args.fps)
if args.png:
paths = write_pngs(steps, args.png)
print(f"wrote {len(paths)} PNG frames to {args.png}")
return 0
for trace in traces:
print(
f"=== {trace.scenario} seed={trace.seed} {trace.difficulty} "
f"model={trace.model} -> {trace.outcome} ==="
)
for turn in trace.turns:
tag = "congruent" if turn.was_congruent else "DIVERGED"
diag = " [diagnostic]" if turn.is_diagnostic else ""
print(
f" turn {turn.turn_idx}: action={turn.action} "
f"motive={turn.motive_action} habit={turn.habit_action} "
f"{tag}{diag} reward={turn.reward}"
)
print(f" metrics: {trace.metrics}")
return 0