Skip to content

Replace XML tags with markdown formatting in chat prompts#205

Merged
subsy merged 2 commits intomainfrom
claude/fix-opencode-cli-issue-V8Zcy
Jan 23, 2026
Merged

Replace XML tags with markdown formatting in chat prompts#205
subsy merged 2 commits intomainfrom
claude/fix-opencode-cli-issue-V8Zcy

Conversation

@subsy
Copy link
Copy Markdown
Owner

@subsy subsy commented Jan 23, 2026

Summary

Updated the prompt building logic in ChatEngine to use markdown formatting instead of XML tags for better compatibility with CLI agents that may interpret angle-bracket tags as protocol markers.

Changes

  • Replaced <system> XML tags with ## Instructions markdown header
  • Replaced <conversation> XML tags with ## Conversation History markdown header
  • Added ## Current Request markdown header for the current user message
  • Removed the explicit Assistant: prompt suffix to allow agents more flexibility in response formatting
  • Improved overall prompt structure with consistent markdown formatting

Implementation Details

  • The prompt structure remains logically equivalent, with system instructions, conversation history, and current request clearly separated
  • Markdown headers provide clear visual separation while avoiding potential conflicts with CLI agent protocol parsing
  • Conversation history entries maintain the User: and Assistant: prefixes for clarity within the history section
  • Empty strings are added to parts array to ensure proper line spacing in the final joined output

Summary by CodeRabbit

  • Refactor

    • Prompt assembly now uses Markdown section headers for instructions, conversation history and current request; surrounding spacing adjusted. No change to behaviour or user-facing features.
  • Tests

    • Expanded test coverage to validate the new prompt formatting, section ordering and history limits.

✏️ Tip: You can customize this high-level summary in your review settings.

…t compatibility

The chat engine's buildPrompt() method used <system> and <conversation>
XML tags to wrap the system prompt and history. This caused OpenCode CLI
(and potentially other agents) to timeout when processing the prompt via
stdin, as the angle-bracket tags may be interpreted as protocol markers
by the CLI tool's input parser.

Replace with markdown headers (## Instructions, ## Conversation History,
## Current Request) which matches the format used by the ralph-tui run
engine templates that work correctly with all agents.

Fixes #204

https://claude.ai/code/session_014bffPdJT7UX84NpCw7zxig
@vercel
Copy link
Copy Markdown

vercel bot commented Jan 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
ralph-tui Ignored Ignored Preview Jan 23, 2026 2:32pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 23, 2026

Walkthrough

Prompt assembly in the chat engine was reformatted from XML-like tags to Markdown sections (## Instructions, ## Conversation History, ## Current Request). Tests were expanded and a public ChatEngine export was added; no changes to message handling, history slicing, or API interactions.

Changes

Cohort / File(s) Change Summary
Prompt format & export
src/chat/engine.ts
Replaced XML-style wrappers (<system>, <conversation>, trailing Assistant:) with Markdown headers (## Instructions, ## Conversation History, ## Current Request) and adjusted surrounding blank lines; ChatEngine is now publicly exported.
Tests & mocking
src/chat/engine.test.ts
Added/imported ChatEngine, introduced createMockAgent helper, expanded assertions to verify Markdown section headers, history formatting and limits, and absence of old XML tags.

Sequence Diagram(s)

(omitted — changes are formatting and tests, no new multi-component control flow)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐇 I hopped through prompts, tidy and bright,

Swapped tags for headers, made sections light.
Instructions here, history in view,
Current request, crisp and new.
A rabbit’s nod to clean, readable cue.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Replace XML tags with markdown formatting in chat prompts' directly and concisely describes the main change in the changeset — replacing XML-like tags with Markdown headers in the prompt assembly logic.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 23, 2026

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 44.88%. Comparing base (e4ccc45) to head (9f66979).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/chat/engine.ts 87.50% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #205      +/-   ##
==========================================
+ Coverage   44.23%   44.88%   +0.65%     
==========================================
  Files          84       84              
  Lines       24229    24231       +2     
==========================================
+ Hits        10718    10877     +159     
+ Misses      13511    13354     -157     
Files with missing lines Coverage Δ
src/chat/engine.ts 63.54% <87.50%> (+53.10%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Adds tests verifying the ChatEngine.buildPrompt() method uses markdown
headers instead of XML tags for CLI agent compatibility:
- Uses ## Instructions instead of <system> tags
- Uses ## Conversation History instead of <conversation> tags
- Uses ## Current Request for the user message
- Does not end with bare Assistant: marker
- Sections appear in correct order
- Respects maxHistoryMessages limit
- Includes User:/Assistant: role prefixes in history

https://claude.ai/code/session_014bffPdJT7UX84NpCw7zxig
@subsy subsy merged commit eff9228 into main Jan 23, 2026
9 checks passed
@subsy subsy deleted the claude/fix-opencode-cli-issue-V8Zcy branch January 23, 2026 14:38
sakaman pushed a commit to sakaman/ralph-tui that referenced this pull request Feb 15, 2026
…-V8Zcy

Replace XML tags with markdown formatting in chat prompts
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.

2 participants