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/aienos.com/blob/main/crates/site-builder/src/components/omega_reference.rs # aienos.com Source of www.aienos.com, served from my own hardware 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 `aienos.com / crates / site-builder / src / components / omega_reference.rs` 144 lines ยท 7272 bytes Raw Blame History 1 //! /omega/reference/: the agent-facing Omega language reference. Seeded 2 //! Omega writes it: om/omega-reference/page.om renders the vendored 3 //! omega-harness guide and every gated worked example (om/omega-reference/ 4 //! check.sh), and this module only places the generated HTML in the layout. 5 use maud::{html, Markup, PreEscaped}; 6 7 pub const TITLE: &str = "Omega language reference | AienOS"; 8 pub const DESCRIPTION: &str = "The Omega language for agents: program shape, types, declarations, statements, words, OM-2, host words, every compiler error and trap exit code, common mistakes and every gated worked example with its expected output."; 9 pub const URL: &str = "https://www.aienos.com/omega/reference/"; 10 pub const PAGE: &str = include_str!("../../../../om/omega-reference/main.html"); 11 pub fn render_omega_reference_page() -> Markup { html! { (PreEscaped(PAGE)) } } 12 13 /// Vendored files (path relative to om/omega-reference/vendor) with their 14 /// recorded sha256, in manifest order. 15 pub fn manifest() -> Vec<(&'static str, &'static str)> { 16 include_str!("../../../../om/omega-reference/vendor.sha256") 17 .lines() 18 .map(|l| { 19 let (hash, path) = l.split_once(" ").expect("sha256sum line"); 20 (path, hash) 21 }) 22 .collect() 23 } 24 25 /// Every vendored file must appear in llms-full.txt byte for byte as its 26 /// `File: PATH` label and fenced block, the form html_to_text gives the page. 27 pub fn verify_llms_full(dist: &std::path::Path) { 28 let full = std::fs::read_to_string(dist.join("llms-full.txt")).expect("read llms-full.txt"); 29 let files = extract(&full); 30 let vendor = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../om/omega-reference/vendor"); 31 let mut programs = 0; 32 for (path, _) in manifest() { 33 if path == "skills/writing-omega/SKILL.md" { 34 continue; 35 } 36 let want = std::fs::read(vendor.join(path)).unwrap_or_else(|_| panic!("read vendored {path}")); 37 let got = files.iter().find(|(p, _)| p == path).unwrap_or_else(|| panic!("llms-full.txt lacks File: {path}")); 38 assert!(got.1 == want, "llms-full.txt changes the bytes of {path}"); 39 programs += usize::from(path.ends_with(".om")); 40 } 41 assert!(programs >= 30, "/omega/reference/ must carry at least 30 worked examples, found {programs}"); 42 println!(" [LLMS] llms-full.txt carries {} reference files byte for byte ({programs} programs)", files.len()); 43 } 44 45 /// Files in llms-full.txt: each `File: PATH` line, with an optional 46 /// `(empty file)`, `(no final newline)` or `(hex bytes)` mark, and the 47 /// fenced block after it. A `File:` line in other copy, without a mark or 48 /// fence of this form, is not a file and is passed over. 49 pub fn extract(full: &str) -> Vec<(String, Vec)> { 50 let lines: Vec<&str> = full.split('\n').collect(); 51 let mut out = Vec::new(); 52 let mut i = 0; 53 while i < lines.len() { 54 let Some(label) = lines[i].strip_prefix("File: ") else { i += 1; continue }; 55 let (path, mark) = match label.split_once(' ') { 56 Some((p, m)) => (p, m), 57 None => (label, ""), 58 }; 59 i += 1; 60 if !matches!(mark, "" | "(empty file)" | "(no final newline)" | "(hex bytes)") { 61 continue; 62 } 63 if mark == "(empty file)" { 64 out.push((path.to_string(), Vec::new())); 65 continue; 66 } 67 let mut f = i; 68 while f < lines.len() && lines[f].is_empty() { 69 f += 1; 70 } 71 if f >= lines.len() || lines[f] != "```" { 72 continue; 73 } 74 let start = f + 1; 75 let Some(len) = lines[start..].iter().position(|l| *l == "```") else { continue }; 76 let end = start + len; 77 let mut body = String::new(); 78 for l in &lines[start..end] { 79 body.push_str(l); 80 body.push('\n'); 81 } 82 let bytes = match mark { 83 "(no final newline)" => body[..body.len() - 1].as_bytes().to_vec(), 84 "(hex bytes)" => body.split_whitespace().map(|h| u8::from_str_radix(h, 16).expect("hex byte")).collect(), 85 _ => body.into_bytes(), 86 }; 87 out.push((path.to_string(), bytes)); 88 i = end + 1; 89 } 90 out 91 } 92 93 #[cfg(test)] 94 mod tests { 95 use super::*; 96 use sha2::{Digest, Sha256}; 97 98 #[test] 99 fn reference_generated_artifacts_match_hashes() { 100 let receipt = include_str!("../../../../om/omega-reference/main.html.sha256"); 101 assert_eq!(format!("{:x}", Sha256::digest(PAGE.as_bytes())), receipt.split_whitespace().next().expect("digest")); 102 let vendor = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../om/omega-reference/vendor"); 103 let listed = manifest(); 104 for (path, hash) in &listed { 105 let bytes = std::fs::read(vendor.join(path)).unwrap_or_else(|_| panic!("read {path}")); 106 assert_eq!(&format!("{:x}", Sha256::digest(&bytes)), hash, "{path} differs from vendor.sha256"); 107 } 108 fn count(dir: &std::path::Path) -> usize { 109 std::fs::read_dir(dir).expect("read vendor dir").map(|e| { 110 let p = e.expect("entry").path(); 111 if p.is_dir() { count(&p) } else { 1 } 112 }).sum() 113 } 114 assert_eq!(count(&vendor), listed.len(), "vendor/ holds a file that vendor.sha256 does not list"); 115 } 116 117 #[test] 118 fn reference_page_covers_every_program_and_the_error_table() { 119 let programs: Vec<_> = manifest().into_iter().filter(|(p, _)| p.ends_with(".om")).collect(); 120 assert!(programs.len() >= 30, "at least 30 worked examples, found {}", programs.len()); 121 for (path, _) in &programs { 122 assert!(PAGE.contains(&format!("File: {path}")), "main.html lacks {path}"); 123 } 124 for needle in ["id=\"s11\"", "id=\"s5\"", "id=\"s12\"", "id=\"examples\"", "id=\"gate\"", "File: examples/gate.sh", "never emitted at the pin", "24", "`e5b32567a7aff3ce594e3254a622a846a6cd190b`", "`2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`"] { 125 assert!(PAGE.contains(needle), "main.html lacks {needle}"); 126 } 127 assert!(!PAGE.contains('\u{2014}') && !PAGE.contains('\u{2013}'), "no em or en dash"); 128 let info = crate::seo::PAGES.iter().find(|p| p.path == "/omega/reference/").expect("/omega/reference/ in seo::PAGES"); 129 let count = format!(" {} worked examples", programs.len()); 130 assert!(info.what.contains(&count), "seo::PAGES must give the example count{count}"); 131 assert!(PAGE.contains(&count), "main.html must give the example count{count}"); 132 } 133 134 #[test] 135 fn extract_reads_marks_and_fences() { 136 let full = "File: notes on this, not a file\nFile: a.om\n\n```\nnote a\n\n x\n```\nFile: b.stdin (no final newline)\n```\nab\n```\nFile: c.out (hex bytes)\n```\n00 ff 0a\n```\nFile: d.stdout (empty file)\n"; 137 let got = extract(full); 138 assert_eq!(got[0], ("a.om".to_string(), b"note a\n\n x\n".to_vec())); 139 assert_eq!(got[1], ("b.stdin".to_string(), b"ab".to_vec())); 140 assert_eq!(got[2], ("c.out".to_string(), vec![0, 255, 10])); 141 assert_eq!(got[3], ("d.stdout".to_string(), Vec::new())); 142 assert_eq!(got.len(), 4); 143 } 144 }