Repository navigation
Expand file tree
/
Copy pathmonitor.py
More file actions
50 lines (45 loc) · 1.6 KB
/
Copy pathmonitor.py
File metadata and controls
50 lines (45 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
"""Print a colored STATUS line whenever the run's state changes.
Usage: python3 monitor.py runs/<task>/<model>/<timestamp> (started by lib_run.sh)"""
import json, os, sys, time
ws = sys.argv[1]
def snapshot():
stage = "studying refs"
if os.path.exists(f"{ws}/script.md"):
stage = "script written"
n = len(os.listdir(f"{ws}/assets")) if os.path.isdir(f"{ws}/assets") else 0
if n:
stage = f"producing · {n} assets"
if os.path.exists(f"{ws}/final.mp4"):
stage = f"cut assembled · {n} assets"
if os.path.exists(f"{ws}/director_statement.md"):
stage = f"finishing · {n} assets"
credits, calls, iters, last = "?", "?", "?", ""
try:
m = json.load(open(f"{ws}/manifest.json"))
tc = m.get("tool_calls", []) or []
calls = len(tc)
credits = m.get("credits_total")
if credits is None:
credits = sum(c.get("credits_charged", 0) or 0 for c in tc)
iters = m.get("iterations", "?")
if tc:
last = tc[-1].get("purpose") or tc[-1].get("tool") or ""
last = " ".join(str(last).split())[:60]
except Exception:
pass
line = f"stage: {stage} · credits spent: {credits} · calls: {calls} · iterations: {iters}"
if last:
line += f" · last: {last}"
return line
prev = None
while True:
try:
cur = snapshot()
if cur != prev:
ts = time.strftime("%H:%M:%S")
print(f"\033[36m── STATUS {ts} · {cur}\033[0m", flush=True)
prev = cur
except Exception:
pass
time.sleep(5)