@in-the-loop-labs/pair-review 4.1.1 → 5.0.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 (70) hide show
  1. package/README.md +81 -13
  2. package/package.json +6 -2
  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/plugin-pair-loop/skills/loop/SKILL.md +17 -8
  7. package/public/css/ai-summary-modal.css +1 -1
  8. package/public/css/analysis-config.css +33 -49
  9. package/public/css/council-card.css +118 -0
  10. package/public/css/council-dropdown.css +164 -0
  11. package/public/css/pr.css +666 -394
  12. package/public/css/repo-settings.css +15 -305
  13. package/public/css/settings.css +1141 -0
  14. package/public/css/snippet-manager.css +233 -0
  15. package/public/index.html +40 -59
  16. package/public/js/components/AIPanel.js +82 -16
  17. package/public/js/components/ChatPanel.js +401 -5
  18. package/public/js/components/CouncilCard.js +202 -0
  19. package/public/js/components/CouncilDropdown.js +292 -0
  20. package/public/js/components/DiffOptionsDropdown.js +177 -4
  21. package/public/js/components/SnippetManager.js +463 -0
  22. package/public/js/index.js +7 -30
  23. package/public/js/local.js +20 -2
  24. package/public/js/modules/comment-manager.js +8 -1
  25. package/public/js/modules/comment-minimizer.js +249 -190
  26. package/public/js/modules/external-comment-manager.js +414 -48
  27. package/public/js/modules/file-comment-manager.js +28 -21
  28. package/public/js/modules/hunk-summary-renderer.js +155 -29
  29. package/public/js/modules/pierre-bridge.js +2513 -0
  30. package/public/js/modules/pierre-context.js +345 -0
  31. package/public/js/modules/suggestion-manager.js +176 -20
  32. package/public/js/modules/tour-renderer.js +400 -184
  33. package/public/js/pr.js +1434 -150
  34. package/public/js/repo-settings.js +60 -284
  35. package/public/js/settings.js +1086 -0
  36. package/public/js/theme-bootstrap.js +40 -0
  37. package/public/js/theme.js +247 -0
  38. package/public/js/utils/provider-model.js +3 -3
  39. package/public/js/utils/suggestion-ui.js +157 -8
  40. package/public/local.html +20 -31
  41. package/public/pr.html +14 -23
  42. package/public/repo-settings.html +24 -14
  43. package/public/settings.html +138 -0
  44. package/public/setup.html +8 -13
  45. package/src/chat/api-reference.js +9 -5
  46. package/src/chat/prompt-builder.js +8 -1
  47. package/src/config.js +15 -6
  48. package/src/database.js +307 -14
  49. package/src/external/github-adapter.js +39 -5
  50. package/src/headless/delegate.js +682 -0
  51. package/src/local-review.js +10 -10
  52. package/src/local-scope.js +9 -0
  53. package/src/main.js +276 -157
  54. package/src/mcp-stdio.js +24 -1
  55. package/src/review-config.js +93 -25
  56. package/src/routes/chat.js +2 -2
  57. package/src/routes/config.js +12 -10
  58. package/src/routes/external-comments.js +5 -1
  59. package/src/routes/local.js +2 -4
  60. package/src/routes/mcp.js +18 -13
  61. package/src/routes/reviews.js +223 -4
  62. package/src/routes/settings.js +252 -0
  63. package/src/routes/setup.js +80 -1
  64. package/src/routes/shared.js +31 -29
  65. package/src/routes/snippets.js +154 -0
  66. package/src/routes/stack-analysis.js +17 -14
  67. package/src/server.js +86 -18
  68. package/src/settings/global-settings-service.js +472 -0
  69. package/src/settings/registry.js +624 -0
  70. package/src/utils/db-identity.js +44 -0
@@ -0,0 +1,463 @@
1
+ // Copyright 2026 Tim Perkins (tjwp) | SPDX-License-Identifier: Apache-2.0
2
+ /**
3
+ * SnippetManager — shared editor for chat prompt snippets.
4
+ *
5
+ * One class, two entry points:
6
+ * - Inline mount: `new SnippetManager(container, { onChange })` renders a
7
+ * list of snippets with Edit/Delete controls plus an add/edit form. Used by
8
+ * the global settings page's "Chat Snippets" section.
9
+ * - Modal: `SnippetManager.openModal({ onClose })` wraps an instance in a
10
+ * modal shell (reachable from the chat input's snippet-picker gear).
11
+ *
12
+ * All data flows through the /api/snippets endpoints. The list is re-fetched
13
+ * after every successful mutation so it stays in MRU order, and `onChange()`
14
+ * fires after each success so callers (e.g. an open chat dropdown) can refresh.
15
+ *
16
+ * Snippet bodies are untrusted text and are always rendered via textContent /
17
+ * DOM construction — never string-interpolated into innerHTML.
18
+ */
19
+
20
+ /* global window, document, fetch, module */
21
+
22
+ class SnippetManager {
23
+ /**
24
+ * @param {HTMLElement} container - Mount point; its contents are managed here.
25
+ * @param {Object} [options]
26
+ * @param {Function} [options.onChange] - Called after any successful mutation.
27
+ */
28
+ constructor(container, { onChange } = {}) {
29
+ this.container = container;
30
+ this.onChange = typeof onChange === 'function' ? onChange : null;
31
+
32
+ // View state: 'list' | 'add' | 'edit'.
33
+ this._mode = 'list';
34
+ // Id of the snippet being edited (only meaningful in 'edit' mode).
35
+ this._editingId = null;
36
+ // Latest snippet list from the API.
37
+ this._snippets = [];
38
+ // Guards against overlapping saves/deletes.
39
+ this._busy = false;
40
+ // In-progress form text preserved across a failed-save re-render (null when
41
+ // no draft is pending). See _save / _buildForm.
42
+ this._formDraft = null;
43
+ // Last error message to surface in the banner (null when clear).
44
+ this._error = null;
45
+
46
+ // Document-level listeners we attach (currently none for the inline view,
47
+ // but tracked so destroy() can always tear them down safely).
48
+ this._docListeners = [];
49
+
50
+ if (this.container) {
51
+ this._renderLoading();
52
+ this._fetchAndRender();
53
+ }
54
+ }
55
+
56
+ // ─── Data ──────────────────────────────────────────────────────────────────
57
+
58
+ async _fetchAndRender() {
59
+ try {
60
+ const response = await fetch('/api/snippets');
61
+ if (!response.ok) throw new Error(`Failed to load snippets (${response.status})`);
62
+ const data = await response.json();
63
+ this._snippets = Array.isArray(data.snippets) ? data.snippets : [];
64
+ this._error = null;
65
+ } catch (error) {
66
+ this._snippets = [];
67
+ this._error = error && error.message ? error.message : 'Failed to load snippets';
68
+ }
69
+ this._render();
70
+ }
71
+
72
+ // ─── Rendering ─────────────────────────────────────────────────────────────
73
+
74
+ _renderLoading() {
75
+ if (!this.container) return;
76
+ this.container.innerHTML = '';
77
+ const loading = document.createElement('div');
78
+ loading.className = 'snippet-manager__loading';
79
+ loading.textContent = 'Loading snippets…';
80
+ this.container.appendChild(loading);
81
+ }
82
+
83
+ _render() {
84
+ if (!this.container) return;
85
+ this.container.innerHTML = '';
86
+
87
+ const root = document.createElement('div');
88
+ root.className = 'snippet-manager';
89
+
90
+ if (this._error) {
91
+ const err = document.createElement('div');
92
+ err.className = 'snippet-manager__error';
93
+ err.textContent = this._error;
94
+ root.appendChild(err);
95
+ }
96
+
97
+ if (this._mode === 'add' || this._mode === 'edit') {
98
+ root.appendChild(this._buildForm());
99
+ } else {
100
+ root.appendChild(this._buildList());
101
+ }
102
+
103
+ this.container.appendChild(root);
104
+ }
105
+
106
+ _buildList() {
107
+ const wrap = document.createElement('div');
108
+ wrap.className = 'snippet-manager__list-wrap';
109
+
110
+ if (this._snippets.length === 0) {
111
+ const empty = document.createElement('div');
112
+ empty.className = 'snippet-manager__empty';
113
+ empty.textContent = 'No snippets yet.';
114
+ wrap.appendChild(empty);
115
+ } else {
116
+ const list = document.createElement('div');
117
+ list.className = 'snippet-manager__list';
118
+ for (const snippet of this._snippets) {
119
+ list.appendChild(this._buildRow(snippet));
120
+ }
121
+ wrap.appendChild(list);
122
+ }
123
+
124
+ const addBtn = document.createElement('button');
125
+ addBtn.type = 'button';
126
+ addBtn.className = 'snippet-manager__add-btn';
127
+ addBtn.textContent = 'Add snippet';
128
+ addBtn.addEventListener('click', () => this._showAddForm());
129
+ wrap.appendChild(addBtn);
130
+
131
+ return wrap;
132
+ }
133
+
134
+ /**
135
+ * One snippet row: a DIV holding a single-line truncated preview and sibling
136
+ * Edit/Delete buttons. Rows are DIVs (not buttons) so the action buttons are
137
+ * never nested inside an interactive element (see public/js/CONVENTIONS.md).
138
+ */
139
+ _buildRow(snippet) {
140
+ const row = document.createElement('div');
141
+ row.className = 'snippet-manager__row';
142
+ row.dataset.id = String(snippet.id);
143
+
144
+ const preview = document.createElement('span');
145
+ preview.className = 'snippet-manager__preview';
146
+ // textContent + CSS ellipsis (white-space:nowrap) collapses any newlines to
147
+ // a single line and escapes the body.
148
+ preview.textContent = snippet.body || '';
149
+ preview.title = snippet.body || '';
150
+ row.appendChild(preview);
151
+
152
+ const actions = document.createElement('div');
153
+ actions.className = 'snippet-manager__row-actions';
154
+
155
+ const editBtn = document.createElement('button');
156
+ editBtn.type = 'button';
157
+ editBtn.className = 'snippet-manager__row-btn snippet-manager__edit-btn';
158
+ editBtn.textContent = 'Edit';
159
+ editBtn.addEventListener('click', () => this._showEditForm(snippet.id));
160
+ actions.appendChild(editBtn);
161
+
162
+ const deleteBtn = document.createElement('button');
163
+ deleteBtn.type = 'button';
164
+ deleteBtn.className = 'snippet-manager__row-btn snippet-manager__delete-btn';
165
+ deleteBtn.textContent = 'Delete';
166
+ deleteBtn.addEventListener('click', () => this._delete(snippet.id));
167
+ actions.appendChild(deleteBtn);
168
+
169
+ row.appendChild(actions);
170
+ return row;
171
+ }
172
+
173
+ _buildForm() {
174
+ const isEdit = this._mode === 'edit';
175
+ const editing = isEdit ? this._snippets.find(s => s.id === this._editingId) : null;
176
+
177
+ const form = document.createElement('form');
178
+ form.className = 'snippet-manager__form';
179
+
180
+ const label = document.createElement('label');
181
+ label.className = 'snippet-manager__form-label';
182
+ label.textContent = isEdit ? 'Edit snippet' : 'New snippet';
183
+ form.appendChild(label);
184
+
185
+ const textarea = document.createElement('textarea');
186
+ textarea.className = 'snippet-manager__textarea';
187
+ textarea.rows = 5;
188
+ textarea.placeholder = 'Enter a reusable prompt snippet…';
189
+ // Prefer a preserved draft (from a failed save) over the stored body so the
190
+ // user's in-progress text survives an error re-render.
191
+ textarea.value = this._formDraft != null
192
+ ? this._formDraft
193
+ : (editing ? (editing.body || '') : '');
194
+ form.appendChild(textarea);
195
+ this._formTextarea = textarea;
196
+
197
+ const actions = document.createElement('div');
198
+ actions.className = 'snippet-manager__form-actions';
199
+
200
+ const saveBtn = document.createElement('button');
201
+ saveBtn.type = 'submit';
202
+ saveBtn.className = 'snippet-manager__save-btn';
203
+ saveBtn.textContent = 'Save';
204
+ actions.appendChild(saveBtn);
205
+
206
+ const cancelBtn = document.createElement('button');
207
+ cancelBtn.type = 'button';
208
+ cancelBtn.className = 'snippet-manager__cancel-btn';
209
+ cancelBtn.textContent = 'Cancel';
210
+ cancelBtn.addEventListener('click', () => this._cancelForm());
211
+ actions.appendChild(cancelBtn);
212
+
213
+ form.appendChild(actions);
214
+
215
+ const syncDisabled = () => {
216
+ saveBtn.disabled = textarea.value.trim() === '' || this._busy;
217
+ };
218
+ textarea.addEventListener('input', syncDisabled);
219
+ syncDisabled();
220
+
221
+ form.addEventListener('submit', (e) => {
222
+ e.preventDefault();
223
+ this._save(textarea.value);
224
+ });
225
+
226
+ // Focus the textarea so typing can begin immediately.
227
+ setTimeout(() => { try { textarea.focus(); } catch (_) { /* jsdom */ } }, 0);
228
+
229
+ return form;
230
+ }
231
+
232
+ // ─── View transitions ──────────────────────────────────────────────────────
233
+
234
+ _showAddForm() {
235
+ this._mode = 'add';
236
+ this._editingId = null;
237
+ this._formDraft = null; // fresh form
238
+ this._error = null; // don't carry a stale banner across the transition
239
+ this._render();
240
+ }
241
+
242
+ _showEditForm(id) {
243
+ this._mode = 'edit';
244
+ this._editingId = id;
245
+ this._formDraft = null; // fresh form
246
+ this._error = null;
247
+ this._render();
248
+ }
249
+
250
+ _cancelForm() {
251
+ this._mode = 'list';
252
+ this._editingId = null;
253
+ this._formDraft = null; // discard the in-progress draft
254
+ this._error = null;
255
+ this._render();
256
+ }
257
+
258
+ // ─── Mutations ─────────────────────────────────────────────────────────────
259
+
260
+ async _save(rawBody) {
261
+ // Persist the body verbatim — leading/trailing whitespace and newlines are
262
+ // user content (the snippet is inserted into chat unmodified later). Only
263
+ // the empty-guard uses a trimmed copy; the backend rejects all-whitespace.
264
+ const body = rawBody == null ? '' : String(rawBody);
265
+ if (body.trim() === '' || this._busy) return;
266
+ this._busy = true;
267
+
268
+ const isEdit = this._mode === 'edit';
269
+ const id = this._editingId;
270
+
271
+ try {
272
+ const response = isEdit
273
+ ? await fetch(`/api/snippets/${encodeURIComponent(id)}`, {
274
+ method: 'PUT',
275
+ headers: { 'Content-Type': 'application/json' },
276
+ body: JSON.stringify({ body })
277
+ })
278
+ : await fetch('/api/snippets', {
279
+ method: 'POST',
280
+ headers: { 'Content-Type': 'application/json' },
281
+ body: JSON.stringify({ body })
282
+ });
283
+
284
+ if (!response.ok) {
285
+ const data = await response.json().catch(() => ({}));
286
+ throw new Error(data.error || `Failed to save snippet (${response.status})`);
287
+ }
288
+
289
+ this._busy = false;
290
+ this._mode = 'list';
291
+ this._editingId = null;
292
+ this._formDraft = null; // committed — discard the in-progress draft
293
+ this._error = null;
294
+ this._notifyChanged();
295
+ await this._fetchAndRender();
296
+ } catch (error) {
297
+ this._busy = false;
298
+ // Preserve the user's in-progress text across the error re-render so a
299
+ // failed save doesn't wipe what they typed. _buildForm prefers the draft.
300
+ this._formDraft = body;
301
+ this._error = error && error.message ? error.message : 'Failed to save snippet';
302
+ this._render();
303
+ }
304
+ }
305
+
306
+ /**
307
+ * Confirm a destructive delete. Prefers the repo's styled confirmDialog
308
+ * (available in the chat modal context, where it stacks above via a higher
309
+ * z-index); falls back to native confirm on pages that don't load it (e.g.
310
+ * the settings page). Returns true when the user confirms.
311
+ */
312
+ async _confirmDelete() {
313
+ const message = 'Delete this snippet? This cannot be undone.';
314
+ if (typeof window !== 'undefined' && window.confirmDialog && typeof window.confirmDialog.show === 'function') {
315
+ const choice = await window.confirmDialog.show({
316
+ title: 'Delete snippet',
317
+ message,
318
+ confirmText: 'Delete',
319
+ confirmClass: 'btn-danger'
320
+ });
321
+ return choice === 'confirm';
322
+ }
323
+ if (typeof window !== 'undefined' && typeof window.confirm === 'function') {
324
+ return window.confirm(message);
325
+ }
326
+ return true;
327
+ }
328
+
329
+ async _delete(id) {
330
+ if (this._busy) return;
331
+ if (!(await this._confirmDelete())) return;
332
+ this._busy = true;
333
+
334
+ try {
335
+ const response = await fetch(`/api/snippets/${encodeURIComponent(id)}`, {
336
+ method: 'DELETE'
337
+ });
338
+ if (!response.ok) {
339
+ const data = await response.json().catch(() => ({}));
340
+ throw new Error(data.error || `Failed to delete snippet (${response.status})`);
341
+ }
342
+ this._busy = false;
343
+ this._notifyChanged();
344
+ await this._fetchAndRender();
345
+ } catch (error) {
346
+ this._busy = false;
347
+ this._error = error && error.message ? error.message : 'Failed to delete snippet';
348
+ this._render();
349
+ }
350
+ }
351
+
352
+ _notifyChanged() {
353
+ if (this.onChange) {
354
+ try { this.onChange(); } catch (_) { /* callback errors must not break the UI */ }
355
+ }
356
+ }
357
+
358
+ // ─── Teardown ──────────────────────────────────────────────────────────────
359
+
360
+ destroy() {
361
+ for (const { target, type, handler } of this._docListeners) {
362
+ target.removeEventListener(type, handler);
363
+ }
364
+ this._docListeners = [];
365
+ this._formTextarea = null;
366
+ if (this.container) {
367
+ this.container.innerHTML = '';
368
+ }
369
+ }
370
+
371
+ // ─── Modal entry point ─────────────────────────────────────────────────────
372
+
373
+ /**
374
+ * Open the snippet manager in a modal. Mirrors the modal shell structure of
375
+ * ReviewModal (`.modal-overlay` / `.modal-backdrop` / `.modal-container`) but
376
+ * wires teardown with addEventListener (no inline onclick globals).
377
+ *
378
+ * @param {Object} [options]
379
+ * @param {Function} [options.onClose] - Called with `(changed: boolean)` when
380
+ * the modal is dismissed; `changed` is true if any mutation succeeded.
381
+ * @returns {SnippetManager} the mounted instance.
382
+ */
383
+ static openModal({ onClose } = {}) {
384
+ let changed = false;
385
+
386
+ const overlay = document.createElement('div');
387
+ overlay.className = 'modal-overlay snippet-manager-modal';
388
+
389
+ const backdrop = document.createElement('div');
390
+ backdrop.className = 'modal-backdrop';
391
+
392
+ const containerEl = document.createElement('div');
393
+ containerEl.className = 'modal-container snippet-manager-modal__container';
394
+
395
+ const header = document.createElement('div');
396
+ header.className = 'modal-header snippet-manager-modal__header';
397
+
398
+ const heading = document.createElement('h3');
399
+ heading.textContent = 'Manage snippets';
400
+ header.appendChild(heading);
401
+
402
+ const closeBtn = document.createElement('button');
403
+ closeBtn.type = 'button';
404
+ closeBtn.className = 'modal-close-btn snippet-manager-modal__close';
405
+ closeBtn.title = 'Close';
406
+ closeBtn.setAttribute('aria-label', 'Close');
407
+ closeBtn.innerHTML = '<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><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"/></svg>';
408
+ header.appendChild(closeBtn);
409
+
410
+ const bodyEl = document.createElement('div');
411
+ bodyEl.className = 'modal-body snippet-manager-modal__body';
412
+
413
+ containerEl.appendChild(header);
414
+ containerEl.appendChild(bodyEl);
415
+ overlay.appendChild(backdrop);
416
+ overlay.appendChild(containerEl);
417
+ document.body.appendChild(overlay);
418
+
419
+ const instance = new SnippetManager(bodyEl, { onChange: () => { changed = true; } });
420
+
421
+ let torndown = false;
422
+ const teardown = () => {
423
+ if (torndown) return;
424
+ torndown = true;
425
+ // Must pass the SAME capture flag as addEventListener or the listener leaks.
426
+ document.removeEventListener('keydown', onKey, true);
427
+ instance.destroy();
428
+ if (overlay.parentNode) overlay.parentNode.removeChild(overlay);
429
+ if (typeof onClose === 'function') onClose(changed);
430
+ };
431
+
432
+ // Capture phase + stopPropagation so Escape closes only this modal and does
433
+ // not bubble to ChatPanel's own keydown handler (which would also close the
434
+ // chat panel behind the modal).
435
+ const onKey = (e) => {
436
+ if (e.key !== 'Escape') return;
437
+ // A nested confirm dialog (the delete confirmation) stacks above this
438
+ // modal and handles Escape from its own bubble-phase listener. Because we
439
+ // run in the capture phase, we'd otherwise swallow the event and tear down
440
+ // the whole modal, orphaning the confirm dialog. Yield to it. (Repo
441
+ // pattern: TextInputDialog.js.)
442
+ if (window.confirmDialog && window.confirmDialog.isVisible) return;
443
+ e.stopPropagation();
444
+ teardown();
445
+ };
446
+
447
+ backdrop.addEventListener('click', teardown);
448
+ closeBtn.addEventListener('click', teardown);
449
+ document.addEventListener('keydown', onKey, true);
450
+
451
+ return instance;
452
+ }
453
+ }
454
+
455
+ // Make SnippetManager available globally.
456
+ if (typeof window !== 'undefined') {
457
+ window.SnippetManager = SnippetManager;
458
+ }
459
+
460
+ // Export for CommonJS testing environments.
461
+ if (typeof module !== 'undefined' && module.exports) {
462
+ module.exports = { SnippetManager };
463
+ }
@@ -15,26 +15,10 @@
15
15
  'use strict';
16
16
 
17
17
  // ─── Theme Management ───────────────────────────────────────────────────────
18
-
19
- function initTheme() {
20
- const savedTheme = localStorage.getItem('theme');
21
- const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
22
- const theme = savedTheme || (prefersDark ? 'dark' : 'light');
23
- document.documentElement.setAttribute('data-theme', theme);
24
- }
25
-
26
- function toggleTheme() {
27
- const currentTheme = document.documentElement.getAttribute('data-theme');
28
- const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
29
- document.documentElement.setAttribute('data-theme', newTheme);
30
- localStorage.setItem('theme', newTheme);
31
- }
32
-
33
- // Initialize theme on page load
34
- initTheme();
35
-
36
- // Set up theme toggle button
37
- document.getElementById('theme-toggle').addEventListener('click', toggleTheme);
18
+ // The shared helper (js/theme.js) owns preference storage, the
19
+ // light → dark → system toggle cycle, the button icon, and the live
20
+ // OS-change listener that keeps 'system' in sync with the OS setting.
21
+ window.PairReviewTheme.setup();
38
22
 
39
23
  // ─── Help Modal ─────────────────────────────────────────────────────────────
40
24
 
@@ -79,13 +63,6 @@
79
63
  }
80
64
  });
81
65
 
82
- // Listen for system theme changes
83
- window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function (e) {
84
- if (!localStorage.getItem('theme')) {
85
- document.documentElement.setAttribute('data-theme', e.matches ? 'dark' : 'light');
86
- }
87
- });
88
-
89
66
  // ─── Shared Utilities ───────────────────────────────────────────────────────
90
67
 
91
68
  /** localStorage key for persisting the active tab */
@@ -1413,9 +1390,9 @@
1413
1390
  window.__pairReview.chatProviders = chatProviders;
1414
1391
  window.__pairReview.defaultProvider = config.default_provider || 'claude';
1415
1392
  window.__pairReview.defaultModel = config.default_model || 'opus';
1416
- // CLI/env override (PAIR_REVIEW_PROVIDER / PAIR_REVIEW_MODEL) surfaced
1417
- // by /api/config. The bulk-analysis seed prepends these ahead of repo
1418
- // settings so a `--provider` override outranks a repo's saved default.
1393
+ // Per-run --provider/--model override surfaced by /api/config. The
1394
+ // bulk-analysis seed prepends these ahead of repo settings so a
1395
+ // `--provider` override outranks a repo's saved default.
1419
1396
  window.__pairReview.providerOverride = config.provider_override || null;
1420
1397
  window.__pairReview.modelOverride = config.model_override || null;
1421
1398
  window.__pairReview.hasGithubToken = Boolean(config.has_github_token);
@@ -1095,6 +1095,15 @@ class LocalManager {
1095
1095
  onToggleWhitespace: (hide) => manager.handleWhitespaceToggle(hide),
1096
1096
  onToggleMinimize: (minimized) => manager.handleMinimizeToggle(minimized),
1097
1097
  onScopeChange: (start, end) => this._handleScopeChange(start, end),
1098
+ // Diff view (Unified / Split) — the handler lives on PRManager and is
1099
+ // shared with PR mode (no re-fetch, so local mode needs no override).
1100
+ onDiffViewChange: (mode) => manager.handleDiffViewChange(mode),
1101
+ diffView: window.readPersistedDiffView
1102
+ ? window.readPersistedDiffView()
1103
+ : (localStorage.getItem('pair-review-diff-view') === 'split' ? 'split' : 'unified'),
1104
+ // Match PR mode: only offer the control when the Pierre render path
1105
+ // can apply the swap (see pr.js construction site).
1106
+ diffViewAvailable: Boolean(manager.pierreBridge && !manager.pierreBridge._disabled),
1098
1107
  initialScope: { start: scopeStart, end: scopeEnd },
1099
1108
  branchAvailable
1100
1109
  });
@@ -1554,8 +1563,14 @@ class LocalManager {
1554
1563
  // Pass through the server-computed canonical hunk hashes; renderPatch
1555
1564
  // requires these to anchor persisted summaries (no client-side fallback).
1556
1565
  hunk_hashes: hunkHashesByFile[fileName] || null,
1557
- status: patch.includes('new file mode') ? 'added' :
1558
- patch.includes('deleted file mode') ? 'removed' : 'modified'
1566
+ // Inspect only the header (before the first @@) so file contents
1567
+ // containing "new file mode" / "deleted file mode" can't spoof status.
1568
+ status: (() => {
1569
+ const atIdx = patch.indexOf('@@');
1570
+ const hdr = atIdx === -1 ? patch : patch.substring(0, atIdx);
1571
+ return hdr.includes('new file mode') ? 'added' :
1572
+ hdr.includes('deleted file mode') ? 'removed' : 'modified';
1573
+ })()
1559
1574
  });
1560
1575
 
1561
1576
  totalAdditions += additions;
@@ -1604,6 +1619,9 @@ class LocalManager {
1604
1619
  // Render diff
1605
1620
  manager.renderDiff({ changed_files: sortedFiles });
1606
1621
 
1622
+ // Progressively fetch full file contents for hunk expansion
1623
+ manager._upgradeFilesWithContents(sortedFiles);
1624
+
1607
1625
  } catch (error) {
1608
1626
  console.error('Error loading local diff:', error);
1609
1627
  const diffContainer = document.getElementById('diff-container');
@@ -316,7 +316,14 @@ class CommentManager {
316
316
  * @returns {string} The code content from the lines
317
317
  */
318
318
  getCodeFromLines(fileName, startLine, endLine, side) {
319
- // Find the file wrapper
319
+ // Try PierreBridge first (for @pierre/diffs rendered files)
320
+ const bridge = this.prManager?.pierreBridge;
321
+ if (bridge && bridge.files.has(fileName)) {
322
+ const code = bridge.getCodeFromLines(fileName, startLine, endLine, side);
323
+ if (code !== null) return code;
324
+ }
325
+
326
+ // Legacy path: DOM query for diff2html table rows
320
327
  const fileWrappers = document.querySelectorAll('.d2h-file-wrapper');
321
328
  let targetWrapper = null;
322
329