Skip to content

feat(annotate): per-file version diff for .md and .html (rendered HTML highlights) - #961

Merged
backnotprop merged 7 commits into
backnotprop:mainfrom
Mainloop-AI:feat/annotate-version-diff
Jul 7, 2026
Merged

backnotprop merged 7 commits into
backnotprop:mainfrom
Mainloop-AI:feat/annotate-version-diff

Conversation

@egouilliard-leyton

Copy link
Copy Markdown
Contributor

Closes #960

What

Brings the version diff (the highlighted "what changed since the last version" view that plan mode has) to annotate mode, for both Markdown and HTML files. Annotate already has the diff UI (PlanDiffViewer, Version Browser, block-level comments) — it just never received previousPlan/versionInfo, because the annotate server didn't track history. This wires that up.

  • .md / .txt → the existing rendered Markdown diff (clean / classic / raw), with block comments.
  • .html with --render-html → the diff is rendered as the real page with inline <ins>/<del> highlights (not a source dump), so you see where it changed, and commenting still works because it's the same HtmlViewer iframe.

How

  • History keyed by file path. Unlike the plan flow (generateSlug = first-heading + date), annotate keys history by file path — annotate-{sanitized-basename}-{hash8} — so re-opening the same file groups its versions across edits even when headings change. Dedup + sequential numbering reuse the existing saveToHistory storage.
  • Server (packages/server/annotate.ts + Pi apps/pi-extension/server/serverAnnotate.ts). On open, save the markdown (or raw HTML source) to history, then expose previousPlan / versionInfo / diffCurrent on /api/plan and add /api/plan/version + /api/plan/versions. Both runtimes updated per AGENTS.md.
  • HTML rendered diff. New packages/shared/html-diff.ts: a small, dependency-light, tag-aware htmlDiff(old, new) that wraps changed text in <ins>/<del> while keeping tags balanced (<script>/<style> treated as opaque). The server sends diffHtml = rewriteHtml(htmlDiff(prev, current)); HtmlViewer injects ins/del highlight CSS and shows a "Show changes" toggle; App swaps the iframe to the diff page when toggled and suppresses the Markdown block-diff path on the HTML surface (where markdown is empty).

Testing

  • packages/shared/html-diff.test.ts — 9 unit tests (text change, word replace, added element, script/style opacity, identical-input no-op, structural balance).
  • tsc --noEmit clean for packages/shared, packages/server, packages/ui; frontend build clean.
  • Manually verified end to end on a real 58 KB HTML spec: the diff renders as the page with inline highlights, the toggle works, and commenting works on the diff view. /api/plan returns renderAs: html + diffHtml, and /api/plan/versions lists the stored versions.

Notes

  • HTML diff is a linear token diff (delete + insert for moves; attribute-only changes re-emit the tag without a visible marker). Good enough for the prose/spec-review use case; a tree-aware pass could be a follow-up.

🤖 Generated with Claude Code

egouilliard and others added 5 commits June 24, 2026 17:32
Annotate mode never tracked version history, so the existing Plan Diff
(highlighted diff vs a previous version) only worked in plan mode. Wire
per-file version history into the annotate server so the same diff UI —
badge, Version Browser, block-level comments — works when annotating a
standalone .md/.txt/.html file.

- key history by file path (stable across edits) rather than the plan
  flow's heading+date slug
- save the markdown (or raw HTML source) to history on each open, expose
  previousPlan + versionInfo + diffCurrent on /api/plan
- add /api/plan/version and /api/plan/versions to the annotate server

Markdown lights up end to end; HTML needs frontend follow-ups (feed the
HTML source as the diff content, surface the badge on the html surface,
default to source diff mode).
For --render-html files, render the version diff as the real page with
inline <ins>/<del> highlights instead of a markdown/source diff:

- add packages/shared/html-diff.ts: a tag-aware htmlDiff() that wraps
  changed text in <ins>/<del> while keeping tags balanced (script/style
  opaque). 9 unit tests.
- annotate server computes diffHtml = rewriteHtml(htmlDiff(prev, current))
  and exposes it on /api/plan
- HtmlViewer: inject ins/del highlight CSS, add a 'Show/Hide changes'
  toggle in its action bar
- App: store diffHtml, swap the iframe to the diff page when toggled, and
  suppress the markdown block-diff path on the HTML surface

Commenting still works because the diff page renders through the same
HtmlViewer iframe bridge.
Parity for the Pi (node:http) runtime: per-file version history,
previousPlan/versionInfo/diffCurrent + diffHtml on /api/plan, the
/api/plan/version[s] endpoints, and project wiring from the Pi CLI.
Vendors @plannotator/shared/html-diff into pi-extension/generated.
…ut, hide dead version picker on HTML

- apps/pi-extension/package.json: declare the 'diff' dependency —
  generated/html-diff.js imports it at module load, so a standalone Pi
  install failed to resolve it and broke every annotate session (the
  monorepo masked this via root hoisting)
- packages/shared/html-diff.ts: tag tokenizer now consumes quoted
  attribute values whole, so a '>' inside title="a > b" no longer
  splits the tag and corrupts the diff output; 3 regression tests
- annotate history is now gated by PLANNOTATOR_ANNOTATE_HISTORY /
  config.annotateHistory (default on) and disclosed in AGENTS.md —
  it writes copies of annotated files into the data dir, which users
  should be able to see coming and turn off
- packages/editor/App.tsx: hide the sidebar Versions tab on the HTML
  surface — the base-version picker has nothing to drive there (the
  HTML diff is fixed to current-vs-previous); the viewer's Show
  changes toggle is unaffected
@backnotprop

Copy link
Copy Markdown
Owner

Great feature and genuinely well-built — the reuse of the plan-version machinery, the dual-runtime mirror, and the htmlDiff test cases all show real care. Thank you!

We reviewed in depth and, to save you a round-trip, pushed the fixes directly to your branch (hope that's OK — happy to walk through any of it):

  1. diff dependency declared in apps/pi-extension/package.json — html-diff imports it at module load, so a standalone Pi install couldn't resolve it (the monorepo masked this via hoisting) and every annotate session broke.
  2. Tokenizer made attribute-aware — <[^>]*> split tags at a > inside quoted attributes (e.g. title="a > b"), corrupting the diff output. Now quoted values are consumed whole; 3 regression tests added.
  3. History persistence disclosed + opt-out — saving a copy of every annotated file into the data dir is new behavior users should be able to see and disable: PLANNOTATOR_ANNOTATE_HISTORY=0 / { "annotateHistory": false }, default on, documented in AGENTS.md.
  4. Versions tab hidden on the HTML surface — the base-version picker had nothing to drive there (the HTML diff is fixed to current-vs-previous), so it was a dead control; the viewer's "Show changes" toggle is untouched.

All gates green after the changes (typecheck, 1,698 tests, both app builds). Non-blocking notes for possible follow-ups, no action needed: a size cap on htmlDiff for very large documents, and <textarea> contents rendering literal <ins> markers when changed.

Merging once CI confirms — thanks again for the contribution!

The repo/diff badge cluster is absolutely positioned in the card's top
padding, sized by guesswork (py-5..py-12). One chip row fit; the diff
badge's second row overflowed into the H1, and mobile wrapping made the
badge sit on top of the heading. Measure the cluster (ResizeObserver)
and insert exactly the clearance it needs — zero when it fits, so
existing single-row layouts don't shift. Pre-existing plan-mode bug
surfaced by the annotate version diff.
@backnotprop
backnotprop merged commit 73efacf into backnotprop:main Jul 7, 2026
13 checks passed
@egouilliard-leyton
egouilliard-leyton deleted the feat/annotate-version-diff branch July 7, 2026 08:16
backnotprop added a commit that referenced this pull request Jul 10, 2026
…f failing startup

QA probe: with PLANNOTATOR_DATA_DIR on a read-only mount, `plannotator
annotate file.md` crashed before the UI opened — twice. (1) #961's
saveToHistory call on annotate open was unguarded, so the new version-diff
enhancement gated startup that was stateless at v0.22.0; now wrapped
(both the Bun server and the Pi mirror) and degrades to no-version-diff
with a stderr notice. (2) registerSession's mkdir/writeFileSync (pre-existing
since #795) threw after the server was already listening; the session
registry only powers `plannotator sessions` discovery, so it is now
best-effort, and unregisterSession/listSessions tolerate an unwritable
sessions dir too. Verified: read-only data dir now starts, serves
/api/plan with no versionInfo, and prints the session URL.

Claude-Session: https://claude.ai/code/session_01SFy9fY27SA8g5BtotWPi1G
@backnotprop

Copy link
Copy Markdown
Owner

This is now released in version 0.23.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Annotate mode: show the version diff (highlighted) for .md and .html files

3 participants