关于 grepai-quickstart
这是一份 GrepAI 入门指南,面向首次使用或为新项目配置代码搜索的开发者。它从安装、索引到语义搜索和调用关系分析,介绍基本工作流程。
主要功能
- 01安装并初始化 GrepAI
- 02通过 Ollama 生成嵌入
- 03监视并索引代码文件
- 04语义搜索代码
- 05追踪函数调用关系
适用场景
- 01在新项目中建立代码索引
- 02按意图查找相关实现
- 03以 JSON 格式获取搜索结果
- 04分析函数依赖关系
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ yoanbernabeu/ grepai-skills --skill grepai-quickstart安装后在 Claude Code 中输入/grepai-quickstart确认已加载。
详细介绍
GrepAI 快速入门
本技能提供完整的操作指南,帮助你在 5 分钟内运行 GrepAI 并搜索代码。
何时使用此技能
- 首次使用 GrepAI
- 需要快速回顾基本工作流程
- 在新项目中设置 GrepAI
- 向他人演示 GrepAI
前置条件
- 可访问终端
- 一个要建立索引的代码项目
步骤 1:安装 GrepAI
macOS
brew install yoanbernabeu/tap/grepai
Linux/macOS(替代方式)
curl -sSL https://raw.githubusercontent.com/yoanbernabeu/grepai/main/install.sh | sh
Windows
irm https://raw.githubusercontent.com/yoanbernabeu/grepai/main/install.ps1 | iex
验证:grepai version
步骤 2:安装 Ollama(本地嵌入)
macOS
brew install ollama
ollama serve &
ollama pull nomic-embed-text
Linux
curl -fsSL https://ollama.com/install.sh | sh
ollama serve &
ollama pull nomic-embed-text
验证:curl http://localhost:11434/api/tags
步骤 3:初始化项目
进入你的项目并初始化 GrepAI:
cd /path/to/your/project
grepai init
这会使用默认设置创建 .grepai/config.yaml:
- Ollama 作为嵌入提供方
nomic-embed-text模型- GOB 文件存储
- 标准忽略模式
步骤 4:开始建立索引
启动监视守护进程,为代码建立索引:
grepai watch
执行内容:
- 扫描所有源文件(遵循
.gitignore) - 将代码切分为约 512 个 token 的片段
- 通过 Ollama 生成嵌入
- 将向量存储在
.grepai/index.gob中
首次建立索引的输出:
🔍 GrepAI Watch
Scanning files...
Found 245 files
Processing chunks...
████████████████████████████████ 100%
Indexed 1,234 chunks
Watching for changes...
后台模式
对于长期运行的项目:
# Start in background
grepai watch --background
# Check status
grepai watch --status
# Stop when done
grepai watch --stop
步骤 5:搜索代码
现在可以进行语义搜索:
# Basic search
grepai search "authentication flow"
# Limit results
grepai search "error handling" --limit 5
# JSON output for scripts
grepai search "database queries" --json
示例输出
Score: 0.89 | src/auth/middleware.go:15-45
──────────────────────────────────────────
func AuthMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
token := c.GetHeader("Authorization")
if token == "" {
c.AbortWithStatus(401)
return
}
// Validate JWT token...
}
}
Score: 0.82 | src/auth/jwt.go:23-55
──────────────────────────────────────────
func ValidateToken(tokenString string) (*Claims, error) {
token, err := jwt.Parse(tokenString, func(t *jwt.Token) (interface{}, error) {
return []byte(secretKey), nil
})
// ...
}
步骤 6:分析调用图(可选)
追踪函数之间的关系:
# Who calls this function?
grepai trace callers "Login"
# What does this function call?
grepai trace callees "ProcessPayment"
# Full dependency graph
grepai trace graph "ValidateToken" --depth 3
完整工作流程摘要
# 1. Install (once)
brew install yoanbernabeu/tap/grepai
brew install ollama && ollama serve & && ollama pull nomic-embed-text
# 2. Setup project (once per project)
cd /your/project
grepai init
# 3. Index (run in background)
grepai watch --background
# 4. Search (as needed)
grepai search "your query here"
# 5. Trace (as needed)
grepai trace callers "FunctionName"
常用命令速查
| 命令 | 用途 |
|---|---|
grepai init | 初始化项目配置 |
grepai watch | 启动索引守护进程 |
grepai watch --background | 在后台运行守护进程 |
grepai watch --status | 检查守护进程状态 |
grepai watch --stop | 停止守护进程 |
grepai search "query" | 语义搜索 |
grepai search --json | JSON 输出 |
grepai trace callers "fn" | 查找调用方 |
grepai trace callees "fn" | 查找被调用方 |
grepai status | 索引统计信息 |
grepai version | 显示版本 |
搜索技巧
描述具体,不要照搬字面内容:
- ✅“用户身份验证和会话管理”
- ❌“auth”
描述意图:
- ✅“错误记录到控制台的位置”
- ❌“console.error”
使用英语:
- 模型主要基于英文文本训练
- 使用英文查询效果最佳
后续步骤
掌握基础知识后:
- **配置嵌入:**参阅
grepai-embeddings-*技能 - **设置存储:**参阅
grepai-storage-*技能 - **高级搜索:**参阅
grepai-search-*技能 - **MCP 集成:**参阅
grepai-mcp-*技能
输出格式
快速入门成功后的输出:
✅ GrepAI Quickstart Complete
Project: /path/to/your/project
Files indexed: 245
Chunks created: 1,234
Embedder: Ollama (nomic-embed-text)
Storage: GOB (local file)
Try these searches:
- grepai search "main entry point"
- grepai search "database connection"
- grepai search "error handling"
评论
支持 Markdown