diff --git a/README.md b/README.md index 1ce6527..489c350 100644 --- a/README.md +++ b/README.md @@ -1208,6 +1208,22 @@ To use ACP-compatible agents with Avante.nvim, you need to configure an ACP prov } ``` +#### Goose with ACP +```lua +{ + provider = "goose", + -- other configuration options... +} +``` + +#### Codex with ACP +```lua +{ + provider = "codex", + -- other configuration options... +} +``` + ### ACP Configuration ACP providers are configured in the `acp_providers` section of your configuration: @@ -1231,6 +1247,17 @@ ACP providers are configured in the `acp_providers` section of your configuratio ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY"), }, }, + ["goose"] = { + command = "goose", + args = { "acp" }, + }, + ["codex"] = { + command = "codex-acp", + env = { + NODE_NO_WARNINGS = "1", + OPENAI_API_KEY = os.getenv("OPENAI_API_KEY"), + }, + }, }, -- other configuration options... } diff --git a/lua/avante/config.lua b/lua/avante/config.lua index a7ed1a9..5474082 100644 --- a/lua/avante/config.lua +++ b/lua/avante/config.lua @@ -262,6 +262,13 @@ M._defaults = { command = "goose", args = { "acp" }, }, + ["codex"] = { + command = "codex-acp", + env = { + NODE_NO_WARNINGS = "1", + OPENAI_API_KEY = os.getenv("OPENAI_API_KEY"), + }, + }, }, ---To add support for custom provider, follow the format below ---See https://github.com/yetone/avante.nvim/wiki#custom-providers for more details diff --git a/lua/avante/history/render.lua b/lua/avante/history/render.lua index 797763d..efdd9a9 100644 --- a/lua/avante/history/render.lua +++ b/lua/avante/history/render.lua @@ -86,7 +86,11 @@ end local function thinking_to_lines(item) local text = item.thinking or item.data or "" local text_lines = vim.split(text, "\n") - --- trime suffix empty lines + --- trim prefix empty lines + while #text_lines > 0 and text_lines[1] == "" do + table.remove(text_lines, 1) + end + --- trim suffix empty lines while #text_lines > 0 and text_lines[#text_lines] == "" do table.remove(text_lines, #text_lines) end diff --git a/lua/avante/libs/acp_client.lua b/lua/avante/libs/acp_client.lua index 179b9ee..246d2fe 100644 --- a/lua/avante/libs/acp_client.lua +++ b/lua/avante/libs/acp_client.lua @@ -509,7 +509,7 @@ function ACPClient:_send_result(id, result) local data = vim.json.encode(message) if self.debug_log_file then - self.debug_log_file:write("request: " .. data .. string.rep("=", 100) .. "\n") + self.debug_log_file:write("request: " .. data .. "\n" .. string.rep("=", 100) .. "\n") self.debug_log_file:flush() end self.transport:send(data) diff --git a/lua/avante/llm.lua b/lua/avante/llm.lua index 020eb58..482d119 100644 --- a/lua/avante/llm.lua +++ b/lua/avante/llm.lua @@ -907,7 +907,7 @@ function M._stream_acp(opts) end if opts.on_messages_add then opts.on_messages_add(messages) - vim.schedule(function() vim.cmd("redraw") end) + -- vim.schedule(function() vim.cmd("redraw") end) end end local function add_tool_call_message(update) @@ -992,6 +992,24 @@ function M._stream_acp(opts) end if update.sessionUpdate == "agent_thought_chunk" then if update.content.type == "text" then + local messages = opts.get_history_messages() + local last_message = messages[#messages] + if last_message and last_message.message.role == "assistant" then + local is_thinking = false + local content = last_message.message.content + if type(content) == "table" then + for idx, item in ipairs(content) do + if type(item) == "table" and item.type == "thinking" then + is_thinking = true + content[idx].thinking = content[idx].thinking .. update.content.text + end + end + end + if is_thinking then + on_messages_add({ last_message }) + return + end + end local message = History.Message:new("assistant", { type = "thinking", thinking = update.content.text, diff --git a/lua/avante/sidebar.lua b/lua/avante/sidebar.lua index 0983e64..a595ded 100644 --- a/lua/avante/sidebar.lua +++ b/lua/avante/sidebar.lua @@ -1949,7 +1949,7 @@ function Sidebar:get_message_lines(ctx, message, messages, ignore_record_prefix) if type(item) == "string" then text_len = text_len + #item else - for _, subitem in ipairs(item) do + for _, subitem in pairs(item) do if type(subitem) == "string" then text_len = text_len + #subitem end end end