Remove the `atomic` entry from agy's `import_manifest.json`.
(config_dir: &Path)
| 663 | |
| 664 | /// Remove the `atomic` entry from agy's `import_manifest.json`. |
| 665 | fn unregister_import(config_dir: &Path) -> AgentResult<()> { |
| 666 | let manifest_path = config_dir.join(IMPORT_MANIFEST_FILE); |
| 667 | if !manifest_path.exists() { |
| 668 | return Ok(()); |
| 669 | } |
| 670 | |
| 671 | let content = |
| 672 | std::fs::read_to_string(&manifest_path).map_err(|e| AgentError::ConfigError { |
| 673 | operation: "read import manifest".to_string(), |
| 674 | path: manifest_path.clone(), |
| 675 | reason: e.to_string(), |
| 676 | })?; |
| 677 | let mut manifest: Value = |
| 678 | serde_json::from_str(&content).unwrap_or_else(|_| Value::Object(Map::new())); |
| 679 | |
| 680 | let Some(imports) = manifest |
| 681 | .as_object_mut() |
| 682 | .and_then(|root| root.get_mut("imports")) |
| 683 | .and_then(Value::as_array_mut) |
| 684 | else { |
| 685 | return Ok(()); |
| 686 | }; |
| 687 | |
| 688 | imports.retain(|entry| entry.get("name").and_then(Value::as_str) != Some(ATOMIC_GROUP)); |
| 689 | |
| 690 | if imports.is_empty() { |
| 691 | // Nothing registered — drop the manifest file entirely. |
| 692 | let _ = std::fs::remove_file(&manifest_path); |
| 693 | Ok(()) |
| 694 | } else { |
| 695 | Self::write_json(&manifest_path, &manifest) |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | // Global install/uninstall (plugins are inherently global, so these are |
| 700 | // the same operation as project-level install for this adapter) |