|
| 1 | +import re |
| 2 | + |
| 3 | +# Fix panels.rs |
| 4 | +with open('src/app/panels.rs', 'r') as f: |
| 5 | + panels_rs = f.read() |
| 6 | + |
| 7 | +panels_rs = panels_rs.replace("crate::app::frame_average_ms", "crate::app::ui_main::frame_average_ms") |
| 8 | + |
| 9 | +with open('src/app/panels.rs', 'w') as f: |
| 10 | + f.write(panels_rs) |
| 11 | + |
| 12 | + |
| 13 | +# Fix ui_components.rs |
| 14 | +with open('src/app/ui_components.rs', 'r') as f: |
| 15 | + ui_comp = f.read() |
| 16 | + |
| 17 | +ui_comp = ui_comp.replace("use super::state::*;", "use super::state::*;\nuse crate::app::PaletteCommand;\nuse crate::engine::EngineStatus;") |
| 18 | + |
| 19 | +with open('src/app/ui_components.rs', 'w') as f: |
| 20 | + f.write(ui_comp) |
| 21 | + |
| 22 | +# Fix monitor_chatgpt_mcp in ui_main.rs |
| 23 | +# I'll just append it to impl BrazenApp in ui_main.rs |
| 24 | +monitor_code = """ |
| 25 | + pub(super) fn monitor_chatgpt_mcp(&mut self) { |
| 26 | + if !self.shell_state.observe_dom || !self.shell_state.control_terminal { |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + let Some(snapshot) = &self.shell_state.dom_snapshot else { return; }; |
| 31 | + |
| 32 | + // Use scraper to find <client mcp="terminal">...</client> |
| 33 | + let fragment = scraper::Html::parse_fragment(snapshot); |
| 34 | + let selector = scraper::Selector::parse("client[mcp=\\"terminal\\"]").unwrap(); |
| 35 | + |
| 36 | + for element in fragment.select(&selector) { |
| 37 | + let command = element.text().collect::<String>(); |
| 38 | + let command = command.trim(); |
| 39 | + if !command.is_empty() && !self.processed_mcp_commands.contains(command) { |
| 40 | + tracing::info!(target: "brazen::automation", command = %command, "Found new MCP terminal command in DOM"); |
| 41 | + |
| 42 | + // Run command |
| 43 | + if let Some(tx) = &self.terminal_tx { |
| 44 | + let _ = tx.send(command.to_string()); |
| 45 | + } |
| 46 | + |
| 47 | + // Mark as processed |
| 48 | + self.processed_mcp_commands.insert(command.to_string()); |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | +""" |
| 53 | + |
| 54 | +with open('src/app/ui_main.rs', 'r') as f: |
| 55 | + ui_main_rs = f.read() |
| 56 | + |
| 57 | +# insert before last } of impl BrazenApp |
| 58 | +last_brace = ui_main_rs.find("impl eframe::App") |
| 59 | +if last_brace != -1: |
| 60 | + # go back to find the } of impl BrazenApp |
| 61 | + idx = ui_main_rs.rfind("}", 0, last_brace) |
| 62 | + ui_main_rs = ui_main_rs[:idx] + monitor_code + ui_main_rs[idx:] |
| 63 | + |
| 64 | +with open('src/app/ui_main.rs', 'w') as f: |
| 65 | + f.write(ui_main_rs) |
| 66 | + |
| 67 | +print("Errors fixed") |
0 commit comments