Skip to content

fix: make /rewrite preserve formatting, structure, and verbatim content#207

Merged
quiet-node merged 2 commits into
mainfrom
fix/rewrite-preserve-mentions
Jun 8, 2026
Merged

fix: make /rewrite preserve formatting, structure, and verbatim content#207
quiet-node merged 2 commits into
mainfrom
fix/rewrite-preserve-mentions

Conversation

@quiet-node

@quiet-node quiet-node commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Overview

/rewrite was destroying the structure of anything it touched. Pasting a Markdown message (a bold header, a bulleted list of links, a relayed blockquote) and running /rewrite returned a single flattened prose paragraph: the list collapsed into a sentence, the blockquote and its > were stripped, and @mentions were dropped. The root cause was a prompt rule, "No markdown, bullets, or decorative icons," that told the model to remove every bit of formatting the user wrote.

This makes /rewrite format-preserving: it mirrors whatever formatting the input has and only improves the prose inside it.

How it works

The /rewrite prompt template is reworked around a single principle: mirror the original's formatting, change only the wording.

  • Format mirroring. Markdown headings, bold, italics, bullet and numbered lists, links, blockquotes, and code are kept along with their structure and order. The text inside each element is rewritten, but a list is never flattened into a paragraph. Plain text stays plain: no Markdown is added that was not already there.
  • Verbatim zones. Blockquotes (>), fenced and inline code, raw URLs, link targets, @mentions, and #channels are reproduced character for character. The wording inside a quote or code block is not changed at all.
  • Lighter touch. Already-natural text is left alone instead of being rewritten for its own sake.

The rule list was also consolidated (eleven rules down to seven) to cut redundancy, which matters because Thuki targets small local models that follow a dense, focused prompt more reliably than a long one. Two worked examples were added covering the exact failure modes (a Markdown link list and a relayed blockquote), and one redundant example was removed. The user-facing behavior text and generated docs are updated to match. /refine is intentionally left unchanged.

Testing

  • Regression tests assert the composed /rewrite prompt carries the format-mirroring and verbatim-zone instructions, preserves @mentions/#channels, and no longer contains the old Markdown-stripping rule.
  • Frontend suite green: 1598 tests, 100% coverage, typecheck, ESLint, and Prettier clean.

Note: this is a prompt-level guarantee rather than deterministic post-processing, so on a small model it is high-reliability rather than absolute. A deterministic parse-and-restitch approach was considered and rejected because it cannot preserve a quote's position or a list's structure without reimplementing a Markdown round-tripper, and it would strip the surrounding context the model needs to rewrite well.

Signed-off-by: Logan Nguyen <lg.131.dev@gmail.com>
Signed-off-by: Logan Nguyen <lg.131.dev@gmail.com>
@quiet-node quiet-node changed the title fix: preserve @mentions and #channels in /rewrite output fix: make /rewrite preserve formatting, structure, and verbatim content Jun 8, 2026
@quiet-node quiet-node merged commit d3d2edb into main Jun 8, 2026
3 checks passed
@quiet-node quiet-node deleted the fix/rewrite-preserve-mentions branch June 8, 2026 16:33
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.

1 participant