'content' => 'You are a helpful AI coding assistant focused on the Flight Framework for PHP. You are up to date with all your knowledge from https://docs.flightphp.com. As an expert into the programming language PHP, you are top notch at architecting out proper instructions for FlightPHP projects. Output a single AGENTS.md document only.',
],
['role' => 'user', 'content' => $prompt],
],
'temperature' => 0.2,
];
$jsonData = json_encode($data);
// Ask questions
// add info line that this may take a few minutes
$io->info('Generating AI instructions, this may take a few minutes...', true);
@ -110,83 +165,66 @@ class AiGenerateInstructionsCommand extends AbstractBaseCommand
'API' => $api ? 'yes' : 'no',
'API' => $api ? 'yes' : 'no',
'Other' => $other,
'Other' => $other,
];
];
$detailsText = "";
}
/**
* Build the LLM user prompt from answers and existing instructions.
*
* @param array<string,string> $userDetails
* @param string $context
*
* @return string
*/
protected function buildPrompt(array $userDetails, string $context): string
{
$detailsText = '';
foreach ($userDetails as $k => $v) {
foreach ($userDetails as $k => $v) {
$detailsText .= "$k: $v\n";
$detailsText .= "$k: $v\n";
}
}
// phpcs:disable Generic.Files.LineLength
$prompt = <<<EOT
$prompt = <<<EOT
You are an AI coding assistant. Update the following project instructions for this Flight PHP project based on the latest user answers. Only output the new instructions, no extra commentary.
You are an AI coding assistant. Write or update project instructions for this Flight PHP project based on the latest user answers. Only output the new instructions (markdown suitable for AGENTS.md), no extra commentary.
Conventions to encode in the instructions (unless the user answers clearly contradict them):
- Use App\\ namespaces: App\\Controller, App\\Middleware, App\\Model, App\\Utils, App\\Command
- Controllers live in app/Controller/; inject flight\\Engine and other services via the DI container (Dice). Do not use the Flight:: facade in the app layer.
- Prefer flight\\database\\SimplePdo for database access (PdoWrapper is deprecated). Use ActiveRecord for models when an ORM is needed.
- Prefer Twig for HTML views when a templating engine is used.
- AGENTS.md is the sole AI instruction surface (no separate Copilot/Cursor/Gemini/Windsurf rule files). Scoped AGENTS.md files under app/ directories are fine when useful.
- Keep Flight simple and fast; avoid unnecessary abstractions.
User answers:
User answers:
$detailsText
$detailsText
Current instructions:
Current instructions:
$context
$context
EOT; // phpcs:ignore
EOT;
// phpcs:enable Generic.Files.LineLength
// Read LLM creds
$creds = $runwayConfig['ai'];
$apiKey = $creds['api_key'];
$model = $creds['model'];
$baseUrl = $creds['base_url'];
// Prepare curl call (OpenAI compatible)
$headers = [
'Content-Type: application/json',
'Authorization: Bearer ' . $apiKey,
];
$data = [
'model' => $model,
'messages' => [
[
'role' => 'system',
'content' => 'You are a helpful AI coding assistant focused on the Flight Framework for PHP. '
. 'You are up to date with all your knowledge from https://docs.flightphp.com. '
. 'As an expert into the programming language PHP, '
. 'you are top notch at architecting out proper instructions for FlightPHP projects.'
],
['role' => 'user', 'content' => $prompt],
],
'temperature' => 0.2,
];
$jsonData = json_encode($data);
// add info line that this may take a few minutes
$io->info('Generating AI instructions, this may take a few minutes...', true);
rawMessage: 'Method flight\core\Dispatcher::parseStringClassAndMethod() should return array{class-string|object, string} but returns non-empty-list<string>.'