grepai-trace-callees
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGrepAI Trace Callees
GrepAI Trace Callees
This skill covers using to find all functions called by a specific function.
grepai trace callees本技能介绍如何使用查找某个特定函数调用的所有函数。
grepai trace calleesWhen to Use This Skill
适用场景
- Understanding function dependencies
- Mapping function behavior
- Finding deeply nested dependencies
- Code comprehension and documentation
- 理解函数依赖关系
- 映射函数行为
- 查找深层嵌套依赖
- 代码理解与文档编写
What is Trace Callees?
什么是Trace Callees?
grepai trace calleesfunc ProcessOrder(order) {
validateOrder(order)
calculateTotal(order)
sendConfirmation(order.email)
}
│
↓
┌───────┴───────────────────┐
│ What does ProcessOrder │
│ call? │
├───────────────────────────┤
│ • validateOrder │
│ • calculateTotal │
│ • sendConfirmation │
└───────────────────────────┘grepai trace calleesfunc ProcessOrder(order) {
validateOrder(order)
calculateTotal(order)
sendConfirmation(order.email)
}
│
↓
┌───────┴───────────────────┐
│ What does ProcessOrder │
│ call? │
├───────────────────────────┤
│ • validateOrder │
│ • calculateTotal │
│ • sendConfirmation │
└───────────────────────────┘Basic Usage
基础用法
bash
grepai trace callees "FunctionName"bash
grepai trace callees "FunctionName"Example
示例
bash
grepai trace callees "ProcessOrder"Output:
🔍 Callees of "ProcessOrder"
Found 4 callees:
1. validateOrder
File: services/order.go:45
Context: validateOrder(order)
2. calculateTotal
File: services/order.go:48
Context: total := calculateTotal(order.Items)
3. applyDiscount
File: services/order.go:51
Context: total = applyDiscount(total, order.Coupon)
4. sendConfirmation
File: services/order.go:55
Context: sendConfirmation(order.Email, total)bash
grepai trace callees "ProcessOrder"输出:
🔍 Callees of "ProcessOrder"
Found 4 callees:
1. validateOrder
File: services/order.go:45
Context: validateOrder(order)
2. calculateTotal
File: services/order.go:48
Context: total := calculateTotal(order.Items)
3. applyDiscount
File: services/order.go:51
Context: total = applyDiscount(total, order.Coupon)
4. sendConfirmation
File: services/order.go:55
Context: sendConfirmation(order.Email, total)JSON Output
JSON格式输出
bash
grepai trace callees "ProcessOrder" --jsonOutput:
json
{
"query": "ProcessOrder",
"mode": "callees",
"count": 4,
"results": [
{
"file": "services/order.go",
"line": 45,
"callee": "validateOrder",
"context": "validateOrder(order)"
},
{
"file": "services/order.go",
"line": 48,
"callee": "calculateTotal",
"context": "total := calculateTotal(order.Items)"
},
{
"file": "services/order.go",
"line": 51,
"callee": "applyDiscount",
"context": "total = applyDiscount(total, order.Coupon)"
},
{
"file": "services/order.go",
"line": 55,
"callee": "sendConfirmation",
"context": "sendConfirmation(order.Email, total)"
}
]
}bash
grepai trace callees "ProcessOrder" --json输出:
json
{
"query": "ProcessOrder",
"mode": "callees",
"count": 4,
"results": [
{
"file": "services/order.go",
"line": 45,
"callee": "validateOrder",
"context": "validateOrder(order)"
},
{
"file": "services/order.go",
"line": 48,
"callee": "calculateTotal",
"context": "total := calculateTotal(order.Items)"
},
{
"file": "services/order.go",
"line": 51,
"callee": "applyDiscount",
"context": "total = applyDiscount(total, order.Coupon)"
},
{
"file": "services/order.go",
"line": 55,
"callee": "sendConfirmation",
"context": "sendConfirmation(order.Email, total)"
}
]
}Compact JSON (AI Optimized)
紧凑JSON格式(AI优化)
bash
grepai trace callees "ProcessOrder" --json --compactOutput:
json
{
"q": "ProcessOrder",
"m": "callees",
"c": 4,
"r": [
{"f": "services/order.go", "l": 45, "fn": "validateOrder"},
{"f": "services/order.go", "l": 48, "fn": "calculateTotal"},
{"f": "services/order.go", "l": 51, "fn": "applyDiscount"},
{"f": "services/order.go", "l": 55, "fn": "sendConfirmation"}
]
}bash
grepai trace callees "ProcessOrder" --json --compact输出:
json
{
"q": "ProcessOrder",
"m": "callees",
"c": 4,
"r": [
{"f": "services/order.go", "l": 45, "fn": "validateOrder"},
{"f": "services/order.go", "l": 48, "fn": "calculateTotal"},
{"f": "services/order.go", "l": 51, "fn": "applyDiscount"},
{"f": "services/order.go", "l": 55, "fn": "sendConfirmation"}
]
}TOON Output (v0.26.0+)
TOON格式输出(v0.26.0及以上版本)
TOON format offers ~50% fewer tokens than JSON:
bash
grepai trace callees "ProcessOrder" --toonNote:and--jsonare mutually exclusive.--toon
TOON格式的令牌数比JSON少约50%:
bash
grepai trace callees "ProcessOrder" --toon注意:和--json参数互斥。--toon
Extraction Modes
提取模式
Fast Mode (Default)
快速模式(默认)
bash
grepai trace callees "ProcessOrder" --mode fastbash
grepai trace callees "ProcessOrder" --mode fastPrecise Mode
精确模式
bash
grepai trace callees "ProcessOrder" --mode precise| Mode | Speed | Accuracy | Dependencies |
|---|---|---|---|
| ⚡⚡⚡ | Good | None |
| ⚡⚡ | Excellent | tree-sitter |
bash
grepai trace callees "ProcessOrder" --mode precise| 模式 | 速度 | 准确率 | 依赖 |
|---|---|---|---|
| ⚡⚡⚡ | 良好 | 无 |
| ⚡⚡ | 优秀 | tree-sitter |
Use Cases
使用场景
Understanding Function Behavior
理解函数行为
bash
undefinedbash
undefinedWhat does this complex function do?
这个复杂函数的作用是什么?
grepai trace callees "handleRequest"
grepai trace callees "handleRequest"
Map the data flow
映射数据流
grepai trace callees "processPayment"
undefinedgrepai trace callees "processPayment"
undefinedFinding Dependencies
查找依赖关系
bash
undefinedbash
undefinedWhat external services does this call?
该函数调用了哪些外部服务?
grepai trace callees "syncData"
grepai trace callees "syncData"
What database operations happen?
执行了哪些数据库操作?
grepai trace callees "saveUser"
undefinedgrepai trace callees "saveUser"
undefinedCode Review
代码审查
bash
undefinedbash
undefinedWhat side effects does this function have?
该函数有哪些副作用?
grepai trace callees "updateProfile"
grepai trace callees "updateProfile"
Is this function doing too much?
这个函数是否职责过多?
grepai trace callees "doEverything" # Lots of callees = code smell
undefinedgrepai trace callees "doEverything" # 大量被调用方 = 代码异味
undefinedDocumentation
文档编写
bash
undefinedbash
undefinedGenerate dependency list for docs
为文档生成依赖列表
grepai trace callees "initialize" --json | jq '.results[].callee'
undefinedgrepai trace callees "initialize" --json | jq '.results[].callee'
undefinedCallers vs Callees
Callers与Callees对比
| Command | Question | Use Case |
|---|---|---|
| Who calls me? | Impact analysis |
| What do I call? | Behavior analysis |
bash
undefined| 命令 | 解决的问题 | 适用场景 |
|---|---|---|
| 谁调用了我? | 影响分析 |
| 我调用了什么? | 行为分析 |
bash
undefinedCombined analysis
组合分析
grepai trace callers "processOrder" # Who uses this?
grepai trace callees "processOrder" # What does it do?
undefinedgrepai trace callers "processOrder" # 谁在使用这个函数?
grepai trace callees "processOrder" # 这个函数的作用是什么?
undefinedFiltering Results
结果过滤
By File Type
按文件类型过滤
bash
undefinedbash
undefinedGet callees and filter to only .go files
获取被调用方并仅筛选.go文件
grepai trace callees "main" --json | jq '.results[] | select(.file | endswith(".go"))'
undefinedgrepai trace callees "main" --json | jq '.results[] | select(.file | endswith(".go"))'
undefinedExclude Test Functions
排除测试函数
bash
grepai trace callees "Login" --json | jq '.results[] | select(.callee | startswith("Test") | not)'bash
grepai trace callees "Login" --json | jq '.results[] | select(.callee | startswith("Test") | not)'Count by Category
按类别统计
bash
undefinedbash
undefinedCount how many database vs. API calls
统计数据库调用与API调用的数量
grepai trace callees "processOrder" --json | jq '.results[].callee' | grep -c "db"
undefinedgrepai trace callees "processOrder" --json | jq '.results[].callee' | grep -c "db"
undefinedWhat Callees Includes
Callees包含的内容
The trace finds:
- Direct function calls
- Method calls
- Built-in function calls (depending on mode)
该追踪功能可查找:
- 直接函数调用
- 方法调用
- 内置函数调用(取决于模式)
Example
示例
go
func ProcessOrder(order Order) error {
// Direct call
validateOrder(order)
// Method call
order.Validate()
// Package function
utils.Log("processing")
// Built-in (may or may not be captured)
fmt.Println("done")
return nil
}Callees found:
validateOrder- (method)
Validate - (from utils)
Log - (depending on mode)
Println
go
func ProcessOrder(order Order) error {
// 直接调用
validateOrder(order)
// 方法调用
order.Validate()
// 包函数
utils.Log("processing")
// 内置函数(可能会被捕获,也可能不会)
fmt.Println("done")
return nil
}找到的被调用方:
validateOrder- (方法)
Validate - (来自utils包)
Log - (取决于模式)
Println
Limitations
局限性
What Callees Might Miss
Callees可能遗漏的内容
- Dynamic/runtime calls
- Callbacks and closures
- Interface method calls (may show interface, not implementation)
- Reflection-based calls
- 动态/运行时调用
- 回调与闭包
- 接口方法调用(可能显示接口而非实现)
- 基于反射的调用
Example of Undetected Call
未被检测到的调用示例
go
func process(fn func()) {
fn() // Callee is unknown at static analysis time
}go
func process(fn func()) {
fn() // 静态分析时无法确定被调用方
}Combining with Trace Graph
与Trace Graph结合使用
For recursive dependency analysis, use trace graph:
bash
undefined如需进行递归依赖分析,可使用trace graph:
bash
undefinedDirect callees only
仅查看直接被调用方
grepai trace callees "main"
grepai trace callees "main"
Full dependency tree (recursive)
完整依赖树(递归)
grepai trace graph "main" --depth 3
undefinedgrepai trace graph "main" --depth 3
undefinedScripting Examples
脚本示例
List All Callees
列出所有被调用方
bash
grepai trace callees "main" --json | jq -r '.results[].callee' | sort -ubash
grepai trace callees "main" --json | jq -r '.results[].callee' | sort -uCheck for Specific Callee
检查特定被调用方
bash
undefinedbash
undefinedDoes processOrder call sendEmail?
processOrder是否调用了sendEmail?
grepai trace callees "processOrder" --json | jq -e '.results[] | select(.callee == "sendEmail")' && echo "Yes" || echo "No"
undefinedgrepai trace callees "processOrder" --json | jq -e '.results[] | select(.callee == "sendEmail")' && echo "是" || echo "否"
undefinedGenerate Dependency Report
生成依赖报告
bash
#!/bin/bash
echo "# Function Dependencies Report"
echo ""
for fn in main initialize processOrder; do
echo "## $fn"
grepai trace callees "$fn" --json | jq -r '.results[].callee' | sed 's/^/- /'
echo ""
donebash
#!/bin/bash
echo "# 函数依赖报告"
echo ""
for fn in main initialize processOrder; do
echo "## $fn"
grepai trace callees "$fn" --json | jq -r '.results[].callee' | sed 's/^/- /'
echo ""
doneCommon Issues
常见问题
❌ Problem: Function not found
✅ Solution: Check spelling and ensure function exists in indexed files
❌ Problem: No callees found (but function has calls)
✅ Solutions:
- Try
--mode precise - Check language is in
enabled_languages - Ensure symbols.gob is up to date ()
grepai watch
❌ Problem: Missing some callees
✅ Solution: Use for better accuracy
--mode precise❌ 问题: 未找到函数
✅ 解决方案: 检查拼写并确保函数存在于已索引的文件中
❌ 问题: 未找到被调用方(但函数确实有调用)
✅ 解决方案:
- 尝试使用参数
--mode precise - 检查语言是否在中
enabled_languages - 确保symbols.gob是最新的(使用)
grepai watch
❌ 问题: 遗漏部分被调用方
✅ 解决方案: 使用参数以获得更高的准确率
--mode preciseBest Practices
最佳实践
- Use for understanding: Great for learning new codebases
- Combine with callers: Full dependency picture
- Use graph for deep analysis: When you need recursion
- Filter results: Focus on relevant callees
- Document findings: Export to markdown for docs
- 用于代码理解: 非常适合学习新代码库
- 与callers结合使用: 获得完整的依赖关系图
- 使用graph进行深度分析: 需要递归分析时使用
- 过滤结果: 聚焦于相关的被调用方
- 记录结果: 导出为Markdown格式用于文档
Output Format
输出格式
Trace callees result:
🔍 Callees of "ProcessOrder"
Mode: fast
Function found in: services/order.go:40
Found 4 callees:
1. validateOrder
File: services/order.go:45
Context: validateOrder(order)
2. calculateTotal
File: services/order.go:48
Context: total := calculateTotal(order.Items)
3. applyDiscount
File: services/order.go:51
Context: total = applyDiscount(total, order.Coupon)
4. sendConfirmation
File: services/order.go:55
Context: sendConfirmation(order.Email, total)
Tip: Use 'grepai trace graph ProcessOrder' for recursive analysisTrace callees的结果示例:
🔍 Callees of "ProcessOrder"
Mode: fast
Function found in: services/order.go:40
Found 4 callees:
1. validateOrder
File: services/order.go:45
Context: validateOrder(order)
2. calculateTotal
File: services/order.go:48
Context: total := calculateTotal(order.Items)
3. applyDiscount
File: services/order.go:51
Context: total = applyDiscount(total, order.Coupon)
4. sendConfirmation
File: services/order.go:55
Context: sendConfirmation(order.Email, total)
Tip: Use 'grepai trace graph ProcessOrder' for recursive analysis