@in-the-loop-labs/pair-review 5.3.6 → 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 (41) 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 +407 -13
  7. package/public/js/components/AIPanel.js +323 -104
  8. package/public/js/components/ReviewHistoryModal.js +294 -0
  9. package/public/js/components/ReviewModal.js +131 -14
  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 +6 -12
  13. package/public/js/modules/comment-minimizer.js +4 -1
  14. package/public/js/modules/file-comment-manager.js +38 -74
  15. package/public/js/modules/pierre-bridge.js +36 -0
  16. package/public/js/modules/suggestion-manager.js +4 -1
  17. package/public/js/pr.js +337 -191
  18. package/public/js/utils/posted-comment.js +326 -0
  19. package/public/js/vendor/pierre-diffs-worker.js +41 -13485
  20. package/public/js/vendor/pierre-diffs.js +131 -1364
  21. package/public/local.html +1 -0
  22. package/public/pr.html +2 -0
  23. package/src/chat/api-reference.js +22 -2
  24. package/src/config.js +28 -4
  25. package/src/database.js +177 -35
  26. package/src/github/client.js +95 -16
  27. package/src/github/impl/graphql/pending-review-comments.js +118 -14
  28. package/src/github/impl/graphql/pending-review.js +8 -2
  29. package/src/github/impl/graphql/review-comment-edit.js +89 -0
  30. package/src/github/impl/host/pending-review-comments.js +41 -10
  31. package/src/github/impl/host/review-comment-edit.js +36 -0
  32. package/src/github/impl/rest/pending-review.js +6 -2
  33. package/src/github/impl/rest/review-comment-edit.js +44 -0
  34. package/src/github/impl/review-comment-edit-utils.js +45 -0
  35. package/src/github/operations/pending-review.js +4 -3
  36. package/src/github/operations/review-comment-edit.js +35 -0
  37. package/src/github/record-submission.js +78 -0
  38. package/src/github/update-posted-comment.js +115 -0
  39. package/src/main.js +24 -38
  40. package/src/routes/mcp.js +1 -0
  41. package/src/routes/pr.js +152 -100
@@ -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,9 +135,12 @@ 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>
138
+ <label class="remember-toggle hide-posted-comments-option">
139
+ <input type="checkbox" id="hide-posted-comments">
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>
143
+ </label>
132
144
 
133
145
  <!-- Warning dialog for large reviews -->
134
146
  <div class="warning-dialog" id="large-review-warning" style="display: none;">
@@ -159,6 +171,7 @@ class ReviewModal {
159
171
 
160
172
  document.body.appendChild(modalContainer);
161
173
  this.modal = modalContainer;
174
+
162
175
 
163
176
  // Store reference globally for onclick handlers
164
177
  window.reviewModal = this;
@@ -204,6 +217,9 @@ class ReviewModal {
204
217
  if (e.target.matches('#assisted-by-checkbox')) {
205
218
  window.reviewModal?.handleAssistedByToggle();
206
219
  }
220
+ if (e.target.matches('#hide-posted-comments')) {
221
+ window.reviewModal?.handleHidePostedToggle();
222
+ }
207
223
  });
208
224
  }
209
225
 
@@ -220,6 +236,8 @@ class ReviewModal {
220
236
  if (!textarea || !selectedOption) return;
221
237
 
222
238
  const isDraft = selectedOption.value === 'DRAFT';
239
+ const hidePostedOption = this.modal.querySelector('.hide-posted-comments-option');
240
+ if (hidePostedOption) hidePostedOption.hidden = isDraft;
223
241
 
224
242
  textarea.disabled = isDraft;
225
243
 
@@ -246,6 +264,15 @@ class ReviewModal {
246
264
 
247
265
  // Update comment count
248
266
  this.updateCommentCount();
267
+ const hidePosted = this.modal.querySelector('#hide-posted-comments');
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;
249
276
 
250
277
  // Reset form
251
278
  const textarea = this.modal.querySelector('#review-body-modal');
@@ -268,7 +295,6 @@ class ReviewModal {
268
295
 
269
296
  // Clear any errors or warnings
270
297
  this.hideError();
271
- this.updateLargeReviewWarning(0);
272
298
 
273
299
  // Show modal
274
300
  this.modal.style.display = 'flex';
@@ -381,11 +407,10 @@ class ReviewModal {
381
407
  * Update comment count display in modal
382
408
  */
383
409
  updateCommentCount() {
384
- // Count both line-level comments (.user-comment-row) and file-level comments (.file-comment-card.user-comment)
385
- const lineComments = document.querySelectorAll('.user-comment-row:not(.suggestion-edit-pending)').length;
386
- const fileComments = document.querySelectorAll('.file-comment-card.user-comment').length;
387
- const userComments = lineComments + fileComments;
410
+ const userComments = window.prManager?.getPendingCommentCount?.() || 0;
388
411
  const countElement = this.modal.querySelector('.review-comment-count');
412
+ const summary = this.modal.querySelector('.review-comment-summary');
413
+ if (summary) summary.style.display = userComments > 0 ? 'flex' : 'none';
389
414
 
390
415
  if (countElement) {
391
416
  if (userComments > 0) {
@@ -403,6 +428,73 @@ class ReviewModal {
403
428
 
404
429
  // Update large review warning
405
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;
483
+ }
484
+
485
+ handleHidePostedToggle() {
486
+ const checked = this.modal.querySelector('#hide-posted-comments').checked;
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();
492
+ try {
493
+ window.prManager?.applyPostedCommentVisibility();
494
+ } catch (error) {
495
+ console.error('Error updating comment visibility:', error);
496
+ window.toast?.showError('Could not update comment visibility. Please reload the page.');
497
+ }
406
498
  }
407
499
 
408
500
  /**
@@ -481,17 +573,19 @@ class ReviewModal {
481
573
  : reviewBody;
482
574
  const selectedOption = this.modal.querySelector('input[name="review-event"]:checked');
483
575
  const reviewEvent = selectedOption ? selectedOption.value : 'COMMENT';
484
- // Count BOTH line-level (.user-comment-row) and file-level (.file-comment-card.user-comment) comments
485
- // This must match the counting logic in updateCommentCount() for consistency
486
- const lineComments = document.querySelectorAll('.user-comment-row:not(.suggestion-edit-pending)').length;
487
- const fileComments = document.querySelectorAll('.file-comment-card.user-comment').length;
488
- const commentCount = lineComments + fileComments;
576
+ const commentCount = window.prManager?.getPendingCommentCount?.() || 0;
577
+ // Comments saved to the pending draft are published with this review too
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) : [];
489
583
 
490
584
  // Hide any previous errors
491
585
  this.hideError();
492
586
 
493
587
  // Validate
494
- if (reviewEvent === 'REQUEST_CHANGES' && !reviewBody && commentCount === 0) {
588
+ if (reviewEvent === 'REQUEST_CHANGES' && !reviewBody && submittableCount === 0) {
495
589
  this.showError('Please add comments or a review summary when requesting changes.');
496
590
  return;
497
591
  }
@@ -538,6 +632,11 @@ class ReviewModal {
538
632
  }
539
633
 
540
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: [] };
541
640
 
542
641
  // Show appropriate success message
543
642
  if (window.toast) {
@@ -561,6 +660,15 @@ class ReviewModal {
561
660
  }
562
661
  }
563
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
+
564
672
  // Clear submitting state before hiding modal
565
673
  this.setSubmittingState(false);
566
674
 
@@ -581,6 +689,15 @@ class ReviewModal {
581
689
  window.removeEventListener('beforeunload', handleBeforeUnload);
582
690
  }
583
691
 
692
+ // loadUserComments catches its own errors and resolves false when the
693
+ // reload failed. It resolves undefined when no PR is loaded, which is
694
+ // not a failure, so compare with false rather than testing !refreshed.
695
+ const refreshed = await window.prManager?.loadUserComments();
696
+ if (refreshed === false) {
697
+ console.error('Review posted, but comment refresh failed');
698
+ window.toast?.showWarning('Review posted, but comments could not be refreshed. Please reload the page.');
699
+ }
700
+
584
701
  // Update the pending draft indicator and modal state
585
702
  if (window.prManager?.currentPR) {
586
703
  if (isDraft) {
@@ -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
@@ -491,25 +491,16 @@ class CommentManager {
491
491
  // Create comment display row
492
492
  this.displayUserComment(commentData, formRow.previousElementSibling);
493
493
 
494
- // Notify AI Panel about the new comment
495
- if (window.aiPanel?.addComment) {
496
- window.aiPanel.addComment(commentData);
497
- }
498
-
499
494
  // Hide form and clear selection
500
495
  this.hideCommentForm();
501
496
  if (this.prManager?.lineTracker) {
502
497
  this.prManager.lineTracker.clearRangeSelection();
503
498
  }
504
499
 
505
- // Update comment count
506
- if (this.prManager?.updateCommentCount) {
507
- this.prManager.updateCommentCount();
508
- }
500
+ // Cache it and refresh the AI panel, counts and minimize-mode indicators
501
+ this.prManager?.registerUserComment?.(commentData);
509
502
 
510
- // Refresh minimize-mode indicators so the new comment is reflected
511
503
  if (window.prManager?.commentMinimizer) {
512
- window.prManager.commentMinimizer.refreshIndicators();
513
504
  // Auto-expand so the new comment stays visible in minimize mode
514
505
  const newRow = document.querySelector(`.user-comment-row[data-comment-id="${commentData.id}"]`);
515
506
  if (newRow) {
@@ -533,7 +524,7 @@ class CommentManager {
533
524
  /**
534
525
  * Display a user comment inline
535
526
  * Note: Dismissed comments are never rendered in the diff view per design decision.
536
- * They only appear in the AI/Review Panel. This method only receives active comments.
527
+ * They only appear in the AI/Review Panel. Posted comments can remain visible here.
537
528
  * @param {Object} comment - Comment data
538
529
  * @param {HTMLElement} targetRow - Row to insert after
539
530
  */
@@ -541,6 +532,7 @@ class CommentManager {
541
532
  const commentRow = document.createElement('tr');
542
533
  commentRow.className = 'user-comment-row';
543
534
  commentRow.dataset.commentId = comment.id;
535
+ window.PostedComment?.stampCommentStatus(commentRow, comment);
544
536
  // Store file/line/side data for editing
545
537
  commentRow.dataset.file = comment.file;
546
538
  commentRow.dataset.lineStart = comment.line_start;
@@ -614,6 +606,7 @@ class CommentManager {
614
606
  ${commentIcon}
615
607
  </span>
616
608
  <span class="user-comment-line-info">${lineInfo}</span>
609
+ ${window.getPostedCommentIcon?.(comment, { link: true }) || ''}
617
610
  ${expandedContextIndicator}
618
611
  ${metadataHTML}
619
612
  </div>
@@ -634,6 +627,7 @@ class CommentManager {
634
627
  </div>
635
628
  </div>
636
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) || ''}
637
631
  </div>
638
632
  `;
639
633