diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts index 60276393..b68bd76f 100644 --- a/app/api/chat/route.ts +++ b/app/api/chat/route.ts @@ -113,14 +113,26 @@ function classifyTurnIntent(message: string): TurnIntent { ) return "status_check"; - // Conversational fallback — ONLY when the entire message is a greeting or a - // bare acknowledgement. Previously `/^(ok|...)/` matched "ok" as a prefix of - // "okay ", misclassifying real work as chat (budget 1) and - // causing round_cap cut-offs. Require the whole message to be the ack. + // Conversational: greetings, acknowledgements, and short pleasantries. + // By this point we've already matched action verbs, diagnostics, and + // questions, so anything that *starts* with a greeting/ack, or is a very + // short verb-less leftover, is chat — reply in text, don't run the agent + // loop. Note we still avoid the old `/^(ok)/` prefix bug: "okay is the auth + // connected up?" already returned `status_check` above (ends with "?"). + const wordCount = m.split(/\s+/).filter(Boolean).length; if ( - /^(hi|hey|hello|yo|thanks|thank you|ok|okay|kk|k|yes|yep|yeah|yup|no|nope|nah|sure|cool|nice|great|awesome|perfect)[\s!.?]*$/.test( + // Greetings (incl. multi-word: "hey there!", "good morning") + /^(hi|hey|hello|heya|hiya|yo|sup|howdy|greetings|good (morning|afternoon|evening|day))\b/.test( m, - ) + ) || + // Acknowledgements / pleasantries + /^(thanks|thank you|ty|ok|okay|kk|k|yes|yep|yeah|yup|no|nope|nah|sure|cool|nice|great|awesome|perfect|got it|sounds good|will do|nvm|never mind)\b/.test( + m, + ) || + /(what'?s up|how are you|how'?s it going|good to see you)/.test(m) || + // Very short, verb-less, non-question leftovers are ambiguous → treat as + // chat and let the model ask, rather than spinning up a 40-round build. + (wordCount <= 4 && m.length <= 30 && !m.endsWith("?")) ) return "conversational";