Skip to content

[P2.1-T04] Implement priority-based rule sorting #41

@RichardHightower

Description

@RichardHightower

Task: Implement priority-based rule sorting

Phase: 2.1 - Core Governance
Estimated: 0.5 day
File: cch_cli/src/hooks/processor.rs
Depends on: P2.1-T03

Description

Sort rules by priority before matching, with higher numbers running first.

Acceptance Criteria

  • Create function sort_rules_by_priority(rules: &mut Vec<Rule>)
  • Sort by priority descending (higher first)
  • Stable sort to preserve file order for same priority
  • Default priority = 0 for rules without explicit priority
  • Call sorting before rule matching in hook processor
  • Add unit tests for sorting behavior

Code Reference

pub fn sort_rules_by_priority(rules: &mut [Rule]) {
    rules.sort_by(|a, b| {
        let priority_a = a.priority.unwrap_or(0);
        let priority_b = b.priority.unwrap_or(0);
        priority_b.cmp(&priority_a) // Descending order
    });
}

Tests Required

  • Higher priority rules run first
  • Same priority preserves file order (stable sort)
  • Default priority (0) sorts after explicit priorities

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions