claude-dev-env 8.119.0 → 8.119.2
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/git_hooks_installer.mjs +26 -2
- package/bin/git_hooks_installer.test.mjs +36 -0
- package/bin/install-transaction.mjs +3 -1
- package/bin/install.mjs +12 -8
- package/bin/install.test.mjs +89 -0
- package/bin/install.transaction.test.mjs +34 -0
- package/bin/merge_profile_settings.mjs +3 -2
- package/bin/merge_profile_settings.test.mjs +25 -1
- package/bin/profile-stop-gate.mjs +2 -1
- package/bin/profile-stop-gate.test.mjs +26 -1
- package/bin/write-file-atomically.mjs +148 -0
- package/bin/write-file-atomically.test.mjs +263 -0
- package/hooks/blocking/followup_pr_dedupe.py +71 -13
- package/hooks/blocking/merge_review_gate.py +4 -0
- package/hooks/blocking/merge_review_gate_parts/create_folders.py +6 -2
- package/hooks/blocking/merge_review_gate_parts/open_request.py +40 -15
- package/hooks/blocking/resolve_thread_reply_gate.py +116 -1
- package/hooks/blocking/test_cloud_graphql_gate.py +4 -0
- package/hooks/blocking/test_followup_pr_dedupe.py +99 -0
- package/hooks/blocking/test_gh_global_account_switch_gate.py +4 -0
- package/hooks/blocking/test_headless_claude_broker_gate.py +4 -0
- package/hooks/blocking/test_merge_review_gate.py +133 -0
- package/hooks/blocking/test_python_windows_invocation_gate.py +4 -0
- package/hooks/blocking/test_resolve_thread_reply_gate.py +430 -0
- package/hooks/blocking/tests/test_create_folders.py +7 -0
- package/hooks/blocking/tests/test_open_request.py +21 -0
- package/hooks/features/conduct-gates.md +3 -3
- package/hooks/hooks_constants/followup_pr_dedupe_constants.py +5 -0
- package/hooks/hooks_constants/merge_review_gate_constants.py +5 -0
- package/hooks/hooks_constants/pytest_invocation.py +24 -9
- package/hooks/hooks_constants/resolve_thread_reply_gate_constants.py +21 -1
- package/hooks/hooks_constants/test_pytest_invocation.py +25 -0
- package/hooks/hooks_constants/test_shell_command_mutation.py +11 -0
- package/hooks/hooks_constants/transcript_skill_scan_constants.py +22 -0
- package/hooks/session/test_npx_pele_guidance.py +4 -0
- package/hooks/test_transcript_skill_scan.py +72 -0
- package/hooks/transcript_skill_scan.py +138 -4
- package/hooks/validators/config/security_checks_constants.py +88 -0
- package/hooks/validators/security_checks.py +186 -1
- package/hooks/validators/test_security_checks.py +149 -0
- package/package.json +1 -1
|
@@ -513,3 +513,433 @@ def should_allow_a_review_write_resolve_after_a_reply_on_that_thread(tmp_path: P
|
|
|
513
513
|
def should_leave_a_review_write_that_submits_a_review_alone(tmp_path: Path) -> None:
|
|
514
514
|
transcript_path = _write_transcript(tmp_path, [_prompt("Review the pull request.")])
|
|
515
515
|
assert gate.decision_for(_review_write_payload(transcript_path, "create")) is None
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
REPLY_SCRIPT_COMMAND = (
|
|
519
|
+
f"python .github/ci/review_reply_post.py request --pull 7 --comment-id {FIRST_COMMENT_ID}"
|
|
520
|
+
f" --thread-id {FIRST_THREAD_ID} --body-file reply.md"
|
|
521
|
+
)
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
def _script_reply(tool_use_id: str, command: str = REPLY_SCRIPT_COMMAND, is_background: bool = False) -> str:
|
|
525
|
+
tool_input: dict[str, object] = {"command": command}
|
|
526
|
+
if is_background:
|
|
527
|
+
tool_input["run_in_background"] = True
|
|
528
|
+
return _call(tool_use_id, "Bash", tool_input)
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
def _task_notice(tool_use_id: str, exit_code: int = 0) -> str:
|
|
532
|
+
status = "completed" if exit_code == 0 else "failed"
|
|
533
|
+
text = (
|
|
534
|
+
f"<task-notification>\n<task-id>b1</task-id>\n<tool-use-id>{tool_use_id}</tool-use-id>\n"
|
|
535
|
+
f"<status>{status}</status>\n<summary>Background command {status} (exit code {exit_code})</summary>\n"
|
|
536
|
+
"</task-notification>"
|
|
537
|
+
)
|
|
538
|
+
return json.dumps({"type": "user", "origin": {"kind": "task-notification"}, "message": {"content": text}})
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
def should_allow_a_resolve_after_the_reply_script_posted(tmp_path: Path) -> None:
|
|
542
|
+
transcript_path = _write_transcript(
|
|
543
|
+
tmp_path,
|
|
544
|
+
[
|
|
545
|
+
_prompt("Address the review threads."),
|
|
546
|
+
_script_reply("reply-1"),
|
|
547
|
+
_result("reply-1", text="already posted https://github.com/o/r/pull/7#discussion_r1"),
|
|
548
|
+
],
|
|
549
|
+
)
|
|
550
|
+
assert gate.decision_for(_resolve_payload(transcript_path)) is None
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
def should_allow_a_comment_id_resolve_after_the_reply_script_named_no_thread(tmp_path: Path) -> None:
|
|
554
|
+
command = f"python review_reply_post.py request --pull 7 --comment-id={FIRST_COMMENT_ID} --body-file reply.md"
|
|
555
|
+
transcript_path = _write_transcript(
|
|
556
|
+
tmp_path,
|
|
557
|
+
[_prompt("Address the review threads."), *_threads_read(), _script_reply("reply-1", command), _result("reply-1")],
|
|
558
|
+
)
|
|
559
|
+
assert gate.decision_for(_resolve_payload(transcript_path)) is None
|
|
560
|
+
resolve_command = f"gh api -X POST repos/o/r/pulls/7/ccr/comments/{FIRST_COMMENT_ID}/resolve"
|
|
561
|
+
assert gate.decision_for(_shell_resolve_payload(transcript_path, resolve_command)) is None
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
def should_deny_a_resolve_when_the_reply_script_did_not_post(tmp_path: Path) -> None:
|
|
565
|
+
transcript_path = _write_transcript(
|
|
566
|
+
tmp_path,
|
|
567
|
+
[
|
|
568
|
+
_prompt("Address the review threads."),
|
|
569
|
+
_script_reply("reply-1"),
|
|
570
|
+
_result("reply-1", is_error=True, text="not posted"),
|
|
571
|
+
],
|
|
572
|
+
)
|
|
573
|
+
assert _deny_reason(gate.decision_for(_resolve_payload(transcript_path))) == MISSING_REPLY_REASON
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
def should_deny_a_resolve_of_another_thread_after_the_reply_script(tmp_path: Path) -> None:
|
|
577
|
+
transcript_path = _write_transcript(
|
|
578
|
+
tmp_path,
|
|
579
|
+
[_prompt("Address the review threads."), *_threads_read(), _script_reply("reply-1"), _result("reply-1")],
|
|
580
|
+
)
|
|
581
|
+
decision = gate.decision_for(_resolve_payload(transcript_path, SECOND_THREAD_ID))
|
|
582
|
+
assert _deny_reason(decision) == MISSING_REPLY_REASON
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
def should_deny_a_resolve_after_a_script_call_that_requests_no_reply(tmp_path: Path) -> None:
|
|
586
|
+
all_commands = [
|
|
587
|
+
f"python review_reply_post.py post --request review-reply.json --branch b --sender s # {FIRST_THREAD_ID}",
|
|
588
|
+
f"cat review_reply_post.py; echo request --comment-id {FIRST_COMMENT_ID} {FIRST_THREAD_ID}",
|
|
589
|
+
f"python review_reply_post.py request --help; echo {FIRST_THREAD_ID}",
|
|
590
|
+
]
|
|
591
|
+
for each_command in all_commands:
|
|
592
|
+
transcript_path = _write_transcript(
|
|
593
|
+
tmp_path,
|
|
594
|
+
[_prompt("Address the review threads."), _script_reply("reply-1", each_command), _result("reply-1")],
|
|
595
|
+
)
|
|
596
|
+
assert _deny_reason(gate.decision_for(_resolve_payload(transcript_path))) == MISSING_REPLY_REASON
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
def should_allow_a_resolve_after_a_background_reply_script_exits_zero(tmp_path: Path) -> None:
|
|
600
|
+
transcript_path = _write_transcript(
|
|
601
|
+
tmp_path,
|
|
602
|
+
[
|
|
603
|
+
_prompt("Address the review threads."),
|
|
604
|
+
_script_reply("reply-1", is_background=True),
|
|
605
|
+
_result("reply-1", text="Command running in background with ID: b1"),
|
|
606
|
+
_task_notice("reply-1"),
|
|
607
|
+
],
|
|
608
|
+
)
|
|
609
|
+
assert gate.decision_for(_resolve_payload(transcript_path)) is None
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
def should_deny_a_resolve_while_a_background_reply_script_still_runs(tmp_path: Path) -> None:
|
|
613
|
+
transcript_path = _write_transcript(
|
|
614
|
+
tmp_path,
|
|
615
|
+
[
|
|
616
|
+
_prompt("Address the review threads."),
|
|
617
|
+
_script_reply("reply-1", is_background=True),
|
|
618
|
+
_result("reply-1", text="Command running in background with ID: b1"),
|
|
619
|
+
],
|
|
620
|
+
)
|
|
621
|
+
assert _deny_reason(gate.decision_for(_resolve_payload(transcript_path))) == MISSING_REPLY_REASON
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
def should_deny_a_resolve_after_a_background_reply_script_fails(tmp_path: Path) -> None:
|
|
625
|
+
transcript_path = _write_transcript(
|
|
626
|
+
tmp_path,
|
|
627
|
+
[
|
|
628
|
+
_prompt("Address the review threads."),
|
|
629
|
+
_script_reply("reply-1", is_background=True),
|
|
630
|
+
_result("reply-1", text="Command running in background with ID: b1"),
|
|
631
|
+
_task_notice("reply-1", exit_code=3),
|
|
632
|
+
_task_notice("another-call"),
|
|
633
|
+
],
|
|
634
|
+
)
|
|
635
|
+
assert _deny_reason(gate.decision_for(_resolve_payload(transcript_path))) == MISSING_REPLY_REASON
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
def should_keep_a_posted_reply_across_a_background_task_notice(tmp_path: Path) -> None:
|
|
639
|
+
transcript_path = _write_transcript(
|
|
640
|
+
tmp_path,
|
|
641
|
+
[
|
|
642
|
+
_prompt("Address the review threads."),
|
|
643
|
+
*_threads_read(),
|
|
644
|
+
_reply("reply-1"),
|
|
645
|
+
_result("reply-1"),
|
|
646
|
+
_task_notice("another-call"),
|
|
647
|
+
],
|
|
648
|
+
)
|
|
649
|
+
assert gate.decision_for(_resolve_payload(transcript_path)) is None
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
def should_credit_only_the_thread_the_reply_script_names_as_its_own_argument(tmp_path: Path) -> None:
|
|
653
|
+
command = (
|
|
654
|
+
f"python review_reply_post.py request --pull 7 --comment-id {FIRST_COMMENT_ID}"
|
|
655
|
+
f" --thread-id {FIRST_THREAD_ID} --body-file {SECOND_THREAD_ID}.md"
|
|
656
|
+
)
|
|
657
|
+
transcript_path = _write_transcript(
|
|
658
|
+
tmp_path, [_prompt("Address the review threads."), _script_reply("reply-1", command), _result("reply-1")]
|
|
659
|
+
)
|
|
660
|
+
assert gate.decision_for(_resolve_payload(transcript_path)) is None
|
|
661
|
+
decision = gate.decision_for(_resolve_payload(transcript_path, SECOND_THREAD_ID))
|
|
662
|
+
assert _deny_reason(decision) == MISSING_REPLY_REASON
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
def should_not_count_a_reply_script_call_the_parser_can_read_another_way() -> None:
|
|
666
|
+
plain_call = (
|
|
667
|
+
f"python3 .github/ci/review_reply_post.py request --pull 7 --comment-id {FIRST_COMMENT_ID}"
|
|
668
|
+
f" --thread-id {FIRST_THREAD_ID} --body-file reply.md"
|
|
669
|
+
)
|
|
670
|
+
assert gate.reply_script_targets(plain_call) == (frozenset({FIRST_THREAD_ID}), frozenset({str(FIRST_COMMENT_ID)}))
|
|
671
|
+
assert gate.reply_script_targets(plain_call + " --wait-seconds 30 --supersede") is not None
|
|
672
|
+
assert gate.reply_script_targets("/usr/bin/" + plain_call) is not None
|
|
673
|
+
all_misread_commands = [
|
|
674
|
+
f"{plain_call} --he",
|
|
675
|
+
f"{plain_call} --h",
|
|
676
|
+
f"{plain_call} --hel",
|
|
677
|
+
f"{plain_call} --hel{{p,p}}",
|
|
678
|
+
f"{plain_call} {{--help,--help}}",
|
|
679
|
+
f"{plain_call} --comment {SECOND_COMMENT_ID}",
|
|
680
|
+
f"{plain_call} --comment-i={SECOND_COMMENT_ID}",
|
|
681
|
+
f"{plain_call} --c {SECOND_COMMENT_ID}",
|
|
682
|
+
f"{plain_call} --thread {SECOND_THREAD_ID}",
|
|
683
|
+
f"{plain_call} --thread-i={SECOND_THREAD_ID}",
|
|
684
|
+
f"{plain_call} --comment-id {SECOND_COMMENT_ID}",
|
|
685
|
+
f"{plain_call} --thread-id={SECOND_THREAD_ID}",
|
|
686
|
+
f"{plain_call} --supersede --supersede",
|
|
687
|
+
f"{plain_call} --supersede=1",
|
|
688
|
+
f"{plain_call} --unknown 1",
|
|
689
|
+
f"{plain_call} extra",
|
|
690
|
+
f"{plain_call} --wait-seconds -1",
|
|
691
|
+
f"{plain_call} --wait-seconds",
|
|
692
|
+
f"{plain_call} --wait-seconds=",
|
|
693
|
+
f"{plain_call} --body-file repl?.md",
|
|
694
|
+
f"{plain_call} --body-file ~/reply.md",
|
|
695
|
+
f"{plain_call} --body-file reply[1].md",
|
|
696
|
+
f"{plain_call} --body-file reply\\ one.md",
|
|
697
|
+
"python3 review_reply_post.py request --pull 7 --thread-id not-a-thread --comment-id 9",
|
|
698
|
+
f"./{plain_call}",
|
|
699
|
+
f"bin/{plain_call}",
|
|
700
|
+
"python3 -u review_reply_post.py request --comment-id 9",
|
|
701
|
+
"py -3 review_reply_post.py request --comment-id 9",
|
|
702
|
+
"C:Python312/python.exe review_reply_post.py request --comment-id 9",
|
|
703
|
+
"CD:/Python312/python.exe review_reply_post.py request --comment-id 9",
|
|
704
|
+
".venv/bin/python review_reply_post.py request --comment-id 9",
|
|
705
|
+
"python2 review_reply_post.py request --comment-id 9",
|
|
706
|
+
"python3.12x review_reply_post.py request --comment-id 9",
|
|
707
|
+
"pythonw.exe review_reply_post.py request --comment-id 9",
|
|
708
|
+
"python review_reply_post.py request --comment-id 9 --body-file 'reply (1).md'",
|
|
709
|
+
"uv run review_reply_post.py request --comment-id 9",
|
|
710
|
+
"~/bin/python3 review_reply_post.py request --comment-id 9",
|
|
711
|
+
]
|
|
712
|
+
for each_command in all_misread_commands:
|
|
713
|
+
assert gate.reply_script_targets(each_command) is None, each_command
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
def should_not_count_a_reply_script_whose_exit_code_the_command_can_hide() -> None:
|
|
717
|
+
plain_call = f"python .github/ci/review_reply_post.py request --pull 7 --comment-id {FIRST_COMMENT_ID}"
|
|
718
|
+
assert gate.reply_script_targets(plain_call) is not None
|
|
719
|
+
all_masked_commands = [
|
|
720
|
+
f"{plain_call} || true",
|
|
721
|
+
f"{plain_call}; true",
|
|
722
|
+
f"{plain_call} | cat",
|
|
723
|
+
f"({plain_call}) || true",
|
|
724
|
+
f"{plain_call} &",
|
|
725
|
+
f"{plain_call} > out.txt",
|
|
726
|
+
f"{plain_call}\ntrue",
|
|
727
|
+
f"echo $({plain_call})",
|
|
728
|
+
f"{plain_call} --thread-id $THREAD",
|
|
729
|
+
f"{plain_call} # --comment-id {SECOND_COMMENT_ID}",
|
|
730
|
+
f"{plain_call} --help",
|
|
731
|
+
f"{plain_call} -h",
|
|
732
|
+
f"echo {plain_call}",
|
|
733
|
+
f"env X=1 {plain_call}",
|
|
734
|
+
f"python -c pass review_reply_post.py request --comment-id {FIRST_COMMENT_ID}",
|
|
735
|
+
"python review_reply_post.py request --comment-id abc",
|
|
736
|
+
"python review_reply_post.py request --pull 7",
|
|
737
|
+
f"python review_reply_post.py post --comment-id {FIRST_COMMENT_ID}",
|
|
738
|
+
f"python other_review_reply_post.py request --comment-id {FIRST_COMMENT_ID}",
|
|
739
|
+
f"python review_reply_post.py request --comment-id '{FIRST_COMMENT_ID}",
|
|
740
|
+
]
|
|
741
|
+
for each_command in all_masked_commands:
|
|
742
|
+
assert gate.reply_script_targets(each_command) is None, each_command
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
def should_deny_a_resolve_after_a_masked_reply_script_call(tmp_path: Path) -> None:
|
|
746
|
+
transcript_path = _write_transcript(
|
|
747
|
+
tmp_path,
|
|
748
|
+
[
|
|
749
|
+
_prompt("Address the review threads."),
|
|
750
|
+
_script_reply("reply-1", REPLY_SCRIPT_COMMAND + " || true"),
|
|
751
|
+
_result("reply-1"),
|
|
752
|
+
],
|
|
753
|
+
)
|
|
754
|
+
assert _deny_reason(gate.decision_for(_resolve_payload(transcript_path))) == MISSING_REPLY_REASON
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
def _raw_notice(text: str) -> str:
|
|
758
|
+
return json.dumps({"type": "user", "origin": {"kind": "task-notification"}, "message": {"content": text}})
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
def should_deny_a_resolve_when_a_failed_notice_carries_a_passing_one(tmp_path: Path) -> None:
|
|
762
|
+
passing_block = (
|
|
763
|
+
"<task-notification><tool-use-id>other</tool-use-id><status>completed</status>"
|
|
764
|
+
"<summary>Background command completed (exit code 0)</summary></task-notification>"
|
|
765
|
+
)
|
|
766
|
+
failed_block = (
|
|
767
|
+
"<task-notification><tool-use-id>reply-1</tool-use-id><status>failed</status>"
|
|
768
|
+
"<summary>Background command failed (exit code 3)</summary></task-notification>"
|
|
769
|
+
)
|
|
770
|
+
quoting_summary = (
|
|
771
|
+
"<task-notification><tool-use-id>reply-1</tool-use-id><status>failed</status>"
|
|
772
|
+
'<summary>Background command "post (exit code 0)</summary></task-notification>'
|
|
773
|
+
"<task-notification><tool-use-id>reply-1</tool-use-id><status>completed</status>"
|
|
774
|
+
'<summary>(exit code 0)" failed (exit code 3)</summary></task-notification>'
|
|
775
|
+
)
|
|
776
|
+
quoted_status = (
|
|
777
|
+
"<task-notification><tool-use-id>reply-1</tool-use-id><status>failed</status>"
|
|
778
|
+
'<summary>Background command "<status>completed</status> (exit code 0)" failed (exit code 3)</summary>'
|
|
779
|
+
"</task-notification>"
|
|
780
|
+
)
|
|
781
|
+
for each_text in (passing_block + failed_block, failed_block + passing_block, quoting_summary, quoted_status):
|
|
782
|
+
transcript_path = _write_transcript(
|
|
783
|
+
tmp_path,
|
|
784
|
+
[
|
|
785
|
+
_prompt("Address the review threads."),
|
|
786
|
+
_script_reply("reply-1", is_background=True),
|
|
787
|
+
_result("reply-1", text="Command running in background with ID: b1"),
|
|
788
|
+
_raw_notice(each_text),
|
|
789
|
+
],
|
|
790
|
+
)
|
|
791
|
+
assert _deny_reason(gate.decision_for(_resolve_payload(transcript_path))) == MISSING_REPLY_REASON, each_text
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
BACKGROUND_STARTED_TEXT = "Command running in background with ID: b1"
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
def _queued_command(text: str, origin_kind: str, command_mode: str) -> str:
|
|
798
|
+
return json.dumps(
|
|
799
|
+
{
|
|
800
|
+
"parentUuid": "00000000-0000-4000-8000-000000000001",
|
|
801
|
+
"isSidechain": False,
|
|
802
|
+
"attachment": {
|
|
803
|
+
"type": "queued_command",
|
|
804
|
+
"prompt": text,
|
|
805
|
+
"source_uuid": "00000000-0000-4000-8000-000000000002",
|
|
806
|
+
"delivery_id": "00000000-0000-4000-8000-000000000003",
|
|
807
|
+
"commandMode": command_mode,
|
|
808
|
+
"origin": {"kind": origin_kind},
|
|
809
|
+
"timestamp": "2026-01-01T00:00:00.000Z",
|
|
810
|
+
},
|
|
811
|
+
"type": "attachment",
|
|
812
|
+
"uuid": "00000000-0000-4000-8000-000000000004",
|
|
813
|
+
"timestamp": "2026-01-01T00:00:00.000Z",
|
|
814
|
+
"rendered": [{"content": text}],
|
|
815
|
+
"renderedRole": "system",
|
|
816
|
+
}
|
|
817
|
+
)
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
def _notice_text(tool_use_id: str, status: str = "completed", exit_code: int = 0) -> str:
|
|
821
|
+
return (
|
|
822
|
+
f"<task-notification>\n<task-id>b1</task-id>\n<tool-use-id>{tool_use_id}</tool-use-id>\n"
|
|
823
|
+
f"<output-file>/tmp/b1.output</output-file>\n<status>{status}</status>\n"
|
|
824
|
+
f'<summary>Background command "Post the reply" {status} (exit code {exit_code})</summary>\n'
|
|
825
|
+
"</task-notification>"
|
|
826
|
+
)
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
def _background_reply(run_in_background: object = True) -> list[str]:
|
|
830
|
+
return [
|
|
831
|
+
_call("reply-1", "Bash", {"command": REPLY_SCRIPT_COMMAND, "run_in_background": run_in_background}),
|
|
832
|
+
_result("reply-1", text=BACKGROUND_STARTED_TEXT),
|
|
833
|
+
]
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
def should_allow_a_resolve_after_a_notice_queued_mid_turn_reports_exit_code_zero(tmp_path: Path) -> None:
|
|
837
|
+
all_lines = [_prompt("Address the review threads."), *_background_reply()]
|
|
838
|
+
queued_notice = _queued_command(_notice_text("reply-1"), "task-notification", "task-notification")
|
|
839
|
+
transcript_path = _write_transcript(tmp_path, [*all_lines, queued_notice])
|
|
840
|
+
assert gate.decision_for(_resolve_payload(transcript_path)) is None
|
|
841
|
+
for each_notice_text in (
|
|
842
|
+
_notice_text("reply-1", "failed", 3),
|
|
843
|
+
_notice_text("another-call"),
|
|
844
|
+
_notice_text("another-call") + _notice_text("reply-1", "failed", 3),
|
|
845
|
+
):
|
|
846
|
+
queued_notice = _queued_command(each_notice_text, "task-notification", "task-notification")
|
|
847
|
+
transcript_path = _write_transcript(tmp_path, [*all_lines, queued_notice])
|
|
848
|
+
assert _deny_reason(gate.decision_for(_resolve_payload(transcript_path))) == MISSING_REPLY_REASON
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
def should_deny_a_resolve_after_a_prompt_the_user_queued_mid_turn(tmp_path: Path) -> None:
|
|
852
|
+
all_lines = [_prompt("Address the review threads."), *_threads_read(), _reply("reply-1"), _result("reply-1")]
|
|
853
|
+
transcript_path = _write_transcript(tmp_path, all_lines)
|
|
854
|
+
assert gate.decision_for(_resolve_payload(transcript_path)) is None
|
|
855
|
+
for each_origin_kind in ("human", "peer"):
|
|
856
|
+
queued_prompt = _queued_command("Stop, leave the threads open.", each_origin_kind, "prompt")
|
|
857
|
+
transcript_path = _write_transcript(tmp_path, [*all_lines, queued_prompt])
|
|
858
|
+
assert _deny_reason(gate.decision_for(_resolve_payload(transcript_path))) == MISSING_REPLY_REASON
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
def should_wait_for_the_notice_whatever_truthy_value_the_background_flag_holds(tmp_path: Path) -> None:
|
|
862
|
+
for each_flag in ("true", 1):
|
|
863
|
+
all_lines = [_prompt("Address the review threads."), *_background_reply(each_flag)]
|
|
864
|
+
transcript_path = _write_transcript(tmp_path, all_lines)
|
|
865
|
+
assert _deny_reason(gate.decision_for(_resolve_payload(transcript_path))) == MISSING_REPLY_REASON
|
|
866
|
+
transcript_path = _write_transcript(tmp_path, [*all_lines, _task_notice("reply-1")])
|
|
867
|
+
assert gate.decision_for(_resolve_payload(transcript_path)) is None
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
def should_wait_for_the_notice_when_a_result_says_the_call_moved_to_the_background(tmp_path: Path) -> None:
|
|
871
|
+
for each_result_text in (
|
|
872
|
+
"Command was manually backgrounded by user with ID: b1",
|
|
873
|
+
"partial output\nCommand did not complete within its 120s timeout and was moved to the background (ID: b1).",
|
|
874
|
+
):
|
|
875
|
+
all_lines = [
|
|
876
|
+
_prompt("Address the review threads."),
|
|
877
|
+
_script_reply("reply-1"),
|
|
878
|
+
_result("reply-1", text=each_result_text),
|
|
879
|
+
]
|
|
880
|
+
transcript_path = _write_transcript(tmp_path, all_lines)
|
|
881
|
+
assert _deny_reason(gate.decision_for(_resolve_payload(transcript_path))) == MISSING_REPLY_REASON
|
|
882
|
+
transcript_path = _write_transcript(tmp_path, [*all_lines, _raw_notice(_notice_text("reply-1"))])
|
|
883
|
+
assert gate.decision_for(_resolve_payload(transcript_path)) is None
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
def should_deny_a_resolve_when_a_notice_appends_exit_code_zero_after_a_failure(tmp_path: Path) -> None:
|
|
887
|
+
appended_text = (
|
|
888
|
+
"<task-notification>\n<tool-use-id>reply-1</tool-use-id>\n<status>completed</status>\n"
|
|
889
|
+
'<summary>Background command "d" failed (exit code 3) (exit code 0)</summary>\n</task-notification>'
|
|
890
|
+
)
|
|
891
|
+
transcript_path = _write_transcript(
|
|
892
|
+
tmp_path, [_prompt("Address the review threads."), *_background_reply(), _raw_notice(appended_text)]
|
|
893
|
+
)
|
|
894
|
+
assert _deny_reason(gate.decision_for(_resolve_payload(transcript_path))) == MISSING_REPLY_REASON
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
def should_read_a_versioned_or_exe_launcher_and_a_bare_script_path() -> None:
|
|
898
|
+
all_plain_commands = [
|
|
899
|
+
"python3.12 review_reply_post.py request --comment-id 9",
|
|
900
|
+
"python.exe review_reply_post.py request --comment-id 9",
|
|
901
|
+
"py.exe ci/review_reply_post.py request --comment-id 9",
|
|
902
|
+
"/usr/bin/python3.13 review_reply_post.py request --comment-id 9",
|
|
903
|
+
"/python3 review_reply_post.py request --comment-id 9",
|
|
904
|
+
"C:/Python312/python.exe review_reply_post.py request --comment-id 9",
|
|
905
|
+
"ci/review_reply_post.py request --comment-id 9",
|
|
906
|
+
]
|
|
907
|
+
for each_command in all_plain_commands:
|
|
908
|
+
assert gate.reply_script_targets(each_command) == (frozenset(), frozenset({"9"})), each_command
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
BACKGROUND_WORDS_IN_A_BODY = (
|
|
912
|
+
"Command running in background with ID: b1\nThe job is backgrounded and running in the background."
|
|
913
|
+
)
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
def should_count_a_reply_tool_whose_result_quotes_the_background_words(tmp_path: Path) -> None:
|
|
917
|
+
all_lines = [
|
|
918
|
+
_prompt("Address the review threads."),
|
|
919
|
+
*_threads_read(),
|
|
920
|
+
_reply("reply-1"),
|
|
921
|
+
_result("reply-1", text=BACKGROUND_WORDS_IN_A_BODY),
|
|
922
|
+
]
|
|
923
|
+
assert gate.decision_for(_resolve_payload(_write_transcript(tmp_path, all_lines))) is None
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
def should_spend_the_reply_when_a_resolve_result_quotes_the_background_words(tmp_path: Path) -> None:
|
|
927
|
+
all_lines = [
|
|
928
|
+
_prompt("Address the review threads."),
|
|
929
|
+
*_threads_read(),
|
|
930
|
+
_reply("reply-1"),
|
|
931
|
+
_result("reply-1"),
|
|
932
|
+
_resolve("resolve-1"),
|
|
933
|
+
_result("resolve-1", text=BACKGROUND_WORDS_IN_A_BODY),
|
|
934
|
+
]
|
|
935
|
+
transcript_path = _write_transcript(tmp_path, all_lines)
|
|
936
|
+
assert _deny_reason(gate.decision_for(_resolve_payload(transcript_path))) == MISSING_REPLY_REASON
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
def should_count_a_shell_reply_whose_output_mentions_the_background_mid_line(tmp_path: Path) -> None:
|
|
940
|
+
all_lines = [
|
|
941
|
+
_prompt("Address the review threads."),
|
|
942
|
+
_script_reply("reply-1"),
|
|
943
|
+
_result("reply-1", text="posted: the job is backgrounded and running in the background"),
|
|
944
|
+
]
|
|
945
|
+
assert gate.decision_for(_resolve_payload(_write_transcript(tmp_path, all_lines))) is None
|
|
@@ -288,3 +288,10 @@ def test_should_leave_unread_a_create_past_the_unwrap_depth(command: str) -> Non
|
|
|
288
288
|
def test_should_read_no_create_in_text_past_the_unwrap_depth_that_holds_none() -> None:
|
|
289
289
|
assert _placements("eval " * 18 + "'echo hi'") == []
|
|
290
290
|
|
|
291
|
+
|
|
292
|
+
def test_should_keep_two_creates_apart_when_only_one_names_its_repository_with_a_gh_repo_prefix() -> None:
|
|
293
|
+
command = "gh pr create --repo o/r ; GH_REPO=o/r env -u GH_REPO gh pr create"
|
|
294
|
+
all_command_words = [each_create.all_command_words for each_create in all_placed_creates(command, START)]
|
|
295
|
+
assert len(all_command_words) == 2
|
|
296
|
+
assert all_command_words[1][0] == "GH_REPO=o/r"
|
|
297
|
+
|
|
@@ -532,3 +532,24 @@ def test_should_read_create_words_after_a_separator_inside_a_quoted_value(separa
|
|
|
532
532
|
)
|
|
533
533
|
def test_should_not_read_a_later_quoted_create(command: str) -> None:
|
|
534
534
|
assert "two" not in _branches(command)
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
@pytest.mark.parametrize(
|
|
538
|
+
"command",
|
|
539
|
+
[
|
|
540
|
+
"GH_REPO=other/thing env -u GH_REPO gh pr create --head two",
|
|
541
|
+
"gh pr create --repo other/thing --head two ; GH_REPO=other/thing env -u GH_REPO gh pr create --head two",
|
|
542
|
+
"gh pr create --repo other/thing --head two && GH_REPO=other/thing gh pr create --head two",
|
|
543
|
+
],
|
|
544
|
+
)
|
|
545
|
+
def test_should_add_an_origin_call_for_every_create_a_gh_repo_prefix_names(command: str) -> None:
|
|
546
|
+
payload = {"tool_name": "Bash", "tool_input": {"command": command}, "cwd": MAIN_FLOOR_START}
|
|
547
|
+
all_calls = open_calls_from(payload)
|
|
548
|
+
assert ShellOpenCall(repository=("other", "thing"), branch="two", folder=MAIN_FLOOR_START) in all_calls
|
|
549
|
+
assert ShellOpenCall(repository=None, branch="two", folder=MAIN_FLOOR_START) in all_calls
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
def test_should_add_no_origin_call_for_a_create_that_names_its_own_repository() -> None:
|
|
553
|
+
command = "GH_REPO=a/b gh pr create --repo other/thing --head two"
|
|
554
|
+
payload = {"tool_name": "Bash", "tool_input": {"command": command}, "cwd": MAIN_FLOOR_START}
|
|
555
|
+
assert {each_call.repository for each_call in open_calls_from(payload)} == {("other", "thing")}
|
|
@@ -18,10 +18,10 @@ This family stops a chat reply, edited message, or tool call when its payload br
|
|
|
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. For an `Agent` or `Task` spawn it adds the same quote as an advisory note and does not block.
|
|
20
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. The scan reads the transcript newest line first, so the first load or compaction boundary it meets decides. Every create spelling the shared listing in `blocking/followup_pr_dedupe.py` reads counts as a pull request action. Read-only `gh pr` subcommands (`view`, `list`, `checks`, `diff`, `status`) pass without it, unless a later argument names another `gh pr` subcommand.
|
|
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 does not count. With no readable transcript, the resolve passes.
|
|
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 shell command that is one plain `review_reply_post.py request` call is a reply on the comment its `--comment-id` names and on the thread its `--thread-id` names. The launcher is absent, or is `python`, `python3`, `python3.<n>` or `py`, with or without `.exe`, bare or by an absolute path that starts with `/` or with a drive letter and `:/`. The script's parser accepts any prefix of an option name, so each word after `request` must be `--pull`, `--comment-id`, `--thread-id`, `--body-file` or `--wait-seconds` with a value that starts with no `-`, or the bare `--supersede`, each given once. A command that holds `;`, `&`, `|`, a redirect, a subshell, a substitution, a variable, `#`, a brace, a glob, `~`, `!`, a backslash or a line break is no reply. So a `cd dir &&` prefix, an environment prefix, a launcher option such as `python3 -u` or `py -3`, a launcher by a relative path such as `.venv/bin/python`, `uv run`, a line continuation, a backslash path, a pipe to `tail`, and a quoted value that holds `(`, `[` or `~` all count for nothing; run the plain form. A file of the same name, or a launcher of the same name at an absolute path, that exits 0 without posting still counts. 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 does not count. A background task notice is no user prompt, so a reply before it still counts. A call runs in the background when its `run_in_background` input is truthy, or when it is a `Bash` or `PowerShell` call whose result holds a line that starts `Command running in background with ID:`, `Command was manually backgrounded by user with ID:` or `Command did not complete within`. Those words in the result of any other tool, such as a reply tool that returns the comment body, change nothing. Such a reply counts only once a notice names its tool use id and a completed status before its summary, and ends its summary with `completed (exit code 0)`. The notice is read from a user entry or from a `queued_command` attachment, and a text that holds two notices vouches for no call. Any other `queued_command` attachment, such as a prompt the user sent mid-turn or a message another agent queued, ends the turn as a user prompt does, so a reply before it does not count and the agent replies again before it resolves. 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.
|
|
24
|
-
- `blocking/merge_review_gate.py` denies an agent's merge until a review pass on the merged head reported zero findings, or ruled out every finding and linked the posted rulings. It reads the receipt `scripts/merge_review_receipt.py` writes, requires the merge, auto-merge or merge-queue entry to be pinned to that head, and skips repositories listed in `CLAUDE_MERGE_REVIEW_EXEMPT_REPOSITORIES`. A `gh pr merge` call whose every merge segment carries `--disable-auto` only turns auto-merge off, so it passes. A segment that also carries `--auto`, gives `--auto` or `--disable-auto` an `=` value, joins short flags such as `-sb`, or holds a bare `--` keeps every check. Its deny reason names the review command `CLAUDE_MERGE_REVIEW_COMMAND` sets. The reason tells the agent to run that command for the first three passes and `/code-review low --fix <number>` for each later pass; the gate itself counts no passes. It also denies a pull request open, through a shell create or a `create_pull_request` tool, until a pass recorded as `merge_review_receipt.py <owner/name> open <head> 0` covers the head the pull request opens with. A shell create is any spelling the shared listing in `blocking/followup_pr_dedupe.py` reads: `gh pr create`, `gh pr new`, `gh` with a root `-R` or `--repo` before `pr`, a `GH_REPO=` prefix, and `pull_request.py create` run by any `python`, `python3.x`, `py` or `uv run` launcher, with interpreter options or a path to the script. A command that chains several creates is checked create by create, in command order, and the deny names the first head with no clean pass. Each create reads its repository as gh does: among every `-R`, `--repo`, `--repo=`, `-R=` or clustered `-dR` flag before or after `pr`, the last one decides, and a flag word that is the value of another option, such as `--title --repo=x/y`, is not a flag. `blocking/merge_review_gate_parts/create_options.py` reads each value as gh does: an option that takes a value takes the next word, so `--title -Hx` and `--body -H --title x` name no head, and in a short cluster such as `-bHx` the first letter that takes a value takes the rest of the cluster. With no flag it reads the last `GH_REPO=` prefix, then the origin remote. The first create in a command is also read the way the gate read it before it walked every create: its repository comes from a `--repo` flag or the origin remote, never from a prefix. That reading is the one that covers `GH_REPO=o/r env -u GH_REPO gh pr create`, where gh opens in the origin repository. So a first create behind a `GH_REPO=` prefix needs a clean pass for the prefix repository and for origin, and a create that passes `--repo owner/name` needs one for that repository only. A `GH_REPO+=` append, in a create's own prefix or anywhere else in the command, counts as a set whose value the gate cannot read. When the command sets `GH_REPO` anywhere outside a create's own prefix, through an assignment before another program, such as `GH_REPO=o/r bash -c ...`, or through an `export`, `declare`, `typeset`, `local` or `readonly` word that names `GH_REPO`, each create that names no repository flag and no `GH_REPO=` prefix of its own is denied as unread, and the reason says to pass `--repo owner/name`. The gate does not follow where that value reaches. `blocking/followup_pr_dedupe.py` reads the same condition through the same `sets_gh_repository` helper and refuses such a follow-up create, with a reason that says to name the repository with `--repo`. Each head it names through `-H x`, `-Hx`, `-H=x`, `--head x`, `--head=x` or a cluster of short flags such as `-dHx`, `-dH x` or `-fH=x` gets its own check, also a head a later head flag overrides, as gh reads each one. A create that names no head reads `HEAD`. The first-create reading takes a head only from `-H x`, `--head x` or their `=` forms, so a create that gives its head as `-Hx` is also checked on `HEAD`; name the head with `--head` when the working folder is on another branch. `blocking/merge_review_gate_parts/create_folders.py` walks the command to give each create its folder, and `blocking/merge_review_gate_parts/folder_state.py` holds that folder, whether it is followed, and the `pushd` stack. The walk follows `cd`, `chdir`, `Set-Location`, `pushd` and `popd`, also after `builtin` or `command`; the end of a subshell, back to the folder in effect when that subshell opened, also when nested subshells close together on one line or across line breaks; and `eval`, which changes the folder of its own shell. A create inside `bash -c`, `sh -c` or a command substitution runs in the folder before it, also when a line break inside the script comes before it. A `cd` in a background job stays in that job. The walk does not model a folder change in a pipeline member, a brace group, `if`, `case`, `for`, `while`, `until`, `select` or a function body, a folder change after a redirect, or a folder word anywhere but the program place. Each later create in that scope is denied as unreadable. So is each create after a folder the walk cannot name, such as `cd "$VAR"`, `cd -` or a glob, and each create after a folder change the walk cannot follow, such as `popd` with nothing pushed, in any wrapper. A create in a folder that does not exist gets no git answer and is denied as unreadable. Text nested past 16 levels of `bash -c`, `eval` or substitution that names `gh` and a `create` or `new` word, or names `pull_request.py`, gives one create whose folder is not followed, so it is denied as unread. `blocking/merge_review_gate_parts/quoted_lines.py` cuts the text into lines and words as bash reads its quotes: `\"` inside a double-quoted value does not end the value, an ANSI-C `$'...'` value is one word, and a line break ends a command only outside quotes, subshells and substitutions. So the walk reads no command in a heredoc body or in a quoted option value, such as `--body "a; gh pr create --head x"`, with or without a line break inside it. It does read the script that `bash -c`, `sh -c`, `pwsh -Command`, `eval` or `Invoke-Expression` gets, line breaks included, and each `$(...)` or backtick substitution, also one inside a double-quoted value, such as `--body "$(gh pr create --head x)"`, since bash runs those. It reads no substitution bash does not run: one inside single quotes, such as `--body '$(gh pr create --head x)'` or `echo '$(gh pr create --head x)'`, or one whose `$(` or backtick a backslash escapes, such as `echo \$(gh pr create --head x)`. It reads `eval`'s words joined by spaces, as bash does, so `eval 'gh pr create --body "a b"'` is one create, and it reads the words after the last `)` inside a segment, such as the command of a `case` arm, as a create and as a wrapper. A command whose quotes do not close is read both ways the earlier walk read it, POSIX and raw words, as written and with its quoted line breaks joined. `blocking/merge_review_gate_parts/wrapped_creates.py` reads each wrapped inner text once more in POSIX words and gives a create the walk did not place as one whose folder is not followed; it skips the command itself, each closed text with its line breaks read as spaces, and each text unwrapped from one, so a heredoc body inside `--body "$(cat <<'B' ...)"` runs no command and `bash -c 'gh pr create\nls'` is one create. The gate also keeps the earlier first-create reading: the first `gh pr create` or `pull_request.py create` the raw text spells outside `--title`, `--body` and `--body-file` values, in the folder of the last `cd`, `pushd`, `Set-Location` or `sl` before it, with its first `--repo` and its first `-H` or `--head` given with a space or `=`. That reading is one more check unless a walk check equals it. So these are checked on the head that first create names: `echo gh pr create --head x | bash`; a create in a heredoc fed to `bash` or `.`; and the first create words after `;`, `&&`, `||` or `|` inside a quoted value, such as a `git commit -m` message. Beyond that first-create reading, the gate does not read: a create a shell gets through its input, a here-string, a heredoc, a process substitution such as `bash <(echo ...)` or a script file; a create in a command string that a program other than `bash`, `sh`, `pwsh`, `powershell`, `cmd /c`, `eval`, `Invoke-Expression`, `find -exec`, `xargs` or `Start-Process` runs, such as `zsh -c`, `su -c`, `ssh`, `watch`, `python -c` or a git alias; or a program name that a variable, alias or function holds. These forms are read in part. A `case` arm inside a double-quoted substitution, such as `--body "$(case x in x) gh pr create ;; esac)"`, is cut at the arm's `)`, so its create is not read. An arithmetic `<<` followed by a word, such as `$((1<<x))`, opens a heredoc for the walk, so the lines after it up to a line `x` are not read; the first-create reading still checks the first create in the raw text. A substitution in an unquoted heredoc body fed to a plain command such as `cat` is not walked; the first-create reading checks the first create there with the closing `)` kept in its head, so that head is unreadable and denied. A create in a heredoc fed to `.` or `bash` is checked only through the first-create reading: it reads `--repo` and a `--head` or `-H` given with a space or `=`, checks a `-Hx` or clustered head as `HEAD`, and does not read a create after the first. The words of a quoted option value are not commands, so a create in one is not read and needs no review. Once the gate knows the call opens or merges a pull request, a check that raises denies the call with the fault reason, which names the error type. A payload read that raises is denied the same way for a `create_pull_request`, `merge_pull_request` or `enable_pr_auto_merge` tool, and for a shell command whose text holds the word `gh` and a `create`, `new` or `merge` word anywhere, or names `pull_request.py`. Any other payload read fault goes to the shared helper. A call that opens and merges nothing gets no such deny. An open pass also counts when every finding is ruled out: `merge_review_receipt.py <owner/name> open <head> <count> --ruled-out <count> --rulings <path:line,...>`, with a different `path:line` for each finding, checked against the file at that head when the pass is recorded. A merge pinned to that same head passes on the open receipt only when the pass found zero findings.
|
|
24
|
+
- `blocking/merge_review_gate.py` denies an agent's merge until a review pass on the merged head reported zero findings, or ruled out every finding and linked the posted rulings. It reads the receipt `scripts/merge_review_receipt.py` writes, requires the merge, auto-merge or merge-queue entry to be pinned to that head, and skips repositories listed in `CLAUDE_MERGE_REVIEW_EXEMPT_REPOSITORIES`. A `gh pr merge` call whose every merge segment carries `--disable-auto` only turns auto-merge off, so it passes. A segment that also carries `--auto`, gives `--auto` or `--disable-auto` an `=` value, joins short flags such as `-sb`, or holds a bare `--` keeps every check. Its deny reason names the review command `CLAUDE_MERGE_REVIEW_COMMAND` sets. The reason tells the agent to run that command for the first three passes and `/code-review low --fix <number>` for each later pass; the gate itself counts no passes. It also denies a pull request open, through a shell create or a `create_pull_request` tool, until a pass recorded as `merge_review_receipt.py <owner/name> open <head> 0` covers the head the pull request opens with. A shell create is any spelling the shared listing in `blocking/followup_pr_dedupe.py` reads: `gh pr create`, `gh pr new`, `gh` with a root `-R` or `--repo` before `pr`, a `GH_REPO=` prefix, and `pull_request.py create` run by any `python`, `python3.x`, `py` or `uv run` launcher, with interpreter options or a path to the script. A command that chains several creates is checked create by create, in command order, and the deny names the first head with no clean pass. Each create reads its repository as gh does: among every `-R`, `--repo`, `--repo=`, `-R=` or clustered `-dR` flag before or after `pr`, the last one decides, and a flag word that is the value of another option, such as `--title --repo=x/y`, is not a flag. `blocking/merge_review_gate_parts/create_options.py` reads each value as gh does: an option that takes a value takes the next word, so `--title -Hx` and `--body -H --title x` name no head, and in a short cluster such as `-bHx` the first letter that takes a value takes the rest of the cluster. With no flag it reads the last `GH_REPO=` prefix, then the origin remote. A wrapper such as `env -u GH_REPO`, `env -i` or `sudo` can drop the prefix before gh runs, as in `GH_REPO=o/r env -u GH_REPO gh pr create`, where gh opens in the origin repository. So every create the walk reaches whose repository comes only from a `GH_REPO=` prefix needs a clean pass for the prefix repository and for origin, also when the prefix value names no repository, and its deny for origin says to name the repository with `--repo owner/name` on the create. The walk steps over `env`, `sudo` and `timeout` with their options, and over the launchers `nohup`, `nice`, `stdbuf`, `setsid` and `time` when each launcher option holds its value in the same word or takes a number, as in `stdbuf -o0` or `nice -n 5`. It also reads a create behind `command` or `exec`, as in `command env -u GH_REPO` or `exec nohup env -u GH_REPO`. A create after the first one is not read behind a program the walk does not step over, such as `ionice`, `flock` or `doas`, or behind a launcher option with a separate value that is not a number, such as `stdbuf -o L` or `time -o out.txt`. A create that passes `--repo owner/name` needs a pass for that repository only. Two creates with the same options stay two checks when one has a prefix and the other does not. The first create in a command is also read the way the gate read it before it walked every create: its repository comes from a `--repo` flag or the origin remote, never from a prefix. A `GH_REPO+=` append, in a create's own prefix or anywhere else in the command, counts as a set whose value the gate cannot read. When the command sets `GH_REPO` anywhere outside a create's own prefix, through an assignment before another program, such as `GH_REPO=o/r bash -c ...`, or through an `export`, `declare`, `typeset`, `local` or `readonly` word that names `GH_REPO`, each create that names no repository flag and no `GH_REPO=` prefix of its own is denied as unread, and the reason says to pass `--repo owner/name`. The gate does not follow where that value reaches. `blocking/followup_pr_dedupe.py` reads the same condition through the same `sets_gh_repository` helper and refuses such a follow-up create, with a reason that says to name the repository with `--repo`. For a follow-up create whose repository comes only from a `GH_REPO=` prefix, it reads the open pull requests of the prefix repository and of the origin remote, since a wrapper can drop the prefix; a prefix value that names no repository, such as `GH_REPO=nonsense`, still gets the origin read, and a deny from the origin read opens with the sentence to name the repository with `--repo owner/name`; when the origin remote names no GitHub repository it reads the prefix repository only. A duplicate found in origin that way is refused with a reason that says to name the repository with `--repo owner/name` on the create, and a create that names its repository with its own `--repo` reads that repository only. Each head it names through `-H x`, `-Hx`, `-H=x`, `--head x`, `--head=x` or a cluster of short flags such as `-dHx`, `-dH x` or `-fH=x` gets its own check, also a head a later head flag overrides, as gh reads each one. A create that names no head reads `HEAD`. The first-create reading takes a head only from `-H x`, `--head x` or their `=` forms, so a create that gives its head as `-Hx` is also checked on `HEAD`; name the head with `--head` when the working folder is on another branch. `blocking/merge_review_gate_parts/create_folders.py` walks the command to give each create its folder, and `blocking/merge_review_gate_parts/folder_state.py` holds that folder, whether it is followed, and the `pushd` stack. The walk follows `cd`, `chdir`, `Set-Location`, `pushd` and `popd`, also after `builtin` or `command`; the end of a subshell, back to the folder in effect when that subshell opened, also when nested subshells close together on one line or across line breaks; and `eval`, which changes the folder of its own shell. A create inside `bash -c`, `sh -c` or a command substitution runs in the folder before it, also when a line break inside the script comes before it. A `cd` in a background job stays in that job. The walk does not model a folder change in a pipeline member, a brace group, `if`, `case`, `for`, `while`, `until`, `select` or a function body, a folder change after a redirect, or a folder word anywhere but the program place. Each later create in that scope is denied as unreadable. So is each create after a folder the walk cannot name, such as `cd "$VAR"`, `cd -` or a glob, and each create after a folder change the walk cannot follow, such as `popd` with nothing pushed, in any wrapper. A create in a folder that does not exist gets no git answer and is denied as unreadable. Text nested past 16 levels of `bash -c`, `eval` or substitution that names `gh` and a `create` or `new` word, or names `pull_request.py`, gives one create whose folder is not followed, so it is denied as unread. `blocking/merge_review_gate_parts/quoted_lines.py` cuts the text into lines and words as bash reads its quotes: `\"` inside a double-quoted value does not end the value, an ANSI-C `$'...'` value is one word, and a line break ends a command only outside quotes, subshells and substitutions. So the walk reads no command in a heredoc body or in a quoted option value, such as `--body "a; gh pr create --head x"`, with or without a line break inside it. It does read the script that `bash -c`, `sh -c`, `pwsh -Command`, `eval` or `Invoke-Expression` gets, line breaks included, and each `$(...)` or backtick substitution, also one inside a double-quoted value, such as `--body "$(gh pr create --head x)"`, since bash runs those. It reads no substitution bash does not run: one inside single quotes, such as `--body '$(gh pr create --head x)'` or `echo '$(gh pr create --head x)'`, or one whose `$(` or backtick a backslash escapes, such as `echo \$(gh pr create --head x)`. It reads `eval`'s words joined by spaces, as bash does, so `eval 'gh pr create --body "a b"'` is one create, and it reads the words after the last `)` inside a segment, such as the command of a `case` arm, as a create and as a wrapper. A command whose quotes do not close is read both ways the earlier walk read it, POSIX and raw words, as written and with its quoted line breaks joined. `blocking/merge_review_gate_parts/wrapped_creates.py` reads each wrapped inner text once more in POSIX words and gives a create the walk did not place as one whose folder is not followed; it skips the command itself, each closed text with its line breaks read as spaces, and each text unwrapped from one, so a heredoc body inside `--body "$(cat <<'B' ...)"` runs no command and `bash -c 'gh pr create\nls'` is one create. The gate also keeps the earlier first-create reading: the first `gh pr create` or `pull_request.py create` the raw text spells outside `--title`, `--body` and `--body-file` values, in the folder of the last `cd`, `pushd`, `Set-Location` or `sl` before it, with its first `--repo` and its first `-H` or `--head` given with a space or `=`. That reading is one more check unless a walk check equals it. So these are checked on the head that first create names: `echo gh pr create --head x | bash`; a create in a heredoc fed to `bash` or `.`; and the first create words after `;`, `&&`, `||` or `|` inside a quoted value, such as a `git commit -m` message. Beyond that first-create reading, the gate does not read: a create a shell gets through its input, a here-string, a heredoc, a process substitution such as `bash <(echo ...)` or a script file; a create in a command string that a program other than `bash`, `sh`, `pwsh`, `powershell`, `cmd /c`, `eval`, `Invoke-Expression`, `find -exec`, `xargs` or `Start-Process` runs, such as `zsh -c`, `su -c`, `ssh`, `watch`, `python -c` or a git alias; or a program name that a variable, alias or function holds. These forms are read in part. A `case` arm inside a double-quoted substitution, such as `--body "$(case x in x) gh pr create ;; esac)"`, is cut at the arm's `)`, so its create is not read. An arithmetic `<<` followed by a word, such as `$((1<<x))`, opens a heredoc for the walk, so the lines after it up to a line `x` are not read; the first-create reading still checks the first create in the raw text. A substitution in an unquoted heredoc body fed to a plain command such as `cat` is not walked; the first-create reading checks the first create there with the closing `)` kept in its head, so that head is unreadable and denied. A create in a heredoc fed to `.` or `bash` is checked only through the first-create reading: it reads `--repo` and a `--head` or `-H` given with a space or `=`, checks a `-Hx` or clustered head as `HEAD`, and does not read a create after the first. The words of a quoted option value are not commands, so a create in one is not read and needs no review. Once the gate knows the call opens or merges a pull request, a check that raises denies the call with the fault reason, which names the error type. A payload read that raises is denied the same way for a `create_pull_request`, `merge_pull_request` or `enable_pr_auto_merge` tool, and for a shell command whose text holds the word `gh` and a `create`, `new` or `merge` word anywhere, or names `pull_request.py`. Any other payload read fault goes to the shared helper. A call that opens and merges nothing gets no such deny. An open pass also counts when every finding is ruled out: `merge_review_receipt.py <owner/name> open <head> <count> --ruled-out <count> --rulings <path:line,...>`, with a different `path:line` for each finding, checked against the file at that head when the pass is recorded. A merge pinned to that same head passes on the open receipt only when the pass found zero findings.
|
|
25
25
|
- `blocking/artifact_dark_mode_gate.py` denies an Artifact page publish when the page, inside the publish wrapper, keeps a light body or shows text under 4.5:1 contrast in dark mode. `blocking/artifact_dark_mode_render.cjs` renders the page in headless Chromium for it.
|
|
26
26
|
- `blocking/send_user_file_worktree_root_gate.py` denies a `SendUserFile` call that names a file outside the session's working directory, the `cwd` in the hook payload. The desktop file pane opens a sent file only under that folder and shows "Couldn't find this file" for any other path. The reason lists each outside file and names `<cwd>\.scratch\` as the folder to copy it into.
|
|
27
27
|
- `blocking/question_brief_gate.py` denies an `AskUserQuestion` call when the assistant chat text before it in the same turn runs over 450 words or 15 list or table items. A turn starts at a message the user types, at a result of an earlier question call, or at the first input after an `end_turn` reply or a `stop_hook_summary` entry. A Stop hook that holds the turn adds no input, so the text before a held stop still counts. Each bullet or numbered line is one item, each table row below the header is one item, and lines inside a code fence are not items. The reason names each limit passed and says to shorten the brief or split the question. The gate polls the transcript for up to 3 seconds for its own call and passes when the call never appears. A subagent call, an unreadable payload, and a missing or unreadable transcript, or one that is not a regular file, pass at once. The gate reads only the last 1 MB of the transcript, so a long review followed by more than 1 MB of tool output in the same turn is not seen.
|
|
@@ -76,7 +76,7 @@ Preconditions:
|
|
|
76
76
|
- **Lifecycle skill.** Input is a `git commit` or `gh pr create` command with no `pr-lifecycle` invocation in the transcript. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_pr_lifecycle_skill_gate.py -q`. The adjacent test observes a denial, then a silent allow once the skill or its slash command appears.
|
|
77
77
|
- **Verify before commit.** Input is `git add app.py; git commit -m change` in a temporary repository with `.agents/skills/verify`, and a transcript with no `verify` load after its last prompt. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_verify_before_commit_gate.py -q`. The adjacent test observes a denial, then a silent allow after a `verify` Skill call or a `/verify` prompt. A load before the last prompt still denies. A docs-only commit, a commit of data files under a `docs` folder, a tests-only commit, and a repository with no verify skill pass. A `.py` file under `docs` and a `.json` file outside `docs` still deny.
|
|
78
78
|
- **Eval write.** Input is a Write to `evals/cases.json` with no build-eval call in the transcript. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_build_eval_before_eval_write_gate.py -q`. The adjacent test observes a denial, then an allow once the call appears; a write outside an eval path passes.
|
|
79
|
-
- **Clean review.** Input is a merge with no receipt, a receipt with findings, a merge pinned to a newer head, an unpinned merge, or auto-merge with no head. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_merge_review_gate.py -q`. The adjacent test observes a denial for each; a merge or auto-merge pinned to the clean head and a merge in an exempt repository pass. A `gh pr merge --disable-auto` call passes; a merge chained with it, or one that adds `--disable-auto=false` or `-sb --disable-auto`, is still checked. An open with no clean open receipt at its head is denied; an open reviewed clean at its head, and a merge pinned to that head, pass. An open pass whose every finding has its own `path:line` ruling lets the open through; a merge pinned to that head is denied, since only a zero-finding open pass carries to the merge. An open whose branch neither GitHub nor the working folder holds is denied as unreadable. Two chained creates whose second head has no clean open receipt are denied with the second head named. An open whose reads ran past the shared deadline, or whose git read hit its own timeout, is denied as unreadable, with the sentence that a second run may pass; a git read that fails fast gets no such sentence. Every create spelling is denied when its head has no clean pass. A create whose last repository flag names a repository with no clean pass is denied, however many repository flags come before it. A create that names an unreviewed second head with `-Hx`, a repeated `--head` or `--head=` is denied, and so is one whose short-flag cluster, such as `-dHx`, names an unreviewed head. A flag word that is another option's value, such as `--title --repo=x/y`, `--title -Hx` or `-bHx`, is read as that value. A create with no repository of its own in a command that sets `GH_REPO` elsewhere, through an assignment or `export`, is denied as unread with the `--repo owner/name` sentence, and one that names `--repo` or a `GH_REPO=` prefix is read. A create after a subshell or `popd` reads the starting folder, also after nested subshells close on one line or across line breaks, and `builtin cd` and `command cd` are followed. A create in a `case` arm, also one with a root `-R`, is checked on its head. A create inside a single-quoted or backslash-escaped substitution is not read, and one inside a double-quoted or bare substitution is checked. A create after `cd "$VAR"`, or after a `cd` in a piped brace group, `if`, `case`, a loop, a function body or after a redirect, is denied as unreadable, and so is a create nested past the unwrap depth. The first create the raw text spells is also checked with the earlier first-create reading, which a frozen table of commands pins, so a create fed to `bash` through a pipe or a heredoc is checked on its head. A later create on an unreviewed head is denied after an ANSI-C `$'...'` value, after a line break inside `bash -c`, `sh -c` or `eval`, and after a double-quoted value whose substitution holds a quote character. A later create inside a quoted value, such as `--body "say \"x\" ; gh pr create --head y"`, is not read. A here-string or piped create beyond the first, a create in a command string run by a program the walk does not unwrap, and a program name in a variable or alias are not read. An open or a merge whose check raises is denied with the fault reason, also when the text spells the create or merge in a form the strict pattern misses, and so is an MCP merge whose `pullNumber` overflows.
|
|
79
|
+
- **Clean review.** Input is a merge with no receipt, a receipt with findings, a merge pinned to a newer head, an unpinned merge, or auto-merge with no head. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_merge_review_gate.py -q`. The adjacent test observes a denial for each; a merge or auto-merge pinned to the clean head and a merge in an exempt repository pass. A `gh pr merge --disable-auto` call passes; a merge chained with it, or one that adds `--disable-auto=false` or `-sb --disable-auto`, is still checked. An open with no clean open receipt at its head is denied; an open reviewed clean at its head, and a merge pinned to that head, pass. An open pass whose every finding has its own `path:line` ruling lets the open through; a merge pinned to that head is denied, since only a zero-finding open pass carries to the merge. An open whose branch neither GitHub nor the working folder holds is denied as unreadable. Two chained creates whose second head has no clean open receipt are denied with the second head named. An open whose reads ran past the shared deadline, or whose git read hit its own timeout, is denied as unreadable, with the sentence that a second run may pass; a git read that fails fast gets no such sentence. Every create spelling is denied when its head has no clean pass. A create whose last repository flag names a repository with no clean pass is denied, however many repository flags come before it. A create that names an unreviewed second head with `-Hx`, a repeated `--head` or `--head=` is denied, and so is one whose short-flag cluster, such as `-dHx`, names an unreviewed head. A flag word that is another option's value, such as `--title --repo=x/y`, `--title -Hx` or `-bHx`, is read as that value. A create with no repository of its own in a command that sets `GH_REPO` elsewhere, through an assignment or `export`, is denied as unread with the `--repo owner/name` sentence, and one that names `--repo` or a `GH_REPO=` prefix is read. A first create behind a `GH_REPO=` prefix is denied when origin has no clean pass, also when the prefix repository is exempt or reviewed clean. A later create is denied the same way when the walk reaches it: behind `env`, `sudo` and `timeout` with their options, and behind chains of the launchers `nohup`, `nice`, `stdbuf`, `setsid` and `time` whose options hold their value in the same word or take a number, such as `nice -n 5 env -u GH_REPO stdbuf -o0`. A create after the first one, behind a program the walk does not step over, such as `ionice`, is not read. A create the walk reaches whose prefix value names no repository, such as `GH_REPO=nonsense`, is denied for origin with the `--repo owner/name` sentence. A first create the walk does not reach, such as one behind `stdbuf -o L`, is denied for origin through the first-create reading without that sentence, and a prefixed create after an unprefixed create on the same head is denied on the unprefixed create, also without it. A create that names an exempt repository with its own `--repo` passes. A create after a subshell or `popd` reads the starting folder, also after nested subshells close on one line or across line breaks, and `builtin cd` and `command cd` are followed. A create in a `case` arm, also one with a root `-R`, is checked on its head. A create inside a single-quoted or backslash-escaped substitution is not read, and one inside a double-quoted or bare substitution is checked. A create after `cd "$VAR"`, or after a `cd` in a piped brace group, `if`, `case`, a loop, a function body or after a redirect, is denied as unreadable, and so is a create nested past the unwrap depth. The first create the raw text spells is also checked with the earlier first-create reading, which a frozen table of commands pins, so a create fed to `bash` through a pipe or a heredoc is checked on its head. A later create on an unreviewed head is denied after an ANSI-C `$'...'` value, after a line break inside `bash -c`, `sh -c` or `eval`, and after a double-quoted value whose substitution holds a quote character. A later create inside a quoted value, such as `--body "say \"x\" ; gh pr create --head y"`, is not read. A here-string or piped create beyond the first, a create in a command string run by a program the walk does not unwrap, and a program name in a variable or alias are not read. An open or a merge whose check raises is denied with the fault reason, also when the text spells the create or merge in a form the strict pattern misses, and so is an MCP merge whose `pullNumber` overflows.
|
|
80
80
|
- **Dark mode page.** Input is an Artifact publish of a page that themes `html` but leaves `body` to the publish wrapper. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_artifact_dark_mode_gate.py -q`. The adjacent test observes a denial that names the text and its contrast; a page that themes `body` passes. The render tests skip on a host with no Node Playwright and Chromium.
|
|
81
81
|
- **Sent file root.** Input is a `SendUserFile` call for a file on `Y:\` or in the session scratchpad, with `cwd` set to a worktree. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_send_user_file_worktree_root_gate.py -q`. The adjacent test observes a denial that names the file and `<cwd>\.scratch\`; a file under `<cwd>\.scratch\` passes.
|
|
82
82
|
- **Question brief.** Input is a transcript whose turn posts 451 words or 16 bullets before an `AskUserQuestion` call. Run `python -m pytest packages/claude-dev-env/hooks/blocking/test_question_brief_gate.py -q`. The adjacent test observes exit 2 with a reason that names the limit passed. A list before a held stop still counts. A short brief, text from an earlier turn, fenced lines, a subagent call, and a missing transcript pass.
|
|
@@ -16,6 +16,11 @@ DUPLICATE_FOLLOWUP_REASON_TEMPLATE = (
|
|
|
16
16
|
" ({open_url}). Add this finding to the open follow-up pull request #{open_number}."
|
|
17
17
|
" One combined follow-up pull request per parent pull request."
|
|
18
18
|
)
|
|
19
|
+
PREFIX_ORIGIN_FOLLOWUP_SENTENCE = (
|
|
20
|
+
"Name the repository with `--repo owner/name` on the create instead of a `GH_REPO=` prefix."
|
|
21
|
+
" A wrapper such as `env -u GH_REPO` can drop that prefix before gh runs, so the gate"
|
|
22
|
+
" also reads the origin repository, and there it found this: "
|
|
23
|
+
)
|
|
19
24
|
UNANSWERED_FOLLOWUP_REASON_TEMPLATE = (
|
|
20
25
|
"The gate could not read the open pull requests of {owner}/{repo}: the read timed out"
|
|
21
26
|
" or GitHub answered with a server error. So it cannot tell"
|
|
@@ -263,6 +263,11 @@ NO_CLEAN_OPEN_REVIEW_REASON_TEMPLATE = (
|
|
|
263
263
|
"finding, comma separated>`, each path:line a line this head holds. Then open the pull "
|
|
264
264
|
"request. A merge pinned to {head} accepts an open pass only at zero findings."
|
|
265
265
|
)
|
|
266
|
+
PREFIX_ORIGIN_CHECK_SENTENCE = (
|
|
267
|
+
" This create names its repository only with a `GH_REPO=` prefix, and a wrapper such as "
|
|
268
|
+
"`env -u GH_REPO` can drop that prefix before gh runs, so the gate also checks the origin "
|
|
269
|
+
"repository. Name the repository with `--repo owner/name` on the create instead."
|
|
270
|
+
)
|
|
266
271
|
UNKNOWN_OPEN_TARGET_REASON = (
|
|
267
272
|
"This pull request names no repository or head commit the review gate can read. Check that "
|
|
268
273
|
"the head branch is on GitHub and this session can reach it, or run it from the branch "
|