-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Refactor: Complete rewrite of AI message parsing system with streaming XML parser #4866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: Complete rewrite of AI message parsing system with streaming XML parser #4866
Conversation
…ed increased log level
…conflict with numerous other things that just use the default.
- Add TextDirective alias for TextContent - Add ToolDirective alias for ToolUse - Add Directive union type for TextDirective | ToolDirective - Maintain backward compatibility with AssistantMessageContent alias - Update internal usage to use new type names
- Extract parsing logic from monolithic parseAssistantMessage function - Create StreamingParser with specialized handler classes: - TextContentHandler: handles text content parsing - ToolUseHandler: manages tool directive detection and parsing - ParameterHandler: processes tool parameters - Maintain original streaming behavior and backward compatibility - All tests pass, no breaking changes - Improve code organization and maintainability
- Extract TextContentHandler into TextContentHandler.ts - Extract ParameterHandler into ParameterHandler.ts - Extract ToolUseHandler into ToolUseHandler.ts - Create types.ts for shared type definitions - Update StreamingParser to import from separate files - Update index.ts exports to reference correct files - Update README.md to reflect new file structure - Maintain backward compatibility and streaming behavior - All tests pass, multi-contributor friendly structure
…d names - Moved StreamingParser to DirectiveStreamingParser in assistant-message/ - Renamed directives/ to parsers/ - Created new parser classes with updated names: TextContentParser, ToolUseParser, ParameterParser - Simplified method names to parse() and finalize() - Updated documentation in README.md
- Changed imports in DirectiveStreamingParser.ts to use the index.ts file in parsers/ for a cleaner import structure
…amingParser - Replace character-by-character XML parsing with robust SAX parser library - Add sax and @types/sax dependencies for reliable XML parsing - Implement event-driven parsing with onopentag, onclosetag, ontext handlers - Add XML wrapping to handle multiple root elements in streaming scenarios - Create hasIncompleteXml() method for proper partial XML detection - Maintain backward compatibility with existing partial detection logic - Add comprehensive test suite with 6 new test cases - Preserve fallback to manual parsing when SAX parser fails - Improve error handling and maintain all existing functionality Benefits: - More robust XML parsing with better edge case handling - Improved performance with event-driven parsing - Cleaner, more maintainable code - Standards-compliant XML parsing - Full backward compatibility
…age case handler - Add missing log_message case handler in presentAssistantMessage.ts - Fix syntax error by adding missing opening brace for tool_use case - Make LogManager public in Task class to allow access from presentAssistantMessage - All tests passing (11/11) and TypeScript compilation clean - Log messages now properly displayed in Roo-Code Output window
…failures across all related files
- Update PushToolResult mock parameter type from string to ToolResponse - Update RemoveClosingTag mock to handle optional content parameter - Fix toolResult variable declarations to use ToolResponse type
- Add path normalization for Windows/Unix compatibility in test mocks - Use normalized paths and fallback matching for extractTextFromFile mocks - Handle backslash to forward slash conversion for cross-platform support - Add better error messages for debugging path issues
- Increase timeout from 5000ms to 10000ms for Windows compatibility - Test was timing out on Windows due to slower file system operations
- Add normalizePath helper to extract relative paths from absolute Windows paths - Use normalizePath consistently across all path resolution and file operation mocks - This ensures Windows absolute paths like D:\git\...\test\valid.txt are correctly normalized to test/valid.txt for comparison with expected relative paths - Fixes validation order test that was failing on Windows but passing on Linux
|
I'm really excited about this implementation! I'm marking this PR as a draft for now since I noticed a few changes that seem to be outside the scope of this PR. Let me know if you'd like a hand cleaning it up - I'm more than happy to help! |
|
@daniel-lxs @mrubens @cte @hannesrudolph In case it helps the approval process, I really like this implementation: it is really well-thought-out and well-organized. |
|
Oh, such a nice feature being put on hold almost indefinitely. |
|
Hey @mechanicmuthu, do you want to work on this? I think the contributor doesn't have time to work on this currently |
|
Closed as stale. |
Related GitHub Issue
Closes: #4692
Closes: #1317
Closes: #3039
Closes: #4426
Closes: #3404
Description
This PR represents a complete rewrite of the AI message parsing system, replacing the legacy
parseAssistantMessageimplementation with a modern, streaming-capable XML parser architecture. This addresses several critical issues with the previous parsing system and introduces significant architectural improvements.What Changed
Core Architecture Overhaul:
DirectiveStreamingParser)assistant-message/tomessage-parsing/directory structureNew Streaming Parser Features:
code)Type Safety Improvements:
Modular Component System:
Key Technical Improvements
Files Changed (97 total)
assistant-message/parsing system (3 files, ~550 lines)message-parsing/system (30+ files, ~2,000+ lines)Test Procedure
Automated Testing
Manual Testing Scenarios
Streaming Response Handling:
Code Block Processing:
code blockswith XML-like contentError Recovery:
Tool Integration:
Type of Change
srcor test files.Pre-Submission Checklist
pnpm lint).pnpm test).pnpm build).mainbranch.Screenshots / Videos
N/A - This is a backend/parsing system refactor with no UI changes.
Documentation Updates
src/core/message-parsing/Overview.md: Complete system architecture documentationdocs/directive-streaming-parser-code-block-fix.md: Detailed implementation plan and technical specsAdditional Notes
Performance Impact
Breaking Changes
None - This refactor maintains complete backward compatibility. All existing tool integrations continue to work without modification.
Migration Path
Code Review Focus Areas
Given the size of this PR (97 files), reviewers should focus on:
DirectiveStreamingParser.ts): Streaming XML processing and state managementhandlers/directory): Directive-specific processing logicdirectives/directory): New type system and interfaces__tests__/directories): Comprehensive test scenariosFuture Enhancements Enabled
This new architecture enables several future improvements:
Get in Touch
Discord: StevenTCramer
Important
Complete rewrite of AI message parsing system with a streaming XML parser, introducing modular directives and enhanced type safety.
DirectiveStreamingParserusing SAX-based streaming XML parser.assistant-message/tomessage-parsing/directory structure.assistant-message/parsing system (3 files, ~550 lines).message-parsing/system (30+ files, ~2,000+ lines).This description was created by
for 0fb5bf3. You can customize this summary. It will automatically update as commits are pushed.