MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / vault_intent_update

Method vault_intent_update

atomic-repository/src/repository/vault_intent.rs:606–816  ·  view source on GitHub ↗

Update an intent's fields.

(
        &self,
        intent_id: &str,
        options: IntentUpdateOptions,
    )

Source from the content-addressed store, hash-verified

604
605 /// Update an intent's fields.
606 pub fn vault_intent_update(
607 &self,
608 intent_id: &str,
609 options: IntentUpdateOptions,
610 ) -> Result<IntentInfo, RepositoryError> {
611 let full_id = self.normalize_intent_id(intent_id)?;
612 let intent_file =
613 self.find_intent_path(&full_id)?
614 .ok_or_else(|| RepositoryError::InvalidOperation {
615 message: format!("Intent '{}' not found", full_id),
616 })?;
617
618 // Read from disk first so we pick up any user/agent edits to the
619 // markdown body. If the file doesn't exist on disk, fall back to
620 // the redb entry.
621 let disk_path = self.vault_dir().join(&intent_file);
622 let (content_bytes, frontmatter_json) = if disk_path.exists() {
623 let file_content = std::fs::read_to_string(&disk_path)?;
624 let (fm_json, body) = crate::repository::vault::parse_vault_frontmatter(&file_content);
625 (body.into_bytes(), fm_json)
626 } else {
627 let entry = self.vault_retrieve(&intent_file)?.ok_or_else(|| {
628 RepositoryError::InvalidOperation {
629 message: format!("Intent '{}' not found", full_id),
630 }
631 })?;
632 (entry.content_bytes.clone(), entry.frontmatter_json.clone())
633 };
634
635 // Update frontmatter
636 let mut fm: serde_json::Map<String, serde_json::Value> =
637 serde_json::from_str(&frontmatter_json).unwrap_or_default();
638
639 if options.content.is_some() && !options.force {
640 let manifest = self.vault_manifest()?;
641 let summary = manifest.intents.get(&full_id);
642 let current_status = summary
643 .map(|intent| intent.status.as_str())
644 .or_else(|| fm.get("status").and_then(|value| value.as_str()))
645 .unwrap_or("unknown");
646 let has_linked_goal = summary.is_some_and(|intent| intent.goals > 0)
647 || manifest.goals.values().any(|goal| {
648 goal.intent
649 .as_deref()
650 .is_some_and(|id| id.eq_ignore_ascii_case(&full_id))
651 });
652
653 if current_status != "backlog" || has_linked_goal {
654 return Err(RepositoryError::InvalidOperation {
655 message: format!(
656 "Intent '{}' has started or is linked to a goal; rewriting its body would \
657 change the execution context. Retry with force enabled.",
658 full_id
659 ),
660 });
661 }
662 }
663

Calls 15

parse_vault_frontmatterFunction · 0.85
lift_intentFunction · 0.85
validate_intentFunction · 0.85
normalize_intent_idMethod · 0.80
find_intent_pathMethod · 0.80
vault_dirMethod · 0.80
vault_retrieveMethod · 0.80
vault_manifestMethod · 0.80
vault_storeMethod · 0.80
write_txnMethod · 0.80
get_mutMethod · 0.80
put_vault_manifestMethod · 0.80