본문으로 건너뛰기
cccskills
무료GitHub에 공개한국어 소개

ast-grep

코드의 구문 구조를 바탕으로 함수와 호출을 찾고 여러 파일을 한꺼번에 수정합니다. 적용 전에 변경 내용을 미리 확인하고 YAML 규칙으로 검사와 자동 수정을 수행합니다.

원문원문 설명 보기

AST-aware structural code search and rewrite via ast-grep.

AI 평가100점/ 100설치 방법 보기

이럴 때 유용합니다

  • 특정 구조의 함수와 호출 검색
  • 여러 파일의 코드를 일괄 치환
  • 수정 전에 변경 내용 미리 확인
  • 재사용할 YAML 규칙으로 코드 검사

한국어 소개

할 수 있는 일

코드 구조를 조건으로 검색하고 일괄 수정합니다. 코드를 문법 단위로 나눈 구조인 구문 트리를 사용하여 함수 정의, 호출, import 문 등을 찾습니다. 부속 scripts/ast_grep_helper.py로 검색 패턴을 사전 점검하고 수정 위치를 미리 본 뒤 변경을 적용합니다. YAML 규칙을 통한 검사와 자동 수정도 지원합니다.

이럴 때 유용합니다

여러 파일에서 같은 형태의 호출을 치환하거나 빈 catch 블록처럼 특정 모양의 코드를 찾을 때 유용합니다. 반복해서 사용할 검사 조건을 규칙으로 저장하는 데도 사용합니다.

사용 예시

  • “console.log(x)를 찾아 logger.info(x)로 바꿀 내용을 먼저 보여 주세요.”
  • “Python의 Optional[X]를 X | None으로 바꿔 주세요.”

주의 사항

부속 도우미에는 Python 3와 ast-grep 실행 프로그램이 필요합니다. 검색 패턴은 정규 표현식이 아니라 코드로 해석합니다. 수정 전에 미리 보기를 확인하는 절차가 정해져 있습니다. 주석이나 문자열 내용 검색, 변수가 무엇을 참조하는지 확인하는 의미 분석에는 다른 도구를 사용합니다.

이 소개문은 공개된 SKILL.md를 바탕으로 AI(OpenAI Codex)가 작성했습니다. 정확한 사양은 아래 원문을 확인하세요.

객관 평가

AI가 SKILL.md의 내용만을 근거로 4가지 관점에서 판정했습니다. 스타 수나 인기도는 판정에 넣지 않았습니다.

지시의 명확성언제 쓰고 무엇을 하는지 알 수 있는가
A양호구조 검색과 일괄 수정 용도를 설명하고 텍스트 검색 및 의미 분석과 구분합니다.
절차의 구체성절차·입출력·예시가 구체적으로 적혀 있는가
A양호search, replace, scan 실행 예시와 검증, 미리 보기, 적용 절차가 있습니다.
안전성전송·삭제·명령 실행 등을 명시하고 있는가
A양호replace는 기본적으로 미리 보기만 하며 파일 수정에는 --apply를 명시해야 합니다.
도입의 용이성필요한 도구나 API 키가 적고 적혀 있는가
A양호Python 3와 ast-grep이 필요하며 install, doctor와 운영체제별 설치 스크립트를 제공합니다.

총점은 각 항목을 A=25점, B=15점, C=5점으로 더한 값입니다. 2026년 10월 20일 기준으로 AI(OpenAI Codex)가 판정했습니다. 참고용이므로 설치 전에 원문도 확인해 주세요.

평가가 다르다고 생각되면 재검토를 요청하기

어느 항목이 왜 다르다고 생각하는지 적어 주세요. 로그인은 필요 없습니다. SKILL.md와 대조해 평가를 다시 만들고 이곳에 반영합니다.

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

포함된 파일(14)

  • SKILL.md12.8 KB
  • install.ps17.0 KB
  • install.sh7.4 KB
  • LICENSE1.0 KB
  • references/cli.md7.1 KB
  • references/install.md5.5 KB
  • references/patterns.md5.4 KB
  • references/pitfalls.md8.7 KB
  • references/recipes.md7.7 KB
  • references/sgconfig.md6.3 KB
  • references/yaml-rules.md11.1 KB
  • scripts/ast_grep_helper.py27.3 KB
  • tests/smoke.ps15.6 KB
  • tests/smoke.sh7.6 KB

SKILL.md(원문)

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

ast-grep

ast-grep (binary also named sg) is an AST-aware search and rewrite tool across 25 languages. It treats your pattern as code, parses it the same way it parses your project, and matches structurally. It is the right tool whenever your question depends on code shape rather than text bytes.

This skill ships a Python wrapper at scripts/ast_grep_helper.py and platform install scripts at install.sh (POSIX) and install.ps1 (Windows). The helper adds offline pattern validation, the two-pass write trick, and binary auto-resolution. Use it as your default entry point.

Upstream source: vendored from code-yeongyu/ast-grep-skill (MIT), as shipped in oh-my-openagent's shared-skills bundle.


When to use this skill

Use it whenever the question is about code structure, not bytes:

  • "Find every function that takes a Request parameter."
  • "Rewrite every console.log(x) to logger.info(x)."
  • "Strip every as any cast."
  • "Replace require(...) with import across the repo."
  • "Find empty catch blocks."
  • "Migrate Optional[X] to X | None."
  • "Apply this codemod across these 200 files."
  • "Run our YAML lint rules and surface violations."

Switch to search_files (or plain rg) when the question is text-shaped (string literal contents, comments, license headers, file names, cross-language regex). When in doubt, ask: "does the answer depend on the language's syntax tree, or just on the file's bytes?" If the former, ast-grep. If the latter, search_files.

Hermes integration notes:

  • Run the helper and sg through the terminal tool. Single-quote every pattern so the shell never expands $VAR.
  • For find→read chains around matches, use --json-out and process with execute_code rather than piping through interpreters.
  • This complements (does not replace) Hermes's patch tool: patch is for targeted edits you author; ast-grep is for pattern-driven bulk rewrites across many sites.

Three things the agent must internalize

1. ast-grep is NOT regex

The wildcards are $VAR (one AST node) and $$$ (zero or more nodes). Regex syntax fails silently:

You wroteWhat ast-grep sawWhat you wanted
foo|barbitwise-or of foo and barrun two separate searches
.*foonot parseable$$$ foo (if $$$ is a list of nodes) or use rg
\w+not parseable$VAR to capture any identifier
[a-z]character class, not parseableswitch to rg

The full anti-pattern table is in references/pitfalls.md §1. The helper's validate subcommand catches these mechanically — call it before debugging "no matches" by hand.

2. Patterns must be valid code

The pattern itself must parse. def $FN($$$): fails because the trailing : makes it incomplete; use def $FN($$$). function $NAME without params/body fails; use function $NAME($$$) { $$$ }. Full table per language in references/pitfalls.md §2.

3. --update-all and --json are mutually exclusive (silently)

This is the single biggest gotcha when scripting. sg run -p P -r R --json --update-all returns the JSON but does not mutate files. To both preview AND apply, run two passes:

sg run -p P -r R --json=compact .   # pass 1: see what would change
sg run -p P -r R --update-all .     # pass 2: actually apply

The helper does this automatically when you call replace --apply. Read references/pitfalls.md §9.


The helper script — scripts/ast_grep_helper.py

A single-file Python 3 stdlib wrapper. Same on every OS. The agent's default entry point.

search — find all matches of a pattern

python scripts/ast_grep_helper.py search 'console.log($MSG)' --lang ts src/

Validates the pattern offline first. If the pattern looks like regex (\w, .*, |, etc.) the helper exits with a hint and never calls sg — saves a round-trip. Pass --force to skip validation.

Flags:

  • --lang ts (or any of the 25 languages; aliases like js, py, rs, kt accepted)
  • --globs '!**/*.test.ts' (repeatable; prefix ! to exclude)
  • -C 3 (context lines)
  • --json-out (raw JSON instead of human format)

replace — rewrite by pattern, dry-run by default

# Dry-run preview (default — no files mutated)
python scripts/ast_grep_helper.py replace 'console.log($MSG)' 'logger.info($MSG)' --lang ts src/

# Actually apply
python scripts/ast_grep_helper.py replace 'console.log($MSG)' 'logger.info($MSG)' --lang ts src/ --apply

The helper:

  1. Validates both pattern and rewrite for hint-detectable mistakes.
  2. Runs pass 1 with --json=compact to collect matches and show a preview.
  3. If --apply is set, runs pass 2 with --update-all to mutate files.

scan — run YAML rules

# Discover sgconfig.yml from cwd and run all rules
python scripts/ast_grep_helper.py scan src/

# Run a single rule file
python scripts/ast_grep_helper.py scan -r rules/no-console.yml src/

# Apply auto-fixes
python scripts/ast_grep_helper.py scan -U src/

# CI-friendly GitHub annotations
python scripts/ast_grep_helper.py scan --report-style short src/

validate — offline pattern check (no sg call)

Useful for CI lints, pre-commit hooks, and quick sanity checks:

python scripts/ast_grep_helper.py validate '\w+' --lang ts
# → exit 2: regex \w not supported. Use $VAR for identifiers.

python scripts/ast_grep_helper.py validate 'console.log($MSG)' --lang ts
# → exit 0: pattern looks plausible for ast-grep.

langs / doctor / install

python scripts/ast_grep_helper.py langs       # list 25 supported languages and aliases
python scripts/ast_grep_helper.py doctor      # check ast-grep binary availability
python scripts/ast_grep_helper.py install     # delegate to install.sh / install.ps1

new and test subcommands proxy directly to sg new and sg test.


Direct sg use (when the helper isn't enough)

The helper is opinionated. For full control, drop to sg. The skill ships a CLI cheat sheet in references/cli.md. The minimal idioms:

# Search
sg run -p 'console.log($MSG)' --lang ts src/

# Search with JSON for scripting
sg run -p 'console.log($MSG)' --lang ts --json=compact src/

# Rewrite, dry-run
sg run -p 'console.log($MSG)' -r 'logger.info($MSG)' --lang ts --json=compact src/

# Rewrite, apply
sg run -p 'console.log($MSG)' -r 'logger.info($MSG)' --lang ts --update-all src/

# Pattern from stdin (great for ad-hoc experiments)
echo 'console.log("hi")' | sg run -p 'console.log($MSG)' --lang js --stdin

# Debug a pattern that returns 0 matches
sg run -p '<your pattern>' --lang <lang> --debug-query=ast --stdin <<< '<sample-code>'

# Run YAML rules
sg scan src/

# Inline YAML rule (one-off)
sg scan --inline-rules '
id: no-todo
language: TypeScript
severity: warning
rule: { pattern: TODO }' src/

When using sg directly in a shell, always single-quote patterns so $VAR is not expanded by the shell.


Decision tree — what to use, when

USER asks for "find/rewrite/codemod"
│
├─ structural pattern (function shape, call, class, import, control flow)
│  └→ ast-grep (this skill)
│
├─ text pattern (regex, alternation, character classes, file names)
│  └→ search_files / rg
│
├─ semantic question (what variable does this refer to? does this throw?)
│  └→ LSP tools, TypeScript compiler, Pyright, Semgrep with type inference
│
└─ multiple repos / federated search
   └→ a search engine + then ast-grep / rg / LSP per-repo

If the user says "find all" or "every", default to ast-grep when the target is shaped (function, class, call, import, statement). Default to search_files when the target is text (string content, comment, license header, file name, identifier substring).


Always run dry-run first when rewriting

A bad pattern silently rewrites the wrong thing. The helper's replace defaults to dry-run for this reason. The flow is:

  1. Search to confirm matches: helper search '<pattern>' --lang X .
  2. Dry-run rewrite: helper replace '<pattern>' '<rewrite>' --lang X . (no --apply)
  3. Inspect the dry-run summary: number of matches, files affected, the per-location preview.
  4. If wrong: refine pattern, go back to step 1.
  5. If right: helper replace '<pattern>' '<rewrite>' --lang X . --apply.

Never apply a rewrite that you have not first dry-run. After an --apply in a git repo, review with git diff --stat before committing.


When sg returns 0 matches but you know the code is there

In priority order:

  1. Run helper validate '<pattern>' --lang <lang> — catches regex misuse, missing function bodies, Python trailing colons.
  2. Check --lang — sg infers from extension; if you pass a .tsx file with --lang ts (not tsx), JSX won't parse.
  3. Inspect the parsed pattern: sg run -p '<pattern>' --lang <lang> --debug-query=ast --stdin <<< '<sample>'. If it shows ERROR nodes, the pattern is malformed.
  4. Check the AST of the target file: sg run -p '$_' --lang <lang> --debug-query=cst path/to/file | head -40 — find the kind you're trying to match.
  5. Try the playground: https://ast-grep.github.io/playground.html — paste code + pattern, see what's happening.

Do not blindly retry with variations. Each failure has a reason; surface it.


When to use YAML rules vs inline -p patterns

Use inline -p when:

  • One-off ad-hoc query.
  • The pattern is simple (no constraints, no fix template).
  • You're exploring.

Use YAML rules (file under rules/, run via sg scan) when:

  • The pattern is reused (lint rule, codemod that runs in CI).
  • You need constraints, transform, complex inside/has, or composite logic.
  • You want auto-fix (fix: field).
  • You want to test the rule (snapshot tests via sg test).

The full YAML rule schema is in references/yaml-rules.md. Project setup (sgconfig.yml, ruleDirs, utilDirs) is in references/sgconfig.md.


Output discipline

  • sg run --json=compact produces an array of match objects: { file, range: {start, end}, text, replacement?, lines, language, ... }.
  • Without --json, sg produces human-readable colored output suitable for terminals.
  • The helper's default output is human-readable (file:line:column + match preview). Pass --json-out for raw JSON.
  • The helper's replace always summarizes: number of matches, number of files, per-location preview.

When summarizing for the user, always include the count of files affected, not just the count of matches. Users care about blast radius.


Required reading (in order of priority)

  1. references/patterns.md — meta-variables, naming rules, strictness levels. Read when you're unsure why a pattern doesn't match.
  2. references/pitfalls.md — the failure-mode field guide. Read when 0 matches surprises you.
  3. references/recipes.md — copy-paste patterns by language. Read first when you start a new task.
  4. references/cli.md — sg run, sg scan, sg test, sg new, sg lsp. Read when the helper isn't enough.
  5. references/yaml-rules.md — YAML rule schema. Read when you outgrow inline patterns.
  6. references/sgconfig.md — project-level configuration. Read when you set up sg scan for a real project.
  7. references/install.md — per-OS install methods. Read only if install.sh / install.ps1 fail.

Invariants (do not break)

  • Validate before searching. When emitting a pattern programmatically, call helper validate first. It catches the regex-misuse class of mistakes that account for ~70% of "0 matches" debug sessions.
  • Dry-run before applying. Never run sg run -r ... --update-all without first inspecting the matches. The helper's replace enforces this by default.
  • Two-pass writes. When using sg directly to both preview and apply, run two invocations — --json ignores --update-all.
  • Single-quote patterns in shell. '$VAR' not "$VAR". The shell expands $VAR to the empty string in double quotes, breaking the pattern.
  • Pattern is code, not regex. When the pattern would need |, .*, \w, or [a-z], switch to search_files instead. Don't try to force ast-grep into a regex shape.
  • --lang is required for stdin. When piping with --stdin, set --lang explicitly; sg cannot infer from extension.
  • Linux: prefer ast-grep over sg because sg collides with setgroups from util-linux. The helper handles this; if you call sg directly, alias it: alias sg=ast-grep.

리뷰

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

댓글

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

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

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

0 / 1,000자

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

같은 저장소의 스킬

1password

무료요약 있음AI 평가 100점

1Password에 저장한 비밀번호와 API 키를 명령과 설정 템플릿에 사용합니다. CLI 설치와 인증부터 비밀 값 조회 및 환경 변수 전달까지 안내합니다.

  • 1Password CLI 설치와 설정
  • 저장된 API 키로 명령 실행
  • 설정 템플릿에 비밀 값 삽입
NousResearch/hermes-agent25.5만2026년 10월 19일 업데이트

3-statement-model

무료요약 있음AI 평가 90점

손익계산서·재무상태표·현금흐름표를 수식으로 연결한 Excel 모델을 만듭니다. 실적과 예측 가정을 입력하고 시나리오를 비교하며 세 재무제표의 일관성을 단계별로 확인합니다.

  • 재무 템플릿에 실적 입력
  • 세 재무제표가 연동되는 예측 작성
  • 기본·상향·하향 시나리오 비교
NousResearch/hermes-agent25.5만2026년 10월 19일 업데이트

accelerate

무료요약 있음AI 평가 80점

기존 PyTorch 학습 코드를 적은 수정으로 여러 GPU나 컴퓨터에 맞게 구성합니다. 혼합 정밀도, 메모리 절약 설정과 학습 실행 방법을 안내합니다.

  • 단일 GPU 학습을 여러 GPU로 옮깁니다
  • 혼합 정밀도 학습을 설정합니다
  • DeepSpeed나 FSDP로 메모리를 절약합니다
NousResearch/hermes-agent25.5만2026년 10월 19일 업데이트

Configure Hermes to run AI models through Actual Computer on your own hardware. Set up either the hosted relay or a local connection, select models, verify responses, and troubleshoot request errors or empty output.

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

  • Connecting Hermes with an Actual inference key
  • Running models through a local Actual daemon
  • Downloading and loading local models
NousResearch/hermes-agent25.5만2026년 10월 19일 업데이트

adversarial-ux-test

무료요약 있음AI 평가 80점

기술에 익숙하지 않고 쉽게 불만을 느끼는 사용자로 앱을 시험합니다. 혼란스러운 조작과 이탈 원인을 찾고, 개선 과제와 개인적 불만을 나눠 수정안을 정리합니다.

  • 출시나 시연 전에 사용성을 확인합니다
  • 신규 사용자의 경험을 점검합니다
  • 가입과 결제 과정의 어려움을 찾습니다
NousResearch/hermes-agent25.5만2026년 10월 19일 업데이트

agent-merge-conflict-arbiter

무료요약 있음AI 평가 100점

두 에이전트가 각각 수정한 브랜치의 Git 충돌을 양쪽 변경 내용과 의도에 따라 중립적으로 해결합니다. 충돌별 판단 이유를 기록하고 빌드나 테스트로 통합 결과를 확인합니다.

  • 두 에이전트의 브랜치 충돌 해결
  • 병렬 worktree의 변경 내용 통합
  • 충돌하는 설계 판단의 이유 확인
NousResearch/hermes-agent25.5만2026년 10월 19일 업데이트

NousResearch의 스킬 모두 보기

이 스킬의 문제 신고