Public Access
Chat: markdown rendered by render-markdown.nvim (chat buffer only, not markdown files), `## You` / `## Claude Code` headers as tinted bars, upright code, no line numbers. Winbar shows icon, title and agent · model · effort, with a spinner and timer while the agent works; a lualine extension shows context items and tokens. Highlights live in lua/ai_ui.lua and follow gruvbox's light/dark switch. Inline: the progress float is now a pill with per-part colours that shows done/failed/cancelled for a moment; the diff banner is a label. Inline edits always open the diff for review again (approval_mode auto was applying them straight away), and run at medium effort with every agent and model unless an adapter sets its own thought_level. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
214 lines
11 KiB
Lua
214 lines
11 KiB
Lua
-- 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).
|
|
-- Inline always runs at medium effort, whichever agent/model (see below).
|
|
-- 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 (see lua/ai_ui.lua).
|
|
|
|
-- 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
|
|
|
|
local ui = require("ai_ui") -- look of the chat (lua/ai_ui.lua)
|
|
|
|
require("codecompanion").setup({
|
|
adapters = {
|
|
acp = {
|
|
-- List only the two agents below in the adapter picker.
|
|
opts = { show_presets = false },
|
|
|
|
-- Chat agents start in their own auto mode: the agent approves
|
|
-- routine actions itself and only asks about risky ones.
|
|
-- (Claude falls back to its default if a model lacks auto.)
|
|
claude_code = function()
|
|
return acp.extend("claude_code", {
|
|
defaults = { session_config_options = { mode = "auto" } },
|
|
})
|
|
end,
|
|
|
|
antigravity = function() return antigravity("antigravity", { mode = "auto" }) end,
|
|
|
|
-- Inline edits: Gemini 4 Hydrogen. A separate adapter so the
|
|
-- model pin doesn't change chats. Effort comes from the inline
|
|
-- default further down (set `thought_level` here to override it).
|
|
-- Hidden from the `ga` picker below. No auto mode here on purpose:
|
|
-- inline never prompts you anyway (CodeCompanion answers the
|
|
-- agent's permission requests itself), and those requests are
|
|
-- how it keeps the agent to editing only the buffer copy. An
|
|
-- agent in auto mode would skip them.
|
|
antigravity_inline = function()
|
|
return antigravity("antigravity_inline", { model = "gemini-4-hydrogen" })
|
|
end,
|
|
},
|
|
-- Merged into the default hidden list. All HTTP adapters get hidden
|
|
-- after setup() below; this one is an agent, so it's listed here.
|
|
http = { opts = { hidden = { antigravity_inline = true } } },
|
|
},
|
|
|
|
interactions = {
|
|
chat = {
|
|
adapter = "claude_code",
|
|
roles = ui.roles, -- `## You` / `## Claude Code` headers
|
|
-- CodeCompanion's own approval layer (`gty` to change per chat).
|
|
-- Auto: the agent's reads, searches, edits and fetches go through;
|
|
-- shell commands outside tools.run_command.opts.safe_commands
|
|
-- (git status, ls, pwd) and anything else (e.g. deletes) still ask.
|
|
tools = { opts = { approval_mode = "auto" } },
|
|
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", -- must stay "claude" for :CodeCompanionCLI Install hooks
|
|
args = { "--permission-mode", "auto" },
|
|
description = "Claude Code CLI",
|
|
},
|
|
antigravity = { cmd = "agy", args = { "--mode", "auto" }, description = "Antigravity CLI" },
|
|
},
|
|
},
|
|
},
|
|
|
|
display = {
|
|
-- Winbar title, padding instead of line numbers, etc.
|
|
chat = vim.tbl_deep_extend("force", ui.chat_display, {
|
|
window = { position = "right", width = 0.4 },
|
|
}),
|
|
input = { title = " Inline edit" }, -- `:CodeCompanion` with no prompt
|
|
},
|
|
})
|
|
|
|
-- The `ga` picker shows only Claude Code and Antigravity: hide every
|
|
-- built-in HTTP (API-key) provider, including ones added in later releases.
|
|
-- The hidden list is read whenever the picker opens, and hidden adapters
|
|
-- still work by name (cmd/background use anthropic, web tools duckduckgo).
|
|
local http_adapters = require("codecompanion.config").adapters.http
|
|
for name in pairs(http_adapters) do
|
|
if name ~= "opts" and name ~= "extend" then http_adapters.opts.hidden[name] = true end
|
|
end
|
|
|
|
-- Inline edits always open the diff for review. CodeCompanion decides that
|
|
-- with the same approval check as chat tools, keyed by the edited buffer, and
|
|
-- buffers without a mode of their own fall back to approval_mode ("auto"
|
|
-- above), which would apply the edit straight away. So give each buffer that
|
|
-- gets an inline edit "ask". Only that check looks at a file buffer's mode
|
|
-- (chat tools look up the chat's); `g1` (always accept for this buffer) in
|
|
-- the diff still works. Internal API, fine while pinned to ^20.
|
|
vim.api.nvim_create_autocmd("User", {
|
|
pattern = "CodeCompanionInlineStarted",
|
|
callback = function(ev)
|
|
require("codecompanion.interactions.chat.tools.approvals"):set_mode(ev.data.bufnr, { mode = "ask" })
|
|
end,
|
|
})
|
|
|
|
-- Inline edits run at medium effort with every agent and model, including
|
|
-- ones picked with `ga` in the inline prompt: those come with the chat
|
|
-- adapter's settings, which leave effort to the agent (and so to whatever the
|
|
-- CLI was last set to). When CodeCompanion opens an inline session it applies
|
|
-- the adapter's session_config_options; this adds `thought_level` to them
|
|
-- unless the adapter sets its own. Chats are untouched (the caller check),
|
|
-- and a model without a "medium" level keeps its default (logged, no popup).
|
|
-- Internal API, fine while pinned to ^20.
|
|
local INLINE_EFFORT = "medium"
|
|
local acp_defaults = require("codecompanion.interactions.chat.acp.defaults")
|
|
local apply_defaults = acp_defaults.apply
|
|
acp_defaults.apply = function(adapter, connection)
|
|
local caller = debug.getinfo(2, "S").source -- the module opening the session
|
|
local opts = vim.tbl_get(adapter or {}, "defaults", "session_config_options") or {}
|
|
if caller:find("/interactions/inline/", 1, true) and opts.thought_level == nil then
|
|
local defaults = vim.tbl_extend("force", adapter.defaults or {}, {
|
|
session_config_options = vim.tbl_extend("force", opts, { thought_level = INLINE_EFFORT }),
|
|
})
|
|
adapter = setmetatable({ defaults = defaults }, { __index = adapter })
|
|
end
|
|
return apply_defaults(adapter, connection)
|
|
end
|
|
|
|
-- Highlights, markdown rendering in the chat, busy spinner in its winbar.
|
|
ui.setup()
|
|
-- Progress pill 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" })
|