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.

fix: normalize SettingsManager user_id keys and per-session relative path formatting\n\n- settings_manager: add _normalize_user_id; prevent int/str duplicate keys; unify updates\n- claude_client: accept get_relative_path callback and thread through formatting\n- message_handler: pass per-session get_relative_path to formatter for accurate cwd

cyhhao097815663570
diff --git a/core/handlers/message_handler.py b/core/handlers/message_handler.py
index 0c4a986e7..ee008ec05 100644
--- a/core/handlers/message_handler.py
+++ b/core/handlers/message_handler.py
@@ -193,8 +193,13 @@ class MessageHandler:
# Format and send message using claude_client
if hasattr(self.controller, "claude_client"):
+ # Provide a per-session relative path resolver to ensure correct cwd
+ def _rel(path: str) -> str:
+ return self.get_relative_path(path, context)
formatted_message = (
- self.controller.claude_client.format_message(message)
+ self.controller.claude_client.format_message(
+ message, get_relative_path=_rel
+ )
)
if formatted_message and formatted_message.strip():
# Add separator line for Slack to improve message separation
diff --git a/modules/claude_client.py b/modules/claude_client.py
index 6d39ab1e9..3742e4090 100644
--- a/modules/claude_client.py
+++ b/modules/claude_client.py
@@ -1,6 +1,6 @@
import logging
import os
-from typing import Optional
+from typing import Optional, Callable
from claude_code_sdk import (
ClaudeCodeOptions,
SystemMessage,
@@ -32,15 +32,15 @@ class ClaudeClient:
system_prompt=config.system_prompt,
)
- def format_message(self, message) -> str:
+ def format_message(self, message, get_relative_path: Optional[Callable[[str], str]] = None) -> str:
"""Format different types of messages according to specified rules"""
try:
if isinstance(message, SystemMessage):
return self._format_system_message(message)
elif isinstance(message, AssistantMessage):
- return self._format_assistant_message(message)
+ return self._format_assistant_message(message, get_relative_path)
elif isinstance(message, UserMessage):
- return self._format_user_message(message)
+ return self._format_user_message(message, get_relative_path)
elif isinstance(message, ResultMessage):
return self._format_result_message(message)
else:
@@ -51,7 +51,7 @@ class ClaudeClient:
logger.error(f"Error formatting message: {e}")
return self.formatter.format_error(f"Error formatting message: {str(e)}")
- def _process_content_blocks(self, content_blocks) -> list:
+ def _process_content_blocks(self, content_blocks, get_relative_path: Optional[Callable[[str], str]] = None) -> list:
"""Process content blocks (TextBlock, ToolUseBlock) and return formatted parts"""
formatted_parts = []
@@ -61,7 +61,7 @@ class ClaudeClient:
# This avoids double escaping
formatted_parts.append(block.text)
elif isinstance(block, ToolUseBlock):
- tool_info = self._format_tool_use_block(block)
+ tool_info = self._format_tool_use_block(block, get_relative_path)
formatted_parts.append(tool_info)
elif isinstance(block, ToolResultBlock):
result_info = self._format_tool_result_block(block)
@@ -93,12 +93,11 @@ class ClaudeClient:
# Fallback to original path if any error
return full_path
- def _format_tool_use_block(self, block: ToolUseBlock) -> str:
+ def _format_tool_use_block(self, block: ToolUseBlock, get_relative_path: Optional[Callable[[str], str]] = None) -> str:
"""Format ToolUseBlock using formatter"""
- # Use formatter's format_tool_use method
- return self.formatter.format_tool_use(
- block.name, block.input, get_relative_path=self._get_relative_path
- )
+ # Prefer caller-provided get_relative_path (per-session cwd), fallback to self
+ rel = get_relative_path if get_relative_path else self._get_relative_path
+ return self.formatter.format_tool_use(block.name, block.input, get_relative_path=rel)
def _format_tool_result_block(self, block: ToolResultBlock) -> str:
"""Format ToolResultBlock using formatter"""
@@ -110,14 +109,14 @@ class ClaudeClient:
session_id = message.data.get("session_id", None)
return self.formatter.format_system_message(cwd, message.subtype, session_id)
- def _format_assistant_message(self, message: AssistantMessage) -> str:
+ def _format_assistant_message(self, message: AssistantMessage, get_relative_path: Optional[Callable[[str], str]] = None) -> str:
"""Format AssistantMessage using formatter"""
- content_parts = self._process_content_blocks(message.content)
+ content_parts = self._process_content_blocks(message.content, get_relative_path)
return self.formatter.format_assistant_message(content_parts)
- def _format_user_message(self, message: UserMessage) -> str:
+ def _format_user_message(self, message: UserMessage, get_relative_path: Optional[Callable[[str], str]] = None) -> str:
"""Format UserMessage using formatter"""
- content_parts = self._process_content_blocks(message.content)
+ content_parts = self._process_content_blocks(message.content, get_relative_path)
return self.formatter.format_user_message(content_parts)
def _format_result_message(self, message: ResultMessage) -> str:
diff --git a/modules/settings_manager.py b/modules/settings_manager.py
index a7ff71c85..bf3bd6c8e 100644
--- a/modules/settings_manager.py
+++ b/modules/settings_manager.py
@@ -34,6 +34,21 @@ class SettingsManager:
self.settings_file = Path(settings_file)
self.settings: Dict[Union[int, str], UserSettings] = {}
self._load_settings()
+
+ # ---------------------------------------------
+ # Internal helpers
+ # ---------------------------------------------
+ def _normalize_user_id(self, user_id: Union[int, str]) -> Union[int, str]:
+ """Normalize user_id to avoid duplicate keys (e.g. '123' vs 123)
+
+ - If user_id is a numeric string, convert to int (Telegram case)
+ - Otherwise keep as string (Slack IDs are non-numeric strings)
+ """
+ if isinstance(user_id, int):
+ return user_id
+ if isinstance(user_id, str) and user_id.isdigit():
+ return int(user_id)
+ return user_id
def _load_settings(self):
"""Load settings from JSON file"""
@@ -79,42 +94,34 @@ class SettingsManager:
def get_user_settings(self, user_id: Union[int, str]) -> UserSettings:
"""Get settings for a specific user"""
- # Normalize user_id to handle both int and string forms
- normalized_id = user_id
-
- # For Telegram, try to find by both int and string forms
- if isinstance(user_id, str) and user_id.isdigit():
- # Try as int first
- int_id = int(user_id)
- if int_id in self.settings:
- return self.settings[int_id]
- # Also check string form
- if user_id in self.settings:
- return self.settings[user_id]
- # Use int form for Telegram
- normalized_id = int_id
- elif isinstance(user_id, int):
- # Check if exists as int
- if user_id in self.settings:
- return self.settings[user_id]
- # Also check string form
- str_id = str(user_id)
- if str_id in self.settings:
- return self.settings[str_id]
- normalized_id = user_id
- else:
- # For Slack and other platforms, keep as string
- if user_id in self.settings:
- return self.settings[user_id]
-
- # Create new settings if not found
- self.settings[normalized_id] = UserSettings()
- self._save_settings()
+ normalized_id = self._normalize_user_id(user_id)
+
+ # Try to merge stray duplicate key (e.g. both '123' and 123 exist)
+ other_form = str(normalized_id) if isinstance(normalized_id, int) else None
+ if isinstance(normalized_id, int) and other_form in self.settings:
+ # Prefer normalized (int). If int not present, migrate string value
+ if normalized_id not in self.settings:
+ self.settings[normalized_id] = self.settings[other_form]
+ del self.settings[other_form]
+ self._save_settings()
+
+ # Return existing or create new
+ if normalized_id not in self.settings:
+ self.settings[normalized_id] = UserSettings()
+ self._save_settings()
return self.settings[normalized_id]
def update_user_settings(self, user_id: Union[int, str], settings: UserSettings):
"""Update settings for a specific user"""
- self.settings[user_id] = settings
+ normalized_id = self._normalize_user_id(user_id)
+
+ # Remove stray duplicate under the other representation to keep single source
+ if isinstance(normalized_id, int):
+ stray_key = str(normalized_id)
+ if stray_key in self.settings and self.settings.get(normalized_id) is not self.settings[stray_key]:
+ del self.settings[stray_key]
+
+ self.settings[normalized_id] = settings
self._save_settings()
def toggle_hidden_message_type(self, user_id: Union[int, str], message_type: str) -> bool: