Class: Aidp::PromptOptimization::PromptBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/prompt_optimization/prompt_builder.rb

Overview

Builds the final PROMPT.md from selected fragments

Assembles an optimized prompt that includes:

  • Task description

  • Relevant style guide sections

  • Selected template fragments

  • Code context

  • Implementation guidance

Examples:

Basic usage

builder = PromptBuilder.new
prompt = builder.build(task_context, composition_result, options)

Instance Method Summary collapse

Instance Method Details

#build(task_context, composition_result, options = {}) ⇒ PromptOutput

Build prompt from composition result

Parameters:

  • task_context (TaskContext)

    Task context

  • composition_result (CompositionResult)

    Selected fragments

  • options (Hash) (defaults to: {})

    Build options

Options Hash (options):

  • :include_metadata (Boolean)

    Include selection metadata

  • :include_stats (Boolean)

    Include composition statistics

Returns:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/aidp/prompt_optimization/prompt_builder.rb', line 26

def build(task_context, composition_result, options = {})
  sections = []

  # Task section
  sections << build_task_section(task_context)

  # Group fragments by type
  style_guide_fragments = composition_result.fragments_by_type(:style_guide)
  template_fragments = composition_result.fragments_by_type(:template)
  code_fragments = composition_result.fragments_by_type(:code)

  # Add relevant sections if they have content
  sections << build_style_guide_section(style_guide_fragments) unless style_guide_fragments.empty?
  sections << build_template_section(template_fragments) unless template_fragments.empty?
  sections << build_code_section(code_fragments) unless code_fragments.empty?

  # Optional metadata
  if options[:include_metadata]
    sections << (composition_result)
  end

  content = sections.join("\n\n---\n\n")

  PromptOutput.new(
    content: content,
    composition_result: composition_result,
    task_context: task_context,
    metadata: (composition_result, options)
  )
end