import { Ora } from 'ora'; export { readFile, writeFile } from 'node:fs/promises'; /** * 工具配置类型定义 */ /** * 支持的工具键名 */ type ToolKey = 'cursor' | 'claude' | 'codebuddy' | 'opencode' | 'gemini' | 'iflow' | 'codex' | 'zcode' | 'pi' | ({} & string); /** * 配置类型 */ type ConfigType = 'commands' | 'skills' | 'instructions' | 'mcp' | 'settings' | 'agents'; /** * 文件格式类型 */ type FormatType = 'markdown' | 'toml' | 'mdc' | 'json'; /** * 配置目录类型 (Config directory type) */ type ConfigDirType = 'global' | 'project'; /** * 命令配置 */ interface CommandConfig { source?: string; format?: FormatType; target?: string | string[]; convert?: boolean; /** * 自定义内容转换逻辑 (Custom content transformation logic) */ transform?: (content: string, fileName: string) => string | Promise; } /** * 技能配置 */ interface SkillConfig { source?: string; target?: string | string[]; /** * 软链接模式:目标 skills 目录中的每个条目以符号链接指向 Claude 源,不再复制内容 * * 目标中已存在的同名复制文件/目录(或指向他处的旧链接)会被删除并替换为软链接; * 指向源目录但源已删除的失效链接会被清理;与源无关的条目保持不动 * 此模式不受 `autoOverwrite` 影响,配置了 `transform` 时自动回退为转换复制 * * @default true */ symlink?: boolean; /** * 自定义内容转换逻辑 (Custom content transformation logic) */ transform?: (content: string, fileName: string) => string | Promise; } /** * Agent 配置 */ interface AgentConfig { source?: string; target?: string | string[]; /** * 自定义内容转换逻辑 (Custom content transformation logic) */ transform?: (content: string, fileName: string) => string | Promise; } /** * 指令文件配置(CLAUDE.md → GEMINI.md / AGENTS.md / CODEBUDDY.md) */ interface InstructionsConfig { source?: string; /** 目标指令文件路径 */ target?: string | string[]; /** * 自定义内容转换逻辑 */ transform?: (content: string, fileName: string) => string | Promise; } /** * MCP配置 */ interface MCPConfig { source?: string; target?: string | string[]; convert?: boolean; /** * 自定义MCP配置转换逻辑 (Custom MCP configuration transformation logic) */ transform?: (config: any) => any | Promise; /** * 转换后、写入前调用:把目标文件里用户在目标工具内改过、源里没有的设置带回转换结果 * (Carry target-side user settings missing from the source back into the converted result) */ preserveExisting?: (converted: any, existing: any) => any; } /** * Local MCP配置 */ interface LocalMCPConfig { command: string | string[]; args?: string[]; env?: Record; enabled?: boolean; type?: 'local'; } /** * Remote MCP配置 */ interface RemoteMCPConfig { url?: string; httpUrl?: string; type?: 'http' | 'remote' | 'streamable-http'; headers?: Record; enabled?: boolean; } /** * MCP服务器配置 */ type MCPServerConfig = LocalMCPConfig | RemoteMCPConfig; /** * Settings 配置(包含 Hooks 和 Permissions) */ interface SettingsConfig { source?: string; target?: string | string[]; /** * 合并模式(深度合并现有配置) */ merge?: boolean; /** * 自定义 Settings 转换逻辑(如 ZCode 的 hooks 结构差异)(Custom settings transformation logic) */ transform?: (config: any) => any | Promise; } /** * 工具配置 */ interface ToolConfig { name: string; commands: CommandConfig; skills: SkillConfig; instructions?: InstructionsConfig; mcp: MCPConfig; settings?: SettingsConfig; agents?: AgentConfig; supported: ConfigType[]; } /** * 工具选择项 */ interface ToolChoice { name: string; value: ToolKey; } /** * 配置目录选择项 (Config directory choice) */ interface ConfigDirChoice { name: string; value: ConfigDirType; } /** * 配置类型信息 */ interface ConfigTypeInfo { name: string; source: string; } /** * 完整配置类型 */ interface SyncConfig { /** * 工具配置 */ tools?: Record>; /** * 全局配置 */ global?: { /** * 默认源目录 */ defaultSourceDir?: string; /** * 默认配置目录 */ defaultConfigDir?: string; /** * 默认目标工具 */ defaultTargetTools?: ToolKey[]; }; } /** * 配置定义函数类型 */ type ConfigFn = (defaultConfig: SyncConfig) => SyncConfig | Promise; /** * 工具配置 */ /** * 项目完整内置配置 */ declare const INTERNAL_CONFIG: { tools: Record; }; /** * 工具配置映射 */ declare const TOOL_CONFIGS: Record; /** * 获取工具选择列表 */ declare function getToolChoiceList(tools?: Record): ToolChoice[]; /** * 获取配置目录选择列表 */ declare function getConfigDirChoiceList(): ConfigDirChoice[]; /** * 检查工具是否支持指定配置类型 */ declare function isConfigTypeSupported(tool: string, configType: ConfigType, tools?: Record): boolean; /** * defineConfig 函数,用于项目配置定义 */ declare function defineConfig(config: T): T; /** * Markdown 转 TOML 转换器 * * Claude command(`~/.claude/commands/*.md`)→ Gemini/IFlow prompt(TOML 格式) */ /** * Claude command(Markdown)→ Gemini/IFlow prompt(写入 `~/.gemini/commands/*.toml` 等) * * - frontmatter 仅提取 `description`,正文进 `prompt` 字段 * - 参数语法转换:`$ARGUMENTS` → `{{args}}`,`$1` → `{{arg1}}`,`` !`cmd` `` → `!{cmd}` * - 正文中的 `allowed-tools:` / `argument-hint:` / `context:` 行移除 * * @example * ```txt * 输入(Claude ~/.claude/commands/review.md): * --- * description: 审查代码 * --- * 审查 $1,先执行 !`git diff` * * 输出(Gemini ~/.gemini/commands/review.toml): * description = "审查代码" * prompt = "审查 {{arg1}},先执行 !{git diff}" * ``` */ declare function convertMarkdownToTOML(sourcePath: string, targetPath: string): Promise; /** * 自定义配置支持 * 允许用户通过 ai-sync.config.js 文件自定义迁移配置 */ /** * 查找配置文件 */ declare function findConfigFile(cwd?: string): Promise; /** * 加载用户配置 */ declare function loadUserConfig(cwd?: string, explicitPath?: string): Promise; /** * 合并配置 */ declare function mergeConfigs(defaultConfig: SyncConfig, userConfig: SyncConfig): SyncConfig; /** * 日志工具类 (Logger Utility Class) */ /** * 日志工具类 (Logger Utility Class) */ declare class Logger { private spinners; constructor(); /** * 开始加载动画 (Start loading animation) */ start(message: string): Ora; /** * 信息 (Info) */ info(message: string): void; /** * 警告 (Warn) */ warn(message: string): void; /** * 成功消息 (Success message) */ success(message: string): void; /** * 错误消息 (Error message) */ error(message: string): void; /** * 分节标题 (Section title) */ section(title: string): void; /** * 汇总结果 (Summary results) */ summary(results: MigrationResults): void; } declare const logger: Logger; interface MigrationError { file: string; error: string; } interface MigrationResults { success: number; skipped: number; error: number; errors: MigrationError[]; tools: string[]; } /** * 迁移选项 */ interface MigrateOptions { autoOverwrite: boolean; sourceDir?: string; } /** * 复制/迁移结果统计 */ interface MigrationStats { success: number; skipped: number; error: number; errors: MigrationError[]; } /** * 迁移器抽象基类 */ declare abstract class BaseMigrator { protected sourceDir: string; protected targetTools: ToolKey[]; protected options: MigrateOptions; protected configType: ConfigType; protected tools: Record; protected logger: Logger; constructor(sourceDir: string, targetTools: ToolKey[], options: MigrateOptions, configType: ConfigType, tools: Record); /** * 执行迁移的主入口 (模板方法) */ migrate(): Promise; /** * 为单个工具执行迁移 (由子类实现) */ protected abstract migrateForTool(tool: ToolKey, targetDir: string): Promise; /** * 获取目标路径 */ protected getTargetDir(tool: ToolKey): Promise; /** * 辅助方法:报告成功 */ protected reportSuccess(message: string): void; /** * 辅助方法:报告错误 */ protected reportError(message: string, error?: string): void; /** * 辅助方法:合并统计结果 */ protected sumStats(base: MigrationStats, addition: MigrationStats): void; } /** * Agents 迁移器 */ /** * Agents 迁移器类 */ declare class AgentsMigrator extends BaseMigrator { constructor(sourceDir: string, targetTools: ToolKey[], options: MigrateOptions, tools: Record); /** * 为单个工具执行迁移 */ protected migrateForTool(tool: ToolKey, targetDir: string): Promise; /** * 带自定义转换的迁移 */ private migrateWithTransform; } /** * Commands 迁移器 */ /** * Commands 迁移器类 */ declare class CommandsMigrator extends BaseMigrator { constructor(sourceDir: string, targetTools: ToolKey[], options: MigrateOptions, tools: Record); /** * 为单个工具执行迁移 */ protected migrateForTool(tool: ToolKey, targetDir: string): Promise; /** * 使用自定义转换逻辑 */ private migrateWithCustomTransform; /** * 带转换的迁移 (MD -> TOML) */ private migrateWithConversion; } /** * Instructions 迁移器 * 将 CLAUDE.md 同步为各工具的全局指令文件(GEMINI.md / AGENTS.md / CODEBUDDY.md) */ /** * Instructions 迁移器类 */ declare class InstructionsMigrator extends BaseMigrator { constructor(sourceDir: string, targetTools: ToolKey[], options: MigrateOptions, tools: Record); /** * 为单个工具执行迁移(单文件复制) */ protected migrateForTool(tool: ToolKey, targetPath: string): Promise; } declare class MCPMigrator extends BaseMigrator { constructor(sourceFile: string, targetTools: ToolKey[], options: MigrateOptions, tools: Record); migrate(): Promise; protected migrateForTool(tool: ToolKey, targetPath: string): Promise; } /** * Skills 迁移器 * * 默认使用软链接模式:各工具 skills 目录中的条目以符号链接指向 Claude 源, * 只有源保留真实文件;配置 `symlink: false` 时回退为复制模式 */ /** * Skills 迁移器类 */ declare class SkillsMigrator extends BaseMigrator { constructor(sourceDir: string, targetTools: ToolKey[], options: MigrateOptions, tools: Record); /** * 为单个工具执行迁移 */ protected migrateForTool(tool: ToolKey, targetDir: string): Promise; /** * 解除指向源的遗留软链接;失败时计入错误并返回 `false`(调用方应中止该工具迁移) * * 解除失败还继续写入会有沿链接改写真实源的风险,宁可失败也不冒险 */ private unlinkLegacySymlinksOrFail; /** * 带自定义转换的迁移 */ private migrateWithTransform; } /** * 路径工具函数 */ /** * 展开家目录路径 */ declare function expandHome(filepath: string): string; /** * 获取工具配置路径 (统一且唯一从配置中心读取) * 不再包含任何 Fallback 猜测,完全由 ToolConfig 驱动 * 注意:由于涉及数组探测,此同步版本仅返回第一个配置值 */ declare function getToolPath(tool: ToolKey, configType: ConfigType): string; /** * 异步解析最终目标路径 (支持数组动态探测) */ declare function resolveTargetPath(tool: ToolKey, configType: ConfigType): Promise; /** * 规范化路径 */ declare function normalizePath(filepath: string): string; /** * 探测并获取最终的源目录 */ declare function resolveSourceDir(providedSourceDir: string | undefined, _defaultConfigDir: string): Promise; /** * 获取 MCP 源路径 */ declare function getMCPSourcePath(sourceDir: string): Promise; /** * 获取 OpenCode 配置文件路径 (动态探测逻辑) * 用于当配置虽然定义了 target,但需要检查磁盘上是否存在已有的 alternative 格式 */ declare function getOpenCodeMCPPath(basePath: string): Promise; declare function getCommandsSourcePath(sourceDir: string): Promise; declare function getSkillsSourcePath(sourceDir: string): Promise; declare function getAgentsSourcePath(sourceDir: string): Promise; declare function getInstructionsSourcePath(sourceDir: string): Promise; declare function getSettingsSourcePath(sourceDir: string): Promise; /** * 判断值是否为对象类型(排除 null 和数组) * * @param value 要检查的值 * @returns 如果是对象类型则返回 true,否则返回 false */ declare function isObj(value: any): value is Record; /** * 深度合并对象 * 将源对象的属性深度合并到目标对象中,保留目标对象中源对象未包含的属性 * * @param target 目标对象 * @param mergeSource 源对象(要合并的对象) * @returns 合并后的新对象 * * @example * ```ts * const target = { a: 1, b: { c: 2, d: 3 } } * const mergeSource = { b: { c: 4 } } * deepMerge(target, mergeSource) // { a: 1, b: { c: 4, d: 3 } } * ``` * * @remarks * 本函数是用户提供的深度合并实现,具有以下特点: * - 只合并源对象的自有属性 * - 跳过 undefined 值 * - 深度合并嵌套对象(排除数组) * - 数组、基本类型和 null 直接替换 * - 保留目标对象中源对象未包含的属性 */ declare function deepMerge>(target: T, mergeSource: Partial): T; /** * 文件工具函数 */ /** * 确保目录存在 */ declare function ensureDirectoryExists(dirPath: string): Promise; /** * 检查文件是否存在 */ declare function fileExists(filePath: string): Promise; /** * 检查目录是否存在 */ declare function directoryExists(dirPath: string): Promise; /** * 安全复制文件 */ declare function copyFileSafe(sourcePath: string, targetPath: string, autoOverwrite?: boolean): Promise; /** * 复制目录 */ declare function copyDirectory(sourceDir: string, targetDir: string, autoOverwrite?: boolean): Promise; /** * 以软链接方式同步目录(Skills 软链接模式) * * 将 `sourceDir` 下每个顶级条目在 `targetDir` 中创建为指向源的符号链接: * - 目标已是正确指向源的链接 → 跳过(幂等) * - 目标存在同名复制文件/目录或指向他处的链接 → 安全替换(先建临时链接,成功后才替换旧内容) * - 目标中存在指向源目录内、但源已删除的失效链接 → 自动清理(源目录整体不存在时同样清理) * - 目标中与源无关的真实条目 → 保留不动 * - 目标与源指向同一物理目录(互为别名)或存在包含关系 → 整体跳过,避免误删真实源 * - 交叉布局(源条目本身是指向目标目录内部的链接,如 skills CLI 的安装布局)→ 跳过该条目, * 目标处的同名内容就是唯一真实数据,绝不能当作旧副本替换或删除 * * 链接统一使用绝对路径;Windows 上目录使用 junction(无需管理员权限) */ declare function symlinkDirectory(sourceDir: string, targetDir: string): Promise; /** * 解除目标目录中指向源目录内部的符号链接(软链接模式的遗留产物) * * 用于从软链接模式切回复制/转换模式:只删除链接本身、不动真实文件, * 确保后续复制/转换产出真实副本,而不是沿链接写穿到源 * 链接目标按物理路径(realpath)与源比较,覆盖源路径以别名形式传入的场景 * 解除失败会如实上报,由调用方决定是否继续(继续写入会有写穿风险) */ interface UnlinkSymlinksResult { /** 解除的链接数量 */ unlinked: number; /** 解除失败的条目及错误 */ errors: MigrationError[]; } declare function unlinkSymlinksInto(targetDir: string, sourceDir: string): Promise; /** * 获取 Markdown 文件列表 */ declare function getMarkdownFiles(dirPath: string): Promise; /** * 读取 JSON 文件(支持 JSONC 格式) * * 使用 `comment-json` 解析,注释会以 symbol 形式挂在返回对象上, * 配合 `writeJSONFile` 可在写回时保留未改动部分的注释 */ declare function readJSONFile(filePath: string): Promise; /** * 写入 JSON 文件 * * 若 `data` 由 `readJSONFile` 解析得来,其上携带的注释会被一并写回 */ declare function writeJSONFile(filePath: string, data: unknown): Promise; /** * 读取 TOML 文件 */ declare function readTOMLFile(filePath: string): Promise; /** * 写入 TOML 文件 * * 目标已存在时尽量保留原文中「未改动」顶层配置的注释与格式: * 只把发生变化的顶层「表类型」键(如迁移时整体替换的 `mcp_servers`)剥离后用 * `@iarna/toml` 重新生成,其余文本逐字保留。任何无法安全处理的情况都回退到完整 * 序列化,确保输出始终是合法 TOML(正确性优先于注释保留) */ declare function writeTOMLFile(filePath: string, data: any): Promise; /** * 设置可执行权限 */ declare function setExecutablePermission(filePath: string): Promise; interface CopyResult { success: boolean; skipped: boolean; error: Error | null; } interface CopyDirectoryResults { success: number; skipped: number; error: number; errors: MigrationError[]; } /** * 移除目录及其内容 */ declare function removeDirectory(dirPath: string): Promise; export { type AgentConfig, AgentsMigrator, type CommandConfig, CommandsMigrator, type ConfigDirChoice, type ConfigDirType, type ConfigFn, type ConfigType, type ConfigTypeInfo, type CopyDirectoryResults, type CopyResult, type FormatType, INTERNAL_CONFIG, type InstructionsConfig, InstructionsMigrator, type LocalMCPConfig, Logger, type MCPConfig, MCPMigrator, type MCPServerConfig, type MigrationError, type MigrationResults, type RemoteMCPConfig, type SettingsConfig, type SkillConfig, SkillsMigrator, type SyncConfig, TOOL_CONFIGS, type ToolChoice, type ToolConfig, type ToolKey, type UnlinkSymlinksResult, convertMarkdownToTOML, copyDirectory, copyFileSafe, deepMerge, defineConfig, directoryExists, ensureDirectoryExists, expandHome, fileExists, findConfigFile, getAgentsSourcePath, getCommandsSourcePath, getConfigDirChoiceList, getInstructionsSourcePath, getMCPSourcePath, getMarkdownFiles, getOpenCodeMCPPath, getSettingsSourcePath, getSkillsSourcePath, getToolChoiceList, getToolPath, isConfigTypeSupported, isObj, loadUserConfig, logger, mergeConfigs, normalizePath, readJSONFile, readTOMLFile, removeDirectory, resolveSourceDir, resolveTargetPath, setExecutablePermission, symlinkDirectory, unlinkSymlinksInto, writeJSONFile, writeTOMLFile };