diff --git a/src/Command/AgentDetector.php b/src/Command/AgentDetector.php new file mode 100644 index 0000000000..a9fec967cf --- /dev/null +++ b/src/Command/AgentDetector.php @@ -0,0 +1,31 @@ +getContainer()->getParameter('errorFormat'); } + $container = $inceptionResult->getContainer(); + + if ($errorFormat === null && AgentDetector::isAgentDetected()) { + $errorFormat = 'raw'; + } + if ($errorFormat === null) { $errorFormat = 'table'; } - $container = $inceptionResult->getContainer(); $errorFormatterServiceName = sprintf('errorFormatter.%s', $errorFormat); if (!$container->hasService($errorFormatterServiceName)) { $errorOutput->writeLineFormatted(sprintf( diff --git a/src/Command/ErrorsConsoleStyle.php b/src/Command/ErrorsConsoleStyle.php index 18301f5ab8..43149240d9 100644 --- a/src/Command/ErrorsConsoleStyle.php +++ b/src/Command/ErrorsConsoleStyle.php @@ -32,7 +32,8 @@ final class ErrorsConsoleStyle extends SymfonyStyle public function __construct(InputInterface $input, OutputInterface $output) { parent::__construct($input, $output); - $this->showProgress = $input->hasOption(self::OPTION_NO_PROGRESS) && !(bool) $input->getOption(self::OPTION_NO_PROGRESS); + $showProgress = $input->hasOption(self::OPTION_NO_PROGRESS) && !(bool) $input->getOption(self::OPTION_NO_PROGRESS); + $this->showProgress = $showProgress && !AgentDetector::isAgentDetected(); } private function isCiDetected(): bool @@ -95,9 +96,10 @@ public function createProgressBar(int $max = 0): ProgressBar } $ci = $this->isCiDetected(); - $this->progressBar->setOverwrite(!$ci); + $agent = AgentDetector::isAgentDetected(); + $this->progressBar->setOverwrite(!$ci && !$agent); - if ($ci) { + if ($ci || $agent) { $this->progressBar->minSecondsBetweenRedraws(15); $this->progressBar->maxSecondsBetweenRedraws(30); } elseif (DIRECTORY_SEPARATOR === '\\') { diff --git a/tests/PHPStan/Command/AgentDetectorTest.php b/tests/PHPStan/Command/AgentDetectorTest.php new file mode 100644 index 0000000000..0db56d22ad --- /dev/null +++ b/tests/PHPStan/Command/AgentDetectorTest.php @@ -0,0 +1,77 @@ +assertFalse(AgentDetector::isAgentDetected()); + } + + public function testReturnsTrueWithAiAgent(): void + { + putenv('AI_AGENT=test'); + $this->assertTrue(AgentDetector::isAgentDetected()); + } + + public function testReturnsFalseWithEmptyAiAgent(): void + { + putenv('AI_AGENT='); + $this->assertFalse(AgentDetector::isAgentDetected()); + } + + public function testReturnsTrueWithClaudeCode(): void + { + putenv('CLAUDE_CODE=1'); + $this->assertTrue(AgentDetector::isAgentDetected()); + } + + public function testReturnsTrueWithCursorTraceId(): void + { + putenv('CURSOR_TRACE_ID=abc'); + $this->assertTrue(AgentDetector::isAgentDetected()); + } + + public function testReturnsTrueWithReplitAgent(): void + { + putenv('REPLIT_AGENT=1'); + $this->assertTrue(AgentDetector::isAgentDetected()); + } + +}