diff --git a/src/cli/handlers/agent/general_commands.cc b/src/cli/handlers/agent/general_commands.cc index e62b52fc..763787d1 100644 --- a/src/cli/handlers/agent/general_commands.cc +++ b/src/cli/handlers/agent/general_commands.cc @@ -624,24 +624,44 @@ absl::Status HandleSimpleChatCommand(const std::vector& arg_vec, // Try to load project and labels automatically auto _ = TryLoadProjectAndLabels(rom); // Ignore errors - we'll use defaults - // Parse flags + // Parse flags and positional arguments std::optional batch_file; + std::optional single_message; + bool non_interactive = false; + for (size_t i = 0; i < arg_vec.size(); ++i) { const std::string& arg = arg_vec[i]; + if (absl::StartsWith(arg, "--file=")) { batch_file = arg.substr(7); } else if (arg == "--file" && i + 1 < arg_vec.size()) { batch_file = arg_vec[i + 1]; ++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; session.SetRomContext(&rom); + // Priority: batch file > single message > interactive/piped if (batch_file.has_value()) { 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 { + // Interactive or piped input mode return session.RunInteractive(); } } diff --git a/src/cli/modern_cli.cc b/src/cli/modern_cli.cc index bf55ce79..5a31a2ac 100644 --- a/src/cli/modern_cli.cc +++ b/src/cli/modern_cli.cc @@ -74,10 +74,18 @@ void ModernCLI::SetupCommands() { " → Ask about rooms, sprites, entrances, items naturally\n" " → Example: 'What sprites are in room 5?' or 'List all dungeons'\n" "\n" - "💡 SIMPLE CHAT MODE:\n" - " z3ed agent simple-chat \"\" [--rom=]\n" - " → Quick AI queries with automatic ROM loading\n" - " → Example: z3ed agent simple-chat \"describe entrance 0\"\n" + "💡 SIMPLE CHAT MODE (Multiple input methods):\n" + " # Single message\n" + " z3ed agent simple-chat \"\" --rom=\n" + " \n" + " # Interactive session\n" + " z3ed agent simple-chat --rom=\n" + " \n" + " # Piped input\n" + " echo \"What is room 5?\" | z3ed agent simple-chat --rom=\n" + " \n" + " # Batch file (one question per line)\n" + " z3ed agent simple-chat --file=questions.txt --rom=\n" "\n" "🎯 ADVANCED CHAT MODE:\n" " z3ed agent chat \"\" [--host=] [--port=]\n" diff --git a/src/cli/service/agent/simple_chat_session.h b/src/cli/service/agent/simple_chat_session.h index c58bf691..4371fb10 100644 --- a/src/cli/service/agent/simple_chat_session.h +++ b/src/cli/service/agent/simple_chat_session.h @@ -20,6 +20,12 @@ namespace agent { * * Provides a basic REPL-style interface without FTXUI dependencies, * 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 { public: @@ -33,6 +39,7 @@ class SimpleChatSession { std::string* response_out = nullptr); // Run interactive REPL mode (reads from stdin) + // If stdin is piped, runs in quiet mode absl::Status RunInteractive(); // Run batch mode from file (one message per line)