Skip to content

Rule-Based Engine: 3-Tier YAML Rule System #18

@ashu17706

Description

@ashu17706

Overview

Implement a flexible 3-tier rule system for message classification, replacing hardcoded regex patterns with YAML-based rules that support language-specific and project-specific customization.

Status

✅ Phase 1: MVP (COMPLETE)

  • Language detection (TypeScript, Python, Rust, Go, JavaScript)
  • Framework detection (Next.js, FastAPI, Axum, Django, Actix)
  • YAML rule loader with 3-tier merge logic
  • Migrated 26 hardcoded rules to general.yml
  • Pattern compilation and caching
  • GitHub rule fetching with database cache
  • Comprehensive test coverage (27 tests passing)
  • Database schema extensions
  • Backward compatibility maintained

Commit: f15c532 - "Implement Phase 1: 3-Tier Rule-Based Engine (MVP Complete)"

📋 Phase 1.5: Language-Specific Rules (Next)

  • Create TypeScript-specific rule set
  • Create JavaScript-specific rule set
  • Create Python-specific rule set
  • Create Rust-specific rule set
  • Create Go-specific rule set
  • Implement smriti init command with auto-detection
  • Implement smriti rules add command
  • Implement smriti rules validate command
  • Implement smriti rules list command

📋 Phase 2: Auto-Update & Versioning

  • Implement smriti rules update command
  • Auto-check for rule updates on categorize
  • Add --no-update flag
  • Display changelog before update
  • Version tracking in database

📋 Phase 4+: Community

  • GitHub community rule repository
  • Community-contributed rule sets
  • Plugin marketplace integration

Architecture

3-Tier Rule System

Tier 3 (Runtime Override) ← CLI flags, programmatic
    ↓ (highest precedence)
Tier 2 (Project Custom) ← .smriti/rules/custom.yml
    ↓ (overrides base)
Tier 1 (Base) ← general.yml (GitHub or local)
    (lowest precedence)

Key Files

  • src/detect/language.ts - Language/framework detection
  • src/categorize/rules/loader.ts - YAML loader + 3-tier merge
  • src/categorize/rules/github.ts - GitHub fetcher + cache
  • src/categorize/rules/general.yml - 26 general rules
  • PHASE1_IMPLEMENTATION.md - Technical documentation
  • RULES_QUICK_REFERENCE.md - Developer guide

Test Results (Phase 1)

  • ✅ 27/27 new tests passing
  • ✅ 63 assertions verified
  • ✅ All existing categorization tests still working

Performance (Phase 1)

  • Language Detection: 20-50ms
  • Rule Loading: 50-100ms (cached)
  • Classification: 2-5ms per message

Related Issues

  • None yet

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestphase-2Phase 2: New agent parsers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions