doc-sync-tool

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

文档同步工具 (Doc Sync Tool)

Doc Sync Tool

功能说明

Feature Description

这个工具用于自动同步项目中的 AI Agent 配置文档,确保
Agents.md
claude.md
gemini.md
三个文件内容保持一致。
This tool is used to automatically sync AI Agent configuration documents in the project, ensuring that the content of the three files
Agents.md
,
claude.md
and
gemini.md
remains consistent.

核心功能

Core Features

  1. 自动发现: 递归扫描当前目录下所有文件夹,查找这三个文档
  2. 智能同步: 发现任意一个文档时,自动创建/更新其余两个
  3. 文件监听: 实时监听文件变化,自动同步最新内容
  4. 手动触发: 支持命令行手动执行同步
  1. Auto Discovery: Recursively scan all folders in the current directory to find these three documents
  2. Intelligent Sync: When any one of the documents is found, automatically create/update the other two
  3. File Monitoring: Real-time monitoring of file changes, automatically sync the latest content
  4. Manual Trigger: Supports manual execution of sync via command line

使用场景

Usage Scenarios

  • 在多个 AI Agent 之间共享相同的项目配置
  • 自动保持不同 AI 的工作指令一致
  • 避免手动维护多个相同文档的麻烦
  • Share the same project configuration among multiple AI Agents
  • Automatically keep work instructions consistent across different AIs
  • Avoid the hassle of manually maintaining multiple identical documents

使用方法

Usage Methods

安装依赖

Install Dependencies

bash
cd /Users/ben/Downloads/go\ to\ wild/auto-website-system/_skills/doc-sync-tool
pnpm install
bash
cd /Users/ben/Downloads/go\ to\ wild/auto-website-system/_skills/doc-sync-tool
pnpm install

手动同步(单次执行)

Manual Sync (One-time Execution)

bash
undefined
bash
undefined

在项目根目录执行

Execute in the project root directory

node /Users/ben/Downloads/go\ to\ wild/auto-website-system/_skills/doc-sync-tool/sync.js
node /Users/ben/Downloads/go\ to\ wild/auto-website-system/_skills/doc-sync-tool/sync.js

或者使用 npm script

Or use npm script

pnpm run sync
undefined
pnpm run sync
undefined

自动监听(持续运行)

Auto Monitoring (Continuous Run)

bash
undefined
bash
undefined

启动文件监听服务

Start the file monitoring service

node /Users/ben/Downloads/go\ to\ wild/auto-website-system/_skills/doc-sync-tool/watch.js
node /Users/ben/Downloads/go\ to\ wild/auto-website-system/_skills/doc-sync-tool/watch.js

或者使用 npm script

Or use npm script

pnpm run watch
undefined
pnpm run watch
undefined

后台运行(推荐)

Run in Background (Recommended)

bash
undefined
bash
undefined

使用 PM2 在后台运行

Run in background using PM2

pm2 start /Users/ben/Downloads/go\ to\ wild/auto-website-system/_skills/doc-sync-tool/watch.js --name doc-sync
pm2 start /Users/ben/Downloads/go\ to\ wild/auto-website-system/_skills/doc-sync-tool/watch.js --name doc-sync

查看状态

Check status

pm2 status
pm2 status

停止服务

Stop service

pm2 stop doc-sync
undefined
pm2 stop doc-sync
undefined

工作原理

Working Principle

  1. 扫描阶段: 递归遍历指定目录,查找
    Agents.md
    claude.md
    gemini.md
    文件
  2. 分组阶段: 将同一文件夹下的这三个文件归为一组
  3. 同步阶段:
    • 如果某组只有一个文件,复制内容创建其余两个
    • 如果某组有多个文件,选择最新修改的作为源,同步到其他文件
  4. 监听阶段 (watch 模式): 持续监听文件变化,触发同步
  1. Scanning Phase: Recursively traverse the specified directory to find
    Agents.md
    ,
    claude.md
    ,
    gemini.md
    files
  2. Grouping Phase: Group these three files in the same folder into one group
  3. Sync Phase:
    • If a group has only one file, copy its content to create the other two
    • If a group has multiple files, select the most recently modified one as the source and sync to other files
  4. Monitoring Phase (watch mode): Continuously monitor file changes and trigger sync

配置选项

Configuration Options

可以在
sync.js
中修改以下配置:
javascript
const CONFIG = {
  targetFiles: ['Agents.md', 'claude.md', 'gemini.md'],  // 目标文件列表
  scanPath: process.cwd(),                                // 扫描路径(默认当前目录)
  excludeDirs: ['node_modules', '.git', '.next', 'dist'] // 排除目录
};
You can modify the following configurations in
sync.js
:
javascript
const CONFIG = {
  targetFiles: ['Agents.md', 'claude.md', 'gemini.md'],  // Target file list
  scanPath: process.cwd(),                                // Scan path (current directory by default)
  excludeDirs: ['node_modules', '.git', '.next', 'dist'] // Excluded directories
};

注意事项

Notes

  • 工具会自动跳过
    node_modules
    .git
    .next
    dist
    等目录
  • 同步时会保留文件的原始格式和内容
  • 建议在 Git 仓库中使用,方便追踪文件变化
  • 监听模式会持续运行,建议使用 PM2 管理进程
  • The tool will automatically skip directories such as
    node_modules
    ,
    .git
    ,
    .next
    ,
    dist
  • The original format and content of the files will be preserved during sync
  • It is recommended to use in a Git repository for easy tracking of file changes
  • The monitoring mode runs continuously, it is recommended to use PM2 to manage the process

故障排除

Troubleshooting

权限问题

Permission Issues

bash
chmod +x sync.js watch.js
bash
chmod +x sync.js watch.js

Node.js 版本要求

Node.js Version Requirement

需要 Node.js 14+ 版本
Node.js 14+ is required

依赖安装失败

Dependency Installation Failure

bash
rm -rf node_modules package-lock.json
pnpm install
bash
rm -rf node_modules package-lock.json
pnpm install