Class: AgentHarness::Providers::GithubCopilot
Constant Summary
collapse
- PACKAGE_NAME =
"@githubnext/github-copilot-cli"
- SUPPORTED_CLI_VERSION =
"0.1.36"
- SUPPORTED_CLI_REQUIREMENT =
Gem::Requirement.new(">= #{SUPPORTED_CLI_VERSION}", "< 0.2.0").freeze
- MODEL_PATTERN =
/^gpt-[\d.o-]+(?:-turbo)?(?:-mini)?$/i
- JSON_OUTPUT_MIN_VERSION =
Gem::Version.new("0.0.422").freeze
- SMOKE_TEST_CONTRACT =
{
prompt: "Reply with exactly OK.",
expected_output: "OK",
timeout: 30,
require_output: true,
success_message: "Smoke test passed"
}.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?, #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
.binary_name ⇒ Object
31
32
33
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 31
def binary_name
"github-copilot-cli"
end
|
.discover_models ⇒ Object
109
110
111
112
113
114
115
116
117
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 109
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
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 86
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: SUPPORTED_CLI_VERSION) ⇒ Object
70
71
72
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 70
def install_command(version: SUPPORTED_CLI_VERSION)
installation_contract(version: version)[:install_command]
end
|
.installation_contract(version: SUPPORTED_CLI_VERSION) ⇒ Object
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
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 40
def installation_contract(version: SUPPORTED_CLI_VERSION)
version = version.strip if version.respond_to?(:strip)
validate_install_version!(version)
package_spec = "#{PACKAGE_NAME}@#{version}".freeze
install_command_prefix = ["npm", "install", "-g", "--ignore-scripts"].freeze
install_command = (install_command_prefix + [package_spec]).freeze
version_requirement = SUPPORTED_CLI_REQUIREMENT.requirements
.map { |op, ver| "#{op} #{ver}".freeze }
.freeze
contract = {
source: {
type: :npm,
package: PACKAGE_NAME
}.freeze,
install_command_prefix: install_command_prefix,
install_command: install_command,
binary_name: binary_name,
default_version: SUPPORTED_CLI_VERSION,
version: version,
version_requirement: version_requirement,
supported_version_requirement: SUPPORTED_CLI_REQUIREMENT.to_s
}
contract.each_value do |value|
value.freeze if value.is_a?(String)
end
contract.freeze
end
|
.instruction_file_paths ⇒ Object
99
100
101
102
103
104
105
106
107
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 99
def instruction_file_paths
[
{
path: ".github/copilot-instructions.md",
description: "GitHub Copilot agent instructions",
symlink: true
}
]
end
|
.model_family(provider_model_name) ⇒ Object
123
124
125
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 123
def model_family(provider_model_name)
provider_model_name
end
|
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 74
def provider_metadata_overrides
{
auth: {
service: :github,
api_family: :github_copilot
},
identity: {
bot_usernames: ["github-copilot[bot]"]
}
}
end
|
.provider_model_name(family_name) ⇒ Object
127
128
129
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 127
def provider_model_name(family_name)
family_name
end
|
.provider_name ⇒ Object
27
28
29
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 27
def provider_name
:github_copilot
end
|
.smoke_test_contract ⇒ Object
119
120
121
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 119
def smoke_test_contract
SMOKE_TEST_CONTRACT
end
|
.supports_model_family?(family_name) ⇒ Boolean
131
132
133
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 131
def supports_model_family?(family_name)
MODEL_PATTERN.match?(family_name)
end
|
Instance Method Details
#auth_type ⇒ Object
212
213
214
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 212
def auth_type
:oauth
end
|
#capabilities ⇒ Object
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 185
def capabilities
{
streaming: false,
file_upload: false,
vision: false,
tool_use: true,
json_mode: false,
mcp: false,
dangerous_mode: true
}
end
|
#configuration_schema ⇒ Object
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 168
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: {}) ⇒ Object
197
198
199
200
201
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 197
def dangerous_mode_flags(probe_timeout: nil, env: {})
return [] unless supports_json_output_format?(probe_timeout: probe_timeout, env: env)
["--allow-all"]
end
|
#display_name ⇒ Object
164
165
166
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 164
def display_name
"GitHub Copilot CLI"
end
|
#error_patterns ⇒ Object
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 231
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 216
def execution_semantics
{
prompt_delivery: :arg,
output_format: :text,
sandbox_aware: false,
uses_subcommand: false,
non_interactive_flag: "-p",
legitimate_exit_codes: [0],
stderr_is_diagnostic: true,
parses_rate_limit_reset: false
}
end
|
#name ⇒ Object
160
161
162
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 160
def name
"github_copilot"
end
|
#send_message(prompt:, **options) ⇒ Object
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
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
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 267
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) ⇒ Object
207
208
209
210
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 207
def session_flags(session_id)
return [] unless session_id && !session_id.empty?
["--resume", session_id]
end
|
#supports_sessions? ⇒ Boolean
203
204
205
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 203
def supports_sessions?
true
end
|
#supports_token_counting? ⇒ Boolean
263
264
265
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 263
def supports_token_counting?
supports_json_output_format?
end
|
#translate_error(message) ⇒ Object
256
257
258
259
260
261
|
# File 'lib/agent_harness/providers/github_copilot.rb', line 256
def translate_error(message)
case message
when /github-copilot-cli.*not found/i then "GitHub Copilot CLI not installed."
else message
end
end
|