Delete an unstarted backlog intent. This is intentionally conservative: only backlog intents with no linked goals can be deleted. Started work should be closed or superseded instead of removed from the vault.
(
&self,
intent_id: &str,
)
| 340 | /// goals can be deleted. Started work should be closed or superseded |
| 341 | /// instead of removed from the vault. |
| 342 | pub fn vault_intent_delete( |
| 343 | &self, |
| 344 | intent_id: &str, |
| 345 | ) -> Result<IntentDeleteResult, RepositoryError> { |
| 346 | let full_id = self.normalize_intent_id(intent_id)?; |
| 347 | let intent_file = |
| 348 | self.find_intent_path(&full_id)? |
| 349 | .ok_or_else(|| RepositoryError::InvalidOperation { |
| 350 | message: format!("Intent '{}' not found", full_id), |
| 351 | })?; |
| 352 | |
| 353 | let manifest = self.vault_manifest()?; |
| 354 | let summary = |
| 355 | manifest |
| 356 | .intents |
| 357 | .get(&full_id) |
| 358 | .ok_or_else(|| RepositoryError::InvalidOperation { |
| 359 | message: format!("Intent '{}' not found", full_id), |
| 360 | })?; |
| 361 | |
| 362 | if summary.status != "backlog" { |
| 363 | return Err(RepositoryError::InvalidOperation { |
| 364 | message: format!( |
| 365 | "Intent '{}' has status '{}'; only backlog intents can be deleted", |
| 366 | full_id, summary.status |
| 367 | ), |
| 368 | }); |
| 369 | } |
| 370 | |
| 371 | let referenced_goals = manifest |
| 372 | .goals |
| 373 | .values() |
| 374 | .filter(|goal| { |
| 375 | goal.intent |
| 376 | .as_deref() |
| 377 | .is_some_and(|id| id.eq_ignore_ascii_case(&full_id)) |
| 378 | }) |
| 379 | .count() as u32; |
| 380 | let linked_goals = summary.goals.max(referenced_goals); |
| 381 | |
| 382 | if linked_goals > 0 { |
| 383 | return Err(RepositoryError::InvalidOperation { |
| 384 | message: format!( |
| 385 | "Intent '{}' is linked to {} goal(s); unlink or close the work instead", |
| 386 | full_id, linked_goals |
| 387 | ), |
| 388 | }); |
| 389 | } |
| 390 | |
| 391 | let deleted = self.vault_delete(&intent_file)?; |
| 392 | if !deleted { |
| 393 | return Err(RepositoryError::InvalidOperation { |
| 394 | message: format!("Intent '{}' not found", full_id), |
| 395 | }); |
| 396 | } |
| 397 | |
| 398 | { |
| 399 | let mut txn = self |