Structural Search Skill (Hybrid Edition)
Optimized codebase navigation using both text-based (ripgrep) and syntax-aware (ast-grep) engines. This skill implements the "MassGen" progressive refinement protocol to maximize accuracy and minimize token consumption.
Engines
- Text Engine (grep_search): Best for strings, comments, and literal identifiers.
- Structural Engine (ast-grep): Best for finding function definitions, class hierarchies, and complex patterns (e.g., "find all React components with more than 3 props").
The Hybrid Protocol (Progressive Refinement)
- Count First: Always run a count check if the codebase is large.
- Structural Pattern: Use
$Xas wildcards inast-grepto find logic, not just text. - Scope Limiting: Force
--typeor--langto avoid scanning unrelated binaries. - Token Guard: If results > 50, show only the file paths first.
Usage Examples
- "Find all python functions that return a dictionary:
sg -p 'def $NAME($$$) -> dict: $$$' -l py" - "Search for hardcoded API keys in strings:
grep_search pattern='API_KEY='" - "Locate all classes extending BaseService:
sg -p 'class $CLASS extends BaseService { $$$ }' -l ts"
Hybrid Logic: Ripgrep Speed + AST-Grep Intelligence.