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