claude-dev-env 8.120.0 → 8.122.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/docs/rule-guides/question-presentation.md +4 -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/sent_file_question_detector.py +340 -0
- package/hooks/blocking/sent_file_question_gate.py +307 -0
- package/hooks/blocking/sent_file_scan.py +209 -0
- package/hooks/blocking/test_auto_mode_refusal_stop_gate.py +484 -0
- package/hooks/blocking/test_sent_file_question_detector.py +68 -0
- package/hooks/blocking/test_sent_file_question_gate.py +688 -0
- package/hooks/blocking/test_sent_file_scan.py +71 -0
- package/hooks/blocking/test_user_step_wording.py +46 -0
- package/hooks/blocking/user_step_wording.py +113 -15
- package/hooks/features/README.md +1 -1
- package/hooks/features/conduct-gates.md +3 -0
- package/hooks/features/session-context.md +5 -2
- package/hooks/hooks.json +15 -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/sent_file_question_gate_constants.py +261 -0
- package/hooks/hooks_constants/user_step_wording_constants.py +4 -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 +10 -0
- package/scripts/policy_lint/config/constants.py +2 -0
- package/scripts/tests/test_adapter_configuration.py +16 -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
|
@@ -137,10 +137,12 @@ def _names_exempt_registration_path(registered_string: str) -> bool:
|
|
|
137
137
|
hooks/blocking/task_subject_outcome_gate.py -> exempt
|
|
138
138
|
hooks/blocking/artifact_dark_mode_gate.py -> exempt
|
|
139
139
|
hooks/blocking/send_user_file_worktree_root_gate.py -> exempt
|
|
140
|
+
hooks/blocking/sent_file_question_gate.py -> exempt
|
|
140
141
|
hooks/blocking/question_brief_gate.py -> exempt
|
|
141
142
|
hooks/blocking/build_eval_before_eval_write_gate.py -> exempt
|
|
142
143
|
hooks/blocking/final_reply_gate.py -> exempt
|
|
143
144
|
hooks/blocking/open_tasks_stop_gate.py -> exempt
|
|
145
|
+
hooks/blocking/auto_mode_refusal_stop_gate.py -> exempt
|
|
144
146
|
hooks/blocking/resolve_thread_reply_gate.py -> exempt
|
|
145
147
|
hooks/blocking/turn_review_gate.py -> exempt
|
|
146
148
|
hooks/blocking/wakeup_cap_gate.py -> exempt
|
|
@@ -188,6 +190,10 @@ def _names_exempt_registration_path(registered_string: str) -> bool:
|
|
|
188
190
|
working directory, which the desktop file pane cannot open. It decides
|
|
189
191
|
where a sent file sits and no code or safety policy.
|
|
190
192
|
|
|
193
|
+
The sent file question gate denies a sent file or page that asks the
|
|
194
|
+
user a question, so the question goes through the question tool. It
|
|
195
|
+
decides where a question is asked and no code or safety policy.
|
|
196
|
+
|
|
191
197
|
The question brief gate denies a question call when the chat text before
|
|
192
198
|
it in the same turn is too long to read at a glance. It decides the shape
|
|
193
199
|
of a brief and no code or safety policy.
|
|
@@ -200,6 +206,10 @@ def _names_exempt_registration_path(registered_string: str) -> bool:
|
|
|
200
206
|
on an ask and made no task list call. It decides when a turn may end and
|
|
201
207
|
no code or safety policy.
|
|
202
208
|
|
|
209
|
+
The auto mode refusal Stop gate holds the end of a turn while a refused
|
|
210
|
+
step waits on the user's question or on its rule. It decides when a turn
|
|
211
|
+
may end and no code or safety policy.
|
|
212
|
+
|
|
203
213
|
The resolve reply gate denies a review thread resolve until a reply on the
|
|
204
214
|
thread has posted. It decides the order of two review calls and no code or
|
|
205
215
|
safety policy.
|
|
@@ -75,11 +75,13 @@ ALL_ACTION_BOUNDARY_EXEMPT_REGISTRATION_PATHS = (
|
|
|
75
75
|
"blocking/image_read_size_gate.py",
|
|
76
76
|
"blocking/artifact_dark_mode_gate.py",
|
|
77
77
|
"blocking/send_user_file_worktree_root_gate.py",
|
|
78
|
+
"blocking/sent_file_question_gate.py",
|
|
78
79
|
"blocking/question_brief_gate.py",
|
|
79
80
|
"blocking/haiku_spawn_slim_gate.py",
|
|
80
81
|
"blocking/build_eval_before_eval_write_gate.py",
|
|
81
82
|
"blocking/final_reply_gate.py",
|
|
82
83
|
"blocking/open_tasks_stop_gate.py",
|
|
84
|
+
"blocking/auto_mode_refusal_stop_gate.py",
|
|
83
85
|
"blocking/resolve_thread_reply_gate.py",
|
|
84
86
|
"blocking/turn_review_gate.py",
|
|
85
87
|
"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"],
|
|
@@ -162,6 +170,14 @@ def test_new_send_user_file_gate_registration_is_clean(tmp_path: Path) -> None:
|
|
|
162
170
|
assert adapters.hook_configuration_diagnostics(current_document, tmp_path) == ()
|
|
163
171
|
|
|
164
172
|
|
|
173
|
+
def test_new_sent_file_question_gate_registration_is_clean(tmp_path: Path) -> None:
|
|
174
|
+
current_document = _hook_document(
|
|
175
|
+
["hooks/blocking/sent_file_question_gate.py"],
|
|
176
|
+
'{"hooks": {}}',
|
|
177
|
+
)
|
|
178
|
+
assert adapters.hook_configuration_diagnostics(current_document, tmp_path) == ()
|
|
179
|
+
|
|
180
|
+
|
|
165
181
|
def test_new_question_brief_gate_registration_is_clean(tmp_path: Path) -> None:
|
|
166
182
|
current_document = _hook_document(
|
|
167
183
|
["hooks/blocking/question_brief_gate.py"],
|