Move the judge, the interrupt, trust and model resolution into their own modules
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import json
|
||||
import sys
|
||||
|
||||
from loop_claude.private_file import replace_json
|
||||
|
||||
|
||||
def trust(config, roots):
|
||||
try:
|
||||
with open(config, encoding="utf-8") as handle:
|
||||
data = json.load(handle)
|
||||
except (OSError, ValueError) as failure:
|
||||
print(f"could not read {config}: {getattr(failure, 'strerror', failure)}", file=sys.stderr)
|
||||
return
|
||||
projects = data.setdefault("projects", {}) if isinstance(data, dict) else None
|
||||
if not isinstance(projects, dict):
|
||||
print(f"could not read {config}: not an object whose \"projects\" is an object", file=sys.stderr)
|
||||
return
|
||||
if wrong := next((path for path, record in projects.items() if not isinstance(record, dict)), None):
|
||||
print(f"could not read {config}: projects[{json.dumps(wrong)}] is not an object", file=sys.stderr)
|
||||
return
|
||||
untrusted = [path for path in roots if not projects.get(path, {}).get("hasTrustDialogAccepted")]
|
||||
if not untrusted:
|
||||
return
|
||||
for path in untrusted:
|
||||
projects.setdefault(path, {})["hasTrustDialogAccepted"] = True
|
||||
if failure := replace_json(config, data, indent=2):
|
||||
print(f"could not write {config}: {failure.strerror}", file=sys.stderr)
|
||||
return
|
||||
print("trusted for the interrupt: " + ", ".join(untrusted), file=sys.stderr)
|
||||
Reference in New Issue
Block a user