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(core): parse slack quick reply links

cyhbcef7611af22
diff --git a/core/reply_enhancer.py b/core/reply_enhancer.py
index d983762db..49ab28ffd 100644
--- a/core/reply_enhancer.py
+++ b/core/reply_enhancer.py
@@ -9,7 +9,7 @@ Extracts special syntaxes from agent reply text:
e.g. ``[screenshot](file:///tmp/shot.png)``
3. **Quick-reply buttons** – A ``---`` separator followed by
- ``[button text]`` tokens separated by ``|``
+ ``[button text]`` or Slack-style ``<url|button text>`` tokens separated by ``|``
e.g. ``---\\n[👌好的] | [✅提交PR] | [先review一下]``
"""
@@ -65,16 +65,16 @@ class EnhancedReply:
_FILE_LINK_RE = re.compile(r"(!?)\[([^\]]*)\]\((file://(?:[^()]+|\([^)]*\))+)\)")
# Matches the quick-reply button block at the end of the text.
-# A horizontal rule (``---``) on its own line, followed by one or more
-# ``[text]`` tokens separated by ``|`` or full-width ``|``.
+# A horizontal rule (``---``) on its own line, followed by bracket buttons or
+# Slack-style link buttons separated by ``|`` or full-width ``|``.
_BUTTON_BLOCK_RE = re.compile(
r"\n-{3,}\s*\n" # --- separator line
- r"((?:\s*\[[^\]]+\]\s*(?:[||]\s*)?)+)" # [text] tokens
+ r"((?:\s*(?:\[[^\]]+\]|<[^|>\n]+\|[^>\n]+>)\s*(?:[||]\s*)?)+)" # button tokens
r"\s*$", # trailing whitespace / end of string
)
-# Individual button token: [button text]
-_BUTTON_TOKEN_RE = re.compile(r"\[([^\]]+)\]")
+# Individual button tokens: [button text] or Slack-style <url|button text>.
+_BUTTON_TOKEN_RE = re.compile(r"\[([^\]]+)\]|<[^|>\n]+\|([^>\n]+)>")
# Silent output blocks are intentionally simple and model-facing. They are
# stripped before any reply enhancement parsing so hidden text cannot create
@@ -176,7 +176,8 @@ def _extract_buttons(text: str) -> Tuple[List[QuickReplyButton], str]:
block = m.group(1)
buttons: List[QuickReplyButton] = []
- for label in _BUTTON_TOKEN_RE.findall(block):
+ for bracket_label, slack_label in _BUTTON_TOKEN_RE.findall(block):
+ label = bracket_label or slack_label
label = label.strip()
if label:
buttons.append(QuickReplyButton(text=label))
diff --git a/tests/test_reply_enhancer_platform.py b/tests/test_reply_enhancer_platform.py
index bcceccb61..d6bca698b 100644
--- a/tests/test_reply_enhancer_platform.py
+++ b/tests/test_reply_enhancer_platform.py
@@ -126,6 +126,26 @@ class ReplyEnhancerPlatformTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual([file.path for file in reply.files], ["/tmp/report.txt"])
self.assertEqual(reply.buttons, [])
+ def test_process_reply_accepts_slack_link_style_quick_reply_button(self):
+ reply = process_reply(
+ "Done.\n\n---\n"
+ "<https://github.com/cyhhao/vibe-remote/pull/298|:eyes: 看 PR> | "
+ "[:rocket: 等评审完合并] | [:test_tube: 先回归测一遍]"
+ )
+
+ self.assertEqual(reply.text, "Done.")
+ self.assertEqual(
+ [button.text for button in reply.buttons],
+ [":eyes: 看 PR", ":rocket: 等评审完合并", ":test_tube: 先回归测一遍"],
+ )
+
+ def test_process_reply_ignores_bare_angle_link_as_quick_reply_button(self):
+ text = "Done.\n\n---\n<https://github.com/cyhhao/vibe-remote/pull/298>"
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, text)
+ self.assertEqual(reply.buttons, [])
+
def test_prompt_includes_task_watch_and_hook_usage_with_thread_default_session_key(self):
context = MessageContext(
user_id="U1",
@@ -264,6 +284,28 @@ class ReplyEnhancerPlatformTests(unittest.IsolatedAsyncioTestCase):
keyboard = controller.im_client.sent_button_messages[0][3]
self.assertEqual([[button.text for button in row] for row in keyboard.buttons], [["继续"], ["提交PR"]])
+ async def test_slack_link_style_quick_reply_dispatches_label_callbacks(self):
+ controller = _StubController("slack")
+ dispatcher = ConsolidatedMessageDispatcher(controller)
+ context = MessageContext(user_id="U1", channel_id="C1", platform="slack")
+
+ await dispatcher.emit_agent_message(
+ context,
+ "result",
+ "Done.\n---\n"
+ "<https://github.com/cyhhao/vibe-remote/pull/298|:eyes: 看 PR> | "
+ "[:rocket: 等评审完合并]",
+ )
+
+ self.assertEqual(len(controller.im_client.sent_button_messages), 1)
+ keyboard = controller.im_client.sent_button_messages[0][3]
+ buttons = keyboard.buttons[0]
+ self.assertEqual([button.text for button in buttons], [":eyes: 看 PR", ":rocket: 等评审完合并"])
+ self.assertEqual(
+ [button.callback_data for button in buttons],
+ ["quick_reply::eyes: 看 PR", "quick_reply::rocket: 等评审完合并"],
+ )
+
async def test_lark_log_message_strips_file_links_before_sending(self):
controller = _StubController("lark")
dispatcher = ConsolidatedMessageDispatcher(controller)