fix(cliproxy): improve thinking flag validation and warnings

- U1: reject --thinking with no value (show usage hint)

- U2: warn when provider doesn't support thinking budget
This commit is contained in:
kaitranntt
2026-01-08 16:55:14 -05:00
parent 3ea549addd
commit d5652de634
2 changed files with 19 additions and 9 deletions
+10 -8
View File
@@ -337,14 +337,16 @@ export async function execClaudeWithCLIProxy(
} else { } else {
// Fall back to --thinking value format // Fall back to --thinking value format
const thinkingIdx = argsWithoutProxy.indexOf('--thinking'); const thinkingIdx = argsWithoutProxy.indexOf('--thinking');
if ( if (thinkingIdx !== -1) {
thinkingIdx !== -1 && const nextArg = argsWithoutProxy[thinkingIdx + 1];
argsWithoutProxy[thinkingIdx + 1] && // U1: Check if --thinking has a value (not missing or another flag)
// W4: Intentionally block negative numbers (negative budgets don't make sense) if (!nextArg || nextArg.startsWith('-')) {
// Values starting with '-' are treated as next flag, not a negative number console.error(fail('--thinking requires a value'));
!argsWithoutProxy[thinkingIdx + 1].startsWith('-') console.error(' Examples: --thinking low, --thinking 8192, --thinking off');
) { console.error(' Levels: minimal, low, medium, high, xhigh, auto');
const val = argsWithoutProxy[thinkingIdx + 1]; process.exit(1);
}
const val = nextArg;
// Parse as number if numeric, otherwise keep as string (level name) // Parse as number if numeric, otherwise keep as string (level name)
const numVal = parseInt(val, 10); const numVal = parseInt(val, 10);
thinkingOverride = !isNaN(numVal) ? numVal : val; thinkingOverride = !isNaN(numVal) ? numVal : val;
+9 -1
View File
@@ -110,7 +110,15 @@ export function applyThinkingConfig(
// Get base model to check thinking support // Get base model to check thinking support
const baseModel = result.ANTHROPIC_MODEL || ''; const baseModel = result.ANTHROPIC_MODEL || '';
if (!supportsThinking(provider, baseModel)) { if (!supportsThinking(provider, baseModel)) {
return result; // Model doesn't support thinking // U2: Warn user if they explicitly provided --thinking but model doesn't support it
if (thinkingOverride !== undefined && thinkingConfig.show_warnings !== false) {
console.warn(
warn(
`Model ${baseModel || 'unknown'} (provider: ${provider}) does not support thinking budget. --thinking flag ignored.`
)
);
}
return result;
} }
// Determine thinking value to use // Determine thinking value to use