Class: Aidp::Skills::Router
- Inherits:
-
Object
- Object
- Aidp::Skills::Router
- Defined in:
- lib/aidp/skills/router.rb
Overview
Routes file paths and tasks to appropriate skills based on routing rules
The Router reads routing configuration from aidp.yml and matches:
-
File paths against glob patterns (path_rules)
-
Task descriptions against keywords (task_rules)
-
Combined path + task rules (combined_rules)
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#project_dir ⇒ Object
readonly
Returns the value of attribute project_dir.
Instance Method Summary collapse
-
#default_skill ⇒ String?
Get default skill.
-
#initialize(project_dir:) ⇒ Router
constructor
Initialize router with project directory.
-
#route(path: nil, task: nil) ⇒ String?
Route based on both path and task (highest priority).
-
#route_by_path(path) ⇒ String?
Route based on file path.
-
#route_by_task(task) ⇒ String?
Route based on task description.
-
#routing_enabled? ⇒ Boolean
Check if routing is enabled.
-
#rules ⇒ Hash
Get all routing rules.
Constructor Details
#initialize(project_dir:) ⇒ Router
Initialize router with project directory
34 35 36 37 |
# File 'lib/aidp/skills/router.rb', line 34 def initialize(project_dir:) @project_dir = project_dir @config = load_config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
29 30 31 |
# File 'lib/aidp/skills/router.rb', line 29 def config @config end |
#project_dir ⇒ Object (readonly)
Returns the value of attribute project_dir.
29 30 31 |
# File 'lib/aidp/skills/router.rb', line 29 def project_dir @project_dir end |
Instance Method Details
#default_skill ⇒ String?
Get default skill
112 113 114 |
# File 'lib/aidp/skills/router.rb', line 112 def default_skill config.dig("skills", "routing", "default") end |
#route(path: nil, task: nil) ⇒ String?
Route based on both path and task (highest priority)
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/aidp/skills/router.rb', line 44 def route(path: nil, task: nil) # Priority 1: Combined rules (path AND task) if path && task combined_match = match_combined_rules(path, task) return combined_match if combined_match end # Priority 2: Path rules path_match = route_by_path(path) if path return path_match if path_match # Priority 3: Task rules task_match = route_by_task(task) if task return task_match if task_match # Priority 4: Default skill config.dig("skills", "routing", "default") end |
#route_by_path(path) ⇒ String?
Route based on file path
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/aidp/skills/router.rb', line 67 def route_by_path(path) return nil unless path path_rules = config.dig("skills", "routing", "path_rules") || {} path_rules.each do |skill_id, patterns| patterns = [patterns] unless patterns.is_a?(Array) patterns.each do |pattern| return skill_id if File.fnmatch?(pattern, path, File::FNM_PATHNAME | File::FNM_EXTGLOB) end end nil end |
#route_by_task(task) ⇒ String?
Route based on task description
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/aidp/skills/router.rb', line 86 def route_by_task(task) return nil unless task task_rules = config.dig("skills", "routing", "task_rules") || {} task_lower = task.downcase task_rules.each do |skill_id, keywords| keywords = [keywords] unless keywords.is_a?(Array) keywords.each do |keyword| return skill_id if task_lower.include?(keyword.downcase) end end nil end |
#routing_enabled? ⇒ Boolean
Check if routing is enabled
105 106 107 |
# File 'lib/aidp/skills/router.rb', line 105 def routing_enabled? config.dig("skills", "routing", "enabled") == true end |
#rules ⇒ Hash
Get all routing rules
119 120 121 122 123 124 125 |
# File 'lib/aidp/skills/router.rb', line 119 def rules { path_rules: config.dig("skills", "routing", "path_rules") || {}, task_rules: config.dig("skills", "routing", "task_rules") || {}, combined_rules: config.dig("skills", "routing", "combined_rules") || {} } end |