Skip to content

Conversation

@KJ7LNW
Copy link
Contributor

@KJ7LNW KJ7LNW commented Jun 5, 2025

Context

Currently, Roo only loads custom rules from the immediate working directory, which creates several limitations:

  1. Redundancy and Maintenance Burden: Users must duplicate common rules across multiple project directories.
  2. Context Fragmentation: When working in subdirectories, the AI loses access to project-level rules.
  3. Feature Branch Isolation: When developing multiple features for the same project in different directories, each needs its own complete set of rules.

This PR implements hierarchical loading of custom rules by traversing from the current working directory up to the root directory, collecting and merging rules at each level. This enables:

  • Organization-wide rules at organization repository roots
  • Project-wide rules at project roots
  • Feature-specific rules in feature directories

Implementation

Added a new addSingleCustomInstructions function to handle loading rules from a single directory level and modified addCustomInstructions to traverse from the current directory up to the root. Rules from parent directories are loaded first (starting from root).

How to Test

  • Create a .roo/rules/ directory in a parent directory of your project
  • Add some rule files to it
  • Create a .roo/rules/ directory in your project directory with different rules
  • Verify that both sets of rules are loaded

Get in Touch

Discord: KJ7LNW

Fixes #4364


Important

This PR adds hierarchical rule loading from parent directories with a configurable depth, enhancing rule management across project levels.

  • Behavior:
    • Implements hierarchical rule loading by traversing parent directories up to a configurable depth (parentRulesMaxDepth).
    • Rules from parent directories are loaded first, starting from the root.
  • Configuration:
    • Adds parentRulesMaxDepth to global-settings.ts to control directory traversal depth.
    • UI component added in ModesView.tsx for setting parentRulesMaxDepth.
  • Core Logic:
    • Modifies getRooDirectoriesForCwd() in index.ts to support parent directory traversal.
    • Uses a Set to avoid duplicate directories and ensures proper sorting.
  • Testing:
    • Updates tests in index.spec.ts to cover new traversal logic and configuration.
  • Localization:
    • Updates multiple localization files to include strings for parentRulesMaxDepth setting.

This description was created by Ellipsis for 43d0bb0. You can customize this summary. It will automatically update as commits are pushed.

@KJ7LNW KJ7LNW requested review from cte and mrubens as code owners June 5, 2025 06:11
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Jun 5, 2025
@KJ7LNW KJ7LNW self-assigned this Jun 5, 2025
@KJ7LNW KJ7LNW moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jun 5, 2025
@KJ7LNW
Copy link
Contributor Author

KJ7LNW commented Jun 5, 2025

Cc: @swiftugandan, @yisrael-rosen, @MusiCode1 because they heart-emojii'ed this feature in Cline last year, but it was never merged.

@KJ7LNW KJ7LNW force-pushed the hierarchical-rule-loading branch from f8767b6 to 61a173a Compare June 7, 2025 01:57
@KJ7LNW KJ7LNW requested a review from jr as a code owner June 7, 2025 01:57
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jun 7, 2025
@KJ7LNW
Copy link
Contributor Author

KJ7LNW commented Jun 7, 2025

This is ready for review.

Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

Hey @KJ7LNW, Thanks for your contribution! The implementation looks clean and the feature addresses a real pain point.

However I would like to know what you think about allowing users to disable this behavior, specially since for some users it might be quite unexpected or undesirable (it can potentially add a lot of tokens to each request without the user knowing).

Also the implementation could really benefit from some unit tests.

Let me know what you think!

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jun 7, 2025
@KJ7LNW KJ7LNW force-pushed the hierarchical-rule-loading branch from 61a173a to 368c1d3 Compare June 16, 2025 03:35
@KJ7LNW
Copy link
Contributor Author

KJ7LNW commented Jun 16, 2025

The setting has been added on the "Modes" page:

image

and console.info provides debug if necessary:

[Roo Rules] Detected .roo/rules-code directory: /home/ewheeler/src/roo/Roo3/.roo/rules-code
[Roo Rules] Detected .roo/rules directory: /home/ewheeler/src/roo/Roo3/.roo/rules
[Roo Rules] Detected .roo/rules directory: /home/ewheeler/src/roo/.roo/rules
[Roo Rules] Detected .roo/rules-code directory: /home/ewheeler/.roo/rules-code
[Roo Rules] Detected .roo/rules directory: /home/ewheeler/.roo/rules

@KJ7LNW KJ7LNW moved this from PR [Changes Requested] to PR [Needs Prelim Review] in Roo Code Roadmap Jun 16, 2025
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jun 16, 2025
@daniel-lxs
Copy link
Member

Hey @KJ7LNW, it seems like the failing test is genuine. Can you take a look?

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jun 16, 2025
@daniel-lxs daniel-lxs force-pushed the hierarchical-rule-loading branch from 174f320 to 3886e16 Compare June 21, 2025 12:46
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Jun 21, 2025
@daniel-lxs daniel-lxs force-pushed the hierarchical-rule-loading branch from 3886e16 to d97ac5d Compare June 21, 2025 12:49
daniel-lxs
daniel-lxs previously approved these changes Jun 21, 2025
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

Not really sure how this PR is consistently triggering this test and causing it to fail.

I'll approve the changes but it would be great if @cte could take a quick look, maybe I'm missing something here.

@daniel-lxs daniel-lxs moved this from PR [Needs Review] to PR [Needs Prelim Review] in Roo Code Roadmap Jun 27, 2025
@daniel-lxs
Copy link
Member

Hey @KJ7LNW, I looked into the test failure and tried to sort it out.

The issue seems to come from the webview build trying to bundle Node.js-only modules like fs, path, and os, which obviously don't work in the browser. This happens because getFullModeDetails in src/shared/modes.ts was calling addCustomInstructions, which pulls in those modules.

Since src/shared/modes.ts is also used by the webview, Vite tries to include those Node modules in the browser bundle, which causes the build to fail.

I tried moving the call to addCustomInstructions into the extension side (src/core/environment/getEnvironmentDetails.ts) so it runs in Node, and passed the result into getFullModeDetails as a string.

While the tests are passing now, I still couldn’t get the actual behavior to work correctly again. Something's still off, and custom instructions aren't loading the way they should.

Please take a look when you get a chance and let me know what you find. Happy to pair on it if needed.

@daniel-lxs daniel-lxs marked this pull request as draft June 28, 2025 16:07
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Draft / In Progress] in Roo Code Roadmap Jun 28, 2025
@daniel-lxs daniel-lxs dismissed their stale review June 28, 2025 16:09

The unit tests need fixing

@KJ7LNW
Copy link
Contributor Author

KJ7LNW commented Jun 30, 2025

@daniel-lxs - I was able to reproduce it locally by running a build:

The problem was caused by d97ac5d04a27897b7259c0e78d1f1d23e2aad79d - for some reason it does not like await import("../../../core/config/ContextProxy") but require("../../../core/config/ContextProxy") works fine.

I am going to rework this pull request so leave it as in progress for now.

Eric Wheeler added 2 commits June 29, 2025 20:59
This commit implements the parentRulesMaxDepth setting which controls how many parent directories are searched for .roo/rules files. The setting is accessible from the Modes view and persists across sessions.

Key changes:
- Added parentRulesMaxDepth to the global settings schema
- Added UI component in ModesView.tsx with improved styling
- Updated state management to properly persist the setting

Signed-off-by: Eric Wheeler <[email protected]>
@KJ7LNW KJ7LNW force-pushed the hierarchical-rule-loading branch from bda6ab9 to 58ac018 Compare June 30, 2025 04:12
Add comprehensive test coverage for the parentRulesMaxDepth feature:
- Mock ContextProxy for consistent test behavior
- Test default depth behavior
- Test error handling when ContextProxy is unavailable
- Test traversing parent directories based on maxDepth
- Test stopping at root directory
- Test safety break handling
- Add consistent os.homedir mock for custom-instructions tests

Signed-off-by: Eric Wheeler <[email protected]>
@KJ7LNW KJ7LNW force-pushed the hierarchical-rule-loading branch from 58ac018 to f5e39d1 Compare June 30, 2025 04:27
Added translations for the parentRulesMaxDepth setting to all language files.
This setting controls how many directory levels up to search for .roo/rules files,
enabling hierarchical rule loading from parent directories.

Signed-off-by: Eric Wheeler <[email protected]>
@KJ7LNW
Copy link
Contributor Author

KJ7LNW commented Jun 30, 2025

@daniel-lxs this is fixed up and ready to review

@KJ7LNW KJ7LNW marked this pull request as ready for review June 30, 2025 04:30
@KJ7LNW KJ7LNW moved this from PR [Draft / In Progress] to PR [Needs Prelim Review] in Roo Code Roadmap Jun 30, 2025
@hannesrudolph
Copy link
Collaborator

@KJ7LNW Thanks for your work on this PR. However, we're closing it for now, as the solution introduces complexity that seems disproportionate to the relatively niche problem described in the linked issue. At this stage, we don't have sufficient evidence indicating this impacts enough users to justify the additional complexity and maintenance overhead. If further data emerges showing broader user impact, please feel free to reopen or revisit this approach.

@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Jun 30, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jun 30, 2025
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 PR - Needs Preliminary Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Rules cannot be shared across directories or inherited from parent directories

3 participants