agent/skills/tools/sg/SKILL.md
Search and rewrite code with ast-grep (sg) using AST patterns and $VAR meta-variables. Use when finding code patterns or refactoring at scale.
npx skillsauth add knoopx/pi sgInstall 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.
sg)Searches code by AST structure, not text. Patterns must be valid parseable code with $VAR meta-variables for wildcards.
ast-grep run -l ts --pattern 'console.log($X)' src/
ast-grep run --pattern '$FUNC()' agent/extensions/ # Auto-detect language
$VAR — matches a single AST node (uppercase only: $MOD, $_)$$$VAR — matches zero or more nodes (function args, statements)$_VAR — non-capturing (same name can match different content)import { $X } from "$Y" works, bare from $X failsFind re-exports (barrel files):
ast-grep run -l ts --pattern 'export * from "$Y"' ./
ast-grep run -l ts --pattern 'export { $$$X } from "$Y"' ./
Find all imports from a module:
ast-grep run -l ts --pattern 'import { $$$X } from "$MOD"' ./
Find function calls with specific structure:
ast-grep run -l ts --pattern 'console.log($MSG)' ./
ast-grep run -l ts --pattern 'fetch($URL).then($H)' ./
Detect anti-patterns (await inside Promise.all):
ast-grep run -l ts --pattern 'await $X' ./ \
--selector call_expression \
--pattern 'Promise.all($$_)'
--debug-query=ast$VAR (uppercase) for meta-variables; $_VAR for non-capturing--debug-query=ast when patterns fail silentlytools
Inform the user what is happening — skip passive lookups
development
Renders markdown to self-contained HTML with a custom dark stylesheet and opens in browser. Use when previewing markdown documents, generating styled HTML from README or report files.
testing
Programmatic hunk selection for Jujutsu — split, commit, or squash specific hunks without interactive prompts. Use when making partial commits or selective squashes.
content-media
Manage version control with Jujutsu (jj) — no staging area, immediate changes, smart rebasing. Use when navigating history, squashing, or pushing to Git remotes.