AgentSkillsCN

ast-grep

借助 ast-grep/sg 实现只读的结构性代码搜索。作为 AST-aware CLI 探索、模式搜索与快速代码发现的替代方案,rg/sed 皆可被其取代。它依托 ast-grep/sg、结构性搜索、AST 搜索、查找使用场景,以及 tree-sitter 工具,助您高效完成代码探索任务。

SKILL.md
--- frontmatter
name: ast-grep
description: "Read-only structural code search with ast-grep/sg. Grep/rg/sed alternative for AST-aware CLI exploration, pattern search, and fast code discovery. Activates on ast-grep/sg, structural search, AST search, find usages, tree-sitter."

ast-grep

Overview

Read-only CLI search with sg or ast-grep. AST-aware grep for code exploration and SWE tasks.

Quick start

  • Prefer sg. Fallback ast-grep run. Last resort: nix run nixpkgs#ast-grep -- run
  • Example: sg -p 'console.log($MSG)' -l ts src
  • Files only: sg -p 'console.log($$$)' -l ts --files-with-matches src

Guardrails

  • Read-only: never use --rewrite, -r, --update-all, or --interactive
  • Stdin requires --lang

Resources

  • reference.md: flags, strictness, selectors, output formats
  • cookbook/: troubleshooting and recipes