[Mate] Ask for the PHP binary in init and support containerized setups#2271
[Mate] Ask for the PHP binary in init and support containerized setups#2271fatonh wants to merge 1 commit into
Conversation
|
Hey! To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done? Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review. Cheers! Carsonbot |
0e09cc8 to
ad25eb2
Compare
|
@wachterjohannes Heads up: the PHPStan / Demo check fails on a pre-existing error in demo/src/Crop/Image/Resampler.php, which this PR doesn't touch — looks unrelated to the Mate change. |
wachterjohannes
left a comment
There was a problem hiding this comment.
Thanks for this contribution 🎉
| // Create symlink from .mcp.json to mcp.json for compatibility | ||
| $mcpJsonPath = $this->rootDir.'/mcp.json'; | ||
| if (file_exists($mcpJsonPath)) { | ||
| $phpBinary = $this->resolvePhpBinary($io); |
There was a problem hiding this comment.
i like the idea of resolving the PHP-Binary here and put that into the mcp.json!
But i would add a replacer to the resource file for mcp.json ##PHP_BINARY## or whatever :) and replace that here.
ad25eb2 to
fb44bed
Compare
|
@wachterjohannes thanks! Addressed both issues :) |
| * | ||
| * @return bool whether the file was modified | ||
| */ | ||
| private function applyPhpBinaryToMcpJson(string $mcpJsonPath, string $phpBinary): bool |
There was a problem hiding this comment.
it does not realy replace ist parses the json - i thaught about file_get_contents & str_replace & file_put_contents
fb44bed to
3443704
Compare
mate init generates an mcp.json that the coding agent launches on the host. For containerized setups (e.g. DDEV) PHP only exists in the container, so the default command fails. init now detects a .ddev/ directory and offers a sensible default PHP binary (ddev exec php, otherwise php), which the user can confirm or override. The mcp.json template carries a ##PHP_BINARY## placeholder; init injects the resolved binary, splitting a multi-word wrapper (e.g. "ddev exec php") into command and args. Fix symfony#2264
3443704 to
ed4cfb6
Compare
| $parts | ||
| ); | ||
| $argsLine = $indent.implode(",\n".$indent, $encoded).",\n"; | ||
| } |
There was a problem hiding this comment.
this looks a bit weird especially the $indent thing ... is this realy neccesary?
mate initgenerates anmcp.jsonthat the coding agent launches on the host. In acontainerized setup (DDEV, and Docker-based envs generally) PHP only exists inside the
container, so the default
./vendor/bin/matecommand can't start and Claude Code shows theserver as failed. Reported in #2264.
This makes
initask which PHP binary the agent should use to launch Mate, and detects asensible default from the environment:
.ddev/directory is present → defaultddev exec phpphpThe prompt is offered interactively (accept the default or override); under
--no-interactionthe detected default is used, so CI/scripted runs don't block. Theanswer is written into the generated
mcp.json— the first token becomescommandand therest are prepended to
args.Example
DDEV project (
.ddev/detected):produces:
{ "mcpServers": { "symfony-ai-mate": { "command": "ddev", "args": ["exec", "php", "vendor/bin/mate", "serve", "--force-keep-alive"] } } } A plain Docker Compose user can instead type e.g. docker compose exec php php. Note The non-container default now emits php vendor/bin/mate … rather than the previous ./vendor/bin/mate …. It's functionally equivalent (and a bit more portable), but happy to special-case plain php back to ./vendor/bin/mate if you'd prefer zero change for the common case. I don't use DDEV enough to be sure the detection covers every layout — the .ddev/ check is deliberately minimal; generic Docker/Sail/Lando are left to the manual override for now.