fix(sdk): honor Codex model overrides in init progress

This commit is contained in:
Tom Boucher
2026-05-10 17:40:11 -04:00
committed by GitHub
parent 19295f5ab6
commit 52337a8861
5 changed files with 118 additions and 6 deletions

View File

@@ -24,7 +24,13 @@ import { planningPaths } from './helpers.js';
import { maskIfSecret } from './secrets.js';
import type { QueryHandler } from './utils.js';
export { MODEL_PROFILES, VALID_PROFILES, getAgentToModelMapForProfile } from '../model-catalog.js';
import { MODEL_PROFILES, VALID_PROFILES, getAgentToModelMapForProfile } from '../model-catalog.js';
import {
AGENT_TO_PHASE_TYPE,
MODEL_PROFILES,
VALID_PROFILES,
getAgentToModelMapForProfile,
resolveRuntimeTierDefault,
} from '../model-catalog.js';
// ─── configGet ──────────────────────────────────────────────────────────────
@@ -114,6 +120,40 @@ export const configPath: QueryHandler = async (_args, projectDir, workstream) =>
// ─── resolveModel ───────────────────────────────────────────────────────────
type RuntimeTierName = 'opus' | 'sonnet' | 'haiku';
interface RuntimeTierEntry {
model?: string;
reasoning_effort?: string;
}
function isRuntimeTierName(value: string): value is RuntimeTierName {
return value === 'opus' || value === 'sonnet' || value === 'haiku';
}
function normalizeRuntimeTierEntry(entry: unknown): RuntimeTierEntry | null {
if (typeof entry === 'string') return { model: entry };
if (entry && typeof entry === 'object' && !Array.isArray(entry)) {
return entry as RuntimeTierEntry;
}
return null;
}
function resolveRuntimeTier(config: Record<string, unknown>, tier: string): RuntimeTierEntry | null {
if (!isRuntimeTierName(tier)) return null;
const runtime = typeof config.runtime === 'string' ? config.runtime : '';
if (!runtime || runtime === 'claude') return null;
const builtin = resolveRuntimeTierDefault(runtime, tier);
const profileOverrides = config.model_profile_overrides as Record<string, unknown> | undefined;
const runtimeOverrides = profileOverrides?.[runtime] as Record<string, unknown> | undefined;
const userEntry = normalizeRuntimeTierEntry(runtimeOverrides?.[tier]);
if (!builtin && !userEntry) return null;
return { ...(builtin ?? {}), ...(userEntry ?? {}) };
}
/**
* Query handler for resolve-model command.
*
@@ -149,10 +189,11 @@ export const resolveModel: QueryHandler = async (args, projectDir, workstream) =
return { data: result };
}
// No project config (or explicit omit policy) -> return empty model id (CJS parity)
const agentModels = MODEL_PROFILES[agentType];
// No project config -> return empty model id (CJS parity)
const resolveModelIds = (config as Record<string, unknown>).resolve_model_ids;
if (!configExists || resolveModelIds === 'omit') {
const agentModels = MODEL_PROFILES[agentType];
if (!configExists) {
const result = agentModels
? { model: '', profile }
: { model: '', profile, unknown_agent: true };
@@ -160,7 +201,6 @@ export const resolveModel: QueryHandler = async (args, projectDir, workstream) =
}
// Fall back to profile lookup
const agentModels = MODEL_PROFILES[agentType];
if (!agentModels) {
const semanticFallback =
profile === 'quality' ? 'opus'
@@ -175,5 +215,19 @@ export const resolveModel: QueryHandler = async (args, projectDir, workstream) =
}
const alias = agentModels[profile] || agentModels['balanced'] || 'sonnet';
const phaseType = AGENT_TO_PHASE_TYPE[agentType];
const phaseTier = phaseType && typeof (config as Record<string, unknown>).models === 'object'
? ((config as Record<string, unknown>).models as Record<string, unknown>)[phaseType]
: undefined;
const tier = typeof phaseTier === 'string' ? phaseTier : alias;
const runtimeTier = resolveRuntimeTier(config as Record<string, unknown>, tier);
if (runtimeTier?.model) {
return { data: { model: runtimeTier.model, profile } };
}
if (resolveModelIds === 'omit') {
return { data: { model: '', profile } };
}
return { data: { model: alias, profile } };
};