Add batched AI false positive detection with check-specific prompts#1278
Draft
davidperezgar wants to merge 9 commits intotrunkfrom
Draft
Add batched AI false positive detection with check-specific prompts#1278davidperezgar wants to merge 9 commits intotrunkfrom
davidperezgar wants to merge 9 commits intotrunkfrom
Conversation
…itives-in-plugin-checks
…itives-in-plugin-checks Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Closes #1106
Refactors the AI false positive detection system to use a batched, check-specific approach inspired by the internal scanner, replacing the previous one-issue-at-a-time implementation. Now uses WordPress 7.0 core AI client (
wp_ai_client_prompt()) instead of the oldSettings_Page/wp-ai-clientlibrary.Why?
The previous AI implementation analyzed each issue individually with a generic prompt, which was:
Settings_Page+\WordPress\AI_Client\AI_Clientapproach instead of WordPress 7.0 core AI.The internal scanner already solved this with batched requests and check-specific prompts — this PR brings that proven pattern to PCP.
How?
Refactored
AI_Analyzertrait (AI_Analyzer.php)WordPress.Security.EscapeOutput.*issues go together), then sent in batches of up to 12 cases per AI request.prompts/ai-review-*.mdthat describes the specific issue type and what constitutes a false positive.wp_ai_client_prompt()withusing_model_preference()— same pattern asAI_Check_Names.wp_plugin_check_ai_severity_thresholdfilter.>>>marker on the flagged line.New prompt templates (
prompts/ai-review-*.md)ai-review-late-escaping.mdWordPress.Security.EscapeOutput,PluginCheck.CodeAnalysis.EscapeOutputai-review-nonce-verification.mdWordPress.Security.NonceVerificationai-review-sanitization.mdWordPress.Security.ValidatedSanitizedInputai-review-direct-db-queries.mdWordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQLai-review-code-obfuscation.mdPluginCheck.CodeAnalysis.Obfuscationai-review-setting-sanitization.mdPluginCheck.CodeAnalysis.SettingSanitizationai-review-plugin-updater.mdPluginCheck.CodeAnalysis.PluginUpdaterai-review-generic.mdCLI enhancements (Plugin_Check_Command.php)
--ai-model=<model>option to select AI model (e.g.,openai::gpt-4o).display_ai_summary()method showing a formatted summary with ✨ markers for false positives.Runner updates (Abstract_Check_Runner.php)
Settings_Pagedependency.$ai_model_preferenceproperty andset_ai_model_preference()setter.analyze_results_with_ai().Testing Instructions
--use-aiflag — should behave exactly as before (no AI analysis).AI Usage Disclosure
If AI tools were used, please describe how they were used:
Used GitHub Copilot (Claude) to assist with the implementation of the batched AI analysis approach, prompt template creation, and CLI output formatting. The architecture and prompt content were designed based on the existing internal scanner implementation patterns.