@in-the-loop-labs/pair-review 4.1.0 → 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 (71) 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/ai/codex-provider.js +59 -11
  46. package/src/chat/api-reference.js +9 -5
  47. package/src/chat/prompt-builder.js +8 -1
  48. package/src/config.js +15 -6
  49. package/src/database.js +307 -14
  50. package/src/external/github-adapter.js +39 -5
  51. package/src/headless/delegate.js +682 -0
  52. package/src/local-review.js +10 -10
  53. package/src/local-scope.js +9 -0
  54. package/src/main.js +276 -157
  55. package/src/mcp-stdio.js +24 -1
  56. package/src/review-config.js +93 -25
  57. package/src/routes/chat.js +2 -2
  58. package/src/routes/config.js +12 -10
  59. package/src/routes/external-comments.js +5 -1
  60. package/src/routes/local.js +2 -4
  61. package/src/routes/mcp.js +18 -13
  62. package/src/routes/reviews.js +223 -4
  63. package/src/routes/settings.js +252 -0
  64. package/src/routes/setup.js +80 -1
  65. package/src/routes/shared.js +31 -29
  66. package/src/routes/snippets.js +154 -0
  67. package/src/routes/stack-analysis.js +17 -14
  68. package/src/server.js +86 -18
  69. package/src/settings/global-settings-service.js +472 -0
  70. package/src/settings/registry.js +624 -0
  71. package/src/utils/db-identity.js +44 -0
@@ -2,12 +2,26 @@
2
2
  /**
3
3
  * TourRenderer - Inline tour-stop annotations + body-level tour mode.
4
4
  *
5
+ * DUAL RENDERING PATH — a stop's file is rendered by ONE of two engines:
6
+ * - PIERRE (@pierre/diffs): the file lives in a shadow-DOM
7
+ * `<diffs-container>` with NO light-DOM `<tr>` rows. The stop mounts as a
8
+ * custom `'tour-stop'` annotation (via PierreBridge.addAnnotation), which
9
+ * the bridge slots BELOW its anchor line into the file's light DOM as a
10
+ * `<div class="tour-annotation-row">`. A file is pierre-rendered iff
11
+ * `prManager.pierreBridge.files.has(filePath)`.
12
+ * - LEGACY (table renderer): context files added via ensureContextFile
13
+ * still render as an HTML table. The stop mounts as a
14
+ * `<tr class="tour-annotation-row">` inserted immediately ABOVE the
15
+ * anchor row.
16
+ * Both variants carry the SAME inner `.tour-annotation` card (title, full
17
+ * description, Chat-about button; Prev/Next lives on the TourBar) and the
18
+ * same `data-stop-index`, so page CSS and the navigator code are agnostic to
19
+ * which path mounted them.
20
+ *
5
21
  * Responsibilities:
6
- * - Look up the DOM anchor row for a stop by (file_path, side, line_start).
7
- * - Mount a styled <tr class="tour-annotation-row"> immediately above the
8
- * anchor row, carrying the stop's title + description and Prev/Next
9
- * buttons that callback into the owning PRManager.
10
- * - Track the currently-highlighted row and toggle the `active-stop` class.
22
+ * - Resolve a stop's anchor line by (file_path, side, [line_start, line_end])
23
+ * and mount its annotation via the correct engine.
24
+ * - Track the currently-highlighted stop and toggle the `active-stop` class.
11
25
  * - Toggle the `body.tour-active` class for tour-specific chrome styling
12
26
  * (sticky tour-bar offsets on .diff-toolbar / .d2h-file-header, plus
13
27
  * the active-stop annotation highlight). Hunk summaries and tour stops
@@ -15,12 +29,11 @@
15
29
  * toggles each independently.
16
30
  *
17
31
  * Stops are line-range based (see plans/semantic-hunk-summaries-and-tours.md);
18
- * there is NO content_hash on stops. The anchor row is found via the
19
- * diff-renderer's existing `data-line-number` + `data-side` attributes.
32
+ * there is NO content_hash on stops.
20
33
  *
21
- * A stop whose anchor row is missing (file filtered out, line not in the
22
- * rendered diff, etc.) is skipped with a console.warn — the caller treats
23
- * a null return as "couldn't render, advance to the next stop".
34
+ * A stop whose anchor is missing (file filtered out, line not in the rendered
35
+ * diff, etc.) is skipped with a console.warn — the caller treats a null
36
+ * return as "couldn't render, advance to the next stop".
24
37
  *
25
38
  * Before calling `mountStop`, the caller should `await prepareStop(index)`,
26
39
  * which makes the stop's lines mountable when possible:
@@ -63,8 +76,29 @@ class TourRenderer {
63
76
  constructor(prManager) {
64
77
  this.prManager = prManager;
65
78
  this._stops = [];
66
- // Map<number, HTMLTableRowElement> — stop index -> mounted row
79
+ // Map<number, HTMLElement> — stop index -> mounted annotation element.
80
+ // For LEGACY (table-rendered) files this is the injected
81
+ // `<tr class="tour-annotation-row">`. For PIERRE-rendered files it is
82
+ // the last-known `<div class="tour-annotation-row">` slotted into the
83
+ // file's light DOM — that div is RE-CREATED on every FileDiff rerender,
84
+ // so the cached reference can go stale; always re-resolve the live node
85
+ // via `_resolveRow(index)` before operating on it.
67
86
  this._mounted = new Map();
87
+ // Map<number, {filePath, side, id, anchorLine}> — pierre-mounted stops.
88
+ // Presence here marks a stop as living inside a @pierre/diffs shadow-DOM
89
+ // file (annotation-based) rather than a legacy injected <tr>. Holds the
90
+ // metadata needed to remove the annotation (bridge.removeAnnotation) and
91
+ // re-query the live slotted element after a rerender.
92
+ this._pierreMounts = new Map();
93
+ // The index highlighted as the active stop, or -1. Tracked on the
94
+ // instance (not just the DOM) because a pierre annotation element is
95
+ // rebuilt on every file rerender — the renderer callback re-applies the
96
+ // `active-stop` class from this value so the highlight survives churn.
97
+ this._activeIndex = -1;
98
+ // One-time guard: the 'tour-stop' custom annotation renderer is
99
+ // registered on the shared PierreBridge exactly once (it persists on the
100
+ // bridge across tours).
101
+ this._tourStopRendererRegistered = false;
68
102
  // Set<string> — file paths that we auto-expanded during this tour so we
69
103
  // can re-collapse them on exit. Tracking this lets us preserve the
70
104
  // user's pre-tour collapse state (the user-facing `collapsedFiles` set
@@ -75,12 +109,6 @@ class TourRenderer {
75
109
  // PR diff. Removed in unmountAll so the user's persistent context-files
76
110
  // list isn't polluted by transient tour state.
77
111
  this._autoAddedContextFileIds = new Set();
78
- // Set<number> — stop indices whose description the user has expanded
79
- // via "Show more". Survives unmount/remount within the same tour
80
- // session (e.g. when the user scrolls past, then back to, the stop)
81
- // so the description doesn't snap back to its clamped form. Cleared
82
- // when setStops replaces the tour entirely.
83
- this._expandedDescriptions = new Set();
84
112
  // Cache the user's motion preference at construction so scrollIntoView
85
113
  // honors it on every navigation. Reading matchMedia each call would
86
114
  // still work; caching just avoids the lookup.
@@ -105,10 +133,7 @@ class TourRenderer {
105
133
  setStops(stops) {
106
134
  this.unmountAll();
107
135
  this._stops = Array.isArray(stops) ? stops : [];
108
- // A new stops list silently remaps indices; previously-expanded entries
109
- // would point at the wrong descriptions. Reset rather than carry stale
110
- // state across.
111
- this._expandedDescriptions.clear();
136
+ this._activeIndex = -1;
112
137
  }
113
138
 
114
139
  /**
@@ -264,6 +289,171 @@ class TourRenderer {
264
289
  const stop = this._stops[index];
265
290
  if (!stop) return null;
266
291
 
292
+ const filePath = stop.file_path;
293
+ const side = stop.side || 'RIGHT';
294
+ const lineStart = stop.line_start;
295
+ // `line_end` may be missing on legacy/older stops; fall back to
296
+ // `line_start` so the range scan still works.
297
+ const lineEnd = (typeof stop.line_end === 'number' && stop.line_end >= lineStart)
298
+ ? stop.line_end
299
+ : lineStart;
300
+
301
+ if (!filePath || typeof lineStart !== 'number') {
302
+ console.warn('[TourRenderer] stop missing file_path/line_start; skipping', stop);
303
+ return null;
304
+ }
305
+
306
+ // Route by rendering engine. Pierre-rendered files have no light-DOM
307
+ // <tr> rows to anchor against, so they mount via the annotation bridge.
308
+ if (this._isPierreFile(filePath)) {
309
+ return this._mountStopPierre(index, stop, filePath, side, lineStart, lineEnd);
310
+ }
311
+ return this._mountStopLegacy(index, stop, filePath, side, lineStart, lineEnd);
312
+ }
313
+
314
+ /**
315
+ * Mount a stop into a PIERRE-rendered file as a `'tour-stop'` annotation.
316
+ *
317
+ * The bridge slots the annotation BELOW its anchor line into the file's
318
+ * light DOM (so page CSS + inline handlers work). We anchor at `line_end`
319
+ * (parity with how suggestions anchor; the banner then reads as describing
320
+ * the code above it), scanning backward through the range to the first
321
+ * VISIBLE line so a stop whose exact line_end sits in a still-folded gap
322
+ * still finds a home.
323
+ *
324
+ * The `toggleFileCollapse` await is a suspension window guarded against a
325
+ * mid-flight tour teardown exactly like the legacy path — see the inline
326
+ * note. Returns the slotted `<div class="tour-annotation-row">`, or null
327
+ * when no line in the range is mountable (probe advances).
328
+ *
329
+ * @returns {Promise<HTMLElement|null>}
330
+ */
331
+ async _mountStopPierre(index, stop, filePath, side, lineStart, lineEnd) {
332
+ const bridge = this.prManager && this.prManager.pierreBridge;
333
+ if (!bridge) return null;
334
+
335
+ // Capture the open-generation ONCE at entry — mirrors the legacy path's
336
+ // guard so the `toggleFileCollapse` await below can't record state for a
337
+ // torn-down tour.
338
+ const startGen = this.prManager?._tourGen;
339
+ const isStale = () => this.prManager?._tourGen !== startGen;
340
+
341
+ // Idempotent remount: if the annotation is still live in the DOM, reuse
342
+ // it. If it went missing (the file was re-rendered from scratch, dropping
343
+ // its annotations), fall through and re-add.
344
+ if (this._pierreMounts.has(index)) {
345
+ const existing = this._queryPierreRow(filePath, index);
346
+ if (existing) {
347
+ this._mounted.set(index, existing);
348
+ return existing;
349
+ }
350
+ this._pierreMounts.delete(index);
351
+ this._mounted.delete(index);
352
+ }
353
+
354
+ // Pick the anchor line: prefer line_end, scan back to line_start for the
355
+ // first line that renders (isLineVisible checks the instance's current
356
+ // hunk metadata, so it is correct even while an async repaint is in
357
+ // flight). No visible line in range → unmountable; return null so the
358
+ // navigator probes onward.
359
+ let anchorLine = null;
360
+ if (typeof bridge.isLineVisible === 'function') {
361
+ for (let n = lineEnd; n >= lineStart; n--) {
362
+ if (bridge.isLineVisible(filePath, n, side)) {
363
+ anchorLine = n;
364
+ break;
365
+ }
366
+ }
367
+ } else {
368
+ // Bridge without visibility probing — fall back to line_end and let the
369
+ // post-add DOM query decide whether it actually mounted.
370
+ anchorLine = lineEnd;
371
+ }
372
+ if (anchorLine == null) {
373
+ console.warn(
374
+ `[TourRenderer] no visible line for ${filePath}:${lineStart}-${lineEnd} (${side}); ` +
375
+ 'pierre stop will be skipped'
376
+ );
377
+ return null;
378
+ }
379
+
380
+ // Expand a collapsed wrapper the same way the legacy path does — route
381
+ // through PRManager.toggleFileCollapse so `collapsedFiles` stays in sync,
382
+ // and refuse (bail) rather than strip the class directly when the API is
383
+ // missing. The pierre body is hidden by `.collapsed` CSS just like the
384
+ // legacy table, so a collapsed file would slot the annotation invisibly.
385
+ const wrapper = document.querySelector(
386
+ `.d2h-file-wrapper[data-file-name="${tourRendererEscapeAttr(filePath)}"]`
387
+ );
388
+ if (wrapper && wrapper.classList.contains('collapsed')) {
389
+ if (this.prManager && typeof this.prManager.toggleFileCollapse === 'function') {
390
+ try {
391
+ await this.prManager.toggleFileCollapse(filePath);
392
+ // Suspension window: if the tour exited/restarted while the expand
393
+ // was in flight, `unmountAll` already ran against a snapshot that
394
+ // excludes this stop. Recording `_autoExpanded` / adding the
395
+ // annotation now would orphan both. Bail without mutating state.
396
+ if (isStale()) return null;
397
+ this._autoExpanded.add(filePath);
398
+ } catch (err) {
399
+ console.warn('[TourRenderer] toggleFileCollapse failed; skipping pierre stop', err);
400
+ return null;
401
+ }
402
+ } else {
403
+ console.warn(
404
+ '[TourRenderer] prManager.toggleFileCollapse missing; ' +
405
+ 'refusing to strip collapsed class — pierre stop skipped'
406
+ );
407
+ return null;
408
+ }
409
+ }
410
+
411
+ // Ensure the 'tour-stop' renderer is registered on the bridge, then add
412
+ // the annotation. addAnnotation triggers a synchronous rerender that
413
+ // invokes our renderer and slots the `<div class="tour-annotation-row">`
414
+ // into the file's light DOM.
415
+ this._ensureTourStopRendererRegistered();
416
+ const id = this._pierreAnnotationId(index);
417
+ // Record BEFORE adding so the renderer callback (fired synchronously by
418
+ // addAnnotation) can resolve the active-stop state for this index.
419
+ this._pierreMounts.set(index, { filePath, side, id, anchorLine });
420
+ if (typeof bridge.addAnnotation === 'function') {
421
+ bridge.addAnnotation(filePath, {
422
+ lineNumber: anchorLine,
423
+ side,
424
+ type: 'tour-stop',
425
+ data: { index },
426
+ id,
427
+ });
428
+ }
429
+
430
+ const row = this._queryPierreRow(filePath, index);
431
+ if (!row) {
432
+ // The bridge accepted the annotation but nothing slotted (line not
433
+ // actually rendered). Roll back so we don't leave a phantom mount.
434
+ this._pierreMounts.delete(index);
435
+ if (typeof bridge.removeAnnotation === 'function') {
436
+ try { bridge.removeAnnotation(filePath, id); } catch (_) { /* best effort */ }
437
+ }
438
+ console.warn(
439
+ `[TourRenderer] pierre annotation did not slot for ${filePath}:${anchorLine} (${side}); ` +
440
+ 'stop will be skipped'
441
+ );
442
+ return null;
443
+ }
444
+ this._mounted.set(index, row);
445
+ return row;
446
+ }
447
+
448
+ /**
449
+ * Mount a stop into a LEGACY (table-rendered) file as a
450
+ * `<tr class="tour-annotation-row">` inserted immediately above the anchor.
451
+ * This is the original pre-@pierre/diffs path, kept for context files that
452
+ * still render as HTML tables.
453
+ *
454
+ * @returns {Promise<HTMLTableRowElement|null>}
455
+ */
456
+ async _mountStopLegacy(index, stop, filePath, side, lineStart, lineEnd) {
267
457
  // Capture the open-generation ONCE at entry. The `toggleFileCollapse`
268
458
  // await below is a suspension window — the tour can be exited or
269
459
  // restarted (Escape, reopen) while it's in flight, which bumps
@@ -280,20 +470,6 @@ class TourRenderer {
280
470
  this._mounted.delete(index);
281
471
  }
282
472
 
283
- const filePath = stop.file_path;
284
- const side = stop.side || 'RIGHT';
285
- const lineStart = stop.line_start;
286
- // `line_end` may be missing on legacy/older stops; fall back to
287
- // `line_start` so the range scan still works.
288
- const lineEnd = (typeof stop.line_end === 'number' && stop.line_end >= lineStart)
289
- ? stop.line_end
290
- : lineStart;
291
-
292
- if (!filePath || typeof lineStart !== 'number') {
293
- console.warn('[TourRenderer] stop missing file_path/line_start; skipping', stop);
294
- return null;
295
- }
296
-
297
473
  const wrapper = document.querySelector(
298
474
  `.d2h-file-wrapper[data-file-name="${tourRendererEscapeAttr(filePath)}"]`
299
475
  );
@@ -376,16 +552,98 @@ class TourRenderer {
376
552
  const row = this._buildAnnotationRow(index, stop, anchorRow);
377
553
  anchorRow.parentNode.insertBefore(row, anchorRow);
378
554
  this._mounted.set(index, row);
379
-
380
- // Now that the row is in the live DOM, measure the description and
381
- // append a "Show more" toggle if it actually overflows the clamp.
382
- // Defer one frame (rAF when available, microtask in jsdom) so the
383
- // browser has time to apply layout to the just-inserted node before
384
- // we read `scrollHeight`. The helper is idempotent against re-mounts.
385
- this._scheduleOverflowCheck(index);
386
555
  return row;
387
556
  }
388
557
 
558
+ // --- pierre helpers -----------------------------------------------------
559
+
560
+ /**
561
+ * Whether `filePath` is rendered by @pierre/diffs (vs the legacy table).
562
+ * @param {string} filePath
563
+ * @returns {boolean}
564
+ */
565
+ _isPierreFile(filePath) {
566
+ const files = this.prManager && this.prManager.pierreBridge && this.prManager.pierreBridge.files;
567
+ return !!(files && typeof files.has === 'function' && files.has(filePath));
568
+ }
569
+
570
+ /**
571
+ * Stable annotation id for the stop at `index`.
572
+ * @param {number} index
573
+ * @returns {string}
574
+ */
575
+ _pierreAnnotationId(index) {
576
+ return `tour-stop-${index}`;
577
+ }
578
+
579
+ /**
580
+ * The light-DOM container (`.pierre-diff-body`) a pierre file's annotations
581
+ * are slotted into, or null.
582
+ * @param {string} filePath
583
+ * @returns {HTMLElement|null}
584
+ */
585
+ _pierreContainer(filePath) {
586
+ const fileState = this.prManager?.pierreBridge?.files?.get?.(filePath);
587
+ return (fileState && fileState.container) || null;
588
+ }
589
+
590
+ /**
591
+ * Re-query the live slotted annotation element for a pierre stop. The
592
+ * element is rebuilt on every FileDiff rerender, so cached references go
593
+ * stale — always resolve fresh before operating on it.
594
+ * @param {string} filePath
595
+ * @param {number} index
596
+ * @returns {HTMLElement|null}
597
+ */
598
+ _queryPierreRow(filePath, index) {
599
+ const container = this._pierreContainer(filePath);
600
+ if (!container) return null;
601
+ return container.querySelector(
602
+ `.tour-annotation-row[data-stop-index="${index}"]`
603
+ ) || null;
604
+ }
605
+
606
+ /**
607
+ * Resolve the live annotation element for a stop, regardless of engine.
608
+ * Legacy: the cached `<tr>` if still connected. Pierre: re-query the
609
+ * slotted `<div>` (and refresh the `_mounted` cache). Returns null when
610
+ * nothing is currently mounted for the index.
611
+ * @param {number} index
612
+ * @returns {HTMLElement|null}
613
+ */
614
+ _resolveRow(index) {
615
+ const pierre = this._pierreMounts.get(index);
616
+ if (pierre) {
617
+ const el = this._queryPierreRow(pierre.filePath, index);
618
+ if (el) this._mounted.set(index, el);
619
+ else this._mounted.delete(index);
620
+ return el;
621
+ }
622
+ const row = this._mounted.get(index);
623
+ return row && row.isConnected ? row : null;
624
+ }
625
+
626
+ /**
627
+ * Register the `'tour-stop'` custom annotation renderer on the shared
628
+ * PierreBridge (once). The callback receives (data, id, fileName) and
629
+ * returns the annotation card element the bridge slots below the anchor
630
+ * line. It is re-invoked on every file rerender, so it rebuilds the card
631
+ * from CURRENT state (active-stop) each time.
632
+ */
633
+ _ensureTourStopRendererRegistered() {
634
+ if (this._tourStopRendererRegistered) return;
635
+ const bridge = this.prManager && this.prManager.pierreBridge;
636
+ if (!bridge || typeof bridge.registerAnnotationRenderer !== 'function') return;
637
+ bridge.registerAnnotationRenderer('tour-stop', (data) => {
638
+ const index = data && typeof data.index === 'number' ? data.index : -1;
639
+ const stop = this._stops[index];
640
+ if (!stop) return null;
641
+ const row = this._buildAnnotationDiv(index, stop);
642
+ return row;
643
+ });
644
+ this._tourStopRendererRegistered = true;
645
+ }
646
+
389
647
  /**
390
648
  * Remove the mounted annotation for `index`. Returns true if a row was
391
649
  * removed.
@@ -393,6 +651,23 @@ class TourRenderer {
393
651
  * @returns {boolean}
394
652
  */
395
653
  unmountStop(index) {
654
+ // Pierre stop: remove via the bridge (which rerenders the file without
655
+ // this annotation). Do NOT touch the DOM node directly — the bridge owns
656
+ // its lifecycle.
657
+ const pierre = this._pierreMounts.get(index);
658
+ if (pierre) {
659
+ this._pierreMounts.delete(index);
660
+ this._mounted.delete(index);
661
+ const bridge = this.prManager && this.prManager.pierreBridge;
662
+ if (bridge && typeof bridge.removeAnnotation === 'function') {
663
+ try {
664
+ bridge.removeAnnotation(pierre.filePath, pierre.id);
665
+ } catch (err) {
666
+ console.warn('[TourRenderer] removeAnnotation failed for', pierre.id, err);
667
+ }
668
+ }
669
+ return true;
670
+ }
396
671
  const row = this._mounted.get(index);
397
672
  if (!row) return false;
398
673
  if (row.isConnected) row.remove();
@@ -421,6 +696,25 @@ class TourRenderer {
421
696
  * @returns {Promise<void>}
422
697
  */
423
698
  unmountAll() {
699
+ // Pierre stops: remove each via the bridge (rerenders the file without
700
+ // the annotation) and drop their `_mounted` cache entries so the legacy
701
+ // DOM-removal loop below only sees injected <tr> rows.
702
+ if (this._pierreMounts.size > 0) {
703
+ const bridge = this.prManager && this.prManager.pierreBridge;
704
+ for (const [index, pierre] of this._pierreMounts) {
705
+ if (bridge && typeof bridge.removeAnnotation === 'function') {
706
+ try {
707
+ bridge.removeAnnotation(pierre.filePath, pierre.id);
708
+ } catch (err) {
709
+ console.warn('[TourRenderer] removeAnnotation failed for', pierre.id, err);
710
+ }
711
+ }
712
+ this._mounted.delete(index);
713
+ }
714
+ this._pierreMounts.clear();
715
+ }
716
+ this._activeIndex = -1;
717
+
424
718
  for (const row of this._mounted.values()) {
425
719
  if (row && row.isConnected) row.remove();
426
720
  }
@@ -486,7 +780,10 @@ class TourRenderer {
486
780
  * @param {number} index
487
781
  */
488
782
  scrollToStop(index) {
489
- const row = this._mounted.get(index);
783
+ // Resolve the live element (pierre annotations are rebuilt on rerender,
784
+ // so the cached reference can be stale). The slotted pierre `<div>` and
785
+ // the legacy `<tr>` both have layout, so scrollIntoView works on either.
786
+ const row = this._resolveRow(index);
490
787
  if (!row || !row.isConnected) return;
491
788
  const options = {
492
789
  behavior: this._reduceMotion ? 'auto' : 'smooth',
@@ -510,7 +807,13 @@ class TourRenderer {
510
807
  * @param {number} index
511
808
  */
512
809
  highlightActive(index) {
513
- for (const [i, row] of this._mounted.entries()) {
810
+ // Persist the active index so the pierre renderer callback can re-apply
811
+ // `active-stop` when the annotation element is rebuilt on a rerender.
812
+ this._activeIndex = index;
813
+ // Snapshot keys — `_resolveRow` may delete stale pierre entries from
814
+ // `_mounted`, which would mutate the map mid-iteration.
815
+ for (const i of [...this._mounted.keys()]) {
816
+ const row = this._resolveRow(i);
514
817
  if (!row) continue;
515
818
  row.classList.toggle('active-stop', i === index);
516
819
  }
@@ -518,15 +821,62 @@ class TourRenderer {
518
821
 
519
822
  // --- private ------------------------------------------------------------
520
823
 
824
+ /**
825
+ * Build the LEGACY `<tr class="tour-annotation-row">` wrapper (table-based
826
+ * files). Inner `.tour-annotation` card is shared with the pierre variant.
827
+ * @param {number} index
828
+ * @param {Object} stop
829
+ * @param {HTMLElement} anchorRow
830
+ * @returns {HTMLTableRowElement}
831
+ */
521
832
  _buildAnnotationRow(index, stop, anchorRow) {
522
833
  const row = document.createElement('tr');
523
834
  row.className = 'tour-annotation-row';
835
+ if (index === this._activeIndex) row.classList.add('active-stop');
524
836
  row.dataset.stopIndex = String(index);
525
837
 
526
838
  const cell = document.createElement('td');
527
839
  cell.colSpan = 2;
528
840
  cell.className = 'tour-annotation-cell';
529
841
 
842
+ cell.appendChild(this._buildAnnotationInner(index, stop));
843
+ row.appendChild(cell);
844
+
845
+ // Suppress the anchorRow parameter being marked unused by linters that
846
+ // care; it's only here for future enhancements (e.g. computing colspan
847
+ // from the anchor row's siblings).
848
+ void anchorRow;
849
+
850
+ return row;
851
+ }
852
+
853
+ /**
854
+ * Build the PIERRE `<div class="tour-annotation-row">` wrapper. The bridge
855
+ * slots this into the file's light DOM below the anchor line. Carries the
856
+ * same class + `data-stop-index` as the legacy `<tr>` so page CSS and the
857
+ * light-DOM query (`_queryPierreRow`) treat both uniformly.
858
+ * @param {number} index
859
+ * @param {Object} stop
860
+ * @returns {HTMLDivElement}
861
+ */
862
+ _buildAnnotationDiv(index, stop) {
863
+ const row = document.createElement('div');
864
+ row.className = 'tour-annotation-row';
865
+ if (index === this._activeIndex) row.classList.add('active-stop');
866
+ row.dataset.stopIndex = String(index);
867
+ row.appendChild(this._buildAnnotationInner(index, stop));
868
+ return row;
869
+ }
870
+
871
+ /**
872
+ * Build the shared `.tour-annotation` card (marker + Chat button, title,
873
+ * full description) used by both the legacy `<tr>` and the pierre `<div>`
874
+ * wrappers.
875
+ * @param {number} index
876
+ * @param {Object} stop
877
+ * @returns {HTMLDivElement}
878
+ */
879
+ _buildAnnotationInner(index, stop) {
530
880
  const annotation = document.createElement('div');
531
881
  annotation.className = 'tour-annotation';
532
882
 
@@ -568,153 +918,19 @@ class TourRenderer {
568
918
  title.className = 'tour-annotation-title';
569
919
  title.textContent = stop.title || '';
570
920
 
571
- // The wrapper carries the CSS line-clamp so we can measure overflow
572
- // (scrollHeight > clientHeight) on the SAME element that hosts the clamp.
573
- // The inner <p> stays so existing selectors (.tour-annotation-description)
574
- // — including tests and the e2e spec — keep working.
575
- const descriptionWrap = document.createElement('div');
576
- descriptionWrap.className = 'tour-annotation-description-wrap';
577
- if (this._expandedDescriptions.has(index)) {
578
- descriptionWrap.classList.add('expanded');
579
- }
580
-
921
+ // Descriptions are always shown in full — they are short by design, so
922
+ // there is no truncation or "Show more" toggle. The prose width is capped
923
+ // to a readable measure in CSS (.tour-annotation-description), matching
924
+ // full-width comment/suggestion bodies.
581
925
  const description = document.createElement('p');
582
926
  description.className = 'tour-annotation-description';
583
927
  description.textContent = stop.description || '';
584
- descriptionWrap.appendChild(description);
585
928
 
586
929
  annotation.appendChild(header);
587
930
  annotation.appendChild(title);
588
- annotation.appendChild(descriptionWrap);
589
-
590
- // Footer is reserved for the "Show more"/"Show less" toggle that the
591
- // overflow check appends when the description is clamped. Empty when
592
- // the description fits inline.
593
- const footer = document.createElement('div');
594
- footer.className = 'tour-annotation-footer';
595
- annotation.appendChild(footer);
596
-
597
- cell.appendChild(annotation);
598
- row.appendChild(cell);
599
-
600
- // Suppress the anchorRow parameter being marked unused by linters that
601
- // care; it's only here for future enhancements (e.g. computing colspan
602
- // from the anchor row's siblings).
603
- void anchorRow;
604
-
605
- return row;
606
- }
931
+ annotation.appendChild(description);
607
932
 
608
- /**
609
- * Defer one frame, then evaluate description overflow for `index`. Real
610
- * browsers need a layout pass before `scrollHeight` is meaningful on a
611
- * just-inserted node; jsdom returns 0 either way, which is fine — there
612
- * is no real overflow to detect.
613
- *
614
- * Uses `requestAnimationFrame` when present (real browsers), otherwise
615
- * falls back to a 0ms timer (jsdom). Tests that want to force the
616
- * overflow path can stub `scrollHeight` / `clientHeight` on the wrapper
617
- * and call `_evaluateDescriptionOverflow(index)` directly without
618
- * waiting for the timer.
619
- *
620
- * @param {number} index
621
- */
622
- _scheduleOverflowCheck(index) {
623
- const run = () => this._evaluateDescriptionOverflow(index);
624
- if (typeof requestAnimationFrame === 'function') {
625
- requestAnimationFrame(run);
626
- } else if (typeof setTimeout === 'function') {
627
- setTimeout(run, 0);
628
- } else {
629
- run();
630
- }
631
- }
632
-
633
- /**
634
- * Synchronously read the description wrapper's overflow state and, if
635
- * it overflows the line-clamp, append a "Show more" toggle to the stop's
636
- * footer. Idempotent — calling it twice on the same row does NOT add
637
- * two buttons.
638
- *
639
- * Overflow check: `scrollHeight > clientHeight + 1`. The 1px fudge
640
- * dampens sub-pixel rounding noise on retina displays.
641
- *
642
- * Exported (as a regular method) so tests can stub scrollHeight /
643
- * clientHeight on the wrapper before triggering the check, sidestepping
644
- * jsdom's zero-layout default.
645
- *
646
- * @param {number} index
647
- */
648
- _evaluateDescriptionOverflow(index) {
649
- const row = this._mounted.get(index);
650
- if (!row || !row.isConnected) return;
651
- const wrap = row.querySelector('.tour-annotation-description-wrap');
652
- if (!wrap) return;
653
- const footer = row.querySelector('.tour-annotation-footer');
654
- if (!footer) return;
655
- // Idempotency guard — re-running after a remount must not add a
656
- // second button.
657
- if (footer.querySelector('.tour-annotation-show-more-btn')) return;
658
- // Don't show the toggle when the user already expanded this stop;
659
- // the wrapper has no overflow to detect in that state.
660
- if (this._expandedDescriptions.has(index)) {
661
- this._appendShowMoreButton(index, row, /* expanded */ true);
662
- return;
663
- }
664
- const overflows = wrap.scrollHeight > wrap.clientHeight + 1;
665
- if (!overflows) return;
666
- this._appendShowMoreButton(index, row, /* expanded */ false);
667
- }
668
-
669
- /**
670
- * Build and insert the "Show more"/"Show less" button into the stop's
671
- * footer. The Chat about button now lives in the header, so the footer
672
- * is dedicated to the show-more toggle.
673
- *
674
- * @param {number} index
675
- * @param {HTMLElement} row
676
- * @param {boolean} expanded
677
- */
678
- _appendShowMoreButton(index, row, expanded) {
679
- const footer = row.querySelector('.tour-annotation-footer');
680
- if (!footer) return;
681
- const wrap = row.querySelector('.tour-annotation-description-wrap');
682
- if (!wrap) return;
683
- const btn = document.createElement('button');
684
- btn.type = 'button';
685
- btn.className = 'tour-annotation-show-more-btn';
686
- btn.dataset.stopIndex = String(index);
687
- btn.textContent = expanded ? 'Show less' : 'Show more';
688
- btn.setAttribute('aria-expanded', expanded ? 'true' : 'false');
689
- btn.addEventListener('click', (e) => {
690
- e.stopPropagation();
691
- this._toggleDescriptionExpansion(index);
692
- });
693
- footer.appendChild(btn);
694
- }
695
-
696
- /**
697
- * Flip the expanded state for stop `index`: toggles the wrapper's
698
- * `.expanded` class and the button label. Persists the index into
699
- * `_expandedDescriptions` so a remount restores the expanded state.
700
- *
701
- * @param {number} index
702
- */
703
- _toggleDescriptionExpansion(index) {
704
- const row = this._mounted.get(index);
705
- if (!row) return;
706
- const wrap = row.querySelector('.tour-annotation-description-wrap');
707
- const btn = row.querySelector('.tour-annotation-show-more-btn');
708
- if (!wrap || !btn) return;
709
- const willExpand = !wrap.classList.contains('expanded');
710
- wrap.classList.toggle('expanded', willExpand);
711
- btn.textContent = willExpand ? 'Show less' : 'Show more';
712
- btn.setAttribute('aria-expanded', willExpand ? 'true' : 'false');
713
- if (willExpand) {
714
- this._expandedDescriptions.add(index);
715
- } else {
716
- this._expandedDescriptions.delete(index);
717
- }
933
+ return annotation;
718
934
  }
719
935
 
720
936
  /**