on main help sign in
fix: reduce max read size from 5mb to 1mb for view and fetch tools (#2447)
dfc57d4Andrey Nering
internal/agent/tools/fetch.go+8−9
@@ -16,7 +16,10 @@ import (
16 "github.com/charmbracelet/crush/internal/permission"
16 "github.com/charmbracelet/crush/internal/permission"
17)
17)
18
18
19+const (
19−const FetchToolName = "fetch"
20+ FetchToolName = "fetch"
21+ MaxFetchSize = 1 * 1024 * 1024 // 1MB
22+)
20
23
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
106 }
109 }
107
110
108− // maxFetchResponseSizeBytes is the maximum size of response body to read (5MB)
109− const maxFetchResponseSizeBytes = int64(5 * 1024 * 1024)
110−
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
115 }
114 }
@@ -161,9 +160,9 @@ func NewFetchTool(permissions permission.Service, workingDir string, client *htt
161 }
160 }
162 }
161 }
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)
167 }
166 }
168
167
169 return fantasy.NewTextResponse(content), nil
168 return fantasy.NewTextResponse(content), nil
internal/agent/tools/view.go+3−3
@@ -53,7 +53,7 @@ type ViewResponseMetadata struct {
53
53
54const (
54const (
55 ViewToolName = "view"
55 ViewToolName = "view"
56− MaxReadSize = 5 * 1024 * 1024 // 5MB
56+ MaxViewSize = 1 * 1024 * 1024 // 1MB
57 DefaultReadLimit = 2000
57 DefaultReadLimit = 2000
58 MaxLineLength = 2000
58 MaxLineLength = 2000
59)
59)
@@ -155,9 +155,9 @@ func NewViewTool(
155 }
155 }
156
156
157 // Based on the specifications we should not limit the skills read.
157 // Based on the specifications we should not limit the skills read.
158− if !isSkillFile && fileInfo.Size() > MaxReadSize {
158+ if !isSkillFile && fileInfo.Size() > MaxViewSize {
159 return fantasy.NewTextErrorResponse(fmt.Sprintf("File is too large (%d bytes). Maximum size is %d bytes",
159 return fantasy.NewTextErrorResponse(fmt.Sprintf("File is too large (%d bytes). Maximum size is %d bytes",
160− fileInfo.Size(), MaxReadSize)), nil
160+ fileInfo.Size(), MaxViewSize)), nil
161 }
161 }
162
162
163 // Set default limit if not provided (no limit for SKILL.md files)
163 // Set default limit if not provided (no limit for SKILL.md files)