(&mut self, os: &Os)
| 93 | } |
| 94 | |
| 95 | pub async fn validate(&mut self, os: &Os) -> Result<()> { |
| 96 | match self { |
| 97 | Knowledge::Add(add) => { |
| 98 | // Check if value is intended to be a path (doesn't contain newlines) |
| 99 | if !add.value.contains('\n') { |
| 100 | let path = crate::cli::chat::tools::sanitize_path_tool_arg(os, &add.value); |
| 101 | if !path.exists() { |
| 102 | eyre::bail!("Path '{}' does not exist", add.value); |
| 103 | } |
| 104 | } |
| 105 | Ok(()) |
| 106 | }, |
| 107 | Knowledge::Remove(remove) => { |
| 108 | if remove.name.is_empty() && remove.context_id.is_empty() && remove.path.is_empty() { |
| 109 | eyre::bail!("Please provide at least one of: name, context_id, or path"); |
| 110 | } |
| 111 | // If path is provided, validate it exists |
| 112 | if !remove.path.is_empty() { |
| 113 | let path = crate::cli::chat::tools::sanitize_path_tool_arg(os, &remove.path); |
| 114 | if !path.exists() { |
| 115 | warn!( |
| 116 | "Path '{}' does not exist, will try to remove by path string match", |
| 117 | remove.path |
| 118 | ); |
| 119 | } |
| 120 | } |
| 121 | Ok(()) |
| 122 | }, |
| 123 | Knowledge::Update(update) => { |
| 124 | // Require at least one identifier (context_id or name) |
| 125 | if update.context_id.is_empty() && update.name.is_empty() && update.path.is_empty() { |
| 126 | eyre::bail!( |
| 127 | "Please provide either context_id, name, or path to identify the knowledge base entry to update" |
| 128 | ); |
| 129 | } |
| 130 | |
| 131 | // Validate the path exists |
| 132 | if !update.path.is_empty() { |
| 133 | let path = crate::cli::chat::tools::sanitize_path_tool_arg(os, &update.path); |
| 134 | if !path.exists() { |
| 135 | eyre::bail!("Path '{}' does not exist", update.path); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | Ok(()) |
| 140 | }, |
| 141 | Knowledge::Clear(clear) => { |
| 142 | if !clear.confirm { |
| 143 | eyre::bail!("Please confirm clearing knowledge base by setting confirm=true"); |
| 144 | } |
| 145 | Ok(()) |
| 146 | }, |
| 147 | Knowledge::Search(_) => Ok(()), |
| 148 | Knowledge::Show => Ok(()), |
| 149 | Knowledge::Cancel(_) => Ok(()), |
| 150 | } |
| 151 | } |
| 152 |
nothing calls this directly
no test coverage detected