interplane.Get Omega
Read in your language

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

GitHub aien-dev/aien-sovereign-core-mv#377 (code only)

closed derived 483925f0f7b27c6c #377

Imported from GitHub aien-dev/aien-sovereign-core-mv#377 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base 4de815a8c68c53c9236271a6f411beb51460577c · Head add7226179d95d057319c84d7aadeafb5eedfa58

Apply it

git checkout -b patch-483925f0f7b27c6c 4de815a8c68c53c9236271a6f411beb51460577c
curl -fsSL https://interplane.io/drakestapleton/aien-sovereign-core-mv/patches/483925f0f7b27c6c.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/aien-sovereign-core-mv
377
add7226179d95d057319c84d7aadeafb5eedfa58
{"kind":"github-import","owner":"aien-dev","repo":"aien-sovereign-core-mv","number":377,"url":"https://github.com/aien-dev/aien-sovereign-core-mv/pull/377","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:59Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/.crumb b/.crumb
index efbb9485..bfed28e4 100644
--- a/.crumb
+++ b/.crumb
@@ -65,26 +65,26 @@
       "children": [
         {
           "digest": "8f8e6711a2369bd507758796628aef121a2426011f68d13f58f5b414f0e19af3",
-          "last_commit": "9052fe3",
+          "last_commit": "4de815a",
           "name": "scripts",
           "purpose": ""
         },
         {
-          "digest": "ac32ed84159cae1f43f3b5d2307b2a1ab04ea580c8f96c1f52566a7f21cca0b0",
-          "last_commit": "5b7861f",
+          "digest": "f432725dc4aef6ecd69eea043123fbb7593a9d29af97d70a561f5f355a8ad180",
+          "last_commit": "8a48904",
           "name": "skills",
           "purpose": ""
         }
       ],
-      "children_root": "sha256:579fdac7b333de165168a61d3198f109b92dc0e2973a8d40ed615a07c56d7e1f",
-      "compiled_at": "2026-10-10T03:55:24Z",
+      "children_root": "sha256:555bca7d68bcd3bac739f3dc7bac1a895ed71ea4707dd70aa1ed96c771290c44",
+      "compiled_at": "2026-10-10T08:55:54Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:38cb86c9f992536e9f5ccfd3b1fb40d825ecb375974e30ed81d056c06493c1d1",
+      "digest": "sha256:edcae732adfe4e19a227dccee3b9e12c402e52cf9a9c74f9eed545b6a4160a89",
       "evidence_files": 187,
       "evidence_root": "sha256:27ee0353cb4d4aae2b7dbce2bfe0d9f4ef2a94cd7a4555b84684d59372503280",
-      "files": 1851,
-      "generated_at_commit": "9052fe3fd075386dafa45cb5e06acd46c95b9d01",
-      "source_tree": "sha256:35b0206be0b5122cdf42b04c6bf158d0efd828c1a32dcb314a3ccfdcca6796ff"
+      "files": 1853,
+      "generated_at_commit": "8a48904fde00f3a182f9840aeb2acd23e3c79fa6",
+      "source_tree": "sha256:65e82e7a1c76308118a463577b8b2837e2aa22651318e9ba3d4007cae195161e"
     }
   },
   "history": [],
diff --git a/crates/aien-cli/.crumb b/crates/aien-cli/.crumb
index cd9d0212..a2553009 100644
--- a/crates/aien-cli/.crumb
+++ b/crates/aien-cli/.crumb
@@ -34,21 +34,21 @@
     "generated": {
       "children": [
         {
-          "digest": "dd43e4f3ee00804bd1aaac8906238f44688f719d9c5422a68fc4fee6906768af",
-          "last_commit": "b0cee16",
+          "digest": "1c24673fa15c3bb2a7653404d808dda4fd97753dabd992570f3e371add429c81",
+          "last_commit": "8a48904",
           "name": "src",
           "purpose": ""
         }
       ],
-      "children_root": "sha256:e2f54116bdcc7366210192f3e08ba76d21cbec793541c092782b2c14aecafc49",
-      "compiled_at": "2026-10-09T13:31:53Z",
+      "children_root": "sha256:1c3e00a737a636e539345fe90a2f67c0bb9512bf6dbd4bbe053d43641d3bab05",
+      "compiled_at": "2026-10-10T08:55:54Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:7a0a20fef74798fed69624009d7e2df05c772ca399ca3ee43bd9b8f5fb5fe181",
+      "digest": "sha256:7402aa7e5c3ad0624bc6dbea93130049dc798d1e56b9e6ef20153b8b81820b10",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "files": 35,
-      "generated_at_commit": "1bdadbdc330fe604b5d79413a2534406bac63fd9",
-      "source_tree": "sha256:53716c2c2996d2a42fb09165455b14fb31ec260433a6c39e7cd162659733c15f"
+      "files": 37,
+      "generated_at_commit": "8a48904fde00f3a182f9840aeb2acd23e3c79fa6",
+      "source_tree": "sha256:c9e5fa0ccc920bb8d8dec375c1aa619489ea7288dd246090d403d7f8c2b76051"
     }
   },
   "history": [
diff --git a/crates/aien-cli/src/.crumb b/crates/aien-cli/src/.crumb
index db43671c..32a720b7 100644
--- a/crates/aien-cli/src/.crumb
+++ b/crates/aien-cli/src/.crumb
@@ -64,14 +64,14 @@
     "generated": {
       "children": [],
       "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "compiled_at": "2026-10-08T20:16:31Z",
+      "compiled_at": "2026-10-10T08:55:54Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:dd43e4f3ee00804bd1aaac8906238f44688f719d9c5422a68fc4fee6906768af",
+      "digest": "sha256:1c24673fa15c3bb2a7653404d808dda4fd97753dabd992570f3e371add429c81",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "files": 26,
-      "generated_at_commit": "ec9a17e8fd7e138937179095ffee55d561df844a",
-      "source_tree": "sha256:18914c7b2e6c4d5ed98120a7793b48786044589c947c390a052ca39a8430a709"
+      "files": 28,
+      "generated_at_commit": "8a48904fde00f3a182f9840aeb2acd23e3c79fa6",
+      "source_tree": "sha256:c5cd891af69455b3dd990b78440b756dddbb1f6dbdc05445f88e52f92ae6a8a1"
     }
   },
   "history": [
diff --git a/crates/aien-cli/src/bin/aien-browser-mirror.rs b/crates/aien-cli/src/bin/aien-browser-mirror.rs
new file mode 100644
index 00000000..f0b88de4
--- /dev/null
+++ b/crates/aien-cli/src/bin/aien-browser-mirror.rs
@@ -0,0 +1,78 @@
+//! `aien-browser-mirror`: headless-Chrome Cockpit mirror over the Chrome
+//! DevTools Protocol. Rust replacement for the removed Python script
+//! `basecamp/scripts/browser_mirror_test.py` (sovereign-core #180), same flags.
+//!
+//! ```text
+//! aien-browser-mirror --test                      Cockpit self-test (default)
+//! aien-browser-mirror --mentor "PROMPT"           one chat prompt, wait for the reply
+//! aien-browser-mirror --screenshot [FILE.png]     screenshot of --url
+//! aien-browser-mirror --eval "EXPR"               evaluate JavaScript on --url
+//!   --url URL        Cockpit or any page (default http://127.0.0.1:18095)
+//!   --out-dir DIR    where screenshots and reports go (default ~/basecamp/ui-tests)
+//! ```
+//!
+//! Prints the JSON report on stdout. Exit status 0 when the report says
+//! PASSED, COMPLETED or ok; 1 otherwise; 2 for a usage error.
+
+use aien_cli::browser_mirror as bm;
+use std::path::PathBuf;
+
+fn usage() -> ! {
+    eprintln!(
+        "usage: aien-browser-mirror [--test | --mentor PROMPT | --screenshot [FILE] | --eval EXPR]\n\
+         \x20                          [--url URL] [--out-dir DIR]"
+    );
+    std::process::exit(2)
+}
+
+fn main() {
+    let args: Vec<String> = std::env::args().skip(1).collect();
+    let mut action = "test".to_string();
+    let mut arg: Option<String> = None;
+    let mut url = std::env::var("AIEN_COCKPIT_URL").unwrap_or_else(|_| bm::DEFAULT_URL.to_string());
+    let mut out_dir: PathBuf = bm::default_out_dir();
+    let mut i = 0;
+    while i < args.len() {
+        match args[i].as_str() {
+            "--test" => action = "test".to_string(),
+            "--mentor" => {
+                action = "mentor".to_string();
+                if let Some(p) = args.get(i + 1).filter(|p| !p.starts_with("--")) {
+                    arg = Some(p.clone());
+                    i += 1;
+                }
+            }
+            "--screenshot" => {
+                action = "screenshot".to_string();
+                if let Some(p) = args.get(i + 1).filter(|p| !p.starts_with("--")) {
+                    arg = Some(p.clone());
+                    i += 1;
+                }
+            }
+            "--eval" => {
+                action = "eval".to_string();
+                arg = Some(args.get(i + 1).cloned().unwrap_or_else(|| usage()));
+                i += 1;
+            }
+            "--url" => {
+                url = args.get(i + 1).cloned().unwrap_or_else(|| usage());
+                i += 1;
+            }
+            "--out-dir" => {
+                out_dir = PathBuf::from(args.get(i + 1).cloned().unwrap_or_else(|| usage()));
+                i += 1;
+            }
+            "-h" | "--help" => usage(),
+            _ => usage(),
+        }
+        i += 1;
+    }
+    let report = bm::dispatch(&action, arg.as_deref(), &url, &out_dir);
+    println!(
+        "{}",
+        serde_json::to_string_pretty(&report).unwrap_or_default()
+    );
+    let status = report.get("status").and_then(|s| s.as_str()).unwrap_or("");
+    let ok = matches!(status, "PASSED" | "COMPLETED" | "ok");
+    std::process::exit(if ok { 0 } else { 1 });
+}
diff --git a/crates/aien-cli/src/browser_mirror.rs b/crates/aien-cli/src/browser_mirror.rs
new file mode 100644
index 00000000..96a9d5ba
--- /dev/null
+++ b/crates/aien-cli/src/browser_mirror.rs
@@ -0,0 +1,943 @@
+//! Headless-Chrome Cockpit mirror over the Chrome DevTools Protocol (CDP).
+//!
+//! This is the Rust replacement for the removed Python script
+//! `basecamp/scripts/browser_mirror_test.py` (sovereign-core #180/#181). It
+//! carries no new dependencies: the websocket client, the tiny HTTP fetch and
+//! the base64 decoder are written here against `std::net`.
+//!
+//! Modes (also exposed by the `aien-browser-mirror` binary and `aien --browser`):
+//!
+//! * `test`       Cockpit self-test: hydration, chat stream, navigation, three screenshots.
+//! * `mentor`     Send one prompt to the Cockpit chat, wait for the reply, screenshot it.
+//! * `screenshot` Open any URL, capture a PNG, record the document title.
+//! * `eval`       Open any URL and evaluate a JavaScript expression (value returned as JSON).
+//!
+//! Every mode spawns its own Chrome with a private profile directory and kills it
+//! when done, whatever happened in between.
+
+use serde_json::{json, Value};
+use std::fs;
+use std::io::{Read, Write};
+use std::net::TcpStream;
+use std::path::{Path, PathBuf};
+use std::process::{Child, Command, Stdio};
+use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
+
+/// Default Cockpit address (spark-cockpit-rs).
+pub const DEFAULT_URL: &str = "http://127.0.0.1:18095";
+
+/// How long to wait for Chrome to publish its debugging port.
+const CHROME_BOOT_TIMEOUT: Duration = Duration::from_secs(20);
+/// Per-command CDP reply timeout.
+const CDP_REPLY_TIMEOUT: Duration = Duration::from_secs(30);
+/// Largest websocket message we accept (screenshots are a few MB).
+const MAX_WS_MESSAGE: usize = 64 * 1024 * 1024;
+
+/// Where screenshots and reports land when no `--out-dir` is given.
+pub fn default_out_dir() -> PathBuf {
+    let home = std::env::var("HOME").unwrap_or_else(|_| ".".to_string());
+    Path::new(&home).join("basecamp").join("ui-tests")
+}
+
+/// Candidate Chrome binaries, first match wins. `AIEN_CHROME` overrides.
+pub fn chrome_candidates() -> Vec<String> {
+    let mut v = Vec::new();
+    if let Ok(p) = std::env::var("AIEN_CHROME") {
+        if !p.is_empty() {
+            v.push(p);
+        }
+    }
+    for name in [
+        "google-chrome",
+        "google-chrome-stable",
+        "chromium",
+        "chromium-browser",
+        "chrome",
+    ] {
+        v.push(name.to_string());
+    }
+    v
+}
+
+/// Returns the first Chrome binary that answers `--version`, if any.
+pub fn find_chrome() -> Option<String> {
+    chrome_candidates().into_iter().find(|c| {
+        Command::new(c)
+            .arg("--version")
+            .stdout(Stdio::null())
+            .stderr(Stdio::null())
+            .status()
+            .map(|s| s.success())
+            .unwrap_or(false)
+    })
+}
+
+fn now_secs() -> u64 {
+    SystemTime::now()
+        .duration_since(UNIX_EPOCH)
+        .map(|d| d.as_secs())
+        .unwrap_or(0)
+}
+
+fn now_nanos() -> u128 {
+    SystemTime::now()
+        .duration_since(UNIX_EPOCH)
+        .map(|d| d.as_nanos())
+        .unwrap_or(0)
+}
+
+// ---------------------------------------------------------------------------
+// base64 (standard alphabet, padding tolerated)
+// ---------------------------------------------------------------------------
+
+const B64: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+fn base64_encode(data: &[u8]) -> String {
+    let mut out = String::with_capacity(data.len().div_ceil(3) * 4);
+    for chunk in data.chunks(3) {
+        let b = [
+            chunk[0],
+            chunk.get(1).copied().unwrap_or(0),
+            chunk.get(2).copied().unwrap_or(0),
+        ];
+        let n = (u32::from(b[0]) << 16) | (u32::from(b[1]) << 8) | u32::from(b[2]);
+        out.push(B64[(n >> 18) as usize & 63] as char);
+        out.push(B64[(n >> 12) as usize & 63] as char);
+        out.push(if chunk.len() > 1 {
+            B64[(n >> 6) as usize & 63] as char
+        } else {
+            '='
+        });
+        out.push(if chunk.len() > 2 {
+            B64[n as usize & 63] as char
+        } else {
+            '='
+        });
+    }
+    out
+}
+
+/// Decodes standard base64. Whitespace is skipped; anything else is an error.
+pub fn base64_decode(text: &str) -> Result<Vec<u8>, String> {
+    fn val(c: u8) -> Option<u32> {
+        match c {
+            b'A'..=b'Z' => Some(u32::from(c - b'A')),
+            b'a'..=b'z' => Some(u32::from(c - b'a') + 26),
+            b'0'..=b'9' => Some(u32::from(c - b'0') + 52),
+            b'+' => Some(62),
+            b'/' => Some(63),
+            _ => None,
+        }
+    }
+    let mut out = Vec::with_capacity(text.len() / 4 * 3);
+    let mut acc: u32 = 0;
+    let mut bits = 0u32;
+    for &c in text.as_bytes() {
+        if c.is_ascii_whitespace() || c == b'=' {
+            continue;
+        }
+        let v = val(c).ok_or_else(|| format!("base64: invalid byte 0x{:02x}", c))?;
+        acc = (acc << 6) | v;
+        bits += 6;
+        if bits >= 8 {
+            bits -= 8;
+            out.push((acc >> bits) as u8);
+            acc &= (1 << bits) - 1;
+        }
+    }
+    Ok(out)
+}
+
+// ---------------------------------------------------------------------------
+// Minimal HTTP GET (used for /json on the DevTools port)
+// ---------------------------------------------------------------------------
+
+fn http_get(host: &str, port: u16, path: &str, timeout: Duration) -> Result<String, String> {
+    let mut s = TcpStream::connect((host, port)).map_err(|e| format!("connect: {}", e))?;
+    s.set_read_timeout(Some(timeout))
+        .map_err(|e| format!("timeout: {}", e))?;
+    let req = format!(
+        "GET {} HTTP/1.1\r\nHost: {}:{}\r\nConnection: close\r\n\r\n",
+        path, host, port
+    );
+    s.write_all(req.as_bytes())
+        .map_err(|e| format!("write: {}", e))?;
+    // Chrome honours Content-Length but keeps the connection open, so read the
+    // headers first and then exactly the announced body.
+    let mut head = Vec::new();
+    let mut one = [0u8; 1];
+    while !head.ends_with(b"\r\n\r\n") {
+        let n = s.read(&mut one).map_err(|e| format!("read: {}", e))?;
+        if n == 0 {
+            return Err("http: connection closed in headers".to_string());
+        }
+        head.push(one[0]);
+        if head.len() > 64 * 1024 {
+            return Err("http: header too long".to_string());
+        }
+    }
+    let head = String::from_utf8_lossy(&head).to_string();
+    let status = head.lines().next().unwrap_or("");
+    if !status.contains(" 200 ") {
+        return Err(format!("http: {}", status));
+    }
+    let len = head.lines().find_map(|l| {
+        let (k, v) = l.split_once(':')?;
+        if k.trim().eq_ignore_ascii_case("content-length") {
+            v.trim().parse::<usize>().ok()
+        } else {
+            None
+        }
+    });
+    let mut body = Vec::new();
+    match len {
+        Some(n) => {
+            body.resize(n, 0);
+            s.read_exact(&mut body)
+                .map_err(|e| format!("read body: {}", e))?;
+        }
+        None => {
+            s.read_to_end(&mut body)
+                .map_err(|e| format!("read: {}", e))?;
+        }
+    }
+    Ok(String::from_utf8_lossy(&body).to_string())
+}
+
+// ---------------------------------------------------------------------------
+// Websocket client (RFC 6455, client side, text frames)
+// ---------------------------------------------------------------------------
+
+struct WebSocket {
+    stream: TcpStream,
+    rng: u64,
+}
+
+impl WebSocket {
+    /// Connects to `ws://host:port/path` and completes the HTTP upgrade.
+    fn connect(url: &str) -> Result<Self, String> {
+        let rest = url
+            .strip_prefix("ws://")
+            .ok_or_else(|| format!("websocket: unsupported url {}", url))?;
+        let (hostport, path) = match rest.find('/') {
+            Some(i) => (&rest[..i], &rest[i..]),
+            None => (rest, "/"),
+        };
+        let (host, port) = match hostport.rsplit_once(':') {
+            Some((h, p)) => (h, p.parse::<u16>().map_err(|e| format!("port: {}", e))?),
+            None => (hostport, 80),
+        };
+        let stream = TcpStream::connect((host, port)).map_err(|e| format!("connect: {}", e))?;
+        stream
+            .set_read_timeout(Some(CDP_REPLY_TIMEOUT))
+            .map_err(|e| format!("timeout: {}", e))?;
+        stream.set_nodelay(true).ok();
+        let mut ws = WebSocket {
+            stream,
+            rng: now_nanos() as u64 ^ 0x9E37_79B9_7F4A_7C15,
+        };
+        let mut key = [0u8; 16];
+        for b in key.iter_mut() {
+            *b = ws.next_byte();
+        }
+        let req = format!(
+            "GET {} HTTP/1.1\r\nHost: {}:{}\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n\
+             Sec-WebSocket-Key: {}\r\nSec-WebSocket-Version: 13\r\n\r\n",
+            path,
+            host,
+            port,
+            base64_encode(&key)
+        );
+        ws.stream
+            .write_all(req.as_bytes())
+            .map_err(|e| format!("handshake write: {}", e))?;
+        // Read the response headers byte by byte up to the blank line.
+        let mut head = Vec::new();
+        let mut one = [0u8; 1];
+        while !head.ends_with(b"\r\n\r\n") {
+            let n = ws
+                .stream
+                .read(&mut one)
+                .map_err(|e| format!("handshake read: {}", e))?;
+            if n == 0 {
+                return Err("handshake: connection closed".to_string());
+            }
+            head.push(one[0]);
+            if head.len() > 16 * 1024 {
+                return Err("handshake: header too long".to_string());
+            }
+        }
+        let text = String::from_utf8_lossy(&head);
+        let status = text.lines().next().unwrap_or("");
+        if !status.contains(" 101 ") {
+            return Err(format!("handshake refused: {}", status));
+        }
+        Ok(ws)
+    }
+
+    fn next_byte(&mut self) -> u8 {
+        // xorshift64*: only used for mask keys and the handshake nonce.
+        let mut x = self.rng;
+        x ^= x >> 12;
+        x ^= x << 25;
+        x ^= x >> 27;
+        self.rng = x;
+        (x.wrapping_mul(0x2545_F491_4F6C_DD1D) >> 56) as u8
+    }
+
+    fn send_frame(&mut self, opcode: u8, payload: &[u8]) -> Result<(), String> {
+        let mut frame = Vec::with_capacity(payload.len() + 14);
+        frame.push(0x80 | opcode);
+        let len = payload.len();
+        if len < 126 {
+            frame.push(0x80 | len as u8);
+        } else if len <= 0xFFFF {
+            frame.push(0x80 | 126);
+            frame.extend_from_slice(&(len as u16).to_be_bytes());
+        } else {
+            frame.push(0x80 | 127);
+            frame.extend_from_slice(&(len as u64).to_be_bytes());
+        }
+        let mask = [
+            self.next_byte(),
+            self.next_byte(),
+            self.next_byte(),
+            self.next_byte(),
+        ];
+        frame.extend_from_slice(&mask);
+        frame.extend(payload.iter().enumerate().map(|(i, b)| b ^ mask[i % 4]));
+        self.stream
+            .write_all(&frame)
+            .map_err(|e| format!("websocket write: {}", e))
+    }
+
+    fn send_text(&mut self, text: &str) -> Result<(), String> {
+        self.send_frame(0x1, text.as_bytes())
+    }
+
+    fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), String> {
+        self.stream
+            .read_exact(buf)
+            .map_err(|e| format!("websocket read: {}", e))
+    }
+
+    /// Reads one complete text message, answering pings and honouring close.
+    fn recv_text(&mut self) -> Result<String, String> {
+        let mut message: Vec<u8> = Vec::new();
+        loop {
+            let mut hdr = [0u8; 2];
+            self.read_exact(&mut hdr)?;
+            let fin = hdr[0] & 0x80 != 0;
+            let opcode = hdr[0] & 0x0F;
+            let masked = hdr[1] & 0x80 != 0;
+            let mut len = u64::from(hdr[1] & 0x7F);
+            if len == 126 {
+                let mut b = [0u8; 2];
+                self.read_exact(&mut b)?;
+                len = u64::from(u16::from_be_bytes(b));
+            } else if len == 127 {
+                let mut b = [0u8; 8];
+                self.read_exact(&mut b)?;
+                len = u64::from_be_bytes(b);
+            }
+            if len as usize > MAX_WS_MESSAGE || message.len() + len as usize > MAX_WS_MESSAGE {
+                return Err("websocket: message too large".to_string());
+            }
+            let mut mask = [0u8; 4];
+            if masked {
+                self.read_exact(&mut mask)?;
+            }
+            let mut payload = vec![0u8; len as usize];
+            self.read_exact(&mut payload)?;
+            if masked {
+                for (i, b) in payload.iter_mut().enumerate() {
+                    *b ^= mask[i % 4];
+                }
+            }
+            match opcode {
+                0x0..=0x2 => {
+                    message.extend_from_slice(&payload);
+                    if fin {
+                        return String::from_utf8(message)
+                            .map_err(|e| format!("websocket: bad utf-8: {}", e));
+                    }
+                }
+                0x8 => {
+                    self.send_frame(0x8, &payload).ok();
+                    return Err("websocket: closed by peer".to_string());
+                }
+                0x9 => self.send_frame(0xA, &payload)?,
+                0xA => {}
+                other => return Err(format!("websocket: unknown opcode {}", other)),
+            }
+        }
+    }
+
+    fn close(&mut self) {
+        self.send_frame(0x8, &1000u16.to_be_bytes()).ok();
+    }
+}
+
+// ---------------------------------------------------------------------------
+// Chrome process + CDP session
+// ---------------------------------------------------------------------------
+
+struct ChromeProcess {
+    child: Child,
+    profile_dir: PathBuf,
+    port: u16,
+}
+
+impl ChromeProcess {
+    fn spawn(binary: &str, url: &str) -> Result<Self, String> {
+        let profile_dir = std::env::temp_dir().join(format!(
+            "aien-browser-mirror-{}-{}",
+            std::process::id(),
+            now_nanos()
+        ));
+        fs::create_dir_all(&profile_dir).map_err(|e| format!("profile dir: {}", e))?;
+        let child = Command::new(binary)
+            .arg("--headless=new")
+            .arg("--remote-debugging-port=0")
+            .arg(format!("--user-data-dir={}", profile_dir.display()))
+            .arg("--remote-allow-origins=*")
+            .arg("--no-first-run")
+            .arg("--no-default-browser-check")
+            .arg("--disable-dev-shm-usage")
+            .arg("--disable-gpu")
+            .arg("--no-sandbox")
+            .arg("--window-size=1280,900")
+            .arg(url)
+            .stdin(Stdio::null())
+            .stdout(Stdio::null())
+            .stderr(Stdio::null())
+            .spawn()
+            .map_err(|e| format!("spawn {}: {}", binary, e))?;
+        let mut me = ChromeProcess {
+            child,
+            profile_dir,
+            port: 0,
+        };
+        // Chrome writes "<port>\n<browser ws path>" once the debugger listens.
+        let deadline = Instant::now() + CHROME_BOOT_TIMEOUT;
+        let marker = me.profile_dir.join("DevToolsActivePort");
+        loop {
+            if let Ok(text) = fs::read_to_string(&marker) {
+                if let Some(p) = text
+                    .lines()
+                    .next()
+                    .and_then(|l| l.trim().parse::<u16>().ok())
+                {
+                    me.port = p;
+                    break;
+                }
+            }
+            if let Ok(Some(status)) = me.child.try_wait() {
+                return Err(format!("chrome exited early: {}", status));
+            }
+            if Instant::now() >= deadline {
+                return Err("chrome did not publish DevToolsActivePort in time".to_string());
+            }
+            std::thread::sleep(Duration::from_millis(100));
+        }
+        Ok(me)
+    }
+
+    /// Finds the websocket URL of the first page target.
+    fn page_ws_url(&self) -> Result<String, String> {
+        let deadline = Instant::now() + CHROME_BOOT_TIMEOUT;
+        loop {
+            if let Ok(body) = http_get("127.0.0.1", self.port, "/json", Duration::from_secs(5)) {
+                if let Ok(Value::Array(targets)) = serde_json::from_str::<Value>(&body) {
+                    for t in &targets {
+                        if t.get("type").and_then(Value::as_str) == Some("page") {
+                            if let Some(ws) = t.get("webSocketDebuggerUrl").and_then(Value::as_str)
+                            {
+                                return Ok(ws.to_string());
+                            }
+                        }
+                    }
+                }
+            }
+            if Instant::now() >= deadline {
+                return Err("chrome exposed no page target".to_string());
+            }
+            std::thread::sleep(Duration::from_millis(150));
+        }
+    }
+}
+
+impl Drop for ChromeProcess {
+    fn drop(&mut self) {
+        self.child.kill().ok();
+        self.child.wait().ok();
+        fs::remove_dir_all(&self.profile_dir).ok();
+    }
+}
+
+/// One CDP page session.
+pub struct CdpClient {
+    ws: WebSocket,
+    next_id: u64,
+}
+
+impl CdpClient {
+    fn connect(ws_url: &str) -> Result<Self, String> {
+        Ok(CdpClient {
+            ws: WebSocket::connect(ws_url)?,
+            next_id: 1,
+        })
+    }
+
+    /// Sends a CDP command and returns its `result` object.
+    pub fn send(&mut self, method: &str, params: Value) -> Result<Value, String> {
+        let id = self.next_id;
+        self.next_id += 1;
+        let msg = json!({"id": id, "method": method, "params": params});
+        self.ws.send_text(&msg.to_string())?;
+        let deadline = Instant::now() + CDP_REPLY_TIMEOUT;
+        loop {
+            if Instant::now() >= deadline {
+                return Err(format!("cdp: {} timed out", method));
+            }
+            let text = self.ws.recv_text()?;
+            let v: Value = serde_json::from_str(&text).map_err(|e| format!("cdp json: {}", e))?;
+            if v.get("id").and_then(Value::as_u64) != Some(id) {
+                continue; // an event or a stale reply
+            }
+            if let Some(err) = v.get("error") {
+                return Err(format!("cdp {}: {}", method, err));
+            }
+            return Ok(v.get("result").cloned().unwrap_or(Value::Null));
+        }
+    }
+
+    /// Evaluates JavaScript and returns the value (`returnByValue`).
+    pub fn eval(&mut self, expr: &str, await_promise: bool) -> Result<Value, String> {
+        let r = self.send(
+            "Runtime.evaluate",
+            json!({"expression": expr, "returnByValue": true, "awaitPromise": await_promise}),
+        )?;
+        if let Some(ex) = r.get("exceptionDetails") {
+            let text = ex
+                .get("exception")
+                .and_then(|e| e.get("description"))
+                .and_then(Value::as_str)
+                .or_else(|| ex.get("text").and_then(Value::as_str))
+                .unwrap_or("javascript exception");
+            return Err(format!("eval: {}", text));
+        }
+        Ok(r.get("result")
+            .and_then(|x| x.get("value"))
+            .cloned()
+            .unwrap_or(Value::Null))
+    }
+
+    /// Captures a PNG screenshot into `out_dir/filename`; returns the path.
+    pub fn screenshot(&mut self, out_dir: &Path, filename: &str) -> Result<PathBuf, String> {
+        let r = self.send("Page.captureScreenshot", json!({"format": "png"}))?;
+        let data = r
+            .get("data")
+            .and_then(Value::as_str)
+            .ok_or_else(|| "screenshot: no data".to_string())?;
+        let bytes = base64_decode(data)?;
+        fs::create_dir_all(out_dir).map_err(|e| format!("out dir: {}", e))?;
+        let path = out_dir.join(filename);
+        fs::write(&path, bytes).map_err(|e| format!("write {}: {}", path.display(), e))?;
+        Ok(path)
+    }
+
+    /// Waits until the page's `document.readyState` is complete (or the deadline passes).
+    fn wait_loaded(&mut self, timeout: Duration) {
+        let deadline = Instant::now() + timeout;
+        while Instant::now() < deadline {
+            if self
+                .eval("document.readyState", false)
+                .ok()
+                .as_ref()
+                .and_then(Value::as_str)
+                == Some("complete")
+            {
+                return;
+            }
+            std::thread::sleep(Duration::from_millis(200));
+        }
+    }
+}
+
+/// A live browser: Chrome process plus the page session. Dropping it kills Chrome.
+pub struct Mirror {
+    _chrome: ChromeProcess,
+    pub cdp: CdpClient,
+}
+
+impl Mirror {
+    /// Spawns Chrome on `url` and attaches to its page.
+    pub fn open(url: &str) -> Result<Self, String> {
+        let binary = find_chrome().ok_or_else(|| {
+            "no Chrome found (set AIEN_CHROME or install google-chrome/chromium)".to_string()
+        })?;
+        let chrome = ChromeProcess::spawn(&binary, url)?;
+        let ws_url = chrome.page_ws_url()?;
+        let mut cdp = CdpClient::connect(&ws_url)?;
+        cdp.send("Page.enable", json!({}))?;
+        cdp.send("Runtime.enable", json!({}))?;
+        cdp.wait_loaded(Duration::from_secs(15));
+        Ok(Mirror {
+            _chrome: chrome,
+            cdp,
+        })
+    }
+}
+
+impl Drop for Mirror {
+    fn drop(&mut self) {
+        self.cdp.ws.close();
+    }
+}
+
+// ---------------------------------------------------------------------------
+// Modes
+// ---------------------------------------------------------------------------
+
+fn write_report(out_dir: &Path, name: &str, report: &Value) -> Result<PathBuf, String> {
+    fs::create_dir_all(out_dir).map_err(|e| format!("out dir: {}", e))?;
+    let path = out_dir.join(name);
+    let text = serde_json::to_string_pretty(report).map_err(|e| e.to_string())?;
+    fs::write(&path, text).map_err(|e| format!("write {}: {}", path.display(), e))?;
+    Ok(path)
+}
+
+fn agent_messages_js() -> &'static str {
+    // Current Cockpit (spark-cockpit-rs/static): agent replies are rows with
+    // class "message-row agent-row". The old ".chat-msg.assistant" selector is
+    // kept as a fallback for older builds.
+    "Array.from(document.querySelectorAll('.message-row.agent-row, .chat-msg.assistant'))\
+       .map(el => el.textContent.trim())"
+}
+
+fn send_chat_js(prompt: &str) -> String {
+    format!(
+        "(() => {{ const inp = document.getElementById('chat-input'); if (!inp) return 'no-input';\
+           inp.value = {p}; inp.dispatchEvent(new Event('input', {{bubbles: true}}));\
+           const btn = document.getElementById('btn-send');\
+           if (btn) {{ btn.click(); return 'clicked'; }}\
+           if (typeof sendMessage === 'function') {{ sendMessage(); return 'called'; }}\
+           return 'no-send'; }})()",
+        p = Value::String(prompt.to_string())
+    )
+}
+
+/// Polls agent rows until a reply appears and stops growing (or `timeout` passes).
+fn wait_for_reply(cdp: &mut CdpClient, before: usize, timeout: Duration) -> (String, bool) {
+    let deadline = Instant::now() + timeout;
+    let mut last = String::new();
+    let mut stable = 0u32;
+    while Instant::now() < deadline {
+        std::thread::sleep(Duration::from_millis(500));
+        let msgs = cdp.eval(agent_messages_js(), false).unwrap_or(Value::Null);
+        let texts: Vec<String> = msgs
+            .as_array()
+            .map(|a| {
+                a.iter()
+                    .filter_map(Value::as_str)
+                    .map(str::to_string)
+                    .collect()
+            })
+            .unwrap_or_default();
+        if texts.len() > before {
+            let current = texts.last().cloned().unwrap_or_default();
+            if !current.is_empty() && current == last {
+                stable += 1;
+                if stable >= 4 {
+                    return (current, true);
+                }
+            } else {
+                stable = 0;
+            }
+            last = current;
+        }
+    }
+    (last, false)
+}
+
+/// Cockpit self-test: hydration, chat stream, navigation, three screenshots.
+pub fn run_test(url: &str, out_dir: &Path) -> Value {
+    let mut report = json!({
+        "mode": "test",
+        "timestamp": now_secs(),
+        "target_url": url,
+        "assertions": {},
+        "screenshots": [],
+        "status": "in_progress"
+    });
+    let push_shot = |report: &mut Value, p: PathBuf| {
+        if let Some(a) = report["screenshots"].as_array_mut() {
+            a.push(json!(p.display().to_string()));
+        }
+    };
+    let mut mirror = match Mirror::open(url) {
+        Ok(m) => m,
+        Err(e) => {
+            report["status"] = json!("FAILED");
+            report["error"] = json!(e);
+            if let Ok(p) = write_report(out_dir, "report.json", &report) {
+                report["report_path"] = json!(p.display().to_string());
+            }
+            return report;
+        }
+    };
+    let cdp = &mut mirror.cdp;
+
+    // 1. Hydration: title, chat input and navigation present.
+    let title = cdp
+        .eval("document.title", false)
+        .ok()
+        .and_then(|v| v.as_str().map(str::to_string))
+        .unwrap_or_default();
+    let has_input = cdp
+        .eval("!!document.getElementById('chat-input')", false)
+        .ok()
+        .and_then(|v| v.as_bool())
+        .unwrap_or(false);
+    let has_nav = cdp
+        .eval(
+            "!!(document.querySelector('[data-view]') || document.querySelector('[data-tab]'))",
+            false,
+        )
+        .ok()
+        .and_then(|v| v.as_bool())
+        .unwrap_or(false);
+    let hydrated = !title.is_empty() && has_input && has_nav;
+    report["assertions"]["initial_page_hydration"] = json!({
+        "pass": hydrated, "title": title, "chat_input": has_input, "navigation": has_nav
+    });
+    if let Ok(p) = cdp.screenshot(out_dir, "cockpit_init.png") {
+        push_shot(&mut report, p);
+    }
+
+    // 2. Chat stream: send a prompt and wait for a stable agent reply.
+    let before = cdp
+        .eval(&format!("{}.length", agent_messages_js()), false)
+        .ok()
+        .and_then(|v| v.as_u64())
+        .unwrap_or(0) as usize;
+    let sent = cdp
+        .eval(
+            &send_chat_js("Hello AIEN, please report current sovereign status."),
+            false,
+        )
+        .unwrap_or(Value::Null);
+    let (reply, stable) = if sent.as_str() == Some("clicked") || sent.as_str() == Some("called") {
+        wait_for_reply(cdp, before, Duration::from_secs(45))
+    } else {
+        (String::new(), false)
+    };
+    let chat_pass = !reply.is_empty() && stable;
+    report["assertions"]["chat_live_stream"] = json!({
+        "pass": chat_pass, "send": sent, "reply_chars": reply.chars().count(), "stable": stable
+    });
+    if let Ok(p) = cdp.screenshot(out_dir, "cockpit_chat_stream.png") {
+        push_shot(&mut report, p);
+    }
+
+    // 3. Navigation: click every nav control, confirm a visible view switches.
+    let nav = cdp
+        .eval(
+            "(() => { const btns = Array.from(document.querySelectorAll('[data-view], [data-tab]'));\
+               const seen = []; for (const b of btns) { b.click();\
+               const v = b.dataset.view || b.dataset.tab;\
+               const el = document.getElementById('view-' + v) || document.getElementById('pane-' + v)\
+                 || document.getElementById(v);\
+               seen.push({view: v, present: !!el, visible: !!el && el.offsetParent !== null}); }\
+               return seen; })()",
+            false,
+        )
+        .unwrap_or(Value::Null);
+    let nav_items = nav.as_array().cloned().unwrap_or_default();
+    let nav_pass = !nav_items.is_empty()
+        && nav_items
+            .iter()
+            .all(|i| i.get("present").and_then(Value::as_bool).unwrap_or(false));
+    report["assertions"]["tab_navigation_and_actions"] = json!({"pass": nav_pass, "views": nav});
+    // Back to chat for the final frame.
+    cdp.eval(
+        "document.querySelector('[data-view=\"chat\"], [data-tab=\"chat\"]')?.click()",
+        false,
+    )
+    .ok();
+    if let Ok(p) = cdp.screenshot(out_dir, "cockpit_actions.png") {
+        push_shot(&mut report, p);
+    }
+
+    let all = hydrated && chat_pass && nav_pass;
+    report["status"] = json!(if all { "PASSED" } else { "FAILED" });
+    if let Ok(p) = write_report(out_dir, "report.json", &report) {
+        report["report_path"] = json!(p.display().to_string());
+    }
+    report
+}
+
+/// Mentor session: one prompt into the Cockpit chat, wait for the reply, screenshot.
+pub fn run_mentor(url: &str, prompt: &str, out_dir: &Path) -> Value {
+    let mut report = json!({
+        "mode": "mentor",
+        "timestamp": now_secs(),
+        "target_url": url,
+        "prompt": prompt,
+        "response": "",
+        "screenshot": "",
+        "status": "in_progress"
+    });
+    let mut mirror = match Mirror::open(url) {
+        Ok(m) => m,
+        Err(e) => {
+            report["status"] = json!("FAILED");
+            report["error"] = json!(e);
+            if let Ok(p) = write_report(out_dir, "mentor_response.json", &report) {
+                report["report_path"] = json!(p.display().to_string());
+            }
+            return report;
+        }
+    };
+    let cdp = &mut mirror.cdp;
+    cdp.eval(
+        "document.querySelector('[data-view=\"chat\"], [data-tab=\"chat\"]')?.click()",
+        false,
+    )
+    .ok();
+    let before = cdp
+        .eval(&format!("{}.length", agent_messages_js()), false)
+        .ok()
+        .and_then(|v| v.as_u64())
+        .unwrap_or(0) as usize;
+    let sent = cdp
+        .eval(&send_chat_js(prompt), false)
+        .unwrap_or(Value::Null);
+    report["send"] = sent;
+    let (reply, stable) = wait_for_reply(cdp, before, Duration::from_secs(120));
+    report["response"] = json!(reply);
+    report["stable"] = json!(stable);
+    if let Ok(p) = cdp.screenshot(out_dir, "cockpit_mentor_response.png") {
+        report["screenshot"] = json!(p.display().to_string());
+    }
+    report["status"] = json!(if reply.chars().count() > 50 {
+        "COMPLETED"
+    } else {
+        "FAILED"
+    });
+    if let Ok(p) = write_report(out_dir, "mentor_response.json", &report) {
+        report["report_path"] = json!(p.display().to_string());
+    }
+    report
+}
+
+/// Opens `url`, records the title and saves `filename` (PNG) under `out_dir`.
+pub fn run_screenshot(url: &str, out_dir: &Path, filename: &str) -> Value {
+    let mut mirror = match Mirror::open(url) {
+        Ok(m) => m,
+        Err(e) => return json!({"mode": "screenshot", "status": "error", "error": e}),
+    };
+    let title = mirror
+        .cdp
+        .eval("document.title", false)
+        .unwrap_or(Value::Null);
+    match mirror.cdp.screenshot(out_dir, filename) {
+        Ok(p) => json!({
+            "mode": "screenshot", "status": "ok", "target_url": url,
+            "title": title, "screenshot": p.display().to_string()
+        }),
+        Err(e) => json!({"mode": "screenshot", "status": "error", "error": e, "title": title}),
+    }
+}
+
+/// Opens `url` and evaluates `expr`, returning its value.
+pub fn run_eval(url: &str, expr: &str) -> Value {
+    let mut mirror = match Mirror::open(url) {
+        Ok(m) => m,
+        Err(e) => return json!({"mode": "eval", "status": "error", "error": e}),
+    };
+    match mirror.cdp.eval(expr, true) {
+        Ok(v) => json!({"mode": "eval", "status": "ok", "target_url": url, "value": v}),
+        Err(e) => json!({"mode": "eval", "status": "error", "error": e}),
+    }
+}
+
+/// Entry point shared by the `browser` tool and the binary.
+///
+/// `action` is one of `test`, `mentor`, `screenshot`, `eval`. `arg` is the
+/// mentor prompt or the eval expression. Unknown actions report an error.
+pub fn dispatch(action: &str, arg: Option<&str>, url: &str, out_dir: &Path) -> Value {
+    match action {
+        "test" => run_test(url, out_dir),
+        "mentor" => run_mentor(
+            url,
+            arg.unwrap_or("AIEN, report self-improvement status."),
+            out_dir,
+        ),
+        "screenshot" => run_screenshot(url, out_dir, arg.unwrap_or("screenshot.png")),
+        "eval" => run_eval(url, arg.unwrap_or("document.title")),
+        other => json!({
+            "status": "error",
+            "error": format!("unknown browser action '{}' (use test, mentor, screenshot or eval)", other)
+        }),
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    #[test]
+    fn base64_roundtrip() {
+        for s in ["", "f", "fo", "foo", "foob", "fooba", "foobar"] {
+            let enc = base64_encode(s.as_bytes());
+            assert_eq!(base64_decode(&enc).unwrap(), s.as_bytes());
+        }
+        assert_eq!(base64_encode(b"foobar"), "Zm9vYmFy");
+        assert_eq!(base64_decode("Zm9v\nYmFy").unwrap(), b"foobar");
+        assert!(base64_decode("Zm9v*").is_err());
+    }
+
+    #[test]
+    fn unknown_action_is_an_error() {
+        let v = dispatch("fly", None, DEFAULT_URL, Path::new("/nonexistent"));
+        assert_eq!(v["status"], "error");
+        assert!(v["error"].as_str().unwrap().contains("fly"));
+    }
+
+    /// Spawns a real headless Chrome on a local stub page, screenshots it and
+    /// evaluates the title. Skipped (with a note) when no Chrome is installed,
+    /// so CI without a browser still passes.
+    #[test]
+    fn stub_page_screenshot_and_eval() {
+        if find_chrome().is_none() {
+            eprintln!("skipping stub_page_screenshot_and_eval: no Chrome binary found");
+            return;
+        }
+        let dir = tempfile::tempdir().expect("tempdir");
+        let page = dir.path().join("stub.html");
+        fs::write(
+            &page,
+            "<!doctype html><html><head><title>AIEN Stub</title></head>\
+             <body><h1 id=\"h\">mirror</h1><textarea id=\"chat-input\"></textarea></body></html>",
+        )
+        .unwrap();
+        let url = format!("file://{}", page.display());
+        let out = dir.path().join("shots");
+
+        let shot = run_screenshot(&url, &out, "stub.png");
+        assert_eq!(shot["status"], "ok", "{}", shot);
+        assert_eq!(shot["title"], "AIEN Stub");
+        let bytes = fs::read(out.join("stub.png")).unwrap();
+        assert!(bytes.len() > 100, "png too small: {} bytes", bytes.len());
+        assert_eq!(&bytes[..8], b"\x89PNG\r\n\x1a\n");
+
+        let ev = run_eval(
+            &url,
+            "document.getElementById('h').textContent + ':' + 2 * 21",
+        );
+        assert_eq!(ev["status"], "ok", "{}", ev);
+        assert_eq!(ev["value"], "mirror:42");
+    }
+}
diff --git a/crates/aien-cli/src/commands.rs b/crates/aien-cli/src/commands.rs
index 3e8487d8..2702cf3e 100644
--- a/crates/aien-cli/src/commands.rs
+++ b/crates/aien-cli/src/commands.rs
@@ -54,7 +54,7 @@ pub async fn handle_slash_command(cmd: &str) -> bool {
   /context7 resolve <library> [query] | /context7 query <library_id> <query>
   context7-sync             Refresh Rust, Mojo, MAX, Tokio, Axum, and Serde docs into Cortex
   /sandbox [init|status|test|promote|clean] Isolated Git worktree sandbox
-  /browser [test|mentor]    Headless Chrome CDP mirror self-testing & mentoring
+  /browser [test|mentor|screenshot|eval] Headless Chrome CDP mirror (Rust, aien-browser-mirror)
   /subagents [list|view|run] Recursive contextual subagents hierarchy
   /goal [list|new|done]     Manage project goals & milestone lattices"
             );
diff --git a/crates/aien-cli/src/lib.rs b/crates/aien-cli/src/lib.rs
index 89c0242b..35229cc3 100644
--- a/crates/aien-cli/src/lib.rs
+++ b/crates/aien-cli/src/lib.rs
@@ -1,2 +1,5 @@
 // Verified autonomous sandbox edit
 // Verified autonomous self-improvement loop active
+
+/// Headless-Chrome Cockpit mirror over CDP (sovereign-core #180).
+pub mod browser_mirror;
diff --git a/crates/aien-cli/src/sandbox.rs b/crates/aien-cli/src/sandbox.rs
index 473ccf54..b619cb3c 100644
--- a/crates/aien-cli/src/sandbox.rs
+++ b/crates/aien-cli/src/sandbox.rs
@@ -358,17 +358,30 @@ pub fn sandbox_dispatch_tool(args: &Value) -> Value {
     }
 }
 
-pub fn browser_dispatch_tool(action: &str, _prompt: Option<&str>) -> Value {
-    // The browser mirror ran a Python script outside this repository
-    // (basecamp/scripts/browser_mirror_test.py). AIEN carries no Python, so the
-    // tool reports itself unavailable instead of shelling out.
-    json!({
-        "status": "error",
-        "error": format!(
-            "browser action '{}' is unavailable: the Python browser mirror was removed from the sovereign build",
-            action
-        )
-    })
+pub fn browser_dispatch_tool(action: &str, prompt: Option<&str>) -> Value {
+    browser_dispatch_tool_at(action, prompt, None, None)
+}
+
+/// Browser mirror with an explicit Cockpit URL and output directory.
+/// `None` falls back to the Cockpit default (127.0.0.1:18095) and
+/// `~/basecamp/ui-tests`. The AIEN_COCKPIT_URL environment variable
+/// overrides the default URL.
+pub fn browser_dispatch_tool_at(
+    action: &str,
+    prompt: Option<&str>,
+    url: Option<&str>,
+    out_dir: Option<&std::path::Path>,
+) -> Value {
+    use aien_cli::browser_mirror as bm;
+    let env_url = std::env::var("AIEN_COCKPIT_URL").ok();
+    let url = url
+        .map(str::to_string)
+        .or(env_url)
+        .unwrap_or_else(|| bm::DEFAULT_URL.to_string());
+    let out = out_dir
+        .map(std::path::Path::to_path_buf)
+        .unwrap_or_else(bm::default_out_dir);
+    bm::dispatch(action, prompt, &url, &out)
 }
 
 pub fn handle_sandbox_command(parts: &[&str]) {
@@ -437,30 +450,25 @@ pub fn handle_sandbox_command(parts: &[&str]) {
 }
 
 pub fn handle_browser_command(parts: &[&str]) {
-    if !parts.is_empty() && parts[0] == "mentor" {
-        let prompt = if parts.len() > 1 {
-            parts[1..].join(" ")
-        } else {
-            "AIEN, report self-improvement status.".to_string()
-        };
-        println!(
-            "{}",
-            format!(
-                "Spawning browser mentor session with prompt: '{}'...",
-                prompt
-            )
-            .yellow()
-        );
-        let res = browser_dispatch_tool("mentor", Some(&prompt));
-        println!("{}", serde_json::to_string_pretty(&res).unwrap_or_default());
+    let action = parts.first().copied().unwrap_or("test");
+    let rest = if parts.len() > 1 {
+        Some(parts[1..].join(" "))
     } else {
-        println!(
-            "{}",
-            "Spawning headless Chrome and running mirror self-test on Cockpit...".yellow()
-        );
-        let res = browser_dispatch_tool("test", None);
-        println!("{}", serde_json::to_string_pretty(&res).unwrap_or_default());
-    }
+        None
+    };
+    let note = match action {
+        "mentor" => format!(
+            "Spawning browser mentor session with prompt: '{}'...",
+            rest.as_deref()
+                .unwrap_or("AIEN, report self-improvement status.")
+        ),
+        "screenshot" => "Spawning headless Chrome for a Cockpit screenshot...".to_string(),
+        "eval" => "Spawning headless Chrome to evaluate JavaScript on the Cockpit...".to_string(),
+        _ => "Spawning headless Chrome and running mirror self-test on Cockpit...".to_string(),
+    };
+    println!("{}", note.yellow());
+    let res = browser_dispatch_tool(action, rest.as_deref());
+    println!("{}", serde_json::to_string_pretty(&res).unwrap_or_default());
 }
 
 #[cfg(test)]
diff --git a/skills/.crumb b/skills/.crumb
index 57fbcb1e..2b0a72b3 100644
--- a/skills/.crumb
+++ b/skills/.crumb
@@ -63,8 +63,8 @@
           "purpose": ""
         },
         {
-          "digest": "5c53b4ecd62e0faa383da295b44842cd3f7d2d6c41f5b432757e3f5f0e361245",
-          "last_commit": "b2fef5c",
+          "digest": "ef4f65f16a7f6267935e22d7358b1a8bf842e823d6da698ea9230dab893f039d",
+          "last_commit": "8a48904",
           "name": "self-improvement",
           "purpose": ""
         },
@@ -75,15 +75,15 @@
           "purpose": ""
         }
       ],
-      "children_root": "sha256:b84fd33f93982c0d0f78d560d7ac7a9d0c6df559fd3872d4f5bb03c75ea2bb4b",
-      "compiled_at": "2026-10-09T21:32:49Z",
+      "children_root": "sha256:6de9b42dfb7b31f2399253cdc72b049c4457a68c0d140d5b2255cc478d062079",
+      "compiled_at": "2026-10-10T08:55:54Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:ac32ed84159cae1f43f3b5d2307b2a1ab04ea580c8f96c1f52566a7f21cca0b0",
+      "digest": "sha256:f432725dc4aef6ecd69eea043123fbb7593a9d29af97d70a561f5f355a8ad180",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 10,
-      "generated_at_commit": "df60af9215d57c3e6a37f476caba05ef3b2cf384",
-      "source_tree": "sha256:fbe818262c8e6a6dff3417d6265ec5ebf15dbaf7650dd9132dd65cd767e66d7a"
+      "generated_at_commit": "8a48904fde00f3a182f9840aeb2acd23e3c79fa6",
+      "source_tree": "sha256:73a9a804b9e8f835e987f14a45f29bb816bdca24a5a8cb535ba7f84eb87ab682"
     }
   },
   "history": [
diff --git a/skills/self-improvement/.crumb b/skills/self-improvement/.crumb
index 14f51008..ec405aef 100644
--- a/skills/self-improvement/.crumb
+++ b/skills/self-improvement/.crumb
@@ -4,14 +4,14 @@
     "generated": {
       "children": [],
       "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "compiled_at": "2026-10-09T21:32:49Z",
+      "compiled_at": "2026-10-10T08:55:54Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:5c53b4ecd62e0faa383da295b44842cd3f7d2d6c41f5b432757e3f5f0e361245",
+      "digest": "sha256:ef4f65f16a7f6267935e22d7358b1a8bf842e823d6da698ea9230dab893f039d",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 1,
-      "generated_at_commit": "df60af9215d57c3e6a37f476caba05ef3b2cf384",
-      "source_tree": "sha256:587b443b5c01970b3c53425b1b78c8766782e1ffccd50acfabf4977b380241c2"
+      "generated_at_commit": "8a48904fde00f3a182f9840aeb2acd23e3c79fa6",
+      "source_tree": "sha256:29770718c173eb2462729405676ab5516dc8684c33033fb2fec0fb491ff12667"
     }
   },
   "parent": {
diff --git a/skills/self-improvement/SKILL.md b/skills/self-improvement/SKILL.md
index 96a1a544..e8586590 100644
--- a/skills/self-improvement/SKILL.md
+++ b/skills/self-improvement/SKILL.md
@@ -91,9 +91,18 @@ The Python dream engine (basecamp/aien-dream/dream_engine.py) was removed from t
 
 ## 4. Headless Browser Mirror and Mentor Harness
 
-AIEN's headless-Chrome Cockpit mirror (Chrome DevTools Protocol) was a Python script outside this repository (basecamp/scripts/browser_mirror_test.py). It was removed from the sovereign build (sovereign-core #181). Today `aien --browser` and `aien --browser mentor "<prompt>"` run, but both report `status: error` ("browser action ... is unavailable"). The assertion self-test and self-mentoring steps are unavailable until the Rust browser test lands (sovereign-core #180). Do not run the old script by hand.
+AIEN drives a headless Chrome over the Chrome DevTools Protocol from Rust (`crates/aien-cli/src/browser_mirror.rs`, sovereign-core #180). No Python and no extra crates: the websocket client and the base64 decoder live in the module. The same code runs behind the `browser` tool, `aien --browser`, and the standalone binary:
 
-When #180 lands, restore here: the self-test checks (hydration, chat stream, tactile actions, tab navigation) and the screenshots saved under ~/basecamp/ui-tests/.
+```
+aien-browser-mirror --test                          # Cockpit self-test: report.json + 3 screenshots
+aien-browser-mirror --mentor "<prompt>"             # one chat prompt, waits for the reply, screenshot
+aien-browser-mirror --screenshot [file.png] --url U # screenshot of any page
+aien-browser-mirror --eval "<javascript>" --url U   # evaluate an expression on any page
+```
+
+Defaults: `--url http://127.0.0.1:18095` (override with `--url` or `AIEN_COCKPIT_URL`), `--out-dir ~/basecamp/ui-tests`, Chrome found as `google-chrome`, `chromium` or `AIEN_CHROME`. Exit status 0 means PASSED, COMPLETED or ok.
+
+The self-test checks hydration (title, `#chat-input`, navigation controls), a live chat reply sent through `#btn-send` that stops growing, and every `[data-view]` or `[data-tab]` control switching to a present view. Screenshots land as `cockpit_init.png`, `cockpit_chat_stream.png` and `cockpit_actions.png`, next to `report.json`. The mentor run writes `cockpit_mentor_response.png` and `mentor_response.json` (COMPLETED when the reply is longer than 50 characters). The Cockpit must be running for the self-test; against a dead port the report says FAILED with `chat_input: false`.
 
 ## 5. Cortex Memory Commitment