From b344757fb0ccff41d2ac5b34c7719f1371802307 Mon Sep 17 00:00:00 2001 From: Ryan Ragona Date: Sun, 27 Apr 2025 09:00:37 -0700 Subject: [PATCH] first pass at get --- codex-rs/session/src/cli.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/codex-rs/session/src/cli.rs b/codex-rs/session/src/cli.rs index da7a5ecdb5..18c6f0d6cc 100644 --- a/codex-rs/session/src/cli.rs +++ b/codex-rs/session/src/cli.rs @@ -42,6 +42,7 @@ impl Cli { Commands::Delete(x) => x.run().await, Commands::Logs(x) => x.run().await, Commands::List(x) => x.run().await, + Commands::Get(x) => x.run().await, } } } @@ -58,6 +59,9 @@ enum Commands { Logs(LogsCmd), /// List all known sessions. List(ListCmd), + + /// Print the raw metadata JSON for a session. + Get(GetCmd), } #[derive(Subcommand)] @@ -354,6 +358,39 @@ impl LogsCmd { #[derive(Args)] pub struct ListCmd {} +// ----------------------------------------------------------------------------- +// get – print metadata +// ----------------------------------------------------------------------------- + +#[derive(Args)] +pub struct GetCmd { + /// Session selector (index, id or prefix) to print metadata for. + id: String, +} + +impl GetCmd { + pub async fn run(self) -> Result<()> { + // Re-use the same selector resolution that `attach`, `delete`, … use so users can refer + // to sessions by index or prefix. + let id = store::resolve_selector(&self.id)?; + let paths = store::paths_for(&id)?; + + let bytes = std::fs::read(&paths.meta) + .with_context(|| format!("failed to read metadata for session '{id}'"))?; + + // We *could* just write the file contents as-is but parsing + re-serialising guarantees + // the output is valid and nicely formatted even when the on-disk representation ever + // switches away from pretty-printed JSON. + let meta: SessionMeta = serde_json::from_slice(&bytes) + .context("failed to deserialize session metadata")?; + + let pretty = serde_json::to_string_pretty(&meta)?; + println!("{pretty}"); + + Ok(()) + } +} + #[derive(Serialize)] #[allow(missing_docs)] pub struct StatusRow {