yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
advanced_routing.cc
Go to the documentation of this file.
2
3#include <algorithm>
4#include <map>
5#include <sstream>
6
7#include "absl/strings/str_format.h"
8#include "absl/strings/str_join.h"
9
10namespace yaze {
11namespace cli {
12namespace agent {
13
15 const std::vector<uint8_t>& data, uint32_t address,
16 const RouteContext& ctx) {
17 RoutedResponse response;
18
19 // Infer data type
20 std::string data_type = InferDataType(data);
21 auto patterns = ExtractPatterns(data);
22
23 // Summary for user
24 response.summary = absl::StrFormat("Address 0x%06X contains %s (%zu bytes)",
25 address, data_type, data.size());
26
27 // Detailed data for agent with structure hints
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]);
34 }
35 detailed << " | ";
36 for (size_t j = i; j < std::min(i + 16, data.size()); ++j) {
37 char c = data[j];
38 detailed << (isprint(c) ? c : '.');
39 }
40 detailed << "\n";
41 }
42
43 if (!patterns.empty()) {
44 detailed << "\nDetected patterns:\n";
45 for (const auto& pattern : patterns) {
46 detailed << "- " << pattern << "\n";
47 }
48 }
49
50 response.detailed_data = detailed.str();
51
52 // Next steps based on data type
53 if (data_type.find("sprite") != std::string::npos) {
54 response.next_steps =
55 "Use resource-list --type=sprite to identify sprite IDs";
56 } else if (data_type.find("tile") != std::string::npos) {
57 response.next_steps =
58 "Use overworld-find-tile to see where this tile appears";
59 } else if (data_type.find("palette") != std::string::npos) {
60 response.next_steps = "Use palette-get-colors to see full palette";
61 } else {
62 response.next_steps = "Use hex-search to find similar patterns in ROM";
63 }
64
65 return response;
66}
67
69 const std::string& edit_intent, const RouteContext& ctx) {
70 RoutedResponse response;
71
72 // Parse intent and generate action sequence
73 response.summary = "Preparing map edit operation";
74 response.needs_approval = true;
75
76 // Generate GUI automation steps
77 response.gui_actions = {
78 "Click(\"Overworld Editor\")",
79 "Wait(500)",
80 "Click(canvas, x, y)",
81 "SelectTile(tile_id)",
82 "Click(target_x, target_y)",
83 "Wait(100)",
84 "Screenshot(\"after_edit.png\")",
85 };
86
87 response.detailed_data = GenerateGUIScript(response.gui_actions);
88 response.next_steps = "Review proposed changes, then approve or modify";
89
90 return response;
91}
92
94 const std::vector<uint16_t>& colors, const RouteContext& ctx) {
95 RoutedResponse response;
96
97 // Analyze color relationships
98 int unique_colors = 0;
99 std::map<uint16_t, int> color_counts;
100 for (uint16_t c : colors) {
101 color_counts[c]++;
102 }
103 unique_colors = color_counts.size();
104
105 response.summary = absl::StrFormat("Palette has %zu colors (%d unique)",
106 colors.size(), unique_colors);
107
108 // Detailed breakdown
109 std::ostringstream detailed;
110 detailed << "Color breakdown:\n";
111 for (size_t i = 0; i < colors.size(); ++i) {
112 uint16_t snes = colors[i];
113 uint8_t r = (snes & 0x1F) << 3;
114 uint8_t g = ((snes >> 5) & 0x1F) << 3;
115 uint8_t b = ((snes >> 10) & 0x1F) << 3;
116 detailed << absl::StrFormat(" [%zu] $%04X = #%02X%02X%02X\n", i, snes, r,
117 g, b);
118 }
119
120 if (color_counts.size() < colors.size()) {
121 detailed << "\nDuplicates found - optimization possible\n";
122 }
123
124 response.detailed_data = detailed.str();
125 response.next_steps = "Use palette-set-color to modify colors";
126
127 return response;
128}
129
131 const std::vector<std::string>& tool_results, const RouteContext& ctx) {
132 RoutedResponse response;
133
134 // Combine results intelligently
135 response.summary =
136 absl::StrFormat("Analyzed %zu data sources", tool_results.size());
137 response.detailed_data = absl::StrJoin(tool_results, "\n---\n");
138
139 // Generate insights
140 response.next_steps = "Analysis complete. " + ctx.user_intent;
141
142 return response;
143}
144
146 const std::vector<std::string>& actions) {
147 std::ostringstream script;
148 script << "# Generated GUI Automation Script\n";
149 script << "test: \"Automated Edit\"\n";
150 script << "steps:\n";
151 for (const auto& action : actions) {
152 script << " - " << action << "\n";
153 }
154 return script.str();
155}
156
157std::string AdvancedRouter::InferDataType(const std::vector<uint8_t>& data) {
158 if (data.size() == 8)
159 return "tile16 data";
160 if (data.size() % 3 == 0 && data.size() <= 48)
161 return "sprite data";
162 if (data.size() == 32)
163 return "palette data (16 colors)";
164 if (data.size() > 1000)
165 return "compressed data block";
166 return "unknown data";
167}
168
169std::vector<std::string> AdvancedRouter::ExtractPatterns(
170 const std::vector<uint8_t>& data) {
171 std::vector<std::string> patterns;
172
173 // Check for repeating bytes
174 if (data.size() > 2) {
175 bool all_same = true;
176 for (size_t i = 1; i < data.size(); ++i) {
177 if (data[i] != data[0]) {
178 all_same = false;
179 break;
180 }
181 }
182 if (all_same) {
183 patterns.push_back(absl::StrFormat("Repeating byte: 0x%02X", data[0]));
184 }
185 }
186
187 // Check for ascending/descending sequences
188 if (data.size() > 3) {
189 bool ascending = true, descending = true;
190 for (size_t i = 1; i < data.size(); ++i) {
191 if (data[i] != data[i - 1] + 1)
192 ascending = false;
193 if (data[i] != data[i - 1] - 1)
194 descending = false;
195 }
196 if (ascending)
197 patterns.push_back("Ascending sequence");
198 if (descending)
199 patterns.push_back("Descending sequence");
200 }
201
202 return patterns;
203}
204
205std::string AdvancedRouter::FormatForAgent(const std::string& raw_data) {
206 // Format data for easy agent consumption
207 return "```\n" + raw_data + "\n```";
208}
209
210} // namespace agent
211} // namespace cli
212} // namespace yaze
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)