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"
49 std::ostringstream help;
50 help <<
"Usage: agent <subcommand> [options]\n\n";
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";
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) {
74 for (
size_t pad = cmd.length(); pad < 24; ++pad) help <<
" ";
75 help << meta->description <<
"\n";
78 if (agent_commands.size() > preview_count) {
79 help <<
" ... and " << (agent_commands.size() - preview_count)
80 <<
" more (see z3ed --list-commands)\n";
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";
89 help <<
"For detailed help: z3ed agent <command> --help\n";
90 help <<
"For all commands: z3ed --list-commands\n";
95constexpr absl::string_view
kUsage =
"";
110 if (arg_vec.empty()) {
111 std::cout << GenerateAgentHelp();
112 return absl::InvalidArgumentError(
"No subcommand specified");
115 const std::string& subcommand = arg_vec[0];
116 std::vector<std::string> subcommand_args(arg_vec.begin() + 1, arg_vec.end());
120 if (subcommand ==
"simple-chat" || subcommand ==
"chat") {
122 return registry.Execute(
"simple-chat", subcommand_args,
nullptr);
125 auto& agent_rom = AgentRom();
127 if (subcommand ==
"run") {
131 if (subcommand ==
"plan") {
135 if (subcommand ==
"diff") {
139 if (subcommand ==
"accept") {
143 if (subcommand ==
"commit") {
147 if (subcommand ==
"revert") {
151 if (subcommand ==
"test") {
155 if (subcommand ==
"test-conversation") {
159 if (subcommand ==
"gui") {
162 return absl::InvalidArgumentError(
163 "Use 'z3ed gui-<command>' or see 'z3ed --help gui' for available GUI automation commands");
166 if (subcommand ==
"learn") {
170 if (subcommand ==
"todo") {
174 if (subcommand ==
"list") {
178 if (subcommand ==
"describe") {
187 if (registry.HasCommand(subcommand)) {
188 return registry.Execute(subcommand, subcommand_args,
nullptr);
192 std::cout << GenerateAgentHelp();
193 return absl::InvalidArgumentError(
194 absl::StrCat(
"Unknown agent command: ", subcommand));
ABSL_DECLARE_FLAG(bool, quiet)
The Rom class is used to load, save, and modify Rom data.
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
std::string GenerateAgentHelp()
absl::Status HandleAgentCommand(const std::vector< std::string > &args)
Unified agent command handler using CommandRegistry.
absl::Status HandleTodoCommand(const std::vector< std::string > &args)
Handle z3ed agent todo commands.
Main namespace for the application.