Add AI agent detection to auto-switch to raw output#4939
Closed
pushpak1300 wants to merge 1 commit intophpstan:2.1.xfrom
Closed
Add AI agent detection to auto-switch to raw output#4939pushpak1300 wants to merge 1 commit intophpstan:2.1.xfrom
pushpak1300 wants to merge 1 commit intophpstan:2.1.xfrom
Conversation
Collaborator
|
This pull request has been marked as ready for review. |
Member
|
JSON is not good for LLM agents https://www.reddit.com/r/AI_Agents/comments/1p3kc7s/stop_burning_money_sending_json_to_your_agents/ |
Author
|
@ondrejmirtes Are you open for adding toon formatter ? happy to send the pr. |
Member
|
try the existing |
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.
This pull request adds AI agent detection that automatically switches PHPStan to raw error format and suppresses progress bar output when executed within Claude Code, Cursor, Gemini CLI, Codex, OpenCode, Augment, Replit, or Devin.
Why:
The default PHPStan output is designed for humans - colorful tables, progress bars with animations, and formatted summaries. AI agents need something different: minimal output that saves context window and reduces token cost, unambiguous error details with file paths and line numbers, and no progress bar animations that waste tokens on redraw noise.
Why raw format over JSON?
The raw format (
file:line:message, one error per line) is significantly more token-efficient than JSON:JSON carries structural overhead per error (repeated keys like
"message","line","ignorable","identifier", plus nesting and punctuation). The raw format eliminates all of this while preserving the essential information agents need: file path, line number, and error message.How it works:
CLAUDECODE/CLAUDE_CODEenvironment variableCURSOR_TRACE_ID/CURSOR_AGENTGEMINI_CLI,CODEX_SANDBOX,AI_AGENT, etc.)file:line:message)--no-progress)Detection is inlined (simple
getenv()calls) to avoid any external dependency and maintain compatibility with all PHP versions PHPStan supports.Output example:
Explicit
--error-format=tableor configerrorFormat: tablealways takes priority over agent detection.Changes:
AgentDetectedErrorFormatterclass (followsCiDetectedErrorFormatterpattern) — delegates toRawErrorFormatterAnalyseCommandto check for agents when no explicit format is setErrorsConsoleStyleto fully suppress progress bar for agents (no output at all, not just slower redraws)