From ca52629a2499340ad24b85419c8664b299266c2f Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Thu, 7 May 2026 15:23:50 -0600 Subject: [PATCH] feat: dynamic tab completions now show the sessions for a given agent instead of only listing global sessions --- src/cli/completer.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/cli/completer.rs b/src/cli/completer.rs index 1809bbc..eb72959 100644 --- a/src/cli/completer.rs +++ b/src/cli/completer.rs @@ -1,9 +1,11 @@ use crate::client::{ModelType, list_models}; use crate::config::paths; use crate::config::{AppConfig, Config, list_agents, list_sessions}; +use crate::utils::list_file_names; use crate::vault::Vault; use clap_complete::{CompletionCandidate, Shell, generate}; use clap_complete_nushell::Nushell; +use std::env; use std::ffi::OsStr; use std::io; @@ -94,9 +96,36 @@ pub(super) fn macro_completer(current: &OsStr) -> Vec { .collect() } +fn extract_agent_from_args() -> Option { + let args: Vec = env::args().collect(); + let mut i = 0; + while i < args.len() { + let arg = &args[i]; + + if let Some(value) = arg.strip_prefix("--agent=") { + return Some(value.to_string()); + } + + if (arg == "--agent" || arg == "-a") && i + 1 < args.len() { + return Some(args[i + 1].clone()); + } + + i += 1; + } + None +} + pub(super) fn session_completer(current: &OsStr) -> Vec { let cur = current.to_string_lossy(); - list_sessions() + + let sessions = if let Some(agent_name) = extract_agent_from_args() { + let sessions_dir = paths::agent_data_dir(&agent_name).join("sessions"); + list_file_names(sessions_dir, ".yaml") + } else { + list_sessions() + }; + + sessions .into_iter() .filter(|s| s.starts_with(&*cur)) .map(CompletionCandidate::new)