Add list tools; normalize tool names and paths in transcript

This commit is contained in:
Ian Gulliver
2026-10-20 21:05:29 -07:00
parent e5a7fc4c1a
commit 53f20e40d3
9 changed files with 175 additions and 20 deletions
+34
View File
@@ -0,0 +1,34 @@
package dirlist
import (
"fmt"
"os"
"path/filepath"
"strings"
)
const keep = 64<<10 - 100
func List(path string) (string, error) {
entries, err := os.ReadDir(path)
if err != nil {
return "", err
}
if len(entries) == 0 {
return fmt.Sprintf("%s is empty.\n", path), nil
}
b := &strings.Builder{}
for i, e := range entries {
name := e.Name()
info, err := os.Stat(filepath.Join(path, name))
if err == nil && info.IsDir() {
name += "/"
}
if b.Len()+len(name)+1 > keep {
fmt.Fprintf(b, "(%d more entries not shown; output stops at 64 KiB)\n", len(entries)-i)
break
}
b.WriteString(name + "\n")
}
return b.String(), nil
}