Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Dec 5, 2025

This PR attempts to address Issue #9858 by implementing an API method that provides programmatic access to the "Copy as markdown" functionality.

Summary

This implementation adds a new getTaskAsMarkdown API method that allows external extensions to programmatically retrieve task content formatted as markdown, similar to the existing UI "Copy as markdown" feature.

Implementation Details

The solution follows the established patterns in the Roo Code codebase for API methods and UI-backend communication:

  1. API Method: Added getTaskAsMarkdown to the main API class (src/extension/api.ts)
  2. Formatting Logic: Created a dedicated utility function formatTaskAsMarkdown (src/core/task/formatTaskAsMarkdown.ts) that converts ClineMessage arrays to markdown
  3. Type Definitions: Updated the RooCodeAPI interface in packages/types/src/api.ts
  4. Task Persistence: The method properly loads messages from disk for historical tasks using the existing readTaskMessages function

Key Features

  • Supports retrieving markdown for the current active task (no parameters)
  • Supports retrieving markdown for historical tasks by ID
  • Handles various message types (user feedback, assistant responses, tool usage, errors, etc.)
  • Returns undefined when no task is found or task has no messages
  • Comprehensive test coverage for both the formatting utility and API method

Testing

  • Added unit tests for formatTaskAsMarkdown utility (19 test cases)
  • Added unit tests for getTaskAsMarkdown API method (8 test cases)
  • All tests passing

Architecture Considerations

This implementation represents an internal "middleware" approach as suggested in the issue comment:

  • It leverages the existing UI formatting logic
  • It uses the established backend API patterns
  • It properly integrates with the task persistence layer
  • It follows the same error handling patterns as other API methods

Feedback and guidance are welcome!

- Add formatTaskAsMarkdown utility to convert ClineMessage arrays to markdown
- Implement getTaskAsMarkdown method in API class to retrieve task content as markdown
- Support both current active task and historical tasks by ID
- Add comprehensive tests for formatting and API functionality
- Update RooCodeAPI interface to include new method
- Fix ESLint warnings by wrapping case blocks with curly braces

This addresses issue #9858 by providing a programmatic way to access the "Copy as markdown" functionality that was previously only available through the UI.
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 5, 2025
@roomote
Copy link
Contributor Author

roomote bot commented Dec 5, 2025

Rooviewer Clock   See task on Roo Cloud

Review completed. This PR adds a well-implemented getTaskAsMarkdown API method that provides programmatic access to task content formatted as markdown. The implementation follows established codebase patterns, includes comprehensive test coverage (27 test cases), and handles edge cases appropriately. No issues found.

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@JohnDeeBDD
Copy link

@roomote I have a question. Before these methods are merged, I want to check to see if they are redundant in the code base. The application has a frontend UI component "Copy as markdown".The method getTaskAsMarkdown seams related to that, but our proposed method isn't used in the current implementation. The question is, how does the current implementation accomplish the functionality of composing the current task to markdown to send to the clipboard? Are we proposing a method that is already accomplished in the codebase via a different technique? Check for redundancy before we proceed.

@roomote
Copy link
Contributor Author

roomote bot commented Dec 7, 2025

Fixaroo Clock   See task on Roo Cloud

Redundancy Analysis Complete

The PR's getTaskAsMarkdown API method is NOT redundant. Here's why:

Existing Functionality Found

Feature Location Input Format Output Use Case
UI "Copy as markdown" button Markdown.tsx Single markdown string (prop) Clipboard Copy a single message block's visible markdown
Export Task History export-markdown.ts Anthropic.MessageParam[] File on disk (via save dialog) Interactive file export for sharing

This PR's New Functionality

Feature Location Input Format Output Use Case
getTaskAsMarkdown API formatTaskAsMarkdown.ts ClineMessage[] String return value Programmatic API access for external extensions

Key Differences

  1. Different data formats:

    • downloadTask works with Anthropic.MessageParam[] (API conversation format)
    • formatTaskAsMarkdown works with ClineMessage[] (internal UI message format stored in task persistence)
  2. Different access patterns:

    • UI Copy: User clicks a button for a single message
    • downloadTask: User triggers file save dialog (not programmatic)
    • getTaskAsMarkdown: Programmatic API call with string return (no UI interaction)
  3. No existing programmatic API: Before this PR, external extensions could NOT programmatically retrieve task content as markdown. They would need to either:

    • Use the UI manually (not programmatic)
    • Call downloadTask (shows save dialog - unsuitable for automation)
    • Parse ClineMessage arrays themselves (complex)

Conclusion

The PR fills a gap by providing programmatic API access to markdown-formatted task content for external extensions. The existing "Copy as markdown" UI button only copies individual message blocks to clipboard and doesn't provide the same capability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

4 participants