Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/blob/main/crates/aien-closure/src/manifest.rs # aien-sovereign-core-mv AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / crates / aien-closure / src / manifest.rs` 209 lines ยท 7453 bytes Raw Blame History 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 //! `closure.toml`: strict, line based component manifest, in the style of the 17 //! aien-test `.gate` format. Despite the file name it is not general TOML. 18 //! 19 //! ```text 20 //! closure-manifest v1 21 //! component aien-scheduler 22 //! profile host-v1 23 //! receipt <64 hex> 24 //! source blake3:<64 hex> 25 //! dep aien-kv-cache <64 hex receipt id of that dependency> 26 //! dep aien-platform 27 //! ``` 28 //! 29 //! Rules: first line is the header; `component`, `profile`, `receipt` and 30 //! `source` appear exactly once; `dep` lines are unique per name; no tabs, no 31 //! CR, no blank lines, no comments, no trailing whitespace, no unknown keys. A 32 //! `dep` line without a receipt id parses (it is reported as 33 //! DEPENDENCY_NOT_PINNED by the verifier, not hidden here). 34 35 use std::collections::BTreeMap; 36 37 pub const FILE_NAME: &str = "closure.toml"; 38 pub const HEADER: &str = "closure-manifest v1"; 39 pub const MAX_BYTES: usize = 64 * 1024; 40 41 #[derive(Debug, Clone, PartialEq, Eq)] 42 pub struct Manifest { 43 pub component: String, 44 pub profile: String, 45 /// Receipt id (lowercase hex) that qualifies this component. 46 pub receipt: String, 47 /// `blake3:` digest of the component source the receipt was taken at. 48 pub source: String, 49 /// Declared internal deps: name -> pinned receipt id of that dependency. 50 pub deps: BTreeMap>, 51 } 52 53 pub fn is_hex64(s: &str) -> bool { 54 s.len() == 64 55 && s.bytes() 56 .all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b)) 57 } 58 59 fn is_name(s: &str) -> bool { 60 !s.is_empty() 61 && s.bytes() 62 .all(|b| b.is_ascii_alphanumeric() || b == b'_' || b == b'-' || b == b'.') 63 } 64 65 pub fn parse(text: &str) -> Result { 66 if text.len() > MAX_BYTES { 67 return Err("manifest too large".into()); 68 } 69 if text.starts_with('\u{feff}') { 70 return Err("BOM not allowed".into()); 71 } 72 if text.contains('\r') || text.contains('\t') { 73 return Err("tabs and CR are not allowed".into()); 74 } 75 let body = text 76 .strip_suffix('\n') 77 .ok_or("file must end with a single newline")?; 78 let mut lines = body.split('\n').enumerate(); 79 match lines.next() { 80 Some((_, l)) if l == HEADER => {} 81 _ => return Err(format!("line 1: expected header {HEADER:?}")), 82 } 83 let mut component = None; 84 let mut profile = None; 85 let mut receipt = None; 86 let mut source = None; 87 let mut deps: BTreeMap> = BTreeMap::new(); 88 for (i, line) in lines { 89 let n = i + 1; 90 if line.is_empty() || line != line.trim() { 91 return Err(format!("line {n}: blank line or stray whitespace")); 92 } 93 let parts: Vec<&str> = line.split(' ').collect(); 94 if parts.iter().any(|p| p.is_empty()) { 95 return Err(format!("line {n}: repeated spaces")); 96 } 97 match (parts[0], parts.len()) { 98 ("component", 2) | ("profile", 2) => { 99 if !is_name(parts[1]) { 100 return Err(format!("line {n}: bad name {:?}", parts[1])); 101 } 102 let slot = if parts[0] == "component" { 103 &mut component 104 } else { 105 &mut profile 106 }; 107 if slot.replace(parts[1].to_string()).is_some() { 108 return Err(format!("line {n}: duplicate {}", parts[0])); 109 } 110 } 111 ("receipt", 2) => { 112 if !is_hex64(parts[1]) { 113 return Err(format!("line {n}: receipt must be 64 lowercase hex")); 114 } 115 if receipt.replace(parts[1].to_string()).is_some() { 116 return Err(format!("line {n}: duplicate receipt")); 117 } 118 } 119 ("source", 2) => { 120 let ok = parts[1].strip_prefix("blake3:").is_some_and(is_hex64); 121 if !ok { 122 return Err(format!( 123 "line {n}: source must be blake3:<64 lowercase hex>" 124 )); 125 } 126 if source.replace(parts[1].to_string()).is_some() { 127 return Err(format!("line {n}: duplicate source")); 128 } 129 } 130 ("dep", 2) | ("dep", 3) => { 131 if !is_name(parts[1]) { 132 return Err(format!("line {n}: bad dep name {:?}", parts[1])); 133 } 134 let pin = match parts.get(2) { 135 Some(p) if is_hex64(p) => Some(p.to_string()), 136 Some(_) => return Err(format!("line {n}: dep pin must be 64 lowercase hex")), 137 None => None, 138 }; 139 if deps.insert(parts[1].to_string(), pin).is_some() { 140 return Err(format!("line {n}: duplicate dep {}", parts[1])); 141 } 142 } 143 (key, _) => return Err(format!("line {n}: unknown or malformed key {key:?}")), 144 } 145 } 146 Ok(Manifest { 147 component: component.ok_or("missing component")?, 148 profile: profile.ok_or("missing profile")?, 149 receipt: receipt.ok_or("missing receipt")?, 150 source: source.ok_or("missing source")?, 151 deps, 152 }) 153 } 154 155 pub fn render(m: &Manifest) -> String { 156 let mut s = format!( 157 "{HEADER}\ncomponent {}\nprofile {}\nreceipt {}\nsource {}\n", 158 m.component, m.profile, m.receipt, m.source 159 ); 160 for (name, pin) in &m.deps { 161 match pin { 162 Some(p) => s.push_str(&format!("dep {name} {p}\n")), 163 None => s.push_str(&format!("dep {name}\n")), 164 } 165 } 166 s 167 } 168 169 #[cfg(test)] 170 mod tests { 171 use super::*; 172 173 fn sample() -> Manifest { 174 let mut deps = BTreeMap::new(); 175 deps.insert("b".to_string(), Some("1".repeat(64))); 176 deps.insert("c".to_string(), None); 177 Manifest { 178 component: "a".into(), 179 profile: "host-v1".into(), 180 receipt: "2".repeat(64), 181 source: format!("blake3:{}", "3".repeat(64)), 182 deps, 183 } 184 } 185 186 #[test] 187 fn round_trips() { 188 let m = sample(); 189 assert_eq!(parse(&render(&m)).unwrap(), m); 190 } 191 192 #[test] 193 fn rejects_malformed() { 194 let good = render(&sample()); 195 for bad in [ 196 good.replace("closure-manifest v1", "closure-manifest v2"), 197 good.replace('\n', "\r\n"), 198 good.trim_end().to_string(), 199 format!("{good}\n"), 200 format!("{good}extra thing\n"), 201 format!("{good}component again\n"), 202 good.replace("profile host-v1\n", ""), 203 good.replace(&"2".repeat(64), "XYZ"), 204 format!("{good}dep b\n"), 205 ] { 206 assert!(parse(&bad).is_err(), "should reject:\n{bad}"); 207 } 208 } 209 }