Update context by path
(&mut self, path_str: &str)
| 500 | |
| 501 | /// Update context by path |
| 502 | pub async fn update_by_path(&mut self, path_str: &str) -> Result<String, String> { |
| 503 | if let Some(context) = self.agent_client.get_context_by_path(path_str).await { |
| 504 | // Remove the existing context first |
| 505 | self.agent_client |
| 506 | .remove_context_by_id(&context.id) |
| 507 | .await |
| 508 | .map_err(|e| e.to_string())?; |
| 509 | |
| 510 | // Then add it back with the same name and original patterns (agent scope) |
| 511 | let options = AddOptions { |
| 512 | description: None, |
| 513 | include_patterns: context.include_patterns.clone(), |
| 514 | exclude_patterns: context.exclude_patterns.clone(), |
| 515 | embedding_type: None, |
| 516 | }; |
| 517 | self.add(&context.name, path_str, options).await |
| 518 | } else { |
| 519 | // Debug: List all available contexts |
| 520 | let available_paths = self.agent_client.list_context_paths().await; |
| 521 | if available_paths.is_empty() { |
| 522 | Err("No contexts found. Add a context first with 'knowledge add <name> <path>'".to_string()) |
| 523 | } else { |
| 524 | Err(format!( |
| 525 | "No context found with path '{}'\nAvailable contexts:\n{}", |
| 526 | path_str, |
| 527 | available_paths.join("\n") |
| 528 | )) |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | /// Update context by ID |
| 534 | pub async fn update_context_by_id(&mut self, context_id: &str, path_str: &str) -> Result<String, String> { |
no test coverage detected