claude-dev-env 8.111.1 → 8.111.3

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.
@@ -18,6 +18,8 @@ from hooks_constants.pr_lifecycle_skill_gate_constants import (
18
18
  ALL_BUILD_EVAL_SKILL_NAMES,
19
19
  ALL_API_ACTION_NAMES,
20
20
  ALL_COMMAND_PREFIX_WORDS,
21
+ ALL_GH_PULL_REQUEST_READ_SUBCOMMANDS,
22
+ ALL_GH_PULL_REQUEST_SUBCOMMANDS,
21
23
  ALL_GITHUB_MCP_TOOL_SUFFIXES,
22
24
  ALL_PIECE_REPLACEMENT_TEXTS,
23
25
  ALL_PREFIX_OPTIONS_WITH_VALUE,
@@ -28,6 +30,9 @@ from hooks_constants.pr_lifecycle_skill_gate_constants import (
28
30
  BUILD_EVAL_ARGUMENT_WORD,
29
31
  BUILD_EVAL_COMMAND_MARKER,
30
32
  COMMAND_PIECE_PATTERN,
33
+ BACKTICK_SUBSTITUTION_GROUP,
34
+ COMMAND_SUBSTITUTION_PATTERN,
35
+ DOLLAR_SUBSTITUTION_GROUP,
31
36
  COMMAND_WHITESPACE,
32
37
  DENY_DECISION,
33
38
  DENY_REASON,
@@ -48,6 +53,10 @@ from hooks_constants.pr_lifecycle_skill_gate_constants import (
48
53
  PATH_SEPARATOR_PATTERN,
49
54
  PERMISSION_DECISION_REASON_KEY,
50
55
  PULL_REQUEST_SCRIPT_NAME,
56
+ ALL_NESTED_PROGRAM_NAMES,
57
+ ALL_NESTED_PROGRAM_WRAPPER_NAMES,
58
+ EVAL_ARGUMENT_SEPARATOR,
59
+ EVAL_PROGRAM_NAME,
51
60
  PYTHON_OPTIONS_WITH_VALUE,
52
61
  REMOVED_TEXT,
53
62
  SEGMENT_BREAK,
@@ -185,10 +194,20 @@ def _is_git_action(all_words: list[str]) -> bool:
185
194
  return action in GIT_ACTIONS
186
195
 
187
196
 
197
+ def _is_pull_request_action(all_gh_words: list[str]) -> bool:
198
+ all_subcommand_words = all_gh_words[1:]
199
+ if not all_subcommand_words:
200
+ return False
201
+ subcommand, *all_later_words = all_subcommand_words
202
+ if subcommand not in ALL_GH_PULL_REQUEST_READ_SUBCOMMANDS:
203
+ return True
204
+ return any(each_word in ALL_GH_PULL_REQUEST_SUBCOMMANDS for each_word in all_later_words)
205
+
206
+
188
207
  def _is_gh_action(all_words: list[str]) -> bool:
189
208
  all_gh_words = gh_command_words(all_words[1:])
190
209
  if all_gh_words[:1] == [GH_PULL_REQUEST_COMMAND]:
191
- return len(all_gh_words) > 1
210
+ return _is_pull_request_action(all_gh_words)
192
211
  if all_gh_words[:1] != [GH_API_COMMAND]:
193
212
  return False
194
213
  all_api_arguments = all_words[all_words.index(GH_API_COMMAND, 1) + 1 :]
@@ -207,7 +226,7 @@ def _words_from_executable(all_words: list[str]) -> list[str]:
207
226
  if re.match(ENVIRONMENT_ASSIGNMENT_PATTERN, each_word):
208
227
  index += 1
209
228
  continue
210
- if each_word not in ALL_COMMAND_PREFIX_WORDS:
229
+ if file_name(each_word) not in ALL_COMMAND_PREFIX_WORDS:
211
230
  return all_words[index:]
212
231
  index += 1
213
232
  while index < len(all_words) and all_words[index].startswith("-"):
@@ -247,12 +266,34 @@ def executable_word_lists(command: str) -> list[list[str]]:
247
266
  all_command_words = _words_from_executable(each_segment)
248
267
  if not all_command_words:
249
268
  continue
250
- all_word_lists.append(all_command_words)
251
- all_word_lists.extend(_wrapped_word_lists(all_command_words))
269
+ all_word_lists.extend(_command_and_nested_word_lists(all_command_words))
270
+ for each_match in COMMAND_SUBSTITUTION_PATTERN.finditer(command):
271
+ inner_command = (
272
+ each_match.group(DOLLAR_SUBSTITUTION_GROUP)
273
+ if each_match.group(DOLLAR_SUBSTITUTION_GROUP) is not None
274
+ else each_match.group(BACKTICK_SUBSTITUTION_GROUP)
275
+ )
276
+ all_word_lists.extend(executable_word_lists(inner_command))
277
+ return all_word_lists
278
+
279
+
280
+ def _command_and_nested_word_lists(all_command_words: list[str]) -> list[list[str]]:
281
+ return [all_command_words, *_wrapped_word_lists(all_command_words), *_nested_program_word_lists(all_command_words)]
282
+
283
+
284
+ def _nested_program_word_lists(all_command_words: list[str]) -> list[list[str]]:
285
+ if file_name(all_command_words[0]) not in ALL_NESTED_PROGRAM_WRAPPER_NAMES:
286
+ return []
287
+ all_word_lists: list[list[str]] = []
288
+ for each_index in range(1, len(all_command_words)):
289
+ if file_name(all_command_words[each_index]) in ALL_NESTED_PROGRAM_NAMES:
290
+ all_word_lists.extend(_command_and_nested_word_lists(all_command_words[each_index:]))
252
291
  return all_word_lists
253
292
 
254
293
 
255
294
  def _wrapped_word_lists(all_command_words: list[str]) -> list[list[str]]:
295
+ if file_name(all_command_words[0]) == EVAL_PROGRAM_NAME:
296
+ return executable_word_lists(EVAL_ARGUMENT_SEPARATOR.join(all_command_words[1:]))
256
297
  if file_name(all_command_words[0]) not in ALL_SHELL_WRAPPER_EXECUTABLES:
257
298
  return []
258
299
  return [
@@ -5,8 +5,14 @@ from pathlib import Path
5
5
  import pytest
6
6
 
7
7
  import chat_reply_gate
8
-
9
- FOUR_SENTENCE_REPLY = "PR one merged. PR two is queued. PR three needs a fix. Nothing else is open."
8
+ from hooks_constants.reply_length_gate_constants import MAXIMUM_SENTENCE_COUNT
9
+
10
+ OVER_LIMIT_SENTENCES = [
11
+ f"Status line {each_number} is ready." for each_number in range(MAXIMUM_SENTENCE_COUNT + 1)
12
+ ]
13
+ OVER_LIMIT_REPLY = " ".join(OVER_LIMIT_SENTENCES)
14
+ FIRST_HELD_BATCH = " ".join(OVER_LIMIT_SENTENCES[: len(OVER_LIMIT_SENTENCES) // 2])
15
+ LAST_HELD_BATCH = " ".join(OVER_LIMIT_SENTENCES[len(OVER_LIMIT_SENTENCES) // 2 :])
10
16
  THREE_SENTENCE_REPLY = "PR one merged. PR two is queued. Nothing else is open."
11
17
  PASSING_DRAFT = "PR one merged. Two others wait."
12
18
 
@@ -46,7 +52,7 @@ def test_should_show_a_passing_draft_in_place_of_a_long_reply(
46
52
  monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
47
53
  ) -> None:
48
54
  monkeypatch.setattr(chat_reply_gate, "ask_drafter", lambda *_args: PASSING_DRAFT)
49
- exit_code, hook_output = run_hook(monkeypatch, capsys, display_input(FOUR_SENTENCE_REPLY))
55
+ exit_code, hook_output = run_hook(monkeypatch, capsys, display_input(OVER_LIMIT_REPLY))
50
56
  assert exit_code == 0
51
57
  assert hook_output == {"hookEventName": "MessageDisplay", "displayContent": PASSING_DRAFT}
52
58
 
@@ -70,16 +76,14 @@ def test_should_hold_batches_until_the_last_one_arrives(
70
76
  lambda reply_text, _violation: all_requests.append(reply_text) or PASSING_DRAFT,
71
77
  )
72
78
  _, first_output = run_hook(
73
- monkeypatch, capsys, display_input("PR one merged. PR two is queued.\n", False)
79
+ monkeypatch, capsys, display_input(FIRST_HELD_BATCH + "\n", False)
74
80
  )
75
81
  _, last_output = run_hook(
76
- monkeypatch, capsys, display_input("PR three needs a fix. Nothing else is open.")
82
+ monkeypatch, capsys, display_input(LAST_HELD_BATCH)
77
83
  )
78
84
  assert first_output == {"hookEventName": "MessageDisplay", "displayContent": ""}
79
85
  assert last_output == {"hookEventName": "MessageDisplay", "displayContent": PASSING_DRAFT}
80
- assert all_requests == [
81
- "PR one merged. PR two is queued.\nPR three needs a fix. Nothing else is open."
82
- ]
86
+ assert all_requests == [FIRST_HELD_BATCH + "\n" + LAST_HELD_BATCH]
83
87
 
84
88
 
85
89
  def test_should_show_the_whole_held_message_when_it_passes(
@@ -100,9 +104,9 @@ def test_should_show_the_original_when_no_draft_passes(
100
104
  monkeypatch.setattr(
101
105
  chat_reply_gate,
102
106
  "ask_drafter",
103
- lambda reply_text, _violation: all_calls.append(reply_text) or FOUR_SENTENCE_REPLY,
107
+ lambda reply_text, _violation: all_calls.append(reply_text) or OVER_LIMIT_REPLY,
104
108
  )
105
- _, hook_output = run_hook(monkeypatch, capsys, display_input(FOUR_SENTENCE_REPLY))
109
+ _, hook_output = run_hook(monkeypatch, capsys, display_input(OVER_LIMIT_REPLY))
106
110
  assert hook_output is None
107
111
  assert len(all_calls) == 2
108
112
 
@@ -111,7 +115,7 @@ def test_should_tell_the_agent_which_draft_the_user_saw(
111
115
  monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
112
116
  ) -> None:
113
117
  monkeypatch.setattr(chat_reply_gate, "ask_drafter", lambda *_args: PASSING_DRAFT)
114
- run_hook(monkeypatch, capsys, display_input(FOUR_SENTENCE_REPLY))
118
+ run_hook(monkeypatch, capsys, display_input(OVER_LIMIT_REPLY))
115
119
  prompt_input = {"hook_event_name": "UserPromptSubmit", "session_id": "abc"}
116
120
  _, first_output = run_hook(monkeypatch, capsys, prompt_input)
117
121
  _, second_output = run_hook(monkeypatch, capsys, prompt_input)
@@ -124,7 +128,7 @@ def test_should_delete_the_shown_draft_at_session_end(
124
128
  monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
125
129
  ) -> None:
126
130
  monkeypatch.setattr(chat_reply_gate, "ask_drafter", lambda *_args: PASSING_DRAFT)
127
- run_hook(monkeypatch, capsys, display_input(FOUR_SENTENCE_REPLY))
131
+ run_hook(monkeypatch, capsys, display_input(OVER_LIMIT_REPLY))
128
132
  shown_draft_path = chat_reply_gate.state_file_path("claude-chat-reply-shown-", "abc")
129
133
  assert shown_draft_path.exists()
130
134
  exit_code, hook_output = run_hook(
@@ -144,14 +148,14 @@ def test_should_add_the_reply_limit_on_each_user_prompt(
144
148
  assert exit_code == 0
145
149
  assert hook_output is not None
146
150
  assert hook_output["hookEventName"] == "UserPromptSubmit"
147
- assert "3 sentences or fewer" in str(hook_output["additionalContext"])
151
+ assert f"{MAXIMUM_SENTENCE_COUNT} sentences or fewer" in str(hook_output["additionalContext"])
148
152
 
149
153
 
150
154
  def test_should_do_nothing_inside_the_drafter_process(
151
155
  monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
152
156
  ) -> None:
153
157
  monkeypatch.setenv("CHAT_REPLY_DRAFTER_ACTIVE", "1")
154
- exit_code, hook_output = run_hook(monkeypatch, capsys, display_input(FOUR_SENTENCE_REPLY))
158
+ exit_code, hook_output = run_hook(monkeypatch, capsys, display_input(OVER_LIMIT_REPLY))
155
159
  assert exit_code == 0
156
160
  assert hook_output is None
157
161
 
@@ -162,7 +166,7 @@ def test_should_ignore_the_stop_event(
162
166
  exit_code, hook_output = run_hook(
163
167
  monkeypatch,
164
168
  capsys,
165
- {"hook_event_name": "Stop", "last_assistant_message": FOUR_SENTENCE_REPLY},
169
+ {"hook_event_name": "Stop", "last_assistant_message": OVER_LIMIT_REPLY},
166
170
  )
167
171
  assert exit_code == 0
168
172
  assert hook_output is None
@@ -179,7 +183,7 @@ def test_ask_drafter_should_read_the_result_field(monkeypatch: pytest.MonkeyPatc
179
183
  "run",
180
184
  lambda command, **_kwargs: all_commands.append(command) or CompletedDrafter(),
181
185
  )
182
- assert chat_reply_gate.ask_drafter(FOUR_SENTENCE_REPLY, "too long") == PASSING_DRAFT
186
+ assert chat_reply_gate.ask_drafter(OVER_LIMIT_REPLY, "too long") == PASSING_DRAFT
183
187
  assert all_commands[0][:4] == ["C:/npm/claude.cmd", "-p", "--model", "haiku"]
184
188
 
185
189
 
@@ -188,14 +192,14 @@ def test_ask_drafter_should_return_none_for_an_error_result(monkeypatch: pytest.
188
192
  stdout = json.dumps({"is_error": True, "result": "Credit balance is too low"})
189
193
 
190
194
  monkeypatch.setattr(chat_reply_gate.subprocess, "run", lambda *_args, **_kwargs: FailedDrafter())
191
- assert chat_reply_gate.ask_drafter(FOUR_SENTENCE_REPLY, "too long") is None
195
+ assert chat_reply_gate.ask_drafter(OVER_LIMIT_REPLY, "too long") is None
192
196
 
193
197
 
194
198
  def test_should_forget_the_shown_draft_when_a_later_reply_passes(
195
199
  monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
196
200
  ) -> None:
197
201
  monkeypatch.setattr(chat_reply_gate, "ask_drafter", lambda *_args: PASSING_DRAFT)
198
- run_hook(monkeypatch, capsys, display_input(FOUR_SENTENCE_REPLY))
202
+ run_hook(monkeypatch, capsys, display_input(OVER_LIMIT_REPLY))
199
203
  run_hook(monkeypatch, capsys, {**display_input(THREE_SENTENCE_REPLY), "message_id": "m2"})
200
204
  _, hook_output = run_hook(monkeypatch, capsys, {"hook_event_name": "UserPromptSubmit", "session_id": "abc"})
201
205
  assert hook_output is not None
@@ -510,3 +510,107 @@ def test_deny_decision_should_carry_the_reason_as_a_deny() -> None:
510
510
  output = gate.deny_decision("Load the skill first.")["hookSpecificOutput"]
511
511
  assert output["permissionDecision"] == "deny"
512
512
  assert output["permissionDecisionReason"] == "Load the skill first."
513
+
514
+
515
+ READ_ONLY_PULL_REQUEST_COMMANDS = (
516
+ "gh pr list",
517
+ "gh pr list --state all",
518
+ "gh pr view 12",
519
+ "gh pr view 12 --web",
520
+ "gh pr checks 12",
521
+ "gh pr diff 12",
522
+ "gh pr status",
523
+ "gh -R jl-cmd-projects/claude-dev-env pr view 12",
524
+ )
525
+ WRITE_PULL_REQUEST_COMMANDS = (
526
+ "gh pr create --title t --body b",
527
+ "gh pr merge 12 --squash",
528
+ "gh pr edit 12 --body b",
529
+ "gh pr comment 12 --body b",
530
+ "gh pr review 12 --approve",
531
+ "gh pr close 12",
532
+ "gh pr ready 12",
533
+ "gh pr frobnicate 12",
534
+ )
535
+
536
+
537
+ def test_read_only_pull_request_commands_should_pass_without_the_skill(tmp_path: Path) -> None:
538
+ path = _transcript(tmp_path)
539
+ for each_command in READ_ONLY_PULL_REQUEST_COMMANDS:
540
+ assert gate.decision_for(_payload(each_command, path)) is None, each_command
541
+
542
+
543
+ def test_read_only_pull_request_command_should_run_silently_without_the_skill(tmp_path: Path) -> None:
544
+ assert _run_main(_payload("gh pr list", _transcript(tmp_path))) == (0, "")
545
+
546
+
547
+ def test_write_pull_request_commands_should_be_denied_without_the_skill(tmp_path: Path) -> None:
548
+ path = _transcript(tmp_path)
549
+ for each_command in WRITE_PULL_REQUEST_COMMANDS:
550
+ _assert_denied(_payload(each_command, path))
551
+
552
+
553
+ OPTION_SHIFTED_WRITE_COMMANDS = (
554
+ "gh pr --subject view merge 12 --squash",
555
+ "gh pr --subject view 12 merge",
556
+ )
557
+
558
+
559
+ def test_write_behind_an_unlisted_option_should_be_denied_without_the_skill(tmp_path: Path) -> None:
560
+ path = _transcript(tmp_path)
561
+ for each_command in OPTION_SHIFTED_WRITE_COMMANDS:
562
+ _assert_denied(_payload(each_command, path))
563
+
564
+
565
+ XARGS_WRITE_COMMANDS = (
566
+ "gh pr view 12 | xargs gh pr merge",
567
+ "echo 12 | xargs -I {} gh pr merge {}",
568
+ "echo 12 | xargs -n 1 -P 4 gh pr merge",
569
+ "echo 12 | xargs -- gh pr merge",
570
+ "echo https://example.test | xargs git push origin HEAD",
571
+ )
572
+ XARGS_READ_COMMANDS = (
573
+ "echo 12 | xargs gh pr view",
574
+ "echo 12 | xargs -I {} gh pr checks {}",
575
+ )
576
+
577
+
578
+ def test_write_run_through_xargs_should_be_denied_without_the_skill(tmp_path: Path) -> None:
579
+ path = _transcript(tmp_path)
580
+ for each_command in XARGS_WRITE_COMMANDS:
581
+ _assert_denied(_payload(each_command, path))
582
+
583
+
584
+ def test_read_only_run_through_xargs_should_pass_without_the_skill(tmp_path: Path) -> None:
585
+ path = _transcript(tmp_path)
586
+ for each_command in XARGS_READ_COMMANDS:
587
+ assert gate.decision_for(_payload(each_command, path)) is None, each_command
588
+
589
+
590
+ WRAPPED_WRITE_COMMANDS = (
591
+ "timeout 10 gh pr merge 12",
592
+ "nice -n 5 gh pr merge 12",
593
+ "find . -maxdepth 1 -exec gh pr merge 12 {} ;",
594
+ "parallel gh pr merge 12 ::: 12",
595
+ 'eval "gh pr merge 12"',
596
+ "eval gh pr merge 12",
597
+ 'eval "gh pr" "merge 12"',
598
+ )
599
+ SUBSTITUTED_AND_GRAPHQL_WRITE_COMMANDS = (
600
+ 'echo "$(gh pr merge 12 --squash)"',
601
+ "echo `gh pr merge 12`",
602
+ "/usr/bin/env gh pr merge 12",
603
+ "gh api graphql -f query='mutation { mergePullRequest(input: {pullRequestId: \"PR_x\"}) { clientMutationId } }'",
604
+ )
605
+
606
+
607
+ def test_substituted_or_graphql_pull_request_write_should_be_denied_without_the_skill(tmp_path: Path) -> None:
608
+ path = _transcript(tmp_path)
609
+ for each_command in SUBSTITUTED_AND_GRAPHQL_WRITE_COMMANDS:
610
+ _assert_denied(_payload(each_command, path))
611
+
612
+
613
+ def test_write_run_through_a_wrapper_should_be_denied_without_the_skill(tmp_path: Path) -> None:
614
+ path = _transcript(tmp_path)
615
+ for each_command in WRAPPED_WRITE_COMMANDS:
616
+ _assert_denied(_payload(each_command, path))
@@ -5,15 +5,25 @@ from pathlib import Path
5
5
  import pytest
6
6
 
7
7
  import reply_length_gate
8
+ from hooks_constants.reply_length_gate_constants import (
9
+ MAXIMUM_SENTENCE_COUNT,
10
+ MAXIMUM_WORDS_PER_SENTENCE,
11
+ )
8
12
 
9
13
  REPLY_TOOL_NAME = "mcp__hearthbot__reply"
10
14
  POST_TOOL_NAME = "mcp__hearthbot__post_message"
11
- SIXTEEN_WORD_SENTENCE = (
12
- "One two three four five six seven eight nine ten eleven twelve thirteen "
13
- "fourteen fifteen sixteen."
15
+ OVER_SENTENCE_LIMIT_TEXT = " ".join(
16
+ f"Status line {each_number} is ready." for each_number in range(MAXIMUM_SENTENCE_COUNT + 1)
17
+ )
18
+ OVER_WORD_LIMIT_SENTENCE = (
19
+ "One two three "
20
+ + " ".join(f"word{each_number}" for each_number in range(3, MAXIMUM_WORDS_PER_SENTENCE + 1))
21
+ + "."
14
22
  )
15
- FIFTEEN_WORD_SENTENCE = (
16
- "One two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen."
23
+ AT_WORD_LIMIT_SENTENCE = (
24
+ "One two three "
25
+ + " ".join(f"word{each_number}" for each_number in range(3, MAXIMUM_WORDS_PER_SENTENCE))
26
+ + "."
17
27
  )
18
28
 
19
29
 
@@ -59,43 +69,43 @@ def test_should_allow_three_short_sentences(
59
69
  assert (exit_code, stderr_text) == (0, "")
60
70
 
61
71
 
62
- def test_should_allow_a_fifteen_word_sentence(
72
+ def test_should_allow_a_sentence_at_the_word_limit(
63
73
  monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
64
74
  ) -> None:
65
- exit_code, _ = run_gate(monkeypatch, capsys, REPLY_TOOL_NAME, {"text": FIFTEEN_WORD_SENTENCE})
75
+ exit_code, _ = run_gate(monkeypatch, capsys, REPLY_TOOL_NAME, {"text": AT_WORD_LIMIT_SENTENCE})
66
76
  assert exit_code == 0
67
77
 
68
78
 
69
- def test_should_deny_four_sentences_and_name_the_count(
79
+ def test_should_deny_too_many_sentences_and_name_the_count(
70
80
  monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
71
81
  ) -> None:
72
82
  exit_code, stderr_text = run_gate(
73
83
  monkeypatch,
74
84
  capsys,
75
85
  REPLY_TOOL_NAME,
76
- {"text": "One. Two. Three. Four."},
86
+ {"text": OVER_SENTENCE_LIMIT_TEXT},
77
87
  )
78
88
  assert exit_code == 2
79
- assert "4 sentences" in stderr_text
80
- assert "3" in stderr_text
89
+ assert f"{MAXIMUM_SENTENCE_COUNT + 1} sentences" in stderr_text
90
+ assert f"limit {MAXIMUM_SENTENCE_COUNT}" in stderr_text
81
91
 
82
92
 
83
- def test_should_deny_a_sixteen_word_sentence_and_name_it(
93
+ def test_should_deny_a_sentence_over_the_word_limit_and_name_it(
84
94
  monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
85
95
  ) -> None:
86
96
  exit_code, stderr_text = run_gate(
87
- monkeypatch, capsys, REPLY_TOOL_NAME, {"text": SIXTEEN_WORD_SENTENCE}
97
+ monkeypatch, capsys, REPLY_TOOL_NAME, {"text": OVER_WORD_LIMIT_SENTENCE}
88
98
  )
89
99
  assert exit_code == 2
90
- assert "16 words" in stderr_text
91
- assert "15" in stderr_text
100
+ assert f"{MAXIMUM_WORDS_PER_SENTENCE + 1} words" in stderr_text
101
+ assert f"limit {MAXIMUM_WORDS_PER_SENTENCE}" in stderr_text
92
102
  assert "One two three" in stderr_text
93
103
 
94
104
 
95
105
  def test_should_check_the_project_chat_post_tool(
96
106
  monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
97
107
  ) -> None:
98
- exit_code, _ = run_gate(monkeypatch, capsys, POST_TOOL_NAME, {"text": "One. Two. Three. Four."})
108
+ exit_code, _ = run_gate(monkeypatch, capsys, POST_TOOL_NAME, {"text": OVER_SENTENCE_LIMIT_TEXT})
99
109
  assert exit_code == 2
100
110
 
101
111
 
@@ -106,10 +116,10 @@ def test_should_count_each_line_of_a_list_as_a_sentence(
106
116
  monkeypatch,
107
117
  capsys,
108
118
  REPLY_TOOL_NAME,
109
- {"text": "Done:\n- first item\n- second item\n- third item"},
119
+ {"text": "\n".join(f"- item {each_number}" for each_number in range(MAXIMUM_SENTENCE_COUNT + 1))},
110
120
  )
111
121
  assert exit_code == 2
112
- assert "4 sentences" in stderr_text
122
+ assert f"{MAXIMUM_SENTENCE_COUNT + 1} sentences" in stderr_text
113
123
 
114
124
 
115
125
  def test_should_not_count_urls_as_words(
@@ -156,7 +166,7 @@ def test_should_not_count_backticked_spans_as_words(
156
166
  def test_should_not_count_fenced_blocks(
157
167
  monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
158
168
  ) -> None:
159
- fenced_block = "```\nOne.\nTwo.\nThree.\nFour.\n" + SIXTEEN_WORD_SENTENCE + "\n```"
169
+ fenced_block = "```\nOne.\nTwo.\nThree.\nFour.\n" + OVER_WORD_LIMIT_SENTENCE + "\n```"
160
170
  exit_code, _ = run_gate(
161
171
  monkeypatch,
162
172
  capsys,
@@ -369,14 +379,14 @@ def short_card(**all_overrides: object) -> dict[str, object]:
369
379
  return card
370
380
 
371
381
 
372
- def test_should_allow_a_card_context_of_two_fifteen_word_sentences(
382
+ def test_should_allow_a_card_context_of_two_sentences_at_the_word_limit(
373
383
  monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
374
384
  ) -> None:
375
385
  exit_code, stderr_text = run_gate(
376
386
  monkeypatch,
377
387
  capsys,
378
388
  DECISION_TOOL_NAME,
379
- short_card(context=" ".join([FIFTEEN_WORD_SENTENCE] * 2)),
389
+ short_card(context=" ".join([AT_WORD_LIMIT_SENTENCE] * 2)),
380
390
  )
381
391
  assert (exit_code, stderr_text) == (0, "")
382
392
 
@@ -439,13 +449,13 @@ def test_should_deny_a_long_card_consequence(
439
449
  DECISION_TOOL_NAME,
440
450
  short_card(
441
451
  options=[
442
- {"label": "Exclude it", "consequence": SIXTEEN_WORD_SENTENCE},
452
+ {"label": "Exclude it", "consequence": OVER_WORD_LIMIT_SENTENCE},
443
453
  {"label": "Leave it", "consequence": "Seven themes keep a warning."},
444
454
  ]
445
455
  ),
446
456
  )
447
457
  assert exit_code == 2
448
- assert "Sentence too long: 16 words, limit 15" in stderr_text
458
+ assert f"Sentence too long: {MAXIMUM_WORDS_PER_SENTENCE + 1} words, limit {MAXIMUM_WORDS_PER_SENTENCE}" in stderr_text
449
459
 
450
460
 
451
461
  @pytest.mark.parametrize("card_field_name", ["question", "reason"])
@@ -456,10 +466,10 @@ def test_should_deny_a_long_sentence_in_the_card_question_and_reason(
456
466
  monkeypatch,
457
467
  capsys,
458
468
  DECISION_TOOL_NAME,
459
- short_card(**{card_field_name: SIXTEEN_WORD_SENTENCE}),
469
+ short_card(**{card_field_name: OVER_WORD_LIMIT_SENTENCE}),
460
470
  )
461
471
  assert exit_code == 2
462
- assert "Sentence too long: 16 words" in stderr_text
472
+ assert f"Sentence too long: {MAXIMUM_WORDS_PER_SENTENCE + 1} words" in stderr_text
463
473
 
464
474
 
465
475
  @pytest.mark.parametrize(
@@ -760,7 +770,7 @@ def test_should_keep_the_length_check_when_the_mode_is_off(
760
770
  monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str], tmp_path: Path
761
771
  ) -> None:
762
772
  turn_mode_off(tmp_path)
763
- exit_code, _ = run_gate(monkeypatch, capsys, REPLY_TOOL_NAME, {"text": "One. Two. Three. Four."})
773
+ exit_code, _ = run_gate(monkeypatch, capsys, REPLY_TOOL_NAME, {"text": OVER_SENTENCE_LIMIT_TEXT})
764
774
  assert exit_code == 2
765
775
 
766
776
 
@@ -1025,7 +1035,7 @@ def test_should_split_prose_sentences_outside_fenced_blocks() -> None:
1025
1035
 
1026
1036
 
1027
1037
  LONG_GITHUB_COMMENT = " ".join(
1028
- "Sentence number one of a long comment that keeps going." for _ in range(50)
1038
+ "Sentence number one of a long comment that keeps going." for _ in range(MAXIMUM_SENTENCE_COUNT + 1)
1029
1039
  )
1030
1040
  SHORT_GITHUB_COMMENT = "Fixed the cap check. The test now covers it. Checks pass."
1031
1041
 
@@ -1037,7 +1047,7 @@ def test_should_deny_long_github_comment(
1037
1047
  monkeypatch, capsys, "mcp__github__add_issue_comment", {"body": LONG_GITHUB_COMMENT}
1038
1048
  )
1039
1049
  assert exit_code == 2
1040
- assert "50 sentences, limit 3" in error_text
1050
+ assert f"{MAXIMUM_SENTENCE_COUNT + 1} sentences, limit {MAXIMUM_SENTENCE_COUNT}" in error_text
1041
1051
 
1042
1052
 
1043
1053
  def test_should_allow_short_github_comment_with_code_and_details(
@@ -1124,13 +1134,13 @@ def test_should_name_every_broken_rule_in_one_refusal(
1124
1134
  monkeypatch,
1125
1135
  capsys,
1126
1136
  POST_TOOL_NAME,
1127
- {"text": f"See PR 7452 and PR 7460.\n{SIXTEEN_WORD_SENTENCE}\nIt failed — again."},
1137
+ {"text": f"See PR 7452 and PR 7460.\n{OVER_WORD_LIMIT_SENTENCE}\nIt failed — again."},
1128
1138
  )
1129
1139
 
1130
1140
  assert exit_code == reply_length_gate.BLOCK_EXIT_CODE
1131
1141
  assert "PR 7452" in error_text
1132
1142
  assert "PR 7460" in error_text
1133
- assert "16 words" in error_text
1143
+ assert f"{MAXIMUM_WORDS_PER_SENTENCE + 1} words" in error_text
1134
1144
  assert reply_length_gate.EM_DASH_MESSAGE in error_text
1135
1145
  assert error_text.endswith(reply_length_gate.FIX_EVERY_ITEM_INSTRUCTION)
1136
1146
 
@@ -1142,16 +1152,16 @@ def test_should_number_nested_violations_once_in_one_refusal(
1142
1152
  monkeypatch,
1143
1153
  capsys,
1144
1154
  POST_TOOL_NAME,
1145
- {"text": f"One.\nTwo.\nThree.\n{SIXTEEN_WORD_SENTENCE}\n{SIXTEEN_WORD_SENTENCE}\nIt failed — again."},
1155
+ {"text": f"{OVER_SENTENCE_LIMIT_TEXT}\n{OVER_WORD_LIMIT_SENTENCE}\n{OVER_WORD_LIMIT_SENTENCE}\nIt failed — again."},
1146
1156
  )
1147
1157
 
1148
1158
  assert exit_code == reply_length_gate.BLOCK_EXIT_CODE
1149
1159
  all_numbered_lines = [each_line for each_line in error_text.splitlines() if each_line[:1].isdigit()]
1150
- assert [each_line.split(". ", 1)[0] for each_line in all_numbered_lines] == ["1", "2", "3", "4"]
1160
+ assert [each_line.split(". ", 1)[0] for each_line in all_numbered_lines] == ["1", "2", "3", "4", "5"]
1151
1161
  assert not any(each_line.split(". ", 1)[1][:1].isdigit() for each_line in all_numbered_lines)
1152
- assert "Reply too long: 6 sentences" in all_numbered_lines[0]
1153
- assert all_numbered_lines[1].count("16 words") == 1
1154
- assert all_numbered_lines[2].count("16 words") == 1
1162
+ assert f"Reply too long: {MAXIMUM_SENTENCE_COUNT + 4} sentences" in all_numbered_lines[0]
1163
+ assert all_numbered_lines[1].count(f"{MAXIMUM_WORDS_PER_SENTENCE + 1} words") == 1
1164
+ assert all_numbered_lines[2].count(f"{MAXIMUM_WORDS_PER_SENTENCE + 1} words") == 1
1155
1165
  assert reply_length_gate.EM_DASH_MESSAGE in all_numbered_lines[3]
1156
1166
 
1157
1167
 
@@ -17,7 +17,7 @@ This family stops a chat reply, edited message, or tool call when its payload br
17
17
  - `blocking/step_note_gate.py` requires a status line before a tool call while its opt-in flag is on.
18
18
  - `blocking/wakeup_cap_gate.py` keeps a self-wakeup inside the 1-hour prompt cache. A wake over the step-down (57 minutes for `send_later` and Routines, 3480 seconds for `ScheduleWakeup`) and at most 60 minutes away runs with its delay rewritten to the step-down. A wake over 60 minutes away, or a cron with more than 57 minutes between wakes, is denied with a reason that says to stack wakes under the cap. A Routine that starts a fresh session on each firing passes.
19
19
  - `blocking/verify_before_acting.py` blocks a completed mutating call when the agent's reasoning contains an unchecked claim.
20
- - `blocking/pr_lifecycle_skill_gate.py` denies a commit, push, pull request action, or merge until the `pr-lifecycle` skill appears in the transcript since the last compaction.
20
+ - `blocking/pr_lifecycle_skill_gate.py` denies a commit, push, pull request action, or merge until the `pr-lifecycle` skill appears in the transcript since the last compaction. Read-only `gh pr` subcommands (`view`, `list`, `checks`, `diff`, `status`) pass without it, unless a later argument names another `gh pr` subcommand.
21
21
  - `blocking/resolve_thread_reply_gate.py` denies a review thread resolve until the agent's own transcript shows a reply on that same thread that posted after the last user prompt and that no successful resolve of the thread has spent. A resolve is a `resolve_review_thread` call, which names the thread by `threadID`; a `pull_request_review_write` call with method `resolve_thread`, which names it by `threadId`; a shell command with a `gh api graphql` `resolveReviewThread` mutation, which names it by a literal `PRRT_` id; or a shell call to `pulls/<n>/ccr/comments/<id>/resolve`, which names it by a comment id. A graphql resolve that names no `PRRT_` id is denied. A reply is an `add_reply_to_pull_request_comment` call, or a `gh api` call to a comment's `replies` endpoint or to `addPullRequestReviewThreadReply`, which names its thread by `PRRT_` id. A reply and a resolve by comment id match when they name the same comment, or when a successful tool result in the transcript, such as `pull_request_read` `get_review_comments`, lists the comment under the thread by its `discussion_r` anchor or `databaseId`. A reply whose result is an error, such as a refusal from `blocking/reply_length_gate.py`, does not count. With no readable transcript, the resolve passes.
22
22
  - `blocking/verify_before_commit_gate.py` denies a `git commit` in a repository with a `.claude/skills/verify` or `.agents/skills/verify` directory until the `verify` skill loads after the last user prompt, through a Skill call whose result comes back without an error, or the `/verify` command in that prompt. It reads the committed paths from the staged diff, the tracked changes for `-a`, and the paths of each `git add` earlier in the same command, and passes a commit whose paths are all docs, images, test files, or `.json`, `.jsonl`, `.yaml`, `.yml`, or `.csv` files under a `docs` folder.
23
23
  - `blocking/build_eval_before_eval_write_gate.py` denies a write to an eval file until a Skill call named exactly `claude-api` with args `build-eval`, or the `/claude-api build-eval` command, appears in the transcript.
@@ -59,13 +59,43 @@ GIT_ACTIONS = frozenset({"commit", "push"})
59
59
  GH_PULL_REQUEST_COMMAND = "pr"
60
60
  GH_API_COMMAND = "api"
61
61
  MERGE_PATH_SUFFIX = "/merge"
62
- ALL_API_ACTION_NAMES = ("auto-merge", "enablePullRequestAutoMerge")
62
+ ALL_API_ACTION_NAMES = ("auto-merge", "enablePullRequestAutoMerge", "mergePullRequest", "createPullRequest")
63
+ COMMAND_SUBSTITUTION_PATTERN = re.compile(r"\$\(([^()]*)\)|`([^`]*)`")
64
+ DOLLAR_SUBSTITUTION_GROUP = 1
65
+ BACKTICK_SUBSTITUTION_GROUP = 2
63
66
  ALL_COMMAND_PREFIX_WORDS = frozenset({"env", "sudo", "command", "exec", "nohup", "time"})
67
+ ALL_GH_PULL_REQUEST_READ_SUBCOMMANDS = frozenset({"checks", "diff", "list", "status", "view"})
68
+ ALL_GH_PULL_REQUEST_SUBCOMMANDS = ALL_GH_PULL_REQUEST_READ_SUBCOMMANDS | frozenset(
69
+ {
70
+ "checkout",
71
+ "close",
72
+ "comment",
73
+ "create",
74
+ "edit",
75
+ "lock",
76
+ "merge",
77
+ "ready",
78
+ "reopen",
79
+ "review",
80
+ "revert",
81
+ "unlock",
82
+ "update-branch",
83
+ }
84
+ )
64
85
  ALL_PREFIX_OPTIONS_WITH_VALUE = frozenset({"-u", "--unset", "-C", "--chdir", "-g", "--group", "--user"})
65
86
  ENVIRONMENT_ASSIGNMENT_PATTERN = r"^[A-Za-z_][A-Za-z0-9_]*="
66
- ALL_SHELL_WRAPPER_EXECUTABLES = frozenset({"bash", "sh", "zsh", "dash", "pwsh", "pwsh.exe", "powershell", "powershell.exe"})
87
+ ALL_SHELL_WRAPPER_EXECUTABLES = frozenset({"bash", "sh", "zsh", "dash", "eval", "pwsh", "pwsh.exe", "powershell", "powershell.exe"})
67
88
  ALL_PYTHON_EXECUTABLES = frozenset({"python", "python3", "python.exe", "python3.exe", "py", "py.exe"})
68
89
  PULL_REQUEST_SCRIPT_NAME = "pull_request.py"
90
+ EVAL_PROGRAM_NAME = "eval"
91
+ EVAL_ARGUMENT_SEPARATOR = " "
92
+ ALL_NESTED_PROGRAM_WRAPPER_NAMES = frozenset({"xargs", "timeout", "nice", "ionice", "stdbuf", "parallel", "watch", "find"})
93
+ ALL_NESTED_PROGRAM_NAMES = (
94
+ frozenset({"gh", "gh.exe", "git", "git.exe", PULL_REQUEST_SCRIPT_NAME})
95
+ | ALL_PYTHON_EXECUTABLES
96
+ | ALL_SHELL_WRAPPER_EXECUTABLES
97
+ | ALL_NESTED_PROGRAM_WRAPPER_NAMES
98
+ )
69
99
  PATH_SEPARATOR_PATTERN = r"[\\/]"
70
100
  PYTHON_OPTIONS_WITH_VALUE = frozenset({"-X", "-W"})
71
101
  ALL_BUILD_EVAL_SKILL_NAMES = ("claude-api",)
@@ -2,8 +2,8 @@
2
2
 
3
3
  import re
4
4
 
5
- MAXIMUM_SENTENCE_COUNT = 3
6
- MAXIMUM_WORDS_PER_SENTENCE = 15
5
+ MAXIMUM_SENTENCE_COUNT = 50
6
+ MAXIMUM_WORDS_PER_SENTENCE = 35
7
7
  ALL_CHECKED_TOOL_NAMES = frozenset(
8
8
  {"mcp__hearthbot__reply", "mcp__hearthbot__post_message", "mcp__hearthbot__update_message"}
9
9
  )
@@ -182,6 +182,6 @@ ALL_GH_BODY_FLAGS = frozenset({"--body", "-b"})
182
182
  GH_BODY_FLAG_PREFIX = "--body="
183
183
  DETAILS_BLOCK_PATTERN = re.compile(r"<details\b.*?</details>", re.IGNORECASE | re.DOTALL)
184
184
  COMMENT_RETRY_INSTRUCTION = (
185
- " A comment on GitHub holds at most three short sentences."
185
+ f" A comment on GitHub holds at most {MAXIMUM_SENTENCE_COUNT} short sentences."
186
186
  " Put detail in the pull request body, a code block, or a collapsed <details> block, then post again."
187
187
  )
@@ -1,8 +1,8 @@
1
1
  from hooks_constants import reply_length_gate_constants as constants
2
2
 
3
3
 
4
- def test_gate_limits_replies_to_three_sentences_of_fifteen_words() -> None:
5
- assert (constants.MAXIMUM_SENTENCE_COUNT, constants.MAXIMUM_WORDS_PER_SENTENCE) == (3, 15)
4
+ def test_gate_limits_replies_to_fifty_sentences_of_thirty_five_words() -> None:
5
+ assert (constants.MAXIMUM_SENTENCE_COUNT, constants.MAXIMUM_WORDS_PER_SENTENCE) == (50, 35)
6
6
 
7
7
 
8
8
  def test_gate_checks_the_three_chat_tools_that_post_to_the_user() -> None:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-dev-env",
3
- "version": "8.111.1",
3
+ "version": "8.111.3",
4
4
  "description": "Claude Code development standards — rules, hooks, agents, commands, and skills",
5
5
  "type": "module",
6
6
  "bin": {
@@ -10,6 +10,10 @@ from pathlib import Path
10
10
  import pytest
11
11
 
12
12
  import durable_post_lint
13
+ from hooks_constants.reply_length_gate_constants import (
14
+ MAXIMUM_SENTENCE_COUNT,
15
+ MAXIMUM_WORDS_PER_SENTENCE,
16
+ )
13
17
  from dev_env_scripts_constants.private_term_constants import PrivateTermDigest
14
18
  from hooks_constants.pull_request_proof_constants import (
15
19
  MISSING_EVAL_SECTION_REASON,
@@ -62,9 +66,8 @@ Ran `python scripts/durable_post_lint.py --action pr-create --body-file body.md`
62
66
  """
63
67
  OVER_LONG_REPLY_BODY = (
64
68
  "Fixed in `abc1234`.\n\n"
65
- "The parser now rejects an empty header.\n\n"
66
- "The test covers both cases.\n\n"
67
- "---\nPosted by the review agent."
69
+ + " ".join(f"Status line {each_number} is ready." for each_number in range(MAXIMUM_SENTENCE_COUNT + 1))
70
+ + "\n\n---\nPosted by the review agent."
68
71
  )
69
72
  MINIMAL_PR_BODY = """## Why
70
73
 
@@ -444,7 +447,7 @@ def should_exit_with_findings_for_a_create_body_with_no_existing_work_section(
444
447
  assert completed_process.stderr == f"{MISSING_EXISTING_WORK_REASON}\n"
445
448
 
446
449
 
447
- def should_report_a_review_reply_over_three_sentences() -> None:
450
+ def should_report_a_review_reply_over_the_sentence_limit() -> None:
448
451
  all_findings = durable_post_lint.lint_durable_post(
449
452
  action="github-mcp-comment",
450
453
  title=None,
@@ -455,13 +458,12 @@ def should_report_a_review_reply_over_three_sentences() -> None:
455
458
  ]
456
459
 
457
460
 
458
- def should_report_a_review_reply_sentence_over_fifteen_words() -> None:
461
+ def should_report_a_review_reply_sentence_over_the_word_limit() -> None:
459
462
  all_findings = durable_post_lint.lint_durable_post(
460
463
  action="github-mcp-comment",
461
464
  title=None,
462
465
  body_text=(
463
- "This change moves the parser into its own module and keeps every"
464
- " caller on the same import path."
466
+ " ".join(f"word{each_number}" for each_number in range(MAXIMUM_WORDS_PER_SENTENCE + 1)) + "."
465
467
  ),
466
468
  )
467
469
  assert [each_finding.code for each_finding in all_findings] == [
@@ -495,7 +497,7 @@ def should_exit_with_findings_for_an_over_long_review_reply(tmp_path: Path) -> N
495
497
  text=True,
496
498
  )
497
499
  assert completed_process.returncode == 1
498
- assert "at most three short sentences" in completed_process.stderr
500
+ assert f"at most {MAXIMUM_SENTENCE_COUNT} short sentences" in completed_process.stderr
499
501
 
500
502
 
501
503
  def should_exit_clean_for_a_short_review_reply(tmp_path: Path) -> None: