polish the codecompanion look, review inline diffs, inline effort medium

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>
This commit is contained in:
jannikdonkerandClaude Opus 5.5 committed 2026-11-18 10:01:03 +01:00
1 parent 056c309bd6
commit 6fcc20b6ff
4 files changed
+470 -69

No files matched your search

+85 -18
View File
@@ -1,16 +1,20 @@
-- Progress bar for inline edits (`:CodeCompanion`). While a request runs, a
-- Progress pill for inline edits (`:CodeCompanion`). While a request runs, a
-- one-line float sits in the bottom-right corner of the window being edited:
-- ⠹ Claude Code · Read ai.lua · 3 tools · 12s
-- ( ⠹ Antigravity Read ai.lua · 3 tools · 12s )
-- and when it ends shows the outcome for a moment ("󰄬 done", "󰅖 failed").
-- CodeCompanion itself shows nothing until the diff appears. It does receive
-- the agent's progress over ACP (tool calls, thinking, reply), but inline
-- mode only keeps the reply text. So this wraps the internal method those
-- updates go through, and listens to the documented Inline* events for
-- start/stop. HTTP adapters get the spinner and timer only.
local api = vim.api
local ui = require("ai_ui") -- spinner, agent colours, Cc* highlight groups
local M = {}
local SPINNER = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" }
local ns = api.nvim_create_namespace("ai_inline_status")
local active = {} ---@type table<integer, table> inline bufnr -> state
local LINGER = 1500 -- ms the outcome stays up after the request ends
local CAP_L, CAP_R = "\238\130\182", "\238\130\180" -- Nerd Font round caps U+E0B6/U+E0B4
-- Tool titles contain paths. Inline agents edit a copy of the buffer in
-- Neovim's temp dir (e.g. /tmp/nvim.user/AbC123/1/foo.lua), so show just the
@@ -42,36 +46,75 @@ local function close_float(st)
st.win = nil
end
-- Segments of the pill: { text, highlight }.
local function segments(st)
local agent = ui.agent(st.name)
local secs = math.floor(((st.ended or vim.uv.now()) - st.started) / 1000) .. "s"
local tools = st.tools > 0 and (st.tools .. (st.tools == 1 and " tool" or " tools")) or nil
local segs
if not st.ended then
segs = {
{ ui.SPINNER[st.frame] .. " ", agent.hl .. "Pill" },
{ st.name .. " ", agent.hl .. "Pill" },
{ st.activity, "CcPill" },
}
elseif st.status == "success" or st.status == nil then
segs = { { "󰄬 ", "CcPillOk" }, { st.name .. " ", agent.hl .. "Pill" }, { "done", "CcPill" } }
elseif st.status == "cancelled" then
segs = { { "󰜺 ", "CcPillDim" }, { st.name .. " ", agent.hl .. "Pill" }, { "cancelled", "CcPillDim" } }
else
segs = { { "󰅖 ", "CcPillErr" }, { st.name .. " ", agent.hl .. "Pill" }, { "failed", "CcPillErr" } }
end
for _, meta in ipairs({ tools, secs }) do
if meta then table.insert(segs, { " · " .. meta, "CcPillDim" }) end
end
return segs
end
local function render(bufnr)
local st = active[bufnr]
if not st then return end
local anchor = target_win(bufnr)
if not anchor then return close_float(st) end
if not st.ended then st.frame = st.frame % #ui.SPINNER + 1 end
st.frame = st.frame % #SPINNER + 1
local parts = { SPINNER[st.frame] .. " " .. st.name, st.activity }
if st.tools > 0 then table.insert(parts, st.tools .. (st.tools == 1 and " tool" or " tools")) end
table.insert(parts, math.floor((vim.uv.now() - st.started) / 1000) .. "s")
local text = " " .. table.concat(parts, " · ") .. " "
local max = api.nvim_win_get_width(anchor) - 2
if vim.fn.strdisplaywidth(text) > max then
text = vim.fn.strcharpart(text, 0, max - 2) .. "… "
-- Rounded caps around the body; the activity gets cut short first.
local segs = segments(st)
local max = api.nvim_win_get_width(anchor) - 4
local width = 0
for _, seg in ipairs(segs) do width = width + vim.fn.strdisplaywidth(seg[1]) end
if width > max and segs[3] then
local keep = math.max(vim.fn.strdisplaywidth(segs[3][1]) - (width - max) - 1, 0)
segs[3][1] = vim.fn.strcharpart(segs[3][1], 0, keep) .. "…"
end
local width = vim.fn.strdisplaywidth(text)
table.insert(segs, 1, { CAP_L, "CcPillCap" })
table.insert(segs, 2, { " ", "CcPill" })
table.insert(segs, { " ", "CcPill" })
table.insert(segs, { CAP_R, "CcPillCap" })
local text, marks = "", {}
for _, seg in ipairs(segs) do
table.insert(marks, { #text, #text + #seg[1], seg[2] })
text = text .. seg[1]
end
width = vim.fn.strdisplaywidth(text)
if not (st.buf and api.nvim_buf_is_valid(st.buf)) then
st.buf = api.nvim_create_buf(false, true)
vim.bo[st.buf].bufhidden = "wipe"
end
api.nvim_buf_set_lines(st.buf, 0, -1, false, { text })
api.nvim_buf_clear_namespace(st.buf, ns, 0, -1)
for _, m in ipairs(marks) do
api.nvim_buf_set_extmark(st.buf, ns, 0, m[1], { end_col = m[2], hl_group = m[3] })
end
local cfg = {
relative = "win",
win = anchor,
anchor = "SE",
row = api.nvim_win_get_height(anchor),
col = api.nvim_win_get_width(anchor),
col = api.nvim_win_get_width(anchor) - 1,
width = width,
height = 1,
focusable = false,
@@ -84,7 +127,8 @@ local function render(bufnr)
cfg.style = "minimal"
cfg.noautocmd = true
st.win = api.nvim_open_win(st.buf, false, cfg)
vim.wo[st.win].winhighlight = "Normal:StatusLine"
-- Caps take the editor background; the body's colours come from the marks.
vim.wo[st.win].winhighlight = "Normal:Normal"
end
end
@@ -92,15 +136,38 @@ local function stop(bufnr)
local st = active[bufnr]
if not st then return end
active[bufnr] = nil
st.timer:stop()
st.timer:close()
if not st.timer:is_closing() then
st.timer:stop()
st.timer:close()
end
close_float(st)
end
-- The request ended: freeze the pill on its outcome, then remove it. Both
-- RequestFinished (has the status) and InlineFinished (doesn't) end up here,
-- in either order, so the outcome is drawn on the next tick, not right away.
local function finish(bufnr, status)
local st = active[bufnr]
if not st then return end
st.status = status or st.status
if st.ended then return end
st.ended = vim.uv.now()
st.timer:stop()
vim.defer_fn(function()
if active[bufnr] ~= st then return end
render(bufnr)
vim.defer_fn(function()
if active[bufnr] == st then stop(bufnr) end
end, LINGER)
end, 50)
end
local function start(bufnr, adapter)
stop(bufnr)
local st = {
name = adapter and (adapter.formatted_name or adapter.name) or "AI",
status = nil, ---@type string? from RequestFinished: success|error|cancelled
ended = nil, ---@type integer? when the request ended (ms)
activity = "starting…",
tools = 0,
frame = 0,
@@ -142,7 +209,7 @@ function M.setup()
callback = function(ev)
local d = ev.data or {}
if ev.match == "CodeCompanionInlineFinished" or d.interaction == "inline" then
stop(d.bufnr)
finish(d.bufnr, d.status)
end
end,
})