Skip to content

Commit 99fe1db

Browse files
chaynaborsKonippicwoolumWoolum
authored
feat: Chat persistence by directory (#1767)
* Update login copy * chore: fix path to the dashboard README (#1696) * feat: add Windows support for os shim (#1714) Co-authored-by: Woolum <[email protected]> * start telemetry, state, and settings refactor * finish rewrite * finish rewrite * finish rewrite (actually?) * change profile set copy * fix spellcheck lint * finish chat persistence --------- Co-authored-by: Kyosuke Konishi <[email protected]> Co-authored-by: Chris Woolum <[email protected]> Co-authored-by: Woolum <[email protected]>
1 parent e1b92fc commit 99fe1db

File tree

5 files changed

+135
-84
lines changed

5 files changed

+135
-84
lines changed

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ use crate::api_client::model::{
6464
UserInputMessageContext,
6565
};
6666
use crate::cli::chat::util::shared_writer::SharedWriter;
67+
use crate::database::Database;
6768
use crate::mcp_client::Prompt;
6869
use crate::platform::Context;
6970

@@ -222,12 +223,16 @@ impl ConversationState {
222223
}
223224

224225
/// Sets the response message according to the currently set [Self::next_message].
225-
pub fn push_assistant_message(&mut self, message: AssistantMessage) {
226+
pub fn push_assistant_message(&mut self, message: AssistantMessage, database: &mut Database) {
226227
debug_assert!(self.next_message.is_some(), "next_message should exist");
227228
let next_user_message = self.next_message.take().expect("next user message should exist");
228229

229230
self.append_assistant_transcript(&message);
230231
self.history.push_back((next_user_message, message));
232+
233+
if let Ok(cwd) = std::env::current_dir() {
234+
database.set_conversation_by_path(cwd, self).ok();
235+
}
231236
}
232237

233238
/// Returns the conversation id.
@@ -951,7 +956,8 @@ mod tests {
951956
for i in 0..=(MAX_CONVERSATION_STATE_HISTORY_LEN + 100) {
952957
let s = conversation_state.as_sendable_conversation_state(true).await;
953958
assert_conversation_state_invariants(s, i);
954-
conversation_state.push_assistant_message(AssistantMessage::new_response(None, i.to_string()));
959+
conversation_state
960+
.push_assistant_message(AssistantMessage::new_response(None, i.to_string()), &mut database);
955961
conversation_state.set_next_user_message(i.to_string()).await;
956962
}
957963
}
@@ -977,13 +983,14 @@ mod tests {
977983
let s = conversation_state.as_sendable_conversation_state(true).await;
978984
assert_conversation_state_invariants(s, i);
979985

980-
conversation_state.push_assistant_message(AssistantMessage::new_tool_use(None, i.to_string(), vec![
981-
AssistantToolUse {
986+
conversation_state.push_assistant_message(
987+
AssistantMessage::new_tool_use(None, i.to_string(), vec![AssistantToolUse {
982988
id: "tool_id".to_string(),
983989
name: "tool name".to_string(),
984990
args: serde_json::Value::Null,
985-
},
986-
]));
991+
}]),
992+
&mut database,
993+
);
987994
conversation_state.add_tool_results(vec![ToolUseResult {
988995
tool_use_id: "tool_id".to_string(),
989996
content: vec![],
@@ -1005,20 +1012,22 @@ mod tests {
10051012
let s = conversation_state.as_sendable_conversation_state(true).await;
10061013
assert_conversation_state_invariants(s, i);
10071014
if i % 3 == 0 {
1008-
conversation_state.push_assistant_message(AssistantMessage::new_tool_use(None, i.to_string(), vec![
1009-
AssistantToolUse {
1015+
conversation_state.push_assistant_message(
1016+
AssistantMessage::new_tool_use(None, i.to_string(), vec![AssistantToolUse {
10101017
id: "tool_id".to_string(),
10111018
name: "tool name".to_string(),
10121019
args: serde_json::Value::Null,
1013-
},
1014-
]));
1020+
}]),
1021+
&mut database,
1022+
);
10151023
conversation_state.add_tool_results(vec![ToolUseResult {
10161024
tool_use_id: "tool_id".to_string(),
10171025
content: vec![],
10181026
status: ToolResultStatus::Success,
10191027
}]);
10201028
} else {
1021-
conversation_state.push_assistant_message(AssistantMessage::new_response(None, i.to_string()));
1029+
conversation_state
1030+
.push_assistant_message(AssistantMessage::new_response(None, i.to_string()), &mut database);
10221031
conversation_state.set_next_user_message(i.to_string()).await;
10231032
}
10241033
}
@@ -1066,7 +1075,8 @@ mod tests {
10661075

10671076
assert_conversation_state_invariants(s, i);
10681077

1069-
conversation_state.push_assistant_message(AssistantMessage::new_response(None, i.to_string()));
1078+
conversation_state
1079+
.push_assistant_message(AssistantMessage::new_response(None, i.to_string()), &mut database);
10701080
conversation_state.set_next_user_message(i.to_string()).await;
10711081
}
10721082
}
@@ -1134,7 +1144,8 @@ mod tests {
11341144
s.user_input_message.content
11351145
);
11361146

1137-
conversation_state.push_assistant_message(AssistantMessage::new_response(None, i.to_string()));
1147+
conversation_state
1148+
.push_assistant_message(AssistantMessage::new_response(None, i.to_string()), &mut database);
11381149
conversation_state.set_next_user_message(i.to_string()).await;
11391150
}
11401151
}

0 commit comments

Comments
 (0)