diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 46ee5f5..986f6c3 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -79,6 +79,20 @@ pub enum Commands { limit: u64, }, + /// List posts by a specific agent (defaults to yourself) + Posts { + /// Agent name (defaults to your own) + #[arg(short, long)] + author: Option, + + /// Sort order (hot, new, top, rising) + #[arg(short, long, default_value = "new")] + sort: String, + + #[arg(short, long, default_value = "25")] + limit: u64, + }, + /// Get global posts (not personalized) (One-shot) Global { /// Sort order (hot, new, top, rising) @@ -475,6 +489,10 @@ pub async fn execute(command: Commands, client: &MoltbookClient) -> Result<(), A // Post Commands Commands::Feed { sort, limit } => post::feed(client, &sort, limit).await, + Commands::Posts { author, sort, limit } => { + let name = author.unwrap_or_else(|| client.agent_name.clone()); + post::agent_posts(client, &name, &sort, limit).await + } Commands::Global { sort, limit } => post::global_feed(client, &sort, limit).await, Commands::Post { title, diff --git a/src/cli/post.rs b/src/cli/post.rs index 60ce527..bd1407a 100644 --- a/src/cli/post.rs +++ b/src/cli/post.rs @@ -56,6 +56,28 @@ pub async fn feed(client: &MoltbookClient, sort: &str, limit: u64) -> Result<(), Ok(()) } +/// Fetches and displays posts by a specific agent. +pub async fn agent_posts(client: &MoltbookClient, author: &str, sort: &str, limit: u64) -> Result<(), ApiError> { + let encoded = urlencoding::encode(author); + let response: FeedResponse = client + .get(&format!("/posts?author={}&sort={}&limit={}", encoded, sort, limit)) + .await?; + println!( + "\n{} {}", + "Posts by".bright_green().bold(), + author.bright_cyan().bold() + ); + println!("{}", "=".repeat(60)); + if response.posts.is_empty() { + display::info("No posts found."); + } else { + for (i, post) in response.posts.iter().enumerate() { + display::display_post(post, Some(i + 1)); + } + } + Ok(()) +} + /// Fetches and displays global posts from the entire network. pub async fn global_feed(client: &MoltbookClient, sort: &str, limit: u64) -> Result<(), ApiError> { let response: FeedResponse = client