From d429dcdd7627f23f0c828be0f6c3db188d3e0d20 Mon Sep 17 00:00:00 2001 From: Hoshina Date: Fri, 27 Feb 2026 17:35:50 +0800 Subject: [PATCH] chore: fix go fmt formatting issues after rebase Apply go fmt to files that had formatting inconsistencies (alignment, indentation) after rebasing onto refactor/channel-system. --- pkg/agent/loop.go | 12 ++++++---- .../whatsapp_native/whatsapp_native.go | 23 ++++++++++++------- .../whatsapp_native/whatsapp_native_stub.go | 6 ++++- pkg/config/config.go | 4 ++-- pkg/utils/string.go | 6 ++--- 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index aacc28093..f9dead544 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -211,12 +211,16 @@ func (al *AgentLoop) Run(ctx context.Context) error { }) logger.InfoCF("agent", "Published outbound response", map[string]any{ - "channel": msg.Channel, - "chat_id": msg.ChatID, + "channel": msg.Channel, + "chat_id": msg.ChatID, "content_len": len(response), }) } else { - logger.DebugCF("agent", "Skipped outbound (message tool already sent)", map[string]any{"channel": msg.Channel}) + logger.DebugCF( + "agent", + "Skipped outbound (message tool already sent)", + map[string]any{"channel": msg.Channel}, + ) } } }() @@ -395,7 +399,7 @@ func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage) "agent_id": agent.ID, "session_key": sessionKey, "matched_by": route.MatchedBy, - }) + }) return al.runAgentLoop(ctx, agent, processOptions{ SessionKey: sessionKey, diff --git a/pkg/channels/whatsapp_native/whatsapp_native.go b/pkg/channels/whatsapp_native/whatsapp_native.go index 254f15918..23115bda7 100644 --- a/pkg/channels/whatsapp_native/whatsapp_native.go +++ b/pkg/channels/whatsapp_native/whatsapp_native.go @@ -18,15 +18,14 @@ import ( "time" "github.com/mdp/qrterminal/v3" - _ "modernc.org/sqlite" - "go.mau.fi/whatsmeow" + "go.mau.fi/whatsmeow/proto/waE2E" "go.mau.fi/whatsmeow/store/sqlstore" + "go.mau.fi/whatsmeow/types" "go.mau.fi/whatsmeow/types/events" waLog "go.mau.fi/whatsmeow/util/log" - "go.mau.fi/whatsmeow/proto/waE2E" - "go.mau.fi/whatsmeow/types" "google.golang.org/protobuf/proto" + _ "modernc.org/sqlite" "github.com/sipeed/picoclaw/pkg/bus" "github.com/sipeed/picoclaw/pkg/channels" @@ -61,7 +60,11 @@ type WhatsAppNativeChannel struct { // NewWhatsAppNativeChannel creates a WhatsApp channel that uses whatsmeow for connection. // storePath is the directory for the SQLite session store (e.g. workspace/whatsapp). -func NewWhatsAppNativeChannel(cfg config.WhatsAppConfig, bus *bus.MessageBus, storePath string) (channels.Channel, error) { +func NewWhatsAppNativeChannel( + cfg config.WhatsAppConfig, + bus *bus.MessageBus, + storePath string, +) (channels.Channel, error) { base := channels.NewBaseChannel("whatsapp_native", cfg, bus, cfg.AllowFrom, channels.WithMaxMessageLength(65536)) if storePath == "" { storePath = "whatsapp" @@ -77,7 +80,7 @@ func NewWhatsAppNativeChannel(cfg config.WhatsAppConfig, bus *bus.MessageBus, st func (c *WhatsAppNativeChannel) Start(ctx context.Context) error { logger.InfoCF("whatsapp", "Starting WhatsApp native channel (whatsmeow)", map[string]any{"store": c.storePath}) - if err := os.MkdirAll(c.storePath, 0700); err != nil { + if err := os.MkdirAll(c.storePath, 0o700); err != nil { return fmt.Errorf("create session store dir: %w", err) } @@ -173,7 +176,7 @@ func (c *WhatsAppNativeChannel) Stop(ctx context.Context) error { return nil } -func (c *WhatsAppNativeChannel) eventHandler(evt interface{}) { +func (c *WhatsAppNativeChannel) eventHandler(evt any) { switch evt.(type) { case *events.Message: c.handleIncoming(evt.(*events.Message)) @@ -284,7 +287,11 @@ func (c *WhatsAppNativeChannel) handleIncoming(evt *events.Message) { return } - logger.DebugCF("whatsapp", "WhatsApp message received", map[string]any{"sender_id": senderID, "content_preview": utils.Truncate(content, 50)}) + logger.DebugCF( + "whatsapp", + "WhatsApp message received", + map[string]any{"sender_id": senderID, "content_preview": utils.Truncate(content, 50)}, + ) c.HandleMessage(c.runCtx, peer, messageID, senderID, chatID, content, mediaPaths, metadata, sender) } diff --git a/pkg/channels/whatsapp_native/whatsapp_native_stub.go b/pkg/channels/whatsapp_native/whatsapp_native_stub.go index d57a3b6e7..984af23e7 100644 --- a/pkg/channels/whatsapp_native/whatsapp_native_stub.go +++ b/pkg/channels/whatsapp_native/whatsapp_native_stub.go @@ -12,6 +12,10 @@ import ( // NewWhatsAppNativeChannel returns an error when the binary was not built with -tags whatsapp_native. // Build with: go build -tags whatsapp_native ./cmd/... -func NewWhatsAppNativeChannel(cfg config.WhatsAppConfig, bus *bus.MessageBus, storePath string) (channels.Channel, error) { +func NewWhatsAppNativeChannel( + cfg config.WhatsAppConfig, + bus *bus.MessageBus, + storePath string, +) (channels.Channel, error) { return nil, fmt.Errorf("whatsapp native not compiled in; build with -tags whatsapp_native") } diff --git a/pkg/config/config.go b/pkg/config/config.go index 9a6fda58a..01511864b 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -224,9 +224,9 @@ type PlaceholderConfig struct { type WhatsAppConfig struct { Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_WHATSAPP_ENABLED"` - BridgeURL string `json:"bridge_url" env:"PICOCLAW_CHANNELS_WHATSAPP_BRIDGE_URL"` + BridgeURL string `json:"bridge_url" env:"PICOCLAW_CHANNELS_WHATSAPP_BRIDGE_URL"` UseNative bool `json:"use_native" env:"PICOCLAW_CHANNELS_WHATSAPP_USE_NATIVE"` - SessionStorePath string `json:"session_store_path" env:"PICOCLAW_CHANNELS_WHATSAPP_SESSION_STORE_PATH"` + SessionStorePath string `json:"session_store_path" env:"PICOCLAW_CHANNELS_WHATSAPP_SESSION_STORE_PATH"` AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_WHATSAPP_ALLOW_FROM"` } diff --git a/pkg/utils/string.go b/pkg/utils/string.go index edc413972..6a78f59fe 100644 --- a/pkg/utils/string.go +++ b/pkg/utils/string.go @@ -5,8 +5,8 @@ import ( "unicode" ) -// SanitizeMessage removes Unicode control characters, format characters (RTL overrides, -// zero-width characters), and other non-graphic characters that could confuse an LLM +// SanitizeMessage removes Unicode control characters, format characters (RTL overrides, +// zero-width characters), and other non-graphic characters that could confuse an LLM // or cause display issues in the agent UI. func SanitizeMessageContent(input string) string { var sb strings.Builder @@ -16,7 +16,7 @@ func SanitizeMessageContent(input string) string { for _, r := range input { // unicode.IsGraphic returns true if the rune is a Unicode graphic character. // This includes letters, marks, numbers, punctuation, and symbols. - // It excludes control characters (Cc), format characters (Cf), + // It excludes control characters (Cc), format characters (Cf), // surrogates (Cs), and private use (Co). if unicode.IsGraphic(r) || r == '\n' || r == '\r' || r == '\t' { sb.WriteRune(r)