-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_wander.py
More file actions
60 lines (45 loc) · 1.59 KB
/
Copy pathrun_wander.py
File metadata and controls
60 lines (45 loc) · 1.59 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
51
52
53
54
55
56
57
58
59
60
"""run_wander.py — Run the Wander Engine against a draft snapshot.
Usage:
python run_wander.py # defaults to m1/
python run_wander.py <ir.json> <snapshot.json>
"""
from __future__ import annotations
import json
import sys
from datetime import datetime, timezone
from pathlib import Path
sys.stdout.reconfigure(encoding="utf-8")
ROOT = Path(__file__).parent
M1 = ROOT / "m1"
def _load(path: Path) -> dict:
for enc in ("utf-8-sig", "utf-16", "utf-8"):
try:
return json.loads(path.read_bytes().decode(enc))
except (UnicodeDecodeError, ValueError):
continue
print(f"ERROR: cannot decode '{path}'", file=sys.stderr)
sys.exit(2)
def main() -> None:
if len(sys.argv) == 3:
ir_path = Path(sys.argv[1])
snapshot_path = Path(sys.argv[2])
alerts_dir = snapshot_path.parent / "alerts"
else:
ir_path = M1 / "ir.json"
snapshot_path = M1 / "draft_snapshot.json"
alerts_dir = M1 / "alerts"
ir = _load(ir_path)
snapshot = _load(snapshot_path)
from creative_os.engine import evaluate
trace, rendered, exit_code = evaluate(ir, snapshot)
print(rendered)
if exit_code == 1:
alerts_dir.mkdir(parents=True, exist_ok=True)
ts = datetime.now(timezone.utc).strftime("%Y-%m-%d_%H%M%S")
dest = alerts_dir / f"{ts}.txt"
dest.write_text(rendered, encoding="utf-8")
print(f"\nAlert saved -> {dest}")
else:
print("\nNo drift detected — alert not saved.")
if __name__ == "__main__":
main()