Skip to content

Commit feb6eae

Browse files
authored
fixes save with context (#3217)
1 parent 027c3c0 commit feb6eae

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

crates/chat-cli/src/cli/chat/cli/persist.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crossterm::style::{
55
};
66

77
use crate::cli::ConversationState;
8+
use crate::cli::chat::context::ContextFilePath;
89
use crate::cli::chat::{
910
ChatError,
1011
ChatSession,
@@ -102,6 +103,21 @@ impl PersistSubcommand {
102103
std::mem::swap(&mut new_state.tool_manager, &mut session.conversation.tool_manager);
103104
std::mem::swap(&mut new_state.mcp_enabled, &mut session.conversation.mcp_enabled);
104105
std::mem::swap(&mut new_state.model_info, &mut session.conversation.model_info);
106+
// For context, we would only take paths that are not in the current agent
107+
// And we'll place them as temporary context
108+
// Note that we are NOT doing the same with hooks because hooks are more
109+
// instrinsically linked to agent and it affects the behavior of an agent
110+
if let Some(cm) = &new_state.context_manager {
111+
if let Some(existing_cm) = &mut session.conversation.context_manager {
112+
let existing_paths = &mut existing_cm.paths;
113+
for incoming_path in &cm.paths {
114+
if !existing_paths.contains(incoming_path) {
115+
existing_paths
116+
.push(ContextFilePath::Session(incoming_path.get_path_as_str().to_string()));
117+
}
118+
}
119+
}
120+
}
105121
std::mem::swap(
106122
&mut new_state.context_manager,
107123
&mut session.conversation.context_manager,

crates/chat-cli/src/cli/chat/context.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ impl Serialize for ContextFilePath {
4141
S: Serializer,
4242
{
4343
match self {
44-
ContextFilePath::Agent(path) => path.serialize(serializer),
45-
ContextFilePath::Session(_) => Err(serde::ser::Error::custom("Session paths are not serialized")),
44+
ContextFilePath::Agent(path) | ContextFilePath::Session(path) => path.serialize(serializer),
4645
}
4746
}
4847
}

0 commit comments

Comments
 (0)