feat(editor): add domain entities and file I/O infrastructure

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
openclaw 2026-03-23 16:59:21 +00:00
parent 4bf8a85660
commit 11f59c6073
2 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,22 @@
from dataclasses import dataclass
from datetime import datetime
@dataclass
class EditableFile:
path: str
format: str # csv, md, yaml, openapi
content: str
last_modified: datetime
@dataclass
class AffectedFile:
path: str
reason: str
@dataclass
class ImpactResult:
source_file: str
affected_files: list[AffectedFile]

View File

@ -0,0 +1,35 @@
from datetime import datetime, timezone
from pathlib import Path
from app.modules.editor.domain.entities import EditableFile
from app.shared.infrastructure.filesystem import read_text, write_text
def detect_format(file_path: Path) -> str:
suffix = file_path.suffix.lower()
if suffix == ".csv":
return "csv"
elif suffix == ".md":
return "md"
elif suffix in (".yaml", ".yml"):
if "openapi" in file_path.name or "api-contracts" in file_path.name:
return "openapi"
return "yaml"
return "unknown"
def read_file(base_dir: Path, relative_path: str) -> EditableFile:
full_path = base_dir / relative_path
content = read_text(full_path)
stat = full_path.stat()
return EditableFile(
path=relative_path,
format=detect_format(full_path),
content=content,
last_modified=datetime.fromtimestamp(stat.st_mtime, tz=timezone.utc),
)
def write_file(base_dir: Path, relative_path: str, content: str) -> None:
full_path = base_dir / relative_path
write_text(full_path, content)