#!/usr/bin/env python3
"""Fold LLM-Auto-Trader's JSON log lines into one readable line each.

The bot logs structlog JSON; at ~250 chars a line it does not fit a terminal.
This keeps every line the bot printed, just narrower — nothing is dropped
except the fields already shown in the prefix.

    python run_native_paper.py 2>&1 | python lat_view.py
"""
import json
import sys

SKIP = {"event", "level", "logger", "timestamp"}

for raw in sys.stdin:
    raw = raw.rstrip("\n")
    try:
        d = json.loads(raw)
    except ValueError:
        print(raw, flush=True)                       # [ASK]/[FILL] lines etc.
        continue
    rest = " ".join(f"{k}={v}" for k, v in d.items() if k not in SKIP)
    print(f"{d.get('timestamp','')[11:19]} {d.get('event',''):<28} {rest}", flush=True)
