mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-12-02 15:07:31 -06:00
4.0 KiB
4.0 KiB
Claude Explain Implementation Plan
This document outlines the implementation plan for adding a "Claude Explain" feature to Compiler Explorer. This feature will allow users to get an AI-powered explanation of their code and its compilation results using Claude.
Overview
The Claude Explain feature is implemented completely as a client-side feature that:
- Takes compilation results from the client (source code, assembly, etc.)
- Sends them directly from the client browser to the Claude Explain API
- Displays the AI-generated explanation to the user
This approach distributes API load across clients rather than funneling through the CE server, making rate limiting more natural and reducing server load.
Implementation Status
- Create minimal server-side configuration in properties files
- Add tool registration in client-side config
- Implement client-side API integration in the UI
- Add user consent UI before sending data to API
- Implement error handling and loading states
- Update documentation
- Replace Monaco editor with HTML-based markdown rendering
- Test the implementation with various languages
Technical Implementation Details
Client-Side Implementation (Completed)
API Integration (Completed)
We've implemented direct API calls from the client using fetch inside the ExplainView class:
- The API endpoint is configured through the
explainApiEndpointoption (which comes fromcompiler-explorer.*.properties) - Requests include source code, compiler info, and assembly output
- Responses are displayed as markdown in the tool window
- Error handling is in place for API communication issues
UI Implementation (Completed)
-
Pane View:
- Created
ExplainViewclass extending the existingPaneclass - Set up proper markdown rendering for the explanation
- Implemented window title updating
- Created pug template at
views/templates/panes/explain.pug - Added extensive CSS styling with initial theme support
- Created
-
User Consent:
- Added a consent UI that appears before sending data to API
- Implemented session-persistent consent using a static class variable
- After consenting once, subsequent compilations explain automatically
-
Loading State:
- Shows a loading indicator during API calls
- Provides user feedback during explanation generation
-
Error Handling:
- Displays user-friendly error messages
- Handles network errors and API communication issues
Current Operation
- When compilation completes, the Claude Explain tool shows the consent UI
- User grants consent (stored for the session)
- Data is sent directly to the Claude Explain API
- The markdown explanation is displayed in the tool window
- Subsequent compilations automatically generate new explanations (no need to re-consent)
Next Steps
- Test with various languages and compilation scenarios
- Evaluate API performance and rate limiting needs
- Refine instruction set and language detection
- Address UI styling improvements based on user feedback:
- Update UI styling for "generating explanation" to work with all themes (especially pink theme)
- Make "generating explanation" part of the toolbar with proper animation and status colors (similar to
.status-iconin compiler view) - Reduce excessive padding on the bottom bar
- Dark mode AI disclaimer is invisible
- General toolbar alignment and padding
- Bottom bar sizing
- Update privacy policy - we need to mention this in the privacy policy, and check the wording on the "Send my code" consent thingy.
- Proper theming support across all color schemes. we seem to have put the dark theme in the main sccs.
- Disclaimers about AI limitations and potential inaccuracies. Better and longer text here
- Be much clearer about what information is sent before the first submission. Folks didn't necessarily know the source was sent too
- Support a
// no-aimagic comment in source to never send to Anthropic etc (cc @hanadusikova)