@@ -6,6 +6,7 @@ use crossterm::style::{
6
6
Color ,
7
7
} ;
8
8
9
+ use crate :: cli:: ConversationState ;
9
10
use crate :: cli:: chat:: {
10
11
ChatError ,
11
12
ChatSession ,
@@ -74,17 +75,37 @@ impl PersistSubcommand {
74
75
style:: SetAttribute ( Attribute :: Reset )
75
76
) ?;
76
77
} ,
77
- Self :: Load { path : _ } => {
78
- // For profile operations that need a profile name, show profile selector
79
- // As part of the agent implementation, we are disabling the ability to
80
- // switch profile after a session has started.
81
- // TODO: perhaps revive this after we have a decision on profile switching
78
+ Self :: Load { path } => {
79
+ // Try the original path first
80
+ let original_result = os. fs . read_to_string ( & path) . await ;
81
+
82
+ // If the original path fails and doesn't end with .json, try with .json appended
83
+ let contents = if original_result. is_err ( ) && !path. ends_with ( ".json" ) {
84
+ let json_path = format ! ( "{}.json" , path) ;
85
+ match os. fs . read_to_string ( & json_path) . await {
86
+ Ok ( content) => content,
87
+ Err ( _) => {
88
+ // If both paths fail, return the original error for better user experience
89
+ tri ! ( original_result, "import from" , & path)
90
+ } ,
91
+ }
92
+ } else {
93
+ tri ! ( original_result, "import from" , & path)
94
+ } ;
95
+
96
+ let mut new_state: ConversationState = tri ! ( serde_json:: from_str( & contents) , "import from" , & path) ;
97
+ std:: mem:: swap ( & mut new_state. tool_manager , & mut session. conversation . tool_manager ) ;
98
+ std:: mem:: swap (
99
+ & mut new_state. context_manager ,
100
+ & mut session. conversation . context_manager ,
101
+ ) ;
102
+ std:: mem:: swap ( & mut new_state. agents , & mut session. conversation . agents ) ;
103
+ session. conversation = new_state;
104
+
82
105
execute ! (
83
106
session. stderr,
84
- style:: SetForegroundColor ( Color :: Yellow ) ,
85
- style:: Print (
86
- "Conversation loading has been disabled. To load a conversation. Quit and restart q chat."
87
- ) ,
107
+ style:: SetForegroundColor ( Color :: Green ) ,
108
+ style:: Print ( format!( "\n ✔ Imported conversation state from {}\n \n " , & path) ) ,
88
109
style:: SetAttribute ( Attribute :: Reset )
89
110
) ?;
90
111
} ,
0 commit comments