Class: Ace::Review::Models::ReviewOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/review/models/review_options.rb

Overview

Options for code review execution

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ ReviewOptions

Returns a new instance of ReviewOptions.



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
48
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
76
# File 'lib/ace/review/models/review_options.rb', line 19

def initialize(hash = {})
  # Core options
  @preset = hash[:preset] || Ace::Review.get("defaults", "preset")
  @output_dir = hash[:output_dir]
  @output = hash[:output]

  # Context and subject
  @context = hash[:context]
  @subject = hash[:subject]

  # Prompt composition overrides
  @prompt_base = hash[:prompt_base]
  @prompt_format = hash[:prompt_format]
  @prompt_focus = hash[:prompt_focus]
  @add_focus = hash[:add_focus]
  @prompt_guidelines = hash[:prompt_guidelines]

  # Execution options
  @model = hash[:model]
  @models = hash[:models]
  @dry_run = hash[:dry_run] || false
  @verbose = hash[:verbose] || false
  @auto_execute = if @dry_run
    false
  elsif hash[:auto_execute].nil?
    Ace::Review.get("defaults", "auto_execute") || false
  else
    hash[:auto_execute]
  end

  # Session options
  @save_session = hash.fetch(:save_session, true)
  @session_dir = hash[:session_dir]

  # PR review options
  @pr = hash[:pr]
  @post_comment = hash[:post_comment] || false
   = hash[:pr_metadata]
  @gh_timeout = hash[:gh_timeout]

  # PR comment options
  @pr_comments = hash[:pr_comments]  # nil = use default, true/false = explicit
  @pr_comment_data = nil  # Populated during execution
  @evidence_sessions = Array(hash[:evidence_session]).flat_map { |value| value.to_s.split("\x1F") }.reject(&:empty?)

  # Delta round: nil = not requested, :auto = resolve reference from prior
  # sessions, otherwise the explicit reference head
  @delta = hash[:delta]

  # Feedback extraction options
  @no_feedback = hash[:no_feedback] || false
  @feedback_model = hash[:feedback_model]

  # List commands
  @list_presets = hash[:list_presets] || false
  @list_prompts = hash[:list_prompts] || false
  @help = hash[:help] || false
end

Instance Attribute Details

#add_focus ⇒ Object

Returns the value of attribute add_focus.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def add_focus
  @add_focus
end

#auto_execute ⇒ Object

Returns the value of attribute auto_execute.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def auto_execute
  @auto_execute
end

#context ⇒ Object

Returns the value of attribute context.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def context
  @context
end

#delta ⇒ Object

Returns the value of attribute delta.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def delta
  @delta
end

#dry_run ⇒ Object

Returns the value of attribute dry_run.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def dry_run
  @dry_run
end

#evidence_sessions ⇒ Object

Returns the value of attribute evidence_sessions.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def evidence_sessions
  @evidence_sessions
end

#feedback_model ⇒ Object

Returns the value of attribute feedback_model.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def feedback_model
  @feedback_model
end

#gh_timeout ⇒ Object

Returns the value of attribute gh_timeout.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def gh_timeout
  @gh_timeout
end

#help ⇒ Object

Returns the value of attribute help.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def help
  @help
end

#list_presets ⇒ Object

Returns the value of attribute list_presets.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def list_presets
  @list_presets
end

#list_prompts ⇒ Object

Returns the value of attribute list_prompts.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def list_prompts
  @list_prompts
end

#model ⇒ Object

Returns the value of attribute model.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def model
  @model
end

#models ⇒ Object

Returns the value of attribute models.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def models
  @models
end

#no_feedback ⇒ Object

Returns the value of attribute no_feedback.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def no_feedback
  @no_feedback
end

#output ⇒ Object

Returns the value of attribute output.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def output
  @output
end

#output_dir ⇒ Object

Returns the value of attribute output_dir.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def output_dir
  @output_dir
end

#post_comment ⇒ Object

Returns the value of attribute post_comment.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def post_comment
  @post_comment
end

#pr ⇒ Object

Returns the value of attribute pr.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def pr
  @pr
end

#pr_comment_data ⇒ Object

Returns the value of attribute pr_comment_data.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def pr_comment_data
  @pr_comment_data
end

#pr_comments ⇒ Object

Returns the value of attribute pr_comments.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def pr_comments
  @pr_comments
end

#pr_metadata ⇒ Object

Returns the value of attribute pr_metadata.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def 
  
end

#preset ⇒ Object

Returns the value of attribute preset.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def preset
  @preset
end

#prompt_base ⇒ Object

Returns the value of attribute prompt_base.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def prompt_base
  @prompt_base
end

#prompt_focus ⇒ Object

Returns the value of attribute prompt_focus.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def prompt_focus
  @prompt_focus
end

#prompt_format ⇒ Object

Returns the value of attribute prompt_format.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def prompt_format
  @prompt_format
end

#prompt_guidelines ⇒ Object

Returns the value of attribute prompt_guidelines.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def prompt_guidelines
  @prompt_guidelines
end

#save_session ⇒ Object

Returns the value of attribute save_session.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def save_session
  @save_session
end

#session_dir ⇒ Object

Returns the value of attribute session_dir.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def session_dir
  @session_dir
end

#subject ⇒ Object

Returns the value of attribute subject.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def subject
  @subject
end

#verbose ⇒ Object

Returns the value of attribute verbose.



8
9
10
# File 'lib/ace/review/models/review_options.rb', line 8

def verbose
  @verbose
end

Instance Method Details

#delta_requested? ⇒ Boolean

Check if a delta round was requested (--delta, with or without a head)

Returns:

  • (Boolean)


98
99
100
# File 'lib/ace/review/models/review_options.rb', line 98

def delta_requested?
  !delta.nil?
end

#effective_model(config_model = nil) ⇒ Object

Get effective model (single model) Priority: model scalar > first model in models array > config_model > default



132
133
134
135
136
# File 'lib/ace/review/models/review_options.rb', line 132

def effective_model(config_model = nil)
  return model if model
  return models.first if models&.any?
  config_model || "google:gemini-2.5-flash"
end

#effective_models(config_models = nil) ⇒ Object

Get effective models array Returns array of models, handling both single model and multi-model cases Priority: models array > model scalar > config_models > default



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/ace/review/models/review_options.rb', line 141

def effective_models(config_models = nil)
  # If models array is set (from CLI), use it
  return models if models&.any?

  # If model scalar is set, wrap in array
  return [model] if model

  # If config provides models array, use it
  if config_models.is_a?(Array) && config_models.any?
    return config_models
  end

  # If config provides single model, wrap in array
  if config_models.is_a?(String) && !config_models.empty?
    return [config_models]
  end

  # Default to single model
  ["google:gemini-2.5-flash"]
end

#feedback_enabled? ⇒ Boolean

Check if feedback extraction is enabled

Returns:

  • (Boolean)


126
127
128
# File 'lib/ace/review/models/review_options.rb', line 126

def feedback_enabled?
  !@no_feedback
end

#include_pr_comments? ⇒ Boolean

Check if PR comments should be included as feedback source Enabled by default for PR reviews, can be disabled with --no-pr-comments

Returns:

  • (Boolean)


109
110
111
112
113
114
115
116
117
118
# File 'lib/ace/review/models/review_options.rb', line 109

def include_pr_comments?
  return false unless pr_review?

  # Explicit flag overrides everything
  return pr_comments unless pr_comments.nil?

  # Check config default (defaults to true for PR reviews)
  config_default = Ace::Review.get("defaults", "pr_comments")
  config_default.nil? || config_default
end

#list_command? ⇒ Boolean

Check if this is a list command

Returns:

  • (Boolean)


88
89
90
# File 'lib/ace/review/models/review_options.rb', line 88

def list_command?
  list_presets || list_prompts || help
end

#merge_config(config) ⇒ Object

Merge with config values



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/ace/review/models/review_options.rb', line 163

def merge_config(config)
  return if config.nil?

  # Merge system prompt configuration if not overridden
  @prompt_base ||= config.dig("system_prompt", "base")
  @prompt_format ||= config.dig("system_prompt", "format")

  # Handle focus modules
  if @add_focus && config.dig("system_prompt", "focus")
    existing_focus = config.dig("system_prompt", "focus") || []
    additional_focus = @add_focus.split(",").map(&:strip)
    @prompt_focus = (existing_focus + additional_focus).uniq.join(",")
  elsif !@prompt_focus && config.dig("system_prompt", "focus")
    @prompt_focus = Array(config.dig("system_prompt", "focus")).join(",")
  end

  @prompt_guidelines ||= Array(config.dig("system_prompt", "guidelines")).join(",") if config.dig("system_prompt", "guidelines")

  # Merge other config values
  @context ||= config["context"]
  @subject ||= config["subject"]

  # Handle models from config
  # CLI models override preset models
  unless @models&.any?
    if config["models"].is_a?(Array) && config["models"].any?
      @models = config["models"]
    elsif config["model"]
      @model ||= config["model"]
    end
  end

  @gh_timeout ||= config["gh_timeout"]

  self
end

#pr_review? ⇒ Boolean

Check if this is a PR review

Returns:

  • (Boolean)


93
94
95
# File 'lib/ace/review/models/review_options.rb', line 93

def pr_review?
  !pr.nil? && !pr.to_s.strip.empty?
end

#save_output? ⇒ Boolean

Check if output should be saved

Returns:

  • (Boolean)


121
122
123
# File 'lib/ace/review/models/review_options.rb', line 121

def save_output?
  !dry_run && save_session
end

#should_post_comment? ⇒ Boolean

Check if comment posting should be triggered (includes dry-run preview)

Returns:

  • (Boolean)


103
104
105
# File 'lib/ace/review/models/review_options.rb', line 103

def should_post_comment?
  pr_review? && post_comment
end

#system_prompt_composition ⇒ Object

Build system prompt composition hash



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/ace/review/models/review_options.rb', line 201

def system_prompt_composition
  composition = {}

  composition["base"] = prompt_base if prompt_base
  composition["format"] = prompt_format if prompt_format

  if prompt_focus
    composition["focus"] = prompt_focus.split(",").map(&:strip)
  end

  if prompt_guidelines
    composition["guidelines"] = prompt_guidelines.split(",").map(&:strip)
  end

  composition.empty? ? nil : composition
end

#to_h ⇒ Object

Convert back to hash for compatibility



79
80
81
82
83
84
85
# File 'lib/ace/review/models/review_options.rb', line 79

def to_h
  instance_variables.each_with_object({}) do |var, hash|
    key = var.to_s.delete_prefix("@").to_sym
    value = instance_variable_get(var)
    hash[key] = value unless value.nil?
  end
end