fix(05-03): normalize shared-volume attachment paths

- strip /workspace and /agents roots before forwarding attachments upstream
- reuse the same normalization for send-file events returned to Matrix
This commit is contained in:
Mikhail Putilovskij 2026-04-28 01:05:15 +03:00
parent cafb0ec9e4
commit 9a0316076a

View file

@ -191,6 +191,27 @@ class RealPlatformClient(PlatformClient):
code = getattr(exc, "code", None) or "PLATFORM_CONNECTION_ERROR"
return PlatformError(str(exc), code=code)
@staticmethod
def _normalize_workspace_path(location: str) -> str | None:
if not location:
return None
path = Path(location)
if not path.is_absolute():
normalized = path.as_posix()
return normalized or None
parts = path.parts
if len(parts) >= 2 and parts[1] == "workspace":
relative = Path(*parts[2:]).as_posix()
return relative or None
if len(parts) >= 3 and parts[1] == "agents":
relative = Path(*parts[3:]).as_posix()
return relative or None
relative = path.as_posix().lstrip("/")
return relative or None
@staticmethod
def _attachment_paths(attachments: list[Attachment] | None) -> list[str]:
if not attachments:
@ -198,18 +219,18 @@ class RealPlatformClient(PlatformClient):
paths = []
for attachment in attachments:
if attachment.workspace_path:
paths.append(attachment.workspace_path)
normalized = RealPlatformClient._normalize_workspace_path(
attachment.workspace_path
)
if normalized:
paths.append(normalized)
return paths
@staticmethod
def _attachment_from_send_file_event(event: MsgEventSendFile) -> Attachment:
location = str(event.path)
filename = Path(location).name or None
workspace_path = location
if workspace_path.startswith("/workspace/"):
workspace_path = workspace_path[len("/workspace/") :]
elif workspace_path == "/workspace":
workspace_path = ""
workspace_path = RealPlatformClient._normalize_workspace_path(location)
return Attachment(
url=location,
mime_type="application/octet-stream",