@@ -9,44 +9,29 @@ final class AgentDetector
99 public static function detect (): AgentResult
1010 {
1111 $ aiAgent = getenv ('AI_AGENT ' );
12+
1213 if (is_string ($ aiAgent ) && trim ($ aiAgent ) !== '' ) {
1314 return new AgentResult (true , trim ($ aiAgent ));
1415 }
1516
16- if (getenv ('CURSOR_TRACE_ID ' ) !== false ) {
17- return new AgentResult (true , 'cursor ' );
18- }
19-
20- if (getenv ('CURSOR_AGENT ' ) !== false ) {
21- return new AgentResult (true , 'cursor-cli ' );
22- }
23-
24- if (getenv ('GEMINI_CLI ' ) !== false ) {
25- return new AgentResult (true , 'gemini ' );
26- }
27-
28- if (getenv ('CODEX_SANDBOX ' ) !== false || getenv ('CODEX_THREAD_ID ' ) !== false ) {
29- return new AgentResult (true , 'codex ' );
30- }
31-
32- if (getenv ('AUGMENT_AGENT ' ) !== false ) {
33- return new AgentResult (true , 'augment-cli ' );
34- }
35-
36- if (getenv ('OPENCODE_CLIENT ' ) !== false || getenv ('OPENCODE ' ) !== false ) {
37- return new AgentResult (true , 'opencode ' );
38- }
39-
40- if (getenv ('AMP_CURRENT_THREAD_ID ' ) !== false ) {
41- return new AgentResult (true , 'amp ' );
42- }
43-
44- if (getenv ('CLAUDECODE ' ) !== false || getenv ('CLAUDE_CODE ' ) !== false ) {
45- return new AgentResult (true , 'claude ' );
46- }
47-
48- if (getenv ('REPL_ID ' ) !== false ) {
49- return new AgentResult (true , 'replit ' );
17+ $ agentsWithEnvVars = [
18+ 'cursor ' => ['CURSOR_TRACE_ID ' ],
19+ 'cursor-cli ' => ['CURSOR_AGENT ' ],
20+ 'gemini ' => ['GEMINI_CLI ' ],
21+ 'codex ' => ['CODEX_SANDBOX ' , 'CODEX_THREAD_ID ' ],
22+ 'augment-cli ' => ['AUGMENT_AGENT ' ],
23+ 'opencode ' => ['OPENCODE_CLIENT ' , 'OPENCODE ' ],
24+ 'amp ' => ['AMP_CURRENT_THREAD_ID ' ],
25+ 'claude ' => ['CLAUDECODE ' , 'CLAUDE_CODE ' ],
26+ 'replit ' => ['REPL_ID ' ],
27+ ];
28+
29+ foreach ($ agentsWithEnvVars as $ agent => $ envVars ) {
30+ foreach ($ envVars as $ envVar ) {
31+ if (getenv ($ envVar ) !== false ) {
32+ return new AgentResult (true , $ agent );
33+ }
34+ }
5035 }
5136
5237 if (file_exists ('/opt/.devin ' )) {
0 commit comments