Assistants search and edit code with regex tools (fs_grep_files, fs_modify_file). A question about code shape, such as "every call to foo that passes a closure", is awkward as a regex, and the same structural edit across many files takes one pattern per variation.
Add two local tools that wrap ast-grep: one that searches by syntax pattern and one that rewrites the matches. Working names: code_search and code_rewrite.
ast-grep keeps no state and covers many languages through tree-sitter grammars. It fits the one-process-per-call local-tool model, and serves the Swift and TypeScript in this repository as well as the Rust.
These tools match syntax, not symbols: $X.iter() matches every .iter() call regardless of receiver type. Semantic symbol lookup and renaming require a language server (code_symbol and code_rename).