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.
Files changed (101) hide show
  1. package/bin/ever-registered-hooks.mjs +2 -0
  2. package/bin/install-constants.mjs +3 -1
  3. package/bin/install.cursor-rules.test.mjs +64 -2
  4. package/bin/install.mjs +15 -2
  5. package/bin/install.prune.test.mjs +92 -0
  6. package/bin/install.test.mjs +1 -0
  7. package/docs/model-choice/escalation.md +3 -3
  8. package/docs/model-choice/subagents-and-fan-out.md +2 -2
  9. package/docs/model-choice/which-model.md +1 -1
  10. package/docs/references/working-style.md +1 -0
  11. package/docs/rule-guides/question-presentation.md +6 -0
  12. package/docs/rule-guides/session-title.md +8 -9
  13. package/docs/rule-guides/subagent-model-effort.md +13 -13
  14. package/hooks/advisory/owned_pr_review_loop.py +2 -3
  15. package/hooks/blocking/bash_post_call_dispatcher.py +17 -9
  16. package/hooks/blocking/bash_pre_tool_use_dispatcher.py +12 -8
  17. package/hooks/blocking/final_reply_gate.py +5 -9
  18. package/hooks/blocking/open_tasks_stop_gate.py +9 -20
  19. package/hooks/blocking/open_tasks_transcript.py +8 -3
  20. package/hooks/blocking/pii_prevention_blocker_parts/repository_exemption.py +7 -2
  21. package/hooks/blocking/question_brief_gate.py +382 -0
  22. package/hooks/blocking/step_note_gate.py +5 -2
  23. package/hooks/blocking/task_subject_length_gate.py +111 -0
  24. package/hooks/blocking/test_bash_post_call_dispatcher.py +36 -1
  25. package/hooks/blocking/test_bash_pre_tool_use_dispatcher.py +57 -0
  26. package/hooks/blocking/test_final_reply_gate.py +26 -2
  27. package/hooks/blocking/test_open_tasks_stop_gate.py +21 -11
  28. package/hooks/blocking/test_question_brief_gate.py +916 -0
  29. package/hooks/blocking/test_step_note_gate.py +26 -0
  30. package/hooks/blocking/test_task_subject_length_gate.py +221 -0
  31. package/hooks/blocking/test_turn_review_findings.py +124 -1
  32. package/hooks/blocking/test_turn_review_gate.py +1312 -10
  33. package/hooks/blocking/test_turn_review_snapshot.py +8 -0
  34. package/hooks/blocking/tests/test_repository_exemption.py +11 -0
  35. package/hooks/blocking/turn_review_findings.py +173 -13
  36. package/hooks/blocking/turn_review_gate.py +878 -105
  37. package/hooks/blocking/turn_review_snapshot.py +5 -1
  38. package/hooks/features/bash-dispatchers.md +1 -3
  39. package/hooks/features/conduct-gates.md +19 -9
  40. package/hooks/features/lifecycle-cleanup.md +1 -1
  41. package/hooks/features/spawn-routing.md +1 -1
  42. package/hooks/hooks.json +24 -11
  43. package/hooks/hooks_constants/final_reply_gate_constants.py +0 -3
  44. package/hooks/hooks_constants/hook_time_budget.py +61 -0
  45. package/hooks/hooks_constants/hosted_hook_runner.py +51 -21
  46. package/hooks/hooks_constants/hosted_hook_runner_constants.py +3 -0
  47. package/hooks/hooks_constants/nested_project_hooks_constants.py +8 -0
  48. package/hooks/hooks_constants/once_per_session_constants.py +1 -0
  49. package/hooks/hooks_constants/open_tasks_stop_gate_constants.py +0 -4
  50. package/hooks/hooks_constants/owned_pr_review_loop_constants.py +0 -4
  51. package/hooks/hooks_constants/pre_tool_use_context_runner.py +23 -3
  52. package/hooks/hooks_constants/pre_tool_use_context_runner_constants.py +5 -0
  53. package/hooks/hooks_constants/pre_tool_use_stdin.py +1 -1
  54. package/hooks/hooks_constants/question_brief_gate_constants.py +66 -0
  55. package/hooks/hooks_constants/session_title_constants.py +6 -27
  56. package/hooks/hooks_constants/stop_hook_hold.py +54 -0
  57. package/hooks/hooks_constants/stop_hook_hold_constants.py +9 -0
  58. package/hooks/hooks_constants/subagent_effort_levels.json +6 -0
  59. package/hooks/hooks_constants/subagent_effort_route_constants.py +20 -19
  60. package/hooks/hooks_constants/task_subject_length_gate_constants.py +43 -0
  61. package/hooks/hooks_constants/test_hook_time_budget.py +104 -0
  62. package/hooks/hooks_constants/test_hosted_hook_runner.py +12 -0
  63. package/hooks/hooks_constants/test_pre_tool_use_context_runner.py +16 -0
  64. package/hooks/hooks_constants/test_pre_tool_use_stdin.py +6 -0
  65. package/hooks/hooks_constants/test_stop_hook_hold.py +40 -0
  66. package/hooks/hooks_constants/thread_spawn_pace_hook_constants.py +1 -2
  67. package/hooks/hooks_constants/turn_review_gate_constants.py +246 -12
  68. package/hooks/lifecycle/nested_project_hooks.py +34 -4
  69. package/hooks/lifecycle/test_nested_project_hooks.py +52 -0
  70. package/hooks/once_per_session.py +33 -4
  71. package/hooks/open_task_asks.py +1 -1
  72. package/hooks/owned_pr_session_record.py +1 -76
  73. package/hooks/routing/subagent_effort_route.py +107 -13
  74. package/hooks/routing/subagent_effort_route_hook.py +9 -8
  75. package/hooks/routing/test_subagent_effort_route.py +201 -14
  76. package/hooks/routing/test_subagent_effort_route_hook.py +56 -0
  77. package/hooks/routing/thread_spawn_pace_hook.py +3 -3
  78. package/hooks/session/background_silence_prompt.py +1 -1
  79. package/hooks/session/test_tracking_nudge.py +114 -2
  80. package/hooks/session/tracking_nudge.py +28 -18
  81. package/hooks/session_title_transcript.py +195 -0
  82. package/hooks/test_once_per_session.py +10 -0
  83. package/hooks/test_owned_pr_session_record.py +0 -26
  84. package/hooks/test_session_title_transcript.py +111 -0
  85. package/hooks/validation/post_tool_use_dispatcher.py +38 -21
  86. package/hooks/validation/test_post_tool_use_dispatcher.py +43 -0
  87. package/hooks/validators/ruff_integration.py +46 -4
  88. package/hooks/validators/test_ruff_integration.py +67 -5
  89. package/package.json +1 -1
  90. package/rules/question-presentation.md +4 -4
  91. package/rules/subagent-model-effort.md +1 -1
  92. package/scripts/claude_account_worker.py +4 -3
  93. package/scripts/policy_lint/adapter_configuration.py +12 -11
  94. package/scripts/policy_lint/config/constants.py +2 -2
  95. package/scripts/test_claude_account_worker.py +1 -0
  96. package/scripts/tests/test_adapter_configuration.py +10 -2
  97. package/hooks/blocking/owned_pr_merge_stop_gate.py +0 -185
  98. package/hooks/blocking/session_title_turn_gate.py +0 -417
  99. package/hooks/blocking/test_owned_pr_merge_stop_gate.py +0 -254
  100. package/hooks/blocking/test_session_title_turn_gate.py +0 -396
  101. package/hooks/hooks_constants/owned_pr_merge_stop_gate_constants.py +0 -40
@@ -3,6 +3,7 @@ from pathlib import Path
3
3
 
4
4
  import pytest
5
5
 
6
+ from hooks_constants.hook_time_budget import time_budget
6
7
  from turn_review_snapshot import turn_changed_paths, working_tree_snapshot
7
8
 
8
9
 
@@ -105,3 +106,10 @@ def test_should_keep_the_leading_space_of_a_changed_path(repository: Path) -> No
105
106
  (repository / " notes.txt").write_text("new\n")
106
107
  turn_commit = working_tree_snapshot(repository, base_commit)
107
108
  assert turn_changed_paths(repository, base_commit, turn_commit) == [" notes.txt"]
109
+
110
+
111
+ def test_should_take_no_snapshot_once_the_time_budget_is_spent(repository: Path) -> None:
112
+ (repository / "service.py").write_text("call(1)\n")
113
+ with time_budget(0):
114
+ assert working_tree_snapshot(repository, None) is None
115
+ assert working_tree_snapshot(repository, None) is not None
@@ -15,6 +15,7 @@ import subprocess
15
15
  from pathlib import Path
16
16
 
17
17
  import pytest
18
+ from hooks_constants.hook_time_budget import time_budget
18
19
  from pii_prevention_blocker_parts.repository_exemption import (
19
20
  _is_repository_exempt_from_pii_scan,
20
21
  _owner_repo_slug_from_origin_url,
@@ -110,3 +111,13 @@ def test_repository_origin_slug_reads_the_origin_remote(tmp_path: Path) -> None:
110
111
  repository_root = tmp_path / "repo"
111
112
  _init_repo_with_github_origin(repository_root, "SlugOwner/slug-repo")
112
113
  assert repository_origin_slug(repository_root) == "slugowner/slug-repo"
114
+
115
+
116
+ def test_should_read_no_origin_slug_once_the_time_budget_is_spent(tmp_path: Path) -> None:
117
+ subprocess.run(["git", "init", "-q"], cwd=tmp_path, check=True)
118
+ subprocess.run(
119
+ ["git", "remote", "add", "origin", "https://github.com/Owner/Repo.git"], cwd=tmp_path, check=True
120
+ )
121
+ with time_budget(0):
122
+ assert repository_origin_slug(tmp_path) is None
123
+ assert repository_origin_slug(tmp_path) == "owner/repo"
@@ -1,4 +1,4 @@
1
- """Read the findings out of a turn review's text, for the turn review Stop gate.
1
+ """Read the findings, the dismissal requests and the judge's verdicts for the turn review gate.
2
2
 
3
3
  A review either prints a JSON array of findings or prose that names each
4
4
  problem by its changed path and line::
@@ -14,49 +14,92 @@ The last non-empty array of objects with a ``file`` key wins. Its entries count
14
14
  when ``file`` is a changed path and ``line`` is a number. With no such array,
15
15
  each line that opens with a changed path, a colon and a line number counts,
16
16
  after an optional list marker, backtick or emphasis mark.
17
+
18
+ The agent contests a finding with a reply line, and the judge answers in JSON::
19
+
20
+ "Dismiss TR-3: the caller retries" -> {"TR-3": "the caller retries"}
21
+ '[{"id": "TR-3", "verdict": "reject", "reason": "nothing retries"}]'
22
+ -> {"TR-3": JudgeVerdict(is_approved=False, reason="nothing retries")}
23
+
24
+ A dismiss line may open with a list marker, quote mark, backtick or emphasis
25
+ mark. The first line for an id wins, and its reason is cut to 2000 characters.
26
+ The judge's whole answer must be one JSON array, inside at most one code fence.
27
+ Each object holds exactly ``id``, ``verdict`` and ``reason`` once each, and
28
+ each id is one the judge was asked about. Any other answer gives None, such as
29
+ an object that repeats a key or a NaN or Infinity value. So an array or a key
30
+ that the agent planted in its reason and the judge echoed never counts. An entry
31
+ counts when its verdict is ``approve`` or ``reject``, its reason is not empty,
32
+ and no other entry names its id. A character in a reason that UTF-8 cannot
33
+ write, such as a lone surrogate, is kept as its escape text.
17
34
  """
18
35
 
19
36
  from __future__ import annotations
20
37
 
21
38
  import json
22
39
  import re
40
+ from collections import Counter
41
+ from dataclasses import dataclass
42
+ from typing import TypeGuard
23
43
 
24
44
  from hooks_constants.turn_review_gate_constants import (
45
+ ALL_JUDGE_ENTRY_KEYS,
46
+ DISMISS_LINE_PREFIX_PATTERN,
25
47
  FINDING_LINE_PATTERN_TEMPLATE,
26
48
  JSON_ARRAY_START,
49
+ JUDGE_ANSWER_CONSTANT_REASON,
50
+ JUDGE_ANSWER_FENCE_PATTERN,
51
+ JUDGE_ANSWER_REPEATED_KEY_REASON,
52
+ JUDGE_APPROVE_VERDICT,
53
+ JUDGE_ID_KEY,
54
+ JUDGE_REASON_KEY,
55
+ JUDGE_REASON_TEXT_ENCODING,
56
+ JUDGE_REASON_UNENCODABLE_HANDLER,
57
+ JUDGE_REJECT_VERDICT,
58
+ JUDGE_VERDICT_KEY,
27
59
  JSON_FINDING_FILE_KEY,
28
60
  JSON_FINDING_LINE_KEY,
29
61
  JSON_FINDING_LINE_TEMPLATE,
30
62
  JSON_FINDING_SUMMARY_KEY,
63
+ MAXIMUM_DISMISS_REASON_CHARACTERS,
31
64
  NO_FINDINGS_MARKER,
65
+ REASON_EDGE_CHARACTERS,
66
+ REPLY_LINE_SEPARATOR,
32
67
  )
33
68
 
34
69
 
70
+ @dataclass(frozen=True)
71
+ class JudgeVerdict:
72
+ """The judge's answer on one dismissal request."""
73
+
74
+ is_approved: bool
75
+ reason: str
76
+
77
+
35
78
  def _json_finding_lines(review_text: str, all_changed_paths: list[str]) -> list[str] | None:
36
- all_filled_arrays = _filled_finding_arrays(review_text)
79
+ all_filled_arrays = _filled_object_arrays(review_text, JSON_FINDING_FILE_KEY)
37
80
  if not all_filled_arrays:
38
81
  return None
39
82
  return _entries_on_changed_paths(all_filled_arrays[-1], all_changed_paths)
40
83
 
41
84
 
42
- def _filled_finding_arrays(review_text: str) -> list[list[dict[str, object]]]:
85
+ def _filled_object_arrays(text: str, required_key: str) -> list[list[dict[str, object]]]:
43
86
  json_decoder = json.JSONDecoder()
44
- all_finding_arrays: list[list[dict[str, object]]] = []
45
- array_start = review_text.find(JSON_ARRAY_START)
87
+ all_object_arrays: list[list[dict[str, object]]] = []
88
+ array_start = text.find(JSON_ARRAY_START)
46
89
  while array_start >= 0:
47
90
  try:
48
- decoded_array, next_search_start = json_decoder.raw_decode(review_text, array_start)
49
- except ValueError:
91
+ decoded_array, next_search_start = json_decoder.raw_decode(text, array_start)
92
+ except (ValueError, RecursionError):
50
93
  decoded_array, next_search_start = None, array_start + 1
51
- if decoded_array and _is_finding_array(decoded_array):
52
- all_finding_arrays.append(decoded_array)
53
- array_start = review_text.find(JSON_ARRAY_START, next_search_start)
54
- return all_finding_arrays
94
+ if decoded_array and _is_object_array(decoded_array, required_key):
95
+ all_object_arrays.append(decoded_array)
96
+ array_start = text.find(JSON_ARRAY_START, next_search_start)
97
+ return all_object_arrays
55
98
 
56
99
 
57
- def _is_finding_array(decoded_array: object) -> bool:
100
+ def _is_object_array(decoded_array: object, required_key: str) -> bool:
58
101
  return isinstance(decoded_array, list) and all(
59
- isinstance(each_entry, dict) and JSON_FINDING_FILE_KEY in each_entry
102
+ isinstance(each_entry, dict) and required_key in each_entry
60
103
  for each_entry in decoded_array
61
104
  )
62
105
 
@@ -100,3 +143,120 @@ def finding_lines(review_text: str, all_changed_paths: list[str]) -> list[str]:
100
143
  for each_line in review_text.splitlines()
101
144
  if any(each_pattern.search(each_line) for each_pattern in all_patterns)
102
145
  ]
146
+
147
+
148
+ def dismiss_requests(reply_text: str) -> dict[str, str]:
149
+ """Return the reason of each ``Dismiss TR-<n>: <reason>`` line in a reply, by finding id.
150
+
151
+ Args:
152
+ reply_text: The text of the agent's last reply.
153
+
154
+ Returns:
155
+ The reason for each finding id, cut to its first
156
+ ``MAXIMUM_DISMISS_REASON_CHARACTERS``; the first line for an id wins.
157
+ """
158
+ prefix_pattern = re.compile(DISMISS_LINE_PREFIX_PATTERN)
159
+ all_requests: dict[str, str] = {}
160
+ for each_line in reply_text.split(REPLY_LINE_SEPARATOR):
161
+ prefix_match = prefix_pattern.match(each_line)
162
+ if prefix_match is None:
163
+ continue
164
+ reason = each_line[prefix_match.end() :].strip(REASON_EDGE_CHARACTERS)
165
+ if reason and not reason[0].isspace():
166
+ all_requests.setdefault(
167
+ prefix_match.group(1), reason[:MAXIMUM_DISMISS_REASON_CHARACTERS]
168
+ )
169
+ return all_requests
170
+
171
+
172
+ def _object_without_repeated_keys(all_pairs: list[tuple[str, object]]) -> dict[str, object]:
173
+ all_fields = dict(all_pairs)
174
+ if len(all_fields) != len(all_pairs):
175
+ raise ValueError(JUDGE_ANSWER_REPEATED_KEY_REASON)
176
+ return all_fields
177
+
178
+
179
+ def _refused_constant(constant_name: str) -> object:
180
+ raise ValueError(JUDGE_ANSWER_CONSTANT_REASON)
181
+
182
+
183
+ def _decoded_answer(result_text: str) -> object | None:
184
+ answer_text = result_text.strip()
185
+ fence_match = re.fullmatch(JUDGE_ANSWER_FENCE_PATTERN, answer_text, re.DOTALL)
186
+ if fence_match is not None:
187
+ answer_text = fence_match.group(1)
188
+ try:
189
+ return json.loads(
190
+ answer_text,
191
+ object_pairs_hook=_object_without_repeated_keys,
192
+ parse_constant=_refused_constant,
193
+ )
194
+ except (ValueError, RecursionError):
195
+ return None
196
+
197
+
198
+ def _is_verdict_array(
199
+ decoded_answer: object, all_requested_ids: list[str]
200
+ ) -> TypeGuard[list[dict[str, object]]]:
201
+ return (
202
+ isinstance(decoded_answer, list)
203
+ and bool(decoded_answer)
204
+ and all(
205
+ isinstance(each_entry, dict)
206
+ and set(each_entry) == ALL_JUDGE_ENTRY_KEYS
207
+ and each_entry[JUDGE_ID_KEY] in all_requested_ids
208
+ for each_entry in decoded_answer
209
+ )
210
+ )
211
+
212
+
213
+ def _entry_verdict(all_entry_fields: dict[str, object]) -> JudgeVerdict | None:
214
+ verdict_word = all_entry_fields[JUDGE_VERDICT_KEY]
215
+ reason = all_entry_fields[JUDGE_REASON_KEY]
216
+ if (
217
+ verdict_word in (JUDGE_APPROVE_VERDICT, JUDGE_REJECT_VERDICT)
218
+ and isinstance(reason, str)
219
+ and reason.strip()
220
+ ):
221
+ return JudgeVerdict(
222
+ verdict_word == JUDGE_APPROVE_VERDICT, _encodable_text(reason.strip())
223
+ )
224
+ return None
225
+
226
+
227
+ def _encodable_text(reason: str) -> str:
228
+ return reason.encode(
229
+ JUDGE_REASON_TEXT_ENCODING, JUDGE_REASON_UNENCODABLE_HANDLER
230
+ ).decode(JUDGE_REASON_TEXT_ENCODING)
231
+
232
+
233
+ def judge_verdicts(
234
+ result_text: str, all_requested_ids: list[str]
235
+ ) -> dict[str, JudgeVerdict] | None:
236
+ """Return the judge's verdict for each requested finding its answer covers.
237
+
238
+ Args:
239
+ result_text: The ``result`` text of the judge run.
240
+ all_requested_ids: The finding ids the judge was asked about.
241
+
242
+ Returns:
243
+ The verdicts by finding id. An id the answer names twice gets none. None when
244
+ the whole answer, inside at most one code fence, is not one strict JSON array
245
+ of objects with exactly an id the judge was asked about, a verdict and a
246
+ reason, each named once.
247
+ """
248
+ decoded_answer = _decoded_answer(result_text)
249
+ if not _is_verdict_array(decoded_answer, all_requested_ids):
250
+ return None
251
+ all_entry_counts = Counter(each_entry[JUDGE_ID_KEY] for each_entry in decoded_answer)
252
+ all_verdicts: dict[str, JudgeVerdict] = {}
253
+ for each_entry in decoded_answer:
254
+ entry_id = each_entry[JUDGE_ID_KEY]
255
+ entry_verdict = _entry_verdict(each_entry)
256
+ if (
257
+ isinstance(entry_id, str)
258
+ and entry_verdict is not None
259
+ and all_entry_counts[entry_id] == 1
260
+ ):
261
+ all_verdicts[entry_id] = entry_verdict
262
+ return all_verdicts