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

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 (59) 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/index.html +1 -0
  8. package/public/js/components/AIPanel.js +317 -99
  9. package/public/js/components/AdvancedConfigTab.js +18 -108
  10. package/public/js/components/ReviewHistoryModal.js +294 -0
  11. package/public/js/components/ReviewModal.js +96 -7
  12. package/public/js/components/SplitButton.js +14 -0
  13. package/public/js/components/VoiceCentricConfigTab.js +18 -108
  14. package/public/js/index.js +18 -5
  15. package/public/js/local.js +4 -8
  16. package/public/js/modules/comment-manager.js +2 -1
  17. package/public/js/modules/diff-renderer.js +7 -6
  18. package/public/js/modules/file-comment-manager.js +6 -2
  19. package/public/js/modules/pierre-bridge.js +35 -1
  20. package/public/js/modules/suggestion-manager.js +4 -1
  21. package/public/js/pr.js +174 -66
  22. package/public/js/utils/council-timeout.js +203 -0
  23. package/public/js/utils/posted-comment.js +259 -14
  24. package/public/js/vendor/pierre-diffs-worker.js +41 -13485
  25. package/public/js/vendor/pierre-diffs.js +131 -1364
  26. package/public/local.html +4 -0
  27. package/public/pr.html +5 -0
  28. package/src/ai/copilot-provider.js +21 -2
  29. package/src/ai/cursor-agent-provider.js +21 -2
  30. package/src/ai/opencode-provider.js +21 -2
  31. package/src/chat/api-reference.js +22 -2
  32. package/src/config.js +28 -4
  33. package/src/database.js +416 -114
  34. package/src/git/worktree-pool-lifecycle.js +152 -33
  35. package/src/git/worktree-pool-usage.js +20 -0
  36. package/src/git/worktree.js +14 -5
  37. package/src/github/client.js +70 -15
  38. package/src/github/impl/graphql/pending-review-comments.js +50 -11
  39. package/src/github/impl/graphql/pending-review.js +8 -2
  40. package/src/github/impl/graphql/review-comment-edit.js +89 -0
  41. package/src/github/impl/host/pending-review-comments.js +41 -10
  42. package/src/github/impl/host/review-comment-edit.js +36 -0
  43. package/src/github/impl/rest/pending-review.js +6 -2
  44. package/src/github/impl/rest/review-comment-edit.js +44 -0
  45. package/src/github/impl/review-comment-edit-utils.js +45 -0
  46. package/src/github/operations/pending-review.js +4 -3
  47. package/src/github/operations/review-comment-edit.js +35 -0
  48. package/src/github/record-submission.js +78 -0
  49. package/src/github/update-posted-comment.js +115 -0
  50. package/src/main.js +42 -50
  51. package/src/routes/mcp.js +1 -0
  52. package/src/routes/pr.js +158 -120
  53. package/src/routes/reviews.js +8 -30
  54. package/src/routes/setup.js +22 -9
  55. package/src/setup/pr-setup.js +12 -3
  56. package/src/utils/diff-file-content.js +62 -25
  57. package/src/utils/json-extractor.js +267 -13
  58. package/src/utils/pr-file-blob-cache.js +134 -0
  59. package/src/utils/process-liveness.js +64 -0
@@ -44,6 +44,17 @@ class AdvancedConfigTab {
44
44
  /** Default timeout in milliseconds (10 minutes) */
45
45
  static DEFAULT_TIMEOUT = 600000;
46
46
 
47
+ /** DOM shape for the shared timeout mixin (see utils/council-timeout.js) */
48
+ static TIMEOUT_DOM = {
49
+ panelId: 'tab-panel-advanced',
50
+ voiceWrapperClass: 'participant-wrapper',
51
+ voiceKeys: ['level', 'index'],
52
+ timeoutClass: 'adv-timeout',
53
+ orchestrationTimeoutId: 'adv-orchestration-timeout',
54
+ orchestrationToggleId: 'adv-orchestration-timeout-toggle',
55
+ orchestrationRowId: 'orchestration-voice',
56
+ };
57
+
47
58
 
48
59
  constructor(modal) {
49
60
  this.modal = modal;
@@ -669,7 +680,7 @@ class AdvancedConfigTab {
669
680
  this._updateOrchestrationTimeoutIcon(panel, e.target.value);
670
681
  } else {
671
682
  const { level, index } = e.target.dataset;
672
- this._updateTimeoutIcon(panel, level, index, e.target.value);
683
+ this._updateTimeoutIcon(panel, { level, index }, e.target.value);
673
684
  }
674
685
  }
675
686
  });
@@ -946,45 +957,6 @@ class AdvancedConfigTab {
946
957
  iconBtn.classList.toggle('has-instructions', hasContent);
947
958
  }
948
959
 
949
- /**
950
- * Get the default timeout for a provider, falling back to the static DEFAULT_TIMEOUT.
951
- * @param {string} providerId - Provider ID (e.g., 'pi', 'claude')
952
- * @returns {number} Default timeout in ms
953
- */
954
- _getProviderDefaultTimeout(providerId) {
955
- const provider = this.providers[providerId];
956
- return provider?.defaultTimeout ?? AdvancedConfigTab.DEFAULT_TIMEOUT;
957
- }
958
-
959
- /**
960
- * Update the clock/timeout icon styling to indicate non-default timeout.
961
- * @param {Element} panel - The council panel element
962
- * @param {string} level - Level number
963
- * @param {string} index - Voice index
964
- * @param {string} value - Current timeout value (as string of ms)
965
- */
966
- _updateTimeoutIcon(panel, level, index, value) {
967
- const wrapper = panel.querySelector(`.participant-wrapper[data-level="${level}"][data-index="${index}"]`);
968
- const iconBtn = wrapper?.querySelector(`.toggle-timeout-icon[data-level="${level}"][data-index="${index}"]`);
969
- if (!iconBtn) return;
970
-
971
- const providerId = wrapper?.querySelector('.voice-provider')?.value;
972
- const defaultTimeout = this._getProviderDefaultTimeout(providerId);
973
- const isNonDefault = parseInt(value, 10) !== defaultTimeout;
974
- iconBtn.classList.toggle('has-custom-timeout', isNonDefault);
975
- }
976
-
977
- _updateOrchestrationTimeoutIcon(panel, value) {
978
- const iconBtn = panel.querySelector('#adv-orchestration-timeout-toggle');
979
- if (!iconBtn) return;
980
-
981
- const orchRow = panel.querySelector('#orchestration-voice');
982
- const providerId = orchRow?.querySelector('.voice-provider')?.value;
983
- const defaultTimeout = this._getProviderDefaultTimeout(providerId);
984
- const isNonDefault = parseInt(value, 10) !== defaultTimeout;
985
- iconBtn.classList.toggle('has-custom-timeout', isNonDefault);
986
- }
987
-
988
960
  _updateOrchestrationInstructionsIcon(panel, value) {
989
961
  const iconBtn = panel.querySelector('#adv-orchestration-instructions-toggle');
990
962
  if (!iconBtn) return;
@@ -996,48 +968,6 @@ class AdvancedConfigTab {
996
968
  iconBtn.classList.toggle('has-instructions', hasContent);
997
969
  }
998
970
 
999
- /**
1000
- * When a voice's provider changes, update its timeout to the new provider's default,
1001
- * preserving explicit user overrides via Math.max when the user had customized the value.
1002
- * @param {HTMLSelectElement} providerSelect - The provider dropdown that changed
1003
- */
1004
- _applyProviderDefaultTimeout(providerSelect) {
1005
- const panel = this.modal.querySelector('#tab-panel-advanced');
1006
- if (!panel) return;
1007
-
1008
- const providerId = providerSelect.value;
1009
- const newDefault = this._getProviderDefaultTimeout(providerId);
1010
- const oldProviderId = providerSelect.dataset.previousProvider;
1011
- const oldDefault = oldProviderId ? this._getProviderDefaultTimeout(oldProviderId) : null;
1012
-
1013
- const isOrchestration = providerSelect.dataset.target === 'orchestration';
1014
- if (isOrchestration) {
1015
- const timeoutEl = panel.querySelector('#adv-orchestration-timeout');
1016
- if (timeoutEl) {
1017
- const currentValue = parseInt(timeoutEl.value, 10);
1018
- const resolvedTimeout = (oldDefault !== null && currentValue !== oldDefault)
1019
- ? Math.max(currentValue, newDefault)
1020
- : newDefault;
1021
- timeoutEl.value = String(resolvedTimeout);
1022
- this._updateOrchestrationTimeoutIcon(panel, String(resolvedTimeout));
1023
- }
1024
- } else {
1025
- const { level, index } = providerSelect.dataset;
1026
- const wrapper = providerSelect.closest('.participant-wrapper');
1027
- const timeoutEl = wrapper?.querySelector('.adv-timeout');
1028
- if (timeoutEl) {
1029
- const currentValue = parseInt(timeoutEl.value, 10);
1030
- const resolvedTimeout = (oldDefault !== null && currentValue !== oldDefault)
1031
- ? Math.max(currentValue, newDefault)
1032
- : newDefault;
1033
- timeoutEl.value = String(resolvedTimeout);
1034
- this._updateTimeoutIcon(panel, level, index, String(resolvedTimeout));
1035
- }
1036
- }
1037
-
1038
- providerSelect.dataset.previousProvider = providerId;
1039
- }
1040
-
1041
971
  // --- Dirty state tracking ---
1042
972
 
1043
973
  _markDirty() {
@@ -1231,18 +1161,7 @@ class AdvancedConfigTab {
1231
1161
  TimeoutSelect.mount(mount, { className: 'adv-timeout', title: 'Per-reviewer timeout' });
1232
1162
  }
1233
1163
  const timeoutEl = row?.querySelector('.adv-timeout');
1234
- const providerDefaultTimeout = this._getProviderDefaultTimeout(voice.provider);
1235
- if (timeoutEl && voice.timeout) {
1236
- timeoutEl.value = String(voice.timeout);
1237
- // Show the dropdown if non-default for this provider
1238
- if (voice.timeout !== providerDefaultTimeout) {
1239
- timeoutEl.style.display = '';
1240
- }
1241
- this._updateTimeoutIcon(panel, String(level), String(i), String(voice.timeout));
1242
- } else if (timeoutEl) {
1243
- // No saved timeout — apply the provider's default
1244
- timeoutEl.value = String(providerDefaultTimeout);
1245
- }
1164
+ this._restoreVoiceTimeout(panel, { level: String(level), index: String(i) }, timeoutEl, voice);
1246
1165
 
1247
1166
  if (voice.customInstructions) {
1248
1167
  const instrInput = participantWrapper?.querySelector(`.voice-instructions-input[data-level="${level}"][data-index="${i}"]`);
@@ -1280,20 +1199,7 @@ class AdvancedConfigTab {
1280
1199
  }
1281
1200
 
1282
1201
  // Restore consolidation timeout
1283
- const orchTimeoutSelect = panel.querySelector('#adv-orchestration-timeout');
1284
- const orchProviderDefaultTimeout = this._getProviderDefaultTimeout(consolSection.provider);
1285
- if (orchTimeoutSelect && consolSection.timeout) {
1286
- orchTimeoutSelect.value = String(consolSection.timeout);
1287
- // Show the dropdown if non-default for this provider
1288
- if (consolSection.timeout !== orchProviderDefaultTimeout) {
1289
- orchTimeoutSelect.style.display = '';
1290
- }
1291
- this._updateOrchestrationTimeoutIcon(panel, String(consolSection.timeout));
1292
- } else if (orchTimeoutSelect) {
1293
- // No saved timeout — apply the provider's default
1294
- orchTimeoutSelect.value = String(orchProviderDefaultTimeout);
1295
- this._updateOrchestrationTimeoutIcon(panel, String(orchProviderDefaultTimeout));
1296
- }
1202
+ this._restoreOrchestrationTimeout(panel, consolSection);
1297
1203
 
1298
1204
  // Restore consolidation custom instructions
1299
1205
  const orchInstrInput = panel.querySelector('#adv-orchestration-instructions');
@@ -1475,6 +1381,10 @@ class AdvancedConfigTab {
1475
1381
  }
1476
1382
  }
1477
1383
 
1384
+ // Shared timeout methods (public/js/utils/council-timeout.js). In the browser the
1385
+ // util's <script> tag loads first; unit tests load it via require().
1386
+ ((typeof window !== 'undefined' && window.CouncilTimeout) || require('../utils/council-timeout.js')).mixInto(AdvancedConfigTab);
1387
+
1478
1388
  // Export for use in other modules
1479
1389
  if (typeof window !== 'undefined') {
1480
1390
  window.AdvancedConfigTab = AdvancedConfigTab;
@@ -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;