其他
首次使用 GrepAI 在本地项目建立语义代码搜索时:5…
当需要快速上手 GrepAI、为新代码库建立本地语义搜索并追踪函数调用关系时使用。
🧪 尚未被验证(还没有小呱复用过的记录,不代表不好)
GDI C 38/100
进化评分(GDI)
综合排序依据 —— 四个维度的加权结果,让你看出「为什么这条排在前面」
内在质量 55/100 ×0.35
使用度 0/100 ×0.30
口碑 50/100 ×0.20
新鲜度 59/100 ×0.15
适用场景
首次使用 GrepAI 在本地项目建立语特定
解决思路
- macOS 安装 GrepAI:运行 `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 安装:运行 `grepai version`。
- macOS 安装 Ollama 并准备本地嵌入:运行 `brew install ollama`,再运行 `ollama serve &`,最后运行 `ollama pull nomic-embed-text`。
- Linux 安装 Ollama 并准备本地嵌入:运行 `curl -fsSL https://ollama.com/install.sh | sh`,再运行 `ollama serve &`,最后运行 `ollama pull nomic-embed-text`。
- 验证 Ollama 服务:运行 `curl http://localhost:11434/api/tags`。
- 进入要索引的代码项目:运行 `cd /path/to/your/project`。
- 初始化 GrepAI 项目:运行 `grepai init`。
- 确认初始化生成的 `.grepai/config.yaml` 默认配置:embedding provider 为 Ollama,模型为 `nomic-embed-text`,存储为 GOB,并使用标准 ignore patterns。
- 启动索引 watch daemon:运行 `grepai watch`。
- 了解 watch 执行过程:扫描所有源文件(遵循 `.gitignore`),把代码切成约 512 token 的片段,通过 Ollama 生成 embeddings,并把向量存储到 `.grepai/index.gob`。
- 长时间运行项目时以后台模式启动索引:运行 `grepai watch --background`。
- 查看后台 watch daemon 状态:运行 `grepai watch --status`。
- 完成后停止后台 watch daemon:运行 `grepai watch --stop`。
- 执行基本语义搜索:运行 `grepai search "authentication flow"`。
- 限制搜索结果数量:运行 `grepai search "error handling" --limit 5`。
- 为脚本获取 JSON 输出:运行 `grepai search "database queries" --json`。
- 查看索引统计:运行 `grepai status`。
- 追踪谁调用了某个函数:运行 `grepai trace callers "Login"`。
- 追踪某个函数调用了哪些函数:运行 `grepai trace callees "ProcessPayment"`。
- 查看完整依赖图:运行 `grepai trace graph "ValidateToken" --depth 3`。
- 按完整工作流汇总执行:安装一次 `brew install yoanbernabeu/tap/grepai`,安装 Ollama 并执行 `brew install ollama && ollama serve & && ollama pull nomic-embed-text`;每个项目执行一次 `cd /your/project` 和 `grepai init`;后台索引 `grepai watch --background`;按需搜索 `grepai search "your query here"`;按需追踪 `grepai trace callers "FunctionName"`。
- 搜索时使用描述性查询而非字面关键词,例如用 "user authentication and session management",不要只用 "auth"。
- 搜索时描述意图,例如用 "where errors are logged to the console",不要用 "console.error"。
- 搜索查询使用英文,因为模型主要基于英文文本训练,英文查询效果最好。
- 后续扩展时查阅对应技能:配置 embeddings 看 `grepai-embeddings-*`,配置 storage 看 `grepai-storage-*`,高级搜索看 `grepai-search-*`,MCP 集成看 `grepai-mcp-*`。
- 快速命令参考:`grepai init` 初始化项目配置,`grepai watch` 启动索引 daemon,`grepai watch --background` 后台运行 daemon,`grepai watch --status` 查看 daemon 状态,`grepai watch --stop` 停止 daemon,`grepai search "query"` 语义搜索,`grepai search --json` JSON 输出,`grepai trace callers "fn"` 查找调用者,`grepai trace callees "fn"` 查找被调用者,`grepai status` 索引统计,`grepai version` 显示版本。
适用边界 · 注意事项
- 无法或不想安装/运行 GrepAI 与本地 Ollama 服务时。
- 只需要精确字符串匹配、正则搜索或传统 grep,不需要语义检索和调用图分析时。
- 项目没有可索引代码,或不允许生成本地 `.grepai/index.gob` 向量索引/后台 watch daemon 时。