grepai-watch-daemon
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGrepAI Watch Daemon
GrepAI 监控守护进程
This skill covers the command and daemon management for real-time code indexing.
grepai watch此技能涵盖命令以及用于实时代码索引的守护进程管理。
grepai watchWhen to Use This Skill
何时使用此技能
- Starting initial code indexing
- Setting up real-time file monitoring
- Running the daemon in background
- Troubleshooting indexing issues
- 启动初始代码索引
- 设置实时文件监控
- 在后台运行守护进程
- 排查索引相关问题
What the Watch Daemon Does
监控守护进程的功能
The watch daemon:
- Scans all source files in your project
- Chunks code into segments (~512 tokens)
- Generates embeddings via your configured provider
- Stores vectors in your configured backend
- Monitors for file changes in real-time
- Updates the index when files change
监控守护进程会:
- 扫描项目中的所有源文件
- 拆分代码为片段(约512个tokens)
- 生成嵌入向量(通过你配置的提供商)
- 存储向量到你配置的后端
- 实时监控文件变更
- 文件变更时更新索引
Basic Usage
基础用法
Start Watching (Foreground)
启动监控(前台模式)
bash
cd /your/project
grepai watchOutput:
🔍 GrepAI Watch
Scanning files...
Found 245 files
Processing chunks...
████████████████████████████████ 100%
Indexed 1,234 chunks
Watching for changes...Press to stop.
Ctrl+Cbash
cd /your/project
grepai watch输出:
🔍 GrepAI Watch
正在扫描文件...
找到245个文件
正在处理代码片段...
████████████████████████████████ 100%
已索引1,234个代码片段
正在监控变更...按停止。
Ctrl+CStart in Background
后台启动
bash
grepai watch --backgroundOutput:
🔍 GrepAI Watch (background)
Daemon started with PID 12345
Log file: ~/.grepai/daemon.logbash
grepai watch --background输出:
🔍 GrepAI Watch (background)
守护进程已启动,PID为12345
日志文件: ~/.grepai/daemon.logCheck Daemon Status
检查守护进程状态
bash
grepai watch --statusOutput:
✅ GrepAI Daemon Running
PID: 12345
Started: 2025-01-28 10:30:00
Project: /path/to/project
Statistics:
- Files indexed: 245
- Chunks: 1,234
- Last update: 2 minutes agobash
grepai watch --status输出:
✅ GrepAI 守护进程正在运行
PID: 12345
启动时间: 2025-01-28 10:30:00
项目路径: /path/to/project
统计信息:
- 已索引文件数: 245
- 代码片段数: 1,234
- 最后更新时间: 2分钟前Stop the Daemon
停止守护进程
bash
grepai watch --stopOutput:
✅ Daemon stopped (PID 12345)bash
grepai watch --stop输出:
✅ 守护进程已停止(PID 12345)Command Reference
命令参考
| Command | Description |
|---|---|
| Start daemon in foreground |
| Start daemon in background |
| Check daemon status |
| Stop running daemon |
| 命令 | 描述 |
|---|---|
| 前台启动守护进程 |
| 后台启动守护进程 |
| 检查守护进程状态 |
| 停止运行中的守护进程 |
Configuration
配置
Watch Settings
监控设置
yaml
undefinedyaml
undefined.grepai/config.yaml
.grepai/config.yaml
watch:
Debounce delay in milliseconds
Groups rapid file changes together
debounce_ms: 500
undefinedwatch:
防抖延迟(毫秒)
将频繁的文件变更合并处理
debounce_ms: 500
undefinedDebounce Explained
防抖机制说明
When you save a file, editors often write multiple times quickly. Debouncing waits for changes to settle:
| Value | Behavior |
|---|---|
| More responsive, more reindexing |
| Balanced (default) |
| Less responsive, fewer reindexing |
当你保存文件时,编辑器通常会快速多次写入。防抖机制会等待变更稳定后再处理:
| 数值 | 行为 |
|---|---|
| 响应更快,重新索引更频繁 |
| 平衡模式(默认) |
| 响应较慢,重新索引次数更少 |
Initial Indexing
初始索引
What Gets Indexed
索引范围
The daemon indexes files:
- Matching supported extensions (.go, .js, .ts, .py, etc.)
- Not in ignore patterns (node_modules, .git, etc.)
- Respecting
.gitignore
守护进程会索引以下文件:
- 匹配支持的扩展名(.go、.js、.ts、.py等)
- 不在忽略规则内(node_modules、.git等)
- 遵循配置
.gitignore
Indexing Progress
索引进度
Large codebases show progress:
Scanning files...
Found 10,245 files
Processing chunks...
████████████████░░░░░░░░░░░░░░░░ 50% (5,122/10,245)大型代码库会显示进度:
正在扫描文件...
找到10,245个文件
正在处理代码片段...
████████████████░░░░░░░░░░░░░░░░ 50% (5,122/10,245)Indexing Time Estimates
索引时间预估
| Codebase | Files | Time (Ollama) | Time (OpenAI) |
|---|---|---|---|
| Small | 100 | ~30s | ~10s |
| Medium | 1,000 | ~5min | ~1min |
| Large | 10,000 | ~30min | ~5min |
| 代码库规模 | 文件数 | 耗时(Ollama) | 耗时(OpenAI) |
|---|---|---|---|
| 小型 | 100 | ~30秒 | ~10秒 |
| 中型 | 1,000 | ~5分钟 | ~1分钟 |
| 大型 | 10,000 | ~30分钟 | ~5分钟 |
Real-Time Monitoring
实时监控
After initial indexing, the daemon watches for:
- File creation
- File modification
- File deletion
- File renames
初始索引完成后,守护进程会监控以下操作:
- 文件创建
- 文件修改
- 文件删除
- 文件重命名
File Change Detection
文件变更检测
Uses OS-native file watching:
- macOS: FSEvents
- Linux: inotify
- Windows: ReadDirectoryChangesW
使用操作系统原生的文件监控机制:
- macOS: FSEvents
- Linux: inotify
- Windows: ReadDirectoryChangesW
What Triggers Reindexing
触发重新索引的操作
| Action | Result |
|---|---|
| Save existing file | Re-embed file chunks |
| Create new file | Index new chunks |
| Delete file | Remove from index |
| Rename file | Update path, keep vectors |
| 操作 | 结果 |
|---|---|
| 保存现有文件 | 重新嵌入该文件的代码片段 |
| 创建新文件 | 索引新的代码片段 |
| 删除文件 | 从索引中移除 |
| 重命名文件 | 更新路径,保留向量数据 |
Background Daemon Management
后台守护进程管理
Starting on System Boot
开机自启配置
macOS (launchd)
macOS(launchd)
Create :
~/Library/LaunchAgents/com.grepai.watch.plistxml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.grepai.watch</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/grepai</string>
<string>watch</string>
</array>
<key>WorkingDirectory</key>
<string>/path/to/your/project</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>Load:
bash
launchctl load ~/Library/LaunchAgents/com.grepai.watch.plist创建:
~/Library/LaunchAgents/com.grepai.watch.plistxml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.grepai.watch</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/grepai</string>
<string>watch</string>
</array>
<key>WorkingDirectory</key>
<string>/path/to/your/project</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>加载配置:
bash
launchctl load ~/Library/LaunchAgents/com.grepai.watch.plistLinux (systemd)
Linux(systemd)
Create :
~/.config/systemd/user/grepai-watch.serviceini
[Unit]
Description=GrepAI Watch Daemon
After=network.target
[Service]
Type=simple
WorkingDirectory=/path/to/your/project
ExecStart=/usr/local/bin/grepai watch
Restart=always
[Install]
WantedBy=default.targetEnable:
bash
systemctl --user enable grepai-watch
systemctl --user start grepai-watch创建:
~/.config/systemd/user/grepai-watch.serviceini
[Unit]
Description=GrepAI Watch Daemon
After=network.target
[Service]
Type=simple
WorkingDirectory=/path/to/your/project
ExecStart=/usr/local/bin/grepai watch
Restart=always
[Install]
WantedBy=default.target启用并启动:
bash
systemctl --user enable grepai-watch
systemctl --user start grepai-watchChecking Logs
查看日志
bash
undefinedbash
undefinedBackground daemon logs
后台守护进程日志
tail -f ~/.grepai/daemon.log
tail -f ~/.grepai/daemon.log
Or with systemd
或者使用systemd查看
journalctl --user -u grepai-watch -f
undefinedjournalctl --user -u grepai-watch -f
undefinedMultiple Projects
多项目管理
One Daemon Per Project
每个项目一个守护进程
Run separate daemons for each project:
bash
undefined为每个项目运行独立的守护进程:
bash
undefinedTerminal 1: Project A
终端1:项目A
cd /path/to/project-a
grepai watch --background
cd /path/to/project-a
grepai watch --background
Terminal 2: Project B
终端2:项目B
cd /path/to/project-b
grepai watch --background
undefinedcd /path/to/project-b
grepai watch --background
undefinedUsing Workspaces
使用工作区
For multi-project setups:
bash
grepai workspace create my-workspace
grepai workspace add my-workspace /path/to/project-a
grepai workspace add my-workspace /path/to/project-b
grepai watch --workspace my-workspace针对多项目场景:
bash
grepai workspace create my-workspace
grepai workspace add my-workspace /path/to/project-a
grepai workspace add my-workspace /path/to/project-b
grepai watch --workspace my-workspaceTroubleshooting
故障排查
Daemon Won't Start
守护进程无法启动
❌ Problem: "Another daemon is already running"
✅ Solution:
bash
grepai watch --stop
grepai watch --background❌ Problem: "Config not found"
✅ Solution: Initialize first:
bash
grepai init
grepai watch❌ Problem: "Embedder connection failed"
✅ Solution: Start your embedding provider:
bash
ollama serve # For Ollama❌ 问题: "Another daemon is already running"(已有另一个守护进程在运行)
✅ 解决方案:
bash
grepai watch --stop
grepai watch --background❌ 问题: "Config not found"(未找到配置)
✅ 解决方案: 先初始化配置:
bash
grepai init
grepai watch❌ 问题: "Embedder connection failed"(嵌入提供商连接失败)
✅ 解决方案: 启动你的嵌入提供商:
bash
ollama serve # 针对OllamaIndexing Issues
索引问题
❌ Problem: Files not being indexed
✅ Solution: Check ignore patterns in config, ensure file extension is supported
❌ Problem: Indexing very slow
✅ Solutions:
- Use OpenAI for faster cloud embeddings
- Add more ignore patterns
- Increase chunking size
❌ Problem: Index seems outdated
✅ Solution: Clear and reindex:
bash
rm .grepai/index.gob
grepai watch❌ 问题: 文件未被索引
✅ 解决方案: 检查配置中的忽略规则,确保文件扩展名受支持
❌ 问题: 索引速度极慢
✅ 解决方案:
- 使用OpenAI的云端嵌入服务以提高速度
- 添加更多忽略规则
- 增大代码片段拆分尺寸
❌ 问题: 索引内容过时
✅ 解决方案: 清除并重新索引:
bash
rm .grepai/index.gob
grepai watchFile Watch Issues
文件监控问题
❌ Problem: Changes not detected
✅ Solutions:
- Reduce debounce_ms
- Check inotify limits (Linux):
bash
echo 65536 | sudo tee /proc/sys/fs/inotify/max_user_watches
❌ 问题: 变更未被检测到
✅ 解决方案:
- 减小debounce_ms数值
- 检查inotify限制(Linux):
bash
echo 65536 | sudo tee /proc/sys/fs/inotify/max_user_watches
Best Practices
最佳实践
- Run in background: For continuous monitoring
- Use workspace for monorepos: Better organization
- Set up auto-start: launchd or systemd
- Check logs periodically: Monitor for errors
- Reindex after config changes: Especially after changing embedding model
- 后台运行: 用于持续监控
- 为单体仓库使用工作区: 更好的组织管理
- 配置开机自启: 使用launchd或systemd
- 定期查看日志: 监控错误情况
- 配置变更后重新索引: 尤其是在更改嵌入模型后
Status Check
状态检查
Regular health check:
bash
grepai statusOutput:
✅ GrepAI Status
Project: /path/to/project
Config: .grepai/config.yaml
Embedder: Ollama (nomic-embed-text)
Storage: GOB (.grepai/index.gob)
Index:
- Files: 245
- Chunks: 1,234
- Size: 12.5 MB
- Last updated: 2025-01-28 10:30:00
Daemon: Running (PID 12345)定期进行健康检查:
bash
grepai status输出:
✅ GrepAI 状态正常
项目路径: /path/to/project
配置文件: .grepai/config.yaml
嵌入提供商: Ollama (nomic-embed-text)
存储后端: GOB (.grepai/index.gob)
索引信息:
- 文件数: 245
- 代码片段数: 1,234
- 索引大小: 12.5 MB
- 最后更新时间: 2025-01-28 10:30:00
守护进程状态: 运行中(PID 12345)Output Format
输出格式
Watch daemon status:
✅ Watch Daemon Active
Mode: Background
PID: 12345
Project: /path/to/project
Initial Index:
- Files scanned: 245
- Chunks created: 1,234
- Duration: 45s
Real-time Monitor:
- Debounce: 500ms
- Events processed: 23
- Last event: 5 minutes ago
Next steps:
- Run 'grepai search "query"' to search
- Run 'grepai watch --status' to check status
- Run 'grepai watch --stop' to stop daemon监控守护进程状态输出:
✅ 监控守护进程已激活
模式: 后台
PID: 12345
项目路径: /path/to/project
初始索引信息:
- 已扫描文件数: 245
- 已创建代码片段数: 1,234
- 耗时: 45秒
实时监控信息:
- 防抖延迟: 500ms
- 已处理事件数: 23
- 最后事件时间: 5分钟前
下一步操作:
- 运行'grepai search "query"'进行搜索
- 运行'grepai watch --status'检查状态
- 运行'grepai watch --stop'停止守护进程