execute method
Execute the command.
Implementation
@override
Future<CommandResult> execute(String args, ToolUseContext context) async {
final force = args.trim() == '--force';
final projectDir = Directory('${context.cwd}/.neomage');
if (await projectDir.exists() && !force) {
return const TextCommandResult(
'Project already initialized (.neomage/ exists).\n'
'Use /init --force to reinitialize.',
);
}
try {
// Create .neomage directory structure
await projectDir.create(recursive: true);
// Create settings.json
final settingsFile = File('${projectDir.path}/settings.json');
if (!await settingsFile.exists() || force) {
await settingsFile.writeAsString(
'{\n'
' "permissions": {},\n'
' "hooks": {},\n'
' "mcpServers": {}\n'
'}\n',
);
}
// Create NEOMAGE.md
final neomageFile = File('${context.cwd}/NEOMAGE.md');
if (!await neomageFile.exists() || force) {
await neomageFile.writeAsString(
'# Project Instructions\n\n'
'Add project-specific instructions for the AI assistant here.\n\n'
'## Build & Test\n\n'
'- Build: `<your build command>`\n'
'- Test: `<your test command>`\n'
'- Lint: `<your lint command>`\n\n'
'## Code Style\n\n'
'- Follow existing patterns in the codebase\n',
);
}
final buffer = StringBuffer();
buffer.writeln('Project initialized:');
buffer.writeln(' Created .neomage/settings.json');
buffer.writeln(' Created NEOMAGE.md');
buffer.writeln();
buffer.writeln('Edit NEOMAGE.md to add project-specific instructions.');
return TextCommandResult(buffer.toString());
} catch (e) {
return TextCommandResult('Initialization failed: $e');
}
}