关于 grepai-init
这份技能指南介绍如何使用 `grepai init` 在项目中初始化 GrepAI。它说明生成的配置与索引目录、默认设置,以及开发者如何为项目或 monorepo 定制配置。
主要功能
- 01创建 `.grepai/` 目录和配置文件
- 02查看默认嵌入与存储设置
- 03调整切分、监控和忽略规则
- 04为项目或 monorepo 设置工作区
- 05验证或重置初始化
适用场景
- 01在新项目中设置 GrepAI
- 02定制嵌入或存储配置
- 03排除生成文件和第三方代码
- 04初始化 monorepo 或重置项目设置
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ yoanbernabeu/ grepai-skills --skill grepai-init安装后在 Claude Code 中输入/grepai-init确认已加载。
详细介绍
GrepAI 初始化
本技能介绍 grepai init 命令和项目初始化。
何时使用本技能
- 在新项目中设置 GrepAI
- 了解
grepai init会创建哪些内容 - 自定义初始配置
- 排查初始化问题
基本用法
cd /path/to/your/project
grepai init
Init 会创建什么
运行 grepai init 会创建 .grepai/ 目录,其中包含:
.grepai/
├── config.yaml # Configuration file
├── index.gob # Vector index (created by watch)
└── symbols.gob # Symbol index for trace (created by watch)
默认配置
生成的 config.yaml:
version: 1
embedder:
provider: ollama
model: nomic-embed-text
endpoint: http://localhost:11434
store:
backend: gob
chunking:
size: 512
overlap: 50
watch:
debounce_ms: 500
trace:
mode: fast
enabled_languages:
- .go
- .js
- .ts
- .jsx
- .tsx
- .py
- .php
- .c
- .h
- .cpp
- .hpp
- .cc
- .cxx
- .rs
- .zig
- .cs
- .pas
- .dpr
ignore:
- .git
- .grepai
- node_modules
- vendor
- target
- __pycache__
- dist
- build
了解默认设置
嵌入模型设置
| 设置 | 默认值 | 用途 |
|---|---|---|
provider | ollama | 本地生成嵌入向量 |
model | nomic-embed-text | 768 维模型 |
endpoint | http://localhost:11434 | Ollama API URL |
存储设置
| 设置 | 默认值 | 用途 |
|---|---|---|
backend | gob | 本地文件存储 |
分块设置
| 设置 | 默认值 | 用途 |
|---|---|---|
size | 512 | 每个块的令牌数 |
overlap | 50 | 上下文重叠量 |
监视设置
| 设置 | 默认值 | 用途 |
|---|---|---|
debounce_ms | 500 | 重新索引前的等待时间 |
忽略模式
默认模式会排除:
- 版本控制:
.git - GrepAI 数据:
.grepai - 依赖项:
node_modules、vendor - 构建输出:
target、dist、build - 缓存:
__pycache__
Init 后自定义配置
编辑 .grepai/config.yaml 进行自定义:
更改嵌入模型提供方
embedder:
provider: openai
model: text-embedding-3-small
api_key: ${OPENAI_API_KEY}
更改存储后端
store:
backend: postgres
postgres:
dsn: postgres://user:pass@localhost:5432/grepai
添加自定义忽略模式
ignore:
- .git
- .grepai
- node_modules
- "*.min.js"
- "*.bundle.js"
- coverage/
- .nyc_output/
在单体仓库中 Init
对于单体仓库,请在根目录执行 init:
cd /path/to/monorepo
grepai init
或者使用工作区创建单独的索引:
grepai workspace create my-workspace
grepai workspace add my-workspace /path/to/project1
grepai workspace add my-workspace /path/to/project2
重新初始化
如果需要重置:
# Remove existing config
rm -rf .grepai
# Re-initialize
grepai init
警告: 这会删除索引。你需要重新运行 grepai watch。
验证初始化
Init 后,运行以下命令进行验证:
# Check config exists
cat .grepai/config.yaml
# Check status (will show no index yet)
grepai status
常见问题
❌ 问题: .grepai 已存在
✅ 解决方案: 先删除它,或编辑现有配置:
rm -rf .grepai && grepai init
❌ 问题: 配置已创建,但 Ollama 未运行
✅ 解决方案: 在运行 grepai watch 前启动 Ollama:
ollama serve
❌ 问题: 在错误的目录中进行了初始化
✅ 解决方案: 移除 .grepai,然后在正确的目录中执行 init
最佳实践
- 在项目根目录执行 Init: 即主要代码所在的位置
- 将
.grepai/添加到.gitignore: 索引因机器而异 - 自定义忽略模式: 排除生成的代码或供应商代码
- Init 后检查配置: 根据你的技术栈进行调整
.gitignore 添加示例
# GrepAI
.grepai/
输出格式
初始化成功后:
✅ GrepAI Initialized
Config: .grepai/config.yaml
Default settings:
- Embedder: Ollama (nomic-embed-text)
- Storage: GOB (local file)
- Chunking: 512 tokens, 50 overlap
Next steps:
1. Ensure Ollama is running: ollama serve
2. Start indexing: grepai watch
评论
支持 Markdown