Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src-tauri/src/cli/commands/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ use crate::session_manager::{self, SessionMessage, SessionMessageBatch, SessionM

#[derive(Subcommand, Debug, Clone)]
pub enum SessionsCommand {
/// Repair legacy Codex session names (dry-run unless --apply is passed)
RepairCodexNames {
/// Apply the reported repairs to the Codex state database
#[arg(long)]
apply: bool,
},
/// List saved assistant sessions
List {
/// Scan a specific provider instead of --app
Expand Down Expand Up @@ -126,6 +132,7 @@ struct SessionMessagesOutput<'a> {

pub fn execute(cmd: SessionsCommand, app: Option<AppType>) -> Result<(), AppError> {
match cmd {
SessionsCommand::RepairCodexNames { apply } => repair_codex_names(apply),
SessionsCommand::List {
provider,
all,
Expand Down Expand Up @@ -164,6 +171,24 @@ pub fn execute(cmd: SessionsCommand, app: Option<AppType>) -> Result<(), AppErro
}
}

fn repair_codex_names(apply: bool) -> Result<(), AppError> {
let changed = crate::codex_history_migration::repair_codex_legacy_thread_names(apply)?;
if apply {
println!(
"{}",
success(&format!("Repaired {changed} Codex session name(s)."))
);
} else {
println!(
"{}",
info(&format!(
"Dry run: {changed} Codex session name(s) can be repaired. Re-run with --apply to write changes."
))
);
}
Ok(())
}

fn list_sessions(
app: Option<AppType>,
provider: Option<AppType>,
Expand Down
24 changes: 24 additions & 0 deletions src-tauri/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,30 @@ mod tests {
}
}

#[test]
fn parses_sessions_repair_codex_names_as_dry_run_by_default() {
let cli = Cli::parse_from(["cc-switch", "sessions", "repair-codex-names"]);

match cli.command {
Some(Commands::Sessions(
super::commands::sessions::SessionsCommand::RepairCodexNames { apply },
)) => assert!(!apply),
_ => panic!("expected sessions repair-codex-names command"),
}
}

#[test]
fn parses_sessions_repair_codex_names_apply_flag() {
let cli = Cli::parse_from(["cc-switch", "sessions", "repair-codex-names", "--apply"]);

match cli.command {
Some(Commands::Sessions(
super::commands::sessions::SessionsCommand::RepairCodexNames { apply },
)) => assert!(apply),
_ => panic!("expected sessions repair-codex-names command"),
}
}

#[test]
fn parses_sessions_list_with_backend_provider_id() {
let cli = Cli::parse_from(["cc-switch", "sessions", "list", "--provider", "opencode"]);
Expand Down
Loading