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