feat: Enhance simple chat command to support multiple input modes including batch files and single messages

This commit is contained in:
scawful
2025-10-04 02:29:15 -04:00
parent 2fb96cbbfd
commit f39ce79048
3 changed files with 40 additions and 5 deletions

View File

@@ -624,24 +624,44 @@ absl::Status HandleSimpleChatCommand(const std::vector<std::string>& arg_vec,
// Try to load project and labels automatically // Try to load project and labels automatically
auto _ = TryLoadProjectAndLabels(rom); // Ignore errors - we'll use defaults auto _ = TryLoadProjectAndLabels(rom); // Ignore errors - we'll use defaults
// Parse flags // Parse flags and positional arguments
std::optional<std::string> batch_file; std::optional<std::string> batch_file;
std::optional<std::string> single_message;
bool non_interactive = false;
for (size_t i = 0; i < arg_vec.size(); ++i) { for (size_t i = 0; i < arg_vec.size(); ++i) {
const std::string& arg = arg_vec[i]; const std::string& arg = arg_vec[i];
if (absl::StartsWith(arg, "--file=")) { if (absl::StartsWith(arg, "--file=")) {
batch_file = arg.substr(7); batch_file = arg.substr(7);
} else if (arg == "--file" && i + 1 < arg_vec.size()) { } else if (arg == "--file" && i + 1 < arg_vec.size()) {
batch_file = arg_vec[i + 1]; batch_file = arg_vec[i + 1];
++i; ++i;
} else if (arg == "--non-interactive" || arg == "-n") {
non_interactive = true;
} else if (!absl::StartsWith(arg, "--") && !single_message.has_value()) {
// Treat first non-flag argument as the message
single_message = arg;
} }
} }
SimpleChatSession session; SimpleChatSession session;
session.SetRomContext(&rom); session.SetRomContext(&rom);
// Priority: batch file > single message > interactive/piped
if (batch_file.has_value()) { if (batch_file.has_value()) {
return session.RunBatch(*batch_file); return session.RunBatch(*batch_file);
} else if (single_message.has_value()) {
// Single message mode - send message and print response
std::string response;
auto status = session.SendAndWaitForResponse(*single_message, &response);
if (!status.ok()) {
return status;
}
std::cout << response << "\n";
return absl::OkStatus();
} else { } else {
// Interactive or piped input mode
return session.RunInteractive(); return session.RunInteractive();
} }
} }

View File

@@ -74,10 +74,18 @@ void ModernCLI::SetupCommands() {
" → Ask about rooms, sprites, entrances, items naturally\n" " → Ask about rooms, sprites, entrances, items naturally\n"
" → Example: 'What sprites are in room 5?' or 'List all dungeons'\n" " → Example: 'What sprites are in room 5?' or 'List all dungeons'\n"
"\n" "\n"
"💡 SIMPLE CHAT MODE:\n" "💡 SIMPLE CHAT MODE (Multiple input methods):\n"
" z3ed agent simple-chat \"<your question>\" [--rom=<path>]\n" " # Single message\n"
" → Quick AI queries with automatic ROM loading\n" " z3ed agent simple-chat \"<your question>\" --rom=<path>\n"
" → Example: z3ed agent simple-chat \"describe entrance 0\"\n" " \n"
" # Interactive session\n"
" z3ed agent simple-chat --rom=<path>\n"
" \n"
" # Piped input\n"
" echo \"What is room 5?\" | z3ed agent simple-chat --rom=<path>\n"
" \n"
" # Batch file (one question per line)\n"
" z3ed agent simple-chat --file=questions.txt --rom=<path>\n"
"\n" "\n"
"🎯 ADVANCED CHAT MODE:\n" "🎯 ADVANCED CHAT MODE:\n"
" z3ed agent chat \"<prompt>\" [--host=<host>] [--port=<port>]\n" " z3ed agent chat \"<prompt>\" [--host=<host>] [--port=<port>]\n"

View File

@@ -20,6 +20,12 @@ namespace agent {
* *
* Provides a basic REPL-style interface without FTXUI dependencies, * Provides a basic REPL-style interface without FTXUI dependencies,
* suitable for automated testing and AI agent interactions. * suitable for automated testing and AI agent interactions.
*
* Supports multiple input modes:
* - Interactive REPL (default when stdin is a TTY)
* - Piped input (reads lines from stdin)
* - Batch file (reads lines from file)
* - Single message (programmatic use)
*/ */
class SimpleChatSession { class SimpleChatSession {
public: public:
@@ -33,6 +39,7 @@ class SimpleChatSession {
std::string* response_out = nullptr); std::string* response_out = nullptr);
// Run interactive REPL mode (reads from stdin) // Run interactive REPL mode (reads from stdin)
// If stdin is piped, runs in quiet mode
absl::Status RunInteractive(); absl::Status RunInteractive();
// Run batch mode from file (one message per line) // Run batch mode from file (one message per line)