自动同步项目中的 Agents.md、claude.md 和 gemini.md 文件,保持内容一致性。支持自动监听和手动触发。
自动同步项目中的 Agents.md、claude.md 和 gemini.md 文件,确保内容一致性。
无需额外依赖,只需要 Node.js 14+ 环境。
# 克隆或下载工具到你的项目
cd path/to/doc-sync-tool
chmod +x sync.js watch.js
在项目根目录执行:
node path/to/doc-sync-tool/sync.js
或者使用相对路径:
cd your-project-root
node doc-sync-tool/sync.js
输出示例:
🚀 开始扫描文档...
📂 扫描路径: /path/to/your-project
📋 目标文件: AGENTS.md, CLAUDE.md, GEMINI.md
✓ 找到 3 个目录包含目标文件
📁 处理目录: /path/to/your-project/websites/example
📄 源文件: CLAUDE.md (2025-11-27 10:30:45)
✨ 创建: AGENTS.md
✨ 创建: GEMINI.md
🎉 成功同步 2 个文件
============================================================
✅ 同步完成!
📊 处理目录: 3 个
📝 更新文件: 5 个
⏱️ 耗时: 0.23s
============================================================
启动监听服务:
node path/to/doc-sync-tool/watch.js
输出示例:
🚀 启动文档同步监听服务...
🔍 正在扫描现有文件...
✓ 找到 3 个目录包含目标文件
============================================================
👀 文件监听已启动!
📂 监听目录: /path/to/your-project
📋 目标文件: AGENTS.md, CLAUDE.md, GEMINI.md
🗂️ 监听中的目录: 1 个
💡 按 Ctrl+C 停止监听
============================================================
[10:35:20] 📝 检测到文件变化: /path/to/CLAUDE.md
[10:35:20] 📁 处理目录: /path/to
[10:35:20] 📄 源文件: CLAUDE.md
[10:35:20] ✅ 更新: AGENTS.md
[10:35:20] 🎉 成功同步 1 个文件
按 Ctrl+C 停止监听。
使用 PM2 管理进程:
# 安装 PM2(如果还没有)
npm install -g pm2
# 启动服务
pm2 start path/to/doc-sync-tool/watch.js --name doc-sync --cwd /path/to/your-project
# 查看状态
pm2 status
# 查看日志
pm2 logs doc-sync
# 停止服务
pm2 stop doc-sync
# 删除服务
pm2 delete doc-sync
# 开机自启动
pm2 startup
pm2 save
可以编辑 sync.js 修改配置:
const CONFIG = {
// 要同步的文件名列表
targetFiles: ['AGENTS.md', 'CLAUDE.md', 'GEMINI.md'],
// 扫描的根目录(默认为当前工作目录)
scanPath: process.cwd(),
// 排除的目录(不会扫描和监听)
excludeDirs: [
'node_modules',
'.git',
'.next',
'dist',
'.obsidian',
'build',
'out',
'_pagefind'
]
};
在项目中创建 CLAUDE.md,工具会自动创建 AGENTS.md 和 GEMINI.md。
修改任意一个文件(如 CLAUDE.md),其他两个文件会自动同步更新。
对多个项目的文档进行手动同步:
cd your-project-root
node doc-sync-tool/sync.js
chmod +x sync.js watch.js
确保在正确的目录下执行:
pwd # 查看当前目录
ls -la doc-sync-tool/ # 确认文件存在
node --version # 查看版本(需要 14+)
检查是否有文件被 Git 忽略或权限限制。
在 .git/hooks/post-commit 中添加:
#!/bin/bash
node path/to/doc-sync-tool/sync.js
在 GitHub Actions 中添加:
- name: Sync Doc Files
run: |
node doc-sync-tool/sync.js
git add -A
git commit -m "chore: sync agent docs" || true
MIT License
Ben (@littlebena)
提示: 建议使用 PM2 在后台运行监听服务,确保文档始终保持同步!
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer