Skip to content

Commit 1dd5c6d

Browse files
committed
fix(editor): allow create_file tool to accept content argument
1 parent 11cdf46 commit 1dd5c6d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

metagpt/tools/libs/editor.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,21 +354,23 @@ def scroll_up(self) -> str:
354354
output += self._print_window(self.current_file, self.current_line, self.window)
355355
return output
356356

357-
async def create_file(self, filename: str) -> str:
358-
"""Creates and opens a new file with the given name.
357+
async def create_file(self, filename: str, content: str = "") -> str:
358+
"""Creates and opens a new file with the given name and optional content.
359359
360360
Args:
361-
filename: str: The name of the file to create. If the parent directory does not exist, it will be created.
361+
filename: str: The name of the file to create.
362+
content: str: (Optional) The initial content to write to the file.
362363
"""
363364
filename = self._try_fix_path(filename)
364365

365366
if filename.exists():
366367
raise FileExistsError(f"File '{filename}' already exists.")
367-
await awrite(filename, "\n")
368+
369+
# Write content if provided, otherwise default to newline
370+
await awrite(filename, content if content else "\n")
368371

369372
self.open_file(filename)
370-
return f"[File {filename} created.]"
371-
373+
return f"[File {filename} created with {len(content)} characters.]"
372374
@staticmethod
373375
def _append_impl(lines, content):
374376
"""Internal method to handle appending to a file.

0 commit comments

Comments
 (0)