claude-dev-env 8.111.2 → 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
|
|
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.
|
|
251
|
-
|
|
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 [
|
|
@@ -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))
|
|
@@ -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",)
|