aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / crates / site-builder / src / components / hive.rs
| 1 | //! Public live observations, deliberately separate from verified project receipts. |
| 2 | //! |
| 3 | //! Nothing structural is written here. The whole page skeleton is generated by |
| 4 | //! `om/hive-page/hive.om`, a seeded Omega program in program mode that writes the |
| 5 | //! markup to stdout; `sh om/hive-page/check.sh` compiles it with the pinned |
| 6 | //! compiler and keeps the bytes in `om/hive-page/main.html`. This module embeds |
| 7 | //! those bytes unchanged. The Omega edge renderer supplies the board HTML; |
| 8 | //! the Omega-generated browser client preserves interactive state while morphing it. |
| 9 | use maud::{html, Markup, PreEscaped}; |
| 10 | |
| 11 | pub const TITLE: &str = "The Hive | AienOS"; |
| 12 | pub const DESCRIPTION: &str = "Watch the Aien coding agents work in public: real missions, nested agents, exact models and what the agents are saying, live. Learn how to build with AI."; |
| 13 | pub const URL: &str = "https://www.aienos.com/hive/"; |
| 14 | pub const SOURCE: &str = "https://interplane.io/drakestapleton/aienos.com/blob/main/crates/site-builder/src/components/hive.rs"; |
| 15 | |
| 16 | /// The generated skeleton, byte for byte as `check.sh` wrote it. |
| 17 | pub const SKELETON: &str = include_str!("../../../../om/hive-page/main.html"); |
| 18 | |
| 19 | /// The page stylesheet, byte for byte as the build copies it. |
| 20 | #[cfg(test)] |
| 21 | const HIVE_CSS: &str = include_str!("../../../../public/assets/hive.css"); |
| 22 | |
| 23 | pub fn render_hive_page() -> Markup { |
| 24 | debug_assert!( |
| 25 | SOURCE.starts_with(crate::forge::FORGE) || crate::forge::valid_repo_link(SOURCE), |
| 26 | "the published source pointer must point at the forge or Radicle: {SOURCE}" |
| 27 | ); |
| 28 | html! { (PreEscaped(SKELETON)) } |
| 29 | } |
| 30 | |
| 31 | #[cfg(test)] |
| 32 | mod tests { |
| 33 | use super::*; |
| 34 | use sha2::{Digest, Sha256}; |
| 35 | |
| 36 | fn hex_colour(css: &str) -> Option<String> { |
| 37 | let bytes = css.as_bytes(); |
| 38 | let mut i = 0; |
| 39 | while i < bytes.len() { |
| 40 | if bytes[i] == b'#' { |
| 41 | let run = bytes[i + 1..].iter().take_while(|b| b.is_ascii_hexdigit()).count(); |
| 42 | if run == 3 || run == 6 || run == 8 { |
| 43 | return Some(css[i..i + 1 + run].to_string()); |
| 44 | } |
| 45 | } |
| 46 | i += 1; |
| 47 | } |
| 48 | None |
| 49 | } |
| 50 | |
| 51 | #[test] |
| 52 | fn the_embedded_skeleton_matches_its_recorded_sha256() { |
| 53 | let recorded = include_str!("../../../../om/hive-page/main.html.sha256"); |
| 54 | let want = recorded |
| 55 | .split_whitespace() |
| 56 | .next() |
| 57 | .expect("om/hive-page/main.html.sha256 holds a digest"); |
| 58 | assert_eq!(want.len(), 64, "main.html.sha256 must hold one sha256 digest"); |
| 59 | let got = Sha256::digest(SKELETON.as_bytes()) |
| 60 | .iter() |
| 61 | .fold(String::new(), |mut acc, byte| { |
| 62 | acc.push_str(&format!("{byte:02x}")); |
| 63 | acc |
| 64 | }); |
| 65 | assert_eq!( |
| 66 | got, want, |
| 67 | "the committed skeleton and its digest disagree; run: sh om/hive-page/check.sh" |
| 68 | ); |
| 69 | } |
| 70 | |
| 71 | #[test] |
| 72 | fn served_scripts_match_their_omega_generated_sha256() { |
| 73 | for (name, script, recorded) in [ |
| 74 | ( |
| 75 | "hive.js", |
| 76 | include_bytes!("../../../../public/js/hive.js").as_slice(), |
| 77 | include_str!("../../../../om/hive-page/hive.js.sha256"), |
| 78 | ), |
| 79 | ( |
| 80 | "turing-look.js", |
| 81 | include_bytes!("../../../../public/js/turing-look.js").as_slice(), |
| 82 | include_str!("../../../../om/hive-page/turing-look.js.sha256"), |
| 83 | ), |
| 84 | ( |
| 85 | "hive-fresh.wasm", |
| 86 | include_bytes!("../../../../public/wasm/hive-fresh.wasm").as_slice(), |
| 87 | include_str!("../../../../public/wasm/hive-fresh.wasm.sha256"), |
| 88 | ), |
| 89 | ] { |
| 90 | let want = recorded.split_whitespace().next().expect("script digest"); |
| 91 | assert_eq!(want.len(), 64, "{name} must have a sha256 digest"); |
| 92 | let got = format!("{:x}", Sha256::digest(script)); |
| 93 | assert_eq!( |
| 94 | got, want, |
| 95 | "{name} is generated, never hand-edited; run: sh om/hive-page/check.sh" |
| 96 | ); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | #[test] |
| 101 | fn the_skeleton_accepts_edge_rendered_native_branches() { |
| 102 | assert!(!SKELETON.contains("<template"), "obsolete browser row templates must not return"); |
| 103 | let renderer = include_str!("../../../../om/hive-render/render.om"); |
| 104 | assert!(renderer.contains(r#"<details id=\"branch-"#)); |
| 105 | assert!(renderer.contains(r#"<summary class=\"hive-record"#)); |
| 106 | assert!(SKELETON.contains(r#"<div id="hive-manifest-cards" hidden>"#)); |
| 107 | assert!(SKELETON.contains(r#"href="/hive/board/""#)); |
| 108 | assert!(SKELETON.contains(r#"id="hive-motion" type="checkbox""#)); |
| 109 | // Bounded panels: the head stays and only the body scrolls, so the |
| 110 | // fleet cannot become a document thousands of pixels tall again. |
| 111 | assert_eq!( |
| 112 | SKELETON.matches(r#"<div class="hive-panel-head">"#).count(), |
| 113 | 2, |
| 114 | "the missions panel and the selected mission panel are the two bounded panels" |
| 115 | ); |
| 116 | assert_eq!( |
| 117 | SKELETON.matches(r#"<div class="hive-panel-body">"#).count(), |
| 118 | 2, |
| 119 | "each bounded panel needs its scroll body" |
| 120 | ); |
| 121 | assert!( |
| 122 | SKELETON.contains(r#"<div class="hive-tools">"#), |
| 123 | "the missions tools ride at the top of the scroll body" |
| 124 | ); |
| 125 | } |
| 126 | |
| 127 | fn strip_comments(css: &str) -> String { |
| 128 | let mut out = String::with_capacity(css.len()); |
| 129 | let mut rest = css; |
| 130 | while let Some(start) = rest.find("/*") { |
| 131 | out.push_str(&rest[..start]); |
| 132 | match rest[start..].find("*/") { |
| 133 | Some(end) => rest = &rest[start + end + 2..], |
| 134 | None => return out, |
| 135 | } |
| 136 | } |
| 137 | out.push_str(rest); |
| 138 | out |
| 139 | } |
| 140 | |
| 141 | #[test] |
| 142 | fn the_stylesheet_stays_on_the_shared_palette_and_compositor_motion() { |
| 143 | assert!( |
| 144 | hex_colour(HIVE_CSS).is_none(), |
| 145 | "hive.css must use the palette tokens, never a local hex colour: {:?}", |
| 146 | hex_colour(HIVE_CSS) |
| 147 | ); |
| 148 | for (name, text) in [("main.html", SKELETON), ("hive.css", HIVE_CSS)] { |
| 149 | assert!(!text.contains('\u{2014}'), "{name} carries an em dash"); |
| 150 | assert!(!text.contains('\u{2013}'), "{name} carries an en dash"); |
| 151 | } |
| 152 | // Motion is compositor only: transform or opacity, and never a filter, |
| 153 | // a box shadow or the all shorthand that would animate both. Comments |
| 154 | // are prose, and prose may name a word this scan looks for. |
| 155 | for rule in strip_comments(HIVE_CSS).split('}') { |
| 156 | let rule = rule.to_ascii_lowercase(); |
| 157 | if let Some(at) = rule.find("transition") { |
| 158 | let decl = &rule[at..]; |
| 159 | let decl = &decl[..decl.find(';').unwrap_or(decl.len())]; |
| 160 | assert!(!decl.contains("all"), "a transition must name transform or opacity: {decl}"); |
| 161 | assert!(!decl.contains("filter"), "a transition must not animate filter: {decl}"); |
| 162 | assert!(!decl.contains("box-shadow"), "a transition must not animate box-shadow: {decl}"); |
| 163 | } |
| 164 | assert!(!rule.contains("animation-name"), "hive.css must not name an animation: {rule}"); |
| 165 | for (at, _) in rule.match_indices("animation") { |
| 166 | let rest = rule[at + "animation".len()..].trim_start(); |
| 167 | if !rest.starts_with(':') { |
| 168 | continue; |
| 169 | } |
| 170 | let value = rest[1..].split(';').next().unwrap_or("").trim(); |
| 171 | assert!(value.starts_with("none"), "hive.css must not animate: {value}"); |
| 172 | } |
| 173 | } |
| 174 | assert!( |
| 175 | HIVE_CSS.contains("prefers-reduced-motion"), |
| 176 | "the single transform transition must be removed under prefers-reduced-motion" |
| 177 | ); |
| 178 | assert!( |
| 179 | HIVE_CSS.contains(".hive:not(:has(#hive-motion:checked))"), |
| 180 | "the page's own motion control must also disable the transition" |
| 181 | ); |
| 182 | } |
| 183 | |
| 184 | #[test] |
| 185 | fn the_scene_is_emitted_by_the_omega_program() { |
| 186 | // Allen's two black holes are computed by om/hive-page/hive.om, so the |
| 187 | // markup, every keyframe and the motion gate are bytes of the skeleton, |
| 188 | // and the stylesheet only places them. |
| 189 | for part in [ |
| 190 | r#"<div class="hive-scene" aria-hidden="true" data-scene="allen""#, |
| 191 | "data-appear=\"2600\"", |
| 192 | "data-spiral=\"6000\"", |
| 193 | "data-merge=\"12000\"", |
| 194 | "data-gone=\"15200\"", |
| 195 | "--hive-cycle:19000ms", |
| 196 | "@keyframes hive-posa", |
| 197 | "@keyframes hive-msiz", |
| 198 | "@media (prefers-reduced-motion:no-preference)", |
| 199 | ".hive:has(#hive-motion:checked) .hive-hole-a{animation:hive-posa var(--hive-cycle) linear infinite}", |
| 200 | ] { |
| 201 | assert!(SKELETON.contains(part), "the emitted scene lost {part:?}"); |
| 202 | } |
| 203 | // Every keyframe stop animates transform or opacity and nothing else, so |
| 204 | // the whole sequence runs on the compositor and cannot cause layout. |
| 205 | let stops = SKELETON.matches("%{").count(); |
| 206 | let animated = SKELETON.matches("{transform:").count() + SKELETON.matches("{opacity:").count(); |
| 207 | assert!(stops > 400, "the scene lost its samples: {stops} stops"); |
| 208 | assert_eq!(animated, stops, "a keyframe stop animates something other than transform or opacity"); |
| 209 | for forbidden in ["filter:", "box-shadow:", "background-position:", "background-size:"] { |
| 210 | assert!(!SKELETON.contains(forbidden), "the scene animates or paints {forbidden}"); |
| 211 | } |
| 212 | // One motion gate holds every animation, so reduced motion has one place to gate. |
| 213 | assert_eq!( |
| 214 | SKELETON.matches("animation:").count(), |
| 215 | SKELETON.matches(":has(#hive-motion:checked) .hive-").count(), |
| 216 | "an animation escaped the prefers-reduced-motion gate" |
| 217 | ); |
| 218 | // The scene is a layer at 0 in the masthead, never a negative z-index. |
| 219 | assert!( |
| 220 | HIVE_CSS.contains(".hive-masthead > .hive-scene") && HIVE_CSS.contains("z-index:0"), |
| 221 | "the scene layer must be placed in the masthead at z-index 0" |
| 222 | ); |
| 223 | assert!(!HIVE_CSS.contains("z-index:-"), "never a negative z-index for the scene"); |
| 224 | assert!( |
| 225 | !HIVE_CSS.contains("@keyframes") && !HIVE_CSS.contains("animation:hive-"), |
| 226 | "the sequence belongs to the .om, not to the stylesheet" |
| 227 | ); |
| 228 | } |
| 229 | } |