aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / crates / site-builder / src / components / names.rs
| 1 | //! Canonical names in rendered copy. Every visible spelling of a project, |
| 2 | //! product or vendor name must match `CANON`: "Aienos", "AIEN" in a |
| 3 | //! sentence, "Github" or a visible "Allen" (renamed to Aien) fail the build. |
| 4 | //! |
| 5 | //! Not copy, so never checked: attributes (href, id, data-speaker="allen"), |
| 6 | //! `<script>`, `<style>`, `<code>`, `<pre>`, `<kbd>`, `<samp>`, any element |
| 7 | //! marked `data-verbatim` (quoted third-party words such as GitHub repository |
| 8 | //! descriptions), identifier joins (aien-dev, aienos.com, nvidia.ko), the |
| 9 | //! phrases in `ALLOW` (published titles, CI check names) and text copied |
| 10 | //! verbatim from a record: the work ledger on /now/, the research status table |
| 11 | //! and the titles read from GitHub into `facts.json` (merged PR titles, decision |
| 12 | //! record titles, the receipt's commit title and status). Hand-written roles in |
| 13 | //! `facts.json` are not a record. A label written entirely in |
| 14 | //! capitals (AIEN VERIFICATION) uppercases every name, so it is not a misspelling. |
| 15 | |
| 16 | use regex::Regex; |
| 17 | use std::fs; |
| 18 | use std::path::Path; |
| 19 | |
| 20 | /// (every spelling, as a pattern; the accepted spellings). A match passes |
| 21 | /// only when it equals an accepted spelling exactly. Lowercase `aienos` is |
| 22 | /// the repository aien-dev/aienos, named in records as "aienos #440". |
| 23 | pub const CANON: &[(&str, &[&str])] = &[ |
| 24 | (r"(?i)\baien\s?os\b", &["AienOS", "aienos"]), |
| 25 | (r"(?i)\baien\b", &["Aien"]), |
| 26 | (r"\bAllen\b", &["Aien"]), |
| 27 | (r"(?i)\baienix\b", &["aienix"]), |
| 28 | (r"(?i)\baienux\b", &["aienux"]), |
| 29 | (r"(?i)\bgithub\b", &["GitHub"]), |
| 30 | (r"(?i)\bnvidia\b", &["NVIDIA"]), |
| 31 | (r"(?i)\bwebassembly\b", &["WebAssembly"]), |
| 32 | (r"(?i)\bimac\b", &["iMac"]), |
| 33 | (r"(?i)\bzenodo\b", &["Zenodo"]), |
| 34 | (r"(?i)\bopencl\b", &["OpenCL"]), |
| 35 | (r"(?i)\bpocl\b", &["PoCL"]), |
| 36 | (r"(?i)\bspir-?v\b", &["SPIR-V"]), |
| 37 | (r"(?i)\buefi\b", &["UEFI"]), |
| 38 | (r"(?i)\bdgx\b", &["DGX"]), |
| 39 | (r"(?i)\bgb10\b", &["GB10"]), |
| 40 | (r"(?i)\bqwen\b", &["Qwen"]), |
| 41 | (r"(?i)\bcuda\+\+", &["CUDA++"]), |
| 42 | ]; |
| 43 | |
| 44 | /// Exact phrases that keep a non-canonical spelling on purpose, on every page. |
| 45 | /// Each one is a published title, a CI check name or a dated record. |
| 46 | pub const ALLOW: &[&str] = &[ |
| 47 | // Zenodo-published paper titles, kept as published. |
| 48 | "The AIEN Papers", |
| 49 | "Atemporal AIEN", |
| 50 | "Measure Emerging from AIEN", |
| 51 | // Citation of a published preprint: the publisher line as printed. |
| 52 | "AIEN Research, 2026", |
| 53 | // The required CI check and its Spark context, named exactly as GitHub shows them. |
| 54 | "AIEN Verification", |
| 55 | // A product name and an image caption, kept until Drake decides. |
| 56 | "AIEN Rig", |
| 57 | "AIEN headband", |
| 58 | ]; |
| 59 | |
| 60 | |
| 61 | const SKIP_TAGS: &[&str] = &["script", "style", "code", "pre", "kbd", "samp"]; |
| 62 | |
| 63 | fn tag_name(tag: &str) -> String { |
| 64 | tag.trim_start_matches('<').trim_start_matches('/').chars().take_while(|c| c.is_ascii_alphanumeric()).collect::<String>().to_ascii_lowercase() |
| 65 | } |
| 66 | |
| 67 | /// Visible copy of an HTML page with every tag turned into a line break, so a |
| 68 | /// label stays one line. Skipped elements (see the module doc) are removed. |
| 69 | pub fn copy_text(raw: &str) -> String { |
| 70 | let mut out = String::with_capacity(raw.len()); |
| 71 | let mut i = 0; |
| 72 | while let Some(off) = raw[i..].find('<') { |
| 73 | out.push_str(&raw[i..i + off]); |
| 74 | let start = i + off; |
| 75 | if raw[start..].starts_with("<!--") { |
| 76 | i = raw[start..].find("-->").map_or(raw.len(), |e| start + e + 3); |
| 77 | out.push('\n'); |
| 78 | continue; |
| 79 | } |
| 80 | let end = raw[start..].find('>').map_or(raw.len(), |e| start + e + 1); |
| 81 | let tag = &raw[start..end]; |
| 82 | let name = tag_name(tag); |
| 83 | out.push('\n'); |
| 84 | i = end; |
| 85 | let opening = !tag.starts_with("</") && !tag.ends_with("/>") && !name.is_empty(); |
| 86 | if opening && (SKIP_TAGS.contains(&name.as_str()) || tag.contains(" data-verbatim")) { |
| 87 | // Skip to the matching close tag of the same name. |
| 88 | let (open, close) = (format!("<{name}"), format!("</{name}")); |
| 89 | let mut depth = 1; |
| 90 | let mut j = end; |
| 91 | while depth > 0 { |
| 92 | let Some(n) = raw[j..].find('<') else { j = raw.len(); break }; |
| 93 | let at = j + n; |
| 94 | let rest = &raw[at..]; |
| 95 | let te = rest.find('>').map_or(raw.len(), |e| at + e + 1); |
| 96 | let t = &raw[at..te]; |
| 97 | if rest.starts_with(&close) && tag_name(t) == name { |
| 98 | depth -= 1; |
| 99 | } else if rest.starts_with(&open) && tag_name(t) == name && !t.ends_with("/>") { |
| 100 | depth += 1; |
| 101 | } |
| 102 | j = te; |
| 103 | } |
| 104 | i = j; |
| 105 | } |
| 106 | } |
| 107 | out.push_str(&raw[i.min(raw.len())..]); |
| 108 | out.replace("&", "&") |
| 109 | .replace("'", "'") |
| 110 | .replace("'", "'") |
| 111 | .replace(""", "\"") |
| 112 | .replace("<", "<") |
| 113 | .replace(">", ">") |
| 114 | .replace(" ", " ") |
| 115 | } |
| 116 | |
| 117 | fn squash(s: &str) -> String { |
| 118 | s.split_whitespace().collect::<Vec<_>>().join(" ") |
| 119 | } |
| 120 | |
| 121 | /// A line written entirely in capitals with at least two words is a styled label. |
| 122 | fn caps_label(line: &str) -> bool { |
| 123 | let words = line.split(|c: char| !c.is_alphabetic()).filter(|w| w.chars().count() >= 2).count(); |
| 124 | // Every letter is a capital; CJK text has no case, so it is never a label. |
| 125 | words >= 2 && line.chars().filter(|c| c.is_alphabetic()).all(|c| c.is_uppercase()) |
| 126 | } |
| 127 | |
| 128 | /// Non-canonical names in the copy `text` of the page `rel`, after removing |
| 129 | /// `ALLOW` phrases and link targets. A match passes when the record holds it |
| 130 | /// with at least four characters of the same context on one side. |
| 131 | pub fn violations(text: &str, record: &str) -> Vec<String> { |
| 132 | let links = Regex::new(r"https?://\S+").unwrap(); |
| 133 | let rules: Vec<(Regex, &[&str])> = CANON.iter().map(|(p, c)| (Regex::new(p).unwrap(), *c)).collect(); |
| 134 | let mut out = Vec::new(); |
| 135 | for raw_line in text.lines() { |
| 136 | let mut line = raw_line.to_string(); |
| 137 | for phrase in ALLOW { |
| 138 | line = line.replace(phrase, " "); |
| 139 | } |
| 140 | let line = squash(&links.replace_all(&line, " ")); |
| 141 | if line.is_empty() || caps_label(&line) { |
| 142 | continue; |
| 143 | } |
| 144 | for (re, canon) in &rules { |
| 145 | for m in re.find_iter(&line) { |
| 146 | if canon.contains(&m.as_str()) { |
| 147 | continue; |
| 148 | } |
| 149 | // Identifier and address parts: aien-dev, aienos.com, nvidia.ko, @aien. |
| 150 | let joined = |c: Option<char>| c.is_some_and(|c| matches!(c, '-' | '_' | '/' | '.' | '#' | '@' | '=')); |
| 151 | let next = line[m.end()..].chars().next(); |
| 152 | let trailing_dot = next == Some('.') && line[m.end() + 1..].chars().next().is_none_or(|c| c.is_whitespace()); |
| 153 | if joined(line[..m.start()].chars().last()) || (joined(next) && !trailing_dot) { |
| 154 | continue; |
| 155 | } |
| 156 | if in_record(&line, m.start(), m.end(), record) { |
| 157 | continue; |
| 158 | } |
| 159 | out.push(format!("\"{}\" should be \"{}\" in: {line}", m.as_str(), canon[0])); |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | out |
| 164 | } |
| 165 | |
| 166 | /// The match with up to 12 characters of context on either side, read in |
| 167 | /// the record. A side shorter than four characters proves nothing. |
| 168 | fn in_record(line: &str, s: usize, e: usize, record: &str) -> bool { |
| 169 | if record.is_empty() { |
| 170 | return false; |
| 171 | } |
| 172 | let before: Vec<usize> = line[..s].char_indices().map(|(i, _)| i).collect(); |
| 173 | let after: Vec<usize> = line[e..].char_indices().map(|(i, _)| e + i).chain([line.len()]).collect(); |
| 174 | let b = before.len().min(12); |
| 175 | let a = (after.len() - 1).min(12); |
| 176 | (b >= 4 && record.contains(&line[before[before.len() - b]..e])) || (a >= 4 && record.contains(&line[s..after[a]])) |
| 177 | } |
| 178 | |
| 179 | /// Every string in the research status record, one per line. |
| 180 | fn status_record(raw: &str) -> String { |
| 181 | fn walk(v: &serde_json::Value, out: &mut String) { |
| 182 | match v { |
| 183 | serde_json::Value::String(s) => { |
| 184 | out.push_str(&squash(s)); |
| 185 | out.push('\n'); |
| 186 | } |
| 187 | serde_json::Value::Array(a) => a.iter().for_each(|x| walk(x, out)), |
| 188 | serde_json::Value::Object(o) => o.values().for_each(|x| walk(x, out)), |
| 189 | _ => {} |
| 190 | } |
| 191 | } |
| 192 | let mut out = String::new(); |
| 193 | walk(&serde_json::from_str(raw).expect("research status JSON"), &mut out); |
| 194 | out |
| 195 | } |
| 196 | |
| 197 | /// The strings `facts` copied from GitHub, one per line: each component's last |
| 198 | /// merged PR title, each decision record title, the receipt's commit title and |
| 199 | /// status description. Editorial fields (names, roles) are typed by hand and |
| 200 | /// stay checked. |
| 201 | fn facts_record(raw: &str) -> String { |
| 202 | let facts: crate::facts::Facts = serde_json::from_str(raw).expect("facts.json parses"); |
| 203 | let mut out = String::new(); |
| 204 | let titles = facts.components.iter().filter_map(|c| c.last_merge.as_ref()).map(|m| m.title.as_str()); |
| 205 | let titles = titles.chain(facts.decisions.iter().map(|d| d.title.as_str())); |
| 206 | for t in titles.chain([facts.receipt.commit_title.as_str(), facts.receipt.description.as_str()]) { |
| 207 | out.push_str(&squash(t)); |
| 208 | out.push('\n'); |
| 209 | } |
| 210 | out |
| 211 | } |
| 212 | |
| 213 | /// The strings the progress collector copied from Radicle and GitHub, one per line: the |
| 214 | /// title of every activity row (a patch or pull request title) and of every event. Nothing |
| 215 | /// else in the dataset is a record. |
| 216 | fn progress_record(raw: &str) -> String { |
| 217 | let data: serde_json::Value = serde_json::from_str(raw).expect("project-progress.json parses"); |
| 218 | let mut out = String::new(); |
| 219 | for list in ["activity", "events"] { |
| 220 | for item in data.get(list).and_then(serde_json::Value::as_array).into_iter().flatten() { |
| 221 | if let Some(title) = item.get("title").and_then(serde_json::Value::as_str) { |
| 222 | out.push_str(&squash(title)); |
| 223 | out.push('\n'); |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | out |
| 228 | } |
| 229 | |
| 230 | fn walk(dir: &Path, root: &Path, record: &str, out: &mut Vec<String>) { |
| 231 | for entry in fs::read_dir(dir).expect("read dist dir") { |
| 232 | let path = entry.expect("dist entry").path(); |
| 233 | if path.is_dir() { |
| 234 | walk(&path, root, record, out); |
| 235 | continue; |
| 236 | } |
| 237 | let rel = path.strip_prefix(root).unwrap().to_string_lossy().replace('\\', "/"); |
| 238 | if !rel.ends_with(".html") { |
| 239 | continue; |
| 240 | } |
| 241 | let raw = fs::read_to_string(&path).unwrap_or_else(|_| panic!("read {rel}")); |
| 242 | for v in violations(©_text(&raw), record) { |
| 243 | out.push(format!("{rel}: {v}")); |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | /// Every rendered page spells project, product and vendor names canonically. |
| 249 | pub fn verify_canonical_names(dist: &Path) { |
| 250 | // Records quoted on the pages: the work ledger (/now/), the research status |
| 251 | // table, the GitHub titles in facts.json and the patch and PR titles in the |
| 252 | // progress dataset. |
| 253 | let mut record = squash(&fs::read_to_string(dist.join("data/now.tsv")).unwrap_or_default().replace('\t', " ")); |
| 254 | record.push('\n'); |
| 255 | record.push_str(&status_record(super::research_status::RAW)); |
| 256 | record.push_str(&facts_record(&fs::read_to_string(dist.join("facts.json")).expect("read dist/facts.json"))); |
| 257 | record.push_str(&progress_record( |
| 258 | &fs::read_to_string(dist.join("data/project-progress.json")).expect("read dist/data/project-progress.json"), |
| 259 | )); |
| 260 | let mut out = Vec::new(); |
| 261 | walk(dist, dist, &record, &mut out); |
| 262 | assert!( |
| 263 | out.is_empty(), |
| 264 | "Non-canonical names in site copy (see the naming table in AGENTS.md):\n{}", |
| 265 | out.join("\n") |
| 266 | ); |
| 267 | } |
| 268 | |
| 269 | #[cfg(test)] |
| 270 | mod tests { |
| 271 | use super::*; |
| 272 | |
| 273 | fn check(html: &str) -> Vec<String> { |
| 274 | violations(©_text(html), "") |
| 275 | } |
| 276 | |
| 277 | #[test] |
| 278 | fn visible_wrong_spelling_fails() { |
| 279 | assert_eq!(check("<p>Welcome to Aienos.</p>").len(), 1); |
| 280 | assert_eq!(check("<p>AIEN proposes structure.</p>").len(), 1); |
| 281 | assert_eq!(check("<h2>Say hello to Allen?</h2>").len(), 1); |
| 282 | assert_eq!(check("<p>Read it on Github</p>").len(), 1); |
| 283 | assert_eq!(check("<p>The Aienux kernel</p>").len(), 1); |
| 284 | } |
| 285 | |
| 286 | #[test] |
| 287 | fn urls_attributes_and_code_pass() { |
| 288 | assert!(check(r#"the repository (<code>Aienos</code>)"#).is_empty()); |
| 289 | assert!(check("<p>Run <code>Aienos --help</code> first.</p>").is_empty()); |
| 290 | assert!(check("<p>See https://example.org/Aienos today.</p>").is_empty()); |
| 291 | assert!(check(r#"<p data-speaker="allen" id="allen-intro">Hello, I am Aien.</p>"#).is_empty()); |
| 292 | assert!(check("<p>Visit aienos.com or aien-dev on GitHub; nvidia.ko stays.</p>").is_empty()); |
| 293 | } |
| 294 | |
| 295 | #[test] |
| 296 | fn verbatim_elements_titles_and_labels_pass() { |
| 297 | assert!(check(r#"<p class="desc" data-verbatim>Aienux, the AienOS kernel</p>"#).is_empty()); |
| 298 | assert!(check("<cite>The AIEN Papers: The Complete Collection</cite>").is_empty()); |
| 299 | assert!(check("<h3>AIEN VERIFICATION</h3>").is_empty()); |
| 300 | // A lone capitalised word is not a label. |
| 301 | assert_eq!(check("<strong>AIEN</strong> is a machine").len(), 1); |
| 302 | // The verbatim element ends at its own close tag. |
| 303 | assert_eq!(check("<p data-verbatim><p>x</p></p><p>Aienos</p>").len(), 1); |
| 304 | } |
| 305 | |
| 306 | #[test] |
| 307 | fn sentence_end_is_not_an_identifier_join() { |
| 308 | assert_eq!(check("<p>It runs on Aienos.</p>").len(), 1); |
| 309 | assert!(check("<p>It runs on aienos.com.</p>").is_empty()); |
| 310 | } |
| 311 | |
| 312 | #[test] |
| 313 | fn ledger_records_pass_only_with_the_record() { |
| 314 | let rec = "L1 2026-10-26 Drake: boot the Imac"; |
| 315 | assert!(violations("Drake: boot the Imac", rec).is_empty()); |
| 316 | assert_eq!(violations("Drake: boot the Imac", "").len(), 1); |
| 317 | // Too little shared context: one word on its own proves nothing. |
| 318 | assert_eq!(violations("Imac", rec).len(), 1); |
| 319 | assert_eq!(violations("Boot your Imac now", rec).len(), 1); |
| 320 | } |
| 321 | |
| 322 | #[test] |
| 323 | fn github_titles_in_facts_are_a_record_but_roles_are_not() { |
| 324 | // aien-protocols #60, merged 2026-10-28: the last merged change of a component. |
| 325 | let facts = r#"{"generated_at":"2026-10-29T00:00:00Z", |
| 326 | "components":[{"key":"protocols","name":"Protocols","repo":"aien-dev/aien-protocols", |
| 327 | "role":"Allen speaks the protocols.","url":"","pushed_at":"","open_prs":0, |
| 328 | "last_merge":{"number":60,"title":"rename: Allen -> Aien (pi-spark-task spec)","merged_at":"","url":""}}], |
| 329 | "decisions":[],"receipt":{"repo":"","sha":"","commit_title":"","committed_at":"","state":"none","description":"","target_url":"","updated_at":""}}"#; |
| 330 | let rec = facts_record(facts); |
| 331 | let page = |rec: &str, body: &str| violations(©_text(body), rec); |
| 332 | let merge = r#"<td>rename: Allen -> Aien (pi-spark-task spec) (<code>aien-protocols PR #60</code>)</td>"#; |
| 333 | assert!(page(&rec, merge).is_empty()); |
| 334 | assert_eq!(page("", merge).len(), 1); |
| 335 | // The hand-written role is in facts.json but not a record. |
| 336 | assert_eq!(page(&rec, "<td>Allen speaks the protocols.</td>").len(), 1); |
| 337 | // New prose that only shares the bare name is still caught. |
| 338 | assert_eq!(page(&rec, "<p>Say hello to Allen today.</p>").len(), 1); |
| 339 | } |
| 340 | |
| 341 | #[test] |
| 342 | fn patch_titles_in_the_progress_dataset_are_a_record_but_page_copy_is_not() { |
| 343 | // aien-train patch 151366a, merged 2026-11-09: a Radicle patch title quoted as written. |
| 344 | let data = r#"{"activity":[{"repo":"aien-train","title":"ollm: kvdec decode reuse and gb10 decode forward","number":"151366a", |
| 345 | "url":"","state":"Merged","date":"2026-11-09","timestamp":"2026-11-09T20:00:00.000Z"}], |
| 346 | "events":[{"id":"x","title":"Earliest retained site history","detail":"The gb10 board arrived.","repo":"","date":"2026-08-13"}], |
| 347 | "sourcePolicy":"Measured on the gb10 host."}"#; |
| 348 | let rec = progress_record(data); |
| 349 | let page = |rec: &str, body: &str| violations(©_text(body), rec); |
| 350 | let row = "<dd>ollm: kvdec decode reuse and gb10 decode forward</dd>"; |
| 351 | assert!(page(&rec, row).is_empty()); |
| 352 | assert_eq!(page("", row).len(), 1); |
| 353 | // Only titles are records: an event's detail and the policy text stay checked. |
| 354 | assert_eq!(page(&rec, "<dd>The gb10 board arrived.</dd>").len(), 1); |
| 355 | assert_eq!(page(&rec, "<p>Measured on the gb10 host.</p>").len(), 1); |
| 356 | // Page copy that only shares the bare name is still caught. |
| 357 | assert_eq!(page(&rec, "<p>Our gb10 runs the decode forward pass.</p>").len(), 1); |
| 358 | } |
| 359 | } |