Workspace is a tool suite for file operations, version management, and development workflow automation. Includes refac (string replacement), scrap (local trash folder), unscrap (file restoration), and state (automatic versioning).
The wsb refactor tool is a string replacement engine designed for safe code refactoring and content modification across codebases.
Refac (short for βrefactorβ) provides string replacement capabilities with:
wsb refactor <directory> <old_string> <new_string> [OPTIONS]
# Refac always previews changes and asks for confirmation
wsb refactor ./src "OldClassName" "NewClassName" --verbose
# Apply with backup for safety
wsb refactor ./src "OldClassName" "NewClassName" --backup
# Target specific file types
wsb refactor ./src "old_api" "new_api" --include "*.rs" --include "*.toml"
Refac validates every operation before making changes:
# Validation process (automatic):
# 1. File accessibility check
# 2. Encoding validation
# 3. Permission verification
# 4. Collision detection
# 5. Path length validation
# 6. Disk space check
Validation Output Example:
INFO: Phase 1: Discovering files and directories...
INFO: Phase 2: Checking for naming collisions...
INFO: Phase 3: Validating all operations...
INFO: Validation passed: All operations can be performed safely.
Refac always shows changes before applying them and asks for confirmation:
# Basic operation (shows preview automatically)
wsb refactor . "oldname" "newname"
# Verbose output with detailed information
wsb refactor . "oldname" "newname" --verbose
# JSON output for scripting (still shows preview)
wsb refactor . "oldname" "newname" --format json
Preview Output Example:
=== CHANGE SUMMARY ===
Content modifications: 15 file(s)
File renames: 8 file(s)
Directory renames: 3 directory(ies)
Total changes: 26
FILES TO BE MODIFIED:
src/main.rs: 3 occurrence(s)
src/lib.rs: 1 occurrence(s)
tests/integration.rs: 2 occurrence(s)
FILES TO BE RENAMED:
oldname_config.toml β newname_config.toml
src/oldname_module.rs β src/newname_module.rs
Optimized parallel processing for large datasets:
# Use multiple threads for faster processing
wsb refactor . "oldname" "newname" --threads 8
# Auto-detect optimal thread count
wsb refactor . "oldname" "newname" --threads 0
# Progress tracking for long operations
wsb refactor . "oldname" "newname" --progress always
Performance Features:
Control exactly what gets modified:
# Only rename files and directories (skip content)
wsb refactor . "oldproject" "newproject" --names-only
# Only replace content (skip renaming)
wsb refactor . "old.api.com" "new.api.com" --content-only
# Only process files (skip directories)
wsb refactor . "oldname" "newname" --files-only
# Only process directories (skip files)
wsb refactor . "oldname" "newname" --dirs-only
Precise control over which files are processed:
# Include specific file types
wsb refactor . "oldname" "newname" \
--include "*.rs" \
--include "*.toml" \
--include "*.md"
# Exclude unwanted areas
wsb refactor . "oldname" "newname" \
--exclude "target/*" \
--exclude "*.log" \
--exclude ".git/*"
# Complex filtering
wsb refactor ./src "OldStruct" "NewStruct" \
--include "*.rs" \
--exclude "*/tests/*" \
--exclude "*/examples/*"
Manage traversal depth for large projects:
# Limit to current directory only
wsb refactor . "oldname" "newname" --max-depth 1
# Search 3 levels deep
wsb refactor . "oldname" "newname" --max-depth 3
# Unlimited depth (default)
wsb refactor . "oldname" "newname" --max-depth 0
Safe modification with automatic backups:
# Create backups before modifying files
wsb refactor . "oldname" "newname" --backup
# Backups are created with .refac_backup extension
# Example: config.toml β config.toml.refac_backup
Backup Features:
Mission-critical safety features:
# Force operation without confirmation
wsb refactor . "oldname" "newname" --force
# Case-sensitive matching (default)
wsb refactor . "OldName" "NewName"
# Show detailed error information
wsb refactor . "oldname" "newname" --verbose
Safety Guarantees:
Consistent behavior across all platforms:
# Works identically on Windows, macOS, and Linux
wsb refactor . "oldname" "newname"
# Handles platform-specific path separators
wsb refactor . "old\\path" "new/path" # Windows
wsb refactor . "old/path" "new/path" # Unix-like
Platform Features:
Migrate from old API to new API across entire codebase:
# 1. Review the migration (wsb refactor shows changes before applying)
wsb refactor ./src "old_api::Client" "new_api::Client" --verbose
# 2. Update import statements
wsb refactor ./src "use old_api" "use new_api" --content-only --include "*.rs"
# 3. Update function calls
wsb refactor ./src "old_api::connect" "new_api::connect" --content-only
# 4. Update configuration files
wsb refactor ./config "old_api_endpoint" "new_api_endpoint" --content-only --include "*.toml"
Rename a project throughout the codebase:
# 1. Update package names
wsb refactor . "oldproject" "newproject" --include "Cargo.toml" --include "package.json"
# 2. Update file names and directory structure
wsb refactor . "oldproject" "newproject" --names-only
# 3. Update content references
wsb refactor . "oldproject" "newproject" --content-only --exclude "target/*"
# 4. Update documentation
wsb refactor ./docs "OldProject" "NewProject" --include "*.md"
Reorganize and rename code components:
# 1. Rename a module throughout the codebase
wsb refactor ./src "user_service" "account_service" --include "*.rs"
# 2. Update struct names
wsb refactor ./src "UserData" "AccountData" --content-only --include "*.rs"
# 3. Update configuration keys
wsb refactor ./config "user_" "account_" --content-only --include "*.toml" --include "*.yaml"
Update configuration across multiple environments:
# Update API endpoints across all configs
wsb refactor ./config "api.old.com" "api.new.com" \
--content-only \
--include "*.toml" \
--include "*.yaml" \
--include "*.json" \
--include "*.env"
# Update database connection strings
wsb refactor ./config "old_database" "new_database" \
--content-only \
--backup
Default format with clear progress information:
=== REFAC TOOL ===
Root directory: /path/to/project
Old string: 'oldname'
New string: 'newname'
Mode: Full
Phase 1: Discovering files and directories...
Found 1,234 files and 56 directories to process
Phase 2: Checking for naming collisions...
No collisions detected
Phase 3: Validating all operations...
Validation passed: All operations can be performed safely.
=== CHANGE SUMMARY ===
Content modifications: 15 file(s)
File renames: 8 file(s)
Directory renames: 3 directory(ies)
Total changes: 26
Do you want to proceed? (y/N) y
Replacing content in files...
[ββββββββββββββββββββββββββββββββββββββββ] 15/15 files
Renaming files and directories...
[ββββββββββββββββββββββββββββββββββββββββ] 11/11 items
=== OPERATION COMPLETE ===
Operation completed successfully!
Total changes applied: 26
Machine-readable format for automation:
wsb refactor . "oldname" "newname" --format json
{
"summary": {
"content_changes": 15,
"file_renames": 8,
"directory_renames": 3,
"total_changes": 26
},
"operations": [
{
"type": "content_replace",
"file": "src/main.rs",
"occurrences": 3
},
{
"type": "file_rename",
"from": "oldname_config.toml",
"to": "newname_config.toml"
}
],
"result": "success",
"interactive": false,
"execution_time_ms": 1234
}
Minimal output for scripting:
wsb refactor . "oldname" "newname" --format plain
Content changes: 15
File renames: 8
Directory renames: 3
Total changes: 26
| Option | Short | Description |
|βββ|ββ-|ββββ-|
| --assume-yes | -y | Skip confirmation prompts (non-interactive mode) |
| --verbose | -v | Show detailed output |
| --backup | -b | Create backup files before modification |
| Option | Description |
|βββ|ββββ-|
| --names-only | Only rename files/directories, skip content |
| --content-only | Only replace content, skip renaming |
| --files-only | Only process files, skip directories |
| --dirs-only | Only process directories, skip files |
| Option | Description |
|βββ|ββββ-|
| --include <pattern> | Include only files matching pattern |
| --exclude <pattern> | Exclude files matching pattern |
| --max-depth <n> | Maximum depth to search (0 = unlimited) |
| --follow-symlinks | Follow symbolic links |
| Option | Short | Description |
|βββ|ββ-|ββββ-|
| --threads <n> | -j | Number of threads (0 = auto) |
| --progress <mode> | | Progress display: auto, always, never |
| Option | Description |
|βββ|ββββ-|
| --format <format> | Output format: human, json, plain |
| --quiet | Suppress non-essential output |
--backup for important files--include and --exclude patterns--threads for optimal performance--max-depth for deep directory structuresβPermission deniedβ errors
# Check file permissions
ls -la affected_file.txt
# Run with appropriate permissions
sudo wsb refactor . "oldname" "newname" # Use carefully
βNo changes foundβ when changes expected
# Use verbose mode to see what's being processed
wsb refactor . "oldname" "newname" --verbose
# Check case sensitivity
wsb refactor . "OldName" "NewName" # vs "oldname" "newname"
# Verify include/exclude patterns
wsb refactor . "oldname" "newname" --include "*.txt" --verbose
βNaming collision detectedβ
# Review the collision report (shown automatically)
wsb refactor . "oldname" "newname" --verbose
# Resolve conflicts manually before proceeding
mv conflicting_file.txt conflicting_file_backup.txt
wsb refactor . "oldname" "newname"
Binary files not being processed
# This is by design for safety
# Use verbose mode to see which files are skipped
wsb refactor . "oldname" "newname" --verbose --content-only
For detailed debugging information:
# Maximum verbosity (shows preview automatically)
wsb refactor . "oldname" "newname" --verbose --progress always
# Check specific file processing
wsb refactor specific_file.txt "oldname" "newname" --verbose
# Safe refactoring workflow
git checkout -b refactor-api-names
git add .
git commit -m "Checkpoint before refactoring"
wsb refactor ./src "old_api" "new_api" --verbose
wsb refactor ./src "old_api" "new_api" --backup
git add .
git commit -m "Refactor API names from old_api to new_api"
# Update build configurations
wsb refactor . "old_target_name" "new_target_name" \
--include "Makefile" \
--include "*.cmake" \
--include "*.toml" \
--content-only
#!/bin/bash
# Automated refactoring script
set -e
# Validate refactoring first (using assume-yes for non-interactive)
if wsb refactor ./src "$OLD_NAME" "$NEW_NAME" --assume-yes --format json > refac_plan.json; then
echo "Refactoring plan validated"
# Apply changes
wsb refactor ./src "$OLD_NAME" "$NEW_NAME" --format json > refac_result.json
# Verify success
if [ $? -eq 0 ]; then
echo "Refactoring completed successfully"
exit 0
else
echo "Refactoring failed"
exit 1
fi
else
echo "Refactoring validation failed"
exit 1
fi
The wsb refactor tool provides comprehensive, safe, and efficient string replacement capabilities for any scale of refactoring operation, from small tweaks to large-scale codebase transformations.