auto_plan/src/main.cpp

114 lines
3.6 KiB
C++
Raw Normal View History

2026-04-28 07:13:01 +00:00
#include "aise/engine.hpp"
#include <iostream>
#include <string>
// ── 控制台彩色输出(跨平台) ──
#ifdef _WIN32
#include <windows.h>
#define COLOR_GREEN ""
#define COLOR_YELLOW ""
#define COLOR_CYAN ""
#define COLOR_RESET ""
#else
#define COLOR_GREEN "\033[32m"
#define COLOR_YELLOW "\033[33m"
#define COLOR_CYAN "\033[36m"
#define COLOR_RESET "\033[0m"
#endif
static void printBanner() {
std::cout << COLOR_CYAN
<< "\n"
<< " ╔═══════════════════════════════════════╗\n"
<< " ║ AISE Platform v" << aise::Engine::version()
<< "\n"
<< " ║ AI-aided Software Engineering ║\n"
<< " ╚═══════════════════════════════════════╝\n"
<< COLOR_RESET << "\n";
}
static void printHelp() {
std::cout << COLOR_YELLOW
<< "Commands:\n"
<< " req <text> - Process raw requirement text\n"
<< " gen <id,lang> - Generate code (e.g. gen SRS-AISE_F-001,cpp)\n"
<< " test - Run test automation\n"
<< " status - Show engine status\n"
<< " help - Show this help\n"
<< " quit - Exit\n"
<< COLOR_RESET;
}
static void handleCommand(aise::Engine& engine, const std::string& line) {
if (line == "help") {
printHelp();
return;
}
if (line == "quit" || line == "exit") {
std::cout << "Goodbye.\n";
engine.shutdown();
return;
}
if (line == "status") {
std::cout << "Engine " << (engine.is_running() ? COLOR_GREEN "RUNNING" : COLOR_YELLOW "STOPPED")
<< COLOR_RESET << "\n";
return;
}
if (line == "test") {
aise::ApiRequest req;
req.operation = "testing.run";
req.payload = "auto";
auto resp = engine.processRequest(req);
std::cout << COLOR_GREEN << "[Test] " << resp.message << COLOR_RESET << "\n";
return;
}
// req 命令
if (line.substr(0, 4) == "req ") {
std::string text = line.substr(4);
aise::ApiRequest req;
req.operation = "requirements.process";
req.payload = text;
auto resp = engine.processRequest(req);
std::cout << COLOR_GREEN << "[Req] " << resp.message << COLOR_RESET << "\n";
return;
}
// gen 命令
if (line.substr(0, 4) == "gen ") {
std::string params = line.substr(4);
aise::ApiRequest req;
req.operation = "code.generate";
req.payload = params;
auto resp = engine.processRequest(req);
if (resp.code == 0) {
std::cout << COLOR_GREEN << "[Gen] " << resp.message << COLOR_RESET << "\n";
} else {
std::cout << COLOR_YELLOW << "[Gen] Error: " << resp.message << COLOR_RESET << "\n";
}
return;
}
std::cout << "Unknown command. Type 'help' for usage.\n";
}
int main() {
aise::Engine engine;
if (!engine.initialize()) {
std::cerr << "FATAL: Engine initialization failed.\n";
return 1;
}
printBanner();
// 交互式命令行
std::string line;
while (engine.is_running()) {
std::cout << "\n" COLOR_CYAN "aise> " COLOR_RESET;
if (!std::getline(std::cin, line)) break;
handleCommand(engine, line);
}
return 0;
}