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

Function create_intent

atomic-cli/src/commands/intent/new.rs:134–203  ·  view source on GitHub ↗

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>,
)

Source from the content-addressed store, hash-verified

132/// a `review` regardless of `kind`. The CLI parser already rejects supplying
133/// both explicitly (`conflicts_with`), so this only encodes the precedence.
134fn 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 (
143 "review".to_string(),
144 REVIEW_SCAFFOLD.to_string().replace("{target}", target),
145 )
146 } else {
147 if !is_known_intent_kind(kind) {
148 return Err(CliError::InvalidArgument {
149 message: format!(
150 "unknown intent kind '{}' (expected one of {:?})",
151 kind, INTENT_KIND
152 ),
153 });
154 }
155 (kind.to_string(), FEATURE_SCAFFOLD.to_string())
156 };
157
158 // A non-default kind is threaded into `IntentCreateOptions` so create writes
159 // the `kind:` frontmatter key; the default `feature` stays `None` to keep an
160 // ordinary intent's frontmatter (and canonical hash) byte-for-byte unchanged.
161 let kind_opt = if kind == "feature" {
162 None
163 } else {
164 Some(kind.clone())
165 };
166
167 // Create through the EXISTING vault write path so the intent enters redb
168 // normally and joins the merkle exactly as `atomic vault intent create` does
169 // — we do NOT invent a new redb write.
170 let created = repo
171 .vault_intent_create(IntentCreateOptions {
172 title: title.to_string(),
173 priority: None,
174 assignee: None,
175 labels: Vec::new(),
176 session_id: None,
177 turn_id: None,
178 kind: kind_opt,
179 })
180 .map_err(CliError::Repository)?;
181
182 // Overwrite the (legacy positional) scaffold body with the directive
183 // scaffold, again through the existing update path. `force` is set because
184 // this runs immediately after create; the intent is a fresh backlog draft
185 // with no linked goal, so force is a no-op guard-skip.
186 //
187 // Child ids (acceptance criteria, tasks) are namespaced under the intent's
188 // ULID — not the human key — so they are globally unique and never carry the
189 // human key's `::`/`-` separators. The frontmatter `kind:` key written at
190 // create time survives this body-only update.
191 let scaffold = scaffold.replace("{id}", &created.uid);

Callers 6

runMethod · 0.85
new_defaults_to_featureFunction · 0.85
new_kind_bug_sets_bugFunction · 0.85
new_kind_bogus_errorsFunction · 0.85

Calls 5

is_known_intent_kindFunction · 0.85
vault_intent_createMethod · 0.80
vault_intent_updateMethod · 0.80
replaceMethod · 0.45
cloneMethod · 0.45