forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgentDetector.php
More file actions
54 lines (43 loc) · 974 Bytes
/
AgentDetector.php
File metadata and controls
54 lines (43 loc) · 974 Bytes
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
54
<?php declare(strict_types = 1);
namespace PHPStan\Internal;
use function file_exists;
use function getenv;
use function trim;
final class AgentDetector
{
public const ENV_VARS = [
'AUGMENT_AGENT',
'AMP_CURRENT_THREAD_ID',
'AI_AGENT',
'CURSOR_TRACE_ID',
'CURSOR_AGENT',
'GEMINI_CLI',
'CODEX_SANDBOX',
'CODEX_THREAD_ID',
'AUGMENT_AGENT',
'OPENCODE_CLIENT',
'OPENCODE',
'CLAUDECODE',
'CLAUDE_CODE',
'REPL_ID',
];
public static function isRunningInAgent(): bool
{
// Copyright (c) Pushpak Chhajed pushpak1300@gmail.com
// from https://github.com/shipfastlabs/agent-detector/blob/98766473b2dfe183b0c2605ceb04e587a78d1872/src/AgentDetector.php
foreach (self::ENV_VARS as $envVar) {
$value = getenv($envVar);
if ($value === false) {
continue;
}
if ($envVar === 'AI_AGENT' && trim($value) === '') {
continue;
}
return true;
}
if (@file_exists('/opt/.devin')) {
return true;
}
return false;
}
}