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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,200 @@
1
+ // Copyright 2026 Tim Perkins (tjwp) | SPDX-License-Identifier: Apache-2.0
2
+ /**
3
+ * Known PR Host Names
4
+ *
5
+ * Derives the list of code hosts pair-review will accept a pull request from,
6
+ * for use in copy that is rendered BEFORE any repository has been resolved —
7
+ * the landing-page PR input, the URL validation errors, and the
8
+ * "that's a URL, not a path" local-review error.
9
+ *
10
+ * `resolveHostName()` in ./repo-links.js answers the same question for a
11
+ * KNOWN repo. This module answers it for the whole configuration, which is
12
+ * what the pre-resolution surfaces need: at the point where a user is typing
13
+ * a URL there is no repo to look up yet.
14
+ *
15
+ * The list is derived, never hardcoded:
16
+ *
17
+ * - "GitHub" is always present. Unconfigured repos fall back to github.com
18
+ * with the top-level credentials, so github.com is always reachable.
19
+ * - "Graphite" appears only when `enable_graphite` is true. It defaults to
20
+ * false, so a default install must not advertise it.
21
+ * - Each distinct `repos[*].links.external.name` for a repo that also sets
22
+ * `api_host` — the alt-host display name (e.g. "Meteorite").
23
+ *
24
+ * Alt-host repos with no `links.external.name` resolve to "GitHub" via
25
+ * `resolveHostName` and are therefore de-duplicated away rather than
26
+ * appearing twice.
27
+ */
28
+
29
+ const { resolveHostName } = require('./repo-links');
30
+
31
+ const DEFAULT_HOST_NAME = 'GitHub';
32
+ const GRAPHITE_HOST_NAME = 'Graphite';
33
+
34
+ // Hostnames whose PR URLs are recognised even without a scheme. Alt hosts are
35
+ // appended from config by resolveUrlLikeHostnames().
36
+ const BUILTIN_PR_HOSTNAMES = Object.freeze([
37
+ 'github.com',
38
+ 'app.graphite.dev',
39
+ 'app.graphite.com'
40
+ ]);
41
+
42
+ /**
43
+ * Iterate every configured repo entry.
44
+ *
45
+ * `loadConfig()` lowercases the legacy `monorepos` map, merges it into `repos`,
46
+ * and deletes it, so for any loaded config that branch never fires — it is here
47
+ * only for raw/hand-built configs, mirroring `getRepoConfig`'s equivalent
48
+ * fallback.
49
+ *
50
+ * @param {Object} config
51
+ * @returns {Array<[string, Object]>} `[repoKey, repoEntry]` pairs
52
+ */
53
+ function configuredRepoEntries(config) {
54
+ const entries = [];
55
+ for (const section of [config.repos, config.monorepos]) {
56
+ if (!section || typeof section !== 'object') continue;
57
+ for (const [repoKey, repoEntry] of Object.entries(section)) {
58
+ if (!repoEntry || typeof repoEntry !== 'object') continue;
59
+ entries.push([repoKey, repoEntry]);
60
+ }
61
+ }
62
+ return entries;
63
+ }
64
+
65
+ /**
66
+ * True when a repo entry declares an alt host.
67
+ *
68
+ * @param {Object} repoEntry
69
+ * @returns {boolean}
70
+ */
71
+ function hasApiHost(repoEntry) {
72
+ return typeof repoEntry.api_host === 'string' && repoEntry.api_host.length > 0;
73
+ }
74
+
75
+ /**
76
+ * Resolve the ordered, de-duplicated list of host display names that
77
+ * pair-review can accept PR URLs for.
78
+ *
79
+ * @param {Object} [config] - Configuration object from loadConfig()
80
+ * @returns {string[]} Non-empty list, always starting with "GitHub"
81
+ */
82
+ function resolveKnownHostNames(config) {
83
+ const safeConfig = (config && typeof config === 'object') ? config : {};
84
+
85
+ const names = [DEFAULT_HOST_NAME];
86
+ if (safeConfig.enable_graphite === true) names.push(GRAPHITE_HOST_NAME);
87
+
88
+ const seen = new Set(names.map(name => name.toLowerCase()));
89
+
90
+ for (const [repoKey, repoEntry] of configuredRepoEntries(safeConfig)) {
91
+ if (!hasApiHost(repoEntry)) continue;
92
+ // Route through resolveHostName so the global list agrees with the
93
+ // per-repo name used in the submit toast and draft notices — including
94
+ // its validation (a `name` without a usable `label`/`url_template` pair
95
+ // does not register as an external link, and so does not appear here).
96
+ const name = resolveHostName(safeConfig, repoKey);
97
+ const dedupeKey = name.toLowerCase();
98
+ if (seen.has(dedupeKey)) continue;
99
+ seen.add(dedupeKey);
100
+ names.push(name);
101
+ }
102
+
103
+ return names;
104
+ }
105
+
106
+ /**
107
+ * Join host names into a user-facing fragment with an Oxford comma:
108
+ * "GitHub", "GitHub or Graphite", "GitHub, Graphite, or Meteorite".
109
+ *
110
+ * @param {string[]} names
111
+ * @returns {string}
112
+ */
113
+ function formatHostList(names) {
114
+ const list = Array.isArray(names) ? names.filter(name => typeof name === 'string' && name) : [];
115
+ if (list.length === 0) return DEFAULT_HOST_NAME;
116
+ if (list.length === 1) return list[0];
117
+ if (list.length === 2) return `${list[0]} or ${list[1]}`;
118
+ return `${list.slice(0, -1).join(', ')}, or ${list[list.length - 1]}`;
119
+ }
120
+
121
+ /**
122
+ * Convenience wrapper: the formatted host fragment for a config.
123
+ *
124
+ * @param {Object} [config]
125
+ * @returns {string}
126
+ */
127
+ function resolveHostListText(config) {
128
+ return formatHostList(resolveKnownHostNames(config));
129
+ }
130
+
131
+ /**
132
+ * Hostnames (lowercased) that belong to configured alt hosts, recorded both
133
+ * with and without an explicit port so either shape of paste is recognised.
134
+ *
135
+ * Derived from each alt-host repo's `api_host` and, when present, the web
136
+ * host in `links.external.url_template` — the API host and the web host are
137
+ * frequently different domains, and a user pastes the latter.
138
+ *
139
+ * @param {Object} [config]
140
+ * @returns {string[]}
141
+ */
142
+ function resolveAltHostHostnames(config) {
143
+ const safeConfig = (config && typeof config === 'object') ? config : {};
144
+ const hostnames = new Set();
145
+
146
+ const add = (value) => {
147
+ if (typeof value !== 'string' || !value) return;
148
+ // `api_host` is only validated as a non-empty string, so a bare
149
+ // `ghe.example.com` is a legitimate configuration — give it a scheme so
150
+ // `new URL()` can parse it rather than throwing into the catch below.
151
+ const absolute = /^[a-z][a-z0-9+.-]*:\/\//i.test(value) ? value : `https://${value}`;
152
+ let url;
153
+ try {
154
+ url = new URL(absolute);
155
+ } catch {
156
+ // Not parseable even with a scheme — nothing to derive.
157
+ return;
158
+ }
159
+ // A template can carry a placeholder in its authority section
160
+ // (`https://{owner}.example/…` parses, yielding hostname `{owner}.example`);
161
+ // no pasted input can start with that, so drop it rather than ship junk.
162
+ if (!url.hostname || url.hostname.includes('{')) return;
163
+ // `host` keeps a non-default port — what a user actually pastes for
164
+ // `https://ghe.example.com:8443/…`; `hostname` drops it.
165
+ hostnames.add(url.host.toLowerCase());
166
+ hostnames.add(url.hostname.toLowerCase());
167
+ };
168
+
169
+ for (const [, repoEntry] of configuredRepoEntries(safeConfig)) {
170
+ if (!hasApiHost(repoEntry)) continue;
171
+ add(repoEntry.api_host);
172
+ add(repoEntry.links?.external?.url_template);
173
+ }
174
+
175
+ return Array.from(hostnames);
176
+ }
177
+
178
+ /**
179
+ * Every hostname whose PR URLs should be recognised without a scheme —
180
+ * the built-ins plus every configured alt host. De-duplicated, lowercased.
181
+ *
182
+ * @param {Object} [config]
183
+ * @returns {string[]}
184
+ */
185
+ function resolveUrlLikeHostnames(config) {
186
+ const seen = new Set(BUILTIN_PR_HOSTNAMES);
187
+ for (const hostname of resolveAltHostHostnames(config)) seen.add(hostname);
188
+ return Array.from(seen);
189
+ }
190
+
191
+ module.exports = {
192
+ DEFAULT_HOST_NAME,
193
+ GRAPHITE_HOST_NAME,
194
+ BUILTIN_PR_HOSTNAMES,
195
+ resolveKnownHostNames,
196
+ formatHostList,
197
+ resolveHostListText,
198
+ resolveAltHostHostnames,
199
+ resolveUrlLikeHostnames,
200
+ };
@@ -1018,7 +1018,13 @@ async function handleLocalReview(targetPath, flags = {}) {
1018
1018
  let setupComplete = false;
1019
1019
 
1020
1020
  try {
1021
- rejectUrlLikeLocalReviewPath(targetPath);
1021
+ // Loaded before path validation so the "that's a URL" error can name the
1022
+ // configured hosts (GitHub, Graphite, alt hosts) and so scheme-less
1023
+ // alt-host URLs are recognised. The first-run welcome still waits until
1024
+ // the path has been validated.
1025
+ const { config, isFirstRun } = await loadConfig();
1026
+
1027
+ rejectUrlLikeLocalReviewPath(targetPath, config);
1022
1028
 
1023
1029
  const resolvedPath = path.resolve(targetPath || process.cwd());
1024
1030
 
@@ -1032,8 +1038,6 @@ async function handleLocalReview(targetPath, flags = {}) {
1032
1038
  const repoPath = await module.exports.findGitRoot(resolvedPath);
1033
1039
  console.log(`Found git repository at: ${repoPath}`);
1034
1040
 
1035
- const { config, isFirstRun } = await loadConfig();
1036
-
1037
1041
  if (isFirstRun) {
1038
1042
  showWelcomeMessage();
1039
1043
  }
package/src/main.js CHANGED
@@ -242,7 +242,7 @@ OPTIONS:
242
242
  --model when the model belongs to a non-default
243
243
  provider (e.g. --provider codex --model gpt-5.5).
244
244
  Available: claude, antigravity, codex, copilot,
245
- opencode, cursor-agent, pi, muse
245
+ opencode, cursor-agent, pi, omp, muse
246
246
  --council <handle> Run analysis with a saved council (multi-voice). Handle is a
247
247
  council name, name-slug, or id (prefix). See --list-councils.
248
248
  --list-councils List saved councils (handles to use with --council) and exit
@@ -277,6 +277,7 @@ ENVIRONMENT VARIABLES:
277
277
  PAIR_REVIEW_CLAUDE_CMD Custom command to invoke Claude CLI (default: claude)
278
278
  PAIR_REVIEW_ANTIGRAVITY_CMD Custom command to invoke Antigravity CLI (default: agy)
279
279
  PAIR_REVIEW_CODEX_CMD Custom command to invoke Codex CLI (default: codex)
280
+ PAIR_REVIEW_OMP_CMD Custom command to invoke OMP (Oh My Pi) CLI (default: omp)
280
281
  PAIR_REVIEW_MUSE_CMD Custom command to invoke Muse Code CLI (default: muse)
281
282
 
282
283
  CONFIGURATION:
@@ -566,6 +567,12 @@ function parseArgs(args) {
566
567
  flags.local = true;
567
568
  // Next argument is optional path (if not starting with -)
568
569
  if (i + 1 < args.length && !args[i + 1].startsWith('-')) {
570
+ // parseArgs() is deliberately config-free — it is exported and
571
+ // unit-tested as a pure argv parser — so this catches only explicit
572
+ // `scheme://` inputs, with host-neutral copy. A scheme-less alt-host
573
+ // URL needs config and is caught by the re-check in main() right after
574
+ // loadConfig() (and again downstream by handleLocalReview /
575
+ // attemptDelegation / the local routes).
569
576
  rejectUrlLikeLocalReviewPath(args[i + 1]);
570
577
  flags.localPath = args[i + 1];
571
578
  i++; // Skip next argument since we consumed it
@@ -667,6 +674,7 @@ ENVIRONMENT VARIABLES:
667
674
  PAIR_REVIEW_CLAUDE_CMD Custom Claude CLI command (default: claude)
668
675
  PAIR_REVIEW_ANTIGRAVITY_CMD Custom Antigravity CLI command (default: agy)
669
676
  PAIR_REVIEW_CODEX_CMD Custom Codex CLI command (default: codex)
677
+ PAIR_REVIEW_OMP_CMD Custom OMP (Oh My Pi) CLI command (default: omp)
670
678
  PAIR_REVIEW_MUSE_CMD Custom Muse Code CLI command (default: muse)
671
679
  PAIR_REVIEW_DB_NAME Custom database filename (overrides config)
672
680
 
@@ -678,6 +686,7 @@ AI PROVIDERS:
678
686
  Claude (default): Requires 'claude' CLI installed
679
687
  Antigravity: Requires 'agy' CLI installed
680
688
  Codex: Requires 'codex' CLI installed
689
+ OMP: Requires 'omp' CLI installed
681
690
  Muse: Requires 'muse' CLI installed
682
691
 
683
692
  Select provider per-repository in the web UI settings.
@@ -739,6 +748,17 @@ AI PROVIDERS:
739
748
  // single-port delegation can skip DB entirely)
740
749
  const { prArgs, flags } = parseArgs(args);
741
750
 
751
+ // parseArgs() ran config-free, so it could only reject `scheme://` inputs.
752
+ // Re-check now that config is loaded: a configured alt host makes
753
+ // `ghe.example.com/owner/repo/pull/1` a URL too, and the message can name
754
+ // the hosts this install actually accepts. Several branches below resolve
755
+ // flags.localPath directly (the instruction handoff at the delegation
756
+ // check, handleHeadlessDelegated, the headless local path), so the
757
+ // invariant has to hold here rather than only in handleLocalReview().
758
+ if (flags.local && flags.localPath) {
759
+ rejectUrlLikeLocalReviewPath(flags.localPath, config);
760
+ }
761
+
742
762
  // Headless-mode flag validation (fail fast, before any DB/server work).
743
763
  // --instructions and --instructions-file are mutually exclusive.
744
764
  if (flags.instructions && flags.instructionsFile) {
@@ -22,6 +22,14 @@
22
22
  const { RepoSettingsRepository, CouncilRepository } = require('./database');
23
23
  const { resolveCouncilHandle } = require('./councils/resolve-council');
24
24
  const { normalizeCouncilConfig, validateCouncilConfig } = require('./routes/councils');
25
+ // Require the ./ai index (not ./ai/provider) so the provider registry is
26
+ // populated by the provider files' self-registration before lookups here.
27
+ const {
28
+ getProviderClass,
29
+ getProviderConfigOverrides,
30
+ applyModelOverrides,
31
+ resolveDefaultModel
32
+ } = require('./ai');
25
33
  const logger = require('./utils/logger');
26
34
 
27
35
  /**
@@ -52,7 +60,7 @@ function _buildCouncilSelection(council) {
52
60
  * Precedence (highest first), per the global-settings design ("specificity
53
61
  * first, then in-app > files"):
54
62
  * provider: explicit › repo default › global in-app override › config.default_provider › config.provider › 'claude'
55
- * model: explicit › repo default › global in-app override › config.default_model › config.model › 'opus'
63
+ * model: explicit › repo default › global in-app override › config.default_model › provider's own default › 'opus'
56
64
  *
57
65
  * The global in-app override (from the /settings page, carried on
58
66
  * `config._globalOverrides`) sits ABOVE the config files but BELOW the repo
@@ -78,7 +86,22 @@ function _buildCouncilSelection(council) {
78
86
  *
79
87
  * Each field falls through independently, so supplying only `explicit.model`
80
88
  * still resolves the provider from repo/override/config defaults (and vice
81
- * versa).
89
+ * versa) — BUT a tier's `default_model` is *intended* to pair with that
90
+ * tier's `default_provider`, so a tier's model is only consulted when its
91
+ * provider agrees with the resolved provider. Without that guard, a
92
+ * provider-only pick (`--provider omp`) walks the model ladder down to the
93
+ * global default and hands OMP a foreign model id like 'opus' instead of the
94
+ * provider's own default mode. A tier that names no provider is treated as
95
+ * provider-agnostic and still applies (e.g. a model-only in-app override).
96
+ * Note `cfg` is the FLATTENED effective config, not a single layer:
97
+ * loadConfig() merges DEFAULT_CONFIG and the config files, then
98
+ * buildEffectiveConfig() dot-path-writes in-app overrides into the same flat
99
+ * object, so `cfg.default_provider` and `cfg.default_model` may come from
100
+ * different layers — see the `cfgPairSuspect` guard below for the case where
101
+ * that incoherence is provable. When no compatible tier supplies a model,
102
+ * the provider's own default is used (mirroring what the settings UI derives
103
+ * via `models.find(m => m.default)`), with the global model as the last
104
+ * resort for providers with no built-in default (e.g. OpenCode).
82
105
  *
83
106
  * @param {Object} explicit - { provider, model } (either may be undefined)
84
107
  * @param {Object|null} repoSettings - Row from RepoSettingsRepository.getRepoSettings
@@ -95,15 +118,67 @@ function _buildSingleSelection(explicit, repoSettings, config) {
95
118
  || cfg.default_provider
96
119
  || cfg.provider
97
120
  || 'claude';
121
+
122
+ // A tier's model applies only when that tier's provider matches the
123
+ // resolved provider (or the tier names no provider at all).
124
+ const tierModel = (tierProvider, model) =>
125
+ ((!tierProvider || tierProvider === provider) ? model : null);
126
+
127
+ // A provider-only in-app override proves the flattened `cfg` pair is
128
+ // incoherent: buildEffectiveConfig() wrote the new provider into `cfg` via
129
+ // setPath() but left the config-file/default model beneath it. In that
130
+ // case `cfg`'s provider matches the resolved provider by construction, so
131
+ // the tier guard cannot catch the mismatch — skip the `cfg` tier entirely
132
+ // and let the provider's own default supply the model. (A config FILE that
133
+ // sets only default_provider over DEFAULT_CONFIG's model has the same
134
+ // incoherence but is not detectable here; tracked separately.)
135
+ const cfgPairSuspect = Boolean(overrides.default_provider && !overrides.default_model);
136
+
137
+ // An explicit --model passes through verbatim: Pi/OMP fuzzy-match arbitrary
138
+ // ids ('opus', 'gpt-5.2') that are deliberately not in their model list, so
139
+ // it must never be second-guessed against the provider's models. The
140
+ // hardcoded 'claude'/'opus' pair sits BELOW the override-aware provider
141
+ // default as a last-resort rescue (e.g. no provider class registered for
142
+ // 'claude'), so a configured `providers.claude.default_model` or a
143
+ // disabled 'opus' is honored on the provider-default rung first.
98
144
  const model = explicit.model
99
- || repoSettings?.default_model
100
- || overrides.default_model
145
+ || tierModel(repoSettings?.default_provider, repoSettings?.default_model)
146
+ || tierModel(overrides.default_provider, overrides.default_model)
147
+ || (cfgPairSuspect ? null : tierModel(cfg.default_provider || cfg.provider, cfg.default_model || cfg.model))
148
+ || _resolveProviderDefaultModel(provider)
149
+ || tierModel('claude', 'opus')
101
150
  || cfg.default_model
102
151
  || cfg.model
103
152
  || 'opus';
104
153
  return { type: 'single', provider, model };
105
154
  }
106
155
 
156
+ /**
157
+ * Resolve a provider's own default model, honoring config overrides
158
+ * (`providers.<id>.models` / `default_model` / `disabled_models`) exactly the
159
+ * way `createProvider` does when handed a null model — so a provider-only
160
+ * selection lands on the same model the settings UI shows as that provider's
161
+ * default. Returns null for unknown providers and for providers with no
162
+ * default (e.g. OpenCode), letting the caller fall back to the global model.
163
+ *
164
+ * @param {string} providerId - Provider ID
165
+ * @returns {string|null} Default model id, or null
166
+ * @private
167
+ */
168
+ function _resolveProviderDefaultModel(providerId) {
169
+ const ProviderClass = getProviderClass(providerId);
170
+ if (!ProviderClass) return null;
171
+ try {
172
+ const overrides = getProviderConfigOverrides(providerId);
173
+ const effectiveModels = applyModelOverrides(ProviderClass.getModels(), overrides);
174
+ return resolveDefaultModel(effectiveModels, overrides?.default_model)
175
+ || ProviderClass.getDefaultModel();
176
+ } catch (error) {
177
+ logger.warn(`Could not resolve default model for provider "${providerId}": ${error.message}`);
178
+ return null;
179
+ }
180
+ }
181
+
107
182
  /**
108
183
  * Resolve the review configuration (council vs single provider/model) for a run.
109
184
  *
@@ -124,7 +199,8 @@ function _buildSingleSelection(explicit, repoSettings, config) {
124
199
  * single provider/model default.
125
200
  * 5. `repo_settings.default_provider` / `default_model`, then global in-app
126
201
  * override (`config._globalOverrides`) › global `config` defaults — single
127
- * selection (final hardcoded fallbacks 'claude' / 'opus').
202
+ * selection. The final fallback provider is 'claude' with that provider's
203
+ * own default model; 'opus' remains the hardcoded last-resort model floor.
128
204
  *
129
205
  * @param {Object} db - Database instance.
130
206
  * @param {string} repository - Repository in `owner/repo` form (may be null/undefined
@@ -34,6 +34,7 @@ const {
34
34
  getTourAutoGenerate
35
35
  } = require('../config');
36
36
  const { resolveRepoLinks } = require('../links/repo-links');
37
+ const { resolveKnownHostNames, formatHostList, resolveUrlLikeHostnames } = require('../links/host-names');
37
38
  const { version } = require('../../package.json');
38
39
  const semver = require('semver');
39
40
  const { getAllChatProviders, getAllCachedChatAvailability } = require('../chat/chat-providers');
@@ -158,6 +159,8 @@ router.get('/api/config', (req, res) => {
158
159
  hasRepoGithubToken = Boolean(resolvePreflightBinding(repository, config, undefined).token);
159
160
  }
160
161
 
162
+ const hostNames = resolveKnownHostNames(config);
163
+
161
164
  // Only return safe configuration values (not secrets like github_token)
162
165
  res.json({
163
166
  version,
@@ -190,6 +193,19 @@ router.get('/api/config', (req, res) => {
190
193
  pi_available: getCachedAvailability('pi')?.available || false,
191
194
  assisted_by_url: config.assisted_by_url || 'https://github.com/in-the-loop-labs/pair-review',
192
195
  enable_graphite: config.enable_graphite === true,
196
+ // Code hosts pair-review accepts PR URLs from, derived from config
197
+ // (GitHub always; Graphite only when enabled; each alt host's
198
+ // `links.external.name`). Drives the landing-page placeholder, the help
199
+ // copy, and the client-side URL validation errors — surfaces that render
200
+ // before any repo is resolved and so cannot use resolveHostName().
201
+ // Both shapes are shipped so the Oxford-comma formatting has exactly one
202
+ // implementation (server-side) and cannot drift from the server's own copy.
203
+ pr_host_names: hostNames,
204
+ pr_host_list: formatHostList(hostNames),
205
+ // Hostnames the local-path input should recognise as scheme-less PR URLs
206
+ // (github.com, Graphite, and every configured alt host's API and web
207
+ // domains), so the client pre-flight matches the server's own check.
208
+ pr_url_hostnames: resolveUrlLikeHostnames(config),
193
209
  external_comments: config.external_comments !== false,
194
210
  chat_spinner: config.chat_spinner || 'dots',
195
211
  summaries: {
@@ -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
@@ -29,6 +29,7 @@ const path = require('path');
29
29
  const { resolveHostBinding, resolveBindingRepositoryFromPR, getWorktreeDisplayName, resolveLoadSkills, buildCouncilProviderOverrides, getSummaryEnabled, getTourEnabled } = require('../config');
30
30
  const { storedHostToOption, isDualHostRepo } = 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');
@@ -1992,7 +1993,7 @@ router.post('/api/parse-pr-url', (req, res) => {
1992
1993
  }
1993
1994
 
1994
1995
  return res.status(400).json({
1995
- error: 'Invalid PR URL. Please enter a GitHub or Graphite PR URL.',
1996
+ error: `Invalid PR URL. Please enter a ${resolveHostListText(config)} PR URL.`,
1996
1997
  valid: false
1997
1998
  });
1998
1999
  });
@@ -271,7 +271,7 @@ router.post('/api/setup/local', async (req, res) => {
271
271
  }
272
272
 
273
273
  try {
274
- rejectUrlLikeLocalReviewPath(rawPath);
274
+ rejectUrlLikeLocalReviewPath(rawPath, req.app.get('config'));
275
275
  } catch (err) {
276
276
  return res.status(400).json({ error: err.message });
277
277
  }
@@ -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 });
@@ -327,7 +327,7 @@ async function attemptDelegation(config, flags, prArgs, _deps, options = {}) {
327
327
  // analyze=true (and analysisConfigId supersedes both when present).
328
328
  let url;
329
329
  if (flags.local) {
330
- rejectUrlLikeLocalReviewPath(flags.localPath);
330
+ rejectUrlLikeLocalReviewPath(flags.localPath, config);
331
331
  const targetPath = path.resolve(flags.localPath || process.cwd());
332
332
  const analysisConfigId = await handoffAnalysisConfigId(options.localRepository || null);
333
333
  url = buildDelegationUrl(port, 'local', {
@@ -1,23 +1,62 @@
1
1
  // Copyright 2026 Tim Perkins (tjwp) | SPDX-License-Identifier: Apache-2.0
2
2
 
3
- 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.';
3
+ const { resolveHostListText, resolveUrlLikeHostnames } = require('../links/host-names');
4
+
5
+ /**
6
+ * Error code stamped on the "you passed a URL, not a path" error.
7
+ *
8
+ * Callers MUST branch on this rather than comparing the message text — the
9
+ * message names the configured hosts and therefore varies per installation.
10
+ */
11
+ const LOCAL_PATH_IS_URL_CODE = 'LOCAL_PATH_IS_URL';
12
+
13
+ /**
14
+ * Build the user-facing message for a local-review path that is really a URL.
15
+ *
16
+ * Without a config the message stays host-neutral. Falling back to the
17
+ * built-in list would name GitHub alone, which actively misinforms: on an
18
+ * install with `enable_graphite` or an alt host, those URLs ARE accepted as PR
19
+ * review inputs.
20
+ *
21
+ * @param {Object} [config] - Configuration object from loadConfig()
22
+ * @returns {string}
23
+ */
24
+ function localReviewPathUrlError(config) {
25
+ const hostClause = (config && typeof config === 'object')
26
+ ? `${resolveHostListText(config)} URLs`
27
+ : 'PR URLs';
28
+ return 'Local reviews require a filesystem path, not a URL. '
29
+ + `Pass ${hostClause} as PR review inputs instead.`;
30
+ }
4
31
 
5
32
  /**
6
33
  * Detect inputs that are URLs or remote-style Git URLs rather than filesystem paths.
7
34
  * This intentionally checks only unambiguous URL forms so normal absolute,
8
35
  * relative, tilde, and Windows paths continue to work.
9
36
  *
37
+ * Scheme-less PR URLs are recognised for github.com, Graphite, and every
38
+ * configured alt host (both its `api_host` and its `links.external`
39
+ * web host, which are frequently different domains).
40
+ *
10
41
  * @param {unknown} input
42
+ * @param {Object} [config] - Configuration object; without it only the
43
+ * built-in hosts are recognised scheme-less.
11
44
  * @returns {boolean}
12
45
  */
13
- function isUrlLikeLocalReviewPath(input) {
46
+ function isUrlLikeLocalReviewPath(input, config) {
14
47
  if (typeof input !== 'string') return false;
15
48
 
16
49
  const value = input.trim();
17
50
  if (!value) return false;
18
51
 
19
52
  if (/^[a-z][a-z0-9+.-]*:\/\//i.test(value)) return true;
20
- if (/^(?:github\.com|app\.graphite\.(?:dev|com))\//i.test(value)) return true;
53
+
54
+ const hostnames = resolveUrlLikeHostnames(config);
55
+ const lower = value.toLowerCase();
56
+ // Require a path separator so a bare hostname-shaped directory name is not
57
+ // mistaken for a URL, matching the previous built-in behaviour.
58
+ if (hostnames.some(hostname => lower.startsWith(`${hostname}/`))) return true;
59
+
21
60
  // Treat only a leading user@host:path token as SSH remote syntax; if a
22
61
  // directory prefix contains @ and : it should remain a filesystem path.
23
62
  if (/^[^@/\\\s]+@[^:/\\\s]+:[^\s]+$/.test(value)) return true;
@@ -28,17 +67,34 @@ function isUrlLikeLocalReviewPath(input) {
28
67
  /**
29
68
  * Throw a user-facing error when a local review path is actually a URL.
30
69
  *
70
+ * The thrown error carries `code === LOCAL_PATH_IS_URL_CODE`.
71
+ *
31
72
  * @param {unknown} input
73
+ * @param {Object} [config] - Configuration object from loadConfig()
32
74
  * @throws {Error}
33
75
  */
34
- function rejectUrlLikeLocalReviewPath(input) {
35
- if (isUrlLikeLocalReviewPath(input)) {
36
- throw new Error(LOCAL_REVIEW_PATH_URL_ERROR);
76
+ function rejectUrlLikeLocalReviewPath(input, config) {
77
+ if (isUrlLikeLocalReviewPath(input, config)) {
78
+ const error = new Error(localReviewPathUrlError(config));
79
+ error.code = LOCAL_PATH_IS_URL_CODE;
80
+ throw error;
37
81
  }
38
82
  }
39
83
 
84
+ /**
85
+ * True when an error came from rejectUrlLikeLocalReviewPath().
86
+ *
87
+ * @param {unknown} error
88
+ * @returns {boolean}
89
+ */
90
+ function isLocalPathUrlError(error) {
91
+ return Boolean(error) && error.code === LOCAL_PATH_IS_URL_CODE;
92
+ }
93
+
40
94
  module.exports = {
41
- LOCAL_REVIEW_PATH_URL_ERROR,
95
+ LOCAL_PATH_IS_URL_CODE,
96
+ localReviewPathUrlError,
42
97
  isUrlLikeLocalReviewPath,
43
- rejectUrlLikeLocalReviewPath
98
+ rejectUrlLikeLocalReviewPath,
99
+ isLocalPathUrlError
44
100
  };