Skip to content

Commit 0faef92

Browse files
authored
Add pi detection (#7)
1 parent 2648be0 commit 0faef92

4 files changed

Lines changed: 16 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ $result = detectAgent();
6161
| Replit | `REPL_ID` env var |
6262
| Devin | `/opt/.devin` file exists |
6363
| Antigravity | `ANTIGRAVITY_AGENT` env var |
64+
| Pi | `PI_CODING_AGENT` env var |
6465

6566
### Custom Agent
6667

src/AgentDetector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static function detect(): AgentResult
2525
'replit' => ['REPL_ID'],
2626
'copilot' => ['COPILOT_CLI'],
2727
'antigravity' => ['ANTIGRAVITY_AGENT'],
28+
'pi' => ['PI_CODING_AGENT'],
2829
];
2930

3031
foreach ($agentsWithEnvVars as $agent => $envVars) {

src/KnownAgent.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ enum KnownAgent: string
1717
case Amp = 'amp';
1818
case Copilot = 'copilot';
1919
case Antigravity = 'antigravity';
20+
case Pi = 'pi';
2021
}

tests/AgentDetectorTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'COPILOT_CLI',
2424
'REPL_ID',
2525
'ANTIGRAVITY_AGENT',
26+
'PI_CODING_AGENT',
2627
] as $var) {
2728
putenv($var);
2829
}
@@ -46,6 +47,7 @@
4647
'COPILOT_CLI',
4748
'REPL_ID',
4849
'ANTIGRAVITY_AGENT',
50+
'PI_CODING_AGENT',
4951
] as $var) {
5052
putenv($var);
5153
}
@@ -202,6 +204,16 @@
202204
->and($result->knownAgent())->toBe(KnownAgent::Antigravity);
203205
});
204206

207+
it('detects pi via PI_CODING_AGENT', function (): void {
208+
putenv('PI_CODING_AGENT=true');
209+
210+
$result = AgentDetector::detect();
211+
212+
expect($result->isAgent)->toBeTrue()
213+
->and($result->name)->toBe('pi')
214+
->and($result->knownAgent())->toBe(KnownAgent::Pi);
215+
});
216+
205217
// Devin detection via file_exists mock
206218
it('detects devin via /opt/.devin file', function (): void {
207219
$GLOBALS['__mock_file_exists'] = fn (string $path): bool => $path === '/opt/.devin';
@@ -317,6 +329,7 @@
317329
'claude' => ['CLAUDECODE', '1', KnownAgent::Claude],
318330
'replit' => ['REPL_ID', 'id', KnownAgent::Replit],
319331
'antigravity' => ['ANTIGRAVITY_AGENT', '1', KnownAgent::Antigravity],
332+
'pi' => ['PI_CODING_AGENT', 'true', KnownAgent::Pi],
320333
]);
321334

322335
it('returns null knownAgent for custom agent', function (): void {

0 commit comments

Comments
 (0)