Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 14 additions & 2 deletions crates/goose-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ enum SessionCommand {
long_help = "Sort sessions by date in ascending order (oldest first). Default is descending order (newest first)."
)]
ascending: bool,

#[arg(
short = 'p',
long = "path",
help = "Filter sessions by working directory"
)]
path: Option<PathBuf>,
Comment thread
exitcode0 marked this conversation as resolved.
Outdated

#[arg(short = 'l', long = "limit", help = "Limit the number of results")]
limit: Option<usize>,
},
#[command(about = "Remove sessions. Runs interactively if no ID or regex is provided.")]
Remove {
Expand Down Expand Up @@ -184,7 +194,7 @@ enum SchedulerCommand {
id: String,
/// Maximum number of sessions to return
Comment thread
exitcode0 marked this conversation as resolved.
Outdated
#[arg(long, help = "Maximum number of sessions to return")]
limit: Option<u32>,
limit: Option<usize>,
},
/// Run a scheduled job immediately
#[command(about = "Run a scheduled job immediately")]
Expand Down Expand Up @@ -794,8 +804,10 @@ pub async fn cli() -> Result<()> {
verbose,
format,
ascending,
path,
limit,
}) => {
handle_session_list(verbose, format, ascending).await?;
handle_session_list(verbose, format, ascending, path, limit).await?;
Ok(())
}
Some(SessionCommand::Remove { id, regex }) => {
Expand Down
4 changes: 2 additions & 2 deletions crates/goose-cli/src/commands/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,14 @@ pub async fn handle_schedule_remove(id: String) -> Result<()> {
}
}

pub async fn handle_schedule_sessions(id: String, limit: Option<u32>) -> Result<()> {
pub async fn handle_schedule_sessions(id: String, limit: Option<usize>) -> Result<()> {
let scheduler_storage_path =
get_default_scheduler_storage_path().context("Failed to get scheduler storage path")?;
let scheduler = SchedulerFactory::create(scheduler_storage_path)
.await
.context("Failed to initialize scheduler")?;

match scheduler.sessions(&id, limit.unwrap_or(50) as usize).await {
match scheduler.sessions(&id, limit.unwrap_or(50)).await {
Ok(sessions) => {
if sessions.is_empty() {
println!("No sessions found for schedule ID '{}'.", id);
Expand Down
23 changes: 22 additions & 1 deletion crates/goose-cli/src/commands/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,35 @@ pub async fn handle_session_remove(id: Option<String>, regex_string: Option<Stri
remove_sessions(matched_sessions).await
}

pub async fn handle_session_list(verbose: bool, format: String, ascending: bool) -> Result<()> {
pub async fn handle_session_list(
verbose: bool,
Comment thread
exitcode0 marked this conversation as resolved.
Outdated
format: String,
ascending: bool,
path: Option<PathBuf>,
limit: Option<usize>,
) -> Result<()> {
let mut sessions = SessionManager::list_sessions().await?;

if let Some(ref pat) = path {
let pat_lower = pat.to_string_lossy().to_lowercase();
sessions.retain(|s| {
s.working_dir
.to_string_lossy()
.to_lowercase()
.contains(&pat_lower)
});
}

if ascending {
sessions.sort_by(|a, b| a.updated_at.cmp(&b.updated_at));
} else {
sessions.sort_by(|a, b| b.updated_at.cmp(&a.updated_at));
}

if let Some(n) = limit {
sessions.truncate(n);
}
Comment thread
exitcode0 marked this conversation as resolved.

match format.as_str() {
"json" => {
println!("{}", serde_json::to_string(&sessions)?);
Expand Down
Loading