본문으로 건너뛰기
cccskills
무료GitHub에 공개

code-structural-search

Use ast-grep for AST-based code pattern matching.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(12)

  • SKILL.md8.1 KB
  • commands/code-structural-search.md122 B
  • hooks/post-execute.cjs322 B
  • hooks/pre-execute.cjs439 B
  • PATTERNS.md11.2 KB
  • README.md7.8 KB
  • references/research-requirements.md344 B
  • rules/code-structural-search.md241 B
  • schemas/input.schema.json526 B
  • schemas/output.schema.json266 B
  • scripts/main.cjs1.1 KB
  • templates/implementation-template.md196 B

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Code Structural Search

Use ast-grep for AST-based code pattern matching.

When to Use

  • Find code by structure, not keywords
  • "Find all functions with 3 arguments"
  • "Find all classes that extend X"
  • "Find all database queries"
  • "Find all error handling patterns"
  • Precise code refactoring (change exact patterns)

Interface

Skill({ skill: 'code-structural-search', args: 'pattern-here --lang ts' });

Language Support

ast-grep supports 20+ languages via tree-sitter:

LanguageFlagFile Extensions
JavaScript--lang js.js, .jsx
TypeScript--lang ts.ts, .tsx
Python--lang py.py, .pyi
Go--lang go.go
Rust--lang rs.rs
Java--lang java.java
C--lang c.c, .h
C++--lang cpp.cpp, .cc, .hpp, .hh
C#--lang cs.cs
Kotlin--lang kt.kt, .kts
Swift--lang swift.swift
PHP--lang php.php
Ruby--lang rb.rb
Lua--lang lua.lua
Elixir--lang ex.ex, .exs
HTML--lang html.html, .htm
CSS--lang css.css
JSON--lang json.json
Bash--lang bash.sh, .bash
Thrift--lang thrift.thrift

Pattern Examples

JavaScript/TypeScript

Find all functions:

function $NAME($ARGS) { $$ }

Find functions with exactly 2 arguments:

function $NAME($A, $B) { $$ }

Find async functions:

async function $NAME($ARGS) { $$ }

Find class methods:

class $NAME {
  $METHOD($ARGS) { $$ }
}

Find arrow functions:

const $NAME = ($ARGS) => { $$ }

Find console.log statements:

console.log($$$)

Find try-catch blocks:

try { $$ } catch ($ERR) { $$ }

Python

Find all functions:

def $NAME($ARGS): $$$

Find class definitions:

class $NAME: $$$

Find async functions:

async def $NAME($ARGS): $$$

Find imports:

import $MODULE

Find from imports:

from $MODULE import $$$

Go

Find all functions:

func $NAME($ARGS) $RETURN { $$ }

Find struct definitions:

type $NAME struct { $$$ }

Find interface definitions:

type $NAME interface { $$$ }

Rust

Find all functions:

fn $NAME($ARGS) -> $RETURN { $$ }

Find impl blocks:

impl $NAME { $$$ }

Find pub functions:

pub fn $NAME($ARGS) -> $RETURN { $$ }

Java

Find all methods:

public $RETURN $NAME($ARGS) { $$ }

Find class definitions:

public class $NAME { $$$ }

Find interface definitions:

public interface $NAME { $$$ }

Pattern Syntax

SymbolMeaningExample
$NAMESingle node/identifierfunction $NAME() {}
$$$Zero or more statements/nodesclass $NAME { $$$ }
$$Zero or more statements (block)if ($COND) { $$ }
$_Anonymous wildcard (discard)console.log($_)

Performance

  • Speed: <50ms per search (typical)
  • Best combined with semantic search (Phase 1)
  • Use ripgrep first for initial file discovery

vs Other Tools

vs Ripgrep (grep):

  • Ripgrep: Fast text search, finds keywords
  • ast-grep: Structural search, finds exact code patterns
  • Use ripgrep first → then ast-grep to refine

vs Semantic Search (Phase 1):

  • Semantic: Understands code meaning
  • ast-grep: Understands code structure
  • Combined: Best results (Phase 2)

Usage Workflow

  1. Broad search with ripgrep:

    Skill({ skill: 'ripgrep', args: 'authenticate --type ts' })
    
  2. Structural refinement with ast-grep:

    Skill({ skill: 'code-structural-search', args: 'function authenticate($$$) { $$ } --lang ts' })
    
  3. Semantic understanding with Phase 1:

    Skill({ skill: 'code-semantic-search', args: 'authentication logic' })
    

Common Use Cases

Security Patterns

Find unvalidated inputs:

router.post($PATH, ($REQ, $RES) => { $$ })

Find SQL queries (potential injection):

db.query(`SELECT * FROM ${$VAR}`)

Find eval usage:

eval($$$)

Code Quality Patterns

Find deeply nested functions:

function $NAME($ARGS) {
  if ($COND) {
    if ($COND2) {
      if ($COND3) { $$ }
    }
  }
}

Find long parameter lists (>5 params):

function $NAME($A, $B, $C, $D, $E, $F, $$$) { $$ }

Find unused variables:

const $NAME = $VALUE;

Refactoring Patterns

Find old API usage:

oldAPI.deprecatedMethod($$$)

Find callback patterns (convert to async/await):

$FUNC($ARGS, ($ERR, $DATA) => { $$ })

Find React class components (convert to hooks):

class $NAME extends React.Component { $$$ }

Iron Laws

  1. ALWAYS specify the language with --lang flag — without a language flag, ast-grep applies heuristics that produce false positives; specify --lang ts, --lang py, etc. for accurate AST parsing.
  2. ALWAYS use ripgrep/keyword search first to narrow the target set — structural search over the whole codebase is slow; use ripgrep to find candidate files first, then apply ast-grep for precise matching.
  3. NEVER use regex for structural code patterns — regex breaks on formatting differences, nested structures, and multi-line code; AST patterns are format-independent and semantically precise.
  4. ALWAYS test patterns on a known match before running project-wide — patterns with incorrect syntax silently match nothing; verify the pattern finds at least one known example before broad application.
  5. ALWAYS use $$$ for variable argument lists, not * or . — ast-grep uses metavariable syntax ($NAME, $$$, $$); regex or glob syntax in patterns produces silent failures.

Anti-Patterns

Anti-PatternWhy It FailsCorrect Approach
No --lang flagWrong parser applied; produces false positives and missesAlways specify --lang ts, --lang py, etc.
Running project-wide without ripgrep pre-filterSlow on large codebases; many irrelevant resultsUse ripgrep to identify candidate files first
Regex for structural matchingBreaks on multi-line, whitespace variations, nestingUse ast-grep AST patterns ($NAME, $$$, etc.)
Untested pattern on full codebaseIncorrect patterns silently return nothingTest on one known match first
Using * or . for wildcardsNot valid ast-grep syntax; ignored or errorsUse $NAME for single node, $$$ for sequences

Memory Protocol (MANDATORY)

Before starting: Read .claude/context/memory/learnings.md

After completing:

  • New pattern → .claude/context/memory/learnings.md
  • Issue found → .claude/context/memory/issues.md
  • Decision made → .claude/context/memory/decisions.md

ASSUME INTERRUPTION: If it's not in memory, it didn't happen.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Ensure accessibility in UI components including semantic HTML, ARIA attributes, keyboard navigation, and WCAG 2.2 AA compliance.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

oimiragieo/agent-studio422026년 7월 14일 업데이트

Use when you want to improve response quality through meta-cognitive reasoning. Applies 15+ reasoning methods to reconsider and refine initial outputs.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

oimiragieo/agent-studio422026년 7월 14일 업데이트

N-round opposing-stance debates for trade-off analysis. Assigns pro/con roles to agents, runs structured debate rounds with quality scoring, and produces a moderator synthesis with confidence-rated recommendation. Generalizable to architecture, technology, security, and design decisions.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

oimiragieo/agent-studio422026년 7월 14일 업데이트

Force adversarial code review stance that eliminates confirmation bias — reviewer must find issues or re-analyze

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

oimiragieo/agent-studio422026년 7월 14일 업데이트

Creates specialized AI agents on-demand when no existing agent matches a request. Use when the Router cannot find a suitable agent for a task. Enables self-evolution by generating persistent agents.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

oimiragieo/agent-studio422026년 7월 14일 업데이트

LLM-as-judge evaluation framework with 5-dimension rubric (accuracy, groundedness, coherence, completeness, helpfulness) for scoring AI-generated content quality with weighted composite scores and evidence citations

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

oimiragieo/agent-studio422026년 7월 14일 업데이트

oimiragieo의 스킬 모두 보기

이 스킬의 문제 신고