@@ -216,16 +216,17 @@ def generate_openai_commit_message(diff, style, scope = nil, retry_attempt = nil
216216 "6. Be descriptive but concise\n " \
217217 "7. Do not include a period at the end"
218218 when "conventional"
219- "You are a commit message generator that MUST follow the conventional commit format: <type>(<scope>): <description>\n " \
220- "Valid types are: #{ commit_types } \n " \
221- "Rules:\n " \
222- "1. ALWAYS start with a type from the list above\n " \
223- "2. ALWAYS use the exact format <type>(<scope>): <description>\n " \
224- "3. Keep the message under 72 characters\n " \
225- "4. Use lowercase\n " \
226- "5. Use present tense\n " \
227- "6. Be descriptive but concise\n " \
228- "7. Do not include a period at the end"
219+ "You are a commit message generator that MUST follow these rules EXACTLY:\n " \
220+ "1. ONLY output a single line containing the commit message\n " \
221+ "2. Use format: <type>(<scope>): <description>\n " \
222+ "3. Valid types are: #{ commit_types } \n " \
223+ "4. Keep under 72 characters\n " \
224+ "5. Use lowercase\n " \
225+ "6. Use present tense\n " \
226+ "7. Be descriptive but concise\n " \
227+ "8. No period at the end\n " \
228+ "9. NO explanations or additional text\n " \
229+ "10. NO markdown formatting"
229230 else
230231 "You are an expert in writing clear and concise git commit messages..."
231232 end
@@ -277,16 +278,17 @@ def generate_claude_commit_message(diff, style, scope = nil, retry_attempt = nil
277278 "6. Be descriptive but concise\n " \
278279 "7. Do not include a period at the end"
279280 when "conventional"
280- "You are a commit message generator that MUST follow the conventional commit format: <type>(<scope>): <description>\n " \
281- "Valid types are: #{ commit_types } \n " \
282- "Rules:\n " \
283- "1. ALWAYS start with a type from the list above\n " \
284- "2. ALWAYS use the exact format <type>(<scope>): <description>\n " \
285- "3. Keep the message under 72 characters\n " \
286- "4. Use lowercase\n " \
287- "5. Use present tense\n " \
288- "6. Be descriptive but concise\n " \
289- "7. Do not include a period at the end"
281+ "You are a commit message generator that MUST follow these rules EXACTLY:\n " \
282+ "1. ONLY output a single line containing the commit message\n " \
283+ "2. Use format: <type>(<scope>): <description>\n " \
284+ "3. Valid types are: #{ commit_types } \n " \
285+ "4. Keep under 72 characters\n " \
286+ "5. Use lowercase\n " \
287+ "6. Use present tense\n " \
288+ "7. Be descriptive but concise\n " \
289+ "8. No period at the end\n " \
290+ "9. NO explanations or additional text\n " \
291+ "10. NO markdown formatting"
290292 else
291293 "You are an expert in writing clear and concise git commit messages..."
292294 end
@@ -353,7 +355,8 @@ def handle_response(response)
353355 case response . code
354356 when 200
355357 json = JSON . parse ( response . body . to_s )
356- # puts "Debug - API Response: #{json.inspect}"
358+ puts "\n Debug - API Response: #{ json . inspect } "
359+
357360 case @settings . get ( :ai_provider )
358361 when "openai"
359362 message = json . dig ( "choices" , 0 , "message" , "content" )
@@ -362,7 +365,9 @@ def handle_response(response)
362365 raise Error , "No message content in response"
363366 end
364367
368+ # puts "Debug - OpenAI message: #{message}"
365369 message . split ( "\n " ) . first . strip
370+
366371 when "claude"
367372 content = json . dig ( "content" , 0 , "text" )
368373 # puts "Debug - Claude content: #{content.inspect}"
@@ -372,14 +377,16 @@ def handle_response(response)
372377 raise Error , "No message content in response"
373378 end
374379
375- lines = content . split ( " \n " ) . map ( & :strip ) . reject ( & :empty? )
376- # puts "Debug - Lines: #{lines.inspect}"
380+ # Extract the first actual commit message from the response
381+ commit_message = content . scan ( /(?:feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(?: \( [^)]+ \) )?:.*/ ) &. first
377382
378- message = lines . first
379-
380- raise Error , "No valid commit message found in response" if message . nil? || !message . match? ( /^[a-z]+:/ )
383+ if commit_message . nil?
384+ # puts "Debug - No valid commit message pattern found in content"
385+ raise Error , "No valid commit message found in response"
386+ end
381387
382- message
388+ # puts "Debug - Extracted commit message: #{commit_message}"
389+ commit_message . strip
383390 end
384391 when 401
385392 raise APIKeyError , "Invalid API key" unless ENV [ "RACK_ENV" ] == "test"
0 commit comments