claude-dev-env 8.119.2 → 8.121.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 (44) hide show
  1. package/bin/ever-registered-hooks.mjs +1 -0
  2. package/hooks/advisory/auto_mode_denial_quick_fix.py +275 -27
  3. package/hooks/advisory/auto_mode_rule_flow_eval/auto_mode_rule_flow_cases.json +3475 -0
  4. package/hooks/advisory/auto_mode_rule_flow_eval/auto_mode_rule_flow_runner.py +849 -0
  5. package/hooks/advisory/auto_mode_rule_flow_eval/stub_allow_hook.py +20 -0
  6. package/hooks/advisory/auto_mode_rule_flow_eval/stub_hold_hook.py +54 -0
  7. package/hooks/advisory/auto_mode_rule_flow_eval/test_auto_mode_rule_flow_runner.py +143 -0
  8. package/hooks/advisory/test_auto_mode_denial_quick_fix.py +533 -9
  9. package/hooks/auto_mode_question_transcript.py +215 -0
  10. package/hooks/auto_mode_refusal_ledger.py +481 -0
  11. package/hooks/auto_mode_refusal_ledger_files.py +336 -0
  12. package/hooks/auto_mode_rule_steps.py +177 -0
  13. package/hooks/blocking/auto_mode_refusal_stop_gate.py +384 -0
  14. package/hooks/blocking/gh_api_budget_gate.py +286 -0
  15. package/hooks/blocking/test_auto_mode_refusal_stop_gate.py +484 -0
  16. package/hooks/blocking/test_bash_dispatcher_interpreter_starts.py +8 -3
  17. package/hooks/blocking/test_bash_pre_tool_use_dispatcher.py +1 -0
  18. package/hooks/blocking/test_gh_api_budget_gate.py +602 -0
  19. package/hooks/features/README.md +1 -1
  20. package/hooks/features/bash-dispatchers.md +3 -0
  21. package/hooks/features/session-context.md +5 -2
  22. package/hooks/hooks.json +5 -0
  23. package/hooks/hooks_constants/auto_mode_denial_quick_fix_constants.py +51 -3
  24. package/hooks/hooks_constants/auto_mode_refusal_ledger_constants.py +85 -0
  25. package/hooks/hooks_constants/auto_mode_refusal_stop_gate_constants.py +80 -0
  26. package/hooks/hooks_constants/auto_mode_rule_flow_runner_constants.py +225 -0
  27. package/hooks/hooks_constants/auto_mode_rule_steps_constants.py +82 -0
  28. package/hooks/hooks_constants/bash_pre_tool_use_dispatcher_constants.py +4 -0
  29. package/hooks/hooks_constants/gh_api_budget.py +186 -0
  30. package/hooks/hooks_constants/gh_api_budget_gate_constants.py +215 -0
  31. package/hooks/hooks_constants/gh_argument_lists.py +169 -0
  32. package/hooks/hooks_constants/gh_shell_loop_scan.py +386 -0
  33. package/hooks/hooks_constants/test_bash_pre_tool_use_dispatcher_constants.py +5 -1
  34. package/hooks/hooks_constants/test_gh_api_budget.py +125 -0
  35. package/hooks/hooks_constants/test_gh_argument_lists.py +49 -0
  36. package/hooks/hooks_constants/test_gh_shell_loop_scan.py +50 -0
  37. package/hooks/test_auto_mode_question_transcript.py +113 -0
  38. package/hooks/test_auto_mode_refusal_ledger.py +398 -0
  39. package/hooks/test_auto_mode_refusal_ledger_files.py +155 -0
  40. package/hooks/test_auto_mode_rule_steps.py +210 -0
  41. package/package.json +1 -1
  42. package/scripts/policy_lint/adapter_configuration.py +5 -0
  43. package/scripts/policy_lint/config/constants.py +1 -0
  44. package/scripts/tests/test_adapter_configuration.py +8 -0
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env python3
2
+ """Calibration stub that never acts: no output, no ledger file, exit 0.
3
+
4
+ The case runner feeds it both PermissionDenied and Stop events. It must score
5
+ 0 on every ``should act`` case, which shows that no such case passes when a
6
+ hook does nothing.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import sys
12
+
13
+
14
+ def main() -> int:
15
+ sys.stdin.read()
16
+ return 0
17
+
18
+
19
+ if __name__ == "__main__":
20
+ raise SystemExit(main())
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env python3
2
+ """Calibration stub that always acts.
3
+
4
+ ::
5
+
6
+ PermissionDenied -> writes one pending ledger file per refusal, prints nothing
7
+ Stop -> holds the turn: block decision on stdout, exit 2
8
+
9
+ It must score 0 on every ``should stay quiet`` case, which shows that no such
10
+ case passes when a hook records and holds on every event. It logs each hold
11
+ with ``log_hook_block``, which writes under ``HOME`` and never to stdout.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ import os
18
+ import sys
19
+ import uuid
20
+ from pathlib import Path
21
+
22
+ _hooks_root_directory = str(Path(__file__).resolve().parent.parent.parent)
23
+ if _hooks_root_directory not in sys.path:
24
+ sys.path.insert(0, _hooks_root_directory)
25
+
26
+ from hooks_constants.auto_mode_rule_flow_runner_constants import (
27
+ ALL_LEDGER_RELATIVE_PARTS,
28
+ CONFIG_DIRECTORY_VARIABLE,
29
+ HOLD_EXIT_CODE,
30
+ STOP_EVENT_NAME,
31
+ STUB_HOLD_REASON,
32
+ )
33
+ from hooks_constants.hook_block_logger import log_hook_block
34
+
35
+
36
+ def main() -> int:
37
+ payload = json.load(sys.stdin)
38
+ if payload.get("hook_event_name") == STOP_EVENT_NAME:
39
+ log_hook_block(Path(__file__).name, STOP_EVENT_NAME, STUB_HOLD_REASON)
40
+ sys.stdout.write(json.dumps({"decision": "block", "reason": STUB_HOLD_REASON}))
41
+ return HOLD_EXIT_CODE
42
+ ledger_directory = Path(os.environ[CONFIG_DIRECTORY_VARIABLE]).joinpath(
43
+ *ALL_LEDGER_RELATIVE_PARTS, str(payload.get("session_id"))
44
+ )
45
+ ledger_directory.mkdir(parents=True, exist_ok=True)
46
+ entry = {"tool_name": payload.get("tool_name"), "answer": None}
47
+ (ledger_directory / f"{uuid.uuid4().hex[:12]}.json").write_text(
48
+ json.dumps(entry), encoding="utf-8"
49
+ )
50
+ return 0
51
+
52
+
53
+ if __name__ == "__main__":
54
+ raise SystemExit(main())
@@ -0,0 +1,143 @@
1
+ """Behavior tests for the auto mode rule flow case runner and its calibration."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import sys
7
+ from pathlib import Path
8
+
9
+ import pytest
10
+
11
+ eval_directory = Path(__file__).resolve().parent
12
+ if str(eval_directory) not in sys.path:
13
+ sys.path.insert(0, str(eval_directory))
14
+ import auto_mode_rule_flow_runner as runner
15
+
16
+ case_file_path = eval_directory / "auto_mode_rule_flow_cases.json"
17
+ allow_stub = eval_directory / "stub_allow_hook.py"
18
+ hold_stub = eval_directory / "stub_hold_hook.py"
19
+ today_refusal_hook = eval_directory.parent / "auto_mode_denial_quick_fix.py"
20
+
21
+
22
+ def _cases_by_id() -> dict[str, dict[str, object]]:
23
+ return {
24
+ str(each_case["id"]): each_case
25
+ for each_case in runner.load_case_file(case_file_path)["cases"]
26
+ }
27
+
28
+
29
+ def test_should_score_no_should_act_case_when_the_hooks_never_act() -> None:
30
+ all_outcomes = runner.run_all_cases(case_file_path, allow_stub, allow_stub, ())
31
+ summary = runner.score_summary(all_outcomes)
32
+ assert summary["should_act_total"] > 0
33
+ assert summary["should_act_passed"] == 0
34
+ assert summary["errors"] == 0
35
+
36
+
37
+ def test_should_score_no_should_stay_quiet_case_when_the_hooks_always_record_and_hold() -> None:
38
+ all_outcomes = runner.run_all_cases(case_file_path, hold_stub, hold_stub, ())
39
+ summary = runner.score_summary(all_outcomes)
40
+ assert summary["should_stay_quiet_total"] > 0
41
+ assert summary["should_stay_quiet_passed"] == 0
42
+ assert summary["errors"] == 0
43
+
44
+
45
+ def test_should_report_a_missing_stop_gate_as_an_error(tmp_path: Path) -> None:
46
+ outcome = runner.run_case(
47
+ _cases_by_id()["Q1"], today_refusal_hook, tmp_path / "missing_gate.py", {}
48
+ )
49
+ assert outcome.verdict == runner.ERROR_VERDICT
50
+
51
+
52
+ @pytest.mark.parametrize("case_id", ["R11", "R13", "R14"])
53
+ def test_should_keep_the_refusal_hook_output_equal_to_todays_output(case_id: str) -> None:
54
+ all_today_outputs = runner.load_case_file(case_file_path)["today_outputs"]
55
+ assert isinstance(all_today_outputs, dict)
56
+ outcome = runner.run_case(
57
+ _cases_by_id()[case_id], today_refusal_hook, allow_stub, all_today_outputs
58
+ )
59
+ assert outcome.verdict == runner.PASS_VERDICT, outcome.all_problems
60
+
61
+
62
+ def test_should_place_the_ledger_folder_under_the_config_directory(tmp_path: Path) -> None:
63
+ assert (
64
+ runner.ledger_directory_for(tmp_path, "s1")
65
+ == tmp_path / "state" / "auto-mode-refusals" / "s1"
66
+ )
67
+
68
+
69
+ def test_should_read_only_ledger_objects_that_carry_an_answer(tmp_path: Path) -> None:
70
+ ledger_directory = runner.ledger_directory_for(tmp_path, "s1")
71
+ ledger_directory.mkdir(parents=True)
72
+ (ledger_directory / "entry.json").write_text(json.dumps({"answer": "kept"}), encoding="utf-8")
73
+ (ledger_directory / "question.json").write_text(json.dumps({"question": "Q"}), encoding="utf-8")
74
+ assert runner.read_ledger_answers(tmp_path, "s1") == {ledger_directory / "entry.json": "kept"}
75
+
76
+
77
+ def test_should_write_an_answered_question_the_way_a_transcript_stores_it() -> None:
78
+ event = {
79
+ "transcript": "ask",
80
+ "questions": [{"question": "Q?", "answer": "Allow it"}],
81
+ "timestamp": None,
82
+ }
83
+ call_record, result_record = runner.transcript_records_for(event, "toolu_1", "s1")
84
+ assert call_record["message"]["content"][0]["name"] == "AskUserQuestion"
85
+ assert result_record["toolUseResult"]["answers"] == {"Q?": "Allow it"}
86
+ assert "timestamp" not in result_record
87
+
88
+
89
+ def test_should_count_passes_per_kind_and_errors_apart() -> None:
90
+ all_outcomes = [
91
+ runner.CaseOutcome("R1", runner.SHOULD_ACT_KIND, runner.PASS_VERDICT, ()),
92
+ runner.CaseOutcome("R8", runner.SHOULD_STAY_QUIET_KIND, runner.FAIL_VERDICT, ()),
93
+ runner.CaseOutcome("Q1", runner.SHOULD_ACT_KIND, runner.ERROR_VERDICT, ()),
94
+ ]
95
+ assert runner.score_summary(all_outcomes) == {
96
+ "should_act_passed": 1,
97
+ "should_act_total": 2,
98
+ "should_stay_quiet_passed": 0,
99
+ "should_stay_quiet_total": 1,
100
+ "errors": 1,
101
+ }
102
+
103
+
104
+ def test_should_report_no_calibration_problem_for_the_shipped_cases() -> None:
105
+ assert runner.calibration_problems(case_file_path) == []
106
+
107
+
108
+ def test_should_report_a_should_act_case_that_a_quiet_hook_passes(tmp_path: Path) -> None:
109
+ loose_case_file = tmp_path / "cases.json"
110
+ loose_case_file.write_text(
111
+ json.dumps(
112
+ {
113
+ "today_outputs": {},
114
+ "cases": [
115
+ {
116
+ "id": "L1",
117
+ "kind": runner.SHOULD_ACT_KIND,
118
+ "summary": "No expectation, so every hook passes it.",
119
+ "events": [{"refusal": {"tool_name": "Bash", "tool_input": {}}}],
120
+ }
121
+ ],
122
+ }
123
+ ),
124
+ encoding="utf-8",
125
+ )
126
+ all_problems = runner.calibration_problems(loose_case_file)
127
+ assert len(all_problems) == 1
128
+ assert all_problems[0].startswith("stub_allow_hook.py is not calibrated")
129
+
130
+
131
+ def test_should_print_each_case_then_the_score_and_problems_only_when_verbose() -> None:
132
+ all_outcomes = [
133
+ runner.CaseOutcome("R1", runner.SHOULD_ACT_KIND, runner.FAIL_VERDICT, ("event 1: x",)),
134
+ ]
135
+ summary = runner.score_summary(all_outcomes)
136
+ quiet_text = runner.report_text_for(all_outcomes, summary, False)
137
+ assert quiet_text.splitlines() == [
138
+ "R1 should act fail",
139
+ "should act passed 0 of 1; should stay quiet passed 0 of 0; errors 0",
140
+ "A missing hook, an unexpected exit code or output that is not a JSON object counts as an error.",
141
+ ]
142
+ verbose_lines = runner.report_text_for(all_outcomes, summary, True).splitlines()
143
+ assert verbose_lines[1] == " event 1: x"