AI Rules Sync
This is a VS Code extension designed to synchronize the rule file contents of various AI-assisted programming tools (like Windsurf, Cursor, Cline, Roo Code, etc.). With this extension, you can maintain your AI tool rule configurations in one place and automatically sync them to all other tools, ensuring a consistent AI assistance experience across different environments.
Background
With the growing popularity of AI-assisted programming tools, developers might use multiple different AI tools simultaneously. These tools often have their own rule configuration files to customize the AI assistant's behavior. Manually maintaining multiple rule files is time-consuming and error-prone. This extension aims to solve this problem by providing a one-stop solution for rule management.
Features
- Select a base rule file as the primary source (custom or from presets).
- Automatically or manually synchronize the base rule file content to target rule files.
- Provides a sidebar Tree View for intuitive display of rule files and sync status.
- Customizable list of target rule files, with presets available.
- Supports path variables (currently
${userHome}
) for cross-platform compatibility.
- NEW: Command to ensure configured rule files exist, creating them if necessary.
- NEW: Command to switch the display language of the extension UI (English/Chinese).
- NEW: Auto-sync feature triggers synchronization when the base rule file is saved (with debounce).
- NEW: Centralized services for configuration, localization, error handling, file watching, and state management.
Project Structure
src/
: Source code directory
extension.ts
: Main extension entry point
treeDataProvider.ts
: Sidebar Tree View provider
commandRegistrar.ts
: Handles command registration
pathResolver.ts
: Resolves paths with variables
logger.ts
: Simple output channel logger
commands/
: Directory containing command implementations (e.g., syncRulesCommand.ts
, selectBaseRuleCommand.ts
, etc.)
services/
: Directory containing service implementations (e.g., configService.ts
, localizationService.ts
, errorHandlerService.ts
, fileWatcherService.ts
, stateManagementService.ts
)
rules/
: Directory for preset rule files
test-rules/
: Directory for test rule files
Usage
1. Select Base Rule File
Select the base rule file using one of the following methods:
- Execute the
AI Rules Sync: Select Base Rule File
command from the Command Palette (Ctrl+Shift+P).
- Click the "Select Base Rule File" action item in the sidebar view.
- Click on a preset rule file in the sidebar view and choose "Select as Base Rule File".
Presets include:
- Windsurf
- Cursor
- Cline
- Roo Code
- Test Rule
You can also select a custom file.
Configure target rule files using one of the following methods:
- Execute the
AI Rules Sync: Configure Target Rule Files
command from the Command Palette.
- Click the "Configure Target Files" action item in the sidebar view.
You can select multiple files from the preset list or add custom files as synchronization targets. The target file list is displayed in the sidebar, and you can add or remove targets at any time.
3. Synchronize Rule Files
Synchronize rule files in the following ways:
- Manual Sync: Execute the
AI Rules Sync: Sync Rule Files
command from the Command Palette or click the "Sync Rules Now" action item in the sidebar.
- Auto Sync: Enable the
aiRulesSync.autoSync
setting. When the base rule file is saved, changes will be automatically synchronized to all target files after a short delay (debounce).
Synchronization results will be shown in notifications.
4. Ensure Rule Files Exist
Execute the AI Rules Sync: Ensure Rule Files Exist
command from the Command Palette or click the "Ensure Rule Files Exist" action item in the sidebar. This command checks if the configured base and target rule files exist at their resolved paths. If a file does not exist, it will be created (including necessary directories). A summary report is shown afterwards.
5. Select Display Language
Execute the AI Rules Sync: Select Display Language
command from the Command Palette or click the "Select Display Language" action item in the sidebar to choose between English and Chinese for the extension's UI elements. A window reload might be required for all changes to take effect.
Extension Settings
This extension provides the following settings:
aiRulesSync.baseRulePath
: Path to the base rule file (absolute or relative).
aiRulesSync.targetRulePaths
: List of paths to target rule files (absolute or relative).
aiRulesSync.autoSync
: Whether to automatically sync rule files on save (default: false
).
aiRulesSync.presets
: Preset rule file paths (default includes Windsurf, Cursor, Cline, Roo Code, and a test rule).
Path Variables
The following variable can be used in file paths within the settings:
${userHome}
: The user's home directory.
Installation
- Open the Extensions view in VS Code (Ctrl+Shift+X).
- Search for "AI Rules Sync".
- Click "Install".
Alternatively, download the .vsix
file and install it using the "Install from VSIX..." option.
Development Notes
.gitignore Configuration
The project includes a .gitignore
file to exclude files and directories that should not be committed to version control:
node_modules/
: Dependency packages directory
dist/
and out/
: Build output directories
*.vsix
: Extension package files
.vscode-test/
: VS Code test directory
.history/
: Local history directory
- Various log and temporary files
- OS-specific files (e.g.,
.DS_Store
)
This ensures a clean repository and prevents unnecessary files from being committed.
Building from Source
git clone https://github.com/yourusername/ai-rules-sync.git # Replace with actual repo URL if available
cd ai-rules-sync
npm install
npm run compile # Or use the webpack script if defined, e.g., npm run webpack-dev
Packaging
npm run package # Assumes vsce is installed globally or via devDependencies
License
MIT