Say why trust cannot read ~/.claude.json and look up trust without inserting entries #40
@@ -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` 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` 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` 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, and the interrupt then lands in Claude Code's 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 --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.
|
- `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`.
|
- Reviewers share one protocol for verdicts, severities, rounds and declines: `agents/review-protocol.md`.
|
||||||
|
|||||||
+7
-5
@@ -219,22 +219,24 @@ def checkouts():
|
|||||||
def trust(paths):
|
def trust(paths):
|
||||||
config = os.path.expanduser("~/.claude.json")
|
config = os.path.expanduser("~/.claude.json")
|
||||||
try:
|
try:
|
||||||
data = json.load(open(config, encoding="utf-8"))
|
with open(config, encoding="utf-8") as handle:
|
||||||
except (OSError, ValueError):
|
data = json.load(handle)
|
||||||
|
except (OSError, ValueError) as failure:
|
||||||
|
print(f"could not read {config}: {getattr(failure, 'strerror', failure)}", file=sys.stderr)
|
||||||
return
|
return
|
||||||
projects = data.setdefault("projects", {})
|
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:
|
if not granted:
|
||||||
return
|
return
|
||||||
for path in granted:
|
for path in granted:
|
||||||
projects[path]["hasTrustDialogAccepted"] = True
|
projects.setdefault(path, {})["hasTrustDialogAccepted"] = True
|
||||||
staged = f"{config}.loop-claude"
|
staged = f"{config}.loop-claude"
|
||||||
try:
|
try:
|
||||||
with open(staged, "w", encoding="utf-8") as handle:
|
with open(staged, "w", encoding="utf-8") as handle:
|
||||||
json.dump(data, handle, indent=2)
|
json.dump(data, handle, indent=2)
|
||||||
os.replace(staged, config)
|
os.replace(staged, config)
|
||||||
except OSError as failure:
|
except OSError as failure:
|
||||||
print(f"could not record trust: {failure}", file=sys.stderr)
|
print(f"could not write {config}: {failure.strerror}", file=sys.stderr)
|
||||||
return
|
return
|
||||||
print("trusted for the interrupt: " + ", ".join(granted), file=sys.stderr)
|
print("trusted for the interrupt: " + ", ".join(granted), file=sys.stderr)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import contextlib
|
import contextlib
|
||||||
|
import errno
|
||||||
import importlib.machinery
|
import importlib.machinery
|
||||||
import importlib.util
|
import importlib.util
|
||||||
|
import io
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
@@ -199,6 +201,37 @@ class Interrupt(unittest.TestCase):
|
|||||||
self.assertEqual(loop.interrupt(SESSION_ID, transcript, "q?"), "")
|
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.assertEqual(err.getvalue(), f"could not read {config}: No such file or directory\n")
|
||||||
|
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)
|
||||||
|
with (
|
||||||
|
contextlib.redirect_stderr(io.StringIO()) as err,
|
||||||
|
unittest.mock.patch("os.replace", side_effect=OSError(errno.EACCES, "Permission denied")),
|
||||||
|
):
|
||||||
|
loop.trust(["/c"])
|
||||||
|
self.assertEqual(err.getvalue(), f"could not write {config}: Permission denied\n")
|
||||||
|
self.assertEqual(json.loads(config.read_text()), data)
|
||||||
|
|
||||||
|
|
||||||
class Parse(unittest.TestCase):
|
class Parse(unittest.TestCase):
|
||||||
def test_yields_only_json_objects(self):
|
def test_yields_only_json_objects(self):
|
||||||
self.assertEqual(loop.parse('{"type": "user"}'), {"type": "user"})
|
self.assertEqual(loop.parse('{"type": "user"}'), {"type": "user"})
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
## loop-claude: the trust file is rewritten before an interrupt
|
## loop-claude: the trust file is rewritten before an interrupt
|
||||||
|
|
||||||
2026-09-21, lilleman; the lost-write risk accepted 2026-09-24 by larv-review. Serves goal 4. No CLI flag skips the trust dialog, so `~/.claude.json` gets `hasTrustDialogAccepted` for every checkout before `claude --resume`. A write by another claude inside that read-modify-write window is lost. Valid while no flag skips the dialog.
|
2026-09-21, lilleman; the lost-write risk accepted 2026-09-24 by larv-review. Serves goal 4. A write by another claude inside `trust`'s read-modify-write window is lost. Valid while no flag skips the dialog.
|
||||||
|
|
||||||
## bin/: host python, no container
|
## bin/: host python, no container
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
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.
|
- 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.
|
- 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.
|
- Place `larv-review`'s Re-entry section after the passes it cites, today five forward references before §0.
|
||||||
@@ -23,3 +22,4 @@ Ordered by how many seats of the 2026-09-25 scoring panel (`docs/decisions.md`)
|
|||||||
- Group `bin/loop-claude` by the Claude Code internals it rests on, in the docstring's order, with `main` and `run_cycle` above what they call, today 36 flat names with the adapter scattered.
|
- Group `bin/loop-claude` by the Claude Code internals it rests on, in the docstring's order, with `main` and `run_cycle` above what they call, today 36 flat names with the adapter scattered.
|
||||||
- Exit `loop-claude` with a message, today a traceback, when `README.md` is not UTF-8.
|
- Exit `loop-claude` with a message, today a traceback, when `README.md` is not UTF-8.
|
||||||
- Say under `CLAUDE.md` → "One spelling per goal" that one spelling in two places is the same case, and what its rejection names.
|
- Say under `CLAUDE.md` → "One spelling per goal" that one spelling in two places is the same case, and what its rejection names.
|
||||||
|
- Say `could not read` when `~/.claude.json` parses to anything but an object whose `projects` maps paths to objects, today a traceback before the interrupt.
|
||||||
|
|||||||
Reference in New Issue
Block a user