refactor: reorganize scratch files into subdirectories to fix main collision in make check

This commit is contained in:
stevef 2026-04-17 13:20:09 +02:00
parent 10f568f87e
commit c501efe6b6
3 changed files with 81 additions and 0 deletions

24
scratch/json/main.go Normal file
View file

@ -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)
}
}

15
scratch/match/main.go Normal file
View file

@ -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)
}

42
scratch/sanitize/main.go Normal file
View file

@ -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"))
}