Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Agent Detector Laravel Package

ergebnis/agent-detector

Detect the presence of coding agents in your PHP app by checking environment variables. Supports Amp, Antigravity, Augment, Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, and more via a simple Detector::isAgentPresent() API.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Lightweight & Non-Invasive: The package leverages environment variable inspection (no runtime hooks, no database calls, no external APIs), making it ideal for Laravel middleware, service containers, or event listeners.
  • Extensible: Supports a generic AI_AGENT variable, allowing future-proofing for unknown agents without forking the package.
  • Stateless: Pure function (isAgentPresent()) ensures thread safety in concurrent Laravel requests (critical for high-traffic APIs).
  • Laravel Synergy:
    • Can be injected into service providers (e.g., AppServiceProvider::boot()) for global agent detection.
    • Works seamlessly with Laravel’s Request object (via $_SERVER or getenv()).
    • Compatible with Laravel’s caching layer (e.g., cache isAgentPresent() results for repeated requests).

Integration Feasibility

  • Zero Framework Dependencies: Pure PHP 8.2+ (Laravel 9+ compatible), no Composer conflicts with existing packages.
  • Middleware Integration:
    namespace App\Http\Middleware;
    use Ergebnis\AgentDetector\Detector;
    class DetectAgentMiddleware {
        public function handle($request, Closure $next) {
            $detector = new Detector();
            if ($detector->isAgentPresent($_SERVER)) {
                // Block, rate-limit, or log
            }
            return $next($request);
        }
    }
    
  • Service Container Binding:
    $app->bind(Detector::class, fn() => new Detector());
    
    Then inject Detector into controllers/services via constructor DI.
  • Event Listeners: Trigger custom events (e.g., AgentDetected) when an agent is present.

Technical Risk

Risk Area Mitigation Strategy
False Positives Test with real-world agent environments (e.g., GitHub Actions, Copilot CLI).
Performance Overhead Cache results in Laravel’s cache layer (e.g., Cache::remember()).
PHP Version Support Drop PHP 7.4/8.0 (EOL) and standardize on PHP 8.2+ for long-term support.
Agent Coverage Gaps Extend the Detector class or submit PRs for missing agents (e.g., Perplexity).
Dependency Bloat No transitive dependencies—safe for monolithic apps.

Key Questions

  1. Use Case Priority:
    • Is this for fraud prevention, feature gating, or CI/CD optimization? (Prioritize testing accordingly.)
  2. False Positive Tolerance:
    • Can the team accept legitimate tools (e.g., VS Code extensions) being flagged as agents?
  3. Integration Scope:
    • Should this be global middleware, selective route protection, or event-driven?
  4. Maintenance Plan:
    • Will the team monitor for new agent variables (e.g., future AI tools) or rely on upstream updates?
  5. Performance Baseline:
    • Benchmark isAgentPresent() in high-traffic endpoints (should be <1ms for most cases).

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Middleware: Ideal for global bot detection (e.g., app/Http/Kernel.php).
    • Service Container: Reusable across controllers/services.
    • Events: Trigger custom logic (e.g., AgentDetected event with agent type).
    • Testing: Mock $_SERVER/getenv() in PHPUnit for unit tests.
  • Non-Laravel PHP:
    • Works in Slim, Symfony, or standalone scripts (minimal boilerplate).
  • CI/CD Pipelines:
    • Detect Copilot/Replit agents to optimize pipeline steps (e.g., skip tests for bot traffic).

Migration Path

  1. Phase 1: Proof of Concept
    • Add to composer.json:
      "require": {
          "ergebnis/agent-detector": "^1.2"
      }
      
    • Test in a non-production environment with known agent traffic (e.g., GitHub Actions).
  2. Phase 2: Middleware Integration
    • Register middleware in app/Http/Kernel.php:
      protected $middleware = [
          \App\Http\Middleware\DetectAgentMiddleware::class,
      ];
      
  3. Phase 3: Feature Gating
    • Extend middleware to block/redirect based on agent presence:
      if ($detector->isAgentPresent($_SERVER)) {
          abort(403, 'Agent traffic not allowed.');
      }
      
  4. Phase 4: Event-Driven Extensions
    • Dispatch custom events (e.g., AgentDetected) for analytics or logging.

Compatibility

Component Compatibility Notes
Laravel Works with Laravel 9+ (PHP 8.1+). Test with Lumen if using micro-framework.
PHP Extensions No dependencies beyond PHP core.
Environment Docker/Kubernetes: Ensure agent env vars (e.g., COPILOT_CLI) propagate.
Caching Cache results in Redis/Memcached for high-throughput apps.
Testing Mock $_SERVER in PHPUnit:
 ```php
 $_SERVER['COPILOT_CLI'] = 'true';
 $this->assertTrue($detector->isAgentPresent($_SERVER));
 ``` |

Sequencing

  1. Low-Risk First:
    • Start with logging agent presence (no blocking) to validate detection accuracy.
  2. Gradual Rollout:
    • Apply to non-critical endpoints (e.g., /docs, /api/public) before production APIs.
  3. A/B Testing:
    • Compare bot traffic metrics before/after integration (e.g., using Laravel Telescope).
  4. Post-Launch:
    • Monitor false positives (e.g., legitimate tools misclassified) and adjust env var checks.

Operational Impact

Maintenance

  • Upstream Dependencies:
    • No transitive dependencies—only PHP core required.
    • MIT License: No vendor lock-in; fork if needed.
  • Local Extensions:
    • Override Detector class to add custom agent checks (e.g., internal tools).
    • Example:
      class CustomDetector extends \Ergebnis\AgentDetector\Detector {
          protected function getAgentVariables(): array {
              return array_merge(parent::getAgentVariables(), ['MY_CUSTOM_AGENT']);
          }
      }
      
  • Version Updates:
    • SemVer-compliant: Backward-compatible minor updates (e.g., 1.2.x).
    • Deprecation Policy: Follow PHP’s EOL (e.g., drop PHP 8.1 support after Dec 2025).

Support

  • Limited Maintainer Support:
    • GitHub Issues: Use for bugs/feature requests (response time: ~days).
    • Community: Leverage ergebnis’ Twitter (@localheinz) for urgent questions.
  • Internal Runbooks:
    • Document common agent env vars (e.g., COPILOT_GITHUB_TOKEN) for debugging.
    • Create a troubleshooting guide for false positives (e.g., "Why is my CI pipeline flagged?").
  • Monitoring:
    • Log agent detections to Laravel Horizon or Sentry for observability.
    • Alert on unexpected agent spikes (e.g., sudden Copilot traffic).

Scaling

  • Performance:
    • O(1) complexity: Env var checks are constant-time.
    • Caching: Cache results for 1 minute in Redis to avoid repeated checks:
      $cacheKey = 'agent_detected_' . md5(serialize($_SERVER));
      return Cache::remember($cacheKey, now()->addMinute(), fn() => $detector->isAgentPresent($_SERVER));
      
  • High Traffic:
    • Load testing: Simulate 10K RPS to validate middleware latency (<5ms).
    • Edge Cases: Test with malformed env vars (e.g., null values).
  • Distributed Systems:
    • Microservices: Deploy detector in API gateways (e.g., Laravel Octane) to centralize checks.

Failure Modes

Failure Scenario Impact Mitigation Strategy
False Positives Legitimate traffic blocked Whitelist env vars (e.g., `ALLOWED_AGENTS = ['CURSOR_AGENT
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor