laravel/pao
Agent-optimized output for PHP tools. Auto-detects AI agents (Claude Code, Cursor, Devin, Gemini CLI) and replaces verbose PHPUnit/Pest/Paratest/PHPStan output with minimal structured JSON; cleans Laravel Artisan output too. Zero config; human output unchanged.
Installation:
composer require laravel/pao --dev
First Use Case:
phpunit, pest, phpstan, or artisan) in an AI agent environment (e.g., Claude Code, Cursor, or Gemini CLI).Where to Look First:
php artisan about) by stripping ANSI colors and decorations.Testing Workflows:
php artisan test # Outputs structured JSON in AI agents, raw output locally
vendor/bin/pest # Same behavior
vendor/bin/phpstan analyse app --level=max
Output includes errors, error_details (with file paths and line numbers), and a capped list of 30 errors.Laravel Artisan:
php artisan migrate:status # Compact JSON output in AI agents
php artisan db:show # Stripped of ANSI colors and decorations
about, db:show, migrate:status, etc. (see release/v0.1.3).Parallel Testing:
--parallel) are supported, but raw output (e.g., dots for progress) is captured in a raw array in JSON.Pest Plugins:
--coverage or --profile is included in the raw array of the JSON response.Local Development:
Custom Tools:
pao.php config file (see Gotchas).CI/CD Pipelines:
# Example GitHub Actions step
- run: php artisan test
env:
AI_AGENT: "true" # Optional: Force PAO activation (if agent detection fails)
Laravel Service Provider:
PAOServiceProvider in Laravel. No manual registration needed.Agent Detection:
laravel/agent-detector to identify AI agents.pao.php config:
// config/pao.php
return [
'agents' => [
'CustomAgent/1.0', // Add your agent's user-agent string
],
];
php artisan pao:debug
Exit Codes:
1 for test failures). Ensure your AI agent handles non-zero exits gracefully.Parallel Testing Quirks:
...) into the raw array. This is expected and stripped of ANSI codes.Artisan Command Limitations:
app/Providers/PAOServiceProvider.php.PHPStan Error Capping:
error_details to debug specific issues.Verify PAO Activation:
php artisan pao:debug
Outputs the detected agent and PAO status.Raw Output Leaks:
raw arrays contain unwanted ANSI codes or decorations, update PAO’s cleaning logic in:
vendor/laravel/pao/src/Tools/ArtisanTool.php
(Note: This is a vendor file; consider forking PAO for custom changes.)Missing Tool Support:
Token Optimization:
Structured Data:
$output = json_decode(file_get_contents('php://stdout'), true);
if ($output['result'] === 'failed') {
// Trigger alerts or rollback logic
}
Local Testing:
HTTP_USER_AGENT environment variable:
HTTP_USER_AGENT="Claude Code/1.0" php artisan test
Extending PAO:
Tool class (e.g., CustomTool) and registering it in PAOServiceProvider.$this->app->bind('pao.tools.custom', function () {
return new CustomTool();
});
Performance:
How can I help you explore Laravel packages today?