mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-08 00:54:49 +08:00
feat: b5-markdown-fence — batch 5 wave 2
This commit is contained in:
@@ -4059,9 +4059,55 @@ impl LiveCli {
|
||||
);
|
||||
Ok(true)
|
||||
}
|
||||
Some("delete") => {
|
||||
let Some(target) = target else {
|
||||
println!("Usage: /session delete <session-id> [--force]");
|
||||
return Ok(false);
|
||||
};
|
||||
let handle = resolve_session_reference(target)?;
|
||||
if handle.id == self.session.id {
|
||||
println!(
|
||||
"delete: refusing to delete the active session '{}'.\nSwitch to another session first with /session switch <session-id>.",
|
||||
handle.id
|
||||
);
|
||||
return Ok(false);
|
||||
}
|
||||
if !confirm_session_deletion(&handle.id) {
|
||||
println!("delete: cancelled.");
|
||||
return Ok(false);
|
||||
}
|
||||
delete_managed_session(&handle.path)?;
|
||||
println!(
|
||||
"Session deleted\n Deleted session {}\n File {}",
|
||||
handle.id,
|
||||
handle.path.display(),
|
||||
);
|
||||
Ok(false)
|
||||
}
|
||||
Some("delete-force") => {
|
||||
let Some(target) = target else {
|
||||
println!("Usage: /session delete <session-id> [--force]");
|
||||
return Ok(false);
|
||||
};
|
||||
let handle = resolve_session_reference(target)?;
|
||||
if handle.id == self.session.id {
|
||||
println!(
|
||||
"delete: refusing to delete the active session '{}'.\nSwitch to another session first with /session switch <session-id>.",
|
||||
handle.id
|
||||
);
|
||||
return Ok(false);
|
||||
}
|
||||
delete_managed_session(&handle.path)?;
|
||||
println!(
|
||||
"Session deleted\n Deleted session {}\n File {}",
|
||||
handle.id,
|
||||
handle.path.display(),
|
||||
);
|
||||
Ok(false)
|
||||
}
|
||||
Some(other) => {
|
||||
println!(
|
||||
"Unknown /session action '{other}'. Use /session list, /session switch <session-id>, or /session fork [branch-name]."
|
||||
"Unknown /session action '{other}'. Use /session list, /session switch <session-id>, /session fork [branch-name], or /session delete <session-id> [--force]."
|
||||
);
|
||||
Ok(false)
|
||||
}
|
||||
@@ -4347,6 +4393,24 @@ fn latest_managed_session() -> Result<ManagedSessionSummary, Box<dyn std::error:
|
||||
.ok_or_else(|| format_no_managed_sessions().into())
|
||||
}
|
||||
|
||||
fn delete_managed_session(path: &Path) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if !path.exists() {
|
||||
return Err(format!("session file does not exist: {}", path.display()).into());
|
||||
}
|
||||
fs::remove_file(path)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn confirm_session_deletion(session_id: &str) -> bool {
|
||||
print!("Delete session '{session_id}'? This cannot be undone. [y/N]: ");
|
||||
io::stdout().flush().unwrap_or(());
|
||||
let mut answer = String::new();
|
||||
if io::stdin().read_line(&mut answer).is_err() {
|
||||
return false;
|
||||
}
|
||||
matches!(answer.trim(), "y" | "Y" | "yes" | "Yes" | "YES")
|
||||
}
|
||||
|
||||
fn format_missing_session_reference(reference: &str) -> String {
|
||||
format!(
|
||||
"session not found: {reference}\nHint: managed sessions live in .claw/sessions/. Try `{LATEST_SESSION_REFERENCE}` for the most recent session or `/session list` in the REPL."
|
||||
|
||||
Reference in New Issue
Block a user