[Mate] Consolidate .mate/ and mate/ directories into single mate/ directory

This commit is contained in:
Johannes Wachter
2025-12-22 13:53:21 +01:00
committed by Christopher Hertel
parent c1a2d853aa
commit a14abfce89
13 changed files with 46 additions and 45 deletions

View File

@@ -66,5 +66,7 @@ return (new PhpCsFixer\Config())
->append([__FILE__])
->exclude('var')
->notPath('demo/config/reference.php')
->notPath('src/mate/resources/mate/extensions.php')
->notPath('src/mate/resources/mate/config.php')
)
;

View File

@@ -74,10 +74,10 @@ The component includes embedded bridge packages:
- `LogReader`: Reads and filters log files
### Configuration
- `.mate/extensions.php`: Enable/disable extensions
- `.mate/config.php`: Custom service configuration
- `.mate/.env`: Environment variables for mate configuration
- `mate/`: Directory for user-defined MCP tools
- `mate/extensions.php`: Enable/disable extensions
- `mate/config.php`: Custom service configuration
- `mate/.env`: Environment variables for mate configuration
- `mate/src/`: Directory for user-defined MCP tools
## Testing Architecture

View File

@@ -69,7 +69,7 @@ class DiscoverCommand extends Command
return Command::SUCCESS;
}
$extensionsFile = $this->rootDir.'/.mate/extensions.php';
$extensionsFile = $this->rootDir.'/mate/extensions.php';
$existingExtensions = [];
$newPackages = [];
$removedPackages = [];
@@ -138,7 +138,7 @@ class DiscoverCommand extends Command
$io->comment([
'Next steps:',
' • Edit .mate/extensions.php to enable/disable specific extensions',
' • Edit mate/extensions.php to enable/disable specific extensions',
' • Run "vendor/bin/mate serve" to start the MCP server',
]);

View File

@@ -51,13 +51,13 @@ class InitCommand extends Command
$actions = [];
$mateDir = $this->rootDir.'/.mate';
$mateDir = $this->rootDir.'/mate';
if (!is_dir($mateDir)) {
mkdir($mateDir, 0755, true);
$actions[] = ['✓', 'Created', '.mate/ directory'];
$actions[] = ['✓', 'Created', 'mate/ directory'];
}
$files = ['.mate/extensions.php', '.mate/config.php', '.mate/.env', '.mate/.gitignore', 'mcp.json'];
$files = ['mate/extensions.php', 'mate/config.php', 'mate/.env', 'mate/.gitignore', 'mcp.json'];
foreach ($files as $file) {
$fullPath = $this->rootDir.'/'.$file;
if (!file_exists($fullPath)) {
@@ -91,13 +91,13 @@ class InitCommand extends Command
}
}
$mateUserDir = $this->rootDir.'/mate';
if (!is_dir($mateUserDir)) {
mkdir($mateUserDir, 0755, true);
file_put_contents($mateUserDir.'/.gitignore', '');
$actions[] = ['✓', 'Created', 'mate/ directory (for custom extensions)'];
$mateSrcDir = $this->rootDir.'/mate/src';
if (!is_dir($mateSrcDir)) {
mkdir($mateSrcDir, 0755, true);
file_put_contents($mateSrcDir.'/.gitkeep', '');
$actions[] = ['✓', 'Created', 'mate/src/ directory (for custom MCP tools)'];
} else {
$actions[] = ['○', 'Exists', 'mate/ directory'];
$actions[] = ['○', 'Exists', 'mate/src/ directory'];
}
$composerActions = $this->updateComposerJson();
@@ -112,7 +112,7 @@ class InitCommand extends Command
'Next steps:',
' 1. Run "composer dump-autoload" to update the autoloader',
' 2. Run "vendor/bin/mate discover" to find MCP extensions',
' 3. Add your custom MCP tools/resources/prompts to the mate/ directory',
' 3. Add your custom MCP tools/resources/prompts to the mate/src/ directory',
' 4. Run "vendor/bin/mate serve" to start the MCP server',
]);
@@ -171,7 +171,7 @@ class InitCommand extends Command
}
if (!isset($composerJson['autoload']['psr-4']['App\\Mate\\'])) {
$composerJson['autoload']['psr-4']['App\\Mate\\'] = 'mate/';
$composerJson['autoload']['psr-4']['App\\Mate\\'] = 'mate/src/';
$modified = true;
$actions[] = ['✓', 'Added', 'App\\Mate\\ autoloader'];
} else {

View File

@@ -67,7 +67,7 @@ final class ContainerFactory
*/
private function getEnabledExtensions(): array
{
$extensionsFile = $this->rootDir.'/.mate/extensions.php';
$extensionsFile = $this->rootDir.'/mate/extensions.php';
if (!file_exists($extensionsFile)) {
return [];
@@ -145,7 +145,7 @@ final class ContainerFactory
$logger = $container->get(LoggerInterface::class);
\assert($logger instanceof LoggerInterface);
$loader = new PhpFileLoader($container, new FileLocator($this->rootDir.'/.mate'));
$loader = new PhpFileLoader($container, new FileLocator($this->rootDir.'/mate'));
foreach ($rootProject['includes'] as $include) {
try {
$loader->load($include);

View File

@@ -31,7 +31,7 @@ class MateHelper
*
* Call this method only once. The second call will override the first one.
*
* Example usage in .mate/config.php:
* Example usage in mate/config.php:
* ```php
* use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
* use Symfony\AI\Mate\Container\MateHelper;

View File

@@ -43,9 +43,9 @@ final class DiscoverCommandTest extends TestCase
$tester->execute([]);
$this->assertSame(Command::SUCCESS, $tester->getStatusCode());
$this->assertFileExists($tempDir.'/.mate/extensions.php');
$this->assertFileExists($tempDir.'/mate/extensions.php');
$extensions = include $tempDir.'/.mate/extensions.php';
$extensions = include $tempDir.'/mate/extensions.php';
$this->assertIsArray($extensions);
$this->assertArrayHasKey('vendor/package-a', $extensions);
$this->assertArrayHasKey('vendor/package-b', $extensions);
@@ -53,7 +53,6 @@ final class DiscoverCommandTest extends TestCase
$this->assertIsArray($extensions['vendor/package-b']);
$this->assertTrue($extensions['vendor/package-a']['enabled']);
$this->assertTrue($extensions['vendor/package-b']['enabled']);
$output = $tester->getDisplay();
$this->assertStringContainsString('Discovered 2 Extension', $output);
$this->assertStringContainsString('vendor/package-a', $output);
@@ -66,11 +65,11 @@ final class DiscoverCommandTest extends TestCase
public function testPreservesExistingEnabledState()
{
$tempDir = sys_get_temp_dir().'/mate-discover-test-'.uniqid();
mkdir($tempDir.'/.mate', 0755, true);
mkdir($tempDir.'/mate', 0755, true);
try {
// Create existing extensions.php with package-a disabled
file_put_contents($tempDir.'/.mate/extensions.php', <<<'PHP'
file_put_contents($tempDir.'/mate/extensions.php', <<<'PHP'
<?php
return [
'vendor/package-a' => ['enabled' => false],
@@ -85,7 +84,7 @@ PHP
$tester->execute([]);
$extensions = include $tempDir.'/.mate/extensions.php';
$extensions = include $tempDir.'/mate/extensions.php';
$this->assertIsArray($extensions);
$this->assertIsArray($extensions['vendor/package-a']);
$this->assertIsArray($extensions['vendor/package-b']);
@@ -99,11 +98,11 @@ PHP
public function testNewPackagesDefaultToEnabled()
{
$tempDir = sys_get_temp_dir().'/mate-discover-test-'.uniqid();
mkdir($tempDir.'/.mate', 0755, true);
mkdir($tempDir.'/mate', 0755, true);
try {
// Create existing extensions.php with only package-a
file_put_contents($tempDir.'/.mate/extensions.php', <<<'PHP'
file_put_contents($tempDir.'/mate/extensions.php', <<<'PHP'
<?php
return [
'vendor/package-a' => ['enabled' => false],
@@ -117,7 +116,7 @@ PHP
$tester->execute([]);
$extensions = include $tempDir.'/.mate/extensions.php';
$extensions = include $tempDir.'/mate/extensions.php';
$this->assertIsArray($extensions);
$this->assertIsArray($extensions['vendor/package-a']);
$this->assertIsArray($extensions['vendor/package-b']);

View File

@@ -43,15 +43,15 @@ final class InitCommandTest extends TestCase
$tester->execute([]);
$this->assertSame(Command::SUCCESS, $tester->getStatusCode());
$this->assertDirectoryExists($this->tempDir.'/.mate');
$this->assertFileExists($this->tempDir.'/.mate/extensions.php');
$this->assertFileExists($this->tempDir.'/.mate/config.php');
$this->assertFileExists($this->tempDir.'/.mate/.env');
$this->assertDirectoryExists($this->tempDir.'/mate');
$this->assertFileExists($this->tempDir.'/mate/extensions.php');
$this->assertFileExists($this->tempDir.'/mate/config.php');
$this->assertFileExists($this->tempDir.'/mate/.env');
$this->assertFileExists($this->tempDir.'/mcp.json');
$this->assertTrue(is_link($this->tempDir.'/.mcp.json'));
$this->assertSame('mcp.json', readlink($this->tempDir.'/.mcp.json'));
$content = file_get_contents($this->tempDir.'/.mate/extensions.php');
$content = file_get_contents($this->tempDir.'/mate/extensions.php');
$this->assertIsString($content);
$this->assertStringContainsString('mate discover', $content);
$this->assertStringContainsString('enabled', $content);
@@ -79,15 +79,15 @@ final class InitCommandTest extends TestCase
$tester = new CommandTester($command);
// Create existing file
mkdir($this->tempDir.'/.mate', 0755, true);
file_put_contents($this->tempDir.'/.mate/extensions.php', '<?php return ["test" => "value"];');
mkdir($this->tempDir.'/mate', 0755, true);
file_put_contents($this->tempDir.'/mate/extensions.php', '<?php return ["test" => "value"];');
// Execute with 'no' response (twice for both files)
$tester->setInputs(['no', 'no']);
$tester->execute([]);
// File should still contain original content
$content = file_get_contents($this->tempDir.'/.mate/extensions.php');
$content = file_get_contents($this->tempDir.'/mate/extensions.php');
$this->assertIsString($content);
$this->assertStringContainsString('test', $content);
$this->assertStringContainsString('value', $content);
@@ -99,15 +99,15 @@ final class InitCommandTest extends TestCase
$tester = new CommandTester($command);
// Create existing file
mkdir($this->tempDir.'/.mate', 0755, true);
file_put_contents($this->tempDir.'/.mate/extensions.php', '<?php return ["test" => "value"];');
mkdir($this->tempDir.'/mate', 0755, true);
file_put_contents($this->tempDir.'/mate/extensions.php', '<?php return ["test" => "value"];');
// Execute with 'yes' response (twice for both files)
$tester->setInputs(['yes', 'yes']);
$tester->execute([]);
// File should be overwritten with template content
$content = file_get_contents($this->tempDir.'/.mate/extensions.php');
$content = file_get_contents($this->tempDir.'/mate/extensions.php');
$this->assertIsString($content);
$this->assertStringNotContainsString('test', $content);
$this->assertStringContainsString('mate discover', $content);
@@ -119,15 +119,15 @@ final class InitCommandTest extends TestCase
$command = new InitCommand($this->tempDir);
$tester = new CommandTester($command);
// Ensure .mate directory doesn't exist
$this->assertDirectoryDoesNotExist($this->tempDir.'/.mate');
// Ensure mate directory doesn't exist
$this->assertDirectoryDoesNotExist($this->tempDir.'/mate');
$tester->execute([]);
// Directory should be created
$this->assertDirectoryExists($this->tempDir.'/.mate');
$this->assertFileExists($this->tempDir.'/.mate/extensions.php');
$this->assertFileExists($this->tempDir.'/.mate/config.php');
$this->assertDirectoryExists($this->tempDir.'/mate');
$this->assertFileExists($this->tempDir.'/mate/extensions.php');
$this->assertFileExists($this->tempDir.'/mate/config.php');
}
private function removeDirectory(string $dir): void