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