### Go Path Adjustment Algorithm Example Source: https://context7.com/upamune/airulesync/llms.txt Illustrates the programmatic use of the path adjustment algorithm in Go. This example demonstrates how to adjust relative paths within a file based on source and target directory structures, and lists common patterns detected. ```go // Example: Path adjustment between directories package main import ( "fmt" "github.com/upamune/airulesync/internal/pathadjust" ) func main() { // Create path adjuster with verbose output adjuster := pathadjust.NewPathAdjuster(true) // Adjust paths in a file from source to target sourceFile := "./src/main-project/.clinerules" targetFile := "./src/sub-project-a/.clinerules" sourceDir := "./src/main-project" targetDir := "./src/sub-project-a" adjustments, err := adjuster.AdjustPaths(sourceFile, targetFile, sourceDir, targetDir) if err != nil { panic(err) } // Review adjustments for _, adj := range adjustments { fmt.Printf("Line %d: '%s' -> '%s'\n", adj.LineNumber, adj.OriginalPath, adj.AdjustedPath) } // Path detection patterns include: // - Import/require statements: import './path/to/file' // - JSON/YAML references: "path": "./config.json" // - Markdown links: [text](./docs/file.md) // - HTML attributes: href="./style.css" // - File extensions: "./(file.json|.yaml|.js|.ts|.go|.py)" } ``` -------------------------------- ### Install Airulesync using Go Source: https://github.com/upamune/airulesync/blob/main/README.md This command installs the airulesync tool globally on your system using the Go programming language's package manager. Ensure you have Go installed and configured correctly. This command fetches the latest release and makes it available in your system's PATH. ```bash go install github.com/upamune/airulesync@latest ``` -------------------------------- ### Airulesync Command-Line Interface Examples (Bash) Source: https://context7.com/upamune/airulesync/llms.txt Demonstrates various ways to use the airulesync command-line tool. This includes displaying version and help information, specifying a custom configuration file, enabling verbose output, performing a dry run, and using short flag equivalents. The examples showcase the flexibility of the CLI for managing rule file synchronization. ```Bash # Display version information airulesync version # Output: # airulesync version 1.0.0 # Display help information airulesync help # Using custom configuration file airulesync sync --config ./custom-config.yaml # Verbose output with detailed logging airulesync sync --verbose # Combine flags airulesync sync --config ./custom-config.yaml --verbose --dry-run # Short flags airulesync sync -c ./custom-config.yaml -v -d ``` -------------------------------- ### Airulesync YAML Configuration Example Source: https://github.com/upamune/airulesync/blob/main/README.md This is an example of the .airulesync.yaml configuration file used by the airulesync tool. It defines source directories with specific files and patterns to synchronize, including options for adjusting paths and ignoring certain files. It also specifies target directories where the files will be synced. ```yaml # yaml-language-server: $schema=https://raw.githubusercontent.com/upamune/airulesync/refs/heads/main/schema.json # vim: set ts=2 sw=2 tw=0 fo=cnqoj # Source directories containing rule files to sync source_dirs: - path: "./src/main-project" files: - ".clinerules" - pattern: ".cursor/rules/**/*.mdc" adjust_paths: true - pattern: ".roomodes" adjust_paths: false ignore_files: - ".cursor/rules/private/*.mdc" # Target directories to sync to target_dirs: - path: "./src/sub-project-a" - path: "./src/sub-project-b" - path: "../other-repo/src/component" external: true ``` -------------------------------- ### CLI Implementation Structure (Go) Source: https://context7.com/upamune/airulesync/llms.txt Provides an example of the command-line interface implementation using the 'kong' library in Go. It defines a 'CLI' struct with global flags like 'Config' and 'Verbose', and commands such as 'Sync', 'Init', and 'Version'. The code demonstrates how to parse arguments, create an application instance, and dispatch commands to the appropriate application methods. Dependencies include 'github.com/alecthomas/kong' and the internal 'app' package. ```Go // Example: CLI implementation structure package main import ( "github.com/alecthomas/kong" "github.com/upamune/airulesync/internal/app" ) type CLI struct { // Global flags Config string `short:"c" help:"Path to config file" default:".airulesync.yaml"` Verbose bool `short:"v" help:"Enable verbose output"` // Commands Sync struct { DryRun bool `short:"d" help:"Simulate execution without applying changes"` } `cmd:"" help:"Synchronize rule files according to configuration"` Init struct { Dir string `arg:"" optional:"" help:"Directory to scan for rule files"` } `cmd:"" help:"Scan directory and generate a configuration file"` Version struct{} `cmd:"" help:"Display version information"` } func main() { var cli CLI ctx := kong.Parse(&cli, kong.Name("airulesync"), kong.Description("Synchronize AI coding tool rule files across directories"), ) // Create application application := app.NewApp(cli.Config, cli.Verbose) // Execute command switch ctx.Command() { case "sync": application.RunSync(cli.Sync.DryRun) case "init": application.RunInit(cli.Init.Dir) case "version": application.RunVersion() } } ``` -------------------------------- ### Programmatic Synchronization with Go Source: https://context7.com/upamune/airulesync/llms.txt Provides an example of how to use the airulesync library programmatically in Go to perform synchronization. This includes loading configuration, creating a syncer instance, executing the sync operation, and processing the results with verbose output. ```go // Example: Programmatic synchronization package main import ( "fmt" "github.com/upamune/airulesync/internal/app" "github.com/upamune/airulesync/internal/config" "github.com/upamune/airulesync/internal/sync" ) func main() { // Load configuration cfg, err := config.LoadConfig(".airulesync.yaml") if err != nil { panic(err) } // Create syncer with verbose output syncer := sync.NewSyncer(cfg, false, true) // Perform synchronization report, err := syncer.Sync() if err != nil { panic(fmt.Sprintf("Sync failed: %v", err)) } // Process results for _, result := range report.Results { if result.Success { fmt.Printf("✓ Synced: %s -> %s\n", result.SourceFile, result.TargetFile) // Show path adjustments for _, adj := range result.PathAdjustments { fmt.Printf(" Line %d: '%s' -> '%s'\n", adj.LineNumber, adj.OriginalPath, adj.AdjustedPath) } } else if result.Skipped { fmt.Printf("⊘ Skipped: %s (%s)\n", result.TargetFile, result.SkipReason) } else { fmt.Printf("✗ Error: %s - %v\n", result.TargetFile, result.Error) } } // Print summary report syncer.PrintReport(report, false) } ``` -------------------------------- ### Install Airulesync using Homebrew Source: https://github.com/upamune/airulesync/blob/main/README.md This command installs airulesync using the Homebrew package manager on macOS and Linux systems. It adds the airulesync binary to your system's PATH, making it accessible from the command line. This is a convenient method for users who already manage their software with Homebrew. ```bash brew install upamune/tap/airulesync ``` -------------------------------- ### Generate JSON Schema for Airulesync Configuration Source: https://github.com/upamune/airulesync/blob/main/README.md This development command generates the JSON Schema file for the airulesync configuration. This schema is used for validating the structure and content of the `.airulesync.yaml` file, ensuring that the configuration is correctly formatted. It's primarily useful for developers contributing to the project or for advanced validation setups. ```bash make schema ``` -------------------------------- ### Initialize airulesync Configuration in Go Source: https://context7.com/upamune/airulesync/llms.txt Initializes the airulesync configuration by scanning the current directory for AI rule files. This Go code demonstrates how to create an application instance and run the 'init' command, generating a .airulesync.yaml file. ```go package main import ( "github.com/upamune/airulesync/internal/app" "github.com/upamune/airulesync/internal/config" ) func main() { // Create application instance application := app.NewApp(".airulesync.yaml", false) // Run init command - scans current directory err := application.RunInit("") if err != nil { panic(err) } // Generated config will include detected files like: // - .clinerules // - .cursor/rules/*.mdc // - .roomodes } ``` -------------------------------- ### Generate Airulesync Configuration Source: https://github.com/upamune/airulesync/blob/main/README.md This command initiates the airulesync configuration process by scanning the specified directory ('.') and generating a default '.airulesync.yaml' configuration file. This file will contain settings for source and target directories, files to sync, and other synchronization options. It's the first step before performing actual synchronization. ```bash airulesync init . # Edit .airulesync.yaml if needed ``` -------------------------------- ### Initialize airulesync Configuration via CLI Source: https://context7.com/upamune/airulesync/llms.txt Initializes the airulesync configuration using the command-line interface. This command scans the specified directory for AI rule files and generates a .airulesync.yaml configuration file. ```bash # CLI Usage: Initialize configuration airulesync init . # Output: # Scanning directory for rule files... # Found 3 potential rule files: # - /project/.clinerules # - /project/.cursor/rules/main.mdc # - /project/.roomodes # Configuration written to .airulesync.yaml # Review and edit the configuration as needed before running 'airulesync sync' ``` -------------------------------- ### Load and Validate airulesync Configuration in Go Source: https://context7.com/upamune/airulesync/llms.txt Loads and validates the airulesync configuration file programmatically using Go. This snippet demonstrates accessing source and target directories from the loaded configuration object. ```go package main import ( "fmt" "github.com/upamune/airulesync/internal/config" ) func main() { // Load configuration file cfg, err := config.LoadConfig(".airulesync.yaml") if err != nil { panic(fmt.Sprintf("Failed to load config: %v", err)) } // Configuration is automatically validated // Paths are normalized (cleaned) // Access source directories for _, srcDir := range cfg.SourceDirs { fmt.Printf("Source: %s\n", srcDir.Path) for _, file := range srcDir.Files { fmt.Printf(" - Pattern: %s\n", file.Pattern) fmt.Printf(" Adjust paths: %v\n", file.ShouldAdjustPaths()) fmt.Printf(" Overwrite: %v\n", file.ShouldOverwrite(srcDir.GetDirectoryOverwrite())) } } // Access target directories for _, tgtDir := range cfg.TargetDirs { fmt.Printf("Target: %s (external: %v)\n", tgtDir.Path, tgtDir.External) } } ``` -------------------------------- ### CLI Synchronization with Airulesync Source: https://context7.com/upamune/airulesync/llms.txt Demonstrates how to use the airulesync command-line tool for synchronizing files between projects. It covers basic synchronization and verbose mode for detailed output, including path adjustments. ```bash airulesync sync airulesync sync --verbose ``` -------------------------------- ### Scan Directory for Rule Files (Go) Source: https://context7.com/upamune/airulesync/llms.txt Scans a specified directory to discover common AI tool rule files. It identifies files like .clinerules, .rooignore, and .roomodes, as well as rule files within .cursor/rules directories. Additionally, it finds potential target directories that contain source code but lack rule files. Dependencies include the 'fmt' package and the internal 'scanner' package. ```Go // Example: Scan directory for rule files package main import ( "fmt" "github.com/upamune/airulesync/internal/scanner" ) func main() { // Create scanner s := scanner.NewScanner(nil) // Scan directory for common rule file patterns ruleFiles, err := s.ScanDirectory("./src/main-project") if err != nil { panic(err) } // Prints discovered files: // - .clinerules // - .cursor/rules/main.mdc // - .cursor/rules/python.mdc // - .roomodes // - .rooignore for _, file := range ruleFiles { fmt.Printf("Found rule file: %s\n", file) } // Find potential target directories // (directories with source code but no rule files) targetDirs, err := s.FindPotentialTargetDirs("./src/main-project") if err != nil { panic(err) } // Prints potential targets: // - src/utils // - src/services // - src/components for _, dir := range targetDirs { fmt.Printf("Potential target: %s\n", dir) } } ``` -------------------------------- ### Scan Source Dirs with Config (Go) Source: https://context7.com/upamune/airulesync/llms.txt Scans source directories based on a provided configuration file, typically '.airulesync.yaml'. It utilizes the 'config' and 'scanner' internal packages. The function returns a list of FileInfo structs, detailing the source path, relative path, matched pattern, and options for path adjustment and overwriting. This allows for more granular control over file synchronization. ```Go // Example: Scan source directories with configuration package main import ( "fmt" "github.com/upamune/airulesync/internal/config" "github.com/upamune/airulesync/internal/scanner" ) func main() { // Load configuration cfg, err := config.LoadConfig(".airulesync.yaml") if err != nil { panic(err) } // Create scanner with configuration s := scanner.NewScanner(cfg) // Scan all configured source directories files, err := s.ScanSourceDirs() if err != nil { panic(err) } // Process discovered files for _, file := range files { fmt.Printf("File: %s\n", file.RelativePath) fmt.Printf(" Source: %s\n", file.SourcePath) fmt.Printf(" Pattern: %s\n", file.Pattern) fmt.Printf(" Adjust paths: %v\n", file.AdjustPaths) fmt.Printf(" Overwrite: %v\n", file.Overwrite) } // FileInfo includes: // - SourcePath: absolute path to source file // - SourceDir: source directory path // - RelativePath: relative path within source directory // - Pattern: glob pattern that matched the file // - AdjustPaths: whether to adjust paths in this file // - Overwrite: whether to overwrite existing files } ``` -------------------------------- ### Perform Dry-Run Synchronization with Airulesync Source: https://github.com/upamune/airulesync/blob/main/README.md This command simulates the synchronization process without making any actual changes to your files. It's useful for verifying the planned operations, checking for potential issues, and understanding how airulesync will adjust paths and sync files before committing to the changes. The configuration is read from '.airulesync.yaml' by default. ```bash airulesync sync --dry-run ``` -------------------------------- ### Go File Copy Without Path Adjustment Source: https://context7.com/upamune/airulesync/llms.txt Shows how to use the airulesync library in Go to copy a file directly without performing any path adjustments. This is useful for files that should be duplicated as-is, ensuring the target directory is created if it doesn't exist. ```go // Example: Copy file without path adjustment package main import ( "github.com/upamune/airulesync/internal/pathadjust" ) func main() { adjuster := pathadjust.NewPathAdjuster(false) // Copy file directly without modifying paths sourceFile := "./src/main-project/.roomodes" targetFile := "./src/sub-project-a/.roomodes" err := adjuster.CopyFile(sourceFile, targetFile) if err != nil { panic(err) } // File is copied byte-for-byte // Target directory is created if it doesn't exist } ``` -------------------------------- ### airulesync YAML Configuration Structure Source: https://context7.com/upamune/airulesync/llms.txt Defines the structure for the .airulesync.yaml configuration file. It specifies source directories with file patterns, overwrite settings, path adjustment flags, ignore patterns, and target directories, including external ones. ```yaml # yaml-language-server: $schema=https://raw.githubusercontent.com/upamune/airulesync/refs/heads/main/schema.json # vim: set ts=2 sw=2 tw=0 fo=cnqoj # Source directories containing rule files to sync source_dirs: - path: "./src/main-project" overwrite: true files: # Simple format - uses defaults (adjust_paths=true, overwrite=true) - pattern: ".clinerules" # Detailed format with explicit settings - pattern: ".cursor/rules/**/*.mdc" adjust_paths: true overwrite: true # Disable path adjustment for specific files - pattern: ".roomodes" adjust_paths: false # Ignore specific files in source ignore_files: - ".cursor/rules/private/*.mdc" # Target directories to sync to target_dirs: - path: "./src/sub-project-a" - path: "./src/sub-project-b" # External directory (outside current repository) - path: "../other-repo/src/component" external: true ignore_files: - ".clinerules" ``` -------------------------------- ### Execute Synchronization with Airulesync Source: https://github.com/upamune/airulesync/blob/main/README.md This command performs the actual synchronization of AI coding tool rule files based on the configuration specified in '.airulesync.yaml'. It will copy files from source directories to target directories, applying path adjustments as needed. Use this command after reviewing the results of a dry-run. ```bash airulesync sync ``` -------------------------------- ### Synchronize Files with airulesync Dry-Run via CLI Source: https://context7.com/upamune/airulesync/llms.txt Performs a dry-run synchronization of rule files using airulesync. This command previews the changes that would be made without actually modifying any files, showing which files would be synchronized and where. ```bash # Dry-run mode - preview changes without applying them airulesync sync --dry-run # Output: # [DRY-RUN] Starting synchronization process # [DRY-RUN] Scanning source directories for target files... # # [DRY-RUN] Files to synchronize: # [DRY-RUN] - './src/main-project/.clinerules' -> './src/sub-project-a/.clinerules' # [DRY-RUN] * Path adjustments: 5 locations ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.