diff --git a/contributors/emails/coffee@coffeebot.dev b/contributors/emails/coffee@coffeebot.dev new file mode 100644 index 0000000000..917bb57cf7 --- /dev/null +++ b/contributors/emails/coffee@coffeebot.dev @@ -0,0 +1 @@ +coffee-the-dev diff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.py index c064716fd5..56cb90a949 100644 --- a/plugins/platforms/discord/adapter.py +++ b/plugins/platforms/discord/adapter.py @@ -46,11 +46,14 @@ def _format_discord_markdown_link(label: str, url: str) -> str: URL label can therefore win over the Markdown destination and remain a broken link. Dropping only the scheme keeps the preview recognizable while leaving one unambiguous click target. + + The destination is wrapped in angle brackets (````) so Discord does + not unfurl an OG-preview embed under every tool progress bubble. """ label = _DISCORD_URL_LABEL_SCHEME_RE.sub("", label, count=1) escaped_label = _DISCORD_MARKDOWN_LINK_LABEL_RE.sub(r"\\\1", label) escaped_url = quote(url, safe=":/?#[]@!$&'*+,;=%") - return f"[{escaped_label}]({escaped_url})" + return f"[{escaped_label}](<{escaped_url}>)" class _Snowflake: diff --git a/tests/gateway/test_discord_format.py b/tests/gateway/test_discord_format.py index 56726fc2b2..5684eb6f1c 100644 --- a/tests/gateway/test_discord_format.py +++ b/tests/gateway/test_discord_format.py @@ -54,7 +54,7 @@ class TestDiscordToolPreviewFormatting: out = adapter.format_tool_preview(ToolPreview(visible, truncated=True, url=url)) - assert out == f"[hermes-agent.nousresearch...]({url})" + assert out == f"[hermes-agent.nousresearch...](<{url}>)" def test_truncated_url_label_is_not_a_second_url_target(self): from agent.display import ToolPreview @@ -67,7 +67,7 @@ class TestDiscordToolPreviewFormatting: assert out == ( "[centaur.run/secrets/advanced-...]" - "(https://centaur.run/secrets/advanced-permissioning)" + "()" ) def test_link_escapes_discord_markdown_delimiters(self): @@ -82,7 +82,7 @@ class TestDiscordToolPreviewFormatting: assert adapter.format_tool_preview(preview) == ( r"[example.com/docs/\[beta\]...]" - r"(https://example.com/docs/_%28beta%29)" + r"()" ) def test_structured_tool_event_uses_clickable_truncated_url(self): @@ -99,7 +99,7 @@ class TestDiscordToolPreviewFormatting: ) assert out is not None - assert f"[{visible.removeprefix('https://')}]({url})" in out + assert f"[{visible.removeprefix('https://')}](<{url}>)" in out def test_untruncated_url_remains_plain(self): from agent.display import ToolPreview diff --git a/tests/gateway/test_run_progress_topics.py b/tests/gateway/test_run_progress_topics.py index d3adf9160b..18020f0a96 100644 --- a/tests/gateway/test_run_progress_topics.py +++ b/tests/gateway/test_run_progress_topics.py @@ -577,7 +577,7 @@ def test_discord_truncated_tool_url_links_to_full_destination(monkeypatch, tmp_p assert adapter.sent visible = UrlPreviewAgent.URL[:37] + "..." label = visible.removeprefix("https://") - assert f"[{label}]({UrlPreviewAgent.URL})" in adapter.sent[0]["content"] + assert f"[{label}](<{UrlPreviewAgent.URL}>)" in adapter.sent[0]["content"] class CommentaryAgent: