Loading...
Loading...
Use AST parsing and code graph indexing for deep codebase analysis — refactoring, dead-code detection, dependency tracing, impact analysis, and safe symbol renaming
npx skill4agent add rolandbrecht/agent-skills ast-code-graphgrepripgrepsgast-grep| Task | Why AST beats grep |
|---|---|
| Refactoring / renaming | Grep finds the string in comments and strings too; AST finds only the symbol |
| Dead code detection | Grep can't tell if an export is actually imported elsewhere |
| Dependency tracing | "What modules does X depend on?" requires understanding |
| Impact analysis | "If I change function X, what breaks?" needs call-graph traversal |
| Circular dependency detection | Requires building and analyzing a full import graph |
| Code migration | Rewriting deprecated API patterns structurally across a codebase |
| Custom linting | Enforcing project-specific patterns that standard linters don't cover |
grepfindfd$METAVAR# Find all calls to console.log
ast-grep -p 'console.log($MSG)' -l js src/
# Find all require() calls
ast-grep -p 'require($MOD)' -l js src/
# Find all async functions
ast-grep -p 'async function $NAME($$$PARAMS) { $$$BODY }' -l js src/
# Find if-else without braces
ast-grep -p 'if ($COND) $STMT' -l js src/$NAME.$$$ARGS.*$_# Preview replacing var with const
ast-grep -p 'var $NAME = $VALUE' -r 'const $NAME = $VALUE' -l js src/
# Apply interactively (prompts y/n per match)
ast-grep -p 'var $NAME = $VALUE' -r 'const $NAME = $VALUE' -l js --interactive src/# Export list with line numbers
node /home/user/.gemini/antigravity/skills/ast-code-graph/scripts/parse-js.mjs <file> --symbols
# Full JSON AST
node /home/user/.gemini/antigravity/skills/ast-code-graph/scripts/parse-js.mjs <file>python3 /home/user/.gemini/antigravity/skills/ast-code-graph/scripts/build-graph.py <directory> [flags]ast-grep scan --inline-rules '
id: find-unsafe-eval
language: JavaScript
rule:
pattern: eval($CODE)
' src/rules/no-console-log.ymlid: no-console-log
language: JavaScript
severity: warning
message: Remove console.log before committing
rule:
pattern: console.log($$$ARGS)ast-grep scan --rule rules/no-console-log.yml src/allanynothasinsidefollowsprecedesid: await-in-loop
language: JavaScript
rule:
pattern: await $EXPR
inside:
any:
- kind: for_statement
- kind: for_in_statement
- kind: while_statement
stopBy: end--json# Export all function definitions as JSON
ast-grep -p 'function $NAME($$$PARAMS) { $$$BODY }' -l js --json src/
# Export all import statements as JSON
ast-grep -p 'import $$$SPECS from $MOD' -l js --json src/
# Export all require calls as JSON
ast-grep -p 'const $NAME = require($MOD)' -l js --json src/python3 scripts/build-graph.py <dir> --callers <symbol> # find callers
python3 scripts/build-graph.py <dir> --unused # dead code
python3 scripts/build-graph.py <dir> --depends-on <mod> # reverse deps
python3 scripts/build-graph.py <dir> --cycles # circular imports# Replace deprecated API calls
ast-grep -p 'oldApi($ARGS)' -r 'newApi($ARGS)' -l js --interactive src/
# Convert arrow functions to regular functions
ast-grep -p 'const $NAME = ($$$PARAMS) => { $$$BODY }' \
-r 'function $NAME($$$PARAMS) { $$$BODY }' -l js --interactive src/
# Add error handling wrapper
ast-grep -p 'fetch($URL)' -r 'safeFetch($URL)' -l js --interactive src/ast-grep -p '<pattern>' src/--json-r '<rewrite>'--interactive| I want to... | ast-grep command |
|---|---|
Find all calls to | |
| Find function definitions | |
| Find unused imports | |
Rename | |
Convert | |
| Find patterns in JSON output | |
| Run YAML lint rule | |
| Check change impact | Build graph → find all transitive callers (reverse BFS) |