@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
@@ -26,6 +26,8 @@ const {
26
26
  const { getAdapter } = require('../external');
27
27
  const { GitHubApiError } = require('../github/client');
28
28
  const logger = require('../utils/logger');
29
+ const { resolveBindingRepositoryFromPR } = require('../config');
30
+ const { resolveRecordedHost } = require('../utils/host-resolution');
29
31
 
30
32
  const router = express.Router();
31
33
 
@@ -136,15 +138,25 @@ async function executeSync({ db, config, review, source, _deps }) {
136
138
  );
137
139
  }
138
140
 
139
- // Look up the PR's stored host so a DUAL repo's alt-hosted PR binds to the
140
- // alt host (and its line-based anchoring path) rather than api.github.com.
141
- // Pass the raw stored value through to the adapter, which applies the
142
- // legacy-NULL convention against its resolved binding key. `undefined`
143
- // (no row / unknown) preserves the two-arg ambiguity behaviour.
141
+ // Look up the host the PR is recorded on so a DUAL repo's alt-hosted PR binds
142
+ // to the alt host (and its line-based anchoring path) rather than
143
+ // api.github.com. `resolveRecordedHost` reads the stored host plus the recorded
144
+ // html_url, which is what distinguishes a pre-stamping row from a github.com
145
+ // one; the adapter then applies the legacy-NULL convention against the binding
146
+ // key it resolves for that host. `undefined` (no row) preserves the two-arg
147
+ // ambiguity behaviour.
144
148
  let storedHost;
145
149
  if (Number.isInteger(review.pr_number)) {
146
150
  const prMetadataRepo = new PRMetadataRepository(db);
147
- storedHost = await prMetadataRepo.getPRHost(review.repository, review.pr_number);
151
+ const recorded = await prMetadataRepo.getPRHostWithRecordedUrl(review.repository, review.pr_number);
152
+ if (recorded !== undefined) {
153
+ storedHost = resolveRecordedHost(
154
+ config || {},
155
+ resolveBindingRepositoryFromPR(owner, repo, config || {}),
156
+ recorded.host,
157
+ recorded.recordedUrl
158
+ );
159
+ }
148
160
  }
149
161
 
150
162
  // Delegate credential resolution to the adapter so the route stays
@@ -18,6 +18,8 @@ const { query, run, withTransaction } = require('../database');
18
18
  const { GitHubClient } = require('../github/client');
19
19
  const { getGitHubToken, resolveHostBinding } = require('../config');
20
20
  const logger = require('../utils/logger');
21
+ const { resolveRepoLinks } = require('../links/repo-links');
22
+ const { resolveBindingRepositoryForHost, setupHostParam } = require('../utils/host-resolution');
21
23
 
22
24
  const router = express.Router();
23
25
 
@@ -235,6 +237,30 @@ async function getCachedRows(db, collection) {
235
237
  );
236
238
  }
237
239
 
240
+ /**
241
+ * Attach the host-aware repository link configuration consumed by the landing
242
+ * page, plus the `?host=` value its rows navigate with. Resolution is an
243
+ * in-memory config lookup, so this avoids per-row HTTP requests while keeping
244
+ * cached and refreshed responses identical.
245
+ *
246
+ * A row's `host` is authoritative here, unlike a legacy `pr_metadata` NULL:
247
+ * every refresh re-derives these rows, stamping NULL from the github.com search
248
+ * branch and the `api_host` from the alt-host sweep. Both the links and the
249
+ * navigation target are therefore resolved for that known host, through the
250
+ * same two helpers the setup route uses — so a row's action icon and its click
251
+ * always reach the system the PR actually lives on.
252
+ */
253
+ function attachRepoLinks(rows, config) {
254
+ return rows.map((row) => {
255
+ const bindingRepository = resolveBindingRepositoryForHost(row.owner, row.repo, config, row.host);
256
+ return {
257
+ ...row,
258
+ repo_links: resolveRepoLinks(config, bindingRepository, row.host),
259
+ setup_host: setupHostParam(config, row.owner, row.repo, row.host)
260
+ };
261
+ });
262
+ }
263
+
238
264
  /**
239
265
  * Register the GET (cached) and POST (refresh) routes for a single collection.
240
266
  * @param {Object} def - Collection definition
@@ -259,8 +285,9 @@ function registerCollection(def) {
259
285
 
260
286
  const db = req.app.get('db');
261
287
  const rows = await getCachedRows(db, cacheKey(name, team));
288
+ const prs = attachRepoLinks(rows, req.app.get('config') || {});
262
289
  const fetchedAt = rows.length > 0 ? rows[0].fetched_at : null;
263
- res.json({ success: true, prs: rows, fetched_at: fetchedAt });
290
+ res.json({ success: true, prs, fetched_at: fetchedAt });
264
291
  } catch (error) {
265
292
  logger.error(`Failed to fetch ${label}:`, error);
266
293
  res.status(500).json({ success: false, error: `Failed to fetch ${label}` });
@@ -344,13 +371,13 @@ function registerCollection(def) {
344
371
  });
345
372
 
346
373
  const rows = await getCachedRows(db, key);
374
+ const resolvedRows = attachRepoLinks(rows, config);
347
375
  const fetchedAt = rows.length > 0 ? rows[0].fetched_at : null;
348
376
  // `hosts` is additive; omit it entirely when every source is healthy (no
349
- // alt-host repos and a working github token) so the github-only happy-path
350
- // response shape is byte-identical to before. A skipped github source or
351
- // any alt-host status makes it appear.
377
+ // alt-host repos and a working github token) so the happy path gains no
378
+ // `hosts` key. A skipped github source or any alt-host status adds it.
352
379
  const allStatuses = sourceStatuses.concat(hosts);
353
- const payload = { success: true, prs: rows, fetched_at: fetchedAt };
380
+ const payload = { success: true, prs: resolvedRows, fetched_at: fetchedAt };
354
381
  if (allStatuses.length > 0) payload.hosts = allStatuses;
355
382
  res.json(payload);
356
383
  } catch (error) {
@@ -390,7 +390,7 @@ router.post('/api/local/start', async (req, res) => {
390
390
  }
391
391
 
392
392
  try {
393
- rejectUrlLikeLocalReviewPath(inputPath);
393
+ rejectUrlLikeLocalReviewPath(inputPath, req.app.get('config'));
394
394
  } catch (err) {
395
395
  return res.status(400).json({ error: err.message });
396
396
  }
package/src/routes/pr.js CHANGED
@@ -26,9 +26,10 @@ const Analyzer = require('../ai/analyzer');
26
26
  const { v4: uuidv4 } = require('uuid');
27
27
  const fs = require('fs').promises;
28
28
  const path = require('path');
29
- const { resolveHostBinding, resolveBindingRepositoryFromPR, getWorktreeDisplayName, resolveLoadSkills, buildCouncilProviderOverrides, getSummaryEnabled, getTourEnabled } = require('../config');
30
- const { storedHostToOption, isDualHostRepo } = require('../utils/host-resolution');
29
+ const { resolveHostBinding, getWorktreeDisplayName, resolveLoadSkills, buildCouncilProviderOverrides, getSummaryEnabled, getTourEnabled, resolveBindingRepositoryFromPR } = require('../config');
30
+ const { storedHostToOption, resolveRecordedHost, resolveBindingRepositoryForHost, setupHostParam } = require('../utils/host-resolution');
31
31
  const { resolveHostName } = require('../links/repo-links');
32
+ const { resolveHostListText } = require('../links/host-names');
32
33
  const { backgroundQueue } = require('../ai/background-queue');
33
34
  const logger = require('../utils/logger');
34
35
  const { buildDiffLineSet } = require('../utils/diff-annotator');
@@ -139,28 +140,46 @@ module.exports._attachHunkHashes = attachHunkHashes;
139
140
  */
140
141
  async function resolveBindingForRequest(req, repository) {
141
142
  const config = req.app.get('config') || {};
142
- // `repository` here is the PR-identity `${owner}/${repo}`. For
143
- // monorepo-style configs the binding-key in `config.repos` can differ;
144
- // resolve it via `resolveBindingRepositoryFromPR` before looking up
145
- // the host binding so per-repo tokens/api_host/features apply.
143
+ // `repository` here is the PR-identity `${owner}/${repo}`. For monorepo-style
144
+ // configs the binding-key in `config.repos` can differ, so it is resolved
145
+ // through the shared helper before looking up the host binding — per-repo
146
+ // tokens/api_host/features then apply. The lookup is host-aware: an exclusive
147
+ // alt entry that only `url_pattern`-claimed this owner/repo cannot serve a PR
148
+ // proven to be on github.com, and must not bind it (same rule the dashboard
149
+ // rows and the setup route use).
146
150
  const [owner, repo] = String(repository).split('/');
147
- const bindingRepository = resolveBindingRepositoryFromPR(owner, repo, config);
148
151
 
149
152
  // PR-aware host resolution. Every caller is an `/:owner/:repo/:number` route,
150
- // so a per-PR host may already be stored. When a pr_metadata row exists, bind
151
- // to its stored host (github for NULL, the api_host string for an alt host);
152
- // when no row exists, fall back to the ambiguity rule (two-arg resolve). A
153
- // stale stored host (config changed) makes resolveHostBinding throw — that
154
- // surfaces to the route's error handler as a clear failure rather than a
155
- // silent bind to a dead host.
153
+ // so a per-PR host may already be recorded. `resolveRecordedHost` reads the
154
+ // stored host plus the recorded html_url, upgrading a NULL to the alt host
155
+ // only where the URL proves it — an unprovable legacy NULL resolves to `null`
156
+ // (github.com), the same value the raw column carried, so those reviews bind
157
+ // exactly as before. A stale stored host (config changed) makes
158
+ // resolveHostBinding throw — that surfaces to the route's error handler
159
+ // rather than a silent bind to a dead host.
156
160
  const prNumber = parseInt(req.params && req.params.number, 10);
157
- let hostOptions;
161
+ let recordedHost;
158
162
  if (Number.isInteger(prNumber) && prNumber > 0) {
159
163
  const prMetadataRepo = new PRMetadataRepository(req.app.get('db'));
160
- const storedHost = await prMetadataRepo.getPRHost(repository, prNumber);
161
- // Apply the legacy-NULL back-compat convention (see storedHostToOption).
162
- hostOptions = storedHostToOption(config, bindingRepository, storedHost);
164
+ const recorded = await prMetadataRepo.getPRHostWithRecordedUrl(repository, prNumber);
165
+ if (recorded !== undefined) {
166
+ recordedHost = resolveRecordedHost(
167
+ config,
168
+ resolveBindingRepositoryFromPR(owner, repo, config),
169
+ recorded.host,
170
+ recorded.recordedUrl
171
+ );
172
+ }
163
173
  }
174
+ const bindingRepository = resolveBindingRepositoryForHost(owner, repo, config, recordedHost);
175
+ // Bind the host the evidence resolved to, NOT the raw column: a pre-stamping
176
+ // row whose recorded URL is on the alt host resolves to that host, and
177
+ // reapplying its NULL here would force a github.com binding while the row's
178
+ // links point at the alt host. `storedHostToOption` still applies the
179
+ // legacy-NULL convention against the entry that survived the check above.
180
+ const hostOptions = recordedHost === undefined
181
+ ? undefined
182
+ : storedHostToOption(config, bindingRepository, recordedHost);
164
183
  const binding = resolveHostBinding(bindingRepository, config, hostOptions || {});
165
184
  if (binding.token) {
166
185
  return { binding, token: binding.token, bindingRepository };
@@ -1769,7 +1788,11 @@ router.post('/api/pr/:owner/:repo/:number/submit-review', async (req, res) => {
1769
1788
  // string=alt) so a dual-host repo names the system this PR was submitted
1770
1789
  // to rather than its repo-level default.
1771
1790
  const cfg = req.app.get('config') || {};
1772
- const hostName = resolveHostName(cfg, resolveBindingRepositoryFromPR(owner, repo, cfg), binding.host);
1791
+ const hostName = resolveHostName(
1792
+ cfg,
1793
+ resolveBindingRepositoryForHost(owner, repo, cfg, binding.host),
1794
+ binding.host
1795
+ );
1773
1796
  res.json({
1774
1797
  success: true,
1775
1798
  message: `${event === 'DRAFT' ? 'Draft review created' : 'Review submitted'} successfully ${event === 'DRAFT' ? 'on' : 'to'} ${hostName}`,
@@ -1966,15 +1989,11 @@ router.post('/api/parse-pr-url', (req, res) => {
1966
1989
  const result = parser.parsePRUrl(url);
1967
1990
 
1968
1991
  if (result) {
1969
- // Report whether the resolved repo is DUAL (github + alt-host). A github URL
1970
- // (host === null) for a dual repo must be forwarded to setup as an explicit
1971
- // github pick (the "github" sentinel) so it does not probe alt-first; for a
1972
- // plain or exclusive repo the client omits host (no probe / avoids the
1973
- // exclusive-null throw). Resolve the binding key first (url_pattern match
1974
- // supplies it; otherwise derive from owner/repo).
1992
+ // `setupHost` is the resolved `?host=` value for this URL (see
1993
+ // setupHostParam): an alt api_host string, the 'github' sentinel when any
1994
+ // api_host entry could otherwise claim this repo, or null to omit. Computed
1995
+ // here so the browser never has to reason about repo configuration.
1975
1996
  const safeConfig = config || {};
1976
- const bindingRepository = result.bindingRepository
1977
- || resolveBindingRepositoryFromPR(result.owner, result.repo, safeConfig);
1978
1997
  return res.json({
1979
1998
  valid: true,
1980
1999
  owner: result.owner,
@@ -1987,12 +2006,12 @@ router.post('/api/parse-pr-url', (req, res) => {
1987
2006
  // from owner/repo for monorepo-style url_pattern configs).
1988
2007
  host: result.host,
1989
2008
  bindingRepository: result.bindingRepository,
1990
- isDualHost: isDualHostRepo(safeConfig, bindingRepository)
2009
+ setupHost: setupHostParam(safeConfig, result.owner, result.repo, result.host)
1991
2010
  });
1992
2011
  }
1993
2012
 
1994
2013
  return res.status(400).json({
1995
- error: 'Invalid PR URL. Please enter a GitHub or Graphite PR URL.',
2014
+ error: `Invalid PR URL. Please enter a ${resolveHostListText(config)} PR URL.`,
1996
2015
  valid: false
1997
2016
  });
1998
2017
  });
@@ -15,8 +15,8 @@ const crypto = require('crypto');
15
15
  const { activeSetups, broadcastSetupProgress } = require('./shared');
16
16
  const { setupPRReview } = require('../setup/pr-setup');
17
17
  const { setupLocalReview } = require('../setup/local-setup');
18
- const { expandPath, resolveBindingRepositoryFromPR } = require('../config');
19
- const { resolvePreflightBinding } = require('../utils/host-resolution');
18
+ const { expandPath } = require('../config');
19
+ const { resolvePreflightBinding, explicitHostForBinding, resolveBindingRepositoryForHost } = require('../utils/host-resolution');
20
20
  const { queryOne, ReviewRepository } = require('../database');
21
21
  const { normalizeRepository } = require('../utils/paths');
22
22
  const { rejectUrlLikeLocalReviewPath } = require('../utils/local-path-input');
@@ -130,13 +130,20 @@ router.post('/api/setup/pr/:owner/:repo/:number', async (req, res) => {
130
130
 
131
131
  // GitHub token is required for PR setup. Resolve the binding key first so
132
132
  // monorepo-style `repos[...]` entries (matched via `url_pattern` named
133
- // captures) supply their per-repo token even when the captured owner/repo
134
- // differs from the config key.
135
- const repositoryForToken = resolveBindingRepositoryFromPR(owner, repo, config);
133
+ // captures) supply their per-repo token — and their path, checkout script,
134
+ // pool, and reset script — even when the captured owner/repo differs from
135
+ // the config key. The lookup is host-aware: an explicit github.com host
136
+ // rejects an EXCLUSIVE alt entry that only pattern-claimed this owner/repo,
137
+ // matching the parser's invariant that such an entry never binds a
138
+ // canonical github.com PR. Dual entries are kept for either host.
139
+ const repositoryForToken = resolveBindingRepositoryForHost(owner, repo, config, bodyHost);
140
+ // Then normalise the hint against the entry that survived: a github.com hint
141
+ // for a repo whose own config says alt-host-only is ignored with a warning.
142
+ const effectiveHost = explicitHostForBinding(config, repositoryForToken, bodyHost);
136
143
  // Preflight the credential. resolvePreflightBinding gates on ANY usable
137
144
  // binding — including a dual repo's alt-only token or a token pinned by an
138
145
  // explicit body host — so an alt-host setup isn't falsely 401'd.
139
- const preflightBinding = resolvePreflightBinding(repositoryForToken, config, bodyHost);
146
+ const preflightBinding = resolvePreflightBinding(repositoryForToken, config, effectiveHost);
140
147
  if (!preflightBinding.token) {
141
148
  return res.status(401).json({ error: 'GitHub token not configured' });
142
149
  }
@@ -226,7 +233,7 @@ router.post('/api/setup/pr/:owner/:repo/:number', async (req, res) => {
226
233
  githubToken,
227
234
  bindingRepository: repositoryForToken,
228
235
  config,
229
- host: bodyHost,
236
+ host: effectiveHost,
230
237
  poolLifecycle: req.app.get('poolLifecycle'),
231
238
  restoreMetadata,
232
239
  onProgress: (progress) => {
@@ -271,7 +278,7 @@ router.post('/api/setup/local', async (req, res) => {
271
278
  }
272
279
 
273
280
  try {
274
- rejectUrlLikeLocalReviewPath(rawPath);
281
+ rejectUrlLikeLocalReviewPath(rawPath, req.app.get('config'));
275
282
  } catch (err) {
276
283
  return res.status(400).json({ error: err.message });
277
284
  }
@@ -20,7 +20,7 @@ const { mergeInstructions } = require('../utils/instructions');
20
20
  const { GitWorktreeManager } = require('../git/worktree');
21
21
  const { GitHubClient } = require('../github/client');
22
22
  const { getGitHubToken, resolveHostBinding, resolveBindingRepositoryFromPR, resolveRepoOptions, resolveLoadSkills, buildCouncilProviderOverrides } = require('../config');
23
- const { storedHostToOption } = require('../utils/host-resolution');
23
+ const { storedHostToOption, resolveRecordedHost, resolveBindingRepositoryForHost } = require('../utils/host-resolution');
24
24
  const { setupStackPR } = require('../setup/stack-setup');
25
25
  const Analyzer = require('../ai/analyzer');
26
26
  const { getProviderClass, createProvider } = require('../ai/provider');
@@ -255,14 +255,27 @@ async function executeStackAnalysis(params) {
255
255
  // monorepo-style `url_pattern` configs (one `repos[...]` entry serves many
256
256
  // captured owner/repo pairs). The PR identity is still used for DB rows and
257
257
  // worktree identity.
258
- // Resolve the stack binding from the MAIN (trigger) PR's stored host so every
259
- // sibling is fetched from — and later stamped with — the same host. Stacks
260
- // don't span systems, so a dual repo's alt-hosted stack must not fall back to
261
- // github via the two-arg ambiguity rule. `storedHostToOption` applies the
262
- // legacy-NULL convention; `undefined` (no row) preserves the ambiguity rule.
263
- const mainStoredHost = await new PRMetadataRepository(db).getPRHost(repository, triggerPRNumber);
264
- const stackHostOption = storedHostToOption(config, bindingRepository, mainStoredHost);
265
- const stackBinding = deps.resolveHostBinding(bindingRepository, config, stackHostOption || {});
258
+ // Resolve the stack binding from the MAIN (trigger) PR's recorded host so
259
+ // every sibling is fetched from — and later stamped with — the same host.
260
+ // Stacks don't span systems, so a dual repo's alt-hosted stack must not fall
261
+ // back to github via the two-arg ambiguity rule. `storedHostToOption` applies
262
+ // the legacy-NULL convention; `undefined` (no row) preserves it.
263
+ //
264
+ // The HOST key is resolved separately from `bindingRepository` above: that
265
+ // one is this PR's config identity (worktree options, pool, reset script) and
266
+ // must not move, while an exclusive alt entry that only `url_pattern`-claimed
267
+ // this owner/repo cannot serve a stack proven to be on github.com.
268
+ const mainRecorded = await new PRMetadataRepository(db).getPRHostWithRecordedUrl(repository, triggerPRNumber);
269
+ const mainRecordedHost = mainRecorded === undefined
270
+ ? undefined
271
+ : resolveRecordedHost(config, bindingRepository, mainRecorded.host, mainRecorded.recordedUrl);
272
+ const stackBindingRepository = resolveBindingRepositoryForHost(owner, repo, config, mainRecordedHost);
273
+ // Bind the resolved host, not the raw column: a pre-stamping trigger PR whose
274
+ // recorded URL is on the alt host must keep the stack on the alt host.
275
+ const stackHostOption = mainRecordedHost === undefined
276
+ ? undefined
277
+ : storedHostToOption(config, stackBindingRepository, mainRecordedHost);
278
+ const stackBinding = deps.resolveHostBinding(stackBindingRepository, config, stackHostOption || {});
266
279
  const githubToken = stackBinding.token;
267
280
  const prDataMap = new Map();
268
281
  if (githubToken) {
@@ -17,6 +17,12 @@ const { activeAnalyses, reviewToAnalysisId, killProcesses, broadcastProgress } =
17
17
  const fs = require('fs').promises;
18
18
  const logger = require('../utils/logger');
19
19
  const { resolvePoolConfig } = require('../config');
20
+ const { resolveRepoLinks } = require('../links/repo-links');
21
+ const {
22
+ resolveRecordedHost,
23
+ resolveBindingRepositoryForHost,
24
+ setupHostParam
25
+ } = require('../utils/host-resolution');
20
26
 
21
27
  const router = express.Router();
22
28
 
@@ -140,6 +146,7 @@ router.get('/api/worktrees/recent', async (req, res) => {
140
146
  const limit = Math.min(parseInt(req.query.limit) || 10, 50);
141
147
  const before = req.query.before || null;
142
148
  const db = req.app.get('db');
149
+ const config = req.app.get('config') || {};
143
150
 
144
151
  // Fetch limit + 1 to determine hasMore
145
152
  const fetchCount = limit + 1;
@@ -152,10 +159,13 @@ router.get('/api/worktrees/recent', async (req, res) => {
152
159
  pm.pr_number,
153
160
  pm.title,
154
161
  pm.author,
162
+ pm.base_branch,
155
163
  pm.head_branch,
156
164
  pm.last_accessed_at,
157
165
  pm.created_at,
158
166
  json_extract(pm.pr_data, '$.html_url') as html_url,
167
+ json_extract(pm.pr_data, '$.head_sha') as head_sha,
168
+ pm.host,
159
169
  w.id as worktree_id,
160
170
  w.path as worktree_path,
161
171
  w.branch,
@@ -195,6 +205,27 @@ router.get('/api/worktrees/recent', async (req, res) => {
195
205
  }
196
206
  }
197
207
  }
208
+ const [owner, repo] = row.repository.split('/');
209
+ // Host stamping (schema v50) was never backfilled, so a stored NULL can
210
+ // mean "github.com" OR "recorded before stamping existed".
211
+ // `resolveRecordedHost` upgrades a NULL to the alt host only where the
212
+ // recorded html_url proves it; an unprovable legacy row resolves to
213
+ // `null` (github.com), the stored convention, rather than to a host this
214
+ // row's click would not bind. Links, navigation, and the /pr binding all
215
+ // derive from this one value.
216
+ const host = resolveRecordedHost(
217
+ config,
218
+ resolveBindingRepositoryForHost(owner, repo, config, undefined),
219
+ row.host,
220
+ row.html_url
221
+ );
222
+ // With the host settled, resolve links and navigation from it through the
223
+ // same helpers the setup route uses, so the row's icon and its click
224
+ // cannot reach different systems. /pr's applyHostQueryCorrection also
225
+ // stamps the value on the way through, healing the legacy NULL.
226
+ const bindingRepository = resolveBindingRepositoryForHost(owner, repo, config, host);
227
+ const repoLinks = resolveRepoLinks(config, bindingRepository, host);
228
+ const setupHost = setupHostParam(config, owner, repo, host);
198
229
  reviews.push({
199
230
  id: row.id,
200
231
  repository: row.repository,
@@ -202,10 +233,15 @@ router.get('/api/worktrees/recent', async (req, res) => {
202
233
  pr_title: row.title,
203
234
  author: row.author || null,
204
235
  head_branch: row.head_branch || row.branch || null,
236
+ base_branch: row.base_branch || null,
205
237
  last_accessed_at: row.last_accessed_at,
206
238
  created_at: row.created_at,
207
239
  storage_status: storageStatus,
208
240
  html_url: row.html_url || null,
241
+ head_sha: row.head_sha || null,
242
+ host: host,
243
+ setup_host: setupHost,
244
+ repo_links: repoLinks,
209
245
  review_id: row.review_id || null
210
246
  });
211
247
  }
package/src/server.js CHANGED
@@ -1,9 +1,10 @@
1
1
  // Copyright 2026 Tim Perkins (tjwp) | SPDX-License-Identifier: Apache-2.0
2
2
  const express = require('express');
3
3
  const path = require('path');
4
- const { loadConfig, getGitHubToken, resolveDbName, warnIfDevModeWithoutDbName, getRepoConfig, resolveBindingRepositoryFromPR, isExclusiveAltHost } = require('./config');
4
+ const { loadConfig, getGitHubToken, resolveDbName, warnIfDevModeWithoutDbName, getRepoConfig, isExclusiveAltHost } = require('./config');
5
5
  const { initializeDatabase, getDatabaseStatus, queryOne, run, PRMetadataRepository } = require('./database');
6
6
  const { normalizeRepository } = require('./utils/paths');
7
+ const { resolveBindingRepositoryForHost } = require('./utils/host-resolution');
7
8
  const { GlobalSettingsService } = require('./settings/global-settings-service');
8
9
  const { applyConfigOverrides, checkAllProviders } = require('./ai');
9
10
  const { checkAllChatProviders } = require('./chat/chat-providers');
@@ -79,8 +80,12 @@ async function applyHostQueryCorrection(db, config, owner, repo, repository, prN
79
80
  const targetHost = rawHost === 'github' ? null : rawHost;
80
81
 
81
82
  // Resolve the repo's config entry (handles monorepo-style keys matched via
82
- // url_pattern) to learn its configured api_host.
83
- const bindingRepo = resolveBindingRepositoryFromPR(owner, repo, config);
83
+ // url_pattern) to learn its configured api_host. Host-aware: an explicit
84
+ // github.com correction is authoritative — the dashboard row it came from was
85
+ // sourced from the github.com search, or the user pasted a github.com URL —
86
+ // so an exclusive alt entry that merely `url_pattern`-claimed this owner/repo
87
+ // is rejected here too, and the correction is accepted instead of dropped.
88
+ const bindingRepo = resolveBindingRepositoryForHost(owner, repo, config, targetHost);
84
89
  const repoConfig = getRepoConfig(config, bindingRepo);
85
90
  const configuredApiHost = (repoConfig && typeof repoConfig.api_host === 'string' && repoConfig.api_host)
86
91
  ? repoConfig.api_host
@@ -66,7 +66,7 @@ const REGISTRY = [
66
66
  {
67
67
  key: 'enable_graphite',
68
68
  label: 'Show Graphite links',
69
- description: 'Show Graphite links alongside GitHub links in the PR header.',
69
+ description: 'Show Graphite links alongside GitHub links in the PR header, and name Graphite in the PR URL prompts and errors. Graphite PR URLs are accepted either way.',
70
70
  group: 'general',
71
71
  type: 'boolean',
72
72
  default: false,
@@ -6,7 +6,7 @@ const { fireHooks, hasHooks } = require('../hooks/hook-runner');
6
6
  const { buildReviewStartedPayload, buildReviewLoadedPayload, getCachedUser } = require('../hooks/payloads');
7
7
  const { STOPS } = require('../local-scope');
8
8
  const logger = require('../utils/logger');
9
- const { LOCAL_REVIEW_PATH_URL_ERROR, rejectUrlLikeLocalReviewPath } = require('../utils/local-path-input');
9
+ const { isLocalPathUrlError, rejectUrlLikeLocalReviewPath } = require('../utils/local-path-input');
10
10
  const path = require('path');
11
11
  const fs = require('fs').promises;
12
12
 
@@ -35,12 +35,14 @@ async function setupLocalReview({ db, targetPath, onProgress, config, flags = {}
35
35
  let resolvedPath;
36
36
  try {
37
37
  progress({ step: 'validate', status: 'running', message: 'Validating target path...' });
38
- rejectUrlLikeLocalReviewPath(targetPath);
38
+ rejectUrlLikeLocalReviewPath(targetPath, config);
39
39
  resolvedPath = path.resolve(targetPath);
40
40
  await fs.access(resolvedPath);
41
41
  progress({ step: 'validate', status: 'completed', message: `Path resolved to ${resolvedPath}` });
42
42
  } catch (err) {
43
- const message = err.message === LOCAL_REVIEW_PATH_URL_ERROR
43
+ // Branch on the error CODE, never the message: the URL error names the
44
+ // configured hosts, so its text varies per installation.
45
+ const message = isLocalPathUrlError(err)
44
46
  ? err.message
45
47
  : `Path does not exist: ${path.resolve(targetPath)}`;
46
48
  progress({ step: 'validate', status: 'error', message });
@@ -18,7 +18,7 @@ const { GitHubClient } = require('../github/client');
18
18
  const { normalizeRepository } = require('../utils/paths');
19
19
  const { findMainGitRoot } = require('../local-review');
20
20
  const { getConfigDir, getRepoPath, resolveRepoOptions, resolvePoolConfig, getRepoResetScript, resolveHostBinding, resolveBindingRepositoryFromPR, getRepoConfig, DEFAULT_CHECKOUT_TIMEOUT_MS } = require('../config');
21
- const { storedHostToOption, isDualHostRepoConfig } = require('../utils/host-resolution');
21
+ const { storedHostToOption, isDualHostRepoConfig, resolveRecordedHost, bindingRepositoryForHost } = require('../utils/host-resolution');
22
22
  const logger = require('../utils/logger');
23
23
  const { fireReviewStartedHook } = require('../hooks/payloads');
24
24
  const simpleGit = require('simple-git');
@@ -270,7 +270,49 @@ async function storePRData(db, prInfo, prData, diff, changedFiles, worktreePath,
270
270
  async function resolvePrHostBinding({ db, config, bindingRepository, owner, repo, prNumber, host, githubToken, deps = {} }) {
271
271
  const Client = deps.GitHubClient || GitHubClient;
272
272
  const repository = normalizeRepository(owner, repo);
273
- const repoConfig = getRepoConfig(config, bindingRepository);
273
+
274
+ // Apply host precedence FIRST, because the resolved host selects which config
275
+ // entry may be bound through: an exclusive alt entry that only
276
+ // `url_pattern`-claimed this owner/repo cannot serve a PR that lives on
277
+ // github.com. The caller's `bindingRepository` arrives already filtered
278
+ // against the host known at entry (the setup route and CLI both apply this
279
+ // rule), and that same key selects the repo's local configuration — path,
280
+ // checkout script, pool, reset script — as well as credentials. The local
281
+ // `hostBindingRepository` below re-applies the filter with the RECORDED host,
282
+ // which only this function resolves.
283
+ let effectiveHost;
284
+ let hostKnown = false;
285
+ let recordedHost;
286
+ if (host !== undefined) {
287
+ effectiveHost = host;
288
+ hostKnown = true;
289
+ recordedHost = host;
290
+ } else {
291
+ const prMetadataRepo = new PRMetadataRepository(db);
292
+ const recorded = await prMetadataRepo.getPRHostWithRecordedUrl(repository, prNumber);
293
+ if (recorded !== undefined) {
294
+ // resolveRecordedHost reads the stored host against the recorded html_url,
295
+ // which is what separates a pre-stamping row from a github.com one.
296
+ recordedHost = resolveRecordedHost(config, bindingRepository, recorded.host, recorded.recordedUrl);
297
+ // storedHostToOption applies the legacy-NULL convention: `undefined` means
298
+ // "host unknown" (leave hostKnown false → ambiguity/probe path), while a
299
+ // returned option object pins the host. It receives the RESOLVED host, not
300
+ // the raw column — a pre-stamping row whose recorded URL is on the alt host
301
+ // must fetch from there instead of being forced to github.com.
302
+ const storedOption = storedHostToOption(
303
+ config,
304
+ bindingRepositoryForHost(config, repository, bindingRepository, recordedHost),
305
+ recordedHost
306
+ );
307
+ if (storedOption !== undefined) {
308
+ effectiveHost = storedOption.host;
309
+ hostKnown = true;
310
+ }
311
+ }
312
+ }
313
+
314
+ const hostBindingRepository = bindingRepositoryForHost(config, repository, bindingRepository, recordedHost);
315
+ const repoConfig = getRepoConfig(config, hostBindingRepository);
274
316
  const configuredApiHost = (repoConfig && typeof repoConfig.api_host === 'string' && repoConfig.api_host)
275
317
  ? repoConfig.api_host
276
318
  : null;
@@ -289,34 +331,15 @@ async function resolvePrHostBinding({ db, config, bindingRepository, owner, repo
289
331
  if (binding.token) return binding;
290
332
  if (binding.apiHost === null) return githubToken;
291
333
  throw new Error(
292
- `No token configured for alt host ${binding.apiHost} (repo ${bindingRepository}). ` +
293
- `Configure repos["${bindingRepository}"].token or token_command.`
334
+ `No token configured for alt host ${binding.apiHost} (repo ${hostBindingRepository}). ` +
335
+ `Configure repos["${hostBindingRepository}"].token or token_command.`
294
336
  );
295
337
  };
296
338
 
297
- // Apply host precedence to decide whether we know the host up front.
298
- let effectiveHost;
299
- let hostKnown = false;
300
- if (host !== undefined) {
301
- effectiveHost = host;
302
- hostKnown = true;
303
- } else {
304
- const prMetadataRepo = new PRMetadataRepository(db);
305
- const storedHost = await prMetadataRepo.getPRHost(repository, prNumber);
306
- // storedHostToOption applies the legacy-NULL convention: `undefined` means
307
- // "host unknown" (leave hostKnown false → ambiguity/probe path), while a
308
- // returned option object pins the host.
309
- const storedOption = storedHostToOption(config, bindingRepository, storedHost);
310
- if (storedOption !== undefined) {
311
- effectiveHost = storedOption.host;
312
- hostKnown = true;
313
- }
314
- }
315
-
316
339
  // Fixed-binding path: host is known, OR the repo can only live on one host
317
340
  // (plain github / exclusive alt) so the ambiguity rule is unambiguous.
318
341
  if (hostKnown || !isDual) {
319
- const binding = resolveHostBinding(bindingRepository, config, hostKnown ? { host: effectiveHost } : {});
342
+ const binding = resolveHostBinding(hostBindingRepository, config, hostKnown ? { host: effectiveHost } : {});
320
343
  const client = new Client(clientArgFor(binding));
321
344
  const repoExists = await client.repositoryExists(owner, repo);
322
345
  if (!repoExists) {
@@ -329,7 +352,7 @@ async function resolvePrHostBinding({ db, config, bindingRepository, owner, repo
329
352
  // Probe path: dual repo, host unknown. Try the alt host first. `clientArgFor`
330
353
  // errors clearly if the alt binding has no token rather than silently probing
331
354
  // github.com disguised as the alt host.
332
- const altBinding = resolveHostBinding(bindingRepository, config, { host: configuredApiHost });
355
+ const altBinding = resolveHostBinding(hostBindingRepository, config, { host: configuredApiHost });
333
356
  const altClient = new Client(clientArgFor(altBinding));
334
357
  try {
335
358
  const prData = await altClient.fetchPullRequest(owner, repo, prNumber);
@@ -338,7 +361,7 @@ async function resolvePrHostBinding({ db, config, bindingRepository, owner, repo
338
361
  } catch (altErr) {
339
362
  if (altErr && altErr.status === 404) {
340
363
  logger.info(`PR #${prNumber} (${repository}) not found on alt host ${configuredApiHost}; falling back to github.com`);
341
- const githubBinding = resolveHostBinding(bindingRepository, config, { host: null });
364
+ const githubBinding = resolveHostBinding(hostBindingRepository, config, { host: null });
342
365
  const githubClient = new Client(clientArgFor(githubBinding));
343
366
  const prData = await githubClient.fetchPullRequest(owner, repo, prNumber);
344
367
  return { binding: githubBinding, prData, githubClient };