@in-the-loop-labs/pair-review 5.2.2 → 5.3.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.
Files changed (48) hide show
  1. package/README.md +26 -16
  2. package/package.json +1 -1
  3. package/plugin/.claude-plugin/plugin.json +1 -1
  4. package/plugin-code-critic/.claude-plugin/plugin.json +1 -1
  5. package/plugin-code-critic/skills/analyze/references/level1-thorough.md +52 -121
  6. package/plugin-code-critic/skills/analyze/references/level2-thorough.md +49 -113
  7. package/plugin-code-critic/skills/analyze/references/level3-thorough.md +46 -195
  8. package/plugin-code-critic/skills/analyze/references/orchestration-thorough.md +56 -112
  9. package/plugin-pair-loop/.claude-plugin/plugin.json +1 -1
  10. package/public/css/analysis-config.css +29 -0
  11. package/public/css/pr.css +208 -0
  12. package/public/js/components/AIPanel.js +14 -9
  13. package/public/js/components/ChatPanel.js +790 -54
  14. package/public/js/components/ConfirmDialog.js +70 -2
  15. package/public/js/modules/pierre-bridge.js +58 -97
  16. package/public/js/modules/suggestion-manager.js +9 -121
  17. package/public/js/pr.js +15 -28
  18. package/public/js/utils/scroll-into-view.js +18 -4
  19. package/src/ai/analyzer.js +31 -6
  20. package/src/ai/antigravity-provider.js +62 -42
  21. package/src/ai/claude-provider.js +18 -20
  22. package/src/ai/codex-provider.js +76 -81
  23. package/src/ai/executable-provider.js +3 -1
  24. package/src/ai/index.js +2 -0
  25. package/src/ai/muse-provider.js +84 -52
  26. package/src/ai/omp-provider.js +27 -12
  27. package/src/ai/pi-provider.js +12 -6
  28. package/src/ai/prompts/baseline/consolidation/thorough.js +56 -43
  29. package/src/ai/prompts/baseline/level1/thorough.js +76 -138
  30. package/src/ai/prompts/baseline/level2/thorough.js +76 -129
  31. package/src/ai/prompts/baseline/level3/thorough.js +67 -212
  32. package/src/ai/prompts/baseline/orchestration/thorough.js +79 -130
  33. package/src/ai/prompts/render-for-skill.js +5 -0
  34. package/src/ai/prompts/shared/adversarial-verification.js +68 -0
  35. package/src/ai/provider.js +61 -2
  36. package/src/ai/stream-parser.js +22 -1
  37. package/src/chat/acp-bridge.js +11 -0
  38. package/src/chat/chat-models.js +348 -0
  39. package/src/chat/chat-providers.js +17 -0
  40. package/src/chat/claude-code-bridge.js +9 -0
  41. package/src/chat/codex-bridge.js +6 -1
  42. package/src/chat/omp-bridge.js +5 -0
  43. package/src/chat/pi-bridge.js +20 -5
  44. package/src/chat/session-manager.js +158 -63
  45. package/src/config.js +1 -1
  46. package/src/hooks/payloads.js +5 -1
  47. package/src/main.js +1 -1
  48. package/src/routes/chat.js +83 -11
@@ -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
- const OMP_CHAT_TOOLS = 'read,bash,grep,glob';
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 resolvedModel = model || providerDef?.model || null;
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
- this._sessions.set(sessionId, { bridge, listeners, initialContext: initialContext || null });
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
- return { id: sessionId, status: 'active' };
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
- const bridge = this._createBridge(row.provider, {
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, { bridge, listeners, initialContext: null });
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 new AcpBridge({
556
- ...options,
557
- model: options.model || def?.model,
558
- acpCommand: def?.command,
559
- acpArgs: def?.args,
560
- env: def?.env,
561
- useShell: def?.useShell,
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 new ClaudeCodeBridge({
566
- ...options,
567
- model: options.model || def?.model,
568
- claudeCommand: def?.command,
569
- env: def?.env,
570
- useShell: def?.useShell,
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 new CodexBridge({
575
- ...options,
576
- model: options.model || def?.model,
577
- codexCommand: def?.command,
578
- codexArgs: def?.args,
579
- env: def?.env,
580
- useShell: def?.useShell,
581
- sandbox: def?.sandbox,
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), matching the AI provider,
590
- // which also omits it for OMP.
591
- return new OmpBridge({
592
- ...options,
593
- provider: def?.provider || null,
594
- model: options.model || def?.model,
595
- piCommand: def?.command,
596
- extraArgs: def?.args,
597
- env: def?.env,
598
- useShell: def?.useShell,
599
- tools: OMP_CHAT_TOOLS,
600
- loadSkills: options.loadSkills ?? def?.load_skills,
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 new PiBridge({
612
- ...options,
613
- provider: def?.provider || null,
614
- model: options.model || def?.model,
615
- piCommand: def?.command,
616
- extraArgs: def?.args,
617
- env: def?.env,
618
- useShell: def?.useShell,
619
- tools: CHAT_TOOLS,
620
- extensions: appExtensions ? [taskExtensionDir] : [],
621
- loadSkills: options.loadSkills ?? def?.load_skills,
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
@@ -68,7 +68,7 @@ const DEFAULT_CONFIG = {
68
68
  single_port: true, // When true, reuse a single server on the configured port; new invocations delegate to the running server
69
69
  theme: "light",
70
70
  default_provider: "claude", // AI provider: 'claude', 'antigravity', 'codex', 'copilot', 'opencode', 'cursor-agent', 'pi', 'omp', 'muse'
71
- default_model: "opus", // Model within the provider (e.g., 'opus' for Claude, 'gemini-3.1-pro-low' for Antigravity)
71
+ default_model: "opus", // Model within the provider (e.g., 'opus' for Claude, 'gemini-3.8-flash-high' for Antigravity)
72
72
  tours: {
73
73
  enabled: false, // When true, the guided-tour feature is available (toolbar button visible, etc.)
74
74
  auto_generate: true, // When true, a tour generation job is kicked off automatically on review load
@@ -87,7 +87,7 @@ function buildAnalysisCompletedPayload({
87
87
 
88
88
  // ── Chat payloads ───────────────────────────────────────────────
89
89
 
90
- function buildChatPayload(event, { reviewId, sessionId, provider, model, mode, prContext, localContext, user }) {
90
+ function buildChatPayload(event, { reviewId, sessionId, provider, model, cliModel, mode, prContext, localContext, user }) {
91
91
  return {
92
92
  event,
93
93
  timestamp: new Date().toISOString(),
@@ -95,7 +95,11 @@ function buildChatPayload(event, { reviewId, sessionId, provider, model, mode, p
95
95
  reviewId,
96
96
  sessionId,
97
97
  provider: provider ?? null,
98
+ // `model` is the selector stored on the session (a canonical catalog id, or a raw
99
+ // CLI string from chat_providers.<id>.model). `cli_model` is what was actually
100
+ // handed to the CLI; null means the provider's own default was used.
98
101
  model: model ?? null,
102
+ cli_model: cliModel ?? null,
99
103
  ...buildContextFields({ mode, prContext, localContext, user }),
100
104
  };
101
105
  }
package/src/main.js CHANGED
@@ -235,7 +235,7 @@ OPTIONS:
235
235
  opus-4.7-xhigh, opus-4.7-high, opus-4.6-high,
236
236
  opus-4.6-1m, sonnet-5-xhigh, sonnet-5-high,
237
237
  sonnet-4.6
238
- (opus is Opus 4.8 XHigh, the default)
238
+ (default is opus-5-high; opus is Opus 4.8 XHigh)
239
239
  or use provider-specific models with Antigravity/Codex
240
240
  --provider <name> Override the AI provider for headless modes
241
241
  (--ai-draft / --ai-review). Defaults to the
@@ -21,6 +21,8 @@ const ws = require('../ws');
21
21
  const { fireHooks, hasHooks } = require('../hooks/hook-runner');
22
22
  const { buildChatStartedPayload, buildChatResumedPayload, buildChatHookContext, getCachedUser } = require('../hooks/payloads');
23
23
  const { resolveFormat } = require('../utils/comment-formatter');
24
+ const { getAllChatProviders, getAllCachedChatAvailability } = require('../chat/chat-providers');
25
+ const { getChatModelCatalog, canonicalChatModel } = require('../chat/chat-models');
24
26
  const { resolveLoadSkills } = require('../config');
25
27
 
26
28
  /**
@@ -31,16 +33,17 @@ const { resolveLoadSkills } = require('../config');
31
33
  * @param {Object} opts.review - Review record
32
34
  * @param {number} opts.sessionId - Chat session ID
33
35
  * @param {string} opts.provider - AI provider
34
- * @param {string} opts.model - AI model
36
+ * @param {string} opts.model - Model selector stored on the session
37
+ * @param {string|null} [opts.cliModel] - Model string actually passed to the CLI
35
38
  */
36
- function fireChatHook(event, { req, review, sessionId, provider, model }) {
39
+ function fireChatHook(event, { req, review, sessionId, provider, model, cliModel }) {
37
40
  const config = req.app.get('config') || {};
38
41
  if (!hasHooks(event, config)) return;
39
42
 
40
43
  const buildPayload = event === 'chat.started' ? buildChatStartedPayload : buildChatResumedPayload;
41
44
  getCachedUser(config).then(user => {
42
45
  const payload = buildPayload({
43
- reviewId: review.id, sessionId, provider, model,
46
+ reviewId: review.id, sessionId, provider, model, cliModel,
44
47
  ...buildChatHookContext(review), user,
45
48
  });
46
49
  fireHooks(event, payload, config);
@@ -243,6 +246,38 @@ async function getRepoLoadSkillsForChat(db, review, config, provider) {
243
246
  return resolveLoadSkills(config, review.repository, repoSettings, providerLoadSkills);
244
247
  }
245
248
 
249
+ /**
250
+ * List chat providers with their model catalogs.
251
+ *
252
+ * Kept separate from GET /api/config (which is fetched inline in the page head and
253
+ * should stay light). The response is picker-facing only: catalog entries are built by
254
+ * getChatModelCatalog, which whitelists display fields, so cli_model / env / extra_args
255
+ * never reach the browser.
256
+ */
257
+ router.get('/api/chat/providers', (req, res) => {
258
+ try {
259
+ const availability = getAllCachedChatAvailability();
260
+ const providers = getAllChatProviders().map((def) => {
261
+ const { models, configuredModel, hasCatalog } = getChatModelCatalog(def.id, def);
262
+ return {
263
+ id: def.id,
264
+ name: def.name,
265
+ type: def.type,
266
+ available: availability[def.id]?.available || false,
267
+ models,
268
+ configuredModel,
269
+ // Defined at the source as "there is something to pick from" (models.length > 0),
270
+ // so a provider that maps to a review provider with an empty list reports false.
271
+ hasCatalog,
272
+ };
273
+ });
274
+ res.json({ data: { providers } });
275
+ } catch (error) {
276
+ logger.error(`Error listing chat providers: ${error.message}`);
277
+ res.status(500).json({ error: 'Failed to list chat providers' });
278
+ }
279
+ });
280
+
246
281
  /**
247
282
  * Create a new chat session
248
283
  */
@@ -258,6 +293,15 @@ router.post('/api/chat/session', async (req, res) => {
258
293
  });
259
294
  }
260
295
 
296
+ // `model` is optional. Absent/null both mean "provider default"; anything else must
297
+ // be a string. Unknown ids are allowed on purpose — chat_providers.<id>.model has
298
+ // always accepted raw CLI strings, and the resolver passes them through.
299
+ if (model !== undefined && model !== null && typeof model !== 'string') {
300
+ return res.status(400).json({
301
+ error: 'Invalid model: must be a string or null'
302
+ });
303
+ }
304
+
261
305
  const chatSessionManager = req.app.chatSessionManager;
262
306
  const db = req.app.get('db');
263
307
 
@@ -353,9 +397,19 @@ router.post('/api/chat/session', async (req, res) => {
353
397
  // Register broadcast listeners so events reach all connected clients
354
398
  registerChatBroadcast(chatSessionManager, session.id, serverPort);
355
399
 
356
- fireChatHook('chat.started', { req, review, sessionId: session.id, provider, model });
400
+ fireChatHook('chat.started', {
401
+ req, review, sessionId: session.id, provider,
402
+ // The manager resolved the effective selector (request model > provider config
403
+ // default); fall back to the request value if a caller returns the legacy shape.
404
+ model: session.model !== undefined ? session.model : (model ?? null),
405
+ cliModel: session.cliModel ?? null,
406
+ });
357
407
 
358
- const responseData = { id: session.id, status: session.status };
408
+ // `model` is the canonicalised selector the session actually runs (an alias resolves
409
+ // to its catalog id, and a "Provider default" pick that config pinned to a concrete
410
+ // model comes back as that model). The client adopts it so its tab state matches the
411
+ // DB without waiting for a reload. Contract: string | null (null = provider default).
412
+ const responseData = { id: session.id, status: session.status, model: session.model ?? null };
359
413
 
360
414
  // Include analysis context metadata so the frontend can show a context indicator
361
415
  if (initialContext && suggestions && suggestions.length > 0) {
@@ -423,12 +477,16 @@ router.post('/api/chat/session/:id/message', async (req, res) => {
423
477
  const loadSkills = await getRepoLoadSkillsForChat(db, review, config, session.provider);
424
478
 
425
479
  try {
426
- await chatSessionManager.resumeSession(sessionId, { systemPrompt, cwd, loadSkills });
480
+ const resumed = await chatSessionManager.resumeSession(sessionId, { systemPrompt, cwd, loadSkills });
427
481
  unregisterChatBroadcast(sessionId);
428
482
  registerChatBroadcast(chatSessionManager, sessionId, req.socket.localPort);
429
483
  logger.info(`[ChatRoute] Auto-resumed session ${sessionId} for message delivery`);
430
484
 
431
- fireChatHook('chat.resumed', { req, review, sessionId, provider: session.provider, model: session.model });
485
+ fireChatHook('chat.resumed', {
486
+ req, review, sessionId, provider: session.provider,
487
+ model: resumed?.model !== undefined ? resumed.model : session.model,
488
+ cliModel: resumed?.cliModel ?? null,
489
+ });
432
490
 
433
491
  // Inject port correction so the agent knows the current server address,
434
492
  // even if the conversational history has a stale port from session creation.
@@ -535,7 +593,14 @@ router.post('/api/chat/session/:id/resume', async (req, res) => {
535
593
 
536
594
  // Already active
537
595
  if (chatSessionManager.isSessionActive(sessionId)) {
538
- return res.json({ data: { id: sessionId, status: 'active' } });
596
+ const active = chatSessionManager.getSession(sessionId);
597
+ return res.json({
598
+ data: {
599
+ id: sessionId,
600
+ status: 'active',
601
+ model: active ? canonicalChatModel(active.provider, active.model) : null,
602
+ },
603
+ });
539
604
  }
540
605
 
541
606
  const session = chatSessionManager.getSession(sessionId);
@@ -565,7 +630,7 @@ router.post('/api/chat/session/:id/resume', async (req, res) => {
565
630
  const cwd = await resolveReviewCwd(db, review);
566
631
  const loadSkills = await getRepoLoadSkillsForChat(db, review, config, session.provider);
567
632
 
568
- await chatSessionManager.resumeSession(sessionId, { systemPrompt, cwd, loadSkills });
633
+ const resumed = await chatSessionManager.resumeSession(sessionId, { systemPrompt, cwd, loadSkills });
569
634
  unregisterChatBroadcast(sessionId);
570
635
  const serverPort = req.socket.localPort;
571
636
  registerChatBroadcast(chatSessionManager, sessionId, serverPort);
@@ -580,9 +645,13 @@ router.post('/api/chat/session/:id/resume', async (req, res) => {
580
645
 
581
646
  logger.info(`[ChatRoute] Explicitly resumed session ${sessionId}`);
582
647
 
583
- fireChatHook('chat.resumed', { req, review, sessionId, provider: session.provider, model: session.model });
648
+ fireChatHook('chat.resumed', {
649
+ req, review, sessionId, provider: session.provider,
650
+ model: resumed?.model !== undefined ? resumed.model : session.model,
651
+ cliModel: resumed?.cliModel ?? null,
652
+ });
584
653
 
585
- res.json({ data: { id: sessionId, status: 'active' } });
654
+ res.json({ data: { id: sessionId, status: 'active', model: resumed?.model ?? null } });
586
655
  } catch (error) {
587
656
  logger.error(`Error resuming chat session: ${error.message}`);
588
657
  res.status(500).json({ error: 'Failed to resume session: ' + error.message });
@@ -620,8 +689,11 @@ router.get('/api/review/:reviewId/chat/sessions', (req, res) => {
620
689
  const sessions = chatSessionManager.getSessionsWithMessageCount(parseInt(reviewId, 10));
621
690
 
622
691
  // Annotate each session with live state
692
+ // `model` is canonicalised on read (rows are never rewritten): a session stored
693
+ // under an alias by an older build must report the id the picker renders.
623
694
  const annotated = sessions.map((s) => ({
624
695
  ...s,
696
+ model: canonicalChatModel(s.provider, s.model),
625
697
  isActive: chatSessionManager.isSessionActive(s.id),
626
698
  isResumable: !chatSessionManager.isSessionActive(s.id) && !!s.agent_session_id
627
699
  }));