60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
"""Live log viewer for overview pane. Run: python3 bin/log_view.py [--follow]"""
|
|
import sys
|
|
import time
|
|
import os
|
|
|
|
sys.path.insert(0, os.path.dirname(__file__))
|
|
from log_append import read_entries
|
|
|
|
from rich.console import Console
|
|
from rich.table import Table
|
|
from rich import box
|
|
|
|
LOG_PATH = os.path.expanduser('~/.claude/autoresearch/log.jsonl')
|
|
console = Console()
|
|
|
|
|
|
def render_table(entries):
|
|
table = Table(box=box.SIMPLE, show_header=True, header_style="bold #DA251C")
|
|
table.add_column("Time", style="dim", width=8)
|
|
table.add_column("Project", width=14)
|
|
table.add_column("Exp", width=6)
|
|
table.add_column("Description", width=42)
|
|
table.add_column("Δ", width=8, justify="right")
|
|
table.add_column("", width=2)
|
|
for e in entries[-40:]:
|
|
ts = (e.get('ts') or '')[11:16] # HH:MM from ISO8601
|
|
before = e.get('metric_before')
|
|
after = e.get('metric_after')
|
|
if before is not None and after is not None:
|
|
delta = f"{after - before:+.3f}"
|
|
delta_style = "green" if after < before else "red"
|
|
else:
|
|
delta, delta_style = "n/a", "dim"
|
|
kept = "✓" if e.get('kept') else "✗"
|
|
kept_style = "green" if e.get('kept') else "red"
|
|
table.add_row(
|
|
ts,
|
|
(e.get('project') or '?')[:14],
|
|
str(e.get('exp') or '?'),
|
|
(e.get('description') or '')[:42],
|
|
f"[{delta_style}]{delta}[/{delta_style}]",
|
|
f"[{kept_style}]{kept}[/{kept_style}]",
|
|
)
|
|
return table
|
|
|
|
|
|
if __name__ == '__main__':
|
|
follow = '--follow' in sys.argv
|
|
while True:
|
|
entries = read_entries()
|
|
console.clear()
|
|
console.print(
|
|
f"[bold #DA251C]autoresearch[/bold #DA251C] — {len(entries)} experiments",
|
|
justify="center"
|
|
)
|
|
console.print(render_table(entries))
|
|
if not follow:
|
|
break
|
|
time.sleep(5)
|