@kafeg/pi-grep-ast

grep-ast extension for Pi with AST-aware regex context and line-numbered results

Packages

Package details

extension

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

$ pi install npm:@kafeg/pi-grep-ast
Package
@kafeg/pi-grep-ast
Version
0.1.1
Published
Jul 21, 2026
Downloads
235/mo · 235/wk
Author
kafeg
License
MIT
Types
extension
Size
8.7 KB
Dependencies
0 dependencies · 2 peers
Pi manifest JSON
{
  "extensions": [
    "index.ts"
  ]
}

Security note

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

README

@kafeg/pi-grep-ast

Pi package that adds a grep_ast tool backed by Aider-AI/grep-ast.

grep-ast is not ast-grep: it searches by regular expression, then prints AST-aware structural context around matches (functions, methods, classes, loops, etc.) with line numbers. Use it when plain grep finds too little context and ast-grep is too structural for the task.

Based on code-archaeology use, grep_ast works best as a complement to plain grep rather than a complete replacement: use it first to discover entrypoints, classes/functions, dispatch points, and surrounding control flow; use plain grep for exhaustive literal audits such as status codes, exact response helpers, config keys, or all occurrences of one string.

Install

pi install git:github.com/kafeg/pi-grep-ast
# or, after publishing to npm:
pi install npm:@kafeg/pi-grep-ast

The extension expects the Python CLI to be available as grep-ast or gast:

python -m pip install git+https://github.com/Aider-AI/grep-ast.git

Tool

grep_ast

Parameters:

  • pattern — regular expression to search for
  • paths — optional files/directories; defaults to . and respects .gitignore
  • ignoreCase — optional --ignore-case
  • encoding — optional file encoding
  • noGitignore — optional; pass --no-gitignore to include ignored files
  • maxOutputChars — optional truncation limit, default 20000

The tool always passes --line-number so results can be cited as file:line references.

Example requests to Pi:

Use grep_ast to find all uses of fetchUser in src/ and show the surrounding functions/classes.

Use grep_ast to find Python requests.get calls in app/ and show the surrounding functions/classes.

Use grep_ast to map likely HTTP route handlers and dispatch functions. Then use grep to enumerate exact status-code branches.

Development

pi -e ./index.ts

For a quick CLI sanity check outside Pi:

grep-ast --no-color QTimer /path/to/repo/server