From d5652de63423ebad7afe8f8a428c271d29edb427 Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Thu, 8 Jan 2026 16:55:14 -0500 Subject: [PATCH] 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 --- src/cliproxy/cliproxy-executor.ts | 18 ++++++++++-------- src/cliproxy/config-generator.ts | 10 +++++++++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/cliproxy/cliproxy-executor.ts b/src/cliproxy/cliproxy-executor.ts index 1c2bc4d7..c8161dc7 100644 --- a/src/cliproxy/cliproxy-executor.ts +++ b/src/cliproxy/cliproxy-executor.ts @@ -337,14 +337,16 @@ export async function execClaudeWithCLIProxy( } else { // Fall back to --thinking value format const thinkingIdx = argsWithoutProxy.indexOf('--thinking'); - if ( - thinkingIdx !== -1 && - argsWithoutProxy[thinkingIdx + 1] && - // W4: Intentionally block negative numbers (negative budgets don't make sense) - // Values starting with '-' are treated as next flag, not a negative number - !argsWithoutProxy[thinkingIdx + 1].startsWith('-') - ) { - const val = argsWithoutProxy[thinkingIdx + 1]; + if (thinkingIdx !== -1) { + const nextArg = argsWithoutProxy[thinkingIdx + 1]; + // U1: Check if --thinking has a value (not missing or another flag) + if (!nextArg || nextArg.startsWith('-')) { + console.error(fail('--thinking requires a value')); + console.error(' Examples: --thinking low, --thinking 8192, --thinking off'); + console.error(' Levels: minimal, low, medium, high, xhigh, auto'); + process.exit(1); + } + const val = nextArg; // Parse as number if numeric, otherwise keep as string (level name) const numVal = parseInt(val, 10); thinkingOverride = !isNaN(numVal) ? numVal : val; diff --git a/src/cliproxy/config-generator.ts b/src/cliproxy/config-generator.ts index a80e68f1..9d43d520 100644 --- a/src/cliproxy/config-generator.ts +++ b/src/cliproxy/config-generator.ts @@ -110,7 +110,15 @@ export function applyThinkingConfig( // Get base model to check thinking support const baseModel = result.ANTHROPIC_MODEL || ''; 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