Token导航 LogoToken导航

Agent Skill · 研究检索

ast-code-graph(ast 代码图)

ast-code-graph 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

ast-code-graph 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为执行命令;许可证信息还不明确,第三方扫描已通过,按安装量在研究检索类的 73,675 个 Skill 里排第 52,401。

总安装 559周安装 24GitHub Stars 3下载 196核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:ast-code-graph(ast 代码图)
来源仓库:https://github.com/rolandbrecht/agent-skills
仓库路径:skills/ast-code-graph
安装命令:
npx skills add https://github.com/rolandbrecht/agent-skills --skill ast-code-graph
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/rolandbrecht/agent-skills --skill ast-code-graph

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

ast-code-graph 利用 AST 分析理解代码结构,生成函数调用图与依赖关系。适用于大型代码库的理解、重构与安全审计。基于 ast-grep 实现跨语言结构搜索与模式匹配。区分结构查询与文本查询,前者用于语义理解,后者用于关键词查找。输出可视化的代码图谱与热点分析报告。

ast-code-graph 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/ast-code-graph

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/rolandbrecht/agent-skills --skill ast-code-gra…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要执行命令,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

ast-code-graph 怎么安装?

在终端执行 npx skills add https://github.com/rolandbrecht/agent-skills --skill ast-code-graph。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

ast-code-graph 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

ast-code-graph 需要什么权限?

权限级别是执行命令。安装流程涉及命令执行,可能通过 npx skills add https://github.com/rolandbrecht/agent-skills --skill ast-code-graph 联网下载 Skill 或依赖。用户安装前应确认命令来源、仓库内容和执行环境。

ast-code-graph 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

ast-code-graph 用的人多吗?

公开数据是累计安装 559 次,近一周安装 24 次,下载 196 次,GitHub 3 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

ast-code-graph 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 需要执行命令,装到常用环境前要先评估影响面。
  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。

不太适合

  • 不能接受 Skill 在你机器上执行命令的人。
  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
ast-code-graph

ast 代码图 · 本页

5593执行命令未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

AST & Code Graph Indexing

Overview

Text-based search (grep, ripgrep) finds string matches. AST-based analysis understands structure — it knows the difference between a function definition, a function call, a comment, and a string literal.

Primary tool: ast-grep (sg / ast-grep) — a fast, Rust-based CLI for structural code search, lint, and rewriting. It uses tree-sitter for parsing and supports 20+ languages out of the box.

Core principle: When the question is about *code structure*, use AST analysis. When the question is about *text content*, use grep.

Trigger Patterns

Detailed examples of when to trigger this skill:

CategoryExample queries
Structural pattern search"useEffect without dependency array", "async functions without try-catch", "User.objects.get() without exception handling", "fetch() calls outside src/api/", "console.log inside class methods", "route handlers missing error handling"
Bulk code migrationwrap all async handlers, replace all X() calls with Y(), add error handling to all route handlers, rewrite deprecated API patterns across hundreds of files
Dependency & impact analysis"what does analyzePayment depend on", "blast radius of changing X", "which modules depend on./lib/database.js", "direct and transitive dependencies"
Safe renaming"rename fetchUserData to getUserData safely", rename across TypeScript/JavaScript codebase
Dead code & circular imports"exports never imported anywhere", "circular imports causing webpack bundle", unused exports, which npm dependencies are actually used in source
ast-grep ruleswrite an ast-grep rule, sg pattern, ast-grep syntax

When to Use

Use this skill when the task involves:

TaskWhy AST beats grep
Refactoring / renamingGrep finds the string in comments and strings too; AST finds only the symbol
Dead code detectionGrep can't tell if an export is actually imported elsewhere
Dependency tracing"What modules does X depend on?" requires understanding import/require
Impact analysis"If I change function X, what breaks?" needs call-graph traversal
Circular dependency detectionRequires building and analyzing a full import graph
Code migrationRewriting deprecated API patterns structurally across a codebase
Custom lintingEnforcing project-specific patterns that standard linters don't cover

Don't use this skill when:

  • Searching for a specific string, error message, or config value → use grep
  • Finding files by name or extension → use find/fd
  • The codebase is < 5 files and you can read them all → just read them

Prerequisites

Before using this tool for searches, you MUST check if ast-grep is installed natively on the system:

which ast-grep || which sg

If it is installed, use the native binary directly for semantic searches. Do not attempt to run it via Docker containers or complex wrapper scripts unless absolutely necessary.

If it is not installed, you can install it using one of the following methods depending on the OS:

  • Node.js: npm install -g @ast-grep/cli
  • MacOS (Homebrew): brew install ast-grep
  • Rust (Cargo): cargo install ast-grep --locked

Script Dependencies

The bundled scripts for graph building and AST parsing require additional dependencies:

  • JS/TS Parsing (scripts/parse-js.mjs): Requires Node.js v14+, acorn, and acorn-walk. Before running, check if they are installed globally or in the ast-code-graph directory. If not, you can install them by running npm install acorn acorn-walk in the ast-code-graph directory or npm install -g acorn acorn-walk globally.
  • Python Graph Builder (scripts/build-graph.py): Requires Python 3.8+ (uses standard library only, no external dependencies).

Phase 1: Search — Find Code by Structure

ast-grep (recommended — all languages)

ast-grep uses pattern syntax that looks exactly like the code you're searching for, using $METAVAR wildcards to match any AST node.

Basic pattern search:

# Find all calls to console.log
ast-grep -p 'console.log($MSG)' -l js src/

# Find all require() calls
ast-grep -p 'require($MOD)' -l js src/

# Find all async functions
ast-grep -p 'async function $NAME($$$PARAMS) { $$$BODY }' -l js src/

# Find if-else without braces
ast-grep -p 'if ($COND) $STMT' -l js src/

Key metavariable syntax:

  • $NAME — matches a single AST node (like regex .). Example: foo($ARG) matches foo(a) but NOT foo(a, b).
  • $$$ARGS — matches zero or more nodes (like regex .*). Example: foo($$$ARGS) matches foo(), foo(a), and foo(a, b). This is the most common pitfall! Default to $$$ when matching arguments or block bodies unless you strictly want one node.
  • $_ — anonymous match (when you don't need to reference it later).

TypeScript generic calls require a separate pattern:

In TypeScript/TSX, a call like useState<string>('') has <string> as a separate type_arguments AST node. The pattern useState($$$ARGS) will NOT match it. You need two passes for full coverage:

# Non-generic calls (works for all languages)
ast-grep -p 'useState($$$ARGS)' src/

# Generic TypeScript calls like useState<T>()
ast-grep -p 'useState<$T>($$$ARGS)' -l tsx src/
ast-grep -p 'useState<$T>($$$ARGS)' -l ts src/

Use $$$T instead of $T if the type argument can be a union like string | null.

Search with rewrite preview:

# Preview replacing var with const
ast-grep -p 'var $NAME = $VALUE' -r 'const $NAME = $VALUE' -l js src/

# Apply interactively (prompts y/n per match)
ast-grep -p 'var $NAME = $VALUE' -r 'const $NAME = $VALUE' -l js --interactive src/

See ast-grep-cheatsheet.md for the full pattern reference.


Phase 2: Pipeline JSON Output to Scripts

Often, simply printing matches to the terminal isn't enough. For complex analysis, you should export the matches as JSON and process them with a script. This is highly recommended for building graphs, finding dead code, or generating reports.

Generate and save JSON:

# Export all function definitions to a file for secondary analysis
ast-grep -p 'function $NAME($$$PARAMS) { $$$BODY }' -l typescript --json src/ > functions.json

Then, write a quick Python or Node.js script to read functions.json and extract the specific node text, line numbers, or relationships you need! *(e.g., parsing the JSON to find functions that have a specific naming convention or parsing out all import sources to build a dependency graph).*


Phase 3: Complex Workflows (Step-by-Step)

Here are detailed methodologies for solving complex structural problems:

Workflow A: Impact Analysis (What breaks if I change X?)

  1. Search: Find the definition of the target symbol X using ast-grep and ensure you have its exact name and module path.
  2. Find Direct Callers: Use ast-grep to find all import statements that import X, and all function calls to X(). Save these results to a JSON file.
  3. Analyze: If the codebase is large, write a quick script to parse the JSON and list the files/functions that call X.
  4. Iterate (Transitive Callers): If necessary, repeat the process for the functions that call X to build a full call graph. (Alternatively, if this is a Python project, use the bundled build-graph.py script as shown in Phase 4).

Workflow B: Safe Refactoring / Migration

  1. Search: ast-grep -p '<pattern>' src/ to find all matches of the old pattern.
  2. Review: Add --json to inspect match details and ensure your pattern isn't capturing unintended code boundaries (e.g. ensure you used $$$BODY for blocks, not $BODY).
  3. Preview: Add -r '<rewrite>' to see the replacement printed to stdout. Check a few edge cases.
  4. Apply: Add --interactive to selectively apply changes, or remove --interactive if you're 100% confident (though you should usually trust but verify).
  5. Verify: Re-run the search pattern ast-grep -p '<pattern>' and ensure it returns 0 matches.

Renaming a symbol requires multiple passes — function definitions, call sites, and import/export statements are structurally distinct AST node types, so a single pattern won't catch all of them:

# Pass 1: rename the definition
ast-grep -p 'function oldName($$$P) { $$$B }' -r 'function newName($$$P) { $$$B }' -l ts src/

# Pass 2: rename all call sites (also catches bare references like arr.map(oldName))
ast-grep -p 'oldName($$$ARGS)' -r 'newName($$$ARGS)' -l ts src/

# Pass 3: rename named imports
ast-grep -p 'import { oldName } from $MOD' -r 'import { newName } from $MOD' -l ts src/

Note: AST matching is exact on identifiers, so oldNameHelper will NOT be affected — unlike a naive sed replace.


Phase 4: Bundled Graph Builders (Fallback)

While ast-grep + JSON pipelines are powerful, this skill includes bundled scripts for common graph building tasks when you need full AST traversal beyond simple pattern matching.

*Use these particularly when checking for dead code or circular dependencies.*

🤖 Note to AI Agent: When calling these bundled scripts, you must construct an absolute path by replacing <SKILL_DIR> with the absolute directory path where this SKILL.md file is located. Do not execute these with relative paths from the user's project root, or they will fail.

Python codebases:

python3 <SKILL_DIR>/scripts/build-graph.py <directory> [flags]

# Common Flags:
# --callers <symbol>  (find direct and transitive callers)
# --unused            (find dead code / unreferenced symbols)
# --depends-on <mod>  (find reverse dependencies)
# --cycles            (detect circular imports)

JavaScript/TypeScript codebases:

# Export a quick symbol list with line numbers
node <SKILL_DIR>/scripts/parse-js.mjs <file> --symbols

Quick Reference

I want to...ast-grep command
Find all calls to foo()ast-grep -p 'foo($$$ARGS)' src/
Find function definitionsast-grep -p 'function $NAME($$$P) {$$$B}' src/
Find unused importsast-grep scan --inline-rules '...' src/
Rename oldFn → newFn3 passes: definition, call sites, imports (see Workflow B)
Convert var → constast-grep -p 'var $N = $V' -r 'const $N = $V' --interactive src/
JSON output for scriptingast-grep -p '<pattern>' --json src/ > out.json
Check change impactBuild graph → find all transitive callers (reverse BFS)

Supporting Files

平台分布

Codex

36.54%
按下载量换算72

Claude

28.19%
按下载量换算55

Cursor

19.07%
按下载量换算37

Gemini CLI

9.8%
按下载量换算19

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

执行命令

安装流程涉及命令执行,可能通过 npx skills add https://github.com/rolandbrecht/agent-skills --skill ast-code-graph 联网下载 Skill 或依赖。用户安装前应确认命令来源、仓库内容和执行环境。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills