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

Method vault_intent_link

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

Link a goal to an intent.

(
        &self,
        intent_id: &str,
        goal_name: &str,
    )

Source from the content-addressed store, hash-verified

556
557 /// Link a goal to an intent.
558 pub fn vault_intent_link(
559 &self,
560 intent_id: &str,
561 goal_name: &str,
562 ) -> Result<(), RepositoryError> {
563 let full_id = self.normalize_intent_id(intent_id)?;
564 let intent_file =
565 self.find_intent_path(&full_id)?
566 .ok_or_else(|| RepositoryError::InvalidOperation {
567 message: format!("Intent '{}' not found", full_id),
568 })?;
569
570 // Read from disk first so we pick up any user/agent edits to the
571 // markdown body (same pattern as vault_intent_update).
572 let disk_path = self.vault_dir().join(&intent_file);
573 let (content_bytes, frontmatter_json) = if disk_path.exists() {
574 let file_content = std::fs::read_to_string(&disk_path)?;
575 let (fm_json, body) = crate::repository::vault::parse_vault_frontmatter(&file_content);
576 (body.into_bytes(), fm_json)
577 } else {
578 let entry = self.vault_retrieve(&intent_file)?.ok_or_else(|| {
579 RepositoryError::InvalidOperation {
580 message: format!("Intent '{}' not found", full_id),
581 }
582 })?;
583 (entry.content_bytes.clone(), entry.frontmatter_json.clone())
584 };
585
586 // Verify goal exists
587 let goal_file = format!("goals/{}/_goal.md", goal_name);
588 if self.vault_retrieve(&goal_file)?.is_none() {
589 return Err(RepositoryError::InvalidOperation {
590 message: format!("Goal '{}' not found", goal_name),
591 });
592 }
593
594 // Update frontmatter to add goal to the list
595 let mut fm: serde_json::Map<String, serde_json::Value> =
596 serde_json::from_str(&frontmatter_json).unwrap_or_default();
597
598 let goals = fm
599 .entry("goals".to_string())
600 .or_insert_with(|| serde_json::Value::Array(Vec::new()));
601 if let serde_json::Value::Array(ref mut arr) = goals {
602 let goal_val = serde_json::Value::String(goal_name.to_string());
603 if !arr.contains(&goal_val) {
604 arr.push(goal_val);
605 }
606 }
607 let new_fm = serde_json::to_string(&fm).unwrap_or_else(|_| "{}".to_string());
608
609 self.vault_store(&intent_file, VaultEntryType::Intent, content_bytes, new_fm)?;
610
611 // Update manifest goal count
612 {
613 let mut txn = self
614 .pristine
615 .write_txn()

Callers 5

runMethod · 0.80
runMethod · 0.80
test_intent_link_goalFunction · 0.80

Calls 15

parse_vault_frontmatterFunction · 0.85
normalize_intent_idMethod · 0.80
find_intent_pathMethod · 0.80
vault_dirMethod · 0.80
vault_retrieveMethod · 0.80
is_noneMethod · 0.80
vault_storeMethod · 0.80
write_txnMethod · 0.80
get_mutMethod · 0.80
put_vault_manifestMethod · 0.80
commitMethod · 0.80
vault_materializeMethod · 0.80