Procházet zdrojové kódy

feat: add translation orchestration to PR Fixer mode (#5280)

Co-authored-by: Daniel Riccio <[email protected]>
Hannes Rudolph před 6 měsíci
rodič
revize
adb3ee9a11

+ 13 - 5
.roo/rules-pr-fixer/1_workflow.xml

@@ -41,17 +41,24 @@
     <phase name="implementation">
       <description>Execute the user's chosen course of action.</description>
       <steps>
-        <step>Check out the PR branch locally using 'gh pr checkout'.</step>
-        <step>Apply code changes based on review feedback.</step>
-        <step>Fix failing tests.</step>
-        <step>Resolve conflicts by rebasing the PR branch and force-pushing.</step>
+        <step>Check out the PR branch locally using 'gh pr checkout --force'.</step>
+        <step>Determine if the PR is from a fork by checking 'gh pr view --json isCrossRepository'.</step>
+        <step>Apply code changes based on review feedback using file editing tools.</step>
+        <step>Fix failing tests by modifying test files or source code as needed.</step>
+        <step>For conflict resolution: Use GIT_EDITOR=true for non-interactive rebases, then resolve conflicts via file editing.</step>
+        <step>If changes affect user-facing content (i18n files, UI components, announcements), delegate translation updates using the new_task tool with translate mode.</step>
+        <step>Commit changes using git commands.</step>
+        <step>Push changes to the correct remote (origin for same-repo PRs, fork remote for cross-repo PRs) using 'git push --force-with-lease'.</step>
       </steps>
     </phase>
 
     <phase name="validation">
       <description>Verify that the pushed changes resolve the issues.</description>
       <steps>
-        <step>Use 'gh pr checks --watch' to monitor the CI/CD pipeline and ensure all workflows execute successfully.</step>
+        <step>Use 'gh pr checks --watch' to monitor check status in real-time until all checks complete.</step>
+        <step>If needed, check specific workflow runs with 'gh run list --pr' for detailed CI/CD pipeline status.</step>
+        <step>Verify that all translation updates (if any) have been completed and committed.</step>
+        <step>Confirm PR is ready for review by checking mergeable state with 'gh pr view --json'.</step>
       </steps>
     </phase>
   </main_workflow>
@@ -60,5 +67,6 @@
     <criterion>All actionable review comments have been addressed.</criterion>
     <criterion>All tests are passing.</criterion>
     <criterion>The PR is free of merge conflicts.</criterion>
+    <criterion>All required translations have been completed and committed (if changes affect user-facing content).</criterion>
   </completion_criteria>
 </workflow_instructions>

+ 10 - 0
.roo/rules-pr-fixer/2_best_practices.xml

@@ -10,6 +10,16 @@
       <description>Address issues one at a time (e.g., fix tests first, then address comments). This makes the process more manageable and easier to validate.</description>
       <rationale>Tackling all issues at once can be complex and error-prone.</rationale>
     </principle>
+    <principle priority="high">
+      <name>Handle Fork Remotes Correctly</name>
+      <description>Always check if a PR comes from a fork (cross-repository) before pushing changes. Use 'gh pr view --json isCrossRepository' to determine the correct remote.</description>
+      <rationale>Pushing to the wrong remote (e.g., origin instead of fork) will fail for cross-repository PRs.</rationale>
+      <example>
+        <scenario>PR from a fork</scenario>
+        <good>Check isCrossRepository, add fork remote if needed, push to fork</good>
+        <bad>Always push to origin without checking PR source</bad>
+      </example>
+    </principle>
   </general_principles>
 
   <code_conventions>

+ 72 - 16
.roo/rules-pr-fixer/3_common_patterns.xml

@@ -24,31 +24,87 @@
       </command>
     </template>
   </pattern>
-  <pattern name="resolving_conflicts_rebase">
-    <usage>A sequence of commands to resolve merge conflicts locally using rebase.</usage>
+  <pattern name="detecting_conflicts">
+    <usage>Commands to detect merge conflicts.</usage>
+    <template>
+      <comment>Fetch latest main branch</comment>
+      <command tool="git">git fetch origin main</command>
+      <comment>Check if rebase would create conflicts</comment>
+      <command tool="git">git rebase --dry-run origin/main</command>
+    </template>
+  </pattern>
+  
+  <pattern name="non_interactive_rebase">
+    <usage>Rebase operations using GIT_EDITOR to prevent interactive prompts.</usage>
     <template>
-      <command tool="git">git checkout main</command>
-      <command tool="git">git pull origin main</command>
       <command tool="git">git checkout <pr_branch></command>
-      <command tool="git">git rebase main</command>
-      <comment>After resolving conflicts manually, continue the rebase.</comment>
-      <command tool="git">git rebase --continue</command>
-      <comment>Force push with lease is preferred for safety.</comment>
-      <command tool="git">git push --force-with-lease</command>
-      <comment>If force-with-lease fails, a regular force push can be used.</comment>
-      <command tool="git">git push --force</command>
+      <command tool="git">GIT_EDITOR=true git rebase main</command>
+      <comment>If conflicts occur, resolve them manually then use 'git rebase --continue'</comment>
+      <command tool="git">git push --force-with-lease <remote> <pr_branch></command>
+    </template>
+  </pattern>
+  
+  <pattern name="conflict_status_check">
+    <usage>Check current conflict status without interactive input.</usage>
+    <template>
+      <command tool="git">git status --porcelain</command>
+      <command tool="git">git diff --name-only --diff-filter=U</command>
+      <comment>List files with unresolved conflicts</comment>
+      <command tool="git">git ls-files --unmerged</command>
     </template>
   </pattern>
   <pattern name="checking_out_pr">
-    <usage>Command to check out a pull request branch locally.</usage>
+    <usage>Check out a pull request branch locally.</usage>
+    <template>
+      <command tool="gh">gh pr checkout <pr_number_or_url> --force</command>
+      <comment>Alternative if gh checkout fails:</comment>
+      <command tool="git">git fetch origin pull/<pr_number>/head:<branch_name> && git checkout <branch_name></command>
+    </template>
+  </pattern>
+  
+  <pattern name="determine_push_remote">
+    <usage>Determine the correct remote to push to (handles forks).</usage>
+    <template>
+      <comment>Get PR metadata to check if it's from a fork</comment>
+      <command tool="gh">gh pr view <pr_number> --json headRepositoryOwner,headRefName,isCrossRepository</command>
+      <comment>If isCrossRepository is true, it's from a fork</comment>
+      <command tool="git">git remote -v</command>
+      <comment>Check if fork remote exists, otherwise add it</comment>
+      <command tool="git">git remote add fork https://github.com/<fork_owner>/<repo_name>.git</command>
+      <comment>Use appropriate remote based on PR source</comment>
+    </template>
+  </pattern>
+  
+  <pattern name="real_time_monitoring">
+    <usage>Monitor PR checks in real-time as they run.</usage>
+    <template>
+      <command tool="gh">gh pr checks <pr_number> --watch</command>
+      <comment>Continuously monitor check status with automatic updates</comment>
+      <alternative>For one-time status check: gh pr checks <pr_number> --json state,conclusion,name,detailsUrl</alternative>
+      <command tool="gh">gh run list --pr <pr_number> --json databaseId,status,conclusion</command>
+    </template>
+  </pattern>
+  
+  <pattern name="safe_push_operations">
+    <usage>Push operations that handle both origin and fork remotes correctly.</usage>
     <template>
-      <command tool="gh">gh pr checkout <pr_number_or_url></command>
+      <comment>First determine the correct remote (origin or fork)</comment>
+      <command tool="gh">gh pr view <pr_number> --json headRepositoryOwner,headRefName,isCrossRepository</command>
+      <comment>If isCrossRepository is false, push to origin</comment>
+      <command tool="git">git push --force-with-lease origin <branch_name></command>
+      <comment>If isCrossRepository is true, push to fork remote</comment>
+      <command tool="git">git push --force-with-lease fork <branch_name></command>
+      <comment>If force-with-lease fails, fetch and retry</comment>
+      <command tool="git">git fetch <remote> <branch_name></command>
+      <command tool="git">git push --force <remote> <branch_name></command>
     </template>
   </pattern>
-  <pattern name="watching_pr_checks">
-    <usage>After pushing changes, use this command to monitor the CI/CD pipeline in real-time.</usage>
+
+  <pattern name="automated_commit_operations">
+    <usage>Commit operations that work in automated environments.</usage>
     <template>
-      <command tool="gh">gh pr checks --watch</command>
+      <command tool="git">git add .</command>
+      <command tool="git">git commit -m "<commit_message>"</command>
     </template>
   </pattern>
 </common_patterns>

+ 69 - 0
.roo/rules-pr-fixer/4_tool_usage.xml

@@ -11,6 +11,11 @@
       <why>Quickly identifies if there are failing automated checks that need investigation.</why>
    </priority>
    <priority level="3">
+     <tool>new_task (mode: translate)</tool>
+     <when>When changes affect user-facing content, i18n files, or UI components that require translation.</when>
+     <why>Ensures translation consistency across all supported languages when PR fixes involve user-facing changes.</why>
+   </priority>
+   <priority level="4">
      <tool>gh pr checks --watch</tool>
      <when>After pushing a fix, to confirm that the changes have resolved the CI/CD failures.</when>
      <why>Provides real-time feedback on whether the fix was successful.</why>
@@ -35,6 +40,41 @@
       <best_practices>
         <practice>Use this command to get the exact error messages from failing tests.</practice>
         <practice>Search the log for keywords like 'error', 'failed', or 'exception' to quickly find the root cause.</practice>
+        <practice>Always specify run ID explicitly to avoid interactive selection prompts.</practice>
+      </best_practices>
+    </tool>
+
+    <tool name="gh pr checkout">
+      <best_practices>
+        <practice>Use --force flag: 'gh pr checkout <pr_number> --force'</practice>
+        <practice>If gh checkout fails, use: git fetch origin pull/<pr_number>/head:<branch_name></practice>
+      </best_practices>
+    </tool>
+
+    <tool name="git operations">
+      <best_practices>
+        <practice>Use --force-with-lease for safer force pushing.</practice>
+        <practice>Use GIT_EDITOR=true to prevent interactive prompts during rebases.</practice>
+        <practice>Always determine the correct remote before pushing (origin vs fork).</practice>
+      </best_practices>
+      <remote_handling>
+        <step>Check if PR is from a fork: 'gh pr view <pr_number> --json isCrossRepository'</step>
+        <step>If isCrossRepository is true, add fork remote if needed</step>
+        <step>Push to appropriate remote: 'git push --force-with-lease <remote> <branch>'</step>
+      </remote_handling>
+      <conflict_resolution>
+        <step>Use 'GIT_EDITOR=true git rebase main' to start rebase</step>
+        <step>If conflicts occur, edit files to resolve them</step>
+        <step>Use 'git add .' and 'git rebase --continue' to proceed</step>
+      </conflict_resolution>
+    </tool>
+
+    <tool name="gh pr checks">
+      <best_practices>
+        <practice>Use --watch flag to monitor checks in real-time: 'gh pr checks <pr_number> --watch'</practice>
+        <practice>For one-time status checks, use --json flag: 'gh pr checks <pr_number> --json state,conclusion,name'</practice>
+        <practice>The --watch flag automatically updates the display as check statuses change.</practice>
+        <practice>Use 'gh run list --pr <pr_number>' to get detailed workflow status if needed.</practice>
       </best_practices>
     </tool>
     
@@ -45,5 +85,34 @@
         <practice>Example suggestions: "Address review comments first.", "Tackle the failing tests.", "Resolve merge conflicts."</practice>
       </best_practices>
     </tool>
+
+    <tool name="new_task (mode: translate)">
+      <best_practices>
+        <practice>Use when PR fixes involve changes to user-facing strings, i18n files, or UI components.</practice>
+        <practice>Provide specific details about what content needs translation in the message.</practice>
+        <practice>Include file paths and descriptions of the changes made.</practice>
+        <practice>List all affected languages that need updates.</practice>
+        <practice>Wait for translation completion before proceeding to validation phase.</practice>
+      </best_practices>
+      <when_to_use>
+        <trigger>Changes to webview-ui/src/i18n/locales/en/*.json files</trigger>
+        <trigger>Changes to src/i18n/locales/en/*.json files</trigger>
+        <trigger>Modifications to UI components with user-facing text</trigger>
+        <trigger>Updates to announcement files or documentation requiring localization</trigger>
+        <trigger>Addition of new error messages or user notifications</trigger>
+      </when_to_use>
+      <example_usage><![CDATA[
+<new_task>
+<mode>translate</mode>
+<message>Translation updates needed for PR #1234 fixes. Please translate the following changes:
+
+Files modified:
+- webview-ui/src/i18n/locales/en/common.json: Added new error message "connection_failed"
+- webview-ui/src/components/settings/ApiSettings.tsx: Updated button text from "Save" to "Save Configuration"
+
+Please ensure all supported languages (ca, de, es, fr, hi, id, it, ja, ko, nl, pl, pt-BR, ru, tr, vi, zh-CN, zh-TW) are updated with appropriate translations for these changes.</message>
+</new_task>
+      ]]></example_usage>
+    </tool>
   </tool_specific_guidance>
 </tool_usage_guide>

+ 112 - 4
.roo/rules-pr-fixer/5_examples.xml

@@ -62,7 +62,7 @@
         <description>Check out the pull request branch.</description>
         <tool_use>
           <execute_command>
-            <command>gh pr checkout 4365</command>
+            <command>gh pr checkout 4365 --force</command>
           </execute_command>
         </tool_use>
         <analysis>The PR branch is now ready for local edits.</analysis>
@@ -82,13 +82,13 @@
         </tool_use>
       </step>
      <step number="6">
-       <description>After pushing the changes, watch the PR checks to confirm the fix.</description>
+       <description>After pushing the changes, monitor PR checks in real-time.</description>
        <tool_use>
          <execute_command>
-           <command>gh pr checks --watch</command>
+           <command>gh pr checks 4365 --watch</command>
          </execute_command>
        </tool_use>
-       <analysis>Confirm that all checks are passing after the fix.</analysis>
+       <analysis>Monitor checks continuously until all complete. The --watch flag provides real-time updates as check statuses change.</analysis>
      </step>
     </workflow>
 
@@ -97,4 +97,112 @@
       <takeaway>Use a combination of the GitHub MCP server and the `gh` CLI to get a complete picture of the PR's status.</takeaway>
     </key_takeaways>
   </example>
+
+  <example name="fix_pr_with_translation_requirements">
+    <scenario>
+      A pull request has review comments requesting UI text changes that require translation updates across all supported languages.
+    </scenario>
+    
+    <user_request>
+      Fix PR #1234 in RooCodeInc/Roo-Code - the reviewer asked to change button text and there are some failing tests.
+    </user_request>
+
+    <workflow>
+      <step number="1">
+        <description>Get PR details and analyze changes.</description>
+        <tool_use>
+<use_mcp_tool>
+  <server_name>github</server_name>
+  <tool_name>get_pull_request</tool_name>
+  <arguments>
+    {
+      "owner": "RooCodeInc",
+      "repo": "Roo-Code",
+      "pullNumber": 1234
+    }
+  </arguments>
+</use_mcp_tool>
+        </tool_use>
+        <expected_outcome>Identify the files changed and review feedback requiring UI text modifications.</expected_outcome>
+      </step>
+
+      <step number="2">
+        <description>Check out PR and apply the requested changes.</description>
+        <tool_use>
+<execute_command>
+<command>gh pr checkout 1234 --force</command>
+</execute_command>
+        </tool_use>
+        <analysis>Make the requested button text changes in the UI components.</analysis>
+      </step>
+
+      <step number="3">
+        <description>Identify translation requirements and delegate to translate mode.</description>
+        <tool_use>
+<new_task>
+<mode>translate</mode>
+<message>Translation updates needed for PR #1234 fixes. The following changes were made based on review feedback:
+
+Files modified:
+- webview-ui/src/components/settings/ApiSettings.tsx: Changed button text from "Save" to "Save Configuration"
+- webview-ui/src/i18n/locales/en/common.json: Updated key "save_button" to "save_config_button"
+
+Please update all supported languages (ca, de, es, fr, hi, id, it, ja, ko, nl, pl, pt-BR, ru, tr, vi, zh-CN, zh-TW) with appropriate translations for:
+- New key "save_config_button" with translation equivalent to "Save Configuration"
+- Any other text changes that affect user-facing content
+
+Ensure consistency across all language files and maintain the same context and tone as existing translations.</message>
+</new_task>
+        </tool_use>
+        <expected_outcome>Translation subtask created and all language files updated.</expected_outcome>
+      </step>
+
+      <step number="4">
+        <description>Commit all changes including translations with automated git configuration.</description>
+        <tool_use>
+<execute_command>
+<command>git add . && git commit -m "fix: update button text and translations as requested in review"</command>
+</execute_command>
+        </tool_use>
+        <analysis>All code changes and translation updates are now committed.</analysis>
+      </step>
+
+      <step number="5">
+        <description>Check if PR is from a fork and push to correct remote.</description>
+        <tool_use>
+<execute_command>
+<command>gh pr view 1234 --json isCrossRepository,headRepositoryOwner,headRefName</command>
+</execute_command>
+        </tool_use>
+        <analysis>Determine if this is a cross-repository PR to know which remote to push to.</analysis>
+      </step>
+      
+      <step number="6">
+        <description>Push changes to the appropriate remote.</description>
+        <tool_use>
+<execute_command>
+<command>git push --force-with-lease origin <branch_name></command>
+</execute_command>
+        </tool_use>
+        <analysis>Push changes safely to update the pull request. Use 'fork' remote instead if PR is from a fork.</analysis>
+      </step>
+
+      <step number="7">
+        <description>Monitor CI status in real-time.</description>
+        <tool_use>
+<execute_command>
+<command>gh pr checks 1234 --watch</command>
+</execute_command>
+        </tool_use>
+        <analysis>Watch CI checks continuously until all tests pass. The --watch flag provides automatic updates as check statuses change.</analysis>
+      </step>
+    </workflow>
+
+    <key_takeaways>
+      <takeaway>Always check if PR fixes involve user-facing content that requires translation.</takeaway>
+      <takeaway>Use new_task with translate mode to ensure consistent translation updates.</takeaway>
+      <takeaway>Include detailed context about what changed and why in translation requests.</takeaway>
+      <takeaway>Verify translation completeness before considering the PR fix complete.</takeaway>
+    </key_takeaways>
+  </example>
 </complete_examples>