Linora

Editor (packages/editor)

Owner: ED1 (wave 3; WP-E before). ADRs 0008 (undo), 0013 (engine), 0007 (drag preview via presence), 0002. Contracts: DocSession, Gesture, MountEditor in shared/src/session.ts.

Current (wave 3, ED1)

packages/editor/src/ runs on a DocSession (ADRs 0008, 0024, 0501, 0502). Every document change is session.commit(ops) or a Gesture; undo/redo are the session’s (own transactions only).

Target

packages/editor/src/
  editor.ts       wiring: session, engine, camera, render loop hooks, selection (local state)
  tools/          move (select, marquee, drag, alt-dup, resize, endpoint, drop into frames), hand, shape
                  (rect/ellipse/line/arrow/polygon/star/frame), pencil, text (+ in-place editing)
  frames.ts       top-level frame index (labels, draw / drop targets)
  text/layout.ts  caret / selection / hit layout of the edited text (engine line layout)
  commands.ts     delete, duplicate, clipboard, nudge, z-order, bounds/rotation/style edits -> ops
  keymap.ts       shortcuts (unchanged)
  overlay.ts      selection/handles/marquee + remote cursors, remote selections, agent badges
  bench.ts        scripted benchmarks (unchanged behaviour)
  index.ts        mountEditor(stage, session): EditorHandle

The target layout above is implemented (wave 3, ED1). Remaining target items: bulk TRANSFORM / SET_GEOMETRY commits (ADR 0103) and engine clip content (EN2).

Rules: every change to the document is session.commit(ops) or a Gesture. Tools never touch engine buffers except through the existing GPU preview (xf) during drags. Selection, hover, camera and tool are local UI state (selection is mirrored to presence).

Tool and command map

Every editor capability maps to ops and to an MCP tool (agents can do everything a person can).

Editor feature (today) Ops MCP tool
Rect / Ellipse / Polygon / Star / Line / Arrow tool (drag, click = 100x100) Gesture: CREATE, then SET x/y/w/h (rotation for lines) create_nodes
Pencil Gesture: CREATE PATH, SET points (sent at <= 10 Hz while drawing) create_nodes (points)
Move drag (selection) none during drag (GPU preview + presence drag); pointer-up: SET x/y per node transform_nodes (translate/moveTo)
Alt-drag duplicate CREATE_BULK of copies + SET x/y duplicate_nodes
Resize handles (shift = keep ratio, alt = from center) pointer-up: SET x/y/w/h (lines: endpoints) transform_nodes (scale + anchor)
Line endpoint drag Gesture: SET x/y/w/rotation update_nodes (x1,y1,x2,y2)
Arrow-key nudge (shift = 10) SET x/y transform_nodes (translate)
Delete / Cut DELETE delete_nodes
Duplicate (Cmd+D), Copy/Paste (into the selected frame) CREATE_BULK (encodeSubtrees, fresh ids, offset) duplicate_nodes
Bring forward / backward / front / back SET PARENT_INDEX (new keys) arrange_nodes (order)
Select all, click/shift select, marquee local selection + presence find_nodes, set_selection
Properties: X/Y/W/H SET x/y/w/h update_nodes, transform_nodes
Rotation SET rotation update_nodes, transform_nodes (rotate)
Corner radius, opacity, stroke width SET cornerRadius / opacity / strokeWidth update_nodes
Fill / stroke color (picker drag = one undo step) Gesture: SET fill/stroke update_nodes
Undo / Redo commit inverse batches (own only) undo, redo
Zoom, fit, pan, hand tool local camera; viewport in presence render (region), get_peers (viewports)
Generate website / random shapes (perf panel) CREATE_BULK blocks from packages/doc/gen dev only
Clear canvas DELETE of root children delete_nodes
Text tool: click = auto width, drag = fixed width (T) Gesture: CREATE TEXT, then SET text + w/h/x/y per keystroke (one undo step) create_nodes (text)
Edit text in place (double-click, Enter), font size / weight / line height / alignment / sizing Gesture or commit: SET text / font props + re-measured w/h/x/y update_nodes
Frame tool (F / A), drawn frames adopt enclosed layers; presets Gesture: CREATE FRAME (+ SET PARENT_INDEX/x/y of adopted layers); commit: CREATE FRAME (preset) create_nodes
Resize a frame (handles: content kept; panel W/H, presets) Gesture: SET frame x/y/w/h (+ children x/y); commit: SET w/h update_nodes
Clip content SET clipContent update_nodes
Draw into a frame / drop into or out of a frame (move drag) CREATE with the frame as parent / SET PARENT_INDEX + x/y/rotation (page placement kept) create_nodes (parent), arrange_nodes
Layers panel drag and drop (reorder, reparent into frames and groups, multi-select) SET PARENT_INDEX (+ x/y/rotation when the parent changes) arrange_nodes

Remote collaboration UI

Remote cursors (interpolated, name label, agent badge), remote selection outlines in the peer’s color, remote drag previews (engine remote-xf slots), avatars in the top bar (web app). Overlay drawing costs O(visible peers) per rendered frame.

How it protects the baseline

Drags remain GPU-only; ops are produced once per gesture end or per frame (gestures); remote changes reach the engine through the change feed, never synchronously. Every change passes the interleaved perf gate (npm run bench, ADR 0015) and the memory gate (npm run bench -- --memory, ADR 0024).

Acceptance (WP-E, phase E1)

All rows above implemented against DocSession (tested with createLocalSession and two-session sync tests); undo/redo bit-exact; remote cursors/selections/drag previews visible; bench parity; 10K remote SETs <= 4 ms.

Status (wave 3, ED1)