claude-dev-env 8.116.5 → 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.
- package/bin/ever-registered-hooks.mjs +2 -0
- package/bin/install-constants.mjs +3 -1
- package/bin/install.cursor-rules.test.mjs +64 -2
- package/bin/install.mjs +15 -2
- package/bin/install.prune.test.mjs +92 -0
- package/bin/install.test.mjs +1 -0
- package/docs/model-choice/escalation.md +3 -3
- package/docs/model-choice/subagents-and-fan-out.md +2 -2
- package/docs/model-choice/which-model.md +1 -1
- package/docs/references/working-style.md +1 -0
- package/docs/rule-guides/question-presentation.md +6 -0
- package/docs/rule-guides/session-title.md +8 -9
- package/docs/rule-guides/subagent-model-effort.md +13 -13
- package/hooks/advisory/owned_pr_review_loop.py +2 -3
- package/hooks/blocking/bash_post_call_dispatcher.py +17 -9
- package/hooks/blocking/bash_pre_tool_use_dispatcher.py +12 -8
- package/hooks/blocking/final_reply_gate.py +5 -9
- package/hooks/blocking/open_tasks_stop_gate.py +9 -20
- package/hooks/blocking/open_tasks_transcript.py +8 -3
- package/hooks/blocking/pii_prevention_blocker_parts/repository_exemption.py +7 -2
- package/hooks/blocking/question_brief_gate.py +382 -0
- package/hooks/blocking/step_note_gate.py +5 -2
- package/hooks/blocking/task_subject_length_gate.py +111 -0
- package/hooks/blocking/test_bash_post_call_dispatcher.py +36 -1
- package/hooks/blocking/test_bash_pre_tool_use_dispatcher.py +57 -0
- package/hooks/blocking/test_final_reply_gate.py +26 -2
- package/hooks/blocking/test_open_tasks_stop_gate.py +21 -11
- package/hooks/blocking/test_question_brief_gate.py +916 -0
- package/hooks/blocking/test_step_note_gate.py +26 -0
- package/hooks/blocking/test_task_subject_length_gate.py +221 -0
- package/hooks/blocking/test_turn_review_findings.py +124 -1
- package/hooks/blocking/test_turn_review_gate.py +1312 -10
- package/hooks/blocking/test_turn_review_snapshot.py +8 -0
- package/hooks/blocking/tests/test_repository_exemption.py +11 -0
- package/hooks/blocking/turn_review_findings.py +173 -13
- package/hooks/blocking/turn_review_gate.py +878 -105
- package/hooks/blocking/turn_review_snapshot.py +5 -1
- package/hooks/features/bash-dispatchers.md +1 -3
- package/hooks/features/conduct-gates.md +19 -9
- package/hooks/features/lifecycle-cleanup.md +1 -1
- package/hooks/features/spawn-routing.md +1 -1
- package/hooks/hooks.json +24 -11
- package/hooks/hooks_constants/final_reply_gate_constants.py +0 -3
- package/hooks/hooks_constants/hook_time_budget.py +61 -0
- package/hooks/hooks_constants/hosted_hook_runner.py +51 -21
- package/hooks/hooks_constants/hosted_hook_runner_constants.py +3 -0
- package/hooks/hooks_constants/nested_project_hooks_constants.py +8 -0
- package/hooks/hooks_constants/once_per_session_constants.py +1 -0
- package/hooks/hooks_constants/open_tasks_stop_gate_constants.py +0 -4
- package/hooks/hooks_constants/owned_pr_review_loop_constants.py +0 -4
- package/hooks/hooks_constants/pre_tool_use_context_runner.py +23 -3
- package/hooks/hooks_constants/pre_tool_use_context_runner_constants.py +5 -0
- package/hooks/hooks_constants/pre_tool_use_stdin.py +1 -1
- package/hooks/hooks_constants/question_brief_gate_constants.py +66 -0
- package/hooks/hooks_constants/session_title_constants.py +6 -27
- package/hooks/hooks_constants/stop_hook_hold.py +54 -0
- package/hooks/hooks_constants/stop_hook_hold_constants.py +9 -0
- package/hooks/hooks_constants/subagent_effort_levels.json +6 -0
- package/hooks/hooks_constants/subagent_effort_route_constants.py +20 -19
- package/hooks/hooks_constants/task_subject_length_gate_constants.py +43 -0
- package/hooks/hooks_constants/test_hook_time_budget.py +104 -0
- package/hooks/hooks_constants/test_hosted_hook_runner.py +12 -0
- package/hooks/hooks_constants/test_pre_tool_use_context_runner.py +16 -0
- package/hooks/hooks_constants/test_pre_tool_use_stdin.py +6 -0
- package/hooks/hooks_constants/test_stop_hook_hold.py +40 -0
- package/hooks/hooks_constants/thread_spawn_pace_hook_constants.py +1 -2
- package/hooks/hooks_constants/turn_review_gate_constants.py +246 -12
- package/hooks/lifecycle/nested_project_hooks.py +34 -4
- package/hooks/lifecycle/test_nested_project_hooks.py +52 -0
- package/hooks/once_per_session.py +33 -4
- package/hooks/open_task_asks.py +1 -1
- package/hooks/owned_pr_session_record.py +1 -76
- package/hooks/routing/subagent_effort_route.py +107 -13
- package/hooks/routing/subagent_effort_route_hook.py +9 -8
- package/hooks/routing/test_subagent_effort_route.py +201 -14
- package/hooks/routing/test_subagent_effort_route_hook.py +56 -0
- package/hooks/routing/thread_spawn_pace_hook.py +3 -3
- package/hooks/session/background_silence_prompt.py +1 -1
- package/hooks/session/test_tracking_nudge.py +114 -2
- package/hooks/session/tracking_nudge.py +28 -18
- package/hooks/session_title_transcript.py +195 -0
- package/hooks/test_once_per_session.py +10 -0
- package/hooks/test_owned_pr_session_record.py +0 -26
- package/hooks/test_session_title_transcript.py +111 -0
- package/hooks/validation/post_tool_use_dispatcher.py +38 -21
- package/hooks/validation/test_post_tool_use_dispatcher.py +43 -0
- package/package.json +1 -1
- package/rules/question-presentation.md +4 -4
- package/rules/subagent-model-effort.md +1 -1
- package/scripts/claude_account_worker.py +4 -3
- package/scripts/policy_lint/adapter_configuration.py +12 -11
- package/scripts/policy_lint/config/constants.py +2 -2
- package/scripts/test_claude_account_worker.py +1 -0
- package/scripts/tests/test_adapter_configuration.py +10 -2
- package/hooks/blocking/owned_pr_merge_stop_gate.py +0 -185
- package/hooks/blocking/session_title_turn_gate.py +0 -417
- package/hooks/blocking/test_owned_pr_merge_stop_gate.py +0 -254
- package/hooks/blocking/test_session_title_turn_gate.py +0 -396
- 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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
207
|
-
assert
|
|
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
|
-
|
|
257
|
-
|
|
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
|
|
347
|
-
|
|
348
|
-
|
|
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"
|