fix: handle user-declined tool executions separately from errors (#2258)

This commit is contained in:
Brewinski
2025-06-21 02:50:00 +10:00
committed by GitHub
parent babb114bc4
commit 8572a4832d
3 changed files with 19 additions and 4 deletions

View File

@@ -682,6 +682,7 @@ function M._stream(opts)
tool_use_id = tool_result.tool_use_id, tool_use_id = tool_result.tool_use_id,
content = tool_result.content, content = tool_result.content,
is_error = tool_result.is_error, is_error = tool_result.is_error,
is_user_declined = tool_result.is_user_declined,
}, },
}, },
}) })
@@ -726,10 +727,12 @@ function M._stream(opts)
return opts.on_stop({ reason = "cancelled" }) return opts.on_stop({ reason = "cancelled" })
end end
local is_user_declined = error and error:match("^User declined")
local tool_result = { local tool_result = {
tool_use_id = partial_tool_use.id, tool_use_id = partial_tool_use.id,
content = error ~= nil and error or result, content = error ~= nil and error or result,
is_error = error ~= nil, is_error = error ~= nil, -- Keep this as error to prevent processing as success
is_user_declined = is_user_declined ~= nil,
} }
table.insert(tool_results, tool_result) table.insert(tool_results, tool_result)
return handle_next_tool_use(partial_tool_use_list, tool_use_index + 1, tool_results) return handle_next_tool_use(partial_tool_use_list, tool_use_index + 1, tool_results)

View File

@@ -2195,11 +2195,20 @@ function Sidebar:get_history_messages_for_api(opts)
local tool_use_message = Utils.get_tool_use_message(message, history_messages0) local tool_use_message = Utils.get_tool_use_message(message, history_messages0)
local is_edit_func_call, _, _, path = Utils.is_edit_func_call_message(tool_use_message) local is_edit_func_call, _, _, path = Utils.is_edit_func_call_message(tool_use_message)
if is_edit_func_call and message.message.content[1].is_error then local tool_result = message.message.content[1]
failed_edit_tool_ids[message.message.content[1].tool_use_id] = true
-- Only track as failed if it's an error AND not user-declined
if is_edit_func_call and tool_result.is_error and not tool_result.is_user_declined then
failed_edit_tool_ids[tool_result.tool_use_id] = true
end end
if is_edit_func_call and path and not message.message.content[1].is_error then -- Only track as successful modification if not an error AND not user-declined
if
is_edit_func_call
and path
and not message.message.content[1].is_error
and not message.message.content[1].is_user_declined
then
local uniformed_path = Utils.uniform_path(path) local uniformed_path = Utils.uniform_path(path)
last_modified_files[uniformed_path] = idx last_modified_files[uniformed_path] = idx
end end
@@ -2260,6 +2269,7 @@ function Sidebar:get_history_messages_for_api(opts)
tool_use_id = view_tool_use_id, tool_use_id = view_tool_use_id,
content = view_result, content = view_result,
is_error = view_error ~= nil, is_error = view_error ~= nil,
is_user_declined = false,
}, },
}, },
}, { }, {
@@ -2299,6 +2309,7 @@ function Sidebar:get_history_messages_for_api(opts)
tool_use_id = get_diagnostics_tool_use_id, tool_use_id = get_diagnostics_tool_use_id,
content = vim.json.encode(diagnostics), content = vim.json.encode(diagnostics),
is_error = false, is_error = false,
is_user_declined = false,
}, },
}, },
}, { }, {

View File

@@ -116,6 +116,7 @@ vim.g.avante_login = vim.g.avante_login
---@field tool_use_id string ---@field tool_use_id string
---@field content string ---@field content string
---@field is_error? boolean ---@field is_error? boolean
---@field is_user_declined? boolean
--- ---
---@class AvantePromptOptions: table<[string], string> ---@class AvantePromptOptions: table<[string], string>
---@field system_prompt string ---@field system_prompt string