Improving & Refactoring Code
Safe refactoring with workspace isolation in Verdent
Verdent's workspace isolation makes refactoring safer by allowing you to experiment in isolated workspaces before rebasing changes.
What You'll Learn
- Use workspace isolation for safe refactoring
- Execute multi-file refactoring workflows
- Leverage parallel agents for large refactors
Using Workspace Isolation
Why Workspaces for Refactoring
| Benefit | Description |
|---|---|
| Safe experimentation | Changes isolated from master branch |
| Easy rollback | Delete workspace to discard changes |
| Clean diffs | All changes in one reviewable branch |
| No interference | Other work continues unaffected |
Refactoring Setup
Create Workspace
Click New Workspace in the Top Bar with a descriptive name (e.g., refactor-auth-module)
Work in Workspace
Verdent now operates in the isolated workspace
Execute Refactoring
In the input box, describe the refactoring changes you want
Review Changes
Click Task Changes in the middle panel to review all modifications
Rebase or Discard
Click Workspace Actions → Rebase to main branch if satisfied, or Delete Workspace in the Workspace Bar to discard
Refactoring Workflows
Rename symbols across your entire codebase:
Rename the function getUserData to fetchUserProfile across the entire codebase,
including all imports, references, and documentationWhat Verdent does:
- Finds all occurrences using search
- Updates function definition
- Updates all import statements
- Updates all call sites
- Updates comments and documentation
Extract logic into separate functions or components:
Extract the validation logic from @userForm.tsx into a separate validateUserInput function
in @utils/validation.tsWhat Verdent does:
- Identifies the logic to extract
- Creates the new function/file
- Updates original to use the extracted code
- Maintains all imports and types
Restructure code architecture:
Refactor @services/ from class-based services to functional modules.
Follow the pattern in @services/productService.ts which has already been converted.Best approach:
- Use Plan Mode first to review approach
- Approve plan after reviewing scope
- Execute in isolated workspace
- Review all changes before rebasing
Comparing Changes
Review Workflow
Open Task Changes
Click Task Changes in the middle panel to review changes
Review Each File
Navigate through changed files
Verify Tests
Run tests to verify refactoring correctness
Desktop-Specific Refactoring
Parallel Refactoring
For large codebases, split refactoring across workspaces:
flowchart TD
B[master branch - stable] --> W1[Workspace 1: refactor-auth]
B --> W2[Workspace 2: refactor-api]
B --> W3[Workspace 3: refactor-utils]Coordination:
- Assign independent modules to different workspaces
- Minimize overlap to reduce rebase conflicts
- Rebase in dependency order
Use Plan Mode first to define the target architecture and function signatures. Pass these signatures to each agent so they understand the final structure and can implement compatible interfaces across workspaces.
Plan Mode for Complex Refactors
Switch to Plan Mode
Press Shift+Tab or Ctrl+. to switch to Plan Mode
Describe Refactoring
In the input box, describe the refactoring:
Plan a refactoring of the authentication module to:
- Split monolithic auth service into smaller focused services
- Add proper TypeScript types
- Improve testabilityReview Plan
Verdent creates detailed plan with affected files and steps
Iterate
Ask questions, refine approach until satisfied
Execute
Switch to Agent Mode to implement in the workspace
Common Refactoring Patterns
The @UserList.tsx and @ProductList.tsx components share pagination logic.
Extract the common pagination logic into a usePagination hook in @hooks/Update all class components in @components/ to functional components with hooks.
Preserve the existing behavior and props interface.Add proper TypeScript types to @api/client.ts.
The API responses currently use 'any' types - create proper interfaces based on the actual response shapes.Find and consolidate duplicate utility functions across @utils/ and @helpers/.
Keep the most complete implementation and update all imports.FAQs
What if refactoring breaks something?
In a workspace:
- Run tests to identify failures
- Fix issues or request Verdent to fix
- If too broken, delete workspace and start fresh
The master branch remains unaffected until you rebase.
How do I handle conflicts when rebasing?
- Complete refactoring in workspace
- Sync with base using Workspace Actions → Sync with main branch
- Resolve any conflicts in the workspace
- Then click Workspace Actions → Rebase to main branch
This keeps conflict resolution contained to the workspace.
Should I refactor in small pieces or all at once?
Small pieces are safer:
- Easier to review
- Faster to rollback if needed
- Tests can validate each step
All at once can work for:
- Tightly coupled changes
- Rename operations
- When using isolated workspace