From e208c59d02c612f8f6f6db367cd8c857bf8a8686 Mon Sep 17 00:00:00 2001 From: Konippi Date: Fri, 23 May 2025 00:05:44 +0900 Subject: [PATCH] fix: inconsistency in /save and /load behavior with regard to file extensions --- crates/cli/src/cli/chat/mod.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/cli/src/cli/chat/mod.rs b/crates/cli/src/cli/chat/mod.rs index b4bcb8af7..26cbce424 100644 --- a/crates/cli/src/cli/chat/mod.rs +++ b/crates/cli/src/cli/chat/mod.rs @@ -2878,7 +2878,23 @@ impl ChatContext { }; } - let contents = tri!(self.ctx.fs().read_to_string(&path).await); + // Try the original path first + let original_result = self.ctx.fs().read_to_string(&path).await; + + // If the original path fails and doesn't end with .json, try with .json appended + let contents = if original_result.is_err() && !path.ends_with(".json") { + let json_path = format!("{}.json", path); + match self.ctx.fs().read_to_string(&json_path).await { + Ok(content) => content, + Err(_) => { + // If both paths fail, return the original error for better user experience + tri!(original_result) + }, + } + } else { + tri!(original_result) + }; + let mut new_state: ConversationState = tri!(serde_json::from_str(&contents)); new_state .reload_serialized_state(Arc::clone(&self.ctx), Some(self.output.clone()))