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

Method vault_intent_update

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

Update an intent's fields.

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

Source from the content-addressed store, hash-verified

429
430 /// Update an intent's fields.
431 pub fn vault_intent_update(
432 &self,
433 intent_id: &str,
434 options: IntentUpdateOptions,
435 ) -> Result<IntentInfo, RepositoryError> {
436 let full_id = self.normalize_intent_id(intent_id)?;
437 let intent_file =
438 self.find_intent_path(&full_id)?
439 .ok_or_else(|| RepositoryError::InvalidOperation {
440 message: format!("Intent '{}' not found", full_id),
441 })?;
442
443 // Read from disk first so we pick up any user/agent edits to the
444 // markdown body. If the file doesn't exist on disk, fall back to
445 // the redb entry.
446 let disk_path = self.vault_dir().join(&intent_file);
447 let (content_bytes, frontmatter_json) = if disk_path.exists() {
448 let file_content = std::fs::read_to_string(&disk_path)?;
449 let (fm_json, body) = crate::repository::vault::parse_vault_frontmatter(&file_content);
450 (body.into_bytes(), fm_json)
451 } else {
452 let entry = self.vault_retrieve(&intent_file)?.ok_or_else(|| {
453 RepositoryError::InvalidOperation {
454 message: format!("Intent '{}' not found", full_id),
455 }
456 })?;
457 (entry.content_bytes.clone(), entry.frontmatter_json.clone())
458 };
459
460 // Update frontmatter
461 let mut fm: serde_json::Map<String, serde_json::Value> =
462 serde_json::from_str(&frontmatter_json).unwrap_or_default();
463
464 if options.content.is_some() && !options.force {
465 let manifest = self.vault_manifest()?;
466 let summary = manifest.intents.get(&full_id);
467 let current_status = summary
468 .map(|intent| intent.status.as_str())
469 .or_else(|| fm.get("status").and_then(|value| value.as_str()))
470 .unwrap_or("unknown");
471 let has_linked_goal = summary.is_some_and(|intent| intent.goals > 0)
472 || manifest.goals.values().any(|goal| {
473 goal.intent
474 .as_deref()
475 .is_some_and(|id| id.eq_ignore_ascii_case(&full_id))
476 });
477
478 if current_status != "backlog" || has_linked_goal {
479 return Err(RepositoryError::InvalidOperation {
480 message: format!(
481 "Intent '{}' has started or is linked to a goal; rewriting its body would \
482 change the execution context. Retry with force enabled.",
483 full_id
484 ),
485 });
486 }
487 }
488

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
vault_manifestMethod · 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