Spaces:
Sleeping
Sleeping
Update modules/codex_logger.py
Browse files- modules/codex_logger.py +40 -2
modules/codex_logger.py
CHANGED
|
@@ -1,15 +1,53 @@
|
|
|
|
|
| 1 |
# Author: Liam Grinstead
|
| 2 |
# Logs activation, mutation, and collapse with author credit and hash
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
from datetime import datetime
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
def log_artifact(agent, score, hash_val):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
log = {
|
| 8 |
-
"timestamp":
|
| 9 |
"agent_id": agent.get("id", "Unknown"),
|
| 10 |
"status": agent.get("status"),
|
| 11 |
"fitness_score": score,
|
| 12 |
"hash": hash_val,
|
| 13 |
"author": "Liam Grinstead"
|
| 14 |
}
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# codex_logger.py
|
| 2 |
# Author: Liam Grinstead
|
| 3 |
# Logs activation, mutation, and collapse with author credit and hash
|
| 4 |
+
# All logs are saved as JSON files with timestamp and SHA-512 seal
|
| 5 |
|
| 6 |
+
import json
|
| 7 |
+
import os
|
| 8 |
+
import hashlib
|
| 9 |
from datetime import datetime
|
| 10 |
|
| 11 |
+
LOG_DIR = "logs"
|
| 12 |
+
os.makedirs(LOG_DIR, exist_ok=True)
|
| 13 |
+
|
| 14 |
def log_artifact(agent, score, hash_val):
|
| 15 |
+
"""
|
| 16 |
+
Log an artifact with timestamp, agent details, fitness score, and SHA-512 seal.
|
| 17 |
+
Saves to logs directory as JSON.
|
| 18 |
+
"""
|
| 19 |
+
timestamp = datetime.utcnow().isoformat()
|
| 20 |
log = {
|
| 21 |
+
"timestamp": timestamp,
|
| 22 |
"agent_id": agent.get("id", "Unknown"),
|
| 23 |
"status": agent.get("status"),
|
| 24 |
"fitness_score": score,
|
| 25 |
"hash": hash_val,
|
| 26 |
"author": "Liam Grinstead"
|
| 27 |
}
|
| 28 |
+
|
| 29 |
+
# Seal the log entry itself
|
| 30 |
+
entry_str = json.dumps(log, sort_keys=True)
|
| 31 |
+
log["sha512"] = hashlib.sha512(entry_str.encode()).hexdigest()
|
| 32 |
+
|
| 33 |
+
# Save to file
|
| 34 |
+
filename = f"{LOG_DIR}/artifact_{timestamp}.json"
|
| 35 |
+
with open(filename, "w") as f:
|
| 36 |
+
json.dump(log, f, indent=2)
|
| 37 |
+
|
| 38 |
+
print("Artifact Logged:", log)
|
| 39 |
+
return log
|
| 40 |
+
|
| 41 |
+
def list_logs():
|
| 42 |
+
"""
|
| 43 |
+
List all saved logs.
|
| 44 |
+
"""
|
| 45 |
+
return sorted(os.listdir(LOG_DIR))
|
| 46 |
+
|
| 47 |
+
def load_log(filename):
|
| 48 |
+
"""
|
| 49 |
+
Load a specific log file.
|
| 50 |
+
"""
|
| 51 |
+
filepath = os.path.join(LOG_DIR, filename)
|
| 52 |
+
with open(filepath, "r") as f:
|
| 53 |
+
return json.load(f)
|