diff --git a/bin/loop_claude/claude_code/formats.py b/bin/loop_claude/claude_code/formats.py index 33692f71..aa79a2a5 100644 --- a/bin/loop_claude/claude_code/formats.py +++ b/bin/loop_claude/claude_code/formats.py @@ -122,20 +122,15 @@ def structured_output(stdout): # ~/.claude.json: {"projects": {"/home/me/code/log": {"hasTrustDialogAccepted": true, ...}}, ...} -def trust_records(config): - projects = config.setdefault("projects", {}) if isinstance(config, dict) else None +def mark_trusted(config, roots): + projects = config.get("projects", {}) if isinstance(config, dict) else None if not isinstance(projects, dict): return Failure('not an object whose "projects" is an object') if (wrong := next((path for path, record in projects.items() if not isinstance(record, dict)), None)) is not None: return Failure(f"projects[{json.dumps(wrong)}] is not an object") - return projects - - -def mark_trusted(projects, roots): untrusted = [path for path in roots if not projects.get(path, {}).get("hasTrustDialogAccepted")] - for path in untrusted: - projects.setdefault(path, {})["hasTrustDialogAccepted"] = True - return untrusted + marked = {path: {**projects.get(path, {}), "hasTrustDialogAccepted": True} for path in untrusted} + return {**config, "projects": {**projects, **marked}}, untrusted # /*.json: {"fetchedAt": 1790618085238, "catalog": {"config": {"models": [{"id": "claude-opus-5-5", "name": "Opus 5.5", ...}]}}} diff --git a/bin/loop_claude/claude_code/trust.py b/bin/loop_claude/claude_code/trust.py index 715254d5..bec5ac16 100644 --- a/bin/loop_claude/claude_code/trust.py +++ b/bin/loop_claude/claude_code/trust.py @@ -1,7 +1,7 @@ import json import sys -from loop_claude.claude_code.formats import mark_trusted, trust_records +from loop_claude.claude_code.formats import mark_trusted from loop_claude.file_writes import replace_json from loop_claude.outcome import Failure @@ -13,14 +13,14 @@ def trust(config, roots): except (OSError, ValueError) as failure: print(f"could not read {config}: {getattr(failure, 'strerror', failure)}", file=sys.stderr) return - projects = trust_records(data) - if isinstance(projects, Failure): - print(f"could not read {config}: {projects.reason}", file=sys.stderr) + marked = mark_trusted(data, roots) + if isinstance(marked, Failure): + print(f"could not read {config}: {marked.reason}", file=sys.stderr) return - untrusted = mark_trusted(projects, roots) + updated, untrusted = marked if not untrusted: return - if failure := replace_json(config, data, indent=2): + if failure := replace_json(config, updated, indent=2): print(f"could not write {config}: {failure.reason}", file=sys.stderr) return print("trusted for the interrupt: " + ", ".join(untrusted), file=sys.stderr) diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 9d361fa2..6aeca665 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -85,6 +85,15 @@ class Parse(unittest.TestCase): self.assertIsNone(formats.parse("[1, 2]")) +class MarkTrusted(unittest.TestCase): + def test_returns_the_updated_config_and_leaves_the_one_it_was_handed(self): + config = {"other": 1, "projects": {"/a": {"hasTrustDialogAccepted": True}, "/b": {"kept": True}}} + handed = json.dumps(config) + self.assertEqual(formats.mark_trusted(config, ["/a", "/b", "/c"]), ({"other": 1, "projects": {"/a": {"hasTrustDialogAccepted": True}, "/b": {"hasTrustDialogAccepted": True, "kept": True}, "/c": {"hasTrustDialogAccepted": True}}}, ["/b", "/c"])) + self.assertEqual(json.dumps(config), handed) + self.assertEqual(formats.mark_trusted({}, ["/a"]), ({"projects": {"/a": {"hasTrustDialogAccepted": True}}}, ["/a"])) + + class Grounded(unittest.TestCase): def test_every_verdict_must_quote_the_transcript(self): def verdict(evidence): diff --git a/todo.md b/todo.md index 8c17f891..b7418871 100644 --- a/todo.md +++ b/todo.md @@ -8,7 +8,6 @@ The rebuild lifts every dimension, one chunk per item, until the last item opens The places the panel on `rebuild` at 7f9de5c named (`docs/decisions.md`), capping dimension first: -- **Make `mark_trusted` return the updated `~/.claude.json`, so `trust` writes what it was handed and `formats.py` mutates nothing.** Three seats: `trust_records` `setdefault`s into the config and `trust` writes `data` changed through an alias. - **Make `decode_state` check the fields' types without relying on the annotations being runtime types.** Two seats: `from __future__ import annotations` in `main.py` would fail every reload. - **State once, in `outcome.py`, that a `Failure` is retried and a `Stop` exits.** Three seats inferred it from `run_loop`. - **Define a round once, in larv-review's "Round cap", and link it from `review-findings.md` → "Rounds", the Vocabulary and the auto-reviewer's step.** All four seats held §3, "Rounds" and the Vocabulary open together to settle whether a launch counts.