Refactor view modules for improved readability and consistency
- Updated markdown rendering logic to use more concise methods for obtaining vector lengths. - Changed review status display to use the correct flag from settings. - Cleaned up sidebar rendering code for better formatting and readability. - Enhanced status bar rendering with improved string formatting and consistent style application. - Refined workflow panel rendering, ensuring consistent style usage and improved readability. - Added architecture overview and detailed documentation for backend, data, dependencies, and frontend structures.
This commit is contained in:
@@ -15,11 +15,10 @@
|
||||
//! `git_operator`, ...) are never touched, even with identical
|
||||
//! arguments, because call order and repetition can be semantically
|
||||
//! meaningful (e.g. retrying a flaky `bash` command until it passes).
|
||||
|
||||
use std::collections::HashMap;
|
||||
use sha2::Digest;
|
||||
use crate::app::subagent::division::tool_scope::READ_TOOLS;
|
||||
use crate::dto::chat::message::{ChatMessage, Role};
|
||||
use sha2::Digest;
|
||||
use std::collections::HashMap;
|
||||
|
||||
const DUPLICATE_PLACEHOLDER: &str =
|
||||
"[duplicate result — superseded by a later identical call, see below]";
|
||||
@@ -50,7 +49,9 @@ pub fn collapse(messages: &[ChatMessage]) -> (Vec<ChatMessage>, bool) {
|
||||
continue;
|
||||
}
|
||||
let Some(id) = &m.tool_call_id else { continue };
|
||||
let Some((name, args)) = call_info.get(id) else { continue };
|
||||
let Some((name, args)) = call_info.get(id) else {
|
||||
continue;
|
||||
};
|
||||
if !READ_TOOLS.contains(&name.as_str()) {
|
||||
continue;
|
||||
}
|
||||
@@ -58,22 +59,30 @@ pub fn collapse(messages: &[ChatMessage]) -> (Vec<ChatMessage>, bool) {
|
||||
}
|
||||
|
||||
let mut changed = false;
|
||||
let result = messages.iter().enumerate().map(|(idx, m)| {
|
||||
if m.role != Role::Tool {
|
||||
return m.clone();
|
||||
}
|
||||
let Some(id) = &m.tool_call_id else { return m.clone() };
|
||||
let Some((name, args)) = call_info.get(id) else { return m.clone() };
|
||||
if !READ_TOOLS.contains(&name.as_str()) {
|
||||
return m.clone();
|
||||
}
|
||||
let key = dedup_key(name, args);
|
||||
if last_index_for_key.get(&key) == Some(&idx) {
|
||||
return m.clone();
|
||||
}
|
||||
changed = true;
|
||||
ChatMessage::tool_result(id.clone(), DUPLICATE_PLACEHOLDER.to_string())
|
||||
}).collect();
|
||||
let result = messages
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(idx, m)| {
|
||||
if m.role != Role::Tool {
|
||||
return m.clone();
|
||||
}
|
||||
let Some(id) = &m.tool_call_id else {
|
||||
return m.clone();
|
||||
};
|
||||
let Some((name, args)) = call_info.get(id) else {
|
||||
return m.clone();
|
||||
};
|
||||
if !READ_TOOLS.contains(&name.as_str()) {
|
||||
return m.clone();
|
||||
}
|
||||
let key = dedup_key(name, args);
|
||||
if last_index_for_key.get(&key) == Some(&idx) {
|
||||
return m.clone();
|
||||
}
|
||||
changed = true;
|
||||
ChatMessage::tool_result(id.clone(), DUPLICATE_PLACEHOLDER.to_string())
|
||||
})
|
||||
.collect();
|
||||
|
||||
(result, changed)
|
||||
}
|
||||
@@ -102,7 +111,10 @@ mod tests {
|
||||
m.tool_calls = Some(vec![ToolCall {
|
||||
id: id.to_string(),
|
||||
type_: "function".to_string(),
|
||||
function: ToolFunction { name: name.to_string(), arguments: args },
|
||||
function: ToolFunction {
|
||||
name: name.to_string(),
|
||||
arguments: args,
|
||||
},
|
||||
}]);
|
||||
m
|
||||
}
|
||||
@@ -172,9 +184,10 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn tool_result_with_no_matching_call_is_left_untouched() {
|
||||
let messages = vec![
|
||||
ChatMessage::tool_result("orphan-id".to_string(), "some result".to_string()),
|
||||
];
|
||||
let messages = vec![ChatMessage::tool_result(
|
||||
"orphan-id".to_string(),
|
||||
"some result".to_string(),
|
||||
)];
|
||||
|
||||
let (result, changed) = collapse(&messages);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user