Skip to content

Commit c6388a9

Browse files
committed
patch cloning bug; now creates unique deep copies with suffix trick
1 parent 12ec1ab commit c6388a9

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fur-cli"
3-
version = "1.2.0"
3+
version = "1.2.1"
44
edition = "2021"
55
authors = ["Andrew Garcia"]
66
description = "Turn your AI chats into a durable, local-first diary. Save messages, attach notes, organize conversations, and stop losing context every time the model forgets you exist."

src/helpers/cloning.rs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,46 @@ pub fn clone_markdown_if_any(old_msg: &Value) -> Option<String> {
9696
let old_md_path = PathBuf::from(md_raw);
9797

9898
if old_md_path.exists() {
99-
let ts = Utc::now().format("CHAT-%Y%m%d-%H%M%S.md").to_string();
100-
let new_md = format!("chats/{}", ts);
101-
fs::copy(&old_md_path, &new_md).expect("❌ Failed to copy markdown file");
102-
return Some(new_md);
99+
// Extract the base filename
100+
let filename = old_md_path.file_name()?.to_string_lossy();
101+
102+
// Detect clone-depth (count trailing 'c')
103+
let stem = filename.trim_end_matches(".md");
104+
let (base, existing_c_suffix) = split_clone_suffix(stem);
105+
106+
// Generate the new suffix by appending one more 'c'
107+
let new_suffix = format!("{}c", existing_c_suffix);
108+
109+
let new_filename = format!("{}{}.md", base, new_suffix);
110+
let new_path = format!("chats/{}", new_filename);
111+
112+
fs::copy(&old_md_path, &new_path)
113+
.expect("❌ Failed to copy markdown file");
114+
115+
return Some(new_path);
103116
}
104117
}
105118
None
106119
}
107120

121+
/// Splits "CHAT-timestamp-ccc" → ("CHAT-timestamp-", "ccc")
122+
fn split_clone_suffix(stem: &str) -> (String, String) {
123+
// Find where the trailing c's start
124+
let c_count = stem.chars().rev().take_while(|&ch| ch == 'c').count();
125+
126+
if c_count == 0 {
127+
// No suffix at all
128+
return (stem.to_string(), String::new());
129+
}
130+
131+
let base_len = stem.len() - c_count;
132+
let base = stem[..base_len].to_string();
133+
let suffix = stem[base_len..].to_string();
134+
135+
(base, suffix)
136+
}
137+
138+
108139
pub fn write_new_conversation(
109140
new_id: &str,
110141
new_title: &str,

0 commit comments

Comments
 (0)