Repository navigation
Markdown Formatting IR + Chunking (Signal/Slack/Telegram) - #920
TheSethRose wants to merge 3 commits into
Conversation
…oken styles) Co-authored-by: Piotr Rogowski <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR implements markdown formatting and chunked message delivery for Signal, superseding PR #843. The key improvement is a "format-first" approach where markdown is converted to Signal's text style format before chunking, preventing formatting tags from being split across chunks.
Changes:
- Added
format.tsmodule for Signal markdown-to-text-style conversion with chunking support - Modified
send.tsto support both markdown and plain text modes with style ranges - Updated
deliver.tsto apply Signal-specific formatting before chunking for text and media messages
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/signal/format.ts | New module implementing markdown-to-Signal conversion with style preservation during chunking |
| src/signal/format.test.ts | Test coverage for markdown formatting edge cases |
| src/signal/send.ts | Added textMode and textStyles options to support pre-formatted text |
| src/infra/outbound/deliver.ts | Integrated Signal-specific formatting and chunking logic |
| src/infra/outbound/deliver.test.ts | Test for Signal markdown chunking behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const cfg: ClawdbotConfig = { | ||
| channels: { signal: { textChunkLimit: 20 } }, | ||
| }; | ||
| const text = `Intro\\n\\n\`\`\`\`md\\n${"y".repeat(60)}\\n\`\`\`\\n\\nOutro`; |
There was a problem hiding this comment.
The template string contains incorrectly escaped characters. The \\n sequences should be actual newlines \n, and there are four backticks instead of three for the code fence. The test should be: `Intro\n\n\`\`\`md\n${"y".repeat(60)}\n\`\`\`\n\nOutro`
| const text = `Intro\\n\\n\`\`\`\`md\\n${"y".repeat(60)}\\n\`\`\`\\n\\nOutro`; | |
| const text = `Intro\n\n\`\`\`md\n${"y".repeat(60)}\n\`\`\`\n\nOutro`; |
| it("uses UTF-16 code units for offsets", () => { | ||
| const res = markdownToSignalText("😀 **bold**"); | ||
|
|
||
| const prefix = "😀 "; | ||
| expect(res.text).toBe(`${prefix}bold`); | ||
| expect(res.styles).toEqual([ | ||
| { start: prefix.length, length: 4, style: "BOLD" }, | ||
| ]); | ||
| }); |
There was a problem hiding this comment.
The test name says "uses UTF-16 code units for offsets" but doesn't actually verify UTF-16 behavior. The emoji 😀 is 2 UTF-16 code units, so if the implementation correctly uses UTF-16, prefix.length should be 3 (2 for emoji + 1 for space). The test should explicitly assert that the start offset is 3, not implicitly rely on prefix.length which may vary depending on JavaScript's string representation.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
| const results: SignalFormattedText[] = []; | ||
| let cursor = 0; | ||
|
|
||
| chunks.forEach((chunk, index) => { |
There was a problem hiding this comment.
Using forEach with imperative state mutations (cursor, results.push) is less clear than a traditional for loop. Consider using a for-of loop for better readability when performing stateful iteration.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
|
@copilot open a new pull request to apply changes based on the comments in this thread |
|
Please disable and don't use Copilot on this repo, reviews are so crappy. Use codex, though we will also use codex anyway to help review it so you don't need to |
|
Landed on main via:
Gate: pnpm lint && pnpm build && pnpm test |
This PR supersedes #843. It replaces per-channel markdown handling with a shared Markdown IR + renderer, and chunks before rendering so inline formatting never splits.
What changed
<url|label>; Telegram: HTML parse mode; Signal:text-styleranges +label (url)when needed./concepts/markdown-formatting.Notes
Testing
Credits
Original implementation by @Szpadel.