feat(annotate): per-file version diff for .md and .html (rendered HTML highlights)#961
Open
egouilliard-leyton wants to merge 4 commits into
Open
Conversation
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.
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.
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 receivedpreviousPlan/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..htmlwith--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 sameHtmlVieweriframe.How
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 existingsaveToHistorystorage.packages/server/annotate.ts+ Piapps/pi-extension/server/serverAnnotate.ts). On open, save the markdown (or raw HTML source) to history, then exposepreviousPlan/versionInfo/diffCurrenton/api/planand add/api/plan/version+/api/plan/versions. Both runtimes updated perAGENTS.md.packages/shared/html-diff.ts: a small, dependency-light, tag-awarehtmlDiff(old, new)that wraps changed text in<ins>/<del>while keeping tags balanced (<script>/<style>treated as opaque). The server sendsdiffHtml = rewriteHtml(htmlDiff(prev, current));HtmlViewerinjectsins/delhighlight CSS and shows a "Show changes" toggle;Appswaps the iframe to the diff page when toggled and suppresses the Markdown block-diff path on the HTML surface (wheremarkdownis 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 --noEmitclean forpackages/shared,packages/server,packages/ui; frontend build clean./api/planreturnsrenderAs: html+diffHtml, and/api/plan/versionslists the stored versions.Notes
🤖 Generated with Claude Code