Skip to content

Markdown Formatting IR + Chunking (Signal/Slack/Telegram) - #920

Closed
TheSethRose wants to merge 3 commits into
openclaw:mainfrom
TheSethRose:fix-signal-formatting
Closed

TheSethRose wants to merge 3 commits into
openclaw:mainfrom
TheSethRose:fix-signal-formatting

Conversation

@TheSethRose

@TheSethRose TheSethRose commented Jan 14, 2026 •

Copy link
Copy Markdown

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

  • Added shared Markdown IR + renderer with UTF-16 offsets for Signal style ranges.
  • Chunk on IR before rendering (format-first) for Slack/Telegram/Signal.
  • Slack: render links as <url|label>; Telegram: HTML parse mode; Signal: text-style ranges + label (url) when needed.
  • Updated send paths + tests; new docs: /concepts/markdown-formatting.

Notes

  • Small output diffs expected (link rendering + chunk boundaries).
  • Spoilers are parsed only for Signal.

Testing

  • Not run locally yet (will run full gate before merge).

Credits

Original implementation by @Szpadel.

Copilot AI review requested due to automatic review settings January 14, 2026 21:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts module for Signal markdown-to-text-style conversion with chunking support
  • Modified send.ts to support both markdown and plain text modes with style ranges
  • Updated deliver.ts to 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`;

Copilot AI Jan 14, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`

Suggested change
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`;

Copilot uses AI. Check for mistakes.
Comment thread src/signal/format.test.ts
Comment on lines +58 to +66
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" },
]);
});

Copilot AI Jan 14, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Comment thread src/infra/outbound/deliver.ts Resolved
Comment thread src/signal/format.ts Outdated
const results: SignalFormattedText[] = [];
let cursor = 0;

chunks.forEach((chunk, index) => {

Copilot AI Jan 14, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

@TheSethRose

Copy link
Copy Markdown
Author

@copilot open a new pull request to apply changes based on the comments in this thread

@thewilloftheshadow

Copy link
Copy Markdown
Member

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

@steipete steipete changed the title Signal Formatting and Chunking Fixes (Supersedes #843) Markdown Formatting IR + Chunking (Signal/Slack/Telegram) Jan 15, 2026
@steipete

Copy link
Copy Markdown
Contributor

@steipete

Copy link
Copy Markdown
Contributor

Landed on main via:

  • bd7d362 refactor: unify markdown formatting pipeline
  • 9f1a8be refactor: unify markdown formatting pipeline (rebase cleanup)
  • 2c312e2 fix: finalize markdown IR formatting
  • e5c8aba fix: preserve markdown code fences
  • daf69e8 chore: update clawtributors (adds @TheSethRose)

Gate: pnpm lint && pnpm build && pnpm test

@steipete steipete closed this Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants