feat: Use docker api to pull files from container
Some checks failed
CI / test (push) Failing after 20s
CI / publish (push) Has been skipped

This commit is contained in:
2026-04-02 15:40:08 +02:00
parent 0efa9e2720
commit 4bb5a645e0
4 changed files with 937 additions and 26 deletions

View File

@@ -2,7 +2,6 @@
from __future__ import annotations
from shlex import quote
from typing import TYPE_CHECKING
from langchain_core.tools import BaseTool, tool
@@ -36,11 +35,21 @@ def make_edit_file_tool(sandbox: "DockerSandbox") -> BaseTool:
Returns a confirmation with the number of lines affected, or an error.
"""
logger.debug("Editing file inside sandbox: {!r}", path)
exit_code, content = sandbox.exec(f"cat -- {quote(path)}")
if exit_code != 0:
return f"[ERROR reading {path!r} for edit] {content.strip()}"
_MAX_EDIT_BYTES = 1_000_000 # 1 MB
logger.debug("Editing file inside sandbox: {!r}", path)
try:
data = sandbox.read_file(path)
except (FileNotFoundError, IsADirectoryError, RuntimeError) as exc:
return f"[ERROR reading {path!r} for edit] {exc}"
if len(data) > _MAX_EDIT_BYTES:
return (
f"[ERROR] {path!r} is {len(data)} bytes; edit_file only supports files "
f"up to {_MAX_EDIT_BYTES} bytes."
)
content = data.decode("utf-8", errors="replace")
count = content.count(old_str)
if count == 0:
return (