dirge-agent 0.11.1

Minimalistic coding agent written in Rust, optimized for memory footprint and performance
//! /prompt — list available prompts.

use crate::ui::slash::{SlashCtx, c_agent, c_result};

pub(crate) async fn cmd_prompt_list(ctx: &mut SlashCtx<'_>) -> anyhow::Result<()> {
    let mut sorted: Vec<String> = ctx.context.prompts.keys().cloned().collect();
    sorted.sort();

    if sorted.is_empty() {
        ctx.renderer.write_line("no prompts available", c_agent())?;
    } else {
        let current = ctx
            .context
            .current_prompt_name
            .as_deref()
            .unwrap_or("(none)")
            .to_string();
        ctx.renderer.write_line(
            &format!("available prompts (current: {}):", current),
            c_agent(),
        )?;
        let max_name = sorted.iter().map(|n| n.len()).max().unwrap_or(0);
        for name in &sorted {
            let desc = ctx
                .context
                .prompts
                .get(name)
                .and_then(|p| p.description.as_deref())
                .map(|s| s.to_string());
            match desc {
                Some(d) => ctx.renderer.write_line(
                    &format!("  {:<width$}  {}", name, d, width = max_name),
                    c_result(),
                )?,
                None => ctx
                    .renderer
                    .write_line(&format!("  {}", name), c_result())?,
            }
        }
        ctx.renderer.write_line("", c_agent())?;
        ctx.renderer
            .write_line("usage: /prompt <name>  |  /prompt default", c_result())?;
    }
    Ok(())
}