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

Function create_intent

atomic-cli/src/commands/intent/new.rs:62–149  ·  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

60/// a `review` regardless of `kind`. The CLI parser already rejects supplying
61/// both explicitly (`conflicts_with`), so this only encodes the precedence.
62fn create_intent(
63 repo: &Repository,
64 title: &str,
65 kind: &str,
66 review_target: Option<&str>,
67) -> CliResult<(IntentCreateResult, String)> {
68 // Resolve the effective kind + which scaffold to emit.
69 let (kind, scaffold) = if let Some(target) = review_target {
70 // Emit the canonical URN even when the caller named the target
71 // bare. A bare ULID reads fine but projects an edge that nothing
72 // can match, so the review silently fails to cover its target.
73 let target = if target.trim().starts_with("urn:") {
74 target.trim().to_string()
75 } else {
76 format!("urn:atomic:intent:{}", target.trim())
77 };
78 (
79 "review".to_string(),
80 REVIEW_SCAFFOLD.to_string().replace("{target}", &target),
81 )
82 } else {
83 if !is_known_intent_kind(kind) {
84 return Err(CliError::InvalidArgument {
85 message: format!(
86 "unknown intent kind '{}' (expected one of {:?})",
87 kind, INTENT_KIND
88 ),
89 });
90 }
91 (
92 kind.to_string(),
93 if kind == "review" {
94 REVIEW_SCAFFOLD.replace(
95 ":::ref{to={target} edge=reviews}\n:::\n",
96 "<!-- Add one or more ::ref{to=urn:atomic:intent:UID edge=reviews} links. -->\n",
97 )
98 } else {
99 FEATURE_SCAFFOLD.to_string()
100 },
101 )
102 };
103
104 // A non-default kind is threaded into `IntentCreateOptions` so create writes
105 // the `kind:` frontmatter key; the default `feature` stays `None` to keep an
106 // ordinary intent's frontmatter (and canonical hash) byte-for-byte unchanged.
107 let kind_opt = if kind == "feature" {
108 None
109 } else {
110 Some(kind.clone())
111 };
112
113 // Create through the EXISTING vault write path so the intent enters redb
114 // normally and joins the merkle exactly as `atomic vault intent create` does
115 // — we do NOT invent a new redb write.
116 let created = repo
117 .vault_intent_create(IntentCreateOptions {
118 title: title.to_string(),
119 priority: None,

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