@in-the-loop-labs/pair-review 4.1.1 → 5.0.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 +81 -13
- package/package.json +6 -2
- 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/plugin-pair-loop/skills/loop/SKILL.md +17 -8
- package/public/css/ai-summary-modal.css +1 -1
- package/public/css/analysis-config.css +33 -49
- package/public/css/council-card.css +118 -0
- package/public/css/council-dropdown.css +164 -0
- package/public/css/pr.css +668 -393
- package/public/css/repo-settings.css +15 -305
- package/public/css/settings.css +1141 -0
- package/public/css/snippet-manager.css +233 -0
- package/public/index.html +40 -59
- package/public/js/components/AIPanel.js +82 -16
- package/public/js/components/ChatPanel.js +401 -5
- package/public/js/components/CouncilCard.js +202 -0
- package/public/js/components/CouncilDropdown.js +292 -0
- package/public/js/components/DiffOptionsDropdown.js +177 -4
- package/public/js/components/SnippetManager.js +463 -0
- package/public/js/index.js +7 -30
- package/public/js/local.js +20 -2
- package/public/js/modules/comment-manager.js +8 -1
- package/public/js/modules/comment-minimizer.js +249 -190
- package/public/js/modules/diff-renderer.js +16 -4
- package/public/js/modules/external-comment-manager.js +414 -48
- package/public/js/modules/file-comment-manager.js +28 -21
- package/public/js/modules/hunk-summary-renderer.js +155 -29
- package/public/js/modules/pierre-bridge.js +2513 -0
- package/public/js/modules/pierre-context.js +345 -0
- package/public/js/modules/suggestion-manager.js +176 -20
- package/public/js/modules/tour-renderer.js +400 -184
- package/public/js/pr.js +1614 -158
- package/public/js/repo-settings.js +60 -284
- package/public/js/settings.js +1086 -0
- package/public/js/theme-bootstrap.js +40 -0
- package/public/js/theme.js +247 -0
- package/public/js/utils/provider-model.js +3 -3
- package/public/js/utils/suggestion-ui.js +157 -8
- package/public/local.html +20 -31
- package/public/pr.html +14 -23
- package/public/repo-settings.html +24 -14
- package/public/settings.html +138 -0
- package/public/setup.html +8 -13
- package/src/chat/api-reference.js +9 -5
- package/src/chat/prompt-builder.js +8 -1
- package/src/config.js +15 -6
- package/src/database.js +307 -14
- package/src/external/github-adapter.js +39 -5
- package/src/headless/delegate.js +682 -0
- package/src/local-review.js +10 -10
- package/src/local-scope.js +9 -0
- package/src/main.js +276 -157
- package/src/mcp-stdio.js +24 -1
- package/src/review-config.js +93 -25
- package/src/routes/chat.js +2 -2
- package/src/routes/config.js +12 -10
- package/src/routes/external-comments.js +5 -1
- package/src/routes/local.js +2 -4
- package/src/routes/mcp.js +18 -13
- package/src/routes/reviews.js +223 -4
- package/src/routes/settings.js +252 -0
- package/src/routes/setup.js +80 -1
- package/src/routes/shared.js +31 -29
- package/src/routes/snippets.js +154 -0
- package/src/routes/stack-analysis.js +17 -14
- package/src/server.js +86 -18
- package/src/settings/global-settings-service.js +472 -0
- package/src/settings/registry.js +624 -0
- package/src/utils/db-identity.js +44 -0
|
@@ -2,16 +2,29 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* CommentMinimizer - Manages "minimize comments" mode for the diff view.
|
|
4
4
|
*
|
|
5
|
-
* When active, all inline comment
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* When active, all inline comment cards (.user-comment-row), AI suggestion
|
|
6
|
+
* cards (.ai-suggestion) and external review threads (.external-comment-row)
|
|
7
|
+
* anchored to diff lines are hidden via CSS. A single small clickable
|
|
8
|
+
* indicator is injected for each diff line that has hidden cards, showing a
|
|
9
|
+
* person icon (user comments), AI-comment icon (adopted suggestions),
|
|
10
|
+
* sparkles icon (AI suggestions) or chat-bubble icon (external comments),
|
|
11
|
+
* with a count badge when a line holds more than one card.
|
|
10
12
|
*
|
|
11
13
|
* File-level comments (.file-comment-card inside .file-comments-zone) are also
|
|
12
14
|
* hidden, with an indicator button injected into the file header bar.
|
|
13
15
|
*
|
|
14
|
-
* Clicking an indicator toggles visibility of that line's or file's
|
|
16
|
+
* Clicking an indicator toggles visibility of that line's or file's cards.
|
|
17
|
+
*
|
|
18
|
+
* ── @pierre/diffs rendering ──────────────────────────────────────────────
|
|
19
|
+
* Diff lines are shadow-DOM elements owned by the vendor renderer; annotation
|
|
20
|
+
* cards live in the LIGHT DOM, each wrapped by the vendor in a
|
|
21
|
+
* `<div data-annotation-slot slot="annotation-{side}-{lineNumber}">` that is a
|
|
22
|
+
* child of the file's `<diffs-container>` host and projected into the matching
|
|
23
|
+
* shadow annotation cell. All cards anchored to the same line+side share the
|
|
24
|
+
* same `slot` value, so we group by `{fileName}\0{slot}` — a STABLE string key
|
|
25
|
+
* that survives the vendor's card-recreating rerenders (element identity does
|
|
26
|
+
* NOT survive them). The line-level indicator is injected into the first
|
|
27
|
+
* wrapper of each group (light DOM, so page CSS reaches it).
|
|
15
28
|
*/
|
|
16
29
|
|
|
17
30
|
class CommentMinimizer {
|
|
@@ -29,10 +42,18 @@ class CommentMinimizer {
|
|
|
29
42
|
|
|
30
43
|
constructor() {
|
|
31
44
|
this._active = false;
|
|
32
|
-
//
|
|
45
|
+
// Diff lines the user has expanded, keyed by the STABLE string
|
|
46
|
+
// `${fileName}\0${slot}` (see class doc). NOT element references — the
|
|
47
|
+
// vendor recreates annotation wrappers on every rerender.
|
|
33
48
|
this._expandedLines = new Set();
|
|
34
|
-
//
|
|
49
|
+
// Files whose file-level zone has been expanded (Set of zone elements —
|
|
50
|
+
// zones are pr.js light DOM, not vendor-managed, so they persist).
|
|
35
51
|
this._expandedFiles = new Set();
|
|
52
|
+
// MutationObserver that re-injects indicators after vendor rerenders
|
|
53
|
+
// (diffStyle switch, hunk expansion, worker-highlight streaming, lazy file
|
|
54
|
+
// render) that are NOT followed by an explicit refreshIndicators() call.
|
|
55
|
+
this._observer = null;
|
|
56
|
+
this._refreshScheduled = false;
|
|
36
57
|
}
|
|
37
58
|
|
|
38
59
|
/** @returns {boolean} Whether minimize mode is active */
|
|
@@ -55,7 +76,9 @@ class CommentMinimizer {
|
|
|
55
76
|
if (minimized) {
|
|
56
77
|
diffContainer.classList.add('comments-minimized');
|
|
57
78
|
this.refreshIndicators();
|
|
79
|
+
this._startObserving();
|
|
58
80
|
} else {
|
|
81
|
+
this._stopObserving();
|
|
59
82
|
diffContainer.classList.remove('comments-minimized');
|
|
60
83
|
this._removeAllIndicators();
|
|
61
84
|
// Remove any per-line expansion overrides
|
|
@@ -66,118 +89,163 @@ class CommentMinimizer {
|
|
|
66
89
|
}
|
|
67
90
|
|
|
68
91
|
/**
|
|
69
|
-
* Rebuild all indicator buttons on diff lines.
|
|
92
|
+
* Rebuild all indicator buttons on diff lines and file headers.
|
|
70
93
|
* Call this after comments or suggestions are added/removed/re-rendered.
|
|
94
|
+
* Idempotent: starts by removing every existing indicator.
|
|
71
95
|
*/
|
|
72
96
|
refreshIndicators() {
|
|
73
97
|
if (!this._active) return;
|
|
74
98
|
|
|
75
|
-
|
|
99
|
+
// The vendor recreates annotation wrappers as we inject indicators; pause
|
|
100
|
+
// the observer so our own DOM writes don't re-trigger a refresh loop.
|
|
101
|
+
this._stopObserving();
|
|
102
|
+
try {
|
|
103
|
+
this._removeAllIndicators();
|
|
76
104
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
105
|
+
// Line-level: group the vendor annotation wrappers by file + slot.
|
|
106
|
+
for (const group of this._buildLineGroups().values()) {
|
|
107
|
+
this._injectLineIndicator(group);
|
|
108
|
+
}
|
|
81
109
|
|
|
82
|
-
|
|
83
|
-
|
|
110
|
+
// File-level indicators (pr.js light DOM — unchanged path).
|
|
111
|
+
this._refreshFileIndicators();
|
|
112
|
+
} finally {
|
|
113
|
+
if (this._active) this._startObserving();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Build a map of line-level groups keyed by `${fileName}\0${slot}`.
|
|
119
|
+
* Each group aggregates the hidden cards anchored to one line+side and keeps
|
|
120
|
+
* references to their vendor wrappers (`[data-annotation-slot]`).
|
|
121
|
+
* @returns {Map<string, {key: string, wrappers: HTMLElement[], info: Object}>}
|
|
122
|
+
* @private
|
|
123
|
+
*/
|
|
124
|
+
_buildLineGroups() {
|
|
125
|
+
const groups = new Map();
|
|
84
126
|
const newEntry = () => ({
|
|
85
127
|
hasUser: false, hasAI: false, hasAdopted: false, hasExternal: false,
|
|
86
128
|
userCount: 0, aiCount: 0, adoptedCount: 0, externalCount: 0
|
|
87
129
|
});
|
|
88
130
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (row.querySelector('.adopted-comment')) {
|
|
94
|
-
entry.hasAdopted = true;
|
|
95
|
-
entry.adoptedCount++;
|
|
96
|
-
} else {
|
|
97
|
-
entry.hasUser = true;
|
|
98
|
-
entry.userCount++;
|
|
99
|
-
}
|
|
100
|
-
lineMap.set(diffRow, entry);
|
|
101
|
-
}
|
|
131
|
+
const wrappers = document.querySelectorAll('#diff-container [data-annotation-slot]');
|
|
132
|
+
for (const wrapper of wrappers) {
|
|
133
|
+
const card = this._cardOf(wrapper);
|
|
134
|
+
if (!card) continue;
|
|
102
135
|
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
136
|
+
const isComment = card.classList.contains('user-comment-row');
|
|
137
|
+
const isSuggestion = card.classList.contains('ai-suggestion');
|
|
138
|
+
const isExternal = card.classList.contains('external-comment-row');
|
|
139
|
+
// Skip comment forms, tour stops, hunk summaries — those stay visible.
|
|
140
|
+
if (!isComment && !isSuggestion && !isExternal) continue;
|
|
141
|
+
|
|
142
|
+
const key = this._lineKeyFor(wrapper);
|
|
143
|
+
if (!key) continue;
|
|
144
|
+
|
|
145
|
+
let group = groups.get(key);
|
|
146
|
+
if (!group) {
|
|
147
|
+
group = { key, wrappers: [], info: newEntry() };
|
|
148
|
+
groups.set(key, group);
|
|
115
149
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
150
|
+
group.wrappers.push(wrapper);
|
|
151
|
+
const info = group.info;
|
|
152
|
+
|
|
153
|
+
if (isComment) {
|
|
154
|
+
// Adopted AI suggestions render with an inner `.adopted-comment` card.
|
|
155
|
+
if (card.querySelector('.adopted-comment')) {
|
|
156
|
+
info.hasAdopted = true;
|
|
157
|
+
info.adoptedCount++;
|
|
158
|
+
} else {
|
|
159
|
+
info.hasUser = true;
|
|
160
|
+
info.userCount++;
|
|
161
|
+
}
|
|
162
|
+
} else if (isSuggestion) {
|
|
163
|
+
// A suggestion hidden for adoption is already represented by its
|
|
164
|
+
// adopted comment card — don't double-count it. The flag is a string:
|
|
165
|
+
// 'true' when adopted, and suggestion-ui.js writes the literal 'false'
|
|
166
|
+
// on runtime restore, so compare against 'true' (not truthiness) or a
|
|
167
|
+
// restored suggestion would be wrongly dropped from the count.
|
|
168
|
+
if (card.dataset?.hiddenForAdoption !== 'true') {
|
|
169
|
+
info.hasAI = true;
|
|
170
|
+
info.aiCount++;
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
// External thread: count root + replies so the badge matches the
|
|
174
|
+
// total the thread card itself shows.
|
|
175
|
+
const bubbles = card.querySelectorAll('.external-comment');
|
|
176
|
+
info.hasExternal = true;
|
|
177
|
+
info.externalCount += (bubbles.length || 1);
|
|
119
178
|
}
|
|
120
|
-
lineMap.set(diffRow, entry);
|
|
121
179
|
}
|
|
122
180
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (!diffRow) continue;
|
|
126
|
-
const entry = lineMap.get(diffRow) || newEntry();
|
|
127
|
-
// Count root + replies — each .external-comment is one bubble in the
|
|
128
|
-
// thread card and the reviewer should see the same total here that
|
|
129
|
-
// the thread itself shows.
|
|
130
|
-
const bubbles = row.querySelectorAll('.external-comment');
|
|
131
|
-
const bubbleCount = bubbles.length || 1;
|
|
132
|
-
entry.hasExternal = true;
|
|
133
|
-
entry.externalCount += bubbleCount;
|
|
134
|
-
lineMap.set(diffRow, entry);
|
|
135
|
-
}
|
|
181
|
+
return groups;
|
|
182
|
+
}
|
|
136
183
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
184
|
+
/**
|
|
185
|
+
* The annotation card element inside a vendor `[data-annotation-slot]`
|
|
186
|
+
* wrapper (the element returned by PierreBridge's renderAnnotation).
|
|
187
|
+
* @param {HTMLElement} wrapper
|
|
188
|
+
* @returns {HTMLElement|null}
|
|
189
|
+
* @private
|
|
190
|
+
*/
|
|
191
|
+
_cardOf(wrapper) {
|
|
192
|
+
return wrapper.firstElementChild || null;
|
|
193
|
+
}
|
|
141
194
|
|
|
142
|
-
|
|
143
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Stable grouping key for a vendor annotation wrapper: the owning file plus
|
|
197
|
+
* the vendor slot name (`annotation-{side}-{lineNumber}`). Wrappers on the
|
|
198
|
+
* same line+side share a slot, so they share a key.
|
|
199
|
+
* @param {HTMLElement} wrapper
|
|
200
|
+
* @returns {string|null}
|
|
201
|
+
* @private
|
|
202
|
+
*/
|
|
203
|
+
_lineKeyFor(wrapper) {
|
|
204
|
+
const slot = wrapper.getAttribute('slot');
|
|
205
|
+
if (!slot) return null;
|
|
206
|
+
const fileWrapper = wrapper.closest('.d2h-file-wrapper');
|
|
207
|
+
const file = fileWrapper?.dataset?.fileName || '';
|
|
208
|
+
return `${file}\0${slot}`;
|
|
144
209
|
}
|
|
145
210
|
|
|
146
211
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* @
|
|
151
|
-
* @returns {HTMLElement|null}
|
|
212
|
+
* All vendor annotation wrappers that share a group key (a line+side).
|
|
213
|
+
* @param {string} key
|
|
214
|
+
* @returns {HTMLElement[]}
|
|
215
|
+
* @private
|
|
152
216
|
*/
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (
|
|
157
|
-
!prev.classList.contains('user-comment-row') &&
|
|
158
|
-
!prev.classList.contains('ai-suggestion-row') &&
|
|
159
|
-
!prev.classList.contains('external-comment-row') &&
|
|
160
|
-
!prev.classList.contains('comment-form-row') &&
|
|
161
|
-
!prev.classList.contains('context-expand-row')
|
|
162
|
-
) {
|
|
163
|
-
return prev;
|
|
164
|
-
}
|
|
165
|
-
prev = prev.previousElementSibling;
|
|
217
|
+
_wrappersForKey(key) {
|
|
218
|
+
const out = [];
|
|
219
|
+
for (const wrapper of document.querySelectorAll('#diff-container [data-annotation-slot]')) {
|
|
220
|
+
if (this._lineKeyFor(wrapper) === key) out.push(wrapper);
|
|
166
221
|
}
|
|
167
|
-
return
|
|
222
|
+
return out;
|
|
168
223
|
}
|
|
169
224
|
|
|
170
225
|
/**
|
|
171
|
-
* Inject
|
|
172
|
-
*
|
|
173
|
-
* @param {
|
|
226
|
+
* Inject a single indicator button for a line group into the first wrapper,
|
|
227
|
+
* and sync the group's expanded/collapsed card visibility.
|
|
228
|
+
* @param {{key: string, wrappers: HTMLElement[], info: Object}} group
|
|
229
|
+
* @private
|
|
174
230
|
*/
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
if (!
|
|
231
|
+
_injectLineIndicator(group) {
|
|
232
|
+
const first = group.wrappers[0];
|
|
233
|
+
if (!first) return;
|
|
234
|
+
|
|
235
|
+
// Nothing to represent — e.g. the line's only card is a suggestion hidden
|
|
236
|
+
// for adoption (represented by its adopted comment elsewhere). Injecting
|
|
237
|
+
// here would produce an empty button with no icon, count, or title.
|
|
238
|
+
const info = group.info;
|
|
239
|
+
const total = info.userCount + info.adoptedCount + info.aiCount + info.externalCount;
|
|
240
|
+
if (total === 0) return;
|
|
178
241
|
|
|
179
|
-
//
|
|
180
|
-
|
|
242
|
+
// Sync card visibility to the persisted expanded state (survives rerenders
|
|
243
|
+
// because the state is keyed by the stable group key).
|
|
244
|
+
const expanded = this._expandedLines.has(group.key);
|
|
245
|
+
this._applyExpanded(group.wrappers, expanded);
|
|
246
|
+
|
|
247
|
+
// Don't double-inject.
|
|
248
|
+
if (first.querySelector(':scope > .comment-indicator')) return;
|
|
181
249
|
|
|
182
250
|
const btn = document.createElement('button');
|
|
183
251
|
btn.className = 'comment-indicator';
|
|
@@ -202,7 +270,6 @@ class CommentMinimizer {
|
|
|
202
270
|
icons.push(`<span class="indicator-icon indicator-external" title="${info.externalCount} external comment${info.externalCount !== 1 ? 's' : ''}">${CommentMinimizer.EXTERNAL_ICON}</span>`);
|
|
203
271
|
}
|
|
204
272
|
|
|
205
|
-
const total = info.userCount + info.adoptedCount + info.aiCount + info.externalCount;
|
|
206
273
|
const countBadge = total > 1 ? `<span class="indicator-count">${total}</span>` : '';
|
|
207
274
|
|
|
208
275
|
btn.innerHTML = icons.join('') + countBadge;
|
|
@@ -214,118 +281,81 @@ class CommentMinimizer {
|
|
|
214
281
|
if (info.externalCount) totalLabel.push(`${info.externalCount} external comment${info.externalCount !== 1 ? 's' : ''}`);
|
|
215
282
|
btn.title = totalLabel.join(', ');
|
|
216
283
|
|
|
217
|
-
|
|
218
|
-
// `.comment-expanded` to the (possibly rebuilt) comment rows is
|
|
219
|
-
// important: when an external-comment refresh tears down and rebuilds
|
|
220
|
-
// `.external-comment-row` elements, the new rows have no expanded
|
|
221
|
-
// class even though the indicator button is still marked expanded.
|
|
222
|
-
// Without this step the indicator says "open" but the rows stay
|
|
223
|
-
// hidden via the `.comments-minimized` display: none rule.
|
|
224
|
-
if (this._expandedLines.has(diffRow)) {
|
|
284
|
+
if (expanded) {
|
|
225
285
|
btn.classList.add('expanded');
|
|
226
|
-
this._getCommentRowsFor(diffRow).forEach(row => row.classList.add('comment-expanded'));
|
|
227
286
|
}
|
|
228
287
|
|
|
229
|
-
// Click handler
|
|
288
|
+
// Click handler toggles this line's cards. Closes over the current
|
|
289
|
+
// wrappers; a rerender replaces both wrappers and handler together.
|
|
230
290
|
btn.addEventListener('click', (e) => {
|
|
231
291
|
e.stopPropagation();
|
|
232
292
|
e.preventDefault();
|
|
233
|
-
this._toggleLineComments(
|
|
293
|
+
this._toggleLineComments(group.key, btn);
|
|
234
294
|
});
|
|
235
295
|
|
|
236
|
-
|
|
237
|
-
codeCell.style.position = 'relative';
|
|
238
|
-
codeCell.appendChild(btn);
|
|
296
|
+
first.appendChild(btn);
|
|
239
297
|
}
|
|
240
298
|
|
|
241
299
|
/**
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
* @param {HTMLElement}
|
|
300
|
+
* Show or hide the cards of a line group by toggling `.comment-expanded` on
|
|
301
|
+
* each wrapper's card element.
|
|
302
|
+
* @param {HTMLElement[]} wrappers
|
|
303
|
+
* @param {boolean} expanded
|
|
304
|
+
* @private
|
|
245
305
|
*/
|
|
246
|
-
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
// Collapse: remove .comment-expanded from this line's rows
|
|
251
|
-
this._expandedLines.delete(diffRow);
|
|
252
|
-
btn.classList.remove('expanded');
|
|
253
|
-
this._getCommentRowsFor(diffRow).forEach(row => row.classList.remove('comment-expanded'));
|
|
254
|
-
} else {
|
|
255
|
-
// Expand: add .comment-expanded to this line's rows
|
|
256
|
-
this._expandedLines.add(diffRow);
|
|
257
|
-
btn.classList.add('expanded');
|
|
258
|
-
this._getCommentRowsFor(diffRow).forEach(row => row.classList.add('comment-expanded'));
|
|
306
|
+
_applyExpanded(wrappers, expanded) {
|
|
307
|
+
for (const wrapper of wrappers) {
|
|
308
|
+
const card = this._cardOf(wrapper);
|
|
309
|
+
if (card) card.classList.toggle('comment-expanded', expanded);
|
|
259
310
|
}
|
|
260
311
|
}
|
|
261
312
|
|
|
262
313
|
/**
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
* @param {HTMLElement}
|
|
266
|
-
* @
|
|
314
|
+
* Toggle visibility of the cards for one line group.
|
|
315
|
+
* @param {string} key - The stable group key
|
|
316
|
+
* @param {HTMLElement} btn - The indicator button
|
|
317
|
+
* @private
|
|
267
318
|
*/
|
|
268
|
-
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
)
|
|
277
|
-
|
|
278
|
-
} else if (
|
|
279
|
-
next.classList.contains('comment-form-row') ||
|
|
280
|
-
next.classList.contains('context-expand-row')
|
|
281
|
-
) {
|
|
282
|
-
// Skip these but keep looking
|
|
283
|
-
next = next.nextElementSibling;
|
|
284
|
-
continue;
|
|
285
|
-
} else {
|
|
286
|
-
// Hit another diff line — stop
|
|
287
|
-
break;
|
|
288
|
-
}
|
|
289
|
-
next = next.nextElementSibling;
|
|
319
|
+
_toggleLineComments(key, btn) {
|
|
320
|
+
const wrappers = this._wrappersForKey(key);
|
|
321
|
+
if (this._expandedLines.has(key)) {
|
|
322
|
+
this._expandedLines.delete(key);
|
|
323
|
+
btn.classList.remove('expanded');
|
|
324
|
+
this._applyExpanded(wrappers, false);
|
|
325
|
+
} else {
|
|
326
|
+
this._expandedLines.add(key);
|
|
327
|
+
btn.classList.add('expanded');
|
|
328
|
+
this._applyExpanded(wrappers, true);
|
|
290
329
|
}
|
|
291
|
-
return rows;
|
|
292
330
|
}
|
|
293
331
|
|
|
294
332
|
/**
|
|
295
|
-
* Find the
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
* @
|
|
333
|
+
* Find the vendor annotation wrapper (`[data-annotation-slot]`) that holds a
|
|
334
|
+
* given card element. Used by navigation callers as a stable scroll anchor;
|
|
335
|
+
* returns null for elements not slotted onto a diff line (callers fall back
|
|
336
|
+
* to the element itself).
|
|
337
|
+
* @param {HTMLElement} element - A card element (or a child of one)
|
|
338
|
+
* @returns {HTMLElement|null}
|
|
300
339
|
*/
|
|
301
340
|
findDiffRowFor(element) {
|
|
302
|
-
|
|
303
|
-
if (
|
|
304
|
-
!commentRow.classList.contains('user-comment-row') &&
|
|
305
|
-
!commentRow.classList.contains('ai-suggestion-row') &&
|
|
306
|
-
!commentRow.classList.contains('external-comment-row')
|
|
307
|
-
) {
|
|
308
|
-
return null;
|
|
309
|
-
}
|
|
310
|
-
return this._findDiffRowFor(commentRow);
|
|
341
|
+
return element?.closest?.('[data-annotation-slot]') || null;
|
|
311
342
|
}
|
|
312
343
|
|
|
313
344
|
// TODO: expose via API route so chat can programmatically expand findings when discussing them
|
|
314
345
|
/**
|
|
315
|
-
* Expand comments for a given element so it becomes visible when
|
|
316
|
-
* Call this before scrolling to a
|
|
317
|
-
* @param {HTMLElement} element - The target
|
|
346
|
+
* Expand the comments for a given element so it becomes visible when
|
|
347
|
+
* minimized. Call this before scrolling to a card that may be hidden.
|
|
348
|
+
* @param {HTMLElement} element - The target card element (or a child of one)
|
|
318
349
|
*/
|
|
319
350
|
expandForElement(element) {
|
|
320
|
-
if (!this._active) return;
|
|
351
|
+
if (!this._active || !element) return;
|
|
321
352
|
|
|
322
|
-
//
|
|
353
|
+
// File-level comment inside a file-comments-zone.
|
|
323
354
|
const zone = element.closest('.file-comments-zone');
|
|
324
355
|
if (zone) {
|
|
325
356
|
if (this._expandedFiles.has(zone)) return; // already expanded
|
|
326
357
|
this._expandedFiles.add(zone);
|
|
327
358
|
zone.classList.add('file-comments-expanded');
|
|
328
|
-
// Update the file-header indicator button
|
|
329
359
|
const wrapper = zone.closest('.d2h-file-wrapper');
|
|
330
360
|
const btn = wrapper?.querySelector('.d2h-file-header .file-comment-indicator');
|
|
331
361
|
if (btn) {
|
|
@@ -334,29 +364,18 @@ class CommentMinimizer {
|
|
|
334
364
|
return;
|
|
335
365
|
}
|
|
336
366
|
|
|
337
|
-
// Line-level:
|
|
338
|
-
const
|
|
339
|
-
if (
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
!commentRow.classList.contains('external-comment-row')
|
|
343
|
-
) {
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// Find the parent diff row for this comment row
|
|
348
|
-
const diffRow = this._findDiffRowFor(commentRow);
|
|
349
|
-
if (!diffRow) return;
|
|
367
|
+
// Line-level: resolve the containing vendor annotation wrapper.
|
|
368
|
+
const annotationWrapper = element.closest('[data-annotation-slot]');
|
|
369
|
+
if (!annotationWrapper) return;
|
|
370
|
+
const key = this._lineKeyFor(annotationWrapper);
|
|
371
|
+
if (!key) return;
|
|
350
372
|
|
|
351
|
-
|
|
352
|
-
|
|
373
|
+
this._expandedLines.add(key);
|
|
374
|
+
const wrappers = this._wrappersForKey(key);
|
|
375
|
+
this._applyExpanded(wrappers, true);
|
|
353
376
|
|
|
354
|
-
//
|
|
355
|
-
|
|
356
|
-
this._getCommentRowsFor(diffRow).forEach(row => row.classList.add('comment-expanded'));
|
|
357
|
-
|
|
358
|
-
// Update the indicator button's expanded state
|
|
359
|
-
const btn = diffRow.querySelector('.d2h-code-line-ctn .comment-indicator');
|
|
377
|
+
// Mark the indicator (injected into the group's first wrapper) as expanded.
|
|
378
|
+
const btn = wrappers[0]?.querySelector(':scope > .comment-indicator');
|
|
360
379
|
if (btn) {
|
|
361
380
|
btn.classList.add('expanded');
|
|
362
381
|
}
|
|
@@ -487,6 +506,46 @@ class CommentMinimizer {
|
|
|
487
506
|
document.querySelectorAll('.comment-indicator').forEach(btn => btn.remove());
|
|
488
507
|
document.querySelectorAll('.file-comment-indicator').forEach(btn => btn.remove());
|
|
489
508
|
}
|
|
509
|
+
|
|
510
|
+
// ---------------------------------------------------------------------------
|
|
511
|
+
// Rerender resilience
|
|
512
|
+
// ---------------------------------------------------------------------------
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Observe the diff container for the vendor's card-recreating rerenders and
|
|
516
|
+
* re-inject indicators. Debounced via rAF and idempotent (refreshIndicators
|
|
517
|
+
* clears first). Paused during our own refresh so injecting indicators does
|
|
518
|
+
* not loop. No-op without a DOM (tests may run headless without MutationObserver).
|
|
519
|
+
* @private
|
|
520
|
+
*/
|
|
521
|
+
_startObserving() {
|
|
522
|
+
if (this._observer || typeof MutationObserver === 'undefined') return;
|
|
523
|
+
const container = document.getElementById('diff-container');
|
|
524
|
+
if (!container) return;
|
|
525
|
+
this._observer = new MutationObserver(() => this._onDomMutation());
|
|
526
|
+
this._observer.observe(container, { childList: true, subtree: true });
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** Stop observing the diff container. @private */
|
|
530
|
+
_stopObserving() {
|
|
531
|
+
if (this._observer) {
|
|
532
|
+
this._observer.disconnect();
|
|
533
|
+
this._observer = null;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/** Debounced reaction to diff-container mutations. @private */
|
|
538
|
+
_onDomMutation() {
|
|
539
|
+
if (!this._active || this._refreshScheduled) return;
|
|
540
|
+
this._refreshScheduled = true;
|
|
541
|
+
const raf = (typeof requestAnimationFrame === 'function')
|
|
542
|
+
? requestAnimationFrame
|
|
543
|
+
: (fn) => setTimeout(fn, 16);
|
|
544
|
+
raf(() => {
|
|
545
|
+
this._refreshScheduled = false;
|
|
546
|
+
if (this._active) this.refreshIndicators();
|
|
547
|
+
});
|
|
548
|
+
}
|
|
490
549
|
}
|
|
491
550
|
|
|
492
551
|
window.CommentMinimizer = CommentMinimizer;
|
|
@@ -273,7 +273,14 @@ class DiffRenderer {
|
|
|
273
273
|
: filePath;
|
|
274
274
|
|
|
275
275
|
try {
|
|
276
|
-
|
|
276
|
+
// Scope to `.d2h-file-wrapper` so a nested `.file-comments-zone` (which
|
|
277
|
+
// also carries data-file-name) can never be returned, and skip context
|
|
278
|
+
// entries — those are targeted explicitly via `.context-file` selectors
|
|
279
|
+
// (see PRManager.findContextFileWrapper). No unguarded fallback here:
|
|
280
|
+
// findFileElement's pathsMatch loop handles rename syntax and
|
|
281
|
+
// context-only files, and prefers the diff wrapper itself.
|
|
282
|
+
const selector = `.d2h-file-wrapper[${attribute}="${escapedValue}"]:not(.context-file)`;
|
|
283
|
+
return document.querySelector(selector);
|
|
277
284
|
} catch {
|
|
278
285
|
return null;
|
|
279
286
|
}
|
|
@@ -798,17 +805,22 @@ class DiffRenderer {
|
|
|
798
805
|
}
|
|
799
806
|
|
|
800
807
|
// Fall back to normalized iteration so special characters, rename syntax,
|
|
801
|
-
// and formatted variants still resolve to the rendered wrapper.
|
|
808
|
+
// and formatted variants still resolve to the rendered wrapper. Prefer a
|
|
809
|
+
// diff wrapper over a context entry that shares the file path.
|
|
802
810
|
const allFileWrappers = document.querySelectorAll('.d2h-file-wrapper');
|
|
811
|
+
let contextMatch = null;
|
|
803
812
|
for (const wrapper of allFileWrappers) {
|
|
804
813
|
const fileName = wrapper.dataset.fileName;
|
|
805
814
|
const filePathAttr = wrapper.dataset.filePath;
|
|
806
815
|
if (DiffRenderer.pathsMatch(fileName, filePath) || DiffRenderer.pathsMatch(filePathAttr, filePath)) {
|
|
807
|
-
|
|
816
|
+
if (!wrapper.classList?.contains('context-file')) {
|
|
817
|
+
return wrapper;
|
|
818
|
+
}
|
|
819
|
+
if (!contextMatch) contextMatch = wrapper;
|
|
808
820
|
}
|
|
809
821
|
}
|
|
810
822
|
|
|
811
|
-
return
|
|
823
|
+
return contextMatch;
|
|
812
824
|
}
|
|
813
825
|
}
|
|
814
826
|
|