-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat[#1540]: Base changes for cli list sessions #1586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,4 +3,5 @@ pub mod bench; | |
| pub mod configure; | ||
| pub mod info; | ||
| pub mod mcp; | ||
| pub mod session; | ||
| pub mod update; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| use anyhow::Result; | ||
| use goose::session::info::{get_session_info, SessionInfo}; | ||
|
|
||
| pub fn handle_session_list(verbose: bool, format: String) -> Result<()> { | ||
| let sessions = match get_session_info() { | ||
| Ok(sessions) => sessions, | ||
| Err(e) => { | ||
| tracing::error!("Failed to list sessions: {:?}", e); | ||
| return Err(anyhow::anyhow!("Failed to list sessions")); | ||
| } | ||
| }; | ||
|
|
||
| match format.as_str() { | ||
| "json" => { | ||
| println!("{}", serde_json::to_string(&sessions)?); | ||
| } | ||
| _ => { | ||
| if sessions.is_empty() { | ||
| println!("No sessions found"); | ||
| return Ok(()); | ||
| } else { | ||
| println!("Available sessions:"); | ||
| for SessionInfo { | ||
| id, | ||
| path, | ||
| metadata, | ||
| modified, | ||
| } in sessions | ||
| { | ||
| let description = if metadata.description.is_empty() { | ||
| "(none)" | ||
| } else { | ||
| &metadata.description | ||
| }; | ||
| let output = format!("{} - {} - {}", id, description, modified); | ||
| if verbose { | ||
| println!(" {}", output); | ||
| println!(" Path: {}", path); | ||
| } else { | ||
| println!("{}", output); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| use anyhow::Result; | ||
| use serde::Serialize; | ||
|
|
||
| use crate::session::{self, SessionMetadata}; | ||
|
|
||
| #[derive(Serialize)] | ||
| pub struct SessionInfo { | ||
| pub id: String, | ||
| pub path: String, | ||
| pub modified: String, | ||
| pub metadata: SessionMetadata, | ||
| } | ||
|
|
||
| pub fn get_session_info() -> Result<Vec<SessionInfo>> { | ||
| let sessions = match session::list_sessions() { | ||
| Ok(sessions) => sessions, | ||
| Err(e) => { | ||
| tracing::error!("Failed to list sessions: {:?}", e); | ||
| return Err(anyhow::anyhow!("Failed to list sessions")); | ||
| } | ||
| }; | ||
| let session_infos = sessions | ||
| .into_iter() | ||
| .map(|(id, path)| { | ||
| // Get last modified time as string | ||
| let modified = path | ||
| .metadata() | ||
| .and_then(|m| m.modified()) | ||
| .map(|time| { | ||
| chrono::DateTime::<chrono::Utc>::from(time) | ||
| .format("%Y-%m-%d %H:%M:%S UTC") | ||
| .to_string() | ||
| }) | ||
| .unwrap_or_else(|_| "Unknown".to_string()); | ||
|
|
||
| // Get session description | ||
| let metadata = session::read_metadata(&path).expect("Failed to read session metadata"); | ||
|
|
||
| SessionInfo { | ||
| id, | ||
| path: path.to_string_lossy().to_string(), | ||
| modified, | ||
| metadata, | ||
| } | ||
| }) | ||
| .collect(); | ||
|
|
||
| Ok(session_infos) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently the output looks like this:
i think it'd be nicer to do sth similar to what we have in goose-server routes:
goose/crates/goose-server/src/routes/session.rs
Lines 47 to 79 in fa9bb9e
then we can print sth like this: