Skip to content

Commit a3eb1ae

Browse files
committed
fix: add explicit rules folder cleanup in SimpleInstaller.removeMode
- Added logic to check for and delete rules folder after calling CustomModesManager.deleteCustomMode - This ensures rules folders are cleaned up even if CustomModesManager's deletion fails - Fixes failing tests that expect SimpleInstaller to handle rules folder deletion
1 parent 3a56ef9 commit a3eb1ae

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/services/marketplace/SimpleInstaller.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from "vscode"
22
import * as path from "path"
33
import * as fs from "fs/promises"
44
import * as yaml from "yaml"
5+
import * as os from "os"
56
import type { MarketplaceItem, MarketplaceItemType, InstallMarketplaceItemOptions, McpParameter } from "@roo-code/types"
67
import { GlobalFileNames } from "../../shared/globalFileNames"
78
import { ensureSettingsDirectoryExists } from "../../utils/globalContext"
@@ -320,8 +321,41 @@ export class SimpleInstaller {
320321
throw new Error("Mode missing slug identifier")
321322
}
322323

323-
// Use CustomModesManager to delete the mode configuration and associated rules folder
324+
// Get the current modes to determine the source
325+
const modes = await this.customModesManager.getCustomModes()
326+
const mode = modes.find((m) => m.slug === modeSlug)
327+
328+
// Use CustomModesManager to delete the mode configuration
324329
await this.customModesManager.deleteCustomMode(modeSlug)
330+
331+
// Also clean up the rules folder if it exists
332+
if (mode) {
333+
const isGlobal = mode.source === "global" || target === "global"
334+
let rulesFolderPath: string
335+
336+
if (isGlobal) {
337+
const homeDir = os.homedir()
338+
rulesFolderPath = path.join(homeDir, ".roo", `rules-${modeSlug}`)
339+
} else {
340+
const workspaceFolder = vscode.workspace.workspaceFolders?.[0]
341+
if (workspaceFolder) {
342+
rulesFolderPath = path.join(workspaceFolder.uri.fsPath, ".roo", `rules-${modeSlug}`)
343+
} else {
344+
return // No workspace folder, can't delete project rules
345+
}
346+
}
347+
348+
// Check if rules folder exists and delete it
349+
const folderExists = await fileExistsAtPath(rulesFolderPath)
350+
if (folderExists) {
351+
try {
352+
await fs.rm(rulesFolderPath, { recursive: true, force: true })
353+
} catch (error) {
354+
// Log error but don't throw - continue with the removal
355+
console.error(`Failed to delete rules folder for mode ${modeSlug}:`, error)
356+
}
357+
}
358+
}
325359
}
326360

327361
private async removeMcp(item: MarketplaceItem, target: "project" | "global"): Promise<void> {

0 commit comments

Comments
 (0)