feat: Enhance chat command with multiple output formats and improve help documentation

- Updated the chat command to support new output formats: text, markdown, json, and compact.
- Modified the agent configuration to include output format settings.
- Enhanced the command line interface to handle new format options and provide detailed usage instructions.
- Improved the message printing logic in SimpleChatSession to format output based on the selected format.
- Added JSON and Markdown formatting for session metrics and messages.
- Updated help documentation to reflect changes in command usage and available options.
This commit is contained in:
scawful
2025-10-04 13:33:19 -04:00
parent 0db71a71fe
commit 6990e565b8
8 changed files with 736 additions and 75 deletions

View File

@@ -73,7 +73,7 @@ constexpr absl::string_view kUsage =
" --ai_model=<name> Model name (e.g., qwen2.5-coder:7b for Ollama)\n"
" --ollama_host=<url> Ollama server URL (default: http://localhost:11434)\n"
" --gemini_api_key=<key> Gemini API key (or set GEMINI_API_KEY env var)\n"
" --format=<type> Output format: json | table | yaml\n"
" --format=<type> Output format: text | markdown | json | compact\n"
"\n"
"For more details, see: docs/simple_chat_input_methods.md";

View File

@@ -12,13 +12,14 @@
#include "absl/flags/declare.h"
#include "absl/flags/flag.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/status/status.h"
#include "absl/strings/ascii.h"
#include "absl/strings/match.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_join.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "absl/strings/string_view.h"
#include "app/core/project.h"
#include "app/zelda3/dungeon/room.h"
@@ -533,6 +534,7 @@ absl::Status HandleSimpleChatCommand(const std::vector<std::string>& arg_vec,
std::optional<std::string> batch_file;
std::optional<std::string> single_message;
bool verbose = false;
std::optional<std::string> format_option;
for (size_t i = 0; i < arg_vec.size(); ++i) {
const std::string& arg = arg_vec[i];
@@ -540,6 +542,16 @@ absl::Status HandleSimpleChatCommand(const std::vector<std::string>& arg_vec,
batch_file = arg.substr(7);
} else if (arg == "--file" && i + 1 < arg_vec.size()) {
batch_file = arg_vec[++i];
} else if (absl::StartsWith(arg, "--format=")) {
format_option = arg.substr(9);
} else if (arg == "--format" && i + 1 < arg_vec.size()) {
format_option = arg_vec[++i];
} else if (arg == "--json") {
format_option = "json";
} else if (arg == "--markdown" || arg == "--md") {
format_option = "markdown";
} else if (arg == "--compact" || arg == "--raw") {
format_option = "compact";
} else if (arg == "--verbose" || arg == "-v") {
verbose = true;
} else if (!absl::StartsWith(arg, "--") && !single_message.has_value()) {
@@ -549,6 +561,23 @@ absl::Status HandleSimpleChatCommand(const std::vector<std::string>& arg_vec,
agent::AgentConfig config;
config.verbose = verbose;
if (format_option.has_value()) {
std::string normalized = absl::AsciiStrToLower(*format_option);
if (normalized == "json") {
config.output_format = AgentOutputFormat::kJson;
} else if (normalized == "markdown" || normalized == "md") {
config.output_format = AgentOutputFormat::kMarkdown;
} else if (normalized == "compact" || normalized == "raw") {
config.output_format = AgentOutputFormat::kCompact;
} else if (normalized == "text" || normalized == "friendly" ||
normalized == "pretty") {
config.output_format = AgentOutputFormat::kFriendly;
} else {
return absl::InvalidArgumentError(
absl::StrCat("Unsupported chat format: ", *format_option,
". Supported formats: text, markdown, json, compact"));
}
}
SimpleChatSession session;
session.SetConfig(config);