Update an intent's fields.
(
&self,
intent_id: &str,
options: IntentUpdateOptions,
)
| 628 | |
| 629 | /// Update an intent's fields. |
| 630 | pub fn vault_intent_update( |
| 631 | &self, |
| 632 | intent_id: &str, |
| 633 | options: IntentUpdateOptions, |
| 634 | ) -> Result<IntentInfo, RepositoryError> { |
| 635 | let full_id = self.normalize_intent_id(intent_id)?; |
| 636 | let intent_file = |
| 637 | self.find_intent_path(&full_id)? |
| 638 | .ok_or_else(|| RepositoryError::InvalidOperation { |
| 639 | message: format!("Intent '{}' not found", full_id), |
| 640 | })?; |
| 641 | |
| 642 | // Read from disk first so we pick up any user/agent edits to the |
| 643 | // markdown body. If the file doesn't exist on disk, fall back to |
| 644 | // the redb entry. |
| 645 | let disk_path = self.vault_dir().join(&intent_file); |
| 646 | let (content_bytes, frontmatter_json) = if disk_path.exists() { |
| 647 | let file_content = std::fs::read_to_string(&disk_path)?; |
| 648 | let (fm_json, body) = crate::repository::vault::parse_vault_frontmatter(&file_content); |
| 649 | (body.into_bytes(), fm_json) |
| 650 | } else { |
| 651 | let entry = self.vault_retrieve(&intent_file)?.ok_or_else(|| { |
| 652 | RepositoryError::InvalidOperation { |
| 653 | message: format!("Intent '{}' not found", full_id), |
| 654 | } |
| 655 | })?; |
| 656 | (entry.content_bytes.clone(), entry.frontmatter_json.clone()) |
| 657 | }; |
| 658 | |
| 659 | // Update frontmatter |
| 660 | let mut fm: serde_json::Map<String, serde_json::Value> = |
| 661 | serde_json::from_str(&frontmatter_json).unwrap_or_default(); |
| 662 | |
| 663 | // The status as stored on disk BEFORE this update mutates anything. The |
| 664 | // T5b lapse check keys off this: a substance edit on an already-`done` |
| 665 | // intent (that is not itself re-asserting a status) can lapse the grant. |
| 666 | let prior_status = fm |
| 667 | .get("status") |
| 668 | .and_then(|v| v.as_str()) |
| 669 | .map(str::to_string); |
| 670 | // The authoring view is frozen in frontmatter at create time. |
| 671 | // TODO(T5b-follow-up): scope-gating uses this frozen authoring `view` |
| 672 | // (recon gaps #3/#4). A Draft-authored intent whose changes were already |
| 673 | // inserted into a Shared view still reads its original Draft view here; |
| 674 | // precise "Shared doneness is immutable" needs the visibility walk. |
| 675 | let fm_view_name = fm.get("view").and_then(|v| v.as_str()).map(str::to_string); |
| 676 | |
| 677 | if options.content.is_some() && !options.force { |
| 678 | let manifest = self.vault_manifest()?; |
| 679 | let summary = manifest.intents.get(&full_id); |
| 680 | let current_status = summary |
| 681 | .map(|intent| intent.status.as_str()) |
| 682 | .or_else(|| fm.get("status").and_then(|value| value.as_str())) |
| 683 | .unwrap_or("unknown"); |
| 684 | let has_linked_goal = summary.is_some_and(|intent| intent.goals > 0) |
| 685 | || manifest.goals.values().any(|goal| { |
| 686 | goal.intent |
| 687 | .as_deref() |