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

Method run

atomic-cli/src/commands/memory/new.rs:77–195  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

75
76impl Command for MemoryNew {
77 fn run(&self) -> CliResult<()> {
78 // Reject a bad --kind EARLY (before touching the vault) so `new` never
79 // writes a non-liftable / non-conforming spine.
80 if !MEMORY_KIND.contains(&self.kind.as_str()) {
81 return Err(CliError::InvalidArgument {
82 message: format!(
83 "unknown memory kind '{}' (one of {:?})",
84 self.kind, MEMORY_KIND
85 ),
86 });
87 }
88 // status is an equally-closed vocabulary — reject a bad one early too,
89 // so `new` never persists a non-conforming spine (the gate would only
90 // catch it later at validate/attest).
91 if !MEMORY_STATUS.contains(&self.status.as_str()) {
92 return Err(CliError::InvalidArgument {
93 message: format!(
94 "unknown memory status '{}' (one of {:?})",
95 self.status, MEMORY_STATUS
96 ),
97 });
98 }
99 if self
100 .text
101 .as_ref()
102 .is_some_and(|text| text.trim().is_empty())
103 {
104 return Err(CliError::InvalidArgument {
105 message: "memory text cannot be empty".to_string(),
106 });
107 }
108
109 let root = find_repository_root()?;
110 let repo = Repository::open(&root).map_err(CliError::Repository)?;
111
112 let id = self.id.clone().unwrap_or_else(generate_ulid_lowercased);
113 let vault_path = bridge::normalize_memory_path(&id);
114
115 // Build the frontmatter SPINE as FLAT SCALAR/array fields only (so it
116 // survives yaml_frontmatter_to_json round-trip). Do NOT write
117 // attributedTo/proof/contentHash — attest fills those. createdAt is
118 // STABLE (load-bearing: it is signed, so every re-lift must reproduce
119 // byte-identical signing bytes).
120 let mut spine = Map::new();
121 spine.insert("uid".into(), Value::String(id.clone()));
122 spine.insert("memoryKind".into(), Value::String(self.kind.clone()));
123 spine.insert("status".into(), Value::String(self.status.clone()));
124 spine.insert(
125 "createdAt".into(),
126 Value::String(chrono::Utc::now().to_rfc3339()),
127 );
128 if !self.about.is_empty() {
129 spine.insert(
130 "about".into(),
131 Value::Array(self.about.iter().cloned().map(Value::String).collect()),
132 );
133 }
134 if !self.derived_from.is_empty() {

Callers

nothing calls this directly

Calls 12

find_repository_rootFunction · 0.85
normalize_memory_pathFunction · 0.85
as_refMethod · 0.80
vault_storeMethod · 0.80
vault_materializeMethod · 0.80
is_noneMethod · 0.80
containsMethod · 0.45
as_strMethod · 0.45
is_emptyMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected