claude-dev-env 8.116.0 → 8.116.2

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 (39) hide show
  1. package/bin/install.prompt-context.test.mjs +5 -6
  2. package/docs/rule-guides/proof-before-pull-request.md +4 -2
  3. package/hooks/blocking/final_reply_gate.py +7 -29
  4. package/hooks/blocking/followup_pr_dedupe.py +118 -33
  5. package/hooks/blocking/gate_run_reads.py +284 -0
  6. package/hooks/blocking/pr_lifecycle_skill_gate.py +33 -33
  7. package/hooks/blocking/pull_request_proof.py +60 -63
  8. package/hooks/blocking/test_final_reply_gate.py +4 -196
  9. package/hooks/blocking/test_followup_pr_dedupe.py +59 -0
  10. package/hooks/blocking/test_gate_run_reads.py +241 -0
  11. package/hooks/blocking/test_pr_lifecycle_skill_gate.py +89 -1
  12. package/hooks/blocking/test_pull_request_proof.py +63 -2
  13. package/hooks/features/conduct-gates.md +6 -13
  14. package/hooks/hooks.json +1 -42
  15. package/hooks/hooks_constants/background_silence_prompt_constants.py +2 -0
  16. package/hooks/hooks_constants/gate_run_reads_constants.py +10 -0
  17. package/hooks/hooks_constants/resolve_thread_reply_gate_constants.py +0 -8
  18. package/hooks/hooks_constants/test_followup_pr_dedupe_constants.py +0 -4
  19. package/hooks/session/background_silence_prompt.py +1 -1
  20. package/hooks/test_context_budget_hooks.py +0 -1
  21. package/package.json +1 -1
  22. package/scripts/durable_post_lint.py +0 -12
  23. package/scripts/durable_post_lint_config/config/constants.py +1 -2
  24. package/scripts/policy_lint/adapter_configuration.py +0 -2
  25. package/scripts/policy_lint/config/constants.py +0 -2
  26. package/scripts/test_durable_post_lint.py +0 -53
  27. package/scripts/tests/test_adapter_configuration.py +0 -16
  28. package/hooks/blocking/chat_reply_gate.py +0 -260
  29. package/hooks/blocking/reply_length_gate.py +0 -804
  30. package/hooks/blocking/test_chat_reply_gate.py +0 -302
  31. package/hooks/blocking/test_reply_length_gate.py +0 -1324
  32. package/hooks/hooks_constants/chat_reply_gate_constants.py +0 -60
  33. package/hooks/hooks_constants/reply_length_gate_constants.py +0 -203
  34. package/hooks/hooks_constants/test_reply_length_gate_constants.py +0 -81
  35. package/hooks/hooks_constants/test_visual_reply_rules_constants.py +0 -50
  36. package/hooks/hooks_constants/visual_reply_rules_constants.py +0 -106
  37. package/hooks/test_visual_reply_rules.py +0 -362
  38. package/hooks/visual_reply_rules.py +0 -478
  39. package/rules/visual-reply-rules.json +0 -56
@@ -0,0 +1,241 @@
1
+ """Behavior tests for the answers one pull request lifecycle gate run remembers."""
2
+
3
+ import json
4
+ import sys
5
+ import time
6
+ from pathlib import Path
7
+
8
+ import pytest
9
+
10
+ HOOKS_DIRECTORY = Path(__file__).resolve().parent.parent
11
+ if str(HOOKS_DIRECTORY) not in sys.path:
12
+ sys.path.insert(0, str(HOOKS_DIRECTORY))
13
+
14
+ from blocking import gate_run_reads
15
+ from blocking.gate_run_reads import (
16
+ ReadSlice,
17
+ answer_once,
18
+ answer_within_allowance,
19
+ child_stdout,
20
+ gate_run,
21
+ read_allowance,
22
+ read_deadlines_started,
23
+ )
24
+ from hooks_constants.followup_pr_dedupe_constants import READ_TIMEOUT_SECONDS
25
+ from hooks_constants.gate_run_reads_constants import (
26
+ FOLLOWUP_READS_SECONDS,
27
+ KILL_GRACE_SECONDS,
28
+ MOST_CUT_READS_PER_RUN,
29
+ PROOF_AND_LOOK_READS_SECONDS,
30
+ STARTUP_AND_SCAN_MARGIN_SECONDS,
31
+ )
32
+
33
+ CLOCK_START = 100.0
34
+ HIDDEN_WINDOW_FLAGS = 0x08000000
35
+ SLEEP_THEN_PRINT = "import time; time.sleep(30); print('late')"
36
+ GRANDCHILD_HOLDS_THE_PIPE = (
37
+ "import subprocess, sys, time;"
38
+ " subprocess.Popen([sys.executable, '-c', 'import time; time.sleep(30)']);"
39
+ " time.sleep(30)"
40
+ )
41
+ ELAPSED_SLACK_SECONDS = 8.0
42
+ GATE_COMMAND_SUFFIX = "hooks/blocking/pr_lifecycle_" + "skill_gate.py"
43
+
44
+
45
+ class FakeClock:
46
+ def __init__(self) -> None:
47
+ self.now = CLOCK_START
48
+
49
+ def __call__(self) -> float:
50
+ return self.now
51
+
52
+
53
+ def _counting_read(all_reads: list[str], answer: str | None):
54
+ def read() -> str | None:
55
+ all_reads.append("read")
56
+ return answer
57
+
58
+ return read
59
+
60
+
61
+ def test_answer_once_should_read_a_question_once_inside_one_run() -> None:
62
+ all_reads: list[str] = []
63
+ with gate_run():
64
+ assert (
65
+ answer_once(("origin", "/repo"), _counting_read(all_reads, "owner/name"))
66
+ == "owner/name"
67
+ )
68
+ assert (
69
+ answer_once(("origin", "/repo"), _counting_read(all_reads, "other/name"))
70
+ == "owner/name"
71
+ )
72
+ assert all_reads == ["read"]
73
+
74
+
75
+ def test_answer_once_should_remember_an_unanswered_read() -> None:
76
+ all_reads: list[str] = []
77
+ with gate_run():
78
+ assert answer_once(("origin", "/repo"), _counting_read(all_reads, None)) is None
79
+ assert answer_once(("origin", "/repo"), _counting_read(all_reads, "owner/name")) is None
80
+ assert all_reads == ["read"]
81
+
82
+
83
+ def test_answer_once_should_read_each_time_with_no_run_open() -> None:
84
+ all_reads: list[str] = []
85
+ assert answer_once(("origin", "/repo"), _counting_read(all_reads, "a")) == "a"
86
+ assert answer_once(("origin", "/repo"), _counting_read(all_reads, "b")) == "b"
87
+ assert all_reads == ["read", "read"]
88
+
89
+
90
+ def test_gate_run_should_forget_its_answers_when_it_closes() -> None:
91
+ all_reads: list[str] = []
92
+ with gate_run() as first_run:
93
+ answer_once(("origin", "/repo"), _counting_read(all_reads, "a"))
94
+ with gate_run():
95
+ assert answer_once(("origin", "/repo"), _counting_read(all_reads, "b")) == "b"
96
+ assert first_run.answer_by_question == {("origin", "/repo"): "a"}
97
+ assert all_reads == ["read", "read"]
98
+
99
+
100
+ def test_read_allowance_should_keep_the_own_timeout_with_no_deadline_started() -> None:
101
+ assert read_allowance(5, ReadSlice.PROOF_AND_LOOK) == 5
102
+ assert read_allowance(4, ReadSlice.FOLLOWUP) == 4
103
+
104
+
105
+ def test_read_allowance_should_take_the_smaller_of_the_own_timeout_and_the_time_left() -> None:
106
+ clock = FakeClock()
107
+ with read_deadlines_started(clock):
108
+ assert read_allowance(5, ReadSlice.PROOF_AND_LOOK) == 5
109
+ clock.now = CLOCK_START + 9
110
+ assert read_allowance(5, ReadSlice.PROOF_AND_LOOK) == 3
111
+ clock.now = CLOCK_START + 18
112
+ assert read_allowance(4, ReadSlice.FOLLOWUP) == 2
113
+ assert read_allowance(5, ReadSlice.PROOF_AND_LOOK) == 5
114
+
115
+
116
+ def test_read_allowance_should_keep_the_reserved_slice_for_followup_reads() -> None:
117
+ clock = FakeClock()
118
+ with read_deadlines_started(clock):
119
+ clock.now = CLOCK_START + PROOF_AND_LOOK_READS_SECONDS - 0.5
120
+ assert read_allowance(5, ReadSlice.PROOF_AND_LOOK) == 0.5
121
+ assert read_allowance(4, ReadSlice.FOLLOWUP) == 4
122
+ clock.now = CLOCK_START + PROOF_AND_LOOK_READS_SECONDS
123
+ assert read_allowance(5, ReadSlice.PROOF_AND_LOOK) is None
124
+ assert read_allowance(4, ReadSlice.FOLLOWUP) == 4
125
+ clock.now = CLOCK_START + PROOF_AND_LOOK_READS_SECONDS + FOLLOWUP_READS_SECONDS
126
+ assert read_allowance(4, ReadSlice.FOLLOWUP) is None
127
+
128
+
129
+ def test_child_stdout_should_skip_a_read_with_no_time_left(tmp_path: Path) -> None:
130
+ marker_path = tmp_path / "ran.txt"
131
+ clock = FakeClock()
132
+ with read_deadlines_started(clock), gate_run() as run:
133
+ clock.now = CLOCK_START + PROOF_AND_LOOK_READS_SECONDS
134
+ command = [sys.executable, "-c", f"open({str(marker_path)!r}, 'w').write('x')"]
135
+ assert child_stdout(command, 5, ReadSlice.PROOF_AND_LOOK) is None
136
+ assert not marker_path.exists()
137
+ assert run.was_read_cut_short
138
+
139
+
140
+ def test_child_stdout_should_return_the_output_of_a_child_that_answers() -> None:
141
+ with gate_run() as run:
142
+ assert child_stdout([sys.executable, "-c", "print('answer')"], 5, ReadSlice.PROOF_AND_LOOK) == "answer\n"
143
+ assert child_stdout([sys.executable, "-c", "raise SystemExit(3)"], 5, ReadSlice.PROOF_AND_LOOK) is None
144
+ assert not run.was_read_cut_short
145
+
146
+
147
+ def test_child_stdout_should_start_its_child_with_the_hidden_window_flags(monkeypatch: pytest.MonkeyPatch) -> None:
148
+ all_seen_flags: list[object] = []
149
+
150
+ def refuse_to_start(*all_arguments: object, **all_options: object) -> None:
151
+ all_seen_flags.append(all_options.get("creationflags"))
152
+ raise OSError("this test starts no child")
153
+
154
+ monkeypatch.setattr(gate_run_reads, "hidden_window_creation_flags", lambda: HIDDEN_WINDOW_FLAGS)
155
+ monkeypatch.setattr(gate_run_reads.subprocess, "Popen", refuse_to_start)
156
+ assert child_stdout(["git", "status"], 5, ReadSlice.PROOF_AND_LOOK) is None
157
+ assert all_seen_flags == [HIDDEN_WINDOW_FLAGS]
158
+
159
+
160
+ def test_child_stdout_should_kill_a_child_that_outlives_its_own_timeout() -> None:
161
+ with gate_run() as run:
162
+ started = time.monotonic()
163
+ assert child_stdout([sys.executable, "-c", SLEEP_THEN_PRINT], 0.5, ReadSlice.PROOF_AND_LOOK) is None
164
+ elapsed = time.monotonic() - started
165
+ assert elapsed < 0.5 + ELAPSED_SLACK_SECONDS
166
+ assert not run.was_read_cut_short
167
+
168
+
169
+ def test_child_stdout_should_stop_waiting_when_a_grandchild_holds_the_pipe() -> None:
170
+ started = time.monotonic()
171
+ assert child_stdout([sys.executable, "-c", GRANDCHILD_HOLDS_THE_PIPE], 0.5, ReadSlice.PROOF_AND_LOOK) is None
172
+ assert time.monotonic() - started < 0.5 + KILL_GRACE_SECONDS + ELAPSED_SLACK_SECONDS
173
+
174
+
175
+ def test_child_stdout_should_mark_the_run_when_the_deadline_cuts_a_read_short() -> None:
176
+ clock = FakeClock()
177
+ with read_deadlines_started(clock), gate_run() as run:
178
+ clock.now = CLOCK_START + PROOF_AND_LOOK_READS_SECONDS - 0.4
179
+ started = time.monotonic()
180
+ assert child_stdout([sys.executable, "-c", SLEEP_THEN_PRINT], 5, ReadSlice.PROOF_AND_LOOK) is None
181
+ elapsed = time.monotonic() - started
182
+ assert elapsed < 0.4 + ELAPSED_SLACK_SECONDS
183
+ assert run.was_read_cut_short
184
+
185
+
186
+ def _slow_read(allowance: float) -> list[str]:
187
+ time.sleep(allowance + 30)
188
+ return ["late"]
189
+
190
+
191
+ def test_answer_within_allowance_should_bound_the_whole_read() -> None:
192
+ clock = FakeClock()
193
+ with read_deadlines_started(clock), gate_run() as run:
194
+ clock.now = CLOCK_START + PROOF_AND_LOOK_READS_SECONDS + FOLLOWUP_READS_SECONDS - 0.3
195
+ started = time.monotonic()
196
+ answer = answer_within_allowance(_slow_read, 4, ReadSlice.FOLLOWUP)
197
+ elapsed = time.monotonic() - started
198
+ assert answer is None
199
+ assert elapsed < 0.3 + ELAPSED_SLACK_SECONDS
200
+ assert run.was_read_cut_short
201
+
202
+
203
+ def test_answer_within_allowance_should_return_the_answer_and_raise_the_read_error() -> None:
204
+ all_allowances: list[float] = []
205
+
206
+ def answering_read(allowance: float) -> list[str]:
207
+ all_allowances.append(allowance)
208
+ return ["ok"]
209
+
210
+ def failing_read(allowance: float) -> list[str]:
211
+ raise OSError("offline")
212
+
213
+ assert answer_within_allowance(answering_read, 4, ReadSlice.FOLLOWUP) == ["ok"]
214
+ assert all_allowances == [4]
215
+ with pytest.raises(OSError, match="offline"):
216
+ answer_within_allowance(failing_read, 4, ReadSlice.FOLLOWUP)
217
+
218
+
219
+ def _registered_gate_timeout_seconds() -> int:
220
+ all_registration_fields = json.loads((HOOKS_DIRECTORY / "hooks.json").read_text(encoding="utf-8"))
221
+ all_timeouts = [
222
+ each_hook["timeout"]
223
+ for each_group in all_registration_fields["hooks"]["PreToolUse"]
224
+ for each_hook in each_group["hooks"]
225
+ if each_hook.get("command", "").endswith(GATE_COMMAND_SUFFIX)
226
+ ]
227
+ assert len(all_timeouts) == 1
228
+ return all_timeouts[0]
229
+
230
+
231
+ def test_both_followup_reads_should_fit_inside_their_reserved_slice() -> None:
232
+ assert READ_TIMEOUT_SECONDS * 2 <= FOLLOWUP_READS_SECONDS
233
+
234
+
235
+ def test_registered_timeout_should_outlast_every_read_deadline_and_kill_grace() -> None:
236
+ last_read_ends_at = (
237
+ PROOF_AND_LOOK_READS_SECONDS
238
+ + FOLLOWUP_READS_SECONDS
239
+ + KILL_GRACE_SECONDS * MOST_CUT_READS_PER_RUN
240
+ )
241
+ assert _registered_gate_timeout_seconds() >= last_read_ends_at + STARTUP_AND_SCAN_MARGIN_SECONDS
@@ -7,17 +7,24 @@ from io import BytesIO, StringIO, TextIOWrapper
7
7
  from pathlib import Path
8
8
  from unittest.mock import patch
9
9
 
10
+ import pytest
11
+
10
12
  HOOKS_DIRECTORY = Path(__file__).resolve().parent.parent
11
13
  if str(HOOKS_DIRECTORY) not in sys.path:
12
14
  sys.path.insert(0, str(HOOKS_DIRECTORY))
13
15
 
14
16
  from blocking import followup_pr_dedupe as gate_dedupe
17
+ from blocking import gate_run_reads
15
18
  from blocking import pr_lifecycle_skill_gate as gate
19
+ from blocking.gate_run_reads import read_deadlines_started
20
+ from hooks_constants.followup_pr_dedupe_constants import ALL_GIT_REMOTE_COMMAND_WORDS
21
+ from hooks_constants.gate_run_reads_constants import PROOF_AND_LOOK_READS_SECONDS, READS_RAN_OUT_SENTENCE
16
22
  from hooks_constants.pr_lifecycle_skill_gate_constants import DENY_REASON
17
23
  from hooks_constants.pull_request_proof_constants import (
18
24
  MISSING_BUILD_EVAL_REASON,
19
25
  MISSING_PROOF_REASON,
20
26
  UNPROVEN_PROOF_REASON,
27
+ UNREADABLE_CHANGES_REASON,
21
28
  )
22
29
 
23
30
  WHAT_THIS_DOES_SECTION = (
@@ -309,7 +316,7 @@ def test_hook_has_its_own_pre_tool_use_registration() -> None:
309
316
  {
310
317
  "type": "command",
311
318
  "command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/blocking/pr_lifecycle_skill_gate.py",
312
- "timeout": 10,
319
+ "timeout": 30,
313
320
  }
314
321
  ],
315
322
  }
@@ -354,6 +361,87 @@ def test_loaded_skill_allows_a_followup_when_the_read_fails(tmp_path: Path) -> N
354
361
  assert gate.decision_for(payload) is None
355
362
 
356
363
 
364
+ PICTURE_LINE = "![after](https://example.com/after.png)\n"
365
+ CREATE_WORDS = " ".join(("gh", "pr", "create"))
366
+
367
+
368
+ def _unstarted_children(monkeypatch: pytest.MonkeyPatch) -> list[list[str]]:
369
+ all_asked_commands: list[list[str]] = []
370
+
371
+ def refuse_to_start(all_command_words: list[str], **all_options: object) -> None:
372
+ all_asked_commands.append(list(all_command_words))
373
+ raise OSError("this test starts no child")
374
+
375
+ monkeypatch.setattr(gate_run_reads.subprocess, "Popen", refuse_to_start)
376
+ return all_asked_commands
377
+
378
+
379
+ def _origin_reads(all_asked_commands: list[list[str]]) -> int:
380
+ return sum(each_command == list(ALL_GIT_REMOTE_COMMAND_WORDS) for each_command in all_asked_commands)
381
+
382
+
383
+ def _quoted_shell_create_without_repository(tmp_path: Path, body: str) -> dict[str, object]:
384
+ (tmp_path / "body.md").write_text(body, encoding="utf-8")
385
+ return {
386
+ "tool_name": "Bash",
387
+ "tool_input": {"command": CREATE_WORDS + ' --title "fix: quoted title" --body-file body.md'},
388
+ "cwd": str(tmp_path),
389
+ }
390
+
391
+
392
+ def test_one_gate_run_should_read_the_origin_once_for_a_followup_body(
393
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
394
+ ) -> None:
395
+ all_asked_commands = _unstarted_children(monkeypatch)
396
+ payload = _quoted_shell_create_without_repository(tmp_path, PROVEN_FOLLOWUP_BODY + PICTURE_LINE)
397
+ assert gate.decision_for(payload) is None
398
+ assert _origin_reads(all_asked_commands) == 1
399
+
400
+
401
+ def test_gate_should_not_read_the_origin_when_no_body_names_a_parent(
402
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
403
+ ) -> None:
404
+ all_asked_commands = _unstarted_children(monkeypatch)
405
+ body = PROVEN_FOLLOWUP_BODY.replace("Follow-up to #1731", "Adds a guard.") + PICTURE_LINE
406
+ payload = _quoted_shell_create_without_repository(tmp_path, body)
407
+ assert gate.decision_for(payload) is None
408
+ assert _origin_reads(all_asked_commands) == 0
409
+
410
+
411
+ class LateClock:
412
+ """Reads zero at the start, then the end of the proof and look slice on every later read."""
413
+
414
+ def __init__(self) -> None:
415
+ self.read_count = 0
416
+
417
+ def __call__(self) -> float:
418
+ self.read_count += 1
419
+ return 0.0 if self.read_count == 1 else float(PROOF_AND_LOOK_READS_SECONDS)
420
+
421
+
422
+ def _mcp_create_without_repository(tmp_path: Path) -> dict[str, object]:
423
+ body = PROVEN_FOLLOWUP_BODY.replace("Follow-up to #1731", "Adds a guard.")
424
+ return {
425
+ "tool_name": "mcp__github__create_pull_request",
426
+ "tool_input": {"title": "fix: x", "body": body, "head": "feature"},
427
+ "cwd": str(tmp_path),
428
+ }
429
+
430
+
431
+ def test_deny_should_add_the_reads_ran_out_sentence_when_the_deadline_cut_a_read(tmp_path: Path) -> None:
432
+ payload = _mcp_create_without_repository(tmp_path)
433
+ with read_deadlines_started(LateClock()):
434
+ decision = gate.decision_for(payload)
435
+ assert decision is not None
436
+ assert decision["hookSpecificOutput"]["permissionDecisionReason"] == UNREADABLE_CHANGES_REASON + READS_RAN_OUT_SENTENCE
437
+
438
+
439
+ def test_deny_should_keep_its_reason_when_every_read_had_time(tmp_path: Path) -> None:
440
+ decision = gate.decision_for(_mcp_create_without_repository(tmp_path))
441
+ assert decision is not None
442
+ assert decision["hookSpecificOutput"]["permissionDecisionReason"] == UNREADABLE_CHANGES_REASON
443
+
444
+
357
445
  def test_loaded_skill_still_denies_a_new_pull_request_without_proof(tmp_path: Path) -> None:
358
446
  exit_code, output = _run_main(_payload("gh pr create --body 'Adds a gate.'", _transcript(tmp_path, "pr-lifecycle")))
359
447
  assert exit_code == 0
@@ -12,6 +12,7 @@ if str(HOOKS_DIRECTORY) not in sys.path:
12
12
  sys.path.insert(0, str(HOOKS_DIRECTORY))
13
13
 
14
14
  from blocking import pull_request_proof as gate
15
+ from blocking.pr_lifecycle_skill_gate import decision_for
15
16
  from hooks_constants.pull_request_proof_constants import (
16
17
  COMPARE_FILE_LIST_LIMIT,
17
18
  COMPARE_FILE_STATUS_QUERY,
@@ -764,7 +765,7 @@ def test_should_deny_a_visible_file_on_a_full_compare_page(
764
765
  assert "module_0.py" not in reason
765
766
 
766
767
 
767
- def test_should_allow_a_page_the_compare_api_lists_when_the_proof_links_an_artifact(
768
+ def test_should_allow_a_page_whose_proof_links_an_artifact_without_a_read(
768
769
  tmp_path: Path, monkeypatch: pytest.MonkeyPatch
769
770
  ) -> None:
770
771
  all_endpoints: list[str] = []
@@ -777,7 +778,7 @@ def test_should_allow_a_page_the_compare_api_lists_when_the_proof_links_an_artif
777
778
  tmp_path,
778
779
  )
779
780
  assert gate.missing_look_reason(payload) is None
780
- assert all_endpoints == [compare_endpoint]
781
+ assert all_endpoints == []
781
782
 
782
783
 
783
784
  def test_should_skip_the_compare_api_without_a_named_repository(
@@ -1112,6 +1113,66 @@ def test_remote_added_workflow_files_should_report_none_when_a_full_page_lists_n
1112
1113
  assert gate.remote_added_workflow_files(None, "main", "feature") is None
1113
1114
 
1114
1115
 
1116
+ WAIVER_BODY = (
1117
+ "## What this does\nAdds a guard to the tool.\n\n"
1118
+ "```mermaid\nflowchart LR\n A[call] --> B[guard]\n```\n\n"
1119
+ "## Existing work\nNothing found; I searched `hooks/` and open pull requests.\n\n"
1120
+ "## Proof in practice\nRan `python3 tool.py --check` and it printed `ok`.\n"
1121
+ "Not run: the first GitHub Actions workflow run.\n\n"
1122
+ "## After merge\nThe session records the run link for `new.yml`.\n"
1123
+ )
1124
+
1125
+
1126
+ def test_quoted_shell_create_should_look_up_the_added_workflows_once(
1127
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1128
+ ) -> None:
1129
+ all_endpoints: list[str] = []
1130
+ compare_endpoint = "repos/owner/name/compare/main...some-branch"
1131
+ all_responses = {compare_endpoint: _workflow_compare_lines(1, [f"{WORKFLOW_DIRECTORY}/new.yml"])}
1132
+ monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api(all_responses, all_endpoints))
1133
+ (tmp_path / "body.md").write_text(WAIVER_BODY, encoding="utf-8")
1134
+ payload = _shell(
1135
+ 'gh pr create --title "fix: quoted title" --body-file body.md'
1136
+ " --head some-branch --base main --repo owner/name",
1137
+ tmp_path,
1138
+ )
1139
+ assert gate.missing_proof_reason(payload) is None
1140
+ assert all_endpoints.count(compare_endpoint) == 1
1141
+
1142
+
1143
+ def test_look_check_should_read_nothing_when_every_body_shows_a_picture(
1144
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1145
+ ) -> None:
1146
+ all_endpoints: list[str] = []
1147
+ monkeypatch.setattr(gate, "_gh_api_lines", _fake_gh_api({}, all_endpoints))
1148
+ body = PROVEN_BODY + "![after](https://example.com/after.png)\n"
1149
+ payload = _shell_create_elsewhere(tmp_path, "--repo o/r --base main --head feature", body)
1150
+ assert gate.missing_look_reason(payload) is None
1151
+ assert all_endpoints == []
1152
+ no_picture_payload = _shell_create_elsewhere(tmp_path, "--repo o/r --base main --head feature")
1153
+ assert gate.missing_look_reason(no_picture_payload) == UNREADABLE_CHANGES_REASON
1154
+ assert all_endpoints == ["repos/o/r/compare/main...feature"]
1155
+
1156
+
1157
+ def test_one_gate_run_should_resolve_the_merge_base_once_for_the_waiver_and_look_checks(
1158
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
1159
+ ) -> None:
1160
+ clone_path = _repository_with_workflow_change(tmp_path, "new.yml")
1161
+ all_head_references: list[str] = []
1162
+ original_first_merge_base = gate._first_merge_base
1163
+
1164
+ def counted_first_merge_base(working_directory: str, head_reference: str) -> str | None:
1165
+ all_head_references.append(head_reference)
1166
+ return original_first_merge_base(working_directory, head_reference)
1167
+
1168
+ monkeypatch.setattr(gate, "_first_merge_base", counted_first_merge_base)
1169
+ payload = _mcp_create_on_branch(WAIVER_BODY, clone_path)
1170
+ assert decision_for(payload) is None
1171
+ assert all_head_references == ["HEAD"]
1172
+ assert decision_for(payload) is None
1173
+ assert all_head_references == ["HEAD", "HEAD"]
1174
+
1175
+
1115
1176
  def test_unproven_line_should_stay_denied_when_it_is_about_something_other_than_a_run(tmp_path: Path) -> None:
1116
1177
  clone_path = _repository_with_workflow_change(tmp_path, NEW_WORKFLOW_NAME)
1117
1178
  unrelated_line = "Untested on Windows."
@@ -4,13 +4,11 @@ This family stops a chat reply, edited message, or tool call when its payload br
4
4
 
5
5
  ## Checks
6
6
 
7
- - `blocking/reply_length_gate.py` caps chat reply length, denies a configured banned word, requires a readable link when the text names a pull request number, and denies a causal claim in a reply that cites no code span, output block, or link. It denies a sentence that guesses, estimates, hedges a duration, or admits a skipped check, such as "I didn't confirm this one." It denies a cited Actions run, pull request, or run, job, or check id that no successful tool result in the transcript shows; a subagent's report is the result of its Agent call. A question card from `AskUserQuestion` gets the banned word check and `unvalidated_claim_violation`, like a decision card. One refusal names every broken rule and every offending sentence, numbered, and ends with "Fix every item above in your next write." With visual reply mode on, it also runs the checks in `visual_reply_rules.py` from the rule list in `rules/visual-reply-rules.json`: no abbreviation or tracker number outside a link, a widget or page before a reply of more than one sentence, and no anchor link inside widget code. The mode is off by default; `~/.claude/visual-reply-mode.json` with `{"enabled": true}` turns the mode checks on. The results-picture check runs with the mode off too. A reply with a markdown table, or more than two figures, needs a picture: an attached `.svg`, `.png`, `.jpg`, `.jpeg`, `.gif`, or `.webp` file, an attached `frame` output such as a published page, or a markdown picture outside code. The check reads the attached name only, so it does not confirm that the file exists. It skips an edit of a posted message, because the edit tool attaches nothing, and the closing reply of a turn, which `blocking/final_reply_gate.py` does not run it on.
8
- - `blocking/final_reply_gate.py` applies the banned words, `unvalidated_claim_violation`, and `unseen_citation_violation_with_hook_text` from the reply gate to the reply a session ends its turn with. In that citation check a `/pull/N` link also counts as shown when hook or harness text shows it: stop-hook feedback, system reminders, a background agent's task notification, and hook additional context, hook system message, and queued task notification attachments. A skill body, or a prompt the user typed while the session worked, does not count. The gate's own feedback, which quotes the reply, does not count. Its `windows_path_violation` blocks a path the terminal would render without one of its backslashes. Its `unbriefed_question_violation` blocks a reply whose last paragraph, with fences, quotes, and code spans left out, ends with a question mark or says a question still stands, when the turn sent no `AskUserQuestion`, hearthbot decision card, or Codex `request_user_input` call; it is skipped when the transcript cannot be read.
7
+ - `blocking/final_reply_gate.py` checks the reply a session ends its turn with. Its `windows_path_violation` blocks a path the terminal would render without one of its backslashes. Its `unbriefed_question_violation` blocks a reply whose last paragraph, with fences, quotes, and code spans left out, ends with a question mark or says a question still stands, when the turn sent no `AskUserQuestion`, hearthbot decision card, or Codex `request_user_input` call; it is skipped when the transcript cannot be read.
9
8
  - `blocking/open_tasks_stop_gate.py` holds the end of a turn once when the prompt that started it asks for work, the turn ran a work tool, and the turn made no tracker call: TaskCreate, TaskUpdate, TodoWrite, the Codex `update_plan`, or the desktop `mcp__ccd_turn__update_plan`. A work tool is any tool but a tracker call, the session title tool, `AskUserQuestion`, a hearthbot decision card, Codex `request_user_input`, `ToolSearch`, `TaskList`, or `TaskGet`. It never reads the reply text. `open_task_asks.is_ask` decides whether a prompt asks for work: a question-only prompt, an acknowledgement such as `thanks!`, an empty prompt, a prompt of only `<system-reminder>` blocks, and an envelope such as `<agent-message>` or `<task-notification>` do not. `blocking/open_tasks_transcript.py` replays the transcript for it: the turn's prompt, its tool calls, and the task list. `session_task_items` merges the task store with the transcript items whose subject the store does not hold, for the session title gate.
10
9
  - `session/tracking_nudge.py` adds one `additionalContext` note to a prompt that asks for work. The note asks for an item in the session's task list tool. It shows on the session's first ask and on the first ask after each compaction, through `once_per_session.py`. When the title shows the red flag or the check mark, it also asks for the hourglass before other work. It never blocks.
11
10
  - `session/background_silence_prompt.py` adds one `additionalContext` note to a background event prompt, one that starts with `<task-notification>` or opens itself or a `<system-reminder>` block with `[SYSTEM NOTIFICATION - NOT USER INPUT]`, while the user asked for silence. The newest user-typed message that sets silence ("silent unless", "stay silent", "silent on updates", "no updates unless") or lifts it ("you can talk again", "updates are fine", "stop being silent") decides. The note quotes the user's "unless" or "except" clause word for word, or the whole message when it has no such clause, and says to end the turn with no text unless that exception applies now. Envelope prompts, compaction summaries, and quoted `>` lines are not the user's words. It never blocks.
12
- - The claim judge is a `prompt` hook in `hooks.json`, with no `model` set, so Claude Code's small default hook model reads each chat message and denies every claim, numbered in one refusal, about how code, a file, a tool, a service, a run, or a process behaves, or why something happened, when nothing in the message shows it: inline code that quotes output or a code line, a file and line, or a link. A pull request link covers what that change does, what it blocks or lets through, and its checks. The author's own actions, a restatement of the user's words, questions, instructions, and a decision card's option consequences pass. It catches the plain claims the causal word list in `blocking/reply_length_gate.py` misses, such as "The code lets any of them rewrite it mid-check." `continueOnBlock` returns the reason to the agent as the tool error, so it can add the source and send again. The installer owns it through the `claude-dev-env: ` prefix on its `statusMessage`. It skips `post_widget`, whose input is SVG or HTML markup.
13
- - `blocking/chat_reply_gate.py` runs the `reply_length_gate.py` reply checks on a plain chat reply, which is no tool call. On the first `UserPromptSubmit` of a session, and on the first one after each compaction, it adds the reply rules as `additionalContext`. On `MessageDisplay` it holds each streamed batch until the message ends. A message that passes shows whole. A message that fails shows as a draft from `claude -p` on Haiku that passes the same checks, and the original shows when two drafts fail. The draft changes only the text on screen, so the next `UserPromptSubmit` tells the agent the text the user saw, and `SessionEnd` deletes the stored draft and the session's once-per-session markers for all three hooks. The [reply arena harness](https://github.com/jl-cmd-projects/claude-dev-env/tree/160349b90f627ea542fc6bc7b2b7f86dcbf98b73/tests/reply_arena) ran the comparison that chose this display path.
11
+ - The claim judge is a `prompt` hook in `hooks.json`, with no `model` set, so Claude Code's small default hook model reads each chat message and denies every claim, numbered in one refusal, about how code, a file, a tool, a service, a run, or a process behaves, or why something happened, when nothing in the message shows it: inline code that quotes output or a code line, a file and line, or a link. A pull request link covers what that change does, what it blocks or lets through, and its checks. The author's own actions, a restatement of the user's words, questions, instructions, and a decision card's option consequences pass. It catches plain claims such as "The code lets any of them rewrite it mid-check." `continueOnBlock` returns the reason to the agent as the tool error, so it can add the source and send again. The installer owns it through the `claude-dev-env: ` prefix on its `statusMessage`. It skips `post_widget`, whose input is SVG or HTML markup.
14
12
  - `blocking/edit_marker_gate.py` rejects strikethrough and edit-note markers in replacement chat text or cards.
15
13
  - `blocking/issue_close_handoff_gate.py` denies an issue comment or issue write that closes the issue and routes a found defect to another issue or epic.
16
14
  - `blocking/session_title_format_gate.py` denies a session title that breaks the `<emoji> <name>` shape or has a name longer than 25 characters.
@@ -19,7 +17,7 @@ This family stops a chat reply, edited message, or tool call when its payload br
19
17
  - `blocking/wakeup_cap_gate.py` keeps a self-wakeup inside the 1-hour prompt cache. A wake over the step-down (57 minutes for `send_later` and Routines, 3480 seconds for `ScheduleWakeup`) and at most 60 minutes away runs with its delay rewritten to the step-down. A wake over 60 minutes away, or a cron with more than 57 minutes between wakes, is denied with a reason that says to stack wakes under the cap. A Routine that starts a fresh session on each firing passes.
20
18
  - `blocking/verify_before_acting.py` blocks a completed mutating call when the agent's reasoning contains an unchecked claim. For an `Agent` or `Task` spawn it adds the same quote as an advisory note and does not block.
21
19
  - `blocking/pr_lifecycle_skill_gate.py` denies a commit, push, pull request action, or merge until the `pr-lifecycle` skill appears in the transcript since the last compaction. Read-only `gh pr` subcommands (`view`, `list`, `checks`, `diff`, `status`) pass without it, unless a later argument names another `gh pr` subcommand.
22
- - `blocking/resolve_thread_reply_gate.py` denies a review thread resolve until the agent's own transcript shows a reply on that same thread that posted after the last user prompt and that no successful resolve of the thread has spent. A resolve is a `resolve_review_thread` call, which names the thread by `threadID`; a `pull_request_review_write` call with method `resolve_thread`, which names it by `threadId`; a shell command with a `gh api graphql` `resolveReviewThread` mutation, which names it by a literal `PRRT_` id; or a shell call to `pulls/<n>/ccr/comments/<id>/resolve`, which names it by a comment id. A graphql resolve that names no `PRRT_` id is denied. A reply is an `add_reply_to_pull_request_comment` call, or a `gh api` call to a comment's `replies` endpoint or to `addPullRequestReviewThreadReply`, which names its thread by `PRRT_` id. A reply and a resolve by comment id match when they name the same comment, or when a successful tool result in the transcript, such as `pull_request_read` `get_review_comments`, lists the comment under the thread by its `discussion_r` anchor or `databaseId`. A reply whose result is an error, such as a refusal from `blocking/reply_length_gate.py`, does not count. With no readable transcript, the resolve passes.
20
+ - `blocking/resolve_thread_reply_gate.py` denies a review thread resolve until the agent's own transcript shows a reply on that same thread that posted after the last user prompt and that no successful resolve of the thread has spent. A resolve is a `resolve_review_thread` call, which names the thread by `threadID`; a `pull_request_review_write` call with method `resolve_thread`, which names it by `threadId`; a shell command with a `gh api graphql` `resolveReviewThread` mutation, which names it by a literal `PRRT_` id; or a shell call to `pulls/<n>/ccr/comments/<id>/resolve`, which names it by a comment id. A graphql resolve that names no `PRRT_` id is denied. A reply is an `add_reply_to_pull_request_comment` call, or a `gh api` call to a comment's `replies` endpoint or to `addPullRequestReviewThreadReply`, which names its thread by `PRRT_` id. A reply and a resolve by comment id match when they name the same comment, or when a successful tool result in the transcript, such as `pull_request_read` `get_review_comments`, lists the comment under the thread by its `discussion_r` anchor or `databaseId`. A reply whose result is an error does not count. With no readable transcript, the resolve passes.
23
21
  - `blocking/verify_before_commit_gate.py` denies a `git commit` in a repository with a `.claude/skills/verify` or `.agents/skills/verify` directory until the `verify` skill loads after the last user prompt, through a Skill call whose result comes back without an error, or the `/verify` command in that prompt. It reads the committed paths from the staged diff, the tracked changes for `-a`, and the paths of each `git add` earlier in the same command, and passes a commit whose paths are all docs, images, test files, or `.json`, `.jsonl`, `.yaml`, `.yml`, or `.csv` files under a `docs` folder.
24
22
  - `blocking/build_eval_before_eval_write_gate.py` denies a write to an eval file until a Skill call named exactly `claude-api` with args `build-eval`, or the `/claude-api build-eval` command, appears in the transcript.
25
23
  - `blocking/merge_review_gate.py` denies an agent's merge until a review pass on the merged head reported zero findings, or ruled out every finding and linked the posted rulings. It reads the receipt `scripts/merge_review_receipt.py` writes, requires the merge, auto-merge or merge-queue entry to be pinned to that head, and skips repositories listed in `CLAUDE_MERGE_REVIEW_EXEMPT_REPOSITORIES`. A `gh pr merge` call whose every merge segment carries `--disable-auto` only turns auto-merge off, so it passes. A segment that also carries `--auto`, gives `--auto` or `--disable-auto` an `=` value, joins short flags such as `-sb`, or holds a bare `--` keeps every check. Its deny reason names the review command `CLAUDE_MERGE_REVIEW_COMMAND` sets. The reason tells the agent to run that command for the first three passes and `/code-review low --fix <number>` for each later pass; the gate itself counts no passes. It also denies a pull request open, through `gh pr create`, `pull_request.py create` or a `create_pull_request` tool, until a pass recorded as `merge_review_receipt.py <owner/name> open <head> 0` covers the head the pull request opens with. An open pass also counts when every finding is ruled out: `merge_review_receipt.py <owner/name> open <head> <count> --ruled-out <count> --rulings <path:line,...>`, with a different `path:line` for each finding, checked against the file at that head when the pass is recorded. A merge pinned to that same head passes on the open receipt only when the pass found zero findings.
@@ -29,13 +27,11 @@ This family stops a chat reply, edited message, or tool call when its payload br
29
27
 
30
28
  ## When it fires
31
29
 
32
- - `blocking/reply_length_gate.py` runs on `PreToolUse`, matcher `mcp__hearthbot__reply|mcp__hearthbot__post_message|mcp__hearthbot__update_message|mcp__hearthbot__ask_decision|AskUserQuestion|mcp__hearthbot__post_widget`, timeout `10` seconds in `hooks.json`.
33
30
  - `blocking/final_reply_gate.py` runs on `Stop`, timeout `10` seconds in `hooks.json`.
34
31
  - `blocking/open_tasks_stop_gate.py` runs on `Stop`, timeout `10` seconds in `hooks.json`. The installer also registers it on Codex `Stop` and as a native Cursor `stop` entry in `~/.cursor/hooks.json`, where a block also returns `followup_message`. A Cursor stop with status `aborted` or `error` passes. A Cursor stop whose `loop_count` is above 0 passes, because a copy Cursor imports from `~/.claude/settings.json` has no follow-up limit.
35
32
  - `session/tracking_nudge.py` runs on `UserPromptSubmit`, matcher empty, timeout `10` seconds in `hooks.json`.
36
33
  - `session/background_silence_prompt.py` runs on `UserPromptSubmit`, matcher empty, timeout `10` seconds in `hooks.json`. It reads the transcript only for a background event prompt.
37
34
  - The claim judge runs on `PreToolUse`, matcher `mcp__hearthbot__reply|mcp__hearthbot__post_message|mcp__hearthbot__update_message|mcp__hearthbot__ask_decision`, timeout `30` seconds in `hooks.json`.
38
- - `blocking/chat_reply_gate.py` runs on `UserPromptSubmit`, matcher empty, timeout `10` seconds, on `MessageDisplay`, timeout `100` seconds, and on `SessionEnd`, timeout `3` seconds, in `hooks.json`.
39
35
  - `blocking/edit_marker_gate.py` runs on `PreToolUse`, matcher `mcp__.*__update_message`, timeout `10` seconds in `hooks.json`.
40
36
  - `blocking/issue_close_handoff_gate.py` runs on `PreToolUse`, matcher `mcp__.*__(add_issue_comment|issue_write|update_issue_comment)`, timeout `10` seconds in `hooks.json`.
41
37
  - `blocking/session_title_format_gate.py` runs on `PreToolUse`, matcher `mcp__.*__set_session_title`, timeout `10` seconds in `hooks.json`.
@@ -43,7 +39,7 @@ This family stops a chat reply, edited message, or tool call when its payload br
43
39
  - `blocking/step_note_gate.py` runs on `PreToolUse`, matcher `*`, timeout `15` seconds in `hooks.json`.
44
40
  - `blocking/wakeup_cap_gate.py` runs on `PreToolUse`, matcher `ScheduleWakeup|CronCreate|mcp__.*__(send_later|create_trigger|update_trigger)`, timeout `10` seconds in `hooks.json`.
45
41
  - `blocking/verify_before_acting.py` runs on `PostToolUse`, matcher `Write|Edit|MultiEdit|NotebookEdit|Agent|Task|apply_patch|Bash|PowerShell|mcp__.*`, timeout `10` seconds in `hooks.json`.
46
- - `blocking/pr_lifecycle_skill_gate.py` runs on `PreToolUse`, matcher `Bash|PowerShell|mcp__.*__(create_pull_request|merge_pull_request|enable_pr_auto_merge|update_pull_request|actions_run_trigger)`, timeout `10` seconds in `hooks.json`.
42
+ - `blocking/pr_lifecycle_skill_gate.py` runs on `PreToolUse`, matcher `Bash|PowerShell|mcp__.*__(create_pull_request|merge_pull_request|enable_pr_auto_merge|update_pull_request|actions_run_trigger)`, timeout `30` seconds in `hooks.json`. The gate's git and GitHub reads end by 21 s after its read clock starts (a 20 s deadline and a 1 s grace for a stopped child).
47
43
  - `blocking/resolve_thread_reply_gate.py` runs on `PreToolUse`, matcher `Bash|PowerShell|mcp__.*__resolve_review_thread|mcp__.*__pull_request_review_write`, timeout `10` seconds in `hooks.json`.
48
44
  - `blocking/verify_before_commit_gate.py` runs on `PreToolUse`, matcher `Bash|PowerShell`, timeout `30` seconds in `hooks.json`.
49
45
  - `blocking/build_eval_before_eval_write_gate.py` runs on `PreToolUse`, matcher `Write|Edit|MultiEdit|NotebookEdit|apply_patch`, timeout `10` seconds in `hooks.json`.
@@ -58,14 +54,12 @@ Preconditions:
58
54
 
59
55
  - Run each command from the repository root with Python and pytest available. The tests create transcript and payload fixtures.
60
56
 
61
- - **Reply length.** Input is a reply with four sentences, a plain pull request number, an abbreviation, two sentences with no widget this turn, or widget code with an anchor link. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_reply_length_gate.py -q`. The adjacent test observes a denial and its count, link, or mode reason. Widget code with no flowchart passes with a flowchart reminder in `additionalContext`.
62
57
  - **Resolve reply.** Input is a transcript where a thread reply came back refused, or with no reply, or with one reply already spent on a resolve, or with a reply on another thread, then a resolve call, a `pull_request_review_write` `resolve_thread` call, a graphql `resolveReviewThread` command, or a `ccr/comments/<id>/resolve` call. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_resolve_thread_reply_gate.py -q`. The adjacent test observes a deny whose reason says to post the reply, confirm it posted, then resolve. A reply that posted before the resolve passes, and an unreadable transcript passes.
63
- - **Final reply.** Input is a closing reply that says "My guess is one to two hours." or cites a run no tool result shows. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_final_reply_gate.py -q`. The adjacent test observes a `block` decision that quotes the sentence or the citation; a reply that cites a run a tool result shows passes. A reply with a plain-text `D:\Reports\.claude\report.html` is blocked; the same path in backticks or a fenced block passes.
58
+ - **Final reply.** Input is a closing reply. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_final_reply_gate.py -q`. The adjacent test observes a `block` decision for a path in plain text. A reply with a plain-text `D:\Reports\.claude\report.html` is blocked; the same path in backticks or a fenced block passes.
64
59
  - **Open tasks.** Input is a transcript whose last prompt asks for work and whose turn ran a Bash call and no tracker call. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_open_tasks_stop_gate.py -q`. The adjacent test observes one `block` decision; the same turn with a TaskCreate, TaskUpdate, TodoWrite, or desktop plan call passes. A question, an acknowledgement, a `<task-notification>` envelope, a tool-free turn, and a held stop pass. The same file covers Codex and Cursor payloads.
65
60
  - **Ask nudge.** Input is a `UserPromptSubmit` payload with a work prompt, a question, and a `<task-notification>` envelope, after a transcript whose title shows the red flag. Run `python -m pytest packages/claude-dev-env/hooks/session/test_tracking_nudge.py -q`. The adjacent test observes a task list note and a title note for the work prompt, and empty stdout for the other two. A second ask in the same session gets no task list note until the transcript records a compaction.
66
61
  - **Background silence.** Input is a `UserPromptSubmit` payload whose prompt is a `<task-notification>` envelope, after a transcript whose user message reads "Silent on updates unless something merges or youre blocked". Run `python -m pytest packages/claude-dev-env/hooks/session/test_background_silence_prompt.py -q`. The adjacent test observes a note that quotes "unless something merges or youre blocked", and empty stdout for a user-typed prompt, after a lift, and with no silence message.
67
62
  - **Claim judge.** Input is a headless `claude -p` session with a stub MCP server named `hearthbot` that exposes `reply` and `ask_decision`, told to send "The code lets any of them rewrite it mid-check." The session settings add the `hooks.json` prompt hook. The stub logs zero bytes sent, and the tool error reads `PreToolUse:mcp__hearthbot__reply hook error: [<the prompt>]: Facts with no source: 1. ...`, numbering every failing claim. The same sentence with a `file:line` in backticks posts. A hook whose `model` Claude Code does not recognize lets every message through, so leave `model` unset. Run `node --test packages/claude-dev-env/bin/install.prompt-hook.test.mjs` for the installer side; it observes one managed prompt hook after two installs and none after uninstall.
68
- - **Chat reply.** Input is a `MessageDisplay` event whose message holds four sentences, the same message split over two batches, and a `UserPromptSubmit` event. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_chat_reply_gate.py -q`. The adjacent test observes the drafter's text in `displayContent`, an empty first batch, no output for three sentences, the original after two failed drafts, the shown draft in the next `additionalContext`, and the stored draft deleted at session end. A replay of two prompts and a compaction observes the reply rules on the first prompt, no output on the second, and the rules again after the compaction.
69
63
  - **Edit marker.** Input is an update message with strikethrough or an edit note. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_edit_marker_gate.py -q`. The adjacent test observes a denial; clean replacement text passes.
70
64
  - **Handoff close.** Input is an issue comment that says the issue is closed and that the found defect belongs to another issue. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_issue_close_handoff_gate.py -q`. The adjacent test observes a denial; a close with a plain cross-reference and a routing comment on an open issue both pass.
71
65
  - **Session title.** Input is a set session title call with no leading emoji or a name over 25 characters. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_session_title_format_gate.py -q`. The adjacent test observes a denial that names the broken rule; a well-formed title passes.
@@ -90,8 +84,7 @@ Preconditions:
90
84
  - `blocking/step_note_gate.py` is off by default and polls for the transcript record. Subagent calls and unreadable records pass.
91
85
  - `blocking/wakeup_cap_gate.py` lets an `update_trigger` cron change pass, because that input does not say whether the Routine wakes a session. Its step-down values come from fire-time probes: `send_later` rounds its fire time up to the next minute and polls once a minute, so a 1-minute request landed 123 and 158 seconds later. `ScheduleWakeup` rounds its fire time up to the next minute, so requests of 60 and 90 seconds landed 70 and 121 seconds later.
92
86
  - `blocking/verify_before_acting.py` runs after the tool. A block asks the agent to check the claim and undo a contradicted change. A spawn has already started when the hook runs, so a block would stop nothing. The advisory note asks the agent to check the claim before it acts on the spawned agent's result.
93
- - The reply gate counts each nonempty list line as a sentence. Link targets and code spans add no words. Its banned words come from `reply-banned-words.json` in the Claude home, or the file `CLAUDE_REPLY_BANNED_WORDS_PATH` names, with built-in defaults.
94
- - The final reply gate blocks the stop and returns its reason to the model, which rewrites the reply. Claude Code ends the turn anyway after eight blocks in a row. The cited number checks in both gates skip when the transcript cannot be read.
87
+ - The final reply gate blocks the stop and returns its reason to the model, which rewrites the reply. Claude Code ends the turn anyway after eight blocks in a row.
95
88
  - The edit marker gate scans replacement cards as well as the message text.
96
89
  - The handoff close gate reads the `body` and `comment` fields of issue tools only. A `gh issue close --comment` command in Bash and a pull request body that closes the issue with `Closes #N` do not reach it.
97
90
  - The eval write gate reads Write, Edit, MultiEdit, NotebookEdit and apply_patch calls. A Bash or PowerShell command that writes an eval file reaches it without the gate. An apply_patch that will not parse counts as an eval write when any of its words is an eval path. A missing or unreadable transcript denies the write.
package/hooks/hooks.json CHANGED
@@ -98,7 +98,7 @@
98
98
  {
99
99
  "type": "command",
100
100
  "command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/blocking/pr_lifecycle_skill_gate.py",
101
- "timeout": 10
101
+ "timeout": 30
102
102
  }
103
103
  ]
104
104
  },
@@ -187,16 +187,6 @@
187
187
  }
188
188
  ]
189
189
  },
190
- {
191
- "matcher": "mcp__hearthbot__reply|mcp__hearthbot__post_message|mcp__hearthbot__update_message|mcp__hearthbot__ask_decision|AskUserQuestion|mcp__hearthbot__post_widget",
192
- "hooks": [
193
- {
194
- "type": "command",
195
- "command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/blocking/reply_length_gate.py",
196
- "timeout": 10
197
- }
198
- ]
199
- },
200
190
  {
201
191
  "matcher": "mcp__hearthbot__reply|mcp__hearthbot__post_message|mcp__hearthbot__update_message|mcp__hearthbot__ask_decision",
202
192
  "hooks": [
@@ -328,16 +318,6 @@
328
318
  "timeout": 15
329
319
  }
330
320
  ]
331
- },
332
- {
333
- "matcher": "Bash|mcp__github__add_issue_comment|mcp__github__update_issue_comment|mcp__github__add_reply_to_pull_request_comment|mcp__github__add_comment_to_pending_review|mcp__github__pull_request_review_write",
334
- "hooks": [
335
- {
336
- "type": "command",
337
- "command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/blocking/reply_length_gate.py",
338
- "timeout": 10
339
- }
340
- ]
341
321
  }
342
322
  ],
343
323
  "UserPromptSubmit": [
@@ -354,11 +334,6 @@
354
334
  "command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/lifecycle/nested_project_hooks.py",
355
335
  "timeout": 120
356
336
  },
357
- {
358
- "type": "command",
359
- "command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/blocking/chat_reply_gate.py",
360
- "timeout": 10
361
- },
362
337
  {
363
338
  "type": "command",
364
339
  "command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/session/tracking_nudge.py",
@@ -506,11 +481,6 @@
506
481
  "type": "command",
507
482
  "command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/session/session_edit_tracker_cleanup.py",
508
483
  "timeout": 3
509
- },
510
- {
511
- "type": "command",
512
- "command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/blocking/chat_reply_gate.py",
513
- "timeout": 3
514
484
  }
515
485
  ]
516
486
  }
@@ -590,17 +560,6 @@
590
560
  }
591
561
  ]
592
562
  }
593
- ],
594
- "MessageDisplay": [
595
- {
596
- "hooks": [
597
- {
598
- "type": "command",
599
- "command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/blocking/chat_reply_gate.py",
600
- "timeout": 100
601
- }
602
- ]
603
- }
604
563
  ]
605
564
  }
606
565
  }
@@ -40,3 +40,5 @@ SILENCE_NOTE_WITHOUT_EXCEPTION = (
40
40
  " End this turn with no text at all unless that message names an exception that applies now."
41
41
  ' Tool calls are fine, and a status line such as "No change." counts as text.'
42
42
  )
43
+
44
+ ADDITIONAL_CONTEXT_KEY = "additionalContext"