Module: Legion::Extensions::Developer::Helpers::PromptBuilder

Extended by:
PromptBuilder
Included in:
PromptBuilder
Defined in:
lib/legion/extensions/developer/helpers/prompt_builder.rb

Instance Method Summary collapse

Instance Method Details

#build_feedback_prompt(work_item:, context: nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/legion/extensions/developer/helpers/prompt_builder.rb', line 49

def build_feedback_prompt(work_item:, context: nil)
  feedback = work_item.dig(:pipeline, :feedback_history) || []
  attempt = work_item.dig(:pipeline, :attempt) || 0

  <<~PROMPT
    You are a senior software developer revising a code change based on review feedback.

    ## Task
    Title: #{work_item[:title]}
    Description: #{work_item[:description]}

    ## Current Attempt
    This is attempt #{attempt} (previous attempts were rejected).

    ## Review Feedback
    #{format_feedback(feedback)}

    ## Plan
    #{format_plan(work_item.dig(:pipeline, :plan))}

    #{format_context(context)}

    ## Instructions
    Address ALL feedback issues listed above. Output complete file contents using the
    `# file: path/to/file` format inside fenced code blocks.
  PROMPT
end

#build_implementation_prompt(work_item:, context: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/legion/extensions/developer/helpers/prompt_builder.rb', line 10

def build_implementation_prompt(work_item:, context: nil)
  plan = work_item.dig(:pipeline, :plan) || {}
  repo = work_item[:repo] || {}

  <<~PROMPT
    You are a senior software developer implementing a code change.

    ## Task
    Title: #{work_item[:title]}
    Description: #{work_item[:description]}
    Repository: #{repo[:owner]}/#{repo[:name]}
    Language: #{repo[:language] || 'unknown'}

    ## Plan
    Approach: #{plan[:approach]}
    Test strategy: #{plan[:test_strategy]}

    ## Files to Modify
    #{format_files_to_modify(plan[:files_to_modify] || [])}

    #{format_context(context)}

    ## Instructions
    Implement the changes described above. For each file you modify or create,
    output the complete file content in a fenced code block with a `# file: path/to/file`
    comment as the first line inside the block.

    Example format:
    ```ruby
    # file: lib/example.rb
    # frozen_string_literal: true

    class Example
      # implementation here
    end
    ```
  PROMPT
end

#thinking_budget(attempt:) ⇒ Object



77
78
79
80
# File 'lib/legion/extensions/developer/helpers/prompt_builder.rb', line 77

def thinking_budget(attempt:)
  budget = base_thinking_budget * (2**attempt)
  [budget, max_thinking_budget].min
end