Skip to content

Feature Proposal: Intelligent Semantic Rule Injection #6707

@insight-automate

Description

@insight-automate

What specific problem does this solve?

Problem

RooCode currently injects all applicable rules into every chat session via the system prompt, regardless of relevance. This creates significant issues:

  • Token waste: Irrelevant rules consume valuable context tokens
  • Context pollution: Unrelated rules can mislead LLM responses
  • Poor scalability: Rule overhead grows linearly with project complexity
  • Limited rule depth: Users avoid detailed rules due to constant overhead

While custom modes exist for task specialization, creating modes for every variant (Next.js App Router vs Pages Router vs Flask backend, etc.) leads to mode proliferation. Similarly, different parts of a codebase need different rules without warranting separate modes.

Current Behavior

From the documentation:

"The system prompt is generated dynamically each time you interact with Roo, adapting to your current mode, available tools, and custom settings."

All applicable rules are combined and injected into every system prompt, whether relevant or not.

Proposed Feature: Smart Rules

Introduce intelligent rule injection that automatically determines which rules are relevant to the current task and includes only those in the chat context.

User Experience

Setup

Users can create "smart rules" with explicit context triggers alongside existing rules:

.roo/smart-rules/supabase.md
---
use-when: "interacting with Supabase client, database queries, or authentication"
---

Supabase Best Practices

When working with Supabase:

  • Always use TypeScript for better type safety
  • Prefer RLS policies over client-side filtering
    ...
.roo/smart-rules/nextjs-app-router.md
---
use-when: "working with Next.js App Router, server components, or app directory structure"
---

# Next.js App Router Guidelines
For App Router development:
- Use server components by default
- Client components only when needed for interactivity
...

Rule Structure

Each smart rule includes:

  • Context trigger: Explicit description of when to use this rule
  • Rule content: The actual guidance/instructions
  • Optional metadata: Priority, dependencies, etc.

Automatic Selection

When users interact with RooCode, the system:

  • Analyzes the query against each rule's "use-when" criteria
  • Selects relevant smart rules based on context matching
  • Injects them alongside always-applied rules
  • Optionally shows which rules were activated

Example Scenarios

User Query Smart Rules Applied Trigger Match
"Set up Supabase auth in my Next.js app" supabase.md, nextjs-app-router.md "Supabase client/authentication" + "Next.js App Router"
"Write API documentation for this endpoint" documentation-style.md "API documentation"
"Debug this database query" supabase.md, database-patterns.md "database queries"

Key Requirements

  1. Explicit Context Definition: Users define when each rule should apply
  2. Intelligent Matching: System matches user queries to rule contexts
  3. Seamless Integration: Works alongside existing rule system without breaking changes
  4. User Control: Configurable sensitivity and rule limits
  5. Transparency: Optional visibility into which rules were selected and why
  6. Global Support: Works at both project and global levels
  7. Rich Content: Enables detailed rules with examples since they're only used when relevant

Benefits

  • Precise Context: User-defined triggers ensure rules apply exactly when intended
  • Efficient Tokens: Dramatically reduce irrelevant rule overhead
  • Detailed Guidance: Enable rich, "few-shot" example-heavy rules without excessive token cost
  • Clear Intent: Explicit "use-when" criteria make rule purpose transparent
  • Better Responses: Focused, relevant guidance without conflicting instructions
  • Scalable Management: Support extensive rule libraries with predictable activation
  • This feature would enable precise, contextually-intelligent rule management with user-controlled activation criteria, allowing rich guidance libraries while keeping conversations focused and efficient.

    Additional context (optional)

    No response

    Roo Code Task Links (Optional)

    No response

    Request checklist

    • I've searched existing Issues and Discussions for duplicates
    • This describes a specific problem with clear impact and context

    Interested in implementing this?

    • Yes, I'd like to help implement this feature

    Implementation requirements

    • I understand this needs approval before implementation begins

    How should this be solved? (REQUIRED if contributing, optional otherwise)

    No response

    How will we know it works? (Acceptance Criteria - REQUIRED if contributing, optional otherwise)

    No response

    Technical considerations (REQUIRED if contributing, optional otherwise)

    No response

    Trade-offs and risks (REQUIRED if contributing, optional otherwise)

    No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue - Needs ApprovalReady to move forward, but waiting on maintainer or team sign-off.enhancementNew feature or requestproposal

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions