Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Install/CodeEnvironment/ClaudeCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function systemDetectionConfig(Platform $platform): array
{
return match ($platform) {
Platform::Darwin, Platform::Linux => [
'command' => 'which claude',
'command' => 'command -v claude',
],
Platform::Windows => [
'command' => 'where claude 2>null',
Expand Down
31 changes: 25 additions & 6 deletions src/Install/CodeEnvironment/CodeEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public function mcpConfigKey(): string
return 'mcpServers';
}

/** @return array<string, mixed> */
public function newMcpConfig(): array
{
return [];
}

/**
* Install MCP server using the appropriate strategy.
*
Expand Down Expand Up @@ -174,17 +180,30 @@ protected function installFileMcp(string $key, string $command, array $args = []

$config = File::exists($path)
? json_decode(File::get($path), true) ?: []
: [];
: $this->newMcpConfig();

$mcpKey = $this->mcpConfigKey();
data_set($config, "{$mcpKey}.{$key}", collect([
'command' => $command,
'args' => $args,
'env' => $env,
])->filter()->toArray());
$mcpConfig = $this->buildMcpConfig($command, $args, $env);
data_set($config, "{$mcpKey}.{$key}", $mcpConfig);

$json = json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);

return $json && File::put($path, $json);
}

/**
* Build MCP config array.
*
* @param array<int, string> $args
* @param array<string, string> $env
* @return array<string, mixed>
*/
protected function buildMcpConfig(string $command, array $args = [], array $env = []): array
{
return collect([
'command' => $command,
'args' => $args,
'env' => $env,
])->filter()->toArray();
}
}
81 changes: 81 additions & 0 deletions src/Install/CodeEnvironment/OpenCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

declare(strict_types=1);

namespace Laravel\Boost\Install\CodeEnvironment;

use Laravel\Boost\Contracts\Agent;
use Laravel\Boost\Contracts\McpClient;
use Laravel\Boost\Install\Enums\McpInstallationStrategy;
use Laravel\Boost\Install\Enums\Platform;

class OpenCode extends CodeEnvironment implements Agent, McpClient
{
public function name(): string
{
return 'opencode';
}

public function displayName(): string
{
return 'opencode'; // intentional
}

public function systemDetectionConfig(Platform $platform): array
{
return match ($platform) {
Platform::Darwin, Platform::Linux => [
'command' => 'command -v opencode',
],
Platform::Windows => [
'command' => 'where opencode 2>null',
],
};
}

public function projectDetectionConfig(): array
{
return [
'files' => ['AGENTS.md', 'opencode.json'],
];
}

public function mcpInstallationStrategy(): McpInstallationStrategy
{
return McpInstallationStrategy::FILE;
}

public function mcpConfigPath(): string
{
return 'opencode.json';
}

public function guidelinesPath(): string
{
return 'AGENTS.md';
}

public function mcpConfigKey(): string
{
return 'mcp';
}

/** @inheritDoc */
public function newMcpConfig(): array
{
return [
'$schema' => 'https://opencode.ai/config.json',
];
}

/** @inheritDoc */
protected function buildMcpConfig(string $command, array $args = [], array $env = []): array
{
return collect([
'type' => 'local',
'enabled' => true,
'command' => [$command, ...$args],
'env' => $env,
])->filter()->toArray();
}
}
2 changes: 1 addition & 1 deletion src/Install/CodeEnvironment/VSCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function systemDetectionConfig(Platform $platform): array
'paths' => ['/Applications/Visual Studio Code.app'],
],
Platform::Linux => [
'command' => 'which code',
'command' => 'command -v code',
],
Platform::Windows => [
'paths' => [
Expand Down
2 changes: 2 additions & 0 deletions src/Install/CodeEnvironmentsDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Laravel\Boost\Install\CodeEnvironment\CodeEnvironment;
use Laravel\Boost\Install\CodeEnvironment\Copilot;
use Laravel\Boost\Install\CodeEnvironment\Cursor;
use Laravel\Boost\Install\CodeEnvironment\OpenCode;
use Laravel\Boost\Install\CodeEnvironment\PhpStorm;
use Laravel\Boost\Install\CodeEnvironment\VSCode;
use Laravel\Boost\Install\Enums\Platform;
Expand All @@ -23,6 +24,7 @@ class CodeEnvironmentsDetector
'cursor' => Cursor::class,
'claudecode' => ClaudeCode::class,
'copilot' => Copilot::class,
'opencode' => OpenCode::class,
];

public function __construct(
Expand Down
16 changes: 16 additions & 0 deletions tests/Unit/Install/CodeEnvironmentsDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
$container->bind(\Laravel\Boost\Install\CodeEnvironment\VSCode::class, fn () => $program2);
$container->bind(\Laravel\Boost\Install\CodeEnvironment\Cursor::class, fn () => $program3);
$container->bind(\Laravel\Boost\Install\CodeEnvironment\ClaudeCode::class, fn () => $otherProgram);
$container->bind(\Laravel\Boost\Install\CodeEnvironment\OpenCode::class, fn () => $otherProgram);
$container->bind(\Laravel\Boost\Install\CodeEnvironment\Copilot::class, fn () => $otherProgram);

$detector = new CodeEnvironmentsDetector($container);
Expand All @@ -64,6 +65,7 @@
$container->bind(\Laravel\Boost\Install\CodeEnvironment\VSCode::class, fn () => $otherProgram);
$container->bind(\Laravel\Boost\Install\CodeEnvironment\Cursor::class, fn () => $otherProgram);
$container->bind(\Laravel\Boost\Install\CodeEnvironment\ClaudeCode::class, fn () => $otherProgram);
$container->bind(\Laravel\Boost\Install\CodeEnvironment\OpenCode::class, fn () => $otherProgram);
$container->bind(\Laravel\Boost\Install\CodeEnvironment\Copilot::class, fn () => $otherProgram);

$detector = new CodeEnvironmentsDetector($container);
Expand Down Expand Up @@ -174,6 +176,20 @@
rmdir($tempDir);
});

test('discoverProjectInstalledCodeEnvironments detects opencode with file', function (string $file) {
$tempDir = sys_get_temp_dir().'/boost_test_'.uniqid();
mkdir($tempDir);
file_put_contents($tempDir.'/'.$file, 'test');

$detected = $this->detector->discoverProjectInstalledCodeEnvironments($tempDir);

expect($detected)->toContain('opencode');

// Cleanup
unlink($tempDir.'/'.$file);
rmdir($tempDir);
})->with(['AGENTS.md', 'opencode.json']);

test('discoverProjectInstalledCodeEnvironments detects phpstorm with idea directory', function () {
$tempDir = sys_get_temp_dir().'/boost_test_'.uniqid();
mkdir($tempDir);
Expand Down