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