@in-the-loop-labs/pair-review 5.1.1 → 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.
Files changed (41) hide show
  1. package/README.md +12 -4
  2. package/package.json +3 -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/public/index.html +6 -2
  7. package/public/js/index.js +251 -73
  8. package/public/js/repo-links.js +60 -11
  9. package/src/ai/index.js +1 -0
  10. package/src/ai/omp/review-config.yml +13 -0
  11. package/src/ai/omp-provider.js +279 -0
  12. package/src/ai/pi-format.js +535 -0
  13. package/src/ai/pi-provider.js +38 -963
  14. package/src/ai/pi-style-provider.js +526 -0
  15. package/src/ai/provider.js +2 -0
  16. package/src/chat/chat-providers.js +34 -11
  17. package/src/chat/omp-bridge.js +111 -0
  18. package/src/chat/pi-bridge.js +42 -34
  19. package/src/chat/session-manager.js +30 -4
  20. package/src/config.js +32 -3
  21. package/src/database.js +24 -0
  22. package/src/external/github-adapter.js +8 -10
  23. package/src/links/host-names.js +200 -0
  24. package/src/local-review.js +7 -3
  25. package/src/main.js +72 -23
  26. package/src/review-config.js +81 -5
  27. package/src/routes/config.js +42 -12
  28. package/src/routes/external-comments.js +18 -6
  29. package/src/routes/github-collections.js +32 -5
  30. package/src/routes/local.js +1 -1
  31. package/src/routes/pr.js +47 -28
  32. package/src/routes/setup.js +15 -8
  33. package/src/routes/stack-analysis.js +22 -9
  34. package/src/routes/worktrees.js +36 -0
  35. package/src/server.js +8 -3
  36. package/src/settings/registry.js +1 -1
  37. package/src/setup/local-setup.js +5 -3
  38. package/src/setup/pr-setup.js +49 -26
  39. package/src/single-port.js +7 -7
  40. package/src/utils/host-resolution.js +177 -27
  41. package/src/utils/local-path-input.js +64 -8
@@ -112,18 +112,105 @@
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, '"')
119
+ .replace(/'/g, ''');
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.
118
125
 
119
- const LOCAL_REVIEW_PATH_URL_ERROR = 'Local reviews require a filesystem path, not a URL. Pass GitHub or Graphite URLs as PR review inputs instead.';
126
+ // Hosts named in URL copy, from /api/config's `pr_host_list`, which the
127
+ // SERVER formats (GitHub always; Graphite only when enable_graphite; each alt
128
+ // host's links.external.name). Taking the pre-joined string rather than the
129
+ // array keeps the Oxford-comma formatting in exactly one place —
130
+ // src/links/host-names.js — so this copy cannot drift from the
131
+ // identically-worded server-side errors.
132
+ //
133
+ // null until /api/config resolves. The copy then reads host-neutral rather
134
+ // than naming the built-ins, which would claim an alt host's URLs are
135
+ // unsupported when they are accepted (matching localReviewPathUrlError() in
136
+ // src/utils/local-path-input.js for its config-free callers).
137
+ let prHostList = null;
138
+
139
+ // Hostnames recognised as scheme-less PR URLs. Seeded with the built-ins and
140
+ // replaced from /api/config's `pr_url_hostnames`, which adds every
141
+ // configured alt host. Mirrors resolveUrlLikeHostnames() server-side.
142
+ let prUrlHostnames = ['github.com', 'app.graphite.dev', 'app.graphite.com'];
143
+
144
+ /** "GitHub " / "GitHub or Graphite " while the host list is known, else "". */
145
+ function prHostPrefix() {
146
+ return prHostList ? prHostList + ' ' : '';
147
+ }
148
+
149
+ function localReviewPathUrlError() {
150
+ return 'Local reviews require a filesystem path, not a URL. '
151
+ + 'Pass ' + (prHostList ? prHostList + ' URLs' : 'PR URLs')
152
+ + ' as PR review inputs instead.';
153
+ }
154
+
155
+ /**
156
+ * Adopt the server-formatted host list and refresh the copy that names it.
157
+ *
158
+ * Called once /api/config resolves. The static markup ships host-neutral
159
+ * ("Enter PR URL", "a GitHub URL") so nothing flashes a host list that the
160
+ * installation does not actually support.
161
+ *
162
+ * @param {Object} config - /api/config payload
163
+ */
164
+ function applyPrHostList(config) {
165
+ if (!config) return;
166
+ if (Array.isArray(config.pr_url_hostnames) && config.pr_url_hostnames.length > 0) {
167
+ prUrlHostnames = config.pr_url_hostnames;
168
+ }
169
+ if (typeof config.pr_host_list !== 'string' || !config.pr_host_list) return;
170
+ prHostList = config.pr_host_list;
171
+
172
+ const urlInput = document.getElementById('pr-url-input');
173
+ if (urlInput) urlInput.placeholder = 'Enter ' + prHostList + ' PR URL';
174
+
175
+ document.querySelectorAll('[data-pr-host-list]').forEach(el => {
176
+ el.textContent = prHostList;
177
+ });
178
+ }
179
+
180
+ /**
181
+ * Drop the "this element is showing the URL error" marker.
182
+ *
183
+ * Called from every writer that replaces or hides the message, so the flag
184
+ * cannot outlive the message it describes — otherwise an unrelated error
185
+ * (e.g. a failed directory picker) would be dismissed by the next keystroke.
186
+ *
187
+ * @param {HTMLElement} errorEl
188
+ */
189
+ function clearLocalPathUrlErrorFlag(errorEl) {
190
+ if (errorEl) delete errorEl.dataset.localPathUrlError;
191
+ }
192
+
193
+ /**
194
+ * Show the "that's a URL, not a path" error and mark the element so
195
+ * handleLocalPathInput can clear it without comparing message text.
196
+ */
197
+ function showLocalPathUrlError() {
198
+ // showError() clears the flag first, so setting it AFTER is what makes it
199
+ // describe THIS message rather than a previous one.
200
+ showError('local', localReviewPathUrlError());
201
+ const errorEl = document.getElementById('start-review-error-local');
202
+ if (errorEl) errorEl.dataset.localPathUrlError = 'true';
203
+ }
120
204
 
121
205
  function isUrlLikeLocalReviewPath(value) {
122
206
  if (!value || typeof value !== 'string') return false;
123
207
  const trimmed = value.trim();
124
208
  if (!trimmed) return false;
125
209
  if (/^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed)) return true;
126
- if (/^(?:github\.com|app\.graphite\.(?:dev|com))\//i.test(trimmed)) return true;
210
+ // Require a path separator so a bare hostname-shaped directory name is
211
+ // not mistaken for a URL.
212
+ const lower = trimmed.toLowerCase();
213
+ if (prUrlHostnames.some(hostname => lower.startsWith(hostname + '/'))) return true;
127
214
  // Keep this aligned with src/utils/local-path-input.js: only a leading
128
215
  // user@host:path token is treated as an SSH-style remote.
129
216
  if (/^[^@/\\\s]+@[^:/\\\s]+:[^\s]+$/.test(trimmed)) return true;
@@ -172,6 +259,7 @@
172
259
  const elId = tab === 'pr' ? 'start-review-error-pr' : 'start-review-error-local';
173
260
  const errorEl = document.getElementById(elId);
174
261
  if (errorEl) {
262
+ clearLocalPathUrlErrorFlag(errorEl);
175
263
  errorEl.textContent = message;
176
264
  errorEl.classList.remove('info');
177
265
  errorEl.classList.add('visible');
@@ -188,6 +276,7 @@
188
276
  const elId = tab === 'pr' ? 'start-review-error-pr' : 'start-review-error-local';
189
277
  const errorEl = document.getElementById(elId);
190
278
  if (errorEl) {
279
+ clearLocalPathUrlErrorFlag(errorEl);
191
280
  errorEl.textContent = message;
192
281
  errorEl.classList.add('visible', 'info');
193
282
  }
@@ -257,9 +346,9 @@
257
346
 
258
347
  return '' +
259
348
  '<tr data-session-id="' + session.id + '">' +
260
- '<td class="col-local-name" title="' + escapeHtml(session.name || 'Untitled') + '"><a href="' + link + '">' + nameDisplay + '</a></td>' +
261
- '<td class="col-local-sha" title="' + escapeHtml(session.local_head_sha || '') + '">' + escapeHtml(sha) + '</td>' +
262
- '<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>' +
263
352
  '<td class="col-repo">' + escapeHtml(session.repository || '') + '</td>' +
264
353
  '<td class="col-time">' + relativeTime + '</td>' +
265
354
  '<td class="col-actions">' +
@@ -267,7 +356,7 @@
267
356
  '<button' +
268
357
  ' class="btn-delete-session"' +
269
358
  ' data-session-id="' + session.id + '"' +
270
- ' data-session-path="' + escapeHtml(pathDisplay) + '"' +
359
+ ' data-session-path="' + escapeHtmlAttribute(pathDisplay) + '"' +
271
360
  ' title="Delete session"' +
272
361
  '>' +
273
362
  '<svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor">' +
@@ -388,6 +477,79 @@
388
477
  if (clearBtn) clearBtn.hidden = !value;
389
478
  }
390
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
+
391
553
  /**
392
554
  * Render a single row for a collection PR table.
393
555
  * @param {Object} pr - PR object from the API
@@ -403,39 +565,37 @@
403
565
  ? '<a href="https://github.com/' + encodeURIComponent(pr.author) + '" target="_blank" rel="noopener">' + escapeHtml(pr.author) + '</a>'
404
566
  : '';
405
567
 
406
- var githubLinkHtml =
407
- '<a href="' + escapeHtml(pr.html_url || prUrl) + '" target="_blank" rel="noopener" class="btn-github-link" title="Open on GitHub">' +
408
- '<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>' +
409
- '</a>';
410
-
411
- var graphiteLinkHtml = '';
412
- if (window.__pairReview?.enableGraphite && pr.html_url) {
413
- // Derive from html_url to preserve GitHub's original casing (Graphite URLs are case-sensitive)
414
- var graphiteUrl = window.__pairReview.toGraphiteUrl(pr.html_url);
415
- graphiteLinkHtml =
416
- '<a href="' + escapeHtml(graphiteUrl) + '" target="_blank" rel="noopener" class="btn-github-link" title="Open on Graphite">' +
417
- '<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>' +
418
- '</a>';
419
- }
420
-
421
568
  var authorTd = collection === 'my-prs'
422
569
  ? ''
423
570
  : '<td class="col-author">' + authorDisplay + '</td>';
424
571
 
425
- // `data-host` carries the alt-host api_host string for PRs that live on an
426
- // alternate host; github.com rows have no host and render an empty
427
- // attribute. The click handler threads it into the setup call so a dual
428
- // repo's alt-host PR opens against the right system without re-probing.
429
- 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
+ });
430
590
 
431
591
  return '' +
432
- '<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 + '>' +
433
593
  '<td class="col-repo">' + escapeHtml(repoFull) + '</td>' +
434
594
  '<td class="col-pr"><span class="collection-pr-number">#' + pr.number + '</span></td>' +
435
- '<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>' +
436
596
  authorTd +
437
597
  '<td class="col-time">' + relativeTime + '</td>' +
438
- '<td class="col-actions">' + githubLinkHtml + graphiteLinkHtml + '</td>' +
598
+ '<td class="col-actions">' + actionLinks + '</td>' +
439
599
  '</tr>';
440
600
  }
441
601
 
@@ -885,7 +1045,10 @@
885
1045
 
886
1046
  // Clear previous errors/info messages
887
1047
  const errorEl = document.getElementById('start-review-error-local');
888
- if (errorEl) errorEl.classList.remove('visible', 'info');
1048
+ if (errorEl) {
1049
+ errorEl.classList.remove('visible', 'info');
1050
+ clearLocalPathUrlErrorFlag(errorEl);
1051
+ }
889
1052
 
890
1053
  if (!pathValue) {
891
1054
  showError('local', 'Please enter a directory path');
@@ -894,7 +1057,7 @@
894
1057
  }
895
1058
 
896
1059
  if (isUrlLikeLocalReviewPath(pathValue)) {
897
- showError('local', LOCAL_REVIEW_PATH_URL_ERROR);
1060
+ showLocalPathUrlError();
898
1061
  input.focus();
899
1062
  return;
900
1063
  }
@@ -912,12 +1075,16 @@
912
1075
  if (!input || !errorEl) return;
913
1076
 
914
1077
  if (isUrlLikeLocalReviewPath(input.value)) {
915
- showError('local', LOCAL_REVIEW_PATH_URL_ERROR);
1078
+ showLocalPathUrlError();
916
1079
  return;
917
1080
  }
918
1081
 
919
- if (errorEl.textContent === LOCAL_REVIEW_PATH_URL_ERROR) {
1082
+ // Flagged rather than text-compared: the message names the configured
1083
+ // hosts, so it can change between being shown and being cleared (the
1084
+ // host list arrives asynchronously from /api/config).
1085
+ if (errorEl.dataset.localPathUrlError === 'true') {
920
1086
  errorEl.classList.remove('visible', 'info');
1087
+ clearLocalPathUrlErrorFlag(errorEl);
921
1088
  }
922
1089
  }
923
1090
 
@@ -976,7 +1143,11 @@
976
1143
  const parts = review.repository.split('/');
977
1144
  const owner = parts[0];
978
1145
  const repo = parts[1];
979
- 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) : '');
980
1151
  const settingsLink = '/repo-settings.html?owner=' + encodeURIComponent(owner) + '&repo=' + encodeURIComponent(repo);
981
1152
  const relativeTime = formatRelativeTime(review.last_accessed_at);
982
1153
 
@@ -985,23 +1156,27 @@
985
1156
  : '';
986
1157
 
987
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
+ });
988
1170
 
989
1171
  return '' +
990
1172
  '<tr data-review-id="' + review.id + '"' + reviewIdAttr + '>' +
991
1173
  '<td class="col-repo">' + escapeHtml(review.repository) + '</td>' +
992
1174
  '<td class="col-pr"><a href="' + link + '">#' + review.pr_number + '</a></td>' +
993
- '<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>' +
994
1176
  '<td class="col-author">' + authorDisplay + '</td>' +
995
1177
  '<td class="col-time">' + relativeTime + '</td>' +
996
1178
  '<td class="col-actions">' +
997
- '<a href="https://github.com/' + escapeHtml(review.repository) + '/pull/' + review.pr_number + '" target="_blank" rel="noopener" class="btn-github-link" title="Open on GitHub">' +
998
- '<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>' +
999
- '</a>' +
1000
- (window.__pairReview?.enableGraphite && review.html_url
1001
- ? '<a href="' + escapeHtml(window.__pairReview.toGraphiteUrl(review.html_url)) + '" target="_blank" rel="noopener" class="btn-github-link" title="Open on Graphite">' +
1002
- '<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>' +
1003
- '</a>'
1004
- : '') +
1179
+ actionLinks +
1005
1180
  '<a href="' + settingsLink + '" class="btn-repo-settings" title="Repository settings">' +
1006
1181
  '<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">' +
1007
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"/>' +
@@ -1010,7 +1185,7 @@
1010
1185
  '<button' +
1011
1186
  ' class="btn-delete-review"' +
1012
1187
  ' data-review-id="' + review.id + '"' +
1013
- ' data-repository="' + escapeHtml(review.repository) + '"' +
1188
+ ' data-repository="' + escapeHtmlAttribute(review.repository) + '"' +
1014
1189
  ' data-pr-number="' + review.pr_number + '"' +
1015
1190
  ' title="Delete review"' +
1016
1191
  '>' +
@@ -1281,9 +1456,9 @@
1281
1456
  // string = alt host, null = github.com, undefined = unknown.
1282
1457
  host: data.host,
1283
1458
  bindingRepository: data.bindingRepository,
1284
- // Whether the repo is dual (github + alt-host). Only dual repos probe,
1285
- // so only they need an explicit github pick when the URL is a github URL.
1286
- 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
1287
1462
  };
1288
1463
  }
1289
1464
 
@@ -1313,7 +1488,7 @@
1313
1488
 
1314
1489
  // Validate input
1315
1490
  if (!url) {
1316
- showError('pr', 'Please enter a GitHub PR URL');
1491
+ showError('pr', 'Please enter a ' + prHostPrefix() + 'PR URL');
1317
1492
  input.focus();
1318
1493
  return;
1319
1494
  }
@@ -1325,7 +1500,7 @@
1325
1500
  const parsed = await parsePRUrl(url);
1326
1501
  if (!parsed) {
1327
1502
  setFormLoading('pr', false);
1328
- showError('pr', 'Invalid PR URL. Please enter a GitHub or Graphite PR URL (e.g., https://github.com/owner/repo/pull/123)');
1503
+ showError('pr', 'Invalid PR URL. Please enter a ' + prHostPrefix() + 'PR URL (e.g., https://github.com/owner/repo/pull/123)');
1329
1504
  input.focus();
1330
1505
  return;
1331
1506
  }
@@ -1335,17 +1510,12 @@
1335
1510
  let href = '/pr/' + encodeURIComponent(parsed.owner) + '/' + encodeURIComponent(parsed.repo) + '/' + encodeURIComponent(parsed.prNumber);
1336
1511
  var params = new URLSearchParams();
1337
1512
  if (analyze) params.set('analyze', 'true');
1338
- // Forward the parsed host so setup binds directly instead of probing:
1339
- // - alt-host URL string → the api_host (setup binds that alt host)
1340
- // - github URL (host === null) on a DUAL repo → the "github" sentinel, so
1341
- // setup binds github.com instead of probing alt-first (which would fail
1342
- // loudly if the alt host is down for a PR we KNOW is on github)
1343
- // - anything else (plain/exclusive repo, unknown host) → omit; no probe
1344
- // happens for those and omitting avoids the exclusive-null throw.
1345
- if (typeof parsed.host === 'string' && parsed.host) {
1346
- params.set('host', parsed.host);
1347
- } else if (parsed.host === null && parsed.isDualHost) {
1348
- 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);
1349
1519
  }
1350
1520
  var qs = params.toString();
1351
1521
  if (qs) href += '?' + qs;
@@ -1397,6 +1567,7 @@
1397
1567
  window.__pairReview.modelOverride = config.model_override || null;
1398
1568
  window.__pairReview.hasGithubToken = Boolean(config.has_github_token);
1399
1569
  window.__pairReview.enableGraphite = config.enable_graphite === true;
1570
+ applyPrHostList(config);
1400
1571
  window.__pairReview.chatSpinner = config.chat_spinner || 'dots';
1401
1572
  window.__pairReview.chatEnterToSend = config.chat_enter_to_send !== false;
1402
1573
 
@@ -1919,9 +2090,9 @@
1919
2090
  repo: tr.dataset.repo,
1920
2091
  number: tr.dataset.number,
1921
2092
  prUrl: prUrl,
1922
- // Alt-host rows carry a host; github.com rows leave it undefined. The
1923
- // single-row click path threads this the same way (see the collection
1924
- // 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.
1925
2096
  host: tr.dataset.host
1926
2097
  });
1927
2098
  }
@@ -1931,9 +2102,9 @@
1931
2102
 
1932
2103
  function buildReviewUrlsFromRows(rows, query) {
1933
2104
  return rows.map(function (row) {
1934
- // Preserve any existing params (analyze / analysisConfigId) and append the
1935
- // alt host so setup opens the PR against the system it lives on instead of
1936
- // 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.
1937
2108
  var qs = query || '';
1938
2109
  if (row.host) {
1939
2110
  qs += (qs ? '&' : '?') + 'host=' + encodeURIComponent(row.host);
@@ -2192,12 +2363,10 @@
2192
2363
  return;
2193
2364
  }
2194
2365
 
2195
- // Alt-host PR: we already know owner/repo/number and the host it lives
2196
- // on, so navigate straight to the PR route with the host as a query
2197
- // param (setup.html forwards it into the setup POST body). This bypasses
2198
- // the URL-parse round trip, which can't reliably recover the host from a
2199
- // pasted alt-host html_url. github.com rows (no host) keep the existing
2200
- // 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.
2201
2370
  var rowHost = collectionRow.dataset.host;
2202
2371
  if (rowHost) {
2203
2372
  var o = encodeURIComponent(collectionRow.dataset.owner);
@@ -2592,7 +2761,16 @@
2592
2761
  if (typeof module !== 'undefined' && module.exports) {
2593
2762
  module.exports = {
2594
2763
  buildReviewUrlsFromRows: buildReviewUrlsFromRows,
2595
- getSelectedCollectionRows: getSelectedCollectionRows
2764
+ getSelectedCollectionRows: getSelectedCollectionRows,
2765
+ applyPrHostList: applyPrHostList,
2766
+ isUrlLikeLocalReviewPath: isUrlLikeLocalReviewPath,
2767
+ localReviewPathUrlError: localReviewPathUrlError,
2768
+ showError: showError,
2769
+ showInfo: showInfo,
2770
+ showLocalPathUrlError: showLocalPathUrlError,
2771
+ handleLocalPathInput: handleLocalPathInput,
2772
+ renderCollectionPrRow: renderCollectionPrRow,
2773
+ renderRecentReviewRow: renderRecentReviewRow
2596
2774
  };
2597
2775
  }
2598
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/ai/index.js CHANGED
@@ -55,6 +55,7 @@ require('./copilot-provider');
55
55
  require('./opencode-provider');
56
56
  require('./cursor-agent-provider');
57
57
  require('./pi-provider');
58
+ require('./omp-provider');
58
59
  require('./muse-provider');
59
60
 
60
61
  // Export the unified API