MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / save_agent_config

Function save_agent_config

crates/chat-cli/src/cli/chat/mod.rs:3965–3992  ·  view source on GitHub ↗

Helper method to save the agent config to file

(os: &mut Os, config: &Agent, agent_name: &str, is_global: bool)

Source from the content-addressed store, hash-verified

3963
3964// Helper method to save the agent config to file
3965async fn save_agent_config(os: &mut Os, config: &Agent, agent_name: &str, is_global: bool) -> Result<(), ChatError> {
3966 let resolver = PathResolver::new(os);
3967 let config_dir = if is_global {
3968 resolver
3969 .global()
3970 .agents_dir()
3971 .map_err(|e| ChatError::Custom(format!("Could not find global agent directory: {}", e).into()))?
3972 } else {
3973 resolver
3974 .workspace()
3975 .agents_dir()
3976 .map_err(|e| ChatError::Custom(format!("Could not find local agent directory: {}", e).into()))?
3977 };
3978
3979 tokio::fs::create_dir_all(&config_dir)
3980 .await
3981 .map_err(|e| ChatError::Custom(format!("Failed to create config directory: {}", e).into()))?;
3982
3983 let config_file = config_dir.join(format!("{}.json", agent_name));
3984 let config_json = serde_json::to_string_pretty(config)
3985 .map_err(|e| ChatError::Custom(format!("Failed to serialize agent config: {}", e).into()))?;
3986
3987 tokio::fs::write(&config_file, config_json)
3988 .await
3989 .map_err(|e| ChatError::Custom(format!("Failed to write agent config file: {}", e).into()))?;
3990
3991 Ok(())
3992}
3993
3994#[cfg(test)]
3995mod tests {

Callers 1

Calls 5

CustomClass · 0.85
agents_dirMethod · 0.80
globalMethod · 0.80
joinMethod · 0.80
workspaceMethod · 0.45

Tested by

no test coverage detected