Skip to content

Automatically switch to imported mode after successful import #6491

@MuriloFP

Description

@MuriloFP

What specific problem does this solve?

When users are in the modes configuration page and import a mode using the import button, they currently need to manually switch to the newly imported mode after the import completes. This creates unnecessary friction in the workflow.

Who is affected: All users who import custom modes
When does this happen: Every time a user imports a mode from the modes configuration page
Current behavior: After successful import, the user remains on their current mode and must manually select the imported mode
Expected behavior: After successful import, automatically switch to the imported mode
Impact: Extra clicks and cognitive load - users expect to start using their imported mode immediately

Additional context (optional)

🔍 Comprehensive Issue Scoping
Root Cause / Implementation Target
The current implementation in webviewMessageHandler.ts only updates the state and shows a success message after import, but doesn't trigger a mode switch. The importModeWithRules method returns only { success: boolean, error?: string } without information about which mode was imported.

Affected Components
Primary Files:

src/core/config/CustomModesManager.ts (lines 920-994): Need to modify importModeWithRules to return imported mode slugs
src/core/webview/webviewMessageHandler.ts (lines 1865-1900): Need to add mode switching after successful import
webview-ui/src/components/modes/ModesView.tsx (lines 458-468): Need to handle mode switching in UI
Secondary Impact:

Interface definition at src/core/config/CustomModesManager.ts (lines 41-44)
Tests that verify the import functionality
Current Implementation Analysis
The function at line 953 in CustomModesManager.ts processes each mode in the import but doesn't track which modes were imported. The result only indicates success/failure, not which mode(s) were imported.

Roo Code Task Links (Optional)

No response

Request checklist

  • I've searched existing Issues and Discussions for duplicates
  • This describes a specific problem with clear impact and context

Interested in implementing this?

  • Yes, I'd like to help implement this feature

Implementation requirements

  • I understand this needs approval before implementation begins

How should this be solved? (REQUIRED if contributing, optional otherwise)

Modify the import flow to return information about imported modes and automatically switch to the first imported mode:

Update the ImportResult interface to include imported mode slugs:

interface ImportResult {
success: boolean
error?: string
importedModes?: string[] // Add this field
}

typescript

Modify importModeWithRules method to track and return imported mode slugs

Update the message handler in webviewMessageHandler.ts to:

Check if modes were imported successfully
If single mode imported, switch to it automatically
If multiple modes imported, switch to the first one
Update the UI in ModesView.tsx to handle the mode switch after import

How will we know it works? (Acceptance Criteria - REQUIRED if contributing, optional otherwise)

Given I am on the modes configuration page
When I click import and select a mode file
Then the mode imports successfully
And I am automatically switched to the imported mode
And the UI reflects the mode change immediately
But if import fails, no mode switch occurs

Given I import a file with multiple modes
When the import completes successfully
Then I am switched to the first mode in the file
And all modes are available in the mode selector

Technical considerations (REQUIRED if contributing, optional otherwise)

The importModeWithRules method already loops through modes at line 953, making it easy to collect imported slugs
Mode switching functionality already exists via handleModeSwitch in ClineProvider.ts
The UI already has setVisualMode for immediate visual feedback
Need to ensure backwards compatibility with existing import workflows

Trade-offs and risks (REQUIRED if contributing, optional otherwise)

Alternative approach: Could show a dialog asking which mode to switch to if multiple modes imported, but this adds complexity
Risk: If the imported mode has the same slug as an existing mode, we need to ensure we switch to the newly imported (overwritten) version
Edge case: Need to handle the case where import succeeds but mode switching fails
Breaking change: None - the API change is additive (new optional field)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue - In ProgressSomeone is actively working on this. Should link to a PR soon.enhancementNew feature or requestproposal

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions