summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/config/mod.rs27
-rw-r--r--src/repl/mod.rs33
2 files changed, 36 insertions, 24 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 20f19e5..19bd239 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -3,7 +3,7 @@ mod input;
mod role;
mod session;
-pub use self::agent::{list_agents, Agent, AgentVariables};
+pub use self::agent::{list_agents, Agent, AgentDefinition, AgentVariables};
pub use self::input::Input;
pub use self::role::{
Role, RoleLike, CODE_ROLE, CREATE_TITLE_ROLE, EXPLAIN_SHELL_ROLE, SHELL_ROLE,
@@ -1798,12 +1798,25 @@ impl Config {
};
values = candidates.into_iter().map(|v| (v, None)).collect();
filter = args[1];
- } else if cmd == ".agent" && args.len() == 2 {
- let dir = Self::agent_data_dir(args[0]).join(SESSIONS_DIR_NAME);
- values = list_file_names(dir, ".yaml")
- .into_iter()
- .map(|v| (v, None))
- .collect();
+ } else if cmd == ".agent" {
+ if args.len() == 2 {
+ let dir = Self::agent_data_dir(args[0]).join(SESSIONS_DIR_NAME);
+ values = list_file_names(dir, ".yaml")
+ .into_iter()
+ .map(|v| (v, None))
+ .collect();
+ }
+ let definition_file_path = Self::agent_functions_dir(args[0]).join("index.yaml");
+ if definition_file_path.exists() {
+ if let Ok(definition) = AgentDefinition::load(&definition_file_path) {
+ values.extend(
+ definition
+ .variables
+ .iter()
+ .map(|v| (format!("{}=", v.name), Some(v.description.clone()))),
+ );
+ }
+ }
};
values
.into_iter()
diff --git a/src/repl/mod.rs b/src/repl/mod.rs
index ef7921d..908fa67 100644
--- a/src/repl/mod.rs
+++ b/src/repl/mod.rs
@@ -422,22 +422,21 @@ pub async fn run_repl_command(
".agent" => match split_first_arg(args) {
Some((agent_name, args)) => {
let (new_args, _) = split_args_text(args.unwrap_or_default(), cfg!(windows));
- let mut session_name = None;
- if let Some((name, variable_pairs)) = new_args.split_first() {
- if name != "null" && name != "none" {
- session_name = Some(name.as_str());
- }
- let variables: AgentVariables = variable_pairs
- .iter()
- .filter_map(|v| v.split_once('='))
- .map(|(key, value)| (key.to_string(), value.to_string()))
- .collect();
- if variables.len() != variable_pairs.len() {
- bail!("Some variable key-value pairs are invalid");
- }
- if !variables.is_empty() {
- config.write().agent_variables = Some(variables);
- }
+ let (session_name, variable_pairs) = match new_args.first() {
+ Some(name) if name.contains('=') => (None, new_args.as_slice()),
+ Some(name) => (Some(name.as_str()), &new_args[1..]),
+ None => (None, &[] as &[String]),
+ };
+ let variables: AgentVariables = variable_pairs
+ .iter()
+ .filter_map(|v| v.split_once('='))
+ .map(|(key, value)| (key.to_string(), value.to_string()))
+ .collect();
+ if variables.len() != variable_pairs.len() {
+ bail!("Some variable values are not key=value pairs");
+ }
+ if !variables.is_empty() {
+ config.write().agent_variables = Some(variables);
}
let ret =
Config::use_agent(config, agent_name, session_name, abort_signal.clone())
@@ -446,7 +445,7 @@ pub async fn run_repl_command(
ret?;
}
None => {
- println!(r#"Usage: .agent <agent-name> [session-name|null] [key=value]..."#)
+ println!(r#"Usage: .agent <agent-name> [session-name] [key=value]..."#)
}
},
".starter" => match args {