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
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
Reads the tool payload from stdin once, runs each hosted hook in-process via
|
|
5
5
|
runpy in the fixed order declared in the constants module, aggregates the
|
|
6
6
|
results, and emits one PostToolUse block decision when any hook blocked
|
|
7
|
-
(carrying every blocking reason) or exits zero to allow.
|
|
7
|
+
(carrying every blocking reason) or exits zero to allow. When a hosted hook
|
|
8
|
+
exits 2, the dispatcher exits 2 after the whole roster runs, and on
|
|
9
|
+
PostToolUse the host then shows that hook's stderr to the model.
|
|
8
10
|
|
|
9
11
|
The hosted hooks keep every side effect they have today: the formatter writes
|
|
10
12
|
the reformatted file to disk, and the doc publisher uploads the gist. Running
|
|
@@ -44,6 +46,7 @@ from hooks_constants.post_tool_use_dispatcher_constants import ( # noqa: E402
|
|
|
44
46
|
from hooks_constants.pre_tool_use_stdin import ( # noqa: E402
|
|
45
47
|
read_hook_input_dictionary_from_stdin,
|
|
46
48
|
)
|
|
49
|
+
from hooks_constants.hosted_hook_runner_constants import BLOCKING_EXIT_CODE
|
|
47
50
|
|
|
48
51
|
|
|
49
52
|
@dataclass
|
|
@@ -54,11 +57,13 @@ class PostHostedHookResult:
|
|
|
54
57
|
captured_stdout: The text the hook wrote to stdout during its run.
|
|
55
58
|
did_crash: True when the hook raised a non-SystemExit exception.
|
|
56
59
|
is_blocking: True when this hook's crash surfaces a blocking signal.
|
|
60
|
+
exit_code: The integer code the hook passed to SystemExit, else 0.
|
|
57
61
|
"""
|
|
58
62
|
|
|
59
63
|
captured_stdout: str
|
|
60
64
|
did_crash: bool = field(default=False)
|
|
61
65
|
is_blocking: bool = field(default=False)
|
|
66
|
+
exit_code: int = field(default=0)
|
|
62
67
|
|
|
63
68
|
|
|
64
69
|
def _log_hook_crash(hook_script_path: str, error: Exception) -> None:
|
|
@@ -88,8 +93,8 @@ def run_hosted_hook(
|
|
|
88
93
|
Sets stdin to a fresh stream over payload_text, sets argv to the hook's
|
|
89
94
|
script path plus its argument tail so a hook reading sys.argv resolves the
|
|
90
95
|
same arguments the live entry passes, captures stdout into a buffer, runs
|
|
91
|
-
the hook via runpy under __main__, catches SystemExit to
|
|
92
|
-
exit without ending the dispatcher, and catches a non-SystemExit exception
|
|
96
|
+
the hook via runpy under __main__, catches SystemExit to record the hook's
|
|
97
|
+
exit code without ending the dispatcher, and catches a non-SystemExit exception
|
|
93
98
|
to log the crash and classify it. Always restores stdin, stdout, and argv
|
|
94
99
|
in the finally block.
|
|
95
100
|
|
|
@@ -101,22 +106,23 @@ def run_hosted_hook(
|
|
|
101
106
|
is_blocking: Whether a crash from this hook surfaces a blocking signal.
|
|
102
107
|
|
|
103
108
|
Returns:
|
|
104
|
-
A PostHostedHookResult carrying the captured stdout, crash flag,
|
|
105
|
-
blocking classification.
|
|
109
|
+
A PostHostedHookResult carrying the captured stdout, crash flag,
|
|
110
|
+
blocking classification, and exit code.
|
|
106
111
|
"""
|
|
107
112
|
original_stdin = sys.stdin
|
|
108
113
|
original_stdout = sys.stdout
|
|
109
114
|
original_argv = sys.argv
|
|
110
115
|
captured_output = io.StringIO()
|
|
111
116
|
hook_did_crash = False
|
|
117
|
+
hook_exit_code = 0
|
|
112
118
|
|
|
113
119
|
try:
|
|
114
120
|
sys.stdin = io.StringIO(payload_text)
|
|
115
121
|
sys.stdout = captured_output
|
|
116
122
|
sys.argv = [hook_script_path, *all_hook_arguments]
|
|
117
123
|
runpy.run_path(hook_script_path, run_name="__main__")
|
|
118
|
-
except SystemExit:
|
|
119
|
-
|
|
124
|
+
except SystemExit as exit_signal:
|
|
125
|
+
hook_exit_code = exit_signal.code if isinstance(exit_signal.code, int) else 0
|
|
120
126
|
except Exception as error:
|
|
121
127
|
_log_hook_crash(hook_script_path, error)
|
|
122
128
|
hook_did_crash = True
|
|
@@ -129,6 +135,7 @@ def run_hosted_hook(
|
|
|
129
135
|
captured_stdout=captured_output.getvalue(),
|
|
130
136
|
did_crash=hook_did_crash,
|
|
131
137
|
is_blocking=is_blocking,
|
|
138
|
+
exit_code=hook_exit_code,
|
|
132
139
|
)
|
|
133
140
|
|
|
134
141
|
|
|
@@ -288,32 +295,43 @@ def _resolve_argument_tail(each_entry: PostHostedHookEntry, plugin_root: str) ->
|
|
|
288
295
|
return resolved_arguments
|
|
289
296
|
|
|
290
297
|
|
|
291
|
-
def
|
|
292
|
-
|
|
298
|
+
def _run_every_hosted_hook(payload_text: str, plugin_root: str) -> list[PostHostedHookResult]:
|
|
299
|
+
return [
|
|
300
|
+
run_hosted_hook(
|
|
301
|
+
_resolve_hook_script_path(each_entry.script_relative_path),
|
|
302
|
+
_resolve_argument_tail(each_entry, plugin_root),
|
|
303
|
+
payload_text,
|
|
304
|
+
each_entry.is_blocking,
|
|
305
|
+
)
|
|
306
|
+
for each_entry in ALL_POST_HOSTED_HOOK_ENTRIES
|
|
307
|
+
]
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def dispatch(payload_text: str, plugin_root: str) -> int:
|
|
311
|
+
"""Run all hosted PostToolUse hooks, emit one aggregated decision, and return the exit code.
|
|
293
312
|
|
|
294
313
|
Runs each hosted hook in-process via run_hosted_hook in the fixed order,
|
|
295
314
|
aggregates the results, and emits a block JSON object when any hook blocked.
|
|
296
|
-
A clean run with no block emits nothing
|
|
315
|
+
A clean run with no block emits nothing. Returns 2 when a hosted hook exited
|
|
316
|
+
2 and 0 otherwise, and the caller exits with that code.
|
|
297
317
|
|
|
298
318
|
Args:
|
|
299
319
|
payload_text: The raw JSON payload text to replay to each hook.
|
|
300
320
|
plugin_root: The plugin root absolute path used to resolve hook
|
|
301
321
|
arguments.
|
|
302
|
-
"""
|
|
303
|
-
all_results: list[PostHostedHookResult] = []
|
|
304
|
-
for each_entry in ALL_POST_HOSTED_HOOK_ENTRIES:
|
|
305
|
-
script_path = _resolve_hook_script_path(each_entry.script_relative_path)
|
|
306
|
-
argument_tail = _resolve_argument_tail(each_entry, plugin_root)
|
|
307
|
-
hook_result = run_hosted_hook(
|
|
308
|
-
script_path, argument_tail, payload_text, each_entry.is_blocking
|
|
309
|
-
)
|
|
310
|
-
all_results.append(hook_result)
|
|
311
322
|
|
|
323
|
+
Returns:
|
|
324
|
+
The exit code the dispatcher hands the host.
|
|
325
|
+
"""
|
|
326
|
+
all_results = _run_every_hosted_hook(payload_text, plugin_root)
|
|
312
327
|
aggregated_decision = aggregate_post_hosted_hook_results(all_results)
|
|
313
328
|
if aggregated_decision.should_block:
|
|
314
329
|
_emit_block_decision(aggregated_decision)
|
|
315
330
|
else:
|
|
316
331
|
_emit_non_block_stdout(aggregated_decision.all_non_block_stdout, sys.stdout)
|
|
332
|
+
if any(each_result.exit_code == BLOCKING_EXIT_CODE for each_result in all_results):
|
|
333
|
+
return BLOCKING_EXIT_CODE
|
|
334
|
+
return 0
|
|
317
335
|
|
|
318
336
|
|
|
319
337
|
def _resolve_plugin_root() -> str:
|
|
@@ -336,8 +354,7 @@ def main() -> None:
|
|
|
336
354
|
sys.exit(0)
|
|
337
355
|
|
|
338
356
|
payload_text = json.dumps(payload_dict)
|
|
339
|
-
dispatch(payload_text, _resolve_plugin_root())
|
|
340
|
-
sys.exit(0)
|
|
357
|
+
sys.exit(dispatch(payload_text, _resolve_plugin_root()))
|
|
341
358
|
|
|
342
359
|
|
|
343
360
|
if __name__ == "__main__":
|
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import io
|
|
5
6
|
import json
|
|
6
7
|
import os
|
|
7
8
|
import subprocess
|
|
8
9
|
import sys
|
|
9
10
|
from pathlib import Path
|
|
10
11
|
|
|
12
|
+
import pytest
|
|
13
|
+
|
|
11
14
|
_HOOKS_DIR = str(Path(__file__).resolve().parent.parent)
|
|
12
15
|
if _HOOKS_DIR not in sys.path:
|
|
13
16
|
sys.path.insert(0, _HOOKS_DIR)
|
|
@@ -368,3 +371,43 @@ def test_live_roster_contains_only_nonblocking_hooks() -> None:
|
|
|
368
371
|
"workflow/auto_formatter.py",
|
|
369
372
|
"advisory/edit_lint_context.py",
|
|
370
373
|
)
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
_EXIT_PROBE_SOURCE = "import sys\nsys.stderr.write('probe child says stop\\n')\nsys.exit({exit_code})\n"
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
def _write_exit_probe(tmp_path: Path, exit_code: int) -> str:
|
|
380
|
+
probe_path = tmp_path / f"exit_{exit_code}_probe.py"
|
|
381
|
+
probe_path.write_text(_EXIT_PROBE_SOURCE.format(exit_code=exit_code), encoding="utf-8")
|
|
382
|
+
return str(probe_path)
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
@pytest.mark.parametrize(("child_exit_code", "expected_exit_code"), [(2, 2), (1, 0), (0, 0)])
|
|
386
|
+
def test_should_pass_a_hosted_hook_exit_two_to_the_host_with_its_stderr(
|
|
387
|
+
tmp_path: Path,
|
|
388
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
389
|
+
capsys: pytest.CaptureFixture[str],
|
|
390
|
+
child_exit_code: int,
|
|
391
|
+
expected_exit_code: int,
|
|
392
|
+
) -> None:
|
|
393
|
+
dispatcher_module = sys.modules[aggregate_post_hosted_hook_results.__module__]
|
|
394
|
+
later_marker = tmp_path / "later_hook_ran.txt"
|
|
395
|
+
later_probe = tmp_path / "later_probe.py"
|
|
396
|
+
later_probe.write_text(
|
|
397
|
+
f"from pathlib import Path\nPath({str(later_marker)!r}).write_text('ran')\n",
|
|
398
|
+
encoding="utf-8",
|
|
399
|
+
)
|
|
400
|
+
all_entries = (
|
|
401
|
+
PostHostedHookEntry(script_relative_path=_write_exit_probe(tmp_path, child_exit_code)),
|
|
402
|
+
PostHostedHookEntry(script_relative_path=str(later_probe)),
|
|
403
|
+
)
|
|
404
|
+
monkeypatch.setattr(dispatcher_module, "ALL_POST_HOSTED_HOOK_ENTRIES", all_entries)
|
|
405
|
+
monkeypatch.setattr(sys, "argv", [_DISPATCHER_SCRIPT])
|
|
406
|
+
monkeypatch.setattr(sys, "stdin", io.StringIO(json.dumps({"tool_name": _WRITE_TOOL_NAME})))
|
|
407
|
+
|
|
408
|
+
with pytest.raises(SystemExit) as raised_exit:
|
|
409
|
+
dispatcher_module.main()
|
|
410
|
+
|
|
411
|
+
assert (raised_exit.value.code or 0) == expected_exit_code
|
|
412
|
+
assert "probe child says stop" in capsys.readouterr().err
|
|
413
|
+
assert later_marker.exists()
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# Present questions clearly
|
|
2
2
|
|
|
3
|
-
Before every ask, repeats
|
|
3
|
+
Before every ask, repeats too, give a short chat brief with context, each choice's effect, and helpful visuals.
|
|
4
4
|
|
|
5
|
-
Ask one short,
|
|
5
|
+
Ask one short question per item, never a chat list, with two or three choices, each a short label and sentence. Reuse labels in brief, comparison, and picker. Keep the turn's chat text before a question to 450 words and 15 list or table items; a Claude hook refuses more.
|
|
6
6
|
|
|
7
|
-
Find the native question tool
|
|
7
|
+
Find the native question tool. Claude may use `AskUserQuestion`; Codex may use `request_user_input_async` or `request_user_input`. Honor mode rules. Put the question and choices in its fields. If unusable, ask in chat.
|
|
8
8
|
|
|
9
|
-
When the user asks for option cards
|
|
9
|
+
When the user asks for option cards or a Codex visual comparison, read the full text first.
|
|
10
10
|
|
|
11
11
|
**Full text:** [`~/.claude/docs/rule-guides/question-presentation.md`](../docs/rule-guides/question-presentation.md).
|
|
@@ -11,7 +11,7 @@ paths:
|
|
|
11
11
|
|
|
12
12
|
**When:** Write or change anything that starts another agent, such as an agent definition, a skill, a hook, a workflow or a `claude -p` command.
|
|
13
13
|
|
|
14
|
-
Name both the model and the effort on every spawn.
|
|
14
|
+
Name both the model and the effort on every spawn. The efforts each model may run at, and the effort it gets otherwise, are in [`subagent_effort_levels.json`](../hooks/hooks_constants/subagent_effort_levels.json). Use Anthropic models only. An advisor that is not the built-in advisor tool runs on Opus at high.
|
|
15
15
|
|
|
16
16
|
**Enforcement:** `hooks/routing/subagent_effort_route_hook.py` sets the allowed effort on Agent and Task spawns, and `hooks/routing/thread_spawn_pace_hook.py` does it for thread spawns that name a model.
|
|
17
17
|
|
|
@@ -40,7 +40,7 @@ from dev_env_scripts_constants.claude_account_worker_constants import (
|
|
|
40
40
|
VERBOSE_FLAG,
|
|
41
41
|
UTF8_ENCODING,
|
|
42
42
|
)
|
|
43
|
-
from subagent_effort_route import model_family, routed_effort
|
|
43
|
+
from subagent_effort_route import load_effort_levels, model_family, routed_effort
|
|
44
44
|
|
|
45
45
|
worker_job_runner = run_job
|
|
46
46
|
|
|
@@ -84,10 +84,11 @@ def worker_effort(model: str | None, effort: str | None) -> str | None:
|
|
|
84
84
|
The allowed effort for the model's family, or ``effort`` when the
|
|
85
85
|
model has no Anthropic family.
|
|
86
86
|
"""
|
|
87
|
-
|
|
87
|
+
all_efforts_by_family = load_effort_levels()
|
|
88
|
+
family = model_family(model, all_efforts_by_family)
|
|
88
89
|
if family is None:
|
|
89
90
|
return effort
|
|
90
|
-
return routed_effort(family, effort)
|
|
91
|
+
return routed_effort(family, effort, all_efforts_by_family)
|
|
91
92
|
|
|
92
93
|
|
|
93
94
|
def _invocation(*, model: str | None, effort: str | None, permission_mode: str, is_streamed: bool) -> list[str]:
|
|
@@ -136,14 +136,14 @@ def _names_exempt_registration_path(registered_string: str) -> bool:
|
|
|
136
136
|
hooks/blocking/session_title_format_gate.py -> exempt
|
|
137
137
|
hooks/blocking/artifact_dark_mode_gate.py -> exempt
|
|
138
138
|
hooks/blocking/send_user_file_worktree_root_gate.py -> exempt
|
|
139
|
+
hooks/blocking/question_brief_gate.py -> exempt
|
|
139
140
|
hooks/blocking/build_eval_before_eval_write_gate.py -> exempt
|
|
140
141
|
hooks/blocking/final_reply_gate.py -> exempt
|
|
141
142
|
hooks/blocking/open_tasks_stop_gate.py -> exempt
|
|
142
|
-
hooks/blocking/owned_pr_merge_stop_gate.py -> exempt
|
|
143
|
-
hooks/blocking/session_title_turn_gate.py -> exempt
|
|
144
143
|
hooks/blocking/resolve_thread_reply_gate.py -> exempt
|
|
145
144
|
hooks/blocking/turn_review_gate.py -> exempt
|
|
146
145
|
hooks/blocking/wakeup_cap_gate.py -> exempt
|
|
146
|
+
hooks/blocking/task_subject_length_gate.py -> exempt
|
|
147
147
|
hooks/blocking/some_new_blocker.py -> flagged
|
|
148
148
|
|
|
149
149
|
The Bash PreToolUse dispatcher sits under ``blocking/`` for layout reasons
|
|
@@ -173,10 +173,8 @@ def _names_exempt_registration_path(registered_string: str) -> bool:
|
|
|
173
173
|
The verify-before-acting hook runs after a mutating call has finished. It
|
|
174
174
|
asks the model to check a hedged claim, and the call it reads stays in place.
|
|
175
175
|
|
|
176
|
-
The session title
|
|
177
|
-
|
|
178
|
-
shown status stops fitting. They decide the shape of a title and no code
|
|
179
|
-
or safety policy.
|
|
176
|
+
The session title format gate denies a malformed title. It decides the
|
|
177
|
+
shape of a title and no code or safety policy.
|
|
180
178
|
|
|
181
179
|
The artifact page gate denies a page publish whose text is unreadable in
|
|
182
180
|
dark mode. It decides how a page renders and no code or safety policy.
|
|
@@ -185,6 +183,10 @@ def _names_exempt_registration_path(registered_string: str) -> bool:
|
|
|
185
183
|
working directory, which the desktop file pane cannot open. It decides
|
|
186
184
|
where a sent file sits and no code or safety policy.
|
|
187
185
|
|
|
186
|
+
The question brief gate denies a question call when the chat text before
|
|
187
|
+
it in the same turn is too long to read at a glance. It decides the shape
|
|
188
|
+
of a brief and no code or safety policy.
|
|
189
|
+
|
|
188
190
|
The eval write gate denies a write to an eval file until the session
|
|
189
191
|
invokes ``/claude-api build-eval``. It holds eval writes until a skill
|
|
190
192
|
loads, and it judges no code or safety content.
|
|
@@ -193,11 +195,6 @@ def _names_exempt_registration_path(registered_string: str) -> bool:
|
|
|
193
195
|
on an ask and made no task list call. It decides when a turn may end and
|
|
194
196
|
no code or safety policy.
|
|
195
197
|
|
|
196
|
-
The owned pull request Stop gate holds the end of a turn while a pull
|
|
197
|
-
request the session opened on an owned repository is still open and the
|
|
198
|
-
closing reply names no ``Blocked:`` line for it. It decides when a turn may
|
|
199
|
-
end and no code or safety policy.
|
|
200
|
-
|
|
201
198
|
The resolve reply gate denies a review thread resolve until a reply on the
|
|
202
199
|
thread has posted. It decides the order of two review calls and no code or
|
|
203
200
|
safety policy.
|
|
@@ -211,6 +208,10 @@ def _names_exempt_registration_path(registered_string: str) -> bool:
|
|
|
211
208
|
or more away, so the wake lands inside the prompt cache. It decides when a
|
|
212
209
|
session wakes and no code or safety policy.
|
|
213
210
|
|
|
211
|
+
The task subject length gate denies a task list item whose name is over 80
|
|
212
|
+
characters. It decides the shape of a task subject and no code or safety
|
|
213
|
+
policy.
|
|
214
|
+
|
|
214
215
|
Args:
|
|
215
216
|
registered_string: One command, path, script, or entrypoint string.
|
|
216
217
|
"""
|
|
@@ -74,16 +74,16 @@ ALL_ACTION_BOUNDARY_EXEMPT_REGISTRATION_PATHS = (
|
|
|
74
74
|
"blocking/image_read_size_gate.py",
|
|
75
75
|
"blocking/artifact_dark_mode_gate.py",
|
|
76
76
|
"blocking/send_user_file_worktree_root_gate.py",
|
|
77
|
+
"blocking/question_brief_gate.py",
|
|
77
78
|
"blocking/haiku_spawn_slim_gate.py",
|
|
78
79
|
"blocking/build_eval_before_eval_write_gate.py",
|
|
79
80
|
"blocking/final_reply_gate.py",
|
|
80
81
|
"blocking/open_tasks_stop_gate.py",
|
|
81
|
-
"blocking/owned_pr_merge_stop_gate.py",
|
|
82
|
-
"blocking/session_title_turn_gate.py",
|
|
83
82
|
"blocking/resolve_thread_reply_gate.py",
|
|
84
83
|
"blocking/turn_review_gate.py",
|
|
85
84
|
"blocking/wakeup_cap_gate.py",
|
|
86
85
|
"blocking/transcript_root_search_gate.py",
|
|
86
|
+
"blocking/task_subject_length_gate.py",
|
|
87
87
|
)
|
|
88
88
|
ALL_TEST_DIRECTORY_NAMES = frozenset({"tests"})
|
|
89
89
|
ALL_TEST_FILE_PREFIXES = ("test_",)
|
|
@@ -121,6 +121,7 @@ def test_should_run_the_worker_at_an_allowed_effort(
|
|
|
121
121
|
("model", "effort", "expected_effort"),
|
|
122
122
|
[
|
|
123
123
|
("opus", "xhigh", "medium"),
|
|
124
|
+
("opus", "high", "high"),
|
|
124
125
|
("sonnet", None, "high"),
|
|
125
126
|
("haiku", "max", "max"),
|
|
126
127
|
("gpt-5", "xhigh", "xhigh"),
|
|
@@ -130,9 +130,9 @@ def test_new_session_title_gate_registration_is_clean(tmp_path: Path) -> None:
|
|
|
130
130
|
assert adapters.hook_configuration_diagnostics(current_document, tmp_path) == ()
|
|
131
131
|
|
|
132
132
|
|
|
133
|
-
def
|
|
133
|
+
def test_new_task_subject_gate_registration_is_clean(tmp_path: Path) -> None:
|
|
134
134
|
current_document = _hook_document(
|
|
135
|
-
["hooks/blocking/
|
|
135
|
+
["hooks/blocking/task_subject_length_gate.py"],
|
|
136
136
|
'{"hooks": {}}',
|
|
137
137
|
)
|
|
138
138
|
assert adapters.hook_configuration_diagnostics(current_document, tmp_path) == ()
|
|
@@ -154,6 +154,14 @@ def test_new_send_user_file_gate_registration_is_clean(tmp_path: Path) -> None:
|
|
|
154
154
|
assert adapters.hook_configuration_diagnostics(current_document, tmp_path) == ()
|
|
155
155
|
|
|
156
156
|
|
|
157
|
+
def test_new_question_brief_gate_registration_is_clean(tmp_path: Path) -> None:
|
|
158
|
+
current_document = _hook_document(
|
|
159
|
+
["hooks/blocking/question_brief_gate.py"],
|
|
160
|
+
'{"hooks": {}}',
|
|
161
|
+
)
|
|
162
|
+
assert adapters.hook_configuration_diagnostics(current_document, tmp_path) == ()
|
|
163
|
+
|
|
164
|
+
|
|
157
165
|
def test_new_eval_write_gate_registration_is_clean(tmp_path: Path) -> None:
|
|
158
166
|
current_document = _hook_document(
|
|
159
167
|
["hooks/blocking/build_eval_before_eval_write_gate.py"],
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""Stop hook that keeps a session working until its owned pull requests merge.
|
|
3
|
-
|
|
4
|
-
The owned pull request review-loop hook records each pull request the agent
|
|
5
|
-
opens on an owned repository outside the preset list. At the end of a turn
|
|
6
|
-
this gate asks GitHub for the state and head of each recorded pull request::
|
|
7
|
-
|
|
8
|
-
allow: every recorded pull request reads closed (merged or closed)
|
|
9
|
-
allow: the reply has "Blocked: acme/widgets#42 - the owner must approve"
|
|
10
|
-
allow: acme/widgets#42 is open on the head this gate already blocked on
|
|
11
|
-
block: acme/widgets#42 reads open on a new head and the reply names no blocker
|
|
12
|
-
|
|
13
|
-
A block sends those pull requests back as the reason, so the model keeps
|
|
14
|
-
working the loop, and records each head it blocked on. A later stop on the
|
|
15
|
-
same head passes, and a push to a new head blocks once more. An open pull
|
|
16
|
-
request whose head GitHub does not report blocks on every stop. Claude Code
|
|
17
|
-
ends the turn after eight blocks in a row, and Codex turns the reason into a
|
|
18
|
-
continuation prompt. A state lookup that fails,
|
|
19
|
-
such as a missing ``gh`` or no network, counts as closed, so the gate never
|
|
20
|
-
holds a turn on a fact it could not read. The failure goes to stderr, where
|
|
21
|
-
the host shows it in the hook log.
|
|
22
|
-
"""
|
|
23
|
-
|
|
24
|
-
from __future__ import annotations
|
|
25
|
-
|
|
26
|
-
import json
|
|
27
|
-
import re
|
|
28
|
-
import subprocess
|
|
29
|
-
import sys
|
|
30
|
-
from pathlib import Path
|
|
31
|
-
|
|
32
|
-
hooks_root_directory = str(Path(__file__).resolve().parent.parent)
|
|
33
|
-
if hooks_root_directory not in sys.path:
|
|
34
|
-
sys.path.insert(0, hooks_root_directory)
|
|
35
|
-
|
|
36
|
-
from hooks_constants.hook_block_logger import log_hook_block
|
|
37
|
-
from hooks_constants.owned_pr_merge_stop_gate_constants import (
|
|
38
|
-
ALLOW_EXIT_CODE,
|
|
39
|
-
BLOCK_DECISION,
|
|
40
|
-
BLOCK_REASON_PREFIX,
|
|
41
|
-
BLOCK_REASON_SUFFIX,
|
|
42
|
-
BLOCKED_LINE_PATTERN,
|
|
43
|
-
BLOCKED_TEXT_GROUP_INDEX,
|
|
44
|
-
BOLD_MARKER,
|
|
45
|
-
DECISION_KEY,
|
|
46
|
-
GH_API_SUBCOMMAND,
|
|
47
|
-
GH_JQ_OPTION,
|
|
48
|
-
GH_PROGRAM_NAME,
|
|
49
|
-
HEAD_FIELD,
|
|
50
|
-
HOOK_EVENT_NAME,
|
|
51
|
-
LAST_ASSISTANT_MESSAGE_KEY,
|
|
52
|
-
LOOKUP_FAILURE_TEMPLATE,
|
|
53
|
-
NAME_END_PATTERN,
|
|
54
|
-
NAME_START_PATTERN,
|
|
55
|
-
OPEN_PULL_REQUEST_STATE,
|
|
56
|
-
PULL_REQUEST_ENDPOINT_TEMPLATE,
|
|
57
|
-
PULL_REQUEST_LINE_TEMPLATE,
|
|
58
|
-
PULL_REQUEST_REFERENCE_TEMPLATE,
|
|
59
|
-
PULL_REQUEST_STATE_QUERY,
|
|
60
|
-
REASON_KEY,
|
|
61
|
-
SESSION_ID_KEY,
|
|
62
|
-
STATE_AND_HEAD_SEPARATOR,
|
|
63
|
-
STATE_QUERY_TIMEOUT_SECONDS,
|
|
64
|
-
URL_FIELD,
|
|
65
|
-
)
|
|
66
|
-
from hooks_constants.pre_tool_use_stdin import read_hook_input_dictionary_from_stdin
|
|
67
|
-
from owned_pr_session_record import (
|
|
68
|
-
all_blocked_heads,
|
|
69
|
-
all_recorded_pull_requests,
|
|
70
|
-
record_blocked_heads,
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def open_head(all_pull_request_fields: dict[str, str]) -> str | None:
|
|
75
|
-
"""Return the head sha when GitHub reports the pull request as open, else None.
|
|
76
|
-
|
|
77
|
-
An open pull request whose head GitHub did not report returns an empty
|
|
78
|
-
string, which no earlier block can match.
|
|
79
|
-
|
|
80
|
-
Args:
|
|
81
|
-
all_pull_request_fields: The owner, repository, number, and url fields.
|
|
82
|
-
"""
|
|
83
|
-
endpoint = PULL_REQUEST_ENDPOINT_TEMPLATE.format(**all_pull_request_fields)
|
|
84
|
-
try:
|
|
85
|
-
completed = subprocess.run(
|
|
86
|
-
[GH_PROGRAM_NAME, GH_API_SUBCOMMAND, endpoint, GH_JQ_OPTION, PULL_REQUEST_STATE_QUERY],
|
|
87
|
-
capture_output=True,
|
|
88
|
-
text=True,
|
|
89
|
-
timeout=STATE_QUERY_TIMEOUT_SECONDS,
|
|
90
|
-
check=False,
|
|
91
|
-
)
|
|
92
|
-
except (OSError, subprocess.TimeoutExpired) as lookup_error:
|
|
93
|
-
sys.stderr.write(LOOKUP_FAILURE_TEMPLATE.format(endpoint=endpoint, detail=lookup_error))
|
|
94
|
-
return None
|
|
95
|
-
if completed.returncode != 0:
|
|
96
|
-
sys.stderr.write(LOOKUP_FAILURE_TEMPLATE.format(endpoint=endpoint, detail=completed.stderr.strip()))
|
|
97
|
-
return None
|
|
98
|
-
state, _, head = completed.stdout.strip().partition(STATE_AND_HEAD_SEPARATOR)
|
|
99
|
-
return head.strip() if state == OPEN_PULL_REQUEST_STATE else None
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
def is_reported_blocked(all_pull_request_fields: dict[str, str], reply_text: str) -> bool:
|
|
103
|
-
"""Return True when a Blocked: line of the reply names the pull request.
|
|
104
|
-
|
|
105
|
-
The line names it by ``owner/repository#number`` or by its url. Bold
|
|
106
|
-
markers such as ``**Blocked:**`` are ignored.
|
|
107
|
-
|
|
108
|
-
Args:
|
|
109
|
-
all_pull_request_fields: The owner, repository, number, and url fields.
|
|
110
|
-
reply_text: The closing reply of the turn.
|
|
111
|
-
"""
|
|
112
|
-
all_names = (
|
|
113
|
-
PULL_REQUEST_REFERENCE_TEMPLATE.format(**all_pull_request_fields).lower(),
|
|
114
|
-
all_pull_request_fields["url"].lower(),
|
|
115
|
-
)
|
|
116
|
-
all_blocked_texts = (
|
|
117
|
-
each_match.group(BLOCKED_TEXT_GROUP_INDEX).lower()
|
|
118
|
-
for each_match in map(BLOCKED_LINE_PATTERN.match, reply_text.replace(BOLD_MARKER, "").splitlines())
|
|
119
|
-
if each_match
|
|
120
|
-
)
|
|
121
|
-
all_name_patterns = [NAME_START_PATTERN + re.escape(each_name) + NAME_END_PATTERN for each_name in all_names]
|
|
122
|
-
return any(
|
|
123
|
-
re.search(each_pattern, each_text)
|
|
124
|
-
for each_text in all_blocked_texts
|
|
125
|
-
for each_pattern in all_name_patterns
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
def unfinished_pull_requests(all_hook_input_fields: dict[str, object]) -> list[dict[str, str]]:
|
|
130
|
-
"""Return the recorded pull requests that are open, not reported blocked, and on a new head.
|
|
131
|
-
|
|
132
|
-
Each entry carries its head sha under ``head``. A pull request the gate
|
|
133
|
-
already blocked on at its current head is left out.
|
|
134
|
-
|
|
135
|
-
Args:
|
|
136
|
-
all_hook_input_fields: The Stop hook payload.
|
|
137
|
-
"""
|
|
138
|
-
reply_value = all_hook_input_fields.get(LAST_ASSISTANT_MESSAGE_KEY)
|
|
139
|
-
reply_text = reply_value if isinstance(reply_value, str) else ""
|
|
140
|
-
session_id = all_hook_input_fields.get(SESSION_ID_KEY)
|
|
141
|
-
blocked_heads_by_url = all_blocked_heads(session_id)
|
|
142
|
-
all_unfinished = []
|
|
143
|
-
for each_pull_request in all_recorded_pull_requests(session_id):
|
|
144
|
-
if is_reported_blocked(each_pull_request, reply_text):
|
|
145
|
-
continue
|
|
146
|
-
head = open_head(each_pull_request)
|
|
147
|
-
if head is None or (head and blocked_heads_by_url.get(each_pull_request[URL_FIELD]) == head):
|
|
148
|
-
continue
|
|
149
|
-
all_unfinished.append({**each_pull_request, HEAD_FIELD: head})
|
|
150
|
-
return all_unfinished
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
def block_reason_for(all_open_pull_requests: list[dict[str, str]]) -> str:
|
|
154
|
-
"""Return the block reason that lists each open pull request.
|
|
155
|
-
|
|
156
|
-
Args:
|
|
157
|
-
all_open_pull_requests: The pull requests that hold the turn.
|
|
158
|
-
"""
|
|
159
|
-
all_lines = (PULL_REQUEST_LINE_TEMPLATE.format(**each) for each in all_open_pull_requests)
|
|
160
|
-
return BLOCK_REASON_PREFIX + "".join(all_lines) + BLOCK_REASON_SUFFIX
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
def main() -> int:
|
|
164
|
-
hook_input = read_hook_input_dictionary_from_stdin()
|
|
165
|
-
if hook_input is None:
|
|
166
|
-
return ALLOW_EXIT_CODE
|
|
167
|
-
all_open_pull_requests = unfinished_pull_requests(hook_input)
|
|
168
|
-
if not all_open_pull_requests:
|
|
169
|
-
return ALLOW_EXIT_CODE
|
|
170
|
-
record_blocked_heads(
|
|
171
|
-
hook_input.get(SESSION_ID_KEY),
|
|
172
|
-
{
|
|
173
|
-
each_pull_request[URL_FIELD]: each_pull_request[HEAD_FIELD]
|
|
174
|
-
for each_pull_request in all_open_pull_requests
|
|
175
|
-
if each_pull_request[HEAD_FIELD]
|
|
176
|
-
},
|
|
177
|
-
)
|
|
178
|
-
block_reason = block_reason_for(all_open_pull_requests)
|
|
179
|
-
log_hook_block(Path(__file__).name, HOOK_EVENT_NAME, block_reason)
|
|
180
|
-
sys.stdout.write(json.dumps({DECISION_KEY: BLOCK_DECISION, REASON_KEY: block_reason}))
|
|
181
|
-
return ALLOW_EXIT_CODE
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if __name__ == "__main__":
|
|
185
|
-
sys.exit(main())
|