/** * @nahisaho/musubix-codegraph - Refactoring Applier * * Applies refactoring suggestions to source files * * @packageDocumentation * @module @nahisaho/musubix-codegraph/pr * * @see REQ-CG-PR-002 - Auto Apply Refactoring * @see DES-CG-PR-004 - Class Design */ import type { RefactoringSuggestion, CodeChange, FileDiff } from './types.js'; /** * Result of applying a single change */ export interface ApplyChangeResult { /** Whether the change was applied successfully */ success: boolean; /** File path */ filePath: string; /** Error message if failed */ error?: string; /** Backup path if backup was created */ backupPath?: string; } /** * Result of applying all changes in a suggestion */ export interface ApplyResult { /** Overall success status */ success: boolean; /** Files modified */ filesModified: string[]; /** Files created */ filesCreated: string[]; /** Files deleted */ filesDeleted: string[]; /** Individual change results */ changeResults: ApplyChangeResult[]; /** Overall error if failed */ error?: string; } /** * Options for applying refactoring */ export interface ApplyOptions { /** Repository root path */ repoPath: string; /** Create backups before modifying */ createBackups?: boolean; /** Backup directory (default: .musubix-backup) */ backupDir?: string; /** Validate changes before applying */ validate?: boolean; /** Dry run - don't actually modify files */ dryRun?: boolean; } /** * Refactoring Applier * * Applies code changes from refactoring suggestions to source files. * Supports validation, backup, and rollback. * * @see DES-CG-PR-004 * @example * ```typescript * const applier = new RefactoringApplier({ repoPath: '/path/to/repo' }); * const result = await applier.apply(suggestion); * if (!result.success) { * await applier.rollback(); * } * ``` */ export declare class RefactoringApplier { private readonly repoPath; private readonly createBackups; private readonly backupDir; private readonly validate; private appliedChanges; /** * Create a new RefactoringApplier * @param options - Apply options */ constructor(options: ApplyOptions); /** * Apply a refactoring suggestion * @see REQ-CG-PR-002 */ apply(suggestion: RefactoringSuggestion): ApplyResult; /** * Preview changes without applying * @see REQ-CG-PR-007 */ preview(suggestion: RefactoringSuggestion): FileDiff[]; /** * Rollback applied changes */ rollback(): void; /** * Validate changes can be applied */ validateChanges(changes: CodeChange[]): string | null; /** * Check if a suggestion can be applied */ canApply(suggestion: RefactoringSuggestion): { canApply: boolean; reason?: string; }; /** * Group changes by file */ private groupChangesByFile; /** * Apply changes to a single file */ private applyChangesToFile; /** * Apply changes to content string */ private applyChangesToContent; /** * Create a backup of a file */ private createBackup; /** * Normalize whitespace for comparison */ private normalizeWhitespace; /** * Generate unified diff format */ private generateUnifiedDiff; /** * Calculate diff statistics */ private calculateDiffStats; } /** * Create a RefactoringApplier instance */ export declare function createRefactoringApplier(repoPath: string, options?: Partial): RefactoringApplier; //# sourceMappingURL=refactoring-applier.d.ts.map