home/common/programs/ai/pi-coding-agent/skills/ast-grep/SKILL.md
Guide for writing ast-grep rules for structural code search. Use when searching codebases with AST patterns, finding specific code structures, or performing queries beyond simple text search.
npx skillsauth add megalithic/dotfiles ast-grepInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Translate natural language queries into ast-grep rules for structural code matching.
Save to a temp file for testing.
Use pattern for simple matches, kind + has/inside for complex structures. Always use stopBy: end on relational rules.
id: async-with-await
language: javascript
rule:
kind: function_declaration
has:
pattern: await $EXPR
stopBy: end
See references/rule_reference.md for full rule syntax.
# Inline (quick iteration)
echo "async function test() { await fetch(); }" | ast-grep scan --inline-rules "id: test
language: javascript
rule:
kind: function_declaration
has:
pattern: await \$EXPR
stopBy: end" --stdin
# Rule file (complex rules)
ast-grep scan --rule test_rule.yml test_example.js
Debug with --debug-query=cst to see the AST structure.
# Simple pattern
ast-grep run --pattern 'console.log($ARG)' --lang javascript .
# Complex rule
ast-grep scan --rule my_rule.yml /path/to/project
# Inline rule
ast-grep scan --inline-rules "..." /path/to/project
Use \$VAR (shell interprets $) or wrap in single quotes.
console.log($ARG))all, any, not for logical combinations$VAR (named node), $$VAR (unnamed node), $$$ (zero or more nodes)pattern → kind → add relational → composite--debug-query=cst shows actual AST; --debug-query=pattern shows how ast-grep interprets your patterntesting
Apply Strunk's timeless writing rules to ANY prose humans will read - documentation, commit messages, error messages, explanations, reports, or UI text. Makes your writing clearer, stronger, and more professional.
tools
Web search using DuckDuckGo (free, unlimited). Falls back to pi-web-access extension for content extraction.
tools
Interact with web pages using agent-browser CLI. MUST run 'browser connect 9222' FIRST to use existing browser with authenticated sessions.
tools
Remote control tmux sessions for interactive CLIs (python, gdb, etc.) by sending keystrokes and scraping pane output.