From 40f0b73a19b0dba0a3dd74b55961f19b5f5bc7fd Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 25 Sep 2026 17:24:16 +0200 Subject: [PATCH] Say why trust cannot read ~/.claude.json and look up trust without inserting entries --- CHANGELOG.md | 1 + bin/loop-claude | 10 ++++++---- bin/test_loop_claude.py | 26 ++++++++++++++++++++++++++ todo.md | 1 - 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d62dbcb..f76f6faa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - `loop-claude` exits 2 when an interrupt gets no answer, saying why: stdin or stdout is not a terminal, or nothing was typed. Rerunning resumes the session. - `loop-claude` archives each session's transcript under `~/.claude/loop-claude-transcripts/`, one folder per project; `LOOP_CLAUDE_TRANSCRIPTS` overrides the root. - `loop-claude` runs at the checkout root wherever inside the checkout it is started. +- `loop-claude` says why when it cannot read `~/.claude.json` before an interrupt, which then lands in the trust dialog. - `loop-claude --help` names the Claude Code version its transcript, session and trust handling were observed on; check it first when an upgrade breaks a cycle. - `loop-claude` runs the model each project's settings pick; `LOOP_CLAUDE_WORKER_MODEL` and `LOOP_CLAUDE_JUDGE_MODEL` override it. This repo runs on Fable 5.1. - Reviewers share one protocol for verdicts, severities, rounds and declines: `agents/review-protocol.md`. diff --git a/bin/loop-claude b/bin/loop-claude index 9fac06f2..b0384cd6 100755 --- a/bin/loop-claude +++ b/bin/loop-claude @@ -219,15 +219,17 @@ def checkouts(): def trust(paths): config = os.path.expanduser("~/.claude.json") try: - data = json.load(open(config, encoding="utf-8")) - except (OSError, ValueError): + with open(config, encoding="utf-8") as handle: + data = json.load(handle) + except (OSError, ValueError) as failure: + print(f"could not read {config}: {failure}", file=sys.stderr) return projects = data.setdefault("projects", {}) - granted = [path for path in paths if not projects.setdefault(path, {}).get("hasTrustDialogAccepted")] + granted = [path for path in paths if not projects.get(path, {}).get("hasTrustDialogAccepted")] if not granted: return for path in granted: - projects[path]["hasTrustDialogAccepted"] = True + projects.setdefault(path, {})["hasTrustDialogAccepted"] = True staged = f"{config}.loop-claude" try: with open(staged, "w", encoding="utf-8") as handle: diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 94a0c723..f7af7ef5 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -1,6 +1,7 @@ import contextlib import importlib.machinery import importlib.util +import io import json import os import pathlib @@ -199,6 +200,31 @@ class Interrupt(unittest.TestCase): self.assertEqual(loop.interrupt(SESSION_ID, transcript, "q?"), "") +class Trust(unittest.TestCase): + def test_says_why_the_config_cannot_be_read_and_records_only_what_is_new(self): + with tempfile.TemporaryDirectory() as home, unittest.mock.patch.dict(os.environ, {"HOME": home}): + config = pathlib.Path(home, ".claude.json") + with contextlib.redirect_stderr(io.StringIO()) as err: + loop.trust(["/a"]) + self.assertIn(f"could not read {config}: ", err.getvalue()) + self.assertIn("No such file or directory", err.getvalue()) + config.write_text("{") + with contextlib.redirect_stderr(io.StringIO()) as err: + loop.trust(["/a"]) + self.assertIn(f"could not read {config}: ", err.getvalue()) + data = {"other": 1, "projects": {"/a": {"hasTrustDialogAccepted": True, "kept": 2}}} + config.write_text(json.dumps(data)) + with contextlib.redirect_stderr(io.StringIO()) as err: + loop.trust(["/a"]) + self.assertEqual(err.getvalue(), "") + self.assertEqual(json.loads(config.read_text()), data) + with contextlib.redirect_stderr(io.StringIO()) as err: + loop.trust(["/a", "/b"]) + self.assertEqual(err.getvalue(), "trusted for the interrupt: /b\n") + data["projects"]["/b"] = {"hasTrustDialogAccepted": True} + self.assertEqual(json.loads(config.read_text()), data) + + class Parse(unittest.TestCase): def test_yields_only_json_objects(self): self.assertEqual(loop.parse('{"type": "user"}'), {"type": "user"}) diff --git a/todo.md b/todo.md index c420fda9..5e83a381 100644 --- a/todo.md +++ b/todo.md @@ -4,7 +4,6 @@ Ordered by how many seats of the 2026-09-25 scoring panel (`docs/decisions.md`) named the place; each is one chunk. -- Print why when `trust` cannot read `~/.claude.json`, today a silent return that lands the interrupt in the dialog it exists to skip, and look up `hasTrustDialogAccepted` without inserting an entry per path. - Hand the counters `reload_if_edited` carries across `os.execv` outside the `LOOP_CLAUDE_` prefix `--help` documents, today `LOOP_CLAUDE_CYCLE` and `LOOP_CLAUDE_FAILURES` a user can set by mistake. - Define a human turn at `typed` in one line and name what it tests, today the definition sits in the docstring 150 lines above. - Place `larv-review`'s Re-entry section after the passes it cites, today five forward references before ยง0.