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
+37
View File
@@ -12,6 +12,7 @@ import (
"strings"
"unicode/utf8"
"g.fc.run/ai/byre/internal/dirlist"
"g.fc.run/ai/byre/internal/grep"
"g.fc.run/ai/byre/internal/mcp"
)
@@ -19,6 +20,9 @@ import (
const grepDescription = "Search files for lines matching a regular expression (Go RE2 syntax), as ripgrep does: a directory is searched recursively, skipping .git, what .gitignore files exclude, and binary files. " +
"Each match comes back as path:line:text, at most 64 KiB in all."
const listDescription = "List one directory's entries, not recursively, one name per line sorted by name, with / after each directory (symlinks to directories included). " +
"Nothing is left out: dotfiles, binary and gitignored files all show. At most 64 KiB in all."
func (m *Manager) fileTools(l *live) []mcp.Tool {
return []mcp.Tool{
{
@@ -88,6 +92,19 @@ func (m *Manager) fileTools(l *live) []mcp.Tool {
return m.grep(ctx, l, raw)
},
},
{
Name: "list",
Description: listDescription + " It lists a directory on the Mac byre runs on, outside any sandbox your own tools have.",
InputSchema: json.RawMessage(`{
"type": "object",
"properties": {
"path": {"type": "string", "description": "The directory, relative to your worktree, absolute, or starting with ~/ (default your worktree)."}
}
}`),
Handler: func(ctx context.Context, raw json.RawMessage) (string, error) {
return m.list(l, raw)
},
},
}
}
@@ -250,6 +267,26 @@ func (m *Manager) grep(ctx context.Context, l *live, raw json.RawMessage) (strin
return grep.Search(cctx, args.Pattern, l.dir, path, args.options())
}
type listArgs struct {
Path string `json:"path"`
}
func (m *Manager) list(l *live, raw json.RawMessage) (string, error) {
args := listArgs{}
err := json.Unmarshal(raw, &args)
if err != nil {
return "", fmt.Errorf("malformed list call: %w", err)
}
if args.Path == "" {
args.Path = "."
}
full, err := l.resolve(args.Path)
if err != nil {
return "", err
}
return dirlist.List(full)
}
var imageTypes = map[string]string{".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".webp": "image/webp"}
func readResult(path string, data []byte, offset, limit *int) mcp.Result {