@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
@@ -6,7 +6,7 @@ const { PRArgumentParser } = require('./github/parser');
6
6
  const logger = require('./utils/logger');
7
7
  const { rejectUrlLikeLocalReviewPath } = require('./utils/local-path-input');
8
8
  const { normalizeRepository } = require('./utils/paths');
9
- const { isDualHostRepo, hostSetupParamValue } = require('./utils/host-resolution');
9
+ const { setupHostParam } = require('./utils/host-resolution');
10
10
  const { buildInteractiveAnalysisConfig } = require('./interactive-analysis-config');
11
11
  const { version: packageVersion } = require('../package.json');
12
12
 
@@ -172,7 +172,7 @@ function storeAnalysisConfigRemote(port, analysisConfig, _deps) {
172
172
  * mirroring the cold-start precedence in handlePullRequest/handleLocalReview.
173
173
  * @param {string} [context.host] - Setup `?host=` value (alt api_host string or the
174
174
  * 'github' sentinel) so a pasted alt URL binds directly instead of re-probing.
175
- * Already resolved by the caller via `hostSetupParamValue`; omitted when null.
175
+ * Already resolved by the caller via `setupHostParam`; omitted when null.
176
176
  * @param {string} [context.provider] - CLI provider override to carry to the running server
177
177
  * @param {string} [context.model] - CLI model override to carry to the running server
178
178
  * @param {string} [context.scope] - Local-mode only: the `--scope` range to carry
@@ -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', {
@@ -340,10 +340,10 @@ async function attemptDelegation(config, flags, prArgs, _deps, options = {}) {
340
340
  const repository = normalizeRepository(prInfo.owner, prInfo.repo);
341
341
  const analysisConfigId = await handoffAnalysisConfigId(repository);
342
342
  // Thread the parsed host so a pasted alt URL binds directly (no re-probe) —
343
- // same mapping as the cold-start handlePullRequest path. bindingRepository
344
- // (from a url_pattern match) is the config key that determines dual-ness.
345
- const bindingRepository = prInfo.bindingRepository || repository;
346
- const host = hostSetupParamValue(prInfo.host, isDualHostRepo(config, bindingRepository));
343
+ // same mapping as the cold-start handlePullRequest path. See setupHostParam:
344
+ // a github.com URL announces itself whenever an api_host entry could
345
+ // otherwise claim this repo, so setup never falls back to the alt host.
346
+ const host = setupHostParam(config, prInfo.owner, prInfo.repo, prInfo.host);
347
347
  url = buildDelegationUrl(port, 'pr', {
348
348
  ...prInfo, analyze, councilId, analysisConfigId, host,
349
349
  provider: flags.provider, model: flags.model
@@ -9,7 +9,8 @@
9
9
  * here stops the copies from drifting.
10
10
  */
11
11
 
12
- const { getRepoConfig, isExclusiveAltHost, resolveHostBinding } = require('../config');
12
+ const { getRepoConfig, isExclusiveAltHost, resolveHostBinding, resolveBindingRepositoryFromPR } = require('../config');
13
+ const logger = require('./logger');
13
14
 
14
15
  /**
15
16
  * Translate a stored `pr_metadata.host` value into the `options` object for
@@ -38,6 +39,176 @@ function storedHostToOption(config, bindingRepository, storedHost) {
38
39
  return { host: storedHost };
39
40
  }
40
41
 
42
+ /**
43
+ * Normalise an EXPLICIT host hint (a setup request body, a `?host=` sentinel, a
44
+ * pasted URL's parsed host) against config. The explicit-hint sibling of
45
+ * {@link storedHostToOption}:
46
+ *
47
+ * - `undefined` → `undefined` (no hint; the ambiguity rule applies).
48
+ * - a URL string → unchanged; `resolveHostBinding` validates it against the
49
+ * repo's `api_host` and reports a mismatch.
50
+ * - `null` (github.com) on a plain or dual repo → `null`.
51
+ * - `null` on an EXCLUSIVE alt-host repo → `undefined` + a warning. The repo
52
+ * config asserts there is no github.com presence (`exclusive` defaults to
53
+ * true whenever `api_host` is set), so the hint contradicts configuration.
54
+ * Ignoring it matches `applyHostQueryCorrection` in `src/server.js`, which
55
+ * warns and ignores the same sentinel rather than acting on it, and keeps
56
+ * `resolveHostBinding`'s exclusive-null guard unreachable from user input —
57
+ * a clickable dashboard row must never 500 on a config contradiction.
58
+ *
59
+ * @param {Object} config - Application config
60
+ * @param {string} bindingRepository - `repos[...]` config-lookup key
61
+ * @param {string|null|undefined} host - The explicit hint
62
+ * @returns {string|null|undefined} The host to bind with
63
+ */
64
+ function explicitHostForBinding(config, bindingRepository, host) {
65
+ if (host !== null) return host;
66
+ if (!isExclusiveAltHost(getRepoConfig(config, bindingRepository))) return null;
67
+ logger.warn(
68
+ `Ignoring github.com host hint for "${bindingRepository}": it is configured as an ` +
69
+ 'exclusive alt-host repo (api_host without "exclusive": false), so it has no github.com ' +
70
+ 'binding. Set "exclusive": false on that repo if its PRs can live on github.com too.'
71
+ );
72
+ return undefined;
73
+ }
74
+
75
+ /**
76
+ * Resolve the host a RECORDED PR lives on, from its stored `host` column plus
77
+ * its recorded `html_url`.
78
+ *
79
+ * Mirrors the convention {@link storedHostToOption} encodes, which already says
80
+ * which stored NULLs are ambiguous: dual-host support shipped WITH host stamping
81
+ * (schema v50), so a NULL on a dual or plain repo means github.com. What a NULL
82
+ * cannot tell us is whether an older row predates stamping — and the recorded
83
+ * `html_url` settles that in ONE direction, since a URL that is not on
84
+ * github.com cannot be a github.com PR:
85
+ *
86
+ * - a URL string → that host (already stamped; nothing to infer).
87
+ * - NULL on a repo with no `api_host` → `null`; there is no other host.
88
+ * - NULL with a non-github `html_url` → the configured `api_host`. This is the
89
+ * pre-stamping row (or a repo that was exclusive-alt before gaining
90
+ * `exclusive: false`), so github.com would be wrong.
91
+ * - NULL otherwise → `null` (github.com), per the convention above.
92
+ * - `undefined` (no row) → `undefined`.
93
+ *
94
+ * One resolver serves links, navigation, AND binding on purpose: a row that
95
+ * renders a github.com icon must bind github.com when clicked, and the only way
96
+ * to guarantee that is to derive every one of them from the same value.
97
+ *
98
+ * @param {Object} config - Application config
99
+ * @param {string} bindingRepository - `repos[...]` config-lookup key
100
+ * @param {string|null|undefined} storedHost - Value from the `host` column
101
+ * @param {string|null|undefined} recordedUrl - The PR's stored `html_url`
102
+ * @returns {string|null|undefined} The host this PR is recorded on
103
+ */
104
+ function resolveRecordedHost(config, bindingRepository, storedHost, recordedUrl) {
105
+ if (storedHost !== null) return storedHost;
106
+ const apiHost = getConfiguredApiHost(config, bindingRepository);
107
+ if (!apiHost) return null;
108
+ if (typeof recordedUrl !== 'string' || !recordedUrl) return null;
109
+ let hostname;
110
+ try {
111
+ hostname = new URL(recordedUrl).hostname.toLowerCase();
112
+ } catch {
113
+ return null;
114
+ }
115
+ return (hostname === 'github.com' || hostname.endsWith('.github.com')) ? null : apiHost;
116
+ }
117
+
118
+ /**
119
+ * Resolve the `repos[...]` config key for a PR whose host is KNOWN.
120
+ *
121
+ * `resolveBindingRepositoryFromPR` answers "which entry serves this
122
+ * owner/repo?" with no host context: its slow path probes each entry's
123
+ * `url_pattern` against a URL built from that entry's OWN `api_host`, so a
124
+ * correctly anchored monorepo-style pattern claims EVERY owner/repo — including
125
+ * repos that exist only on github.com.
126
+ *
127
+ * `PRArgumentParser.parsePRUrl` already refuses the same overreach in the URL
128
+ * dimension (see its INVARIANT: "an `api_host`-bearing `url_pattern` must NEVER
129
+ * bind a canonical github.com / Graphite URL"), discarding the match so a
130
+ * pasted github.com URL resolves to its own `owner/repo`. This applies that
131
+ * settled rule to the owner/repo dimension, for the one case that can be
132
+ * decided safely:
133
+ *
134
+ * - `host` unknown or an alt-host string → the matched key, unchanged.
135
+ * - `host === null` (github.com) and the entry was claimed by its
136
+ * `url_pattern` probe (its key is not this PR's identity) and it is an
137
+ * EXCLUSIVE alt-host entry → the PR's own `owner/repo`. Such an entry has
138
+ * no github.com presence, so it describes neither this PR's API host nor
139
+ * its checkout.
140
+ * - a DUAL entry is kept for either host: `resolveHostBinding` has a
141
+ * first-class github.com binding for dual repos, so the entry does serve
142
+ * this PR (and its path/pool/reset config still applies).
143
+ * - a directly-keyed exclusive entry is kept: there the configuration itself
144
+ * asserts this exact repo is alt-host-only, and config wins over inference.
145
+ *
146
+ * Two entry points share the rule: this one resolves the key itself, while
147
+ * {@link bindingRepositoryForHost} filters a key a caller already holds (from a
148
+ * `url_pattern` parse, say) without re-deriving it.
149
+ *
150
+ * @param {string} owner
151
+ * @param {string} repo
152
+ * @param {Object} config
153
+ * @param {string|null|undefined} host
154
+ * @returns {string} The `repos[...]` config-lookup key
155
+ */
156
+ function resolveBindingRepositoryForHost(owner, repo, config, host) {
157
+ const identity = `${String(owner || '').toLowerCase()}/${String(repo || '').toLowerCase()}`;
158
+ return bindingRepositoryForHost(
159
+ config,
160
+ identity,
161
+ resolveBindingRepositoryFromPR(owner, repo, config),
162
+ host
163
+ );
164
+ }
165
+
166
+ /**
167
+ * Filter form of {@link resolveBindingRepositoryForHost}: applies the same rule
168
+ * to a binding key the caller already resolved. Used where re-deriving the key
169
+ * from owner/repo could lose it — a `url_pattern` entry whose captures do not
170
+ * reproduce its config key, for instance.
171
+ *
172
+ * @param {Object} config
173
+ * @param {string} identity - The PR's own normalized `owner/repo`
174
+ * @param {string} bindingRepository - Key the caller resolved
175
+ * @param {string|null|undefined} host
176
+ * @returns {string} The key to bind through
177
+ */
178
+ function bindingRepositoryForHost(config, identity, bindingRepository, host) {
179
+ if (host !== null) return bindingRepository;
180
+ if (String(bindingRepository).toLowerCase() === String(identity).toLowerCase()) return bindingRepository;
181
+ return isExclusiveAltHost(getRepoConfig(config, bindingRepository)) ? identity : bindingRepository;
182
+ }
183
+
184
+ /**
185
+ * The single mapping from a PR's KNOWN host to the setup `?host=` param value.
186
+ * Used by every entry point that can name a PR's host up front: dashboard
187
+ * collection rows, recent-review rows, the pasted-URL flow, the CLI cold start,
188
+ * and single-port delegation.
189
+ *
190
+ * - an alt-host string → that string (setup binds it directly, no probe).
191
+ * - `null` (github.com) with ANY `api_host`-bearing entry in play → the
192
+ * `'github'` sentinel. Staying silent here leaves setup on the ambiguity
193
+ * rule, which probes a dual repo and binds an exclusive one to its alt host;
194
+ * announcing it is also what lets setup apply the host-aware key rule above.
195
+ * - `null` on a plain github.com repo → `null` (omit; the ambiguity rule
196
+ * already binds github.com, so there is nothing to say).
197
+ * - unknown host → `null` (omit; the server derives it).
198
+ *
199
+ * @param {Object} config
200
+ * @param {string} owner
201
+ * @param {string} repo
202
+ * @param {string|null|undefined} host - The PR's resolved host
203
+ * @returns {string|null} `?host=` value, or null to omit
204
+ */
205
+ function setupHostParam(config, owner, repo, host) {
206
+ if (typeof host === 'string' && host) return host;
207
+ if (host !== null) return null;
208
+ const matched = resolveBindingRepositoryFromPR(owner, repo, config);
209
+ return getConfiguredApiHost(config, matched) ? 'github' : null;
210
+ }
211
+
41
212
  /**
42
213
  * A DUAL repo has an `api_host` configured but is NOT exclusive — its PRs may
43
214
  * live on github.com OR the alt host, so a host-unknown setup must probe.
@@ -122,36 +293,15 @@ function resolvePreflightBinding(bindingRepository, config, host) {
122
293
  return primary;
123
294
  }
124
295
 
125
- /**
126
- * Map a parser/stored host to the VALUE for the setup `?host=` query param, or
127
- * `null` to omit the param. Single source for the CLI cold-start, single-port
128
- * delegation, and (mirrored) the web paste flow — so a pasted alt URL binds the
129
- * alt host directly instead of re-probing at setup.
130
- *
131
- * - alt api_host URL string → that string (setup binds the alt host)
132
- * - `null` on a DUAL repo → the `'github'` sentinel (setup binds github.com,
133
- * no probe — avoids a loud failure if the alt host is down for a PR we KNOW
134
- * is on github)
135
- * - anything else (plain/exclusive repo, or unknown host) → `null` (omit; no
136
- * probe happens for those, and omitting avoids the exclusive-null throw)
137
- *
138
- * Callers append the value as `host=${encodeURIComponent(value)}`.
139
- *
140
- * @param {string|null|undefined} host - parser/stored host
141
- * @param {boolean} isDual - whether the repo is dual (github + alt-host)
142
- * @returns {string|null} the param value, or null to omit
143
- */
144
- function hostSetupParamValue(host, isDual) {
145
- if (typeof host === 'string' && host) return host;
146
- if (host === null && isDual) return 'github';
147
- return null;
148
- }
149
-
150
296
  module.exports = {
151
297
  storedHostToOption,
298
+ explicitHostForBinding,
299
+ resolveRecordedHost,
300
+ resolveBindingRepositoryForHost,
301
+ bindingRepositoryForHost,
302
+ setupHostParam,
152
303
  isDualHostRepo,
153
304
  isDualHostRepoConfig,
154
305
  getConfiguredApiHost,
155
306
  resolvePreflightBinding,
156
- hostSetupParamValue,
157
307
  };
@@ -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
  };