This is the canonical implementation doc for Marginalia.
If you need release steps, read docs/maintainers/release.md. If you need reliability guarantees, read docs/reliability.md.
Marginalia is not a general editor. It is a disposable review surface that sits inside an agent loop:
- a draft file lands on disk,
- a hook opens Marginalia,
- the user edits inline and optionally explains important changes,
- the app writes a bundle,
- the agent reads
summary_for_agent.md.
The job is to preserve intent with minimal friction, then get out of the way.
The current desktop UI has three distinct areas:
- Change rail: visible edits only, ordered by document position.
- Manuscript editor: Milkdown editor with diff decorations and persistent saved-note markers.
- Rationale column: explicit compose/read states for change-bound rationales.
Compact layouts use a popover instead of the full rationale column.
Important interaction rule: selecting an edit is not the same as composing a rationale. Compose mode must be entered deliberately.
- Rust reads the markdown file and exposes it to the frontend.
- The frontend stores:
- original markdown
- edited markdown
- original plain text
- edited plain text
- annotation records
- Diffing runs on the plain-text projections, because that is what the user actually reviewed.
- Resolved annotations are derived against the latest diff.
- On finalize, the frontend generates the bundle and Rust persists it.
Annotations are durable records, not a changeId -> note map.
Each record stores:
- stable annotation ID
- rationale text
- optional matched writing rule
- target metadata:
- last resolved change ID
- change type
- excerpt
- line hint
- before/current/after line context
- block key
- created/updated timestamps
Resolution policy:
- exact change ID match,
- conservative heuristic reattachment,
- otherwise mark the note
stale.
Stale notes are a first-class state. They should never drift silently to a different edit.
Current bundle contents:
original.mdfinal.mdchanges.jsonannotations.jsonchanges.patchprovenance.jsonsummary_for_agent.md
summary_for_agent.md is the primary agent-facing artifact.
Current schema notes:
changes.jsonis bundle format3.0annotations.jsonschema is3.0provenance.jsonschema is1.0
src/routes/review/+page.svelteApp orchestration, recovery, selection/composer state, bundle finalization.src/lib/stores/app.jsShared document state and derived annotation/diff state.src/lib/utils/diff.jsStable text diff logic.src/lib/utils/annotations.jsAnnotation creation, normalization, remapping, and stale resolution.src/lib/utils/bundle.jsBundle generation and summary/provenance output.src/lib/components/Editor.svelteMilkdown host plus manuscript note markers.src/lib/components/ChangeRail.svelteLeft-side review index.src/lib/components/AnnotationColumn.svelteDesktop rationale workflow.src/lib/components/AnnotationPopover.svelteCompact rationale workflow.src-tauri/src/lib.rsNative file and bundle I/O, CLI parsing, window commands.hooks/post-write.shHook queueing and handoff back to the agent.
- A session begins when a file is loaded.
- Autosave snapshots are written under
~/.marginalia/sessions/. - Recovery can resume the last active session, including in-progress rationale drafts.
- Finalizing a review writes a bundle and clears the active session marker.
- full document management
- collaborative editing
- open-ended comment threads
- silently “helpful” note reassignment
If a behavior makes the review surface feel like a general editor instead of a sharp review tool, it is probably the wrong direction.