From 19018a31077b9244c1739a5a06cc556899cf5cba Mon Sep 17 00:00:00 2001 From: Vishnuvardhan Reddy Date: Sun, 1 Mar 2026 15:23:48 +0000 Subject: [PATCH] feat(audit): Phase 3 - Integrate audit logging with tools registry Add audit logging to ExecuteWithContext: - Log all tool executions with args, result, duration - Log tool not found errors - Include channel context for request tracing - Works alongside existing structured logging The audit logs capture: - Tool name and ID - Arguments (JSON-serializable) - Result content - Error status and async status - Execution duration in milliseconds --- pkg/tools/registry.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/tools/registry.go b/pkg/tools/registry.go index d37a093a8..f44c4f70f 100644 --- a/pkg/tools/registry.go +++ b/pkg/tools/registry.go @@ -7,6 +7,7 @@ import ( "sync" "time" + "github.com/sipeed/picoclaw/pkg/audit" "github.com/sipeed/picoclaw/pkg/logger" "github.com/sipeed/picoclaw/pkg/providers" ) @@ -61,6 +62,8 @@ func (r *ToolRegistry) ExecuteWithContext( map[string]any{ "tool": name, }) + // Audit the error + audit.LogError(ctx, "tool_not_found", fmt.Sprintf("tool %q not found", name), true) return ErrorResult(fmt.Sprintf("tool %q not found", name)).WithError(fmt.Errorf("tool not found")) } @@ -105,6 +108,17 @@ func (r *ToolRegistry) ExecuteWithContext( }) } + // Audit logging + ctx = audit.WithChannelContext(ctx, channel, chatID, "") + audit.LogToolCall(ctx, &audit.ToolCallData{ + ToolID: name, + Name: name, + Arguments: args, + Result: result.ForLLM, + IsError: result.IsError, + IsAsync: result.Async, + }, duration.Milliseconds()) + return result }