grepai-trace-callers by yoanbernabeu/grepai-skills
npx skills add https://github.com/yoanbernabeu/grepai-skills --skill grepai-trace-callers本技能涵盖使用 grepai trace callers 来查找调用特定函数或方法的所有代码位置。
grepai trace callers 回答:"谁调用了这个函数?"
func Login(user, pass) {...}
↑
│
┌───────┴───────────────────┐
│ Who calls Login()? │
├───────────────────────────┤
│ • HandleAuth (auth.go:42) │
│ • TestLogin (test.go:15) │
│ • CLI (main.go:88) │
└───────────────────────────┘
grepai trace callers "FunctionName"
grepai trace callers "Login"
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
输出:
🔍 Callers of "Login"
Found 3 callers:
1. HandleAuth
File: handlers/auth.go:42
Context: user.Login(ctx, credentials)
2. TestLoginSuccess
File: handlers/auth_test.go:15
Context: result := Login(testUser, testPass)
3. RunCLI
File: cmd/main.go:88
Context: err := auth.Login(username, password)
用于编程使用:
grepai trace callers "Login" --json
输出:
{
"query": "Login",
"mode": "callers",
"count": 3,
"results": [
{
"file": "handlers/auth.go",
"line": 42,
"caller": "HandleAuth",
"context": "user.Login(ctx, credentials)"
},
{
"file": "handlers/auth_test.go",
"line": 15,
"caller": "TestLoginSuccess",
"context": "result := Login(testUser, testPass)"
},
{
"file": "cmd/main.go",
"line": 88,
"caller": "RunCLI",
"context": "err := auth.Login(username, password)"
}
]
}
grepai trace callers "Login" --json --compact
输出:
{
"q": "Login",
"m": "callers",
"c": 3,
"r": [
{"f": "handlers/auth.go", "l": 42, "fn": "HandleAuth"},
{"f": "handlers/auth_test.go", "l": 15, "fn": "TestLoginSuccess"},
{"f": "cmd/main.go", "l": 88, "fn": "RunCLI"}
]
}
TOON 格式比 JSON 少用约 50% 的令牌:
grepai trace callers "Login" --toon
输出:
callers[3]:
- call_site:
context: "user.Login(ctx, credentials)"
file: handlers/auth.go
line: 42
symbol:
name: HandleAuth
...
注意:
--json和--toon是互斥的。
GrepAI 提供两种提取模式:
使用正则表达式模式。快速且无依赖。
grepai trace callers "Login" --mode fast
使用 tree-sitter AST 解析。更准确但需要 tree-sitter。
grepai trace callers "Login" --mode precise
| 模式 | 速度 | 准确性 | 依赖项 |
|---|---|---|---|
fast | ⚡⚡⚡ | 良好 | 无 |
precise | ⚡⚡ | 优秀 | tree-sitter |
在 .grepai/config.yaml 中配置追踪:
trace:
mode: fast # fast or precise
enabled_languages:
- .go
- .js
- .ts
- .py
- .php
- .rs
exclude_patterns:
- "*_test.go"
- "*.spec.ts"
| 语言 | 扩展名 |
|---|---|
| Go | .go |
| JavaScript | .js, .jsx |
| TypeScript | .ts, .tsx |
| Python | .py |
| PHP | .php |
| C/C++ | .c, .h, .cpp, .hpp, .cc, .cxx |
| Rust | .rs |
| Zig | .zig |
| C# | .cs |
| Java | .java |
| Pascal/Delphi | .pas, .dpr |
# 在重命名前查找所有用法
grepai trace callers "getUserById"
# 检查更改签名的影响
grepai trace callers "processPayment"
# 谁使用了这个核心函数?
grepai trace callers "validateToken"
# 查找模块的入口点
grepai trace callers "initialize"
# 这个函数是从哪里调用的?
grepai trace callers "problematicFunction"
# 在批准更改前验证函数用法
grepai trace callers "deprecatedMethod"
如果你的函数名很常见,结果可能包含不相关的代码:
grepai trace callers "get" # 太常见,会有很多误报
grepai trace callers "getUserProfile"
grepai trace callers "get" --json | jq '.results[] | select(.file | contains("auth"))'
结合使用以获得全面的理解:
# 查找 Login 的作用(语义)
grepai search "user login authentication"
# 查找谁使用了 Login(追踪)
grepai trace callers "Login"
# 统计调用者数量
grepai trace callers "MyFunction" --json | jq '.count'
# 获取调用者函数名
grepai trace callers "MyFunction" --json | jq -r '.results[].caller'
# 仅获取文件路径
grepai trace callers "MyFunction" --json | jq -r '.results[].file' | sort -u
import subprocess
import json
result = subprocess.run(
['grepai', 'trace', 'callers', 'Login', '--json'],
capture_output=True,
text=True
)
data = json.loads(result.stdout)
print(f"Found {data['count']} callers of Login:")
for r in data['results']:
print(f" - {r['caller']} in {r['file']}:{r['line']}")
❌ 问题: 未找到调用者 ✅ 解决方案:
enabled_languages 中grepai watch 以更新符号索引❌ 问题: 误报太多 ✅ 解决方案:
jq 过滤结果❌ 问题: 缺少某些调用者 ✅ 解决方案:
--mode precise 以获得更好的准确性grepai watchjq 或 grep追踪调用者结果:
🔍 Callers of "Login"
Mode: fast
Language files scanned: 245
Found 3 callers:
1. HandleAuth
File: handlers/auth.go:42
Context: user.Login(ctx, credentials)
2. TestLoginSuccess
File: handlers/auth_test.go:15
Context: result := Login(testUser, testPass)
3. RunCLI
File: cmd/main.go:88
Context: err := auth.Login(username, password)
Tip: Use --json for machine-readable output
Use --mode precise for more accurate results
每周安装量
300
仓库
GitHub 星标数
15
首次出现
2026年1月28日
安全审计
安装于
opencode244
codex236
gemini-cli219
github-copilot216
kimi-cli199
amp197
This skill covers using grepai trace callers to find all code locations that call a specific function or method.
grepai trace callers answers: "Who calls this function?"
func Login(user, pass) {...}
↑
│
┌───────┴───────────────────┐
│ Who calls Login()? │
├───────────────────────────┤
│ • HandleAuth (auth.go:42) │
│ • TestLogin (test.go:15) │
│ • CLI (main.go:88) │
└───────────────────────────┘
grepai trace callers "FunctionName"
grepai trace callers "Login"
Output:
🔍 Callers of "Login"
Found 3 callers:
1. HandleAuth
File: handlers/auth.go:42
Context: user.Login(ctx, credentials)
2. TestLoginSuccess
File: handlers/auth_test.go:15
Context: result := Login(testUser, testPass)
3. RunCLI
File: cmd/main.go:88
Context: err := auth.Login(username, password)
For programmatic use:
grepai trace callers "Login" --json
Output:
{
"query": "Login",
"mode": "callers",
"count": 3,
"results": [
{
"file": "handlers/auth.go",
"line": 42,
"caller": "HandleAuth",
"context": "user.Login(ctx, credentials)"
},
{
"file": "handlers/auth_test.go",
"line": 15,
"caller": "TestLoginSuccess",
"context": "result := Login(testUser, testPass)"
},
{
"file": "cmd/main.go",
"line": 88,
"caller": "RunCLI",
"context": "err := auth.Login(username, password)"
}
]
}
grepai trace callers "Login" --json --compact
Output:
{
"q": "Login",
"m": "callers",
"c": 3,
"r": [
{"f": "handlers/auth.go", "l": 42, "fn": "HandleAuth"},
{"f": "handlers/auth_test.go", "l": 15, "fn": "TestLoginSuccess"},
{"f": "cmd/main.go", "l": 88, "fn": "RunCLI"}
]
}
TOON format offers ~50% fewer tokens than JSON:
grepai trace callers "Login" --toon
Output:
callers[3]:
- call_site:
context: "user.Login(ctx, credentials)"
file: handlers/auth.go
line: 42
symbol:
name: HandleAuth
...
Note:
--jsonand--toonare mutually exclusive.
GrepAI offers two extraction modes:
Uses regex patterns. Fast and dependency-free.
grepai trace callers "Login" --mode fast
Uses tree-sitter AST parsing. More accurate but requires tree-sitter.
grepai trace callers "Login" --mode precise
| Mode | Speed | Accuracy | Dependencies |
|---|---|---|---|
fast | ⚡⚡⚡ | Good | None |
precise | ⚡⚡ | Excellent | tree-sitter |
Configure trace in .grepai/config.yaml:
trace:
mode: fast # fast or precise
enabled_languages:
- .go
- .js
- .ts
- .py
- .php
- .rs
exclude_patterns:
- "*_test.go"
- "*.spec.ts"
| Language | Extensions |
|---|---|
| Go | .go |
| JavaScript | .js, .jsx |
| TypeScript | .ts, .tsx |
| Python | .py |
| PHP | .php |
| C/C++ |
# Find all usages before renaming
grepai trace callers "getUserById"
# Check impact of changing signature
grepai trace callers "processPayment"
# Who uses this core function?
grepai trace callers "validateToken"
# Find entry points to a module
grepai trace callers "initialize"
# Where is this function called from?
grepai trace callers "problematicFunction"
# Verify function usage before approving changes
grepai trace callers "deprecatedMethod"
If your function name is common, results may include unrelated code:
grepai trace callers "get" # Too common, many false positives
grepai trace callers "getUserProfile"
grepai trace callers "get" --json | jq '.results[] | select(.file | contains("auth"))'
Use together for comprehensive understanding:
# Find what Login does (semantic)
grepai search "user login authentication"
# Find who uses Login (trace)
grepai trace callers "Login"
# Count callers
grepai trace callers "MyFunction" --json | jq '.count'
# Get caller function names
grepai trace callers "MyFunction" --json | jq -r '.results[].caller'
# Get file paths only
grepai trace callers "MyFunction" --json | jq -r '.results[].file' | sort -u
import subprocess
import json
result = subprocess.run(
['grepai', 'trace', 'callers', 'Login', '--json'],
capture_output=True,
text=True
)
data = json.loads(result.stdout)
print(f"Found {data['count']} callers of Login:")
for r in data['results']:
print(f" - {r['caller']} in {r['file']}:{r['line']}")
❌ Problem: No callers found ✅ Solutions:
enabled_languagesgrepai watch to update symbol index❌ Problem: Too many false positives ✅ Solutions:
jq❌ Problem: Missing some callers ✅ Solutions:
--mode precise for better accuracygrepai watch firstjq or grepTrace callers result:
🔍 Callers of "Login"
Mode: fast
Language files scanned: 245
Found 3 callers:
1. HandleAuth
File: handlers/auth.go:42
Context: user.Login(ctx, credentials)
2. TestLoginSuccess
File: handlers/auth_test.go:15
Context: result := Login(testUser, testPass)
3. RunCLI
File: cmd/main.go:88
Context: err := auth.Login(username, password)
Tip: Use --json for machine-readable output
Use --mode precise for more accurate results
Weekly Installs
300
Repository
GitHub Stars
15
First Seen
Jan 28, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode244
codex236
gemini-cli219
github-copilot216
kimi-cli199
amp197
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
140,500 周安装
Svelte 5 代码编写器 - SvelteKit CLI 工具,自动修复代码与文档查询
3,100 周安装
浏览器自动化专家指南:Playwright、Puppeteer、Selenium 最佳实践与反模式
3,100 周安装
Prisma Client API 参考 - 完整 ORM 7.x 查询、过滤、关联与事务指南
3,200 周安装
金融专家Skill:金融系统开发、支付处理与银行API集成专业指南
3,200 周安装
GitHub Copilot Spaces 使用指南:如何创建和管理项目专属AI助手空间
3,100 周安装
数据可视化指南:图表选择、Python代码与设计原则
3,100 周安装
.c, .h, .cpp, .hpp, .cc, .cxx |
| Rust | .rs |
| Zig | .zig |
| C# | .cs |
| Java | .java |
| Pascal/Delphi | .pas, .dpr |