One-click install
npx skills add https://github.com/cosmoscalibur/agent-hardness --skill ast-grep-cosmoscalibur
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/cosmoscalibur/agent-hardness/tree/main/skills/ast-grep
Command: npx skills add https://github.com/cosmoscalibur/agent-hardness --skill ast-grep-cosmoscalibur

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires astgrep, and includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill addresses the challenge of searching codebases for complex patterns and structures that go beyond simple text search, leveraging Abstract Syntax Tree (AST) patterns for precise and efficient code discovery.

Core Features & Use Cases

  • AST-Based Code Search: Search for code patterns using AST patterns, enabling structural matching.
  • Rule Authoring: Guide users in writing ast-grep rules for specific code search needs.
  • Use Case: When a developer needs to find all async functions with specific parameters or locate code with particular structural characteristics in a large codebase.

Quick Start

Run the ast-grep skill with the rule file 'my_rule.yml' to search for all JavaScript functions that use the 'await' keyword.

Frequently Asked Questions about ast-grep

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

FAQPage Schema
How do I search for specific code structures in a large codebase beyond simple text matching?

Structural code search uses Abstract Syntax Tree (AST) patterns to target specific code structures and patterns within large codebases, enabling precise structural matching that goes beyond simple text search.

How do I write ast-grep rules to find async functions with specific parameters?

You can author ast-grep rules in a YAML file to define AST patterns that match specific code structures, such as locating all JavaScript async functions that use the await keyword with particular parameters.

What is AST-based code pattern matching and when do I need it?

AST-based code pattern matching leverages Abstract Syntax Tree structures for efficient code discovery. You need it when searching for complex structural characteristics in a codebase that simple text search cannot accurately capture.

Do I need to install the ast-grep CLI tool and Python library to perform structural analysis?

Yes, performing structural code search and analysis requires the ast-grep CLI tool and a Python environment with the ast-grep library installed to execute the pattern matching rules correctly.

What is the best way to locate code with particular structural characteristics across a large project?

Using AST patterns for structural code search is the best way to locate code with particular structural characteristics, as it targets specific code structures efficiently within large codebases instead of relying on text strings.

Why use AST patterns instead of regular expressions for code search?

AST patterns provide structural analysis that understands code syntax, allowing you to target specific code structures like async functions accurately, whereas regular expressions lack syntax awareness and are prone to false positives.