@in-the-loop-labs/pair-review 5.2.3 → 5.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -3
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin-code-critic/.claude-plugin/plugin.json +1 -1
- package/plugin-code-critic/skills/analyze/references/level1-thorough.md +52 -121
- package/plugin-code-critic/skills/analyze/references/level2-thorough.md +49 -113
- package/plugin-code-critic/skills/analyze/references/level3-thorough.md +46 -195
- package/plugin-code-critic/skills/analyze/references/orchestration-thorough.md +56 -112
- package/plugin-pair-loop/.claude-plugin/plugin.json +1 -1
- package/public/css/analysis-config.css +29 -0
- package/public/css/pr.css +208 -0
- package/public/js/components/AIPanel.js +14 -9
- package/public/js/components/ChatPanel.js +790 -54
- package/public/js/components/ConfirmDialog.js +70 -2
- package/public/js/modules/pierre-bridge.js +58 -97
- package/public/js/modules/suggestion-manager.js +9 -121
- package/public/js/pr.js +15 -28
- package/public/js/utils/scroll-into-view.js +18 -4
- package/src/ai/analyzer.js +30 -5
- package/src/ai/antigravity-provider.js +7 -6
- package/src/ai/claude-provider.js +4 -8
- package/src/ai/codex-provider.js +3 -4
- package/src/ai/index.js +2 -0
- package/src/ai/muse-provider.js +3 -4
- package/src/ai/omp-provider.js +27 -12
- package/src/ai/pi-provider.js +12 -6
- package/src/ai/prompts/baseline/consolidation/thorough.js +56 -43
- package/src/ai/prompts/baseline/level1/thorough.js +76 -138
- package/src/ai/prompts/baseline/level2/thorough.js +76 -129
- package/src/ai/prompts/baseline/level3/thorough.js +67 -212
- package/src/ai/prompts/baseline/orchestration/thorough.js +79 -130
- package/src/ai/prompts/render-for-skill.js +5 -0
- package/src/ai/prompts/shared/adversarial-verification.js +68 -0
- package/src/ai/provider.js +60 -1
- package/src/ai/stream-parser.js +22 -1
- package/src/chat/acp-bridge.js +11 -0
- package/src/chat/chat-models.js +348 -0
- package/src/chat/chat-providers.js +17 -0
- package/src/chat/claude-code-bridge.js +9 -0
- package/src/chat/codex-bridge.js +6 -1
- package/src/chat/omp-bridge.js +5 -0
- package/src/chat/pi-bridge.js +20 -5
- package/src/chat/session-manager.js +158 -63
- package/src/config.js +92 -5
- package/src/git/worktree.js +29 -10
- package/src/github/client.js +30 -10
- package/src/hooks/payloads.js +5 -1
- package/src/routes/chat.js +83 -11
- package/src/setup/pr-setup.js +54 -1
|
@@ -15,6 +15,7 @@ const AcpBridge = require('./acp-bridge');
|
|
|
15
15
|
const ClaudeCodeBridge = require('./claude-code-bridge');
|
|
16
16
|
const CodexBridge = require('./codex-bridge');
|
|
17
17
|
const { getChatProvider, isAcpProvider, isOmpProvider, isClaudeCodeProvider, isCodexProvider, applyConfigOverrides: applyChatConfigOverrides } = require('./chat-providers');
|
|
18
|
+
const { resolveChatModel } = require('./chat-models');
|
|
18
19
|
const logger = require('../utils/logger');
|
|
19
20
|
|
|
20
21
|
const taskExtensionDir = path.resolve(__dirname, '../../.pi/extensions/task');
|
|
@@ -23,7 +24,14 @@ const CHAT_TOOLS = 'read,bash,grep,find,ls';
|
|
|
23
24
|
|
|
24
25
|
// OMP's tool names differ from Pi's: file listing is `glob` (no find/ls), and
|
|
25
26
|
// OMP errors on unknown tool names in --tools, so the Pi list cannot be reused.
|
|
26
|
-
|
|
27
|
+
// `task` is OMP's built-in subagent tool. Note that OMP subagents take their
|
|
28
|
+
// tool set from OMP agent definitions, not from --tools, so the write/edit
|
|
29
|
+
// exclusion here applies to the parent turn only (Pi's extension, by contrast,
|
|
30
|
+
// re-passes the parent's active tool list to its subtasks). Chat runs in the
|
|
31
|
+
// review's real working tree — no worktree isolation in Local mode — but the
|
|
32
|
+
// blast radius is unchanged because bash is already granted. See the SECURITY
|
|
33
|
+
// comment block in src/ai/omp-provider.js for detail.
|
|
34
|
+
const OMP_CHAT_TOOLS = 'read,bash,grep,glob,task';
|
|
27
35
|
|
|
28
36
|
class ChatSessionManager {
|
|
29
37
|
/**
|
|
@@ -46,14 +54,27 @@ class ChatSessionManager {
|
|
|
46
54
|
* @param {string} [options.systemPrompt] - System prompt text
|
|
47
55
|
* @param {string} [options.cwd] - Working directory for agent
|
|
48
56
|
* @param {string} [options.initialContext] - Initial context to prepend to the first user message
|
|
49
|
-
* @returns {Promise<{id: number, status: string}>}
|
|
57
|
+
* @returns {Promise<{id: number, status: string, model: string|null, cliModel: string|null}>}
|
|
58
|
+
* `model` is the stored selector (canonical catalog id or raw string); `cliModel` is
|
|
59
|
+
* what was actually handed to the CLI.
|
|
50
60
|
*/
|
|
51
61
|
async createSession({ provider, model, reviewId, contextCommentId, systemPrompt, cwd, initialContext, loadSkills }) {
|
|
52
62
|
// Resolve provider definition once — used for model fallback and bridge construction
|
|
53
63
|
const providerDef = getChatProvider(provider);
|
|
54
64
|
|
|
55
65
|
// Resolve model: explicit request value > provider config default
|
|
56
|
-
const
|
|
66
|
+
const selector = model || providerDef?.model || null;
|
|
67
|
+
|
|
68
|
+
// Canonicalise BEFORE the INSERT. Both the request and `chat_providers.<id>.model`
|
|
69
|
+
// may name a model by alias (`opus` -> `opus-4.8-xhigh`); storing the alias would
|
|
70
|
+
// leave the sessions list, the hook payload, and the picker's checkmark disagreeing
|
|
71
|
+
// with the catalog. `resolution.id` is exactly what to store: the canonical id when
|
|
72
|
+
// known, the raw selector for a passthrough (raw CLI strings are supported), and
|
|
73
|
+
// null when the selector resolves to nothing — absent, or an analysis-only model,
|
|
74
|
+
// both of which run the provider's own default. Re-resolving the stored value in
|
|
75
|
+
// `_createBridge` is idempotent: a canonical id matches itself.
|
|
76
|
+
const selectorResolution = resolveChatModel(provider, selector, providerDef);
|
|
77
|
+
const resolvedModel = selectorResolution.id;
|
|
57
78
|
|
|
58
79
|
// Insert session record into DB
|
|
59
80
|
const stmt = this._db.prepare(`
|
|
@@ -72,7 +93,7 @@ class ChatSessionManager {
|
|
|
72
93
|
|
|
73
94
|
// Create and start the bridge
|
|
74
95
|
// Chat sessions get bash for git commands; review analysis uses the safe default
|
|
75
|
-
const bridge = this._createBridge(provider, {
|
|
96
|
+
const { bridge, resolved } = this._createBridge(provider, {
|
|
76
97
|
provider,
|
|
77
98
|
model: resolvedModel,
|
|
78
99
|
cwd,
|
|
@@ -88,8 +109,16 @@ class ChatSessionManager {
|
|
|
88
109
|
error: new Set()
|
|
89
110
|
};
|
|
90
111
|
|
|
91
|
-
// Store in map before starting so event handlers can find it
|
|
92
|
-
|
|
112
|
+
// Store in map before starting so event handlers can find it.
|
|
113
|
+
// model/cliModel are kept alongside so callers (hook payloads) can report both the
|
|
114
|
+
// stored selector and the model string actually handed to the CLI.
|
|
115
|
+
this._sessions.set(sessionId, {
|
|
116
|
+
bridge,
|
|
117
|
+
listeners,
|
|
118
|
+
initialContext: initialContext || null,
|
|
119
|
+
model: resolvedModel,
|
|
120
|
+
cliModel: resolved.cliModel,
|
|
121
|
+
});
|
|
93
122
|
|
|
94
123
|
// Wire up bridge events
|
|
95
124
|
this._wireBridgeEvents(sessionId, bridge, listeners);
|
|
@@ -109,7 +138,7 @@ class ChatSessionManager {
|
|
|
109
138
|
}
|
|
110
139
|
|
|
111
140
|
logger.info(`[ChatSession] Session ${sessionId} active`);
|
|
112
|
-
return { id: sessionId, status: 'active' };
|
|
141
|
+
return { id: sessionId, status: 'active', model: resolvedModel, cliModel: resolved.cliModel };
|
|
113
142
|
}
|
|
114
143
|
|
|
115
144
|
/**
|
|
@@ -420,12 +449,18 @@ class ChatSessionManager {
|
|
|
420
449
|
* @param {string} [options.systemPrompt] - System prompt text
|
|
421
450
|
* @param {string} [options.cwd] - Working directory for agent
|
|
422
451
|
* @param {boolean} [options.loadSkills] - Resolved load_skills override for the session
|
|
423
|
-
* @returns {Promise<{id: number, status: string}>}
|
|
452
|
+
* @returns {Promise<{id: number, status: string, model: string|null, cliModel: string|null}>}
|
|
424
453
|
*/
|
|
425
454
|
async resumeSession(sessionId, { systemPrompt, cwd, loadSkills } = {}) {
|
|
426
455
|
// Already active — return immediately
|
|
427
456
|
if (this._sessions.has(sessionId)) {
|
|
428
|
-
|
|
457
|
+
const active = this._sessions.get(sessionId);
|
|
458
|
+
return {
|
|
459
|
+
id: sessionId,
|
|
460
|
+
status: 'active',
|
|
461
|
+
model: active.model ?? null,
|
|
462
|
+
cliModel: active.cliModel ?? null,
|
|
463
|
+
};
|
|
429
464
|
}
|
|
430
465
|
|
|
431
466
|
// Load session row from DB
|
|
@@ -461,7 +496,10 @@ class ChatSessionManager {
|
|
|
461
496
|
resumeOptions = { sessionPath: row.agent_session_id };
|
|
462
497
|
}
|
|
463
498
|
|
|
464
|
-
|
|
499
|
+
// Resume re-resolves the stored selector: a session created on a canonical catalog
|
|
500
|
+
// id (e.g. `opus-5-high`) must get its cli_model and effort env back after a restart,
|
|
501
|
+
// not `--model opus-5-high`, which the CLI would reject.
|
|
502
|
+
const { bridge, resolved } = this._createBridge(row.provider, {
|
|
465
503
|
provider: row.provider,
|
|
466
504
|
model: row.model,
|
|
467
505
|
cwd,
|
|
@@ -478,7 +516,16 @@ class ChatSessionManager {
|
|
|
478
516
|
error: new Set()
|
|
479
517
|
};
|
|
480
518
|
|
|
481
|
-
this._sessions.set(sessionId, {
|
|
519
|
+
this._sessions.set(sessionId, {
|
|
520
|
+
bridge,
|
|
521
|
+
listeners,
|
|
522
|
+
initialContext: null,
|
|
523
|
+
// Canonical, not the raw stored value: a row written before an alias was
|
|
524
|
+
// canonicalised (or one whose model now comes from `chat_providers.<id>.model`)
|
|
525
|
+
// must report the same id the picker shows. See `resolveChatModel`'s `id` contract.
|
|
526
|
+
model: resolved.id ?? null,
|
|
527
|
+
cliModel: resolved.cliModel,
|
|
528
|
+
});
|
|
482
529
|
this._wireBridgeEvents(sessionId, bridge, listeners);
|
|
483
530
|
|
|
484
531
|
// Start the bridge process
|
|
@@ -501,7 +548,7 @@ class ChatSessionManager {
|
|
|
501
548
|
`).run(sessionId);
|
|
502
549
|
|
|
503
550
|
logger.info(`[ChatSession] Session ${sessionId} resumed`);
|
|
504
|
-
return { id: sessionId, status: 'active' };
|
|
551
|
+
return { id: sessionId, status: 'active', model: resolved.id ?? null, cliModel: resolved.cliModel };
|
|
505
552
|
}
|
|
506
553
|
|
|
507
554
|
/**
|
|
@@ -544,61 +591,104 @@ class ChatSessionManager {
|
|
|
544
591
|
* ACP providers get an AcpBridge, Claude gets a ClaudeCodeBridge, Codex gets
|
|
545
592
|
* a CodexBridge, OMP gets an OmpBridge; everything else gets a PiBridge with
|
|
546
593
|
* tools/skills.
|
|
594
|
+
* This is also the single choke point for model resolution: `options.model` (or the
|
|
595
|
+
* provider's configured default) is run through `resolveChatModel` exactly once, and
|
|
596
|
+
* the resulting CLI model, effort args, and env are what reach the bridge.
|
|
597
|
+
*
|
|
547
598
|
* @param {string} provider
|
|
548
599
|
* @param {Object} options - Bridge constructor options
|
|
549
600
|
* @param {Object} [providerDef] - Pre-resolved provider definition (avoids redundant getChatProvider calls)
|
|
550
|
-
* @returns {PiBridge|OmpBridge|AcpBridge|ClaudeCodeBridge|CodexBridge}
|
|
601
|
+
* @returns {{bridge: PiBridge|OmpBridge|AcpBridge|ClaudeCodeBridge|CodexBridge, resolved: {id: string|null, cliModel: string|null, extraArgs: string[], env: Object, known: boolean}}}
|
|
551
602
|
*/
|
|
552
603
|
_createBridge(provider, options, providerDef) {
|
|
553
604
|
const def = providerDef || getChatProvider(provider);
|
|
605
|
+
|
|
606
|
+
// Single resolution point for both createSession and resumeSession. The stored
|
|
607
|
+
// selector (canonical catalog id, or a raw CLI string from config) is translated
|
|
608
|
+
// here into the CLI model plus any effort flags/env the catalog entry carries.
|
|
609
|
+
const selector = options.model || def?.model || null;
|
|
610
|
+
const resolved = resolveChatModel(provider, selector, def);
|
|
611
|
+
logger.debug(
|
|
612
|
+
`[ChatSession] Model resolution for ${provider}: selector=${selector ?? '(provider default)'} ` +
|
|
613
|
+
`-> id=${resolved.id ?? '(none)'}, cliModel=${resolved.cliModel ?? '(none)'}, known=${resolved.known}`
|
|
614
|
+
);
|
|
615
|
+
|
|
616
|
+
// Env merge order matches the review providers: provider-level def.env first,
|
|
617
|
+
// then the model-level catalog env (e.g. CLAUDE_CODE_EFFORT_LEVEL).
|
|
618
|
+
const env = { ...(def?.env || {}), ...resolved.env };
|
|
619
|
+
|
|
554
620
|
if (isAcpProvider(provider)) {
|
|
555
|
-
return
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
621
|
+
return {
|
|
622
|
+
resolved,
|
|
623
|
+
bridge: new AcpBridge({
|
|
624
|
+
...options,
|
|
625
|
+
model: resolved.cliModel,
|
|
626
|
+
acpCommand: def?.command,
|
|
627
|
+
acpArgs: def?.args,
|
|
628
|
+
extraArgs: resolved.extraArgs,
|
|
629
|
+
env,
|
|
630
|
+
useShell: def?.useShell,
|
|
631
|
+
}),
|
|
632
|
+
};
|
|
563
633
|
}
|
|
564
634
|
if (isClaudeCodeProvider(provider)) {
|
|
565
|
-
return
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
635
|
+
return {
|
|
636
|
+
resolved,
|
|
637
|
+
bridge: new ClaudeCodeBridge({
|
|
638
|
+
...options,
|
|
639
|
+
model: resolved.cliModel,
|
|
640
|
+
claudeCommand: def?.command,
|
|
641
|
+
// ClaudeCodeBridge builds its own structural flags, so there is no slot for
|
|
642
|
+
// `args` to replace — the configured args are appended alongside the catalog
|
|
643
|
+
// args, exactly as in the Pi/OMP branches. Without this,
|
|
644
|
+
// `chat_providers.claude.args`/`extra_args` were silently dropped.
|
|
645
|
+
extraArgs: [...(def?.args || []), ...resolved.extraArgs],
|
|
646
|
+
env,
|
|
647
|
+
useShell: def?.useShell,
|
|
648
|
+
}),
|
|
649
|
+
};
|
|
572
650
|
}
|
|
573
651
|
if (isCodexProvider(provider)) {
|
|
574
|
-
return
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
652
|
+
return {
|
|
653
|
+
resolved,
|
|
654
|
+
bridge: new CodexBridge({
|
|
655
|
+
...options,
|
|
656
|
+
model: resolved.cliModel,
|
|
657
|
+
codexCommand: def?.command,
|
|
658
|
+
codexArgs: def?.args,
|
|
659
|
+
extraArgs: resolved.extraArgs,
|
|
660
|
+
env,
|
|
661
|
+
useShell: def?.useShell,
|
|
662
|
+
sandbox: def?.sandbox,
|
|
663
|
+
}),
|
|
664
|
+
};
|
|
583
665
|
}
|
|
584
666
|
if (isOmpProvider(provider)) {
|
|
585
667
|
// OMP — same RPC protocol as Pi, so the option mapping below mirrors the
|
|
586
668
|
// Pi branch (see its comments), with two OMP-specific differences:
|
|
587
|
-
// - Tools: OMP_CHAT_TOOLS (OMP rejects Pi's find/ls tool names).
|
|
669
|
+
// - Tools: OMP_CHAT_TOOLS (OMP rejects Pi's find/ls tool names). It
|
|
670
|
+
// includes OMP's built-in `task` subagent tool so chat can delegate
|
|
671
|
+
// large explorations; see the OMP_CHAT_TOOLS comment above for why that
|
|
672
|
+
// tool's subagents are not bound by this allowlist.
|
|
588
673
|
// - No task extension: pair-review's bundled extension is Pi-specific
|
|
589
|
-
// (it spawns `pi` subagents via PI_CMD)
|
|
590
|
-
// which also omits
|
|
591
|
-
return
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
674
|
+
// (it spawns `pi` subagents via PI_CMD) and OMP ships its own `task`
|
|
675
|
+
// tool, matching the AI provider, which also omits the extension.
|
|
676
|
+
return {
|
|
677
|
+
resolved,
|
|
678
|
+
bridge: new OmpBridge({
|
|
679
|
+
...options,
|
|
680
|
+
provider: def?.provider || null,
|
|
681
|
+
model: resolved.cliModel,
|
|
682
|
+
piCommand: def?.command,
|
|
683
|
+
// Catalog args come AFTER the provider's configured args so a model-level
|
|
684
|
+
// flag wins over a provider-level one.
|
|
685
|
+
extraArgs: [...(def?.args || []), ...resolved.extraArgs],
|
|
686
|
+
env,
|
|
687
|
+
useShell: def?.useShell,
|
|
688
|
+
tools: OMP_CHAT_TOOLS,
|
|
689
|
+
loadSkills: options.loadSkills ?? def?.load_skills,
|
|
690
|
+
}),
|
|
691
|
+
};
|
|
602
692
|
}
|
|
603
693
|
// Pi provider — resolve config overrides (command, model, env) from provider def.
|
|
604
694
|
// options.provider is the chat provider ID (e.g. "pi") — do NOT pass it to PiBridge,
|
|
@@ -608,18 +698,23 @@ class ChatSessionManager {
|
|
|
608
698
|
// app_extensions (default true): when false, omit pair-review's task extension.
|
|
609
699
|
// load_skills (default true): when false, suppress Pi's skill auto-discovery.
|
|
610
700
|
const appExtensions = def?.app_extensions !== false;
|
|
611
|
-
return
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
701
|
+
return {
|
|
702
|
+
resolved,
|
|
703
|
+
bridge: new PiBridge({
|
|
704
|
+
...options,
|
|
705
|
+
provider: def?.provider || null,
|
|
706
|
+
model: resolved.cliModel,
|
|
707
|
+
piCommand: def?.command,
|
|
708
|
+
// Catalog args come AFTER the provider's configured args so a model-level
|
|
709
|
+
// flag wins over a provider-level one.
|
|
710
|
+
extraArgs: [...(def?.args || []), ...resolved.extraArgs],
|
|
711
|
+
env,
|
|
712
|
+
useShell: def?.useShell,
|
|
713
|
+
tools: CHAT_TOOLS,
|
|
714
|
+
extensions: appExtensions ? [taskExtensionDir] : [],
|
|
715
|
+
loadSkills: options.loadSkills ?? def?.load_skills,
|
|
716
|
+
}),
|
|
717
|
+
};
|
|
623
718
|
}
|
|
624
719
|
|
|
625
720
|
/**
|
package/src/config.js
CHANGED
|
@@ -627,6 +627,10 @@ function isExclusiveAltHost(repoConfig) {
|
|
|
627
627
|
* is consulted. The repo's explicit `features` block (written for the alt host)
|
|
628
628
|
* also does not apply to its github.com binding.
|
|
629
629
|
*
|
|
630
|
+
* The binding also carries `cloneUrl` — the repo's explicitly configured
|
|
631
|
+
* `clone_url`, or `null` when unset. Like `features`, it describes the ALT
|
|
632
|
+
* host, so the github.com binding of a DUAL repo always reports `null`.
|
|
633
|
+
*
|
|
630
634
|
* Refreshable sources (`repo:token_command`, `config:github_token_command`)
|
|
631
635
|
* additionally carry a `refresh` closure on the returned binding. Calling
|
|
632
636
|
* `refresh()` busts the cached token for that exact source, re-runs the
|
|
@@ -638,7 +642,7 @@ function isExclusiveAltHost(repoConfig) {
|
|
|
638
642
|
* @param {string|null|undefined} repository - "owner/repo" identifier, or null/undefined for no-repo fallback
|
|
639
643
|
* @param {Object} config - Configuration object from loadConfig()
|
|
640
644
|
* @param {{ host?: string|null }} [options] - Per-PR host override (see above)
|
|
641
|
-
* @returns {{ apiHost: string|null, host: string|null, token: string, features: Object, source: string, refresh: (function(): string)|null }}
|
|
645
|
+
* @returns {{ apiHost: string|null, host: string|null, token: string, features: Object, cloneUrl: string|null, source: string, refresh: (function(): string)|null }}
|
|
642
646
|
*/
|
|
643
647
|
function resolveHostBinding(repository, config, options = {}) {
|
|
644
648
|
const safeConfig = config || {};
|
|
@@ -688,6 +692,14 @@ function resolveHostBinding(repository, config, options = {}) {
|
|
|
688
692
|
const explicitFeatures = isDualGithubBinding ? undefined : repoConfig?.features;
|
|
689
693
|
const features = _resolveFeatures(apiHost, explicitFeatures);
|
|
690
694
|
|
|
695
|
+
// Explicitly configured canonical clone URL for this repo. Like `features`,
|
|
696
|
+
// it describes the alt host, so a dual repo's github.com binding does not
|
|
697
|
+
// carry it (github.com's API reports the right clone_url itself).
|
|
698
|
+
const configuredCloneUrl = (repoConfig && typeof repoConfig.clone_url === 'string' && repoConfig.clone_url)
|
|
699
|
+
? repoConfig.clone_url
|
|
700
|
+
: null;
|
|
701
|
+
const cloneUrl = isDualGithubBinding ? null : configuredCloneUrl;
|
|
702
|
+
|
|
691
703
|
// Token resolution
|
|
692
704
|
let token = '';
|
|
693
705
|
let source = 'none';
|
|
@@ -697,7 +709,7 @@ function resolveHostBinding(repository, config, options = {}) {
|
|
|
697
709
|
token = process.env.GITHUB_TOKEN;
|
|
698
710
|
source = 'env:GITHUB_TOKEN';
|
|
699
711
|
logger.debug('Using GitHub token from GITHUB_TOKEN environment variable');
|
|
700
|
-
return { apiHost, host: apiHost, token, features, source, refresh: null };
|
|
712
|
+
return { apiHost, host: apiHost, token, features, cloneUrl, source, refresh: null };
|
|
701
713
|
}
|
|
702
714
|
|
|
703
715
|
// 2. Repo-level literal token (alt-host credential; not used for a dual
|
|
@@ -706,7 +718,7 @@ function resolveHostBinding(repository, config, options = {}) {
|
|
|
706
718
|
token = repoConfig.token;
|
|
707
719
|
source = 'repo:token';
|
|
708
720
|
logger.debug(`Using token from repos[${repository}].token`);
|
|
709
|
-
return { apiHost, host: apiHost, token, features, source, refresh: null };
|
|
721
|
+
return { apiHost, host: apiHost, token, features, cloneUrl, source, refresh: null };
|
|
710
722
|
}
|
|
711
723
|
|
|
712
724
|
// 3. Repo-level token_command
|
|
@@ -718,6 +730,7 @@ function resolveHostBinding(repository, config, options = {}) {
|
|
|
718
730
|
host: apiHost,
|
|
719
731
|
token: result,
|
|
720
732
|
features,
|
|
733
|
+
cloneUrl,
|
|
721
734
|
source: 'repo:token_command',
|
|
722
735
|
refresh: _makeRefresh(repository, safeConfig, 'repo:token_command', options)
|
|
723
736
|
};
|
|
@@ -731,7 +744,7 @@ function resolveHostBinding(repository, config, options = {}) {
|
|
|
731
744
|
token = safeConfig.github_token;
|
|
732
745
|
source = 'config:github_token';
|
|
733
746
|
logger.debug('Using GitHub token from config.github_token');
|
|
734
|
-
return { apiHost, host: apiHost, token, features, source, refresh: null };
|
|
747
|
+
return { apiHost, host: apiHost, token, features, cloneUrl, source, refresh: null };
|
|
735
748
|
}
|
|
736
749
|
|
|
737
750
|
// 5. Top-level github_token_command. Like step 4, github.com-only.
|
|
@@ -747,6 +760,7 @@ function resolveHostBinding(repository, config, options = {}) {
|
|
|
747
760
|
host: apiHost,
|
|
748
761
|
token: result,
|
|
749
762
|
features,
|
|
763
|
+
cloneUrl,
|
|
750
764
|
source: 'config:github_token_command',
|
|
751
765
|
refresh: _makeRefresh(repository, safeConfig, 'config:github_token_command', options)
|
|
752
766
|
};
|
|
@@ -758,7 +772,7 @@ function resolveHostBinding(repository, config, options = {}) {
|
|
|
758
772
|
} else {
|
|
759
773
|
logger.debug('No token resolved for host binding');
|
|
760
774
|
}
|
|
761
|
-
return { apiHost, host: apiHost, token: '', features, source: 'none', refresh: null };
|
|
775
|
+
return { apiHost, host: apiHost, token: '', features, cloneUrl, source: 'none', refresh: null };
|
|
762
776
|
}
|
|
763
777
|
|
|
764
778
|
/**
|
|
@@ -1091,6 +1105,18 @@ function validateRepoConfig(config) {
|
|
|
1091
1105
|
}
|
|
1092
1106
|
}
|
|
1093
1107
|
|
|
1108
|
+
// Optional canonical clone URL for the repository. Primarily for alt
|
|
1109
|
+
// hosts whose API omits `base.repo.clone_url` on the PR response; without
|
|
1110
|
+
// it pair-review falls back to a github.com URL, which matches the wrong
|
|
1111
|
+
// local remote and clones from the wrong host.
|
|
1112
|
+
if (repoEntry.clone_url !== undefined && repoEntry.clone_url !== null) {
|
|
1113
|
+
if (typeof repoEntry.clone_url !== 'string' || !repoEntry.clone_url) {
|
|
1114
|
+
throw new Error(
|
|
1115
|
+
`Invalid pair-review config: repos["${repoKey}"].clone_url must be a non-empty string.`
|
|
1116
|
+
);
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1094
1120
|
const links = repoEntry.links;
|
|
1095
1121
|
if (links && typeof links === 'object' && links.external !== undefined && links.external !== null) {
|
|
1096
1122
|
const ext = links.external;
|
|
@@ -1482,6 +1508,65 @@ function getRepoSkipBulkFetch(config, repository) {
|
|
|
1482
1508
|
return repoConfig?.skip_bulk_fetch === true;
|
|
1483
1509
|
}
|
|
1484
1510
|
|
|
1511
|
+
/**
|
|
1512
|
+
* Gets the explicitly configured canonical clone URL for a repository.
|
|
1513
|
+
*
|
|
1514
|
+
* Primarily for alt hosts whose GitHub-compatible REST API omits
|
|
1515
|
+
* `base.repo.clone_url` from the pull request response. When configured, it
|
|
1516
|
+
* is the URL matched against the local checkout's `git remote -v` entries to
|
|
1517
|
+
* pick the fetch remote, and the URL used for a fresh clone when no local
|
|
1518
|
+
* checkout exists.
|
|
1519
|
+
*
|
|
1520
|
+
* @param {Object} config - Configuration object from loadConfig()
|
|
1521
|
+
* @param {string} repository - Repository in "owner/repo" format
|
|
1522
|
+
* @returns {string|null} - Clone URL or null if not configured
|
|
1523
|
+
*/
|
|
1524
|
+
function getRepoCloneUrl(config, repository) {
|
|
1525
|
+
const repoConfig = getRepoConfig(config || {}, repository);
|
|
1526
|
+
const value = repoConfig?.clone_url;
|
|
1527
|
+
return (typeof value === 'string' && value) ? value : null;
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
/**
|
|
1531
|
+
* Host-aware variant of {@link getRepoCloneUrl}.
|
|
1532
|
+
*
|
|
1533
|
+
* `clone_url`, like `features`, describes the repo's ALT host, so the
|
|
1534
|
+
* github.com binding of a DUAL repo (`api_host` set with `exclusive: false`)
|
|
1535
|
+
* must not report it — github.com's API reports the right `clone_url` itself.
|
|
1536
|
+
* This mirrors the `isDualGithubBinding` guard in `resolveHostBinding`, for
|
|
1537
|
+
* callers that need the configured URL WITHOUT resolving a full binding (e.g.
|
|
1538
|
+
* restore mode, which never contacts an API).
|
|
1539
|
+
*
|
|
1540
|
+
* `host` follows the `resolveHostBinding` options convention:
|
|
1541
|
+
* - `undefined` — host unknown; apply the ambiguity rule (an EXCLUSIVE
|
|
1542
|
+
* alt-host repo binds to its alt host, a DUAL or plain repo to github.com).
|
|
1543
|
+
* - `null` — github.com.
|
|
1544
|
+
* - `'<url>'` — an alt host.
|
|
1545
|
+
*
|
|
1546
|
+
* Unlike `resolveHostBinding` this never throws on a contradictory host: it
|
|
1547
|
+
* is an advisory lookup, and a bad host simply yields the conservative answer.
|
|
1548
|
+
*
|
|
1549
|
+
* @param {Object} config - Configuration object from loadConfig()
|
|
1550
|
+
* @param {string} repository - `repos[...]` config-lookup key
|
|
1551
|
+
* @param {string|null|undefined} host - The host this lookup is for (see above)
|
|
1552
|
+
* @returns {string|null} - Clone URL, or null when unset or not applicable
|
|
1553
|
+
*/
|
|
1554
|
+
function getRepoCloneUrlForHost(config, repository, host) {
|
|
1555
|
+
const repoConfig = getRepoConfig(config || {}, repository);
|
|
1556
|
+
const configuredApiHost = (repoConfig && typeof repoConfig.api_host === 'string' && repoConfig.api_host)
|
|
1557
|
+
? repoConfig.api_host
|
|
1558
|
+
: null;
|
|
1559
|
+
if (configuredApiHost !== null && !isExclusiveAltHost(repoConfig)) {
|
|
1560
|
+
// Dual repo: the ambiguity rule (host unknown) binds github.com, and so
|
|
1561
|
+
// does an explicit `null`. Either way the configured URL does not apply.
|
|
1562
|
+
const effectiveHost = host === undefined ? null : host;
|
|
1563
|
+
if (effectiveHost === null) {
|
|
1564
|
+
return null;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
return getRepoCloneUrl(config, repository);
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1485
1570
|
/**
|
|
1486
1571
|
* Gets the configured pool size for a repository from file config only.
|
|
1487
1572
|
* Prefer resolvePoolConfig() when DB repo_settings are available.
|
|
@@ -1732,6 +1817,8 @@ module.exports = {
|
|
|
1732
1817
|
resolveRepoOptions,
|
|
1733
1818
|
getRepoResetScript,
|
|
1734
1819
|
getRepoSkipBulkFetch,
|
|
1820
|
+
getRepoCloneUrl,
|
|
1821
|
+
getRepoCloneUrlForHost,
|
|
1735
1822
|
getRepoPoolSize,
|
|
1736
1823
|
getRepoPoolFetchInterval,
|
|
1737
1824
|
getRepoLoadSkills,
|
package/src/git/worktree.js
CHANGED
|
@@ -73,6 +73,11 @@ class GitWorktreeManager {
|
|
|
73
73
|
* repository's git config. This preserves proxy/mirror setups where the
|
|
74
74
|
* canonical fetch URL may differ from GitHub's clone URL.
|
|
75
75
|
*
|
|
76
|
+
* A remote matching `cloneUrl` always wins over one matching `sshUrl`,
|
|
77
|
+
* regardless of `git remote -v` ordering: `cloneUrl` may be the user's
|
|
78
|
+
* explicitly configured `repos[...].clone_url`, while `sshUrl` still comes
|
|
79
|
+
* from the API and can name a different host.
|
|
80
|
+
*
|
|
76
81
|
* @param {Object} git - simple-git instance
|
|
77
82
|
* @param {string} cloneUrl - HTTPS clone URL of the target repository
|
|
78
83
|
* @param {string} sshUrl - SSH URL of the target repository (may be empty/null)
|
|
@@ -88,10 +93,15 @@ class GitWorktreeManager {
|
|
|
88
93
|
throw new Error(`No remotes configured — cannot resolve base repository for ${cloneUrl}`);
|
|
89
94
|
}
|
|
90
95
|
|
|
91
|
-
// Parse remote output into { name: url } map (fetch URLs only)
|
|
96
|
+
// Parse remote output into { name: url } map (fetch URLs only).
|
|
97
|
+
// `git remote -v` annotates a partial-clone remote's fetch line with its
|
|
98
|
+
// object filter (`origin<TAB>https://… (fetch) [blob:none]`), so the
|
|
99
|
+
// `(fetch)` marker is not always the end of the line. Anchoring on it
|
|
100
|
+
// would drop every filtered remote — typically `origin` itself on a
|
|
101
|
+
// partial clone — and send resolution to an unrelated remote.
|
|
92
102
|
const remotes = {};
|
|
93
103
|
for (const line of remoteOutput.trim().split('\n')) {
|
|
94
|
-
const match = line.match(/^(\S+)\s+(\S+)\s+\(fetch\)
|
|
104
|
+
const match = line.match(/^(\S+)\s+(\S+)\s+\(fetch\)(?:\s|$)/);
|
|
95
105
|
if (match) {
|
|
96
106
|
remotes[match[1]] = match[2];
|
|
97
107
|
}
|
|
@@ -122,16 +132,25 @@ class GitWorktreeManager {
|
|
|
122
132
|
? 'origin'
|
|
123
133
|
: remoteNames.find((name) => name !== MANAGED_REMOTE) || 'origin';
|
|
124
134
|
|
|
125
|
-
// Check each non-managed remote for a direct URL match
|
|
126
|
-
|
|
127
|
-
|
|
135
|
+
// Check each non-managed remote for a direct URL match, in TWO passes:
|
|
136
|
+
// the clone URL first across every remote, only then the SSH URL.
|
|
137
|
+
//
|
|
138
|
+
// A single pass would let `git remote -v` ordering decide between them,
|
|
139
|
+
// which breaks an explicitly configured `repos[...].clone_url`: that value
|
|
140
|
+
// replaces the API's `base.repo.clone_url` but NOT its `ssh_url`, so an
|
|
141
|
+
// earlier-sorting remote matching the (possibly wrong-host) API ssh_url
|
|
142
|
+
// would outrank the remote the user pointed us at. When both URLs name the
|
|
143
|
+
// same repository the two passes pick the same remote as before.
|
|
144
|
+
const nonManagedRemotes = Object.entries(remotes).filter(([name]) => name !== MANAGED_REMOTE);
|
|
145
|
+
for (const target of [normalizedCloneUrl, normalizedSshUrl]) {
|
|
146
|
+
if (!target) {
|
|
128
147
|
continue;
|
|
129
148
|
}
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
(
|
|
133
|
-
|
|
134
|
-
|
|
149
|
+
for (const [name, url] of nonManagedRemotes) {
|
|
150
|
+
if (normalizeUrl(url) === target) {
|
|
151
|
+
console.log(`Found matching remote '${name}' for base repository`);
|
|
152
|
+
return name;
|
|
153
|
+
}
|
|
135
154
|
}
|
|
136
155
|
}
|
|
137
156
|
|
package/src/github/client.js
CHANGED
|
@@ -50,8 +50,15 @@ function withAuthorizationPrefix(token) {
|
|
|
50
50
|
* `refresh: null`, so a github.com PAT client behaves exactly as before
|
|
51
51
|
* (no hook-driven retry).
|
|
52
52
|
*
|
|
53
|
+
* The optional `cloneUrl` from an object binding (the repo's explicitly
|
|
54
|
+
* configured `clone_url`) is carried through so `fetchPullRequest` can report
|
|
55
|
+
* it in place of the API's `base.repo.clone_url` — some GitHub-compatible
|
|
56
|
+
* hosts omit that field entirely. The legacy bare-token path keeps
|
|
57
|
+
* `cloneUrl: null`, so a github.com PAT client reports exactly what the API
|
|
58
|
+
* returned.
|
|
59
|
+
*
|
|
53
60
|
* @param {string|Object} arg - Token string or binding object
|
|
54
|
-
* @returns {{ token: string, apiHost: string|null, features: Object, refresh: (function(): (string|Promise<string>))|null }}
|
|
61
|
+
* @returns {{ token: string, apiHost: string|null, features: Object, cloneUrl: string|null, refresh: (function(): (string|Promise<string>))|null }}
|
|
55
62
|
*/
|
|
56
63
|
function normaliseBinding(arg) {
|
|
57
64
|
if (typeof arg === 'string') {
|
|
@@ -59,6 +66,7 @@ function normaliseBinding(arg) {
|
|
|
59
66
|
token: arg,
|
|
60
67
|
apiHost: null,
|
|
61
68
|
features: { ...DEFAULT_FEATURES },
|
|
69
|
+
cloneUrl: null,
|
|
62
70
|
refresh: null
|
|
63
71
|
};
|
|
64
72
|
}
|
|
@@ -68,20 +76,23 @@ function normaliseBinding(arg) {
|
|
|
68
76
|
const features = (arg.features && typeof arg.features === 'object')
|
|
69
77
|
? { ...DEFAULT_FEATURES, ...arg.features }
|
|
70
78
|
: { ...DEFAULT_FEATURES };
|
|
79
|
+
const cloneUrl = (typeof arg.cloneUrl === 'string' && arg.cloneUrl) ? arg.cloneUrl : null;
|
|
71
80
|
const refresh = typeof arg.refresh === 'function' ? arg.refresh : null;
|
|
72
|
-
return { token, apiHost, features, refresh };
|
|
81
|
+
return { token, apiHost, features, cloneUrl, refresh };
|
|
73
82
|
}
|
|
74
|
-
return { token: '', apiHost: null, features: { ...DEFAULT_FEATURES }, refresh: null };
|
|
83
|
+
return { token: '', apiHost: null, features: { ...DEFAULT_FEATURES }, cloneUrl: null, refresh: null };
|
|
75
84
|
}
|
|
76
85
|
|
|
77
86
|
/**
|
|
78
87
|
* GitHub API client wrapper with error handling and rate limiting.
|
|
79
88
|
*
|
|
80
89
|
* Constructor accepts either a bare token string (legacy) or a binding
|
|
81
|
-
* object `{ token, apiHost, features }` returned by
|
|
90
|
+
* object `{ token, apiHost, features, cloneUrl }` returned by
|
|
82
91
|
* `resolveHostBinding()`. When a binding is provided, `apiHost` is passed
|
|
83
|
-
* to Octokit as `baseUrl` (defaults to `api.github.com` when null)
|
|
84
|
-
* `features` controls per-area dispatch into the operations layer
|
|
92
|
+
* to Octokit as `baseUrl` (defaults to `api.github.com` when null),
|
|
93
|
+
* `features` controls per-area dispatch into the operations layer, and
|
|
94
|
+
* `cloneUrl` (the repo's configured `clone_url`) overrides the clone URL
|
|
95
|
+
* reported by `fetchPullRequest`.
|
|
85
96
|
*
|
|
86
97
|
* The public method signatures remain identical to the pre-refactor
|
|
87
98
|
* shape — all GraphQL operations are now thin delegations to the
|
|
@@ -98,6 +109,11 @@ class GitHubClient {
|
|
|
98
109
|
this.features = binding.features;
|
|
99
110
|
this.apiHost = binding.apiHost;
|
|
100
111
|
this.token = binding.token;
|
|
112
|
+
// Explicitly configured canonical clone URL for this repo (`repos[...]
|
|
113
|
+
// .clone_url`), or null. Wins over the API's `base.repo.clone_url` in
|
|
114
|
+
// `fetchPullRequest` — it is the user's direct statement of where the git
|
|
115
|
+
// objects live, and some alt hosts omit the API field altogether.
|
|
116
|
+
this.cloneUrl = binding.cloneUrl;
|
|
101
117
|
// Capability to obtain a fresh token (e.g. re-run a token_command).
|
|
102
118
|
// Only present for refreshable bindings; null for bare-token / literal
|
|
103
119
|
// / env sources, which therefore get NO 401 refresh-and-retry behaviour.
|
|
@@ -257,11 +273,15 @@ class GitHubClient {
|
|
|
257
273
|
mergeable: data.mergeable,
|
|
258
274
|
mergeable_state: data.mergeable_state,
|
|
259
275
|
html_url: data.html_url,
|
|
276
|
+
// `base.repo` is absent on some GitHub-compatible hosts, so every
|
|
277
|
+
// field is read defensively. A configured `clone_url` wins over the
|
|
278
|
+
// API's value: it is the user's explicit statement of where the git
|
|
279
|
+
// objects live.
|
|
260
280
|
repository: {
|
|
261
|
-
full_name: data.base
|
|
262
|
-
clone_url: data.base
|
|
263
|
-
ssh_url: data.base
|
|
264
|
-
default_branch: data.base
|
|
281
|
+
full_name: data.base?.repo?.full_name || `${owner}/${repo}`,
|
|
282
|
+
clone_url: this.cloneUrl || data.base?.repo?.clone_url,
|
|
283
|
+
ssh_url: data.base?.repo?.ssh_url,
|
|
284
|
+
default_branch: data.base?.repo?.default_branch
|
|
265
285
|
}
|
|
266
286
|
};
|
|
267
287
|
} catch (error) {
|