Public Access
codecompanion with claude code and antigravity agents
Chat defaults to Claude Code (via claude-agent-acp), inline edits to Antigravity pinned to Gemini 4 Hydrogen at high effort. The chat winbar shows agent/model/effort, `ge` switches effort, and inline edits get a progress float. Keymaps live under <leader>a. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
29f9a1bb43
commit
48b149f4ef
4 files changed
+354
No files matched your search
+188
@@ -0,0 +1,188 @@
|
||||
-- CodeCompanion: AI chat / inline edits backed by agents over ACP (Agent
|
||||
-- Client Protocol), so both use their own CLI login. No API keys needed.
|
||||
-- claude_code -> `claude-agent-acp` (npm i -g @agentclientprotocol/claude-agent-acp),
|
||||
-- which reuses the `claude` CLI login.
|
||||
-- antigravity -> `agy acp` (Antigravity CLI: Gemini, plus Claude/GPT-OSS via
|
||||
-- Google). Uses the `agy` Google login.
|
||||
-- Chat uses Claude Code, inline uses Antigravity (Gemini 4 Hydrogen, high).
|
||||
-- Agents read their own CLAUDE.md / GEMINI.md / AGENTS.md and settings, so
|
||||
-- model, permissions and MCP servers come from the CLI configs unless pinned
|
||||
-- here (only inline is).
|
||||
-- In a chat: `ga` switches agent/model, `ge` effort, `?` lists all keymaps.
|
||||
-- The winbar shows the current agent · model · effort.
|
||||
|
||||
-- The ACP module directly: the generic adapters.extend() decides http vs acp
|
||||
-- by looking the name up in the config, and gemini_cli is hidden from it.
|
||||
local acp = require("codecompanion.adapters.acp")
|
||||
|
||||
-- Antigravity (`agy acp`). There's no built-in adapter for it yet; its ACP
|
||||
-- server speaks the same dialect as Gemini CLI (same auth method ids), so
|
||||
-- reuse that adapter with a different command. `session_options` pins
|
||||
-- model/effort/mode for new sessions (values match ids or display names).
|
||||
local function antigravity(name, session_options)
|
||||
return acp.extend("gemini_cli", {
|
||||
name = name, -- must equal the key under adapters.acp
|
||||
formatted_name = "Antigravity",
|
||||
commands = {
|
||||
default = { "agy", "acp" },
|
||||
yolo = { "agy", "acp", "--dangerously-skip-permissions" },
|
||||
},
|
||||
defaults = {
|
||||
auth_method = "oauth-personal", -- Google login
|
||||
session_config_options = session_options,
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
-- Effort ("thought_level" in ACP terms; both agents report it under that
|
||||
-- category). Opens a picker with just the effort levels of the current model,
|
||||
-- the same one `/acp_session_options` shows after you pick "Effort" there.
|
||||
-- Uses that slash command's module, which isn't public API (fine while
|
||||
-- pinned to ^20).
|
||||
local function pick_effort(chat)
|
||||
local conn = chat.acp_connection
|
||||
if not conn then
|
||||
return vim.notify("Effort: only agent (ACP) chats have it", vim.log.levels.WARN)
|
||||
end
|
||||
for _, opt in ipairs(conn:get_config_options()) do
|
||||
if opt.category == "thought_level" then
|
||||
return require("codecompanion.interactions.chat.slash_commands.builtin.acp_session_options")
|
||||
.new({ Chat = chat })
|
||||
:show_values(opt)
|
||||
end
|
||||
end
|
||||
vim.notify("Effort: the agent hasn't reported one (still connecting, or this model has none)",
|
||||
vim.log.levels.WARN)
|
||||
end
|
||||
|
||||
-- Display name of an ACP chat's current value for an option category, read
|
||||
-- live from the agent connection. (The metadata CodeCompanion hands the
|
||||
-- winbar caches its value->name map before the agent has sent its options,
|
||||
-- so it only has raw ids there, e.g. Claude's model is just "default".)
|
||||
local function acp_option_name(md, category)
|
||||
local bufnr
|
||||
for b, m in pairs(_G.codecompanion_chat_metadata or {}) do
|
||||
if m == md then bufnr = b end
|
||||
end
|
||||
local chat = bufnr and require("codecompanion").buf_get_chat(bufnr)
|
||||
local conn = chat and chat.acp_connection
|
||||
if not conn then return nil end
|
||||
for _, opt in ipairs(conn:get_config_options()) do
|
||||
if opt.category == category and opt.currentValue then
|
||||
for _, item in ipairs(opt.options or {}) do
|
||||
for _, v in ipairs(item.options or { item }) do -- items may be grouped
|
||||
if v.value == opt.currentValue then return v.name end
|
||||
end
|
||||
end
|
||||
return opt.currentValue
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Chat winbar: title on the left, `agent · model · effort` on the right.
|
||||
local function chat_winbar(md)
|
||||
local title = (md.title or "CodeCompanion"):gsub("%%", "%%%%")
|
||||
local parts = { md.adapter.name }
|
||||
local model = acp_option_name(md, "model") or md.adapter.model -- HTTP: model id
|
||||
if model then table.insert(parts, model) end
|
||||
local effort = acp_option_name(md, "thought_level")
|
||||
if effort then table.insert(parts, "effort " .. effort:lower()) end
|
||||
local right = table.concat(parts, " · "):gsub("%%", "%%%%")
|
||||
return string.format("%%#CodeCompanionChatHeader# %s%%*%%=%%#Comment#%s ", title, right)
|
||||
end
|
||||
|
||||
require("codecompanion").setup({
|
||||
adapters = {
|
||||
acp = {
|
||||
-- List only the two agents below in the adapter picker.
|
||||
opts = { show_presets = false },
|
||||
|
||||
claude_code = function()
|
||||
return acp.extend("claude_code", {})
|
||||
end,
|
||||
|
||||
antigravity = function() return antigravity("antigravity") end,
|
||||
|
||||
-- Inline edits: Gemini 4 Hydrogen at high effort. A separate
|
||||
-- adapter because inline can only pin a model, not effort, and
|
||||
-- setting effort on `antigravity` would change chats too. Hidden
|
||||
-- from the `ga` picker below.
|
||||
antigravity_inline = function()
|
||||
return antigravity("antigravity_inline", {
|
||||
model = "gemini-4-hydrogen",
|
||||
thought_level = "high",
|
||||
})
|
||||
end,
|
||||
},
|
||||
http = {
|
||||
-- The defaults (web search/fetch backends) plus the inline-only agent.
|
||||
opts = {
|
||||
hidden = {
|
||||
duckduckgo = true, jina = true, markitdown = true, tavily = true,
|
||||
antigravity_inline = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
interactions = {
|
||||
chat = {
|
||||
adapter = "claude_code",
|
||||
keymaps = {
|
||||
-- `ga` already switches agent + model; `ge` (normally "end of
|
||||
-- previous word", only overridden in the chat buffer) switches
|
||||
-- effort. Everything else: `/acp_session_options` (mode etc.).
|
||||
change_effort = {
|
||||
modes = { n = "ge" },
|
||||
callback = pick_effort,
|
||||
description = "Change effort (reasoning level)",
|
||||
},
|
||||
},
|
||||
},
|
||||
-- ACP agents edit a temp copy of the buffer and hand back a diff.
|
||||
-- `ga` in the :CodeCompanion input box overrides this per buffer.
|
||||
inline = { adapter = "antigravity_inline" },
|
||||
|
||||
-- These two only work with HTTP adapters (plain API calls), not
|
||||
-- agents. They need ANTHROPIC_API_KEY; without it they stay unused
|
||||
-- (background tasks are off by default; :CodeCompanionCmd errors).
|
||||
-- The default would be Copilot, which isn't set up here.
|
||||
cmd = { adapter = { name = "anthropic", model = "claude-haiku-5-5" } },
|
||||
background = { adapter = { name = "anthropic", model = "claude-haiku-5-5" } },
|
||||
|
||||
-- The full CLIs in a terminal split, with context sharing from
|
||||
-- buffers (`:CodeCompanionCLI`, `:CodeCompanionCLI agent=antigravity`).
|
||||
cli = {
|
||||
agent = "claude_code",
|
||||
agents = {
|
||||
claude_code = { cmd = "claude", args = {}, description = "Claude Code CLI" },
|
||||
antigravity = { cmd = "agy", args = {}, description = "Antigravity CLI" },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
display = {
|
||||
chat = {
|
||||
window = { position = "right", width = 0.4 },
|
||||
-- Winbar instead of a heading in the buffer, so it stays visible.
|
||||
title = { position = "winbar", text = { winbar = chat_winbar } },
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
-- Progress float while an inline edit runs (see lua/ai_status.lua).
|
||||
require("ai_status").setup()
|
||||
|
||||
-- Keymaps: everything under <leader>a. Visual-mode maps use `:` rather than
|
||||
-- <cmd> so the selection is passed as a range ('<,'>).
|
||||
local map = vim.keymap.set
|
||||
map("n", "<leader>aa", "<cmd>CodeCompanionChat Toggle<cr>", { desc = "AI: toggle chat" })
|
||||
map("x", "<leader>aa", ":CodeCompanionChat Add<cr>", { silent = true, desc = "AI: add selection to chat" })
|
||||
map("n", "<leader>ac", "<cmd>CodeCompanionChat adapter=claude_code<cr>", { desc = "AI: new Claude Code chat" })
|
||||
map("n", "<leader>ag", "<cmd>CodeCompanionChat adapter=antigravity<cr>", { desc = "AI: new Antigravity chat" })
|
||||
map({ "n", "x" }, "<leader>ai", ":CodeCompanion ", { desc = "AI: inline edit (type prompt)" })
|
||||
map("n", "<leader>ap", "<cmd>CodeCompanionActions<cr>", { desc = "AI: action palette" })
|
||||
map("x", "<leader>ap", ":CodeCompanionActions<cr>", { silent = true, desc = "AI: action palette (selection)" })
|
||||
map("n", "<leader>at", "<cmd>CodeCompanionCLI<cr>", { desc = "AI: CLI agent in terminal" })
|
||||
map("x", "<leader>at", ":CodeCompanionCLI<cr>", { silent = true, desc = "AI: send selection to CLI agent" })
|
||||
map("n", "<leader>ar", "<cmd>CodeCompanionCodeReview<cr>", { desc = "AI: review agent changes" })
|
||||
Reference in new issue
Block a user