Repository navigation
emrg: draggable, resizable annotation panel, and annotations on the HTML preview - #3303
Merged
Merged
Conversation
…he HTML preview The panel was pinned by the stylesheet at one position for every window (`top: 76px; right: 20px; width: 340px`), and the HTML preview could not be annotated at all: it is a `WebContentsView` the main process composites above the app, so no DOM layer in the renderer can cover it. The chat panel's box is state now. The header is the drag handle, the corner is the only resize surface, a double-click puts it back, and the position survives a close because `persistPanelBox` writes it. The one rule the CSS carried - never larger than the window - moved into `clampBox` with it, since a style sheet cannot clamp a value a drag produces. The preview gets its own panel, drawn inside the page it previews: `preview-preload.js` runs in a sandboxed preload's own world behind a closed shadow root and hands the page nothing - no `contextBridge`, no `window.emrg`. A batch leaves as plain strings and the main process forwards it only when the sender is the preview view itself, with the file path taken from its own `previewPath` rather than from the page. It arrives in the renderer through `onPreviewAnnotation` and leaves through the composer, the same door the transcript's own batch uses. `sandbox: true` on the browser view is unchanged and still loads no preload, which `preview-annotation-wiring.test.js` pins: that view exists to show remote pages, and the page reaching nothing is its boundary.
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
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.
What the host asked for
The annotation panel could not be moved or resized, and the HTML preview could not be annotated at all. Two different causes:
annotation.css(position: fixed; top: 76px; right: 20px; width: 340px), so every person on every window got the same box.WebContentsViewthe main process composites above the app window. A DOM layer in the renderer sits under it, so the app's own floating panel can never hang over a previewed page.What changed
The panel's box is state.
lib/annotation.tsgainsPanelBox,defaultPanelBox,clampBox,storedPanelBoxandpersistPanelBox. The header is the drag handle, the bottom-right corner is the only resize surface, a double-click puts it back, and the position is remembered across a close. The one rule the stylesheet carried — never larger than the window — moved intoclampBox, because a style sheet cannot clamp a value a drag produces. While a drag is in flight the body getsanno-dragging, the same bargaincol-resizingmakes for a column handle: the pointer crosses the reply on its way, and a selection there would create an annotation mid-drag.The preview gets its own panel, drawn inside the page.
preview-preload.jsruns in a sandboxed preload's own world and builds its interface behind a closed shadow root. It hands the page nothing: nocontextBridge, noexposeInMainWorld, nowindow.emrg. Selecting text wraps it in a<mark>, the containing block becomes the quote, and the element path becomes the address — the rendered words are not the source words, so the file and the element are what make an annotation locatable again.The batch is text, and one sender is allowed. The preload answers
{ items: [{ paragraph, body, selector }] };main.jsforwards it only whenevent.sender === previewView.webContents, and the file comes from its ownpreviewPath, never from the page. The renderer receives it throughonPreviewAnnotation(preload's second subscription) and sends it through the composer — queueing, the user record and the session all live on that one path, as with the transcript's batch.composeMessagegrew an optionalsourceso a previewed page's annotation names its address; a message without one is byte-identical to what it produced before, and a test holds that half still.Tests
lib/annotation.test.ts: the default box, the clamp into a shrunken window, the floor a drag cannot pass, a corrupt stored value, the round trip, and the source line staying inside the item it belongs to.AnnotationMode.test.tsx: drag by header, clamped at the window's edge, resize from the corner, stopped at the floor, remembered across a close, reset by double-click. The old case that pinnedmax-height: calc(100vh - 168px)now measures the panel's real size against the window, because the bound moved from the stylesheet intoclampBox.preview-annotation-wiring.test.js(new): the preview view loads the preload, the browser view loads none, the preload hands the page nothing (comment-stripped, so a mention in prose is not a call), only the preview view's ownwebContentscan send a batch up, and the renderer composes through the composer.preload-api.test.js: the subscription surface became method → channel, soonPreviewAnnotationis frozen likeonEventis.Readings taken here
npm run typecheckclean,npm test1282 passed / 67 files.npm test272 pass, 8 skipped, 0 fail (279 executed).pytest tests/test_doc_counts.py82 passed,tests/test_agent_md_prompt_cap.py6 passed.Not here
Marks are not reattached after a preview reloads: that layer keeps no store, and an annotation that silently moved is worse than one that is gone. Persisting them across a reload is its own change.