from modal.exception import SandboxFilesystemNotFoundError
from rebuno import tool
@tool("shell", resources=["workspace"])
async def shell(command: str) -> str:
"""Run a shell command in the repository and return its exit code and output."""
process = await workspace.exec.aio(
"bash", "-c", command, workdir=WORKDIR, timeout=120
)
stdout = await process.stdout.read.aio()
stderr = await process.stderr.read.aio()
exit_code = await process.wait.aio()
return f"exit code {exit_code}\n{stdout}{stderr}"[-10000:]
@tool("read_file")
async def read_file(path: str) -> str:
"""Return a file's contents. The path is relative to the repository root."""
try:
return await workspace.filesystem.read_text.aio(f"{WORKDIR}/{path}")
except SandboxFilesystemNotFoundError:
return f"{path} does not exist"
@tool("write_file", resources=["workspace"])
async def write_file(path: str, content: str) -> str:
"""Replace a file's contents, creating it if needed. The path is relative to the repository root."""
await workspace.filesystem.write_text.aio(content, f"{WORKDIR}/{path}")
return f"wrote {path}"