From 6cde142fcea9820db6a9cb1267b5cf5da74b6a6e Mon Sep 17 00:00:00 2001 From: dj-oyu <68707227+dj-oyu@users.noreply.github.com> Date: Mon, 2 Mar 2026 03:55:59 +0900 Subject: [PATCH] fix: resolve lint errors (gci, golines, unused variable) - Fix import ordering (gci) in 8 files - Break long line in openai_compat/provider.go (golines) - Remove unused absolutePathPattern in tools/shell.go Co-Authored-By: Claude Opus 4.6 --- pkg/channels/discord/discord.go | 1 - pkg/channels/interfaces.go | 1 - pkg/channels/manager.go | 2 - pkg/channels/pico/pico.go | 1 - pkg/channels/slack/slack.go | 1 - pkg/channels/telegram/telegram.go | 1 - pkg/providers/openai_compat/provider.go | 12 ++- pkg/tools/shell.go | 104 +++++++++++------------- pkg/utils/string.go | 1 - 9 files changed, 60 insertions(+), 64 deletions(-) diff --git a/pkg/channels/discord/discord.go b/pkg/channels/discord/discord.go index 64e36af91..57070c6d7 100644 --- a/pkg/channels/discord/discord.go +++ b/pkg/channels/discord/discord.go @@ -255,7 +255,6 @@ func (c *DiscordChannel) SendWithID(ctx context.Context, chatID string, content } } - // EditMessage implements channels.MessageEditor. func (c *DiscordChannel) EditMessage(ctx context.Context, chatID string, messageID string, content string) error { _, err := c.session.ChannelMessageEdit(chatID, messageID, content) diff --git a/pkg/channels/interfaces.go b/pkg/channels/interfaces.go index cc735426a..4421e7662 100644 --- a/pkg/channels/interfaces.go +++ b/pkg/channels/interfaces.go @@ -28,7 +28,6 @@ type MessageSenderWithID interface { SendWithID(ctx context.Context, chatID string, content string) (messageID string, err error) } - // PlaceholderCapable — channels that can send a placeholder message // (e.g. "Thinking... 💭") that will later be edited to the actual response. // The channel MUST also implement MessageEditor for the placeholder to be useful. diff --git a/pkg/channels/manager.go b/pkg/channels/manager.go index d5bd4f73e..f6ba2c2cc 100644 --- a/pkg/channels/manager.go +++ b/pkg/channels/manager.go @@ -63,7 +63,6 @@ type statusMsgEntry struct { createdAt time.Time } - // channelRateConfig maps channel name to per-second rate limit. var channelRateConfig = map[string]float64{ "telegram": 20, @@ -559,7 +558,6 @@ func (m *Manager) handleTaskStatusSend(ctx context.Context, name string, w *chan _ = w.ch.Send(ctx, msg) } - // sendWithRetry sends a message through the channel with rate limiting and // retry logic. It classifies errors to determine the retry strategy: // - ErrNotRunning / ErrSendFailed: permanent, no retry diff --git a/pkg/channels/pico/pico.go b/pkg/channels/pico/pico.go index 0fa775212..4394d472a 100644 --- a/pkg/channels/pico/pico.go +++ b/pkg/channels/pico/pico.go @@ -170,7 +170,6 @@ func (c *PicoChannel) SendWithID(ctx context.Context, chatID string, content str return msgID, nil } - // EditMessage implements channels.MessageEditor. func (c *PicoChannel) EditMessage(ctx context.Context, chatID string, messageID string, content string) error { outMsg := newMessage(TypeMessageUpdate, map[string]any{ diff --git a/pkg/channels/slack/slack.go b/pkg/channels/slack/slack.go index 6b2f3bf84..3b30ce3c7 100644 --- a/pkg/channels/slack/slack.go +++ b/pkg/channels/slack/slack.go @@ -318,7 +318,6 @@ func (c *SlackChannel) handleMessageEvent(ev *slackevents.MessageEvent) { var mediaPaths []string - scope := channels.BuildMediaScope("slack", chatID, messageTS) // Helper to register a local file with the media store diff --git a/pkg/channels/telegram/telegram.go b/pkg/channels/telegram/telegram.go index b58e8bfd7..c302ddb68 100644 --- a/pkg/channels/telegram/telegram.go +++ b/pkg/channels/telegram/telegram.go @@ -221,7 +221,6 @@ func (c *TelegramChannel) SendWithID(ctx context.Context, chatID string, content return fmt.Sprintf("%d", sent.MessageID), nil } - // StartTyping implements channels.TypingCapable. // It sends ChatAction(typing) immediately and then repeats every 4 seconds // (Telegram's typing indicator expires after ~5s) in a background goroutine. diff --git a/pkg/providers/openai_compat/provider.go b/pkg/providers/openai_compat/provider.go index 302f481fb..ef900af95 100644 --- a/pkg/providers/openai_compat/provider.go +++ b/pkg/providers/openai_compat/provider.go @@ -596,7 +596,17 @@ func normalizeModel(model, apiBase string) string { prefix := strings.ToLower(before) switch prefix { - case "openai", "moonshot", "nvidia", "groq", "ollama", "deepseek", "google", "openrouter", "zhipu", "minimax", "mistral": + case "openai", + "moonshot", + "nvidia", + "groq", + "ollama", + "deepseek", + "google", + "openrouter", + "zhipu", + "minimax", + "mistral": return after default: return model diff --git a/pkg/tools/shell.go b/pkg/tools/shell.go index e58f249ff..98eb4c388 100644 --- a/pkg/tools/shell.go +++ b/pkg/tools/shell.go @@ -134,61 +134,55 @@ type ExecTool struct { bgCtx context.Context } -var ( - defaultDenyPatterns = []*regexp.Regexp{ - regexp.MustCompile(`\brm\s+-[rf]{1,2}\b`), - regexp.MustCompile(`\bdel\s+/[fq]\b`), - regexp.MustCompile(`\brmdir\s+/s\b`), - // Match disk wiping commands (must be followed by space/args) - regexp.MustCompile( - `\b(format|mkfs|diskpart)\b\s`, - ), - regexp.MustCompile(`\bdd\s+if=`), - regexp.MustCompile(`>\s*/dev/sd[a-z]\b`), // Block writes to disk devices (but allow /dev/null) - regexp.MustCompile(`\b(shutdown|reboot|poweroff)\b`), - regexp.MustCompile(`:\(\)\s*\{.*\};\s*:`), - regexp.MustCompile(`\$\([^)]+\)`), - regexp.MustCompile(`\$\{[^}]+\}`), - regexp.MustCompile("`[^`]+`"), - regexp.MustCompile(`\|\s*sh\b`), - regexp.MustCompile(`\|\s*bash\b`), - regexp.MustCompile(`;\s*rm\s+-[rf]`), - regexp.MustCompile(`&&\s*rm\s+-[rf]`), - regexp.MustCompile(`\|\|\s*rm\s+-[rf]`), - regexp.MustCompile(`>\s*/dev/null\s*>&?\s*\d?`), - regexp.MustCompile(`<<\s*EOF`), - regexp.MustCompile(`\$\(\s*cat\s+`), - regexp.MustCompile(`\$\(\s*curl\s+`), - regexp.MustCompile(`\$\(\s*wget\s+`), - regexp.MustCompile(`\$\(\s*which\s+`), - regexp.MustCompile(`\bsudo\b`), - regexp.MustCompile(`\bchmod\s+[0-7]{3,4}\b`), - regexp.MustCompile(`\bchown\b`), - regexp.MustCompile(`\bpkill\b`), - regexp.MustCompile(`\bkillall\b`), - regexp.MustCompile(`\bkill\s+-[9]\b`), - regexp.MustCompile(`\bcurl\b.*\|\s*(sh|bash)`), - regexp.MustCompile(`\bwget\b.*\|\s*(sh|bash)`), - regexp.MustCompile(`\bnpm\s+install\s+-g\b`), - regexp.MustCompile(`\bpip\s+install\s+--user\b`), - regexp.MustCompile(`\bapt\s+(install|remove|purge)\b`), - regexp.MustCompile(`\byum\s+(install|remove)\b`), - regexp.MustCompile(`\bdnf\s+(install|remove)\b`), - regexp.MustCompile(`\bdocker\s+run\b`), - regexp.MustCompile(`\bdocker\s+exec\b`), - regexp.MustCompile(`\bgit\s+push\b`), - regexp.MustCompile(`\bgit\s+force\b`), - regexp.MustCompile(`\bgit\s+checkout\b`), - regexp.MustCompile(`\bgit\s+switch\b`), - regexp.MustCompile(`\bssh\b.*@`), - regexp.MustCompile(`\beval\b`), - regexp.MustCompile(`\bsource\s+.*\.sh\b`), - } - - // absolutePathPattern matches absolute file paths in commands (Unix and Windows). - absolutePathPattern = regexp.MustCompile(`[A-Za-z]:\\[^\\\"']+|/[^\s\"']+`) -) - +var defaultDenyPatterns = []*regexp.Regexp{ + regexp.MustCompile(`\brm\s+-[rf]{1,2}\b`), + regexp.MustCompile(`\bdel\s+/[fq]\b`), + regexp.MustCompile(`\brmdir\s+/s\b`), + // Match disk wiping commands (must be followed by space/args) + regexp.MustCompile( + `\b(format|mkfs|diskpart)\b\s`, + ), + regexp.MustCompile(`\bdd\s+if=`), + regexp.MustCompile(`>\s*/dev/sd[a-z]\b`), // Block writes to disk devices (but allow /dev/null) + regexp.MustCompile(`\b(shutdown|reboot|poweroff)\b`), + regexp.MustCompile(`:\(\)\s*\{.*\};\s*:`), + regexp.MustCompile(`\$\([^)]+\)`), + regexp.MustCompile(`\$\{[^}]+\}`), + regexp.MustCompile("`[^`]+`"), + regexp.MustCompile(`\|\s*sh\b`), + regexp.MustCompile(`\|\s*bash\b`), + regexp.MustCompile(`;\s*rm\s+-[rf]`), + regexp.MustCompile(`&&\s*rm\s+-[rf]`), + regexp.MustCompile(`\|\|\s*rm\s+-[rf]`), + regexp.MustCompile(`>\s*/dev/null\s*>&?\s*\d?`), + regexp.MustCompile(`<<\s*EOF`), + regexp.MustCompile(`\$\(\s*cat\s+`), + regexp.MustCompile(`\$\(\s*curl\s+`), + regexp.MustCompile(`\$\(\s*wget\s+`), + regexp.MustCompile(`\$\(\s*which\s+`), + regexp.MustCompile(`\bsudo\b`), + regexp.MustCompile(`\bchmod\s+[0-7]{3,4}\b`), + regexp.MustCompile(`\bchown\b`), + regexp.MustCompile(`\bpkill\b`), + regexp.MustCompile(`\bkillall\b`), + regexp.MustCompile(`\bkill\s+-[9]\b`), + regexp.MustCompile(`\bcurl\b.*\|\s*(sh|bash)`), + regexp.MustCompile(`\bwget\b.*\|\s*(sh|bash)`), + regexp.MustCompile(`\bnpm\s+install\s+-g\b`), + regexp.MustCompile(`\bpip\s+install\s+--user\b`), + regexp.MustCompile(`\bapt\s+(install|remove|purge)\b`), + regexp.MustCompile(`\byum\s+(install|remove)\b`), + regexp.MustCompile(`\bdnf\s+(install|remove)\b`), + regexp.MustCompile(`\bdocker\s+run\b`), + regexp.MustCompile(`\bdocker\s+exec\b`), + regexp.MustCompile(`\bgit\s+push\b`), + regexp.MustCompile(`\bgit\s+force\b`), + regexp.MustCompile(`\bgit\s+checkout\b`), + regexp.MustCompile(`\bgit\s+switch\b`), + regexp.MustCompile(`\bssh\b.*@`), + regexp.MustCompile(`\beval\b`), + regexp.MustCompile(`\bsource\s+.*\.sh\b`), +} func NewExecTool(workingDir string, restrict bool) (*ExecTool, error) { return NewExecToolWithConfig(workingDir, restrict, nil) diff --git a/pkg/utils/string.go b/pkg/utils/string.go index 21654ebe6..4a3af779c 100644 --- a/pkg/utils/string.go +++ b/pkg/utils/string.go @@ -95,7 +95,6 @@ func DetectRepetitionLoop(text string) bool { return ratio < repetitionUniqueThreshold } - // SanitizeMessageContent 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.