packages/opencode-hive/skills/ast-grep/SKILL.md
--- name: ast-grep description: Use ast-grep MCP tools for syntax-aware structural search, AST inspection, rule testing, and structural verification. Triggers: code-shape queries, structural invariants, pattern debugging, AST inspection, and multi-file syntax matching. --- # ast-grep MCP Workflow ## When to use this skill Use this skill when the question depends on code structure rather than plain text. Good fits: - Find all code matching a syntax shape. - Verify a structural invariant acros
npx skillsauth add tctinh/agent-hive packages/opencode-hive/skills/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.
Use this skill when the question depends on code structure rather than plain text.
Good fits:
Do not use ast-grep as the default repo navigation tool when cymbal can answer the question more directly.
This local setup uses the official ast-grep/ast-grep-mcp server. Do not assume extra MCP tools exist beyond the four tools below.
ast_grep_dump_syntax_tree
format: cst shows concrete syntax.format: ast shows named syntax nodes.format: pattern shows how ast-grep interprets your search pattern.ast_grep_test_match_code_rule
ast_grep_find_code
ast_grep_find_code_by_rule
has, inside, precedes, follows, or composite rules like all, any, not.Unavailable here:
ast_grep_rewrite_codeast_grep_scan-codeast_grep_analyze-importsAlternates:
ast_grep_find_code or ast_grep_find_code_by_rule to verify structural candidates before editing.cymbal, grep, and read for import discovery and narrow local inspection.Decide:
Write a tiny code sample that should match. If exclusions matter, write one sample that should not match too.
Use ast_grep_dump_syntax_tree on:
format: cst or format: astformat: patternDo this when you are unsure about node kinds, nesting, or how metavariables are interpreted.
Useful defaults:
pattern for direct shape matches.kind plus relational rules for more complex structure.all, any, and not when combining conditions.has and inside, default to stopBy: end unless you need a tighter stop condition.Use ast_grep_test_match_code_rule to validate a YAML rule against the minimal example.
If the rule fails:
ast_grep_find_code for straightforward pattern searches.ast_grep_find_code_by_rule for relational or composite logic.Prefer the narrowest project path and language that answers the question.
cymbal first.read.Goal: find console.log(...) calls in JavaScript.
ast_grep_find_codeconsole.log($ARG)Goal: find async functions that use await.
ast_grep_test_match_code_rule.ast_grep_find_code_by_rule.Example rule:
id: async-with-await
language: javascript
rule:
kind: function_declaration
has:
pattern: await $EXPR
stopBy: end
Goal: find async functions with await but without try/catch.
Use a composite rule with all and not.
references/rule_reference.md contains the detailed ast-grep rule syntax.Use the reference when you need exact YAML syntax for:
development
Use when you have a spec or requirements for a multi-step task, before touching code
testing
Use when independently verifying implementation claims, post-merge review, or when a reviewer needs to falsify success assertions with command-and-output evidence
data-ai
Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always
development
Use when implementing any feature or bugfix, before writing implementation code