(&self)
| 42 | |
| 43 | impl Command for IntentValidate { |
| 44 | fn run(&self) -> CliResult<()> { |
| 45 | if crate::commands::rpc::intent_validate(self)? { |
| 46 | return Ok(()); |
| 47 | } |
| 48 | |
| 49 | // Resolve the argument. A path-shaped argument (ends in `.md` or |
| 50 | // contains a separator) is loaded as a file — and if it doesn't exist |
| 51 | // we report FileNotFound rather than misreporting it as a bad ID. |
| 52 | // Otherwise the argument is an intent ID read through the vault bridge; |
| 53 | // if a FRESH attestation sidecar exists we gate the attested node (so a |
| 54 | // previously-attested intent reports conforms), a STALE one warns and |
| 55 | // falls back to the raw node. |
| 56 | let mut stored_inputs = None; |
| 57 | let node = if is_path_shaped(&self.id_or_path) { |
| 58 | let path = Path::new(&self.id_or_path); |
| 59 | if !path.is_file() { |
| 60 | return Err(CliError::FileNotFound { |
| 61 | path: path.to_path_buf(), |
| 62 | }); |
| 63 | } |
| 64 | let doc = std::fs::read_to_string(path).map_err(CliError::Io)?; |
| 65 | let (fm, body) = parse_markdown(&doc).map_err(|e| CliError::InvalidArgument { |
| 66 | message: format!("could not parse markdown frontmatter: {e}"), |
| 67 | })?; |
| 68 | lift_intent(&fm, &body).map_err(|e| CliError::InvalidArgument { |
| 69 | message: format!("could not lift intent: {e}"), |
| 70 | })? |
| 71 | } else { |
| 72 | let root = find_repository_root()?; |
| 73 | let repo = |
| 74 | crate::commands::open_readonly_repository(&root).map_err(CliError::Repository)?; |
| 75 | let inputs = bridge::read_intent(&repo, &self.id_or_path)?; |
| 76 | let node = match bridge::load_attestation(&repo, &self.id_or_path, &inputs)? { |
| 77 | bridge::Attestation::Fresh(node) => *node, |
| 78 | bridge::Attestation::Stale(_) => { |
| 79 | eprintln!( |
| 80 | "warning: the attestation for {} is stale (the intent changed since it \ |
| 81 | was signed); re-run `atomic intent attest {}`.", |
| 82 | self.id_or_path, self.id_or_path |
| 83 | ); |
| 84 | bridge::lift(&inputs)? |
| 85 | } |
| 86 | bridge::Attestation::None => bridge::lift(&inputs)?, |
| 87 | }; |
| 88 | stored_inputs = Some(inputs); |
| 89 | node |
| 90 | }; |
| 91 | |
| 92 | let mut report = validate_intent(&node); |
| 93 | let wants_context = self.evidence_context || self.replay_evidence.is_some(); |
| 94 | if wants_context && is_path_shaped(&self.id_or_path) { |
| 95 | return Err(validation_failed( |
| 96 | "evidence replay/context requires a stored intent ID", |
| 97 | )); |
| 98 | } |
| 99 | let context = if wants_context { |
| 100 | let inputs = stored_inputs.as_ref().ok_or_else(|| { |
| 101 | validation_failed("evidence replay/context requires a stored intent ID") |
nothing calls this directly
no test coverage detected