yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
agent.cc
Go to the documentation of this file.
2#include "cli/cli.h"
3
4#include <algorithm>
5#include <sstream>
6#include <string>
7#include <vector>
8
9#include "absl/flags/declare.h"
10#include "absl/flags/flag.h"
11#include "absl/status/status.h"
12#include "absl/strings/str_cat.h"
13#include "app/rom.h"
18
19ABSL_DECLARE_FLAG(bool, quiet);
20
21namespace yaze {
22namespace cli {
23
24// Forward declarations for special agent commands (not in registry)
25namespace agent {
26absl::Status HandleRunCommand(const std::vector<std::string>& args, Rom& rom);
27absl::Status HandlePlanCommand(const std::vector<std::string>& args);
28absl::Status HandleTestCommand(const std::vector<std::string>& args);
29absl::Status HandleTestConversationCommand(const std::vector<std::string>& args);
30absl::Status HandleLearnCommand(const std::vector<std::string>& args);
31absl::Status HandleListCommand();
32absl::Status HandleDiffCommand(Rom& rom, const std::vector<std::string>& args);
33absl::Status HandleCommitCommand(Rom& rom);
34absl::Status HandleRevertCommand(Rom& rom);
35absl::Status HandleAcceptCommand(const std::vector<std::string>& args, Rom& rom);
36absl::Status HandleDescribeCommand(const std::vector<std::string>& args);
37} // namespace agent
38
39namespace {
40
42 static Rom rom;
43 return rom;
44}
45
46std::string GenerateAgentHelp() {
47 auto& registry = CommandRegistry::Instance();
48
49 std::ostringstream help;
50 help << "Usage: agent <subcommand> [options]\n\n";
51
52 help << "AI-Powered Agent Commands:\n";
53 help << " simple-chat Interactive AI chat\n";
54 help << " test-conversation Automated test conversation\n";
55 help << " plan Generate execution plan\n";
56 help << " run Execute plan in sandbox\n";
57 help << " diff Review the latest proposal diff\n";
58 help << " accept Apply proposal changes to ROM\n";
59 help << " commit Save current ROM changes\n";
60 help << " revert Reload ROM from disk\n";
61 help << " learn Manage learned knowledge\n";
62 help << " todo Task management\n";
63 help << " test Run tests\n";
64 help << " list/describe List/describe proposals\n\n";
65
66 // Auto-list available tool commands from registry
67 help << "Tool Commands (AI can call these):\n";
68 auto agent_commands = registry.GetAgentCommands();
69 const size_t preview_count = std::min<size_t>(10, agent_commands.size());
70 for (size_t i = 0; i < preview_count; ++i) {
71 const auto& cmd = agent_commands[i];
72 if (auto* meta = registry.GetMetadata(cmd); meta != nullptr) {
73 help << " " << cmd;
74 for (size_t pad = cmd.length(); pad < 24; ++pad) help << " ";
75 help << meta->description << "\n";
76 }
77 }
78 if (agent_commands.size() > preview_count) {
79 help << " ... and " << (agent_commands.size() - preview_count)
80 << " more (see z3ed --list-commands)\n";
81 }
82 help << "\n";
83
84 help << "Global Options:\n";
85 help << " --rom=<path> Path to ROM file\n";
86 help << " --ai_provider=<name> AI provider: ollama | gemini\n";
87 help << " --format=<type> Output format: text | json\n\n";
88
89 help << "For detailed help: z3ed agent <command> --help\n";
90 help << "For all commands: z3ed --list-commands\n";
91
92 return help.str();
93}
94
95constexpr absl::string_view kUsage = "";
96
97} // namespace
98
99namespace handlers {
100
109absl::Status HandleAgentCommand(const std::vector<std::string>& arg_vec) {
110 if (arg_vec.empty()) {
111 std::cout << GenerateAgentHelp();
112 return absl::InvalidArgumentError("No subcommand specified");
113 }
114
115 const std::string& subcommand = arg_vec[0];
116 std::vector<std::string> subcommand_args(arg_vec.begin() + 1, arg_vec.end());
117
118 // === Special Agent Commands (not in registry) ===
119
120 if (subcommand == "simple-chat" || subcommand == "chat") {
121 auto& registry = CommandRegistry::Instance();
122 return registry.Execute("simple-chat", subcommand_args, nullptr);
123 }
124
125 auto& agent_rom = AgentRom();
126
127 if (subcommand == "run") {
128 return agent::HandleRunCommand(subcommand_args, agent_rom);
129 }
130
131 if (subcommand == "plan") {
132 return agent::HandlePlanCommand(subcommand_args);
133 }
134
135 if (subcommand == "diff") {
136 return agent::HandleDiffCommand(agent_rom, subcommand_args);
137 }
138
139 if (subcommand == "accept") {
140 return agent::HandleAcceptCommand(subcommand_args, agent_rom);
141 }
142
143 if (subcommand == "commit") {
144 return agent::HandleCommitCommand(agent_rom);
145 }
146
147 if (subcommand == "revert") {
148 return agent::HandleRevertCommand(agent_rom);
149 }
150
151 if (subcommand == "test") {
152 return agent::HandleTestCommand(subcommand_args);
153 }
154
155 if (subcommand == "test-conversation") {
156 return agent::HandleTestConversationCommand(subcommand_args);
157 }
158
159 if (subcommand == "gui") {
160 // GUI commands are in the registry (gui-place-tile, gui-click, etc.)
161 // Route to registry instead
162 return absl::InvalidArgumentError(
163 "Use 'z3ed gui-<command>' or see 'z3ed --help gui' for available GUI automation commands");
164 }
165
166 if (subcommand == "learn") {
167 return agent::HandleLearnCommand(subcommand_args);
168 }
169
170 if (subcommand == "todo") {
171 return handlers::HandleTodoCommand(subcommand_args);
172 }
173
174 if (subcommand == "list") {
176 }
177
178 if (subcommand == "describe") {
179 return agent::HandleDescribeCommand(subcommand_args);
180 }
181
182 // === Registry Commands (resource, dungeon, overworld, emulator, etc.) ===
183
184 auto& registry = CommandRegistry::Instance();
185
186 // Check if this is a registered command
187 if (registry.HasCommand(subcommand)) {
188 return registry.Execute(subcommand, subcommand_args, nullptr);
189 }
190
191 // Not found
192 std::cout << GenerateAgentHelp();
193 return absl::InvalidArgumentError(
194 absl::StrCat("Unknown agent command: ", subcommand));
195}
196
197// Handler implementations live in general_commands.cc
198
199} // namespace handlers
200} // namespace cli
201} // namespace yaze
ABSL_DECLARE_FLAG(bool, quiet)
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:74
static CommandRegistry & Instance()
absl::Status HandleLearnCommand(const std::vector< std::string > &args)
absl::Status HandleAcceptCommand(const std::vector< std::string > &args, Rom &rom)
absl::Status HandleTestConversationCommand(const std::vector< std::string > &args)
absl::Status HandleRunCommand(const std::vector< std::string > &args, Rom &rom)
absl::Status HandleTestCommand(const std::vector< std::string > &args)
absl::Status HandleCommitCommand(Rom &rom)
absl::Status HandleDescribeCommand(const std::vector< std::string > &args)
absl::Status HandleDiffCommand(Rom &rom, const std::vector< std::string > &args)
absl::Status HandleRevertCommand(Rom &rom)
absl::Status HandleListCommand()
absl::Status HandlePlanCommand(const std::vector< std::string > &args)
constexpr absl::string_view kUsage
Definition agent.cc:95
absl::Status HandleAgentCommand(const std::vector< std::string > &args)
Unified agent command handler using CommandRegistry.
Definition agent.cc:109
absl::Status HandleTodoCommand(const std::vector< std::string > &args)
Handle z3ed agent todo commands.
Main namespace for the application.
Definition controller.cc:20