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 {
final planFile = File('.spectra/PLAN.md');
if (!planFile.existsSync()) {
logger.err('PLAN.md not found. Run `spectra plan` first.');
return;
}
final content = planFile.readAsStringSync();
final tasks = _parseTasks(content);
if (tasks.isEmpty) {
logger.warn('No tasks found in PLAN.md.');
return;
}
// Check for manual mode
final config = await _configService.loadConfig();
final manualFlag = argResults?['manual'] as bool? ?? false;
final modeStr = config.executionMode ?? 'automatic';
final mode = ExecutionMode.values.firstWhere(
(m) => m.name == modeStr,
orElse: () => ExecutionMode.automatic,
);
if (manualFlag || mode == ExecutionMode.manual) {
_displayTasksForManualExecution(tasks);
return;
}
final workersArg = argResults?['workers'] as String?;
final workerCount = int.tryParse(workersArg ?? '2') ?? 2;
final orchestrator = OrchestratorService(logger: logger);
final convoy = Convoy(id: 'plan-main', name: 'Main Plan', tasks: tasks);
orchestrator.addConvoy(convoy);
logger.info('Starting orchestrator with $workerCount workers...');
await orchestrator.start(workerCount: workerCount);
logger.success('Orchestrator is running. Press Enter to stop.');
// Keep alive until user input
await stdin.first;
orchestrator.stop();
}