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,
)
| 555 | /// goals can be deleted. Started work should be closed or superseded |
| 556 | /// instead of removed from the vault. |
| 557 | pub fn vault_intent_delete( |
| 558 | &self, |
| 559 | intent_id: &str, |
| 560 | ) -> Result<IntentDeleteResult, RepositoryError> { |
| 561 | let full_id = self.normalize_intent_id(intent_id)?; |
| 562 | let intent_file = |
| 563 | self.find_intent_path(&full_id)? |
| 564 | .ok_or_else(|| RepositoryError::InvalidOperation { |
| 565 | message: format!("Intent '{}' not found", full_id), |
| 566 | })?; |
| 567 | |
| 568 | let manifest = self.vault_manifest()?; |
| 569 | let summary = |
| 570 | manifest |
| 571 | .intents |
| 572 | .get(&full_id) |
| 573 | .ok_or_else(|| RepositoryError::InvalidOperation { |
| 574 | message: format!("Intent '{}' not found", full_id), |
| 575 | })?; |
| 576 | |
| 577 | if summary.status != "backlog" { |
| 578 | return Err(RepositoryError::InvalidOperation { |
| 579 | message: format!( |
| 580 | "Intent '{}' has status '{}'; only backlog intents can be deleted", |
| 581 | full_id, summary.status |
| 582 | ), |
| 583 | }); |
| 584 | } |
| 585 | |
| 586 | let referenced_goals = manifest |
| 587 | .goals |
| 588 | .values() |
| 589 | .filter(|goal| { |
| 590 | goal.intent |
| 591 | .as_deref() |
| 592 | .is_some_and(|id| id.eq_ignore_ascii_case(&full_id)) |
| 593 | }) |
| 594 | .count() as u32; |
| 595 | let linked_goals = summary.goals.max(referenced_goals); |
| 596 | |
| 597 | if linked_goals > 0 { |
| 598 | return Err(RepositoryError::InvalidOperation { |
| 599 | message: format!( |
| 600 | "Intent '{}' is linked to {} goal(s); unlink or close the work instead", |
| 601 | full_id, linked_goals |
| 602 | ), |
| 603 | }); |
| 604 | } |
| 605 | |
| 606 | let deleted = self.vault_delete(&intent_file)?; |
| 607 | if !deleted { |
| 608 | return Err(RepositoryError::InvalidOperation { |
| 609 | message: format!("Intent '{}' not found", full_id), |
| 610 | }); |
| 611 | } |
| 612 | |
| 613 | { |
| 614 | let mut txn = self |