7#include "absl/strings/str_format.h"
8#include "absl/strings/str_join.h"
15 const std::vector<uint8_t>& data, uint32_t address,
24 response.
summary = absl::StrFormat(
"Address 0x%06X contains %s (%zu bytes)",
25 address, data_type, data.size());
28 std::ostringstream detailed;
29 detailed << absl::StrFormat(
"Raw hex at 0x%06X:\n", address);
30 for (
size_t i = 0; i < data.size(); i += 16) {
31 detailed << absl::StrFormat(
"%06X: ", address + i);
32 for (
size_t j = i; j < std::min(i + 16, data.size()); ++j) {
33 detailed << absl::StrFormat(
"%02X ", data[j]);
36 for (
size_t j = i; j < std::min(i + 16, data.size()); ++j) {
38 detailed << (isprint(c) ? c :
'.');
43 if (!patterns.empty()) {
44 detailed <<
"\nDetected patterns:\n";
45 for (
const auto& pattern : patterns) {
46 detailed <<
"- " << pattern <<
"\n";
53 if (data_type.find(
"sprite") != std::string::npos) {
55 "Use resource-list --type=sprite to identify sprite IDs";
56 }
else if (data_type.find(
"tile") != std::string::npos) {
58 "Use overworld-find-tile to see where this tile appears";
59 }
else if (data_type.find(
"palette") != std::string::npos) {
61 "Use palette-get-colors for a generic preview, or "
62 "dungeon-get-palette with a room ID to resolve shared dungeon scope";
64 response.
next_steps =
"Use hex-search to find similar patterns in ROM";
71 const std::string& edit_intent,
const RouteContext& ctx) {
75 response.
summary =
"Preparing map edit operation";
80 "Click(\"Overworld Editor\")",
82 "Click(canvas, x, y)",
83 "SelectTile(tile_id)",
84 "Click(target_x, target_y)",
86 "Screenshot(\"after_edit.png\")",
90 response.
next_steps =
"Review proposed changes, then approve or modify";
96 const std::vector<uint16_t>& colors,
const RouteContext& ctx) {
100 int unique_colors = 0;
101 std::map<uint16_t, int> color_counts;
102 for (uint16_t c : colors) {
105 unique_colors = color_counts.size();
107 response.
summary = absl::StrFormat(
"Palette has %zu colors (%d unique)",
108 colors.size(), unique_colors);
111 std::ostringstream detailed;
112 detailed <<
"Color breakdown:\n";
113 for (
size_t i = 0; i < colors.size(); ++i) {
114 uint16_t snes = colors[i];
115 uint8_t r = (snes & 0x1F) << 3;
116 uint8_t g = ((snes >> 5) & 0x1F) << 3;
117 uint8_t b = ((snes >> 10) & 0x1F) << 3;
118 detailed << absl::StrFormat(
" [%zu] $%04X = #%02X%02X%02X\n", i, snes, r,
122 if (color_counts.size() < colors.size()) {
123 detailed <<
"\nDuplicates found - optimization possible\n";
128 "Legacy palette-set-color is preview-only. For a dungeon palette, use "
129 "dungeon-get-palette, then dry-run dungeon-set-palette-color with exact "
130 "CAS values and a Hack Manifest before requesting --write";
136 const std::vector<std::string>& tool_results,
const RouteContext& ctx) {
141 absl::StrFormat(
"Analyzed %zu data sources", tool_results.size());
142 response.
detailed_data = absl::StrJoin(tool_results,
"\n---\n");
151 const std::vector<std::string>& actions) {
152 std::ostringstream script;
153 script <<
"# Generated GUI Automation Script\n";
154 script <<
"test: \"Automated Edit\"\n";
155 script <<
"steps:\n";
156 for (
const auto& action : actions) {
157 script <<
" - " << action <<
"\n";
163 if (data.size() == 8)
164 return "tile16 data";
165 if (data.size() % 3 == 0 && data.size() <= 48)
166 return "sprite data";
167 if (data.size() == 32)
168 return "palette data (16 colors)";
169 if (data.size() > 1000)
170 return "compressed data block";
171 return "unknown data";
175 const std::vector<uint8_t>& data) {
176 std::vector<std::string> patterns;
179 if (data.size() > 2) {
180 bool all_same =
true;
181 for (
size_t i = 1; i < data.size(); ++i) {
182 if (data[i] != data[0]) {
188 patterns.push_back(absl::StrFormat(
"Repeating byte: 0x%02X", data[0]));
193 if (data.size() > 3) {
194 bool ascending =
true, descending =
true;
195 for (
size_t i = 1; i < data.size(); ++i) {
196 if (data[i] != data[i - 1] + 1)
198 if (data[i] != data[i - 1] - 1)
202 patterns.push_back(
"Ascending sequence");
204 patterns.push_back(
"Descending sequence");
212 return "```\n" + raw_data +
"\n```";
static std::string FormatForAgent(const std::string &raw_data)
static RoutedResponse RouteHexAnalysis(const std::vector< uint8_t > &data, uint32_t address, const RouteContext &ctx)
Route hex data analysis response.
static RoutedResponse SynthesizeMultiToolResponse(const std::vector< std::string > &tool_results, const RouteContext &ctx)
Synthesize multi-tool response.
static RoutedResponse RoutePaletteAnalysis(const std::vector< uint16_t > &colors, const RouteContext &ctx)
Route palette analysis response.
static std::vector< std::string > ExtractPatterns(const std::vector< uint8_t > &data)
static std::string GenerateGUIScript(const std::vector< std::string > &actions)
Generate GUI automation script.
static RoutedResponse RouteMapEdit(const std::string &edit_intent, const RouteContext &ctx)
Route map editing response.
static std::string InferDataType(const std::vector< uint8_t > &data)
std::string detailed_data
std::vector< std::string > gui_actions