run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
Future<void> run() async {
logger.info('Mapping existing repository...');
final currentDir = Directory.current;
final allFiles = currentDir
.listSync(recursive: true)
.whereType<File>()
.where((f) => !f.path.contains('.git/') && !f.path.contains('.spectra/'));
final fileStructure = allFiles.map((f) => f.path.replaceFirst(currentDir.path, '')).toList();
final provider = await _llmService.getPreferredProvider();
if (provider == null) {
logger.err('No LLM provider configured.');
return;
}
logger.info('Analyzing architecture using ${provider.name}...');
final prompt = '''
Analyze the following file structure and summarize the project's tech stack, architecture, and core modules.
FILE STRUCTURE:
${fileStructure.join('\n')}
Return a markdown summary with sections: ## Tech Stack, ## Architecture, ## Core Modules.
''';
try {
final analysis = await provider.generateResponse(prompt);
logger.info('\n--- Analysis Results ---\n');
logger.info(analysis);
final confirm =
Confirm(prompt: 'Generate .spectra context based on this analysis?')
.interact();
if (confirm) {
_generateSpectraFromMap(analysis);
logger.success('Spectra context generated from repository map!');
}
} catch (e) {
logger.err('Error mapping repository: $e');
}
}