From c501efe6b611092f41ccb48eef3d0c5f17e0e051 Mon Sep 17 00:00:00 2001 From: stevef Date: Fri, 17 Apr 2026 13:20:09 +0200 Subject: [PATCH] refactor: reorganize scratch files into subdirectories to fix main collision in make check --- scratch/json/main.go | 24 +++++++++++++++++++++++ scratch/match/main.go | 15 ++++++++++++++ scratch/sanitize/main.go | 42 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 scratch/json/main.go create mode 100644 scratch/match/main.go create mode 100644 scratch/sanitize/main.go diff --git a/scratch/json/main.go b/scratch/json/main.go new file mode 100644 index 000000000..e2d3877c4 --- /dev/null +++ b/scratch/json/main.go @@ -0,0 +1,24 @@ +package main + +import ( + "encoding/json" + "fmt" +) + +type Config struct { + AllowedTools map[string]bool `json:"allowed_tools"` +} + +func main() { + data := []byte(`{"allowed_tools": {"hdn-server": true}}`) + var cfg Config + err := json.Unmarshal(data, &cfg) + if err != nil { + fmt.Println(err) + return + } + fmt.Printf("Config: %+v\n", cfg) + for w, ok := range cfg.AllowedTools { + fmt.Printf("w: %q, ok: %v\n", w, ok) + } +} diff --git a/scratch/match/main.go b/scratch/match/main.go new file mode 100644 index 000000000..dc02236e7 --- /dev/null +++ b/scratch/match/main.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + "strings" +) + +func main() { + tool := "mcp_hdn-server_weather" + w := "hdn-server" + match := strings.HasPrefix(tool, "mcp_"+w+"_") || + strings.HasPrefix(tool, "tool_"+w+"_") || + strings.HasPrefix(tool, w+"_") + fmt.Printf("Match: %v\n", match) +} diff --git a/scratch/sanitize/main.go b/scratch/sanitize/main.go new file mode 100644 index 000000000..e08c3552a --- /dev/null +++ b/scratch/sanitize/main.go @@ -0,0 +1,42 @@ +package main + +import ( + "fmt" + "strings" +) + +func sanitizeIdentifierComponent(s string) string { + s = strings.ToLower(s) + var b strings.Builder + b.Grow(len(s)) + prevUnderscore := false + for _, r := range s { + isAllowed := (r >= 'a' && r <= 'z') || + (r >= '0' && r <= '9') || + r == '_' || r == '-' + if !isAllowed { + if !prevUnderscore { + b.WriteRune('_') + prevUnderscore = true + } + continue + } + if r == '_' { + if prevUnderscore { + continue + } + prevUnderscore = true + } else { + prevUnderscore = false + } + b.WriteRune(r) + } + result := strings.Trim(b.String(), "_") + if result == "" { + result = "unnamed" + } + return result +} +func main() { + fmt.Println(sanitizeIdentifierComponent("hdn-server")) +}