44
55namespace flight \commands ;
66
7- use Ahc \Cli \Input \Command ;
8-
97/**
10- * @property-read ?string $credsFile
8+ * @property-read ?string $configFile
119 * @property-read ?string $baseDir
1210 */
13- class AiGenerateInstructionsCommand extends Command
11+ class AiGenerateInstructionsCommand extends AbstractBaseCommand
1412{
1513 /**
1614 * Constructor for the AiGenerateInstructionsCommand class.
1715 *
1816 * Initializes a new instance of the command.
17+ *
18+ * @param array<string,mixed> $config Config from config.php
1919 */
20- public function __construct ()
20+ public function __construct (array $ config )
2121 {
22- parent ::__construct ('ai:generate-instructions ' , 'Generate project-specific AI coding instructions ' );
23- $ this ->option ('--creds-file ' , 'Path to .runway-creds.json file ' , null , '' );
24- $ this ->option ('--base-dir ' , 'Project base directory (for testing or custom use) ' , null , '' );
22+ parent ::__construct ('ai:generate-instructions ' , 'Generate project-specific AI coding instructions ' , $ config );
23+ $ this ->option ('--config-file ' , 'Path to .runway-config.json file (deprecated, use config.php instead) ' , null , '' );
2524 }
2625
2726 /**
@@ -37,12 +36,19 @@ public function __construct()
3736 public function execute ()
3837 {
3938 $ io = $ this ->app ()->io ();
40- $ baseDir = $ this ->baseDir ? rtrim ($ this ->baseDir , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR : getcwd () . DIRECTORY_SEPARATOR ;
41- $ runwayCredsFile = $ this ->credsFile ?: $ baseDir . '.runway-creds.json ' ;
4239
43- // Check for runway creds
44- if (!file_exists ($ runwayCredsFile )) {
45- $ io ->error ('Missing .runway-creds.json. Please run the \'ai:init \' command first. ' , true );
40+ if (empty ($ this ->config ['runway ' ])) {
41+ $ configFile = $ this ->configFile ;
42+ $ io = $ this ->app ()->io ();
43+ $ io ->warn ('The --config-file option is deprecated. Move your config values to the \'runway \' key in the config.php file for configuration. ' , true );
44+ $ runwayConfig = json_decode (file_get_contents ($ configFile ), true ) ?? [];
45+ } else {
46+ $ runwayConfig = $ this ->config ['runway ' ];
47+ }
48+
49+ // Check for runway creds ai
50+ if (empty ($ runwayConfig ['ai ' ])) {
51+ $ io ->error ('Missing AI configuration. Please run the \'ai:init \' command first. ' , true );
4652 return 1 ;
4753 }
4854
@@ -61,8 +67,8 @@ public function execute()
6167 $ other = $ io ->prompt ('Any other important requirements or context? (optional) ' , 'no ' );
6268
6369 // Prepare prompt for LLM
64- $ contextFile = $ baseDir . '.github/copilot-instructions.md ' ;
65- $ context = file_exists ($ contextFile ) ? file_get_contents ($ contextFile ) : '' ;
70+ $ contextFile = $ this -> projectRoot . '.github/copilot-instructions.md ' ;
71+ $ context = file_exists ($ contextFile ) === true ? file_get_contents ($ contextFile ) : '' ;
6672 $ userDetails = [
6773 'Project Description ' => $ projectDesc ,
6874 'Database ' => $ database ,
@@ -80,18 +86,18 @@ public function execute()
8086 $ detailsText .= "$ k: $ v \n" ;
8187 }
8288 $ prompt = <<<EOT
83- You are an AI coding assistant. Update the following project instructions for this FlightPHP project based on the latest user answers. Only output the new instructions, no extra commentary.
89+ 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.
8490 User answers:
8591 $ detailsText
8692 Current instructions:
8793 $ context
8894 EOT ; // phpcs:ignore
8995
9096 // Read LLM creds
91- $ creds = json_decode ( file_get_contents ( $ runwayCredsFile ), true ) ;
92- $ apiKey = $ creds ['api_key ' ] ?? '' ;
93- $ model = $ creds ['model ' ] ?? ' gpt-4o ' ;
94- $ baseUrl = $ creds ['base_url ' ] ?? ' https://api.openai.com ' ;
97+ $ creds = $ runwayConfig [ ' ai ' ] ;
98+ $ apiKey = $ creds ['api_key ' ];
99+ $ model = $ creds ['model ' ];
100+ $ baseUrl = $ creds ['base_url ' ];
95101
96102 // Prepare curl call (OpenAI compatible)
97103 $ headers = [
@@ -123,16 +129,20 @@ public function execute()
123129 }
124130
125131 // Write to files
126- $ io ->info ('Updating .github/copilot-instructions.md, .cursor/rules/project-overview.mdc, and .windsurfrules... ' , true );
127- if (!is_dir ($ baseDir . '.github ' )) {
128- mkdir ($ baseDir . '.github ' , 0755 , true );
132+ $ io ->info ('Updating .github/copilot-instructions.md, .cursor/rules/project-overview.mdc, .gemini/GEMINI.md and .windsurfrules... ' , true );
133+ if (!is_dir ($ this ->projectRoot . '.github ' )) {
134+ mkdir ($ this ->projectRoot . '.github ' , 0755 , true );
135+ }
136+ if (!is_dir ($ this ->projectRoot . '.cursor/rules ' )) {
137+ mkdir ($ this ->projectRoot . '.cursor/rules ' , 0755 , true );
129138 }
130- if (!is_dir ($ baseDir . '.cursor/rules ' )) {
131- mkdir ($ baseDir . '.cursor/rules ' , 0755 , true );
139+ if (!is_dir ($ this -> projectRoot . '.gemini ' )) {
140+ mkdir ($ this -> projectRoot . '.gemini ' , 0755 , true );
132141 }
133- file_put_contents ($ baseDir . '.github/copilot-instructions.md ' , $ instructions );
134- file_put_contents ($ baseDir . '.cursor/rules/project-overview.mdc ' , $ instructions );
135- file_put_contents ($ baseDir . '.windsurfrules ' , $ instructions );
142+ file_put_contents ($ this ->projectRoot . '.github/copilot-instructions.md ' , $ instructions );
143+ file_put_contents ($ this ->projectRoot . '.cursor/rules/project-overview.mdc ' , $ instructions );
144+ file_put_contents ($ this ->projectRoot . '.gemini/GEMINI.md ' , $ instructions );
145+ file_put_contents ($ this ->projectRoot . '.windsurfrules ' , $ instructions );
136146 $ io ->ok ('AI instructions updated successfully. ' , true );
137147 return 0 ;
138148 }
0 commit comments