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.
- package/bin/ever-registered-hooks.mjs +1 -0
- package/hooks/advisory/auto_mode_denial_quick_fix.py +275 -27
- package/hooks/advisory/auto_mode_rule_flow_eval/auto_mode_rule_flow_cases.json +3475 -0
- package/hooks/advisory/auto_mode_rule_flow_eval/auto_mode_rule_flow_runner.py +849 -0
- package/hooks/advisory/auto_mode_rule_flow_eval/stub_allow_hook.py +20 -0
- package/hooks/advisory/auto_mode_rule_flow_eval/stub_hold_hook.py +54 -0
- package/hooks/advisory/auto_mode_rule_flow_eval/test_auto_mode_rule_flow_runner.py +143 -0
- package/hooks/advisory/test_auto_mode_denial_quick_fix.py +533 -9
- package/hooks/auto_mode_question_transcript.py +215 -0
- package/hooks/auto_mode_refusal_ledger.py +481 -0
- package/hooks/auto_mode_refusal_ledger_files.py +336 -0
- package/hooks/auto_mode_rule_steps.py +177 -0
- package/hooks/blocking/auto_mode_refusal_stop_gate.py +384 -0
- package/hooks/blocking/gh_api_budget_gate.py +286 -0
- package/hooks/blocking/test_auto_mode_refusal_stop_gate.py +484 -0
- package/hooks/blocking/test_bash_dispatcher_interpreter_starts.py +8 -3
- package/hooks/blocking/test_bash_pre_tool_use_dispatcher.py +1 -0
- package/hooks/blocking/test_gh_api_budget_gate.py +602 -0
- package/hooks/features/README.md +1 -1
- package/hooks/features/bash-dispatchers.md +3 -0
- package/hooks/features/session-context.md +5 -2
- package/hooks/hooks.json +5 -0
- package/hooks/hooks_constants/auto_mode_denial_quick_fix_constants.py +51 -3
- package/hooks/hooks_constants/auto_mode_refusal_ledger_constants.py +85 -0
- package/hooks/hooks_constants/auto_mode_refusal_stop_gate_constants.py +80 -0
- package/hooks/hooks_constants/auto_mode_rule_flow_runner_constants.py +225 -0
- package/hooks/hooks_constants/auto_mode_rule_steps_constants.py +82 -0
- package/hooks/hooks_constants/bash_pre_tool_use_dispatcher_constants.py +4 -0
- package/hooks/hooks_constants/gh_api_budget.py +186 -0
- package/hooks/hooks_constants/gh_api_budget_gate_constants.py +215 -0
- package/hooks/hooks_constants/gh_argument_lists.py +169 -0
- package/hooks/hooks_constants/gh_shell_loop_scan.py +386 -0
- package/hooks/hooks_constants/test_bash_pre_tool_use_dispatcher_constants.py +5 -1
- package/hooks/hooks_constants/test_gh_api_budget.py +125 -0
- package/hooks/hooks_constants/test_gh_argument_lists.py +49 -0
- package/hooks/hooks_constants/test_gh_shell_loop_scan.py +50 -0
- package/hooks/test_auto_mode_question_transcript.py +113 -0
- package/hooks/test_auto_mode_refusal_ledger.py +398 -0
- package/hooks/test_auto_mode_refusal_ledger_files.py +155 -0
- package/hooks/test_auto_mode_rule_steps.py +210 -0
- package/package.json +1 -1
- package/scripts/policy_lint/adapter_configuration.py +5 -0
- package/scripts/policy_lint/config/constants.py +1 -0
- package/scripts/tests/test_adapter_configuration.py +8 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"""Behavior tests for telling the auto mode rule flow's own steps apart."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
from auto_mode_rule_steps import RuleFlowSetting, is_rule_flow_step
|
|
10
|
+
|
|
11
|
+
RULE_BRANCH = "claude/auto-mode-rule-own-push"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _repository(tmp_path: Path, branch_name: str = RULE_BRANCH) -> Path:
|
|
15
|
+
repository_root = tmp_path / "agent-channels"
|
|
16
|
+
(repository_root / ".git").mkdir(parents=True, exist_ok=True)
|
|
17
|
+
(repository_root / ".git" / "HEAD").write_text(
|
|
18
|
+
f"ref: refs/heads/{branch_name}\n", encoding="utf-8"
|
|
19
|
+
)
|
|
20
|
+
return repository_root
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _worktree(tmp_path: Path, branch_name: str) -> Path:
|
|
24
|
+
worktree_git_directory = tmp_path / "agent-channels" / ".git" / "worktrees" / "rule"
|
|
25
|
+
worktree_git_directory.mkdir(parents=True)
|
|
26
|
+
(worktree_git_directory / "HEAD").write_text(
|
|
27
|
+
f"ref: refs/heads/{branch_name}\n", encoding="utf-8"
|
|
28
|
+
)
|
|
29
|
+
(worktree_git_directory / "commondir").write_text("../..\n", encoding="utf-8")
|
|
30
|
+
worktree_directory = tmp_path / "scratch" / "agent-channels-rule"
|
|
31
|
+
worktree_directory.mkdir(parents=True)
|
|
32
|
+
(worktree_directory / ".git").write_text(
|
|
33
|
+
f"gitdir: {worktree_git_directory}\n", encoding="utf-8"
|
|
34
|
+
)
|
|
35
|
+
(worktree_git_directory / "gitdir").write_text(
|
|
36
|
+
f"{worktree_directory / '.git'}\n", encoding="utf-8"
|
|
37
|
+
)
|
|
38
|
+
return worktree_directory
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _is_step(
|
|
42
|
+
tmp_path: Path,
|
|
43
|
+
command: str,
|
|
44
|
+
working_folder: Path | None = None,
|
|
45
|
+
has_allowed_entry: bool = True,
|
|
46
|
+
head_branch: str = RULE_BRANCH,
|
|
47
|
+
) -> bool:
|
|
48
|
+
repository_root = _repository(tmp_path, head_branch)
|
|
49
|
+
setting = RuleFlowSetting(repository_root, has_allowed_entry)
|
|
50
|
+
folder = working_folder or repository_root
|
|
51
|
+
return is_rule_flow_step("Bash", {"command": command}, str(folder), setting)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@pytest.mark.parametrize(
|
|
55
|
+
"command",
|
|
56
|
+
[
|
|
57
|
+
"python3 setup/add_auto_mode_rule.py add --label 'Own push' --rule-file r.txt --ledger e.json",
|
|
58
|
+
"python3 setup/add_auto_mode_rule.py validate --base origin/main",
|
|
59
|
+
],
|
|
60
|
+
)
|
|
61
|
+
def test_should_count_the_rule_tool_run_from_agent_channels_without_an_allowed_entry(
|
|
62
|
+
tmp_path: Path, command: str
|
|
63
|
+
) -> None:
|
|
64
|
+
assert _is_step(tmp_path, command, has_allowed_entry=False)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@pytest.mark.parametrize(
|
|
68
|
+
"command",
|
|
69
|
+
[
|
|
70
|
+
f"git push -u origin {RULE_BRANCH}",
|
|
71
|
+
f"git push origin {RULE_BRANCH}",
|
|
72
|
+
'git commit -m "Add the Own push auto mode rule"',
|
|
73
|
+
],
|
|
74
|
+
)
|
|
75
|
+
def test_should_count_a_rule_branch_commit_or_push_with_an_allowed_entry(
|
|
76
|
+
tmp_path: Path, command: str
|
|
77
|
+
) -> None:
|
|
78
|
+
assert _is_step(tmp_path, command)
|
|
79
|
+
assert not _is_step(tmp_path, command, has_allowed_entry=False)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_should_count_the_table_shapes_in_a_rule_worktree_of_agent_channels(
|
|
83
|
+
tmp_path: Path,
|
|
84
|
+
) -> None:
|
|
85
|
+
worktree_directory = _worktree(tmp_path, RULE_BRANCH)
|
|
86
|
+
assert _is_step(tmp_path, "python3 setup/add_auto_mode_rule.py validate", worktree_directory)
|
|
87
|
+
assert _is_step(tmp_path, 'git commit -m "Add"', worktree_directory)
|
|
88
|
+
assert _is_step(tmp_path, f"git push -u origin {RULE_BRANCH}", worktree_directory)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@pytest.mark.parametrize(
|
|
92
|
+
"command",
|
|
93
|
+
[
|
|
94
|
+
"cd /tmp/agent-channels-rule && python3 setup/add_auto_mode_rule.py validate",
|
|
95
|
+
"cd ..",
|
|
96
|
+
"python3 setup/add_auto_mode_rule.py validate\npython3 setup/add_auto_mode_rule.py add",
|
|
97
|
+
"python3 setup/add_auto_mode_rule.py validate | tail -5",
|
|
98
|
+
"python3 setup/add_auto_mode_rule.py validate; rm -rf ~/build",
|
|
99
|
+
"python3 setup/add_auto_mode_rule.py add --label $LABEL",
|
|
100
|
+
"python3 setup/add_auto_mode_rule.py add --label `id`",
|
|
101
|
+
"python3 setup/add_auto_mode_rule.py add > ~/.bashrc",
|
|
102
|
+
"python3 setup/add_auto_mode_rule.py add --label 'a;b'",
|
|
103
|
+
"LABEL=x python3 setup/add_auto_mode_rule.py add",
|
|
104
|
+
"python setup/add_auto_mode_rule.py add",
|
|
105
|
+
"python3 ./setup/add_auto_mode_rule.py add",
|
|
106
|
+
"python3 /tmp/other/setup/add_auto_mode_rule.py add",
|
|
107
|
+
"python3 setup/add_auto_mode_rule.py remove",
|
|
108
|
+
"python3 setup/add_auto_mode_rule.py",
|
|
109
|
+
"python3 'setup/add_auto_mode_rule.py",
|
|
110
|
+
"cat setup/add_auto_mode_rule.py",
|
|
111
|
+
"git push --all origin",
|
|
112
|
+
"git push --mirror origin",
|
|
113
|
+
"git push --tags origin",
|
|
114
|
+
f"git push --delete origin {RULE_BRANCH}",
|
|
115
|
+
f"git push -f origin {RULE_BRANCH}",
|
|
116
|
+
f"git push https://github.com/other/repo.git {RULE_BRANCH}",
|
|
117
|
+
f"git -c core.sshCommand=/tmp/x push -u origin {RULE_BRANCH}",
|
|
118
|
+
f"git -C /tmp/agent-channels push -u origin {RULE_BRANCH}",
|
|
119
|
+
f"git push origin HEAD:refs/heads/{RULE_BRANCH}",
|
|
120
|
+
f"git push origin {RULE_BRANCH} main",
|
|
121
|
+
"git push -u origin",
|
|
122
|
+
"git push origin claude/project-thread-rule",
|
|
123
|
+
"git push origin claude/auto-mode-rule-Own_Push",
|
|
124
|
+
"git add setup/auto-mode-allow.d/own-push.txt",
|
|
125
|
+
"git commit -m Add -a",
|
|
126
|
+
"git commit -am Add",
|
|
127
|
+
"rm -rf ~/agent-channels-old/build",
|
|
128
|
+
"git commit -m {a,--amend}",
|
|
129
|
+
"git commit -m *",
|
|
130
|
+
"git commit -m [s]etup",
|
|
131
|
+
"git commit -m a?",
|
|
132
|
+
"python3 setup/add_auto_mode_rule.py add --label {a,b}",
|
|
133
|
+
"git commit\t-m Add",
|
|
134
|
+
],
|
|
135
|
+
)
|
|
136
|
+
def test_should_not_count_any_command_outside_the_table(tmp_path: Path, command: str) -> None:
|
|
137
|
+
assert not _is_step(tmp_path, command)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def test_should_not_count_a_copied_worktree_folder(tmp_path: Path) -> None:
|
|
141
|
+
worktree_directory = _worktree(tmp_path, RULE_BRANCH)
|
|
142
|
+
copied_directory = tmp_path / "elsewhere" / "agent-channels-rule"
|
|
143
|
+
copied_directory.mkdir(parents=True)
|
|
144
|
+
(copied_directory / ".git").write_text(
|
|
145
|
+
(worktree_directory / ".git").read_text(encoding="utf-8"), encoding="utf-8"
|
|
146
|
+
)
|
|
147
|
+
assert _is_step(tmp_path, f"git push origin {RULE_BRANCH}", worktree_directory)
|
|
148
|
+
assert not _is_step(tmp_path, f"git push origin {RULE_BRANCH}", copied_directory)
|
|
149
|
+
assert not _is_step(
|
|
150
|
+
tmp_path, "python3 setup/add_auto_mode_rule.py validate", copied_directory
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def test_should_not_count_a_folder_whose_git_file_links_to_a_worktree(tmp_path: Path) -> None:
|
|
155
|
+
worktree_directory = _worktree(tmp_path, RULE_BRANCH)
|
|
156
|
+
linking_directory = tmp_path / "elsewhere" / "agent-channels-rule"
|
|
157
|
+
linking_directory.mkdir(parents=True)
|
|
158
|
+
(linking_directory / ".git").symlink_to(worktree_directory / ".git")
|
|
159
|
+
assert not _is_step(tmp_path, f"git push origin {RULE_BRANCH}", linking_directory)
|
|
160
|
+
assert not _is_step(
|
|
161
|
+
tmp_path, "python3 setup/add_auto_mode_rule.py validate", linking_directory
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def test_should_not_count_a_commit_while_head_is_on_another_branch(tmp_path: Path) -> None:
|
|
166
|
+
assert not _is_step(tmp_path, 'git commit -m "Add"', head_branch="main")
|
|
167
|
+
worktree_directory = _worktree(tmp_path, "claude/project-thread-rule")
|
|
168
|
+
assert not _is_step(tmp_path, 'git commit -m "Add"', worktree_directory)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
@pytest.mark.parametrize("folder_name", ["agent-channels-old", "agent-channels/docs", ""])
|
|
172
|
+
def test_should_not_count_a_table_shape_from_another_folder(
|
|
173
|
+
tmp_path: Path, folder_name: str
|
|
174
|
+
) -> None:
|
|
175
|
+
_repository(tmp_path)
|
|
176
|
+
working_folder = tmp_path / folder_name
|
|
177
|
+
working_folder.mkdir(parents=True, exist_ok=True)
|
|
178
|
+
assert not _is_step(tmp_path, "python3 setup/add_auto_mode_rule.py validate", working_folder)
|
|
179
|
+
assert not _is_step(tmp_path, f"git push -u origin {RULE_BRANCH}", working_folder)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def test_should_count_agent_channels_reached_through_a_symbolic_link(tmp_path: Path) -> None:
|
|
183
|
+
repository_root = _repository(tmp_path)
|
|
184
|
+
linked_folder = tmp_path / "linked-channels"
|
|
185
|
+
linked_folder.symlink_to(repository_root)
|
|
186
|
+
assert _is_step(tmp_path, "python3 setup/add_auto_mode_rule.py validate", linked_folder)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
@pytest.mark.parametrize("working_folder", [None, "", "agent-channels"])
|
|
190
|
+
def test_should_not_count_a_step_with_no_absolute_working_folder(
|
|
191
|
+
tmp_path: Path, working_folder: str | None
|
|
192
|
+
) -> None:
|
|
193
|
+
setting = RuleFlowSetting(_repository(tmp_path), True)
|
|
194
|
+
tool_input = {"command": "python3 setup/add_auto_mode_rule.py validate"}
|
|
195
|
+
assert not is_rule_flow_step("Bash", tool_input, working_folder, setting)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def test_should_not_count_an_edit_of_the_rule_tool(tmp_path: Path) -> None:
|
|
199
|
+
repository_root = _repository(tmp_path)
|
|
200
|
+
setting = RuleFlowSetting(repository_root, True)
|
|
201
|
+
tool_input = {"file_path": str(repository_root / "setup" / "add_auto_mode_rule.py")}
|
|
202
|
+
assert not is_rule_flow_step("Edit", tool_input, str(repository_root), setting)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def test_should_not_count_a_worktree_whose_git_file_cannot_be_read(tmp_path: Path) -> None:
|
|
206
|
+
worktree_directory = _worktree(tmp_path, RULE_BRANCH)
|
|
207
|
+
(worktree_directory / ".git").write_bytes(b"\xff\xfe not text")
|
|
208
|
+
assert not _is_step(
|
|
209
|
+
tmp_path, "python3 setup/add_auto_mode_rule.py validate", worktree_directory
|
|
210
|
+
)
|
package/package.json
CHANGED
|
@@ -141,6 +141,7 @@ def _names_exempt_registration_path(registered_string: str) -> bool:
|
|
|
141
141
|
hooks/blocking/build_eval_before_eval_write_gate.py -> exempt
|
|
142
142
|
hooks/blocking/final_reply_gate.py -> exempt
|
|
143
143
|
hooks/blocking/open_tasks_stop_gate.py -> exempt
|
|
144
|
+
hooks/blocking/auto_mode_refusal_stop_gate.py -> exempt
|
|
144
145
|
hooks/blocking/resolve_thread_reply_gate.py -> exempt
|
|
145
146
|
hooks/blocking/turn_review_gate.py -> exempt
|
|
146
147
|
hooks/blocking/wakeup_cap_gate.py -> exempt
|
|
@@ -200,6 +201,10 @@ def _names_exempt_registration_path(registered_string: str) -> bool:
|
|
|
200
201
|
on an ask and made no task list call. It decides when a turn may end and
|
|
201
202
|
no code or safety policy.
|
|
202
203
|
|
|
204
|
+
The auto mode refusal Stop gate holds the end of a turn while a refused
|
|
205
|
+
step waits on the user's question or on its rule. It decides when a turn
|
|
206
|
+
may end and no code or safety policy.
|
|
207
|
+
|
|
203
208
|
The resolve reply gate denies a review thread resolve until a reply on the
|
|
204
209
|
thread has posted. It decides the order of two review calls and no code or
|
|
205
210
|
safety policy.
|
|
@@ -80,6 +80,7 @@ ALL_ACTION_BOUNDARY_EXEMPT_REGISTRATION_PATHS = (
|
|
|
80
80
|
"blocking/build_eval_before_eval_write_gate.py",
|
|
81
81
|
"blocking/final_reply_gate.py",
|
|
82
82
|
"blocking/open_tasks_stop_gate.py",
|
|
83
|
+
"blocking/auto_mode_refusal_stop_gate.py",
|
|
83
84
|
"blocking/resolve_thread_reply_gate.py",
|
|
84
85
|
"blocking/turn_review_gate.py",
|
|
85
86
|
"blocking/wakeup_cap_gate.py",
|
|
@@ -90,6 +90,14 @@ def test_new_open_tasks_stop_gate_registration_is_clean(tmp_path: Path) -> None:
|
|
|
90
90
|
assert adapters.hook_configuration_diagnostics(current_document, tmp_path) == ()
|
|
91
91
|
|
|
92
92
|
|
|
93
|
+
def test_new_auto_mode_refusal_stop_gate_registration_is_clean(tmp_path: Path) -> None:
|
|
94
|
+
current_document = _hook_document(
|
|
95
|
+
["hooks/blocking/auto_mode_refusal_stop_gate.py"],
|
|
96
|
+
'{"hooks": {}}',
|
|
97
|
+
)
|
|
98
|
+
assert adapters.hook_configuration_diagnostics(current_document, tmp_path) == ()
|
|
99
|
+
|
|
100
|
+
|
|
93
101
|
def test_new_step_note_gate_registration_is_clean(tmp_path: Path) -> None:
|
|
94
102
|
current_document = _hook_document(
|
|
95
103
|
["hooks/blocking/step_note_gate.py"],
|