The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(discord): header-only cards for slash confirm and clarify prompts too
teknium163aa02d339f4
diff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.pyindex a22a4c7e190..d647d37b717 100644--- a/plugins/platforms/discord/adapter.py+++ b/plugins/platforms/discord/adapter.py@@ -5391,11 +5391,6 @@ class DiscordAdapter(DiscordMediaMixin, BasePlatformAdapter):logger.warning("[%s] %s failed: %s", self.name, fail_log, e)return SendResult(success=False, error=str(e))- @staticmethod- def _embed_body(text: str, limit: int = 4088) -> str:- """Trim to Discord's 4096-char embed description limit (conservatively)."""- return text if len(text) <= limit else text[: limit - 3] + "..."-# Payload lives in plain content: embeds can be invisible/detached on web/mobile._EA_HEADER = (f"⚠️ **{EA_HEADER_TEXT}**\n\n""Do you want Hermes to run this command?\n\n"@@ -5451,9 +5446,9 @@ class DiscordAdapter(DiscordMediaMixin, BasePlatformAdapter):) -> SendResult:"""Send a three-button slash-command confirmation prompt."""def _build(_channel):- embed = discord.Embed(- title=title or "Confirm", description=self._embed_body(message), color=discord.Color.orange(),- )+ # Header-only card (same rule as the exec approval prompt): the message lives in+ # content only, so embed-rendering clients don't see it twice (#114693).+ embed = discord.Embed(title=title or "Confirm", color=discord.Color.orange())content = self._self_contained_prompt_content(f"**{title or 'Confirm'}**", message)view = SlashConfirmView(session_key=session_key, confirm_id=confirm_id,@@ -5486,16 +5481,13 @@ class DiscordAdapter(DiscordMediaMixin, BasePlatformAdapter):return str(c).strip()def _build(_channel):- embed = discord.Embed(- title="❓ Hermes needs your input",- description=self._embed_body(str(question or "").strip()),- color=discord.Color.orange(),- )+ # Header-only card (same rule as the exec approval prompt): the question and hint live+ # in content only, so embed-rendering clients don't see them twice (#114693).+ embed = discord.Embed(title="❓ Hermes needs your input", color=discord.Color.orange())# 5 buttons × 5 rows = 25; one slot is reserved for "Other".clean_choices = [s for s in (_flatten_choice(c) for c in (choices or [])) if s][:24]if clean_choices:hint = "Pick one below, or click ✏️ Other to type a custom answer."- embed.add_field(name="Choices", value=hint, inline=False)view = ClarifyChoiceView(choices=clean_choices, clarify_id=clarify_id,allowed_user_ids=self._allowed_user_ids,@@ -5503,7 +5495,6 @@ class DiscordAdapter(DiscordMediaMixin, BasePlatformAdapter):)else:hint = "Reply in this channel with your answer."- embed.add_field(name="Reply", value=hint, inline=False)view = Nonecontent = self._self_contained_prompt_content("❓ **Hermes needs your input**", str(question or "").strip(), tail=f"\n\n{hint}",diff --git a/tests/gateway/test_discord_exec_approval_content.py b/tests/gateway/test_discord_exec_approval_content.pyindex a4e1b97d3c8..deb1c8d8f21 100644--- a/tests/gateway/test_discord_exec_approval_content.py+++ b/tests/gateway/test_discord_exec_approval_content.py@@ -69,3 +69,38 @@ async def test_exec_approval_content_stays_within_discord_cap_for_long_reason():assert len(sent["content"]) <= adapter.MAX_MESSAGE_LENGTHassert "xxx" in sent["content"] # the command preview is not starved to zero+++def _embed_text(embed):+ # Fields are attribute objects on discord.py and dicts on the test stub.+ return (embed.description or "") + "".join(+ str(getattr(f, "value", None) or (f.get("value") if isinstance(f, dict) else "") or "")+ for f in embed.fields)+++async def test_slash_confirm_embed_is_header_only_card():+ """Same rule as the approval prompt: content carries the message once, the embed is a header card."""+ adapter = DiscordAdapter(PlatformConfig(enabled=True, token="***"))+ sent = _capture_channel(adapter)++ await adapter.send_slash_confirm(+ chat_id="555", title="Reset session?", message="This will clear the conversation history.",+ session_key="discord:555", confirm_id="c1")++ assert "clear the conversation history" in sent["content"]+ assert "clear the conversation history" not in _embed_text(sent["embed"])+++async def test_clarify_embed_is_header_only_card():+ adapter = DiscordAdapter(PlatformConfig(enabled=True, token="***"))+ sent = _capture_channel(adapter)++ await adapter.send_clarify(+ chat_id="555", question="Which environment should I deploy to?", choices=["staging", "prod"],+ clarify_id="cl1", session_key="discord:555")++ assert "Which environment should I deploy to?" in sent["content"]+ assert "Pick one below" in sent["content"]+ assert "Which environment should I deploy to?" not in _embed_text(sent["embed"])