(path: &Path, agent_path: &Path, owned_agent: bool)
| 742 | } |
| 743 | |
| 744 | fn uninstall_default_agent(path: &Path, agent_path: &Path, owned_agent: bool) { |
| 745 | if !path.exists() { |
| 746 | return; |
| 747 | } |
| 748 | let Ok(contents) = std::fs::read_to_string(path) else { |
| 749 | return; |
| 750 | }; |
| 751 | let Ok(mut config) = serde_json::from_str::<serde_json::Value>(&contents) else { |
| 752 | return; |
| 753 | }; |
| 754 | if config |
| 755 | .get("chat") |
| 756 | .and_then(|v| v.get("defaultAgent")) |
| 757 | .and_then(serde_json::Value::as_str) |
| 758 | != Some(KIRO_AGENT_NAME) |
| 759 | { |
| 760 | return; |
| 761 | } |
| 762 | if agent_path.exists() && !owned_agent { |
| 763 | eprintln!( |
| 764 | " Kiro default agent points at a user-managed tracedecay agent, leaving unchanged" |
| 765 | ); |
| 766 | return; |
| 767 | } |
| 768 | |
| 769 | let Some(chat) = config.get_mut("chat").and_then(|v| v.as_object_mut()) else { |
| 770 | return; |
| 771 | }; |
| 772 | chat.remove("defaultAgent"); |
| 773 | if chat.is_empty() { |
| 774 | config.as_object_mut().map(|o| o.remove("chat")); |
| 775 | } |
| 776 | |
| 777 | let is_empty = config.as_object().is_some_and(serde_json::Map::is_empty); |
| 778 | if is_empty { |
| 779 | std::fs::remove_file(path).ok(); |
| 780 | eprintln!("\x1b[32m✔\x1b[0m Removed {} (was empty)", path.display()); |
| 781 | } else if backup_and_write_json(path, &config) { |
| 782 | eprintln!( |
| 783 | "\x1b[32m✔\x1b[0m Removed tracedecay Kiro default agent from {}", |
| 784 | path.display() |
| 785 | ); |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | fn is_owned_agent_file(path: &Path) -> bool { |
| 790 | if !path.exists() { |
no test coverage detected