-
Notifications
You must be signed in to change notification settings - Fork 62
refactor(ai): sync shared surfaces for AI chat enhancements #732
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
70e4a43
refactor(ai): sync shared surfaces for PR #353 AI chat enhancements
dcoutinho1328 672e71b
chore(deps): bump dompurify from 3.2.4 to 3.4.0
dcoutinho1328 c906ab0
fix(ai): remove AI badge, restore per-hunk inline diff review
dcoutinho1328 1efb52c
fix(ai): sort imports, add diff and @types/diff dependencies
dcoutinho1328 b47b66c
Merge branch 'development' into refactor/ai-chat-pr353
dcoutinho1328 fa62720
Merge branch 'development' into refactor/ai-chat-pr353
dcoutinho1328 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
159 changes: 159 additions & 0 deletions
159
src/frontend/components/_features/[workspace]/editor/monaco/ai-diff-review.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| import * as monaco from 'monaco-editor' | ||
|
|
||
| import type { DiffHunk } from '../../../../../utils/ai-diff-review' | ||
|
|
||
| /** Render all diff review UI for the given hunks. Returns a cleanup function. */ | ||
| export function renderDiffReview( | ||
| editor: monaco.editor.IStandaloneCodeEditor, | ||
| hunks: DiffHunk[], | ||
| onKeep: (hunkId: string) => void, | ||
| onUndo: (hunkId: string) => void, | ||
| ): () => void { | ||
| const viewZoneIds: string[] = [] | ||
|
|
||
| // Clean up any stale buttons from previous renders | ||
| const editorDom = editor.getDomNode() | ||
| if (editorDom) { | ||
| editorDom.querySelectorAll('.ai-hunk-buttons').forEach((el) => { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| ;(el as any)._scrollDisposable?.dispose() | ||
| el.remove() | ||
| }) | ||
| } | ||
|
|
||
| // 1. Line decorations (green backgrounds for added/modified lines) | ||
| const decoOptions: monaco.editor.IModelDeltaDecoration[] = [] | ||
| for (const hunk of hunks) { | ||
| if (hunk.type === 'added' || hunk.type === 'modified') { | ||
| for (let line = hunk.startLine; line <= hunk.endLine; line++) { | ||
| decoOptions.push({ | ||
| range: new monaco.Range(line, 1, line, 1), | ||
| options: { | ||
| isWholeLine: true, | ||
| className: 'ai-diff-added', | ||
| glyphMarginClassName: 'ai-diff-added-gutter', | ||
| }, | ||
| }) | ||
| } | ||
| } | ||
| } | ||
| const decorations = editor.createDecorationsCollection(decoOptions) | ||
|
|
||
| // 2. View zones for deleted/modified lines (red ghost text) | ||
| editor.changeViewZones((accessor) => { | ||
| for (const hunk of hunks) { | ||
| if (hunk.oldLines.length === 0) continue | ||
| if (hunk.type !== 'removed' && hunk.type !== 'modified') continue | ||
|
|
||
| const domNode = document.createElement('div') | ||
| domNode.className = 'ai-diff-removed-zone' | ||
| domNode.style.fontFamily = 'var(--vscode-editor-font-family, monospace)' | ||
| domNode.style.fontSize = '13px' | ||
| domNode.style.lineHeight = '19px' | ||
| domNode.style.paddingLeft = '60px' | ||
| domNode.style.opacity = '0.45' | ||
|
|
||
| for (const line of hunk.oldLines) { | ||
| const lineDiv = document.createElement('div') | ||
| lineDiv.textContent = line || ' ' | ||
| lineDiv.style.textDecoration = 'line-through' | ||
| lineDiv.style.color = 'rgba(239, 68, 68, 0.7)' | ||
| domNode.appendChild(lineDiv) | ||
| } | ||
|
|
||
| const zoneId = accessor.addZone({ | ||
| afterLineNumber: hunk.startLine - 1, | ||
| heightInLines: hunk.oldLines.length, | ||
| domNode, | ||
| }) | ||
| viewZoneIds.push(zoneId) | ||
| } | ||
| }) | ||
|
|
||
| // 3. Action buttons per hunk ("Keep" / "Undo") | ||
| const buttonContainers: HTMLDivElement[] = [] | ||
|
|
||
| if (editorDom) { | ||
| for (const hunk of hunks) { | ||
| const container = document.createElement('div') | ||
| container.className = 'ai-hunk-buttons' | ||
| container.style.cssText = ` | ||
| position: absolute; right: 24px; z-index: 20; pointer-events: auto; | ||
| display: inline-flex; flex-direction: row; gap: 4px; | ||
| ` | ||
|
|
||
| const keepBtn = document.createElement('button') | ||
| keepBtn.textContent = 'Keep' | ||
| keepBtn.style.cssText = ` | ||
| cursor: pointer; border: none; background: rgba(34,197,94,0.2); | ||
| color: #4ade80; border-radius: 3px; padding: 1px 8px; | ||
| font-size: 10px; font-weight: 500; font-family: inherit; | ||
| transition: background 0.15s; line-height: 16px; | ||
| ` | ||
| keepBtn.onmouseenter = () => { | ||
| keepBtn.style.background = 'rgba(34,197,94,0.35)' | ||
| } | ||
| keepBtn.onmouseleave = () => { | ||
| keepBtn.style.background = 'rgba(34,197,94,0.2)' | ||
| } | ||
| keepBtn.addEventListener('click', (e) => { | ||
| e.stopPropagation() | ||
| onKeep(hunk.id) | ||
| }) | ||
|
|
||
| const undoBtn = document.createElement('button') | ||
| undoBtn.textContent = 'Undo' | ||
| undoBtn.style.cssText = ` | ||
| cursor: pointer; border: none; background: rgba(239,68,68,0.2); | ||
| color: #f87171; border-radius: 3px; padding: 1px 8px; | ||
| font-size: 10px; font-weight: 500; font-family: inherit; | ||
| transition: background 0.15s; line-height: 16px; | ||
| ` | ||
| undoBtn.onmouseenter = () => { | ||
| undoBtn.style.background = 'rgba(239,68,68,0.35)' | ||
| } | ||
| undoBtn.onmouseleave = () => { | ||
| undoBtn.style.background = 'rgba(239,68,68,0.2)' | ||
| } | ||
| undoBtn.addEventListener('click', (e) => { | ||
| e.stopPropagation() | ||
| onUndo(hunk.id) | ||
| }) | ||
|
|
||
| container.appendChild(keepBtn) | ||
| container.appendChild(undoBtn) | ||
|
|
||
| // Position based on the line's top coordinate | ||
| const topPx = Math.max(0, editor.getTopForLineNumber(hunk.startLine) - editor.getScrollTop()) | ||
| container.style.top = `${topPx}px` | ||
|
|
||
| editorDom.appendChild(container) | ||
| buttonContainers.push(container) | ||
|
|
||
| // Update position on scroll | ||
| const scrollDisposable = editor.onDidScrollChange(() => { | ||
| const newTop = Math.max(0, editor.getTopForLineNumber(hunk.startLine) - editor.getScrollTop()) | ||
| container.style.top = `${newTop}px` | ||
| }) | ||
|
|
||
| // Store disposable for cleanup | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| ;(container as any)._scrollDisposable = scrollDisposable | ||
| } | ||
| } | ||
|
|
||
| // Cleanup function — removes everything | ||
| return () => { | ||
| decorations.clear() | ||
| editor.changeViewZones((accessor) => { | ||
| for (const id of viewZoneIds) { | ||
| accessor.removeZone(id) | ||
| } | ||
| }) | ||
| for (const container of buttonContainers) { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| ;(container as any)._scrollDisposable?.dispose() | ||
| container.remove() | ||
| } | ||
| } | ||
| } |
51 changes: 0 additions & 51 deletions
51
src/frontend/components/_features/[workspace]/editor/monaco/ai-status-indicator.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: Autonomy-Logic/openplc-editor
Length of output: 448
🏁 Script executed:
Repository: Autonomy-Logic/openplc-editor
Length of output: 1297
🏁 Script executed:
Repository: Autonomy-Logic/openplc-editor
Length of output: 3267
🌐 Web query:
diff npm package v9 type definitions shipped💡 Result:
No, the "diff" npm package (kpdecker/jsdiff) version 9 type definitions have not shipped as of 2026-04-22. The latest released version is 8.0.4 (published around 2026-03-23). Type definitions were first shipped in v8.0.0 (May 2025), making
@types/diffobsolete. Version 9.0.0 exists as a prerelease on GitHub (drops ES5 support, uses TextDecoder/Uint8Array, compiled to ES6 target), but it is not published to npm. GitHub tags confirm no v9 release; latest is 8.0.4. npm/cli recently updated to diff@8.0.3 (Jan 2026).Citations:
🏁 Script executed:
Repository: Autonomy-Logic/openplc-editor
Length of output: 710
🏁 Script executed:
Repository: Autonomy-Logic/openplc-editor
Length of output: 348
Remove redundant
@types/diff—diffv9 ships its own type definitions.The
@types/diffpackage has been deprecated; its author explicitly states it is a stub types definition and that "diff provides its own type definitions, so you do not need this installed." From thediffpackage changelog: type definitions were first shipped in version 8.0.0 (May 2025).Beyond being redundant, the major versions are mismatched (
@types/diff@^7.0.2vsdiff@^9.0.0), which can cause TypeScript to pick up outdated stub types on some resolution setups. Drop the dev dependency and rely on the types bundled withdiff.📦 Suggested fix
- "@types/diff": "^7.0.2", "@types/eslint": "^9.6.1",🤖 Prompt for AI Agents