From 4aaad015f627a2325b4c2f61afedbf88dec387a9 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 29 Sep 2026 10:24:57 +0200 Subject: [PATCH 1/3] Return the updated ~/.claude.json from mark_trusted --- bin/loop_claude/claude_code/formats.py | 12 +++--------- bin/loop_claude/claude_code/trust.py | 12 ++++++------ bin/test_loop_claude.py | 10 ++++++++++ todo.md | 1 - 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/bin/loop_claude/claude_code/formats.py b/bin/loop_claude/claude_code/formats.py index 33692f71..0a7615bb 100644 --- a/bin/loop_claude/claude_code/formats.py +++ b/bin/loop_claude/claude_code/formats.py @@ -122,20 +122,14 @@ 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 + return {**config, "projects": {**projects, **{path: {**projects.get(path, {}), "hasTrustDialogAccepted": True} for path in untrusted}}}, 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..aeb62115 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -85,6 +85,16 @@ 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"])) + self.assertEqual(formats.mark_trusted({"projects": {"/a": 1}}, ["/a"]), Failure('projects["/a"] is not an object')) + + 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. -- 2.52.0 From f4f996f124679fa28187dc22cc6bcb926a014752 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 29 Sep 2026 10:26:36 +0200 Subject: [PATCH 2/3] Drop the unit assertion the black-box test covers --- bin/test_loop_claude.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index aeb62115..6aeca665 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -92,7 +92,6 @@ class MarkTrusted(unittest.TestCase): 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"])) - self.assertEqual(formats.mark_trusted({"projects": {"/a": 1}}, ["/a"]), Failure('projects["/a"] is not an object')) class Grounded(unittest.TestCase): -- 2.52.0 From b69b37b334a256acfefa42e24be79530c3aacf3b Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 29 Sep 2026 10:27:03 +0200 Subject: [PATCH 3/3] Name the records mark_trusted adds --- bin/loop_claude/claude_code/formats.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/loop_claude/claude_code/formats.py b/bin/loop_claude/claude_code/formats.py index 0a7615bb..aa79a2a5 100644 --- a/bin/loop_claude/claude_code/formats.py +++ b/bin/loop_claude/claude_code/formats.py @@ -129,7 +129,8 @@ def mark_trusted(config, roots): 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") untrusted = [path for path in roots if not projects.get(path, {}).get("hasTrustDialogAccepted")] - return {**config, "projects": {**projects, **{path: {**projects.get(path, {}), "hasTrustDialogAccepted": True} for path in untrusted}}}, 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", ...}]}}} -- 2.52.0