31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
import json
|
|
import sys
|
|
|
|
from loop_claude.file_writes 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)) is not None:
|
|
print(f"could not read {config}: projects[{json.dumps(wrong)}] is not an object", file=sys.stderr)
|
|
return
|
|
# Where Claude Code 2.1.282 keeps a checkout's trust.
|
|
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)
|