Skip to content

Commit 069a152

Browse files
committed
refactor: add more granular logs
1 parent 9724e13 commit 069a152

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

lua/codecompanion/acp/init.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ function Connection:connect_and_authenticate()
142142
end
143143

144144
self._initialized = true
145+
log:debug("[acp] Initialized (protocol_version=%s)", initialized.protocolVersion or "unknown")
145146

146147
api.nvim_create_autocmd("VimLeavePre", {
147148
group = api.nvim_create_augroup("codecompanion.acp.disconnect", { clear = false }),
@@ -234,6 +235,7 @@ function Connection:_authenticate()
234235
self._authenticated = true
235236
end
236237

238+
log:debug("[acp] Authenticated")
237239
return true
238240
end
239241

@@ -398,6 +400,7 @@ function Connection:_establish_session()
398400
apply_session_metadata(new_session, "New session")
399401
end
400402

403+
log:debug("[acp] Session established: %s", self.session_id)
401404
return true
402405
end
403406

@@ -518,6 +521,7 @@ function Connection:start_agent_process()
518521
end
519522

520523
self._state.handle = sysobj
524+
log:debug("[acp] Process started: %s", table.concat(self.adapter_modified.command, " "))
521525
return true
522526
end
523527

@@ -913,6 +917,8 @@ end
913917
---@param code number
914918
---@param signal number
915919
function Connection:handle_process_exit(code, signal)
920+
log:debug("[acp] Process exited (code=%s, signal=%s)", code, signal)
921+
916922
if self.adapter_modified and self.adapter_modified.handlers and self.adapter_modified.handlers.on_exit then
917923
self.adapter_modified.handlers.on_exit(self.adapter_modified, code)
918924
end

lua/codecompanion/interactions/chat/acp/handler.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ end
221221
function ACPHandler:process_tool_call(tool_call)
222222
local id = tool_call.toolCallId
223223

224-
log:trace("[ACP::Handler] Processing tool call %s", tool_call)
224+
log:debug("[ACP::Handler] Processing tool call %s", utils.truncate(tool_call))
225225

226226
local merged = merge_tool_call(self.tools[id], tool_call)
227227
tool_call = merged
@@ -298,7 +298,15 @@ function ACPHandler:handle_permission_request(request)
298298
end
299299
end
300300

301-
log:debug("[ACPHandler::handle_permission_request] Asking for approval")
301+
log:debug(
302+
"[ACP::Handler] Permission Request\n id: %s\n kind: %s\n %s\n options: %s",
303+
tool_call and tool_call.toolCallId or "unknown",
304+
tool_call and tool_call.kind or "unknown",
305+
tool_call and tool_call.title or "No title",
306+
vim.inspect(vim.tbl_map(function(o)
307+
return o.kind
308+
end, request.options or {}))
309+
)
302310

303311
return require("codecompanion.interactions.chat.acp.request_permission").confirm(self.chat, request)
304312
end

lua/codecompanion/utils/init.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,27 @@ function M.pluralize(count, word)
270270
return count == 1 and word or word .. "s"
271271
end
272272

273+
---Deep copy a table, truncating any string values
274+
---@param tbl table
275+
---@param max_len? number
276+
---@return table
277+
function M.truncate(tbl, max_len)
278+
if not max_len then
279+
max_len = 255
280+
end
281+
282+
local output = {}
283+
for k, v in pairs(tbl) do
284+
if type(v) == "table" then
285+
output[k] = M.truncate(v, max_len)
286+
elseif type(v) == "string" and #v > max_len then
287+
output[k] = v:sub(1, max_len) .. "...[truncated]"
288+
else
289+
output[k] = v
290+
end
291+
end
292+
293+
return output
294+
end
295+
273296
return M

0 commit comments

Comments
 (0)