kairos-chain 3.101.0 → 3.103.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 +4 -4
- data/CHANGELOG.md +61 -0
- data/lib/kairos_mcp/version.rb +1 -1
- data/templates/skillsets/llm_client/lib/llm_client/antigravity_adapter.rb +410 -0
- data/templates/skillsets/llm_client/lib/llm_client/call_router.rb +4 -0
- data/templates/skillsets/llm_client/skillset.json +2 -2
- data/templates/skillsets/llm_client/test/test_antigravity_adapter.rb +558 -0
- data/templates/skillsets/llm_client/tools/llm_call.rb +5 -1
- data/templates/skillsets/llm_client/tools/llm_configure.rb +1 -1
- data/templates/skillsets/llm_client/tools/llm_status.rb +2 -1
- data/templates/skillsets/trust_gate/knowledge/trust_boundary_questions/trust_boundary_questions.md +170 -0
- data/templates/skillsets/trust_gate/plugin/SKILL.md +44 -0
- data/templates/skillsets/trust_gate/plugin/agents/gatekeeper.md +39 -0
- data/templates/skillsets/trust_gate/skillset.json +20 -0
- data/templates/skillsets/trust_gate/test/test_trust_gate.rb +80 -0
- metadata +8 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0d26c39a2a0ec104e28190d16536fe5abf91ca573c9dc1036987e1ac185016c2
|
|
4
|
+
data.tar.gz: '09d7d3ed975982320ad0e03e46ee98b57c7f5e244fd5d1dab797431290b44e81'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b1319f8c1bdb67b1cee7e97171cbe959dea154b2a9f31bc2d29b889c96489af0e11a345da526e007972a7ea5111b6c97020f6138298fdc0f5c0bba95cf8a4b2e
|
|
7
|
+
data.tar.gz: 31db4857a4cefb1efe057d27985c8ca58ee1ab02c74ae62652843c836cc69a7be71af898d61317ffb5979fbb7e75b2ea7be703290b66062bce2775137d9d51b4
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,67 @@ This project follows [Semantic Versioning](https://semver.org/).
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [3.103.0] - 2026-11-22
|
|
10
|
+
|
|
11
|
+
### Added — trust_gate 0.1.0: an on-demand gate for trust boundaries (opt-in SkillSet)
|
|
12
|
+
|
|
13
|
+
- New SkillSet `trust_gate`. It asks four questions of a design or a diff that adds or changes an
|
|
14
|
+
entrance into an instance: an external connection, a credential, a run handed to another agent or
|
|
15
|
+
process, or outside text that a model will read. The questions are whether trust is attached to
|
|
16
|
+
verified content or identity and not to a location, whether authority is issued for one piece of
|
|
17
|
+
work and ends with it, whether outside text stays data whichever layer delivers it, and what a
|
|
18
|
+
compromised part could reach.
|
|
19
|
+
- It is a gate that is called, not a norm that is always on. The operator calls it by name. It
|
|
20
|
+
answers per place with file-and-line evidence, it does not block, and it fixes nothing. Every
|
|
21
|
+
report ends by saying that it is what one reading found and not a complete inventory.
|
|
22
|
+
- The SkillSet adds no MCP tools, no hooks and no config. It ships L1 `trust_boundary_questions`
|
|
23
|
+
0.3.1 (the questions and the only definition of the answer form), a plugin skill for the calling
|
|
24
|
+
session, and the subagent `trust-gatekeeper`, which did not write what it judges.
|
|
25
|
+
- **Not in the core list.** It is installed only on request: `kairos-chain skillset install
|
|
26
|
+
trust_gate`, or `system_upgrade` with `names: ["trust_gate"]`. An upgrade check lists it as
|
|
27
|
+
optional and changes nothing for instances that do not install it.
|
|
28
|
+
- The subagent's tools are an allowlist (read, search, list a directory, retrieve the entry). On
|
|
29
|
+
Claude Code the host's own record showed exactly those tools for a fresh process, and those plus
|
|
30
|
+
the hand-back tool for a subagent. **The OpenCode projection drops the allowlist** and keeps only
|
|
31
|
+
the denial of Write, Edit and Bash, so on that host the judge holds more tools than the work
|
|
32
|
+
needs. A definition edited during a session is not picked up until a new session.
|
|
33
|
+
- The standard the judge obeys is looked up by name. An entry of the same name in an instance's own
|
|
34
|
+
knowledge store is returned before the SkillSet's entry, so an instance that already holds one
|
|
35
|
+
must remove it to use the shipped text.
|
|
36
|
+
- Design review: three rounds. New blocking findings went 9, 2, 0, and round 3 was 5 of 5 seats
|
|
37
|
+
APPROVE. One call of the gate used 119 to 173 thousand subagent tokens in the trial.
|
|
38
|
+
|
|
39
|
+
## [3.102.0] - 2026-11-20
|
|
40
|
+
|
|
41
|
+
### Added — llm_client 0.5.0: provider `antigravity` (the Antigravity CLI, `agy`)
|
|
42
|
+
|
|
43
|
+
- New llm_client provider `antigravity` (`AntigravityAdapter`) drives `agy`. The prompt goes to stdin
|
|
44
|
+
as one stream-json line, because `agy -p` takes the prompt only as its own argument. The call runs
|
|
45
|
+
under a per-call agent definition whose tool allowlist is empty (the only guard that removes web
|
|
46
|
+
search), with session settings that deny all seven permission actions under strict permission mode,
|
|
47
|
+
and with `--sandbox` and slash commands off. Plan mode is not used: it injects the /plan procedure
|
|
48
|
+
and wrote plan files under `~/.gemini/antigravity-cli/brain/`. Success requires exit 0 and a
|
|
49
|
+
`result` event with status SUCCESS and a non-empty response, since a turn whose tool was auto-denied
|
|
50
|
+
exits 0 with nothing said. On every run, before success is judged, a reply is refused unless the
|
|
51
|
+
session reports this call's agent (a random name per call) and strict permission mode, and every
|
|
52
|
+
tool step's last state is the CLI's own permission refusal (a tool that completed, failed after
|
|
53
|
+
running or never reported an outcome, and any unrecognised step or event, refuse the reply).
|
|
54
|
+
Measured: outside read, shell fetch, web search and a 100 KB prompt. **Not yet measured: the write
|
|
55
|
+
probe.** No `model_observed` is returned: the CLI's init event names a model before any model has
|
|
56
|
+
answered.
|
|
57
|
+
- agy keeps every turn on disk under `~/.gemini/antigravity-cli/` and no setting turns that off, so
|
|
58
|
+
whatever is sent through this provider persists there.
|
|
59
|
+
- **The default multi_llm_review roster is unchanged.** No seat uses this provider unless an
|
|
60
|
+
instance's own config names it.
|
|
61
|
+
- Review state: three multi-LLM review rounds (2026-11-15 to 2026-11-18). The fixes for the round-3
|
|
62
|
+
blocking finding (a tool step left active passed the after-run check) have not been re-reviewed.
|
|
63
|
+
- Not changed: core `Capability::EXTERNAL_BINARIES` does not name `agy`, so the capability manifest
|
|
64
|
+
under-reports this dependency.
|
|
65
|
+
- Upgrade note: `kairos-chain upgrade` overwrites an installed SkillSet whose files differ from the
|
|
66
|
+
gem's, whatever the two versions are (only `config/` is left alone). An instance that carried
|
|
67
|
+
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
|
|
68
|
+
this release the two are equal. The upgrade itself is not changed.
|
|
69
|
+
|
|
9
70
|
## [3.101.0] - 2026-11-20
|
|
10
71
|
|
|
11
72
|
### Added — succession edges on the L2 save path; dream 0.4.0 digests read them, label membership and record checks
|
data/lib/kairos_mcp/version.rb
CHANGED
|
@@ -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
|
-
"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": [],
|