Skip to main content

ralph_workflow/cli/handlers/
list.rs

1//! Agent listing handlers.
2//!
3//! This module provides handlers for listing agents and their configurations.
4
5use crate::agents::{is_ccs_ref, AgentRegistry};
6
7/// Handle --list-agents command.
8///
9/// Lists all registered agents with their configuration details including:
10/// - Agent name
11/// - Command to invoke the agent
12/// - JSON parser type
13/// - Whether the agent can create commits (`can_commit` flag)
14///
15/// CCS aliases (ccs/...) are displayed separately for clarity.
16/// Output is sorted alphabetically by agent name within each section.
17pub fn handle_list_agents(registry: &AgentRegistry) {
18    let mut items = registry.list();
19    items.sort_by(|(a, _), (b, _)| a.cmp(b));
20
21    // Separate regular agents from CCS aliases
22    let (ccs_aliases, regular_agents): (Vec<_>, Vec<_>) =
23        items.into_iter().partition(|(name, _)| is_ccs_ref(name));
24
25    // Print regular agents
26    if !regular_agents.is_empty() {
27        println!("Agents:");
28        for (name, cfg) in regular_agents {
29            let display_name = registry.display_name(name);
30            println!(
31                "  {}\tcmd={}\tparser={}\tcan_commit={}",
32                display_name, cfg.cmd, cfg.json_parser, cfg.can_commit
33            );
34        }
35    }
36
37    // Print CCS aliases
38    if !ccs_aliases.is_empty() {
39        println!("\nCCS Aliases:");
40        for (name, cfg) in ccs_aliases {
41            let display_name = registry.display_name(name);
42            println!("  {}\t→ \"{}\"", display_name, cfg.cmd);
43        }
44    }
45}
46
47/// Handle --list-available-agents command.
48///
49/// Lists only agents whose commands are available on the system PATH.
50/// This helps users quickly identify which agents they can use without
51/// additional setup.
52///
53/// CCS aliases are shown separately to distinguish them from regular agents.
54/// Output is sorted alphabetically by agent name within each section.
55pub fn handle_list_available_agents(registry: &AgentRegistry) {
56    let mut items = registry.list_available();
57    items.sort_unstable();
58
59    // Separate regular agents from CCS aliases
60    let (ccs_aliases, regular_agents): (Vec<_>, Vec<_>) =
61        items.into_iter().partition(|name| is_ccs_ref(name));
62
63    // Print regular agents
64    if !regular_agents.is_empty() {
65        println!("Available agents:");
66        for name in regular_agents {
67            let display_name = registry.display_name(name);
68            println!("  {display_name}");
69        }
70    }
71
72    // Print CCS aliases
73    if !ccs_aliases.is_empty() {
74        println!("\nAvailable CCS aliases:");
75        for name in ccs_aliases {
76            let display_name = registry.display_name(name);
77            println!("  {display_name}");
78        }
79    }
80}