https://github.com/invokable/laravel-copilot-sdk
Laravel version of GitHub Copilot CLI SDK
https://github.com/invokable/laravel-copilot-sdk
copilot-cli copilot-sdk laravel
Last synced: 19 days ago
JSON representation
Laravel version of GitHub Copilot CLI SDK
- Host: GitHub
- URL: https://github.com/invokable/laravel-copilot-sdk
- Owner: invokable
- License: mit
- Created: 2026-01-20T23:48:31.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2026-02-18T00:45:53.000Z (about 1 month ago)
- Last Synced: 2026-02-18T04:53:16.272Z (about 1 month ago)
- Topics: copilot-cli, copilot-sdk, laravel
- Language: PHP
- Homepage: https://packagist.org/packages/revolution/laravel-copilot-sdk
- Size: 391 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GitHub Copilot CLI SDK for Laravel
[](https://github.com/invokable/laravel-copilot-sdk/actions/workflows/tests.yml)
[](https://qlty.sh/gh/invokable/projects/laravel-copilot-sdk)
[](https://qlty.sh/gh/invokable/projects/laravel-copilot-sdk)
[](https://deepwiki.com/invokable/laravel-copilot-sdk)
This package is Laravel version of [GitHub Copilot CLI SDK](https://github.com/github/copilot-sdk), which allows you to interact with GitHub Copilot CLI programmatically from your Laravel applications.
## Requirements
- PHP >= 8.4
- Laravel >= 12.x
- [Copilot CLI](https://github.com/github/copilot-cli) Latest version
## Installation
```shell
composer require revolution/laravel-copilot-sdk
```
Optional operation
### .env (Optional)
```dotenv
COPILOT_CLI_PATH=copilot
```
### TCP Mode (Optional)
Instead of starting a new CLI process for each request, you can connect to an existing Copilot CLI server running in TCP mode. This is useful for:
- Laravel Forge/Cloud deployments with background process management
- Sharing a single CLI instance across multiple Laravel processes
- Better performance with persistent connections
Start the Copilot CLI server:
```shell
copilot --headless --port 12345
```
Configure your `.env`:
```dotenv
COPILOT_URL=127.0.0.1:12345
```
When `COPILOT_URL` is set, the SDK will connect to the existing server instead of starting a new CLI process.
### Publish config (Optional)
```shell
php artisan vendor:publish --tag=copilot-config
```
### Uninstall
```shell
composer remove revolution/laravel-copilot-sdk
```
## Getting Started
[Getting Started Guide](./docs/getting-started.md)
## Usage
We provide a high-level API that uses a Laravel Facade on top of a layer that replicates the official SDK.
This should be sufficient for general use.
Artisan commands, controllers, jobs... the SDK can be used anywhere in Laravel where you can invoke the Copilot CLI.
### Run single prompt
```php
use Revolution\Copilot\Facades\Copilot;
$response = Copilot::run(prompt: 'Tell me something about Laravel.');
dump($response->content());
```
### Multiple prompts in a single session
```php
use Revolution\Copilot\Contracts\CopilotSession;
use Revolution\Copilot\Facades\Copilot;
$content = Copilot::start(function (CopilotSession $session) {
dump('Starting Copilot session: '.$session->id());
$response = $session->sendAndWait(prompt: 'Tell me something about PHP.');
dump($response->content());
$response = $session->sendAndWait(prompt: 'Tell me something about Laravel.');
dump($response->content());
return $response->content();
});
dump($content);
```
### `copilot()` helper
Alternatively, you can use the `copilot()` helper function.
```php
// Don't forget to import the function
use function Revolution\Copilot\copilot;
// If you specify a prompt as a string, it is the same as Copilot::run().
$response = copilot('Tell me something about Laravel.');
// If you pass a closure, it is the same as Copilot::start().
copilot(function (CopilotSession $session) {
$response = $session->sendAndWait(prompt: 'Tell me something about PHP.');
});
// If you don't pass anything, it's the same as Facade.
dump(copilot()->client()->ping());
```
For more than simple use, use the Copilot Facade above.
## Testing
Provide Laravel way testing support with `Copilot::fake()`.
### Copilot::fake()
`Copilot::fake()` is a mock for features used from the Copilot Facade. Other features are not mocked.
```php
use Revolution\Copilot\Facades\Copilot;
Copilot::fake('2');
$response = Copilot::run(prompt: '1 + 1');
// Pest
expect($response->content())->toBe('2');
// PHPUnit
$this->assertEquals('2', $response->content());
```
When calling multiple times with Copilot::start()
```php
use Revolution\Copilot\Facades\Copilot;
use Revolution\Copilot\Contracts\CopilotSession;
Copilot::fake([
'*' => Copilot::sequence()
->push(Copilot::response('2'))
->push(Copilot::response('4')),
]);
Copilot::start(function (CopilotSession $session) use (&$response1, &$response2) {
$response1 = $session->sendAndWait(prompt: '1 + 1');
$response2 = $session->sendAndWait(prompt: '2 + 2');
});
expect($response1->content())->toBe('2');
```
### Assertions
Assert that a specific prompt was called.
```php
Copilot::assertPrompt('1 + *');
```
Assert that a prompt was not called.
```php
Copilot::assertNotPrompt('1 + *');
```
Assert the number of prompts called.
```php
Copilot::assertPromptCount(3);
```
Assert that no prompts were called.
```php
Copilot::assertNothingSent();
```
### Prevent stray requests
Prevent all JSON-RPC requests. If called, an exception `Revolution\Copilot\Exceptions\StrayRequestException` is thrown.
```php
Copilot::preventStrayRequests();
```
When you want to allow only some commands.
```php
Copilot::preventStrayRequests(allow: ['ping']);
```
Stop prevention.
```php
Copilot::preventStrayRequests(false);
```
Only JSON-RPC requests are prevented, so starting a client is not prevented.
## Documentation
Most of the English documentation is included in the official SDK, so we won't provide much here. README and [Getting Started Guide](./docs/getting-started.md) are provided in English.
Only Japanese documentation is available in [docs/jp](./docs/jp). **Ask Copilot!!**
## Our other packages
- [laravel-boost-copilot-cli](https://github.com/invokable/laravel-boost-copilot-cli)
- [laravel-boost-phpstorm-copilot](https://github.com/invokable/laravel-boost-phpstorm-copilot)
## License
MIT