@davehardy20/pi-ast-grep-tools
v0.1.0
Published
Pi package for structural code search and replace using AST matching via ast-grep.
Maintainers
Readme
@davehardy20/pi-ast-grep-tools
Structural code search and replace for Pi using AST matching via ast-grep.
What it adds
ast_grep_searchtool — Find code patterns using AST matching. More precise than text search. Supports TypeScript, JavaScript, and TSX.ast_grep_replacetool — Find and replace code patterns using AST matching. Safer than text replace because it respects syntax boundaries. Applies changes to files./ast-grep-statuscommand — Show package name, version, source path, and supported languages.
Pattern syntax
Pattern syntax is language-specific AST pattern syntax:
console.log($A)matches anyconsole.logcallfunction $NAME() { }matches empty function declarations$FUNC($$$ARGS)matches any function call
See the ast-grep pattern guide for full details.
Install
From npm:
pi install npm:@davehardy20/pi-ast-grep-toolsFrom git:
pi install git:github.com/davehardy20/pi-ast-grep-toolsFrom a local checkout during development:
pi install /Users/dave/tools/pi-ast-grep-toolsFor one run only:
pi -e /Users/dave/tools/pi-ast-grep-toolsSettings
No special settings required. The extension auto-detects the target language from file extensions. You can override the language explicitly with the language parameter.
Supported languages: TypeScript, JavaScript, TSX.
Troubleshooting
Run /ast-grep-status to confirm:
- package name
- package version
- loaded source path
If commands appear twice, Pi may be loading both the package and the old local extension. Disable or remove the old local auto-discovered extension (ast-grep-tools.ts in ~/.pi/agent/extensions/) before reload verification.
Update flow
- Update the package repo
- Push to GitHub
- Run
pi update --extensionsor reinstall the package - Run
/reload
/reload alone does not fetch newer package commits.
Build and test
npm run typecheck
npm run build
npm test