grepai-watch-daemon

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GrepAI Watch Daemon

GrepAI 监控守护进程

This skill covers the
grepai watch
command and daemon management for real-time code indexing.
此技能涵盖
grepai watch
命令以及用于实时代码索引的守护进程管理。

When 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:
  1. Scans all source files in your project
  2. Chunks code into segments (~512 tokens)
  3. Generates embeddings via your configured provider
  4. Stores vectors in your configured backend
  5. Monitors for file changes in real-time
  6. Updates the index when files change
监控守护进程会:
  1. 扫描项目中的所有源文件
  2. 拆分代码为片段(约512个tokens)
  3. 生成嵌入向量(通过你配置的提供商)
  4. 存储向量到你配置的后端
  5. 实时监控文件变更
  6. 文件变更时更新索引

Basic Usage

基础用法

Start Watching (Foreground)

启动监控(前台模式)

bash
cd /your/project
grepai watch
Output:
🔍 GrepAI Watch
   Scanning files...
   Found 245 files
   Processing chunks...
   ████████████████████████████████ 100%
   Indexed 1,234 chunks
   Watching for changes...
Press
Ctrl+C
to stop.
bash
cd /your/project
grepai watch
输出:
🔍 GrepAI Watch
   正在扫描文件...
   找到245个文件
   正在处理代码片段...
   ████████████████████████████████ 100%
   已索引1,234个代码片段
   正在监控变更...
Ctrl+C
停止。

Start in Background

后台启动

bash
grepai watch --background
Output:
🔍 GrepAI Watch (background)
   Daemon started with PID 12345
   Log file: ~/.grepai/daemon.log
bash
grepai watch --background
输出:
🔍 GrepAI Watch (background)
   守护进程已启动,PID为12345
   日志文件: ~/.grepai/daemon.log

Check Daemon Status

检查守护进程状态

bash
grepai watch --status
Output:
✅ 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 ago
bash
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 --stop
Output:
✅ Daemon stopped (PID 12345)
bash
grepai watch --stop
输出:
✅ 守护进程已停止(PID 12345)

Command Reference

命令参考

CommandDescription
grepai watch
Start daemon in foreground
grepai watch --background
Start daemon in background
grepai watch --status
Check daemon status
grepai watch --stop
Stop running daemon
命令描述
grepai watch
前台启动守护进程
grepai watch --background
后台启动守护进程
grepai watch --status
检查守护进程状态
grepai watch --stop
停止运行中的守护进程

Configuration

配置

Watch Settings

监控设置

yaml
undefined
yaml
undefined

.grepai/config.yaml

.grepai/config.yaml

watch:

Debounce delay in milliseconds

Groups rapid file changes together

debounce_ms: 500
undefined
watch:

防抖延迟(毫秒)

将频繁的文件变更合并处理

debounce_ms: 500
undefined

Debounce Explained

防抖机制说明

When you save a file, editors often write multiple times quickly. Debouncing waits for changes to settle:
ValueBehavior
100
More responsive, more reindexing
500
Balanced (default)
1000
Less responsive, fewer reindexing
当你保存文件时,编辑器通常会快速多次写入。防抖机制会等待变更稳定后再处理:
数值行为
100
响应更快,重新索引更频繁
500
平衡模式(默认)
1000
响应较慢,重新索引次数更少

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

索引时间预估

CodebaseFilesTime (Ollama)Time (OpenAI)
Small100~30s~10s
Medium1,000~5min~1min
Large10,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

触发重新索引的操作

ActionResult
Save existing fileRe-embed file chunks
Create new fileIndex new chunks
Delete fileRemove from index
Rename fileUpdate path, keep vectors
操作结果
保存现有文件重新嵌入该文件的代码片段
创建新文件索引新的代码片段
删除文件从索引中移除
重命名文件更新路径,保留向量数据

Background Daemon Management

后台守护进程管理

Starting on System Boot

开机自启配置

macOS (launchd)

macOS(launchd)

Create
~/Library/LaunchAgents/com.grepai.watch.plist
:
xml
<?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.plist
xml
<?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.plist

Linux (systemd)

Linux(systemd)

Create
~/.config/systemd/user/grepai-watch.service
:
ini
[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
Enable:
bash
systemctl --user enable grepai-watch
systemctl --user start grepai-watch
创建
~/.config/systemd/user/grepai-watch.service
ini
[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-watch

Checking Logs

查看日志

bash
undefined
bash
undefined

Background daemon logs

后台守护进程日志

tail -f ~/.grepai/daemon.log
tail -f ~/.grepai/daemon.log

Or with systemd

或者使用systemd查看

journalctl --user -u grepai-watch -f
undefined
journalctl --user -u grepai-watch -f
undefined

Multiple Projects

多项目管理

One Daemon Per Project

每个项目一个守护进程

Run separate daemons for each project:
bash
undefined
为每个项目运行独立的守护进程:
bash
undefined

Terminal 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
undefined
cd /path/to/project-b grepai watch --background
undefined

Using 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-workspace

Troubleshooting

故障排查

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  # 针对Ollama

Indexing 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 watch

File 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

最佳实践

  1. Run in background: For continuous monitoring
  2. Use workspace for monorepos: Better organization
  3. Set up auto-start: launchd or systemd
  4. Check logs periodically: Monitor for errors
  5. Reindex after config changes: Especially after changing embedding model
  1. 后台运行: 用于持续监控
  2. 为单体仓库使用工作区: 更好的组织管理
  3. 配置开机自启: 使用launchd或systemd
  4. 定期查看日志: 监控错误情况
  5. 配置变更后重新索引: 尤其是在更改嵌入模型后

Status Check

状态检查

Regular health check:
bash
grepai status
Output:
✅ 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'停止守护进程