kairos-chain 3.101.0 → 3.102.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a16d51cad2a913a4f5914035e68a301959234a5af6f0e16175caa51bcb3b436a
4
- data.tar.gz: 816b44086375fa9a8f8d6eb3b2c5944f8e91edaeef4dc39b4fbf25c87c29ea23
3
+ metadata.gz: f92cefb68006ad142c4c25bf42b56118408706706c594dd277fbcc011166b355
4
+ data.tar.gz: 874c9a039bcefa99c681edef56738e078977df4db5db6def05b1594cebe32106
5
5
  SHA512:
6
- metadata.gz: 1842916505079de71ad956939b30acacf989c008b62654947d05dff6baf4260d94677e51c2cf332c40d4e317e6886f306644a0fc84125ec0188c9cbfc3cbc1ab
7
- data.tar.gz: a8c4824c8aea908a7d0e6fca7131440e888dc767cdbfb4c656157ddc9cd63dbdc5e22d5643d93cb474625bc46e127c1f174e71e1b1c1a25ab89a1dc251d0b727
6
+ metadata.gz: ffa02e574a2d88a867a32bf09924e4d19dccd68eda6a2e7bccd053385f2770b53a1c5e72301fb0f36acb899540aa04df21e0ba964b4c2f3d7b627eac188f2422
7
+ data.tar.gz: 4e99bc88884fa32696047393de4186e29f9d8f6c5a5972307e46a7dad90904458bd63947bbb5f6d335363cac41fb651e3e625fb076926aa8550b4819e5602535
data/CHANGELOG.md CHANGED
@@ -6,6 +6,37 @@ This project follows [Semantic Versioning](https://semver.org/).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [3.102.0] - 2026-11-20
10
+
11
+ ### Added — llm_client 0.5.0: provider `antigravity` (the Antigravity CLI, `agy`)
12
+
13
+ - New llm_client provider `antigravity` (`AntigravityAdapter`) drives `agy`. The prompt goes to stdin
14
+ as one stream-json line, because `agy -p` takes the prompt only as its own argument. The call runs
15
+ under a per-call agent definition whose tool allowlist is empty (the only guard that removes web
16
+ search), with session settings that deny all seven permission actions under strict permission mode,
17
+ and with `--sandbox` and slash commands off. Plan mode is not used: it injects the /plan procedure
18
+ and wrote plan files under `~/.gemini/antigravity-cli/brain/`. Success requires exit 0 and a
19
+ `result` event with status SUCCESS and a non-empty response, since a turn whose tool was auto-denied
20
+ exits 0 with nothing said. On every run, before success is judged, a reply is refused unless the
21
+ session reports this call's agent (a random name per call) and strict permission mode, and every
22
+ tool step's last state is the CLI's own permission refusal (a tool that completed, failed after
23
+ running or never reported an outcome, and any unrecognised step or event, refuse the reply).
24
+ Measured: outside read, shell fetch, web search and a 100 KB prompt. **Not yet measured: the write
25
+ probe.** No `model_observed` is returned: the CLI's init event names a model before any model has
26
+ answered.
27
+ - agy keeps every turn on disk under `~/.gemini/antigravity-cli/` and no setting turns that off, so
28
+ whatever is sent through this provider persists there.
29
+ - **The default multi_llm_review roster is unchanged.** No seat uses this provider unless an
30
+ instance's own config names it.
31
+ - Review state: three multi-LLM review rounds (2026-11-15 to 2026-11-18). The fixes for the round-3
32
+ blocking finding (a tool step left active passed the after-run check) have not been re-reviewed.
33
+ - Not changed: core `Capability::EXTERNAL_BINARIES` does not name `agy`, so the capability manifest
34
+ under-reports this dependency.
35
+ - Upgrade note: `kairos-chain upgrade` overwrites an installed SkillSet whose files differ from the
36
+ gem's, whatever the two versions are (only `config/` is left alone). An instance that carried
37
+ llm_client 0.5.0 ahead of the gem was put back to 0.4.0 by the 3.100.1 and 3.101.0 upgrades; from
38
+ this release the two are equal. The upgrade itself is not changed.
39
+
9
40
  ## [3.101.0] - 2026-11-20
10
41
 
11
42
  ### Added — succession edges on the L2 save path; dream 0.4.0 digests read them, label membership and record checks
@@ -1,4 +1,4 @@
1
1
  module KairosMcp
2
- VERSION = "3.101.0"
2
+ VERSION = "3.102.0"
3
3
  CHANGELOG_URL = "https://github.com/masaomi/KairosChain_2026/blob/main/CHANGELOG.md"
4
4
  end
@@ -0,0 +1,410 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'securerandom'
5
+ require 'tmpdir'
6
+ require 'fileutils'
7
+ require_relative 'adapter'
8
+ require_relative 'safe_subprocess'
9
+ require_relative 'cli_failure'
10
+
11
+ module KairosMcp
12
+ module SkillSets
13
+ module LlmClient
14
+ # Adapter that uses the Antigravity CLI (`agy`) as the LLM backend.
15
+ # Uses the CLI's own login state under ~/.gemini/antigravity-cli/; HOME is
16
+ # preserved so that state is reachable.
17
+ #
18
+ # Transport (measured 2026-11-15, agy 1.5.9; re-measured 2026-11-18, 1.5.10):
19
+ # - `agy -p` takes the prompt only as the flag's value. `-p -` sends the
20
+ # literal "-" as the prompt, and an empty value is refused. A review
21
+ # prompt on argv would be bounded by ARG_MAX and visible in ps, so it
22
+ # is not used.
23
+ # - `--input-format stream-json` reads NDJSON from stdin, one line per
24
+ # turn, shaped {"event":"user","message":{"content":"..."}}. It
25
+ # requires `--output-format stream-json` and refuses -p beside it.
26
+ # A 103,620-byte prompt went through on one line (2026-11-18).
27
+ # - Output is NDJSON: an `init` event, then `step_update` events (each
28
+ # with a step_type; tool steps carry tool_name and a state), then one
29
+ # `result` event carrying status, response and usage.
30
+ # - A turn whose tool needed permission can end with exit 0 and an empty
31
+ # response, so exit status alone cannot mean success. Success here is
32
+ # exit 0, a `result` with status SUCCESS and a non-empty response, and
33
+ # no tool step that completed.
34
+ #
35
+ # Confinement. A review seat only answers; it needs no tool. `agy` is an
36
+ # agent with file, shell, web-search, browser and scheduling tools, and
37
+ # each guard below closes a path the others leave open (measured
38
+ # 2026-11-18, log/mlr_agy_gemini_seat_20261115/r2_probes/):
39
+ # - A per-call agent definition in the per-call workspace,
40
+ # `.agents/agents/kairos_review_seat_<random>.md`, with an empty
41
+ # `tools` allowlist, selected with `--agent`. This is the only guard
42
+ # that removes `search_web`: deny rules, including `*`, do not reach
43
+ # it, and toolPermission "strict" does not stop it in headless mode.
44
+ # Under the agent the model reports no web, file or shell tool; one
45
+ # tool, `manage_task`, is still declared to it. The name is random per
46
+ # call so no agent of the same name elsewhere (for example under
47
+ # ~/.gemini/config/agents/) can stand in for it.
48
+ # - `--settings` (one session, never saved): deny rules on all seven
49
+ # permission actions, toolPermission "strict", no non-workspace
50
+ # access, the terminal sandbox on, slash commands off, agentMode ""
51
+ # rather than "plan". A read outside the workspace and a shell fetch
52
+ # were both refused by the deny rules.
53
+ # - `--mode plan` is NOT used. It injects the /plan procedure, and on
54
+ # 2026-11-15 plan-mode sessions wrote plan files under
55
+ # ~/.gemini/antigravity-cli/brain/. Plan mode is not read-only.
56
+ # - Fail closed on what the session reports, on every run, before the
57
+ # run is judged a success or a failure: the init event must name this
58
+ # call's agent (when the definition is not loaded, init carries no
59
+ # agent) and permission mode "strict" (this shows toolPermission is in
60
+ # effect; the CLI does not report the deny list). Every step must be
61
+ # user input, a model response, or a tool step whose last reported
62
+ # state ended in ERROR with the CLI's permission refusal (matched
63
+ # against the whole message). Anything else (a tool that completed,
64
+ # ran and then failed, or never reported an outcome; an unrecognised
65
+ # state, step type or event) refuses the reply. A run that failed
66
+ # before any init event is an ordinary failure, not a breach. The
67
+ # write probe has not been run. The check
68
+ # happens after the run, so it cannot undo what a tool did; it makes
69
+ # sure such a run is never counted as a confined review. On a timeout
70
+ # the CLI's output is not returned to the adapter, so a breach there
71
+ # cannot be seen.
72
+ #
73
+ # Not confined: agy keeps every turn on disk under
74
+ # ~/.gemini/antigravity-cli/ (brain/<id>/.system_generated/, including
75
+ # logs/ and steps/, conversations/, conversation_summaries.db). No
76
+ # setting turns this off, so an artifact reviewed through this seat
77
+ # persists there; the response carries the CLI's conversation_id so the
78
+ # copy can be found. The operator's own agy configuration outside the
79
+ # per-call workspace (global MCP servers, plugins, hooks, skills under
80
+ # ~/.gemini/config/) is not read by this adapter and not overridden by it
81
+ # beyond the guards above; whether a configured MCP server is started
82
+ # (its calls are denied) and whether hooks fire is not measured.
83
+ #
84
+ # Model attribution: the init event names a model before the model has
85
+ # answered (it appears on runs that fail with zero turns), so it is not
86
+ # evidence of who answered and is not returned as model_observed. (agy's
87
+ # own transcript does record the generating model per response step;
88
+ # under the agent it read gemini-4-hydrogen-high on 2026-11-18. That
89
+ # store is the CLI's private format and is not read here.)
90
+ #
91
+ # Effort is part of the model id (e.g. gemini-4-hydrogen-high), so no
92
+ # effort flag is built; a configured effort would be recorded and never
93
+ # sent, which is why roster entries for this provider carry none.
94
+ class AntigravityAdapter < Adapter
95
+ DEFAULT_TIMEOUT = 180
96
+ BINARY = 'agy'
97
+ AGENT_PREFIX = 'kairos_review_seat'
98
+
99
+ DENY_RULES = %w[
100
+ read_file(*) write_file(*) read_url(*) execute_url(*)
101
+ command(*) mcp(*) unsandboxed(*)
102
+ ].freeze
103
+
104
+ SESSION_SETTINGS = {
105
+ 'agentMode' => '',
106
+ 'toolPermission' => 'strict',
107
+ 'allowNonWorkspaceAccess' => false,
108
+ 'enableTerminalSandbox' => true,
109
+ 'disableSlashCommands' => true,
110
+ 'permissions' => { 'deny' => DENY_RULES }
111
+ }.freeze
112
+
113
+ BASE_ARGS = [
114
+ BINARY, '--sandbox', '--disable-slash-commands',
115
+ '--settings', JSON.generate(SESSION_SETTINGS),
116
+ '--input-format', 'stream-json', '--output-format', 'stream-json'
117
+ ].freeze
118
+
119
+ # Shapes that are not a breach. Events: init, step_update, result.
120
+ # Steps: user input, a model response, or a tool step whose LAST
121
+ # reported state (per step_index) is ERROR with the CLI's own permission
122
+ # refusal, matched against the whole message in the shape measured on
123
+ # 2026-11-18:
124
+ # permission check failed for read_file "<path>": Permission denied
125
+ # for read_file(<path>). Matches user-configured deny rule.
126
+ # A tool step that never reports an outcome is a breach too.
127
+ ALLOWED_EVENTS = %w[init step_update result].freeze
128
+ ALLOWED_STEP_TYPES = %w[user_input agent_response].freeze
129
+ REFUSAL_RE = /\Apermission check failed for \S+ ".*": Permission denied for \S+\(.*\)\. Matches user-configured deny rule\.\z/m
130
+
131
+ def self.agent_definition(name)
132
+ <<~MD
133
+ ---
134
+ name: #{name}
135
+ description: Answers the message in a single reply, without tools.
136
+ tools: []
137
+ mainAgent: true
138
+ subagent: false
139
+ model: inherit
140
+ commandExecutionPolicy: "off"
141
+ ---
142
+ Answer the user's message directly, in a single reply. You have no tools.
143
+ MD
144
+ end
145
+
146
+ # Status codes count only where the text says they are a status: a
147
+ # bare "500" also matches "500 tokens".
148
+ TRANSIENT_PATTERNS = [
149
+ /unavailable/i, /overloaded/i, /temporar/i, /rate.?limit/i,
150
+ /resource.?exhausted/i,
151
+ /\b(?:http|status|code|error)\s*[:=]?\s*(?:429|500|502|503|504)\b/i
152
+ ].freeze
153
+
154
+ def call(messages:, system: nil, tools: nil, model: nil,
155
+ max_tokens: nil, temperature: nil, output_schema: nil)
156
+ prompt = build_prompt(messages, system, tools, output_schema)
157
+ timeout_seconds = @config&.dig('timeout_seconds') || DEFAULT_TIMEOUT
158
+
159
+ agent = "#{AGENT_PREFIX}_#{SecureRandom.hex(6)}"
160
+ args = BASE_ARGS + ['--agent', agent]
161
+ args << '--model' << model.to_s if model && !model.to_s.strip.empty?
162
+
163
+ stdin_line = JSON.generate({ 'event' => 'user', 'message' => { 'content' => prompt } }) + "\n"
164
+
165
+ workdir = Dir.mktmpdir('kairos_agy_')
166
+ stdout, stderr, status = begin
167
+ write_agent_definition(workdir, agent)
168
+ SafeSubprocess.safe_capture(
169
+ args,
170
+ stdin_data: stdin_line,
171
+ timeout_seconds: timeout_seconds,
172
+ env: {},
173
+ dispatch_id: @config&.dig('dispatch_id'),
174
+ chdir: workdir
175
+ )
176
+ ensure
177
+ FileUtils.remove_entry(workdir, true)
178
+ end
179
+
180
+ events = parse_events(stdout)
181
+ result = events.reverse.find { |e| e['event'] == 'result' }&.dig('result')
182
+ ok = status&.success? && result && result['status'] == 'SUCCESS' &&
183
+ !result['response'].to_s.strip.empty?
184
+
185
+ # Confinement first, on every run that reached the session: a breach
186
+ # on a run that also failed must not read as an ordinary (possibly
187
+ # retryable) failure. A run that failed before any init event (CLI
188
+ # not started, unknown agent, login) has no session to judge and is
189
+ # an ordinary failure.
190
+ started = events.any? { |e| e['event'] == 'init' }
191
+ breach = started || ok ? confinement_breach(events, agent) : nil
192
+ if breach
193
+ also = ok ? '' : " (the run also failed: #{failure_detail(result, stderr, status)[0..200]})"
194
+ raise ApiError.new(
195
+ "agy seat not confined: #{breach}#{also}", provider: 'antigravity', retryable: false
196
+ )
197
+ end
198
+
199
+ unless ok
200
+ detail = failure_detail(result, stderr, status)
201
+ raise ApiError.new(
202
+ "agy exited with status #{status&.exitstatus.inspect}: #{detail[0..300]}",
203
+ provider: 'antigravity',
204
+ retryable: TRANSIENT_PATTERNS.any? { |re| re.match?(detail) }
205
+ )
206
+ end
207
+
208
+ build_response(result, tools, model)
209
+ rescue Timeout::Error
210
+ raise ApiError.new(
211
+ "agy timed out after #{timeout_seconds}s",
212
+ provider: 'antigravity', retryable: true, code: CliFailure::CLI_TIMEOUT
213
+ )
214
+ rescue Errno::ENOENT
215
+ raise ApiError.new(
216
+ 'agy CLI not found. Install the Antigravity CLI.',
217
+ provider: 'antigravity', retryable: false, code: CliFailure.missing_code(BINARY)
218
+ )
219
+ rescue ApiError
220
+ raise
221
+ rescue StandardError => e
222
+ raise ApiError.new("agy error: #{e.message}", provider: 'antigravity')
223
+ end
224
+
225
+ private
226
+
227
+ def write_agent_definition(workdir, name)
228
+ dir = File.join(workdir, '.agents', 'agents')
229
+ FileUtils.mkdir_p(dir)
230
+ File.write(File.join(dir, "#{name}.md"), self.class.agent_definition(name))
231
+ end
232
+
233
+ # What the session itself reports. Returns a description of the first
234
+ # breach, or nil. Allow-list shaped: anything not recognised as safe is
235
+ # a breach.
236
+ def confinement_breach(events, agent)
237
+ init = events.find { |e| e['event'] == 'init' }&.dig('init')
238
+ return 'no init event' unless init.is_a?(Hash)
239
+
240
+ loaded = init['agent']
241
+ unless loaded == agent
242
+ return "agent #{loaded.inspect}, not this call's #{agent} (tool allowlist not in effect)"
243
+ end
244
+
245
+ mode = init['permission_mode'].to_s
246
+ return "permission mode #{mode.inspect}, not \"strict\"" unless mode == 'strict'
247
+
248
+ last = {}
249
+ events.each_with_index do |e, i|
250
+ kind = e['event'].to_s
251
+ return "unrecognised event #{kind.inspect}" unless ALLOWED_EVENTS.include?(kind)
252
+ next unless kind == 'step_update'
253
+
254
+ s = e['step_update']
255
+ return 'malformed step_update' unless s.is_a?(Hash)
256
+
257
+ type = s['step_type'].to_s
258
+ next if ALLOWED_STEP_TYPES.include?(type)
259
+ return "unrecognised step type #{type.inspect}" unless type == 'tool'
260
+
261
+ name = s['tool_name'] || s.dig('tool_info', 'name') || 'unnamed tool'
262
+ state = s['state'].to_s
263
+ next last[s['step_index'] || "anon#{i}"] = [name, s] if state == 'ACTIVE'
264
+ next last[s['step_index'] || "anon#{i}"] = [name, s] if state == 'ERROR' && refused?(s)
265
+
266
+ return "tool #{name} reached #{state.empty? ? '(no state)' : state}"
267
+ end
268
+ open = last.values.find { |_name, s| s['state'] == 'ACTIVE' }
269
+ open ? "tool #{open[0]} never reported an outcome" : nil
270
+ end
271
+
272
+ def refused?(step)
273
+ REFUSAL_RE.match?(step.dig('tool_info', 'error', 'message').to_s)
274
+ end
275
+
276
+ def build_prompt(messages, system, tools, output_schema = nil)
277
+ parts = []
278
+
279
+ if system
280
+ parts << "[System]: #{system}"
281
+ parts << ''
282
+ end
283
+
284
+ if tools && !tools.empty?
285
+ parts << '[Available tools - respond with JSON when you want to use a tool]:'
286
+ tools.each do |t|
287
+ name = t[:name] || t['name']
288
+ desc = t[:description] || t['description']
289
+ schema = t[:input_schema] || t['input_schema'] || t[:inputSchema] || t['inputSchema']
290
+ parts << "- #{name}: #{desc}"
291
+ if schema.is_a?(Hash) && schema['properties']
292
+ parts << " Parameters: #{schema['properties'].keys.join(', ')}"
293
+ end
294
+ end
295
+ parts << ''
296
+ parts << 'To use a tool, include in your response:'
297
+ parts << '```json'
298
+ parts << '{"tool_use": [{"name": "tool_name", "input": {"param": "value"}}]}'
299
+ parts << '```'
300
+ parts << ''
301
+ end
302
+
303
+ if output_schema
304
+ qualifier = tools && !tools.empty? ? 'When you are NOT using a tool, respond' : 'Respond'
305
+ parts << "[Output Format]: #{qualifier} with ONLY valid JSON (no markdown fences) matching this schema:"
306
+ parts << JSON.generate(output_schema)
307
+ parts << ''
308
+ end
309
+
310
+ messages.each do |msg|
311
+ role = msg['role'] || msg[:role]
312
+ content = msg['content'] || msg[:content]
313
+ case role
314
+ when 'user'
315
+ parts << content.to_s
316
+ when 'assistant'
317
+ parts << "[Previous assistant response]: #{content}"
318
+ when 'tool'
319
+ tool_id = msg['tool_use_id'] || msg[:tool_use_id] || 'unknown'
320
+ parts << "[Tool result for #{tool_id}]: #{content}"
321
+ end
322
+ end
323
+
324
+ prompt = parts.join("\n")
325
+ prompt.lstrip.start_with?('/') ? "[Request]:\n#{prompt}" : prompt
326
+ end
327
+
328
+ # One JSON object per line; lines that are not JSON objects are skipped
329
+ # so a stray warning on stdout cannot hide the result event.
330
+ def parse_events(stdout)
331
+ strip_ansi(stdout).each_line.filter_map do |line|
332
+ line = line.strip
333
+ next if line.empty?
334
+
335
+ obj = JSON.parse(line)
336
+ obj.is_a?(Hash) ? obj : nil
337
+ rescue JSON::ParserError
338
+ nil
339
+ end
340
+ end
341
+
342
+ # Everything the CLI said about the failure, each part naming the
343
+ # condition it actually observed: the missing or failed result, an
344
+ # empty reply, a non-zero exit beside a good result, and stderr (where
345
+ # agy explains an auto-denied tool). Joined so no part hides another.
346
+ def failure_detail(result, stderr, status)
347
+ parts = []
348
+ if result.nil?
349
+ parts << 'no result event'
350
+ else
351
+ st = result['status'].to_s.strip
352
+ parts << "result status #{st.empty? ? '(none)' : st}" unless st == 'SUCCESS'
353
+ parts << result['error'].to_s.strip
354
+ parts << 'empty response' if result['response'].to_s.strip.empty?
355
+ if st == 'SUCCESS' && !result['response'].to_s.strip.empty? && !status&.success?
356
+ parts << (status&.exitstatus.nil? ? 'result SUCCESS but the process ended without an exit status' : 'result SUCCESS but the process exited non-zero')
357
+ end
358
+ end
359
+ err = strip_ansi(stderr).strip
360
+ parts << (err.empty? ? 'stderr empty' : err)
361
+ parts.reject(&:empty?).join(' | ')
362
+ end
363
+
364
+ def build_response(result, tools, model)
365
+ text = result['response'].to_s
366
+ # Only a caller that offered tools asked for tool calls. Without
367
+ # tools, a JSON tool_use sample inside a review is part of the review.
368
+ tool_use = tools && !tools.empty? ? extract_tool_use(text) : nil
369
+ usage = result['usage'].is_a?(Hash) ? result['usage'] : {}
370
+
371
+ {
372
+ 'content' => tool_use ? nil : text,
373
+ 'tool_use' => tool_use,
374
+ 'stop_reason' => tool_use ? 'tool_use' : 'end_turn',
375
+ 'model' => model || 'agy-cli-default',
376
+ 'input_tokens' => usage['input_tokens'],
377
+ 'output_tokens' => usage['output_tokens'],
378
+ # Where agy keeps its own copy of this turn (see header).
379
+ 'conversation_id' => result['conversation_id']
380
+ }
381
+ end
382
+
383
+ def extract_tool_use(text)
384
+ json_match = text.match(/```json\s*\n?(.*?)\n?\s*```/m) ||
385
+ text.match(/\{[^{}]*"tool_use"\s*:[^{}]*\}/m)
386
+ return nil unless json_match
387
+
388
+ parsed = JSON.parse(json_match[1] || json_match[0])
389
+ return nil unless parsed.is_a?(Hash) && parsed['tool_use'].is_a?(Array)
390
+
391
+ parsed['tool_use'].map do |tu|
392
+ {
393
+ 'id' => "ag_#{SecureRandom.hex(4)}",
394
+ 'name' => tu['name'],
395
+ 'input' => tu['input'] || {}
396
+ }
397
+ end
398
+ rescue JSON::ParserError
399
+ nil
400
+ end
401
+
402
+ def strip_ansi(s)
403
+ return '' if s.nil?
404
+
405
+ s.gsub(/\e\[[0-9;]*[A-Za-z]/, '')
406
+ end
407
+ end
408
+ end
409
+ end
410
+ end
@@ -25,6 +25,7 @@ module KairosMcp
25
25
  'openai' => 'OPENAI_API_KEY',
26
26
  'codex' => nil,
27
27
  'cursor' => nil,
28
+ 'antigravity' => nil,
28
29
  'claude_code' => nil,
29
30
  'bedrock' => nil,
30
31
  'local' => nil,
@@ -164,6 +165,9 @@ module KairosMcp
164
165
  when 'cursor'
165
166
  require_relative 'cursor_adapter'
166
167
  CursorAdapter.new(config)
168
+ when 'antigravity'
169
+ require_relative 'antigravity_adapter'
170
+ AntigravityAdapter.new(config)
167
171
  when 'bedrock'
168
172
  require_relative 'bedrock_adapter'
169
173
  BedrockAdapter.new(config)
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "llm_client",
3
- "version": "0.4.0",
4
- "description": "Pure LLM provider abstraction. One API call, returns response. No loop, no retry, no fallback.",
3
+ "version": "0.5.0",
4
+ "description": "Pure LLM provider abstraction. One API call, returns response. No loop, no retry, no fallback. v0.5.0 (2026-11-15): provider `antigravity` drives the Antigravity CLI (`agy`), prompt on stdin as stream-json, in a per-call directory holding only an agent definition (random name per call) with an empty tool allowlist; session settings deny every permission action under strict permission mode, plan mode is not used (it writes plan files), and a reply is refused unless the session reports that agent and strict mode and every tool step ends in the CLI's own permission refusal. The write probe has not been run. No model_observed is returned: the CLI's init event names a model before any model answers. agy keeps every turn on disk under ~/.gemini/antigravity-cli/.",
5
5
  "author": "Masaomi Hatakeyama",
6
6
  "layer": "L1",
7
7
  "depends_on": [],
@@ -0,0 +1,558 @@
1
+ # frozen_string_literal: true
2
+ # antigravity_adapter: `agy` stream-json transport (2026-11-15, confinement
3
+ # revised 2026-11-18). Every case drives AntigravityAdapter#call with
4
+ # SafeSubprocess.safe_capture stubbed, so no CLI runs and no model is called.
5
+
6
+ require 'minitest/autorun'
7
+ require 'json'
8
+ require 'timeout'
9
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __dir__)
10
+ require_relative '../lib/llm_client/adapter'
11
+ require_relative '../lib/llm_client/antigravity_adapter'
12
+
13
+ module KairosMcp
14
+ module SkillSets
15
+ module LlmClient
16
+ class TestAntigravityAdapter < Minitest::Test
17
+ Status = Struct.new(:success?, :exitstatus)
18
+
19
+ INIT = { 'event' => 'init',
20
+ 'init' => { 'model' => 'gemini-4-hydrogen-high', 'cwd' => '/tmp/x',
21
+ 'permission_mode' => 'strict', 'agent' => '__AGENT__' } }.freeze
22
+
23
+ def result_line(status: 'SUCCESS', response: "VERDICT: APPROVE\n", error: nil)
24
+ r = { 'status' => status, 'response' => response,
25
+ 'usage' => { 'input_tokens' => 11, 'output_tokens' => 7 } }
26
+ r['error'] = error if error
27
+ JSON.generate({ 'event' => 'result', 'result' => r })
28
+ end
29
+
30
+ def tool_step(name, state, error: nil, index: 2)
31
+ step = { 'step_index' => index, 'step_type' => 'tool', 'tool_name' => name, 'state' => state }
32
+ step['tool_info'] = { 'name' => name, 'error' => { 'type' => 'TOOL_ERROR', 'message' => error } } if error
33
+ { 'event' => 'step_update', 'step_update' => step }
34
+ end
35
+
36
+ REFUSED = 'permission check failed for read_file "/x": Permission denied for read_file(/x). Matches user-configured deny rule.'
37
+
38
+ def response_step
39
+ { 'event' => 'step_update', 'step_update' => { 'step_type' => 'agent_response', 'state' => 'DONE' } }
40
+ end
41
+
42
+ def agent_of(args)
43
+ args[args.index('--agent') + 1]
44
+ end
45
+
46
+ def stdout_of(*lines)
47
+ lines.map { |l| l.is_a?(String) ? l : JSON.generate(l) }.join("\n") + "\n"
48
+ end
49
+
50
+ def setup
51
+ @adapter = AntigravityAdapter.new({ 'timeout_seconds' => 30 })
52
+ @calls = []
53
+ end
54
+
55
+ # Records, at the moment of the call, what the per-call directory held
56
+ # and the agent definition's text, so the tests see what agy would see.
57
+ def with_capture(stdout: '', stderr: '', status: Status.new(true, 0), raise_error: nil)
58
+ calls = @calls
59
+ SafeSubprocess.singleton_class.send(:alias_method, :_orig_safe_capture, :safe_capture)
60
+ SafeSubprocess.singleton_class.send(:define_method, :safe_capture) do |args, **kw|
61
+ dir = kw[:chdir]
62
+ name = args[args.index('--agent') + 1]
63
+ agent = File.join(dir, '.agents', 'agents', "#{name}.md")
64
+ calls << { args: args, kw: kw, agent: name,
65
+ files: Dir.glob('**/*', File::FNM_DOTMATCH, base: dir).reject { |f| f.end_with?('.') || File.directory?(File.join(dir, f)) },
66
+ agent_text: File.exist?(agent) ? File.read(agent) : nil }
67
+ raise raise_error if raise_error
68
+
69
+ [stdout.gsub('__AGENT__', name), stderr, status]
70
+ end
71
+ yield
72
+ ensure
73
+ SafeSubprocess.singleton_class.send(:remove_method, :safe_capture)
74
+ SafeSubprocess.singleton_class.send(:alias_method, :safe_capture, :_orig_safe_capture)
75
+ SafeSubprocess.singleton_class.send(:remove_method, :_orig_safe_capture)
76
+ end
77
+
78
+ def msg(text)
79
+ [{ 'role' => 'user', 'content' => text }]
80
+ end
81
+
82
+ def settings_of(args)
83
+ JSON.parse(args[args.index('--settings') + 1])
84
+ end
85
+
86
+ # --- confinement as built ---------------------------------------------
87
+
88
+ def test_never_runs_plan_mode
89
+ with_capture(stdout: stdout_of(INIT, result_line)) do
90
+ @adapter.call(messages: msg('review this'), model: 'gemini-4-hydrogen-high')
91
+ end
92
+ args = @calls.first[:args]
93
+ refute_includes args, '--mode', 'plan mode writes plan files; it is not read-only'
94
+ refute_includes args, 'plan'
95
+ assert_equal '', settings_of(args)['agentMode']
96
+ end
97
+
98
+ def test_settings_deny_every_permission_action_under_strict
99
+ with_capture(stdout: stdout_of(INIT, result_line)) do
100
+ @adapter.call(messages: msg('hi'), model: 'm')
101
+ end
102
+ s = settings_of(@calls.first[:args])
103
+ assert_equal 'strict', s['toolPermission']
104
+ assert_equal false, s['allowNonWorkspaceAccess']
105
+ assert_equal true, s['enableTerminalSandbox']
106
+ assert_equal true, s['disableSlashCommands']
107
+ refute s.key?('artifactReviewPolicy'), 'no loosening setting is passed'
108
+ %w[read_file write_file read_url execute_url command mcp unsandboxed].each do |action|
109
+ assert_includes s.dig('permissions', 'deny'), "#{action}(*)"
110
+ end
111
+ end
112
+
113
+ def test_flags_sandbox_slash_commands_agent_stream_and_model
114
+ with_capture(stdout: stdout_of(INIT, result_line)) do
115
+ @adapter.call(messages: msg('hi'), model: 'gemini-4-hydrogen-high')
116
+ end
117
+ args = @calls.first[:args]
118
+ assert_equal ['--agent', agent_of(args), '--model', 'gemini-4-hydrogen-high'], args.last(4)
119
+ assert_match(/\Akairos_review_seat_[0-9a-f]{12}\z/, agent_of(args))
120
+ assert_includes args, '--sandbox'
121
+ assert_includes args, '--disable-slash-commands'
122
+ refute_includes args, '-p'
123
+ end
124
+
125
+ def test_nil_model_omits_flag
126
+ with_capture(stdout: stdout_of(INIT, result_line)) do
127
+ @adapter.call(messages: msg('hi'), model: nil)
128
+ end
129
+ args = @calls.first[:args]
130
+ refute_includes args, '--model'
131
+ assert_equal ['--agent', agent_of(args)], args.last(2)
132
+ end
133
+
134
+ def test_the_per_call_directory_holds_only_the_agent_with_no_tools_and_is_removed
135
+ with_capture(stdout: stdout_of(INIT, result_line)) do
136
+ @adapter.call(messages: msg('hi'), model: 'm')
137
+ end
138
+ call = @calls.first
139
+ assert_equal [".agents/agents/#{call[:agent]}.md"], call[:files]
140
+ front = call[:agent_text].split(/^---\s*$/)[1]
141
+ require 'yaml'
142
+ fm = YAML.safe_load(front)
143
+ assert_equal call[:agent], fm['name']
144
+ assert_equal [], fm['tools'], 'an empty allowlist is the only guard that removes search_web'
145
+ assert_equal true, fm['mainAgent']
146
+ assert_equal 'off', fm['commandExecutionPolicy']
147
+ refute Dir.exist?(call[:kw][:chdir]), 'the per-call directory is removed afterwards'
148
+ end
149
+
150
+ def test_the_per_call_directory_is_removed_on_timeout_too
151
+ assert_raises(ApiError) do
152
+ with_capture(raise_error: Timeout::Error.new('slow')) do
153
+ @adapter.call(messages: msg('hi'), model: 'm')
154
+ end
155
+ end
156
+ refute Dir.exist?(@calls.first[:kw][:chdir])
157
+ end
158
+
159
+ # --- fail closed on what the session reports -----------------------------
160
+
161
+ def test_the_agent_name_is_unique_per_call
162
+ with_capture(stdout: stdout_of(INIT, result_line)) do
163
+ 2.times { @adapter.call(messages: msg('hi'), model: 'm') }
164
+ end
165
+ refute_equal @calls[0][:agent], @calls[1][:agent]
166
+ end
167
+
168
+ # Measured: init carries `agent` only when the definition was loaded.
169
+ def test_a_session_without_the_agent_is_refused
170
+ init = { 'event' => 'init', 'init' => { 'model' => 'm', 'permission_mode' => 'strict' } }
171
+ err = assert_raises(ApiError) do
172
+ with_capture(stdout: stdout_of(init, result_line)) do
173
+ @adapter.call(messages: msg('hi'), model: 'm')
174
+ end
175
+ end
176
+ assert_includes err.message, 'tool allowlist not in effect'
177
+ refute err.retryable
178
+ end
179
+
180
+ def test_a_session_under_another_agent_is_refused
181
+ init = { 'event' => 'init', 'init' => { 'model' => 'm', 'permission_mode' => 'strict',
182
+ 'agent' => 'kairos_review_seat' } }
183
+ err = assert_raises(ApiError) do
184
+ with_capture(stdout: stdout_of(init, result_line)) do
185
+ @adapter.call(messages: msg('hi'), model: 'm')
186
+ end
187
+ end
188
+ assert_includes err.message, 'not this call'
189
+ end
190
+
191
+ def test_permission_mode_other_than_strict_is_refused
192
+ init = { 'event' => 'init', 'init' => { 'model' => 'm', 'permission_mode' => 'request-review',
193
+ 'agent' => '__AGENT__' } }
194
+ err = assert_raises(ApiError) do
195
+ with_capture(stdout: stdout_of(init, result_line)) do
196
+ @adapter.call(messages: msg('hi'), model: 'm')
197
+ end
198
+ end
199
+ assert_includes err.message, 'not confined'
200
+ assert_includes err.message, 'request-review'
201
+ refute err.retryable
202
+ end
203
+
204
+ def test_missing_init_is_refused
205
+ err = assert_raises(ApiError) do
206
+ with_capture(stdout: stdout_of(result_line)) do
207
+ @adapter.call(messages: msg('hi'), model: 'm')
208
+ end
209
+ end
210
+ assert_includes err.message, 'no init event'
211
+ end
212
+
213
+ def test_a_tool_that_ran_refuses_the_reply
214
+ err = assert_raises(ApiError) do
215
+ with_capture(stdout: stdout_of(INIT, tool_step('search_web', 'ACTIVE'),
216
+ tool_step('search_web', 'DONE'), result_line)) do
217
+ @adapter.call(messages: msg('hi'), model: 'm')
218
+ end
219
+ end
220
+ assert_includes err.message, 'tool search_web reached DONE'
221
+ refute err.retryable
222
+ end
223
+
224
+ def test_a_tool_the_cli_refused_is_not_a_failure
225
+ out = nil
226
+ with_capture(stdout: stdout_of(INIT, tool_step('read_file', 'ACTIVE'),
227
+ tool_step('read_file', 'ERROR', error: REFUSED), result_line)) do
228
+ out = @adapter.call(messages: msg('hi'), model: 'm')
229
+ end
230
+ assert_equal "VERDICT: APPROVE\n", out['content']
231
+ end
232
+
233
+ def test_a_tool_that_ran_and_then_failed_is_refused
234
+ err = assert_raises(ApiError) do
235
+ with_capture(stdout: stdout_of(INIT, tool_step('run_command', 'ERROR', error: 'exit status 1'), result_line)) do
236
+ @adapter.call(messages: msg('hi'), model: 'm')
237
+ end
238
+ end
239
+ assert_includes err.message, 'tool run_command reached ERROR'
240
+ end
241
+
242
+ def test_a_tool_in_an_unrecognised_state_is_refused
243
+ err = assert_raises(ApiError) do
244
+ with_capture(stdout: stdout_of(INIT, tool_step('write_to_file', 'COMPLETED'), result_line)) do
245
+ @adapter.call(messages: msg('hi'), model: 'm')
246
+ end
247
+ end
248
+ assert_includes err.message, 'tool write_to_file reached COMPLETED'
249
+ end
250
+
251
+ def test_an_unrecognised_step_type_is_refused
252
+ step = { 'event' => 'step_update', 'step_update' => { 'step_type' => 'subagent', 'state' => 'DONE' } }
253
+ err = assert_raises(ApiError) do
254
+ with_capture(stdout: stdout_of(INIT, step, result_line)) do
255
+ @adapter.call(messages: msg('hi'), model: 'm')
256
+ end
257
+ end
258
+ assert_includes err.message, 'unrecognised step type "subagent"'
259
+ end
260
+
261
+ def test_a_breach_on_a_failed_run_is_reported_as_a_breach
262
+ err = assert_raises(ApiError) do
263
+ with_capture(stdout: stdout_of(INIT, tool_step('search_web', 'DONE'),
264
+ result_line(status: 'ERROR', response: '', error: 'model unavailable'))) do
265
+ @adapter.call(messages: msg('hi'), model: 'm')
266
+ end
267
+ end
268
+ assert_includes err.message, 'not confined'
269
+ assert_includes err.message, 'the run also failed'
270
+ assert_includes err.message, 'model unavailable'
271
+ refute err.retryable, 'a breach is never retried, even when the failure text looks transient'
272
+ end
273
+
274
+ def test_a_tool_step_left_active_is_refused
275
+ err = assert_raises(ApiError) do
276
+ with_capture(stdout: stdout_of(INIT, tool_step('search_web', 'ACTIVE'), result_line)) do
277
+ @adapter.call(messages: msg('hi'), model: 'm')
278
+ end
279
+ end
280
+ assert_includes err.message, 'tool search_web never reported an outcome'
281
+ end
282
+
283
+ def test_refusal_text_inside_another_error_is_not_a_refusal
284
+ [
285
+ 'exit status 1: permission check failed',
286
+ 'search failed for query "Matches user-configured deny rule."',
287
+ "warning: #{REFUSED}"
288
+ ].each do |message|
289
+ err = assert_raises(ApiError, message) do
290
+ with_capture(stdout: stdout_of(INIT, tool_step('run_command', 'ERROR', error: message), result_line)) do
291
+ @adapter.call(messages: msg('hi'), model: 'm')
292
+ end
293
+ end
294
+ assert_includes err.message, 'tool run_command reached ERROR', message
295
+ end
296
+ end
297
+
298
+ def test_an_unrecognised_event_is_refused
299
+ ev = { 'event' => 'subagent_step', 'subagent_step' => { 'tool_name' => 'write_to_file', 'state' => 'DONE' } }
300
+ err = assert_raises(ApiError) do
301
+ with_capture(stdout: stdout_of(INIT, ev, result_line)) do
302
+ @adapter.call(messages: msg('hi'), model: 'm')
303
+ end
304
+ end
305
+ assert_includes err.message, 'unrecognised event "subagent_step"'
306
+ end
307
+
308
+ # Measured 2026-11-18 (missing_agent.ndjson): an unknown agent ends with
309
+ # a result-only stream, ERROR, exit 1 and no init. Nothing ran.
310
+ def test_a_run_that_failed_before_init_is_an_ordinary_failure
311
+ line = JSON.generate({ 'event' => 'result', 'result' => { 'status' => 'ERROR', 'num_turns' => 0 } })
312
+ err = assert_raises(ApiError) do
313
+ with_capture(stdout: stdout_of(line), stderr: 'error: unknown agent "x" (no custom agents are available)',
314
+ status: Status.new(false, 1)) do
315
+ @adapter.call(messages: msg('hi'), model: 'm')
316
+ end
317
+ end
318
+ refute_includes err.message, 'not confined'
319
+ assert_includes err.message, 'unknown agent'
320
+ end
321
+
322
+ def test_a_successful_result_without_init_is_still_refused
323
+ err = assert_raises(ApiError) do
324
+ with_capture(stdout: stdout_of(result_line)) do
325
+ @adapter.call(messages: msg('hi'), model: 'm')
326
+ end
327
+ end
328
+ assert_includes err.message, 'no init event'
329
+ end
330
+
331
+ # --- prompt transport ---------------------------------------------------
332
+
333
+ def test_prompt_goes_to_stdin_as_one_user_event_line
334
+ with_capture(stdout: stdout_of(INIT, result_line)) do
335
+ @adapter.call(messages: msg("line one\nline two"), system: 'be strict', model: 'm')
336
+ end
337
+ stdin = @calls.first[:kw][:stdin_data]
338
+ assert_equal 1, stdin.lines.size
339
+ event = JSON.parse(stdin)
340
+ assert_equal 'user', event['event']
341
+ assert_equal "[System]: be strict\n\nline one\nline two", event.dig('message', 'content')
342
+ end
343
+
344
+ def test_a_100k_prompt_stays_one_line
345
+ big = "word " * 20_000
346
+ with_capture(stdout: stdout_of(INIT, result_line)) do
347
+ @adapter.call(messages: msg(big), model: 'm')
348
+ end
349
+ stdin = @calls.first[:kw][:stdin_data]
350
+ assert_operator stdin.bytesize, :>, 100_000
351
+ assert_equal 1, stdin.lines.size
352
+ end
353
+
354
+ def test_prompt_opening_with_slash_is_tagged
355
+ with_capture(stdout: stdout_of(INIT, result_line)) do
356
+ @adapter.call(messages: msg('/help me'), model: 'm')
357
+ end
358
+ content = JSON.parse(@calls.first[:kw][:stdin_data]).dig('message', 'content')
359
+ refute content.lstrip.start_with?('/')
360
+ assert content.end_with?('/help me')
361
+ end
362
+
363
+ # --- the reply ----------------------------------------------------------
364
+
365
+ def test_success_returns_response_usage_and_no_observed_model
366
+ out = nil
367
+ with_capture(stdout: stdout_of(INIT, response_step, 'not json', result_line)) do
368
+ out = @adapter.call(messages: msg('hi'), model: 'gemini-4-hydrogen-high')
369
+ end
370
+ assert_equal "VERDICT: APPROVE\n", out['content']
371
+ assert_equal 'gemini-4-hydrogen-high', out['model']
372
+ assert_nil out['model_observed'], 'init names a model before any model answered'
373
+ assert_equal 11, out['input_tokens']
374
+ assert_equal 7, out['output_tokens']
375
+ end
376
+
377
+ def test_the_conversation_id_is_returned
378
+ line = JSON.generate({ 'event' => 'result', 'result' => { 'status' => 'SUCCESS', 'response' => "ok\n",
379
+ 'conversation_id' => 'c0ffee' } })
380
+ out = nil
381
+ with_capture(stdout: stdout_of(INIT, line)) do
382
+ out = @adapter.call(messages: msg('hi'), model: 'm')
383
+ end
384
+ assert_equal 'c0ffee', out['conversation_id']
385
+ end
386
+
387
+ def test_the_last_result_event_is_the_one_read
388
+ out = nil
389
+ with_capture(stdout: stdout_of(INIT, result_line(response: "first\n"), result_line(response: "second\n"))) do
390
+ out = @adapter.call(messages: msg('hi'), model: 'm')
391
+ end
392
+ assert_equal "second\n", out['content']
393
+ end
394
+
395
+ def test_a_tool_use_sample_in_a_review_without_tools_stays_text
396
+ reply = "**Overall Verdict**: REVISE\nP2: the sample ```json\n{\"tool_use\": [{\"name\": \"x\", \"input\": {}}]}\n``` is parsed [location: a:1]\n"
397
+ out = nil
398
+ with_capture(stdout: stdout_of(INIT, result_line(response: reply))) do
399
+ out = @adapter.call(messages: msg('review'), model: 'm')
400
+ end
401
+ assert_equal reply, out['content']
402
+ assert_nil out['tool_use']
403
+ end
404
+
405
+ def test_tool_use_is_read_when_the_caller_offered_tools
406
+ reply = "```json\n{\"tool_use\": [{\"name\": \"lookup\", \"input\": {\"q\": 1}}]}\n```"
407
+ out = nil
408
+ with_capture(stdout: stdout_of(INIT, result_line(response: reply))) do
409
+ out = @adapter.call(messages: msg('go'), model: 'm',
410
+ tools: [{ 'name' => 'lookup', 'description' => 'd' }])
411
+ end
412
+ assert_nil out['content']
413
+ assert_equal 'lookup', out['tool_use'].first['name']
414
+ end
415
+
416
+ # --- failures, each named by what was observed --------------------------
417
+
418
+ def test_exit_zero_with_empty_response_is_an_error_carrying_stderr
419
+ denied = 'jetski: no output produced — a tool required the "command" permission'
420
+ err = assert_raises(ApiError) do
421
+ with_capture(stdout: stdout_of(INIT, result_line(response: '')), stderr: denied) do
422
+ @adapter.call(messages: msg('hi'), model: 'm')
423
+ end
424
+ end
425
+ assert_includes err.message, 'empty response'
426
+ assert_includes err.message, denied
427
+ assert_equal 'antigravity', err.provider
428
+ end
429
+
430
+ def test_whitespace_only_reply_is_an_empty_response
431
+ err = assert_raises(ApiError) do
432
+ with_capture(stdout: stdout_of(INIT, result_line(response: " \n\t\n"))) do
433
+ @adapter.call(messages: msg('hi'), model: 'm')
434
+ end
435
+ end
436
+ assert_includes err.message, 'empty response'
437
+ end
438
+
439
+ def test_error_result_raises_with_its_message
440
+ err = assert_raises(ApiError) do
441
+ with_capture(stdout: stdout_of(INIT, result_line(status: 'ERROR', response: '', error: 'model unavailable')),
442
+ status: Status.new(false, 1)) do
443
+ @adapter.call(messages: msg('hi'), model: 'm')
444
+ end
445
+ end
446
+ assert_includes err.message, 'model unavailable'
447
+ assert_includes err.message, 'result status ERROR'
448
+ assert err.retryable, 'an unavailable model is worth one retry'
449
+ end
450
+
451
+ def test_result_without_status_says_none
452
+ line = JSON.generate({ 'event' => 'result', 'result' => { 'response' => '' } })
453
+ err = assert_raises(ApiError) do
454
+ with_capture(stdout: stdout_of(INIT, line)) do
455
+ @adapter.call(messages: msg('hi'), model: 'm')
456
+ end
457
+ end
458
+ assert_includes err.message, 'result status (none)'
459
+ refute_includes err.message, 'status :'
460
+ end
461
+
462
+ def test_no_result_event_raises
463
+ err = assert_raises(ApiError) do
464
+ with_capture(stdout: stdout_of(INIT), stderr: '') do
465
+ @adapter.call(messages: msg('hi'), model: 'm')
466
+ end
467
+ end
468
+ assert_includes err.message, 'no result event'
469
+ assert_includes err.message, 'stderr empty'
470
+ refute err.retryable
471
+ end
472
+
473
+ def test_nonzero_exit_beside_a_success_result_is_named_as_such
474
+ err = assert_raises(ApiError) do
475
+ with_capture(stdout: stdout_of(INIT, result_line), status: Status.new(false, 2)) do
476
+ @adapter.call(messages: msg('hi'), model: 'm')
477
+ end
478
+ end
479
+ assert_includes err.message, 'result SUCCESS but the process exited non-zero'
480
+ refute_includes err.message, 'no result event'
481
+ end
482
+
483
+ def test_no_exit_status_is_named_as_such
484
+ err = assert_raises(ApiError) do
485
+ with_capture(stdout: stdout_of(INIT, result_line), status: Status.new(false, nil)) do
486
+ @adapter.call(messages: msg('hi'), model: 'm')
487
+ end
488
+ end
489
+ assert_includes err.message, 'ended without an exit status'
490
+ end
491
+
492
+ def test_a_bare_500_in_text_is_not_transient
493
+ err = assert_raises(ApiError) do
494
+ with_capture(stdout: stdout_of(INIT, result_line(status: 'ERROR', response: '', error: 'context used 500 tokens'))) do
495
+ @adapter.call(messages: msg('hi'), model: 'm')
496
+ end
497
+ end
498
+ refute err.retryable
499
+ end
500
+
501
+ def test_an_http_status_503_is_transient
502
+ err = assert_raises(ApiError) do
503
+ with_capture(stdout: stdout_of(INIT, result_line(status: 'ERROR', response: '', error: 'HTTP 503 from backend'))) do
504
+ @adapter.call(messages: msg('hi'), model: 'm')
505
+ end
506
+ end
507
+ assert err.retryable
508
+ end
509
+
510
+ def test_timeout_is_cli_timeout_and_retryable
511
+ err = assert_raises(ApiError) do
512
+ with_capture(raise_error: Timeout::Error.new('slow')) do
513
+ @adapter.call(messages: msg('hi'), model: 'm')
514
+ end
515
+ end
516
+ assert_equal CliFailure::CLI_TIMEOUT, err.code
517
+ assert err.retryable
518
+ end
519
+
520
+ def test_missing_binary_is_cli_missing
521
+ CliFailure.singleton_class.send(:alias_method, :_orig_on_path, :binary_on_path?)
522
+ CliFailure.singleton_class.send(:define_method, :binary_on_path?) { |_b| false }
523
+ err = assert_raises(ApiError) do
524
+ with_capture(raise_error: Errno::ENOENT.new('agy')) do
525
+ @adapter.call(messages: msg('hi'), model: 'm')
526
+ end
527
+ end
528
+ assert_equal CliFailure::CLI_MISSING, err.code
529
+ refute err.retryable
530
+ ensure
531
+ CliFailure.singleton_class.send(:remove_method, :binary_on_path?)
532
+ CliFailure.singleton_class.send(:alias_method, :binary_on_path?, :_orig_on_path)
533
+ CliFailure.singleton_class.send(:remove_method, :_orig_on_path)
534
+ end
535
+
536
+ # --- the two places that build adapters ---------------------------------
537
+
538
+ def test_router_builds_this_adapter_for_the_provider
539
+ require_relative '../lib/llm_client/call_router'
540
+ adapter = CallRouter.build_adapter({ 'provider' => 'antigravity' })
541
+ assert_instance_of AntigravityAdapter, adapter
542
+ assert CallRouter::PROVIDER_API_KEY_DEFAULTS.key?('antigravity')
543
+ assert_nil CallRouter::PROVIDER_API_KEY_DEFAULTS['antigravity']
544
+ end
545
+
546
+ def test_the_llm_call_tool_builds_this_adapter_and_offers_the_provider
547
+ require 'kairos_mcp/tools/base_tool'
548
+ require_relative '../tools/llm_call'
549
+ tool = Tools::LlmCall.new
550
+ assert_instance_of AntigravityAdapter, tool.send(:build_adapter, { 'provider' => 'antigravity' })
551
+ enum = tool.input_schema.dig(:properties, :provider_override, :enum) ||
552
+ tool.input_schema.dig('properties', 'provider_override', 'enum')
553
+ assert_includes enum, 'antigravity'
554
+ end
555
+ end
556
+ end
557
+ end
558
+ end
@@ -81,7 +81,7 @@ module KairosMcp
81
81
  type: 'string',
82
82
  description: 'Override configured provider for this call only ' \
83
83
  '(e.g., "codex", "cursor", "claude_code"). Useful for multi-LLM review.',
84
- enum: %w[anthropic openai local openrouter bedrock claude_code codex cursor]
84
+ enum: %w[anthropic openai local openrouter bedrock claude_code codex cursor antigravity]
85
85
  },
86
86
  dispatch_id: {
87
87
  type: 'string',
@@ -131,6 +131,7 @@ module KairosMcp
131
131
  'openai' => 'OPENAI_API_KEY',
132
132
  'codex' => nil, # uses `codex login` CLI auth (~/.codex/)
133
133
  'cursor' => nil, # uses `cursor login` CLI auth (~/.cursor/)
134
+ 'antigravity' => nil, # uses `agy` CLI login (~/.gemini/antigravity-cli/)
134
135
  'claude_code' => nil, # uses subscription auth
135
136
  'bedrock' => nil, # uses AWS credentials
136
137
  'local' => nil,
@@ -291,6 +292,9 @@ module KairosMcp
291
292
  when 'cursor'
292
293
  require_relative '../lib/llm_client/cursor_adapter'
293
294
  CursorAdapter.new(config)
295
+ when 'antigravity'
296
+ require_relative '../lib/llm_client/antigravity_adapter'
297
+ AntigravityAdapter.new(config)
294
298
  when 'bedrock'
295
299
  require_relative '../lib/llm_client/bedrock_adapter'
296
300
  BedrockAdapter.new(config)
@@ -28,7 +28,7 @@ module KairosMcp
28
28
  provider: {
29
29
  type: 'string',
30
30
  description: 'LLM provider',
31
- enum: %w[anthropic openai local openrouter bedrock claude_code codex cursor]
31
+ enum: %w[anthropic openai local openrouter bedrock claude_code codex cursor antigravity]
32
32
  },
33
33
  model: { type: 'string', description: 'Model name' },
34
34
  api_key_env: { type: 'string', description: 'Environment variable name for API key' },
@@ -68,7 +68,8 @@ module KairosMcp
68
68
  {
69
69
  'claude_code' => probe_cli('claude', %w[--version]),
70
70
  'codex' => probe_cli('codex', %w[--version]),
71
- 'cursor' => probe_cli('agent', %w[--version])
71
+ 'cursor' => probe_cli('agent', %w[--version]),
72
+ 'antigravity' => probe_cli('agy', %w[--version])
72
73
  }
73
74
  end
74
75
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kairos-chain
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.101.0
4
+ version: 3.102.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaomi Hatakeyama
@@ -745,6 +745,7 @@ files:
745
745
  - templates/skillsets/llm_client/config/llm_client.yml
746
746
  - templates/skillsets/llm_client/lib/llm_client/adapter.rb
747
747
  - templates/skillsets/llm_client/lib/llm_client/anthropic_adapter.rb
748
+ - templates/skillsets/llm_client/lib/llm_client/antigravity_adapter.rb
748
749
  - templates/skillsets/llm_client/lib/llm_client/bedrock_adapter.rb
749
750
  - templates/skillsets/llm_client/lib/llm_client/call_router.rb
750
751
  - templates/skillsets/llm_client/lib/llm_client/claude_code_adapter.rb
@@ -758,6 +759,7 @@ files:
758
759
  - templates/skillsets/llm_client/lib/llm_client/safe_subprocess.rb
759
760
  - templates/skillsets/llm_client/lib/llm_client/schema_converter.rb
760
761
  - templates/skillsets/llm_client/skillset.json
762
+ - templates/skillsets/llm_client/test/test_antigravity_adapter.rb
761
763
  - templates/skillsets/llm_client/test/test_bedrock_adapter_timeout.rb
762
764
  - templates/skillsets/llm_client/test/test_call_router.rb
763
765
  - templates/skillsets/llm_client/test/test_claude_code_adapter_parse.rb