Add show_page and show_file, and let file tools reach any path

This commit is contained in:
Ian Gulliver
2026-10-21 18:29:01 -07:00
parent 585c8ba5f8
commit 524bc0252e
11 changed files with 540 additions and 496 deletions
-22
View File
@@ -9,7 +9,6 @@ import (
"path/filepath"
"strings"
"g.fc.run/ai/byre/internal/agents"
"g.fc.run/ai/byre/internal/api"
)
@@ -28,17 +27,6 @@ func (s *Server) GetTaskImage(w http.ResponseWriter, r *http.Request, taskID str
return
}
root, err := filepath.EvalSymlinks(t.WorktreePath)
if err != nil {
writeError(w, http.StatusInternalServerError, err)
return
}
media, err := filepath.EvalSymlinks(agents.MediaDir(t.WorktreePath))
if err != nil && !errors.Is(err, fs.ErrNotExist) {
writeError(w, http.StatusInternalServerError, err)
return
}
path := params.Path
if !filepath.IsAbs(path) {
path = filepath.Join(t.WorktreePath, path)
@@ -53,11 +41,6 @@ func (s *Server) GetTaskImage(w http.ResponseWriter, r *http.Request, taskID str
return
}
if !within(root, real) && (media == "" || !within(media, real)) {
writeError(w, http.StatusForbidden, fmt.Errorf("%s is outside the task's worktree and media folder", params.Path))
return
}
contentType := worktreeImageTypes[strings.ToLower(filepath.Ext(real))]
if contentType == "" {
writeError(w, http.StatusBadRequest, fmt.Errorf("%s is not a PNG, JPEG, GIF, WebP or SVG file", params.Path))
@@ -87,8 +70,3 @@ func (s *Server) GetTaskImage(w http.ResponseWriter, r *http.Request, taskID str
w.Header().Set("Cache-Control", "private, no-cache")
http.ServeContent(w, r, "", info.ModTime(), f)
}
func within(root, path string) bool {
rel, err := filepath.Rel(root, path)
return err == nil && rel != ".." && !strings.HasPrefix(rel, ".."+string(filepath.Separator))
}