Run every claude the loop starts in a Claude home generated outside the clone
CI / tests (pull_request) Successful in 4m45s
CI / tests (pull_request) Successful in 4m45s
This commit is contained in:
@@ -101,7 +101,7 @@ def breaches_of(call: Call, home: str, environ: typing.Mapping[str, str]) -> tup
|
||||
command = text(call.given, "command")
|
||||
return command, command.split("\n", 1)[0], bash_breaches(command, call.cwd, home, environ, call.tool == "Monitor") + read_breaches(call, home) + env_file_breaches(call, home, environ)
|
||||
if call.tool == "Read":
|
||||
return "", text(call.given, "file_path"), read_breaches(call, home) + env_file_breaches(call, home, environ) + transcript_breaches(call, home)
|
||||
return "", text(call.given, "file_path"), read_breaches(call, home) + env_file_breaches(call, home, environ) + transcript_breaches(call, home, environ)
|
||||
if call.tool == "Grep":
|
||||
# Only env-file-read checks a Grep, and it takes no override, so no marker or log line concerns the call.
|
||||
return "", "", env_file_breaches(call, home, environ)
|
||||
|
||||
@@ -100,8 +100,8 @@ RULES: dict[RuleName, Rule] = {
|
||||
),
|
||||
# A Read carries no text for a marker, so no marker waives it.
|
||||
"transcript-read": Rule(
|
||||
"an agent never reads a session transcript under ~/.claude/projects with Read, since the file holds every tool result of its session, and reading it costs far more than the lines the agent needs; the agent prints only those lines with grep or jq; the `tool-results/` files that Claude Code saves a long Bash result to are not transcripts and may be read",
|
||||
"a Read call whose file is a `.jsonl` file under ~/.claude/projects; a Grep or a Bash command that reads one is not checked",
|
||||
"an agent never reads a session transcript of a Claude home with Read, since the file holds every tool result of its session, and reading it costs far more than the lines the agent needs; the agent prints only those lines with grep or jq; the `tool-results/` files that Claude Code saves a long Bash result to are not transcripts and may be read",
|
||||
"a Read call whose file is a `.jsonl` file under `projects` in the loop's Claude home, ~/.local/share/build-release/claude-home unless `XDG_DATA_HOME` holds an absolute path, or under ~/.claude/projects; a Grep or a Bash command that reads one is not checked",
|
||||
overridable=False,
|
||||
),
|
||||
}
|
||||
|
||||
@@ -1646,6 +1646,11 @@ class TranscriptRead(unittest.TestCase):
|
||||
self.assertEqual(self.breached("Read", {"file_path": self.TRANSCRIPT}), ["transcript-read"])
|
||||
self.assertEqual(self.breached("Read", {"file_path": "/home/h/.claude/projects/-home-h-code-acme/abc-123/subagents/agent-a1.jsonl"}), ["transcript-read"])
|
||||
|
||||
def test_a_read_of_a_transcript_in_the_loops_claude_home_is_refused(self):
|
||||
self.assertEqual(self.breached("Read", {"file_path": "/home/h/.local/share/build-release/claude-home/projects/-home-h-code-acme/abc-123.jsonl"}), ["transcript-read"])
|
||||
found = breaches_of(Call("Read", {"file_path": "/x/data/build-release/claude-home/projects/-r/abc-123.jsonl"}, "/r"), self.HOME, {"XDG_DATA_HOME": "/x/data"})
|
||||
self.assertEqual([breach.rule for breach in found[2]], ["transcript-read"])
|
||||
|
||||
def test_a_read_spelt_from_home_or_from_the_working_directory_is_refused(self):
|
||||
self.assertEqual(self.breached("Read", {"file_path": "~/.claude/projects/-home-h-code-acme/abc-123.jsonl"}), ["transcript-read"])
|
||||
self.assertEqual(self.breached("Read", {"file_path": "abc-123.jsonl"}, "/home/h/.claude/projects/-home-h-code-acme"), ["transcript-read"])
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
"""Whether a Read asks for a session transcript under ~/.claude/projects, for the `transcript-read` rule.
|
||||
"""Whether a Read asks for a session transcript, for the `transcript-read` rule.
|
||||
|
||||
A transcript is a `.jsonl` file there, a session's own or a subagent's. It holds every tool result of its session, so reading one costs far more than the lines a task needs. The files Claude Code saves a long Bash result to, under the session's `tool-results/` folder, are `.txt` files and pass: the model is handed their path to read."""
|
||||
A transcript is a `.jsonl` file under the `projects` folder of a Claude home, the loop's or the person's own, a session's own or a subagent's. It holds every tool result of its session, so reading one costs far more than the lines a task needs. The files Claude Code saves a long Bash result to, under the session's `tool-results/` folder, are `.txt` files and pass: the model is handed their path to read."""
|
||||
import pathlib
|
||||
import posixpath
|
||||
import typing
|
||||
|
||||
from rule_hook.rules import Breach
|
||||
from rule_hook.call import Call, text
|
||||
from loop_state.paths import CLAUDE_HOME
|
||||
from loop_state.paths import CLAUDE_HOME, claude_home
|
||||
from command_lines.shell_command import resolved
|
||||
|
||||
READS = "the call reads {}, a session transcript that holds every tool result of its session; print only the lines you need with grep or jq"
|
||||
|
||||
|
||||
def transcript_breaches(call: Call, home: str) -> list[Breach]:
|
||||
def transcript_breaches(call: Call, home: str, env: typing.Mapping[str, str]) -> list[Breach]:
|
||||
if call.tool != "Read":
|
||||
return []
|
||||
path = resolved(call.cwd, text(call.given, "file_path"), home)
|
||||
if path.endswith(".jsonl") and path.startswith(posixpath.join(home, CLAUDE_HOME, "projects") + "/"):
|
||||
# The path is only compared: no file of either home is read.
|
||||
homes = (posixpath.join(home, CLAUDE_HOME), str(claude_home(env, pathlib.Path(home))))
|
||||
if path.endswith(".jsonl") and path.startswith(tuple(posixpath.join(each, "projects") + "/" for each in homes)):
|
||||
return [Breach("transcript-read", READS.format(path), call.cwd)]
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user