diff --git a/.roo/rules-merge-resolver/1_workflow.xml b/.roo/rules-merge-resolver/1_workflow.xml new file mode 100644 index 00000000000..a63809db70e --- /dev/null +++ b/.roo/rules-merge-resolver/1_workflow.xml @@ -0,0 +1,142 @@ + + + This mode resolves merge conflicts for a specific pull request by analyzing git history, + commit messages, and code changes to make intelligent resolution decisions. It receives + a PR number (e.g., "#123") and handles the entire conflict resolution process. + + + + + Parse PR number from user input +
+ Extract the PR number from input like "#123" or "PR #123" + Validate that a PR number was provided +
+
+ + + Fetch PR information + + gh pr view [PR_NUMBER] --json title,body,headRefName,baseRefName + +
+ Get PR title and description to understand the intent + Identify the source and target branches +
+
+ + + Checkout PR branch and prepare for rebase + + gh pr checkout [PR_NUMBER] --force + git fetch origin main + git rebase origin/main + +
+ Force checkout the PR branch to ensure clean state + Fetch the latest main branch + Attempt to rebase onto main to reveal conflicts +
+
+ + + Check for merge conflicts + + git status --porcelain + git diff --name-only --diff-filter=U + +
+ Identify files with merge conflicts (marked with 'UU') + Create a list of files that need resolution +
+
+
+ + + + Analyze each conflicted file to understand the changes + + Read the conflicted file to identify conflict markers + Extract the conflicting sections between <<<<<<< and >>>>>>> + Run git blame on both sides of the conflict + Fetch commit messages and diffs for relevant commits + Analyze the intent behind each change + + + + + Determine the best resolution strategy for each conflict + + Categorize changes by intent (bugfix, feature, refactor, etc.) + Evaluate recency and relevance of changes + Check for structural overlap vs formatting differences + Identify if changes can be combined or if one should override + Consider test updates and related changes + + + + + Apply the resolution strategy to resolve conflicts + + For each conflict, apply the chosen resolution + Ensure proper escaping of conflict markers in diffs + Validate that resolved code is syntactically correct + Stage resolved files with git add + + + + + Verify the resolution and prepare for commit + + Run git status to confirm all conflicts are resolved + Check for any compilation or syntax errors + Review the final diff to ensure sensible resolutions + Prepare a summary of resolution decisions + + + + + + + gh pr checkout [PR_NUMBER] --force + Force checkout the PR branch to ensure clean state + + + + git fetch origin main + Get the latest main branch from origin + + + + git rebase origin/main + Rebase current branch onto main to reveal conflicts + + + + git blame -L [start_line],[end_line] [commit_sha] -- [file_path] + Get commit information for specific lines + + + + git show --format="%H%n%an%n%ae%n%ad%n%s%n%b" --no-patch [commit_sha] + Get commit metadata including message + + + + git show [commit_sha] -- [file_path] + Get the actual changes made in a commit + + + + git ls-files -u + List unmerged files with stage information + + + + + All merge conflicts have been resolved + Resolved files have been staged + No syntax errors in resolved code + Resolution decisions are documented + +
\ No newline at end of file diff --git a/.roo/rules-merge-resolver/2_best_practices.xml b/.roo/rules-merge-resolver/2_best_practices.xml new file mode 100644 index 00000000000..5bf1b393eb2 --- /dev/null +++ b/.roo/rules-merge-resolver/2_best_practices.xml @@ -0,0 +1,165 @@ + + + + Intent-Based Resolution + + Always prioritize understanding the intent behind changes rather than + just looking at the code differences. Commit messages, PR descriptions, + and issue references provide crucial context. + + + Code changes have purpose - bugfixes should be preserved, features + should be integrated properly, and refactors should maintain consistency. + + + Conflict between a bugfix and a refactor + Apply the bugfix logic within the refactored structure + Simply choose one side without considering both intents + + + + + Preserve All Valuable Changes + + When possible, combine non-conflicting changes from both sides rather + than discarding one side entirely. + + + Both sides of a conflict often contain valuable changes that can coexist + if properly integrated. + + + + + Escape Conflict Markers + + When using apply_diff or search_and_replace tools, always escape merge + conflict markers with backslashes to prevent parsing errors. + + + + + + Consider Related Changes + + Look beyond the immediate conflict to understand related changes in + tests, documentation, or dependent code. + + + A change might seem isolated but could be part of a larger feature + or fix that spans multiple files. + + + + + + + Bugfixes generally take precedence over features + + Bugfixes address existing problems and should be preserved, + while features can be reintegrated around the fix. + + + + + More recent changes are often more relevant + + Recent changes likely reflect the current understanding of + requirements and may supersede older implementations. + + + When older changes are bugfixes or security patches that + haven't been addressed in newer code. + + + + + Changes that include test updates are likely more complete + + Developers who update tests alongside code changes demonstrate + thoroughness and understanding of the impact. + + + + + Logic changes take precedence over formatting changes + + Formatting can be reapplied, but logic changes represent + functional improvements or fixes. + + + + + + + Blindly choosing one side without analysis + + You might lose important changes or introduce regressions + + + Always analyze both sides using git blame and commit history + + + + + Ignoring the PR description and context + + The PR description often explains the why behind changes, + which is crucial for proper resolution + + + Always fetch and read the PR information before resolving + + + + + Not validating the resolved code + + Merged code might be syntactically incorrect or introduce + logical errors + + + Always check for syntax errors and review the final diff + + + + + Not escaping conflict markers in diffs + + Unescaped conflict markers (<<<<<<, =======, >>>>>>) in SEARCH + or REPLACE sections will be interpreted as actual diff syntax, + causing the apply_diff tool to fail or produce incorrect results + + + Always escape conflict markers with a backslash (\) when they + appear in the content you're searching for or replacing. + Example: \<<<<<<< HEAD instead of <<<<<<< HEAD + + + + + + + Fetch PR title and description for context + Identify all files with conflicts + Understand the overall change being merged + + + + Run git blame on conflicting sections + Read commit messages for intent + Consider if changes can be combined + Escape conflict markers in diffs + + + + Verify no conflict markers remain + Check for syntax/compilation errors + Review the complete diff + Document resolution decisions + + + \ No newline at end of file diff --git a/.roo/rules-merge-resolver/3_tool_usage.xml b/.roo/rules-merge-resolver/3_tool_usage.xml new file mode 100644 index 00000000000..35f3b5da759 --- /dev/null +++ b/.roo/rules-merge-resolver/3_tool_usage.xml @@ -0,0 +1,228 @@ + + + + execute_command + For all git and gh CLI operations + Git commands provide the historical context needed for intelligent resolution + + + + read_file + To examine conflicted files and understand the conflict structure + Need to see the actual conflict markers and code + + + + apply_diff or search_and_replace + To resolve conflicts by replacing conflicted sections + Precise editing of specific conflict blocks + + + + + + + Always use gh CLI for GitHub operations instead of MCP tools + Chain git commands with && for efficiency + Use --format options for structured output + Capture command output for parsing + + + + + Get PR information + gh pr view [PR_NUMBER] --json title,body,headRefName,baseRefName + + + + Checkout PR branch + gh pr checkout [PR_NUMBER] --force + + + + Fetch latest main branch + git fetch origin main + + + + Rebase onto main to reveal conflicts + git rebase origin/main + + + + Check conflict status + git status --porcelain | grep "^UU" + + + + Get blame for specific lines + git blame -L [start],[end] HEAD -- [file] | cut -d' ' -f1 + + + + Get commit message + git log -1 --format="%s%n%n%b" [commit_sha] + + + + Stage resolved file + git add [file_path] + + + + Continue rebase after resolution + git rebase --continue + + + + + + + Read the entire conflicted file first to understand structure + Note line numbers of conflict markers for precise editing + Identify the pattern of conflicts (multiple vs single) + + + + <<<<<<< HEAD - Start of current branch changes + ======= - Separator between versions + >>>>>>> [branch] - End of incoming changes + + + + + + Always escape conflict markers with backslash + Include enough context to ensure unique matches + Use :start_line: for precision + Combine multiple resolutions in one diff when possible + + + +src/feature.ts + +<<<<<<< SEARCH +:start_line:45 +------- +\<<<<<<< HEAD +function oldImplementation() { + return "old"; +} +\======= +function newImplementation() { + return "new"; +} +\>>>>>>> feature-branch +======= +function mergedImplementation() { + // Combining both approaches + return "merged"; +} +>>>>>>> REPLACE + + + ]]> + + + + + Use for simple conflict resolutions + Enable regex mode for complex patterns + Always escape special characters + + + +src/config.ts +\<<<<<<< HEAD[\s\S]*?\>>>>>>> \w+ +// Resolved configuration +const config = { + // Merged settings from both branches +} +true + + ]]> + + + + + + + execute_command - Get PR info with gh CLI + execute_command - Checkout PR with gh pr checkout --force + execute_command - Fetch origin main + execute_command - Rebase onto origin/main + execute_command - Check for conflicts with git status + + + + + + execute_command - List conflicted files + read_file - Examine conflict structure + execute_command - Git blame on conflict regions + execute_command - Fetch commit messages + + + + + + read_file - Get exact conflict content + apply_diff - Replace conflict with resolution + execute_command - Stage resolved file + execute_command - Verify resolution status + + + + + + execute_command - Check all conflicts resolved + execute_command - Continue rebase with git rebase --continue + execute_command - Verify clean status + + + + + + + Rebase completes without conflicts + + Inform user that PR can be merged without conflicts + No resolution needed + + + + + A rebase is already in progress + + Check status with git status + Either continue existing rebase or abort with git rebase --abort + + + + + Conflict markers are incomplete or nested + + Use search_and_replace with careful regex patterns + Manual inspection may be required + + + + + Binary files cannot be merged automatically + + Identify which version to keep based on PR intent + Use git checkout --theirs or --ours + + + + + Code contains literal conflict marker strings + + Extra careful escaping in diffs + Consider using search_and_replace with precise patterns + + + + \ No newline at end of file diff --git a/.roo/rules-merge-resolver/4_complete_example.xml b/.roo/rules-merge-resolver/4_complete_example.xml new file mode 100644 index 00000000000..dae85879971 --- /dev/null +++ b/.roo/rules-merge-resolver/4_complete_example.xml @@ -0,0 +1,315 @@ + + + User provides PR #123 which has merge conflicts between a bugfix branch + and a feature branch that refactored the same code. + + + + #123 + + + + + Parse PR number and fetch PR information + +gh pr view 123 --json title,body,headRefName,baseRefName + + ]]> + + + The PR is a bugfix for a memory leak issue. This context will help + prioritize preserving the fix during conflict resolution. + + + + + Checkout PR branch and prepare for rebase + +gh pr checkout 123 --force + + ]]> + + + +git fetch origin main + + ]]> + FETCH_HEAD + ]]> + + +git rebase origin/main + + ]]> + ", then run "git rebase --continue". + ]]> + + + + Check for merge conflicts + +git status --porcelain | grep "^UU" + + ]]> + + + Two files have conflicts: the main processor file and its test file. + Both need to be resolved before continuing the rebase. + + + + + Examine the conflicted processor file + +src/data/processor.ts + + ]]> + = new Map(); +47 | +48 | <<<<<<< HEAD +49 | async processData(data: DataInput): Promise { +50 | // Refactored to use async/await +51 | const result = await this.transform(data); +52 | return result; +53 | } +54 | ======= +55 | processData(data: any[]): ProcessedData { +56 | const listener = this.createListener(); +57 | this.listeners.set(data.id, listener); +58 | +59 | return this.transform(data); +60 | } +61 | >>>>>>> abc123 (Fix memory leak in data processor) +62 | +63 | cleanup() { +64 | <<<<<<< HEAD +65 | // TODO: Implement cleanup +66 | ======= +67 | // Fix: Clear all listeners to prevent memory leak +68 | this.listeners.forEach(listener => { +69 | listener.removeAllListeners(); +70 | }); +71 | this.listeners.clear(); +72 | >>>>>>> abc123 (Fix memory leak in data processor) +73 | } +74 | } + ]]> + + + + Analyze the conflicts using git blame + +git blame -L 49,53 HEAD -- src/data/processor.ts | cut -d' ' -f1 | sort -u | xargs -I {} git log -1 --format="%h %s" {} + + ]]> + + + +git log -1 --format="%h %s" abc123 + + ]]> + + + + HEAD (main after rebase): Has async/await refactor but missing listener logic + Incoming (bugfix branch): Adds listener tracking and cleanup for memory leak fix + + Resolution strategy: Combine both changes - keep async/await refactor + but include the listener tracking and cleanup logic. + + + + + Resolve the conflicts + +src/data/processor.ts + +<<<<<<< SEARCH +:start_line:48 +------- +\<<<<<<< HEAD + async processData(data: DataInput): Promise { + // Refactored to use async/await + const result = await this.transform(data); + return result; + } +\======= + processData(data: any[]): ProcessedData { + const listener = this.createListener(); + this.listeners.set(data.id, listener); + + return this.transform(data); + } +\>>>>>>> abc123 (Fix memory leak in data processor) +======= + async processData(data: DataInput): Promise { + // Create and track listener for cleanup (memory leak fix) + const listener = this.createListener(); + this.listeners.set(data.id, listener); + + // Refactored to use async/await + const result = await this.transform(data); + return result; + } +>>>>>>> REPLACE + +<<<<<<< SEARCH +:start_line:63 +------- + cleanup() { +\<<<<<<< HEAD + // TODO: Implement cleanup +\======= + // Fix: Clear all listeners to prevent memory leak + this.listeners.forEach(listener => { + listener.removeAllListeners(); + }); + this.listeners.clear(); +\>>>>>>> abc123 (Fix memory leak in data processor) + } +======= + cleanup() { + // Fix: Clear all listeners to prevent memory leak + this.listeners.forEach(listener => { + listener.removeAllListeners(); + }); + this.listeners.clear(); + } +>>>>>>> REPLACE + + + ]]> + + Combined both changes: kept the async/await refactor from main + while preserving the memory leak fix (listener tracking and cleanup) + from the bugfix branch. + + + + + Resolve test file conflicts + +src/data/processor.test.ts + + ]]> + + +src/data/processor.test.ts + + + + + ]]> + + + + Stage resolved files and continue rebase + +git add src/data/processor.ts src/data/processor.test.ts + + ]]> + + +git rebase --continue + + ]]> + + + + + Final validation + +git status + + ]]> + + + +git diff origin/main --stat + + ]]> + + + + + + +Successfully resolved merge conflicts for PR #123 "Fix memory leak in data processor". + +Resolution Summary: +- src/data/processor.ts: Combined the async/await refactor with the memory leak fix by preserving listener tracking and cleanup logic within the refactored async method +- src/data/processor.test.ts: Updated tests to work with the async implementation while maintaining memory leak test coverage + +Both the feature refactor and the critical bugfix have been preserved in the resolution. The rebase has been completed successfully and the branch is ready to be pushed. + + + ]]> + + + Always checkout PR with --force and rebase to reveal conflicts + Fetch PR context to understand the intent of changes + Use git blame and commit messages to understand the history + Combine non-conflicting improvements when possible + Prioritize bugfixes while accommodating refactors + Complete the rebase process with git rebase --continue + Validate that both sets of changes work together + + \ No newline at end of file diff --git a/.roo/rules-merge-resolver/5_communication.xml b/.roo/rules-merge-resolver/5_communication.xml new file mode 100644 index 00000000000..18594d52696 --- /dev/null +++ b/.roo/rules-merge-resolver/5_communication.xml @@ -0,0 +1,153 @@ + + + Be direct and technical when explaining resolution decisions + Focus on the rationale behind each conflict resolution + Provide clear summaries of what was merged and why + + + I'll help you resolve these conflicts... + Let me handle this for you... + Don't worry about the conflicts... + + + + Analyzing PR #123 for merge conflicts... + Resolving conflicts based on commit history analysis... + Applied resolution strategy: [specific strategy] + + + + + + Acknowledge the PR number + State that you're fetching PR information + Indicate the analysis will begin + + + + Fetching information for PR #123 to understand the context and identify merge conflicts... + + + + + During each major phase of resolution + + Analyzing [X] conflicted files... + Running git blame on [file] to understand change history... + Resolving conflicts in [file] by [strategy]... + Validating resolved changes... + + + + Number of conflicts found + Files being processed + Resolution strategy being applied + + + + + Explain each significant resolution decision + Reference specific commits when relevant + Justify why certain changes were kept or merged + + + + Conflict in [file]: + - HEAD: [brief description of changes] + - Incoming: [brief description of changes] + - Resolution: [what was decided and why] + + + + + + + + Expected a PR number (e.g., "#123" or "123"). Please provide the PR number to resolve conflicts for. + + + + + + PR #[number] does not have any merge conflicts. The branch can be merged without conflict resolution. + + + + + + Could not find PR #[number]. Please verify the PR number and ensure you have access to the repository. + + + + + + Found complex conflicts in [file] that require careful analysis. Examining commit history to determine the best resolution strategy... + + + + + + + State that conflicts are resolved + Provide resolution summary + List files that were resolved + Mention key decisions made + + + + + + Questions about next steps + Offers to do additional work + Uncertain language about the resolution + + + + + Document why specific resolutions were chosen + Reference commit SHAs when they influenced decisions + Explain trade-offs when both sides had valid changes + + + + Preserved bugfix from commit abc123 while adapting it to the refactored structure from def456 + + + Combined both implementations as they addressed different aspects of the same feature + + + Chose the more recent implementation as it included additional error handling + + + + + + + + Binary file conflict in [file]. Based on PR intent "[title]", choosing [which version] version. + + + + + + Conflict: [file] was deleted in one branch but modified in another. Based on the changes, [keeping/removing] the file because [reason]. + + + + + + Conflict in [file] involves only whitespace/formatting. Applying consistent formatting from [which] branch. + + + + \ No newline at end of file diff --git a/.roo/rules-pr-fixer/1_workflow.xml b/.roo/rules-pr-fixer/1_workflow.xml index db74ead7ee5..fb487e5fddf 100644 --- a/.roo/rules-pr-fixer/1_workflow.xml +++ b/.roo/rules-pr-fixer/1_workflow.xml @@ -45,7 +45,7 @@ Determine if the PR is from a fork by checking 'gh pr view [PR_NUMBER] --repo [owner]/[repo] --json isCrossRepository'. Apply code changes based on review feedback using file editing tools. Fix failing tests by modifying test files or source code as needed. - For conflict resolution: Use GIT_EDITOR=true for non-interactive rebases, then resolve conflicts via file editing. + For conflict resolution: Delegate to merge-resolver mode using new_task with the PR number. If changes affect user-facing content (i18n files, UI components, announcements), delegate translation updates using the new_task tool with translate mode. Review modified files with 'git status --porcelain' to ensure no temporary files are included. Stage files selectively using 'git add -u' (for modified tracked files) or 'git add ' (for new files). diff --git a/.roo/rules-pr-fixer/2_best_practices.xml b/.roo/rules-pr-fixer/2_best_practices.xml index 50a8395b9cd..2dc5775cedf 100644 --- a/.roo/rules-pr-fixer/2_best_practices.xml +++ b/.roo/rules-pr-fixer/2_best_practices.xml @@ -41,33 +41,25 @@ - How to correctly escape conflict markers when using apply_diff. + Delegate merge conflict resolution to the merge-resolver mode. diff --git a/.roo/rules-pr-fixer/3_common_patterns.xml b/.roo/rules-pr-fixer/3_common_patterns.xml index 1c6c0bcf650..4ef2a34b9e6 100644 --- a/.roo/rules-pr-fixer/3_common_patterns.xml +++ b/.roo/rules-pr-fixer/3_common_patterns.xml @@ -27,32 +27,26 @@ Commands to detect merge conflicts. - - Rebase operations using GIT_EDITOR to prevent interactive prompts. + + Delegate merge conflict resolution to the merge-resolver mode. - - Check current conflict status without interactive input. - - Check out a pull request branch locally.