### Ast-grep Tool
**Tool Name**: `ast_grep`
**Tool Description**: Structural code search using AST pattern matching. Matches code structure, not text — eliminates false positives in comments/strings. Use when query is about syntactic shape. For literal text, comment markers, version strings, or non-source files, use `grep` instead.
**Example `ast_grep` usage**: function definitions (`fn name($$$) $$$`), struct/enum definitions (`struct Foo $$$`, `enum Bar $$$`), method calls (`$RECV.method($$$)`), type-qualified paths (`Type::variant`), attributes (`#[allow(dead_code)] $ITEM`), control-flow shapes (`$X.unwrap()`, `match`, `if let`).
**Split mixed searches**: if a query combines code-structure with literal text, run `ast_grep` for structural patterns and `grep` for literals. NEVER fold both into one `grep` alternation.
**Tool Arguments**:
- `pattern`: required, string — AST pattern with `$METAVAR` wildcards (e.g., `$A && $A()`, `console.log($$$)`, `unwrap()`)
- `language`: optional, string — language hint (rust, ts, js, python, go, java, c, cpp). Auto-detected from file extension if omitted
- `path`: optional, string — search root, defaults to cwd, use specific paths if you know them
- `rewrite`: optional, string — replacement pattern (e.g., `$A?.()`). Shows diff preview without modifying files
- `limit`: optional, integer, min: 1, max: 500