@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
@@ -138,6 +138,8 @@ class CommentMinimizer {
138
138
  const isExternal = card.classList.contains('external-comment-row');
139
139
  // Skip comment forms, tour stops, hunk summaries — those stay visible.
140
140
  if (!isComment && !isSuggestion && !isExternal) continue;
141
+ // Posted comments the reviewer chose to hide have nothing to expand.
142
+ if (card.classList.contains('posted-comment-hidden')) continue;
141
143
 
142
144
  const key = this._lineKeyFor(wrapper);
143
145
  if (!key) continue;
@@ -398,7 +400,8 @@ class CommentMinimizer {
398
400
  const info = { hasUser: false, hasAI: false, hasAdopted: false, userCount: 0, aiCount: 0, adoptedCount: 0 };
399
401
  for (const card of cards) {
400
402
  // Skip collapsed cards (adopted/dismissed originals remain in DOM)
401
- if (card.classList.contains('collapsed')) continue;
403
+ // and posted comments the reviewer chose to hide
404
+ if (card.classList.contains('collapsed') || card.classList.contains('posted-comment-hidden')) continue;
402
405
 
403
406
  if (card.classList.contains('ai-suggestion')) {
404
407
  info.hasAI = true;
@@ -315,25 +315,9 @@ class FileCommentManager {
315
315
  // Update count badge
316
316
  this.updateCommentCount(zone);
317
317
 
318
- // Refresh minimize-mode indicators so file-header counts stay current
319
- if (this.prManager?.commentMinimizer) {
320
- this.prManager.commentMinimizer.refreshIndicators();
321
- // Auto-expand so the new comment stays visible in minimize mode
322
- const newCard = zone.querySelector(`.file-comment-card[data-comment-id="${commentData.id}"]`);
323
- if (newCard) {
324
- this.prManager.commentMinimizer.expandForElement(newCard);
325
- }
326
- }
327
-
328
- // Notify AI Panel if available
329
- if (window.aiPanel?.addComment) {
330
- window.aiPanel.addComment(commentData);
331
- }
332
-
333
- // Update parent comment count
334
- if (this.prManager?.updateCommentCount) {
335
- this.prManager.updateCommentCount();
336
- }
318
+ // Cache it and refresh the AI panel, counts and minimize-mode indicators
319
+ this.prManager?.registerUserComment?.(commentData);
320
+ this.expandNewCardForMinimizer(zone, commentData.id);
337
321
 
338
322
  window.chatPanel?.queueUserActionHint(`[User Action: created comment ${result.commentId}]`);
339
323
 
@@ -353,7 +337,7 @@ class FileCommentManager {
353
337
  /**
354
338
  * Display a user file-level comment
355
339
  * Note: Dismissed comments are never rendered in the diff view per design decision.
356
- * They only appear in the AI/Review Panel. This method only receives active comments.
340
+ * They only appear in the AI/Review Panel. Posted comments can remain visible here.
357
341
  * @param {HTMLElement} zone - The file comments zone
358
342
  * @param {Object} comment - The comment data
359
343
  */
@@ -365,6 +349,7 @@ class FileCommentManager {
365
349
  const isAIOrigin = !!comment.parent_id;
366
350
  card.className = `file-comment-card user-comment ${isAIOrigin ? 'adopted-comment comment-ai-origin' : 'comment-user-origin'}`;
367
351
  card.dataset.commentId = comment.id;
352
+ window.PostedComment?.stampCommentStatus(card, comment);
368
353
 
369
354
  const renderedBody = window.renderMarkdown
370
355
  ? window.renderMarkdown(comment.body)
@@ -393,6 +378,7 @@ class FileCommentManager {
393
378
  ${commentIcon}
394
379
  </span>
395
380
  <span class="file-comment-badge" title="Comment applies to the entire file">File comment</span>
381
+ ${window.getPostedCommentIcon?.(comment, { link: true }) || ''}
396
382
  ${praiseBadge}
397
383
  ${titleHtml}
398
384
  </div>
@@ -413,6 +399,7 @@ class FileCommentManager {
413
399
  </div>
414
400
  </div>
415
401
  <div class="user-comment-body" data-original-markdown="${window.escapeHtmlAttribute(comment.body)}">${renderedBody}</div>
402
+ ${window.PostedComment?.getEditedSincePostedHtml(comment) || ''}
416
403
  `;
417
404
 
418
405
  // Wire up edit/delete buttons
@@ -462,7 +449,10 @@ class FileCommentManager {
462
449
  const userComments = this.prManager?.userComments || [];
463
450
  const suggestionIdNum = parseInt(suggestion.id);
464
451
  const wasAdopted = userComments.some(comment =>
465
- 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)
466
456
  );
467
457
 
468
458
  // Determine if suggestion should be collapsed based on status or adoption
@@ -629,25 +619,9 @@ class FileCommentManager {
629
619
  this.displayUserComment(zone, commentData);
630
620
  this.updateCommentCount(zone);
631
621
 
632
- // Refresh minimize-mode indicators so file-header counts stay current
633
- if (this.prManager?.commentMinimizer) {
634
- this.prManager.commentMinimizer.refreshIndicators();
635
- // Auto-expand so the new comment stays visible in minimize mode
636
- const newCard = zone.querySelector(`.file-comment-card[data-comment-id="${commentData.id}"]`);
637
- if (newCard) {
638
- this.prManager.commentMinimizer.expandForElement(newCard);
639
- }
640
- }
641
-
642
- // Update parent comment count for Preview button
643
- if (this.prManager?.updateCommentCount) {
644
- this.prManager.updateCommentCount();
645
- }
646
-
647
- // Add comment to AI Panel's comment list for navigation and display
648
- if (window.aiPanel?.addComment) {
649
- window.aiPanel.addComment(commentData);
650
- }
622
+ // Cache it and refresh the AI panel, counts and minimize-mode indicators
623
+ this.prManager?.registerUserComment?.(commentData);
624
+ this.expandNewCardForMinimizer(zone, commentData.id);
651
625
 
652
626
  // Update finding status in AI Panel (mark suggestion as adopted)
653
627
  if (window.aiPanel?.updateFindingStatus) {
@@ -897,25 +871,9 @@ class FileCommentManager {
897
871
  this.displayUserComment(zone, commentData);
898
872
  this.updateCommentCount(zone);
899
873
 
900
- // Refresh minimize-mode indicators so file-header counts stay current
901
- if (this.prManager?.commentMinimizer) {
902
- this.prManager.commentMinimizer.refreshIndicators();
903
- // Auto-expand so the new comment stays visible in minimize mode
904
- const newCard = zone.querySelector(`.file-comment-card[data-comment-id="${commentData.id}"]`);
905
- if (newCard) {
906
- this.prManager.commentMinimizer.expandForElement(newCard);
907
- }
908
- }
909
-
910
- // Update parent comment count for Preview button
911
- if (this.prManager?.updateCommentCount) {
912
- this.prManager.updateCommentCount();
913
- }
914
-
915
- // Add comment to AI Panel's comment list for navigation and display
916
- if (window.aiPanel?.addComment) {
917
- window.aiPanel.addComment(commentData);
918
- }
874
+ // Cache it and refresh the AI panel, counts and minimize-mode indicators
875
+ this.prManager?.registerUserComment?.(commentData);
876
+ this.expandNewCardForMinimizer(zone, commentData.id);
919
877
 
920
878
  // Update finding status in AI Panel (mark suggestion as adopted)
921
879
  if (window.aiPanel?.updateFindingStatus) {
@@ -1033,6 +991,8 @@ class FileCommentManager {
1033
991
  bodyEl.innerHTML = renderedBody;
1034
992
  bodyEl.dataset.originalMarkdown = newBody;
1035
993
 
994
+ this.prManager?.patchUserComment?.(commentId, { body: newBody });
995
+
1036
996
  } catch (error) {
1037
997
  console.error('Error updating comment:', error);
1038
998
  if (window.toast) {
@@ -1073,20 +1033,9 @@ class FileCommentManager {
1073
1033
 
1074
1034
  this.updateCommentCount(zone);
1075
1035
 
1076
- // Refresh minimize-mode indicators so file-header counts stay current
1077
- if (this.prManager?.commentMinimizer) {
1078
- this.prManager.commentMinimizer.refreshIndicators();
1079
- }
1080
-
1081
- // Update parent comment count
1082
- if (this.prManager?.updateCommentCount) {
1083
- this.prManager.updateCommentCount();
1084
- }
1085
-
1086
- // Notify AI Panel about the deleted comment
1087
- if (window.aiPanel?.removeComment) {
1088
- window.aiPanel.removeComment(commentId);
1089
- }
1036
+ // Updates the counts, the minimizer, and the AI panel (dismissed styling
1037
+ // when it shows dismissed comments, otherwise removed)
1038
+ this.prManager?.patchUserComment?.(commentId, { status: 'inactive' });
1090
1039
 
1091
1040
  // If a parent suggestion existed, the suggestion card is still collapsed/dismissed in the diff view.
1092
1041
  // Update AIPanel to show the suggestion as 'dismissed' (matching its visual state).
@@ -1121,6 +1070,20 @@ class FileCommentManager {
1121
1070
  return `/api/reviews/${reviewId}/suggestions/${suggestionId}/status`;
1122
1071
  }
1123
1072
 
1073
+ /**
1074
+ * Expand a newly rendered card in minimize mode so it stays visible
1075
+ * @param {HTMLElement} zone - The file comments zone
1076
+ * @param {number} commentId - The new comment's ID
1077
+ */
1078
+ expandNewCardForMinimizer(zone, commentId) {
1079
+ const minimizer = this.prManager?.commentMinimizer;
1080
+ if (!minimizer) return;
1081
+ const newCard = zone.querySelector(`.file-comment-card[data-comment-id="${commentId}"]`);
1082
+ if (newCard) {
1083
+ minimizer.expandForElement(newCard);
1084
+ }
1085
+ }
1086
+
1124
1087
  /**
1125
1088
  * Update the zone state based on comment count
1126
1089
  * @param {HTMLElement} zone - The file comments zone
@@ -1128,7 +1091,8 @@ class FileCommentManager {
1128
1091
  updateCommentCount(zone) {
1129
1092
  const container = zone.querySelector('.file-comments-container');
1130
1093
 
1131
- const userComments = container.querySelectorAll('.file-comment-card:not(.ai-suggestion)').length;
1094
+ // Hidden posted comments don't count: the reviewer can't see them
1095
+ const userComments = container.querySelectorAll('.file-comment-card:not(.ai-suggestion):not(.posted-comment-hidden)').length;
1132
1096
  const aiSuggestions = container.querySelectorAll('.file-comment-card.ai-suggestion').length;
1133
1097
  const total = userComments + aiSuggestions;
1134
1098
 
@@ -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) {
@@ -1945,6 +1978,7 @@ class PierreBridge {
1945
1978
  const container = document.createElement('div');
1946
1979
  container.className = 'user-comment-row';
1947
1980
  container.dataset.commentId = comment.id;
1981
+ window.PostedComment?.stampCommentStatus(container, comment);
1948
1982
  container.dataset.file = comment.file;
1949
1983
  container.dataset.lineStart = comment.line_start;
1950
1984
  container.dataset.lineEnd = comment.line_end || comment.line_start;
@@ -1956,6 +1990,7 @@ class PierreBridge {
1956
1990
  <div class="user-comment-header-left">
1957
1991
  <span class="comment-origin-icon">${commentIcon}</span>
1958
1992
  <span class="user-comment-line-info">${lineInfo}</span>
1993
+ ${window.getPostedCommentIcon?.(comment, { link: true }) || ''}
1959
1994
  ${metadataHTML}
1960
1995
  </div>
1961
1996
  <div class="user-comment-actions">
@@ -1980,6 +2015,7 @@ class PierreBridge {
1980
2015
  </div>
1981
2016
  </div>
1982
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) || ''}
1983
2019
  </div>
1984
2020
  `;
1985
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