Gather every Claude Code format loop-claude reads into claude_code.py, verified on 2.1.284

This commit is contained in:
2026-09-28 20:17:39 +02:00
parent b7538bd21d
commit 80629fc6d9
9 changed files with 158 additions and 114 deletions
+6 -10
View File
@@ -1,7 +1,9 @@
import json
import sys
from loop_claude.claude_code import mark_trusted, trust_records
from loop_claude.file_writes import replace_json
from loop_claude.outcome import Failure
def trust(config, roots):
@@ -11,19 +13,13 @@ def trust(config, roots):
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)
projects = trust_records(data)
if isinstance(projects, Failure):
print(f"could not read {config}: {projects.reason}", 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")]
untrusted = mark_trusted(projects, roots)
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