Compare commits

...

10 Commits

Author SHA1 Message Date
lilleman 538fbfc8a0 Cut release 0.4.1 2026-10-31 01:33:00 +01:00
lilleman 095340da78 Merge pull request 'Open claude on a terminal with CLAUDE_CODE_SANDBOXED set, and stop writing ~/.claude.json' (#408) from item-6 into main 2026-10-31 01:03:12 +01:00
lilleman 43682c819a Answer product-owner round 1: 0 🔴, 0 🟡 (0 misread); its 🟢 is superseded by stability's deletion of the docstring sentence 2026-10-30 21:53:49 +01:00
lilleman 87a555b7cd Answer prose round 1: 0 🔴, 4 🟡 (0 misread); restore the decision's first entry, say what the variable claims, name both tools in the title and changelog 2026-10-30 21:53:49 +01:00
lilleman 4a6cad05ea Answer stability round 1: 0 🔴, 4 🟡 (0 misread); drop the stale worktree git answers, assert the routing claude's folder, keep the host's CLAUDE_CODE_SANDBOXED out of the tests, delete the docstring's trust sentence 2026-10-30 21:53:49 +01:00
lilleman fd878353bc Answer security round 1: 0 🔴, 0 🟡 (0 misread); clean 2026-10-30 21:37:25 +01:00
lilleman 6ffe432dba Expect CLAUDE_CODE_SANDBOXED in the terminal claude's environment 2026-10-30 21:32:21 +01:00
lilleman 0a0a2207c9 Open claude on a terminal with CLAUDE_CODE_SANDBOXED set, and stop writing ~/.claude.json 2026-10-30 21:31:44 +01:00
lilleman 28b714d5ca Record the reading cost of the last chunk 2026-10-30 21:31:44 +01:00
lilleman 2d60ab11bd Merge pull request 'Refuse a security-review or claude-security Skill call below the project's rung' (#407) from item-167 into main 2026-10-30 13:22:39 +01:00
17 changed files with 60 additions and 153 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ Decisions live in `docs/decisions.md`:
- larv-review: within a chunk lifting a project towards the comprehension floor, work on the project's lowest-scoring dimension comes first, and the floor doesn't block anything
- loop-claude: a `claude` that cannot start is a failed worker run, retried
- loop-claude: a judge decides each interrupt and each quoted answer from the transcript, the README's premises, `AGENTS.md`, `docs/decisions.md`, `~/.claude/CLAUDE.md`, `~/.claude/rules/` and larv-review's standards, and holds a chunk open while an answer the human typed in it is recorded nowhere; the worker's own account of which goal settles a choice decides nothing
- loop-claude: before it or loop-inbox opens claude on a terminal, it marks the checkout and each of its worktrees trusted in `~/.claude.json`
- loop-claude: every claude it or loop-inbox opens on a terminal has `CLAUDE_CODE_SANDBOXED` set, so Claude Code skips its trust dialog, and neither tool writes `~/.claude.json`
- loop-claude: each project's model lives in `~/.claude/loop-claude-models.json`, which only loop-claude writes
- loop-claude: every claude it starts bypasses permissions inside its sandbox
- loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it
+2 -1
View File
@@ -1,10 +1,11 @@
# Changelog
## Unreleased
## 0.4.1
- A release review now fixes the findings of its architecture and principles passes in the release it reviews. Before, it filed each one in `todo.md`, so the release held the drift the review had found. It files only three kinds of finding, each under the release being reviewed: one whose fix needs a human answer, marked `question`; one whose fix adds a feature; and one whose fix the five rounds cannot finish. Until each is done, the release isn't ready to cut.
- In a repo with no tag yet, `chunk-preflight` now calls a release finished once `todo.md` files no item under it: its release review is due, and no later release's item is taken. Before, it lost sight of such a release.
- In a run `loop-claude` started, `rule-hook` now refuses a `/security-review` or `/claude-security` Skill call that the worker makes in its own context on a rung below the project's. It also refuses one from any subagent whose prompt doesn't open with `You are the security pass for this chunk.`, since that subagent's rung is unchecked. The refusal says to invoke the skill from a subagent on the project's rung, its prompt opening with that sentence. Before, only an Agent call that launched the security pass was held to that rung.
- `loop-claude` and `loop-inbox` no longer write `~/.claude.json`. Each claude they open on a terminal, for `/talk`, a release ready to cut or a routing call, now has `CLAUDE_CODE_SANDBOXED=1` set, so Claude Code skips its trust dialog. Before, they marked the checkout and each worktree trusted in that file, and a write Claude Code made at the same moment could be lost. Claude Code doesn't document the variable: where a version drops it, the trust dialog comes back.
## 0.4.0
+1 -10
View File
@@ -6,7 +6,7 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from claude_code import entries, reply, transcript, trust
from claude_code import entries, reply, transcript
from failure import Failure
@@ -132,14 +132,5 @@ class ClaudeReply(unittest.TestCase):
self.assertEqual(reply.claude_reply(self.claude(FileNotFoundError(2, "No such file or directory")), [], "/r", "p", "claude"), Failure("could not start claude: No such file or directory"))
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(trust.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(trust.mark_trusted({}, ["/a"]), ({"projects": {"/a": {"hasTrustDialogAccepted": True}}}, ["/a"]))
if __name__ == "__main__":
unittest.main()
-38
View File
@@ -1,38 +0,0 @@
import json
import pathlib
import typing
from failure import Failure
from file_writes import replace_json
# A failure only warns: claude still opens, and the human answers Claude Code's trust dialog.
def trust(config: pathlib.Path, roots: list[str], note: typing.Callable[[str], None]) -> None:
try:
with open(config, encoding="utf-8") as handle:
data = json.load(handle)
except (OSError, ValueError) as failure:
note(f"could not read {config}: {getattr(failure, 'strerror', failure)}")
return
marked = mark_trusted(data, roots)
if isinstance(marked, Failure):
note(f"could not read {config}: {marked.reason}")
return
updated, untrusted = marked
if not untrusted:
return
if unwritten := replace_json(config, updated, indent=2):
note(f"could not write {config}: {unwritten.reason}")
return
note("trusted for the interrupt: " + ", ".join(untrusted))
# Claude Code's config: {"projects": {"/home/me/code/log": {"hasTrustDialogAccepted": true, ...}}, ...}
def mark_trusted(config: object, roots: list[str]) -> tuple[dict, list[str]] | Failure:
if not isinstance(config, dict) or not isinstance(projects := config.get("projects", {}), dict):
return Failure('not an object whose "projects" is an object')
if (wrong := next((path for path, settings in projects.items() if not isinstance(settings, 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")]
marked = {path: {**projects.get(path, {}), "hasTrustDialogAccepted": True} for path in untrusted}
return {**config, "projects": {**projects, **marked}}, untrusted
+1 -1
View File
@@ -82,7 +82,7 @@ def claude_open(ask: Ask, where: OpenOnTerminal | OpenInInbox, session: WorkerSe
match where:
case OpenOnTerminal():
shown(paths.waiting, dataclasses.replace(ask, state=where), effects)
if unstarted := hand_over(session.claude_command(), paths, effects):
if unstarted := hand_over(session.claude_command(), effects):
return Stop(1, f"could not start claude for the interrupt: {unstarted.reason}")
case OpenInInbox(pid):
make_way(paths.waiting, ask, pid, effects)
+6 -8
View File
@@ -1,12 +1,9 @@
"""Opens claude on the terminal for the human. It sits outside cycle/, since loop-inbox's /talk and the loop's routing calls open claude too."""
import dataclasses
from loop_claude.effects import Effects, say
from loop_claude.effects import Effects
from failure import Failure
from loop_claude.paths import Paths
from model_routing.ladder import Rung
from claude_code.trust import trust
from loop_claude.project.checkout import worktrees
@dataclasses.dataclass(frozen=True)
@@ -21,11 +18,12 @@ def claude_args(rung: Rung, args: list[str]) -> list[str]:
return [*rung.flags(), "--permission-mode", "bypassPermissions", *args]
def hand_over(command: ClaudeCommand, paths: Paths, effects: Effects) -> Failure | None:
"""Marks trusted the checkout that command runs in, and each of its worktrees, then runs claude on the terminal as command says; the failure is why claude could not start."""
trust(paths.claude_json, worktrees(command.cwd, effects), lambda text: say(text, effects))
# CLAUDE_CODE_SANDBOXED, which Claude Code doesn't document, skips its trust dialog without writing ~/.claude.json:
# docs/decisions.md → `loop-claude: every claude it or loop-inbox opens on a terminal has CLAUDE_CODE_SANDBOXED set`.
def hand_over(command: ClaudeCommand, effects: Effects) -> Failure | None:
"""Runs claude on the terminal as command says, with CLAUDE_CODE_SANDBOXED=1 added to its environment; the failure is why claude could not start."""
try:
effects.claude_on_terminal(command.args, command.cwd, command.env)
effects.claude_on_terminal(command.args, command.cwd, {**command.env, "CLAUDE_CODE_SANDBOXED": "1"})
except OSError as failure:
return Failure(str(failure.strerror))
return None
+1 -2
View File
@@ -30,8 +30,7 @@ interrupts of every loop on the machine. The first answer counts, from either pl
discuss first. Once that claude exits, the judge rules on what was typed there.
- Enter alone, on loop-claude's terminal: stops the loop.
A release ready to cut opens that session on the terminal at once, since only the human may cut it;
loop-inbox lists it too. Before claude opens, the checkout and each of its worktrees are marked
trusted in ~/.claude.json. While claude is open, Ctrl-C reaches it alone, and the loop goes on.
loop-inbox lists it too. While claude is open, Ctrl-C reaches it alone, and the loop goes on.
While it runs, loop-claude also lists itself in loop-inbox, with the todo.md items its chunk takes,
as bin/loop_claude/running_loops.py describes.
+1 -1
View File
@@ -55,7 +55,7 @@ def raise_calls(root: pathlib.Path, checkout: str, session: str, new: list[str],
prompt = f"Put these calls for a routing change from loop-claude's figures to the human, and change nothing until they answer:\n{bullets}The figures are in {root / archive.FIGURES}. The ladder, its steps and the delegation rule are docs/decisions.md → `routing:`, and a change to them is the human's. Record what they decide as ~/.claude/CLAUDE.md says; the next chunk of this repo files the plan item for these calls."
ask = Ask(effects.new_id(), session, checkout, question, effects.now(), OpenOnTerminal())
with listed(paths.waiting, ask, effects):
unstarted = hand_over(ClaudeCommand(claude_args(rung, [prompt]), str(paths.claude_dir), {}), paths, effects)
unstarted = hand_over(ClaudeCommand(claude_args(rung, [prompt]), str(paths.claude_dir), {}), effects)
if unstarted:
return Stop(1, f"could not start claude for the routing calls: {unstarted.reason}")
# Raised once the human has seen them, answered or not: an unanswered call reaches the plan through AGENTS.md, so it is not asked twice.
-2
View File
@@ -6,7 +6,6 @@ import pathlib
class Paths:
claude_code_transcripts: pathlib.Path
claude_dir: pathlib.Path
claude_json: pathlib.Path
home: pathlib.Path
model_catalog: pathlib.Path
models_file: pathlib.Path
@@ -19,7 +18,6 @@ def paths_from(home: pathlib.Path) -> Paths:
return Paths(
claude_code_transcripts=claude / "projects",
claude_dir=claude,
claude_json=home / ".claude.json",
home=home,
model_catalog=claude / "cache" / "model-catalog",
models_file=claude / "loop-claude-models.json",
-4
View File
@@ -11,7 +11,3 @@ def checkout_root(cwd: pathlib.Path, effects: Effects) -> str | Stop:
return Stop(1, found.reason) if isinstance(found, Failure) else found.strip()
def worktrees(root: str, effects: Effects) -> list[str]:
listing = effects.git("worktree", "list", "--porcelain", cwd=root)
listed = [] if isinstance(listing, Failure) else [line.split(" ", 1)[1] for line in listing.splitlines() if line.startswith("worktree ")]
return sorted({root, *listed})
+5 -51
View File
@@ -39,7 +39,7 @@ argv = sys.argv[1:]
role = "judge" if "--json-schema" in argv else "worker" if "-p" in argv else "interrupt"
scenario = pathlib.Path(os.environ["FAKE_CLAUDE_SCENARIO"])
steps = json.loads(scenario.read_text())
call = {{"argv": argv, "cwd": os.getcwd(), "role": role, "ctrl_c_ignored": signal.getsignal(signal.SIGINT) == signal.SIG_IGN}}
call = {{"argv": argv, "cwd": os.getcwd(), "role": role, "ctrl_c_ignored": signal.getsignal(signal.SIGINT) == signal.SIG_IGN, "sandboxed": os.environ.get("CLAUDE_CODE_SANDBOXED")}}
# The items each loop lists in loop-inbox as this claude starts.
call["running"] = [json.loads(path.read_text())["items"] for path in sorted((pathlib.Path.home() / ".local" / "state" / "loop-claude").glob("*.running"))]
if role == "judge":
@@ -776,9 +776,8 @@ class Interrupt(unittest.TestCase):
def test_hands_the_terminal_over_and_exits_2_when_nothing_is_typed(self):
checkout = Checkout(self)
checkout.git("commit", "--allow-empty", "--quiet", "-m", "start")
checkout.git("worktree", "add", "--quiet", str(checkout.home / "code" / "proj-wt"))
checkout.claude_json().write_text(json.dumps({"other": 1, "projects": {str(checkout.root): {"kept": True}}}))
checkout.claude_json().chmod(0o644)
claude_json = json.dumps({"projects": {str(checkout.root): {"kept": True}}})
checkout.claude_json().write_text(claude_json)
asked = [worker(say="Shall I use A or B?"), judge(interrupt=True, evidence="Shall I use A or B?", question="A or B?")]
(checkout.root / "sub").mkdir()
run = checkout.run([*asked, interrupt(type="B"), judge(evidence="B"), worker()], cwd=checkout.root / "sub", terminal_input="/talk\n", before_typing=ANSWERING)
@@ -790,12 +789,8 @@ class Interrupt(unittest.TestCase):
self.assertEqual(argument(run.calls[2], "--model"), "worker-model")
self.assertNotIn("-p", handed)
self.assertIn("[human] B", run.calls[3]["stdin"])
trusted = json.loads(checkout.claude_json().read_text())
self.assertEqual(trusted["other"], 1)
self.assertEqual(trusted["projects"][str(checkout.root)], {"hasTrustDialogAccepted": True, "kept": True})
self.assertEqual(trusted["projects"][str(checkout.home / "code" / "proj-wt")], {"hasTrustDialogAccepted": True})
self.assertEqual(stat.S_IMODE(checkout.claude_json().stat().st_mode), 0o644)
self.assertIn(f"trusted for the interrupt: {checkout.root}, {checkout.home / 'code' / 'proj-wt'}\n", run.stderr)
self.assertEqual(run.calls[2]["sandboxed"], "1")
self.assertEqual(checkout.claude_json().read_text(), claude_json)
for transcript in checkout.transcripts():
transcript.unlink()
@@ -815,47 +810,6 @@ class Interrupt(unittest.TestCase):
self.assertFalse(run.calls[2]["ctrl_c_ignored"])
self.assertIn("[human] B", run.calls[3]["stdin"])
def test_says_why_the_trust_file_cannot_be_read_and_leaves_it_as_it_was(self):
checkout = Checkout(self)
asked = [worker(say="A or B?"), judge(interrupt=True, evidence="A or B?", question="A or B?"), interrupt()]
root = json.dumps(str(checkout.root))
shapes = {
None: "No such file or directory",
"{": "Expecting property name enclosed in double quotes: line 1 column 2 (char 1)",
"[]": 'not an object whose "projects" is an object',
'{"projects": []}': 'not an object whose "projects" is an object',
f'{{"projects": {{{root}: 1}}}}': f"projects[{root}] is not an object",
}
for text, said in shapes.items():
with self.subTest(said=said):
checkout.claude_json().unlink(missing_ok=True)
if text is not None:
checkout.claude_json().write_text(text)
run = checkout.run(asked, terminal_input="/talk\n", before_typing=ANSWERING)
self.assertEqual(run.code, 2)
self.assertIn(f"could not read {checkout.claude_json()}: {said}\n", run.stderr)
self.assertEqual(checkout.claude_json().read_text() if checkout.claude_json().exists() else None, text)
trusted = json.dumps({"projects": {str(checkout.root): {"hasTrustDialogAccepted": True}}})
checkout.claude_json().write_text(trusted)
run = checkout.run(asked, terminal_input="/talk\n", before_typing=ANSWERING)
self.assertNotIn(str(checkout.claude_json()), run.stderr)
self.assertNotIn("trusted for the interrupt", run.stderr)
self.assertEqual(checkout.claude_json().read_text(), trusted)
@unittest.skipIf(os.geteuid() == 0, "root writes into a read-only directory")
def test_says_why_the_trust_file_cannot_be_written(self):
checkout = Checkout(self)
checkout.claude_json().write_text("{}")
asked = [worker(say="A or B?"), judge(interrupt=True, evidence="A or B?", question="A or B?"), interrupt()]
checkout.run(asked[:2])
checkout.home.chmod(0o500)
self.addCleanup(checkout.home.chmod, 0o700)
run = checkout.run([worker(), *asked[1:]], terminal_input="/talk\n", before_typing=ANSWERING)
self.assertEqual(run.code, 2)
self.assertIn(f"could not write {checkout.claude_json()}: Permission denied\n", run.stderr)
self.assertEqual(checkout.claude_json().read_text(), "{}")
@unittest.skipIf(os.geteuid() == 0, "root reads an unreadable file")
def test_exits_1_when_the_transcript_cannot_be_read_after_the_interrupt(self):
checkout = Checkout(self)
+18 -21
View File
@@ -88,6 +88,7 @@ class FakeEffects:
self.terminal = on_terminal
self.worker_environments = []
self.terminal_environments = []
self.terminal_folders = []
def effects(self):
return Effects(
@@ -124,6 +125,7 @@ class FakeEffects:
def on_terminal_claude(self, args, cwd, env):
self.terminal_environments.append(env)
self.terminal_folders.append(cwd)
return self.answer("claude_on_terminal", args)
def stream(self, args, cwd, env):
@@ -301,11 +303,11 @@ class Cycles(unittest.TestCase):
with open(session.transcript_file(self.session), "a") as handle:
handle.write(json.dumps(human("the second")) + "\n")
return 0
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("interrupt"), judged("finished")], inputs=["/talk"], on_terminal_claude=[answer], git=[""])
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("interrupt"), judged("finished")], inputs=["/talk"], on_terminal_claude=[answer])
cycle = dataclasses.replace(self.cycle(fake), project=Rung("claude-opus-5-5", "medium"), route=Route(Rung("claude-haiku-5-5", "max"), 163, 1, 5))
with contextlib.redirect_stderr(io.StringIO()):
self.assertEqual(run.run_cycle(cycle).verdict, Finished("working"))
self.assertEqual(fake.terminal_environments, fake.worker_environments)
self.assertEqual(fake.terminal_environments, [{**environment, "CLAUDE_CODE_SANDBOXED": "1"} for environment in fake.worker_environments])
self.assertEqual(fake.terminal_environments[0]["LOOP_CLAUDE_WORKER_RUNG"], "claude-haiku-5-5 at max effort")
def test_an_unfinished_chunks_transcript_is_archived_and_the_next_cycle_resumes_its_session_with_the_judges_evidence(self):
@@ -397,7 +399,7 @@ class Cycles(unittest.TestCase):
with open(session.transcript_file(self.session), "a") as handle:
handle.write(json.dumps(human("the second")) + "\n")
return 0
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("interrupt"), judged("unfinished")], inputs=["/talk"], on_terminal_claude=[answer], git=[""])
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("interrupt"), judged("unfinished")], inputs=["/talk"], on_terminal_claude=[answer])
with contextlib.redirect_stderr(io.StringIO()):
self.assertEqual(run.run_cycle(self.cycle(fake)).verdict, Unfinished("working", entries_read=4))
self.assertEqual(self.archived_outcomes(), [f"Task: Do it.\n\n2026-09-21T14:13:20Z Verdict: interrupt\n\nWhich one?\n\nEvidence:\n> working\n\nJudge: judge-model\nWorker: {OFF_LADDER}\n", f"Task: Do it.\n\n2026-09-21T14:13:20Z Verdict: unfinished\n\nEvidence:\n> working\n\nJudge: judge-model\nWorker: {OFF_LADDER}\n"])
@@ -521,7 +523,7 @@ class Cycles(unittest.TestCase):
with open(session.transcript_file(self.session), "a") as handle:
handle.write(json.dumps(human("cut")) + "\n")
return 0
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("interrupt", release_ready=True), judged("finished")], on_terminal_claude=[answer], git=[""])
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("interrupt", release_ready=True), judged("finished")], on_terminal_claude=[answer])
with contextlib.redirect_stderr(io.StringIO()):
self.assertEqual(run.run_cycle(self.cycle(fake)).verdict, Finished("working"))
self.assertEqual(fake.made("input"), [])
@@ -725,7 +727,7 @@ class Interrupts(unittest.TestCase):
def test_talks_on_talk_or_at_once_where_the_answer_is_not_asked_for_here(self):
for typed, answer_here in (([" /talk "], True), ([], False)):
with self.subTest(typed=typed):
fake = FakeEffects(inputs=typed, on_terminal_claude=[self.typed_there], git=[""])
fake = FakeEffects(inputs=typed, on_terminal_claude=[self.typed_there])
self.assertEqual(self.put(fake, answer_here)[0], interrupt.Talked())
self.assertEqual(len(fake.made("input")), len(typed))
self.assertEqual(fake.calls[0], ("discard_typed", None))
@@ -761,7 +763,7 @@ class Interrupts(unittest.TestCase):
answer, said = self.put(FakeEffects(inputs=["Use B."]))
self.assertEqual(answer, "Use B.")
self.assertIn(f"loop-inbox cannot show this question: cannot make {self.paths.waiting}: File exists", said)
stop, _ = self.put(FakeEffects(inputs=["/talk"], on_terminal_claude=[0], git=[""]))
stop, _ = self.put(FakeEffects(inputs=["/talk"], on_terminal_claude=[0]))
self.assertEqual(stop, Stop(2, "the human is needed to answer the question above, but the interrupt ended with nothing typed"))
def test_makes_way_only_warns_where_loop_inbox_cannot_list_the_open_claude(self):
@@ -810,21 +812,21 @@ class Interrupts(unittest.TestCase):
def ran(args):
self.assertEqual(self.asked(), [self.ask("Cut 0.4.0?", OpenOnTerminal())])
return 0
fake = FakeEffects(inputs=typed, on_terminal_claude=[ran], git=[""])
fake = FakeEffects(inputs=typed, on_terminal_claude=[ran])
self.put(fake, answer_here, question="Cut 0.4.0?")
self.assertEqual(len(fake.made("claude_on_terminal")), 1)
self.assertEqual(asks_and_answers(self.paths.waiting), [])
def test_stops_when_nothing_was_typed_in_the_session(self):
fake = FakeEffects(inputs=["/talk"], on_terminal_claude=[0], git=[""])
fake = FakeEffects(inputs=["/talk"], on_terminal_claude=[0])
stop, _ = self.put(fake)
self.assertEqual(fake.made("claude_on_terminal")[0][:4], ["--model", "m", "--effort", "high"])
self.assertEqual(stop, Stop(2, "the human is needed to answer the question above, but the interrupt ended with nothing typed"))
def test_hands_the_claude_that_takes_the_terminal_the_workers_environment(self):
fake = FakeEffects(inputs=["/talk"], on_terminal_claude=[0], git=[""])
fake = FakeEffects(inputs=["/talk"], on_terminal_claude=[0])
self.put(fake)
self.assertEqual(fake.terminal_environments, [{"LOOP_CLAUDE_WORKER_RUNG": "m at high effort"}])
self.assertEqual(fake.terminal_environments, [{"LOOP_CLAUDE_WORKER_RUNG": "m at high effort", "CLAUDE_CODE_SANDBOXED": "1"}])
class RoutingCheck(unittest.TestCase):
@@ -861,7 +863,7 @@ class RoutingCheck(unittest.TestCase):
def ran(args):
self.assertEqual(waiting(self.paths.waiting), [Ask(ASK_ID, "s1", "/code/log", question, NOW, OpenOnTerminal())])
return 0
self.check(FakeEffects(on_terminal_claude=[ran], git=[UNREAD, ""]))
self.check(FakeEffects(on_terminal_claude=[ran], git=[UNREAD]))
self.assertEqual(asks_and_answers(self.paths.waiting), [])
def test_measures_once_20_cycles_have_closed_since_the_last_measurement(self):
@@ -881,7 +883,7 @@ class RoutingCheck(unittest.TestCase):
def test_hands_the_terminal_over_once_for_each_new_call(self):
self.chunks(5, 4)
fake = FakeEffects(on_terminal_claude=[0], git=[UNREAD, ""])
fake = FakeEffects(on_terminal_claude=[0], git=[UNREAD])
stop, said = self.check(fake)
self.assertIsNone(stop)
call = "Explore subagents' reports took more of the worker's context than their searches would have."
@@ -890,7 +892,8 @@ class RoutingCheck(unittest.TestCase):
((args),) = fake.made("claude_on_terminal")
self.assertEqual(args[:6], ["--model", "m", "--effort", "high", "--permission-mode", "bypassPermissions"])
self.assertIn(f"change nothing until they answer:\n- {call}", args[6])
self.assertEqual(fake.terminal_environments, [{}])
self.assertEqual(fake.terminal_environments, [{"CLAUDE_CODE_SANDBOXED": "1"}])
self.assertEqual(fake.terminal_folders, [str(self.home / ".claude")])
(self.root / "routing-figures.md").write_text("Measured x, at cycle 0 across")
self.assertEqual(self.check(FakeEffects(git=[UNREAD]))[0], None)
self.assertNotIn(call, self.check(FakeEffects())[1])
@@ -898,7 +901,7 @@ class RoutingCheck(unittest.TestCase):
def test_stamps_the_figures_and_the_calls_raised_when_it_measures(self):
self.chunks(5, 4)
(self.root / "routing-calls-raised.md").write_text("# Routing calls raised\n\n- 2026-10-14T10:02:00Z Reset\n")
self.check(FakeEffects(on_terminal_claude=[0], git=[UNREAD, ""]))
self.check(FakeEffects(on_terminal_claude=[0], git=[UNREAD]))
figures = (self.root / "routing-figures.md").read_text()
self.assertIn(f"Measured {utc(NOW)}, at cycle 20 across", figures)
self.assertIn("that finished after the reset of 2026-10-14T10:02:00Z", figures)
@@ -924,7 +927,7 @@ class RoutingCheck(unittest.TestCase):
def test_stops_when_claude_cannot_start_for_the_calls(self):
self.chunks(5, 4)
stop, _ = self.check(FakeEffects(on_terminal_claude=[OSError(2, "No such file or directory")], git=[UNREAD, ""]))
stop, _ = self.check(FakeEffects(on_terminal_claude=[OSError(2, "No such file or directory")], git=[UNREAD]))
self.assertEqual(stop, Stop(1, "could not start claude for the routing calls: No such file or directory"))
self.assertEqual(asks_and_answers(self.paths.waiting), [])
@@ -1890,11 +1893,5 @@ class JudgeFailures(unittest.TestCase):
self.assertEqual([clause for *_, clause in clauses if clause not in judge_clause], [])
class Worktrees(unittest.TestCase):
def test_lists_the_root_alone_when_git_cannot_start(self):
fake = FakeEffects(git=[Failure("git worktree list --porcelain could not start: [Errno 2] No such file or directory: 'git'")])
self.assertEqual(checkout.worktrees("/r", fake.effects()), ["/r"])
if __name__ == "__main__":
unittest.main()
+1 -1
View File
@@ -168,7 +168,7 @@ def opened(screen_off: typing.Callable[[], typing.ContextManager[None]], paths:
return f"Could not open claude for {ask.root}: the loop was answered elsewhere or stopped, or didn't respond within {MAKE_WAY_SECONDS:g} s. If it is still listed, pick it again."
with screen_off():
try:
unstarted = hand_over(ask.state.talk, paths, effects)
unstarted = hand_over(ask.state.talk, effects)
finally:
unsent = send(folder, ask, ClaudeEnded())
# The loop goes on only where the human typed in the worker's session, as interrupt.human_typed checks.
+3 -2
View File
@@ -1,6 +1,7 @@
import os
# A git hook's GIT_DIR, the host's LOOP_CLAUDE_* or PYTHONPATH would point the program under test at the host's own state.
# A git hook's GIT_DIR, the host's LOOP_CLAUDE_* or PYTHONPATH would point the program under test at the host's own state,
# and the host's CLAUDE_CODE_SANDBOXED would hide whether loop-claude sets it.
def isolated_env() -> dict[str, str]:
return {name: value for name, value in os.environ.items() if not name.startswith(("GIT_", "LOOP_CLAUDE_", "PYTHON"))}
return {name: value for name, value in os.environ.items() if not name.startswith(("GIT_", "LOOP_CLAUDE_", "PYTHON")) and name != "CLAUDE_CODE_SANDBOXED"}
+3 -5
View File
@@ -54,13 +54,11 @@ The cap is 5, `bin/todo_table.py`'s `BUNDLE_MAX_R`, from the same chunks: by the
2026-10-17, lilleman, todo item 168. The human answers an interrupt on loop-claude's terminal, and the worker resumes headless with the answer in a `-p` prompt. The judge reads that answer as a `[human]` line, not a `[loop]` one, so it holds the chunk open until the answer is recorded, as it does for an answer typed in claude.
## loop-claude: before it or loop-inbox opens claude on a terminal, it marks the checkout and each of its worktrees trusted in `~/.claude.json`
## loop-claude: every claude it or loop-inbox opens on a terminal has `CLAUDE_CODE_SANDBOXED` set, so Claude Code skips its trust dialog, and neither tool writes `~/.claude.json`
2026-09-21, lilleman. Serves goal 1. `claude --resume` re-enters the worktree the worker last entered, recorded in the transcript's `worktree-state` entry, and Claude Code asks trust per path, so trusting the checkout alone still lands the human in the dialog. Trusting every worktree `git worktree list` names spares reading which one from the transcript. Since the human answers an interrupt on loop-claude's own terminal (todo item 168), claude opens there only for `/talk`, a release ready to cut and the routing calls, and the trust is marked only then. Valid while resume re-enters a recorded worktree and trust is kept per path.
2026-09-21, lilleman. Serves goal 1. `claude --resume` re-enters the worktree the worker last entered, recorded in the transcript's `worktree-state` entry, and Claude Code asks trust per path, so trusting the checkout alone would still land the human in the trust dialog.
2026-09-30, lilleman. A write by another claude inside `trust`'s read-modify-write window is lost, a risk larv-review accepted on 2026-09-24. Claude Code owns and writes `~/.claude.json`, so `loop-claude` is to move out of it, bringing each case that must stay to the human. Stands until `todo.md` item 6 ends it.
2026-10-28, lilleman, todo item 243. `/talk` from loop-inbox opens claude in loop-inbox's terminal, through loop-claude's `hand_over`, which marks the trust just before. It adds a second writer to `~/.claude.json`, under the same risk, until item 6 ends it.
2026-10-30, lilleman, todo item 6. Serves goal 1. Until then loop-claude marked each worktree trusted in `~/.claude.json`, reading the file, changing it and writing it back. Claude Code owns and writes that file, so a write it made in between could be lost. Claude Code 2.1.314 treats every folder as trusted while `CLAUDE_CODE_SANDBOXED` is set, and doesn't persist that trust. A claude started in a new folder with the variable set showed no dialog, and Claude Code recorded the folder untrusted. `hand_over` sets the variable for every claude it opens on a terminal: for `/talk`, a release ready to cut and the routing calls. The variable tells Claude Code it runs inside a sandbox, which holds here: loop-claude runs only in the sandbox README → Install names (`loop-claude: every claude it starts bypasses permissions inside its sandbox`). Claude Code doesn't document the variable. Where a later version drops it, the trust dialog comes back on those claudes, and nothing is lost. Valid while Claude Code honours `CLAUDE_CODE_SANDBOXED`.
## loop-claude: each project's model lives in `~/.claude/loop-claude-models.json`, which only loop-claude writes
+17
View File
@@ -940,3 +940,20 @@ Read most (opens and searches):
- `bin/loop_claude/test_black_box.py` 2
- `bin/loop_inbox/main.py` 2
- `bin/loop_inbox/test_loop_inbox.py` 2
## Reading cost, chunk 856cc431e771, finished 2026-10-30T12:23:00Z
65006 new input tokens before the first commit.
Read most (opens and searches):
- `todo.md` 4
- `README.md` 3
- `bin/rule_hook/test_rule_hook.py` 3
- `docs/decisions.md` 3
- `CHANGELOG.md` 2
- `settings.json` 2
- `AGENTS.md` 1
- `bin/model_routing/ladder.py` 1
- `bin/model_routing/worker_rungs.py` 1
- `bin/rule_hook/call.py` 1
-5
View File
@@ -12,7 +12,6 @@
| ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 6 | 0.5.0 | | decision | **Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay.** | 3 | 3 | 3 | 7 | 3 | 1.1 by 5 | 5.3 |
| 257 | 0.5.0 | | | **Make `chunk-preflight` create the item's worktree and branch only when loop-claude starts a worker on it, so a run for the facts alone leaves nothing to remove.** | 3 | 2 | 3 | 6 | 4 | 1.5 by 2 | 1.3 |
| 226 | 0.6.0 | | question | **Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording.** | 2 | 2 | 3 | 5 | 3 | 1.2 by 2, 1.5 by 2 | 4.0 |
| 248 | 0.6.0 | | question | **Answer whether the `rule-hook:` decision should name every rule that takes no override, `repeat-read`, `reviewer-report` and `reviewer-rung`, with each one's reason.** | 1 | 2 | 1 | 2 | 1 | 1.2 by 2 | 3.3 |
@@ -76,10 +75,6 @@
## Details
### 6. Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay.
Claude Code owns that file and writes it. `trust` reads it, changes it and writes it back, so a write that lands in between is lost.
### 257. Make `chunk-preflight` create the item's worktree and branch only when loop-claude starts a worker on it, so a run for the facts alone leaves nothing to remove.
Found in fejkdata.dev on 2026-10-29 and 2026-10-30. Two runs of `chunk-preflight` by hand, made to read its facts and not to start a chunk, each added the sibling worktree `fejkdata.dev-item-20` and the branch `item-20` at `origin/main`, and the session had to remove both. `bin/chunk_preflight/main.py` makes the worktree whenever the plan has an item, since loop-claude runs it as a chunk starts (`bin/loop_claude/loop/main.py` → `chunk_start`) and the worker then works in that worktree. It takes no argument and exits 1 on one, so a caller cannot ask for the facts alone. Make the worktree, `reading-cost`, `larv-review places` and the other tools it runs in the worktree opt-in, loop-claude's call asking for them; a bare run prints the facts and says no worktree was made. Update `--help`, the docstring and the worker prompt that tells the worker its worktree exists. Item 256 removes the case that made most of these worktrees, a pick the worker must not take.