-
Notifications
You must be signed in to change notification settings - Fork 61
Feat: Implement job code diff preview and coordinated apply for AI assistant #4283
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
Draft
lmac-1
wants to merge
13
commits into
main
Choose a base branch
from
3369-job-ai-chat-improvements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Implement backend support for coordinating job code apply operations across multiple collaborators, mirroring the workflow apply pattern. Backend changes: - Extract code field from Apollo responses in ai_assistant.ex - Support Apollo PR #259 'suggested_code' field with markdown fallback - Add channel handlers for start/done job code apply coordination - Broadcast apply state to prevent concurrent modifications Tests: - Add channel tests for job code apply coordination - Add end-to-end coordination test - Verify broadcasts include user metadata
Implement "Generated Job Code" display with APPLY/COPY buttons, coordinating apply operations across all collaborators. Frontend changes: - Add job code apply handler to AIAssistantPanelWrapper - Display "Generated Job Code" section in MessageList for job chat - Add store coordination functions for job code apply state - Disable save button during apply operation - Hide inline ADD buttons when message.code exists - Sync apply state across all connected users via broadcasts Coordination: - All users see "APPLYING..." state during apply - Apply buttons disabled for all users during operation - Graceful degradation when channel unavailable
Create foundational support for inline code diff previews: - Add MonacoRefContext to share Monaco ref without prop drilling - Implement showDiff/clearDiff methods in CollaborativeMonaco - Use dual-container pattern (standard editor + diff overlay) - Add dismiss button on diff overlay This infrastructure enables job chat to preview AI-suggested code changes directly in the Monaco editor.
Enable users to preview AI-suggested code changes: - Add PREVIEW button to job code messages (alongside APPLY/COPY) - Allow PREVIEW in readonly mode (removed isWriteDisabled check) - Auto-preview diffs when AI responds with code - Auto-dismiss diff when user changes workflow version - Track previewing state to prevent duplicate operations Addresses phase 2 enhancements from issue #3369.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4283 +/- ##
==========================================
+ Coverage 89.29% 89.30% +0.01%
==========================================
Files 425 425
Lines 19899 19914 +15
==========================================
+ Hits 17768 17784 +16
+ Misses 2131 2130 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Add 8 tests for extract_code_from_markdown/1 covering JavaScript/JS code block extraction, edge cases, and nil handling - Add 4 tests for job code apply coordination via Phoenix Channel covering user attribution (first_name vs email fallback), sequential coordination, and retry scenarios
- Add 11 tests for useAutoPreview hook covering mode filtering, session mount behavior, author filtering, duplicate prevention, and message selection - Add 11 tests for Monaco diff display (showDiff/clearDiff methods, dismiss button functionality) - Add monaco-editor mock to avoid 8MB+ package resolution issues - Configure vitest to alias monaco-editor to mock file
Auto-preview was broken for new conversations because the hook checked for any messages instead of assistant code messages. When a user sent the first message, the session had [userMessage], causing hasMessages to be true and preventing hasLoadedSession from being set. This meant the AI's code response would be skipped. Changes: - Check for assistant code messages instead of any messages on session initialization to correctly identify new vs old conversations - Add session ID tracking to properly reset state when switching between conversations - Add cleanup for diff editor on unmount to prevent memory leaks - Add test coverage for session switching behavior
The function was defined as private (defp) but tests were calling it as a public function, causing "undefined or private" errors. Changes: - Change defp to def to make the function public - Add @doc and @SPEC annotations - Update misleading comment that referenced waiting for Apollo PR #259 (that PR is already deployed; this is now a legitimate fallback) Fixes failing extract_code_from_markdown tests in AiAssistantTest.
Extract shared editor options (theme, fontSize, etc.) into a single baseEditorOptions object to ensure consistent formatting across both the collaborative editor and AI diff preview. Previously, the diff editor used 'vs-dark' theme with default font size while the main editor used custom 'default' theme with fontSize 14, causing visual inconsistencies.
Prevent users from accessing AI Assistant features when viewing older workflow versions (snapshots) to avoid confusion about which version they're modifying. Disables both UI buttons and keyboard shortcuts. Changes: - Add disabledMessage prop to AIButton component - Disable workflow-level AI button (Header) when viewing old snapshot - Disable job-level AI button (WorkflowEditor) when viewing pinned version - Disable Cmd+K keyboard shortcut when viewing pinned version - Show tooltip: "Switch to the latest version of this workflow to use the AI Assistant." Checks params['v'] to determine if viewing a pinned version vs latest.
Extend version change handling to automatically close the AI Assistant panel with animation when users switch to a pinned workflow version. Changes: - Close AI panel and clear session when switching to pinned version - Dismiss any active diff previews - Clear AI session messages and URL params (w-chat, j-chat) - Disable hover effects on AI buttons when disabled - Reuse isPinnedVersion to avoid duplicate version checks The panel remains closed when switching back to latest, requiring manual reopen. This prevents confusion about which version the AI is working with.
When closing the AI assistant panel or navigating back to the session list, clear any active diff preview in Monaco editor. This prevents the diff from persisting after the user has left the chat context. - Update handleClosePanel to clear diff before closing - Update handleShowSessions to clear diff before showing session list - Move both handlers after monacoRef and previewingMessageId declarations
Add applyingJobCodeMessageId to WorkflowStore state to track which AI message is being applied when job code changes are coordinated across collaborators. This ensures the "APPLYING..." indicator displays on the correct message for all users in a collaborative session, matching the existing workflow apply pattern. Changes: - Add applyingJobCodeMessageId field to Workflow.State interface - Store message_id in job_code_applying channel event handler - Clear message_id in job_code_applied channel event handler - Use stored message ID in AIAssistantPanelWrapper for display
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm still working on this (almost done!) but raising this in case you want to have a look.
Still to do:
Description
[todo]
Closes #3369
Validation steps
Additional notes for the reviewer
AI Usage
Please disclose how you've used AI in this work (it's cool, we just want to know!):
You can read more details in our Responsible AI Policy
Pre-submission checklist
:owner,:admin,:editor,:viewer)