@in-the-loop-labs/pair-review 5.4.4 → 5.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@in-the-loop-labs/pair-review",
3
- "version": "5.4.4",
3
+ "version": "5.5.0",
4
4
  "description": "Your AI-powered code review partner - Close the feedback loop with AI coding agents",
5
5
  "main": "src/server.js",
6
6
  "bin": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pair-review",
3
- "version": "5.4.4",
3
+ "version": "5.5.0",
4
4
  "description": "pair-review app integration — Open PRs and local changes in the pair-review web UI, run server-side AI analysis, and address review feedback. Requires the pair-review MCP server.",
5
5
  "author": {
6
6
  "name": "in-the-loop-labs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code-critic",
3
- "version": "5.4.4",
3
+ "version": "5.5.0",
4
4
  "description": "AI-powered code review analysis — Run three-level AI analysis directly in your coding agent. Works standalone, no server required.",
5
5
  "author": {
6
6
  "name": "in-the-loop-labs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pair-loop",
3
- "version": "5.4.4",
3
+ "version": "5.5.0",
4
4
  "description": "Agent-orchestrated review loop — implement, review with pair-review multi-model councils via the headless CLI, triage, fix, and repeat until a final review returns no blockers. MCP-independent.",
5
5
  "author": {
6
6
  "name": "in-the-loop-labs",
package/public/css/pr.css CHANGED
@@ -951,6 +951,17 @@
951
951
  margin-bottom: 8px;
952
952
  }
953
953
 
954
+ /* Nested folders sit tight under their parent */
955
+ .file-group .file-group {
956
+ margin-bottom: 0;
957
+ }
958
+
959
+ /* Collapsed folder chains (e.g. "src/js/utils") can be long */
960
+ .file-group-name {
961
+ min-width: 0;
962
+ overflow-wrap: anywhere;
963
+ }
964
+
954
965
  .file-group-header {
955
966
  display: flex;
956
967
  align-items: center;
@@ -984,7 +995,9 @@
984
995
  height: 12px;
985
996
  }
986
997
 
987
- .file-group.expanded .file-group-chevron {
998
+ /* Child combinators: only a folder's own chevron follows its expanded state,
999
+ not the chevrons of nested subfolders */
1000
+ .file-group.expanded > .file-group-header > .file-group-chevron {
988
1001
  transform: rotate(90deg);
989
1002
  }
990
1003
 
@@ -1001,7 +1014,7 @@
1001
1014
  }
1002
1015
 
1003
1016
  .file-group-items {
1004
- margin-left: 16px;
1017
+ margin-left: 12px;
1005
1018
  }
1006
1019
 
1007
1020
  /* Hide file items when group is collapsed */
@@ -9060,8 +9073,9 @@ body.resizing * {
9060
9073
  display: none;
9061
9074
  }
9062
9075
 
9063
- /* Comment filter menu: a funnel at the right of the segment row that opens
9064
- labeled options for user comments (show dismissed, show posted). */
9076
+ /* Filter menu: a funnel at the right of the segment row that opens labeled
9077
+ options: sort and severity filter for AI suggestions, and show dismissed /
9078
+ show posted for user comments. The dot means this review hides something. */
9065
9079
  .comment-filter {
9066
9080
  position: relative;
9067
9081
  flex-shrink: 0;
@@ -9122,6 +9136,9 @@ body.resizing * {
9122
9136
  z-index: 100;
9123
9137
  min-width: 160px;
9124
9138
  padding: 6px 0;
9139
+ /* max-height is set when the menu opens (AIPanel._fitFilterMenuToViewport) so it
9140
+ scrolls instead of running past the window */
9141
+ overflow-y: auto;
9125
9142
  background: var(--color-bg-primary);
9126
9143
  border: 1px solid var(--color-border-primary);
9127
9144
  border-radius: var(--radius-sm);
@@ -9161,15 +9178,28 @@ body.resizing * {
9161
9178
  accent-color: var(--comment-primary);
9162
9179
  }
9163
9180
 
9181
+ /* Line between the AI suggestion (severity) and user comment sections */
9182
+ .comment-filter-menu-divider {
9183
+ height: 1px;
9184
+ margin: 6px 0;
9185
+ background: var(--color-border-primary);
9186
+ }
9187
+
9188
+ .comment-filter-section .comment-filter-option + .comment-filter-menu-title {
9189
+ padding-top: 8px;
9190
+ }
9191
+
9164
9192
  /* Muted line at the end of the user comment list when filters hide some */
9165
- .hidden-comments-notice {
9193
+ .hidden-comments-notice,
9194
+ .hidden-severity-notice {
9166
9195
  padding: 8px 12px;
9167
9196
  font-size: 12px;
9168
9197
  color: var(--color-text-tertiary);
9169
9198
  text-align: center;
9170
9199
  }
9171
9200
 
9172
- .hidden-comments-show {
9201
+ .hidden-comments-show,
9202
+ .hidden-severity-show {
9173
9203
  padding: 0;
9174
9204
  background: none;
9175
9205
  border: none;
@@ -9178,7 +9208,8 @@ body.resizing * {
9178
9208
  cursor: pointer;
9179
9209
  }
9180
9210
 
9181
- .hidden-comments-show:hover {
9211
+ .hidden-comments-show:hover,
9212
+ .hidden-severity-show:hover {
9182
9213
  text-decoration: underline;
9183
9214
  }
9184
9215
 
@@ -25,6 +25,21 @@ class AIPanel {
25
25
  </svg>`
26
26
  };
27
27
 
28
+ /** Browser-wide key for the severity sort; the hidden levels are saved per review. */
29
+ static SEVERITY_SORT_STORAGE_KEY = 'pair-review-severity-sort';
30
+
31
+ /** Smallest max-height (px) for the filter menu, so a low funnel still shows a few rows. */
32
+ static FILTER_MENU_MIN_HEIGHT = 120;
33
+
34
+ /** The SeverityFilter helpers (window global in the browser, require in tests). */
35
+ static severityFilter() {
36
+ if (typeof window !== 'undefined' && window.SeverityFilter) return window.SeverityFilter;
37
+ if (typeof module !== 'undefined' && module.exports && typeof require === 'function') {
38
+ return require('../utils/severity-filter.js');
39
+ }
40
+ throw new Error('SeverityFilter is not loaded');
41
+ }
42
+
28
43
  constructor() {
29
44
  this.panel = document.getElementById('ai-panel');
30
45
  // Check actual DOM state for collapsed status
@@ -53,6 +68,12 @@ class AIPanel {
53
68
  this.showDismissedComments = false;
54
69
  // User comments the filters hide, counted by PRManager from its data
55
70
  this.hiddenCommentCounts = { posted: 0, dismissed: 0 };
71
+ // Severity sort/filter for AI suggestions: the sort is browser-wide and
72
+ // the hidden severities are per review (see restoreSeverityState).
73
+ // severityHiddenCount is how many AI suggestions the filter hides, for
74
+ // the list notice.
75
+ this.severityState = AIPanel.severityFilter().defaultSeverityState();
76
+ this.severityHiddenCount = 0;
56
77
 
57
78
  this.initElements();
58
79
  this.bindEvents();
@@ -126,10 +147,11 @@ class AIPanel {
126
147
  }
127
148
 
128
149
  /**
129
- * Create the comment filter menu: a funnel button at the right of the
130
- * segment row that opens a small popover of labeled options. The options
131
- * only affect user comments. Local mode has no posted comments, so it
132
- * gets no "Show posted" option.
150
+ * Create the filter menu: a funnel button at the right of the segment row
151
+ * that opens a small popover of labeled options. The severity options sort
152
+ * and filter AI suggestions in the panel; the other options affect user
153
+ * comments. Local mode has no posted comments, so it gets no "Show posted"
154
+ * option.
133
155
  */
134
156
  createFilterMenu() {
135
157
  const wrapper = document.createElement('div');
@@ -146,13 +168,29 @@ class AIPanel {
146
168
  menu.className = 'comment-filter-menu';
147
169
  menu.id = 'comment-filter-menu';
148
170
  menu.setAttribute('role', 'group');
149
- menu.setAttribute('aria-label', 'User comment filters');
171
+ menu.setAttribute('aria-label', 'Review filters');
150
172
  menu.hidden = true;
151
173
  const postedOption = this._isLocalMode() ? '' : `
152
174
  <label class="comment-filter-option">
153
175
  <input type="checkbox" data-filter="showPosted"> Show posted
154
176
  </label>`;
177
+ const { SEVERITY_LEVELS, SEVERITY_LABELS } = AIPanel.severityFilter();
178
+ const severityOptions = SEVERITY_LEVELS.map(level => `
179
+ <label class="comment-filter-option">
180
+ <input type="checkbox" data-severity="${level}"> <span class="severity-option-label severity-option-${level}">${SEVERITY_LABELS[level]}</span>
181
+ </label>`).join('');
155
182
  menu.innerHTML = `
183
+ <div class="comment-filter-section" data-section="severity">
184
+ <div class="comment-filter-menu-title">Sort AI suggestions</div>
185
+ <label class="comment-filter-option">
186
+ <input type="radio" name="severity-sort" data-severity-sort="file"> File order
187
+ </label>
188
+ <label class="comment-filter-option">
189
+ <input type="radio" name="severity-sort" data-severity-sort="severity"> Severity
190
+ </label>
191
+ <div class="comment-filter-menu-title">Show in panel</div>${severityOptions}
192
+ </div>
193
+ <div class="comment-filter-menu-divider" role="separator"></div>
156
194
  <div class="comment-filter-menu-title">User comments</div>
157
195
  <label class="comment-filter-option">
158
196
  <input type="checkbox" data-filter="showDismissed"> Show dismissed
@@ -174,6 +212,17 @@ class AIPanel {
174
212
  });
175
213
  menu.addEventListener('change', (e) => {
176
214
  const input = e.target;
215
+ if (input?.dataset?.severitySort) {
216
+ if (input.checked) this.setSeverityState({ sort: input.dataset.severitySort });
217
+ return;
218
+ }
219
+ if (input?.dataset?.severity) {
220
+ const level = input.dataset.severity;
221
+ const hidden = this.severityState.hidden.filter(l => l !== level);
222
+ if (!input.checked) hidden.push(level);
223
+ this.setSeverityState({ hidden });
224
+ return;
225
+ }
177
226
  if (!input?.dataset?.filter) return;
178
227
  this.setCommentFilter({ [input.dataset.filter]: input.checked });
179
228
  });
@@ -212,8 +261,23 @@ class AIPanel {
212
261
  this.filterMenuBtn.setAttribute('aria-expanded', 'true');
213
262
  // Lift the segment row above the panel sections below it (pr.css)
214
263
  this.segmentControl?.classList.add('comment-filter-open');
264
+ this._fitFilterMenuToViewport();
215
265
  document.addEventListener('pointerdown', this._onFilterMenuOutsidePointer, true);
216
- this.filterMenu.querySelector('input')?.focus();
266
+ // Enter the menu on the checked radio, as native radio groups do
267
+ (this.filterMenu.querySelector('input:checked') || this.filterMenu.querySelector('input'))?.focus();
268
+ }
269
+
270
+ /**
271
+ * Limit the open menu to the space below the funnel so it scrolls instead
272
+ * of running off the window (the page itself cannot scroll, and stacked
273
+ * layouts put the funnel low on the screen).
274
+ * @private
275
+ */
276
+ _fitFilterMenuToViewport() {
277
+ if (!this.filterMenu || !this.filterMenuBtn || typeof window === 'undefined') return;
278
+ const gap = 4 + 8; // menu offset below the button + breathing room at the window edge
279
+ const available = window.innerHeight - this.filterMenuBtn.getBoundingClientRect().bottom - gap;
280
+ this.filterMenu.style.maxHeight = `${Math.max(AIPanel.FILTER_MENU_MIN_HEIGHT, Math.floor(available))}px`;
217
281
  }
218
282
 
219
283
  /**
@@ -332,9 +396,13 @@ class AIPanel {
332
396
  */
333
397
  updateFilterMenuVisual() {
334
398
  if (!this.filterMenuBtn) return;
335
- const nonDefault = this.isCommentFilterNonDefault();
399
+ // The dot means "this review hides something". The severity sort is a
400
+ // browser-wide preference, so like the browser-wide "hide posted"
401
+ // setting it never lights the dot; hidden severities do.
402
+ const nonDefault = this.isCommentFilterNonDefault()
403
+ || this.severityState.hidden.length > 0;
336
404
  this.filterMenuBtn.classList.toggle('has-active-filter', nonDefault);
337
- const label = nonDefault ? 'Filter user comments (filters on)' : 'Filter user comments';
405
+ const label = nonDefault ? 'Sort and filter (filters on)' : 'Sort and filter';
338
406
  this.filterMenuBtn.title = label;
339
407
  this.filterMenuBtn.setAttribute('aria-label', label);
340
408
 
@@ -343,6 +411,65 @@ class AIPanel {
343
411
  if (dismissedInput) dismissedInput.checked = state.includeDismissed;
344
412
  const postedInput = this.filterMenu?.querySelector('input[data-filter="showPosted"]');
345
413
  if (postedInput) postedInput.checked = state.showPosted;
414
+
415
+ const { sort, hidden } = this.severityState;
416
+ this.filterMenu?.querySelectorAll('input[data-severity-sort]').forEach(input => {
417
+ input.checked = input.dataset.severitySort === sort;
418
+ });
419
+ this.filterMenu?.querySelectorAll('input[data-severity]').forEach(input => {
420
+ input.checked = !hidden.includes(input.dataset.severity);
421
+ });
422
+ }
423
+
424
+ /**
425
+ * Change the AI suggestion severity sort/filter as the user asked: persist
426
+ * it, update the menu and re-render the list. AI suggestions are already
427
+ * loaded, so nothing reloads.
428
+ * @param {{sort?: 'file'|'severity', hidden?: string[]}} updates
429
+ * @returns {boolean} Whether anything changed
430
+ */
431
+ setSeverityState(updates = {}) {
432
+ const lib = AIPanel.severityFilter();
433
+ const next = lib.parseSeverityState({ ...this.severityState, ...updates });
434
+ const prev = this.severityState;
435
+ const sortChanged = next.sort !== prev.sort;
436
+ const hiddenChanged = next.hidden.join() !== prev.hidden.join();
437
+ const changed = sortChanged || hiddenChanged;
438
+ // Navigation updates the index, so capture its identity using the old
439
+ // sort/filter before changing which items that index refers to.
440
+ if (changed) this.saveCurrentSelection();
441
+ this.severityState = next;
442
+ this.updateFilterMenuVisual();
443
+ if (!changed) return false;
444
+
445
+ this.saveSeverityState({ sort: sortChanged, hidden: hiddenChanged });
446
+ this.renderFindings();
447
+ if (!this.restoreSelection()) {
448
+ this.selectedItemKey = null;
449
+ this.currentIndex = -1;
450
+ this.autoSelectFirst();
451
+ }
452
+ return true;
453
+ }
454
+
455
+ /** Show every severity again (the notice's Show button). Keeps the sort. */
456
+ showAllSeverities() {
457
+ return this.setSeverityState({ hidden: [] });
458
+ }
459
+
460
+ /**
461
+ * The muted "N AI suggestions hidden from this list — Show all" line, or ''
462
+ * when the severity filter hides nothing in this segment.
463
+ */
464
+ renderHiddenSeverityNotice() {
465
+ const count = this.severityHiddenCount;
466
+ if (!count || (this.selectedSegment !== 'ai' && this.selectedSegment !== 'all')) return '';
467
+ const noun = count === 1 ? 'AI suggestion' : 'AI suggestions';
468
+ return `
469
+ <div class="hidden-severity-notice">
470
+ <span>${count} ${noun} hidden from this list</span> —
471
+ <button type="button" class="hidden-severity-show" aria-label="Show AI suggestions of every severity">Show all</button>
472
+ </div>`;
346
473
  }
347
474
 
348
475
  /**
@@ -484,6 +611,67 @@ class AIPanel {
484
611
  return `pair-review-show-posted_${this.currentPRKey}`;
485
612
  }
486
613
 
614
+ /**
615
+ * Get the localStorage key for this review's hidden severities (per-review).
616
+ * The sort is browser-wide instead (AIPanel.SEVERITY_SORT_STORAGE_KEY): it
617
+ * is how the reviewer likes to work, while which severities to hide
618
+ * depends on the review.
619
+ * @returns {string|null} Storage key or null if no PR context
620
+ */
621
+ getSeverityStorageKey() {
622
+ if (!this.currentPRKey) return null;
623
+ return `pair-review-severity-hidden_${this.currentPRKey}`;
624
+ }
625
+
626
+ /**
627
+ * Save what the reviewer changed: the severity sort (browser-wide, last
628
+ * choice wins) and/or this review's hidden severities. A tab only writes
629
+ * the setting it changed, so another tab's choice for the other one is
630
+ * never overwritten with this tab's stale copy. Default values remove the
631
+ * entry.
632
+ * @param {{sort?: boolean, hidden?: boolean}} [scope] - What to write (both by default)
633
+ */
634
+ saveSeverityState({ sort: saveSort = true, hidden: saveHidden = true } = {}) {
635
+ const { sort, hidden } = this.severityState;
636
+ if (saveSort) {
637
+ if (sort === 'file') {
638
+ localStorage.removeItem(AIPanel.SEVERITY_SORT_STORAGE_KEY);
639
+ } else {
640
+ localStorage.setItem(AIPanel.SEVERITY_SORT_STORAGE_KEY, sort);
641
+ }
642
+ }
643
+
644
+ const key = this.getSeverityStorageKey();
645
+ if (saveHidden && key) {
646
+ if (hidden.length === 0) {
647
+ localStorage.removeItem(key);
648
+ } else {
649
+ localStorage.setItem(key, JSON.stringify(hidden));
650
+ }
651
+ }
652
+ }
653
+
654
+ /**
655
+ * Restore the severity sort (browser-wide) and this review's hidden
656
+ * severities. Missing or corrupt entries fall back to the defaults.
657
+ */
658
+ restoreSeverityState() {
659
+ const lib = AIPanel.severityFilter();
660
+ const sort = localStorage.getItem(AIPanel.SEVERITY_SORT_STORAGE_KEY);
661
+
662
+ let hidden = [];
663
+ const key = this.getSeverityStorageKey();
664
+ const storedHidden = key ? localStorage.getItem(key) : null;
665
+ if (storedHidden) {
666
+ try {
667
+ hidden = JSON.parse(storedHidden);
668
+ } catch {
669
+ hidden = [];
670
+ }
671
+ }
672
+ this.severityState = lib.parseSeverityState({ sort, hidden });
673
+ }
674
+
487
675
  /**
488
676
  * Save the "Show dismissed" filter to localStorage (per-review)
489
677
  */
@@ -509,6 +697,7 @@ class AIPanel {
509
697
  const key = this.getFilterStorageKey();
510
698
  // Default to false (hidden) for new reviews
511
699
  this.showDismissedComments = key ? localStorage.getItem(key) === 'true' : false;
700
+ this.restoreSeverityState();
512
701
 
513
702
  // "Show posted": this review's override, if any. Local mode has no
514
703
  // posted comments and so no override.
@@ -565,8 +754,10 @@ class AIPanel {
565
754
  setPR(owner, repo, number) {
566
755
  this.currentPRKey = `${owner}/${repo}#${number}`;
567
756
  this._restoreOrCollapsePanel();
568
- this.restoreSegmentSelection();
757
+ // Restore the filters first: restoreSegmentSelection renders the list,
758
+ // and the render must see this review's severity sort and filter.
569
759
  this.restoreFilterState();
760
+ this.restoreSegmentSelection();
570
761
 
571
762
  // If the external-comment manager finished its initial fetch BEFORE
572
763
  // the panel was wired up (race on slow loads), pull the threads it
@@ -908,8 +1099,13 @@ class AIPanel {
908
1099
  break;
909
1100
  }
910
1101
 
911
- // Sort by canonical file order, then file-level first, then line number
912
- return this.sortItemsByFileOrder(items);
1102
+ // Sort by canonical file order, then file-level first, then line
1103
+ // number; then apply the severity filter and (optional) severity sort,
1104
+ // which is stable so equal severities stay in file order.
1105
+ const result = AIPanel.severityFilter().applySeverityState(
1106
+ this.sortItemsByFileOrder(items), this.severityState);
1107
+ this.severityHiddenCount = result.hiddenCount;
1108
+ return result.items;
913
1109
  }
914
1110
 
915
1111
  /**
@@ -976,7 +1172,7 @@ class AIPanel {
976
1172
 
977
1173
  const items = this.getFilteredItems();
978
1174
  // "N posted · M dismissed hidden — Show", or '' when nothing is hidden
979
- const hiddenNotice = this.renderHiddenCommentsNotice();
1175
+ const hiddenNotice = this.renderHiddenSeverityNotice() + this.renderHiddenCommentsNotice();
980
1176
 
981
1177
  // Show empty state based on segment and analysis state
982
1178
  if (items.length === 0) {
@@ -993,6 +1189,14 @@ class AIPanel {
993
1189
  <div class="empty-state-title">No comments yet</div>
994
1190
  <div class="empty-state-description">Click the <strong>+</strong> button next to any line to add a comment.</div>
995
1191
  `;
1192
+ } else if ((this.selectedSegment === 'ai' || this.selectedSegment === 'all')
1193
+ && this.severityHiddenCount > 0) {
1194
+ // Nothing else to show (in All: no comments or threads either)
1195
+ emptyContent = `
1196
+ <div class="empty-state-icon">${this.getEmptyStateIcon('sparkle')}</div>
1197
+ <div class="empty-state-title">No suggestions shown</div>
1198
+ <div class="empty-state-description">The severity filter hides every AI suggestion.</div>
1199
+ `;
996
1200
  } else if (this.selectedSegment === 'ai') {
997
1201
  // Show different states based on analysis status
998
1202
  if (this.analysisState === 'loading') {
@@ -1140,6 +1344,13 @@ class AIPanel {
1140
1344
  this.showHiddenComments();
1141
1345
  });
1142
1346
  }
1347
+ const severityBtn = this.findingsList?.querySelector('.hidden-severity-show');
1348
+ if (severityBtn) {
1349
+ severityBtn.addEventListener('click', (e) => {
1350
+ e.stopPropagation();
1351
+ this.showAllSeverities();
1352
+ });
1353
+ }
1143
1354
  }
1144
1355
 
1145
1356
  /**
package/public/js/pr.js CHANGED
@@ -7835,16 +7835,20 @@ class PRManager {
7835
7835
  return 'modified';
7836
7836
  }
7837
7837
 
7838
- groupFilesByDirectory(files) {
7839
- const groups = {};
7840
- files.forEach(file => {
7838
+ /**
7839
+ * Build the file navigator's directory tree. Directories that only contain
7840
+ * a single subdirectory are collapsed into one node (e.g. `src/js/utils`),
7841
+ * so long shared prefixes take one row instead of one row per segment.
7842
+ * @param {Array} files - Diff/context file entries
7843
+ * @returns {Object} Root node from FileOrderUtils.buildDirectoryTree whose
7844
+ * `files` are navigator items and `dirs` are nested nodes
7845
+ */
7846
+ buildFileNavigatorTree(files) {
7847
+ const items = files.map(file => {
7841
7848
  const filePath = file.file;
7842
7849
  const lastSlashIndex = filePath.lastIndexOf('/');
7843
- const dirPath = lastSlashIndex === -1 ? '.' : filePath.substring(0, lastSlashIndex);
7844
7850
  const fileName = lastSlashIndex === -1 ? filePath : filePath.substring(lastSlashIndex + 1);
7845
-
7846
- if (!groups[dirPath]) groups[dirPath] = [];
7847
- groups[dirPath].push({
7851
+ return {
7848
7852
  name: fileName,
7849
7853
  fullPath: filePath,
7850
7854
  status: this.getFileStatus(file),
@@ -7859,14 +7863,9 @@ class PRManager {
7859
7863
  label: file.label || null,
7860
7864
  lineStart: file.lineStart || null,
7861
7865
  lineEnd: file.lineEnd || null,
7862
- });
7863
- });
7864
-
7865
- const sortedGroups = {};
7866
- Object.keys(groups).sort().forEach(key => {
7867
- sortedGroups[key] = groups[key];
7866
+ };
7868
7867
  });
7869
- return sortedGroups;
7868
+ return window.FileOrderUtils.buildDirectoryTree(items, item => item.fullPath);
7870
7869
  }
7871
7870
 
7872
7871
  updateFileList(files) {
@@ -7887,22 +7886,27 @@ class PRManager {
7887
7886
  return;
7888
7887
  }
7889
7888
 
7890
- const groupedFiles = this.groupFilesByDirectory(files);
7889
+ const tree = this.buildFileNavigatorTree(files);
7891
7890
  fileListContainer.innerHTML = '';
7892
7891
 
7893
- for (const [dirPath, dirFiles] of Object.entries(groupedFiles)) {
7894
- const groupElement = this.renderFileGroup(dirPath, dirFiles);
7895
- fileListContainer.appendChild(groupElement);
7896
- }
7892
+ // Root-level files sit directly in the list, followed by top-level folders
7893
+ tree.files.forEach(file => fileListContainer.appendChild(this.renderFileItem(file)));
7894
+ tree.dirs.forEach(dir => fileListContainer.appendChild(this.renderFileGroup(dir)));
7897
7895
  }
7898
7896
 
7899
- renderFileGroup(dirPath, files) {
7897
+ /**
7898
+ * Render a directory node and, recursively, its subdirectories.
7899
+ * @param {{name: string, path: string, files: Array, dirs: Array}} node
7900
+ * @returns {HTMLElement}
7901
+ */
7902
+ renderFileGroup(node) {
7900
7903
  const group = document.createElement('div');
7901
7904
  group.className = 'file-group';
7902
- group.dataset.path = dirPath;
7905
+ group.dataset.path = node.path;
7903
7906
 
7904
7907
  const header = document.createElement('div');
7905
7908
  header.className = 'file-group-header';
7909
+ header.title = node.path;
7906
7910
 
7907
7911
  const chevron = document.createElement('span');
7908
7912
  chevron.className = 'file-group-chevron';
@@ -7913,7 +7917,8 @@ class PRManager {
7913
7917
  folderIcon.innerHTML = `<svg viewBox="0 0 16 16" fill="currentColor" width="14" height="14"><path d="M1.75 1A1.75 1.75 0 000 2.75v10.5C0 14.216.784 15 1.75 15h12.5A1.75 1.75 0 0016 13.25v-8.5A1.75 1.75 0 0014.25 3H7.5a.25.25 0 01-.2-.1l-.9-1.2C6.07 1.26 5.55 1 5 1H1.75z"/></svg>`;
7914
7918
 
7915
7919
  const dirName = document.createElement('span');
7916
- dirName.textContent = dirPath === '.' ? '(root)' : dirPath;
7920
+ dirName.className = 'file-group-name';
7921
+ dirName.textContent = node.name;
7917
7922
 
7918
7923
  header.appendChild(chevron);
7919
7924
  header.appendChild(folderIcon);
@@ -7923,10 +7928,8 @@ class PRManager {
7923
7928
  const fileList = document.createElement('div');
7924
7929
  fileList.className = 'file-group-items';
7925
7930
 
7926
- files.forEach(file => {
7927
- const fileItem = this.renderFileItem(file);
7928
- fileList.appendChild(fileItem);
7929
- });
7931
+ node.files.forEach(file => fileList.appendChild(this.renderFileItem(file)));
7932
+ node.dirs.forEach(dir => fileList.appendChild(this.renderFileGroup(dir)));
7930
7933
 
7931
7934
  group.appendChild(fileList);
7932
7935
  group.classList.add('expanded');
@@ -2,41 +2,47 @@
2
2
  /**
3
3
  * File ordering utilities for consistent file display across components.
4
4
  *
5
- * This module provides functions to sort files to match the file navigator's
6
- * directory-grouped ordering, ensuring consistency across all panels.
5
+ * This module provides functions to build the file navigator's directory tree
6
+ * and to sort files in the same order, ensuring consistency across all panels.
7
7
  */
8
8
 
9
9
  /**
10
- * Extract the directory path from a file path.
11
- * @param {string} filePath - Full file path
12
- * @returns {string} Directory path (or '.' for root-level files)
10
+ * Compare two file paths in file-navigator tree order.
11
+ *
12
+ * Paths are compared directory segment by directory segment. Within any
13
+ * directory, its own files come before its subdirectories; siblings are
14
+ * sorted alphabetically (numeric-aware, so file2 < file10).
15
+ *
16
+ * @param {string} pathA
17
+ * @param {string} pathB
18
+ * @returns {number} Negative, zero or positive, like Array#sort comparators
13
19
  */
14
- function getDirectoryPath(filePath) {
15
- const lastSlashIndex = filePath.lastIndexOf('/');
16
- return lastSlashIndex === -1 ? '.' : filePath.substring(0, lastSlashIndex);
17
- }
20
+ function compareFilePaths(pathA, pathB) {
21
+ const dirsA = pathA.split('/');
22
+ const dirsB = pathB.split('/');
23
+ const nameA = dirsA.pop();
24
+ const nameB = dirsB.pop();
18
25
 
19
- /**
20
- * Extract the file name from a file path.
21
- * @param {string} filePath - Full file path
22
- * @returns {string} File name
23
- */
24
- function getFileName(filePath) {
25
- const lastSlashIndex = filePath.lastIndexOf('/');
26
- return lastSlashIndex === -1 ? filePath : filePath.substring(lastSlashIndex + 1);
26
+ const shared = Math.min(dirsA.length, dirsB.length);
27
+ for (let i = 0; i < shared; i++) {
28
+ const cmp = dirsA[i].localeCompare(dirsB[i], undefined, { numeric: true });
29
+ if (cmp !== 0) return cmp;
30
+ }
31
+
32
+ // One directory contains the other: the file directly in the shallower
33
+ // directory comes first (files before subdirectories).
34
+ if (dirsA.length !== dirsB.length) return dirsA.length - dirsB.length;
35
+
36
+ return nameA.localeCompare(nameB, undefined, { numeric: true });
27
37
  }
28
38
 
29
39
  /**
30
- * Sort files to match the file navigator's directory-grouped ordering.
40
+ * Sort files to match the file navigator's tree ordering.
31
41
  *
32
- * The file navigator uses groupFilesByDirectory which:
33
- * 1. Groups files by their directory path
34
- * 2. Sorts directory keys alphabetically
35
- * 3. Within each directory group, files are sorted alphabetically by filename
36
- *
37
- * To match this behavior, we sort by:
38
- * 1. Directory path (alphabetically)
39
- * 2. Then by filename (alphabetically, with numeric sorting for numbered files)
42
+ * The file navigator renders a nested directory tree (see buildDirectoryTree)
43
+ * in which each directory lists its files first, then its subdirectories,
44
+ * each alphabetically. Sorting with the same rules keeps every panel in the
45
+ * same order as the navigator.
40
46
  *
41
47
  * @param {Array} files - Array of file objects with a `file` property containing the path
42
48
  * @returns {Array} New array sorted to match file navigator order
@@ -44,21 +50,75 @@ function getFileName(filePath) {
44
50
  function sortFilesByPath(files) {
45
51
  if (!Array.isArray(files)) return [];
46
52
 
47
- return [...files].sort((a, b) => {
48
- const pathA = a.file || '';
49
- const pathB = b.file || '';
53
+ return [...files].sort((a, b) => compareFilePaths(a.file || '', b.file || ''));
54
+ }
50
55
 
51
- // First, compare by directory path
52
- const dirA = getDirectoryPath(pathA);
53
- const dirB = getDirectoryPath(pathB);
54
- const dirCompare = dirA.localeCompare(dirB, undefined, { numeric: true });
55
- if (dirCompare !== 0) return dirCompare;
56
+ /**
57
+ * Build a nested directory tree for the file navigator, collapsing
58
+ * single-child directory chains into one node (like GitHub's sidebar).
59
+ *
60
+ * For `root/foo/bar/xyz/example.rb`, `root/foo/bar/index.md` and
61
+ * `root/foo/README.md` this produces:
62
+ *
63
+ * root/foo
64
+ * README.md
65
+ * bar
66
+ * index.md
67
+ * xyz
68
+ * example.rb
69
+ *
70
+ * A directory is merged into its parent when the parent has no files of its
71
+ * own and exactly one subdirectory. Root-level files stay on the root node.
72
+ *
73
+ * @param {Array<T>} items - Items to place in the tree
74
+ * @param {function(T): string} [getPath] - Returns an item's path (defaults to `item.file`)
75
+ * @returns {{name: string, path: string, files: Array<T>, dirs: Array}} Root node;
76
+ * `name` is the label to display (may contain slashes after collapsing),
77
+ * `path` is the full directory path ('' for the root). Files and dirs are sorted.
78
+ * @template T
79
+ */
80
+ function buildDirectoryTree(items, getPath = item => item.file) {
81
+ const makeNode = (name, path) => ({ name, path, files: [], dirs: [], _children: new Map() });
82
+ const root = makeNode('', '');
56
83
 
57
- // Within same directory, sort by filename (with numeric sorting for files like file2.js, file10.js)
58
- const nameA = getFileName(pathA);
59
- const nameB = getFileName(pathB);
60
- return nameA.localeCompare(nameB, undefined, { numeric: true });
84
+ (Array.isArray(items) ? items : []).forEach(item => {
85
+ const segments = (getPath(item) || '').split('/');
86
+ segments.pop();
87
+ let node = root;
88
+ segments.forEach(segment => {
89
+ if (!node._children.has(segment)) {
90
+ const childPath = node.path ? `${node.path}/${segment}` : segment;
91
+ node._children.set(segment, makeNode(segment, childPath));
92
+ }
93
+ node = node._children.get(segment);
94
+ });
95
+ node.files.push(item);
61
96
  });
97
+
98
+ const fileName = item => (getPath(item) || '').split('/').pop();
99
+ const byName = (a, b) => a.localeCompare(b, undefined, { numeric: true });
100
+
101
+ const finalize = (node, isRoot) => {
102
+ let current = node;
103
+ // Collapse chains of directories that only contain one subdirectory
104
+ while (!isRoot && current.files.length === 0 && current._children.size === 1) {
105
+ const [only] = current._children.values();
106
+ only.name = `${current.name}/${only.name}`;
107
+ current = only;
108
+ }
109
+ // Sort before collapsing: each child's name is still a single path segment
110
+ // here, matching how compareFilePaths orders directories. Sorting collapsed
111
+ // labels like "foo/bar" would put "foo-x" first, since '-' sorts before '/'.
112
+ // Collapsing never reorders siblings: a collapsed node keeps its first segment.
113
+ current.dirs = [...current._children.values()]
114
+ .sort((a, b) => byName(a.name, b.name))
115
+ .map(child => finalize(child, false));
116
+ current.files.sort((a, b) => byName(fileName(a), fileName(b)));
117
+ delete current._children;
118
+ return current;
119
+ };
120
+
121
+ return finalize(root, true);
62
122
  }
63
123
 
64
124
  /**
@@ -82,6 +142,8 @@ function createFileOrderMap(files) {
82
142
 
83
143
  // Export to window for use in other modules
84
144
  window.FileOrderUtils = {
145
+ compareFilePaths,
85
146
  sortFilesByPath,
147
+ buildDirectoryTree,
86
148
  createFileOrderMap
87
149
  };
@@ -0,0 +1,139 @@
1
+ // Copyright 2026 Tim Perkins (tjwp) | SPDX-License-Identifier: Apache-2.0
2
+ /**
3
+ * Severity sort and filter for AI suggestions in the Review panel.
4
+ *
5
+ * AI suggestions carry `severity` of "critical", "medium" or "minor"; praise
6
+ * and older suggestions have none, which this module treats as "none".
7
+ * The state is plain data: { sort: 'file' | 'severity', hidden: ['minor', 'none', ...] }.
8
+ * AIPanel saves the sort browser-wide and the hidden levels per review.
9
+ * Only AI suggestions are filtered; user comments and external threads always
10
+ * pass, and sort after every AI suggestion when sorting by severity.
11
+ */
12
+ (function () {
13
+ /** Severity levels, most severe first. "none" covers praise and unset. */
14
+ const SEVERITY_LEVELS = ['critical', 'medium', 'minor', 'none'];
15
+
16
+ const SEVERITY_LABELS = {
17
+ critical: 'Critical',
18
+ medium: 'Medium',
19
+ minor: 'Minor',
20
+ none: 'No severity'
21
+ };
22
+
23
+ const SORT_MODES = ['file', 'severity'];
24
+
25
+ /**
26
+ * Other names providers use for the three levels. Severity is free text
27
+ * from the provider (executable providers pass a tool's own value through),
28
+ * so "high" must not fall into "none" with praise.
29
+ */
30
+ const SEVERITY_ALIASES = {
31
+ blocker: 'critical',
32
+ severe: 'critical',
33
+ high: 'critical',
34
+ error: 'critical',
35
+ major: 'medium',
36
+ moderate: 'medium',
37
+ warning: 'medium',
38
+ low: 'minor',
39
+ trivial: 'minor',
40
+ info: 'minor',
41
+ nit: 'minor'
42
+ };
43
+
44
+ /** @returns {'critical'|'medium'|'minor'|'none'} */
45
+ function normalizeSeverity(severity) {
46
+ const value = typeof severity === 'string' ? severity.trim().toLowerCase() : '';
47
+ if (Object.hasOwn(SEVERITY_ALIASES, value)) return SEVERITY_ALIASES[value];
48
+ return SEVERITY_LEVELS.includes(value) && value !== 'none' ? value : 'none';
49
+ }
50
+
51
+ /** @returns {{sort: string, hidden: string[]}} */
52
+ function defaultSeverityState() {
53
+ return { sort: 'file', hidden: [] };
54
+ }
55
+
56
+ /**
57
+ * Validate a state object (e.g. built from storage): unknown sort modes fall
58
+ * back to 'file', unknown or repeated levels are dropped. Anything that is
59
+ * not an object gives the default state.
60
+ * @param {{sort?: string, hidden?: string[]}} value
61
+ * @returns {{sort: string, hidden: string[]}}
62
+ */
63
+ function parseSeverityState(value) {
64
+ if (!value || typeof value !== 'object') return defaultSeverityState();
65
+ const sort = SORT_MODES.includes(value.sort) ? value.sort : 'file';
66
+ const hiddenInput = Array.isArray(value.hidden) ? value.hidden : [];
67
+ // Keep canonical order so equal states serialize the same way
68
+ const hidden = SEVERITY_LEVELS.filter(level => hiddenInput.includes(level));
69
+ return { sort, hidden };
70
+ }
71
+
72
+ function isFinding(item) {
73
+ return item?._itemType === 'finding';
74
+ }
75
+
76
+ /**
77
+ * Drop AI suggestions whose severity is hidden. Other items pass.
78
+ * @param {Array} items - Items with _itemType
79
+ * @param {{hidden: string[]}} state
80
+ * @returns {{items: Array, hiddenCount: number}}
81
+ */
82
+ function filterBySeverity(items, state) {
83
+ const hidden = new Set(parseSeverityState(state).hidden);
84
+ const list = Array.isArray(items) ? items : [];
85
+ if (hidden.size === 0) return { items: [...list], hiddenCount: 0 };
86
+ const kept = list.filter(item => !isFinding(item) || !hidden.has(normalizeSeverity(item.severity)));
87
+ return { items: kept, hiddenCount: list.length - kept.length };
88
+ }
89
+
90
+ /** Sort rank: severity index for AI suggestions, after all of them for anything else. */
91
+ function severityRank(item) {
92
+ if (!isFinding(item)) return SEVERITY_LEVELS.length;
93
+ return SEVERITY_LEVELS.indexOf(normalizeSeverity(item.severity));
94
+ }
95
+
96
+ /**
97
+ * Stable sort by severity, most severe first. Items of equal rank keep
98
+ * their incoming order, so pass items already in file order.
99
+ * @param {Array} items
100
+ * @returns {Array} New array
101
+ */
102
+ function sortBySeverity(items) {
103
+ const list = Array.isArray(items) ? items : [];
104
+ return list
105
+ .map((item, index) => ({ item, index, rank: severityRank(item) }))
106
+ .sort((a, b) => (a.rank - b.rank) || (a.index - b.index))
107
+ .map(entry => entry.item);
108
+ }
109
+
110
+ /**
111
+ * Filter then (when state.sort is 'severity') sort.
112
+ * @returns {{items: Array, hiddenCount: number}}
113
+ */
114
+ function applySeverityState(items, state) {
115
+ const parsed = parseSeverityState(state);
116
+ const result = filterBySeverity(items, parsed);
117
+ if (parsed.sort === 'severity') result.items = sortBySeverity(result.items);
118
+ return result;
119
+ }
120
+
121
+ const SeverityFilter = {
122
+ SEVERITY_LEVELS,
123
+ SEVERITY_LABELS,
124
+ SORT_MODES,
125
+ normalizeSeverity,
126
+ defaultSeverityState,
127
+ parseSeverityState,
128
+ filterBySeverity,
129
+ sortBySeverity,
130
+ applySeverityState
131
+ };
132
+
133
+ if (typeof window !== 'undefined') {
134
+ window.SeverityFilter = SeverityFilter;
135
+ }
136
+ if (typeof module !== 'undefined' && module.exports) {
137
+ module.exports = SeverityFilter;
138
+ }
139
+ })();
package/public/local.html CHANGED
@@ -599,6 +599,7 @@
599
599
 
600
600
  <!-- File order utility -->
601
601
  <script src="/js/utils/file-order.js"></script>
602
+ <script src="/js/utils/severity-filter.js"></script>
602
603
 
603
604
  <!-- Timestamp parsing utility -->
604
605
  <script src="/js/utils/time.js"></script>
package/public/pr.html CHANGED
@@ -404,6 +404,7 @@
404
404
 
405
405
  <!-- File order utility -->
406
406
  <script src="/js/utils/file-order.js"></script>
407
+ <script src="/js/utils/severity-filter.js"></script>
407
408
 
408
409
  <!-- Timestamp parsing utility -->
409
410
  <script src="/js/utils/time.js"></script>