diff --git a/internal/core/agent.go b/internal/core/agent.go index b9081b9..e08110f 100644 --- a/internal/core/agent.go +++ b/internal/core/agent.go @@ -235,10 +235,10 @@ func stringifyArguments(arguments json.RawMessage) string { } var out bytes.Buffer - if err := json.Indent(&out, arguments, "", " "); err == nil { - return out.String() + if err := json.Indent(&out, arguments, "", " "); err != nil { + return string(arguments) } - return string(arguments) + return out.String() } func emitProgress(observer TurnObserver, event ProgressEvent) { diff --git a/internal/tools/interceptors.go b/internal/tools/interceptors.go index c68afef..8338efd 100644 --- a/internal/tools/interceptors.go +++ b/internal/tools/interceptors.go @@ -91,9 +91,6 @@ func SafeJoin(root string, candidate string) (string, error) { // stringArg 从已解析参数中安全读取字符串值。 func stringArg(arguments map[string]any, key string) (string, bool) { - if arguments == nil { - return "", false - } value, ok := arguments[key] if !ok { return "", false diff --git a/internal/tools/registry.go b/internal/tools/registry.go index e20685c..9f637be 100644 --- a/internal/tools/registry.go +++ b/internal/tools/registry.go @@ -77,9 +77,7 @@ func (r *Registry) Execute(ctx context.Context, call provider.ToolCall, state St SessionID: state.SessionID, Arguments: call.Arguments, } - if len(call.Arguments) > 0 { - _ = json.Unmarshal(call.Arguments, &invocation.ParsedArgs) - } + _ = json.Unmarshal(call.Arguments, &invocation.ParsedArgs) for _, interceptor := range r.interceptors { if err := interceptor.Before(ctx, &invocation); err != nil { diff --git a/internal/tools/write_tool.go b/internal/tools/write_tool.go index 234e2b8..57bf4f1 100644 --- a/internal/tools/write_tool.go +++ b/internal/tools/write_tool.go @@ -77,10 +77,8 @@ func (t *WriteTool) Execute(_ context.Context, invocation Invocation) (Result, e } create := true - if invocation.ParsedArgs != nil { - if v, ok := invocation.ParsedArgs["create"].(bool); ok { - create = v - } + if v, ok := invocation.ParsedArgs["create"].(bool); ok { + create = v } return t.write(target, args.Content, args.Append, create)