Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

refactor(attachments): store files in ~/.vibe_remote/attachments/

yh c46b8119b595b
diff --git a/config/paths.py b/config/paths.py
index b752df223..2610a42f6 100644
--- a/config/paths.py
+++ b/config/paths.py
@@ -21,6 +21,10 @@ def get_runtime_dir() -> Path:
return get_vibe_remote_dir() / "runtime"
+def get_attachments_dir() -> Path:
+ return get_vibe_remote_dir() / "attachments"
+
+
def get_runtime_pid_path() -> Path:
return get_runtime_dir() / "vibe.pid"
@@ -54,3 +58,4 @@ def ensure_data_dirs() -> None:
get_state_dir().mkdir(parents=True, exist_ok=True)
get_logs_dir().mkdir(parents=True, exist_ok=True)
get_runtime_dir().mkdir(parents=True, exist_ok=True)
+ get_attachments_dir().mkdir(parents=True, exist_ok=True)
diff --git a/core/handlers/message_handler.py b/core/handlers/message_handler.py
index c15f5b9b8..ad7c1fb2d 100644
--- a/core/handlers/message_handler.py
+++ b/core/handlers/message_handler.py
@@ -136,6 +136,7 @@ class MessageHandler:
else:
try:
from pathlib import Path
+
subagent_def = load_claude_subagent(
normalized,
project_root=Path(working_path),
@@ -331,9 +332,7 @@ class MessageHandler:
if not self.session_handler:
raise RuntimeError("Session handler not initialized")
- base_session_id, working_path, composite_key = (
- self.session_handler.get_session_info(context)
- )
+ base_session_id, working_path, composite_key = self.session_handler.get_session_info(context)
settings_key = self._get_settings_key(context)
request = AgentRequest(
context=context,
@@ -431,22 +430,30 @@ class MessageHandler:
async def _process_file_attachments(self, context: MessageContext, working_path: str) -> Optional[list]:
"""Download and process file attachments from the message.
- All files (including images) are saved to the working directory.
+ All files (including images) are saved to ~/.vibe_remote/attachments/{channel_id}/
+ to avoid polluting the working directory (which is often a git repo).
The agent can then use Read tools to access them.
Args:
context: Message context with file attachments
- working_path: Working directory path for saving files
+ working_path: Working directory path (not used for storage, kept for API compat)
Returns:
List of processed FileAttachment objects with local_path set
"""
import os
+ import time
+ from config.paths import get_attachments_dir
from modules.im.base import FileAttachment
if not context.files:
return None
+ # Create channel-specific attachments directory
+ # Path: ~/.vibe_remote/attachments/{channel_id}/
+ attachments_dir = get_attachments_dir() / context.channel_id
+ attachments_dir.mkdir(parents=True, exist_ok=True)
+
processed = []
for attachment in context.files:
if not isinstance(attachment, FileAttachment):
@@ -459,30 +466,20 @@ class MessageHandler:
file_info = {
"url_private_download": attachment.url,
"name": attachment.name,
+ "size": attachment.size,
}
content = await self.im_client.download_file(file_info)
if content:
- # Save all files (including images) to working directory
- # Create attachments subdirectory
- attachments_dir = os.path.join(working_path, "_attachments")
- os.makedirs(attachments_dir, exist_ok=True)
-
- # Sanitize filename and save
+ # Generate filename: {timestamp}_{original_name}
+ timestamp = int(time.time())
safe_name = self._sanitize_filename(attachment.name)
- local_path = os.path.join(attachments_dir, safe_name)
-
- # Avoid overwriting: add timestamp if file exists
- if os.path.exists(local_path):
- import time
-
- base, ext = os.path.splitext(safe_name)
- safe_name = f"{base}_{int(time.time())}{ext}"
- local_path = os.path.join(attachments_dir, safe_name)
+ filename = f"{timestamp}_{safe_name}"
+ local_path = attachments_dir / filename
with open(local_path, "wb") as f:
f.write(content)
- attachment.local_path = local_path
+ attachment.local_path = str(local_path)
attachment.size = len(content)
# Determine file type for logging
diff --git a/modules/agents/claude_agent.py b/modules/agents/claude_agent.py
index fac0dbbf9..724566b1b 100644
--- a/modules/agents/claude_agent.py
+++ b/modules/agents/claude_agent.py
@@ -494,20 +494,20 @@ class ClaudeAgent(BaseAgent):
def _prepare_message_with_files(self, request: AgentRequest) -> str:
"""Prepare message with file attachment information.
- If there are file attachments, prepend file info to the message
- so Claude knows what files are available to read.
+ If there are file attachments, append file info to the message
+ so the agent knows what files are available to read.
+ Files are stored in ~/.vibe_remote/attachments/{channel_id}/.
Args:
request: The agent request containing message and files
Returns:
- Message string, potentially with file info prepended
+ Message string, potentially with file info appended
"""
if not request.files:
return request.message
# Build file info section
- file_info_parts = []
images = []
other_files = []
@@ -521,32 +521,25 @@ class ClaudeAgent(BaseAgent):
else:
other_files.append(attachment)
- # Format file info
- if images:
- if len(images) == 1:
- img = images[0]
- file_info_parts.append(f"[User attached an image: {img.local_path}]")
- else:
- paths = ", ".join(img.local_path for img in images)
- file_info_parts.append(f"[User attached {len(images)} images: {paths}]")
+ if not images and not other_files:
+ return request.message
- if other_files:
- if len(other_files) == 1:
- f = other_files[0]
- file_info_parts.append(f"[User attached a file: {f.local_path} ({f.mimetype})]")
- else:
- files_desc = ", ".join(f"{f.local_path} ({f.mimetype})" for f in other_files)
- file_info_parts.append(f"[User attached {len(other_files)} files: {files_desc}]")
+ # Format file info as a clear block at the end
+ file_lines = ["", "[User Attachments]"]
- if not file_info_parts:
- return request.message
+ for img in images:
+ size_str = f", {img.size} bytes" if img.size else ""
+ file_lines.append(f"- Image: {img.local_path} ({img.mimetype}{size_str})")
+
+ for f in other_files:
+ size_str = f", {f.size} bytes" if f.size else ""
+ file_lines.append(f"- File: {f.local_path} ({f.mimetype}{size_str})")
- # Combine file info with user message
- file_info = "\n".join(file_info_parts)
+ file_info = "\n".join(file_lines)
- # If there's no text message, just use file info
+ # If there's no text message, just use file info (without leading newline)
if not request.message or not request.message.strip():
- return file_info
+ return file_info.lstrip()
- # Prepend file info to message
- return f"{file_info}\n\n{request.message}"
+ # Append file info to message
+ return f"{request.message}{file_info}"
diff --git a/modules/agents/opencode/agent.py b/modules/agents/opencode/agent.py
index f28c9d7fe..0c524dcde 100644
--- a/modules/agents/opencode/agent.py
+++ b/modules/agents/opencode/agent.py
@@ -464,20 +464,20 @@ class OpenCodeAgent(OpenCodeMessageProcessorMixin, BaseAgent):
def _prepare_message_with_files(self, request: AgentRequest) -> str:
"""Prepare message with file attachment information.
- If there are file attachments, prepend file info to the message
+ If there are file attachments, append file info to the message
so the agent knows what files are available to read.
+ Files are stored in ~/.vibe_remote/attachments/{channel_id}/.
Args:
request: The agent request containing message and files
Returns:
- Message string, potentially with file info prepended
+ Message string, potentially with file info appended
"""
if not request.files:
return request.message
# Build file info section
- file_info_parts = []
images = []
other_files = []
@@ -491,32 +491,25 @@ class OpenCodeAgent(OpenCodeMessageProcessorMixin, BaseAgent):
else:
other_files.append(attachment)
- # Format file info
- if images:
- if len(images) == 1:
- img = images[0]
- file_info_parts.append(f"[User attached an image: {img.local_path}]")
- else:
- paths = ", ".join(img.local_path for img in images)
- file_info_parts.append(f"[User attached {len(images)} images: {paths}]")
+ if not images and not other_files:
+ return request.message
- if other_files:
- if len(other_files) == 1:
- f = other_files[0]
- file_info_parts.append(f"[User attached a file: {f.local_path} ({f.mimetype})]")
- else:
- files_desc = ", ".join(f"{f.local_path} ({f.mimetype})" for f in other_files)
- file_info_parts.append(f"[User attached {len(other_files)} files: {files_desc}]")
+ # Format file info as a clear block at the end
+ file_lines = ["", "[User Attachments]"]
- if not file_info_parts:
- return request.message
+ for img in images:
+ size_str = f", {img.size} bytes" if img.size else ""
+ file_lines.append(f"- Image: {img.local_path} ({img.mimetype}{size_str})")
+
+ for f in other_files:
+ size_str = f", {f.size} bytes" if f.size else ""
+ file_lines.append(f"- File: {f.local_path} ({f.mimetype}{size_str})")
- # Combine file info with user message
- file_info = "\n".join(file_info_parts)
+ file_info = "\n".join(file_lines)
- # If there's no text message, just use file info
+ # If there's no text message, just use file info (without leading newline)
if not request.message or not request.message.strip():
- return file_info
+ return file_info.lstrip()
- # Prepend file info to message
- return f"{file_info}\n\n{request.message}"
+ # Append file info to message
+ return f"{request.message}{file_info}"
diff --git a/tests/test_v2_paths.py b/tests/test_v2_paths.py
index 50623d5be..b702f5896 100644
--- a/tests/test_v2_paths.py
+++ b/tests/test_v2_paths.py
@@ -16,3 +16,4 @@ def test_ensure_data_dirs(tmp_path, monkeypatch):
assert (tmp_path / ".vibe_remote" / "state").exists()
assert (tmp_path / ".vibe_remote" / "logs").exists()
assert (tmp_path / ".vibe_remote" / "runtime").exists()
+ assert (tmp_path / ".vibe_remote" / "attachments").exists()