"""Whether a Read asks for a session transcript, for the `transcript-read` rule. A transcript is a `.jsonl` file under the `projects` folder of a Claude home: the loop's home or the person's own. A session's transcript counts, and so does 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, 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, env: typing.Mapping[str, str]) -> list[Breach]: if call.tool != "Read": return [] path = resolved(call.cwd, text(call.given, "file_path"), home) # 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 []