diff --git a/pkg/tools/filesystem.go b/pkg/tools/filesystem.go index cd8da3195..d857eb090 100644 --- a/pkg/tools/filesystem.go +++ b/pkg/tools/filesystem.go @@ -13,6 +13,8 @@ import ( "github.com/sipeed/picoclaw/pkg/fileutil" ) +const maxWriteSize = 20 * 1024 * 1024 // 20 MB — limit for file writes via the write tool + // validatePath ensures the given path is within the workspace if restrict is true. func validatePath(path, workspace string, restrict bool) (string, error) { if workspace == "" { @@ -178,6 +180,10 @@ func (t *WriteFileTool) Execute(ctx context.Context, args map[string]any) *ToolR return ErrorResult("content is required") } + if len(content) > maxWriteSize { + return ErrorResult(fmt.Sprintf("content too large: %d bytes exceeds %d byte limit", len(content), maxWriteSize)) + } + if err := t.fs.WriteFile(path, []byte(content)); err != nil { return ErrorResult(err.Error()) }