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:
@@ -221,8 +221,10 @@ const SLASH_COMMAND_SPECS: &[SlashCommandSpec] = &[
|
||||
SlashCommandSpec {
|
||||
name: "session",
|
||||
aliases: &[],
|
||||
summary: "List, switch, or fork managed local sessions",
|
||||
argument_hint: Some("[list|switch <session-id>|fork [branch-name]]"),
|
||||
summary: "List, switch, fork, or delete managed local sessions",
|
||||
argument_hint: Some(
|
||||
"[list|switch <session-id>|fork [branch-name]|delete <session-id> [--force]]",
|
||||
),
|
||||
resume_supported: false,
|
||||
},
|
||||
SlashCommandSpec {
|
||||
@@ -1526,7 +1528,7 @@ fn parse_session_command(args: &[&str]) -> Result<SlashCommand, SlashCommandPars
|
||||
action: Some("list".to_string()),
|
||||
target: None,
|
||||
}),
|
||||
["list", ..] => Err(usage_error("session", "[list|switch <session-id>|fork [branch-name]]")),
|
||||
["list", ..] => Err(usage_error("session", "[list|switch <session-id>|fork [branch-name]|delete <session-id> [--force]]")),
|
||||
["switch"] => Err(usage_error("session switch", "<session-id>")),
|
||||
["switch", target] => Ok(SlashCommand::Session {
|
||||
action: Some("switch".to_string()),
|
||||
@@ -1550,12 +1552,33 @@ fn parse_session_command(args: &[&str]) -> Result<SlashCommand, SlashCommandPars
|
||||
"session",
|
||||
"/session fork [branch-name]",
|
||||
)),
|
||||
[action, ..] => Err(command_error(
|
||||
["delete"] => Err(usage_error("session delete", "<session-id> [--force]")),
|
||||
["delete", target] => Ok(SlashCommand::Session {
|
||||
action: Some("delete".to_string()),
|
||||
target: Some((*target).to_string()),
|
||||
}),
|
||||
["delete", target, "--force"] => Ok(SlashCommand::Session {
|
||||
action: Some("delete-force".to_string()),
|
||||
target: Some((*target).to_string()),
|
||||
}),
|
||||
["delete", _target, unexpected] => Err(command_error(
|
||||
&format!(
|
||||
"Unknown /session action '{action}'. Use list, switch <session-id>, or fork [branch-name]."
|
||||
"Unsupported /session delete flag '{unexpected}'. Use --force to skip confirmation."
|
||||
),
|
||||
"session",
|
||||
"/session [list|switch <session-id>|fork [branch-name]]",
|
||||
"/session delete <session-id> [--force]",
|
||||
)),
|
||||
["delete", ..] => Err(command_error(
|
||||
"Unexpected arguments for /session delete.",
|
||||
"session",
|
||||
"/session delete <session-id> [--force]",
|
||||
)),
|
||||
[action, ..] => Err(command_error(
|
||||
&format!(
|
||||
"Unknown /session action '{action}'. Use list, switch <session-id>, fork [branch-name], or delete <session-id> [--force]."
|
||||
),
|
||||
"session",
|
||||
"/session [list|switch <session-id>|fork [branch-name]|delete <session-id> [--force]]",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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