Skip to content

Add "Clear Chat" feature with backend support and markdown parsing#11

Merged
codebyNorthsteep merged 2 commits into
mainfrom
enhancement/clear-message-history
May 11, 2026
Merged

Add "Clear Chat" feature with backend support and markdown parsing#11
codebyNorthsteep merged 2 commits into
mainfrom
enhancement/clear-message-history

Conversation

@codebyNorthsteep

@codebyNorthsteep codebyNorthsteep commented May 11, 2026

Copy link
Copy Markdown
Owner

This pull request introduces a new "Clear Chat" feature, allowing users to erase their chat history for a session both on the frontend and backend. It also improves markdown rendering in chat messages and updates documentation and tests accordingly. The changes enhance user experience and maintainability by providing a more robust chat management system and clearer feedback.

Backend API and Logic Enhancements

  • Added a new DELETE /api/v1/chat/{sessionId} endpoint in BifrostController to clear chat history for a session, along with corresponding service and storage methods to empty the chat history while preserving the session itself. [1] [2] [3] [4]
  • Updated and added tests for the new clear chat feature in controller, service, and storage layers to ensure correct behavior and coverage. [1] [2] [3]

Frontend Features and UI Improvements

  • Implemented a "Clear Chat" button in the UI (index.html, app.js, style.css) that calls the new backend endpoint, resets the personality selection to default, and displays a confirmation prompt and thematic message. [1] [2] [3] [4]
  • Integrated Marked.js for markdown parsing, enabling rich formatting in chat messages. Updated the message rendering logic to display markdown content as HTML in the chat window. [1] [2]

Documentation Updates

  • Expanded the README.md to document the new clear chat functionality, including updated API documentation, backend and frontend descriptions, and tech stack notes. [1] [2] [3]

Project Structure and Test Cleanup

  • Renamed BifrostController.java to reside in the controller package for better project organization and updated test imports accordingly. [1] [2] [3]

Minor Improvements

  • Updated documentation and code comments for clarity, and added notes about the test suite coverage in the README.md.

These changes collectively provide users with more control over their chat sessions, improve the chat interface, and ensure the system is well-documented and tested.

Summary by CodeRabbit

  • New Features

    • Added "Clear Chat History" button to delete stored conversations and reset the active session.
    • Assistant responses now render with Markdown formatting support.
  • Documentation

    • Expanded README with detailed architecture documentation, API endpoint reference including new DELETE endpoint, tech stack updates, and resilience settings.
  • Tests

    • Added test coverage for chat history clearing functionality.

Review Change Stack

- Implemented a "Clear Chat" button in the UI to reset chat history and personality selection.
- Backend enhancements include a `DELETE /api/v1/chat/{sessionId}` endpoint for clearing chat history while preserving the session.
- Added markdown rendering for chat messages using Marked.js.
- Updated related tests and README documentation to reflect changes.
@coderabbitai

coderabbitai Bot commented May 11, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@codebyNorthsteep has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 17 minutes and 14 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2c7bb925-a139-4f4d-abcd-51e7af88eb49

📥 Commits

Reviewing files that changed from the base of the PR and between dbe1cd1 and 2f44b29.

📒 Files selected for processing (3)
  • README.md
  • src/main/resources/static/app.js
  • src/main/resources/static/index.html
📝 Walkthrough

Walkthrough

This PR implements a complete "clear chat history" feature across backend and frontend. The backend adds a DELETE endpoint (/api/v1/chat/{sessionId}) that clears stored session history, while the frontend provides a UI button with confirmation and markdown rendering of assistant messages via Marked.js.

Changes

Clear Chat History Feature

Layer / File(s) Summary
Domain Model
src/main/java/org/example/projectbifrost/domain/ChatSession.java
ChatSession.clearChatHistory() clears the message list while preserving the session ID.
Storage Layer
src/main/java/org/example/projectbifrost/storage/ChatSessionStorage.java
clearSessionHistory(sessionId) looks up an existing session and clears its chat history without deleting the session.
Service Orchestration
src/main/java/org/example/projectbifrost/service/ChatService.java
clearChatHistory(sessionId) delegates to storage to clear a session's history.
Controller and HTTP API
src/main/java/org/example/projectbifrost/controller/BifrostController.java
Wraps POST/GET endpoints in ResponseEntity; adds DELETE /api/v1/chat/{sessionId} returning 204 No Content; logs requests with session-ID masking.
Frontend UI and Clear Button
src/main/resources/static/index.html, src/main/resources/static/app.js
Adds clear button and Marked.js CDN; clearChat() prompts user, sends DELETE request, and resets chat display and personality to HEIMDALL on success.
Button Styling
src/main/resources/static/style.css
#clear-button base and hover styles with padding, colors, borders, and transitions.
Markdown Rendering
src/main/resources/static/app.js
appendMessage() now parses assistant messages via window.marked.parse() and injects HTML into a markdown-body div for rich text display.
Test Coverage
src/test/java/org/example/projectbifrost/controller/BifrostControllerTest.java, src/test/java/org/example/projectbifrost/service/ChatServiceTest.java, src/test/java/org/example/projectbifrost/storage/ChatSessionStorageTest.java
New tests for controller DELETE endpoint (204 response and service invocation), service history clearing, and storage clearing with session persistence.
Documentation
README.md
Expanded feature list, API endpoint table, backend architecture (storage/exception handling/message flow), resilience settings, frontend client behavior, techstack (Marked.js), and test suite notes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A clear-chat feature hops into the fold,
With markdown so bright and histories bold,
The session persists, but the chat takes a bow,
Marked.js renders the future, right here, right now!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: adding a 'Clear Chat' feature with backend support and markdown parsing. It directly relates to the core functionality introduced across backend (DELETE endpoint, service, storage), frontend (clear button, markdown rendering), tests, and documentation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch enhancement/clear-message-history

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Line 149: appendMessage currently assigns parsed markdown directly into the
DOM via contentDiv.innerHTML = window.marked.parse(text), which allows XSS from
untrusted LLM output; fix by either installing and importing DOMPurify and
replacing that assignment with a sanitized string (use
DOMPurify.sanitize(window.marked.parse(text))) or by configuring Marked to
disallow raw HTML (disable HTML parsing in Marked options) and then inserting
the safe output, ensuring you update appendMessage and any direct uses of
window.marked.parse to use the sanitized output instead.

In `@src/main/resources/static/app.js`:
- Around line 101-125: clearChat can race with an in-flight send and a late POST
response may repopulate the cleared UI; modify clearChat to
check/chatState.isWaiting and return early when true, or abort the active send
request before issuing the DELETE by wiring an AbortController used by your send
routine; also disable dom.clearBtn while chatState.isWaiting (you can reuse the
provided setLoading(active) to toggle chatState.isWaiting,
dom.clearBtn.disabled, dom.button.disabled and dom.typing visibility) so clears
are gated until the send completes or is aborted.
- Around line 139-143: The code injects HTML from window.marked.parse(text)
directly into contentDiv.innerHTML causing stored/reflected XSS; fix by
sanitizing the parsed HTML before assigning innerHTML — e.g., call a sanitizer
like DOMPurify.sanitize(...) on the string returned by window.marked.parse(text)
(or enable/plug a safe renderer option in marked if available) and then assign
the sanitized result to contentDiv.innerHTML; update the code paths around
contentDiv, window.marked.parse, and msgDiv to ensure all
user/model/backend-provided text is parsed then sanitized before DOM insertion.

In `@src/main/resources/static/index.html`:
- Line 8: Update the external marked.js import in
src/main/resources/static/index.html to pin to a specific version (use
marked@18.0.3) and add Subresource Integrity and crossorigin attributes on the
<script> tag; generate the SHA-256 SRI hash for the exact versioned file (e.g.,
marked.umd.js) using the suggested curl/openssl command or an SRI tool and place
that base64 hash in the integrity attribute while adding crossorigin="anonymous"
to the same <script> element so the browser can verify the CDN payload before
execution.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 35709376-0d48-47cf-9f98-6998160a4ca8

📥 Commits

Reviewing files that changed from the base of the PR and between 0b11978 and dbe1cd1.

📒 Files selected for processing (11)
  • README.md
  • src/main/java/org/example/projectbifrost/controller/BifrostController.java
  • src/main/java/org/example/projectbifrost/domain/ChatSession.java
  • src/main/java/org/example/projectbifrost/service/ChatService.java
  • src/main/java/org/example/projectbifrost/storage/ChatSessionStorage.java
  • src/main/resources/static/app.js
  • src/main/resources/static/index.html
  • src/main/resources/static/style.css
  • src/test/java/org/example/projectbifrost/controller/BifrostControllerTest.java
  • src/test/java/org/example/projectbifrost/service/ChatServiceTest.java
  • src/test/java/org/example/projectbifrost/storage/ChatSessionStorageTest.java

Comment thread README.md Outdated
Comment thread src/main/resources/static/app.js
Comment thread src/main/resources/static/app.js
Comment thread src/main/resources/static/index.html Outdated
- Integrated DOMPurify to sanitize AI-generated markdown and prevent XSS attacks.
- Enhanced UI by disabling "Clear Chat" button during active responses to avoid race conditions.
- Updated README to document added XSS protection.
@codebyNorthsteep
codebyNorthsteep merged commit 3202e99 into main May 11, 2026
2 checks passed
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