@in-the-loop-labs/pair-review 5.2.0 → 5.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@in-the-loop-labs/pair-review",
3
- "version": "5.2.0",
3
+ "version": "5.2.1",
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.2.0",
3
+ "version": "5.2.1",
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.2.0",
3
+ "version": "5.2.1",
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.2.0",
3
+ "version": "5.2.1",
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/index.html CHANGED
@@ -1574,6 +1574,7 @@
1574
1574
  <script src="/js/components/VoiceCentricConfigTab.js"></script>
1575
1575
  <script src="/js/components/AdvancedConfigTab.js"></script>
1576
1576
  <script src="/js/theme.js"></script>
1577
+ <script src="/js/repo-links.js"></script>
1577
1578
  <script src="/js/index.js"></script>
1578
1579
  </body>
1579
1580
  </html>
@@ -112,6 +112,13 @@
112
112
  return div.innerHTML;
113
113
  }
114
114
 
115
+ /** Escape text for insertion into a quoted HTML attribute. */
116
+ function escapeHtmlAttribute(text) {
117
+ return escapeHtml(text)
118
+ .replace(/"/g, '&quot;')
119
+ .replace(/'/g, '&#39;');
120
+ }
121
+
115
122
  // encodeBase64Utf8 / getRepoStorageKey live in public/js/utils/storage-keys.js
116
123
  // (window.encodeBase64Utf8 / window.getRepoStorageKey), shared with pr.js so the
117
124
  // per-repo keys this page writes stay byte-identical to those the PR page reads.
@@ -339,9 +346,9 @@
339
346
 
340
347
  return '' +
341
348
  '<tr data-session-id="' + session.id + '">' +
342
- '<td class="col-local-name" title="' + escapeHtml(session.name || 'Untitled') + '"><a href="' + link + '">' + nameDisplay + '</a></td>' +
343
- '<td class="col-local-sha" title="' + escapeHtml(session.local_head_sha || '') + '">' + escapeHtml(sha) + '</td>' +
344
- '<td class="col-local-path" title="' + escapeHtml(pathDisplay) + '">' + escapeHtml(pathDisplay) + '</td>' +
349
+ '<td class="col-local-name" title="' + escapeHtmlAttribute(session.name || 'Untitled') + '"><a href="' + link + '">' + nameDisplay + '</a></td>' +
350
+ '<td class="col-local-sha" title="' + escapeHtmlAttribute(session.local_head_sha || '') + '">' + escapeHtml(sha) + '</td>' +
351
+ '<td class="col-local-path" title="' + escapeHtmlAttribute(pathDisplay) + '">' + escapeHtml(pathDisplay) + '</td>' +
345
352
  '<td class="col-repo">' + escapeHtml(session.repository || '') + '</td>' +
346
353
  '<td class="col-time">' + relativeTime + '</td>' +
347
354
  '<td class="col-actions">' +
@@ -349,7 +356,7 @@
349
356
  '<button' +
350
357
  ' class="btn-delete-session"' +
351
358
  ' data-session-id="' + session.id + '"' +
352
- ' data-session-path="' + escapeHtml(pathDisplay) + '"' +
359
+ ' data-session-path="' + escapeHtmlAttribute(pathDisplay) + '"' +
353
360
  ' title="Delete session"' +
354
361
  '>' +
355
362
  '<svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor">' +
@@ -470,6 +477,79 @@
470
477
  if (clearBtn) clearBtn.hidden = !value;
471
478
  }
472
479
 
480
+ var GITHUB_ACTION_ICON = '<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor"><path d="M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z"/></svg>';
481
+ var GRAPHITE_ACTION_ICON = '<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor"><path d="M9.7932,1.3079L3.101,3.101l-1.7932,6.6921,4.899,4.899,6.6921-1.7931,1.7932-6.6921L9.7932,1.3079Zm1.0936,11.6921H5.1133l-2.8867-5L5.1133,3h5.7735l2.8867,5-2.8867,5Z"/><polygon points="11.3504 4.6496 6.7737 3.4232 3.4232 6.7737 4.6496 11.3504 9.2263 12.5768 12.5768 9.2263 11.3504 4.6496"/></svg>';
482
+ var EXTERNAL_ACTION_ICON = '<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor"><path d="M3.75 2A1.75 1.75 0 0 0 2 3.75v8.5C2 13.216 2.784 14 3.75 14h8.5A1.75 1.75 0 0 0 14 12.25v-3a.75.75 0 0 0-1.5 0v3a.25.25 0 0 1-.25.25h-8.5a.25.25 0 0 1-.25-.25v-8.5a.25.25 0 0 1 .25-.25h3a.75.75 0 0 0 0-1.5h-3Zm6.97-.53a.75.75 0 0 0 0 1.06l1.72 1.72-4.97 4.97a.75.75 0 1 0 1.06 1.06l4.97-4.97 1.72 1.72a.75.75 0 0 0 1.28-.53V2.75A.75.75 0 0 0 14.75 2h-3.5a.75.75 0 0 0-.53 1.28Z"/></svg>';
483
+
484
+ /**
485
+ * Render the configured external-host icon, falling back to the generic
486
+ * "open in new tab" glyph when no icon is configured or the SVG failed
487
+ * sanitisation. Malformed parser output also falls back instead of breaking
488
+ * the entire table row.
489
+ */
490
+ function renderExternalActionIcon(icon) {
491
+ if (!icon || !window.RepoLinks || typeof window.RepoLinks.parseSvgIcon !== 'function') {
492
+ return EXTERNAL_ACTION_ICON;
493
+ }
494
+
495
+ var svg = window.RepoLinks.parseSvgIcon(icon);
496
+ if (!svg || typeof svg.outerHTML !== 'string') return EXTERNAL_ACTION_ICON;
497
+
498
+ // Match the 16px sizing of the built-in action icons.
499
+ if (typeof svg.getAttribute === 'function' && typeof svg.setAttribute === 'function') {
500
+ if (!svg.getAttribute('width')) svg.setAttribute('width', '16');
501
+ if (!svg.getAttribute('height')) svg.setAttribute('height', '16');
502
+ }
503
+ return svg.outerHTML;
504
+ }
505
+
506
+ /**
507
+ * Render the external, GitHub, and Graphite action links resolved by the
508
+ * backend for one landing-page row.
509
+ */
510
+ function renderRepoActionLinks(context) {
511
+ var repoLinks = context.repo_links || { external: null, github: true, graphite: true };
512
+ // Prefer html_url to preserve GitHub's original casing for Graphite and to
513
+ // keep unconfigured alternate-host rows pointing at their actual host.
514
+ var defaultUrl = typeof context.html_url === 'string' && context.html_url.startsWith('https://')
515
+ ? context.html_url
516
+ : 'https://github.com/' + encodeURIComponent(context.owner) + '/' + encodeURIComponent(context.repo) + '/pull/' + context.number;
517
+ var html = '';
518
+
519
+ if (repoLinks.external && window.RepoLinks && typeof window.RepoLinks.substituteUrlTemplate === 'function') {
520
+ var externalUrl = window.RepoLinks.substituteUrlTemplate(repoLinks.external.url_template, context);
521
+ // A template that needs row data this surface cannot supply (a stale
522
+ // `head_sha`, say) substitutes to nothing. Fall back to the recorded PR
523
+ // URL rather than dropping the button: with `links.github: false` the
524
+ // external link is the row's ONLY route to the PR.
525
+ if (!externalUrl && typeof context.html_url === 'string' && context.html_url.startsWith('https://')) {
526
+ externalUrl = context.html_url;
527
+ }
528
+ if (externalUrl) {
529
+ var label = escapeHtmlAttribute(repoLinks.external.label);
530
+ html += '<a href="' + escapeHtmlAttribute(externalUrl) + '" target="_blank" rel="noopener" class="btn-github-link" title="' + label + '" aria-label="' + label + '">' +
531
+ renderExternalActionIcon(repoLinks.external.icon) +
532
+ '</a>';
533
+ }
534
+ }
535
+
536
+ if (repoLinks.github !== false) {
537
+ html += '<a href="' + escapeHtmlAttribute(defaultUrl) + '" target="_blank" rel="noopener" class="btn-github-link" title="Open on GitHub">' +
538
+ GITHUB_ACTION_ICON +
539
+ '</a>';
540
+ }
541
+
542
+ if (repoLinks.graphite !== false && window.__pairReview?.enableGraphite
543
+ && typeof context.html_url === 'string' && /^https:\/\/github\.com\//i.test(defaultUrl)) {
544
+ var graphiteUrl = window.__pairReview.toGraphiteUrl(defaultUrl);
545
+ html += '<a href="' + escapeHtmlAttribute(graphiteUrl) + '" target="_blank" rel="noopener" class="btn-github-link" title="Open on Graphite">' +
546
+ GRAPHITE_ACTION_ICON +
547
+ '</a>';
548
+ }
549
+
550
+ return html;
551
+ }
552
+
473
553
  /**
474
554
  * Render a single row for a collection PR table.
475
555
  * @param {Object} pr - PR object from the API
@@ -485,39 +565,37 @@
485
565
  ? '<a href="https://github.com/' + encodeURIComponent(pr.author) + '" target="_blank" rel="noopener">' + escapeHtml(pr.author) + '</a>'
486
566
  : '';
487
567
 
488
- var githubLinkHtml =
489
- '<a href="' + escapeHtml(pr.html_url || prUrl) + '" target="_blank" rel="noopener" class="btn-github-link" title="Open on GitHub">' +
490
- '<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor"><path d="M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z"/></svg>' +
491
- '</a>';
492
-
493
- var graphiteLinkHtml = '';
494
- if (window.__pairReview?.enableGraphite && pr.html_url) {
495
- // Derive from html_url to preserve GitHub's original casing (Graphite URLs are case-sensitive)
496
- var graphiteUrl = window.__pairReview.toGraphiteUrl(pr.html_url);
497
- graphiteLinkHtml =
498
- '<a href="' + escapeHtml(graphiteUrl) + '" target="_blank" rel="noopener" class="btn-github-link" title="Open on Graphite">' +
499
- '<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor"><path d="M9.7932,1.3079L3.101,3.101l-1.7932,6.6921,4.899,4.899,6.6921-1.7931,1.7932-6.6921L9.7932,1.3079Zm1.0936,11.6921H5.1133l-2.8867-5L5.1133,3h5.7735l2.8867,5-2.8867,5Z"/><polygon points="11.3504 4.6496 6.7737 3.4232 3.4232 6.7737 4.6496 11.3504 9.2263 12.5768 12.5768 9.2263 11.3504 4.6496"/></svg>' +
500
- '</a>';
501
- }
502
-
503
568
  var authorTd = collection === 'my-prs'
504
569
  ? ''
505
570
  : '<td class="col-author">' + authorDisplay + '</td>';
506
571
 
507
- // `data-host` carries the alt-host api_host string for PRs that live on an
508
- // alternate host; github.com rows have no host and render an empty
509
- // attribute. The click handler threads it into the setup call so a dual
510
- // repo's alt-host PR opens against the right system without re-probing.
511
- var hostAttr = pr.host ? ' data-host="' + escapeHtml(pr.host) + '"' : '';
572
+ // `setup_host` is resolved by the collection API (setupHostParam): an alt
573
+ // api_host string, the 'github' sentinel, or null to omit. Open, Analyze,
574
+ // and single-row navigation thread it into setup, which resolves the same
575
+ // row's binding key from it — so the row opens against the host its action
576
+ // icons point at. The browser only echoes the value; deriving it here would
577
+ // duplicate a config-dependent decision and let the icon and the click
578
+ // disagree.
579
+ var hostAttr = pr.setup_host
580
+ ? ' data-host="' + escapeHtmlAttribute(pr.setup_host) + '"'
581
+ : '';
582
+ var actionLinks = renderRepoActionLinks({
583
+ owner: pr.owner,
584
+ repo: pr.repo,
585
+ number: pr.number,
586
+ html_url: pr.html_url,
587
+ repo_links: pr.repo_links,
588
+ host: pr.host
589
+ });
512
590
 
513
591
  return '' +
514
- '<tr class="collection-pr-row" data-pr-url="' + escapeHtml(prUrl) + '" data-owner="' + escapeHtml(pr.owner) + '" data-repo="' + escapeHtml(pr.repo) + '" data-number="' + pr.number + '"' + hostAttr + '>' +
592
+ '<tr class="collection-pr-row" data-pr-url="' + escapeHtmlAttribute(prUrl) + '" data-owner="' + escapeHtmlAttribute(pr.owner) + '" data-repo="' + escapeHtmlAttribute(pr.repo) + '" data-number="' + pr.number + '"' + hostAttr + '>' +
515
593
  '<td class="col-repo">' + escapeHtml(repoFull) + '</td>' +
516
594
  '<td class="col-pr"><span class="collection-pr-number">#' + pr.number + '</span></td>' +
517
- '<td class="col-title" title="' + escapeHtml(pr.title || '') + '">' + escapeHtml(pr.title || '') + '</td>' +
595
+ '<td class="col-title" title="' + escapeHtmlAttribute(pr.title || '') + '">' + escapeHtml(pr.title || '') + '</td>' +
518
596
  authorTd +
519
597
  '<td class="col-time">' + relativeTime + '</td>' +
520
- '<td class="col-actions">' + githubLinkHtml + graphiteLinkHtml + '</td>' +
598
+ '<td class="col-actions">' + actionLinks + '</td>' +
521
599
  '</tr>';
522
600
  }
523
601
 
@@ -1065,7 +1143,11 @@
1065
1143
  const parts = review.repository.split('/');
1066
1144
  const owner = parts[0];
1067
1145
  const repo = parts[1];
1068
- const link = '/pr/' + owner + '/' + repo + '/' + review.pr_number;
1146
+ // Carry the API's resolved host into /pr so the row opens against the same
1147
+ // system its action icons point at. applyHostQueryCorrection validates it
1148
+ // and stamps a legacy NULL row on the way through.
1149
+ const link = '/pr/' + owner + '/' + repo + '/' + review.pr_number
1150
+ + (review.setup_host ? '?host=' + encodeURIComponent(review.setup_host) : '');
1069
1151
  const settingsLink = '/repo-settings.html?owner=' + encodeURIComponent(owner) + '&repo=' + encodeURIComponent(repo);
1070
1152
  const relativeTime = formatRelativeTime(review.last_accessed_at);
1071
1153
 
@@ -1074,23 +1156,27 @@
1074
1156
  : '';
1075
1157
 
1076
1158
  var reviewIdAttr = review.review_id ? ' data-analysis-review-id="' + review.review_id + '"' : '';
1159
+ var actionLinks = renderRepoActionLinks({
1160
+ owner: owner,
1161
+ repo: repo,
1162
+ number: review.pr_number,
1163
+ html_url: review.html_url,
1164
+ branch: review.head_branch,
1165
+ base_branch: review.base_branch,
1166
+ head_sha: review.head_sha,
1167
+ repo_links: review.repo_links,
1168
+ host: review.host
1169
+ });
1077
1170
 
1078
1171
  return '' +
1079
1172
  '<tr data-review-id="' + review.id + '"' + reviewIdAttr + '>' +
1080
1173
  '<td class="col-repo">' + escapeHtml(review.repository) + '</td>' +
1081
1174
  '<td class="col-pr"><a href="' + link + '">#' + review.pr_number + '</a></td>' +
1082
- '<td class="col-title" title="' + escapeHtml(review.pr_title) + '">' + escapeHtml(review.pr_title) + '</td>' +
1175
+ '<td class="col-title" title="' + escapeHtmlAttribute(review.pr_title) + '">' + escapeHtml(review.pr_title) + '</td>' +
1083
1176
  '<td class="col-author">' + authorDisplay + '</td>' +
1084
1177
  '<td class="col-time">' + relativeTime + '</td>' +
1085
1178
  '<td class="col-actions">' +
1086
- '<a href="https://github.com/' + escapeHtml(review.repository) + '/pull/' + review.pr_number + '" target="_blank" rel="noopener" class="btn-github-link" title="Open on GitHub">' +
1087
- '<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor"><path d="M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z"/></svg>' +
1088
- '</a>' +
1089
- (window.__pairReview?.enableGraphite && review.html_url
1090
- ? '<a href="' + escapeHtml(window.__pairReview.toGraphiteUrl(review.html_url)) + '" target="_blank" rel="noopener" class="btn-github-link" title="Open on Graphite">' +
1091
- '<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor"><path d="M9.7932,1.3079L3.101,3.101l-1.7932,6.6921,4.899,4.899,6.6921-1.7931,1.7932-6.6921L9.7932,1.3079Zm1.0936,11.6921H5.1133l-2.8867-5L5.1133,3h5.7735l2.8867,5-2.8867,5Z"/><polygon points="11.3504 4.6496 6.7737 3.4232 3.4232 6.7737 4.6496 11.3504 9.2263 12.5768 12.5768 9.2263 11.3504 4.6496"/></svg>' +
1092
- '</a>'
1093
- : '') +
1179
+ actionLinks +
1094
1180
  '<a href="' + settingsLink + '" class="btn-repo-settings" title="Repository settings">' +
1095
1181
  '<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">' +
1096
1182
  '<path d="M8 0a8.2 8.2 0 0 1 .701.031C9.444.095 9.99.645 10.16 1.29l.288 1.107c.018.066.079.158.212.224.231.114.454.243.668.386.123.082.233.09.299.071l1.103-.303c.644-.176 1.392.021 1.82.63.27.385.506.792.704 1.218.315.675.111 1.422-.364 1.891l-.814.806c-.049.048-.098.147-.088.294.016.257.016.515 0 .772-.01.147.038.246.088.294l.814.806c.475.469.679 1.216.364 1.891a7.977 7.977 0 0 1-.704 1.217c-.428.61-1.176.807-1.82.63l-1.102-.302c-.067-.019-.177-.011-.3.071a5.909 5.909 0 0 1-.668.386c-.133.066-.194.158-.211.224l-.29 1.106c-.168.646-.715 1.196-1.458 1.26a8.006 8.006 0 0 1-1.402 0c-.743-.064-1.289-.614-1.458-1.26l-.289-1.106c-.018-.066-.079-.158-.212-.224a5.738 5.738 0 0 1-.668-.386c-.123-.082-.233-.09-.299-.071l-1.103.303c-.644.176-1.392-.021-1.82-.63a8.12 8.12 0 0 1-.704-1.218c-.315-.675-.111-1.422.363-1.891l.815-.806c.05-.048.098-.147.088-.294a6.214 6.214 0 0 1 0-.772c.01-.147-.038-.246-.088-.294l-.815-.806C.635 6.045.431 5.298.746 4.623a7.92 7.92 0 0 1 .704-1.217c.428-.61 1.176-.807 1.82-.63l1.102.302c.067.019.177.011.3-.071.214-.143.437-.272.668-.386.133-.066.194-.158.211-.224l.29-1.106C6.009.645 6.556.095 7.299.03 7.53.01 7.764 0 8 0Zm-.571 1.525c-.036.003-.108.036-.137.146l-.289 1.105c-.147.561-.549.967-.998 1.189-.173.086-.34.183-.5.29-.417.278-.97.423-1.529.27l-1.103-.303c-.109-.03-.175.016-.195.045-.22.312-.412.644-.573.99-.014.031-.021.11.059.19l.815.806c.411.406.562.957.53 1.456a4.709 4.709 0 0 0 0 .582c.032.499-.119 1.05-.53 1.456l-.815.806c-.081.08-.073.159-.059.19.162.346.353.677.573.989.02.03.085.076.195.046l1.102-.303c.56-.153 1.113-.008 1.53.27.161.107.328.204.501.29.447.222.85.629.997 1.189l.289 1.105c.029.109.101.143.137.146a6.6 6.6 0 0 0 1.142 0c.036-.003.108-.036.137-.146l.289-1.105c.147-.561.549-.967.998-1.189.173-.086.34-.183.5-.29.417-.278.97-.423 1.529-.27l1.103.303c.109.029.175-.016.195-.045.22-.313.411-.644.573-.99.014-.031.021-.11-.059-.19l-.815-.806c-.411-.406-.562-.957-.53-1.456a4.709 4.709 0 0 0 0-.582c-.032-.499.119-1.05.53-1.456l.815-.806c.081-.08.073-.159.059-.19a6.464 6.464 0 0 0-.573-.989c-.02-.03-.085-.076-.195-.046l-1.102.303c-.56.153-1.113.008-1.53-.27a4.44 4.44 0 0 0-.501-.29c-.447-.222-.85-.629-.997-1.189l-.289-1.105c-.029-.11-.101-.143-.137-.146a6.6 6.6 0 0 0-1.142 0ZM11 8a3 3 0 1 1-6 0 3 3 0 0 1 6 0ZM9.5 8a1.5 1.5 0 1 0-3.001.001A1.5 1.5 0 0 0 9.5 8Z"/>' +
@@ -1099,7 +1185,7 @@
1099
1185
  '<button' +
1100
1186
  ' class="btn-delete-review"' +
1101
1187
  ' data-review-id="' + review.id + '"' +
1102
- ' data-repository="' + escapeHtml(review.repository) + '"' +
1188
+ ' data-repository="' + escapeHtmlAttribute(review.repository) + '"' +
1103
1189
  ' data-pr-number="' + review.pr_number + '"' +
1104
1190
  ' title="Delete review"' +
1105
1191
  '>' +
@@ -1370,9 +1456,9 @@
1370
1456
  // string = alt host, null = github.com, undefined = unknown.
1371
1457
  host: data.host,
1372
1458
  bindingRepository: data.bindingRepository,
1373
- // Whether the repo is dual (github + alt-host). Only dual repos probe,
1374
- // so only they need an explicit github pick when the URL is a github URL.
1375
- isDualHost: data.isDualHost
1459
+ // Server-resolved `?host=` value for this URL (see setupHostParam).
1460
+ // The browser echoes it rather than deciding from repo config.
1461
+ setupHost: data.setupHost
1376
1462
  };
1377
1463
  }
1378
1464
 
@@ -1424,17 +1510,12 @@
1424
1510
  let href = '/pr/' + encodeURIComponent(parsed.owner) + '/' + encodeURIComponent(parsed.repo) + '/' + encodeURIComponent(parsed.prNumber);
1425
1511
  var params = new URLSearchParams();
1426
1512
  if (analyze) params.set('analyze', 'true');
1427
- // Forward the parsed host so setup binds directly instead of probing:
1428
- // - alt-host URL string → the api_host (setup binds that alt host)
1429
- // - github URL (host === null) on a DUAL repo → the "github" sentinel, so
1430
- // setup binds github.com instead of probing alt-first (which would fail
1431
- // loudly if the alt host is down for a PR we KNOW is on github)
1432
- // - anything else (plain/exclusive repo, unknown host) → omit; no probe
1433
- // happens for those and omitting avoids the exclusive-null throw.
1434
- if (typeof parsed.host === 'string' && parsed.host) {
1435
- params.set('host', parsed.host);
1436
- } else if (parsed.host === null && parsed.isDualHost) {
1437
- params.set('host', 'github');
1513
+ // Forward the server-resolved host so setup binds directly instead of
1514
+ // probing. `setupHost` is already the exact param value — an api_host
1515
+ // string, the 'github' sentinel, or null to omit — so no configuration
1516
+ // reasoning happens in the browser.
1517
+ if (parsed.setupHost) {
1518
+ params.set('host', parsed.setupHost);
1438
1519
  }
1439
1520
  var qs = params.toString();
1440
1521
  if (qs) href += '?' + qs;
@@ -2009,9 +2090,9 @@
2009
2090
  repo: tr.dataset.repo,
2010
2091
  number: tr.dataset.number,
2011
2092
  prUrl: prUrl,
2012
- // Alt-host rows carry a host; github.com rows leave it undefined. The
2013
- // single-row click path threads this the same way (see the collection
2014
- // row click handler) so bulk-open binds to the right system too.
2093
+ // Known rows carry either the "github" sentinel or an alternate
2094
+ // api_host; unknown rows leave it undefined. The single-row click
2095
+ // path threads the same value so bulk and individual routing agree.
2015
2096
  host: tr.dataset.host
2016
2097
  });
2017
2098
  }
@@ -2021,9 +2102,9 @@
2021
2102
 
2022
2103
  function buildReviewUrlsFromRows(rows, query) {
2023
2104
  return rows.map(function (row) {
2024
- // Preserve any existing params (analyze / analysisConfigId) and append the
2025
- // alt host so setup opens the PR against the system it lives on instead of
2026
- // re-probing. github.com rows (no host) keep the URL unchanged.
2105
+ // Preserve existing params and append any known host (the "github"
2106
+ // sentinel or an alternate api_host) so setup bypasses probing. Rows
2107
+ // whose host is unknown keep the URL unchanged.
2027
2108
  var qs = query || '';
2028
2109
  if (row.host) {
2029
2110
  qs += (qs ? '&' : '?') + 'host=' + encodeURIComponent(row.host);
@@ -2282,12 +2363,10 @@
2282
2363
  return;
2283
2364
  }
2284
2365
 
2285
- // Alt-host PR: we already know owner/repo/number and the host it lives
2286
- // on, so navigate straight to the PR route with the host as a query
2287
- // param (setup.html forwards it into the setup POST body). This bypasses
2288
- // the URL-parse round trip, which can't reliably recover the host from a
2289
- // pasted alt-host html_url. github.com rows (no host) keep the existing
2290
- // parse-and-submit flow below, byte-identical.
2366
+ // The collection API resolved this PR's system, so navigate straight to
2367
+ // the PR route with its host (the "github" sentinel or an alternate
2368
+ // api_host). setup.html forwards it into the setup POST body, bypassing
2369
+ // the host probe. Rows with no host retain the parse-and-submit fallback.
2291
2370
  var rowHost = collectionRow.dataset.host;
2292
2371
  if (rowHost) {
2293
2372
  var o = encodeURIComponent(collectionRow.dataset.owner);
@@ -2689,7 +2768,9 @@
2689
2768
  showError: showError,
2690
2769
  showInfo: showInfo,
2691
2770
  showLocalPathUrlError: showLocalPathUrlError,
2692
- handleLocalPathInput: handleLocalPathInput
2771
+ handleLocalPathInput: handleLocalPathInput,
2772
+ renderCollectionPrRow: renderCollectionPrRow,
2773
+ renderRecentReviewRow: renderRecentReviewRow
2693
2774
  };
2694
2775
  }
2695
2776
 
@@ -25,6 +25,24 @@
25
25
  'owner', 'repo', 'number', 'branch', 'base_branch', 'head_sha'
26
26
  ];
27
27
 
28
+ // Custom icons are presentation-only. Restrict the parsed tree to inert SVG
29
+ // shapes and paint attributes before it can enter the live document.
30
+ const SAFE_SVG_ELEMENTS = new Set([
31
+ 'svg', 'g', 'path', 'circle', 'ellipse', 'line', 'polyline', 'polygon',
32
+ 'rect', 'title', 'desc', 'defs', 'lineargradient', 'radialgradient',
33
+ 'stop', 'clippath', 'mask'
34
+ ]);
35
+ const SAFE_SVG_ATTRIBUTES = new Set([
36
+ 'xmlns', 'viewbox', 'preserveaspectratio', 'width', 'height',
37
+ 'x', 'y', 'x1', 'y1', 'x2', 'y2', 'cx', 'cy', 'r', 'rx', 'ry',
38
+ 'fx', 'fy', 'fr', 'd', 'points', 'fill', 'fill-rule', 'fill-opacity',
39
+ 'stroke', 'stroke-width', 'stroke-linecap', 'stroke-linejoin',
40
+ 'stroke-miterlimit', 'stroke-dasharray', 'stroke-dashoffset',
41
+ 'stroke-opacity', 'opacity', 'transform', 'clip-path', 'clip-rule',
42
+ 'mask', 'id', 'class', 'offset', 'stop-color', 'stop-opacity',
43
+ 'gradientunits', 'gradienttransform', 'spreadmethod', 'role', 'focusable'
44
+ ]);
45
+
28
46
  // The most recently resolved links + substitution context for the
29
47
  // current review. Stored so other code (ReviewModal, pr.js) can read
30
48
  // the configured host name / external URL / icon instead of hardcoding
@@ -77,37 +95,68 @@
77
95
  // image/svg+xml mode returns a <parsererror> root on bad input.
78
96
  const root = doc.documentElement;
79
97
  if (!root || root.nodeName !== 'svg') return null;
80
- // Belt-and-braces: strip dangerous attributes/elements even though
81
- // the server already removed them.
82
- stripDangerousAttributes(root);
98
+ // The server strips scripts/on*/javascript:, while embedded active HTML
99
+ // and external references are removed by this inert allowlist pass.
100
+ const removed = { elements: 0, attributes: 0 };
101
+ sanitizeSvgTree(root, removed);
102
+ if (removed.elements || removed.attributes) {
103
+ // A configured icon that renders differently than authored is otherwise
104
+ // silent and hard to diagnose — this parser also feeds the review header
105
+ // and the submit button, not just the dashboard rows.
106
+ console.warn(
107
+ '[repo-links] Sanitised configured icon: removed ' + removed.elements +
108
+ ' element(s) and ' + removed.attributes + ' attribute(s). Only inert SVG ' +
109
+ 'shapes, paint attributes, and local url(#id) references are kept.'
110
+ );
111
+ }
83
112
  return root;
84
113
  } catch {
85
114
  return null;
86
115
  }
87
116
  }
88
117
 
118
+ // A paint/reference attribute may point at a LOCAL fragment only. Accepts
119
+ // optional surrounding whitespace and optional matching quotes — `url(#a)`,
120
+ // `url("#paint0")`, `url('#clip0')` and ` url(#mask0) ` are all the same
121
+ // local reference, and the allowlist deliberately keeps `defs`, `id`,
122
+ // gradients, `clip-path` and `mask` so they are clearly intended. Anything
123
+ // else (`url(https://…)`, `url(//…)`, `url(data:…)`, mismatched quotes, or
124
+ // more than one reference) fails and the attribute is dropped.
125
+ const LOCAL_FRAGMENT_URL_RE = /^\s*url\(\s*(["']?)#[^)"'\s]+\1\s*\)\s*$/i;
126
+
89
127
  /**
90
- * Recursively strip on* event handlers and `javascript:` URLs from an
91
- * SVG element tree, and remove any `<script>` descendants. Defensive
92
- * second pass after server sanitisation.
128
+ * Restrict a parsed SVG tree to inert presentation elements and attributes.
129
+ * Active HTML (`foreignObject`, iframes), scripts, event handlers, external
130
+ * resource references, and animation elements are removed.
131
+ *
132
+ * @param {Element} element - Subtree root to sanitise in place
133
+ * @param {{ elements: number, attributes: number }} removed - Accumulator so
134
+ * the caller can report what changed with a single warning.
93
135
  */
94
- function stripDangerousAttributes(element) {
136
+ function sanitizeSvgTree(element, removed) {
95
137
  if (!element || !element.attributes) return;
96
138
  const attrs = Array.from(element.attributes);
97
139
  for (const attr of attrs) {
98
140
  const name = attr.name.toLowerCase();
99
- const value = String(attr.value || '').toLowerCase();
100
- if (name.startsWith('on') || value.includes('javascript:')) {
141
+ const value = String(attr.value || '');
142
+ const isDataOrAria = name.startsWith('data-') || name.startsWith('aria-');
143
+ const hasUnsafeUrl = /javascript:/i.test(value)
144
+ || (/url\s*\(/i.test(value) && !LOCAL_FRAGMENT_URL_RE.test(value));
145
+ if ((!SAFE_SVG_ATTRIBUTES.has(name) && !isDataOrAria) || hasUnsafeUrl) {
101
146
  element.removeAttribute(attr.name);
147
+ removed.attributes++;
102
148
  }
103
149
  }
150
+
104
151
  const children = Array.from(element.children || []);
105
152
  for (const child of children) {
106
- if (child.nodeName && child.nodeName.toLowerCase() === 'script') {
153
+ const name = String(child.localName || child.nodeName || '').toLowerCase();
154
+ if (!SAFE_SVG_ELEMENTS.has(name)) {
107
155
  child.remove();
156
+ removed.elements++;
108
157
  continue;
109
158
  }
110
- stripDangerousAttributes(child);
159
+ sanitizeSvgTree(child, removed);
111
160
  }
112
161
  }
113
162
 
package/src/database.js CHANGED
@@ -5336,6 +5336,30 @@ class PRMetadataRepository {
5336
5336
  return row.host;
5337
5337
  }
5338
5338
 
5339
+ /**
5340
+ * Get the stored host binding for a PR together with its recorded web URL.
5341
+ *
5342
+ * A stored `NULL` is ambiguous on its own: it means github.com for anything
5343
+ * stamped since schema v50, but "never stamped" for older rows. The recorded
5344
+ * `html_url` is the evidence that settles it, so host resolution can read
5345
+ * both in one query instead of guessing (see `resolveRecordedHost`).
5346
+ *
5347
+ * @param {string} repository - Repository in owner/repo format
5348
+ * @param {number} prNumber - Pull request number
5349
+ * @returns {Promise<{host: string|null, recordedUrl: string|null}|undefined>}
5350
+ * `undefined` when no pr_metadata row exists for the PR.
5351
+ */
5352
+ async getPRHostWithRecordedUrl(repository, prNumber) {
5353
+ const row = await queryOne(this.db, `
5354
+ SELECT host, json_extract(pr_data, '$.html_url') AS recorded_url
5355
+ FROM pr_metadata
5356
+ WHERE pr_number = ? AND repository = ? COLLATE NOCASE
5357
+ `, [prNumber, repository]);
5358
+
5359
+ if (!row) return undefined;
5360
+ return { host: row.host, recordedUrl: row.recorded_url || null };
5361
+ }
5362
+
5339
5363
  /**
5340
5364
  * Update ONLY the host binding for a PR's metadata row.
5341
5365
  *
@@ -19,12 +19,8 @@
19
19
  */
20
20
 
21
21
  const { GitHubClient, GitHubApiError } = require('../github/client');
22
- const {
23
- getGitHubToken,
24
- resolveHostBinding,
25
- resolveBindingRepositoryFromPR
26
- } = require('../config');
27
- const { storedHostToOption } = require('../utils/host-resolution');
22
+ const { getGitHubToken, resolveHostBinding } = require('../config');
23
+ const { storedHostToOption, resolveBindingRepositoryForHost } = require('../utils/host-resolution');
28
24
 
29
25
  const name = 'github';
30
26
 
@@ -88,17 +84,19 @@ function resolveCredentials(config, repository, _deps, options = {}) {
88
84
  GitHubClient,
89
85
  getGitHubToken,
90
86
  resolveHostBinding,
91
- resolveBindingRepositoryFromPR,
87
+ resolveBindingRepositoryForHost,
92
88
  ..._deps
93
89
  };
94
90
  const safeConfig = config || {};
95
91
 
96
92
  if (repository) {
97
93
  // Binding-aware path. Mirrors resolveBindingForRequest in routes/pr.js:
98
- // resolve the PR identity to a binding key, then to a host binding —
99
- // pinned to the PR's stored host for dual repos.
94
+ // resolve the PR identity to a binding key for the host it is recorded on,
95
+ // then to a host binding — pinned to that host for dual repos. Passing the
96
+ // host into the key lookup keeps an exclusive alt entry that merely
97
+ // `url_pattern`-claimed this owner/repo from serving a github.com PR.
100
98
  const [owner, repo] = String(repository).split('/');
101
- const bindingRepository = deps.resolveBindingRepositoryFromPR(owner, repo, safeConfig);
99
+ const bindingRepository = deps.resolveBindingRepositoryForHost(owner, repo, safeConfig, options.storedHost);
102
100
  const hostOption = storedHostToOption(safeConfig, bindingRepository, options.storedHost);
103
101
  const binding = deps.resolveHostBinding(bindingRepository, safeConfig, hostOption || {});
104
102
  if (!binding || !binding.token) {