Skip to content

Refuse Brace-Expanded Blanket Adds in the Write Guard and Pin Its Glob-Character Exception #4514

Done

Description

@ptr727

Problem

PR #4511 (for #4462 and #4501, merged as ee90b1d8) added README requirement 11 to host-setup/agent-safety/claude/gh-write-guard.py, the blanket git add and commit -a refusal in any checkout with an origin. Its final local review left two gaps. The maintainer chose to file them rather than hold the merge (2026-11-27).

Findings

  1. Brace expansion passes. git add {.,a.txt} and git commit {-a,-m} x are not read as the blanket forms the shell expands them to. The same shape already passed requirement 6's in-place exemption before Refuse a Blanket Stage in Any Checkout With an Origin and Pin the Rules Read's Host #4511, so this is a lexer gap shared by both requirements.
  2. No selftest pins the glob-character exception. A path holding a glob character passes only where it names an existing file that no other file matches as a glob. Two review passes disagreed on whether git needs that strictness, and the strict form was kept untested.

Declined at the same review, so not owed here: the mkdir-then-add race (#4462's answer), and git commit --mess "fix docs/" read as a directory pathspec, a low-impact false refusal of an abbreviated option.

Constraint

gh-write-guard.py is at 2498 of the 2500 lines tests/test_guard_size.py allows, after #4511 compacted the selftest tables. A fix first makes room by further compaction, or by the sibling-module split the maintainer allowed on #4462 if compaction frees too little. That split changes install.py. The ceiling is not raised.

Done looks like

  • A brace-expanded blanket form is refused under both requirements 6 and 11, with selftest cases.
  • A selftest case pins the glob-character exception either way it is decided.

The file is under host-setup/agent-safety/, so a fix runs attended and its merge waits on the maintainer reading the diff.

Activity

  1. added
    introduced
    on Nov 27, 2026
  2. ptr727 commented on Nov 27, 2026

    @ptr727
    OwnerAuthor

    Added from Copilot's round on promotion #4515 (2026-11-27): gh-write-guard.py around line 1272. A path naming a file literally called :secret, or one wrapped in backticks, reads as literal, so the not lit guard lets it through. It is a variant of item 2's glob and run-time-word handling. Done also looks like a selftest case refusing it, or a recorded reason it is safe.

  3. ptr727 commented on Nov 27, 2026

    @ptr727
    OwnerAuthor

    Added from CodeRabbit's round on promotion #4515 (2026-11-27), deferred here at the maintainer's choice:

    • Nested glob (gh-write-guard.py around line 1269). The singleton-glob exception uses Python's nonrecursive glob, but git's pathspec matches nested paths too. A file literally named src/*.py, beside src/nested/extra.py, passes while git would stage both. This is part of item 2.
    • --dry-run --no-dry-run (around line 1290). It is exempted as a dry run, but the last flag wins, so it stages. The fix is small.
    • The selftest's unquoted temp --git-dir (around line 2098). A temp path holding a space fails the selftest.

    Declined at the same round: a path that does not exist yet being accepted inside a compound command (mkdir generated && ... && git add generated). It is the same class as the mkdir-then-add race declined on #4462, a compound command that changes the tree after the check, which is not the accident the guard exists for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    introduced

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions