claude-dev-env 8.115.0 → 8.116.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/bin/install.prompt-context.test.mjs +5 -6
  2. package/docs/rule-guides/verified-work.md +1 -1
  3. package/hooks/advisory/commit_and_pull_request_words.py +346 -0
  4. package/hooks/advisory/piece_clauses.py +248 -0
  5. package/hooks/advisory/pieces_per_level_analysis.py +192 -0
  6. package/hooks/advisory/pieces_per_level_note.py +265 -0
  7. package/hooks/advisory/test_commit_and_pull_request_words.py +126 -0
  8. package/hooks/advisory/test_piece_clauses.py +183 -0
  9. package/hooks/advisory/test_pieces_per_level_note.py +389 -0
  10. package/hooks/advisory/test_pieces_per_level_note_bounds.py +215 -0
  11. package/hooks/advisory/test_pieces_per_level_note_deadline.py +282 -0
  12. package/hooks/blocking/final_reply_gate.py +7 -29
  13. package/hooks/blocking/test_final_reply_gate.py +4 -196
  14. package/hooks/features/README.md +1 -1
  15. package/hooks/features/conduct-gates.md +5 -12
  16. package/hooks/features/session-context.md +4 -1
  17. package/hooks/hooks.json +10 -41
  18. package/hooks/hooks_constants/background_silence_prompt_constants.py +2 -0
  19. package/hooks/hooks_constants/pieces_per_level_note_constants.py +255 -0
  20. package/hooks/hooks_constants/resolve_thread_reply_gate_constants.py +0 -8
  21. package/hooks/hooks_constants/shell_command_wrappers.py +20 -8
  22. package/hooks/hooks_constants/test_shell_command_wrappers.py +7 -0
  23. package/hooks/session/background_silence_prompt.py +1 -1
  24. package/hooks/test_context_budget_hooks.py +0 -1
  25. package/package.json +1 -1
  26. package/scripts/durable_post_lint.py +0 -12
  27. package/scripts/durable_post_lint_config/config/constants.py +1 -2
  28. package/scripts/policy_lint/adapter_configuration.py +0 -2
  29. package/scripts/policy_lint/config/constants.py +0 -2
  30. package/scripts/test_durable_post_lint.py +0 -53
  31. package/scripts/tests/test_adapter_configuration.py +0 -16
  32. package/scripts/tests/test_verified_work_rule.py +13 -0
  33. package/hooks/blocking/chat_reply_gate.py +0 -260
  34. package/hooks/blocking/reply_length_gate.py +0 -804
  35. package/hooks/blocking/test_chat_reply_gate.py +0 -302
  36. package/hooks/blocking/test_reply_length_gate.py +0 -1324
  37. package/hooks/hooks_constants/chat_reply_gate_constants.py +0 -60
  38. package/hooks/hooks_constants/reply_length_gate_constants.py +0 -203
  39. package/hooks/hooks_constants/test_reply_length_gate_constants.py +0 -81
  40. package/hooks/hooks_constants/test_visual_reply_rules_constants.py +0 -50
  41. package/hooks/hooks_constants/visual_reply_rules_constants.py +0 -106
  42. package/hooks/test_visual_reply_rules.py +0 -362
  43. package/hooks/visual_reply_rules.py +0 -478
  44. package/rules/visual-reply-rules.json +0 -56
@@ -0,0 +1,215 @@
1
+ """Bound tests for the pieces-per-level note.
2
+
3
+ The analysis reads its input only up to fixed caps. These tests feed the
4
+ analysis and the hook inputs that were slow before the caps existed and read the
5
+ silence, the exit status, and the wall time.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ import subprocess
12
+ import sys
13
+ import time
14
+ from pathlib import Path
15
+
16
+ import pytest
17
+
18
+ hooks_root_directory = str(Path(__file__).resolve().parent.parent)
19
+ if hooks_root_directory not in sys.path:
20
+ sys.path.insert(0, hooks_root_directory)
21
+ advisory_directory = str(Path(__file__).resolve().parent)
22
+ if advisory_directory not in sys.path:
23
+ sys.path.insert(0, advisory_directory)
24
+
25
+ import commit_and_pull_request_words
26
+ import piece_clauses
27
+ import pieces_per_level_analysis
28
+ from hooks_constants.pieces_per_level_note_constants import (
29
+ COMMIT_NEXT_COMMAND,
30
+ MAXIMUM_BODY_CHARACTERS,
31
+ MAXIMUM_TITLE_CHARACTERS,
32
+ )
33
+
34
+ SCRIPT_PATH = Path(__file__).resolve().parent / "pieces_per_level_note.py"
35
+ ENTRY_SECONDS_BOUND = 1.0
36
+ OVER_BARE_START_SECONDS_BOUND = 1.0
37
+ INTERPRETER_STARTS_PER_RUN = 2
38
+ RUNS_PER_INPUT = 3
39
+ MIXED_SUBJECT = (
40
+ "fix(convert): always publish drawn icons, put Tips on the tray, stop the label smear"
41
+ )
42
+ MANY_SUBSTITUTIONS = "$(" * 3_900 + " git commit -m x"
43
+ PROOF_HEADING = "## Proof in practice"
44
+
45
+
46
+ def _bare_start_seconds() -> float:
47
+ all_runs = []
48
+ for _ in range(3):
49
+ started_at = time.perf_counter()
50
+ subprocess.run([sys.executable, "-c", "pass"], check=False)
51
+ all_runs.append(time.perf_counter() - started_at)
52
+ return min(all_runs)
53
+
54
+
55
+ def _run_hook(payload: dict[str, object]) -> tuple[subprocess.CompletedProcess[str], float]:
56
+ started_at = time.perf_counter()
57
+ completed = subprocess.run(
58
+ [sys.executable, str(SCRIPT_PATH)],
59
+ input=json.dumps(payload),
60
+ capture_output=True,
61
+ text=True,
62
+ timeout=60,
63
+ check=False,
64
+ )
65
+ return completed, time.perf_counter() - started_at
66
+
67
+
68
+ def _shell_payload(command: str) -> dict[str, object]:
69
+ return {"tool_name": "Bash", "tool_input": {"command": command}}
70
+
71
+
72
+ def _mcp_payload(title: str, body: str) -> dict[str, object]:
73
+ return {
74
+ "tool_name": "mcp__github__create_pull_request",
75
+ "tool_input": {"title": title, "body": body},
76
+ }
77
+
78
+
79
+ def _seconds_of(call, *all_arguments: object) -> tuple[object, float]:
80
+ started_at = time.perf_counter()
81
+ result = call(*all_arguments)
82
+ return result, time.perf_counter() - started_at
83
+
84
+
85
+ @pytest.mark.parametrize(
86
+ "payload",
87
+ [
88
+ _shell_payload(MANY_SUBSTITUTIONS),
89
+ _mcp_payload("fix: a" + " " * 100_000 + "b", ""),
90
+ _mcp_payload("fix: a" + "(" * 200_000, ""),
91
+ _mcp_payload("fix: a", PROOF_HEADING + " " * 60_000 + "x"),
92
+ ],
93
+ ids=["substitutions", "title spaces", "title parentheses", "body heading spaces"],
94
+ )
95
+ def test_an_input_that_was_slow_gives_silence_exit_zero_and_a_short_wall_time(
96
+ payload: dict[str, object],
97
+ ) -> None:
98
+ bare_start_seconds = _bare_start_seconds()
99
+ all_runs = [_run_hook(payload) for _ in range(RUNS_PER_INPUT)]
100
+ for each_completed, _each_seconds in all_runs:
101
+ assert each_completed.returncode == 0
102
+ assert each_completed.stdout == ""
103
+ assert each_completed.stderr == ""
104
+ fastest_seconds = min(each_seconds for _each_completed, each_seconds in all_runs)
105
+ assert fastest_seconds - INTERPRETER_STARTS_PER_RUN * bare_start_seconds < OVER_BARE_START_SECONDS_BOUND
106
+
107
+
108
+ def test_a_commit_with_many_substitutions_gets_no_note_within_the_entry_bound() -> None:
109
+ all_fields = {"tool_name": "Bash", "tool_input": {"command": MANY_SUBSTITUTIONS}, "cwd": ""}
110
+ output, elapsed_seconds = _seconds_of(pieces_per_level_analysis.decide_hook_output, all_fields)
111
+ assert output is None
112
+ assert elapsed_seconds < ENTRY_SECONDS_BOUND
113
+
114
+
115
+ def test_a_heredoc_message_still_gets_the_note_with_one_substitution() -> None:
116
+ command = f"git commit -m \"$(cat <<'EOF'{chr(10)}{MIXED_SUBJECT}{chr(10)}EOF{chr(10)})\""
117
+ all_fields = {"tool_name": "Bash", "tool_input": {"command": command}, "cwd": ""}
118
+ assert "stop the label smear" in json.dumps(
119
+ pieces_per_level_analysis.decide_hook_output(all_fields)
120
+ )
121
+
122
+
123
+ def test_the_commit_and_pull_request_readers_unwrap_the_command_once(
124
+ monkeypatch: pytest.MonkeyPatch,
125
+ ) -> None:
126
+ all_calls: list[str] = []
127
+ real_unwrap = commit_and_pull_request_words.all_wrapped_command_texts
128
+
129
+ def counting_unwrap(command: str, *all_arguments: object) -> list[str]:
130
+ all_calls.append(command)
131
+ return real_unwrap(command, *all_arguments)
132
+
133
+ monkeypatch.setattr(commit_and_pull_request_words, "all_wrapped_command_texts", counting_unwrap)
134
+ commit_and_pull_request_words.clear_parse_cache()
135
+ command = "git commit -m 'fix(x): one thing' && gh pr create --title t"
136
+ all_fields = {"tool_name": "Bash", "tool_input": {"command": command}, "cwd": ""}
137
+ assert pieces_per_level_analysis.decide_hook_output(all_fields) is None
138
+ assert len(all_calls) == 1
139
+
140
+
141
+ def test_a_command_with_many_substitution_markers_is_not_unwrapped(
142
+ monkeypatch: pytest.MonkeyPatch,
143
+ ) -> None:
144
+ all_calls: list[str] = []
145
+ monkeypatch.setattr(
146
+ commit_and_pull_request_words,
147
+ "all_wrapped_command_texts",
148
+ lambda command, *_all_arguments: all_calls.append(command) or [command],
149
+ )
150
+ commit_and_pull_request_words.clear_parse_cache()
151
+ commit_and_pull_request_words.commit_subjects(MANY_SUBSTITUTIONS, "")
152
+ assert all_calls == []
153
+
154
+
155
+ @pytest.mark.parametrize(
156
+ "title",
157
+ [
158
+ "fix: a" + " " * 20_000 + "b",
159
+ "fix: a" + " " * 100_000 + "b",
160
+ "fix: a" + "(" * 200_000,
161
+ "fix: a" + "`" * 100_000,
162
+ "fix: a" + ", " * 100_000,
163
+ ],
164
+ ids=["20k spaces", "100k spaces", "200k parentheses", "100k backticks", "100k commas"],
165
+ )
166
+ def test_a_long_title_names_no_pieces_within_the_entry_bound(title: str) -> None:
167
+ all_pieces, elapsed_seconds = _seconds_of(piece_clauses.subject_pieces, title)
168
+ assert all_pieces == []
169
+ assert elapsed_seconds < ENTRY_SECONDS_BOUND
170
+
171
+
172
+ def test_a_title_at_the_cap_still_names_its_pieces() -> None:
173
+ assert len(MIXED_SUBJECT) < MAXIMUM_TITLE_CHARACTERS
174
+ assert len(piece_clauses.subject_pieces(MIXED_SUBJECT)) == 3
175
+
176
+
177
+ @pytest.mark.parametrize(
178
+ "body",
179
+ [
180
+ PROOF_HEADING + " " * 60_000 + "x",
181
+ "## What this does" + " " * 60_000 + "x",
182
+ PROOF_HEADING + chr(10) + "Without it " + ";" * 100_000,
183
+ PROOF_HEADING + chr(10) + "- " + "**a " * 100_000,
184
+ (PROOF_HEADING + chr(10) + "Without the change: x" + chr(10)) * 5_000,
185
+ ],
186
+ ids=["proof heading", "what heading", "semicolons", "bold bullets", "many lines"],
187
+ )
188
+ def test_a_hostile_body_is_read_within_the_entry_bound(body: str) -> None:
189
+ all_counts, elapsed_seconds = _seconds_of(
190
+ lambda text: (piece_clauses.proof_pair_count(text), piece_clauses.topic_bullets(text)),
191
+ body,
192
+ )
193
+ assert all_counts[0] <= len(body)
194
+ assert elapsed_seconds < ENTRY_SECONDS_BOUND
195
+
196
+
197
+ def test_a_body_is_read_only_up_to_the_character_cap() -> None:
198
+ pair = chr(10).join(["Without the change: a failed.", "With the change: a passed."])
199
+ filler = chr(10) + "x" * (MAXIMUM_BODY_CHARACTERS + 10)
200
+ body = PROOF_HEADING + chr(10) + pair + chr(10) + filler + chr(10) + pair
201
+ assert piece_clauses.proof_pair_count(body) == 1
202
+
203
+
204
+ def test_a_heading_line_padded_past_the_line_cap_still_opens_its_section() -> None:
205
+ pair = chr(10).join(["Without the change: a failed.", "With the change: a passed."])
206
+ body = PROOF_HEADING + " " * 5_000 + chr(10) + pair + chr(10) + pair
207
+ assert piece_clauses.proof_pair_count(body) == 2
208
+
209
+
210
+ def test_the_commit_note_holds_the_commit_and_names_the_split_commands() -> None:
211
+ assert "git add -p" not in COMMIT_NEXT_COMMAND
212
+ assert "The commit that is running holds every piece." in COMMIT_NEXT_COMMAND
213
+ assert "`git reset --soft HEAD~1`" in COMMIT_NEXT_COMMAND
214
+ assert "`git add <paths of the first piece>`" in COMMIT_NEXT_COMMAND
215
+
@@ -0,0 +1,282 @@
1
+ """Deadline tests for the pieces-per-level note.
2
+
3
+ The hook runs its analysis in a child process under one wall-clock deadline for
4
+ the whole child, from start to exit. These tests use fake children that stall
5
+ at each stage and read the silence, the exit status, the wall time, and whether
6
+ a child was started.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import json
12
+ import subprocess
13
+ import sys
14
+ import time
15
+ from pathlib import Path
16
+
17
+ import pytest
18
+
19
+ hooks_root_directory = str(Path(__file__).resolve().parent.parent)
20
+ if hooks_root_directory not in sys.path:
21
+ sys.path.insert(0, hooks_root_directory)
22
+ advisory_directory = str(Path(__file__).resolve().parent)
23
+ if advisory_directory not in sys.path:
24
+ sys.path.insert(0, advisory_directory)
25
+
26
+ import pieces_per_level_note
27
+ from hooks_constants.pieces_per_level_note_constants import (
28
+ DEADLINE_ENVIRONMENT_VARIABLE,
29
+ EXIT_WAIT_SECONDS,
30
+ TOTAL_DEADLINE_SECONDS,
31
+ )
32
+
33
+ STALL_SECONDS = 30
34
+ SHORT_DEADLINE_SECONDS = 0.5
35
+ RETURN_BOUND_SECONDS = STALL_SECONDS / 3
36
+ MIXED_SUBJECT = (
37
+ "fix(convert): always publish drawn icons, put Tips on the tray, stop the label smear"
38
+ )
39
+ ALL_RUNNER_SOURCE = (
40
+ "import sys; sys.path.insert(0, {advisory!r}); import pieces_per_level_note as hook; "
41
+ "hook._child_arguments = lambda: [sys.executable, '-c', {child!r}]; sys.exit(hook.main())"
42
+ )
43
+
44
+
45
+ def _child_arguments(code: str) -> list[str]:
46
+ return [sys.executable, "-c", code]
47
+
48
+
49
+ def _shell_fields(command: str) -> dict[str, object]:
50
+ return {"tool_name": "Bash", "tool_input": {"command": command}}
51
+
52
+
53
+ def _mcp_fields(title: str, body: str) -> dict[str, object]:
54
+ return {
55
+ "tool_name": "mcp__github__create_pull_request",
56
+ "tool_input": {"title": title, "body": body},
57
+ }
58
+
59
+
60
+ def _bare_start_seconds() -> float:
61
+ all_runs = []
62
+ for _ in range(3):
63
+ started_at = time.perf_counter()
64
+ subprocess.run([sys.executable, "-c", "pass"], check=False)
65
+ all_runs.append(time.perf_counter() - started_at)
66
+ return min(all_runs)
67
+
68
+
69
+ def _run_hook_with_fake_child(
70
+ fields: dict[str, object], child_code: str
71
+ ) -> tuple[subprocess.CompletedProcess[str], float]:
72
+ runner_source = ALL_RUNNER_SOURCE.format(advisory=advisory_directory, child=child_code)
73
+ started_at = time.perf_counter()
74
+ completed = subprocess.run(
75
+ [sys.executable, "-c", runner_source],
76
+ input=json.dumps(fields),
77
+ capture_output=True,
78
+ text=True,
79
+ timeout=60,
80
+ check=False,
81
+ )
82
+ return completed, time.perf_counter() - started_at
83
+
84
+
85
+ def _marker_child_code(marker_path: Path) -> str:
86
+ return (
87
+ f"open({str(marker_path)!r}, 'w').write('started'); "
88
+ f"import time; time.sleep({STALL_SECONDS})"
89
+ )
90
+
91
+
92
+ def test_the_default_deadline_is_about_one_second_and_the_exit_wait_fits_inside_it() -> None:
93
+ assert 0.5 <= TOTAL_DEADLINE_SECONDS <= 1.5
94
+ assert 0 < EXIT_WAIT_SECONDS <= TOTAL_DEADLINE_SECONDS / 2
95
+
96
+
97
+ def test_a_child_that_never_prints_is_killed_at_the_deadline() -> None:
98
+ started_at = time.perf_counter()
99
+ output = pieces_per_level_note.analysis_output(
100
+ b"{}", _child_arguments(f"import time; time.sleep({STALL_SECONDS})"), SHORT_DEADLINE_SECONDS
101
+ )
102
+ assert output == b""
103
+ assert time.perf_counter() - started_at < RETURN_BOUND_SECONDS
104
+
105
+
106
+ def test_a_child_that_never_reads_a_large_payload_is_killed_at_the_deadline() -> None:
107
+ started_at = time.perf_counter()
108
+ output = pieces_per_level_note.analysis_output(
109
+ b"x" * 20_000_000,
110
+ _child_arguments(f"import time; time.sleep({STALL_SECONDS})"),
111
+ SHORT_DEADLINE_SECONDS,
112
+ )
113
+ assert output == b""
114
+ assert time.perf_counter() - started_at < RETURN_BOUND_SECONDS
115
+
116
+
117
+ def test_a_child_that_prints_then_hangs_after_closing_its_output_is_cut_off_at_the_exit_wait() -> (
118
+ None
119
+ ):
120
+ all_arguments = _child_arguments(
121
+ "import os, sys, time; sys.stdin.read(); sys.stdout.write('late'); sys.stdout.flush(); "
122
+ f"os.close(1); time.sleep({STALL_SECONDS})"
123
+ )
124
+ started_at = time.perf_counter()
125
+ output = pieces_per_level_note.analysis_output(b"{}", all_arguments, 3)
126
+ assert output == b""
127
+ assert time.perf_counter() - started_at < RETURN_BOUND_SECONDS
128
+
129
+
130
+ def test_a_child_that_starts_slowly_still_inside_the_deadline_passes_its_output_through() -> None:
131
+ all_arguments = _child_arguments(
132
+ "import sys, time; time.sleep(0.3); sys.stdin.read(); sys.stdout.write('done')"
133
+ )
134
+ assert pieces_per_level_note.analysis_output(b"{}", all_arguments, 20) == b"done"
135
+
136
+
137
+ def test_a_child_past_the_deadline_is_killed_and_does_not_finish_its_work(tmp_path: Path) -> None:
138
+ marker_path = tmp_path / "finished.txt"
139
+ all_arguments = _child_arguments(
140
+ f"import time; time.sleep(2.0); open({str(marker_path)!r}, 'w').write('finished')"
141
+ )
142
+ assert (
143
+ pieces_per_level_note.analysis_output(b"{}", all_arguments, SHORT_DEADLINE_SECONDS) == b""
144
+ )
145
+ time.sleep(3.0)
146
+ assert not marker_path.exists()
147
+
148
+
149
+ def test_an_analysis_that_exits_non_zero_gives_no_output() -> None:
150
+ all_arguments = _child_arguments(
151
+ "import sys; sys.stdin.read(); sys.stdout.write('x'); sys.exit(3)"
152
+ )
153
+ assert pieces_per_level_note.analysis_output(b"{}", all_arguments, 20) == b""
154
+
155
+
156
+ def test_a_child_that_cannot_start_gives_no_output() -> None:
157
+ assert (
158
+ pieces_per_level_note.analysis_output(b"{}", ["definitely-not-a-program-name"], 20) == b""
159
+ )
160
+
161
+
162
+ def test_the_hook_prints_nothing_and_exits_zero_when_its_child_never_prints(tmp_path: Path) -> None:
163
+ marker_path = tmp_path / "started.txt"
164
+ bare_start_seconds = _bare_start_seconds()
165
+ all_runs = [
166
+ _run_hook_with_fake_child(
167
+ _shell_fields(f'git commit -m "{MIXED_SUBJECT}"'), _marker_child_code(marker_path)
168
+ )
169
+ for _ in range(3)
170
+ ]
171
+ for each_completed, _each_seconds in all_runs:
172
+ assert each_completed.returncode == 0
173
+ assert each_completed.stdout == ""
174
+ assert each_completed.stderr == ""
175
+ assert marker_path.exists()
176
+ fastest_seconds = min(each_seconds for _each_completed, each_seconds in all_runs)
177
+ assert fastest_seconds < 3 * bare_start_seconds + TOTAL_DEADLINE_SECONDS + 1.0
178
+
179
+
180
+ @pytest.mark.parametrize(
181
+ "command",
182
+ [
183
+ "ls -la",
184
+ "git status",
185
+ "git log --grep=commit",
186
+ "mkdir createdir",
187
+ "npm run create-app",
188
+ 'git commit -m "fix(icons): put Tips on the tray"',
189
+ "git commit",
190
+ ],
191
+ )
192
+ def test_a_call_that_cannot_name_several_pieces_starts_no_child(
193
+ command: str, tmp_path: Path
194
+ ) -> None:
195
+ marker_path = tmp_path / "started.txt"
196
+ completed, _elapsed_seconds = _run_hook_with_fake_child(
197
+ _shell_fields(command), _marker_child_code(marker_path)
198
+ )
199
+ assert (completed.returncode, completed.stdout, completed.stderr) == (0, "", "")
200
+ assert not marker_path.exists()
201
+
202
+
203
+ @pytest.mark.parametrize(
204
+ "fields",
205
+ [
206
+ _shell_fields(f'git commit -m "{MIXED_SUBJECT}"'),
207
+ _shell_fields("git commit -F message.txt"),
208
+ _shell_fields("git commit -am 'fix: add a and b'"),
209
+ _shell_fields('git add x && git commit --message="fix: a; b"'),
210
+ _shell_fields('gh pr create --title "fix: a, b" --body-file body.md'),
211
+ _shell_fields("gh pr create --title t --body-file body.md"),
212
+ _shell_fields('python pull_request.py create --title "fix: a, b"'),
213
+ _mcp_fields(MIXED_SUBJECT, ""),
214
+ _mcp_fields("fix: one thing", "## What this does"),
215
+ ],
216
+ )
217
+ def test_a_call_that_may_name_several_pieces_is_worth_analysing(fields: dict[str, object]) -> None:
218
+ assert pieces_per_level_note.could_hold_a_note(fields)
219
+
220
+
221
+ @pytest.mark.parametrize(
222
+ "fields",
223
+ [
224
+ _shell_fields("ls -la"),
225
+ _shell_fields("git log --grep=commit"),
226
+ _shell_fields("npm run create-app"),
227
+ _shell_fields('git commit -m "fix(icons): put Tips on the tray"'),
228
+ _shell_fields("git status, git diff"),
229
+ _shell_fields("a, b " + "x" * 20_000 + " git commit -m y"),
230
+ _mcp_fields("fix: one thing", ""),
231
+ {"tool_name": "Bash", "tool_input": "git commit -m 'a, b'"},
232
+ {"tool_name": "Bash"},
233
+ {"tool_input": {}},
234
+ ],
235
+ )
236
+ def test_a_call_that_cannot_name_several_pieces_is_not_worth_analysing(
237
+ fields: dict[str, object],
238
+ ) -> None:
239
+ assert not pieces_per_level_note.could_hold_a_note(fields)
240
+
241
+
242
+ def test_the_parent_imports_none_of_the_analysis_modules() -> None:
243
+ source = (
244
+ f"import sys; sys.path.insert(0, {advisory_directory!r}); import pieces_per_level_note; "
245
+ "all_names = ('commit_and_pull_request_words', 'piece_clauses', 'pieces_per_level_analysis', "
246
+ "'hooks_constants.pre_tool_use_context_runner'); "
247
+ "print([each for each in all_names if each in sys.modules])"
248
+ )
249
+ completed = subprocess.run(
250
+ [sys.executable, "-c", source], capture_output=True, text=True, check=False
251
+ )
252
+ assert completed.stdout.strip() == "[]"
253
+
254
+
255
+ @pytest.mark.parametrize(
256
+ "raw_payload",
257
+ ["[" * 200_000, "{" * 200_000, '{"a":' * 100_000],
258
+ ids=["brackets", "braces", "nested keys"],
259
+ )
260
+ def test_a_payload_that_breaks_the_json_parser_gives_silence_and_exit_zero(
261
+ raw_payload: str,
262
+ ) -> None:
263
+ completed = subprocess.run(
264
+ [sys.executable, str(Path(advisory_directory) / "pieces_per_level_note.py")],
265
+ input=raw_payload,
266
+ capture_output=True,
267
+ text=True,
268
+ timeout=60,
269
+ check=False,
270
+ )
271
+ assert (completed.returncode, completed.stdout, completed.stderr) == (0, "", "")
272
+
273
+
274
+ def test_the_test_only_environment_variable_sets_the_deadline() -> None:
275
+ assert pieces_per_level_note.deadline_seconds({}) == TOTAL_DEADLINE_SECONDS
276
+ assert pieces_per_level_note.deadline_seconds({DEADLINE_ENVIRONMENT_VARIABLE: "30"}) == 30.0
277
+
278
+
279
+ @pytest.mark.parametrize("raw_value", ["", "soon", "0", "-2", "nan", "inf"])
280
+ def test_a_bad_environment_value_keeps_the_default_deadline(raw_value: str) -> None:
281
+ all_environment = {DEADLINE_ENVIRONMENT_VARIABLE: raw_value}
282
+ assert pieces_per_level_note.deadline_seconds(all_environment) == TOTAL_DEADLINE_SECONDS
@@ -1,22 +1,11 @@
1
1
  #!/usr/bin/env python3
2
- """Stop hook that checks the closing chat reply for an unvalidated claim.
2
+ """Stop hook that checks the closing chat reply for a path the terminal garbles.
3
3
 
4
- The reply length gate checks the chat tools. This gate checks the reply the
5
- session ends its turn with, which reaches the user with no tool call::
6
-
7
- flag: My guess is one to two hours.
8
- flag: I didn't confirm this one.
9
- flag: Run 18239174012 passed. (no tool result shows the run)
10
- ok: Run 18239174012 took 39 minutes. (a tool result shows the run)
11
-
12
- It applies the banned words, the unvalidated claim pattern, and the cited
13
- run, job, check, and pull request numbers from ``reply_length_gate.py``. A
14
- pull request link also counts as shown when hook or harness text shows it. The
15
- citation check is skipped when the transcript cannot be read. It also flags
16
- a path outside code whose backslash the terminal drops, such as
17
- ``D:\\Reports\\.claude``. A block sends
18
- the reason back so the model rewrites the reply. Claude Code ends the turn
19
- after eight blocks in a row.
4
+ This gate checks the reply the session ends its turn with, which reaches the
5
+ user with no tool call. It flags a path outside code whose backslash the
6
+ terminal drops, such as ``D:\\Reports\\.claude``. A block sends the reason
7
+ back so the model rewrites the reply. Claude Code ends the turn after eight
8
+ blocks in a row.
20
9
 
21
10
  It also blocks a reply whose last paragraph ends with a question mark, or says a question still stands, when the
22
11
  turn sent no AskUserQuestion, hearthbot decision card, or Codex
@@ -44,12 +33,6 @@ hooks_root_directory = str(Path(__file__).resolve().parent.parent)
44
33
  if hooks_root_directory not in sys.path:
45
34
  sys.path.insert(0, hooks_root_directory)
46
35
 
47
- from reply_length_gate import (
48
- banned_word_violation,
49
- configured_banned_words,
50
- unseen_citation_violation_with_hook_text,
51
- unvalidated_claim_violation,
52
- )
53
36
  from open_tasks_transcript import replayed_transcript
54
37
  from hooks_constants.hook_block_logger import log_hook_block
55
38
  from hooks_constants.pre_tool_use_stdin import read_hook_input_dictionary_from_stdin
@@ -270,12 +253,7 @@ def unbriefed_question_violation(reply_text: str, transcript_path: object) -> st
270
253
 
271
254
  def final_reply_violation(reply_text: str, transcript_path: object) -> str | None:
272
255
  """Return the block reason for the closing reply, or None when it passes."""
273
- return (
274
- banned_word_violation(reply_text, configured_banned_words())
275
- or unvalidated_claim_violation(reply_text)
276
- or unseen_citation_violation_with_hook_text(reply_text, transcript_path)
277
- or windows_path_violation(reply_text)
278
- )
256
+ return windows_path_violation(reply_text)
279
257
 
280
258
 
281
259
  def main() -> int: