diff --git a/src/AI/GeminiFixer.php b/src/AI/GeminiFixer.php index 7ba4573..f4c4082 100644 --- a/src/AI/GeminiFixer.php +++ b/src/AI/GeminiFixer.php @@ -38,21 +38,15 @@ Error: {$violation->message} Severity: {$violation->severity->value} Standard: {$violation->standard->value} -Please provide ONLY the fixed version of the HTML snippet. -Do not explain, do not add markdown code blocks, just return the corrected HTML. -If the error is about missing 'alt' text, add a meaningful alt text based on context. -If it's about ARIA roles, add the correct ones. +Please provide a short explanation of the fix (in Turkish) and the fixed version of the HTML snippet. +Use the following EXACT format: +EXPLANATION: [A short explanation of what you fixed and why] +FIX: [Only the corrected HTML snippet] PROMPT; try { - // Stable model: gemini-1.5-flash - $result = $this->client->generativeModel('gemini-1.5-flash')->generateContent($prompt); - $suggestion = trim($result->text()); - - // Clean up if AI included markdown blocks anyway - $suggestion = preg_replace('/^```html\s*|\s*```$/i', '', $suggestion); - - return $suggestion; + $result = $this->client->generativeModel('gemini-2.5-flash')->generateContent($prompt); + return trim($result->text()); } catch (\Throwable $e) { return "AI Düzeltme Hatası: " . $e->getMessage(); } diff --git a/src/Console/Command/FixCommand.php b/src/Console/Command/FixCommand.php index 4cf6ad1..0fc8c6f 100644 --- a/src/Console/Command/FixCommand.php +++ b/src/Console/Command/FixCommand.php @@ -79,9 +79,17 @@ class FixCommand extends Command } // Get AI Suggestion - $suggestion = $fixer->suggestFix($violation); - if (!$suggestion) { - $io->writeln("Skipped (AI could not generate fix)"); + $rawSuggestion = $fixer->suggestFix($violation); + $suggestion = $rawSuggestion; + if ($rawSuggestion && str_contains($rawSuggestion, 'FIX:')) { + preg_match('/FIX:(.*)/s', $rawSuggestion, $matches); + $suggestion = trim($matches[1] ?? $rawSuggestion); + // Clean up potential markdown + $suggestion = preg_replace('/^```html\s*|\s*```$/i', '', $suggestion); + } + + if (!$suggestion || ($suggestion === $rawSuggestion && str_contains($suggestion, 'EXPLANATION:'))) { + $io->writeln("Skipped (AI could not generate a clean fix)"); continue; } diff --git a/src/Reporting/HtmlDashboardReporter.php b/src/Reporting/HtmlDashboardReporter.php index 23f5d0a..8c717e5 100644 --- a/src/Reporting/HtmlDashboardReporter.php +++ b/src/Reporting/HtmlDashboardReporter.php @@ -17,12 +17,29 @@ class HtmlDashboardReporter $rows = ''; foreach ($violations as $v) { $severityClass = strtolower($v->severity->value); + $aiSuggestion = $v->fixSuggestion; + $explanation = ''; + $fixedCode = ''; + + if ($aiSuggestion && str_contains($aiSuggestion, 'FIX:')) { + preg_match('/EXPLANATION:(.*)FIX:(.*)/s', $aiSuggestion, $matches); + $explanation = trim($matches[1] ?? ''); + $fixedCode = trim($matches[2] ?? ''); + // Clean up potential markdown + $fixedCode = preg_replace('/^```html\s*|\s*```$/i', '', $fixedCode); + } else { + $fixedCode = $aiSuggestion; + } + $rows .= " {$v->ruleId} {$v->message}
" . htmlspecialchars($v->htmlSnippet) . "
- " . ($v->fixSuggestion ? "
" . htmlspecialchars($v->fixSuggestion) . "
" : "Manual fix required") . " + + " . ($explanation ? "
Öneri: {$explanation}
" : "") . " + " . ($fixedCode ? "
" . htmlspecialchars($fixedCode) . "
" : "Manual fix required") . " + " . ($v->location ? "{$v->location['file']}:{$v->location['line']}" : 'N/A') . " "; } @@ -44,7 +61,8 @@ class HtmlDashboardReporter th, td { text-align: left; padding: 12px; border-bottom: 1px solid #eee; } th { background: #f8f9fa; } pre { background: #272822; color: #f8f8f2; padding: 10px; border-radius: 4px; overflow-x: auto; font-size: 12px; } - .ai-fix { border-left: 4px solid #2ecc71; background: #1e1e1e; } + .ai-explanation { margin-bottom: 8px; font-size: 13px; color: #27ae60; line-height: 1.4; } + .ai-fix { border-left: 4px solid #2ecc71; background: #1e1e1e; margin-top: 5px; } .badge { background: #34495e; color: white; padding: 4px 8px; border-radius: 4px; font-size: 11px; } .severity-error { background: #fff5f5; } .text-muted { color: #95a5a6; font-size: 0.9em; font-style: italic; }