Skip to content

Expand Stepped and Signed Brace Ranges in the Write Guard - #4596

Merged
ptr727 merged 3 commits into
developfrom
fix/4594-write-guard-brace-steps
Nov 30, 2026
Merged

ptr727 merged 3 commits into
developfrom
fix/4594-write-guard-brace-steps

Conversation

@ptr727

@ptr727 ptr727 commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

Answers a Copilot finding on the promotion PR #4594 against #4592 (issue #4514).

What changed

The write guard's lexer expands unquoted brace ranges as bash does, so a blanket commit hidden in a range is still refused under requirement 11. Two range forms bash accepts were left literal:

  • A stepped alphabetic range. _sequence took ..step only on numeric ranges. Bash runs git commit -{A..z..32} x as git commit -A -a x, and the guard allowed it.
  • A signed integer. Bash takes a leading + on a range's endpoints and step, so git commit -{A..z..+32} x runs the same way. Both patterns now share one signed-integer fragment, _BRACE_INT.

Copilot's own example, git commit -{a..z..2} x, was already denied on develop, since its literal word carries an a. The regression row is deny:git commit -{A..z..+32} x, whose literal has none. With that row in place, the self-test fails on develop and on this branch's first commit, and passes on its head.

Verification

  • _sequence matches GNU bash 5.2 for each of these:
    • {a..e..2}, {e..a..2}, {a..e..-2}, {a..e..0}, {A..z..+32}
    • {+1..3}, {+01..3} (unpadded, as bash does), {1..5..+2}, {-01..1} (padded)
  • gh-write-guard.py --selftest passes, as do tests/test_guard_size.py, tests/test_cli_usage.py and tests/test_pr_review_policy.py. Ruff and mypy are clean.
  • The file stays at its 2500-line ceiling.

Local review

Recorded local-strict-review passes ran at the frontier tier. The pass over 4f73652b raised two findings, both fixed in 15632ee5: the regression row was denied even without the fix, and a leading + still slipped past. The pass over 15632ee5 raised one more, fixed in eab7c6d1: no self-test row reached the signed half of the numeric pattern. The new row deny:4514:git status {+1..65} fails once that half is reverted. The pass over eab7c6d1 found nothing, and it is attested on the head.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of signed numeric and stepped alphabetic brace expansions. Existing expansion limits and numeric ordering behavior are preserved.

ptr727 and others added 2 commits November 30, 2026 14:27
Bash steps an alphabetic range as it steps a numeric one, so
`git commit -{a..z..2} x` runs with `-a`. The guard's lexer left a
stepped alphabetic range literal and let that blanket commit through
requirement 11. It now takes the optional step on both kinds of range.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bash takes a leading + on a range's endpoints and step, so
`git commit -{A..z..+32} x` runs as `git commit -A -a x`. Both range
patterns now share one signed-integer fragment. The regression row now
carries no literal `a` of its own, since the old row was denied even
without the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings November 30, 2026 22:35
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The brace-range parser now accepts explicit signs on numeric values and optional signed steps on alphabetic ranges. Both expansion types remain capped. Self-tests add denial cases for expansions that exceed the cap.

Changes: Brace-range parsing

Layer / File(s) Summary
Parse and test brace ranges
host-setup/agent-safety/claude/gh-write-guard.py
_sequence accepts explicitly signed numeric values and stepped alphabetic ranges. The self-tests add denial cases for over-cap numeric and alphabetic expansions.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • ptr727/ProjectTemplate issue 4514 — The change addresses its stepped alphabetic brace-range case, but does not cover comma-list brace forms or the glob-character exception.

Possibly related PRs

Merge Risk: Minimal · up to eab7c

The change makes the write guard's brace-range parsing stricter so that stepped alphabetic and signed numeric expansions can no longer slip past it. No actionable merge risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title says the PR expands stepped and signed brace ranges in the write guard. The raw summary confirms that alphabetic brace expansions now accept an optional signed integer step, and numeric expa…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title says the PR expands stepped and signed brace ranges in the write guard. The raw summary confirms that alphabetic brace expansions now accept an optional signed integer step, and numeric expansions now accept explicit + signs. The PR objectives describe the same change, so the title matches the main change. It is 57 characters, which is within a reasonable length for a title.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9acbb87 and eab7c6d.

Files selected for processing: 1

  • host-setup/agent-safety/claude/gh-write-guard.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@ptr727

ptr727 commented Nov 30, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 15632ee513aa68e8ac8ae23dda0852ad591c1744, the content this pull request carries at that commit against develop, and it recorded 1 finding.

`git status {+1..65}` expands past the brace cap in bash, so the guard
must read its signed endpoint. The new row fails once the numeric
pattern loses its `+` sign, which no row caught before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ptr727

ptr727 commented Nov 30, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head eab7c6d132ca92164ecd481fbebfc739604c84b5, the content this pull request carries at that commit against develop, and it recorded 0 findings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A test is still needed for signed numeric brace expansion because a regression could bypass the 64-word cap while all existing self-tests continue to pass.

1 open issue
What changed in this PR

This PR closes brace-expansion gaps in the write guard by supporting stepped alphabetic ranges and signed integer range syntax, preventing blanket-operation bypasses.

Changes:

  • Adds a shared signed-integer pattern for numeric and alphabetic range endpoints and steps.
  • Expands stepped alphabetic ranges, including signed steps, while preserving Bash-compatible behavior.
  • Adds a regression case for git commit -{A..z..+32} x.
  • A test-coverage finding remains for the untested signed numeric expansion path.
File Description
host-setup/​agent-safety/​claude/​gh-write-guard.py Extends brace-range parsing for signed and stepped numeric and alphabetic ranges and adds related write-guard self-test coverage.

Review effort: Lite

@codecov

codecov Bot commented Nov 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 16.66667% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.07%. Comparing base (9acbb87) to head (eab7c6d).

Files with missing lines Patch % Lines
host-setup/agent-safety/claude/gh-write-guard.py 16.66% 5 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4596   +/-   ##
========================================
  Coverage    79.07%   79.07%           
========================================
  Files           52       52           
  Lines        17360    17360           
========================================
  Hits         13728    13728           
  Misses        3632     3632           
Flag Coverage Δ
python-3.13 79.07% <16.66%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ptr727

ptr727 commented Nov 30, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@ptr727

ptr727 commented Nov 30, 2026

Copy link
Copy Markdown
Owner Author

/review

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ptr727
ptr727 merged commit 6797d69 into develop Nov 30, 2026
14 checks passed
@ptr727
ptr727 deleted the fix/4594-write-guard-brace-steps branch November 30, 2026 23:28
ptr727 added a commit that referenced this pull request Dec 1, 2026
…Hook-Path Denials (#4594)

## Promoted pull requests

- #4590: Read the attention lists under a fine-grained token. The full
check read still runs first. A token refused `contexts` or `checkSuites`
gets a lean read of the same page and every later one. That read names
failing pull requests from the head's Actions runs and the jobs of each
run's listed attempt, and it records what went unread.
- #4592: Deny a commit or push whose text sets GIT_CONFIG*, HOME, or
XDG_CONFIG_HOME (each can change which hooks run), and read unquoted
bash brace expansion in the guard's lexer so brace-expanded blanket adds
and `commit -a` are refused under requirements 6 and 11.
- #4596: Expand stepped alphabetic and signed brace ranges in the write
guard, as bash does, so `git commit -{A..z..+32} x` is refused as the
blanket commit it runs (fixes a Copilot finding raised on this promotion
against #4592).
- #4597: Show every write-guard denial in the decision-flow diagram, the
brace cap and requirement 11 included, and split one self-test table
through `_rows` (fixes this promotion's local review findings against
#4592).
- #4593: Let `cleanup` remove a worktree holding a populated submodule
once a strict proof shows nothing is lost: every submodule repository
clean, untracked files included, no stash, paused operation, linked
worktree or shallow history, and every commit and tag its refs and HEAD
reflog reach held by its own remote after a fetch. Anything it cannot
show refuses and routes to the maintainer. The clearing lives in
scripts/pr_cleanup_clear.py.
- #4599: Answer the second local review of this promotion. The guard's
docs state its fail-closed behavior without a closed list, one set of
state-changing builtins serves both guard sites, and the attention read
tolerates a check suite's unread `workflowRun` as the review gate does,
marking only the pull request it names.

## Promotion review findings

Copilot raised one finding on head ed0326f, that the lean retry could
hide an unrelated null node. It was declined in its thread with the code
path: the lean re-read tolerates nothing, so a null that persists still
fails the read and exits 1.

Copilot raised three findings on head 9acbb87, all against #4592:

- Stepped alphabetic brace ranges were left literal. This was real, and
#4596 fixed it (`6797d691`). The fix also reads a leading `+` sign as
bash does. Copilot's own example, `-{a..z..2}`, was already denied,
since its literal word carries an `a`, so the regression rows use cases
that `develop` really allowed.
- An empty brace word must be kept. Declined, because bash drops the
empty word: `printf "[%s]" {,--all}` prints `[--all]`.
- The zero-padded self-test fixture was wrong. Declined, because the
fixture creates the directory `01` and the self-test passes.

Copilot's round on head 6797d69 opened on a verdict naming no defect:
that synthetic tests cannot establish live behavior. It was answered
with the live evidence and acknowledged as declined.

A local `frontier` pass against `main` at head 6797d69 raised two
findings against #4592, and #4597 fixed both (`9a5af3f9`). The
decision-flow diagram lacked the brace-cap denial, and requirement 11 as
well, as #4597's own review found. One self-test table was split by hand
rather than through `_rows`.

A second local `frontier` pass against `main` at head 9a5af3f raised
four findings, and #4599 fixed them (`e60890ad`). They were the brace
cap missing from the guard's fail-closed docs, a phrase with no
referent, two drifted lists of state-changing builtins, and a refused
`workflowRun` failing the attention read.

Closes #4584
Closes #4582
Closes #4514
Closes #4583

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants