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(slack): preserve control routing with raw mentions

cyh970c76d35ccd
diff --git a/core/handlers/message_handler.py b/core/handlers/message_handler.py
index 11a62232a..577c00e92 100644
--- a/core/handlers/message_handler.py
+++ b/core/handlers/message_handler.py
@@ -126,6 +126,7 @@ class MessageHandler(BaseHandler):
typing_indicator_task = None
try:
is_human = source == self.TURN_SOURCE_HUMAN
+ control_message = self._get_control_message(context, message) if is_human else message
# Record user activity for auto-update idle detection
if is_human and hasattr(self.controller, "update_checker"):
@@ -134,7 +135,7 @@ class MessageHandler(BaseHandler):
# If message is empty AND no files attached (e.g., user just @mentioned bot without text),
# trigger the /start command instead of sending empty message to agent
has_files = bool(context.files)
- if (not message or not message.strip()) and not has_files:
+ if (not control_message or not control_message.strip()) and not has_files:
if is_human:
await self.controller.command_handler.handle_start(context, "")
return None
@@ -159,14 +160,14 @@ class MessageHandler(BaseHandler):
if is_human and not has_files:
maybe_consume_setup_reply = getattr(self.controller.agent_auth_service, "maybe_consume_setup_reply", None)
if callable(maybe_consume_setup_reply):
- consumed = await maybe_consume_setup_reply(context, message)
+ consumed = await maybe_consume_setup_reply(context, control_message)
if consumed:
return None
# Skip automatic cleanup; receiver tasks are retained until shutdown
# Allow "stop" shortcut inside Slack threads
- if is_human and context.thread_id and message.strip().lower() in ["stop", "/stop"]:
+ if is_human and context.thread_id and control_message.strip().lower() in ["stop", "/stop"]:
if await self._handle_inline_stop(context):
return None
@@ -228,7 +229,7 @@ class MessageHandler(BaseHandler):
parse_subagent_prefix,
)
- parsed = parse_subagent_prefix(message)
+ parsed = parse_subagent_prefix(control_message)
if parsed:
normalized = normalize_subagent_name(parsed.name)
if agent_name == "opencode":
@@ -432,6 +433,14 @@ class MessageHandler(BaseHandler):
return f"[Agent Identity] Slack bot mention: {bot_mention.strip()}\n{message}"
return message
+ @staticmethod
+ def _get_control_message(context: MessageContext, message: str) -> str:
+ payload = context.platform_specific or {}
+ control_text = payload.get("control_text")
+ if isinstance(control_text, str):
+ return control_text
+ return message
+
async def handle_callback_query(self, context: MessageContext, callback_data: str):
"""Route callback queries to appropriate handlers"""
try:
diff --git a/modules/im/slack.py b/modules/im/slack.py
index 7437ead5a..13122d933 100644
--- a/modules/im/slack.py
+++ b/modules/im/slack.py
@@ -1524,6 +1524,7 @@ class SlackBot(BaseIMClient):
"is_dm": is_dm,
"bot_user_id": bot_user_id,
"bot_mention": bot_mention,
+ "control_text": route_text,
},
files=file_attachments,
)
@@ -1616,6 +1617,7 @@ class SlackBot(BaseIMClient):
"is_dm": channel_id.startswith("D"),
"bot_user_id": bot_user_id,
"bot_mention": bot_mention,
+ "control_text": route_text,
},
files=file_attachments,
)
diff --git a/tests/test_message_handler_typing.py b/tests/test_message_handler_typing.py
index 01d6928d9..85516a128 100644
--- a/tests/test_message_handler_typing.py
+++ b/tests/test_message_handler_typing.py
@@ -142,13 +142,19 @@ class _StubAgentService:
def __init__(self):
self.default_agent = "codex"
self.requests = []
+ self.stop_requests = []
self.error = None
+ self.stop_result = True
async def handle_message(self, agent_name, request):
if self.error is not None:
raise self.error
self.requests.append((agent_name, request))
+ async def handle_stop(self, agent_name, request):
+ self.stop_requests.append((agent_name, request))
+ return self.stop_result
+
class _StubController:
def __init__(self, *, platform: str, ack_mode: str, typing_result: bool):
@@ -165,6 +171,7 @@ class _StubController:
self.agent_service = _StubAgentService()
self.settings_handler = type("Settings", (), {})()
self.command_handler = type("Cmd", (), {"handle_start": staticmethod(lambda context, args: None)})()
+ self.agent_auth_service = type("Auth", (), {})()
def update_thread_message_id(self, context):
return None
@@ -317,6 +324,49 @@ class MessageHandlerTypingTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual(result, "[WeChat User<wx-user>] hello")
+ async def test_control_text_handles_mentioned_inline_stop(self):
+ controller = _StubController(platform="slack", ack_mode="reaction", typing_result=True)
+ handler = MessageHandler(controller)
+ handler.set_session_handler(_StubSessionHandler())
+ context = MessageContext(
+ user_id="U1",
+ channel_id="C1",
+ thread_id="T1",
+ message_id="m1",
+ platform="slack",
+ platform_specific={"control_text": "stop"},
+ )
+
+ await handler.handle_user_message(context, "<@U_BOT> stop")
+
+ self.assertEqual(len(controller.agent_service.stop_requests), 1)
+ self.assertEqual(controller.agent_service.requests, [])
+
+ async def test_control_text_routes_mentioned_subagent_prefix(self):
+ controller = _StubController(platform="slack", ack_mode="reaction", typing_result=True)
+ handler = MessageHandler(controller)
+ handler.set_session_handler(_StubSessionHandler())
+ context = MessageContext(
+ user_id="U1",
+ channel_id="C1",
+ message_id="m1",
+ platform="slack",
+ platform_specific={"bot_mention": "<@U_BOT>", "control_text": "reviewer: check this"},
+ )
+
+ from modules.agents.subagent_router import SubagentDefinition
+
+ with patch(
+ "modules.agents.subagent_router.load_codex_subagent",
+ return_value=SubagentDefinition(name="reviewer"),
+ ):
+ await handler.handle_user_message(context, "<@U_BOT> reviewer: check this")
+
+ _, request = controller.agent_service.requests[0]
+ self.assertEqual(request.subagent_name, "reviewer")
+ self.assertEqual(request.subagent_key, "reviewer")
+ self.assertEqual(request.message, "[Agent Identity] Slack bot mention: <@U_BOT>\ncheck this")
+
async def test_scheduled_turn_returns_error_string_after_notifying_im(self):
controller = _StubController(platform="slack", ack_mode="reaction", typing_result=True)
controller.agent_service.error = RuntimeError("boom")