grepai-trace-graph by yoanbernabeu/grepai-skills
npx skills add https://github.com/yoanbernabeu/grepai-skills --skill grepai-trace-graph此技能涵盖使用 grepai trace graph 构建完整的调用图,以递归方式显示所有依赖关系。
grepai trace graph 构建一个递归的依赖树:
main
├── initialize
│ ├── loadConfig
│ │ └── parseYAML
│ └── connectDB
│ ├── createPool
│ └── ping
├── startServer
│ ├── registerRoutes
│ │ ├── authMiddleware
│ │ └── loggingMiddleware
│ └── listen
└── gracefulShutdown
└── closeDB
grepai trace graph "FunctionName"
grepai trace graph "main"
输出:
🔍 Call Graph for "main"
main
├── initialize
│ ├── loadConfig
│ └── connectDB
├── startServer
│ ├── registerRoutes
│ └── listen
└── gracefulShutdown
└── closeDB
Nodes: 9
Max depth: 3
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
使用 --depth 限制递归深度:
# 默认深度(2 层)
grepai trace graph "main"
# 更深层次的分析(3 层)
grepai trace graph "main" --depth 3
# 浅层(1 层,与 callees 相同)
grepai trace graph "main" --depth 1
# 非常深(5 层)
grepai trace graph "main" --depth 5
--depth 1 (与 callees 相同):
main
├── initialize
├── startServer
└── gracefulShutdown
--depth 2 (默认):
main
├── initialize
│ ├── loadConfig
│ └── connectDB
├── startServer
│ ├── registerRoutes
│ └── listen
└── gracefulShutdown
└── closeDB
--depth 3 :
main
├── initialize
│ ├── loadConfig
│ │ └── parseYAML
│ └── connectDB
│ ├── createPool
│ └── ping
├── startServer
│ ├── registerRoutes
│ │ ├── authMiddleware
│ │ └── loggingMiddleware
│ └── listen
└── gracefulShutdown
└── closeDB
grepai trace graph "main" --depth 2 --json
输出:
{
"query": "main",
"mode": "graph",
"depth": 2,
"root": {
"name": "main",
"file": "cmd/main.go",
"line": 10,
"children": [
{
"name": "initialize",
"file": "cmd/main.go",
"line": 15,
"children": [
{
"name": "loadConfig",
"file": "config/config.go",
"line": 20,
"children": []
},
{
"name": "connectDB",
"file": "db/db.go",
"line": 30,
"children": []
}
]
},
{
"name": "startServer",
"file": "server/server.go",
"line": 25,
"children": [
{
"name": "registerRoutes",
"file": "server/routes.go",
"line": 10,
"children": []
}
]
}
]
},
"stats": {
"nodes": 6,
"max_depth": 2
}
}
grepai trace graph "main" --depth 2 --json --compact
输出:
{
"q": "main",
"d": 2,
"r": {
"n": "main",
"c": [
{"n": "initialize", "c": [{"n": "loadConfig"}, {"n": "connectDB"}]},
{"n": "startServer", "c": [{"n": "registerRoutes"}]}
]
},
"s": {"nodes": 6, "depth": 2}
}
TOON 格式比 JSON 少用约 50% 的令牌:
grepai trace graph "main" --depth 2 --toon
注意:
--json和--toon是互斥的。
# 快速模式(基于正则表达式)
grepai trace graph "main" --mode fast
# 精确模式(tree-sitter AST)
grepai trace graph "main" --mode precise
# 映射整个应用程序启动过程
grepai trace graph "main" --depth 4
# 哪些功能依赖这个工具函数?
grepai trace graph "validateInput" --depth 3
# 更改数据库层的完整影响
grepai trace graph "executeQuery" --depth 2
# 这个函数是否过于复杂?
grepai trace graph "processOrder" --depth 5
# 节点多 = 复杂度高
# 生成架构图数据
grepai trace graph "main" --depth 3 --json > architecture.json
# 如果更改这个,什么会出问题?
grepai trace graph "legacyAuth" --depth 3
GrepAI 检测并标记循环依赖:
main
├── processA
│ └── processB
│ └── processA [CYCLE]
在 JSON 中:
{
"name": "processA",
"cycle": true
}
对于非常大的代码库,图可能会过于庞大:
# 从浅层开始
grepai trace graph "main" --depth 2
# 不追踪 main,而是追踪特定的子系统
grepai trace graph "authMiddleware" --depth 3
# 获取 JSON 并进行过滤
grepai trace graph "main" --depth 3 --json | jq '...'
# 将 JSON 转换为 DOT
grepai trace graph "main" --depth 3 --json | python3 << 'EOF'
import json
import sys
data = json.load(sys.stdin)
print("digraph G {")
print(" rankdir=TB;")
def traverse(node, parent=None):
name = node.get('name') or node.get('n')
if parent:
print(f' "{parent}" -> "{name}";')
children = node.get('children') or node.get('c') or []
for child in children:
traverse(child, name)
traverse(data.get('root') or data.get('r'))
print("}")
EOF
然后渲染:
dot -Tpng graph.dot -o graph.png
grepai trace graph "main" --depth 2 --json | python3 << 'EOF'
import json
import sys
data = json.load(sys.stdin)
print("```mermaid")
print("graph TD")
def traverse(node, parent=None):
name = node.get('name') or node.get('n')
if parent:
print(f" {parent} --> {name}")
children = node.get('children') or node.get('c') or []
for child in children:
traverse(child, name)
traverse(data.get('root') or data.get('r'))
print("```")
EOF
随时间跟踪复杂度:
# 获取节点数
grepai trace graph "main" --depth 3 --json | jq '.stats.nodes'
# 比较重构前后的情况
echo "Before: $(grepai trace graph 'main' --depth 3 --json | jq '.stats.nodes') nodes"
# ... 重构 ...
echo "After: $(grepai trace graph 'main' --depth 3 --json | jq '.stats.nodes') nodes"
❌ 问题: 图太大 / 超时 ✅ 解决方案:
--depth 2main--mode fast❌ 问题: 检测到许多循环依赖 ✅ 解决方案: 这表明代码中存在循环依赖。考虑进行重构。
❌ 问题: 缺少分支 ✅ 解决方案:
--mode precise--depth 2 开始,根据需要增加main追踪图结果:
🔍 Call Graph for "main"
Depth: 3
Mode: fast
main
├── initialize
│ ├── loadConfig
│ │ └── parseYAML
│ └── connectDB
│ ├── createPool
│ └── ping
├── startServer
│ ├── registerRoutes
│ │ ├── authMiddleware
│ │ └── loggingMiddleware
│ └── listen
└── gracefulShutdown
└── closeDB
Statistics:
- Total nodes: 12
- Maximum depth reached: 3
- Cycles detected: 0
Tip: Use --json for machine-readable output
Use --depth N to control recursion depth
每周安装量
304
仓库
GitHub 星标数
15
首次出现
2026 年 1 月 28 日
安全审计
安装于
opencode244
codex236
gemini-cli217
github-copilot214
kimi-cli201
amp199
This skill covers using grepai trace graph to build complete call graphs showing all dependencies recursively.
grepai trace graph builds a recursive dependency tree:
main
├── initialize
│ ├── loadConfig
│ │ └── parseYAML
│ └── connectDB
│ ├── createPool
│ └── ping
├── startServer
│ ├── registerRoutes
│ │ ├── authMiddleware
│ │ └── loggingMiddleware
│ └── listen
└── gracefulShutdown
└── closeDB
grepai trace graph "FunctionName"
grepai trace graph "main"
Output:
🔍 Call Graph for "main"
main
├── initialize
│ ├── loadConfig
│ └── connectDB
├── startServer
│ ├── registerRoutes
│ └── listen
└── gracefulShutdown
└── closeDB
Nodes: 9
Max depth: 3
Limit recursion depth with --depth:
# Default depth (2 levels)
grepai trace graph "main"
# Deeper analysis (3 levels)
grepai trace graph "main" --depth 3
# Shallow (1 level, same as callees)
grepai trace graph "main" --depth 1
# Very deep (5 levels)
grepai trace graph "main" --depth 5
--depth 1 (same as callees):
main
├── initialize
├── startServer
└── gracefulShutdown
--depth 2 (default):
main
├── initialize
│ ├── loadConfig
│ └── connectDB
├── startServer
│ ├── registerRoutes
│ └── listen
└── gracefulShutdown
└── closeDB
--depth 3 :
main
├── initialize
│ ├── loadConfig
│ │ └── parseYAML
│ └── connectDB
│ ├── createPool
│ └── ping
├── startServer
│ ├── registerRoutes
│ │ ├── authMiddleware
│ │ └── loggingMiddleware
│ └── listen
└── gracefulShutdown
└── closeDB
grepai trace graph "main" --depth 2 --json
Output:
{
"query": "main",
"mode": "graph",
"depth": 2,
"root": {
"name": "main",
"file": "cmd/main.go",
"line": 10,
"children": [
{
"name": "initialize",
"file": "cmd/main.go",
"line": 15,
"children": [
{
"name": "loadConfig",
"file": "config/config.go",
"line": 20,
"children": []
},
{
"name": "connectDB",
"file": "db/db.go",
"line": 30,
"children": []
}
]
},
{
"name": "startServer",
"file": "server/server.go",
"line": 25,
"children": [
{
"name": "registerRoutes",
"file": "server/routes.go",
"line": 10,
"children": []
}
]
}
]
},
"stats": {
"nodes": 6,
"max_depth": 2
}
}
grepai trace graph "main" --depth 2 --json --compact
Output:
{
"q": "main",
"d": 2,
"r": {
"n": "main",
"c": [
{"n": "initialize", "c": [{"n": "loadConfig"}, {"n": "connectDB"}]},
{"n": "startServer", "c": [{"n": "registerRoutes"}]}
]
},
"s": {"nodes": 6, "depth": 2}
}
TOON format offers ~50% fewer tokens than JSON:
grepai trace graph "main" --depth 2 --toon
Note:
--jsonand--toonare mutually exclusive.
# Fast mode (regex-based)
grepai trace graph "main" --mode fast
# Precise mode (tree-sitter AST)
grepai trace graph "main" --mode precise
# Map entire application startup
grepai trace graph "main" --depth 4
# What depends on this utility function?
grepai trace graph "validateInput" --depth 3
# Full impact of changing database layer
grepai trace graph "executeQuery" --depth 2
# Is this function too complex?
grepai trace graph "processOrder" --depth 5
# Many nodes = high complexity
# Generate architecture diagram data
grepai trace graph "main" --depth 3 --json > architecture.json
# What would break if we change this?
grepai trace graph "legacyAuth" --depth 3
GrepAI detects and marks circular dependencies:
main
├── processA
│ └── processB
│ └── processA [CYCLE]
In JSON:
{
"name": "processA",
"cycle": true
}
For very large codebases, graphs can be overwhelming:
# Start shallow
grepai trace graph "main" --depth 2
# Instead of main, trace specific subsystem
grepai trace graph "authMiddleware" --depth 3
# Get JSON and filter
grepai trace graph "main" --depth 3 --json | jq '...'
# Convert JSON to DOT
grepai trace graph "main" --depth 3 --json | python3 << 'EOF'
import json
import sys
data = json.load(sys.stdin)
print("digraph G {")
print(" rankdir=TB;")
def traverse(node, parent=None):
name = node.get('name') or node.get('n')
if parent:
print(f' "{parent}" -> "{name}";')
children = node.get('children') or node.get('c') or []
for child in children:
traverse(child, name)
traverse(data.get('root') or data.get('r'))
print("}")
EOF
Then render:
dot -Tpng graph.dot -o graph.png
grepai trace graph "main" --depth 2 --json | python3 << 'EOF'
import json
import sys
data = json.load(sys.stdin)
print("```mermaid")
print("graph TD")
def traverse(node, parent=None):
name = node.get('name') or node.get('n')
if parent:
print(f" {parent} --> {name}")
children = node.get('children') or node.get('c') or []
for child in children:
traverse(child, name)
traverse(data.get('root') or data.get('r'))
print("```")
EOF
Track complexity over time:
# Get node count
grepai trace graph "main" --depth 3 --json | jq '.stats.nodes'
# Compare before/after refactoring
echo "Before: $(grepai trace graph 'main' --depth 3 --json | jq '.stats.nodes') nodes"
# ... refactoring ...
echo "After: $(grepai trace graph 'main' --depth 3 --json | jq '.stats.nodes') nodes"
❌ Problem: Graph too large / timeout ✅ Solutions:
--depth 2main--mode fast❌ Problem: Many cycles detected ✅ Solution: This indicates circular dependencies in code. Consider refactoring.
❌ Problem: Missing branches ✅ Solutions:
--mode precise--depth 2, increase as neededmainTrace graph result:
🔍 Call Graph for "main"
Depth: 3
Mode: fast
main
├── initialize
│ ├── loadConfig
│ │ └── parseYAML
│ └── connectDB
│ ├── createPool
│ └── ping
├── startServer
│ ├── registerRoutes
│ │ ├── authMiddleware
│ │ └── loggingMiddleware
│ └── listen
└── gracefulShutdown
└── closeDB
Statistics:
- Total nodes: 12
- Maximum depth reached: 3
- Cycles detected: 0
Tip: Use --json for machine-readable output
Use --depth N to control recursion depth
Weekly Installs
304
Repository
GitHub Stars
15
First Seen
Jan 28, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode244
codex236
gemini-cli217
github-copilot214
kimi-cli201
amp199
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
138,300 周安装