Skip to content

fix(ast-grep): only treat first positional as subcommand for filter gate - #4163

Open
Yahiro025 wants to merge 2 commits into
rtk-ai:developfrom
Yahiro025:Yahiro025/fix-ast-grep-path-subcommand-4162
Open

Yahiro025 wants to merge 2 commits into
rtk-ai:developfrom
Yahiro025:Yahiro025/fix-ast-grep-path-subcommand-4162

Conversation

@Yahiro025

@Yahiro025 Yahiro025 commented Sep 21, 2026 •

Copy link
Copy Markdown

Summary

  • Fix rtk ast-grep so a path argument named like a subcommand (test/, scan/, new/, …) no longer disables output filtering on implicit-run invocations.
  • filters_this_invocation now treats only the first free positional as a possible subcommand (matching ast-grep’s own dispatch), instead of using .any() over all positionals.
  • Leaves OTHER_SUBCOMMANDS contents alone (orthogonal to fix(ast-grep): route subcommands by the grammar ast-grep actually has #4150).

Fixes #4162

Test plan

  • Unit tests in src/cmds/system/ast_grep_cmd.rs: implicit-run with later path named test/scan/new still filters; real first-positional subcommands still disable filtering; explicit run with path args still filters
  • cargo test --bin rtk cmds::system::ast_grep_cmd:: (16 passed)
  • cargo fmt --all && cargo clippy --all-targets && cargo test
  • Manual: with ast-grep on PATH, compare rtk ast-grep -p '…' src test vs rtk ast-grep run -p '…' src test (both should be filtered)

Targets develop per CONTRIBUTING.

ast-grep dispatches on the first positional only, so a later path named
like test/scan/new no longer disables filtering for an implicit run.
@CLAassistant

CLAassistant commented Sep 21, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Yahiro025
Yahiro025 force-pushed the Yahiro025/fix-ast-grep-path-subcommand-4162 branch from ebcc031 to 4de52c2 Compare September 21, 2026 02:54
@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added ast-grep bug Something isn't working labels Sep 21, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes ast-grep's implicit-run filter gate so it only inspects the first positional argument to decide whether a real subcommand (test/scan/new/etc.) was invoked, rather than scanning all positionals. Previously, a path argument later on the command line that happened to match a subcommand name (e.g., a directory named 'test') would incorrectly disable output filtering for an implicit run.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4162


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

@Yahiro025

Copy link
Copy Markdown
Author

CLA is signed now (CLA Assistant shows all committers authorized). Ready for review whenever you have a chance.

Reconcile with the grammar tables now read off the ast-grep binary
(rtk-ai#4150). With `-c/--config` the only option that can put a value ahead
of a subcommand, the first free positional is reliably the subcommand
slot, which is the precondition rtk-ai#4162 set for looking at it alone.

- Doc comment: state why checking only the first positional is safe.
- test_a_subcommand_behind_any_flag_is_still_a_subcommand: drop the
  `--color always <sub>` cases. `--color` is a `run` option that
  ast-grep rejects ahead of a subcommand, so it is not a global option
  and the line is not valid ast-grep input.
@openbotgit
openbotgit Bot force-pushed the Yahiro025/fix-ast-grep-path-subcommand-4162 branch from 9a03927 to d1eeb2a Compare November 6, 2026 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ast-grep bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk ast-grep: a directory named after a subcommand disables filtering for the whole implicit-run invocation

2 participants