Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions docs/daemon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# OpenViking Active Daemon

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file can be placed in docs/zh/agent-integrations


自动监听 Claude Code 会话日志,提取知识并写入 OpenViking 知识库。

## 快速开始

### 启用 Daemon

设置环境变量:

```bash
export OV_DAEMON_ENABLED=true
export OV_DAEMON_WATCH_DIR=~/.claude/projects # 监听目录(可选)
export OV_DAEMON_BATCH_LINES=50 # 批处理触发行数(可选)
export OV_DAEMON_BATCH_SECONDS=300 # 批处理触发秒数(可选)
```

### 启动 OpenViking Server

```bash
openviking serve
```

Daemon 会在服务器启动时自动运行(如果 `OV_DAEMON_ENABLED=true`)。

## 工作原理

1. **文件监听** — 监控 `~/.claude/projects/` 下的 `.jsonl` 文件变化
2. **增量读取** — 文件游标技术,只处理新增内容
3. **批量处理** — 累积 50 行或 5 分钟后触发 ETL 管道
4. **知识提取** — 调用 LLM 过滤噪声,提取有价值的知识
5. **自动存储** — 写入 `viking://resources/skills/`、`viking://resources/memories/`、`viking://resources/`

## 知识分类

| 类型 | 目标路径 | 说明 |
|------|---------|------|
| Skills | `viking://resources/skills/<source>/<title>.md` | 可复用的操作指南 |
| Memories (有项目) | `viking://resources/memories/<project>/decisions.md` | 项目决策日志 |
| Memories (无项目) | `viking://resources/memories/global/<title>.md` | 全局记忆 |
| Resources | `viking://resources/<tech>/<title>.md` | 参考资源 |

> **注意**:viking:// URI 只支持 `resources/`、`user/`、`agent/` 三个顶级 scope。所有知识统一路由到 `resources/` 下。

## 架构

```
Claude Code JSONL → File Watcher → Batch Buffer → Filter → Reconstruct
→ LLM Extract → Deduplicate → Route → viking:// Storage
```

## 故障排查

### Daemon 未启动
检查日志中是否有 `Active Daemon is disabled` 消息,确认 `OV_DAEMON_ENABLED=true`。

### 没有提取到知识
- 确认 Claude Code 正在写入 JSONL 文件(`~/.claude/projects/` 下有 `.jsonl` 文件)
- 对话内容可能不够有价值(简单问答会被过滤)
- 查看日志中的 ETL 处理信息

### 知识写入失败
检查 OpenViking ResourceService 是否正常运行。
85 changes: 85 additions & 0 deletions docs/daemon/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Active Daemon 配置指南

## 环境变量

| 变量 | 说明 | 默认值 |
|------|------|--------|
| `OV_DAEMON_ENABLED` | 启用 Daemon | `false` |
| `OV_DAEMON_WATCH_DIR` | 监听目录 | `~/.claude/projects` |
| `OV_DAEMON_DB_PATH` | 游标数据库路径 | `~/.qoderworkcn/openviking/daemon_cursors.db` |
| `OV_DAEMON_BATCH_LINES` | 批处理触发行数 | `50` |
| `OV_DAEMON_BATCH_SECONDS` | 批处理触发秒数 | `300` |

## JSON 配置 (ov.conf)

> **重要**:daemon 配置必须放在 `"server"` 节内,不是顶层配置。ov.conf 的 JSON 解析器不支持 `#` 注释。

单 watcher 配置:

```json
{
"server": {
"port": 1988,
"daemon": {
"enabled": true,
"watch_dir": "~/.claude/projects",
"batch_trigger_lines": 50,
"batch_trigger_seconds": 300
}
}
}
```

多 watcher 配置(推荐,支持同时监听多个 AI 工具):

```json
{
"server": {
"port": 1988,
"daemon": {
"enabled": true,
"watchers": [
{
"tool_name": "claude_code",
"watch_dir": "C:\\Users\\xxx\\.claude\\projects",
"batch_trigger_lines": 5,
"batch_trigger_seconds": 60
},
{
"tool_name": "cursor_db",
"watch_dir": "C:\\Users\\xxx\\AppData\\Roaming\\Cursor\\User\\globalStorage",
"poll_interval": 60
}
]
}
}
}
```

`watchers` 数组中每项支持 `tool_name`、`watch_dir`、`batch_trigger_lines`、`batch_trigger_seconds`、`extra` 字段。当 `watchers` 存在时,顶层的 `watch_dir` 被忽略。

## Docker 部署

```yaml
services:
openviking:
image: openviking:latest
environment:
- OV_DAEMON_ENABLED=true
- OV_DAEMON_WATCH_DIR=/data/claude-projects
- OV_DAEMON_DB_PATH=/data/daemon.db
volumes:
- ./claude-projects:/data/claude-projects
- ./daemon-data:/data
ports:
- "1933:1933"
```

## 日志

Daemon 使用 OpenViking 标准日志系统。关键日志:

- `Claude Code watcher started on ...` — 监听器启动
- `Flushing batch with N events` — 批处理触发
- `Extracted N knowledge items` — 知识提取完成
- `Knowledge ingested: viking://...` — 知识写入成功
Loading