hai-ast-grep

Create validated ast-grep YAML rules for structural code search and transformation.

278|15|Updated Mar 25, 2026
One-click install
npx skills add https://github.com/hylarucoder/hai-stack --skill hai-ast-grep
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hai-ast-grep
Source: https://github.com/hylarucoder/hai-stack/tree/main/skills/hai-ast-grep
Command: npx skills add https://github.com/hylarucoder/hai-stack --skill hai-ast-grep

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill solves inaccurate code searching and risky bulk refactoring by replacing text-based matching with syntax-aware AST analysis that finds, validates, and transforms code patterns reliably.

Core Features & Use Cases

  • Structural Code Matching: Create ast-grep patterns and YAML rules for finding code structures, linting violations, and reusable analysis workflows.
  • Safe Code Transformation: Design codemods and automated rewrites with positive and negative fixture validation before applying changes across a repository.
  • Use Case: When migrating an API across a large TypeScript codebase, use this Skill to locate every call pattern, avoid false matches in comments or strings, and generate a validated rewrite rule.

Quick Start

Use the hai-ast-grep skill to create an ast-grep rule that finds all deprecated API calls in my repository and validates the matches before rewriting them.

Frequently Asked Questions about hai-ast-grep

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create safe codemods for API migrations across a large codebase?

Safe codemods require structural AST matching to locate exact call patterns and validate rewrites against positive and negative fixtures before applying changes. This prevents false matches in comments or strings that occur with unreliable text-based matching.

What is the best way to write custom lint rules using AST patterns?

Custom lint rules use YAML rule definitions containing validated AST patterns to identify syntax-aware code structures. This approach enables precise structural code matching for linting violations without relying on fragile regular expressions.

How does tree-sitter based structural matching prevent false positives during code refactoring?

Tree-sitter based structural matching parses code into an abstract syntax tree to locate exact syntactic structures. This syntax-aware analysis ignores text appearances inside comments or strings, eliminating false positives common in text-based refactoring searches.

Can I validate codemod transformations before applying them to my repository?

Codemod transformations are validated using positive and negative fixtures to verify safe rewrite behavior. This fixture-based verification ensures the AST matching rules produce dependable automation results before executing repository-wide changes.

Do I need to install ast-grep separately to use structural code search rules?

Structural code search rules are designed for ast-grep workflows and require the ast-grep CLI to execute YAML rule definitions. The Skill generates the validated AST patterns and rule configurations, while ast-grep handles the actual repository scanning and transformation execution.

Why does text-based search fail when refactoring deprecated API calls?

Text-based search fails during API refactoring because it cannot distinguish actual code syntax from variable names, comments, or string literals. AST matching solves this by analyzing the structural syntax tree to find precise call patterns for dependable automated rewrites.