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): accept plain-markdown-link quick-reply buttons in a group (#455)

Call White8e2dcde994bc
diff --git a/core/reply_enhancer.py b/core/reply_enhancer.py
index 02f35b9e4..156642a1b 100644
--- a/core/reply_enhancer.py
+++ b/core/reply_enhancer.py
@@ -66,17 +66,38 @@ _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 bracket buttons.
-# Accept link-formatted variants defensively because some agents accidentally
-# wrap a quick-reply label in a Markdown/Slack link.
+# Accept link-formatted variants defensively because agents routinely wrap a
+# quick-reply label in a link — the label stays the payload, the URL is dropped.
+# Tolerated link forms: plain Markdown ``[label](https://…)``, Slack-escaped
+# ``[label](<https://…>)``, and Slack autolink ``<https://…|label>``. Only
+# ``http(s)`` targets count (a bare ``[label](foo)`` is left alone).
+#
+# ``_PLAIN_URL`` allows one level of balanced parentheses (e.g. Wikipedia
+# ``…/A_(B)``) like ``_FILE_LINK_RE`` does, so such a URL doesn't truncate at the
+# first ``)`` and drop the rest of the button group.
+_PLAIN_URL = r"https?://(?:[^()\s]|\([^()]*\))+"
+# Optional link wrapper after a ``[label]`` token: ``(<https://…>)`` or ``(https://…)``.
+_LINK_SUFFIX = r"(?:\((?:<https?://[^>\n]+>|" + _PLAIN_URL + r")\))?"
+
_BUTTON_BLOCK_RE = re.compile(
r"\n-{3,}\s*\n" # --- separator line
- r"((?:\s*(?:\[[^\]]+\](?:\(<https?://[^)>\n]+>\))?|<https?://[^|>\n]+\|[^>\n]+>)\s*(?:[||]\s*)?)+)" # button tokens
+ r"((?:\s*(?:\[[^\]]+\]" + _LINK_SUFFIX + r"|<https?://[^|>\n]+\|[^>\n]+>)\s*(?:[||]\s*)?)+)" # button tokens
r"\s*$", # trailing whitespace / end of string
)
# Individual button tokens. Link variants are accepted for compatibility only;
-# the button label remains the quick-reply payload.
-_BUTTON_TOKEN_RE = re.compile(r"\[([^\]]+)\](?:\(<https?://[^)>\n]+>\))?|<https?://[^|>\n]+\|([^>\n]+)>")
+# the bracket label (or Slack link text) remains the quick-reply payload.
+_BUTTON_TOKEN_RE = re.compile(
+ r"\[([^\]]+)\]" + _LINK_SUFFIX + r"|<https?://[^|>\n]+\|([^>\n]+)>"
+)
+
+# A block that is *only* plain ``[label](https://…)`` links (one or more, with no
+# ``|``/``|`` separator and no bare/angle/Slack token) is a genuine reference-link
+# section, not a button group — see ``_extract_buttons``. Plain links become
+# buttons only when an explicit separator or another unambiguous token is present.
+# (Detection matches the whole block instead of scanning for ``|``, which a URL
+# may itself contain.)
+_PLAIN_LINKS_ONLY_RE = re.compile(r"(?:\s*\[[^\]]+\]\(" + _PLAIN_URL + r"\)\s*)+")
# Silent output blocks are intentionally simple and model-facing. They are
# stripped before any reply enhancement parsing so hidden text cannot create
@@ -185,6 +206,14 @@ def _extract_buttons(text: str) -> Tuple[List[QuickReplyButton], str]:
return [], text
block = m.group(1)
+ # A block made up solely of plain Markdown links with no ``|``/``|``
+ # separator is a genuine reference-link section (``---\n[Release notes](…)``,
+ # possibly several on their own lines), not a button group — leave the text
+ # untouched. Plain links become buttons only alongside a separator or another
+ # unambiguous token (bare ``[label]`` / angle / Slack link).
+ if _PLAIN_LINKS_ONLY_RE.fullmatch(block.strip()):
+ return [], text
+
buttons: List[QuickReplyButton] = []
for bracket_label, slack_label in _BUTTON_TOKEN_RE.findall(block):
label = bracket_label or slack_label
diff --git a/tests/test_reply_enhancer_platform.py b/tests/test_reply_enhancer_platform.py
index 54a20aedc..9cf34b3dc 100644
--- a/tests/test_reply_enhancer_platform.py
+++ b/tests/test_reply_enhancer_platform.py
@@ -206,6 +206,58 @@ class ReplyEnhancerPlatformTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual(reply.text, text)
self.assertEqual(reply.buttons, [])
+ def test_process_reply_accepts_plain_markdown_link_button_within_group(self):
+ # Regression: a plain ``[label](https://…)`` token used to drop EVERY
+ # button in the group (its trailing ``(url)`` broke the end-anchored
+ # block match). A link inside a ``|`` group must render as a button, with
+ # the label as the payload and the URL discarded.
+ reply = process_reply(
+ "Done.\n\n---\n"
+ "[👀 我先确认] | [🔗 看 PR](https://github.com/cyhhao/vibe-remote/pull/451) | [✅ 直接合并]"
+ )
+
+ self.assertEqual(reply.text, "Done.")
+ self.assertEqual(
+ [button.text for button in reply.buttons],
+ ["👀 我先确认", "🔗 看 PR", "✅ 直接合并"],
+ )
+
+ def test_process_reply_accepts_plain_markdown_link_button_as_last_token(self):
+ reply = process_reply("Done.\n\n---\n[A] | [docs](https://example.com)")
+
+ self.assertEqual(reply.text, "Done.")
+ self.assertEqual([button.text for button in reply.buttons], ["A", "docs"])
+
+ def test_process_reply_preserves_lone_plain_link_with_pipe_in_url(self):
+ # A lone reference link whose URL contains ``|`` must still be preserved
+ # as text: the lone-link disambiguation matches the whole block rather than
+ # scanning for a stray ``|`` (which a URL may legitimately hold).
+ text = "Done.\n\n---\n[chart](https://example.com/a?b=1|2)"
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, text)
+ self.assertEqual(reply.buttons, [])
+
+ def test_process_reply_preserves_multiple_plain_reference_links_without_separator(self):
+ # Several plain Markdown links after ``---`` with no ``|`` separator are a
+ # reference-link section, not a button group — they must stay as text.
+ text = "Done.\n\n---\n[Release notes](https://example.com/r)\n[Changelog](https://example.com/c)"
+ reply = process_reply(text)
+
+ self.assertEqual(reply.text, text)
+ self.assertEqual(reply.buttons, [])
+
+ def test_process_reply_accepts_plain_link_button_with_balanced_parens_in_url(self):
+ # A plain-link button whose URL contains balanced parentheses (e.g. a
+ # Wikipedia ``A_(B)`` target) must not truncate at the first ``)`` and drop
+ # the group.
+ reply = process_reply(
+ "Done.\n\n---\n[Wiki](https://en.wikipedia.org/wiki/A_(B)) | [Done]"
+ )
+
+ self.assertEqual(reply.text, "Done.")
+ self.assertEqual([button.text for button in reply.buttons], ["Wiki", "Done"])
+
def test_prompt_includes_task_watch_and_hook_usage_with_current_session_id(self):
context = MessageContext(
user_id="U1",