Skip to content

Commit 410923c

Browse files
authored
Merge pull request #357 from block/hampton-history-range-diff
Compare revision ranges in History (replaces #354)
2 parents 6bfe165 + ad7e8f6 commit 410923c

33 files changed

Lines changed: 973 additions & 148 deletions

‎docs/DEMO_LIBRARY.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ look up this key rather than copying generated UUIDs.
9292
| Key | Expected initial state |
9393
| --- | --- |
9494
| untouched-document | One version, no comments or collaborators |
95-
| many-small-edits | Eight versions: initial draft plus seven small agent edits with token provenance |
95+
| many-small-edits | Eight versions: initial draft plus seven small agent edits with token provenance. In History, choose v1 in From and v8 in To. Or click v8 and Shift-click v4 to include edits v4 through v8. The version list shows lines added and removed. A fresh seed includes a version without an edit summary. |
9696
| writing-human / writing-ai / writing-unknown | Person, robot, and unknown icons; lazy source breakdown and reported harness identity |
9797
| writing-mixed | Human input, unknown imported context, and an agent proposal; opt-in source inspection |
9898
| writing-word-edit | Agent text with a human-added “not” in v2; hover for Hampton, version, and time |

‎docs/PLAN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ Plan creation is API-only (`POST /api/v1/plans`). The web UI provides index, sho
403403
|---|---------|-----------------|-------------|
404404
| 2.1 | Plan + PlanVersion models | Migrations, models, associations. Service object: `Plans::Create.call(title:, content:, user:)` creates plan + version 1. | Models + service pass tests |
405405
| 2.2 | Plans CRUD UI | Index page (org-scoped, filtered by status). New plan form (title + paste/upload markdown). Show page with current content. Status badge. | Can create and view plans in browser |
406-
| 2.3 | Version history | Version list sidebar/section on plan show page. Click to view any version. Diff view between adjacent versions using `diffy`. | Can browse full version history |
406+
| 2.3 | Version history | Click a version to see its changes or choose From and To snapshots to compare their Markdown using `diffy`. | Can browse full version history and compare revisions |
407407
| 2.4 | Status transitions + visibility | Status update controls (Author only). Enforce brainstorm privacy — 404 for non-collaborators. Collaborator model + invite flow. | Status workflow works, privacy enforced |
408408

409409
### Phase 3 — Markdown Rendering + Inline Commenting ✅

‎engine/app/assets/stylesheets/coplan/document-resources.css‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
background: var(--color-danger-soft);
181181
}
182182

183-
/* History page (the plan's time machine) */
183+
/* History page */
184184
.history-page {
185185
padding: var(--space-lg);
186186
}
@@ -198,14 +198,6 @@
198198
background: var(--color-bg-muted);
199199
}
200200

201-
.history-title-link {
202-
color: inherit;
203-
text-decoration: none;
204-
}
205-
206-
.history-title-link:hover {
207-
color: var(--color-primary);
208-
}
209201

210202
/* References section */
211203
/* Empty attachment copy hangs under the header, indented past the round "+". */

‎engine/app/assets/stylesheets/coplan/plan-header.css‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@
9595
margin-top: 1px;
9696
}
9797

98-
/* Center the back arrow (24px hit area) against the title's first line. */
99-
.page-header--plan .history-back {
100-
margin-top: 7px;
101-
}
102-
10398
.page-header__text {
10499
min-width: 0;
105100
display: flex;

‎engine/app/assets/stylesheets/coplan/plan-history.css‎

Lines changed: 191 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,25 @@
114114
word-wrap: break-word;
115115
}
116116

117-
/* Version list */
118-
/* History split view */
117+
.history-heading {
118+
display: flex;
119+
align-items: center;
120+
justify-content: flex-start;
121+
gap: var(--space-sm);
122+
margin-bottom: var(--space-sm);
123+
}
124+
125+
.history-heading h1 { margin: 0; }
126+
119127
.history-split {
120128
display: grid;
121-
grid-template-columns: 280px 1fr;
129+
grid-template-columns: 280px minmax(0, 1fr);
122130
gap: 0;
123131
min-height: 400px;
124132
}
125133

126134
.history-split__list {
135+
position: relative;
127136
border-right: 1px solid var(--color-border);
128137
overflow-y: auto;
129138
max-height: 70vh;
@@ -139,19 +148,55 @@
139148
transition: background 0.1s;
140149
}
141150

142-
.history-split__item:hover {
143-
background: var(--color-bg-muted);
151+
.history-split__item[data-revision] {
152+
border-inline-start: 3px solid transparent;
153+
padding: 0;
154+
}
155+
156+
.history-split__entry {
157+
display: block;
158+
min-width: 0;
159+
padding: var(--space-sm) var(--space-md) var(--space-sm) calc(var(--space-md) - 3px);
160+
color: inherit;
144161
text-decoration: none;
145162
}
146163

147-
.history-split__item--active {
164+
.history-split__entry:hover { text-decoration: none; }
165+
166+
.history-split__entry:focus-visible {
167+
outline: 2px solid var(--color-primary);
168+
outline-offset: -2px;
169+
}
170+
171+
.history-split__item[data-revision]:hover {
148172
background: var(--color-primary-light);
149-
border-left: 3px solid var(--color-primary);
150-
padding-left: calc(var(--space-md) - 3px);
151173
}
152174

153-
.history-split__item--active:hover {
175+
.history-split__item.history-split__item--active {
154176
background: var(--color-primary-light);
177+
border-inline-start-color: var(--color-primary);
178+
}
179+
180+
.history-split__entry-heading {
181+
display: flex;
182+
align-items: baseline;
183+
justify-content: space-between;
184+
gap: var(--space-xs);
185+
}
186+
187+
.history-split__stats {
188+
display: inline-flex;
189+
gap: var(--space-xs);
190+
font-size: var(--text-sm);
191+
font-variant-numeric: tabular-nums;
192+
}
193+
194+
.history-split__added {
195+
color: var(--color-diff-ins-text);
196+
}
197+
198+
.history-split__removed {
199+
color: var(--color-diff-del-text);
155200
}
156201

157202
.history-split__version {
@@ -210,16 +255,134 @@
210255
}
211256

212257
.history-split__detail {
213-
padding: var(--space-md) var(--space-lg);
214-
overflow-y: auto;
215-
max-height: 70vh;
258+
padding: 0 var(--space-lg) var(--space-md);
259+
}
260+
261+
.history-comparison {
262+
display: flex;
263+
align-items: end;
264+
justify-content: space-between;
265+
flex-wrap: wrap;
266+
gap: var(--space-sm);
267+
padding-bottom: var(--space-sm);
268+
margin-bottom: var(--space-sm);
269+
border-bottom: 1px solid var(--color-border);
270+
}
271+
272+
.history-comparison__range {
273+
display: flex;
274+
align-items: end;
275+
gap: var(--space-xs);
276+
}
277+
278+
.history-comparison__endpoint {
279+
display: grid;
280+
gap: 3px;
281+
font-size: var(--text-sm);
282+
color: var(--color-text-muted);
283+
}
284+
285+
.history-comparison__select {
286+
field-sizing: content;
287+
min-width: 4rem;
288+
min-height: 2.25rem;
289+
padding-inline: var(--space-xs);
290+
border: 1px solid var(--color-border-strong);
291+
border-radius: var(--radius);
292+
color: var(--color-text);
293+
background: var(--color-input-bg);
294+
font: inherit;
295+
font-weight: 650;
296+
cursor: pointer;
297+
}
298+
299+
.history-comparison__select:hover {
300+
border-color: var(--color-primary);
301+
}
302+
303+
.history-comparison__select:focus-visible {
304+
outline: 2px solid var(--color-primary);
305+
outline-offset: 2px;
216306
}
217307

218-
.history-split__placeholder {
308+
.history-comparison__arrow {
309+
display: grid;
310+
min-height: 2.25rem;
311+
place-items: center;
312+
color: var(--color-text-muted);
313+
}
314+
315+
.history-comparison__feedback {
219316
display: flex;
220317
align-items: center;
221-
justify-content: center;
222-
height: 200px;
318+
flex-wrap: wrap;
319+
gap: var(--space-xs);
320+
min-height: 2.25rem;
321+
}
322+
323+
.history-split__detail .version-diff-preview__standalone {
324+
display: none;
325+
}
326+
327+
.history-split__detail .diff-view,
328+
.history-split__detail .diff-view ul {
329+
margin-top: 0;
330+
}
331+
332+
.history-split__detail #version-diff[aria-busy="true"] {
333+
visibility: hidden;
334+
}
335+
336+
.history-split__diff:focus-visible {
337+
outline: 2px solid var(--color-primary);
338+
outline-offset: -2px;
339+
}
340+
341+
@media (min-width: 721px) and (min-height: 400px) {
342+
body:has(> .main-content > .history-screen) {
343+
height: 100dvh;
344+
min-height: 0;
345+
}
346+
347+
.main-content:has(> .history-screen) {
348+
display: flex;
349+
flex-direction: column;
350+
min-height: 0;
351+
}
352+
353+
.history-screen {
354+
display: grid;
355+
flex: 1;
356+
min-height: 0;
357+
grid-template-rows: auto minmax(0, 1fr);
358+
}
359+
360+
.history-screen .history-page,
361+
#plan-history {
362+
display: grid;
363+
grid-template-rows: minmax(0, 1fr);
364+
min-height: 0;
365+
}
366+
367+
.history-split {
368+
grid-template-rows: minmax(0, 1fr);
369+
min-height: 0;
370+
}
371+
372+
.history-split__detail {
373+
display: grid;
374+
grid-template-rows: auto minmax(0, 1fr);
375+
min-height: 0;
376+
padding-bottom: 0;
377+
}
378+
379+
.history-split__list,
380+
.history-split__diff {
381+
max-height: none;
382+
overflow-y: auto;
383+
overscroll-behavior-y: contain;
384+
scrollbar-gutter: stable;
385+
}
223386
}
224387

225388
/* On narrow screens the side-by-side split would crush the diff to a
@@ -238,19 +401,28 @@
238401

239402
.history-split__detail {
240403
padding: var(--space-md);
241-
max-height: none;
242404
}
243405
}
244406

245407
/* Version diff preview */
246408
.version-diff-preview__header {
247409
display: flex;
248-
align-items: baseline;
249-
gap: var(--space-md);
250-
margin-bottom: var(--space-md);
410+
align-items: center;
411+
gap: var(--space-xs) var(--space-md);
412+
margin-bottom: var(--space-sm);
251413
flex-wrap: wrap;
252414
}
253415

416+
.version-diff-preview__byline {
417+
display: inline-flex;
418+
align-items: center;
419+
gap: var(--space-xs);
420+
}
421+
422+
.version-diff-preview__summary {
423+
overflow-wrap: anywhere;
424+
}
425+
254426
.version-diff-preview__header h3 {
255427
font-size: var(--text-xl);
256428
font-weight: 700;

‎engine/app/controllers/coplan/plans_controller.rb‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ def comments_body
179179
# <document>/history; the actions below are the pages under it.
180180
def history
181181
authorize!(@plan, :show?)
182+
load_version(revision: params[:to].presence || @plan.current_revision)
182183
@history_items = @plan.history_items
183184
end
184185

@@ -793,12 +794,17 @@ def set_plan
793794
# The revision number in the URL, not a version id — see
794795
# BrowseController's routes. A revision nobody wrote is a 404, the same
795796
# as any other address that names nothing.
796-
def load_version
797-
@version = @plan.plan_versions.find_by!(revision: params[:revision])
798-
@previous_version = @plan.plan_versions.find_by(revision: @version.revision - 1)
799-
return if @previous_version.nil?
797+
def load_version(revision: params[:revision])
798+
first = params[:from].presence || revision
799+
unless [ first, revision ].all? { |value| value.to_s.match?(/\A[1-9]\d*\z/) } && first.to_i <= revision.to_i
800+
raise ActiveRecord::RecordNotFound
801+
end
802+
803+
@version = @plan.plan_versions.find_by!(revision: revision)
804+
@first_version = @plan.plan_versions.find_by!(revision: first)
805+
@previous_version = @plan.plan_versions.find_by!(revision: @first_version.revision - 1) if @first_version.revision > 1
800806

801-
@diff = Diffy::Diff.new(@previous_version.content_markdown, @version.content_markdown,
807+
@diff = Diffy::Diff.new(@previous_version&.content_markdown.to_s, @version.content_markdown,
802808
include_plus_and_minus_in_html: true, context: 3)
803809
end
804810

0 commit comments

Comments
 (0)