Skip to content

fix(discover): preserve zsh &! disown operator during segmentation and rewrite - #4968

Open
CG-5228 wants to merge 1 commit into
rtk-ai:developfrom
CG-5228:fix/zsh-disown-bang-operator
Open

CG-5228 wants to merge 1 commit into
rtk-ai:developfrom
CG-5228:fix/zsh-disown-bang-operator

Conversation

@CG-5228

@CG-5228 CG-5228 commented Nov 3, 2026

Copy link
Copy Markdown

Summary

Fixes #4918

In zsh, &! (and &|) is a single two-character operator that backgrounds and disowns the preceding pipeline without waiting for it, then continues executing the remainder of the command line.

Previously:

  • rewrite_compound treated & as a standalone single-token boundary and restarted seg_start at the glued !, causing rewrite_segment to prepend ! to the rewritten trailing command and turning git status &!git log into rtk git status & ! rtk git log (which in zsh negates the second pipeline instead of disowning the first, or under &! git log leaves a bare ! that prevents the trailing command from running).
  • lexer::segment similarly started the next segment at the glued ! token, causing split_for_permissions to return "!rm -rf /tmp/example" instead of "rm -rf /tmp/example" and hiding the trailing command from permission rules.

This change detects when a boundary & token is immediately followed by an adjacent ! token (bang.offset == tok.offset + tok.value.len()) in both lexer::segment and registry::rewrite_compound, stepping seg_start past the ! token while preserving &! verbatim in the rewritten output.

Checklist

  • Pre-commit hooks pass (cargo fmt --check, cargo clippy --all-targets, cargo test)
  • Tests added for new functionality
  • Commit message follows conventional commits (fix(scope): ...)
  • Single concern per PR
  • Targeting develop branch (not main)

@CLAassistant

CLAassistant commented Nov 3, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added area:cli bug Something isn't working security zsh labels Nov 3, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Fixes handling of zsh's &! disown operator in the discover lexer and command rewriter so the trailing command after &! is no longer mistakenly treated as starting with a standalone ! token. Previously this caused the rewriter to emit a semantically incorrect & ! sequence and caused the permissions segmenter to hide the trailing command behind a leading !, bypassing deny/ask rules.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4918


Analyzed automatically by wshm · This is an automated analysis, not a human review.

yungSNAT added a commit to yungSNAT/PascalsLetter that referenced this pull request Nov 3, 2026
* fix(permissions): check the command after zsh's &! disown operator

In zsh, 'git status &!git push' backgrounds and disowns the first command and then runs git push, but the permission split read the second segment as '!git push', so a deny or ask rule for git push did not match and the command was allowed. A ! glued to a background & now ends the operator, as zsh reads it; in bash, where '!git' names no command, this only adds a check. Same reading as rtk-ai#4968 for rtk-ai#4918.

* fix(permissions): check both readings of a command after &!

zsh runs the command after the `!` of `&!`; bash runs `!git` as a command
name. Dropping the `!` (the previous commit) let a literal `!git:*` rule be
skipped, so a segment that opens with a `!` glued to a background `&` is now
checked both with and without it. Classification keeps one reading.

Tests add the `!git:*` rule, a quoted command name, a zsh -c wrapper, a
spaced, quoted or escaped `!` or `&`, and the wrapper policy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli bug Something isn't working security zsh

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rewrite re-spells zsh's &! as & !, so under zsh the command after it no longer runs

2 participants