Class: AgentHarness::Providers::OhMyPi
- Inherits:
-
Base
- Object
- Base
- AgentHarness::Providers::OhMyPi
show all
- Defined in:
- lib/agent_harness/providers/omp.rb
Overview
Oh My Pi coding agent CLI provider
Provides integration with the Oh My Pi (can1357/oh-my-pi) terminal
coding agent, a Bun-based fork of the Pi coding agent. Distinct from
the Pi provider, which targets the upstream @mariozechner/pi-coding-agent
CLI.
Constant Summary
collapse
- CLI_PACKAGE =
"@oh-my-pi/pi-coding-agent"
- SUPPORTED_CLI_VERSION =
"17.0.1"
- SUPPORTED_CLI_REQUIREMENT =
Gem::Requirement.new("= #{SUPPORTED_CLI_VERSION}").freeze
- BUN_BINARY =
Bun runtime requirements. The omp entrypoint is
#!/usr/bin/env bun and the published package metadata requires
Bun >= 1.3.14. Consumers must provision a compatible Bun runtime
before installing the @oh-my-pi/pi-coding-agent package.
The bun npm package relies on its postinstall script to fetch the
platform binary; installing it with npm install --ignore-scripts
ships only the Windows shims (bin/bun.exe, bunx.exe) and leaves
Linux/macOS without a working bun binary. Provision Bun via the
official installer script instead, which fetches the correct
platform binary directly.
"bun"
- BUN_INSTALL_SCRIPT_URL =
"https://bun.sh/install"
- SUPPORTED_BUN_VERSION =
"1.3.14"
- BUN_REQUIREMENT_STRING =
">= #{SUPPORTED_BUN_VERSION}".freeze
- SMOKE_TEST_CONTRACT =
Smoke-test contract suitable for container health probes.
Oh My Pi runs non-interactively via -p with --no-session, so the
probe is a single deterministic round trip. The contract is tuned for
a tight probe budget: a short prompt that elicits a predictable reply
and a bounded timeout that accommodates a cold Bun runtime start.
{
prompt: "Reply with exactly OK.",
expected_output: "OK",
timeout: 30,
require_output: true,
success_message: "Oh My Pi smoke test passed"
}.freeze
- ERROR_PATTERNS =
Oh My Pi is a multi-provider CLI: it routes to a backend through
--provider and surfaces that backend's error vocabulary. The
patterns below extend the shared HTTP-style set with Oh My Pi /
upstream-Pi specific phrasing observed for auth expiry, quota and
rate-limit surfaces, model resolution failures, and transient
network faults.
{
rate_limited: COMMON_ERROR_PATTERNS[:rate_limited],
auth_expired: COMMON_ERROR_PATTERNS[:auth_expired] + [
/\b401\b/,
/session.*(?:expired|invalid)/i,
/log(?:ged)?.?in.*required/i,
/api.?key.*(?:invalid|missing|expired|revoked)/i,
/token.*(?:expired|invalid|revoked)/i,
/credentials.*(?:expired|invalid|missing)/i
],
quota_exceeded: COMMON_ERROR_PATTERNS[:quota_exceeded],
model_not_found: [
/model.*not.*found/i,
/no.*such.*model/i,
/unknown.*model/i,
/model.*does.*not.*exist/i,
/invalid.*model/i,
/model.*unavailable/i,
/provider.*does.*not.*support.*model/i
],
transient: COMMON_ERROR_PATTERNS[:transient] + [
/connection.*reset/i,
/econnreset/i,
/socket.*hang.*up/i,
/network.*error/i
]
}.tap { |patterns| patterns.each_value(&:freeze) }.freeze
- NOISY_OUTPUT_PATTERNS =
Non-actionable output that Oh My Pi writes while the Bun runtime and
the agent bootstrap. Downstream consumers use these to filter probe
and run output so startup banners do not masquerade as failures.
[
/oh.?my.?pi\b/i,
/pi(?:-coding.?agent)?\s+v?\d+\.\d+/i,
/\bbun\s+v?\d+\.\d+/i,
/\bloading/i,
/\binitializing/i,
/\bwarming.?up/i,
/fetching.*model/i
].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
#cli_env_overrides, #configure, #initialize, #parse_container_output, #parse_test_error, #plan_execution, #preflight_check, #sandboxed_environment?, #send_chat_message, #send_message, #test_command_overrides
#parse_rate_limit_reset
Methods included from Adapter
#auth_lock_config, #build_mcp_flags, #chat_transport, #chat_transport_type, #config_file_content, #dangerous_mode_flags, #fetch_mcp_servers, #health_status, #heartbeat_integration, included, metadata_package_name, normalize_metadata_installation, normalize_metadata_runtime_requirements, normalize_metadata_source_type, normalize_metadata_version_requirement, #notify_hook_content, #parse_rate_limit_reset, #plan_execution, #preflight_check, #send_message, #session_flags, #smoke_test, #smoke_test_contract, #supported_mcp_transports, #supports_activity_heartbeat?, #supports_chat?, #supports_dangerous_mode?, #supports_mcp?, #supports_message_tool_injection?, #supports_text_mode?, #supports_token_counting?, #token_usage_from_api_response, #validate_config, #validate_mcp_servers!
Class Method Details
.binary_name ⇒ Object
104
105
106
|
# File 'lib/agent_harness/providers/omp.rb', line 104
def binary_name
"omp"
end
|
.bun_runtime_contract ⇒ Object
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/agent_harness/providers/omp.rb', line 166
def bun_runtime_contract
install_command_prefix = ["sh", "-c"].freeze
inner_script = "curl -fsSL #{BUN_INSTALL_SCRIPT_URL} | " \
"BUN_VERSION=#{SUPPORTED_BUN_VERSION} bash"
install_command = (install_command_prefix + [inner_script]).freeze
{
name: :bun,
binary_name: BUN_BINARY,
pinned_version: SUPPORTED_BUN_VERSION,
version_requirement: BUN_REQUIREMENT_STRING,
source: :script,
install_script_url: BUN_INSTALL_SCRIPT_URL,
install_command_prefix: install_command_prefix,
install_command: install_command,
install_command_string: inner_script,
rationale: "omp entrypoint is #!/usr/bin/env bun; the bun npm package relies on " \
"its postinstall script to fetch the platform binary, so install Bun " \
"via the official installer script rather than npm --ignore-scripts"
}.freeze
end
|
.discover_models ⇒ Object
161
162
163
164
|
# File 'lib/agent_harness/providers/omp.rb', line 161
def discover_models
return [] unless available?
[]
end
|
.firewall_requirements ⇒ Object
137
138
139
140
141
142
143
144
|
# File 'lib/agent_harness/providers/omp.rb', line 137
def firewall_requirements
{
domains: [
"pi.dev"
],
ip_ranges: []
}
end
|
.installation_contract(version: SUPPORTED_CLI_VERSION) ⇒ Object
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
# File 'lib/agent_harness/providers/omp.rb', line 190
def installation_contract(version: SUPPORTED_CLI_VERSION)
version = version.strip if version.respond_to?(:strip)
unless version.is_a?(String) && !version.empty?
raise ArgumentError,
"Unsupported Oh My Pi CLI version #{version.inspect}; " \
"supported versions must satisfy #{SUPPORTED_CLI_REQUIREMENT}"
end
parsed_version = begin
Gem::Version.new(version)
rescue ArgumentError
raise ArgumentError,
"Unsupported Oh My Pi CLI version #{version.inspect}; " \
"supported versions must satisfy #{SUPPORTED_CLI_REQUIREMENT}"
end
unless SUPPORTED_CLI_REQUIREMENT.satisfied_by?(parsed_version)
raise ArgumentError,
"Unsupported Oh My Pi CLI version #{version.inspect}; " \
"supported versions must satisfy #{SUPPORTED_CLI_REQUIREMENT}"
end
package = "#{CLI_PACKAGE}@#{version}".freeze
install_command_prefix = ["npm", "install", "-g", "--ignore-scripts"].freeze
install_command = (install_command_prefix + [package]).freeze
supported_versions = [version].freeze
version_requirement = SUPPORTED_CLI_REQUIREMENT.requirements
.map { |op, ver| "#{op} #{ver}".freeze }
.freeze
contract = {
source: :npm,
package: package,
package_name: CLI_PACKAGE,
version: version,
version_requirement: version_requirement,
binary_name: binary_name,
install_command_prefix: install_command_prefix,
install_command: install_command,
supported_versions: supported_versions,
runtime_requirements: [bun_runtime_contract]
}
contract.each_value do |value|
value.freeze if value.is_a?(String)
end
contract.freeze
end
|
.instruction_file_paths ⇒ Object
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/agent_harness/providers/omp.rb', line 146
def instruction_file_paths
[
{
path: "AGENTS.md",
description: "Oh My Pi agent instructions",
symlink: false
},
{
path: "SYSTEM.md",
description: "Oh My Pi system prompt override",
symlink: false
}
]
end
|
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/agent_harness/providers/omp.rb', line 113
def provider_metadata_overrides
{
auth: {
service: :omp,
api_family: :multi_provider,
api_key_source: :provider_runtime_env
}
}
end
|
.provider_name ⇒ Object
100
101
102
|
# File 'lib/agent_harness/providers/omp.rb', line 100
def provider_name
:omp
end
|
.smoke_test_contract ⇒ Object
240
241
242
|
# File 'lib/agent_harness/providers/omp.rb', line 240
def smoke_test_contract
SMOKE_TEST_CONTRACT
end
|
Instance Method Details
#api_key_env_var_names ⇒ Object
Conventional backend API-key env vars the omp CLI reads. Oh My Pi is
multi-provider: the effective var is the one matching the selected
--provider, supplied per request through ProviderRuntime#env.
352
353
354
355
356
357
358
359
360
361
362
363
364
|
# File 'lib/agent_harness/providers/omp.rb', line 352
def api_key_env_var_names
[
"ANTHROPIC_API_KEY",
"OPENAI_API_KEY",
"GEMINI_API_KEY",
"GOOGLE_API_KEY",
"XAI_API_KEY",
"DEEPSEEK_API_KEY",
"OPENROUTER_API_KEY",
"GROQ_API_KEY",
"MISTRAL_API_KEY"
]
end
|
#api_key_unset_vars ⇒ Object
omp routes through --provider rather than an env-driven proxy/base
URL, so there are no known proxy header vars to scrub when a caller
supplies its own key.
369
370
371
|
# File 'lib/agent_harness/providers/omp.rb', line 369
def api_key_unset_vars
[]
end
|
#auth_type ⇒ Object
345
346
347
|
# File 'lib/agent_harness/providers/omp.rb', line 345
def auth_type
:oauth
end
|
#capabilities ⇒ Object
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
# File 'lib/agent_harness/providers/omp.rb', line 276
def capabilities
{
streaming: false,
file_upload: true,
vision: true,
tool_use: true,
json_mode: false,
mcp: false,
dangerous_mode: false
}
end
|
#configuration_schema ⇒ Object
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
# File 'lib/agent_harness/providers/omp.rb', line 253
def configuration_schema
{
fields: [
{
name: :model,
type: :string,
label: "Model",
required: false,
hint: "Oh My Pi model pattern or ID passed to --model"
},
{
name: :provider,
type: :string,
label: "Provider",
required: false,
hint: "Oh My Pi provider name passed to --provider"
}
],
auth_modes: %i[api_key oauth],
openai_compatible: false
}
end
|
#display_name ⇒ Object
249
250
251
|
# File 'lib/agent_harness/providers/omp.rb', line 249
def display_name
"Oh My Pi"
end
|
#error_classification_patterns ⇒ Object
Downstream-facing error classification. Augments the shared quota set
with auth-expiry, model-resolution, and authentication-specific
phrasing so consumers can route omp failures without re-deriving the
CLI vocabulary. The inherited :quota set is deliberately preserved
(not overridden) so omp's multi-provider backends surface their full
credit/balance vocabulary (requires more credits, insufficient
balance, spend limit reached, billing limit, etc.).
306
307
308
309
310
311
312
313
314
315
316
317
|
# File 'lib/agent_harness/providers/omp.rb', line 306
def error_classification_patterns
super.merge(
auth_expired: ERROR_PATTERNS[:auth_expired],
authentication: [
/api.?key.*not.*(?:set|configured)/i,
/no.*api.?key/i,
/missing.*credentials/i,
/log(?:ged)?.?in.*required/i
],
model_not_found: ERROR_PATTERNS[:model_not_found]
)
end
|
#error_patterns ⇒ Object
295
296
297
|
# File 'lib/agent_harness/providers/omp.rb', line 295
def error_patterns
ERROR_PATTERNS
end
|
#execution_semantics ⇒ Object
379
380
381
382
383
384
385
386
387
388
389
390
|
# File 'lib/agent_harness/providers/omp.rb', line 379
def execution_semantics
{
prompt_delivery: :flag,
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
245
246
247
|
# File 'lib/agent_harness/providers/omp.rb', line 245
def name
"omp"
end
|
#noisy_error_patterns ⇒ Object
Oh My Pi emits a startup banner (version, Bun runtime, model fetch)
that is not actionable. Expose it so callers can strip probe noise.
321
322
323
|
# File 'lib/agent_harness/providers/omp.rb', line 321
def noisy_error_patterns
NOISY_OUTPUT_PATTERNS
end
|
#subscription_unset_vars ⇒ Object
When running against an OAuth/subscription session, drop backend
API-key env vars so the CLI prefers the stored session credentials.
375
376
377
|
# File 'lib/agent_harness/providers/omp.rb', line 375
def subscription_unset_vars
api_key_env_var_names
end
|
#supports_sessions? ⇒ Boolean
Oh My Pi runs stateless through --no-session; the harness does not
expose session persistence, so callers cannot resume a session.
337
338
339
|
# File 'lib/agent_harness/providers/omp.rb', line 337
def supports_sessions?
false
end
|
341
342
343
|
# File 'lib/agent_harness/providers/omp.rb', line 341
def supports_tool_control?
true
end
|
#translate_error(message) ⇒ Object
325
326
327
328
329
330
331
332
333
|
# File 'lib/agent_harness/providers/omp.rb', line 325
def translate_error(message)
if ERROR_PATTERNS[:model_not_found].any? { |p| message.match?(p) }
"Oh My Pi could not resolve the requested model. Check --model/--provider."
elsif /api.?key.*not.*(?:set|configured)/i.match?(message) || /no.*api.?key/i.match?(message)
"Oh My Pi API key not set for the selected provider."
else
message
end
end
|