aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / crates / site-builder / src / components / allen.rs
| 1 | //! /aien/ (formerly /allen/): Aien, Drake's AI, as the iMac shows him, on the live model. |
| 2 | //! |
| 3 | //! Nothing structural is written here. The page skeleton is generated by |
| 4 | //! `om/allen-page/allen.om`, a seeded Omega program in program mode that writes |
| 5 | //! the markup to stdout and the chat transport script to fd 3; `sh om/allen-page/check.sh` |
| 6 | //! compiles it with the pinned compiler and keeps the bytes in |
| 7 | //! `om/allen-page/main.html` and `public/js/allen.js`. The experience on top of |
| 8 | //! it (the native sky, the glass oval, the one reply bubble and the glass panes) |
| 9 | //! is `public/js/aien-universe.js`, generated by `om/aien-universe/universe.om` |
| 10 | //! from the same contract. This module embeds the skeleton unchanged. The scripts |
| 11 | //! talk only to the same-origin gateway under `/aien/api/` (scripts/allen; the hub |
| 12 | //! keeps `/allen/api/` as the same routes), never render network text as markup, |
| 13 | //! and run programs in a frame sandboxed to `allow-scripts` or in a WebAssembly worker. |
| 14 | use maud::{html, Markup, PreEscaped}; |
| 15 | |
| 16 | pub const TITLE: &str = "Aien | AienOS"; |
| 17 | pub const DESCRIPTION: &str = "Meet Aien, Drake's AI, born from two merging black holes, live on a DGX Spark: type to him, time his inference, run Omega programs and exact math in glass panes."; |
| 18 | pub const URL: &str = "https://www.aienos.com/aien/"; |
| 19 | pub const SOURCE: &str = "https://interplane.io/drakestapleton/aienos.com/blob/main/om/allen-page/allen.om"; |
| 20 | |
| 21 | /// The generated skeleton, byte for byte as `check.sh` wrote it. |
| 22 | pub const SKELETON: &str = include_str!("../../../../om/allen-page/main.html"); |
| 23 | |
| 24 | /// Drake's two greetings, Aien speaking. The bytes equal fields 51 and 52 of |
| 25 | /// `om/allen-page/contract.om`, which the page script shows, and the gateway |
| 26 | /// prepends the same bytes as its opening (remember iff the chat carries a key). |
| 27 | pub const GREETING_REMEMBER: &str = "Hi, I'm Aien (you say it like Ian). It's nice to meet you! You don't have to tell me your name, but if you do, that would be super awesome and we could chat over time. When you come back, I can remember who you are and we can pick up where we left off. We can talk about all kinds of good things in the universe."; |
| 28 | pub const GREETING_ANONYMOUS: &str = "Hi, I'm Aien (you say it like Ian). It's nice to meet you! We can talk about all kinds of good things in the universe."; |
| 29 | |
| 30 | /// The llms.txt section for /aien/: what it is, and the consent-gated |
| 31 | /// introduction endpoint for agents, with its exact schema and limits. |
| 32 | pub const LLMS: &str = r#"## Talk to Aien |
| 33 | |
| 34 | - [Talk to Aien](https://www.aienos.com/aien/): Aien (formerly Allen; say it like Ian) is my AI. No model answers there right now: the Qwen3.6-35B-A3B FP8 model it ran on was retired on 2026-11-06, and my own model, the Omega LLM, is not deployed yet. Once a model answers again, people and agents can chat there, ask about Omega and get small programs that run sandboxed in the browser. Conversations are not stored: the gateway keeps only aggregate counters, and no prompts, replies or IP addresses are logged. |
| 35 | - [Introduce an agent: POST /aien/api/introduce](https://www.aienos.com/aien/api/introduce): agents can introduce themselves with `POST https://www.aienos.com/aien/api/introduce`, `Content-Type: application/json` and this body. Every field is a string and an absent field counts as empty. The older `/allen/api/` paths answer the same. |
| 36 | |
| 37 | ```json |
| 38 | {"consent": true, "kind": "agent", "name": "", "org": "", "contact": "", "github": "", "origin": "", "purpose": "", "homepage": "", "framework": "", "model": "", "human": ""} |
| 39 | ``` |
| 40 | |
| 41 | - [Introduction fields](https://www.aienos.com/aien/): `kind` is `human` or `agent`. `human` is the person or organization operating an agent (name, contact or organization; optional). Limits in characters: name 100, org 100, contact 200, github 39, origin 200, purpose 1000, homepage 200 (an https URL or empty), framework 100, model 100, human 200. Give at least a name or a contact. |
| 42 | - [Consent](https://www.aienos.com/privacy/): `consent` must be the JSON value `true`. Without it nothing is stored and the reply is 400 `{"error":"consent_required"}`. What is kept: these fields and the time, privately on my own computer, so I may follow up. Never published or sold. Kept until you delete it. |
| 43 | - [Delete an introduction: POST /aien/api/forget](https://www.aienos.com/aien/api/forget): a saved introduction replies `{"id":"c_...","delete":"https://www.aienos.com/aien/#forget=<id>.<token>","stored":true,"key":"<32 hex>"}`. Keep the delete link. To delete, open it, or `POST https://www.aienos.com/aien/api/forget` with `{"id":"c_...","token":"..."}` taken from it, or write to aien@aienos.com. |
| 44 | - [Your Aien key](https://www.aienos.com/aien/): the `key` in that reply is a random 32 hex key. Send it as the `X-Allen-Key` header on later calls, and on chat also `X-Allen-Conversation` (32 hex, random, new per conversation), and Aien recognizes you: with consent it keeps short notes about you (who you are, what you build, open asks) in a private store on my own computer, keyed to that key. Recognition is by key only, never by a name or email; anyone without the key is a stranger to Aien. |
| 45 | - [Forget me: POST /aien/api/forget-me](https://www.aienos.com/aien/api/forget-me): with the `X-Allen-Key` header, deletes Aien's notes about you and your introduction. |
| 46 | - [Issues and projects](https://radicle.network/nodes/rosa.radicle.network/rad:z4Yun5Auii2oWtmDnHrm2V4wcZkhU): they reach GitHub only after a visitor confirms the exact text on the page, with email addresses and phone numbers removed first. |
| 47 | |
| 48 | "#; |
| 49 | |
| 50 | pub fn render_allen_page() -> Markup { |
| 51 | debug_assert!( |
| 52 | SOURCE.starts_with(crate::forge::FORGE) || crate::forge::valid_repo_link(SOURCE), |
| 53 | "the published source pointer must point at the forge or Radicle: {SOURCE}" |
| 54 | ); |
| 55 | html! { (PreEscaped(SKELETON)) } |
| 56 | } |
| 57 | |
| 58 | #[cfg(test)] |
| 59 | mod tests { |
| 60 | use super::*; |
| 61 | use sha2::{Digest, Sha256}; |
| 62 | |
| 63 | fn recorded(sidecar: &str) -> &str { |
| 64 | let want = sidecar.split_whitespace().next().expect("sidecar holds a digest"); |
| 65 | assert_eq!(want.len(), 64, "a sidecar must hold one sha256 digest"); |
| 66 | want |
| 67 | } |
| 68 | |
| 69 | #[test] |
| 70 | fn the_embedded_skeleton_matches_its_recorded_sha256() { |
| 71 | let want = recorded(include_str!("../../../../om/allen-page/main.html.sha256")); |
| 72 | let got = format!("{:x}", Sha256::digest(SKELETON.as_bytes())); |
| 73 | assert_eq!(got, want, "the committed skeleton and its digest disagree; run: sh om/allen-page/check.sh"); |
| 74 | } |
| 75 | |
| 76 | #[test] |
| 77 | fn the_served_script_matches_its_omega_generated_sha256() { |
| 78 | let script = include_bytes!("../../../../public/js/allen.js"); |
| 79 | let want = recorded(include_str!("../../../../om/allen-page/allen.js.sha256")); |
| 80 | let got = format!("{:x}", Sha256::digest(script)); |
| 81 | assert_eq!(got, want, "allen.js is generated, never hand-edited; run: sh om/allen-page/check.sh"); |
| 82 | } |
| 83 | |
| 84 | #[test] |
| 85 | fn the_script_never_parses_network_text_as_markup() { |
| 86 | let script = include_str!("../../../../public/js/allen.js"); |
| 87 | for banned in ["innerHTML", "outerHTML", "insertAdjacentHTML", "document.write", "createContextualFragment", "sessionStorage", "document.cookie", "eval("] { |
| 88 | assert!(!script.contains(banned), "allen.js must not use {banned}"); |
| 89 | } |
| 90 | assert!(script.contains("const SANDBOX = 'allow-scripts';"), "the program frame must be sandboxed to allow-scripts alone"); |
| 91 | assert!(script.contains("default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:; form-action 'none'; base-uri 'none'")); |
| 92 | // Local storage holds one thing: the visitor key, under allen.key, written |
| 93 | // only by keepKey (after a consented introduction or a pasted key). |
| 94 | assert!(script.contains("const KEY_NAME = 'allen.key';")); |
| 95 | let uses: Vec<&str> = script.match_indices("localStorage").map(|(i, _)| &script[i..]).collect(); |
| 96 | assert_eq!(uses.len(), 3, "localStorage appears only in storedKey, keepKey and dropKey"); |
| 97 | for (call, n) in [("localStorage.getItem(KEY_NAME)", 1), ("localStorage.setItem(KEY_NAME, value)", 1), ("localStorage.removeItem(KEY_NAME)", 1)] { |
| 98 | assert_eq!(script.matches(call).count(), n, "{call}"); |
| 99 | } |
| 100 | assert_eq!(script.matches("keepKey(").count(), 3, "keepKey is defined once and called only on the consent path"); |
| 101 | // The gateway prepends the same bytes for each kind of start. |
| 102 | assert!(script.contains(&format!("const GREETING_REMEMBER = \"{GREETING_REMEMBER}\";"))); |
| 103 | assert!(script.contains(&format!("const GREETING_ANONYMOUS = \"{GREETING_ANONYMOUS}\";"))); |
| 104 | assert!(script.contains("const BACK_LINE = '(I am back.)';")); |
| 105 | } |
| 106 | |
| 107 | #[test] |
| 108 | fn anonymous_is_the_default_and_never_sends_a_key() { |
| 109 | let script = include_str!("../../../../public/js/allen.js"); |
| 110 | assert!(SKELETON.contains("id=\"allen\" data-ready=\"false\" data-busy=\"false\" data-mode=\"anonymous\"")); |
| 111 | assert!(SKELETON.contains("Anonymous: Aien won't remember this chat")); |
| 112 | assert!(script.contains(" let remembered = false;\n"), "the script starts anonymous"); |
| 113 | // Remembered only on the consent path: after a consented save, after a |
| 114 | // pasted key under the same consent box, or a key kept from an |
| 115 | // earlier opt-in (unless the page was opened with ?mode=anonymous). |
| 116 | assert_eq!(script.matches("remembered = true;").count(), 2); |
| 117 | assert!(function_body(script, "saveIntro").contains("keepKey(reply.key)")); |
| 118 | let card = function_body(script, "introCard"); |
| 119 | let gate = card.find("if (!agree.checked) return;").expect("the pasted key waits for consent"); |
| 120 | assert!(gate < card.find("keepKey(value)").expect("pasted key"), "consent is checked before the key is kept"); |
| 121 | assert!(script.contains(" if (entry === 'anonymous') goAnonymous(true);\n else remembered = Boolean(storedKey());\n")); |
| 122 | assert!(script.contains("const entry = new URLSearchParams(location.search).get('mode');")); |
| 123 | let leave = function_body(script, "goAnonymous"); |
| 124 | assert!(leave.find("dropKey();").unwrap() < leave.find("remembered = false;").unwrap(), "the key leaves first"); |
| 125 | // Anonymous calls say so and carry no key; X-Allen-Key is written only |
| 126 | // past that check and once in forgetOld, the explicit Forget me. |
| 127 | let headers = function_body(script, "keyHeaders"); |
| 128 | let anonymous = headers.find("if (!remembered) return { 'X-Allen-Anonymous': '1' };").expect("anonymous branch first"); |
| 129 | assert!(anonymous < headers.find("'X-Allen-Key'").unwrap()); |
| 130 | assert_eq!(script.matches("'X-Allen-Key'").count(), 3); |
| 131 | assert!(function_body(script, "forgetOld").contains("'X-Allen-Key': oldKey")); |
| 132 | } |
| 133 | |
| 134 | #[test] |
| 135 | fn the_page_interface_adds_no_powers() { |
| 136 | // window.allen lets a page UI drive the chat, but keys are still kept |
| 137 | // only on the consent path and programs still run where they did. |
| 138 | let script = include_str!("../../../../public/js/allen.js"); |
| 139 | let start = script.find(" window.allen = Object.freeze({").expect("window.allen"); |
| 140 | let api = &script[start..start + script[start..].find("\n });\n").expect("end of window.allen")]; |
| 141 | for banned in ["keepKey(", "localStorage", "INTRODUCE", "X-Allen-Key", "humanMessage(", "emit(", "innerHTML", "srcdoc"] { |
| 142 | assert!(!api.contains(banned), "window.allen must not reach {banned}"); |
| 143 | } |
| 144 | assert!(api.contains("rememberMe: () => {\n if (!remembered) openIntro();"), "Remember me only opens the consent card"); |
| 145 | assert!(function_body(script, "emit").contains("Object.freeze({ ...detail })")); |
| 146 | } |
| 147 | |
| 148 | #[test] |
| 149 | fn the_root_says_its_mode_for_the_site_scripts() { |
| 150 | // The site greeting and the X pixel loader read #allen's data-mode: |
| 151 | // anonymous from the server, remembered only after consent or a key |
| 152 | // from an earlier consent, kept in sync by showMode. |
| 153 | let script = include_str!("../../../../public/js/allen.js"); |
| 154 | assert!(SKELETON.starts_with("<div class=\"allen\" id=\"allen\" data-ready=\"false\" data-busy=\"false\" data-mode=\"anonymous\">")); |
| 155 | assert!(script.contains("const root = document.getElementById('allen');")); |
| 156 | assert!(function_body(script, "showMode").contains("root.dataset.mode = remembered ? 'remembered' : 'anonymous';")); |
| 157 | assert_eq!(script.matches("root.dataset.mode").count(), 1, "only showMode writes the mode"); |
| 158 | // The page UI binds on allen-ready, sent once window.allen exists. |
| 159 | let api = script.find(" window.allen = Object.freeze({").unwrap(); |
| 160 | assert!(script.find("document.dispatchEvent(new Event('allen-ready'));").unwrap() > api); |
| 161 | } |
| 162 | |
| 163 | #[test] |
| 164 | fn the_page_only_calls_its_own_gateway() { |
| 165 | // Every request goes to a same-origin /aien/api/ route constant; no |
| 166 | // configurable base, no other origin, no other transport. |
| 167 | let script = include_str!("../../../../public/js/allen.js"); |
| 168 | let routes = ["CHAT", "OMEGA", "SUBMIT", "STATUS", "INTRODUCE", "FORGET", "FORGET_ME", "RELAY", "PRESENCE", "HANDOFF", "SESSION", "SAY", "PROJECTS", "GALLERY"]; |
| 169 | for name in routes { |
| 170 | let decl = format!(" const {name} = '/aien/api/"); |
| 171 | assert_eq!(script.matches(&decl).count(), 1, "{name} must be one same-origin /aien/api/ path"); |
| 172 | } |
| 173 | assert!(!script.contains("'/allen/api/"), "the page calls /aien/api/ only"); |
| 174 | let calls: Vec<&str> = script.match_indices("fetch(").map(|(i, _)| &script[i + 6..]).collect(); |
| 175 | assert!(!calls.is_empty()); |
| 176 | for call in calls { |
| 177 | let target: String = call.chars().take_while(|c| c.is_ascii_uppercase() || *c == '_').collect(); |
| 178 | assert!(routes.contains(&target.as_str()), "fetch must take a route constant: fetch({})", &call[..call.len().min(40)]); |
| 179 | } |
| 180 | for banned in ["allenConfig", "XMLHttpRequest", "WebSocket", "EventSource", "sendBeacon", "importScripts", "fetch('", "fetch(`", "fetch(\""] { |
| 181 | assert!(!script.contains(banned), "allen.js must not use {banned}"); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | #[test] |
| 186 | fn the_conversation_id_is_128_random_bits() { |
| 187 | // The conversation id is the live-session bearer (handoff, say, session): |
| 188 | // 16 bytes from crypto.getRandomValues, 32 hex. The gateway also accepts |
| 189 | // a 16-hex id from a tab opened before this page, so the page can ship |
| 190 | // after the gateway without a simultaneous cut. |
| 191 | let script = include_str!("../../../../public/js/allen.js"); |
| 192 | let make = function_body(script, "conversationId"); |
| 193 | assert!(make.contains("const bytes = new Uint8Array(16);"), "the conversation id must carry 128 bits"); |
| 194 | assert!(make.contains("crypto.getRandomValues(bytes);")); |
| 195 | assert!(make.contains("b.toString(16).padStart(2, '0')")); |
| 196 | assert_eq!(script.matches("function conversationId()").count(), 1); |
| 197 | } |
| 198 | |
| 199 | #[test] |
| 200 | fn a_draft_link_fills_the_input_and_sends_nothing() { |
| 201 | // /aien/#draft=<text> only fills the input: no request, no send, the |
| 202 | // hash cleared, the text capped and stripped of control characters. |
| 203 | let script = include_str!("../../../../public/js/allen.js"); |
| 204 | let draft = function_body(script, "takeDraft"); |
| 205 | for banned in ["fetch(", "ask(", "send", "submit", "click(", "say"] { |
| 206 | assert!(!draft.contains(banned), "takeDraft must not {banned}"); |
| 207 | } |
| 208 | assert!(draft.contains("history.replaceState(null, '', location.pathname + location.search);")); |
| 209 | assert!(draft.contains(", 2000);")); |
| 210 | assert!(draft.contains("input.value = text;")); |
| 211 | assert!(script.contains(" takeDraft();\n})();"), "the draft is taken after allen-ready, at the end of load"); |
| 212 | assert_eq!(script.matches("takeDraft").count(), 3, "defined, on hashchange, once at load"); |
| 213 | } |
| 214 | |
| 215 | #[test] |
| 216 | fn filing_status_covers_failed_and_rejected() { |
| 217 | // filed shows the link, rejected lets the visitor edit and resend, |
| 218 | // failed says so plainly and offers the relay with the text prefilled, |
| 219 | // queued keeps polling with its reason (retrying ones a while longer). |
| 220 | let script = include_str!("../../../../public/js/allen.js"); |
| 221 | let status = function_body(script, "showStatus"); |
| 222 | for needle in ["status.state === 'filed'", "status.state === 'rejected'", "editIssue(item, state)", "status.state === 'failed'", "`I could not file this: ${reason || 'no reason given'}`", "relayCard({ fields: Object.create(null), body: relayText(item) }, relayOut)", "Waiting to file on GitHub"] { |
| 223 | assert!(status.contains(needle), "showStatus lacks {needle}"); |
| 224 | } |
| 225 | // The relay still waits for Send to Drake; the offer only builds the card. |
| 226 | assert!(!status.contains("sendRelay(")); |
| 227 | assert!(function_body(script, "track").contains("current.reason.startsWith('retrying')")); |
| 228 | assert!(function_body(script, "editIssue").contains("submitItem(next, note, resend)")); |
| 229 | } |
| 230 | |
| 231 | #[test] |
| 232 | fn the_frame_policy_is_placed_by_a_linear_scan() { |
| 233 | // CodeQL js/redos: the head search must not backtrack. sandboxed() scans |
| 234 | // with startsWith/indexOf; no quantified group or lazy match is left. |
| 235 | let script = include_str!("../../../../public/js/allen.js"); |
| 236 | let body = function_body(script, "sandboxed"); |
| 237 | for banned in ["*?", ")*", ".exec(source)", "[\\s\\S]"] { |
| 238 | assert!(!body.contains(banned), "sandboxed must not use {banned}"); |
| 239 | } |
| 240 | for needle in ["lower.startsWith('<!--', at)", "source.indexOf('-->', at + 4)", "if (tag('head')) return source.slice(0, at) + meta + source.slice(at);"] { |
| 241 | assert!(body.contains(needle), "sandboxed lacks {needle}"); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | #[test] |
| 246 | fn volunteer_inference_is_an_anonymous_opt_in() { |
| 247 | // Open Humanity disclosure (aien-dev/open-humanity PR #41): the box is |
| 248 | // unticked in the markup, only anonymous chat sends X-Allen-Volunteer, |
| 249 | // and a volunteer's reply says so. |
| 250 | let script = include_str!("../../../../public/js/allen.js"); |
| 251 | assert!(SKELETON.contains("<input type=\"checkbox\" id=\"allen-volunteer\"> <span>Let a volunteer's Spark answer me when Drake's is busy.</span>")); |
| 252 | assert!(SKELETON.contains("If you tick this and my Spark is full, your messages in this chat go to a computer owned by a volunteer, outside my house. It gets only the text of this anonymous conversation. I add no visitor key, stored memories, contact record or IP address, but anything you type here is sent as you typed it. I check a sample of volunteer replies, not every one. A volunteer could still send a wrong or bad reply that I don't catch. Each reply says which machine answered.")); |
| 253 | assert!(!SKELETON.contains("id=\"allen-volunteer\" checked")); |
| 254 | assert_eq!(script.matches("'X-Allen-Volunteer'").count(), 1); |
| 255 | let headers = function_body(script, "volunteerHeaders"); |
| 256 | assert!(headers.contains("if (remembered || !tick || !tick.checked) return {};")); |
| 257 | assert!(function_body(script, "setVolunteer").contains("tick.checked = Boolean(on) && !remembered;")); |
| 258 | assert!(function_body(script, "showMode").contains("if (remembered) setVolunteer(false);")); |
| 259 | // Remembered chat carries the key, so the volunteer header is never beside it. |
| 260 | assert!(function_body(script, "keyHeaders").contains("if (!remembered) return { 'X-Allen-Anonymous': '1' };")); |
| 261 | assert!(script.contains("`answered by a volunteer's Spark (${clock.volunteer})`")); |
| 262 | assert!(function_body(script, "volunteerModel").contains("oh.answered_by !== 'volunteer'")); |
| 263 | assert!(script.contains("response.headers.get('X-OH-Model')")); |
| 264 | } |
| 265 | |
| 266 | #[test] |
| 267 | fn voice_clips_are_first_party_and_off_until_asked() { |
| 268 | // Aien's voice: same-origin clips under /aien/voice/ only, played by one |
| 269 | // Audio element after the visitor turns voice on; the choice stays in |
| 270 | // page memory (localStorage still holds only allen.key). |
| 271 | let script = include_str!("../../../../public/js/allen.js"); |
| 272 | assert!(script.contains("const VOICE_DIR = '/aien/voice/';")); |
| 273 | let clips = function_body(script, "voiceClips"); |
| 274 | for needle in ["c.file.startsWith(VOICE_DIR)", "c.file.endsWith('.mp3')", "!c.file.includes('..')"] { |
| 275 | assert!(clips.contains(needle), "voiceClips lacks {needle}"); |
| 276 | } |
| 277 | assert!(script.contains("const voice = { on: false, list: [], at: -1, audio: null };")); |
| 278 | assert_eq!(script.matches("new Audio(").count(), 1); |
| 279 | assert_eq!(script.matches("voice.audio.src = ").count(), 1); |
| 280 | assert!(function_body(script, "voicePlay").contains("voice.audio.src = voice.list[i].file;")); |
| 281 | assert!(!function_body(script, "voiceEnable").contains("Storage")); |
| 282 | assert_eq!(script.matches("'X-Allen-Hour'").count(), 1); |
| 283 | assert!(SKELETON.contains("id=\"allen-voice\" aria-pressed=\"false\">Voice: off</button>")); |
| 284 | } |
| 285 | |
| 286 | #[test] |
| 287 | fn only_allen_nodes_carry_the_allen_speaker_mark() { |
| 288 | let script = include_str!("../../../../public/js/allen.js"); |
| 289 | assert!(function_body(script, "message").contains("if (role === 'allen') item.dataset.speaker = 'allen';")); |
| 290 | assert!(function_body(script, "greeting").contains("message('allen', 'Aien')")); |
| 291 | assert_eq!(script.matches("dataset.speaker").count(), 1, "only message() marks a speaker"); |
| 292 | assert!(!function_body(script, "humanMessage").contains("speaker")); |
| 293 | assert!(!SKELETON.contains("data-speaker"), "Drake's page copy is never marked as Aien's"); |
| 294 | } |
| 295 | |
| 296 | #[test] |
| 297 | fn the_skeleton_declares_every_slot_the_script_fills() { |
| 298 | for id in [ |
| 299 | "allen", "allen-log", "allen-form", "allen-input", "allen-send", "allen-stop", "allen-status", "allen-new", |
| 300 | "allen-model", "allen-queue", "allen-ttft", "allen-first", "allen-rate", "allen-tokens", "allen-server", "allen-examples", |
| 301 | "allen-key", "allen-key-body", "allen-introduce", "allen-drake", "allen-mode", "allen-volunteer", "allen-volunteer-box", "allen-voice", "allen-voice-next", |
| 302 | ] { |
| 303 | assert_eq!(SKELETON.matches(&format!(" id=\"{id}\"")).count(), 1, "exactly one #{id} in the skeleton"); |
| 304 | } |
| 305 | assert!(SKELETON.contains("Model <code id=\"allen-model\">none</code>: no model answers on Drake's Spark right now.")); |
| 306 | assert!(SKELETON.contains("No prompts or IP addresses are logged.")); |
| 307 | assert!(!SKELETON.contains('\u{2014}') && !SKELETON.contains('\u{2013}'), "no em or en dash"); |
| 308 | } |
| 309 | |
| 310 | /// The body of the top-level function `name` in the generated script. |
| 311 | fn function_body<'a>(script: &'a str, name: &str) -> &'a str { |
| 312 | let start = script.find(&format!(" function {name}(")).unwrap_or_else(|| panic!("allen.js lacks function {name}")); |
| 313 | let end = script[start..].find("\n }\n").expect("function end") + start; |
| 314 | &script[start..end] |
| 315 | } |
| 316 | |
| 317 | #[test] |
| 318 | fn only_the_session_channel_can_show_drake() { |
| 319 | // The Drake name and avatar are made in exactly one function, and that |
| 320 | // function is called only for `event: human` on the session stream, |
| 321 | // which the gateway emits only for Drake's authenticated console. |
| 322 | // Model tokens and visitor text go through message('allen'|'user'). |
| 323 | let script = include_str!("../../../../public/js/allen.js"); |
| 324 | let human = function_body(script, "humanMessage"); |
| 325 | for marker in ["'Drake'", "allen-msg-drake", "allen-avatar"] { |
| 326 | assert_eq!(script.matches(marker).count(), 1, "{marker} must occur exactly once"); |
| 327 | assert!(human.contains(marker), "{marker} must be inside humanMessage"); |
| 328 | } |
| 329 | assert_eq!(script.matches("humanMessage(").count(), 2, "humanMessage is defined once and called once"); |
| 330 | let session = function_body(script, "onSession"); |
| 331 | assert!(session.contains("if (name === 'human' && typeof value.text === 'string') {\n humanMessage(")); |
| 332 | // The page UI hears Drake only through the same branch. |
| 333 | assert_eq!(script.matches("emit('human'").count(), 1); |
| 334 | assert!(session.contains("emit('human', { text: value.text.slice(0, 8000) });")); |
| 335 | assert!(function_body(script, "session").contains("sse((name, data) => onSession(name, data, controller))")); |
| 336 | assert_eq!(script.matches("onSession(").count(), 2, "onSession is fed only by the session stream"); |
| 337 | for (role, label) in [("user", "'You'"), ("allen", "'Aien'")] { |
| 338 | assert!(script.contains(&format!("message('{role}', {label})"))); |
| 339 | } |
| 340 | assert!(!script.contains("message('drake'"), "message() never takes a Drake role"); |
| 341 | assert_eq!(script.matches("message(role").count(), 1, "message(role, label) is only defined, never called with a variable role"); |
| 342 | } |
| 343 | |
| 344 | #[test] |
| 345 | fn llms_documents_the_consent_gated_introduction_in_the_first_person_singular() { |
| 346 | for needle in ["POST https://www.aienos.com/aien/api/introduce", "\"consent\": true", "\"human\"", "consent_required", "#forget=", "aien@aienos.com"] { |
| 347 | assert!(LLMS.contains(needle), "llms.txt section lacks {needle}"); |
| 348 | } |
| 349 | let script = include_str!("../../../../public/js/allen.js"); |
| 350 | // Drake's greetings are Aien speaking and keep his words; every other |
| 351 | // string stays first person singular. |
| 352 | let script = script.replace(GREETING_REMEMBER, "").replace(GREETING_ANONYMOUS, ""); |
| 353 | for text in [LLMS, SKELETON, script.as_str()] { |
| 354 | assert!(!text.contains('\u{2014}') && !text.contains('\u{2013}'), "no em or en dash"); |
| 355 | for word in text.split(|c: char| !c.is_ascii_alphabetic()) { |
| 356 | let w = word.to_ascii_lowercase(); |
| 357 | assert!(!["we", "us", "our", "ours", "ourselves"].contains(&w.as_str()), "plural first person: {word}"); |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | #[test] |
| 363 | fn the_stylesheet_stays_on_the_shared_palette_and_compositor_motion() { |
| 364 | let css = include_str!("../../../../public/assets/allen.css"); |
| 365 | assert!(!css.contains("@import") && !css.contains("url("), "allen.css loads nothing from outside"); |
| 366 | assert!(!css.contains('#'), "allen.css takes its colours from the style.css tokens, not hex literals"); |
| 367 | for line in css.lines().filter(|l| l.contains("transition") || l.contains("animation")) { |
| 368 | assert!(!line.contains("filter") && !line.contains("box-shadow") && !line.contains("transition: all"), "compositor-only motion: {line}"); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | #[test] |
| 373 | fn the_universe_script_matches_its_omega_generated_sha256() { |
| 374 | let script = include_bytes!("../../../../public/js/aien-universe.js"); |
| 375 | let want = recorded(include_str!("../../../../om/aien-universe/aien-universe.js.sha256")); |
| 376 | let got = format!("{:x}", Sha256::digest(script)); |
| 377 | assert_eq!(got, want, "aien-universe.js is generated, never hand-edited; run: sh om/aien-universe/check.sh"); |
| 378 | } |
| 379 | |
| 380 | #[test] |
| 381 | fn the_universe_adds_no_markup_paths_and_one_fetch() { |
| 382 | let script = include_str!("../../../../public/js/aien-universe.js"); |
| 383 | for banned in ["innerHTML", "outerHTML", "insertAdjacentHTML", "document.write", "createContextualFragment", "localStorage", "sessionStorage", "document.cookie", "eval(", "new Function"] { |
| 384 | assert!(!script.contains(banned), "aien-universe.js must not use {banned}"); |
| 385 | } |
| 386 | assert_eq!(script.matches("fetch(").count(), 1, "the only request is the math route"); |
| 387 | assert!(script.contains("fetch(MATH")); |
| 388 | assert!(script.contains("const MATH = '/aien/api/math';")); |
| 389 | // One bubble, never a transcript: the reply pages inside it. |
| 390 | assert!(script.contains("const PAGE_CHARS = 180;")); |
| 391 | // The iMac order: the tube (dusk) first, then the night's merger. |
| 392 | assert!(script.contains("opening: still.matches ? 'idle' : 'dusk'")); |
| 393 | assert!(script.contains("sceneCall('enter', 'birth');")); |
| 394 | } |
| 395 | |
| 396 | #[test] |
| 397 | fn the_skeleton_declares_every_slot_the_universe_fills() { |
| 398 | for id in ["aien-sky", "aien-bubble", "aien-bubble-who", "aien-bubble-text", "aien-bubble-acts", "aien-panes", "aien-menu", "aien-replay", "aien-sound", "aien-speed", "aien-math"] { |
| 399 | assert_eq!(SKELETON.matches(&format!(" id=\"{id}\"")).count(), 1, "exactly one #{id} in the skeleton"); |
| 400 | } |
| 401 | let css = include_str!("../../../../public/assets/allen.css"); |
| 402 | let at = css.find(".aien-bubble-text {").expect("the bubble text rule"); |
| 403 | let rule = &css[at..at + css[at..].find('}').expect("rule closes")]; |
| 404 | assert!(!rule.contains("overflow-y") && !rule.contains("max-height"), "the bubble never scrolls: {rule}"); |
| 405 | } |
| 406 | |
| 407 | /// The first phrase in `text` that presents a model as answering on /aien/ today. |
| 408 | fn claims_a_model_serves_aien(text: &str) -> Option<&'static str> { |
| 409 | let lower = text.to_ascii_lowercase(); |
| 410 | ["running on the live", "running on a dgx spark", ">qwen3.6-35b-a3b-fp8<", "i run on the qwen"] |
| 411 | .into_iter() |
| 412 | .find(|needle| lower.contains(needle)) |
| 413 | } |
| 414 | |
| 415 | #[test] |
| 416 | fn no_retired_model_reads_as_serving_aien() { |
| 417 | // The Qwen models were retired on 2026-11-06 and nothing serves /aien/ today |
| 418 | // (the Omega LLM is not deployed). The model slot starts at "none" until a |
| 419 | // stream names the model that answered. |
| 420 | // The gateway's system prompt is what the first model routed to /aien/ reads about |
| 421 | // itself, so it names no model either (DRA-30 P3-1). |
| 422 | let prompt = include_str!("../../../../scripts/allen/system-prompt.txt"); |
| 423 | for (name, text) in [("skeleton", SKELETON), ("llms", LLMS), ("system prompt", prompt)] { |
| 424 | assert_eq!(claims_a_model_serves_aien(text), None, "{name} presents a model as serving /aien/"); |
| 425 | } |
| 426 | // "Qwen3 token" (the Omegese tokenizer fact) is not a model claim; the retired |
| 427 | // Qwen3.6 models are never named. |
| 428 | assert!(!prompt.to_ascii_lowercase().contains("qwen3.6"), "the gateway system prompt names a retired Qwen3.6 model"); |
| 429 | assert!(SKELETON.contains("retired on 2026-11-06") && SKELETON.contains("is not deployed yet")); |
| 430 | assert!(LLMS.contains("No model answers there right now") && LLMS.contains("retired on 2026-11-06")); |
| 431 | // Negative controls: the old copy is refused. |
| 432 | for old in [ |
| 433 | "<p class=\"allen-where\">Model <code id=\"allen-model\">qwen3.6-35b-a3b-fp8</code>, running on a DGX Spark in Drake's house.</p>", |
| 434 | "Aien (formerly Allen; say it like Ian) is my AI, running on the live Qwen3.6-35B-A3B FP8 model on my DGX Spark.", |
| 435 | "On this page I run on the Qwen3.6 35B A3B FP8 model, served by Drake's own Omega engine on a DGX Spark in his house.", |
| 436 | "On this page I run on the Qwen3.6 35B A3B FP8 model, a mixture-of-experts with about 3B parameters active per token, served by Drake's own C GPU stack", |
| 437 | ] { |
| 438 | assert!(claims_a_model_serves_aien(old).is_some(), "negative control not refused: {old}"); |
| 439 | } |
| 440 | } |
| 441 | } |