yippie
This commit is contained in:
47
agents/modules/geoscaper/lib/state.py
Normal file
47
agents/modules/geoscaper/lib/state.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import json
|
||||
import os
|
||||
from .security import get_safe_path, STATE_DIR
|
||||
|
||||
def _load_json(filename):
|
||||
try:
|
||||
path = get_safe_path(STATE_DIR, filename)
|
||||
if os.path.exists(path):
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
except Exception:
|
||||
pass
|
||||
return {}
|
||||
|
||||
def _save_json(filename, data):
|
||||
os.makedirs(os.path.realpath(STATE_DIR), exist_ok=True)
|
||||
path = get_safe_path(STATE_DIR, filename)
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f, indent=2)
|
||||
|
||||
# --- Staging Cache (Planner) ---
|
||||
def load_staging(project_name):
|
||||
return _load_json(f"{project_name}_staging.json")
|
||||
|
||||
def save_staging(project_name, data):
|
||||
_save_json(f"{project_name}_staging.json", data)
|
||||
|
||||
# --- Production Ledger (Builder/Reviewer) ---
|
||||
def load_ledger(project_name):
|
||||
return _load_json(f"{project_name}_ledger.json")
|
||||
|
||||
def save_ledger(project_name, data):
|
||||
_save_json(f"{project_name}_ledger.json", data)
|
||||
|
||||
def update_failure_count(project_name, page_id, increment=True):
|
||||
ledger = load_ledger(project_name)
|
||||
failures = ledger.get("failure_counts", {})
|
||||
current = failures.get(page_id, 0)
|
||||
|
||||
if increment:
|
||||
failures[page_id] = current + 1
|
||||
else:
|
||||
failures[page_id] = 0
|
||||
|
||||
ledger["failure_counts"] = failures
|
||||
save_ledger(project_name, ledger)
|
||||
return failures[page_id]
|
||||
Reference in New Issue
Block a user