forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgentDetectedErrorFormatter.php
More file actions
53 lines (45 loc) · 1.33 KB
/
AgentDetectedErrorFormatter.php
File metadata and controls
53 lines (45 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php declare(strict_types = 1);
namespace PHPStan\Command\ErrorFormatter;
use PHPStan\Command\AnalysisResult;
use PHPStan\Command\Output;
use PHPStan\DependencyInjection\AutowiredParameter;
use PHPStan\DependencyInjection\AutowiredService;
use function file_exists;
use function getenv;
use function is_string;
use function trim;
/**
* @api
*/
#[AutowiredService(as: AgentDetectedErrorFormatter::class)]
final class AgentDetectedErrorFormatter implements ErrorFormatter
{
public function __construct(
#[AutowiredParameter(ref: '@errorFormatter.json')]
private JsonErrorFormatter $jsonErrorFormatter,
)
{
}
public function isAgentDetected(): bool
{
$aiAgent = getenv('AI_AGENT');
if (is_string($aiAgent) && trim($aiAgent) !== '') {
return true;
}
return getenv('CURSOR_TRACE_ID') !== false
|| getenv('CURSOR_AGENT') !== false
|| getenv('GEMINI_CLI') !== false
|| getenv('CODEX_SANDBOX') !== false
|| getenv('AUGMENT_AGENT') !== false
|| getenv('OPENCODE_CLIENT') !== false
|| getenv('OPENCODE') !== false
|| getenv('CLAUDECODE') !== false
|| getenv('CLAUDE_CODE') !== false
|| getenv('REPL_ID') !== false
|| file_exists('/opt/.devin');
}
public function formatErrors(AnalysisResult $analysisResult, Output $output): int
{
return $this->jsonErrorFormatter->formatErrors($analysisResult, $output);
}
}