Skip to content

fix: inconsistency in /save and /load behavior with regard to file ex… #1939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion crates/cli/src/cli/chat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down