Class: Aidp::PromptOptimization::TemplateIndexer
- Inherits:
-
Object
- Object
- Aidp::PromptOptimization::TemplateIndexer
- Defined in:
- lib/aidp/prompt_optimization/template_indexer.rb
Overview
Indexes step templates into retrievable fragments
Parses template markdown files from the templates/ directory and creates searchable fragments based on template category, content, and keywords.
Constant Summary collapse
- CATEGORIES =
Template categories based on directory structure
%w[analysis planning implementation].freeze
Instance Attribute Summary collapse
-
#project_dir ⇒ Object
readonly
Returns the value of attribute project_dir.
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
Instance Method Summary collapse
-
#all_tags ⇒ Array<String>
Get all unique tags from indexed templates.
-
#categories ⇒ Array<String>
Get all categories.
-
#find_by_id(id) ⇒ TemplateFragment?
Get template by ID.
-
#find_templates(category: nil, tags: nil, name: nil) ⇒ Array<TemplateFragment>
Find templates matching given criteria.
-
#index! ⇒ Array<TemplateFragment>
Index all template files.
-
#initialize(project_dir:) ⇒ TemplateIndexer
constructor
A new instance of TemplateIndexer.
Constructor Details
#initialize(project_dir:) ⇒ TemplateIndexer
Returns a new instance of TemplateIndexer.
21 22 23 24 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 21 def initialize(project_dir:) @project_dir = project_dir @templates = [] end |
Instance Attribute Details
#project_dir ⇒ Object (readonly)
Returns the value of attribute project_dir.
16 17 18 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 16 def project_dir @project_dir end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
16 17 18 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 16 def templates @templates end |
Instance Method Details
#all_tags ⇒ Array<String>
Get all unique tags from indexed templates
72 73 74 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 72 def @templates.flat_map(&:tags).uniq.sort end |
#categories ⇒ Array<String>
Get all categories
79 80 81 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 79 def categories @templates.map(&:category).uniq.sort end |
#find_by_id(id) ⇒ TemplateFragment?
Get template by ID
87 88 89 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 87 def find_by_id(id) @templates.find { |t| t.id == id } end |
#find_templates(category: nil, tags: nil, name: nil) ⇒ Array<TemplateFragment>
Find templates matching given criteria
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 50 def find_templates(category: nil, tags: nil, name: nil) results = @templates if category results = results.select { |t| t.category == category } end if && !.empty? results = results.select { |t| t.matches_any_tag?() } end if name pattern = Regexp.new(name, Regexp::IGNORECASE) results = results.select { |t| t.name =~ pattern } end results end |
#index! ⇒ Array<TemplateFragment>
Index all template files
Scans the templates/ directory and indexes all markdown templates
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/aidp/prompt_optimization/template_indexer.rb', line 31 def index! @templates = [] CATEGORIES.each do |category| category_dir = File.join(@project_dir, "templates", category) next unless Dir.exist?(category_dir) index_category(category, category_dir) end @templates end |