Skip to content

Commit 9d4aa62

Browse files
committed
fix(chat): hide tool context for ACP chats
1 parent f70759e commit 9d4aa62

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

lua/codecompanion/interactions/chat/tool_registry.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ end
5656
---@param opts? table Optional parameters for the context_item
5757
---@return nil
5858
local function add_context(chat, id, opts)
59+
opts = opts or {}
60+
if chat.adapter and chat.adapter.type == "acp" and opts.visible == nil then
61+
opts.visible = false
62+
end
63+
5964
chat.context:add({
6065
source = "tool",
6166
name = "tool",
@@ -121,7 +126,7 @@ end
121126
function ToolRegistry:add_single_tool(tool, opts)
122127
opts = opts or {}
123128
if opts.visible == nil then
124-
opts.visible = true
129+
opts.visible = self.chat.adapter and self.chat.adapter.type ~= "acp"
125130
end
126131

127132
local tool_config = opts.config or config.interactions.chat.tools[tool]

tests/interactions/chat/tools/test_tool_registry.lua

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,63 @@ T["ToolRegistry"][":add"]["renders tool in the chat buffer"] = function()
6060
h.expect_contains("func", content)
6161
end
6262

63+
T["ToolRegistry"][":add"]["hides tool context for ACP chats"] = function()
64+
child.lua([[
65+
_G.chat = h.setup_chat_buffer({}, {
66+
name = "test_acp",
67+
config = {
68+
name = "test_acp",
69+
type = "acp",
70+
roles = { user = "user", assistant = "assistant" },
71+
handlers = {
72+
form_messages = function()
73+
return {}
74+
end,
75+
},
76+
},
77+
})
78+
_G.chat.tool_registry:add("func")
79+
_G.chat.context:render()
80+
_G.buf_lines = h.get_buf_lines(_G.chat.bufnr)
81+
]])
82+
83+
local lines = child.lua_get([[_G.buf_lines]])
84+
local content = table.concat(lines, "\n")
85+
86+
h.expect_tbl_contains("func", child.lua_get([[_G.chat.tool_registry.in_use]]))
87+
h.eq(nil, content:find("func", 1, true))
88+
end
89+
90+
T["ToolRegistry"][":add"]["hides tool group context for ACP chats"] = function()
91+
child.lua([[
92+
_G.chat = h.setup_chat_buffer({}, {
93+
name = "test_acp",
94+
config = {
95+
name = "test_acp",
96+
type = "acp",
97+
roles = { user = "user", assistant = "assistant" },
98+
handlers = {
99+
form_messages = function()
100+
return {}
101+
end,
102+
},
103+
},
104+
})
105+
_G.chat.tool_registry:add("senior_dev")
106+
_G.chat.context:render()
107+
_G.buf_lines = h.get_buf_lines(_G.chat.bufnr)
108+
]])
109+
110+
local lines = child.lua_get([[_G.buf_lines]])
111+
local content = table.concat(lines, "\n")
112+
113+
h.expect_tbl_contains("func", child.lua_get([[_G.chat.tool_registry.in_use]]))
114+
h.expect_tbl_contains("cmd", child.lua_get([[_G.chat.tool_registry.in_use]]))
115+
h.eq(nil, content:find("senior_dev", 1, true))
116+
h.eq(nil, content:find("func", 1, true))
117+
h.eq(nil, content:find("cmd", 1, true))
118+
end
119+
63120
T["ToolRegistry"][":add"]["returns nil for unknown name"] = function()
64121
local result = child.lua_get([[_G.chat.tool_registry:add("nonexistent_tool_xyz")]])
65122

0 commit comments

Comments
 (0)