Spaces:
Running
Running
File size: 1,873 Bytes
c706455 37f9abc c706455 37f9abc c706455 37f9abc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | from multi_agent_sdlc.tools.coder.validation import FileContent
from multi_agent_sdlc.tools.coder.validation import ProjectRelativePath
from multi_agent_sdlc.runtime.workspace import get_project_directory
from multi_agent_sdlc.tools.coder.validation import reject_coder_test_path
from multi_agent_sdlc.tools.coder.descriptions import (
WRITE_FILE_DESCRIPTION,
CREATE_DIRECTORY_DESCRIPTION,
)
from multi_agent_sdlc.runtime.paths import resolve_project_path
from multi_agent_sdlc.state import DevState
from langchain.tools import ToolRuntime, tool
@tool(
"write_file",
description=WRITE_FILE_DESCRIPTION,
)
def coder_write_file(
path: ProjectRelativePath,
content: FileContent,
runtime: ToolRuntime[DevState],
) -> str:
reject_coder_test_path(path)
project_directory = get_project_directory(runtime)
file_path = resolve_project_path(project_directory, path)
if file_path.exists() and file_path.is_dir():
raise IsADirectoryError(f"Cannot replace a directory with a file: {path}")
file_path.parent.mkdir(
parents=True,
exist_ok=True,
)
file_path.write_text(
content,
encoding="utf-8",
)
return f"Written production file: {path}"
@tool(
"create_directory",
description=CREATE_DIRECTORY_DESCRIPTION,
)
def coder_create_directory(
path: ProjectRelativePath,
runtime: ToolRuntime[DevState],
) -> str:
reject_coder_test_path(path)
project_directory = get_project_directory(runtime)
directory_path = resolve_project_path(
project_directory,
path,
)
if directory_path.exists() and not directory_path.is_dir():
raise FileExistsError(f"A file already exists at this path: {path}")
directory_path.mkdir(
parents=True,
exist_ok=True,
)
return f"Created production directory: {path}"
|