Skip to content

Commit e217e73

Browse files
committed
feat: enhance custom modes handling by checking .roomodes file for mode existence and consolidating rules
1 parent 6f86638 commit e217e73

File tree

2 files changed

+403
-3
lines changed

2 files changed

+403
-3
lines changed

src/core/config/CustomModesManager.ts

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,40 @@ export class CustomModesManager {
420420
return false
421421
}
422422

423+
// Check if .roomodes file exists and contains this mode
424+
// This ensures we can only consolidate rules for modes that have been customized
425+
const roomodesPath = path.join(workspacePath, ROOMODES_FILENAME)
426+
try {
427+
const roomodesExists = await fileExistsAtPath(roomodesPath)
428+
if (roomodesExists) {
429+
const roomodesContent = await fs.readFile(roomodesPath, "utf-8")
430+
const roomodesData = yaml.parse(roomodesContent)
431+
const roomodesModes = roomodesData?.customModes || []
432+
433+
// Check if this specific mode exists in .roomodes
434+
const modeInRoomodes = roomodesModes.find((m: any) => m.slug === slug)
435+
if (!modeInRoomodes) {
436+
return false // Mode not customized in .roomodes, cannot consolidate
437+
}
438+
} else {
439+
// If no .roomodes file exists, check if it's in global custom modes
440+
const allModes = await this.getCustomModes()
441+
const mode = allModes.find((m) => m.slug === slug)
442+
443+
if (!mode) {
444+
return false // Not a custom mode, cannot consolidate
445+
}
446+
}
447+
} catch (error) {
448+
// If we can't read .roomodes, fall back to checking custom modes
449+
const allModes = await this.getCustomModes()
450+
const mode = allModes.find((m) => m.slug === slug)
451+
452+
if (!mode) {
453+
return false // Not a custom mode, cannot consolidate
454+
}
455+
}
456+
423457
// Check for .roo/rules-{slug}/ directory
424458
const modeRulesDir = path.join(workspacePath, ".roo", `rules-${slug}`)
425459

@@ -463,10 +497,34 @@ export class CustomModesManager {
463497
try {
464498
// Get all current modes
465499
const allModes = await this.getCustomModes()
466-
const mode = allModes.find((m) => m.slug === slug)
500+
let mode = allModes.find((m) => m.slug === slug)
467501

502+
// If mode not found in custom modes, check if it's a built-in mode that has been customized in .roomodes
468503
if (!mode) {
469-
return { success: false, error: "Mode not found" }
504+
const workspacePath = getWorkspacePath()
505+
if (!workspacePath) {
506+
return { success: false, error: "No workspace found" }
507+
}
508+
509+
const roomodesPath = path.join(workspacePath, ROOMODES_FILENAME)
510+
try {
511+
const roomodesExists = await fileExistsAtPath(roomodesPath)
512+
if (roomodesExists) {
513+
const roomodesContent = await fs.readFile(roomodesPath, "utf-8")
514+
const roomodesData = yaml.parse(roomodesContent)
515+
const roomodesModes = roomodesData?.customModes || []
516+
517+
// Find the mode in .roomodes
518+
mode = roomodesModes.find((m: any) => m.slug === slug)
519+
if (!mode) {
520+
return { success: false, error: "Mode not found in custom modes or .roomodes" }
521+
}
522+
} else {
523+
return { success: false, error: "Mode not found" }
524+
}
525+
} catch (error) {
526+
return { success: false, error: "Mode not found" }
527+
}
470528
}
471529

472530
// Get workspace path

0 commit comments

Comments
 (0)