Skip to content

Commit 7722201

Browse files
committed
handle implicit manual approval flow
1 parent cfbb271 commit 7722201

2 files changed

Lines changed: 43 additions & 5 deletions

File tree

lua/eca/approve.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@ local M = {}
22

33
---@param tool_call eca.ToolCallRun
44
function M.get_preview_lines(tool_call)
5-
if not tool_call.details then
6-
local arguments = vim.split(vim.inspect(tool_call.arguments), "\n")
5+
-- If no details or details without diff, show tool call info
6+
if not tool_call.details or not tool_call.details.diff then
7+
local arguments_text = tool_call.arguments or ""
8+
local arguments = vim.split(vim.inspect(arguments_text), "\n")
79
local messages = {}
810
if tool_call.summary then
911
table.insert(messages, "Summary: " .. tool_call.summary)
1012
end
11-
table.insert(messages, "Tool Name: " .. tool_call.name)
12-
table.insert(messages, "Tool Type: " .. tool_call.origin)
13+
table.insert(messages, "Tool Name: " .. (tool_call.name or "unknown"))
14+
table.insert(messages, "Tool Type: " .. (tool_call.origin or "unknown"))
1315
table.insert(messages, "Tool Arguments: ")
1416
for _, v in pairs(arguments) do
1517
table.insert(messages, v)
1618
end
1719
return messages
1820
end
1921
local lines = vim.split(tool_call.details.diff, "\n")
20-
return { tool_call.details.path, unpack(lines) }
22+
return { tool_call.details.path or "", unpack(lines) }
2123
end
2224

2325
---@param lines string[]

lua/eca/sidebar.lua

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,9 @@ function M:handle_chat_content_received(params)
12051205
if content.state == "finished" then
12061206
self:_finalize_streaming_response()
12071207
self:_update_input_display()
1208+
elseif content.text == "Waiting for tool call approval" then
1209+
-- Handle implicit approval flow when toolCallPrepare was already received
1210+
self:render_tool_call(content, chat_id)
12081211
end
12091212
elseif content.type == "toolCallPrepare" then
12101213
self:_finalize_streaming_response()
@@ -1375,13 +1378,45 @@ function M:handle_chat_content_received(params)
13751378
end
13761379

13771380
function M:render_tool_call(tool_content, chat_id)
1381+
-- Handle explicit manual approval (toolCallRun with manualApproval flag)
13781382
if tool_content.type == "toolCallRun" and tool_content.manualApproval then
13791383
return require("eca.approve").approve_tool_call(tool_content, function()
13801384
self.mediator:send("chat/toolCallApprove", { chatId = chat_id, toolCallId = tool_content.id }, nil)
13811385
end, function()
13821386
self.mediator:send("chat/toolCallReject", { chatId = chat_id, toolCallId = tool_content.id }, nil)
13831387
end)
13841388
end
1389+
1390+
-- Handle implicit approval flow: progress message "Waiting for tool call approval"
1391+
-- with a previously prepared tool call (toolCallPrepare stored in _current_tool_call)
1392+
if tool_content.type == "progress"
1393+
and tool_content.text == "Waiting for tool call approval"
1394+
and self._current_tool_call
1395+
and self._current_tool_call.id
1396+
and not self._current_tool_call.approval_shown then
1397+
-- Mark as shown to avoid duplicate approval dialogs
1398+
self._current_tool_call.approval_shown = true
1399+
1400+
-- Store the tool call id in a local variable to avoid closure issues
1401+
local tool_call_id = self._current_tool_call.id
1402+
1403+
-- Build tool content from the prepared tool call for the approval dialog
1404+
-- Using field names expected by approve.lua
1405+
local prepared_tool_call = {
1406+
id = tool_call_id,
1407+
name = self._current_tool_call.name or "Tool call",
1408+
summary = self._current_tool_call.summary,
1409+
arguments = self._current_tool_call.arguments or "",
1410+
origin = "eca", -- default origin for implicit approval
1411+
details = self._current_tool_call.details,
1412+
}
1413+
1414+
return require("eca.approve").approve_tool_call(prepared_tool_call, function()
1415+
self.mediator:send("chat/toolCallApprove", { chatId = chat_id, toolCallId = tool_call_id }, nil)
1416+
end, function()
1417+
self.mediator:send("chat/toolCallReject", { chatId = chat_id, toolCallId = tool_call_id }, nil)
1418+
end)
1419+
end
13851420
end
13861421

13871422
---@param text string
@@ -1811,6 +1846,7 @@ function M:_handle_tool_call_prepare(content)
18111846
arguments = "",
18121847
details = {},
18131848
outputs = "",
1849+
approval_shown = false,
18141850
}
18151851
end
18161852

0 commit comments

Comments
 (0)