From e47657533453270565caa5e94cfa59307d2a7970 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Sun, 15 Mar 2026 11:50:22 +0300 Subject: Chore: linter complaints --- tools/chain.go | 21 +++++++++------- tools/fs.go | 78 +++++++++++++++++++++++++++++++++------------------------- tools/pw.go | 6 ----- tools/tools.go | 13 +++++----- 4 files changed, 62 insertions(+), 56 deletions(-) (limited to 'tools') diff --git a/tools/chain.go b/tools/chain.go index b94d2f8..8a79eda 100644 --- a/tools/chain.go +++ b/tools/chain.go @@ -1,10 +1,12 @@ package tools import ( + "errors" "fmt" "os" "os/exec" "path/filepath" + "strconv" "strings" ) @@ -143,7 +145,7 @@ func ExecChain(command string) string { func execSingle(command, stdin string) (string, error) { parts := tokenize(command) if len(parts) == 0 { - return "", fmt.Errorf("empty command") + return "", errors.New("empty command") } name := parts[0] args := parts[1:] @@ -243,10 +245,10 @@ func execBuiltin(name string, args []string, stdin string) string { return fmt.Sprintf("[error] cd: %v", err) } if !info.IsDir() { - return fmt.Sprintf("[error] cd: not a directory: %s", dir) + return "[error] cd: not a directory: " + dir } cfg.FilePickerDir = abs - return fmt.Sprintf("Changed directory to: %s", cfg.FilePickerDir) + return "Changed directory to: " + cfg.FilePickerDir case "mkdir": if len(args) == 0 { return "[error] usage: mkdir [-p] " @@ -278,9 +280,9 @@ func execBuiltin(name string, args []string, stdin string) string { return fmt.Sprintf("[error] mkdir: %v", err) } if createParents { - return fmt.Sprintf("Created %s (with parents)", dirPath) + return "Created " + dirPath + " (with parents)" } - return fmt.Sprintf("Created %s", dirPath) + return "Created " + dirPath case "ls": dir := "." for _, a := range args { @@ -300,16 +302,17 @@ func execBuiltin(name string, args []string, stdin string) string { var out strings.Builder for _, e := range entries { info, _ := e.Info() - if e.IsDir() { + switch { + case e.IsDir(): fmt.Fprintf(&out, "d %-8s %s/\n", "-", e.Name()) - } else if info != nil { + case info != nil: size := info.Size() - sizeStr := fmt.Sprintf("%d", size) + sizeStr := strconv.FormatInt(size, 10) if size > 1024 { sizeStr = fmt.Sprintf("%.1fKB", float64(size)/1024) } fmt.Fprintf(&out, "f %-8s %s\n", sizeStr, e.Name()) - } else { + default: fmt.Fprintf(&out, "f %-8s %s\n", "?", e.Name()) } } diff --git a/tools/fs.go b/tools/fs.go index 7b33a3c..fb43084 100644 --- a/tools/fs.go +++ b/tools/fs.go @@ -3,6 +3,7 @@ package tools import ( "encoding/base64" "encoding/json" + "errors" "fmt" "gf-lt/models" "os" @@ -30,6 +31,9 @@ func SetMemoryStore(store MemoryStore, role string) { } func SetFSRoot(dir string) { + if cfg == nil { + return + } cfg.FilePickerDir = dir } @@ -55,7 +59,7 @@ func SetFSCwd(dir string) error { func resolvePath(rel string) (string, error) { if cfg.FilePickerDir == "" { - return "", fmt.Errorf("fs root not set") + return "", errors.New("fs root not set") } if filepath.IsAbs(rel) { abs := filepath.Clean(rel) @@ -104,11 +108,12 @@ func FsLs(args []string, stdin string) string { var out strings.Builder for _, e := range entries { info, _ := e.Info() - if e.IsDir() { + switch { + case e.IsDir(): fmt.Fprintf(&out, "d %-8s %s/\n", "-", e.Name()) - } else if info != nil { + case info != nil: fmt.Fprintf(&out, "f %-8s %s\n", humanSize(info.Size()), e.Name()) - } else { + default: fmt.Fprintf(&out, "f %-8s %s\n", "?", e.Name()) } } @@ -198,12 +203,15 @@ func FsWrite(args []string, stdin string) string { var path string var contentParts []string for _, a := range args { - if a == "-b" || a == "--base64" { + switch a { + case "-b", "--base64": b64 = true - } else if path == "" { - path = a - } else { - contentParts = append(contentParts, a) + default: + if path == "" { + path = a + } else { + contentParts = append(contentParts, a) + } } } if path == "" { @@ -296,7 +304,7 @@ func FsRm(args []string, stdin string) string { if err := os.RemoveAll(abs); err != nil { return fmt.Sprintf("[error] rm: %v", err) } - return fmt.Sprintf("Removed %s", args[0]) + return "Removed " + args[0] } func FsCp(args []string, stdin string) string { @@ -375,9 +383,9 @@ func FsMkdir(args []string, stdin string) string { return fmt.Sprintf("[error] mkdir: %v", err) } if createParents { - return fmt.Sprintf("Created %s (with parents)", dirPath) + return "Created " + dirPath + " (with parents)" } - return fmt.Sprintf("Created %s", dirPath) + return "Created " + dirPath } // Text processing commands @@ -435,7 +443,7 @@ func FsGrep(args []string, stdin string) string { } } if countOnly { - return fmt.Sprintf("%d", len(matched)) + return strconv.Itoa(len(matched)) } return strings.Join(matched, "\n") } @@ -487,11 +495,11 @@ func FsWc(args []string, stdin string) string { if len(args) > 0 { switch args[0] { case "-l": - return fmt.Sprintf("%d", lines) + return strconv.Itoa(lines) case "-w": - return fmt.Sprintf("%d", words) + return strconv.Itoa(words) case "-c": - return fmt.Sprintf("%d", chars) + return strconv.Itoa(chars) } } return fmt.Sprintf("%d lines, %d words, %d chars", lines, words, chars) @@ -502,9 +510,10 @@ func FsSort(args []string, stdin string) string { reverse := false numeric := false for _, a := range args { - if a == "-r" { + switch a { + case "-r": reverse = true - } else if a == "-n" { + case "-n": numeric = true } } @@ -615,10 +624,10 @@ func FsCd(args []string, stdin string) string { return fmt.Sprintf("[error] cd: %v", err) } if !info.IsDir() { - return fmt.Sprintf("[error] cd: not a directory: %s", dir) + return "[error] cd: not a directory: " + dir } cfg.FilePickerDir = abs - return fmt.Sprintf("Changed directory to: %s", cfg.FilePickerDir) + return "Changed directory to: " + cfg.FilePickerDir } func FsSed(args []string, stdin string) string { @@ -629,13 +638,15 @@ func FsSed(args []string, stdin string) string { var filePath string var pattern string for _, a := range args { - if a == "-i" || a == "--in-place" { + switch a { + case "-i", "--in-place": inPlace = true - } else if strings.HasPrefix(a, "s") && len(a) > 1 { - // This looks like a sed pattern - pattern = a - } else if filePath == "" && !strings.HasPrefix(a, "-") { - filePath = a + default: + if strings.HasPrefix(a, "s") && len(a) > 1 { + pattern = a + } else if filePath == "" && !strings.HasPrefix(a, "-") { + filePath = a + } } } if pattern == "" { @@ -650,8 +661,8 @@ func FsSed(args []string, stdin string) string { newStr := parts[1] global := len(parts) >= 3 && strings.Contains(parts[2], "g") var content string - if filePath != "" && stdin == "" { - // Read from file + switch { + case filePath != "" && stdin == "": abs, err := resolvePath(filePath) if err != nil { return fmt.Sprintf("[error] sed: %v", err) @@ -661,10 +672,9 @@ func FsSed(args []string, stdin string) string { return fmt.Sprintf("[error] sed: %v", err) } content = string(data) - } else if stdin != "" { - // Use stdin + case stdin != "": content = stdin - } else { + default: return "[error] sed: no input (use file path or pipe from stdin)" } // Apply sed replacement @@ -681,7 +691,7 @@ func FsSed(args []string, stdin string) string { if err := os.WriteFile(abs, []byte(content), 0644); err != nil { return fmt.Sprintf("[error] sed: %v", err) } - return fmt.Sprintf("Modified %s", filePath) + return "Modified " + filePath } return content } @@ -709,7 +719,7 @@ func FsMemory(args []string, stdin string) string { if err != nil { return fmt.Sprintf("[error] failed to store: %v", err) } - return fmt.Sprintf("Stored under topic: %s", topic) + return "Stored under topic: " + topic case "get": if len(args) < 2 { return "[error] usage: memory get " @@ -738,7 +748,7 @@ func FsMemory(args []string, stdin string) string { if err != nil { return fmt.Sprintf("[error] failed to forget: %v", err) } - return fmt.Sprintf("Deleted topic: %s", topic) + return "Deleted topic: " + topic default: return fmt.Sprintf("[error] unknown subcommand: %s. Use: store, get, list, topics, forget, delete", args[0]) } diff --git a/tools/pw.go b/tools/pw.go index 936da1a..05b1390 100644 --- a/tools/pw.go +++ b/tools/pw.go @@ -386,8 +386,6 @@ func pwDragBySelector(args map[string]string) []byte { if !browserStarted || page == nil { return []byte(`{"error": "Browser not started. Call pw_start first."}`) } - - // Get center coordinates of both elements using JavaScript fromJS := fmt.Sprintf(` function getCenter(selector) { const el = document.querySelector(selector); @@ -406,7 +404,6 @@ func pwDragBySelector(args map[string]string) []byte { } getCenter(%q) `, toSelector) - fromResult, err := page.Evaluate(fromJS) if err != nil { return []byte(fmt.Sprintf(`{"error": "failed to get from element: %s"}`, err.Error())) @@ -417,7 +414,6 @@ func pwDragBySelector(args map[string]string) []byte { } fromX := fromMap["x"].(float64) fromY := fromMap["y"].(float64) - toResult, err := page.Evaluate(toJS) if err != nil { return []byte(fmt.Sprintf(`{"error": "failed to get to element: %s"}`, err.Error())) @@ -428,8 +424,6 @@ func pwDragBySelector(args map[string]string) []byte { } toX := toMap["x"].(float64) toY := toMap["y"].(float64) - - // Perform the drag using coordinates mouse := page.Mouse() err = mouse.Move(fromX, fromY) if err != nil { diff --git a/tools/tools.go b/tools/tools.go index bf6976f..9baafd3 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -135,8 +135,8 @@ func (t *Tools) initAgentsB() { } func InitTools(cfg *config.Config, logger *slog.Logger, store storage.FullRepo) *Tools { - logger = logger - cfg = cfg + _ = logger + _ = cfg if cfg.PlaywrightEnabled { if err := CheckPlaywright(); err != nil { // slow, need a faster check if playwright install @@ -392,8 +392,7 @@ func runCmd(args map[string]string) []byte { // memory store | memory get | memory list | memory forget return []byte(FsMemory(append([]string{"store"}, rest...), "")) case "todo": - // todo create|read|update|delete - route to existing todo handlers - return []byte(handleTodoSubcommand(rest, args)) + return handleTodoSubcommand(rest, args) case "window", "windows": // window list - list all windows return listWindows(args) @@ -545,7 +544,7 @@ Actions: "toSelector": rest[1], }) default: - return []byte(fmt.Sprintf("unknown browser action: %s", action)) + return []byte("unknown browser action: " + action) } } @@ -816,7 +815,7 @@ func handleTodoSubcommand(args []string, originalArgs map[string]string) []byte } return todoDelete(map[string]string{"id": args[1]}) default: - return []byte(fmt.Sprintf("unknown todo subcommand: %s", subcmd)) + return []byte("unknown todo subcommand: " + subcmd) } } @@ -1296,7 +1295,7 @@ func summarizeChat(args map[string]string) []byte { if err != nil { return []byte("error: failed to marshal arguments") } - return []byte(data) + return data } // func removePlaywrightToolsFromBaseTools() { -- cgit v1.2.3