Lifei/sub recipe desktop temp (#3576)
This commit is contained in:
@@ -193,15 +193,7 @@ async fn collect_results(
|
||||
expected_count: usize,
|
||||
) -> Vec<TaskResult> {
|
||||
let mut results = Vec::new();
|
||||
while let Some(mut result) = result_rx.recv().await {
|
||||
// Truncate data to 650 chars if needed
|
||||
if let Some(data) = result.data.as_mut() {
|
||||
if let Some(data_str) = data.as_str() {
|
||||
if data_str.len() > 650 {
|
||||
*data = serde_json::Value::String(format!("{}...", &data_str[..650]));
|
||||
}
|
||||
}
|
||||
}
|
||||
while let Some(result) = result_rx.recv().await {
|
||||
task_execution_tracker
|
||||
.complete_task(&result.task_id, result.clone())
|
||||
.await;
|
||||
|
||||
@@ -8,6 +8,7 @@ use tokio_util::sync::CancellationToken;
|
||||
|
||||
use crate::agents::subagent_execution_tool::task_execution_tracker::TaskExecutionTracker;
|
||||
use crate::agents::subagent_execution_tool::task_types::{Task, TaskResult, TaskStatus};
|
||||
use crate::agents::subagent_execution_tool::utils::strip_ansi_codes;
|
||||
use crate::agents::subagent_handler::run_complete_subagent_task;
|
||||
use crate::agents::subagent_task_config::TaskConfig;
|
||||
|
||||
@@ -70,7 +71,7 @@ async fn get_task_result(
|
||||
if success {
|
||||
process_output(stdout_output)
|
||||
} else {
|
||||
Err(format!("Command failed:\n{}", stderr_output))
|
||||
Err(format!("Command failed:\n{}", &stderr_output))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -224,6 +225,7 @@ fn spawn_output_reader(
|
||||
let mut buffer = String::new();
|
||||
let mut lines = BufReader::new(reader).lines();
|
||||
while let Ok(Some(line)) = lines.next_line().await {
|
||||
let line = strip_ansi_codes(&line);
|
||||
buffer.push_str(&line);
|
||||
buffer.push('\n');
|
||||
|
||||
|
||||
@@ -23,5 +23,38 @@ pub fn count_by_status(tasks: &HashMap<String, TaskInfo>) -> (usize, usize, usiz
|
||||
(total, pending, running, completed, failed)
|
||||
}
|
||||
|
||||
pub fn strip_ansi_codes(text: &str) -> String {
|
||||
let mut result = String::new();
|
||||
let mut chars = text.chars();
|
||||
|
||||
while let Some(ch) = chars.next() {
|
||||
if ch == '\x1b' {
|
||||
if let Some(next_ch) = chars.next() {
|
||||
if next_ch == '[' {
|
||||
// This is an ANSI escape sequence, consume until alphabetic character
|
||||
loop {
|
||||
match chars.next() {
|
||||
Some(c) if c.is_ascii_alphabetic() => break,
|
||||
Some(_) => continue,
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Not an ANSI sequence, keep both characters
|
||||
result.push(ch);
|
||||
result.push(next_ch);
|
||||
}
|
||||
} else {
|
||||
// End of string after \x1b
|
||||
result.push(ch);
|
||||
}
|
||||
} else {
|
||||
result.push(ch);
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use crate::agents::subagent_execution_tool::task_types::{Task, TaskInfo, TaskStatus};
|
||||
use crate::agents::subagent_execution_tool::utils::{count_by_status, get_task_name};
|
||||
use crate::agents::subagent_execution_tool::utils::{
|
||||
count_by_status, get_task_name, strip_ansi_codes,
|
||||
};
|
||||
use serde_json::json;
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -152,3 +154,24 @@ mod count_by_status {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod strip_ansi_codes {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_strip_ansi_codes() {
|
||||
assert_eq!(strip_ansi_codes("hello world"), "hello world");
|
||||
assert_eq!(strip_ansi_codes("\x1b[31mred text\x1b[0m"), "red text");
|
||||
assert_eq!(
|
||||
strip_ansi_codes("\x1b[1;32mbold green\x1b[0m"),
|
||||
"bold green"
|
||||
);
|
||||
assert_eq!(
|
||||
strip_ansi_codes("normal\x1b[33myellow\x1b[0mnormal"),
|
||||
"normalyellownormal"
|
||||
);
|
||||
assert_eq!(strip_ansi_codes("\x1bhello"), "\x1bhello");
|
||||
assert_eq!(strip_ansi_codes("hello\x1b"), "hello\x1b");
|
||||
assert_eq!(strip_ansi_codes(""), "");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user