@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
@@ -122,20 +122,9 @@ class RepoSettingsPage {
122
122
  }
123
123
 
124
124
  initTheme() {
125
- // Check for saved theme preference
126
- const savedTheme = localStorage.getItem('theme') || 'light';
127
- document.documentElement.setAttribute('data-theme', savedTheme);
128
-
129
- // Theme toggle button
130
- const themeToggle = document.getElementById('theme-toggle');
131
- if (themeToggle) {
132
- themeToggle.addEventListener('click', () => {
133
- const currentTheme = document.documentElement.getAttribute('data-theme');
134
- const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
135
- document.documentElement.setAttribute('data-theme', newTheme);
136
- localStorage.setItem('theme', newTheme);
137
- });
138
- }
125
+ // Shared helper owns preference storage, the light → dark → system toggle
126
+ // cycle, the button icon, and the live OS-change listener (js/theme.js).
127
+ window.PairReviewTheme.setup();
139
128
  }
140
129
 
141
130
  setupEventListeners() {
@@ -345,162 +334,38 @@ class RepoSettingsPage {
345
334
  }
346
335
 
347
336
  /**
348
- * Get the display label for a council type
349
- * @param {string} type - Council type ('council' or 'advanced')
350
- * @returns {{ label: string, cssClass: string }}
351
- */
352
- getCouncilTypeBadge(type) {
353
- if (type === 'advanced') {
354
- return { label: 'Advanced', cssClass: 'badge-advanced' };
355
- }
356
- return { label: 'Standard', cssClass: 'badge-standard' };
357
- }
358
-
359
- /**
360
- * Render the custom council dropdown
337
+ * Render (or refresh) the custom council dropdown via the shared
338
+ * CouncilDropdown component (public/js/components/CouncilDropdown.js). The
339
+ * component owns rendering + interaction; a selection routes back into
340
+ * selectCouncilOption, which updates the card preview and change tracking —
341
+ * preserving the original behavior. The instance is created once and reused so
342
+ * its document-level outside-click listener is not re-stacked on each refresh.
361
343
  */
362
344
  renderCouncilDropdown() {
363
345
  const container = document.getElementById('default-council-dropdown');
364
346
  if (!container) return;
365
347
 
348
+ // Resolve the component constructor without a bare reference (unit tests
349
+ // eval this class in a scope where the global may be absent).
350
+ const Dropdown = (typeof window !== 'undefined' && window.CouncilDropdown)
351
+ || (typeof CouncilDropdown !== 'undefined' ? CouncilDropdown : null);
352
+ if (!Dropdown) return;
353
+
366
354
  const selectedId = this.currentSettings.default_council_id || '';
367
- const selectedCouncil = this.councils.find(c => c.id === selectedId);
368
-
369
- // Build trigger display
370
- let triggerHTML;
371
- if (selectedCouncil) {
372
- const badge = this.getCouncilTypeBadge(selectedCouncil.type);
373
- triggerHTML = `<span class="trigger-text">${this.escapeHtml(selectedCouncil.name)}</span>
374
- <span class="council-type-badge ${badge.cssClass}">${badge.label}</span>`;
375
- } else if (this.councils.length > 0) {
376
- triggerHTML = '<span class="trigger-text placeholder">Select a council...</span>';
355
+ if (!this._councilDropdown) {
356
+ this._councilDropdown = new Dropdown({
357
+ container,
358
+ councils: this.councils,
359
+ selectedId,
360
+ placeholder: 'Select a council...',
361
+ emptyText: 'No councils yet — create one from the analysis config',
362
+ onSelect: (value) => this.selectCouncilOption(container, value)
363
+ });
377
364
  } else {
378
- triggerHTML = '<span class="trigger-text placeholder">No councils yet — create one from the analysis config</span>';
379
- }
380
-
381
- // Build option list — sort alphabetically by name
382
- const sortedCouncils = [...this.councils].sort((a, b) =>
383
- (a.name || '').localeCompare(b.name || '', undefined, { sensitivity: 'base' })
384
- );
385
- let optionsHTML = '';
386
-
387
- for (const council of sortedCouncils) {
388
- const badge = this.getCouncilTypeBadge(council.type);
389
- const isSelected = council.id === selectedId;
390
- optionsHTML += `<div class="custom-dropdown-option${isSelected ? ' selected' : ''}" data-value="${this.escapeHtml(council.id)}" role="option" aria-selected="${isSelected}">
391
- <span class="option-name">${this.escapeHtml(council.name)}</span>
392
- <span class="council-type-badge ${badge.cssClass}">${badge.label}</span>
393
- </div>`;
394
- }
395
-
396
- container.innerHTML = `
397
- <button type="button" class="custom-dropdown-trigger" aria-haspopup="listbox" aria-expanded="false">
398
- ${triggerHTML}
399
- </button>
400
- <div class="custom-dropdown-list" role="listbox">
401
- ${optionsHTML}
402
- </div>
403
- `;
404
-
405
- // Attach event listeners for the dropdown
406
- this.setupCouncilDropdownListeners(container);
407
- }
408
-
409
- /**
410
- * Set up event listeners for the custom council dropdown
411
- * @param {HTMLElement} container - The dropdown container element
412
- */
413
- setupCouncilDropdownListeners(container) {
414
- const trigger = container.querySelector('.custom-dropdown-trigger');
415
- const list = container.querySelector('.custom-dropdown-list');
416
- if (!trigger || !list) return;
417
-
418
- // Track focused option index for keyboard navigation
419
- let focusedIndex = -1;
420
- const getOptions = () => Array.from(list.querySelectorAll('.custom-dropdown-option'));
421
-
422
- const updateFocus = (options, index) => {
423
- options.forEach(opt => opt.classList.remove('focused'));
424
- if (index >= 0 && index < options.length) {
425
- options[index].classList.add('focused');
426
- options[index].scrollIntoView({ block: 'nearest' });
427
- }
428
- };
429
-
430
- // Toggle dropdown on trigger click
431
- trigger.addEventListener('click', () => {
432
- const isOpen = container.classList.contains('open');
433
- if (isOpen) {
434
- this.closeCouncilDropdown(container);
435
- } else {
436
- this.openCouncilDropdown(container);
437
- focusedIndex = -1;
438
- }
439
- });
440
-
441
- // Select option on click
442
- list.addEventListener('click', (e) => {
443
- const option = e.target.closest('.custom-dropdown-option');
444
- if (!option) return;
445
- this.selectCouncilOption(container, option.dataset.value);
446
- });
447
-
448
- // Keyboard navigation
449
- trigger.addEventListener('keydown', (e) => {
450
- const isOpen = container.classList.contains('open');
451
-
452
- if (e.key === 'Escape' && isOpen) {
453
- e.preventDefault();
454
- this.closeCouncilDropdown(container);
455
- trigger.focus();
456
- return;
457
- }
458
-
459
- if (e.key === 'Enter' || e.key === ' ') {
460
- e.preventDefault();
461
- if (!isOpen) {
462
- this.openCouncilDropdown(container);
463
- focusedIndex = -1;
464
- } else {
465
- const options = getOptions();
466
- if (focusedIndex >= 0 && focusedIndex < options.length) {
467
- this.selectCouncilOption(container, options[focusedIndex].dataset.value);
468
- }
469
- }
470
- return;
471
- }
472
-
473
- if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && isOpen) {
474
- e.preventDefault();
475
- const options = getOptions();
476
- if (e.key === 'ArrowDown') {
477
- focusedIndex = Math.min(focusedIndex + 1, options.length - 1);
478
- } else {
479
- focusedIndex = Math.max(focusedIndex - 1, 0);
480
- }
481
- updateFocus(options, focusedIndex);
482
- return;
483
- }
484
-
485
- // Open on arrow down when closed
486
- if (e.key === 'ArrowDown' && !isOpen) {
487
- e.preventDefault();
488
- this.openCouncilDropdown(container);
489
- focusedIndex = 0;
490
- updateFocus(getOptions(), focusedIndex);
491
- }
492
- });
493
-
494
- // Close on click outside (remove previous handler to avoid accumulation on re-render)
495
- if (this._councilDropdownOutsideClickHandler) {
496
- document.removeEventListener('click', this._councilDropdownOutsideClickHandler);
365
+ this._councilDropdown.councils = this.councils;
366
+ this._councilDropdown.selectedId = selectedId;
367
+ this._councilDropdown.render();
497
368
  }
498
- this._councilDropdownOutsideClickHandler = (e) => {
499
- if (!container.contains(e.target) && container.classList.contains('open')) {
500
- this.closeCouncilDropdown(container);
501
- }
502
- };
503
- document.addEventListener('click', this._councilDropdownOutsideClickHandler);
504
369
  }
505
370
 
506
371
  /**
@@ -541,27 +406,19 @@ class RepoSettingsPage {
541
406
  }
542
407
 
543
408
  /**
544
- * Open the custom council dropdown
545
- * @param {HTMLElement} container
409
+ * Open the custom council dropdown (delegates to the shared component).
410
+ * @param {HTMLElement} [container] - Unused; kept for signature compatibility.
546
411
  */
547
412
  openCouncilDropdown(container) {
548
- container.classList.add('open');
549
- const trigger = container.querySelector('.custom-dropdown-trigger');
550
- if (trigger) trigger.setAttribute('aria-expanded', 'true');
413
+ if (this._councilDropdown) this._councilDropdown.open();
551
414
  }
552
415
 
553
416
  /**
554
- * Close the custom council dropdown
555
- * @param {HTMLElement} container
417
+ * Close the custom council dropdown (delegates to the shared component).
418
+ * @param {HTMLElement} [container] - Unused; kept for signature compatibility.
556
419
  */
557
420
  closeCouncilDropdown(container) {
558
- container.classList.remove('open');
559
- const trigger = container.querySelector('.custom-dropdown-trigger');
560
- if (trigger) trigger.setAttribute('aria-expanded', 'false');
561
- // Clear focus highlights
562
- container.querySelectorAll('.custom-dropdown-option.focused').forEach(
563
- opt => opt.classList.remove('focused')
564
- );
421
+ if (this._councilDropdown) this._councilDropdown.close();
565
422
  }
566
423
 
567
424
  /**
@@ -733,127 +590,46 @@ class RepoSettingsPage {
733
590
  }
734
591
 
735
592
  /**
736
- * Render a standard (voice) council card
593
+ * Lazily build (and cache) the shared CouncilCard bound to this page's
594
+ * container + alias-aware model-display resolver. Re-created if the target
595
+ * container changes (e.g. between test cases).
596
+ * @param {HTMLElement} container
597
+ * @returns {Object|null} A CouncilCard, or null if the component is unavailable.
598
+ * @private
599
+ */
600
+ _getCouncilCard(container) {
601
+ const Card = (typeof window !== 'undefined' && window.CouncilCard)
602
+ || (typeof CouncilCard !== 'undefined' ? CouncilCard : null);
603
+ if (!Card) return null;
604
+ if (!this._councilCard || this._councilCard.container !== container) {
605
+ this._councilCard = new Card({
606
+ container,
607
+ resolveModelDisplay: (providerId, modelId) => this.resolveModelDisplay(providerId, modelId)
608
+ });
609
+ }
610
+ return this._councilCard;
611
+ }
612
+
613
+ /**
614
+ * Render a standard (voice) council card via the shared CouncilCard component.
737
615
  * @param {object} council
738
616
  */
739
617
  renderVoiceCouncilCard(council) {
740
618
  const container = document.getElementById('model-card-preview');
741
619
  if (!container) return;
742
-
743
- const config = council.config || {};
744
- const voices = config.voices || [];
745
- const levels = config.levels || {};
746
-
747
- // Build summary: "Levels 1, 2" for enabled levels
748
- const enabledLevels = Object.entries(levels)
749
- .filter(([, enabled]) => enabled)
750
- .map(([level]) => level);
751
- const summaryText = enabledLevels.length > 0
752
- ? `Levels ${enabledLevels.join(', ')}`
753
- : 'No levels configured';
754
-
755
- // Build reviewer list
756
- const reviewerLines = voices.map(voice => {
757
- const display = this.resolveModelDisplay(voice.provider, voice.model);
758
- const tierLabel = voice.tier ? `<span class="council-card-tier">${this.escapeHtml(voice.tier)}</span>` : '';
759
- return `<div class="council-card-reviewer">
760
- <span class="council-card-reviewer-name">${this.escapeHtml(display.providerName)} / ${this.escapeHtml(display.modelName)}</span>
761
- ${tierLabel}
762
- </div>`;
763
- }).join('');
764
-
765
- // Build consolidation section
766
- let consolidationHTML = '';
767
- if (config.consolidation && config.consolidation.provider) {
768
- const consolDisplay = this.resolveModelDisplay(config.consolidation.provider, config.consolidation.model);
769
- const consolTier = config.consolidation.tier ? `<span class="council-card-tier">${this.escapeHtml(config.consolidation.tier)}</span>` : '';
770
- consolidationHTML = `
771
- <div class="council-card-divider"></div>
772
- <div class="council-card-consolidation">
773
- <div class="council-card-consolidation-label">Consolidation</div>
774
- <div class="council-card-reviewer">
775
- <span class="council-card-reviewer-name">${this.escapeHtml(consolDisplay.providerName)} / ${this.escapeHtml(consolDisplay.modelName)}</span>
776
- ${consolTier}
777
- </div>
778
- </div>`;
779
- }
780
-
781
- container.innerHTML = `
782
- <div class="council-card">
783
- <div class="council-card-name">${this.escapeHtml(council.name)}</div>
784
- <div class="council-card-summary">${summaryText}</div>
785
- <div class="council-card-reviewers">
786
- ${reviewerLines}
787
- </div>
788
- ${consolidationHTML}
789
- </div>
790
- `;
620
+ const card = this._getCouncilCard(container);
621
+ if (card) card.renderVoice(council);
791
622
  }
792
623
 
793
624
  /**
794
- * Render an advanced council card with level-grouped reviewers
625
+ * Render an advanced council card via the shared CouncilCard component.
795
626
  * @param {object} council
796
627
  */
797
628
  renderAdvancedCouncilCard(council) {
798
629
  const container = document.getElementById('model-card-preview');
799
630
  if (!container) return;
800
-
801
- const config = council.config || {};
802
- const levels = config.levels || {};
803
-
804
- const levelLabels = {
805
- '1': 'Level 1 — Isolation',
806
- '2': 'Level 2 — File Context',
807
- '3': 'Level 3 — Codebase'
808
- };
809
-
810
- // Build level groups for enabled levels
811
- let levelGroupsHTML = '';
812
- for (const [levelNum, levelConfig] of Object.entries(levels)) {
813
- if (!levelConfig || !levelConfig.enabled) continue;
814
- const voices = levelConfig.voices || [];
815
- const header = levelLabels[levelNum] || `Level ${levelNum}`;
816
- const voiceLines = voices.map(voice => {
817
- const display = this.resolveModelDisplay(voice.provider, voice.model);
818
- const tierLabel = voice.tier ? `<span class="council-card-tier">${this.escapeHtml(voice.tier)}</span>` : '';
819
- return `<div class="council-card-reviewer">
820
- <span class="council-card-reviewer-name">${this.escapeHtml(display.providerName)} / ${this.escapeHtml(display.modelName)}</span>
821
- ${tierLabel}
822
- </div>`;
823
- }).join('');
824
- levelGroupsHTML += `
825
- <div class="council-card-level-header">${this.escapeHtml(header)}</div>
826
- ${voiceLines}`;
827
- }
828
-
829
- // Build consolidation/orchestration section
830
- let consolidationHTML = '';
831
- if (config.consolidation && config.consolidation.provider) {
832
- const consolDisplay = this.resolveModelDisplay(config.consolidation.provider, config.consolidation.model);
833
- const consolTier = config.consolidation.tier ? `<span class="council-card-tier">${this.escapeHtml(config.consolidation.tier)}</span>` : '';
834
- consolidationHTML = `
835
- <div class="council-card-divider"></div>
836
- <div class="council-card-consolidation">
837
- <div class="council-card-consolidation-label">Orchestration</div>
838
- <div class="council-card-reviewer">
839
- <span class="council-card-reviewer-name">${this.escapeHtml(consolDisplay.providerName)} / ${this.escapeHtml(consolDisplay.modelName)}</span>
840
- ${consolTier}
841
- </div>
842
- </div>`;
843
- }
844
-
845
- container.innerHTML = `
846
- <div class="council-card">
847
- <div class="council-card-name">
848
- ${this.escapeHtml(council.name)}
849
- <span class="council-card-badge-advanced">Advanced</span>
850
- </div>
851
- <div class="council-card-reviewers">
852
- ${levelGroupsHTML}
853
- </div>
854
- ${consolidationHTML}
855
- </div>
856
- `;
631
+ const card = this._getCouncilCard(container);
632
+ if (card) card.renderAdvanced(council);
857
633
  }
858
634
 
859
635
  async loadSettings() {