Skip to content

Commit d2c4f3e

Browse files
committed
Display the diff in the chat window
1 parent 6d4a020 commit d2c4f3e

File tree

3 files changed

+53
-12
lines changed

3 files changed

+53
-12
lines changed

lua/eca/init.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function M._init(id)
171171
local sidebar = M.sidebars[id]
172172

173173
if not sidebar then
174-
sidebar = Sidebar:new(id)
174+
sidebar = Sidebar.new(id)
175175
M.sidebars[id] = sidebar
176176
end
177177
M.current = { sidebar = sidebar }
@@ -235,9 +235,7 @@ function M.setup(opts)
235235
return
236236
end
237237

238-
-- Initialize logger with configuration
239238
require("eca.logger").setup(Config.options.log)
240-
241239
require("eca.highlights").setup()
242240
require("eca.commands").setup()
243241

lua/eca/sidebar.lua

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ local SAFETY_MARGIN = 2 -- Extra margin to prevent "Not enough room
4141

4242
---@param id integer Tab ID
4343
---@return eca.Sidebar
44-
function M:new(id)
44+
function M.new(id)
4545
local instance = setmetatable({}, M)
4646
instance.id = id
4747
instance.containers = {}
@@ -1223,13 +1223,16 @@ function M:_handle_server_content(params)
12231223
-- IMPORTANT: Return immediately - do NOT display anything for toolCallPrepare
12241224
return
12251225
elseif content.type == "toolCalled" then
1226-
1227-
1226+
-- Add diff to current tool call if present in toolCalled content
1227+
if self._current_tool_call and content.details and content.details.diff then
1228+
self._current_tool_call.details = content.details
1229+
end
1230+
12281231
-- Show the final accumulated tool call if we have one
12291232
if self._is_tool_call_streaming and self._current_tool_call then
12301233
self:_display_tool_call()
12311234
end
1232-
1235+
12331236
-- Show the tool result
12341237
local tool_text = string.format("✅ **Tool Result**: %s", content.name or "unknown")
12351238
if content.outputs and #content.outputs > 0 then
@@ -1528,6 +1531,10 @@ function M:_handle_tool_call_prepare(content)
15281531
if content.argumentsText then
15291532
self._current_tool_call.arguments = (self._current_tool_call.arguments or "") .. content.argumentsText
15301533
end
1534+
1535+
if content.details then
1536+
self._current_tool_call.details = content.details
1537+
end
15311538
end
15321539

15331540
function M:_display_tool_call()
@@ -1539,6 +1546,11 @@ function M:_display_tool_call()
15391546
tool_text = tool_text .. "\n```json\n" .. self._current_tool_call.arguments .. "\n```"
15401547
end
15411548

1549+
1550+
if self._current_tool_call.details and self._current_tool_call.details.diff then
1551+
tool_text = tool_text .. "\n\n**Diff**:\n```diff\n" .. self._current_tool_call.details.diff .. "\n```"
1552+
end
1553+
15421554
self:_add_message("assistant", tool_text)
15431555
end
15441556

@@ -1547,4 +1559,4 @@ function M:_finalize_tool_call()
15471559
self._is_tool_call_streaming = false
15481560
end
15491561

1550-
return M
1562+
return M

lua/eca/types.lua

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,50 @@
11
---@meta
2+
23
---@class eca.ChatContext
34
---@field type string
45
---@field path? string
5-
---@field lines_range? {start: integer, end: integer}
6+
---@field linesRange? {start: integer, end: integer}
67
---@field url? string
78
---@field uri? string
89
---@field name? string
910
---@field description? string
10-
---@field mime_type? string
11+
---@field mimeType? string
1112
---@field server string
12-
---
13-
---
13+
1414
---@class eca.ChatCommand
1515
---@field name string
1616
---@field description string
1717
---@field help string
1818
---@field type "mcp-prompt"|"native"
1919
---@field arguments {name: string, description?: string, required: boolean}[]
20+
21+
---@alias eca.ToolCallOrigin "mcp"|"native"
22+
23+
---@alias eca.ToolCallDetails eca.FileChangedDetails
24+
25+
---@class eca.FileChangedDetails
26+
---@field type 'fileChange'
27+
---@field path string the file path of this file change
28+
---@field diff string the content diff of this file change
29+
---@field linesAdded integer the count of lines added in this change
30+
---@field linesRemoved integer the count of lines removed in this change
31+
32+
---@class eca.ToolCallRun
33+
---@field type 'toolCallRun'
34+
---@field origin eca.ToolCallOrigin
35+
---@field id string the id of the tool call
36+
---@field name string name of the tool
37+
---@field arguments {[string]: string} arguments of the tool call
38+
---@field manualApproval boolean whether the call requires manual approval from the user
39+
---@field summary string summary text to present about this tool call
40+
---@field details eca.ToolCallDetails extra details for the call. clients may use this to present a different UX for this tool call.
41+
42+
---@class eca.ToolCalled
43+
---@field type 'toolCalled'
44+
---@field id string the id of the tool call
45+
---@field name string name of the tool
46+
---@field arguments {[string]: string} arguments of the tool call
47+
---@field errors boolean was there an error calling the tool
48+
---@field outputs {type: 'text', text: string}[] the result of the tool call
49+
---@field summary? string summary text to present about the tool call
50+
---@field details? eca.ToolCallDetails extra details about the call

0 commit comments

Comments
 (0)