Refactor CLI Service Structure and Enhance AI Integration
- Restructured CLI service source files to improve organization, moving files into dedicated directories for better maintainability. - Introduced new AI service components, including `AIService`, `MockAIService`, and `GeminiAIService`, to facilitate natural language command generation. - Implemented `PolicyEvaluator` and `ProposalRegistry` for enhanced proposal management and policy enforcement in AI workflows. - Updated CMake configurations to reflect new file paths and ensure proper linking of the restructured components. - Enhanced test suite with new test workflow generation capabilities, improving the robustness of automated testing. This commit significantly advances the architecture of the z3ed system, laying the groundwork for more sophisticated AI-driven features and streamlined development processes.
This commit is contained in:
@@ -172,10 +172,10 @@ if (YAZE_BUILD_LIB)
|
|||||||
${YAZE_GUI_SRC}
|
${YAZE_GUI_SRC}
|
||||||
${YAZE_UTIL_SRC}
|
${YAZE_UTIL_SRC}
|
||||||
# CLI service sources (needed for ProposalDrawer)
|
# CLI service sources (needed for ProposalDrawer)
|
||||||
cli/service/proposal_registry.cc
|
cli/service/planning/proposal_registry.cc
|
||||||
cli/service/rom_sandbox_manager.cc
|
cli/service/rom/rom_sandbox_manager.cc
|
||||||
# cli/service/gui_automation_client.cc # Moved to yaze_c
|
# cli/service/gui_automation_client.cc # Moved to yaze_c
|
||||||
cli/service/test_workflow_generator.cc
|
cli/service/testing/test_workflow_generator.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create full library for C API
|
# Create full library for C API
|
||||||
@@ -184,7 +184,7 @@ if (YAZE_BUILD_LIB)
|
|||||||
${YAZE_CORE_SOURCES}
|
${YAZE_CORE_SOURCES}
|
||||||
${YAZE_GUI_SRC}
|
${YAZE_GUI_SRC}
|
||||||
${IMGUI_SRC}
|
${IMGUI_SRC}
|
||||||
cli/service/gui_automation_client.cc
|
cli/service/gui/gui_automation_client.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add emulator sources (required for comprehensive testing)
|
# Add emulator sources (required for comprehensive testing)
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ if (APPLE)
|
|||||||
${YAZE_GUI_SRC}
|
${YAZE_GUI_SRC}
|
||||||
${IMGUI_SRC}
|
${IMGUI_SRC}
|
||||||
# CLI service sources (needed for ProposalDrawer)
|
# CLI service sources (needed for ProposalDrawer)
|
||||||
cli/service/proposal_registry.cc
|
cli/service/planning/proposal_registry.cc
|
||||||
cli/service/rom_sandbox_manager.cc
|
cli/service/rom/rom_sandbox_manager.cc
|
||||||
cli/service/policy_evaluator.cc
|
cli/service/planning/policy_evaluator.cc
|
||||||
# Bundled Resources
|
# Bundled Resources
|
||||||
${YAZE_RESOURCE_FILES}
|
${YAZE_RESOURCE_FILES}
|
||||||
)
|
)
|
||||||
@@ -58,9 +58,9 @@ else()
|
|||||||
${YAZE_GUI_SRC}
|
${YAZE_GUI_SRC}
|
||||||
${IMGUI_SRC}
|
${IMGUI_SRC}
|
||||||
# CLI service sources (needed for ProposalDrawer)
|
# CLI service sources (needed for ProposalDrawer)
|
||||||
cli/service/proposal_registry.cc
|
cli/service/planning/proposal_registry.cc
|
||||||
cli/service/rom_sandbox_manager.cc
|
cli/service/rom/rom_sandbox_manager.cc
|
||||||
cli/service/policy_evaluator.cc
|
cli/service/planning/policy_evaluator.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add asset files for Windows/Linux builds
|
# Add asset files for Windows/Linux builds
|
||||||
|
|||||||
@@ -8,11 +8,11 @@
|
|||||||
#include "absl/time/time.h"
|
#include "absl/time/time.h"
|
||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
#include "app/gui/icons.h"
|
#include "app/gui/icons.h"
|
||||||
#include "cli/service/rom_sandbox_manager.h"
|
#include "cli/service/rom/rom_sandbox_manager.h"
|
||||||
|
|
||||||
// Policy evaluation support (optional, only in main yaze build)
|
// Policy evaluation support (optional, only in main yaze build)
|
||||||
#ifdef YAZE_ENABLE_POLICY_FRAMEWORK
|
#ifdef YAZE_ENABLE_POLICY_FRAMEWORK
|
||||||
#include "cli/service/policy_evaluator.h"
|
#include "cli/service/planning/policy_evaluator.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "cli/service/proposal_registry.h"
|
#include "cli/service/planning/proposal_registry.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
class Rom;
|
class Rom;
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ if (NOT YAZE_MINIMAL_BUILD AND APPLE)
|
|||||||
${YAZE_GUI_SRC}
|
${YAZE_GUI_SRC}
|
||||||
${IMGUI_SRC}
|
${IMGUI_SRC}
|
||||||
# CLI service sources (needed for ProposalDrawer)
|
# CLI service sources (needed for ProposalDrawer)
|
||||||
cli/service/proposal_registry.cc
|
cli/service/planning/proposal_registry.cc
|
||||||
cli/service/rom_sandbox_manager.cc
|
cli/service/rom/rom_sandbox_manager.cc
|
||||||
)
|
)
|
||||||
target_link_libraries(yaze_emu PUBLIC ${COCOA_LIBRARY})
|
target_link_libraries(yaze_emu PUBLIC ${COCOA_LIBRARY})
|
||||||
elseif(NOT YAZE_MINIMAL_BUILD)
|
elseif(NOT YAZE_MINIMAL_BUILD)
|
||||||
@@ -33,8 +33,8 @@ elseif(NOT YAZE_MINIMAL_BUILD)
|
|||||||
${YAZE_GUI_SRC}
|
${YAZE_GUI_SRC}
|
||||||
${IMGUI_SRC}
|
${IMGUI_SRC}
|
||||||
# CLI service sources (needed for ProposalDrawer)
|
# CLI service sources (needed for ProposalDrawer)
|
||||||
cli/service/proposal_registry.cc
|
cli/service/planning/proposal_registry.cc
|
||||||
cli/service/rom_sandbox_manager.cc
|
cli/service/rom/rom_sandbox_manager.cc
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace agent {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr absl::string_view kUsage =
|
constexpr absl::string_view kUsage =
|
||||||
"Usage: agent <run|plan|diff|test|gui|learn|list|commit|revert|describe> "
|
"Usage: agent <run|plan|diff|accept|test|gui|learn|list|commit|revert|describe> "
|
||||||
"[options]";
|
"[options]";
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
@@ -35,6 +35,9 @@ absl::Status Agent::Run(const std::vector<std::string>& arg_vec) {
|
|||||||
if (subcommand == "diff") {
|
if (subcommand == "diff") {
|
||||||
return agent::HandleDiffCommand(rom_, subcommand_args);
|
return agent::HandleDiffCommand(rom_, subcommand_args);
|
||||||
}
|
}
|
||||||
|
if (subcommand == "accept") {
|
||||||
|
return agent::HandleAcceptCommand(subcommand_args, rom_);
|
||||||
|
}
|
||||||
if (subcommand == "test") {
|
if (subcommand == "test") {
|
||||||
return agent::HandleTestCommand(subcommand_args);
|
return agent::HandleTestCommand(subcommand_args);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ absl::Status HandleRunCommand(const std::vector<std::string>& args,
|
|||||||
absl::Status HandlePlanCommand(const std::vector<std::string>& args);
|
absl::Status HandlePlanCommand(const std::vector<std::string>& args);
|
||||||
absl::Status HandleDiffCommand(Rom& rom,
|
absl::Status HandleDiffCommand(Rom& rom,
|
||||||
const std::vector<std::string>& args);
|
const std::vector<std::string>& args);
|
||||||
|
absl::Status HandleAcceptCommand(const std::vector<std::string>& args, Rom& rom);
|
||||||
absl::Status HandleTestCommand(const std::vector<std::string>& args);
|
absl::Status HandleTestCommand(const std::vector<std::string>& args);
|
||||||
absl::Status HandleGuiCommand(const std::vector<std::string>& args);
|
absl::Status HandleGuiCommand(const std::vector<std::string>& args);
|
||||||
absl::Status HandleLearnCommand();
|
absl::Status HandleLearnCommand();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "absl/time/time.h"
|
#include "absl/time/time.h"
|
||||||
#include "cli/service/gui_automation_client.h"
|
#include "cli/service/gui/gui_automation_client.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace cli {
|
namespace cli {
|
||||||
|
|||||||
@@ -18,12 +18,13 @@
|
|||||||
#include "absl/strings/str_replace.h"
|
#include "absl/strings/str_replace.h"
|
||||||
#include "cli/handlers/agent/common.h"
|
#include "cli/handlers/agent/common.h"
|
||||||
#include "cli/modern_cli.h"
|
#include "cli/modern_cli.h"
|
||||||
#include "cli/service/ai_service.h"
|
#include "cli/service/ai/ai_service.h"
|
||||||
#include "cli/service/ollama_ai_service.h"
|
#include "cli/service/ai/ollama_ai_service.h"
|
||||||
#include "cli/service/gemini_ai_service.h"
|
#include "cli/service/ai/gemini_ai_service.h"
|
||||||
#include "cli/service/proposal_registry.h"
|
#include "cli/service/planning/proposal_registry.h"
|
||||||
#include "cli/service/resource_catalog.h"
|
#include "cli/service/planning/tile16_proposal_generator.h"
|
||||||
#include "cli/service/rom_sandbox_manager.h"
|
#include "cli/service/resources/resource_catalog.h"
|
||||||
|
#include "cli/service/rom/rom_sandbox_manager.h"
|
||||||
#include "cli/z3ed.h"
|
#include "cli/z3ed.h"
|
||||||
#include "util/macro.h"
|
#include "util/macro.h"
|
||||||
|
|
||||||
@@ -174,109 +175,84 @@ absl::Status HandleRunCommand(const std::vector<std::string>& arg_vec,
|
|||||||
if (rom_path.empty()) {
|
if (rom_path.empty()) {
|
||||||
return absl::FailedPreconditionError(
|
return absl::FailedPreconditionError(
|
||||||
"No ROM loaded. Use --rom=<path> to specify ROM file.\n"
|
"No ROM loaded. Use --rom=<path> to specify ROM file.\n"
|
||||||
"Example: z3ed agent run --rom=zelda3.sfc --prompt \"Your prompt here\"");
|
"Example: z3ed agent run --rom=zelda3.sfc --prompt \"Your prompt "
|
||||||
|
"here\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto status = rom.LoadFromFile(rom_path);
|
auto status = rom.LoadFromFile(rom_path);
|
||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
return absl::FailedPreconditionError(
|
return absl::FailedPreconditionError(absl::StrFormat(
|
||||||
absl::StrFormat("Failed to load ROM from '%s': %s", rom_path,
|
"Failed to load ROM from '%s': %s", rom_path, status.message()));
|
||||||
status.message()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sandbox_or = RomSandboxManager::Instance().CreateSandbox(rom,
|
// 1. Create a sandbox ROM to apply changes to
|
||||||
"agent-run");
|
auto sandbox_or =
|
||||||
|
RomSandboxManager::Instance().CreateSandbox(rom, "agent-run");
|
||||||
if (!sandbox_or.ok()) {
|
if (!sandbox_or.ok()) {
|
||||||
return sandbox_or.status();
|
return sandbox_or.status();
|
||||||
}
|
}
|
||||||
auto sandbox = sandbox_or.value();
|
auto sandbox = sandbox_or.value();
|
||||||
|
|
||||||
auto proposal_or = ProposalRegistry::Instance().CreateProposal(
|
// 2. Get commands from the AI service
|
||||||
sandbox.id, prompt, "Agent-generated ROM modifications");
|
auto ai_service = CreateAIService(); // Use service factory
|
||||||
|
auto commands_or = ai_service->GetCommands(prompt);
|
||||||
|
if (!commands_or.ok()) {
|
||||||
|
return commands_or.status();
|
||||||
|
}
|
||||||
|
std::vector<std::string> commands = commands_or.value();
|
||||||
|
|
||||||
|
// 3. Generate a structured proposal from the commands
|
||||||
|
Tile16ProposalGenerator generator;
|
||||||
|
auto proposal_or = generator.GenerateFromCommands(
|
||||||
|
prompt, commands, "ollama", &rom); // Pass original ROM to get old tiles
|
||||||
if (!proposal_or.ok()) {
|
if (!proposal_or.ok()) {
|
||||||
return proposal_or.status();
|
return proposal_or.status();
|
||||||
}
|
}
|
||||||
auto proposal = proposal_or.value();
|
auto proposal = proposal_or.value();
|
||||||
|
|
||||||
RETURN_IF_ERROR(ProposalRegistry::Instance().AppendLog(
|
// 4. Apply the proposal to the sandbox ROM for preview
|
||||||
proposal.id, absl::StrCat("Starting agent run with prompt: ", prompt)));
|
Rom sandbox_rom;
|
||||||
|
auto load_status = sandbox_rom.LoadFromFile(sandbox.rom_path.string());
|
||||||
auto ai_service = CreateAIService(); // Use service factory
|
if (!load_status.ok()) {
|
||||||
auto commands_or = ai_service->GetCommands(prompt);
|
return absl::InternalError(absl::StrCat(
|
||||||
if (!commands_or.ok()) {
|
"Failed to load sandbox ROM: ", load_status.message()));
|
||||||
RETURN_IF_ERROR(ProposalRegistry::Instance().AppendLog(
|
|
||||||
proposal.id,
|
|
||||||
absl::StrCat("AI service error: ", commands_or.status().message())));
|
|
||||||
return commands_or.status();
|
|
||||||
}
|
|
||||||
std::vector<std::string> commands = commands_or.value();
|
|
||||||
|
|
||||||
RETURN_IF_ERROR(ProposalRegistry::Instance().AppendLog(
|
|
||||||
proposal.id, absl::StrCat("Generated ", commands.size(),
|
|
||||||
" commands")));
|
|
||||||
|
|
||||||
ModernCLI cli;
|
|
||||||
int commands_executed = 0;
|
|
||||||
for (const auto& command : commands) {
|
|
||||||
RETURN_IF_ERROR(ProposalRegistry::Instance().AppendLog(
|
|
||||||
proposal.id, absl::StrCat("Executing: ", command)));
|
|
||||||
|
|
||||||
std::vector<std::string> command_parts;
|
|
||||||
std::string current_part;
|
|
||||||
bool in_quotes = false;
|
|
||||||
for (char c : command) {
|
|
||||||
if (c == '"') {
|
|
||||||
in_quotes = !in_quotes;
|
|
||||||
} else if (c == ' ' && !in_quotes) {
|
|
||||||
command_parts.push_back(current_part);
|
|
||||||
current_part.clear();
|
|
||||||
} else {
|
|
||||||
current_part += c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
command_parts.push_back(current_part);
|
|
||||||
|
|
||||||
if (command_parts.size() < 2) {
|
|
||||||
auto error_msg = absl::StrFormat("Malformed command: %s", command);
|
|
||||||
RETURN_IF_ERROR(ProposalRegistry::Instance().AppendLog(proposal.id,
|
|
||||||
error_msg));
|
|
||||||
return absl::InvalidArgumentError(error_msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string cmd_name = command_parts[0] + " " + command_parts[1];
|
|
||||||
std::vector<std::string> cmd_args(command_parts.begin() + 2,
|
|
||||||
command_parts.end());
|
|
||||||
|
|
||||||
auto it = cli.commands_.find(cmd_name);
|
|
||||||
if (it != cli.commands_.end()) {
|
|
||||||
auto status = it->second.handler(cmd_args);
|
|
||||||
if (!status.ok()) {
|
|
||||||
RETURN_IF_ERROR(ProposalRegistry::Instance().AppendLog(
|
|
||||||
proposal.id, absl::StrCat("Command failed: ", status.message())));
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
commands_executed++;
|
|
||||||
RETURN_IF_ERROR(
|
|
||||||
ProposalRegistry::Instance().AppendLog(proposal.id,
|
|
||||||
"Command succeeded"));
|
|
||||||
} else {
|
|
||||||
auto error_msg = absl::StrCat("Unknown command: ", cmd_name);
|
|
||||||
RETURN_IF_ERROR(
|
|
||||||
ProposalRegistry::Instance().AppendLog(proposal.id, error_msg));
|
|
||||||
return absl::NotFoundError(error_msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RETURN_IF_ERROR(ProposalRegistry::Instance().AppendLog(
|
auto apply_status = generator.ApplyProposal(proposal, &sandbox_rom);
|
||||||
proposal.id,
|
if (!apply_status.ok()) {
|
||||||
absl::StrCat("Completed execution of ", commands_executed,
|
return absl::InternalError(
|
||||||
" commands")));
|
absl::StrCat("Failed to apply proposal to sandbox ROM: ",
|
||||||
|
apply_status.message()));
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "✅ Agent run completed successfully." << std::endl;
|
// 5. Save the sandbox ROM to persist the changes for diffing
|
||||||
|
auto save_status = sandbox_rom.SaveToFile({.save_new = false});
|
||||||
|
if (!save_status.ok()) {
|
||||||
|
return absl::InternalError(
|
||||||
|
absl::StrCat("Failed to save sandbox ROM: ", save_status.message()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. Save the proposal metadata for later use (accept/reject)
|
||||||
|
// For now, we'll just use the proposal generator's save function.
|
||||||
|
// A better approach would be to integrate with ProposalRegistry.
|
||||||
|
auto proposal_path =
|
||||||
|
RomSandboxManager::Instance().RootDirectory() / (proposal.id + ".json");
|
||||||
|
auto save_proposal_status = generator.SaveProposal(proposal, proposal_path.string());
|
||||||
|
if (!save_proposal_status.ok()) {
|
||||||
|
return absl::InternalError(absl::StrCat("Failed to save proposal file: ",
|
||||||
|
save_proposal_status.message()));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "✅ Agent successfully planned and executed changes in a sandbox."
|
||||||
|
<< std::endl;
|
||||||
std::cout << " Proposal ID: " << proposal.id << std::endl;
|
std::cout << " Proposal ID: " << proposal.id << std::endl;
|
||||||
std::cout << " Sandbox: " << sandbox.rom_path << std::endl;
|
std::cout << " Sandbox ROM: " << sandbox.rom_path << std::endl;
|
||||||
std::cout << " Use 'z3ed agent diff' to review changes" << std::endl;
|
std::cout << " Proposal file: " << proposal_path << std::endl;
|
||||||
|
std::cout << "\nTo review the changes, run:\n";
|
||||||
|
std::cout << " z3ed agent diff --proposal-id " << proposal.id << std::endl;
|
||||||
|
std::cout << "\nTo accept the changes, run:\n";
|
||||||
|
std::cout << " z3ed agent accept --proposal-id " << proposal.id << std::endl;
|
||||||
|
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
@@ -294,10 +270,20 @@ absl::Status HandlePlanCommand(const std::vector<std::string>& arg_vec) {
|
|||||||
}
|
}
|
||||||
std::vector<std::string> commands = commands_or.value();
|
std::vector<std::string> commands = commands_or.value();
|
||||||
|
|
||||||
std::cout << "AI Agent Plan:" << std::endl;
|
// Create a proposal from the commands
|
||||||
for (const auto& command : commands) {
|
Tile16ProposalGenerator generator;
|
||||||
std::cout << " - " << command << std::endl;
|
auto proposal_or =
|
||||||
|
generator.GenerateFromCommands(prompt, commands, "ollama", nullptr);
|
||||||
|
if (!proposal_or.ok()) {
|
||||||
|
return proposal_or.status();
|
||||||
}
|
}
|
||||||
|
auto proposal = proposal_or.value();
|
||||||
|
|
||||||
|
// TODO: Save the proposal to disk using ProposalRegistry
|
||||||
|
// For now, just print it.
|
||||||
|
std::cout << "AI Agent Plan (Proposal ID: " << proposal.id << "):\n";
|
||||||
|
std::cout << proposal.ToJson() << std::endl;
|
||||||
|
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -542,6 +528,56 @@ absl::Status HandleDescribeCommand(const std::vector<std::string>& arg_vec) {
|
|||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
absl::Status HandleAcceptCommand(const std::vector<std::string>& arg_vec,
|
||||||
|
Rom& rom) {
|
||||||
|
if (arg_vec.empty() || arg_vec[0] != "--proposal-id") {
|
||||||
|
return absl::InvalidArgumentError(
|
||||||
|
"Usage: agent accept --proposal-id <proposal_id>");
|
||||||
|
}
|
||||||
|
std::string proposal_id = arg_vec[1];
|
||||||
|
|
||||||
|
// 1. Load the proposal from disk.
|
||||||
|
Tile16ProposalGenerator generator;
|
||||||
|
auto proposal_path =
|
||||||
|
RomSandboxManager::Instance().RootDirectory() / (proposal_id + ".json");
|
||||||
|
auto proposal_or = generator.LoadProposal(proposal_path.string());
|
||||||
|
if (!proposal_or.ok()) {
|
||||||
|
return absl::InternalError(absl::StrCat("Failed to load proposal file '",
|
||||||
|
proposal_path.string(),
|
||||||
|
"': ", proposal_or.status().message()));
|
||||||
|
}
|
||||||
|
auto proposal = proposal_or.value();
|
||||||
|
|
||||||
|
// 2. Ensure the main ROM is loaded.
|
||||||
|
if (!rom.is_loaded()) {
|
||||||
|
return absl::FailedPreconditionError(
|
||||||
|
"No ROM loaded. Use --rom=<path> to specify the ROM to apply changes to.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Apply the proposal to the main ROM.
|
||||||
|
auto apply_status = generator.ApplyProposal(proposal, &rom);
|
||||||
|
if (!apply_status.ok()) {
|
||||||
|
return absl::InternalError(
|
||||||
|
absl::StrCat("Failed to apply proposal to main ROM: ",
|
||||||
|
apply_status.message()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Save the changes to the main ROM file.
|
||||||
|
auto save_status = rom.SaveToFile({.save_new = false});
|
||||||
|
if (!save_status.ok()) {
|
||||||
|
return absl::InternalError(
|
||||||
|
absl::StrCat("Failed to save changes to main ROM: ",
|
||||||
|
save_status.message()));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "✅ Proposal '" << proposal_id << "' accepted and applied to '"
|
||||||
|
<< rom.filename() << "'." << std::endl;
|
||||||
|
|
||||||
|
// TODO: Clean up sandbox and proposal files.
|
||||||
|
|
||||||
|
return absl::OkStatus();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace agent
|
} // namespace agent
|
||||||
} // namespace cli
|
} // namespace cli
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#include "absl/strings/str_format.h"
|
#include "absl/strings/str_format.h"
|
||||||
#include "absl/time/time.h"
|
#include "absl/time/time.h"
|
||||||
#include "cli/handlers/agent/common.h"
|
#include "cli/handlers/agent/common.h"
|
||||||
#include "cli/service/gui_automation_client.h"
|
#include "cli/service/gui/gui_automation_client.h"
|
||||||
#include "util/macro.h"
|
#include "util/macro.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
#include "cli/handlers/agent/common.h"
|
#include "cli/handlers/agent/common.h"
|
||||||
|
|
||||||
#ifdef YAZE_WITH_GRPC
|
#ifdef YAZE_WITH_GRPC
|
||||||
#include "cli/service/gui_automation_client.h"
|
#include "cli/service/gui/gui_automation_client.h"
|
||||||
#include "cli/service/test_workflow_generator.h"
|
#include "cli/service/testing/test_workflow_generator.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "cli/service/ai_service.h"
|
#include "cli/service/ai/ai_service.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace cli {
|
namespace cli {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "cli/service/gemini_ai_service.h"
|
#include "cli/service/ai/gemini_ai_service.h"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "absl/status/statusor.h"
|
#include "absl/status/statusor.h"
|
||||||
#include "cli/service/ai_service.h"
|
#include "cli/service/ai/ai_service.h"
|
||||||
#include "cli/service/prompt_builder.h"
|
#include "cli/service/ai/prompt_builder.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace cli {
|
namespace cli {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "cli/service/ollama_ai_service.h"
|
#include "cli/service/ai/ollama_ai_service.h"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "absl/status/statusor.h"
|
#include "absl/status/statusor.h"
|
||||||
#include "cli/service/ai_service.h"
|
#include "cli/service/ai/ai_service.h"
|
||||||
#include "cli/service/prompt_builder.h"
|
#include "cli/service/ai/prompt_builder.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace cli {
|
namespace cli {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "cli/service/prompt_builder.h"
|
#include "cli/service/ai/prompt_builder.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -248,9 +248,20 @@ std::string PromptBuilder::BuildConstraintsSection() {
|
|||||||
|
|
||||||
std::string PromptBuilder::BuildContextSection(const RomContext& context) {
|
std::string PromptBuilder::BuildContextSection(const RomContext& context) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
|
|
||||||
oss << "# Current ROM Context\n\n";
|
oss << "# Current ROM Context\n\n";
|
||||||
|
|
||||||
|
// Use ResourceContextBuilder if a ROM is available
|
||||||
|
if (rom_ && rom_->is_loaded()) {
|
||||||
|
if (!resource_context_builder_) {
|
||||||
|
resource_context_builder_ = std::make_unique<ResourceContextBuilder>(rom_);
|
||||||
|
}
|
||||||
|
auto resource_context_or = resource_context_builder_->BuildResourceContext();
|
||||||
|
if (resource_context_or.ok()) {
|
||||||
|
oss << resource_context_or.value();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (context.rom_loaded) {
|
if (context.rom_loaded) {
|
||||||
oss << "- **ROM Loaded:** Yes (" << context.rom_path << ")\n";
|
oss << "- **ROM Loaded:** Yes (" << context.rom_path << ")\n";
|
||||||
} else {
|
} else {
|
||||||
@@ -6,6 +6,8 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "absl/status/statusor.h"
|
#include "absl/status/statusor.h"
|
||||||
|
#include "cli/service/resources/resource_context_builder.h"
|
||||||
|
#include "app/rom.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace cli {
|
namespace cli {
|
||||||
@@ -30,6 +32,8 @@ class PromptBuilder {
|
|||||||
public:
|
public:
|
||||||
PromptBuilder();
|
PromptBuilder();
|
||||||
|
|
||||||
|
void SetRom(Rom* rom) { rom_ = rom; }
|
||||||
|
|
||||||
// Load z3ed command documentation from resources
|
// Load z3ed command documentation from resources
|
||||||
absl::Status LoadResourceCatalogue(const std::string& yaml_path);
|
absl::Status LoadResourceCatalogue(const std::string& yaml_path);
|
||||||
|
|
||||||
@@ -62,6 +66,8 @@ class PromptBuilder {
|
|||||||
|
|
||||||
void LoadDefaultExamples();
|
void LoadDefaultExamples();
|
||||||
|
|
||||||
|
Rom* rom_ = nullptr;
|
||||||
|
std::unique_ptr<ResourceContextBuilder> resource_context_builder_;
|
||||||
std::map<std::string, std::string> command_docs_; // Command name -> docs
|
std::map<std::string, std::string> command_docs_; // Command name -> docs
|
||||||
std::vector<FewShotExample> examples_;
|
std::vector<FewShotExample> examples_;
|
||||||
int verbosity_ = 1;
|
int verbosity_ = 1;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// gui_automation_client.cc
|
// gui_automation_client.cc
|
||||||
// Implementation of gRPC client for YAZE GUI automation
|
// Implementation of gRPC client for YAZE GUI automation
|
||||||
|
|
||||||
#include "cli/service/gui_automation_client.h"
|
#include "cli/service/gui/gui_automation_client.h"
|
||||||
|
|
||||||
#include "absl/strings/str_cat.h"
|
#include "absl/strings/str_cat.h"
|
||||||
#include "absl/strings/str_format.h"
|
#include "absl/strings/str_format.h"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "cli/service/policy_evaluator.h"
|
#include "cli/service/planning/policy_evaluator.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
#include "absl/strings/numbers.h"
|
#include "absl/strings/numbers.h"
|
||||||
#include "absl/strings/str_format.h"
|
#include "absl/strings/str_format.h"
|
||||||
#include "absl/strings/str_split.h"
|
#include "absl/strings/str_split.h"
|
||||||
#include "cli/service/proposal_registry.h"
|
#include "cli/service/planning/proposal_registry.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace cli {
|
namespace cli {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "cli/service/proposal_registry.h"
|
#include "cli/service/planning/proposal_registry.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "cli/service/tile16_proposal_generator.h"
|
#include "cli/service/planning/tile16_proposal_generator.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "cli/service/resource_catalog.h"
|
#include "cli/service/resources/resource_catalog.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "cli/service/resource_context_builder.h"
|
#include "cli/service/resources/resource_context_builder.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "cli/service/rom_sandbox_manager.h"
|
#include "cli/service/rom/rom_sandbox_manager.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "absl/strings/string_view.h"
|
#include "absl/strings/string_view.h"
|
||||||
#include "absl/time/time.h"
|
#include "absl/time/time.h"
|
||||||
#include "cli/service/gui_automation_client.h"
|
#include "cli/service/gui/gui_automation_client.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace cli {
|
namespace cli {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "cli/service/test_suite_loader.h"
|
#include "cli/service/testing/test_suite_loader.h"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "absl/status/statusor.h"
|
#include "absl/status/statusor.h"
|
||||||
#include "absl/strings/string_view.h"
|
#include "absl/strings/string_view.h"
|
||||||
#include "cli/service/test_suite.h"
|
#include "cli/service/testing/test_suite.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace cli {
|
namespace cli {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "cli/service/test_suite_reporter.h"
|
#include "cli/service/testing/test_suite_reporter.h"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "absl/status/statusor.h"
|
#include "absl/status/statusor.h"
|
||||||
#include "cli/service/test_suite.h"
|
#include "cli/service/testing/test_suite.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace cli {
|
namespace cli {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "cli/service/test_suite_writer.h"
|
#include "cli/service/testing/test_suite_writer.h"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "cli/service/test_suite.h"
|
#include "cli/service/testing/test_suite.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace cli {
|
namespace cli {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// test_workflow_generator.cc
|
// test_workflow_generator.cc
|
||||||
// Implementation of natural language to test workflow conversion
|
// Implementation of natural language to test workflow conversion
|
||||||
|
|
||||||
#include "cli/service/test_workflow_generator.h"
|
#include "cli/service/testing/test_workflow_generator.h"
|
||||||
|
|
||||||
#include "absl/strings/ascii.h"
|
#include "absl/strings/ascii.h"
|
||||||
#include "absl/strings/match.h"
|
#include "absl/strings/match.h"
|
||||||
@@ -47,25 +47,25 @@ add_executable(
|
|||||||
cli/handlers/agent/test_common.cc
|
cli/handlers/agent/test_common.cc
|
||||||
cli/handlers/agent/test_commands.cc
|
cli/handlers/agent/test_commands.cc
|
||||||
cli/handlers/agent/gui_commands.cc
|
cli/handlers/agent/gui_commands.cc
|
||||||
cli/service/ai_service.cc
|
cli/service/ai/ai_service.cc
|
||||||
cli/service/ollama_ai_service.cc
|
cli/service/ai/ollama_ai_service.cc
|
||||||
cli/service/prompt_builder.cc
|
cli/service/ai/prompt_builder.cc
|
||||||
cli/service/proposal_registry.cc
|
cli/service/planning/proposal_registry.cc
|
||||||
cli/service/resource_catalog.cc
|
cli/service/resources/resource_catalog.cc
|
||||||
cli/service/rom_sandbox_manager.cc
|
cli/service/rom/rom_sandbox_manager.cc
|
||||||
cli/service/policy_evaluator.cc
|
cli/service/planning/policy_evaluator.cc
|
||||||
cli/service/test_suite.h
|
cli/service/testing/test_suite.h
|
||||||
cli/service/test_suite_loader.cc
|
cli/service/testing/test_suite_loader.cc
|
||||||
cli/service/test_suite_loader.h
|
cli/service/testing/test_suite_loader.h
|
||||||
cli/service/test_suite_reporter.cc
|
cli/service/testing/test_suite_reporter.cc
|
||||||
cli/service/test_suite_reporter.h
|
cli/service/testing/test_suite_reporter.h
|
||||||
cli/service/test_suite_writer.cc
|
cli/service/testing/test_suite_writer.cc
|
||||||
cli/service/test_suite_writer.h
|
cli/service/testing/test_suite_writer.h
|
||||||
cli/service/gemini_ai_service.cc
|
cli/service/ai/gemini_ai_service.cc
|
||||||
cli/service/tile16_proposal_generator.h
|
cli/service/planning/tile16_proposal_generator.h
|
||||||
cli/service/tile16_proposal_generator.cc
|
cli/service/planning/tile16_proposal_generator.cc
|
||||||
cli/service/resource_context_builder.h
|
cli/service/resources/resource_context_builder.h
|
||||||
cli/service/resource_context_builder.cc
|
cli/service/resources/resource_context_builder.cc
|
||||||
app/rom.cc
|
app/rom.cc
|
||||||
app/core/project.cc
|
app/core/project.cc
|
||||||
app/core/asar_wrapper.cc
|
app/core/asar_wrapper.cc
|
||||||
@@ -83,8 +83,8 @@ if(YAZE_WITH_JSON)
|
|||||||
add_subdirectory(${CMAKE_SOURCE_DIR}/third_party/json ${CMAKE_BINARY_DIR}/third_party/json)
|
add_subdirectory(${CMAKE_SOURCE_DIR}/third_party/json ${CMAKE_BINARY_DIR}/third_party/json)
|
||||||
target_compile_definitions(z3ed PRIVATE YAZE_WITH_JSON)
|
target_compile_definitions(z3ed PRIVATE YAZE_WITH_JSON)
|
||||||
target_link_libraries(z3ed PRIVATE nlohmann_json::nlohmann_json)
|
target_link_libraries(z3ed PRIVATE nlohmann_json::nlohmann_json)
|
||||||
list(APPEND Z3ED_SRC_FILES cli/service/gemini_ai_service.cc)
|
list(APPEND Z3ED_SRC_FILES cli/service/ai/gemini_ai_service.cc)
|
||||||
list(APPEND Z3ED_SRC_FILES cli/service/prompt_builder.cc)
|
list(APPEND Z3ED_SRC_FILES cli/service/ai/prompt_builder.cc)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
@@ -162,10 +162,10 @@ if(YAZE_WITH_GRPC)
|
|||||||
|
|
||||||
# Add CLI gRPC service sources
|
# Add CLI gRPC service sources
|
||||||
target_sources(z3ed PRIVATE
|
target_sources(z3ed PRIVATE
|
||||||
${CMAKE_SOURCE_DIR}/src/cli/service/gui_automation_client.cc
|
${CMAKE_SOURCE_DIR}/src/cli/service/gui/gui_automation_client.cc
|
||||||
${CMAKE_SOURCE_DIR}/src/cli/service/gui_automation_client.h
|
${CMAKE_SOURCE_DIR}/src/cli/service/gui/gui_automation_client.h
|
||||||
${CMAKE_SOURCE_DIR}/src/cli/service/test_workflow_generator.cc
|
${CMAKE_SOURCE_DIR}/src/cli/service/testing/test_workflow_generator.cc
|
||||||
${CMAKE_SOURCE_DIR}/src/cli/service/test_workflow_generator.h)
|
${CMAKE_SOURCE_DIR}/src/cli/service/testing/test_workflow_generator.h)
|
||||||
|
|
||||||
# Link gRPC libraries
|
# Link gRPC libraries
|
||||||
target_link_libraries(z3ed PRIVATE
|
target_link_libraries(z3ed PRIVATE
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ if(YAZE_BUILD_TESTS AND NOT YAZE_BUILD_TESTS STREQUAL "OFF")
|
|||||||
unit/zelda3/dungeon_component_unit_test.cc
|
unit/zelda3/dungeon_component_unit_test.cc
|
||||||
|
|
||||||
# CLI Services (for catalog serialization tests)
|
# CLI Services (for catalog serialization tests)
|
||||||
../src/cli/service/resource_catalog.cc
|
../src/cli/service/resources/resource_catalog.cc
|
||||||
|
|
||||||
# Integration Tests
|
# Integration Tests
|
||||||
integration/asar_integration_test.cc
|
integration/asar_integration_test.cc
|
||||||
@@ -98,7 +98,7 @@ if(YAZE_BUILD_TESTS AND NOT YAZE_BUILD_TESTS STREQUAL "OFF")
|
|||||||
unit/zelda3/dungeon_component_unit_test.cc
|
unit/zelda3/dungeon_component_unit_test.cc
|
||||||
|
|
||||||
# CLI Services (for catalog serialization tests)
|
# CLI Services (for catalog serialization tests)
|
||||||
../src/cli/service/resource_catalog.cc
|
../src/cli/service/resources/resource_catalog.cc
|
||||||
|
|
||||||
# Integration Tests
|
# Integration Tests
|
||||||
integration/asar_integration_test.cc
|
integration/asar_integration_test.cc
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "cli/service/resource_catalog.h"
|
#include "cli/service/resources/resource_catalog.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|||||||
Reference in New Issue
Block a user