ast-grep
Structural code search and rewrite for BB agents, using ast-grep's AST patterns instead of regex.
Overview
Structural code search for BB agents
Grep finds strings. This finds shapes: every caller of a function, every if whose condition you care about, every matching declaration — and it will not be fooled by the same text sitting inside a comment or a string.
The plugin wraps ast-grep, a tree-sitter based matcher, and registers two agent tools over its CLI. No ast-grep code is copied into the plugin; it is a typed caller.
Tools
bb_ast_search— pass an AST pattern with metavariables, plus a language. Patterns look like ordinary code:console.log($A)matches a call with any argument,if ($COND) { $$$BODY }matches a block of any length. Results come back aspath:line:columnwith the source line, capped at 200 matches, plus a count.bb_ast_rewrite— substitutes the pattern's metavariables into a replacement and rewrites the matches. It is preview-only by default: the tool returns a unified diff and writes nothing. Call it again withapply: trueto write.
The diff is the point
A structural rewrite is precise but not type-aware. It will match the same shape in a place you did not mean. The preview step exists so the agent reads the diff before the tree changes.
Requirements
The ast-grep CLI must be on PATH. Languages cover what ast-grep supports: JavaScript, TypeScript, TSX, Python, Rust, Go, Java, C, C++, Ruby, and more.
Tool names are scoped
bb_ prefixed rather than ast_grep_search: BB registers plugin tools into the same namespace a provider's own extensions see, and Pi ships an ast_grep_search of its own. A duplicate name makes Pi refuse to start and fails the whole thread.
More from prismatic7
More in Code & Reviews 69
Work with repositories, builds, changes, pull requests, issues, and reviews.


