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