Class: Aidp::Providers::GithubCopilot

Inherits:
Base
  • Object
show all
Includes:
DebugMixin
Defined in:
lib/aidp/providers/github_copilot.rb

Constant Summary

Constants included from DebugMixin

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

Constants inherited from Base

Base::ACTIVITY_STATES, Base::DEFAULT_STUCK_TIMEOUT, Base::TIER_TIMEOUT_MULTIPLIERS, Base::TIMEOUT_ARCHITECTURE_ANALYSIS, Base::TIMEOUT_DEFAULT, Base::TIMEOUT_DOCUMENTATION_ANALYSIS, Base::TIMEOUT_FUNCTIONALITY_ANALYSIS, Base::TIMEOUT_IMPLEMENTATION, Base::TIMEOUT_QUICK_MODE, Base::TIMEOUT_REFACTORING_RECOMMENDATIONS, Base::TIMEOUT_REPOSITORY_ANALYSIS, Base::TIMEOUT_STATIC_ANALYSIS, Base::TIMEOUT_TEST_ANALYSIS

Constants included from MessageDisplay

MessageDisplay::COLOR_MAP

Instance Attribute Summary

Attributes inherited from Base

#activity_state, #last_activity_time, #model, #start_time, #step_name, #stuck_timeout

Class Method Summary collapse

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

Methods inherited from Base

#activity_summary, #configure, discover_models_from_registry, #execution_time, #fetch_mcp_servers, #harness_config, #harness_health_status, #harness_metrics, #harness_mode?, #initialize, #mark_completed, #mark_failed, #record_activity, #record_harness_request, #send_with_harness, #set_harness_context, #set_job_context, #setup_activity_monitoring, #stuck?, #supports_activity_monitoring?, #supports_mcp?, #time_since_last_activity, #update_activity_state

Methods included from Adapter

#capabilities, #classify_error, #dangerous_mode=, #dangerous_mode_enabled?, #dangerous_mode_flags, #error_metadata, #error_patterns, #fetch_mcp_servers, #health_status, #logging_metadata, #redact_secrets, #retryable_error?, #supports_dangerous_mode?, #supports_mcp?, #validate_config

Methods included from MessageDisplay

#display_message, included, #message_display_prompt

Constructor Details

This class inherits a constructor from Aidp::Providers::Base

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/aidp/providers/github_copilot.rb', line 13

def self.available?
  !!Aidp::Util.which("copilot")
end

.firewall_requirementsObject

Get firewall requirements for GitHub Copilot provider



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/aidp/providers/github_copilot.rb', line 18

def self.firewall_requirements
  {
    domains: [
      "copilot-proxy.githubusercontent.com",
      "api.githubcopilot.com",
      "copilot-telemetry.githubusercontent.com",
      "default.exp-tas.com",
      "copilot-completions.githubusercontent.com",
      "business.githubcopilot.com",
      "enterprise.githubcopilot.com",
      "individual.githubcopilot.com"
    ],
    ip_ranges: []
  }
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
52
# File 'lib/aidp/providers/github_copilot.rb', line 42

def available?
  return false unless self.class.available?

  # Additional check to ensure the CLI is properly configured
  begin
    result = Aidp::Util.execute_command("copilot", ["--version"], timeout: 10)
    result.exit_status == 0
  rescue
    false
  end
end

#display_nameObject



38
39
40
# File 'lib/aidp/providers/github_copilot.rb', line 38

def display_name
  "GitHub Copilot CLI"
end

#harness_healthy?Boolean

Override health check for GitHub Copilot specific considerations

Returns:

  • (Boolean)


171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/aidp/providers/github_copilot.rb', line 171

def harness_healthy?
  return false unless super

  # Additional health checks specific to GitHub Copilot CLI
  # Check if we can access GitHub (basic connectivity test)
  begin
    result = Aidp::Util.execute_command("copilot", ["--help"], timeout: 5)
    result.exit_status == 0
  rescue
    false
  end
end

#nameObject



34
35
36
# File 'lib/aidp/providers/github_copilot.rb', line 34

def name
  "github_copilot"
end

#send_message(prompt:, session: nil, options: {}) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/aidp/providers/github_copilot.rb', line 54

def send_message(prompt:, session: nil, options: {})
  raise "copilot CLI not available" unless self.class.available?

  # Smart timeout calculation
  timeout_seconds = calculate_timeout

  debug_provider("copilot", "Starting execution", {timeout: timeout_seconds})
  debug_log("📝 Sending prompt to copilot (length: #{prompt.length})", level: :info)

  # Set up activity monitoring
  setup_activity_monitoring("copilot", method(:activity_callback))
  record_activity("Starting copilot execution")

  # Create a spinner for activity display
  spinner = TTY::Spinner.new("[:spinner] :title", format: :dots, hide_cursor: true)
  spinner.auto_spin

  activity_display_thread = Thread.new do
    start_time = Time.now
    loop do
      sleep 0.5 # Update every 500ms to reduce spam
      elapsed = Time.now - start_time

      # Break if we've been running too long or state changed
      break if elapsed > timeout_seconds || @activity_state == :completed || @activity_state == :failed

      update_spinner_status(spinner, elapsed, "🤖 GitHub Copilot CLI")
    end
  end

  begin
    # Use non-interactive mode for automation
    args = ["-p", prompt, "--allow-all-tools"]

    # Add session support if provided
    if session && !session.empty?
      args += ["--resume", session]
    end

    # Use debug_execute_command for better debugging (no input since prompt is in args)
    result = debug_execute_command("copilot", args: args, timeout: timeout_seconds)

    # Log the results
    debug_command("copilot", args: args, input: prompt, output: result.out, error: result.err, exit_code: result.exit_status)

    # Detect authorization/access errors
    auth_error = result.err.to_s =~ /not authorized|requires an enterprise|access denied|permission denied|not enabled/i
    if auth_error
      spinner.error("")
      mark_failed("copilot authorization error: #{result.err}")
      @unavailable = true
      debug_error(StandardError.new("copilot authorization error"), {exit_code: result.exit_status, stderr: result.err})
      raise Aidp::Providers::ProviderUnavailableError.new("copilot authorization error: #{result.err}")
    end

    if result.exit_status == 0
      spinner.success("")
      mark_completed
      result.out
    else
      spinner.error("")
      mark_failed("copilot failed with exit code #{result.exit_status}")
      debug_error(StandardError.new("copilot failed"), {exit_code: result.exit_status, stderr: result.err})
      raise "copilot failed with exit code #{result.exit_status}: #{result.err}"
    end
  rescue Aidp::Providers::ProviderUnavailableError
    raise
  rescue => e
    spinner&.error("")
    mark_failed("copilot execution failed: #{e.message}")
    debug_error(e, {provider: "github_copilot", prompt_length: prompt.length})
    raise
  ensure
    cleanup_activity_display(activity_display_thread, spinner)
  end
end

#send_with_options(prompt:, session: nil, tools: nil, log_level: nil, config_file: nil, directories: nil) ⇒ Object

Enhanced send method with additional options



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/aidp/providers/github_copilot.rb', line 132

def send_with_options(prompt:, session: nil, tools: nil, log_level: nil, config_file: nil, directories: nil)
  args = ["-p", prompt]

  # Add session support
  if session && !session.empty?
    args += ["--resume", session]
  end

  # Add tool permissions
  if tools && !tools.empty?
    if tools.include?("all")
      args += ["--allow-all-tools"]
    else
      tools.each do |tool|
        args += ["--allow-tool", tool]
      end
    end
  else
    # Default to allowing all tools for automation
    args += ["--allow-all-tools"]
  end

  # Add logging level
  if log_level
    args += ["--log-level", log_level]
  end

  # Add allowed directories
  if directories && !directories.empty?
    directories.each do |dir|
      args += ["--add-dir", dir]
    end
  end

  # Use the enhanced version of send
  send_with_custom_args(prompt: prompt, args: args)
end