File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace TicketSwap \PHPStanErrorFormatter ;
6+
7+ // Copied from https://github.com/shipfastlabs/agent-detector/blob/main/src/AgentDetector.php
8+ final class AgentDetector
9+ {
10+ public static function isAgent () : bool
11+ {
12+ $ aiAgent = getenv ('AI_AGENT ' );
13+
14+ if (is_string ($ aiAgent ) && trim ($ aiAgent ) !== '' ) {
15+ return true ;
16+ }
17+
18+ $ agentsWithEnvVars = [
19+ 'cursor ' => ['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 $ envVars ) {
30+ foreach ($ envVars as $ envVar ) {
31+ if (getenv ($ envVar ) !== false ) {
32+ return true ;
33+ }
34+ }
35+ }
36+
37+ if (file_exists ('/opt/.devin ' )) {
38+ return true ;
39+ }
40+
41+ return false ;
42+ }
43+ }
Original file line number Diff line number Diff line change @@ -169,7 +169,7 @@ public static function link(
169169 $ editorUrl ,
170170 ),
171171 '{relativePath} ' => $ relativePath ,
172- '{shortPath} ' => self ::trimPath ($ relativePath ),
172+ '{shortPath} ' => AgentDetector:: isAgent () ? $ relativePath : self ::trimPath ($ relativePath ),
173173 ':{line} ' => $ line === 0 ? '' : ': ' . $ line ,
174174 '{line} ' => $ line === 0 ? '' : (string ) $ line ,
175175 ],
Original file line number Diff line number Diff line change @@ -433,6 +433,31 @@ public function getWrites() : array
433433 };
434434 }
435435
436+ public function testLinkDoesNotTrimPathWhenAgent () : void
437+ {
438+ putenv ('AI_AGENT=1 ' );
439+
440+ try {
441+ $ result = TicketSwapErrorFormatter::link (
442+ TicketSwapErrorFormatter::LINK_FORMAT_DEFAULT ,
443+ 20 ,
444+ self ::isWindows () ? 'c:\www\project\src\Core\Admin\Controller\Dashboard\User\AddUserController.php ' : '/www/project/src/Core/Admin/Controller/Dashboard/User/AddUserController.php ' ,
445+ self ::isWindows () ? 'src\Core\Admin\Controller\Dashboard\User\AddUserController.php ' : 'src/Core/Admin/Controller/Dashboard/User/AddUserController.php ' ,
446+ self ::PHPSTORM_EDITOR_URL ,
447+ true ,
448+ );
449+
450+ $ expectedRelativePath = self ::isWindows ()
451+ ? 'src\Core\Admin\Controller\Dashboard\User\AddUserController.php '
452+ : 'src/Core/Admin/Controller/Dashboard/User/AddUserController.php ' ;
453+
454+ self ::assertStringContainsString ($ expectedRelativePath , $ result );
455+ self ::assertStringNotContainsString ('... ' , $ result );
456+ } finally {
457+ putenv ('AI_AGENT ' );
458+ }
459+ }
460+
436461 public function testFormatErrorsNoErrorsWritesNoErrorsAndReturnsZero () : void
437462 {
438463 $ analysisResult = new AnalysisResult (
You can’t perform that action at this time.
0 commit comments