Class: Aidp::PromptOptimization::StyleGuideIndexer
- Inherits:
-
Object
- Object
- Aidp::PromptOptimization::StyleGuideIndexer
- Defined in:
- lib/aidp/prompt_optimization/style_guide_indexer.rb
Overview
Indexes LLM_STYLE_GUIDE.md into retrievable fragments
Parses the style guide markdown and creates searchable fragments based on headings and sections. Each fragment can be independently included or excluded from prompts based on relevance.
Instance Attribute Summary collapse
-
#fragments ⇒ Object
readonly
Returns the value of attribute fragments.
-
#project_dir ⇒ Object
readonly
Returns the value of attribute project_dir.
Instance Method Summary collapse
-
#all_tags ⇒ Array<String>
Get all unique tags from indexed fragments.
-
#find_by_id(id) ⇒ Fragment?
Get fragment by ID.
-
#find_fragments(tags: nil, heading: nil, min_level: 1, max_level: 6) ⇒ Array<Fragment>
Find fragments matching given criteria.
-
#index! ⇒ Array<Fragment>
Index the style guide file.
-
#initialize(project_dir:) ⇒ StyleGuideIndexer
constructor
A new instance of StyleGuideIndexer.
Constructor Details
#initialize(project_dir:) ⇒ StyleGuideIndexer
Returns a new instance of StyleGuideIndexer.
18 19 20 21 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 18 def initialize(project_dir:) @project_dir = project_dir @fragments = [] end |
Instance Attribute Details
#fragments ⇒ Object (readonly)
Returns the value of attribute fragments.
16 17 18 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 16 def fragments @fragments end |
#project_dir ⇒ Object (readonly)
Returns the value of attribute project_dir.
16 17 18 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 16 def project_dir @project_dir end |
Instance Method Details
#all_tags ⇒ Array<String>
Get all unique tags from indexed fragments
64 65 66 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 64 def @fragments.flat_map(&:tags).uniq.sort end |
#find_by_id(id) ⇒ Fragment?
Get fragment by ID
72 73 74 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 72 def find_by_id(id) @fragments.find { |f| f.id == id } end |
#find_fragments(tags: nil, heading: nil, min_level: 1, max_level: 6) ⇒ Array<Fragment>
Find fragments matching given criteria
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 46 def find_fragments(tags: nil, heading: nil, min_level: 1, max_level: 6) results = @fragments if && !.empty? results = results.select { |f| f.matches_any_tag?() } end if heading pattern = Regexp.new(heading, Regexp::IGNORECASE) results = results.select { |f| f.heading =~ pattern } end results.select { |f| f.level.between?(min_level, max_level) } end |
#index! ⇒ Array<Fragment>
Index the style guide file
Parses the LLM_STYLE_GUIDE.md and extracts fragments organized by sections and headings
29 30 31 32 33 34 35 36 37 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 29 def index! @fragments = [] content = read_style_guide return @fragments if content.nil? || content.empty? parse_fragments(content) @fragments end |