fur_cli/commands/
clone.rs1use std::fs;
2use std::path::Path;
3use serde_json::Value;
4use crate::helpers::cloning::{
5 load_conversation_metadata,
6 make_new_conversation_header,
7 build_id_remap,
8 clone_all_messages,
9 write_new_conversation,
10 update_index
11};
12
13pub fn run_clone_from_active(title: Option<String>) {
15 let index_path = Path::new(".fur").join("index.json");
16 let index: Value =
17 serde_json::from_str(&fs::read_to_string(&index_path).unwrap()).unwrap();
18
19 let active_tid = index["active_thread"]
20 .as_str()
21 .expect("❌ No active conversation set");
22
23 run_clone(active_tid, title);
24}
25
26pub fn run_clone(tid: &str, title: Option<String>) {
28 let fur_dir = Path::new(".fur");
29 let old_convo_path = fur_dir.join("threads").join(format!("{}.json", tid));
30
31 if !old_convo_path.exists() {
32 eprintln!("❌ Conversation {} not found.", tid);
33 return;
34 }
35
36 let (old_title, old_messages) = load_conversation_metadata(&old_convo_path);
37
38 let (new_convo_id, new_title, timestamp) =
39 make_new_conversation_header(&old_title, title);
40
41 let id_map = build_id_remap(&old_messages);
42
43 fs::create_dir_all("chats").ok();
44
45 clone_all_messages(&id_map, &old_messages);
46
47 write_new_conversation(
48 &new_convo_id,
49 &new_title,
50 ×tamp,
51 &id_map,
52 &old_messages,
53 );
54
55 update_index(&new_convo_id);
56
57 println!(
58 "🌀 Successfully cloned conversation \"{}\" → new ID {}",
59 old_title,
60 &new_convo_id[..8]
61 );
62}