Skip to content

Consolidate the Write Guard's Shell Context Scanners Into One Walker #3354

Closed

Description

@ptr727

Context

A design finding from the local review of the backslash-newline narrowing (branch feature/guard-backslash-newline-quoting), declined there because consolidating means changing shared helpers on every tokenizer path of a security hook inside a narrowing change.

Finding

gh-write-guard.py holds several hand-written scanners of bash's quoting and nesting contexts, and the narrowing adds one more, _line_break_contexts. Its inner readers repeat existing ones:

  • its double-quote reader repeats _skip_quote_body
  • its command reader repeats _skip_group with comments=True: paren depth, case counting, a # at a word start, and pending heredocs from _HEREDOC_IN_GROUP
  • its heredoc reader repeats _skip_heredoc_lines and _heredoc_body_end, and adds a rule those lack, that a line ending in an unescaped backslash in an unquoted heredoc joins the next, so the next is not its delimiter
  • its quoted-delimiter test repeats the one in _unquoted_heredoc_bodies

Each copy is a place for the same bash rule to be read two ways, as the heredoc continuation rule already is.

Possible Direction

One context walker over _skip_group and _skip_quote_body, taking an optional visitor that records the context at each index it passes. The skippers keep their return contract, _line_break_contexts becomes a visitor, and the heredoc readers share one body-end rule.

Activity

  1. ptr727 commented on Oct 22, 2026

    @ptr727
    OwnerAuthor

    This issue now also carries the fourth finding of #3358, which #3368 left out on purpose: a quoted span naming git or gh that holds an apostrophe, double quote, backquote, or << is still read as develop reads it, so a pull request body that mentions git in a code span and holds a Markdown hard line break is still denied. Letting such a body through needs a reading of a quoted span that is sound across a further quoting level, which is the single context walker's job. #3358 closes with the promotion of its other three findings.

  2. ptr727 commented on Oct 23, 2026

    @ptr727
    OwnerAuthor

    Closed as out of the write guard's scope under the maintainer's decision (ptr727, 2026-10-23) on #3391, item 1. The guard bounds a good-faith agent's mistake rather than an adversary, so a parse gap reached only by a command shape no agent plausibly types in a coding session is closed rather than fixed, and the guard's own growth is a cost each later review pays again. The scope statement lands in the guard's docstring and README under #3391. Reopen only with a command a session actually produced.

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

    enhancementNew feature or requestscriptA defect in hub tooling

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions