From 30fab46ca17b86c91287dd5705b161de041170fb Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 21 Jun 2025 00:55:36 +0800 Subject: [PATCH] fix: compact memory (#2278) --- lua/avante/llm_tools/replace_in_file.lua | 3 +++ lua/avante/sidebar.lua | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/lua/avante/llm_tools/replace_in_file.lua b/lua/avante/llm_tools/replace_in_file.lua index a301380..9ea7c71 100644 --- a/lua/avante/llm_tools/replace_in_file.lua +++ b/lua/avante/llm_tools/replace_in_file.lua @@ -735,6 +735,9 @@ function M.func(opts, on_log, on_complete, session_ctx) on_complete(false, "User declined, reason: " .. (reason or "unknown")) return end + local parent_dir = vim.fn.fnamemodify(abs_path, ":h") + --- check if the parent dir is exists, if not, create it + if not vim.fn.isdirectory(parent_dir) then vim.fn.mkdir(parent_dir, "p") end vim.api.nvim_buf_call(bufnr, function() vim.cmd("noautocmd write") end) if session_ctx then Helpers.mark_as_not_viewed(opts.path, session_ctx) end on_complete(true, nil) diff --git a/lua/avante/sidebar.lua b/lua/avante/sidebar.lua index a17238f..9b098f1 100644 --- a/lua/avante/sidebar.lua +++ b/lua/avante/sidebar.lua @@ -2181,6 +2181,16 @@ function Sidebar:get_history_messages_for_api(opts) if opts.all then return history_messages0 end + if self.chat_history and self.chat_history.memory then + local picked_messages = {} + for idx = #history_messages0, 1, -1 do + local message = history_messages0[idx] + if message.uuid == self.chat_history.memory.last_message_uuid then break end + table.insert(picked_messages, 1, message) + end + history_messages0 = picked_messages + end + local tool_id_to_tool_name = {} local tool_id_to_path = {} local tool_id_to_start_line = {}