Execution working

This commit is contained in:
Dhanji Prasanna
2025-09-05 13:13:41 +10:00
parent 57626042a9
commit 80e5178a1f
2 changed files with 143 additions and 82 deletions

View File

@@ -29,6 +29,7 @@ impl CodeExecutor {
/// Extract code blocks from LLM response and execute them with UI options
pub async fn execute_from_response_with_options(&self, response: &str, show_code: bool) -> Result<String> {
debug!("CodeExecutor received response ({} chars): {}", response.len(), response);
let code_blocks = self.extract_code_blocks(response)?;
if code_blocks.is_empty() {
@@ -89,20 +90,25 @@ impl CodeExecutor {
/// Extract code blocks from markdown-formatted text
fn extract_code_blocks(&self, text: &str) -> Result<Vec<(String, String)>> {
let re = Regex::new(r"```(\w+)?\n(.*?)```")?;
let re = Regex::new(r"(?s)```(\w+)?\n(.*?)```")?;
let mut blocks = Vec::new();
debug!("Extracting code blocks from text: {}", text);
for cap in re.captures_iter(text) {
let language = cap.get(1)
.map(|m| m.as_str().to_lowercase())
.unwrap_or_else(|| "bash".to_string()); // Default to bash
let code = cap.get(2).map(|m| m.as_str()).unwrap_or("").trim();
debug!("Found code block - language: '{}', code: '{}'", language, code);
if !code.is_empty() {
blocks.push((language, code.to_string()));
}
}
debug!("Total code blocks found: {}", blocks.len());
Ok(blocks)
}