Data Model
Rosetta stores documents as Lexical node trees. The live node tree is the source of truth while the user is typing. Plain text and persisted JSON are snapshots derived from that tree. Everything else, including pending edits, template anchors, and sync payloads, references positions inside it.
Core Entities
- Document nodes: block containers such as paragraphs and headings, plus inline marks such as bold, italic, and code.
- Pending edits: changes proposed by an agent. They live outside the document until the user accepts them.
- Template anchors: named regions defined by a template. A locked anchor can’t be modified by any agent.
- Derived editor snapshot: the plain text, selection offsets, cursor position, slash command context, SmartPhrase context, and context menu geometry emitted from a single Lexical update listener.
Persistence Shape
The app persists two synchronized views of the same document:
content: plain text used by workflows, search, exports, and legacy integrations.jsonContent: serialized Lexical state used to restore decorators, template fields, suggestions, and editor metadata.
Typing does not regenerate jsonContent on every keystroke. Rosetta updates the live Lexical tree immediately, emits a lightweight derived snapshot for UI consumers, then writes content and jsonContent after the persistence debounce or an explicit flush boundary.
Pending Edit Structure
A pending edit is a proposed change that has not touched the note yet. It stores the exact range it applies to, the original text, the replacement text, the agent’s reason, and the agent that produced it. Because those details travel with the edit, Rosetta can show the preview, record the audit trail, compare it with other suggestions, or mark it stale without changing the document.
interface PendingEdit {
id: string;
type: "insert" | "replace" | "delete";
start: number;
end: number;
original: string;
replacement: string;
reasoning: string;
agent: string;
}For the full lifecycle, including how a pending edit is remapped when the user types, how conflicts are handled, and when an edit is marked stale, see the Editor Guide.