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,
)
| 325 | /// goals can be deleted. Started work should be closed or superseded |
| 326 | /// instead of removed from the vault. |
| 327 | pub fn vault_intent_delete( |
| 328 | &self, |
| 329 | intent_id: &str, |
| 330 | ) -> Result<IntentDeleteResult, RepositoryError> { |
| 331 | let full_id = self.normalize_intent_id(intent_id)?; |
| 332 | let intent_file = |
| 333 | self.find_intent_path(&full_id)? |
| 334 | .ok_or_else(|| RepositoryError::InvalidOperation { |
| 335 | message: format!("Intent '{}' not found", full_id), |
| 336 | })?; |
| 337 | |
| 338 | let manifest = self.vault_manifest()?; |
| 339 | let summary = |
| 340 | manifest |
| 341 | .intents |
| 342 | .get(&full_id) |
| 343 | .ok_or_else(|| RepositoryError::InvalidOperation { |
| 344 | message: format!("Intent '{}' not found", full_id), |
| 345 | })?; |
| 346 | |
| 347 | if summary.status != "backlog" { |
| 348 | return Err(RepositoryError::InvalidOperation { |
| 349 | message: format!( |
| 350 | "Intent '{}' has status '{}'; only backlog intents can be deleted", |
| 351 | full_id, summary.status |
| 352 | ), |
| 353 | }); |
| 354 | } |
| 355 | |
| 356 | let referenced_goals = manifest |
| 357 | .goals |
| 358 | .values() |
| 359 | .filter(|goal| { |
| 360 | goal.intent |
| 361 | .as_deref() |
| 362 | .is_some_and(|id| id.eq_ignore_ascii_case(&full_id)) |
| 363 | }) |
| 364 | .count() as u32; |
| 365 | let linked_goals = summary.goals.max(referenced_goals); |
| 366 | |
| 367 | if linked_goals > 0 { |
| 368 | return Err(RepositoryError::InvalidOperation { |
| 369 | message: format!( |
| 370 | "Intent '{}' is linked to {} goal(s); unlink or close the work instead", |
| 371 | full_id, linked_goals |
| 372 | ), |
| 373 | }); |
| 374 | } |
| 375 | |
| 376 | let deleted = self.vault_delete(&intent_file)?; |
| 377 | if !deleted { |
| 378 | return Err(RepositoryError::InvalidOperation { |
| 379 | message: format!("Intent '{}' not found", full_id), |
| 380 | }); |
| 381 | } |
| 382 | |
| 383 | { |
| 384 | let mut txn = self |