@@ -16,7 +16,10 @@ import (
16 "github.com/charmbracelet/crush/internal/permission"
16 "github.com/charmbracelet/crush/internal/permission"
19−const FetchToolName = "fetch"
20+ FetchToolName = "fetch"
21+ MaxFetchSize = 1 * 1024 * 1024 // 1MB
21//go:embed fetch.md
24//go:embed fetch.md
22var fetchDescription []byte
25var fetchDescription []byte
@@ -105,11 +108,7 @@ func NewFetchTool(permissions permission.Service, workingDir string, client *htt
105 return fantasy.NewTextErrorResponse(fmt.Sprintf("Request failed with status code: %d", resp.StatusCode)), nil
108 return fantasy.NewTextErrorResponse(fmt.Sprintf("Request failed with status code: %d", resp.StatusCode)), nil
108− // maxFetchResponseSizeBytes is the maximum size of response body to read (5MB)
109− const maxFetchResponseSizeBytes = int64(5 * 1024 * 1024)
111− maxSize := maxFetchResponseSizeBytes
112− body, err := io.ReadAll(io.LimitReader(resp.Body, maxSize))
111+ body, err := io.ReadAll(io.LimitReader(resp.Body, MaxFetchSize))
113 if err != nil {
112 if err != nil {
114 return fantasy.NewTextErrorResponse("Failed to read response body: " + err.Error()), nil
113 return fantasy.NewTextErrorResponse("Failed to read response body: " + err.Error()), nil
@@ -161,9 +160,9 @@ func NewFetchTool(permissions permission.Service, workingDir string, client *htt
163 // truncate content if it exceeds max read size
162 // truncate content if it exceeds max read size
164− if int64(len(content)) > MaxReadSize {
163+ if int64(len(content)) > MaxFetchSize {
165− content = content[:MaxReadSize]
164+ content = content[:MaxFetchSize]
166− content += fmt.Sprintf("\n\n[Content truncated to %d bytes]", MaxReadSize)
165+ content += fmt.Sprintf("\n\n[Content truncated to %d bytes]", MaxFetchSize)
169 return fantasy.NewTextResponse(content), nil
168 return fantasy.NewTextResponse(content), nil