@in-the-loop-labs/pair-review 5.3.7 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +8 -0
  2. package/package.json +3 -3
  3. package/plugin/.claude-plugin/plugin.json +1 -1
  4. package/plugin-code-critic/.claude-plugin/plugin.json +1 -1
  5. package/plugin-pair-loop/.claude-plugin/plugin.json +1 -1
  6. package/public/css/pr.css +389 -13
  7. package/public/js/components/AIPanel.js +317 -99
  8. package/public/js/components/ReviewHistoryModal.js +294 -0
  9. package/public/js/components/ReviewModal.js +96 -7
  10. package/public/js/components/SplitButton.js +14 -0
  11. package/public/js/local.js +4 -8
  12. package/public/js/modules/comment-manager.js +2 -1
  13. package/public/js/modules/file-comment-manager.js +6 -2
  14. package/public/js/modules/pierre-bridge.js +35 -1
  15. package/public/js/modules/suggestion-manager.js +4 -1
  16. package/public/js/pr.js +174 -66
  17. package/public/js/utils/posted-comment.js +259 -14
  18. package/public/js/vendor/pierre-diffs-worker.js +41 -13485
  19. package/public/js/vendor/pierre-diffs.js +131 -1364
  20. package/public/pr.html +1 -0
  21. package/src/chat/api-reference.js +22 -2
  22. package/src/config.js +28 -4
  23. package/src/database.js +177 -56
  24. package/src/github/client.js +70 -15
  25. package/src/github/impl/graphql/pending-review-comments.js +50 -11
  26. package/src/github/impl/graphql/pending-review.js +8 -2
  27. package/src/github/impl/graphql/review-comment-edit.js +89 -0
  28. package/src/github/impl/host/pending-review-comments.js +41 -10
  29. package/src/github/impl/host/review-comment-edit.js +36 -0
  30. package/src/github/impl/rest/pending-review.js +6 -2
  31. package/src/github/impl/rest/review-comment-edit.js +44 -0
  32. package/src/github/impl/review-comment-edit-utils.js +45 -0
  33. package/src/github/operations/pending-review.js +4 -3
  34. package/src/github/operations/review-comment-edit.js +35 -0
  35. package/src/github/record-submission.js +78 -0
  36. package/src/github/update-posted-comment.js +115 -0
  37. package/src/main.js +24 -44
  38. package/src/routes/mcp.js +1 -0
  39. package/src/routes/pr.js +147 -106
@@ -0,0 +1,294 @@
1
+ // Copyright 2026 Tim Perkins (tjwp) | SPDX-License-Identifier: Apache-2.0
2
+ /**
3
+ * Review History Modal
4
+ *
5
+ * Lists this review's submissions to the code host, newest first. Opening a
6
+ * submission shows its full summary and the comments it carried as sent;
7
+ * Back returns to the list. In-place edits of a posted comment appear under
8
+ * the submission that first posted it, marked "edited".
9
+ * Clicking a comment jumps to it in the diff. PR mode only.
10
+ */
11
+ class ReviewHistoryModal {
12
+ constructor({ fetchImpl } = {}) {
13
+ this.modal = null;
14
+ this.isVisible = false;
15
+ this.fetchImpl = fetchImpl || ((...args) => fetch(...args));
16
+ this._loadGen = 0;
17
+ this.submissions = [];
18
+ this.selectedIndex = null;
19
+ this.handleKeydown = this.handleKeydown.bind(this);
20
+ this.createModal();
21
+ }
22
+
23
+ createModal() {
24
+ document.getElementById('review-history-modal')?.remove();
25
+ const container = document.createElement('div');
26
+ container.id = 'review-history-modal';
27
+ container.className = 'modal-overlay review-history-modal-overlay';
28
+ container.style.display = 'none';
29
+ container.setAttribute('role', 'dialog');
30
+ container.setAttribute('aria-modal', 'true');
31
+ container.setAttribute('aria-labelledby', 'review-history-title');
32
+ container.innerHTML = `
33
+ <div class="modal-backdrop" data-history-close></div>
34
+ <div class="modal-container review-history-modal-container">
35
+ <div class="modal-header">
36
+ <button class="review-history-back" type="button" data-history-back hidden>← Back</button>
37
+ <h3 id="review-history-title">Review history</h3>
38
+ <button class="modal-close-btn" type="button" data-history-close title="Close" aria-label="Close">
39
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true">
40
+ <path d="M3.72 3.72a.75.75 0 011.06 0L8 6.94l3.22-3.22a.75.75 0 111.06 1.06L9.06 8l3.22 3.22a.75.75 0 11-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 01-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 010-1.06z"/>
41
+ </svg>
42
+ </button>
43
+ </div>
44
+ <div class="modal-body review-history-body"></div>
45
+ </div>
46
+ `;
47
+ container.addEventListener('click', (e) => {
48
+ if (e.target.closest('[data-history-close]')) {
49
+ this.hide();
50
+ return;
51
+ }
52
+ if (e.target.closest('[data-history-back]')) {
53
+ this.showList();
54
+ return;
55
+ }
56
+ const row = e.target.closest('[data-submission-index]');
57
+ if (row) {
58
+ this.showSubmission(Number(row.dataset.submissionIndex));
59
+ return;
60
+ }
61
+ const item = e.target.closest('.review-history-comment[data-jump-comment-id]');
62
+ // Links inside a comment open the host, not the diff
63
+ if (item && !e.target.closest('a')) this.jumpToComment(item);
64
+ });
65
+ container.addEventListener('keydown', (e) => {
66
+ const item = e.target.closest?.('.review-history-comment[data-jump-comment-id]');
67
+ if (item && (e.key === 'Enter' || e.key === ' ') && e.target === item) {
68
+ e.preventDefault();
69
+ this.jumpToComment(item);
70
+ }
71
+ });
72
+ document.body.appendChild(container);
73
+ this.modal = container;
74
+ this.body = container.querySelector('.review-history-body');
75
+ }
76
+
77
+ handleKeydown(e) {
78
+ if (!this.isVisible || window.confirmDialog?.isVisible) return;
79
+ if (e.key === 'Escape') {
80
+ e.preventDefault();
81
+ e.stopPropagation();
82
+ if (this.selectedIndex !== null) this.showList();
83
+ else this.hide();
84
+ } else if (e.key === 'Tab') {
85
+ const controls = [...this.modal.querySelectorAll('button:not([hidden]), a[href], [tabindex="0"]')];
86
+ const first = controls[0];
87
+ const last = controls[controls.length - 1];
88
+ if (e.shiftKey && document.activeElement === first) {
89
+ e.preventDefault();
90
+ last?.focus();
91
+ } else if (!e.shiftKey && document.activeElement === last) {
92
+ e.preventDefault();
93
+ first?.focus();
94
+ }
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Show the modal and load the review's submissions.
100
+ * @param {number|string} reviewId
101
+ */
102
+ async show(reviewId) {
103
+ if (!this.modal) this.createModal();
104
+ if (!this.isVisible) this.opener = document.activeElement;
105
+ this.selectedIndex = null;
106
+ this.modal.querySelector('[data-history-back]').hidden = true;
107
+ this.modal.querySelector('#review-history-title').textContent = 'Review history';
108
+ this.modal.style.display = 'flex';
109
+ this.isVisible = true;
110
+ // Capture before ChatPanel's document listener so history owns its Escape ladder.
111
+ document.addEventListener('keydown', this.handleKeydown, true);
112
+ this.modal.querySelector('.modal-close-btn').focus();
113
+ await this.load(reviewId);
114
+ }
115
+
116
+ hide() {
117
+ if (!this.modal) return;
118
+ this.modal.style.display = 'none';
119
+ this.isVisible = false;
120
+ ++this._loadGen;
121
+ document.removeEventListener('keydown', this.handleKeydown, true);
122
+ // The split-menu item that opened us is hidden when its dropdown closes.
123
+ const opener = this.opener?.getClientRects().length
124
+ ? this.opener : document.getElementById('split-button-dropdown-toggle');
125
+ opener?.focus();
126
+ }
127
+
128
+ async load(reviewId) {
129
+ const gen = ++this._loadGen;
130
+ this.body.innerHTML = '<div class="review-history-loading">Loading review history...</div>';
131
+ try {
132
+ const response = await this.fetchImpl(`/api/reviews/${reviewId}/submissions`);
133
+ const data = await response.json().catch(() => ({}));
134
+ if (!response.ok) throw new Error(data.error || 'Failed to load review history');
135
+ if (gen !== this._loadGen) return;
136
+ this.render(data.submissions || []);
137
+ } catch (error) {
138
+ if (gen !== this._loadGen) return;
139
+ this.body.innerHTML = `<div class="review-history-error" role="alert">${ReviewHistoryModal.escapeHtml(error.message)}</div>`;
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Render the submissions (newest first, as the server orders them).
145
+ * @param {Array<Object>} submissions
146
+ */
147
+ render(submissions) {
148
+ this.submissions = submissions;
149
+ this.showList(0);
150
+ }
151
+
152
+ showList(focusIndex = this.selectedIndex ?? 0) {
153
+ this.selectedIndex = null;
154
+ this.modal.querySelector('[data-history-back]').hidden = true;
155
+ this.modal.querySelector('#review-history-title').textContent = 'Review history';
156
+ if (!this.submissions.length) {
157
+ this.body.innerHTML = `<div class="review-history-empty">Nothing from this review has been posted to ${ReviewHistoryModal.escapeHtml(ReviewHistoryModal.hostName())} yet.</div>`;
158
+ return;
159
+ }
160
+ this.body.innerHTML = `<ol class="review-history-list">${this.submissions.map((s, i) => this.renderSubmissionRow(s, i)).join('')}</ol>`;
161
+ this.body.querySelector(`[data-submission-index="${focusIndex}"]`)?.focus();
162
+ }
163
+
164
+ showSubmission(index) {
165
+ const submission = this.submissions[index];
166
+ if (!submission) return;
167
+ this.selectedIndex = index;
168
+ const back = this.modal.querySelector('[data-history-back]');
169
+ back.hidden = false;
170
+ this.modal.querySelector('#review-history-title').textContent = 'Review submission';
171
+ this.body.innerHTML = this.renderSubmission(submission);
172
+ this.body.scrollTop = 0;
173
+ back.focus();
174
+ }
175
+
176
+ renderSubmissionRow(submission, index) {
177
+ const PC = window.PostedComment;
178
+ const esc = ReviewHistoryModal.escapeHtml;
179
+ const chip = PC.submissionEventChip(submission);
180
+ const when = ReviewHistoryModal.formatTimestamp(PC.submissionTimestamp(submission));
181
+ const url = PC.safeUrl(submission.github_url);
182
+ const summary = ReviewHistoryModal.summaryLine(submission.body);
183
+ const counts = ReviewHistoryModal.postingCounts(submission.postings);
184
+ // The link is a sibling of the full-width row button, never nested in it.
185
+ return `<li class="review-history-submission review-history-row" data-submission-state="${esc(submission.state || '')}">
186
+ <button type="button" class="review-history-row-button" data-submission-index="${index}">
187
+ <span class="review-history-submission-header">
188
+ <span class="review-history-chip review-history-chip-${esc(chip.tone)}">${esc(chip.label)}</span>
189
+ ${when ? `<time class="review-history-time" datetime="${esc(when.iso)}">${esc(when.text)}</time>` : ''}
190
+ </span>
191
+ <span class="review-history-counts">${counts.comments} ${counts.comments === 1 ? 'comment' : 'comments'} · ${counts.edits} ${counts.edits === 1 ? 'edit' : 'edits'}</span>
192
+ ${summary ? `<span class="review-history-summary-preview">${esc(summary)}</span>` : ''}
193
+ </button>
194
+ ${url ? `<a class="review-history-link" href="${esc(url)}" target="_blank" rel="noopener">View on ${esc(ReviewHistoryModal.hostName())}</a>` : ''}
195
+ </li>`;
196
+ }
197
+
198
+ renderSubmission(submission) {
199
+ const PC = window.PostedComment;
200
+ const esc = ReviewHistoryModal.escapeHtml;
201
+ const chip = PC.submissionEventChip(submission);
202
+ const when = ReviewHistoryModal.formatTimestamp(PC.submissionTimestamp(submission));
203
+ const url = PC.safeUrl(submission.github_url);
204
+ const body = submission.body
205
+ ? `<div class="review-history-summary">${ReviewHistoryModal.renderMarkdown(submission.body)}</div>` : '';
206
+ const postings = submission.postings || [];
207
+ const comments = postings.length
208
+ ? `<ul class="review-history-comments">${postings.map(p => this.renderPostedComment(p)).join('')}</ul>`
209
+ : '<div class="review-history-no-comments">No comments</div>';
210
+ return `<section class="review-history-submission" data-submission-state="${esc(submission.state || '')}">
211
+ <div class="review-history-submission-header">
212
+ <span class="review-history-chip review-history-chip-${esc(chip.tone)}">${esc(chip.label)}</span>
213
+ ${when ? `<time class="review-history-time" datetime="${esc(when.iso)}">${esc(when.text)}</time>` : ''}
214
+ ${url ? `<a class="review-history-link" href="${esc(url)}" target="_blank" rel="noopener">View on ${esc(ReviewHistoryModal.hostName())}</a>` : ''}
215
+ </div>
216
+ ${body}
217
+ ${comments}
218
+ </section>`;
219
+ }
220
+
221
+ /** Render one posted snapshot, shared by every history presentation. */
222
+ renderPostedComment(posting) {
223
+ const PC = window.PostedComment;
224
+ const esc = ReviewHistoryModal.escapeHtml;
225
+ const edited = PC.isEditPosting(posting);
226
+ const dismissed = (posting.comment_status || posting.status) === 'inactive';
227
+ const url = PC.safeUrl(posting.github_comment_url);
228
+ const when = ReviewHistoryModal.formatTimestamp(posting.posted_at);
229
+ // Dismissed comments are not rendered in the diff, so there is nothing to jump to
230
+ const jump = !dismissed && posting.comment_id != null;
231
+ const jumpAttrs = jump
232
+ ? ` data-jump-comment-id="${esc(posting.comment_id)}" data-file="${esc(posting.file || '')}" data-line="${esc(posting.line_start ?? '')}" data-side="${esc(posting.side || '')}" tabindex="0" role="button" title="Show in diff"`
233
+ : '';
234
+ return `<li class="review-history-comment${edited ? ' review-history-comment-edited' : ''}" data-posting-kind="${esc(posting.kind || 'post')}"${jumpAttrs}>
235
+ <div class="review-history-comment-header">
236
+ <span class="review-history-comment-file">${esc(posting.file || '')}</span>
237
+ <span class="review-history-comment-line">${esc(PC.postingLocation(posting))}</span>
238
+ ${edited ? '<span class="review-history-chip review-history-chip-edited">edited</span>' : ''}
239
+ ${posting.backfilled && !edited ? '<span class="review-history-chip" title="Legacy snapshot and review association may be approximate">approximate</span>' : ''}
240
+ ${dismissed ? '<span class="review-history-chip review-history-chip-dismissed">dismissed</span>' : ''}
241
+ ${when ? `<time class="review-history-time" datetime="${esc(when.iso)}">${esc(when.text)}</time>` : ''}
242
+ ${url ? `<a class="review-history-link" href="${esc(url)}" target="_blank" rel="noopener">View</a>` : ''}
243
+ </div>
244
+ <div class="review-history-comment-body user-comment-body">${ReviewHistoryModal.renderMarkdown(posting.body || '')}</div>
245
+ </li>`;
246
+ }
247
+
248
+ /** Close the modal and scroll to the comment, as the comment panel does. */
249
+ jumpToComment(item) {
250
+ const { jumpCommentId, file, line, side } = item.dataset;
251
+ this.hide();
252
+ window.aiPanel?.scrollToComment?.(jumpCommentId, file || undefined, line || undefined, side || undefined);
253
+ }
254
+
255
+ static summaryLine(body) {
256
+ return String(body ?? '').trim().split(/\r?\n/, 1)[0]
257
+ .replace(/^(?:#{1,6}\s+|(?:[-+*]|\d+[.)])\s+)/, '')
258
+ .replace(/(?<!\w)(\*\*|__|~~|`|\*|_)(.+?)\1(?!\w)/g, '$2');
259
+ }
260
+
261
+ static postingCounts(postings) {
262
+ const counts = { comments: 0, edits: 0 };
263
+ for (const posting of postings || []) {
264
+ if (posting.kind === 'update') counts.edits++;
265
+ else counts.comments++;
266
+ }
267
+ return counts;
268
+ }
269
+
270
+ static formatTimestamp(timestamp) {
271
+ if (!timestamp) return null;
272
+ // SQLite timestamps carry no zone but are UTC (see utils/time.js)
273
+ const date = (typeof window !== 'undefined' && window.parseTimestamp)
274
+ ? window.parseTimestamp(timestamp)
275
+ : new Date(/Z$|[+-]\d{2}:\d{2}$/.test(timestamp) ? timestamp : `${timestamp.replace(' ', 'T')}Z`);
276
+ if (Number.isNaN(date.getTime())) return null;
277
+ return { iso: date.toISOString(), text: date.toLocaleString() };
278
+ }
279
+
280
+ static renderMarkdown(text) {
281
+ return window.renderMarkdown ? window.renderMarkdown(text) : ReviewHistoryModal.escapeHtml(text);
282
+ }
283
+
284
+ static hostName() {
285
+ return window.PostedComment?.hostName() || 'GitHub';
286
+ }
287
+
288
+ static escapeHtml(value) {
289
+ return String(value ?? '').replace(/[&"<>']/g, ch => ({ '&': '&amp;', '"': '&quot;', '<': '&lt;', '>': '&gt;', "'": '&#39;' }[ch]));
290
+ }
291
+ }
292
+
293
+ if (typeof window !== 'undefined') window.ReviewHistoryModal = ReviewHistoryModal;
294
+ if (typeof module !== 'undefined' && module.exports) module.exports = ReviewHistoryModal;
@@ -89,6 +89,15 @@ class ReviewModal {
89
89
  </label>
90
90
  </div>
91
91
 
92
+ <div class="review-comment-summary">
93
+ <div class="review-comment-count"></div>
94
+ </div>
95
+ <label class="remember-toggle update-edited-comments-option" hidden>
96
+ <input type="checkbox" id="update-edited-comments" checked>
97
+ <span class="toggle-switch"></span>
98
+ <span class="toggle-label update-edited-comments-text"></span>
99
+ </label>
100
+
92
101
  <div class="review-type-section">
93
102
  <label class="review-label">Review Type</label>
94
103
  <div class="review-type-options">
@@ -126,12 +135,11 @@ class ReviewModal {
126
135
  </div>
127
136
  </div>
128
137
 
129
- <div class="review-comment-summary">
130
- <div class="review-comment-count"></div>
131
- </div>
132
- <label class="hide-posted-comments-option">
138
+ <label class="remember-toggle hide-posted-comments-option">
133
139
  <input type="checkbox" id="hide-posted-comments">
134
- Hide comments after posting
140
+ <span class="toggle-switch"></span>
141
+ <span class="toggle-label">Hide comments after posting</span>
142
+ <span class="hide-posted-override-hint" hidden>(set for this review in the comment filter; changing it here applies to all reviews)</span>
135
143
  </label>
136
144
 
137
145
  <!-- Warning dialog for large reviews -->
@@ -257,7 +265,14 @@ class ReviewModal {
257
265
  // Update comment count
258
266
  this.updateCommentCount();
259
267
  const hidePosted = this.modal.querySelector('#hide-posted-comments');
260
- if (hidePosted) hidePosted.checked = window.PostedComment?.isHidePostedEnabled() || false;
268
+ // Show what applies to this review: its "Show posted" override, if any,
269
+ // else the browser-wide setting. Toggling writes the browser-wide setting
270
+ // and clears the override (handleHidePostedToggle), so the box always
271
+ // matches what happens.
272
+ if (hidePosted) hidePosted.checked = window.PostedComment?.isHidePostedInEffect() || false;
273
+ this.updateHidePostedOverrideHint();
274
+ const updateEdited = this.modal.querySelector('#update-edited-comments');
275
+ if (updateEdited) updateEdited.checked = true;
261
276
 
262
277
  // Reset form
263
278
  const textarea = this.modal.querySelector('#review-body-modal');
@@ -413,11 +428,67 @@ class ReviewModal {
413
428
 
414
429
  // Update large review warning
415
430
  this.updateLargeReviewWarning(userComments);
431
+ this.updateEditedCommentsOption();
432
+ }
433
+
434
+ /**
435
+ * Posted comments edited since they were posted. They are updated in place
436
+ * on the host after the submit, never posted again, so they are not part
437
+ * of the "will be submitted" count.
438
+ * @returns {Array<Object>}
439
+ */
440
+ getEditedPostedComments() {
441
+ return window.PostedComment?.getUpdatableComments(window.prManager?.userComments) || [];
442
+ }
443
+
444
+ /** Show "Also update N edited comments on GitHub" when there are any. */
445
+ updateEditedCommentsOption() {
446
+ const option = this.modal?.querySelector('.update-edited-comments-option');
447
+ if (!option) return;
448
+ const count = this.getEditedPostedComments().length;
449
+ option.hidden = count === 0;
450
+ const text = option.querySelector('.update-edited-comments-text');
451
+ if (text) {
452
+ text.textContent = `Also update ${count} edited ${count === 1 ? 'comment' : 'comments'} on ${ReviewModal.hostName()}`;
453
+ }
454
+ }
455
+
456
+ /**
457
+ * Update edited posted comments on the host, one at a time, after the
458
+ * review was submitted. Each goes through the same in-place update as the
459
+ * comment's own "Update on GitHub" action; none is ever re-posted.
460
+ * @param {Array<number>} commentIds
461
+ * @returns {Promise<{updated: number, failed: Array<{id: number, error: Object}>}>}
462
+ */
463
+ async updateEditedComments(commentIds) {
464
+ const failed = [];
465
+ let updated = 0;
466
+ const submitBtn = this.modal?.querySelector('#submit-review-btn-modal');
467
+ for (const [index, id] of commentIds.entries()) {
468
+ if (submitBtn) {
469
+ submitBtn.innerHTML = `<div class="loading-spinner-small"></div> Updating edited comments (${index + 1}/${commentIds.length})...`;
470
+ }
471
+ const result = await window.prManager?.updatePostedCommentOnHost?.(id)
472
+ || { ok: false, error: { message: 'Comment updates are unavailable' } };
473
+ if (result.ok) updated++;
474
+ else failed.push({ id, error: result.error });
475
+ }
476
+ return { updated, failed };
477
+ }
478
+
479
+ /** Show the override hint while this review has its own "Show posted" setting. */
480
+ updateHidePostedOverrideHint() {
481
+ const hint = this.modal?.querySelector('.hide-posted-override-hint');
482
+ if (hint) hint.hidden = (window.PostedComment?.getShowPostedOverride() ?? null) === null;
416
483
  }
417
484
 
418
485
  handleHidePostedToggle() {
419
486
  const checked = this.modal.querySelector('#hide-posted-comments').checked;
420
487
  window.PostedComment.setHidePostedEnabled(checked);
488
+ // The reviewer just chose the browser-wide setting, so this review
489
+ // follows it again instead of its own "Show posted" override.
490
+ window.aiPanel?.clearShowPostedOverride?.();
491
+ this.updateHidePostedOverrideHint();
421
492
  try {
422
493
  window.prManager?.applyPostedCommentVisibility();
423
494
  } catch (error) {
@@ -505,6 +576,10 @@ class ReviewModal {
505
576
  const commentCount = window.prManager?.getPendingCommentCount?.() || 0;
506
577
  // Comments saved to the pending draft are published with this review too
507
578
  const submittableCount = window.prManager?.getSubmittableCommentCount?.() || 0;
579
+ // Decided now: comments edited after this point are not part of this submit
580
+ const updateEditedBox = this.modal.querySelector('#update-edited-comments');
581
+ const editedIds = updateEditedBox?.checked && !updateEditedBox.closest('label')?.hidden
582
+ ? this.getEditedPostedComments().map(c => c.id) : [];
508
583
 
509
584
  // Hide any previous errors
510
585
  this.hideError();
@@ -557,6 +632,11 @@ class ReviewModal {
557
632
  }
558
633
 
559
634
  const result = await response.json();
635
+
636
+ // The review is on the host now; edits to posted comments follow it
637
+ const editedUpdates = editedIds.length > 0
638
+ ? await this.updateEditedComments(editedIds)
639
+ : { updated: 0, failed: [] };
560
640
 
561
641
  // Show appropriate success message
562
642
  if (window.toast) {
@@ -580,6 +660,15 @@ class ReviewModal {
580
660
  }
581
661
  }
582
662
 
663
+ if (editedUpdates.failed.length > 0) {
664
+ const count = editedUpdates.failed.length;
665
+ const first = editedUpdates.failed[0].error?.message || 'Update failed';
666
+ window.toast?.showWarning(
667
+ `Review submitted, but ${count} edited ${count === 1 ? 'comment' : 'comments'} could not be updated on ${ReviewModal.escapeHtml(ReviewModal.hostName())}: ${ReviewModal.escapeHtml(first)}`,
668
+ 8000
669
+ );
670
+ }
671
+
583
672
  // Clear submitting state before hiding modal
584
673
  this.setSubmittingState(false);
585
674
 
@@ -603,7 +692,7 @@ class ReviewModal {
603
692
  // loadUserComments catches its own errors and resolves false when the
604
693
  // reload failed. It resolves undefined when no PR is loaded, which is
605
694
  // not a failure, so compare with false rather than testing !refreshed.
606
- const refreshed = await window.prManager?.loadUserComments(window.aiPanel?.showDismissedComments || false);
695
+ const refreshed = await window.prManager?.loadUserComments();
607
696
  if (refreshed === false) {
608
697
  console.error('Review posted, but comment refresh failed');
609
698
  window.toast?.showWarning('Review posted, but comments could not be refreshed. Please reload the page.');
@@ -28,6 +28,8 @@ class SplitButton {
28
28
  this.onPreview = options.onPreview || (() => {});
29
29
  this.onClear = options.onClear || (() => {});
30
30
  this.onShare = options.onShare || (() => {});
31
+ // Review history lists what was posted to the host: PR mode only
32
+ this.onHistory = options.onHistory || null;
31
33
  this.onSetDefault = options.onSetDefault || (() => {});
32
34
  this.shareUrl = options.shareUrl || null;
33
35
  // Custom icon SVG, label, and description for share menu item
@@ -130,6 +132,15 @@ class SplitButton {
130
132
  <span class="menu-item-text">Preview</span>
131
133
  </button>`;
132
134
 
135
+ if (!this.hideSubmit && this.onHistory) {
136
+ menuItems += `
137
+ <div class="split-button-menu-separator"></div>
138
+ <button class="split-button-menu-item" data-action="history" role="menuitem">
139
+ <span class="menu-item-check"></span>
140
+ <span class="menu-item-text">Review history</span>
141
+ </button>`;
142
+ }
143
+
133
144
  if (this.shareUrl) {
134
145
  // Icon renders on the right side of the label (unlike checkmarks which are on the left)
135
146
  const iconHtml = this.shareIcon
@@ -207,6 +218,9 @@ class SplitButton {
207
218
  case 'share':
208
219
  this.onShare();
209
220
  break;
221
+ case 'history':
222
+ this.onHistory?.();
223
+ break;
210
224
  case 'clear':
211
225
  this.onClear();
212
226
  break;
@@ -539,8 +539,7 @@ class LocalManager {
539
539
  await self.loadLocalDiff();
540
540
 
541
541
  // Re-anchor comments and suggestions on the fresh DOM
542
- const includeDismissed = window.aiPanel?.showDismissedComments || false;
543
- await manager.loadUserComments(includeDismissed);
542
+ await manager.loadUserComments();
544
543
  await manager.loadAISuggestions(null, manager.selectedRunId);
545
544
 
546
545
  // Restore scroll position after the DOM settles
@@ -941,8 +940,7 @@ class LocalManager {
941
940
 
942
941
  // Re-render comments and AI suggestions on the fresh DOM
943
942
  // (renderDiff clears the diff container, so we must re-populate)
944
- const includeDismissed = window.aiPanel?.showDismissedComments || false;
945
- await manager.loadUserComments(includeDismissed);
943
+ await manager.loadUserComments();
946
944
  // Note: Unlike loadLocalReview() which skips this when analysisHistoryManager exists
947
945
  // (because the manager triggers loadAISuggestions via onSelectionChange on init),
948
946
  // refresh must call unconditionally since the manager won't re-fire its callback.
@@ -1157,8 +1155,7 @@ class LocalManager {
1157
1155
  window.panelGroup?.setPR(`local/${reviewData.repository}#${this.reviewId}`);
1158
1156
 
1159
1157
  // Load saved comments using the restored filter state from AI Panel
1160
- const includeDismissed = window.aiPanel?.showDismissedComments || false;
1161
- await manager.loadUserComments(includeDismissed);
1158
+ await manager.loadUserComments();
1162
1159
 
1163
1160
  // Initialize analysis history manager for local mode
1164
1161
  if (window.AnalysisHistoryManager) {
@@ -1691,8 +1688,7 @@ class LocalManager {
1691
1688
  await this.loadLocalDiff();
1692
1689
 
1693
1690
  // Re-anchor comments and suggestions
1694
- const includeDismissed = window.aiPanel?.showDismissedComments || false;
1695
- await manager.loadUserComments(includeDismissed);
1691
+ await manager.loadUserComments();
1696
1692
  await manager.loadAISuggestions(null, manager.selectedRunId);
1697
1693
 
1698
1694
  // Only update dropdown if user hasn't clicked again since this request started
@@ -606,7 +606,7 @@ class CommentManager {
606
606
  ${commentIcon}
607
607
  </span>
608
608
  <span class="user-comment-line-info">${lineInfo}</span>
609
- ${window.getPostedCommentIcon?.(comment) || ''}
609
+ ${window.getPostedCommentIcon?.(comment, { link: true }) || ''}
610
610
  ${expandedContextIndicator}
611
611
  ${metadataHTML}
612
612
  </div>
@@ -627,6 +627,7 @@ class CommentManager {
627
627
  </div>
628
628
  </div>
629
629
  <div class="user-comment-body" data-original-markdown="${window.escapeHtmlAttribute(comment.body)}">${window.renderMarkdown ? window.renderMarkdown(comment.body) : escapeHtml(comment.body)}</div>
630
+ ${window.PostedComment?.getEditedSincePostedHtml(comment) || ''}
630
631
  </div>
631
632
  `;
632
633
 
@@ -378,7 +378,7 @@ class FileCommentManager {
378
378
  ${commentIcon}
379
379
  </span>
380
380
  <span class="file-comment-badge" title="Comment applies to the entire file">File comment</span>
381
- ${window.getPostedCommentIcon?.(comment) || ''}
381
+ ${window.getPostedCommentIcon?.(comment, { link: true }) || ''}
382
382
  ${praiseBadge}
383
383
  ${titleHtml}
384
384
  </div>
@@ -399,6 +399,7 @@ class FileCommentManager {
399
399
  </div>
400
400
  </div>
401
401
  <div class="user-comment-body" data-original-markdown="${window.escapeHtmlAttribute(comment.body)}">${renderedBody}</div>
402
+ ${window.PostedComment?.getEditedSincePostedHtml(comment) || ''}
402
403
  `;
403
404
 
404
405
  // Wire up edit/delete buttons
@@ -448,7 +449,10 @@ class FileCommentManager {
448
449
  const userComments = this.prManager?.userComments || [];
449
450
  const suggestionIdNum = parseInt(suggestion.id);
450
451
  const wasAdopted = userComments.some(comment =>
451
- comment.parent_id && (comment.parent_id === suggestion.id || comment.parent_id === suggestionIdNum)
452
+ // A dismissed comment no longer adopts its suggestion (dismissing it
453
+ // dismisses the suggestion); the cache keeps dismissed comments.
454
+ comment.status !== 'inactive' && comment.parent_id &&
455
+ (comment.parent_id === suggestion.id || comment.parent_id === suggestionIdNum)
452
456
  );
453
457
 
454
458
  // Determine if suggestion should be collapsed based on status or adoption
@@ -45,6 +45,10 @@ class PierreBridge {
45
45
  // Monotonic counter for unique annotation IDs
46
46
  this._annotationCounter = 0;
47
47
 
48
+ // Rendered annotation elements, keyed by the annotation's metadata object.
49
+ // See _renderAnnotation for why these are reused across renders.
50
+ this._renderedAnnotations = new WeakMap();
51
+
48
52
  // Cache for gutter button containers — keyed by fileName.
49
53
  // Stored here instead of on fileState because renderGutterUtility fires
50
54
  // during instance.render(), before fileState is set on this.files.
@@ -1853,6 +1857,35 @@ class PierreBridge {
1853
1857
  * @private
1854
1858
  */
1855
1859
  _renderAnnotation(annotation, fileName, formElements) {
1860
+ const { metadata, lineNumber, side } = annotation;
1861
+ // Forms already reuse their DOM through formElements.
1862
+ if (metadata.type === 'comment-form') {
1863
+ return this._renderAnnotationContent(annotation, fileName, formElements);
1864
+ }
1865
+ // @pierre/diffs 1.6 calls renderAnnotation again for EVERY annotation
1866
+ // whenever the fileDiff object changes (context ranges, gap expansion,
1867
+ // rebuilds from base metadata), not only when the annotation changed, as
1868
+ // 1.2 did. Rebuilt cards would disconnect elements that callers still hold
1869
+ // (e.g. a scroll-to-finding in flight) and drop in-place DOM state. An
1870
+ // annotation's metadata object is replaced whenever its content changes
1871
+ // (_pushAnnotation), so the same metadata at the same line and side means
1872
+ // the same card: hand back the element already built for it.
1873
+ const cached = this._renderedAnnotations.get(metadata);
1874
+ if (cached && cached.lineNumber === lineNumber && cached.side === side) {
1875
+ return cached.element;
1876
+ }
1877
+ const element = this._renderAnnotationContent(annotation, fileName, formElements);
1878
+ if (element) {
1879
+ this._renderedAnnotations.set(metadata, { element, lineNumber, side });
1880
+ }
1881
+ return element;
1882
+ }
1883
+
1884
+ /**
1885
+ * Build the element for an annotation, by type.
1886
+ * @private
1887
+ */
1888
+ _renderAnnotationContent(annotation, fileName, formElements) {
1856
1889
  const { type, data, id } = annotation.metadata;
1857
1890
 
1858
1891
  switch (type) {
@@ -1957,7 +1990,7 @@ class PierreBridge {
1957
1990
  <div class="user-comment-header-left">
1958
1991
  <span class="comment-origin-icon">${commentIcon}</span>
1959
1992
  <span class="user-comment-line-info">${lineInfo}</span>
1960
- ${window.getPostedCommentIcon?.(comment) || ''}
1993
+ ${window.getPostedCommentIcon?.(comment, { link: true }) || ''}
1961
1994
  ${metadataHTML}
1962
1995
  </div>
1963
1996
  <div class="user-comment-actions">
@@ -1982,6 +2015,7 @@ class PierreBridge {
1982
2015
  </div>
1983
2016
  </div>
1984
2017
  <div class="user-comment-body" data-original-markdown="${window.escapeHtmlAttribute ? window.escapeHtmlAttribute(comment.body) : ''}">${window.renderMarkdown ? window.renderMarkdown(comment.body || '') : escapeHtml(comment.body || '')}</div>
2018
+ ${window.PostedComment?.getEditedSincePostedHtml(comment) || ''}
1985
2019
  </div>
1986
2020
  `;
1987
2021
 
@@ -619,7 +619,10 @@ class SuggestionManager {
619
619
 
620
620
  // Check if this suggestion was adopted by looking for user comments with matching parent_id
621
621
  const wasAdopted = userComments.some(comment =>
622
- comment.parent_id && (comment.parent_id === suggestion.id || comment.parent_id === suggestionIdNum)
622
+ // A dismissed comment no longer adopts its suggestion (dismissing it
623
+ // dismisses the suggestion); the cache keeps dismissed comments.
624
+ comment.status !== 'inactive' && comment.parent_id &&
625
+ (comment.parent_id === suggestion.id || comment.parent_id === suggestionIdNum)
623
626
  );
624
627
 
625
628
  // Log when a suggestion is detected as adopted