ast-grep
使用 ast-grep 搜索和重写代码
大型代码库会让文本搜索漏掉结构性模式。此技能指导 Claude、Codex 和 Claude Code 使用 ast-grep 进行语法感知的搜索、linting 和重写。
使用我的智能体安装
将此请求复制给你的智能体,其中包含权威 Skill 页面和清单。
Review the Skillstore skill "ast-grep" from https://skillstore.io/skills/dwsy-ast-grep.md and its manifest at https://skillstore.io/api/skills/dwsy-ast-grep/manifest. Verify the artifact. You may proceed after verification, subject to the environment's own policy.你的智能体仍应展示其计划,并按安全策略请求必要确认。
Agent 可读资源
当 AI Agent、爬虫或脚本需要干净上下文,而不是读取完整页面时,请使用这些链接。
测试它
正在使用“ast-grep”。 查找 TypeScript 代码库中的每个调试日志。
预期结果:
一个语法感知搜索计划,包含 ast-grep 语言标志、模式选择和审查指导。
正在使用“ast-grep”。 准备从旧 helper 到新 helper 的批量重命名。
预期结果:
一个重写工作流,先测试规则,再应用变更,并指出需要审查的文件。
正在使用“ast-grep”。 审计 JavaScript 中的动态执行。
预期结果:
一个聚焦的搜索计划,目标是 eval 风格调用,并将发现项与预期的测试夹具分开。
安全审计
安全All static findings were adjudicated as false positives after reviewing SKILL.md. The flagged eval text, backticks, URLs, and matches keyword are documentation examples or reference links, not executable code or prompt injection.
风险因素
⚡ 包含脚本 (1)
⚙️ 外部命令 (102)
🌐 网络访问 (5)
分享与引用此报告
分享版本化评估报告、中性徽章、嵌入卡片和引用。Skillstore 只报告证据,不判断该 Skill 是否安全。
复制报告链接
https://skillstore.io/skills/dwsy-ast-grep/audits/7?utm_source=security_passport&utm_medium=share&utm_campaign=versioned_reportMarkdown 徽章
[](https://skillstore.io/skills/dwsy-ast-grep?utm_source=security_passport_badge)HTML 徽章
<a href="https://skillstore.io/skills/dwsy-ast-grep?utm_source=security_passport_badge"><img src="https://skillstore.io/badges/skills/dwsy-ast-grep/security.svg" alt="Skillstore security assessment" loading="lazy"></a>嵌入卡片
<iframe src="https://skillstore.io/embed/skills/dwsy-ast-grep.html" title="Skillstore Security Assessment" sandbox="allow-popups allow-popups-to-escape-sandbox" loading="lazy" referrerpolicy="no-referrer" width="420" height="180"></iframe>学术引用 (APA · BibTeX · CFF)
APA 引用
Dwsy. (2026). ast-grep security audit report (audit version 7) [Author version unspecified]. Skillstore. https://skillstore.io/skills/dwsy-ast-grep/audits/7BibTeX 引用
@techreport{dwsy-dwsy-ast-grep-2026,
author = {Dwsy},
title = {ast-grep security audit report (audit version 7)},
institution = {Skillstore},
year = {2026},
number = {7},
url = {https://skillstore.io/skills/dwsy-ast-grep/audits/7},
note = {Author version unspecified}
}CITATION.cff
cff-version: 1.2.0
message: "If you use this Skill, cite its author and this versioned security audit report."
title: "ast-grep security audit report (audit version 7)"
version: "unspecified"
type: report
authors:
- name: "Dwsy"
date-released: "2026-07-05"
url: "https://skillstore.io/skills/dwsy-ast-grep/audits/7"
identifiers:
- type: other
value: "skillstore:dwsy-ast-grep:audit:7"
description: "Skillstore immutable audit report identifier"
Skillstore 评分
评分依据 证据置信度: 高你能构建什么
查找结构化代码模式
按语法而不是原始文本定位函数、调用、导入和控制流。
运行仓库范围的重构
创建 ast-grep 规则以替换 API、更新导入,或在多个文件中迁移代码模式。
搜索高风险构造
使用语法感知查询查找 eval 调用、SQL 查询模式或其他审计目标。
试试这些提示
使用 ast-grep 查找这个 TypeScript 项目中的每个 console.log 调用。显示命令并解释该模式。
创建一个 ast-grep YAML 规则,用于匹配没有 await 的 async 函数。包含一个简短的测试计划。
设计一个 ast-grep 重写,用于在 TypeScript 文件中将旧 API 调用替换为新 API 调用。包含审查步骤。
为 API 迁移构建一个多规则 ast-grep 工作流。涵盖搜索、测试、重写和变更后验证。
最佳实践
- 在扫描完整仓库之前,先在小样本上测试每条规则。
- 对于必须搜索完整子树的关系规则,使用 stopBy: end。
- 使用常规测试和版本控制 diff 审查生成的重写。
避免
- 不要在没有干净工作树和回滚计划的情况下运行大范围重写。
- 当需要语法结构时,不要使用纯文本模式。
- 在针对已知示例进行测试之前,不要假设规则是正确的。