From 86062a8950620825d90ac197d4c21be11a9eae2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=AD=D0=BC=D0=B8=D0=BB=D1=8C=20=D0=90=D0=BC=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Tue, 26 May 2026 07:51:30 +0000 Subject: [PATCH] add export_utils.py --- export_utils.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 export_utils.py diff --git a/export_utils.py b/export_utils.py new file mode 100644 index 0000000..7b63fe3 --- /dev/null +++ b/export_utils.py @@ -0,0 +1,45 @@ +"""Экспорт виртуальных файлов агента в реальную файловую систему.""" +from __future__ import annotations + +import shutil +from pathlib import Path + + +def export_virtual_files( + workspace_dir: Path, + output_dir: Path, + *, + clear_output: bool = True, +) -> list[str]: + """Копирует все файлы из workspace агента в output_dir. + + Returns: + Список относительных путей экспортированных файлов. + """ + workspace_dir = workspace_dir.resolve() + output_dir = output_dir.resolve() + output_dir.mkdir(parents=True, exist_ok=True) + + if clear_output: + for child in output_dir.iterdir(): + if child.is_dir(): + shutil.rmtree(child) + else: + child.unlink() + + exported: list[str] = [] + if not workspace_dir.exists(): + return exported + + for src in workspace_dir.rglob("*"): + if not src.is_file(): + continue + rel = src.relative_to(workspace_dir) + if rel.parts and rel.parts[0] == ".git": + continue + dest = output_dir / rel + dest.parent.mkdir(parents=True, exist_ok=True) + shutil.copy2(src, dest) + exported.append(str(rel).replace("\\", "/")) + + return exported