VOOZH about

URL: https://deepwiki.com/invokable/laravel-boost-copilot-cli/4.3-service-provider-integration

⇱ Service Provider Integration | invokable/laravel-boost-copilot-cli | DeepWiki


Loading...
Last indexed: 7 March 2026 (397730)
Menu

Service Provider Integration

Purpose and Scope

This document explains how CopilotCliServiceProvider integrates the laravel-boost-copilot-cli package with the Laravel application and the Laravel Boost framework. The service provider is responsible for registering the CopilotCli agent with Laravel Boost and handling environment-specific path configurations when running under Orchestra Testbench.

For details about the CopilotCli agent itself, see CopilotCli Agent Class. For information about how the MCP protocol is implemented, see MCP Protocol Integration. For testing within the Testbench environment, see Testing with Orchestra Testbench.

Service Provider Overview

The CopilotCliServiceProvider class extends Laravel's ServiceProvider base class and serves as the integration point between the package and the Laravel application. It performs two primary functions:

  1. Agent Registration: Registers the CopilotCli agent with Laravel Boost's agent registry
  2. Testbench Path Correction: Adjusts application paths when running within Orchestra Testbench

Service Provider Location and Structure

AspectDetails
Class NameRevolution\Laravel\Boost\CopilotCliServiceProvider
Base ClassIlluminate\Support\ServiceProvider
File Locationsrc/CopilotCliServiceProvider.php1-44
Registration Methodboot()
DependenciesLaravel\Boost\Boost, Illuminate\Console\Events\CommandStarting

Sources: src/CopilotCliServiceProvider.php1-44

Agent Registration Process

The primary responsibility of the service provider is to register the CopilotCli agent with Laravel Boost's agent registry during the boot() phase.


Agent Registration Call

The registration occurs in the boot() method via a single static method call:


Registration Parameters

ParameterValuePurpose
Agent ID'copilot-cli'String identifier used in boost.json configuration
Agent ClassCopilotCli::classFully qualified class name Revolution\Laravel\Boost\CopilotCli

This registration makes the CopilotCli agent available when Laravel Boost processes the boost.json configuration file. The agent ID 'copilot-cli' corresponds to entries in the agents array of the configuration.

Sources: src/CopilotCliServiceProvider.php16-23 tests/Feature/CopilotCliServiceProviderTest.php8-13

Testbench Path Correction

When running under Orchestra Testbench, the package implements a path correction mechanism to handle differences between a full Laravel application and the Testbench skeleton environment.


Detection of Testbench Environment

The service provider detects the Testbench environment by checking for the TESTBENCH_CORE constant:


This constant is defined by Orchestra Testbench when the package runs in a testing environment. When detected, the testbench() method is invoked to set up path corrections.

Event-Based Path Correction

The path correction uses Laravel's event system to intercept commands before they execute:

Event Listener Registration

ComponentValue
Event ClassIlluminate\Console\Events\CommandStarting
Registration MethodEvent::listen()
Targeted Commandsboost:install, boost:update
TimingBefore command execution

Path Correction Operations

The listener performs three path adjustments:

  1. Base Path: Changes from Testbench skeleton to current working directory

    
    
  2. Storage Path: Points to Testbench skeleton's storage directory

    
    
  3. App Path: Points to Testbench skeleton's app directory

    
    

Why Path Correction is Required

Orchestra Testbench creates a minimal Laravel application skeleton in a temporary location. However, when running boost:install or boost:update commands, the package needs to:

  • Generate files in the actual package directory (current working directory), not the Testbench skeleton
  • Access certain Laravel paths from the Testbench skeleton (like storage and app directories)

The path correction balances these requirements by setting the base path to the real package directory while maintaining references to Testbench's infrastructure directories.

Sources: src/CopilotCliServiceProvider.php20-42

Method Reference

boot(): void

The main service provider boot method that performs all initialization logic.

Execution Flow:


Location: src/CopilotCliServiceProvider.php16-23

Responsibilities:

  • Registers CopilotCli agent with Laravel Boost
  • Conditionally invokes Testbench path corrections

testbench(): void

Protected method that sets up event listeners for path correction in Testbench environments.

Location: src/CopilotCliServiceProvider.php28-42

Event Listener Logic:

ConditionAction
Command is boost:installApply path corrections
Command is boost:updateApply path corrections
Any other commandNo action taken

Path Correction Details:


Helper Function Used:

  • Orchestra\Testbench\default_skeleton_path() - Returns path to Testbench skeleton directory

Sources: src/CopilotCliServiceProvider.php28-42

Integration with Laravel Boost

The service provider enables seamless integration with the Laravel Boost framework by participating in its agent registry system.


Discovery and Registration Flow

  1. Package Discovery: Laravel's package auto-discovery locates the service provider via composer.json
  2. Service Provider Boot: Laravel calls boot() during application bootstrapping
  3. Agent Registration: Boost::registerAgent() stores the agent class reference
  4. Command Availability: Boost commands can instantiate the agent when needed

Agent Accessibility

Once registered, the CopilotCli agent becomes accessible through:

  • Boost Commands: Commands like boost:install, boost:update, and boost:mcp can instantiate the agent
  • Agent Registry: The static method Boost::getAgents() returns all registered agents
  • Configuration Processing: The boost.json file references the agent by its ID 'copilot-cli'

Sources: src/CopilotCliServiceProvider.php16-23 tests/Feature/CopilotCliServiceProviderTest.php8-13

Testing and Verification

The package includes a feature test that verifies the service provider correctly registers the agent.

Test Implementation

The test validates agent registration by querying the Boost agent registry:


Test Verification Points

AssertionPurpose
toHaveKey('copilot-cli')Confirms agent ID is registered
toBe(CopilotCli::class)Verifies correct class is mapped to ID

Test Execution Context

The test runs in an Orchestra Testbench environment, which means:

  • The Testbench path corrections are active
  • The TESTBENCH_CORE constant is defined
  • Event listeners for CommandStarting are registered

This validates that both the agent registration and Testbench integration work correctly.

Sources: tests/Feature/CopilotCliServiceProviderTest.php1-14

Package Auto-Discovery Configuration

The service provider is automatically discovered by Laravel through the composer.json configuration:


This configuration eliminates the need for manual provider registration in the consuming application's config/app.php file.

Auto-Discovery Benefits

BenefitDescription
Zero ConfigurationNo manual provider registration required
Automatic LoadingProvider loads on every application boot
Testbench CompatibleWorks in both full applications and Testbench
Standard PracticeFollows Laravel package conventions

Sources: src/CopilotCliServiceProvider.php1-44

Code Quality and Standards

The service provider follows strict code quality standards enforced by Laravel Pint:

Coding Standards Applied

RuleConfigurationPurpose
preset"laravel"Follows Laravel coding conventions
strict_comparisontrueRequires === and !== operators
declare_strict_typestrueEnforces strict type declarations
no_unused_importsfalseAllows unused imports (disabled)

The service provider includes declare(strict_types=1) at the top of the file, ensuring type safety throughout the class.

Sources: src/CopilotCliServiceProvider.php3 pint.json1-9