Class: AgentHarness::Providers::GithubCopilot
Constant Summary
collapse
- MODEL_PATTERN =
/^gpt-[\d.o-]+(?:-turbo)?(?:-mini)?$/i
- JSON_OUTPUT_MIN_VERSION =
Gem::Version.new("0.0.422").freeze
- SUBCOMMAND_CLI_MIN_VERSION =
Gem::Version.new("0.1.0").freeze
- UNSUPPORTED_SUBCOMMAND_CLI_MESSAGE =
"github-copilot-cli 0.1.x does not expose a non-interactive send interface; " \
"the what-the-shell subcommand is interactive and cannot be used by AgentHarness."
- SMOKE_TEST_CONTRACT =
{
prompt: "Reply with exactly OK.",
expected_output: "OK",
timeout: 30,
require_output: true,
success_message: "Smoke test passed"
}.freeze
- GITHUB_MODELS_BASE_URL =
"https://models.inference.ai.azure.com"
- CHAT_DEFAULT_MODEL =
"gpt-4o"
- CHAT_MODELS =
%w[gpt-4o gpt-4o-mini gpt-4-turbo].freeze
Constants inherited
from Base
Base::COMMON_ERROR_PATTERNS, Base::DEFAULT_SMOKE_TEST_CONTRACT
Instance Attribute Summary
Attributes inherited from Base
#config, #executor, #logger
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#api_key_env_var_names, #api_key_unset_vars, #cli_env_overrides, #configure, #initialize, #parse_rate_limit_reset, #parse_test_error, #sandboxed_environment?, #send_chat_message, #subscription_unset_vars, #test_command_overrides
Methods included from Adapter
#auth_lock_config, #build_mcp_flags, #config_file_content, #error_classification_patterns, #fetch_mcp_servers, #health_status, included, metadata_package_name, #noisy_error_patterns, normalize_metadata_installation, normalize_metadata_source_type, normalize_metadata_version_requirement, #notify_hook_content, #parse_rate_limit_reset, #smoke_test, #smoke_test_contract, #supported_mcp_transports, #supports_dangerous_mode?, #supports_mcp?, #supports_text_mode?, #supports_tool_control?, #token_usage_from_api_response, #validate_config, #validate_mcp_servers!
Class Method Details
.available? ⇒ Boolean
36
37
38
39
40
41
42
43
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 36
def available?
executor = AgentHarness.configuration.command_executor
return false unless executor.which(binary_name)
!subcommand_cli_version?(copilot_cli_version(executor: executor))
rescue
false
end
|
.binary_name ⇒ Object
32
33
34
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 32
def binary_name
"github-copilot-cli"
end
|
.discover_models ⇒ Object
91
92
93
94
95
96
97
98
99
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 91
def discover_models
return [] unless available?
[
{name: "gpt-4o", family: "gpt-4o", tier: "standard", provider: "github_copilot"},
{name: "gpt-4o-mini", family: "gpt-4o-mini", tier: "mini", provider: "github_copilot"},
{name: "gpt-4-turbo", family: "gpt-4-turbo", tier: "advanced", provider: "github_copilot"}
]
end
|
.firewall_requirements ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 68
def firewall_requirements
{
domains: [
"copilot-proxy.githubusercontent.com",
"api.githubcopilot.com",
"copilot-telemetry.githubusercontent.com",
"default.exp-tas.com",
"copilot-completions.githubusercontent.com"
],
ip_ranges: []
}
end
|
.install_command(version: nil) ⇒ Object
52
53
54
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 52
def install_command(version: nil)
installation_contract(version: version)&.fetch(:install_command)
end
|
.installation_contract(version: nil) ⇒ Object
45
46
47
48
49
50
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 45
def installation_contract(version: nil)
nil
end
|
.instruction_file_paths ⇒ Object
81
82
83
84
85
86
87
88
89
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 81
def instruction_file_paths
[
{
path: ".github/copilot-instructions.md",
description: "GitHub Copilot agent instructions",
symlink: true
}
]
end
|
.model_family(provider_model_name) ⇒ Object
109
110
111
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 109
def model_family(provider_model_name)
provider_model_name
end
|
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 56
def provider_metadata_overrides
{
auth: {
service: :github,
api_family: :github_copilot
},
identity: {
bot_usernames: ["github-copilot[bot]"]
}
}
end
|
.provider_model_name(family_name) ⇒ Object
113
114
115
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 113
def provider_model_name(family_name)
family_name
end
|
.provider_name ⇒ Object
28
29
30
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 28
def provider_name
:github_copilot
end
|
.smoke_test_contract ⇒ Object
105
106
107
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 105
def smoke_test_contract
SMOKE_TEST_CONTRACT
end
|
.supports_chat? ⇒ Boolean
101
102
103
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 101
def supports_chat?
true
end
|
.supports_model_family?(family_name) ⇒ Boolean
117
118
119
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 117
def supports_model_family?(family_name)
MODEL_PATTERN.match?(family_name)
end
|
Instance Method Details
#auth_type ⇒ Object
236
237
238
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 236
def auth_type
:oauth
end
|
#build_runtime_chat_transport(runtime) ⇒ Object
223
224
225
226
227
228
229
230
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 223
def build_runtime_chat_transport(runtime)
OpenAICompatibleTransport.new(
base_url: runtime.chat_base_url || GITHUB_MODELS_BASE_URL,
api_key: runtime.chat_api_key || resolve_chat_api_key,
model: runtime.chat_model || runtime.model || CHAT_DEFAULT_MODEL,
logger: @logger
)
end
|
#capabilities ⇒ Object
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 171
def capabilities
{
streaming: false,
file_upload: false,
vision: false,
tool_use: true,
json_mode: false,
mcp: false,
dangerous_mode: true
}
end
|
#chat_models ⇒ Object
210
211
212
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 210
def chat_models
CHAT_MODELS
end
|
#chat_transport_type ⇒ Object
232
233
234
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 232
def chat_transport_type
:openai_compatible
end
|
#configuration_schema ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 154
def configuration_schema
{
fields: [
{
name: :model,
type: :string,
label: "Model",
required: false,
hint: "Copilot model identifier (for example gpt-4o or gpt-4o-mini)",
accepts_arbitrary: true
}
],
auth_modes: [:oauth],
openai_compatible: false
}
end
|
#dangerous_mode_flags(probe_timeout: nil, env: {}, version: nil) ⇒ Object
183
184
185
186
187
188
189
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 183
def dangerous_mode_flags(probe_timeout: nil, env: {}, version: nil)
version ||= copilot_cli_version(probe_timeout: probe_timeout, env: env)
return [] if subcommand_cli_version?(version)
return [] unless supports_json_output_format?(version: version)
["--allow-all"]
end
|
#display_name ⇒ Object
150
151
152
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 150
def display_name
"GitHub Copilot CLI"
end
|
#error_patterns ⇒ Object
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 255
def error_patterns
{
auth_expired: [
/not.?authorized/i,
/access.?denied/i,
/permission.?denied/i,
/not.?enabled/i,
/subscription.?required/i
],
rate_limited: [
/usage.?limit/i,
/rate.?limit/i
],
transient: [
/connection.?error/i,
/timeout/i,
/try.?again/i
],
permanent: [
/invalid.?command/i,
/unknown.?flag/i
]
}
end
|
#execution_semantics ⇒ Object
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 240
def execution_semantics
{
prompt_delivery: :arg,
output_format: :text,
sandbox_aware: false,
uses_subcommand: false,
non_interactive_flag: nil,
legitimate_exit_codes: [0],
stderr_is_diagnostic: true,
parses_rate_limit_reset: false
}
end
|
#name ⇒ Object
146
147
148
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 146
def name
"github_copilot"
end
|
#send_message(prompt:, **options) ⇒ Object
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 291
def send_message(prompt:, **options)
log_debug("send_message_start", prompt_length: prompt.length, options: options.keys)
options = normalize_provider_runtime(options)
options = normalize_mcp_servers(options)
validate_mcp_servers!(options[:mcp_servers]) if options[:mcp_servers]&.any?
timeout = options[:timeout] || @config.timeout || default_timeout
raise TimeoutError, "Command timed out before execution started" if timeout <= 0
env = build_env(options)
options = options.merge(_version_probe_timeout: [timeout, 5].min, _command_env: env)
start_time = Time.now
command = build_command(prompt, options)
preparation = build_execution_preparation(options)
remaining_timeout = timeout - (Time.now - start_time)
raise TimeoutError, "Command timed out before execution started" if remaining_timeout <= 0
json_output_requested = command.include?("--output-format") && command.include?("json")
result = execute_with_timeout(
command,
timeout: remaining_timeout,
env: env,
preparation: preparation,
**command_execution_options(options)
)
duration = Time.now - start_time
response = parse_response(result, duration: duration, json_output_requested: json_output_requested)
runtime = options[:provider_runtime]
effective_runtime_model = normalized_model_name(runtime&.model)
if effective_runtime_model
response = Response.new(
output: response.output,
exit_code: response.exit_code,
duration: response.duration,
provider: response.provider,
model: effective_runtime_model,
tokens: response.tokens,
metadata: response.metadata,
error: response.error
)
end
track_tokens(response) if response.tokens
log_debug("send_message_complete", duration: duration, tokens: response.tokens)
response
rescue McpConfigurationError, McpUnsupportedError, McpTransportUnsupportedError
raise
rescue => e
handle_error(e, prompt: prompt, options: options)
end
|
#session_flags(session_id, version: nil, probe_timeout: nil, env: {}) ⇒ Object
195
196
197
198
199
200
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 195
def session_flags(session_id, version: nil, probe_timeout: nil, env: {})
return [] unless session_id && !session_id.empty?
return [] unless legacy_prompt_cli?(version: version, probe_timeout: probe_timeout, env: env)
["--resume", session_id]
end
|
#supports_chat? ⇒ Boolean
206
207
208
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 206
def supports_chat?
true
end
|
#supports_sessions?(probe_timeout: nil, env: {}, version: nil) ⇒ Boolean
191
192
193
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 191
def supports_sessions?(probe_timeout: nil, env: {}, version: nil)
legacy_prompt_cli?(version: version, probe_timeout: probe_timeout, env: env)
end
|
#supports_token_counting? ⇒ Boolean
287
288
289
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 287
def supports_token_counting?
supports_json_output_format?
end
|
#translate_error(message) ⇒ Object
280
281
282
283
284
285
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 280
def translate_error(message)
case message
when /github-copilot-cli.*not found/i then "GitHub Copilot CLI not installed."
else message
end
end
|