fix: prioritize settings model over ANTHROPIC_MODEL env var and improve bun executable resolution

- Swap model resolution priority so user's explicit model selection via /login takes precedence over ANTHROPIC_MODEL environment variable
- Use process.execPath instead of hardcoded 'bun'/'bun.exe' for more reliable executable resolution across installation methods
- Disable biome formatter
This commit is contained in:
Askhz 2026-04-14 11:35:03 +08:00
parent 48d64ccd23
commit ccd135c4ed
2 changed files with 11 additions and 8 deletions

View File

@ -53,9 +53,10 @@ const inspectArgs = process.env.BUN_INSPECT
? ["--inspect-wait=" + process.env.BUN_INSPECT] ? ["--inspect-wait=" + process.env.BUN_INSPECT]
: []; : [];
// Use the bun executable from PATH - on Windows, Bun CLI registers 'bun' command // Use process.execPath to get the absolute path of the currently running Bun
// which resolves to bun.exe. Using 'bun' directly works on all platforms. // executable. This works regardless of how Bun was installed (native installer,
const bunCmd = process.platform === 'win32' ? 'bun.exe' : 'bun'; // npm, etc.) and on all platforms.
const bunCmd = process.execPath;
const result = Bun.spawnSync( const result = Bun.spawnSync(
[bunCmd, ...inspectArgs, "run", ...defineArgs, ...featureArgs, cliPath, ...process.argv.slice(2)], [bunCmd, ...inspectArgs, "run", ...defineArgs, ...featureArgs, cliPath, ...process.argv.slice(2)],

View File

@ -65,8 +65,8 @@ export function isNonCustomOpusModel(model: ModelName): boolean {
* Priority order within this function: * Priority order within this function:
* 1. Model override during session (from /model command) - highest priority * 1. Model override during session (from /model command) - highest priority
* 2. Model override at startup (from --model flag) * 2. Model override at startup (from --model flag)
* 3. ANTHROPIC_MODEL environment variable * 3. Settings (from user's saved settings) - includes model selected via /login
* 4. Settings (from user's saved settings) * 4. ANTHROPIC_MODEL environment variable
*/ */
export function getUserSpecifiedModelSetting(): ModelSetting | undefined { export function getUserSpecifiedModelSetting(): ModelSetting | undefined {
let specifiedModel: ModelSetting | undefined let specifiedModel: ModelSetting | undefined
@ -76,7 +76,9 @@ export function getUserSpecifiedModelSetting(): ModelSetting | undefined {
specifiedModel = modelOverride specifiedModel = modelOverride
} else { } else {
const settings = getSettings_DEPRECATED() || {} const settings = getSettings_DEPRECATED() || {}
specifiedModel = process.env.ANTHROPIC_MODEL || settings.model || undefined // Settings.model takes precedence over ANTHROPIC_MODEL env var
// This ensures user's explicit model selection via /login is respected
specifiedModel = settings.model || process.env.ANTHROPIC_MODEL || undefined
} }
// Ignore the user-specified model if it's not in the availableModels allowlist. // Ignore the user-specified model if it's not in the availableModels allowlist.
@ -93,8 +95,8 @@ export function getUserSpecifiedModelSetting(): ModelSetting | undefined {
* Model Selection Priority Order: * Model Selection Priority Order:
* 1. Model override during session (from /model command) - highest priority * 1. Model override during session (from /model command) - highest priority
* 2. Model override at startup (from --model flag) * 2. Model override at startup (from --model flag)
* 3. ANTHROPIC_MODEL environment variable * 3. Settings (from user's saved settings) - includes model selected via /login
* 4. Settings (from user's saved settings) * 4. ANTHROPIC_MODEL environment variable
* 5. Built-in default * 5. Built-in default
* *
* @returns The resolved model name to use * @returns The resolved model name to use