Work in progress: Bash output ceiling and refusing Reads of session transcripts

This commit is contained in:
2026-11-18 08:28:38 +01:00
parent 641645c081
commit a7b2fd0ae1
16 changed files with 274 additions and 114 deletions
+34
View File
@@ -1493,6 +1493,40 @@ class CommittedFiles(unittest.TestCase):
self.assertEqual(self.commit().returncode, 0)
class TranscriptRead(unittest.TestCase):
HOME = "/home/h"
TRANSCRIPT = "/home/h/.claude/projects/-home-h-code-acme/abc-123.jsonl"
def breached(self, tool: str, given: dict[str, typing.Any], cwd: str = "/r") -> list[str]:
found = breaches_of(Call(tool, given, cwd), self.HOME, {})
return [rule for rule in rules(found[2]) if rule == "transcript-read"] if found else []
def test_a_read_of_a_session_s_transcript_or_a_subagent_s_is_refused(self):
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_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"])
def test_the_refusal_names_the_file_and_what_to_use_instead(self):
found = breaches_of(Call("Read", {"file_path": self.TRANSCRIPT}, "/r"), self.HOME, {})
self.assertEqual([breach.detail for breach in found[2] if breach.rule == "transcript-read"], [f"the call reads {self.TRANSCRIPT}, a session transcript that holds every tool result of its session; print only the lines you need with grep or jq"])
def test_a_read_of_a_long_result_claude_code_saved_to_a_file_or_of_a_memory_file_passes(self):
for path in ("/home/h/.claude/projects/-home-h-code-acme/abc-123/tool-results/b3ij9u144.txt", "/home/h/.claude/projects/-home-h-code-acme/memory/MEMORY.md"):
with self.subTest(path):
self.assertEqual(self.breached("Read", {"file_path": path}), [])
def test_a_jsonl_file_outside_the_projects_folder_passes(self):
self.assertEqual(self.breached("Read", {"file_path": "/home/h/code/acme/cases.jsonl"}), [])
self.assertEqual(self.breached("Read", {"file_path": "/home/h/.claude/loop-claude-transcripts/x.jsonl"}), [])
def test_a_search_of_a_transcript_is_not_checked(self):
self.assertEqual(self.breached("Grep", {"pattern": "x", "path": self.TRANSCRIPT}), [])
self.assertEqual(self.breached("Bash", {"command": f"grep x {self.TRANSCRIPT}"}), [])
class RuleNames(unittest.TestCase):
def test_every_rule_name_has_a_rule_and_every_rule_a_name(self):
self.assertEqual(set(RULES), set(typing.get_args(RuleName)))