| 13 | use std::sync::Arc; |
| 14 | |
| 15 | pub(super) fn load_code_config(config_source: String) -> Result<CodeConfig> { |
| 16 | let expanded = expand_home(&config_source); |
| 17 | let path = Path::new(&expanded); |
| 18 | let ext = path.extension().and_then(|ext| ext.to_str()); |
| 19 | |
| 20 | if matches!(ext, Some("acl")) { |
| 21 | if !path.exists() { |
| 22 | return Err(CodeError::Config(format!( |
| 23 | "Config file not found: {}", |
| 24 | path.display() |
| 25 | ))); |
| 26 | } |
| 27 | |
| 28 | return Ok(CodeConfig::from_file(path) |
| 29 | .with_context(|| format!("Failed to load config: {}", path.display()))?); |
| 30 | } |
| 31 | |
| 32 | if matches!(ext, Some("hcl")) { |
| 33 | return Err(CodeError::Config( |
| 34 | "HCL config files are not supported in 2.0; rename the file to .acl".into(), |
| 35 | )); |
| 36 | } |
| 37 | |
| 38 | if config_source.trim().starts_with('{') { |
| 39 | return Err(CodeError::Config( |
| 40 | "JSON config is not supported; use ACL-compatible .acl config".into(), |
| 41 | )); |
| 42 | } |
| 43 | |
| 44 | if matches!(ext, Some("json")) { |
| 45 | return Err(CodeError::Config( |
| 46 | "JSON config files are not supported; use .acl".into(), |
| 47 | )); |
| 48 | } |
| 49 | |
| 50 | Ok(CodeConfig::from_acl(&config_source).context("Failed to parse config as ACL string")?) |
| 51 | } |
| 52 | |
| 53 | pub(super) async fn build_agent_from_config(config: CodeConfig) -> Result<Agent> { |
| 54 | config |