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
|
@@ -1,396 +0,0 @@
|
|
|
1
|
-
import io
|
|
2
|
-
import json
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
|
|
5
|
-
import pytest
|
|
6
|
-
|
|
7
|
-
import session_title_turn_gate
|
|
8
|
-
from open_tasks_transcript import TaskItem
|
|
9
|
-
|
|
10
|
-
REMOTE_TITLE_TOOL = "mcp__claude-code-remote__set_session_title"
|
|
11
|
-
DESKTOP_TITLE_TOOL = "mcp__ccd_session_mgmt__set_session_title"
|
|
12
|
-
TOOL_LISTING = {
|
|
13
|
-
"type": "attachment",
|
|
14
|
-
"attachment": {
|
|
15
|
-
"type": "prompt_snapshot",
|
|
16
|
-
"tools": [{"name": "Bash"}, {"name": REMOTE_TITLE_TOOL}],
|
|
17
|
-
},
|
|
18
|
-
}
|
|
19
|
-
DEFERRED_LISTING = {
|
|
20
|
-
"type": "attachment",
|
|
21
|
-
"attachment": {"type": "deferred_tools_delta", "addedNames": [DESKTOP_TITLE_TOOL]},
|
|
22
|
-
}
|
|
23
|
-
PROMPT = {"type": "user", "message": {"role": "user", "content": "Fix the gate"}}
|
|
24
|
-
WORK_CALL = {
|
|
25
|
-
"type": "assistant",
|
|
26
|
-
"message": {"content": [{"type": "tool_use", "id": "w1", "name": "Bash", "input": {}}]},
|
|
27
|
-
}
|
|
28
|
-
WORK_RESULT = {
|
|
29
|
-
"type": "user",
|
|
30
|
-
"message": {"content": [{"type": "tool_result", "tool_use_id": "w1", "content": "ok"}]},
|
|
31
|
-
}
|
|
32
|
-
SESSION_ID = "s-title"
|
|
33
|
-
RED_FLAG_TITLE = "\U0001f6a9 Merge approval"
|
|
34
|
-
HOURGLASS_TITLE = "\u23f3 Export"
|
|
35
|
-
QUESTION_PROMPT = {"type": "user", "message": {"role": "user", "content": "did the export fail?"}}
|
|
36
|
-
REPLY = {"type": "assistant", "message": {"content": [{"type": "text", "text": "Done."}]}}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def title_call(
|
|
40
|
-
tool_use_id: str, tool_name: str = REMOTE_TITLE_TOOL, title: str = "✅ Gate"
|
|
41
|
-
) -> dict[str, object]:
|
|
42
|
-
return {
|
|
43
|
-
"type": "assistant",
|
|
44
|
-
"message": {
|
|
45
|
-
"content": [
|
|
46
|
-
{
|
|
47
|
-
"type": "tool_use",
|
|
48
|
-
"id": tool_use_id,
|
|
49
|
-
"name": tool_name,
|
|
50
|
-
"input": {"title": title},
|
|
51
|
-
}
|
|
52
|
-
]
|
|
53
|
-
},
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def title_result(tool_use_id: str, is_error: bool = False) -> dict[str, object]:
|
|
58
|
-
return {
|
|
59
|
-
"type": "user",
|
|
60
|
-
"message": {
|
|
61
|
-
"content": [
|
|
62
|
-
{
|
|
63
|
-
"type": "tool_result",
|
|
64
|
-
"tool_use_id": tool_use_id,
|
|
65
|
-
"content": "ok",
|
|
66
|
-
"is_error": is_error,
|
|
67
|
-
}
|
|
68
|
-
]
|
|
69
|
-
},
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def run_gate(
|
|
74
|
-
monkeypatch: pytest.MonkeyPatch,
|
|
75
|
-
capsys: pytest.CaptureFixture[str],
|
|
76
|
-
tmp_path: Path,
|
|
77
|
-
all_entries: list[dict[str, object]],
|
|
78
|
-
is_stop_hook_active: bool = False,
|
|
79
|
-
) -> tuple[int, str]:
|
|
80
|
-
transcript_path = tmp_path / "transcript.jsonl"
|
|
81
|
-
transcript_path.write_text(
|
|
82
|
-
"\n".join(json.dumps(each) for each in all_entries) + "\n", encoding="utf-8"
|
|
83
|
-
)
|
|
84
|
-
hook_input = {
|
|
85
|
-
"hook_event_name": "Stop",
|
|
86
|
-
"session_id": SESSION_ID,
|
|
87
|
-
"stop_hook_active": is_stop_hook_active,
|
|
88
|
-
"transcript_path": str(transcript_path),
|
|
89
|
-
}
|
|
90
|
-
monkeypatch.setattr(
|
|
91
|
-
"sys.stdin", io.TextIOWrapper(io.BytesIO(json.dumps(hook_input).encode("utf-8")))
|
|
92
|
-
)
|
|
93
|
-
exit_code = session_title_turn_gate.main()
|
|
94
|
-
return exit_code, capsys.readouterr().out
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
@pytest.fixture(autouse=True)
|
|
98
|
-
def isolated_home(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
|
|
99
|
-
monkeypatch.setenv("HOME", str(tmp_path))
|
|
100
|
-
monkeypatch.setenv("USERPROFILE", str(tmp_path))
|
|
101
|
-
monkeypatch.delenv("CLAUDE_CONFIG_DIR", raising=False)
|
|
102
|
-
monkeypatch.delenv("CLAUDE_CODE_TASK_LIST_ID", raising=False)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
def write_task_store(home_directory: Path, all_statuses: list[str]) -> None:
|
|
106
|
-
task_directory = home_directory / ".claude" / "tasks" / SESSION_ID
|
|
107
|
-
task_directory.mkdir(parents=True)
|
|
108
|
-
for each_number, each_status in enumerate(all_statuses, start=1):
|
|
109
|
-
each_task = {"id": str(each_number), "subject": f"Step {each_number}", "status": each_status}
|
|
110
|
-
(task_directory / f"{each_number}.json").write_text(json.dumps(each_task), encoding="utf-8")
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
def earlier_turn(title: str) -> list[dict[str, object]]:
|
|
114
|
-
return [TOOL_LISTING, PROMPT, title_call("t0", title=title), title_result("t0"), REPLY]
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
def block_reason(
|
|
118
|
-
monkeypatch: pytest.MonkeyPatch,
|
|
119
|
-
capsys: pytest.CaptureFixture[str],
|
|
120
|
-
tmp_path: Path,
|
|
121
|
-
all_entries: list[dict[str, object]],
|
|
122
|
-
) -> str:
|
|
123
|
-
stdout_text = run_gate(monkeypatch, capsys, tmp_path, all_entries)[1]
|
|
124
|
-
return json.loads(stdout_text)["reason"] if stdout_text else ""
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
def test_should_hold_a_work_turn_in_a_session_with_no_title(
|
|
128
|
-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
|
|
129
|
-
) -> None:
|
|
130
|
-
exit_code, stdout_text = run_gate(
|
|
131
|
-
monkeypatch, capsys, tmp_path, [TOOL_LISTING, PROMPT, WORK_CALL, WORK_RESULT, REPLY]
|
|
132
|
-
)
|
|
133
|
-
block_output = json.loads(stdout_text)
|
|
134
|
-
assert exit_code == 0
|
|
135
|
-
assert block_output["decision"] == "block"
|
|
136
|
-
assert "no title yet" in block_output["reason"]
|
|
137
|
-
assert REMOTE_TITLE_TOOL in block_output["reason"]
|
|
138
|
-
assert all(
|
|
139
|
-
each_emoji in block_output["reason"]
|
|
140
|
-
for each_emoji in ("\U0001f6a9", "\U0001f6a7", "✅", "⏳")
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
def test_should_pass_a_turn_that_set_a_title(
|
|
145
|
-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
|
|
146
|
-
) -> None:
|
|
147
|
-
write_task_store(tmp_path, ["completed"])
|
|
148
|
-
all_entries = [
|
|
149
|
-
TOOL_LISTING,
|
|
150
|
-
PROMPT,
|
|
151
|
-
WORK_CALL,
|
|
152
|
-
WORK_RESULT,
|
|
153
|
-
title_call("t1", title=HOURGLASS_TITLE),
|
|
154
|
-
title_result("t1"),
|
|
155
|
-
REPLY,
|
|
156
|
-
]
|
|
157
|
-
assert run_gate(monkeypatch, capsys, tmp_path, all_entries) == (0, "")
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
@pytest.mark.parametrize(
|
|
161
|
-
("earlier_title", "all_statuses"),
|
|
162
|
-
[
|
|
163
|
-
(HOURGLASS_TITLE, ["completed", "in_progress"]),
|
|
164
|
-
("✅ Gate", []),
|
|
165
|
-
("✅ Gate", ["completed"]),
|
|
166
|
-
("\U0001f6a7 Org secret", ["pending"]),
|
|
167
|
-
],
|
|
168
|
-
)
|
|
169
|
-
def test_should_pass_a_work_turn_whose_carried_title_still_fits(
|
|
170
|
-
monkeypatch: pytest.MonkeyPatch,
|
|
171
|
-
capsys: pytest.CaptureFixture[str],
|
|
172
|
-
tmp_path: Path,
|
|
173
|
-
earlier_title: str,
|
|
174
|
-
all_statuses: list[str],
|
|
175
|
-
) -> None:
|
|
176
|
-
if all_statuses:
|
|
177
|
-
write_task_store(tmp_path, all_statuses)
|
|
178
|
-
all_entries = [*earlier_turn(earlier_title), PROMPT, WORK_CALL, WORK_RESULT, REPLY]
|
|
179
|
-
assert run_gate(monkeypatch, capsys, tmp_path, all_entries) == (0, "")
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
def test_should_hold_a_carried_red_flag_after_a_prompt_that_gives_work(
|
|
183
|
-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
|
|
184
|
-
) -> None:
|
|
185
|
-
all_entries = [*earlier_turn(RED_FLAG_TITLE), PROMPT, WORK_CALL, WORK_RESULT, REPLY]
|
|
186
|
-
reason_text = block_reason(monkeypatch, capsys, tmp_path, all_entries)
|
|
187
|
-
assert RED_FLAG_TITLE in reason_text
|
|
188
|
-
assert "red flag" in reason_text
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
def test_should_pass_a_carried_red_flag_after_a_question(
|
|
192
|
-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
|
|
193
|
-
) -> None:
|
|
194
|
-
all_entries = [*earlier_turn(RED_FLAG_TITLE), QUESTION_PROMPT, WORK_CALL, WORK_RESULT, REPLY]
|
|
195
|
-
assert run_gate(monkeypatch, capsys, tmp_path, all_entries) == (0, "")
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
def test_should_hold_a_carried_check_mark_while_items_are_open(
|
|
199
|
-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
|
|
200
|
-
) -> None:
|
|
201
|
-
write_task_store(tmp_path, ["completed", "pending"])
|
|
202
|
-
all_entries = [*earlier_turn("✅ Gate"), QUESTION_PROMPT, WORK_CALL, WORK_RESULT, REPLY]
|
|
203
|
-
assert "open items" in block_reason(monkeypatch, capsys, tmp_path, all_entries)
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
def test_should_hold_a_carried_hourglass_once_every_item_is_completed(
|
|
207
|
-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
|
|
208
|
-
) -> None:
|
|
209
|
-
write_task_store(tmp_path, ["completed", "completed"])
|
|
210
|
-
all_entries = [*earlier_turn(HOURGLASS_TITLE), PROMPT, WORK_CALL, WORK_RESULT, REPLY]
|
|
211
|
-
assert "every task list item is completed" in block_reason(
|
|
212
|
-
monkeypatch, capsys, tmp_path, all_entries
|
|
213
|
-
)
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
def test_should_pass_a_held_turn_even_with_no_title(
|
|
217
|
-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
|
|
218
|
-
) -> None:
|
|
219
|
-
all_entries = [TOOL_LISTING, PROMPT, WORK_CALL, WORK_RESULT, REPLY]
|
|
220
|
-
assert run_gate(monkeypatch, capsys, tmp_path, all_entries, is_stop_hook_active=True) == (0, "")
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
def test_should_pass_a_tool_free_turn_with_no_title(
|
|
224
|
-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
|
|
225
|
-
) -> None:
|
|
226
|
-
assert run_gate(monkeypatch, capsys, tmp_path, [TOOL_LISTING, PROMPT, REPLY]) == (0, "")
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
def test_should_keep_showing_the_earlier_title_when_this_turns_title_call_was_denied(
|
|
230
|
-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
|
|
231
|
-
) -> None:
|
|
232
|
-
all_entries = [
|
|
233
|
-
*earlier_turn(RED_FLAG_TITLE),
|
|
234
|
-
PROMPT,
|
|
235
|
-
WORK_CALL,
|
|
236
|
-
WORK_RESULT,
|
|
237
|
-
title_call("t1", title="⏳ bad title."),
|
|
238
|
-
title_result("t1", is_error=True),
|
|
239
|
-
REPLY,
|
|
240
|
-
]
|
|
241
|
-
assert RED_FLAG_TITLE in block_reason(monkeypatch, capsys, tmp_path, all_entries)
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
def test_should_ignore_a_title_set_on_a_sidechain(
|
|
245
|
-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
|
|
246
|
-
) -> None:
|
|
247
|
-
sidechain_call = {**title_call("s1"), "isSidechain": True}
|
|
248
|
-
sidechain_result = {**title_result("s1"), "isSidechain": True}
|
|
249
|
-
all_entries = [
|
|
250
|
-
TOOL_LISTING,
|
|
251
|
-
PROMPT,
|
|
252
|
-
sidechain_call,
|
|
253
|
-
sidechain_result,
|
|
254
|
-
WORK_CALL,
|
|
255
|
-
WORK_RESULT,
|
|
256
|
-
REPLY,
|
|
257
|
-
]
|
|
258
|
-
assert "no title yet" in block_reason(monkeypatch, capsys, tmp_path, all_entries)
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
def test_should_start_a_turn_at_an_image_only_prompt(
|
|
262
|
-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
|
|
263
|
-
) -> None:
|
|
264
|
-
write_task_store(tmp_path, ["pending"])
|
|
265
|
-
image_prompt = {
|
|
266
|
-
"type": "user",
|
|
267
|
-
"message": {"content": [{"type": "image", "source": {"type": "base64", "data": ""}}]},
|
|
268
|
-
}
|
|
269
|
-
all_entries = [*earlier_turn("✅ Gate"), image_prompt, WORK_CALL, WORK_RESULT, REPLY]
|
|
270
|
-
assert "open items" in block_reason(monkeypatch, capsys, tmp_path, all_entries)
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
def test_should_keep_the_turn_across_a_stop_block_and_a_meta_entry(
|
|
274
|
-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
|
|
275
|
-
) -> None:
|
|
276
|
-
write_task_store(tmp_path, ["pending"])
|
|
277
|
-
stop_block = {
|
|
278
|
-
"type": "attachment",
|
|
279
|
-
"attachment": {"type": "hook_blocking_error", "hookEvent": "Stop"},
|
|
280
|
-
}
|
|
281
|
-
meta_entry = {"type": "user", "isMeta": True, "message": {"content": "Stop hook feedback"}}
|
|
282
|
-
all_entries = [
|
|
283
|
-
TOOL_LISTING,
|
|
284
|
-
PROMPT,
|
|
285
|
-
WORK_CALL,
|
|
286
|
-
WORK_RESULT,
|
|
287
|
-
title_call("t1"),
|
|
288
|
-
title_result("t1"),
|
|
289
|
-
REPLY,
|
|
290
|
-
stop_block,
|
|
291
|
-
meta_entry,
|
|
292
|
-
REPLY,
|
|
293
|
-
]
|
|
294
|
-
assert run_gate(monkeypatch, capsys, tmp_path, all_entries) == (0, "")
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
def test_should_name_a_deferred_title_tool_in_the_reason(
|
|
298
|
-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
|
|
299
|
-
) -> None:
|
|
300
|
-
all_entries = [DEFERRED_LISTING, PROMPT, WORK_CALL, WORK_RESULT, REPLY]
|
|
301
|
-
assert DESKTOP_TITLE_TOOL in block_reason(monkeypatch, capsys, tmp_path, all_entries)
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
@pytest.mark.parametrize(
|
|
305
|
-
"all_entries",
|
|
306
|
-
[
|
|
307
|
-
[PROMPT, WORK_CALL, WORK_RESULT, REPLY],
|
|
308
|
-
[
|
|
309
|
-
DEFERRED_LISTING,
|
|
310
|
-
{
|
|
311
|
-
"type": "attachment",
|
|
312
|
-
"attachment": {
|
|
313
|
-
"type": "deferred_tools_delta",
|
|
314
|
-
"removedNames": [DESKTOP_TITLE_TOOL],
|
|
315
|
-
},
|
|
316
|
-
},
|
|
317
|
-
PROMPT,
|
|
318
|
-
WORK_CALL,
|
|
319
|
-
WORK_RESULT,
|
|
320
|
-
REPLY,
|
|
321
|
-
],
|
|
322
|
-
],
|
|
323
|
-
)
|
|
324
|
-
def test_should_pass_a_session_without_the_title_tool(
|
|
325
|
-
monkeypatch: pytest.MonkeyPatch,
|
|
326
|
-
capsys: pytest.CaptureFixture[str],
|
|
327
|
-
tmp_path: Path,
|
|
328
|
-
all_entries: list[dict[str, object]],
|
|
329
|
-
) -> None:
|
|
330
|
-
assert run_gate(monkeypatch, capsys, tmp_path, all_entries) == (0, "")
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
def test_should_pass_when_the_transcript_cannot_be_read(
|
|
334
|
-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
|
|
335
|
-
) -> None:
|
|
336
|
-
hook_input = {"hook_event_name": "Stop", "transcript_path": str(tmp_path / "missing.jsonl")}
|
|
337
|
-
monkeypatch.setattr(
|
|
338
|
-
"sys.stdin", io.TextIOWrapper(io.BytesIO(json.dumps(hook_input).encode("utf-8")))
|
|
339
|
-
)
|
|
340
|
-
assert (session_title_turn_gate.main(), capsys.readouterr().out) == (0, "")
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
def test_should_return_the_last_title_that_came_back_without_an_error() -> None:
|
|
344
|
-
all_entries = [
|
|
345
|
-
title_call("t1", title=HOURGLASS_TITLE),
|
|
346
|
-
title_result("t1"),
|
|
347
|
-
title_call("t2", title=RED_FLAG_TITLE),
|
|
348
|
-
title_result("t2", is_error=True),
|
|
349
|
-
]
|
|
350
|
-
assert session_title_turn_gate.shown_title(all_entries) == HOURGLASS_TITLE
|
|
351
|
-
assert session_title_turn_gate.shown_title([PROMPT]) is None
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
@pytest.mark.parametrize(
|
|
355
|
-
("title", "expected_status"),
|
|
356
|
-
[(RED_FLAG_TITLE, "\U0001f6a9"), ("⏳️ Export", "⏳"), ("Export", None)],
|
|
357
|
-
)
|
|
358
|
-
def test_should_read_the_status_emoji_without_its_variation_selector(
|
|
359
|
-
title: str, expected_status: str | None
|
|
360
|
-
) -> None:
|
|
361
|
-
assert session_title_turn_gate.title_status(title) == expected_status
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
@pytest.mark.parametrize(
|
|
365
|
-
("title", "is_ask_turn", "all_statuses", "is_expected_stale"),
|
|
366
|
-
[
|
|
367
|
-
(RED_FLAG_TITLE, True, [], True),
|
|
368
|
-
(RED_FLAG_TITLE, False, [], False),
|
|
369
|
-
("✅ Gate", False, ["pending"], True),
|
|
370
|
-
("✅ Gate", True, ["completed"], False),
|
|
371
|
-
("✅ Gate", True, ["completed", "deleted"], False),
|
|
372
|
-
(HOURGLASS_TITLE, True, ["completed", "deleted"], True),
|
|
373
|
-
(HOURGLASS_TITLE, True, ["completed"], True),
|
|
374
|
-
(HOURGLASS_TITLE, True, ["in_progress"], False),
|
|
375
|
-
(HOURGLASS_TITLE, True, [], False),
|
|
376
|
-
],
|
|
377
|
-
)
|
|
378
|
-
def test_should_call_a_status_stale_only_when_the_session_state_contradicts_it(
|
|
379
|
-
title: str, is_ask_turn: bool, all_statuses: list[str], is_expected_stale: bool
|
|
380
|
-
) -> None:
|
|
381
|
-
all_items = [
|
|
382
|
-
TaskItem(str(each_number), "Step", each_status)
|
|
383
|
-
for each_number, each_status in enumerate(all_statuses)
|
|
384
|
-
]
|
|
385
|
-
stale_reason = session_title_turn_gate.stale_status_reason(title, is_ask_turn, all_items)
|
|
386
|
-
assert (stale_reason is not None) is is_expected_stale
|
|
387
|
-
if stale_reason is not None:
|
|
388
|
-
assert title in stale_reason
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
def test_should_build_the_block_reason_from_the_stale_status() -> None:
|
|
392
|
-
all_entries = [*earlier_turn(RED_FLAG_TITLE), PROMPT, WORK_CALL, WORK_RESULT, REPLY]
|
|
393
|
-
reason_text = session_title_turn_gate.turn_block_reason(all_entries, False, True, [])
|
|
394
|
-
assert reason_text is not None
|
|
395
|
-
assert reason_text.startswith("The title '" + RED_FLAG_TITLE)
|
|
396
|
-
assert session_title_turn_gate.turn_block_reason(all_entries, False, False, []) is None
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"""Constants for the owned pull request merge Stop gate."""
|
|
2
|
-
|
|
3
|
-
import re
|
|
4
|
-
|
|
5
|
-
HOOK_EVENT_NAME = "Stop"
|
|
6
|
-
SESSION_ID_KEY = "session_id"
|
|
7
|
-
LAST_ASSISTANT_MESSAGE_KEY = "last_assistant_message"
|
|
8
|
-
DECISION_KEY = "decision"
|
|
9
|
-
BLOCK_DECISION = "block"
|
|
10
|
-
REASON_KEY = "reason"
|
|
11
|
-
ALLOW_EXIT_CODE = 0
|
|
12
|
-
GH_PROGRAM_NAME = "gh"
|
|
13
|
-
GH_API_SUBCOMMAND = "api"
|
|
14
|
-
GH_JQ_OPTION = "--jq"
|
|
15
|
-
PULL_REQUEST_ENDPOINT_TEMPLATE = "repos/{owner}/{repository}/pulls/{number}"
|
|
16
|
-
PULL_REQUEST_STATE_QUERY = '.state + " " + .head.sha'
|
|
17
|
-
STATE_AND_HEAD_SEPARATOR = " "
|
|
18
|
-
OPEN_PULL_REQUEST_STATE = "open"
|
|
19
|
-
HEAD_FIELD = "head"
|
|
20
|
-
URL_FIELD = "url"
|
|
21
|
-
STATE_QUERY_TIMEOUT_SECONDS = 10
|
|
22
|
-
LOOKUP_FAILURE_TEMPLATE = "owned_pr_merge_stop_gate: could not read {endpoint}: {detail}\n"
|
|
23
|
-
BLOCKED_LINE_PATTERN: re.Pattern[str] = re.compile(
|
|
24
|
-
r"^\s*(?:[-*]\s*)?blocked\s*:(.*)$", re.IGNORECASE
|
|
25
|
-
)
|
|
26
|
-
BLOCKED_TEXT_GROUP_INDEX = 1
|
|
27
|
-
BOLD_MARKER = "**"
|
|
28
|
-
NAME_START_PATTERN = r"(?<![0-9A-Za-z_./-])"
|
|
29
|
-
NAME_END_PATTERN = r"(?![0-9A-Za-z/])"
|
|
30
|
-
PULL_REQUEST_REFERENCE_TEMPLATE = "{owner}/{repository}#{number}"
|
|
31
|
-
PULL_REQUEST_LINE_TEMPLATE = "\n- {url}"
|
|
32
|
-
BLOCK_REASON_PREFIX = "You opened these owned pull requests and they are still open:"
|
|
33
|
-
BLOCK_REASON_SUFFIX = (
|
|
34
|
-
"\nThe repository owner approves the whole owned PR loop, the merge included."
|
|
35
|
-
" Keep working now: run /efficient-review until a pass is clean, mark the PR ready,"
|
|
36
|
-
" babysit CI and review threads, then merge it and read it back as merged."
|
|
37
|
-
" End the turn early only with one line per pull request:"
|
|
38
|
-
" 'Blocked: <owner>/<repository>#<number> - <what only the owner can give>'."
|
|
39
|
-
" A user who asked to hold the PR or to read it first is such a blocker."
|
|
40
|
-
)
|