@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.
- package/README.md +8 -0
- package/package.json +3 -3
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin-code-critic/.claude-plugin/plugin.json +1 -1
- package/plugin-pair-loop/.claude-plugin/plugin.json +1 -1
- package/public/css/pr.css +389 -13
- package/public/index.html +1 -0
- package/public/js/components/AIPanel.js +317 -99
- package/public/js/components/AdvancedConfigTab.js +18 -108
- package/public/js/components/ReviewHistoryModal.js +294 -0
- package/public/js/components/ReviewModal.js +96 -7
- package/public/js/components/SplitButton.js +14 -0
- package/public/js/components/VoiceCentricConfigTab.js +18 -108
- package/public/js/index.js +18 -5
- package/public/js/local.js +4 -8
- package/public/js/modules/comment-manager.js +2 -1
- package/public/js/modules/diff-renderer.js +7 -6
- package/public/js/modules/file-comment-manager.js +6 -2
- package/public/js/modules/pierre-bridge.js +35 -1
- package/public/js/modules/suggestion-manager.js +4 -1
- package/public/js/pr.js +174 -66
- package/public/js/utils/council-timeout.js +203 -0
- package/public/js/utils/posted-comment.js +259 -14
- package/public/js/vendor/pierre-diffs-worker.js +41 -13485
- package/public/js/vendor/pierre-diffs.js +131 -1364
- package/public/local.html +4 -0
- package/public/pr.html +5 -0
- package/src/ai/copilot-provider.js +21 -2
- package/src/ai/cursor-agent-provider.js +21 -2
- package/src/ai/opencode-provider.js +21 -2
- package/src/chat/api-reference.js +22 -2
- package/src/config.js +28 -4
- package/src/database.js +416 -114
- package/src/git/worktree-pool-lifecycle.js +152 -33
- package/src/git/worktree-pool-usage.js +20 -0
- package/src/git/worktree.js +14 -5
- package/src/github/client.js +70 -15
- package/src/github/impl/graphql/pending-review-comments.js +50 -11
- package/src/github/impl/graphql/pending-review.js +8 -2
- package/src/github/impl/graphql/review-comment-edit.js +89 -0
- package/src/github/impl/host/pending-review-comments.js +41 -10
- package/src/github/impl/host/review-comment-edit.js +36 -0
- package/src/github/impl/rest/pending-review.js +6 -2
- package/src/github/impl/rest/review-comment-edit.js +44 -0
- package/src/github/impl/review-comment-edit-utils.js +45 -0
- package/src/github/operations/pending-review.js +4 -3
- package/src/github/operations/review-comment-edit.js +35 -0
- package/src/github/record-submission.js +78 -0
- package/src/github/update-posted-comment.js +115 -0
- package/src/main.js +42 -50
- package/src/routes/mcp.js +1 -0
- package/src/routes/pr.js +158 -120
- package/src/routes/reviews.js +8 -30
- package/src/routes/setup.js +22 -9
- package/src/setup/pr-setup.js +12 -3
- package/src/utils/diff-file-content.js +62 -25
- package/src/utils/json-extractor.js +267 -13
- package/src/utils/pr-file-blob-cache.js +134 -0
- package/src/utils/process-liveness.js +64 -0
package/public/js/pr.js
CHANGED
|
@@ -663,10 +663,10 @@ class PRManager {
|
|
|
663
663
|
}
|
|
664
664
|
});
|
|
665
665
|
|
|
666
|
-
//
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
this.loadUserComments(
|
|
666
|
+
// Reload user comments when the reviewer changes the comment panel's
|
|
667
|
+
// filters (show dismissed, show posted). loadUserComments reads them.
|
|
668
|
+
document.addEventListener('commentFilterChanged', () => {
|
|
669
|
+
this.loadUserComments();
|
|
670
670
|
});
|
|
671
671
|
}
|
|
672
672
|
|
|
@@ -675,6 +675,17 @@ class PRManager {
|
|
|
675
675
|
* This avoids memory leaks from attaching listeners to each textarea
|
|
676
676
|
*/
|
|
677
677
|
setupCommentFormDelegation() {
|
|
678
|
+
// "Update on GitHub" on an edited posted comment, in any diff renderer
|
|
679
|
+
document.addEventListener('click', (e) => {
|
|
680
|
+
const button = e.target.closest?.('.btn-update-on-host');
|
|
681
|
+
if (!button || button.disabled) return;
|
|
682
|
+
e.preventDefault();
|
|
683
|
+
e.stopPropagation();
|
|
684
|
+
this.updatePostedCommentOnHost(button.dataset.updateCommentId).then(result => {
|
|
685
|
+
if (result?.ok) window.toast?.showSuccess(`Comment updated on ${window.PostedComment.escapeHtml(window.PostedComment.hostName())}`);
|
|
686
|
+
});
|
|
687
|
+
});
|
|
688
|
+
|
|
678
689
|
document.addEventListener('keydown', (e) => {
|
|
679
690
|
// Check if we're in a comment-related textarea
|
|
680
691
|
const textarea = e.target;
|
|
@@ -1028,10 +1039,8 @@ class PRManager {
|
|
|
1028
1039
|
}
|
|
1029
1040
|
window.panelGroup?.setPR(`${owner}/${repo}#${number}`);
|
|
1030
1041
|
|
|
1031
|
-
// Load saved comments
|
|
1032
|
-
|
|
1033
|
-
const includeDismissed = window.aiPanel?.showDismissedComments || false;
|
|
1034
|
-
await this.loadUserComments(includeDismissed);
|
|
1042
|
+
// Load saved comments: uses the comment panel's filters (restored from localStorage by setPR)
|
|
1043
|
+
await this.loadUserComments();
|
|
1035
1044
|
|
|
1036
1045
|
// Initialize analysis history manager if review ID is available
|
|
1037
1046
|
// The review ID is needed to fetch analysis runs from the database
|
|
@@ -1111,8 +1120,7 @@ class PRManager {
|
|
|
1111
1120
|
* the existing mirror.
|
|
1112
1121
|
*/
|
|
1113
1122
|
async _rerenderAllOverlays({ analysisRunId, syncExternal = false } = {}) {
|
|
1114
|
-
|
|
1115
|
-
await this.loadUserComments(includeDismissed);
|
|
1123
|
+
await this.loadUserComments();
|
|
1116
1124
|
await this.loadAISuggestions(null, analysisRunId);
|
|
1117
1125
|
// Skip external-comment re-rendering entirely when the feature is off.
|
|
1118
1126
|
// The manager is never populated with rows in that case, so there's
|
|
@@ -4170,8 +4178,7 @@ class PRManager {
|
|
|
4170
4178
|
|
|
4171
4179
|
async _reanchorInlineFeedbackAfterDeferredRender() {
|
|
4172
4180
|
try {
|
|
4173
|
-
|
|
4174
|
-
await this.loadUserComments(includeDismissed);
|
|
4181
|
+
await this.loadUserComments();
|
|
4175
4182
|
await this.loadAISuggestions(null, this.selectedRunId);
|
|
4176
4183
|
} catch (err) {
|
|
4177
4184
|
console.error('Failed to re-anchor inline feedback after deferred diff render:', err);
|
|
@@ -6126,8 +6133,7 @@ class PRManager {
|
|
|
6126
6133
|
// Remove form annotation
|
|
6127
6134
|
this.pierreBridge.removeAnnotation(fileName, annotationId);
|
|
6128
6135
|
// Reload comments to show the new one
|
|
6129
|
-
|
|
6130
|
-
await this.loadUserComments(includeDismissed);
|
|
6136
|
+
await this.loadUserComments();
|
|
6131
6137
|
|
|
6132
6138
|
// Legacy-path side-effects: clear the dragged range, auto-expand in
|
|
6133
6139
|
// minimize mode, and notify the AI chat context. Parity with
|
|
@@ -6434,9 +6440,7 @@ class PRManager {
|
|
|
6434
6440
|
if (!response.ok) throw new Error('Failed to restore comment');
|
|
6435
6441
|
|
|
6436
6442
|
// Reload comments to update both the diff view and AI panel
|
|
6437
|
-
|
|
6438
|
-
const includeDismissed = window.aiPanel?.showDismissedComments || false;
|
|
6439
|
-
await this.loadUserComments(includeDismissed);
|
|
6443
|
+
await this.loadUserComments();
|
|
6440
6444
|
|
|
6441
6445
|
// Show success toast
|
|
6442
6446
|
if (window.toast) {
|
|
@@ -6467,10 +6471,8 @@ class PRManager {
|
|
|
6467
6471
|
* Clear all user comments (soft-delete with confirmation for bulk operations)
|
|
6468
6472
|
*/
|
|
6469
6473
|
async clearAllUserComments() {
|
|
6470
|
-
|
|
6471
|
-
const
|
|
6472
|
-
const fileCommentCards = document.querySelectorAll('.file-comment-card.user-comment');
|
|
6473
|
-
const totalComments = lineCommentRows.length + fileCommentCards.length;
|
|
6474
|
+
const totalComments = this.getPendingCommentCount();
|
|
6475
|
+
const hasPosted = (this.userComments || []).some(window.PostedComment.isPostedComment);
|
|
6474
6476
|
|
|
6475
6477
|
if (totalComments === 0) {
|
|
6476
6478
|
if (window.toast?.showInfo) {
|
|
@@ -6486,7 +6488,7 @@ class PRManager {
|
|
|
6486
6488
|
|
|
6487
6489
|
const dialogResult = await window.confirmDialog.show({
|
|
6488
6490
|
title: 'Clear All Comments?',
|
|
6489
|
-
message: `This will dismiss all ${totalComments} comment${totalComments !== 1 ? 's' : ''}. You can restore them later
|
|
6491
|
+
message: `This will dismiss all ${totalComments} pending comment${totalComments !== 1 ? 's' : ''}. You can restore them later.${hasPosted ? ' Posted comments are kept.' : ''}`,
|
|
6490
6492
|
confirmText: 'Clear All',
|
|
6491
6493
|
confirmClass: 'btn-danger'
|
|
6492
6494
|
});
|
|
@@ -6501,30 +6503,11 @@ class PRManager {
|
|
|
6501
6503
|
if (!response.ok) throw new Error('Failed to delete comments');
|
|
6502
6504
|
|
|
6503
6505
|
const result = await response.json();
|
|
6504
|
-
const deletedCount = result.deletedCount
|
|
6505
|
-
|
|
6506
|
-
// Remove line-level comment rows from DOM
|
|
6507
|
-
lineCommentRows.forEach(row => row.remove());
|
|
6508
|
-
|
|
6509
|
-
// Remove file-level comment cards from DOM
|
|
6510
|
-
fileCommentCards.forEach(card => {
|
|
6511
|
-
const zone = card.closest('.file-comments-zone');
|
|
6512
|
-
card.remove();
|
|
6513
|
-
|
|
6514
|
-
// Update the file comment zone header button state
|
|
6515
|
-
if (zone && this.fileCommentManager) {
|
|
6516
|
-
this.fileCommentManager.updateCommentCount(zone);
|
|
6517
|
-
}
|
|
6518
|
-
});
|
|
6519
|
-
|
|
6520
|
-
// Remove line-level and file-level comment elements from diff view
|
|
6521
|
-
// (They have been soft-deleted, so should not appear in the diff panel per design decision)
|
|
6522
|
-
// The comments array will be reloaded below with proper dismissed state.
|
|
6506
|
+
const deletedCount = result.deletedCount ?? totalComments;
|
|
6523
6507
|
|
|
6524
6508
|
// Reload comments to update both internal state and AI Panel
|
|
6525
6509
|
// This shows dismissed comments in AI Panel if filter is enabled, matching individual deletion behavior
|
|
6526
|
-
|
|
6527
|
-
await this.loadUserComments(includeDismissed);
|
|
6510
|
+
await this.loadUserComments();
|
|
6528
6511
|
|
|
6529
6512
|
// Update dismissed suggestions in the diff view UI
|
|
6530
6513
|
// (AI Panel is already updated by loadUserComments via setComments)
|
|
@@ -6549,24 +6532,26 @@ class PRManager {
|
|
|
6549
6532
|
}
|
|
6550
6533
|
|
|
6551
6534
|
/**
|
|
6552
|
-
* Load user comments from API
|
|
6553
|
-
*
|
|
6554
|
-
*
|
|
6555
|
-
*
|
|
6556
|
-
*
|
|
6557
|
-
*
|
|
6558
|
-
*
|
|
6535
|
+
* Load user comments from API and render them.
|
|
6536
|
+
*
|
|
6537
|
+
* Every user comment is fetched, dismissed ones included, so the cache
|
|
6538
|
+
* matches what live edits leave in it and the hidden-comments notice can
|
|
6539
|
+
* count from data. What shows follows the comment panel's filters
|
|
6540
|
+
* (getCommentFilterState), read at render time, so reloads triggered by
|
|
6541
|
+
* events (live sync, tab becoming visible) keep what the panel shows.
|
|
6542
|
+
* Dismissed comments are NEVER shown in the diff panel (design decision);
|
|
6543
|
+
* they show in the AI Panel when its "Show dismissed" filter is on.
|
|
6559
6544
|
* @returns {Promise<boolean|undefined>} true once rendered, false if the
|
|
6560
6545
|
* reload failed, undefined when no PR is loaded. A load overtaken by a
|
|
6561
6546
|
* newer one resolves with the newer load's result.
|
|
6562
6547
|
*/
|
|
6563
|
-
loadUserComments(
|
|
6564
|
-
const load = this._loadUserComments(
|
|
6548
|
+
loadUserComments() {
|
|
6549
|
+
const load = this._loadUserComments();
|
|
6565
6550
|
this._latestUserCommentsLoad = load;
|
|
6566
6551
|
return load;
|
|
6567
6552
|
}
|
|
6568
6553
|
|
|
6569
|
-
async _loadUserComments(
|
|
6554
|
+
async _loadUserComments() {
|
|
6570
6555
|
if (!this.currentPR) return;
|
|
6571
6556
|
|
|
6572
6557
|
const generation = (this._userCommentsLoadGeneration || 0) + 1;
|
|
@@ -6581,7 +6566,7 @@ class PRManager {
|
|
|
6581
6566
|
// so fetch again (a few times at most) until the cache stood still.
|
|
6582
6567
|
for (let attempt = 1; ; attempt++) {
|
|
6583
6568
|
const cacheVersion = this._userCommentsVersion || 0;
|
|
6584
|
-
({ comments, fileLevelComments, lineLevelComments } = await this._fetchUserCommentsForRender(
|
|
6569
|
+
({ comments, fileLevelComments, lineLevelComments } = await this._fetchUserCommentsForRender());
|
|
6585
6570
|
if (generation !== this._userCommentsLoadGeneration) return this._latestUserCommentsLoad;
|
|
6586
6571
|
if (cacheVersion === (this._userCommentsVersion || 0) || attempt >= 3) break;
|
|
6587
6572
|
}
|
|
@@ -6670,9 +6655,8 @@ class PRManager {
|
|
|
6670
6655
|
* every line-level comment's target line reachable in the DOM.
|
|
6671
6656
|
* @private
|
|
6672
6657
|
*/
|
|
6673
|
-
async _fetchUserCommentsForRender(
|
|
6674
|
-
const
|
|
6675
|
-
const response = await fetch(`/api/reviews/${this.currentPR.id}/comments${queryParam}`);
|
|
6658
|
+
async _fetchUserCommentsForRender() {
|
|
6659
|
+
const response = await fetch(`/api/reviews/${this.currentPR.id}/comments?includeDismissed=true`);
|
|
6676
6660
|
if (!response.ok) throw new Error('Failed to load comments');
|
|
6677
6661
|
|
|
6678
6662
|
const data = await response.json();
|
|
@@ -6713,15 +6697,46 @@ class PRManager {
|
|
|
6713
6697
|
return { comments, fileLevelComments, lineLevelComments };
|
|
6714
6698
|
}
|
|
6715
6699
|
|
|
6700
|
+
/**
|
|
6701
|
+
* The comment panel's user-comment filters. Falls back to the panel's
|
|
6702
|
+
* show-dismissed flag and this review's posted setting when the panel
|
|
6703
|
+
* predates getCommentFilterState (or is a test stub).
|
|
6704
|
+
* @returns {{includeDismissed: boolean, showPosted: boolean}}
|
|
6705
|
+
*/
|
|
6706
|
+
getCommentFilterState() {
|
|
6707
|
+
const state = window.aiPanel?.getCommentFilterState?.();
|
|
6708
|
+
if (state) return state;
|
|
6709
|
+
return {
|
|
6710
|
+
includeDismissed: !!window.aiPanel?.showDismissedComments,
|
|
6711
|
+
showPosted: !(window.PostedComment?.isHidePostedInEffect() ?? false)
|
|
6712
|
+
};
|
|
6713
|
+
}
|
|
6714
|
+
|
|
6715
|
+
/**
|
|
6716
|
+
* How many cached user comments the panel's filters hide, counted from the
|
|
6717
|
+
* comment data (never DOM rows), for the panel's hidden-comments notice.
|
|
6718
|
+
* @param {{includeDismissed: boolean, showPosted: boolean}} [filter]
|
|
6719
|
+
* @returns {{posted: number, dismissed: number}}
|
|
6720
|
+
*/
|
|
6721
|
+
getHiddenCommentCounts(filter = this.getCommentFilterState()) {
|
|
6722
|
+
const comments = this.userComments || [];
|
|
6723
|
+
return {
|
|
6724
|
+
posted: window.PostedComment.countHiddenPostedComments(comments, !filter.showPosted),
|
|
6725
|
+
dismissed: filter.includeDismissed ? 0 : comments.filter(c => c.status === 'inactive').length
|
|
6726
|
+
};
|
|
6727
|
+
}
|
|
6728
|
+
|
|
6716
6729
|
applyPostedCommentVisibility() {
|
|
6717
|
-
const {
|
|
6718
|
-
const
|
|
6730
|
+
const { shouldHidePostedComment } = window.PostedComment;
|
|
6731
|
+
const filter = this.getCommentFilterState();
|
|
6732
|
+
const hidePosted = !filter.showPosted;
|
|
6719
6733
|
document.querySelectorAll('[data-comment-status]').forEach(element => {
|
|
6720
6734
|
element.classList.toggle('posted-comment-hidden',
|
|
6721
|
-
shouldHidePostedComment({ status: element.dataset.commentStatus }, hidePosted));
|
|
6735
|
+
shouldHidePostedComment({ status: element.dataset.commentStatus, publication: element.dataset.commentPublication === 'none' ? null : { state: element.dataset.commentPublication } }, hidePosted));
|
|
6722
6736
|
});
|
|
6737
|
+
window.aiPanel?.setHiddenCommentCounts?.(this.getHiddenCommentCounts(filter));
|
|
6723
6738
|
window.aiPanel?.setComments?.((this.userComments || []).filter(c =>
|
|
6724
|
-
(c.status !== 'inactive' ||
|
|
6739
|
+
(c.status !== 'inactive' || filter.includeDismissed) &&
|
|
6725
6740
|
!shouldHidePostedComment(c, hidePosted)
|
|
6726
6741
|
));
|
|
6727
6742
|
|
|
@@ -7344,6 +7359,7 @@ class PRManager {
|
|
|
7344
7359
|
onPreview: () => this.openPreviewModal(),
|
|
7345
7360
|
onClear: () => this.clearAllUserComments(),
|
|
7346
7361
|
onShare: () => this.openSharePage(),
|
|
7362
|
+
onHistory: window.PAIR_REVIEW_LOCAL_MODE ? null : () => this.openReviewHistory(),
|
|
7347
7363
|
shareUrl: validatedShareUrl,
|
|
7348
7364
|
shareIcon: shareConfig?.icon || null,
|
|
7349
7365
|
shareLabel: shareConfig?.label || 'Share',
|
|
@@ -7374,6 +7390,17 @@ class PRManager {
|
|
|
7374
7390
|
this.reviewModal.show();
|
|
7375
7391
|
}
|
|
7376
7392
|
|
|
7393
|
+
/**
|
|
7394
|
+
* Open the review history: what this review posted to the host. PR mode only.
|
|
7395
|
+
*/
|
|
7396
|
+
openReviewHistory() {
|
|
7397
|
+
if (window.PAIR_REVIEW_LOCAL_MODE || !this.currentPR?.id || !window.ReviewHistoryModal) return;
|
|
7398
|
+
if (!this.reviewHistoryModal) {
|
|
7399
|
+
this.reviewHistoryModal = new window.ReviewHistoryModal();
|
|
7400
|
+
}
|
|
7401
|
+
this.reviewHistoryModal.show(this.currentPR.id);
|
|
7402
|
+
}
|
|
7403
|
+
|
|
7377
7404
|
/**
|
|
7378
7405
|
* Open preview modal
|
|
7379
7406
|
*/
|
|
@@ -7475,9 +7502,19 @@ class PRManager {
|
|
|
7475
7502
|
* @param {Object} updates - e.g. { body } or { status: 'inactive' }
|
|
7476
7503
|
*/
|
|
7477
7504
|
patchUserComment(commentId, updates) {
|
|
7505
|
+
const before = (this.userComments || []).find(c => c.id === commentId);
|
|
7478
7506
|
this.userComments = (this.userComments || []).map(c => c.id === commentId ? { ...c, ...updates } : c);
|
|
7507
|
+
// Editing a posted comment changes whether it differs from what was
|
|
7508
|
+
// posted; only the server knows the posted text, so ask it.
|
|
7509
|
+
if (updates.body !== undefined && before && window.PostedComment?.isPostedComment(before)) {
|
|
7510
|
+
window.PostedComment.setUpdateError(commentId, null);
|
|
7511
|
+
this.refreshCommentPublication(commentId);
|
|
7512
|
+
}
|
|
7479
7513
|
this._userCommentsVersion = (this._userCommentsVersion || 0) + 1;
|
|
7480
|
-
if (
|
|
7514
|
+
if (window.aiPanel?.setHiddenCommentCounts) {
|
|
7515
|
+
window.aiPanel.setHiddenCommentCounts(this.getHiddenCommentCounts());
|
|
7516
|
+
}
|
|
7517
|
+
if (updates.status === 'inactive' && !this.getCommentFilterState().includeDismissed) {
|
|
7481
7518
|
window.aiPanel?.removeComment?.(commentId);
|
|
7482
7519
|
} else {
|
|
7483
7520
|
window.aiPanel?.updateComment?.(commentId, updates);
|
|
@@ -7486,9 +7523,80 @@ class PRManager {
|
|
|
7486
7523
|
this.commentMinimizer?.refreshIndicators();
|
|
7487
7524
|
}
|
|
7488
7525
|
|
|
7526
|
+
/**
|
|
7527
|
+
* Replace a cached comment with the server's copy (fresh publication) and
|
|
7528
|
+
* re-render its edited-since-posted note in place, in every renderer.
|
|
7529
|
+
* @param {Object} comment - Comment from the server
|
|
7530
|
+
*/
|
|
7531
|
+
applyServerComment(comment) {
|
|
7532
|
+
if (!comment) return;
|
|
7533
|
+
this.userComments = (this.userComments || []).map(c => c.id === comment.id ? { ...c, ...comment } : c);
|
|
7534
|
+
this._userCommentsVersion = (this._userCommentsVersion || 0) + 1;
|
|
7535
|
+
const cached = this.userComments.find(c => c.id === comment.id) || comment;
|
|
7536
|
+
// @pierre/diffs re-renders annotations from their stored data
|
|
7537
|
+
for (const annotation of this.pierreBridge?.getAnnotations?.(cached.file, 'comment') || []) {
|
|
7538
|
+
if (annotation.metadata?.data?.id === cached.id) Object.assign(annotation.metadata.data, cached);
|
|
7539
|
+
}
|
|
7540
|
+
window.PostedComment?.findRenderedComments(comment.id)
|
|
7541
|
+
.forEach(element => window.PostedComment.syncEditedSincePosted(element, cached));
|
|
7542
|
+
window.aiPanel?.updateComment?.(comment.id, { body: cached.body, publication: cached.publication });
|
|
7543
|
+
if (this.reviewModal?.isVisible) this.reviewModal.updateCommentCount();
|
|
7544
|
+
}
|
|
7545
|
+
|
|
7546
|
+
/** Fetch one comment's publication after an edit. Best effort. */
|
|
7547
|
+
async refreshCommentPublication(commentId) {
|
|
7548
|
+
const reviewId = this.currentPR?.id;
|
|
7549
|
+
if (!reviewId || window.PAIR_REVIEW_LOCAL_MODE) return;
|
|
7550
|
+
try {
|
|
7551
|
+
const response = await fetch(`/api/reviews/${reviewId}/comments/${commentId}`);
|
|
7552
|
+
if (!response.ok) return;
|
|
7553
|
+
this.applyServerComment(await response.json());
|
|
7554
|
+
} catch (error) {
|
|
7555
|
+
console.warn('Could not refresh comment publication:', error);
|
|
7556
|
+
}
|
|
7557
|
+
}
|
|
7558
|
+
|
|
7559
|
+
/**
|
|
7560
|
+
* Update an edited, already-posted comment on the host in place. Never
|
|
7561
|
+
* creates a comment. On failure the comment stays "Edited since posted" and
|
|
7562
|
+
* the server's message is shown beside it.
|
|
7563
|
+
* @param {number|string} commentId
|
|
7564
|
+
* @returns {Promise<{ok: boolean, comment?: Object, error?: Object}>}
|
|
7565
|
+
*/
|
|
7566
|
+
async updatePostedCommentOnHost(commentId) {
|
|
7567
|
+
const PostedComment = window.PostedComment;
|
|
7568
|
+
const reviewId = this.currentPR?.id;
|
|
7569
|
+
if (!PostedComment || !reviewId) return { ok: false, error: { message: 'No review loaded' } };
|
|
7570
|
+
const id = Number(commentId);
|
|
7571
|
+
this._hostUpdatesInFlight = this._hostUpdatesInFlight || new Map();
|
|
7572
|
+
if (this._hostUpdatesInFlight.has(id)) return this._hostUpdatesInFlight.get(id);
|
|
7573
|
+
|
|
7574
|
+
const run = (async () => {
|
|
7575
|
+
PostedComment.setUpdateBusy(id, true);
|
|
7576
|
+
const result = await PostedComment.requestHostUpdate(reviewId, id);
|
|
7577
|
+
PostedComment.setUpdateError(id, result.ok ? null : result.error);
|
|
7578
|
+
const comment = result.ok ? result.comment
|
|
7579
|
+
: (this.userComments || []).find(c => c.id === id);
|
|
7580
|
+
// Re-rendering the note also clears the busy state
|
|
7581
|
+
if (comment) {
|
|
7582
|
+
if (result.ok) this.applyServerComment(comment);
|
|
7583
|
+
else PostedComment.findRenderedComments(id).forEach(el => PostedComment.syncEditedSincePosted(el, comment));
|
|
7584
|
+
} else {
|
|
7585
|
+
PostedComment.setUpdateBusy(id, false);
|
|
7586
|
+
}
|
|
7587
|
+
return result;
|
|
7588
|
+
})();
|
|
7589
|
+
this._hostUpdatesInFlight.set(id, run);
|
|
7590
|
+
try {
|
|
7591
|
+
return await run;
|
|
7592
|
+
} finally {
|
|
7593
|
+
this._hostUpdatesInFlight.delete(id);
|
|
7594
|
+
}
|
|
7595
|
+
}
|
|
7596
|
+
|
|
7489
7597
|
/** Comments the next submit will post: what "will be submitted" counts. */
|
|
7490
7598
|
getPendingCommentCount() {
|
|
7491
|
-
return (this.userComments || []).filter(
|
|
7599
|
+
return (this.userComments || []).filter(window.PostedComment.isPendingComment).length;
|
|
7492
7600
|
}
|
|
7493
7601
|
|
|
7494
7602
|
/**
|
|
@@ -7497,7 +7605,8 @@ class PRManager {
|
|
|
7497
7605
|
* Used only to decide whether a review has any comments at all.
|
|
7498
7606
|
*/
|
|
7499
7607
|
getSubmittableCommentCount() {
|
|
7500
|
-
return (this.userComments || []).filter(c => c
|
|
7608
|
+
return (this.userComments || []).filter(c => window.PostedComment.isPendingComment(c) ||
|
|
7609
|
+
(c.status === 'active' && window.PostedComment.publicationState(c) === 'draft')).length;
|
|
7501
7610
|
}
|
|
7502
7611
|
|
|
7503
7612
|
/**
|
|
@@ -8954,8 +9063,7 @@ class PRManager {
|
|
|
8954
9063
|
// comments targeting lines in these files find their DOM targets.
|
|
8955
9064
|
// loadUserComments() is idempotent (clears existing comment rows first).
|
|
8956
9065
|
if (newFilesRendered) {
|
|
8957
|
-
|
|
8958
|
-
await this.loadUserComments(includeDismissed);
|
|
9066
|
+
await this.loadUserComments();
|
|
8959
9067
|
}
|
|
8960
9068
|
} catch (error) {
|
|
8961
9069
|
console.error('Error loading context files:', error);
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// Copyright 2026 Tim Perkins (tjwp) | SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/**
|
|
3
|
+
* Shared per-provider timeout logic for the council config tabs.
|
|
4
|
+
*
|
|
5
|
+
* AdvancedConfigTab and VoiceCentricConfigTab both show a timeout dropdown and a
|
|
6
|
+
* clock icon per voice plus one for orchestration/consolidation. They kept
|
|
7
|
+
* separate copies of the same timeout methods, and the copies drifted apart
|
|
8
|
+
* (e.g. the _defaultConfig() provider-default gap). This mixin is the single
|
|
9
|
+
* copy.
|
|
10
|
+
*
|
|
11
|
+
* The tabs differ only in DOM shape, so each tab describes its own with a
|
|
12
|
+
* static TIMEOUT_DOM:
|
|
13
|
+
*
|
|
14
|
+
* static TIMEOUT_DOM = {
|
|
15
|
+
* panelId: 'tab-panel-advanced', // panel inside the modal
|
|
16
|
+
* voiceWrapperClass: 'participant-wrapper', // wraps one voice row
|
|
17
|
+
* voiceKeys: ['level', 'index'], // data-* attrs that identify a voice
|
|
18
|
+
* timeoutClass: 'adv-timeout', // per-voice timeout select
|
|
19
|
+
* orchestrationTimeoutId: 'adv-orchestration-timeout',
|
|
20
|
+
* orchestrationToggleId: 'adv-orchestration-timeout-toggle',
|
|
21
|
+
* orchestrationRowId: 'orchestration-voice',
|
|
22
|
+
* };
|
|
23
|
+
*
|
|
24
|
+
* A voice is addressed by a key object holding its voiceKeys, e.g.
|
|
25
|
+
* { level: '1', index: '0' } (Advanced) or { index: '0' } (Voice-centric).
|
|
26
|
+
*
|
|
27
|
+
* The host class must also define static DEFAULT_TIMEOUT and instance
|
|
28
|
+
* `providers` and `modal`.
|
|
29
|
+
*/
|
|
30
|
+
(function () {
|
|
31
|
+
/**
|
|
32
|
+
* Timeout to use after a voice's provider changes. A value still at the old
|
|
33
|
+
* provider's default follows the new default; a customised value is kept
|
|
34
|
+
* unless the new default is longer.
|
|
35
|
+
* @param {number} currentValue - Current timeout in ms
|
|
36
|
+
* @param {number|null} oldDefault - Previous provider's default, or null if unknown
|
|
37
|
+
* @param {number} newDefault - New provider's default
|
|
38
|
+
* @returns {number} Timeout in ms
|
|
39
|
+
*/
|
|
40
|
+
function resolveProviderSwitchTimeout(currentValue, oldDefault, newDefault) {
|
|
41
|
+
return (oldDefault !== null && currentValue !== oldDefault)
|
|
42
|
+
? Math.max(currentValue, newDefault)
|
|
43
|
+
: newDefault;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Attribute selector for a voice key, e.g. '[data-level="1"][data-index="0"]'.
|
|
48
|
+
* @param {string[]} voiceKeys
|
|
49
|
+
* @param {Object} key
|
|
50
|
+
* @returns {string}
|
|
51
|
+
*/
|
|
52
|
+
function voiceKeySelector(voiceKeys, key) {
|
|
53
|
+
return voiceKeys.map(k => `[data-${k}="${key[k]}"]`).join('');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const methods = {
|
|
57
|
+
/**
|
|
58
|
+
* Get the default timeout for a provider, falling back to the static DEFAULT_TIMEOUT.
|
|
59
|
+
* @param {string} providerId - Provider ID (e.g., 'pi', 'claude')
|
|
60
|
+
* @returns {number} Default timeout in ms
|
|
61
|
+
*/
|
|
62
|
+
_getProviderDefaultTimeout(providerId) {
|
|
63
|
+
const provider = this.providers[providerId];
|
|
64
|
+
return provider?.defaultTimeout ?? this.constructor.DEFAULT_TIMEOUT;
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Update the clock/timeout icon styling to indicate non-default timeout.
|
|
69
|
+
* @param {Element} panel - The council panel element
|
|
70
|
+
* @param {Object} key - Voice key, e.g. { level, index } or { index }
|
|
71
|
+
* @param {string} value - Current timeout value (as string of ms)
|
|
72
|
+
*/
|
|
73
|
+
_updateTimeoutIcon(panel, key, value) {
|
|
74
|
+
const dom = this.constructor.TIMEOUT_DOM;
|
|
75
|
+
const keySel = voiceKeySelector(dom.voiceKeys, key);
|
|
76
|
+
const wrapper = panel.querySelector(`.${dom.voiceWrapperClass}${keySel}`);
|
|
77
|
+
const iconBtn = wrapper?.querySelector(`.toggle-timeout-icon${keySel}`);
|
|
78
|
+
if (!iconBtn) return;
|
|
79
|
+
|
|
80
|
+
const providerId = wrapper?.querySelector('.voice-provider')?.value;
|
|
81
|
+
const defaultTimeout = this._getProviderDefaultTimeout(providerId);
|
|
82
|
+
const isNonDefault = parseInt(value, 10) !== defaultTimeout;
|
|
83
|
+
iconBtn.classList.toggle('has-custom-timeout', isNonDefault);
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
_updateOrchestrationTimeoutIcon(panel, value) {
|
|
87
|
+
const dom = this.constructor.TIMEOUT_DOM;
|
|
88
|
+
const iconBtn = panel.querySelector(`#${dom.orchestrationToggleId}`);
|
|
89
|
+
if (!iconBtn) return;
|
|
90
|
+
|
|
91
|
+
const orchRow = panel.querySelector(`#${dom.orchestrationRowId}`);
|
|
92
|
+
const providerId = orchRow?.querySelector('.voice-provider')?.value;
|
|
93
|
+
const defaultTimeout = this._getProviderDefaultTimeout(providerId);
|
|
94
|
+
const isNonDefault = parseInt(value, 10) !== defaultTimeout;
|
|
95
|
+
iconBtn.classList.toggle('has-custom-timeout', isNonDefault);
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* When a voice's provider changes, update its timeout to the new provider's default,
|
|
100
|
+
* preserving explicit user overrides via Math.max when the user had customized the value.
|
|
101
|
+
* @param {HTMLSelectElement} providerSelect - The provider dropdown that changed
|
|
102
|
+
*/
|
|
103
|
+
_applyProviderDefaultTimeout(providerSelect) {
|
|
104
|
+
const dom = this.constructor.TIMEOUT_DOM;
|
|
105
|
+
const panel = this.modal.querySelector(`#${dom.panelId}`);
|
|
106
|
+
if (!panel) return;
|
|
107
|
+
|
|
108
|
+
const providerId = providerSelect.value;
|
|
109
|
+
const newDefault = this._getProviderDefaultTimeout(providerId);
|
|
110
|
+
const oldProviderId = providerSelect.dataset.previousProvider;
|
|
111
|
+
const oldDefault = oldProviderId ? this._getProviderDefaultTimeout(oldProviderId) : null;
|
|
112
|
+
|
|
113
|
+
const isOrchestration = providerSelect.dataset.target === 'orchestration';
|
|
114
|
+
if (isOrchestration) {
|
|
115
|
+
const timeoutEl = panel.querySelector(`#${dom.orchestrationTimeoutId}`);
|
|
116
|
+
if (timeoutEl) {
|
|
117
|
+
const resolvedTimeout = resolveProviderSwitchTimeout(parseInt(timeoutEl.value, 10), oldDefault, newDefault);
|
|
118
|
+
timeoutEl.value = String(resolvedTimeout);
|
|
119
|
+
this._updateOrchestrationTimeoutIcon(panel, String(resolvedTimeout));
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
const key = {};
|
|
123
|
+
dom.voiceKeys.forEach(k => { key[k] = providerSelect.dataset[k]; });
|
|
124
|
+
const wrapper = providerSelect.closest(`.${dom.voiceWrapperClass}`);
|
|
125
|
+
const timeoutEl = wrapper?.querySelector(`.${dom.timeoutClass}`);
|
|
126
|
+
if (timeoutEl) {
|
|
127
|
+
const resolvedTimeout = resolveProviderSwitchTimeout(parseInt(timeoutEl.value, 10), oldDefault, newDefault);
|
|
128
|
+
timeoutEl.value = String(resolvedTimeout);
|
|
129
|
+
this._updateTimeoutIcon(panel, key, String(resolvedTimeout));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
providerSelect.dataset.previousProvider = providerId;
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Restore a voice's saved timeout into its (already mounted) timeout select.
|
|
138
|
+
* Shows the select when the saved value differs from the provider's default;
|
|
139
|
+
* with no saved value, applies the provider's default.
|
|
140
|
+
* @param {Element} panel - The council panel element
|
|
141
|
+
* @param {Object} key - Voice key, e.g. { level, index } or { index }
|
|
142
|
+
* @param {HTMLSelectElement|null} timeoutEl - The voice's timeout select
|
|
143
|
+
* @param {{provider: string, timeout?: number}} voice - Saved voice config
|
|
144
|
+
*/
|
|
145
|
+
_restoreVoiceTimeout(panel, key, timeoutEl, voice) {
|
|
146
|
+
const providerDefaultTimeout = this._getProviderDefaultTimeout(voice.provider);
|
|
147
|
+
if (timeoutEl && voice.timeout) {
|
|
148
|
+
timeoutEl.value = String(voice.timeout);
|
|
149
|
+
// Show the dropdown if non-default for this provider
|
|
150
|
+
if (voice.timeout !== providerDefaultTimeout) {
|
|
151
|
+
timeoutEl.style.display = '';
|
|
152
|
+
}
|
|
153
|
+
this._updateTimeoutIcon(panel, key, String(voice.timeout));
|
|
154
|
+
} else if (timeoutEl) {
|
|
155
|
+
// No saved timeout — apply the provider's default
|
|
156
|
+
timeoutEl.value = String(providerDefaultTimeout);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Restore the orchestration/consolidation timeout select and its icon.
|
|
162
|
+
* @param {Element} panel - The council panel element
|
|
163
|
+
* @param {{provider: string, timeout?: number}} orchestration - Saved orchestration config
|
|
164
|
+
*/
|
|
165
|
+
_restoreOrchestrationTimeout(panel, orchestration) {
|
|
166
|
+
const dom = this.constructor.TIMEOUT_DOM;
|
|
167
|
+
const orchTimeoutSelect = panel.querySelector(`#${dom.orchestrationTimeoutId}`);
|
|
168
|
+
const orchProviderDefaultTimeout = this._getProviderDefaultTimeout(orchestration.provider);
|
|
169
|
+
if (orchTimeoutSelect && orchestration.timeout) {
|
|
170
|
+
orchTimeoutSelect.value = String(orchestration.timeout);
|
|
171
|
+
// Show the dropdown if non-default for this provider
|
|
172
|
+
if (orchestration.timeout !== orchProviderDefaultTimeout) {
|
|
173
|
+
orchTimeoutSelect.style.display = '';
|
|
174
|
+
}
|
|
175
|
+
this._updateOrchestrationTimeoutIcon(panel, String(orchestration.timeout));
|
|
176
|
+
} else if (orchTimeoutSelect) {
|
|
177
|
+
// No saved timeout — apply the provider's default
|
|
178
|
+
orchTimeoutSelect.value = String(orchProviderDefaultTimeout);
|
|
179
|
+
this._updateOrchestrationTimeoutIcon(panel, String(orchProviderDefaultTimeout));
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Copy the shared timeout methods onto a tab class's prototype.
|
|
186
|
+
* @param {Function} TabClass - Class with static TIMEOUT_DOM and DEFAULT_TIMEOUT
|
|
187
|
+
*/
|
|
188
|
+
function mixInto(TabClass) {
|
|
189
|
+
Object.assign(TabClass.prototype, methods);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const CouncilTimeout = { resolveProviderSwitchTimeout, methods, mixInto };
|
|
193
|
+
|
|
194
|
+
if (typeof window !== 'undefined') {
|
|
195
|
+
window.CouncilTimeout = CouncilTimeout;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Support CommonJS require() in unit tests while keeping the browser IIFE
|
|
199
|
+
// behavior of assigning to window.
|
|
200
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
201
|
+
module.exports = CouncilTimeout;
|
|
202
|
+
}
|
|
203
|
+
})();
|