@davehardy20/pi-ast-grep-tools

Pi package for structural code search and replace using AST matching via ast-grep.

Packages

Package details

extension

Install @davehardy20/pi-ast-grep-tools from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:@davehardy20/pi-ast-grep-tools
Package
@davehardy20/pi-ast-grep-tools
Version
0.1.0
Published
May 17, 2026
Downloads
103/mo · 7/wk
Author
davehardy20
License
MIT
Types
extension
Size
21 KB
Dependencies
1 dependency · 2 peers
Pi manifest JSON
{
  "extensions": [
    "./src/index.ts"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

@davehardy20/pi-ast-grep-tools

Structural code search and replace for Pi using AST matching via ast-grep.

What it adds

  • ast_grep_search tool — Find code patterns using AST matching. More precise than text search. Supports TypeScript, JavaScript, and TSX.
  • ast_grep_replace tool — Find and replace code patterns using AST matching. Safer than text replace because it respects syntax boundaries. Applies changes to files.
  • /ast-grep-status command — Show package name, version, source path, and supported languages.

Pattern syntax

Pattern syntax is language-specific AST pattern syntax:

  • console.log($A) matches any console.log call
  • function $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-tools

From git:

pi install git:github.com/davehardy20/pi-ast-grep-tools

From a local checkout during development:

pi install /Users/dave/tools/pi-ast-grep-tools

For one run only:

pi -e /Users/dave/tools/pi-ast-grep-tools

Settings

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

  1. Update the package repo
  2. Push to GitHub
  3. Run pi update --extensions or reinstall the package
  4. Run /reload

/reload alone does not fetch newer package commits.

Build and test

npm run typecheck
npm run build
npm test