Skip to content

Conversation

@MuriloFP
Copy link
Contributor

@MuriloFP MuriloFP commented Jul 31, 2025

Related GitHub Issue

Closes: #6491

Roo Code Task Context (Optional)

No Roo Code task context for this PR

Description

This PR implements automatic mode switching after importing custom modes. When users import a mode via the import button, they are now automatically switched to the imported mode, eliminating the need for manual switching.

Key implementation details:

  • Added importedModes field to ImportResult interface to track imported mode slugs
  • Modified importModeWithRules method to collect and return imported mode slugs
  • Added mode switching logic in webview message handler after successful import
  • Updated UI components to handle the automatic mode switch
  • Added proper validation to ensure the mode exists before switching
  • Included error handling for mode switch failures
  • Added telemetry tracking for automatic mode switches

Test Procedure

Automated Tests:

  • Run: cd src && npx vitest run core/config/__tests__/CustomModesManager.spec.ts
  • Run: cd src && npx vitest run core/webview/__tests__/webviewMessageHandler.spec.ts
  • Run: cd webview-ui && npx vitest run src/components/modes/__tests__/ModesView.spec.tsx

All 72 tests pass (49 + 12 + 11 across three test suites).

Manual Testing Steps:

  1. Open the modes configuration page
  2. Click the import button and select a mode file
  3. Verify that after successful import, you are automatically switched to the imported mode
  4. Test with a file containing multiple modes - verify it switches to the first mode
  5. Test with an invalid file - verify no mode switch occurs and error is displayed

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

No UI changes in this PR

Documentation Updates

  • No documentation updates are required.

Additional Notes

This feature improves user workflow by reducing manual steps when importing custom modes. The implementation:

Get in Touch

@MuriloFP


Important

Automatically switch to the first imported mode after a successful import, with UI and backend updates to handle mode switching and error handling.

  • Behavior:
    • Automatically switches to the first imported mode after a successful import in webviewMessageHandler.ts.
    • Handles invalid mode slugs gracefully by logging errors without switching.
  • Core Changes:
    • importModeWithRules in CustomModesManager.ts now returns importedModes.
    • webviewMessageHandler.ts updated to switch modes post-import and handle errors.
  • UI Updates:
    • ModesView.tsx updated to handle import results and switch modes.
    • Added import dialog and mode switching logic.
  • Testing:
    • Added tests in CustomModesManager.spec.ts and webviewMessageHandler.spec.ts for import functionality.
    • Added UI tests in ModesView.spec.tsx for mode switching on import.

This description was created by Ellipsis for 0a70720. You can customize this summary. It will automatically update as commits are pushed.

MuriloFP and others added 30 commits July 3, 2025 15:26
…ooCodeInc#6491)

- Add importedModes field to ImportResult interface to track imported mode slugs
- Modify importModeWithRules to collect and return imported mode slugs
- Update webview message handler to automatically switch to first imported mode
- Add proper validation and error handling for mode switching
- Update ModesView to handle automatic mode switching in UI
- Add comprehensive tests for all components

Fixes RooCodeInc#6491
@MuriloFP MuriloFP requested review from cte, jr and mrubens as code owners July 31, 2025 20:06
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Jul 31, 2025
Copy link
Contributor

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! I've reviewed the changes and the implementation looks solid overall. The automatic mode switching after import is working as expected with proper error handling and backward compatibility.

I have a few suggestions for improvement that could make the implementation even more robust.

return () => window.removeEventListener("message", handler)
}, []) // Empty dependency array - only register once
// Re-register handler when dependencies change to ensure it has access to latest values
}, [customModes, findModeBySlug, handleModeSwitch, modes])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The component re-registers the message event handler when dependencies change, which could potentially cause race conditions if multiple imports happen quickly. Consider using a more stable event handling pattern, perhaps with a cleanup function that properly removes the previous handler before adding a new one, or using a ref to maintain handler stability.


if (validMode) {
// Validate that the mode slug is a valid string before type assertion
if (typeof modeToSwitch === "string" && modeToSwitch.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mode slug validation uses type assertion without proper type guards. Consider adding a type guard function for safer validation:

const relativePath = path.relative(modeRulesDir, filePath)
// Normalize path to use forward slashes for cross-platform compatibility
const normalizedRelativePath = relativePath.replace(/\\/g, '/')
const normalizedRelativePath = relativePath.replace(/\\/g, "/")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor style inconsistency - this line uses double quotes while the rest of the file uses single quotes. Consider maintaining consistent quote style:

@MuriloFP MuriloFP marked this pull request as draft July 31, 2025 20:12
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 31, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Draft / In Progress] in Roo Code Roadmap Aug 1, 2025
@hannesrudolph hannesrudolph added PR - Draft / In Progress and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Aug 1, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 22, 2025
@github-project-automation github-project-automation bot moved this from PR [Draft / In Progress] to Done in Roo Code Roadmap Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request PR - Draft / In Progress size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Automatically switch to imported mode after successful import

2 participants