mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-10-10 03:28:03 +00:00
fix: preserve .roomodes file formatting when importing modes
- Modified updateModesInFile method to detect and preserve original YAML formatting - Analyzes existing file indentation and applies same formatting when rewriting - Prevents complete reformatting of .roomodes files during mode import operations - All existing tests continue to pass Fixes issue where importing a mode would reformat the entire .roomodes file, changing user-preferred formatting and layout.
This commit is contained in:
parent
82a3212180
commit
c4b8d2e3ee
1 changed files with 29 additions and 3 deletions
|
|
@ -458,12 +458,38 @@ export class CustomModesManager {
|
||||||
|
|
||||||
private async updateModesInFile(filePath: string, operation: (modes: ModeConfig[]) => ModeConfig[]): Promise<void> {
|
private async updateModesInFile(filePath: string, operation: (modes: ModeConfig[]) => ModeConfig[]): Promise<void> {
|
||||||
let content = "{}"
|
let content = "{}"
|
||||||
|
let originalYamlOptions: yaml.ToStringOptions = { lineWidth: 0 }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
content = await fs.readFile(filePath, "utf-8")
|
content = await fs.readFile(filePath, "utf-8")
|
||||||
|
|
||||||
|
// Try to detect original YAML formatting style to preserve it
|
||||||
|
if (content.trim()) {
|
||||||
|
// Analyze the original content to preserve formatting style
|
||||||
|
const lines = content.split("\n")
|
||||||
|
let indentSize = 2 // default
|
||||||
|
let hasFlowStyle = false
|
||||||
|
|
||||||
|
// Detect indentation size from the first indented line
|
||||||
|
for (const line of lines) {
|
||||||
|
const match = line.match(/^(\s+)/)
|
||||||
|
if (match && match[1].length > 0) {
|
||||||
|
indentSize = match[1].length
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the file uses flow style (arrays with brackets)
|
||||||
|
hasFlowStyle = content.includes("[") && content.includes("]")
|
||||||
|
|
||||||
|
originalYamlOptions = {
|
||||||
|
lineWidth: 0, // Prevent line wrapping
|
||||||
|
indent: indentSize,
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// File might not exist yet.
|
// File might not exist yet.
|
||||||
content = yaml.stringify({ customModes: [] }, { lineWidth: 0 })
|
content = yaml.stringify({ customModes: [] }, originalYamlOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
let settings
|
let settings
|
||||||
|
|
@ -484,7 +510,7 @@ export class CustomModesManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.customModes = operation(settings.customModes)
|
settings.customModes = operation(settings.customModes)
|
||||||
await fs.writeFile(filePath, yaml.stringify(settings, { lineWidth: 0 }), "utf-8")
|
await fs.writeFile(filePath, yaml.stringify(settings, originalYamlOptions), "utf-8")
|
||||||
}
|
}
|
||||||
|
|
||||||
private async refreshMergedState(): Promise<void> {
|
private async refreshMergedState(): Promise<void> {
|
||||||
|
|
@ -786,7 +812,7 @@ export class CustomModesManager {
|
||||||
// This excludes the rules-{slug} folder from the path
|
// This excludes the rules-{slug} folder from the path
|
||||||
const relativePath = path.relative(modeRulesDir, filePath)
|
const relativePath = path.relative(modeRulesDir, filePath)
|
||||||
// Normalize path to use forward slashes for cross-platform compatibility
|
// Normalize path to use forward slashes for cross-platform compatibility
|
||||||
const normalizedRelativePath = relativePath.replace(/\\/g, '/')
|
const normalizedRelativePath = relativePath.replace(/\\/g, "/")
|
||||||
rulesFiles.push({ relativePath: normalizedRelativePath, content: content.trim() })
|
rulesFiles.push({ relativePath: normalizedRelativePath, content: content.trim() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue