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

Method run

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

memory_newFunction · 0.85
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

Tested by

no test coverage detected