agent-cli-runtime 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 59030c0c124438712ef78cc86c61a0d26ce929ff424ea468493e0c899f660599
4
+ data.tar.gz: fe1ccdd4b7c38c75dbd5491b20eefde6d60e493e4ceec116cbc3c2181f159559
5
+ SHA512:
6
+ metadata.gz: 4f794b419f2503d453e08c60e49a0c39d21eb7fd096a658fc18fd159c2b13803e5259f7c0bcb69f1033e1f964d818789db9713ada5eeaecd624710af65806506
7
+ data.tar.gz: 6746e8807b5da2ee77b9e48828db7cb7de5aea48553961be867143a5b09110ca59de3ff40f3a34fbaeb38df6b763d728f9727586cfd5bb2126982a6c22e85327
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 - 2026-07-26
4
+
5
+ - Add immutable profiles for Claude Code, Codex CLI, Pi, and Grok CLI.
6
+ - Add provider-neutral invocation compilation, local prerequisite probes,
7
+ capability evidence, usage extraction, and result normalization.
8
+ - Add the `agent-runtime probe` diagnostic executable with versioned JSON and
9
+ stable exit statuses.
10
+ - Keep missing provider usage unknown instead of recording fabricated zero
11
+ counts, and preserve typed unknown-provider errors through the public facade.
12
+ - Harden local probing around subprocess environments, ambiguous version
13
+ output, TERM-resistant descendants, custom capability evidence, unused Grok
14
+ credential paths, and long or JSON-delimited secrets.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ivan Kuznetsov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,156 @@
1
+ # Agent CLI Runtime
2
+
3
+ `agent-cli-runtime` is a small Ruby library for tools that need to describe
4
+ and inspect locally installed headless agent CLIs without owning an agent
5
+ orchestration system.
6
+
7
+ It ships immutable profiles for Claude Code, Codex CLI, Pi, and Grok CLI;
8
+ compiles provider-neutral requests into argv/stdin; reports typed capability
9
+ evidence; extracts usage from provider JSON events; and exposes an honest local
10
+ diagnostic command.
11
+
12
+ ## Install
13
+
14
+ ```ruby
15
+ gem "agent-cli-runtime", "~> 0.1.0"
16
+ ```
17
+
18
+ ```ruby
19
+ require "agent_cli_runtime"
20
+ ```
21
+
22
+ Ruby 3.4 or newer is required. Version 0.1.x is tested on Linux and macOS.
23
+
24
+ ## Compile an invocation
25
+
26
+ ```ruby
27
+ profile = AgentCliRuntime::Profiles.fetch(:codex)
28
+ request = AgentCliRuntime::Request.new(
29
+ profile: profile,
30
+ prompt: "Review the current diff",
31
+ permission_mode: "read-only",
32
+ model: "gpt-5.6-terra",
33
+ effort: "high"
34
+ )
35
+
36
+ invocation = AgentCliRuntime.compile(request)
37
+ invocation.argv # frozen argv; no shell interpolation
38
+ invocation.stdin_data # prompt text for stdin-style providers
39
+ ```
40
+
41
+ Compilation does not execute the returned command. Unsupported requested
42
+ controls raise `AgentCliRuntime::UnsupportedCapability` with typed evidence
43
+ instead of silently widening the request.
44
+
45
+ `permission_mode: nil` deliberately preserves Hive's existing trusted,
46
+ headless behavior: providers with a bypass flag receive that flag. Consumers
47
+ that do not want this compatibility path should pass `"read-only"` or
48
+ `"workspace-write"` explicitly. A profile raises instead of pretending to
49
+ enforce a mode its CLI cannot represent.
50
+
51
+ ## Public API
52
+
53
+ - `compile(request)` returns a frozen argv/stdin invocation.
54
+ - `probe(profile)` and `probe_all` report local prerequisite evidence without
55
+ contacting a provider.
56
+ - `prepare!(profile)` requires that local probe to be ready.
57
+ - `require_capability!(profile, name)` verifies a named CLI capability and
58
+ returns typed evidence.
59
+ - `extract_usage(profile, event)` normalizes provider usage when present and
60
+ returns `nil` when usage is absent or malformed.
61
+ - `observe(profile, result)` normalizes bounded, redacted result metadata.
62
+
63
+ Provider arguments accept a built-in name or an `AgentCliRuntime::Profile`.
64
+ Unknown built-in names raise `AgentCliRuntime::UnknownProvider`; they are not
65
+ converted into generic probe or capability failures.
66
+
67
+ ## Custom profiles
68
+
69
+ ```ruby
70
+ profile = AgentCliRuntime::Profile.new(
71
+ name: :acme,
72
+ bin_default: "acme-agent",
73
+ env_bin_override_keys: ["ACME_AGENT_BIN"],
74
+ headless_flag: "run",
75
+ version_flag: "--version",
76
+ min_version: "1.2.0",
77
+ prompt_style: :stdin,
78
+ read_only_flags: ["--sandbox", "read-only"],
79
+ cli_capabilities: {
80
+ safe_mode: ["--safe-mode"]
81
+ },
82
+ usage_extractor: ->(event) { event["usage"] },
83
+ auth_configuration_probe: ->(home:, env:) {
84
+ AgentCliRuntime::AuthConfiguration.new(
85
+ status: env["ACME_API_KEY"].to_s.empty? ? :missing : :configured,
86
+ source: "environment"
87
+ )
88
+ }
89
+ )
90
+
91
+ request = AgentCliRuntime::Request.new(
92
+ profile: profile,
93
+ prompt: "Inspect the project",
94
+ permission_mode: "read-only",
95
+ capabilities: [:safe_mode]
96
+ )
97
+ AgentCliRuntime.compile(request)
98
+ ```
99
+
100
+ Custom capability names cannot shadow the standard capability vocabulary.
101
+ Capability checks use discrete argv, inspect the installed CLI's help, and
102
+ fail closed when a declared option is not advertised.
103
+
104
+ ## Inspect local prerequisites
105
+
106
+ ```sh
107
+ agent-runtime probe codex
108
+ agent-runtime probe --all --json
109
+ ```
110
+
111
+ The JSON contract is `{"schema_version":1,"probes":[...]}` and always orders
112
+ all-provider output as `claude`, `codex`, `pi`, `grok`.
113
+
114
+ - Exit `0`: every requested local probe is ready.
115
+ - Exit `1`: at least one requested local prerequisite is unavailable.
116
+ - Exit `64`: invalid usage.
117
+
118
+ The probe observes only the local executable, version output, authentication
119
+ configuration presence, and declared capabilities. `configured` means a
120
+ recognized local file or environment variable is present. It does not mean the
121
+ credential is valid, the provider is online, or the account has quota.
122
+
123
+ ## Scope and compatibility
124
+
125
+ The library does not spawn or supervise agents, retry work, run workflows,
126
+ accept artifacts, or interpret Hive state. Provider flags and event formats are
127
+ SemVer-governed public behavior. Additive fields are compatible within 0.1.x;
128
+ removing or changing an existing field or meaning requires a new minor version
129
+ while the gem remains pre-1.0.
130
+
131
+ Development remains in the Hive monorepo under
132
+ `components/agent-cli-runtime`. Hive is the primary consumer and HiveBench is
133
+ the first named external adopter. The Hive maintainer team owns compatibility,
134
+ security response, and releases for the package.
135
+
136
+ ## Development
137
+
138
+ ```sh
139
+ cd components/agent-cli-runtime
140
+ bundle exec rake test
141
+ gem build agent-cli-runtime.gemspec
142
+ ```
143
+
144
+ The root suite includes these package tests plus Hive/package parity coverage;
145
+ run `bundle exec rake test:agent_cli_runtime` from the repository root for the
146
+ standalone component gate alone.
147
+
148
+ Release instructions live in the repository's `docs/RELEASING.md`. Releases
149
+ use component-scoped tags and publish exact preverified gem bytes through
150
+ RubyGems trusted publishing.
151
+
152
+ ## Security
153
+
154
+ Diagnostics are bounded and redact common credential forms. The library never
155
+ prints credential file contents or environment values. Report vulnerabilities
156
+ through the Hive repository’s security policy.
@@ -0,0 +1,48 @@
1
+ require_relative "lib/agent_cli_runtime/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "agent-cli-runtime"
5
+ spec.version = AgentCliRuntime::VERSION
6
+ spec.authors = [ "Ivan Kuznetsov" ]
7
+ spec.email = [ "ivan@ikuznetsov.com" ]
8
+ spec.summary = "Provider-neutral contracts for installed agent CLIs"
9
+ spec.description = <<~DESC
10
+ Agent CLI Runtime provides immutable profiles, invocation compilation,
11
+ local prerequisite probes, capability evidence, usage extraction, and
12
+ result normalization for Claude Code, Codex CLI, Pi, and Grok CLI. It does
13
+ not spawn agents or claim live provider health, quota, or credential validity.
14
+ DESC
15
+ spec.homepage = "https://github.com/ivankuznetsov/hive"
16
+ spec.license = "MIT"
17
+ spec.required_ruby_version = ">= 3.4.0"
18
+
19
+ spec.metadata = {
20
+ "homepage_uri" => spec.homepage,
21
+ "source_code_uri" =>
22
+ "https://github.com/ivankuznetsov/hive/tree/main/components/agent-cli-runtime",
23
+ "changelog_uri" =>
24
+ "https://github.com/ivankuznetsov/hive/blob/main/components/agent-cli-runtime/CHANGELOG.md",
25
+ "bug_tracker_uri" => "https://github.com/ivankuznetsov/hive/issues",
26
+ "documentation_uri" =>
27
+ "https://github.com/ivankuznetsov/hive/blob/main/components/agent-cli-runtime/README.md",
28
+ "rubygems_mfa_required" => "true"
29
+ }
30
+
31
+ spec.files = Dir.chdir(__dir__) do
32
+ Dir[
33
+ "lib/**/*.rb",
34
+ "exe/agent-runtime",
35
+ "README.md",
36
+ "CHANGELOG.md",
37
+ "LICENSE.txt",
38
+ "agent-cli-runtime.gemspec"
39
+ ]
40
+ end
41
+ spec.bindir = "exe"
42
+ spec.executables = [ "agent-runtime" ]
43
+ spec.require_paths = [ "lib" ]
44
+
45
+ spec.add_dependency "json", ">= 2.7", "< 3.0"
46
+ spec.add_dependency "open3", "~> 0.2"
47
+ spec.add_dependency "timeout", ">= 0.4", "< 1.0"
48
+ end
data/exe/agent-runtime ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "agent_cli_runtime"
4
+
5
+ exit AgentCliRuntime::CLI.run(ARGV)
@@ -0,0 +1,98 @@
1
+ require "json"
2
+
3
+ module AgentCliRuntime
4
+ class CLI
5
+ USAGE = <<~TEXT.freeze
6
+ Usage:
7
+ agent-runtime probe PROVIDER [--json]
8
+ agent-runtime probe --all [--json]
9
+ agent-runtime --version
10
+
11
+ Providers: #{Profiles.names.join(', ')}
12
+ TEXT
13
+
14
+ class << self
15
+ def run(argv, out: $stdout, err: $stderr, home: nil, env: ENV)
16
+ arguments = argv.dup
17
+ if arguments == [ "--version" ]
18
+ out.puts VERSION
19
+ return 0
20
+ end
21
+ return usage_error(err) unless arguments.shift == "probe"
22
+
23
+ json = arguments.delete("--json")
24
+ all = arguments.delete("--all")
25
+ return usage_error(err) if arguments.any? { |arg| arg.start_with?("-") }
26
+ return usage_error(err) if all && !arguments.empty?
27
+ return usage_error(err) unless all || arguments.length == 1
28
+
29
+ results =
30
+ if all
31
+ Probe.all(home: home, env: env)
32
+ else
33
+ [ Probe.call(Profiles.fetch(arguments.fetch(0)), home: home, env: env) ]
34
+ end
35
+ json ? render_json(results, out) : render_text(results, out)
36
+ results.all?(&:ready) ? 0 : 1
37
+ rescue UnknownProvider => e
38
+ err.puts e.message
39
+ err.print USAGE
40
+ 64
41
+ end
42
+
43
+ private
44
+
45
+ def usage_error(err)
46
+ err.print USAGE
47
+ 64
48
+ end
49
+
50
+ def render_json(results, out)
51
+ payload = {
52
+ schema_version: 1,
53
+ probes: results.map { |result| probe_hash(result) }
54
+ }
55
+ out.puts JSON.generate(payload)
56
+ end
57
+
58
+ def render_text(results, out)
59
+ results.each do |result|
60
+ state = result.ready ? "ready" : "unavailable"
61
+ version = result.version || "unknown"
62
+ auth = result.auth_configuration.status
63
+ out.puts(
64
+ "#{result.provider}: #{state} " \
65
+ "(installed=#{result.installed} version=#{version} " \
66
+ "auth_configuration=#{auth})"
67
+ )
68
+ out.puts " #{result.diagnostic}" if result.diagnostic
69
+ end
70
+ end
71
+
72
+ def probe_hash(result)
73
+ {
74
+ provider: result.provider.to_s,
75
+ ready: result.ready,
76
+ installed: result.installed,
77
+ executable: Redactor.diagnostic(result.executable, bytes: 256),
78
+ version: result.version,
79
+ minimum_version: result.minimum_version,
80
+ auth_configuration: {
81
+ status: result.auth_configuration.status.to_s,
82
+ source: Redactor.diagnostic(
83
+ result.auth_configuration.source,
84
+ bytes: 256
85
+ )
86
+ },
87
+ capabilities: result.capability_evidence.map do |evidence|
88
+ {
89
+ capability: evidence.capability.to_s,
90
+ supported: evidence.supported
91
+ }
92
+ end,
93
+ diagnostic: result.diagnostic
94
+ }
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,17 @@
1
+ module AgentCliRuntime
2
+ class Error < StandardError
3
+ attr_reader :evidence
4
+
5
+ def initialize(message, evidence: nil)
6
+ super(message)
7
+ @evidence = evidence
8
+ end
9
+ end
10
+
11
+ class BinaryUnavailable < Error; end
12
+ class VersionError < Error; end
13
+ class UnsupportedCapability < Error; end
14
+ class ProbeError < Error; end
15
+ class CompilationError < Error; end
16
+ class UnknownProvider < Error; end
17
+ end
@@ -0,0 +1,91 @@
1
+ module AgentCliRuntime
2
+ module Probe
3
+ module_function
4
+
5
+ def call(profile, home: nil, env: ENV)
6
+ resolved = Profiles.resolve(profile)
7
+ executable = resolved.bin(env:)
8
+ installed = resolved.binary_installed?(env:)
9
+ version = nil
10
+ diagnostic = nil
11
+
12
+ if installed
13
+ begin
14
+ version = resolved.check_version!(env:)
15
+ rescue Error => e
16
+ diagnostic = Redactor.diagnostic(e)
17
+ end
18
+ else
19
+ diagnostic = Redactor.diagnostic(
20
+ "#{resolved.name} binary not runnable: #{executable}"
21
+ )
22
+ end
23
+
24
+ auth =
25
+ if installed
26
+ resolved.auth_configuration(home: home, env: env)
27
+ else
28
+ AuthConfiguration.new(status: :not_checked)
29
+ end
30
+ diagnostic ||= auth.diagnostic
31
+ ready = installed &&
32
+ !version.nil? &&
33
+ auth.status != :missing
34
+
35
+ ProbeResult.new(
36
+ provider: resolved.name,
37
+ ready: ready,
38
+ installed: installed,
39
+ executable: executable,
40
+ version: version,
41
+ minimum_version: resolved.min_version,
42
+ auth_configuration: auth,
43
+ capability_evidence: capability_evidence(
44
+ resolved, installed: installed, version: version, auth: auth
45
+ ),
46
+ diagnostic: diagnostic
47
+ )
48
+ rescue StandardError => e
49
+ resolved ||= Profiles.resolve(profile)
50
+ ProbeResult.new(
51
+ provider: resolved.name,
52
+ ready: false,
53
+ installed: false,
54
+ executable: resolved.bin(env:),
55
+ version: nil,
56
+ minimum_version: resolved.min_version,
57
+ auth_configuration: AuthConfiguration.new(status: :not_checked),
58
+ capability_evidence: [],
59
+ diagnostic: Redactor.diagnostic(e)
60
+ )
61
+ end
62
+
63
+ def all(home: nil, env: ENV)
64
+ Profiles.names.map do |provider|
65
+ call(provider, home: home, env: env)
66
+ end.freeze
67
+ end
68
+
69
+ def capability_evidence(profile, installed:, version:, auth:)
70
+ declared = profile.declared_capability_support
71
+ capabilities = {
72
+ headless: declared.fetch(:headless),
73
+ version: !version.nil?,
74
+ auth_configuration: auth.status != :missing
75
+ }
76
+ declared.each do |capability, supported|
77
+ capabilities[capability] = supported unless capability == :headless
78
+ end
79
+ capabilities[:installation] = installed
80
+ capabilities.map do |capability, supported|
81
+ CapabilityEvidence.new(
82
+ capability: capability,
83
+ supported: supported,
84
+ provider: profile.name,
85
+ launcher_identity: profile.launcher_identity
86
+ )
87
+ end.freeze
88
+ end
89
+ private_class_method :capability_evidence
90
+ end
91
+ end