claude-dev-env 8.116.4 → 8.117.0

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 (101) hide show
  1. package/bin/ever-registered-hooks.mjs +2 -0
  2. package/bin/install-constants.mjs +3 -1
  3. package/bin/install.cursor-rules.test.mjs +64 -2
  4. package/bin/install.mjs +15 -2
  5. package/bin/install.prune.test.mjs +92 -0
  6. package/bin/install.test.mjs +1 -0
  7. package/docs/model-choice/escalation.md +3 -3
  8. package/docs/model-choice/subagents-and-fan-out.md +2 -2
  9. package/docs/model-choice/which-model.md +1 -1
  10. package/docs/references/working-style.md +1 -0
  11. package/docs/rule-guides/question-presentation.md +6 -0
  12. package/docs/rule-guides/session-title.md +8 -9
  13. package/docs/rule-guides/subagent-model-effort.md +13 -13
  14. package/hooks/advisory/owned_pr_review_loop.py +2 -3
  15. package/hooks/blocking/bash_post_call_dispatcher.py +17 -9
  16. package/hooks/blocking/bash_pre_tool_use_dispatcher.py +12 -8
  17. package/hooks/blocking/final_reply_gate.py +5 -9
  18. package/hooks/blocking/open_tasks_stop_gate.py +9 -20
  19. package/hooks/blocking/open_tasks_transcript.py +8 -3
  20. package/hooks/blocking/pii_prevention_blocker_parts/repository_exemption.py +7 -2
  21. package/hooks/blocking/question_brief_gate.py +382 -0
  22. package/hooks/blocking/step_note_gate.py +5 -2
  23. package/hooks/blocking/task_subject_length_gate.py +111 -0
  24. package/hooks/blocking/test_bash_post_call_dispatcher.py +36 -1
  25. package/hooks/blocking/test_bash_pre_tool_use_dispatcher.py +57 -0
  26. package/hooks/blocking/test_final_reply_gate.py +26 -2
  27. package/hooks/blocking/test_open_tasks_stop_gate.py +21 -11
  28. package/hooks/blocking/test_question_brief_gate.py +916 -0
  29. package/hooks/blocking/test_step_note_gate.py +26 -0
  30. package/hooks/blocking/test_task_subject_length_gate.py +221 -0
  31. package/hooks/blocking/test_turn_review_findings.py +124 -1
  32. package/hooks/blocking/test_turn_review_gate.py +1312 -10
  33. package/hooks/blocking/test_turn_review_snapshot.py +8 -0
  34. package/hooks/blocking/tests/test_repository_exemption.py +11 -0
  35. package/hooks/blocking/turn_review_findings.py +173 -13
  36. package/hooks/blocking/turn_review_gate.py +878 -105
  37. package/hooks/blocking/turn_review_snapshot.py +5 -1
  38. package/hooks/features/bash-dispatchers.md +1 -3
  39. package/hooks/features/conduct-gates.md +19 -9
  40. package/hooks/features/lifecycle-cleanup.md +1 -1
  41. package/hooks/features/spawn-routing.md +1 -1
  42. package/hooks/hooks.json +24 -11
  43. package/hooks/hooks_constants/final_reply_gate_constants.py +0 -3
  44. package/hooks/hooks_constants/hook_time_budget.py +61 -0
  45. package/hooks/hooks_constants/hosted_hook_runner.py +51 -21
  46. package/hooks/hooks_constants/hosted_hook_runner_constants.py +3 -0
  47. package/hooks/hooks_constants/nested_project_hooks_constants.py +8 -0
  48. package/hooks/hooks_constants/once_per_session_constants.py +1 -0
  49. package/hooks/hooks_constants/open_tasks_stop_gate_constants.py +0 -4
  50. package/hooks/hooks_constants/owned_pr_review_loop_constants.py +0 -4
  51. package/hooks/hooks_constants/pre_tool_use_context_runner.py +23 -3
  52. package/hooks/hooks_constants/pre_tool_use_context_runner_constants.py +5 -0
  53. package/hooks/hooks_constants/pre_tool_use_stdin.py +1 -1
  54. package/hooks/hooks_constants/question_brief_gate_constants.py +66 -0
  55. package/hooks/hooks_constants/session_title_constants.py +6 -27
  56. package/hooks/hooks_constants/stop_hook_hold.py +54 -0
  57. package/hooks/hooks_constants/stop_hook_hold_constants.py +9 -0
  58. package/hooks/hooks_constants/subagent_effort_levels.json +6 -0
  59. package/hooks/hooks_constants/subagent_effort_route_constants.py +20 -19
  60. package/hooks/hooks_constants/task_subject_length_gate_constants.py +43 -0
  61. package/hooks/hooks_constants/test_hook_time_budget.py +104 -0
  62. package/hooks/hooks_constants/test_hosted_hook_runner.py +12 -0
  63. package/hooks/hooks_constants/test_pre_tool_use_context_runner.py +16 -0
  64. package/hooks/hooks_constants/test_pre_tool_use_stdin.py +6 -0
  65. package/hooks/hooks_constants/test_stop_hook_hold.py +40 -0
  66. package/hooks/hooks_constants/thread_spawn_pace_hook_constants.py +1 -2
  67. package/hooks/hooks_constants/turn_review_gate_constants.py +246 -12
  68. package/hooks/lifecycle/nested_project_hooks.py +34 -4
  69. package/hooks/lifecycle/test_nested_project_hooks.py +52 -0
  70. package/hooks/once_per_session.py +33 -4
  71. package/hooks/open_task_asks.py +1 -1
  72. package/hooks/owned_pr_session_record.py +1 -76
  73. package/hooks/routing/subagent_effort_route.py +107 -13
  74. package/hooks/routing/subagent_effort_route_hook.py +9 -8
  75. package/hooks/routing/test_subagent_effort_route.py +201 -14
  76. package/hooks/routing/test_subagent_effort_route_hook.py +56 -0
  77. package/hooks/routing/thread_spawn_pace_hook.py +3 -3
  78. package/hooks/session/background_silence_prompt.py +1 -1
  79. package/hooks/session/test_tracking_nudge.py +114 -2
  80. package/hooks/session/tracking_nudge.py +28 -18
  81. package/hooks/session_title_transcript.py +195 -0
  82. package/hooks/test_once_per_session.py +10 -0
  83. package/hooks/test_owned_pr_session_record.py +0 -26
  84. package/hooks/test_session_title_transcript.py +111 -0
  85. package/hooks/validation/post_tool_use_dispatcher.py +38 -21
  86. package/hooks/validation/test_post_tool_use_dispatcher.py +43 -0
  87. package/hooks/validators/ruff_integration.py +46 -4
  88. package/hooks/validators/test_ruff_integration.py +67 -5
  89. package/package.json +1 -1
  90. package/rules/question-presentation.md +4 -4
  91. package/rules/subagent-model-effort.md +1 -1
  92. package/scripts/claude_account_worker.py +4 -3
  93. package/scripts/policy_lint/adapter_configuration.py +12 -11
  94. package/scripts/policy_lint/config/constants.py +2 -2
  95. package/scripts/test_claude_account_worker.py +1 -0
  96. package/scripts/tests/test_adapter_configuration.py +10 -2
  97. package/hooks/blocking/owned_pr_merge_stop_gate.py +0 -185
  98. package/hooks/blocking/session_title_turn_gate.py +0 -417
  99. package/hooks/blocking/test_owned_pr_merge_stop_gate.py +0 -254
  100. package/hooks/blocking/test_session_title_turn_gate.py +0 -396
  101. package/hooks/hooks_constants/owned_pr_merge_stop_gate_constants.py +0 -40
@@ -20,7 +20,10 @@ from bash_post_call_dispatcher import (
20
20
  main,
21
21
  select_applicable_entries,
22
22
  )
23
- from hooks_constants.bash_pre_tool_use_dispatcher_constants import BASH_TOOL_NAME
23
+ from hooks_constants.bash_pre_tool_use_dispatcher_constants import (
24
+ BASH_TOOL_NAME,
25
+ BashHostedHookEntry,
26
+ )
24
27
  from hooks_constants.hosted_hook_runner import HostedHookRun
25
28
 
26
29
  _ALL_EXPECTED_ROSTER_PATHS = [
@@ -148,3 +151,35 @@ def test_end_to_end_hosted_hooks_leave_an_ordinary_call_silent(
148
151
  dispatch(payload, BASH_TOOL_NAME)
149
152
 
150
153
  assert capsys.readouterr().out == ""
154
+
155
+
156
+ _EXIT_PROBE_SOURCE = "import sys\nsys.stderr.write('probe child says stop\\n')\nsys.exit({exit_code})\n"
157
+
158
+
159
+ def _write_exit_probe(tmp_path: Path, exit_code: int) -> str:
160
+ probe_path = tmp_path / f"exit_{exit_code}_probe.py"
161
+ probe_path.write_text(_EXIT_PROBE_SOURCE.format(exit_code=exit_code), encoding="utf-8")
162
+ return str(probe_path)
163
+
164
+
165
+ @pytest.mark.parametrize(("child_exit_code", "expected_exit_code"), [(2, 2), (1, 0), (0, 0)])
166
+ def test_should_pass_a_hosted_hook_exit_two_to_the_host_with_its_stderr(
167
+ tmp_path: Path,
168
+ monkeypatch: pytest.MonkeyPatch,
169
+ capsys: pytest.CaptureFixture[str],
170
+ child_exit_code: int,
171
+ expected_exit_code: int,
172
+ ) -> None:
173
+ dispatcher_module = sys.modules[main.__module__]
174
+ probe_entry = BashHostedHookEntry(
175
+ script_relative_path=_write_exit_probe(tmp_path, child_exit_code),
176
+ applicable_tool_names=frozenset({BASH_TOOL_NAME}),
177
+ )
178
+ monkeypatch.setattr(dispatcher_module, "ALL_BASH_POST_TOOL_USE_HOSTED_HOOK_ENTRIES", (probe_entry,))
179
+ monkeypatch.setattr(sys, "stdin", io.StringIO(json.dumps({"tool_name": BASH_TOOL_NAME})))
180
+
181
+ with pytest.raises(SystemExit) as raised_exit:
182
+ main()
183
+
184
+ assert (raised_exit.value.code or 0) == expected_exit_code
185
+ assert "probe child says stop" in capsys.readouterr().err
@@ -9,6 +9,7 @@ updatedInput passthrough, and the fail-open posture on a crashed hook.
9
9
 
10
10
  from __future__ import annotations
11
11
 
12
+ import io
12
13
  import json
13
14
  import os
14
15
  import subprocess
@@ -302,3 +303,59 @@ def test_should_deny_a_headless_claude_command_while_no_mod_is_on(
302
303
  monkeypatch.setenv("CLAUDE_PROJECT_DIR", str(tmp_path))
303
304
  completed = _run_process(_DISPATCHER_SCRIPT, _bash_payload("claude -p 'say hello'"))
304
305
  assert _decision_from_stdout(completed.stdout)[0] == "deny"
306
+
307
+
308
+ _EXIT_PROBE_SOURCE = "import sys\nsys.stderr.write('probe child says stop\\n')\nsys.exit({exit_code})\n"
309
+
310
+
311
+ def _write_exit_probe(tmp_path: Path, exit_code: int) -> str:
312
+ probe_path = tmp_path / f"exit_{exit_code}_probe.py"
313
+ probe_path.write_text(_EXIT_PROBE_SOURCE.format(exit_code=exit_code), encoding="utf-8")
314
+ return str(probe_path)
315
+
316
+
317
+ @pytest.mark.parametrize(("child_exit_code", "expected_exit_code"), [(2, 2), (1, 0), (0, 0)])
318
+ def test_should_pass_a_hosted_hook_exit_two_to_the_host_with_its_stderr(
319
+ tmp_path: Path,
320
+ monkeypatch: pytest.MonkeyPatch,
321
+ capsys: pytest.CaptureFixture[str],
322
+ child_exit_code: int,
323
+ expected_exit_code: int,
324
+ ) -> None:
325
+ dispatcher_module = sys.modules[dispatch.__module__]
326
+ probe_entry = dispatcher_module.BashHostedHookEntry(
327
+ script_relative_path=_write_exit_probe(tmp_path, child_exit_code),
328
+ applicable_tool_names=frozenset({BASH_TOOL_NAME}),
329
+ )
330
+ monkeypatch.setattr(dispatcher_module, "ALL_BASH_HOSTED_HOOK_ENTRIES", (probe_entry,))
331
+ monkeypatch.setattr(sys, "stdin", io.StringIO(_bash_payload("echo one")))
332
+
333
+ with pytest.raises(SystemExit) as raised_exit:
334
+ dispatcher_module.main()
335
+
336
+ assert (raised_exit.value.code or 0) == expected_exit_code
337
+ assert "probe child says stop" in capsys.readouterr().err
338
+
339
+
340
+ def test_should_stop_the_chain_at_the_first_hosted_hook_that_exits_two(
341
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
342
+ ) -> None:
343
+ dispatcher_module = sys.modules[dispatch.__module__]
344
+ later_marker = tmp_path / "later_hook_ran.txt"
345
+ later_probe = tmp_path / "later_probe.py"
346
+ later_probe.write_text(
347
+ f"from pathlib import Path\nPath({str(later_marker)!r}).write_text('ran')\n",
348
+ encoding="utf-8",
349
+ )
350
+ all_entries = tuple(
351
+ dispatcher_module.BashHostedHookEntry(
352
+ script_relative_path=each_path, applicable_tool_names=frozenset({BASH_TOOL_NAME})
353
+ )
354
+ for each_path in (_write_exit_probe(tmp_path, 2), str(later_probe))
355
+ )
356
+ monkeypatch.setattr(dispatcher_module, "ALL_BASH_HOSTED_HOOK_ENTRIES", all_entries)
357
+
358
+ exit_code = dispatch(_bash_payload("echo one"), BASH_TOOL_NAME)
359
+
360
+ assert exit_code == 2
361
+ assert not later_marker.exists()
@@ -108,8 +108,9 @@ def test_should_block_a_windows_path_markdown_mangles(
108
108
  reply_text: str,
109
109
  quoted_text: str,
110
110
  ) -> None:
111
- _, stdout_text = run_gate(monkeypatch, capsys, reply_text)
111
+ exit_code, stdout_text = run_gate(monkeypatch, capsys, reply_text)
112
112
  decision = json.loads(stdout_text)
113
+ assert exit_code == 2
113
114
  assert decision["decision"] == "block"
114
115
  assert quoted_text in decision["reason"]
115
116
 
@@ -254,8 +255,9 @@ def test_should_block_a_closing_question_no_question_tool_sent(
254
255
  all_turn_records: list[dict[str, object]],
255
256
  ) -> None:
256
257
  transcript_path = write_records(tmp_path / "s.jsonl", all_turn_records)
257
- _, stdout_text = run_gate(monkeypatch, capsys, reply_text, transcript_path)
258
+ exit_code, stdout_text = run_gate(monkeypatch, capsys, reply_text, transcript_path)
258
259
  decision = json.loads(stdout_text)
260
+ assert exit_code == 2
259
261
  assert decision["decision"] == "block"
260
262
  assert "AskUserQuestion" in decision["reason"]
261
263
  assert "Rewrite the reply without it." not in decision["reason"]
@@ -343,3 +345,25 @@ def test_should_pass_a_closing_question_when_the_transcript_cannot_be_read(
343
345
  ) -> None:
344
346
  _, stdout_text = run_gate(monkeypatch, capsys, BARE_QUESTION_REPLY, tmp_path / "missing.jsonl")
345
347
  assert stdout_text == ""
348
+
349
+
350
+ def test_should_block_a_closing_question_when_the_transcript_holds_an_undecodable_byte(
351
+ monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
352
+ ) -> None:
353
+ transcript_path = tmp_path / "s.jsonl"
354
+ transcript_path.write_bytes(b"\xff\n")
355
+ exit_code, stdout_text = run_gate(monkeypatch, capsys, BARE_QUESTION_REPLY, transcript_path)
356
+ assert exit_code == 2
357
+ assert "AskUserQuestion" in json.loads(stdout_text)["reason"]
358
+
359
+
360
+ def test_should_write_the_block_reason_to_stderr_as_well(
361
+ monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
362
+ ) -> None:
363
+ hook_input = {"hook_event_name": "Stop", "last_assistant_message": INSIGHTS_REPLY}
364
+ monkeypatch.setattr(
365
+ "sys.stdin", io.TextIOWrapper(io.BytesIO(json.dumps(hook_input).encode("utf-8")))
366
+ )
367
+ assert final_reply_gate.main() == 2
368
+ captured = capsys.readouterr()
369
+ assert captured.err == json.loads(captured.out)["reason"]
@@ -62,9 +62,12 @@ def run_gate(
62
62
  if transcript_path is not None:
63
63
  hook_input["transcript_path"] = str(transcript_path)
64
64
  monkeypatch.setattr("sys.stdin", io.TextIOWrapper(io.BytesIO(json.dumps(hook_input).encode("utf-8"))))
65
- assert open_tasks_stop_gate.main() == 0
66
- printed_output = capsys.readouterr().out
67
- return json.loads(printed_output) if printed_output else {}
65
+ exit_code = open_tasks_stop_gate.main()
66
+ captured = capsys.readouterr()
67
+ block_output = json.loads(captured.out) if captured.out else {}
68
+ assert exit_code == (2 if block_output else 0)
69
+ assert captured.err == block_output.get("reason", "")
70
+ return block_output
68
71
 
69
72
 
70
73
  def test_should_block_a_work_turn_that_left_the_task_list_unchanged(
@@ -203,8 +206,10 @@ def test_should_block_through_a_subprocess_with_the_documented_contract(tmp_path
203
206
  env={"HOME": str(tmp_path), "USERPROFILE": str(tmp_path), "PATH": ""},
204
207
  check=False,
205
208
  )
206
- assert completed_process.returncode == 0
207
- assert json.loads(completed_process.stdout)["decision"] == "block"
209
+ block_output = json.loads(completed_process.stdout)
210
+ assert completed_process.returncode == 2
211
+ assert block_output["decision"] == "block"
212
+ assert completed_process.stderr == block_output["reason"]
208
213
 
209
214
 
210
215
  def codex_record(payload: dict[str, object]) -> dict[str, object]:
@@ -252,9 +257,10 @@ def run_cursor_gate(
252
257
  "transcript_path": str(transcript_path),
253
258
  }
254
259
  monkeypatch.setattr("sys.stdin", io.TextIOWrapper(io.BytesIO(json.dumps(hook_input).encode("utf-8"))))
255
- open_tasks_stop_gate.main()
256
- printed_output = capsys.readouterr().out
257
- return json.loads(printed_output) if printed_output else {}
260
+ assert open_tasks_stop_gate.main() == 0
261
+ captured = capsys.readouterr()
262
+ assert captured.err == ""
263
+ return json.loads(captured.out) if captured.out else {}
258
264
 
259
265
 
260
266
  def write_cursor_work_turn(tmp_path: Path, all_tool_blocks: list[dict[str, object]]) -> Path:
@@ -343,6 +349,10 @@ def test_should_tell_a_held_stop_from_a_first_stop(hook_input: dict[str, object]
343
349
  assert open_tasks_stop_gate.is_held_stop(hook_input) is is_expected_held
344
350
 
345
351
 
346
- def test_should_add_a_followup_message_only_for_a_cursor_payload() -> None:
347
- assert open_tasks_stop_gate.block_output_for({}, "why") == {"decision": "block", "reason": "why"}
348
- assert open_tasks_stop_gate.block_output_for({"conversation_id": "c-1"}, "why")["followup_message"] == "why"
352
+ def test_should_block_a_work_turn_whose_transcript_holds_an_undecodable_byte(
353
+ monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
354
+ ) -> None:
355
+ transcript_path = write_records(tmp_path / "s.jsonl", [user_prompt_record(WORK_PROMPT), tool_call_record("Bash")])
356
+ with transcript_path.open("ab") as transcript_file:
357
+ transcript_file.write(b"\n\xff\n")
358
+ assert run_gate(monkeypatch, capsys, transcript_path)["decision"] == "block"