claude-dev-env 8.116.4 → 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/hooks/validators/ruff_integration.py +46 -4
- package/hooks/validators/test_ruff_integration.py +67 -5
- 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()
|
|
@@ -12,11 +12,17 @@ _validators_directory = str(Path(__file__).resolve().parent)
|
|
|
12
12
|
_hooks_directory = str(Path(__file__).resolve().parent.parent)
|
|
13
13
|
|
|
14
14
|
try:
|
|
15
|
-
from pyproject_config_discovery import
|
|
15
|
+
from pyproject_config_discovery import (
|
|
16
|
+
ancestor_directories,
|
|
17
|
+
find_pyproject_configuring_tool,
|
|
18
|
+
)
|
|
16
19
|
except ModuleNotFoundError:
|
|
17
20
|
if _validators_directory not in sys.path:
|
|
18
21
|
sys.path.insert(0, _validators_directory)
|
|
19
|
-
from pyproject_config_discovery import
|
|
22
|
+
from pyproject_config_discovery import (
|
|
23
|
+
ancestor_directories,
|
|
24
|
+
find_pyproject_configuring_tool,
|
|
25
|
+
)
|
|
20
26
|
|
|
21
27
|
try:
|
|
22
28
|
from hooks_constants.blocking_check_limits import RUFF_STDIN_ENCODING
|
|
@@ -239,10 +245,45 @@ def _run_staged_ruff_check(
|
|
|
239
245
|
return _staged_ruff_result(resolved_pyproject, stdin_filename, staged_content)
|
|
240
246
|
|
|
241
247
|
|
|
248
|
+
def _native_ruff_working_directory(config_source_path: Path | None) -> str | None:
|
|
249
|
+
"""Return the folder a native ruff run starts in, or None for the caller's folder.
|
|
250
|
+
|
|
251
|
+
::
|
|
252
|
+
|
|
253
|
+
config_source_path .../repo/pkg/module.py, pkg exists -> ".../repo/pkg"
|
|
254
|
+
config_source_path .../repo/new_pkg/module.py, new_pkg missing -> ".../repo"
|
|
255
|
+
config_source_path None -> None (the caller's working folder)
|
|
256
|
+
|
|
257
|
+
Ruff grades a file with no config above it under the config found from its
|
|
258
|
+
working folder. A staged copy has no config above it, so starting ruff
|
|
259
|
+
beside the original target makes that fallback the target's own config.
|
|
260
|
+
|
|
261
|
+
Args:
|
|
262
|
+
config_source_path: The original target path the staged copy stands in
|
|
263
|
+
for, or ``None`` for a run over files checked in place.
|
|
264
|
+
|
|
265
|
+
Returns:
|
|
266
|
+
The nearest existing folder at or above the target, or ``None``.
|
|
267
|
+
"""
|
|
268
|
+
if config_source_path is None:
|
|
269
|
+
return None
|
|
270
|
+
return next(
|
|
271
|
+
(
|
|
272
|
+
str(each_candidate_directory)
|
|
273
|
+
for each_candidate_directory in ancestor_directories(config_source_path)
|
|
274
|
+
if each_candidate_directory.is_dir()
|
|
275
|
+
),
|
|
276
|
+
None,
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
|
|
242
280
|
def _run_native_ruff_check(
|
|
243
281
|
all_python_files: list[str], config_source_path: Path | None
|
|
244
282
|
) -> RuffResult:
|
|
245
|
-
"""Run ruff over *all_python_files* directly, resolving
|
|
283
|
+
"""Run ruff over *all_python_files* directly, resolving config from the path.
|
|
284
|
+
|
|
285
|
+
Ruff starts in the folder ``_native_ruff_working_directory`` picks.
|
|
286
|
+
"""
|
|
246
287
|
config_argument = _ruff_config_argument(config_source_path)
|
|
247
288
|
concise_output_arguments = ["--output-format", "concise"]
|
|
248
289
|
result = subprocess.run(
|
|
@@ -250,6 +291,7 @@ def _run_native_ruff_check(
|
|
|
250
291
|
check=False,
|
|
251
292
|
capture_output=True,
|
|
252
293
|
text=True,
|
|
294
|
+
cwd=_native_ruff_working_directory(config_source_path),
|
|
253
295
|
env=_ruff_subprocess_environment(),
|
|
254
296
|
creationflags=hidden_window_creation_flags(),
|
|
255
297
|
)
|
|
@@ -267,7 +309,7 @@ def run_ruff_check(
|
|
|
267
309
|
|
|
268
310
|
A given ``config_source_path`` grades the single staged copy under the project
|
|
269
311
|
config resolved from the original target, applying its path-scoped
|
|
270
|
-
per-file-ignores.
|
|
312
|
+
per-file-ignores. Otherwise the files are checked natively."""
|
|
271
313
|
if not all_files:
|
|
272
314
|
return RuffResult(passed=True, output="No files to check", fixed_count=0)
|
|
273
315
|
|
|
@@ -5,6 +5,8 @@ import sys
|
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
from unittest.mock import patch
|
|
7
7
|
|
|
8
|
+
import pytest
|
|
9
|
+
|
|
8
10
|
from .ruff_integration import (
|
|
9
11
|
RuffResult,
|
|
10
12
|
_config_relative_stdin_filename,
|
|
@@ -72,23 +74,23 @@ def test_run_ruff_check_returns_passed_for_empty_files() -> None:
|
|
|
72
74
|
|
|
73
75
|
|
|
74
76
|
def test_run_ruff_check_applies_config_resolved_from_config_source_path(
|
|
75
|
-
tmp_path: Path,
|
|
77
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
76
78
|
) -> None:
|
|
77
79
|
"""A given config_source_path resolves the ruff config for a staged copy.
|
|
78
80
|
|
|
79
81
|
A ``[tool.ruff.lint]`` selecting B flags an ``assert False`` (B011) only when
|
|
80
82
|
``config_source_path`` — the original ``.py`` target — resolves it; native
|
|
81
|
-
discovery from the detached staged copy
|
|
83
|
+
discovery from the detached staged copy, started in a folder with no ruff
|
|
84
|
+
config, finds none and passes.
|
|
82
85
|
"""
|
|
86
|
+
monkeypatch.chdir(tmp_path)
|
|
83
87
|
ruff_repo = tmp_path / "ruff_repo"
|
|
84
88
|
ruff_repo.mkdir()
|
|
85
89
|
(ruff_repo / "pyproject.toml").write_text(
|
|
86
90
|
"[tool.ruff.lint]\nselect = ['B']\n", encoding="utf-8"
|
|
87
91
|
)
|
|
88
92
|
original_target = ruff_repo / "asserts.py"
|
|
89
|
-
staged_copy = tmp_path
|
|
90
|
-
staged_copy.parent.mkdir(parents=True)
|
|
91
|
-
staged_copy.write_text("def probe() -> None:\n assert False\n", encoding="utf-8")
|
|
93
|
+
staged_copy = _write_detached_assert_false_copy(tmp_path)
|
|
92
94
|
|
|
93
95
|
without_source = run_ruff_check([staged_copy])
|
|
94
96
|
with_source = run_ruff_check([staged_copy], config_source_path=original_target)
|
|
@@ -97,6 +99,66 @@ def test_run_ruff_check_applies_config_resolved_from_config_source_path(
|
|
|
97
99
|
assert "B011" in with_source.output
|
|
98
100
|
|
|
99
101
|
|
|
102
|
+
def _write_detached_assert_false_copy(tmp_path: Path) -> Path:
|
|
103
|
+
"""Write a staged copy holding ``assert False`` under a folder with no ruff config."""
|
|
104
|
+
staged_copy = tmp_path / "detached" / "asserts.py"
|
|
105
|
+
staged_copy.parent.mkdir(parents=True)
|
|
106
|
+
staged_copy.write_text("def probe() -> None:\n assert False\n", encoding="utf-8")
|
|
107
|
+
return staged_copy
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def test_run_ruff_check_should_not_grade_a_staged_copy_under_the_working_folder_config(
|
|
111
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
112
|
+
) -> None:
|
|
113
|
+
"""The working folder's ruff config never grades a staged copy of an unconfigured target.
|
|
114
|
+
|
|
115
|
+
The original target sits in a folder with no ruff config, so the staged run
|
|
116
|
+
does not apply and ruff checks the copy natively. The working folder selects
|
|
117
|
+
B; the copy is still graded under ruff's defaults, which omit B011.
|
|
118
|
+
"""
|
|
119
|
+
session_folder = tmp_path / "session_folder"
|
|
120
|
+
session_folder.mkdir()
|
|
121
|
+
(session_folder / "pyproject.toml").write_text(
|
|
122
|
+
"[tool.ruff.lint]\nselect = ['B']\n", encoding="utf-8"
|
|
123
|
+
)
|
|
124
|
+
unconfigured_repo = tmp_path / "unconfigured_repo"
|
|
125
|
+
unconfigured_repo.mkdir()
|
|
126
|
+
staged_copy = _write_detached_assert_false_copy(tmp_path)
|
|
127
|
+
monkeypatch.chdir(session_folder)
|
|
128
|
+
|
|
129
|
+
result = run_ruff_check(
|
|
130
|
+
[staged_copy], config_source_path=unconfigured_repo / "asserts.py"
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
assert "All checks passed" in result.output
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def test_run_ruff_check_should_grade_a_staged_copy_under_a_ruff_toml_beside_the_target(
|
|
137
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
138
|
+
) -> None:
|
|
139
|
+
"""A ``ruff.toml`` above the original target grades its staged copy.
|
|
140
|
+
|
|
141
|
+
The pyproject walk finds no ``[tool.ruff]`` table, so ruff checks the copy
|
|
142
|
+
natively. Started from a folder with no ruff config, it still reads the
|
|
143
|
+
target's ``ruff.toml``, which selects B and reports B011. The target's
|
|
144
|
+
``new_package`` folder does not exist yet, as for a Write that creates it.
|
|
145
|
+
"""
|
|
146
|
+
session_folder = tmp_path / "session_folder"
|
|
147
|
+
session_folder.mkdir()
|
|
148
|
+
ruff_toml_repo = tmp_path / "ruff_toml_repo"
|
|
149
|
+
ruff_toml_repo.mkdir()
|
|
150
|
+
(ruff_toml_repo / "ruff.toml").write_text("[lint]\nselect = ['B']\n", encoding="utf-8")
|
|
151
|
+
staged_copy = _write_detached_assert_false_copy(tmp_path)
|
|
152
|
+
monkeypatch.chdir(session_folder)
|
|
153
|
+
|
|
154
|
+
result = run_ruff_check(
|
|
155
|
+
[staged_copy],
|
|
156
|
+
config_source_path=ruff_toml_repo / "new_package" / "asserts.py",
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
assert "B011" in result.output
|
|
160
|
+
|
|
161
|
+
|
|
100
162
|
def test_run_ruff_check_grades_a_staged_copy_holding_non_ascii_text(
|
|
101
163
|
tmp_path: Path,
|
|
102
164
|
) -> None:
|
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"],
|