1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! Source-file read detection for tool-output compression.
//!
//! Why: #6986 — the dispatch classifies by substring against a tool name that
//! is the wrapped command's first two tokens, so `cat …/gh_cli/tests.rs`
//! matched the `test` branch and `filter_test_runner` deleted every byte
//! (`bytes_before=6037 bytes_after=0`), and `cat …/mod.rs` reached
//! `filter_file_read`, which strips `//`-prefixed lines and so removed the
//! doc comments the agent was reading. Those filters exist for gate output —
//! a test runner's log, a compiler's log — not for source an agent is reading
//! to edit it.
//! What: [`is_source_file_read`], the predicate [`super::classify_tool`]
//! consults first. It answers from the command alone: a read verb applied to
//! a path with a source or prose extension. That is the reliable signal here
//! because the tool name IS the command (`tm hook`'s rewrite passes
//! `effective_tool_name`, e.g. `cat crates/x/src/tests.rs`), whereas output
//! shape cannot separate a `.rs` file's contents from a compiler log that
//! quotes source.
//! Test: `is_source_file_read_*`, `classify_tool_passes_through_source_reads`,
//! and `cat_of_a_rust_test_file_survives_compression_byte_for_byte` in
//! `tool_output::tests`.
/// Commands whose whole job is to print a file's bytes back to a reader.
///
/// Why: A read verb names the caller's intent — "show me this file" — which
/// no substring of the path can override. `sed` and `tail` are listed for
/// completeness even though `effective_tool_name` usually drops their path
/// argument behind a flag (`sed -n`, `tail -f`); when a path does survive,
/// the same passthrough must apply.
/// What: Matched against the command's first token, with any directory
/// prefix stripped, case-insensitively.
/// Test: `is_source_file_read_requires_a_read_verb`.
const READ_VERBS: & = &;
/// File extensions whose contents are source or prose read for editing.
///
/// Why: The extension is what separates "an agent is reading code" from "an
/// agent is reading a gate's captured output". `.txt`, `.log` and `.out` are
/// deliberately ABSENT: `<gate> > /tmp/gate.txt` is this project's documented
/// capture pattern (`assets/agents/BASE-AGENT.md`), so a later
/// `cat /tmp/gate.txt` is genuine gate output that must stay compressible.
/// What: Lowercase, without the dot, compared against the final `.`-segment
/// of a path token's basename.
/// Test: `is_source_file_read_ignores_gate_capture_extensions`.
const SOURCE_EXTENSIONS: & = &;
/// Whether `tool_name` is a read verb applied to a source or prose file.
///
/// Why: #6986 — such a command's output is the file itself, and every filter
/// in this module would damage it: the test-runner filter drops any line that
/// is not a failure, and the file-read filter drops every `//` and `#` line.
/// The compressor is for gate output, so a source read must bypass it
/// entirely rather than be compressed more gently.
/// What: `true` when the first whitespace token (directory prefix stripped,
/// lowercased) is in [`READ_VERBS`] and any later token's basename ends in a
/// [`SOURCE_EXTENSIONS`] entry. A read verb with no source-file argument
/// (`cat /tmp/gate.txt`, a bare `cat`) returns `false` and keeps its existing
/// classification.
/// Test: `is_source_file_read_matches_the_reported_shapes`,
/// `is_source_file_read_requires_a_read_verb`,
/// `is_source_file_read_ignores_gate_capture_extensions`.
/// Whether a command token names a file with a [`SOURCE_EXTENSIONS`] suffix.