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>,
)
| 132 | /// a `review` regardless of `kind`. The CLI parser already rejects supplying |
| 133 | /// both explicitly (`conflicts_with`), so this only encodes the precedence. |
| 134 | fn create_intent( |
| 135 | repo: &Repository, |
| 136 | title: &str, |
| 137 | kind: &str, |
| 138 | review_target: Option<&str>, |
| 139 | ) -> CliResult<(IntentCreateResult, String)> { |
| 140 | // Resolve the effective kind + which scaffold to emit. |
| 141 | let (kind, scaffold) = if let Some(target) = review_target { |
| 142 | // Emit the canonical URN even when the caller named the target |
| 143 | // bare. A bare ULID reads fine but projects an edge that nothing |
| 144 | // can match, so the review silently fails to cover its target. |
| 145 | let target = if target.trim().starts_with("urn:") { |
| 146 | target.trim().to_string() |
| 147 | } else { |
| 148 | format!("urn:atomic:intent:{}", target.trim()) |
| 149 | }; |
| 150 | ( |
| 151 | "review".to_string(), |
| 152 | REVIEW_SCAFFOLD.to_string().replace("{target}", &target), |
| 153 | ) |
| 154 | } else { |
| 155 | if !is_known_intent_kind(kind) { |
| 156 | return Err(CliError::InvalidArgument { |
| 157 | message: format!( |
| 158 | "unknown intent kind '{}' (expected one of {:?})", |
| 159 | kind, INTENT_KIND |
| 160 | ), |
| 161 | }); |
| 162 | } |
| 163 | (kind.to_string(), FEATURE_SCAFFOLD.to_string()) |
| 164 | }; |
| 165 | |
| 166 | // A non-default kind is threaded into `IntentCreateOptions` so create writes |
| 167 | // the `kind:` frontmatter key; the default `feature` stays `None` to keep an |
| 168 | // ordinary intent's frontmatter (and canonical hash) byte-for-byte unchanged. |
| 169 | let kind_opt = if kind == "feature" { |
| 170 | None |
| 171 | } else { |
| 172 | Some(kind.clone()) |
| 173 | }; |
| 174 | |
| 175 | // Create through the EXISTING vault write path so the intent enters redb |
| 176 | // normally and joins the merkle exactly as `atomic vault intent create` does |
| 177 | // — we do NOT invent a new redb write. |
| 178 | let created = repo |
| 179 | .vault_intent_create(IntentCreateOptions { |
| 180 | title: title.to_string(), |
| 181 | priority: None, |
| 182 | assignee: None, |
| 183 | labels: Vec::new(), |
| 184 | session_id: None, |
| 185 | turn_id: None, |
| 186 | kind: kind_opt, |
| 187 | }) |
| 188 | .map_err(CliError::Repository)?; |
| 189 | |
| 190 | // Overwrite the (legacy positional) scaffold body with the directive |
| 191 | // scaffold, again through the existing update path. `force` is set because |