Skip to content

Conversation

@upamune
Copy link
Contributor

@upamune upamune commented Apr 6, 2025

Context

This PR enhances the custom instructions system by adding support for directory-based rule loading and improving the file handling functionality. The main goal is to allow users to organize their rules in directories (.roo/rules/ and .roo/rules-${mode}/) while maintaining backward compatibility with existing file-based rules (.roorules and .clinerules).

Design Doc: https://hackmd.io/@upamune/roo-rule-directory

Implementation

The changes introduce several new functions and modify existing ones to support directory-based rule loading:

  • Added directoryExists function to safely check if a directory exists
  • Added readTextFilesFromDirectory function to read all text files from a directory recursively
  • Added formatDirectoryContent function to format content from multiple files with proper headers
  • Enhanced loadRuleFiles to first check for .roo/rules/ directory before falling back to single file rules
  • Modified addCustomInstructions to support .roo/rules-${mode}/ directory for mode-specific rules

The implementation follows a progressive enhancement approach:

  1. First tries to load rules from the new directory structure
  2. Falls back to the existing single-file approach if directory-based rules are not found
  3. Maintains consistent formatting of rule content regardless of the source

Key improvements:

  • Better organization of rules through directory structure
  • Support for multiple rule files in a single directory
  • Recursive file reading with proper error handling
  • Consistent formatting of rule content from different sources

How to Test

  1. Create a new .roo/rules/ directory and add some rule files
  2. Create a .roo/rules-${mode}/ directory (e.g., .roo/rules-dev/) and add mode-specific rule files
  3. Verify that rules are properly loaded from both directories
  4. Test fallback behavior by:
    • Removing the directories and using .roorules and .clinerules files
    • Using .roorules-${mode} and .clinerules-${mode} files for mode-specific rules
  5. Verify that the content formatting is consistent across all sources

Get in Touch

I'm available in the Roo Code Discord for any questions or discussions about these changes. (serizawa_ )


Important

Enhance rule file loading by supporting .roo/rules/ directories, updating UI, tests, and translations for directory-based rule management.

  • Behavior:
    • loadRuleFiles and addCustomInstructions now support loading rules from .roo/rules/ and .roo/rules-${mode}/ directories.
    • Falls back to .roorules and .clinerules if directories are not found.
    • Consistent formatting of rule content from directories and files.
  • Functions:
    • Added directoryExists, readTextFilesFromDirectory, and formatDirectoryContent in custom-instructions.ts.
  • UI:
    • Updated PromptsView.tsx to open rule files from new directory structure.
  • Tests:
    • Enhanced tests in custom-instructions.test.ts to cover new directory-based rule loading.
  • Translations:
    • Updated translation files to reflect new directory-based rule loading paths.

This description was created by Ellipsis for 381d526. It will automatically update as commits are pushed.

- Introduced functions to safely read files and check for directory existence.
- Added capability to read all text files from a specified directory in alphabetical order.
- Updated `loadRuleFiles` to prioritize loading rules from a `.roo/rules/` directory, falling back to existing rule files if necessary.
- Enhanced `addCustomInstructions` to support loading mode-specific rules from a `.roo/rules-{mode}/` directory, improving flexibility in rule management.

This change improves the organization and retrieval of rule files, allowing for better modularity and maintainability.
@changeset-bot
Copy link

changeset-bot bot commented Apr 6, 2025

⚠️ No Changeset found

Latest commit: 67dee67

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@upamune
Copy link
Contributor Author

upamune commented Apr 6, 2025

@mrubens I would like you to review the Pull Request to confirm if the direction is aligned 😄 I am intentionally leaving .roomodes as is. This Pull Request is targeting only .roo/rules.
If the implementation direction and pull request content are acceptable, I will modify the tests and update the documentation.

Copy link
Collaborator

@mrubens mrubens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems on the right track to me! Let's do it.

@mrubens
Copy link
Collaborator

mrubens commented Apr 6, 2025

I just pushed a small change to update the promptsview and associated strings, hopefully not stepping on toes!

@hannesrudolph hannesrudolph moved this from New to PR [Pre Approval Review] in Roo Code Roadmap Apr 6, 2025
@mrubens mrubens marked this pull request as ready for review April 7, 2025 13:35
@mrubens mrubens requested a review from cte as a code owner April 7, 2025 13:35
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. enhancement New feature or request labels Apr 7, 2025
/**
* Safely read a file and return its trimmed content
*/
async function safeReadFile(filePath: string): Promise<string> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is identical to the existing implementation. Consider importing and reusing the existing function instead.

@mrubens
Copy link
Collaborator

mrubens commented Apr 7, 2025

I'm not sure that the system prompt preview is loading the rules directories correctly

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 7, 2025
@mrubens mrubens merged commit 580672f into RooCodeInc:main Apr 7, 2025
12 checks passed
@github-project-automation github-project-automation bot moved this from PR [Pre Approval Review] to Done in Roo Code Roadmap Apr 7, 2025
snoyiatk added a commit to snoyiatk/Roo-Code that referenced this pull request Apr 7, 2025
- Implemented functionality in `custom-instruction.ts` to handle loading rules from custom instruction paths.
- Refactored and fixed previously incorrect logic in `custom-instruction.ts` for better reliability and maintainability. (comment in RooCodeInc#2354)
- Enhanced `system.ts` to pass custom instruction paths to `addCustomInstructions`.
- Extended `roo-code.d.ts` and `types.ts` to include `customInstructionsPaths` in `ModeConfig`.
- Modified `index.ts` schema to define `customInstructionsPathsConfigSchema` and integrate it into `ModeConfig`.
- Updated `modes.ts` to support `customInstructionsPaths` in mode configuration and full mode details.
SmartManoj pushed a commit to SmartManoj/Raa-Code that referenced this pull request May 6, 2025
* initial

* More error handling and git option

* Cleanup and tweaks

* one small change

* Update src/integrations/checkpoints/CheckpointUtils.ts

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

---------

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants