feat(pulse/telegram): render markdown in messages via HTML parse mode#1285
Open
catchingknives wants to merge 1 commit into
Open
feat(pulse/telegram): render markdown in messages via HTML parse mode#1285catchingknives wants to merge 1 commit into
catchingknives wants to merge 1 commit into
Conversation
The Telegram module sends ctx.reply(text) with no parse_mode, so the DA's **bold**, *italic*, `code`, code fences, and links arrive as literal characters on the phone. The existing TELEGRAM MODE OVERRIDE prompt worked around this by steering the DA toward plain prose — a render-side problem masquerading as a content-side restriction. Changes: - New `mdToHtml` helper in modules/markdown-html.ts converts a useful subset of markdown to Telegram HTML: bold, italic, strikethrough, inline code, fenced code, links, ATX headers (→ bold lines), bullets (→ '•'). - Telegram module sends with parse_mode: 'HTML' by default; plain-text fallback on any send error via .catch(). - New `markdown_mode: "html" | "plain"` field in TelegramConfig, defaults to 'html' — opt-out preserved for users who want raw text. - TELEGRAM MODE OVERRIDE prompt flipped from 'no formatting' to an inline cheatsheet of what renders, so the DA writes naturally- formatted prose. Robustness: - Code blocks are stash-and-restored before other transforms run — bold/italic cannot leak into them. - Italic boundaries admit punctuation, whitespace, and HTML tag chars so '**a _b_**' nests correctly while 'snake_case' and 'Array<T>' survive untouched. - Unbalanced markers degrade to literal characters, so chunk-splitting at the 4096-char boundary cannot produce broken HTML. Tests: $ bun test ./Releases/v5.0.0/.claude/PAI/PULSE/modules/telegram.test.ts 21 pass, 0 fail End-to-end validation: showcase message exercising every transformation sent through @nairyo_bot; renders correctly on iOS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The Telegram module sends
ctx.reply(text)with noparse_mode, so the DA's**bold**,*italic*,`code`, code fences, and links arrive as literal characters on the phone. The existing TELEGRAM MODE OVERRIDE prompt worked around this by steering the DA toward plain prose — a render-side problem masquerading as a content-side restriction.Change
mdToHtmlhelper inmodules/markdown-html.tsconverts a useful subset of markdown to Telegram HTML: bold, italic,strikethrough,inline code, fenced code, links, ATX headers (→ bold lines), bullets (→•).parse_mode: "HTML"by default; plain-text fallback on any send error via.catch().markdown_mode: "html" | "plain"field inTelegramConfig, defaults to"html"— opt-out preserved for anyone who wants raw text.Robustness choices
**a _b_**nests correctly whilesnake_caseandArray<T>survive untouched.Tests
Releases/v5.0.0/.claude/PAI/PULSE/modules/telegram.test.ts— 21 cases covering snake_case safety, nested formatting, HTML escaping, code-block isolation, unbalanced markers, URLs with underscores, multiple inline spans.End-to-end validation
Showcase message exercising every transformation sent through a real Telegram bot; renders correctly on iOS.
Relationship to other open PRs
v2 — per-thread sessions, live tool reactions, empty-response recovery) — no functional overlap on markdown rendering. feat(pulse/telegram): v2 — per-thread sessions, live tool reactions, empty-response recovery #1281 setsparse_mode: "Markdown"on its/help,/status, and/threadscommand-output text only, not on the DA's actual replies, and uses the legacy Telegram Markdown mode (no nesting, no underscores-in-identifiers safety). This PR adds proper HTML rendering of the DA's prose with a regex-tested converter and a plain-text fallback. The two PRs do sharemodules/telegram.tsand would file-conflict on merge — whichever lands second will need a rebase, but the conceptual scopes are orthogonal.