@@ -135,7 +135,7 @@ enum SessionCommand {
|
||||
#[arg(short, long, help = "Regex for removing matched sessions (optional)")]
|
||||
regex: Option<String>,
|
||||
},
|
||||
#[command(about = "Export a session to Markdown format")]
|
||||
#[command(about = "Export a session")]
|
||||
Export {
|
||||
#[command(flatten)]
|
||||
identifier: Option<Identifier>,
|
||||
@@ -156,6 +156,16 @@ enum SessionCommand {
|
||||
)]
|
||||
format: String,
|
||||
},
|
||||
#[command(name = "diagnostics")]
|
||||
Diagnostics {
|
||||
/// Session ID to generate diagnostics for
|
||||
#[arg(short, long)]
|
||||
session_id: String,
|
||||
|
||||
/// Output path for the diagnostics zip file (optional, defaults to current directory)
|
||||
#[arg(short, long)]
|
||||
output: Option<PathBuf>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
@@ -847,6 +857,10 @@ pub async fn cli() -> Result<()> {
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
Some(SessionCommand::Diagnostics { session_id, output }) => {
|
||||
crate::commands::session::handle_diagnostics(&session_id, output).await?;
|
||||
Ok(())
|
||||
}
|
||||
None => {
|
||||
let session_start = std::time::Instant::now();
|
||||
let session_type = if resume { "resumed" } else { "new" };
|
||||
|
||||
@@ -2,10 +2,11 @@ use crate::session::message_to_markdown;
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
use cliclack::{confirm, multiselect, select};
|
||||
use goose::session::{Session, SessionManager};
|
||||
use goose::session::{generate_diagnostics, Session, SessionManager};
|
||||
use goose::utils::safe_truncate;
|
||||
use regex::Regex;
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
const TRUNCATED_DESC_LENGTH: usize = 60;
|
||||
@@ -204,10 +205,39 @@ pub async fn handle_session_export(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
/// Convert a list of messages to markdown format for session export
|
||||
///
|
||||
/// This function handles the formatting of a complete session including headers,
|
||||
/// message organization, and proper tool request/response pairing.
|
||||
|
||||
pub async fn handle_diagnostics(session_id: &str, output_path: Option<PathBuf>) -> Result<()> {
|
||||
println!(
|
||||
"Generating diagnostics bundle for session '{}'...",
|
||||
session_id
|
||||
);
|
||||
|
||||
let diagnostics_data = generate_diagnostics(session_id).await.with_context(|| {
|
||||
format!(
|
||||
"Failed to write to generate diagnostics bundle for session '{}'",
|
||||
session_id
|
||||
)
|
||||
})?;
|
||||
|
||||
let output_file = if let Some(path) = output_path {
|
||||
path.clone()
|
||||
} else {
|
||||
PathBuf::from(format!("diagnostics_{}.zip", session_id))
|
||||
};
|
||||
|
||||
let mut file = fs::File::create(&output_file).context(format!(
|
||||
"Failed to create output file: {}",
|
||||
output_file.display()
|
||||
))?;
|
||||
|
||||
file.write_all(&diagnostics_data)
|
||||
.context("Failed to write diagnostics data")?;
|
||||
|
||||
println!("Diagnostics bundle saved to: {}", output_file.display());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn export_session_to_markdown(
|
||||
messages: Vec<goose::conversation::message::Message>,
|
||||
session_name: &String,
|
||||
|
||||
Reference in New Issue
Block a user