Class: Aidp::Analyze::Runner

Inherits:
Object
  • Object
show all
Includes:
DebugMixin
Defined in:
lib/aidp/analyze/runner.rb

Constant Summary

Constants included from DebugMixin

DebugMixin::DEBUG_BASIC, DebugMixin::DEBUG_OFF, DebugMixin::DEBUG_VERBOSE

Instance Method Summary collapse

Methods included from DebugMixin

#debug_basic?, #debug_command, #debug_enabled?, #debug_error, #debug_execute_command, #debug_level, #debug_log, #debug_logger, #debug_provider, #debug_step, #debug_timing, #debug_verbose?, included, shared_logger

Constructor Details

#initialize(project_dir, harness_runner = nil) ⇒ Runner

Returns a new instance of Runner.



13
14
15
16
17
18
# File 'lib/aidp/analyze/runner.rb', line 13

def initialize(project_dir, harness_runner = nil)
  @project_dir = project_dir
  @harness_runner = harness_runner
  @is_harness_mode = !harness_runner.nil?
  @file_manager = Aidp::Storage::FileManager.new(File.join(project_dir, ".aidp"))
end

Instance Method Details

#all_stepsObject

Harness integration methods



93
94
95
# File 'lib/aidp/analyze/runner.rb', line 93

def all_steps
  Aidp::Analyze::Steps::SPEC.keys
end

#all_steps_completed?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/aidp/analyze/runner.rb', line 101

def all_steps_completed?
  all_steps.all? { |step| progress.step_completed?(step) }
end

#get_step_description(step_name) ⇒ Object



121
122
123
124
# File 'lib/aidp/analyze/runner.rb', line 121

def get_step_description(step_name)
  spec = get_step_spec(step_name)
  spec ? spec["description"] : nil
end

#get_step_outputs(step_name) ⇒ Object



131
132
133
134
# File 'lib/aidp/analyze/runner.rb', line 131

def get_step_outputs(step_name)
  spec = get_step_spec(step_name)
  spec ? spec["outs"] : []
end

#get_step_spec(step_name) ⇒ Object



117
118
119
# File 'lib/aidp/analyze/runner.rb', line 117

def get_step_spec(step_name)
  Aidp::Analyze::Steps::SPEC[step_name]
end

#get_step_templates(step_name) ⇒ Object



136
137
138
139
# File 'lib/aidp/analyze/runner.rb', line 136

def get_step_templates(step_name)
  spec = get_step_spec(step_name)
  spec ? spec["templates"] : []
end

#harness_statusObject

Harness-aware status information



142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/aidp/analyze/runner.rb', line 142

def harness_status
  {
    mode: :analyze,
    total_steps: all_steps.size,
    completed_steps: progress.completed_steps.size,
    current_step: progress.current_step,
    next_step: next_step,
    all_completed: all_steps_completed?,
    started_at: progress.started_at,
    progress_percentage: all_steps_completed? ? 100.0 : (progress.completed_steps.size.to_f / all_steps.size * 100).round(2)
  }
end

#is_gate_step?(step_name) ⇒ Boolean

Returns:

  • (Boolean)


126
127
128
129
# File 'lib/aidp/analyze/runner.rb', line 126

def is_gate_step?(step_name)
  spec = get_step_spec(step_name)
  spec ? spec["gate"] : false
end

#mark_step_completed(step_name) ⇒ Object



109
110
111
# File 'lib/aidp/analyze/runner.rb', line 109

def mark_step_completed(step_name)
  progress.mark_step_completed(step_name)
end

#mark_step_in_progress(step_name) ⇒ Object



113
114
115
# File 'lib/aidp/analyze/runner.rb', line 113

def mark_step_in_progress(step_name)
  progress.mark_step_in_progress(step_name)
end

#next_stepObject



97
98
99
# File 'lib/aidp/analyze/runner.rb', line 97

def next_step
  all_steps.find { |step| !progress.step_completed?(step) }
end

#progressObject



20
21
22
# File 'lib/aidp/analyze/runner.rb', line 20

def progress
  @progress ||= Aidp::Analyze::Progress.new(@project_dir)
end

#run_step(step_name, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/aidp/analyze/runner.rb', line 24

def run_step(step_name, options = {})
  # Always validate step exists first
  step_spec = Aidp::Analyze::Steps::SPEC[step_name]
  raise "Step '#{step_name}' not found" unless step_spec

  debug_step(step_name, "Starting execution", {
    harness_mode: @is_harness_mode,
    options: options.keys
  })

  # In harness mode, use the harness's provider management
  if @is_harness_mode
    run_step_with_harness(step_name, options)
  else
    run_step_standalone(step_name, options)
  end
end

#run_step_standalone(step_name, options = {}) ⇒ Object

Standalone step execution (simplified - synchronous)



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/aidp/analyze/runner.rb', line 74

def run_step_standalone(step_name, options = {})
  puts "🚀 Running step synchronously: #{step_name}"

  start_time = Time.now
  prompt = composed_prompt(step_name, options)

  # Execute step synchronously with a simple provider
  result = execute_step_synchronously(step_name, prompt, options)

  duration = Time.now - start_time

  # Store execution metrics
  @file_manager.record_step_execution(step_name, "cursor", duration, result[:status] == "completed")

  puts "✅ Step completed in #{duration.round(2)}s"
  result
end

#run_step_with_harness(step_name, options = {}) ⇒ Object

Harness-aware step execution



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
# File 'lib/aidp/analyze/runner.rb', line 43

def run_step_with_harness(step_name, options = {})
  # Get current provider from harness
  current_provider = @harness_runner.instance_variable_get(:@current_provider)
  provider_type = current_provider || "cursor"

  debug_step(step_name, "Harness execution", {
    provider: provider_type,
    project_dir: @project_dir
  })

  # Compose prompt with harness context
  prompt = composed_prompt_with_harness_context(step_name, options)

  debug_log("📝 Composed prompt for #{step_name}", level: :info, data: {
    prompt_length: prompt.length,
    provider: provider_type
  })

  # Execute with harness error handling
  result = execute_with_harness_provider(provider_type, prompt, step_name, options)

  debug_step(step_name, "Harness execution completed", {
    status: result[:status],
    provider: result[:provider]
  })

  # Process result for harness
  process_result_for_harness(result, step_name, options)
end

#step_completed?(step_name) ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/aidp/analyze/runner.rb', line 105

def step_completed?(step_name)
  progress.step_completed?(step_name)
end