ast-grep
处理按语法形状匹配与批量重写,比文本查找更精确。
会修改代码文件,建议在受控分支或备份下运行。
基于 ast-grep 的结构化代码搜索与确定性 codemod 工具。
用 ast-grep 做结构化的代码搜索和确定性 codemod:按语法树匹配代码形状,能找函数、调用、类、import 的特定结构并安全重写(比如把 console.log 换成 logger.info、把 require 改成 import)。遇到语法形态而非简单文本搜索的改动就用它,不要跟 rg/grep 混用。它支持 25 种语言,并带有 Python 辅助脚本便于批量应用规则。
▸ 展开 SKILL.md 英文原文
Use ast-grep (sg) for AST-aware code search and rewrite across 25 languages. Trigger for structural code matching or deterministic codemods: find every function/call/class/import shaped like X, rewrite console.log to logger.info, strip `as any`, migrate require() to import, find empty catch blocks or missing await, and scan/apply YAML rules. Prefer this over rg/grep when the target is syntax shape rather than text; use rg for string contents, comments, filenames, or regex-style byte searches.
帮我安装这个 skill:https://raw.githubusercontent.com/code-yeongyu/oh-my-openagent/dev/packages/shared-skills/skills/ast-grep/SKILL.mdcurl -fsSL "https://raw.githubusercontent.com/code-yeongyu/oh-my-openagent/dev/packages/shared-skills/skills/ast-grep/SKILL.md"# ast-grep `sg` (also installed as `ast-grep`) 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. --- ## When to use this skill Use it whenever the user's question is about **code structure**, not byt