The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(slack): parse mrkdwn <url|label> inside rich_text lists
z23da25b166628d
diff --git a/plugins/platforms/slack/block_kit.py b/plugins/platforms/slack/block_kit.pyindex b29827c29af..ed447824e65 100644--- a/plugins/platforms/slack/block_kit.py+++ b/plugins/platforms/slack/block_kit.py@@ -75,6 +75,11 @@ def _indent_level(spaces: str) -> int:# Order matters: code first (opaque), then links, then emphasis._INLINE_CODE_RE = re.compile(r"`([^`]+)`")_LINK_RE = re.compile(r"(?<!!)\[([^\]]+)\]\(([^()\s]+(?:\([^()]*\)[^()\s]*)*)\)")+# Slack mrkdwn autolink: <scheme:target> or <scheme:target|label>.+# Mentions (<@U…>, <#C…>, <!here>) have no scheme: and stay as text.+_SLACK_LINK_RE = re.compile(+ r"<([a-zA-Z][a-zA-Z0-9+.\-]*:[^>|]+)(?:\|([^>]+))?>"+)_BOLD_RE = re.compile(r"(?:\*\*|__)(.+?)(?:\*\*|__)")_ITALIC_RE = re.compile(r"(?<![\*_])(?:\*|_)(?![\*_\s])(.+?)(?<![\*_\s])(?:\*|_)(?![\*_])")_STRIKE_RE = re.compile(r"~~(.+?)~~")@@ -105,14 +110,28 @@ def _inline_elements(text: str) -> List[Dict[str, Any]]:emit_text(m.group(1), {**style, "code": True})pos = m.end()_walk_links(s[pos:], style)+ def _emit_link(url: str, text: str, style: Dict[str, bool]) -> None:+ link_el: Dict[str, Any] = {"type": "link", "url": url, "text": text}+ if style:+ link_el["style"] = dict(style)+ elements.append(link_el)+def _walk_links(s: str, style: Dict[str, bool]) -> None:pos = 0for m in _LINK_RE.finditer(s):+ _walk_slack_links(s[pos : m.start()], style)+ _emit_link(m.group(2), m.group(1), style)+ pos = m.end()+ _walk_slack_links(s[pos:], style)++ def _walk_slack_links(s: str, style: Dict[str, bool]) -> None:+ # rich_text does not interpret mrkdwn. Agents often emit <url|label>+ # (works in section/mrkdwn; was literal in lists/quotes/table cells).+ pos = 0+ for m in _SLACK_LINK_RE.finditer(s):_walk_emphasis(s[pos : m.start()], style)- link_el: Dict[str, Any] = {"type": "link", "url": m.group(2), "text": m.group(1)}- if style:- link_el["style"] = dict(style)- elements.append(link_el)+ url = m.group(1)+ _emit_link(url, m.group(2) or url, style)pos = m.end()_walk_emphasis(s[pos:], style)def _walk_emphasis(s: str, style: Dict[str, bool]) -> None:diff --git a/tests/gateway/test_slack_block_kit.py b/tests/gateway/test_slack_block_kit.pyindex 434d127be73..966a933a1d8 100644--- a/tests/gateway/test_slack_block_kit.py+++ b/tests/gateway/test_slack_block_kit.py@@ -46,6 +46,34 @@ class TestInlineFormatting:blob = str(blocks)assert "https://example.com/x" in blob+ def test_slack_mrkdwn_link_in_bullet_becomes_link_element(self):+ """rich_text lists must parse Slack <url|label>, not emit it as text.++ rich_blocks turns markdown bullets into rich_text_list. rich_text does+ not interpret mrkdwn, so <url|text> has to become type=link.+ """+ blocks = render_blocks(+ "- <https://example.com/x|GitLab #1> — allow `in_progress`"+ )+ assert blocks is not None+ rich = [b for b in blocks if b["type"] == "rich_text"][0]+ els = rich["elements"][0]["elements"][0]["elements"]+ links = [e for e in els if e.get("type") == "link"]+ assert len(links) == 1+ assert links[0]["url"] == "https://example.com/x"+ assert links[0]["text"] == "GitLab #1"+ assert not any("<https://" in (e.get("text") or "") for e in els)+ assert any(e.get("style", {}).get("code") for e in els)++ def test_slack_mentions_in_bullet_are_not_links(self):+ blocks = render_blocks("- ping <@U123> in <#C456>")+ assert blocks is not None+ els = blocks[0]["elements"][0]["elements"][0]["elements"]+ assert all(e.get("type") != "link" for e in els)+ blob = "".join(e.get("text") or "" for e in els)+ assert "<@U123>" in blob+ assert "<#C456>" in blob+def test_blank_line_separated_ordered_items_stay_in_one_list(self):"""Regression: blank lines between ordered items must not reset numbering.