diff --git a/internal/agent/tools/fetch.go b/internal/agent/tools/fetch.go index 0129fc3a46d264007649be088d843c0ebbf76149..e8d11d98ef930d5f8b77bd31ffd945199c93c69d 100644 --- a/internal/agent/tools/fetch.go +++ b/internal/agent/tools/fetch.go @@ -16,7 +16,10 @@ import ( "github.com/charmbracelet/crush/internal/permission" ) -const FetchToolName = "fetch" +const ( + FetchToolName = "fetch" + MaxFetchSize = 1 * 1024 * 1024 // 1MB +) //go:embed fetch.md var fetchDescription []byte @@ -105,11 +108,7 @@ func NewFetchTool(permissions permission.Service, workingDir string, client *htt return fantasy.NewTextErrorResponse(fmt.Sprintf("Request failed with status code: %d", resp.StatusCode)), nil } - // maxFetchResponseSizeBytes is the maximum size of response body to read (5MB) - const maxFetchResponseSizeBytes = int64(5 * 1024 * 1024) - - maxSize := maxFetchResponseSizeBytes - body, err := io.ReadAll(io.LimitReader(resp.Body, maxSize)) + body, err := io.ReadAll(io.LimitReader(resp.Body, MaxFetchSize)) if err != nil { return fantasy.NewTextErrorResponse("Failed to read response body: " + err.Error()), nil } @@ -161,9 +160,9 @@ func NewFetchTool(permissions permission.Service, workingDir string, client *htt } } // truncate content if it exceeds max read size - if int64(len(content)) > MaxReadSize { - content = content[:MaxReadSize] - content += fmt.Sprintf("\n\n[Content truncated to %d bytes]", MaxReadSize) + if int64(len(content)) > MaxFetchSize { + content = content[:MaxFetchSize] + content += fmt.Sprintf("\n\n[Content truncated to %d bytes]", MaxFetchSize) } return fantasy.NewTextResponse(content), nil diff --git a/internal/agent/tools/view.go b/internal/agent/tools/view.go index 9b856fd1fad961a2aabf491c0f8aac6914965e2e..db6eb2b5a92d778eeebe211bd2ce013ab316e5de 100644 --- a/internal/agent/tools/view.go +++ b/internal/agent/tools/view.go @@ -53,7 +53,7 @@ type ViewResponseMetadata struct { const ( ViewToolName = "view" - MaxReadSize = 5 * 1024 * 1024 // 5MB + MaxViewSize = 1 * 1024 * 1024 // 1MB DefaultReadLimit = 2000 MaxLineLength = 2000 ) @@ -155,9 +155,9 @@ func NewViewTool( } // Based on the specifications we should not limit the skills read. - if !isSkillFile && fileInfo.Size() > MaxReadSize { + if !isSkillFile && fileInfo.Size() > MaxViewSize { return fantasy.NewTextErrorResponse(fmt.Sprintf("File is too large (%d bytes). Maximum size is %d bytes", - fileInfo.Size(), MaxReadSize)), nil + fileInfo.Size(), MaxViewSize)), nil } // Set default limit if not provided (no limit for SKILL.md files)