基于 Bun + TypeScript 的命令行工具,用于通过 WebDAV 在多台设备之间同步 AI 编码工具配置与工作目录。
它面向 .claude、.cursor、.opencode 等 AI 开发工具场景,支持多 profile、源目录类型与部署方式分离的同步模型(sourceType + deployMode)、远程锁、安全扫描、钩子扩展与配置校验。
如果你会在多台设备之间切换开发环境,通常会遇到这些问题:
ai-coding-sync 旨在提供一个统一的 CLI,同步这些 AI coding 配置,并尽量保持:
WebDAV 同步后端
二维同步模型
sourceType:描述 .ai-coding-sync 下源目录是否为 Git 仓库,可取 auto / git / filedeployMode:描述部署到目标位置时使用 link(ln -s)或 copy(cp)git/file × link/copy 的 2×2 同步矩阵多 profile 配置
sourceType、deployMode、strategy、conflict、webdav 等选项多 mapping 管理
sourceType / deployMode / ignore / hooks安全与诊断
doctor 环境诊断并发控制
可扩展自动化
bun install
bun run dev -- --help
项目已在 package.json 中声明 bin:
{
"bin": {
"ai-coding-sync": "./src/index.ts"
}
}
如需全局或本地链接,可按 Bun/包管理器常规方式处理。
bun run dev -- init
bun run dev -- status
bun run dev -- sync
bun run dev -- push
bun run dev -- pull
项目使用统一配置文件描述 WebDAV、profiles、mappings、hooks 等内容。
syncId:标识当前设备webdav:远端地址、认证与请求选项profiles:按场景覆盖主配置,可定义默认 sourceType 与 deployModemappings:定义源目录、目标目录与远端目录的同步关系,并可单独覆盖源类型与部署方式ignoreGlobal:全局忽略规则hooks:同步生命周期钩子{
"version": "1",
"syncId": "macbook-pro",
"webdav": {
"endpoint": "https://dav.example.com",
"auth": {
"type": "env",
"username": "your-name",
"password": null
},
"remoteRoot": "/ai-coding-sync",
"options": {
"depth": "infinity",
"verifySsl": true,
"timeout": 10000,
"maxRetries": 2,
"concurrency": 4
}
},
"profiles": {
"work": {
"sourceType": "git",
"deployMode": "link",
"strategy": "two-way",
"conflict": "backup"
},
"personal": {
"sourceType": "file",
"deployMode": "copy",
"strategy": "push-only"
}
},
"mappings": [
{
"name": "claude",
"sourcePath": "~/.ai-coding-sync/claude",
"local": "~/.claude",
"remotePath": "/configs/claude",
"profile": "work",
"respectGitignore": true
},
{
"name": "cursor",
"sourcePath": "~/.ai-coding-sync/cursor",
"local": "~/.cursor",
"remotePath": "/configs/cursor",
"sourceType": "auto",
"deployMode": "copy",
"ignore": ["*.log", "*.tmp"]
}
],
"ignoreGlobal": [".DS_Store", "*.swp", "*.tmp"],
"hooks": {
"pre-sync": null,
"post-sync": null,
"on-conflict": null
}
}
项目中的同步行为由两个正交维度组成,而不是单一 mode:
sourceType用于描述 .ai-coding-sync 下对应源目录的类型。
auto自动检测源目录是否为 Git 仓库:如果存在 .git,则按 git 处理;否则按 file 处理。
git显式声明源目录是 Git 仓库。
适合:
file显式声明源目录只是普通文件目录,不依赖 Git 元数据。
适合:
deployMode用于描述如何把 .ai-coding-sync 下的 sourcePath 源目录部署到 local 目标位置。
link使用 ln -s 将目标位置连接到源目录。
适合:
.ai-coding-sync 中copy使用 cp 将源目录内容复制到目标位置,不依赖软链接。
适合:
默认建议把所有真实配置放在 ~/.ai-coding-sync/<mapping-name> 之类的源目录中,再通过 sourcePath -> local 的方式进行部署。
最终同步行为是一个 2×2 矩阵:
git + linkgit + copyfile + linkfile + copy| Command | Description |
|---|---|
init |
初始化配置并测试首轮连接 |
sync |
执行默认双向同步流程 |
push |
将本地内容推送到远端 |
pull |
将远端内容拉取到本地 |
status |
查看同步状态与映射信息 |
doctor |
诊断环境、配置与依赖问题 |
config get <key> |
读取配置项 |
config set <key> <value> |
修改配置项 |
| Option | Description |
|---|---|
--profile <name> |
使用指定 profile |
--source-type <type> |
覆盖源目录类型(auto/git/file) |
--deploy-mode <mode> |
覆盖部署方式(link/copy) |
--dry-run |
预览操作,不执行真实写入 |
--force |
跳过部分保护性确认 |
--yes |
自动确认提示 |
--verbose |
输出更详细日志 |
bun run dev -- status
bun run dev -- sync --profile work
bun run dev -- sync --source-type auto --deploy-mode link
bun run dev -- push --dry-run
bun run dev -- doctor --verbose
bun run dev -- config get webdav.endpoint
bun run dev -- config set syncId macbook-pro
bun run dev -- sync --profile work
bun run dev -- push --dry-run
bun run dev -- sync --profile personal
bun run dev -- sync --profile work
src/
├── cli/ # CLI 路由与命令解析
├── config/ # 配置加载、schema 校验、变量插值
├── credentials/ # 凭证来源与解析
├── hooks/ # 生命周期钩子
├── output/ # 输出与进度展示
├── security/ # 敏感信息扫描与脱敏
├── sync/ # File / Git / Link 三种同步模式
├── utils/ # 通用工具与错误模型
├── webdav/ # WebDAV 客户端与锁管理
├── index.ts # CLI 入口
└── types.ts # 核心类型定义
test/
├── cli.test.ts
├── config-*.test.ts
├── credentials*.test.ts
├── security.test.ts
├── sync*.test.ts
├── webdav*.test.ts
└── docs-ci.test.ts
bun run typecheck
bun run lint
bun run lint:fix
bun run format
bun run format:check
bun test
bun run test:coverage
bun run docs
bun run docs:check
bun run check
bun run check
该命令会依次执行:
bun run docs
bun run docs:check
生成结果位于:
docs/
项目已包含 GitHub Pages 发布流程,可将 TypeDoc 输出直接发布为文档站点。
当前项目测试覆盖率目标为 90%+。
当前已记录覆盖率:
如需更新,请运行:
bun run test:coverage
当前版本已经具备:
后续可以继续增强:
This project is licensed under the MIT License. See LICENSE for details.
This project was primarily created and iterated with AI-assisted development workflows.