The core create logic, factored out so it can be unit-tested against an explicit [`Repository`] (the [`Command::run`] impl resolves the repo from the cwd and delegates here). Returns the created intent alongside its resolved classification `kind` (for display). `--review` wins over `--kind`: when `review_target` is `Some`, the intent is a `review` regardless of `kind`. The CLI parser already reje
(
repo: &Repository,
title: &str,
kind: &str,
review_target: Option<&str>,
)
| 61 | /// a `review` regardless of `kind`. The CLI parser already rejects supplying |
| 62 | /// both explicitly (`conflicts_with`), so this only encodes the precedence. |
| 63 | fn create_intent( |
| 64 | repo: &Repository, |
| 65 | title: &str, |
| 66 | kind: &str, |
| 67 | review_target: Option<&str>, |
| 68 | ) -> CliResult<(IntentCreateResult, String)> { |
| 69 | // Resolve the effective kind + which scaffold to emit. |
| 70 | let (kind, scaffold) = if let Some(target) = review_target { |
| 71 | // Emit the canonical URN even when the caller named the target |
| 72 | // bare. A bare ULID reads fine but projects an edge that nothing |
| 73 | // can match, so the review silently fails to cover its target. |
| 74 | let target = if target.trim().starts_with("urn:") { |
| 75 | target.trim().to_string() |
| 76 | } else { |
| 77 | format!("urn:atomic:intent:{}", target.trim()) |
| 78 | }; |
| 79 | ( |
| 80 | "review".to_string(), |
| 81 | REVIEW_SCAFFOLD.to_string().replace("{target}", &target), |
| 82 | ) |
| 83 | } else { |
| 84 | if !is_known_intent_kind(kind) { |
| 85 | return Err(CliError::InvalidArgument { |
| 86 | message: format!( |
| 87 | "unknown intent kind '{}' (expected one of {:?})", |
| 88 | kind, INTENT_KIND |
| 89 | ), |
| 90 | }); |
| 91 | } |
| 92 | (kind.to_string(), FEATURE_SCAFFOLD.to_string()) |
| 93 | }; |
| 94 | |
| 95 | // A non-default kind is threaded into `IntentCreateOptions` so create writes |
| 96 | // the `kind:` frontmatter key; the default `feature` stays `None` to keep an |
| 97 | // ordinary intent's frontmatter (and canonical hash) byte-for-byte unchanged. |
| 98 | let kind_opt = if kind == "feature" { |
| 99 | None |
| 100 | } else { |
| 101 | Some(kind.clone()) |
| 102 | }; |
| 103 | |
| 104 | // Create through the EXISTING vault write path so the intent enters redb |
| 105 | // normally and joins the merkle exactly as `atomic vault intent create` does |
| 106 | // — we do NOT invent a new redb write. |
| 107 | let created = repo |
| 108 | .vault_intent_create(IntentCreateOptions { |
| 109 | title: title.to_string(), |
| 110 | priority: None, |
| 111 | assignee: None, |
| 112 | labels: Vec::new(), |
| 113 | session_id: None, |
| 114 | turn_id: None, |
| 115 | kind: kind_opt, |
| 116 | }) |
| 117 | .map_err(CliError::Repository)?; |
| 118 | |
| 119 | // Overwrite the (legacy positional) scaffold body with the directive |
| 120 | // scaffold, again through the existing update path. `force` is set because |