Dogfooding 设置
用 Context Chain 分析它自己。两个实例、两个 Memgraph、一套代码。
为什么要两个实例?
在真实代码上测试完整 pipeline,同时为 Context Chain 自己的开发提供决策图谱。两个 Memgraph 完全隔离。
架构
~/dev/context-chain/ ← 产品(你在开发的东西)
├── Memgraph :7687 ← 存业务 repo 的决策
├── Dashboard :3001
└── .mcp.json ← 指向 context-chain-dev 的 MCP server
~/dev/context-chain-dev/ ← Dogfood 实例
├── Memgraph :7688 ← 存 context-chain 自身的决策
├── Dashboard :3003
├── Memgraph Lab :3002
└── ckg.config.json ← repos: [{ name: "context-chain", path: "..." }]设置步骤
1. 克隆 Dogfood 实例
bash
cd ~/dev
git clone [email protected]:YOUR_ORG/context-chain.git context-chain-dev
cd context-chain-dev
npm install2. 配置端口
修改 context-chain-dev 的 docker-compose.yml,避免端口冲突:
| 组件 | 生产 | Dogfood |
|---|---|---|
| Memgraph (bolt) | 7687 | 7688 |
| Memgraph Lab | 3000 | 3002 |
| Dashboard | 3001 | 3003 |
yaml
services:
memgraph:
container_name: ckg-memgraph-dev
ports:
- "7688:7687"
- "7445:7444"
volumes:
- memgraph-data-dev:/var/lib/memgraph
- memgraph-log-dev:/var/log/memgraph
memgraph-lab:
container_name: ckg-memgraph-lab-dev
ports:
- "3002:3000"
volumes:
memgraph-data-dev:
memgraph-log-dev:3. 配置目标 Repo
修改 context-chain-dev 的 ckg.config.json:
json
{
"project": "context-chain",
"ai": { "provider": "claude-cli" },
"repos": [
{
"name": "context-chain",
"path": "/absolute/path/to/context-chain",
"type": "backend",
"cpgFile": "data/context-chain.json",
"language": "javascript",
"srcDir": "src",
"packages": []
}
]
}4. 创建运行脚本
在 context-chain-dev 里创建 run.sh:
bash
#!/bin/bash
export CKG_MEMGRAPH_PORT=7688
export DASHBOARD_PORT=3003
exec npm run "$@"bash
chmod +x run.sh5. 启动
bash
docker compose up -d
CKG_MEMGRAPH_PORT=7688 npm run db:schema
./run.sh dashboard # → http://localhost:30036. 跑 Pipeline
在 localhost:3003 Dashboard 上:
- System → 为
context-chain生成 CPG - Run → 执行完整 pipeline
- Overview → 确认决策出现
7. 连接 MCP
在 ~/dev/context-chain/.mcp.json 中:
json
{
"mcpServers": {
"context-chain": {
"command": "/bin/bash",
"args": ["/absolute/path/to/context-chain-dev/mcp-start.sh"],
"env": {
"CKG_MEMGRAPH_PORT": "7688"
}
}
}
}这样在 ~/dev/context-chain 里用 Claude Code 时,就能查询关于自己代码库的设计决策了。
日常使用
| 任务 | 命令 |
|---|---|
| 启动 dogfood Memgraph | cd context-chain-dev && docker compose up -d |
| 打开 dogfood Dashboard | ./run.sh dashboard → localhost:3003 |
| 运行任意脚本 | ./run.sh <script>(自动设端口 7688) |
| 重新生成 CPG | Dashboard → System → Regenerate CPG |
| 看生产数据 | localhost:3001(端口 7687) |
| 看 dogfood 数据 | localhost:3003(端口 7688) |
注意事项
- 不要推 dev 专用文件:
ckg.config.json、docker-compose.yml、run.sh、.env应该在 gitignore 里 - 代码改动先在 dev 里做: 在
context-chain-dev里改和测试,然后再 push/pull 到生产 repo - CPG 过期检测 从第二次生成 CPG 开始才生效(第一次没有旧的 hash 基线可以对比)