diff --git a/src/openjarvis/agents/deep_research.py b/src/openjarvis/agents/deep_research.py index da23ab8a..4d4d63af 100644 --- a/src/openjarvis/agents/deep_research.py +++ b/src/openjarvis/agents/deep_research.py @@ -141,10 +141,9 @@ abbreviations, related terms. - Research answers: cite as [source] title -- author. End with Sources. - Casual answers: no citations needed. - Concise unless detail is asked for. -- Format for text messages: use plain text, short paragraphs, and \ -simple bullet points (- item). Never use markdown headers (##), bold \ -(**), italic (*), code blocks, LaTeX ($), or tables. These don't \ -render in SMS/iMessage. Use line breaks and dashes for structure. +- Use simple markdown: **bold** for emphasis, bullet lists with -, \ +short paragraphs. Avoid LaTeX, complex tables, and deeply nested \ +formatting. Keep it readable in both web and messaging apps. - If nothing found, say so honestly and suggest alternatives.""" diff --git a/src/openjarvis/server/agent_manager_routes.py b/src/openjarvis/server/agent_manager_routes.py index 9338f1aa..8c7fb556 100644 --- a/src/openjarvis/server/agent_manager_routes.py +++ b/src/openjarvis/server/agent_manager_routes.py @@ -1428,17 +1428,42 @@ def create_agent_manager_router( _msg_queue: _q.Queue = _q.Queue() _processing = _thr.Event() - def _strip_markdown(text: str) -> str: - """Strip markdown for clean Slack messages.""" - # Remove headers - text = _re.sub(r"^#{1,6}\s+", "", text, flags=_re.MULTILINE) - # Remove bold/italic markers - text = _re.sub(r"\*\*(.+?)\*\*", r"\1", text) - text = _re.sub(r"\*(.+?)\*", r"\1", text) - # Remove code blocks - text = _re.sub(r"```[\s\S]*?```", "", text) - text = _re.sub(r"`(.+?)`", r"\1", text) - # Clean up extra whitespace + def _to_slack_fmt(text: str) -> str: + """Convert markdown to Slack formatting.""" + # Headers → bold + text = _re.sub( + r"^#{1,6}\s+(.+)$", + r"*\1*", + text, + flags=_re.MULTILINE, + ) + # Bold: **text** → *text* + text = _re.sub( + r"\*\*(.+?)\*\*", r"*\1*", text, + ) + # Italic: _text_ stays, *text* → _text_ + # (only single * not already bold) + text = _re.sub( + r"(? + text = _re.sub( + r"\[(.+?)\]\((.+?)\)", + r"<\2|\1>", + text, + ) + # Remove LaTeX + text = _re.sub(r"\$\$.+?\$\$", "", text) + text = _re.sub(r"\$(.+?)\$", r"\1", text) + # Remove HTML tags + text = _re.sub(r"<[^>|]+>", "", text) + # Clean up whitespace text = _re.sub(r"\n{3,}", "\n\n", text) return text.strip() @@ -1460,7 +1485,7 @@ def create_agent_manager_router( reply = ( "Agent not available." ) - say_fn(_strip_markdown(reply)) + say_fn(_to_slack_fmt(reply)) _processing.clear() @bolt_app.event("message")