argument('batch'); $provider = $this->option('provider'); $refine = $this->option('refine'); $dryRun = $this->option('dry-run'); $articleSlug = $this->option('article'); if (! $batchId) { return $this->listBatches(); } if ($refine) { return $this->refineBatch($batchId, $dryRun); } return $this->generateBatch($batchId, $provider, $dryRun, $articleSlug); } protected function listBatches(): int { $batches = $this->batchService->listBatches(); if (empty($batches)) { $this->error('No batch specifications found in doc/phase42/tasks/'); return self::FAILURE; } $this->info('Available content batches:'); $this->newLine(); $this->table( ['Batch ID', 'Service', 'Category', 'Articles', 'Priority'], array_map(fn ($b) => [ $b['id'], $b['service'], $b['category'], $b['article_count'], $b['priority'], ], $batches) ); $this->newLine(); $this->line('Usage: php artisan content:generate batch-001-link-getting-started'); return self::SUCCESS; } protected function generateBatch(string $batchId, string $provider, bool $dryRun, ?string $articleSlug): int { $this->info("Generating content for batch: {$batchId}"); $this->line("Provider: {$provider}"); if ($dryRun) { $this->warn('Dry run mode - no files will be created'); } $this->newLine(); // Get batch status first $status = $this->batchService->getBatchStatus($batchId); if (isset($status['error'])) { $this->error($status['error']); return self::FAILURE; } $this->table( ['Metric', 'Count'], [ ['Total articles', $status['total']], ['Already drafted', $status['drafted']], ['Remaining', $status['remaining']], ] ); if ($status['remaining'] === 0 && ! $articleSlug) { $this->info('All articles in this batch have been drafted.'); return self::SUCCESS; } $this->newLine(); if (! $dryRun && ! $this->confirm('Proceed with generation?', true)) { $this->line('Cancelled.'); return self::SUCCESS; } $this->newLine(); $results = $this->batchService->generateBatch($batchId, $provider, $dryRun); if (isset($results['error'])) { $this->error($results['error']); return self::FAILURE; } // Display results $this->info('Generation Results:'); foreach ($results['articles'] as $slug => $result) { $statusIcon = match ($result['status']) { 'generated' => '✓', 'skipped' => '-', 'would_generate' => '?', 'failed' => '✗', }; $message = match ($result['status']) { 'generated' => "Generated: {$result['path']}", 'skipped' => "Skipped: {$result['reason']}", 'would_generate' => "Would generate: {$result['path']}", 'failed' => "Failed: {$result['error']}", }; $this->line(" {$statusIcon} {$slug} - {$message}"); } $this->newLine(); $this->table( ['Generated', 'Skipped', 'Failed'], [[$results['generated'], $results['skipped'], $results['failed']]] ); return $results['failed'] > 0 ? self::FAILURE : self::SUCCESS; } protected function refineBatch(string $batchId, bool $dryRun): int { $this->info("Refining drafts for batch: {$batchId}"); $this->line('Using: Claude for quality refinement'); if ($dryRun) { $this->warn('Dry run mode - no files will be modified'); } $this->newLine(); $spec = $this->batchService->loadBatch($batchId); if (! $spec) { $this->error("Batch not found: {$batchId}"); return self::FAILURE; } $refined = 0; $skipped = 0; $failed = 0; foreach ($spec['articles'] ?? [] as $article) { $slug = $article['slug'] ?? null; if (! $slug) { continue; } // Find draft file $draftPath = $this->findDraft($slug); if (! $draftPath) { $this->line(" - {$slug} - No draft found"); $skipped++; continue; } if ($dryRun) { $this->line(" ? {$slug} - Would refine: {$draftPath}"); continue; } try { $refinedContent = $this->batchService->refineDraft($draftPath); // Create backup copy($draftPath, $draftPath.'.backup'); // Write refined content file_put_contents($draftPath, $refinedContent); $this->line(" {$slug} - Refined"); $refined++; } catch (\Exception $e) { $this->line(" {$slug} - {$e->getMessage()}"); $failed++; } } $this->newLine(); $this->table( ['Refined', 'Skipped', 'Failed'], [[$refined, $skipped, $failed]] ); return $failed > 0 ? self::FAILURE : self::SUCCESS; } protected function findDraft(string $slug): ?string { $basePath = base_path('doc/phase42/drafts'); $patterns = [ "{$basePath}/help/**/{$slug}.md", "{$basePath}/blog/**/{$slug}.md", "{$basePath}/**/{$slug}.md", ]; foreach ($patterns as $pattern) { $matches = glob($pattern); if (! empty($matches)) { return $matches[0]; } } return null; } }